diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 756046163..afa63aa92 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -2,9 +2,9 @@ name: CI on: push: - branches: [ main, feat/* ] + branches: [ main, feat/*, rc/* ] pull_request: - branches: [ main, feat/* ] + branches: [ main, feat/*, rc/* ] workflow_dispatch: permissions: @@ -20,9 +20,61 @@ permissions: jobs: contracts: name: Contracts - uses: multiversx/mx-sc-actions/.github/workflows/contracts.yml@v2 + uses: multiversx/mx-sc-actions/.github/workflows/contracts.yml@v2.3.5 with: - rust-toolchain: nightly-2022-12-08 - vmtools-version: v1.4.60 + rust-toolchain: nightly-2023-12-11 + vmtools-version: v1.5.24 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/.github/workflows/release.yml b/.github/workflows/release.yml index 261ffd637..a19b5ed98 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,7 +9,7 @@ permissions: jobs: build: - uses: multiversx/mx-sc-actions/.github/workflows/reproducible-build.yml@v2.3.1 + uses: multiversx/mx-sc-actions/.github/workflows/reproducible-build.yml@v2.3.5 with: - image_tag: v4.2.0 + image_tag: v6.0.0 attach_to_existing_release: true diff --git a/Cargo.lock b/Cargo.lock index 5a2898f4e..fe863b981 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,17 +13,20 @@ dependencies = [ ] [[package]] -name = "ahash" -version = "0.8.6" +name = "addr2line" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", - "zerocopy", + "gimli", ] +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "aho-corasick" version = "1.1.2" @@ -35,58 +38,57 @@ dependencies = [ [[package]] name = "anstream" -version = "0.3.2" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", - "is-terminal", "utf8parse", ] [[package]] name = "anstyle" -version = "1.0.1" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" [[package]] name = "anstyle-parse" -version = "0.2.1" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "1.0.2" +version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c677ab05e09154296dd37acecd46420c17b9713e8366facafa8fc0885167cf4c" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" dependencies = [ "anstyle", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "anyhow" -version = "1.0.77" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9d19de80eff169429ac1e9f48fffb163916b448a44e8e046186232046d9e1f9" +checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" [[package]] name = "arrayvec" @@ -95,21 +97,37 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] -name = "atty" -version = "0.2.14" +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "backtrace" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" dependencies = [ - "hermit-abi 0.1.19", + "addr2line", + "cc", + "cfg-if 1.0.0", "libc", - "winapi", + "miniz_oxide", + "object", + "rustc-demangle", ] [[package]] -name = "autocfg" -version = "1.1.0" +name = "base64" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "bech32" @@ -118,26 +136,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" [[package]] -name = "bitflags" -version = "1.3.2" +name = "bip39" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "93f2635620bf0b9d4576eb7bb9a38a55df78bd1205d26fa994b25911a69f212f" +dependencies = [ + "bitcoin_hashes", + "rand", + "rand_core", + "serde", + "unicode-normalization", +] + +[[package]] +name = "bitcoin_hashes" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90064b8dee6815a6470d60bad07bbbaee885c0e12d04177138fa3291a01b7bc4" [[package]] name = "bitflags" -version = "2.4.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] -name = "block-buffer" -version = "0.9.0" +name = "bitflags" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "block-padding", - "generic-array", -] +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "block-buffer" @@ -148,28 +175,43 @@ dependencies = [ "generic-array", ] -[[package]] -name = "block-padding" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" - [[package]] name = "bstr" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "542f33a8835a0884b006a0c3df3dadd99c0c3f296ed26c2fdc8028e01ad6230c" +checksum = "c48f0051a4b4c5e0b6d365cd04af53aeaa209e3cc15ec2cdb69e73cc87fbd0dc" dependencies = [ "memchr", "serde", ] +[[package]] +name = "bumpalo" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" + [[package]] name = "byteorder" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "bytes" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" + +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] + [[package]] name = "cfg-if" version = "0.1.10" @@ -184,45 +226,43 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.3.11" +version = "4.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1640e5cc7fb47dbb8338fd471b105e7ed6c3cb2aeb00c2e067127ffd3764a05d" +checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c" dependencies = [ "clap_builder", "clap_derive", - "once_cell", ] [[package]] name = "clap_builder" -version = "4.3.11" +version = "4.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98c59138d527eeaf9b53f35a77fcc1fad9d883116070c63d5de1c7dc7b00c72b" +checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7" dependencies = [ "anstream", "anstyle", "clap_lex", - "once_cell", "strsim", ] [[package]] name = "clap_derive" -version = "4.3.2" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8cd2b2a819ad6eec39e8f1d6b53001af1e5469f8c177579cdaeb313115b825f" +checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.43", + "syn", ] [[package]] name = "clap_lex" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" [[package]] name = "colorchoice" @@ -232,15 +272,20 @@ checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] name = "colored" -version = "2.0.4" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2674ec482fbc38012cf31e6c42ba0177b431a0cb6f15fe40efa5aab1bda516f6" +checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" dependencies = [ - "is-terminal", "lazy_static", "windows-sys 0.48.0", ] +[[package]] +name = "common-path" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2382f75942f4b3be3690fe4f86365e9c853c1587d6ee58212cebf6e2a9ccd101" + [[package]] name = "common-types" version = "0.0.0" @@ -278,6 +323,12 @@ 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" @@ -295,15 +346,83 @@ dependencies = [ "token_send", ] +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "copy_dir" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "543d1dd138ef086e2ff05e3a48cf9da045da2033d16f8538fd76b86cd49b2ca3" +dependencies = [ + "walkdir", +] + +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + [[package]] name = "cpufeatures" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ "libc", ] +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" + [[package]] name = "crypto-common" version = "0.1.6" @@ -316,17 +435,42 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "3.2.1" +version = "4.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90f9d052967f590a76e62eb387bd0bbb1b000182c3cefe5364db6b7211651bc0" +checksum = "e89b8c6a2e4b1f45971ad09761aafb85514a84744b67a95e32c3cc1352d1f65c" dependencies = [ - "byteorder", - "digest 0.9.0", - "rand_core 0.5.1", + "cfg-if 1.0.0", + "cpufeatures", + "curve25519-dalek-derive", + "digest", + "fiat-crypto", + "platforms", + "rustc_version", "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" @@ -353,23 +497,15 @@ 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 0.10.4", + "block-buffer", "crypto-common", + "subtle", ] [[package]] @@ -416,24 +552,25 @@ dependencies = [ [[package]] name = "ed25519" -version = "1.5.3" +version = "2.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" dependencies = [ + "pkcs8", "signature", ] [[package]] name = "ed25519-dalek" -version = "1.0.1" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" +checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" dependencies = [ "curve25519-dalek", "ed25519", - "rand 0.7.3", "serde", - "sha2 0.9.9", + "sha2", + "subtle", "zeroize", ] @@ -443,6 +580,15 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +[[package]] +name = "encoding_rs" +version = "0.8.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "endian-type" version = "0.1.2" @@ -522,6 +668,12 @@ dependencies = [ "multiversx-sc-meta", ] +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "errno" version = "0.3.8" @@ -550,7 +702,7 @@ dependencies = [ "common_structs", "energy-factory", "hex", - "itertools", + "itertools 0.10.5", "multiversx-sc", "multiversx-sc-modules", "multiversx-sc-scenario", @@ -672,12 +824,16 @@ version = "0.0.0" dependencies = [ "common_structs", "config", + "energy-factory", + "energy-query", "farm", "farm-boosted-yields", "farm-staking", + "farm-with-locked-rewards", "farm_token", "fixed-supply-token", - "hex-literal", + "hex-literal 0.3.4", + "locking_module", "mergeable", "multiversx-sc", "multiversx-sc-modules", @@ -687,6 +843,7 @@ dependencies = [ "pausable", "rewards", "sc_whitelist_module", + "simple-lock", "token_send", "unwrappable", "utils", @@ -778,6 +935,12 @@ dependencies = [ "token_send", ] +[[package]] +name = "fastrand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" + [[package]] name = "fees-collector" version = "0.0.0" @@ -806,6 +969,12 @@ dependencies = [ "multiversx-sc-meta", ] +[[package]] +name = "fiat-crypto" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1676f435fc1dadde4d03e43f5d62b259e1ce5f40bd4ffb21db2b42ebe59c1382" + [[package]] name = "fixed-supply-token" version = "0.0.0" @@ -813,6 +982,94 @@ dependencies = [ "multiversx-sc", ] +[[package]] +name = "flate2" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-core", + "futures-io", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + [[package]] name = "fuzz" version = "0.0.0" @@ -830,7 +1087,7 @@ dependencies = [ "pair-mock", "pausable", "price-discovery", - "rand 0.8.5", + "rand", "rewards", "router", "simple-lock", @@ -848,25 +1105,20 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.1.16" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if 1.0.0", "libc", - "wasi 0.9.0+wasi-snapshot-preview1", + "wasi", ] [[package]] -name = "getrandom" -version = "0.2.11" +name = "gimli" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi 0.11.0+wasi-snapshot-preview1", -] +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] name = "globset" @@ -903,9 +1155,14 @@ dependencies = [ name = "governance-v2" version = "0.0.0" dependencies = [ + "energy-factory-mock", + "energy-query", + "fees-collector", "multiversx-sc", "multiversx-sc-scenario", "num-bigint", + "permissions_module", + "weekly-rewards-splitting", ] [[package]] @@ -917,19 +1174,29 @@ dependencies = [ ] [[package]] -name = "hashbrown" -version = "0.12.3" +name = "h2" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +checksum = "bb2c4422095b67ee78da96fbb51a4cc413b3b25883c7717ff7ca1ab31022c9c9" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] [[package]] name = "hashbrown" -version = "0.13.2" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" [[package]] name = "heck" @@ -939,18 +1206,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - -[[package]] -name = "hermit-abi" -version = "0.3.3" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +checksum = "d0c62115964e08cb8039170eb33c1d0e2388a256930279edca206fff675f82c3" [[package]] name = "hex" @@ -965,43 +1223,133 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" [[package]] -name = "ignore" -version = "0.4.20" +name = "hex-literal" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492" -dependencies = [ - "globset", - "lazy_static", - "log", - "memchr", - "regex", - "same-file", - "thread_local", - "walkdir", - "winapi-util", -] +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] -name = "indexmap" -version = "1.9.3" +name = "hmac" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "autocfg", - "hashbrown 0.12.3", + "digest", ] [[package]] -name = "is-terminal" -version = "0.4.9" +name = "http" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" dependencies = [ - "hermit-abi 0.3.3", - "rustix", - "windows-sys 0.48.0", + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "0.14.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "ignore" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b46810df39e66e925525d6e38ce1e7f6e1d208f72dc39757880fcb66e2c58af1" +dependencies = [ + "crossbeam-deque", + "globset", + "log", + "memchr", + "regex-automata", + "same-file", + "walkdir", + "winapi-util", ] +[[package]] +name = "indexmap" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "ipnet" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" + [[package]] name = "itertools" version = "0.10.5" @@ -1011,17 +1359,35 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +[[package]] +name = "js-sys" +version = "0.3.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "keccak" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" dependencies = [ "cpufeatures", ] @@ -1043,15 +1409,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.151" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "linux-raw-sys" -version = "0.4.12" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "lkmex-transfer" @@ -1078,6 +1444,16 @@ dependencies = [ "multiversx-sc-meta", ] +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "locked-token-wrapper" version = "0.0.0" @@ -1130,9 +1506,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.6.4" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "memory_units" @@ -1167,11 +1543,37 @@ dependencies = [ "multiversx-sc-meta", ] +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + [[package]] name = "multiversx-chain-scenario-format" -version = "0.19.1" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d2592a441608937c5aebec6732c38e6097f58de1dc9a64d7dbe98e0ab97a3c0" +checksum = "2dfc2b1dc76af14c24145672c2779474046ab44ef56bac82a58844328f4b4d2e" dependencies = [ "bech32", "hex", @@ -1179,41 +1581,43 @@ dependencies = [ "num-traits", "serde", "serde_json", - "sha3 0.9.1", + "sha3", ] [[package]] name = "multiversx-chain-vm" -version = "0.1.4" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccfe504d59cbdce3136fd1e8549ff174c204cd600e2c0ca3482fb172c211c921" +checksum = "75459864359798406a45a7bb2ed221d623b2e39484ec3e4ac6d23167bfc50b33" dependencies = [ - "bech32", + "bitflags 2.4.2", "ed25519-dalek", "hex", - "itertools", - "multiversx-chain-scenario-format", - "multiversx-sc", - "multiversx-sc-meta", + "hex-literal 0.4.1", + "itertools 0.12.1", + "multiversx-chain-vm-executor", "num-bigint", "num-traits", - "rand 0.8.5", + "rand", "rand_seeder", - "serde", - "serde_json", - "sha2 0.10.8", - "sha3 0.10.8", + "sha2", + "sha3", ] +[[package]] +name = "multiversx-chain-vm-executor" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b59072fa0624b55ae5ae3fa6bfa91515bbeb4ac440214bc4a509e2c8806d6e9f" + [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ - "bitflags 1.3.2", - "hashbrown 0.13.2", - "hex-literal", + "bitflags 2.4.2", + "hex-literal 0.4.1", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", @@ -1221,81 +1625,145 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", "num-bigint", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", "quote", "radix_trie", - "syn 1.0.109", + "syn", ] [[package]] name = "multiversx-sc-meta" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40a73abbabf2408616624b421f8ac2a6dda10beaa076dc4bdb0ce2e1b635a367" +checksum = "2c8250fd72b78dff76fd3789078aee3dec2524ca37250c645dcb2b1bf067551e" dependencies = [ "clap", "colored", + "common-path", + "convert_case", + "copy_dir", + "hex", + "lazy_static", "multiversx-sc", + "pathdiff", + "reqwest", "ruplacer", "rustc_version", "serde", "serde_json", "toml", + "wasmparser 0.118.1", + "wasmprinter", + "zip", ] [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-scenario" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b9e4d968f161ce956a2d4a235631c3b1df89d3ea75445f6dc654c2bab3a0caf" +checksum = "3aa2644018c85caf3cc39a130961e39bd719ff3d75751b60a7394d6eace1c847" dependencies = [ + "base64", + "bech32", + "clap", "colored", "hex", - "itertools", + "itertools 0.12.1", + "log", + "multiversx-chain-scenario-format", "multiversx-chain-vm", + "multiversx-chain-vm-executor", + "multiversx-sc", + "multiversx-sc-meta", + "multiversx-sdk", + "num-bigint", "num-traits", "pathdiff", "serde", "serde_json", - "sha2 0.10.8", + "sha2", + "tokio", +] + +[[package]] +name = "multiversx-sdk" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f86d0da66ca2eb334414786a287010bb669b8d815a7d3b690d629a04b86bb80" +dependencies = [ + "anyhow", + "base64", + "bech32", + "bip39", + "hex", + "hmac", + "itertools 0.12.1", + "pbkdf2", + "pem", + "rand", + "reqwest", + "serde", + "serde_json", + "serde_repr", + "sha2", + "sha3", + "tokio", + "zeroize", +] + +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", ] [[package]] @@ -1337,6 +1805,25 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.19.0" @@ -1344,10 +1831,48 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] -name = "opaque-debug" -version = "0.3.0" +name = "openssl" +version = "0.10.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15c9d69dd87a29568d4d017cfe8ec518706046a05184e5aea92d0af890b803c8" +dependencies = [ + "bitflags 2.4.2", + "cfg-if 1.0.0", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22e1bf214306098e4832460f797824c05d25aacdf896f64a985fb0fd992454ae" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] [[package]] name = "pair" @@ -1356,7 +1881,7 @@ dependencies = [ "common_errors", "common_structs", "fees-collector", - "itertools", + "itertools 0.10.5", "multiversx-sc", "multiversx-sc-scenario", "num-bigint", @@ -1364,6 +1889,7 @@ dependencies = [ "permissions_module", "simple-lock", "token_send", + "utils", ] [[package]] @@ -1379,7 +1905,7 @@ name = "pair-mock" version = "0.0.0" dependencies = [ "common_errors", - "itertools", + "itertools 0.10.5", "multiversx-sc", "multiversx-sc-scenario", ] @@ -1392,6 +1918,29 @@ dependencies = [ "pair-mock", ] +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.48.5", +] + [[package]] name = "pathdiff" version = "0.2.1" @@ -1426,15 +1975,74 @@ dependencies = [ "pause-all", ] +[[package]] +name = "pbkdf2" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" +dependencies = [ + "digest", +] + +[[package]] +name = "pem" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b8fcc794035347fb64beda2d3b462595dd2753e3f268d89c5aae77e8cf2c310" +dependencies = [ + "base64", + "serde", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + [[package]] name = "permissions_module" version = "0.0.0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.2", "common_errors", "multiversx-sc", ] +[[package]] +name = "pin-project-lite" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" + +[[package]] +name = "pin-utils" +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" @@ -1446,7 +2054,7 @@ name = "price-discovery" version = "0.0.0" dependencies = [ "hex", - "hex-literal", + "hex-literal 0.3.4", "locking_module", "multiversx-sc", "multiversx-sc-modules", @@ -1466,9 +2074,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.71" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75cb1540fadbd5b8fbccc4dddad2734eba435053f725621c070711a14bb5f4b8" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] @@ -1509,7 +2117,7 @@ dependencies = [ "farm_token", "fixed-supply-token", "hex", - "itertools", + "itertools 0.10.5", "legacy_token_decode_module", "locking_module", "mergeable", @@ -1538,9 +2146,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -1555,19 +2163,6 @@ 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" @@ -1575,18 +2170,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "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", + "rand_chacha", + "rand_core", ] [[package]] @@ -1596,16 +2181,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "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", + "rand_core", ] [[package]] @@ -1614,32 +2190,32 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.11", + "getrandom", ] [[package]] -name = "rand_hc" -version = "0.2.0" +name = "rand_seeder" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +checksum = "cf2890aaef0aa82719a50e808de264f9484b74b442e1a3a0e5ee38243ac40bdb" dependencies = [ - "rand_core 0.5.1", + "rand_core", ] [[package]] -name = "rand_seeder" -version = "0.2.3" +name = "redox_syscall" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf2890aaef0aa82719a50e808de264f9484b74b442e1a3a0e5ee38243ac40bdb" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ - "rand_core 0.6.4", + "bitflags 1.3.2", ] [[package]] name = "regex" -version = "1.10.2" +version = "1.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" dependencies = [ "aho-corasick", "memchr", @@ -1649,9 +2225,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.3" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" dependencies = [ "aho-corasick", "memchr", @@ -1665,14 +2241,54 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] -name = "rewards" -version = "0.0.0" +name = "reqwest" +version = "0.11.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6920094eb85afde5e4a138be3f2de8bbdf28000f0029e72c45025a56b042251" dependencies = [ - "common_errors", - "common_structs", - "config", - "farm_token", - "multiversx-sc", + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + +[[package]] +name = "rewards" +version = "0.0.0" +dependencies = [ + "common_errors", + "common_structs", + "config", + "farm_token", + "multiversx-sc", "multiversx-sc-modules", "pausable", "permissions_module", @@ -1702,19 +2318,24 @@ dependencies = [ [[package]] name = "ruplacer" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1001b63b19333d7a462006c7d281a43ce5c1b3c44cd2a9696ab54b8e9aa7e388" +checksum = "58a26a1b15ff113d31d139357f7422708312978ed69cd5dd47e36d1b80b7eaf3" dependencies = [ "Inflector", "anyhow", - "atty", "clap", "colored", "ignore", "regex", ] +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + [[package]] name = "rustc_version" version = "0.4.0" @@ -1726,17 +2347,26 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.28" +version = "0.38.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316" +checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" dependencies = [ - "bitflags 2.4.1", + "bitflags 2.4.2", "errno", "libc", "linux-raw-sys", "windows-sys 0.52.0", ] +[[package]] +name = "rustls-pemfile" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +dependencies = [ + "base64", +] + [[package]] name = "ryu" version = "1.0.16" @@ -1760,54 +2390,112 @@ dependencies = [ "multiversx-sc", ] +[[package]] +name = "schannel" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "security-framework" +version = "2.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "semver" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" [[package]] name = "serde" -version = "1.0.193" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn", ] [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.113" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79" dependencies = [ + "indexmap", "itoa", "ryu", "serde", ] [[package]] -name = "sha2" -version = "0.9.9" +name = "serde_repr" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb" dependencies = [ - "block-buffer 0.9.0", - "cfg-if 1.0.0", - "cpufeatures", - "digest 0.9.0", - "opaque-debug", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_spanned" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", ] [[package]] @@ -1818,36 +2506,36 @@ checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if 1.0.0", "cpufeatures", - "digest 0.10.7", + "digest", ] [[package]] name = "sha3" -version = "0.9.1" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" dependencies = [ - "block-buffer 0.9.0", - "digest 0.9.0", + "digest", "keccak", - "opaque-debug", ] [[package]] -name = "sha3" -version = "0.10.8" +name = "signal-hook-registry" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" dependencies = [ - "digest 0.10.7", - "keccak", + "libc", ] [[package]] name = "signature" -version = "1.6.4" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "rand_core", +] [[package]] name = "simple-lock" @@ -1892,11 +2580,40 @@ dependencies = [ "simple-lock-whitelist", ] +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" + +[[package]] +name = "socket2" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +dependencies = [ + "libc", + "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" @@ -1912,9 +2629,9 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "syn" -version = "1.0.109" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -1922,26 +2639,59 @@ dependencies = [ ] [[package]] -name = "syn" -version = "2.0.43" +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + +[[package]] +name = "system-configuration" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee659fb5f3d355364e1f3e5bc10fb82068efbf824a1e9d1c9504244a6469ad53" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", ] [[package]] -name = "thread_local" -version = "1.1.7" +name = "tempfile" +version = "3.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +checksum = "a365e8cd18e44762ef95d87f284f4b5cd04107fec2ff3052bd6a3e6069669e67" dependencies = [ "cfg-if 1.0.0", - "once_cell", + "fastrand", + "rustix", + "windows-sys 0.52.0", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", ] +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "token-unstake" version = "0.0.0" @@ -1986,28 +2736,159 @@ dependencies = [ "multiversx-sc", ] +[[package]] +name = "tokio" +version = "1.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + [[package]] name = "toml" -version = "0.5.11" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +checksum = "9a9aad4a3066010876e8dcf5a8a06e70a558751117a145c6ce2b82c2e2054290" dependencies = [ "indexmap", "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", ] +[[package]] +name = "toml_datetime" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c9ffdf896f8daaabf9b66ba8e77ea1ed5ed0f72821b398aba62352e95062951" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + [[package]] name = "typenum" version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + [[package]] name = "unwrappable" version = "0.0.0" @@ -2015,6 +2896,17 @@ dependencies = [ "multiversx-sc", ] +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + [[package]] name = "utf8parse" version = "0.2.1" @@ -2031,6 +2923,12 @@ dependencies = [ "multiversx-sc", ] +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.4" @@ -2048,10 +2946,13 @@ dependencies = [ ] [[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" +name = "want" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] [[package]] name = "wasi" @@ -2059,6 +2960,113 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877b9c3f61ceea0e56331985743b13f3d25c406a7098d45180fb5f09bc19ed97" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" + +[[package]] +name = "wasmparser" +version = "0.118.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95ee9723b928e735d53000dec9eae7b07a60e490c85ab54abb66659fc61bfcd9" +dependencies = [ + "indexmap", + "semver", +] + +[[package]] +name = "wasmparser" +version = "0.121.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953cf6a7606ab31382cb1caa5ae403e77ba70c7f8e12eeda167e7040d42bfda8" +dependencies = [ + "bitflags 2.4.2", + "indexmap", + "semver", +] + +[[package]] +name = "wasmprinter" +version = "0.2.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05e32c13c59fdc64d3f6998a1d52eb1d362b6904a88b754190ccb85661ad577a" +dependencies = [ + "anyhow", + "wasmparser 0.121.0", +] + +[[package]] +name = "web-sys" +version = "0.3.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96565907687f7aceb35bc5fc03770a8a0471d82e479f25832f54a0e3f4b28446" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "wee_alloc" version = "0.4.5" @@ -2255,41 +3263,38 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] -name = "zerocopy" -version = "0.7.32" +name = "winnow" +version = "0.5.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +checksum = "5389a154b01683d28c77f8f68f49dea75f0a4da32557a58f68ee51ebba472d29" dependencies = [ - "zerocopy-derive", + "memchr", ] [[package]] -name = "zerocopy-derive" -version = "0.7.32" +name = "winreg" +version = "0.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.43", + "cfg-if 1.0.0", + "windows-sys 0.48.0", ] [[package]] name = "zeroize" -version = "1.3.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" -dependencies = [ - "zeroize_derive", -] +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" [[package]] -name = "zeroize_derive" -version = "1.4.2" +name = "zip" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.43", + "byteorder", + "crc32fast", + "crossbeam-utils", + "flate2", ] diff --git a/Cargo.toml b/Cargo.toml index 03bc3e07d..dbdd0d3ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,6 @@ [workspace] +resolver = "2" + members = [ "dex", "dex/farm", diff --git a/README.md b/README.md index e5376eaa0..615a1e32e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# Maiar Exchange Smart Contracts +# xExchange Smart Contracts -This repository contains the principal Smart Contract components of Maiar Exchange. +This repository contains the principal Smart Contract components of xExchange. This document is a brief description of the Smart Contracts. It covers the basic workflows that a user may do in order to succesfully interact with each contract. For those interested about more in-depth technical details, each contract will have its separate README in its own root directory. -- [Maiar Exchange Smart Contracts](#maiar-exchange-smart-contracts) +- [xExchange Smart Contracts](#xexchange-smart-contracts) - [DEX Contracts](#dex-contracts) - [Pair Contract](#pair-contract) - [Router Contract](#router-contract) @@ -20,13 +20,13 @@ This document is a brief description of the Smart Contracts. It covers the basic - [DEX Proxy Contract](#dex-proxy-contract) - [Locked MEX Factory Contract](#locked-mex-factory-contract) -Other Smart Contracts that are part of Maiar exchange, but are not part of this repository: +Other Smart Contracts that are part of xExchange, but are not part of this repository: - [Egld wrapping](https://github.com/multiversx/mx-sdk-rs/tree/master/contracts/core/wegld-swap) used for swapping EGLD to an ESDT and reversed with an exchange rate of 1:1. ## DEX Contracts -Core SCs of Maiar Exchange. They usually handle a few tokens and are used as primitives by the other contracts as they are built on top of them. +Core SCs of xExchange. They usually handle a few tokens and are used as primitives by the other contracts as they are built on top of them. ### Pair Contract diff --git a/common/common_errors/Cargo.toml b/common/common_errors/Cargo.toml index c4d256a3c..c61a89e80 100644 --- a/common/common_errors/Cargo.toml +++ b/common/common_errors/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [lib] path = "src/lib.rs" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/common_structs/Cargo.toml b/common/common_structs/Cargo.toml index 98b03285a..8e5655f12 100644 --- a/common/common_structs/Cargo.toml +++ b/common/common_structs/Cargo.toml @@ -6,8 +6,9 @@ edition = "2021" [lib] path = "src/lib.rs" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.mergeable] diff --git a/common/modules/farm/config/Cargo.toml b/common/modules/farm/config/Cargo.toml index 7380edcdc..b5de657af 100644 --- a/common/modules/farm/config/Cargo.toml +++ b/common/modules/farm/config/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [lib] path = "src/config.rs" + [dependencies.common_structs] path = "../../../common_structs" @@ -22,5 +23,5 @@ path = "../../pausable" path = "../../permissions_module" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/farm/config/src/config.rs b/common/modules/farm/config/src/config.rs index 38606f280..b712765e5 100644 --- a/common/modules/farm/config/src/config.rs +++ b/common/modules/farm/config/src/config.rs @@ -7,15 +7,95 @@ use common_structs::Nonce; use pausable::State; pub const DEFAULT_NFT_DEPOSIT_MAX_LEN: usize = 10; +pub const DEFAULT_FARM_POSITION_MIGRATION_NONCE: u64 = 1; + +#[derive( + ManagedVecItem, + TopEncode, + TopDecode, + NestedEncode, + NestedDecode, + TypeAbi, + Clone, + PartialEq, + Debug, +)] +pub struct UserTotalFarmPosition { + pub total_farm_position: BigUint, + pub allow_external_claim_boosted_rewards: bool, +} + +impl Default for UserTotalFarmPosition { + fn default() -> Self { + Self { + total_farm_position: BigUint::zero(), + allow_external_claim_boosted_rewards: false, + } + } +} #[multiversx_sc::module] pub trait ConfigModule: pausable::PausableModule + permissions_module::PermissionsModule { + #[endpoint(allowExternalClaimBoostedRewards)] + fn allow_external_claim_boosted_rewards(&self, allow_external_claim: bool) { + let caller = self.blockchain().get_caller(); + let mut user_total_farm_position = self.get_user_total_farm_position(&caller); + user_total_farm_position.allow_external_claim_boosted_rewards = allow_external_claim; + self.user_total_farm_position(&caller) + .set(user_total_farm_position); + } + + #[view(getAllowExternalClaimRewards)] + fn get_allow_external_claim_rewards(&self, user: ManagedAddress) -> bool { + let user_total_farm_position = self.get_user_total_farm_position(&user); + user_total_farm_position.allow_external_claim_boosted_rewards + } + #[inline] fn is_active(&self) -> bool { let state = self.state().get(); state == State::Active } + fn get_user_total_farm_position( + &self, + user: &ManagedAddress, + ) -> UserTotalFarmPosition { + let user_total_farm_position_mapper = self.user_total_farm_position(user); + if user_total_farm_position_mapper.is_empty() { + UserTotalFarmPosition::default() + } else { + user_total_farm_position_mapper.get() + } + } + + fn is_old_farm_position(&self, token_nonce: Nonce) -> bool { + let farm_position_migration_nonce = self.farm_position_migration_nonce().get(); + token_nonce > 0 && token_nonce < farm_position_migration_nonce + } + + fn try_set_farm_position_migration_nonce( + &self, + farm_token_mapper: NonFungibleTokenMapper, + ) { + if !self.farm_position_migration_nonce().is_empty() { + return; + } + + let migration_farm_token_nonce = if farm_token_mapper.get_token_state().is_set() { + let token_identifier = farm_token_mapper.get_token_id_ref(); + let current_nonce = self + .blockchain() + .get_current_esdt_nft_nonce(&self.blockchain().get_sc_address(), token_identifier); + current_nonce + DEFAULT_FARM_POSITION_MIGRATION_NONCE + } else { + DEFAULT_FARM_POSITION_MIGRATION_NONCE + }; + + self.farm_position_migration_nonce() + .set(migration_farm_token_nonce); + } + #[view(getFarmingTokenId)] #[storage_mapper("farming_token_id")] fn farming_token_id(&self) -> SingleValueMapper; @@ -38,4 +118,15 @@ pub trait ConfigModule: pausable::PausableModule + permissions_module::Permissio #[view(getDivisionSafetyConstant)] #[storage_mapper("division_safety_constant")] fn division_safety_constant(&self) -> SingleValueMapper; + + #[view(getUserTotalFarmPosition)] + #[storage_mapper("userTotalFarmPosition")] + fn user_total_farm_position( + &self, + user: &ManagedAddress, + ) -> SingleValueMapper>; + + #[view(getFarmPositionMigrationNonce)] + #[storage_mapper("farm_position_migration_nonce")] + fn farm_position_migration_nonce(&self) -> SingleValueMapper; } diff --git a/common/modules/farm/contexts/Cargo.toml b/common/modules/farm/contexts/Cargo.toml index 1fc3a93ed..b61c7a7cb 100644 --- a/common/modules/farm/contexts/Cargo.toml +++ b/common/modules/farm/contexts/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [lib] path = "src/mod.rs" + [dependencies.common_structs] path = "../../../common_structs" @@ -34,8 +35,8 @@ path = "../../pausable" path = "../../permissions_module" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" diff --git a/common/modules/farm/contexts/src/claim_rewards_context.rs b/common/modules/farm/contexts/src/claim_rewards_context.rs index d327156b5..653c6b2e6 100644 --- a/common/modules/farm/contexts/src/claim_rewards_context.rs +++ b/common/modules/farm/contexts/src/claim_rewards_context.rs @@ -3,6 +3,7 @@ multiversx_sc::derive_imports!(); use common_errors::{ERROR_BAD_PAYMENTS, ERROR_EMPTY_PAYMENTS}; use common_structs::PaymentAttributesPair; +use multiversx_sc::api::BlockchainApi; use multiversx_sc::contract_base::BlockchainWrapper; pub struct ClaimRewardsContext diff --git a/common/modules/farm/contexts/src/exit_farm_context.rs b/common/modules/farm/contexts/src/exit_farm_context.rs index b56d88498..98aea1adb 100644 --- a/common/modules/farm/contexts/src/exit_farm_context.rs +++ b/common/modules/farm/contexts/src/exit_farm_context.rs @@ -3,6 +3,7 @@ multiversx_sc::derive_imports!(); use common_errors::ERROR_BAD_PAYMENTS; use common_structs::PaymentAttributesPair; +use multiversx_sc::api::BlockchainApi; use multiversx_sc::contract_base::BlockchainWrapper; pub struct ExitFarmContext diff --git a/common/modules/farm/events/Cargo.toml b/common/modules/farm/events/Cargo.toml index 453278dd2..f69904d95 100644 --- a/common/modules/farm/events/Cargo.toml +++ b/common/modules/farm/events/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [lib] path = "src/events.rs" + [dependencies.common_structs] path = "../../../common_structs" @@ -13,5 +14,5 @@ path = "../../../common_structs" path = "../contexts" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/farm/farm_base_impl/Cargo.toml b/common/modules/farm/farm_base_impl/Cargo.toml index db5644507..7ac538eff 100644 --- a/common/modules/farm/farm_base_impl/Cargo.toml +++ b/common/modules/farm/farm_base_impl/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [lib] path = "src/lib.rs" + [dependencies.config] path = "../config" @@ -49,10 +50,11 @@ path = "../../../traits/mergeable" path = "../../../traits/fixed-supply-token" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" + [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" diff --git a/common/modules/farm/farm_base_impl/src/base_farm_init.rs b/common/modules/farm/farm_base_impl/src/base_farm_init.rs index dcba4b6c4..700057a3e 100644 --- a/common/modules/farm/farm_base_impl/src/base_farm_init.rs +++ b/common/modules/farm/farm_base_impl/src/base_farm_init.rs @@ -1,6 +1,6 @@ multiversx_sc::imports!(); -use common_errors::{ERROR_NOT_AN_ESDT, ERROR_SAME_TOKEN_IDS, ERROR_ZERO_AMOUNT}; +use common_errors::{ERROR_NOT_AN_ESDT, ERROR_ZERO_AMOUNT}; use pausable::State; use permissions_module::Permissions; @@ -30,10 +30,6 @@ pub trait BaseFarmInitModule: ); require!(division_safety_constant != 0u64, ERROR_ZERO_AMOUNT); - let farm_token = self.farm_token().get_token_id(); - require!(reward_token_id != farm_token, ERROR_SAME_TOKEN_IDS); - require!(farming_token_id != farm_token, ERROR_SAME_TOKEN_IDS); - self.state().set(State::Inactive); self.division_safety_constant() .set_if_empty(&division_safety_constant); 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 eaa86c5ac..f2ccc293c 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 @@ -6,6 +6,7 @@ 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 = @@ -187,6 +188,63 @@ pub trait FarmContract { _storage_cache: &StorageCache, ) { } + + 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 { + farm_token_mapper.require_same_token(&farm_position.token_identifier); + + if sc.is_old_farm_position(farm_position.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); + } + } + } + + #[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: FarmTokenAttributes<::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(); + } + }); + } } pub struct DefaultFarmWrapper 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 256828ca3..d9dfe293e 100644 --- a/common/modules/farm/farm_base_impl/src/claim_rewards.rs +++ b/common/modules/farm/farm_base_impl/src/claim_rewards.rs @@ -58,7 +58,7 @@ pub trait BaseClaimRewardsModule: self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); let claim_rewards_context = ClaimRewardsContext::::new( - payments, + payments.clone(), &storage_cache.farm_token_id, self.blockchain(), ); @@ -81,6 +81,8 @@ pub trait BaseClaimRewardsModule: ); storage_cache.reward_reserve -= &reward; + FC::check_and_update_user_farm_position(self, &caller, &payments); + let farm_token_mapper = self.farm_token(); let base_attributes = FC::create_claim_rewards_initial_attributes( self, 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 0b17976f4..06e52585c 100644 --- a/common/modules/farm/farm_base_impl/src/compound_rewards.rs +++ b/common/modules/farm/farm_base_impl/src/compound_rewards.rs @@ -46,7 +46,7 @@ pub trait BaseCompoundRewardsModule: ); let compound_rewards_context = CompoundRewardsContext::::new( - payments, + payments.clone(), &storage_cache.farm_token_id, self.blockchain(), ); @@ -70,10 +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); + let farm_token_mapper = self.farm_token(); let base_attributes = FC::create_compound_rewards_initial_attributes( self, - caller, + caller.clone(), token_attributes, storage_cache.reward_per_share.clone(), &reward, @@ -84,6 +86,8 @@ pub trait BaseCompoundRewardsModule: &farm_token_mapper, ); + FC::increase_user_farm_position(self, &caller, &reward); + let first_farm_token = &compound_rewards_context.first_farm_token.payment; farm_token_mapper.nft_burn(first_farm_token.token_nonce, &first_farm_token.amount); self.send() 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 79f9e5df9..02e20d42a 100644 --- a/common/modules/farm/farm_base_impl/src/enter_farm.rs +++ b/common/modules/farm/farm_base_impl/src/enter_farm.rs @@ -44,6 +44,18 @@ pub trait BaseEnterFarmModule: &storage_cache.farm_token_id, ); + // The order is important - first check and update, then increase position + FC::check_and_update_user_farm_position( + self, + &caller, + &enter_farm_context.additional_farm_tokens, + ); + FC::increase_user_farm_position( + self, + &caller, + &enter_farm_context.farming_token_payment.amount, + ); + FC::generate_aggregated_rewards(self, &mut storage_cache); storage_cache.farm_token_supply += &enter_farm_context.farming_token_payment.amount; 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 c60dd7a73..315abe421 100644 --- a/common/modules/farm/farm_base_impl/src/exit_farm.rs +++ b/common/modules/farm/farm_base_impl/src/exit_farm.rs @@ -39,7 +39,7 @@ pub trait BaseExitFarmModule: self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); let exit_farm_context = ExitFarmContext::::new( - payment, + payment.clone(), &storage_cache.farm_token_id, self.blockchain(), ); @@ -62,6 +62,8 @@ pub trait BaseExitFarmModule: ); storage_cache.reward_reserve -= &reward; + FC::decrease_user_farm_position(self, &payment); + let farming_token_amount = token_attributes.get_total_supply(); let farming_token_payment = EsdtTokenPayment::new( storage_cache.farming_token_id.clone(), diff --git a/common/modules/farm/farm_token/Cargo.toml b/common/modules/farm/farm_token/Cargo.toml index 7fc2158cc..64834bd68 100644 --- a/common/modules/farm/farm_token/Cargo.toml +++ b/common/modules/farm/farm_token/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [lib] path = "src/farm_token.rs" + [dependencies.common_structs] path = "../../../common_structs" @@ -25,8 +26,8 @@ path = "../../pausable" path = "../../permissions_module" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" diff --git a/common/modules/farm/farm_token/src/farm_token.rs b/common/modules/farm/farm_token/src/farm_token.rs index 30843ef3d..de3f32d5d 100644 --- a/common/modules/farm/farm_token/src/farm_token.rs +++ b/common/modules/farm/farm_token/src/farm_token.rs @@ -20,7 +20,7 @@ pub trait FarmTokenModule: ) { self.require_caller_has_owner_or_admin_permissions(); - let payment_amount = self.call_value().egld_value(); + let payment_amount = self.call_value().egld_value().clone_value(); self.farm_token().issue_and_set_all_roles( EsdtTokenType::Meta, payment_amount, diff --git a/common/modules/farm/farm_token_merge/Cargo.toml b/common/modules/farm/farm_token_merge/Cargo.toml index e73555fd1..4df9540e8 100644 --- a/common/modules/farm/farm_token_merge/Cargo.toml +++ b/common/modules/farm/farm_token_merge/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [lib] path = "src/lib.rs" + [dependencies.common_structs] path = "../../../common_structs" @@ -22,8 +23,11 @@ path = "../../token_merge_helper" path = "../farm_token" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/common/modules/farm/rewards/Cargo.toml b/common/modules/farm/rewards/Cargo.toml index 57a1fe8de..68d37f46d 100644 --- a/common/modules/farm/rewards/Cargo.toml +++ b/common/modules/farm/rewards/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [lib] path = "src/rewards.rs" + [dependencies.common_structs] path = "../../../common_structs" @@ -28,8 +29,8 @@ path = "../../pausable" path = "../../permissions_module" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" diff --git a/common/modules/legacy_token_decode_module/Cargo.toml b/common/modules/legacy_token_decode_module/Cargo.toml index 5f26f6f7b..124b2ec02 100644 --- a/common/modules/legacy_token_decode_module/Cargo.toml +++ b/common/modules/legacy_token_decode_module/Cargo.toml @@ -6,8 +6,9 @@ edition = "2018" [lib] path = "src/lib.rs" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" 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 b6179493e..660635a24 100644 --- a/common/modules/locking_module/Cargo.toml +++ b/common/modules/locking_module/Cargo.toml @@ -6,8 +6,9 @@ edition = "2021" [lib] path = "src/lib.rs" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.simple-lock] diff --git a/common/modules/math/Cargo.toml b/common/modules/math/Cargo.toml index 4b5883072..5f1f99325 100644 --- a/common/modules/math/Cargo.toml +++ b/common/modules/math/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [lib] path = "src/lib.rs" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/pausable/Cargo.toml b/common/modules/pausable/Cargo.toml index 1f6aa17be..2f258161b 100644 --- a/common/modules/pausable/Cargo.toml +++ b/common/modules/pausable/Cargo.toml @@ -6,9 +6,10 @@ edition = "2021" [lib] path = "src/pausable.rs" + [dependencies.permissions_module] path = "../permissions_module" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/permissions_module/Cargo.toml b/common/modules/permissions_module/Cargo.toml index e899bb299..fdc8d7d2e 100644 --- a/common/modules/permissions_module/Cargo.toml +++ b/common/modules/permissions_module/Cargo.toml @@ -1,18 +1,21 @@ [package] name = "permissions_module" version = "0.0.0" -authors = ["Dorin Iancu ", "Claudiu-Marcel Bruda "] +authors = [ + "Dorin Iancu ", + "Claudiu-Marcel Bruda ", +] edition = "2021" [lib] path = "src/permissions_module.rs" [dependencies] -bitflags = "1.3.2" +bitflags = "2.4.1" [dependencies.common_errors] path = "../../common_errors" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/permissions_module/src/permissions.rs b/common/modules/permissions_module/src/permissions.rs index db63950ca..623c72718 100644 --- a/common/modules/permissions_module/src/permissions.rs +++ b/common/modules/permissions_module/src/permissions.rs @@ -4,6 +4,7 @@ use multiversx_sc::{ codec::{DecodeError, TopDecode, TopEncode}, }; bitflags! { + #[derive(Clone)] pub struct Permissions: u32 { const NONE = 0; const OWNER = 1; diff --git a/common/modules/permissions_module/src/permissions_module.rs b/common/modules/permissions_module/src/permissions_module.rs index 0bf91aafd..5853ca0da 100644 --- a/common/modules/permissions_module/src/permissions_module.rs +++ b/common/modules/permissions_module/src/permissions_module.rs @@ -54,7 +54,7 @@ pub trait PermissionsModule { permissions: Permissions, ) { for address in addresses { - self.add_permissions(address, permissions); + self.add_permissions(address, permissions.clone()); } } diff --git a/common/modules/sc_whitelist_module/Cargo.toml b/common/modules/sc_whitelist_module/Cargo.toml index 0b3bc696d..978cd6a89 100644 --- a/common/modules/sc_whitelist_module/Cargo.toml +++ b/common/modules/sc_whitelist_module/Cargo.toml @@ -6,9 +6,10 @@ edition = "2021" [lib] path = "src/sc_whitelist_module.rs" + [dependencies.common_errors] path = "../../common_errors" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" 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 2bf0e30e9..c337a5996 100644 --- a/common/modules/token_merge_helper/Cargo.toml +++ b/common/modules/token_merge_helper/Cargo.toml @@ -6,9 +6,10 @@ edition = "2021" [lib] path = "src/lib.rs" + [dependencies.common_errors] path = "../../common_errors" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/token_send/Cargo.toml b/common/modules/token_send/Cargo.toml index f2aeda9cc..28b005064 100644 --- a/common/modules/token_send/Cargo.toml +++ b/common/modules/token_send/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [lib] path = "src/token_send.rs" + [dependencies.common_structs] path = "../../common_structs" @@ -13,5 +14,5 @@ path = "../../common_structs" path = "../../common_errors" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/utils/Cargo.toml b/common/modules/utils/Cargo.toml index 6b821e33e..a18635d6e 100644 --- a/common/modules/utils/Cargo.toml +++ b/common/modules/utils/Cargo.toml @@ -6,8 +6,9 @@ edition = "2021" [lib] path = "src/lib.rs" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" 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 333c3e509..990b88329 100644 --- a/common/modules/utils/src/lib.rs +++ b/common/modules/utils/src/lib.rs @@ -32,7 +32,7 @@ pub trait UtilsModule { let payments = self.call_value().all_esdt_transfers(); require!(!payments.is_empty(), ERR_EMPTY_PAYMENTS); - payments + payments.clone_value() } fn pop_first_payment( @@ -126,4 +126,8 @@ pub trait UtilsModule { "Invalid SC address" ); } + + fn require_not_empty_buffer(&self, buffer: &ManagedBuffer) { + require!(!buffer.is_empty(), "Empty buffer"); + } } diff --git a/common/traits/fixed-supply-token/Cargo.toml b/common/traits/fixed-supply-token/Cargo.toml index 1fe4b6fbc..eafd9fe32 100644 --- a/common/traits/fixed-supply-token/Cargo.toml +++ b/common/traits/fixed-supply-token/Cargo.toml @@ -6,5 +6,6 @@ edition = "2021" [lib] path = "src/lib.rs" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" diff --git a/common/traits/mergeable/Cargo.toml b/common/traits/mergeable/Cargo.toml index 526ec4e13..4800de5ca 100644 --- a/common/traits/mergeable/Cargo.toml +++ b/common/traits/mergeable/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [lib] path = "src/lib.rs" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/traits/unwrappable/Cargo.toml b/common/traits/unwrappable/Cargo.toml index 05a13e631..9ba6e7e73 100644 --- a/common/traits/unwrappable/Cargo.toml +++ b/common/traits/unwrappable/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [lib] path = "src/lib.rs" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] diff --git a/dex/Cargo.toml b/dex/Cargo.toml index 25e221076..62d9161bf 100644 --- a/dex/Cargo.toml +++ b/dex/Cargo.toml @@ -3,18 +3,19 @@ name = "dex-tests" version = "0.0.0" edition = "2021" publish = false + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" [dev-dependencies.config] path = "../common/modules/farm/config" diff --git a/dex/farm-staking-proxy/wasm/Cargo.lock b/dex/farm-staking-proxy/wasm/Cargo.lock deleted file mode 100644 index 8f5238cd6..000000000 --- a/dex/farm-staking-proxy/wasm/Cargo.lock +++ /dev/null @@ -1,457 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "ahash" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - -[[package]] -name = "arrayvec" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "common_errors" -version = "0.0.0" -dependencies = [ - "multiversx-sc", -] - -[[package]] -name = "common_structs" -version = "0.0.0" -dependencies = [ - "multiversx-sc", -] - -[[package]] -name = "config" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "multiversx-sc", - "token_send", -] - -[[package]] -name = "contexts" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "config", - "multiversx-sc", - "farm_token", - "rewards", - "token_merge", - "token_send", -] - -[[package]] -name = "either" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" - -[[package]] -name = "elrond-codec" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6d85f2b7c969a12da26157a989f759f59d1df2b0e2f4ae7b2ebb011334a63c1" -dependencies = [ - "arrayvec", - "elrond-codec-derive", - "wee_alloc", -] - -[[package]] -name = "elrond-codec-derive" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae84b062b57562daf6b90d12c6568a6df21ef355625f6dd21a3106d774456a51" -dependencies = [ - "hex", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "multiversx-sc" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c99bd13acbd995a1b048fcc791a8acd8d2d4ab1085738c9077607d218fb2a42f" -dependencies = [ - "bitflags", - "elrond-codec", - "multiversx-sc-derive", - "hashbrown", - "hex-literal", - "wee_alloc", -] - -[[package]] -name = "multiversx-sc-derive" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a3e0e238435b3e1ac971e15ac345bf4f75efc88c8ee0032e286cf67dbff9681" -dependencies = [ - "hex", - "proc-macro2", - "quote", - "radix_trie", - "syn", -] - -[[package]] -name = "multiversx-sc-node" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad55a0495ab1760ab532766529bc4b1cda04c918e44cfb2d84e1ac066d574397" -dependencies = [ - "multiversx-sc", -] - -[[package]] -name = "multiversx-sc-output" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a1b54eef1004bb8b622b7f8cbe0100c715dfd58699bb7b0c5a50d23c3a87f38" -dependencies = [ - "multiversx-sc-node", - "wee_alloc", -] - -[[package]] -name = "endian-type" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" - -[[package]] -name = "events" -version = "0.0.0" -dependencies = [ - "common_structs", - "contexts", - "multiversx-sc", -] - -[[package]] -name = "factory" -version = "0.0.0" -dependencies = [ - "arrayvec", - "common_errors", - "common_structs", - "multiversx-sc", - "itertools", - "token_merge", - "token_send", - "wee_alloc", -] - -[[package]] -name = "farm" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "config", - "contexts", - "multiversx-sc", - "events", - "factory", - "farm_token", - "migration_from_v1_2", - "pair", - "rewards", - "token_merge", - "token_send", -] - -[[package]] -name = "farm-staking" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "config", - "multiversx-sc", - "factory", - "farm_token", - "pair", - "rewards", - "token_merge", - "token_send", -] - -[[package]] -name = "farm-staking-proxy" -version = "0.0.0" -dependencies = [ - "common_structs", - "multiversx-sc", - "farm", - "farm-staking", - "hex-literal", - "pair", - "token_merge", -] - -[[package]] -name = "farm-staking-proxy-wasm" -version = "0.0.0" -dependencies = [ - "multiversx-sc-node", - "multiversx-sc-output", - "farm-staking-proxy", -] - -[[package]] -name = "farm_token" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "config", - "multiversx-sc", - "token_send", -] - -[[package]] -name = "getrandom" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi", -] - -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" -dependencies = [ - "ahash", -] - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "hex-literal" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" - -[[package]] -name = "itertools" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" -dependencies = [ - "either", -] - -[[package]] -name = "libc" -version = "0.2.119" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" - -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - -[[package]] -name = "migration_from_v1_2" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "config", - "multiversx-sc", - "farm_token", - "rewards", - "token_send", -] - -[[package]] -name = "nibble_vec" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8d77f3db4bce033f4d04db08079b2ef1c3d02b44e86f25d08886fafa7756ffa" - -[[package]] -name = "once_cell" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" - -[[package]] -name = "pair" -version = "0.0.0" -dependencies = [ - "common_structs", - "multiversx-sc", - "itertools", - "token_send", -] - -[[package]] -name = "proc-macro2" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" -dependencies = [ - "unicode-xid", -] - -[[package]] -name = "quote" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "radix_trie" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d3681b28cd95acfb0560ea9441f82d6a4504fa3b15b97bd7b6e952131820e95" -dependencies = [ - "endian-type", - "nibble_vec", -] - -[[package]] -name = "rewards" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "config", - "multiversx-sc", - "farm_token", - "token_send", -] - -[[package]] -name = "syn" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - -[[package]] -name = "token_merge" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "multiversx-sc", -] - -[[package]] -name = "token_send" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "multiversx-sc", -] - -[[package]] -name = "unicode-xid" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/dex/farm-staking/wasm/Cargo.lock b/dex/farm-staking/wasm/Cargo.lock deleted file mode 100644 index c4db9fb9a..000000000 --- a/dex/farm-staking/wasm/Cargo.lock +++ /dev/null @@ -1,389 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "ahash" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - -[[package]] -name = "arrayvec" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "common_errors" -version = "0.0.0" -dependencies = [ - "multiversx-sc", -] - -[[package]] -name = "common_structs" -version = "0.0.0" -dependencies = [ - "multiversx-sc", -] - -[[package]] -name = "config" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "multiversx-sc", - "token_send", -] - -[[package]] -name = "either" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" - -[[package]] -name = "elrond-codec" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6d85f2b7c969a12da26157a989f759f59d1df2b0e2f4ae7b2ebb011334a63c1" -dependencies = [ - "arrayvec", - "elrond-codec-derive", - "wee_alloc", -] - -[[package]] -name = "elrond-codec-derive" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae84b062b57562daf6b90d12c6568a6df21ef355625f6dd21a3106d774456a51" -dependencies = [ - "hex", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "multiversx-sc" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c99bd13acbd995a1b048fcc791a8acd8d2d4ab1085738c9077607d218fb2a42f" -dependencies = [ - "bitflags", - "elrond-codec", - "multiversx-sc-derive", - "hashbrown", - "hex-literal", - "wee_alloc", -] - -[[package]] -name = "multiversx-sc-derive" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a3e0e238435b3e1ac971e15ac345bf4f75efc88c8ee0032e286cf67dbff9681" -dependencies = [ - "hex", - "proc-macro2", - "quote", - "radix_trie", - "syn", -] - -[[package]] -name = "multiversx-sc-node" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad55a0495ab1760ab532766529bc4b1cda04c918e44cfb2d84e1ac066d574397" -dependencies = [ - "multiversx-sc", -] - -[[package]] -name = "multiversx-sc-output" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a1b54eef1004bb8b622b7f8cbe0100c715dfd58699bb7b0c5a50d23c3a87f38" -dependencies = [ - "multiversx-sc-node", - "wee_alloc", -] - -[[package]] -name = "endian-type" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" - -[[package]] -name = "factory" -version = "0.0.0" -dependencies = [ - "arrayvec", - "common_errors", - "common_structs", - "multiversx-sc", - "itertools", - "token_merge", - "token_send", - "wee_alloc", -] - -[[package]] -name = "farm-staking" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "config", - "multiversx-sc", - "factory", - "farm_token", - "pair", - "rewards", - "token_merge", - "token_send", -] - -[[package]] -name = "farm-staking-wasm" -version = "0.0.0" -dependencies = [ - "multiversx-sc-node", - "multiversx-sc-output", - "farm-staking", -] - -[[package]] -name = "farm_token" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "config", - "multiversx-sc", - "token_send", -] - -[[package]] -name = "getrandom" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi", -] - -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" -dependencies = [ - "ahash", -] - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "hex-literal" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" - -[[package]] -name = "itertools" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" -dependencies = [ - "either", -] - -[[package]] -name = "libc" -version = "0.2.115" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a8d982fa7a96a000f6ec4cfe966de9703eccde29750df2bb8949da91b0e818d" - -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - -[[package]] -name = "nibble_vec" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8d77f3db4bce033f4d04db08079b2ef1c3d02b44e86f25d08886fafa7756ffa" - -[[package]] -name = "once_cell" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" - -[[package]] -name = "pair" -version = "0.0.0" -dependencies = [ - "common_structs", - "multiversx-sc", - "itertools", - "token_send", -] - -[[package]] -name = "proc-macro2" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" -dependencies = [ - "unicode-xid", -] - -[[package]] -name = "quote" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "radix_trie" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d3681b28cd95acfb0560ea9441f82d6a4504fa3b15b97bd7b6e952131820e95" -dependencies = [ - "endian-type", - "nibble_vec", -] - -[[package]] -name = "rewards" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "config", - "multiversx-sc", - "farm_token", - "token_send", -] - -[[package]] -name = "syn" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - -[[package]] -name = "token_merge" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "multiversx-sc", -] - -[[package]] -name = "token_send" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "multiversx-sc", -] - -[[package]] -name = "unicode-xid" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/dex/farm-with-locked-rewards/Cargo.toml b/dex/farm-with-locked-rewards/Cargo.toml index 3052499d2..c19480688 100644 --- a/dex/farm-with-locked-rewards/Cargo.toml +++ b/dex/farm-with-locked-rewards/Cargo.toml @@ -7,6 +7,7 @@ publish = false [lib] path = "src/lib.rs" + [dependencies.farm_base_impl] path = "../../common/modules/farm/farm_base_impl" @@ -74,17 +75,17 @@ path = "../../locked-asset/energy-factory" path = "../../energy-integration/common-modules/energy-query" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" [dev-dependencies.simple-lock] path = "../../locked-asset/simple-lock" diff --git a/dex/farm-with-locked-rewards/README.md b/dex/farm-with-locked-rewards/README.md index ba1d7b443..fd70b0aa2 100644 --- a/dex/farm-with-locked-rewards/README.md +++ b/dex/farm-with-locked-rewards/README.md @@ -2,7 +2,7 @@ ## Abstract -Liquidity providers of Maiar Exchange are incentivized with locked rewards in exchange for them locking their tokens in Farm contracts. +Liquidity providers of xExchange are incentivized with locked rewards in exchange for them locking their tokens in Farm contracts. ## Introduction diff --git a/dex/farm-with-locked-rewards/elrond.json b/dex/farm-with-locked-rewards/elrond.json deleted file mode 100644 index 736553962..000000000 --- a/dex/farm-with-locked-rewards/elrond.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "language": "rust" -} \ No newline at end of file diff --git a/dex/farm-with-locked-rewards/meta/Cargo.toml b/dex/farm-with-locked-rewards/meta/Cargo.toml index b35c1982d..47476c339 100644 --- a/dex/farm-with-locked-rewards/meta/Cargo.toml +++ b/dex/farm-with-locked-rewards/meta/Cargo.toml @@ -4,8 +4,10 @@ version = "0.0.0" authors = ["MultiversX "] edition = "2021" publish = false + [dependencies.farm-with-locked-rewards] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/dex/farm-with-locked-rewards/src/lib.rs b/dex/farm-with-locked-rewards/src/lib.rs index 0bfbff59b..a42f6518c 100644 --- a/dex/farm-with-locked-rewards/src/lib.rs +++ b/dex/farm-with-locked-rewards/src/lib.rs @@ -8,10 +8,9 @@ multiversx_sc::derive_imports!(); use common_structs::FarmTokenAttributes; use contexts::storage_cache::StorageCache; use core::marker::PhantomData; -use mergeable::Mergeable; use farm::{ - base_functions::{BaseFunctionsModule, ClaimRewardsResultType, Wrapper}, + base_functions::{BaseFunctionsModule, ClaimRewardsResultType, DoubleMultiPayment, Wrapper}, exit_penalty::{ DEFAULT_BURN_GAS_LIMIT, DEFAULT_MINUMUM_FARMING_EPOCHS, DEFAULT_PENALTY_PERCENT, }, @@ -34,8 +33,6 @@ pub trait Farm: + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + farm::base_functions::BaseFunctionsModule + farm::exit_penalty::ExitPenaltyModule - + farm::progress_update::ProgressUpdateModule - + farm::claim_boost_only::ClaimBoostOnlyModule + farm_base_impl::base_farm_init::BaseFarmInitModule + farm_base_impl::base_farm_validation::BaseFarmValidationModule + farm_base_impl::enter_farm::BaseEnterFarmModule @@ -78,6 +75,20 @@ pub trait Farm: let current_epoch = self.blockchain().get_block_epoch(); self.first_week_start_epoch().set_if_empty(current_epoch); + + // Farm position migration code + let farm_token_mapper = self.farm_token(); + self.try_set_farm_position_migration_nonce(farm_token_mapper); + } + + #[endpoint] + fn upgrade(&self) { + let current_epoch = self.blockchain().get_block_epoch(); + self.first_week_start_epoch().set_if_empty(current_epoch); + + // Farm position migration code + let farm_token_mapper = self.farm_token(); + self.try_set_farm_position_migration_nonce(farm_token_mapper); } #[payable("*")] @@ -89,27 +100,21 @@ pub trait Farm: let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); - let payments = self.get_non_empty_payments(); - let first_additional_payment_index = 1; - let boosted_rewards = match payments.try_get(first_additional_payment_index) { - Some(p) => { - let unlocked_rewards = self.claim_only_boosted_payment(&orig_caller, &p); - self.send_to_lock_contract_non_zero( - unlocked_rewards.token_identifier, - unlocked_rewards.amount, - caller.clone(), - orig_caller.clone(), - ) - } - None => EsdtTokenPayment::new(self.reward_token_id().get(), 0, BigUint::zero()), - }; + self.migrate_old_farm_positions(&orig_caller); + let boosted_rewards = self.claim_only_boosted_payment(&orig_caller); + let boosted_rewards_payment = self.send_to_lock_contract_non_zero( + self.reward_token_id().get(), + boosted_rewards, + caller.clone(), + orig_caller.clone(), + ); let new_farm_token = self.enter_farm::>(orig_caller.clone()); self.send_payment_non_zero(&caller, &new_farm_token); self.update_energy_and_progress(&orig_caller); - (new_farm_token, boosted_rewards).into() + (new_farm_token, boosted_rewards_payment).into() } #[payable("*")] @@ -121,7 +126,9 @@ pub trait Farm: let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); - let payments = self.call_value().all_esdt_transfers(); + self.migrate_old_farm_positions(&orig_caller); + + let payments = self.call_value().all_esdt_transfers().clone_value(); let base_claim_rewards_result = self.claim_rewards_base::>(orig_caller.clone(), payments); let output_farm_token_payment = base_claim_rewards_result.new_farm_token.payment.clone(); @@ -151,70 +158,32 @@ pub trait Farm: #[endpoint(exitFarm)] fn exit_farm_endpoint( &self, - exit_amount: BigUint, opt_orig_caller: OptionalValue, ) -> ExitFarmWithPartialPosResultType { let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); - let mut payment = self.call_value().single_esdt(); - require!( - payment.amount >= exit_amount, - "Exit amount is bigger than the payment amount" - ); + let payment = self.call_value().single_esdt(); - let boosted_rewards_full_position = self.claim_only_boosted_payment(&orig_caller, &payment); - let remaining_farm_payment = EsdtTokenPayment::new( - payment.token_identifier.clone(), - payment.token_nonce, - &payment.amount - &exit_amount, - ); - - payment.amount = exit_amount; + let migrated_amount = self.migrate_old_farm_positions(&orig_caller); let exit_farm_result = self.exit_farm::>(orig_caller.clone(), payment); - let mut rewards = exit_farm_result.rewards; - rewards.merge_with(boosted_rewards_full_position); + self.decrease_old_farm_positions(migrated_amount, &orig_caller); + + let rewards = exit_farm_result.rewards; self.send_payment_non_zero(&caller, &exit_farm_result.farming_tokens); - self.send_payment_non_zero(&caller, &remaining_farm_payment); let locked_rewards_payment = self.send_to_lock_contract_non_zero( rewards.token_identifier.clone(), - rewards.amount.clone(), + rewards.amount, caller, orig_caller.clone(), ); - self.clear_user_energy_if_needed(&orig_caller, &remaining_farm_payment.amount); + self.clear_user_energy_if_needed(&orig_caller); - ( - exit_farm_result.farming_tokens, - locked_rewards_payment, - remaining_farm_payment, - ) - .into() - } - - #[view(calculateRewardsForGivenPosition)] - fn calculate_rewards_for_given_position( - &self, - user: ManagedAddress, - farm_token_amount: BigUint, - attributes: FarmTokenAttributes, - ) -> BigUint { - self.require_queried(); - - let mut storage_cache = StorageCache::new(self); - NoMintWrapper::::generate_aggregated_rewards(self, &mut storage_cache); - - NoMintWrapper::::calculate_rewards( - self, - &user, - &farm_token_amount, - &attributes, - &storage_cache, - ) + (exit_farm_result.farming_tokens, locked_rewards_payment).into() } #[payable("*")] @@ -222,15 +191,51 @@ pub trait Farm: fn merge_farm_tokens_endpoint( &self, opt_orig_caller: OptionalValue, - ) -> EsdtTokenPayment { + ) -> DoubleMultiPayment { let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); - self.check_claim_progress_for_merge(&orig_caller); + + 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::>(); + self.send_payment_non_zero(&caller, &merged_farm_token); + let locked_rewards_payment = self.send_to_lock_contract_non_zero( + self.reward_token_id().get(), + boosted_rewards, + caller, + orig_caller, + ); + + (merged_farm_token, locked_rewards_payment).into() + } + + #[endpoint(claimBoostedRewards)] + fn claim_boosted_rewards( + &self, + opt_user: OptionalValue, + ) -> EsdtTokenPayment { + let caller = self.blockchain().get_caller(); + let user = match &opt_user { + OptionalValue::Some(user) => user, + OptionalValue::None => &caller, + }; + let user_total_farm_position = self.get_user_total_farm_position(user); + if user != &caller { + require!( + user_total_farm_position.allow_external_claim_boosted_rewards, + "Cannot claim rewards for this address" + ); + } - merged_farm_token + let boosted_rewards = self.claim_only_boosted_payment(user); + self.send_to_lock_contract_non_zero( + self.reward_token_id().get(), + boosted_rewards, + user.clone(), + user.clone(), + ) } #[endpoint(startProduceRewards)] @@ -251,6 +256,27 @@ pub trait Farm: self.set_per_block_rewards::>(per_block_amount); } + #[view(calculateRewardsForGivenPosition)] + fn calculate_rewards_for_given_position( + &self, + user: ManagedAddress, + farm_token_amount: BigUint, + attributes: FarmTokenAttributes, + ) -> BigUint { + self.require_queried(); + + let mut storage_cache = StorageCache::new(self); + NoMintWrapper::::generate_aggregated_rewards(self, &mut storage_cache); + + NoMintWrapper::::calculate_rewards( + self, + &user, + &farm_token_amount, + &attributes, + &storage_cache, + ) + } + fn send_to_lock_contract_non_zero( &self, token_id: TokenIdentifier, @@ -259,7 +285,8 @@ pub trait Farm: energy_address: ManagedAddress, ) -> EsdtTokenPayment { if amount == 0 { - return EsdtTokenPayment::new(token_id, 0, amount); + let locked_token_id = self.get_locked_token_id(); + return EsdtTokenPayment::new(locked_token_id, 0, amount); } self.lock_virtual(token_id, amount, destination_address, energy_address) diff --git a/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_setup/mod.rs b/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_setup/mod.rs index dfccee8b9..f92abc5c7 100644 --- a/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_setup/mod.rs +++ b/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_setup/mod.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + use common_structs::FarmTokenAttributes; use config::ConfigModule; use multiversx_sc::{ @@ -7,7 +9,7 @@ use multiversx_sc::{ }; use multiversx_sc_scenario::{ managed_address, managed_biguint, managed_token_id, rust_biguint, - whitebox::{BlockchainStateWrapper, ContractObjWrapper}, + whitebox_legacy::{BlockchainStateWrapper, ContractObjWrapper}, DebugApi, }; @@ -25,6 +27,7 @@ use multiversx_sc_modules::pause::PauseModule; use pausable::{PausableModule, State}; use sc_whitelist_module::SCWhitelistModule; use simple_lock::locked_token::LockedTokenModule; +use week_timekeeping::Epoch; pub static REWARD_TOKEN_ID: &[u8] = b"MEX-123456"; pub static LOCKED_REWARD_TOKEN_ID: &[u8] = b"LOCKED-123456"; @@ -46,6 +49,14 @@ pub const EPOCHS_IN_YEAR: u64 = 360; pub static LOCK_OPTIONS: &[u64] = &[EPOCHS_IN_YEAR, 2 * EPOCHS_IN_YEAR, 4 * EPOCHS_IN_YEAR]; pub static PENALTY_PERCENTAGES: &[u64] = &[4_000, 6_000, 8_000]; +pub struct RawFarmTokenAttributes { + pub reward_per_share_bytes: Vec, + pub entering_epoch: Epoch, + pub compounded_reward_bytes: Vec, + pub current_farm_amount_bytes: Vec, + pub original_owner_bytes: [u8; 32], +} + pub struct FarmSetup where FarmObjBuilder: 'static + Copy + Fn() -> farm_with_locked_rewards::ContractObj, @@ -300,12 +311,50 @@ where attributes: FarmTokenAttributes, ) -> u64 { let mut result = 0; + + let raw_attributes = RawFarmTokenAttributes { + reward_per_share_bytes: attributes + .reward_per_share + .to_bytes_be() + .as_slice() + .to_vec(), + entering_epoch: attributes.entering_epoch, + compounded_reward_bytes: attributes + .compounded_reward + .to_bytes_be() + .as_slice() + .to_vec(), + current_farm_amount_bytes: attributes + .current_farm_amount + .to_bytes_be() + .as_slice() + .to_vec(), + original_owner_bytes: attributes.original_owner.to_byte_array(), + }; + self.b_mock .execute_query(&self.farm_wrapper, |sc| { + let attributes_managed = FarmTokenAttributes { + reward_per_share: multiversx_sc::types::BigUint::::from_bytes_be( + &raw_attributes.reward_per_share_bytes, + ), + entering_epoch: raw_attributes.entering_epoch, + compounded_reward: multiversx_sc::types::BigUint::::from_bytes_be( + &raw_attributes.compounded_reward_bytes, + ), + current_farm_amount: multiversx_sc::types::BigUint::::from_bytes_be( + &raw_attributes.current_farm_amount_bytes, + ), + original_owner: + multiversx_sc::types::ManagedAddress::::new_from_bytes( + &raw_attributes.original_owner_bytes, + ), + }; + let result_managed = sc.calculate_rewards_for_given_position( managed_address!(user), managed_biguint!(farm_token_amount), - attributes, + attributes_managed, ); result = result_managed.to_u64().unwrap(); }) @@ -342,17 +391,13 @@ where assert_eq!(out_farm_token.token_nonce, expected_farm_token_nonce); assert_eq!(out_farm_token.amount, managed_biguint!(farm_token_amount)); + assert_eq!( + out_reward_token.token_identifier, + managed_token_id!(LOCKED_REWARD_TOKEN_ID) + ); if out_reward_token.amount > 0 { - assert_eq!( - out_reward_token.token_identifier, - managed_token_id!(LOCKED_REWARD_TOKEN_ID) - ); assert_eq!(out_reward_token.token_nonce, 1); } else { - assert_eq!( - out_reward_token.token_identifier, - managed_token_id!(REWARD_TOKEN_ID) - ); assert_eq!(out_reward_token.token_nonce, 0); } @@ -364,25 +409,16 @@ where result } - pub fn exit_farm( - &mut self, - user: &Address, - farm_token_nonce: u64, - farm_token_amount: u64, - exit_farm_amount: u64, - ) { + pub fn exit_farm(&mut self, user: &Address, farm_token_nonce: u64, exit_farm_amount: u64) { self.b_mock .execute_esdt_transfer( user, &self.farm_wrapper, FARM_TOKEN_ID, farm_token_nonce, - &rust_biguint!(farm_token_amount), + &rust_biguint!(exit_farm_amount), |sc| { - let _ = sc.exit_farm_endpoint( - managed_biguint!(exit_farm_amount), - OptionalValue::Some(managed_address!(user)), - ); + let _ = sc.exit_farm_endpoint(OptionalValue::Some(managed_address!(user))); }, ) .assert_ok(); diff --git a/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_test.rs b/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_test.rs index f88ed6774..8a9fb8793 100644 --- a/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_test.rs +++ b/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_test.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + use common_structs::FarmTokenAttributes; use multiversx_sc_scenario::{managed_address, managed_biguint, rust_biguint, DebugApi}; use simple_lock::locked_token::LockedTokenAttributes; @@ -10,7 +12,7 @@ mod farm_with_locked_rewards_setup; #[test] fn farm_with_no_boost_no_proxy_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = FarmSetup::new( farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, @@ -110,7 +112,7 @@ fn farm_with_no_boost_no_proxy_test() { #[test] fn farm_with_boosted_yields_no_proxy_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = FarmSetup::new( farm_with_locked_rewards::contract_obj, energy_factory::contract_obj, @@ -147,7 +149,7 @@ fn farm_with_boosted_yields_no_proxy_test() { 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, 5, 1, 1); + farm_setup.exit_farm(&third_user, 5, 1); // advance 1 week farm_setup.b_mock.set_block_epoch(10); @@ -226,3 +228,110 @@ fn farm_with_boosted_yields_no_proxy_test() { None, ); } + +#[test] +fn total_farm_position_claim_with_locked_rewards_test() { + DebugApi::dummy(); + let mut farm_setup = FarmSetup::new( + farm_with_locked_rewards::contract_obj, + energy_factory::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); + + let temp_user = farm_setup.third_user.clone(); + + // first user enter farm + let farm_in_amount = 50_000_000; + let first_user = farm_setup.first_user.clone(); + farm_setup.set_user_energy(&first_user, 1_000, 2, 1); + farm_setup.enter_farm(&first_user, farm_in_amount); + farm_setup.enter_farm(&first_user, farm_in_amount); + + farm_setup.b_mock.check_nft_balance( + &first_user, + FARM_TOKEN_ID, + 1, + &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!(&first_user), + }), + ); + + farm_setup.b_mock.check_nft_balance( + &first_user, + FARM_TOKEN_ID, + 2, + &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!(&first_user), + }), + ); + + // users claim rewards to get their energy registered + let _ = farm_setup.claim_rewards(&first_user, 1, 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(&first_user, 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(&first_user, 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(&first_user, 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::>( + &first_user, + FARM_TOKEN_ID, + 5, + &rust_biguint!(farm_in_amount), + None, + ); + + // Check user receive locked rewards + farm_setup + .b_mock + .check_nft_balance::>( + &first_user, + LOCKED_REWARD_TOKEN_ID, + 1, + &rust_biguint!(first_received_reward_amt), + None, + ); +} diff --git a/dex/farm-with-locked-rewards/wasm/Cargo.lock b/dex/farm-with-locked-rewards/wasm/Cargo.lock index 83649b5f2..f3af20c87 100644 --- a/dex/farm-with-locked-rewards/wasm/Cargo.lock +++ b/dex/farm-with-locked-rewards/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common-types" @@ -99,9 +76,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "endian-type" @@ -283,15 +260,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -300,9 +268,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "itertools" @@ -322,12 +290,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - [[package]] name = "locking_module" version = "0.0.0" @@ -344,12 +306,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -359,12 +315,11 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -373,20 +328,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -396,9 +350,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -409,21 +363,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -437,19 +390,13 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "pair" version = "0.0.0" @@ -463,6 +410,7 @@ dependencies = [ "permissions_module", "simple-lock", "token_send", + "utils", ] [[package]] @@ -484,18 +432,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -544,15 +492,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -578,9 +526,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -599,24 +547,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - [[package]] name = "week-timekeeping" version = "0.0.0" @@ -636,25 +566,3 @@ dependencies = [ "unwrappable", "week-timekeeping", ] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/dex/farm-with-locked-rewards/wasm/Cargo.toml b/dex/farm-with-locked-rewards/wasm/Cargo.toml index 2c92c6c62..369d8346f 100644 --- a/dex/farm-with-locked-rewards/wasm/Cargo.toml +++ b/dex/farm-with-locked-rewards/wasm/Cargo.toml @@ -1,26 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "farm-with-locked-rewards-wasm" version = "0.0.0" -authors = ["MultiversX "] edition = "2021" publish = false [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.farm-with-locked-rewards] -default-features = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/dex/farm-with-locked-rewards/wasm/src/lib.rs b/dex/farm-with-locked-rewards/wasm/src/lib.rs index d4f9e0650..47d140e12 100644 --- a/dex/farm-with-locked-rewards/wasm/src/lib.rs +++ b/dex/farm-with-locked-rewards/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 62 +// Endpoints: 68 // Async Callback: 1 -// Total number of exported functions: 64 +// Total number of exported functions: 70 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,68 +19,76 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { farm_with_locked_rewards ( - enterFarm - claimRewards - exitFarm - calculateRewardsForGivenPosition - mergeFarmTokens - startProduceRewards - endProduceRewards - setPerBlockRewardAmount - getRewardPerShare - getRewardReserve - getFarmingTokenId - getRewardTokenId - getPerBlockRewardAmount - getLastRewardBlockNonce - getDivisionSafetyConstant - setLockingScAddress - setLockEpochs - getLockingScAddress - getLockEpochs - registerFarmToken - getFarmTokenId - getFarmTokenSupply - addToPauseWhitelist - removeFromPauseWhitelist - pause - resume - getState - addAdmin - removeAdmin - updateOwnerOrAdmin - getPermissions - addSCAddressToWhitelist - removeSCAddressFromWhitelist - isSCAddressWhitelisted - set_penalty_percent - set_minimum_farming_epochs - set_burn_gas_limit - getPenaltyPercent - getMinimumFarmingEpoch - getBurnGasLimit - getPairContractManagedAddress - setBoostedYieldsRewardsPercentage - collectUndistributedBoostedRewards - getBoostedYieldsRewardsPercentage - getAccumulatedRewardsForWeek - getFarmSupplyForWeek - getRemainingBoostedRewardsToDistribute - getUndistributedBoostedRewards - setBoostedYieldsFactors - getBoostedYieldsFactors - getCurrentWeek - getFirstWeekStartEpoch - getLastActiveWeekForUser - getUserEnergyForWeek - getLastGlobalUpdateWeek - getTotalRewardsForWeek - getTotalEnergyForWeek - getTotalLockedTokensForWeek - updateEnergyForUser - getCurrentClaimProgress - setEnergyFactoryAddress - getEnergyFactoryAddress - callBack + init => init + upgrade => upgrade + enterFarm => enter_farm_endpoint + claimRewards => claim_rewards_endpoint + exitFarm => exit_farm_endpoint + mergeFarmTokens => merge_farm_tokens_endpoint + claimBoostedRewards => claim_boosted_rewards + startProduceRewards => start_produce_rewards_endpoint + endProduceRewards => end_produce_rewards_endpoint + setPerBlockRewardAmount => set_per_block_rewards_endpoint + calculateRewardsForGivenPosition => calculate_rewards_for_given_position + getRewardPerShare => reward_per_share + getRewardReserve => reward_reserve + allowExternalClaimBoostedRewards => allow_external_claim_boosted_rewards + getAllowExternalClaimRewards => get_allow_external_claim_rewards + getFarmingTokenId => farming_token_id + getRewardTokenId => reward_token_id + getPerBlockRewardAmount => per_block_reward_amount + getLastRewardBlockNonce => last_reward_block_nonce + getDivisionSafetyConstant => division_safety_constant + getUserTotalFarmPosition => user_total_farm_position + getFarmPositionMigrationNonce => farm_position_migration_nonce + setLockingScAddress => set_locking_sc_address + setLockEpochs => set_lock_epochs + getLockingScAddress => locking_sc_address + getLockEpochs => lock_epochs + registerFarmToken => register_farm_token + getFarmTokenId => farm_token + getFarmTokenSupply => farm_token_supply + addToPauseWhitelist => add_to_pause_whitelist + removeFromPauseWhitelist => remove_from_pause_whitelist + pause => pause + resume => resume + getState => state + addAdmin => add_admin_endpoint + removeAdmin => remove_admin_endpoint + updateOwnerOrAdmin => update_owner_or_admin_endpoint + getPermissions => permissions + addSCAddressToWhitelist => add_sc_address_to_whitelist + removeSCAddressFromWhitelist => remove_sc_address_from_whitelist + isSCAddressWhitelisted => is_sc_address_whitelisted + set_penalty_percent => set_penalty_percent + set_minimum_farming_epochs => set_minimum_farming_epochs + set_burn_gas_limit => set_burn_gas_limit + getPenaltyPercent => penalty_percent + getMinimumFarmingEpoch => minimum_farming_epochs + getBurnGasLimit => burn_gas_limit + getPairContractManagedAddress => pair_contract_address + setBoostedYieldsRewardsPercentage => set_boosted_yields_rewards_percentage + collectUndistributedBoostedRewards => collect_undistributed_boosted_rewards + getBoostedYieldsRewardsPercentage => boosted_yields_rewards_percentage + getAccumulatedRewardsForWeek => accumulated_rewards_for_week + getFarmSupplyForWeek => farm_supply_for_week + getRemainingBoostedRewardsToDistribute => remaining_boosted_rewards_to_distribute + getUndistributedBoostedRewards => undistributed_boosted_rewards + setBoostedYieldsFactors => set_boosted_yields_factors + getBoostedYieldsFactors => get_boosted_yields_factors + getCurrentWeek => get_current_week + getFirstWeekStartEpoch => first_week_start_epoch + getLastActiveWeekForUser => get_last_active_week_for_user_view + getUserEnergyForWeek => get_user_energy_for_week_view + getLastGlobalUpdateWeek => last_global_update_week + getTotalRewardsForWeek => total_rewards_for_week + getTotalEnergyForWeek => total_energy_for_week + getTotalLockedTokensForWeek => total_locked_tokens_for_week + updateEnergyForUser => update_energy_for_user + getCurrentClaimProgress => current_claim_progress + setEnergyFactoryAddress => set_energy_factory_address + getEnergyFactoryAddress => energy_factory_address ) } + +multiversx_sc_wasm_adapter::async_callback! { farm_with_locked_rewards } diff --git a/dex/farm/Cargo.toml b/dex/farm/Cargo.toml index f2cca8bf7..517a35cae 100644 --- a/dex/farm/Cargo.toml +++ b/dex/farm/Cargo.toml @@ -7,6 +7,7 @@ publish = false [lib] path = "src/lib.rs" + [dependencies.farm_base_impl] path = "../../common/modules/farm/farm_base_impl" @@ -68,11 +69,11 @@ path = "../../energy-integration/common-modules/weekly-rewards-splitting" path = "../../energy-integration/common-modules/energy-query" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" [dev-dependencies] num-bigint = "0.4.2" @@ -81,7 +82,7 @@ num-bigint = "0.4.2" path = "../../energy-integration/energy-update" [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" [dev-dependencies.energy-factory-mock] path = "../../energy-integration/energy-factory-mock" diff --git a/dex/farm/README.md b/dex/farm/README.md index 7a202719a..fcc860299 100644 --- a/dex/farm/README.md +++ b/dex/farm/README.md @@ -2,7 +2,7 @@ ## Abstract -Liquidity providers of Maiar Exchange are incentivized with MEX rewards in exchange for them locking their LP tokens in Farm contracts. +Liquidity providers of xExchange are incentivized with MEX rewards in exchange for them locking their LP tokens in Farm contracts. ## Introduction diff --git a/dex/farm/meta/Cargo.toml b/dex/farm/meta/Cargo.toml index ba2cff5c0..d6abd09e7 100644 --- a/dex/farm/meta/Cargo.toml +++ b/dex/farm/meta/Cargo.toml @@ -4,8 +4,10 @@ version = "0.0.0" authors = ["MultiversX "] edition = "2021" publish = false + [dependencies.farm] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/dex/farm/src/base_functions.rs b/dex/farm/src/base_functions.rs index 317ae4c1c..968e3381d 100644 --- a/dex/farm/src/base_functions.rs +++ b/dex/farm/src/base_functions.rs @@ -19,6 +19,8 @@ pub type DoubleMultiPayment = MultiValue2, EsdtTokenPayme pub type ClaimRewardsResultType = DoubleMultiPayment; pub type ExitFarmResultType = DoubleMultiPayment; +pub const DEFAULT_FARM_POSITION_MIGRATION_NONCE: u64 = 1; + pub struct ClaimRewardsResultWrapper { pub new_farm_token: EsdtTokenPayment, pub rewards: EsdtTokenPayment, @@ -73,7 +75,7 @@ pub trait BaseFunctionsModule: &self, caller: ManagedAddress, ) -> EsdtTokenPayment { - let payments = self.call_value().all_esdt_transfers(); + let payments = self.call_value().all_esdt_transfers().clone_value(); let base_enter_farm_result = self.enter_farm_base::(caller.clone(), payments); self.set_farm_supply_for_current_week( @@ -95,7 +97,7 @@ pub trait BaseFunctionsModule: &self, caller: ManagedAddress, ) -> ClaimRewardsResultWrapper { - let payments = self.call_value().all_esdt_transfers(); + let payments = self.call_value().all_esdt_transfers().clone_value(); let base_claim_rewards_result = self.claim_rewards_base::(caller.clone(), payments); let output_farm_token_payment = base_claim_rewards_result.new_farm_token.payment.clone(); @@ -124,7 +126,7 @@ pub trait BaseFunctionsModule: &self, caller: ManagedAddress, ) -> EsdtTokenPayment { - let payments = self.call_value().all_esdt_transfers(); + let payments = self.call_value().all_esdt_transfers().clone_value(); let base_compound_rewards_result = self.compound_rewards_base::(caller.clone(), payments); @@ -186,12 +188,57 @@ pub trait BaseFunctionsModule: 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 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) } + fn claim_only_boosted_payment(&self, caller: &ManagedAddress) -> BigUint { + let reward = Wrapper::::calculate_boosted_rewards(self, caller); + if reward > 0 { + self.reward_reserve().update(|reserve| *reserve -= &reward); + } + + reward + } + + fn migrate_old_farm_positions(&self, caller: &ManagedAddress) -> BigUint { + let payments = self.get_non_empty_payments(); + let farm_token_mapper = self.farm_token(); + let farm_token_id = farm_token_mapper.get_token_id(); + let mut migrated_amount = BigUint::zero(); + for farm_position in &payments { + if farm_position.token_identifier == farm_token_id + && self.is_old_farm_position(farm_position.token_nonce) + { + migrated_amount += farm_position.amount; + } + } + + if migrated_amount > 0 { + let mut user_total_farm_position = self.get_user_total_farm_position(caller); + user_total_farm_position.total_farm_position += &migrated_amount; + self.user_total_farm_position(caller) + .set(user_total_farm_position); + } + + migrated_amount + } + + fn decrease_old_farm_positions(&self, migrated_amount: BigUint, caller: &ManagedAddress) { + if migrated_amount == BigUint::zero() { + return; + } + self.user_total_farm_position(caller) + .update(|user_total_farm_position| { + user_total_farm_position.total_farm_position -= migrated_amount; + }); + } + fn end_produce_rewards>(&self) { let mut storage = StorageCache::new(self); FC::generate_aggregated_rewards(self, &mut storage); @@ -235,16 +282,11 @@ where pub fn calculate_boosted_rewards( sc: &::FarmSc, caller: &ManagedAddress<<::FarmSc as ContractBase>::Api>, - token_attributes: &::AttributesType, - farm_token_amount: BigUint<<::FarmSc as ContractBase>::Api>, ) -> BigUint<<::FarmSc as ContractBase>::Api> { - if &token_attributes.original_owner != caller { - sc.update_energy_and_progress(caller); + let user_total_farm_position = sc.get_user_total_farm_position(caller); + let user_farm_position = user_total_farm_position.total_farm_position; - return BigUint::zero(); - } - - sc.claim_boosted_yields_rewards(caller, farm_token_amount) + sc.claim_boosted_yields_rewards(caller, user_farm_position) } } @@ -288,12 +330,7 @@ where token_attributes, storage_cache, ); - let boosted_yield_rewards = Self::calculate_boosted_rewards( - sc, - caller, - token_attributes, - farm_token_amount.clone(), - ); + let boosted_yield_rewards = Self::calculate_boosted_rewards(sc, caller); base_farm_reward + boosted_yield_rewards } diff --git a/dex/farm/src/claim_boost_only.rs b/dex/farm/src/claim_boost_only.rs deleted file mode 100644 index 88d445df8..000000000 --- a/dex/farm/src/claim_boost_only.rs +++ /dev/null @@ -1,57 +0,0 @@ -multiversx_sc::imports!(); - -use crate::base_functions::Wrapper; - -#[multiversx_sc::module] -pub trait ClaimBoostOnlyModule: - config::ConfigModule - + rewards::RewardsModule - + farm_token::FarmTokenModule - + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule - + week_timekeeping::WeekTimekeepingModule - + pausable::PausableModule - + permissions_module::PermissionsModule - + 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 - + token_send::TokenSendModule - + events::EventsModule - + crate::exit_penalty::ExitPenaltyModule - + farm_base_impl::base_farm_init::BaseFarmInitModule - + farm_base_impl::base_farm_validation::BaseFarmValidationModule - + farm_base_impl::enter_farm::BaseEnterFarmModule - + farm_base_impl::claim_rewards::BaseClaimRewardsModule - + farm_base_impl::compound_rewards::BaseCompoundRewardsModule - + farm_base_impl::exit_farm::BaseExitFarmModule - + utils::UtilsModule - + farm_boosted_yields::FarmBoostedYieldsModule - + farm_boosted_yields::boosted_yields_factors::BoostedYieldsFactorsModule - + crate::base_functions::BaseFunctionsModule -{ - fn claim_only_boosted_payment( - &self, - caller: &ManagedAddress, - payment: &EsdtTokenPayment, - ) -> EsdtTokenPayment { - let farm_token_mapper = self.farm_token(); - farm_token_mapper.require_same_token(&payment.token_identifier); - - let token_attributes = - self.get_attributes_as_part_of_fixed_supply(payment, &farm_token_mapper); - let reward = Wrapper::::calculate_boosted_rewards( - self, - caller, - &token_attributes, - payment.amount.clone(), - ); - if reward > 0 { - self.reward_reserve().update(|reserve| *reserve -= &reward); - } - - let reward_token_id = self.reward_token_id().get(); - EsdtTokenPayment::new(reward_token_id, 0, reward) - } -} diff --git a/dex/farm/src/exit_penalty.rs b/dex/farm/src/exit_penalty.rs index 388a8b1f2..e8905fade 100644 --- a/dex/farm/src/exit_penalty.rs +++ b/dex/farm/src/exit_penalty.rs @@ -2,6 +2,7 @@ multiversx_sc::imports!(); use common_errors::ERROR_PARAMETERS; use common_structs::Epoch; +use pair::pair_actions::remove_liq::ProxyTrait as _; pub const MAX_PERCENT: u64 = 10_000; pub const DEFAULT_PENALTY_PERCENT: u64 = 100; diff --git a/dex/farm/src/lib.rs b/dex/farm/src/lib.rs index 34975a2a5..669dd2e50 100644 --- a/dex/farm/src/lib.rs +++ b/dex/farm/src/lib.rs @@ -6,9 +6,7 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); pub mod base_functions; -pub mod claim_boost_only; pub mod exit_penalty; -pub mod progress_update; use base_functions::{ClaimRewardsResultType, DoubleMultiPayment, Wrapper}; use common_structs::FarmTokenAttributes; @@ -18,11 +16,9 @@ use exit_penalty::{ DEFAULT_BURN_GAS_LIMIT, DEFAULT_MINUMUM_FARMING_EPOCHS, DEFAULT_PENALTY_PERCENT, }; use farm_base_impl::base_traits_impl::FarmContract; -use mergeable::Mergeable; pub type EnterFarmResultType = DoubleMultiPayment; -pub type ExitFarmWithPartialPosResultType = - MultiValue3, EsdtTokenPayment, EsdtTokenPayment>; +pub type ExitFarmWithPartialPosResultType = DoubleMultiPayment; #[multiversx_sc::contract] pub trait Farm: @@ -37,8 +33,6 @@ pub trait Farm: + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + base_functions::BaseFunctionsModule + exit_penalty::ExitPenaltyModule - + progress_update::ProgressUpdateModule - + claim_boost_only::ClaimBoostOnlyModule + farm_base_impl::base_farm_init::BaseFarmInitModule + farm_base_impl::base_farm_validation::BaseFarmValidationModule + farm_base_impl::enter_farm::BaseEnterFarmModule @@ -82,6 +76,20 @@ pub trait Farm: let current_epoch = self.blockchain().get_block_epoch(); self.first_week_start_epoch().set_if_empty(current_epoch); + + // Farm position migration code + let farm_token_mapper = self.farm_token(); + self.try_set_farm_position_migration_nonce(farm_token_mapper); + } + + #[endpoint] + fn upgrade(&self) { + let current_epoch = self.blockchain().get_block_epoch(); + self.first_week_start_epoch().set_if_empty(current_epoch); + + // Farm position migration code + let farm_token_mapper = self.farm_token(); + self.try_set_farm_position_migration_nonce(farm_token_mapper); } #[payable("*")] @@ -93,20 +101,18 @@ pub trait Farm: let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); - let payments = self.get_non_empty_payments(); - let first_additional_payment_index = 1; - let boosted_rewards = match payments.try_get(first_additional_payment_index) { - Some(p) => self.claim_only_boosted_payment(&orig_caller, &p), - None => EsdtTokenPayment::new(self.reward_token_id().get(), 0, BigUint::zero()), - }; + self.migrate_old_farm_positions(&orig_caller); + let boosted_rewards = self.claim_only_boosted_payment(&orig_caller); + let boosted_rewards_payment = + EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards); let new_farm_token = self.enter_farm::>(orig_caller.clone()); self.send_payment_non_zero(&caller, &new_farm_token); - self.send_payment_non_zero(&caller, &boosted_rewards); + self.send_payment_non_zero(&caller, &boosted_rewards_payment); self.update_energy_and_progress(&orig_caller); - (new_farm_token, boosted_rewards).into() + (new_farm_token, boosted_rewards_payment).into() } #[payable("*")] @@ -118,7 +124,10 @@ pub trait Farm: let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); + self.migrate_old_farm_positions(&orig_caller); + let claim_rewards_result = self.claim_rewards::>(orig_caller); + self.send_payment_non_zero(&caller, &claim_rewards_result.new_farm_token); self.send_payment_non_zero(&caller, &claim_rewards_result.rewards); @@ -134,9 +143,14 @@ pub trait Farm: let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); - let output_farm_token_payment = self.compound_rewards::>(orig_caller); + self.migrate_old_farm_positions(&orig_caller); + + let output_farm_token_payment = self.compound_rewards::>(orig_caller.clone()); + self.send_payment_non_zero(&caller, &output_farm_token_payment); + self.update_energy_and_progress(&orig_caller); + output_farm_token_payment } @@ -144,65 +158,25 @@ pub trait Farm: #[endpoint(exitFarm)] fn exit_farm_endpoint( &self, - exit_amount: BigUint, opt_orig_caller: OptionalValue, ) -> ExitFarmWithPartialPosResultType { let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); - let mut payment = self.call_value().single_esdt(); - require!( - payment.amount >= exit_amount, - "Exit amount is bigger than the payment amount" - ); + let payment = self.call_value().single_esdt(); - let boosted_rewards_full_position = self.claim_only_boosted_payment(&orig_caller, &payment); - let remaining_farm_payment = EsdtTokenPayment::new( - payment.token_identifier.clone(), - payment.token_nonce, - &payment.amount - &exit_amount, - ); + let migrated_amount = self.migrate_old_farm_positions(&orig_caller); - payment.amount = exit_amount; + let exit_farm_result = self.exit_farm::>(orig_caller.clone(), payment); - let mut exit_farm_result = self.exit_farm::>(orig_caller.clone(), payment); - exit_farm_result - .rewards - .merge_with(boosted_rewards_full_position); + self.decrease_old_farm_positions(migrated_amount, &orig_caller); self.send_payment_non_zero(&caller, &exit_farm_result.farming_tokens); self.send_payment_non_zero(&caller, &exit_farm_result.rewards); - self.send_payment_non_zero(&caller, &remaining_farm_payment); - self.clear_user_energy_if_needed(&orig_caller, &remaining_farm_payment.amount); + self.clear_user_energy_if_needed(&orig_caller); - ( - exit_farm_result.farming_tokens, - exit_farm_result.rewards, - remaining_farm_payment, - ) - .into() - } - - #[view(calculateRewardsForGivenPosition)] - fn calculate_rewards_for_given_position( - &self, - user: ManagedAddress, - farm_token_amount: BigUint, - attributes: FarmTokenAttributes, - ) -> BigUint { - self.require_queried(); - - let mut storage_cache = StorageCache::new(self); - Wrapper::::generate_aggregated_rewards(self, &mut storage_cache); - - Wrapper::::calculate_rewards( - self, - &user, - &farm_token_amount, - &attributes, - &storage_cache, - ) + (exit_farm_result.farming_tokens, exit_farm_result.rewards).into() } #[payable("*")] @@ -210,15 +184,47 @@ pub trait Farm: fn merge_farm_tokens_endpoint( &self, opt_orig_caller: OptionalValue, - ) -> EsdtTokenPayment { + ) -> DoubleMultiPayment { let caller = self.blockchain().get_caller(); let orig_caller = self.get_orig_caller_from_opt(&caller, opt_orig_caller); - self.check_claim_progress_for_merge(&orig_caller); + self.migrate_old_farm_positions(&orig_caller); + + let boosted_rewards = self.claim_only_boosted_payment(&orig_caller); + let boosted_rewards_payment = + EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards); let merged_farm_token = self.merge_farm_tokens::>(); self.send_payment_non_zero(&caller, &merged_farm_token); + self.send_payment_non_zero(&caller, &boosted_rewards_payment); - merged_farm_token + (merged_farm_token, boosted_rewards_payment).into() + } + + #[endpoint(claimBoostedRewards)] + fn claim_boosted_rewards( + &self, + opt_user: OptionalValue, + ) -> EsdtTokenPayment { + let caller = self.blockchain().get_caller(); + let user = match &opt_user { + OptionalValue::Some(user) => user, + OptionalValue::None => &caller, + }; + let user_total_farm_position = self.get_user_total_farm_position(user); + if user != &caller { + require!( + user_total_farm_position.allow_external_claim_boosted_rewards, + "Cannot claim rewards for this address" + ); + } + + let boosted_rewards = self.claim_only_boosted_payment(user); + let boosted_rewards_payment = + EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards); + + self.send_payment_non_zero(user, &boosted_rewards_payment); + + boosted_rewards_payment } #[endpoint(startProduceRewards)] @@ -238,4 +244,25 @@ pub trait Farm: self.require_caller_has_admin_permissions(); self.set_per_block_rewards::>(per_block_amount); } + + #[view(calculateRewardsForGivenPosition)] + fn calculate_rewards_for_given_position( + &self, + user: ManagedAddress, + farm_token_amount: BigUint, + attributes: FarmTokenAttributes, + ) -> BigUint { + self.require_queried(); + + let mut storage_cache = StorageCache::new(self); + Wrapper::::generate_aggregated_rewards(self, &mut storage_cache); + + Wrapper::::calculate_rewards( + self, + &user, + &farm_token_amount, + &attributes, + &storage_cache, + ) + } } diff --git a/dex/farm/src/progress_update.rs b/dex/farm/src/progress_update.rs deleted file mode 100644 index 48e4b7644..000000000 --- a/dex/farm/src/progress_update.rs +++ /dev/null @@ -1,27 +0,0 @@ -multiversx_sc::imports!(); - -#[multiversx_sc::module] -pub trait ProgressUpdateModule: - 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 - + utils::UtilsModule -{ - fn check_claim_progress_for_merge(&self, caller: &ManagedAddress) { - let claim_progress_mapper = self.current_claim_progress(caller); - if claim_progress_mapper.is_empty() { - return; - } - - let current_week = self.get_current_week(); - let claim_progress = claim_progress_mapper.get(); - require!( - claim_progress.week == current_week, - "The user claim progress must be up to date." - ) - } -} diff --git a/dex/farm/tests/energy_update_test.rs b/dex/farm/tests/energy_update_test.rs index d8dd4e639..1d8f78a98 100644 --- a/dex/farm/tests/energy_update_test.rs +++ b/dex/farm/tests/energy_update_test.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + mod farm_setup; use farm_setup::multi_user_farm_setup::*; diff --git a/dex/farm/tests/farm_multi_user_test.rs b/dex/farm/tests/farm_multi_user_test.rs index 45b388ba0..03315b184 100644 --- a/dex/farm/tests/farm_multi_user_test.rs +++ b/dex/farm/tests/farm_multi_user_test.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + use common_structs::FarmTokenAttributes; use multiversx_sc_scenario::{managed_address, managed_biguint, rust_biguint, DebugApi}; @@ -11,7 +13,7 @@ use weekly_rewards_splitting::global_info::WeeklyRewardsGlobalInfo; #[test] fn farm_with_no_boost_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = MultiUserFarmSetup::new( farm::contract_obj, energy_factory_mock::contract_obj, @@ -109,7 +111,7 @@ fn farm_with_no_boost_test() { #[test] fn farm_with_boosted_yields_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = MultiUserFarmSetup::new( farm::contract_obj, energy_factory_mock::contract_obj, @@ -147,7 +149,7 @@ fn farm_with_boosted_yields_test() { 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, 5, 1, 1); + farm_setup.exit_farm(&third_user, 5, 1); // advance 1 week farm_setup.b_mock.set_block_epoch(10); @@ -221,7 +223,7 @@ fn farm_with_boosted_yields_test() { #[test] fn farm_change_boosted_yields_factors_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = MultiUserFarmSetup::new( farm::contract_obj, energy_factory_mock::contract_obj, @@ -284,7 +286,7 @@ fn farm_change_boosted_yields_factors_test() { #[test] fn farm_boosted_yields_claim_with_different_user_pos_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = MultiUserFarmSetup::new( farm::contract_obj, energy_factory_mock::contract_obj, @@ -336,7 +338,7 @@ fn farm_boosted_yields_claim_with_different_user_pos_test() { 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, 5, 1, 1); + farm_setup.exit_farm(&third_user, 5, 1); // advance 1 week farm_setup.b_mock.set_block_epoch(10); @@ -361,11 +363,15 @@ fn farm_boosted_yields_claim_with_different_user_pos_test() { ); // second user claim with first user's pos - // user will only receive rewards for base farm, no boosted rewards + // user will receive both base and boosted rewards, as the claims uses his already saved total token amount let second_base_farm_amt = first_farm_token_amount * 7_500 / total_farm_tokens; + let second_boosted_rewards = 1_533; let second_receveived_reward_amt = farm_setup.claim_rewards(&second_user, 3, first_farm_token_amount); - assert_eq!(second_receveived_reward_amt, second_base_farm_amt); + assert_eq!( + second_receveived_reward_amt, + second_base_farm_amt + second_boosted_rewards + ); farm_setup .b_mock @@ -386,7 +392,7 @@ fn farm_boosted_yields_claim_with_different_user_pos_test() { #[test] fn farm_known_proxy_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = MultiUserFarmSetup::new( farm::contract_obj, energy_factory_mock::contract_obj, @@ -485,7 +491,7 @@ fn farm_known_proxy_test() { #[test] fn farm_multiple_claim_weeks_with_collect_undistributed_rewards_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = MultiUserFarmSetup::new( farm::contract_obj, energy_factory_mock::contract_obj, @@ -523,7 +529,7 @@ fn farm_multiple_claim_weeks_with_collect_undistributed_rewards_test() { 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, 5, 1, 1); + farm_setup.exit_farm(&third_user, 5, 1); // advance 1 week farm_setup.b_mock.set_block_epoch(10); @@ -604,7 +610,7 @@ fn farm_multiple_claim_weeks_with_collect_undistributed_rewards_test() { 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, 8, 1, 1); + farm_setup.exit_farm(&third_user, 8, 1); // advance blocks - 10 blocks - 10 * 1_000 = 10_000 total rewards // 7_500 base farm, 2_500 boosted yields @@ -616,7 +622,7 @@ fn farm_multiple_claim_weeks_with_collect_undistributed_rewards_test() { 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, 9, 1, 1); + farm_setup.exit_farm(&third_user, 9, 1); // advance week farm_setup.b_mock.set_block_epoch(22); @@ -735,7 +741,7 @@ fn farm_multiple_claim_weeks_with_collect_undistributed_rewards_test() { #[test] fn farm_enter_with_multiple_farm_token() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = MultiUserFarmSetup::new( farm::contract_obj, energy_factory_mock::contract_obj, @@ -773,7 +779,7 @@ fn farm_enter_with_multiple_farm_token() { 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, 5, 1, 1); + farm_setup.exit_farm(&third_user, 5, 1); // advance 1 week farm_setup.b_mock.set_block_epoch(10); @@ -850,7 +856,7 @@ fn farm_enter_with_multiple_farm_token() { #[test] fn farm_claim_with_minimum_tokens() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = MultiUserFarmSetup::new( farm::contract_obj, energy_factory_mock::contract_obj, @@ -888,7 +894,7 @@ fn farm_claim_with_minimum_tokens() { farm_setup.set_user_energy(&second_user, 90_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, 5, 1, 1); + farm_setup.exit_farm(&third_user, 5, 1); // advance 1 week farm_setup.b_mock.set_block_epoch(10); diff --git a/dex/farm/tests/farm_setup/farm_rewards_distr_setup.rs b/dex/farm/tests/farm_setup/farm_rewards_distr_setup.rs index 7b9672d4f..f39c3136e 100644 --- a/dex/farm/tests/farm_setup/farm_rewards_distr_setup.rs +++ b/dex/farm/tests/farm_setup/farm_rewards_distr_setup.rs @@ -1,11 +1,12 @@ #![allow(dead_code)] +#![allow(deprecated)] use multiversx_sc::codec::multi_types::OptionalValue; use multiversx_sc::storage::mappers::StorageTokenWrapper; use multiversx_sc::types::{Address, BigUint, EsdtLocalRole, ManagedAddress, MultiValueEncoded}; use multiversx_sc_scenario::{ - managed_address, managed_biguint, managed_token_id, rust_biguint, whitebox::TxTokenTransfer, - whitebox::*, DebugApi, + managed_address, managed_biguint, managed_token_id, rust_biguint, + whitebox_legacy::TxTokenTransfer, whitebox_legacy::*, DebugApi, }; pub type RustBigUint = num_bigint::BigUint; @@ -182,12 +183,11 @@ where &self.farm_wrapper, FARM_TOKEN_ID, farm_token_nonce, - &farm_out_amount.clone(), + &farm_out_amount, |sc| { - let exit_amount = to_managed_biguint(farm_out_amount); - let multi_result = sc.exit_farm_endpoint(exit_amount, OptionalValue::None); + let multi_result = sc.exit_farm_endpoint(OptionalValue::None); - let (first_result, second_result, _third_result) = multi_result.into_tuple(); + let (first_result, second_result) = multi_result.into_tuple(); assert_eq!( first_result.token_identifier, 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 aa669401e..2e74ab42c 100644 --- a/dex/farm/tests/farm_setup/multi_user_farm_setup.rs +++ b/dex/farm/tests/farm_setup/multi_user_farm_setup.rs @@ -1,16 +1,17 @@ #![allow(dead_code)] +#![allow(deprecated)] use common_structs::FarmTokenAttributes; -use config::ConfigModule; +use config::{ConfigModule, UserTotalFarmPosition}; use multiversx_sc::codec::multi_types::OptionalValue; use multiversx_sc::{ storage::mappers::StorageTokenWrapper, types::{Address, BigInt, EsdtLocalRole, MultiValueEncoded}, }; -use multiversx_sc_scenario::whitebox::TxTokenTransfer; +use multiversx_sc_scenario::whitebox_legacy::TxTokenTransfer; use multiversx_sc_scenario::{ managed_address, managed_biguint, managed_token_id, rust_biguint, - whitebox::{BlockchainStateWrapper, ContractObjWrapper}, + whitebox_legacy::{BlockchainStateWrapper, ContractObjWrapper}, DebugApi, }; @@ -23,6 +24,7 @@ use farm_boosted_yields::FarmBoostedYieldsModule; use farm_token::FarmTokenModule; use pausable::{PausableModule, State}; use sc_whitelist_module::SCWhitelistModule; +use week_timekeeping::Epoch; use weekly_rewards_splitting::update_claim_progress_energy::UpdateClaimProgressEnergyModule; pub static REWARD_TOKEN_ID: &[u8] = b"REW-123456"; @@ -38,6 +40,14 @@ pub const USER_REWARDS_FARM_CONST: u64 = 2; pub const MIN_ENERGY_AMOUNT_FOR_BOOSTED_YIELDS: u64 = 1; pub const MIN_FARM_AMOUNT_FOR_BOOSTED_YIELDS: u64 = 1; +pub struct RawFarmTokenAttributes { + pub reward_per_share_bytes: Vec, + pub entering_epoch: Epoch, + pub compounded_reward_bytes: Vec, + pub current_farm_amount_bytes: Vec, + pub original_owner_bytes: [u8; 32], +} + pub struct MultiUserFarmSetup where FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, @@ -325,7 +335,9 @@ where self.b_mock .execute_esdt_multi_transfer(user, &self.farm_wrapper, &payments, |sc| { - let out_farm_token = sc.merge_farm_tokens_endpoint(OptionalValue::None); + let (out_farm_token, _boosted_rewards) = sc + .merge_farm_tokens_endpoint(OptionalValue::None) + .into_tuple(); assert_eq!( out_farm_token.token_identifier, managed_token_id!(FARM_TOKEN_ID) @@ -346,12 +358,50 @@ where attributes: FarmTokenAttributes, ) -> u64 { let mut result = 0; + + let raw_attributes = RawFarmTokenAttributes { + reward_per_share_bytes: attributes + .reward_per_share + .to_bytes_be() + .as_slice() + .to_vec(), + entering_epoch: attributes.entering_epoch, + compounded_reward_bytes: attributes + .compounded_reward + .to_bytes_be() + .as_slice() + .to_vec(), + current_farm_amount_bytes: attributes + .current_farm_amount + .to_bytes_be() + .as_slice() + .to_vec(), + original_owner_bytes: attributes.original_owner.to_byte_array(), + }; + self.b_mock .execute_query(&self.farm_wrapper, |sc| { + let attributes_managed = FarmTokenAttributes { + reward_per_share: multiversx_sc::types::BigUint::::from_bytes_be( + &raw_attributes.reward_per_share_bytes, + ), + entering_epoch: raw_attributes.entering_epoch, + compounded_reward: multiversx_sc::types::BigUint::::from_bytes_be( + &raw_attributes.compounded_reward_bytes, + ), + current_farm_amount: multiversx_sc::types::BigUint::::from_bytes_be( + &raw_attributes.current_farm_amount_bytes, + ), + original_owner: + multiversx_sc::types::ManagedAddress::::new_from_bytes( + &raw_attributes.original_owner_bytes, + ), + }; + let result_managed = sc.calculate_rewards_for_given_position( managed_address!(user), managed_biguint!(farm_token_amount), - attributes, + attributes_managed, ); result = result_managed.to_u64().unwrap(); }) @@ -401,6 +451,39 @@ where result } + pub fn claim_boosted_rewards_for_user(&mut self, owner: &Address, broker: &Address) -> u64 { + self.last_farm_token_nonce += 1; + + let mut result = 0; + self.b_mock + .execute_tx(broker, &self.farm_wrapper, &rust_biguint!(0), |sc| { + let reward_payment = + sc.claim_boosted_rewards(OptionalValue::Some(managed_address!(owner))); + assert_eq!( + reward_payment.token_identifier, + managed_token_id!(REWARD_TOKEN_ID) + ); + assert_eq!(reward_payment.token_nonce, 0); + + result = reward_payment.amount.to_u64().unwrap(); + }) + .assert_ok(); + + result + } + + 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"); + } + pub fn claim_rewards_known_proxy( &mut self, user: &Address, @@ -444,25 +527,16 @@ where result } - pub fn exit_farm( - &mut self, - user: &Address, - farm_token_nonce: u64, - farm_token_amount: u64, - exit_farm_amount: u64, - ) { + pub fn exit_farm(&mut self, user: &Address, farm_token_nonce: u64, exit_farm_amount: u64) { self.b_mock .execute_esdt_transfer( user, &self.farm_wrapper, FARM_TOKEN_ID, farm_token_nonce, - &rust_biguint!(farm_token_amount), + &rust_biguint!(exit_farm_amount), |sc| { - let _ = sc.exit_farm_endpoint( - managed_biguint!(exit_farm_amount), - OptionalValue::None, - ); + let _ = sc.exit_farm_endpoint(OptionalValue::None); }, ) .assert_ok(); @@ -472,7 +546,6 @@ where &mut self, user: &Address, farm_token_nonce: u64, - farm_token_amount: u64, exit_farm_amount: u64, known_proxy: &Address, ) { @@ -482,17 +555,27 @@ where &self.farm_wrapper, FARM_TOKEN_ID, farm_token_nonce, - &rust_biguint!(farm_token_amount), + &rust_biguint!(exit_farm_amount), |sc| { - let _ = sc.exit_farm_endpoint( - managed_biguint!(exit_farm_amount), - OptionalValue::Some(managed_address!(user)), - ); + let _ = sc.exit_farm_endpoint(OptionalValue::Some(managed_address!(user))); }, ) .assert_ok(); } + pub fn allow_external_claim_rewards(&mut self, user: &Address, allow_external_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 = + allow_external_claim; + }, + ); + }) + .assert_ok(); + } + pub fn update_energy_for_user(&mut self) { let b_mock = &mut self.b_mock; let user_addr = &self.first_user; @@ -567,4 +650,45 @@ where }) .assert_ok(); } + + pub fn check_farm_token_supply(&mut self, expected_farm_token_supply: u64) { + let b_mock = &mut self.b_mock; + b_mock + .execute_query(&self.farm_wrapper, |sc| { + let actual_farm_supply = sc.farm_token_supply().get(); + assert_eq!( + managed_biguint!(expected_farm_token_supply), + actual_farm_supply + ); + }) + .assert_ok(); + } + + pub fn set_user_total_farm_position(&mut self, user_addr: &Address, new_farm_position: u64) { + self.b_mock + .execute_tx(&self.owner, &self.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_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(); + } } diff --git a/dex/farm/tests/farm_setup/single_user_farm_setup.rs b/dex/farm/tests/farm_setup/single_user_farm_setup.rs index 6ec061758..4fb48c955 100644 --- a/dex/farm/tests/farm_setup/single_user_farm_setup.rs +++ b/dex/farm/tests/farm_setup/single_user_farm_setup.rs @@ -1,12 +1,13 @@ #![allow(dead_code)] +#![allow(deprecated)] use common_structs::FarmTokenAttributes; -use multiversx_sc::codec::multi_types::OptionalValue; +use multiversx_sc::codec::multi_types::{MultiValue3, OptionalValue}; use multiversx_sc::storage::mappers::StorageTokenWrapper; use multiversx_sc::types::{Address, EsdtLocalRole, ManagedAddress, MultiValueEncoded}; -use multiversx_sc_scenario::whitebox::{TxContextStack, TxTokenTransfer}; +use multiversx_sc_scenario::whitebox_legacy::{TxContextStack, TxTokenTransfer}; use multiversx_sc_scenario::{ - managed_address, managed_biguint, managed_token_id, rust_biguint, whitebox::*, DebugApi, + managed_address, managed_biguint, managed_token_id, rust_biguint, whitebox_legacy::*, DebugApi, }; type RustBigUint = num_bigint::BigUint; @@ -16,9 +17,12 @@ use farm::exit_penalty::ExitPenaltyModule; use farm::*; use farm_boosted_yields::boosted_yields_factors::BoostedYieldsFactorsModule; use farm_token::FarmTokenModule; +use pair::pair_actions::add_liq::AddLiquidityModule as _; +use pair::{config::ConfigModule as OtherConfigModule, Pair}; use pausable::{PausableModule, State}; pub const FARM_WASM_PATH: &str = "farm/output/farm.wasm"; +pub const PAIR_WASM_PATH: &str = "pair/output/pair.wasm"; pub const WEGLD_TOKEN_ID: &[u8] = b"WEGLD-abcdef"; pub const MEX_TOKEN_ID: &[u8] = b"MEX-abcdef"; // reward token ID @@ -35,25 +39,74 @@ pub const USER_REWARDS_ENERGY_CONST: u64 = 3; pub const USER_REWARDS_FARM_CONST: u64 = 2; pub const MIN_ENERGY_AMOUNT_FOR_BOOSTED_YIELDS: u64 = 1; pub const MIN_FARM_AMOUNT_FOR_BOOSTED_YIELDS: u64 = 1; +pub const LOCKED_TOKEN_ID: &[u8] = b"XMEX-123456"; +pub const LOCKED_LP_TOKEN_ID: &[u8] = b"LKLP-123456"; +pub const FARM_PROXY_TOKEN_ID: &[u8] = b"PROXY-123456"; -pub struct SingleUserFarmSetup +pub struct SingleUserFarmSetup where FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, + PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, { pub blockchain_wrapper: BlockchainStateWrapper, pub owner_address: Address, pub user_address: Address, pub farm_wrapper: ContractObjWrapper, FarmObjBuilder>, + pub pair_wrapper: ContractObjWrapper, PairObjBuilder>, } -impl SingleUserFarmSetup +impl SingleUserFarmSetup where FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, + PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, { - pub fn new(farm_builder: FarmObjBuilder) -> Self { + pub fn new(farm_builder: FarmObjBuilder, pair_builder: PairObjBuilder) -> Self { let rust_zero = rust_biguint!(0u64); let mut blockchain_wrapper = BlockchainStateWrapper::new(); let owner_addr = blockchain_wrapper.create_user_account(&rust_zero); + + let pair_wrapper = blockchain_wrapper.create_sc_account( + &rust_zero, + Some(&owner_addr), + pair_builder, + PAIR_WASM_PATH, + ); + + // init pair contract + blockchain_wrapper + .execute_tx(&owner_addr, &pair_wrapper, &rust_zero, |sc| { + let first_token_id = managed_token_id!(WEGLD_TOKEN_ID); + let second_token_id = managed_token_id!(MEX_TOKEN_ID); + let router_address = managed_address!(&owner_addr); + let router_owner_address = managed_address!(&owner_addr); + let total_fee_percent = 300u64; + let special_fee_percent = 50u64; + + sc.init( + first_token_id, + second_token_id, + router_address, + router_owner_address, + total_fee_percent, + special_fee_percent, + ManagedAddress::::zero(), + MultiValueEncoded::>::new(), + ); + + let lp_token_id = managed_token_id!(LP_TOKEN_ID); + sc.lp_token_identifier().set(&lp_token_id); + + sc.state().set(State::Active); + }) + .assert_ok(); + + let lp_token_roles = [EsdtLocalRole::Mint, EsdtLocalRole::Burn]; + blockchain_wrapper.set_esdt_local_roles( + pair_wrapper.address_ref(), + LP_TOKEN_ID, + &lp_token_roles[..], + ); + let farm_wrapper = blockchain_wrapper.create_sc_account( &rust_zero, Some(&owner_addr), @@ -141,9 +194,52 @@ where owner_address: owner_addr, user_address: user_addr, farm_wrapper, + pair_wrapper, } } + #[allow(clippy::too_many_arguments)] + pub fn add_liquidity( + &mut self, + first_token_amount: u64, + first_token_min: u64, + second_token_amount: u64, + second_token_min: u64, + ) { + let payments = vec![ + TxTokenTransfer { + token_identifier: WEGLD_TOKEN_ID.to_vec(), + nonce: 0, + value: rust_biguint!(first_token_amount), + }, + TxTokenTransfer { + token_identifier: LOCKED_TOKEN_ID.to_vec(), + nonce: 0, + value: rust_biguint!(second_token_amount), + }, + ]; + + self.blockchain_wrapper + .execute_esdt_multi_transfer(&self.user_address, &self.pair_wrapper, &payments, |sc| { + let MultiValue3 { 0: payments } = sc.add_liquidity( + managed_biguint!(first_token_min), + managed_biguint!(second_token_min), + ); + + assert_eq!(payments.0.token_identifier, managed_token_id!(LP_TOKEN_ID)); + + assert_eq!( + payments.1.token_identifier, + managed_token_id!(WEGLD_TOKEN_ID) + ); + assert_eq!( + payments.2.token_identifier, + managed_token_id!(LOCKED_TOKEN_ID) + ); + }) + .assert_ok(); + } + pub fn enter_farm( &mut self, farm_in_amount: u64, @@ -183,7 +279,7 @@ where }) .assert_ok(); - let _ = DebugApi::dummy(); + DebugApi::dummy(); let expected_attributes = FarmTokenAttributes:: { reward_per_share: managed_biguint!(expected_reward_per_share), @@ -221,13 +317,9 @@ where farm_token_nonce, &rust_biguint!(farm_token_amount), |sc| { - let multi_result = sc.exit_farm_endpoint( - managed_biguint!(farm_token_amount), - OptionalValue::None, - ); + let multi_result = sc.exit_farm_endpoint(OptionalValue::None); - let (first_result, second_result, remaining_farm_amount) = - multi_result.into_tuple(); + let (first_result, second_result) = multi_result.into_tuple(); assert_eq!( first_result.token_identifier, @@ -245,7 +337,6 @@ where ); assert_eq!(second_result.token_nonce, 0); assert_eq!(second_result.amount, managed_biguint!(expected_mex_out)); - assert_eq!(remaining_farm_amount.amount, managed_biguint!(0)); }, ) .assert_ok(); @@ -299,7 +390,7 @@ where ) .assert_ok(); - let _ = DebugApi::dummy(); + DebugApi::dummy(); let expected_attributes = FarmTokenAttributes:: { reward_per_share: managed_biguint!(expected_reward_per_share), entering_epoch: 0, diff --git a/dex/farm/tests/farm_single_user_test.rs b/dex/farm/tests/farm_single_user_test.rs index a928eecb6..e060fbbdf 100644 --- a/dex/farm/tests/farm_single_user_test.rs +++ b/dex/farm/tests/farm_single_user_test.rs @@ -1,22 +1,24 @@ +#![allow(deprecated)] + mod farm_setup; use config::ConfigModule; use farm_setup::single_user_farm_setup::*; use multiversx_sc::types::EsdtLocalRole; use multiversx_sc_scenario::{ - managed_address, managed_biguint, managed_token_id, rust_biguint, whitebox::TxTokenTransfer, - DebugApi, + managed_address, managed_biguint, managed_token_id, rust_biguint, + whitebox_legacy::TxTokenTransfer, DebugApi, }; use sc_whitelist_module::SCWhitelistModule; #[test] fn test_farm_setup() { - let _ = SingleUserFarmSetup::new(farm::contract_obj); + let _ = SingleUserFarmSetup::new(farm::contract_obj, pair::contract_obj); } #[test] fn test_enter_farm() { - let mut farm_setup = SingleUserFarmSetup::new(farm::contract_obj); + let mut farm_setup = SingleUserFarmSetup::new(farm::contract_obj, pair::contract_obj); let farm_in_amount = 100_000_000; let expected_farm_token_nonce = 1; @@ -26,7 +28,7 @@ fn test_enter_farm() { #[test] fn test_exit_farm() { - let mut farm_setup = SingleUserFarmSetup::new(farm::contract_obj); + let mut farm_setup = SingleUserFarmSetup::new(farm::contract_obj, pair::contract_obj); let farm_in_amount = 100_000_000; let expected_farm_token_nonce = 1; @@ -51,7 +53,7 @@ fn test_exit_farm() { #[test] fn test_exit_farm_with_penalty() { - let mut farm_setup = SingleUserFarmSetup::new(farm::contract_obj); + let mut farm_setup = SingleUserFarmSetup::new(farm::contract_obj, pair::contract_obj); let farm_in_amount = 100_000_000; let expected_farm_token_nonce = 1; @@ -79,7 +81,7 @@ fn test_exit_farm_with_penalty() { #[test] fn test_claim_rewards() { - let mut farm_setup = SingleUserFarmSetup::new(farm::contract_obj); + let mut farm_setup = SingleUserFarmSetup::new(farm::contract_obj, pair::contract_obj); let farm_in_amount = 100_000_000; let expected_farm_token_nonce = 1; @@ -104,13 +106,15 @@ fn test_claim_rewards() { farm_setup.check_farm_token_supply(farm_in_amount); } -fn steps_enter_farm_twice( +fn steps_enter_farm_twice( farm_builder: FarmObjBuilder, -) -> SingleUserFarmSetup + pair_builder: PairObjBuilder, +) -> SingleUserFarmSetup where FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, + PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, { - let mut farm_setup = SingleUserFarmSetup::new(farm_builder); + let mut farm_setup = SingleUserFarmSetup::new(farm_builder, pair_builder); let farm_in_amount = 100_000_000; let expected_farm_token_nonce = 1; @@ -153,12 +157,12 @@ where #[test] fn test_enter_farm_twice() { - let _ = steps_enter_farm_twice(farm::contract_obj); + let _ = steps_enter_farm_twice(farm::contract_obj, pair::contract_obj); } #[test] fn test_exit_farm_after_enter_twice() { - let mut farm_setup = steps_enter_farm_twice(farm::contract_obj); + let mut farm_setup = steps_enter_farm_twice(farm::contract_obj, pair::contract_obj); let farm_in_amount = 100_000_000; let second_farm_in_amount = 200_000_000; let total_farm_token = farm_in_amount + second_farm_in_amount; @@ -207,9 +211,9 @@ fn test_farm_through_simple_lock() { const LOCKED_LP_TOKEN_ID: &[u8] = b"LKLP-123456"; const FARM_PROXY_TOKEN_ID: &[u8] = b"PROXY-123456"; - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0); - let mut farm_setup = SingleUserFarmSetup::new(farm::contract_obj); + let mut farm_setup = SingleUserFarmSetup::new(farm::contract_obj, pair::contract_obj); let b_mock = &mut farm_setup.blockchain_wrapper; // setup simple lock SC @@ -394,7 +398,7 @@ fn test_farm_through_simple_lock() { 2, &rust_biguint!(1_000_000_000), |sc| { - let exit_farm_result = sc.exit_farm_locked_token(managed_biguint!(1_000_000_000)); + let exit_farm_result = sc.exit_farm_locked_token(); let (locked_tokens, reward_tokens) = exit_farm_result.into_tuple(); assert_eq!( @@ -592,7 +596,7 @@ fn test_farm_through_simple_lock() { 7, &rust_biguint!(1_000_000_000), |sc| { - let exit_farm_result = sc.exit_farm_locked_token(managed_biguint!(1_000_000_000)); + let exit_farm_result = sc.exit_farm_locked_token(); let (locked_tokens, _reward_tokens) = exit_farm_result.into_tuple(); assert_eq!( diff --git a/dex/farm/tests/total_farm_position_test.rs b/dex/farm/tests/total_farm_position_test.rs new file mode 100644 index 000000000..26756ebaa --- /dev/null +++ b/dex/farm/tests/total_farm_position_test.rs @@ -0,0 +1,562 @@ +#![allow(deprecated)] + +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}; + +#[test] +fn total_farm_position_claim_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); + + let temp_user = farm_setup.third_user.clone(); + + // first user enter farm + let farm_in_amount = 50_000_000; + let first_user = farm_setup.first_user.clone(); + farm_setup.set_user_energy(&first_user, 1_000, 2, 1); + farm_setup.enter_farm(&first_user, farm_in_amount); + farm_setup.enter_farm(&first_user, farm_in_amount); + + farm_setup.b_mock.check_nft_balance( + &first_user, + FARM_TOKEN_ID, + 1, + &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!(&first_user), + }), + ); + + farm_setup.b_mock.check_nft_balance( + &first_user, + FARM_TOKEN_ID, + 2, + &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!(&first_user), + }), + ); + + farm_setup.check_farm_token_supply(farm_in_amount * 2); + + // users claim rewards to get their energy registered + let _ = farm_setup.claim_rewards(&first_user, 1, 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(&first_user, 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(&first_user, 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(&first_user, 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::>( + &first_user, + FARM_TOKEN_ID, + 5, + &rust_biguint!(farm_in_amount), + None, + ); + + farm_setup.b_mock.check_esdt_balance( + &first_user, + REWARD_TOKEN_ID, + &rust_biguint!(first_received_reward_amt), + ); +} + +#[test] +fn allow_external_claim_rewards_setting_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 first_farm_token_amount = 100_000_000; + let first_user = farm_setup.first_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, first_farm_token_amount); + + // users claim rewards to get their energy registered + let _ = farm_setup.claim_rewards(&first_user, 1, first_farm_token_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(&first_user, 1_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, 3, 1); + + // advance 1 week + farm_setup.b_mock.set_block_epoch(10); + farm_setup.set_user_energy(&first_user, 1_000, 10, 1); + + let first_boosted_amt = 2500; + + // Second user claim boosted rewards for first user + farm_setup.allow_external_claim_rewards(&first_user, true); + + let first_received_boosted_amt = + farm_setup.claim_boosted_rewards_for_user(&first_user, &third_user); + assert_eq!(first_received_boosted_amt, first_boosted_amt); + + // First user should receive the boosted rewards + farm_setup.b_mock.check_esdt_balance( + &first_user, + REWARD_TOKEN_ID, + &rust_biguint!(first_received_boosted_amt), + ); + + // User who called the claim function should not receive anything + farm_setup + .b_mock + .check_esdt_balance(&third_user, REWARD_TOKEN_ID, &rust_biguint!(0)); + + // Check allow external claim is set to false + farm_setup.allow_external_claim_rewards(&first_user, false); + + farm_setup.claim_boosted_rewards_for_user_expect_error(&first_user, &third_user); +} + +#[test] +fn total_farm_position_claim_for_other_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 first_farm_token_amount = 100_000_000; + let first_user = farm_setup.first_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, first_farm_token_amount); + + // second user enter farm + let second_farm_token_amount = 50_000_000; + let second_user = farm_setup.second_user.clone(); + farm_setup.set_user_energy(&second_user, 4_000, 2, 1); + farm_setup.enter_farm(&second_user, second_farm_token_amount); + + // users claim rewards to get their energy registered + let _ = farm_setup.claim_rewards(&first_user, 1, first_farm_token_amount); + let _ = farm_setup.claim_rewards(&second_user, 2, second_farm_token_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(&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, 5, 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 for himself + let total_farm_tokens = first_farm_token_amount + second_farm_token_amount; + let second_base_farm_amt = second_farm_token_amount * 7_500 / total_farm_tokens; + let second_boosted_amt = 1533; // 4000 energy & 50_000_000 farm tokens + let second_total = second_base_farm_amt + second_boosted_amt; + + let second_received_reward_amt = + farm_setup.claim_rewards(&second_user, 4, second_farm_token_amount); + assert_eq!(second_received_reward_amt, second_total); + + farm_setup + .b_mock + .check_nft_balance::>( + &second_user, + FARM_TOKEN_ID, + 6, + &rust_biguint!(second_farm_token_amount), + None, + ); + + farm_setup.b_mock.check_esdt_balance( + &second_user, + REWARD_TOKEN_ID, + &rust_biguint!(second_received_reward_amt), + ); + + // 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) + // (2500 * 3 * 1_000 / 5_000 + 2500 * 2 * 100_000_000 / 150_000_000) / (3 + 2) + // (1500 + 3333) / (5) = 966 + let first_boosted_amt = 966; // 1000 energy & 100_000_000 farm tokens + + // Second user claim boosted rewards for first user + farm_setup.allow_external_claim_rewards(&first_user, true); + + let first_received_boosted_amt = + farm_setup.claim_boosted_rewards_for_user(&first_user, &second_user); + assert_eq!(first_received_boosted_amt, first_boosted_amt); + + // First user should receive the boosted rewards + farm_setup.b_mock.check_esdt_balance( + &first_user, + REWARD_TOKEN_ID, + &rust_biguint!(first_received_boosted_amt), + ); + + // Second user has the same amount of reward tokens + farm_setup.b_mock.check_esdt_balance( + &second_user, + REWARD_TOKEN_ID, + &rust_biguint!(second_received_reward_amt), + ); +} + +#[test] +fn farm_total_position_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); + + let temp_user = farm_setup.third_user.clone(); + + // first user enter farm + let farm_in_amount = 50_000_000; + let first_user = farm_setup.first_user.clone(); + farm_setup.set_user_energy(&first_user, 1_000, 2, 1); + 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); + + // users claim rewards to get their energy registered + let _ = farm_setup.claim_rewards(&first_user, 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(&first_user, 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(&first_user, 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; + + let first_boosted_amt = 2_000; // claim boosted with only half total position - not full rewards + let first_total_rewards = first_base_farm_amt + first_boosted_amt; + + let first_received_reward_amt = farm_setup.claim_rewards(&first_user, 3, farm_in_amount); + + // Should be equal to half base generated rewards + partial boosted generated rewards + assert_eq!(first_received_reward_amt, first_total_rewards); + + farm_setup + .b_mock + .check_nft_balance::>( + &first_user, + FARM_TOKEN_ID, + 5, + &rust_biguint!(farm_in_amount), + None, + ); + + farm_setup.b_mock.check_esdt_balance( + &first_user, + REWARD_TOKEN_ID, + &rust_biguint!(first_received_reward_amt), + ); + + // advance 10 more blocks - 10_000 more total rewards + // 7_500 base farm, 2_500 boosted yields + farm_setup.b_mock.set_block_nonce(20); + + // random tx on end of week 2, to cummulate rewards + farm_setup.b_mock.set_block_epoch(13); + farm_setup.set_user_energy(&first_user, 1_000, 13, 1); + farm_setup.set_user_energy(&temp_user, 1, 13, 1); + farm_setup.enter_farm(&temp_user, 1); + farm_setup.exit_farm(&temp_user, 6, 1); + + // advance 1 week + farm_setup.b_mock.set_block_epoch(20); + farm_setup.set_user_energy(&first_user, 1_000, 20, 1); + + // user claims with old position - should migrate his entire position + let second_received_reward_amt = farm_setup.claim_rewards(&first_user, 1, farm_in_amount); + + farm_setup.check_user_total_farm_position(&first_user, farm_in_amount * 2); + + let second_base_farm_amt = (farm_in_amount * 7_500 / total_farm_tokens) * 2; // user claims with initial position (2 weeks worth of rewards) + let second_boosted_amt = 2_500; // claim boosted with entire total position - receives full rewards + let second_total_rewards = second_base_farm_amt + second_boosted_amt; + assert_eq!(second_received_reward_amt, second_total_rewards); +} + +#[test] +fn farm_total_position_exit_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); + + let temp_user = farm_setup.third_user.clone(); + + // first user enter farm + let farm_in_amount = 50_000_000; + let first_user = farm_setup.first_user.clone(); + farm_setup.set_user_energy(&first_user, 1_000, 2, 1); + 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); + + // users claim rewards to get their energy registered + let _ = farm_setup.claim_rewards(&first_user, 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(&first_user, 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(&first_user, 1_000, 10, 1); + + // first user exist farm with old position + farm_setup.exit_farm(&first_user, 1, farm_in_amount); + + // user farm position should be unchanged + farm_setup.check_user_total_farm_position(&first_user, farm_in_amount); + + // User should receive half base rewards and full boosted rewards + let total_farm_tokens = farm_in_amount * 2; + let first_base_farm_amt = farm_in_amount * 7_500 / total_farm_tokens; + let first_boosted_amt = 2_500; + let first_total_rewards = first_base_farm_amt + first_boosted_amt; + farm_setup.b_mock.check_esdt_balance( + &first_user, + REWARD_TOKEN_ID, + &rust_biguint!(first_total_rewards), + ); +} + +#[test] +fn no_boosted_rewards_penalty_for_no_energy_test() { + DebugApi::dummy(); + 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(5); + + let temp_user = farm_setup.third_user.clone(); + + // first user enter farm + let farm_in_amount = 50_000_000; + let first_user = farm_setup.first_user.clone(); + farm_setup.set_user_energy(&first_user, 1_000, 5, 1); + farm_setup.enter_farm(&first_user, farm_in_amount); + farm_setup.enter_farm(&first_user, farm_in_amount); + + // users claim rewards to get their energy registered + let _ = farm_setup.claim_rewards(&first_user, 2, farm_in_amount); + + // advance to week 1 + + // 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 the week, to cummulate rewards + farm_setup.b_mock.set_block_epoch(6); + farm_setup.set_user_energy(&first_user, 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 to week 2 + farm_setup.b_mock.set_block_nonce(20); + farm_setup.b_mock.set_block_epoch(13); + + // User unlocks XMEX and has no energy + farm_setup.set_user_energy(&first_user, 0, 13, 1); + + // random tx on end of the week, to cummulate rewards + farm_setup.set_user_energy(&temp_user, 1, 13, 1); + farm_setup.enter_farm(&temp_user, 1); + farm_setup.exit_farm(&temp_user, 5, 1); + + // advance to week 3 + farm_setup.b_mock.set_block_nonce(30); + + // random tx on end of the week, to cummulate rewards + farm_setup.b_mock.set_block_epoch(20); + farm_setup.set_user_energy(&temp_user, 1, 20, 1); + farm_setup.enter_farm(&temp_user, 1); + farm_setup.exit_farm(&temp_user, 6, 1); + + // advance to week 4 + farm_setup.b_mock.set_block_epoch(25); + + // first user claims 3 weeks worth of rewards (2-4) + let total_farm_tokens = farm_in_amount * 2; + let first_base_farm_amt = (farm_in_amount * 7_500 / total_farm_tokens) * 3; + let first_boosted_amt = 2_500 * 3; + let first_total_rewards = first_base_farm_amt + first_boosted_amt; + + let first_receveived_reward_amt = farm_setup.claim_rewards(&first_user, 1, farm_in_amount); + + // Should be equal to half base generated rewards + full boosted generated rewards + assert_eq!(first_receveived_reward_amt, first_total_rewards); + + farm_setup.b_mock.check_esdt_balance( + &first_user, + REWARD_TOKEN_ID, + &rust_biguint!(first_receveived_reward_amt), + ); +} diff --git a/dex/farm/wasm/Cargo.lock b/dex/farm/wasm/Cargo.lock index 97ea7e292..2308d9073 100644 --- a/dex/farm/wasm/Cargo.lock +++ b/dex/farm/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common-types" @@ -99,9 +76,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "endian-type" @@ -253,15 +230,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -270,9 +238,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "itertools" @@ -292,12 +260,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - [[package]] name = "locking_module" version = "0.0.0" @@ -314,12 +276,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -329,12 +285,11 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -343,20 +298,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -366,9 +320,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -379,21 +333,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -407,19 +360,13 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "pair" version = "0.0.0" @@ -433,6 +380,7 @@ dependencies = [ "permissions_module", "simple-lock", "token_send", + "utils", ] [[package]] @@ -454,18 +402,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -514,15 +462,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -548,9 +496,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -569,24 +517,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - [[package]] name = "week-timekeeping" version = "0.0.0" @@ -606,25 +536,3 @@ dependencies = [ "unwrappable", "week-timekeeping", ] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/dex/farm/wasm/Cargo.toml b/dex/farm/wasm/Cargo.toml index 61e5f6174..26ce2670b 100644 --- a/dex/farm/wasm/Cargo.toml +++ b/dex/farm/wasm/Cargo.toml @@ -1,26 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "farm-wasm" version = "0.0.0" -authors = ["MultiversX "] edition = "2021" publish = false [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.farm] -default-features = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/dex/farm/wasm/src/lib.rs b/dex/farm/wasm/src/lib.rs index 9ec1c0a1c..de7b89ee5 100644 --- a/dex/farm/wasm/src/lib.rs +++ b/dex/farm/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 59 +// Endpoints: 65 // Async Callback: 1 -// Total number of exported functions: 61 +// Total number of exported functions: 67 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,65 +19,73 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { farm ( - enterFarm - claimRewards - compoundRewards - exitFarm - calculateRewardsForGivenPosition - mergeFarmTokens - startProduceRewards - endProduceRewards - setPerBlockRewardAmount - getRewardPerShare - getRewardReserve - getFarmingTokenId - getRewardTokenId - getPerBlockRewardAmount - getLastRewardBlockNonce - getDivisionSafetyConstant - registerFarmToken - getFarmTokenId - getFarmTokenSupply - addToPauseWhitelist - removeFromPauseWhitelist - pause - resume - getState - addAdmin - removeAdmin - updateOwnerOrAdmin - getPermissions - addSCAddressToWhitelist - removeSCAddressFromWhitelist - isSCAddressWhitelisted - set_penalty_percent - set_minimum_farming_epochs - set_burn_gas_limit - getPenaltyPercent - getMinimumFarmingEpoch - getBurnGasLimit - getPairContractManagedAddress - setBoostedYieldsRewardsPercentage - collectUndistributedBoostedRewards - getBoostedYieldsRewardsPercentage - getAccumulatedRewardsForWeek - getFarmSupplyForWeek - getRemainingBoostedRewardsToDistribute - getUndistributedBoostedRewards - setBoostedYieldsFactors - getBoostedYieldsFactors - getCurrentWeek - getFirstWeekStartEpoch - getLastActiveWeekForUser - getUserEnergyForWeek - getLastGlobalUpdateWeek - getTotalRewardsForWeek - getTotalEnergyForWeek - getTotalLockedTokensForWeek - updateEnergyForUser - getCurrentClaimProgress - setEnergyFactoryAddress - getEnergyFactoryAddress - callBack + init => init + upgrade => upgrade + enterFarm => enter_farm_endpoint + claimRewards => claim_rewards_endpoint + compoundRewards => compound_rewards_endpoint + exitFarm => exit_farm_endpoint + mergeFarmTokens => merge_farm_tokens_endpoint + claimBoostedRewards => claim_boosted_rewards + startProduceRewards => start_produce_rewards_endpoint + endProduceRewards => end_produce_rewards_endpoint + setPerBlockRewardAmount => set_per_block_rewards_endpoint + calculateRewardsForGivenPosition => calculate_rewards_for_given_position + getRewardPerShare => reward_per_share + getRewardReserve => reward_reserve + allowExternalClaimBoostedRewards => allow_external_claim_boosted_rewards + getAllowExternalClaimRewards => get_allow_external_claim_rewards + getFarmingTokenId => farming_token_id + getRewardTokenId => reward_token_id + getPerBlockRewardAmount => per_block_reward_amount + getLastRewardBlockNonce => last_reward_block_nonce + getDivisionSafetyConstant => division_safety_constant + getUserTotalFarmPosition => user_total_farm_position + getFarmPositionMigrationNonce => farm_position_migration_nonce + registerFarmToken => register_farm_token + getFarmTokenId => farm_token + getFarmTokenSupply => farm_token_supply + addToPauseWhitelist => add_to_pause_whitelist + removeFromPauseWhitelist => remove_from_pause_whitelist + pause => pause + resume => resume + getState => state + addAdmin => add_admin_endpoint + removeAdmin => remove_admin_endpoint + updateOwnerOrAdmin => update_owner_or_admin_endpoint + getPermissions => permissions + addSCAddressToWhitelist => add_sc_address_to_whitelist + removeSCAddressFromWhitelist => remove_sc_address_from_whitelist + isSCAddressWhitelisted => is_sc_address_whitelisted + set_penalty_percent => set_penalty_percent + set_minimum_farming_epochs => set_minimum_farming_epochs + set_burn_gas_limit => set_burn_gas_limit + getPenaltyPercent => penalty_percent + getMinimumFarmingEpoch => minimum_farming_epochs + getBurnGasLimit => burn_gas_limit + getPairContractManagedAddress => pair_contract_address + setBoostedYieldsRewardsPercentage => set_boosted_yields_rewards_percentage + collectUndistributedBoostedRewards => collect_undistributed_boosted_rewards + getBoostedYieldsRewardsPercentage => boosted_yields_rewards_percentage + getAccumulatedRewardsForWeek => accumulated_rewards_for_week + getFarmSupplyForWeek => farm_supply_for_week + getRemainingBoostedRewardsToDistribute => remaining_boosted_rewards_to_distribute + getUndistributedBoostedRewards => undistributed_boosted_rewards + setBoostedYieldsFactors => set_boosted_yields_factors + getBoostedYieldsFactors => get_boosted_yields_factors + getCurrentWeek => get_current_week + getFirstWeekStartEpoch => first_week_start_epoch + getLastActiveWeekForUser => get_last_active_week_for_user_view + getUserEnergyForWeek => get_user_energy_for_week_view + getLastGlobalUpdateWeek => last_global_update_week + getTotalRewardsForWeek => total_rewards_for_week + getTotalEnergyForWeek => total_energy_for_week + getTotalLockedTokensForWeek => total_locked_tokens_for_week + updateEnergyForUser => update_energy_for_user + getCurrentClaimProgress => current_claim_progress + setEnergyFactoryAddress => set_energy_factory_address + getEnergyFactoryAddress => energy_factory_address ) } + +multiversx_sc_wasm_adapter::async_callback! { farm } diff --git a/dex/farm_v1_2_mock/wasm/Cargo.lock b/dex/farm_v1_2_mock/wasm/Cargo.lock deleted file mode 100644 index ac237c601..000000000 --- a/dex/farm_v1_2_mock/wasm/Cargo.lock +++ /dev/null @@ -1,276 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "ahash" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - -[[package]] -name = "arrayvec" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "elrond-codec" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6d85f2b7c969a12da26157a989f759f59d1df2b0e2f4ae7b2ebb011334a63c1" -dependencies = [ - "arrayvec", - "elrond-codec-derive", - "wee_alloc", -] - -[[package]] -name = "elrond-codec-derive" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae84b062b57562daf6b90d12c6568a6df21ef355625f6dd21a3106d774456a51" -dependencies = [ - "hex", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "multiversx-sc" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c99bd13acbd995a1b048fcc791a8acd8d2d4ab1085738c9077607d218fb2a42f" -dependencies = [ - "bitflags", - "elrond-codec", - "multiversx-sc-derive", - "hashbrown", - "hex-literal", - "wee_alloc", -] - -[[package]] -name = "multiversx-sc-derive" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a3e0e238435b3e1ac971e15ac345bf4f75efc88c8ee0032e286cf67dbff9681" -dependencies = [ - "hex", - "proc-macro2", - "quote", - "radix_trie", - "syn", -] - -[[package]] -name = "multiversx-sc-node" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad55a0495ab1760ab532766529bc4b1cda04c918e44cfb2d84e1ac066d574397" -dependencies = [ - "multiversx-sc", -] - -[[package]] -name = "multiversx-sc-output" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a1b54eef1004bb8b622b7f8cbe0100c715dfd58699bb7b0c5a50d23c3a87f38" -dependencies = [ - "multiversx-sc-node", - "wee_alloc", -] - -[[package]] -name = "endian-type" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" - -[[package]] -name = "farm_v1_2_mock" -version = "0.0.0" -dependencies = [ - "multiversx-sc", -] - -[[package]] -name = "farm_v1_2_mock-wasm" -version = "0.0.0" -dependencies = [ - "multiversx-sc-node", - "multiversx-sc-output", - "farm_v1_2_mock", -] - -[[package]] -name = "getrandom" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi", -] - -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" -dependencies = [ - "ahash", -] - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "hex-literal" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" - -[[package]] -name = "libc" -version = "0.2.119" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4" - -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - -[[package]] -name = "nibble_vec" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8d77f3db4bce033f4d04db08079b2ef1c3d02b44e86f25d08886fafa7756ffa" - -[[package]] -name = "once_cell" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" - -[[package]] -name = "proc-macro2" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" -dependencies = [ - "unicode-xid", -] - -[[package]] -name = "quote" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "radix_trie" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d3681b28cd95acfb0560ea9441f82d6a4504fa3b15b97bd7b6e952131820e95" -dependencies = [ - "endian-type", - "nibble_vec", -] - -[[package]] -name = "syn" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - -[[package]] -name = "unicode-xid" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/dex/farm_with_lock/wasm/Cargo.lock b/dex/farm_with_lock/wasm/Cargo.lock deleted file mode 100644 index a286127a2..000000000 --- a/dex/farm_with_lock/wasm/Cargo.lock +++ /dev/null @@ -1,428 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "ahash" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - -[[package]] -name = "arrayvec" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "common_errors" -version = "0.0.0" -dependencies = [ - "multiversx-sc", -] - -[[package]] -name = "common_structs" -version = "0.0.0" -dependencies = [ - "multiversx-sc", -] - -[[package]] -name = "config" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "multiversx-sc", - "token_send", -] - -[[package]] -name = "contexts" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "config", - "multiversx-sc", - "farm_token", - "rewards", - "token_merge", - "token_send", -] - -[[package]] -name = "either" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" - -[[package]] -name = "elrond-codec" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6d85f2b7c969a12da26157a989f759f59d1df2b0e2f4ae7b2ebb011334a63c1" -dependencies = [ - "arrayvec", - "elrond-codec-derive", - "wee_alloc", -] - -[[package]] -name = "elrond-codec-derive" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae84b062b57562daf6b90d12c6568a6df21ef355625f6dd21a3106d774456a51" -dependencies = [ - "hex", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "multiversx-sc" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c99bd13acbd995a1b048fcc791a8acd8d2d4ab1085738c9077607d218fb2a42f" -dependencies = [ - "bitflags", - "elrond-codec", - "multiversx-sc-derive", - "hashbrown", - "hex-literal", - "wee_alloc", -] - -[[package]] -name = "multiversx-sc-derive" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a3e0e238435b3e1ac971e15ac345bf4f75efc88c8ee0032e286cf67dbff9681" -dependencies = [ - "hex", - "proc-macro2", - "quote", - "radix_trie", - "syn", -] - -[[package]] -name = "multiversx-sc-node" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad55a0495ab1760ab532766529bc4b1cda04c918e44cfb2d84e1ac066d574397" -dependencies = [ - "multiversx-sc", -] - -[[package]] -name = "multiversx-sc-output" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a1b54eef1004bb8b622b7f8cbe0100c715dfd58699bb7b0c5a50d23c3a87f38" -dependencies = [ - "multiversx-sc-node", - "wee_alloc", -] - -[[package]] -name = "endian-type" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" - -[[package]] -name = "events" -version = "0.0.0" -dependencies = [ - "common_structs", - "contexts", - "multiversx-sc", -] - -[[package]] -name = "factory" -version = "0.0.0" -dependencies = [ - "arrayvec", - "common_errors", - "common_structs", - "multiversx-sc", - "itertools", - "token_merge", - "token_send", - "wee_alloc", -] - -[[package]] -name = "farm_token" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "config", - "multiversx-sc", - "token_send", -] - -[[package]] -name = "farm_with_lock" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "config", - "contexts", - "multiversx-sc", - "events", - "factory", - "farm_token", - "migration_from_v1_2", - "pair", - "rewards", - "token_merge", - "token_send", -] - -[[package]] -name = "farm_with_lock-wasm" -version = "0.0.0" -dependencies = [ - "multiversx-sc-node", - "multiversx-sc-output", - "farm_with_lock", -] - -[[package]] -name = "getrandom" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi", -] - -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" -dependencies = [ - "ahash", -] - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "hex-literal" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" - -[[package]] -name = "itertools" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" -dependencies = [ - "either", -] - -[[package]] -name = "libc" -version = "0.2.115" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a8d982fa7a96a000f6ec4cfe966de9703eccde29750df2bb8949da91b0e818d" - -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - -[[package]] -name = "migration_from_v1_2" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "config", - "multiversx-sc", - "farm_token", - "rewards", - "token_send", -] - -[[package]] -name = "nibble_vec" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8d77f3db4bce033f4d04db08079b2ef1c3d02b44e86f25d08886fafa7756ffa" - -[[package]] -name = "once_cell" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" - -[[package]] -name = "pair" -version = "0.0.0" -dependencies = [ - "common_structs", - "multiversx-sc", - "itertools", - "token_send", -] - -[[package]] -name = "proc-macro2" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" -dependencies = [ - "unicode-xid", -] - -[[package]] -name = "quote" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "radix_trie" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d3681b28cd95acfb0560ea9441f82d6a4504fa3b15b97bd7b6e952131820e95" -dependencies = [ - "endian-type", - "nibble_vec", -] - -[[package]] -name = "rewards" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "config", - "multiversx-sc", - "farm_token", - "token_send", -] - -[[package]] -name = "syn" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - -[[package]] -name = "token_merge" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "multiversx-sc", -] - -[[package]] -name = "token_send" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "multiversx-sc", -] - -[[package]] -name = "unicode-xid" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/dex/fuzz/Cargo.toml b/dex/fuzz/Cargo.toml index ba40e32f0..57800c37f 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.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" [dependencies.pausable] path = "../../common/modules/pausable" diff --git a/dex/fuzz/src/fuzz_data.rs b/dex/fuzz/src/fuzz_data.rs index a9f19a346..14de4e7c3 100644 --- a/dex/fuzz/src/fuzz_data.rs +++ b/dex/fuzz/src/fuzz_data.rs @@ -1,5 +1,7 @@ #[cfg(test)] pub mod fuzz_data_tests { + #![allow(deprecated)] + multiversx_sc::imports!(); multiversx_sc::derive_imports!(); @@ -14,7 +16,7 @@ pub mod fuzz_data_tests { use multiversx_sc::types::{Address, BigUint, EsdtLocalRole}; use multiversx_sc_scenario::{ managed_address, managed_biguint, managed_token_id, managed_token_id_wrapped, rust_biguint, - whitebox::*, DebugApi, + whitebox_legacy::*, DebugApi, }; use pair::*; use pausable::{PausableModule, State}; diff --git a/dex/fuzz/src/fuzz_factory.rs b/dex/fuzz/src/fuzz_factory.rs index 1aaf848d2..4286c72c7 100644 --- a/dex/fuzz/src/fuzz_factory.rs +++ b/dex/fuzz/src/fuzz_factory.rs @@ -1,10 +1,11 @@ #[cfg(test)] pub mod fuzz_factory_test { + #![allow(deprecated)] multiversx_sc::imports!(); multiversx_sc::derive_imports!(); - use multiversx_sc_scenario::whitebox::TxTokenTransfer; + use multiversx_sc_scenario::whitebox_legacy::TxTokenTransfer; use multiversx_sc_scenario::{rust_biguint, DebugApi}; use crate::fuzz_data::fuzz_data_tests::*; diff --git a/dex/fuzz/src/fuzz_farm.rs b/dex/fuzz/src/fuzz_farm.rs index 6df66416c..c30e94442 100644 --- a/dex/fuzz/src/fuzz_farm.rs +++ b/dex/fuzz/src/fuzz_farm.rs @@ -1,13 +1,14 @@ #[cfg(test)] pub mod fuzz_farm_test { + #![allow(deprecated)] multiversx_sc::imports!(); multiversx_sc::derive_imports!(); use std::cmp::Ordering; - use multiversx_sc_scenario::whitebox::TxTokenTransfer; - use multiversx_sc_scenario::{managed_biguint, rust_biguint, DebugApi}; + use multiversx_sc_scenario::whitebox_legacy::TxTokenTransfer; + use multiversx_sc_scenario::{rust_biguint, DebugApi}; use crate::fuzz_data::fuzz_data_tests::*; use farm::*; @@ -178,7 +179,7 @@ pub mod fuzz_farm_test { farm_token_nonce, &farm_out_amount, |sc| { - sc.exit_farm_endpoint(managed_biguint!(seed), OptionalValue::None); + sc.exit_farm_endpoint(OptionalValue::None); }, ); diff --git a/dex/fuzz/src/fuzz_pair.rs b/dex/fuzz/src/fuzz_pair.rs index 74a326ea0..cd22614cb 100644 --- a/dex/fuzz/src/fuzz_pair.rs +++ b/dex/fuzz/src/fuzz_pair.rs @@ -1,17 +1,20 @@ #[cfg(test)] pub mod fuzz_pair_test { + #![allow(deprecated)] multiversx_sc::imports!(); multiversx_sc::derive_imports!(); use multiversx_sc_scenario::{ - managed_biguint, managed_token_id, rust_biguint, whitebox::TxTokenTransfer, DebugApi, + managed_biguint, managed_token_id, rust_biguint, whitebox_legacy::TxTokenTransfer, DebugApi, }; use rand::prelude::*; use crate::fuzz_data::fuzz_data_tests::*; - use pair::*; + use pair::pair_actions::{ + add_liq::AddLiquidityModule, remove_liq::RemoveLiquidityModule, swap::SwapModule, + }; pub fn add_liquidity( fuzzer_data: &mut FuzzerData< diff --git a/dex/fuzz/src/fuzz_price_discovery.rs b/dex/fuzz/src/fuzz_price_discovery.rs index 45254341b..2b6cd9909 100644 --- a/dex/fuzz/src/fuzz_price_discovery.rs +++ b/dex/fuzz/src/fuzz_price_discovery.rs @@ -1,5 +1,6 @@ #[cfg(test)] pub mod fuzz_price_discovery_test { + #![allow(deprecated)] multiversx_sc::imports!(); multiversx_sc::derive_imports!(); diff --git a/dex/fuzz/src/fuzz_start.rs b/dex/fuzz/src/fuzz_start.rs index 2c673a261..4df24d71a 100644 --- a/dex/fuzz/src/fuzz_start.rs +++ b/dex/fuzz/src/fuzz_start.rs @@ -1,5 +1,6 @@ #[cfg(test)] mod test { + #![allow(deprecated)] multiversx_sc::imports!(); multiversx_sc::derive_imports!(); diff --git a/dex/governance/Cargo.toml b/dex/governance/Cargo.toml index 7aeb1b170..74d9f2849 100644 --- a/dex/governance/Cargo.toml +++ b/dex/governance/Cargo.toml @@ -7,15 +7,16 @@ publish = false [lib] path = "src/lib.rs" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" [dev-dependencies.pair-mock] path = "../pair-mock" diff --git a/dex/governance/meta/Cargo.toml b/dex/governance/meta/Cargo.toml index cc998004f..b692c9007 100644 --- a/dex/governance/meta/Cargo.toml +++ b/dex/governance/meta/Cargo.toml @@ -6,8 +6,10 @@ publish = false authors = ["MultiversX "] [dev-dependencies] + [dependencies.governance] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/dex/governance/src/lib.rs b/dex/governance/src/lib.rs index 605ba4ba0..e9d4147d3 100644 --- a/dex/governance/src/lib.rs +++ b/dex/governance/src/lib.rs @@ -49,6 +49,9 @@ pub trait Governance: self.try_change_price_providers(price_providers); } + #[endpoint] + fn upgrade(&self) {} + #[payable("*")] #[endpoint] fn propose(&self, args: ProposalCreationArgs) -> u64 { diff --git a/dex/governance/src/proposal.rs b/dex/governance/src/proposal.rs index 7f04c1f2f..3a80c60bd 100644 --- a/dex/governance/src/proposal.rs +++ b/dex/governance/src/proposal.rs @@ -103,12 +103,18 @@ pub trait ProposalHelper: config::Config { } fn execute_action(&self, action: &Action) -> Result<(), &'static [u8]> { - Self::Api::send_api_impl().transfer_value_execute( - &action.dest_address, - &BigUint::zero(), - action.gas_limit, - &action.endpoint_name, - &ManagedArgBuffer::from(action.arguments.clone()), - ) + self.send() + .contract_call::<()>(action.dest_address.clone(), action.endpoint_name.clone()) + .with_raw_arguments(ManagedArgBuffer::from(action.arguments.clone())) + .with_gas_limit(action.gas_limit) + .transfer_execute(); + Result::Ok(()) + // ContractCallNoPayment::new() + // self.send_raw().direct_egld( + // &BigUint::zero(), + // action.gas_limit, + // &action.endpoint_name, + // &ManagedArgBuffer::from(action.arguments.clone()), + // ) } } diff --git a/dex/governance/src/weight.rs b/dex/governance/src/weight.rs index 2eda127a1..07b075f95 100644 --- a/dex/governance/src/weight.rs +++ b/dex/governance/src/weight.rs @@ -27,9 +27,7 @@ pub trait Lib: config::Config { if let Some(provider) = self.price_providers().get(&payment.token_identifier) { let call_result: MultiValue2, EsdtTokenPayment> = self.price_provider_proxy(provider) - .get_tokens_for_given_position_with_safe_price( - payment.amount.clone(), - ) + .get_tokens_for_given_position_with_safe_price(payment.amount.clone()) .execute_on_dest_context(); let (token1, token2) = call_result.into_tuple(); diff --git a/dex/governance/tests/gov_tests.rs b/dex/governance/tests/gov_tests.rs index cbc708798..61dc9c985 100644 --- a/dex/governance/tests/gov_tests.rs +++ b/dex/governance/tests/gov_tests.rs @@ -1,9 +1,11 @@ +#![allow(deprecated)] + use multiversx_sc::codec::multi_types::{MultiValue2, OptionalValue}; use multiversx_sc::types::MultiValueEncoded; use multiversx_sc::types::{Address, EsdtLocalRole, EsdtTokenPayment, ManagedVec}; use multiversx_sc_scenario::{ - managed_address, managed_biguint, managed_buffer, managed_token_id, rust_biguint, whitebox::*, - DebugApi, + managed_address, managed_biguint, managed_buffer, managed_token_id, rust_biguint, + whitebox_legacy::*, DebugApi, }; use governance::config::*; diff --git a/dex/governance/wasm/Cargo.lock b/dex/governance/wasm/Cargo.lock index ebe14cc18..30ca50940 100644 --- a/dex/governance/wasm/Cargo.lock +++ b/dex/governance/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "endian-type" @@ -64,15 +41,6 @@ dependencies = [ "multiversx-sc-wasm-adapter", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -81,30 +49,17 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" - -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - -[[package]] -name = "memory_units" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -113,20 +68,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -136,9 +90,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -149,12 +103,11 @@ dependencies = [ [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -168,33 +121,27 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -211,15 +158,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -228,46 +175,6 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/dex/governance/wasm/Cargo.toml b/dex/governance/wasm/Cargo.toml index 8214f691a..905950d0e 100644 --- a/dex/governance/wasm/Cargo.toml +++ b/dex/governance/wasm/Cargo.toml @@ -1,25 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "governance-wasm" version = "0.0.0" -authors = ["MultiversX "] edition = "2021" publish = false [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.governance] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/dex/governance/wasm/src/lib.rs b/dex/governance/wasm/src/lib.rs index bfedec764..913c84bba 100644 --- a/dex/governance/wasm/src/lib.rs +++ b/dex/governance/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 21 +// Endpoints: 22 // Async Callback (empty): 1 -// Total number of exported functions: 23 +// Total number of exported functions: 24 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,28 +19,30 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { governance ( - propose - upvote - downvote - execute - redeem - changeQuorum - changeMinTokenBalanceForProposing - changeVotingDelayInBlocks - changeVotingPeriodInBlocks - changeGovernanceTokenIds - changePriceProviders - getGovernanceTokenId - getQuorum - getMinWeightForProposal - getVotingDelayInBlocks - getVotingPeriodInBlocks - getProposal - getProposalIdCounter - getVoteNFTId - getMexTokenId - getProposalStatus + init => init + upgrade => upgrade + propose => propose + upvote => upvote + downvote => downvote + execute => execute + redeem => redeem + changeQuorum => change_quorum + changeMinTokenBalanceForProposing => change_min_weight_for_proposal + changeVotingDelayInBlocks => change_voting_delay_in_blocks + changeVotingPeriodInBlocks => change_voting_period_in_blocks + changeGovernanceTokenIds => change_governance_token_ids + changePriceProviders => change_price_providers + getGovernanceTokenId => governance_token_ids + getQuorum => quorum + getMinWeightForProposal => min_weight_for_proposal + getVotingDelayInBlocks => voting_delay_in_blocks + getVotingPeriodInBlocks => voting_period_in_blocks + getProposal => proposal + getProposalIdCounter => proposal_id_counter + getVoteNFTId => vote_nft_id + getMexTokenId => mex_token_id + getProposalStatus => get_proposal_status_view ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/dex/pair-mock/Cargo.toml b/dex/pair-mock/Cargo.toml index cda7012ec..bc58d1089 100644 --- a/dex/pair-mock/Cargo.toml +++ b/dex/pair-mock/Cargo.toml @@ -7,15 +7,17 @@ publish = false [lib] path = "src/pair.rs" + [dependencies.common_errors] path = "../../common/common_errors" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.itertools] version = "0.10.1" default-features = false + [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" diff --git a/dex/pair-mock/meta/Cargo.toml b/dex/pair-mock/meta/Cargo.toml index 914c418db..673a8fc84 100644 --- a/dex/pair-mock/meta/Cargo.toml +++ b/dex/pair-mock/meta/Cargo.toml @@ -6,8 +6,10 @@ publish = false authors = ["MultiversX "] [dev-dependencies] + [dependencies.pair-mock] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/dex/pair-mock/src/pair.rs b/dex/pair-mock/src/pair.rs index 751ea8d2c..1f073c215 100644 --- a/dex/pair-mock/src/pair.rs +++ b/dex/pair-mock/src/pair.rs @@ -16,6 +16,7 @@ pub const DEFAULT_SKIP_MINTING_LP_TOKENS: bool = true; #[multiversx_sc::derive::contract] pub trait PairMock { + #[allow_multiple_var_args] #[init] fn init( &self, diff --git a/dex/pair-mock/wasm/Cargo.lock b/dex/pair-mock/wasm/Cargo.lock index fdfb68d12..6311e01de 100644 --- a/dex/pair-mock/wasm/Cargo.lock +++ b/dex/pair-mock/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common_errors" @@ -52,9 +29,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "endian-type" @@ -62,15 +39,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -79,9 +47,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "itertools" @@ -92,26 +60,13 @@ dependencies = [ "either", ] -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -120,20 +75,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -143,9 +97,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -156,12 +110,11 @@ dependencies = [ [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -175,19 +128,13 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "pair-mock" version = "0.0.0" @@ -207,18 +154,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -235,15 +182,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -252,46 +199,6 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/dex/pair-mock/wasm/Cargo.toml b/dex/pair-mock/wasm/Cargo.toml index feebc28dc..9bf537c94 100644 --- a/dex/pair-mock/wasm/Cargo.toml +++ b/dex/pair-mock/wasm/Cargo.toml @@ -1,25 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "pair-mock-wasm" version = "0.0.0" -authors = ["MultiversX "] edition = "2021" publish = false [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.pair-mock] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/dex/pair/Cargo.toml b/dex/pair/Cargo.toml index b4ae5976b..457fb8d8f 100644 --- a/dex/pair/Cargo.toml +++ b/dex/pair/Cargo.toml @@ -7,6 +7,7 @@ publish = false [lib] path = "src/lib.rs" + [dependencies.common_errors] path = "../../common/common_errors" @@ -28,16 +29,19 @@ path = "../../locked-asset/simple-lock" [dependencies.fees-collector] path = "../../energy-integration/fees-collector" +[dependencies.utils] +path = "../../common/modules/utils" + [dependencies.itertools] version = "0.10.1" default-features = false [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" diff --git a/dex/pair/README.md b/dex/pair/README.md index 77c109533..5fefeb960 100644 --- a/dex/pair/README.md +++ b/dex/pair/README.md @@ -33,7 +33,7 @@ The init function is called when deploying/upgrading a smart contract. It receiv - __router_address__ - The address of the router smart contract. In most cases it is the caller address. The router address, together with the router owner address act as managers. They have the rights to upgrade and modify the contract's settings until a multisign dApp implementation will be ready and in place. - __router_owner_address__ - __total_fee_percent__ - Each time a swap is made, a fee is charged. The total percent is configurable by this parameter, but is usually 300, representing a percentage of 0.3, base points being 1_000. -- __special_fee_percent__ - The total fee is handled in two different manners. By default, the fee is reinvested into the pool, thus increasing the amount of tokens of liquidity providers. Part of the total fee is handled differently. More specific, a value of 50, representing a percentage of 0.05 of each swap is used to buyback and burn MEX tokens. The special fee can also be split in many equal parts and can be configured to be sent to other addresses also. The convention is that, if a configured special fee destination address is zero, then the tokens should be burned (the way it is configured in Maiar Exchange as well). +- __special_fee_percent__ - The total fee is handled in two different manners. By default, the fee is reinvested into the pool, thus increasing the amount of tokens of liquidity providers. Part of the total fee is handled differently. More specific, a value of 50, representing a percentage of 0.05 of each swap is used to buyback and burn MEX tokens. The special fee can also be split in many equal parts and can be configured to be sent to other addresses also. The convention is that, if a configured special fee destination address is zero, then the tokens should be burned (the way it is configured in xExchange as well). - __initial_liquidity_adder__ - An optional argument that is usually a Price Discovery smart contract. Used to decrease changes and impact of Pump & Dump at new listings. ### addLiquidity @@ -139,7 +139,7 @@ Considering __f__ being the percent of total fee, the formula including fees is rI * rO = (rI + (1 - f) * aI) * (rO - aO) ``` -Let's presume that __aO__ will be calculated only by taking into account ```(1 - f) * aI```. In Maiar Exchange's current configuration, that would be 0.97% of the input. +Let's presume that __aO__ will be calculated only by taking into account ```(1 - f) * aI```. In xExchange's current configuration, that would be 0.97% of the input. The remaining fee, which is ```f * aI``` would be split afterwards into regular fee - reinvested in the pool and special fee - used for buyback and burn mex. For more in depth dive into how the special fee is handled, see ```send_fee``` private function. @@ -208,8 +208,181 @@ There are four test suites around this contract: ## Interaction -The interaction scripts are located in the _dex/interaction_ directory. The scripts are written in python and erdpy is required in order to be used. Interaction scripts are scripts that ease the interaction with the deployed contract by wrapping erdpy sdk functionality in bash scripts. Make sure to update the PEM path and the PROXY and CHAINID values in order to correctly use the scripts. +The interaction scripts are located in the _dex/interaction_ directory. The scripts are written in python and mxpy is required in order to be used. Interaction scripts are scripts that ease the interaction with the deployed contract by wrapping mxpy sdk functionality in bash scripts. Make sure to update the PEM path and the PROXY and CHAINID values in order to correctly use the scripts. ## Deployment -The deployment of this contract is done by the Router smart contract but it can be done also in a standalone manner using the erdpy interaction scripts for deploy/upgrade. +The deployment of this contract is done by the Router smart contract but it can be done also in a standalone manner using the mxpy interaction scripts for deploy/upgrade. + + +# Safe Price V2 + +## General overview + +The new safe price mechanism is an updated module of the __Pair SC__, designed to stabilize prices over a number of rounds, creating a smoother, more predictable pricing pattern in the __xExchange__ liquidity pools. The mechanism achieves this by storing accumulated reserves over time, with each recorded round representing a snapshot of token reserves at that point in time. This collection of reserve data is then processed through a variety of algorithms to compute and retrieve the safe price. Notably, the mechanism operates through a central view factory contract, which manages requests for all active smart contract pairs. The view factory contract accepts the address of the desired pair as a parameter in its view functions, simplifying the process of querying for data. + +__Important. The Safe Price module retrieves data independently of the liquidity pool's state. As such, even if a pair smart contract is paused, the safe price module will continue to return data. If an external contract requires more control or context concerning the data, it needs to first check the liquidity pool's status manually and subsequently utilize the safe price data according to its needs.__ + +## Features + +- __Accumulated Reserves:__ The mechanism consistently stores the accumulated reserves over time. Each round in which the liquidity pool contract is used creates a snapshot of the token reserves for that time, with the weight of a __PriceObservation__ for a round being the difference between the last saved round and the current one. +- __Price Observations:__ Each round's reserves, once calculated and stored, are then saved in a __PriceObservation__ struct for the subsequent round (n+1). This allows for a clear record of price changes and liquidity over time. +- __Circular List Storage and Binary Search:__ Price observations are stored in a circular list, which is an efficient data structure for storing the rolling price data. A binary search algorithm is used to find specific __PriceObservations__ in this list. +- __Linear Interpolation:__ If a price observation is not available for a queried round, the algorithm will perform a linear interpolation between the nearest price observations to estimate the price for that round. +- __Error Handling:__ To maintain data integrity, a query for a price observation older than the oldest stored observation will result in a SC error. This mechanism helps to prevent the use of outdated or non-existent data. +- __Versatile Safe Price Request Inputs:__ The mechanism offers several view functions, each providing a different way to query the safe price. These views give users flexibility in querying the safe price by either providing all necessary parameters or using default ones. + +## Endpoints available on the View factory contract + +### getSafePrice + +```rust + #[view(getSafePrice)] + fn get_safe_price( + &self, + pair_address: ManagedAddress, + start_round: Round, + end_round: Round, + input_payment: EsdtTokenPayment, + ) -> EsdtTokenPayment +``` + +This function allows you to retrieve the safe price by specifying the pair address, start round, end round, and input payment. +It returns the corresponding output payment computed at the safe price. + +### getSafePriceByRoundOffset + +```rust + #[view(getSafePriceByRoundOffset)] + fn get_safe_price_by_round_offset( + &self, + pair_address: ManagedAddress, + round_offset: u64, + input_payment: EsdtTokenPayment, + ) -> EsdtTokenPayment +``` + +This function allows you to retrieve the safe price by specifying the pair address, round offset, and input payment. It calls the generic __getSafePrice__ endpoint, by automatically computing the end_round parameter as the current block round, and the start_round as the difference between the current_round and the provided round_offset. +It returns the corresponding output payment computed at the safe price. + +### getSafePriceByDefaultOffset + +```rust + #[view(getSafePriceByDefaultOffset)] + fn get_safe_price_by_default_offset( + &self, + pair_address: ManagedAddress, + input_payment: EsdtTokenPayment, + ) -> EsdtTokenPayment +``` + +This function allows you to retrieve the safe price by specifying the pair address and input payment. It works in the same way as __getSafePriceByRoundOffset__ endpoint, but instead of using a provided round_offset parameter, it uses a default one, which at this moment is set to 600 rounds (which translates in an one hour window). +It returns the corresponding output payment computed at the safe price. + +### getSafePriceByTimestampOffset + +```rust + #[view(getSafePriceByTimestampOffset)] + fn get_safe_price_by_timestamp_offset( + &self, + pair_address: ManagedAddress, + timestamp_offset: u64, + input_payment: EsdtTokenPayment, + ) -> EsdtTokenPayment +``` + +A more specific view function, it allows you to retrieve the safe price by specifying the pair address, a timestamp offset, and input payment. It basically converts the timestamp_offset value to a generic round_offset, by dividing it with the constant value __SECONDS_PER_ROUND__. +It returns the corresponding output payment computed at the safe price. +__Important. The output of this endpoint (and any timestamp related endpoint) will return reliable data as long as the timestamp constant will remain unchanged at the protocol level.__ + + +### getLpTokensSafePrice + +```rust + #[view(getLpTokensSafePrice)] + fn get_lp_tokens_safe_price( + &self, + pair_address: ManagedAddress, + start_round: Round, + end_round: Round, + liquidity: BigUint, + ) -> MultiValue2 +``` + +This function allows you to simulate the value of both tokens within a liquidity pool based on a provided LP token amount. It receives the pair address, the start and end rounds, and the amount of LP tokens as parameters. +The function returns two output payments, one for each token in the pair, with their values computed at the safe price. + +### getLpTokensSafePriceByRoundOffset + +```rust + #[view(getLpTokensSafePriceByRoundOffset)] + fn get_lp_tokens_safe_price_by_round_offset( + &self, + pair_address: ManagedAddress, + round_offset: Round, + liquidity: BigUint, + ) -> MultiValue2 +``` + +This function allows you to simulate the value of both tokens within a liquidity pool based on a provided LP token amount. It receives the pair address, a round_offset, and the amount of LP tokens as parameters. It works in the same way as the __getSafePriceByRoundOffset__ function for the round_offset, by computing the end round and the start round automatically, using the current block round and the round offset variable. +The function returns two output payments, one for each token in the pair, with their values computed at the safe price. + +### getLpTokensSafePriceByDefaultOffset + +```rust + #[view(getLpTokensSafePriceByDefaultOffset)] + fn get_lp_tokens_safe_price_by_default_offset( + &self, + pair_address: ManagedAddress, + liquidity: BigUint, + ) -> MultiValue2 +``` + +This function allows you to simulate the value of both tokens within a liquidity pool based on a provided LP token amount. It receives the pair address and the amount of LP tokens as parameters and works similarly to __getLpTokensSafePriceByRoundOffset__ endpoint, but instead of using a provided round_offset variable, it uses a default one which at this moment is set to 600 rounds (which translates in an one hour window). +The function returns two output payments, one for each token in the pair, with their values computed at the safe price. + +### getLpTokensSafePriceByTimestampOffset + +```rust + #[view(getLpTokensSafePriceByTimestampOffset)] + fn get_lp_tokens_safe_price_by_timestamp_offset( + &self, + pair_address: ManagedAddress, + timestamp_offset: u64, + liquidity: BigUint, + ) -> MultiValue2 +``` + +This function allows you to simulate the value of both tokens within a liquidity pool based on a provided LP token amount. It receives the pair address, a timestamp_offset and the amount of LP tokens as parameters. Again, like the __getLpTokensSafePriceByRoundOffset__ endpoint, which automatically computes the start and end rounds of the query, this function calculates the round offset by dividing the timestamp_offset to a generic __SECONDS_PER_ROUND__ constant value. +The function returns two output payments, one for each token in the pair, with their values computed at the safe price. + +## Legacy endpoints + +In order to avoid backwards compatibility issues, the two legacy endpoints from Safe Price V1 were kept, but they now use the new Safe Price V2 logic. One important aspect here is that they are not part of the Safe Price V2 view factory contract, but instead they are actual endpoints in the __Pair SC__. +__Important. These endpoints are planned to be phased out at any point in future, thus we consider them as deprecated and we recommend the usage of the ones available in the View factory contract.__ + +### updateAndGetTokensForGivenPositionWithSafePrice + +```rust + #[endpoint(updateAndGetTokensForGivenPositionWithSafePrice)] + fn update_and_get_tokens_for_given_position_with_safe_price( + &self, + liquidity: BigUint, + ) -> MultiValue2, EsdtTokenPayment> +``` + +This legacy endpoint is kept for backwards compatibility purposes, but it now works the same as the __getLpTokensSafePriceByDefaultOffset__ view function, by using the contract address as the pair_address. It receives only one parameter, the amount of LP tokens. +The function returns two output payments, one for each token in the pair, with their values computed at the safe price. + +### updateAndGetSafePrice + +```rust + #[endpoint(updateAndGetSafePrice)] + fn update_and_get_safe_price( + &self, + input: EsdtTokenPayment, + ) -> EsdtTokenPayment +``` + +This legacy endpoint is kept for backwards compatibility purposes, but it now works the same as the __getSafePriceByDefaultOffset__ view function, by using the contract address as the pair_address. It receives only one parameter, the input payment. +It returns the corresponding output payment computed at the safe price. diff --git a/dex/pair/meta/Cargo.toml b/dex/pair/meta/Cargo.toml index e897f3fe5..b07218ea1 100644 --- a/dex/pair/meta/Cargo.toml +++ b/dex/pair/meta/Cargo.toml @@ -4,8 +4,10 @@ version = "0.0.0" authors = ["MultiversX "] edition = "2021" publish = false + [dependencies.pair] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/dex/pair/multicontract.toml b/dex/pair/sc-config.toml similarity index 92% rename from dex/pair/multicontract.toml rename to dex/pair/sc-config.toml index ed3a54026..738e43967 100644 --- a/dex/pair/multicontract.toml +++ b/dex/pair/sc-config.toml @@ -8,6 +8,7 @@ add-unlabelled = true [contracts.safe-price-view] name = "safe-price-view" external-view = true +add-unlabelled = false add-labels = ["safe-price-view"] [contracts.full] diff --git a/dex/pair/src/contexts/output_builder.rs b/dex/pair/src/contexts/output_builder.rs index ef719da40..3d98d16dc 100644 --- a/dex/pair/src/contexts/output_builder.rs +++ b/dex/pair/src/contexts/output_builder.rs @@ -50,11 +50,6 @@ pub trait OutputBuilderModule: ) -> ManagedVec> { let mut payments: ManagedVec> = ManagedVec::new(); - payments.push(EsdtTokenPayment::new( - storage_cache.lp_token_id.clone(), - 0, - add_liq_context.liq_added.clone(), - )); payments.push(EsdtTokenPayment::new( storage_cache.first_token_id.clone(), 0, @@ -142,14 +137,12 @@ pub trait OutputBuilderModule: )); } - if swap_context.final_input_amount < swap_context.input_token_amount { - let extra_amount = &swap_context.input_token_amount - &swap_context.final_input_amount; - payments.push(EsdtTokenPayment::new( - swap_context.input_token_id.clone(), - 0, - extra_amount, - )); - } + let extra_amount = &swap_context.input_token_amount - &swap_context.final_input_amount; + payments.push(EsdtTokenPayment::new( + swap_context.input_token_id.clone(), + 0, + extra_amount, + )); payments } diff --git a/dex/pair/src/lib.rs b/dex/pair/src/lib.rs index 425b7acc1..98996e34a 100644 --- a/dex/pair/src/lib.rs +++ b/dex/pair/src/lib.rs @@ -11,30 +11,20 @@ mod events; pub mod fee; mod liquidity_pool; pub mod locking_wrapper; +pub mod pair_actions; pub mod safe_price; pub mod safe_price_view; -use crate::contexts::add_liquidity::AddLiquidityContext; -use crate::contexts::remove_liquidity::RemoveLiquidityContext; use crate::errors::*; -use common_errors::ERROR_PERMISSION_DENIED; use contexts::base::*; -use contexts::swap::SwapContext; +use pair_actions::common_result_types::{ + AddLiquidityResultType, RemoveLiquidityResultType, SwapTokensFixedInputResultType, + SwapTokensFixedOutputResultType, +}; use pausable::State; use permissions_module::Permissions; -pub type AddLiquidityResultType = - MultiValue3, EsdtTokenPayment, EsdtTokenPayment>; - -pub type RemoveLiquidityResultType = - MultiValue2, EsdtTokenPayment>; - -pub type SwapTokensFixedInputResultType = EsdtTokenPayment; - -pub type SwapTokensFixedOutputResultType = - MultiValue2, EsdtTokenPayment>; - #[multiversx_sc::contract] pub trait Pair: amm::AmmModule @@ -49,6 +39,13 @@ pub trait Pair: + locking_wrapper::LockingWrapperModule + permissions_module::PermissionsModule + pausable::PausableModule + + pair_actions::initial_liq::InitialLiquidityModule + + pair_actions::add_liq::AddLiquidityModule + + pair_actions::remove_liq::RemoveLiquidityModule + + pair_actions::swap::SwapModule + + pair_actions::views::ViewsModule + + pair_actions::common_methods::CommonMethodsModule + + utils::UtilsModule { #[init] fn init( @@ -90,7 +87,7 @@ pub trait Pair: if admins.is_empty() { // backwards compatibility let all_permissions = Permissions::OWNER | Permissions::ADMIN | Permissions::PAUSE; - self.add_permissions(router_address, all_permissions); + self.add_permissions(router_address, all_permissions.clone()); self.add_permissions(router_owner_address, all_permissions); } else { self.add_permissions(router_address, Permissions::OWNER | Permissions::PAUSE); @@ -102,461 +99,8 @@ pub trait Pair: }; } - #[payable("*")] - #[endpoint(addInitialLiquidity)] - fn add_initial_liquidity(&self) -> AddLiquidityResultType { - let mut storage_cache = StorageCache::new(self); - let caller = self.blockchain().get_caller(); - - let opt_initial_liq_adder = self.initial_liquidity_adder().get(); - if let Some(initial_liq_adder) = opt_initial_liq_adder { - require!(caller == initial_liq_adder, ERROR_PERMISSION_DENIED); - } - - let [first_payment, second_payment] = self.call_value().multi_esdt(); - require!( - first_payment.token_identifier == storage_cache.first_token_id - && first_payment.amount > 0, - ERROR_BAD_PAYMENT_TOKENS - ); - require!( - second_payment.token_identifier == storage_cache.second_token_id - && second_payment.amount > 0, - ERROR_BAD_PAYMENT_TOKENS - ); - require!( - !self.is_state_active(storage_cache.contract_state), - ERROR_ACTIVE - ); - require!( - storage_cache.lp_token_supply == 0, - ERROR_INITIAL_LIQUIDITY_ALREADY_ADDED - ); - - let first_token_optimal_amount = &first_payment.amount; - let second_token_optimal_amount = &second_payment.amount; - let liq_added = self.pool_add_initial_liquidity( - first_token_optimal_amount, - second_token_optimal_amount, - &mut storage_cache, - ); - - self.send() - .esdt_local_mint(&storage_cache.lp_token_id, 0, &liq_added); - self.send() - .direct_esdt(&caller, &storage_cache.lp_token_id, 0, &liq_added); - - self.state().set(State::PartialActive); - - let add_liq_context = AddLiquidityContext { - first_payment: first_payment.clone(), - second_payment: second_payment.clone(), - first_token_amount_min: BigUint::from(1u32), - second_token_amount_min: BigUint::from(1u32), - first_token_optimal_amount: first_token_optimal_amount.clone(), - second_token_optimal_amount: second_token_optimal_amount.clone(), - liq_added, - }; - let output = self.build_add_initial_liq_results(&storage_cache, &add_liq_context); - - self.emit_add_liquidity_event(&storage_cache, add_liq_context); - - output - } - - #[payable("*")] - #[endpoint(addLiquidity)] - fn add_liquidity( - &self, - first_token_amount_min: BigUint, - second_token_amount_min: BigUint, - ) -> AddLiquidityResultType { - require!( - first_token_amount_min > 0 && second_token_amount_min > 0, - ERROR_INVALID_ARGS - ); - - let mut storage_cache = StorageCache::new(self); - let caller = self.blockchain().get_caller(); - - let [first_payment, second_payment] = self.call_value().multi_esdt(); - require!( - first_payment.token_identifier == storage_cache.first_token_id - && first_payment.amount > 0, - ERROR_BAD_PAYMENT_TOKENS - ); - require!( - second_payment.token_identifier == storage_cache.second_token_id - && second_payment.amount > 0, - ERROR_BAD_PAYMENT_TOKENS - ); - require!( - self.is_state_active(storage_cache.contract_state), - ERROR_NOT_ACTIVE - ); - require!( - storage_cache.lp_token_id.is_valid_esdt_identifier(), - ERROR_LP_TOKEN_NOT_ISSUED - ); - require!( - self.initial_liquidity_adder().get().is_none() || storage_cache.lp_token_supply != 0, - ERROR_INITIAL_LIQUIDITY_NOT_ADDED - ); - - self.update_safe_price( - &storage_cache.first_token_reserve, - &storage_cache.second_token_reserve, - ); - - let initial_k = self.calculate_k_constant( - &storage_cache.first_token_reserve, - &storage_cache.second_token_reserve, - ); - - let mut add_liq_context = AddLiquidityContext::new( - first_payment, - second_payment, - first_token_amount_min, - second_token_amount_min, - ); - self.set_optimal_amounts(&mut add_liq_context, &storage_cache); - - add_liq_context.liq_added = if storage_cache.lp_token_supply == 0u64 { - self.pool_add_initial_liquidity( - &add_liq_context.first_token_optimal_amount, - &add_liq_context.second_token_optimal_amount, - &mut storage_cache, - ) - } else { - self.pool_add_liquidity( - &add_liq_context.first_token_optimal_amount, - &add_liq_context.second_token_optimal_amount, - &mut storage_cache, - ) - }; - - let new_k = self.calculate_k_constant( - &storage_cache.first_token_reserve, - &storage_cache.second_token_reserve, - ); - require!(initial_k <= new_k, ERROR_K_INVARIANT_FAILED); - - self.send() - .esdt_local_mint(&storage_cache.lp_token_id, 0, &add_liq_context.liq_added); - - let output_payments = self.build_add_liq_output_payments(&storage_cache, &add_liq_context); - self.send_multiple_tokens_if_not_zero(&caller, &output_payments); - - let output = self.build_add_liq_results(&storage_cache, &add_liq_context); - - self.emit_add_liquidity_event(&storage_cache, add_liq_context); - - output - } - - #[payable("*")] - #[endpoint(removeLiquidity)] - fn remove_liquidity( - &self, - first_token_amount_min: BigUint, - second_token_amount_min: BigUint, - ) -> RemoveLiquidityResultType { - require!( - first_token_amount_min > 0 && second_token_amount_min > 0, - ERROR_INVALID_ARGS - ); - - let mut storage_cache = StorageCache::new(self); - let caller = self.blockchain().get_caller(); - let payment = self.call_value().single_esdt(); - - require!( - self.is_state_active(storage_cache.contract_state), - ERROR_NOT_ACTIVE - ); - require!( - storage_cache.lp_token_id.is_valid_esdt_identifier(), - ERROR_LP_TOKEN_NOT_ISSUED - ); - require!( - payment.token_identifier == storage_cache.lp_token_id && payment.amount > 0, - ERROR_BAD_PAYMENT_TOKENS - ); - - self.update_safe_price( - &storage_cache.first_token_reserve, - &storage_cache.second_token_reserve, - ); - - let initial_k = self.calculate_k_constant( - &storage_cache.first_token_reserve, - &storage_cache.second_token_reserve, - ); - - let mut remove_liq_context = RemoveLiquidityContext::new( - payment.amount, - first_token_amount_min, - second_token_amount_min, - ); - self.pool_remove_liquidity(&mut remove_liq_context, &mut storage_cache); - - let new_k = self.calculate_k_constant( - &storage_cache.first_token_reserve, - &storage_cache.second_token_reserve, - ); - require!(new_k <= initial_k, ERROR_K_INVARIANT_FAILED); - - self.burn( - &storage_cache.lp_token_id, - &remove_liq_context.lp_token_payment_amount, - ); - - let output_payments = - self.build_remove_liq_output_payments(&storage_cache, &remove_liq_context); - self.send_multiple_tokens_if_not_zero(&caller, &output_payments); - - self.emit_remove_liquidity_event(&storage_cache, remove_liq_context); - - self.build_remove_liq_results(output_payments) - } - - #[payable("*")] - #[endpoint(removeLiquidityAndBuyBackAndBurnToken)] - fn remove_liquidity_and_burn_token(&self, token_to_buyback_and_burn: TokenIdentifier) { - let mut storage_cache = StorageCache::new(self); - let caller = self.blockchain().get_caller(); - let payment = self.call_value().single_esdt(); - - require!(self.whitelist().contains(&caller), ERROR_NOT_WHITELISTED); - require!( - storage_cache.lp_token_id.is_valid_esdt_identifier(), - ERROR_LP_TOKEN_NOT_ISSUED - ); - require!( - payment.token_identifier == storage_cache.lp_token_id && payment.amount > 0, - ERROR_BAD_PAYMENT_TOKENS - ); - - self.update_safe_price( - &storage_cache.first_token_reserve, - &storage_cache.second_token_reserve, - ); - - let mut remove_liq_context = - RemoveLiquidityContext::new(payment.amount, BigUint::from(1u64), BigUint::from(1u64)); - self.pool_remove_liquidity(&mut remove_liq_context, &mut storage_cache); - - self.burn( - &storage_cache.lp_token_id, - &remove_liq_context.lp_token_payment_amount, - ); - - let dest_address = ManagedAddress::zero(); - let first_token_id = storage_cache.first_token_id.clone(); - self.send_fee_slice( - &mut storage_cache, - SwapTokensOrder::PoolOrder, - &first_token_id, - &remove_liq_context.first_token_amount_removed, - &dest_address, - &token_to_buyback_and_burn, - ); - - let second_token_id = storage_cache.second_token_id.clone(); - self.send_fee_slice( - &mut storage_cache, - SwapTokensOrder::ReverseOrder, - &second_token_id, - &remove_liq_context.second_token_amount_removed, - &dest_address, - &token_to_buyback_and_burn, - ); - } - - #[payable("*")] - #[endpoint(swapNoFeeAndForward)] - fn swap_no_fee(&self, token_out: TokenIdentifier, destination_address: ManagedAddress) { - let caller = self.blockchain().get_caller(); - require!(self.whitelist().contains(&caller), ERROR_NOT_WHITELISTED); - - let mut storage_cache = StorageCache::new(self); - let (token_in, _, amount_in) = self.call_value().single_esdt().into_tuple(); - let swap_tokens_order = storage_cache.get_swap_tokens_order(&token_in, &token_out); - - require!( - self.can_swap(storage_cache.contract_state), - ERROR_SWAP_NOT_ENABLED - ); - - self.update_safe_price( - &storage_cache.first_token_reserve, - &storage_cache.second_token_reserve, - ); - - let initial_k = self.calculate_k_constant( - &storage_cache.first_token_reserve, - &storage_cache.second_token_reserve, - ); - - let mut swap_context = SwapContext::new( - token_in, - amount_in.clone(), - token_out, - BigUint::from(1u32), - swap_tokens_order, - ); - swap_context.final_input_amount = amount_in; - - let amount_out = self.swap_safe_no_fee( - &mut storage_cache, - swap_context.swap_tokens_order, - &swap_context.final_input_amount, - ); - require!(amount_out > 0u64, ERROR_ZERO_AMOUNT); - - swap_context.final_output_amount = amount_out; - - let new_k = self.calculate_k_constant( - &storage_cache.first_token_reserve, - &storage_cache.second_token_reserve, - ); - require!(initial_k <= new_k, ERROR_K_INVARIANT_FAILED); - - self.burn( - &swap_context.output_token_id, - &swap_context.final_output_amount, - ); - - self.emit_swap_no_fee_and_forward_event(swap_context, destination_address); - } - - #[payable("*")] - #[endpoint(swapTokensFixedInput)] - fn swap_tokens_fixed_input( - &self, - token_out: TokenIdentifier, - amount_out_min: BigUint, - ) -> SwapTokensFixedInputResultType { - require!(amount_out_min > 0, ERROR_INVALID_ARGS); - - let mut storage_cache = StorageCache::new(self); - let (token_in, _, amount_in) = self.call_value().single_esdt().into_tuple(); - let swap_tokens_order = storage_cache.get_swap_tokens_order(&token_in, &token_out); - - require!( - self.can_swap(storage_cache.contract_state), - ERROR_SWAP_NOT_ENABLED - ); - - let reserve_out = storage_cache.get_mut_reserve_out(swap_tokens_order); - require!(*reserve_out > amount_out_min, ERROR_NOT_ENOUGH_RESERVE); - - self.update_safe_price( - &storage_cache.first_token_reserve, - &storage_cache.second_token_reserve, - ); - - let initial_k = self.calculate_k_constant( - &storage_cache.first_token_reserve, - &storage_cache.second_token_reserve, - ); - - let mut swap_context = SwapContext::new( - token_in, - amount_in, - token_out, - amount_out_min, - swap_tokens_order, - ); - self.perform_swap_fixed_input(&mut swap_context, &mut storage_cache); - - let new_k = self.calculate_k_constant( - &storage_cache.first_token_reserve, - &storage_cache.second_token_reserve, - ); - require!(initial_k <= new_k, ERROR_K_INVARIANT_FAILED); - - if swap_context.fee_amount > 0 { - self.send_fee( - &mut storage_cache, - swap_context.swap_tokens_order, - &swap_context.input_token_id, - &swap_context.fee_amount, - ); - } - - let caller = self.blockchain().get_caller(); - let output_payments = self.build_swap_output_payments(&swap_context); - self.send_multiple_tokens_if_not_zero(&caller, &output_payments); - - self.emit_swap_event(&storage_cache, swap_context); - - self.build_swap_fixed_input_results(output_payments) - } - - #[payable("*")] - #[endpoint(swapTokensFixedOutput)] - fn swap_tokens_fixed_output( - &self, - token_out: TokenIdentifier, - amount_out: BigUint, - ) -> SwapTokensFixedOutputResultType { - require!(amount_out > 0, ERROR_INVALID_ARGS); - - let mut storage_cache = StorageCache::new(self); - let (token_in, _, amount_in_max) = self.call_value().single_esdt().into_tuple(); - let swap_tokens_order = storage_cache.get_swap_tokens_order(&token_in, &token_out); - - require!( - self.can_swap(storage_cache.contract_state), - ERROR_SWAP_NOT_ENABLED - ); - - let reserve_out = storage_cache.get_mut_reserve_out(swap_tokens_order); - require!(*reserve_out > amount_out, ERROR_NOT_ENOUGH_RESERVE); - - self.update_safe_price( - &storage_cache.first_token_reserve, - &storage_cache.second_token_reserve, - ); - - let initial_k = self.calculate_k_constant( - &storage_cache.first_token_reserve, - &storage_cache.second_token_reserve, - ); - - let mut swap_context = SwapContext::new( - token_in, - amount_in_max, - token_out, - amount_out, - swap_tokens_order, - ); - self.perform_swap_fixed_output(&mut swap_context, &mut storage_cache); - - let new_k = self.calculate_k_constant( - &storage_cache.first_token_reserve, - &storage_cache.second_token_reserve, - ); - require!(initial_k <= new_k, ERROR_K_INVARIANT_FAILED); - - if swap_context.fee_amount > 0 { - self.send_fee( - &mut storage_cache, - swap_context.swap_tokens_order, - &swap_context.input_token_id, - &swap_context.fee_amount, - ); - } - - let caller = self.blockchain().get_caller(); - let output_payments = self.build_swap_output_payments(&swap_context); - self.send_multiple_tokens_if_not_zero(&caller, &output_payments); - - self.emit_swap_event(&storage_cache, swap_context); - - self.build_swap_fixed_output_results(output_payments) - } + #[endpoint] + fn upgrade(&self) {} #[endpoint(setLpTokenIdentifier)] fn set_lp_token_identifier(&self, token_identifier: TokenIdentifier) { @@ -577,175 +121,4 @@ pub trait Pair: ); self.lp_token_identifier().set(&token_identifier); } - - #[view(getTokensForGivenPosition)] - fn get_tokens_for_given_position( - &self, - liquidity: BigUint, - ) -> MultiValue2, EsdtTokenPayment> { - self.get_both_tokens_for_given_position(liquidity) - } - - #[view(getReservesAndTotalSupply)] - fn get_reserves_and_total_supply(&self) -> MultiValue3 { - let first_token_id = self.first_token_id().get(); - let second_token_id = self.second_token_id().get(); - let first_token_reserve = self.pair_reserve(&first_token_id).get(); - let second_token_reserve = self.pair_reserve(&second_token_id).get(); - let total_supply = self.lp_token_supply().get(); - (first_token_reserve, second_token_reserve, total_supply).into() - } - - #[view(getAmountOut)] - fn get_amount_out_view(&self, token_in: TokenIdentifier, amount_in: BigUint) -> BigUint { - require!(amount_in > 0u64, ERROR_ZERO_AMOUNT); - - let first_token_id = self.first_token_id().get(); - let second_token_id = self.second_token_id().get(); - let first_token_reserve = self.pair_reserve(&first_token_id).get(); - let second_token_reserve = self.pair_reserve(&second_token_id).get(); - - if token_in == first_token_id { - require!(second_token_reserve > 0u64, ERROR_NOT_ENOUGH_RESERVE); - let amount_out = - self.get_amount_out(&amount_in, &first_token_reserve, &second_token_reserve); - require!(second_token_reserve > amount_out, ERROR_NOT_ENOUGH_RESERVE); - amount_out - } else if token_in == second_token_id { - require!(first_token_reserve > 0u64, ERROR_NOT_ENOUGH_RESERVE); - let amount_out = - self.get_amount_out(&amount_in, &second_token_reserve, &first_token_reserve); - require!(first_token_reserve > amount_out, ERROR_NOT_ENOUGH_RESERVE); - amount_out - } else { - sc_panic!(ERROR_UNKNOWN_TOKEN); - } - } - - #[view(getAmountIn)] - fn get_amount_in_view(&self, token_wanted: TokenIdentifier, amount_wanted: BigUint) -> BigUint { - require!(amount_wanted > 0u64, ERROR_ZERO_AMOUNT); - - let first_token_id = self.first_token_id().get(); - let second_token_id = self.second_token_id().get(); - let first_token_reserve = self.pair_reserve(&first_token_id).get(); - let second_token_reserve = self.pair_reserve(&second_token_id).get(); - - if token_wanted == first_token_id { - require!( - first_token_reserve > amount_wanted, - ERROR_NOT_ENOUGH_RESERVE - ); - - self.get_amount_in(&amount_wanted, &second_token_reserve, &first_token_reserve) - } else if token_wanted == second_token_id { - require!( - second_token_reserve > amount_wanted, - ERROR_NOT_ENOUGH_RESERVE - ); - - self.get_amount_in(&amount_wanted, &first_token_reserve, &second_token_reserve) - } else { - sc_panic!(ERROR_UNKNOWN_TOKEN); - } - } - - #[view(getEquivalent)] - fn get_equivalent(&self, token_in: TokenIdentifier, amount_in: BigUint) -> BigUint { - require!(amount_in > 0u64, ERROR_ZERO_AMOUNT); - let zero = BigUint::zero(); - - let first_token_id = self.first_token_id().get(); - let second_token_id = self.second_token_id().get(); - let first_token_reserve = self.pair_reserve(&first_token_id).get(); - let second_token_reserve = self.pair_reserve(&second_token_id).get(); - if first_token_reserve == 0u64 || second_token_reserve == 0u64 { - return zero; - } - - if token_in == first_token_id { - self.quote(&amount_in, &first_token_reserve, &second_token_reserve) - } else if token_in == second_token_id { - self.quote(&amount_in, &second_token_reserve, &first_token_reserve) - } else { - sc_panic!(ERROR_UNKNOWN_TOKEN); - } - } - - #[inline] - fn is_state_active(&self, state: State) -> bool { - state == State::Active || state == State::PartialActive - } - - #[inline] - fn can_swap(&self, state: State) -> bool { - state == State::Active - } - - fn perform_swap_fixed_input( - &self, - context: &mut SwapContext, - storage_cache: &mut StorageCache, - ) { - context.final_input_amount = context.input_token_amount.clone(); - - let reserve_in = storage_cache.get_reserve_in(context.swap_tokens_order); - let reserve_out = storage_cache.get_reserve_out(context.swap_tokens_order); - - let amount_out_optimal = - self.get_amount_out(&context.input_token_amount, reserve_in, reserve_out); - require!( - amount_out_optimal >= context.output_token_amount, - ERROR_SLIPPAGE_EXCEEDED - ); - require!(*reserve_out > amount_out_optimal, ERROR_NOT_ENOUGH_RESERVE); - require!(amount_out_optimal != 0u64, ERROR_ZERO_AMOUNT); - - context.final_output_amount = amount_out_optimal; - - let mut amount_in_after_fee = context.input_token_amount.clone(); - if self.is_fee_enabled() { - let fee_amount = self.get_special_fee_from_input(&amount_in_after_fee); - amount_in_after_fee -= &fee_amount; - - context.fee_amount = fee_amount; - } - - *storage_cache.get_mut_reserve_in(context.swap_tokens_order) += amount_in_after_fee; - *storage_cache.get_mut_reserve_out(context.swap_tokens_order) -= - &context.final_output_amount; - } - - fn perform_swap_fixed_output( - &self, - context: &mut SwapContext, - storage_cache: &mut StorageCache, - ) { - context.final_output_amount = context.output_token_amount.clone(); - - let reserve_in = storage_cache.get_reserve_in(context.swap_tokens_order); - let reserve_out = storage_cache.get_reserve_out(context.swap_tokens_order); - - let amount_in_optimal = - self.get_amount_in(&context.output_token_amount, reserve_in, reserve_out); - require!( - amount_in_optimal <= context.input_token_amount, - ERROR_SLIPPAGE_EXCEEDED - ); - require!(amount_in_optimal != 0, ERROR_ZERO_AMOUNT); - - context.final_input_amount = amount_in_optimal.clone(); - - let mut amount_in_optimal_after_fee = amount_in_optimal; - if self.is_fee_enabled() { - let fee_amount = self.get_special_fee_from_input(&amount_in_optimal_after_fee); - amount_in_optimal_after_fee -= &fee_amount; - - context.fee_amount = fee_amount; - } - - *storage_cache.get_mut_reserve_in(context.swap_tokens_order) += amount_in_optimal_after_fee; - *storage_cache.get_mut_reserve_out(context.swap_tokens_order) -= - &context.final_output_amount; - } } diff --git a/dex/pair/src/liquidity_pool.rs b/dex/pair/src/liquidity_pool.rs index ba8d460f0..4797772e3 100644 --- a/dex/pair/src/liquidity_pool.rs +++ b/dex/pair/src/liquidity_pool.rs @@ -139,11 +139,6 @@ pub trait LiquidityPoolModule: ); if &second_token_amount_optimal <= second_token_amount_desired { - require!( - second_token_amount_optimal >= context.second_token_amount_min, - ERROR_INSUFFICIENT_SECOND_TOKEN - ); - context.first_token_optimal_amount = first_token_amount_desired.clone(); context.second_token_optimal_amount = second_token_amount_optimal; } else { @@ -156,14 +151,17 @@ pub trait LiquidityPoolModule: &first_token_amount_optimal <= first_token_amount_desired, ERROR_OPTIMAL_GRATER_THAN_PAID ); - require!( - first_token_amount_optimal >= context.first_token_amount_min, - ERROR_INSUFFICIENT_FIRST_TOKEN - ); - context.first_token_optimal_amount = first_token_amount_optimal; context.second_token_optimal_amount = second_token_amount_desired.clone(); } + require!( + context.first_token_optimal_amount >= context.first_token_amount_min, + ERROR_INSUFFICIENT_FIRST_TOKEN + ); + require!( + context.second_token_optimal_amount >= context.second_token_amount_min, + ERROR_INSUFFICIENT_SECOND_TOKEN + ); } fn get_token_for_given_position( diff --git a/dex/pair/src/pair_actions/add_liq.rs b/dex/pair/src/pair_actions/add_liq.rs new file mode 100644 index 000000000..769e805f4 --- /dev/null +++ b/dex/pair/src/pair_actions/add_liq.rs @@ -0,0 +1,124 @@ +use crate::{ + contexts::add_liquidity::AddLiquidityContext, StorageCache, ERROR_BAD_PAYMENT_TOKENS, + ERROR_INITIAL_LIQUIDITY_NOT_ADDED, ERROR_INVALID_ARGS, ERROR_K_INVARIANT_FAILED, + ERROR_LP_TOKEN_NOT_ISSUED, ERROR_NOT_ACTIVE, +}; + +use super::common_result_types::AddLiquidityResultType; + +multiversx_sc::imports!(); + +#[multiversx_sc::module] +pub trait AddLiquidityModule: + crate::liquidity_pool::LiquidityPoolModule + + crate::amm::AmmModule + + crate::contexts::output_builder::OutputBuilderModule + + crate::locking_wrapper::LockingWrapperModule + + crate::events::EventsModule + + crate::safe_price::SafePriceModule + + crate::config::ConfigModule + + token_send::TokenSendModule + + permissions_module::PermissionsModule + + pausable::PausableModule + + super::common_methods::CommonMethodsModule + + utils::UtilsModule +{ + #[payable("*")] + #[endpoint(addLiquidity)] + fn add_liquidity( + &self, + first_token_amount_min: BigUint, + second_token_amount_min: BigUint, + ) -> AddLiquidityResultType { + require!( + first_token_amount_min > 0 && second_token_amount_min > 0, + ERROR_INVALID_ARGS + ); + + let mut storage_cache = StorageCache::new(self); + let caller = self.blockchain().get_caller(); + + let [first_payment, second_payment] = self.call_value().multi_esdt(); + require!( + first_payment.token_identifier == storage_cache.first_token_id + && first_payment.amount > 0, + ERROR_BAD_PAYMENT_TOKENS + ); + require!( + second_payment.token_identifier == storage_cache.second_token_id + && second_payment.amount > 0, + ERROR_BAD_PAYMENT_TOKENS + ); + require!( + self.is_state_active(storage_cache.contract_state), + ERROR_NOT_ACTIVE + ); + require!( + storage_cache.lp_token_id.is_valid_esdt_identifier(), + ERROR_LP_TOKEN_NOT_ISSUED + ); + require!( + self.initial_liquidity_adder().get().is_none() || storage_cache.lp_token_supply != 0, + ERROR_INITIAL_LIQUIDITY_NOT_ADDED + ); + + self.update_safe_price( + &storage_cache.first_token_reserve, + &storage_cache.second_token_reserve, + ); + + let initial_k = self.calculate_k_constant( + &storage_cache.first_token_reserve, + &storage_cache.second_token_reserve, + ); + + let mut add_liq_context = AddLiquidityContext::new( + first_payment, + second_payment, + first_token_amount_min, + second_token_amount_min, + ); + self.set_optimal_amounts(&mut add_liq_context, &storage_cache); + + add_liq_context.liq_added = if storage_cache.lp_token_supply == 0u64 { + self.pool_add_initial_liquidity( + &add_liq_context.first_token_optimal_amount, + &add_liq_context.second_token_optimal_amount, + &mut storage_cache, + ) + } else { + self.pool_add_liquidity( + &add_liq_context.first_token_optimal_amount, + &add_liq_context.second_token_optimal_amount, + &mut storage_cache, + ) + }; + + let new_k = self.calculate_k_constant( + &storage_cache.first_token_reserve, + &storage_cache.second_token_reserve, + ); + require!(initial_k <= new_k, ERROR_K_INVARIANT_FAILED); + + self.send() + .esdt_local_mint(&storage_cache.lp_token_id, 0, &add_liq_context.liq_added); + + let lp_payment = EsdtTokenPayment::new( + storage_cache.lp_token_id.clone(), + 0, + add_liq_context.liq_added.clone(), + ); + + let mut output_payments = + self.build_add_liq_output_payments(&storage_cache, &add_liq_context); + output_payments.push(lp_payment); + + self.send_multiple_tokens_if_not_zero(&caller, &output_payments); + + let output = self.build_add_liq_results(&storage_cache, &add_liq_context); + + self.emit_add_liquidity_event(&storage_cache, add_liq_context); + + output + } +} diff --git a/dex/pair/src/pair_actions/common_methods.rs b/dex/pair/src/pair_actions/common_methods.rs new file mode 100644 index 000000000..8839a85d5 --- /dev/null +++ b/dex/pair/src/pair_actions/common_methods.rs @@ -0,0 +1,16 @@ +use pausable::State; + +multiversx_sc::imports!(); + +#[multiversx_sc::module] +pub trait CommonMethodsModule { + #[inline] + fn is_state_active(&self, state: State) -> bool { + state == State::Active || state == State::PartialActive + } + + #[inline] + fn can_swap(&self, state: State) -> bool { + state == State::Active + } +} diff --git a/dex/pair/src/pair_actions/common_result_types.rs b/dex/pair/src/pair_actions/common_result_types.rs new file mode 100644 index 000000000..7fb6407b0 --- /dev/null +++ b/dex/pair/src/pair_actions/common_result_types.rs @@ -0,0 +1,10 @@ +multiversx_sc::imports!(); + +pub type AddLiquidityResultType = + MultiValue3, EsdtTokenPayment, EsdtTokenPayment>; + +pub type RemoveLiquidityResultType = MultiValue2, EsdtTokenPayment>; + +pub type SwapTokensFixedInputResultType = EsdtTokenPayment; + +pub type SwapTokensFixedOutputResultType = MultiValue2, EsdtTokenPayment>; diff --git a/dex/pair/src/pair_actions/initial_liq.rs b/dex/pair/src/pair_actions/initial_liq.rs new file mode 100644 index 000000000..b418fec2a --- /dev/null +++ b/dex/pair/src/pair_actions/initial_liq.rs @@ -0,0 +1,92 @@ +use common_errors::ERROR_PERMISSION_DENIED; +use pausable::State; + +use crate::{ + contexts::add_liquidity::AddLiquidityContext, StorageCache, ERROR_ACTIVE, + ERROR_BAD_PAYMENT_TOKENS, ERROR_INITIAL_LIQUIDITY_ALREADY_ADDED, +}; + +use super::common_result_types::AddLiquidityResultType; + +multiversx_sc::imports!(); + +#[multiversx_sc::module] +pub trait InitialLiquidityModule: + crate::liquidity_pool::LiquidityPoolModule + + crate::amm::AmmModule + + crate::contexts::output_builder::OutputBuilderModule + + crate::locking_wrapper::LockingWrapperModule + + crate::events::EventsModule + + crate::config::ConfigModule + + token_send::TokenSendModule + + permissions_module::PermissionsModule + + pausable::PausableModule + + super::common_methods::CommonMethodsModule + + utils::UtilsModule +{ + #[payable("*")] + #[endpoint(addInitialLiquidity)] + fn add_initial_liquidity(&self) -> AddLiquidityResultType { + let mut storage_cache = StorageCache::new(self); + let caller = self.blockchain().get_caller(); + + let opt_initial_liq_adder = self.initial_liquidity_adder().get(); + if let Some(initial_liq_adder) = opt_initial_liq_adder { + require!(caller == initial_liq_adder, ERROR_PERMISSION_DENIED); + } + + let [first_payment, second_payment] = self.call_value().multi_esdt(); + require!( + first_payment.token_identifier == storage_cache.first_token_id + && first_payment.amount > 0, + ERROR_BAD_PAYMENT_TOKENS + ); + require!( + second_payment.token_identifier == storage_cache.second_token_id + && second_payment.amount > 0, + ERROR_BAD_PAYMENT_TOKENS + ); + require!( + !self.is_state_active(storage_cache.contract_state), + ERROR_ACTIVE + ); + require!( + storage_cache.lp_token_supply == 0, + ERROR_INITIAL_LIQUIDITY_ALREADY_ADDED + ); + + let first_token_optimal_amount = &first_payment.amount; + let second_token_optimal_amount = &second_payment.amount; + let liq_added = self.pool_add_initial_liquidity( + first_token_optimal_amount, + second_token_optimal_amount, + &mut storage_cache, + ); + + self.send() + .esdt_local_mint(&storage_cache.lp_token_id, 0, &liq_added); + + let lp_payment = + EsdtTokenPayment::new(storage_cache.lp_token_id.clone(), 0, liq_added.clone()); + + self.send() + .direct_non_zero_esdt_payment(&caller, &lp_payment); + + self.state().set(State::PartialActive); + + let add_liq_context = AddLiquidityContext { + first_payment: first_payment.clone(), + second_payment: second_payment.clone(), + first_token_amount_min: BigUint::from(1u32), + second_token_amount_min: BigUint::from(1u32), + first_token_optimal_amount: first_token_optimal_amount.clone(), + second_token_optimal_amount: second_token_optimal_amount.clone(), + liq_added, + }; + let output = self.build_add_initial_liq_results(&storage_cache, &add_liq_context); + + self.emit_add_liquidity_event(&storage_cache, add_liq_context); + + output + } +} diff --git a/dex/pair/src/pair_actions/mod.rs b/dex/pair/src/pair_actions/mod.rs new file mode 100644 index 000000000..277650055 --- /dev/null +++ b/dex/pair/src/pair_actions/mod.rs @@ -0,0 +1,7 @@ +pub mod add_liq; +pub mod common_methods; +pub mod common_result_types; +pub mod initial_liq; +pub mod remove_liq; +pub mod swap; +pub mod views; diff --git a/dex/pair/src/pair_actions/remove_liq.rs b/dex/pair/src/pair_actions/remove_liq.rs new file mode 100644 index 000000000..5ee58d591 --- /dev/null +++ b/dex/pair/src/pair_actions/remove_liq.rs @@ -0,0 +1,157 @@ +use crate::{ + contexts::remove_liquidity::RemoveLiquidityContext, StorageCache, SwapTokensOrder, + ERROR_BAD_PAYMENT_TOKENS, ERROR_INVALID_ARGS, ERROR_K_INVARIANT_FAILED, + ERROR_LP_TOKEN_NOT_ISSUED, ERROR_NOT_ACTIVE, ERROR_NOT_WHITELISTED, ERROR_SLIPPAGE_ON_REMOVE, +}; + +use super::common_result_types::RemoveLiquidityResultType; + +multiversx_sc::imports!(); + +#[multiversx_sc::module] +pub trait RemoveLiquidityModule: + crate::liquidity_pool::LiquidityPoolModule + + crate::amm::AmmModule + + crate::contexts::output_builder::OutputBuilderModule + + crate::locking_wrapper::LockingWrapperModule + + crate::events::EventsModule + + crate::safe_price::SafePriceModule + + crate::fee::FeeModule + + crate::config::ConfigModule + + token_send::TokenSendModule + + permissions_module::PermissionsModule + + pausable::PausableModule + + super::common_methods::CommonMethodsModule + + utils::UtilsModule +{ + #[payable("*")] + #[endpoint(removeLiquidity)] + fn remove_liquidity( + &self, + first_token_amount_min: BigUint, + second_token_amount_min: BigUint, + ) -> RemoveLiquidityResultType { + require!( + first_token_amount_min > 0 && second_token_amount_min > 0, + ERROR_INVALID_ARGS + ); + + let mut storage_cache = StorageCache::new(self); + let caller = self.blockchain().get_caller(); + let payment = self.call_value().single_esdt(); + + require!( + self.is_state_active(storage_cache.contract_state), + ERROR_NOT_ACTIVE + ); + require!( + storage_cache.lp_token_id.is_valid_esdt_identifier(), + ERROR_LP_TOKEN_NOT_ISSUED + ); + require!( + payment.token_identifier == storage_cache.lp_token_id && payment.amount > 0, + ERROR_BAD_PAYMENT_TOKENS + ); + + self.update_safe_price( + &storage_cache.first_token_reserve, + &storage_cache.second_token_reserve, + ); + + let initial_k = self.calculate_k_constant( + &storage_cache.first_token_reserve, + &storage_cache.second_token_reserve, + ); + + let mut remove_liq_context = RemoveLiquidityContext::new( + payment.amount, + first_token_amount_min, + second_token_amount_min, + ); + self.pool_remove_liquidity(&mut remove_liq_context, &mut storage_cache); + + let new_k = self.calculate_k_constant( + &storage_cache.first_token_reserve, + &storage_cache.second_token_reserve, + ); + require!(new_k <= initial_k, ERROR_K_INVARIANT_FAILED); + + self.burn( + &storage_cache.lp_token_id, + &remove_liq_context.lp_token_payment_amount, + ); + + let output_payments = + self.build_remove_liq_output_payments(&storage_cache, &remove_liq_context); + + let first_payment_after = output_payments.get(0); + let second_payment_after = output_payments.get(1); + require!( + first_payment_after.amount >= remove_liq_context.first_token_amount_min, + ERROR_SLIPPAGE_ON_REMOVE + ); + require!( + second_payment_after.amount >= remove_liq_context.second_token_amount_min, + ERROR_SLIPPAGE_ON_REMOVE + ); + + self.send_multiple_tokens_if_not_zero(&caller, &output_payments); + + self.emit_remove_liquidity_event(&storage_cache, remove_liq_context); + + self.build_remove_liq_results(output_payments) + } + + #[payable("*")] + #[endpoint(removeLiquidityAndBuyBackAndBurnToken)] + fn remove_liquidity_and_burn_token(&self, token_to_buyback_and_burn: TokenIdentifier) { + let mut storage_cache = StorageCache::new(self); + let caller = self.blockchain().get_caller(); + let payment = self.call_value().single_esdt(); + + require!(self.whitelist().contains(&caller), ERROR_NOT_WHITELISTED); + require!( + storage_cache.lp_token_id.is_valid_esdt_identifier(), + ERROR_LP_TOKEN_NOT_ISSUED + ); + require!( + payment.token_identifier == storage_cache.lp_token_id && payment.amount > 0, + ERROR_BAD_PAYMENT_TOKENS + ); + + self.update_safe_price( + &storage_cache.first_token_reserve, + &storage_cache.second_token_reserve, + ); + + let mut remove_liq_context = + RemoveLiquidityContext::new(payment.amount, BigUint::from(1u64), BigUint::from(1u64)); + self.pool_remove_liquidity(&mut remove_liq_context, &mut storage_cache); + + self.burn( + &storage_cache.lp_token_id, + &remove_liq_context.lp_token_payment_amount, + ); + + let dest_address = ManagedAddress::zero(); + let first_token_id = storage_cache.first_token_id.clone(); + self.send_fee_slice( + &mut storage_cache, + SwapTokensOrder::PoolOrder, + &first_token_id, + &remove_liq_context.first_token_amount_removed, + &dest_address, + &token_to_buyback_and_burn, + ); + + let second_token_id = storage_cache.second_token_id.clone(); + self.send_fee_slice( + &mut storage_cache, + SwapTokensOrder::ReverseOrder, + &second_token_id, + &remove_liq_context.second_token_amount_removed, + &dest_address, + &token_to_buyback_and_burn, + ); + } +} diff --git a/dex/pair/src/pair_actions/swap.rs b/dex/pair/src/pair_actions/swap.rs new file mode 100644 index 000000000..f1ec88d94 --- /dev/null +++ b/dex/pair/src/pair_actions/swap.rs @@ -0,0 +1,295 @@ +use crate::{ + contexts::swap::SwapContext, StorageCache, ERROR_INVALID_ARGS, ERROR_K_INVARIANT_FAILED, + ERROR_NOT_ENOUGH_RESERVE, ERROR_NOT_WHITELISTED, ERROR_SLIPPAGE_EXCEEDED, + ERROR_SWAP_NOT_ENABLED, ERROR_ZERO_AMOUNT, +}; + +use super::common_result_types::{SwapTokensFixedInputResultType, SwapTokensFixedOutputResultType}; + +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +#[derive(TypeAbi, TopEncode, TopDecode, NestedEncode, NestedDecode, Clone, Copy)] +pub enum SwapType { + FixedInput, + FixedOutput, +} + +#[multiversx_sc::module] +pub trait SwapModule: + crate::liquidity_pool::LiquidityPoolModule + + crate::amm::AmmModule + + crate::contexts::output_builder::OutputBuilderModule + + crate::locking_wrapper::LockingWrapperModule + + crate::events::EventsModule + + crate::safe_price::SafePriceModule + + crate::fee::FeeModule + + crate::config::ConfigModule + + token_send::TokenSendModule + + permissions_module::PermissionsModule + + pausable::PausableModule + + super::common_methods::CommonMethodsModule + + utils::UtilsModule +{ + #[payable("*")] + #[endpoint(swapNoFeeAndForward)] + fn swap_no_fee(&self, token_out: TokenIdentifier, destination_address: ManagedAddress) { + let caller = self.blockchain().get_caller(); + require!(self.whitelist().contains(&caller), ERROR_NOT_WHITELISTED); + + let mut storage_cache = StorageCache::new(self); + let payment = self.call_value().single_esdt(); + let swap_tokens_order = + storage_cache.get_swap_tokens_order(&payment.token_identifier, &token_out); + + require!( + self.can_swap(storage_cache.contract_state), + ERROR_SWAP_NOT_ENABLED + ); + + self.update_safe_price( + &storage_cache.first_token_reserve, + &storage_cache.second_token_reserve, + ); + + let initial_k = self.calculate_k_constant( + &storage_cache.first_token_reserve, + &storage_cache.second_token_reserve, + ); + + let mut swap_context = SwapContext::new( + payment.token_identifier, + payment.amount.clone(), + token_out, + BigUint::from(1u32), + swap_tokens_order, + ); + swap_context.final_input_amount = payment.amount; + + let amount_out = self.swap_safe_no_fee( + &mut storage_cache, + swap_context.swap_tokens_order, + &swap_context.final_input_amount, + ); + require!(amount_out > 0u64, ERROR_ZERO_AMOUNT); + + swap_context.final_output_amount = amount_out; + + let new_k = self.calculate_k_constant( + &storage_cache.first_token_reserve, + &storage_cache.second_token_reserve, + ); + require!(initial_k <= new_k, ERROR_K_INVARIANT_FAILED); + + self.burn( + &swap_context.output_token_id, + &swap_context.final_output_amount, + ); + + self.emit_swap_no_fee_and_forward_event(swap_context, destination_address); + } + + #[payable("*")] + #[endpoint(swapTokensFixedInput)] + fn swap_tokens_fixed_input( + &self, + token_out: TokenIdentifier, + amount_out_min: BigUint, + ) -> SwapTokensFixedInputResultType { + require!(amount_out_min > 0, ERROR_INVALID_ARGS); + + let mut storage_cache = StorageCache::new(self); + let payment = self.call_value().single_esdt(); + let swap_tokens_order = + storage_cache.get_swap_tokens_order(&payment.token_identifier, &token_out); + + require!( + self.can_swap(storage_cache.contract_state), + ERROR_SWAP_NOT_ENABLED + ); + + let reserve_out = storage_cache.get_mut_reserve_out(swap_tokens_order); + require!(*reserve_out > amount_out_min, ERROR_NOT_ENOUGH_RESERVE); + + self.update_safe_price( + &storage_cache.first_token_reserve, + &storage_cache.second_token_reserve, + ); + + let initial_k = self.calculate_k_constant( + &storage_cache.first_token_reserve, + &storage_cache.second_token_reserve, + ); + + let mut swap_context = SwapContext::new( + payment.token_identifier, + payment.amount, + token_out, + amount_out_min, + swap_tokens_order, + ); + self.perform_swap_fixed_input(&mut swap_context, &mut storage_cache); + + let new_k = self.calculate_k_constant( + &storage_cache.first_token_reserve, + &storage_cache.second_token_reserve, + ); + require!(initial_k <= new_k, ERROR_K_INVARIANT_FAILED); + + if swap_context.fee_amount > 0 { + self.send_fee( + &mut storage_cache, + swap_context.swap_tokens_order, + &swap_context.input_token_id, + &swap_context.fee_amount, + ); + } + + let caller = self.blockchain().get_caller(); + let output_payments = self.build_swap_output_payments(&swap_context); + + require!( + output_payments.get(0).amount >= swap_context.output_token_amount, + ERROR_SLIPPAGE_EXCEEDED + ); + + self.send_multiple_tokens_if_not_zero(&caller, &output_payments); + + self.emit_swap_event(&storage_cache, swap_context); + + self.build_swap_fixed_input_results(output_payments) + } + + #[payable("*")] + #[endpoint(swapTokensFixedOutput)] + fn swap_tokens_fixed_output( + &self, + token_out: TokenIdentifier, + amount_out: BigUint, + ) -> SwapTokensFixedOutputResultType { + require!(amount_out > 0, ERROR_INVALID_ARGS); + + let mut storage_cache = StorageCache::new(self); + let payment = self.call_value().single_esdt(); + let swap_tokens_order = + storage_cache.get_swap_tokens_order(&payment.token_identifier, &token_out); + + require!( + self.can_swap(storage_cache.contract_state), + ERROR_SWAP_NOT_ENABLED + ); + + let reserve_out = storage_cache.get_mut_reserve_out(swap_tokens_order); + require!(*reserve_out > amount_out, ERROR_NOT_ENOUGH_RESERVE); + + self.update_safe_price( + &storage_cache.first_token_reserve, + &storage_cache.second_token_reserve, + ); + + let initial_k = self.calculate_k_constant( + &storage_cache.first_token_reserve, + &storage_cache.second_token_reserve, + ); + + let mut swap_context = SwapContext::new( + payment.token_identifier, + payment.amount, + token_out, + amount_out, + swap_tokens_order, + ); + self.perform_swap_fixed_output(&mut swap_context, &mut storage_cache); + + let new_k = self.calculate_k_constant( + &storage_cache.first_token_reserve, + &storage_cache.second_token_reserve, + ); + require!(initial_k <= new_k, ERROR_K_INVARIANT_FAILED); + + if swap_context.fee_amount > 0 { + self.send_fee( + &mut storage_cache, + swap_context.swap_tokens_order, + &swap_context.input_token_id, + &swap_context.fee_amount, + ); + } + + let caller = self.blockchain().get_caller(); + let output_payments = self.build_swap_output_payments(&swap_context); + + self.send_multiple_tokens_if_not_zero(&caller, &output_payments); + + self.emit_swap_event(&storage_cache, swap_context); + + self.build_swap_fixed_output_results(output_payments) + } + + fn perform_swap_fixed_input( + &self, + context: &mut SwapContext, + storage_cache: &mut StorageCache, + ) { + context.final_input_amount = context.input_token_amount.clone(); + + let reserve_in = storage_cache.get_reserve_in(context.swap_tokens_order); + let reserve_out = storage_cache.get_reserve_out(context.swap_tokens_order); + + let amount_out_optimal = + self.get_amount_out(&context.input_token_amount, reserve_in, reserve_out); + require!( + amount_out_optimal >= context.output_token_amount, + ERROR_SLIPPAGE_EXCEEDED + ); + require!(*reserve_out > amount_out_optimal, ERROR_NOT_ENOUGH_RESERVE); + require!(amount_out_optimal != 0u64, ERROR_ZERO_AMOUNT); + + context.final_output_amount = amount_out_optimal; + + let mut amount_in_after_fee = context.input_token_amount.clone(); + if self.is_fee_enabled() { + let fee_amount = self.get_special_fee_from_input(&amount_in_after_fee); + amount_in_after_fee -= &fee_amount; + + context.fee_amount = fee_amount; + } + + *storage_cache.get_mut_reserve_in(context.swap_tokens_order) += amount_in_after_fee; + *storage_cache.get_mut_reserve_out(context.swap_tokens_order) -= + &context.final_output_amount; + } + + fn perform_swap_fixed_output( + &self, + context: &mut SwapContext, + storage_cache: &mut StorageCache, + ) { + context.final_output_amount = context.output_token_amount.clone(); + + let reserve_in = storage_cache.get_reserve_in(context.swap_tokens_order); + let reserve_out = storage_cache.get_reserve_out(context.swap_tokens_order); + + let amount_in_optimal = + self.get_amount_in(&context.output_token_amount, reserve_in, reserve_out); + require!( + amount_in_optimal <= context.input_token_amount, + ERROR_SLIPPAGE_EXCEEDED + ); + require!(amount_in_optimal != 0, ERROR_ZERO_AMOUNT); + + context.final_input_amount = amount_in_optimal.clone(); + + let mut amount_in_optimal_after_fee = amount_in_optimal; + if self.is_fee_enabled() { + let fee_amount = self.get_special_fee_from_input(&amount_in_optimal_after_fee); + amount_in_optimal_after_fee -= &fee_amount; + + context.fee_amount = fee_amount; + } + + *storage_cache.get_mut_reserve_in(context.swap_tokens_order) += amount_in_optimal_after_fee; + *storage_cache.get_mut_reserve_out(context.swap_tokens_order) -= + &context.final_output_amount; + } +} diff --git a/dex/pair/src/pair_actions/views.rs b/dex/pair/src/pair_actions/views.rs new file mode 100644 index 000000000..878b3bd5e --- /dev/null +++ b/dex/pair/src/pair_actions/views.rs @@ -0,0 +1,113 @@ +use crate::{ERROR_NOT_ENOUGH_RESERVE, ERROR_UNKNOWN_TOKEN, ERROR_ZERO_AMOUNT}; + +multiversx_sc::imports!(); + +#[multiversx_sc::module] +pub trait ViewsModule: + crate::liquidity_pool::LiquidityPoolModule + + crate::amm::AmmModule + + crate::contexts::output_builder::OutputBuilderModule + + crate::locking_wrapper::LockingWrapperModule + + crate::events::EventsModule + + crate::safe_price::SafePriceModule + + crate::fee::FeeModule + + crate::config::ConfigModule + + token_send::TokenSendModule + + permissions_module::PermissionsModule + + pausable::PausableModule + + super::common_methods::CommonMethodsModule +{ + #[view(getTokensForGivenPosition)] + fn get_tokens_for_given_position( + &self, + liquidity: BigUint, + ) -> MultiValue2, EsdtTokenPayment> { + self.get_both_tokens_for_given_position(liquidity) + } + + #[view(getReservesAndTotalSupply)] + fn get_reserves_and_total_supply(&self) -> MultiValue3 { + let first_token_id = self.first_token_id().get(); + let second_token_id = self.second_token_id().get(); + let first_token_reserve = self.pair_reserve(&first_token_id).get(); + let second_token_reserve = self.pair_reserve(&second_token_id).get(); + let total_supply = self.lp_token_supply().get(); + (first_token_reserve, second_token_reserve, total_supply).into() + } + + #[view(getAmountOut)] + fn get_amount_out_view(&self, token_in: TokenIdentifier, amount_in: BigUint) -> BigUint { + require!(amount_in > 0u64, ERROR_ZERO_AMOUNT); + + let first_token_id = self.first_token_id().get(); + let second_token_id = self.second_token_id().get(); + let first_token_reserve = self.pair_reserve(&first_token_id).get(); + let second_token_reserve = self.pair_reserve(&second_token_id).get(); + + if token_in == first_token_id { + require!(second_token_reserve > 0u64, ERROR_NOT_ENOUGH_RESERVE); + let amount_out = + self.get_amount_out(&amount_in, &first_token_reserve, &second_token_reserve); + require!(second_token_reserve > amount_out, ERROR_NOT_ENOUGH_RESERVE); + amount_out + } else if token_in == second_token_id { + require!(first_token_reserve > 0u64, ERROR_NOT_ENOUGH_RESERVE); + let amount_out = + self.get_amount_out(&amount_in, &second_token_reserve, &first_token_reserve); + require!(first_token_reserve > amount_out, ERROR_NOT_ENOUGH_RESERVE); + amount_out + } else { + sc_panic!(ERROR_UNKNOWN_TOKEN); + } + } + + #[view(getAmountIn)] + fn get_amount_in_view(&self, token_wanted: TokenIdentifier, amount_wanted: BigUint) -> BigUint { + require!(amount_wanted > 0u64, ERROR_ZERO_AMOUNT); + + let first_token_id = self.first_token_id().get(); + let second_token_id = self.second_token_id().get(); + let first_token_reserve = self.pair_reserve(&first_token_id).get(); + let second_token_reserve = self.pair_reserve(&second_token_id).get(); + + if token_wanted == first_token_id { + require!( + first_token_reserve > amount_wanted, + ERROR_NOT_ENOUGH_RESERVE + ); + + self.get_amount_in(&amount_wanted, &second_token_reserve, &first_token_reserve) + } else if token_wanted == second_token_id { + require!( + second_token_reserve > amount_wanted, + ERROR_NOT_ENOUGH_RESERVE + ); + + self.get_amount_in(&amount_wanted, &first_token_reserve, &second_token_reserve) + } else { + sc_panic!(ERROR_UNKNOWN_TOKEN); + } + } + + #[view(getEquivalent)] + fn get_equivalent(&self, token_in: TokenIdentifier, amount_in: BigUint) -> BigUint { + require!(amount_in > 0u64, ERROR_ZERO_AMOUNT); + let zero = BigUint::zero(); + + let first_token_id = self.first_token_id().get(); + let second_token_id = self.second_token_id().get(); + let first_token_reserve = self.pair_reserve(&first_token_id).get(); + let second_token_reserve = self.pair_reserve(&second_token_id).get(); + if first_token_reserve == 0u64 || second_token_reserve == 0u64 { + return zero; + } + + if token_in == first_token_id { + self.quote(&amount_in, &first_token_reserve, &second_token_reserve) + } else if token_in == second_token_id { + self.quote(&amount_in, &second_token_reserve, &first_token_reserve) + } else { + sc_panic!(ERROR_UNKNOWN_TOKEN); + } + } +} diff --git a/dex/pair/tests/pair_rs_test.rs b/dex/pair/tests/pair_rs_test.rs index 585093667..a80469ad0 100644 --- a/dex/pair/tests/pair_rs_test.rs +++ b/dex/pair/tests/pair_rs_test.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + mod pair_setup; use fees_collector::{ config::ConfigModule, fees_accumulation::FeesAccumulationModule, FeesCollector, @@ -9,10 +11,12 @@ use multiversx_sc::{ }; use multiversx_sc_scenario::{ managed_address, managed_biguint, managed_token_id, managed_token_id_wrapped, rust_biguint, - whitebox::TxTokenTransfer, DebugApi, + whitebox_legacy::TxTokenTransfer, DebugApi, +}; +use pair::{ + config::MAX_PERCENTAGE, fee::FeeModule, locking_wrapper::LockingWrapperModule, + pair_actions::swap::SwapModule, }; -// use pair::safe_price::MAX_OBSERVATIONS; -use pair::{config::MAX_PERCENTAGE, fee::FeeModule, locking_wrapper::LockingWrapperModule, Pair}; use pair_setup::*; use simple_lock::{ locked_token::{LockedTokenAttributes, LockedTokenModule}, @@ -56,6 +60,35 @@ fn test_swap_fixed_output() { pair_setup.swap_fixed_output(WEGLD_TOKEN_ID, 1_000, MEX_TOKEN_ID, 900, 96); } +#[test] +fn test_perfect_swap_fixed_output() { + let mut pair_setup = PairSetup::new(pair::contract_obj); + + let token_amount = 1_001_000; + + pair_setup.add_liquidity( + token_amount, + 1_000_000, + token_amount, + 1_000_000, + 1_000_000, + token_amount, + token_amount, + ); + + pair_setup.swap_fixed_output(WEGLD_TOKEN_ID, 1_000, MEX_TOKEN_ID, 996, 0); + pair_setup.b_mock.check_esdt_balance( + &pair_setup.user_address, + WEGLD_TOKEN_ID, + &(rust_biguint!(USER_TOTAL_WEGLD_TOKENS - token_amount - 1_000)), + ); + pair_setup.b_mock.check_esdt_balance( + &pair_setup.user_address, + MEX_TOKEN_ID, + &(rust_biguint!(USER_TOTAL_WEGLD_TOKENS - token_amount + 996)), + ); +} + #[test] fn test_safe_price() { let mut pair_setup = PairSetup::new(pair::contract_obj); @@ -954,7 +987,7 @@ fn test_locked_asset() { ) .assert_ok(); - let _ = DebugApi::dummy(); + DebugApi::dummy(); pair_setup.b_mock.check_nft_balance( &pair_setup.user_address, LOCKED_TOKEN_ID, @@ -1075,7 +1108,7 @@ fn add_liquidity_through_simple_lock_proxy() { ); pair_setup.b_mock.set_block_epoch(5); - let _ = DebugApi::dummy(); + DebugApi::dummy(); // lock some tokens first pair_setup diff --git a/dex/pair/tests/pair_setup/mod.rs b/dex/pair/tests/pair_setup/mod.rs index 2032efe24..5ca0fcd84 100644 --- a/dex/pair/tests/pair_setup/mod.rs +++ b/dex/pair/tests/pair_setup/mod.rs @@ -2,9 +2,9 @@ use multiversx_sc::codec::multi_types::MultiValue3; use multiversx_sc::types::{ Address, EsdtLocalRole, EsdtTokenPayment, ManagedAddress, MultiValueEncoded, }; -use multiversx_sc_scenario::whitebox::TxTokenTransfer; +use multiversx_sc_scenario::whitebox_legacy::TxTokenTransfer; use multiversx_sc_scenario::{ - managed_address, managed_biguint, managed_token_id, rust_biguint, whitebox::*, DebugApi, + managed_address, managed_biguint, managed_token_id, rust_biguint, whitebox_legacy::*, DebugApi, }; pub const PAIR_WASM_PATH: &str = "pair/output/pair.wasm"; @@ -20,6 +20,8 @@ pub const USER_TOTAL_MEX_TOKENS: u64 = 5_000_000_000; pub const USER_TOTAL_WEGLD_TOKENS: u64 = 5_000_000_000; use pair::config::ConfigModule as PairConfigModule; +use pair::pair_actions::add_liq::AddLiquidityModule; +use pair::pair_actions::swap::SwapModule; use pair::safe_price_view::*; use pair::*; use pausable::{PausableModule, State}; diff --git a/dex/pair/wasm-pair-full/Cargo.lock b/dex/pair/wasm-pair-full/Cargo.lock index 9077209cd..77c4e33e1 100644 --- a/dex/pair/wasm-pair-full/Cargo.lock +++ b/dex/pair/wasm-pair-full/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common-types" @@ -70,9 +47,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "endian-type" @@ -129,15 +106,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -146,9 +114,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "itertools" @@ -168,12 +136,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.144" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" - [[package]] name = "locking_module" version = "0.0.0" @@ -190,12 +152,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -205,12 +161,11 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -219,20 +174,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -242,9 +196,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -255,21 +209,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -283,19 +236,13 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" - [[package]] name = "pair" version = "0.0.0" @@ -309,6 +256,7 @@ dependencies = [ "permissions_module", "simple-lock", "token_send", + "utils", ] [[package]] @@ -338,18 +286,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.56" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.27" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f4f29d145265ec1c483c7c654450edde0bfe043d3938d6972630663356d9500" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -383,15 +331,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.109" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -409,9 +357,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.8" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -430,24 +378,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - [[package]] name = "week-timekeeping" version = "0.0.0" @@ -467,25 +397,3 @@ dependencies = [ "unwrappable", "week-timekeeping", ] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/dex/pair/wasm-pair-full/Cargo.toml b/dex/pair/wasm-pair-full/Cargo.toml index 83cc77a50..5fc0f4b76 100644 --- a/dex/pair/wasm-pair-full/Cargo.toml +++ b/dex/pair/wasm-pair-full/Cargo.toml @@ -1,25 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "pair-full-wasm" version = "0.0.0" -authors = ["MultiversX "] edition = "2021" publish = false [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.pair] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/dex/pair/wasm-pair-full/src/lib.rs b/dex/pair/wasm-pair-full/src/lib.rs index 30efb71cb..149c4a91b 100644 --- a/dex/pair/wasm-pair-full/src/lib.rs +++ b/dex/pair/wasm-pair-full/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 63 +// Endpoints: 64 // Async Callback (empty): 1 -// Total number of exported functions: 65 +// Total number of exported functions: 66 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,70 +19,72 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { pair ( - addInitialLiquidity - addLiquidity - removeLiquidity - removeLiquidityAndBuyBackAndBurnToken - swapNoFeeAndForward - swapTokensFixedInput - swapTokensFixedOutput - setLpTokenIdentifier - getTokensForGivenPosition - getReservesAndTotalSupply - getAmountOut - getAmountIn - getEquivalent - getFeeState - whitelist - removeWhitelist - addTrustedSwapPair - removeTrustedSwapPair - setupFeesCollector - setFeeOn - getFeeDestinations - getTrustedSwapPairs - getWhitelistedManagedAddresses - getFeesCollectorAddress - getFeesCollectorCutPercentage - setStateActiveNoSwaps - setFeePercents - getLpTokenIdentifier - getTotalFeePercent - getSpecialFee - getRouterManagedAddress - getFirstTokenId - getSecondTokenId - getTotalSupply - getInitialLiquidtyAdder - getReserve - getSafePriceCurrentIndex - updateAndGetTokensForGivenPositionWithSafePrice - updateAndGetSafePrice - setLockingDeadlineEpoch - setLockingScAddress - setUnlockEpoch - getLockingScAddress - getUnlockEpoch - getLockingDeadlineEpoch - addAdmin - removeAdmin - updateOwnerOrAdmin - getPermissions - addToPauseWhitelist - removeFromPauseWhitelist - pause - resume - getState - getLpTokensSafePriceByDefaultOffset - getLpTokensSafePriceByRoundOffset - getLpTokensSafePriceByTimestampOffset - getLpTokensSafePrice - getSafePriceByDefaultOffset - getSafePriceByRoundOffset - getSafePriceByTimestampOffset - getSafePrice - getPriceObservation + init => init + upgrade => upgrade + setLpTokenIdentifier => set_lp_token_identifier + getFeeState => is_fee_enabled + whitelist => whitelist_endpoint + removeWhitelist => remove_whitelist + addTrustedSwapPair => add_trusted_swap_pair + removeTrustedSwapPair => remove_trusted_swap_pair + setupFeesCollector => setup_fees_collector + setFeeOn => set_fee_on + getFeeDestinations => get_fee_destinations + getTrustedSwapPairs => get_trusted_swap_pairs + getWhitelistedManagedAddresses => get_whitelisted_managed_addresses + getFeesCollectorAddress => fees_collector_address + getFeesCollectorCutPercentage => fees_collector_cut_percentage + setStateActiveNoSwaps => set_state_active_no_swaps + setFeePercents => set_fee_percent + getLpTokenIdentifier => get_lp_token_identifier + getTotalFeePercent => total_fee_percent + getSpecialFee => special_fee_percent + getRouterManagedAddress => router_address + getFirstTokenId => first_token_id + getSecondTokenId => second_token_id + getTotalSupply => lp_token_supply + getInitialLiquidtyAdder => initial_liquidity_adder + getReserve => pair_reserve + getSafePriceCurrentIndex => safe_price_current_index + updateAndGetTokensForGivenPositionWithSafePrice => update_and_get_tokens_for_given_position_with_safe_price + updateAndGetSafePrice => update_and_get_safe_price + setLockingDeadlineEpoch => set_locking_deadline_epoch + setLockingScAddress => set_locking_sc_address + setUnlockEpoch => set_unlock_epoch + getLockingScAddress => locking_sc_address + getUnlockEpoch => unlock_epoch + getLockingDeadlineEpoch => locking_deadline_epoch + addAdmin => add_admin_endpoint + removeAdmin => remove_admin_endpoint + updateOwnerOrAdmin => update_owner_or_admin_endpoint + getPermissions => permissions + addToPauseWhitelist => add_to_pause_whitelist + removeFromPauseWhitelist => remove_from_pause_whitelist + pause => pause + resume => resume + getState => state + addInitialLiquidity => add_initial_liquidity + addLiquidity => add_liquidity + removeLiquidity => remove_liquidity + removeLiquidityAndBuyBackAndBurnToken => remove_liquidity_and_burn_token + swapNoFeeAndForward => swap_no_fee + swapTokensFixedInput => swap_tokens_fixed_input + swapTokensFixedOutput => swap_tokens_fixed_output + getTokensForGivenPosition => get_tokens_for_given_position + getReservesAndTotalSupply => get_reserves_and_total_supply + getAmountOut => get_amount_out_view + getAmountIn => get_amount_in_view + getEquivalent => get_equivalent + getLpTokensSafePriceByDefaultOffset => get_lp_tokens_safe_price_by_default_offset + getLpTokensSafePriceByRoundOffset => get_lp_tokens_safe_price_by_round_offset + getLpTokensSafePriceByTimestampOffset => get_lp_tokens_safe_price_by_timestamp_offset + getLpTokensSafePrice => get_lp_tokens_safe_price + getSafePriceByDefaultOffset => get_safe_price_by_default_offset + getSafePriceByRoundOffset => get_safe_price_by_round_offset + getSafePriceByTimestampOffset => get_safe_price_by_timestamp_offset + getSafePrice => get_safe_price + getPriceObservation => get_price_observation_view ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/dex/pair/wasm-safe-price-view/Cargo.lock b/dex/pair/wasm-safe-price-view/Cargo.lock index c8995accb..48471aad0 100644 --- a/dex/pair/wasm-safe-price-view/Cargo.lock +++ b/dex/pair/wasm-safe-price-view/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common-types" @@ -70,9 +47,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "endian-type" @@ -129,15 +106,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -146,9 +114,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "itertools" @@ -168,12 +136,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.144" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" - [[package]] name = "locking_module" version = "0.0.0" @@ -190,12 +152,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -205,12 +161,11 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -219,20 +174,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -242,9 +196,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -255,21 +209,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -283,19 +236,13 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" - [[package]] name = "pair" version = "0.0.0" @@ -309,6 +256,7 @@ dependencies = [ "permissions_module", "simple-lock", "token_send", + "utils", ] [[package]] @@ -330,18 +278,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.56" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.27" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f4f29d145265ec1c483c7c654450edde0bfe043d3938d6972630663356d9500" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -383,15 +331,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.109" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -409,9 +357,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.8" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -430,24 +378,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - [[package]] name = "week-timekeeping" version = "0.0.0" @@ -467,25 +397,3 @@ dependencies = [ "unwrappable", "week-timekeeping", ] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/dex/pair/wasm-safe-price-view/Cargo.toml b/dex/pair/wasm-safe-price-view/Cargo.toml index 90323de22..28c1d40a9 100644 --- a/dex/pair/wasm-safe-price-view/Cargo.toml +++ b/dex/pair/wasm-safe-price-view/Cargo.toml @@ -1,25 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "safe-price-view-wasm" version = "0.0.0" -authors = ["MultiversX "] edition = "2021" publish = false [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.pair] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/dex/pair/wasm-safe-price-view/src/lib.rs b/dex/pair/wasm-safe-price-view/src/lib.rs index a41f72fd1..cc5f99d90 100644 --- a/dex/pair/wasm-safe-price-view/src/lib.rs +++ b/dex/pair/wasm-safe-price-view/src/lib.rs @@ -1,4 +1,4 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// @@ -10,24 +10,27 @@ // Total number of exported functions: 11 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); +multiversx_sc_wasm_adapter::external_view_init! {} + multiversx_sc_wasm_adapter::external_view_endpoints! { pair ( - getLpTokensSafePriceByDefaultOffset - getLpTokensSafePriceByRoundOffset - getLpTokensSafePriceByTimestampOffset - getLpTokensSafePrice - getSafePriceByDefaultOffset - getSafePriceByRoundOffset - getSafePriceByTimestampOffset - getSafePrice - getPriceObservation + getLpTokensSafePriceByDefaultOffset => get_lp_tokens_safe_price_by_default_offset + getLpTokensSafePriceByRoundOffset => get_lp_tokens_safe_price_by_round_offset + getLpTokensSafePriceByTimestampOffset => get_lp_tokens_safe_price_by_timestamp_offset + getLpTokensSafePrice => get_lp_tokens_safe_price + getSafePriceByDefaultOffset => get_safe_price_by_default_offset + getSafePriceByRoundOffset => get_safe_price_by_round_offset + getSafePriceByTimestampOffset => get_safe_price_by_timestamp_offset + getSafePrice => get_safe_price + getPriceObservation => get_price_observation_view ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/dex/pair/wasm/Cargo.lock b/dex/pair/wasm/Cargo.lock index a2f6f1a44..c1f2406db 100644 --- a/dex/pair/wasm/Cargo.lock +++ b/dex/pair/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common-types" @@ -70,9 +47,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "endian-type" @@ -129,15 +106,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -146,9 +114,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "itertools" @@ -168,12 +136,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - [[package]] name = "locking_module" version = "0.0.0" @@ -190,12 +152,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -205,12 +161,11 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -219,20 +174,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -242,9 +196,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -255,21 +209,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -283,19 +236,13 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "pair" version = "0.0.0" @@ -309,6 +256,7 @@ dependencies = [ "permissions_module", "simple-lock", "token_send", + "utils", ] [[package]] @@ -338,18 +286,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -383,15 +331,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -409,9 +357,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -430,24 +378,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - [[package]] name = "week-timekeeping" version = "0.0.0" @@ -467,25 +397,3 @@ dependencies = [ "unwrappable", "week-timekeeping", ] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/dex/pair/wasm/Cargo.toml b/dex/pair/wasm/Cargo.toml index 6ef96197e..7e096d156 100644 --- a/dex/pair/wasm/Cargo.toml +++ b/dex/pair/wasm/Cargo.toml @@ -1,25 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "pair-wasm" version = "0.0.0" -authors = ["MultiversX "] edition = "2021" publish = false [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.pair] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/dex/pair/wasm/src/lib.rs b/dex/pair/wasm/src/lib.rs index d692b1d2b..82a357b8a 100644 --- a/dex/pair/wasm/src/lib.rs +++ b/dex/pair/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 54 +// Endpoints: 55 // Async Callback (empty): 1 -// Total number of exported functions: 56 +// Total number of exported functions: 57 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,61 +19,63 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { pair ( - addInitialLiquidity - addLiquidity - removeLiquidity - removeLiquidityAndBuyBackAndBurnToken - swapNoFeeAndForward - swapTokensFixedInput - swapTokensFixedOutput - setLpTokenIdentifier - getTokensForGivenPosition - getReservesAndTotalSupply - getAmountOut - getAmountIn - getEquivalent - getFeeState - whitelist - removeWhitelist - addTrustedSwapPair - removeTrustedSwapPair - setupFeesCollector - setFeeOn - getFeeDestinations - getTrustedSwapPairs - getWhitelistedManagedAddresses - getFeesCollectorAddress - getFeesCollectorCutPercentage - setStateActiveNoSwaps - setFeePercents - getLpTokenIdentifier - getTotalFeePercent - getSpecialFee - getRouterManagedAddress - getFirstTokenId - getSecondTokenId - getTotalSupply - getInitialLiquidtyAdder - getReserve - getSafePriceCurrentIndex - updateAndGetTokensForGivenPositionWithSafePrice - updateAndGetSafePrice - setLockingDeadlineEpoch - setLockingScAddress - setUnlockEpoch - getLockingScAddress - getUnlockEpoch - getLockingDeadlineEpoch - addAdmin - removeAdmin - updateOwnerOrAdmin - getPermissions - addToPauseWhitelist - removeFromPauseWhitelist - pause - resume - getState + init => init + upgrade => upgrade + setLpTokenIdentifier => set_lp_token_identifier + getFeeState => is_fee_enabled + whitelist => whitelist_endpoint + removeWhitelist => remove_whitelist + addTrustedSwapPair => add_trusted_swap_pair + removeTrustedSwapPair => remove_trusted_swap_pair + setupFeesCollector => setup_fees_collector + setFeeOn => set_fee_on + getFeeDestinations => get_fee_destinations + getTrustedSwapPairs => get_trusted_swap_pairs + getWhitelistedManagedAddresses => get_whitelisted_managed_addresses + getFeesCollectorAddress => fees_collector_address + getFeesCollectorCutPercentage => fees_collector_cut_percentage + setStateActiveNoSwaps => set_state_active_no_swaps + setFeePercents => set_fee_percent + getLpTokenIdentifier => get_lp_token_identifier + getTotalFeePercent => total_fee_percent + getSpecialFee => special_fee_percent + getRouterManagedAddress => router_address + getFirstTokenId => first_token_id + getSecondTokenId => second_token_id + getTotalSupply => lp_token_supply + getInitialLiquidtyAdder => initial_liquidity_adder + getReserve => pair_reserve + getSafePriceCurrentIndex => safe_price_current_index + updateAndGetTokensForGivenPositionWithSafePrice => update_and_get_tokens_for_given_position_with_safe_price + updateAndGetSafePrice => update_and_get_safe_price + setLockingDeadlineEpoch => set_locking_deadline_epoch + setLockingScAddress => set_locking_sc_address + setUnlockEpoch => set_unlock_epoch + getLockingScAddress => locking_sc_address + getUnlockEpoch => unlock_epoch + getLockingDeadlineEpoch => locking_deadline_epoch + addAdmin => add_admin_endpoint + removeAdmin => remove_admin_endpoint + updateOwnerOrAdmin => update_owner_or_admin_endpoint + getPermissions => permissions + addToPauseWhitelist => add_to_pause_whitelist + removeFromPauseWhitelist => remove_from_pause_whitelist + pause => pause + resume => resume + getState => state + addInitialLiquidity => add_initial_liquidity + addLiquidity => add_liquidity + removeLiquidity => remove_liquidity + removeLiquidityAndBuyBackAndBurnToken => remove_liquidity_and_burn_token + swapNoFeeAndForward => swap_no_fee + swapTokensFixedInput => swap_tokens_fixed_input + swapTokensFixedOutput => swap_tokens_fixed_output + getTokensForGivenPosition => get_tokens_for_given_position + getReservesAndTotalSupply => get_reserves_and_total_supply + getAmountOut => get_amount_out_view + getAmountIn => get_amount_in_view + getEquivalent => get_equivalent ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/dex/price-discovery/Cargo.toml b/dex/price-discovery/Cargo.toml index 7bf90df61..51aa316e3 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.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" [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.39.4" +version = "=0.46.1" diff --git a/dex/price-discovery/meta/Cargo.toml b/dex/price-discovery/meta/Cargo.toml index 1763b6369..176823d06 100644 --- a/dex/price-discovery/meta/Cargo.toml +++ b/dex/price-discovery/meta/Cargo.toml @@ -4,8 +4,10 @@ version = "0.0.0" edition = "2021" publish = false authors = ["Dorin Iancu "] + [dependencies.price-discovery] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/dex/price-discovery/src/lib.rs b/dex/price-discovery/src/lib.rs index 30799231a..32a07acf0 100644 --- a/dex/price-discovery/src/lib.rs +++ b/dex/price-discovery/src/lib.rs @@ -113,6 +113,9 @@ pub trait PriceDiscovery: self.set_locking_sc_address(locking_sc_address); } + #[endpoint] + fn upgrade(&self) {} + /// Users can deposit either launched_token or accepted_token. /// They will receive an SFT that can be used to withdraw said tokens #[payable("*")] diff --git a/dex/price-discovery/src/redeem_token.rs b/dex/price-discovery/src/redeem_token.rs index 70de40567..e54b091d8 100644 --- a/dex/price-discovery/src/redeem_token.rs +++ b/dex/price-discovery/src/redeem_token.rs @@ -19,7 +19,7 @@ pub trait RedeemTokenModule: token_ticker: ManagedBuffer, nr_decimals: usize, ) { - let payment_amount = self.call_value().egld_value(); + let payment_amount = self.call_value().egld_value().clone_value(); self.redeem_token().issue_and_set_all_roles( EsdtTokenType::Meta, payment_amount, diff --git a/dex/price-discovery/tests/price_disc_tests.rs b/dex/price-discovery/tests/price_disc_tests.rs index 5094c568b..a6cfbec43 100644 --- a/dex/price-discovery/tests/price_disc_tests.rs +++ b/dex/price-discovery/tests/price_disc_tests.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + use multiversx_sc::codec::Empty; use multiversx_sc_scenario::{managed_biguint, managed_token_id_wrapped}; use multiversx_sc_scenario::{rust_biguint, DebugApi}; @@ -365,7 +367,7 @@ fn redeem_ok() { ) .assert_ok(); - let _ = DebugApi::dummy(); + DebugApi::dummy(); let first_user_expected_launched_tokens_balance = rust_biguint!(5_000_000_000u64 * 600_000_000 / 1_100_000_000); pd_setup.blockchain_wrapper.check_nft_balance( diff --git a/dex/price-discovery/tests/tests_common.rs b/dex/price-discovery/tests/tests_common.rs index 788013975..984a7ec0c 100644 --- a/dex/price-discovery/tests/tests_common.rs +++ b/dex/price-discovery/tests/tests_common.rs @@ -1,8 +1,10 @@ +#![allow(deprecated)] + use multiversx_sc::codec::Empty; use multiversx_sc::types::{Address, EsdtLocalRole}; -use multiversx_sc_scenario::whitebox::TxResult; +use multiversx_sc_scenario::whitebox_legacy::TxResult; use multiversx_sc_scenario::{ - managed_address, managed_biguint, managed_token_id_wrapped, whitebox::*, + managed_address, managed_biguint, managed_token_id_wrapped, whitebox_legacy::*, }; use multiversx_sc_scenario::{managed_token_id, rust_biguint, DebugApi}; diff --git a/dex/price-discovery/wasm/Cargo.lock b/dex/price-discovery/wasm/Cargo.lock index 7e6dc4c5b..fbcb7ca84 100644 --- a/dex/price-discovery/wasm/Cargo.lock +++ b/dex/price-discovery/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common_errors" @@ -90,15 +67,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -111,6 +79,12 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +[[package]] +name = "hex-literal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + [[package]] name = "legacy_token_decode_module" version = "0.0.0" @@ -120,12 +94,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - [[package]] name = "locking_module" version = "0.0.0" @@ -142,12 +110,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -157,13 +119,12 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", - "hex-literal", + "hex-literal 0.4.1", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", @@ -171,20 +132,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -194,9 +154,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -207,21 +167,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -235,24 +194,18 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "price-discovery" version = "0.0.0" dependencies = [ - "hex-literal", + "hex-literal 0.3.4", "locking_module", "multiversx-sc", "multiversx-sc-modules", @@ -268,18 +221,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -313,15 +266,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -330,9 +283,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -350,43 +303,3 @@ dependencies = [ "mergeable", "multiversx-sc", ] - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/dex/price-discovery/wasm/Cargo.toml b/dex/price-discovery/wasm/Cargo.toml index b706e6a63..04885bcda 100644 --- a/dex/price-discovery/wasm/Cargo.toml +++ b/dex/price-discovery/wasm/Cargo.toml @@ -1,25 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "price-discovery-wasm" version = "0.0.0" -authors = ["Dorin Iancu "] edition = "2021" publish = false [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.price-discovery] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/dex/price-discovery/wasm/src/lib.rs b/dex/price-discovery/wasm/src/lib.rs index 7c227533c..c29196d8a 100644 --- a/dex/price-discovery/wasm/src/lib.rs +++ b/dex/price-discovery/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 27 +// Endpoints: 28 // Async Callback: 1 -// Total number of exported functions: 29 +// Total number of exported functions: 30 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,33 +19,36 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { price_discovery ( - deposit - withdraw - redeem - getCurrentPrice - getMinLaunchedTokenPrice - getPricePrecision - getLaunchedTokenId - getAcceptedTokenId - getLaunchedTokenBalance - getAcceptedTokenBalance - getStartBlock - getEndBlock - setLockingScAddress - setUnlockEpoch - getLockingScAddress - getUnlockEpoch - getCurrentPhase - getNoLimitPhaseDurationBlocks - getLinearPenaltyPhaseDurationBlocks - getFixedPenaltyPhaseDurationBlocks - getPenaltyMinPercentage - getPenaltyMaxPercentage - getFixedPenaltyPercentage - issueRedeemToken - createInitialRedeemTokens - getRedeemTokenId - getRedeemTokenTotalCirculatingSupply - callBack + init => init + upgrade => upgrade + deposit => deposit + withdraw => withdraw + redeem => redeem + getCurrentPrice => calculate_price + getMinLaunchedTokenPrice => min_launched_token_price + getPricePrecision => price_precision + getLaunchedTokenId => launched_token_id + getAcceptedTokenId => accepted_token_id + getLaunchedTokenBalance => launched_token_balance + getAcceptedTokenBalance => accepted_token_balance + getStartBlock => start_block + getEndBlock => end_block + setLockingScAddress => set_locking_sc_address + setUnlockEpoch => set_unlock_epoch + getLockingScAddress => locking_sc_address + getUnlockEpoch => unlock_epoch + getCurrentPhase => get_current_phase + getNoLimitPhaseDurationBlocks => no_limit_phase_duration_blocks + getLinearPenaltyPhaseDurationBlocks => linear_penalty_phase_duration_blocks + getFixedPenaltyPhaseDurationBlocks => fixed_penalty_phase_duration_blocks + getPenaltyMinPercentage => penalty_min_percentage + getPenaltyMaxPercentage => penalty_max_percentage + getFixedPenaltyPercentage => fixed_penalty_percentage + issueRedeemToken => issue_redeem_token + createInitialRedeemTokens => create_initial_redeem_tokens + getRedeemTokenId => redeem_token + getRedeemTokenTotalCirculatingSupply => redeem_token_total_circulating_supply ) } + +multiversx_sc_wasm_adapter::async_callback! { price_discovery } diff --git a/dex/proxy-deployer/Cargo.toml b/dex/proxy-deployer/Cargo.toml index 60586f00a..f5c3b8955 100644 --- a/dex/proxy-deployer/Cargo.toml +++ b/dex/proxy-deployer/Cargo.toml @@ -7,6 +7,7 @@ publish = false [lib] path = "src/lib.rs" + [dependencies.farm] path = "../farm" @@ -20,11 +21,11 @@ path = "../../common/modules/farm/config" path = "../../common/modules/farm/farm_token" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" diff --git a/dex/proxy-deployer/meta/Cargo.toml b/dex/proxy-deployer/meta/Cargo.toml index 3f407684a..629fddbdf 100644 --- a/dex/proxy-deployer/meta/Cargo.toml +++ b/dex/proxy-deployer/meta/Cargo.toml @@ -6,8 +6,10 @@ publish = false authors = ["MultiversX "] [dev-dependencies] + [dependencies.proxy-deployer] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/dex/proxy-deployer/src/lib.rs b/dex/proxy-deployer/src/lib.rs index 38c3b546b..a05bab7b0 100644 --- a/dex/proxy-deployer/src/lib.rs +++ b/dex/proxy-deployer/src/lib.rs @@ -15,4 +15,7 @@ pub trait ProxyDeployer: farm_deploy::FarmDeployModule { self.farm_template_address().set(&farm_template_address); } + + #[endpoint] + fn upgrade(&self) {} } diff --git a/dex/proxy-deployer/wasm/Cargo.lock b/dex/proxy-deployer/wasm/Cargo.lock index 3d762a9be..371955a5f 100644 --- a/dex/proxy-deployer/wasm/Cargo.lock +++ b/dex/proxy-deployer/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common-types" @@ -99,9 +76,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "endian-type" @@ -245,15 +222,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -262,9 +230,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "itertools" @@ -284,12 +252,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - [[package]] name = "locking_module" version = "0.0.0" @@ -306,12 +268,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -321,12 +277,11 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -335,20 +290,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -358,9 +312,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -371,21 +325,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -399,19 +352,13 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "pair" version = "0.0.0" @@ -425,6 +372,7 @@ dependencies = [ "permissions_module", "simple-lock", "token_send", + "utils", ] [[package]] @@ -446,9 +394,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] @@ -474,9 +422,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -525,15 +473,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -559,9 +507,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -580,24 +528,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - [[package]] name = "week-timekeeping" version = "0.0.0" @@ -617,25 +547,3 @@ dependencies = [ "unwrappable", "week-timekeeping", ] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/dex/proxy-deployer/wasm/Cargo.toml b/dex/proxy-deployer/wasm/Cargo.toml index 86fa07458..97ada3a24 100644 --- a/dex/proxy-deployer/wasm/Cargo.toml +++ b/dex/proxy-deployer/wasm/Cargo.toml @@ -1,25 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "proxy-deployer-wasm" version = "0.0.0" edition = "2021" publish = false -authors = ["MultiversX "] [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.proxy-deployer] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/dex/proxy-deployer/wasm/src/lib.rs b/dex/proxy-deployer/wasm/src/lib.rs index bdf618263..b8f3493f8 100644 --- a/dex/proxy-deployer/wasm/src/lib.rs +++ b/dex/proxy-deployer/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 4 +// Endpoints: 5 // Async Callback (empty): 1 -// Total number of exported functions: 6 +// Total number of exported functions: 7 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,11 +19,13 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { proxy_deployer ( - deployFarm - callFarmEndpoint - getAllDeployedFarms - getDeployerFarmAddresses + init => init + upgrade => upgrade + deployFarm => deploy_farm + callFarmEndpoint => call_farm_endpoint + getAllDeployedFarms => get_all_deployed_farms + getDeployerFarmAddresses => deployer_farm_addresses ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/dex/router/Cargo.toml b/dex/router/Cargo.toml index 32e19083e..cc3698241 100644 --- a/dex/router/Cargo.toml +++ b/dex/router/Cargo.toml @@ -7,6 +7,7 @@ publish = false [lib] path = "src/contract.rs" + [dependencies.token_send] path = "../../common/modules/token_send" @@ -14,7 +15,7 @@ path = "../../common/modules/token_send" path = "../../common/modules/pausable" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.pair] @@ -25,5 +26,6 @@ path = "../../common/modules/locking_module" [dependencies.simple-lock] path = "../../locked-asset/simple-lock" + [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" diff --git a/dex/router/README.md b/dex/router/README.md index 442511018..45585f54b 100644 --- a/dex/router/README.md +++ b/dex/router/README.md @@ -16,7 +16,7 @@ This contract allows: - Keeping track -of Pair smart contracts deployed as part of Maiar Exchange. +of Pair smart contracts deployed as part of xExchange. ## Endpoints @@ -95,8 +95,8 @@ There are four test suites around this contract: ## Interaction -The interaction scripts are located in the _dex/interaction_ directory. They are written in python and erdpy is required in order to be used. Interaction scripts are scripts that ease the interaction with the deployed contract by wrapping erdpy sdk functionality in bash scripts. Make sure to update the PEM path and the PROXY and CHAINID values in order to correctly use them. +The interaction scripts are located in the _dex/interaction_ directory. They are written in python and mxpy is required in order to be used. Interaction scripts are scripts that ease the interaction with the deployed contract by wrapping mxpy sdk functionality in bash scripts. Make sure to update the PEM path and the PROXY and CHAINID values in order to correctly use them. ## Deployment -The deployment of this contract is done using erdpy, interaction scripts, or any other tool, in a standalone manner or by previously deploying the template pair smart contract. +The deployment of this contract is done using mxpy, interaction scripts, or any other tool, in a standalone manner or by previously deploying the template pair smart contract. diff --git a/dex/router/meta/Cargo.toml b/dex/router/meta/Cargo.toml index fa3655c94..c5deaf0be 100644 --- a/dex/router/meta/Cargo.toml +++ b/dex/router/meta/Cargo.toml @@ -4,8 +4,10 @@ version = "0.0.0" authors = ["MultiversX "] edition = "2021" publish = false + [dependencies.router] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/dex/router/src/config.rs b/dex/router/src/config.rs new file mode 100644 index 000000000..25c96a3e6 --- /dev/null +++ b/dex/router/src/config.rs @@ -0,0 +1,69 @@ +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +use crate::{enable_swap_by_user::EnableSwapByUserConfig, factory::PairTokens}; + +#[multiversx_sc::module] +pub trait ConfigModule { + 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" + ); + } + + #[view(getPairCreationEnabled)] + #[storage_mapper("pair_creation_enabled")] + fn pair_creation_enabled(&self) -> SingleValueMapper; + + #[view(getState)] + #[storage_mapper("state")] + fn state(&self) -> SingleValueMapper; + + #[view(getOwner)] + #[storage_mapper("owner")] + fn owner(&self) -> SingleValueMapper; + + #[only_owner] + #[endpoint(setTemporaryOwnerPeriod)] + fn set_temporary_owner_period(&self, period_blocks: u64) { + self.temporary_owner_period().set(period_blocks); + } + + #[only_owner] + #[endpoint(setPairTemplateAddress)] + fn set_pair_template_address(&self, address: ManagedAddress) { + self.pair_template_address().set(&address); + } + + #[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; + + #[view(getTemporaryOwnerPeriod)] + #[storage_mapper("temporary_owner_period")] + fn temporary_owner_period(&self) -> SingleValueMapper; + + #[storage_mapper("pair_temporary_owner")] + fn pair_temporary_owner(&self) -> MapMapper; + + #[storage_mapper("enableSwapByUserConfig")] + fn enable_swap_by_user_config( + &self, + token_id: &TokenIdentifier, + ) -> SingleValueMapper>; + + #[view(getCommonTokensForUserPairs)] + #[storage_mapper("commonTokensForUserPairs")] + fn common_tokens_for_user_pairs(&self) -> UnorderedSetMapper; +} diff --git a/dex/router/src/contract.rs b/dex/router/src/contract.rs index 693c7fe23..04b787a03 100644 --- a/dex/router/src/contract.rs +++ b/dex/router/src/contract.rs @@ -3,6 +3,7 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); +pub mod config; pub mod enable_swap_by_user; mod events; pub mod factory; @@ -24,7 +25,8 @@ const USER_DEFINED_TOTAL_FEE_PERCENT: u64 = 1_000; #[multiversx_sc::contract] pub trait Router: - factory::FactoryModule + config::ConfigModule + + factory::FactoryModule + events::EventsModule + multi_pair_swap::MultiPairSwap + token_send::TokenSendModule @@ -39,6 +41,11 @@ pub trait Router: self.owner().set(&self.blockchain().get_caller()); } + #[endpoint] + fn upgrade(&self) { + self.state().set(false); + } + #[only_owner] #[endpoint] fn pause(&self, address: ManagedAddress) { @@ -57,6 +64,10 @@ 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); @@ -67,6 +78,7 @@ pub trait Router: } } + #[allow_multiple_var_args] #[endpoint(createPair)] fn create_pair_endpoint( &self, @@ -190,7 +202,7 @@ pub trait Router: lp_token_display_name: ManagedBuffer, lp_token_ticker: ManagedBuffer, ) { - let issue_cost = self.call_value().egld_value(); + let issue_cost = self.call_value().egld_value().clone_value(); require!(self.is_active(), "Not active"); let caller = self.blockchain().get_caller(); @@ -266,23 +278,6 @@ pub trait Router: .call_and_exit() } - #[only_owner] - #[endpoint(setLocalRolesOwner)] - fn set_local_roles_owner( - &self, - token: TokenIdentifier, - address: ManagedAddress, - roles: MultiValueEncoded, - ) { - require!(self.is_active(), "Not active"); - - self.send() - .esdt_system_sc_proxy() - .set_special_roles(&address, &token, roles.into_iter()) - .async_call() - .call_and_exit() - } - #[only_owner] #[endpoint(removePair)] fn remove_pair( @@ -322,6 +317,8 @@ pub trait Router: .unwrap_or_else(ManagedAddress::zero); } + self.address_pair_map().remove(&pair_address); + pair_address } @@ -383,26 +380,28 @@ pub trait Router: } } - #[inline] - fn is_active(&self) -> bool { - self.state().get() - } - #[only_owner] #[endpoint(setPairCreationEnabled)] fn set_pair_creation_enabled(&self, enabled: bool) { self.pair_creation_enabled().set(enabled); } - #[view(getPairCreationEnabled)] - #[storage_mapper("pair_creation_enabled")] - fn pair_creation_enabled(&self) -> SingleValueMapper; - - #[view(getState)] - #[storage_mapper("state")] - fn state(&self) -> SingleValueMapper; + #[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); + } - #[view(getOwner)] - #[storage_mapper("owner")] - fn owner(&self) -> SingleValueMapper; + 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 eec3f4d02..7c77036c1 100644 --- a/dex/router/src/enable_swap_by_user.rs +++ b/dex/router/src/enable_swap_by_user.rs @@ -1,11 +1,11 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); -use pair::config::ProxyTrait as _; +use pair::{config::ProxyTrait as _, pair_actions::views::ProxyTrait as _}; use pausable::{ProxyTrait as _, State}; use simple_lock::locked_token::LockedTokenAttributes; -use crate::{DEFAULT_SPECIAL_FEE_PERCENT, USER_DEFINED_TOTAL_FEE_PERCENT}; +use crate::{config, DEFAULT_SPECIAL_FEE_PERCENT, USER_DEFINED_TOTAL_FEE_PERCENT}; static PAIR_LP_TOKEN_ID_STORAGE_KEY: &[u8] = b"lpTokenIdentifier"; static PAIR_INITIAL_LIQ_ADDER_STORAGE_KEY: &[u8] = b"initial_liquidity_adder"; @@ -27,7 +27,7 @@ pub struct SafePriceResult { #[multiversx_sc::module] pub trait EnableSwapByUserModule: - crate::factory::FactoryModule + crate::events::EventsModule + config::ConfigModule + crate::factory::FactoryModule + crate::events::EventsModule { #[only_owner] #[endpoint(configEnableByUserParameters)] @@ -250,14 +250,4 @@ pub trait EnableSwapByUserModule: #[proxy] fn user_pair_proxy(&self, to: ManagedAddress) -> pair::Proxy; - - #[storage_mapper("enableSwapByUserConfig")] - fn enable_swap_by_user_config( - &self, - token_id: &TokenIdentifier, - ) -> SingleValueMapper>; - - #[view(getCommonTokensForUserPairs)] - #[storage_mapper("commonTokensForUserPairs")] - fn common_tokens_for_user_pairs(&self) -> UnorderedSetMapper; } diff --git a/dex/router/src/factory.rs b/dex/router/src/factory.rs index bd4b803ca..4994db235 100644 --- a/dex/router/src/factory.rs +++ b/dex/router/src/factory.rs @@ -1,6 +1,8 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); +use crate::config; + const TEMPORARY_OWNER_PERIOD_BLOCKS: u64 = 50; #[derive(TopEncode, TopDecode, NestedEncode, NestedDecode, PartialEq, TypeAbi)] @@ -17,7 +19,7 @@ pub struct PairContractMetadata { } #[multiversx_sc::module] -pub trait FactoryModule { +pub trait FactoryModule: config::ConfigModule { #[proxy] fn pair_contract_deploy_proxy(&self) -> pair::Proxy; @@ -69,6 +71,13 @@ pub trait FactoryModule { }, 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(), ( @@ -165,13 +174,11 @@ pub trait FactoryModule { address } - fn check_is_pair_sc(&self, pair_address: &ManagedAddress) { - require!( - self.pair_map() - .values() - .any(|address| &address == pair_address), - "Not a pair SC" - ); + #[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 { @@ -199,30 +206,4 @@ pub trait FactoryModule { self.pair_temporary_owner().clear(); size } - - #[only_owner] - #[endpoint(setTemporaryOwnerPeriod)] - fn set_temporary_owner_period(&self, period_blocks: u64) { - self.temporary_owner_period().set(period_blocks); - } - - #[only_owner] - #[endpoint(setPairTemplateAddress)] - fn set_pair_template_address(&self, address: ManagedAddress) { - self.pair_template_address().set(&address); - } - - #[storage_mapper("pair_map")] - fn pair_map(&self) -> MapMapper, ManagedAddress>; - - #[view(getPairTemplateAddress)] - #[storage_mapper("pair_template_address")] - fn pair_template_address(&self) -> SingleValueMapper; - - #[view(getTemporaryOwnerPeriod)] - #[storage_mapper("temporary_owner_period")] - fn temporary_owner_period(&self) -> SingleValueMapper; - - #[storage_mapper("pair_temporary_owner")] - fn pair_temporary_owner(&self) -> MapMapper; } diff --git a/dex/router/src/multi_pair_swap.rs b/dex/router/src/multi_pair_swap.rs index e537beed9..e69350ecd 100644 --- a/dex/router/src/multi_pair_swap.rs +++ b/dex/router/src/multi_pair_swap.rs @@ -1,9 +1,11 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); -use super::factory; +use pair::pair_actions::swap::ProxyTrait as _; + +use crate::config; -use pair::ProxyTrait as _; +use super::factory; type SwapOperationType = MultiValue4, ManagedBuffer, TokenIdentifier, BigUint>; @@ -12,10 +14,14 @@ pub const SWAP_TOKENS_FIXED_INPUT_FUNC_NAME: &[u8] = b"swapTokensFixedInput"; pub const SWAP_TOKENS_FIXED_OUTPUT_FUNC_NAME: &[u8] = b"swapTokensFixedOutput"; #[multiversx_sc::module] -pub trait MultiPairSwap: factory::FactoryModule + token_send::TokenSendModule { +pub trait MultiPairSwap: + config::ConfigModule + factory::FactoryModule + token_send::TokenSendModule +{ #[payable("*")] #[endpoint(multiPairSwap)] - fn multi_pair_swap(&self, swap_operations: MultiValueEncoded>) { + 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(); require!(nonce == 0, "Invalid nonce. Should be zero"); require!(amount > 0u64, "Invalid amount. Should not be zero"); @@ -61,6 +67,8 @@ pub trait MultiPairSwap: factory::FactoryModule + token_send::TokenSendModule { payments.push(last_payment); self.send().direct_multi(&caller, &payments); + + payments } fn actual_swap_fixed_input( diff --git a/dex/router/tests/router_setup/mod.rs b/dex/router/tests/router_setup/mod.rs index a7cd6c14c..c72b6a971 100644 --- a/dex/router/tests/router_setup/mod.rs +++ b/dex/router/tests/router_setup/mod.rs @@ -1,9 +1,9 @@ use multiversx_sc::codec::multi_types::{MultiValue4, OptionalValue}; use multiversx_sc::types::{Address, EsdtLocalRole, ManagedAddress, MultiValueEncoded}; -use multiversx_sc_scenario::whitebox::TxTokenTransfer; +use multiversx_sc_scenario::whitebox_legacy::TxTokenTransfer; use multiversx_sc_scenario::{ - managed_address, managed_biguint, managed_buffer, managed_token_id, rust_biguint, whitebox::*, - DebugApi, + managed_address, managed_biguint, managed_buffer, managed_token_id, rust_biguint, + whitebox_legacy::*, DebugApi, }; pub const PAIR_WASM_PATH: &str = "pair/output/pair.wasm"; @@ -27,9 +27,11 @@ pub const MIN_LOCKED_PERIOD_EPOCHS: u64 = 100; pub const USER_CUSTOM_TOKEN_BALANCE: u64 = 1_000_000_000; pub const USER_USDC_BALANCE: u64 = 1_000_000; -use pair::config::*; +use pair::config::ConfigModule as PairConfigModule; +use pair::pair_actions::add_liq::AddLiquidityModule; use pair::*; use pausable::{PausableModule, State}; +use router::config::ConfigModule; use router::factory::*; use router::multi_pair_swap::*; use router::*; @@ -282,4 +284,17 @@ 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 2c1803311..54c73c838 100644 --- a/dex/router/tests/router_test.rs +++ b/dex/router/tests/router_test.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + mod router_setup; use multiversx_sc::{ codec::multi_types::OptionalValue, @@ -7,19 +9,20 @@ use multiversx_sc::{ MultiValueEncoded, }, }; -use pair::{config::ConfigModule, Pair}; +use pair::{ + config::ConfigModule as PairConfigModule, pair_actions::initial_liq::InitialLiquidityModule, + Pair, +}; use pausable::{PausableModule, State}; use router::{ - enable_swap_by_user::EnableSwapByUserModule, - factory::{FactoryModule, PairTokens}, - multi_pair_swap::SWAP_TOKENS_FIXED_INPUT_FUNC_NAME, - Router, + config::ConfigModule, enable_swap_by_user::EnableSwapByUserModule, factory::PairTokens, + multi_pair_swap::SWAP_TOKENS_FIXED_INPUT_FUNC_NAME, Router, }; use router_setup::*; use multiversx_sc_scenario::{ managed_address, managed_biguint, managed_token_id, managed_token_id_wrapped, rust_biguint, - whitebox::BlockchainStateWrapper, whitebox::TxTokenTransfer, DebugApi, + whitebox_legacy::BlockchainStateWrapper, whitebox_legacy::TxTokenTransfer, DebugApi, }; use simple_lock::{ locked_token::{LockedTokenAttributes, LockedTokenModule}, @@ -131,6 +134,7 @@ 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(); @@ -251,6 +255,8 @@ 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), ]))); @@ -342,7 +348,7 @@ fn user_enable_pair_swaps_through_router_test() { ) .assert_ok(); - let _ = DebugApi::dummy(); + DebugApi::dummy(); b_mock.check_nft_balance( &user, LOCKED_TOKEN_ID, @@ -436,6 +442,8 @@ 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), ]))); @@ -511,7 +519,7 @@ fn user_enable_pair_swaps_fail_test() { .assert_ok(); let custom_locked_token = b"LTOK2-123456"; - let _ = DebugApi::dummy(); + DebugApi::dummy(); b_mock.set_nft_balance( &user, custom_locked_token, diff --git a/dex/router/wasm/Cargo.lock b/dex/router/wasm/Cargo.lock index 6746dd43d..0f5cc1535 100644 --- a/dex/router/wasm/Cargo.lock +++ b/dex/router/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common-types" @@ -70,9 +47,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "endian-type" @@ -129,15 +106,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -146,9 +114,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "itertools" @@ -168,12 +136,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - [[package]] name = "locking_module" version = "0.0.0" @@ -190,12 +152,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -205,12 +161,11 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -219,20 +174,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -242,9 +196,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -255,21 +209,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -283,19 +236,13 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "pair" version = "0.0.0" @@ -309,6 +256,7 @@ dependencies = [ "permissions_module", "simple-lock", "token_send", + "utils", ] [[package]] @@ -330,18 +278,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -395,15 +343,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -421,9 +369,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -442,24 +390,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - [[package]] name = "week-timekeeping" version = "0.0.0" @@ -479,25 +409,3 @@ dependencies = [ "unwrappable", "week-timekeeping", ] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/dex/router/wasm/Cargo.toml b/dex/router/wasm/Cargo.toml index 5e1dbd501..dc895383b 100644 --- a/dex/router/wasm/Cargo.toml +++ b/dex/router/wasm/Cargo.toml @@ -1,26 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "router-wasm" version = "0.0.0" -authors = ["MultiversX "] edition = "2021" publish = false [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.router] -default-features = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/dex/router/wasm/src/lib.rs b/dex/router/wasm/src/lib.rs index 28609e0ab..e840498ec 100644 --- a/dex/router/wasm/src/lib.rs +++ b/dex/router/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 30 +// Endpoints: 33 // Async Callback: 1 -// Total number of exported functions: 32 +// Total number of exported functions: 35 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,36 +19,40 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { router ( - pause - resume - createPair - upgradePair - issueLpToken - setLocalRoles - setLocalRolesOwner - removePair - setFeeOn - setFeeOff - setPairCreationEnabled - getPairCreationEnabled - getState - getOwner - getAllPairsManagedAddresses - getAllPairTokens - getAllPairContractMetadata - getPair - clearPairTemporaryOwnerStorage - setTemporaryOwnerPeriod - setPairTemplateAddress - getPairTemplateAddress - getTemporaryOwnerPeriod - multiPairSwap - configEnableByUserParameters - addCommonTokensForUserPairs - removeCommonTokensForUserPairs - setSwapEnabledByUser - getEnableSwapByUserConfig - getCommonTokensForUserPairs - callBack + init => init + upgrade => upgrade + pause => pause + resume => resume + createPair => create_pair_endpoint + upgradePair => upgrade_pair_endpoint + issueLpToken => issue_lp_token + setLocalRoles => set_local_roles + removePair => remove_pair + 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 + setTemporaryOwnerPeriod => set_temporary_owner_period + setPairTemplateAddress => set_pair_template_address + getPairTemplateAddress => pair_template_address + getTemporaryOwnerPeriod => temporary_owner_period + getCommonTokensForUserPairs => common_tokens_for_user_pairs + getAllPairsManagedAddresses => get_all_pairs_addresses + 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 + addCommonTokensForUserPairs => add_common_tokens_for_user_pairs + removeCommonTokensForUserPairs => remove_common_tokens_for_user_pairs + setSwapEnabledByUser => set_swap_enabled_by_user + getEnableSwapByUserConfig => try_get_config ) } + +multiversx_sc_wasm_adapter::async_callback! { router } diff --git a/dex/scenarios/exit_farm.scen.json b/dex/scenarios/exit_farm.scen.json index 9a3ec697d..495520be4 100644 --- a/dex/scenarios/exit_farm.scen.json +++ b/dex/scenarios/exit_farm.scen.json @@ -25,9 +25,7 @@ } ], "function": "exitFarm", - "arguments": [ - "100,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -42,11 +40,6 @@ "1-token_id": "nested:str:WEGLD-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:0" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:2", - "3-amount": "biguint:0" } ], "status": "0", diff --git a/dex/scenarios/exit_farm_too_soon.scen.json b/dex/scenarios/exit_farm_too_soon.scen.json index 8280af81e..72b596bda 100644 --- a/dex/scenarios/exit_farm_too_soon.scen.json +++ b/dex/scenarios/exit_farm_too_soon.scen.json @@ -47,9 +47,7 @@ } ], "function": "exitFarm", - "arguments": [ - "100,000" - ], + "arguments": [], "gasLimit": "1,000,000,000", "gasPrice": "0" }, @@ -64,11 +62,6 @@ "1-token_id": "nested:str:WEGLD-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:0" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:2", - "3-amount": "biguint:0" } ], "status": "0", @@ -125,9 +118,7 @@ } ], "function": "exitFarm", - "arguments": [ - "100,000" - ], + "arguments": [], "gasLimit": "1,000,000,000", "gasPrice": "0" }, @@ -142,11 +133,6 @@ "1-token_id": "nested:str:WEGLD-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:0" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:2", - "3-amount": "biguint:0" } ], "status": "0", diff --git a/dex/scenarios/exit_mex_farm.scen.json b/dex/scenarios/exit_mex_farm.scen.json index 03e17bb16..3cc9dca89 100644 --- a/dex/scenarios/exit_mex_farm.scen.json +++ b/dex/scenarios/exit_mex_farm.scen.json @@ -26,9 +26,7 @@ } ], "function": "exitFarm", - "arguments": [ - "100,000,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -43,11 +41,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:50,000" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:1", - "3-amount": "biguint:0" } ], "status": "0", diff --git a/dex/scenarios/farm_reward_distr_scen_1.scen.json b/dex/scenarios/farm_reward_distr_scen_1.scen.json index 348847c77..e45afaa8e 100644 --- a/dex/scenarios/farm_reward_distr_scen_1.scen.json +++ b/dex/scenarios/farm_reward_distr_scen_1.scen.json @@ -167,9 +167,7 @@ } ], "function": "exitFarm", - "arguments": [ - "1,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -184,11 +182,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:450" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:1", - "3-amount": "biguint:0" } ], "status": "0", @@ -211,9 +204,7 @@ } ], "function": "exitFarm", - "arguments": [ - "1,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -228,11 +219,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:350" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:2", - "3-amount": "biguint:0" } ], "status": "0", diff --git a/dex/scenarios/farm_reward_distr_scen_2.scen.json b/dex/scenarios/farm_reward_distr_scen_2.scen.json index bcab014a5..fc607055a 100644 --- a/dex/scenarios/farm_reward_distr_scen_2.scen.json +++ b/dex/scenarios/farm_reward_distr_scen_2.scen.json @@ -210,9 +210,7 @@ } ], "function": "exitFarm", - "arguments": [ - "2,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -227,11 +225,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:428" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:2", - "3-amount": "biguint:0" } ], "status": "0", @@ -260,9 +253,7 @@ } ], "function": "exitFarm", - "arguments": [ - "1,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -277,11 +268,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:414" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:1", - "3-amount": "biguint:0" } ], "status": "0", @@ -310,9 +296,7 @@ } ], "function": "exitFarm", - "arguments": [ - "500" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -327,11 +311,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:457" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:3", - "3-amount": "biguint:0" } ], "status": "0", diff --git a/dex/scenarios/farm_reward_distr_scen_3.scen.json b/dex/scenarios/farm_reward_distr_scen_3.scen.json index b3a3442a4..b850e7bd9 100644 --- a/dex/scenarios/farm_reward_distr_scen_3.scen.json +++ b/dex/scenarios/farm_reward_distr_scen_3.scen.json @@ -260,9 +260,7 @@ } ], "function": "exitFarm", - "arguments": [ - "2,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -277,11 +275,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:371" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:2", - "3-amount": "biguint:0" } ], "status": "0", @@ -310,9 +303,7 @@ } ], "function": "exitFarm", - "arguments": [ - "1,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -327,11 +318,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:285" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:1", - "3-amount": "biguint:0" } ], "status": "0", @@ -360,9 +346,7 @@ } ], "function": "exitFarm", - "arguments": [ - "500" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -377,11 +361,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:242" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:3", - "3-amount": "biguint:0" } ], "status": "0", diff --git a/dex/scenarios/farm_reward_distr_scen_4.scen.json b/dex/scenarios/farm_reward_distr_scen_4.scen.json index 629b2f5f9..0a9dbaf60 100644 --- a/dex/scenarios/farm_reward_distr_scen_4.scen.json +++ b/dex/scenarios/farm_reward_distr_scen_4.scen.json @@ -260,9 +260,7 @@ } ], "function": "exitFarm", - "arguments": [ - "2,000,000,000,000,000,000,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -277,11 +275,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:3,714,285,714,284,000,000,000" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:2", - "3-amount": "biguint:0" } ], "status": "0", @@ -310,9 +303,7 @@ } ], "function": "exitFarm", - "arguments": [ - "1,000,000,000,000,000,000,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -327,11 +318,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:2,857,142,857,142,000,000,000" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:1", - "3-amount": "biguint:0" } ], "status": "0", @@ -360,9 +346,7 @@ } ], "function": "exitFarm", - "arguments": [ - "500,000,000,000,000,000,000" - ], + "arguments": [], "gasLimit": "100,000,000", "gasPrice": "0" }, @@ -377,11 +361,6 @@ "1-token_id": "nested:str:MEX-abcdef", "2-nonce": "u64:0", "3-amount": "biguint:2,428,571,428,571,000,000,000" - }, - { - "1-token_id": "nested:str:FARM-abcdef", - "2-nonce": "u64:3", - "3-amount": "biguint:0" } ], "status": "0", diff --git a/dex/scenarios/merge_tokens.scen.json b/dex/scenarios/merge_tokens.scen.json index 1a0b187cb..ed059f31b 100644 --- a/dex/scenarios/merge_tokens.scen.json +++ b/dex/scenarios/merge_tokens.scen.json @@ -30,7 +30,8 @@ }, "expect": { "out": [ - "0x0000000b4641524d2d6162636465660000000000000003000000040bebc200" + "0x0000000b4641524d2d6162636465660000000000000003000000040bebc200", + "0x0000000c5745474c442d616263646566000000000000000000000000" ], "status": "0", "message": "", @@ -63,4 +64,4 @@ } } ] -} +} \ No newline at end of file diff --git a/dex/scenarios/upgrade_contract.scen.json b/dex/scenarios/upgrade_contract.scen.json index b895f78f4..cdadc752b 100644 --- a/dex/scenarios/upgrade_contract.scen.json +++ b/dex/scenarios/upgrade_contract.scen.json @@ -16,7 +16,7 @@ "str:ALC-abcdef", "str:WEGLD-abcdef", "0x0000000000000000000000000000000000000000000000000000000000000000", - "301", + "300", "100" ], "gasLimit": "1,000,000,000", @@ -38,7 +38,7 @@ "balance": "*", "esdt": "*", "storage": { - "str:total_fee_percent": "301", + "str:total_fee_percent": "300", "+": "" }, "code": "file:../pair/output/pair.wasm" diff --git a/dex/tests/dex_scenario_go_test.rs b/dex/tests/dex_scenario_go_test.rs index 1bc63e0c1..5675b0a8d 100644 --- a/dex/tests/dex_scenario_go_test.rs +++ b/dex/tests/dex_scenario_go_test.rs @@ -1,203 +1,205 @@ +use multiversx_sc_scenario::*; + +fn world() -> ScenarioWorld { + ScenarioWorld::vm_go() +} + #[test] fn add_liquidity_go() { - multiversx_sc_scenario::run_go("scenarios/add_liquidity.scen.json"); + world().run("scenarios/add_liquidity.scen.json"); } #[test] fn calculate_rewards_for_given_position_go() { - multiversx_sc_scenario::run_go("scenarios/calculate_rewards_for_given_position.scen.json"); + world().run("scenarios/calculate_rewards_for_given_position.scen.json"); } #[test] fn calculate_rewards_for_given_position_after_compound_go() { - multiversx_sc_scenario::run_go( - "scenarios/calculate_rewards_for_given_position_after_compound.scen.json", - ); + world().run("scenarios/calculate_rewards_for_given_position_after_compound.scen.json"); } #[test] fn check_fee_disabled_after_swap_go() { - multiversx_sc_scenario::run_go("scenarios/check_fee_disabled_after_swap.scen.json"); + world().run("scenarios/check_fee_disabled_after_swap.scen.json"); } #[test] fn check_fee_enabled_after_swap_go() { - multiversx_sc_scenario::run_go("scenarios/check_fee_enabled_after_swap.scen.json"); + world().run("scenarios/check_fee_enabled_after_swap.scen.json"); } #[test] fn claim_rewards_go() { - multiversx_sc_scenario::run_go("scenarios/claim_rewards.scen.json"); + world().run("scenarios/claim_rewards.scen.json"); } #[test] fn complete_setup_go() { - multiversx_sc_scenario::run_go("scenarios/complete_setup.scen.json"); + world().run("scenarios/complete_setup.scen.json"); } #[test] fn compound_rewards_go() { - multiversx_sc_scenario::run_go("scenarios/compound_rewards.scen.json"); + world().run("scenarios/compound_rewards.scen.json"); } #[test] fn create_pair_twice_go() { - multiversx_sc_scenario::run_go("scenarios/create_pair_twice.scen.json"); + world().run("scenarios/create_pair_twice.scen.json"); } #[test] fn enter_farm_go() { - multiversx_sc_scenario::run_go("scenarios/enter_farm.scen.json"); + world().run("scenarios/enter_farm.scen.json"); } #[test] fn enter_farm_with_merge_tokens_go() { - multiversx_sc_scenario::run_go("scenarios/enter_farm_with_merge_tokens.scen.json"); + world().run("scenarios/enter_farm_with_merge_tokens.scen.json"); } #[test] fn enter_mex_farm_go() { - multiversx_sc_scenario::run_go("scenarios/enter_mex_farm.scen.json"); + world().run("scenarios/enter_mex_farm.scen.json"); } #[test] fn exit_farm_go() { - multiversx_sc_scenario::run_go("scenarios/exit_farm.scen.json"); + world().run("scenarios/exit_farm.scen.json"); } #[test] fn exit_farm_too_soon_go() { - multiversx_sc_scenario::run_go("scenarios/exit_farm_too_soon.scen.json"); + world().run("scenarios/exit_farm_too_soon.scen.json"); } #[test] fn exit_mex_farm_go() { - multiversx_sc_scenario::run_go("scenarios/exit_mex_farm.scen.json"); + world().run("scenarios/exit_mex_farm.scen.json"); } #[test] fn farm_reward_distr_scen_1_go() { - multiversx_sc_scenario::run_go("scenarios/farm_reward_distr_scen_1.scen.json"); + world().run("scenarios/farm_reward_distr_scen_1.scen.json"); } #[test] fn farm_reward_distr_scen_2_go() { - multiversx_sc_scenario::run_go("scenarios/farm_reward_distr_scen_2.scen.json"); + world().run("scenarios/farm_reward_distr_scen_2.scen.json"); } #[test] fn farm_reward_distr_scen_3_go() { - multiversx_sc_scenario::run_go("scenarios/farm_reward_distr_scen_3.scen.json"); + world().run("scenarios/farm_reward_distr_scen_3.scen.json"); } #[test] fn farm_reward_distr_scen_4_go() { - multiversx_sc_scenario::run_go("scenarios/farm_reward_distr_scen_4.scen.json"); + world().run("scenarios/farm_reward_distr_scen_4.scen.json"); } #[test] fn farm_with_egld_token_go() { - multiversx_sc_scenario::run_go("scenarios/farm_with_egld_token.scen.json"); + world().run("scenarios/farm_with_egld_token.scen.json"); } #[test] fn farm_wrong_lp_token_go() { - multiversx_sc_scenario::run_go("scenarios/farm_wrong_lp_token.scen.json"); + world().run("scenarios/farm_wrong_lp_token.scen.json"); } #[test] fn get_amounts_go() { - multiversx_sc_scenario::run_go("scenarios/get_amounts.scen.json"); + world().run("scenarios/get_amounts.scen.json"); } #[test] fn get_amounts_no_liquidity_go() { - multiversx_sc_scenario::run_go("scenarios/get_amounts_no_liquidity.scen.json"); + world().run("scenarios/get_amounts_no_liquidity.scen.json"); } #[test] fn get_pair_non_existent_go() { - multiversx_sc_scenario::run_go("scenarios/get_pair_non_existent.scen.json"); + world().run("scenarios/get_pair_non_existent.scen.json"); } #[test] fn get_pair_views_go() { - multiversx_sc_scenario::run_go("scenarios/get_pair_views.scen.json"); + world().run("scenarios/get_pair_views.scen.json"); } #[test] fn merge_tokens_go() { - multiversx_sc_scenario::run_go("scenarios/merge_tokens.scen.json"); + world().run("scenarios/merge_tokens.scen.json"); } #[test] fn owner_pause_farm_go() { - multiversx_sc_scenario::run_go("scenarios/owner_pause_farm.scen.json"); + world().run("scenarios/owner_pause_farm.scen.json"); } #[test] fn owner_resume_farm_go() { - multiversx_sc_scenario::run_go("scenarios/owner_resume_farm.scen.json"); + world().run("scenarios/owner_resume_farm.scen.json"); } #[test] fn remove_liquidity_go() { - multiversx_sc_scenario::run_go("scenarios/remove_liquidity.scen.json"); + world().run("scenarios/remove_liquidity.scen.json"); } #[test] fn remove_liquidity_and_buyback_and_burn_token_go() { - multiversx_sc_scenario::run_go( - "scenarios/remove_liquidity_and_buyback_and_burn_token.scen.json", - ); + world().run("scenarios/remove_liquidity_and_buyback_and_burn_token.scen.json"); } #[test] fn remove_liquidity_twice_go() { - multiversx_sc_scenario::run_go("scenarios/remove_liquidity_twice.scen.json"); + world().run("scenarios/remove_liquidity_twice.scen.json"); } #[test] fn remove_pair_go() { - multiversx_sc_scenario::run_go("scenarios/remove_pair.scen.json"); + world().run("scenarios/remove_pair.scen.json"); } #[test] fn router_pause_self_go() { - multiversx_sc_scenario::run_go("scenarios/router_pause_self.scen.json"); + world().run("scenarios/router_pause_self.scen.json"); } #[test] fn router_resume_self_go() { - multiversx_sc_scenario::run_go("scenarios/router_resume_self.scen.json"); + world().run("scenarios/router_resume_self.scen.json"); } #[test] fn swap_fixed_input_go() { - multiversx_sc_scenario::run_go("scenarios/swap_fixed_input.scen.json"); + world().run("scenarios/swap_fixed_input.scen.json"); } #[test] fn swap_fixed_input_after_removed_liquidity_go() { - multiversx_sc_scenario::run_go("scenarios/swap_fixed_input_after_removed_liquidity.scen.json"); + world().run("scenarios/swap_fixed_input_after_removed_liquidity.scen.json"); } #[test] fn swap_fixed_output_go() { - multiversx_sc_scenario::run_go("scenarios/swap_fixed_output.scen.json"); + world().run("scenarios/swap_fixed_output.scen.json"); } #[test] fn swap_same_token_go() { - multiversx_sc_scenario::run_go("scenarios/swap_same_token.scen.json"); + world().run("scenarios/swap_same_token.scen.json"); } #[test] fn swap_wrong_token_go() { - multiversx_sc_scenario::run_go("scenarios/swap_wrong_token.scen.json"); + world().run("scenarios/swap_wrong_token.scen.json"); } #[test] fn upgrade_contract_go() { - multiversx_sc_scenario::run_go("scenarios/upgrade_contract.scen.json"); + world().run("scenarios/upgrade_contract.scen.json"); } diff --git a/dex/tests/dex_scenario_rs_test.rs b/dex/tests/dex_scenario_rs_test.rs index b5124f1d0..623f63667 100644 --- a/dex/tests/dex_scenario_rs_test.rs +++ b/dex/tests/dex_scenario_rs_test.rs @@ -13,212 +13,200 @@ fn world() -> ScenarioWorld { #[test] fn add_liquidity_rs() { - multiversx_sc_scenario::run_rs("scenarios/add_liquidity.scen.json", world()); + world().run("scenarios/add_liquidity.scen.json"); } #[test] fn calculate_rewards_for_given_position_rs() { - multiversx_sc_scenario::run_rs( - "scenarios/calculate_rewards_for_given_position.scen.json", - world(), - ); + world().run("scenarios/calculate_rewards_for_given_position.scen.json"); } #[test] fn calculate_rewards_for_given_position_after_compound_rs() { - multiversx_sc_scenario::run_rs( - "scenarios/calculate_rewards_for_given_position_after_compound.scen.json", - world(), - ); + world().run("scenarios/calculate_rewards_for_given_position_after_compound.scen.json"); } #[test] fn check_fee_disabled_after_swap_rs() { - multiversx_sc_scenario::run_rs("scenarios/check_fee_disabled_after_swap.scen.json", world()); + world().run("scenarios/check_fee_disabled_after_swap.scen.json"); } #[test] fn check_fee_enabled_after_swap_rs() { - multiversx_sc_scenario::run_rs("scenarios/check_fee_enabled_after_swap.scen.json", world()); + world().run("scenarios/check_fee_enabled_after_swap.scen.json"); } #[test] fn claim_rewards_rs() { - multiversx_sc_scenario::run_rs("scenarios/claim_rewards.scen.json", world()); + world().run("scenarios/claim_rewards.scen.json"); } #[test] fn complete_setup_rs() { - multiversx_sc_scenario::run_rs("scenarios/complete_setup.scen.json", world()); + world().run("scenarios/complete_setup.scen.json"); } #[test] fn compound_rewards_rs() { - multiversx_sc_scenario::run_rs("scenarios/compound_rewards.scen.json", world()); + world().run("scenarios/compound_rewards.scen.json"); } #[test] fn create_pair_twice_rs() { - multiversx_sc_scenario::run_rs("scenarios/create_pair_twice.scen.json", world()); + world().run("scenarios/create_pair_twice.scen.json"); } #[test] fn enter_farm_rs() { - multiversx_sc_scenario::run_rs("scenarios/enter_farm.scen.json", world()); + world().run("scenarios/enter_farm.scen.json"); } #[test] fn enter_farm_with_merge_tokens_rs() { - multiversx_sc_scenario::run_rs("scenarios/enter_farm_with_merge_tokens.scen.json", world()); + world().run("scenarios/enter_farm_with_merge_tokens.scen.json"); } #[test] fn enter_mex_farm_rs() { - multiversx_sc_scenario::run_rs("scenarios/enter_mex_farm.scen.json", world()); + world().run("scenarios/enter_mex_farm.scen.json"); } #[test] fn exit_farm_rs() { - multiversx_sc_scenario::run_rs("scenarios/exit_farm.scen.json", world()); + world().run("scenarios/exit_farm.scen.json"); } #[test] fn exit_farm_too_soon_rs() { - multiversx_sc_scenario::run_rs("scenarios/exit_farm_too_soon.scen.json", world()); + world().run("scenarios/exit_farm_too_soon.scen.json"); } #[test] fn exit_mex_farm_rs() { - multiversx_sc_scenario::run_rs("scenarios/exit_mex_farm.scen.json", world()); + world().run("scenarios/exit_mex_farm.scen.json"); } #[test] fn farm_reward_distr_scen_1_rs() { - multiversx_sc_scenario::run_rs("scenarios/farm_reward_distr_scen_1.scen.json", world()); + world().run("scenarios/farm_reward_distr_scen_1.scen.json"); } #[test] fn farm_reward_distr_scen_2_rs() { - multiversx_sc_scenario::run_rs("scenarios/farm_reward_distr_scen_2.scen.json", world()); + world().run("scenarios/farm_reward_distr_scen_2.scen.json"); } #[test] fn farm_reward_distr_scen_3_rs() { - multiversx_sc_scenario::run_rs("scenarios/farm_reward_distr_scen_3.scen.json", world()); + world().run("scenarios/farm_reward_distr_scen_3.scen.json"); } #[test] fn farm_reward_distr_scen_4_rs() { - multiversx_sc_scenario::run_rs("scenarios/farm_reward_distr_scen_4.scen.json", world()); + world().run("scenarios/farm_reward_distr_scen_4.scen.json"); } #[test] fn farm_with_egld_token_rs() { - multiversx_sc_scenario::run_rs("scenarios/farm_with_egld_token.scen.json", world()); + world().run("scenarios/farm_with_egld_token.scen.json"); } #[test] fn farm_wrong_lp_token_rs() { - multiversx_sc_scenario::run_rs("scenarios/farm_wrong_lp_token.scen.json", world()); + world().run("scenarios/farm_wrong_lp_token.scen.json"); } #[test] fn get_amounts_rs() { - multiversx_sc_scenario::run_rs("scenarios/get_amounts.scen.json", world()); + world().run("scenarios/get_amounts.scen.json"); } #[test] fn get_amounts_no_liquidity_rs() { - multiversx_sc_scenario::run_rs("scenarios/get_amounts_no_liquidity.scen.json", world()); + world().run("scenarios/get_amounts_no_liquidity.scen.json"); } #[test] fn get_pair_non_existent_rs() { - multiversx_sc_scenario::run_rs("scenarios/get_pair_non_existent.scen.json", world()); + world().run("scenarios/get_pair_non_existent.scen.json"); } #[test] fn get_pair_views_rs() { - multiversx_sc_scenario::run_rs("scenarios/get_pair_views.scen.json", world()); + world().run("scenarios/get_pair_views.scen.json"); } #[test] fn merge_tokens_rs() { - multiversx_sc_scenario::run_rs("scenarios/merge_tokens.scen.json", world()); + world().run("scenarios/merge_tokens.scen.json"); } #[test] fn owner_pause_farm_rs() { - multiversx_sc_scenario::run_rs("scenarios/owner_pause_farm.scen.json", world()); + world().run("scenarios/owner_pause_farm.scen.json"); } #[test] fn owner_resume_farm_rs() { - multiversx_sc_scenario::run_rs("scenarios/owner_resume_farm.scen.json", world()); + world().run("scenarios/owner_resume_farm.scen.json"); } #[test] fn remove_liquidity_rs() { - multiversx_sc_scenario::run_rs("scenarios/remove_liquidity.scen.json", world()); + world().run("scenarios/remove_liquidity.scen.json"); } #[test] fn remove_liquidity_and_buyback_and_burn_token_rs() { - multiversx_sc_scenario::run_rs( - "scenarios/remove_liquidity_and_buyback_and_burn_token.scen.json", - world(), - ); + world().run("scenarios/remove_liquidity_and_buyback_and_burn_token.scen.json"); } #[test] fn remove_liquidity_twice_rs() { - multiversx_sc_scenario::run_rs("scenarios/remove_liquidity_twice.scen.json", world()); + world().run("scenarios/remove_liquidity_twice.scen.json"); } #[test] fn remove_pair_rs() { - multiversx_sc_scenario::run_rs("scenarios/remove_pair.scen.json", world()); + world().run("scenarios/remove_pair.scen.json"); } #[test] fn router_pause_self_rs() { - multiversx_sc_scenario::run_rs("scenarios/router_pause_self.scen.json", world()); + world().run("scenarios/router_pause_self.scen.json"); } #[test] fn router_resume_self_rs() { - multiversx_sc_scenario::run_rs("scenarios/router_resume_self.scen.json", world()); + world().run("scenarios/router_resume_self.scen.json"); } #[test] fn swap_fixed_input_rs() { - multiversx_sc_scenario::run_rs("scenarios/swap_fixed_input.scen.json", world()); + world().run("scenarios/swap_fixed_input.scen.json"); } #[test] fn swap_fixed_input_after_removed_liquidity_rs() { - multiversx_sc_scenario::run_rs( - "scenarios/swap_fixed_input_after_removed_liquidity.scen.json", - world(), - ); + world().run("scenarios/swap_fixed_input_after_removed_liquidity.scen.json"); } #[test] fn swap_fixed_output_rs() { - multiversx_sc_scenario::run_rs("scenarios/swap_fixed_output.scen.json", world()); + world().run("scenarios/swap_fixed_output.scen.json"); } #[test] fn swap_same_token_rs() { - multiversx_sc_scenario::run_rs("scenarios/swap_same_token.scen.json", world()); + world().run("scenarios/swap_same_token.scen.json"); } #[test] fn swap_wrong_token_rs() { - multiversx_sc_scenario::run_rs("scenarios/swap_wrong_token.scen.json", world()); + world().run("scenarios/swap_wrong_token.scen.json"); } #[test] fn upgrade_contract_rs() { - multiversx_sc_scenario::run_rs("scenarios/upgrade_contract.scen.json", world()); + world().run("scenarios/upgrade_contract.scen.json"); } diff --git a/energy-integration/common-modules/energy-query/Cargo.toml b/energy-integration/common-modules/energy-query/Cargo.toml index 4538084dd..429ddafe2 100644 --- a/energy-integration/common-modules/energy-query/Cargo.toml +++ b/energy-integration/common-modules/energy-query/Cargo.toml @@ -6,8 +6,9 @@ edition = "2021" [lib] path = "src/lib.rs" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" 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 5572b47c6..32e16b01e 100644 --- a/energy-integration/common-modules/week-timekeeping/Cargo.toml +++ b/energy-integration/common-modules/week-timekeeping/Cargo.toml @@ -6,8 +6,9 @@ edition = "2021" [lib] path = "src/lib.rs" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" 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 17f83c964..0603f0084 100644 --- a/energy-integration/common-modules/weekly-rewards-splitting/Cargo.toml +++ b/energy-integration/common-modules/weekly-rewards-splitting/Cargo.toml @@ -6,8 +6,9 @@ edition = "2021" [lib] path = "src/lib.rs" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.energy-query] diff --git a/energy-integration/common-modules/weekly-rewards-splitting/src/base_impl.rs b/energy-integration/common-modules/weekly-rewards-splitting/src/base_impl.rs index e249aa9ba..c8579672d 100644 --- a/energy-integration/common-modules/weekly-rewards-splitting/src/base_impl.rs +++ b/energy-integration/common-modules/weekly-rewards-splitting/src/base_impl.rs @@ -1,6 +1,5 @@ multiversx_sc::imports!(); -use crate::update_claim_progress_energy::UpdateClaimProgressEnergyModule; use common_types::PaymentsVec; use week_timekeeping::Week; @@ -12,7 +11,8 @@ pub trait AllBaseWeeklyRewardsSplittingImplTraits = + week_timekeeping::WeekTimekeepingModule + crate::global_info::WeeklyRewardsGlobalInfo + crate::locked_token_buckets::WeeklyRewardsLockedTokenBucketsModule - + events::WeeklyRewardsSplittingEventsModule; + + events::WeeklyRewardsSplittingEventsModule + + crate::update_claim_progress_energy::UpdateClaimProgressEnergyModule; pub trait WeeklyRewardsSplittingTraitsModule { type WeeklyRewardsSplittingMod: AllBaseWeeklyRewardsSplittingImplTraits; diff --git a/energy-integration/common-modules/weekly-rewards-splitting/src/events.rs b/energy-integration/common-modules/weekly-rewards-splitting/src/events.rs index d7ae843ba..8d2b27f23 100644 --- a/energy-integration/common-modules/weekly-rewards-splitting/src/events.rs +++ b/energy-integration/common-modules/weekly-rewards-splitting/src/events.rs @@ -14,6 +14,9 @@ pub trait WeeklyRewardsSplittingEventsModule { energy: &Energy, all_payments: &ManagedVec>, ) { + if all_payments.is_empty() { + return; + } self.claim_multi_event(user, current_week, energy, all_payments); } diff --git a/energy-integration/common-modules/weekly-rewards-splitting/src/lib.rs b/energy-integration/common-modules/weekly-rewards-splitting/src/lib.rs index 8120994a9..9268023bd 100644 --- a/energy-integration/common-modules/weekly-rewards-splitting/src/lib.rs +++ b/energy-integration/common-modules/weekly-rewards-splitting/src/lib.rs @@ -86,25 +86,17 @@ pub trait WeeklyRewardsSplittingModule: let mut all_rewards = ManagedVec::new(); - // for the case when a user locks, enters the weekly rewards, and then unlocks. - // Then, they wait for a long period, and start claiming, - // getting rewards they shouldn't have access to. - // In this case, they receive no rewards, and their progress is reset - if current_user_energy.get_energy_amount_raw() - >= calculated_energy_for_current_epoch.get_energy_amount_raw() - { - let total_weeks_to_claim = current_week - claim_progress.week; - if total_weeks_to_claim > USER_MAX_CLAIM_WEEKS { - let extra_weeks = total_weeks_to_claim - USER_MAX_CLAIM_WEEKS; - claim_progress.advance_multiple_weeks(extra_weeks); - } + let total_weeks_to_claim = current_week - claim_progress.week; + if total_weeks_to_claim > USER_MAX_CLAIM_WEEKS { + let extra_weeks = total_weeks_to_claim - USER_MAX_CLAIM_WEEKS; + claim_progress.advance_multiple_weeks(extra_weeks); + } - let weeks_to_claim = core::cmp::min(total_weeks_to_claim, USER_MAX_CLAIM_WEEKS); - for _ in 0..weeks_to_claim { - let rewards_for_week = self.claim_single(wrapper, &mut claim_progress); - if !rewards_for_week.is_empty() { - all_rewards.append_vec(rewards_for_week); - } + let weeks_to_claim = core::cmp::min(total_weeks_to_claim, USER_MAX_CLAIM_WEEKS); + for _ in 0..weeks_to_claim { + let rewards_for_week = self.claim_single(wrapper, &mut claim_progress); + if !rewards_for_week.is_empty() { + all_rewards.append_vec(rewards_for_week); } } diff --git a/energy-integration/common-types/Cargo.toml b/energy-integration/common-types/Cargo.toml index 11a2466fa..b2ba8bc79 100644 --- a/energy-integration/common-types/Cargo.toml +++ b/energy-integration/common-types/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [lib] path = "src/lib.rs" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" 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 8af77face..6e246e8fb 100644 --- a/energy-integration/energy-factory-mock/Cargo.toml +++ b/energy-integration/energy-factory-mock/Cargo.toml @@ -7,11 +7,13 @@ publish = false [lib] path = "src/lib.rs" + [dependencies.energy-query] path = "../common-modules/energy-query" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] + [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" diff --git a/energy-integration/energy-factory-mock/meta/Cargo.toml b/energy-integration/energy-factory-mock/meta/Cargo.toml index 3c5417057..94241670d 100644 --- a/energy-integration/energy-factory-mock/meta/Cargo.toml +++ b/energy-integration/energy-factory-mock/meta/Cargo.toml @@ -6,8 +6,10 @@ publish = false authors = ["MultiversX "] [dev-dependencies] + [dependencies.energy-factory-mock] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/energy-integration/energy-factory-mock/wasm/Cargo.lock b/energy-integration/energy-factory-mock/wasm/Cargo.lock index 1b1924b82..0693d6d5f 100644 --- a/energy-integration/energy-factory-mock/wasm/Cargo.lock +++ b/energy-integration/energy-factory-mock/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common_errors" @@ -114,15 +91,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -131,9 +99,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "legacy_token_decode_module" @@ -144,12 +112,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - [[package]] name = "math" version = "0.0.0" @@ -157,12 +119,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -172,12 +128,11 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -186,20 +141,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -209,9 +163,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -222,21 +176,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -250,33 +203,27 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -310,15 +257,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -327,9 +274,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -347,43 +294,3 @@ dependencies = [ "mergeable", "multiversx-sc", ] - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/energy-integration/energy-factory-mock/wasm/Cargo.toml b/energy-integration/energy-factory-mock/wasm/Cargo.toml index 3c5feb01a..426c4c9f0 100644 --- a/energy-integration/energy-factory-mock/wasm/Cargo.toml +++ b/energy-integration/energy-factory-mock/wasm/Cargo.toml @@ -1,25 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "energy-factory-mock-wasm" version = "0.0.0" edition = "2021" publish = false -authors = ["MultiversX "] [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.energy-factory-mock] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/energy-integration/energy-factory-mock/wasm/src/lib.rs b/energy-integration/energy-factory-mock/wasm/src/lib.rs index bfa562d58..c52b88848 100644 --- a/energy-integration/energy-factory-mock/wasm/src/lib.rs +++ b/energy-integration/energy-factory-mock/wasm/src/lib.rs @@ -1,4 +1,4 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// @@ -10,7 +10,8 @@ // Total number of exported functions: 6 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,11 +19,12 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { energy_factory_mock ( - setUserEnergy - getEnergyAmountForUser - getEnergyEntryForUser - setUserEnergyAfterLockedTokenTransfer + init => init + setUserEnergy => set_user_energy + getEnergyAmountForUser => get_energy_amount_for_user + getEnergyEntryForUser => get_energy_entry_for_user + setUserEnergyAfterLockedTokenTransfer => set_user_energy_after_locked_token_transfer ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/energy-integration/energy-update/Cargo.toml b/energy-integration/energy-update/Cargo.toml index 2282d5687..01489f0d7 100644 --- a/energy-integration/energy-update/Cargo.toml +++ b/energy-integration/energy-update/Cargo.toml @@ -7,12 +7,13 @@ publish = false [lib] path = "src/lib.rs" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" [dependencies.farm] path = "../../dex/farm" @@ -24,4 +25,4 @@ path = "../common-modules/weekly-rewards-splitting" num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" diff --git a/energy-integration/energy-update/meta/Cargo.toml b/energy-integration/energy-update/meta/Cargo.toml index 52ca52bdd..aa816ac82 100644 --- a/energy-integration/energy-update/meta/Cargo.toml +++ b/energy-integration/energy-update/meta/Cargo.toml @@ -6,8 +6,10 @@ publish = false authors = ["MultiversX "] [dev-dependencies] + [dependencies.energy-update] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/energy-integration/energy-update/src/lib.rs b/energy-integration/energy-update/src/lib.rs index 730dd8f70..a8e10213f 100644 --- a/energy-integration/energy-update/src/lib.rs +++ b/energy-integration/energy-update/src/lib.rs @@ -9,6 +9,9 @@ pub trait EnergyUpdate { #[init] fn init(&self) {} + #[endpoint] + fn upgrade(&self) {} + #[endpoint(updateFarmsEnergyForUser)] fn update_farms_energy_for_user( &self, diff --git a/energy-integration/energy-update/wasm/Cargo.lock b/energy-integration/energy-update/wasm/Cargo.lock index 5173db1ce..559a8a519 100644 --- a/energy-integration/energy-update/wasm/Cargo.lock +++ b/energy-integration/energy-update/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common-types" @@ -99,9 +76,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "endian-type" @@ -263,15 +240,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -280,9 +248,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "itertools" @@ -302,12 +270,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - [[package]] name = "locking_module" version = "0.0.0" @@ -324,12 +286,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -339,12 +295,11 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -353,20 +308,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -376,9 +330,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -389,21 +343,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -417,19 +370,13 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "pair" version = "0.0.0" @@ -443,6 +390,7 @@ dependencies = [ "permissions_module", "simple-lock", "token_send", + "utils", ] [[package]] @@ -464,18 +412,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -524,15 +472,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -558,9 +506,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -579,24 +527,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - [[package]] name = "week-timekeeping" version = "0.0.0" @@ -616,25 +546,3 @@ dependencies = [ "unwrappable", "week-timekeeping", ] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/energy-integration/energy-update/wasm/Cargo.toml b/energy-integration/energy-update/wasm/Cargo.toml index 1186d489e..399b3a678 100644 --- a/energy-integration/energy-update/wasm/Cargo.toml +++ b/energy-integration/energy-update/wasm/Cargo.toml @@ -1,25 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "energy-update-wasm" version = "0.0.0" edition = "2021" publish = false -authors = ["MultiversX "] [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.energy-update] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/energy-integration/energy-update/wasm/src/lib.rs b/energy-integration/energy-update/wasm/src/lib.rs index 9ddd60e4c..b4de939ec 100644 --- a/energy-integration/energy-update/wasm/src/lib.rs +++ b/energy-integration/energy-update/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 1 +// Endpoints: 2 // Async Callback (empty): 1 -// Total number of exported functions: 3 +// Total number of exported functions: 4 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,8 +19,10 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { energy_update ( - updateFarmsEnergyForUser + init => init + upgrade => upgrade + updateFarmsEnergyForUser => update_farms_energy_for_user ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/energy-integration/farm-boosted-yields/Cargo.toml b/energy-integration/farm-boosted-yields/Cargo.toml index 19d33b080..5a75c8b80 100644 --- a/energy-integration/farm-boosted-yields/Cargo.toml +++ b/energy-integration/farm-boosted-yields/Cargo.toml @@ -6,8 +6,9 @@ edition = "2021" [lib] path = "src/lib.rs" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" 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 e9b38e526..931c58f9d 100644 --- a/energy-integration/farm-boosted-yields/src/lib.rs +++ b/energy-integration/farm-boosted-yields/src/lib.rs @@ -6,6 +6,7 @@ use core::cmp; use boosted_yields_factors::BoostedYieldsConfig; use common_types::PaymentsVec; +use multiversx_sc::api::ErrorApi; use week_timekeeping::Week; use weekly_rewards_splitting::{ base_impl::WeeklyRewardsSplittingTraitsModule, USER_MAX_CLAIM_WEEKS, @@ -128,17 +129,14 @@ pub trait FarmBoostedYieldsModule: self.farm_supply_for_week(current_week).set(farm_supply); } - fn clear_user_energy_if_needed( - &self, - original_caller: &ManagedAddress, - user_remaining_farm_tokens: &BigUint, - ) { + 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_remaining_farm_tokens, + &user_total_farm_position.total_farm_position, &boosted_yields_factors.min_farm_amount, ); } diff --git a/energy-integration/fees-collector/Cargo.toml b/energy-integration/fees-collector/Cargo.toml index 1f260d8f6..1b233b7f6 100644 --- a/energy-integration/fees-collector/Cargo.toml +++ b/energy-integration/fees-collector/Cargo.toml @@ -7,12 +7,13 @@ publish = false [lib] path = "src/lib.rs" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" [dependencies.energy-query] path = "../common-modules/energy-query" @@ -48,7 +49,7 @@ path = "../../common/common_errors" num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" [dev-dependencies.sc_whitelist_module] path = "../../common/modules/sc_whitelist_module" diff --git a/energy-integration/fees-collector/elrond.json b/energy-integration/fees-collector/elrond.json deleted file mode 100644 index 736553962..000000000 --- a/energy-integration/fees-collector/elrond.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "language": "rust" -} \ No newline at end of file diff --git a/energy-integration/fees-collector/meta/Cargo.toml b/energy-integration/fees-collector/meta/Cargo.toml index a619bb638..c91986348 100644 --- a/energy-integration/fees-collector/meta/Cargo.toml +++ b/energy-integration/fees-collector/meta/Cargo.toml @@ -6,8 +6,10 @@ publish = false authors = ["MultiversX "] [dev-dependencies] + [dependencies.fees-collector] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/energy-integration/fees-collector/src/config.rs b/energy-integration/fees-collector/src/config.rs index 9a369df9a..a21dc6d6b 100644 --- a/energy-integration/fees-collector/src/config.rs +++ b/energy-integration/fees-collector/src/config.rs @@ -60,6 +60,13 @@ pub trait ConfigModule { self.all_tokens().set(&all_tokens_vec); } + #[endpoint(setAllowExternalClaimRewards)] + fn set_allow_external_claim_rewards(&self, allow_external_claim_rewards: bool) { + let caller = self.blockchain().get_caller(); + self.allow_external_claim_rewards(&caller) + .set(allow_external_claim_rewards); + } + #[view(getLockedTokenId)] #[storage_mapper("lockedTokenId")] fn locked_token_id(&self) -> SingleValueMapper; @@ -78,4 +85,8 @@ pub trait ConfigModule { #[storage_mapper("allTokens")] fn all_tokens(&self) -> SingleValueMapper>; + + #[view(getAllowExternalClaimRewards)] + #[storage_mapper("allowExternalClaimRewards")] + fn allow_external_claim_rewards(&self, user: &ManagedAddress) -> SingleValueMapper; } diff --git a/energy-integration/fees-collector/src/lib.rs b/energy-integration/fees-collector/src/lib.rs index da7698e88..b5a37d7fb 100644 --- a/energy-integration/fees-collector/src/lib.rs +++ b/energy-integration/fees-collector/src/lib.rs @@ -44,18 +44,50 @@ pub trait FeesCollector: self.energy_factory_address().set(&energy_factory_address); } + #[endpoint] + fn upgrade(&self) {} + #[endpoint(claimRewards)] - fn claim_rewards( + fn claim_rewards_endpoint( &self, opt_original_caller: OptionalValue, ) -> PaymentsVec { require!(self.not_paused(), "Cannot claim while paused"); - self.accumulate_additional_locked_tokens(); - let caller = self.blockchain().get_caller(); let original_caller = self.get_orig_caller_from_opt(&caller, opt_original_caller); + self.claim_rewards(caller, original_caller) + } + + #[endpoint(claimBoostedRewards)] + fn claim_boosted_rewards( + &self, + opt_original_caller: OptionalValue, + ) -> PaymentsVec { + require!(self.not_paused(), "Cannot claim while paused"); + + let original_caller = match opt_original_caller { + OptionalValue::Some(user) => { + require!( + self.allow_external_claim_rewards(&user).get(), + "Cannot claim rewards for this address" + ); + user + } + OptionalValue::None => self.blockchain().get_caller(), + }; + + self.claim_rewards(original_caller.clone(), original_caller) + } + + fn claim_rewards( + &self, + caller: ManagedAddress, + original_caller: ManagedAddress, + ) -> PaymentsVec { + self.accumulate_additional_locked_tokens(); + let wrapper = FeesCollectorWrapper::new(); let mut rewards = self.claim_multi(&wrapper, &original_caller); if rewards.is_empty() { diff --git a/energy-integration/fees-collector/tests/fees_collector_rust_test.rs b/energy-integration/fees-collector/tests/fees_collector_rust_test.rs index c840080e5..11151d2dc 100644 --- a/energy-integration/fees-collector/tests/fees_collector_rust_test.rs +++ b/energy-integration/fees-collector/tests/fees_collector_rust_test.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + mod fees_collector_test_setup; use energy_query::Energy; @@ -464,7 +466,7 @@ fn claim_second_week_test() { } #[test] -fn claim_inactive_week_test() { +fn claim_for_other_user_test() { let rust_zero = rust_biguint!(0); let mut fc_setup = FeesCollectorSetup::new(fees_collector::contract_obj, energy_factory::contract_obj); @@ -472,36 +474,59 @@ fn claim_inactive_week_test() { let first_user = fc_setup.b_mock.create_user_account(&rust_zero); let second_user = fc_setup.b_mock.create_user_account(&rust_zero); - fc_setup.set_energy(&first_user, 50, 3_000); - fc_setup.set_energy(&second_user, 50, 9_000); + fc_setup.set_energy(&first_user, 500, 1_000); + fc_setup.set_energy(&second_user, 500, 9_000); fc_setup.deposit(FIRST_TOKEN_ID, USER_BALANCE).assert_ok(); fc_setup .deposit(SECOND_TOKEN_ID, USER_BALANCE / 2) .assert_ok(); - // user claim first week - users only get registered for week 2, without receiving rewards + // user claim first week - user only get registered for week 2, without receiving rewards fc_setup.claim(&first_user).assert_ok(); fc_setup.claim(&second_user).assert_ok(); // advance week fc_setup.advance_week(); - // deposit rewards week 2 - fc_setup.deposit(FIRST_TOKEN_ID, USER_BALANCE).assert_ok(); + // increase first user's energy + fc_setup.set_energy(&first_user, 1000, 2_000); + + // claim week 2 - receives rewards accumulated in week 1, and gets new energy saved fc_setup - .deposit(SECOND_TOKEN_ID, USER_BALANCE / 2) + .claim_for_user(&first_user, &second_user) + .assert_user_error("Cannot claim rewards for this address"); + + fc_setup + .allow_external_claim_rewards(&first_user) .assert_ok(); + // claim week 2 - receives rewards accumulated in week 1, and gets new energy saved - // decrease user energy - fc_setup.set_energy(&first_user, 50, 2_650); + fc_setup + .claim_for_user(&first_user, &second_user) + .assert_ok(); - // only first user claims in second week - fc_setup.claim(&first_user).assert_ok(); + fc_setup + .b_mock + .execute_query(&fc_setup.fc_wrapper, |sc| { + let mut expected_total_rewards = ManagedVec::new(); + expected_total_rewards.push(EsdtTokenPayment::new( + managed_token_id!(FIRST_TOKEN_ID), + 0, + managed_biguint!(USER_BALANCE), + )); + expected_total_rewards.push(EsdtTokenPayment::new( + managed_token_id!(SECOND_TOKEN_ID), + 0, + managed_biguint!(USER_BALANCE / 2), + )); + assert_eq!(expected_total_rewards, sc.total_rewards_for_week(1).get()); + }) + .assert_ok(); - let first_user_expected_first_token_amt = rust_biguint!(USER_BALANCE) * 3_000u32 / 12_000u32; + let first_user_expected_first_token_amt = rust_biguint!(USER_BALANCE) * 1_000u32 / 10_000u32; let first_user_expected_second_token_amt = - rust_biguint!(USER_BALANCE / 2) * 3_000u32 / 12_000u32; + rust_biguint!(USER_BALANCE / 2) * 1_000u32 / 10_000u32; fc_setup.b_mock.check_esdt_balance( &first_user, @@ -518,18 +543,50 @@ fn claim_inactive_week_test() { fc_setup .b_mock .execute_query(&fc_setup.fc_wrapper, |sc| { - // 12_000 - 700 + 350 - 3_000 + 2_650 - // = 11_300 + 350 - 350 - // = 11_300 - assert_eq!(sc.total_energy_for_week(2).get(), 11_300); // 11_650 - assert_eq!(sc.total_locked_tokens_for_week(2).get(), 100); - assert_eq!(sc.last_global_update_week().get(), 2); + // fees were cleared and accumulated in the total_rewards mapper + assert_eq!( + sc.accumulated_fees(1, &managed_token_id!(FIRST_TOKEN_ID)) + .get(), + managed_biguint!(0) + ); + assert_eq!( + sc.accumulated_fees(1, &managed_token_id!(SECOND_TOKEN_ID)) + .get(), + managed_biguint!(0) + ); + + let mut expected_total_rewards = ManagedVec::new(); + expected_total_rewards.push(EsdtTokenPayment::new( + managed_token_id!(FIRST_TOKEN_ID), + 0, + managed_biguint!(USER_BALANCE), + )); + expected_total_rewards.push(EsdtTokenPayment::new( + managed_token_id!(SECOND_TOKEN_ID), + 0, + managed_biguint!(USER_BALANCE / 2), + )); + assert_eq!(sc.total_rewards_for_week(1).get(), expected_total_rewards); + // first user's new energy is added to week 2 let first_user_energy = Energy::new( - BigInt::from(managed_biguint!(2_650)), + BigInt::from(managed_biguint!(2_000)), current_epoch, - managed_biguint!(50), + managed_biguint!(1_000), ); + + // 10_000 total prev week + // first user's tokens get removed, as they expired + // so we only decrease by second user's 500 tokens worth of energy + // + // - 7 * 500 global decrease (-3_500) + // - 1_000 (first user's surplus energy) + // + 2_000 (first user's new energy) + // = 7_500 + assert_eq!(sc.total_energy_for_week(2).get(), 7_500); + assert_eq!(sc.total_locked_tokens_for_week(2).get(), 1_500); + assert_eq!(sc.last_global_update_week().get(), 2); + assert_eq!( sc.current_claim_progress(&managed_address!(&first_user)) .get(), @@ -540,34 +597,10 @@ fn claim_inactive_week_test() { ); }) .assert_ok(); - - // advance week - fc_setup.advance_week(); - - // second user claim third week - fc_setup.claim(&second_user).assert_ok(); - - // energy week 2 for second user will be 9_000 - 7 * 50 = 9_000 - 350 = 8_650 - let second_user_expected_first_token_amt = rust_biguint!(USER_BALANCE) * 9_000u32 / 12_000u32 - + rust_biguint!(USER_BALANCE) * 8_650u32 / 11_300u32; - let second_user_expected_second_token_amt = rust_biguint!(USER_BALANCE / 2) * 9_000u32 - / 12_000u32 - + rust_biguint!(USER_BALANCE / 2) * 8_650u32 / 11_300u32; - - fc_setup.b_mock.check_esdt_balance( - &second_user, - FIRST_TOKEN_ID, - &second_user_expected_first_token_amt, - ); - fc_setup.b_mock.check_esdt_balance( - &second_user, - SECOND_TOKEN_ID, - &second_user_expected_second_token_amt, - ); } #[test] -fn try_claim_after_unlock() { +fn claim_inactive_week_test() { let rust_zero = rust_biguint!(0); let mut fc_setup = FeesCollectorSetup::new(fees_collector::contract_obj, energy_factory::contract_obj); @@ -597,25 +630,39 @@ fn try_claim_after_unlock() { .assert_ok(); // decrease user energy - fc_setup.set_energy(&first_user, 50, 1_000); + fc_setup.set_energy(&first_user, 50, 2_650); // only first user claims in second week fc_setup.claim(&first_user).assert_ok(); - // no rewards are received, as energy decreased from the calculated amount - fc_setup - .b_mock - .check_esdt_balance(&first_user, FIRST_TOKEN_ID, &rust_zero); - fc_setup - .b_mock - .check_esdt_balance(&first_user, SECOND_TOKEN_ID, &rust_zero); + let first_user_expected_first_token_amt = rust_biguint!(USER_BALANCE) * 3_000u32 / 12_000u32; + let first_user_expected_second_token_amt = + rust_biguint!(USER_BALANCE / 2) * 3_000u32 / 12_000u32; + + fc_setup.b_mock.check_esdt_balance( + &first_user, + FIRST_TOKEN_ID, + &first_user_expected_first_token_amt, + ); + fc_setup.b_mock.check_esdt_balance( + &first_user, + SECOND_TOKEN_ID, + &first_user_expected_second_token_amt, + ); let current_epoch = fc_setup.current_epoch; fc_setup .b_mock .execute_query(&fc_setup.fc_wrapper, |sc| { + // 12_000 - 700 + 350 - 3_000 + 2_650 + // = 11_300 + 350 - 350 + // = 11_300 + assert_eq!(sc.total_energy_for_week(2).get(), 11_300); // 11_650 + assert_eq!(sc.total_locked_tokens_for_week(2).get(), 100); + assert_eq!(sc.last_global_update_week().get(), 2); + let first_user_energy = Energy::new( - BigInt::from(managed_biguint!(1_000)), + BigInt::from(managed_biguint!(2_650)), current_epoch, managed_biguint!(50), ); @@ -629,6 +676,30 @@ fn try_claim_after_unlock() { ); }) .assert_ok(); + + // advance week + fc_setup.advance_week(); + + // second user claim third week + fc_setup.claim(&second_user).assert_ok(); + + // energy week 2 for second user will be 9_000 - 7 * 50 = 9_000 - 350 = 8_650 + let second_user_expected_first_token_amt = rust_biguint!(USER_BALANCE) * 9_000u32 / 12_000u32 + + rust_biguint!(USER_BALANCE) * 8_650u32 / 11_300u32; + let second_user_expected_second_token_amt = rust_biguint!(USER_BALANCE / 2) * 9_000u32 + / 12_000u32 + + rust_biguint!(USER_BALANCE / 2) * 8_650u32 / 11_300u32; + + fc_setup.b_mock.check_esdt_balance( + &second_user, + FIRST_TOKEN_ID, + &second_user_expected_first_token_amt, + ); + fc_setup.b_mock.check_esdt_balance( + &second_user, + SECOND_TOKEN_ID, + &second_user_expected_second_token_amt, + ); } #[test] diff --git a/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs b/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs index e3524ce65..359c4eeb5 100644 --- a/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs +++ b/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + use multiversx_sc::{ codec::multi_types::OptionalValue, storage::mappers::StorageTokenWrapper, @@ -5,7 +7,7 @@ use multiversx_sc::{ }; use multiversx_sc_scenario::{ managed_address, managed_biguint, managed_token_id, managed_token_id_wrapped, rust_biguint, - whitebox::TxResult, whitebox::*, DebugApi, + whitebox_legacy::TxResult, whitebox_legacy::*, DebugApi, }; use energy_factory::{energy::EnergyModule, SimpleLockEnergy}; @@ -106,7 +108,7 @@ where &rust_biguint!(USER_BALANCE * 2), ); - let _ = DebugApi::dummy(); + DebugApi::dummy(); b_mock.set_nft_balance( &depositor_address, @@ -223,7 +225,22 @@ where pub fn claim(&mut self, user: &Address) -> TxResult { self.b_mock .execute_tx(user, &self.fc_wrapper, &rust_biguint!(0), |sc| { - let _ = sc.claim_rewards(OptionalValue::None); + let _ = sc.claim_rewards_endpoint(OptionalValue::None); + }) + } + + pub fn claim_for_user(&mut self, owner: &Address, broker: &Address) -> TxResult { + self.b_mock + .execute_tx(broker, &self.fc_wrapper, &rust_biguint!(0), |sc| { + let _ = sc.claim_boosted_rewards(OptionalValue::Some(managed_address!(owner))); + }) + } + + pub fn allow_external_claim_rewards(&mut self, user: &Address) -> TxResult { + self.b_mock + .execute_tx(user, &self.fc_wrapper, &rust_biguint!(0), |sc| { + sc.allow_external_claim_rewards(&managed_address!(user)) + .set(true); }) } diff --git a/energy-integration/fees-collector/wasm/Cargo.lock b/energy-integration/fees-collector/wasm/Cargo.lock index 601610441..d31ccf2dc 100644 --- a/energy-integration/fees-collector/wasm/Cargo.lock +++ b/energy-integration/fees-collector/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common-types" @@ -131,15 +108,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -148,9 +116,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "legacy_token_decode_module" @@ -161,12 +129,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - [[package]] name = "locking_module" version = "0.0.0" @@ -183,12 +145,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -198,12 +154,11 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -212,20 +167,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -235,9 +189,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -248,21 +202,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -276,33 +229,27 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -336,15 +283,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -353,9 +300,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -374,24 +321,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - [[package]] name = "week-timekeeping" version = "0.0.0" @@ -411,25 +340,3 @@ dependencies = [ "unwrappable", "week-timekeeping", ] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/energy-integration/fees-collector/wasm/Cargo.toml b/energy-integration/fees-collector/wasm/Cargo.toml index 8ccf99214..67ff1cdc8 100644 --- a/energy-integration/fees-collector/wasm/Cargo.toml +++ b/energy-integration/fees-collector/wasm/Cargo.toml @@ -1,25 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "fees-collector-wasm" version = "0.0.0" edition = "2021" publish = false -authors = ["MultiversX "] [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.fees-collector] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/energy-integration/fees-collector/wasm/src/lib.rs b/energy-integration/fees-collector/wasm/src/lib.rs index 74fbfdf40..75812bfb1 100644 --- a/energy-integration/fees-collector/wasm/src/lib.rs +++ b/energy-integration/fees-collector/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 35 +// Endpoints: 39 // Async Callback (empty): 1 -// Total number of exported functions: 37 +// Total number of exported functions: 41 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,42 +19,47 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { fees_collector ( - claimRewards - addKnownContracts - removeKnownContracts - addKnownTokens - removeKnownTokens - getLockedTokenId - getAllTokens - getAllKnownContracts - getLastActiveWeekForUser - getUserEnergyForWeek - getLastGlobalUpdateWeek - getTotalRewardsForWeek - getTotalEnergyForWeek - getTotalLockedTokensForWeek - updateEnergyForUser - getCurrentClaimProgress - depositSwapFees - getAccumulatedFees - setLockedTokensPerBlock - getLastLockedTokensAddWeek - getLockedTokensPerBlock - setLockingScAddress - setLockEpochs - getLockingScAddress - getLockEpochs - setEnergyFactoryAddress - getEnergyFactoryAddress - getCurrentWeek - getFirstWeekStartEpoch - pause - unpause - isPaused - addSCAddressToWhitelist - removeSCAddressFromWhitelist - isSCAddressWhitelisted + init => init + upgrade => upgrade + claimRewards => claim_rewards_endpoint + claimBoostedRewards => claim_boosted_rewards + addKnownContracts => add_known_contracts + removeKnownContracts => remove_known_contracts + addKnownTokens => add_known_tokens + removeKnownTokens => remove_known_tokens + setAllowExternalClaimRewards => set_allow_external_claim_rewards + getLockedTokenId => locked_token_id + getAllTokens => get_all_tokens + getAllKnownContracts => known_contracts + getAllowExternalClaimRewards => allow_external_claim_rewards + getLastActiveWeekForUser => get_last_active_week_for_user_view + getUserEnergyForWeek => get_user_energy_for_week_view + getLastGlobalUpdateWeek => last_global_update_week + getTotalRewardsForWeek => total_rewards_for_week + getTotalEnergyForWeek => total_energy_for_week + getTotalLockedTokensForWeek => total_locked_tokens_for_week + updateEnergyForUser => update_energy_for_user + getCurrentClaimProgress => current_claim_progress + depositSwapFees => deposit_swap_fees + getAccumulatedFees => accumulated_fees + setLockedTokensPerBlock => set_locked_tokens_per_block + getLastLockedTokensAddWeek => last_locked_token_add_week + getLockedTokensPerBlock => locked_tokens_per_block + setLockingScAddress => set_locking_sc_address + setLockEpochs => set_lock_epochs + getLockingScAddress => locking_sc_address + getLockEpochs => lock_epochs + setEnergyFactoryAddress => set_energy_factory_address + getEnergyFactoryAddress => energy_factory_address + getCurrentWeek => get_current_week + getFirstWeekStartEpoch => first_week_start_epoch + pause => pause_endpoint + unpause => unpause_endpoint + isPaused => paused_status + addSCAddressToWhitelist => add_sc_address_to_whitelist + removeSCAddressFromWhitelist => remove_sc_address_from_whitelist + isSCAddressWhitelisted => is_sc_address_whitelisted ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/energy-integration/governance-v2/Cargo.toml b/energy-integration/governance-v2/Cargo.toml index 5e368a734..1b190cd64 100644 --- a/energy-integration/governance-v2/Cargo.toml +++ b/energy-integration/governance-v2/Cargo.toml @@ -8,12 +8,27 @@ publish = false [lib] path = "src/lib.rs" +[dependencies.energy-query] +path = "../common-modules/energy-query" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] +[dependencies.permissions_module] +path = "../../common/modules/permissions_module" + +[dependencies.fees-collector] +path = "../fees-collector" + +[dependencies.weekly-rewards-splitting] +path = "../common-modules/weekly-rewards-splitting" + [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" + +[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 d53044ef9..ca5a80d29 100644 --- a/energy-integration/governance-v2/meta/Cargo.toml +++ b/energy-integration/governance-v2/meta/Cargo.toml @@ -6,8 +6,10 @@ publish = false authors = ["MultiversX "] [dev-dependencies] + [dependencies.governance-v2] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/energy-integration/governance-v2/src/caller_check.rs b/energy-integration/governance-v2/src/caller_check.rs deleted file mode 100644 index f21475a58..000000000 --- a/energy-integration/governance-v2/src/caller_check.rs +++ /dev/null @@ -1,14 +0,0 @@ -multiversx_sc::imports!(); - -#[multiversx_sc::module] -pub trait CallerCheckModule { - fn require_caller_not_self(&self) { - let caller = self.blockchain().get_caller(); - let sc_address = self.blockchain().get_sc_address(); - - require!( - caller != sc_address, - "Cannot call this endpoint through proposed action" - ); - } -} diff --git a/energy-integration/governance-v2/src/configurable.rs b/energy-integration/governance-v2/src/configurable.rs index 3df438fef..b8736c0ca 100644 --- a/energy-integration/governance-v2/src/configurable.rs +++ b/energy-integration/governance-v2/src/configurable.rs @@ -1,4 +1,4 @@ -use crate::{errors::ERROR_NOT_AN_ESDT, FULL_PERCENTAGE}; +use crate::errors::ERROR_NOT_AN_ESDT; multiversx_sc::imports!(); @@ -11,7 +11,7 @@ multiversx_sc::imports!(); /// /// Voting is done through tokens ownership. /// -/// The module provides the following configurable parameters: +/// The module provides the following configurable parameters: /// - `quorum` - the minimum number of (`votes` minus `downvotes`) at the end of voting period /// - `maxActionsPerProposal` - Maximum number of actions (transfers and/or smart contract calls) that a proposal may have /// - `votingDelayInBlocks` - Number of blocks to wait after a block is proposed before being able to vote/downvote that proposal @@ -38,6 +38,8 @@ const MAX_QUORUM: u64 = 6_000; // 60% const MIN_MIN_FEE_FOR_PROPOSE: u64 = 1; const MAX_MIN_FEE_FOR_PROPOSE: u64 = 200_000_000_000; const DECIMALS_CONST: u64 = 1_000_000_000_000_000_000; +pub const MAX_GAS_LIMIT_PER_BLOCK: u64 = 600_000_000; +pub const FULL_PERCENTAGE: u64 = 10_000; #[multiversx_sc::module] pub trait ConfigurablePropertiesModule { diff --git a/energy-integration/governance-v2/src/lib.rs b/energy-integration/governance-v2/src/lib.rs index c914e3a95..f3800f915 100644 --- a/energy-integration/governance-v2/src/lib.rs +++ b/energy-integration/governance-v2/src/lib.rs @@ -2,7 +2,6 @@ multiversx_sc::imports!(); -pub mod caller_check; pub mod configurable; mod errors; pub mod events; @@ -13,6 +12,7 @@ pub mod views; use proposal::*; use proposal_storage::VoteType; +use crate::configurable::{FULL_PERCENTAGE, MAX_GAS_LIMIT_PER_BLOCK}; use crate::errors::*; use crate::proposal_storage::ProposalVotes; @@ -25,7 +25,6 @@ pub trait GovernanceV2: configurable::ConfigurablePropertiesModule + events::EventsModule + proposal_storage::ProposalStorageModule - + caller_check::CallerCheckModule + views::ViewsModule { /// - `min_fee_for_propose` - the minimum fee required for submitting a proposal; @@ -38,7 +37,7 @@ pub trait GovernanceV2: fn init( &self, min_fee_for_propose: BigUint, - quorum_percentage: BigUint, + quorum_percentage: u64, voting_delay_in_blocks: u64, voting_period_in_blocks: u64, withdraw_percentage_defeated: u64, @@ -52,6 +51,17 @@ pub trait GovernanceV2: self.try_change_fee_token_id(fee_token); } + #[endpoint] + fn upgrade( + &self, + proposal_id: ProposalId, + total_percentage: BigUint, + ) { + let mut proposal = self.proposals().get(proposal_id); + proposal.total_quorum = total_percentage; + self.proposals().set(proposal_id, &proposal); + } + /// Propose a list of actions. /// A maximum of MAX_GOVERNANCE_PROPOSAL_ACTIONS can be proposed at a time. /// @@ -207,13 +217,9 @@ pub trait GovernanceV2: } } - /// Cancel a proposed action. This can be done: - /// - by the proposer, at any time - /// - by anyone, if the proposal was defeated + /// Cancel a proposed action. This can be done only during Pending status #[endpoint] fn cancel(&self, proposal_id: ProposalId) { - self.require_caller_not_self(); - match self.get_proposal_status(proposal_id) { GovernanceProposalStatus::None => { sc_panic!(NO_PROPOSAL); @@ -234,10 +240,9 @@ pub trait GovernanceV2: } /// When a proposal was defeated, the proposer can withdraw - /// a part of the FEE. + /// If DefeatedWithVeto only part of the fee can be withdrawn #[endpoint(withdrawDeposit)] fn withdraw_deposit(&self, proposal_id: ProposalId) { - self.require_caller_not_self(); let caller = self.blockchain().get_caller(); match self.get_proposal_status(proposal_id) { diff --git a/energy-integration/governance-v2/src/proposal.rs b/energy-integration/governance-v2/src/proposal.rs index b91f57969..a1e916e69 100644 --- a/energy-integration/governance-v2/src/proposal.rs +++ b/energy-integration/governance-v2/src/proposal.rs @@ -1,3 +1,5 @@ +use multiversx_sc::codec::{DecodeDefault, EncodeDefault}; + multiversx_sc::imports!(); multiversx_sc::derive_imports!(); @@ -52,7 +54,9 @@ impl From> for GovernanceAction } } -#[derive(TypeAbi, TopEncode, TopDecode, PartialEq, Debug)] +#[derive( + TypeAbi, NestedEncode, NestedDecode, PartialEq, Debug, TopEncodeOrDefault, TopDecodeOrDefault, +)] pub struct GovernanceProposal { pub proposal_id: usize, pub proposer: ManagedAddress, @@ -60,10 +64,52 @@ pub struct GovernanceProposal { pub description: ManagedBuffer, pub root_hash: ManagedByteArray, pub fee_payment: EsdtTokenPayment, - pub minimum_quorum: BigUint, + pub minimum_quorum: u64, pub voting_delay_in_blocks: u64, pub voting_period_in_blocks: u64, pub withdraw_percentage_defeated: u64, pub total_quorum: BigUint, pub proposal_start_block: u64, + pub fee_withdrawn: bool, +} + +impl EncodeDefault for GovernanceProposal { + fn is_default(&self) -> bool { + self.proposal_id == 0 + } +} + +impl DecodeDefault for GovernanceProposal { + fn default() -> Self { + Self::new() + } +} + +impl Default for GovernanceProposal { + fn default() -> Self { + Self::new() + } +} + +impl GovernanceProposal { + pub fn new() -> Self { + GovernanceProposal { + proposal_id: 0, + proposer: ManagedAddress::default(), + actions: ArrayVec::default(), + description: ManagedBuffer::default(), + fee_payment: EsdtTokenPayment { + token_identifier: TokenIdentifier::from(""), + token_nonce: 0, + amount: BigUint::zero(), + }, + minimum_quorum: 0, + voting_delay_in_blocks: 0, + voting_period_in_blocks: 0, + withdraw_percentage_defeated: 0, + total_quorum: BigUint::default(), + proposal_start_block: 0, + fee_withdrawn: false, + } + } } diff --git a/energy-integration/governance-v2/src/proposal_storage.rs b/energy-integration/governance-v2/src/proposal_storage.rs index 1e7db1561..28dd58c1d 100644 --- a/energy-integration/governance-v2/src/proposal_storage.rs +++ b/energy-integration/governance-v2/src/proposal_storage.rs @@ -39,22 +39,6 @@ impl ProposalVotes { pub fn get_total_votes(&self) -> BigUint { &self.up_votes + &self.down_votes + &self.down_veto_votes + &self.abstain_votes } - pub fn get_up_votes_percentage(&self) -> BigUint { - let total_votes = self.get_total_votes(); - &self.up_votes / &total_votes - } - pub fn get_down_votes_percentage(&self) -> BigUint { - let total_votes = self.get_total_votes(); - &self.down_votes / &total_votes - } - pub fn get_down_veto_votes_percentage(&self) -> BigUint { - let total_votes = self.get_total_votes(); - &self.down_veto_votes / &total_votes - } - pub fn get_abstain_votes_percentage(&self) -> BigUint { - let total_votes = self.get_total_votes(); - &self.abstain_votes / &total_votes - } } #[multiversx_sc::module] diff --git a/energy-integration/governance-v2/tests/gov_rust_test.rs b/energy-integration/governance-v2/tests/gov_rust_test.rs index f2cc5bf9e..342655adf 100644 --- a/energy-integration/governance-v2/tests/gov_rust_test.rs +++ b/energy-integration/governance-v2/tests/gov_rust_test.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + mod gov_test_setup; use gov_test_setup::*; @@ -5,8 +7,8 @@ use governance_v2::{ configurable::ConfigurablePropertiesModule, proposal::GovernanceProposalStatus, proposal_storage::ProposalStorageModule, views::ViewsModule, }; -use multiversx_sc::{codec::Empty, types::ManagedVec}; -use multiversx_sc_scenario::{managed_biguint, managed_buffer, rust_biguint}; +use multiversx_sc::types::ManagedVec; +use multiversx_sc_scenario::{managed_buffer, rust_biguint}; #[test] fn init_gov_test() { @@ -17,22 +19,16 @@ fn init_gov_test() { fn gov_propose_test() { let mut gov_setup = GovSetup::new(governance_v2::contract_obj); - let first_user_addr = gov_setup.first_merkle_user.clone(); - let first_user_power = gov_setup.get_first_user_voting_power(); - let first_user_proof = gov_setup.first_merkle_proof(); - let second_user_addr = gov_setup.second_merkle_user.clone(); - let second_user_power = gov_setup.get_second_user_voting_power(); - let second_user_proof = gov_setup.second_merkle_proof(); + let first_user_addr = gov_setup.first_user.clone(); + let second_user_addr = gov_setup.second_user.clone(); let sc_addr = gov_setup.gov_wrapper.address_ref().clone(); let min_fee = rust_biguint!(MIN_FEE_FOR_PROPOSE) * DECIMALS_CONST; - // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&first_user_addr, WXMEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); let (result, proposal_id) = gov_setup.propose( - gov_setup.get_merkle_root_hash(), &first_user_addr, &min_fee, &sc_addr, @@ -44,41 +40,19 @@ fn gov_propose_test() { // vote too early gov_setup - .up_vote( - &second_user_addr, - &second_user_power, - &second_user_proof, - proposal_id, - ) + .up_vote(&second_user_addr, proposal_id) .assert_user_error("Proposal is not active"); gov_setup.increment_block_nonce(VOTING_PERIOD_BLOCKS); + gov_setup.up_vote(&first_user_addr, proposal_id).assert_ok(); gov_setup - .up_vote( - &first_user_addr, - &first_user_power, - &first_user_proof, - proposal_id, - ) - .assert_ok(); - gov_setup - .up_vote( - &second_user_addr, - &second_user_power, - &second_user_proof, - proposal_id, - ) + .up_vote(&second_user_addr, proposal_id) .assert_ok(); // user 2 try vote again gov_setup - .up_vote( - &second_user_addr, - &second_user_power, - &second_user_proof, - proposal_id, - ) + .up_vote(&second_user_addr, proposal_id) .assert_user_error("Already voted for this proposal"); gov_setup.increment_block_nonce(LOCKING_PERIOD_BLOCKS); @@ -97,7 +71,7 @@ fn gov_propose_test() { .b_mock .execute_query(&gov_setup.gov_wrapper, |sc| { let proposal = sc.proposals().get(1); - let action = proposal.actions.get(0).unwrap(); + let action = proposal.actions.first().unwrap(); let mut args_managed = ManagedVec::new(); args_managed.push(managed_buffer!(&1_000u64.to_be_bytes())); @@ -111,20 +85,21 @@ fn gov_propose_test() { } #[test] -fn gov_propose_total_quorum_0_test() { +fn gov_propose_total_energy_0_test() { let mut gov_setup = GovSetup::new(governance_v2::contract_obj); - let first_user_addr = gov_setup.first_user.clone(); + let no_energy_user = gov_setup.no_energy_user.clone(); let sc_addr = gov_setup.gov_wrapper.address_ref().clone(); let min_fee = rust_biguint!(MIN_FEE_FOR_PROPOSE) * DECIMALS_CONST; // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&first_user_addr, WXMEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_esdt_balance(&no_energy_user, MEX_TOKEN_ID, &min_fee); + + gov_setup.change_min_energy(0).assert_ok(); let (result, proposal_id) = gov_setup.propose( - gov_setup.get_merkle_root_hash(), - &first_user_addr, + &no_energy_user, &min_fee, &sc_addr, b"changeTODO", @@ -132,16 +107,12 @@ fn gov_propose_total_quorum_0_test() { ); result.assert_ok(); assert_eq!(proposal_id, 1); - gov_setup.increment_block_nonce(VOTING_PERIOD_BLOCKS + VOTING_DELAY_BLOCKS); gov_setup .b_mock .execute_query(&gov_setup.gov_wrapper, |sc| { - let mut proposal = sc.proposals().get(1); - proposal.total_quorum = managed_biguint!(0); - sc.proposals().set(1, &proposal); assert!( - sc.get_proposal_status(1) == GovernanceProposalStatus::Defeated, + sc.get_proposal_status(1) == GovernanceProposalStatus::Pending, "Action should have been Defeated" ); }) @@ -152,25 +123,17 @@ fn gov_propose_total_quorum_0_test() { fn gov_no_veto_vote_test() { let mut gov_setup = GovSetup::new(governance_v2::contract_obj); - let first_user_addr = gov_setup.first_merkle_user.clone(); - let first_user_power = gov_setup.get_first_user_voting_power(); - let first_user_proof = gov_setup.first_merkle_proof(); - let second_user_addr = gov_setup.second_merkle_user.clone(); - let second_user_power = gov_setup.get_second_user_voting_power(); - let second_user_proof = gov_setup.second_merkle_proof(); - let third_user_addr = gov_setup.third_merkle_user.clone(); - let third_user_power = gov_setup.get_third_user_voting_power(); - let third_user_proof = gov_setup.third_merkle_proof(); - + let first_user_addr = gov_setup.first_user.clone(); + let second_user_addr = gov_setup.second_user.clone(); + let third_user_addr = gov_setup.third_user.clone(); let sc_addr = gov_setup.gov_wrapper.address_ref().clone(); let min_fee = rust_biguint!(MIN_FEE_FOR_PROPOSE) * DECIMALS_CONST; // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&first_user_addr, WXMEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); let (result, proposal_id) = gov_setup.propose( - gov_setup.get_merkle_root_hash(), &first_user_addr, &min_fee, &sc_addr, @@ -183,40 +146,20 @@ fn gov_no_veto_vote_test() { gov_setup .b_mock .execute_query(&gov_setup.gov_wrapper, |sc| { - assert_eq!( - sc.quorum_percentage().get(), - managed_biguint!(QUORUM_PERCENTAGE) - ); + assert_eq!(sc.quorum_percentage().get(), QUORUM_PERCENTAGE); }) .assert_ok(); gov_setup.increment_block_nonce(VOTING_PERIOD_BLOCKS); + gov_setup.up_vote(&first_user_addr, proposal_id).assert_ok(); gov_setup - .down_veto_vote( - &first_user_addr, - &first_user_power, - &first_user_proof, - proposal_id, - ) - .assert_ok(); - gov_setup - .up_vote( - &second_user_addr, - &second_user_power, - &second_user_proof, - proposal_id, - ) + .up_vote(&second_user_addr, proposal_id) .assert_ok(); // Third User DownWithVetoVote = 1_100 gov_setup - .up_vote( - &third_user_addr, - &third_user_power, - &third_user_proof, - proposal_id, - ) + .down_veto_vote(&third_user_addr, proposal_id) .assert_ok(); gov_setup.increment_block_nonce(LOCKING_PERIOD_BLOCKS); @@ -236,21 +179,16 @@ fn gov_no_veto_vote_test() { fn gov_abstain_vote_test() { let mut gov_setup = GovSetup::new(governance_v2::contract_obj); - let first_user_addr = gov_setup.first_merkle_user.clone(); - let first_user_power = gov_setup.get_first_user_voting_power(); - let first_user_proof = gov_setup.first_merkle_proof(); - let third_user_addr = gov_setup.third_merkle_user.clone(); - let third_user_power = gov_setup.get_third_user_voting_power(); - let third_user_proof = gov_setup.third_merkle_proof(); + let first_user_addr = gov_setup.first_user.clone(); + let third_user_addr = gov_setup.third_user.clone(); let sc_addr = gov_setup.gov_wrapper.address_ref().clone(); let min_fee = rust_biguint!(MIN_FEE_FOR_PROPOSE) * DECIMALS_CONST; // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&first_user_addr, WXMEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); let (result, proposal_id) = gov_setup.propose( - gov_setup.get_merkle_root_hash(), &first_user_addr, &min_fee, &sc_addr, @@ -262,21 +200,9 @@ fn gov_abstain_vote_test() { gov_setup.increment_block_nonce(VOTING_PERIOD_BLOCKS); + gov_setup.up_vote(&first_user_addr, proposal_id).assert_ok(); gov_setup - .abstain_vote( - &first_user_addr, - &first_user_power, - &first_user_proof, - proposal_id, - ) - .assert_ok(); - gov_setup - .up_vote( - &third_user_addr, - &third_user_power, - &third_user_proof, - proposal_id, - ) + .abstain_vote(&third_user_addr, proposal_id) .assert_ok(); gov_setup.increment_block_nonce(LOCKING_PERIOD_BLOCKS); @@ -296,19 +222,15 @@ fn gov_abstain_vote_test() { fn gov_no_quorum_test() { let mut gov_setup = GovSetup::new(governance_v2::contract_obj); - let first_user_addr = gov_setup.first_merkle_user.clone(); - let third_user_addr = gov_setup.third_merkle_user.clone(); - let third_user_power = gov_setup.get_third_user_voting_power(); - let third_user_proof = gov_setup.third_merkle_proof(); + let first_user_addr = gov_setup.first_user.clone(); let sc_addr = gov_setup.gov_wrapper.address_ref().clone(); let min_fee = rust_biguint!(MIN_FEE_FOR_PROPOSE) * DECIMALS_CONST; // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&first_user_addr, WXMEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); let (result, proposal_id) = gov_setup.propose( - gov_setup.get_merkle_root_hash(), &first_user_addr, &min_fee, &sc_addr, @@ -320,14 +242,7 @@ fn gov_no_quorum_test() { gov_setup.increment_block_nonce(VOTING_PERIOD_BLOCKS); - gov_setup - .up_vote( - &third_user_addr, - &third_user_power, - &third_user_proof, - proposal_id, - ) - .assert_ok(); + gov_setup.up_vote(&first_user_addr, proposal_id).assert_ok(); gov_setup.increment_block_nonce(LOCKING_PERIOD_BLOCKS); @@ -346,19 +261,15 @@ fn gov_no_quorum_test() { fn gov_modify_quorum_after_end_vote_test() { let mut gov_setup = GovSetup::new(governance_v2::contract_obj); - let first_user_addr = gov_setup.first_merkle_user.clone(); - let third_user_addr = gov_setup.third_merkle_user.clone(); - let third_user_power = gov_setup.get_third_user_voting_power(); - let third_user_proof = gov_setup.third_merkle_proof(); + let first_user_addr = gov_setup.first_user.clone(); let sc_addr = gov_setup.gov_wrapper.address_ref().clone(); let min_fee = rust_biguint!(MIN_FEE_FOR_PROPOSE) * DECIMALS_CONST; // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&first_user_addr, WXMEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); let (result, proposal_id) = gov_setup.propose( - gov_setup.get_merkle_root_hash(), &first_user_addr, &min_fee, &sc_addr, @@ -368,18 +279,11 @@ fn gov_modify_quorum_after_end_vote_test() { result.assert_ok(); assert_eq!(proposal_id, 1); - gov_setup.increment_block_nonce(VOTING_DELAY_BLOCKS); + gov_setup.increment_block_nonce(VOTING_PERIOD_BLOCKS); - gov_setup - .up_vote( - &third_user_addr, - &third_user_power, - &third_user_proof, - proposal_id, - ) - .assert_ok(); + gov_setup.up_vote(&first_user_addr, proposal_id).assert_ok(); - gov_setup.increment_block_nonce(VOTING_PERIOD_BLOCKS); + gov_setup.increment_block_nonce(LOCKING_PERIOD_BLOCKS); gov_setup .b_mock @@ -388,8 +292,8 @@ fn gov_modify_quorum_after_end_vote_test() { sc.get_proposal_status(1) == GovernanceProposalStatus::Defeated, "Action should have been Defeated" ); - sc.try_change_quorum_percentage(managed_biguint!(QUORUM_PERCENTAGE / 2)); - assert!(sc.quorum_percentage().get() == managed_biguint!(QUORUM_PERCENTAGE / 2)); + sc.try_change_quorum_percentage(QUORUM_PERCENTAGE / 2); + assert!(sc.quorum_percentage().get() == QUORUM_PERCENTAGE / 2); assert!( sc.get_proposal_status(1) == GovernanceProposalStatus::Defeated, @@ -403,21 +307,16 @@ fn gov_modify_quorum_after_end_vote_test() { fn gov_withdraw_defeated_proposal_test() { let mut gov_setup = GovSetup::new(governance_v2::contract_obj); - let first_user_addr = gov_setup.first_merkle_user.clone(); - let first_user_power = gov_setup.get_first_user_voting_power(); - let first_user_proof = gov_setup.first_merkle_proof(); - let third_user_addr = gov_setup.third_merkle_user.clone(); - let third_user_power = gov_setup.get_third_user_voting_power(); - let third_user_proof = gov_setup.third_merkle_proof(); + let first_user_addr = gov_setup.first_user.clone(); + let third_user_addr = gov_setup.third_user.clone(); let sc_addr = gov_setup.gov_wrapper.address_ref().clone(); let min_fee = rust_biguint!(MIN_FEE_FOR_PROPOSE) * DECIMALS_CONST; // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&first_user_addr, WXMEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); let (result, proposal_id) = gov_setup.propose( - gov_setup.get_merkle_root_hash(), &first_user_addr, &min_fee, &sc_addr, @@ -427,35 +326,18 @@ fn gov_withdraw_defeated_proposal_test() { result.assert_ok(); assert_eq!(proposal_id, 1); - // Check proposer balance - gov_setup.b_mock.check_nft_balance::( - &first_user_addr, - WXMEX_TOKEN_ID, - 1, - &rust_biguint!(0), - None, - ); + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &rust_biguint!(0)); - gov_setup.increment_block_nonce(VOTING_DELAY_BLOCKS); + gov_setup.increment_block_nonce(VOTING_PERIOD_BLOCKS); + gov_setup.up_vote(&first_user_addr, proposal_id).assert_ok(); gov_setup - .down_vote( - &first_user_addr, - &first_user_power, - &first_user_proof, - proposal_id, - ) - .assert_ok(); - gov_setup - .up_vote( - &third_user_addr, - &third_user_power, - &third_user_proof, - proposal_id, - ) + .down_vote(&third_user_addr, proposal_id) .assert_ok(); - gov_setup.increment_block_nonce(VOTING_PERIOD_BLOCKS); + gov_setup.increment_block_nonce(LOCKING_PERIOD_BLOCKS); gov_setup .b_mock @@ -477,35 +359,25 @@ fn gov_withdraw_defeated_proposal_test() { .withdraw_after_defeated(&first_user_addr, proposal_id) .assert_ok(); - // Check proposer balance (fee) - gov_setup.b_mock.check_nft_balance::( - &first_user_addr, - WXMEX_TOKEN_ID, - 1, - &min_fee, - None, - ); + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); } #[test] fn gov_modify_withdraw_defeated_proposal_test() { let mut gov_setup = GovSetup::new(governance_v2::contract_obj); - let first_user_addr = gov_setup.first_merkle_user.clone(); - let first_user_power = gov_setup.get_first_user_voting_power(); - let first_user_proof = gov_setup.first_merkle_proof(); - let third_user_addr = gov_setup.third_merkle_user.clone(); - let third_user_power = gov_setup.get_third_user_voting_power(); - let third_user_proof = gov_setup.third_merkle_proof(); + let first_user_addr = gov_setup.first_user.clone(); + let third_user_addr = gov_setup.third_user.clone(); let sc_addr = gov_setup.gov_wrapper.address_ref().clone(); let min_fee = rust_biguint!(MIN_FEE_FOR_PROPOSE) * DECIMALS_CONST; // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&first_user_addr, WXMEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); let (result, proposal_id) = gov_setup.propose( - gov_setup.get_merkle_root_hash(), &first_user_addr, &min_fee, &sc_addr, @@ -516,35 +388,23 @@ fn gov_modify_withdraw_defeated_proposal_test() { assert_eq!(proposal_id, 1); // Check proposer balance - gov_setup.b_mock.check_nft_balance::( - &first_user_addr, - WXMEX_TOKEN_ID, - 1, - &rust_biguint!(0), - None, - ); + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &rust_biguint!(0)); gov_setup.increment_block_nonce(VOTING_PERIOD_BLOCKS); + gov_setup.up_vote(&first_user_addr, proposal_id).assert_ok(); gov_setup - .down_vote( - &first_user_addr, - &first_user_power, - &first_user_proof, - proposal_id, - ) - .assert_ok(); - gov_setup - .up_vote( - &third_user_addr, - &third_user_power, - &third_user_proof, - proposal_id, - ) + .down_vote(&third_user_addr, proposal_id) .assert_ok(); gov_setup.increment_block_nonce(LOCKING_PERIOD_BLOCKS); + gov_setup + .change_withdraw_percentage(FULL_PERCENTAGE + 1u64) + .assert_error(4, "Not valid value for withdraw percentage if defeated!"); + gov_setup .b_mock .execute_query(&gov_setup.gov_wrapper, |sc| { @@ -570,34 +430,25 @@ fn gov_modify_withdraw_defeated_proposal_test() { .assert_ok(); // Check proposer balance (fee) - gov_setup.b_mock.check_nft_balance::( - &first_user_addr, - WXMEX_TOKEN_ID, - 1, - &min_fee, - None, - ); + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); } #[test] fn gov_withdraw_no_with_veto_defeated_proposal_test() { let mut gov_setup = GovSetup::new(governance_v2::contract_obj); - let first_user_addr = gov_setup.first_merkle_user.clone(); - let first_user_power = gov_setup.get_first_user_voting_power(); - let first_user_proof = gov_setup.first_merkle_proof(); - let third_user_addr = gov_setup.third_merkle_user.clone(); - let third_user_power = gov_setup.get_third_user_voting_power(); - let third_user_proof = gov_setup.third_merkle_proof(); + let first_user_addr = gov_setup.first_user.clone(); + let third_user_addr = gov_setup.third_user.clone(); let sc_addr = gov_setup.gov_wrapper.address_ref().clone(); let min_fee = rust_biguint!(MIN_FEE_FOR_PROPOSE) * DECIMALS_CONST; // Give proposer the minimum fee gov_setup .b_mock - .set_nft_balance(&first_user_addr, WXMEX_TOKEN_ID, 1, &min_fee, &Empty); + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); let (result, proposal_id) = gov_setup.propose( - gov_setup.get_merkle_root_hash(), &first_user_addr, &min_fee, &sc_addr, @@ -608,31 +459,15 @@ fn gov_withdraw_no_with_veto_defeated_proposal_test() { assert_eq!(proposal_id, 1); // Check proposer balance - gov_setup.b_mock.check_nft_balance::( - &first_user_addr, - WXMEX_TOKEN_ID, - 1, - &rust_biguint!(0), - None, - ); + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &rust_biguint!(0)); gov_setup.increment_block_nonce(VOTING_PERIOD_BLOCKS); + gov_setup.up_vote(&first_user_addr, proposal_id).assert_ok(); gov_setup - .down_veto_vote( - &first_user_addr, - &first_user_power, - &first_user_proof, - proposal_id, - ) - .assert_ok(); - gov_setup - .up_vote( - &third_user_addr, - &third_user_power, - &third_user_proof, - proposal_id, - ) + .down_veto_vote(&third_user_addr, proposal_id) .assert_ok(); gov_setup.increment_block_nonce(LOCKING_PERIOD_BLOCKS); @@ -647,44 +482,144 @@ fn gov_withdraw_no_with_veto_defeated_proposal_test() { }) .assert_ok(); - // Other user (not proposer) try to withdraw the fee -> Fail + // Other user (not proposer) withdraw the fee gov_setup .withdraw_after_defeated(&third_user_addr, proposal_id) - .assert_error(4, "Only original proposer may withdraw a pending proposal"); + .assert_ok(); - // Proposer withdraw + // Check proposer balance (fee) gov_setup - .withdraw_after_defeated(&first_user_addr, proposal_id) + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &(&min_fee / 2u64)); + + // Withdraw the fee twice - error + gov_setup + .withdraw_after_defeated(&third_user_addr, proposal_id) + .assert_error(4, "Fee already withdrawn!"); +} + +#[test] +fn gov_withdraw_no_with_veto_penalty_limits_test() { + let mut gov_setup = GovSetup::new(governance_v2::contract_obj); + + let first_user_addr = gov_setup.first_user.clone(); + let third_user_addr = gov_setup.third_user.clone(); + let sc_addr = gov_setup.gov_wrapper.address_ref().clone(); + let min_fee = rust_biguint!(MIN_FEE_FOR_PROPOSE) * DECIMALS_CONST; + // Give proposer the minimum fee + gov_setup + .b_mock + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); + + gov_setup.change_withdraw_percentage(0).assert_ok(); + let (result, proposal_id) = gov_setup.propose( + &first_user_addr, + &min_fee, + &sc_addr, + b"changeTODO", + vec![1_000u64.to_be_bytes().to_vec()], + ); + result.assert_ok(); + assert_eq!(proposal_id, 1); + + // Check proposer balance + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &rust_biguint!(0)); + + gov_setup.increment_block_nonce(VOTING_PERIOD_BLOCKS); + + gov_setup.up_vote(&first_user_addr, proposal_id).assert_ok(); + gov_setup + .down_veto_vote(&third_user_addr, proposal_id) + .assert_ok(); + + gov_setup.increment_block_nonce(LOCKING_PERIOD_BLOCKS); + + gov_setup + .b_mock + .execute_query(&gov_setup.gov_wrapper, |sc| { + assert!( + sc.get_proposal_status(1) == GovernanceProposalStatus::DefeatedWithVeto, + "Action should have been Defeated" + ); + }) + .assert_ok(); + + // Other user (not proposer) withdraw the fee + gov_setup + .withdraw_after_defeated(&third_user_addr, proposal_id) .assert_ok(); // Check proposer balance (fee) - gov_setup.b_mock.check_nft_balance::( + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &rust_biguint!(0)); + + // Give proposer the minimum fee + gov_setup + .b_mock + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); + + gov_setup.change_withdraw_percentage(10_000).assert_ok(); + let (result, proposal_id) = gov_setup.propose( &first_user_addr, - WXMEX_TOKEN_ID, - 1, - &(min_fee / 2u64), - None, + &min_fee, + &sc_addr, + b"changeTODO", + vec![1_000u64.to_be_bytes().to_vec()], ); + result.assert_ok(); + assert_eq!(proposal_id, 2); + + // Check proposer balance + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &rust_biguint!(0)); + + gov_setup.increment_block_nonce(VOTING_PERIOD_BLOCKS); + + gov_setup.up_vote(&first_user_addr, proposal_id).assert_ok(); + gov_setup + .down_veto_vote(&third_user_addr, proposal_id) + .assert_ok(); + + gov_setup.increment_block_nonce(LOCKING_PERIOD_BLOCKS); + + gov_setup + .b_mock + .execute_query(&gov_setup.gov_wrapper, |sc| { + assert!( + sc.get_proposal_status(1) == GovernanceProposalStatus::DefeatedWithVeto, + "Action should have been Defeated" + ); + }) + .assert_ok(); + + // Other user (not proposer) withdraw the fee + gov_setup + .withdraw_after_defeated(&third_user_addr, proposal_id) + .assert_ok(); + + // Check proposer balance (fee) + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); } #[test] fn gov_propose_cancel_proposal_id_test() { let mut gov_setup = GovSetup::new(governance_v2::contract_obj); - let first_user_addr = gov_setup.first_merkle_user.clone(); + let first_user_addr = gov_setup.first_user.clone(); let sc_addr = gov_setup.gov_wrapper.address_ref().clone(); let min_fee = rust_biguint!(MIN_FEE_FOR_PROPOSE) * DECIMALS_CONST; // Give proposer the minimum fee - gov_setup.b_mock.set_nft_balance( - &first_user_addr, - WXMEX_TOKEN_ID, - 1, - &(min_fee.clone() * 3u64), - &Empty, - ); + gov_setup + .b_mock + .set_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &(&min_fee * 3u64)); let (result, proposal_id) = gov_setup.propose( - gov_setup.get_merkle_root_hash(), &first_user_addr, &min_fee, &sc_addr, @@ -699,7 +634,6 @@ fn gov_propose_cancel_proposal_id_test() { // Proposal ID = 2 let (result, proposal_id) = gov_setup.propose( - gov_setup.get_merkle_root_hash(), &first_user_addr, &min_fee, &sc_addr, @@ -714,7 +648,6 @@ fn gov_propose_cancel_proposal_id_test() { // Proposal ID = 3 let (result, proposal_id) = gov_setup.propose( - gov_setup.get_merkle_root_hash(), &first_user_addr, &min_fee, &sc_addr, @@ -728,28 +661,36 @@ fn gov_propose_cancel_proposal_id_test() { .assert_ok(); // Check proposer balance (fee = 0) - gov_setup.b_mock.check_nft_balance::( - &first_user_addr, - WXMEX_TOKEN_ID, - 1, - &rust_biguint!(0), - None, - ); + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &rust_biguint!(0)); gov_setup.cancel_proposal(&first_user_addr, 2).assert_ok(); + // Try to retrieve the cancelled proposal + gov_setup + .b_mock + .execute_tx( + &gov_setup.first_user.clone(), + &gov_setup.gov_wrapper, + &rust_biguint!(0), + |sc| { + sc.proposals().get(2); + }, + ) + .assert_ok(); + // Check proposer balance (fee should be refunded) - gov_setup.b_mock.check_nft_balance::( - &first_user_addr, - WXMEX_TOKEN_ID, - 1, - &min_fee, - None, - ); + gov_setup + .b_mock + .check_esdt_balance(&first_user_addr, MEX_TOKEN_ID, &min_fee); + assert_eq!(proposal_id, 3); + gov_setup + .check_proposal_id_consistency(&first_user_addr, proposal_id) + .assert_ok(); // Proposal ID = 4 let (result, proposal_id) = gov_setup.propose( - gov_setup.get_merkle_root_hash(), &first_user_addr, &min_fee, &sc_addr, @@ -764,9 +705,21 @@ fn gov_propose_cancel_proposal_id_test() { gov_setup.cancel_proposal(&first_user_addr, 4).assert_ok(); + // Try to retrieve the cancelled proposal + gov_setup + .b_mock + .execute_tx( + &gov_setup.first_user.clone(), + &gov_setup.gov_wrapper, + &rust_biguint!(0), + |sc| { + sc.proposals().get(4); + }, + ) + .assert_ok(); + // Proposal ID = 5 let (result, proposal_id) = gov_setup.propose( - gov_setup.get_merkle_root_hash(), &first_user_addr, &min_fee, &sc_addr, diff --git a/energy-integration/governance-v2/tests/gov_test_setup/mod.rs b/energy-integration/governance-v2/tests/gov_test_setup/mod.rs index cc2edc2dd..489fec3b3 100644 --- a/energy-integration/governance-v2/tests/gov_test_setup/mod.rs +++ b/energy-integration/governance-v2/tests/gov_test_setup/mod.rs @@ -1,32 +1,38 @@ +#![allow(deprecated)] + +use energy_factory_mock::EnergyFactoryMock; +use energy_query::Energy; +use fees_collector::FeesCollector; use governance_v2::{ + configurable::ConfigurablePropertiesModule, proposal_storage::{ProposalStorageModule, VoteType}, GovernanceV2, }; use multiversx_sc::{ - arrayvec::ArrayVec, - hex_literal::hex, - types::{Address, ManagedByteArray, ManagedVec, MultiValueEncoded}, + codec::multi_types::OptionalValue, + types::{Address, BigInt, EsdtLocalRole, ManagedVec, MultiValueEncoded}, }; use multiversx_sc_scenario::{ managed_address, managed_biguint, managed_buffer, managed_token_id, rust_biguint, - whitebox::TxResult, - whitebox::{BlockchainStateWrapper, ContractObjWrapper}, + whitebox_legacy::TxResult, + whitebox_legacy::{BlockchainStateWrapper, ContractObjWrapper}, DebugApi, }; use num_bigint::BigUint; -pub const MIN_FEE_FOR_PROPOSE: u64 = 3_000_000; -pub const QUORUM_PERCENTAGE: u64 = 5000; -pub const VOTING_DELAY_BLOCKS: u64 = 10; -pub const VOTING_PERIOD_BLOCKS: u64 = 14_500; +pub const MIN_ENERGY_FOR_PROPOSE: u64 = 0; +pub const MIN_FEE_FOR_PROPOSE: u64 = 1_000_000_000; // 1B MEX +pub const QUORUM_PERCENTAGE: u64 = 4_000; // 40% +pub const VOTING_DELAY_BLOCKS: u64 = 1; +pub const VOTING_PERIOD_BLOCKS: u64 = 144_000; // 10 days pub const LOCKING_PERIOD_BLOCKS: u64 = 30; pub const WITHDRAW_PERCENTAGE: u64 = 5_000; // 50% -pub const WXMEX_TOKEN_ID: &[u8] = b"WXMEX-123456"; +pub const MEX_TOKEN_ID: &[u8] = b"MEX-123456"; +pub const XMEX_TOKEN_ID: &[u8] = b"XMEX-123456"; pub const DECIMALS_CONST: u64 = 1_000_000_000_000_000_000; -pub const GAS_LIMIT: u64 = 1_000_000u64; -pub const FIRST_USER_QUORUM: u64 = 217_433_990_694u64; -pub const SECOND_USER_QUORUM: u64 = 59_024_824_840u64; -pub const THIRD_USER_QUORUM: u64 = 40_000_000_000u64; +pub const FULL_PERCENTAGE: u64 = 10_000; +pub const USER_ENERGY: u64 = 1_000_000; +pub const GAS_LIMIT: u64 = 1_000_000; #[derive(Clone)] pub struct Payment { @@ -44,9 +50,7 @@ where pub first_user: Address, pub second_user: Address, pub third_user: Address, - pub first_merkle_user: Address, - pub second_merkle_user: Address, - pub third_merkle_user: Address, + pub no_energy_user: Address, pub gov_wrapper: ContractObjWrapper, GovBuilder>, pub current_block: u64, } @@ -56,51 +60,138 @@ where GovBuilder: 'static + Copy + Fn() -> governance_v2::ContractObj, { pub fn new(gov_builder: GovBuilder) -> Self { - let _ = DebugApi::dummy(); let rust_zero = rust_biguint!(0); let mut b_mock = BlockchainStateWrapper::new(); let owner = b_mock.create_user_account(&rust_zero); let first_user = b_mock.create_user_account(&rust_zero); let second_user = b_mock.create_user_account(&rust_zero); let third_user = b_mock.create_user_account(&rust_zero); - let first_merkle_user = Address::from(&hex!( - "25ee243280fc6e740424a28fa40c795458943b475cd77f3778f9c8e0b4a1e7f8" - )); - let second_merkle_user = Address::from(&hex!( - "0d5acc0ee5a229ae549dad903fb7bcbc1f80b67198949f02fd611d25d41689cb" - )); - let third_merkle_user = Address::from(&hex!( - "190c55b8f27547244c65ad13cbbe7457d5fb90481f34b84160a1cf6e44e0875c" - )); - b_mock.create_user_account_fixed_address(&first_merkle_user, &rust_zero); + let no_energy_user = b_mock.create_user_account(&rust_zero); + + // init energy factory + let energy_factory_wrapper = b_mock.create_sc_account( + &rust_zero, + Some(&owner), + energy_factory_mock::contract_obj, + "energy factory path", + ); + + // init fees collector + let fees_collector_wrapper = b_mock.create_sc_account( + &rust_biguint!(0), + None, + fees_collector::contract_obj, + "fees collector path", + ); + + b_mock + .execute_tx(&owner, &energy_factory_wrapper, &rust_zero, |sc| { + sc.init(); + sc.user_energy(&managed_address!(&first_user)) + .set(&Energy::new( + BigInt::from(managed_biguint!(USER_ENERGY)), + 0, + managed_biguint!(0), + )); + sc.user_energy(&managed_address!(&second_user)) + .set(&Energy::new( + BigInt::from(managed_biguint!(USER_ENERGY)), + 0, + managed_biguint!(0), + )); + sc.user_energy(&managed_address!(&third_user)) + .set(&Energy::new( + BigInt::from(managed_biguint!(USER_ENERGY + 210_000)), + 0, + managed_biguint!(0), + )); + sc.user_energy(&managed_address!(&no_energy_user)) + .set(&Energy::new( + BigInt::from(managed_biguint!(0)), + 0, + managed_biguint!(0), + )); + }) + .assert_ok(); + + b_mock + .execute_tx(&owner, &fees_collector_wrapper, &rust_biguint!(0), |sc| { + sc.init( + managed_token_id!(XMEX_TOKEN_ID), + managed_address!(energy_factory_wrapper.address_ref()), + ); + }) + .assert_ok(); + + b_mock + .execute_tx( + &first_user, + &fees_collector_wrapper, + &rust_biguint!(0), + |sc| { + sc.claim_rewards_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + b_mock + .execute_tx( + &second_user, + &fees_collector_wrapper, + &rust_biguint!(0), + |sc| { + sc.claim_rewards_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + b_mock + .execute_tx( + &third_user, + &fees_collector_wrapper, + &rust_biguint!(0), + |sc| { + sc.claim_rewards_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); // init governance sc let gov_wrapper = b_mock.create_sc_account(&rust_zero, Some(&owner), gov_builder, "gov path"); - // let min_fee = managed_biguint!(MIN_FEE_FOR_PROPOSE )* managed_biguint!(DECIMALS_CONST); b_mock .execute_tx(&owner, &gov_wrapper, &rust_zero, |sc| { sc.init( + managed_biguint!(MIN_ENERGY_FOR_PROPOSE), managed_biguint!(MIN_FEE_FOR_PROPOSE) * DECIMALS_CONST, - managed_biguint!(QUORUM_PERCENTAGE), + QUORUM_PERCENTAGE, VOTING_DELAY_BLOCKS, VOTING_PERIOD_BLOCKS, WITHDRAW_PERCENTAGE, - managed_token_id!(WXMEX_TOKEN_ID), + managed_address!(energy_factory_wrapper.address_ref()), + managed_address!(fees_collector_wrapper.address_ref()), + managed_token_id!(MEX_TOKEN_ID), ); }) .assert_ok(); + b_mock + .execute_tx(&owner, &gov_wrapper, &rust_zero, |sc| { + sc.fee_token_id().set(managed_token_id!(MEX_TOKEN_ID)); + }) + .assert_ok(); + + let vote_nft_roles = [EsdtLocalRole::Mint, EsdtLocalRole::Burn]; + b_mock.set_esdt_local_roles(gov_wrapper.address_ref(), MEX_TOKEN_ID, &vote_nft_roles[..]); + Self { b_mock, owner, first_user, second_user, third_user, - first_merkle_user, - second_merkle_user, - third_merkle_user, + no_energy_user, gov_wrapper, current_block: 0, } @@ -108,7 +199,6 @@ where pub fn propose( &mut self, - root_hash: ManagedByteArray, proposer: &Address, fee_amount: &BigUint, dest_address: &Address, @@ -119,8 +209,8 @@ where let result = self.b_mock.execute_esdt_transfer( proposer, &self.gov_wrapper, - WXMEX_TOKEN_ID, - 1u64, + MEX_TOKEN_ID, + 0, fee_amount, |sc| { let mut args_managed = ManagedVec::new(); @@ -138,80 +228,39 @@ where ) .into(), ); - let total_quorum = managed_biguint!(FIRST_USER_QUORUM) - + managed_biguint!(SECOND_USER_QUORUM) - + managed_biguint!(THIRD_USER_QUORUM); - proposal_id = sc.propose( - root_hash, - total_quorum, - managed_buffer!(b"changeTODO"), - actions, - ); + + proposal_id = sc.propose(managed_buffer!(b"changeTODO"), actions); }, ); (result, proposal_id) } - pub fn up_vote( - &mut self, - voter: &Address, - power: &BigUint, - proof: &ArrayVec, 18>, - proposal_id: usize, - ) -> TxResult { + pub fn up_vote(&mut self, voter: &Address, proposal_id: usize) -> TxResult { self.b_mock .execute_tx(voter, &self.gov_wrapper, &rust_biguint!(0), |sc| { - sc.vote(proposal_id, VoteType::UpVote, power.into(), proof.clone()); + sc.vote(proposal_id, VoteType::UpVote); }) } - pub fn down_vote( - &mut self, - voter: &Address, - power: &BigUint, - proof: &ArrayVec, 18>, - proposal_id: usize, - ) -> TxResult { + pub fn down_vote(&mut self, voter: &Address, proposal_id: usize) -> TxResult { self.b_mock .execute_tx(voter, &self.gov_wrapper, &rust_biguint!(0), |sc| { - sc.vote(proposal_id, VoteType::DownVote, power.into(), proof.clone()); + sc.vote(proposal_id, VoteType::DownVote); }) } - pub fn down_veto_vote( - &mut self, - voter: &Address, - power: &BigUint, - proof: &ArrayVec, 18>, - proposal_id: usize, - ) -> TxResult { + pub fn down_veto_vote(&mut self, voter: &Address, proposal_id: usize) -> TxResult { self.b_mock .execute_tx(voter, &self.gov_wrapper, &rust_biguint!(0), |sc| { - sc.vote( - proposal_id, - VoteType::DownVetoVote, - power.into(), - proof.clone(), - ); + sc.vote(proposal_id, VoteType::DownVetoVote); }) } - pub fn abstain_vote( - &mut self, - voter: &Address, - power: &BigUint, - proof: &ArrayVec, 18>, - proposal_id: usize, - ) -> TxResult { + pub fn abstain_vote(&mut self, voter: &Address, proposal_id: usize) -> TxResult { self.b_mock .execute_tx(voter, &self.gov_wrapper, &rust_biguint!(0), |sc| { - sc.vote( - proposal_id, - VoteType::AbstainVote, - power.into(), - proof.clone(), - ); + sc.vote(proposal_id, VoteType::AbstainVote); }) } @@ -222,6 +271,21 @@ where }) } + pub fn change_withdraw_percentage(&mut self, withdraw_value: u64) -> TxResult { + self.b_mock + .execute_tx(&self.owner, &self.gov_wrapper, &rust_biguint!(0), |sc| { + sc.change_withdraw_percentage(withdraw_value); + }) + } + + pub fn change_min_energy(&mut self, min_energy_for_propose: usize) -> TxResult { + self.b_mock + .execute_tx(&self.owner, &self.gov_wrapper, &rust_biguint!(0), |sc| { + sc.min_energy_for_propose() + .set(&managed_biguint!(min_energy_for_propose)); + }) + } + pub fn cancel_proposal(&mut self, caller: &Address, proposal_id: usize) -> TxResult { self.b_mock .execute_tx(caller, &self.gov_wrapper, &rust_biguint!(0), |sc| { @@ -247,198 +311,4 @@ where self.current_block += inc_amount; self.b_mock.set_block_nonce(self.current_block); } - pub fn first_merkle_proof(&self) -> ArrayVec, 18> { - ArrayVec::from([ - ManagedByteArray::from(&hex!( - "5e9e904152b2a06dafc26aa02b8c55b2ec3370cdf55b06b15fe8c94bc56e43fc" - )), - ManagedByteArray::from(&hex!( - "47aa547fa524519bc946d0883591e9d273a65b4a8f06a37baf170c707c4fb782" - )), - ManagedByteArray::from(&hex!( - "da05a587448779b9368680f0ee745b3ff2df1132e309a2de518aa9814cc25de8" - )), - ManagedByteArray::from(&hex!( - "14ae69620e727d8e899119ef7a1f04191f15f7c704c2673445510a1bbce7edb2" - )), - ManagedByteArray::from(&hex!( - "449e8beb9a901efc2815253a2ce416e3b98ff771fdfc9e35f4ce31004003e533" - )), - ManagedByteArray::from(&hex!( - "fdf33783f8de396173fd37b558213117bb2be3430d50b18eeb5da1af0b98fd66" - )), - ManagedByteArray::from(&hex!( - "889a7d403faae66ec51db6b0708d889ca277e2fd64f78e47612c07077df6eccc" - )), - ManagedByteArray::from(&hex!( - "5cc55493d05c9bf63431384f184e0cc6ab13c14509c3e9a64dc49b47e3821c6f" - )), - ManagedByteArray::from(&hex!( - "ca559e91dee09fccf8d3dbf9bda81f57d4094faecf2f9ac3a98e84b3f376c81c" - )), - ManagedByteArray::from(&hex!( - "781cf1316f87a336a7219095aa8b523a821d260ca0b7a7f94af5c769e17c8f82" - )), - ManagedByteArray::from(&hex!( - "5e97339ee010d2ae3ac54c38c7158e7a7ef4311f89b28b4634d0d35fd4097dc0" - )), - ManagedByteArray::from(&hex!( - "2c7b2103c3e48386a7eda174cec726c28ec6ce80466deaac49dbaf469f35d059" - )), - ManagedByteArray::from(&hex!( - "9b2ceb7809f078724efb71ea3542885c990985d41746d4cab7948928384c3a4c" - )), - ManagedByteArray::from(&hex!( - "b1f37e46c3f84a3c68804d62b26b7f035c90f344252d77fdeff2393793ae34d4" - )), - ManagedByteArray::from(&hex!( - "95ead464db14a9a65c3b9c5378cf927b76ff530ae0762dbb6456bfeb467f97b2" - )), - ManagedByteArray::from(&hex!( - "39e10ed734ddaa3098edc6300edeed2fce75780fc718140359b13c58045a1838" - )), - ManagedByteArray::from(&hex!( - "b36fbf7a645b24bab3eaca5c351985f6bbb95723b47db78171dd7d7f8883ecad" - )), - ManagedByteArray::from(&hex!( - "bffe20aa722c488465e18d10ac3abe3002603bbd4c535211d9bd9b34ce7259a1" - )), - ]) - } - - pub fn second_merkle_proof(&self) -> ArrayVec, 18> { - ArrayVec::from([ - ManagedByteArray::from(&hex!( - "b1d7a256ae6b35cce14497b3735d71dd205f099f1a035a7a5cb96e8bf5c32f31" - )), - ManagedByteArray::from(&hex!( - "81dc00d137001723d5654e3120d63601b08ca2b4b8dc41802476529e6d6ada9e" - )), - ManagedByteArray::from(&hex!( - "985e3554adfefea5d2c3f7c93d404fd547cfead9054ce313845656507037df40" - )), - ManagedByteArray::from(&hex!( - "14ae69620e727d8e899119ef7a1f04191f15f7c704c2673445510a1bbce7edb2" - )), - ManagedByteArray::from(&hex!( - "449e8beb9a901efc2815253a2ce416e3b98ff771fdfc9e35f4ce31004003e533" - )), - ManagedByteArray::from(&hex!( - "fdf33783f8de396173fd37b558213117bb2be3430d50b18eeb5da1af0b98fd66" - )), - ManagedByteArray::from(&hex!( - "889a7d403faae66ec51db6b0708d889ca277e2fd64f78e47612c07077df6eccc" - )), - ManagedByteArray::from(&hex!( - "5cc55493d05c9bf63431384f184e0cc6ab13c14509c3e9a64dc49b47e3821c6f" - )), - ManagedByteArray::from(&hex!( - "ca559e91dee09fccf8d3dbf9bda81f57d4094faecf2f9ac3a98e84b3f376c81c" - )), - ManagedByteArray::from(&hex!( - "781cf1316f87a336a7219095aa8b523a821d260ca0b7a7f94af5c769e17c8f82" - )), - ManagedByteArray::from(&hex!( - "5e97339ee010d2ae3ac54c38c7158e7a7ef4311f89b28b4634d0d35fd4097dc0" - )), - ManagedByteArray::from(&hex!( - "2c7b2103c3e48386a7eda174cec726c28ec6ce80466deaac49dbaf469f35d059" - )), - ManagedByteArray::from(&hex!( - "9b2ceb7809f078724efb71ea3542885c990985d41746d4cab7948928384c3a4c" - )), - ManagedByteArray::from(&hex!( - "b1f37e46c3f84a3c68804d62b26b7f035c90f344252d77fdeff2393793ae34d4" - )), - ManagedByteArray::from(&hex!( - "95ead464db14a9a65c3b9c5378cf927b76ff530ae0762dbb6456bfeb467f97b2" - )), - ManagedByteArray::from(&hex!( - "39e10ed734ddaa3098edc6300edeed2fce75780fc718140359b13c58045a1838" - )), - ManagedByteArray::from(&hex!( - "b36fbf7a645b24bab3eaca5c351985f6bbb95723b47db78171dd7d7f8883ecad" - )), - ManagedByteArray::from(&hex!( - "bffe20aa722c488465e18d10ac3abe3002603bbd4c535211d9bd9b34ce7259a1" - )), - ]) - } - - pub fn third_merkle_proof(&self) -> ArrayVec, 18> { - ArrayVec::from([ - ManagedByteArray::from(&hex!( - "aa68ae7eac4de3cc643717d33ab7d2e1b098788b127f298f23a34e8720ec609d" - )), - ManagedByteArray::from(&hex!( - "e3db2cf9f85b49279eba44b0f62ac2c6bcdf870f198b9484344634a58860ba2d" - )), - ManagedByteArray::from(&hex!( - "64468b8481d2c1737977e7382eaaa12c8072ee76fda33c3b6aaa193b38d4f1f2" - )), - ManagedByteArray::from(&hex!( - "6159dc0c80183e89221a36db3fedfabe38933d0db73c1156ad32d8caf0537085" - )), - ManagedByteArray::from(&hex!( - "449e8beb9a901efc2815253a2ce416e3b98ff771fdfc9e35f4ce31004003e533" - )), - ManagedByteArray::from(&hex!( - "fdf33783f8de396173fd37b558213117bb2be3430d50b18eeb5da1af0b98fd66" - )), - ManagedByteArray::from(&hex!( - "889a7d403faae66ec51db6b0708d889ca277e2fd64f78e47612c07077df6eccc" - )), - ManagedByteArray::from(&hex!( - "5cc55493d05c9bf63431384f184e0cc6ab13c14509c3e9a64dc49b47e3821c6f" - )), - ManagedByteArray::from(&hex!( - "ca559e91dee09fccf8d3dbf9bda81f57d4094faecf2f9ac3a98e84b3f376c81c" - )), - ManagedByteArray::from(&hex!( - "781cf1316f87a336a7219095aa8b523a821d260ca0b7a7f94af5c769e17c8f82" - )), - ManagedByteArray::from(&hex!( - "5e97339ee010d2ae3ac54c38c7158e7a7ef4311f89b28b4634d0d35fd4097dc0" - )), - ManagedByteArray::from(&hex!( - "2c7b2103c3e48386a7eda174cec726c28ec6ce80466deaac49dbaf469f35d059" - )), - ManagedByteArray::from(&hex!( - "9b2ceb7809f078724efb71ea3542885c990985d41746d4cab7948928384c3a4c" - )), - ManagedByteArray::from(&hex!( - "b1f37e46c3f84a3c68804d62b26b7f035c90f344252d77fdeff2393793ae34d4" - )), - ManagedByteArray::from(&hex!( - "95ead464db14a9a65c3b9c5378cf927b76ff530ae0762dbb6456bfeb467f97b2" - )), - ManagedByteArray::from(&hex!( - "39e10ed734ddaa3098edc6300edeed2fce75780fc718140359b13c58045a1838" - )), - ManagedByteArray::from(&hex!( - "b36fbf7a645b24bab3eaca5c351985f6bbb95723b47db78171dd7d7f8883ecad" - )), - ManagedByteArray::from(&hex!( - "bffe20aa722c488465e18d10ac3abe3002603bbd4c535211d9bd9b34ce7259a1" - )), - ]) - } - - pub fn get_first_user_voting_power(&self) -> BigUint { - BigUint::from(217_433_990_694u64) - } - - pub fn get_second_user_voting_power(&self) -> BigUint { - BigUint::from(59_024_824_840u64) - } - - pub fn get_third_user_voting_power(&self) -> BigUint { - BigUint::from(40_000_000_000u64) - } - - pub fn get_merkle_root_hash(&self) -> ManagedByteArray { - ManagedByteArray::from(&hex!( - "0fdb09afb35351d5becc3a79dd9bf03bae7c2366d186a6c8e8276f545d024ef5" - )) - } } diff --git a/energy-integration/governance-v2/wasm/Cargo.lock b/energy-integration/governance-v2/wasm/Cargo.lock index 7dc6f8db8..71cf78cfd 100644 --- a/energy-integration/governance-v2/wasm/Cargo.lock +++ b/energy-integration/governance-v2/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,34 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +name = "common-types" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] [[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +name = "common_errors" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "common_structs" +version = "0.0.0" +dependencies = [ + "fixed-supply-token", + "math", + "mergeable", + "multiversx-sc", + "unwrappable", +] [[package]] name = "endian-type" @@ -50,27 +52,71 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" [[package]] -name = "governance-v2" +name = "energy-factory" version = "0.0.0" dependencies = [ + "common_structs", + "legacy_token_decode_module", + "math", + "mergeable", "multiversx-sc", + "multiversx-sc-modules", + "sc_whitelist_module", + "simple-lock", + "unwrappable", + "utils", ] [[package]] -name = "governance-v2-wasm" +name = "energy-query" version = "0.0.0" dependencies = [ - "governance-v2", - "multiversx-sc-wasm-adapter", + "energy-factory", + "multiversx-sc", ] [[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +name = "fees-collector" +version = "0.0.0" +dependencies = [ + "common-types", + "common_errors", + "energy-factory", + "energy-query", + "locking_module", + "multiversx-sc", + "multiversx-sc-modules", + "sc_whitelist_module", + "simple-lock", + "utils", + "week-timekeeping", + "weekly-rewards-splitting", +] + +[[package]] +name = "fixed-supply-token" +version = "0.0.0" dependencies = [ - "ahash", + "multiversx-sc", +] + +[[package]] +name = "governance-v2" +version = "0.0.0" +dependencies = [ + "energy-query", + "fees-collector", + "multiversx-sc", + "permissions_module", + "weekly-rewards-splitting", +] + +[[package]] +name = "governance-v2-wasm" +version = "0.0.0" +dependencies = [ + "governance-v2", + "multiversx-sc-wasm-adapter", ] [[package]] @@ -81,30 +127,49 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +name = "legacy_token_decode_module" +version = "0.0.0" +dependencies = [ + "common_structs", + "multiversx-sc", + "utils", +] [[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" +name = "locking_module" +version = "0.0.0" +dependencies = [ + "energy-factory", + "multiversx-sc", + "simple-lock", +] + +[[package]] +name = "math" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "mergeable" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -113,20 +178,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -136,9 +200,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -147,14 +211,22 @@ dependencies = [ "syn", ] +[[package]] +name = "multiversx-sc-modules" +version = "0.46.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -168,33 +240,36 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] [[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" +name = "permissions_module" +version = "0.0.0" +dependencies = [ + "bitflags", + "common_errors", + "multiversx-sc", +] [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -209,17 +284,34 @@ dependencies = [ "nibble_vec", ] +[[package]] +name = "sc_whitelist_module" +version = "0.0.0" +dependencies = [ + "common_errors", + "multiversx-sc", +] + +[[package]] +name = "simple-lock" +version = "0.0.0" +dependencies = [ + "common_structs", + "multiversx-sc", + "multiversx-sc-modules", +] + [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -228,46 +320,43 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" +name = "unwrappable" +version = "0.0.0" dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", + "multiversx-sc", ] [[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +name = "utils" +version = "0.0.0" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "common_structs", + "fixed-supply-token", + "mergeable", + "multiversx-sc", ] [[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +name = "week-timekeeping" +version = "0.0.0" +dependencies = [ + "common-types", + "multiversx-sc", +] [[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +name = "weekly-rewards-splitting" +version = "0.0.0" +dependencies = [ + "common-types", + "energy-query", + "math", + "multiversx-sc", + "unwrappable", + "week-timekeeping", +] diff --git a/energy-integration/governance-v2/wasm/Cargo.toml b/energy-integration/governance-v2/wasm/Cargo.toml index 9150116ff..02189aabe 100644 --- a/energy-integration/governance-v2/wasm/Cargo.toml +++ b/energy-integration/governance-v2/wasm/Cargo.toml @@ -1,25 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "governance-v2-wasm" version = "0.0.0" edition = "2021" publish = false -authors = ["MultiversX "] [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.governance-v2] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/farm-staking/farm-staking-proxy/Cargo.toml b/farm-staking/farm-staking-proxy/Cargo.toml index 65b8c1d5f..7e986d221 100644 --- a/farm-staking/farm-staking-proxy/Cargo.toml +++ b/farm-staking/farm-staking-proxy/Cargo.toml @@ -12,15 +12,18 @@ path = "src/lib.rs" hex-literal = "0.3.1" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" [dependencies.farm] path = "../../dex/farm" +[dependencies.farm-with-locked-rewards] +path = "../../dex/farm-with-locked-rewards" + [dependencies.farm-staking] path = "../farm-staking" @@ -57,14 +60,26 @@ path = "../../common/traits/unwrappable" [dependencies.sc_whitelist_module] path = "../../common/modules/sc_whitelist_module" +[dependencies.energy-query] +path = "../../energy-integration/common-modules/energy-query" + [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" [dev-dependencies.farm_token] path = "../../common/modules/farm/farm_token" [dev-dependencies.farm-boosted-yields] path = "../../energy-integration/farm-boosted-yields" + +[dev-dependencies.energy-factory] +path = "../../locked-asset/energy-factory" + +[dev-dependencies.simple-lock] +path = "../../locked-asset/simple-lock" + +[dev-dependencies.locking_module] +path = "../../common/modules/locking_module" diff --git a/farm-staking/farm-staking-proxy/meta/Cargo.toml b/farm-staking/farm-staking-proxy/meta/Cargo.toml index c7862ed85..404e23810 100644 --- a/farm-staking/farm-staking-proxy/meta/Cargo.toml +++ b/farm-staking/farm-staking-proxy/meta/Cargo.toml @@ -6,8 +6,10 @@ publish = false authors = ["MultiversX "] [dev-dependencies] + [dependencies.farm-staking-proxy] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/farm-staking/farm-staking-proxy/src/dual_yield_token.rs b/farm-staking/farm-staking-proxy/src/dual_yield_token.rs index cb9b5fe73..56a311d85 100644 --- a/farm-staking/farm-staking-proxy/src/dual_yield_token.rs +++ b/farm-staking/farm-staking-proxy/src/dual_yield_token.rs @@ -1,84 +1,19 @@ use fixed_supply_token::FixedSupplyToken; -use multiversx_sc::codec::{NestedDecodeInput, TopDecodeInput}; multiversx_sc::imports!(); multiversx_sc::derive_imports!(); -#[derive(TypeAbi, TopEncode, PartialEq, Debug, Clone)] +#[derive(TypeAbi, TopEncode, TopDecode, Clone, PartialEq, Debug)] pub struct DualYieldTokenAttributes { pub lp_farm_token_nonce: u64, pub lp_farm_token_amount: BigUint, - pub virtual_pos_token_nonce: u64, - pub virtual_pos_token_amount: BigUint, - pub real_pos_token_amount: BigUint, -} - -impl DualYieldTokenAttributes { - pub fn new( - lp_farm_token_nonce: u64, - lp_farm_token_amount: BigUint, - virtual_pos_token_nonce: u64, - virtual_pos_token_amount: BigUint, - ) -> Self { - DualYieldTokenAttributes { - lp_farm_token_nonce, - lp_farm_token_amount, - virtual_pos_token_nonce, - virtual_pos_token_amount, - real_pos_token_amount: BigUint::zero(), - } - } - - pub fn get_total_staking_token_amount(&self) -> BigUint { - &self.virtual_pos_token_amount + &self.real_pos_token_amount - } -} - -impl TopDecode for DualYieldTokenAttributes { - fn top_decode(input: I) -> Result - where - I: TopDecodeInput, - { - let mut buffer = input.into_nested_buffer(); - Self::dep_decode(&mut buffer) - } -} - -impl NestedDecode for DualYieldTokenAttributes { - fn dep_decode(input: &mut I) -> Result { - let lp_farm_token_nonce = u64::dep_decode(input)?; - let lp_farm_token_amount = BigUint::dep_decode(input)?; - let virtual_pos_token_nonce = u64::dep_decode(input)?; - let virtual_pos_token_amount = BigUint::dep_decode(input)?; - - if input.is_depleted() { - return Result::Ok(DualYieldTokenAttributes::new( - lp_farm_token_nonce, - lp_farm_token_amount, - virtual_pos_token_nonce, - virtual_pos_token_amount, - )); - } - - let real_pos_token_amount = BigUint::dep_decode(input)?; - - if !input.is_depleted() { - return Result::Err(DecodeError::INPUT_TOO_LONG); - } - - Result::Ok(DualYieldTokenAttributes { - lp_farm_token_nonce, - lp_farm_token_amount, - virtual_pos_token_nonce, - virtual_pos_token_amount, - real_pos_token_amount, - }) - } + pub staking_farm_token_nonce: u64, + pub staking_farm_token_amount: BigUint, } impl FixedSupplyToken for DualYieldTokenAttributes { fn get_total_supply(&self) -> BigUint { - self.virtual_pos_token_amount.clone() + self.staking_farm_token_amount.clone() } fn into_part(self, payment_amount: &BigUint) -> Self { @@ -88,15 +23,13 @@ impl FixedSupplyToken for DualYieldTokenAttributes { let new_lp_farm_token_amount = self.rule_of_three_non_zero_result(payment_amount, &self.lp_farm_token_amount); - let new_virtual_pos_amount = payment_amount.clone(); - let new_real_pos_amount = self.rule_of_three(payment_amount, &self.real_pos_token_amount); + let new_staking_farm_token_amount = payment_amount.clone(); DualYieldTokenAttributes { lp_farm_token_nonce: self.lp_farm_token_nonce, lp_farm_token_amount: new_lp_farm_token_amount, - virtual_pos_token_nonce: self.virtual_pos_token_nonce, - virtual_pos_token_amount: new_virtual_pos_amount, - real_pos_token_amount: new_real_pos_amount, + staking_farm_token_nonce: self.staking_farm_token_nonce, + staking_farm_token_amount: new_staking_farm_token_amount, } } } @@ -114,7 +47,7 @@ pub trait DualYieldTokenModule: token_ticker: ManagedBuffer, num_decimals: usize, ) { - let register_cost = self.call_value().egld_value(); + let register_cost = self.call_value().egld_value().clone_value(); self.dual_yield_token().issue_and_set_all_roles( EsdtTokenType::Meta, register_cost, diff --git a/farm-staking/farm-staking-proxy/src/external_contracts_interactions.rs b/farm-staking/farm-staking-proxy/src/external_contracts_interactions.rs index 933a93cfd..f8048d66b 100644 --- a/farm-staking/farm-staking-proxy/src/external_contracts_interactions.rs +++ b/farm-staking/farm-staking-proxy/src/external_contracts_interactions.rs @@ -1,23 +1,26 @@ multiversx_sc::imports!(); use farm::{ - base_functions::ClaimRewardsResultType, EnterFarmResultType, ExitFarmWithPartialPosResultType, - ProxyTrait as _, + base_functions::{ClaimRewardsResultType, DoubleMultiPayment}, + EnterFarmResultType, ExitFarmWithPartialPosResultType, }; use farm_staking::{ claim_stake_farm_rewards::ProxyTrait as _, stake_farm::ProxyTrait as _, unstake_farm::ProxyTrait as _, }; -use pair::safe_price_view::ProxyTrait as _; +use farm_with_locked_rewards::ProxyTrait as _; +use pair::{ + pair_actions::{common_result_types::RemoveLiquidityResultType, remove_liq::ProxyTrait as _}, + safe_price_view::ProxyTrait as _, +}; use crate::result_types::*; -use pair::RemoveLiquidityResultType; pub type SafePriceResult = MultiValue2, EsdtTokenPayment>; #[multiversx_sc::module] pub trait ExternalContractsInteractionsModule: - crate::lp_farm_token::LpFarmTokenModule + utils::UtilsModule + crate::lp_farm_token::LpFarmTokenModule + utils::UtilsModule + energy_query::EnergyQueryModule { // lp farm @@ -47,40 +50,40 @@ pub trait ExternalContractsInteractionsModule: orig_caller: ManagedAddress, lp_farm_token_nonce: u64, lp_farm_token_amount: BigUint, - exit_amount: BigUint, ) -> LpFarmExitResult { let lp_farm_token_id = self.lp_farm_token_id().get(); let lp_farm_address = self.lp_farm_address().get(); let exit_farm_result: ExitFarmWithPartialPosResultType = self .lp_farm_proxy_obj(lp_farm_address) - .exit_farm_endpoint(exit_amount, orig_caller) + .exit_farm_endpoint(orig_caller) .with_esdt_transfer((lp_farm_token_id, lp_farm_token_nonce, lp_farm_token_amount)) .execute_on_dest_context(); - let (lp_tokens, lp_farm_rewards, remaining_farm_tokens) = exit_farm_result.into_tuple(); + let (lp_tokens, lp_farm_rewards) = exit_farm_result.into_tuple(); LpFarmExitResult { lp_tokens, lp_farm_rewards, - remaining_farm_tokens, } } fn merge_lp_farm_tokens( &self, orig_caller: ManagedAddress, - base_lp_token: EsdtTokenPayment, - mut additional_lp_tokens: PaymentsVec, - ) -> EsdtTokenPayment { - if additional_lp_tokens.is_empty() { - return base_lp_token; + base_lp_farm_token: EsdtTokenPayment, + mut additional_lp_farm_tokens: PaymentsVec, + ) -> DoubleMultiPayment { + if additional_lp_farm_tokens.is_empty() { + let locked_token_id = self.get_locked_token_id(); + let rewards_payment = EsdtTokenPayment::new(locked_token_id, 0, BigUint::zero()); + return (base_lp_farm_token, rewards_payment).into(); } - additional_lp_tokens.push(base_lp_token); + additional_lp_farm_tokens.push(base_lp_farm_token); let lp_farm_address = self.lp_farm_address().get(); self.lp_farm_proxy_obj(lp_farm_address) .merge_farm_tokens_endpoint(orig_caller) - .with_multi_token_transfer(additional_lp_tokens) + .with_multi_token_transfer(additional_lp_farm_tokens) .execute_on_dest_context() } @@ -138,7 +141,6 @@ pub trait ExternalContractsInteractionsModule: staking_tokens: EsdtTokenPayment, farm_token_nonce: u64, farm_token_amount: BigUint, - exit_amount: BigUint, ) -> StakingFarmExitResult { let staking_farm_token_id = self.staking_farm_token_id().get(); let mut payments = ManagedVec::from_single_item(staking_tokens); @@ -151,40 +153,14 @@ pub trait ExternalContractsInteractionsModule: let staking_farm_address = self.staking_farm_address().get(); let unstake_result: ExitFarmWithPartialPosResultType = self .staking_farm_proxy_obj(staking_farm_address) - .unstake_farm_through_proxy(exit_amount, orig_caller) + .unstake_farm_through_proxy(orig_caller) .with_multi_token_transfer(payments) .execute_on_dest_context(); - let (unbond_staking_farm_token, staking_rewards, remaining_farm_tokens) = - unstake_result.into_tuple(); + let (unbond_staking_farm_token, staking_rewards) = unstake_result.into_tuple(); StakingFarmExitResult { unbond_staking_farm_token, staking_rewards, - remaining_farm_tokens, - } - } - - fn staking_farm_unstake_user_position( - &self, - orig_caller: ManagedAddress, - farm_token_nonce: u64, - farm_token_amount: BigUint, - exit_amount: BigUint, - ) -> StakingFarmExitResult { - let staking_farm_token_id = self.staking_farm_token_id().get(); - let staking_farm_address = self.staking_farm_address().get(); - let unstake_result: ExitFarmWithPartialPosResultType = self - .staking_farm_proxy_obj(staking_farm_address) - .unstake_farm(exit_amount, orig_caller) - .with_esdt_transfer((staking_farm_token_id, farm_token_nonce, farm_token_amount)) - .execute_on_dest_context(); - let (unbond_staking_farm_token, staking_rewards, remaining_farm_tokens) = - unstake_result.into_tuple(); - - StakingFarmExitResult { - unbond_staking_farm_token, - staking_rewards, - remaining_farm_tokens, } } @@ -245,7 +221,10 @@ pub trait ExternalContractsInteractionsModule: fn staking_farm_proxy_obj(&self, sc_address: ManagedAddress) -> farm_staking::Proxy; #[proxy] - fn lp_farm_proxy_obj(&self, sc_address: ManagedAddress) -> farm::Proxy; + fn lp_farm_proxy_obj( + &self, + sc_address: ManagedAddress, + ) -> farm_with_locked_rewards::Proxy; #[proxy] fn pair_proxy_obj(&self, sc_address: ManagedAddress) -> pair::Proxy; diff --git a/farm-staking/farm-staking-proxy/src/lib.rs b/farm-staking/farm-staking-proxy/src/lib.rs index 8f97fd0a6..bd8ef7013 100644 --- a/farm-staking/farm-staking-proxy/src/lib.rs +++ b/farm-staking/farm-staking-proxy/src/lib.rs @@ -16,15 +16,16 @@ pub trait FarmStakingProxy: + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + utils::UtilsModule + token_send::TokenSendModule + + energy_query::EnergyQueryModule + sc_whitelist_module::SCWhitelistModule + proxy_actions::stake::ProxyStakeModule + proxy_actions::claim::ProxyClaimModule + proxy_actions::unstake::ProxyUnstakeModule - + proxy_actions::merge_pos::ProxyMergePosModule { #[init] fn init( &self, + energy_factory_address: ManagedAddress, lp_farm_address: ManagedAddress, staking_farm_address: ManagedAddress, pair_address: ManagedAddress, @@ -33,6 +34,7 @@ pub trait FarmStakingProxy: staking_farm_token_id: TokenIdentifier, lp_token_id: TokenIdentifier, ) { + self.require_sc_address(&energy_factory_address); self.require_sc_address(&lp_farm_address); self.require_sc_address(&staking_farm_address); self.require_sc_address(&pair_address); @@ -42,6 +44,8 @@ pub trait FarmStakingProxy: self.require_valid_token_id(&staking_farm_token_id); self.require_valid_token_id(&lp_token_id); + self.energy_factory_address() + .set_if_empty(&energy_factory_address); self.lp_farm_address().set_if_empty(&lp_farm_address); self.staking_farm_address() .set_if_empty(&staking_farm_address); @@ -53,4 +57,7 @@ pub trait FarmStakingProxy: .set_if_empty(&staking_farm_token_id); self.lp_token_id().set_if_empty(&lp_token_id); } + + #[endpoint] + fn upgrade(&self) {} } diff --git a/farm-staking/farm-staking-proxy/src/proxy_actions/claim.rs b/farm-staking/farm-staking-proxy/src/proxy_actions/claim.rs index 3f90583e2..01df77c36 100644 --- a/farm-staking/farm-staking-proxy/src/proxy_actions/claim.rs +++ b/farm-staking/farm-staking-proxy/src/proxy_actions/claim.rs @@ -16,6 +16,7 @@ pub trait ProxyClaimModule: + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + utils::UtilsModule + token_send::TokenSendModule + + energy_query::EnergyQueryModule + sc_whitelist_module::SCWhitelistModule { #[payable("*")] @@ -34,7 +35,7 @@ pub trait ProxyClaimModule: let internal_claim_result = self.claim_dual_yield( &caller, opt_orig_caller, - attributes.get_total_staking_token_amount(), + attributes.staking_farm_token_amount.clone(), attributes, ); @@ -66,8 +67,7 @@ pub trait ProxyClaimModule: attributes.lp_farm_token_nonce, &attributes.lp_farm_token_amount, ); - let lp_tokens_safe_price = self.get_lp_tokens_safe_price(lp_tokens_in_position); - let new_staking_farm_value = &lp_tokens_safe_price + &attributes.real_pos_token_amount; + let new_staking_farm_value = self.get_lp_tokens_safe_price(lp_tokens_in_position); let staking_farm_token_id = self.staking_farm_token_id().get(); let lp_farm_token_id = self.lp_farm_token_id().get(); @@ -80,7 +80,7 @@ pub trait ProxyClaimModule: let staking_farm_claim_rewards_result = self.staking_farm_claim_rewards( orig_caller, staking_farm_token_id, - attributes.virtual_pos_token_nonce, + attributes.staking_farm_token_nonce, staking_claim_amount, new_staking_farm_value, ); @@ -90,9 +90,8 @@ pub trait ProxyClaimModule: let new_attributes = DualYieldTokenAttributes { lp_farm_token_nonce: new_lp_farm_tokens.token_nonce, lp_farm_token_amount: new_lp_farm_tokens.amount, - virtual_pos_token_nonce: new_staking_farm_tokens.token_nonce, - virtual_pos_token_amount: lp_tokens_safe_price, - real_pos_token_amount: attributes.real_pos_token_amount, + staking_farm_token_nonce: new_staking_farm_tokens.token_nonce, + staking_farm_token_amount: new_staking_farm_tokens.amount, }; InternalClaimResult { diff --git a/farm-staking/farm-staking-proxy/src/proxy_actions/merge_pos.rs b/farm-staking/farm-staking-proxy/src/proxy_actions/merge_pos.rs deleted file mode 100644 index 4a0f89031..000000000 --- a/farm-staking/farm-staking-proxy/src/proxy_actions/merge_pos.rs +++ /dev/null @@ -1,108 +0,0 @@ -use common_structs::PaymentsVec; - -use crate::{dual_yield_token::DualYieldTokenAttributes, result_types::MergeResult}; - -use mergeable::Mergeable; -use unwrappable::Unwrappable; - -multiversx_sc::imports!(); -multiversx_sc::derive_imports!(); - -#[multiversx_sc::module] -pub trait ProxyMergePosModule: - crate::dual_yield_token::DualYieldTokenModule - + crate::external_contracts_interactions::ExternalContractsInteractionsModule - + crate::lp_farm_token::LpFarmTokenModule - + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule - + utils::UtilsModule - + token_send::TokenSendModule - + sc_whitelist_module::SCWhitelistModule - + super::claim::ProxyClaimModule -{ - #[payable("*")] - #[endpoint(mergeMetastakingWithStakingToken)] - fn merge_metastaking_with_staking_token(&self) -> MergeResult { - let mut payments = self.call_value().all_esdt_transfers(); - require!( - payments.len() >= 2, - "Must send metastaking token and at least a staking token" - ); - - let dual_yield_token = self.pop_first_payment(&mut payments); - let dual_yield_token_mapper = self.dual_yield_token(); - dual_yield_token_mapper.require_same_token(&dual_yield_token.token_identifier); - - let mut attributes: DualYieldTokenAttributes = self - .get_attributes_as_part_of_fixed_supply(&dual_yield_token, &dual_yield_token_mapper); - dual_yield_token_mapper.nft_burn(dual_yield_token.token_nonce, &dual_yield_token.amount); - - let caller = self.blockchain().get_caller(); - let staking_farm_rewards = self.claim_staking_rewards_before_merge(&caller, &payments); - - let staking_amount_before_merge = attributes.get_total_staking_token_amount(); - for farm_staking_token in &payments { - attributes.real_pos_token_amount += &farm_staking_token.amount; - } - - let mut dual_yield_claim_result = self.claim_dual_yield( - &caller, - OptionalValue::None, - staking_amount_before_merge, - attributes, - ); - dual_yield_claim_result - .staking_farm_rewards - .merge_with(staking_farm_rewards); - - let new_dual_yield_tokens = self.create_dual_yield_tokens( - &dual_yield_token_mapper, - &dual_yield_claim_result.new_dual_yield_attributes, - ); - let merge_result = MergeResult { - lp_farm_rewards: dual_yield_claim_result.lp_farm_rewards, - staking_farm_rewards: dual_yield_claim_result.staking_farm_rewards, - new_dual_yield_tokens, - }; - - merge_result.send_and_return(self, &caller) - } - - fn claim_staking_rewards_before_merge( - &self, - caller: &ManagedAddress, - farm_staking_tokens: &PaymentsVec, - ) -> EsdtTokenPayment { - let staking_farm_token_id = self.staking_farm_token_id().get(); - let mut opt_staking_farm_rewards = Option::::None; - for farm_staking_token in farm_staking_tokens { - require!( - farm_staking_token.token_identifier == staking_farm_token_id, - "Invalid staking farm token" - ); - - let staking_claim_result = self.staking_farm_claim_rewards( - caller.clone(), - farm_staking_token.token_identifier, - farm_staking_token.token_nonce, - farm_staking_token.amount.clone(), - farm_staking_token.amount, - ); - - match &mut opt_staking_farm_rewards { - Some(rew) => rew.merge_with(staking_claim_result.staking_farm_rewards), - None => { - opt_staking_farm_rewards = Some(staking_claim_result.staking_farm_rewards); - } - }; - - let new_staking_farm_tokens = staking_claim_result.new_staking_farm_tokens; - self.send().esdt_local_burn( - &new_staking_farm_tokens.token_identifier, - new_staking_farm_tokens.token_nonce, - &new_staking_farm_tokens.amount, - ); - } - - opt_staking_farm_rewards.unwrap_or_panic::() - } -} diff --git a/farm-staking/farm-staking-proxy/src/proxy_actions/mod.rs b/farm-staking/farm-staking-proxy/src/proxy_actions/mod.rs index 59916511b..3270b0f79 100644 --- a/farm-staking/farm-staking-proxy/src/proxy_actions/mod.rs +++ b/farm-staking/farm-staking-proxy/src/proxy_actions/mod.rs @@ -1,4 +1,3 @@ pub mod claim; -pub mod merge_pos; pub mod stake; pub mod unstake; diff --git a/farm-staking/farm-staking-proxy/src/proxy_actions/stake.rs b/farm-staking/farm-staking-proxy/src/proxy_actions/stake.rs index 1cfe2047c..b32f62b76 100644 --- a/farm-staking/farm-staking-proxy/src/proxy_actions/stake.rs +++ b/farm-staking/farm-staking-proxy/src/proxy_actions/stake.rs @@ -10,6 +10,7 @@ pub trait ProxyStakeModule: + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + utils::UtilsModule + token_send::TokenSendModule + + energy_query::EnergyQueryModule + sc_whitelist_module::SCWhitelistModule { #[payable("*")] @@ -36,15 +37,14 @@ pub trait ProxyStakeModule: let staking_farm_token_id = self.staking_farm_token_id().get(); let mut additional_staking_farm_tokens = ManagedVec::new(); let mut additional_lp_farm_tokens = ManagedVec::new(); - let mut total_user_real_staking_tokens = BigUint::zero(); for p in &additional_payments { let attributes: DualYieldTokenAttributes = self.get_attributes_as_part_of_fixed_supply(&p, &dual_yield_token_mapper); additional_staking_farm_tokens.push(EsdtTokenPayment::new( staking_farm_token_id.clone(), - attributes.virtual_pos_token_nonce, - attributes.get_total_staking_token_amount(), + attributes.staking_farm_token_nonce, + attributes.staking_farm_token_amount, )); additional_lp_farm_tokens.push(EsdtTokenPayment::new( @@ -53,8 +53,6 @@ pub trait ProxyStakeModule: attributes.lp_farm_token_amount, )); - total_user_real_staking_tokens += attributes.real_pos_token_amount; - dual_yield_token_mapper.nft_burn(p.token_nonce, &p.amount); } @@ -70,26 +68,26 @@ pub trait ProxyStakeModule: ); let received_staking_farm_token = staking_farm_enter_result.received_staking_farm_token; - let merged_lp_farm_tokens = self.merge_lp_farm_tokens( - orig_caller, - lp_farm_token_payment, - additional_lp_farm_tokens, - ); + let (merged_lp_farm_tokens, lp_farm_boosted_rewards) = self + .merge_lp_farm_tokens( + orig_caller, + lp_farm_token_payment, + additional_lp_farm_tokens, + ) + .into_tuple(); - let new_staking_farm_token_amount = - &received_staking_farm_token.amount - &total_user_real_staking_tokens; let new_attributes = DualYieldTokenAttributes { lp_farm_token_nonce: merged_lp_farm_tokens.token_nonce, lp_farm_token_amount: merged_lp_farm_tokens.amount, - virtual_pos_token_nonce: received_staking_farm_token.token_nonce, - virtual_pos_token_amount: new_staking_farm_token_amount, - real_pos_token_amount: total_user_real_staking_tokens, + staking_farm_token_nonce: received_staking_farm_token.token_nonce, + staking_farm_token_amount: received_staking_farm_token.amount, }; let new_dual_yield_tokens = self.create_dual_yield_tokens(&dual_yield_token_mapper, &new_attributes); let output_payments = StakeProxyResult { dual_yield_tokens: new_dual_yield_tokens, - boosted_rewards: staking_farm_enter_result.boosted_rewards, + staking_boosted_rewards: staking_farm_enter_result.boosted_rewards, + lp_farm_boosted_rewards, }; output_payments.send_and_return(self, &caller) diff --git a/farm-staking/farm-staking-proxy/src/proxy_actions/unstake.rs b/farm-staking/farm-staking-proxy/src/proxy_actions/unstake.rs index 59e65f4e0..f4388c9c0 100644 --- a/farm-staking/farm-staking-proxy/src/proxy_actions/unstake.rs +++ b/farm-staking/farm-staking-proxy/src/proxy_actions/unstake.rs @@ -1,5 +1,4 @@ use fixed_supply_token::FixedSupplyToken; -use mergeable::Mergeable; use crate::{dual_yield_token::DualYieldTokenAttributes, result_types::UnstakeResult}; @@ -13,6 +12,7 @@ pub trait ProxyUnstakeModule: + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + utils::UtilsModule + token_send::TokenSendModule + + energy_query::EnergyQueryModule + sc_whitelist_module::SCWhitelistModule { #[payable("*")] @@ -21,7 +21,6 @@ pub trait ProxyUnstakeModule: &self, pair_first_token_min_amount: BigUint, pair_second_token_min_amount: BigUint, - exit_amount: BigUint, opt_orig_caller: OptionalValue, ) -> UnstakeResult { let caller = self.blockchain().get_caller(); @@ -32,24 +31,13 @@ pub trait ProxyUnstakeModule: let full_attributes: DualYieldTokenAttributes = dual_yield_token_mapper.get_token_attributes(payment.token_nonce); - let total_for_nonce = full_attributes.get_total_supply(); - require!( - payment.amount == total_for_nonce, - "Must exit with full position as payment" - ); - require!( - exit_amount > 0 && exit_amount <= payment.amount, - "Invalid exit amount" - ); - let full_staking_token_amount = full_attributes.get_total_staking_token_amount(); let exit_attributes: DualYieldTokenAttributes = - full_attributes.clone().into_part(&exit_amount); + full_attributes.into_part(&payment.amount); let lp_farm_exit_result = self.lp_farm_exit( orig_caller.clone(), - full_attributes.lp_farm_token_nonce, - full_attributes.lp_farm_token_amount, + exit_attributes.lp_farm_token_nonce, exit_attributes.lp_farm_token_amount, ); let remove_liq_result = self.pair_remove_liquidity( @@ -58,64 +46,19 @@ pub trait ProxyUnstakeModule: pair_second_token_min_amount, ); - let remaining_total_staking_farm_tokens = - &full_staking_token_amount - &exit_attributes.virtual_pos_token_amount; let staking_farm_exit_result = self.staking_farm_unstake( - orig_caller.clone(), + orig_caller, remove_liq_result.staking_token_payment, - full_attributes.virtual_pos_token_nonce, - full_staking_token_amount, - exit_attributes.virtual_pos_token_amount.clone(), + exit_attributes.staking_farm_token_nonce, + exit_attributes.staking_farm_token_amount, ); - let opt_unstake_user_pos_result = if exit_attributes.real_pos_token_amount > 0 { - let res = self.staking_farm_unstake_user_position( - orig_caller, - full_attributes.virtual_pos_token_nonce, - remaining_total_staking_farm_tokens, - exit_attributes.real_pos_token_amount.clone(), - ); - Some(res) - } else { - None - }; - - let opt_new_dual_yield_tokens = if exit_amount != total_for_nonce { - let remaining_lp_farm_tokens = lp_farm_exit_result.remaining_farm_tokens.amount; - let remaining_virtual_farm_tokens = - full_attributes.virtual_pos_token_amount - exit_attributes.virtual_pos_token_amount; - let remaining_real_farm_tokens = - full_attributes.real_pos_token_amount - exit_attributes.real_pos_token_amount; - let new_attributes = DualYieldTokenAttributes { - lp_farm_token_nonce: full_attributes.lp_farm_token_nonce, - lp_farm_token_amount: remaining_lp_farm_tokens, - virtual_pos_token_nonce: full_attributes.virtual_pos_token_nonce, - virtual_pos_token_amount: remaining_virtual_farm_tokens, - real_pos_token_amount: remaining_real_farm_tokens, - }; - let new_dual_yield_tokens = - self.create_dual_yield_tokens(&dual_yield_token_mapper, &new_attributes); - - Some(new_dual_yield_tokens) - } else { - None - }; - - let mut total_staking_rewards = staking_farm_exit_result.staking_rewards; - let opt_unbond_token = opt_unstake_user_pos_result.map(|res| { - total_staking_rewards.merge_with(res.staking_rewards); - - res.unbond_staking_farm_token - }); - let caller = self.blockchain().get_caller(); let unstake_result = UnstakeResult { other_token_payment: remove_liq_result.other_token_payment, lp_farm_rewards: lp_farm_exit_result.lp_farm_rewards, - staking_rewards: total_staking_rewards, + staking_rewards: staking_farm_exit_result.staking_rewards, unbond_staking_farm_token: staking_farm_exit_result.unbond_staking_farm_token, - opt_unbond_staking_farm_token_for_user_pos: opt_unbond_token, - opt_new_dual_yield_tokens, }; dual_yield_token_mapper.nft_burn(payment.token_nonce, &payment.amount); diff --git a/farm-staking/farm-staking-proxy/src/result_types.rs b/farm-staking/farm-staking-proxy/src/result_types.rs index f1adc4335..2130fd696 100644 --- a/farm-staking/farm-staking-proxy/src/result_types.rs +++ b/farm-staking/farm-staking-proxy/src/result_types.rs @@ -13,7 +13,6 @@ pub struct LpFarmClaimRewardsResult { pub struct LpFarmExitResult { pub lp_tokens: EsdtTokenPayment, pub lp_farm_rewards: EsdtTokenPayment, - pub remaining_farm_tokens: EsdtTokenPayment, } // staking farm @@ -31,7 +30,6 @@ pub struct StakingFarmClaimRewardsResult { pub struct StakingFarmExitResult { pub unbond_staking_farm_token: EsdtTokenPayment, pub staking_rewards: EsdtTokenPayment, - pub remaining_farm_tokens: EsdtTokenPayment, } // pair @@ -46,7 +44,8 @@ pub struct PairRemoveLiquidityResult { #[derive(TypeAbi, TopEncode, TopDecode)] pub struct StakeProxyResult { pub dual_yield_tokens: EsdtTokenPayment, - pub boosted_rewards: EsdtTokenPayment, + pub staking_boosted_rewards: EsdtTokenPayment, + pub lp_farm_boosted_rewards: EsdtTokenPayment, } impl StakeProxyResult { @@ -56,7 +55,8 @@ impl StakeProxyResult { to: &ManagedAddress, ) -> Self { sc.send_payment_non_zero(to, &self.dual_yield_tokens); - sc.send_payment_non_zero(to, &self.boosted_rewards); + sc.send_payment_non_zero(to, &self.staking_boosted_rewards); + sc.send_payment_non_zero(to, &self.lp_farm_boosted_rewards); self } @@ -92,8 +92,6 @@ pub struct UnstakeResult { pub lp_farm_rewards: EsdtTokenPayment, pub staking_rewards: EsdtTokenPayment, pub unbond_staking_farm_token: EsdtTokenPayment, - pub opt_unbond_staking_farm_token_for_user_pos: Option>, - pub opt_new_dual_yield_tokens: Option>, } impl UnstakeResult { @@ -108,14 +106,6 @@ impl UnstakeResult { payments.push(self.staking_rewards.clone()); payments.push(self.unbond_staking_farm_token.clone()); - if let Some(unbond_for_user_pos) = &self.opt_unbond_staking_farm_token_for_user_pos { - payments.push(unbond_for_user_pos.clone()); - } - - if let Some(new_dual_yield_tokens) = &self.opt_new_dual_yield_tokens { - payments.push(new_dual_yield_tokens.clone()); - } - sc.send_multiple_tokens_if_not_zero(to, &payments); self diff --git a/farm-staking/farm-staking-proxy/tests/composed_pos_test.rs b/farm-staking/farm-staking-proxy/tests/composed_pos_test.rs deleted file mode 100644 index 76b13a8f8..000000000 --- a/farm-staking/farm-staking-proxy/tests/composed_pos_test.rs +++ /dev/null @@ -1,453 +0,0 @@ -pub mod constants; -pub mod staking_farm_with_lp_external_contracts; -pub mod staking_farm_with_lp_staking_contract_interactions; -pub mod staking_farm_with_lp_staking_contract_setup; - -multiversx_sc::imports!(); - -use constants::*; -use farm_staking::stake_farm::StakeFarmModule; -use farm_staking_proxy::dual_yield_token::DualYieldTokenAttributes; -use farm_staking_proxy::proxy_actions::claim::ProxyClaimModule; -use farm_staking_proxy::proxy_actions::merge_pos::ProxyMergePosModule; - -use farm_staking_proxy::proxy_actions::unstake::ProxyUnstakeModule; -use multiversx_sc::codec::Empty; -use multiversx_sc_scenario::{ - managed_biguint, rust_biguint, testing_framework::TxTokenTransfer, DebugApi, -}; -use staking_farm_with_lp_staking_contract_interactions::*; - -#[test] -fn combine_metastaking_with_staking_pos_test() { - let _ = DebugApi::dummy(); - let mut setup = FarmStakingSetup::new( - pair::contract_obj, - farm::contract_obj, - farm_staking::contract_obj, - farm_staking_proxy::contract_obj, - ); - - let expected_staking_token_amount = 1_001_000_000; // safe price of USER_TOTAL_LP_TOKENS in RIDE tokens - let _ = setup.stake_farm_lp_proxy(1, USER_TOTAL_LP_TOKENS, 1, expected_staking_token_amount); - - let user_addr = setup.user_addr.clone(); - let composed_pos_full_amount = 1_000_000; - setup.b_mock.set_esdt_balance( - &user_addr, - STAKING_TOKEN_ID, - &rust_biguint!(composed_pos_full_amount), - ); - - // proxy needs the burn role now the tokens - setup.b_mock.set_esdt_local_roles( - setup.proxy_wrapper.address_ref(), - STAKING_FARM_TOKEN_ID, - &[EsdtLocalRole::NftBurn], - ); - - // stake 1/4 and then 3/4 of the tokens - setup - .b_mock - .execute_esdt_transfer( - &user_addr, - &setup.staking_farm_wrapper, - STAKING_TOKEN_ID, - 0, - &rust_biguint!(composed_pos_full_amount / 4), - |sc| { - sc.stake_farm_endpoint(OptionalValue::None); - }, - ) - .assert_ok(); - - setup - .b_mock - .execute_esdt_transfer( - &user_addr, - &setup.staking_farm_wrapper, - STAKING_TOKEN_ID, - 0, - &rust_biguint!(composed_pos_full_amount * 3 / 4), - |sc| { - sc.stake_farm_endpoint(OptionalValue::None); - }, - ) - .assert_ok(); - - setup.b_mock.check_nft_balance::( - &user_addr, - STAKING_FARM_TOKEN_ID, - 2, - &rust_biguint!(composed_pos_full_amount / 4), - None, - ); - setup.b_mock.check_nft_balance::( - &user_addr, - STAKING_FARM_TOKEN_ID, - 3, - &rust_biguint!(composed_pos_full_amount * 3 / 4), - None, - ); - - // merge metastaking pos with two staking tokens - let merge_payments = vec![ - TxTokenTransfer { - token_identifier: DUAL_YIELD_TOKEN_ID.to_vec(), - nonce: 1, - value: rust_biguint!(expected_staking_token_amount), - }, - TxTokenTransfer { - token_identifier: STAKING_FARM_TOKEN_ID.to_vec(), - nonce: 2, - value: rust_biguint!(composed_pos_full_amount / 4), - }, - TxTokenTransfer { - token_identifier: STAKING_FARM_TOKEN_ID.to_vec(), - nonce: 3, - value: rust_biguint!(composed_pos_full_amount * 3 / 4), - }, - ]; - setup - .b_mock - .execute_esdt_multi_transfer(&user_addr, &setup.proxy_wrapper, &merge_payments, |sc| { - sc.merge_metastaking_with_staking_token(); - }) - .assert_ok(); - - setup.b_mock.check_nft_balance( - &user_addr, - DUAL_YIELD_TOKEN_ID, - 2, - &rust_biguint!(expected_staking_token_amount), - Some(&DualYieldTokenAttributes:: { - lp_farm_token_nonce: 2, - lp_farm_token_amount: managed_biguint!(USER_TOTAL_LP_TOKENS), - virtual_pos_token_nonce: 6, - virtual_pos_token_amount: managed_biguint!(expected_staking_token_amount), - real_pos_token_amount: managed_biguint!(composed_pos_full_amount), - }), - ); - - // claim rewards with composed pos - setup - .b_mock - .execute_esdt_transfer( - &user_addr, - &setup.proxy_wrapper, - DUAL_YIELD_TOKEN_ID, - 2, - &rust_biguint!(expected_staking_token_amount), - |sc| { - sc.claim_dual_yield_endpoint(OptionalValue::None); - }, - ) - .assert_ok(); - - setup.b_mock.check_nft_balance( - &user_addr, - DUAL_YIELD_TOKEN_ID, - 3, - &rust_biguint!(expected_staking_token_amount), - Some(&DualYieldTokenAttributes:: { - lp_farm_token_nonce: 3, - lp_farm_token_amount: managed_biguint!(USER_TOTAL_LP_TOKENS), - virtual_pos_token_nonce: 7, - virtual_pos_token_amount: managed_biguint!(expected_staking_token_amount), - real_pos_token_amount: managed_biguint!(composed_pos_full_amount), - }), - ); - - // claim again - setup - .b_mock - .execute_esdt_transfer( - &user_addr, - &setup.proxy_wrapper, - DUAL_YIELD_TOKEN_ID, - 3, - &rust_biguint!(expected_staking_token_amount), - |sc| { - sc.claim_dual_yield_endpoint(OptionalValue::None); - }, - ) - .assert_ok(); - - setup.b_mock.check_nft_balance( - &user_addr, - DUAL_YIELD_TOKEN_ID, - 4, - &rust_biguint!(expected_staking_token_amount), - Some(&DualYieldTokenAttributes:: { - lp_farm_token_nonce: 4, - lp_farm_token_amount: managed_biguint!(USER_TOTAL_LP_TOKENS), - virtual_pos_token_nonce: 8, - virtual_pos_token_amount: managed_biguint!(expected_staking_token_amount), - real_pos_token_amount: managed_biguint!(composed_pos_full_amount), - }), - ); - - setup - .b_mock - .set_block_nonce(BLOCK_NONCE_AFTER_PAIR_SETUP + 20); - setup.b_mock.set_block_epoch(20); - - // unstake - setup - .b_mock - .execute_esdt_transfer( - &user_addr, - &setup.proxy_wrapper, - DUAL_YIELD_TOKEN_ID, - 4, - &rust_biguint!(expected_staking_token_amount), - |sc| { - let unstake_result = sc.unstake_farm_tokens( - managed_biguint!(1), - managed_biguint!(1), - managed_biguint!(expected_staking_token_amount), - OptionalValue::None, - ); - assert_eq!( - unstake_result - .opt_unbond_staking_farm_token_for_user_pos - .unwrap() - .amount, - composed_pos_full_amount - ); - assert_eq!( - unstake_result.unbond_staking_farm_token.amount, - expected_staking_token_amount - ); - }, - ) - .assert_ok(); -} - -#[test] -fn combine_metastaking_with_staking_pos_partial_actions_test() { - let _ = DebugApi::dummy(); - let mut setup = FarmStakingSetup::new( - pair::contract_obj, - farm::contract_obj, - farm_staking::contract_obj, - farm_staking_proxy::contract_obj, - ); - - let expected_staking_token_amount = 1_001_000_000; // safe price of USER_TOTAL_LP_TOKENS in RIDE tokens - let _ = setup.stake_farm_lp_proxy(1, USER_TOTAL_LP_TOKENS, 1, expected_staking_token_amount); - - let user_addr = setup.user_addr.clone(); - let composed_pos_full_amount = 1_000_000; - setup.b_mock.set_esdt_balance( - &user_addr, - STAKING_TOKEN_ID, - &rust_biguint!(composed_pos_full_amount), - ); - - // proxy needs the burn role now the tokens - setup.b_mock.set_esdt_local_roles( - setup.proxy_wrapper.address_ref(), - STAKING_FARM_TOKEN_ID, - &[EsdtLocalRole::NftBurn], - ); - - // stake 1/4 and then 3/4 of the tokens - setup - .b_mock - .execute_esdt_transfer( - &user_addr, - &setup.staking_farm_wrapper, - STAKING_TOKEN_ID, - 0, - &rust_biguint!(composed_pos_full_amount / 4), - |sc| { - sc.stake_farm_endpoint(OptionalValue::None); - }, - ) - .assert_ok(); - - setup - .b_mock - .execute_esdt_transfer( - &user_addr, - &setup.staking_farm_wrapper, - STAKING_TOKEN_ID, - 0, - &rust_biguint!(composed_pos_full_amount * 3 / 4), - |sc| { - sc.stake_farm_endpoint(OptionalValue::None); - }, - ) - .assert_ok(); - - setup.b_mock.check_nft_balance::( - &user_addr, - STAKING_FARM_TOKEN_ID, - 2, - &rust_biguint!(composed_pos_full_amount / 4), - None, - ); - setup.b_mock.check_nft_balance::( - &user_addr, - STAKING_FARM_TOKEN_ID, - 3, - &rust_biguint!(composed_pos_full_amount * 3 / 4), - None, - ); - - // merge half of metastaking pos with two staking tokens - let merge_payments = vec![ - TxTokenTransfer { - token_identifier: DUAL_YIELD_TOKEN_ID.to_vec(), - nonce: 1, - value: rust_biguint!(expected_staking_token_amount / 2), - }, - TxTokenTransfer { - token_identifier: STAKING_FARM_TOKEN_ID.to_vec(), - nonce: 2, - value: rust_biguint!(composed_pos_full_amount / 4), - }, - TxTokenTransfer { - token_identifier: STAKING_FARM_TOKEN_ID.to_vec(), - nonce: 3, - value: rust_biguint!(composed_pos_full_amount * 3 / 4), - }, - ]; - setup - .b_mock - .execute_esdt_multi_transfer(&user_addr, &setup.proxy_wrapper, &merge_payments, |sc| { - sc.merge_metastaking_with_staking_token(); - }) - .assert_ok(); - - setup.b_mock.check_nft_balance( - &user_addr, - DUAL_YIELD_TOKEN_ID, - 2, - &rust_biguint!(expected_staking_token_amount / 2), - Some(&DualYieldTokenAttributes:: { - lp_farm_token_nonce: 2, - lp_farm_token_amount: managed_biguint!(USER_TOTAL_LP_TOKENS / 2), - virtual_pos_token_nonce: 6, - virtual_pos_token_amount: managed_biguint!(expected_staking_token_amount / 2), - real_pos_token_amount: managed_biguint!(composed_pos_full_amount), - }), - ); - - // claim rewards with part of composed pos - setup - .b_mock - .execute_esdt_transfer( - &user_addr, - &setup.proxy_wrapper, - DUAL_YIELD_TOKEN_ID, - 2, - &rust_biguint!(expected_staking_token_amount / 4), - |sc| { - sc.claim_dual_yield_endpoint(OptionalValue::None); - }, - ) - .assert_ok(); - - setup.b_mock.check_nft_balance( - &user_addr, - DUAL_YIELD_TOKEN_ID, - 3, - &rust_biguint!(expected_staking_token_amount / 4), - Some(&DualYieldTokenAttributes:: { - lp_farm_token_nonce: 3, - lp_farm_token_amount: managed_biguint!(USER_TOTAL_LP_TOKENS / 4), - virtual_pos_token_nonce: 7, - virtual_pos_token_amount: managed_biguint!(expected_staking_token_amount / 4), - real_pos_token_amount: managed_biguint!(composed_pos_full_amount / 2), - }), - ); - - setup - .b_mock - .set_block_nonce(BLOCK_NONCE_AFTER_PAIR_SETUP + 20); - setup.b_mock.set_block_epoch(20); - - // unstake partial - setup - .b_mock - .execute_esdt_transfer( - &user_addr, - &setup.proxy_wrapper, - DUAL_YIELD_TOKEN_ID, - 3, - &rust_biguint!(expected_staking_token_amount / 4), - |sc| { - let unstake_result = sc.unstake_farm_tokens( - managed_biguint!(1), - managed_biguint!(1), - managed_biguint!(expected_staking_token_amount / 8), - OptionalValue::None, - ); - assert_eq!( - unstake_result - .opt_unbond_staking_farm_token_for_user_pos - .unwrap() - .amount, - composed_pos_full_amount / 4 - ); - assert_eq!( - unstake_result.unbond_staking_farm_token.amount, - expected_staking_token_amount / 8 - ); - assert_eq!( - unstake_result.opt_new_dual_yield_tokens.unwrap().amount, - expected_staking_token_amount / 8 - ); - }, - ) - .assert_ok(); - - // check leftover token attributes - setup.b_mock.check_nft_balance( - &user_addr, - DUAL_YIELD_TOKEN_ID, - 4, - &rust_biguint!(expected_staking_token_amount / 8), - Some(&DualYieldTokenAttributes:: { - lp_farm_token_nonce: 3, - lp_farm_token_amount: managed_biguint!(USER_TOTAL_LP_TOKENS / 8), - virtual_pos_token_nonce: 7, - virtual_pos_token_amount: managed_biguint!(expected_staking_token_amount / 8), - real_pos_token_amount: managed_biguint!(composed_pos_full_amount / 4), - }), - ); - - // unstake remaining pos - setup - .b_mock - .execute_esdt_transfer( - &user_addr, - &setup.proxy_wrapper, - DUAL_YIELD_TOKEN_ID, - 4, - &rust_biguint!(expected_staking_token_amount / 8), - |sc| { - let unstake_result = sc.unstake_farm_tokens( - managed_biguint!(1), - managed_biguint!(1), - managed_biguint!(expected_staking_token_amount / 8), - OptionalValue::None, - ); - assert_eq!( - unstake_result - .opt_unbond_staking_farm_token_for_user_pos - .unwrap() - .amount, - composed_pos_full_amount / 4 - ); - assert_eq!( - unstake_result.unbond_staking_farm_token.amount, - expected_staking_token_amount / 8 - ); - assert!(unstake_result.opt_new_dual_yield_tokens.is_none(),); - }, - ) - .assert_ok(); -} diff --git a/farm-staking/farm-staking-proxy/tests/constants/mod.rs b/farm-staking/farm-staking-proxy/tests/constants/mod.rs index 6e9bb9fd9..706bc12a2 100644 --- a/farm-staking/farm-staking-proxy/tests/constants/mod.rs +++ b/farm-staking/farm-staking-proxy/tests/constants/mod.rs @@ -39,8 +39,18 @@ pub const USER_REWARDS_ENERGY_CONST: u64 = 3; pub const USER_REWARDS_FARM_CONST: u64 = 2; pub const MIN_ENERGY_AMOUNT_FOR_BOOSTED_YIELDS: u64 = 1; pub const MIN_FARM_AMOUNT_FOR_BOOSTED_YIELDS: u64 = 1; +pub const BOOSTED_YIELDS_PERCENTAGE: u64 = 2_500; // 25% // Proxy constants pub static PROXY_WASM_PATH: &str = "farm-staking-proxy/output/farm-staking-proxy"; pub static DUAL_YIELD_TOKEN_ID: &[u8] = b"DYIELD-abcdef"; + +// Energy factory constants + +pub const EPOCHS_IN_YEAR: u64 = 360; +pub static MEX_TOKEN_ID: &[u8] = b"MEX-123456"; +pub static LOCKED_TOKEN_ID: &[u8] = b"LOCKED-123456"; +pub static LEGACY_LOCKED_TOKEN_ID: &[u8] = b"LEGACY-123456"; +pub static LOCK_OPTIONS: &[u64] = &[EPOCHS_IN_YEAR, 5 * EPOCHS_IN_YEAR, 10 * EPOCHS_IN_YEAR]; // 1, 5 or 10 years +pub static PENALTY_PERCENTAGES: &[u64] = &[4_000, 6_000, 8_000]; 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 6036f505e..d7ee78e8d 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 @@ -1,3 +1,5 @@ +#![allow(deprecated)] + pub mod constants; pub mod staking_farm_with_lp_external_contracts; pub mod staking_farm_with_lp_staking_contract_interactions; @@ -18,7 +20,8 @@ use staking_farm_with_lp_staking_contract_interactions::*; fn test_all_setup() { let _ = FarmStakingSetup::new( pair::contract_obj, - farm::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, farm_staking::contract_obj, farm_staking_proxy::contract_obj, ); @@ -28,7 +31,8 @@ fn test_all_setup() { fn test_stake_farm_proxy() { let mut setup = FarmStakingSetup::new( pair::contract_obj, - farm::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, farm_staking::contract_obj, farm_staking_proxy::contract_obj, ); @@ -42,7 +46,8 @@ fn test_stake_farm_proxy() { fn test_claim_rewards_farm_proxy_full() { let mut setup = FarmStakingSetup::new( pair::contract_obj, - farm::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, farm_staking::contract_obj, farm_staking_proxy::contract_obj, ); @@ -69,7 +74,8 @@ fn test_claim_rewards_farm_proxy_full() { fn test_claim_rewards_farm_proxy_half() { let mut setup = FarmStakingSetup::new( pair::contract_obj, - farm::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, farm_staking::contract_obj, farm_staking_proxy::contract_obj, ); @@ -96,7 +102,8 @@ fn test_claim_rewards_farm_proxy_half() { fn test_claim_rewards_farm_proxy_twice() { let mut setup = FarmStakingSetup::new( pair::contract_obj, - farm::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, farm_staking::contract_obj, farm_staking_proxy::contract_obj, ); @@ -138,7 +145,8 @@ fn test_claim_rewards_farm_proxy_twice() { fn test_unstake_through_proxy_no_claim() { let mut setup = FarmStakingSetup::new( pair::contract_obj, - farm::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, farm_staking::contract_obj, farm_staking_proxy::contract_obj, ); @@ -168,7 +176,8 @@ fn test_unstake_through_proxy_no_claim() { fn unstake_through_proxy_after_claim() { let mut setup = FarmStakingSetup::new( pair::contract_obj, - farm::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, farm_staking::contract_obj, farm_staking_proxy::contract_obj, ); @@ -205,10 +214,11 @@ fn unstake_through_proxy_after_claim() { #[test] fn unstake_partial_position_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut setup = FarmStakingSetup::new( pair::contract_obj, - farm::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, farm_staking::contract_obj, farm_staking_proxy::contract_obj, ); @@ -224,26 +234,6 @@ fn unstake_partial_position_test() { let dual_yield_token_amount = 1_001_000_000; - // unstake with half position - wrong payment amount - setup - .b_mock - .execute_esdt_transfer( - &setup.user_addr, - &setup.proxy_wrapper, - DUAL_YIELD_TOKEN_ID, - dual_yield_token_nonce_after_stake, - &rust_biguint!(dual_yield_token_amount / 2), - |sc| { - let _ = sc.unstake_farm_tokens( - managed_biguint!(1), - managed_biguint!(1), - managed_biguint!(dual_yield_token_amount / 4), - OptionalValue::None, - ); - }, - ) - .assert_user_error("Must exit with full position as payment"); - // unstake with half position - ok setup .b_mock @@ -252,12 +242,11 @@ fn unstake_partial_position_test() { &setup.proxy_wrapper, DUAL_YIELD_TOKEN_ID, dual_yield_token_nonce_after_stake, - &rust_biguint!(dual_yield_token_amount), + &rust_biguint!(dual_yield_token_amount / 2), |sc| { let results = sc.unstake_farm_tokens( managed_biguint!(1), managed_biguint!(1), - managed_biguint!(dual_yield_token_amount / 2), OptionalValue::None, ); @@ -266,12 +255,12 @@ fn unstake_partial_position_test() { wegld_payment.token_identifier, managed_token_id!(WEGLD_TOKEN_ID) ); - assert_eq!(wegld_payment.amount, 1_001_000_000 / 2); + assert_eq!(wegld_payment.amount, dual_yield_token_amount / 2); let lp_farm_rewards = results.lp_farm_rewards; assert_eq!( lp_farm_rewards.token_identifier, - managed_token_id!(RIDE_TOKEN_ID) + managed_token_id!(LOCKED_TOKEN_ID) ); assert_eq!(lp_farm_rewards.amount, 99_999 / 2); @@ -287,49 +276,24 @@ fn unstake_partial_position_test() { unbond_tokens.token_identifier, managed_token_id!(STAKING_FARM_TOKEN_ID) ); - assert_eq!(unbond_tokens.amount, 1_001_000_000 / 2); - - let new_dual_yield_tokens = results.opt_new_dual_yield_tokens.unwrap(); - assert_eq!( - new_dual_yield_tokens.token_identifier, - managed_token_id!(DUAL_YIELD_TOKEN_ID) - ); - assert_eq!(new_dual_yield_tokens.amount, 1_001_000_000 / 2); + assert_eq!(unbond_tokens.amount, dual_yield_token_amount / 2); }, ) .assert_ok(); - let expected_new_dual_yield_attributes = DualYieldTokenAttributes:: { - lp_farm_token_nonce: 1, - lp_farm_token_amount: managed_biguint!(USER_TOTAL_LP_TOKENS / 2), - virtual_pos_token_nonce: 1, - virtual_pos_token_amount: managed_biguint!(1_001_000_000 / 2), - real_pos_token_amount: managed_biguint!(0), - }; - let new_dual_yield_token_nonce = dual_yield_token_nonce_after_stake + 1; - let new_dual_yield_token_amount = dual_yield_token_amount / 2; - setup.b_mock.check_nft_balance( - &setup.user_addr, - DUAL_YIELD_TOKEN_ID, - new_dual_yield_token_nonce, - &rust_biguint!(new_dual_yield_token_amount), - Some(&expected_new_dual_yield_attributes), - ); - - // unstake with the new dual yield tokens + // unstake with the remaining dual yield tokens setup .b_mock .execute_esdt_transfer( &setup.user_addr, &setup.proxy_wrapper, DUAL_YIELD_TOKEN_ID, - new_dual_yield_token_nonce, - &rust_biguint!(new_dual_yield_token_amount), + dual_yield_token_nonce_after_stake, + &rust_biguint!(dual_yield_token_amount / 2), |sc| { let results = sc.unstake_farm_tokens( managed_biguint!(1), managed_biguint!(1), - managed_biguint!(new_dual_yield_token_amount), OptionalValue::None, ); @@ -343,7 +307,7 @@ fn unstake_partial_position_test() { let lp_farm_rewards = results.lp_farm_rewards; assert_eq!( lp_farm_rewards.token_identifier, - managed_token_id!(RIDE_TOKEN_ID) + managed_token_id!(LOCKED_TOKEN_ID) ); assert_eq!(lp_farm_rewards.amount, 99_999 / 2); @@ -360,9 +324,6 @@ fn unstake_partial_position_test() { managed_token_id!(STAKING_FARM_TOKEN_ID) ); assert_eq!(unbond_tokens.amount, 1_001_000_000 / 2); - - // no new dual yield tokens created - assert!(results.opt_new_dual_yield_tokens.is_none()); }, ) .assert_ok(); @@ -372,7 +333,8 @@ fn unstake_partial_position_test() { fn unbond_test() { let mut setup = FarmStakingSetup::new( pair::contract_obj, - farm::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, farm_staking::contract_obj, farm_staking_proxy::contract_obj, ); @@ -416,7 +378,8 @@ fn unbond_test() { fn farm_staking_compound_rewards_and_unstake_test() { let mut setup = FarmStakingSetup::new( pair::contract_obj, - farm::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, farm_staking::contract_obj, farm_staking_proxy::contract_obj, ); @@ -446,7 +409,8 @@ fn farm_staking_compound_rewards_and_unstake_test() { fn test_stake_farm_through_proxy_with_merging() { let mut setup = FarmStakingSetup::new( pair::contract_obj, - farm::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, farm_staking::contract_obj, farm_staking_proxy::contract_obj, ); @@ -462,9 +426,8 @@ fn test_stake_farm_through_proxy_with_merging() { Some(&DualYieldTokenAttributes:: { lp_farm_token_nonce: 1, lp_farm_token_amount: managed_biguint!(400_000_000), - virtual_pos_token_nonce: 1, - virtual_pos_token_amount: managed_biguint!(400_000_000), - real_pos_token_amount: managed_biguint!(0), + staking_farm_token_nonce: 1, + staking_farm_token_amount: managed_biguint!(400_000_000), }), ) }); @@ -493,9 +456,8 @@ fn test_stake_farm_through_proxy_with_merging() { Some(&DualYieldTokenAttributes:: { lp_farm_token_nonce: 2, lp_farm_token_amount: managed_biguint!(1_000_000_000), - virtual_pos_token_nonce: 2, - virtual_pos_token_amount: managed_biguint!(1_000_000_000), - real_pos_token_amount: managed_biguint!(0), + staking_farm_token_nonce: 2, + staking_farm_token_amount: managed_biguint!(1_000_000_000), }), ) }); @@ -518,3 +480,148 @@ fn test_stake_farm_through_proxy_with_merging() { ) }); } + +#[test] +fn test_farm_stake_proxy_merging_boosted_rewards() { + 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.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 mut farm_token_nonce = setup.enter_lp_farm(&user_address, farm_amount); + let second_farm_token_nonce = setup.enter_lp_farm(&user_address, farm_amount); // will enter Metastaking next week + + // User claims rewards to get his energy registered + farm_token_nonce = setup.claim_lp_farm(&user_address, farm_token_nonce, farm_amount, 0); + + // 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), + }), + ) + }); + + // 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); + + // 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); + + // advance 1 week + setup.b_mock.set_block_epoch(10); + setup.set_user_energy(&user_address, 1_000, 10, 1); + + // check locked tokens rewards before staking farm tokens with merge + setup.b_mock.execute_in_managed_environment(|| { + setup.b_mock.check_nft_balance::( + &user_address, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(0), + None, + ) + }); + + // user enters Metastaking with second position, which should merge with the first one + let dual_yield_token_payments = vec![NonceAmountPair { + nonce: first_dual_yield_token_nonce, + amount: farm_amount, + }]; + let new_dual_yield_token_nonce = setup.stake_farm_lp_proxy_multiple( + second_farm_token_nonce, + farm_amount, + dual_yield_token_payments, + ); + + // check user staking farm tokens + setup.b_mock.check_nft_balance::( + &setup.user_addr, + DUAL_YIELD_TOKEN_ID, + first_dual_yield_token_nonce, + &rust_biguint!(0), + None, + ); + setup.b_mock.execute_in_managed_environment(|| { + setup.b_mock.check_nft_balance( + &setup.user_addr, + DUAL_YIELD_TOKEN_ID, + new_dual_yield_token_nonce, + &rust_biguint!(farm_amount * 2), + Some(&DualYieldTokenAttributes:: { + lp_farm_token_nonce: 6, + lp_farm_token_amount: managed_biguint!(farm_amount * 2), + staking_farm_token_nonce: 2, + staking_farm_token_amount: managed_biguint!(farm_amount * 2), + }), + ) + }); + + // check farm staking SC tokens + setup.b_mock.check_esdt_balance( + setup.staking_farm_wrapper.address_ref(), + RIDE_TOKEN_ID, + &rust_biguint!(1_000_000_000_000), + ); + + // 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, + 6, // farm token nonce after merge + &rust_biguint!(farm_amount * 2), + None, //current attributes + ) + }); + + // check boosted rewards + setup.b_mock.execute_in_managed_environment(|| { + setup.b_mock.check_nft_balance::( + &user_address, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(boosted_rewards), + None, + ) + }); +} diff --git a/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_external_contracts/mod.rs b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_external_contracts/mod.rs index 02729ff2d..327897bfb 100644 --- a/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_external_contracts/mod.rs +++ b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_external_contracts/mod.rs @@ -1,10 +1,20 @@ +#![allow(deprecated)] + +use energy_factory::token_whitelist::TokenWhitelistModule; +use energy_factory::SimpleLockEnergy; +use energy_query::EnergyQueryModule; +use locking_module::lock_with_energy_module::LockWithEnergyModule; use multiversx_sc::codec::multi_types::{MultiValue3, OptionalValue}; use multiversx_sc::storage::mappers::StorageTokenWrapper; use multiversx_sc::types::{Address, EsdtLocalRole, ManagedAddress, MultiValueEncoded}; -use multiversx_sc_scenario::whitebox::TxTokenTransfer; +use multiversx_sc_modules::pause::PauseModule; +use multiversx_sc_scenario::whitebox_legacy::TxTokenTransfer; use multiversx_sc_scenario::{ - managed_address, managed_biguint, managed_token_id, rust_biguint, whitebox::*, DebugApi, + managed_address, managed_biguint, managed_token_id, rust_biguint, whitebox_legacy::*, DebugApi, }; +use pair::pair_actions::add_liq::AddLiquidityModule; +use pair::pair_actions::remove_liq::RemoveLiquidityModule; +use simple_lock::locked_token::LockedTokenModule; use farm::exit_penalty::ExitPenaltyModule; use pair::config as pair_config; @@ -14,10 +24,10 @@ use pair_config::ConfigModule as _; use pausable::{PausableModule, State}; use ::config as farm_config; -use farm::*; use farm_boosted_yields::boosted_yields_factors::BoostedYieldsFactorsModule; use farm_config::ConfigModule as _; use farm_token::FarmTokenModule; +use farm_with_locked_rewards::*; use crate::constants::*; @@ -76,7 +86,7 @@ where &rust_biguint!(USER_TOTAL_RIDE_TOKENS), ); - let mut block_round = 1; + let mut block_round: u64 = 1; b_mock.set_block_round(block_round); b_mock.set_block_nonce(BLOCK_NONCE_FIRST_ADD_LIQ); @@ -239,12 +249,13 @@ fn remove_liquidity( pub fn setup_lp_farm( owner_addr: &Address, user_addr: &Address, + energy_factory_address: &Address, b_mock: &mut BlockchainStateWrapper, farm_builder: FarmObjBuilder, user_farm_in_amount: u64, -) -> ContractObjWrapper, FarmObjBuilder> +) -> ContractObjWrapper, FarmObjBuilder> where - FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, + FarmObjBuilder: 'static + Copy + Fn() -> farm_with_locked_rewards::ContractObj, { let rust_zero = rust_biguint!(0u64); let farm_wrapper = @@ -254,7 +265,7 @@ where b_mock .execute_tx(owner_addr, &farm_wrapper, &rust_zero, |sc| { - let reward_token_id = managed_token_id!(RIDE_TOKEN_ID); + let reward_token_id = managed_token_id!(MEX_TOKEN_ID); let farming_token_id = managed_token_id!(LP_TOKEN_ID); let division_safety_constant = managed_biguint!(DIVISION_SAFETY_CONSTANT); let pair_address = managed_address!(&Address::zero()); @@ -280,6 +291,11 @@ where .set(&managed_biguint!(LP_FARM_PER_BLOCK_REWARD_AMOUNT)); sc.last_reward_block_nonce() .set(BLOCK_NONCE_AFTER_PAIR_SETUP); + sc.lock_epochs().set(LOCK_OPTIONS[2]); + sc.locking_sc_address() + .set(managed_address!(energy_factory_address)); + sc.energy_factory_address() + .set(managed_address!(energy_factory_address)); }) .assert_ok(); @@ -325,14 +341,80 @@ where farm_wrapper } +pub fn setup_energy_factory( + owner_addr: &Address, + b_mock: &mut BlockchainStateWrapper, + energy_factory_builder: EnergyFactoryObjBuilder, +) -> ContractObjWrapper, EnergyFactoryObjBuilder> +where + EnergyFactoryObjBuilder: 'static + Copy + Fn() -> energy_factory::ContractObj, +{ + let rust_zero = rust_biguint!(0u64); + let energy_factory_wrapper = b_mock.create_sc_account( + &rust_zero, + Some(owner_addr), + energy_factory_builder, + "energy factory", + ); + + b_mock + .execute_tx(owner_addr, &energy_factory_wrapper, &rust_zero, |sc| { + let mut lock_options = MultiValueEncoded::new(); + for (option, penalty) in LOCK_OPTIONS.iter().zip(PENALTY_PERCENTAGES.iter()) { + lock_options.push((*option, *penalty).into()); + } + + sc.init( + managed_token_id!(LOCKED_TOKEN_ID), + managed_token_id!(LEGACY_LOCKED_TOKEN_ID), + managed_address!(energy_factory_wrapper.address_ref()), + 0, + lock_options, + ); + + sc.base_asset_token_id() + .set(managed_token_id!(MEX_TOKEN_ID)); + sc.locked_token() + .set_token_id(managed_token_id!(LOCKED_TOKEN_ID)); + sc.set_paused(false); + }) + .assert_ok(); + + b_mock.set_esdt_local_roles( + energy_factory_wrapper.address_ref(), + MEX_TOKEN_ID, + &[EsdtLocalRole::Mint, EsdtLocalRole::Burn], + ); + b_mock.set_esdt_local_roles( + energy_factory_wrapper.address_ref(), + LOCKED_TOKEN_ID, + &[ + EsdtLocalRole::NftCreate, + EsdtLocalRole::NftAddQuantity, + EsdtLocalRole::NftBurn, + EsdtLocalRole::Transfer, + ], + ); + b_mock.set_esdt_local_roles( + energy_factory_wrapper.address_ref(), + LEGACY_LOCKED_TOKEN_ID, + &[EsdtLocalRole::NftBurn], + ); + + energy_factory_wrapper +} + fn enter_farm( user_address: &Address, b_mock: &mut BlockchainStateWrapper, - farm_wrapper: &ContractObjWrapper, FarmObjBuilder>, + farm_wrapper: &ContractObjWrapper< + farm_with_locked_rewards::ContractObj, + FarmObjBuilder, + >, farm_in_amount: u64, additional_farm_tokens: &[TxTokenTransfer], ) where - FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, + FarmObjBuilder: 'static + Copy + Fn() -> farm_with_locked_rewards::ContractObj, { let mut payments = Vec::with_capacity(1 + additional_farm_tokens.len()); payments.push(TxTokenTransfer { 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 f9eb0b06e..8860a604e 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,8 +1,17 @@ -use multiversx_sc::{codec::multi_types::OptionalValue, types::Address}; +#![allow(deprecated)] + +use energy_factory::energy::EnergyModule; +use energy_query::Energy; +use farm_boosted_yields::FarmBoostedYieldsModule; +use farm_with_locked_rewards::Farm; +use multiversx_sc::{ + codec::multi_types::OptionalValue, + types::{Address, BigInt}, +}; use multiversx_sc_scenario::{ - managed_address, managed_biguint, rust_biguint, - whitebox::TxTokenTransfer, - whitebox::{BlockchainStateWrapper, ContractObjWrapper}, + managed_address, managed_biguint, managed_token_id, rust_biguint, + whitebox_legacy::TxTokenTransfer, + whitebox_legacy::{BlockchainStateWrapper, ContractObjWrapper}, DebugApi, }; @@ -21,7 +30,7 @@ use sc_whitelist_module::SCWhitelistModule; use crate::{ constants::*, - staking_farm_with_lp_external_contracts::{setup_lp_farm, setup_pair}, + staking_farm_with_lp_external_contracts::{setup_energy_factory, setup_lp_farm, setup_pair}, staking_farm_with_lp_staking_contract_setup::{ add_proxy_to_whitelist, setup_proxy, setup_staking_farm, }, @@ -35,11 +44,13 @@ pub struct NonceAmountPair { pub struct FarmStakingSetup< PairObjBuilder, FarmObjBuilder, + EnergyFactoryBuilder, StakingContractObjBuilder, ProxyContractObjBuilder, > where PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, - FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, + FarmObjBuilder: 'static + Copy + Fn() -> farm_with_locked_rewards::ContractObj, + EnergyFactoryBuilder: 'static + Copy + Fn() -> energy_factory::ContractObj, StakingContractObjBuilder: 'static + Copy + Fn() -> farm_staking::ContractObj, ProxyContractObjBuilder: 'static + Copy + Fn() -> farm_staking_proxy::ContractObj, { @@ -47,29 +58,41 @@ pub struct FarmStakingSetup< pub user_addr: Address, pub b_mock: BlockchainStateWrapper, pub pair_wrapper: ContractObjWrapper, PairObjBuilder>, - pub lp_farm_wrapper: ContractObjWrapper, FarmObjBuilder>, + pub lp_farm_wrapper: + ContractObjWrapper, FarmObjBuilder>, + pub energy_factory_wrapper: + ContractObjWrapper, EnergyFactoryBuilder>, pub staking_farm_wrapper: ContractObjWrapper, StakingContractObjBuilder>, pub proxy_wrapper: ContractObjWrapper, ProxyContractObjBuilder>, } -impl +impl< + PairObjBuilder, + FarmObjBuilder, + EnergyFactoryBuilder, + StakingContractObjBuilder, + ProxyContractObjBuilder, + > FarmStakingSetup< PairObjBuilder, FarmObjBuilder, + EnergyFactoryBuilder, StakingContractObjBuilder, ProxyContractObjBuilder, > where PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, - FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, + FarmObjBuilder: 'static + Copy + Fn() -> farm_with_locked_rewards::ContractObj, + EnergyFactoryBuilder: 'static + Copy + Fn() -> energy_factory::ContractObj, StakingContractObjBuilder: 'static + Copy + Fn() -> farm_staking::ContractObj, ProxyContractObjBuilder: 'static + Copy + Fn() -> farm_staking_proxy::ContractObj, { pub fn new( pair_builder: PairObjBuilder, lp_farm_builder: FarmObjBuilder, + energy_factory_builder: EnergyFactoryBuilder, staking_farm_builder: StakingContractObjBuilder, proxy_builder: ProxyContractObjBuilder, ) -> Self { @@ -78,10 +101,13 @@ where let owner_addr = b_mock.create_user_account(&rust_zero); let user_addr = b_mock.create_user_account(&rust_biguint!(100_000_000)); + let energy_factory_wrapper = + setup_energy_factory(&owner_addr, &mut b_mock, energy_factory_builder); let pair_wrapper = setup_pair(&owner_addr, &user_addr, &mut b_mock, pair_builder); let lp_farm_wrapper = setup_lp_farm( &owner_addr, &user_addr, + energy_factory_wrapper.address_ref(), &mut b_mock, lp_farm_builder, USER_TOTAL_LP_TOKENS, @@ -109,6 +135,11 @@ where sc.add_sc_address_to_whitelist(managed_address!(proxy_wrapper.address_ref())); }) .assert_ok(); + b_mock + .execute_tx(&owner_addr, &energy_factory_wrapper, &rust_zero, |sc| { + sc.add_sc_address_to_whitelist(managed_address!(lp_farm_wrapper.address_ref())); + }) + .assert_ok(); FarmStakingSetup { owner_addr, @@ -116,6 +147,7 @@ where b_mock, pair_wrapper, lp_farm_wrapper, + energy_factory_wrapper, staking_farm_wrapper, proxy_wrapper, } @@ -154,9 +186,8 @@ where let expected_dual_yield_attributes = DualYieldTokenAttributes:: { lp_farm_token_nonce, lp_farm_token_amount: managed_biguint!(lp_farm_token_stake_amount), - virtual_pos_token_nonce: expected_staking_farm_token_nonce, - virtual_pos_token_amount: managed_biguint!(expected_staking_token_amount), - real_pos_token_amount: managed_biguint!(0), + staking_farm_token_nonce: expected_staking_farm_token_nonce, + staking_farm_token_amount: managed_biguint!(expected_staking_token_amount), }; self.b_mock.check_nft_balance( @@ -270,7 +301,6 @@ where let received_tokens = sc.unstake_farm_tokens( managed_biguint!(1), managed_biguint!(1), - managed_biguint!(dual_yield_token_amount), OptionalValue::None, ); @@ -404,9 +434,8 @@ where farm_token_nonce, &rust_biguint!(farm_token_amount), |sc| { - let (unbond_farm_tokens, reward_tokens, _) = sc - .unstake_farm(managed_biguint!(farm_token_amount), OptionalValue::None) - .into_tuple(); + let (unbond_farm_tokens, reward_tokens) = + sc.unstake_farm(OptionalValue::None).into_tuple(); unbond_token_nonce = unbond_farm_tokens.token_nonce; assert_eq!(reward_tokens.amount, expected_rewards_amount); @@ -420,4 +449,112 @@ where unbond_token_nonce } + + pub fn enter_lp_farm(&mut self, user: &Address, farm_token_amount: u64) -> u64 { + let mut farm_token_nonce = 0; + self.b_mock + .execute_esdt_transfer( + user, + &self.lp_farm_wrapper, + LP_TOKEN_ID, + 0, + &rust_biguint!(farm_token_amount), + |sc| { + let (new_farm_token, _boosted_rewards_payment) = + sc.enter_farm_endpoint(OptionalValue::None).into_tuple(); + assert_eq!( + new_farm_token.token_identifier, + managed_token_id!(LP_FARM_TOKEN_ID) + ); + assert_eq!(new_farm_token.amount, farm_token_amount); + farm_token_nonce = new_farm_token.token_nonce; + }, + ) + .assert_ok(); + + farm_token_nonce + } + + pub fn exit_lp_farm(&mut self, user: &Address, farm_token_nonce: u64, farm_token_amount: u64) { + self.b_mock + .execute_esdt_transfer( + user, + &self.lp_farm_wrapper, + LP_FARM_TOKEN_ID, + farm_token_nonce, + &rust_biguint!(farm_token_amount), + |sc| { + let (_lp_tokens, _boosted_rewards_payment) = + sc.exit_farm_endpoint(OptionalValue::None).into_tuple(); + }, + ) + .assert_ok(); + } + + pub fn claim_lp_farm( + &mut self, + user: &Address, + farm_token_nonce: u64, + farm_token_amount: u64, + expected_lp_farm_rewards: u64, + ) -> u64 { + let mut new_farm_token_nonce = 0; + self.b_mock + .execute_esdt_transfer( + user, + &self.lp_farm_wrapper, + LP_FARM_TOKEN_ID, + farm_token_nonce, + &rust_biguint!(farm_token_amount), + |sc| { + let (output_farm_token, boosted_rewards_payment) = + sc.claim_rewards_endpoint(OptionalValue::None).into_tuple(); + assert_eq!(output_farm_token.amount, farm_token_amount); + assert_eq!(boosted_rewards_payment.amount, expected_lp_farm_rewards); + new_farm_token_nonce = output_farm_token.token_nonce; + }, + ) + .assert_ok(); + + new_farm_token_nonce + } + + pub fn set_user_energy( + &mut self, + user: &Address, + energy: u64, + last_update_epoch: u64, + locked_tokens: u64, + ) { + self.b_mock + .execute_tx( + &self.owner_addr, + &self.energy_factory_wrapper, + &rust_biguint!(0), + |sc| { + sc.user_energy(&managed_address!(user)).set(&Energy::new( + BigInt::from(managed_biguint!(energy)), + last_update_epoch, + managed_biguint!(locked_tokens), + )); + }, + ) + .assert_ok(); + } + + pub fn set_lp_farm_boosted_yields_rewards_percentage( + &mut self, + boosted_yields_rewards_percentage: u64, + ) { + self.b_mock + .execute_tx( + &self.owner_addr, + &self.lp_farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.set_boosted_yields_rewards_percentage(boosted_yields_rewards_percentage); + }, + ) + .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 1635f22e0..2c67d2714 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,8 +1,10 @@ +#![allow(deprecated)] + use multiversx_sc::storage::mappers::StorageTokenWrapper; use multiversx_sc::types::{Address, EsdtLocalRole, ManagedAddress, MultiValueEncoded}; use multiversx_sc_scenario::{ managed_address, managed_biguint, managed_token_id, rust_biguint, - whitebox::{BlockchainStateWrapper, ContractObjWrapper}, + whitebox_legacy::{BlockchainStateWrapper, ContractObjWrapper}, DebugApi, }; @@ -117,6 +119,7 @@ where b_mock .execute_tx(owner_addr, &proxy_wrapper, &rust_zero, |sc| { sc.init( + managed_address!(staking_farm_address), // TODO - replace with energy factory address when needed managed_address!(lp_farm_address), managed_address!(staking_farm_address), managed_address!(pair_address), diff --git a/farm-staking/farm-staking-proxy/wasm/Cargo.lock b/farm-staking/farm-staking-proxy/wasm/Cargo.lock index 6b8cfa51d..feded38ab 100644 --- a/farm-staking/farm-staking-proxy/wasm/Cargo.lock +++ b/farm-staking/farm-staking-proxy/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common-types" @@ -99,9 +76,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "endian-type" @@ -221,10 +198,12 @@ version = "0.0.0" dependencies = [ "common_structs", "config", + "energy-query", "farm", "farm-staking", + "farm-with-locked-rewards", "fixed-supply-token", - "hex-literal", + "hex-literal 0.3.4", "mergeable", "multiversx-sc", "multiversx-sc-modules", @@ -245,6 +224,36 @@ dependencies = [ "multiversx-sc-wasm-adapter", ] +[[package]] +name = "farm-with-locked-rewards" +version = "0.0.0" +dependencies = [ + "common_errors", + "common_structs", + "config", + "contexts", + "energy-factory", + "energy-query", + "events", + "farm", + "farm-boosted-yields", + "farm_base_impl", + "farm_token", + "fixed-supply-token", + "locking_module", + "mergeable", + "multiversx-sc", + "multiversx-sc-modules", + "pausable", + "permissions_module", + "rewards", + "sc_whitelist_module", + "token_send", + "utils", + "week-timekeeping", + "weekly-rewards-splitting", +] + [[package]] name = "farm_base_impl" version = "0.0.0" @@ -306,15 +315,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -327,6 +327,12 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +[[package]] +name = "hex-literal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + [[package]] name = "itertools" version = "0.10.5" @@ -345,12 +351,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - [[package]] name = "locking_module" version = "0.0.0" @@ -367,12 +367,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -382,13 +376,12 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", - "hex-literal", + "hex-literal 0.4.1", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", @@ -396,20 +389,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -419,9 +411,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -432,21 +424,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -460,19 +451,13 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "pair" version = "0.0.0" @@ -486,6 +471,7 @@ dependencies = [ "permissions_module", "simple-lock", "token_send", + "utils", ] [[package]] @@ -507,18 +493,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -567,15 +553,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -601,9 +587,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -622,24 +608,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - [[package]] name = "week-timekeeping" version = "0.0.0" @@ -659,25 +627,3 @@ dependencies = [ "unwrappable", "week-timekeeping", ] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/farm-staking/farm-staking-proxy/wasm/Cargo.toml b/farm-staking/farm-staking-proxy/wasm/Cargo.toml index 199cb1c27..b95744497 100644 --- a/farm-staking/farm-staking-proxy/wasm/Cargo.toml +++ b/farm-staking/farm-staking-proxy/wasm/Cargo.toml @@ -1,26 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "farm-staking-proxy-wasm" version = "0.0.0" -authors = ["MultiversX "] edition = "2021" publish = false [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.farm-staking-proxy] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" -features = ["vm-validate-token-identifier"] +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/farm-staking/farm-staking-proxy/wasm/src/lib.rs b/farm-staking/farm-staking-proxy/wasm/src/lib.rs index 5aea5b134..ee8a50b10 100644 --- a/farm-staking/farm-staking-proxy/wasm/src/lib.rs +++ b/farm-staking/farm-staking-proxy/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 16 +// Endpoints: 18 // Async Callback: 1 -// Total number of exported functions: 18 +// Total number of exported functions: 20 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,22 +19,26 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { farm_staking_proxy ( - registerDualYieldToken - getDualYieldTokenId - getLpFarmAddress - getStakingFarmAddress - getPairAddress - getStakingTokenId - getFarmTokenId - getLpTokenId - getLpFarmTokenId - addSCAddressToWhitelist - removeSCAddressFromWhitelist - isSCAddressWhitelisted - stakeFarmTokens - claimDualYield - unstakeFarmTokens - mergeMetastakingWithStakingToken - callBack + init => init + upgrade => upgrade + registerDualYieldToken => register_dual_yield_token + getDualYieldTokenId => dual_yield_token + getLpFarmAddress => lp_farm_address + getStakingFarmAddress => staking_farm_address + getPairAddress => pair_address + getStakingTokenId => staking_token_id + getFarmTokenId => staking_farm_token_id + getLpTokenId => lp_token_id + getLpFarmTokenId => lp_farm_token_id + setEnergyFactoryAddress => set_energy_factory_address + getEnergyFactoryAddress => energy_factory_address + addSCAddressToWhitelist => add_sc_address_to_whitelist + removeSCAddressFromWhitelist => remove_sc_address_from_whitelist + isSCAddressWhitelisted => is_sc_address_whitelisted + stakeFarmTokens => stake_farm_tokens + claimDualYield => claim_dual_yield_endpoint + unstakeFarmTokens => unstake_farm_tokens ) } + +multiversx_sc_wasm_adapter::async_callback! { farm_staking_proxy } diff --git a/farm-staking/farm-staking/Cargo.toml b/farm-staking/farm-staking/Cargo.toml index d4d155aee..c4db81ca1 100644 --- a/farm-staking/farm-staking/Cargo.toml +++ b/farm-staking/farm-staking/Cargo.toml @@ -7,6 +7,7 @@ publish = false [lib] path = "src/lib.rs" + [dependencies.farm] path = "../../dex/farm" @@ -77,14 +78,14 @@ path = "../../common/common_structs" path = "../../common/common_errors" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" diff --git a/farm-staking/farm-staking/elrond.json b/farm-staking/farm-staking/elrond.json deleted file mode 100644 index 736553962..000000000 --- a/farm-staking/farm-staking/elrond.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "language": "rust" -} \ No newline at end of file diff --git a/farm-staking/farm-staking/meta/Cargo.toml b/farm-staking/farm-staking/meta/Cargo.toml index 24ebe7bfb..20d07fb79 100644 --- a/farm-staking/farm-staking/meta/Cargo.toml +++ b/farm-staking/farm-staking/meta/Cargo.toml @@ -4,8 +4,10 @@ version = "0.0.0" authors = ["MultiversX "] edition = "2021" publish = false + [dependencies.farm-staking] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +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 1d25e1cdc..2b671677f 100644 --- a/farm-staking/farm-staking/src/base_impl_wrapper.rs +++ b/farm-staking/farm-staking/src/base_impl_wrapper.rs @@ -5,6 +5,7 @@ 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; @@ -46,16 +47,16 @@ where pub fn calculate_boosted_rewards( sc: &::FarmSc, caller: &ManagedAddress<<::FarmSc as ContractBase>::Api>, - token_attributes: &::AttributesType, - farm_token_amount: BigUint<<::FarmSc as ContractBase>::Api>, ) -> BigUint<<::FarmSc as ContractBase>::Api> { - if &token_attributes.original_owner != caller { - sc.update_energy_and_progress(caller); + let user_total_farm_position = sc.get_user_total_farm_position(caller); + let user_farm_position = user_total_farm_position.total_farm_position; + let mut boosted_rewards = BigUint::zero(); - return BigUint::zero(); + if user_farm_position > 0 { + boosted_rewards = sc.claim_boosted_yields_rewards(caller, user_farm_position); } - sc.claim_boosted_yields_rewards(caller, farm_token_amount) + boosted_rewards } } @@ -134,12 +135,7 @@ where ) -> BigUint<::Api> { let base_farm_reward = Self::calculate_base_farm_rewards(farm_token_amount, token_attributes, storage_cache); - let boosted_yield_rewards = Self::calculate_boosted_rewards( - sc, - caller, - token_attributes, - farm_token_amount.clone(), - ); + let boosted_yield_rewards = Self::calculate_boosted_rewards(sc, caller); base_farm_reward + boosted_yield_rewards } @@ -188,4 +184,61 @@ 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_only_boosted_staking_rewards.rs b/farm-staking/farm-staking/src/claim_only_boosted_staking_rewards.rs index a41cb1249..b13ccc62d 100644 --- a/farm-staking/farm-staking/src/claim_only_boosted_staking_rewards.rs +++ b/farm-staking/farm-staking/src/claim_only_boosted_staking_rewards.rs @@ -24,28 +24,70 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: + farm_boosted_yields::boosted_yields_factors::BoostedYieldsFactorsModule + crate::custom_rewards::CustomRewardsModule { - // Cannot import the one from farm, as the Wrapper struct has different dependencies - fn claim_only_boosted_payment( - &self, - caller: &ManagedAddress, - payment: &EsdtTokenPayment, - ) -> EsdtTokenPayment { + #[endpoint(claimBoostedRewards)] + fn claim_boosted_rewards(&self, opt_user: OptionalValue) -> EsdtTokenPayment { + let caller = self.blockchain().get_caller(); + let user = match &opt_user { + OptionalValue::Some(user) => user, + OptionalValue::None => &caller, + }; + let user_total_farm_position = self.get_user_total_farm_position(user); + if user != &caller { + require!( + user_total_farm_position.allow_external_claim_boosted_rewards, + "Cannot claim rewards for this address" + ); + } + + let boosted_rewards = self.claim_only_boosted_payment(user); + let boosted_rewards_payment = + EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards); + + self.send_payment_non_zero(user, &boosted_rewards_payment); + + boosted_rewards_payment + } + + fn migrate_old_farm_positions(&self, caller: &ManagedAddress) -> BigUint { + let payments = self.call_value().all_esdt_transfers().clone_value(); let farm_token_mapper = self.farm_token(); - farm_token_mapper.require_same_token(&payment.token_identifier); - - let token_attributes = - self.get_attributes_as_part_of_fixed_supply(payment, &farm_token_mapper); - let reward = FarmStakingWrapper::::calculate_boosted_rewards( - self, - caller, - &token_attributes, - payment.amount.clone(), - ); + let farm_token_id = farm_token_mapper.get_token_id(); + let mut migrated_amount = BigUint::zero(); + for farm_position in &payments { + if farm_position.token_identifier == farm_token_id + && self.is_old_farm_position(farm_position.token_nonce) + { + migrated_amount += farm_position.amount; + } + } + + if migrated_amount > 0 { + let mut user_total_farm_position = self.get_user_total_farm_position(caller); + user_total_farm_position.total_farm_position += &migrated_amount; + self.user_total_farm_position(caller) + .set(user_total_farm_position); + } + + migrated_amount + } + + fn decrease_old_farm_positions(&self, migrated_amount: BigUint, caller: &ManagedAddress) { + if migrated_amount == BigUint::zero() { + return; + } + self.user_total_farm_position(caller) + .update(|user_total_farm_position| { + user_total_farm_position.total_farm_position -= migrated_amount; + }); + } + + // Cannot import the one from farm, as the Wrapper struct has different dependencies + fn claim_only_boosted_payment(&self, caller: &ManagedAddress) -> BigUint { + let reward = FarmStakingWrapper::::calculate_boosted_rewards(self, caller); if reward > 0 { self.reward_reserve().update(|reserve| *reserve -= &reward); } - let reward_token_id = self.reward_token_id().get(); - EsdtTokenPayment::new(reward_token_id, 0, reward) + reward } } 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 f8bef0283..e3d0b1dc4 100644 --- a/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs +++ b/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs @@ -7,6 +7,7 @@ use crate::base_impl_wrapper::FarmStakingWrapper; #[multiversx_sc::module] pub trait ClaimStakeFarmRewardsModule: crate::custom_rewards::CustomRewardsModule + + crate::claim_only_boosted_staking_rewards::ClaimOnlyBoostedStakingRewardsModule + rewards::RewardsModule + config::ConfigModule + events::EventsModule @@ -60,10 +61,11 @@ pub trait ClaimStakeFarmRewardsModule: original_caller: ManagedAddress, 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, + original_caller.clone(), ManagedVec::from_single_item(payment), ); @@ -78,6 +80,8 @@ pub trait ClaimStakeFarmRewardsModule: self.set_farm_supply_for_current_week(&claim_result.storage_cache.farm_token_supply); } + self.update_energy_and_progress(&original_caller); + let new_farm_token_nonce = self.send().esdt_nft_create_compact( &virtual_farm_token.payment.token_identifier, &virtual_farm_token.payment.amount, 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 e51f3b66e..a7d83d574 100644 --- a/farm-staking/farm-staking/src/compound_stake_farm_rewards.rs +++ b/farm-staking/farm-staking/src/compound_stake_farm_rewards.rs @@ -5,6 +5,7 @@ multiversx_sc::imports!(); #[multiversx_sc::module] pub trait CompoundStakeFarmRewardsModule: crate::custom_rewards::CustomRewardsModule + + crate::claim_only_boosted_staking_rewards::ClaimOnlyBoostedStakingRewardsModule + rewards::RewardsModule + config::ConfigModule + events::EventsModule @@ -32,6 +33,7 @@ pub trait CompoundStakeFarmRewardsModule: #[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); diff --git a/farm-staking/farm-staking/src/custom_rewards.rs b/farm-staking/farm-staking/src/custom_rewards.rs index 64bf431ee..4d07dd5a4 100644 --- a/farm-staking/farm-staking/src/custom_rewards.rs +++ b/farm-staking/farm-staking/src/custom_rewards.rs @@ -9,7 +9,9 @@ use crate::base_impl_wrapper::FarmStakingWrapper; pub const MAX_PERCENT: u64 = 10_000; pub const BLOCKS_IN_YEAR: u64 = 31_536_000 / 6; // seconds_in_year / 6_seconds_per_block -const MAX_MIN_UNBOND_EPOCHS: u64 = 30; +pub const MAX_MIN_UNBOND_EPOCHS: u64 = 30; +pub const WITHDRAW_AMOUNT_TOO_HIGH: &str = + "Withdraw amount is higher than the remaining uncollected rewards!"; #[multiversx_sc::module] pub trait CustomRewardsModule: @@ -17,6 +19,7 @@ pub trait CustomRewardsModule: + config::ConfigModule + token_send::TokenSendModule + farm_token::FarmTokenModule + + utils::UtilsModule + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule @@ -42,6 +45,36 @@ pub trait CustomRewardsModule: self.reward_capacity().update(|r| *r += payment_amount); } + #[payable("*")] + #[endpoint(withdrawRewards)] + fn withdraw_rewards(&self, withdraw_amount: BigUint) { + self.require_caller_has_admin_permissions(); + + let mut storage_cache = StorageCache::new(self); + FarmStakingWrapper::::generate_aggregated_rewards(self, &mut storage_cache); + + let reward_capacity_mapper = self.reward_capacity(); + let accumulated_rewards_mapper = self.accumulated_rewards(); + let remaining_rewards = reward_capacity_mapper.get() - accumulated_rewards_mapper.get(); + require!( + withdraw_amount <= remaining_rewards, + WITHDRAW_AMOUNT_TOO_HIGH + ); + + reward_capacity_mapper.update(|rewards| { + require!( + *rewards >= withdraw_amount, + "Not enough rewards to withdraw" + ); + + *rewards -= withdraw_amount.clone() + }); + + let caller = self.blockchain().get_caller(); + let reward_token_id = self.reward_token_id().get(); + self.send_tokens_non_zero(&caller, &reward_token_id, 0, &withdraw_amount); + } + #[endpoint(endProduceRewards)] fn end_produce_rewards(&self) { self.require_caller_has_admin_permissions(); diff --git a/farm-staking/farm-staking/src/lib.rs b/farm-staking/farm-staking/src/lib.rs index d1874d0b4..e517d2aa6 100644 --- a/farm-staking/farm-staking/src/lib.rs +++ b/farm-staking/farm-staking/src/lib.rs @@ -2,14 +2,17 @@ #![allow(clippy::from_over_into)] #![feature(trait_alias)] +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + use base_impl_wrapper::FarmStakingWrapper; use contexts::storage_cache::StorageCache; +use farm::base_functions::DoubleMultiPayment; use farm_base_impl::base_traits_impl::FarmContract; use fixed_supply_token::FixedSupplyToken; use token_attributes::StakingFarmTokenAttributes; -multiversx_sc::imports!(); -multiversx_sc::derive_imports!(); +use crate::custom_rewards::MAX_MIN_UNBOND_EPOCHS; pub mod base_impl_wrapper; pub mod claim_only_boosted_staking_rewards; @@ -40,7 +43,6 @@ pub trait FarmStaking: + farm_base_impl::claim_rewards::BaseClaimRewardsModule + farm_base_impl::compound_rewards::BaseCompoundRewardsModule + farm_base_impl::exit_farm::BaseExitFarmModule - + farm::progress_update::ProgressUpdateModule + utils::UtilsModule + farm_token_roles::FarmTokenRolesModule + stake_farm::StakeFarmModule @@ -79,16 +81,41 @@ pub trait FarmStaking: ); require!(max_apr > 0u64, "Invalid max APR percentage"); - self.max_annual_percentage_rewards().set(&max_apr); + self.max_annual_percentage_rewards().set_if_empty(&max_apr); - self.try_set_min_unbond_epochs(min_unbond_epochs); + require!( + min_unbond_epochs <= MAX_MIN_UNBOND_EPOCHS, + "Invalid min unbond epochs" + ); + self.min_unbond_epochs().set_if_empty(min_unbond_epochs); + + let current_epoch = self.blockchain().get_block_epoch(); + self.first_week_start_epoch().set_if_empty(current_epoch); + + // Farm position migration code + let farm_token_mapper = self.farm_token(); + self.try_set_farm_position_migration_nonce(farm_token_mapper); + } + + #[endpoint] + fn upgrade(&self) { + let current_epoch = self.blockchain().get_block_epoch(); + self.first_week_start_epoch().set_if_empty(current_epoch); + + // Farm position migration code + let farm_token_mapper = self.farm_token(); + self.try_set_farm_position_migration_nonce(farm_token_mapper); } #[payable("*")] #[endpoint(mergeFarmTokens)] - fn merge_farm_tokens_endpoint(&self) -> EsdtTokenPayment { + fn merge_farm_tokens_endpoint(&self) -> DoubleMultiPayment { let caller = self.blockchain().get_caller(); - self.check_claim_progress_for_merge(&caller); + self.migrate_old_farm_positions(&caller); + + let boosted_rewards = self.claim_only_boosted_payment(&caller); + 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(); @@ -98,8 +125,9 @@ pub trait FarmStaking: 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 + (merged_farm_token, boosted_rewards_payment).into() } #[view(calculateRewardsForGivenPosition)] diff --git a/farm-staking/farm-staking/src/stake_farm.rs b/farm-staking/farm-staking/src/stake_farm.rs index a50dca4b8..7ab3dea1c 100644 --- a/farm-staking/farm-staking/src/stake_farm.rs +++ b/farm-staking/farm-staking/src/stake_farm.rs @@ -46,7 +46,7 @@ pub trait StakeFarmModule: let staked_token_simulated_payment = EsdtTokenPayment::new(staked_token_id, 0, staked_token_amount); - let farm_tokens = self.call_value().all_esdt_transfers(); + let farm_tokens = self.call_value().all_esdt_transfers().clone_value(); let mut payments = ManagedVec::from_single_item(staked_token_simulated_payment); payments.append_vec(farm_tokens); @@ -71,22 +71,23 @@ pub trait StakeFarmModule: original_caller: ManagedAddress, payments: PaymentsVec, ) -> EnterFarmResultType { - let first_additional_payment_index = 1; - let boosted_rewards = match payments.try_get(first_additional_payment_index) { - Some(p) => self.claim_only_boosted_payment(&original_caller, &p), - None => EsdtTokenPayment::new(self.reward_token_id().get(), 0, BigUint::zero()), - }; + let caller = self.blockchain().get_caller(); + self.migrate_old_farm_positions(&original_caller); + let boosted_rewards = self.claim_only_boosted_payment(&original_caller); + let boosted_rewards_payment = + EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards); let enter_result = - self.enter_farm_base::>(original_caller, payments); + self.enter_farm_base::>(original_caller.clone(), payments); - let caller = self.blockchain().get_caller(); let new_farm_token = enter_result.new_farm_token.payment.clone(); self.send_payment_non_zero(&caller, &new_farm_token); - self.send_payment_non_zero(&caller, &boosted_rewards); + self.send_payment_non_zero(&caller, &boosted_rewards_payment); self.set_farm_supply_for_current_week(&enter_result.storage_cache.farm_token_supply); + self.update_energy_and_progress(&original_caller); + self.emit_enter_farm_event( &caller, enter_result.context.farming_token_payment, @@ -95,6 +96,6 @@ pub trait StakeFarmModule: enter_result.storage_cache, ); - (new_farm_token, boosted_rewards).into() + (new_farm_token, boosted_rewards_payment).into() } } diff --git a/farm-staking/farm-staking/src/unstake_farm.rs b/farm-staking/farm-staking/src/unstake_farm.rs index 4c9675153..e40642b4f 100644 --- a/farm-staking/farm-staking/src/unstake_farm.rs +++ b/farm-staking/farm-staking/src/unstake_farm.rs @@ -1,7 +1,6 @@ multiversx_sc::imports!(); use farm::ExitFarmWithPartialPosResultType; -use mergeable::Mergeable; use crate::{base_impl_wrapper::FarmStakingWrapper, token_attributes::UnbondSftAttributes}; @@ -36,21 +35,19 @@ pub trait UnstakeFarmModule: #[endpoint(unstakeFarm)] fn unstake_farm( &self, - exit_amount: BigUint, opt_original_caller: OptionalValue, ) -> ExitFarmWithPartialPosResultType { let caller = self.blockchain().get_caller(); let original_caller = self.get_orig_caller_from_opt(&caller, opt_original_caller); let payment = self.call_value().single_esdt(); - self.unstake_farm_common(original_caller, payment, exit_amount, None) + self.unstake_farm_common(original_caller, payment, None) } #[payable("*")] #[endpoint(unstakeFarmThroughProxy)] fn unstake_farm_through_proxy( &self, - exit_amount: BigUint, original_caller: ManagedAddress, ) -> ExitFarmWithPartialPosResultType { let caller = self.blockchain().get_caller(); @@ -66,41 +63,21 @@ pub trait UnstakeFarmModule: "Invalid staking token received" ); - self.unstake_farm_common( - original_caller, - second_payment, - exit_amount, - Some(first_payment.amount), - ) + self.unstake_farm_common(original_caller, second_payment, Some(first_payment.amount)) } fn unstake_farm_common( &self, original_caller: ManagedAddress, - mut payment: EsdtTokenPayment, - exit_amount: BigUint, + payment: EsdtTokenPayment, opt_unbond_amount: Option, ) -> ExitFarmWithPartialPosResultType { - require!( - payment.amount >= exit_amount, - "Exit amount is bigger than the payment amount" - ); - - let boosted_rewards_full_position = - self.claim_only_boosted_payment(&original_caller, &payment); - let remaining_farm_payment = EsdtTokenPayment::new( - payment.token_identifier.clone(), - payment.token_nonce, - &payment.amount - &exit_amount, - ); - - payment.amount = exit_amount; + let migrated_amount = self.migrate_old_farm_positions(&original_caller); - let mut exit_result = + let exit_result = self.exit_farm_base::>(original_caller.clone(), payment); - exit_result - .reward_payment - .merge_with(boosted_rewards_full_position); + + self.decrease_old_farm_positions(migrated_amount, &original_caller); let unbond_token_amount = opt_unbond_amount.unwrap_or(exit_result.farming_token_payment.amount); @@ -111,9 +88,8 @@ pub trait UnstakeFarmModule: self.create_and_send_unbond_tokens(&caller, farm_token_id, unbond_token_amount); self.send_payment_non_zero(&caller, &exit_result.reward_payment); - self.send_payment_non_zero(&caller, &remaining_farm_payment); - self.clear_user_energy_if_needed(&original_caller, &remaining_farm_payment.amount); + self.clear_user_energy_if_needed(&original_caller); self.set_farm_supply_for_current_week(&exit_result.storage_cache.farm_token_supply); self.emit_exit_farm_event( @@ -124,12 +100,7 @@ pub trait UnstakeFarmModule: exit_result.storage_cache, ); - ( - unbond_farm_token, - exit_result.reward_payment, - remaining_farm_payment, - ) - .into() + (unbond_farm_token, exit_result.reward_payment).into() } fn create_and_send_unbond_tokens( 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 d7afaf744..230d84747 100644 --- a/farm-staking/farm-staking/tests/farm_staking_energy_test.rs +++ b/farm-staking/farm-staking/tests/farm_staking_energy_test.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + pub mod farm_staking_setup; use farm_staking::{ claim_stake_farm_rewards::ClaimStakeFarmRewardsModule, stake_farm::StakeFarmModule, @@ -5,7 +7,7 @@ use farm_staking::{ }; use farm_staking_setup::*; use multiversx_sc::codec::multi_types::OptionalValue; -use multiversx_sc_scenario::{managed_biguint, rust_biguint, DebugApi}; +use multiversx_sc_scenario::{rust_biguint, DebugApi}; #[test] fn farm_staking_with_energy_setup_test() { @@ -18,7 +20,7 @@ fn farm_staking_with_energy_setup_test() { #[test] fn farm_staking_boosted_rewards_no_energy_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut fs_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); @@ -54,7 +56,7 @@ fn farm_staking_boosted_rewards_no_energy_test() { #[test] fn farm_staking_boosted_rewards_with_energy_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut fs_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); @@ -119,7 +121,7 @@ fn farm_staking_boosted_rewards_with_energy_test() { 3, &rust_biguint!(10), |sc| { - let _ = sc.unstake_farm(managed_biguint!(10), OptionalValue::None); + let _ = sc.unstake_farm(OptionalValue::None); }, ) .assert_ok(); @@ -148,3 +150,209 @@ fn farm_staking_boosted_rewards_with_energy_test() { ); fs_setup.check_farm_token_supply(farm_in_amount); } + +#[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); + + 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 = 100_000_000; + fs_setup.stake_farm(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, + &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, + 3, + &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); + + // 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); + + // 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(), + &rand_user, + expected_boosted_reward_token_out, + &expected_farming_token_balance, + ); + fs_setup.check_farm_token_supply(farm_in_amount); +} + +#[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); + + 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); + + // 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( + farm_in_amount, + 2, + expected_base_rewards + expected_boosted_rewards, + &expected_farming_token_balance, + &expected_farming_token_balance, + 6, + expected_reward_per_share, + ); + + // Should receive half base rewards and no boosted rewards + expected_farming_token_balance += expected_base_rewards; + fs_setup.claim_rewards( + farm_in_amount, + 3, + expected_base_rewards, + &expected_farming_token_balance, + &expected_farming_token_balance, + 7, + expected_reward_per_share, + ); + fs_setup.check_farm_token_supply(farm_in_amount * 2); +} 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 0ad97a738..d8cfc9a46 100644 --- a/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs +++ b/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs @@ -1,9 +1,12 @@ +#![allow(deprecated)] + +use farm_staking::claim_only_boosted_staking_rewards::ClaimOnlyBoostedStakingRewardsModule; use multiversx_sc::codec::multi_types::OptionalValue; use multiversx_sc::storage::mappers::StorageTokenWrapper; use multiversx_sc::types::{Address, BigInt, EsdtLocalRole, ManagedAddress, MultiValueEncoded}; -use multiversx_sc_scenario::whitebox::TxTokenTransfer; +use multiversx_sc_scenario::whitebox_legacy::TxTokenTransfer; use multiversx_sc_scenario::{ - managed_address, managed_biguint, managed_token_id, rust_biguint, whitebox::*, DebugApi, + managed_address, managed_biguint, managed_token_id, rust_biguint, whitebox_legacy::*, DebugApi, }; pub type RustBigUint = num_bigint::BigUint; @@ -40,6 +43,8 @@ pub const USER_REWARDS_ENERGY_CONST: u64 = 3; pub const USER_REWARDS_FARM_CONST: u64 = 2; pub const MIN_ENERGY_AMOUNT_FOR_BOOSTED_YIELDS: u64 = 1; pub const MIN_FARM_AMOUNT_FOR_BOOSTED_YIELDS: u64 = 1; +pub const WITHDRAW_AMOUNT_TOO_HIGH: &str = + "Withdraw amount is higher than the remaining uncollected rewards!"; pub struct FarmStakingSetup where @@ -274,6 +279,37 @@ where ); } + pub fn claim_boosted_rewards_for_user( + &mut self, + owner: &Address, + broker: &Address, + expected_reward_token_out: u64, + expected_user_reward_token_balance: &RustBigUint, + ) { + self.b_mock + .execute_tx(broker, &self.farm_wrapper, &rust_biguint!(0u64), |sc| { + let payment_result = + sc.claim_boosted_rewards(OptionalValue::Some(managed_address!(owner))); + + assert_eq!( + payment_result.token_identifier, + managed_token_id!(REWARD_TOKEN_ID) + ); + assert_eq!(payment_result.token_nonce, 0); + assert_eq!( + payment_result.amount, + managed_biguint!(expected_reward_token_out) + ); + }) + .assert_ok(); + + self.b_mock.check_esdt_balance( + &self.user_address, + REWARD_TOKEN_ID, + expected_user_reward_token_balance, + ); + } + #[allow(clippy::too_many_arguments)] pub fn unstake_farm( &mut self, @@ -294,10 +330,9 @@ where farm_token_nonce, &rust_biguint!(farm_token_amount), |sc| { - let multi_result = - sc.unstake_farm(managed_biguint!(farm_token_amount), OptionalValue::None); + let multi_result = sc.unstake_farm(OptionalValue::None); - let (first_result, second_result, _) = multi_result.into_tuple(); + let (first_result, second_result) = multi_result.into_tuple(); assert_eq!( first_result.token_identifier, @@ -383,6 +418,30 @@ where .assert_ok(); } + pub fn check_rewards_capacity(&mut self, expected_farm_token_supply: u64) { + self.b_mock + .execute_query(&self.farm_wrapper, |sc| { + let actual_farm_supply = sc.reward_capacity().get(); + assert_eq!( + managed_biguint!(expected_farm_token_supply), + actual_farm_supply + ); + }) + .assert_ok(); + } + + pub fn allow_external_claim_rewards(&mut self, user: &Address) { + 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; + }, + ); + }) + .assert_ok(); + } + pub fn set_block_nonce(&mut self, block_nonce: u64) { self.b_mock.set_block_nonce(block_nonce); } @@ -445,4 +504,35 @@ where ) .assert_ok(); } + + pub fn withdraw_rewards(&mut self, withdraw_amount: &RustBigUint) { + self.b_mock + .execute_tx( + &self.owner_address, + &self.farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.withdraw_rewards(withdraw_amount.into()); + }, + ) + .assert_ok(); + } + + pub fn withdraw_rewards_with_error( + &mut self, + withdraw_amount: &RustBigUint, + expected_status: u64, + expected_message: &str, + ) { + self.b_mock + .execute_tx( + &self.owner_address, + &self.farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.withdraw_rewards(withdraw_amount.into()); + }, + ) + .assert_error(expected_status, expected_message) + } } diff --git a/farm-staking/farm-staking/tests/farm_staking_test.rs b/farm-staking/farm-staking/tests/farm_staking_test.rs index 6a8eba2ae..89192a6a1 100644 --- a/farm-staking/farm-staking/tests/farm_staking_test.rs +++ b/farm-staking/farm-staking/tests/farm_staking_test.rs @@ -1,4 +1,6 @@ -use multiversx_sc_scenario::{rust_biguint, whitebox::TxTokenTransfer, DebugApi}; +#![allow(deprecated)] + +use multiversx_sc_scenario::{rust_biguint, whitebox_legacy::TxTokenTransfer, DebugApi}; pub mod farm_staking_setup; use farm_staking::{ @@ -14,7 +16,7 @@ fn test_farm_setup() { #[test] fn test_enter_farm() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); @@ -26,7 +28,7 @@ fn test_enter_farm() { #[test] fn test_unstake_farm() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); @@ -68,7 +70,7 @@ fn test_unstake_farm() { #[test] fn test_claim_rewards() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); @@ -145,13 +147,13 @@ where #[test] fn test_enter_farm_twice() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let _ = steps_enter_farm_twice(farm_staking::contract_obj, energy_factory::contract_obj); } #[test] fn test_exit_farm_after_enter_twice() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = steps_enter_farm_twice(farm_staking::contract_obj, energy_factory::contract_obj); let farm_in_amount = 100_000_000; @@ -181,7 +183,7 @@ fn test_exit_farm_after_enter_twice() { #[test] fn test_unbond() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut farm_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); @@ -229,3 +231,50 @@ fn test_unbond() { USER_TOTAL_RIDE_TOKENS + expected_rewards, ); } + +#[test] +fn test_withdraw_rewards() { + DebugApi::dummy(); + let mut farm_setup = + FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + + let initial_rewards_capacity = 1_000_000_000_000u64; + farm_setup.check_rewards_capacity(initial_rewards_capacity); + + let withdraw_amount = rust_biguint!(TOTAL_REWARDS_AMOUNT); + farm_setup.withdraw_rewards(&withdraw_amount); + + let final_rewards_capacity = 0u64; + farm_setup.check_rewards_capacity(final_rewards_capacity); +} + +#[test] +fn test_withdraw_after_produced_rewards() { + DebugApi::dummy(); + let mut farm_setup = + FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + + 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.check_farm_token_supply(farm_in_amount); + + farm_setup.set_block_epoch(5); + farm_setup.set_block_nonce(10); + + let withdraw_amount = rust_biguint!(TOTAL_REWARDS_AMOUNT); + farm_setup.withdraw_rewards_with_error(&withdraw_amount, 4, WITHDRAW_AMOUNT_TOO_HIGH); + + let expected_reward_token_out = 40; + + let withdraw_amount = + rust_biguint!(TOTAL_REWARDS_AMOUNT) - rust_biguint!(expected_reward_token_out); + farm_setup.withdraw_rewards(&withdraw_amount); + + // Only the user's rewards will remain + let final_rewards_capacity = expected_reward_token_out; + farm_setup.check_rewards_capacity(final_rewards_capacity); +} diff --git a/farm-staking/farm-staking/wasm/Cargo.lock b/farm-staking/farm-staking/wasm/Cargo.lock index 4584bdf1a..88d4b1bba 100644 --- a/farm-staking/farm-staking/wasm/Cargo.lock +++ b/farm-staking/farm-staking/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common-types" @@ -99,9 +76,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "endian-type" @@ -284,15 +261,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -301,9 +269,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "itertools" @@ -323,12 +291,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - [[package]] name = "locking_module" version = "0.0.0" @@ -345,12 +307,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -360,12 +316,11 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -374,20 +329,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -397,9 +351,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -410,21 +364,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -438,19 +391,13 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "pair" version = "0.0.0" @@ -464,6 +411,7 @@ dependencies = [ "permissions_module", "simple-lock", "token_send", + "utils", ] [[package]] @@ -485,18 +433,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -545,15 +493,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -579,9 +527,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -600,24 +548,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - [[package]] name = "week-timekeeping" version = "0.0.0" @@ -637,25 +567,3 @@ dependencies = [ "unwrappable", "week-timekeeping", ] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/farm-staking/farm-staking/wasm/Cargo.toml b/farm-staking/farm-staking/wasm/Cargo.toml index f8658d344..0dbb347b9 100644 --- a/farm-staking/farm-staking/wasm/Cargo.toml +++ b/farm-staking/farm-staking/wasm/Cargo.toml @@ -1,26 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "farm-staking-wasm" version = "0.0.0" -authors = ["MultiversX "] edition = "2021" publish = false [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.farm-staking] -default-features = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/farm-staking/farm-staking/wasm/src/lib.rs b/farm-staking/farm-staking/wasm/src/lib.rs index f168969c1..02de33846 100644 --- a/farm-staking/farm-staking/wasm/src/lib.rs +++ b/farm-staking/farm-staking/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 64 +// Endpoints: 71 // Async Callback: 1 -// Total number of exported functions: 66 +// Total number of exported functions: 73 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,70 +19,79 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { farm_staking ( - mergeFarmTokens - calculateRewardsForGivenPosition - topUpRewards - endProduceRewards - setPerBlockRewardAmount - setMaxApr - setMinUnbondEpochs - startProduceRewards - getAccumulatedRewards - getRewardCapacity - getAnnualPercentageRewards - getMinUnbondEpochs - getRewardPerShare - getRewardReserve - getFarmingTokenId - getRewardTokenId - getPerBlockRewardAmount - getLastRewardBlockNonce - getDivisionSafetyConstant - registerFarmToken - getFarmTokenId - getFarmTokenSupply - addSCAddressToWhitelist - removeSCAddressFromWhitelist - isSCAddressWhitelisted - addToPauseWhitelist - removeFromPauseWhitelist - pause - resume - getState - addAdmin - removeAdmin - updateOwnerOrAdmin - getPermissions - setBurnRoleForAddress - stakeFarmThroughProxy - stakeFarm - claimRewards - claimRewardsWithNewValue - compoundRewards - unstakeFarm - unstakeFarmThroughProxy - unbondFarm - setBoostedYieldsRewardsPercentage - collectUndistributedBoostedRewards - getBoostedYieldsRewardsPercentage - getAccumulatedRewardsForWeek - getFarmSupplyForWeek - getRemainingBoostedRewardsToDistribute - getUndistributedBoostedRewards - setBoostedYieldsFactors - getBoostedYieldsFactors - getCurrentWeek - getFirstWeekStartEpoch - getLastActiveWeekForUser - getUserEnergyForWeek - getLastGlobalUpdateWeek - getTotalRewardsForWeek - getTotalEnergyForWeek - getTotalLockedTokensForWeek - updateEnergyForUser - getCurrentClaimProgress - setEnergyFactoryAddress - getEnergyFactoryAddress - callBack + init => init + upgrade => upgrade + mergeFarmTokens => merge_farm_tokens_endpoint + calculateRewardsForGivenPosition => calculate_rewards_for_given_position + topUpRewards => top_up_rewards + withdrawRewards => withdraw_rewards + endProduceRewards => end_produce_rewards + setPerBlockRewardAmount => set_per_block_rewards + setMaxApr => set_max_apr + setMinUnbondEpochs => set_min_unbond_epochs_endpoint + startProduceRewards => start_produce_rewards_endpoint + getAccumulatedRewards => accumulated_rewards + getRewardCapacity => reward_capacity + getAnnualPercentageRewards => max_annual_percentage_rewards + getMinUnbondEpochs => min_unbond_epochs + getRewardPerShare => reward_per_share + getRewardReserve => reward_reserve + allowExternalClaimBoostedRewards => allow_external_claim_boosted_rewards + getAllowExternalClaimRewards => get_allow_external_claim_rewards + getFarmingTokenId => farming_token_id + getRewardTokenId => reward_token_id + getPerBlockRewardAmount => per_block_reward_amount + getLastRewardBlockNonce => last_reward_block_nonce + getDivisionSafetyConstant => division_safety_constant + getUserTotalFarmPosition => user_total_farm_position + getFarmPositionMigrationNonce => farm_position_migration_nonce + registerFarmToken => register_farm_token + getFarmTokenId => farm_token + getFarmTokenSupply => farm_token_supply + addSCAddressToWhitelist => add_sc_address_to_whitelist + removeSCAddressFromWhitelist => remove_sc_address_from_whitelist + isSCAddressWhitelisted => is_sc_address_whitelisted + addToPauseWhitelist => add_to_pause_whitelist + removeFromPauseWhitelist => remove_from_pause_whitelist + pause => pause + resume => resume + getState => state + addAdmin => add_admin_endpoint + removeAdmin => remove_admin_endpoint + updateOwnerOrAdmin => update_owner_or_admin_endpoint + getPermissions => permissions + setBurnRoleForAddress => set_burn_role_for_address + stakeFarmThroughProxy => stake_farm_through_proxy + stakeFarm => stake_farm_endpoint + claimRewards => claim_rewards + claimRewardsWithNewValue => claim_rewards_with_new_value + compoundRewards => compound_rewards + unstakeFarm => unstake_farm + unstakeFarmThroughProxy => unstake_farm_through_proxy + unbondFarm => unbond_farm + claimBoostedRewards => claim_boosted_rewards + setBoostedYieldsRewardsPercentage => set_boosted_yields_rewards_percentage + collectUndistributedBoostedRewards => collect_undistributed_boosted_rewards + getBoostedYieldsRewardsPercentage => boosted_yields_rewards_percentage + getAccumulatedRewardsForWeek => accumulated_rewards_for_week + getFarmSupplyForWeek => farm_supply_for_week + getRemainingBoostedRewardsToDistribute => remaining_boosted_rewards_to_distribute + getUndistributedBoostedRewards => undistributed_boosted_rewards + setBoostedYieldsFactors => set_boosted_yields_factors + getBoostedYieldsFactors => get_boosted_yields_factors + getCurrentWeek => get_current_week + getFirstWeekStartEpoch => first_week_start_epoch + getLastActiveWeekForUser => get_last_active_week_for_user_view + getUserEnergyForWeek => get_user_energy_for_week_view + getLastGlobalUpdateWeek => last_global_update_week + getTotalRewardsForWeek => total_rewards_for_week + getTotalEnergyForWeek => total_energy_for_week + getTotalLockedTokensForWeek => total_locked_tokens_for_week + updateEnergyForUser => update_energy_for_user + getCurrentClaimProgress => current_claim_progress + setEnergyFactoryAddress => set_energy_factory_address + getEnergyFactoryAddress => energy_factory_address ) } + +multiversx_sc_wasm_adapter::async_callback! { farm_staking } diff --git a/farm-staking/metabonding-staking/Cargo.toml b/farm-staking/metabonding-staking/Cargo.toml index 8ad683d29..de3c1ff97 100644 --- a/farm-staking/metabonding-staking/Cargo.toml +++ b/farm-staking/metabonding-staking/Cargo.toml @@ -7,12 +7,13 @@ publish = false [lib] path = "src/lib.rs" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" [dependencies.factory] path = "../../locked-asset/factory" @@ -21,7 +22,7 @@ path = "../../locked-asset/factory" num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" [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 d04874c6d..71df2c0ba 100644 --- a/farm-staking/metabonding-staking/meta/Cargo.toml +++ b/farm-staking/metabonding-staking/meta/Cargo.toml @@ -6,8 +6,10 @@ publish = false authors = ["MultiversX "] [dev-dependencies] + [dependencies.metabonding-staking] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/farm-staking/metabonding-staking/src/lib.rs b/farm-staking/metabonding-staking/src/lib.rs index 9b3387a78..94be22193 100644 --- a/farm-staking/metabonding-staking/src/lib.rs +++ b/farm-staking/metabonding-staking/src/lib.rs @@ -26,10 +26,13 @@ pub trait MetabondingStaking: .set_if_empty(&locked_asset_factory_address); } + #[endpoint] + fn upgrade(&self) {} + #[payable("*")] #[endpoint(stakeLockedAsset)] fn stake_locked_asset(&self) { - let payments = self.call_value().all_esdt_transfers(); + let payments = self.call_value().all_esdt_transfers().clone_value(); self.require_all_locked_asset_payments(&payments); let caller = self.blockchain().get_caller(); @@ -74,7 +77,7 @@ pub trait MetabondingStaking: require!(!entry_mapper.is_empty(), "Must stake first"); let mut user_entry: UserEntry = entry_mapper.get(); - let unstake_amount = user_entry.unstake_amount.clone(); + let unstake_amount = user_entry.unstake_amount; require!(unstake_amount > 0, "Must unstake first"); let current_epoch = self.blockchain().get_block_epoch(); diff --git a/farm-staking/metabonding-staking/tests/metabonding_staking_setup/mod.rs b/farm-staking/metabonding-staking/tests/metabonding_staking_setup/mod.rs index 6e7d01b4a..a4b8effeb 100644 --- a/farm-staking/metabonding-staking/tests/metabonding_staking_setup/mod.rs +++ b/farm-staking/metabonding-staking/tests/metabonding_staking_setup/mod.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + use common_structs::{ LockedAssetTokenAttributesEx, UnlockMilestone, UnlockMilestoneEx, UnlockScheduleEx, }; @@ -7,9 +9,9 @@ use metabonding_staking::MetabondingStaking; use multiversx_sc::storage::mappers::StorageTokenWrapper; use multiversx_sc::types::{Address, EsdtLocalRole, ManagedVec}; use multiversx_sc_modules::pause::PauseModule; -use multiversx_sc_scenario::whitebox::{TxResult, TxTokenTransfer}; +use multiversx_sc_scenario::whitebox_legacy::{TxResult, TxTokenTransfer}; use multiversx_sc_scenario::{ - managed_address, managed_biguint, managed_token_id, rust_biguint, whitebox::*, DebugApi, + managed_address, managed_biguint, managed_token_id, rust_biguint, whitebox_legacy::*, DebugApi, }; pub const METABONDING_STAKING_WASM_PATH: &str = "1.wasm"; @@ -45,7 +47,7 @@ where mbs_builder: MetabondingStakingObjBuilder, laf_builder: LockedAssetFactoryObjBuilder, ) -> Self { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0u64); let mut b_mock = BlockchainStateWrapper::new(); diff --git a/farm-staking/metabonding-staking/tests/metabonding_staking_test.rs b/farm-staking/metabonding-staking/tests/metabonding_staking_test.rs index cc084e495..c83be6726 100644 --- a/farm-staking/metabonding-staking/tests/metabonding_staking_test.rs +++ b/farm-staking/metabonding-staking/tests/metabonding_staking_test.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + pub mod metabonding_staking_setup; use metabonding_staking::{ locked_asset_token::{LockedAssetTokenModule, UserEntry}, @@ -5,7 +7,7 @@ use metabonding_staking::{ }; use metabonding_staking_setup::*; use multiversx_sc_scenario::{ - managed_address, managed_biguint, rust_biguint, whitebox::TxTokenTransfer, + managed_address, managed_biguint, rust_biguint, whitebox_legacy::TxTokenTransfer, }; #[test] diff --git a/farm-staking/metabonding-staking/wasm/Cargo.lock b/farm-staking/metabonding-staking/wasm/Cargo.lock index dbb5e6cc5..739fec429 100644 --- a/farm-staking/metabonding-staking/wasm/Cargo.lock +++ b/farm-staking/metabonding-staking/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "cfg-if" @@ -37,12 +26,6 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - [[package]] name = "common_errors" version = "0.0.0" @@ -63,9 +46,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "endian-type" @@ -112,15 +95,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -129,9 +103,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "itertools" @@ -153,9 +127,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.139" +version = "0.2.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" [[package]] name = "math" @@ -196,12 +170,11 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -210,20 +183,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -233,9 +205,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -246,21 +218,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -274,33 +245,27 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -334,15 +299,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -368,9 +333,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -389,19 +354,13 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - [[package]] name = "wee_alloc" version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" dependencies = [ - "cfg-if 0.1.10", + "cfg-if", "libc", "memory_units", "winapi", diff --git a/farm-staking/metabonding-staking/wasm/Cargo.toml b/farm-staking/metabonding-staking/wasm/Cargo.toml index b979245b8..fe2a7c6c2 100644 --- a/farm-staking/metabonding-staking/wasm/Cargo.toml +++ b/farm-staking/metabonding-staking/wasm/Cargo.toml @@ -1,25 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "metabonding-staking-wasm" version = "0.0.0" -authors = ["MultiversX "] edition = "2021" publish = false [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.metabonding-staking] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/farm-staking/metabonding-staking/wasm/src/lib.rs b/farm-staking/metabonding-staking/wasm/src/lib.rs index 337c0ea4b..b8e948d22 100644 --- a/farm-staking/metabonding-staking/wasm/src/lib.rs +++ b/farm-staking/metabonding-staking/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 10 +// Endpoints: 11 // Async Callback (empty): 1 -// Total number of exported functions: 12 +// Total number of exported functions: 13 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,17 +19,19 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { metabonding_staking ( - stakeLockedAsset - unstake - unbond - getStakedAmountForUser - getUserEntry - getSnapshot - getLockedAssetTokenId - getLockedAssetFactoryAddress - getTotalLockedAssetSupply - getUserList + init => init + upgrade => upgrade + stakeLockedAsset => stake_locked_asset + unstake => unstake + unbond => unbond + getStakedAmountForUser => get_staked_amount_for_user + getUserEntry => get_user_entry + getSnapshot => get_snapshot + getLockedAssetTokenId => locked_asset_token_id + getLockedAssetFactoryAddress => locked_asset_factory_address + getTotalLockedAssetSupply => total_locked_asset_supply + getUserList => user_list ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/locked-asset/Cargo.toml b/locked-asset/Cargo.toml index 4dd7afd2e..d7ba66a4c 100644 --- a/locked-asset/Cargo.toml +++ b/locked-asset/Cargo.toml @@ -3,8 +3,9 @@ name = "distribution-tests" version = "0.0.0" edition = "2021" publish = false + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.farm] @@ -49,7 +50,7 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" diff --git a/locked-asset/distribution/Cargo.toml b/locked-asset/distribution/Cargo.toml index 991eb324d..3ebf0939b 100644 --- a/locked-asset/distribution/Cargo.toml +++ b/locked-asset/distribution/Cargo.toml @@ -6,6 +6,7 @@ version = "0.0.0" [lib] path = "src/lib.rs" + [dependencies.common_structs] path = "../../common/common_structs" @@ -13,7 +14,8 @@ path = "../../common/common_structs" path = "../factory" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] + [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" diff --git a/locked-asset/distribution/README.md b/locked-asset/distribution/README.md index 2831173de..3dee590d8 100644 --- a/locked-asset/distribution/README.md +++ b/locked-asset/distribution/README.md @@ -5,11 +5,11 @@ The bigger picture about what a Distribution Contract can do can be found in the ## Deployment -The Distribution contract can be deployed using `erdpy` and using the interaction snippets. +The Distribution contract can be deployed using `mxpy` and using the interaction snippets. The init parameters are: -- __asset_token_id__. The TokenId of the asset that a locked asset represents. In case of Maiar Exchange it will be MEX. +- __asset_token_id__. The TokenId of the asset that a locked asset represents. In case of xExchange it will be MEX. - __locked_asset_factory_address__. ManagedAddress of the locked asset factory which is used to request creation of Locked MEX tokens. diff --git a/locked-asset/distribution/meta/Cargo.toml b/locked-asset/distribution/meta/Cargo.toml index 312beb6bf..76c13747b 100644 --- a/locked-asset/distribution/meta/Cargo.toml +++ b/locked-asset/distribution/meta/Cargo.toml @@ -4,8 +4,10 @@ version = "0.0.0" authors = ["MultiversX "] edition = "2021" publish = false + [dependencies.distribution] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/locked-asset/distribution/src/lib.rs b/locked-asset/distribution/src/lib.rs index 1ae78b009..93187154e 100644 --- a/locked-asset/distribution/src/lib.rs +++ b/locked-asset/distribution/src/lib.rs @@ -47,6 +47,9 @@ pub trait Distribution: global_op::GlobalOperationModule { .set_if_empty(&locked_asset_factory_address); } + #[endpoint] + fn upgrade(&self) {} + #[only_owner] #[endpoint(setCommunityDistribution)] fn set_community_distribution(&self, total_amount: BigUint, spread_epoch: u64) { diff --git a/locked-asset/distribution/wasm/Cargo.lock b/locked-asset/distribution/wasm/Cargo.lock index e1cc0fc9e..fce0d3ebe 100644 --- a/locked-asset/distribution/wasm/Cargo.lock +++ b/locked-asset/distribution/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "cfg-if" @@ -37,12 +26,6 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - [[package]] name = "common_errors" version = "0.0.0" @@ -80,9 +63,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "endian-type" @@ -129,15 +112,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -146,9 +120,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "itertools" @@ -170,9 +144,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.139" +version = "0.2.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" [[package]] name = "math" @@ -196,12 +170,11 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -210,20 +183,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -233,9 +205,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -246,21 +218,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -274,33 +245,27 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -334,15 +299,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -368,9 +333,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -389,19 +354,13 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - [[package]] name = "wee_alloc" version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" dependencies = [ - "cfg-if 0.1.10", + "cfg-if", "libc", "memory_units", "winapi", diff --git a/locked-asset/distribution/wasm/Cargo.toml b/locked-asset/distribution/wasm/Cargo.toml index 616dccf1b..f1cc0ae57 100644 --- a/locked-asset/distribution/wasm/Cargo.toml +++ b/locked-asset/distribution/wasm/Cargo.toml @@ -1,26 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "distribution-wasm" version = "0.0.0" -authors = ["MultiversX "] edition = "2021" publish = false [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.distribution] -default-features = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/locked-asset/distribution/wasm/src/lib.rs b/locked-asset/distribution/wasm/src/lib.rs index 829e87945..87c728bb7 100644 --- a/locked-asset/distribution/wasm/src/lib.rs +++ b/locked-asset/distribution/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 15 +// Endpoints: 16 // Async Callback (empty): 1 -// Total number of exported functions: 17 +// Total number of exported functions: 18 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,22 +19,24 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { distribution ( - setCommunityDistribution - setPerUserDistributedLockedAssets - claimLockedAssets - clearUnclaimableAssets - undoLastCommunityDistribution - undoUserDistributedAssetsBetweenEpochs - setUnlockPeriod - calculateLockedAssets - deleteUserDistributedLockedAssets - getUsersDistributedLockedAssetsLength - getUnlockPeriod - getCommunityDistributionList - getAssetTokenId - startGlobalOperation - endGlobalOperation + init => init + upgrade => upgrade + setCommunityDistribution => set_community_distribution + setPerUserDistributedLockedAssets => set_per_user_distributed_locked_assets + claimLockedAssets => claim_locked_assets + clearUnclaimableAssets => clear_unclaimable_assets + undoLastCommunityDistribution => undo_last_community_distrib + undoUserDistributedAssetsBetweenEpochs => undo_user_assets_between_epochs + setUnlockPeriod => set_unlock_period + calculateLockedAssets => calculate_locked_assets_view + deleteUserDistributedLockedAssets => delete_user_distributed_locked_assets + getUsersDistributedLockedAssetsLength => get_users_distributed_locked_assets_length + getUnlockPeriod => unlock_period + getCommunityDistributionList => community_distribution_list + getAssetTokenId => asset_token_id + startGlobalOperation => global_op_start + endGlobalOperation => global_op_stop ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/locked-asset/energy-factory/Cargo.toml b/locked-asset/energy-factory/Cargo.toml index cad9fd46f..74e3cbea9 100644 --- a/locked-asset/energy-factory/Cargo.toml +++ b/locked-asset/energy-factory/Cargo.toml @@ -7,6 +7,7 @@ publish = false [lib] path = "src/lib.rs" + [dependencies.simple-lock] path = "../simple-lock" @@ -32,11 +33,11 @@ path = "../../common/traits/unwrappable" path = "../../common/modules/legacy_token_decode_module" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" [dev-dependencies] num-bigint = "0.4.2" @@ -44,4 +45,4 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" diff --git a/locked-asset/energy-factory/elrond.json b/locked-asset/energy-factory/elrond.json deleted file mode 100644 index 736553962..000000000 --- a/locked-asset/energy-factory/elrond.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "language": "rust" -} \ No newline at end of file diff --git a/locked-asset/energy-factory/meta/Cargo.toml b/locked-asset/energy-factory/meta/Cargo.toml index 3ad6bc83d..6365191f0 100644 --- a/locked-asset/energy-factory/meta/Cargo.toml +++ b/locked-asset/energy-factory/meta/Cargo.toml @@ -6,8 +6,10 @@ publish = false authors = ["MultiversX "] [dev-dependencies] + [dependencies.energy-factory] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/locked-asset/energy-factory/src/lib.rs b/locked-asset/energy-factory/src/lib.rs index 0b79aa0d7..d146566d6 100644 --- a/locked-asset/energy-factory/src/lib.rs +++ b/locked-asset/energy-factory/src/lib.rs @@ -91,6 +91,9 @@ pub trait SimpleLockEnergy: self.set_paused(true); } + #[endpoint] + fn upgrade(&self) {} + /// Locks a whitelisted token until `unlock_epoch` and receive meta ESDT LOCKED tokens /// on a 1:1 ratio. Accepted input tokens: /// - base asset token @@ -118,7 +121,6 @@ pub trait SimpleLockEnergy: let dest_address = self.dest_from_optional(opt_destination); let current_epoch = self.blockchain().get_block_epoch(); let unlock_epoch = self.unlock_epoch_to_start_of_month(current_epoch + lock_epochs); - require!( unlock_epoch > current_epoch, "Unlock epoch must be greater than the current epoch" @@ -184,4 +186,48 @@ pub trait SimpleLockEnergy: output_payment } + + /// Used internally by proxy-dex + #[payable("*")] + #[endpoint(extendLockPeriod)] + fn extend_lock_period(&self, lock_epochs: Epoch, user: ManagedAddress) -> EsdtTokenPayment { + self.require_not_paused(); + self.require_is_listed_lock_option(lock_epochs); + + let caller = self.blockchain().get_caller(); + require!( + self.token_transfer_whitelist().contains(&caller), + "May not call this endpoint. Use lockTokens instead" + ); + + let payment = self.call_value().single_esdt(); + self.locked_token() + .require_same_token(&payment.token_identifier); + + let current_epoch = self.blockchain().get_block_epoch(); + let unlock_epoch = self.unlock_epoch_to_start_of_month(current_epoch + lock_epochs); + require!( + unlock_epoch > current_epoch, + "Unlock epoch must be greater than the current epoch" + ); + + let output_tokens = self.update_energy(&user, |energy: &mut Energy| { + self.extend_new_token_period(payment.clone(), unlock_epoch, current_epoch, energy) + }); + + self.send().esdt_local_burn( + &payment.token_identifier, + payment.token_nonce, + &payment.amount, + ); + + self.send().direct_esdt( + &caller, + &output_tokens.token_identifier, + output_tokens.token_nonce, + &output_tokens.amount, + ); + + output_tokens + } } diff --git a/locked-asset/energy-factory/src/lock_options.rs b/locked-asset/energy-factory/src/lock_options.rs index 4c9be44e5..2237d2f92 100644 --- a/locked-asset/energy-factory/src/lock_options.rs +++ b/locked-asset/energy-factory/src/lock_options.rs @@ -44,6 +44,9 @@ pub trait LockOptionsModule { fn unlock_epoch_to_start_of_month_upper_estimate(&self, unlock_epoch: Epoch) -> Epoch { let lower_bound_unlock = self.unlock_epoch_to_start_of_month(unlock_epoch); + if unlock_epoch == lower_bound_unlock { + return lower_bound_unlock; + } let new_unlock_epoch = lower_bound_unlock + EPOCHS_PER_MONTH; let current_epoch = self.blockchain().get_block_epoch(); if current_epoch >= new_unlock_epoch { diff --git a/locked-asset/energy-factory/src/token_merging.rs b/locked-asset/energy-factory/src/token_merging.rs index e6b683206..36470c70d 100644 --- a/locked-asset/energy-factory/src/token_merging.rs +++ b/locked-asset/energy-factory/src/token_merging.rs @@ -1,6 +1,8 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); +use multiversx_sc::api::BlockchainApi; + use common_structs::PaymentsVec; use math::weighted_average_round_up; use mergeable::Mergeable; 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 e44ac9fc5..de10068c0 100644 --- a/locked-asset/energy-factory/tests/energy_factory_setup/mod.rs +++ b/locked-asset/energy-factory/tests/energy_factory_setup/mod.rs @@ -1,4 +1,5 @@ #![allow(dead_code)] +#![allow(deprecated)] pub mod unbond_sc_mock; @@ -14,8 +15,8 @@ use multiversx_sc::{ use multiversx_sc_modules::pause::PauseModule; use multiversx_sc_scenario::{ managed_address, managed_biguint, managed_token_id, rust_biguint, - whitebox::TxResult, - whitebox::{BlockchainStateWrapper, ContractObjWrapper}, + whitebox_legacy::TxResult, + whitebox_legacy::{BlockchainStateWrapper, ContractObjWrapper}, DebugApi, }; use simple_lock::locked_token::LockedTokenModule; @@ -51,7 +52,7 @@ where ScBuilder: 'static + Copy + Fn() -> energy_factory::ContractObj, { pub fn new(sc_builder: ScBuilder) -> Self { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0u64); let mut b_mock = BlockchainStateWrapper::new(); let owner = b_mock.create_user_account(&rust_zero); diff --git a/locked-asset/energy-factory/tests/energy_factory_setup/unbond_sc_mock.rs b/locked-asset/energy-factory/tests/energy_factory_setup/unbond_sc_mock.rs index 1b472a676..c993b7e24 100644 --- a/locked-asset/energy-factory/tests/energy_factory_setup/unbond_sc_mock.rs +++ b/locked-asset/energy-factory/tests/energy_factory_setup/unbond_sc_mock.rs @@ -35,11 +35,11 @@ impl UnbondScMock { pub fn send_to_user(&self) { let [locked_tokens, unlocked_tokens] = self.call_value().multi_esdt(); - let locked_tokens_burn_amount = unlocked_tokens.amount.clone(); + let locked_tokens_burn_amount = &unlocked_tokens.amount; self.send().esdt_local_burn( &locked_tokens.token_identifier, locked_tokens.token_nonce, - &locked_tokens_burn_amount, + locked_tokens_burn_amount, ); let (dest_user, ()) = diff --git a/locked-asset/energy-factory/tests/old_tokens_test.rs b/locked-asset/energy-factory/tests/old_tokens_test.rs index ba8be3d6a..d4bd57a3c 100644 --- a/locked-asset/energy-factory/tests/old_tokens_test.rs +++ b/locked-asset/energy-factory/tests/old_tokens_test.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + mod energy_factory_setup; use common_structs::{ @@ -19,7 +21,7 @@ use multiversx_sc_scenario::{ #[test] fn extend_lock_period_old_token_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0); let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); @@ -58,6 +60,8 @@ fn extend_lock_period_old_token_test() { managed_biguint!(60_000) * USER_BALANCE * (second_unlock_epoch - current_epoch) / 100_000u32; + let user_energy_amount_vec = user_energy_amount.to_bytes_be().as_slice().to_vec(); + setup .b_mock .execute_tx(&setup.owner, &setup.sc_wrapper, &rust_zero, |sc| { @@ -66,14 +70,14 @@ fn extend_lock_period_old_token_test() { let user_energy = ( managed_address!(&first_user), managed_biguint!(USER_BALANCE), - BigInt::from(user_energy_amount.clone()), + BigInt::from_signed_bytes_be(&user_energy_amount_vec), ) .into(); users_energy.push(user_energy); sc.set_energy_for_old_tokens(users_energy); let expected_energy = Energy::new( - BigInt::from(user_energy_amount.clone()), + BigInt::from_signed_bytes_be(&user_energy_amount_vec), 1, managed_biguint!(USER_BALANCE), ); @@ -136,7 +140,7 @@ fn extend_lock_period_old_token_test() { #[test] fn min_period_migrated_token_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0); let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); @@ -175,6 +179,8 @@ fn min_period_migrated_token_test() { managed_biguint!(60_000) * USER_BALANCE * (second_unlock_epoch - current_epoch) / 100_000u32; + let user_energy_amount_vec = user_energy_amount.to_bytes_be().as_slice().to_vec(); + setup .b_mock .execute_tx(&setup.owner, &setup.sc_wrapper, &rust_zero, |sc| { @@ -183,14 +189,14 @@ fn min_period_migrated_token_test() { let user_energy = ( managed_address!(&first_user), managed_biguint!(USER_BALANCE), - BigInt::from(user_energy_amount.clone()), + BigInt::from_signed_bytes_be(&user_energy_amount_vec), ) .into(); users_energy.push(user_energy); sc.set_energy_for_old_tokens(users_energy); let expected_energy = Energy::new( - BigInt::from(user_energy_amount.clone()), + BigInt::from_signed_bytes_be(&user_energy_amount_vec), 1, managed_biguint!(USER_BALANCE), ); @@ -244,7 +250,7 @@ fn min_period_migrated_token_test() { #[test] fn min_period_migrated_token_test2() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0); let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); @@ -283,6 +289,8 @@ fn min_period_migrated_token_test2() { managed_biguint!(60_000) * USER_BALANCE * (second_unlock_epoch - current_epoch) / 100_000u32; + let user_energy_amount_vec = user_energy_amount.to_bytes_be().as_slice().to_vec(); + setup .b_mock .execute_tx(&setup.owner, &setup.sc_wrapper, &rust_zero, |sc| { @@ -292,14 +300,14 @@ fn min_period_migrated_token_test2() { let user_energy = ( managed_address!(&first_user), managed_biguint!(USER_BALANCE), - BigInt::from(user_energy_amount.clone()), + BigInt::from_signed_bytes_be(&user_energy_amount_vec), ) .into(); users_energy.push(user_energy); sc.set_energy_for_old_tokens(users_energy); let expected_energy = Energy::new( - BigInt::from(user_energy_amount.clone()), + BigInt::from_signed_bytes_be(&user_energy_amount_vec), 1441, managed_biguint!(USER_BALANCE), ); @@ -362,7 +370,7 @@ fn min_period_migrated_token_test2() { #[test] fn check_initial_old_unlock_schedule_decode_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0); let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); @@ -401,6 +409,8 @@ fn check_initial_old_unlock_schedule_decode_test() { managed_biguint!(60_000) * USER_BALANCE * (second_unlock_epoch - current_epoch) / 100_000u32; + let user_energy_amount_vec = user_energy_amount.to_bytes_be().as_slice().to_vec(); + setup .b_mock .execute_tx(&setup.owner, &setup.sc_wrapper, &rust_zero, |sc| { @@ -409,14 +419,14 @@ fn check_initial_old_unlock_schedule_decode_test() { let user_energy = ( managed_address!(&first_user), managed_biguint!(USER_BALANCE), - BigInt::from(user_energy_amount.clone()), + BigInt::from_signed_bytes_be(&user_energy_amount_vec), ) .into(); users_energy.push(user_energy); sc.set_energy_for_old_tokens(users_energy); let expected_energy = Energy::new( - BigInt::from(user_energy_amount.clone()), + BigInt::from_signed_bytes_be(&user_energy_amount_vec), 1, managed_biguint!(USER_BALANCE), ); 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 21d4f2d29..823a8eb56 100644 --- a/locked-asset/energy-factory/tests/simple_lock_energy_test.rs +++ b/locked-asset/energy-factory/tests/simple_lock_energy_test.rs @@ -1,7 +1,10 @@ +#![allow(deprecated)] + mod energy_factory_setup; use energy_factory::energy::EnergyModule; use energy_factory_setup::*; +use multiversx_sc::types::BigUint; use simple_lock::locked_token::LockedTokenAttributes; use multiversx_sc_scenario::{ @@ -442,14 +445,19 @@ fn energy_deplete_test() { assert_eq!(actual_energy, expected_energy); current_epoch = 10; - let expected_energy = managed_biguint!(LOCK_OPTIONS[0] - current_epoch) * half_balance; + let expected_energy: BigUint = + managed_biguint!(LOCK_OPTIONS[0] - current_epoch) * half_balance; + let expected_energy_vec = expected_energy.to_bytes_be().as_slice().to_vec(); setup .b_mock .execute_query(&setup.sc_wrapper, |sc| { let mut energy = sc.user_energy(&managed_address!(&first_user)).get(); energy.deplete(current_epoch); - assert_eq!(energy.get_energy_amount(), expected_energy); + assert_eq!( + energy.get_energy_amount(), + BigUint::from_bytes_be(&expected_energy_vec) + ); }) .assert_ok(); } diff --git a/locked-asset/energy-factory/tests/token_merging_test.rs b/locked-asset/energy-factory/tests/token_merging_test.rs index d83b6da09..b32445506 100644 --- a/locked-asset/energy-factory/tests/token_merging_test.rs +++ b/locked-asset/energy-factory/tests/token_merging_test.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + mod energy_factory_setup; use energy_factory::{ @@ -17,7 +19,8 @@ use multiversx_sc::{ }; use multiversx_sc_modules::pause::PauseModule; use multiversx_sc_scenario::{ - managed_address, managed_token_id, whitebox::BlockchainStateWrapper, whitebox::TxTokenTransfer, + managed_address, managed_token_id, whitebox_legacy::BlockchainStateWrapper, + whitebox_legacy::TxTokenTransfer, }; use simple_lock::{ basic_lock_unlock::BasicLockUnlock, @@ -28,7 +31,7 @@ use multiversx_sc_scenario::{managed_token_id_wrapped, rust_biguint, DebugApi}; #[test] fn token_merging_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); let first_user = setup.first_user.clone(); @@ -98,7 +101,7 @@ fn token_merging_test() { #[test] fn token_merging_different_years_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); let first_user = setup.first_user.clone(); @@ -168,7 +171,7 @@ fn token_merging_different_years_test() { #[test] fn token_merging_different_years2_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); let first_user = setup.first_user.clone(); @@ -238,7 +241,7 @@ fn token_merging_different_years2_test() { #[test] fn test_specific_tokens_merge() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0u64); let mut b_mock = BlockchainStateWrapper::new(); let owner = b_mock.create_user_account(&rust_zero); @@ -365,3 +368,62 @@ fn test_specific_tokens_merge() { }), ); } + +#[test] +fn merge_same_schedule_test() { + DebugApi::dummy(); + let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); + let user = setup.first_user.clone(); + let unlock_epoch = to_start_of_month(LOCK_OPTIONS[0]); + + let first_token_amount = 400_000; + setup + .lock( + &user, + BASE_ASSET_TOKEN_ID, + first_token_amount, + LOCK_OPTIONS[0], + ) + .assert_ok(); + + let second_token_amount = 100_000; + setup + .lock( + &user, + BASE_ASSET_TOKEN_ID, + second_token_amount, + LOCK_OPTIONS[0], + ) + .assert_ok(); + + let payments = [ + TxTokenTransfer { + token_identifier: LOCKED_TOKEN_ID.to_vec(), + nonce: 1, + value: rust_biguint!(400_000), + }, + TxTokenTransfer { + token_identifier: LOCKED_TOKEN_ID.to_vec(), + nonce: 1, + value: rust_biguint!(100_000), + }, + ]; + setup + .b_mock + .execute_esdt_multi_transfer(&user, &setup.sc_wrapper, &payments[..], |sc| { + let _ = sc.merge_tokens_endpoint(OptionalValue::None); + }) + .assert_ok(); + + setup.b_mock.check_nft_balance( + &user, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(first_token_amount + second_token_amount), + Some(&LockedTokenAttributes:: { + original_token_id: managed_token_id_wrapped!(BASE_ASSET_TOKEN_ID), + original_token_nonce: 0, + unlock_epoch, + }), + ); +} diff --git a/locked-asset/energy-factory/tests/virtual_lock_test.rs b/locked-asset/energy-factory/tests/virtual_lock_test.rs index 1d13e1eb9..250abff1f 100644 --- a/locked-asset/energy-factory/tests/virtual_lock_test.rs +++ b/locked-asset/energy-factory/tests/virtual_lock_test.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + mod energy_factory_setup; use energy_factory::virtual_lock::VirtualLockModule; diff --git a/locked-asset/energy-factory/wasm/Cargo.lock b/locked-asset/energy-factory/wasm/Cargo.lock index 4ce7c14d7..b7f42af38 100644 --- a/locked-asset/energy-factory/wasm/Cargo.lock +++ b/locked-asset/energy-factory/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common_errors" @@ -98,15 +75,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -115,9 +83,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "legacy_token_decode_module" @@ -128,12 +96,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - [[package]] name = "math" version = "0.0.0" @@ -141,12 +103,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -156,12 +112,11 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -170,20 +125,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -193,9 +147,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -206,21 +160,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -234,33 +187,27 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -294,15 +241,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -311,9 +258,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -331,43 +278,3 @@ dependencies = [ "mergeable", "multiversx-sc", ] - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/locked-asset/energy-factory/wasm/Cargo.toml b/locked-asset/energy-factory/wasm/Cargo.toml index 9e5f2dbc6..944055b38 100644 --- a/locked-asset/energy-factory/wasm/Cargo.toml +++ b/locked-asset/energy-factory/wasm/Cargo.toml @@ -1,25 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "energy-factory-wasm" version = "0.0.0" -authors = ["MultiversX "] edition = "2021" publish = false [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.energy-factory] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/locked-asset/energy-factory/wasm/src/lib.rs b/locked-asset/energy-factory/wasm/src/lib.rs index d496bd0d2..7393a9e97 100644 --- a/locked-asset/energy-factory/wasm/src/lib.rs +++ b/locked-asset/energy-factory/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 32 +// Endpoints: 34 // Async Callback: 1 -// Total number of exported functions: 34 +// Total number of exported functions: 36 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,38 +19,42 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { energy_factory ( - lockTokens - unlockTokens - issueLockedToken - getLockedTokenId - getBaseAssetTokenId - getLegacyLockedTokenId - getEnergyEntryForUser - getEnergyAmountForUser - addLockOptions - getLockOptions - unlockEarly - reduceLockPeriod - getPenaltyAmount - setTokenUnstakeAddress - revertUnstake - getTokenUnstakeScAddress - setEnergyForOldTokens - updateEnergyAfterOldTokenUnlock - migrateOldTokens - pause - unpause - isPaused - setTransferRoleLockedToken - setBurnRoleLockedToken - mergeTokens - lockVirtual - addSCAddressToWhitelist - removeSCAddressFromWhitelist - isSCAddressWhitelisted - addToTokenTransferWhitelist - removeFromTokenTransferWhitelist - setUserEnergyAfterLockedTokenTransfer - callBack + init => init + upgrade => upgrade + lockTokens => lock_tokens_endpoint + unlockTokens => unlock_tokens_endpoint + extendLockPeriod => extend_lock_period + issueLockedToken => issue_locked_token + getLockedTokenId => locked_token + getBaseAssetTokenId => base_asset_token_id + getLegacyLockedTokenId => legacy_locked_token_id + getEnergyEntryForUser => get_updated_energy_entry_for_user + getEnergyAmountForUser => get_energy_amount_for_user + addLockOptions => add_lock_options + getLockOptions => get_lock_options_view + unlockEarly => unlock_early + reduceLockPeriod => reduce_lock_period + getPenaltyAmount => calculate_penalty_amount + setTokenUnstakeAddress => set_token_unstake_address + revertUnstake => revert_unstake + getTokenUnstakeScAddress => token_unstake_sc_address + setEnergyForOldTokens => set_energy_for_old_tokens + updateEnergyAfterOldTokenUnlock => update_energy_after_old_token_unlock + migrateOldTokens => migrate_old_tokens + pause => pause_endpoint + unpause => unpause_endpoint + isPaused => paused_status + setTransferRoleLockedToken => set_transfer_role + setBurnRoleLockedToken => set_burn_role + mergeTokens => merge_tokens_endpoint + lockVirtual => lock_virtual + addSCAddressToWhitelist => add_sc_address_to_whitelist + removeSCAddressFromWhitelist => remove_sc_address_from_whitelist + isSCAddressWhitelisted => is_sc_address_whitelisted + addToTokenTransferWhitelist => add_to_token_transfer_whitelist + removeFromTokenTransferWhitelist => remove_from_token_transfer_whitelist + setUserEnergyAfterLockedTokenTransfer => set_user_energy_after_locked_token_transfer ) } + +multiversx_sc_wasm_adapter::async_callback! { energy_factory } diff --git a/locked-asset/factory/Cargo.toml b/locked-asset/factory/Cargo.toml index 80516a5b4..6996881d1 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.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" [dependencies.arrayvec] version = "0.7.1" @@ -49,4 +49,4 @@ hex = "0.4" path = "../simple-lock" [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" diff --git a/locked-asset/factory/meta/Cargo.toml b/locked-asset/factory/meta/Cargo.toml index 899310222..d81d3bb85 100644 --- a/locked-asset/factory/meta/Cargo.toml +++ b/locked-asset/factory/meta/Cargo.toml @@ -4,8 +4,10 @@ version = "0.0.0" authors = ["MultiversX "] edition = "2021" publish = false + [dependencies.factory] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/locked-asset/factory/src/lib.rs b/locked-asset/factory/src/lib.rs index 893f16624..d8de993b4 100644 --- a/locked-asset/factory/src/lib.rs +++ b/locked-asset/factory/src/lib.rs @@ -43,10 +43,7 @@ pub trait LockedAssetFactory: asset_token_id.is_valid_esdt_identifier(), "Asset token ID is not a valid esdt identifier" ); - require!( - asset_token_id != self.locked_asset_token().get_token_id(), - "Asset token ID cannot be the same as Locked asset token ID" - ); + let unlock_milestones = default_unlock_period.to_vec(); self.validate_unlock_milestones(&unlock_milestones); @@ -66,6 +63,9 @@ pub trait LockedAssetFactory: self.set_paused(true); } + #[endpoint] + fn upgrade(&self) {} + fn set_extended_attributes_activation_nonce(&self, is_sc_upgrade: bool) { if !self.extended_attributes_activation_nonce().is_empty() { return; @@ -334,7 +334,7 @@ pub trait LockedAssetFactory: token_ticker: ManagedBuffer, num_decimals: usize, ) { - let payment_amount = self.call_value().egld_value(); + let payment_amount = self.call_value().egld_value().clone_value(); self.locked_asset_token().issue_and_set_all_roles( EsdtTokenType::Meta, payment_amount, diff --git a/locked-asset/factory/tests/factory_setup/mod.rs b/locked-asset/factory/tests/factory_setup/mod.rs index 148ce0e13..633805223 100644 --- a/locked-asset/factory/tests/factory_setup/mod.rs +++ b/locked-asset/factory/tests/factory_setup/mod.rs @@ -1,4 +1,5 @@ #![allow(dead_code)] +#![allow(deprecated)] use common_structs::UnlockMilestone; use energy_factory::SimpleLockEnergy; @@ -11,7 +12,7 @@ use multiversx_sc::{ }; use multiversx_sc_scenario::{ managed_address, managed_token_id, rust_biguint, - whitebox::{BlockchainStateWrapper, ContractObjWrapper}, + whitebox_legacy::{BlockchainStateWrapper, ContractObjWrapper}, DebugApi, }; use simple_lock::locked_token::LockedTokenModule; @@ -49,7 +50,7 @@ where factory_builder: FactoryBuilder, energy_factory_builder: EnergyFactoryBuilder, ) -> Self { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0u64); let mut b_mock = BlockchainStateWrapper::new(); let owner = b_mock.create_user_account(&rust_zero); diff --git a/locked-asset/factory/tests/lock_test.rs b/locked-asset/factory/tests/lock_test.rs index bd097933c..556642eef 100644 --- a/locked-asset/factory/tests/lock_test.rs +++ b/locked-asset/factory/tests/lock_test.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + use common_structs::{ LockedAssetTokenAttributesEx, UnlockMilestone, UnlockMilestoneEx, UnlockScheduleEx, }; @@ -6,7 +8,7 @@ use multiversx_sc::{ types::{EsdtLocalRole, ManagedVec, MultiValueEncoded}, }; use multiversx_sc_scenario::{ - managed_biguint, managed_token_id, rust_biguint, whitebox::*, DebugApi, + managed_biguint, managed_token_id, rust_biguint, whitebox_legacy::*, DebugApi, }; const SC_WASM_PATH: &str = "output/factory.wasm"; diff --git a/locked-asset/factory/tests/unlock_test.rs b/locked-asset/factory/tests/unlock_test.rs index bfc8403de..057cf409c 100644 --- a/locked-asset/factory/tests/unlock_test.rs +++ b/locked-asset/factory/tests/unlock_test.rs @@ -1,8 +1,10 @@ +#![allow(deprecated)] + use common_structs::{LockedAssetTokenAttributesEx, UnlockMilestoneEx, UnlockScheduleEx}; use multiversx_sc::types::{BigInt, MultiValueEncoded}; use multiversx_sc::types::{EsdtTokenPayment, ManagedVec, TokenIdentifier}; use multiversx_sc_scenario::{ - managed_address, managed_biguint, rust_biguint, whitebox::*, DebugApi, + managed_address, managed_biguint, rust_biguint, whitebox_legacy::*, DebugApi, }; const SC_WASM_PATH: &str = "output/factory.wasm"; @@ -773,7 +775,7 @@ fn test_aggregated_unlock_schedule_with_1_offset() { #[test] fn update_energy_after_old_token_unlock_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0); let mut setup = FactorySetup::new(factory::contract_obj, energy_factory::contract_obj); @@ -815,7 +817,7 @@ fn update_energy_after_old_token_unlock_test() { &old_token_attributes, ); - let mut user_energy_amount = managed_biguint!(0); + let mut user_energy_amount: multiversx_sc::types::BigUint = managed_biguint!(0); user_energy_amount += managed_biguint!(20_000) * USER_BALANCE * (first_unlock_epoch - current_epoch) / 100_000u32; user_energy_amount += @@ -826,6 +828,8 @@ fn update_energy_after_old_token_unlock_test() { user_energy_amount += managed_biguint!(40_000) * USER_BALANCE * (forth_unlock_epoch - current_epoch) / 100_000u32; + let expected_energy_vec = user_energy_amount.to_bytes_be().as_slice().to_vec(); + setup .b_mock .execute_tx( @@ -839,14 +843,14 @@ fn update_energy_after_old_token_unlock_test() { let user_energy = ( managed_address!(&first_user), managed_biguint!(USER_BALANCE), - BigInt::from(user_energy_amount.clone()), + BigInt::from_signed_bytes_be(&expected_energy_vec), ) .into(); users_energy.push(user_energy); sc.set_energy_for_old_tokens(users_energy); let expected_energy = Energy::new( - BigInt::from(user_energy_amount.clone()), + BigInt::from_signed_bytes_be(&expected_energy_vec), 1441, managed_biguint!(USER_BALANCE), ); @@ -909,7 +913,8 @@ fn update_energy_after_old_token_unlock_test() { Some(&new_locked_token_attributes), ); - let mut final_user_energy_amount = managed_biguint!(0u64); + let mut final_user_energy_amount: multiversx_sc::types::BigUint = + managed_biguint!(0u64); final_user_energy_amount += managed_biguint!(33_333) * remaining_locked_token_balace * (third_unlock_epoch - current_epoch) @@ -919,11 +924,13 @@ fn update_energy_after_old_token_unlock_test() { * (forth_unlock_epoch - current_epoch) / 100_000u32; // 66_666 + 1 leftover + let final_amount_vec = final_user_energy_amount.to_bytes_be().as_slice().to_vec(); + setup .b_mock .execute_query(&setup.energy_factory_wrapper, |sc| { let expected_energy = Energy::new( - BigInt::from(final_user_energy_amount.clone()), + BigInt::from_signed_bytes_be(&final_amount_vec), current_epoch, managed_biguint!(remaining_locked_token_balace), ); diff --git a/locked-asset/factory/wasm/Cargo.lock b/locked-asset/factory/wasm/Cargo.lock index ca5df67df..39d478ef4 100644 --- a/locked-asset/factory/wasm/Cargo.lock +++ b/locked-asset/factory/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,9 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "cfg-if" @@ -37,12 +26,6 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - [[package]] name = "common_errors" version = "0.0.0" @@ -63,9 +46,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "endian-type" @@ -120,15 +103,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -137,9 +111,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "itertools" @@ -161,9 +135,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.139" +version = "0.2.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" [[package]] name = "math" @@ -187,12 +161,11 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -201,20 +174,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -224,9 +196,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -237,21 +209,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -265,33 +236,27 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -325,15 +290,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -359,9 +324,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -380,19 +345,13 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - [[package]] name = "wee_alloc" version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" dependencies = [ - "cfg-if 0.1.10", + "cfg-if", "libc", "memory_units", "winapi", diff --git a/locked-asset/factory/wasm/Cargo.toml b/locked-asset/factory/wasm/Cargo.toml index e4b9b3780..eb8c084a5 100644 --- a/locked-asset/factory/wasm/Cargo.toml +++ b/locked-asset/factory/wasm/Cargo.toml @@ -1,26 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "factory-wasm" version = "0.0.0" -authors = ["MultiversX "] edition = "2021" publish = false [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.factory] -default-features = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/locked-asset/factory/wasm/src/lib.rs b/locked-asset/factory/wasm/src/lib.rs index e5250b664..7ad9e4ac0 100644 --- a/locked-asset/factory/wasm/src/lib.rs +++ b/locked-asset/factory/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 24 +// Endpoints: 25 // Async Callback: 1 -// Total number of exported functions: 26 +// Total number of exported functions: 27 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,30 +19,33 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { factory ( - whitelist - removeWhitelist - createAndForwardCustomPeriod - createAndForward - unlockAssets - lockAssets - setUnlockPeriod - registerLockedAssetToken - setInitEpoch - getInitEpoch - getWhitelistedContracts - getDefaultUnlockPeriod - getLockedAssetTokenId - getAssetTokenId - getUnlockScheduleForSFTNonce - getCacheSize - mergeTokens - getExtendedAttributesActivationNonce - setLockedTokenBurnRoleForAddress - setTransferRoleOldLockedToken - setNewFactoryAddress - pause - unpause - isPaused - callBack + init => init + upgrade => upgrade + whitelist => whitelist + removeWhitelist => remove_whitelist + createAndForwardCustomPeriod => create_and_forward_custom_period + createAndForward => create_and_forward + unlockAssets => unlock_assets + lockAssets => lock_assets + setUnlockPeriod => set_unlock_period + registerLockedAssetToken => register_locked_asset_token + setInitEpoch => set_init_epoch + getInitEpoch => init_epoch + getWhitelistedContracts => whitelisted_contracts + getDefaultUnlockPeriod => default_unlock_period + getLockedAssetTokenId => locked_asset_token + getAssetTokenId => asset_token_id + getUnlockScheduleForSFTNonce => get_unlock_schedule_for_sft_nonce + getCacheSize => get_cache_size + mergeTokens => merge_tokens + getExtendedAttributesActivationNonce => extended_attributes_activation_nonce + setLockedTokenBurnRoleForAddress => set_locked_token_burn_role_for_address + setTransferRoleOldLockedToken => set_transfer_role_old_locked_token + setNewFactoryAddress => set_new_factory_address + pause => pause_endpoint + unpause => unpause_endpoint + isPaused => paused_status ) } + +multiversx_sc_wasm_adapter::async_callback! { factory } diff --git a/locked-asset/lkmex-transfer/Cargo.toml b/locked-asset/lkmex-transfer/Cargo.toml index 8742e67e8..a6fb9ca95 100644 --- a/locked-asset/lkmex-transfer/Cargo.toml +++ b/locked-asset/lkmex-transfer/Cargo.toml @@ -7,6 +7,7 @@ publish = false [lib] path = "src/lib.rs" + [dependencies.common_structs] path = "../../common/common_structs" @@ -15,6 +16,7 @@ path = "../../common/modules/utils" [dependencies.legacy_token_decode_module] path = "../../common/modules/legacy_token_decode_module" + [dependencies.permissions_module] path = "../../common/modules/permissions_module" @@ -28,14 +30,14 @@ path = "../energy-factory" path = "../../energy-integration/common-modules/energy-query" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" [dev-dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" diff --git a/locked-asset/lkmex-transfer/meta/Cargo.toml b/locked-asset/lkmex-transfer/meta/Cargo.toml index 53ac63600..e0c0588d1 100644 --- a/locked-asset/lkmex-transfer/meta/Cargo.toml +++ b/locked-asset/lkmex-transfer/meta/Cargo.toml @@ -4,8 +4,10 @@ version = "0.0.0" authors = ["MultiversX "] edition = "2021" publish = false + [dependencies.lkmex-transfer] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/locked-asset/lkmex-transfer/src/energy_transfer.rs b/locked-asset/lkmex-transfer/src/energy_transfer.rs index bd974f46a..008517e80 100644 --- a/locked-asset/lkmex-transfer/src/energy_transfer.rs +++ b/locked-asset/lkmex-transfer/src/energy_transfer.rs @@ -53,6 +53,7 @@ pub trait EnergyTransferModule: let epoch_diff = current_epoch - attributes.unlock_epoch; let simulated_deplete_amount = &token.amount * epoch_diff; energy.remove_energy_raw(BigUint::zero(), simulated_deplete_amount); + energy.add_energy_raw(token.amount, BigInt::zero()); } } diff --git a/locked-asset/lkmex-transfer/src/lib.rs b/locked-asset/lkmex-transfer/src/lib.rs index 993eb4913..7c187882e 100644 --- a/locked-asset/lkmex-transfer/src/lib.rs +++ b/locked-asset/lkmex-transfer/src/lib.rs @@ -56,6 +56,9 @@ pub trait LkmexTransfer: self.add_permissions(caller, Permissions::OWNER); } + #[endpoint] + fn upgrade(&self) {} + #[endpoint] fn withdraw(&self, sender: ManagedAddress) { let receiver = self.blockchain().get_caller(); @@ -122,7 +125,7 @@ pub trait LkmexTransfer: let sender_last_transfer_mapper = self.sender_last_transfer_epoch(&sender); self.check_address_on_cooldown(&sender_last_transfer_mapper); - let payments = self.call_value().all_esdt_transfers(); + let payments = self.call_value().all_esdt_transfers().clone_value(); let locked_token_id = self.locked_token_id().get(); for payment in payments.iter() { require!( diff --git a/locked-asset/lkmex-transfer/tests/lkmex_transfer_tests.rs b/locked-asset/lkmex-transfer/tests/lkmex_transfer_tests.rs index 2f265d1a1..4231daecf 100644 --- a/locked-asset/lkmex-transfer/tests/lkmex_transfer_tests.rs +++ b/locked-asset/lkmex-transfer/tests/lkmex_transfer_tests.rs @@ -1,7 +1,9 @@ +#![allow(deprecated)] + use multiversx_sc::codec::multi_types::OptionalValue; use multiversx_sc::storage::mappers::StorageTokenWrapper; use multiversx_sc::types::{BigInt, EsdtLocalRole, MultiValueEncoded}; -use multiversx_sc_scenario::{managed_address, managed_biguint, whitebox::*}; +use multiversx_sc_scenario::{managed_address, managed_biguint, whitebox_legacy::*}; use multiversx_sc_scenario::{managed_token_id, rust_biguint}; use energy_factory::energy::EnergyModule; @@ -619,3 +621,200 @@ fn cancel_transfer_test() { }) .assert_ok(); } + +#[test] +fn transfer_locked_token_after_unlock_period_test() { + let rust_zero = rust_biguint!(0); + let mut b_mock = BlockchainStateWrapper::new(); + + let user_addr = b_mock.create_user_account(&rust_zero); + let claimer_addr = b_mock.create_user_account(&rust_zero); + let owner_addr = b_mock.create_user_account(&rust_zero); + let transfer_sc_wrapper = b_mock.create_sc_account( + &rust_zero, + Some(&owner_addr), + lkmex_transfer::contract_obj, + "Some path", + ); + let factory_sc_wrapper = b_mock.create_sc_account( + &rust_zero, + Some(&owner_addr), + energy_factory::contract_obj, + "Some other path", + ); + + b_mock.set_block_epoch(5); + + // Setup transfer SC + b_mock + .execute_tx(&owner_addr, &transfer_sc_wrapper, &rust_zero, |sc| { + sc.init( + managed_address!(factory_sc_wrapper.address_ref()), + managed_token_id!(LOCKED_TOKEN_ID), + 4, + EPOCHS_IN_YEAR, + ); + }) + .assert_ok(); + + b_mock.set_esdt_local_roles( + transfer_sc_wrapper.address_ref(), + LOCKED_TOKEN_ID, + &[EsdtLocalRole::Transfer], + ); + + // setup energy factory SC + b_mock + .execute_tx(&owner_addr, &factory_sc_wrapper, &rust_zero, |sc| { + let mut lock_options = MultiValueEncoded::new(); + for (option, penalty) in LOCK_OPTIONS.iter().zip(PENALTY_PERCENTAGES.iter()) { + lock_options.push((*option, *penalty).into()); + } + + // sc addresses don't matter here, we don't test that part + sc.init( + managed_token_id!(BASE_ASSET_TOKEN_ID), + managed_token_id!(LEGACY_LOCKED_TOKEN_ID), + managed_address!(transfer_sc_wrapper.address_ref()), + 0, + lock_options, + ); + + sc.locked_token() + .set_token_id(managed_token_id!(LOCKED_TOKEN_ID)); + sc.token_transfer_whitelist() + .add(&managed_address!(transfer_sc_wrapper.address_ref())); + sc.set_paused(false); + }) + .assert_ok(); + + b_mock.set_esdt_local_roles( + factory_sc_wrapper.address_ref(), + BASE_ASSET_TOKEN_ID, + &[EsdtLocalRole::Mint, EsdtLocalRole::Burn], + ); + b_mock.set_esdt_local_roles( + factory_sc_wrapper.address_ref(), + LOCKED_TOKEN_ID, + &[ + EsdtLocalRole::NftCreate, + EsdtLocalRole::NftAddQuantity, + EsdtLocalRole::NftBurn, + EsdtLocalRole::Transfer, + ], + ); + b_mock.set_esdt_local_roles( + factory_sc_wrapper.address_ref(), + LEGACY_LOCKED_TOKEN_ID, + &[EsdtLocalRole::NftBurn], + ); + + // setup user balance + + b_mock.set_esdt_balance( + &user_addr, + BASE_ASSET_TOKEN_ID, + &rust_biguint!(USER_BALANCE), + ); + + // lock tokens + b_mock + .execute_esdt_transfer( + &user_addr, + &factory_sc_wrapper, + BASE_ASSET_TOKEN_ID, + 0, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.lock_tokens_endpoint(LOCK_OPTIONS[0], OptionalValue::None); + + let unlock_epoch = sc.unlock_epoch_to_start_of_month(5 + LOCK_OPTIONS[0]); + let lock_epochs = unlock_epoch - 5; + let expected_energy_amount = + BigInt::from(USER_BALANCE as i64) * BigInt::from(lock_epochs as i64); + let expected_energy = + Energy::new(expected_energy_amount, 5, managed_biguint!(USER_BALANCE)); + let actual_energy = sc.user_energy(&managed_address!(&user_addr)).get(); + assert_eq!(expected_energy, actual_energy); + }, + ) + .assert_ok(); + + // transfer half of the LKMEX to other user + b_mock + .execute_esdt_transfer( + &user_addr, + &transfer_sc_wrapper, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE / 2), + |sc| { + sc.lock_funds(managed_address!(&claimer_addr)); + }, + ) + .assert_ok(); + + // check first user energy after transfer + b_mock + .execute_query(&factory_sc_wrapper, |sc| { + let unlock_epoch = sc.unlock_epoch_to_start_of_month(5 + LOCK_OPTIONS[0]); + let lock_epochs = unlock_epoch - 5; + let expected_energy_amount = + BigInt::from((USER_BALANCE / 2) as i64) * BigInt::from(lock_epochs as i64); + let expected_energy = Energy::new( + expected_energy_amount, + 5, + managed_biguint!(USER_BALANCE / 2), + ); + let actual_energy = sc.user_energy(&managed_address!(&user_addr)).get(); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); + + let current_epoch = EPOCHS_IN_YEAR + 3; + // pass 5 epochs + b_mock.set_block_epoch(current_epoch); + + // second user claim + b_mock + .execute_tx(&claimer_addr, &transfer_sc_wrapper, &rust_zero, |sc| { + sc.withdraw(managed_address!(&user_addr)); + }) + .assert_ok(); + + // check first user energy + b_mock + .execute_query(&factory_sc_wrapper, |sc| { + let unlock_epoch = sc.unlock_epoch_to_start_of_month(5 + LOCK_OPTIONS[0]); + let lock_epochs = unlock_epoch as i64 - current_epoch as i64; + let expected_energy_amount = + BigInt::from((USER_BALANCE / 2) as i64) * BigInt::from(lock_epochs); + let expected_energy = Energy::new( + expected_energy_amount, + current_epoch, + managed_biguint!(USER_BALANCE / 2), + ); + + let actual_energy = sc.user_energy(&managed_address!(&claimer_addr)).get(); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); + + // check second user energy + b_mock + .execute_query(&factory_sc_wrapper, |sc| { + let unlock_epoch = sc.unlock_epoch_to_start_of_month(5 + LOCK_OPTIONS[0]); + let lock_epochs = unlock_epoch as i64 - current_epoch as i64; + let expected_energy_amount = + BigInt::from((USER_BALANCE / 2) as i64) * BigInt::from(lock_epochs); + let expected_energy = Energy::new( + expected_energy_amount, + current_epoch, + managed_biguint!(USER_BALANCE / 2), + ); + + let actual_energy = sc.user_energy(&managed_address!(&claimer_addr)).get(); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); +} diff --git a/locked-asset/lkmex-transfer/wasm/Cargo.lock b/locked-asset/lkmex-transfer/wasm/Cargo.lock index 0956bbfca..503d067d7 100644 --- a/locked-asset/lkmex-transfer/wasm/Cargo.lock +++ b/locked-asset/lkmex-transfer/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common_errors" @@ -98,15 +75,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -115,9 +83,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "legacy_token_decode_module" @@ -128,12 +96,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - [[package]] name = "lkmex-transfer" version = "0.0.0" @@ -163,12 +125,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -178,12 +134,11 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -192,20 +147,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -215,9 +169,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -228,21 +182,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -256,19 +209,13 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "permissions_module" version = "0.0.0" @@ -280,18 +227,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -325,15 +272,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -342,9 +289,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -362,43 +309,3 @@ dependencies = [ "mergeable", "multiversx-sc", ] - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/locked-asset/lkmex-transfer/wasm/Cargo.toml b/locked-asset/lkmex-transfer/wasm/Cargo.toml index 7960ec1fc..dee74ceae 100644 --- a/locked-asset/lkmex-transfer/wasm/Cargo.toml +++ b/locked-asset/lkmex-transfer/wasm/Cargo.toml @@ -1,26 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "lkmex-transfer-wasm" version = "0.0.0" -authors = ["MultiversX "] edition = "2021" publish = false [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.lkmex-transfer] -default-features = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/locked-asset/lkmex-transfer/wasm/src/lib.rs b/locked-asset/lkmex-transfer/wasm/src/lib.rs index 5b48ab16b..6df953b3e 100644 --- a/locked-asset/lkmex-transfer/wasm/src/lib.rs +++ b/locked-asset/lkmex-transfer/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 11 +// Endpoints: 12 // Async Callback (empty): 1 -// Total number of exported functions: 13 +// Total number of exported functions: 14 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,18 +19,20 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { lkmex_transfer ( - withdraw - cancelTransfer - lockFunds - getScheduledTransfers - getAllSenders - setEnergyFactoryAddress - getEnergyFactoryAddress - addAdmin - removeAdmin - updateOwnerOrAdmin - getPermissions + init => init + upgrade => upgrade + withdraw => withdraw + cancelTransfer => cancel_transfer + lockFunds => lock_funds + getScheduledTransfers => get_scheduled_transfers + getAllSenders => all_senders + setEnergyFactoryAddress => set_energy_factory_address + getEnergyFactoryAddress => energy_factory_address + addAdmin => add_admin_endpoint + removeAdmin => remove_admin_endpoint + updateOwnerOrAdmin => update_owner_or_admin_endpoint + getPermissions => permissions ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/locked-asset/locked-token-wrapper/Cargo.toml b/locked-asset/locked-token-wrapper/Cargo.toml index cf44d39d6..787914eeb 100644 --- a/locked-asset/locked-token-wrapper/Cargo.toml +++ b/locked-asset/locked-token-wrapper/Cargo.toml @@ -7,11 +7,12 @@ publish = false [lib] path = "src/lib.rs" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" [dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" [dependencies.utils] path = "../../common/modules/utils" @@ -43,4 +44,4 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" diff --git a/locked-asset/locked-token-wrapper/meta/Cargo.toml b/locked-asset/locked-token-wrapper/meta/Cargo.toml index 438ccf937..6de0a4093 100644 --- a/locked-asset/locked-token-wrapper/meta/Cargo.toml +++ b/locked-asset/locked-token-wrapper/meta/Cargo.toml @@ -6,8 +6,10 @@ publish = false authors = ["MultiversX "] [dev-dependencies] + [dependencies.locked-token-wrapper] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/locked-asset/locked-token-wrapper/src/lib.rs b/locked-asset/locked-token-wrapper/src/lib.rs index 0998f92f5..980736f63 100644 --- a/locked-asset/locked-token-wrapper/src/lib.rs +++ b/locked-asset/locked-token-wrapper/src/lib.rs @@ -20,6 +20,9 @@ pub trait LockedTokenWrapper: self.energy_factory_address().set(&energy_factory_address); } + #[endpoint] + fn upgrade(&self) {} + #[payable("*")] #[endpoint(wrapLockedToken)] fn wrap_locked_token_endpoint(&self) -> EsdtTokenPayment { diff --git a/locked-asset/locked-token-wrapper/src/wrapped_token.rs b/locked-asset/locked-token-wrapper/src/wrapped_token.rs index d4ac823c8..ae3fce50a 100644 --- a/locked-asset/locked-token-wrapper/src/wrapped_token.rs +++ b/locked-asset/locked-token-wrapper/src/wrapped_token.rs @@ -24,7 +24,7 @@ pub trait WrappedTokenModule: token_ticker: ManagedBuffer, num_decimals: usize, ) { - let payment_amount = self.call_value().egld_value(); + let payment_amount = self.call_value().egld_value().clone_value(); self.wrapped_token().issue_and_set_all_roles( EsdtTokenType::Meta, diff --git a/locked-asset/locked-token-wrapper/tests/locked_token_wrapping_test.rs b/locked-asset/locked-token-wrapper/tests/locked_token_wrapping_test.rs index d4c5d22c8..812b114e9 100644 --- a/locked-asset/locked-token-wrapper/tests/locked_token_wrapping_test.rs +++ b/locked-asset/locked-token-wrapper/tests/locked_token_wrapping_test.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + use energy_factory_mock::EnergyFactoryMock; use energy_query::Energy; use locked_token_wrapper::{ @@ -7,7 +9,7 @@ use locked_token_wrapper::{ use multiversx_sc::{storage::mappers::StorageTokenWrapper, types::EsdtLocalRole}; use multiversx_sc_scenario::{ managed_address, managed_biguint, managed_token_id, managed_token_id_wrapped, rust_biguint, - whitebox::BlockchainStateWrapper, DebugApi, + whitebox_legacy::BlockchainStateWrapper, DebugApi, }; use simple_lock::locked_token::LockedTokenAttributes; @@ -17,7 +19,7 @@ static WRAPPED_TOKEN_ID: &[u8] = b"WRAPPED-123456"; #[test] fn token_wrap_unwrap_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0); let mut b_mock = BlockchainStateWrapper::new(); @@ -177,7 +179,7 @@ fn token_wrap_unwrap_test() { #[test] fn tokens_wrap_unwrap_test2() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0); let mut b_mock = BlockchainStateWrapper::new(); diff --git a/locked-asset/locked-token-wrapper/wasm/Cargo.lock b/locked-asset/locked-token-wrapper/wasm/Cargo.lock index 389a26cc8..eb6ca7c6e 100644 --- a/locked-asset/locked-token-wrapper/wasm/Cargo.lock +++ b/locked-asset/locked-token-wrapper/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common_errors" @@ -106,15 +83,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -123,9 +91,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "legacy_token_decode_module" @@ -136,12 +104,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - [[package]] name = "lkmex-transfer" version = "0.0.0" @@ -187,12 +149,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -202,12 +158,11 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -216,20 +171,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -239,9 +193,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -252,21 +206,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -280,19 +233,13 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "permissions_module" version = "0.0.0" @@ -304,18 +251,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -349,15 +296,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -366,9 +313,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -386,43 +333,3 @@ dependencies = [ "mergeable", "multiversx-sc", ] - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/locked-asset/locked-token-wrapper/wasm/Cargo.toml b/locked-asset/locked-token-wrapper/wasm/Cargo.toml index 5fb959317..0d10a2666 100644 --- a/locked-asset/locked-token-wrapper/wasm/Cargo.toml +++ b/locked-asset/locked-token-wrapper/wasm/Cargo.toml @@ -1,25 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "locked-token-wrapper-wasm" version = "0.0.0" -authors = ["MultiversX "] edition = "2021" publish = false [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.locked-token-wrapper] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/locked-asset/locked-token-wrapper/wasm/src/lib.rs b/locked-asset/locked-token-wrapper/wasm/src/lib.rs index efae1ed5e..6c59af09c 100644 --- a/locked-asset/locked-token-wrapper/wasm/src/lib.rs +++ b/locked-asset/locked-token-wrapper/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 8 +// Endpoints: 9 // Async Callback: 1 -// Total number of exported functions: 10 +// Total number of exported functions: 11 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,14 +19,17 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { locked_token_wrapper ( - wrapLockedToken - unwrapLockedToken - issueWrappedToken - setTransferRoleWrappedToken - unsetTransferRoleWrappedToken - getWrappedTokenId - setEnergyFactoryAddress - getEnergyFactoryAddress - callBack + init => init + upgrade => upgrade + wrapLockedToken => wrap_locked_token_endpoint + unwrapLockedToken => unwrap_locked_token_endpoint + issueWrappedToken => issue_wrapped_token + setTransferRoleWrappedToken => set_transfer_role + unsetTransferRoleWrappedToken => unset_transfer_role + getWrappedTokenId => wrapped_token + setEnergyFactoryAddress => set_energy_factory_address + getEnergyFactoryAddress => energy_factory_address ) } + +multiversx_sc_wasm_adapter::async_callback! { locked_token_wrapper } diff --git a/locked-asset/proxy_dex/Cargo.toml b/locked-asset/proxy_dex/Cargo.toml index 5d3be5054..5c52745d9 100644 --- a/locked-asset/proxy_dex/Cargo.toml +++ b/locked-asset/proxy_dex/Cargo.toml @@ -6,6 +6,7 @@ publish = false [lib] path = "src/lib.rs" + [dependencies.common_structs] path = "../../common/common_structs" @@ -44,11 +45,11 @@ path = "../../common/traits/mergeable" path = "../../common/traits/fixed-supply-token" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" [dependencies.energy-factory] path = "../energy-factory" @@ -59,13 +60,16 @@ path = "../../energy-integration/common-modules/energy-query" [dependencies.simple-lock] path = "../simple-lock" +[dependencies.sc_whitelist_module] +path = "../../common/modules/sc_whitelist_module" + [dev-dependencies] num-bigint = "0.4.2" num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" [dev-dependencies.pausable] path = "../../common/modules/pausable" @@ -82,8 +86,5 @@ path = "../../common/modules/farm/farm_token" [dev-dependencies.rewards] path = "../../common/modules/farm/rewards" -[dev-dependencies.sc_whitelist_module] -path = "../../common/modules/sc_whitelist_module" - [dev-dependencies.farm-boosted-yields] path = "../../energy-integration/farm-boosted-yields" diff --git a/locked-asset/proxy_dex/README.md b/locked-asset/proxy_dex/README.md index c0d37d945..24b995891 100644 --- a/locked-asset/proxy_dex/README.md +++ b/locked-asset/proxy_dex/README.md @@ -2,7 +2,7 @@ ## Abstract -Locked MEX tokens can be used as MEX token in Maiar Exchange, with the help of this proxy contract. +Locked MEX tokens can be used as MEX token in xExchange, with the help of this proxy contract. ## Introduction diff --git a/locked-asset/proxy_dex/meta/Cargo.toml b/locked-asset/proxy_dex/meta/Cargo.toml index 2bfb26ea7..41fea1fc8 100644 --- a/locked-asset/proxy_dex/meta/Cargo.toml +++ b/locked-asset/proxy_dex/meta/Cargo.toml @@ -4,8 +4,10 @@ version = "0.0.0" authors = ["MultiversX "] edition = "2021" publish = false + [dependencies.proxy_dex] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/locked-asset/proxy_dex/src/energy_update.rs b/locked-asset/proxy_dex/src/energy_update.rs index 4242350ca..0c62e34f7 100644 --- a/locked-asset/proxy_dex/src/energy_update.rs +++ b/locked-asset/proxy_dex/src/energy_update.rs @@ -1,7 +1,7 @@ multiversx_sc::imports!(); -use common_structs::Nonce; -use energy_factory::locked_token_transfer::ProxyTrait as _; +use common_structs::{Epoch, Nonce}; +use energy_factory::{locked_token_transfer::ProxyTrait as _, ProxyTrait as _}; use energy_query::Energy; use simple_lock::locked_token::LockedTokenAttributes; @@ -49,6 +49,7 @@ pub trait EnergyUpdateModule: if self.blockchain().is_smart_contract(user) { return; } + let attributes = self.decode_legacy_token(token_id, token_nonce); let epoch_amount_pairs = attributes.get_unlock_amounts_per_epoch(token_amount); for pair in epoch_amount_pairs.pairs { @@ -62,6 +63,19 @@ pub trait EnergyUpdateModule: self.set_energy_in_factory(user.clone(), energy, energy_factory_addr); } + fn call_increase_energy( + &self, + user: ManagedAddress, + old_tokens: EsdtTokenPayment, + lock_epochs: Epoch, + energy_factory_addr: ManagedAddress, + ) -> EsdtTokenPayment { + self.energy_factory_proxy(energy_factory_addr) + .extend_lock_period(lock_epochs, user) + .with_esdt_transfer(old_tokens) + .execute_on_dest_context() + } + fn set_energy_in_factory( &self, user: ManagedAddress, diff --git a/locked-asset/proxy_dex/src/farm_interactions.rs b/locked-asset/proxy_dex/src/farm_interactions.rs index ee9a62f30..dab9a7825 100644 --- a/locked-asset/proxy_dex/src/farm_interactions.rs +++ b/locked-asset/proxy_dex/src/farm_interactions.rs @@ -2,8 +2,9 @@ multiversx_sc::imports!(); use farm::{ base_functions::{ClaimRewardsResultType, ClaimRewardsResultWrapper}, - EnterFarmResultType, ExitFarmWithPartialPosResultType, ProxyTrait as _, + EnterFarmResultType, ExitFarmWithPartialPosResultType, }; +use farm_with_locked_rewards::ProxyTrait as _; pub struct EnterFarmResultWrapper { pub farm_token: EsdtTokenPayment, @@ -13,21 +14,20 @@ pub struct EnterFarmResultWrapper { pub struct ExitFarmResultWrapper { pub farming_tokens: EsdtTokenPayment, pub reward_tokens: EsdtTokenPayment, - pub remaining_farm_tokens: EsdtTokenPayment, } #[multiversx_sc::module] pub trait FarmInteractionsModule { fn call_enter_farm( &self, + user: ManagedAddress, farm_address: ManagedAddress, farming_token_id: TokenIdentifier, farming_token_amount: BigUint, ) -> EnterFarmResultWrapper { - let original_caller = self.blockchain().get_caller(); let enter_farm_result: EnterFarmResultType = self .farm_contract_proxy(farm_address) - .enter_farm_endpoint(original_caller) + .enter_farm_endpoint(user) .with_esdt_transfer((farming_token_id, 0, farming_token_amount)) .execute_on_dest_context(); @@ -41,34 +41,32 @@ pub trait FarmInteractionsModule { fn call_exit_farm( &self, + user: ManagedAddress, farm_address: ManagedAddress, farm_token: EsdtTokenPayment, - exit_amount: BigUint, ) -> ExitFarmResultWrapper { - let original_caller = self.blockchain().get_caller(); let raw_result: ExitFarmWithPartialPosResultType = self .farm_contract_proxy(farm_address) - .exit_farm_endpoint(exit_amount, original_caller) + .exit_farm_endpoint(user) .with_esdt_transfer(farm_token) .execute_on_dest_context(); - let (farming_tokens, reward_tokens, remaining_farm_tokens) = raw_result.into_tuple(); + let (farming_tokens, reward_tokens) = raw_result.into_tuple(); ExitFarmResultWrapper { farming_tokens, reward_tokens, - remaining_farm_tokens, } } fn call_claim_rewards_farm( &self, + user: ManagedAddress, farm_address: ManagedAddress, farm_token: EsdtTokenPayment, ) -> ClaimRewardsResultWrapper { - let original_caller = self.blockchain().get_caller(); let raw_result: ClaimRewardsResultType = self .farm_contract_proxy(farm_address) - .claim_rewards_endpoint(original_caller) + .claim_rewards_endpoint(user) .with_esdt_transfer(farm_token) .execute_on_dest_context(); let (new_farm_token, rewards) = raw_result.into_tuple(); @@ -80,5 +78,6 @@ pub trait FarmInteractionsModule { } #[proxy] - fn farm_contract_proxy(&self, to: ManagedAddress) -> farm::Proxy; + fn farm_contract_proxy(&self, to: ManagedAddress) + -> farm_with_locked_rewards::Proxy; } diff --git a/locked-asset/proxy_dex/src/lib.rs b/locked-asset/proxy_dex/src/lib.rs index 6dde5c483..810cd3640 100644 --- a/locked-asset/proxy_dex/src/lib.rs +++ b/locked-asset/proxy_dex/src/lib.rs @@ -9,11 +9,11 @@ pub mod energy_update; pub mod events; pub mod external_merging; pub mod farm_interactions; +pub mod other_sc_whitelist; pub mod pair_interactions; pub mod proxy_common; pub mod proxy_farm; pub mod proxy_pair; -pub mod sc_whitelist; pub mod wrapped_farm_attributes; pub mod wrapped_farm_token_merge; pub mod wrapped_lp_attributes; @@ -22,7 +22,7 @@ pub mod wrapped_lp_token_merge; #[multiversx_sc::contract] pub trait ProxyDexImpl: proxy_common::ProxyCommonModule - + sc_whitelist::ScWhitelistModule + + crate::other_sc_whitelist::OtherScWhitelistModule + proxy_pair::ProxyPairModule + pair_interactions::PairInteractionsModule + proxy_farm::ProxyFarmModule @@ -37,6 +37,7 @@ pub trait ProxyDexImpl: + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + utils::UtilsModule + legacy_token_decode_module::LegacyTokenDecodeModule + + sc_whitelist_module::SCWhitelistModule { #[init] fn init( @@ -57,6 +58,20 @@ pub trait ProxyDexImpl: .set_if_empty(&energy_factory_address); } + #[endpoint] + fn upgrade(&self, old_locked_token_id: TokenIdentifier, old_factory_address: ManagedAddress) { + require!( + old_locked_token_id.is_valid_esdt_identifier(), + "Invalid token id" + ); + self.require_sc_address(&old_factory_address); + + self.old_locked_token_id() + .set_if_empty(&old_locked_token_id); + self.old_factory_address() + .set_if_empty(&old_factory_address); + } + #[only_owner] #[payable("EGLD")] #[endpoint(registerProxyPair)] @@ -66,7 +81,7 @@ pub trait ProxyDexImpl: token_ticker: ManagedBuffer, num_decimals: usize, ) { - let register_cost = self.call_value().egld_value(); + let register_cost = self.call_value().egld_value().clone_value(); self.wrapped_lp_token().issue_and_set_all_roles( EsdtTokenType::Meta, register_cost, @@ -101,7 +116,7 @@ pub trait ProxyDexImpl: token_ticker: ManagedBuffer, num_decimals: usize, ) { - let register_cost = self.call_value().egld_value(); + let register_cost = self.call_value().egld_value().clone_value(); self.wrapped_farm_token().issue_and_set_all_roles( EsdtTokenType::Meta, register_cost, diff --git a/locked-asset/proxy_dex/src/sc_whitelist.rs b/locked-asset/proxy_dex/src/other_sc_whitelist.rs similarity index 97% rename from locked-asset/proxy_dex/src/sc_whitelist.rs rename to locked-asset/proxy_dex/src/other_sc_whitelist.rs index d89b767f8..5fe43bffd 100644 --- a/locked-asset/proxy_dex/src/sc_whitelist.rs +++ b/locked-asset/proxy_dex/src/other_sc_whitelist.rs @@ -1,7 +1,7 @@ multiversx_sc::imports!(); #[multiversx_sc::module] -pub trait ScWhitelistModule { +pub trait OtherScWhitelistModule { #[only_owner] #[endpoint(addPairToIntermediate)] fn add_pair_to_intermediate(&self, pair_address: ManagedAddress) { diff --git a/locked-asset/proxy_dex/src/pair_interactions.rs b/locked-asset/proxy_dex/src/pair_interactions.rs index 40b6b46a9..7e959a4e1 100644 --- a/locked-asset/proxy_dex/src/pair_interactions.rs +++ b/locked-asset/proxy_dex/src/pair_interactions.rs @@ -1,6 +1,10 @@ multiversx_sc::imports!(); -use pair::{AddLiquidityResultType, ProxyTrait as _, RemoveLiquidityResultType}; +use pair::pair_actions::{ + add_liq::ProxyTrait as _, + common_result_types::{AddLiquidityResultType, RemoveLiquidityResultType}, + remove_liq::ProxyTrait as _, +}; pub struct AddLiquidityResultWrapper { pub lp_tokens_received: EsdtTokenPayment, diff --git a/locked-asset/proxy_dex/src/proxy_common.rs b/locked-asset/proxy_dex/src/proxy_common.rs index ff050e729..16608b2e9 100644 --- a/locked-asset/proxy_dex/src/proxy_common.rs +++ b/locked-asset/proxy_dex/src/proxy_common.rs @@ -135,8 +135,8 @@ pub trait ProxyCommonModule: energy_query::EnergyQueryModule { let new_token_id = self.get_locked_token_id(); let old_token_id = self.old_locked_token_id().get(); let mut results = MultiValueEncoded::new(); - results.push(new_token_id); results.push(old_token_id); + results.push(new_token_id); results } diff --git a/locked-asset/proxy_dex/src/proxy_farm.rs b/locked-asset/proxy_dex/src/proxy_farm.rs index beb6cf425..b90f00f69 100644 --- a/locked-asset/proxy_dex/src/proxy_farm.rs +++ b/locked-asset/proxy_dex/src/proxy_farm.rs @@ -3,6 +3,7 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); +use common_structs::Epoch; use fixed_supply_token::FixedSupplyToken; use crate::{ @@ -11,19 +12,20 @@ use crate::{ wrapped_lp_attributes::WrappedLpTokenAttributes, }; -pub struct FarmingFarmTokenPair { +pub struct EnterFarmResult { pub farming_token: EsdtTokenPayment, pub farm_token: EsdtTokenPayment, + pub rewards: EsdtTokenPayment, } -pub type ExitFarmProxyResultType = - MultiValue3, EsdtTokenPayment, EsdtTokenPayment>; +pub type EnterFarmProxyResultType = MultiValue2, EsdtTokenPayment>; +pub type ExitFarmProxyResultType = MultiValue2, EsdtTokenPayment>; pub type ClaimRewardsFarmProxyResultType = MultiValue2, EsdtTokenPayment>; #[multiversx_sc::module] pub trait ProxyFarmModule: crate::proxy_common::ProxyCommonModule - + crate::sc_whitelist::ScWhitelistModule + + crate::other_sc_whitelist::OtherScWhitelistModule + crate::proxy_pair::ProxyPairModule + crate::pair_interactions::PairInteractionsModule + crate::farm_interactions::FarmInteractionsModule @@ -36,30 +38,44 @@ pub trait ProxyFarmModule: + crate::events::EventsModule + utils::UtilsModule + legacy_token_decode_module::LegacyTokenDecodeModule + + sc_whitelist_module::SCWhitelistModule { #[payable("*")] #[endpoint(enterFarmProxy)] - fn enter_farm_proxy_endpoint(&self, farm_address: ManagedAddress) -> EsdtTokenPayment { + fn enter_farm_proxy_endpoint( + &self, + farm_address: ManagedAddress, + opt_original_caller: OptionalValue, + ) -> EnterFarmProxyResultType { self.require_is_intermediated_farm(&farm_address); self.require_wrapped_farm_token_id_not_empty(); self.require_wrapped_lp_token_id_not_empty(); let caller = self.blockchain().get_caller(); + let original_caller = self.get_orig_caller_from_opt(&caller, opt_original_caller); + let mut payments = self.get_non_empty_payments(); let proxy_farming_token = self.pop_first_payment(&mut payments); let wrapped_lp_token_id = self.wrapped_lp_token().get_token_id(); - let farm_farming_token_pair = if self.is_locked_token(&proxy_farming_token.token_identifier) - { - self.enter_farm_locked_token(farm_address.clone(), proxy_farming_token.clone()) + let enter_result = if self.is_locked_token(&proxy_farming_token.token_identifier) { + self.enter_farm_locked_token( + original_caller.clone(), + farm_address.clone(), + proxy_farming_token.clone(), + ) } else if proxy_farming_token.token_identifier == wrapped_lp_token_id { - self.enter_farm_wrapped_lp(farm_address.clone(), proxy_farming_token.clone()) + self.enter_farm_wrapped_lp( + original_caller.clone(), + farm_address.clone(), + proxy_farming_token.clone(), + ) } else { sc_panic!(INVALID_PAYMENTS_ERR_MSG) }; let new_token_attributes = WrappedFarmTokenAttributes { - farm_token: farm_farming_token_pair.farm_token, + farm_token: enter_result.farm_token, proxy_farming_token, }; @@ -72,7 +88,7 @@ pub trait ProxyFarmModule: self.send().esdt_local_burn_multi(&payments); self.merge_wrapped_farm_tokens_with_virtual_pos( - &caller, + &original_caller, farm_address.clone(), wrapped_lp_tokens, new_token_attributes, @@ -89,46 +105,51 @@ pub trait ProxyFarmModule: }; self.send_payment_non_zero(&caller, &new_wrapped_farm_token.payment); + self.send_payment_non_zero(&caller, &enter_result.rewards); self.emit_enter_farm_proxy_event( - &caller, + &original_caller, &farm_address, - farm_farming_token_pair.farming_token, + enter_result.farming_token, new_wrapped_farm_token.payment.clone(), new_wrapped_farm_token.attributes, token_merge_requested, ); - new_wrapped_farm_token.payment + (new_wrapped_farm_token.payment, enter_result.rewards).into() } fn enter_farm_locked_token( &self, + user: ManagedAddress, farm_address: ManagedAddress, locked_token: EsdtTokenPayment, - ) -> FarmingFarmTokenPair { + ) -> EnterFarmResult { let asset_token_id = self.get_base_token_id(); self.send() .esdt_local_mint(&asset_token_id, 0, &locked_token.amount); let minted_asset_tokens = EsdtTokenPayment::new(asset_token_id, 0, locked_token.amount); let enter_result = self.call_enter_farm( + user, farm_address, minted_asset_tokens.token_identifier.clone(), minted_asset_tokens.amount.clone(), ); - FarmingFarmTokenPair { + EnterFarmResult { farming_token: minted_asset_tokens, farm_token: enter_result.farm_token, + rewards: enter_result.reward_token, } } fn enter_farm_wrapped_lp( &self, + user: ManagedAddress, farm_address: ManagedAddress, wrapped_lp_token: EsdtTokenPayment, - ) -> FarmingFarmTokenPair { + ) -> EnterFarmResult { let wrapped_lp_token_mapper = self.wrapped_lp_token(); let wrapped_lp_attributes: WrappedLpTokenAttributes = self .get_attributes_as_part_of_fixed_supply(&wrapped_lp_token, &wrapped_lp_token_mapper); @@ -139,14 +160,16 @@ pub trait ProxyFarmModule: wrapped_lp_attributes.lp_token_amount, ); let enter_result = self.call_enter_farm( + user, farm_address, farming_token.token_identifier.clone(), farming_token.amount.clone(), ); - FarmingFarmTokenPair { + EnterFarmResult { farming_token, farm_token: enter_result.farm_token, + rewards: enter_result.reward_token, } } @@ -155,7 +178,7 @@ pub trait ProxyFarmModule: fn exit_farm_proxy( &self, farm_address: ManagedAddress, - exit_amount: BigUint, + opt_original_caller: OptionalValue, ) -> ExitFarmProxyResultType { self.require_is_intermediated_farm(&farm_address); self.require_wrapped_farm_token_id_not_empty(); @@ -170,57 +193,45 @@ pub trait ProxyFarmModule: .get_token_attributes(&payment.token_identifier, payment.token_nonce); let wrapped_farm_attributes_for_exit: WrappedFarmTokenAttributes = - full_wrapped_farm_attributes - .clone() - .into_part(&payment.amount); + full_wrapped_farm_attributes.into_part(&payment.amount); + + let caller = self.blockchain().get_caller(); + let original_caller = self.get_orig_caller_from_opt(&caller, opt_original_caller); + let exit_result = self.call_exit_farm( + original_caller.clone(), farm_address.clone(), - wrapped_farm_attributes_for_exit.farm_token, - exit_amount.clone(), + wrapped_farm_attributes_for_exit.farm_token.clone(), ); - let mut remaining_wrapped_tokens = payment.clone(); - remaining_wrapped_tokens.amount = exit_result.remaining_farm_tokens.amount; - self.burn_if_base_asset(&exit_result.farming_tokens); - let mut payment_used_for_exit = payment.clone(); - payment_used_for_exit.amount = exit_amount.clone(); - let wrapped_attributes_used_for_exit_farm: WrappedFarmTokenAttributes = - full_wrapped_farm_attributes.into_part(&exit_amount); let wrapped_farm_tokens_for_initial_tokens = WrappedFarmToken { - payment: payment_used_for_exit, - attributes: wrapped_attributes_used_for_exit_farm.clone(), + payment: payment.clone(), + attributes: wrapped_farm_attributes_for_exit.clone(), }; - let caller = self.blockchain().get_caller(); let initial_proxy_farming_tokens = self .handle_farm_penalty_and_get_output_proxy_farming_token( - &caller, + &original_caller, wrapped_farm_tokens_for_initial_tokens, exit_result.farming_tokens.amount, ); self.send_payment_non_zero(&caller, &initial_proxy_farming_tokens); self.send_payment_non_zero(&caller, &exit_result.reward_tokens); - self.send_payment_non_zero(&caller, &remaining_wrapped_tokens); - wrapped_farm_token_mapper.nft_burn(payment.token_nonce, &exit_amount); + wrapped_farm_token_mapper.nft_burn(payment.token_nonce, &payment.amount); self.emit_exit_farm_proxy_event( - &caller, + &original_caller, &farm_address, payment, - wrapped_attributes_used_for_exit_farm, + wrapped_farm_attributes_for_exit, exit_result.reward_tokens.clone(), ); - ( - initial_proxy_farming_tokens, - exit_result.reward_tokens, - remaining_wrapped_tokens, - ) - .into() + (initial_proxy_farming_tokens, exit_result.reward_tokens).into() } fn handle_farm_penalty_and_get_output_proxy_farming_token( @@ -280,6 +291,7 @@ pub trait ProxyFarmModule: fn claim_rewards_proxy( &self, farm_address: ManagedAddress, + opt_original_caller: OptionalValue, ) -> ClaimRewardsFarmProxyResultType { self.require_is_intermediated_farm(&farm_address); self.require_wrapped_farm_token_id_not_empty(); @@ -291,7 +303,12 @@ pub trait ProxyFarmModule: let wrapped_farm_attributes: WrappedFarmTokenAttributes = self.get_attributes_as_part_of_fixed_supply(&payment, &wrapped_farm_token_mapper); + + let caller = self.blockchain().get_caller(); + let original_caller = self.get_orig_caller_from_opt(&caller, opt_original_caller); + let claim_result = self.call_claim_rewards_farm( + original_caller.clone(), farm_address.clone(), wrapped_farm_attributes.farm_token.clone(), ); @@ -304,12 +321,14 @@ pub trait ProxyFarmModule: let new_wrapped_token = wrapped_farm_token_mapper.nft_create(new_token_amount, &new_wrapped_farm_attributes); - let caller = self.blockchain().get_caller(); self.send_payment_non_zero(&caller, &new_wrapped_token); self.send_payment_non_zero(&caller, &claim_result.rewards); + // Burn farm token + wrapped_farm_token_mapper.nft_burn(payment.token_nonce, &payment.amount); + self.emit_claim_rewards_farm_proxy_event( - &caller, + &original_caller, &farm_address, payment, wrapped_farm_attributes, @@ -321,6 +340,88 @@ pub trait ProxyFarmModule: (new_wrapped_token, claim_result.rewards).into() } + #[payable("*")] + #[endpoint(increaseProxyFarmTokenEnergy)] + fn increase_proxy_farm_token_energy_endpoint(&self, lock_epochs: Epoch) -> EsdtTokenPayment { + self.require_wrapped_farm_token_id_not_empty(); + self.require_wrapped_lp_token_id_not_empty(); + + let wrapped_farm_token_mapper = self.wrapped_farm_token(); + let payment = self.call_value().single_esdt(); + wrapped_farm_token_mapper.require_same_token(&payment.token_identifier); + + let wrapped_farm_attributes: WrappedFarmTokenAttributes = + self.get_attributes_as_part_of_fixed_supply(&payment, &wrapped_farm_token_mapper); + + let caller = self.blockchain().get_caller(); + let new_locked_token_id = self.get_locked_token_id(); + let wrapped_lp_token_id = self.wrapped_lp_token().get_token_id(); + + let new_attributes = if wrapped_farm_attributes.proxy_farming_token.token_identifier + == new_locked_token_id + { + let energy_factory_addr = self.energy_factory_address().get(); + let new_locked_token = self.call_increase_energy( + caller.clone(), + wrapped_farm_attributes.proxy_farming_token, + lock_epochs, + energy_factory_addr, + ); + + WrappedFarmTokenAttributes { + farm_token: wrapped_farm_attributes.farm_token, + proxy_farming_token: new_locked_token, + } + } else if wrapped_farm_attributes.proxy_farming_token.token_identifier + == wrapped_lp_token_id + { + let wrapped_lp_mapper = self.wrapped_lp_token(); + let wrapped_lp_attributes: WrappedLpTokenAttributes = self + .get_attributes_as_part_of_fixed_supply( + &wrapped_farm_attributes.proxy_farming_token, + &wrapped_lp_mapper, + ); + let new_locked_tokens = self.increase_proxy_pair_token_energy( + caller.clone(), + lock_epochs, + &wrapped_lp_attributes, + ); + + let new_wrapped_lp_attributes = WrappedLpTokenAttributes { + locked_tokens: new_locked_tokens, + lp_token_id: wrapped_lp_attributes.lp_token_id, + lp_token_amount: wrapped_lp_attributes.lp_token_amount, + }; + + let new_token_amount = new_wrapped_lp_attributes.get_total_supply(); + let new_wrapped_lp = + wrapped_lp_mapper.nft_create(new_token_amount, &new_wrapped_lp_attributes); + + self.send().esdt_local_burn( + &wrapped_farm_attributes.proxy_farming_token.token_identifier, + wrapped_farm_attributes.proxy_farming_token.token_nonce, + &wrapped_farm_attributes.proxy_farming_token.amount, + ); + + WrappedFarmTokenAttributes { + farm_token: wrapped_farm_attributes.farm_token, + proxy_farming_token: new_wrapped_lp, + } + } else { + sc_panic!(INVALID_PAYMENTS_ERR_MSG) + }; + + self.send().esdt_local_burn( + &payment.token_identifier, + payment.token_nonce, + &payment.amount, + ); + + let new_token_amount = new_attributes.get_total_supply(); + + wrapped_farm_token_mapper.nft_create_and_send(&caller, new_token_amount, &new_attributes) + } + fn require_wrapped_farm_token_id_not_empty(&self) { require!(!self.wrapped_farm_token().is_empty(), "Empty token id"); } diff --git a/locked-asset/proxy_dex/src/proxy_pair.rs b/locked-asset/proxy_dex/src/proxy_pair.rs index 5045e0961..79542f06a 100644 --- a/locked-asset/proxy_dex/src/proxy_pair.rs +++ b/locked-asset/proxy_dex/src/proxy_pair.rs @@ -6,19 +6,20 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); use crate::wrapped_lp_attributes::{WrappedLpToken, WrappedLpTokenAttributes}; +use common_structs::Epoch; use fixed_supply_token::FixedSupplyToken; #[multiversx_sc::module] pub trait ProxyPairModule: crate::proxy_common::ProxyCommonModule - + crate::sc_whitelist::ScWhitelistModule + + crate::other_sc_whitelist::OtherScWhitelistModule + crate::pair_interactions::PairInteractionsModule + crate::wrapped_lp_token_merge::WrappedLpTokenMerge + crate::energy_update::EnergyUpdateModule + + crate::events::EventsModule + energy_query::EnergyQueryModule + token_merge_helper::TokenMergeHelperModule + token_send::TokenSendModule - + crate::events::EventsModule + utils::UtilsModule + legacy_token_decode_module::LegacyTokenDecodeModule { @@ -142,12 +143,32 @@ pub trait ProxyPairModule: self.require_wrapped_lp_token_id_not_empty(); let payment = self.call_value().single_esdt(); + + let output_payments = self.remove_liquidity_proxy_common( + payment, + pair_address, + first_token_amount_min, + second_token_amount_min, + ); + let caller = self.blockchain().get_caller(); + self.send_multiple_tokens_if_not_zero(&caller, &output_payments); + + output_payments.into() + } + + fn remove_liquidity_proxy_common( + &self, + input_payment: EsdtTokenPayment, + pair_address: ManagedAddress, + first_token_amount_min: BigUint, + second_token_amount_min: BigUint, + ) -> ManagedVec { let wrapped_lp_mapper = self.wrapped_lp_token(); - wrapped_lp_mapper.require_same_token(&payment.token_identifier); + wrapped_lp_mapper.require_same_token(&input_payment.token_identifier); let caller = self.blockchain().get_caller(); let attributes: WrappedLpTokenAttributes = - self.get_attributes_as_part_of_fixed_supply(&payment, &wrapped_lp_mapper); + self.get_attributes_as_part_of_fixed_supply(&input_payment, &wrapped_lp_mapper); let remove_liq_result = self.call_remove_liquidity( pair_address.clone(), @@ -205,20 +226,71 @@ pub trait ProxyPairModule: let other_tokens = received_token_refs.other_token_ref.clone(); output_payments.push(other_tokens); - wrapped_lp_mapper.nft_burn(payment.token_nonce, &payment.amount); - - self.send_multiple_tokens_if_not_zero(&caller, &output_payments); + wrapped_lp_mapper.nft_burn(input_payment.token_nonce, &input_payment.amount); self.emit_remove_liquidity_proxy_event( &caller, &pair_address, - payment, + input_payment, attributes, remove_liq_result.first_token_received, remove_liq_result.second_token_received, ); - output_payments.into() + output_payments + } + + #[payable("*")] + #[endpoint(increaseProxyPairTokenEnergy)] + fn increase_proxy_pair_token_energy_endpoint(&self, lock_epochs: Epoch) -> EsdtTokenPayment { + self.require_wrapped_lp_token_id_not_empty(); + + let payment = self.call_value().single_esdt(); + let wrapped_lp_mapper = self.wrapped_lp_token(); + wrapped_lp_mapper.require_same_token(&payment.token_identifier); + + let caller = self.blockchain().get_caller(); + let old_attributes: WrappedLpTokenAttributes = + self.get_attributes_as_part_of_fixed_supply(&payment, &wrapped_lp_mapper); + + let new_locked_tokens = + self.increase_proxy_pair_token_energy(caller.clone(), lock_epochs, &old_attributes); + let new_token_attributes = WrappedLpTokenAttributes { + locked_tokens: new_locked_tokens, + lp_token_id: old_attributes.lp_token_id, + lp_token_amount: old_attributes.lp_token_amount, + }; + + self.send().esdt_local_burn( + &payment.token_identifier, + payment.token_nonce, + &payment.amount, + ); + + let new_token_amount = new_token_attributes.get_total_supply(); + + wrapped_lp_mapper.nft_create_and_send(&caller, new_token_amount, &new_token_attributes) + } + + fn increase_proxy_pair_token_energy( + &self, + user: ManagedAddress, + lock_epochs: Epoch, + old_attributes: &WrappedLpTokenAttributes, + ) -> EsdtTokenPayment { + let new_locked_token_id = self.get_locked_token_id(); + require!( + old_attributes.locked_tokens.token_identifier == new_locked_token_id, + "Invalid payment" + ); + + let energy_factory_addr = self.energy_factory_address().get(); + self.call_increase_energy( + user, + old_attributes.locked_tokens.clone(), + lock_epochs, + energy_factory_addr, + ) } fn require_wrapped_lp_token_id_not_empty(&self) { diff --git a/locked-asset/proxy_dex/src/wrapped_farm_token_merge.rs b/locked-asset/proxy_dex/src/wrapped_farm_token_merge.rs index f4052f337..5b071a2f1 100644 --- a/locked-asset/proxy_dex/src/wrapped_farm_token_merge.rs +++ b/locked-asset/proxy_dex/src/wrapped_farm_token_merge.rs @@ -13,7 +13,7 @@ use fixed_supply_token::FixedSupplyToken; pub trait WrappedFarmTokenMerge: token_merge_helper::TokenMergeHelperModule + token_send::TokenSendModule - + crate::sc_whitelist::ScWhitelistModule + + crate::other_sc_whitelist::OtherScWhitelistModule + crate::proxy_common::ProxyCommonModule + crate::wrapped_lp_token_merge::WrappedLpTokenMerge + utils::UtilsModule 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 1fdff8d2b..2ab0326d4 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,3 +1,5 @@ +#![allow(deprecated)] + use config::ConfigModule; use energy_factory::{locked_token_transfer::LockedTokenTransferModule, SimpleLockEnergy}; use energy_query::EnergyQueryModule; @@ -14,12 +16,14 @@ use multiversx_sc::{ use multiversx_sc_modules::pause::PauseModule; use multiversx_sc_scenario::{ managed_address, managed_biguint, managed_token_id, managed_token_id_wrapped, rust_biguint, - whitebox::{BlockchainStateWrapper, ContractObjWrapper}, + whitebox_legacy::{BlockchainStateWrapper, ContractObjWrapper}, DebugApi, }; use pair::{config::ConfigModule as OtherConfigModule, Pair}; use pausable::{PausableModule, State}; -use proxy_dex::{proxy_common::ProxyCommonModule, sc_whitelist::ScWhitelistModule, ProxyDexImpl}; +use proxy_dex::{ + other_sc_whitelist::OtherScWhitelistModule, proxy_common::ProxyCommonModule, ProxyDexImpl, +}; use sc_whitelist_module::SCWhitelistModule; use simple_lock::locked_token::{LockedTokenAttributes, LockedTokenModule}; @@ -85,7 +89,7 @@ where farm_locked_builder: FarmLockedObjBuilder, simple_lock_builder: SimpleLockObjBuilder, ) -> Self { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0); let mut b_mock = BlockchainStateWrapper::new(); @@ -313,6 +317,8 @@ where ); sc.set_locking_sc_address(managed_address!(simple_lock_addr)); sc.set_lock_epochs(EPOCHS_IN_YEAR); + sc.energy_factory_address() + .set(managed_address!(simple_lock_addr)); }) .assert_ok(); diff --git a/locked-asset/proxy_dex/tests/proxy_farm_test.rs b/locked-asset/proxy_dex/tests/proxy_farm_test.rs index 9fb12d6f4..b2acafc94 100644 --- a/locked-asset/proxy_dex/tests/proxy_farm_test.rs +++ b/locked-asset/proxy_dex/tests/proxy_farm_test.rs @@ -1,17 +1,19 @@ +#![allow(deprecated)] + mod proxy_dex_test_setup; use common_structs::FarmTokenAttributes; use config::ConfigModule; -use energy_factory::energy::EnergyModule; +use energy_factory::{energy::EnergyModule, SimpleLockEnergy}; use energy_query::Energy; use farm::exit_penalty::{DEFAULT_PENALTY_PERCENT, MAX_PERCENT}; use multiversx_sc::{ - codec::Empty, + codec::{multi_types::OptionalValue, Empty}, types::{BigInt, EsdtLocalRole, EsdtTokenPayment}, }; use multiversx_sc_scenario::{ - managed_address, managed_biguint, managed_token_id, rust_biguint, whitebox::TxTokenTransfer, - DebugApi, + managed_address, managed_biguint, managed_token_id, managed_token_id_wrapped, rust_biguint, + whitebox_legacy::TxTokenTransfer, DebugApi, }; use num_traits::ToPrimitive; use proxy_dex::{ @@ -21,6 +23,7 @@ use proxy_dex::{ wrapped_lp_attributes::WrappedLpTokenAttributes, }; use proxy_dex_test_setup::*; +use simple_lock::locked_token::LockedTokenAttributes; #[test] fn farm_proxy_setup_test() { @@ -54,7 +57,7 @@ fn farm_proxy_actions_test() { 1, &rust_biguint!(USER_BALANCE), |sc| { - sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr)); + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); }, ) .assert_ok(); @@ -119,7 +122,7 @@ fn farm_proxy_actions_test() { 1, &rust_biguint!(USER_BALANCE / 2), |sc| { - sc.claim_rewards_proxy(managed_address!(&farm_addr)); + sc.claim_rewards_proxy(managed_address!(&farm_addr), OptionalValue::None); }, ) .assert_ok(); @@ -208,7 +211,7 @@ fn farm_proxy_actions_test() { Some(&WrappedFarmTokenAttributes:: { proxy_farming_token: EsdtTokenPayment { token_identifier: managed_token_id!(LOCKED_TOKEN_ID), - token_nonce: 3, + token_nonce: 1, amount: managed_biguint!(USER_BALANCE), }, farm_token: EsdtTokenPayment { @@ -218,6 +221,45 @@ fn farm_proxy_actions_test() { }, }), ); + + // Check balance before exit farm proxy + setup.b_mock.check_nft_balance::( + &first_user, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(0), + None, + ); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_FARM_TOKEN_ID, + 3, + &rust_biguint!(USER_BALANCE), + |sc| { + let output = sc.exit_farm_proxy(managed_address!(&farm_addr), OptionalValue::None); + let output_lp_token = output.0 .0; + assert_eq!(output_lp_token.token_nonce, 1); + assert_eq!(output_lp_token.amount, USER_BALANCE); + }, + ) + .assert_ok(); + + // Check balance after exit farm proxy + setup.b_mock.check_nft_balance( + &first_user, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + Some(&LockedTokenAttributes:: { + original_token_id: managed_token_id_wrapped!(MEX_TOKEN_ID), + original_token_nonce: 0, + unlock_epoch: LOCK_OPTIONS[0], + }), + ); } #[test] @@ -333,7 +375,10 @@ fn farm_with_wrapped_lp_test() { 1, &expected_lp_token_amount, |sc| { - sc.enter_farm_proxy_endpoint(managed_address!(&farm_locked_addr)); + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_locked_addr), + OptionalValue::None, + ); }, ) .assert_ok(); @@ -399,12 +444,9 @@ fn farm_with_wrapped_lp_test() { &setup.proxy_wrapper, WRAPPED_FARM_TOKEN_ID, 1, - &expected_lp_token_amount, + &(expected_lp_token_amount.clone() / rust_biguint!(2)), |sc| { - sc.exit_farm_proxy( - managed_address!(&farm_locked_addr), - managed_biguint!(expected_lp_token_amount.to_u64().unwrap() / 2), - ); + sc.exit_farm_proxy(managed_address!(&farm_locked_addr), OptionalValue::None); }, ) .assert_ok(); @@ -506,7 +548,10 @@ fn farm_proxy_claim_energy_test() { 1, &rust_biguint!(USER_BALANCE), |sc| { - sc.enter_farm_proxy_endpoint(managed_address!(&farm_locked_addr)); + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_locked_addr), + OptionalValue::None, + ); }, ) .assert_ok(); @@ -580,7 +625,7 @@ fn farm_proxy_claim_energy_test() { 1, &rust_biguint!(USER_BALANCE), |sc| { - sc.claim_rewards_proxy(managed_address!(&farm_locked_addr)); + sc.claim_rewards_proxy(managed_address!(&farm_locked_addr), OptionalValue::None); }, ) .assert_ok(); @@ -641,7 +686,10 @@ fn farm_proxy_partial_exit_test() { 1, &rust_biguint!(USER_BALANCE), |sc| { - sc.enter_farm_proxy_endpoint(managed_address!(&farm_locked_addr)); + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_locked_addr), + OptionalValue::None, + ); }, ) .assert_ok(); @@ -715,12 +763,9 @@ fn farm_proxy_partial_exit_test() { &setup.proxy_wrapper, WRAPPED_FARM_TOKEN_ID, 1, - &rust_biguint!(USER_BALANCE), + &rust_biguint!(USER_BALANCE / 2), |sc| { - sc.exit_farm_proxy( - managed_address!(&farm_locked_addr), - managed_biguint!(USER_BALANCE / 2), - ); + sc.exit_farm_proxy(managed_address!(&farm_locked_addr), OptionalValue::None); }, ) .assert_ok(); @@ -819,7 +864,10 @@ fn farm_proxy_partial_exit_with_penalty_test() { 1, &rust_biguint!(USER_BALANCE), |sc| { - sc.enter_farm_proxy_endpoint(managed_address!(&farm_locked_addr)); + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_locked_addr), + OptionalValue::None, + ); }, ) .assert_ok(); @@ -893,12 +941,9 @@ fn farm_proxy_partial_exit_with_penalty_test() { &setup.proxy_wrapper, WRAPPED_FARM_TOKEN_ID, 1, - &rust_biguint!(USER_BALANCE), + &rust_biguint!(USER_BALANCE / 2), |sc| { - sc.exit_farm_proxy( - managed_address!(&farm_locked_addr), - managed_biguint!(USER_BALANCE / 2), - ); + sc.exit_farm_proxy(managed_address!(&farm_locked_addr), OptionalValue::None); }, ) .assert_ok(); @@ -965,3 +1010,478 @@ fn farm_proxy_partial_exit_with_penalty_test() { &rust_biguint!(USER_BALANCE / 2), ); } + +#[test] +fn different_farm_locked_token_nonce_merging_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), 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.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), + }, + }), + ); + + //////////////////////////////////////////// MERGE 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(); + + // check user balance + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_FARM_TOKEN_ID, + 3, + &rust_biguint!(USER_BALANCE * 2), + Some(&WrappedFarmTokenAttributes:: { + proxy_farming_token: EsdtTokenPayment { + token_identifier: managed_token_id!(LOCKED_TOKEN_ID), + token_nonce: 3, + amount: managed_biguint!(USER_BALANCE * 2), + }, + farm_token: EsdtTokenPayment { + token_identifier: managed_token_id!(FARM_LOCKED_TOKEN_ID), + token_nonce: 3, + amount: managed_biguint!(USER_BALANCE * 2), + }, + }), + ); + + 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(); + + let expected_unlock_epoch = (LOCK_OPTIONS[0] + LOCK_OPTIONS[1]) / 2; + setup.b_mock.check_nft_balance( + &first_user, + LOCKED_TOKEN_ID, + 3, + &rust_biguint!(1_980_000_000_000_000_000u64), + Some(&LockedTokenAttributes:: { + original_token_id: managed_token_id_wrapped!(MEX_TOKEN_ID), + original_token_nonce: 0, + unlock_epoch: expected_unlock_epoch, + }), + ); +} + +#[test] +fn increase_proxy_farm_lkmex_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 farm_addr = setup.farm_locked_wrapper.address_ref().clone(); + + //////////////////////////////////////////// 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(); + + 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.user_energy(&managed_address!(&first_user)).get(); + assert_eq!(expected_energy, actual_energy); + }) + .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_ok(); + + // check user energy after + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let lock_epochs = LOCK_OPTIONS[1] - 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.user_energy(&managed_address!(&first_user)).get(); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); +} + +#[test] +fn increase_proxy_farm_proxy_lp_energy() { + 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.user_energy(&managed_address!(&first_user)).get(); + 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!(4u64)), + |sc| { + sc.increase_proxy_farm_token_energy_endpoint(LOCK_OPTIONS[1]); + }, + ) + .assert_ok(); + + // 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] - block_epoch; + let second_lock_epochs = LOCK_OPTIONS[0] - block_epoch; + 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) + * BigInt::from(second_lock_epochs as i64); + let expected_energy = Energy::new( + expected_energy_amount, + block_epoch, + managed_biguint!(USER_BALANCE), + ); + let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); + 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), + }, + }), + ); +} diff --git a/locked-asset/proxy_dex/tests/proxy_lp_test.rs b/locked-asset/proxy_dex/tests/proxy_lp_test.rs index 69237f7ff..9c3710bb7 100644 --- a/locked-asset/proxy_dex/tests/proxy_lp_test.rs +++ b/locked-asset/proxy_dex/tests/proxy_lp_test.rs @@ -1,14 +1,16 @@ +#![allow(deprecated)] + mod proxy_dex_test_setup; -use energy_factory::energy::EnergyModule; +use energy_factory::{energy::EnergyModule, SimpleLockEnergy}; use energy_query::Energy; use multiversx_sc::{ - codec::Empty, + codec::{multi_types::OptionalValue, Empty}, types::{BigInt, EsdtTokenPayment}, }; use multiversx_sc_scenario::{ - managed_address, managed_biguint, managed_token_id, rust_biguint, whitebox::TxTokenTransfer, - DebugApi, + managed_address, managed_biguint, managed_token_id, managed_token_id_wrapped, rust_biguint, + whitebox_legacy::TxTokenTransfer, DebugApi, }; use num_traits::ToPrimitive; use proxy_dex::{ @@ -16,6 +18,7 @@ use proxy_dex::{ wrapped_lp_token_merge::WrappedLpTokenMerge, }; use proxy_dex_test_setup::*; +use simple_lock::locked_token::LockedTokenAttributes; #[test] fn setup_test() { @@ -494,7 +497,7 @@ fn tripple_add_liquidity_proxy_test() { } #[test] -fn wrapped_lp_token_merge_test() { +fn wrapped_same_nonce_lp_token_merge_test() { let mut setup = ProxySetup::new( proxy_dex::contract_obj, pair::contract_obj, @@ -539,12 +542,12 @@ fn wrapped_lp_token_merge_test() { TxTokenTransfer { token_identifier: WRAPPED_LP_TOKEN_ID.to_vec(), nonce: 1, - value: first_amount, + value: first_amount.clone(), }, TxTokenTransfer { token_identifier: WRAPPED_LP_TOKEN_ID.to_vec(), nonce: 1, - value: second_amount, + value: second_amount.clone(), }, ]; @@ -563,11 +566,378 @@ fn wrapped_lp_token_merge_test() { Some(&WrappedLpTokenAttributes:: { locked_tokens: EsdtTokenPayment { token_identifier: managed_token_id!(LOCKED_TOKEN_ID), - token_nonce: 3, + token_nonce: 1, amount: managed_biguint!(800_001_600), // out of 1_000_000_000 }, lp_token_id: managed_token_id!(LP_TOKEN_ID), lp_token_amount: managed_biguint!(400_000_000), }), ); + + let liquidity_token_amount = (&first_amount + &second_amount) * rust_biguint!(2u64); // parity 1 EGLD -> 2 MEX + let expected_locked_token_balance_before = rust_biguint!(USER_BALANCE) - locked_token_amount; + let expected_locked_token_balance_after = + &expected_locked_token_balance_before + &liquidity_token_amount; + + setup.b_mock.check_nft_balance( + &first_user, + LOCKED_TOKEN_ID, + 1, + &(expected_locked_token_balance_before), + Some(&LockedTokenAttributes:: { + original_token_id: managed_token_id_wrapped!(MEX_TOKEN_ID), + original_token_nonce: 0, + unlock_epoch: LOCK_OPTIONS[0], + }), + ); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 2, + &(first_amount + second_amount), + |sc| { + sc.remove_liquidity_proxy( + managed_address!(&pair_addr), + managed_biguint!(1), + managed_biguint!(1), + ); + }, + ) + .assert_ok(); + + setup.b_mock.check_nft_balance( + &first_user, + LOCKED_TOKEN_ID, + 1, + &expected_locked_token_balance_after, + Some(&LockedTokenAttributes:: { + original_token_id: managed_token_id_wrapped!(MEX_TOKEN_ID), + original_token_nonce: 0, + unlock_epoch: LOCK_OPTIONS[0], + }), + ); +} + +#[test] +fn wrapped_different_nonce_lp_token_merge_test() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + let user = setup.first_user.clone(); + let user_balance = rust_biguint!(USER_BALANCE); + setup + .b_mock + .set_esdt_balance(&user, MEX_TOKEN_ID, &user_balance); + + // users lock tokens + setup + .b_mock + .execute_esdt_transfer( + &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 locked_token_amount = rust_biguint!(1_000_000_000); + let other_token_amount = rust_biguint!(500_000_000); + + // set the price to 1 EGLD = 2 MEX + let payments1 = vec![ + TxTokenTransfer { + token_identifier: LOCKED_TOKEN_ID.to_vec(), + nonce: 1, + value: locked_token_amount.clone(), // for MIN_LP_AMOUNT + }, + TxTokenTransfer { + token_identifier: WEGLD_TOKEN_ID.to_vec(), + nonce: 0, + value: other_token_amount.clone(), // for MIN_LP_AMOUNT + }, + ]; + + // add liquidity + let pair_addr = setup.pair_wrapper.address_ref().clone(); + setup + .b_mock + .execute_esdt_multi_transfer(&user, &setup.proxy_wrapper, &payments1, |sc| { + let output_lp_token = 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_eq!(output_lp_token.to_vec().get(0).token_nonce, 1); + assert_eq!( + output_lp_token.to_vec().get(0).amount, + managed_biguint!(500_000_000u64 - 1_000u64) + ); + }) + .assert_ok(); + + // set the price to 1 EGLD = 2 MEX + let payments2 = vec![ + TxTokenTransfer { + token_identifier: LOCKED_TOKEN_ID.to_vec(), + nonce: 2, + 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(&user, &setup.proxy_wrapper, &payments2, |sc| { + let output_lp_token = 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_eq!(output_lp_token.to_vec().get(0).token_nonce, 2); + assert_eq!( + output_lp_token.to_vec().get(0).amount, + managed_biguint!(500_000_000u64) + ); + }) + .assert_ok(); + + let min_lp_amount = 1_000u64; + let first_amount = other_token_amount.clone() - rust_biguint!(min_lp_amount); + let second_amount = other_token_amount.clone(); + let user_lp_amount = 999_999_000u64; // first_amount + second_amount; + let tokens_to_merge = vec![ + TxTokenTransfer { + token_identifier: WRAPPED_LP_TOKEN_ID.to_vec(), + nonce: 1, + value: first_amount, + }, + TxTokenTransfer { + token_identifier: WRAPPED_LP_TOKEN_ID.to_vec(), + nonce: 2, + value: second_amount, + }, + ]; + + setup + .b_mock + .execute_esdt_multi_transfer(&user, &setup.proxy_wrapper, &tokens_to_merge, |sc| { + let output_lp_token = sc.merge_wrapped_lp_tokens_endpoint(); + assert_eq!(output_lp_token.token_nonce, 3); + assert_eq!(output_lp_token.amount, managed_biguint!(user_lp_amount)); + }) + .assert_ok(); + + setup.b_mock.check_nft_balance( + &user, + WRAPPED_LP_TOKEN_ID, + 3, + &rust_biguint!(user_lp_amount), + Some(&WrappedLpTokenAttributes:: { + locked_tokens: EsdtTokenPayment { + token_identifier: managed_token_id!(LOCKED_TOKEN_ID), + token_nonce: 3, + amount: managed_biguint!(2_000_000_000u64), + }, + lp_token_id: managed_token_id!(LP_TOKEN_ID), + lp_token_amount: managed_biguint!(1_000_000_000u64 - min_lp_amount), + }), + ); + + let min_locked_lp_token_amount = rust_biguint!(min_lp_amount); + let expected_locked_token_balance = + &(locked_token_amount - min_locked_lp_token_amount) * rust_biguint!(2); // parity 1 EGLD -> 2 MEX + + setup + .b_mock + .execute_esdt_transfer( + &user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 3, + &rust_biguint!(user_lp_amount), + |sc| { + sc.remove_liquidity_proxy( + managed_address!(&pair_addr), + managed_biguint!(1), + managed_biguint!(1), + ); + }, + ) + .assert_ok(); + + let expected_unlock_epoch = (LOCK_OPTIONS[0] + LOCK_OPTIONS[1]) / 2; + setup.b_mock.check_nft_balance( + &user, + LOCKED_TOKEN_ID, + 3, + &expected_locked_token_balance, + Some(&LockedTokenAttributes:: { + original_token_id: managed_token_id_wrapped!(MEX_TOKEN_ID), + original_token_nonce: 0, + unlock_epoch: expected_unlock_epoch, + }), + ); +} + +#[test] +fn increase_proxy_lp_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: 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.user_energy(&managed_address!(&first_user)).get(); + 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_ok(); + + // chceck 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), + token_nonce: 2, + 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 user energy after + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let first_lock_epochs = LOCK_OPTIONS[1] - block_epoch; + let second_lock_epochs = LOCK_OPTIONS[0] - block_epoch; + 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) + * BigInt::from(second_lock_epochs as i64); + let expected_energy = Energy::new( + expected_energy_amount, + block_epoch, + managed_biguint!(USER_BALANCE), + ); + let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); } diff --git a/locked-asset/proxy_dex/wasm/Cargo.lock b/locked-asset/proxy_dex/wasm/Cargo.lock index fe099d430..7cc65eaa5 100644 --- a/locked-asset/proxy_dex/wasm/Cargo.lock +++ b/locked-asset/proxy_dex/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common-types" @@ -99,9 +76,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "endian-type" @@ -275,15 +252,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -292,9 +260,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "itertools" @@ -314,12 +282,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - [[package]] name = "locking_module" version = "0.0.0" @@ -336,12 +298,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -351,12 +307,11 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -365,20 +320,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -388,9 +342,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -401,21 +355,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -429,19 +382,13 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "pair" version = "0.0.0" @@ -455,6 +402,7 @@ dependencies = [ "permissions_module", "simple-lock", "token_send", + "utils", ] [[package]] @@ -476,9 +424,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] @@ -500,6 +448,7 @@ dependencies = [ "multiversx-sc", "multiversx-sc-modules", "pair", + "sc_whitelist_module", "simple-lock", "token_merge_helper", "token_send", @@ -516,9 +465,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -567,15 +516,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -601,9 +550,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -622,24 +571,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - [[package]] name = "week-timekeeping" version = "0.0.0" @@ -659,25 +590,3 @@ dependencies = [ "unwrappable", "week-timekeeping", ] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/locked-asset/proxy_dex/wasm/Cargo.toml b/locked-asset/proxy_dex/wasm/Cargo.toml index a2523c980..b0753d94f 100644 --- a/locked-asset/proxy_dex/wasm/Cargo.toml +++ b/locked-asset/proxy_dex/wasm/Cargo.toml @@ -1,26 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "proxy_dex-wasm" version = "0.0.0" -authors = ["MultiversX "] edition = "2021" publish = false [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.proxy_dex] -default-features = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/locked-asset/proxy_dex/wasm/src/lib.rs b/locked-asset/proxy_dex/wasm/src/lib.rs index 892463480..29b3ab709 100644 --- a/locked-asset/proxy_dex/wasm/src/lib.rs +++ b/locked-asset/proxy_dex/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 25 +// Endpoints: 31 // Async Callback: 1 -// Total number of exported functions: 27 +// Total number of exported functions: 33 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,31 +19,39 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { proxy_dex ( - registerProxyPair - setTransferRoleWrappedLpToken - registerProxyFarm - setTransferRoleWrappedFarmToken - getAssetTokenId - getLockedTokenIds - getOldLockedTokenId - getOldFactoryAddress - getWrappedLpTokenId - getWrappedFarmTokenId - addPairToIntermediate - removeIntermediatedPair - addFarmToIntermediate - removeIntermediatedFarm - getIntermediatedPairs - getIntermediatedFarms - addLiquidityProxy - removeLiquidityProxy - enterFarmProxy - exitFarmProxy - claimRewardsProxy - mergeWrappedFarmTokens - mergeWrappedLpTokens - setEnergyFactoryAddress - getEnergyFactoryAddress - callBack + init => init + upgrade => upgrade + registerProxyPair => register_proxy_pair + setTransferRoleWrappedLpToken => set_transfer_role_wrapped_lp_token + registerProxyFarm => register_proxy_farm + setTransferRoleWrappedFarmToken => set_transfer_role_wrapped_farm_token + getAssetTokenId => get_asset_token_id_view + getLockedTokenIds => get_locked_token_ids_view + getOldLockedTokenId => old_locked_token_id + getOldFactoryAddress => old_factory_address + getWrappedLpTokenId => wrapped_lp_token + getWrappedFarmTokenId => wrapped_farm_token + addPairToIntermediate => add_pair_to_intermediate + removeIntermediatedPair => remove_intermediated_pair + addFarmToIntermediate => add_farm_to_intermediate + removeIntermediatedFarm => remove_intermediated_farm + getIntermediatedPairs => intermediated_pairs + getIntermediatedFarms => intermediated_farms + addLiquidityProxy => add_liquidity_proxy + removeLiquidityProxy => remove_liquidity_proxy + increaseProxyPairTokenEnergy => increase_proxy_pair_token_energy_endpoint + enterFarmProxy => enter_farm_proxy_endpoint + exitFarmProxy => exit_farm_proxy + claimRewardsProxy => claim_rewards_proxy + increaseProxyFarmTokenEnergy => increase_proxy_farm_token_energy_endpoint + mergeWrappedFarmTokens => merge_wrapped_farm_tokens_endpoint + mergeWrappedLpTokens => merge_wrapped_lp_tokens_endpoint + setEnergyFactoryAddress => set_energy_factory_address + getEnergyFactoryAddress => energy_factory_address + addSCAddressToWhitelist => add_sc_address_to_whitelist + removeSCAddressFromWhitelist => remove_sc_address_from_whitelist + isSCAddressWhitelisted => is_sc_address_whitelisted ) } + +multiversx_sc_wasm_adapter::async_callback! { proxy_dex } diff --git a/locked-asset/simple-lock-whitelist/Cargo.toml b/locked-asset/simple-lock-whitelist/Cargo.toml index 75df4276f..a8d637a5c 100644 --- a/locked-asset/simple-lock-whitelist/Cargo.toml +++ b/locked-asset/simple-lock-whitelist/Cargo.toml @@ -7,6 +7,7 @@ publish = false [lib] path = "src/lib.rs" + [dependencies.simple-lock] path = "../simple-lock" @@ -14,11 +15,11 @@ path = "../simple-lock" path = "../../common/modules/utils" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" [dev-dependencies] num-bigint = "0.4.2" @@ -26,4 +27,4 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" diff --git a/locked-asset/simple-lock-whitelist/elrond.json b/locked-asset/simple-lock-whitelist/elrond.json deleted file mode 100644 index 736553962..000000000 --- a/locked-asset/simple-lock-whitelist/elrond.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "language": "rust" -} \ No newline at end of file diff --git a/locked-asset/simple-lock-whitelist/meta/Cargo.toml b/locked-asset/simple-lock-whitelist/meta/Cargo.toml index 74669e73e..8b95c8a50 100644 --- a/locked-asset/simple-lock-whitelist/meta/Cargo.toml +++ b/locked-asset/simple-lock-whitelist/meta/Cargo.toml @@ -4,8 +4,10 @@ version = "0.0.0" edition = "2021" publish = false authors = ["Dorin Iancu "] + [dependencies.simple-lock-whitelist] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/locked-asset/simple-lock-whitelist/src/lib.rs b/locked-asset/simple-lock-whitelist/src/lib.rs index 80043ec08..48192fb15 100644 --- a/locked-asset/simple-lock-whitelist/src/lib.rs +++ b/locked-asset/simple-lock-whitelist/src/lib.rs @@ -28,6 +28,9 @@ pub trait SimpleLockWhitelist: } } + #[endpoint] + fn upgrade(&self) {} + /// Sets the transfer role for the given address. Defaults to own address. #[only_owner] #[endpoint(setTransferRoleLockedToken)] diff --git a/locked-asset/simple-lock-whitelist/tests/whitelist_test.rs b/locked-asset/simple-lock-whitelist/tests/whitelist_test.rs index 8e3cff4d3..54bb650a5 100644 --- a/locked-asset/simple-lock-whitelist/tests/whitelist_test.rs +++ b/locked-asset/simple-lock-whitelist/tests/whitelist_test.rs @@ -1,7 +1,9 @@ +#![allow(deprecated)] + use multiversx_sc::codec::multi_types::OptionalValue; use multiversx_sc::types::{EsdtLocalRole, MultiValueEncoded}; use multiversx_sc_scenario::{managed_token_id, rust_biguint, DebugApi}; -use multiversx_sc_scenario::{managed_token_id_wrapped, whitebox::*}; +use multiversx_sc_scenario::{managed_token_id_wrapped, whitebox_legacy::*}; use multiversx_sc::storage::mappers::StorageTokenWrapper; use simple_lock::locked_token::*; @@ -80,7 +82,7 @@ fn lock_whitelist_test() { ) .assert_ok(); - let _ = DebugApi::dummy(); + DebugApi::dummy(); b_mock.check_nft_balance( &user_addr, LOCKED_TOKEN_ID, diff --git a/locked-asset/simple-lock-whitelist/wasm/Cargo.lock b/locked-asset/simple-lock-whitelist/wasm/Cargo.lock index 678cb0db6..e6300116a 100644 --- a/locked-asset/simple-lock-whitelist/wasm/Cargo.lock +++ b/locked-asset/simple-lock-whitelist/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common_structs" @@ -67,15 +44,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -84,15 +52,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" - -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "math" @@ -101,12 +63,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -116,12 +72,11 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -130,20 +85,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -153,9 +107,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -166,21 +120,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -194,33 +147,27 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -264,15 +211,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -281,9 +228,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -301,43 +248,3 @@ dependencies = [ "mergeable", "multiversx-sc", ] - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/locked-asset/simple-lock-whitelist/wasm/Cargo.toml b/locked-asset/simple-lock-whitelist/wasm/Cargo.toml index 97334c70b..068857df3 100644 --- a/locked-asset/simple-lock-whitelist/wasm/Cargo.toml +++ b/locked-asset/simple-lock-whitelist/wasm/Cargo.toml @@ -1,25 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "simple-lock-whitelist-wasm" version = "0.0.0" -authors = ["Dorin Iancu "] edition = "2021" publish = false [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.simple-lock-whitelist] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[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 2d42f0f2c..d82101ff8 100644 --- a/locked-asset/simple-lock-whitelist/wasm/src/lib.rs +++ b/locked-asset/simple-lock-whitelist/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 24 +// Endpoints: 25 // Async Callback: 1 -// Total number of exported functions: 26 +// Total number of exported functions: 27 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,30 +19,33 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { simple_lock_whitelist ( - setTransferRoleLockedToken - setTransferRoleProxyLpToken - setTransferRoleProxyFarmToken - setLockedToken - lockTokens - unlockTokens - getTokenWhitelist - issueLockedToken - getLockedTokenId - issueLpProxyToken - addLpToWhitelist - removeLpFromWhitelist - addLiquidityLockedToken - removeLiquidityLockedToken - getKnownLiquidityPools - getLpProxyTokenId - issueFarmProxyToken - addFarmToWhitelist - removeFarmFromWhitelist - enterFarmLockedToken - exitFarmLockedToken - farmClaimRewardsLockedToken - getKnownFarms - getFarmProxyTokenId - callBack + init => init + upgrade => upgrade + setTransferRoleLockedToken => set_transfer_role + setTransferRoleProxyLpToken => set_transfer_role_proxy_lp + setTransferRoleProxyFarmToken => set_transfer_role_proxy_farm + setLockedToken => set_locked_token + lockTokens => lock_tokens_endpoint + unlockTokens => unlock_tokens_endpoint + getTokenWhitelist => token_whitelist + issueLockedToken => issue_locked_token + getLockedTokenId => locked_token + issueLpProxyToken => issue_lp_proxy_token + addLpToWhitelist => add_lp_to_whitelist + removeLpFromWhitelist => remove_lp_from_whitelist + addLiquidityLockedToken => add_liquidity_locked_token + removeLiquidityLockedToken => remove_liquidity_locked_token + getKnownLiquidityPools => known_liquidity_pools + getLpProxyTokenId => lp_proxy_token + issueFarmProxyToken => issue_farm_proxy_token + addFarmToWhitelist => add_farm_to_whitelist + removeFarmFromWhitelist => remove_farm_from_whitelist + enterFarmLockedToken => enter_farm_locked_token + exitFarmLockedToken => exit_farm_locked_token + farmClaimRewardsLockedToken => farm_claim_rewards_locked_token + getKnownFarms => known_farms + getFarmProxyTokenId => farm_proxy_token ) } + +multiversx_sc_wasm_adapter::async_callback! { simple_lock_whitelist } diff --git a/locked-asset/simple-lock/Cargo.toml b/locked-asset/simple-lock/Cargo.toml index 13a7614a3..8f6b5bd1d 100644 --- a/locked-asset/simple-lock/Cargo.toml +++ b/locked-asset/simple-lock/Cargo.toml @@ -7,12 +7,13 @@ publish = false [lib] path = "src/lib.rs" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" [dependencies.common_structs] path = "../../common/common_structs" @@ -23,4 +24,4 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" diff --git a/locked-asset/simple-lock/elrond.json b/locked-asset/simple-lock/elrond.json deleted file mode 100644 index 736553962..000000000 --- a/locked-asset/simple-lock/elrond.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "language": "rust" -} \ No newline at end of file diff --git a/locked-asset/simple-lock/meta/Cargo.toml b/locked-asset/simple-lock/meta/Cargo.toml index 8c31cffd9..889dce931 100644 --- a/locked-asset/simple-lock/meta/Cargo.toml +++ b/locked-asset/simple-lock/meta/Cargo.toml @@ -4,8 +4,10 @@ version = "0.0.0" edition = "2021" publish = false authors = ["Dorin Iancu "] + [dependencies.simple-lock] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/locked-asset/simple-lock/src/farm_interactions.rs b/locked-asset/simple-lock/src/farm_interactions.rs index d68e5ae62..2579a7531 100644 --- a/locked-asset/simple-lock/src/farm_interactions.rs +++ b/locked-asset/simple-lock/src/farm_interactions.rs @@ -6,12 +6,12 @@ multiversx_sc::derive_imports!(); type EnterFarmResultType = MultiValue2, EsdtTokenPayment>; type ExitFarmResultType = - MultiValue3, EsdtTokenPayment, EsdtTokenPayment>; + MultiValue2, EsdtTokenPayment>; type ClaimRewardsResultType = MultiValue2, EsdtTokenPayment>; const ENTER_FARM_RESULTS_LEN: usize = 2; -const EXIT_FARM_RESULTS_LEN: usize = 3; +const EXIT_FARM_RESULTS_LEN: usize = 2; const CLAIM_REWARDS_RESULTS_LEN: usize = 2; pub struct EnterFarmResultWrapper { @@ -22,7 +22,6 @@ pub struct EnterFarmResultWrapper { pub struct ExitFarmResultWrapper { pub initial_farming_tokens: EsdtTokenPayment, pub reward_tokens: EsdtTokenPayment, - pub remaining_farm_tokens: EsdtTokenPayment, } pub struct FarmClaimRewardsResultWrapper { @@ -51,7 +50,6 @@ mod farm_proxy { #[endpoint(exitFarm)] fn exit_farm( &self, - exit_amount: BigUint, opt_orig_caller: OptionalValue, ) -> ExitFarmResultType; @@ -106,12 +104,11 @@ pub trait FarmInteractionsModule { farm_token: TokenIdentifier, farm_token_nonce: u64, farm_token_amount: BigUint, - exit_amount: BigUint, caller: ManagedAddress, ) -> ExitFarmResultWrapper { let raw_results: RawResultsType = self .farm_proxy(farm_address) - .exit_farm(exit_amount, caller) + .exit_farm(caller) .with_esdt_transfer(EsdtTokenPayment::new( farm_token, farm_token_nonce, @@ -124,12 +121,10 @@ pub trait FarmInteractionsModule { let initial_farming_tokens = results_wrapper.decode_next_result(); let reward_tokens = results_wrapper.decode_next_result(); - let remaining_farm_tokens = results_wrapper.decode_next_result(); ExitFarmResultWrapper { initial_farming_tokens, reward_tokens, - remaining_farm_tokens, } } diff --git a/locked-asset/simple-lock/src/lib.rs b/locked-asset/simple-lock/src/lib.rs index f21f1721f..5db24f38e 100644 --- a/locked-asset/simple-lock/src/lib.rs +++ b/locked-asset/simple-lock/src/lib.rs @@ -25,6 +25,9 @@ pub trait SimpleLock: #[init] fn init(&self) {} + #[endpoint] + fn upgrade(&self) {} + /// Locks any token (including EGLD) until `unlock_epoch` and receive meta ESDT LOCKED tokens. /// on a 1:1 ratio. If unlock epoch has already passed, the original tokens are sent instead. /// diff --git a/locked-asset/simple-lock/src/locked_token.rs b/locked-asset/simple-lock/src/locked_token.rs index 700d81a25..dbb9c1a5d 100644 --- a/locked-asset/simple-lock/src/locked_token.rs +++ b/locked-asset/simple-lock/src/locked_token.rs @@ -62,7 +62,7 @@ pub trait LockedTokenModule: token_ticker: ManagedBuffer, num_decimals: usize, ) { - let payment_amount = self.call_value().egld_value(); + let payment_amount = self.call_value().egld_value().clone_value(); self.locked_token().issue_and_set_all_roles( EsdtTokenType::Meta, diff --git a/locked-asset/simple-lock/src/proxy_farm.rs b/locked-asset/simple-lock/src/proxy_farm.rs index 36692a51a..1d1a918d2 100644 --- a/locked-asset/simple-lock/src/proxy_farm.rs +++ b/locked-asset/simple-lock/src/proxy_farm.rs @@ -44,7 +44,7 @@ pub trait ProxyFarmModule: token_ticker: ManagedBuffer, num_decimals: usize, ) { - let payment_amount = self.call_value().egld_value(); + let payment_amount = self.call_value().egld_value().clone_value(); self.farm_proxy_token().issue_and_set_all_roles( EsdtTokenType::Meta, @@ -117,7 +117,7 @@ pub trait ProxyFarmModule: farm_type: FarmType, ) -> EnterFarmThroughProxyResultType { let payments: ManagedVec> = - self.call_value().all_esdt_transfers(); + self.call_value().all_esdt_transfers().clone_value(); require!(!payments.is_empty(), NO_PAYMENT_ERR_MSG); let proxy_lp_payment: EsdtTokenPayment = payments.get(0); @@ -199,18 +199,11 @@ pub trait ProxyFarmModule: /// - farm reward tokens #[payable("*")] #[endpoint(exitFarmLockedToken)] - fn exit_farm_locked_token( - &self, - exit_amount: BigUint, - ) -> ExitFarmThroughProxyResultType { - require!(exit_amount > 0u64, "Exit amount must be greater than 0"); + fn exit_farm_locked_token(&self) -> ExitFarmThroughProxyResultType { let payment: EsdtTokenPayment = self.call_value().single_esdt(); - require!( - exit_amount > 0u64 && exit_amount <= payment.amount, - "Invalid exit amount" - ); + let farm_proxy_token_attributes: FarmProxyTokenAttributes = - self.validate_payment_and_get_farm_proxy_token_attributes(&payment, &exit_amount); + self.validate_payment_and_get_farm_proxy_token_attributes(&payment); let farm_address = self.try_get_farm_address( &farm_proxy_token_attributes.farming_token_id, @@ -222,7 +215,6 @@ pub trait ProxyFarmModule: farm_proxy_token_attributes.farm_token_id, farm_proxy_token_attributes.farm_token_nonce, payment.amount, - exit_amount, caller.clone(), ); require!( @@ -253,15 +245,6 @@ pub trait ProxyFarmModule: ); } - if exit_farm_result.remaining_farm_tokens.amount > 0 { - self.send().direct_esdt( - &caller, - &payment.token_identifier, - payment.token_nonce, - &exit_farm_result.remaining_farm_tokens.amount, - ); - } - (lp_proxy_token_payment, exit_farm_result.reward_tokens).into() } @@ -279,7 +262,7 @@ pub trait ProxyFarmModule: fn farm_claim_rewards_locked_token(&self) -> FarmClaimRewardsThroughProxyResultType { let payment: EsdtTokenPayment = self.call_value().single_esdt(); let mut farm_proxy_token_attributes: FarmProxyTokenAttributes = - self.validate_payment_and_get_farm_proxy_token_attributes(&payment, &payment.amount); + self.validate_payment_and_get_farm_proxy_token_attributes(&payment); let farm_address = self.try_get_farm_address( &farm_proxy_token_attributes.farming_token_id, @@ -290,7 +273,7 @@ pub trait ProxyFarmModule: farm_address, farm_proxy_token_attributes.farm_token_id.clone(), farm_proxy_token_attributes.farm_token_nonce, - payment.amount, + payment.amount.clone(), caller.clone(), ); require!( @@ -337,7 +320,6 @@ pub trait ProxyFarmModule: fn validate_payment_and_get_farm_proxy_token_attributes( &self, payment: &EsdtTokenPayment, - exit_amount: &BigUint, ) -> FarmProxyTokenAttributes { require!(payment.amount > 0, NO_PAYMENT_ERR_MSG); @@ -347,7 +329,7 @@ pub trait ProxyFarmModule: let farm_proxy_token_attributes: FarmProxyTokenAttributes = farm_proxy_token_mapper.get_token_attributes(payment.token_nonce); - farm_proxy_token_mapper.nft_burn(payment.token_nonce, exit_amount); + farm_proxy_token_mapper.nft_burn(payment.token_nonce, &payment.amount); farm_proxy_token_attributes } diff --git a/locked-asset/simple-lock/src/proxy_lp.rs b/locked-asset/simple-lock/src/proxy_lp.rs index ca7a36ba5..ed16b65d1 100644 --- a/locked-asset/simple-lock/src/proxy_lp.rs +++ b/locked-asset/simple-lock/src/proxy_lp.rs @@ -34,7 +34,7 @@ pub trait ProxyLpModule: token_ticker: ManagedBuffer, num_decimals: usize, ) { - let payment_amount = self.call_value().egld_value(); + let payment_amount = self.call_value().egld_value().clone_value(); self.lp_proxy_token().issue_and_set_all_roles( EsdtTokenType::Meta, @@ -165,7 +165,7 @@ pub trait ProxyLpModule: ); let add_liq_result = self.call_pair_add_liquidity( - lp_address, + lp_address.clone(), ref_first_payment_unlocked, ref_second_payment_unlocked, first_token_amount_min, @@ -236,12 +236,26 @@ pub trait ProxyLpModule: second_token_amount_min: BigUint, ) -> RemoveLiquidityThroughProxyResultType { let payment: EsdtTokenPayment = self.call_value().single_esdt(); + + self.remove_liquidity_locked_token_common( + payment, + first_token_amount_min, + second_token_amount_min, + ) + } + + fn remove_liquidity_locked_token_common( + &self, + input_payment: EsdtTokenPayment, + first_token_amount_min: BigUint, + second_token_amount_min: BigUint, + ) -> RemoveLiquidityThroughProxyResultType { let lp_proxy_token_mapper = self.lp_proxy_token(); - lp_proxy_token_mapper.require_same_token(&payment.token_identifier); + lp_proxy_token_mapper.require_same_token(&input_payment.token_identifier); let lp_proxy_token_attributes: LpProxyTokenAttributes = - lp_proxy_token_mapper.get_token_attributes(payment.token_nonce); - lp_proxy_token_mapper.nft_burn(payment.token_nonce, &payment.amount); + lp_proxy_token_mapper.get_token_attributes(input_payment.token_nonce); + lp_proxy_token_mapper.nft_burn(input_payment.token_nonce, &input_payment.amount); let lp_address = self .lp_address_for_token_pair( @@ -249,7 +263,7 @@ pub trait ProxyLpModule: &lp_proxy_token_attributes.second_token_id, ) .get(); - let lp_token_amount = payment.amount; + let lp_token_amount = input_payment.amount; let remove_liq_result = self.call_pair_remove_liquidity( lp_address, lp_proxy_token_attributes.lp_token_id, diff --git a/locked-asset/simple-lock/tests/rust_test.rs b/locked-asset/simple-lock/tests/rust_test.rs index 8b879b610..7b3395672 100644 --- a/locked-asset/simple-lock/tests/rust_test.rs +++ b/locked-asset/simple-lock/tests/rust_test.rs @@ -1,6 +1,8 @@ +#![allow(deprecated)] + use multiversx_sc::codec::multi_types::OptionalValue; use multiversx_sc::types::EsdtLocalRole; -use multiversx_sc_scenario::{managed_biguint, managed_token_id_wrapped, whitebox::*}; +use multiversx_sc_scenario::{managed_biguint, managed_token_id_wrapped, whitebox_legacy::*}; use multiversx_sc_scenario::{managed_token_id, rust_biguint, DebugApi}; use multiversx_sc::storage::mappers::StorageTokenWrapper; @@ -64,7 +66,7 @@ fn lock_unlock_test() { .assert_ok(); // needed for the managed types in LockedTokenAttributes - let _ = DebugApi::dummy(); + DebugApi::dummy(); b_mock.check_nft_balance( &user_addr, LOCKED_TOKEN_ID, diff --git a/locked-asset/simple-lock/wasm/Cargo.lock b/locked-asset/simple-lock/wasm/Cargo.lock index 270c2aca4..e5957696c 100644 --- a/locked-asset/simple-lock/wasm/Cargo.lock +++ b/locked-asset/simple-lock/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common_structs" @@ -67,15 +44,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -84,15 +52,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" - -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "math" @@ -101,12 +63,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -116,12 +72,11 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -130,20 +85,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -153,9 +107,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -166,21 +120,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -194,33 +147,27 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -254,15 +201,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -271,9 +218,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -281,43 +228,3 @@ version = "0.0.0" dependencies = [ "multiversx-sc", ] - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/locked-asset/simple-lock/wasm/Cargo.toml b/locked-asset/simple-lock/wasm/Cargo.toml index 7c877dafc..cc2cf0244 100644 --- a/locked-asset/simple-lock/wasm/Cargo.toml +++ b/locked-asset/simple-lock/wasm/Cargo.toml @@ -1,25 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "simple-lock-wasm" version = "0.0.0" -authors = ["Dorin Iancu "] edition = "2021" publish = false [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.simple-lock] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/locked-asset/simple-lock/wasm/src/lib.rs b/locked-asset/simple-lock/wasm/src/lib.rs index 042660883..4e1b87c7d 100644 --- a/locked-asset/simple-lock/wasm/src/lib.rs +++ b/locked-asset/simple-lock/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 19 +// Endpoints: 20 // Async Callback: 1 -// Total number of exported functions: 21 +// Total number of exported functions: 22 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,25 +19,28 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { simple_lock ( - lockTokens - unlockTokens - issueLockedToken - getLockedTokenId - issueLpProxyToken - addLpToWhitelist - removeLpFromWhitelist - addLiquidityLockedToken - removeLiquidityLockedToken - getKnownLiquidityPools - getLpProxyTokenId - issueFarmProxyToken - addFarmToWhitelist - removeFarmFromWhitelist - enterFarmLockedToken - exitFarmLockedToken - farmClaimRewardsLockedToken - getKnownFarms - getFarmProxyTokenId - callBack + init => init + upgrade => upgrade + lockTokens => lock_tokens_endpoint + unlockTokens => unlock_tokens_endpoint + issueLockedToken => issue_locked_token + getLockedTokenId => locked_token + issueLpProxyToken => issue_lp_proxy_token + addLpToWhitelist => add_lp_to_whitelist + removeLpFromWhitelist => remove_lp_from_whitelist + addLiquidityLockedToken => add_liquidity_locked_token + removeLiquidityLockedToken => remove_liquidity_locked_token + getKnownLiquidityPools => known_liquidity_pools + getLpProxyTokenId => lp_proxy_token + issueFarmProxyToken => issue_farm_proxy_token + addFarmToWhitelist => add_farm_to_whitelist + removeFarmFromWhitelist => remove_farm_from_whitelist + enterFarmLockedToken => enter_farm_locked_token + exitFarmLockedToken => exit_farm_locked_token + farmClaimRewardsLockedToken => farm_claim_rewards_locked_token + getKnownFarms => known_farms + getFarmProxyTokenId => farm_proxy_token ) } + +multiversx_sc_wasm_adapter::async_callback! { simple_lock } diff --git a/locked-asset/tests/distribution_scenario_go_test.rs b/locked-asset/tests/distribution_scenario_go_test.rs index 637f0521b..bedda9fe6 100644 --- a/locked-asset/tests/distribution_scenario_go_test.rs +++ b/locked-asset/tests/distribution_scenario_go_test.rs @@ -1,138 +1,180 @@ -// #[test] -// fn add_liquidity_proxy_go() { -// multiversx_sc_scenario::run_go("scenarios/add_liquidity_proxy.scen.json"); -// } - -// #[test] -// fn claim_locked_assets_basic_go() { -// multiversx_sc_scenario::run_go("scenarios/claim_locked_assets_basic.scen.json"); -// } - -// #[test] -// fn claim_mex_rewards_proxy_after_mint_rewards_go() { -// multiversx_sc_scenario::run_go("scenarios/claim_mex_rewards_proxy_after_mint_rewards.scen.json"); -// } - -// #[test] -// fn claim_only_last_four_go() { -// multiversx_sc_scenario::run_go("scenarios/claim_only_last_four.scen.json"); -// } - -// #[test] -// fn claim_rewards_proxy_go() { -// multiversx_sc_scenario::run_go("scenarios/claim_rewards_proxy.scen.json"); -// } - -// /* -// #[test] -// fn claim_rewards_proxy_after_mint_rewards_go() { -// multiversx_sc_scenario::run_go("scenarios/claim_rewards_proxy_after_mint_rewards.scen.json"); -// } -// */ -// #[test] -// fn clear_unclaimable_assets_go() { -// multiversx_sc_scenario::run_go("scenarios/clear_unclaimable_assets.scen.json"); -// } - -// #[test] -// fn compound_mex_rewards_proxy_after_mint_rewards_go() { -// multiversx_sc_scenario::run_go("scenarios/compound_mex_rewards_proxy_after_mint_rewards.scen.json"); -// } - -// #[test] -// fn enter_farm_proxy_go() { -// multiversx_sc_scenario::run_go("scenarios/enter_farm_proxy.scen.json"); -// } - -// #[test] -// fn enter_mex_farm_proxy_go() { -// multiversx_sc_scenario::run_go("scenarios/enter_mex_farm_proxy.scen.json"); -// } - -// #[test] -// fn exit_farm_proxy_go() { -// multiversx_sc_scenario::run_go("scenarios/exit_farm_proxy.scen.json"); -// } - -// #[test] -// fn exit_mex_farm_proxy_after_compound_rewards_and_epoch_increase_go() { -// multiversx_sc_scenario::run_go( -// "scenarios/exit_mex_farm_proxy_after_compound_rewards_and_epoch_increase.scen.json", -// ); -// } - -// #[test] -// fn exit_mex_farm_proxy_after_compound_rewards_go() { -// multiversx_sc_scenario::run_go("scenarios/exit_mex_farm_proxy_after_compound_rewards.scen.json"); -// } - -// /* -// #[test] -// fn exit_farm_proxy_after_mint_rewards_go() { -// multiversx_sc_scenario::run_go("scenarios/exit_farm_proxy_after_mint_rewards.scen.json"); -// } -// */ -// #[test] -// fn exit_mex_farm_proxy_after_mint_rewards_go() { -// multiversx_sc_scenario::run_go("scenarios/exit_mex_farm_proxy_after_mint_rewards.scen.json"); -// } - -// #[test] -// fn merge_locked_mex_tokens_go() { -// multiversx_sc_scenario::run_go("scenarios/merge_locked_mex_tokens.scen.json"); -// } - -// #[test] -// fn multiple_claim_assets_go() { -// multiversx_sc_scenario::run_go("scenarios/multiple_claim_assets.scen.json"); -// } - -// #[test] -// fn remove_liquidity_proxy_go() { -// multiversx_sc_scenario::run_go("scenarios/remove_liquidity_proxy.scen.json"); -// } - -// #[test] -// fn remove_liquidity_proxy_after_swap_mex_go() { -// multiversx_sc_scenario::run_go("scenarios/remove_liquidity_proxy_after_swap_mex.scen.json"); -// } - -// #[test] -// fn remove_liquidity_proxy_after_swap_wegld_go() { -// multiversx_sc_scenario::run_go("scenarios/remove_liquidity_proxy_after_swap_wegld.scen.json"); -// } - -// #[test] -// fn set_user_distribution_go() { -// multiversx_sc_scenario::run_go("scenarios/set_user_distribution.scen.json"); -// } - -// #[test] -// fn set_user_distribution_above_cap_go() { -// multiversx_sc_scenario::run_go("scenarios/set_user_distribution_above_cap.scen.json"); -// } - -// #[test] -// fn set_user_distribution_duplicate_go() { -// multiversx_sc_scenario::run_go("scenarios/set_user_distribution_duplicate.scen.json"); -// } - -// #[test] -// fn set_user_distribution_with_unlock_go() { -// multiversx_sc_scenario::run_go("scenarios/set_user_distribution_with_unlock.scen.json"); -// } - -// #[test] -// fn undo_last_community_distribution_go() { -// multiversx_sc_scenario::run_go("scenarios/undo_last_community_distribution.scen.json"); -// } - -// #[test] -// fn undo_user_distribution_between_epochs_go() { -// multiversx_sc_scenario::run_go("scenarios/undo_user_distribution_between_epochs.scen.json"); -// } - -// #[test] -// fn unlock_assets_basic_go() { -// multiversx_sc_scenario::run_go("scenarios/unlock_assets_basic.scen.json"); -// } +use multiversx_sc_scenario::*; + +fn world() -> ScenarioWorld { + ScenarioWorld::vm_go() +} + +#[test] +#[ignore] +fn add_liquidity_proxy_go() { + world().run("scenarios/add_liquidity_proxy.scen.json"); +} + +#[test] +#[ignore] +fn add_liquidity_with_merge_tokens_go() { + world().run("scenarios/add_liquidity_with_merge_tokens.scen.json"); +} + +#[test] +#[ignore] +fn claim_locked_assets_basic_go() { + world().run("scenarios/claim_locked_assets_basic.scen.json"); +} + +#[test] +#[ignore] +fn claim_mex_rewards_proxy_after_mint_rewards_go() { + world().run("scenarios/claim_mex_rewards_proxy_after_mint_rewards.scen.json"); +} + +#[test] +#[ignore] +fn claim_only_last_four_go() { + world().run("scenarios/claim_only_last_four.scen.json"); +} + +#[test] +#[ignore] +fn claim_rewards_proxy_go() { + world().run("scenarios/claim_rewards_proxy.scen.json"); +} + +#[test] +#[ignore] +fn clear_unclaimable_assets_go() { + world().run("scenarios/clear_unclaimable_assets.scen.json"); +} + +#[test] +#[ignore] +fn compound_mex_rewards_proxy_after_mint_rewards_go() { + world().run("scenarios/compound_mex_rewards_proxy_after_mint_rewards.scen.json"); +} + +#[test] +#[ignore] +fn enter_farm_proxy_go() { + world().run("scenarios/enter_farm_proxy.scen.json"); +} + +#[test] +#[ignore] +fn enter_farm_proxy_with_merge_tokens_go() { + world().run("scenarios/enter_farm_proxy_with_merge_tokens.scen.json"); +} + +#[test] +#[ignore] +fn enter_mex_farm_proxy_go() { + world().run("scenarios/enter_mex_farm_proxy.scen.json"); +} + +#[test] +#[ignore] +fn exit_farm_proxy_go() { + world().run("scenarios/exit_farm_proxy.scen.json"); +} + +#[test] +#[ignore] +fn exit_mex_farm_proxy_after_compound_rewards_go() { + world().run("scenarios/exit_mex_farm_proxy_after_compound_rewards.scen.json"); +} + +#[test] +#[ignore] +fn exit_mex_farm_proxy_after_compound_rewards_and_epoch_increase_go() { + world() + .run("scenarios/exit_mex_farm_proxy_after_compound_rewards_and_epoch_increase.scen.json"); +} + +#[test] +#[ignore] +fn exit_mex_farm_proxy_after_mint_rewards_go() { + world().run("scenarios/exit_mex_farm_proxy_after_mint_rewards.scen.json"); +} + +#[test] +#[ignore] +fn merge_locked_mex_tokens_go() { + world().run("scenarios/merge_locked_mex_tokens.scen.json"); +} + +#[test] +#[ignore] +fn merge_wrapped_farm_tokens_go() { + world().run("scenarios/merge_wrapped_farm_tokens.scen.json"); +} + +#[test] +#[ignore] +fn merge_wrapped_lp_tokens_go() { + world().run("scenarios/merge_wrapped_lp_tokens.scen.json"); +} + +#[test] +#[ignore] +fn multiple_claim_assets_go() { + world().run("scenarios/multiple_claim_assets.scen.json"); +} + +#[test] +#[ignore] +fn remove_liquidity_proxy_go() { + world().run("scenarios/remove_liquidity_proxy.scen.json"); +} + +#[test] +#[ignore] +fn remove_liquidity_proxy_after_swap_mex_go() { + world().run("scenarios/remove_liquidity_proxy_after_swap_mex.scen.json"); +} + +#[test] +#[ignore] +fn remove_liquidity_proxy_after_swap_wegld_go() { + world().run("scenarios/remove_liquidity_proxy_after_swap_wegld.scen.json"); +} + +#[test] +#[ignore] +fn set_user_distribution_go() { + world().run("scenarios/set_user_distribution.scen.json"); +} + +#[test] +#[ignore] +fn set_user_distribution_above_cap_go() { + world().run("scenarios/set_user_distribution_above_cap.scen.json"); +} + +#[test] +#[ignore] +fn set_user_distribution_duplicate_go() { + world().run("scenarios/set_user_distribution_duplicate.scen.json"); +} + +#[test] +#[ignore] +fn set_user_distribution_with_unlock_go() { + world().run("scenarios/set_user_distribution_with_unlock.scen.json"); +} + +#[test] +#[ignore] +fn undo_last_community_distribution_go() { + world().run("scenarios/undo_last_community_distribution.scen.json"); +} + +#[test] +#[ignore] +fn undo_user_distribution_between_epochs_go() { + world().run("scenarios/undo_user_distribution_between_epochs.scen.json"); +} + +#[test] +#[ignore] +fn unlock_assets_basic_go() { + world().run("scenarios/unlock_assets_basic.scen.json"); +} diff --git a/locked-asset/token-unstake/Cargo.toml b/locked-asset/token-unstake/Cargo.toml index 544b7221b..da727566e 100644 --- a/locked-asset/token-unstake/Cargo.toml +++ b/locked-asset/token-unstake/Cargo.toml @@ -7,8 +7,9 @@ publish = false [lib] path = "src/lib.rs" + [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.mergeable] @@ -38,7 +39,7 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" [dev-dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" diff --git a/locked-asset/token-unstake/meta/Cargo.toml b/locked-asset/token-unstake/meta/Cargo.toml index 6292163a3..fb4914c3d 100644 --- a/locked-asset/token-unstake/meta/Cargo.toml +++ b/locked-asset/token-unstake/meta/Cargo.toml @@ -4,8 +4,10 @@ version = "0.0.0" authors = ["MultiversX "] edition = "2021" publish = false + [dependencies.token-unstake] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/locked-asset/token-unstake/src/lib.rs b/locked-asset/token-unstake/src/lib.rs index d160fce58..6295d46a2 100644 --- a/locked-asset/token-unstake/src/lib.rs +++ b/locked-asset/token-unstake/src/lib.rs @@ -41,4 +41,7 @@ pub trait TokenUnstakeModule: self.fees_collector_address().set(&fees_collector_address); self.fees_burn_percentage().set(fees_burn_percentage); } + + #[endpoint] + fn upgrade(&self) {} } diff --git a/locked-asset/token-unstake/tests/token_unstake_setup/mod.rs b/locked-asset/token-unstake/tests/token_unstake_setup/mod.rs index f74fbb844..edac051d7 100644 --- a/locked-asset/token-unstake/tests/token_unstake_setup/mod.rs +++ b/locked-asset/token-unstake/tests/token_unstake_setup/mod.rs @@ -1,4 +1,5 @@ #![allow(dead_code)] +#![allow(deprecated)] pub mod fees_collector_mock; @@ -15,8 +16,8 @@ use multiversx_sc::{ use multiversx_sc_modules::pause::PauseModule; use multiversx_sc_scenario::{ managed_address, managed_biguint, managed_token_id, rust_biguint, - whitebox::TxResult, - whitebox::{BlockchainStateWrapper, ContractObjWrapper}, + whitebox_legacy::TxResult, + whitebox_legacy::{BlockchainStateWrapper, ContractObjWrapper}, DebugApi, }; use simple_lock::locked_token::LockedTokenModule; @@ -64,7 +65,7 @@ where energy_factory_builder: EnergyFactoryBuilder, unstake_sc_builder: UnstakeScBuilder, ) -> Self { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let rust_zero = rust_biguint!(0u64); let mut b_mock = BlockchainStateWrapper::new(); let owner = b_mock.create_user_account(&rust_zero); diff --git a/locked-asset/token-unstake/tests/token_unstake_test.rs b/locked-asset/token-unstake/tests/token_unstake_test.rs index 21596d411..e247a4a0d 100644 --- a/locked-asset/token-unstake/tests/token_unstake_test.rs +++ b/locked-asset/token-unstake/tests/token_unstake_test.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + mod token_unstake_setup; use multiversx_sc::types::{EsdtTokenPayment, ManagedVec}; diff --git a/locked-asset/token-unstake/tests/unlock_early_test.rs b/locked-asset/token-unstake/tests/unlock_early_test.rs index bbe17cf2c..985796d94 100644 --- a/locked-asset/token-unstake/tests/unlock_early_test.rs +++ b/locked-asset/token-unstake/tests/unlock_early_test.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + mod token_unstake_setup; use energy_factory::energy::EnergyModule; @@ -7,7 +9,7 @@ use token_unstake_setup::*; #[test] fn double_unlock_early_test() { - let _ = DebugApi::dummy(); + DebugApi::dummy(); let mut setup = TokenUnstakeSetup::new(energy_factory::contract_obj, token_unstake::contract_obj); let first_user = setup.first_user.clone(); diff --git a/locked-asset/token-unstake/wasm/Cargo.lock b/locked-asset/token-unstake/wasm/Cargo.lock index 4a78e1d16..d74f133fa 100644 --- a/locked-asset/token-unstake/wasm/Cargo.lock +++ b/locked-asset/token-unstake/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common-types" @@ -105,15 +82,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -122,9 +90,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "legacy_token_decode_module" @@ -135,12 +103,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - [[package]] name = "math" version = "0.0.0" @@ -148,12 +110,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "mergeable" version = "0.0.0" @@ -163,12 +119,11 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -177,20 +132,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -200,9 +154,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -213,21 +167,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -241,33 +194,27 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -301,15 +248,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -340,9 +287,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unwrappable" @@ -361,24 +308,6 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - [[package]] name = "week-timekeeping" version = "0.0.0" @@ -386,25 +315,3 @@ dependencies = [ "common-types", "multiversx-sc", ] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/locked-asset/token-unstake/wasm/Cargo.toml b/locked-asset/token-unstake/wasm/Cargo.toml index d27d882ac..f3e21bb9b 100644 --- a/locked-asset/token-unstake/wasm/Cargo.toml +++ b/locked-asset/token-unstake/wasm/Cargo.toml @@ -1,26 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "token-unstake-wasm" version = "0.0.0" -authors = ["MultiversX "] edition = "2021" publish = false [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.token-unstake] -default-features = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/locked-asset/token-unstake/wasm/src/lib.rs b/locked-asset/token-unstake/wasm/src/lib.rs index e0ac873af..396d02ba0 100644 --- a/locked-asset/token-unstake/wasm/src/lib.rs +++ b/locked-asset/token-unstake/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 10 +// Endpoints: 11 // Async Callback (empty): 1 -// Total number of exported functions: 12 +// Total number of exported functions: 13 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,17 +19,19 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { token_unstake ( - getUnbondEpochs - getUnlockedTokensForUser - claimUnlockedTokens - cancelUnbond - depositUserTokens - depositFees - getFeesBurnPercentage - getFeesCollectorAddress - setEnergyFactoryAddress - getEnergyFactoryAddress + init => init + upgrade => upgrade + getUnbondEpochs => unbond_epochs + getUnlockedTokensForUser => unlocked_tokens_for_user + claimUnlockedTokens => claim_unlocked_tokens + cancelUnbond => cancel_unbond + depositUserTokens => deposit_user_tokens + depositFees => deposit_fees + getFeesBurnPercentage => fees_burn_percentage + getFeesCollectorAddress => fees_collector_address + setEnergyFactoryAddress => set_energy_factory_address + getEnergyFactoryAddress => energy_factory_address ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/pair-mock/wasm/Cargo.lock b/pair-mock/wasm/Cargo.lock deleted file mode 100644 index bcd19a52a..000000000 --- a/pair-mock/wasm/Cargo.lock +++ /dev/null @@ -1,300 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "ahash" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - -[[package]] -name = "arrayvec" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "common_errors" -version = "0.0.0" -dependencies = [ - "multiversx-sc", -] - -[[package]] -name = "either" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" - -[[package]] -name = "elrond-codec" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6d85f2b7c969a12da26157a989f759f59d1df2b0e2f4ae7b2ebb011334a63c1" -dependencies = [ - "arrayvec", - "elrond-codec-derive", - "wee_alloc", -] - -[[package]] -name = "elrond-codec-derive" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae84b062b57562daf6b90d12c6568a6df21ef355625f6dd21a3106d774456a51" -dependencies = [ - "hex", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "multiversx-sc" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c99bd13acbd995a1b048fcc791a8acd8d2d4ab1085738c9077607d218fb2a42f" -dependencies = [ - "bitflags", - "elrond-codec", - "multiversx-sc-derive", - "hashbrown", - "hex-literal", - "wee_alloc", -] - -[[package]] -name = "multiversx-sc-derive" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a3e0e238435b3e1ac971e15ac345bf4f75efc88c8ee0032e286cf67dbff9681" -dependencies = [ - "hex", - "proc-macro2", - "quote", - "radix_trie", - "syn", -] - -[[package]] -name = "multiversx-sc-node" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad55a0495ab1760ab532766529bc4b1cda04c918e44cfb2d84e1ac066d574397" -dependencies = [ - "multiversx-sc", -] - -[[package]] -name = "multiversx-sc-output" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a1b54eef1004bb8b622b7f8cbe0100c715dfd58699bb7b0c5a50d23c3a87f38" -dependencies = [ - "multiversx-sc-node", - "wee_alloc", -] - -[[package]] -name = "endian-type" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" - -[[package]] -name = "getrandom" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi", -] - -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" -dependencies = [ - "ahash", -] - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "hex-literal" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" - -[[package]] -name = "itertools" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" -dependencies = [ - "either", -] - -[[package]] -name = "libc" -version = "0.2.115" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a8d982fa7a96a000f6ec4cfe966de9703eccde29750df2bb8949da91b0e818d" - -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - -[[package]] -name = "nibble_vec" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8d77f3db4bce033f4d04db08079b2ef1c3d02b44e86f25d08886fafa7756ffa" - -[[package]] -name = "once_cell" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" - -[[package]] -name = "pair-mock" -version = "0.0.0" -dependencies = [ - "common_errors", - "multiversx-sc", - "itertools", -] - -[[package]] -name = "pair-mock-wasm" -version = "0.0.0" -dependencies = [ - "multiversx-sc-node", - "multiversx-sc-output", - "pair-mock", -] - -[[package]] -name = "proc-macro2" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" -dependencies = [ - "unicode-xid", -] - -[[package]] -name = "quote" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "radix_trie" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d3681b28cd95acfb0560ea9441f82d6a4504fa3b15b97bd7b6e952131820e95" -dependencies = [ - "endian-type", - "nibble_vec", -] - -[[package]] -name = "syn" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - -[[package]] -name = "unicode-xid" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/pause-all/Cargo.toml b/pause-all/Cargo.toml index 5165b7955..30046978d 100644 --- a/pause-all/Cargo.toml +++ b/pause-all/Cargo.toml @@ -7,17 +7,19 @@ publish = false [lib] path = "src/lib.rs" + [dependencies.pausable] path = "../common/modules/pausable" [dependencies.multiversx-sc] -version = "=0.39.4" +version = "=0.46.1" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.39.4" +version = "=0.46.1" + [dev-dependencies.multiversx-sc-scenario] -version = "=0.39.4" +version = "=0.46.1" [dev-dependencies.farm] path = "../dex/farm" diff --git a/pause-all/meta/Cargo.toml b/pause-all/meta/Cargo.toml index 61c94047d..f6be6643e 100644 --- a/pause-all/meta/Cargo.toml +++ b/pause-all/meta/Cargo.toml @@ -6,8 +6,10 @@ publish = false authors = ["MultiversX "] [dev-dependencies] + [dependencies.pause-all] path = ".." [dependencies.multiversx-sc-meta] -version = "=0.39.4" +version = "0.46.1" +default-features = false diff --git a/pause-all/src/lib.rs b/pause-all/src/lib.rs index 732e16678..6e9bcd823 100644 --- a/pause-all/src/lib.rs +++ b/pause-all/src/lib.rs @@ -28,6 +28,9 @@ pub trait PauseAll: #[init] fn init(&self) {} + #[endpoint] + fn upgrade(&self) {} + #[only_owner] #[endpoint(addPausableContracts)] fn add_pausable_contracts(&self, pausable_sc_addr: MultiValueEncoded) { diff --git a/pause-all/tests/pause_all_test.rs b/pause-all/tests/pause_all_test.rs index 6a46cbbbf..37cc38e70 100644 --- a/pause-all/tests/pause_all_test.rs +++ b/pause-all/tests/pause_all_test.rs @@ -1,7 +1,9 @@ +#![allow(deprecated)] + use farm::Farm; use multiversx_sc::types::{Address, ManagedAddress, MultiValueEncoded, OperationCompletionStatus}; use multiversx_sc_scenario::{ - managed_address, managed_biguint, managed_token_id, rust_biguint, whitebox::*, DebugApi, + managed_address, managed_biguint, managed_token_id, rust_biguint, whitebox_legacy::*, DebugApi, }; use pair::Pair; use pausable::{PausableModule, State}; diff --git a/pause-all/wasm/Cargo.lock b/pause-all/wasm/Cargo.lock index 8dfdb7105..d1b8021d6 100644 --- a/pause-all/wasm/Cargo.lock +++ b/pause-all/wasm/Cargo.lock @@ -2,22 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "autocfg" @@ -27,21 +16,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "common_errors" @@ -56,15 +33,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hex" version = "0.4.3" @@ -73,30 +41,17 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" - -[[package]] -name = "libc" -version = "0.2.139" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" - -[[package]] -name = "memory_units" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "multiversx-sc" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecfb3e03ac6e08114963a54e15a3c78c28e57cc0e31836e870450b35085bdf8d" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -105,20 +60,19 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7638cb46a0e99c636fd55443ac534ff0a5fad0bd772e1037fbac9a75e04c3c9" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", - "wee_alloc", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.17.1" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e976002d51367f16140929c10ee695f95dd8d34c150a45db60d3fcd1328a267a" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", @@ -128,9 +82,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eb54a7d452eb09f5de159ee9b4d1fb9ec79cf49f1602ebd3efc8532015a4ea" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -141,21 +95,20 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12284a3e31c0852b6ca0ce8306d3f404c3712b996a05ed78e97e765c98461f3" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.39.4" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69fa831cdd5a7ea1aedbb6356a55792b821396f48360a6194f4131eddd1045" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", - "wee_alloc", ] [[package]] @@ -169,19 +122,13 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" - [[package]] name = "pausable" version = "0.0.0" @@ -218,18 +165,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -246,15 +193,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" [[package]] name = "syn" -version = "1.0.107" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -263,46 +210,6 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/pause-all/wasm/Cargo.toml b/pause-all/wasm/Cargo.toml index 4e14e45c4..ccffee39c 100644 --- a/pause-all/wasm/Cargo.toml +++ b/pause-all/wasm/Cargo.toml @@ -1,25 +1,31 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + [package] name = "pause-all-wasm" version = "0.0.0" edition = "2021" publish = false -authors = ["MultiversX "] [lib] crate-type = ["cdylib"] -[workspace] -members = ["."] - -[dev-dependencies] [profile.release] codegen-units = 1 opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false + [dependencies.pause-all] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.39.4" +version = "=0.46.1" + +[workspace] +members = ["."] diff --git a/pause-all/wasm/src/lib.rs b/pause-all/wasm/src/lib.rs index 6177d8585..2302b1e6a 100644 --- a/pause-all/wasm/src/lib.rs +++ b/pause-all/wasm/src/lib.rs @@ -1,16 +1,17 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. +// Code generated by the multiversx-sc build system. DO NOT EDIT. //////////////////////////////////////////////////// ////////////////// AUTO-GENERATED ////////////////// //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 7 +// Endpoints: 8 // Async Callback (empty): 1 -// Total number of exported functions: 9 +// Total number of exported functions: 10 #![no_std] -#![feature(alloc_error_handler, lang_items)] +#![allow(internal_features)] +#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -18,14 +19,16 @@ multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { pause_all ( - addPausableContracts - removePausableContracts - pauseSelected - pauseAll - resumeSelected - resumeAll - getPausableContracts + init => init + upgrade => upgrade + addPausableContracts => add_pausable_contracts + removePausableContracts => remove_pausable_contracts + pauseSelected => pause_selected + pauseAll => pause_all + resumeSelected => resume_selected + resumeAll => resume_all + getPausableContracts => pausable_contracts ) } -multiversx_sc_wasm_adapter::empty_callback! {} +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/price-discovery/wasm/Cargo.lock b/price-discovery/wasm/Cargo.lock deleted file mode 100644 index 9f0b1af16..000000000 --- a/price-discovery/wasm/Cargo.lock +++ /dev/null @@ -1,336 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "ahash" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - -[[package]] -name = "arrayvec" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "common_errors" -version = "0.0.0" -dependencies = [ - "multiversx-sc", -] - -[[package]] -name = "common_structs" -version = "0.0.0" -dependencies = [ - "multiversx-sc", -] - -[[package]] -name = "either" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" - -[[package]] -name = "elrond-codec" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6d85f2b7c969a12da26157a989f759f59d1df2b0e2f4ae7b2ebb011334a63c1" -dependencies = [ - "arrayvec", - "elrond-codec-derive", - "wee_alloc", -] - -[[package]] -name = "elrond-codec-derive" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae84b062b57562daf6b90d12c6568a6df21ef355625f6dd21a3106d774456a51" -dependencies = [ - "hex", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "multiversx-sc" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c99bd13acbd995a1b048fcc791a8acd8d2d4ab1085738c9077607d218fb2a42f" -dependencies = [ - "bitflags", - "elrond-codec", - "multiversx-sc-derive", - "hashbrown", - "hex-literal", - "wee_alloc", -] - -[[package]] -name = "multiversx-sc-derive" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a3e0e238435b3e1ac971e15ac345bf4f75efc88c8ee0032e286cf67dbff9681" -dependencies = [ - "hex", - "proc-macro2", - "quote", - "radix_trie", - "syn", -] - -[[package]] -name = "multiversx-sc-node" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad55a0495ab1760ab532766529bc4b1cda04c918e44cfb2d84e1ac066d574397" -dependencies = [ - "multiversx-sc", -] - -[[package]] -name = "multiversx-sc-output" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a1b54eef1004bb8b622b7f8cbe0100c715dfd58699bb7b0c5a50d23c3a87f38" -dependencies = [ - "multiversx-sc-node", - "wee_alloc", -] - -[[package]] -name = "endian-type" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" - -[[package]] -name = "getrandom" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi", -] - -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" -dependencies = [ - "ahash", -] - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - -[[package]] -name = "hex-literal" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" - -[[package]] -name = "itertools" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" -dependencies = [ - "either", -] - -[[package]] -name = "libc" -version = "0.2.115" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a8d982fa7a96a000f6ec4cfe966de9703eccde29750df2bb8949da91b0e818d" - -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - -[[package]] -name = "nibble_vec" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8d77f3db4bce033f4d04db08079b2ef1c3d02b44e86f25d08886fafa7756ffa" - -[[package]] -name = "once_cell" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" - -[[package]] -name = "pair" -version = "0.0.0" -dependencies = [ - "common_structs", - "multiversx-sc", - "itertools", - "token_send", -] - -[[package]] -name = "price-discovery" -version = "0.0.0" -dependencies = [ - "multiversx-sc", - "hex-literal", - "pair", - "token_merge", -] - -[[package]] -name = "price-discovery-wasm" -version = "0.0.0" -dependencies = [ - "multiversx-sc-node", - "multiversx-sc-output", - "price-discovery", -] - -[[package]] -name = "proc-macro2" -version = "1.0.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" -dependencies = [ - "unicode-xid", -] - -[[package]] -name = "quote" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "radix_trie" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d3681b28cd95acfb0560ea9441f82d6a4504fa3b15b97bd7b6e952131820e95" -dependencies = [ - "endian-type", - "nibble_vec", -] - -[[package]] -name = "syn" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - -[[package]] -name = "token_merge" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "multiversx-sc", -] - -[[package]] -name = "token_send" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "multiversx-sc", -] - -[[package]] -name = "unicode-xid" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"