diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index afa63aa92..eb7e44644 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -20,61 +20,9 @@ permissions: jobs: contracts: name: Contracts - uses: multiversx/mx-sc-actions/.github/workflows/contracts.yml@v2.3.5 + uses: multiversx/mx-sc-actions/.github/workflows/contracts.yml@v3.1.0 with: rust-toolchain: nightly-2023-12-11 - vmtools-version: v1.5.24 + coverage-args: --ignore-filename-regex='/.cargo/git' --output ./coverage.md secrets: token: ${{ secrets.GITHUB_TOKEN }} - - # TEMPORARY: Remove this job when we can upgrade to mx-sc-actions v3+ - test_coverage: - name: Test Coverage - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Install rust - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - toolchain: nightly-2023-12-11 - target: wasm32-unknown-unknown - - - name: Install prerequisites - run: | - rustup component add llvm-tools-preview - dirname $(find ~/.rustup -name llvm-cov) >> $GITHUB_PATH - - echo $(dirname $(find ~/.rustup -name llvm-cov)) - - cargo install multiversx-sc-meta --locked - - - name: Run tests and generate report - env: - RUSTFLAGS: "" - run: | - sc-meta test-coverage --output ./coverage.md - - - name: Upload the report - uses: actions/upload-artifact@v3 - with: - name: coverage - path: coverage.md - - - name: Find the comment containing the report - id: fc - uses: peter-evans/find-comment@v2 - if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository - with: - issue-number: ${{ github.event.pull_request.number }} - comment-author: "github-actions[bot]" - body-includes: "Coverage Summary" - - - name: Create or update the report comment - uses: peter-evans/create-or-update-comment@v2 - if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository - with: - comment-id: ${{ steps.fc.outputs.comment-id }} - issue-number: ${{ github.event.pull_request.number }} - body-file: ./coverage.md - edit-mode: replace diff --git a/Cargo.lock b/Cargo.lock index dbfbf95f6..6f7637b31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -123,12 +123,6 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" - [[package]] name = "bech32" version = "0.9.1" @@ -142,8 +136,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93f2635620bf0b9d4576eb7bb9a38a55df78bd1205d26fa994b25911a69f212f" dependencies = [ "bitcoin_hashes", - "rand", - "rand_core", + "rand 0.8.5", + "rand_core 0.6.4", "serde", "unicode-normalization", ] @@ -166,6 +160,15 @@ version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + [[package]] name = "block-buffer" version = "0.10.4" @@ -323,12 +326,6 @@ dependencies = [ "token_send", ] -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "contexts" version = "0.0.0" @@ -435,42 +432,17 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "4.1.1" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89b8c6a2e4b1f45971ad09761aafb85514a84744b67a95e32c3cc1352d1f65c" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" dependencies = [ - "cfg-if 1.0.0", - "cpufeatures", - "curve25519-dalek-derive", - "digest", - "fiat-crypto", - "platforms", - "rustc_version", + "byteorder", + "digest 0.9.0", + "rand_core 0.5.1", "subtle", "zeroize", ] -[[package]] -name = "curve25519-dalek-derive" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "der" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "dex-tests" version = "0.0.0" @@ -497,13 +469,22 @@ dependencies = [ "simple-lock", ] +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + [[package]] name = "digest" version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer", + "block-buffer 0.10.4", "crypto-common", "subtle", ] @@ -552,25 +533,24 @@ dependencies = [ [[package]] name = "ed25519" -version = "2.2.3" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" dependencies = [ - "pkcs8", "signature", ] [[package]] name = "ed25519-dalek" -version = "2.1.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f628eaec48bfd21b865dc2950cfa014450c01d2fa2b69a86c2fd5844ec523c0" +checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" dependencies = [ "curve25519-dalek", "ed25519", + "rand 0.7.3", "serde", - "sha2", - "subtle", + "sha2 0.9.9", "zeroize", ] @@ -969,12 +949,6 @@ dependencies = [ "multiversx-sc-meta", ] -[[package]] -name = "fiat-crypto" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27573eac26f4dd11e2b1916c3fe1baa56407c83c71a773a8ba17ec0bca03b6b7" - [[package]] name = "fixed-supply-token" version = "0.0.0" @@ -1087,7 +1061,7 @@ dependencies = [ "pair-mock", "pausable", "price-discovery", - "rand", + "rand 0.8.5", "rewards", "router", "simple-lock", @@ -1103,6 +1077,17 @@ dependencies = [ "version_check", ] +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + [[package]] name = "getrandom" version = "0.2.12" @@ -1111,7 +1096,7 @@ checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if 1.0.0", "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", ] [[package]] @@ -1234,7 +1219,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "digest", + "digest 0.10.7", ] [[package]] @@ -1565,15 +1550,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" dependencies = [ "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys 0.48.0", ] [[package]] name = "multiversx-chain-scenario-format" -version = "0.21.1" +version = "0.22.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfc2b1dc76af14c24145672c2779474046ab44ef56bac82a58844328f4b4d2e" +checksum = "7a9190bdd56300e801e7793fc4ee7dc0c76c1149aac019da8c71cc58254966fe" dependencies = [ "bech32", "hex", @@ -1586,11 +1571,12 @@ dependencies = [ [[package]] name = "multiversx-chain-vm" -version = "0.7.1" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75459864359798406a45a7bb2ed221d623b2e39484ec3e4ac6d23167bfc50b33" +checksum = "a363734a77774f4095fad6f49c6772b82edd833ed47a7c1ca87db18f68ccfffd" dependencies = [ "bitflags 2.4.2", + "colored", "ed25519-dalek", "hex", "hex-literal 0.4.1", @@ -1598,9 +1584,9 @@ dependencies = [ "multiversx-chain-vm-executor", "num-bigint", "num-traits", - "rand", + "rand 0.8.5", "rand_seeder", - "sha2", + "sha2 0.10.8", "sha3", ] @@ -1612,9 +1598,9 @@ checksum = "b59072fa0624b55ae5ae3fa6bfa91515bbeb4ac440214bc4a509e2c8806d6e9f" [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags 2.4.2", "hex-literal 0.4.1", @@ -1625,9 +1611,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -1636,9 +1622,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -1648,9 +1634,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -1661,9 +1647,9 @@ dependencies = [ [[package]] name = "multiversx-sc-meta" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c8250fd72b78dff76fd3789078aee3dec2524ca37250c645dcb2b1bf067551e" +checksum = "add1bda75ed39bdb246097e5233a4ed7af6587f7c06a7e5084742199d685f6ab" dependencies = [ "clap", "colored", @@ -1677,28 +1663,29 @@ dependencies = [ "reqwest", "ruplacer", "rustc_version", + "semver", "serde", "serde_json", "toml", - "wasmparser 0.118.1", + "wasmparser 0.121.2", "wasmprinter", "zip", ] [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-scenario" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3aa2644018c85caf3cc39a130961e39bd719ff3d75751b60a7394d6eace1c847" +checksum = "42dea5dcc79ef692e907d919ca6bffc81a07c84af977e98b4192c2fd4ff2c67f" dependencies = [ "base64", "bech32", @@ -1718,15 +1705,15 @@ dependencies = [ "pathdiff", "serde", "serde_json", - "sha2", + "sha2 0.10.8", "tokio", ] [[package]] name = "multiversx-sdk" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f86d0da66ca2eb334414786a287010bb669b8d815a7d3b690d629a04b86bb80" +checksum = "46d709ddf46c50a407ce4b90ff487e854926d47f80de6abfe4a4adca3eaa7964" dependencies = [ "anyhow", "base64", @@ -1737,12 +1724,12 @@ dependencies = [ "itertools 0.12.0", "pbkdf2", "pem", - "rand", + "rand 0.8.5", "reqwest", "serde", "serde_json", "serde_repr", - "sha2", + "sha2 0.10.8", "sha3", "tokio", "zeroize", @@ -1830,6 +1817,12 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "opaque-debug" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" + [[package]] name = "openssl" version = "0.10.62" @@ -1981,7 +1974,7 @@ version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" dependencies = [ - "digest", + "digest 0.10.7", ] [[package]] @@ -2021,28 +2014,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - [[package]] name = "pkg-config" version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" -[[package]] -name = "platforms" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "626dec3cac7cc0e1577a2ec3fc496277ec2baa084bebad95bb6fdbfae235f84c" - [[package]] name = "ppv-lite86" version = "0.2.17" @@ -2074,9 +2051,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.76" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] @@ -2163,6 +2140,19 @@ dependencies = [ "nibble_vec", ] +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom 0.1.16", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc", +] + [[package]] name = "rand" version = "0.8.5" @@ -2170,8 +2160,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha", - "rand_core", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", ] [[package]] @@ -2181,7 +2181,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", ] [[package]] @@ -2190,7 +2199,16 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.12", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", ] [[package]] @@ -2199,7 +2217,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf2890aaef0aa82719a50e808de264f9484b74b442e1a3a0e5ee38243ac40bdb" dependencies = [ - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -2487,6 +2505,19 @@ dependencies = [ "serde", ] +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", +] + [[package]] name = "sha2" version = "0.10.8" @@ -2495,7 +2526,7 @@ checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if 1.0.0", "cpufeatures", - "digest", + "digest 0.10.7", ] [[package]] @@ -2504,7 +2535,7 @@ version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" dependencies = [ - "digest", + "digest 0.10.7", "keccak", ] @@ -2519,12 +2550,9 @@ dependencies = [ [[package]] name = "signature" -version = "2.2.0" +version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "rand_core", -] +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" [[package]] name = "simple-lock" @@ -2594,16 +2622,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", -] - [[package]] name = "strsim" version = "0.10.0" @@ -2938,6 +2956,12 @@ dependencies = [ "try-lock", ] +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -3012,19 +3036,20 @@ checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" [[package]] name = "wasmparser" -version = "0.118.1" +version = "0.119.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ee9723b928e735d53000dec9eae7b07a60e490c85ab54abb66659fc61bfcd9" +checksum = "8c35daf77afb4f9b14016625144a391085ec2ca99ca9cc53ed291bb53ab5278d" dependencies = [ + "bitflags 2.4.2", "indexmap", "semver", ] [[package]] name = "wasmparser" -version = "0.119.0" +version = "0.121.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c35daf77afb4f9b14016625144a391085ec2ca99ca9cc53ed291bb53ab5278d" +checksum = "9dbe55c8f9d0dbd25d9447a5a889ff90c0cc3feaa7395310d3d826b2c703eaab" dependencies = [ "bitflags 2.4.2", "indexmap", @@ -3270,6 +3295,20 @@ name = "zeroize" version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "zip" diff --git a/common/common_errors/Cargo.toml b/common/common_errors/Cargo.toml index c61a89e80..09ba443fb 100644 --- a/common/common_errors/Cargo.toml +++ b/common/common_errors/Cargo.toml @@ -8,5 +8,5 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/common_structs/Cargo.toml b/common/common_structs/Cargo.toml index 8e5655f12..80c4d6b33 100644 --- a/common/common_structs/Cargo.toml +++ b/common/common_structs/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.mergeable] diff --git a/common/common_structs/src/farm_types.rs b/common/common_structs/src/farm_types.rs index db4d515c9..676b26e36 100644 --- a/common/common_structs/src/farm_types.rs +++ b/common/common_structs/src/farm_types.rs @@ -51,8 +51,8 @@ impl FixedSupplyToken for FarmTokenAttributes { impl Mergeable for FarmTokenAttributes { #[inline] - fn can_merge_with(&self, other: &Self) -> bool { - self.original_owner == other.original_owner + fn can_merge_with(&self, _other: &Self) -> bool { + true } fn merge_with(&mut self, other: Self) { @@ -80,6 +80,8 @@ pub trait FarmToken { fn get_compounded_rewards(&self) -> BigUint; fn get_initial_farming_tokens(&self) -> BigUint; + + fn get_original_owner(&self) -> ManagedAddress; } impl FarmToken for FarmTokenAttributes { @@ -97,4 +99,9 @@ impl FarmToken for FarmTokenAttributes { fn get_initial_farming_tokens(&self) -> BigUint { &self.current_farm_amount - &self.compounded_reward } + + #[inline] + fn get_original_owner(&self) -> ManagedAddress { + self.original_owner.clone() + } } diff --git a/common/modules/farm/config/Cargo.toml b/common/modules/farm/config/Cargo.toml index b5de657af..f7f478234 100644 --- a/common/modules/farm/config/Cargo.toml +++ b/common/modules/farm/config/Cargo.toml @@ -23,5 +23,5 @@ path = "../../pausable" path = "../../permissions_module" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/farm/contexts/Cargo.toml b/common/modules/farm/contexts/Cargo.toml index b61c7a7cb..033d99987 100644 --- a/common/modules/farm/contexts/Cargo.toml +++ b/common/modules/farm/contexts/Cargo.toml @@ -35,8 +35,8 @@ path = "../../pausable" path = "../../permissions_module" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" diff --git a/common/modules/farm/contexts/src/claim_rewards_context.rs b/common/modules/farm/contexts/src/claim_rewards_context.rs index 653c6b2e6..78b8f4e67 100644 --- a/common/modules/farm/contexts/src/claim_rewards_context.rs +++ b/common/modules/farm/contexts/src/claim_rewards_context.rs @@ -2,26 +2,28 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); use common_errors::{ERROR_BAD_PAYMENTS, ERROR_EMPTY_PAYMENTS}; -use common_structs::PaymentAttributesPair; +use common_structs::{PaymentAttributesPair, PaymentsVec}; use multiversx_sc::api::BlockchainApi; use multiversx_sc::contract_base::BlockchainWrapper; pub struct ClaimRewardsContext where M: ManagedTypeApi, - T: Clone + TopEncode + TopDecode + NestedEncode + NestedDecode, + T: Clone + TopEncode + TopDecode + NestedEncode + NestedDecode + ManagedVecItem, { pub first_farm_token: PaymentAttributesPair, - pub additional_payments: ManagedVec>, + pub additional_payments: PaymentsVec, + pub additional_attributes: ManagedVec, + pub all_attributes: ManagedVec, } impl ClaimRewardsContext where M: ManagedTypeApi + BlockchainApi, - T: Clone + TopEncode + TopDecode + NestedEncode + NestedDecode, + T: Clone + TopEncode + TopDecode + NestedEncode + NestedDecode + ManagedVecItem, { pub fn new( - mut payments: ManagedVec>, + mut payments: PaymentsVec, farm_token_id: &TokenIdentifier, api_wrapper: BlockchainWrapper, ) -> Self { @@ -29,22 +31,32 @@ where M::error_api_impl().signal_error(ERROR_EMPTY_PAYMENTS); } + let own_sc_address = api_wrapper.get_sc_address(); + let mut all_attributes = ManagedVec::new(); for p in &payments { if &p.token_identifier != farm_token_id { M::error_api_impl().signal_error(ERROR_BAD_PAYMENTS); } + + let token_data = + api_wrapper.get_esdt_token_data(&own_sc_address, farm_token_id, p.token_nonce); + let token_attributes: T = token_data.decode_attributes(); + all_attributes.push(token_attributes); } let first_payment = payments.get(0); payments.remove(0); - let own_sc_address = api_wrapper.get_sc_address(); - let token_data = api_wrapper.get_esdt_token_data( + // dumb framework errors otherwise + let first_token_data = api_wrapper.get_esdt_token_data( &own_sc_address, farm_token_id, first_payment.token_nonce, ); - let first_token_attributes: T = token_data.decode_attributes(); + let first_token_attributes: T = first_token_data.decode_attributes(); + + let mut additional_attributes = all_attributes.clone(); + additional_attributes.remove(0); ClaimRewardsContext { first_farm_token: PaymentAttributesPair { @@ -52,6 +64,8 @@ where attributes: first_token_attributes, }, additional_payments: payments, + additional_attributes, + all_attributes, } } } diff --git a/common/modules/farm/contexts/src/enter_farm_context.rs b/common/modules/farm/contexts/src/enter_farm_context.rs index 9da789d9a..27a060015 100644 --- a/common/modules/farm/contexts/src/enter_farm_context.rs +++ b/common/modules/farm/contexts/src/enter_farm_context.rs @@ -2,17 +2,28 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); use common_errors::{ERROR_BAD_PAYMENTS, ERROR_EMPTY_PAYMENTS}; +use common_structs::PaymentsVec; +use multiversx_sc::{api::BlockchainApi, contract_base::BlockchainWrapper}; -pub struct EnterFarmContext { +pub struct EnterFarmContext< + M: ManagedTypeApi, + T: Clone + TopEncode + TopDecode + NestedEncode + NestedDecode + ManagedVecItem, +> { pub farming_token_payment: EsdtTokenPayment, - pub additional_farm_tokens: ManagedVec>, + pub additional_farm_tokens: PaymentsVec, + pub additional_attributes: ManagedVec, } -impl EnterFarmContext { +impl< + M: ManagedTypeApi + BlockchainApi, + T: Clone + TopEncode + TopDecode + NestedEncode + NestedDecode + ManagedVecItem, + > EnterFarmContext +{ pub fn new( - mut payments: ManagedVec>, + mut payments: PaymentsVec, farming_token_id: &TokenIdentifier, farm_token_id: &TokenIdentifier, + api_wrapper: BlockchainWrapper, ) -> Self { if payments.is_empty() { M::error_api_impl().signal_error(ERROR_EMPTY_PAYMENTS); @@ -24,15 +35,24 @@ impl EnterFarmContext { } payments.remove(0); + + let own_sc_address = api_wrapper.get_sc_address(); + let mut additional_attributes = ManagedVec::new(); for p in &payments { if &p.token_identifier != farm_token_id { M::error_api_impl().signal_error(ERROR_BAD_PAYMENTS); } + + let token_data = + api_wrapper.get_esdt_token_data(&own_sc_address, farm_token_id, p.token_nonce); + let token_attributes: T = token_data.decode_attributes(); + additional_attributes.push(token_attributes); } EnterFarmContext { farming_token_payment, additional_farm_tokens: payments, + additional_attributes, } } } diff --git a/common/modules/farm/events/Cargo.toml b/common/modules/farm/events/Cargo.toml index f69904d95..1c4a763d4 100644 --- a/common/modules/farm/events/Cargo.toml +++ b/common/modules/farm/events/Cargo.toml @@ -14,5 +14,5 @@ path = "../../../common_structs" path = "../contexts" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/farm/events/src/events.rs b/common/modules/farm/events/src/events.rs index c32988130..6b55fed0c 100644 --- a/common/modules/farm/events/src/events.rs +++ b/common/modules/farm/events/src/events.rs @@ -142,7 +142,7 @@ pub trait EventsModule { fn emit_claim_rewards_event< 'a, C: FarmContracTraitBounds, - AttributesType: Clone + TopEncode + TopDecode + NestedEncode + NestedDecode, + AttributesType: Clone + TopEncode + TopDecode + NestedEncode + NestedDecode + ManagedVecItem, >( &self, original_caller: &ManagedAddress, @@ -189,7 +189,7 @@ pub trait EventsModule { fn emit_compound_rewards_event< 'a, C: FarmContracTraitBounds, - AttributesType: Clone + TopEncode + TopDecode + NestedEncode + NestedDecode, + AttributesType: Clone + TopEncode + TopDecode + NestedEncode + NestedDecode + ManagedVecItem, >( self, original_caller: &ManagedAddress, diff --git a/common/modules/farm/farm_base_impl/Cargo.toml b/common/modules/farm/farm_base_impl/Cargo.toml index 7ac538eff..119d39c53 100644 --- a/common/modules/farm/farm_base_impl/Cargo.toml +++ b/common/modules/farm/farm_base_impl/Cargo.toml @@ -50,11 +50,11 @@ path = "../../../traits/mergeable" path = "../../../traits/fixed-supply-token" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" diff --git a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs index f2ccc293c..7fdb6cdc3 100644 --- a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs +++ b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs @@ -1,12 +1,11 @@ multiversx_sc::imports!(); -use common_structs::{FarmToken, FarmTokenAttributes, Nonce}; +use common_structs::{FarmToken, FarmTokenAttributes, Nonce, PaymentsVec}; use config::ConfigModule; use contexts::storage_cache::StorageCache; use core::marker::PhantomData; use fixed_supply_token::FixedSupplyToken; use mergeable::Mergeable; -use multiversx_sc_modules::transfer_role_proxy::PaymentsVec; use rewards::RewardsModule; pub trait AllBaseFarmImplTraits = @@ -30,8 +29,8 @@ pub trait FarmContract { + FixedSupplyToken<::Api> + FarmToken<::Api> + From::Api>> - + Into::Api>> = - FarmTokenAttributes<::Api>; + + Into::Api>> + + ManagedVecItem = FarmTokenAttributes<::Api>; #[inline] fn mint_rewards( @@ -192,27 +191,21 @@ pub trait FarmContract { fn check_and_update_user_farm_position( sc: &Self::FarmSc, user: &ManagedAddress<::Api>, - farm_positions: &PaymentsVec<::Api>, + farm_tokens: &PaymentsVec<::Api>, + farm_attributes: &ManagedVec<::Api, Self::AttributesType>, ) { - let farm_token_mapper = sc.farm_token(); - for farm_position in farm_positions { - farm_token_mapper.require_same_token(&farm_position.token_identifier); - - if sc.is_old_farm_position(farm_position.token_nonce) { + for (attr, farm_token) in farm_attributes.into_iter().zip(farm_tokens.iter()) { + if sc.is_old_farm_position(farm_token.token_nonce) { continue; } - let token_attributes: FarmTokenAttributes<::Api> = - farm_token_mapper.get_token_attributes(farm_position.token_nonce); - - if &token_attributes.original_owner != user { - Self::decrease_user_farm_position(sc, &farm_position); - Self::increase_user_farm_position(sc, user, &farm_position.amount); + if &attr.get_original_owner() != user { + Self::decrease_user_farm_position(sc, &farm_token, &attr); + Self::increase_user_farm_position(sc, user, &farm_token.amount); } } } - #[inline] fn increase_user_farm_position( sc: &Self::FarmSc, user: &ManagedAddress<::Api>, @@ -227,16 +220,13 @@ pub trait FarmContract { fn decrease_user_farm_position( sc: &Self::FarmSc, farm_position: &EsdtTokenPayment<::Api>, + attributes: &Self::AttributesType, ) { if sc.is_old_farm_position(farm_position.token_nonce) { return; } - let farm_token_mapper = sc.farm_token(); - let token_attributes: FarmTokenAttributes<::Api> = - farm_token_mapper.get_token_attributes(farm_position.token_nonce); - - sc.user_total_farm_position(&token_attributes.original_owner) + sc.user_total_farm_position(&attributes.get_original_owner()) .update(|user_total_farm_position| { if user_total_farm_position.total_farm_position > farm_position.amount { user_total_farm_position.total_farm_position -= &farm_position.amount; diff --git a/common/modules/farm/farm_base_impl/src/claim_rewards.rs b/common/modules/farm/farm_base_impl/src/claim_rewards.rs index d9dfe293e..30b943089 100644 --- a/common/modules/farm/farm_base_impl/src/claim_rewards.rs +++ b/common/modules/farm/farm_base_impl/src/claim_rewards.rs @@ -11,7 +11,7 @@ use fixed_supply_token::FixedSupplyToken; pub struct InternalClaimRewardsResult<'a, C, T> where C: FarmContracTraitBounds, - T: Clone + TopEncode + TopDecode + NestedEncode + NestedDecode, + T: Clone + TopEncode + TopDecode + NestedEncode + NestedDecode + ManagedVecItem, { pub context: ClaimRewardsContext, pub storage_cache: StorageCache<'a, C>, @@ -81,7 +81,12 @@ pub trait BaseClaimRewardsModule: ); storage_cache.reward_reserve -= &reward; - FC::check_and_update_user_farm_position(self, &caller, &payments); + FC::check_and_update_user_farm_position( + self, + &caller, + &payments, + &claim_rewards_context.all_attributes, + ); let farm_token_mapper = self.farm_token(); let base_attributes = FC::create_claim_rewards_initial_attributes( @@ -90,10 +95,11 @@ pub trait BaseClaimRewardsModule: token_attributes, storage_cache.reward_per_share.clone(), ); + let new_token_attributes = self.merge_attributes_from_payments( base_attributes, + &claim_rewards_context.additional_attributes, &claim_rewards_context.additional_payments, - &farm_token_mapper, ); let new_farm_token = PaymentAttributesPair { payment: EsdtTokenPayment::new( diff --git a/common/modules/farm/farm_base_impl/src/compound_rewards.rs b/common/modules/farm/farm_base_impl/src/compound_rewards.rs index 06e52585c..530f732c0 100644 --- a/common/modules/farm/farm_base_impl/src/compound_rewards.rs +++ b/common/modules/farm/farm_base_impl/src/compound_rewards.rs @@ -12,7 +12,7 @@ use fixed_supply_token::FixedSupplyToken; pub struct InternalCompoundRewardsResult<'a, C, T> where C: FarmContracTraitBounds, - T: Clone + TopEncode + TopDecode + NestedEncode + NestedDecode, + T: Clone + TopEncode + TopDecode + NestedEncode + NestedDecode + ManagedVecItem, { pub context: CompoundRewardsContext, pub storage_cache: StorageCache<'a, C>, @@ -70,7 +70,12 @@ pub trait BaseCompoundRewardsModule: storage_cache.reward_reserve -= &reward; storage_cache.farm_token_supply += &reward; - FC::check_and_update_user_farm_position(self, &caller, &payments); + FC::check_and_update_user_farm_position( + self, + &caller, + &payments, + &compound_rewards_context.all_attributes, + ); let farm_token_mapper = self.farm_token(); let base_attributes = FC::create_compound_rewards_initial_attributes( @@ -82,6 +87,7 @@ pub trait BaseCompoundRewardsModule: ); let new_farm_token = self.merge_and_create_token( base_attributes, + &compound_rewards_context.additional_attributes, &compound_rewards_context.additional_payments, &farm_token_mapper, ); diff --git a/common/modules/farm/farm_base_impl/src/enter_farm.rs b/common/modules/farm/farm_base_impl/src/enter_farm.rs index 02e20d42a..850606829 100644 --- a/common/modules/farm/farm_base_impl/src/enter_farm.rs +++ b/common/modules/farm/farm_base_impl/src/enter_farm.rs @@ -10,9 +10,9 @@ use contexts::{ pub struct InternalEnterFarmResult<'a, C, T> where C: FarmContracTraitBounds, - T: Clone + TopEncode + TopDecode + NestedEncode + NestedDecode, + T: Clone + TopEncode + TopDecode + NestedEncode + NestedDecode + ManagedVecItem, { - pub context: EnterFarmContext, + pub context: EnterFarmContext, pub storage_cache: StorageCache<'a, C>, pub new_farm_token: PaymentAttributesPair, pub created_with_merge: bool, @@ -42,6 +42,7 @@ pub trait BaseEnterFarmModule: payments, &storage_cache.farming_token_id, &storage_cache.farm_token_id, + self.blockchain(), ); // The order is important - first check and update, then increase position @@ -49,6 +50,7 @@ pub trait BaseEnterFarmModule: self, &caller, &enter_farm_context.additional_farm_tokens, + &enter_farm_context.additional_attributes, ); FC::increase_user_farm_position( self, @@ -69,6 +71,7 @@ pub trait BaseEnterFarmModule: ); let new_farm_token = self.merge_and_create_token( base_attributes, + &enter_farm_context.additional_attributes, &enter_farm_context.additional_farm_tokens, &farm_token_mapper, ); diff --git a/common/modules/farm/farm_base_impl/src/exit_farm.rs b/common/modules/farm/farm_base_impl/src/exit_farm.rs index 315abe421..30d420787 100644 --- a/common/modules/farm/farm_base_impl/src/exit_farm.rs +++ b/common/modules/farm/farm_base_impl/src/exit_farm.rs @@ -62,7 +62,7 @@ pub trait BaseExitFarmModule: ); storage_cache.reward_reserve -= &reward; - FC::decrease_user_farm_position(self, &payment); + FC::decrease_user_farm_position(self, &payment, &exit_farm_context.farm_token.attributes); let farming_token_amount = token_attributes.get_total_supply(); let farming_token_payment = EsdtTokenPayment::new( diff --git a/common/modules/farm/farm_token/Cargo.toml b/common/modules/farm/farm_token/Cargo.toml index 64834bd68..d66aef7ed 100644 --- a/common/modules/farm/farm_token/Cargo.toml +++ b/common/modules/farm/farm_token/Cargo.toml @@ -26,8 +26,8 @@ path = "../../pausable" path = "../../permissions_module" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" diff --git a/common/modules/farm/farm_token_merge/Cargo.toml b/common/modules/farm/farm_token_merge/Cargo.toml index 4df9540e8..07e671721 100644 --- a/common/modules/farm/farm_token_merge/Cargo.toml +++ b/common/modules/farm/farm_token_merge/Cargo.toml @@ -23,11 +23,11 @@ path = "../../token_merge_helper" path = "../farm_token" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/common/modules/farm/rewards/Cargo.toml b/common/modules/farm/rewards/Cargo.toml index 68d37f46d..d11286d68 100644 --- a/common/modules/farm/rewards/Cargo.toml +++ b/common/modules/farm/rewards/Cargo.toml @@ -29,8 +29,8 @@ path = "../../pausable" path = "../../permissions_module" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" diff --git a/common/modules/legacy_token_decode_module/Cargo.toml b/common/modules/legacy_token_decode_module/Cargo.toml index 124b2ec02..54c96c1ca 100644 --- a/common/modules/legacy_token_decode_module/Cargo.toml +++ b/common/modules/legacy_token_decode_module/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.common_structs] diff --git a/common/modules/locking_module/Cargo.toml b/common/modules/locking_module/Cargo.toml index 660635a24..5be58100d 100644 --- a/common/modules/locking_module/Cargo.toml +++ b/common/modules/locking_module/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.simple-lock] diff --git a/common/modules/math/Cargo.toml b/common/modules/math/Cargo.toml index 5f1f99325..987f0021e 100644 --- a/common/modules/math/Cargo.toml +++ b/common/modules/math/Cargo.toml @@ -8,5 +8,5 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/pausable/Cargo.toml b/common/modules/pausable/Cargo.toml index 2f258161b..271081564 100644 --- a/common/modules/pausable/Cargo.toml +++ b/common/modules/pausable/Cargo.toml @@ -11,5 +11,5 @@ path = "src/pausable.rs" path = "../permissions_module" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/permissions_module/Cargo.toml b/common/modules/permissions_module/Cargo.toml index fdc8d7d2e..85d7e9b3c 100644 --- a/common/modules/permissions_module/Cargo.toml +++ b/common/modules/permissions_module/Cargo.toml @@ -17,5 +17,5 @@ bitflags = "2.4.1" path = "../../common_errors" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/sc_whitelist_module/Cargo.toml b/common/modules/sc_whitelist_module/Cargo.toml index 978cd6a89..1c0fdd874 100644 --- a/common/modules/sc_whitelist_module/Cargo.toml +++ b/common/modules/sc_whitelist_module/Cargo.toml @@ -11,5 +11,5 @@ path = "src/sc_whitelist_module.rs" path = "../../common_errors" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/token_merge_helper/Cargo.toml b/common/modules/token_merge_helper/Cargo.toml index c337a5996..216bf3ebf 100644 --- a/common/modules/token_merge_helper/Cargo.toml +++ b/common/modules/token_merge_helper/Cargo.toml @@ -11,5 +11,5 @@ path = "src/lib.rs" path = "../../common_errors" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/token_send/Cargo.toml b/common/modules/token_send/Cargo.toml index 28b005064..17b83882c 100644 --- a/common/modules/token_send/Cargo.toml +++ b/common/modules/token_send/Cargo.toml @@ -14,5 +14,5 @@ path = "../../common_structs" path = "../../common_errors" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/utils/Cargo.toml b/common/modules/utils/Cargo.toml index a18635d6e..c17c30212 100644 --- a/common/modules/utils/Cargo.toml +++ b/common/modules/utils/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.common_structs] diff --git a/common/modules/utils/src/lib.rs b/common/modules/utils/src/lib.rs index 990b88329..9077b7203 100644 --- a/common/modules/utils/src/lib.rs +++ b/common/modules/utils/src/lib.rs @@ -57,7 +57,7 @@ pub trait UtilsModule { } fn merge_from_payments_and_burn< - T: FixedSupplyToken + Mergeable + TopDecode, + T: FixedSupplyToken + Mergeable + TopDecode + ManagedVecItem, >( &self, mut payments: PaymentsVec, @@ -68,23 +68,29 @@ pub trait UtilsModule { self.get_attributes_as_part_of_fixed_supply(&first_payment, mapper); mapper.nft_burn(first_payment.token_nonce, &first_payment.amount); + let mut other_attributes = ManagedVec::new(); + for payment in &payments { + let attr = mapper.get_token_attributes(payment.token_nonce); + other_attributes.push(attr); + } + let output_attributes = - self.merge_attributes_from_payments(base_attributes, &payments, mapper); + self.merge_attributes_from_payments(base_attributes, &other_attributes, &payments); self.send().esdt_local_burn_multi(&payments); output_attributes } fn merge_attributes_from_payments< - T: FixedSupplyToken + Mergeable + TopDecode, + T: FixedSupplyToken + Mergeable + TopDecode + ManagedVecItem, >( &self, mut base_attributes: T, + other_attributes: &ManagedVec, payments: &PaymentsVec, - mapper: &NonFungibleTokenMapper, ) -> T { - for payment in payments { - let attributes: T = self.get_attributes_as_part_of_fixed_supply(&payment, mapper); + for (attr, payment) in other_attributes.into_iter().zip(payments.iter()) { + let attributes = attr.into_part(&payment.amount); base_attributes.merge_with(attributes); } @@ -98,15 +104,17 @@ pub trait UtilsModule { + TopEncode + TopDecode + NestedEncode - + NestedDecode, + + NestedDecode + + ManagedVecItem, >( &self, base_attributes: T, + other_attributes: &ManagedVec, payments: &PaymentsVec, mapper: &NonFungibleTokenMapper, ) -> PaymentAttributesPair { let output_attributes = - self.merge_attributes_from_payments(base_attributes, payments, mapper); + self.merge_attributes_from_payments(base_attributes, other_attributes, payments); let new_token_amount = output_attributes.get_total_supply(); let new_token_payment = mapper.nft_create(new_token_amount, &output_attributes); diff --git a/common/traits/fixed-supply-token/Cargo.toml b/common/traits/fixed-supply-token/Cargo.toml index eafd9fe32..bc26dc17d 100644 --- a/common/traits/fixed-supply-token/Cargo.toml +++ b/common/traits/fixed-supply-token/Cargo.toml @@ -8,4 +8,4 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" diff --git a/common/traits/mergeable/Cargo.toml b/common/traits/mergeable/Cargo.toml index 4800de5ca..d0e86244d 100644 --- a/common/traits/mergeable/Cargo.toml +++ b/common/traits/mergeable/Cargo.toml @@ -8,5 +8,5 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/traits/unwrappable/Cargo.toml b/common/traits/unwrappable/Cargo.toml index 9ba6e7e73..fd10b42e4 100644 --- a/common/traits/unwrappable/Cargo.toml +++ b/common/traits/unwrappable/Cargo.toml @@ -8,5 +8,5 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] diff --git a/dex/Cargo.toml b/dex/Cargo.toml index 62d9161bf..7b517a030 100644 --- a/dex/Cargo.toml +++ b/dex/Cargo.toml @@ -5,17 +5,17 @@ edition = "2021" publish = false [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" [dev-dependencies.config] path = "../common/modules/farm/config" diff --git a/dex/farm-with-locked-rewards/Cargo.toml b/dex/farm-with-locked-rewards/Cargo.toml index c19480688..4471c010d 100644 --- a/dex/farm-with-locked-rewards/Cargo.toml +++ b/dex/farm-with-locked-rewards/Cargo.toml @@ -75,17 +75,17 @@ path = "../../locked-asset/energy-factory" path = "../../energy-integration/common-modules/energy-query" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" [dev-dependencies.simple-lock] path = "../../locked-asset/simple-lock" diff --git a/dex/farm-with-locked-rewards/meta/Cargo.toml b/dex/farm-with-locked-rewards/meta/Cargo.toml index 47476c339..453251275 100644 --- a/dex/farm-with-locked-rewards/meta/Cargo.toml +++ b/dex/farm-with-locked-rewards/meta/Cargo.toml @@ -9,5 +9,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/dex/farm-with-locked-rewards/src/lib.rs b/dex/farm-with-locked-rewards/src/lib.rs index e7fd871c4..34600f80b 100644 --- a/dex/farm-with-locked-rewards/src/lib.rs +++ b/dex/farm-with-locked-rewards/src/lib.rs @@ -8,6 +8,7 @@ multiversx_sc::derive_imports!(); use common_structs::FarmTokenAttributes; use contexts::storage_cache::StorageCache; use core::marker::PhantomData; +use fixed_supply_token::FixedSupplyToken; use farm::{ base_functions::{BaseFunctionsModule, ClaimRewardsResultType, DoubleMultiPayment, Wrapper}, @@ -81,7 +82,7 @@ pub trait Farm: self.try_set_farm_position_migration_nonce(farm_token_mapper); } - #[endpoint] + #[upgrade] fn upgrade(&self) { let current_epoch = self.blockchain().get_block_epoch(); self.first_week_start_epoch().set_if_empty(current_epoch); @@ -181,8 +182,6 @@ pub trait Farm: orig_caller.clone(), ); - self.clear_user_energy_if_needed(&orig_caller); - (exit_farm_result.farming_tokens, locked_rewards_payment).into() } @@ -198,7 +197,7 @@ pub trait Farm: self.migrate_old_farm_positions(&orig_caller); let boosted_rewards = self.claim_only_boosted_payment(&orig_caller); - let merged_farm_token = self.merge_farm_tokens::>(); + let merged_farm_token = self.merge_and_update_farm_tokens(orig_caller.clone()); self.send_payment_non_zero(&caller, &merged_farm_token); let locked_rewards_payment = self.send_to_lock_contract_non_zero( @@ -211,6 +210,16 @@ pub trait Farm: (merged_farm_token, locked_rewards_payment).into() } + fn merge_and_update_farm_tokens(&self, orig_caller: ManagedAddress) -> EsdtTokenPayment { + let mut output_attributes = + self.merge_and_return_attributes::>(&orig_caller); + output_attributes.original_owner = orig_caller; + + let new_token_amount = output_attributes.get_total_supply(); + self.farm_token() + .nft_create(new_token_amount, &output_attributes) + } + #[endpoint(claimBoostedRewards)] fn claim_boosted_rewards( &self, diff --git a/dex/farm-with-locked-rewards/wasm/Cargo.lock b/dex/farm-with-locked-rewards/wasm/Cargo.lock index f3af20c87..04273a9ea 100644 --- a/dex/farm-with-locked-rewards/wasm/Cargo.lock +++ b/dex/farm-with-locked-rewards/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common-types" @@ -315,9 +315,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -328,9 +328,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -338,9 +338,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -350,9 +350,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -363,18 +363,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -432,9 +432,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/dex/farm-with-locked-rewards/wasm/Cargo.toml b/dex/farm-with-locked-rewards/wasm/Cargo.toml index 369d8346f..701179e7f 100644 --- a/dex/farm-with-locked-rewards/wasm/Cargo.toml +++ b/dex/farm-with-locked-rewards/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/dex/farm/Cargo.toml b/dex/farm/Cargo.toml index 517a35cae..8563b6fa5 100644 --- a/dex/farm/Cargo.toml +++ b/dex/farm/Cargo.toml @@ -69,11 +69,11 @@ path = "../../energy-integration/common-modules/weekly-rewards-splitting" path = "../../energy-integration/common-modules/energy-query" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" [dev-dependencies] num-bigint = "0.4.2" @@ -82,7 +82,7 @@ num-bigint = "0.4.2" path = "../../energy-integration/energy-update" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" [dev-dependencies.energy-factory-mock] path = "../../energy-integration/energy-factory-mock" diff --git a/dex/farm/meta/Cargo.toml b/dex/farm/meta/Cargo.toml index d6abd09e7..28f681018 100644 --- a/dex/farm/meta/Cargo.toml +++ b/dex/farm/meta/Cargo.toml @@ -9,5 +9,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/dex/farm/src/base_functions.rs b/dex/farm/src/base_functions.rs index 76ce024c9..16704331d 100644 --- a/dex/farm/src/base_functions.rs +++ b/dex/farm/src/base_functions.rs @@ -7,11 +7,12 @@ multiversx_sc::derive_imports!(); use core::marker::PhantomData; use common_errors::ERROR_ZERO_AMOUNT; +use common_structs::FarmToken; use common_structs::FarmTokenAttributes; +use common_structs::PaymentsVec; use contexts::storage_cache::StorageCache; use farm_base_impl::base_traits_impl::{DefaultFarmWrapper, FarmContract}; -use fixed_supply_token::FixedSupplyToken; use crate::{exit_penalty, MAX_PERCENT}; @@ -82,6 +83,11 @@ pub trait BaseFunctionsModule: &base_enter_farm_result.storage_cache.farm_token_supply, ); + self.delete_user_energy_if_needed::( + &base_enter_farm_result.context.additional_farm_tokens, + &base_enter_farm_result.context.additional_attributes, + ); + self.emit_enter_farm_event( &caller, base_enter_farm_result.context.farming_token_payment, @@ -98,7 +104,8 @@ pub trait BaseFunctionsModule: caller: ManagedAddress, ) -> ClaimRewardsResultWrapper { let payments = self.call_value().all_esdt_transfers().clone_value(); - let base_claim_rewards_result = self.claim_rewards_base::(caller.clone(), payments); + let base_claim_rewards_result = + self.claim_rewards_base::(caller.clone(), payments.clone()); let output_farm_token_payment = base_claim_rewards_result.new_farm_token.payment.clone(); let rewards_payment = base_claim_rewards_result.rewards; @@ -107,6 +114,11 @@ pub trait BaseFunctionsModule: &base_claim_rewards_result.storage_cache.farm_token_supply, ); + self.delete_user_energy_if_needed::( + &payments, + &base_claim_rewards_result.context.all_attributes, + ); + self.emit_claim_rewards_event( &caller, base_claim_rewards_result.context, @@ -128,7 +140,7 @@ pub trait BaseFunctionsModule: ) -> EsdtTokenPayment { let payments = self.call_value().all_esdt_transfers().clone_value(); let base_compound_rewards_result = - self.compound_rewards_base::(caller.clone(), payments); + self.compound_rewards_base::(caller.clone(), payments.clone()); let output_farm_token_payment = base_compound_rewards_result.new_farm_token.payment.clone(); @@ -136,6 +148,11 @@ pub trait BaseFunctionsModule: &base_compound_rewards_result.storage_cache.farm_token_supply, ); + self.delete_user_energy_if_needed::( + &payments, + &base_compound_rewards_result.context.all_attributes, + ); + self.emit_compound_rewards_event( &caller, base_compound_rewards_result.context, @@ -153,7 +170,7 @@ pub trait BaseFunctionsModule: caller: ManagedAddress, payment: EsdtTokenPayment, ) -> ExitFarmResultWrapper { - let base_exit_farm_result = self.exit_farm_base::(caller.clone(), payment); + let base_exit_farm_result = self.exit_farm_base::(caller.clone(), payment.clone()); let mut farming_token_payment = base_exit_farm_result.farming_token_payment; let reward_payment = base_exit_farm_result.reward_payment; @@ -162,6 +179,13 @@ pub trait BaseFunctionsModule: &base_exit_farm_result.storage_cache.farm_token_supply, ); + self.delete_user_energy_if_needed::( + &ManagedVec::from_single_item(payment), + &ManagedVec::from_single_item( + base_exit_farm_result.context.farm_token.attributes.clone(), + ), + ); + FC::apply_penalty( self, &mut farming_token_payment.amount, @@ -183,18 +207,26 @@ pub trait BaseFunctionsModule: } } - fn merge_farm_tokens>(&self) -> EsdtTokenPayment { + fn merge_and_return_attributes>( + &self, + orig_caller: &ManagedAddress, + ) -> FC::AttributesType { let payments = self.get_non_empty_payments(); let token_mapper = self.farm_token(); - token_mapper.require_all_same_token(&payments); - let caller = self.blockchain().get_caller(); - FC::check_and_update_user_farm_position(self, &caller, &payments); + let mut all_attributes = ManagedVec::new(); + for payment in &payments { + token_mapper.require_same_token(&payment.token_identifier); + + let attr = token_mapper.get_token_attributes(payment.token_nonce); + all_attributes.push(attr); + } - let output_attributes: FC::AttributesType = - self.merge_from_payments_and_burn(payments, &token_mapper); - let new_token_amount = output_attributes.get_total_supply(); - token_mapper.nft_create(new_token_amount, &output_attributes) + self.delete_user_energy_if_needed::(&payments, &all_attributes); + + FC::check_and_update_user_farm_position(self, orig_caller, &payments, &all_attributes); + + self.merge_from_payments_and_burn(payments, &token_mapper) } fn claim_only_boosted_payment(&self, caller: &ManagedAddress) -> BigUint { @@ -255,6 +287,26 @@ pub trait BaseFunctionsModule: self.per_block_reward_amount().set(&per_block_amount); } + fn delete_user_energy_if_needed>( + &self, + payments: &PaymentsVec, + all_attributes: &ManagedVec, + ) { + let mut processed_users = ManagedMap::new(); + for (payment, attr) in payments.iter().zip(all_attributes.into_iter()) { + let original_owner = attr.get_original_owner(); + if processed_users.contains(original_owner.as_managed_buffer()) + || self.is_old_farm_position(payment.token_nonce) + { + continue; + } + + self.clear_user_energy_if_needed(&original_owner); + + processed_users.put(original_owner.as_managed_buffer(), &ManagedBuffer::new()); + } + } + fn require_queried(&self) { let caller = self.blockchain().get_caller(); let sc_address = self.blockchain().get_sc_address(); diff --git a/dex/farm/src/lib.rs b/dex/farm/src/lib.rs index 0afc41c62..5bf5dba64 100644 --- a/dex/farm/src/lib.rs +++ b/dex/farm/src/lib.rs @@ -16,6 +16,7 @@ use exit_penalty::{ DEFAULT_BURN_GAS_LIMIT, DEFAULT_MINUMUM_FARMING_EPOCHS, DEFAULT_PENALTY_PERCENT, }; use farm_base_impl::base_traits_impl::FarmContract; +use fixed_supply_token::FixedSupplyToken; pub type EnterFarmResultType = DoubleMultiPayment; pub type ExitFarmWithPartialPosResultType = DoubleMultiPayment; @@ -84,7 +85,7 @@ pub trait Farm: self.try_set_farm_position_migration_nonce(farm_token_mapper); } - #[endpoint] + #[upgrade] fn upgrade(&self) { let current_epoch = self.blockchain().get_block_epoch(); self.first_week_start_epoch().set_if_empty(current_epoch); @@ -176,8 +177,6 @@ pub trait Farm: self.send_payment_non_zero(&caller, &exit_farm_result.farming_tokens); self.send_payment_non_zero(&caller, &exit_farm_result.rewards); - self.clear_user_energy_if_needed(&orig_caller); - (exit_farm_result.farming_tokens, exit_farm_result.rewards).into() } @@ -195,13 +194,23 @@ pub trait Farm: let boosted_rewards_payment = EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards); - let merged_farm_token = self.merge_farm_tokens::>(); + let merged_farm_token = self.merge_and_update_farm_tokens(orig_caller); + self.send_payment_non_zero(&caller, &merged_farm_token); self.send_payment_non_zero(&caller, &boosted_rewards_payment); (merged_farm_token, boosted_rewards_payment).into() } + fn merge_and_update_farm_tokens(&self, orig_caller: ManagedAddress) -> EsdtTokenPayment { + let mut output_attributes = self.merge_and_return_attributes::>(&orig_caller); + output_attributes.original_owner = orig_caller; + + let new_token_amount = output_attributes.get_total_supply(); + self.farm_token() + .nft_create(new_token_amount, &output_attributes) + } + #[endpoint(claimBoostedRewards)] fn claim_boosted_rewards( &self, diff --git a/dex/farm/tests/energy_update_test.rs b/dex/farm/tests/energy_update_test.rs index 1d8f78a98..e091a028e 100644 --- a/dex/farm/tests/energy_update_test.rs +++ b/dex/farm/tests/energy_update_test.rs @@ -2,7 +2,14 @@ mod farm_setup; +use common_structs::FarmTokenAttributes; +use farm::Farm; use farm_setup::multi_user_farm_setup::*; +use multiversx_sc::imports::OptionalValue; +use multiversx_sc_scenario::{ + managed_biguint, rust_biguint, whitebox_legacy::TxTokenTransfer, DebugApi, +}; +use weekly_rewards_splitting::global_info::WeeklyRewardsGlobalInfo; #[test] fn test_farm_setup() { @@ -53,3 +60,129 @@ fn test_energy_update_no_claim_current_week() { farm_setup.update_energy_for_user(); farm_setup.check_farm_claim_progress_energy(0); } + +#[test] +fn enter_farm_other_users_pos_test() { + DebugApi::dummy(); + + let mut farm_setup = MultiUserFarmSetup::new( + farm::contract_obj, + energy_factory_mock::contract_obj, + energy_update::contract_obj, + ); + + let first_farm_token_amount = 100_000_000; + let first_user = farm_setup.first_user.clone(); + let second_user = farm_setup.second_user.clone(); + + let first_user_energy_amount = 1_000; + let second_user_energy_amount = 5_000; + farm_setup.set_user_energy(&first_user, first_user_energy_amount, 13, 1); + farm_setup.set_user_energy(&second_user, second_user_energy_amount, 13, 1); + + farm_setup.enter_farm(&first_user, first_farm_token_amount); + + let token_attributes: FarmTokenAttributes = farm_setup + .b_mock + .get_nft_attributes(&first_user, FARM_TOKEN_ID, 1) + .unwrap(); + + // first user transfer pos to second user + farm_setup.b_mock.set_nft_balance( + &second_user, + FARM_TOKEN_ID, + 1, + &rust_biguint!(first_farm_token_amount), + &token_attributes, + ); + farm_setup.b_mock.set_nft_balance( + &first_user, + FARM_TOKEN_ID, + 1, + &rust_biguint!(0), + &token_attributes, + ); + + let transfers = [ + TxTokenTransfer { + token_identifier: FARMING_TOKEN_ID.to_vec(), + nonce: 0, + value: rust_biguint!(1_000), + }, + TxTokenTransfer { + token_identifier: FARM_TOKEN_ID.to_vec(), + nonce: 1, + value: rust_biguint!(first_farm_token_amount), + }, + ]; + + farm_setup + .b_mock + .execute_esdt_multi_transfer(&second_user, &farm_setup.farm_wrapper, &transfers, |sc| { + sc.enter_farm_endpoint(OptionalValue::None); + + let actual_energy = sc.total_energy_for_week(1).get(); + assert_eq!(actual_energy, managed_biguint!(second_user_energy_amount)); + }) + .assert_ok(); +} + +#[test] +fn exit_other_users_pos_test() { + DebugApi::dummy(); + + let mut farm_setup = MultiUserFarmSetup::new( + farm::contract_obj, + energy_factory_mock::contract_obj, + energy_update::contract_obj, + ); + + let first_farm_token_amount = 100_000_000; + let first_user = farm_setup.first_user.clone(); + let second_user = farm_setup.second_user.clone(); + + let first_user_energy_amount = 1_000; + let second_user_energy_amount = 200; + farm_setup.set_user_energy(&first_user, first_user_energy_amount, 13, 1); + farm_setup.set_user_energy(&second_user, second_user_energy_amount, 13, 1); + + farm_setup.enter_farm(&first_user, first_farm_token_amount); + + let token_attributes: FarmTokenAttributes = farm_setup + .b_mock + .get_nft_attributes(&first_user, FARM_TOKEN_ID, 1) + .unwrap(); + + // first user transfer pos to second user + farm_setup.b_mock.set_nft_balance( + &second_user, + FARM_TOKEN_ID, + 1, + &rust_biguint!(first_farm_token_amount), + &token_attributes, + ); + farm_setup.b_mock.set_nft_balance( + &first_user, + FARM_TOKEN_ID, + 1, + &rust_biguint!(0), + &token_attributes, + ); + + farm_setup + .b_mock + .execute_esdt_transfer( + &second_user, + &farm_setup.farm_wrapper, + FARM_TOKEN_ID, + 1, + &rust_biguint!(first_farm_token_amount), + |sc| { + sc.exit_farm_endpoint(OptionalValue::None); + + let actual_energy = sc.total_energy_for_week(1).get(); + assert_eq!(actual_energy, managed_biguint!(0)); + }, + ) + .assert_ok(); +} diff --git a/dex/farm/tests/farm_setup/multi_user_farm_setup.rs b/dex/farm/tests/farm_setup/multi_user_farm_setup.rs index 2e74ab42c..60a82cea2 100644 --- a/dex/farm/tests/farm_setup/multi_user_farm_setup.rs +++ b/dex/farm/tests/farm_setup/multi_user_farm_setup.rs @@ -33,6 +33,7 @@ pub static FARM_TOKEN_ID: &[u8] = b"FARM-123456"; pub const DIV_SAFETY: u64 = 1_000_000_000_000; pub const PER_BLOCK_REWARD_AMOUNT: u64 = 1_000; pub const FARMING_TOKEN_BALANCE: u64 = 200_000_000; +pub const MAX_PERCENTAGE: u64 = 10_000; // 100% pub const BOOSTED_YIELDS_PERCENTAGE: u64 = 2_500; // 25% pub const MAX_REWARDS_FACTOR: u64 = 10; pub const USER_REWARDS_ENERGY_CONST: u64 = 3; @@ -48,6 +49,11 @@ pub struct RawFarmTokenAttributes { pub original_owner_bytes: [u8; 32], } +pub struct NonceAmountPair { + pub nonce: u64, + pub amount: u64, +} + pub struct MultiUserFarmSetup where FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, @@ -310,28 +316,18 @@ where result } - pub fn merge_farm_tokens( - &mut self, - user: &Address, - first_token_nonce: u64, - first_token_amount: u64, - second_token_nonce: u64, - second_token_amount: u64, - ) { + pub fn merge_farm_tokens(&mut self, user: &Address, farm_tokens: Vec) { self.last_farm_token_nonce += 1; - let expected_farm_token_nonce = self.last_farm_token_nonce; - let expected_farm_token_amount = first_token_amount + second_token_amount; + let mut expected_farm_token_amount = 0; let mut payments = Vec::new(); - payments.push(TxTokenTransfer { - token_identifier: FARM_TOKEN_ID.to_vec(), - nonce: first_token_nonce, - value: rust_biguint!(first_token_amount), - }); - payments.push(TxTokenTransfer { - token_identifier: FARM_TOKEN_ID.to_vec(), - nonce: second_token_nonce, - value: rust_biguint!(second_token_amount), - }); + for farm_token in farm_tokens { + expected_farm_token_amount += farm_token.amount; + payments.push(TxTokenTransfer { + token_identifier: FARM_TOKEN_ID.to_vec(), + nonce: farm_token.nonce, + value: rust_biguint!(farm_token.amount), + }); + } self.b_mock .execute_esdt_multi_transfer(user, &self.farm_wrapper, &payments, |sc| { @@ -342,7 +338,7 @@ where out_farm_token.token_identifier, managed_token_id!(FARM_TOKEN_ID) ); - assert_eq!(out_farm_token.token_nonce, expected_farm_token_nonce); + assert_eq!(out_farm_token.token_nonce, self.last_farm_token_nonce); assert_eq!( out_farm_token.amount, managed_biguint!(expected_farm_token_amount) @@ -451,6 +447,54 @@ where result } + pub fn claim_rewards_with_multiple_payments( + &mut self, + user: &Address, + farm_token_payments: Vec, + ) -> u64 { + self.last_farm_token_nonce += 1; + + let mut expected_farm_token_amount = 0; + let mut payments = vec![]; + + for farm_token_payment in farm_token_payments { + expected_farm_token_amount += farm_token_payment.amount; + payments.push(TxTokenTransfer { + token_identifier: FARM_TOKEN_ID.to_vec(), + nonce: farm_token_payment.nonce, + value: rust_biguint!(farm_token_payment.amount), + }); + } + + let expected_farm_token_nonce = self.last_farm_token_nonce; + let mut result = 0; + self.b_mock + .execute_esdt_multi_transfer(user, &self.farm_wrapper, &payments, |sc| { + let (out_farm_token, out_reward_token) = + sc.claim_rewards_endpoint(OptionalValue::None).into_tuple(); + assert_eq!( + out_farm_token.token_identifier, + managed_token_id!(FARM_TOKEN_ID) + ); + assert_eq!(out_farm_token.token_nonce, expected_farm_token_nonce); + assert_eq!( + out_farm_token.amount, + managed_biguint!(expected_farm_token_amount) + ); + + assert_eq!( + out_reward_token.token_identifier, + managed_token_id!(REWARD_TOKEN_ID) + ); + assert_eq!(out_reward_token.token_nonce, 0); + + result = out_reward_token.amount.to_u64().unwrap(); + }) + .assert_ok(); + + result + } + pub fn claim_boosted_rewards_for_user(&mut self, owner: &Address, broker: &Address) -> u64 { self.last_farm_token_nonce += 1; @@ -691,4 +735,89 @@ where }) .assert_ok(); } + + // With the current checks, works only on full position sent (amount/nonce) + pub fn send_farm_position( + &mut self, + sender: &Address, + receiver: &Address, + nonce: u64, + amount: u64, + attr_reward_per_share: u64, + attr_entering_epoch: u64, + ) { + self.b_mock.check_nft_balance( + sender, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(amount), + Some(&FarmTokenAttributes:: { + reward_per_share: managed_biguint!(attr_reward_per_share), + entering_epoch: attr_entering_epoch, + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(amount), + original_owner: managed_address!(&sender), + }), + ); + + self.b_mock + .check_nft_balance::>( + receiver, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(0), + None, + ); + + self.b_mock.set_nft_balance( + sender, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(0), + &FarmTokenAttributes:: { + reward_per_share: managed_biguint!(attr_reward_per_share), + entering_epoch: attr_entering_epoch, + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(amount), + original_owner: managed_address!(&sender), + }, + ); + + self.b_mock.set_nft_balance( + receiver, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(amount), + &FarmTokenAttributes:: { + reward_per_share: managed_biguint!(attr_reward_per_share), + entering_epoch: attr_entering_epoch, + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(amount), + original_owner: managed_address!(&sender), + }, + ); + + self.b_mock + .check_nft_balance::>( + sender, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(0), + None, + ); + + self.b_mock.check_nft_balance( + receiver, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(amount), + Some(&FarmTokenAttributes:: { + reward_per_share: managed_biguint!(attr_reward_per_share), + entering_epoch: attr_entering_epoch, + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(amount), + original_owner: managed_address!(&sender), + }), + ); + } } diff --git a/dex/farm/tests/total_farm_position_test.rs b/dex/farm/tests/total_farm_position_test.rs index 26756ebaa..b7ca1be7b 100644 --- a/dex/farm/tests/total_farm_position_test.rs +++ b/dex/farm/tests/total_farm_position_test.rs @@ -4,10 +4,17 @@ mod farm_setup; use common_structs::FarmTokenAttributes; use config::ConfigModule; -use farm_setup::multi_user_farm_setup::{MultiUserFarmSetup, BOOSTED_YIELDS_PERCENTAGE}; -use multiversx_sc_scenario::{managed_address, managed_biguint, rust_biguint, DebugApi}; - -use crate::farm_setup::multi_user_farm_setup::{FARM_TOKEN_ID, REWARD_TOKEN_ID}; +use farm_setup::multi_user_farm_setup::{ + MultiUserFarmSetup, NonceAmountPair, BOOSTED_YIELDS_PERCENTAGE, MAX_PERCENTAGE, + PER_BLOCK_REWARD_AMOUNT, +}; +use multiversx_sc::types::EsdtLocalRole; +use multiversx_sc_scenario::{ + managed_address, managed_biguint, managed_token_id, rust_biguint, DebugApi, +}; +use sc_whitelist_module::SCWhitelistModule; + +use crate::farm_setup::multi_user_farm_setup::{FARMING_TOKEN_ID, FARM_TOKEN_ID, REWARD_TOKEN_ID}; #[test] fn total_farm_position_claim_test() { @@ -480,6 +487,189 @@ fn farm_total_position_exit_migration_test() { ); } +#[test] +fn farm_total_position_on_claim_migration_test() { + DebugApi::dummy(); + let mut farm_setup = MultiUserFarmSetup::new( + farm::contract_obj, + energy_factory_mock::contract_obj, + energy_update::contract_obj, + ); + + farm_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + farm_setup.set_boosted_yields_factors(); + farm_setup.b_mock.set_block_epoch(2); + + // first user enter farm + let farm_in_amount = 50_000_000; + let first_user = farm_setup.first_user.clone(); + farm_setup.enter_farm(&first_user, farm_in_amount); + + // Remove current farm position from storage + farm_setup.set_user_total_farm_position(&first_user, 0); + farm_setup.check_user_total_farm_position(&first_user, 0); + + // User enters farm again + farm_setup.enter_farm(&first_user, farm_in_amount); + farm_setup.check_user_total_farm_position(&first_user, farm_in_amount); + + // Set farm position migration nonce + farm_setup + .b_mock + .execute_tx( + &farm_setup.owner, + &farm_setup.farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.farm_position_migration_nonce().set(2); + }, + ) + .assert_ok(); + + farm_setup.check_farm_token_supply(farm_in_amount * 2); + + // claim rewards with both positions + let first_payment_amount = farm_in_amount / 2; + let second_payment_amount = farm_in_amount / 4 * 3; + let total_farm_amount = farm_in_amount * 2; + let total_farm_position = farm_in_amount + first_payment_amount; // only the first is migrated by being an old position + let total_claim_payment = first_payment_amount + second_payment_amount; + + let payments = vec![ + NonceAmountPair { + nonce: 1, + amount: first_payment_amount, + }, + NonceAmountPair { + nonce: 2, + amount: second_payment_amount, + }, + ]; + + let block_nonce = 10; + farm_setup.b_mock.set_block_nonce(block_nonce); + + farm_setup.check_user_total_farm_position(&first_user, farm_in_amount); + let _ = farm_setup.claim_rewards_with_multiple_payments(&first_user, payments); + farm_setup.check_user_total_farm_position(&first_user, total_farm_position); + + farm_setup + .b_mock + .check_nft_balance::>( + &first_user, + FARM_TOKEN_ID, + 3, + &rust_biguint!(total_claim_payment), + None, + ); + + // User receives rewards only for the new position + let expected_user_rewards = block_nonce + * PER_BLOCK_REWARD_AMOUNT + * (MAX_PERCENTAGE - BOOSTED_YIELDS_PERCENTAGE) + * first_payment_amount + / total_farm_amount + / MAX_PERCENTAGE; + farm_setup.b_mock.check_esdt_balance( + &first_user, + REWARD_TOKEN_ID, + &rust_biguint!(expected_user_rewards), + ); +} + +#[test] +fn farm_total_position_on_merge_migration_test() { + DebugApi::dummy(); + let mut farm_setup = MultiUserFarmSetup::new( + farm::contract_obj, + energy_factory_mock::contract_obj, + energy_update::contract_obj, + ); + + farm_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + farm_setup.set_boosted_yields_factors(); + farm_setup.b_mock.set_block_epoch(2); + + // user has 2 old farm position + let farm_in_amount = 25_000_000; + let first_user = farm_setup.first_user.clone(); + farm_setup.enter_farm(&first_user, farm_in_amount); + farm_setup.enter_farm(&first_user, farm_in_amount); + + // Remove current farm position from storage + farm_setup.set_user_total_farm_position(&first_user, 0); + farm_setup.check_user_total_farm_position(&first_user, 0); + + // User enters farm again, with 2 new positions + farm_setup.enter_farm(&first_user, farm_in_amount); + farm_setup.enter_farm(&first_user, farm_in_amount); + farm_setup.check_user_total_farm_position(&first_user, farm_in_amount * 2); + + // Set farm position migration nonce + farm_setup + .b_mock + .execute_tx( + &farm_setup.owner, + &farm_setup.farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.farm_position_migration_nonce().set(3); + }, + ) + .assert_ok(); + + let total_farm_tokens = farm_in_amount * 4; + farm_setup.check_farm_token_supply(total_farm_tokens); + + // merge all 4 farm positions + let first_payment_amount = farm_in_amount / 2; + let second_payment_amount = farm_in_amount / 4 * 3; + let third_payment_amount = farm_in_amount / 2; + let forth_payment_amount = farm_in_amount / 4; + let total_payment_amount = + first_payment_amount + second_payment_amount + third_payment_amount + forth_payment_amount; + let total_user_position = farm_in_amount * 2 + first_payment_amount + second_payment_amount; + let payments = vec![ + NonceAmountPair { + nonce: 1, + amount: first_payment_amount, + }, + NonceAmountPair { + nonce: 2, + amount: second_payment_amount, + }, + NonceAmountPair { + nonce: 3, + amount: third_payment_amount, + }, + NonceAmountPair { + nonce: 4, + amount: forth_payment_amount, + }, + ]; + + let block_nonce = 10; + farm_setup.b_mock.set_block_nonce(block_nonce); + + farm_setup.check_user_total_farm_position(&first_user, farm_in_amount * 2); // last 2 positions + farm_setup.merge_farm_tokens(&first_user, payments); + farm_setup.check_user_total_farm_position(&first_user, total_user_position); + + farm_setup + .b_mock + .check_nft_balance::>( + &first_user, + FARM_TOKEN_ID, + 5, + &rust_biguint!(total_payment_amount), + None, + ); + + farm_setup + .b_mock + .check_esdt_balance(&first_user, REWARD_TOKEN_ID, &rust_biguint!(0)); +} + #[test] fn no_boosted_rewards_penalty_for_no_energy_test() { DebugApi::dummy(); @@ -560,3 +750,446 @@ fn no_boosted_rewards_penalty_for_no_energy_test() { &rust_biguint!(first_receveived_reward_amt), ); } + +#[test] +fn total_farm_position_owner_change_test() { + DebugApi::dummy(); + let mut farm_setup = MultiUserFarmSetup::new( + farm::contract_obj, + energy_factory_mock::contract_obj, + energy_update::contract_obj, + ); + + farm_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + farm_setup.set_boosted_yields_factors(); + farm_setup.b_mock.set_block_epoch(2); + + // first user enters farm 6 times + let farm_token_amount = 10_000_000; + let half_token_amount = farm_token_amount / 2; + let first_user = farm_setup.first_user.clone(); + let second_user = farm_setup.second_user.clone(); + let third_user = farm_setup.third_user.clone(); + + farm_setup.set_user_energy(&first_user, 1_000, 2, 1); + farm_setup.enter_farm(&first_user, farm_token_amount); + farm_setup.enter_farm(&first_user, farm_token_amount); + farm_setup.enter_farm(&first_user, farm_token_amount); + farm_setup.enter_farm(&first_user, farm_token_amount); + farm_setup.enter_farm(&first_user, farm_token_amount); + farm_setup.enter_farm(&first_user, farm_token_amount); + + let mut first_user_total_position = farm_token_amount * 6; + let mut second_user_total_position = 0; + farm_setup.check_user_total_farm_position(&first_user, first_user_total_position); + farm_setup.check_user_total_farm_position(&second_user, second_user_total_position); + + assert_eq!(farm_setup.last_farm_token_nonce, 6); + + // First user transfers 5 position to second user + farm_setup.send_farm_position(&first_user, &second_user, 1, farm_token_amount, 0, 2); + farm_setup.send_farm_position(&first_user, &second_user, 2, farm_token_amount, 0, 2); + farm_setup.send_farm_position(&first_user, &second_user, 3, farm_token_amount, 0, 2); + farm_setup.send_farm_position(&first_user, &second_user, 4, farm_token_amount, 0, 2); + farm_setup.send_farm_position(&first_user, &second_user, 5, farm_token_amount, 0, 2); + + // Total farm position unchanged as users only transfered the farm positions + farm_setup.check_user_total_farm_position(&first_user, first_user_total_position); + farm_setup.check_user_total_farm_position(&second_user, second_user_total_position); + + // second user enter farm with LP token + 50% the position from another user + farm_setup.set_user_energy(&second_user, 4_000, 2, 1); + farm_setup.enter_farm_with_additional_payment( + &second_user, + farm_token_amount, + 1, + half_token_amount, + ); + + // 1 half farm position was removed from first user and added to the second user (who entered the farm with a position of his own) + first_user_total_position -= half_token_amount; + second_user_total_position += farm_token_amount + half_token_amount; + farm_setup.check_user_total_farm_position(&first_user, first_user_total_position); + farm_setup.check_user_total_farm_position(&second_user, second_user_total_position); + + // users claim rewards to get their energy registered + let _ = farm_setup.claim_rewards(&first_user, 6, farm_token_amount); + let _ = farm_setup.claim_rewards(&second_user, 7, farm_token_amount); + + // random tx on end of week 1, to cummulate rewards + farm_setup.b_mock.set_block_nonce(10); + farm_setup.b_mock.set_block_epoch(6); + farm_setup.set_user_energy(&first_user, 1_000, 6, 1); + farm_setup.set_user_energy(&second_user, 4_000, 6, 1); + farm_setup.set_user_energy(&third_user, 1, 6, 1); + farm_setup.enter_farm(&third_user, 1); + farm_setup.exit_farm(&third_user, 10, 1); + + // advance 1 week + farm_setup.b_mock.set_block_epoch(10); + farm_setup.set_user_energy(&first_user, 1_000, 10, 1); + farm_setup.set_user_energy(&second_user, 4_000, 10, 1); + + // Second user claims with half a position from the first user + let base_rewards_amount = 535; + let boosted_rewards_amount = 1414; + let mut second_user_reward_balance = base_rewards_amount + boosted_rewards_amount; + + let second_received_reward_amt = farm_setup.claim_rewards(&second_user, 2, half_token_amount); + assert_eq!(second_received_reward_amt, second_user_reward_balance); + + farm_setup.b_mock.check_esdt_balance( + &second_user, + REWARD_TOKEN_ID, + &rust_biguint!(second_user_reward_balance), + ); + farm_setup.b_mock.check_nft_balance( + &second_user, + FARM_TOKEN_ID, + 11, + &rust_biguint!(half_token_amount), + Some(&FarmTokenAttributes:: { + reward_per_share: managed_biguint!(107142857), + entering_epoch: 2, + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(half_token_amount), + original_owner: managed_address!(&second_user), + }), + ); + + // Check users positions after claim + first_user_total_position -= half_token_amount; + second_user_total_position += half_token_amount; + farm_setup.check_user_total_farm_position(&first_user, first_user_total_position); + farm_setup.check_user_total_farm_position(&second_user, second_user_total_position); + + // random tx on end of week 2, to cummulate rewards + farm_setup.b_mock.set_block_nonce(20); + farm_setup.b_mock.set_block_epoch(13); + farm_setup.set_user_energy(&first_user, 1_000, 13, 1); + farm_setup.set_user_energy(&second_user, 4_000, 13, 1); + farm_setup.set_user_energy(&third_user, 1, 13, 1); + farm_setup.enter_farm(&third_user, 1); + farm_setup.exit_farm(&third_user, 12, 1); + + // advance 1 week + farm_setup.b_mock.set_block_epoch(15); + farm_setup.set_user_energy(&first_user, 1_000, 15, 1); + farm_setup.set_user_energy(&second_user, 4_000, 15, 1); + + // Second user exits farm with half of a position previously owned by user 1 + second_user_reward_balance += 1071; // base rewards + second_user_reward_balance += 1487; // boosted rewards + farm_setup.exit_farm(&second_user, 3, half_token_amount); + farm_setup + .b_mock + .check_esdt_balance(&second_user, REWARD_TOKEN_ID, &rust_biguint!(4507)); + + // Check users positions after exit + first_user_total_position -= half_token_amount; + farm_setup.check_user_total_farm_position(&first_user, first_user_total_position); + farm_setup.check_user_total_farm_position(&second_user, second_user_total_position); + + // random tx on end of week 3, to cummulate rewards + farm_setup.b_mock.set_block_nonce(30); + farm_setup.b_mock.set_block_epoch(20); + farm_setup.set_user_energy(&first_user, 1_000, 20, 1); + farm_setup.set_user_energy(&second_user, 4_000, 20, 1); + farm_setup.set_user_energy(&third_user, 1, 20, 1); + farm_setup.enter_farm(&third_user, 1); + farm_setup.exit_farm(&third_user, 13, 1); + + // advance 1 week + farm_setup.b_mock.set_block_epoch(25); + farm_setup.set_user_energy(&first_user, 1_000, 25, 1); + farm_setup.set_user_energy(&second_user, 4_000, 25, 1); + + // First user claims rewards + let first_user_received_reward_amt = + farm_setup.claim_rewards(&first_user, 8, farm_token_amount); + assert_eq!(first_user_received_reward_amt, 6167); + + // Check users positions after first user claim + farm_setup.check_user_total_farm_position(&first_user, first_user_total_position); + farm_setup.check_user_total_farm_position(&second_user, second_user_total_position); + + // Second user merges half from one of his original position with 2 position halves from the first user + let farm_tokens = vec![ + NonceAmountPair { + nonce: 4, + amount: half_token_amount, + }, + NonceAmountPair { + nonce: 5, + amount: half_token_amount, + }, + NonceAmountPair { + nonce: 11, + amount: half_token_amount, + }, + ]; + + farm_setup.b_mock.check_esdt_balance( + &second_user, + REWARD_TOKEN_ID, + &rust_biguint!(second_user_reward_balance), + ); + farm_setup.merge_farm_tokens(&second_user, farm_tokens); + second_user_reward_balance += 1510; // boosted rewards + farm_setup.b_mock.check_esdt_balance( + &second_user, + REWARD_TOKEN_ID, + &rust_biguint!(second_user_reward_balance), + ); + farm_setup.b_mock.check_nft_balance( + &second_user, + FARM_TOKEN_ID, + 15, + &rust_biguint!(half_token_amount * 3), + Some(&FarmTokenAttributes:: { + reward_per_share: managed_biguint!(35714286), + entering_epoch: 2, + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(half_token_amount * 3), + original_owner: managed_address!(&second_user), + }), + ); + + // Check users positions after merge + first_user_total_position -= 2 * half_token_amount; + second_user_total_position += 2 * half_token_amount; + farm_setup.check_user_total_farm_position(&first_user, first_user_total_position); + farm_setup.check_user_total_farm_position(&second_user, second_user_total_position); +} + +#[test] +fn total_farm_position_through_simple_lock_test() { + use multiversx_sc::storage::mappers::StorageTokenWrapper; + use simple_lock::locked_token::LockedTokenModule; + use simple_lock::proxy_farm::ProxyFarmModule; + use simple_lock::proxy_farm::*; + use simple_lock::proxy_lp::{LpProxyTokenAttributes, ProxyLpModule}; + use simple_lock::SimpleLock; + + const LOCKED_TOKEN_ID: &[u8] = b"NOOOO-123456"; + const LOCKED_LP_TOKEN_ID: &[u8] = b"LKLP-123456"; + const FARM_PROXY_TOKEN_ID: &[u8] = b"PROXY-123456"; + const WEGLD_TOKEN_ID: &[u8] = b"WEGLD-abcdef"; + const MEX_TOKEN_ID: &[u8] = b"MEX-abcdef"; // reward token ID + + DebugApi::dummy(); + let mut farm_setup = MultiUserFarmSetup::new( + farm::contract_obj, + energy_factory_mock::contract_obj, + energy_update::contract_obj, + ); + let rust_zero = rust_biguint!(0); + + // setup simple lock SC + let lock_wrapper = farm_setup.b_mock.create_sc_account( + &rust_zero, + Some(&farm_setup.owner), + simple_lock::contract_obj, + "Simple Lock Path", + ); + + let farm_addr = farm_setup.farm_wrapper.address_ref().clone(); + farm_setup + .b_mock + .execute_tx(&farm_setup.owner, &lock_wrapper, &rust_zero, |sc| { + sc.init(); + sc.locked_token() + .set_token_id(managed_token_id!(LOCKED_TOKEN_ID)); + sc.lp_proxy_token() + .set_token_id(managed_token_id!(LOCKED_LP_TOKEN_ID)); + sc.farm_proxy_token() + .set_token_id(managed_token_id!(FARM_PROXY_TOKEN_ID)); + sc.add_farm_to_whitelist( + managed_address!(&farm_addr), + managed_token_id!(FARMING_TOKEN_ID), + FarmType::SimpleFarm, + ); + }) + .assert_ok(); + + // change farming token for farm + whitelist simple lock contract + farm_setup + .b_mock + .execute_tx( + &farm_setup.owner, + &farm_setup.farm_wrapper, + &rust_zero, + |sc| { + sc.farming_token_id() + .set(&managed_token_id!(FARMING_TOKEN_ID)); + sc.add_sc_address_to_whitelist(managed_address!(lock_wrapper.address_ref())); + }, + ) + .assert_ok(); + + farm_setup.b_mock.set_esdt_local_roles( + lock_wrapper.address_ref(), + LOCKED_LP_TOKEN_ID, + &[ + EsdtLocalRole::NftCreate, + EsdtLocalRole::NftAddQuantity, + EsdtLocalRole::NftBurn, + ], + ); + farm_setup.b_mock.set_esdt_local_roles( + lock_wrapper.address_ref(), + FARM_PROXY_TOKEN_ID, + &[ + EsdtLocalRole::NftCreate, + EsdtLocalRole::NftAddQuantity, + EsdtLocalRole::NftBurn, + ], + ); + + // user lock tokens + let user_addr = farm_setup.first_user.clone(); + + let lp_proxy_token_attributes: LpProxyTokenAttributes = LpProxyTokenAttributes { + lp_token_id: managed_token_id!(FARMING_TOKEN_ID), + first_token_id: managed_token_id!(WEGLD_TOKEN_ID), + first_token_locked_nonce: 1, + second_token_id: managed_token_id!(MEX_TOKEN_ID), + second_token_locked_nonce: 2, + }; + + farm_setup.b_mock.set_nft_balance( + &user_addr, + LOCKED_LP_TOKEN_ID, + 1, + &rust_biguint!(1_000_000_000), + &lp_proxy_token_attributes, + ); + + farm_setup.b_mock.set_esdt_balance( + lock_wrapper.address_ref(), + FARMING_TOKEN_ID, + &rust_biguint!(1_000_000_000), + ); + + farm_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + farm_setup.set_boosted_yields_factors(); + farm_setup.b_mock.set_block_epoch(2); + + let temp_user = farm_setup.third_user.clone(); + + farm_setup.check_user_total_farm_position(&user_addr, 0); + + // first user enter farm twice (normal & through simple lock contract) + // enter farm through simple lock contract + let farm_in_amount = 50_000_000; + farm_setup.last_farm_token_nonce += 1; + farm_setup + .b_mock + .execute_esdt_transfer( + &user_addr, + &lock_wrapper, + LOCKED_LP_TOKEN_ID, + 1, + &rust_biguint!(farm_in_amount), + |sc| { + let enter_farm_result = sc.enter_farm_locked_token(FarmType::SimpleFarm); + let (out_farm_token, _reward_token) = enter_farm_result.into_tuple(); + assert_eq!( + out_farm_token.token_identifier, + managed_token_id!(FARM_PROXY_TOKEN_ID) + ); + assert_eq!(out_farm_token.token_nonce, farm_setup.last_farm_token_nonce); + assert_eq!(out_farm_token.amount, managed_biguint!(farm_in_amount)); + }, + ) + .assert_ok(); + + farm_setup.b_mock.check_nft_balance( + &user_addr, + FARM_PROXY_TOKEN_ID, + 1, + &rust_biguint!(farm_in_amount), + Some(&FarmProxyTokenAttributes:: { + farm_type: FarmType::SimpleFarm, + farm_token_id: managed_token_id!(FARM_TOKEN_ID), + farm_token_nonce: 1, + farming_token_id: managed_token_id!(FARMING_TOKEN_ID), + farming_token_locked_nonce: 1, + }), + ); + + farm_setup.check_user_total_farm_position(&user_addr, farm_in_amount); + + // enter farm directly + farm_setup.set_user_energy(&user_addr, 1_000, 2, 1); + farm_setup.enter_farm(&user_addr, farm_in_amount); + + farm_setup.b_mock.check_nft_balance( + &user_addr, + FARM_TOKEN_ID, + farm_setup.last_farm_token_nonce, + &rust_biguint!(farm_in_amount), + Some(&FarmTokenAttributes:: { + reward_per_share: managed_biguint!(0), + compounded_reward: managed_biguint!(0), + entering_epoch: 2, + current_farm_amount: managed_biguint!(farm_in_amount), + original_owner: managed_address!(&user_addr), + }), + ); + + farm_setup.check_user_total_farm_position(&user_addr, farm_in_amount * 2); + farm_setup.check_farm_token_supply(farm_in_amount * 2); + + // users claim rewards to get their energy registered + let _ = farm_setup.claim_rewards(&user_addr, 2, farm_in_amount); + + // advance blocks - 10 blocks - 10 * 1_000 = 10_000 total rewards + // 7_500 base farm, 2_500 boosted yields + farm_setup.b_mock.set_block_nonce(10); + + // random tx on end of week 1, to cummulate rewards + farm_setup.b_mock.set_block_epoch(6); + farm_setup.set_user_energy(&user_addr, 1_000, 6, 1); + farm_setup.set_user_energy(&temp_user, 1, 6, 1); + farm_setup.enter_farm(&temp_user, 1); + farm_setup.exit_farm(&temp_user, 4, 1); + + // advance 1 week + farm_setup.b_mock.set_block_epoch(10); + farm_setup.set_user_energy(&user_addr, 1_000, 10, 1); + + let total_farm_tokens = farm_in_amount * 2; + + // first user claim with half total position + let first_base_farm_amt = farm_in_amount * 7_500 / total_farm_tokens; + + // Boosted yields rewards formula + // total_boosted_rewards * (energy_const * user_energy / total_energy + farm_const * user_farm / total_farm) / (energy_const + farm_const) + // (total_boosted_rewards * energy_const * user_energy / total_energy + total_boosted_rewards * farm_const * user_farm / total_farm) / (energy_const + farm_const) + // (2_500 * 3 * 1_000 / 1_000 + 2_500 * 2 * 100_000_000 / 100_000_000) / (3 + 2) + // (7_500 + 2_500) / (5) = 2_500 + let first_boosted_amt = 2_500; // 1000 energy & 100_000_000 farm tokens + let first_total_rewards = first_base_farm_amt + first_boosted_amt; + + let first_received_reward_amt = farm_setup.claim_rewards(&user_addr, 3, farm_in_amount); + + // Should be equal to half base generated rewards + full boosted generated rewards + assert_eq!(first_received_reward_amt, first_total_rewards); + + farm_setup + .b_mock + .check_nft_balance::>( + &user_addr, + FARM_TOKEN_ID, + 5, + &rust_biguint!(farm_in_amount), + None, + ); + + farm_setup.b_mock.check_esdt_balance( + &user_addr, + REWARD_TOKEN_ID, + &rust_biguint!(first_received_reward_amt), + ); +} diff --git a/dex/farm/wasm/Cargo.lock b/dex/farm/wasm/Cargo.lock index 2308d9073..2dacef823 100644 --- a/dex/farm/wasm/Cargo.lock +++ b/dex/farm/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common-types" @@ -285,9 +285,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -298,9 +298,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -308,9 +308,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -320,9 +320,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -333,18 +333,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -402,9 +402,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/dex/farm/wasm/Cargo.toml b/dex/farm/wasm/Cargo.toml index 26ce2670b..1fa20b905 100644 --- a/dex/farm/wasm/Cargo.toml +++ b/dex/farm/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/dex/fuzz/Cargo.toml b/dex/fuzz/Cargo.toml index 57800c37f..391a4c7c1 100644 --- a/dex/fuzz/Cargo.toml +++ b/dex/fuzz/Cargo.toml @@ -12,11 +12,11 @@ num-bigint = "0.4.2" rand = "0.8.4" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" [dependencies.pausable] path = "../../common/modules/pausable" diff --git a/dex/governance/Cargo.toml b/dex/governance/Cargo.toml index 74d9f2849..61ba59e59 100644 --- a/dex/governance/Cargo.toml +++ b/dex/governance/Cargo.toml @@ -9,14 +9,14 @@ publish = false path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" [dev-dependencies.pair-mock] path = "../pair-mock" diff --git a/dex/governance/meta/Cargo.toml b/dex/governance/meta/Cargo.toml index b692c9007..e99c24667 100644 --- a/dex/governance/meta/Cargo.toml +++ b/dex/governance/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/dex/governance/src/lib.rs b/dex/governance/src/lib.rs index e9d4147d3..460aabcda 100644 --- a/dex/governance/src/lib.rs +++ b/dex/governance/src/lib.rs @@ -49,7 +49,7 @@ pub trait Governance: self.try_change_price_providers(price_providers); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[payable("*")] diff --git a/dex/governance/wasm/Cargo.lock b/dex/governance/wasm/Cargo.lock index 30ca50940..5104abd3f 100644 --- a/dex/governance/wasm/Cargo.lock +++ b/dex/governance/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "endian-type" @@ -55,9 +55,9 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -68,9 +68,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -78,9 +78,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -90,9 +90,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -103,9 +103,9 @@ dependencies = [ [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -130,9 +130,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/dex/governance/wasm/Cargo.toml b/dex/governance/wasm/Cargo.toml index 905950d0e..7b1d0521f 100644 --- a/dex/governance/wasm/Cargo.toml +++ b/dex/governance/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/dex/pair-mock/Cargo.toml b/dex/pair-mock/Cargo.toml index bc58d1089..4854f150c 100644 --- a/dex/pair-mock/Cargo.toml +++ b/dex/pair-mock/Cargo.toml @@ -12,7 +12,7 @@ path = "src/pair.rs" path = "../../common/common_errors" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.itertools] @@ -20,4 +20,4 @@ version = "0.10.1" default-features = false [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" diff --git a/dex/pair-mock/elrond.json b/dex/pair-mock/elrond.json deleted file mode 100644 index 736553962..000000000 --- a/dex/pair-mock/elrond.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "language": "rust" -} \ No newline at end of file diff --git a/dex/pair-mock/meta/Cargo.toml b/dex/pair-mock/meta/Cargo.toml index 673a8fc84..8f2d3b0ca 100644 --- a/dex/pair-mock/meta/Cargo.toml +++ b/dex/pair-mock/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/dex/pair-mock/wasm/Cargo.lock b/dex/pair-mock/wasm/Cargo.lock index 6311e01de..6e83ea775 100644 --- a/dex/pair-mock/wasm/Cargo.lock +++ b/dex/pair-mock/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common_errors" @@ -62,9 +62,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -75,9 +75,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -85,9 +85,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -97,9 +97,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -110,9 +110,9 @@ dependencies = [ [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -154,9 +154,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/dex/pair-mock/wasm/Cargo.toml b/dex/pair-mock/wasm/Cargo.toml index 9bf537c94..2bbacc718 100644 --- a/dex/pair-mock/wasm/Cargo.toml +++ b/dex/pair-mock/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/dex/pair/Cargo.toml b/dex/pair/Cargo.toml index 457fb8d8f..7fc6998a8 100644 --- a/dex/pair/Cargo.toml +++ b/dex/pair/Cargo.toml @@ -37,11 +37,11 @@ version = "0.10.1" default-features = false [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" diff --git a/dex/pair/meta/Cargo.toml b/dex/pair/meta/Cargo.toml index b07218ea1..508ad1a44 100644 --- a/dex/pair/meta/Cargo.toml +++ b/dex/pair/meta/Cargo.toml @@ -9,5 +9,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/dex/pair/src/lib.rs b/dex/pair/src/lib.rs index 98996e34a..e67010d67 100644 --- a/dex/pair/src/lib.rs +++ b/dex/pair/src/lib.rs @@ -12,6 +12,7 @@ pub mod fee; mod liquidity_pool; pub mod locking_wrapper; pub mod pair_actions; +pub mod read_pair_storage; pub mod safe_price; pub mod safe_price_view; @@ -33,6 +34,7 @@ pub trait Pair: + config::ConfigModule + token_send::TokenSendModule + events::EventsModule + + read_pair_storage::ReadPairStorageModule + safe_price::SafePriceModule + safe_price_view::SafePriceViewModule + contexts::output_builder::OutputBuilderModule @@ -99,7 +101,7 @@ pub trait Pair: }; } - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[endpoint(setLpTokenIdentifier)] diff --git a/dex/pair/src/read_pair_storage.rs b/dex/pair/src/read_pair_storage.rs new file mode 100644 index 000000000..2aeff0566 --- /dev/null +++ b/dex/pair/src/read_pair_storage.rs @@ -0,0 +1,76 @@ +use multiversx_sc::storage::StorageKey; + +use crate::safe_price::PriceObservation; + +multiversx_sc::imports!(); + +pub static LP_TOKEN_SUPPLY_STORAGE_KEY: &[u8] = b"lp_token_supply"; +pub static FIRST_TOKEN_ID_STORAGE_KEY: &[u8] = b"first_token_id"; +pub static SECOND_TOKEN_ID_STORAGE_KEY: &[u8] = b"second_token_id"; +pub static SAFE_PRICE_CURRENT_INDEX_STORAGE_KEY: &[u8] = b"safe_price_current_index"; +pub static PRICE_OBSERVATIONS_STORAGE_KEY: &[u8] = b"price_observations"; +pub static PAIR_RESERVE_BASE_STORAGE_KEY: &[u8] = b"reserve"; + +#[multiversx_sc::module] +pub trait ReadPairStorageModule { + fn get_lp_token_supply_mapper( + &self, + pair_address: ManagedAddress, + ) -> SingleValueMapper { + SingleValueMapper::<_, _, ManagedAddress>::new_from_address( + pair_address, + StorageKey::new(LP_TOKEN_SUPPLY_STORAGE_KEY), + ) + } + + fn get_first_token_id_mapper( + &self, + pair_address: ManagedAddress, + ) -> SingleValueMapper { + SingleValueMapper::<_, _, ManagedAddress>::new_from_address( + pair_address, + StorageKey::new(FIRST_TOKEN_ID_STORAGE_KEY), + ) + } + + fn get_second_token_id_mapper( + &self, + pair_address: ManagedAddress, + ) -> SingleValueMapper { + SingleValueMapper::<_, _, ManagedAddress>::new_from_address( + pair_address, + StorageKey::new(SECOND_TOKEN_ID_STORAGE_KEY), + ) + } + + fn get_safe_price_current_index_mapper( + &self, + pair_address: ManagedAddress, + ) -> SingleValueMapper { + SingleValueMapper::<_, _, ManagedAddress>::new_from_address( + pair_address, + StorageKey::new(SAFE_PRICE_CURRENT_INDEX_STORAGE_KEY), + ) + } + + fn get_price_observation_mapper( + &self, + pair_address: ManagedAddress, + ) -> VecMapper, ManagedAddress> { + VecMapper::<_, _, ManagedAddress>::new_from_address( + pair_address, + StorageKey::new(PRICE_OBSERVATIONS_STORAGE_KEY), + ) + } + + fn get_pair_reserve_mapper( + &self, + pair_address: ManagedAddress, + token_id: &TokenIdentifier, + ) -> SingleValueMapper { + let mut storage_key = StorageKey::new(PAIR_RESERVE_BASE_STORAGE_KEY); + storage_key.append_item(&token_id); + + SingleValueMapper::<_, _, ManagedAddress>::new_from_address(pair_address, storage_key) + } +} diff --git a/dex/pair/src/safe_price_view.rs b/dex/pair/src/safe_price_view.rs index 16d5d96c3..e286bc370 100644 --- a/dex/pair/src/safe_price_view.rs +++ b/dex/pair/src/safe_price_view.rs @@ -6,6 +6,7 @@ use core::cmp::Ordering; use crate::{ amm, config, errors::{ERROR_SAFE_PRICE_OBSERVATION_DOES_NOT_EXIST, ERROR_SAFE_PRICE_SAME_ROUNDS}, + read_pair_storage, safe_price::{self, PriceObservation, Round, MAX_OBSERVATIONS}, }; @@ -26,6 +27,7 @@ pub trait SafePriceViewModule: + amm::AmmModule + permissions_module::PermissionsModule + pausable::PausableModule + + read_pair_storage::ReadPairStorageModule { #[label("safe-price-view")] #[view(getLpTokensSafePriceByDefaultOffset)] @@ -89,19 +91,16 @@ pub trait SafePriceViewModule: ) -> MultiValue2 { require!(end_round > start_round, ERROR_PARAMETERS); - let first_token_id = self.first_token_id().get_from_address(&pair_address); - let second_token_id = self.second_token_id().get_from_address(&pair_address); + let first_token_id = self.get_first_token_id_mapper(pair_address.clone()).get(); + let second_token_id = self.get_second_token_id_mapper(pair_address.clone()).get(); let safe_price_current_index = self - .safe_price_current_index() - .get_from_address(&pair_address); - let price_observations = self.price_observations(); + .get_safe_price_current_index_mapper(pair_address.clone()) + .get(); + let price_observations = self.get_price_observation_mapper(pair_address.clone()); - let oldest_price_observation = self.get_oldest_price_observation( - &pair_address, - safe_price_current_index, - &price_observations, - ); + let oldest_price_observation = + self.get_oldest_price_observation(safe_price_current_index, &price_observations); require!( start_round >= oldest_price_observation.recording_round, @@ -130,7 +129,7 @@ pub trait SafePriceViewModule: self.compute_weighted_amounts(&first_price_observation, &last_price_observation); if weighted_amounts.weighted_lp_supply == 0 { - let current_lp_supply = self.lp_token_supply().get_from_address(&pair_address); + let current_lp_supply = self.get_lp_token_supply_mapper(pair_address.clone()).get(); if current_lp_supply == 0 { return ( EsdtTokenPayment::new(first_token_id, 0, BigUint::zero()), @@ -212,22 +211,19 @@ pub trait SafePriceViewModule: require!(end_round > start_round, ERROR_PARAMETERS); let safe_price_current_index = self - .safe_price_current_index() - .get_from_address(&pair_address); - let price_observations = self.price_observations(); + .get_safe_price_current_index_mapper(pair_address.clone()) + .get(); + let price_observations = self.get_price_observation_mapper(pair_address.clone()); - let oldest_price_observation = self.get_oldest_price_observation( - &pair_address, - safe_price_current_index, - &price_observations, - ); + let oldest_price_observation = + self.get_oldest_price_observation(safe_price_current_index, &price_observations); require!( oldest_price_observation.recording_round <= start_round, ERROR_SAFE_PRICE_OBSERVATION_DOES_NOT_EXIST ); - let first_token_id = self.first_token_id().get_from_address(&pair_address); - let second_token_id = self.second_token_id().get_from_address(&pair_address); + let first_token_id = self.get_first_token_id_mapper(pair_address.clone()).get(); + let second_token_id = self.get_second_token_id_mapper(pair_address.clone()).get(); let first_price_observation = self.get_price_observation( &pair_address, &first_token_id, @@ -261,17 +257,14 @@ pub trait SafePriceViewModule: search_round: Round, ) -> PriceObservation { let safe_price_current_index = self - .safe_price_current_index() - .get_from_address(&pair_address); - let first_token_id = self.first_token_id().get_from_address(&pair_address); - let second_token_id = self.second_token_id().get_from_address(&pair_address); - let price_observations = self.price_observations(); - - let oldest_price_observation = self.get_oldest_price_observation( - &pair_address, - safe_price_current_index, - &price_observations, - ); + .get_safe_price_current_index_mapper(pair_address.clone()) + .get(); + let first_token_id = self.get_first_token_id_mapper(pair_address.clone()).get(); + let second_token_id = self.get_second_token_id_mapper(pair_address.clone()).get(); + let price_observations = self.get_price_observation_mapper(pair_address.clone()); + + let oldest_price_observation = + self.get_oldest_price_observation(safe_price_current_index, &price_observations); require!( oldest_price_observation.recording_round <= search_round, ERROR_SAFE_PRICE_OBSERVATION_DOES_NOT_EXIST @@ -294,8 +287,8 @@ pub trait SafePriceViewModule: first_price_observation: &PriceObservation, last_price_observation: &PriceObservation, ) -> EsdtTokenPayment { - let first_token_id = self.first_token_id().get_from_address(pair_address); - let second_token_id = self.second_token_id().get_from_address(pair_address); + let first_token_id = self.get_first_token_id_mapper(pair_address.clone()).get(); + let second_token_id = self.get_second_token_id_mapper(pair_address.clone()).get(); let weighted_amounts = self.compute_weighted_amounts(first_price_observation, last_price_observation); @@ -321,16 +314,16 @@ pub trait SafePriceViewModule: first_token_id: &TokenIdentifier, second_token_id: &TokenIdentifier, current_index: usize, - price_observations: &VecMapper>, + price_observations: &VecMapper, ManagedAddress>, search_round: Round, ) -> PriceObservation { require!( - !price_observations.is_empty_at_address(pair_address), + !price_observations.is_empty(), ERROR_SAFE_PRICE_OBSERVATION_DOES_NOT_EXIST ); // Check if the requested price observation is the last one - let last_observation = price_observations.get_at_address(pair_address, current_index); + let last_observation = price_observations.get(current_index); if last_observation.recording_round == search_round { return last_observation; } @@ -346,12 +339,12 @@ pub trait SafePriceViewModule: ); let first_token_reserve = self - .pair_reserve(first_token_id) - .get_from_address(pair_address); + .get_pair_reserve_mapper(pair_address.clone(), first_token_id) + .get(); let second_token_reserve = self - .pair_reserve(second_token_id) - .get_from_address(pair_address); - let current_lp_supply = self.lp_token_supply().get_from_address(pair_address); + .get_pair_reserve_mapper(pair_address.clone(), second_token_id) + .get(); + let current_lp_supply = self.get_lp_token_supply_mapper(pair_address.clone()).get(); return self.compute_new_observation( search_round, &first_token_reserve, @@ -362,7 +355,6 @@ pub trait SafePriceViewModule: } let (mut price_observation, last_search_index) = self.price_observation_by_binary_search( - pair_address, current_index, price_observations, search_round, @@ -373,7 +365,6 @@ pub trait SafePriceViewModule: } price_observation = self.price_observation_by_linear_interpolation( - pair_address, price_observations, search_round, last_search_index, @@ -384,45 +375,43 @@ pub trait SafePriceViewModule: fn get_oldest_price_observation( &self, - pair_address: &ManagedAddress, current_index: usize, - price_observations: &VecMapper>, + price_observations: &VecMapper, ManagedAddress>, ) -> PriceObservation { require!( - !price_observations.is_empty_at_address(pair_address), + !price_observations.is_empty(), ERROR_SAFE_PRICE_OBSERVATION_DOES_NOT_EXIST ); // VecMapper index starts at 1 let mut oldest_observation_index = 1; - if price_observations.len_at_address(pair_address) == MAX_OBSERVATIONS { + if price_observations.len() == MAX_OBSERVATIONS { oldest_observation_index = (current_index % MAX_OBSERVATIONS) + 1 } - price_observations.get_at_address(pair_address, oldest_observation_index) + price_observations.get(oldest_observation_index) } fn price_observation_by_binary_search( &self, - pair_address: &ManagedAddress, current_index: usize, - price_observations: &VecMapper>, + price_observations: &VecMapper, ManagedAddress>, search_round: Round, ) -> (PriceObservation, usize) { let mut search_index = 1; let mut left_index; let mut right_index; - let observation_at_index_1 = price_observations.get_at_address(pair_address, search_index); + let observation_at_index_1 = price_observations.get(search_index); if observation_at_index_1.recording_round <= search_round { left_index = search_index; right_index = current_index - 1; } else { left_index = current_index + 1; - right_index = price_observations.len_at_address(pair_address); + right_index = price_observations.len(); } while left_index <= right_index { search_index = (left_index + right_index) / 2; - let price_observation = price_observations.get_at_address(pair_address, search_index); + let price_observation = price_observations.get(search_index); match price_observation.recording_round.cmp(&search_round) { Ordering::Equal => return (price_observation, search_index), Ordering::Less => left_index = search_index + 1, @@ -435,27 +424,24 @@ pub trait SafePriceViewModule: fn price_observation_by_linear_interpolation( &self, - pair_address: &ManagedAddress, - price_observations: &VecMapper>, + price_observations: &VecMapper, ManagedAddress>, search_round: Round, search_index: usize, ) -> PriceObservation { - let last_found_observation = price_observations.get_at_address(pair_address, search_index); + let last_found_observation = price_observations.get(search_index); let left_observation; let right_observation; if last_found_observation.recording_round < search_round { left_observation = last_found_observation; let right_observation_index = (search_index % MAX_OBSERVATIONS) + 1; - right_observation = - price_observations.get_at_address(pair_address, right_observation_index); + right_observation = price_observations.get(right_observation_index); } else { let left_observation_index = if search_index == 1 { MAX_OBSERVATIONS } else { search_index - 1 }; - left_observation = - price_observations.get_at_address(pair_address, left_observation_index); + left_observation = price_observations.get(left_observation_index); right_observation = last_found_observation; }; @@ -533,14 +519,11 @@ pub trait SafePriceViewModule: fn get_default_offset_rounds(&self, pair_address: &ManagedAddress, end_round: Round) -> u64 { let safe_price_current_index = self - .safe_price_current_index() - .get_from_address(pair_address); - let price_observations = self.price_observations(); - let oldest_price_observation = self.get_oldest_price_observation( - pair_address, - safe_price_current_index, - &price_observations, - ); + .get_safe_price_current_index_mapper(pair_address.clone()) + .get(); + let price_observations = self.get_price_observation_mapper(pair_address.clone()); + let oldest_price_observation = + self.get_oldest_price_observation(safe_price_current_index, &price_observations); let mut default_offset_rounds = end_round - oldest_price_observation.recording_round; if default_offset_rounds > DEFAULT_SAFE_PRICE_ROUNDS_OFFSET { @@ -556,16 +539,13 @@ pub trait SafePriceViewModule: fn update_and_get_tokens_for_given_position_with_safe_price( &self, liquidity: BigUint, - ) -> MultiValue2, EsdtTokenPayment> { + ) -> MultiValue2 { let pair_address = self.blockchain().get_sc_address(); self.get_lp_tokens_safe_price_by_default_offset(pair_address, liquidity) } #[endpoint(updateAndGetSafePrice)] - fn update_and_get_safe_price( - &self, - input: EsdtTokenPayment, - ) -> EsdtTokenPayment { + fn update_and_get_safe_price(&self, input: EsdtTokenPayment) -> EsdtTokenPayment { let pair_address = self.blockchain().get_sc_address(); self.get_safe_price_by_default_offset(pair_address, input) } diff --git a/dex/pair/tests/pair_setup/mod.rs b/dex/pair/tests/pair_setup/mod.rs index 083ec8e40..78f99b6e9 100644 --- a/dex/pair/tests/pair_setup/mod.rs +++ b/dex/pair/tests/pair_setup/mod.rs @@ -409,7 +409,7 @@ where pub fn set_price_observation_as_old(&mut self, observation_index: usize) { let _ = self.b_mock.execute_query(&self.pair_wrapper, |sc| { - let price_observations = sc.price_observations(); + let mut price_observations = sc.price_observations(); let mut price_observation = price_observations.get(observation_index); price_observation.lp_supply_accumulated = BigUint::zero(); diff --git a/dex/pair/wasm-pair-full/Cargo.lock b/dex/pair/wasm-pair-full/Cargo.lock index 77c4e33e1..9ca48d0d0 100644 --- a/dex/pair/wasm-pair-full/Cargo.lock +++ b/dex/pair/wasm-pair-full/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common-types" @@ -161,9 +161,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -174,9 +174,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -184,9 +184,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -196,9 +196,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -209,18 +209,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -286,9 +286,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/dex/pair/wasm-pair-full/Cargo.toml b/dex/pair/wasm-pair-full/Cargo.toml index 5fc0f4b76..702f1a1fd 100644 --- a/dex/pair/wasm-pair-full/Cargo.toml +++ b/dex/pair/wasm-pair-full/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/dex/pair/wasm-safe-price-view/Cargo.lock b/dex/pair/wasm-safe-price-view/Cargo.lock index 48471aad0..929875e3f 100644 --- a/dex/pair/wasm-safe-price-view/Cargo.lock +++ b/dex/pair/wasm-safe-price-view/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common-types" @@ -161,9 +161,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -174,9 +174,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -184,9 +184,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -196,9 +196,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -209,18 +209,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -278,9 +278,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/dex/pair/wasm-safe-price-view/Cargo.toml b/dex/pair/wasm-safe-price-view/Cargo.toml index 28c1d40a9..035a097bf 100644 --- a/dex/pair/wasm-safe-price-view/Cargo.toml +++ b/dex/pair/wasm-safe-price-view/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/dex/pair/wasm/Cargo.lock b/dex/pair/wasm/Cargo.lock index c1f2406db..26d648185 100644 --- a/dex/pair/wasm/Cargo.lock +++ b/dex/pair/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common-types" @@ -161,9 +161,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -174,9 +174,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -184,9 +184,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -196,9 +196,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -209,18 +209,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -286,9 +286,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/dex/pair/wasm/Cargo.toml b/dex/pair/wasm/Cargo.toml index 7e096d156..8114353ef 100644 --- a/dex/pair/wasm/Cargo.toml +++ b/dex/pair/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/dex/price-discovery/Cargo.toml b/dex/price-discovery/Cargo.toml index 51aa316e3..7eecf6dd9 100644 --- a/dex/price-discovery/Cargo.toml +++ b/dex/price-discovery/Cargo.toml @@ -12,11 +12,11 @@ path = "src/lib.rs" hex-literal = "0.3.1" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" [dependencies.locking_module] path = "../../common/modules/locking_module" @@ -30,4 +30,4 @@ hex = "0.4" path = "../../locked-asset/simple-lock" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" diff --git a/dex/price-discovery/meta/Cargo.toml b/dex/price-discovery/meta/Cargo.toml index 176823d06..c6955d199 100644 --- a/dex/price-discovery/meta/Cargo.toml +++ b/dex/price-discovery/meta/Cargo.toml @@ -9,5 +9,5 @@ authors = ["Dorin Iancu "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/dex/price-discovery/src/lib.rs b/dex/price-discovery/src/lib.rs index 32a07acf0..b0c430e52 100644 --- a/dex/price-discovery/src/lib.rs +++ b/dex/price-discovery/src/lib.rs @@ -113,7 +113,7 @@ pub trait PriceDiscovery: self.set_locking_sc_address(locking_sc_address); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} /// Users can deposit either launched_token or accepted_token. diff --git a/dex/price-discovery/wasm/Cargo.lock b/dex/price-discovery/wasm/Cargo.lock index fbcb7ca84..65c5b9037 100644 --- a/dex/price-discovery/wasm/Cargo.lock +++ b/dex/price-discovery/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common_errors" @@ -119,9 +119,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal 0.4.1", @@ -132,9 +132,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -142,9 +142,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -154,9 +154,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -167,18 +167,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -221,9 +221,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/dex/price-discovery/wasm/Cargo.toml b/dex/price-discovery/wasm/Cargo.toml index 04885bcda..e1d773a07 100644 --- a/dex/price-discovery/wasm/Cargo.toml +++ b/dex/price-discovery/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/dex/proxy-deployer/Cargo.toml b/dex/proxy-deployer/Cargo.toml index f5c3b8955..f4efe45d6 100644 --- a/dex/proxy-deployer/Cargo.toml +++ b/dex/proxy-deployer/Cargo.toml @@ -21,11 +21,11 @@ path = "../../common/modules/farm/config" path = "../../common/modules/farm/farm_token" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" diff --git a/dex/proxy-deployer/meta/Cargo.toml b/dex/proxy-deployer/meta/Cargo.toml index 629fddbdf..9a516a7c0 100644 --- a/dex/proxy-deployer/meta/Cargo.toml +++ b/dex/proxy-deployer/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/dex/proxy-deployer/src/lib.rs b/dex/proxy-deployer/src/lib.rs index a05bab7b0..7f7f0c16a 100644 --- a/dex/proxy-deployer/src/lib.rs +++ b/dex/proxy-deployer/src/lib.rs @@ -16,6 +16,6 @@ pub trait ProxyDeployer: farm_deploy::FarmDeployModule { self.farm_template_address().set(&farm_template_address); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} } diff --git a/dex/proxy-deployer/wasm/Cargo.lock b/dex/proxy-deployer/wasm/Cargo.lock index 371955a5f..02b775cc5 100644 --- a/dex/proxy-deployer/wasm/Cargo.lock +++ b/dex/proxy-deployer/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common-types" @@ -277,9 +277,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -290,9 +290,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -300,9 +300,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -312,9 +312,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -325,18 +325,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -394,9 +394,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/dex/proxy-deployer/wasm/Cargo.toml b/dex/proxy-deployer/wasm/Cargo.toml index 97ada3a24..1a9bc3b4f 100644 --- a/dex/proxy-deployer/wasm/Cargo.toml +++ b/dex/proxy-deployer/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/dex/router/Cargo.toml b/dex/router/Cargo.toml index cc3698241..f70fa5c04 100644 --- a/dex/router/Cargo.toml +++ b/dex/router/Cargo.toml @@ -15,7 +15,7 @@ path = "../../common/modules/token_send" path = "../../common/modules/pausable" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.pair] @@ -28,4 +28,4 @@ path = "../../common/modules/locking_module" path = "../../locked-asset/simple-lock" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" diff --git a/dex/router/meta/Cargo.toml b/dex/router/meta/Cargo.toml index c5deaf0be..8966e7476 100644 --- a/dex/router/meta/Cargo.toml +++ b/dex/router/meta/Cargo.toml @@ -9,5 +9,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/dex/router/src/config.rs b/dex/router/src/config.rs index 25c96a3e6..830d301c8 100644 --- a/dex/router/src/config.rs +++ b/dex/router/src/config.rs @@ -2,18 +2,38 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); use crate::{enable_swap_by_user::EnableSwapByUserConfig, factory::PairTokens}; +use pair::read_pair_storage; #[multiversx_sc::module] -pub trait ConfigModule { +pub trait ConfigModule: read_pair_storage::ReadPairStorageModule { fn is_active(&self) -> bool { self.state().get() } fn check_is_pair_sc(&self, pair_address: &ManagedAddress) { - require!( - self.address_pair_map().contains_key(pair_address), - "Not a pair SC" - ); + let first_token_id = self.get_first_token_id_mapper(pair_address.clone()).get(); + let second_token_id = self.get_second_token_id_mapper(pair_address.clone()).get(); + + let pair_tokens = PairTokens { + first_token_id: first_token_id.clone(), + second_token_id: second_token_id.clone(), + }; + + let mut pair_map_address_opt = self.pair_map().get(&pair_tokens); + if pair_map_address_opt.is_none() { + let reverse_pair_tokens = PairTokens { + first_token_id: second_token_id.clone(), + second_token_id: first_token_id.clone(), + }; + pair_map_address_opt = self.pair_map().get(&reverse_pair_tokens); + } + + require!(pair_map_address_opt.is_some(), "Not a pair SC"); + + unsafe { + let pair_map_address = pair_map_address_opt.unwrap_unchecked(); + require!(&pair_map_address == pair_address, "Not a pair SC"); + } } #[view(getPairCreationEnabled)] @@ -43,9 +63,6 @@ pub trait ConfigModule { #[storage_mapper("pair_map")] fn pair_map(&self) -> MapMapper, ManagedAddress>; - #[storage_mapper("address_pair_map")] - fn address_pair_map(&self) -> MapMapper>; - #[view(getPairTemplateAddress)] #[storage_mapper("pair_template_address")] fn pair_template_address(&self) -> SingleValueMapper; diff --git a/dex/router/src/contract.rs b/dex/router/src/contract.rs index 04b787a03..e23d0f12f 100644 --- a/dex/router/src/contract.rs +++ b/dex/router/src/contract.rs @@ -12,7 +12,7 @@ pub mod multi_pair_swap; use factory::PairTokens; use pair::config::ProxyTrait as _; use pair::fee::ProxyTrait as _; -use pair::ProxyTrait as _; +use pair::{read_pair_storage, ProxyTrait as _}; use pausable::ProxyTrait as _; const LP_TOKEN_DECIMALS: usize = 18; @@ -26,6 +26,7 @@ const USER_DEFINED_TOTAL_FEE_PERCENT: u64 = 1_000; #[multiversx_sc::contract] pub trait Router: config::ConfigModule + + read_pair_storage::ReadPairStorageModule + factory::FactoryModule + events::EventsModule + multi_pair_swap::MultiPairSwap @@ -41,7 +42,7 @@ pub trait Router: self.owner().set(&self.blockchain().get_caller()); } - #[endpoint] + #[upgrade] fn upgrade(&self) { self.state().set(false); } @@ -64,10 +65,6 @@ pub trait Router: #[endpoint] fn resume(&self, address: ManagedAddress) { if address == self.blockchain().get_sc_address() { - require!( - self.pair_map().len() == self.address_pair_map().len(), - "The size of the 2 pair maps is not the same" - ); self.state().set(true); } else { self.check_is_pair_sc(&address); @@ -317,8 +314,6 @@ pub trait Router: .unwrap_or_else(ManagedAddress::zero); } - self.address_pair_map().remove(&pair_address); - pair_address } @@ -385,23 +380,4 @@ pub trait Router: fn set_pair_creation_enabled(&self, enabled: bool) { self.pair_creation_enabled().set(enabled); } - - #[only_owner] - #[endpoint(migratePairMap)] - fn migrate_pair_map(&self) { - let pair_map = self.pair_map(); - let mut address_pair_map = self.address_pair_map(); - require!( - address_pair_map.is_empty(), - "The destination mapper must be empty" - ); - for (pair_tokens, address) in pair_map.iter() { - address_pair_map.insert(address, pair_tokens); - } - - require!( - pair_map.len() == address_pair_map.len(), - "The size of the 2 pair maps is not the same" - ); - } } diff --git a/dex/router/src/enable_swap_by_user.rs b/dex/router/src/enable_swap_by_user.rs index 7c77036c1..1a8c40770 100644 --- a/dex/router/src/enable_swap_by_user.rs +++ b/dex/router/src/enable_swap_by_user.rs @@ -1,7 +1,7 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); -use pair::{config::ProxyTrait as _, pair_actions::views::ProxyTrait as _}; +use pair::{config::ProxyTrait as _, pair_actions::views::ProxyTrait as _, read_pair_storage}; use pausable::{ProxyTrait as _, State}; use simple_lock::locked_token::LockedTokenAttributes; @@ -27,7 +27,10 @@ pub struct SafePriceResult { #[multiversx_sc::module] pub trait EnableSwapByUserModule: - config::ConfigModule + crate::factory::FactoryModule + crate::events::EventsModule + config::ConfigModule + + read_pair_storage::ReadPairStorageModule + + crate::factory::FactoryModule + + crate::events::EventsModule { #[only_owner] #[endpoint(configEnableByUserParameters)] @@ -83,6 +86,7 @@ pub trait EnableSwapByUserModule: #[payable("*")] #[endpoint(setSwapEnabledByUser)] fn set_swap_enabled_by_user(&self, pair_address: ManagedAddress) { + require!(self.is_active(), "Not active"); self.check_is_pair_sc(&pair_address); self.require_state_active_no_swaps(&pair_address); diff --git a/dex/router/src/factory.rs b/dex/router/src/factory.rs index 4994db235..fea434703 100644 --- a/dex/router/src/factory.rs +++ b/dex/router/src/factory.rs @@ -2,6 +2,7 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); use crate::config; +use pair::read_pair_storage; const TEMPORARY_OWNER_PERIOD_BLOCKS: u64 = 50; @@ -19,7 +20,7 @@ pub struct PairContractMetadata { } #[multiversx_sc::module] -pub trait FactoryModule: config::ConfigModule { +pub trait FactoryModule: config::ConfigModule + read_pair_storage::ReadPairStorageModule { #[proxy] fn pair_contract_deploy_proxy(&self) -> pair::Proxy; @@ -71,13 +72,6 @@ pub trait FactoryModule: config::ConfigModule { }, new_address.clone(), ); - self.address_pair_map().insert( - new_address.clone(), - PairTokens { - first_token_id: first_token_id.clone(), - second_token_id: second_token_id.clone(), - }, - ); self.pair_temporary_owner().insert( new_address.clone(), ( @@ -174,13 +168,6 @@ pub trait FactoryModule: config::ConfigModule { address } - #[view(getPairTokens)] - fn get_pair_tokens(&self, pair_address: ManagedAddress) -> PairTokens { - let pair_tokens_opt = self.address_pair_map().get(&pair_address); - require!(pair_tokens_opt.is_some(), "Pair address not found"); - pair_tokens_opt.unwrap() - } - fn get_pair_temporary_owner(&self, pair_address: &ManagedAddress) -> Option { let result = self.pair_temporary_owner().get(pair_address); diff --git a/dex/router/src/multi_pair_swap.rs b/dex/router/src/multi_pair_swap.rs index e69350ecd..1e47378f9 100644 --- a/dex/router/src/multi_pair_swap.rs +++ b/dex/router/src/multi_pair_swap.rs @@ -1,11 +1,9 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); -use pair::pair_actions::swap::ProxyTrait as _; - -use crate::config; - use super::factory; +use crate::config; +use pair::{pair_actions::swap::ProxyTrait as _, read_pair_storage}; type SwapOperationType = MultiValue4, ManagedBuffer, TokenIdentifier, BigUint>; @@ -15,11 +13,17 @@ pub const SWAP_TOKENS_FIXED_OUTPUT_FUNC_NAME: &[u8] = b"swapTokensFixedOutput"; #[multiversx_sc::module] pub trait MultiPairSwap: - config::ConfigModule + factory::FactoryModule + token_send::TokenSendModule + config::ConfigModule + + read_pair_storage::ReadPairStorageModule + + factory::FactoryModule + + token_send::TokenSendModule { #[payable("*")] #[endpoint(multiPairSwap)] - fn multi_pair_swap(&self, swap_operations: MultiValueEncoded>) -> ManagedVec { + fn multi_pair_swap( + &self, + swap_operations: MultiValueEncoded>, + ) -> ManagedVec { require!(self.is_active(), "Not active"); let (token_id, nonce, amount) = self.call_value().single_esdt().into_tuple(); diff --git a/dex/router/tests/router_setup/mod.rs b/dex/router/tests/router_setup/mod.rs index c72b6a971..4339d502d 100644 --- a/dex/router/tests/router_setup/mod.rs +++ b/dex/router/tests/router_setup/mod.rs @@ -284,17 +284,4 @@ where ) .assert_ok(); } - - pub fn migrate_pair_map(&mut self) { - self.blockchain_wrapper - .execute_tx( - &self.owner_address, - &self.router_wrapper, - &rust_biguint!(0u64), - |sc| { - sc.migrate_pair_map(); - }, - ) - .assert_ok(); - } } diff --git a/dex/router/tests/router_test.rs b/dex/router/tests/router_test.rs index 54c73c838..54765f2c4 100644 --- a/dex/router/tests/router_test.rs +++ b/dex/router/tests/router_test.rs @@ -134,7 +134,6 @@ fn test_router_upgrade_pair() { #[test] fn test_multi_pair_swap() { let mut router_setup = RouterSetup::new(router::contract_obj, pair::contract_obj); - router_setup.migrate_pair_map(); router_setup.add_liquidity(); @@ -255,8 +254,6 @@ fn user_enable_pair_swaps_through_router_test() { managed_address!(pair_wrapper.address_ref()), ); - sc.migrate_pair_map(); - sc.add_common_tokens_for_user_pairs(MultiValueEncoded::from(ManagedVec::from(vec![ managed_token_id!(USDC_TOKEN_ID), ]))); @@ -442,8 +439,6 @@ fn user_enable_pair_swaps_fail_test() { managed_address!(pair_wrapper.address_ref()), ); - sc.migrate_pair_map(); - sc.add_common_tokens_for_user_pairs(MultiValueEncoded::from(ManagedVec::from(vec![ managed_token_id!(USDC_TOKEN_ID), ]))); diff --git a/dex/router/wasm/Cargo.lock b/dex/router/wasm/Cargo.lock index 0f5cc1535..6b2344040 100644 --- a/dex/router/wasm/Cargo.lock +++ b/dex/router/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common-types" @@ -161,9 +161,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -174,9 +174,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -184,9 +184,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -196,9 +196,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -209,18 +209,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -278,9 +278,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/dex/router/wasm/Cargo.toml b/dex/router/wasm/Cargo.toml index dc895383b..678a87da6 100644 --- a/dex/router/wasm/Cargo.toml +++ b/dex/router/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/dex/router/wasm/src/lib.rs b/dex/router/wasm/src/lib.rs index e840498ec..ee424764b 100644 --- a/dex/router/wasm/src/lib.rs +++ b/dex/router/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 33 +// Endpoints: 30 // Async Callback: 1 -// Total number of exported functions: 35 +// Total number of exported functions: 32 #![no_std] #![allow(internal_features)] @@ -31,7 +31,6 @@ multiversx_sc_wasm_adapter::endpoints! { setFeeOn => set_fee_on setFeeOff => set_fee_off setPairCreationEnabled => set_pair_creation_enabled - migratePairMap => migrate_pair_map getPairCreationEnabled => pair_creation_enabled getState => state getOwner => owner @@ -44,7 +43,6 @@ multiversx_sc_wasm_adapter::endpoints! { getAllPairTokens => get_all_token_pairs getAllPairContractMetadata => get_all_pair_contract_metadata getPair => get_pair - getPairTokens => get_pair_tokens clearPairTemporaryOwnerStorage => clear_pair_temporary_owner_storage multiPairSwap => multi_pair_swap configEnableByUserParameters => config_enable_by_user_parameters diff --git a/energy-integration/common-modules/energy-query/Cargo.toml b/energy-integration/common-modules/energy-query/Cargo.toml index 429ddafe2..adefb3769 100644 --- a/energy-integration/common-modules/energy-query/Cargo.toml +++ b/energy-integration/common-modules/energy-query/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.energy-factory] diff --git a/energy-integration/common-modules/week-timekeeping/Cargo.toml b/energy-integration/common-modules/week-timekeeping/Cargo.toml index 32e16b01e..b4af11ce3 100644 --- a/energy-integration/common-modules/week-timekeeping/Cargo.toml +++ b/energy-integration/common-modules/week-timekeeping/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.common-types] diff --git a/energy-integration/common-modules/weekly-rewards-splitting/Cargo.toml b/energy-integration/common-modules/weekly-rewards-splitting/Cargo.toml index 0603f0084..36bb5efe2 100644 --- a/energy-integration/common-modules/weekly-rewards-splitting/Cargo.toml +++ b/energy-integration/common-modules/weekly-rewards-splitting/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.energy-query] diff --git a/energy-integration/common-types/Cargo.toml b/energy-integration/common-types/Cargo.toml index b2ba8bc79..a368f9f75 100644 --- a/energy-integration/common-types/Cargo.toml +++ b/energy-integration/common-types/Cargo.toml @@ -8,5 +8,5 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] diff --git a/energy-integration/energy-factory-mock/Cargo.toml b/energy-integration/energy-factory-mock/Cargo.toml index 6e246e8fb..1c919df1f 100644 --- a/energy-integration/energy-factory-mock/Cargo.toml +++ b/energy-integration/energy-factory-mock/Cargo.toml @@ -12,8 +12,8 @@ path = "src/lib.rs" path = "../common-modules/energy-query" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" diff --git a/energy-integration/energy-factory-mock/meta/Cargo.toml b/energy-integration/energy-factory-mock/meta/Cargo.toml index 94241670d..a2872b370 100644 --- a/energy-integration/energy-factory-mock/meta/Cargo.toml +++ b/energy-integration/energy-factory-mock/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/energy-integration/energy-factory-mock/wasm/Cargo.lock b/energy-integration/energy-factory-mock/wasm/Cargo.lock index 0693d6d5f..63470f3ab 100644 --- a/energy-integration/energy-factory-mock/wasm/Cargo.lock +++ b/energy-integration/energy-factory-mock/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common_errors" @@ -128,9 +128,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -141,9 +141,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -151,9 +151,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -163,9 +163,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -176,18 +176,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -212,9 +212,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/energy-integration/energy-factory-mock/wasm/Cargo.toml b/energy-integration/energy-factory-mock/wasm/Cargo.toml index 426c4c9f0..0d381efb7 100644 --- a/energy-integration/energy-factory-mock/wasm/Cargo.toml +++ b/energy-integration/energy-factory-mock/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/energy-integration/energy-update/Cargo.toml b/energy-integration/energy-update/Cargo.toml index 01489f0d7..c7a8d41c8 100644 --- a/energy-integration/energy-update/Cargo.toml +++ b/energy-integration/energy-update/Cargo.toml @@ -9,11 +9,11 @@ publish = false path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" [dependencies.farm] path = "../../dex/farm" @@ -25,4 +25,4 @@ path = "../common-modules/weekly-rewards-splitting" num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" diff --git a/energy-integration/energy-update/meta/Cargo.toml b/energy-integration/energy-update/meta/Cargo.toml index aa816ac82..627514dae 100644 --- a/energy-integration/energy-update/meta/Cargo.toml +++ b/energy-integration/energy-update/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/energy-integration/energy-update/src/lib.rs b/energy-integration/energy-update/src/lib.rs index a8e10213f..6cb9a7520 100644 --- a/energy-integration/energy-update/src/lib.rs +++ b/energy-integration/energy-update/src/lib.rs @@ -9,7 +9,7 @@ pub trait EnergyUpdate { #[init] fn init(&self) {} - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[endpoint(updateFarmsEnergyForUser)] diff --git a/energy-integration/energy-update/wasm/Cargo.lock b/energy-integration/energy-update/wasm/Cargo.lock index 559a8a519..9d23276fc 100644 --- a/energy-integration/energy-update/wasm/Cargo.lock +++ b/energy-integration/energy-update/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common-types" @@ -295,9 +295,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -308,9 +308,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -318,9 +318,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -330,9 +330,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -343,18 +343,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -412,9 +412,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/energy-integration/energy-update/wasm/Cargo.toml b/energy-integration/energy-update/wasm/Cargo.toml index 399b3a678..5042edb22 100644 --- a/energy-integration/energy-update/wasm/Cargo.toml +++ b/energy-integration/energy-update/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/energy-integration/farm-boosted-yields/Cargo.toml b/energy-integration/farm-boosted-yields/Cargo.toml index 5a75c8b80..afd011e84 100644 --- a/energy-integration/farm-boosted-yields/Cargo.toml +++ b/energy-integration/farm-boosted-yields/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.config] diff --git a/energy-integration/farm-boosted-yields/src/lib.rs b/energy-integration/farm-boosted-yields/src/lib.rs index 09bacc676..0c8543132 100644 --- a/energy-integration/farm-boosted-yields/src/lib.rs +++ b/energy-integration/farm-boosted-yields/src/lib.rs @@ -15,6 +15,7 @@ use weekly_rewards_splitting::{ pub mod boosted_yields_factors; const MAX_PERCENT: u64 = 10_000; +const DEFAULT_MIN_FARM_AMT: u64 = 1; pub struct SplitReward { pub base_farm: BigUint, @@ -124,14 +125,19 @@ pub trait FarmBoostedYieldsModule: fn clear_user_energy_if_needed(&self, original_caller: &ManagedAddress) { let opt_config = self.try_get_boosted_yields_config(); let user_total_farm_position = self.get_user_total_farm_position(original_caller); - if let Some(config) = opt_config { - let boosted_yields_factors = config.get_latest_factors(); - self.clear_user_energy( - original_caller, - &user_total_farm_position.total_farm_position, - &boosted_yields_factors.min_farm_amount, - ); - } + let min_farm_amount = match opt_config { + Some(config) => { + let boosted_yields_factors = config.get_latest_factors(); + boosted_yields_factors.min_farm_amount.clone() + } + None => BigUint::from(DEFAULT_MIN_FARM_AMT), + }; + + self.clear_user_energy( + original_caller, + &user_total_farm_position.total_farm_position, + &min_farm_amount, + ); } #[view(getBoostedYieldsRewardsPercentage)] diff --git a/energy-integration/fees-collector/Cargo.toml b/energy-integration/fees-collector/Cargo.toml index 1b233b7f6..09b6525d5 100644 --- a/energy-integration/fees-collector/Cargo.toml +++ b/energy-integration/fees-collector/Cargo.toml @@ -9,11 +9,11 @@ publish = false path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" [dependencies.energy-query] path = "../common-modules/energy-query" @@ -49,7 +49,7 @@ path = "../../common/common_errors" num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" [dev-dependencies.sc_whitelist_module] path = "../../common/modules/sc_whitelist_module" diff --git a/energy-integration/fees-collector/meta/Cargo.toml b/energy-integration/fees-collector/meta/Cargo.toml index c91986348..f4cd4b07f 100644 --- a/energy-integration/fees-collector/meta/Cargo.toml +++ b/energy-integration/fees-collector/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/energy-integration/fees-collector/src/lib.rs b/energy-integration/fees-collector/src/lib.rs index b5a37d7fb..e78ed6812 100644 --- a/energy-integration/fees-collector/src/lib.rs +++ b/energy-integration/fees-collector/src/lib.rs @@ -44,7 +44,7 @@ pub trait FeesCollector: self.energy_factory_address().set(&energy_factory_address); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[endpoint(claimRewards)] diff --git a/energy-integration/fees-collector/wasm/Cargo.lock b/energy-integration/fees-collector/wasm/Cargo.lock index d31ccf2dc..c91a53592 100644 --- a/energy-integration/fees-collector/wasm/Cargo.lock +++ b/energy-integration/fees-collector/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common-types" @@ -154,9 +154,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -167,9 +167,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -177,9 +177,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -189,9 +189,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -202,18 +202,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -238,9 +238,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/energy-integration/fees-collector/wasm/Cargo.toml b/energy-integration/fees-collector/wasm/Cargo.toml index 67ff1cdc8..cf5c52d0b 100644 --- a/energy-integration/fees-collector/wasm/Cargo.toml +++ b/energy-integration/fees-collector/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/energy-integration/governance-v2/Cargo.toml b/energy-integration/governance-v2/Cargo.toml index 1b190cd64..606b40d8c 100644 --- a/energy-integration/governance-v2/Cargo.toml +++ b/energy-integration/governance-v2/Cargo.toml @@ -12,7 +12,7 @@ path = "src/lib.rs" path = "../common-modules/energy-query" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.permissions_module] @@ -28,7 +28,7 @@ path = "../common-modules/weekly-rewards-splitting" num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" [dev-dependencies.energy-factory-mock] path = "../energy-factory-mock" diff --git a/energy-integration/governance-v2/meta/Cargo.toml b/energy-integration/governance-v2/meta/Cargo.toml index ca5a80d29..3187a47ce 100644 --- a/energy-integration/governance-v2/meta/Cargo.toml +++ b/energy-integration/governance-v2/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/energy-integration/governance-v2/src/lib.rs b/energy-integration/governance-v2/src/lib.rs index 0fcb53dca..2014b3a53 100644 --- a/energy-integration/governance-v2/src/lib.rs +++ b/energy-integration/governance-v2/src/lib.rs @@ -61,7 +61,7 @@ pub trait GovernanceV2: self.try_change_fee_token_id(fee_token); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} /// Propose a list of actions. diff --git a/energy-integration/governance-v2/wasm/Cargo.lock b/energy-integration/governance-v2/wasm/Cargo.lock index 71cf78cfd..6ff033cc1 100644 --- a/energy-integration/governance-v2/wasm/Cargo.lock +++ b/energy-integration/governance-v2/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common-types" @@ -165,9 +165,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -178,9 +178,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -188,9 +188,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -200,9 +200,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -213,18 +213,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -258,9 +258,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/energy-integration/governance-v2/wasm/Cargo.toml b/energy-integration/governance-v2/wasm/Cargo.toml index 02189aabe..3615366fb 100644 --- a/energy-integration/governance-v2/wasm/Cargo.toml +++ b/energy-integration/governance-v2/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/farm-staking/farm-staking-proxy/Cargo.toml b/farm-staking/farm-staking-proxy/Cargo.toml index 7e986d221..fb3c4b339 100644 --- a/farm-staking/farm-staking-proxy/Cargo.toml +++ b/farm-staking/farm-staking-proxy/Cargo.toml @@ -12,11 +12,11 @@ path = "src/lib.rs" hex-literal = "0.3.1" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" [dependencies.farm] path = "../../dex/farm" @@ -67,7 +67,7 @@ path = "../../energy-integration/common-modules/energy-query" num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" [dev-dependencies.farm_token] path = "../../common/modules/farm/farm_token" diff --git a/farm-staking/farm-staking-proxy/meta/Cargo.toml b/farm-staking/farm-staking-proxy/meta/Cargo.toml index 404e23810..1c7a0f9fe 100644 --- a/farm-staking/farm-staking-proxy/meta/Cargo.toml +++ b/farm-staking/farm-staking-proxy/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/farm-staking/farm-staking-proxy/src/lib.rs b/farm-staking/farm-staking-proxy/src/lib.rs index bd8ef7013..7bfc66bab 100644 --- a/farm-staking/farm-staking-proxy/src/lib.rs +++ b/farm-staking/farm-staking-proxy/src/lib.rs @@ -58,6 +58,6 @@ pub trait FarmStakingProxy: self.lp_token_id().set_if_empty(&lp_token_id); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} } diff --git a/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp.rs b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp.rs index d7ee78e8d..34fbe059e 100644 --- a/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp.rs +++ b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp.rs @@ -7,13 +7,22 @@ pub mod staking_farm_with_lp_staking_contract_setup; multiversx_sc::imports!(); +use config::ConfigModule; use constants::*; use farm_staking_proxy::dual_yield_token::DualYieldTokenAttributes; use farm_staking_proxy::proxy_actions::unstake::ProxyUnstakeModule; +use farm_staking::{ + claim_only_boosted_staking_rewards::ClaimOnlyBoostedStakingRewardsModule, FarmStaking, +}; +use farm_with_locked_rewards::Farm; use multiversx_sc::codec::Empty; -use multiversx_sc_scenario::{managed_biguint, managed_token_id, rust_biguint, DebugApi}; +use multiversx_sc_scenario::{ + managed_address, managed_biguint, managed_token_id, rust_biguint, DebugApi, +}; +use pair::pair_actions::swap::SwapModule; +use simple_lock::locked_token::LockedTokenAttributes; use staking_farm_with_lp_staking_contract_interactions::*; #[test] @@ -625,3 +634,583 @@ fn test_farm_stake_proxy_merging_boosted_rewards() { ) }); } + +#[test] +fn original_caller_negative_test() { + let mut setup = FarmStakingSetup::new( + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + farm_staking::contract_obj, + farm_staking_proxy::contract_obj, + ); + + let user = setup.user_addr.clone(); + let random_user = setup.b_mock.create_user_account(&rust_biguint!(0u64)); + setup + .stake_farm_for_other_user(&user, &random_user, 1, USER_TOTAL_LP_TOKENS) + .assert_error(4, "Item not whitelisted"); + + setup + .stake_farm_for_other_user(&user, &user, 1, USER_TOTAL_LP_TOKENS) + .assert_ok(); + + setup + .b_mock + .set_block_nonce(BLOCK_NONCE_AFTER_PAIR_SETUP + 20); + setup.b_mock.set_block_epoch(20); + + setup + .claim_dual_yield_for_other_user(&user, &random_user, 1, USER_TOTAL_LP_TOKENS) + .assert_error(4, "Item not whitelisted"); + + setup + .claim_dual_yield_for_other_user(&user, &user, 1, USER_TOTAL_LP_TOKENS) + .assert_ok(); + + setup + .unstake_dual_yield_for_other_user(&user, &random_user, 2, USER_TOTAL_LP_TOKENS) + .assert_error(4, "Item not whitelisted"); + + setup + .unstake_dual_yield_for_other_user(&user, &user, 2, USER_TOTAL_LP_TOKENS) + .assert_ok(); +} + +#[test] +fn claim_for_others_positive_test() { + let mut setup = FarmStakingSetup::new( + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + farm_staking::contract_obj, + farm_staking_proxy::contract_obj, + ); + + // Boosted rewards setup + setup + .b_mock + .execute_tx( + &setup.owner_addr, + &setup.staking_farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + }, + ) + .assert_ok(); + + setup.set_lp_farm_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + let farm_amount = 50_000_000u64; + let user_address = setup.user_addr.clone(); + let temp_user = setup + .b_mock + .create_user_account(&rust_biguint!(100_000_000)); + setup.exit_lp_farm(&user_address, 1, USER_TOTAL_LP_TOKENS); + setup.b_mock.set_esdt_balance( + &setup.user_addr, + LP_TOKEN_ID, + &rust_biguint!(farm_amount * 2), + ); + setup + .b_mock + .set_esdt_balance(&temp_user, LP_TOKEN_ID, &rust_biguint!(1)); + + setup.b_mock.set_block_epoch(2); + + setup.set_user_energy(&user_address, 1_000, 2, 1); + let farm_token_nonce = setup.enter_lp_farm(&user_address, farm_amount); + + // User enters Metastaking + let first_dual_yield_token_nonce = + setup.stake_farm_lp_proxy(farm_token_nonce, farm_amount, 1, farm_amount); + setup.b_mock.execute_in_managed_environment(|| { + setup.b_mock.check_nft_balance( + &setup.user_addr, + DUAL_YIELD_TOKEN_ID, + first_dual_yield_token_nonce, + &rust_biguint!(farm_amount), + Some(&DualYieldTokenAttributes:: { + lp_farm_token_nonce: farm_token_nonce, + lp_farm_token_amount: managed_biguint!(farm_amount), + staking_farm_token_nonce: 1, + staking_farm_token_amount: managed_biguint!(farm_amount), + }), + ) + }); + // User claims rewards to get his energy registered + setup + .claim_dual_yield_for_other_user(&user_address, &user_address, 1, farm_amount) + .assert_ok(); + + // advance blocks - 10 blocks - 10 * 5_000 = 50_000 total rewards + // 37_500 base farm, 12_500 boosted yields + let boosted_rewards = 12_500u64; + setup.b_mock.set_block_nonce(110); + + // farm staking boosted rewards + let farm_staking_boosted_rewards = 10u64; + + // random tx on end of week 1, to cummulate rewards + setup.b_mock.set_block_epoch(6); + setup.set_user_energy(&user_address, 1_000, 6, 1); + setup.set_user_energy(&temp_user, 1, 6, 1); + let temp_user_farm_token_nonce = setup.enter_lp_farm(&temp_user, 1); + setup.exit_lp_farm(&temp_user, temp_user_farm_token_nonce, 1); + + setup.stake_farm(9000000, 9000000); + setup.staking_farm_unstake(3, 9000000, 0, 9000000); + + // advance 1 week + setup.b_mock.set_block_epoch(10); + setup.set_user_energy(&user_address, 1_000, 10, 1); + + // User allows claiming of boosted rewards by other users + setup + .b_mock + .execute_tx( + &user_address, + &setup.lp_farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.allow_external_claim_boosted_rewards(true); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_tx( + &user_address, + &setup.staking_farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.allow_external_claim_boosted_rewards(true); + }, + ) + .assert_ok(); + + // Random user claims boosted rewards for the user + let user_initial_farm_staking_tokens_balance = 990000000; + setup + .b_mock + .check_esdt_balance(&temp_user, RIDE_TOKEN_ID, &rust_biguint!(0)); + setup.b_mock.check_esdt_balance( + &user_address, + RIDE_TOKEN_ID, + &rust_biguint!(user_initial_farm_staking_tokens_balance), + ); + setup + .b_mock + .check_nft_balance::>( + &temp_user, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(0), + None, + ); + setup + .b_mock + .check_nft_balance::>( + &user_address, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(0), + None, + ); + + setup + .b_mock + .execute_tx( + &temp_user, + &setup.lp_farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.claim_boosted_rewards(OptionalValue::Some(managed_address!(&user_address))); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_tx( + &temp_user, + &setup.staking_farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.claim_boosted_rewards(OptionalValue::Some(managed_address!(&user_address))); + }, + ) + .assert_ok(); + + setup + .b_mock + .check_esdt_balance(&temp_user, RIDE_TOKEN_ID, &rust_biguint!(0)); + setup.b_mock.check_esdt_balance( + &user_address, + RIDE_TOKEN_ID, + &rust_biguint!(user_initial_farm_staking_tokens_balance + farm_staking_boosted_rewards), + ); + setup + .b_mock + .check_nft_balance::>( + &temp_user, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(0), + None, + ); + setup + .b_mock + .check_nft_balance::>( + &user_address, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(boosted_rewards), + None, + ); +} + +#[test] +fn stake_farm_through_proxy_migration_test() { + let mut setup = FarmStakingSetup::new( + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + farm_staking::contract_obj, + farm_staking_proxy::contract_obj, + ); + + let user = setup.user_addr.clone(); + let mut user_total_staking_farm_position = 0; + let mut user_total_lp_farm_position = 0; + let farm_amount = 100_000_000; + + setup.check_user_total_staking_farm_position(&user, user_total_staking_farm_position); + setup.check_user_total_lp_farm_position(&user, user_total_lp_farm_position); + let dual_yield_token_nonce1 = setup.stake_farm_lp_proxy(1, farm_amount, 1, farm_amount); + let dual_yield_token_nonce2 = setup.stake_farm_lp_proxy(1, farm_amount, 2, farm_amount); + let dual_yield_token_nonce3 = setup.stake_farm_lp_proxy(1, farm_amount, 3, farm_amount); + + setup.b_mock.execute_in_managed_environment(|| { + setup.b_mock.check_nft_balance( + &user, + DUAL_YIELD_TOKEN_ID, + dual_yield_token_nonce1, + &rust_biguint!(farm_amount), + Some(&DualYieldTokenAttributes:: { + lp_farm_token_nonce: 1, + lp_farm_token_amount: managed_biguint!(farm_amount), + staking_farm_token_nonce: 1, + staking_farm_token_amount: managed_biguint!(farm_amount), + }), + ) + }); + + user_total_staking_farm_position += farm_amount * 3; + user_total_lp_farm_position += 1001000000; + setup.check_user_total_staking_farm_position(&user, user_total_staking_farm_position); + setup.check_user_total_lp_farm_position(&user, user_total_lp_farm_position); + + // Simulate the current position as old positions + setup.set_user_total_staking_farm_position(&user, 0); + setup.set_user_total_lp_farm_position(&user, 0); + setup.set_staking_farm_migration_nonce(4); + setup.set_lp_farm_migration_nonce(2); + + user_total_staking_farm_position = 0; + user_total_lp_farm_position = 0; + setup.check_user_total_staking_farm_position(&user, user_total_staking_farm_position); + setup.check_user_total_lp_farm_position(&user, user_total_lp_farm_position); + + let dual_yield_token_payments = vec![NonceAmountPair { + nonce: dual_yield_token_nonce1, + amount: farm_amount, + }]; + + // User enters with new farming tokens + 1 old position + let enter_dual_yield_token_nonce = + setup.stake_farm_lp_proxy_multiple(1, farm_amount, dual_yield_token_payments); + + // check user staking farm tokens + setup.b_mock.execute_in_managed_environment(|| { + setup.b_mock.check_nft_balance( + &user, + DUAL_YIELD_TOKEN_ID, + enter_dual_yield_token_nonce, + &rust_biguint!(farm_amount * 2), + Some(&DualYieldTokenAttributes:: { + lp_farm_token_nonce: 2, + lp_farm_token_amount: managed_biguint!(farm_amount * 2), + staking_farm_token_nonce: 4, + staking_farm_token_amount: managed_biguint!(farm_amount * 2), + }), + ) + }); + + // check proxy SC tokens + setup.b_mock.execute_in_managed_environment(|| { + setup.b_mock.check_nft_balance::( + setup.proxy_wrapper.address_ref(), + LP_FARM_TOKEN_ID, + 2, + &rust_biguint!(farm_amount * 2), + None, //current attributes + ) + }); + + user_total_staking_farm_position += farm_amount * 2; + user_total_lp_farm_position += farm_amount * 2; + setup.check_user_total_staking_farm_position(&user, user_total_staking_farm_position); + setup.check_user_total_lp_farm_position(&user, user_total_lp_farm_position); + + // User claim with 1 old position + let claim_dual_yield_token_nonce = + setup.claim_rewards_proxy(dual_yield_token_nonce2, farm_amount, 0, 0, farm_amount); + + // check user staking farm tokens + setup.b_mock.execute_in_managed_environment(|| { + setup.b_mock.check_nft_balance( + &user, + DUAL_YIELD_TOKEN_ID, + claim_dual_yield_token_nonce, + &rust_biguint!(farm_amount), + Some(&DualYieldTokenAttributes:: { + lp_farm_token_nonce: 3, + lp_farm_token_amount: managed_biguint!(farm_amount), + staking_farm_token_nonce: 5, + staking_farm_token_amount: managed_biguint!(farm_amount), + }), + ) + }); + + user_total_staking_farm_position += farm_amount; + user_total_lp_farm_position += farm_amount; + setup.check_user_total_staking_farm_position(&user, user_total_staking_farm_position); + setup.check_user_total_lp_farm_position(&user, user_total_lp_farm_position); + + // User exits with 1 half old position + setup.unstake_proxy( + dual_yield_token_nonce3, + farm_amount / 2, + 49950000, + 0, + 0, + 49950000, + 10, + ); + + // Total positions should remain the same + setup.check_user_total_staking_farm_position(&user, user_total_staking_farm_position); + setup.check_user_total_lp_farm_position(&user, user_total_lp_farm_position); +} + +#[test] +fn total_farm_position_after_claim_and_exit_metastaking_test() { + let mut setup = FarmStakingSetup::new( + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + farm_staking::contract_obj, + farm_staking_proxy::contract_obj, + ); + + // Boosted rewards setup + setup + .b_mock + .execute_tx( + &setup.owner_addr, + &setup.staking_farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + }, + ) + .assert_ok(); + + setup.set_lp_farm_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + let farm_amount = 100_000_000u64; + let user_address = setup.user_addr.clone(); + let temp_user = setup + .b_mock + .create_user_account(&rust_biguint!(farm_amount)); + setup.exit_lp_farm(&user_address, 1, USER_TOTAL_LP_TOKENS); + setup + .b_mock + .set_esdt_balance(&setup.user_addr, LP_TOKEN_ID, &rust_biguint!(farm_amount)); + setup + .b_mock + .set_esdt_balance(&temp_user, LP_TOKEN_ID, &rust_biguint!(1)); + + setup.b_mock.set_block_epoch(2); + + setup.set_user_energy(&user_address, 1_000, 2, 1); + let farm_token_nonce = setup.enter_lp_farm(&user_address, farm_amount); + + setup.check_user_total_staking_farm_position(&user_address, 0); + + // User enters Metastaking + setup.stake_farm_lp_proxy(farm_token_nonce, farm_amount, 1, farm_amount); + + // User has his total position saved + setup.check_user_total_staking_farm_position(&user_address, farm_amount); + + // User claims rewards to get his energy registered + setup + .claim_dual_yield_for_other_user(&user_address, &user_address, 1, farm_amount) + .assert_ok(); + + // User total farm position should be the same, as no swaps happened + setup.check_user_total_staking_farm_position(&user_address, farm_amount); + + // Random swaps to change the LP ratio + setup + .b_mock + .set_esdt_balance(&temp_user, WEGLD_TOKEN_ID, &rust_biguint!(300_000_000u64)); + + setup.b_mock.set_block_nonce(700); + setup.b_mock.set_block_round(700); + setup + .b_mock + .execute_esdt_transfer( + &temp_user, + &setup.pair_wrapper, + WEGLD_TOKEN_ID, + 0, + &rust_biguint!(100_000_000u64), + |sc| { + sc.swap_tokens_fixed_input(managed_token_id!(RIDE_TOKEN_ID), managed_biguint!(1)); + }, + ) + .assert_ok(); + + setup.b_mock.set_block_nonce(800); + setup.b_mock.set_block_round(800); + setup + .b_mock + .execute_esdt_transfer( + &temp_user, + &setup.pair_wrapper, + WEGLD_TOKEN_ID, + 0, + &rust_biguint!(100_000_000u64), + |sc| { + sc.swap_tokens_fixed_input(managed_token_id!(RIDE_TOKEN_ID), managed_biguint!(1)); + }, + ) + .assert_ok(); + + setup.b_mock.set_block_nonce(1250); + setup.b_mock.set_block_round(1250); + setup + .b_mock + .execute_esdt_transfer( + &temp_user, + &setup.pair_wrapper, + WEGLD_TOKEN_ID, + 0, + &rust_biguint!(100_000_000u64), + |sc| { + sc.swap_tokens_fixed_input(managed_token_id!(RIDE_TOKEN_ID), managed_biguint!(1)); + }, + ) + .assert_ok(); + + // random tx on end of week 1, to cummulate rewards + setup.b_mock.set_block_epoch(6); + setup.set_user_energy(&user_address, 1_000, 6, 1); + setup.set_user_energy(&temp_user, 1, 6, 1); + let temp_user_farm_token_nonce = setup.enter_lp_farm(&temp_user, 1); + setup.exit_lp_farm(&temp_user, temp_user_farm_token_nonce, 1); + + setup.stake_farm(9000000, 9000000); + setup.staking_farm_unstake(3, 9000000, 0, 9000000); + + // advance 1 week + setup.b_mock.set_block_epoch(10); + setup.set_user_energy(&user_address, 1_000, 10, 1); + + // User total farm position should still be the same + setup.check_user_total_staking_farm_position(&user_address, farm_amount); + + // User claims rewards + setup + .b_mock + .check_nft_balance::>( + &user_address, + DUAL_YIELD_TOKEN_ID, + 2, + &rust_biguint!(farm_amount), + None, + ); + + setup + .claim_dual_yield_for_other_user(&user_address, &user_address, 2, farm_amount) + .assert_ok(); + + // Total farm position should be updated after claim, as a few swaps happened + let new_expected_token_amount = 92_416_406u64; + setup.check_user_total_staking_farm_position(&user_address, new_expected_token_amount); + + // User does not have any dual yield tokens with the before the claim token nonce + setup + .b_mock + .check_nft_balance::>( + &user_address, + DUAL_YIELD_TOKEN_ID, + 2, + &rust_biguint!(0), + None, + ); + + setup + .b_mock + .check_nft_balance::>( + &user_address, + DUAL_YIELD_TOKEN_ID, + 3, + &rust_biguint!(new_expected_token_amount), + None, + ); + + // User exits with partial position + let user_remaining_position = 50_000_000u64; + setup + .unstake_dual_yield_for_other_user( + &user_address, + &user_address, + 3, + new_expected_token_amount - user_remaining_position, + ) + .assert_ok(); + + setup + .b_mock + .check_nft_balance::>( + &user_address, + DUAL_YIELD_TOKEN_ID, + 3, + &rust_biguint!(user_remaining_position), + None, + ); + + setup.check_user_total_staking_farm_position(&user_address, user_remaining_position); + + // User exits with remaining position + setup + .unstake_dual_yield_for_other_user(&user_address, &user_address, 3, user_remaining_position) + .assert_ok(); + + setup + .b_mock + .check_nft_balance::>( + &user_address, + DUAL_YIELD_TOKEN_ID, + 3, + &rust_biguint!(0), + None, + ); + + // Total farm position should be 0 after full unstake + setup.check_user_total_staking_farm_position(&user_address, 0); +} diff --git a/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_interactions/mod.rs b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_interactions/mod.rs index dca88dce5..151a4f5ec 100644 --- a/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_interactions/mod.rs +++ b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_interactions/mod.rs @@ -1,5 +1,6 @@ #![allow(deprecated)] +use config::{ConfigModule, UserTotalFarmPosition}; use energy_factory::energy::EnergyModule; use energy_query::Energy; use farm_with_locked_rewards::Farm; @@ -9,6 +10,7 @@ use multiversx_sc::{ }; use multiversx_sc_scenario::{ managed_address, managed_biguint, managed_token_id, rust_biguint, + testing_framework::TxResult, whitebox_legacy::TxTokenTransfer, whitebox_legacy::{BlockchainStateWrapper, ContractObjWrapper}, DebugApi, @@ -111,8 +113,12 @@ where lp_farm_builder, USER_TOTAL_LP_TOKENS, ); - let staking_farm_wrapper = - setup_staking_farm(&owner_addr, &mut b_mock, staking_farm_builder); + let staking_farm_wrapper = setup_staking_farm( + &owner_addr, + energy_factory_wrapper.address_ref(), + &mut b_mock, + staking_farm_builder, + ); let proxy_wrapper = setup_proxy( &owner_addr, lp_farm_wrapper.address_ref(), @@ -518,6 +524,85 @@ where new_farm_token_nonce } + pub fn stake_farm_for_other_user( + &mut self, + caller: &Address, + original_caller: &Address, + lp_farm_token_nonce: u64, + lp_farm_token_stake_amount: u64, + ) -> TxResult { + self.b_mock.execute_esdt_transfer( + caller, + &self.proxy_wrapper, + LP_FARM_TOKEN_ID, + lp_farm_token_nonce, + &rust_biguint!(lp_farm_token_stake_amount), + |sc| { + if caller == original_caller { + sc.stake_farm_tokens(OptionalValue::None); + } else { + sc.stake_farm_tokens(OptionalValue::Some(managed_address!(original_caller))); + } + }, + ) + } + + pub fn claim_dual_yield_for_other_user( + &mut self, + caller: &Address, + original_caller: &Address, + dual_yield_token_nonce: u64, + dual_yield_token_amount: u64, + ) -> TxResult { + self.b_mock.execute_esdt_transfer( + caller, + &self.proxy_wrapper, + DUAL_YIELD_TOKEN_ID, + dual_yield_token_nonce, + &rust_biguint!(dual_yield_token_amount), + |sc| { + if caller == original_caller { + sc.claim_dual_yield_endpoint(OptionalValue::None); + } else { + sc.claim_dual_yield_endpoint(OptionalValue::Some(managed_address!( + original_caller + ))); + } + }, + ) + } + + pub fn unstake_dual_yield_for_other_user( + &mut self, + caller: &Address, + original_caller: &Address, + dual_yield_token_nonce: u64, + dual_yield_token_amount: u64, + ) -> TxResult { + self.b_mock.execute_esdt_transfer( + caller, + &self.proxy_wrapper, + DUAL_YIELD_TOKEN_ID, + dual_yield_token_nonce, + &rust_biguint!(dual_yield_token_amount), + |sc| { + if caller == original_caller { + sc.unstake_farm_tokens( + managed_biguint!(1u64), + managed_biguint!(1u64), + OptionalValue::None, + ); + } else { + sc.unstake_farm_tokens( + managed_biguint!(1u64), + managed_biguint!(1u64), + OptionalValue::Some(managed_address!(original_caller)), + ); + } + }, + ) + } + pub fn set_user_energy( &mut self, user: &Address, @@ -556,4 +641,104 @@ where ) .assert_ok(); } + + pub fn set_staking_farm_migration_nonce(&mut self, migration_nonce: u64) { + self.b_mock + .execute_tx( + &self.owner_addr, + &self.staking_farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.farm_position_migration_nonce().set(migration_nonce); + }, + ) + .assert_ok(); + } + + pub fn set_lp_farm_migration_nonce(&mut self, migration_nonce: u64) { + self.b_mock + .execute_tx( + &self.owner_addr, + &self.lp_farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.farm_position_migration_nonce().set(migration_nonce); + }, + ) + .assert_ok(); + } + + pub fn set_user_total_staking_farm_position( + &mut self, + user_addr: &Address, + new_farm_position: u64, + ) { + self.b_mock + .execute_tx( + &self.owner_addr, + &self.staking_farm_wrapper, + &rust_biguint!(0), + |sc| { + let user_farm_position = UserTotalFarmPosition { + total_farm_position: managed_biguint!(new_farm_position), + ..Default::default() + }; + sc.user_total_farm_position(&managed_address!(user_addr)) + .set(user_farm_position); + }, + ) + .assert_ok(); + } + + pub fn set_user_total_lp_farm_position(&mut self, user_addr: &Address, new_farm_position: u64) { + self.b_mock + .execute_tx( + &self.owner_addr, + &self.lp_farm_wrapper, + &rust_biguint!(0), + |sc| { + let user_farm_position = UserTotalFarmPosition { + total_farm_position: managed_biguint!(new_farm_position), + ..Default::default() + }; + sc.user_total_farm_position(&managed_address!(user_addr)) + .set(user_farm_position); + }, + ) + .assert_ok(); + } + + pub fn check_user_total_staking_farm_position( + &mut self, + user_addr: &Address, + expected_amount: u64, + ) { + self.b_mock + .execute_query(&self.staking_farm_wrapper, |sc| { + let user_total_farm_position_mapper = + sc.user_total_farm_position(&managed_address!(user_addr)); + if expected_amount > 0 && !user_total_farm_position_mapper.is_empty() { + assert_eq!( + managed_biguint!(expected_amount), + user_total_farm_position_mapper.get().total_farm_position + ); + } + }) + .assert_ok(); + } + + pub fn check_user_total_lp_farm_position(&mut self, user_addr: &Address, expected_amount: u64) { + self.b_mock + .execute_query(&self.lp_farm_wrapper, |sc| { + let user_total_farm_position_mapper = + sc.user_total_farm_position(&managed_address!(user_addr)); + if expected_amount > 0 && !user_total_farm_position_mapper.is_empty() { + assert_eq!( + managed_biguint!(expected_amount), + user_total_farm_position_mapper.get().total_farm_position + ); + } + }) + .assert_ok(); + } } diff --git a/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_setup/mod.rs b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_setup/mod.rs index 2c67d2714..81bb78dbd 100644 --- a/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_setup/mod.rs +++ b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_setup/mod.rs @@ -1,5 +1,7 @@ #![allow(deprecated)] +use energy_query::EnergyQueryModule; +use farm_boosted_yields::boosted_yields_factors::BoostedYieldsFactorsModule; use multiversx_sc::storage::mappers::StorageTokenWrapper; use multiversx_sc::types::{Address, EsdtLocalRole, ManagedAddress, MultiValueEncoded}; use multiversx_sc_scenario::{ @@ -24,6 +26,7 @@ use crate::constants::*; pub fn setup_staking_farm( owner_addr: &Address, + energy_factory_address: &Address, b_mock: &mut BlockchainStateWrapper, builder: StakingContractObjBuilder, ) -> ContractObjWrapper, StakingContractObjBuilder> @@ -49,6 +52,8 @@ where MultiValueEncoded::new(), ); + sc.energy_factory_address() + .set(managed_address!(energy_factory_address)); sc.farm_token() .set_token_id(managed_token_id!(STAKING_FARM_TOKEN_ID)); @@ -62,6 +67,18 @@ where }) .assert_ok(); + b_mock + .execute_tx(owner_addr, &farm_staking_wrapper, &rust_zero, |sc| { + sc.set_boosted_yields_factors( + managed_biguint!(USER_REWARDS_BASE_CONST), + managed_biguint!(USER_REWARDS_ENERGY_CONST), + managed_biguint!(USER_REWARDS_FARM_CONST), + managed_biguint!(MIN_ENERGY_AMOUNT_FOR_BOOSTED_YIELDS), + managed_biguint!(MIN_FARM_AMOUNT_FOR_BOOSTED_YIELDS), + ); + }) + .assert_ok(); + b_mock.set_esdt_balance( farm_staking_wrapper.address_ref(), STAKING_REWARD_TOKEN_ID, diff --git a/farm-staking/farm-staking-proxy/wasm/Cargo.lock b/farm-staking/farm-staking-proxy/wasm/Cargo.lock index feded38ab..4462d4205 100644 --- a/farm-staking/farm-staking-proxy/wasm/Cargo.lock +++ b/farm-staking/farm-staking-proxy/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common-types" @@ -376,9 +376,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal 0.4.1", @@ -389,9 +389,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -399,9 +399,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -411,9 +411,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -424,18 +424,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -493,9 +493,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/farm-staking/farm-staking-proxy/wasm/Cargo.toml b/farm-staking/farm-staking-proxy/wasm/Cargo.toml index b95744497..ee87f5eee 100644 --- a/farm-staking/farm-staking-proxy/wasm/Cargo.toml +++ b/farm-staking/farm-staking-proxy/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/farm-staking/farm-staking/Cargo.toml b/farm-staking/farm-staking/Cargo.toml index c4db81ca1..b4e81589f 100644 --- a/farm-staking/farm-staking/Cargo.toml +++ b/farm-staking/farm-staking/Cargo.toml @@ -78,14 +78,14 @@ path = "../../common/common_structs" path = "../../common/common_errors" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" diff --git a/farm-staking/farm-staking/meta/Cargo.toml b/farm-staking/farm-staking/meta/Cargo.toml index 20d07fb79..49357bd4a 100644 --- a/farm-staking/farm-staking/meta/Cargo.toml +++ b/farm-staking/farm-staking/meta/Cargo.toml @@ -9,5 +9,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/farm-staking/farm-staking/src/base_impl_wrapper.rs b/farm-staking/farm-staking/src/base_impl_wrapper.rs index 2b671677f..da30a1c84 100644 --- a/farm-staking/farm-staking/src/base_impl_wrapper.rs +++ b/farm-staking/farm-staking/src/base_impl_wrapper.rs @@ -5,7 +5,6 @@ use core::marker::PhantomData; use common_structs::FarmToken; use contexts::storage_cache::StorageCache; use farm_base_impl::base_traits_impl::FarmContract; -use multiversx_sc_modules::transfer_role_proxy::PaymentsVec; use crate::token_attributes::StakingFarmTokenAttributes; @@ -184,61 +183,4 @@ where original_owner: caller, } } - - fn check_and_update_user_farm_position( - sc: &Self::FarmSc, - user: &ManagedAddress<::Api>, - farm_positions: &PaymentsVec<::Api>, - ) { - let farm_token_mapper = sc.farm_token(); - for farm_position in farm_positions { - if sc.is_old_farm_position(farm_position.token_nonce) { - continue; - } - - farm_token_mapper.require_same_token(&farm_position.token_identifier); - - let token_attributes: StakingFarmTokenAttributes<::Api> = - farm_token_mapper.get_token_attributes(farm_position.token_nonce); - - if &token_attributes.original_owner != user { - Self::decrease_user_farm_position(sc, &farm_position); - Self::increase_user_farm_position(sc, user, &farm_position.amount); - } - } - } - - #[inline] - fn increase_user_farm_position( - sc: &Self::FarmSc, - user: &ManagedAddress<::Api>, - increase_farm_position_amount: &BigUint<::Api>, - ) { - let mut user_total_farm_position = sc.get_user_total_farm_position(user); - user_total_farm_position.total_farm_position += increase_farm_position_amount; - sc.user_total_farm_position(user) - .set(user_total_farm_position); - } - - fn decrease_user_farm_position( - sc: &Self::FarmSc, - farm_position: &EsdtTokenPayment<::Api>, - ) { - if sc.is_old_farm_position(farm_position.token_nonce) { - return; - } - - let farm_token_mapper = sc.farm_token(); - let token_attributes: StakingFarmTokenAttributes<::Api> = - farm_token_mapper.get_token_attributes(farm_position.token_nonce); - - sc.user_total_farm_position(&token_attributes.original_owner) - .update(|user_total_farm_position| { - if user_total_farm_position.total_farm_position > farm_position.amount { - user_total_farm_position.total_farm_position -= &farm_position.amount; - } else { - user_total_farm_position.total_farm_position = BigUint::zero(); - } - }); - } } diff --git a/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs b/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs index e3d0b1dc4..53050ba98 100644 --- a/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs +++ b/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs @@ -30,6 +30,7 @@ pub trait ClaimStakeFarmRewardsModule: + weekly_rewards_splitting::locked_token_buckets::WeeklyRewardsLockedTokenBucketsModule + weekly_rewards_splitting::update_claim_progress_energy::UpdateClaimProgressEnergyModule + energy_query::EnergyQueryModule + + crate::delete_energy::DeleteEnergyModule { #[payable("*")] #[endpoint(claimRewards)] @@ -62,11 +63,12 @@ pub trait ClaimStakeFarmRewardsModule: opt_new_farming_amount: Option, ) -> ClaimRewardsResultType { self.migrate_old_farm_positions(&original_caller); + let payment = self.call_value().single_esdt(); let mut claim_result = self .claim_rewards_base_no_farm_token_mint::>( original_caller.clone(), - ManagedVec::from_single_item(payment), + ManagedVec::from_single_item(payment.clone()), ); let mut virtual_farm_token = claim_result.new_farm_token.clone(); @@ -74,12 +76,23 @@ pub trait ClaimStakeFarmRewardsModule: claim_result.storage_cache.farm_token_supply -= &virtual_farm_token.payment.amount; claim_result.storage_cache.farm_token_supply += &new_amount; + let mut user_total_farm_position = self.get_user_total_farm_position(&original_caller); + user_total_farm_position.total_farm_position -= &virtual_farm_token.payment.amount; + user_total_farm_position.total_farm_position += &new_amount; + self.user_total_farm_position(&original_caller) + .set(user_total_farm_position); + virtual_farm_token.payment.amount = new_amount.clone(); virtual_farm_token.attributes.current_farm_amount = new_amount; self.set_farm_supply_for_current_week(&claim_result.storage_cache.farm_token_supply); } + self.delete_user_energy_if_needed::>( + &ManagedVec::from_single_item(payment), + &claim_result.context.all_attributes, + ); + self.update_energy_and_progress(&original_caller); let new_farm_token_nonce = self.send().esdt_nft_create_compact( diff --git a/farm-staking/farm-staking/src/compound_stake_farm_rewards.rs b/farm-staking/farm-staking/src/compound_stake_farm_rewards.rs index a7d83d574..cd8df29a9 100644 --- a/farm-staking/farm-staking/src/compound_stake_farm_rewards.rs +++ b/farm-staking/farm-staking/src/compound_stake_farm_rewards.rs @@ -28,21 +28,28 @@ pub trait CompoundStakeFarmRewardsModule: + weekly_rewards_splitting::locked_token_buckets::WeeklyRewardsLockedTokenBucketsModule + weekly_rewards_splitting::update_claim_progress_energy::UpdateClaimProgressEnergyModule + energy_query::EnergyQueryModule + + crate::delete_energy::DeleteEnergyModule { #[payable("*")] #[endpoint(compoundRewards)] fn compound_rewards(&self) -> EsdtTokenPayment { let caller = self.blockchain().get_caller(); self.migrate_old_farm_positions(&caller); + let payments = self.get_non_empty_payments(); - let compound_result = - self.compound_rewards_base::>(caller.clone(), payments); + let compound_result = self + .compound_rewards_base::>(caller.clone(), payments.clone()); let new_farm_token = compound_result.new_farm_token.payment.clone(); self.send_payment_non_zero(&caller, &new_farm_token); self.set_farm_supply_for_current_week(&compound_result.storage_cache.farm_token_supply); + self.delete_user_energy_if_needed::>( + &payments, + &compound_result.context.all_attributes, + ); + self.emit_compound_rewards_event( &caller, compound_result.context, diff --git a/farm-staking/farm-staking/src/delete_energy.rs b/farm-staking/farm-staking/src/delete_energy.rs new file mode 100644 index 000000000..7c80412eb --- /dev/null +++ b/farm-staking/farm-staking/src/delete_energy.rs @@ -0,0 +1,46 @@ +use common_structs::{FarmToken, PaymentsVec}; +use farm_base_impl::base_traits_impl::FarmContract; + +multiversx_sc::imports!(); + +#[multiversx_sc::module] +pub trait DeleteEnergyModule: + rewards::RewardsModule + + config::ConfigModule + + token_send::TokenSendModule + + farm_token::FarmTokenModule + + pausable::PausableModule + + permissions_module::PermissionsModule + + events::EventsModule + + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + + utils::UtilsModule + + farm_boosted_yields::FarmBoostedYieldsModule + + farm_boosted_yields::boosted_yields_factors::BoostedYieldsFactorsModule + + week_timekeeping::WeekTimekeepingModule + + weekly_rewards_splitting::WeeklyRewardsSplittingModule + + weekly_rewards_splitting::events::WeeklyRewardsSplittingEventsModule + + weekly_rewards_splitting::global_info::WeeklyRewardsGlobalInfo + + weekly_rewards_splitting::locked_token_buckets::WeeklyRewardsLockedTokenBucketsModule + + weekly_rewards_splitting::update_claim_progress_energy::UpdateClaimProgressEnergyModule + + energy_query::EnergyQueryModule +{ + fn delete_user_energy_if_needed>( + &self, + payments: &PaymentsVec, + all_attributes: &ManagedVec, + ) { + let mut processed_users = ManagedMap::new(); + for (payment, attr) in payments.iter().zip(all_attributes.into_iter()) { + let original_owner = attr.get_original_owner(); + if processed_users.contains(original_owner.as_managed_buffer()) + || self.is_old_farm_position(payment.token_nonce) + { + continue; + } + + self.clear_user_energy_if_needed(&original_owner); + + processed_users.put(original_owner.as_managed_buffer(), &ManagedBuffer::new()); + } + } +} diff --git a/farm-staking/farm-staking/src/lib.rs b/farm-staking/farm-staking/src/lib.rs index c210d080c..589748364 100644 --- a/farm-staking/farm-staking/src/lib.rs +++ b/farm-staking/farm-staking/src/lib.rs @@ -19,6 +19,7 @@ pub mod claim_only_boosted_staking_rewards; pub mod claim_stake_farm_rewards; pub mod compound_stake_farm_rewards; pub mod custom_rewards; +pub mod delete_energy; pub mod farm_token_roles; pub mod stake_farm; pub mod token_attributes; @@ -60,6 +61,7 @@ pub trait FarmStaking: + weekly_rewards_splitting::locked_token_buckets::WeeklyRewardsLockedTokenBucketsModule + weekly_rewards_splitting::update_claim_progress_energy::UpdateClaimProgressEnergyModule + energy_query::EnergyQueryModule + + delete_energy::DeleteEnergyModule { #[init] fn init( @@ -97,7 +99,7 @@ pub trait FarmStaking: self.try_set_farm_position_migration_nonce(farm_token_mapper); } - #[endpoint] + #[upgrade] fn upgrade(&self) { let current_epoch = self.blockchain().get_block_epoch(); self.first_week_start_epoch().set_if_empty(current_epoch); @@ -117,19 +119,46 @@ pub trait FarmStaking: let boosted_rewards_payment = EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards); - let payments = self.get_non_empty_payments(); - let token_mapper = self.farm_token(); - let output_attributes: StakingFarmTokenAttributes = - self.merge_from_payments_and_burn(payments, &token_mapper); - let new_token_amount = output_attributes.get_total_supply(); + let merged_farm_token = self.merge_and_update_farm_tokens(caller.clone()); - let merged_farm_token = token_mapper.nft_create(new_token_amount, &output_attributes); self.send_payment_non_zero(&caller, &merged_farm_token); self.send_payment_non_zero(&caller, &boosted_rewards_payment); (merged_farm_token, boosted_rewards_payment).into() } + fn merge_and_update_farm_tokens(&self, orig_caller: ManagedAddress) -> EsdtTokenPayment { + let mut output_attributes = + self.merge_farm_tokens::>(&orig_caller); + output_attributes.original_owner = orig_caller; + + let new_token_amount = output_attributes.get_total_supply(); + self.farm_token() + .nft_create(new_token_amount, &output_attributes) + } + + fn merge_farm_tokens>( + &self, + orig_caller: &ManagedAddress, + ) -> FC::AttributesType { + let payments = self.get_non_empty_payments(); + let token_mapper = self.farm_token(); + + let mut all_attributes = ManagedVec::new(); + for payment in &payments { + token_mapper.require_same_token(&payment.token_identifier); + + let attr = token_mapper.get_token_attributes(payment.token_nonce); + all_attributes.push(attr); + } + + self.delete_user_energy_if_needed::(&payments, &all_attributes); + + FC::check_and_update_user_farm_position(self, orig_caller, &payments, &all_attributes); + + self.merge_from_payments_and_burn(payments, &token_mapper) + } + #[endpoint(setBoostedYieldsRewardsPercentage)] fn set_boosted_yields_rewards_percentage(&self, percentage: u64) { self.require_caller_has_admin_permissions(); diff --git a/farm-staking/farm-staking/src/stake_farm.rs b/farm-staking/farm-staking/src/stake_farm.rs index 7ab3dea1c..a022b689d 100644 --- a/farm-staking/farm-staking/src/stake_farm.rs +++ b/farm-staking/farm-staking/src/stake_farm.rs @@ -31,6 +31,7 @@ pub trait StakeFarmModule: + weekly_rewards_splitting::locked_token_buckets::WeeklyRewardsLockedTokenBucketsModule + weekly_rewards_splitting::update_claim_progress_energy::UpdateClaimProgressEnergyModule + energy_query::EnergyQueryModule + + crate::delete_energy::DeleteEnergyModule { #[payable("*")] #[endpoint(stakeFarmThroughProxy)] @@ -86,6 +87,11 @@ pub trait StakeFarmModule: self.set_farm_supply_for_current_week(&enter_result.storage_cache.farm_token_supply); + self.delete_user_energy_if_needed::>( + &enter_result.context.additional_farm_tokens, + &enter_result.context.additional_attributes, + ); + self.update_energy_and_progress(&original_caller); self.emit_enter_farm_event( diff --git a/farm-staking/farm-staking/src/token_attributes.rs b/farm-staking/farm-staking/src/token_attributes.rs index 54074a958..0fcabeba3 100644 --- a/farm-staking/farm-staking/src/token_attributes.rs +++ b/farm-staking/farm-staking/src/token_attributes.rs @@ -82,6 +82,10 @@ impl FarmToken for StakingFarmTokenAttributes { fn get_initial_farming_tokens(&self) -> BigUint { &self.current_farm_amount - &self.compounded_reward } + + fn get_original_owner(&self) -> ManagedAddress { + self.original_owner.clone() + } } impl FixedSupplyToken for StakingFarmTokenAttributes { @@ -108,8 +112,8 @@ impl FixedSupplyToken for StakingFarmTokenAttributes { impl Mergeable for StakingFarmTokenAttributes { #[inline] - fn can_merge_with(&self, other: &Self) -> bool { - self.original_owner == other.original_owner + fn can_merge_with(&self, _other: &Self) -> bool { + true } fn merge_with(&mut self, other: Self) { diff --git a/farm-staking/farm-staking/src/unstake_farm.rs b/farm-staking/farm-staking/src/unstake_farm.rs index e40642b4f..1d40cfd15 100644 --- a/farm-staking/farm-staking/src/unstake_farm.rs +++ b/farm-staking/farm-staking/src/unstake_farm.rs @@ -30,6 +30,7 @@ pub trait UnstakeFarmModule: + weekly_rewards_splitting::locked_token_buckets::WeeklyRewardsLockedTokenBucketsModule + weekly_rewards_splitting::update_claim_progress_energy::UpdateClaimProgressEnergyModule + energy_query::EnergyQueryModule + + crate::delete_energy::DeleteEnergyModule { #[payable("*")] #[endpoint(unstakeFarm)] @@ -74,8 +75,8 @@ pub trait UnstakeFarmModule: ) -> ExitFarmWithPartialPosResultType { let migrated_amount = self.migrate_old_farm_positions(&original_caller); - let exit_result = - self.exit_farm_base::>(original_caller.clone(), payment); + let exit_result = self + .exit_farm_base::>(original_caller.clone(), payment.clone()); self.decrease_old_farm_positions(migrated_amount, &original_caller); @@ -89,9 +90,13 @@ pub trait UnstakeFarmModule: self.send_payment_non_zero(&caller, &exit_result.reward_payment); - self.clear_user_energy_if_needed(&original_caller); self.set_farm_supply_for_current_week(&exit_result.storage_cache.farm_token_supply); + self.delete_user_energy_if_needed::>( + &ManagedVec::from_single_item(payment), + &ManagedVec::from_single_item(exit_result.context.farm_token.attributes.clone()), + ); + self.emit_exit_farm_event( &caller, exit_result.context, diff --git a/farm-staking/farm-staking/tests/farm_staking_energy_test.rs b/farm-staking/farm-staking/tests/farm_staking_energy_test.rs index 230d84747..facc2025f 100644 --- a/farm-staking/farm-staking/tests/farm_staking_energy_test.rs +++ b/farm-staking/farm-staking/tests/farm_staking_energy_test.rs @@ -1,13 +1,19 @@ #![allow(deprecated)] pub mod farm_staking_setup; +use config::ConfigModule; use farm_staking::{ - claim_stake_farm_rewards::ClaimStakeFarmRewardsModule, stake_farm::StakeFarmModule, + claim_stake_farm_rewards::ClaimStakeFarmRewardsModule, + stake_farm::StakeFarmModule, + token_attributes::{StakingFarmTokenAttributes, UnbondSftAttributes}, unstake_farm::UnstakeFarmModule, + FarmStaking, }; use farm_staking_setup::*; use multiversx_sc::codec::multi_types::OptionalValue; -use multiversx_sc_scenario::{rust_biguint, DebugApi}; +use multiversx_sc_scenario::{ + managed_address, managed_biguint, rust_biguint, testing_framework::TxTokenTransfer, DebugApi, +}; #[test] fn farm_staking_with_energy_setup_test() { @@ -24,12 +30,21 @@ fn farm_staking_boosted_rewards_no_energy_test() { let mut fs_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = fs_setup.user_address.clone(); + fs_setup.set_boosted_yields_factors(); fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); let farm_in_amount = 100_000_000; let expected_farm_token_nonce = 1; - fs_setup.stake_farm(farm_in_amount, &[], expected_farm_token_nonce, 0, 0); + fs_setup.stake_farm( + &user_address, + farm_in_amount, + &[], + expected_farm_token_nonce, + 0, + 0, + ); fs_setup.check_farm_token_supply(farm_in_amount); fs_setup.set_block_epoch(5); @@ -43,6 +58,7 @@ fn farm_staking_boosted_rewards_no_energy_test() { rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out); let expected_reward_per_share = 300_000; // from 400_000 -> 300_000 fs_setup.claim_rewards( + &user_address, farm_in_amount, expected_farm_token_nonce, expected_reward_token_out, @@ -54,26 +70,77 @@ fn farm_staking_boosted_rewards_no_energy_test() { fs_setup.check_farm_token_supply(farm_in_amount); } +#[test] +fn farm_staking_other_user_enter_negative_test() { + DebugApi::dummy(); + let mut fs_setup = + FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + + let user_address = fs_setup.user_address.clone(); + let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); + + fs_setup.set_boosted_yields_factors(); + fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + + let farm_in_amount = 100_000_000; + fs_setup + .stake_farm_for_other_user(&rand_user, &user_address, farm_in_amount, &[]) + .assert_error(4, "Item not whitelisted"); + + let expected_farm_token_nonce = 1; + fs_setup.stake_farm( + &user_address, + farm_in_amount, + &[], + expected_farm_token_nonce, + 0, + 0, + ); + + fs_setup + .claim_farm_for_other_user( + &rand_user, + &user_address, + expected_farm_token_nonce, + farm_in_amount, + ) + .assert_error(4, "Item not whitelisted"); + + fs_setup + .unstake_farm_for_other_user( + &rand_user, + &user_address, + expected_farm_token_nonce, + farm_in_amount, + ) + .assert_error(4, "Item not whitelisted"); +} + #[test] fn farm_staking_boosted_rewards_with_energy_test() { DebugApi::dummy(); let mut fs_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = fs_setup.user_address.clone(); + let user_address2 = fs_setup.user_address2.clone(); + fs_setup.set_boosted_yields_factors(); fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); - fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 0, 10); + fs_setup.set_user_energy(&user_address, 9_800, 0, 100); + fs_setup.set_user_energy(&user_address2, 4_900, 0, 350); let farm_in_amount = 100_000_000; - fs_setup.stake_farm(farm_in_amount, &[], 1, 0, 0); - fs_setup.check_farm_token_supply(farm_in_amount); + fs_setup.stake_farm(&user_address, farm_in_amount, &[], 1, 0, 0); + fs_setup.stake_farm(&user_address2, farm_in_amount, &[], 2, 0, 0); + fs_setup.check_farm_token_supply(farm_in_amount * 2); // claim to get energy registered fs_setup .b_mock .execute_esdt_transfer( - &fs_setup.user_address, + &user_address, &fs_setup.farm_wrapper, FARM_TOKEN_ID, 1, @@ -84,10 +151,21 @@ fn farm_staking_boosted_rewards_with_energy_test() { ) .assert_ok(); - fs_setup.set_block_nonce(10); - - // random user tx to collect rewards + fs_setup + .b_mock + .execute_esdt_transfer( + &user_address2, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 2, + &rust_biguint!(farm_in_amount), + |sc| { + let _ = sc.claim_rewards(OptionalValue::None); + }, + ) + .assert_ok(); + // random user tx to collect rewards - week 1 let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); fs_setup.b_mock.set_esdt_balance( &rand_user, @@ -95,8 +173,9 @@ fn farm_staking_boosted_rewards_with_energy_test() { &rust_biguint!(USER_TOTAL_RIDE_TOKENS), ); - fs_setup.set_user_energy(&rand_user, 1, 5, 1); - fs_setup.set_block_epoch(5); + fs_setup.set_user_energy(&rand_user, 1, 6, 1); + fs_setup.set_block_epoch(6); + fs_setup.set_block_nonce(10); fs_setup .b_mock @@ -118,7 +197,7 @@ fn farm_staking_boosted_rewards_with_energy_test() { &rand_user, &fs_setup.farm_wrapper, FARM_TOKEN_ID, - 3, + 5, &rust_biguint!(10), |sc| { let _ = sc.unstake_farm(OptionalValue::None); @@ -126,51 +205,164 @@ fn farm_staking_boosted_rewards_with_energy_test() { ) .assert_ok(); - fs_setup.set_block_epoch(8); + // random user tx to collect rewards - week 2 + fs_setup.set_user_energy(&rand_user, 1, 13, 1); + fs_setup.set_block_epoch(13); + fs_setup.set_block_nonce(20); - fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 8, 10); + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); - // value taken from the "test_unstake_farm" test - // originally, it was 40, but since 25% of the rewards go to boosted yields - // rewards are now only 3/4 * 40 = 30 - // - // 10 reserved for boosted yields -> 30 + 10 - let expected_reward_token_out = 40; - let expected_farming_token_balance = - rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out); - let expected_reward_per_share = 300_000; // from 400_000 -> 300_000 + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 7, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + // random user tx to collect rewards - week 3 + fs_setup.set_user_energy(&rand_user, 1, 20, 1); + fs_setup.set_block_epoch(20); + fs_setup.set_block_nonce(30); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 9, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + // random user tx to collect rewards - week 4 + fs_setup.set_user_energy(&rand_user, 1, 27, 1); + fs_setup.set_block_epoch(27); + fs_setup.set_block_nonce(40); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 11, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(28); + fs_setup.update_energy_for_user(&user_address); + fs_setup.update_energy_for_user(&user_address2); + + let base_rewards = 136; + let boosted_rewards_user = 61; + let boosted_rewards_user2 = 15; // ~ 1/4 rewards than user1 (half the energy for only 2 weeks) + let expected_reward_token_out_user = base_rewards + boosted_rewards_user; + let expected_reward_token_out_user2 = base_rewards + boosted_rewards_user2; + let expected_farming_token_balance_user = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out_user); + let expected_farming_token_balance_user2 = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out_user2); + let expected_reward_per_share = 1_360_000; fs_setup.claim_rewards( + &user_address, farm_in_amount, - 2, - expected_reward_token_out, - &expected_farming_token_balance, - &expected_farming_token_balance, - 5, + 3, + expected_reward_token_out_user, + &expected_farming_token_balance_user, + &expected_farming_token_balance_user, + 13, expected_reward_per_share, ); - fs_setup.check_farm_token_supply(farm_in_amount); + fs_setup.claim_rewards( + &user_address2, + farm_in_amount, + 4, + expected_reward_token_out_user2, + &expected_farming_token_balance_user2, + &expected_farming_token_balance_user2, + 14, + expected_reward_per_share, + ); + fs_setup.check_farm_token_supply(farm_in_amount * 2); } #[test] -fn farm_staking_claim_boosted_rewards_for_user_test() { +fn farm_staking_partial_position_handling_test() { DebugApi::dummy(); let mut fs_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = fs_setup.user_address.clone(); + fs_setup.set_boosted_yields_factors(); fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); - fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 0, 10); + fs_setup.set_user_energy(&user_address, 10_000, 0, 10); let farm_in_amount = 100_000_000; - fs_setup.stake_farm(farm_in_amount, &[], 1, 0, 0); + fs_setup.stake_farm(&user_address, farm_in_amount, &[], 1, 0, 0); fs_setup.check_farm_token_supply(farm_in_amount); // claim to get energy registered fs_setup .b_mock .execute_esdt_transfer( - &fs_setup.user_address, + &user_address, &fs_setup.farm_wrapper, FARM_TOKEN_ID, 1, @@ -184,6 +376,7 @@ fn farm_staking_claim_boosted_rewards_for_user_test() { fs_setup.set_block_nonce(10); // random user tx to collect rewards + let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); fs_setup.b_mock.set_esdt_balance( &rand_user, @@ -224,43 +417,108 @@ fn farm_staking_claim_boosted_rewards_for_user_test() { fs_setup.set_block_epoch(8); - fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 8, 10); + fs_setup.set_user_energy(&user_address, 10_000, 8, 10); - // value taken from the "test_unstake_farm" test - // originally, it was 40, but since 25% of the rewards go to boosted yields - // rewards are now only 3/4 * 40 = 30 - // - // 10 reserved for boosted yields -> 30 + 10 - let expected_boosted_reward_token_out = 10; - let expected_farming_token_balance = - rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_boosted_reward_token_out); + let full_position_base_rewards = 30; + let boosted_rewards_user = 10; + let half_position_expected_rewards = full_position_base_rewards / 2 + boosted_rewards_user; + let expected_farming_token_balance_user = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + half_position_expected_rewards); - // Random_user claim boosted rewards for user - fs_setup.allow_external_claim_rewards(&fs_setup.user_address.clone()); - fs_setup.claim_boosted_rewards_for_user( - &fs_setup.user_address.clone(), + fs_setup.unstake_farm( + &user_address, + farm_in_amount / 2, + 2, + half_position_expected_rewards, + &expected_farming_token_balance_user, + &expected_farming_token_balance_user, + 5, + farm_in_amount / 2, + &UnbondSftAttributes { + unlock_epoch: 8 + MIN_UNBOND_EPOCHS, + }, + ); + + fs_setup.set_block_nonce(20); + + // random user tx to collect rewards + + let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); + fs_setup.b_mock.set_esdt_balance( &rand_user, - expected_boosted_reward_token_out, - &expected_farming_token_balance, + FARMING_TOKEN_ID, + &rust_biguint!(USER_TOTAL_RIDE_TOKENS), + ); + + fs_setup.set_user_energy(&rand_user, 1, 12, 1); + fs_setup.set_block_epoch(12); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 6, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(15); + + fs_setup.set_user_energy(&user_address, 10_000, 15, 10); + + let expected_rewards_amount = full_position_base_rewards / 2 * 2; // half remaining position * 2 times the 10 block period + let half_position_boosted_rewards = boosted_rewards_user / 2; + let remaining_expected_rewards = expected_rewards_amount + half_position_boosted_rewards; + let final_expected_farming_token_balance_user = + expected_farming_token_balance_user + rust_biguint!(remaining_expected_rewards); + let expected_reward_per_share = 600_000; + fs_setup.claim_rewards( + &user_address, + farm_in_amount / 2, + 2, + remaining_expected_rewards, + &final_expected_farming_token_balance_user, + &final_expected_farming_token_balance_user, + 8, + expected_reward_per_share, ); - fs_setup.check_farm_token_supply(farm_in_amount); } #[test] -fn farm_staking_full_position_boosted_rewards_test() { +fn farm_staking_claim_boosted_rewards_for_user_test() { DebugApi::dummy(); let mut fs_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = fs_setup.user_address.clone(); + fs_setup.set_boosted_yields_factors(); fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 0, 10); - let farm_in_amount = 50_000_000; - fs_setup.stake_farm(farm_in_amount, &[], 1, 0, 0); - fs_setup.stake_farm(farm_in_amount, &[], 2, 0, 0); - fs_setup.check_farm_token_supply(farm_in_amount * 2); + let farm_in_amount = 100_000_000; + fs_setup.stake_farm(&user_address, farm_in_amount, &[], 1, 0, 0); + fs_setup.check_farm_token_supply(farm_in_amount); // claim to get energy registered fs_setup @@ -280,8 +538,8 @@ fn farm_staking_full_position_boosted_rewards_test() { fs_setup.set_block_nonce(10); // random user tx to collect rewards - let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); + let user_address = fs_setup.user_address.clone(); fs_setup.b_mock.set_esdt_balance( &rand_user, FARMING_TOKEN_ID, @@ -311,7 +569,7 @@ fn farm_staking_full_position_boosted_rewards_test() { &rand_user, &fs_setup.farm_wrapper, FARM_TOKEN_ID, - 4, + 3, &rust_biguint!(10), |sc| { let _ = sc.unstake_farm(OptionalValue::None); @@ -321,21 +579,137 @@ fn farm_staking_full_position_boosted_rewards_test() { fs_setup.set_block_epoch(8); - fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 8, 10); + fs_setup.set_user_energy(&user_address, 10_000, 8, 10); - let expected_base_rewards = 15; - let expected_boosted_rewards = 10; - let mut expected_farming_token_balance = rust_biguint!( - USER_TOTAL_RIDE_TOKENS - (farm_in_amount * 2) - + expected_base_rewards - + expected_boosted_rewards - ); - let expected_reward_per_share = 300_000; // from 400_000 -> 300_000 + // value taken from the "test_unstake_farm" test + // originally, it was 40, but since 25% of the rewards go to boosted yields + // rewards are now only 3/4 * 40 = 30 + // + // 10 reserved for boosted yields -> 30 + 10 + let expected_boosted_reward_token_out = 10; + let expected_farming_token_balance = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_boosted_reward_token_out); - // Should receive half base rewards and full boosted rewards - fs_setup.claim_rewards( - farm_in_amount, - 2, + // Random_user claim boosted rewards for user + let rand_user_reward_balance = 4_999_999_990u64; + fs_setup.b_mock.check_esdt_balance( + &rand_user, + REWARD_TOKEN_ID, + &rust_biguint!(rand_user_reward_balance), + ); + fs_setup.allow_external_claim_rewards(&user_address, true); + fs_setup.claim_boosted_rewards_for_user( + &user_address, + &rand_user, + expected_boosted_reward_token_out, + &expected_farming_token_balance, + ); + fs_setup.b_mock.check_esdt_balance( + &rand_user, + REWARD_TOKEN_ID, + &rust_biguint!(rand_user_reward_balance), + ); + + fs_setup.check_farm_token_supply(farm_in_amount); + + // User removes the allowance of claim boosted rewards + fs_setup.allow_external_claim_rewards(&user_address, false); + fs_setup.claim_boosted_rewards_for_user_expect_error(&user_address, &rand_user); +} + +#[test] +fn farm_staking_full_position_boosted_rewards_test() { + DebugApi::dummy(); + let mut fs_setup = + FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + + let user_address = fs_setup.user_address.clone(); + + fs_setup.set_boosted_yields_factors(); + fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + + fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 0, 10); + + let farm_in_amount = 50_000_000; + fs_setup.stake_farm(&user_address, farm_in_amount, &[], 1, 0, 0); + fs_setup.stake_farm(&user_address, farm_in_amount, &[], 2, 0, 0); + fs_setup.check_farm_token_supply(farm_in_amount * 2); + + // claim to get energy registered + fs_setup + .b_mock + .execute_esdt_transfer( + &fs_setup.user_address, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 1, + &rust_biguint!(farm_in_amount), + |sc| { + let _ = sc.claim_rewards(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_nonce(10); + + // random user tx to collect rewards + + let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); + fs_setup.b_mock.set_esdt_balance( + &rand_user, + FARMING_TOKEN_ID, + &rust_biguint!(USER_TOTAL_RIDE_TOKENS), + ); + + fs_setup.set_user_energy(&rand_user, 1, 5, 1); + fs_setup.set_block_epoch(5); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 4, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(8); + + fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 8, 10); + + let expected_base_rewards = 15; + let expected_boosted_rewards = 10; + let mut expected_farming_token_balance = rust_biguint!( + USER_TOTAL_RIDE_TOKENS - (farm_in_amount * 2) + + expected_base_rewards + + expected_boosted_rewards + ); + let expected_reward_per_share = 300_000; // from 400_000 -> 300_000 + + // Should receive half base rewards and full boosted rewards + fs_setup.claim_rewards( + &user_address, + farm_in_amount, + 2, expected_base_rewards + expected_boosted_rewards, &expected_farming_token_balance, &expected_farming_token_balance, @@ -346,6 +720,7 @@ fn farm_staking_full_position_boosted_rewards_test() { // Should receive half base rewards and no boosted rewards expected_farming_token_balance += expected_base_rewards; fs_setup.claim_rewards( + &user_address, farm_in_amount, 3, expected_base_rewards, @@ -356,3 +731,702 @@ fn farm_staking_full_position_boosted_rewards_test() { ); fs_setup.check_farm_token_supply(farm_in_amount * 2); } + +#[test] +fn position_owner_change_test() { + DebugApi::dummy(); + let mut fs_setup = + FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + + let first_user = fs_setup.user_address.clone(); + let second_user = fs_setup.user_address2.clone(); + + fs_setup.set_boosted_yields_factors(); + fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + + fs_setup.set_user_energy(&first_user, 10_000, 0, 10); + fs_setup.set_user_energy(&second_user, 5_000, 0, 10); + + let farm_in_amount = 10_000_000; + let half_farm_in_amount = farm_in_amount / 2; + fs_setup.stake_farm(&first_user, farm_in_amount, &[], 1, 0, 0); + fs_setup.stake_farm(&first_user, farm_in_amount, &[], 2, 0, 0); + fs_setup.stake_farm(&first_user, farm_in_amount, &[], 3, 0, 0); + fs_setup.stake_farm(&first_user, farm_in_amount, &[], 4, 0, 0); + fs_setup.stake_farm(&first_user, farm_in_amount, &[], 5, 0, 0); + + fs_setup.check_farm_token_supply(farm_in_amount * 5); + + fs_setup.check_user_total_farm_position(&first_user, farm_in_amount * 5); + fs_setup.check_user_total_farm_position(&second_user, 0); + + // First user transfers 5 position to second user + fs_setup.send_position(&first_user, &second_user, 1, farm_in_amount, 0); + fs_setup.send_position(&first_user, &second_user, 2, farm_in_amount, 0); + fs_setup.send_position(&first_user, &second_user, 3, farm_in_amount, 0); + fs_setup.send_position(&first_user, &second_user, 4, farm_in_amount, 0); + fs_setup.send_position(&first_user, &second_user, 5, farm_in_amount, 0); + + // Total farm position unchanged as users only transfered the farm positions + fs_setup.check_user_total_farm_position(&first_user, half_farm_in_amount * 10); + fs_setup.check_user_total_farm_position(&second_user, 0); + + let additional_farm_tokens = [TxTokenTransfer { + token_identifier: FARM_TOKEN_ID.to_vec(), + nonce: 1, + value: rust_biguint!(half_farm_in_amount), + }]; + + fs_setup.stake_farm( + &second_user, + farm_in_amount, + &additional_farm_tokens, + 6, + 0, + 0, + ); + + fs_setup.check_user_total_farm_position(&first_user, half_farm_in_amount * 9); + fs_setup.check_user_total_farm_position(&second_user, farm_in_amount + half_farm_in_amount); + + let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); + fs_setup.b_mock.set_esdt_balance( + &rand_user, + FARMING_TOKEN_ID, + &rust_biguint!(USER_TOTAL_RIDE_TOKENS), + ); + + // random user tx to collect rewards + + fs_setup.set_user_energy(&rand_user, 1, 5, 1); + fs_setup.set_block_epoch(5); + fs_setup.set_block_nonce(10); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 7, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(8); + + fs_setup.set_user_energy(&first_user, 10_000, 8, 10); + fs_setup.set_user_energy(&second_user, 5_000, 8, 10); + + // Second user claims with half position from first user + let mut rewards = 2; + let mut expected_farming_token_balance = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + rewards); + fs_setup.claim_rewards( + &second_user, + half_farm_in_amount, + 2, + rewards, + &expected_farming_token_balance, + &expected_farming_token_balance, + 9, + 250_000, + ); + + fs_setup.check_user_total_farm_position(&first_user, half_farm_in_amount * 8); + fs_setup.check_user_total_farm_position(&second_user, farm_in_amount + half_farm_in_amount * 2); + + // random user tx to collect rewards + fs_setup.set_user_energy(&rand_user, 1, 12, 1); + fs_setup.set_block_epoch(12); + fs_setup.set_block_nonce(20); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 10, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(15); + + fs_setup.set_user_energy(&first_user, 10_000, 15, 10); + fs_setup.set_user_energy(&second_user, 5_000, 15, 10); + + // Second user exits with half position from first user + fs_setup + .b_mock + .execute_esdt_transfer( + &second_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 3, + &rust_biguint!(half_farm_in_amount), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + rewards += 3; + expected_farming_token_balance = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + rewards); + fs_setup.b_mock.check_esdt_balance( + &second_user, + REWARD_TOKEN_ID, + &expected_farming_token_balance, + ); + + fs_setup.check_user_total_farm_position(&first_user, half_farm_in_amount * 7); + fs_setup.check_user_total_farm_position(&second_user, farm_in_amount + half_farm_in_amount * 2); + + // First user claim boosted rewards + let first_user_expected_boosted_reward_token_out = 5; + let first_user_expected_farming_token_balance = rust_biguint!( + USER_TOTAL_RIDE_TOKENS - farm_in_amount * 5 + first_user_expected_boosted_reward_token_out + ); + fs_setup.claim_boosted_rewards_for_user( + &first_user, + &first_user, + first_user_expected_boosted_reward_token_out, + &first_user_expected_farming_token_balance, + ); + + fs_setup.check_user_total_farm_position(&first_user, half_farm_in_amount * 7); + fs_setup.check_user_total_farm_position(&second_user, farm_in_amount + half_farm_in_amount * 2); + + // random user tx to collect rewards + fs_setup.set_user_energy(&rand_user, 1, 12, 1); + fs_setup.set_block_epoch(20); + fs_setup.set_block_nonce(30); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 13, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(22); + + fs_setup.set_user_energy(&first_user, 10_000, 22, 10); + fs_setup.set_user_energy(&second_user, 5_000, 22, 10); + + // Second user merges half own position with 2 x half position from first user + // We send the payment from first user first, + // to see that the original caller is correctly updated as second user + let farm_tokens = [ + TxTokenTransfer { + token_identifier: FARM_TOKEN_ID.to_vec(), + nonce: 4, + value: rust_biguint!(half_farm_in_amount), + }, + TxTokenTransfer { + token_identifier: FARM_TOKEN_ID.to_vec(), + nonce: 6, + value: rust_biguint!(half_farm_in_amount), + }, + TxTokenTransfer { + token_identifier: FARM_TOKEN_ID.to_vec(), + nonce: 5, + value: rust_biguint!(half_farm_in_amount), + }, + ]; + fs_setup + .b_mock + .execute_esdt_multi_transfer(&second_user, &fs_setup.farm_wrapper, &farm_tokens, |sc| { + let _ = sc.merge_farm_tokens_endpoint(); + }) + .assert_ok(); + + let expected_attributes = StakingFarmTokenAttributes:: { + reward_per_share: managed_biguint!(0), + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(half_farm_in_amount * 3), + original_owner: managed_address!(&second_user), // Check that second user is original owner + }; + fs_setup.b_mock.check_nft_balance( + &second_user, + FARM_TOKEN_ID, + 15, + &rust_biguint!(half_farm_in_amount * 3), + Some(&expected_attributes), + ); + rewards += 1; + expected_farming_token_balance = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + rewards); + fs_setup.b_mock.check_esdt_balance( + &second_user, + REWARD_TOKEN_ID, + &expected_farming_token_balance, + ); + + fs_setup.check_user_total_farm_position(&first_user, half_farm_in_amount * 5); + fs_setup.check_user_total_farm_position(&second_user, farm_in_amount + half_farm_in_amount * 4); +} + +#[test] +fn farm_staking_farm_position_migration_test() { + DebugApi::dummy(); + let mut fs_setup = + FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + + let user = fs_setup.user_address.clone(); + + let farm_in_amount = 10_000_000; + let half_farm_in_amount = farm_in_amount / 2; + fs_setup.stake_farm(&user, farm_in_amount, &[], 1, 0, 0); + fs_setup.stake_farm(&user, farm_in_amount, &[], 2, 0, 0); + fs_setup.stake_farm(&user, farm_in_amount, &[], 3, 0, 0); + fs_setup.stake_farm(&user, farm_in_amount, &[], 4, 0, 0); + fs_setup.check_user_total_farm_position(&user, farm_in_amount * 4); + + // Simulate migration by resetting the user total farm position + fs_setup + .b_mock + .execute_esdt_transfer( + &user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let mut user_total_farm_position = + sc.get_user_total_farm_position(&managed_address!(&user)); + user_total_farm_position.total_farm_position = managed_biguint!(0u64); + sc.user_total_farm_position(&managed_address!(&user)) + .set(user_total_farm_position); + + sc.farm_position_migration_nonce().set(5); + }, + ) + .assert_ok(); + + fs_setup.check_user_total_farm_position(&user, 0); + + let mut expected_total_farm_position = 0u64; + let additional_farm_tokens = [TxTokenTransfer { + token_identifier: FARM_TOKEN_ID.to_vec(), + nonce: 1, + value: rust_biguint!(half_farm_in_amount), + }]; + + // Check enter farm with half old position additional payment + fs_setup.stake_farm(&user, farm_in_amount, &additional_farm_tokens, 5, 0, 0); + expected_total_farm_position += farm_in_amount + half_farm_in_amount; + fs_setup.check_user_total_farm_position(&user, expected_total_farm_position); + + // Check claim with half old position + let expected_farming_token_balance = rust_biguint!(4_949_999_990u64); + fs_setup.claim_rewards( + &user, + half_farm_in_amount, + 2, + 0, + &expected_farming_token_balance, + &expected_farming_token_balance, + 6, + 0, + ); + expected_total_farm_position += half_farm_in_amount; + fs_setup.check_user_total_farm_position(&user, expected_total_farm_position); + + // Check exit with half old position + fs_setup.unstake_farm( + &user, + half_farm_in_amount, + 3, + 0, + &expected_farming_token_balance, + &expected_farming_token_balance, + 7, + half_farm_in_amount, + &UnbondSftAttributes { + unlock_epoch: MIN_UNBOND_EPOCHS, + }, + ); + fs_setup.check_user_total_farm_position(&user, expected_total_farm_position); + + // Check compound with half old position + fs_setup.compound_rewards( + &user, + 4, + half_farm_in_amount, + &[], + 8, + half_farm_in_amount, + 0, + 0, + ); + expected_total_farm_position += half_farm_in_amount; + fs_setup.check_user_total_farm_position(&user, expected_total_farm_position); +} + +#[test] +fn boosted_rewards_config_change_test() { + DebugApi::dummy(); + let mut fs_setup = + FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + + let first_user = fs_setup.user_address.clone(); + let second_user = fs_setup.user_address2.clone(); + let third_user = fs_setup + .b_mock + .create_user_account(&rust_biguint!(100_000_000)); + fs_setup.b_mock.set_esdt_balance( + &third_user, + FARMING_TOKEN_ID, + &rust_biguint!(USER_TOTAL_RIDE_TOKENS), + ); + + let mut first_user_total_rewards = 0u64; + let mut second_user_total_rewards = 0u64; + let mut third_user_total_rewards = 0u64; + + let farm_in_amount = 10_000_000; + fs_setup.stake_farm(&first_user, farm_in_amount, &[], 1, 0, 0); + fs_setup.stake_farm(&second_user, farm_in_amount, &[], 2, 0, 0); + fs_setup.stake_farm(&third_user, farm_in_amount, &[], 3, 0, 0); + + fs_setup.set_user_energy(&first_user, 10_000, 0, 10); + fs_setup.set_user_energy(&second_user, 10_000, 0, 10); + fs_setup.set_user_energy(&third_user, 10_000, 0, 10); + + // claim to get energy registered + fs_setup + .b_mock + .execute_esdt_transfer( + &first_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 1, + &rust_biguint!(farm_in_amount), + |sc| { + let _ = sc.claim_rewards(OptionalValue::None); + }, + ) + .assert_ok(); + fs_setup + .b_mock + .execute_esdt_transfer( + &second_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 2, + &rust_biguint!(farm_in_amount), + |sc| { + let _ = sc.claim_rewards(OptionalValue::None); + }, + ) + .assert_ok(); + fs_setup + .b_mock + .execute_esdt_transfer( + &third_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 3, + &rust_biguint!(farm_in_amount), + |sc| { + let _ = sc.claim_rewards(OptionalValue::None); + }, + ) + .assert_ok(); + + // random user tx to collect rewards + let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); + fs_setup.b_mock.set_esdt_balance( + &rand_user, + FARMING_TOKEN_ID, + &rust_biguint!(USER_TOTAL_RIDE_TOKENS), + ); + + fs_setup.set_user_energy(&rand_user, 1, 6, 1); + fs_setup.set_block_epoch(6); + fs_setup.set_block_nonce(100); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 7, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(7); + fs_setup.set_user_energy(&first_user, 10_000, 7, 10); + fs_setup.set_user_energy(&second_user, 10_000, 7, 10); + fs_setup.set_user_energy(&third_user, 10_000, 7, 10); + + // First user claims + let mut base_rewards1 = 33; + let mut boosted_rewards1 = 0; + let mut expected_reward_token_out = base_rewards1 + boosted_rewards1; + first_user_total_rewards += expected_reward_token_out; + let mut expected_farming_token_balance = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out); + let mut expected_reward_per_share = 3_333_333u64; + fs_setup.claim_rewards( + &first_user, + farm_in_amount, + 4, + expected_reward_token_out, + &expected_farming_token_balance, + &expected_farming_token_balance, + 9, + expected_reward_per_share, + ); + + // Boosted rewards config is added + fs_setup.set_boosted_yields_factors(); + fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + + // random user tx to collect rewards + fs_setup.set_user_energy(&rand_user, 1, 13, 1); + fs_setup.set_block_epoch(13); + fs_setup.set_block_nonce(200); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 10, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(14); + fs_setup.set_user_energy(&first_user, 10_000, 14, 10); + fs_setup.set_user_energy(&second_user, 10_000, 14, 10); + fs_setup.set_user_energy(&third_user, 10_000, 14, 10); + + // First and second users claim + base_rewards1 = 25; + boosted_rewards1 = 8; + expected_reward_token_out = base_rewards1 + boosted_rewards1; + first_user_total_rewards += expected_reward_token_out; + expected_farming_token_balance += expected_reward_token_out; + expected_reward_per_share = 5_833_333u64; + fs_setup.claim_rewards( + &first_user, + farm_in_amount, + 9, + expected_reward_token_out, + &expected_farming_token_balance, + &expected_farming_token_balance, + 12, + expected_reward_per_share, + ); + + let mut base_rewards2 = 33 + 25; + let mut boosted_rewards2 = 8; + let mut expected_reward_token_out2 = base_rewards2 + boosted_rewards2; + second_user_total_rewards += expected_reward_token_out2; + let mut expected_farming_token_balance2 = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out2); + fs_setup.claim_rewards( + &second_user, + farm_in_amount, + 5, + expected_reward_token_out2, + &expected_farming_token_balance2, + &expected_farming_token_balance2, + 13, + expected_reward_per_share, + ); + + // Boosted rewards config is updated + fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE * 2); // 50% + + // random user tx to collect rewards + fs_setup.set_user_energy(&rand_user, 1, 20, 1); + fs_setup.set_block_epoch(20); + fs_setup.set_block_nonce(300); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 14, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(21); + fs_setup.set_user_energy(&first_user, 10_000, 21, 10); + fs_setup.set_user_energy(&second_user, 10_000, 21, 10); + fs_setup.set_user_energy(&third_user, 10_000, 21, 10); + + // All users claim - boosted rewards 50% + base_rewards1 = 16; + boosted_rewards1 = 16; + expected_reward_token_out = base_rewards1 + boosted_rewards1; + first_user_total_rewards += expected_reward_token_out; + expected_farming_token_balance += expected_reward_token_out; + expected_reward_per_share = 7_499_999u64; + fs_setup.claim_rewards( + &first_user, + farm_in_amount, + 12, + expected_reward_token_out, + &expected_farming_token_balance, + &expected_farming_token_balance, + 16, + expected_reward_per_share, + ); + + base_rewards2 = 16; + boosted_rewards2 = 16; + expected_reward_token_out2 = base_rewards2 + boosted_rewards2; + second_user_total_rewards += expected_reward_token_out2; + expected_farming_token_balance2 += expected_reward_token_out2; + fs_setup.claim_rewards( + &second_user, + farm_in_amount, + 13, + expected_reward_token_out2, + &expected_farming_token_balance2, + &expected_farming_token_balance2, + 17, + expected_reward_per_share, + ); + + let base_rewards3 = 74; + let boosted_rewards3 = 24; + let expected_reward_token_out3 = base_rewards3 + boosted_rewards3; + third_user_total_rewards += expected_reward_token_out3; + let expected_farming_token_balance3 = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out3); + fs_setup.claim_rewards( + &third_user, + farm_in_amount, + 6, + expected_reward_token_out3, + &expected_farming_token_balance3, + &expected_farming_token_balance3, + 18, + expected_reward_per_share, + ); + + assert!( + first_user_total_rewards == second_user_total_rewards + && first_user_total_rewards == third_user_total_rewards + ); +} diff --git a/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs b/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs index f9c2b5955..369b029bd 100644 --- a/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs +++ b/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs @@ -1,6 +1,7 @@ #![allow(deprecated)] use farm_staking::claim_only_boosted_staking_rewards::ClaimOnlyBoostedStakingRewardsModule; +use farm_staking::compound_stake_farm_rewards::CompoundStakeFarmRewardsModule; use multiversx_sc::codec::multi_types::OptionalValue; use multiversx_sc::storage::mappers::StorageTokenWrapper; use multiversx_sc::types::{Address, BigInt, EsdtLocalRole, ManagedAddress, MultiValueEncoded}; @@ -53,6 +54,7 @@ where pub b_mock: BlockchainStateWrapper, pub owner_address: Address, pub user_address: Address, + pub user_address2: Address, pub farm_wrapper: ContractObjWrapper, FarmObjBuilder>, pub energy_factory_wrapper: ContractObjWrapper, EnergyFactoryBuilder>, @@ -145,11 +147,18 @@ where FARMING_TOKEN_ID, &rust_biguint!(USER_TOTAL_RIDE_TOKENS), ); + let user_addr2 = b_mock.create_user_account(&rust_biguint!(100_000_000)); + b_mock.set_esdt_balance( + &user_addr2, + FARMING_TOKEN_ID, + &rust_biguint!(USER_TOTAL_RIDE_TOKENS), + ); FarmStakingSetup { b_mock, owner_address: owner_addr, user_address: user_addr, + user_address2: user_addr2, farm_wrapper, energy_factory_wrapper, } @@ -157,6 +166,7 @@ where pub fn stake_farm( &mut self, + user: &Address, farm_in_amount: u64, additional_farm_tokens: &[TxTokenTransfer], expected_farm_token_nonce: u64, @@ -177,7 +187,7 @@ where } self.b_mock - .execute_esdt_multi_transfer(&self.user_address, &self.farm_wrapper, &payments, |sc| { + .execute_esdt_multi_transfer(user, &self.farm_wrapper, &payments, |sc| { let (new_farm_token_payment, _) = sc.stake_farm_endpoint(OptionalValue::None).into_tuple(); assert_eq!( @@ -199,10 +209,10 @@ where reward_per_share: managed_biguint!(expected_reward_per_share), compounded_reward: managed_biguint!(expected_compounded_reward), current_farm_amount: managed_biguint!(expected_total_out_amount), - original_owner: managed_address!(&self.user_address), + original_owner: managed_address!(&user), }; self.b_mock.check_nft_balance( - &self.user_address, + user, FARM_TOKEN_ID, expected_farm_token_nonce, &rust_biguint!(expected_total_out_amount), @@ -210,9 +220,74 @@ where ); } + pub fn stake_farm_for_other_user( + &mut self, + user: &Address, + broker: &Address, + farm_in_amount: u64, + additional_farm_tokens: &[TxTokenTransfer], + ) -> TxResult { + let mut payments = Vec::with_capacity(1 + additional_farm_tokens.len()); + payments.push(TxTokenTransfer { + token_identifier: FARMING_TOKEN_ID.to_vec(), + nonce: 0, + value: rust_biguint!(farm_in_amount), + }); + payments.extend_from_slice(additional_farm_tokens); + + self.b_mock + .execute_esdt_multi_transfer(broker, &self.farm_wrapper, &payments, |sc| { + sc.stake_farm_endpoint(OptionalValue::Some(managed_address!(user))) + .into_tuple(); + }) + } + + pub fn claim_farm_for_other_user( + &mut self, + user: &Address, + broker: &Address, + farm_in_nonce: u64, + farm_in_amount: u64, + ) -> TxResult { + let mut payments = vec![]; + payments.push(TxTokenTransfer { + token_identifier: FARM_TOKEN_ID.to_vec(), + nonce: farm_in_nonce, + value: rust_biguint!(farm_in_amount), + }); + + self.b_mock + .execute_esdt_multi_transfer(broker, &self.farm_wrapper, &payments, |sc| { + sc.claim_rewards(OptionalValue::Some(managed_address!(user))) + .into_tuple(); + }) + } + + pub fn unstake_farm_for_other_user( + &mut self, + user: &Address, + broker: &Address, + farm_in_nonce: u64, + farm_in_amount: u64, + ) -> TxResult { + let mut payments = vec![]; + payments.push(TxTokenTransfer { + token_identifier: FARM_TOKEN_ID.to_vec(), + nonce: farm_in_nonce, + value: rust_biguint!(farm_in_amount), + }); + + self.b_mock + .execute_esdt_multi_transfer(broker, &self.farm_wrapper, &payments, |sc| { + sc.unstake_farm(OptionalValue::Some(managed_address!(user))) + .into_tuple(); + }) + } + #[allow(clippy::too_many_arguments)] pub fn claim_rewards( &mut self, + user: &Address, farm_token_amount: u64, farm_token_nonce: u64, expected_reward_token_out: u64, @@ -223,7 +298,7 @@ where ) { self.b_mock .execute_esdt_transfer( - &self.user_address, + user, &self.farm_wrapper, FARM_TOKEN_ID, farm_token_nonce, @@ -256,26 +331,20 @@ where reward_per_share: managed_biguint!(expected_reward_per_share), compounded_reward: managed_biguint!(0), current_farm_amount: managed_biguint!(farm_token_amount), - original_owner: managed_address!(&self.user_address), + original_owner: managed_address!(user), }; self.b_mock.check_nft_balance( - &self.user_address, + user, FARM_TOKEN_ID, expected_farm_token_nonce_out, &rust_biguint!(farm_token_amount), Some(&expected_attributes), ); - self.b_mock.check_esdt_balance( - &self.user_address, - REWARD_TOKEN_ID, - expected_user_reward_token_balance, - ); - self.b_mock.check_esdt_balance( - &self.user_address, - FARMING_TOKEN_ID, - expected_user_farming_token_balance, - ); + self.b_mock + .check_esdt_balance(user, REWARD_TOKEN_ID, expected_user_reward_token_balance); + self.b_mock + .check_esdt_balance(user, FARMING_TOKEN_ID, expected_user_farming_token_balance); } pub fn claim_boosted_rewards_for_user( @@ -309,9 +378,77 @@ where ); } + pub fn claim_boosted_rewards_for_user_expect_error( + &mut self, + owner: &Address, + broker: &Address, + ) { + self.b_mock + .execute_tx(broker, &self.farm_wrapper, &rust_biguint!(0), |sc| { + let _ = sc.claim_boosted_rewards(OptionalValue::Some(managed_address!(owner))); + }) + .assert_error(4, "Cannot claim rewards for this address"); + } + + #[allow(clippy::too_many_arguments)] + pub fn compound_rewards( + &mut self, + user: &Address, + farm_in_nonce: u64, + farm_in_amount: u64, + additional_farm_tokens: &[TxTokenTransfer], + expected_farm_token_nonce: u64, + expected_farm_token_amount: u64, + expected_reward_per_share: u64, + expected_compounded_reward: u64, + ) { + let mut payments = Vec::with_capacity(1 + additional_farm_tokens.len()); + payments.push(TxTokenTransfer { + token_identifier: FARM_TOKEN_ID.to_vec(), + nonce: farm_in_nonce, + value: rust_biguint!(farm_in_amount), + }); + payments.extend_from_slice(additional_farm_tokens); + + self.b_mock + .execute_esdt_multi_transfer(user, &self.farm_wrapper, &payments, |sc| { + let new_farm_token_payment = sc.compound_rewards(); + assert_eq!( + new_farm_token_payment.token_identifier, + managed_token_id!(FARM_TOKEN_ID) + ); + assert_eq!( + new_farm_token_payment.token_nonce, + expected_farm_token_nonce + ); + assert_eq!( + new_farm_token_payment.amount, + managed_biguint!(expected_farm_token_amount) + ); + }) + .assert_ok(); + + let expected_attributes = StakingFarmTokenAttributes:: { + reward_per_share: managed_biguint!(expected_reward_per_share), + compounded_reward: managed_biguint!(expected_compounded_reward), + current_farm_amount: managed_biguint!( + expected_farm_token_amount + expected_compounded_reward + ), + original_owner: managed_address!(&user), + }; + self.b_mock.check_nft_balance( + user, + FARM_TOKEN_ID, + expected_farm_token_nonce, + &rust_biguint!(expected_farm_token_amount + expected_compounded_reward), + Some(&expected_attributes), + ); + } + #[allow(clippy::too_many_arguments)] pub fn unstake_farm( &mut self, + user: &Address, farm_token_amount: u64, farm_token_nonce: u64, expected_rewards_out: u64, @@ -323,7 +460,7 @@ where ) { self.b_mock .execute_esdt_transfer( - &self.user_address, + user, &self.farm_wrapper, FARM_TOKEN_ID, farm_token_nonce, @@ -429,14 +566,10 @@ where .assert_ok(); } - pub fn allow_external_claim_rewards(&mut self, user: &Address) { + pub fn allow_external_claim_rewards(&mut self, user: &Address, allow_claim: bool) { self.b_mock .execute_tx(user, &self.farm_wrapper, &rust_biguint!(0), |sc| { - sc.user_total_farm_position(&managed_address!(user)).update( - |user_total_farm_position| { - user_total_farm_position.allow_external_claim_boosted_rewards = true; - }, - ); + sc.allow_external_claim_boosted_rewards(allow_claim); }) .assert_ok(); } @@ -534,4 +667,113 @@ where ) .assert_error(expected_status, expected_message) } + + pub fn send_position( + &mut self, + sender: &Address, + receiver: &Address, + nonce: u64, + amount: u64, + attr_reward_per_share: u64, + ) { + self.b_mock.check_nft_balance( + sender, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(amount), + Some(&StakingFarmTokenAttributes:: { + reward_per_share: managed_biguint!(attr_reward_per_share), + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(amount), + original_owner: managed_address!(&sender), + }), + ); + + self.b_mock + .check_nft_balance::>( + receiver, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(0), + None, + ); + + self.b_mock.set_nft_balance( + sender, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(0), + &StakingFarmTokenAttributes:: { + reward_per_share: managed_biguint!(attr_reward_per_share), + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(amount), + original_owner: managed_address!(&sender), + }, + ); + + self.b_mock.set_nft_balance( + receiver, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(amount), + &StakingFarmTokenAttributes:: { + reward_per_share: managed_biguint!(attr_reward_per_share), + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(amount), + original_owner: managed_address!(&sender), + }, + ); + + self.b_mock + .check_nft_balance::>( + sender, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(0), + None, + ); + + self.b_mock.check_nft_balance( + receiver, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(amount), + Some(&StakingFarmTokenAttributes:: { + reward_per_share: managed_biguint!(attr_reward_per_share), + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(amount), + original_owner: managed_address!(&sender), + }), + ); + } + + pub fn check_user_total_farm_position(&mut self, user_addr: &Address, expected_amount: u64) { + self.b_mock + .execute_query(&self.farm_wrapper, |sc| { + let user_total_farm_position_mapper = + sc.user_total_farm_position(&managed_address!(user_addr)); + if expected_amount > 0 && !user_total_farm_position_mapper.is_empty() { + assert_eq!( + managed_biguint!(expected_amount), + user_total_farm_position_mapper.get().total_farm_position + ); + } + }) + .assert_ok(); + } + + pub fn update_energy_for_user(&mut self, user_addr: &Address) { + self.b_mock + .execute_tx( + user_addr, + &self.energy_factory_wrapper, + &rust_biguint!(0), + |sc| { + let user_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(user_addr)); + sc.set_energy_entry(&managed_address!(user_addr), user_energy); + }, + ) + .assert_ok(); + } } diff --git a/farm-staking/farm-staking/tests/farm_staking_test.rs b/farm-staking/farm-staking/tests/farm_staking_test.rs index 89192a6a1..26a9d065b 100644 --- a/farm-staking/farm-staking/tests/farm_staking_test.rs +++ b/farm-staking/farm-staking/tests/farm_staking_test.rs @@ -20,9 +20,18 @@ fn test_enter_farm() { let mut farm_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = farm_setup.user_address.clone(); + let farm_in_amount = 100_000_000; let expected_farm_token_nonce = 1; - farm_setup.stake_farm(farm_in_amount, &[], expected_farm_token_nonce, 0, 0); + farm_setup.stake_farm( + &user_address, + farm_in_amount, + &[], + expected_farm_token_nonce, + 0, + 0, + ); farm_setup.check_farm_token_supply(farm_in_amount); } @@ -32,9 +41,18 @@ fn test_unstake_farm() { let mut farm_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = farm_setup.user_address.clone(); + let farm_in_amount = 100_000_000; let expected_farm_token_nonce = 1; - farm_setup.stake_farm(farm_in_amount, &[], expected_farm_token_nonce, 0, 0); + farm_setup.stake_farm( + &user_address, + farm_in_amount, + &[], + expected_farm_token_nonce, + 0, + 0, + ); farm_setup.check_farm_token_supply(farm_in_amount); let current_block = 10; @@ -54,6 +72,7 @@ fn test_unstake_farm() { let expected_ride_token_balance = rust_biguint!(USER_TOTAL_RIDE_TOKENS) - farm_in_amount + expected_rewards; farm_setup.unstake_farm( + &user_address, farm_in_amount, expected_farm_token_nonce, expected_rewards, @@ -74,9 +93,18 @@ fn test_claim_rewards() { let mut farm_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = farm_setup.user_address.clone(); + let farm_in_amount = 100_000_000; let expected_farm_token_nonce = 1; - farm_setup.stake_farm(farm_in_amount, &[], expected_farm_token_nonce, 0, 0); + farm_setup.stake_farm( + &user_address, + farm_in_amount, + &[], + expected_farm_token_nonce, + 0, + 0, + ); farm_setup.check_farm_token_supply(farm_in_amount); farm_setup.set_block_epoch(5); @@ -88,6 +116,7 @@ fn test_claim_rewards() { rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out); let expected_reward_per_share = 400_000; farm_setup.claim_rewards( + &user_address, farm_in_amount, expected_farm_token_nonce, expected_reward_token_out, @@ -109,9 +138,18 @@ where { let mut farm_setup = FarmStakingSetup::new(farm_builder, energy_factory_builder); + let user_address = farm_setup.user_address.clone(); + let farm_in_amount = 100_000_000; let expected_farm_token_nonce = 1; - farm_setup.stake_farm(farm_in_amount, &[], expected_farm_token_nonce, 0, 0); + farm_setup.stake_farm( + &user_address, + farm_in_amount, + &[], + expected_farm_token_nonce, + 0, + 0, + ); farm_setup.check_farm_token_supply(farm_in_amount); farm_setup.set_block_epoch(5); @@ -134,6 +172,7 @@ where / total_amount; farm_setup.stake_farm( + &user_address, second_farm_in_amount, &prev_farm_tokens, expected_farm_token_nonce + 1, @@ -156,6 +195,9 @@ fn test_exit_farm_after_enter_twice() { DebugApi::dummy(); let mut farm_setup = steps_enter_farm_twice(farm_staking::contract_obj, energy_factory::contract_obj); + + let user_address = farm_setup.user_address.clone(); + let farm_in_amount = 100_000_000; let second_farm_in_amount = 200_000_000; @@ -167,6 +209,7 @@ fn test_exit_farm_after_enter_twice() { rust_biguint!(USER_TOTAL_RIDE_TOKENS) - farm_in_amount - second_farm_in_amount + expected_rewards; farm_setup.unstake_farm( + &user_address, farm_in_amount, 2, expected_rewards, @@ -187,9 +230,18 @@ fn test_unbond() { let mut farm_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = farm_setup.user_address.clone(); + let farm_in_amount = 100_000_000; let expected_farm_token_nonce = 1; - farm_setup.stake_farm(farm_in_amount, &[], expected_farm_token_nonce, 0, 0); + farm_setup.stake_farm( + &user_address, + farm_in_amount, + &[], + expected_farm_token_nonce, + 0, + 0, + ); farm_setup.check_farm_token_supply(farm_in_amount); let current_block = 10; @@ -209,6 +261,7 @@ fn test_unbond() { let expected_ride_token_balance = rust_biguint!(USER_TOTAL_RIDE_TOKENS) - farm_in_amount + expected_rewards; farm_setup.unstake_farm( + &user_address, farm_in_amount, expected_farm_token_nonce, expected_rewards, @@ -254,12 +307,21 @@ fn test_withdraw_after_produced_rewards() { let mut farm_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = farm_setup.user_address.clone(); + let initial_rewards_capacity = 1_000_000_000_000u64; farm_setup.check_rewards_capacity(initial_rewards_capacity); let farm_in_amount = 100_000_000; let expected_farm_token_nonce = 1; - farm_setup.stake_farm(farm_in_amount, &[], expected_farm_token_nonce, 0, 0); + farm_setup.stake_farm( + &user_address, + farm_in_amount, + &[], + expected_farm_token_nonce, + 0, + 0, + ); farm_setup.check_farm_token_supply(farm_in_amount); farm_setup.set_block_epoch(5); diff --git a/farm-staking/farm-staking/wasm/Cargo.lock b/farm-staking/farm-staking/wasm/Cargo.lock index 88d4b1bba..79a0f410b 100644 --- a/farm-staking/farm-staking/wasm/Cargo.lock +++ b/farm-staking/farm-staking/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common-types" @@ -316,9 +316,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -329,9 +329,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -339,9 +339,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -351,9 +351,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -364,18 +364,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -433,9 +433,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/farm-staking/farm-staking/wasm/Cargo.toml b/farm-staking/farm-staking/wasm/Cargo.toml index 0dbb347b9..7068d3f6e 100644 --- a/farm-staking/farm-staking/wasm/Cargo.toml +++ b/farm-staking/farm-staking/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/farm-staking/metabonding-staking/Cargo.toml b/farm-staking/metabonding-staking/Cargo.toml index de3c1ff97..ee8282db3 100644 --- a/farm-staking/metabonding-staking/Cargo.toml +++ b/farm-staking/metabonding-staking/Cargo.toml @@ -9,11 +9,11 @@ publish = false path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" [dependencies.factory] path = "../../locked-asset/factory" @@ -22,7 +22,7 @@ path = "../../locked-asset/factory" num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" [dev-dependencies.common_structs] path = "../../common/common_structs" diff --git a/farm-staking/metabonding-staking/meta/Cargo.toml b/farm-staking/metabonding-staking/meta/Cargo.toml index 71df2c0ba..2e049a4d6 100644 --- a/farm-staking/metabonding-staking/meta/Cargo.toml +++ b/farm-staking/metabonding-staking/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/farm-staking/metabonding-staking/src/lib.rs b/farm-staking/metabonding-staking/src/lib.rs index 94be22193..d15ce3c90 100644 --- a/farm-staking/metabonding-staking/src/lib.rs +++ b/farm-staking/metabonding-staking/src/lib.rs @@ -26,7 +26,7 @@ pub trait MetabondingStaking: .set_if_empty(&locked_asset_factory_address); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[payable("*")] diff --git a/farm-staking/metabonding-staking/wasm/Cargo.lock b/farm-staking/metabonding-staking/wasm/Cargo.lock index 739fec429..21aba28e9 100644 --- a/farm-staking/metabonding-staking/wasm/Cargo.lock +++ b/farm-staking/metabonding-staking/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "cfg-if" @@ -170,9 +170,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -183,9 +183,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -193,9 +193,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -205,9 +205,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -218,18 +218,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -254,9 +254,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/farm-staking/metabonding-staking/wasm/Cargo.toml b/farm-staking/metabonding-staking/wasm/Cargo.toml index fe2a7c6c2..79b5e4fc0 100644 --- a/farm-staking/metabonding-staking/wasm/Cargo.toml +++ b/farm-staking/metabonding-staking/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/locked-asset/Cargo.toml b/locked-asset/Cargo.toml index d7ba66a4c..443d0040d 100644 --- a/locked-asset/Cargo.toml +++ b/locked-asset/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" publish = false [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.farm] @@ -50,7 +50,7 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" diff --git a/locked-asset/distribution/Cargo.toml b/locked-asset/distribution/Cargo.toml index 3ebf0939b..a966c5af6 100644 --- a/locked-asset/distribution/Cargo.toml +++ b/locked-asset/distribution/Cargo.toml @@ -14,8 +14,8 @@ path = "../../common/common_structs" path = "../factory" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" diff --git a/locked-asset/distribution/meta/Cargo.toml b/locked-asset/distribution/meta/Cargo.toml index 76c13747b..de2ca6868 100644 --- a/locked-asset/distribution/meta/Cargo.toml +++ b/locked-asset/distribution/meta/Cargo.toml @@ -9,5 +9,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/locked-asset/distribution/src/lib.rs b/locked-asset/distribution/src/lib.rs index 93187154e..b996701df 100644 --- a/locked-asset/distribution/src/lib.rs +++ b/locked-asset/distribution/src/lib.rs @@ -47,7 +47,7 @@ pub trait Distribution: global_op::GlobalOperationModule { .set_if_empty(&locked_asset_factory_address); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[only_owner] diff --git a/locked-asset/distribution/wasm/Cargo.lock b/locked-asset/distribution/wasm/Cargo.lock index fce0d3ebe..a66da5bfb 100644 --- a/locked-asset/distribution/wasm/Cargo.lock +++ b/locked-asset/distribution/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "cfg-if" @@ -170,9 +170,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -183,9 +183,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -193,9 +193,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -205,9 +205,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -218,18 +218,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -254,9 +254,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/locked-asset/distribution/wasm/Cargo.toml b/locked-asset/distribution/wasm/Cargo.toml index f1cc0ae57..e63900a72 100644 --- a/locked-asset/distribution/wasm/Cargo.toml +++ b/locked-asset/distribution/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/locked-asset/energy-factory/Cargo.toml b/locked-asset/energy-factory/Cargo.toml index 74e3cbea9..2e2f62dc6 100644 --- a/locked-asset/energy-factory/Cargo.toml +++ b/locked-asset/energy-factory/Cargo.toml @@ -33,11 +33,11 @@ path = "../../common/traits/unwrappable" path = "../../common/modules/legacy_token_decode_module" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" [dev-dependencies] num-bigint = "0.4.2" @@ -45,4 +45,4 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" diff --git a/locked-asset/energy-factory/meta/Cargo.toml b/locked-asset/energy-factory/meta/Cargo.toml index 6365191f0..5516a213f 100644 --- a/locked-asset/energy-factory/meta/Cargo.toml +++ b/locked-asset/energy-factory/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/locked-asset/energy-factory/src/lib.rs b/locked-asset/energy-factory/src/lib.rs index d146566d6..f38c2e0e7 100644 --- a/locked-asset/energy-factory/src/lib.rs +++ b/locked-asset/energy-factory/src/lib.rs @@ -91,7 +91,7 @@ pub trait SimpleLockEnergy: self.set_paused(true); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} /// Locks a whitelisted token until `unlock_epoch` and receive meta ESDT LOCKED tokens diff --git a/locked-asset/energy-factory/tests/energy_factory_setup/mod.rs b/locked-asset/energy-factory/tests/energy_factory_setup/mod.rs index de10068c0..7d2c17b79 100644 --- a/locked-asset/energy-factory/tests/energy_factory_setup/mod.rs +++ b/locked-asset/energy-factory/tests/energy_factory_setup/mod.rs @@ -173,6 +173,7 @@ where token_nonce: u64, amount: u64, lock_epochs: u64, + opt_address: Option
, ) -> TxResult { self.b_mock.execute_esdt_transfer( caller, @@ -181,7 +182,15 @@ where token_nonce, &rust_biguint!(amount), |sc| { - sc.lock_tokens_endpoint(lock_epochs, OptionalValue::None); + if opt_address.is_some() { + let address = opt_address.unwrap(); + sc.lock_tokens_endpoint( + lock_epochs, + OptionalValue::Some(managed_address!(&address)), + ); + } else { + sc.lock_tokens_endpoint(lock_epochs, OptionalValue::None); + } }, ) } diff --git a/locked-asset/energy-factory/tests/simple_lock_energy_test.rs b/locked-asset/energy-factory/tests/simple_lock_energy_test.rs index 823a8eb56..202630958 100644 --- a/locked-asset/energy-factory/tests/simple_lock_energy_test.rs +++ b/locked-asset/energy-factory/tests/simple_lock_energy_test.rs @@ -2,7 +2,9 @@ mod energy_factory_setup; -use energy_factory::energy::EnergyModule; +use energy_factory::{ + energy::EnergyModule, locked_token_transfer::LockedTokenTransferModule, SimpleLockEnergy, +}; use energy_factory_setup::*; use multiversx_sc::types::BigUint; use simple_lock::locked_token::LockedTokenAttributes; @@ -315,6 +317,7 @@ fn reduce_lock_period_test() { fn extend_locking_period_test() { let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); let first_user = setup.first_user.clone(); + let random_user = setup.b_mock.create_user_account(&rust_biguint!(0u64)); let half_balance = USER_BALANCE / 2; let current_epoch = 1; @@ -329,7 +332,7 @@ fn extend_locking_period_test() { ) .assert_ok(); - // extend to 3 years - unsupported option + // extend to a random period - unsupported option setup .extend_locking_period( &first_user, @@ -337,10 +340,30 @@ fn extend_locking_period_test() { 1, half_balance, 3 * EPOCHS_IN_YEAR, + None, ) .assert_user_error("Invalid lock choice"); - // extend to 10 years + // extend to a whitelisted period, but for a different user + setup + .extend_locking_period( + &first_user, + LOCKED_TOKEN_ID, + 1, + half_balance, + LOCK_OPTIONS[1], + Some(random_user), + ) + .assert_user_error("May not use the optional destination argument here"); + + // extend to the second option - should work as intended + // 1 epoch has passed + let energy_per_epoch = rust_biguint!(500_000_000_000_000_000u64); + let energy_before = setup.get_user_energy(&first_user); // 179_500_000_000_000_000_000 + assert_eq!( + energy_before, + LOCK_OPTIONS[0] * energy_per_epoch.clone() - energy_per_epoch.clone() + ); setup .extend_locking_period( &first_user, @@ -348,8 +371,14 @@ fn extend_locking_period_test() { 1, half_balance, LOCK_OPTIONS[1], + None, ) .assert_ok(); + let energy_after = setup.get_user_energy(&first_user); // 359_500_000_000_000_000_000 + assert_eq!( + energy_after, + LOCK_OPTIONS[1] * energy_per_epoch.clone() - energy_per_epoch.clone() + ); let new_unlock_epoch = to_start_of_month(current_epoch + LOCK_OPTIONS[1]); setup.b_mock.check_nft_balance( @@ -376,6 +405,7 @@ fn extend_locking_period_test() { 2, half_balance, LOCK_OPTIONS[0], + None, ) .assert_user_error("New lock period must be longer than the current one"); } @@ -461,3 +491,78 @@ fn energy_deplete_test() { }) .assert_ok(); } + +#[test] +fn extend_lock_period_endpoint_test() { + let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); + let first_user = setup.first_user.clone(); + + let current_epoch = 1; + setup.b_mock.set_block_epoch(current_epoch); + + setup + .lock( + &first_user, + BASE_ASSET_TOKEN_ID, + USER_BALANCE, + LOCK_OPTIONS[0], + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.sc_wrapper, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.extend_lock_period(100, managed_address!(&first_user)); + }, + ) + .assert_user_error("Invalid lock choice"); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.sc_wrapper, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.extend_lock_period(LOCK_OPTIONS[0], managed_address!(&first_user)); + }, + ) + .assert_user_error("May not call this endpoint. Use lockTokens instead"); + + let energy_per_epoch = rust_biguint!(USER_BALANCE); + let energy_before = setup.get_user_energy(&first_user); + assert_eq!( + energy_before, + LOCK_OPTIONS[0] * energy_per_epoch.clone() - energy_per_epoch.clone() + ); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.sc_wrapper, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.token_transfer_whitelist() + .add(&managed_address!(&first_user)); + sc.extend_lock_period(LOCK_OPTIONS[1], managed_address!(&first_user)); + }, + ) + .assert_ok(); + + let energy_after = setup.get_user_energy(&first_user); + assert_eq!( + energy_after, + LOCK_OPTIONS[1] * energy_per_epoch.clone() - energy_per_epoch.clone() + ); +} diff --git a/locked-asset/energy-factory/wasm/Cargo.lock b/locked-asset/energy-factory/wasm/Cargo.lock index b7f42af38..d25961008 100644 --- a/locked-asset/energy-factory/wasm/Cargo.lock +++ b/locked-asset/energy-factory/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common_errors" @@ -112,9 +112,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -125,9 +125,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -135,9 +135,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -147,9 +147,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -160,18 +160,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -196,9 +196,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/locked-asset/energy-factory/wasm/Cargo.toml b/locked-asset/energy-factory/wasm/Cargo.toml index 944055b38..05c44897a 100644 --- a/locked-asset/energy-factory/wasm/Cargo.toml +++ b/locked-asset/energy-factory/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/locked-asset/factory/Cargo.toml b/locked-asset/factory/Cargo.toml index 6996881d1..2fb4cc002 100644 --- a/locked-asset/factory/Cargo.toml +++ b/locked-asset/factory/Cargo.toml @@ -26,11 +26,11 @@ path = "../../common/modules/token_merge_helper" path = "../energy-factory" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" [dependencies.arrayvec] version = "0.7.1" @@ -49,4 +49,4 @@ hex = "0.4" path = "../simple-lock" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" diff --git a/locked-asset/factory/meta/Cargo.toml b/locked-asset/factory/meta/Cargo.toml index d81d3bb85..4bc27087e 100644 --- a/locked-asset/factory/meta/Cargo.toml +++ b/locked-asset/factory/meta/Cargo.toml @@ -9,5 +9,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/locked-asset/factory/src/lib.rs b/locked-asset/factory/src/lib.rs index d8de993b4..b826bb14b 100644 --- a/locked-asset/factory/src/lib.rs +++ b/locked-asset/factory/src/lib.rs @@ -63,7 +63,7 @@ pub trait LockedAssetFactory: self.set_paused(true); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} fn set_extended_attributes_activation_nonce(&self, is_sc_upgrade: bool) { diff --git a/locked-asset/factory/wasm/Cargo.lock b/locked-asset/factory/wasm/Cargo.lock index 39d478ef4..26e60cd35 100644 --- a/locked-asset/factory/wasm/Cargo.lock +++ b/locked-asset/factory/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "cfg-if" @@ -161,9 +161,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -174,9 +174,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -184,9 +184,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -196,9 +196,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -209,18 +209,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -245,9 +245,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/locked-asset/factory/wasm/Cargo.toml b/locked-asset/factory/wasm/Cargo.toml index eb8c084a5..e3d3cf466 100644 --- a/locked-asset/factory/wasm/Cargo.toml +++ b/locked-asset/factory/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/locked-asset/lkmex-transfer/Cargo.toml b/locked-asset/lkmex-transfer/Cargo.toml index a6fb9ca95..2f4631f56 100644 --- a/locked-asset/lkmex-transfer/Cargo.toml +++ b/locked-asset/lkmex-transfer/Cargo.toml @@ -30,14 +30,14 @@ path = "../energy-factory" path = "../../energy-integration/common-modules/energy-query" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" [dev-dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" diff --git a/locked-asset/lkmex-transfer/meta/Cargo.toml b/locked-asset/lkmex-transfer/meta/Cargo.toml index e0c0588d1..78211a21e 100644 --- a/locked-asset/lkmex-transfer/meta/Cargo.toml +++ b/locked-asset/lkmex-transfer/meta/Cargo.toml @@ -9,5 +9,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/locked-asset/lkmex-transfer/src/lib.rs b/locked-asset/lkmex-transfer/src/lib.rs index 7c187882e..126e740b8 100644 --- a/locked-asset/lkmex-transfer/src/lib.rs +++ b/locked-asset/lkmex-transfer/src/lib.rs @@ -56,7 +56,7 @@ pub trait LkmexTransfer: self.add_permissions(caller, Permissions::OWNER); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[endpoint] diff --git a/locked-asset/lkmex-transfer/wasm/Cargo.lock b/locked-asset/lkmex-transfer/wasm/Cargo.lock index 503d067d7..b1689bd61 100644 --- a/locked-asset/lkmex-transfer/wasm/Cargo.lock +++ b/locked-asset/lkmex-transfer/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common_errors" @@ -134,9 +134,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -147,9 +147,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -157,9 +157,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -169,9 +169,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -182,18 +182,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -227,9 +227,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/locked-asset/lkmex-transfer/wasm/Cargo.toml b/locked-asset/lkmex-transfer/wasm/Cargo.toml index dee74ceae..474ebc202 100644 --- a/locked-asset/lkmex-transfer/wasm/Cargo.toml +++ b/locked-asset/lkmex-transfer/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/locked-asset/locked-token-wrapper/Cargo.toml b/locked-asset/locked-token-wrapper/Cargo.toml index 787914eeb..941f8aa52 100644 --- a/locked-asset/locked-token-wrapper/Cargo.toml +++ b/locked-asset/locked-token-wrapper/Cargo.toml @@ -9,10 +9,10 @@ publish = false path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" [dependencies.utils] path = "../../common/modules/utils" @@ -44,4 +44,4 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" diff --git a/locked-asset/locked-token-wrapper/meta/Cargo.toml b/locked-asset/locked-token-wrapper/meta/Cargo.toml index 6de0a4093..400316ce3 100644 --- a/locked-asset/locked-token-wrapper/meta/Cargo.toml +++ b/locked-asset/locked-token-wrapper/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/locked-asset/locked-token-wrapper/src/lib.rs b/locked-asset/locked-token-wrapper/src/lib.rs index a6aa3e96f..5398cc42a 100644 --- a/locked-asset/locked-token-wrapper/src/lib.rs +++ b/locked-asset/locked-token-wrapper/src/lib.rs @@ -20,7 +20,7 @@ pub trait LockedTokenWrapper: self.energy_factory_address().set(&energy_factory_address); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[payable("*")] diff --git a/locked-asset/locked-token-wrapper/wasm/Cargo.lock b/locked-asset/locked-token-wrapper/wasm/Cargo.lock index eb6ca7c6e..cf219a208 100644 --- a/locked-asset/locked-token-wrapper/wasm/Cargo.lock +++ b/locked-asset/locked-token-wrapper/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common_errors" @@ -158,9 +158,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -171,9 +171,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -181,9 +181,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -193,9 +193,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -206,18 +206,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -251,9 +251,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/locked-asset/locked-token-wrapper/wasm/Cargo.toml b/locked-asset/locked-token-wrapper/wasm/Cargo.toml index 0d10a2666..87150c0ca 100644 --- a/locked-asset/locked-token-wrapper/wasm/Cargo.toml +++ b/locked-asset/locked-token-wrapper/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/locked-asset/proxy_dex/Cargo.toml b/locked-asset/proxy_dex/Cargo.toml index 5c52745d9..f598598eb 100644 --- a/locked-asset/proxy_dex/Cargo.toml +++ b/locked-asset/proxy_dex/Cargo.toml @@ -45,11 +45,11 @@ path = "../../common/traits/mergeable" path = "../../common/traits/fixed-supply-token" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" [dependencies.energy-factory] path = "../energy-factory" @@ -69,7 +69,7 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" [dev-dependencies.pausable] path = "../../common/modules/pausable" diff --git a/locked-asset/proxy_dex/meta/Cargo.toml b/locked-asset/proxy_dex/meta/Cargo.toml index 41fea1fc8..3a3e9de3e 100644 --- a/locked-asset/proxy_dex/meta/Cargo.toml +++ b/locked-asset/proxy_dex/meta/Cargo.toml @@ -9,5 +9,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/locked-asset/proxy_dex/src/lib.rs b/locked-asset/proxy_dex/src/lib.rs index 810cd3640..3e03c2f06 100644 --- a/locked-asset/proxy_dex/src/lib.rs +++ b/locked-asset/proxy_dex/src/lib.rs @@ -58,7 +58,7 @@ pub trait ProxyDexImpl: .set_if_empty(&energy_factory_address); } - #[endpoint] + #[upgrade] fn upgrade(&self, old_locked_token_id: TokenIdentifier, old_factory_address: ManagedAddress) { require!( old_locked_token_id.is_valid_esdt_identifier(), diff --git a/locked-asset/proxy_dex/tests/proxy_dex_test_setup/mod.rs b/locked-asset/proxy_dex/tests/proxy_dex_test_setup/mod.rs index 2ab0326d4..322fedd61 100644 --- a/locked-asset/proxy_dex/tests/proxy_dex_test_setup/mod.rs +++ b/locked-asset/proxy_dex/tests/proxy_dex_test_setup/mod.rs @@ -1,5 +1,6 @@ #![allow(deprecated)] +use common_structs::{LockedAssetTokenAttributesEx, UnlockMilestoneEx, UnlockScheduleEx}; use config::ConfigModule; use energy_factory::{locked_token_transfer::LockedTokenTransferModule, SimpleLockEnergy}; use energy_query::EnergyQueryModule; @@ -11,7 +12,7 @@ use multiversx_sc::{ codec::multi_types::OptionalValue, contract_base::{CallableContract, ContractBase}, storage::mappers::StorageTokenWrapper, - types::{Address, EsdtLocalRole, ManagedAddress, MultiValueEncoded}, + types::{Address, EsdtLocalRole, ManagedAddress, ManagedVec, MultiValueEncoded}, }; use multiversx_sc_modules::pause::PauseModule; use multiversx_sc_scenario::{ @@ -151,6 +152,25 @@ where b_mock.set_esdt_balance(&second_user, MEX_TOKEN_ID, &user_balance); b_mock.set_esdt_balance(&second_user, WEGLD_TOKEN_ID, &user_balance); + let mut unlock_milestones = ManagedVec::::new(); + unlock_milestones.push(UnlockMilestoneEx { + unlock_percent: 10_000, + unlock_epoch: LOCK_OPTIONS[0], + }); + + let old_token_attributes = LockedAssetTokenAttributesEx { + is_merged: false, + unlock_schedule: UnlockScheduleEx { unlock_milestones }, + }; + b_mock.set_nft_balance( + &first_user, + LEGACY_LOCKED_TOKEN_ID, + 3, // higher random nonce to avoid nonce caching conflicts + &rust_biguint!(USER_BALANCE), + &old_token_attributes, + ); + + // users lock tokens b_mock .execute_esdt_transfer( diff --git a/locked-asset/proxy_dex/tests/proxy_farm_test.rs b/locked-asset/proxy_dex/tests/proxy_farm_test.rs index af6c5f6c4..7f7a23b60 100644 --- a/locked-asset/proxy_dex/tests/proxy_farm_test.rs +++ b/locked-asset/proxy_dex/tests/proxy_farm_test.rs @@ -355,7 +355,8 @@ fn farm_with_wrapped_lp_test() { block_epoch, managed_biguint!(user_balance), ); - let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); assert_eq!(expected_energy, actual_energy); }) .assert_ok(); @@ -1181,6 +1182,236 @@ fn different_farm_locked_token_nonce_merging_test() { ); } +#[test] +fn total_farm_mechanism_test() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + let first_user = setup.first_user.clone(); + let farm_addr = setup.farm_locked_wrapper.address_ref().clone(); + let user_balance = rust_biguint!(USER_BALANCE); + setup + .b_mock + .set_esdt_balance(&first_user, MEX_TOKEN_ID, &user_balance); + + // users lock tokens + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.simple_lock_wrapper, + MEX_TOKEN_ID, + 0, + &user_balance, + |sc| { + let user_payment = sc.lock_tokens_endpoint(LOCK_OPTIONS[1], OptionalValue::None); + assert_eq!(user_payment.token_nonce, 2); + assert_eq!(user_payment.amount, managed_biguint!(USER_BALANCE)); + }, + ) + .assert_ok(); + + let mut block_epoch = 1; + setup.b_mock.set_block_epoch(block_epoch); + + // Check total farm position + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = + sc.get_user_total_farm_position(&managed_address!(&first_user)); + assert_eq!( + first_user_total_farm_position.total_farm_position, + managed_biguint!(0) + ); + }) + .assert_ok(); + + //////////////////////////////////////////// ENTER FARM ///////////////////////////////////// + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + // Check total farm position + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = + sc.get_user_total_farm_position(&managed_address!(&first_user)); + assert_eq!( + first_user_total_farm_position.total_farm_position, + managed_biguint!(USER_BALANCE) + ); + }) + .assert_ok(); + + block_epoch += 7; + setup.b_mock.set_block_epoch(block_epoch); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 2, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + // Check total farm position + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = + sc.get_user_total_farm_position(&managed_address!(&first_user)); + assert_eq!( + first_user_total_farm_position.total_farm_position, + managed_biguint!(USER_BALANCE * 2) + ); + }) + .assert_ok(); + + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_FARM_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + Some(&WrappedFarmTokenAttributes:: { + proxy_farming_token: EsdtTokenPayment { + token_identifier: managed_token_id!(LOCKED_TOKEN_ID), + token_nonce: 1, + amount: managed_biguint!(USER_BALANCE), + }, + farm_token: EsdtTokenPayment { + token_identifier: managed_token_id!(FARM_LOCKED_TOKEN_ID), + token_nonce: 1, + amount: managed_biguint!(USER_BALANCE), + }, + }), + ); + + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_FARM_TOKEN_ID, + 2, + &rust_biguint!(USER_BALANCE), + Some(&WrappedFarmTokenAttributes:: { + proxy_farming_token: EsdtTokenPayment { + token_identifier: managed_token_id!(LOCKED_TOKEN_ID), + token_nonce: 2, + amount: managed_biguint!(USER_BALANCE), + }, + farm_token: EsdtTokenPayment { + token_identifier: managed_token_id!(FARM_LOCKED_TOKEN_ID), + token_nonce: 2, + amount: managed_biguint!(USER_BALANCE), + }, + }), + ); + + //////////////////////////////////////////// CLAIM REWARDS ///////////////////////////////////// + + // claim rewards + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_FARM_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.claim_rewards_proxy(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + // Check total farm position + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = + sc.get_user_total_farm_position(&managed_address!(&first_user)); + assert_eq!( + first_user_total_farm_position.total_farm_position, + managed_biguint!(USER_BALANCE * 2) + ); + }) + .assert_ok(); + + // check user balance + setup.b_mock.check_nft_balance::( + &first_user, + LOCKED_TOKEN_ID, + 2, + &rust_biguint!(0), + None, + ); + setup.b_mock.check_nft_balance::( + &first_user, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(0), + None, + ); + + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_FARM_TOKEN_ID, + 3, + &rust_biguint!(USER_BALANCE), + Some(&WrappedFarmTokenAttributes:: { + proxy_farming_token: EsdtTokenPayment { + token_identifier: managed_token_id!(LOCKED_TOKEN_ID), + token_nonce: 1, + amount: managed_biguint!(USER_BALANCE), + }, + farm_token: EsdtTokenPayment { + token_identifier: managed_token_id!(FARM_LOCKED_TOKEN_ID), + token_nonce: 3, + amount: managed_biguint!(USER_BALANCE), + }, + }), + ); + // new NFT + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_FARM_TOKEN_ID, + 2, + &rust_biguint!(USER_BALANCE), + Some(&WrappedFarmTokenAttributes:: { + proxy_farming_token: EsdtTokenPayment { + token_identifier: managed_token_id!(LOCKED_TOKEN_ID), + token_nonce: 2, + amount: managed_biguint!(USER_BALANCE), + }, + farm_token: EsdtTokenPayment { + token_identifier: managed_token_id!(FARM_LOCKED_TOKEN_ID), + token_nonce: 2, + amount: managed_biguint!(USER_BALANCE), + }, + }), + ); +} + #[test] fn increase_proxy_farm_lkmex_energy() { let mut setup = ProxySetup::new( @@ -1222,7 +1453,8 @@ fn increase_proxy_farm_lkmex_energy() { block_epoch, managed_biguint!(USER_BALANCE), ); - let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); assert_eq!(expected_energy, actual_energy); }) .assert_ok(); @@ -1254,7 +1486,8 @@ fn increase_proxy_farm_lkmex_energy() { block_epoch, managed_biguint!(USER_BALANCE), ); - let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); assert_eq!(expected_energy, actual_energy); }) .assert_ok(); @@ -1350,7 +1583,8 @@ fn increase_proxy_farm_proxy_lp_energy() { block_epoch, managed_biguint!(user_balance), ); - let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); assert_eq!(expected_energy, actual_energy); }) .assert_ok(); @@ -1443,6 +1677,17 @@ fn increase_proxy_farm_proxy_lp_energy() { ) .assert_ok(); + // check old tokens were burned + setup + .b_mock + .check_nft_balance::>( + setup.proxy_wrapper.address_ref(), + WRAPPED_FARM_TOKEN_ID, + 4, + &rust_biguint!(0u64), + None, + ); + // check energy after // lp tokens recharged = total tokens / 4 - 500 let user_locked_tokens_in_lp = locked_token_amount.to_u64().unwrap() / 4 - 500; @@ -1460,7 +1705,8 @@ fn increase_proxy_farm_proxy_lp_energy() { block_epoch, managed_biguint!(USER_BALANCE), ); - let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); assert_eq!(expected_energy, actual_energy); }) .assert_ok(); @@ -1486,3 +1732,1037 @@ fn increase_proxy_farm_proxy_lp_energy() { }), ); } + +#[test] +fn increase_proxy_farm_proxy_lp_energy_unlocked_tokens() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + + setup + .b_mock + .execute_tx( + &setup.owner, + &setup.farm_locked_wrapper, + &rust_biguint!(0), + |sc| { + sc.farming_token_id().set(&managed_token_id!(LP_TOKEN_ID)); + + // set produce rewards to false for easier calculation + sc.produce_rewards_enabled().set(false); + }, + ) + .assert_ok(); + + setup.b_mock.set_esdt_local_roles( + setup.farm_locked_wrapper.address_ref(), + LP_TOKEN_ID, + &[EsdtLocalRole::Burn], + ); + + let first_user = setup.first_user.clone(); + let locked_token_amount = rust_biguint!(1_000_000_000); + let other_token_amount = rust_biguint!(500_000_000); + let expected_lp_token_amount = rust_biguint!(499_999_000); + + // set the price to 1 EGLD = 2 MEX + let payments = vec![ + TxTokenTransfer { + token_identifier: LOCKED_TOKEN_ID.to_vec(), + nonce: 1, + value: locked_token_amount.clone(), + }, + TxTokenTransfer { + token_identifier: WEGLD_TOKEN_ID.to_vec(), + nonce: 0, + value: other_token_amount.clone(), + }, + ]; + + // add liquidity twice, to have 2 nonces + let pair_addr = setup.pair_wrapper.address_ref().clone(); + setup + .b_mock + .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &payments, |sc| { + sc.add_liquidity_proxy( + managed_address!(&pair_addr), + managed_biguint!(locked_token_amount.to_u64().unwrap() / 2), + managed_biguint!(other_token_amount.to_u64().unwrap() / 2), + ); + }) + .assert_ok(); + + let pair_addr = setup.pair_wrapper.address_ref().clone(); + setup + .b_mock + .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &payments, |sc| { + sc.add_liquidity_proxy( + managed_address!(&pair_addr), + managed_biguint!(locked_token_amount.to_u64().unwrap() / 2), + managed_biguint!(other_token_amount.to_u64().unwrap() / 2), + ); + }) + .assert_ok(); + + let mut block_epoch = 1u64; + let user_balance = USER_BALANCE; + + // check energy before + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let unlock_epoch = LOCK_OPTIONS[0]; + let lock_epochs = unlock_epoch - block_epoch; + let expected_energy_amount = + BigInt::from((user_balance) as i64) * BigInt::from(lock_epochs as i64); + let expected_energy = Energy::new( + expected_energy_amount, + block_epoch, + managed_biguint!(user_balance), + ); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); + + let farm_locked_addr = setup.farm_locked_wrapper.address_ref().clone(); + + //////////////////////////////////////////// ENTER FARM ///////////////////////////////////// + + // Enter multiple times, to distribute the nonces + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 1, + &(&expected_lp_token_amount / &rust_biguint!(4u64)), + |sc| { + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_locked_addr), + OptionalValue::None, + ); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 2, + &(&expected_lp_token_amount / &rust_biguint!(4u64)), + |sc| { + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_locked_addr), + OptionalValue::None, + ); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 1, + &(&expected_lp_token_amount / &rust_biguint!(4u64)), + |sc| { + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_locked_addr), + OptionalValue::None, + ); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 2, + &(&expected_lp_token_amount / &rust_biguint!(4u64)), + |sc| { + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_locked_addr), + OptionalValue::None, + ); + }, + ) + .assert_ok(); + + ////////////////////////////// Wait for tokens to unlock ///////////////////////////////////// + block_epoch += LOCK_OPTIONS[0]; + setup.b_mock.set_block_epoch(block_epoch); + + //////////////////////////////////////////// INCREASE ENERGY ///////////////////////////////////// + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_FARM_TOKEN_ID, + 4, + &(&expected_lp_token_amount / &rust_biguint!(4u64)), + |sc| { + sc.increase_proxy_farm_token_energy_endpoint(LOCK_OPTIONS[1]); + }, + ) + .assert_ok(); + + // check old tokens were burned + setup + .b_mock + .check_nft_balance::>( + setup.proxy_wrapper.address_ref(), + WRAPPED_FARM_TOKEN_ID, + 4, + &rust_biguint!(0u64), + None, + ); + + // check energy after + // lp tokens recharged = total tokens / 4 - 500 + let user_locked_tokens_in_lp = locked_token_amount.to_u64().unwrap() / 4 - 500; + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let first_lock_epochs = LOCK_OPTIONS[1] - 1u64; + let second_lock_epochs = + BigInt::from(LOCK_OPTIONS[0] as i64) - BigInt::from(block_epoch as i64); + let expected_energy_amount = BigInt::from((user_locked_tokens_in_lp) as i64) + * BigInt::from(first_lock_epochs as i64) + + BigInt::from((USER_BALANCE - user_locked_tokens_in_lp) as i64) + * second_lock_epochs; + let expected_energy = Energy::new( + expected_energy_amount, + block_epoch, + managed_biguint!(USER_BALANCE), + ); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); + + // check user token after increase energy + // new farm token was created + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_FARM_TOKEN_ID, + 5, + &(&expected_lp_token_amount / &rust_biguint!(4u64)), + Some(&WrappedFarmTokenAttributes:: { + proxy_farming_token: EsdtTokenPayment { + token_identifier: managed_token_id!(WRAPPED_LP_TOKEN_ID), + token_nonce: 3, + amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap() / 4u64), + }, + farm_token: EsdtTokenPayment { + token_identifier: managed_token_id!(FARM_LOCKED_TOKEN_ID), + token_nonce: 4, + amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap() / 4u64), + }, + }), + ); +} + +#[test] +fn increase_proxy_farm_proxy_lp_energy_partially_unlocked_tokens() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + + setup + .b_mock + .execute_tx( + &setup.owner, + &setup.farm_locked_wrapper, + &rust_biguint!(0), + |sc| { + sc.farming_token_id().set(&managed_token_id!(LP_TOKEN_ID)); + + // set produce rewards to false for easier calculation + sc.produce_rewards_enabled().set(false); + }, + ) + .assert_ok(); + + setup.b_mock.set_esdt_local_roles( + setup.farm_locked_wrapper.address_ref(), + LP_TOKEN_ID, + &[EsdtLocalRole::Burn], + ); + + let first_user = setup.first_user.clone(); + let locked_token_amount = rust_biguint!(1_000_000_000); + let other_token_amount = rust_biguint!(500_000_000); + let expected_lp_token_amount = rust_biguint!(499_999_000); + + // set the price to 1 EGLD = 2 MEX + let payments = vec![ + TxTokenTransfer { + token_identifier: LOCKED_TOKEN_ID.to_vec(), + nonce: 1, + value: locked_token_amount.clone(), + }, + TxTokenTransfer { + token_identifier: WEGLD_TOKEN_ID.to_vec(), + nonce: 0, + value: other_token_amount.clone(), + }, + ]; + + // add liquidity twice, to have 2 nonces + let pair_addr = setup.pair_wrapper.address_ref().clone(); + setup + .b_mock + .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &payments, |sc| { + sc.add_liquidity_proxy( + managed_address!(&pair_addr), + managed_biguint!(locked_token_amount.to_u64().unwrap() / 2), + managed_biguint!(other_token_amount.to_u64().unwrap() / 2), + ); + }) + .assert_ok(); + + let pair_addr = setup.pair_wrapper.address_ref().clone(); + setup + .b_mock + .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &payments, |sc| { + sc.add_liquidity_proxy( + managed_address!(&pair_addr), + managed_biguint!(locked_token_amount.to_u64().unwrap() / 2), + managed_biguint!(other_token_amount.to_u64().unwrap() / 2), + ); + }) + .assert_ok(); + + let block_epoch = 1u64; + let user_balance = USER_BALANCE; + + // check energy before + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let unlock_epoch = LOCK_OPTIONS[0]; + let lock_epochs = unlock_epoch - block_epoch; + let expected_energy_amount = + BigInt::from((user_balance) as i64) * BigInt::from(lock_epochs as i64); + let expected_energy = Energy::new( + expected_energy_amount, + block_epoch, + managed_biguint!(user_balance), + ); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); + + let farm_locked_addr = setup.farm_locked_wrapper.address_ref().clone(); + + //////////////////////////////////////////// ENTER FARM ///////////////////////////////////// + + // Enter multiple times, to distribute the nonces + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 1, + &(&expected_lp_token_amount / &rust_biguint!(4u64)), + |sc| { + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_locked_addr), + OptionalValue::None, + ); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 2, + &(&expected_lp_token_amount / &rust_biguint!(4u64)), + |sc| { + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_locked_addr), + OptionalValue::None, + ); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 1, + &(&expected_lp_token_amount / &rust_biguint!(4u64)), + |sc| { + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_locked_addr), + OptionalValue::None, + ); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 2, + &(&expected_lp_token_amount / &rust_biguint!(4u64)), + |sc| { + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_locked_addr), + OptionalValue::None, + ); + }, + ) + .assert_ok(); + + //////////////////////////////////////////// INCREASE ENERGY ///////////////////////////////////// + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_FARM_TOKEN_ID, + 4, + &(&expected_lp_token_amount / &rust_biguint!(8u64)), + |sc| { + sc.increase_proxy_farm_token_energy_endpoint(LOCK_OPTIONS[1]); + }, + ) + .assert_ok(); + + // check old tokens were burned + setup + .b_mock + .check_nft_balance::>( + setup.proxy_wrapper.address_ref(), + WRAPPED_FARM_TOKEN_ID, + 4, + &rust_biguint!(0u64), + None, + ); + + // check energy after + // lp tokens recharged = total tokens / 4 - 500 + let user_locked_tokens_in_lp = locked_token_amount.to_u64().unwrap() / 4 - 500; + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let first_lock_epochs = LOCK_OPTIONS[1] - 1u64; + let second_lock_epochs = + BigInt::from(LOCK_OPTIONS[0] as i64) - BigInt::from(block_epoch as i64); + let expected_energy_amount = BigInt::from((user_locked_tokens_in_lp / 2) as i64) + * BigInt::from(first_lock_epochs as i64) + + BigInt::from((USER_BALANCE) as i64) * second_lock_epochs.clone() + - BigInt::from((user_locked_tokens_in_lp / 2u64) as i64) * second_lock_epochs; + + let expected_energy = Energy::new( + expected_energy_amount, + block_epoch, + managed_biguint!(USER_BALANCE), + ); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); + + // check user token after increase energy + // new farm token was created + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_FARM_TOKEN_ID, + 5, + &(&expected_lp_token_amount / &rust_biguint!(8u64)), + Some(&WrappedFarmTokenAttributes:: { + proxy_farming_token: EsdtTokenPayment { + token_identifier: managed_token_id!(WRAPPED_LP_TOKEN_ID), + token_nonce: 3, + amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap() / 8u64), + }, + farm_token: EsdtTokenPayment { + token_identifier: managed_token_id!(FARM_LOCKED_TOKEN_ID), + token_nonce: 4, + amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap() / 8u64), + }, + }), + ); +} + +#[test] +fn original_caller_negative_test() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + let first_user = setup.first_user.clone(); + let farm_addr = setup.farm_locked_wrapper.address_ref().clone(); + let user_balance = rust_biguint!(USER_BALANCE); + setup + .b_mock + .set_esdt_balance(&first_user, MEX_TOKEN_ID, &user_balance); + + // users lock tokens + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.simple_lock_wrapper, + MEX_TOKEN_ID, + 0, + &user_balance, + |sc| { + let user_payment = sc.lock_tokens_endpoint(LOCK_OPTIONS[1], OptionalValue::None); + assert_eq!(user_payment.token_nonce, 2); + assert_eq!(user_payment.amount, managed_biguint!(USER_BALANCE)); + }, + ) + .assert_ok(); + + //////////////////////////////////////////// ENTER FARM ///////////////////////////////////// + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_addr), + Some(managed_address!(&first_user)).into(), + ); + }, + ) + .assert_error(4, "Item not whitelisted"); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + // claim rewards with half position + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_FARM_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE / 2), + |sc| { + sc.claim_rewards_proxy( + managed_address!(&farm_addr), + Some(managed_address!(&first_user)).into(), + ); + }, + ) + .assert_error(4, "Item not whitelisted"); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_FARM_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + let output = sc.exit_farm_proxy( + managed_address!(&farm_addr), + Some(managed_address!(&first_user)).into(), + ); + let output_lp_token = output.0 .0; + assert_eq!(output_lp_token.token_nonce, 1); + assert_eq!(output_lp_token.amount, USER_BALANCE); + }, + ) + .assert_error(4, "Item not whitelisted"); +} + +#[test] +fn total_farm_position_migration_through_proxy_dex_test() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + let first_user = setup.first_user.clone(); + let farm_addr = setup.farm_locked_wrapper.address_ref().clone(); + let user_balance = rust_biguint!(USER_BALANCE); + setup + .b_mock + .set_esdt_balance(&first_user, MEX_TOKEN_ID, &user_balance); + + // user locks tokens + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.simple_lock_wrapper, + MEX_TOKEN_ID, + 0, + &user_balance, + |sc| { + let user_payment = sc.lock_tokens_endpoint(LOCK_OPTIONS[1], OptionalValue::None); + assert_eq!(user_payment.token_nonce, 2); + assert_eq!(user_payment.amount, managed_biguint!(USER_BALANCE)); + }, + ) + .assert_ok(); + + // User enter farm before migration + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + // Simulate contract upgrade - total farm position is reset and migration nonce set + setup + .b_mock + .execute_tx( + &setup.owner, + &setup.farm_locked_wrapper, + &rust_biguint!(0), + |sc| { + let mut first_user_total_farm_position = + sc.get_user_total_farm_position(&managed_address!(&first_user)); + first_user_total_farm_position.total_farm_position = managed_biguint!(0u64); + + sc.user_total_farm_position(&managed_address!(&first_user)) + .set(first_user_total_farm_position); + sc.farm_position_migration_nonce().set(2u64); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = + sc.get_user_total_farm_position(&managed_address!(&first_user)); + assert_eq!( + first_user_total_farm_position.total_farm_position, + managed_biguint!(0) + ); + }) + .assert_ok(); + + // User enters farm again after migration + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 2, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = + sc.get_user_total_farm_position(&managed_address!(&first_user)); + assert_eq!( + first_user_total_farm_position.total_farm_position, + managed_biguint!(USER_BALANCE) + ); + }) + .assert_ok(); + + // Merge user tokens + let payments = vec![ + TxTokenTransfer { + token_identifier: WRAPPED_FARM_TOKEN_ID.to_vec(), + nonce: 1, + value: rust_biguint!(USER_BALANCE), + }, + TxTokenTransfer { + token_identifier: WRAPPED_FARM_TOKEN_ID.to_vec(), + nonce: 2, + value: rust_biguint!(USER_BALANCE), + }, + ]; + setup + .b_mock + .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &payments, |sc| { + sc.merge_wrapped_farm_tokens_endpoint(managed_address!(&farm_addr)); + }) + .assert_ok(); + + // Total farm position should be correct + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = + sc.get_user_total_farm_position(&managed_address!(&first_user)); + assert_eq!( + first_user_total_farm_position.total_farm_position, + managed_biguint!(USER_BALANCE * 2) + ); + }) + .assert_ok(); +} + +#[test] +fn increase_proxy_farm_legacy_token_energy_negative_test() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + let first_user = setup.first_user.clone(); + let farm_addr = setup.farm_locked_wrapper.address_ref().clone(); + + //////////////////////////////////////////// ENTER FARM ///////////////////////////////////// + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LEGACY_LOCKED_TOKEN_ID, + 3, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + //////////////////////////////////////////// INCREASE ENERGY ///////////////////////////////////// + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_FARM_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.increase_proxy_farm_token_energy_endpoint(LOCK_OPTIONS[1]); + }, + ) + .assert_user_error("Invalid payments"); +} + +#[test] +fn total_farm_position_migration_mechanism_test() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + let first_user = setup.first_user.clone(); + let farm_addr = setup.farm_locked_wrapper.address_ref().clone(); + let user_balance = rust_biguint!(USER_BALANCE * 6); + setup + .b_mock + .set_esdt_balance(&first_user, MEX_TOKEN_ID, &user_balance); + + // user locks tokens + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.simple_lock_wrapper, + MEX_TOKEN_ID, + 0, + &user_balance, + |sc| { + let user_payment = sc.lock_tokens_endpoint(LOCK_OPTIONS[1], OptionalValue::None); + assert_eq!(user_payment.token_nonce, 2); + assert_eq!(user_payment.amount, managed_biguint!(USER_BALANCE * 6)); + }, + ) + .assert_ok(); + + // User enter farm 5 times before migration + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 2, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 2, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 2, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 2, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 2, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + // Simulate contract upgrade - total farm position is reset and migration nonce set + setup + .b_mock + .execute_tx( + &setup.owner, + &setup.farm_locked_wrapper, + &rust_biguint!(0), + |sc| { + let mut first_user_total_farm_position = + sc.get_user_total_farm_position(&managed_address!(&first_user)); + first_user_total_farm_position.total_farm_position = managed_biguint!(0u64); + + sc.user_total_farm_position(&managed_address!(&first_user)) + .set(first_user_total_farm_position); + sc.farm_position_migration_nonce().set(6u64); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = + sc.get_user_total_farm_position(&managed_address!(&first_user)); + assert_eq!( + first_user_total_farm_position.total_farm_position, + managed_biguint!(0) + ); + }) + .assert_ok(); + + // User enters farm again after migration + let enter_payments = vec![ + TxTokenTransfer { + token_identifier: LOCKED_TOKEN_ID.to_vec(), + nonce: 2, + value: rust_biguint!(USER_BALANCE), + }, + TxTokenTransfer { + token_identifier: WRAPPED_FARM_TOKEN_ID.to_vec(), + nonce: 1, + value: rust_biguint!(USER_BALANCE / 2), + }, + ]; + setup + .b_mock + .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &enter_payments, |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }) + .assert_ok(); + + // Check total farm position + let mut user_total_farm_position = USER_BALANCE + (USER_BALANCE / 2); + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = + sc.get_user_total_farm_position(&managed_address!(&first_user)); + assert_eq!( + first_user_total_farm_position.total_farm_position, + managed_biguint!(user_total_farm_position) + ); + }) + .assert_ok(); + + // Claim rewards with half old position + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_FARM_TOKEN_ID, + 2, + &rust_biguint!(USER_BALANCE / 2), + |sc| { + sc.claim_rewards_proxy(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + // Check total farm position + user_total_farm_position += USER_BALANCE / 2; + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = + sc.get_user_total_farm_position(&managed_address!(&first_user)); + assert_eq!( + first_user_total_farm_position.total_farm_position, + managed_biguint!(user_total_farm_position) + ); + }) + .assert_ok(); + + // Exit farm with half old position + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_FARM_TOKEN_ID, + 3, + &rust_biguint!(USER_BALANCE / 2), + |sc| { + sc.exit_farm_proxy(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + // Total farm position stays the same + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = + sc.get_user_total_farm_position(&managed_address!(&first_user)); + assert_eq!( + first_user_total_farm_position.total_farm_position, + managed_biguint!(user_total_farm_position) + ); + }) + .assert_ok(); + + // Merge 2 partial old farm positions + let merge_payments = vec![ + TxTokenTransfer { + token_identifier: WRAPPED_FARM_TOKEN_ID.to_vec(), + nonce: 4, + value: rust_biguint!(USER_BALANCE / 2), + }, + TxTokenTransfer { + token_identifier: WRAPPED_FARM_TOKEN_ID.to_vec(), + nonce: 5, + value: rust_biguint!(USER_BALANCE / 4 * 3), + }, + ]; + setup + .b_mock + .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &merge_payments, |sc| { + sc.merge_wrapped_farm_tokens_endpoint(managed_address!(&farm_addr)); + }) + .assert_ok(); + + // Check final total farm position + user_total_farm_position += USER_BALANCE / 2; + user_total_farm_position += USER_BALANCE / 4 * 3; + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = + sc.get_user_total_farm_position(&managed_address!(&first_user)); + assert_eq!( + first_user_total_farm_position.total_farm_position, + managed_biguint!(user_total_farm_position) + ); + }) + .assert_ok(); +} diff --git a/locked-asset/proxy_dex/tests/proxy_lp_test.rs b/locked-asset/proxy_dex/tests/proxy_lp_test.rs index 9c3710bb7..5d524ba3a 100644 --- a/locked-asset/proxy_dex/tests/proxy_lp_test.rs +++ b/locked-asset/proxy_dex/tests/proxy_lp_test.rs @@ -133,7 +133,8 @@ fn add_remove_liquidity_proxy_test() { block_epoch, managed_biguint!(user_balance), ); - let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); assert_eq!(expected_energy, actual_energy); }) .assert_ok(); @@ -190,7 +191,8 @@ fn add_remove_liquidity_proxy_test() { block_epoch, managed_biguint!(user_balance), ); - let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); assert_eq!(expected_energy, actual_energy); }) .assert_ok(); @@ -884,7 +886,8 @@ fn increase_proxy_lp_token_energy() { block_epoch, managed_biguint!(USER_BALANCE), ); - let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); assert_eq!(expected_energy, actual_energy); }) .assert_ok(); @@ -904,6 +907,17 @@ fn increase_proxy_lp_token_energy() { ) .assert_ok(); + // check old tokens were burned + setup + .b_mock + .check_nft_balance::>( + setup.proxy_wrapper.address_ref(), + WRAPPED_LP_TOKEN_ID, + 1, + &rust_biguint!(0u64), + None, + ); + // chceck new wrapped lp token setup.b_mock.check_nft_balance( &first_user, @@ -936,8 +950,455 @@ fn increase_proxy_lp_token_energy() { block_epoch, managed_biguint!(USER_BALANCE), ); - let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); +} + +#[test] +fn increase_proxy_lp_token_energy_unlocked_tokens() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + let first_user = setup.first_user.clone(); + let full_balance = rust_biguint!(USER_BALANCE); + let locked_token_amount = rust_biguint!(1_000_000_000); + let other_token_amount = rust_biguint!(500_000_000); + let expected_lp_token_amount = rust_biguint!(499_999_000); + + // set the price to 1 EGLD = 2 MEX + let payments = vec![ + TxTokenTransfer { + token_identifier: LOCKED_TOKEN_ID.to_vec(), + nonce: 1, + value: locked_token_amount.clone(), + }, + TxTokenTransfer { + token_identifier: WEGLD_TOKEN_ID.to_vec(), + nonce: 0, + value: other_token_amount.clone(), + }, + ]; + + // add liquidity + let pair_addr = setup.pair_wrapper.address_ref().clone(); + setup + .b_mock + .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &payments, |sc| { + sc.add_liquidity_proxy( + managed_address!(&pair_addr), + managed_biguint!(locked_token_amount.to_u64().unwrap()), + managed_biguint!(other_token_amount.to_u64().unwrap()), + ); + }) + .assert_ok(); + + // check user's balance + setup.b_mock.check_nft_balance::( + &first_user, + LOCKED_TOKEN_ID, + 1, + &(&full_balance - &locked_token_amount), + None, + ); + setup.b_mock.check_esdt_balance( + &first_user, + WEGLD_TOKEN_ID, + &(&full_balance - &other_token_amount), + ); + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_LP_TOKEN_ID, + 1, + &expected_lp_token_amount, + Some(&WrappedLpTokenAttributes:: { + locked_tokens: EsdtTokenPayment { + token_identifier: managed_token_id!(LOCKED_TOKEN_ID), + token_nonce: 1, + amount: managed_biguint!(locked_token_amount.to_u64().unwrap()), + }, + lp_token_id: managed_token_id!(LP_TOKEN_ID), + lp_token_amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap()), + }), + ); + + let mut block_epoch = 1; + let user_locked_tokens_in_lp = locked_token_amount.to_u64().unwrap(); + + // check user energy before + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let lock_epochs = LOCK_OPTIONS[0] - block_epoch; + let expected_energy_amount = + BigInt::from((USER_BALANCE) as i64) * BigInt::from(lock_epochs as i64); + let expected_energy = Energy::new( + expected_energy_amount, + block_epoch, + managed_biguint!(USER_BALANCE), + ); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); + + // Wait for tokens to unlock + block_epoch += LOCK_OPTIONS[0]; + + setup.b_mock.set_block_epoch(block_epoch); + + // call increase energy + setup + .b_mock + .execute_esdt_transfer( + &setup.first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 1, + &expected_lp_token_amount, + |sc| { + let _ = sc.increase_proxy_pair_token_energy_endpoint(LOCK_OPTIONS[1]); + }, + ) + .assert_ok(); + + // check new wrapped lp token + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_LP_TOKEN_ID, + 2, + &expected_lp_token_amount, + Some(&WrappedLpTokenAttributes:: { + locked_tokens: EsdtTokenPayment { + token_identifier: managed_token_id!(LOCKED_TOKEN_ID), + // Nonce increases + token_nonce: 3, + amount: managed_biguint!(locked_token_amount.to_u64().unwrap()), + }, + lp_token_id: managed_token_id!(LP_TOKEN_ID), + lp_token_amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap()), + }), + ); + + // check old tokens were burned + setup + .b_mock + .check_nft_balance::>( + setup.proxy_wrapper.address_ref(), + WRAPPED_LP_TOKEN_ID, + 1, + &rust_biguint!(0u64), + None, + ); + + // check user energy after + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let first_lock_epochs = LOCK_OPTIONS[1] - 1u64; + let second_lock_epochs = + BigInt::from(LOCK_OPTIONS[0] as i64) - BigInt::from(block_epoch as i64); + + let expected_energy_amount = BigInt::from((user_locked_tokens_in_lp) as i64) + * BigInt::from(first_lock_epochs as i64) + + BigInt::from((USER_BALANCE - user_locked_tokens_in_lp) as i64) + * second_lock_epochs; + let expected_energy = Energy::new( + expected_energy_amount, + block_epoch, + managed_biguint!(USER_BALANCE), + ); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); +} + +#[test] +fn increase_proxy_lp_token_energy_partially_unlocked_tokens() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + let first_user = setup.first_user.clone(); + let full_balance = rust_biguint!(USER_BALANCE); + let locked_token_amount = rust_biguint!(1_000_000_000); + let other_token_amount = rust_biguint!(500_000_000); + let expected_lp_token_amount = rust_biguint!(499_999_000); + + // set the price to 1 EGLD = 2 MEX + let payments = vec![ + TxTokenTransfer { + token_identifier: LOCKED_TOKEN_ID.to_vec(), + nonce: 1, + value: locked_token_amount.clone(), + }, + TxTokenTransfer { + token_identifier: WEGLD_TOKEN_ID.to_vec(), + nonce: 0, + value: other_token_amount.clone(), + }, + ]; + + // add liquidity + let pair_addr = setup.pair_wrapper.address_ref().clone(); + setup + .b_mock + .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &payments, |sc| { + sc.add_liquidity_proxy( + managed_address!(&pair_addr), + managed_biguint!(locked_token_amount.to_u64().unwrap()), + managed_biguint!(other_token_amount.to_u64().unwrap()), + ); + }) + .assert_ok(); + + // check user's balance + setup.b_mock.check_nft_balance::( + &first_user, + LOCKED_TOKEN_ID, + 1, + &(&full_balance - &locked_token_amount), + None, + ); + setup.b_mock.check_esdt_balance( + &first_user, + WEGLD_TOKEN_ID, + &(&full_balance - &other_token_amount), + ); + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_LP_TOKEN_ID, + 1, + &expected_lp_token_amount, + Some(&WrappedLpTokenAttributes:: { + locked_tokens: EsdtTokenPayment { + token_identifier: managed_token_id!(LOCKED_TOKEN_ID), + token_nonce: 1, + amount: managed_biguint!(locked_token_amount.to_u64().unwrap()), + }, + lp_token_id: managed_token_id!(LP_TOKEN_ID), + lp_token_amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap()), + }), + ); + + let block_epoch = 1; + let user_locked_tokens_in_lp = locked_token_amount.to_u64().unwrap(); + + // check user energy before + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let lock_epochs = LOCK_OPTIONS[0] - block_epoch; + let expected_energy_amount = + BigInt::from((USER_BALANCE) as i64) * BigInt::from(lock_epochs as i64); + let expected_energy = Energy::new( + expected_energy_amount, + block_epoch, + managed_biguint!(USER_BALANCE), + ); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); assert_eq!(expected_energy, actual_energy); }) .assert_ok(); + + // call increase energy + setup + .b_mock + .execute_esdt_transfer( + &setup.first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 1, + &(&expected_lp_token_amount / 2u64), + |sc| { + let _ = sc.increase_proxy_pair_token_energy_endpoint(LOCK_OPTIONS[1]); + }, + ) + .assert_ok(); + + // check old tokens were burned + setup + .b_mock + .check_nft_balance::>( + setup.proxy_wrapper.address_ref(), + WRAPPED_LP_TOKEN_ID, + 1, + &rust_biguint!(0u64), + None, + ); + + // check remaining old wrapped lp token + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_LP_TOKEN_ID, + 1, + &(&expected_lp_token_amount / 2u64), + Some(&WrappedLpTokenAttributes:: { + locked_tokens: EsdtTokenPayment { + token_identifier: managed_token_id!(LOCKED_TOKEN_ID), + // Nonce increases + token_nonce: 1, + amount: managed_biguint!(locked_token_amount.to_u64().unwrap()), + }, + lp_token_id: managed_token_id!(LP_TOKEN_ID), + lp_token_amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap()), + }), + ); + + // check new wrapped lp token + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_LP_TOKEN_ID, + 2, + &(&expected_lp_token_amount / 2u64), + Some(&WrappedLpTokenAttributes:: { + locked_tokens: EsdtTokenPayment { + token_identifier: managed_token_id!(LOCKED_TOKEN_ID), + token_nonce: 2, + amount: managed_biguint!(locked_token_amount.to_u64().unwrap() / 2u64), + }, + lp_token_id: managed_token_id!(LP_TOKEN_ID), + lp_token_amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap() / 2u64), + }), + ); + + // check user energy after + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let first_lock_epochs = LOCK_OPTIONS[1] - 1u64; + let second_lock_epochs = + BigInt::from(LOCK_OPTIONS[0] as i64) - BigInt::from(block_epoch as i64); + + let expected_energy_amount = BigInt::from((user_locked_tokens_in_lp / 2u64) as i64) + * BigInt::from(first_lock_epochs as i64) + + BigInt::from((USER_BALANCE) as i64) * second_lock_epochs.clone() + - BigInt::from((user_locked_tokens_in_lp / 2u64) as i64) * second_lock_epochs; + let expected_energy = Energy::new( + expected_energy_amount, + block_epoch, + managed_biguint!(USER_BALANCE), + ); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); +} + +#[test] +fn increase_proxy_lp_legacy_token_energy() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + let first_user = setup.first_user.clone(); + let full_balance = rust_biguint!(USER_BALANCE); + let locked_token_amount = rust_biguint!(1_000_000_000); + let other_token_amount = rust_biguint!(500_000_000); + let expected_lp_token_amount = rust_biguint!(499_999_000); + + // set the price to 1 EGLD = 2 MEX + let payments = vec![ + TxTokenTransfer { + token_identifier: LEGACY_LOCKED_TOKEN_ID.to_vec(), + nonce: 3, + value: locked_token_amount.clone(), + }, + TxTokenTransfer { + token_identifier: WEGLD_TOKEN_ID.to_vec(), + nonce: 0, + value: other_token_amount.clone(), + }, + ]; + + // add liquidity + let pair_addr = setup.pair_wrapper.address_ref().clone(); + setup + .b_mock + .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &payments, |sc| { + sc.add_liquidity_proxy( + managed_address!(&pair_addr), + managed_biguint!(locked_token_amount.to_u64().unwrap()), + managed_biguint!(other_token_amount.to_u64().unwrap()), + ); + }) + .assert_ok(); + + // check user's balance + setup.b_mock.check_nft_balance::( + &first_user, + LEGACY_LOCKED_TOKEN_ID, + 3, + &(&full_balance - &locked_token_amount), + None, + ); + setup.b_mock.check_esdt_balance( + &first_user, + WEGLD_TOKEN_ID, + &(&full_balance - &other_token_amount), + ); + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_LP_TOKEN_ID, + 1, + &expected_lp_token_amount, + Some(&WrappedLpTokenAttributes:: { + locked_tokens: EsdtTokenPayment { + token_identifier: managed_token_id!(LEGACY_LOCKED_TOKEN_ID), + token_nonce: 3, + amount: managed_biguint!(locked_token_amount.to_u64().unwrap()), + }, + lp_token_id: managed_token_id!(LP_TOKEN_ID), + lp_token_amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap()), + }), + ); + + let block_epoch = 1; + + // check user energy before + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let lock_epochs = LOCK_OPTIONS[0] - block_epoch; + let expected_energy_amount = + BigInt::from((USER_BALANCE) as i64) * BigInt::from(lock_epochs as i64); + let expected_energy = Energy::new( + expected_energy_amount, + block_epoch, + managed_biguint!(USER_BALANCE), + ); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); + + // call increase energy + setup + .b_mock + .execute_esdt_transfer( + &setup.first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 1, + &expected_lp_token_amount, + |sc| { + let _ = sc.increase_proxy_pair_token_energy_endpoint(LOCK_OPTIONS[1]); + }, + ) + .assert_error(4, "Invalid payment"); } diff --git a/locked-asset/proxy_dex/wasm/Cargo.lock b/locked-asset/proxy_dex/wasm/Cargo.lock index 7cc65eaa5..d601aa1f1 100644 --- a/locked-asset/proxy_dex/wasm/Cargo.lock +++ b/locked-asset/proxy_dex/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common-types" @@ -307,9 +307,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -320,9 +320,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -330,9 +330,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -342,9 +342,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -355,18 +355,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -424,9 +424,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/locked-asset/proxy_dex/wasm/Cargo.toml b/locked-asset/proxy_dex/wasm/Cargo.toml index b0753d94f..6101d9e7a 100644 --- a/locked-asset/proxy_dex/wasm/Cargo.toml +++ b/locked-asset/proxy_dex/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/locked-asset/simple-lock-whitelist/Cargo.toml b/locked-asset/simple-lock-whitelist/Cargo.toml index a8d637a5c..e49600a9a 100644 --- a/locked-asset/simple-lock-whitelist/Cargo.toml +++ b/locked-asset/simple-lock-whitelist/Cargo.toml @@ -15,11 +15,11 @@ path = "../simple-lock" path = "../../common/modules/utils" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" [dev-dependencies] num-bigint = "0.4.2" @@ -27,4 +27,4 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" diff --git a/locked-asset/simple-lock-whitelist/meta/Cargo.toml b/locked-asset/simple-lock-whitelist/meta/Cargo.toml index 8b95c8a50..e5efe2245 100644 --- a/locked-asset/simple-lock-whitelist/meta/Cargo.toml +++ b/locked-asset/simple-lock-whitelist/meta/Cargo.toml @@ -9,5 +9,5 @@ authors = ["Dorin Iancu "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/locked-asset/simple-lock-whitelist/src/lib.rs b/locked-asset/simple-lock-whitelist/src/lib.rs index 577671ede..7ed5b52ac 100644 --- a/locked-asset/simple-lock-whitelist/src/lib.rs +++ b/locked-asset/simple-lock-whitelist/src/lib.rs @@ -30,7 +30,7 @@ pub trait SimpleLockWhitelist: self.transfer_roles_not_set().set(true); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} /// Sets the transfer role for the given address. Defaults to own address. diff --git a/locked-asset/simple-lock-whitelist/wasm/Cargo.lock b/locked-asset/simple-lock-whitelist/wasm/Cargo.lock index e6300116a..34b1df932 100644 --- a/locked-asset/simple-lock-whitelist/wasm/Cargo.lock +++ b/locked-asset/simple-lock-whitelist/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common_structs" @@ -72,9 +72,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -85,9 +85,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -95,9 +95,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -107,9 +107,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -120,18 +120,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -156,9 +156,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/locked-asset/simple-lock-whitelist/wasm/Cargo.toml b/locked-asset/simple-lock-whitelist/wasm/Cargo.toml index 068857df3..57d2e8645 100644 --- a/locked-asset/simple-lock-whitelist/wasm/Cargo.toml +++ b/locked-asset/simple-lock-whitelist/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/locked-asset/simple-lock-whitelist/wasm/src/lib.rs b/locked-asset/simple-lock-whitelist/wasm/src/lib.rs index 6b3f02559..aa78142e1 100644 --- a/locked-asset/simple-lock-whitelist/wasm/src/lib.rs +++ b/locked-asset/simple-lock-whitelist/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 27 +// Endpoints: 26 // Async Callback: 1 -// Total number of exported functions: 29 +// Total number of exported functions: 28 #![no_std] #![allow(internal_features)] diff --git a/locked-asset/simple-lock/Cargo.toml b/locked-asset/simple-lock/Cargo.toml index 8f6b5bd1d..08a745214 100644 --- a/locked-asset/simple-lock/Cargo.toml +++ b/locked-asset/simple-lock/Cargo.toml @@ -9,11 +9,11 @@ publish = false path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" [dependencies.common_structs] path = "../../common/common_structs" @@ -24,4 +24,4 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" diff --git a/locked-asset/simple-lock/meta/Cargo.toml b/locked-asset/simple-lock/meta/Cargo.toml index 889dce931..ade748c64 100644 --- a/locked-asset/simple-lock/meta/Cargo.toml +++ b/locked-asset/simple-lock/meta/Cargo.toml @@ -9,5 +9,5 @@ authors = ["Dorin Iancu "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/locked-asset/simple-lock/src/lib.rs b/locked-asset/simple-lock/src/lib.rs index 5db24f38e..fb59b792c 100644 --- a/locked-asset/simple-lock/src/lib.rs +++ b/locked-asset/simple-lock/src/lib.rs @@ -25,7 +25,7 @@ pub trait SimpleLock: #[init] fn init(&self) {} - #[endpoint] + #[upgrade] fn upgrade(&self) {} /// Locks any token (including EGLD) until `unlock_epoch` and receive meta ESDT LOCKED tokens. diff --git a/locked-asset/simple-lock/wasm/Cargo.lock b/locked-asset/simple-lock/wasm/Cargo.lock index e5957696c..102bb0d32 100644 --- a/locked-asset/simple-lock/wasm/Cargo.lock +++ b/locked-asset/simple-lock/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common_structs" @@ -72,9 +72,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -85,9 +85,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -95,9 +95,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -107,9 +107,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -120,18 +120,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -156,9 +156,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/locked-asset/simple-lock/wasm/Cargo.toml b/locked-asset/simple-lock/wasm/Cargo.toml index cc2cf0244..c52eb04df 100644 --- a/locked-asset/simple-lock/wasm/Cargo.toml +++ b/locked-asset/simple-lock/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/locked-asset/token-unstake/Cargo.toml b/locked-asset/token-unstake/Cargo.toml index da727566e..9f05894e6 100644 --- a/locked-asset/token-unstake/Cargo.toml +++ b/locked-asset/token-unstake/Cargo.toml @@ -9,7 +9,7 @@ publish = false path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.mergeable] @@ -39,7 +39,7 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" [dev-dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" diff --git a/locked-asset/token-unstake/meta/Cargo.toml b/locked-asset/token-unstake/meta/Cargo.toml index fb4914c3d..035037168 100644 --- a/locked-asset/token-unstake/meta/Cargo.toml +++ b/locked-asset/token-unstake/meta/Cargo.toml @@ -9,5 +9,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/locked-asset/token-unstake/src/lib.rs b/locked-asset/token-unstake/src/lib.rs index 6295d46a2..985e91be9 100644 --- a/locked-asset/token-unstake/src/lib.rs +++ b/locked-asset/token-unstake/src/lib.rs @@ -42,6 +42,6 @@ pub trait TokenUnstakeModule: self.fees_burn_percentage().set(fees_burn_percentage); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} } diff --git a/locked-asset/token-unstake/wasm/Cargo.lock b/locked-asset/token-unstake/wasm/Cargo.lock index d74f133fa..415f82989 100644 --- a/locked-asset/token-unstake/wasm/Cargo.lock +++ b/locked-asset/token-unstake/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common-types" @@ -119,9 +119,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -132,9 +132,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -142,9 +142,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -154,9 +154,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -167,18 +167,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -203,9 +203,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/locked-asset/token-unstake/wasm/Cargo.toml b/locked-asset/token-unstake/wasm/Cargo.toml index f3e21bb9b..f7753f8de 100644 --- a/locked-asset/token-unstake/wasm/Cargo.toml +++ b/locked-asset/token-unstake/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."] diff --git a/pause-all/Cargo.toml b/pause-all/Cargo.toml index 30046978d..becbee8e1 100644 --- a/pause-all/Cargo.toml +++ b/pause-all/Cargo.toml @@ -12,14 +12,14 @@ path = "src/lib.rs" path = "../common/modules/pausable" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.48.0" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.48.0" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.48.0" [dev-dependencies.farm] path = "../dex/farm" diff --git a/pause-all/meta/Cargo.toml b/pause-all/meta/Cargo.toml index f6be6643e..cec738238 100644 --- a/pause-all/meta/Cargo.toml +++ b/pause-all/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.48.0" default-features = false diff --git a/pause-all/src/lib.rs b/pause-all/src/lib.rs index 6e9bcd823..05f7fe541 100644 --- a/pause-all/src/lib.rs +++ b/pause-all/src/lib.rs @@ -28,7 +28,7 @@ pub trait PauseAll: #[init] fn init(&self) {} - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[only_owner] diff --git a/pause-all/wasm/Cargo.lock b/pause-all/wasm/Cargo.lock index d1b8021d6..0972422cf 100644 --- a/pause-all/wasm/Cargo.lock +++ b/pause-all/wasm/Cargo.lock @@ -16,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "common_errors" @@ -47,9 +47,9 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "ba1291e3712731f4e34775254e9a9b8ff70132d15414f2e51f9bc82c23faf48c" dependencies = [ "bitflags", "hex-literal", @@ -60,9 +60,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "1da6db65170105c9495848c5e4ba388abb1f9201ff2ca362056c9328f36b7760" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -70,9 +70,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.18.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "631c4d4b37fc94659c8d6cf559c21b68c68899095201de2e1b779fccad7b0b03" dependencies = [ "hex", "proc-macro2", @@ -82,9 +82,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "95f0331893be2b757401b2deaf7d8b8c90745fa69114000d83fe26d8487d35a5" dependencies = [ "hex", "proc-macro2", @@ -95,18 +95,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "4e507a180afcab409cc3d920bc12f3852cf481a6657428879d1a70f6c2666c94" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "f6bd18dbc72c83aa2e9ad3f4a00dcc27c03ada66c13f9056001dc9157055d616" dependencies = [ "multiversx-sc", ] @@ -165,9 +165,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] diff --git a/pause-all/wasm/Cargo.toml b/pause-all/wasm/Cargo.toml index ccffee39c..3fcca5422 100644 --- a/pause-all/wasm/Cargo.toml +++ b/pause-all/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.48.0" [workspace] members = ["."]