diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index afa63aa92..c166a6cfb 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -20,61 +20,9 @@ permissions: jobs: contracts: name: Contracts - uses: multiversx/mx-sc-actions/.github/workflows/contracts.yml@v2.3.5 + uses: multiversx/mx-sc-actions/.github/workflows/contracts.yml@v3.3.1 with: - rust-toolchain: nightly-2023-12-11 - vmtools-version: v1.5.24 + rust-toolchain: nightly-2024-05-22 + coverage-args: --ignore-filename-regex='/.cargo/git' --output ./coverage.md secrets: token: ${{ secrets.GITHUB_TOKEN }} - - # TEMPORARY: Remove this job when we can upgrade to mx-sc-actions v3+ - test_coverage: - name: Test Coverage - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Install rust - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - toolchain: nightly-2023-12-11 - target: wasm32-unknown-unknown - - - name: Install prerequisites - run: | - rustup component add llvm-tools-preview - dirname $(find ~/.rustup -name llvm-cov) >> $GITHUB_PATH - - echo $(dirname $(find ~/.rustup -name llvm-cov)) - - cargo install multiversx-sc-meta --locked - - - name: Run tests and generate report - env: - RUSTFLAGS: "" - run: | - sc-meta test-coverage --output ./coverage.md - - - name: Upload the report - uses: actions/upload-artifact@v3 - with: - name: coverage - path: coverage.md - - - name: Find the comment containing the report - id: fc - uses: peter-evans/find-comment@v2 - if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository - with: - issue-number: ${{ github.event.pull_request.number }} - comment-author: "github-actions[bot]" - body-includes: "Coverage Summary" - - - name: Create or update the report comment - uses: peter-evans/create-or-update-comment@v2 - if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository - with: - comment-id: ${{ steps.fc.outputs.comment-id }} - issue-number: ${{ github.event.pull_request.number }} - body-file: ./coverage.md - edit-mode: replace diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a19b5ed98..3bb9fa310 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.5 + uses: multiversx/mx-sc-actions/.github/workflows/reproducible-build.yml@v3.3.1 with: - image_tag: v6.0.0 + image_tag: v7.0.0 attach_to_existing_release: true diff --git a/Cargo.lock b/Cargo.lock index fe863b981..724f6ca9d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,82 +3,61 @@ version = 3 [[package]] -name = "Inflector" -version = "0.11.4" +name = "ahash" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ - "lazy_static", - "regex", -] - -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "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" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" -dependencies = [ - "memchr", + "cfg-if", + "once_cell", + "version_check", + "zerocopy", ] [[package]] name = "anstream" -version = "0.6.11" +version = "0.6.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", + "is_terminal_polyfill", "utf8parse", ] [[package]] name = "anstyle" -version = "1.0.6" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" [[package]] name = "anstyle-parse" -version = "0.2.3" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.2" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" dependencies = [ "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.2" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" dependencies = [ "anstyle", "windows-sys 0.52.0", @@ -86,42 +65,27 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.79" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] 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" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" -dependencies = [ - "addr2line", - "cc", - "cfg-if 1.0.0", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "base64" -version = "0.21.7" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "base64ct" @@ -131,40 +95,15 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "bech32" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" - -[[package]] -name = "bip39" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -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 = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" [[package]] name = "bitflags" -version = "2.4.2" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "block-buffer" @@ -175,49 +114,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bstr" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -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" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - [[package]] name = "cfg-if" version = "1.0.0" @@ -226,9 +128,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.4.18" +version = "4.5.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c" +checksum = "ed6719fffa43d0d87e5fd8caeab59be1554fb028cd30edc88fc4369b17971019" dependencies = [ "clap_builder", "clap_derive", @@ -236,9 +138,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.18" +version = "4.5.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7" +checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6" dependencies = [ "anstream", "anstyle", @@ -248,9 +150,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.4.7" +version = "4.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" +checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" dependencies = [ "heck", "proc-macro2", @@ -260,15 +162,15 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.6.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "colorchoice" -version = "1.0.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" [[package]] name = "colored" @@ -280,12 +182,6 @@ dependencies = [ "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" @@ -355,74 +251,15 @@ 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.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad" 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" @@ -435,16 +272,15 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "4.1.1" +version = "4.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89b8c6a2e4b1f45971ad09761aafb85514a84744b67a95e32c3cc1352d1f65c" +checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", "curve25519-dalek-derive", "digest", "fiat-crypto", - "platforms", "rustc_version", "subtle", "zeroize", @@ -463,9 +299,9 @@ dependencies = [ [[package]] name = "der" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" dependencies = [ "const-oid", "zeroize", @@ -477,7 +313,6 @@ version = "0.0.0" dependencies = [ "common_structs", "config", - "factory", "farm", "farm-boosted-yields", "farm-staking", @@ -505,25 +340,6 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", "crypto-common", - "subtle", -] - -[[package]] -name = "distribution" -version = "0.0.0" -dependencies = [ - "common_structs", - "factory", - "multiversx-sc", - "multiversx-sc-scenario", -] - -[[package]] -name = "distribution-abi" -version = "0.0.0" -dependencies = [ - "distribution", - "multiversx-sc-meta", ] [[package]] @@ -531,9 +347,7 @@ name = "distribution-tests" version = "0.0.0" dependencies = [ "common_structs", - "distribution", "energy-factory", - "factory", "farm", "fees-collector", "hex", @@ -576,18 +390,9 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" - -[[package]] -name = "encoding_rs" -version = "0.8.33" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" -dependencies = [ - "cfg-if 1.0.0", -] +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "endian-type" @@ -620,7 +425,7 @@ name = "energy-factory-meta" version = "0.0.0" dependencies = [ "energy-factory", - "multiversx-sc-meta", + "multiversx-sc-meta-lib", ] [[package]] @@ -637,7 +442,7 @@ name = "energy-factory-mock-meta" version = "0.0.0" dependencies = [ "energy-factory-mock", - "multiversx-sc-meta", + "multiversx-sc-meta-lib", ] [[package]] @@ -665,7 +470,7 @@ name = "energy-update-meta" version = "0.0.0" dependencies = [ "energy-update", - "multiversx-sc-meta", + "multiversx-sc-meta-lib", ] [[package]] @@ -674,16 +479,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "errno" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "events" version = "0.0.0" @@ -694,32 +489,24 @@ dependencies = [ ] [[package]] -name = "factory" +name = "factory-legacy" version = "0.0.0" dependencies = [ - "arrayvec", "common_errors", "common_structs", "energy-factory", - "hex", - "itertools 0.10.5", "multiversx-sc", "multiversx-sc-modules", "multiversx-sc-scenario", - "num-bigint", - "num-traits", - "simple-lock", "token_merge_helper", - "token_send", - "wee_alloc", ] [[package]] -name = "factory-abi" +name = "factory-legacy-meta" version = "0.0.0" dependencies = [ - "factory", - "multiversx-sc-meta", + "factory-legacy", + "multiversx-sc-meta-lib", ] [[package]] @@ -760,7 +547,7 @@ name = "farm-abi" version = "0.0.0" dependencies = [ "farm", - "multiversx-sc-meta", + "multiversx-sc-meta-lib", ] [[package]] @@ -815,7 +602,7 @@ name = "farm-staking-abi" version = "0.0.0" dependencies = [ "farm-staking", - "multiversx-sc-meta", + "multiversx-sc-meta-lib", ] [[package]] @@ -854,7 +641,107 @@ name = "farm-staking-proxy-meta" version = "0.0.0" dependencies = [ "farm-staking-proxy", - "multiversx-sc-meta", + "multiversx-sc-meta-lib", +] + +[[package]] +name = "farm-staking-proxy-v13" +version = "0.0.0" +dependencies = [ + "common_structs", + "energy-factory", + "energy-query", + "farm-staking", + "farm-v13-locked-rewards", + "farm_token", + "hex", + "locking_module", + "multiversx-sc", + "multiversx-sc-modules", + "multiversx-sc-scenario", + "num-bigint", + "num-traits", + "pair", + "pausable", + "sc_whitelist_module", + "simple-lock", + "token_merge_helper", +] + +[[package]] +name = "farm-staking-proxy-v13-meta" +version = "0.0.0" +dependencies = [ + "farm-staking-proxy-v13", + "multiversx-sc-meta-lib", +] + +[[package]] +name = "farm-v12" +version = "0.0.0" +dependencies = [ + "multiversx-sc", + "multiversx-sc-scenario", + "num-bigint", +] + +[[package]] +name = "farm-v12-meta" +version = "0.0.0" +dependencies = [ + "farm-v12", + "multiversx-sc-meta-lib", +] + +[[package]] +name = "farm-v13" +version = "0.0.0" +dependencies = [ + "multiversx-sc", + "multiversx-sc-scenario", + "num-bigint", +] + +[[package]] +name = "farm-v13-custom-rewards" +version = "0.0.0" +dependencies = [ + "multiversx-sc", + "multiversx-sc-scenario", + "num-bigint", +] + +[[package]] +name = "farm-v13-custom-rewards-meta" +version = "0.0.0" +dependencies = [ + "farm-v13-custom-rewards", + "multiversx-sc-meta-lib", +] + +[[package]] +name = "farm-v13-locked-rewards" +version = "0.0.0" +dependencies = [ + "multiversx-sc", + "multiversx-sc-scenario", + "num-bigint", +] + +[[package]] +name = "farm-v13-locked-rewards-meta" +version = "0.0.0" +dependencies = [ + "farm-v13-locked-rewards", + "multiversx-sc-meta-lib", +] + +[[package]] +name = "farm-v13-meta" +version = "0.0.0" +dependencies = [ + "farm-v13", + "multiversx-sc-meta-lib", ] [[package]] @@ -895,7 +782,7 @@ name = "farm-with-locked-rewards-meta" version = "0.0.0" dependencies = [ "farm-with-locked-rewards", - "multiversx-sc-meta", + "multiversx-sc-meta-lib", ] [[package]] @@ -935,12 +822,6 @@ 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" @@ -966,14 +847,14 @@ name = "fees-collector-meta" version = "0.0.0" dependencies = [ "fees-collector", - "multiversx-sc-meta", + "multiversx-sc-meta-lib", ] [[package]] name = "fiat-crypto" -version = "0.2.6" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1676f435fc1dadde4d03e43f5d62b259e1ce5f40bd4ffb21db2b42ebe59c1382" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" [[package]] name = "fixed-supply-token" @@ -983,154 +864,46 @@ dependencies = [ ] [[package]] -name = "flate2" -version = "1.0.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +name = "fuzz" +version = "0.0.0" dependencies = [ - "crc32fast", - "miniz_oxide", + "common_structs", + "config", + "farm", + "farm-staking", + "farm_token", + "multiversx-sc", + "multiversx-sc-scenario", + "num-bigint", + "pair", + "pair-mock", + "pausable", + "price-discovery", + "rand", + "rewards", + "router", + "simple-lock", ] [[package]] -name = "fnv" -version = "1.0.7" +name = "generic-array" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] [[package]] -name = "foreign-types" -version = "0.3.2" +name = "getrandom" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" 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" -dependencies = [ - "common_structs", - "config", - "factory", - "farm", - "farm-staking", - "farm_token", - "multiversx-sc", - "multiversx-sc-scenario", - "num-bigint", - "pair", - "pair-mock", - "pausable", - "price-discovery", - "rand", - "rewards", - "router", - "simple-lock", -] - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "getrandom" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "wasi", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - -[[package]] -name = "globset" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1" -dependencies = [ - "aho-corasick", - "bstr", - "log", - "regex-automata", - "regex-syntax", + "cfg-if", + "libc", + "wasi", ] [[package]] @@ -1148,7 +921,7 @@ name = "governance-meta" version = "0.0.0" dependencies = [ "governance", - "multiversx-sc-meta", + "multiversx-sc-meta-lib", ] [[package]] @@ -1170,45 +943,24 @@ name = "governance-v2-meta" version = "0.0.0" dependencies = [ "governance-v2", - "multiversx-sc-meta", + "multiversx-sc-meta-lib", ] [[package]] -name = "h2" -version = "0.3.24" +name = "hashbrown" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb2c4422095b67ee78da96fbb51a4cc413b3b25883c7717ff7ca1ab31022c9c9" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", + "ahash", + "serde", ] -[[package]] -name = "hashbrown" -version = "0.14.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" - [[package]] name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - -[[package]] -name = "hermit-abi" -version = "0.3.5" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0c62115964e08cb8039170eb33c1d0e2388a256930279edca206fff675f82c3" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hex" @@ -1228,127 +980,22 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - -[[package]] -name = "http" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" -dependencies = [ - "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" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824b2ae422412366ba479e8111fd301f7b5faece8149317bb81925979a53f520" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", "hashbrown", + "serde", ] [[package]] -name = "ipnet" -version = "2.9.0" +name = "is_terminal_polyfill" +version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "itertools" @@ -1361,27 +1008,18 @@ dependencies = [ [[package]] name = "itertools" -version = "0.12.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" 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" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee" -dependencies = [ - "wasm-bindgen", -] +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "keccak" @@ -1394,9 +1032,9 @@ dependencies = [ [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "legacy_token_decode_module" @@ -1409,15 +1047,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.153" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" - -[[package]] -name = "linux-raw-sys" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "lkmex-transfer" @@ -1441,17 +1073,24 @@ name = "lkmex-transfer-abi" version = "0.0.0" dependencies = [ "lkmex-transfer", - "multiversx-sc-meta", + "multiversx-sc-meta-lib", ] [[package]] -name = "lock_api" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +name = "locked-asset-distribution" +version = "0.0.0" dependencies = [ - "autocfg", - "scopeguard", + "common_structs", + "multiversx-sc", + "multiversx-sc-scenario", +] + +[[package]] +name = "locked-asset-distribution-abi" +version = "0.0.0" +dependencies = [ + "locked-asset-distribution", + "multiversx-sc-meta-lib", ] [[package]] @@ -1479,7 +1118,7 @@ name = "locked-token-wrapper-meta" version = "0.0.0" dependencies = [ "locked-token-wrapper", - "multiversx-sc-meta", + "multiversx-sc-meta-lib", ] [[package]] @@ -1493,9 +1132,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.20" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "math" @@ -1506,15 +1145,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" - -[[package]] -name = "memory_units" -version = "0.4.0" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "mergeable" @@ -1524,56 +1157,27 @@ dependencies = [ ] [[package]] -name = "metabonding-staking" +name = "metabonding-staking-legacy" version = "0.0.0" dependencies = [ - "common_structs", - "factory", "multiversx-sc", - "multiversx-sc-modules", "multiversx-sc-scenario", "num-bigint", ] [[package]] -name = "metabonding-staking-meta" +name = "metabonding-staking-legacy-meta" version = "0.0.0" dependencies = [ - "metabonding-staking", - "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", + "metabonding-staking-legacy", + "multiversx-sc-meta-lib", ] [[package]] name = "multiversx-chain-scenario-format" -version = "0.21.1" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfc2b1dc76af14c24145672c2779474046ab44ef56bac82a58844328f4b4d2e" +checksum = "dcca77966bf5eb9c9f96d0597f17a4fa7b64681cc7b83e39bdf31f8c6ca04d44" dependencies = [ "bech32", "hex", @@ -1586,15 +1190,16 @@ dependencies = [ [[package]] name = "multiversx-chain-vm" -version = "0.7.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75459864359798406a45a7bb2ed221d623b2e39484ec3e4ac6d23167bfc50b33" +checksum = "13c537d27dfc7a8e295d4f7c5f67a967ce66b6c3fc8e31a160e8cf28e14ecb2d" dependencies = [ - "bitflags 2.4.2", + "bitflags", + "colored", "ed25519-dalek", "hex", "hex-literal 0.4.1", - "itertools 0.12.1", + "itertools 0.13.0", "multiversx-chain-vm-executor", "num-bigint", "num-traits", @@ -1612,33 +1217,35 @@ checksum = "b59072fa0624b55ae5ae3fa6bfa91515bbeb4ac440214bc4a509e2c8806d6e9f" [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ - "bitflags 2.4.2", + "bitflags", "hex-literal 0.4.1", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", "num-bigint", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -1648,9 +1255,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -1660,110 +1267,59 @@ dependencies = [ ] [[package]] -name = "multiversx-sc-meta" -version = "0.46.1" +name = "multiversx-sc-meta-lib" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c8250fd72b78dff76fd3789078aee3dec2524ca37250c645dcb2b1bf067551e" +checksum = "ef023806e14a8a6245408c4a7dfdf17d4a1eb39425cedfe50cd2c48f96708ab6" dependencies = [ "clap", "colored", - "common-path", "convert_case", - "copy_dir", "hex", "lazy_static", "multiversx-sc", - "pathdiff", - "reqwest", - "ruplacer", "rustc_version", + "semver", "serde", "serde_json", "toml", - "wasmparser 0.118.1", + "wasmparser", "wasmprinter", - "zip", ] [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-scenario" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3aa2644018c85caf3cc39a130961e39bd719ff3d75751b60a7394d6eace1c847" +checksum = "cd16e3bf1f6696d0add36b7b905b1ffdd13b836e584da000f5e265c11e2bfc8d" dependencies = [ "base64", "bech32", - "clap", "colored", "hex", - "itertools 0.12.1", + "itertools 0.13.0", "log", "multiversx-chain-scenario-format", "multiversx-chain-vm", "multiversx-chain-vm-executor", "multiversx-sc", - "multiversx-sc-meta", - "multiversx-sdk", + "multiversx-sc-meta-lib", "num-bigint", "num-traits", "pathdiff", "serde", "serde_json", "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", + "unwrap-infallible", ] [[package]] @@ -1777,103 +1333,38 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.4" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ - "autocfg", "num-integer", "num-traits", ] [[package]] name = "num-integer" -version = "0.1.45" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "autocfg", "num-traits", ] [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" 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" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -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 = "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" version = "0.0.0" @@ -1896,7 +1387,7 @@ dependencies = [ name = "pair-abi" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", + "multiversx-sc-meta-lib", "pair", ] @@ -1914,33 +1405,10 @@ dependencies = [ name = "pair-mock-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", + "multiversx-sc-meta-lib", "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" @@ -1971,56 +1439,19 @@ dependencies = [ name = "pause-all-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", + "multiversx-sc-meta-lib", "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 2.4.2", + "bitflags", "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" @@ -2031,23 +1462,14 @@ dependencies = [ "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" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] [[package]] name = "price-discovery" @@ -2068,15 +1490,49 @@ dependencies = [ name = "price-discovery-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", + "multiversx-sc-meta-lib", "price-discovery", ] +[[package]] +name = "price-discovery-v1" +version = "0.0.0" +dependencies = [ + "multiversx-sc", + "multiversx-sc-scenario", + "num-bigint", +] + +[[package]] +name = "price-discovery-v1-meta" +version = "0.0.0" +dependencies = [ + "multiversx-sc-meta-lib", + "price-discovery-v1", +] + +[[package]] +name = "price-discovery-v2" +version = "0.0.0" +dependencies = [ + "multiversx-sc", + "multiversx-sc-scenario", + "num-bigint", +] + +[[package]] +name = "price-discovery-v2-meta" +version = "0.0.0" +dependencies = [ + "multiversx-sc-meta-lib", + "price-discovery-v2", +] + [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -2098,10 +1554,33 @@ dependencies = [ name = "proxy-deployer-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", + "multiversx-sc-meta-lib", "proxy-deployer", ] +[[package]] +name = "proxy-dex-legacy" +version = "0.0.0" +dependencies = [ + "common_structs", + "energy-factory", + "energy-query", + "factory-legacy", + "farm-v13-locked-rewards", + "multiversx-sc", + "multiversx-sc-scenario", + "pair", + "token_merge_helper", +] + +[[package]] +name = "proxy-dex-legacy-meta" +version = "0.0.0" +dependencies = [ + "multiversx-sc-meta-lib", + "proxy-dex-legacy", +] + [[package]] name = "proxy_dex" version = "0.0.0" @@ -2140,15 +1619,15 @@ dependencies = [ name = "proxy_dex-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", + "multiversx-sc-meta-lib", "proxy_dex", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -2195,91 +1674,13 @@ dependencies = [ [[package]] name = "rand_seeder" -version = "0.2.3" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf2890aaef0aa82719a50e808de264f9484b74b442e1a3a0e5ee38243ac40bdb" +checksum = "4a9febe641d2842ffc76ee962668a17578767c4e01735e4802b21ed9a24b2e4e" dependencies = [ "rand_core", ] -[[package]] -name = "redox_syscall" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "regex" -version = "1.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" - -[[package]] -name = "reqwest" -version = "0.11.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6920094eb85afde5e4a138be3f2de8bbdf28000f0029e72c45025a56b042251" -dependencies = [ - "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" @@ -2312,75 +1713,24 @@ dependencies = [ name = "router-abi" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", + "multiversx-sc-meta-lib", "router", ] -[[package]] -name = "ruplacer" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58a26a1b15ff113d31d139357f7422708312978ed69cd5dd47e36d1b80b7eaf3" -dependencies = [ - "Inflector", - "anyhow", - "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" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ "semver", ] -[[package]] -name = "rustix" -version = "0.38.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" -dependencies = [ - "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" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" - -[[package]] -name = "same-file" -version = "1.0.6" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "sc_whitelist_module" @@ -2390,87 +1740,26 @@ 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.21" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" - -[[package]] -name = "serde" -version = "1.0.196" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.196" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] -name = "serde_json" -version = "1.0.113" +name = "serde" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79" +checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" dependencies = [ - "indexmap", - "itoa", - "ryu", - "serde", + "serde_derive", ] [[package]] -name = "serde_repr" -version = "0.1.18" +name = "serde_derive" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb" +checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" dependencies = [ "proc-macro2", "quote", @@ -2478,23 +1767,23 @@ dependencies = [ ] [[package]] -name = "serde_spanned" -version = "0.6.5" +name = "serde_json" +version = "1.0.127" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" dependencies = [ + "itoa", + "memchr", + "ryu", "serde", ] [[package]] -name = "serde_urlencoded" -version = "0.7.1" +name = "serde_spanned" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" dependencies = [ - "form_urlencoded", - "itoa", - "ryu", "serde", ] @@ -2504,7 +1793,7 @@ version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", "digest", ] @@ -2519,15 +1808,6 @@ dependencies = [ "keccak", ] -[[package]] -name = "signal-hook-registry" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" -dependencies = [ - "libc", -] - [[package]] name = "signature" version = "2.2.0" @@ -2551,59 +1831,39 @@ dependencies = [ ] [[package]] -name = "simple-lock-meta" -version = "0.0.0" -dependencies = [ - "multiversx-sc-meta", - "simple-lock", -] - -[[package]] -name = "simple-lock-whitelist" +name = "simple-lock-legacy" version = "0.0.0" dependencies = [ + "common_structs", "hex", "multiversx-sc", "multiversx-sc-modules", "multiversx-sc-scenario", "num-bigint", "num-traits", - "simple-lock", - "utils", ] [[package]] -name = "simple-lock-whitelist-meta" +name = "simple-lock-legacy-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", - "simple-lock-whitelist", + "multiversx-sc-meta-lib", + "simple-lock-legacy", ] [[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +name = "simple-lock-meta" +version = "0.0.0" dependencies = [ - "autocfg", + "multiversx-sc-meta-lib", + "simple-lock", ] [[package]] name = "smallvec" -version = "1.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" - -[[package]] -name = "socket2" -version = "0.5.5" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" -dependencies = [ - "libc", - "windows-sys 0.48.0", -] +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "spki" @@ -2617,21 +1877,21 @@ dependencies = [ [[package]] name = "strsim" -version = "0.10.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "subtle" -version = "2.5.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -2639,59 +1899,14 @@ dependencies = [ ] [[package]] -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 = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" -dependencies = [ - "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 = "tempfile" -version = "3.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a365e8cd18e44762ef95d87f284f4b5cd04107fec2ff3052bd6a3e6069669e67" -dependencies = [ - "cfg-if 1.0.0", - "fastrand", - "rustix", - "windows-sys 0.52.0", -] - -[[package]] -name = "tinyvec" -version = "1.6.0" +name = "termcolor" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" dependencies = [ - "tinyvec_macros", + "winapi-util", ] -[[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" @@ -2715,7 +1930,7 @@ dependencies = [ name = "token-unstake-abi" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", + "multiversx-sc-meta-lib", "token-unstake", ] @@ -2736,65 +1951,11 @@ 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.8.10" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a9aad4a3066010876e8dcf5a8a06e70a558751117a145c6ce2b82c2e2054290" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" dependencies = [ "indexmap", "serde", @@ -2805,18 +1966,18 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.5" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.22.4" +version = "0.22.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c9ffdf896f8daaabf9b66ba8e77ea1ed5ed0f72821b398aba62352e95062951" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" dependencies = [ "indexmap", "serde", @@ -2825,70 +1986,30 @@ dependencies = [ "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 = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" @@ -2896,22 +2017,11 @@ 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" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "utils" @@ -2923,36 +2033,11 @@ 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" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "walkdir" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" -dependencies = [ - "same-file", - "winapi-util", -] - -[[package]] -name = "want" -version = "0.3.1" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" -dependencies = [ - "try-lock", -] +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "wasi" @@ -2960,123 +2045,29 @@ 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" +version = "0.216.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953cf6a7606ab31382cb1caa5ae403e77ba70c7f8e12eeda167e7040d42bfda8" +checksum = "bcdee6bea3619d311fb4b299721e89a986c3470f804b6d534340e412589028e3" dependencies = [ - "bitflags 2.4.2", + "ahash", + "bitflags", + "hashbrown", "indexmap", "semver", + "serde", ] [[package]] name = "wasmprinter" -version = "0.2.78" +version = "0.216.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05e32c13c59fdc64d3f6998a1d52eb1d362b6904a88b754190ccb85661ad577a" +checksum = "8f82916f3892e53620639217d6ec78fe15c678352a3fbf3f3745b6417d0bd70f" 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" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "memory_units", - "winapi", + "termcolor", + "wasmparser", ] [[package]] @@ -3099,37 +2090,15 @@ dependencies = [ "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-util" -version = "0.1.6" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "winapi", + "windows-sys 0.59.0", ] -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - [[package]] name = "windows-sys" version = "0.48.0" @@ -3145,7 +2114,16 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.0", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", ] [[package]] @@ -3165,17 +2143,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.0", - "windows_aarch64_msvc 0.52.0", - "windows_i686_gnu 0.52.0", - "windows_i686_msvc 0.52.0", - "windows_x86_64_gnu 0.52.0", - "windows_x86_64_gnullvm 0.52.0", - "windows_x86_64_msvc 0.52.0", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -3186,9 +2165,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -3198,9 +2177,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -3210,9 +2189,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.0" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -3222,9 +2207,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -3234,9 +2219,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -3246,9 +2231,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -3258,43 +2243,42 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.5.39" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5389a154b01683d28c77f8f68f49dea75f0a4da32557a58f68ee51ebba472d29" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" dependencies = [ "memchr", ] [[package]] -name = "winreg" -version = "0.50.0" +name = "zerocopy" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ - "cfg-if 1.0.0", - "windows-sys 0.48.0", + "byteorder", + "zerocopy-derive", ] [[package]] -name = "zeroize" -version = "1.7.0" +name = "zerocopy-derive" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "zip" -version = "0.6.6" +name = "zeroize" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" -dependencies = [ - "byteorder", - "crc32fast", - "crossbeam-utils", - "flate2", -] +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/Cargo.toml b/Cargo.toml index dbdd0d3ec..81e48c99e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,24 +34,41 @@ members = [ "farm-staking/farm-staking/meta", "farm-staking/farm-staking-proxy", "farm-staking/farm-staking-proxy/meta", - "farm-staking/metabonding-staking", - "farm-staking/metabonding-staking/meta", + + "legacy-contracts/simple-lock-legacy", + "legacy-contracts/simple-lock-legacy/meta", + "legacy-contracts/farm-staking-proxy-v13", + "legacy-contracts/farm-staking-proxy-v13/meta", + "legacy-contracts/metabonding-staking-legacy", + "legacy-contracts/metabonding-staking-legacy/meta", + "legacy-contracts/farm-v12", + "legacy-contracts/farm-v12/meta", + "legacy-contracts/farm-v13", + "legacy-contracts/farm-v13/meta", + "legacy-contracts/farm-v13-locked-rewards", + "legacy-contracts/farm-v13-locked-rewards/meta", + "legacy-contracts/farm-v13-custom-rewards", + "legacy-contracts/farm-v13-custom-rewards/meta", + "legacy-contracts/proxy-dex-legacy", + "legacy-contracts/proxy-dex-legacy/meta", + "legacy-contracts/factory-legacy", + "legacy-contracts/factory-legacy/meta", + "legacy-contracts/price-discovery-v1", + "legacy-contracts/price-discovery-v1/meta", + "legacy-contracts/price-discovery-v2", + "legacy-contracts/price-discovery-v2/meta", + "legacy-contracts/locked-asset-distribution", + "legacy-contracts/locked-asset-distribution/meta", "locked-asset/", - "locked-asset/distribution", - "locked-asset/distribution/meta", "locked-asset/proxy_dex", "locked-asset/proxy_dex/meta", "locked-asset/lkmex-transfer", "locked-asset/lkmex-transfer/meta", "locked-asset/locked-token-wrapper", "locked-asset/locked-token-wrapper/meta", - "locked-asset/factory", - "locked-asset/factory/meta", "locked-asset/simple-lock", "locked-asset/simple-lock/meta", - "locked-asset/simple-lock-whitelist", - "locked-asset/simple-lock-whitelist/meta", "locked-asset/energy-factory", "locked-asset/energy-factory/meta", "locked-asset/token-unstake", diff --git a/common/common_errors/Cargo.toml b/common/common_errors/Cargo.toml index c61a89e80..343089fb5 100644 --- a/common/common_errors/Cargo.toml +++ b/common/common_errors/Cargo.toml @@ -8,5 +8,5 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/common_structs/Cargo.toml b/common/common_structs/Cargo.toml index 8e5655f12..74e79fc08 100644 --- a/common/common_structs/Cargo.toml +++ b/common/common_structs/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.mergeable] diff --git a/common/common_structs/src/farm_types.rs b/common/common_structs/src/farm_types.rs index db4d515c9..d7d85e20b 100644 --- a/common/common_structs/src/farm_types.rs +++ b/common/common_structs/src/farm_types.rs @@ -51,8 +51,8 @@ impl FixedSupplyToken for FarmTokenAttributes { impl Mergeable for FarmTokenAttributes { #[inline] - fn can_merge_with(&self, other: &Self) -> bool { - self.original_owner == other.original_owner + fn can_merge_with(&self, _other: &Self) -> bool { + true } fn merge_with(&mut self, other: Self) { diff --git a/common/modules/farm/config/Cargo.toml b/common/modules/farm/config/Cargo.toml index b5de657af..42868939f 100644 --- a/common/modules/farm/config/Cargo.toml +++ b/common/modules/farm/config/Cargo.toml @@ -23,5 +23,5 @@ path = "../../pausable" path = "../../permissions_module" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" 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 b712765e5..88858153e 100644 --- a/common/modules/farm/config/src/config.rs +++ b/common/modules/farm/config/src/config.rs @@ -9,66 +9,14 @@ 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 @@ -121,10 +69,12 @@ pub trait ConfigModule: pausable::PausableModule + permissions_module::Permissio #[view(getUserTotalFarmPosition)] #[storage_mapper("userTotalFarmPosition")] - fn user_total_farm_position( - &self, - user: &ManagedAddress, - ) -> SingleValueMapper>; + fn user_total_farm_position(&self, user: &ManagedAddress) -> SingleValueMapper; + + // Update for this storage disabled for this version of the exchange + #[view(getAllowExternalClaim)] + #[storage_mapper("allowExternalClaim")] + fn allow_external_claim(&self, user: &ManagedAddress) -> SingleValueMapper; #[view(getFarmPositionMigrationNonce)] #[storage_mapper("farm_position_migration_nonce")] diff --git a/common/modules/farm/contexts/Cargo.toml b/common/modules/farm/contexts/Cargo.toml index b61c7a7cb..1e09c2bed 100644 --- a/common/modules/farm/contexts/Cargo.toml +++ b/common/modules/farm/contexts/Cargo.toml @@ -35,8 +35,8 @@ path = "../../pausable" path = "../../permissions_module" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" diff --git a/common/modules/farm/contexts/src/mod.rs b/common/modules/farm/contexts/src/mod.rs index e8f133eb6..a1ceed191 100644 --- a/common/modules/farm/contexts/src/mod.rs +++ b/common/modules/farm/contexts/src/mod.rs @@ -1,5 +1,4 @@ #![no_std] -#![feature(trait_alias)] pub mod claim_rewards_context; pub mod enter_farm_context; diff --git a/common/modules/farm/contexts/src/storage_cache.rs b/common/modules/farm/contexts/src/storage_cache.rs index 4e14ea2ec..76f4cfc1d 100644 --- a/common/modules/farm/contexts/src/storage_cache.rs +++ b/common/modules/farm/contexts/src/storage_cache.rs @@ -3,8 +3,15 @@ multiversx_sc::derive_imports!(); use pausable::State; -pub trait FarmContracTraitBounds = - config::ConfigModule + rewards::RewardsModule + farm_token::FarmTokenModule; +pub trait FarmContracTraitBounds: + config::ConfigModule + rewards::RewardsModule + farm_token::FarmTokenModule +{ +} + +impl FarmContracTraitBounds for T where + T: config::ConfigModule + rewards::RewardsModule + farm_token::FarmTokenModule +{ +} pub struct StorageCache<'a, C: FarmContracTraitBounds> { sc_ref: &'a C, diff --git a/common/modules/farm/events/Cargo.toml b/common/modules/farm/events/Cargo.toml index f69904d95..06b1c21c7 100644 --- a/common/modules/farm/events/Cargo.toml +++ b/common/modules/farm/events/Cargo.toml @@ -14,5 +14,5 @@ path = "../../../common_structs" path = "../contexts" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" 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 7ac538eff..e8c7462d3 100644 --- a/common/modules/farm/farm_base_impl/Cargo.toml +++ b/common/modules/farm/farm_base_impl/Cargo.toml @@ -50,11 +50,11 @@ path = "../../../traits/mergeable" path = "../../../traits/fixed-supply-token" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" diff --git a/common/modules/farm/farm_base_impl/src/base_traits_impl.rs b/common/modules/farm/farm_base_impl/src/base_traits_impl.rs index f2ccc293c..f7f5014ff 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 @@ -4,18 +4,31 @@ use common_structs::{FarmToken, FarmTokenAttributes, Nonce}; use config::ConfigModule; use contexts::storage_cache::StorageCache; use core::marker::PhantomData; +use farm_token::FarmTokenModule; use fixed_supply_token::FixedSupplyToken; use mergeable::Mergeable; use multiversx_sc_modules::transfer_role_proxy::PaymentsVec; use rewards::RewardsModule; -pub trait AllBaseFarmImplTraits = +pub trait AllBaseFarmImplTraits: rewards::RewardsModule + + config::ConfigModule + + farm_token::FarmTokenModule + + permissions_module::PermissionsModule + + pausable::PausableModule + + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule +{ +} + +impl AllBaseFarmImplTraits for T where + T: rewards::RewardsModule + config::ConfigModule + farm_token::FarmTokenModule + permissions_module::PermissionsModule + pausable::PausableModule - + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule; + + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule +{ +} pub trait FarmContract { type FarmSc: AllBaseFarmImplTraits; @@ -30,8 +43,7 @@ pub trait FarmContract { + FixedSupplyToken<::Api> + FarmToken<::Api> + From::Api>> - + Into::Api>> = - FarmTokenAttributes<::Api>; + + Into::Api>>; #[inline] fn mint_rewards( @@ -218,10 +230,8 @@ pub trait FarmContract { 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); + .update(|total_farm_position| *total_farm_position += increase_farm_position_amount); } fn decrease_user_farm_position( @@ -236,14 +246,16 @@ pub trait FarmContract { 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(); - } - }); + let user_total_farm_position_mapper = + sc.user_total_farm_position(&token_attributes.original_owner); + let mut user_total_farm_position = user_total_farm_position_mapper.get(); + + if user_total_farm_position > farm_position.amount { + user_total_farm_position -= &farm_position.amount; + user_total_farm_position_mapper.set(user_total_farm_position); + } else { + user_total_farm_position_mapper.clear(); + } } } @@ -259,4 +271,5 @@ where T: AllBaseFarmImplTraits, { type FarmSc = T; + type AttributesType = FarmTokenAttributes<::Api>; } diff --git a/common/modules/farm/farm_base_impl/src/lib.rs b/common/modules/farm/farm_base_impl/src/lib.rs index f63df2820..24e156d2a 100644 --- a/common/modules/farm/farm_base_impl/src/lib.rs +++ b/common/modules/farm/farm_base_impl/src/lib.rs @@ -1,8 +1,4 @@ #![no_std] -#![allow(clippy::too_many_arguments)] -#![feature(exact_size_is_empty)] -#![feature(trait_alias)] -#![feature(associated_type_defaults)] multiversx_sc::imports!(); multiversx_sc::derive_imports!(); diff --git a/common/modules/farm/farm_token/Cargo.toml b/common/modules/farm/farm_token/Cargo.toml index 64834bd68..aef369e13 100644 --- a/common/modules/farm/farm_token/Cargo.toml +++ b/common/modules/farm/farm_token/Cargo.toml @@ -26,8 +26,8 @@ path = "../../pausable" path = "../../permissions_module" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" diff --git a/common/modules/farm/farm_token_merge/Cargo.toml b/common/modules/farm/farm_token_merge/Cargo.toml index 4df9540e8..038e7b313 100644 --- a/common/modules/farm/farm_token_merge/Cargo.toml +++ b/common/modules/farm/farm_token_merge/Cargo.toml @@ -23,11 +23,11 @@ path = "../../token_merge_helper" path = "../farm_token" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" [workspace] members = ["."] diff --git a/common/modules/farm/rewards/Cargo.toml b/common/modules/farm/rewards/Cargo.toml index 68d37f46d..06bed7548 100644 --- a/common/modules/farm/rewards/Cargo.toml +++ b/common/modules/farm/rewards/Cargo.toml @@ -29,8 +29,8 @@ path = "../../pausable" path = "../../permissions_module" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" diff --git a/common/modules/legacy_token_decode_module/Cargo.toml b/common/modules/legacy_token_decode_module/Cargo.toml index 124b2ec02..29bb78f56 100644 --- a/common/modules/legacy_token_decode_module/Cargo.toml +++ b/common/modules/legacy_token_decode_module/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.common_structs] diff --git a/common/modules/locking_module/Cargo.toml b/common/modules/locking_module/Cargo.toml index 660635a24..3de83e7e6 100644 --- a/common/modules/locking_module/Cargo.toml +++ b/common/modules/locking_module/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.simple-lock] diff --git a/common/modules/locking_module/src/lock_with_energy_module.rs b/common/modules/locking_module/src/lock_with_energy_module.rs index cb7b02911..7569c4f61 100644 --- a/common/modules/locking_module/src/lock_with_energy_module.rs +++ b/common/modules/locking_module/src/lock_with_energy_module.rs @@ -36,7 +36,7 @@ pub trait LockWithEnergyModule { .execute_on_dest_context() } - fn get_locking_sc_proxy_instance(&self) -> energy_factory::Proxy { + fn get_locking_sc_proxy_instance(&self) -> energy_factory::ProxyTo { let locking_sc_address = self.locking_sc_address().get(); self.locking_sc_proxy_obj(locking_sc_address) } diff --git a/common/modules/locking_module/src/locking_module.rs b/common/modules/locking_module/src/locking_module.rs index 4b79a57af..05596a2f5 100644 --- a/common/modules/locking_module/src/locking_module.rs +++ b/common/modules/locking_module/src/locking_module.rs @@ -53,13 +53,13 @@ pub trait LockingModule { .execute_on_dest_context() } - fn get_locking_sc_proxy_instance(&self) -> simple_lock::Proxy { + fn get_locking_sc_proxy_instance(&self) -> simple_lock::ProxyTo { let locking_sc_address = self.locking_sc_address().get(); self.locking_sc_proxy_obj(locking_sc_address) } #[proxy] - fn locking_sc_proxy_obj(&self, sc_address: ManagedAddress) -> simple_lock::Proxy; + fn locking_sc_proxy_obj(&self, sc_address: ManagedAddress) -> simple_lock::ProxyTo; #[view(getLockingScAddress)] #[storage_mapper("lockingScAddress")] diff --git a/common/modules/math/Cargo.toml b/common/modules/math/Cargo.toml index 5f1f99325..b8aa25486 100644 --- a/common/modules/math/Cargo.toml +++ b/common/modules/math/Cargo.toml @@ -8,5 +8,5 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/pausable/Cargo.toml b/common/modules/pausable/Cargo.toml index 2f258161b..9f19f8302 100644 --- a/common/modules/pausable/Cargo.toml +++ b/common/modules/pausable/Cargo.toml @@ -11,5 +11,5 @@ path = "src/pausable.rs" path = "../permissions_module" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/permissions_module/Cargo.toml b/common/modules/permissions_module/Cargo.toml index fdc8d7d2e..99b07bc79 100644 --- a/common/modules/permissions_module/Cargo.toml +++ b/common/modules/permissions_module/Cargo.toml @@ -17,5 +17,5 @@ bitflags = "2.4.1" path = "../../common_errors" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" 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 623c72718..245ccda6a 100644 --- a/common/modules/permissions_module/src/permissions.rs +++ b/common/modules/permissions_module/src/permissions.rs @@ -1,6 +1,6 @@ use bitflags::bitflags; use multiversx_sc::{ - abi::TypeAbi, + abi::{TypeAbi, TypeAbiFrom}, codec::{DecodeError, TopDecode, TopEncode}, }; bitflags! { @@ -32,8 +32,16 @@ impl TopDecode for Permissions { } } -impl TypeAbi for Permissions { - fn type_name() -> multiversx_sc::abi::TypeName { - core::any::type_name::().into() - } -} +impl TypeAbiFrom for Permissions {} + + impl TypeAbi for Permissions { + type Unmanaged = Self; + + fn type_name() -> multiversx_sc::abi::TypeName { + core::any::type_name::().into() + } + + fn type_name_rust() -> multiversx_sc::abi::TypeName { + core::any::type_name::().into() + } + } \ No newline at end of file diff --git a/common/modules/permissions_module/src/permissions_module.rs b/common/modules/permissions_module/src/permissions_module.rs index 5853ca0da..38eab7fdd 100644 --- a/common/modules/permissions_module/src/permissions_module.rs +++ b/common/modules/permissions_module/src/permissions_module.rs @@ -1,6 +1,6 @@ #![no_std] -mod permissions; +pub mod permissions; use common_errors::ERROR_PERMISSION_DENIED; diff --git a/common/modules/sc_whitelist_module/Cargo.toml b/common/modules/sc_whitelist_module/Cargo.toml index 978cd6a89..b67ca8ee6 100644 --- a/common/modules/sc_whitelist_module/Cargo.toml +++ b/common/modules/sc_whitelist_module/Cargo.toml @@ -11,5 +11,5 @@ path = "src/sc_whitelist_module.rs" path = "../../common_errors" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/token_merge_helper/Cargo.toml b/common/modules/token_merge_helper/Cargo.toml index c337a5996..b5b8c1997 100644 --- a/common/modules/token_merge_helper/Cargo.toml +++ b/common/modules/token_merge_helper/Cargo.toml @@ -11,5 +11,5 @@ path = "src/lib.rs" path = "../../common_errors" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/token_send/Cargo.toml b/common/modules/token_send/Cargo.toml index 28b005064..2f2ddb019 100644 --- a/common/modules/token_send/Cargo.toml +++ b/common/modules/token_send/Cargo.toml @@ -14,5 +14,5 @@ path = "../../common_structs" path = "../../common_errors" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/utils/Cargo.toml b/common/modules/utils/Cargo.toml index a18635d6e..6f68bd56b 100644 --- a/common/modules/utils/Cargo.toml +++ b/common/modules/utils/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.common_structs] diff --git a/common/traits/fixed-supply-token/Cargo.toml b/common/traits/fixed-supply-token/Cargo.toml index eafd9fe32..ec88d5add 100644 --- a/common/traits/fixed-supply-token/Cargo.toml +++ b/common/traits/fixed-supply-token/Cargo.toml @@ -8,4 +8,4 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" diff --git a/common/traits/mergeable/Cargo.toml b/common/traits/mergeable/Cargo.toml index 4800de5ca..1f7ce043d 100644 --- a/common/traits/mergeable/Cargo.toml +++ b/common/traits/mergeable/Cargo.toml @@ -8,5 +8,5 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/traits/unwrappable/Cargo.toml b/common/traits/unwrappable/Cargo.toml index 9ba6e7e73..a406958a0 100644 --- a/common/traits/unwrappable/Cargo.toml +++ b/common/traits/unwrappable/Cargo.toml @@ -8,5 +8,5 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] diff --git a/dex/Cargo.toml b/dex/Cargo.toml index 62d9161bf..56a8d4173 100644 --- a/dex/Cargo.toml +++ b/dex/Cargo.toml @@ -5,17 +5,17 @@ edition = "2021" publish = false [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" [dev-dependencies.config] path = "../common/modules/farm/config" @@ -44,9 +44,6 @@ path = "../farm-staking/farm-staking" [dev-dependencies.farm-staking-proxy] path = "../farm-staking/farm-staking-proxy" -[dev-dependencies.factory] -path = "../locked-asset/factory" - [dev-dependencies.simple-lock] path = "../locked-asset/simple-lock" diff --git a/dex/farm-with-locked-rewards/Cargo.toml b/dex/farm-with-locked-rewards/Cargo.toml index c19480688..eedd45925 100644 --- a/dex/farm-with-locked-rewards/Cargo.toml +++ b/dex/farm-with-locked-rewards/Cargo.toml @@ -75,17 +75,17 @@ path = "../../locked-asset/energy-factory" path = "../../energy-integration/common-modules/energy-query" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" [dev-dependencies.simple-lock] path = "../../locked-asset/simple-lock" diff --git a/dex/farm-with-locked-rewards/meta/Cargo.toml b/dex/farm-with-locked-rewards/meta/Cargo.toml index 47476c339..ba8b0bc2b 100644 --- a/dex/farm-with-locked-rewards/meta/Cargo.toml +++ b/dex/farm-with-locked-rewards/meta/Cargo.toml @@ -8,6 +8,6 @@ publish = false [dependencies.farm-with-locked-rewards] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/dex/farm-with-locked-rewards/meta/src/main.rs b/dex/farm-with-locked-rewards/meta/src/main.rs index fa5c57cdf..0f8ec78ae 100644 --- a/dex/farm-with-locked-rewards/meta/src/main.rs +++ b/dex/farm-with-locked-rewards/meta/src/main.rs @@ -1,3 +1,3 @@ fn main() { - multiversx_sc_meta::cli_main::(); + multiversx_sc_meta_lib::cli_main::(); } diff --git a/dex/farm-with-locked-rewards/src/lib.rs b/dex/farm-with-locked-rewards/src/lib.rs index a42f6518c..7434704d1 100644 --- a/dex/farm-with-locked-rewards/src/lib.rs +++ b/dex/farm-with-locked-rewards/src/lib.rs @@ -1,6 +1,4 @@ #![no_std] -#![allow(clippy::too_many_arguments)] -#![feature(exact_size_is_empty)] multiversx_sc::imports!(); multiversx_sc::derive_imports!(); @@ -8,13 +6,14 @@ multiversx_sc::derive_imports!(); use common_structs::FarmTokenAttributes; use contexts::storage_cache::StorageCache; use core::marker::PhantomData; +use fixed_supply_token::FixedSupplyToken; use farm::{ base_functions::{BaseFunctionsModule, ClaimRewardsResultType, DoubleMultiPayment, Wrapper}, exit_penalty::{ DEFAULT_BURN_GAS_LIMIT, DEFAULT_MINUMUM_FARMING_EPOCHS, DEFAULT_PENALTY_PERCENT, }, - EnterFarmResultType, ExitFarmWithPartialPosResultType, + EnterFarmResultType, ExitFarmWithPartialPosResultType, MAX_PERCENT, }; use farm_base_impl::base_traits_impl::FarmContract; @@ -81,7 +80,7 @@ pub trait Farm: self.try_set_farm_position_migration_nonce(farm_token_mapper); } - #[endpoint] + #[upgrade] fn upgrade(&self) { let current_epoch = self.blockchain().get_block_epoch(); self.first_week_start_epoch().set_if_empty(current_epoch); @@ -128,30 +127,19 @@ pub trait Farm: 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(); - self.send_payment_non_zero(&caller, &output_farm_token_payment); + let claim_rewards_result = self.claim_rewards::>(orig_caller.clone()); - let rewards_payment = base_claim_rewards_result.rewards; + self.send_payment_non_zero(&caller, &claim_rewards_result.new_farm_token); + + let rewards_payment = claim_rewards_result.rewards; let locked_rewards_payment = self.send_to_lock_contract_non_zero( rewards_payment.token_identifier, rewards_payment.amount, caller, - orig_caller.clone(), - ); - - self.emit_claim_rewards_event::<_, FarmTokenAttributes>( - &orig_caller, - base_claim_rewards_result.context, - base_claim_rewards_result.new_farm_token, - locked_rewards_payment.clone(), - base_claim_rewards_result.created_with_merge, - base_claim_rewards_result.storage_cache, + orig_caller, ); - (output_farm_token_payment, locked_rewards_payment).into() + (claim_rewards_result.new_farm_token, locked_rewards_payment).into() } #[payable("*")] @@ -198,7 +186,7 @@ pub trait Farm: self.migrate_old_farm_positions(&orig_caller); let boosted_rewards = self.claim_only_boosted_payment(&orig_caller); - let merged_farm_token = self.merge_farm_tokens::>(); + let merged_farm_token = self.merge_and_update_farm_tokens(orig_caller.clone()); self.send_payment_non_zero(&caller, &merged_farm_token); let locked_rewards_payment = self.send_to_lock_contract_non_zero( @@ -211,6 +199,16 @@ pub trait Farm: (merged_farm_token, locked_rewards_payment).into() } + fn merge_and_update_farm_tokens(&self, orig_caller: ManagedAddress) -> EsdtTokenPayment { + let mut output_attributes = + self.merge_and_return_attributes::>(&orig_caller); + output_attributes.original_owner = orig_caller; + + let new_token_amount = output_attributes.get_total_supply(); + self.farm_token() + .nft_create(new_token_amount, &output_attributes) + } + #[endpoint(claimBoostedRewards)] fn claim_boosted_rewards( &self, @@ -221,15 +219,26 @@ pub trait Farm: 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, + self.allow_external_claim(user).get(), "Cannot claim rewards for this address" ); } + require!( + !self.user_total_farm_position(user).is_empty(), + "User total farm position is empty!" + ); + + let mut storage_cache = StorageCache::new(self); + self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); + NoMintWrapper::::generate_aggregated_rewards(self, &mut storage_cache); + let boosted_rewards = self.claim_only_boosted_payment(user); + + self.set_farm_supply_for_current_week(&storage_cache.farm_token_supply); + self.send_to_lock_contract_non_zero( self.reward_token_id().get(), boosted_rewards, @@ -256,6 +265,17 @@ pub trait Farm: self.set_per_block_rewards::>(per_block_amount); } + #[endpoint(setBoostedYieldsRewardsPercentage)] + fn set_boosted_yields_rewards_percentage(&self, percentage: u64) { + self.require_caller_has_admin_permissions(); + require!(percentage <= MAX_PERCENT, "Invalid percentage"); + + let mut storage_cache = StorageCache::new(self); + NoMintWrapper::::generate_aggregated_rewards(self, &mut storage_cache); + + self.boosted_yields_rewards_percentage().set(percentage); + } + #[view(calculateRewardsForGivenPosition)] fn calculate_rewards_for_given_position( &self, 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 f92abc5c7..5f6015658 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 @@ -19,12 +19,12 @@ use fees_collector_mock::*; use energy_factory::{energy::EnergyModule, SimpleLockEnergy}; use energy_query::{Energy, EnergyQueryModule}; use farm_boosted_yields::boosted_yields_factors::BoostedYieldsFactorsModule; -use farm_boosted_yields::FarmBoostedYieldsModule; use farm_token::FarmTokenModule; use farm_with_locked_rewards::Farm; use locking_module::lock_with_energy_module::LockWithEnergyModule; use multiversx_sc_modules::pause::PauseModule; use pausable::{PausableModule, State}; +use rewards::RewardsModule; use sc_whitelist_module::SCWhitelistModule; use simple_lock::locked_token::LockedTokenModule; use week_timekeeping::Epoch; @@ -423,4 +423,53 @@ where ) .assert_ok(); } + + pub fn claim_boosted_rewards_for_user( + &mut self, + owner: &Address, + broker: &Address, + locked_reward_nonce: u64, + ) -> 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!(LOCKED_REWARD_TOKEN_ID) + ); + assert_eq!(reward_payment.token_nonce, locked_reward_nonce); + + result = reward_payment.amount.to_u64().unwrap(); + }) + .assert_ok(); + + result + } + + 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 check_farm_rps(&mut self, expected_amount: u64) { + let b_mock = &mut self.b_mock; + b_mock + .execute_query(&self.farm_wrapper, |sc| { + let current_rps = sc.reward_per_share().get(); + assert_eq!(managed_biguint!(expected_amount), current_rps); + }) + .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 8a9fb8793..649461f18 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,6 +1,8 @@ #![allow(deprecated)] use common_structs::FarmTokenAttributes; +use farm_with_locked_rewards::Farm; +use multiversx_sc::{codec::Empty, imports::OptionalValue}; use multiversx_sc_scenario::{managed_address, managed_biguint, rust_biguint, DebugApi}; use simple_lock::locked_token::LockedTokenAttributes; @@ -335,3 +337,241 @@ fn total_farm_position_claim_with_locked_rewards_test() { None, ); } + +#[test] +fn claim_only_boosted_rewards_per_week_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 = 100_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.check_farm_token_supply(farm_in_amount); + farm_setup.check_farm_rps(0u64); + + farm_setup.b_mock.set_block_nonce(10); + farm_setup.b_mock.set_block_epoch(6); + farm_setup.set_user_energy(&first_user, 1_000, 6, 1); + farm_setup.set_user_energy(&temp_user, 1, 6, 1); + farm_setup.enter_farm(&temp_user, 1); + farm_setup.exit_farm(&temp_user, 2, 1); + + farm_setup.check_farm_rps(75_000_000u64); + + // advance 1 week + farm_setup.set_user_energy(&first_user, 1_000, 13, 1); + farm_setup.b_mock.set_block_nonce(20); + farm_setup.b_mock.set_block_epoch(13); + + let boosted_rewards = 2_500; + let second_week_received_reward_amt = + farm_setup.claim_boosted_rewards_for_user(&first_user, &first_user, 1); + + assert_eq!(second_week_received_reward_amt, boosted_rewards); + farm_setup.check_farm_rps(150_000_000u64); + + // advance 1 week + farm_setup.set_user_energy(&first_user, 1_000, 15, 1); + farm_setup.b_mock.set_block_nonce(30); + farm_setup.b_mock.set_block_epoch(15); + let third_week_received_reward_amt = + farm_setup.claim_boosted_rewards_for_user(&first_user, &first_user, 1); + + assert_eq!(third_week_received_reward_amt, boosted_rewards); + farm_setup.check_farm_rps(225_000_000u64); + + farm_setup.b_mock.check_nft_balance::( + &first_user, + LOCKED_REWARD_TOKEN_ID, + 1, + &rust_biguint!(boosted_rewards * 2), + None, + ); +} + +#[test] +fn claim_rewards_per_week_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 = 100_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.check_farm_token_supply(farm_in_amount); + farm_setup.check_farm_rps(0u64); + + farm_setup.b_mock.set_block_nonce(10); + farm_setup.b_mock.set_block_epoch(6); + farm_setup.set_user_energy(&first_user, 1_000, 6, 1); + farm_setup.set_user_energy(&temp_user, 1, 6, 1); + farm_setup.enter_farm(&temp_user, 1); + farm_setup.exit_farm(&temp_user, 2, 1); + + farm_setup.check_farm_rps(75_000_000u64); + let base_rewards_per_week = 7_500; + let boosted_rewards_per_week = 2_500; + let total_rewards_per_week = base_rewards_per_week + boosted_rewards_per_week; + + // advance 1 week + farm_setup.set_user_energy(&first_user, 1_000, 13, 1); + farm_setup.b_mock.set_block_nonce(20); + farm_setup.b_mock.set_block_epoch(13); + + let second_week_received_reward_amt = farm_setup.claim_rewards(&first_user, 1, farm_in_amount); + + assert_eq!( + second_week_received_reward_amt, + total_rewards_per_week + base_rewards_per_week + ); + farm_setup.check_farm_rps(150_000_000u64); + + // advance 1 week + farm_setup.set_user_energy(&first_user, 1_000, 15, 1); + farm_setup.b_mock.set_block_nonce(30); + farm_setup.b_mock.set_block_epoch(15); + let third_week_received_reward_amt = farm_setup.claim_rewards(&first_user, 3, farm_in_amount); + + assert_eq!(third_week_received_reward_amt, total_rewards_per_week); + farm_setup.check_farm_rps(225_000_000u64); + + farm_setup.b_mock.check_nft_balance::( + &first_user, + LOCKED_REWARD_TOKEN_ID, + 1, + &rust_biguint!(total_rewards_per_week * 2 + base_rewards_per_week), + None, + ); +} + +#[test] +fn claim_boosted_rewards_with_zero_position_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 = 100_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.check_farm_token_supply(farm_in_amount); + farm_setup.check_farm_rps(0u64); + + farm_setup.b_mock.set_block_nonce(10); + farm_setup.b_mock.set_block_epoch(6); + farm_setup.set_user_energy(&first_user, 1_000, 6, 1); + farm_setup.set_user_energy(&temp_user, 1, 6, 1); + farm_setup.enter_farm(&temp_user, 1); + farm_setup.exit_farm(&temp_user, 2, 1); + + farm_setup.check_farm_rps(75_000_000u64); + + // advance 1 week + farm_setup.set_user_energy(&first_user, 1_000, 13, 1); + farm_setup.b_mock.set_block_nonce(20); + farm_setup.b_mock.set_block_epoch(13); + + farm_setup + .b_mock + .execute_tx( + &temp_user, + &farm_setup.farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.claim_boosted_rewards(OptionalValue::Some(managed_address!(&temp_user))); + }, + ) + .assert_error(4, "User total farm position is empty!"); + + farm_setup.check_farm_rps(75_000_000u64); + + // advance 1 week + let boosted_rewards = 2_500; + farm_setup.set_user_energy(&first_user, 1_000, 15, 1); + farm_setup.b_mock.set_block_nonce(30); + farm_setup.b_mock.set_block_epoch(15); + let third_week_received_reward_amt = + farm_setup.claim_boosted_rewards_for_user(&first_user, &first_user, 1); + + assert_eq!(third_week_received_reward_amt, boosted_rewards); + farm_setup.check_farm_rps(225_000_000u64); + + farm_setup.b_mock.check_nft_balance::( + &first_user, + LOCKED_REWARD_TOKEN_ID, + 1, + &rust_biguint!(boosted_rewards), + None, + ); +} + +#[test] +fn claim_boosted_rewards_user_energy_not_registered_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 first_user = farm_setup.first_user.clone(); + let farm_in_amount = 100_000_000; + + farm_setup.set_user_energy(&first_user, 1_000, 2, 1); + + // Attempt to claim boosted rewards without entering the farm + farm_setup + .b_mock + .execute_tx( + &first_user, + &farm_setup.farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.claim_boosted_rewards(OptionalValue::Some(managed_address!(&first_user))); + }, + ) + .assert_error(4, "User total farm position is empty!"); + + // User enters the farm + farm_setup.enter_farm(&first_user, farm_in_amount); + + // Now the user should be able to claim boosted rewards + // Rewards computation is out of scope + farm_setup.claim_boosted_rewards_for_user(&first_user, &first_user, 0); +} diff --git a/dex/farm-with-locked-rewards/wasm/Cargo.lock b/dex/farm-with-locked-rewards/wasm/Cargo.lock index f3af20c87..897ce8c8e 100644 --- a/dex/farm-with-locked-rewards/wasm/Cargo.lock +++ b/dex/farm-with-locked-rewards/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common-types" @@ -76,9 +76,9 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "endian-type" @@ -315,32 +315,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -350,9 +352,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -363,18 +365,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -390,9 +392,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -432,18 +434,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -492,15 +494,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -530,6 +532,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" diff --git a/dex/farm-with-locked-rewards/wasm/Cargo.toml b/dex/farm-with-locked-rewards/wasm/Cargo.toml index 369d8346f..020472854 100644 --- a/dex/farm-with-locked-rewards/wasm/Cargo.toml +++ b/dex/farm-with-locked-rewards/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.farm-with-locked-rewards] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [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 47d140e12..e8aa3099f 100644 --- a/dex/farm-with-locked-rewards/wasm/src/lib.rs +++ b/dex/farm-with-locked-rewards/wasm/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 68 +// Upgrade: 1 +// Endpoints: 66 // Async Callback: 1 -// Total number of exported functions: 70 +// Total number of exported functions: 69 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -29,17 +28,17 @@ multiversx_sc_wasm_adapter::endpoints! { startProduceRewards => start_produce_rewards_endpoint endProduceRewards => end_produce_rewards_endpoint setPerBlockRewardAmount => set_per_block_rewards_endpoint + setBoostedYieldsRewardsPercentage => set_boosted_yields_rewards_percentage 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 + getAllowExternalClaim => allow_external_claim getFarmPositionMigrationNonce => farm_position_migration_nonce setLockingScAddress => set_locking_sc_address setLockEpochs => set_lock_epochs @@ -67,7 +66,6 @@ multiversx_sc_wasm_adapter::endpoints! { 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 diff --git a/dex/farm/Cargo.toml b/dex/farm/Cargo.toml index 517a35cae..f883c4579 100644 --- a/dex/farm/Cargo.toml +++ b/dex/farm/Cargo.toml @@ -69,11 +69,11 @@ path = "../../energy-integration/common-modules/weekly-rewards-splitting" path = "../../energy-integration/common-modules/energy-query" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" [dev-dependencies] num-bigint = "0.4.2" @@ -82,7 +82,7 @@ num-bigint = "0.4.2" path = "../../energy-integration/energy-update" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" [dev-dependencies.energy-factory-mock] path = "../../energy-integration/energy-factory-mock" diff --git a/dex/farm/meta/Cargo.toml b/dex/farm/meta/Cargo.toml index d6abd09e7..14fe0a21e 100644 --- a/dex/farm/meta/Cargo.toml +++ b/dex/farm/meta/Cargo.toml @@ -8,6 +8,6 @@ publish = false [dependencies.farm] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/dex/farm/meta/src/main.rs b/dex/farm/meta/src/main.rs index 0616303c9..ea21b8cf9 100644 --- a/dex/farm/meta/src/main.rs +++ b/dex/farm/meta/src/main.rs @@ -1,3 +1,3 @@ fn main() { - multiversx_sc_meta::cli_main::(); + multiversx_sc_meta_lib::cli_main::(); } diff --git a/dex/farm/src/base_functions.rs b/dex/farm/src/base_functions.rs index 968e3381d..d6455a2b7 100644 --- a/dex/farm/src/base_functions.rs +++ b/dex/farm/src/base_functions.rs @@ -11,9 +11,8 @@ use common_structs::FarmTokenAttributes; use contexts::storage_cache::StorageCache; use farm_base_impl::base_traits_impl::{DefaultFarmWrapper, FarmContract}; -use fixed_supply_token::FixedSupplyToken; -use crate::exit_penalty; +use crate::{exit_penalty, MAX_PERCENT}; pub type DoubleMultiPayment = MultiValue2, EsdtTokenPayment>; pub type ClaimRewardsResultType = DoubleMultiPayment; @@ -183,18 +182,17 @@ pub trait BaseFunctionsModule: } } - fn merge_farm_tokens>(&self) -> EsdtTokenPayment { + fn merge_and_return_attributes>( + &self, + orig_caller: &ManagedAddress, + ) -> FC::AttributesType { let payments = self.get_non_empty_payments(); let token_mapper = self.farm_token(); token_mapper.require_all_same_token(&payments); - let caller = self.blockchain().get_caller(); - FC::check_and_update_user_farm_position(self, &caller, &payments); + FC::check_and_update_user_farm_position(self, orig_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) + self.merge_from_payments_and_burn(payments, &token_mapper) } fn claim_only_boosted_payment(&self, caller: &ManagedAddress) -> BigUint { @@ -220,10 +218,8 @@ pub trait BaseFunctionsModule: } 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); + .update(|total_farm_position| *total_farm_position += &migrated_amount); } migrated_amount @@ -233,10 +229,16 @@ pub trait BaseFunctionsModule: 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; - }); + + let user_total_farm_position_mapper = self.user_total_farm_position(caller); + let mut user_total_farm_position = user_total_farm_position_mapper.get(); + + if user_total_farm_position > migrated_amount { + user_total_farm_position -= &migrated_amount; + user_total_farm_position_mapper.set(user_total_farm_position); + } else { + user_total_farm_position_mapper.clear(); + } } fn end_produce_rewards>(&self) { @@ -283,10 +285,9 @@ where sc: &::FarmSc, caller: &ManagedAddress<<::FarmSc as ContractBase>::Api>, ) -> BigUint<<::FarmSc as ContractBase>::Api> { - let user_total_farm_position = sc.get_user_total_farm_position(caller); - let user_farm_position = user_total_farm_position.total_farm_position; + let user_total_farm_position = sc.user_total_farm_position(caller).get(); - sc.claim_boosted_yields_rewards(caller, user_farm_position) + sc.claim_boosted_yields_rewards(caller, user_total_farm_position) } } @@ -346,7 +347,7 @@ where if user_farming_epochs >= min_farming_epochs { BigUint::zero() } else { - total_exit_amount * sc.penalty_percent().get() / exit_penalty::MAX_PERCENT + total_exit_amount * sc.penalty_percent().get() / MAX_PERCENT } } diff --git a/dex/farm/src/exit_penalty.rs b/dex/farm/src/exit_penalty.rs index e8905fade..19f101a26 100644 --- a/dex/farm/src/exit_penalty.rs +++ b/dex/farm/src/exit_penalty.rs @@ -4,7 +4,8 @@ use common_errors::ERROR_PARAMETERS; use common_structs::Epoch; use pair::pair_actions::remove_liq::ProxyTrait as _; -pub const MAX_PERCENT: u64 = 10_000; +use crate::MAX_PERCENT; + pub const DEFAULT_PENALTY_PERCENT: u64 = 100; pub const DEFAULT_MINUMUM_FARMING_EPOCHS: u64 = 3; pub const DEFAULT_BURN_GAS_LIMIT: u64 = 50_000_000; diff --git a/dex/farm/src/lib.rs b/dex/farm/src/lib.rs index 669dd2e50..2ca53489d 100644 --- a/dex/farm/src/lib.rs +++ b/dex/farm/src/lib.rs @@ -1,6 +1,4 @@ #![no_std] -#![allow(clippy::too_many_arguments)] -#![feature(exact_size_is_empty)] multiversx_sc::imports!(); multiversx_sc::derive_imports!(); @@ -16,10 +14,13 @@ use exit_penalty::{ DEFAULT_BURN_GAS_LIMIT, DEFAULT_MINUMUM_FARMING_EPOCHS, DEFAULT_PENALTY_PERCENT, }; use farm_base_impl::base_traits_impl::FarmContract; +use fixed_supply_token::FixedSupplyToken; pub type EnterFarmResultType = DoubleMultiPayment; pub type ExitFarmWithPartialPosResultType = DoubleMultiPayment; +pub const MAX_PERCENT: u64 = 10_000; + #[multiversx_sc::contract] pub trait Farm: rewards::RewardsModule @@ -82,7 +83,7 @@ pub trait Farm: self.try_set_farm_position_migration_nonce(farm_token_mapper); } - #[endpoint] + #[upgrade] fn upgrade(&self) { let current_epoch = self.blockchain().get_block_epoch(); self.first_week_start_epoch().set_if_empty(current_epoch); @@ -193,13 +194,23 @@ pub trait Farm: let boosted_rewards_payment = EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards); - let merged_farm_token = self.merge_farm_tokens::>(); + let merged_farm_token = self.merge_and_update_farm_tokens(orig_caller); + self.send_payment_non_zero(&caller, &merged_farm_token); self.send_payment_non_zero(&caller, &boosted_rewards_payment); (merged_farm_token, boosted_rewards_payment).into() } + fn merge_and_update_farm_tokens(&self, orig_caller: ManagedAddress) -> EsdtTokenPayment { + let mut output_attributes = self.merge_and_return_attributes::>(&orig_caller); + output_attributes.original_owner = orig_caller; + + let new_token_amount = output_attributes.get_total_supply(); + self.farm_token() + .nft_create(new_token_amount, &output_attributes) + } + #[endpoint(claimBoostedRewards)] fn claim_boosted_rewards( &self, @@ -210,18 +221,28 @@ pub trait Farm: 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, + self.allow_external_claim(user).get(), "Cannot claim rewards for this address" ); } + require!( + !self.user_total_farm_position(user).is_empty(), + "User total farm position is empty!" + ); + + let mut storage_cache = StorageCache::new(self); + self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); + Wrapper::::generate_aggregated_rewards(self, &mut storage_cache); + let boosted_rewards = self.claim_only_boosted_payment(user); let boosted_rewards_payment = EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards); + self.set_farm_supply_for_current_week(&storage_cache.farm_token_supply); + self.send_payment_non_zero(user, &boosted_rewards_payment); boosted_rewards_payment @@ -245,6 +266,17 @@ pub trait Farm: self.set_per_block_rewards::>(per_block_amount); } + #[endpoint(setBoostedYieldsRewardsPercentage)] + fn set_boosted_yields_rewards_percentage(&self, percentage: u64) { + self.require_caller_has_admin_permissions(); + require!(percentage <= MAX_PERCENT, "Invalid percentage"); + + let mut storage_cache = StorageCache::new(self); + Wrapper::::generate_aggregated_rewards(self, &mut storage_cache); + + self.boosted_yields_rewards_percentage().set(percentage); + } + #[view(calculateRewardsForGivenPosition)] fn calculate_rewards_for_given_position( &self, diff --git a/dex/farm/tests/farm_setup/multi_user_farm_setup.rs b/dex/farm/tests/farm_setup/multi_user_farm_setup.rs index 2e74ab42c..cb12a2a1e 100644 --- a/dex/farm/tests/farm_setup/multi_user_farm_setup.rs +++ b/dex/farm/tests/farm_setup/multi_user_farm_setup.rs @@ -2,7 +2,7 @@ #![allow(deprecated)] use common_structs::FarmTokenAttributes; -use config::{ConfigModule, UserTotalFarmPosition}; +use config::ConfigModule; use multiversx_sc::codec::multi_types::OptionalValue; use multiversx_sc::{ storage::mappers::StorageTokenWrapper, @@ -33,6 +33,7 @@ pub static FARM_TOKEN_ID: &[u8] = b"FARM-123456"; pub const DIV_SAFETY: u64 = 1_000_000_000_000; pub const PER_BLOCK_REWARD_AMOUNT: u64 = 1_000; pub const FARMING_TOKEN_BALANCE: u64 = 200_000_000; +pub const MAX_PERCENTAGE: u64 = 10_000; // 100% pub const BOOSTED_YIELDS_PERCENTAGE: u64 = 2_500; // 25% pub const MAX_REWARDS_FACTOR: u64 = 10; pub const USER_REWARDS_ENERGY_CONST: u64 = 3; @@ -48,6 +49,11 @@ pub struct RawFarmTokenAttributes { pub original_owner_bytes: [u8; 32], } +pub struct NonceAmountPair { + pub nonce: u64, + pub amount: u64, +} + pub struct MultiUserFarmSetup where FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, @@ -310,28 +316,18 @@ where result } - pub fn merge_farm_tokens( - &mut self, - user: &Address, - first_token_nonce: u64, - first_token_amount: u64, - second_token_nonce: u64, - second_token_amount: u64, - ) { + pub fn merge_farm_tokens(&mut self, user: &Address, farm_tokens: Vec) { self.last_farm_token_nonce += 1; - let expected_farm_token_nonce = self.last_farm_token_nonce; - let expected_farm_token_amount = first_token_amount + second_token_amount; + let mut expected_farm_token_amount = 0; let mut payments = Vec::new(); - payments.push(TxTokenTransfer { - token_identifier: FARM_TOKEN_ID.to_vec(), - nonce: first_token_nonce, - value: rust_biguint!(first_token_amount), - }); - payments.push(TxTokenTransfer { - token_identifier: FARM_TOKEN_ID.to_vec(), - nonce: second_token_nonce, - value: rust_biguint!(second_token_amount), - }); + for farm_token in farm_tokens { + expected_farm_token_amount += farm_token.amount; + payments.push(TxTokenTransfer { + token_identifier: FARM_TOKEN_ID.to_vec(), + nonce: farm_token.nonce, + value: rust_biguint!(farm_token.amount), + }); + } self.b_mock .execute_esdt_multi_transfer(user, &self.farm_wrapper, &payments, |sc| { @@ -342,7 +338,7 @@ where out_farm_token.token_identifier, managed_token_id!(FARM_TOKEN_ID) ); - assert_eq!(out_farm_token.token_nonce, expected_farm_token_nonce); + assert_eq!(out_farm_token.token_nonce, self.last_farm_token_nonce); assert_eq!( out_farm_token.amount, managed_biguint!(expected_farm_token_amount) @@ -451,6 +447,54 @@ where result } + pub fn claim_rewards_with_multiple_payments( + &mut self, + user: &Address, + farm_token_payments: Vec, + ) -> u64 { + self.last_farm_token_nonce += 1; + + let mut expected_farm_token_amount = 0; + let mut payments = vec![]; + + for farm_token_payment in farm_token_payments { + expected_farm_token_amount += farm_token_payment.amount; + payments.push(TxTokenTransfer { + token_identifier: FARM_TOKEN_ID.to_vec(), + nonce: farm_token_payment.nonce, + value: rust_biguint!(farm_token_payment.amount), + }); + } + + let expected_farm_token_nonce = self.last_farm_token_nonce; + let mut result = 0; + self.b_mock + .execute_esdt_multi_transfer(user, &self.farm_wrapper, &payments, |sc| { + let (out_farm_token, out_reward_token) = + sc.claim_rewards_endpoint(OptionalValue::None).into_tuple(); + assert_eq!( + out_farm_token.token_identifier, + managed_token_id!(FARM_TOKEN_ID) + ); + assert_eq!(out_farm_token.token_nonce, expected_farm_token_nonce); + assert_eq!( + out_farm_token.amount, + managed_biguint!(expected_farm_token_amount) + ); + + assert_eq!( + out_reward_token.token_identifier, + managed_token_id!(REWARD_TOKEN_ID) + ); + assert_eq!(out_reward_token.token_nonce, 0); + + result = out_reward_token.amount.to_u64().unwrap(); + }) + .assert_ok(); + + result + } + pub fn claim_boosted_rewards_for_user(&mut self, owner: &Address, broker: &Address) -> u64 { self.last_farm_token_nonce += 1; @@ -566,12 +610,8 @@ where 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; - }, - ); + sc.allow_external_claim(&managed_address!(user)) + .set(allow_external_claim); }) .assert_ok(); } @@ -667,12 +707,8 @@ where 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); + .set(managed_biguint!(new_farm_position)); }) .assert_ok(); } @@ -685,10 +721,95 @@ where 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 + user_total_farm_position_mapper.get() ); } }) .assert_ok(); } + + // With the current checks, works only on full position sent (amount/nonce) + pub fn send_farm_position( + &mut self, + sender: &Address, + receiver: &Address, + nonce: u64, + amount: u64, + attr_reward_per_share: u64, + attr_entering_epoch: u64, + ) { + self.b_mock.check_nft_balance( + sender, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(amount), + Some(&FarmTokenAttributes:: { + reward_per_share: managed_biguint!(attr_reward_per_share), + entering_epoch: attr_entering_epoch, + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(amount), + original_owner: managed_address!(&sender), + }), + ); + + self.b_mock + .check_nft_balance::>( + receiver, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(0), + None, + ); + + self.b_mock.set_nft_balance( + sender, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(0), + &FarmTokenAttributes:: { + reward_per_share: managed_biguint!(attr_reward_per_share), + entering_epoch: attr_entering_epoch, + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(amount), + original_owner: managed_address!(&sender), + }, + ); + + self.b_mock.set_nft_balance( + receiver, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(amount), + &FarmTokenAttributes:: { + reward_per_share: managed_biguint!(attr_reward_per_share), + entering_epoch: attr_entering_epoch, + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(amount), + original_owner: managed_address!(&sender), + }, + ); + + self.b_mock + .check_nft_balance::>( + sender, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(0), + None, + ); + + self.b_mock.check_nft_balance( + receiver, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(amount), + Some(&FarmTokenAttributes:: { + reward_per_share: managed_biguint!(attr_reward_per_share), + entering_epoch: attr_entering_epoch, + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(amount), + original_owner: managed_address!(&sender), + }), + ); + } } diff --git a/dex/farm/tests/total_farm_position_test.rs b/dex/farm/tests/total_farm_position_test.rs index 26756ebaa..b7ca1be7b 100644 --- a/dex/farm/tests/total_farm_position_test.rs +++ b/dex/farm/tests/total_farm_position_test.rs @@ -4,10 +4,17 @@ mod farm_setup; use common_structs::FarmTokenAttributes; use config::ConfigModule; -use farm_setup::multi_user_farm_setup::{MultiUserFarmSetup, BOOSTED_YIELDS_PERCENTAGE}; -use multiversx_sc_scenario::{managed_address, managed_biguint, rust_biguint, DebugApi}; - -use crate::farm_setup::multi_user_farm_setup::{FARM_TOKEN_ID, REWARD_TOKEN_ID}; +use farm_setup::multi_user_farm_setup::{ + MultiUserFarmSetup, NonceAmountPair, BOOSTED_YIELDS_PERCENTAGE, MAX_PERCENTAGE, + PER_BLOCK_REWARD_AMOUNT, +}; +use multiversx_sc::types::EsdtLocalRole; +use multiversx_sc_scenario::{ + managed_address, managed_biguint, managed_token_id, rust_biguint, DebugApi, +}; +use sc_whitelist_module::SCWhitelistModule; + +use crate::farm_setup::multi_user_farm_setup::{FARMING_TOKEN_ID, FARM_TOKEN_ID, REWARD_TOKEN_ID}; #[test] fn total_farm_position_claim_test() { @@ -480,6 +487,189 @@ fn farm_total_position_exit_migration_test() { ); } +#[test] +fn farm_total_position_on_claim_migration_test() { + DebugApi::dummy(); + let mut farm_setup = MultiUserFarmSetup::new( + farm::contract_obj, + energy_factory_mock::contract_obj, + energy_update::contract_obj, + ); + + farm_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + farm_setup.set_boosted_yields_factors(); + farm_setup.b_mock.set_block_epoch(2); + + // first user enter farm + let farm_in_amount = 50_000_000; + let first_user = farm_setup.first_user.clone(); + farm_setup.enter_farm(&first_user, farm_in_amount); + + // Remove current farm position from storage + farm_setup.set_user_total_farm_position(&first_user, 0); + farm_setup.check_user_total_farm_position(&first_user, 0); + + // User enters farm again + farm_setup.enter_farm(&first_user, farm_in_amount); + farm_setup.check_user_total_farm_position(&first_user, farm_in_amount); + + // Set farm position migration nonce + farm_setup + .b_mock + .execute_tx( + &farm_setup.owner, + &farm_setup.farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.farm_position_migration_nonce().set(2); + }, + ) + .assert_ok(); + + farm_setup.check_farm_token_supply(farm_in_amount * 2); + + // claim rewards with both positions + let first_payment_amount = farm_in_amount / 2; + let second_payment_amount = farm_in_amount / 4 * 3; + let total_farm_amount = farm_in_amount * 2; + let total_farm_position = farm_in_amount + first_payment_amount; // only the first is migrated by being an old position + let total_claim_payment = first_payment_amount + second_payment_amount; + + let payments = vec![ + NonceAmountPair { + nonce: 1, + amount: first_payment_amount, + }, + NonceAmountPair { + nonce: 2, + amount: second_payment_amount, + }, + ]; + + let block_nonce = 10; + farm_setup.b_mock.set_block_nonce(block_nonce); + + farm_setup.check_user_total_farm_position(&first_user, farm_in_amount); + let _ = farm_setup.claim_rewards_with_multiple_payments(&first_user, payments); + farm_setup.check_user_total_farm_position(&first_user, total_farm_position); + + farm_setup + .b_mock + .check_nft_balance::>( + &first_user, + FARM_TOKEN_ID, + 3, + &rust_biguint!(total_claim_payment), + None, + ); + + // User receives rewards only for the new position + let expected_user_rewards = block_nonce + * PER_BLOCK_REWARD_AMOUNT + * (MAX_PERCENTAGE - BOOSTED_YIELDS_PERCENTAGE) + * first_payment_amount + / total_farm_amount + / MAX_PERCENTAGE; + farm_setup.b_mock.check_esdt_balance( + &first_user, + REWARD_TOKEN_ID, + &rust_biguint!(expected_user_rewards), + ); +} + +#[test] +fn farm_total_position_on_merge_migration_test() { + DebugApi::dummy(); + let mut farm_setup = MultiUserFarmSetup::new( + farm::contract_obj, + energy_factory_mock::contract_obj, + energy_update::contract_obj, + ); + + farm_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + farm_setup.set_boosted_yields_factors(); + farm_setup.b_mock.set_block_epoch(2); + + // user has 2 old farm position + let farm_in_amount = 25_000_000; + let first_user = farm_setup.first_user.clone(); + farm_setup.enter_farm(&first_user, farm_in_amount); + farm_setup.enter_farm(&first_user, farm_in_amount); + + // Remove current farm position from storage + farm_setup.set_user_total_farm_position(&first_user, 0); + farm_setup.check_user_total_farm_position(&first_user, 0); + + // User enters farm again, with 2 new positions + farm_setup.enter_farm(&first_user, farm_in_amount); + farm_setup.enter_farm(&first_user, farm_in_amount); + farm_setup.check_user_total_farm_position(&first_user, farm_in_amount * 2); + + // Set farm position migration nonce + farm_setup + .b_mock + .execute_tx( + &farm_setup.owner, + &farm_setup.farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.farm_position_migration_nonce().set(3); + }, + ) + .assert_ok(); + + let total_farm_tokens = farm_in_amount * 4; + farm_setup.check_farm_token_supply(total_farm_tokens); + + // merge all 4 farm positions + let first_payment_amount = farm_in_amount / 2; + let second_payment_amount = farm_in_amount / 4 * 3; + let third_payment_amount = farm_in_amount / 2; + let forth_payment_amount = farm_in_amount / 4; + let total_payment_amount = + first_payment_amount + second_payment_amount + third_payment_amount + forth_payment_amount; + let total_user_position = farm_in_amount * 2 + first_payment_amount + second_payment_amount; + let payments = vec![ + NonceAmountPair { + nonce: 1, + amount: first_payment_amount, + }, + NonceAmountPair { + nonce: 2, + amount: second_payment_amount, + }, + NonceAmountPair { + nonce: 3, + amount: third_payment_amount, + }, + NonceAmountPair { + nonce: 4, + amount: forth_payment_amount, + }, + ]; + + let block_nonce = 10; + farm_setup.b_mock.set_block_nonce(block_nonce); + + farm_setup.check_user_total_farm_position(&first_user, farm_in_amount * 2); // last 2 positions + farm_setup.merge_farm_tokens(&first_user, payments); + farm_setup.check_user_total_farm_position(&first_user, total_user_position); + + farm_setup + .b_mock + .check_nft_balance::>( + &first_user, + FARM_TOKEN_ID, + 5, + &rust_biguint!(total_payment_amount), + None, + ); + + farm_setup + .b_mock + .check_esdt_balance(&first_user, REWARD_TOKEN_ID, &rust_biguint!(0)); +} + #[test] fn no_boosted_rewards_penalty_for_no_energy_test() { DebugApi::dummy(); @@ -560,3 +750,446 @@ fn no_boosted_rewards_penalty_for_no_energy_test() { &rust_biguint!(first_receveived_reward_amt), ); } + +#[test] +fn total_farm_position_owner_change_test() { + DebugApi::dummy(); + let mut farm_setup = MultiUserFarmSetup::new( + farm::contract_obj, + energy_factory_mock::contract_obj, + energy_update::contract_obj, + ); + + farm_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + farm_setup.set_boosted_yields_factors(); + farm_setup.b_mock.set_block_epoch(2); + + // first user enters farm 6 times + let farm_token_amount = 10_000_000; + let half_token_amount = farm_token_amount / 2; + let first_user = farm_setup.first_user.clone(); + let second_user = farm_setup.second_user.clone(); + let third_user = farm_setup.third_user.clone(); + + farm_setup.set_user_energy(&first_user, 1_000, 2, 1); + farm_setup.enter_farm(&first_user, farm_token_amount); + farm_setup.enter_farm(&first_user, farm_token_amount); + farm_setup.enter_farm(&first_user, farm_token_amount); + farm_setup.enter_farm(&first_user, farm_token_amount); + farm_setup.enter_farm(&first_user, farm_token_amount); + farm_setup.enter_farm(&first_user, farm_token_amount); + + let mut first_user_total_position = farm_token_amount * 6; + let mut second_user_total_position = 0; + farm_setup.check_user_total_farm_position(&first_user, first_user_total_position); + farm_setup.check_user_total_farm_position(&second_user, second_user_total_position); + + assert_eq!(farm_setup.last_farm_token_nonce, 6); + + // First user transfers 5 position to second user + farm_setup.send_farm_position(&first_user, &second_user, 1, farm_token_amount, 0, 2); + farm_setup.send_farm_position(&first_user, &second_user, 2, farm_token_amount, 0, 2); + farm_setup.send_farm_position(&first_user, &second_user, 3, farm_token_amount, 0, 2); + farm_setup.send_farm_position(&first_user, &second_user, 4, farm_token_amount, 0, 2); + farm_setup.send_farm_position(&first_user, &second_user, 5, farm_token_amount, 0, 2); + + // Total farm position unchanged as users only transfered the farm positions + farm_setup.check_user_total_farm_position(&first_user, first_user_total_position); + farm_setup.check_user_total_farm_position(&second_user, second_user_total_position); + + // second user enter farm with LP token + 50% the position from another user + farm_setup.set_user_energy(&second_user, 4_000, 2, 1); + farm_setup.enter_farm_with_additional_payment( + &second_user, + farm_token_amount, + 1, + half_token_amount, + ); + + // 1 half farm position was removed from first user and added to the second user (who entered the farm with a position of his own) + first_user_total_position -= half_token_amount; + second_user_total_position += farm_token_amount + half_token_amount; + farm_setup.check_user_total_farm_position(&first_user, first_user_total_position); + farm_setup.check_user_total_farm_position(&second_user, second_user_total_position); + + // users claim rewards to get their energy registered + let _ = farm_setup.claim_rewards(&first_user, 6, farm_token_amount); + let _ = farm_setup.claim_rewards(&second_user, 7, farm_token_amount); + + // random tx on end of week 1, to cummulate rewards + farm_setup.b_mock.set_block_nonce(10); + farm_setup.b_mock.set_block_epoch(6); + farm_setup.set_user_energy(&first_user, 1_000, 6, 1); + farm_setup.set_user_energy(&second_user, 4_000, 6, 1); + farm_setup.set_user_energy(&third_user, 1, 6, 1); + farm_setup.enter_farm(&third_user, 1); + farm_setup.exit_farm(&third_user, 10, 1); + + // advance 1 week + farm_setup.b_mock.set_block_epoch(10); + farm_setup.set_user_energy(&first_user, 1_000, 10, 1); + farm_setup.set_user_energy(&second_user, 4_000, 10, 1); + + // Second user claims with half a position from the first user + let base_rewards_amount = 535; + let boosted_rewards_amount = 1414; + let mut second_user_reward_balance = base_rewards_amount + boosted_rewards_amount; + + let second_received_reward_amt = farm_setup.claim_rewards(&second_user, 2, half_token_amount); + assert_eq!(second_received_reward_amt, second_user_reward_balance); + + farm_setup.b_mock.check_esdt_balance( + &second_user, + REWARD_TOKEN_ID, + &rust_biguint!(second_user_reward_balance), + ); + farm_setup.b_mock.check_nft_balance( + &second_user, + FARM_TOKEN_ID, + 11, + &rust_biguint!(half_token_amount), + Some(&FarmTokenAttributes:: { + reward_per_share: managed_biguint!(107142857), + entering_epoch: 2, + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(half_token_amount), + original_owner: managed_address!(&second_user), + }), + ); + + // Check users positions after claim + first_user_total_position -= half_token_amount; + second_user_total_position += half_token_amount; + farm_setup.check_user_total_farm_position(&first_user, first_user_total_position); + farm_setup.check_user_total_farm_position(&second_user, second_user_total_position); + + // random tx on end of week 2, to cummulate rewards + farm_setup.b_mock.set_block_nonce(20); + farm_setup.b_mock.set_block_epoch(13); + farm_setup.set_user_energy(&first_user, 1_000, 13, 1); + farm_setup.set_user_energy(&second_user, 4_000, 13, 1); + farm_setup.set_user_energy(&third_user, 1, 13, 1); + farm_setup.enter_farm(&third_user, 1); + farm_setup.exit_farm(&third_user, 12, 1); + + // advance 1 week + farm_setup.b_mock.set_block_epoch(15); + farm_setup.set_user_energy(&first_user, 1_000, 15, 1); + farm_setup.set_user_energy(&second_user, 4_000, 15, 1); + + // Second user exits farm with half of a position previously owned by user 1 + second_user_reward_balance += 1071; // base rewards + second_user_reward_balance += 1487; // boosted rewards + farm_setup.exit_farm(&second_user, 3, half_token_amount); + farm_setup + .b_mock + .check_esdt_balance(&second_user, REWARD_TOKEN_ID, &rust_biguint!(4507)); + + // Check users positions after exit + first_user_total_position -= half_token_amount; + farm_setup.check_user_total_farm_position(&first_user, first_user_total_position); + farm_setup.check_user_total_farm_position(&second_user, second_user_total_position); + + // random tx on end of week 3, to cummulate rewards + farm_setup.b_mock.set_block_nonce(30); + farm_setup.b_mock.set_block_epoch(20); + farm_setup.set_user_energy(&first_user, 1_000, 20, 1); + farm_setup.set_user_energy(&second_user, 4_000, 20, 1); + farm_setup.set_user_energy(&third_user, 1, 20, 1); + farm_setup.enter_farm(&third_user, 1); + farm_setup.exit_farm(&third_user, 13, 1); + + // advance 1 week + farm_setup.b_mock.set_block_epoch(25); + farm_setup.set_user_energy(&first_user, 1_000, 25, 1); + farm_setup.set_user_energy(&second_user, 4_000, 25, 1); + + // First user claims rewards + let first_user_received_reward_amt = + farm_setup.claim_rewards(&first_user, 8, farm_token_amount); + assert_eq!(first_user_received_reward_amt, 6167); + + // Check users positions after first user claim + farm_setup.check_user_total_farm_position(&first_user, first_user_total_position); + farm_setup.check_user_total_farm_position(&second_user, second_user_total_position); + + // Second user merges half from one of his original position with 2 position halves from the first user + let farm_tokens = vec![ + NonceAmountPair { + nonce: 4, + amount: half_token_amount, + }, + NonceAmountPair { + nonce: 5, + amount: half_token_amount, + }, + NonceAmountPair { + nonce: 11, + amount: half_token_amount, + }, + ]; + + farm_setup.b_mock.check_esdt_balance( + &second_user, + REWARD_TOKEN_ID, + &rust_biguint!(second_user_reward_balance), + ); + farm_setup.merge_farm_tokens(&second_user, farm_tokens); + second_user_reward_balance += 1510; // boosted rewards + farm_setup.b_mock.check_esdt_balance( + &second_user, + REWARD_TOKEN_ID, + &rust_biguint!(second_user_reward_balance), + ); + farm_setup.b_mock.check_nft_balance( + &second_user, + FARM_TOKEN_ID, + 15, + &rust_biguint!(half_token_amount * 3), + Some(&FarmTokenAttributes:: { + reward_per_share: managed_biguint!(35714286), + entering_epoch: 2, + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(half_token_amount * 3), + original_owner: managed_address!(&second_user), + }), + ); + + // Check users positions after merge + first_user_total_position -= 2 * half_token_amount; + second_user_total_position += 2 * half_token_amount; + farm_setup.check_user_total_farm_position(&first_user, first_user_total_position); + farm_setup.check_user_total_farm_position(&second_user, second_user_total_position); +} + +#[test] +fn total_farm_position_through_simple_lock_test() { + use multiversx_sc::storage::mappers::StorageTokenWrapper; + use simple_lock::locked_token::LockedTokenModule; + use simple_lock::proxy_farm::ProxyFarmModule; + use simple_lock::proxy_farm::*; + use simple_lock::proxy_lp::{LpProxyTokenAttributes, ProxyLpModule}; + use simple_lock::SimpleLock; + + const LOCKED_TOKEN_ID: &[u8] = b"NOOOO-123456"; + const LOCKED_LP_TOKEN_ID: &[u8] = b"LKLP-123456"; + const FARM_PROXY_TOKEN_ID: &[u8] = b"PROXY-123456"; + const WEGLD_TOKEN_ID: &[u8] = b"WEGLD-abcdef"; + const MEX_TOKEN_ID: &[u8] = b"MEX-abcdef"; // reward token ID + + DebugApi::dummy(); + let mut farm_setup = MultiUserFarmSetup::new( + farm::contract_obj, + energy_factory_mock::contract_obj, + energy_update::contract_obj, + ); + let rust_zero = rust_biguint!(0); + + // setup simple lock SC + let lock_wrapper = farm_setup.b_mock.create_sc_account( + &rust_zero, + Some(&farm_setup.owner), + simple_lock::contract_obj, + "Simple Lock Path", + ); + + let farm_addr = farm_setup.farm_wrapper.address_ref().clone(); + farm_setup + .b_mock + .execute_tx(&farm_setup.owner, &lock_wrapper, &rust_zero, |sc| { + sc.init(); + sc.locked_token() + .set_token_id(managed_token_id!(LOCKED_TOKEN_ID)); + sc.lp_proxy_token() + .set_token_id(managed_token_id!(LOCKED_LP_TOKEN_ID)); + sc.farm_proxy_token() + .set_token_id(managed_token_id!(FARM_PROXY_TOKEN_ID)); + sc.add_farm_to_whitelist( + managed_address!(&farm_addr), + managed_token_id!(FARMING_TOKEN_ID), + FarmType::SimpleFarm, + ); + }) + .assert_ok(); + + // change farming token for farm + whitelist simple lock contract + farm_setup + .b_mock + .execute_tx( + &farm_setup.owner, + &farm_setup.farm_wrapper, + &rust_zero, + |sc| { + sc.farming_token_id() + .set(&managed_token_id!(FARMING_TOKEN_ID)); + sc.add_sc_address_to_whitelist(managed_address!(lock_wrapper.address_ref())); + }, + ) + .assert_ok(); + + farm_setup.b_mock.set_esdt_local_roles( + lock_wrapper.address_ref(), + LOCKED_LP_TOKEN_ID, + &[ + EsdtLocalRole::NftCreate, + EsdtLocalRole::NftAddQuantity, + EsdtLocalRole::NftBurn, + ], + ); + farm_setup.b_mock.set_esdt_local_roles( + lock_wrapper.address_ref(), + FARM_PROXY_TOKEN_ID, + &[ + EsdtLocalRole::NftCreate, + EsdtLocalRole::NftAddQuantity, + EsdtLocalRole::NftBurn, + ], + ); + + // user lock tokens + let user_addr = farm_setup.first_user.clone(); + + let lp_proxy_token_attributes: LpProxyTokenAttributes = LpProxyTokenAttributes { + lp_token_id: managed_token_id!(FARMING_TOKEN_ID), + first_token_id: managed_token_id!(WEGLD_TOKEN_ID), + first_token_locked_nonce: 1, + second_token_id: managed_token_id!(MEX_TOKEN_ID), + second_token_locked_nonce: 2, + }; + + farm_setup.b_mock.set_nft_balance( + &user_addr, + LOCKED_LP_TOKEN_ID, + 1, + &rust_biguint!(1_000_000_000), + &lp_proxy_token_attributes, + ); + + farm_setup.b_mock.set_esdt_balance( + lock_wrapper.address_ref(), + FARMING_TOKEN_ID, + &rust_biguint!(1_000_000_000), + ); + + farm_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + farm_setup.set_boosted_yields_factors(); + farm_setup.b_mock.set_block_epoch(2); + + let temp_user = farm_setup.third_user.clone(); + + farm_setup.check_user_total_farm_position(&user_addr, 0); + + // first user enter farm twice (normal & through simple lock contract) + // enter farm through simple lock contract + let farm_in_amount = 50_000_000; + farm_setup.last_farm_token_nonce += 1; + farm_setup + .b_mock + .execute_esdt_transfer( + &user_addr, + &lock_wrapper, + LOCKED_LP_TOKEN_ID, + 1, + &rust_biguint!(farm_in_amount), + |sc| { + let enter_farm_result = sc.enter_farm_locked_token(FarmType::SimpleFarm); + let (out_farm_token, _reward_token) = enter_farm_result.into_tuple(); + assert_eq!( + out_farm_token.token_identifier, + managed_token_id!(FARM_PROXY_TOKEN_ID) + ); + assert_eq!(out_farm_token.token_nonce, farm_setup.last_farm_token_nonce); + assert_eq!(out_farm_token.amount, managed_biguint!(farm_in_amount)); + }, + ) + .assert_ok(); + + farm_setup.b_mock.check_nft_balance( + &user_addr, + FARM_PROXY_TOKEN_ID, + 1, + &rust_biguint!(farm_in_amount), + Some(&FarmProxyTokenAttributes:: { + farm_type: FarmType::SimpleFarm, + farm_token_id: managed_token_id!(FARM_TOKEN_ID), + farm_token_nonce: 1, + farming_token_id: managed_token_id!(FARMING_TOKEN_ID), + farming_token_locked_nonce: 1, + }), + ); + + farm_setup.check_user_total_farm_position(&user_addr, farm_in_amount); + + // enter farm directly + farm_setup.set_user_energy(&user_addr, 1_000, 2, 1); + farm_setup.enter_farm(&user_addr, farm_in_amount); + + farm_setup.b_mock.check_nft_balance( + &user_addr, + FARM_TOKEN_ID, + farm_setup.last_farm_token_nonce, + &rust_biguint!(farm_in_amount), + Some(&FarmTokenAttributes:: { + reward_per_share: managed_biguint!(0), + compounded_reward: managed_biguint!(0), + entering_epoch: 2, + current_farm_amount: managed_biguint!(farm_in_amount), + original_owner: managed_address!(&user_addr), + }), + ); + + farm_setup.check_user_total_farm_position(&user_addr, farm_in_amount * 2); + farm_setup.check_farm_token_supply(farm_in_amount * 2); + + // users claim rewards to get their energy registered + let _ = farm_setup.claim_rewards(&user_addr, 2, farm_in_amount); + + // advance blocks - 10 blocks - 10 * 1_000 = 10_000 total rewards + // 7_500 base farm, 2_500 boosted yields + farm_setup.b_mock.set_block_nonce(10); + + // random tx on end of week 1, to cummulate rewards + farm_setup.b_mock.set_block_epoch(6); + farm_setup.set_user_energy(&user_addr, 1_000, 6, 1); + farm_setup.set_user_energy(&temp_user, 1, 6, 1); + farm_setup.enter_farm(&temp_user, 1); + farm_setup.exit_farm(&temp_user, 4, 1); + + // advance 1 week + farm_setup.b_mock.set_block_epoch(10); + farm_setup.set_user_energy(&user_addr, 1_000, 10, 1); + + let total_farm_tokens = farm_in_amount * 2; + + // first user claim with half total position + let first_base_farm_amt = farm_in_amount * 7_500 / total_farm_tokens; + + // Boosted yields rewards formula + // total_boosted_rewards * (energy_const * user_energy / total_energy + farm_const * user_farm / total_farm) / (energy_const + farm_const) + // (total_boosted_rewards * energy_const * user_energy / total_energy + total_boosted_rewards * farm_const * user_farm / total_farm) / (energy_const + farm_const) + // (2_500 * 3 * 1_000 / 1_000 + 2_500 * 2 * 100_000_000 / 100_000_000) / (3 + 2) + // (7_500 + 2_500) / (5) = 2_500 + let first_boosted_amt = 2_500; // 1000 energy & 100_000_000 farm tokens + let first_total_rewards = first_base_farm_amt + first_boosted_amt; + + let first_received_reward_amt = farm_setup.claim_rewards(&user_addr, 3, farm_in_amount); + + // Should be equal to half base generated rewards + full boosted generated rewards + assert_eq!(first_received_reward_amt, first_total_rewards); + + farm_setup + .b_mock + .check_nft_balance::>( + &user_addr, + FARM_TOKEN_ID, + 5, + &rust_biguint!(farm_in_amount), + None, + ); + + farm_setup.b_mock.check_esdt_balance( + &user_addr, + REWARD_TOKEN_ID, + &rust_biguint!(first_received_reward_amt), + ); +} diff --git a/dex/farm/wasm/Cargo.lock b/dex/farm/wasm/Cargo.lock index 2308d9073..c3dea8cdc 100644 --- a/dex/farm/wasm/Cargo.lock +++ b/dex/farm/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common-types" @@ -76,9 +76,9 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "endian-type" @@ -285,32 +285,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -320,9 +322,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -333,18 +335,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -360,9 +362,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -402,18 +404,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -462,15 +464,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -500,6 +502,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" diff --git a/dex/farm/wasm/Cargo.toml b/dex/farm/wasm/Cargo.toml index 26ce2670b..4c5b25ae8 100644 --- a/dex/farm/wasm/Cargo.toml +++ b/dex/farm/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.farm] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [workspace] members = ["."] diff --git a/dex/farm/wasm/src/lib.rs b/dex/farm/wasm/src/lib.rs index de7b89ee5..525d76239 100644 --- a/dex/farm/wasm/src/lib.rs +++ b/dex/farm/wasm/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 65 +// Upgrade: 1 +// Endpoints: 63 // Async Callback: 1 -// Total number of exported functions: 67 +// Total number of exported functions: 66 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -30,17 +29,17 @@ multiversx_sc_wasm_adapter::endpoints! { startProduceRewards => start_produce_rewards_endpoint endProduceRewards => end_produce_rewards_endpoint setPerBlockRewardAmount => set_per_block_rewards_endpoint + setBoostedYieldsRewardsPercentage => set_boosted_yields_rewards_percentage 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 + getAllowExternalClaim => allow_external_claim getFarmPositionMigrationNonce => farm_position_migration_nonce registerFarmToken => register_farm_token getFarmTokenId => farm_token @@ -64,7 +63,6 @@ multiversx_sc_wasm_adapter::endpoints! { 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 diff --git a/dex/fuzz/Cargo.toml b/dex/fuzz/Cargo.toml index 57800c37f..7278d4708 100644 --- a/dex/fuzz/Cargo.toml +++ b/dex/fuzz/Cargo.toml @@ -12,11 +12,11 @@ num-bigint = "0.4.2" rand = "0.8.4" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" [dependencies.pausable] path = "../../common/modules/pausable" @@ -36,9 +36,6 @@ path = "../../common/common_structs" [dependencies.farm-staking] path = "../../farm-staking/farm-staking" -[dependencies.factory] -path = "../../locked-asset/factory" - [dependencies.pair-mock] path = "../pair-mock" diff --git a/dex/fuzz/src/fuzz_data.rs b/dex/fuzz/src/fuzz_data.rs index 14de4e7c3..320daf5d6 100644 --- a/dex/fuzz/src/fuzz_data.rs +++ b/dex/fuzz/src/fuzz_data.rs @@ -6,9 +6,6 @@ pub mod fuzz_data_tests { multiversx_sc::derive_imports!(); use ::config::ConfigModule; - use common_structs::UnlockMilestone; - use factory::locked_asset::LockedAssetModule; - use factory::*; use farm::exit_penalty::ExitPenaltyModule; use farm::*; use farm_token::FarmTokenModule; @@ -34,7 +31,6 @@ pub mod fuzz_data_tests { pub const FARM_WASM_PATH: &str = "farm/output/farm.wasm"; pub const PAIR_WASM_PATH: &str = "pair/output/pair.wasm"; - pub const FACTORY_WASM_PATH: &str = "factory/output/factory.wasm"; pub const PD_WASM_PATH: &str = "../output/price-discovery.wasm"; pub const WEGLD_TOKEN_ID: &[u8] = b"WEGLD-abcdef"; @@ -45,8 +41,6 @@ pub mod fuzz_data_tests { pub const WEME_FARM_TOKEN_ID: &[u8] = b"WEMEFARM-abcdef"; pub const WEBU_FARM_TOKEN_ID: &[u8] = b"WEBUFARM-abcdef"; pub const MEX_FARM_TOKEN_ID: &[u8] = b"MEXFARM-abcdef"; - pub const LOCKED_MEX_TOKEN_ID: &[u8] = b"LKMEX-abcdef"; - pub const FACTORY_LOCK_NONCE: u64 = 1; pub const MIN_FARMING_EPOCHS: u64 = 2; pub const FARM_PENALTY_PERCENT: u64 = 10; pub const OWNER_EGLD_BALANCE: u64 = 100_000_000; @@ -87,8 +81,6 @@ pub mod fuzz_data_tests { pub exit_farm_prob: u64, pub claim_rewards_prob: u64, pub compound_rewards_prob: u64, - pub factory_lock_asset_prob: u64, - pub factory_unlock_asset_prob: u64, pub price_discovery_deposit_prob: u64, pub price_discovery_withdraw_prob: u64, pub price_discovery_redeem_prob: u64, @@ -101,8 +93,6 @@ pub mod fuzz_data_tests { pub enter_farm_max_value: u64, pub exit_farm_max_value: u64, pub claim_rewards_max_value: u64, - pub factory_lock_asset_max_value: u64, - pub factory_unlock_asset_max_value: u64, pub price_discovery_deposit_max_value: u64, pub price_discovery_withdraw_max_value: u64, pub price_discovery_redeem_max_value: u64, @@ -120,8 +110,6 @@ pub mod fuzz_data_tests { exit_farm_prob: 10, claim_rewards_prob: 15, compound_rewards_prob: 10, - factory_lock_asset_prob: 10, - factory_unlock_asset_prob: 10, price_discovery_deposit_prob: 30, price_discovery_withdraw_prob: 15, price_discovery_redeem_prob: 30, @@ -134,8 +122,6 @@ pub mod fuzz_data_tests { enter_farm_max_value: 100000000u64, exit_farm_max_value: 1000000u64, claim_rewards_max_value: 1000000u64, - factory_lock_asset_max_value: 1000000u64, - factory_unlock_asset_max_value: 100000u64, price_discovery_deposit_max_value: 1000000u64, price_discovery_withdraw_max_value: 1000000u64, price_discovery_redeem_max_value: 1000000u64, @@ -143,38 +129,33 @@ pub mod fuzz_data_tests { } } - pub struct FuzzerData + pub struct FuzzerData where PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, - FactoryObjBuilder: 'static + Copy + Fn() -> factory::ContractObj, PriceDiscObjBuilder: 'static + Copy + Fn() -> price_discovery::ContractObj, { pub rng: StdRng, - pub owner_address: Address, pub fuzz_args: FuzzDexExecutorInitArgs, pub statistics: EventsStatistics, pub blockchain_wrapper: BlockchainStateWrapper, pub users: Vec, pub swap_pairs: Vec>, pub farms: Vec>, - pub factory: FactorySetup, pub price_disc: PriceDiscSetup, } - impl - FuzzerData + impl + FuzzerData where PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, - FactoryObjBuilder: 'static + Copy + Fn() -> factory::ContractObj, PriceDiscObjBuilder: 'static + Copy + Fn() -> price_discovery::ContractObj, { pub fn new( seed: u64, pair_builder: PairObjBuilder, farm_builder: FarmObjBuilder, - factory_builder: FactoryObjBuilder, price_discovery: PriceDiscObjBuilder, ) -> Self { let egld_amount = rust_biguint!(OWNER_EGLD_BALANCE); @@ -226,7 +207,6 @@ pub mod fuzz_data_tests { let user = User { address: user_address, price_discovery_buy, - locked_asset_nonces: Vec::new(), }; users.push(user); @@ -284,27 +264,17 @@ pub mod fuzz_data_tests { let farms = vec![first_farm, second_farm, third_farm]; - let factory = setup_factory( - MEX_TOKEN_ID, - LOCKED_MEX_TOKEN_ID, - &mut blockchain_wrapper, - &owner_addr, - factory_builder, - ); - let price_disc = setup_price_disc(&owner_addr, &mut blockchain_wrapper, price_discovery); FuzzerData { rng, - owner_address: owner_addr, fuzz_args, statistics, blockchain_wrapper, users, swap_pairs, farms, - factory, price_disc, } } @@ -314,7 +284,6 @@ pub mod fuzz_data_tests { pub struct User { pub address: Address, pub price_discovery_buy: bool, - pub locked_asset_nonces: Vec, } #[derive()] @@ -497,100 +466,12 @@ pub mod fuzz_data_tests { } } - #[allow(dead_code)] - pub struct FactorySetup - where - FactoryObjBuilder: 'static + Copy + Fn() -> factory::ContractObj, - { - pub token: String, - pub locked_token: String, - pub factory_wrapper: ContractObjWrapper, FactoryObjBuilder>, - } - - pub fn setup_factory( - token: &[u8], - locked_token: &[u8], - blockchain_wrapper: &mut BlockchainStateWrapper, - owner_addr: &Address, - factory_builder: FactoryObjBuilder, - ) -> FactorySetup - where - FactoryObjBuilder: 'static + Copy + Fn() -> factory::ContractObj, - { - let rust_zero = rust_biguint!(0u64); - - let factory_wrapper = blockchain_wrapper.create_sc_account( - &rust_zero, - Some(owner_addr), - factory_builder, - FACTORY_WASM_PATH, - ); - - blockchain_wrapper - .execute_tx(owner_addr, &factory_wrapper, &rust_biguint!(0), |sc| { - let asset_token_id = managed_token_id!(MEX_TOKEN_ID); - let locked_asset_token_id = managed_token_id!(LOCKED_MEX_TOKEN_ID); - let default_unlock_period = MultiValueEncoded::from(ManagedVec::from(vec![ - UnlockMilestone { - unlock_epoch: 0, - unlock_percent: 25, - }, - UnlockMilestone { - unlock_epoch: 10, - unlock_percent: 25, - }, - UnlockMilestone { - unlock_epoch: 20, - unlock_percent: 25, - }, - UnlockMilestone { - unlock_epoch: 30, - unlock_percent: 25, - }, - ])); - sc.init(asset_token_id, default_unlock_period); - sc.set_init_epoch(FACTORY_LOCK_NONCE); - sc.locked_asset_token().set_token_id(locked_asset_token_id); - }) - .assert_ok(); - - let token_roles = [EsdtLocalRole::Mint, EsdtLocalRole::Burn]; - - blockchain_wrapper.set_esdt_local_roles( - factory_wrapper.address_ref(), - MEX_TOKEN_ID, - &token_roles[..], - ); - - let locked_token_roles = [ - EsdtLocalRole::NftCreate, - EsdtLocalRole::NftAddQuantity, - EsdtLocalRole::NftBurn, - ]; - - blockchain_wrapper.set_esdt_local_roles( - factory_wrapper.address_ref(), - LOCKED_MEX_TOKEN_ID, - &locked_token_roles[..], - ); - - let token_string = String::from_utf8(token.to_vec()).unwrap(); - let locked_token_string = String::from_utf8(locked_token.to_vec()).unwrap(); - - FactorySetup { - token: token_string, - locked_token: locked_token_string, - factory_wrapper, - } - } - pub struct PriceDiscSetup where PriceDiscObjBuilder: 'static + Copy + Fn() -> price_discovery::ContractObj, { pub pd_wrapper: ContractObjWrapper, PriceDiscObjBuilder>, - pub locking_sc_address: Address, } pub fn setup_price_disc( @@ -705,10 +586,7 @@ pub mod fuzz_data_tests { ) .assert_ok(); - PriceDiscSetup { - pd_wrapper, - locking_sc_address: locking_sc_wrapper.address_ref().clone(), - } + PriceDiscSetup { pd_wrapper } } #[derive(Clone, PartialEq)] @@ -739,12 +617,6 @@ pub mod fuzz_data_tests { pub compound_rewards_hits: u64, pub compound_rewards_misses: u64, - pub factory_lock_hits: u64, - pub factory_lock_misses: u64, - - pub factory_unlock_hits: u64, - pub factory_unlock_misses: u64, - pub price_discovery_deposit_hits: u64, pub price_discovery_deposit_misses: u64, @@ -776,10 +648,6 @@ pub mod fuzz_data_tests { claim_rewards_with_rewards: 0, compound_rewards_hits: 0, compound_rewards_misses: 0, - factory_lock_hits: 0, - factory_lock_misses: 0, - factory_unlock_hits: 0, - factory_unlock_misses: 0, price_discovery_deposit_hits: 0, price_discovery_deposit_misses: 0, price_discovery_withdraw_hits: 0, diff --git a/dex/fuzz/src/fuzz_factory.rs b/dex/fuzz/src/fuzz_factory.rs deleted file mode 100644 index 4286c72c7..000000000 --- a/dex/fuzz/src/fuzz_factory.rs +++ /dev/null @@ -1,203 +0,0 @@ -#[cfg(test)] -pub mod fuzz_factory_test { - #![allow(deprecated)] - - multiversx_sc::imports!(); - multiversx_sc::derive_imports!(); - - use multiversx_sc_scenario::whitebox_legacy::TxTokenTransfer; - use multiversx_sc_scenario::{rust_biguint, DebugApi}; - - use crate::fuzz_data::fuzz_data_tests::*; - - use factory::*; - - use rand::prelude::*; - - pub fn lock_assets( - fuzzer_data: &mut FuzzerData< - PairObjBuilder, - FarmObjBuilder, - FactoryObjBuilder, - PriceDiscObjBuilder, - >, - ) where - PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, - FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, - FactoryObjBuilder: 'static + Copy + Fn() -> factory::ContractObj, - PriceDiscObjBuilder: 'static + Copy + Fn() -> price_discovery::ContractObj, - { - let caller_index = fuzzer_data.rng.gen_range(0..fuzzer_data.users.len()); - let caller = &mut fuzzer_data.users[caller_index]; - let factory_setup = &mut fuzzer_data.factory; - - let token_id = factory_setup.token.as_bytes(); - - let seed = fuzzer_data - .rng - .gen_range(0..fuzzer_data.fuzz_args.factory_lock_asset_max_value) - + 1; - - let amount_to_lock = rust_biguint!(seed); - - let token_before = - fuzzer_data - .blockchain_wrapper - .get_esdt_balance(&caller.address, token_id, 0); - - if token_before < amount_to_lock { - println!("Factory lock error: Not enough tokens"); - fuzzer_data.statistics.factory_lock_misses += 1; - - return; - } - - let payments = vec![TxTokenTransfer { - token_identifier: token_id.to_vec(), - nonce: 0, - value: amount_to_lock, - }]; - - let mut locked_asset_nonce = FACTORY_LOCK_NONCE; - let tx_result = fuzzer_data.blockchain_wrapper.execute_esdt_multi_transfer( - &caller.address, - &factory_setup.factory_wrapper, - &payments, - |sc| { - let locked_assets = sc.lock_assets(); - - locked_asset_nonce = locked_assets.token_nonce; - }, - ); - - if !caller.locked_asset_nonces.contains(&locked_asset_nonce) { - caller.locked_asset_nonces.push(locked_asset_nonce); - } - - let locked_amount = rust_biguint!(seed); - - let token_after = - fuzzer_data - .blockchain_wrapper - .get_esdt_balance(&caller.address, token_id, 0); - - let tx_result_string = tx_result.result_message; - - if !tx_result_string.trim().is_empty() { - println!("Factory lock error: {}", tx_result_string); - fuzzer_data.statistics.factory_lock_misses += 1; - } else if token_after != token_before - &locked_amount { - println!("Factory lock error: unlocked token final balance is incorrect"); - fuzzer_data.statistics.factory_lock_misses += 1; - } else { - fuzzer_data.statistics.factory_lock_hits += 1; - } - } - - pub fn unlock_assets( - fuzzer_data: &mut FuzzerData< - PairObjBuilder, - FarmObjBuilder, - FactoryObjBuilder, - PriceDiscObjBuilder, - >, - ) where - PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, - FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, - FactoryObjBuilder: 'static + Copy + Fn() -> factory::ContractObj, - PriceDiscObjBuilder: 'static + Copy + Fn() -> price_discovery::ContractObj, - { - let rust_zero = rust_biguint!(0u64); - - let caller_index = fuzzer_data.rng.gen_range(0..fuzzer_data.users.len()); - let caller = &mut fuzzer_data.users[caller_index]; - let factory_setup = &mut fuzzer_data.factory; - - let token_id = factory_setup.token.as_bytes(); - let locked_token_id = factory_setup.locked_token.as_bytes(); - - // Choose a random locked token nonce to try to unlock - let chosen_nonce = caller.locked_asset_nonces.choose(&mut fuzzer_data.rng); - let locked_token_nonce = match chosen_nonce { - Some(chosen_nonce) => *chosen_nonce, - None => { - println!("Factory unlock error: Caller does not have any locked tokens"); - fuzzer_data.statistics.factory_unlock_misses += 1; - - return; - } - }; - - let seed = fuzzer_data - .rng - .gen_range(0..fuzzer_data.fuzz_args.factory_unlock_asset_max_value) - + 1; - - let mut amount_to_unlock = rust_biguint!(seed); - - let token_before = - fuzzer_data - .blockchain_wrapper - .get_esdt_balance(&caller.address, token_id, 0); - - let locked_token_before = fuzzer_data.blockchain_wrapper.get_esdt_balance( - &caller.address, - locked_token_id, - locked_token_nonce, - ); - - if locked_token_before < amount_to_unlock { - if locked_token_before > rust_zero { - amount_to_unlock = locked_token_before.clone(); - } else { - println!("Factory unlock error: Not enough tokens"); - fuzzer_data.statistics.factory_unlock_misses += 1; - - return; - } - } - - let payments = vec![TxTokenTransfer { - token_identifier: locked_token_id.to_vec(), - nonce: locked_token_nonce, - value: amount_to_unlock, - }]; - - let tx_result = fuzzer_data.blockchain_wrapper.execute_esdt_multi_transfer( - &caller.address, - &factory_setup.factory_wrapper, - &payments, - |sc| { - sc.unlock_assets(); - }, - ); - - let token_after = - fuzzer_data - .blockchain_wrapper - .get_esdt_balance(&caller.address, token_id, 0); - - let locked_token_after = fuzzer_data.blockchain_wrapper.get_esdt_balance( - &caller.address, - locked_token_id, - locked_token_nonce, - ); - - let unlocked_amount = rust_biguint!(seed); - - let tx_result_string = tx_result.result_message; - - if !tx_result_string.trim().is_empty() { - println!("Factory unlock error: {}", tx_result_string); - fuzzer_data.statistics.factory_unlock_misses += 1; - } else if token_after != token_before + &unlocked_amount { - println!("Factory unlock error: final balance is incorrect"); - fuzzer_data.statistics.factory_unlock_misses += 1; - } else if locked_token_after != locked_token_before - &unlocked_amount { - println!("Factory unlock error: locked token final balance is incorrect"); - fuzzer_data.statistics.factory_unlock_misses += 1; - } else { - fuzzer_data.statistics.factory_unlock_hits += 1; - } - } -} diff --git a/dex/fuzz/src/fuzz_farm.rs b/dex/fuzz/src/fuzz_farm.rs index c30e94442..bf1d32618 100644 --- a/dex/fuzz/src/fuzz_farm.rs +++ b/dex/fuzz/src/fuzz_farm.rs @@ -15,17 +15,11 @@ pub mod fuzz_farm_test { use rand::prelude::*; - pub fn enter_farm( - fuzzer_data: &mut FuzzerData< - PairObjBuilder, - FarmObjBuilder, - FactoryObjBuilder, - PriceDiscObjBuilder, - >, + pub fn enter_farm( + fuzzer_data: &mut FuzzerData, ) where PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, - FactoryObjBuilder: 'static + Copy + Fn() -> factory::ContractObj, PriceDiscObjBuilder: 'static + Copy + Fn() -> price_discovery::ContractObj, { let rust_zero = rust_biguint!(0u64); @@ -118,17 +112,11 @@ pub mod fuzz_farm_test { } } - pub fn exit_farm( - fuzzer_data: &mut FuzzerData< - PairObjBuilder, - FarmObjBuilder, - FactoryObjBuilder, - PriceDiscObjBuilder, - >, + pub fn exit_farm( + fuzzer_data: &mut FuzzerData, ) where PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, - FactoryObjBuilder: 'static + Copy + Fn() -> factory::ContractObj, PriceDiscObjBuilder: 'static + Copy + Fn() -> price_discovery::ContractObj, { let rust_zero = rust_biguint!(0u64); @@ -207,17 +195,11 @@ pub mod fuzz_farm_test { } } - pub fn claim_rewards( - fuzzer_data: &mut FuzzerData< - PairObjBuilder, - FarmObjBuilder, - FactoryObjBuilder, - PriceDiscObjBuilder, - >, + pub fn claim_rewards( + fuzzer_data: &mut FuzzerData, ) where PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, - FactoryObjBuilder: 'static + Copy + Fn() -> factory::ContractObj, PriceDiscObjBuilder: 'static + Copy + Fn() -> price_discovery::ContractObj, { let rust_zero = rust_biguint!(0u64); @@ -310,22 +292,11 @@ pub mod fuzz_farm_test { } } - pub fn compound_rewards< - PairObjBuilder, - FarmObjBuilder, - FactoryObjBuilder, - PriceDiscObjBuilder, - >( - fuzzer_data: &mut FuzzerData< - PairObjBuilder, - FarmObjBuilder, - FactoryObjBuilder, - PriceDiscObjBuilder, - >, + pub fn compound_rewards( + fuzzer_data: &mut FuzzerData, ) where PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, - FactoryObjBuilder: 'static + Copy + Fn() -> factory::ContractObj, PriceDiscObjBuilder: 'static + Copy + Fn() -> price_discovery::ContractObj, { let rust_zero = rust_biguint!(0u64); diff --git a/dex/fuzz/src/fuzz_pair.rs b/dex/fuzz/src/fuzz_pair.rs index cd22614cb..e23babcf1 100644 --- a/dex/fuzz/src/fuzz_pair.rs +++ b/dex/fuzz/src/fuzz_pair.rs @@ -16,17 +16,11 @@ pub mod fuzz_pair_test { add_liq::AddLiquidityModule, remove_liq::RemoveLiquidityModule, swap::SwapModule, }; - pub fn add_liquidity( - fuzzer_data: &mut FuzzerData< - PairObjBuilder, - FarmObjBuilder, - FactoryObjBuilder, - PriceDiscObjBuilder, - >, + pub fn add_liquidity( + fuzzer_data: &mut FuzzerData, ) where PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, - FactoryObjBuilder: 'static + Copy + Fn() -> factory::ContractObj, PriceDiscObjBuilder: 'static + Copy + Fn() -> price_discovery::ContractObj, { let pair_index = fuzzer_data.rng.gen_range(0..fuzzer_data.swap_pairs.len()); @@ -125,22 +119,11 @@ pub mod fuzz_pair_test { } } - pub fn remove_liquidity< - PairObjBuilder, - FarmObjBuilder, - FactoryObjBuilder, - PriceDiscObjBuilder, - >( - fuzzer_data: &mut FuzzerData< - PairObjBuilder, - FarmObjBuilder, - FactoryObjBuilder, - PriceDiscObjBuilder, - >, + pub fn remove_liquidity( + fuzzer_data: &mut FuzzerData, ) where PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, - FactoryObjBuilder: 'static + Copy + Fn() -> factory::ContractObj, PriceDiscObjBuilder: 'static + Copy + Fn() -> price_discovery::ContractObj, { let pair_index = fuzzer_data.rng.gen_range(0..fuzzer_data.swap_pairs.len()); @@ -229,17 +212,11 @@ pub mod fuzz_pair_test { } } - pub fn swap_pair( - fuzzer_data: &mut FuzzerData< - PairObjBuilder, - FarmObjBuilder, - FactoryObjBuilder, - PriceDiscObjBuilder, - >, + pub fn swap_pair( + fuzzer_data: &mut FuzzerData, ) where PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, - FactoryObjBuilder: 'static + Copy + Fn() -> factory::ContractObj, PriceDiscObjBuilder: 'static + Copy + Fn() -> price_discovery::ContractObj, { let pair_index = fuzzer_data.rng.gen_range(0..fuzzer_data.swap_pairs.len()); diff --git a/dex/fuzz/src/fuzz_price_discovery.rs b/dex/fuzz/src/fuzz_price_discovery.rs index 2b6cd9909..37c1539d3 100644 --- a/dex/fuzz/src/fuzz_price_discovery.rs +++ b/dex/fuzz/src/fuzz_price_discovery.rs @@ -12,22 +12,11 @@ pub mod fuzz_price_discovery_test { use crate::fuzz_data::fuzz_data_tests::*; use price_discovery::PriceDiscovery; - pub fn price_discovery_deposit< - PairObjBuilder, - FarmObjBuilder, - FactoryObjBuilder, - PriceDiscObjBuilder, - >( - fuzzer_data: &mut FuzzerData< - PairObjBuilder, - FarmObjBuilder, - FactoryObjBuilder, - PriceDiscObjBuilder, - >, + pub fn price_discovery_deposit( + fuzzer_data: &mut FuzzerData, ) where PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, - FactoryObjBuilder: 'static + Copy + Fn() -> factory::ContractObj, PriceDiscObjBuilder: 'static + Copy + Fn() -> price_discovery::ContractObj, { let caller_index = fuzzer_data.rng.gen_range(0..fuzzer_data.users.len()); @@ -148,22 +137,11 @@ pub mod fuzz_price_discovery_test { } } - pub fn price_discovery_withdraw< - PairObjBuilder, - FarmObjBuilder, - FactoryObjBuilder, - PriceDiscObjBuilder, - >( - fuzzer_data: &mut FuzzerData< - PairObjBuilder, - FarmObjBuilder, - FactoryObjBuilder, - PriceDiscObjBuilder, - >, + pub fn price_discovery_withdraw( + fuzzer_data: &mut FuzzerData, ) where PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, - FactoryObjBuilder: 'static + Copy + Fn() -> factory::ContractObj, PriceDiscObjBuilder: 'static + Copy + Fn() -> price_discovery::ContractObj, { let caller_index = fuzzer_data.rng.gen_range(0..fuzzer_data.users.len()); @@ -277,22 +255,11 @@ pub mod fuzz_price_discovery_test { } } - pub fn price_discovery_redeem< - PairObjBuilder, - FarmObjBuilder, - FactoryObjBuilder, - PriceDiscObjBuilder, - >( - fuzzer_data: &mut FuzzerData< - PairObjBuilder, - FarmObjBuilder, - FactoryObjBuilder, - PriceDiscObjBuilder, - >, + pub fn price_discovery_redeem( + fuzzer_data: &mut FuzzerData, ) where PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, - FactoryObjBuilder: 'static + Copy + Fn() -> factory::ContractObj, PriceDiscObjBuilder: 'static + Copy + Fn() -> price_discovery::ContractObj, { let rust_zero = rust_biguint!(0u64); diff --git a/dex/fuzz/src/fuzz_start.rs b/dex/fuzz/src/fuzz_start.rs index 4df24d71a..a22f7a231 100644 --- a/dex/fuzz/src/fuzz_start.rs +++ b/dex/fuzz/src/fuzz_start.rs @@ -8,7 +8,6 @@ mod test { use std::time::SystemTime; use crate::fuzz_data::fuzz_data_tests::*; - use crate::fuzz_factory::fuzz_factory_test::*; use crate::fuzz_farm::fuzz_farm_test::*; use crate::fuzz_pair::fuzz_pair_test::*; use crate::fuzz_price_discovery::fuzz_price_discovery_test::*; @@ -31,7 +30,6 @@ mod test { seed, pair::contract_obj, farm::contract_obj, - factory::contract_obj, price_discovery::contract_obj, ); @@ -45,11 +43,9 @@ mod test { (5, fuzzer_data.fuzz_args.exit_farm_prob), (6, fuzzer_data.fuzz_args.claim_rewards_prob), (7, fuzzer_data.fuzz_args.compound_rewards_prob), - (8, fuzzer_data.fuzz_args.factory_lock_asset_prob), - (9, fuzzer_data.fuzz_args.factory_unlock_asset_prob), - (10, fuzzer_data.fuzz_args.price_discovery_deposit_prob), - (11, fuzzer_data.fuzz_args.price_discovery_withdraw_prob), - (12, fuzzer_data.fuzz_args.price_discovery_redeem_prob), + (8, fuzzer_data.fuzz_args.price_discovery_deposit_prob), + (9, fuzzer_data.fuzz_args.price_discovery_withdraw_prob), + (10, fuzzer_data.fuzz_args.price_discovery_redeem_prob), ]; let mut block_epoch = 1; @@ -97,22 +93,14 @@ mod test { compound_rewards(&mut fuzzer_data); } 8 => { - println!("Event no. {}: Factory lock tokens", (block_nonce)); - lock_assets(&mut fuzzer_data); - } - 9 => { - println!("Event no. {}: Factory unlock tokens", (block_nonce)); - unlock_assets(&mut fuzzer_data); - } - 10 => { println!("Event no. {}: Price discovery deposit", (block_nonce)); price_discovery_deposit(&mut fuzzer_data); } - 11 => { + 9 => { println!("Event no. {}: Price discovery withdraw", (block_nonce)); price_discovery_withdraw(&mut fuzzer_data); } - 12 => { + 10 => { println!("Event no. {}: Price discovery redeem", (block_nonce)); price_discovery_redeem(&mut fuzzer_data); } @@ -123,18 +111,12 @@ mod test { print_statistics(&mut fuzzer_data, seed); } - fn print_statistics( - fuzzer_data: &mut FuzzerData< - PairObjBuilder, - FarmObjBuilder, - FactoryObjBuilder, - PriceDiscObjBuilder, - >, + fn print_statistics( + fuzzer_data: &mut FuzzerData, seed: u64, ) where PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj, - FactoryObjBuilder: 'static + Copy + Fn() -> factory::ContractObj, PriceDiscObjBuilder: 'static + Copy + Fn() -> price_discovery::ContractObj, { println!(); @@ -219,24 +201,6 @@ mod test { fuzzer_data.statistics.compound_rewards_misses ); println!(); - println!( - "factoryLockHits: {}", - fuzzer_data.statistics.factory_lock_hits - ); - println!( - "factoryLockMisses: {}", - fuzzer_data.statistics.factory_lock_misses - ); - println!(); - println!( - "factoryUnlockHits: {}", - fuzzer_data.statistics.factory_unlock_hits - ); - println!( - "factoryUnlockMisses: {}", - fuzzer_data.statistics.factory_unlock_misses - ); - println!(); println!( "priceDiscoveryDepositHits: {}", fuzzer_data.statistics.price_discovery_deposit_hits diff --git a/dex/fuzz/src/lib.rs b/dex/fuzz/src/lib.rs index 7937878cb..06245cbfd 100644 --- a/dex/fuzz/src/lib.rs +++ b/dex/fuzz/src/lib.rs @@ -1,5 +1,4 @@ mod fuzz_data; -mod fuzz_factory; mod fuzz_farm; mod fuzz_pair; mod fuzz_price_discovery; diff --git a/dex/governance/Cargo.toml b/dex/governance/Cargo.toml index 74d9f2849..8cbaf6093 100644 --- a/dex/governance/Cargo.toml +++ b/dex/governance/Cargo.toml @@ -9,14 +9,14 @@ publish = false path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" [dev-dependencies.pair-mock] path = "../pair-mock" diff --git a/dex/governance/meta/Cargo.toml b/dex/governance/meta/Cargo.toml index b692c9007..8102f75d0 100644 --- a/dex/governance/meta/Cargo.toml +++ b/dex/governance/meta/Cargo.toml @@ -10,6 +10,6 @@ authors = ["MultiversX "] [dependencies.governance] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/dex/governance/meta/src/main.rs b/dex/governance/meta/src/main.rs index dd17f3d9d..2acd760bf 100644 --- a/dex/governance/meta/src/main.rs +++ b/dex/governance/meta/src/main.rs @@ -1,3 +1,3 @@ fn main() { - multiversx_sc_meta::cli_main::(); + multiversx_sc_meta_lib::cli_main::(); } diff --git a/dex/governance/src/lib.rs b/dex/governance/src/lib.rs index e9d4147d3..460aabcda 100644 --- a/dex/governance/src/lib.rs +++ b/dex/governance/src/lib.rs @@ -49,7 +49,7 @@ pub trait Governance: self.try_change_price_providers(price_providers); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[payable("*")] diff --git a/dex/governance/wasm/Cargo.lock b/dex/governance/wasm/Cargo.lock index 30ca50940..e6c417480 100644 --- a/dex/governance/wasm/Cargo.lock +++ b/dex/governance/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "endian-type" @@ -55,32 +55,34 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -90,9 +92,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -103,9 +105,9 @@ dependencies = [ [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -121,27 +123,27 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -158,15 +160,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -178,3 +180,9 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" diff --git a/dex/governance/wasm/Cargo.toml b/dex/governance/wasm/Cargo.toml index 905950d0e..249faee52 100644 --- a/dex/governance/wasm/Cargo.toml +++ b/dex/governance/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.governance] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [workspace] members = ["."] diff --git a/dex/governance/wasm/src/lib.rs b/dex/governance/wasm/src/lib.rs index 913c84bba..8e699c12c 100644 --- a/dex/governance/wasm/src/lib.rs +++ b/dex/governance/wasm/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 22 +// Upgrade: 1 +// Endpoints: 21 // Async Callback (empty): 1 // Total number of exported functions: 24 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); diff --git a/dex/pair-mock/Cargo.toml b/dex/pair-mock/Cargo.toml index bc58d1089..30deea9fc 100644 --- a/dex/pair-mock/Cargo.toml +++ b/dex/pair-mock/Cargo.toml @@ -12,7 +12,7 @@ path = "src/pair.rs" path = "../../common/common_errors" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.itertools] @@ -20,4 +20,4 @@ version = "0.10.1" default-features = false [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" diff --git a/dex/pair-mock/meta/Cargo.toml b/dex/pair-mock/meta/Cargo.toml index 673a8fc84..a78d34547 100644 --- a/dex/pair-mock/meta/Cargo.toml +++ b/dex/pair-mock/meta/Cargo.toml @@ -10,6 +10,6 @@ authors = ["MultiversX "] [dependencies.pair-mock] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/dex/pair-mock/meta/src/main.rs b/dex/pair-mock/meta/src/main.rs index e4776f4f6..17e5421af 100644 --- a/dex/pair-mock/meta/src/main.rs +++ b/dex/pair-mock/meta/src/main.rs @@ -1,3 +1,3 @@ fn main() { - multiversx_sc_meta::cli_main::(); + multiversx_sc_meta_lib::cli_main::(); } diff --git a/dex/pair-mock/wasm/Cargo.lock b/dex/pair-mock/wasm/Cargo.lock index 6311e01de..24750e740 100644 --- a/dex/pair-mock/wasm/Cargo.lock +++ b/dex/pair-mock/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common_errors" @@ -29,9 +29,9 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "endian-type" @@ -62,32 +62,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -97,9 +99,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -110,9 +112,9 @@ dependencies = [ [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -128,9 +130,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -154,18 +156,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -182,15 +184,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -202,3 +204,9 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" diff --git a/dex/pair-mock/wasm/Cargo.toml b/dex/pair-mock/wasm/Cargo.toml index 9bf537c94..8978d06da 100644 --- a/dex/pair-mock/wasm/Cargo.toml +++ b/dex/pair-mock/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.pair-mock] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [workspace] members = ["."] diff --git a/dex/pair-mock/wasm/src/lib.rs b/dex/pair-mock/wasm/src/lib.rs index e3462d773..4501da7a5 100644 --- a/dex/pair-mock/wasm/src/lib.rs +++ b/dex/pair-mock/wasm/src/lib.rs @@ -10,8 +10,6 @@ // Total number of exported functions: 4 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); diff --git a/dex/pair/Cargo.toml b/dex/pair/Cargo.toml index 457fb8d8f..7f913c316 100644 --- a/dex/pair/Cargo.toml +++ b/dex/pair/Cargo.toml @@ -37,11 +37,11 @@ version = "0.10.1" default-features = false [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" diff --git a/dex/pair/meta/Cargo.toml b/dex/pair/meta/Cargo.toml index b07218ea1..ee273e2ec 100644 --- a/dex/pair/meta/Cargo.toml +++ b/dex/pair/meta/Cargo.toml @@ -8,6 +8,6 @@ publish = false [dependencies.pair] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/dex/pair/meta/src/main.rs b/dex/pair/meta/src/main.rs index 5adcd78f3..962c4f515 100644 --- a/dex/pair/meta/src/main.rs +++ b/dex/pair/meta/src/main.rs @@ -1,3 +1,3 @@ fn main() { - multiversx_sc_meta::cli_main::(); + multiversx_sc_meta_lib::cli_main::(); } diff --git a/dex/pair/src/lib.rs b/dex/pair/src/lib.rs index 60fd9cc93..76c3c1f5b 100644 --- a/dex/pair/src/lib.rs +++ b/dex/pair/src/lib.rs @@ -12,6 +12,7 @@ pub mod fee; mod liquidity_pool; pub mod locking_wrapper; pub mod pair_actions; +pub mod read_pair_storage; pub mod safe_price; pub mod safe_price_view; @@ -33,6 +34,7 @@ pub trait Pair: + config::ConfigModule + token_send::TokenSendModule + events::EventsModule + + read_pair_storage::ReadPairStorageModule + safe_price::SafePriceModule + safe_price_view::SafePriceViewModule + contexts::output_builder::OutputBuilderModule @@ -99,7 +101,7 @@ pub trait Pair: }; } - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[endpoint(setLpTokenIdentifier)] diff --git a/dex/pair/src/locking_wrapper.rs b/dex/pair/src/locking_wrapper.rs index 14fb910b8..88d056044 100644 --- a/dex/pair/src/locking_wrapper.rs +++ b/dex/pair/src/locking_wrapper.rs @@ -74,7 +74,7 @@ pub trait LockingWrapperModule: current_epoch < locking_deadline_epoch } - fn get_locking_sc_proxy_instance(&self) -> simple_lock::Proxy { + fn get_locking_sc_proxy_instance(&self) -> simple_lock::ProxyTo { let locking_sc_address = self.locking_sc_address().get(); self.locking_sc_proxy_obj(locking_sc_address) } diff --git a/dex/pair/src/pair_actions/add_liq.rs b/dex/pair/src/pair_actions/add_liq.rs index 769e805f4..1e9dbc8d9 100644 --- a/dex/pair/src/pair_actions/add_liq.rs +++ b/dex/pair/src/pair_actions/add_liq.rs @@ -65,6 +65,7 @@ pub trait AddLiquidityModule: self.update_safe_price( &storage_cache.first_token_reserve, &storage_cache.second_token_reserve, + &storage_cache.lp_token_supply, ); let initial_k = self.calculate_k_constant( diff --git a/dex/pair/src/pair_actions/remove_liq.rs b/dex/pair/src/pair_actions/remove_liq.rs index 5ee58d591..1010ac666 100644 --- a/dex/pair/src/pair_actions/remove_liq.rs +++ b/dex/pair/src/pair_actions/remove_liq.rs @@ -56,6 +56,7 @@ pub trait RemoveLiquidityModule: self.update_safe_price( &storage_cache.first_token_reserve, &storage_cache.second_token_reserve, + &storage_cache.lp_token_supply, ); let initial_k = self.calculate_k_constant( @@ -122,6 +123,7 @@ pub trait RemoveLiquidityModule: self.update_safe_price( &storage_cache.first_token_reserve, &storage_cache.second_token_reserve, + &storage_cache.lp_token_supply, ); let mut remove_liq_context = diff --git a/dex/pair/src/pair_actions/swap.rs b/dex/pair/src/pair_actions/swap.rs index f1ec88d94..62cdc01d4 100644 --- a/dex/pair/src/pair_actions/swap.rs +++ b/dex/pair/src/pair_actions/swap.rs @@ -50,6 +50,7 @@ pub trait SwapModule: self.update_safe_price( &storage_cache.first_token_reserve, &storage_cache.second_token_reserve, + &storage_cache.lp_token_supply, ); let initial_k = self.calculate_k_constant( @@ -114,6 +115,7 @@ pub trait SwapModule: self.update_safe_price( &storage_cache.first_token_reserve, &storage_cache.second_token_reserve, + &storage_cache.lp_token_supply, ); let initial_k = self.calculate_k_constant( @@ -185,6 +187,7 @@ pub trait SwapModule: self.update_safe_price( &storage_cache.first_token_reserve, &storage_cache.second_token_reserve, + &storage_cache.lp_token_supply, ); let initial_k = self.calculate_k_constant( diff --git a/dex/pair/src/read_pair_storage.rs b/dex/pair/src/read_pair_storage.rs new file mode 100644 index 000000000..2aeff0566 --- /dev/null +++ b/dex/pair/src/read_pair_storage.rs @@ -0,0 +1,76 @@ +use multiversx_sc::storage::StorageKey; + +use crate::safe_price::PriceObservation; + +multiversx_sc::imports!(); + +pub static LP_TOKEN_SUPPLY_STORAGE_KEY: &[u8] = b"lp_token_supply"; +pub static FIRST_TOKEN_ID_STORAGE_KEY: &[u8] = b"first_token_id"; +pub static SECOND_TOKEN_ID_STORAGE_KEY: &[u8] = b"second_token_id"; +pub static SAFE_PRICE_CURRENT_INDEX_STORAGE_KEY: &[u8] = b"safe_price_current_index"; +pub static PRICE_OBSERVATIONS_STORAGE_KEY: &[u8] = b"price_observations"; +pub static PAIR_RESERVE_BASE_STORAGE_KEY: &[u8] = b"reserve"; + +#[multiversx_sc::module] +pub trait ReadPairStorageModule { + fn get_lp_token_supply_mapper( + &self, + pair_address: ManagedAddress, + ) -> SingleValueMapper { + SingleValueMapper::<_, _, ManagedAddress>::new_from_address( + pair_address, + StorageKey::new(LP_TOKEN_SUPPLY_STORAGE_KEY), + ) + } + + fn get_first_token_id_mapper( + &self, + pair_address: ManagedAddress, + ) -> SingleValueMapper { + SingleValueMapper::<_, _, ManagedAddress>::new_from_address( + pair_address, + StorageKey::new(FIRST_TOKEN_ID_STORAGE_KEY), + ) + } + + fn get_second_token_id_mapper( + &self, + pair_address: ManagedAddress, + ) -> SingleValueMapper { + SingleValueMapper::<_, _, ManagedAddress>::new_from_address( + pair_address, + StorageKey::new(SECOND_TOKEN_ID_STORAGE_KEY), + ) + } + + fn get_safe_price_current_index_mapper( + &self, + pair_address: ManagedAddress, + ) -> SingleValueMapper { + SingleValueMapper::<_, _, ManagedAddress>::new_from_address( + pair_address, + StorageKey::new(SAFE_PRICE_CURRENT_INDEX_STORAGE_KEY), + ) + } + + fn get_price_observation_mapper( + &self, + pair_address: ManagedAddress, + ) -> VecMapper, ManagedAddress> { + VecMapper::<_, _, ManagedAddress>::new_from_address( + pair_address, + StorageKey::new(PRICE_OBSERVATIONS_STORAGE_KEY), + ) + } + + fn get_pair_reserve_mapper( + &self, + pair_address: ManagedAddress, + token_id: &TokenIdentifier, + ) -> SingleValueMapper { + let mut storage_key = StorageKey::new(PAIR_RESERVE_BASE_STORAGE_KEY); + storage_key.append_item(&token_id); + + SingleValueMapper::<_, _, ManagedAddress>::new_from_address(pair_address, storage_key) + } +} diff --git a/dex/pair/src/safe_price.rs b/dex/pair/src/safe_price.rs index 1173cc291..c3823ca44 100644 --- a/dex/pair/src/safe_price.rs +++ b/dex/pair/src/safe_price.rs @@ -1,18 +1,21 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); +use multiversx_sc::codec::{NestedDecodeInput, TopDecodeInput}; + use crate::{amm, config, errors::ERROR_SAFE_PRICE_CURRENT_INDEX}; pub type Round = u64; pub const MAX_OBSERVATIONS: usize = 65_536; // 2^{16} records, to optimise binary search -#[derive(ManagedVecItem, Clone, TopEncode, TopDecode, NestedEncode, NestedDecode, TypeAbi)] +#[derive(ManagedVecItem, Clone, TopEncode, NestedEncode, TypeAbi, Debug)] pub struct PriceObservation { pub first_token_reserve_accumulated: BigUint, pub second_token_reserve_accumulated: BigUint, pub weight_accumulated: u64, pub recording_round: Round, + pub lp_supply_accumulated: BigUint, } impl Default for PriceObservation { @@ -22,7 +25,45 @@ impl Default for PriceObservation { second_token_reserve_accumulated: BigUint::zero(), weight_accumulated: 0, recording_round: 0, + lp_supply_accumulated: BigUint::zero(), + } + } +} + +impl TopDecode for PriceObservation { + fn top_decode(input: I) -> Result + where + I: TopDecodeInput, + { + let mut buffer = input.into_nested_buffer(); + Self::dep_decode(&mut buffer) + } +} + +impl NestedDecode for PriceObservation { + fn dep_decode(input: &mut I) -> Result { + let first_token_reserve_accumulated = BigUint::dep_decode(input)?; + let second_token_reserve_accumulated = BigUint::dep_decode(input)?; + let weight_accumulated = u64::dep_decode(input)?; + let recording_round = u64::dep_decode(input)?; + + let lp_supply_accumulated = if !input.is_depleted() { + BigUint::dep_decode(input)? + } else { + BigUint::zero() + }; + + if !input.is_depleted() { + return Result::Err(DecodeError::INPUT_TOO_LONG); } + + Result::Ok(PriceObservation { + first_token_reserve_accumulated, + second_token_reserve_accumulated, + weight_accumulated, + recording_round, + lp_supply_accumulated, + }) } } @@ -34,8 +75,13 @@ pub trait SafePriceModule: + permissions_module::PermissionsModule + pausable::PausableModule { - fn update_safe_price(&self, first_token_reserve: &BigUint, second_token_reserve: &BigUint) { - if first_token_reserve == &0u64 || second_token_reserve == &0u64 { + fn update_safe_price( + &self, + first_token_reserve: &BigUint, + second_token_reserve: &BigUint, + lp_supply: &BigUint, + ) { + if first_token_reserve == &0u64 || second_token_reserve == &0u64 || lp_supply == &0u64 { return; } @@ -62,6 +108,7 @@ pub trait SafePriceModule: current_round, first_token_reserve, second_token_reserve, + lp_supply, &last_price_observation, ); @@ -79,6 +126,7 @@ pub trait SafePriceModule: new_round: Round, new_first_reserve: &BigUint, new_second_reserve: &BigUint, + new_lp_supply: &BigUint, current_price_observation: &PriceObservation, ) -> PriceObservation { let new_weight = if current_price_observation.recording_round == 0 { @@ -92,6 +140,7 @@ pub trait SafePriceModule: BigUint::from(new_weight) * new_first_reserve; new_price_observation.second_token_reserve_accumulated += BigUint::from(new_weight) * new_second_reserve; + new_price_observation.lp_supply_accumulated += BigUint::from(new_weight) * new_lp_supply; new_price_observation.weight_accumulated += new_weight; new_price_observation.recording_round = new_round; diff --git a/dex/pair/src/safe_price_view.rs b/dex/pair/src/safe_price_view.rs index 4a1042a56..e286bc370 100644 --- a/dex/pair/src/safe_price_view.rs +++ b/dex/pair/src/safe_price_view.rs @@ -6,12 +6,19 @@ use core::cmp::Ordering; use crate::{ amm, config, errors::{ERROR_SAFE_PRICE_OBSERVATION_DOES_NOT_EXIST, ERROR_SAFE_PRICE_SAME_ROUNDS}, + read_pair_storage, safe_price::{self, PriceObservation, Round, MAX_OBSERVATIONS}, }; pub const DEFAULT_SAFE_PRICE_ROUNDS_OFFSET: u64 = 10 * 60; pub const SECONDS_PER_ROUND: u64 = 6; +struct PriceObservationWeightedAmounts { + weighted_first_token_reserve: BigUint, + weighted_second_token_reserve: BigUint, + weighted_lp_supply: BigUint, +} + #[multiversx_sc::module] pub trait SafePriceViewModule: safe_price::SafePriceModule @@ -20,6 +27,7 @@ pub trait SafePriceViewModule: + amm::AmmModule + permissions_module::PermissionsModule + pausable::PausableModule + + read_pair_storage::ReadPairStorageModule { #[label("safe-price-view")] #[view(getLpTokensSafePriceByDefaultOffset)] @@ -83,36 +91,16 @@ pub trait SafePriceViewModule: ) -> MultiValue2 { require!(end_round > start_round, ERROR_PARAMETERS); - let lp_total_supply = self.lp_token_supply().get_from_address(&pair_address); - let first_token_id = self.first_token_id().get_from_address(&pair_address); - let second_token_id = self.second_token_id().get_from_address(&pair_address); - if lp_total_supply == 0 { - return ( - EsdtTokenPayment::new(first_token_id, 0, BigUint::zero()), - EsdtTokenPayment::new(second_token_id, 0, BigUint::zero()), - ) - .into(); - } + let first_token_id = self.get_first_token_id_mapper(pair_address.clone()).get(); + let second_token_id = self.get_second_token_id_mapper(pair_address.clone()).get(); let safe_price_current_index = self - .safe_price_current_index() - .get_from_address(&pair_address); - let price_observations = self.price_observations(); + .get_safe_price_current_index_mapper(pair_address.clone()) + .get(); + let price_observations = self.get_price_observation_mapper(pair_address.clone()); - let last_price_observation = self.get_price_observation( - &pair_address, - &first_token_id, - &second_token_id, - safe_price_current_index, - &price_observations, - end_round, - ); - - let oldest_price_observation = self.get_oldest_price_observation( - &pair_address, - safe_price_current_index, - &price_observations, - ); + let oldest_price_observation = + self.get_oldest_price_observation(safe_price_current_index, &price_observations); require!( start_round >= oldest_price_observation.recording_round, @@ -128,11 +116,35 @@ pub trait SafePriceViewModule: start_round, ); - let (weighted_first_token_reserve, weighted_second_token_reserve) = - self.compute_weighted_reserves(&first_price_observation, &last_price_observation); + let last_price_observation = self.get_price_observation( + &pair_address, + &first_token_id, + &second_token_id, + safe_price_current_index, + &price_observations, + end_round, + ); + + let mut weighted_amounts = + self.compute_weighted_amounts(&first_price_observation, &last_price_observation); + + if weighted_amounts.weighted_lp_supply == 0 { + let current_lp_supply = self.get_lp_token_supply_mapper(pair_address.clone()).get(); + if current_lp_supply == 0 { + return ( + EsdtTokenPayment::new(first_token_id, 0, BigUint::zero()), + EsdtTokenPayment::new(second_token_id, 0, BigUint::zero()), + ) + .into(); + } else { + weighted_amounts.weighted_lp_supply = current_lp_supply; + } + } - let first_token_worth = &liquidity * &weighted_first_token_reserve / &lp_total_supply; - let second_token_worth = &liquidity * &weighted_second_token_reserve / &lp_total_supply; + let first_token_worth = &liquidity * &weighted_amounts.weighted_first_token_reserve + / &weighted_amounts.weighted_lp_supply; + let second_token_worth = &liquidity * &weighted_amounts.weighted_second_token_reserve + / &weighted_amounts.weighted_lp_supply; let first_token_payment = EsdtTokenPayment::new(first_token_id, 0, first_token_worth); let second_token_payment = EsdtTokenPayment::new(second_token_id, 0, second_token_worth); @@ -199,22 +211,19 @@ pub trait SafePriceViewModule: require!(end_round > start_round, ERROR_PARAMETERS); let safe_price_current_index = self - .safe_price_current_index() - .get_from_address(&pair_address); - let price_observations = self.price_observations(); + .get_safe_price_current_index_mapper(pair_address.clone()) + .get(); + let price_observations = self.get_price_observation_mapper(pair_address.clone()); - let oldest_price_observation = self.get_oldest_price_observation( - &pair_address, - safe_price_current_index, - &price_observations, - ); + let oldest_price_observation = + self.get_oldest_price_observation(safe_price_current_index, &price_observations); require!( oldest_price_observation.recording_round <= start_round, ERROR_SAFE_PRICE_OBSERVATION_DOES_NOT_EXIST ); - let first_token_id = self.first_token_id().get_from_address(&pair_address); - let second_token_id = self.second_token_id().get_from_address(&pair_address); + let first_token_id = self.get_first_token_id_mapper(pair_address.clone()).get(); + let second_token_id = self.get_second_token_id_mapper(pair_address.clone()).get(); let first_price_observation = self.get_price_observation( &pair_address, &first_token_id, @@ -248,17 +257,14 @@ pub trait SafePriceViewModule: search_round: Round, ) -> PriceObservation { let safe_price_current_index = self - .safe_price_current_index() - .get_from_address(&pair_address); - let first_token_id = self.first_token_id().get_from_address(&pair_address); - let second_token_id = self.second_token_id().get_from_address(&pair_address); - let price_observations = self.price_observations(); - - let oldest_price_observation = self.get_oldest_price_observation( - &pair_address, - safe_price_current_index, - &price_observations, - ); + .get_safe_price_current_index_mapper(pair_address.clone()) + .get(); + let first_token_id = self.get_first_token_id_mapper(pair_address.clone()).get(); + let second_token_id = self.get_second_token_id_mapper(pair_address.clone()).get(); + let price_observations = self.get_price_observation_mapper(pair_address.clone()); + + let oldest_price_observation = + self.get_oldest_price_observation(safe_price_current_index, &price_observations); require!( oldest_price_observation.recording_round <= search_round, ERROR_SAFE_PRICE_OBSERVATION_DOES_NOT_EXIST @@ -281,19 +287,21 @@ pub trait SafePriceViewModule: first_price_observation: &PriceObservation, last_price_observation: &PriceObservation, ) -> EsdtTokenPayment { - let first_token_id = self.first_token_id().get_from_address(pair_address); - let second_token_id = self.second_token_id().get_from_address(pair_address); + let first_token_id = self.get_first_token_id_mapper(pair_address.clone()).get(); + let second_token_id = self.get_second_token_id_mapper(pair_address.clone()).get(); - let (weighted_first_token_reserve, weighted_second_token_reserve) = - self.compute_weighted_reserves(first_price_observation, last_price_observation); + let weighted_amounts = + self.compute_weighted_amounts(first_price_observation, last_price_observation); if input_payment.token_identifier == first_token_id { - let output_amount = - input_payment.amount * weighted_second_token_reserve / weighted_first_token_reserve; + let output_amount = input_payment.amount + * weighted_amounts.weighted_second_token_reserve + / weighted_amounts.weighted_first_token_reserve; EsdtTokenPayment::new(second_token_id, 0, output_amount) } else if input_payment.token_identifier == second_token_id { - let output_amount = - input_payment.amount * weighted_first_token_reserve / weighted_second_token_reserve; + let output_amount = input_payment.amount + * weighted_amounts.weighted_first_token_reserve + / weighted_amounts.weighted_second_token_reserve; EsdtTokenPayment::new(first_token_id, 0, output_amount) } else { sc_panic!(ERROR_BAD_INPUT_TOKEN); @@ -306,16 +314,16 @@ pub trait SafePriceViewModule: first_token_id: &TokenIdentifier, second_token_id: &TokenIdentifier, current_index: usize, - price_observations: &VecMapper>, + price_observations: &VecMapper, ManagedAddress>, search_round: Round, ) -> PriceObservation { require!( - !price_observations.is_empty_at_address(pair_address), + !price_observations.is_empty(), ERROR_SAFE_PRICE_OBSERVATION_DOES_NOT_EXIST ); // Check if the requested price observation is the last one - let last_observation = price_observations.get_at_address(pair_address, current_index); + let last_observation = price_observations.get(current_index); if last_observation.recording_round == search_round { return last_observation; } @@ -331,21 +339,22 @@ pub trait SafePriceViewModule: ); let first_token_reserve = self - .pair_reserve(first_token_id) - .get_from_address(pair_address); + .get_pair_reserve_mapper(pair_address.clone(), first_token_id) + .get(); let second_token_reserve = self - .pair_reserve(second_token_id) - .get_from_address(pair_address); + .get_pair_reserve_mapper(pair_address.clone(), second_token_id) + .get(); + let current_lp_supply = self.get_lp_token_supply_mapper(pair_address.clone()).get(); return self.compute_new_observation( search_round, &first_token_reserve, &second_token_reserve, + ¤t_lp_supply, &last_observation, ); } let (mut price_observation, last_search_index) = self.price_observation_by_binary_search( - pair_address, current_index, price_observations, search_round, @@ -356,7 +365,6 @@ pub trait SafePriceViewModule: } price_observation = self.price_observation_by_linear_interpolation( - pair_address, price_observations, search_round, last_search_index, @@ -367,45 +375,43 @@ pub trait SafePriceViewModule: fn get_oldest_price_observation( &self, - pair_address: &ManagedAddress, current_index: usize, - price_observations: &VecMapper>, + price_observations: &VecMapper, ManagedAddress>, ) -> PriceObservation { require!( - !price_observations.is_empty_at_address(pair_address), + !price_observations.is_empty(), ERROR_SAFE_PRICE_OBSERVATION_DOES_NOT_EXIST ); // VecMapper index starts at 1 let mut oldest_observation_index = 1; - if price_observations.len_at_address(pair_address) == MAX_OBSERVATIONS { + if price_observations.len() == MAX_OBSERVATIONS { oldest_observation_index = (current_index % MAX_OBSERVATIONS) + 1 } - price_observations.get_at_address(pair_address, oldest_observation_index) + price_observations.get(oldest_observation_index) } fn price_observation_by_binary_search( &self, - pair_address: &ManagedAddress, current_index: usize, - price_observations: &VecMapper>, + price_observations: &VecMapper, ManagedAddress>, search_round: Round, ) -> (PriceObservation, usize) { let mut search_index = 1; let mut left_index; let mut right_index; - let observation_at_index_1 = price_observations.get_at_address(pair_address, search_index); + let observation_at_index_1 = price_observations.get(search_index); if observation_at_index_1.recording_round <= search_round { left_index = search_index; right_index = current_index - 1; } else { left_index = current_index + 1; - right_index = price_observations.len_at_address(pair_address); + right_index = price_observations.len(); } while left_index <= right_index { search_index = (left_index + right_index) / 2; - let price_observation = price_observations.get_at_address(pair_address, search_index); + let price_observation = price_observations.get(search_index); match price_observation.recording_round.cmp(&search_round) { Ordering::Equal => return (price_observation, search_index), Ordering::Less => left_index = search_index + 1, @@ -418,27 +424,24 @@ pub trait SafePriceViewModule: fn price_observation_by_linear_interpolation( &self, - pair_address: &ManagedAddress, - price_observations: &VecMapper>, + price_observations: &VecMapper, ManagedAddress>, search_round: Round, search_index: usize, ) -> PriceObservation { - let last_found_observation = price_observations.get_at_address(pair_address, search_index); + let last_found_observation = price_observations.get(search_index); let left_observation; let right_observation; if last_found_observation.recording_round < search_round { left_observation = last_found_observation; let right_observation_index = (search_index % MAX_OBSERVATIONS) + 1; - right_observation = - price_observations.get_at_address(pair_address, right_observation_index); + right_observation = price_observations.get(right_observation_index); } else { let left_observation_index = if search_index == 1 { MAX_OBSERVATIONS } else { search_index - 1 }; - left_observation = - price_observations.get_at_address(pair_address, left_observation_index); + left_observation = price_observations.get(left_observation_index); right_observation = last_found_observation; }; @@ -455,9 +458,12 @@ pub trait SafePriceViewModule: let second_token_reserve_sum = BigUint::from(left_weight) * left_observation.second_token_reserve_accumulated + BigUint::from(right_weight) * right_observation.second_token_reserve_accumulated; + let lp_supply_sum = BigUint::from(left_weight) * left_observation.lp_supply_accumulated + + BigUint::from(right_weight) * right_observation.lp_supply_accumulated; let first_token_reserve_accumulated = first_token_reserve_sum / weight_sum; let second_token_reserve_accumulated = second_token_reserve_sum / weight_sum; + let lp_supply_accumulated = lp_supply_sum / weight_sum; let weight_accumulated = left_observation.weight_accumulated + search_round - left_observation.recording_round; @@ -466,14 +472,15 @@ pub trait SafePriceViewModule: second_token_reserve_accumulated, weight_accumulated, recording_round: search_round, + lp_supply_accumulated, } } - fn compute_weighted_reserves( + fn compute_weighted_amounts( &self, first_price_observation: &PriceObservation, last_price_observation: &PriceObservation, - ) -> (BigUint, BigUint) { + ) -> PriceObservationWeightedAmounts { let weight_diff = last_price_observation.weight_accumulated - first_price_observation.weight_accumulated; @@ -494,19 +501,29 @@ pub trait SafePriceViewModule: let weighted_first_token_reserve = first_token_reserve_diff / weight_diff; let weighted_second_token_reserve = second_token_reserve_diff / weight_diff; - (weighted_first_token_reserve, weighted_second_token_reserve) + + let weighted_lp_supply = if first_price_observation.lp_supply_accumulated > 0 { + let lp_supply_diff = &last_price_observation.lp_supply_accumulated + - &first_price_observation.lp_supply_accumulated; + lp_supply_diff / weight_diff + } else { + BigUint::zero() + }; + + PriceObservationWeightedAmounts { + weighted_first_token_reserve, + weighted_second_token_reserve, + weighted_lp_supply, + } } fn get_default_offset_rounds(&self, pair_address: &ManagedAddress, end_round: Round) -> u64 { let safe_price_current_index = self - .safe_price_current_index() - .get_from_address(pair_address); - let price_observations = self.price_observations(); - let oldest_price_observation = self.get_oldest_price_observation( - pair_address, - safe_price_current_index, - &price_observations, - ); + .get_safe_price_current_index_mapper(pair_address.clone()) + .get(); + let price_observations = self.get_price_observation_mapper(pair_address.clone()); + let oldest_price_observation = + self.get_oldest_price_observation(safe_price_current_index, &price_observations); let mut default_offset_rounds = end_round - oldest_price_observation.recording_round; if default_offset_rounds > DEFAULT_SAFE_PRICE_ROUNDS_OFFSET { @@ -522,16 +539,13 @@ pub trait SafePriceViewModule: fn update_and_get_tokens_for_given_position_with_safe_price( &self, liquidity: BigUint, - ) -> MultiValue2, EsdtTokenPayment> { + ) -> MultiValue2 { let pair_address = self.blockchain().get_sc_address(); self.get_lp_tokens_safe_price_by_default_offset(pair_address, liquidity) } #[endpoint(updateAndGetSafePrice)] - fn update_and_get_safe_price( - &self, - input: EsdtTokenPayment, - ) -> EsdtTokenPayment { + fn update_and_get_safe_price(&self, input: EsdtTokenPayment) -> EsdtTokenPayment { let pair_address = self.blockchain().get_sc_address(); self.get_safe_price_by_default_offset(pair_address, input) } diff --git a/dex/pair/tests/pair_rs_test.rs b/dex/pair/tests/pair_rs_test.rs index a80469ad0..bd82750d8 100644 --- a/dex/pair/tests/pair_rs_test.rs +++ b/dex/pair/tests/pair_rs_test.rs @@ -4,18 +4,27 @@ mod pair_setup; use fees_collector::{ config::ConfigModule, fees_accumulation::FeesAccumulationModule, FeesCollector, }; +use multiversx_sc::codec::{self, TopDecode}; use multiversx_sc::{ - codec::multi_types::OptionalValue, + api::ManagedTypeApi, + codec::{ + derive::{NestedEncode, TopEncode}, + multi_types::OptionalValue, + top_encode_to_vec_u8, + }, storage::mappers::StorageTokenWrapper, - types::{EsdtLocalRole, MultiValueEncoded}, + types::{BigUint, EsdtLocalRole, MultiValueEncoded}, }; use multiversx_sc_scenario::{ managed_address, managed_biguint, managed_token_id, managed_token_id_wrapped, rust_biguint, whitebox_legacy::TxTokenTransfer, DebugApi, }; use pair::{ - config::MAX_PERCENTAGE, fee::FeeModule, locking_wrapper::LockingWrapperModule, + config::MAX_PERCENTAGE, + fee::FeeModule, + locking_wrapper::LockingWrapperModule, pair_actions::swap::SwapModule, + safe_price::{PriceObservation, Round, SafePriceModule}, }; use pair_setup::*; use simple_lock::{ @@ -24,6 +33,14 @@ use simple_lock::{ SimpleLock, }; +#[derive(TopEncode, NestedEncode, Clone, Debug)] +pub struct OldPriceObservation { + pub first_token_reserve_accumulated: BigUint, + pub second_token_reserve_accumulated: BigUint, + pub weight_accumulated: u64, + pub recording_round: Round, +} + #[test] fn test_pair_setup() { let _ = PairSetup::new(pair::contract_obj); @@ -89,6 +106,214 @@ fn test_perfect_swap_fixed_output() { ); } +#[test] +fn test_safe_price_observation_decoding() { + let mut pair_setup = PairSetup::new(pair::contract_obj); + let _ = pair_setup.b_mock.execute_tx( + &pair_setup.owner_address, + &pair_setup.pair_wrapper, + &rust_biguint!(0), + |sc| { + let old_observation: OldPriceObservation = OldPriceObservation { + first_token_reserve_accumulated: managed_biguint!(1u64), + second_token_reserve_accumulated: managed_biguint!(1u64), + weight_accumulated: 1u64, + recording_round: 1u64, + }; + + let buffer = top_encode_to_vec_u8(&old_observation).unwrap(); + + let mut new_observation = PriceObservation::::top_decode(buffer).unwrap(); + assert_eq!( + new_observation.lp_supply_accumulated, + managed_biguint!(0u64) + ); + + new_observation.lp_supply_accumulated = managed_biguint!(2u64); + sc.price_observations().push(&new_observation.clone()); + let final_observation = sc.price_observations().get(1); + assert_eq!( + new_observation.lp_supply_accumulated, + final_observation.lp_supply_accumulated + ); + }, + ); +} + +#[test] +fn test_safe_price_migration() { + let mut pair_setup = PairSetup::new(pair::contract_obj); + let pair_address = pair_setup.pair_wrapper.address_ref().clone(); + let starting_round = 1000; + let payment_amount = 1000; + let mut expected_amount = 996; + + let weight = 10; + let mut block_round = starting_round + weight; + pair_setup.b_mock.set_block_round(block_round); + + let lp_increase = 1_000_000; + let min_lp_amount = 1_000; + let mut lp_amount = lp_increase + min_lp_amount; + pair_setup.add_liquidity( + lp_increase + min_lp_amount, + lp_increase, + lp_increase + min_lp_amount, + lp_increase, + lp_increase, + lp_increase + min_lp_amount, + lp_increase + min_lp_amount, + ); + pair_setup.swap_fixed_input( + WEGLD_TOKEN_ID, + payment_amount, + MEX_TOKEN_ID, + 900, + expected_amount, + ); + pair_setup.check_lp_amount(lp_amount); + + block_round += weight; + expected_amount -= 2; // slippage + pair_setup.b_mock.set_block_round(block_round); + pair_setup.swap_fixed_input( + WEGLD_TOKEN_ID, + payment_amount, + MEX_TOKEN_ID, + 900, + expected_amount, + ); + pair_setup.check_lp_amount(lp_amount); + + block_round += weight; + expected_amount -= 2; + pair_setup.b_mock.set_block_round(block_round); + + // Change LP amount starting block 1030 + let lp_amount_increase = 998_005; + lp_amount += lp_amount_increase; + pair_setup.add_liquidity( + lp_increase, + lp_increase, + 996_021, + 996_021, + lp_amount_increase, + lp_increase, + 996_021, + ); + pair_setup.swap_fixed_input( + WEGLD_TOKEN_ID, + payment_amount, + MEX_TOKEN_ID, + 900, + expected_amount, + ); + pair_setup.check_lp_amount(lp_amount); + + block_round += weight; + expected_amount -= 1; + pair_setup.b_mock.set_block_round(block_round); + pair_setup.swap_fixed_input( + WEGLD_TOKEN_ID, + payment_amount, + MEX_TOKEN_ID, + 900, + expected_amount, + ); + pair_setup.check_lp_amount(lp_amount); + + block_round += weight; + expected_amount -= 1; + pair_setup.b_mock.set_block_round(block_round); + pair_setup.swap_fixed_input( + WEGLD_TOKEN_ID, + payment_amount, + MEX_TOKEN_ID, + 900, + expected_amount, + ); + pair_setup.check_lp_amount(lp_amount); + + // Check the normal safe price + let lp_token_amount = 100_000; + pair_setup.check_lp_tokens_safe_price( + &pair_address, + 1011, + 1019, + lp_token_amount, + WEGLD_TOKEN_ID, + 100_099, + MEX_TOKEN_ID, + 99_900, + ); + + pair_setup.check_lp_tokens_safe_price( + &pair_address, + 1020, + 1030, + lp_token_amount, + WEGLD_TOKEN_ID, + 100_199, + MEX_TOKEN_ID, + 99_801, + ); + + pair_setup.check_lp_tokens_safe_price( + &pair_address, + 1030, + 1040, + lp_token_amount, + WEGLD_TOKEN_ID, + 100_249, + MEX_TOKEN_ID, + 99_751, + ); + + // Simulate old price observations + pair_setup.set_price_observation_as_old(1); + pair_setup.set_price_observation_as_old(2); + + // Check migration safe price + // Both observations are old + // Latest LP amount is used, so this should be the different than before + pair_setup.check_lp_tokens_safe_price( + &pair_address, + 1011, + 1019, + lp_token_amount, + WEGLD_TOKEN_ID, + 50124, + MEX_TOKEN_ID, + 50_025, + ); + + // First observation is old and the last observation is migrated + // Latest LP amount is used, so this should be the different than before + pair_setup.check_lp_tokens_safe_price( + &pair_address, + 1020, + 1030, + lp_token_amount, + WEGLD_TOKEN_ID, + 50_174, + MEX_TOKEN_ID, + 49_975, + ); + + // Both observations are migrated, + // Saved LP is used, so this should be the same as before + pair_setup.check_lp_tokens_safe_price( + &pair_address, + 1030, + 1040, + lp_token_amount, + WEGLD_TOKEN_ID, + 100_249, + MEX_TOKEN_ID, + 99_751, + ); +} + #[test] fn test_safe_price() { let mut pair_setup = PairSetup::new(pair::contract_obj); diff --git a/dex/pair/tests/pair_setup/mod.rs b/dex/pair/tests/pair_setup/mod.rs index 5ca0fcd84..78f99b6e9 100644 --- a/dex/pair/tests/pair_setup/mod.rs +++ b/dex/pair/tests/pair_setup/mod.rs @@ -1,6 +1,6 @@ use multiversx_sc::codec::multi_types::MultiValue3; use multiversx_sc::types::{ - Address, EsdtLocalRole, EsdtTokenPayment, ManagedAddress, MultiValueEncoded, + Address, BigUint, EsdtLocalRole, EsdtTokenPayment, ManagedAddress, MultiValueEncoded, }; use multiversx_sc_scenario::whitebox_legacy::TxTokenTransfer; use multiversx_sc_scenario::{ @@ -22,6 +22,7 @@ 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::SafePriceModule; use pair::safe_price_view::*; use pair::*; use pausable::{PausableModule, State}; @@ -274,6 +275,15 @@ where ); } + pub fn check_lp_amount(&mut self, expected_amount: u64) { + self.b_mock + .execute_query(&self.pair_wrapper, |sc| { + let lp_amount = sc.lp_token_supply().get(); + assert_eq!(lp_amount, managed_biguint!(expected_amount)); + }) + .assert_ok(); + } + pub fn check_price_observation( &mut self, pair_address: &Address, @@ -358,6 +368,55 @@ where }); } + #[allow(clippy::too_many_arguments)] + pub fn check_lp_tokens_safe_price( + &mut self, + pair_address: &Address, + start_round: u64, + end_round: u64, + lp_token_amount: u64, + expected_first_token_id: &[u8], + expected_first_token_amount: u64, + expected_second_token_id: &[u8], + expected_second_token_amount: u64, + ) { + let _ = self.b_mock.execute_query(&self.pair_wrapper, |sc| { + let lp_tokens_safe_price = sc.get_lp_tokens_safe_price( + managed_address!(pair_address), + start_round, + end_round, + managed_biguint!(lp_token_amount), + ); + let (first_payment, second_payment) = lp_tokens_safe_price.into_tuple(); + assert_eq!( + first_payment.token_identifier, + managed_token_id!(expected_first_token_id) + ); + assert_eq!( + first_payment.amount, + managed_biguint!(expected_first_token_amount) + ); + assert_eq!( + second_payment.token_identifier, + managed_token_id!(expected_second_token_id) + ); + assert_eq!( + second_payment.amount, + managed_biguint!(expected_second_token_amount) + ); + }); + } + + pub fn set_price_observation_as_old(&mut self, observation_index: usize) { + let _ = self.b_mock.execute_query(&self.pair_wrapper, |sc| { + let mut price_observations = sc.price_observations(); + + let mut price_observation = price_observations.get(observation_index); + price_observation.lp_supply_accumulated = BigUint::zero(); + price_observations.set(observation_index, &price_observation); + }); + } + #[allow(clippy::too_many_arguments)] pub fn check_safe_price_from_second_pair( &mut self, diff --git a/dex/pair/wasm-pair-full/Cargo.lock b/dex/pair/wasm-pair-full/Cargo.lock index 77c4e33e1..50c1aa77e 100644 --- a/dex/pair/wasm-pair-full/Cargo.lock +++ b/dex/pair/wasm-pair-full/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common-types" @@ -47,9 +47,9 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "endian-type" @@ -161,32 +161,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -196,9 +198,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -209,18 +211,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -236,9 +238,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -286,18 +288,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -331,15 +333,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -361,6 +363,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" diff --git a/dex/pair/wasm-pair-full/Cargo.toml b/dex/pair/wasm-pair-full/Cargo.toml index 5fc0f4b76..dc76ad64d 100644 --- a/dex/pair/wasm-pair-full/Cargo.toml +++ b/dex/pair/wasm-pair-full/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.pair] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [workspace] members = ["."] diff --git a/dex/pair/wasm-pair-full/src/lib.rs b/dex/pair/wasm-pair-full/src/lib.rs index 149c4a91b..5f39165a9 100644 --- a/dex/pair/wasm-pair-full/src/lib.rs +++ b/dex/pair/wasm-pair-full/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 64 +// Upgrade: 1 +// Endpoints: 63 // Async Callback (empty): 1 // Total number of exported functions: 66 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); diff --git a/dex/pair/wasm-safe-price-view/Cargo.lock b/dex/pair/wasm-safe-price-view/Cargo.lock index 48471aad0..e71c9ac82 100644 --- a/dex/pair/wasm-safe-price-view/Cargo.lock +++ b/dex/pair/wasm-safe-price-view/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common-types" @@ -47,9 +47,9 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "endian-type" @@ -161,32 +161,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -196,9 +198,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -209,18 +211,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -236,9 +238,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -278,18 +280,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -331,15 +333,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -361,6 +363,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" diff --git a/dex/pair/wasm-safe-price-view/Cargo.toml b/dex/pair/wasm-safe-price-view/Cargo.toml index 28c1d40a9..1d7822b69 100644 --- a/dex/pair/wasm-safe-price-view/Cargo.toml +++ b/dex/pair/wasm-safe-price-view/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.pair] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [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 cc5f99d90..de0966c65 100644 --- a/dex/pair/wasm-safe-price-view/src/lib.rs +++ b/dex/pair/wasm-safe-price-view/src/lib.rs @@ -10,8 +10,6 @@ // Total number of exported functions: 11 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); diff --git a/dex/pair/wasm/Cargo.lock b/dex/pair/wasm/Cargo.lock index c1f2406db..1b9f258d3 100644 --- a/dex/pair/wasm/Cargo.lock +++ b/dex/pair/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common-types" @@ -47,9 +47,9 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "endian-type" @@ -161,32 +161,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -196,9 +198,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -209,18 +211,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -236,9 +238,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -286,18 +288,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -331,15 +333,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -361,6 +363,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" diff --git a/dex/pair/wasm/Cargo.toml b/dex/pair/wasm/Cargo.toml index 7e096d156..4d8c6bfa9 100644 --- a/dex/pair/wasm/Cargo.toml +++ b/dex/pair/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.pair] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [workspace] members = ["."] diff --git a/dex/pair/wasm/src/lib.rs b/dex/pair/wasm/src/lib.rs index 82a357b8a..7279213ee 100644 --- a/dex/pair/wasm/src/lib.rs +++ b/dex/pair/wasm/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 55 +// Upgrade: 1 +// Endpoints: 54 // Async Callback (empty): 1 // Total number of exported functions: 57 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); diff --git a/dex/price-discovery/Cargo.toml b/dex/price-discovery/Cargo.toml index 51aa316e3..dbce3a106 100644 --- a/dex/price-discovery/Cargo.toml +++ b/dex/price-discovery/Cargo.toml @@ -12,11 +12,11 @@ path = "src/lib.rs" hex-literal = "0.3.1" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" [dependencies.locking_module] path = "../../common/modules/locking_module" @@ -30,4 +30,4 @@ hex = "0.4" path = "../../locked-asset/simple-lock" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" diff --git a/dex/price-discovery/meta/Cargo.toml b/dex/price-discovery/meta/Cargo.toml index 176823d06..cf2ee11ea 100644 --- a/dex/price-discovery/meta/Cargo.toml +++ b/dex/price-discovery/meta/Cargo.toml @@ -8,6 +8,6 @@ authors = ["Dorin Iancu "] [dependencies.price-discovery] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/dex/price-discovery/meta/src/main.rs b/dex/price-discovery/meta/src/main.rs index cd6c3e67a..99c719344 100644 --- a/dex/price-discovery/meta/src/main.rs +++ b/dex/price-discovery/meta/src/main.rs @@ -1,3 +1,3 @@ fn main() { - multiversx_sc_meta::cli_main::(); + multiversx_sc_meta_lib::cli_main::(); } diff --git a/dex/price-discovery/src/lib.rs b/dex/price-discovery/src/lib.rs index 32a07acf0..b0c430e52 100644 --- a/dex/price-discovery/src/lib.rs +++ b/dex/price-discovery/src/lib.rs @@ -113,7 +113,7 @@ pub trait PriceDiscovery: self.set_locking_sc_address(locking_sc_address); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} /// Users can deposit either launched_token or accepted_token. diff --git a/dex/price-discovery/wasm/Cargo.lock b/dex/price-discovery/wasm/Cargo.lock index fbcb7ca84..4fbe6c51b 100644 --- a/dex/price-discovery/wasm/Cargo.lock +++ b/dex/price-discovery/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common_errors" @@ -119,32 +119,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal 0.4.1", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -154,9 +156,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -167,18 +169,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -194,9 +196,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -221,18 +223,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -266,15 +268,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -287,6 +289,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" diff --git a/dex/price-discovery/wasm/Cargo.toml b/dex/price-discovery/wasm/Cargo.toml index 04885bcda..cc6bf1c73 100644 --- a/dex/price-discovery/wasm/Cargo.toml +++ b/dex/price-discovery/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.price-discovery] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [workspace] members = ["."] diff --git a/dex/price-discovery/wasm/src/lib.rs b/dex/price-discovery/wasm/src/lib.rs index c29196d8a..5e55db7a5 100644 --- a/dex/price-discovery/wasm/src/lib.rs +++ b/dex/price-discovery/wasm/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 28 +// Upgrade: 1 +// Endpoints: 27 // Async Callback: 1 // Total number of exported functions: 30 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); diff --git a/dex/proxy-deployer/Cargo.toml b/dex/proxy-deployer/Cargo.toml index f5c3b8955..d703dda15 100644 --- a/dex/proxy-deployer/Cargo.toml +++ b/dex/proxy-deployer/Cargo.toml @@ -21,11 +21,11 @@ path = "../../common/modules/farm/config" path = "../../common/modules/farm/farm_token" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" diff --git a/dex/proxy-deployer/meta/Cargo.toml b/dex/proxy-deployer/meta/Cargo.toml index 629fddbdf..22fe6e5de 100644 --- a/dex/proxy-deployer/meta/Cargo.toml +++ b/dex/proxy-deployer/meta/Cargo.toml @@ -10,6 +10,6 @@ authors = ["MultiversX "] [dependencies.proxy-deployer] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/dex/proxy-deployer/meta/src/main.rs b/dex/proxy-deployer/meta/src/main.rs index 6df25a6b5..287e43ccd 100644 --- a/dex/proxy-deployer/meta/src/main.rs +++ b/dex/proxy-deployer/meta/src/main.rs @@ -1,3 +1,3 @@ fn main() { - multiversx_sc_meta::cli_main::(); + multiversx_sc_meta_lib::cli_main::(); } diff --git a/dex/proxy-deployer/src/lib.rs b/dex/proxy-deployer/src/lib.rs index a05bab7b0..7f7f0c16a 100644 --- a/dex/proxy-deployer/src/lib.rs +++ b/dex/proxy-deployer/src/lib.rs @@ -16,6 +16,6 @@ pub trait ProxyDeployer: farm_deploy::FarmDeployModule { self.farm_template_address().set(&farm_template_address); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} } diff --git a/dex/proxy-deployer/wasm/Cargo.lock b/dex/proxy-deployer/wasm/Cargo.lock index 371955a5f..8d87420e6 100644 --- a/dex/proxy-deployer/wasm/Cargo.lock +++ b/dex/proxy-deployer/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common-types" @@ -76,9 +76,9 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "endian-type" @@ -277,32 +277,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -312,9 +314,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -325,18 +327,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -352,9 +354,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -394,9 +396,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -422,9 +424,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -473,15 +475,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -511,6 +513,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" diff --git a/dex/proxy-deployer/wasm/Cargo.toml b/dex/proxy-deployer/wasm/Cargo.toml index 97ada3a24..e5da175f9 100644 --- a/dex/proxy-deployer/wasm/Cargo.toml +++ b/dex/proxy-deployer/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.proxy-deployer] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [workspace] members = ["."] diff --git a/dex/proxy-deployer/wasm/src/lib.rs b/dex/proxy-deployer/wasm/src/lib.rs index b8f3493f8..620fcb058 100644 --- a/dex/proxy-deployer/wasm/src/lib.rs +++ b/dex/proxy-deployer/wasm/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 5 +// Upgrade: 1 +// Endpoints: 4 // Async Callback (empty): 1 // Total number of exported functions: 7 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); diff --git a/dex/router/Cargo.toml b/dex/router/Cargo.toml index cc3698241..4ecf1aa3c 100644 --- a/dex/router/Cargo.toml +++ b/dex/router/Cargo.toml @@ -15,7 +15,7 @@ path = "../../common/modules/token_send" path = "../../common/modules/pausable" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.pair] @@ -28,4 +28,4 @@ path = "../../common/modules/locking_module" path = "../../locked-asset/simple-lock" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" diff --git a/dex/router/meta/Cargo.toml b/dex/router/meta/Cargo.toml index c5deaf0be..7dcef100f 100644 --- a/dex/router/meta/Cargo.toml +++ b/dex/router/meta/Cargo.toml @@ -8,6 +8,6 @@ publish = false [dependencies.router] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/dex/router/meta/src/main.rs b/dex/router/meta/src/main.rs index 675a0e481..c79cfbcc5 100644 --- a/dex/router/meta/src/main.rs +++ b/dex/router/meta/src/main.rs @@ -1,3 +1,3 @@ fn main() { - multiversx_sc_meta::cli_main::(); + multiversx_sc_meta_lib::cli_main::(); } diff --git a/dex/router/src/config.rs b/dex/router/src/config.rs index 25c96a3e6..830d301c8 100644 --- a/dex/router/src/config.rs +++ b/dex/router/src/config.rs @@ -2,18 +2,38 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); use crate::{enable_swap_by_user::EnableSwapByUserConfig, factory::PairTokens}; +use pair::read_pair_storage; #[multiversx_sc::module] -pub trait ConfigModule { +pub trait ConfigModule: read_pair_storage::ReadPairStorageModule { fn is_active(&self) -> bool { self.state().get() } fn check_is_pair_sc(&self, pair_address: &ManagedAddress) { - require!( - self.address_pair_map().contains_key(pair_address), - "Not a pair SC" - ); + let first_token_id = self.get_first_token_id_mapper(pair_address.clone()).get(); + let second_token_id = self.get_second_token_id_mapper(pair_address.clone()).get(); + + let pair_tokens = PairTokens { + first_token_id: first_token_id.clone(), + second_token_id: second_token_id.clone(), + }; + + let mut pair_map_address_opt = self.pair_map().get(&pair_tokens); + if pair_map_address_opt.is_none() { + let reverse_pair_tokens = PairTokens { + first_token_id: second_token_id.clone(), + second_token_id: first_token_id.clone(), + }; + pair_map_address_opt = self.pair_map().get(&reverse_pair_tokens); + } + + require!(pair_map_address_opt.is_some(), "Not a pair SC"); + + unsafe { + let pair_map_address = pair_map_address_opt.unwrap_unchecked(); + require!(&pair_map_address == pair_address, "Not a pair SC"); + } } #[view(getPairCreationEnabled)] @@ -43,9 +63,6 @@ pub trait ConfigModule { #[storage_mapper("pair_map")] fn pair_map(&self) -> MapMapper, ManagedAddress>; - #[storage_mapper("address_pair_map")] - fn address_pair_map(&self) -> MapMapper>; - #[view(getPairTemplateAddress)] #[storage_mapper("pair_template_address")] fn pair_template_address(&self) -> SingleValueMapper; diff --git a/dex/router/src/contract.rs b/dex/router/src/contract.rs index 04b787a03..ad30b7f9e 100644 --- a/dex/router/src/contract.rs +++ b/dex/router/src/contract.rs @@ -1,4 +1,5 @@ #![no_std] +#![allow(deprecated)] multiversx_sc::imports!(); multiversx_sc::derive_imports!(); @@ -12,7 +13,7 @@ pub mod multi_pair_swap; use factory::PairTokens; use pair::config::ProxyTrait as _; use pair::fee::ProxyTrait as _; -use pair::ProxyTrait as _; +use pair::{read_pair_storage, ProxyTrait as _}; use pausable::ProxyTrait as _; const LP_TOKEN_DECIMALS: usize = 18; @@ -26,6 +27,7 @@ const USER_DEFINED_TOTAL_FEE_PERCENT: u64 = 1_000; #[multiversx_sc::contract] pub trait Router: config::ConfigModule + + read_pair_storage::ReadPairStorageModule + factory::FactoryModule + events::EventsModule + multi_pair_swap::MultiPairSwap @@ -41,7 +43,7 @@ pub trait Router: self.owner().set(&self.blockchain().get_caller()); } - #[endpoint] + #[upgrade] fn upgrade(&self) { self.state().set(false); } @@ -64,10 +66,6 @@ pub trait Router: #[endpoint] fn resume(&self, address: ManagedAddress) { if address == self.blockchain().get_sc_address() { - require!( - self.pair_map().len() == self.address_pair_map().len(), - "The size of the 2 pair maps is not the same" - ); self.state().set(true); } else { self.check_is_pair_sc(&address); @@ -159,9 +157,6 @@ pub trait Router: &self, first_token_id: TokenIdentifier, second_token_id: TokenIdentifier, - initial_liquidity_adder: ManagedAddress, - total_fee_percent_requested: u64, - special_fee_percent_requested: u64, ) { require!(self.is_active(), "Not active"); @@ -177,21 +172,7 @@ pub trait Router: let pair_address = self.get_pair(first_token_id.clone(), second_token_id.clone()); require!(!pair_address.is_zero(), "Pair does not exists"); - require!( - total_fee_percent_requested >= special_fee_percent_requested - && total_fee_percent_requested < MAX_TOTAL_FEE_PERCENT, - "Bad percents" - ); - - self.upgrade_pair( - pair_address, - &first_token_id, - &second_token_id, - &self.owner().get(), - &initial_liquidity_adder, - total_fee_percent_requested, - special_fee_percent_requested, - ); + self.upgrade_pair(pair_address); } #[payable("EGLD")] @@ -317,8 +298,6 @@ pub trait Router: .unwrap_or_else(ManagedAddress::zero); } - self.address_pair_map().remove(&pair_address); - pair_address } @@ -385,23 +364,4 @@ pub trait Router: fn set_pair_creation_enabled(&self, enabled: bool) { self.pair_creation_enabled().set(enabled); } - - #[only_owner] - #[endpoint(migratePairMap)] - fn migrate_pair_map(&self) { - let pair_map = self.pair_map(); - let mut address_pair_map = self.address_pair_map(); - require!( - address_pair_map.is_empty(), - "The destination mapper must be empty" - ); - for (pair_tokens, address) in pair_map.iter() { - address_pair_map.insert(address, pair_tokens); - } - - require!( - pair_map.len() == address_pair_map.len(), - "The size of the 2 pair maps is not the same" - ); - } } diff --git a/dex/router/src/enable_swap_by_user.rs b/dex/router/src/enable_swap_by_user.rs index 7c77036c1..1a8c40770 100644 --- a/dex/router/src/enable_swap_by_user.rs +++ b/dex/router/src/enable_swap_by_user.rs @@ -1,7 +1,7 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); -use pair::{config::ProxyTrait as _, pair_actions::views::ProxyTrait as _}; +use pair::{config::ProxyTrait as _, pair_actions::views::ProxyTrait as _, read_pair_storage}; use pausable::{ProxyTrait as _, State}; use simple_lock::locked_token::LockedTokenAttributes; @@ -27,7 +27,10 @@ pub struct SafePriceResult { #[multiversx_sc::module] pub trait EnableSwapByUserModule: - config::ConfigModule + crate::factory::FactoryModule + crate::events::EventsModule + config::ConfigModule + + read_pair_storage::ReadPairStorageModule + + crate::factory::FactoryModule + + crate::events::EventsModule { #[only_owner] #[endpoint(configEnableByUserParameters)] @@ -83,6 +86,7 @@ pub trait EnableSwapByUserModule: #[payable("*")] #[endpoint(setSwapEnabledByUser)] fn set_swap_enabled_by_user(&self, pair_address: ManagedAddress) { + require!(self.is_active(), "Not active"); self.check_is_pair_sc(&pair_address); self.require_state_active_no_swaps(&pair_address); diff --git a/dex/router/src/events.rs b/dex/router/src/events.rs index 8ee097a5e..b80888e5a 100644 --- a/dex/router/src/events.rs +++ b/dex/router/src/events.rs @@ -22,6 +22,19 @@ pub struct UserPairSwapEnabledEvent { pair_address: ManagedAddress, } +#[derive(TypeAbi, TopEncode)] +pub struct MultiPairSwapEvent { + caller: ManagedAddress, + token_in: TokenIdentifier, + amount_in: BigUint, + token_out: TokenIdentifier, + amount_out: BigUint, + payments_out: ManagedVec>, + block: u64, + epoch: u64, + timestamp: u64, +} + #[multiversx_sc::module] pub trait EventsModule { fn emit_create_pair_event( @@ -75,6 +88,43 @@ pub trait EventsModule { ) } + fn emit_multi_pair_swap_event( + &self, + caller: ManagedAddress, + token_in: TokenIdentifier, + amount_in: BigUint, + payments_out: ManagedVec, + ) { + if payments_out.is_empty() { + return; + } + + let block = self.blockchain().get_block_nonce(); + let epoch = self.blockchain().get_block_epoch(); + let timestamp = self.blockchain().get_block_timestamp(); + let last_payment_index = payments_out.len() - 1; + let token_out = payments_out.get(last_payment_index); + self.multi_pair_swap_event( + caller.clone(), + token_in.clone(), + amount_in.clone(), + token_out.token_identifier.clone(), + token_out.amount.clone(), + epoch, + MultiPairSwapEvent { + caller, + token_in, + amount_in, + token_out: token_out.token_identifier, + amount_out: token_out.amount, + payments_out, + block, + epoch, + timestamp, + }, + ) + } + #[event("create_pair")] fn create_pair_event( self, @@ -94,4 +144,16 @@ pub trait EventsModule { #[indexed] epoch: u64, swap_enabled_event: UserPairSwapEnabledEvent, ); + + #[event("multiPairSwap")] + fn multi_pair_swap_event( + &self, + #[indexed] caller: ManagedAddress, + #[indexed] token_in: TokenIdentifier, + #[indexed] amount_in: BigUint, + #[indexed] token_out: TokenIdentifier, + #[indexed] amount_out: BigUint, + #[indexed] epoch: u64, + multi_pair_swap_event: MultiPairSwapEvent, + ); } diff --git a/dex/router/src/factory.rs b/dex/router/src/factory.rs index 4994db235..ff7633a15 100644 --- a/dex/router/src/factory.rs +++ b/dex/router/src/factory.rs @@ -2,6 +2,7 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); use crate::config; +use pair::read_pair_storage; const TEMPORARY_OWNER_PERIOD_BLOCKS: u64 = 50; @@ -19,7 +20,7 @@ pub struct PairContractMetadata { } #[multiversx_sc::module] -pub trait FactoryModule: config::ConfigModule { +pub trait FactoryModule: config::ConfigModule + read_pair_storage::ReadPairStorageModule { #[proxy] fn pair_contract_deploy_proxy(&self) -> pair::Proxy; @@ -71,13 +72,6 @@ pub trait FactoryModule: config::ConfigModule { }, new_address.clone(), ); - self.address_pair_map().insert( - new_address.clone(), - PairTokens { - first_token_id: first_token_id.clone(), - second_token_id: second_token_id.clone(), - }, - ); self.pair_temporary_owner().insert( new_address.clone(), ( @@ -88,32 +82,16 @@ pub trait FactoryModule: config::ConfigModule { new_address } - fn upgrade_pair( - &self, - pair_address: ManagedAddress, - first_token_id: &TokenIdentifier, - second_token_id: &TokenIdentifier, - owner: &ManagedAddress, - _initial_liquidity_adder: &ManagedAddress, - total_fee_percent: u64, - special_fee_percent: u64, - ) { - self.pair_contract_deploy_proxy() - .contract(pair_address) - .init( - first_token_id, - second_token_id, - self.blockchain().get_sc_address(), - owner, - total_fee_percent, - special_fee_percent, - ManagedAddress::zero(), - MultiValueEncoded::new(), - ) - .upgrade_from_source( - &self.pair_template_address().get(), - CodeMetadata::UPGRADEABLE | CodeMetadata::READABLE | CodeMetadata::PAYABLE_BY_SC, - ); + fn upgrade_pair(&self, pair_address: ManagedAddress) { + let pair_template_address = self.pair_template_address().get(); + let code_metadata = + CodeMetadata::UPGRADEABLE | CodeMetadata::READABLE | CodeMetadata::PAYABLE_BY_SC; + self.tx() + .to(pair_address) + .raw_upgrade() + .from_source(pair_template_address) + .code_metadata(code_metadata) + .upgrade_async_call_and_exit(); } #[view(getAllPairsManagedAddresses)] @@ -174,13 +152,6 @@ pub trait FactoryModule: config::ConfigModule { address } - #[view(getPairTokens)] - fn get_pair_tokens(&self, pair_address: ManagedAddress) -> PairTokens { - let pair_tokens_opt = self.address_pair_map().get(&pair_address); - require!(pair_tokens_opt.is_some(), "Pair address not found"); - pair_tokens_opt.unwrap() - } - fn get_pair_temporary_owner(&self, pair_address: &ManagedAddress) -> Option { let result = self.pair_temporary_owner().get(pair_address); diff --git a/dex/router/src/multi_pair_swap.rs b/dex/router/src/multi_pair_swap.rs index e69350ecd..8a09bfb9f 100644 --- a/dex/router/src/multi_pair_swap.rs +++ b/dex/router/src/multi_pair_swap.rs @@ -1,11 +1,9 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); -use pair::pair_actions::swap::ProxyTrait as _; - -use crate::config; - use super::factory; +use crate::{config, events}; +use pair::{pair_actions::swap::ProxyTrait as _, read_pair_storage}; type SwapOperationType = MultiValue4, ManagedBuffer, TokenIdentifier, BigUint>; @@ -15,11 +13,18 @@ pub const SWAP_TOKENS_FIXED_OUTPUT_FUNC_NAME: &[u8] = b"swapTokensFixedOutput"; #[multiversx_sc::module] pub trait MultiPairSwap: - config::ConfigModule + factory::FactoryModule + token_send::TokenSendModule + config::ConfigModule + + read_pair_storage::ReadPairStorageModule + + factory::FactoryModule + + token_send::TokenSendModule + + events::EventsModule { #[payable("*")] #[endpoint(multiPairSwap)] - fn multi_pair_swap(&self, swap_operations: MultiValueEncoded>) -> ManagedVec { + fn multi_pair_swap( + &self, + swap_operations: MultiValueEncoded>, + ) -> ManagedVec { require!(self.is_active(), "Not active"); let (token_id, nonce, amount) = self.call_value().single_esdt().into_tuple(); @@ -35,7 +40,7 @@ pub trait MultiPairSwap: let caller = self.blockchain().get_caller(); let mut payments = ManagedVec::new(); - let mut last_payment = EsdtTokenPayment::new(token_id, nonce, amount); + let mut last_payment = EsdtTokenPayment::new(token_id.clone(), nonce, amount.clone()); for entry in swap_operations.into_iter() { let (pair_address, function, token_wanted, amount_wanted) = entry.into_tuple(); @@ -59,7 +64,10 @@ pub trait MultiPairSwap: ); last_payment = payment; - payments.push(residuum); + + if residuum.amount > 0 { + payments.push(residuum); + } } else { sc_panic!("Invalid function to call"); } @@ -68,6 +76,8 @@ pub trait MultiPairSwap: payments.push(last_payment); self.send().direct_multi(&caller, &payments); + self.emit_multi_pair_swap_event(caller, token_id, amount, payments.clone()); + payments } diff --git a/dex/router/tests/router_setup/mod.rs b/dex/router/tests/router_setup/mod.rs index c72b6a971..4339d502d 100644 --- a/dex/router/tests/router_setup/mod.rs +++ b/dex/router/tests/router_setup/mod.rs @@ -284,17 +284,4 @@ where ) .assert_ok(); } - - pub fn migrate_pair_map(&mut self) { - self.blockchain_wrapper - .execute_tx( - &self.owner_address, - &self.router_wrapper, - &rust_biguint!(0u64), - |sc| { - sc.migrate_pair_map(); - }, - ) - .assert_ok(); - } } diff --git a/dex/router/tests/router_test.rs b/dex/router/tests/router_test.rs index 54c73c838..6564a508e 100644 --- a/dex/router/tests/router_test.rs +++ b/dex/router/tests/router_test.rs @@ -113,13 +113,7 @@ fn test_router_upgrade_pair() { .execute_tx(&owner, &router_wrapper, &rust_zero, |sc| { let first_token_id = managed_token_id!(CUSTOM_TOKEN_ID); let second_token_id = managed_token_id!(USDC_TOKEN_ID); - sc.upgrade_pair_endpoint( - first_token_id, - second_token_id, - managed_address!(&user), - 300, - 50, - ); + sc.upgrade_pair_endpoint(first_token_id, second_token_id); }) .assert_ok(); @@ -134,7 +128,6 @@ fn test_router_upgrade_pair() { #[test] fn test_multi_pair_swap() { let mut router_setup = RouterSetup::new(router::contract_obj, pair::contract_obj); - router_setup.migrate_pair_map(); router_setup.add_liquidity(); @@ -255,8 +248,6 @@ fn user_enable_pair_swaps_through_router_test() { managed_address!(pair_wrapper.address_ref()), ); - sc.migrate_pair_map(); - sc.add_common_tokens_for_user_pairs(MultiValueEncoded::from(ManagedVec::from(vec![ managed_token_id!(USDC_TOKEN_ID), ]))); @@ -442,8 +433,6 @@ fn user_enable_pair_swaps_fail_test() { managed_address!(pair_wrapper.address_ref()), ); - sc.migrate_pair_map(); - sc.add_common_tokens_for_user_pairs(MultiValueEncoded::from(ManagedVec::from(vec![ managed_token_id!(USDC_TOKEN_ID), ]))); diff --git a/dex/router/wasm/Cargo.lock b/dex/router/wasm/Cargo.lock index 0f5cc1535..a8e9d5976 100644 --- a/dex/router/wasm/Cargo.lock +++ b/dex/router/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common-types" @@ -47,9 +47,9 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "endian-type" @@ -161,32 +161,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -196,9 +198,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -209,18 +211,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -236,9 +238,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -278,18 +280,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -343,15 +345,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -373,6 +375,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" diff --git a/dex/router/wasm/Cargo.toml b/dex/router/wasm/Cargo.toml index dc895383b..608f891d0 100644 --- a/dex/router/wasm/Cargo.toml +++ b/dex/router/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.router] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [workspace] members = ["."] diff --git a/dex/router/wasm/src/lib.rs b/dex/router/wasm/src/lib.rs index e840498ec..eb0bb84d5 100644 --- a/dex/router/wasm/src/lib.rs +++ b/dex/router/wasm/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 33 +// Upgrade: 1 +// Endpoints: 29 // Async Callback: 1 -// Total number of exported functions: 35 +// Total number of exported functions: 32 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -31,7 +30,6 @@ multiversx_sc_wasm_adapter::endpoints! { setFeeOn => set_fee_on setFeeOff => set_fee_off setPairCreationEnabled => set_pair_creation_enabled - migratePairMap => migrate_pair_map getPairCreationEnabled => pair_creation_enabled getState => state getOwner => owner @@ -44,7 +42,6 @@ multiversx_sc_wasm_adapter::endpoints! { getAllPairTokens => get_all_token_pairs getAllPairContractMetadata => get_all_pair_contract_metadata getPair => get_pair - getPairTokens => get_pair_tokens clearPairTemporaryOwnerStorage => clear_pair_temporary_owner_storage multiPairSwap => multi_pair_swap configEnableByUserParameters => config_enable_by_user_parameters diff --git a/dex/scenarios/upgrade_contract.scen.json b/dex/scenarios/upgrade_contract.scen.json index cdadc752b..9a9c88fe2 100644 --- a/dex/scenarios/upgrade_contract.scen.json +++ b/dex/scenarios/upgrade_contract.scen.json @@ -14,10 +14,7 @@ "function": "upgradePair", "arguments": [ "str:ALC-abcdef", - "str:WEGLD-abcdef", - "0x0000000000000000000000000000000000000000000000000000000000000000", - "300", - "100" + "str:WEGLD-abcdef" ], "gasLimit": "1,000,000,000", "gasPrice": "0" diff --git a/dex/tests/dex_scenario_rs_test.rs b/dex/tests/dex_scenario_rs_test.rs index 623f63667..3a0b16a81 100644 --- a/dex/tests/dex_scenario_rs_test.rs +++ b/dex/tests/dex_scenario_rs_test.rs @@ -2,7 +2,6 @@ use multiversx_sc_scenario::ScenarioWorld; fn world() -> ScenarioWorld { let mut blockchain = ScenarioWorld::new(); - blockchain.set_current_dir_from_workspace("dex"); blockchain.register_contract("file:router/output/router.wasm", router::ContractBuilder); blockchain.register_contract("file:pair/output/pair.wasm", pair::ContractBuilder); diff --git a/energy-integration/common-modules/energy-query/Cargo.toml b/energy-integration/common-modules/energy-query/Cargo.toml index 429ddafe2..bb7f02bc2 100644 --- a/energy-integration/common-modules/energy-query/Cargo.toml +++ b/energy-integration/common-modules/energy-query/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.energy-factory] diff --git a/energy-integration/common-modules/week-timekeeping/Cargo.toml b/energy-integration/common-modules/week-timekeeping/Cargo.toml index 32e16b01e..64a65bd3e 100644 --- a/energy-integration/common-modules/week-timekeeping/Cargo.toml +++ b/energy-integration/common-modules/week-timekeeping/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.common-types] diff --git a/energy-integration/common-modules/weekly-rewards-splitting/Cargo.toml b/energy-integration/common-modules/weekly-rewards-splitting/Cargo.toml index 0603f0084..df65be5b4 100644 --- a/energy-integration/common-modules/weekly-rewards-splitting/Cargo.toml +++ b/energy-integration/common-modules/weekly-rewards-splitting/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" 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 c8579672d..de8783686 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 @@ -3,16 +3,32 @@ multiversx_sc::imports!(); use common_types::PaymentsVec; use week_timekeeping::Week; -use crate::{events, ClaimProgress}; +use crate::{ + events, global_info::WeeklyRewardsGlobalInfo, + update_claim_progress_energy::UpdateClaimProgressEnergyModule, ClaimProgress, +}; -pub trait AllBaseWeeklyRewardsSplittingImplTraits = +pub trait AllBaseWeeklyRewardsSplittingImplTraits: crate::WeeklyRewardsSplittingModule + + energy_query::EnergyQueryModule + + week_timekeeping::WeekTimekeepingModule + + crate::global_info::WeeklyRewardsGlobalInfo + + crate::locked_token_buckets::WeeklyRewardsLockedTokenBucketsModule + + events::WeeklyRewardsSplittingEventsModule + + crate::update_claim_progress_energy::UpdateClaimProgressEnergyModule +{ +} + +impl AllBaseWeeklyRewardsSplittingImplTraits for T where + T: crate::WeeklyRewardsSplittingModule + energy_query::EnergyQueryModule + week_timekeeping::WeekTimekeepingModule + crate::global_info::WeeklyRewardsGlobalInfo + crate::locked_token_buckets::WeeklyRewardsLockedTokenBucketsModule + events::WeeklyRewardsSplittingEventsModule - + crate::update_claim_progress_energy::UpdateClaimProgressEnergyModule; + + crate::update_claim_progress_energy::UpdateClaimProgressEnergyModule +{ +} pub trait WeeklyRewardsSplittingTraitsModule { type WeeklyRewardsSplittingMod: AllBaseWeeklyRewardsSplittingImplTraits; 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 9268023bd..456bf60d2 100644 --- a/energy-integration/common-modules/weekly-rewards-splitting/src/lib.rs +++ b/energy-integration/common-modules/weekly-rewards-splitting/src/lib.rs @@ -1,6 +1,4 @@ #![no_std] -#![feature(trait_alias)] -#![feature(int_roundings)] multiversx_sc::imports!(); multiversx_sc::derive_imports!(); diff --git a/energy-integration/common-types/Cargo.toml b/energy-integration/common-types/Cargo.toml index b2ba8bc79..09dd6ccec 100644 --- a/energy-integration/common-types/Cargo.toml +++ b/energy-integration/common-types/Cargo.toml @@ -8,5 +8,5 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] diff --git a/energy-integration/energy-factory-mock/Cargo.toml b/energy-integration/energy-factory-mock/Cargo.toml index 6e246e8fb..56ee42be8 100644 --- a/energy-integration/energy-factory-mock/Cargo.toml +++ b/energy-integration/energy-factory-mock/Cargo.toml @@ -12,8 +12,8 @@ path = "src/lib.rs" path = "../common-modules/energy-query" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" diff --git a/energy-integration/energy-factory-mock/meta/Cargo.toml b/energy-integration/energy-factory-mock/meta/Cargo.toml index 94241670d..684df0109 100644 --- a/energy-integration/energy-factory-mock/meta/Cargo.toml +++ b/energy-integration/energy-factory-mock/meta/Cargo.toml @@ -10,6 +10,6 @@ authors = ["MultiversX "] [dependencies.energy-factory-mock] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/energy-integration/energy-factory-mock/meta/src/main.rs b/energy-integration/energy-factory-mock/meta/src/main.rs index ac08ec4b7..3866ddff7 100644 --- a/energy-integration/energy-factory-mock/meta/src/main.rs +++ b/energy-integration/energy-factory-mock/meta/src/main.rs @@ -1,3 +1,3 @@ fn main() { - multiversx_sc_meta::cli_main::(); + multiversx_sc_meta_lib::cli_main::(); } diff --git a/energy-integration/energy-factory-mock/wasm/Cargo.lock b/energy-integration/energy-factory-mock/wasm/Cargo.lock index 0693d6d5f..4e08004ac 100644 --- a/energy-integration/energy-factory-mock/wasm/Cargo.lock +++ b/energy-integration/energy-factory-mock/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common_errors" @@ -128,32 +128,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -163,9 +165,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -176,18 +178,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -203,27 +205,27 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -257,15 +259,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -278,6 +280,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" diff --git a/energy-integration/energy-factory-mock/wasm/Cargo.toml b/energy-integration/energy-factory-mock/wasm/Cargo.toml index 426c4c9f0..49b7fc839 100644 --- a/energy-integration/energy-factory-mock/wasm/Cargo.toml +++ b/energy-integration/energy-factory-mock/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.energy-factory-mock] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [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 c52b88848..400849b5a 100644 --- a/energy-integration/energy-factory-mock/wasm/src/lib.rs +++ b/energy-integration/energy-factory-mock/wasm/src/lib.rs @@ -10,8 +10,6 @@ // Total number of exported functions: 6 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); diff --git a/energy-integration/energy-update/Cargo.toml b/energy-integration/energy-update/Cargo.toml index 01489f0d7..58f7627f4 100644 --- a/energy-integration/energy-update/Cargo.toml +++ b/energy-integration/energy-update/Cargo.toml @@ -9,11 +9,11 @@ publish = false path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" [dependencies.farm] path = "../../dex/farm" @@ -25,4 +25,4 @@ path = "../common-modules/weekly-rewards-splitting" num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" diff --git a/energy-integration/energy-update/meta/Cargo.toml b/energy-integration/energy-update/meta/Cargo.toml index aa816ac82..245463e6b 100644 --- a/energy-integration/energy-update/meta/Cargo.toml +++ b/energy-integration/energy-update/meta/Cargo.toml @@ -10,6 +10,6 @@ authors = ["MultiversX "] [dependencies.energy-update] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/energy-integration/energy-update/meta/src/main.rs b/energy-integration/energy-update/meta/src/main.rs index d1938e1aa..0dd45d8fd 100644 --- a/energy-integration/energy-update/meta/src/main.rs +++ b/energy-integration/energy-update/meta/src/main.rs @@ -1,3 +1,3 @@ fn main() { - multiversx_sc_meta::cli_main::(); + multiversx_sc_meta_lib::cli_main::(); } diff --git a/energy-integration/energy-update/src/lib.rs b/energy-integration/energy-update/src/lib.rs index a8e10213f..6cb9a7520 100644 --- a/energy-integration/energy-update/src/lib.rs +++ b/energy-integration/energy-update/src/lib.rs @@ -9,7 +9,7 @@ pub trait EnergyUpdate { #[init] fn init(&self) {} - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[endpoint(updateFarmsEnergyForUser)] diff --git a/energy-integration/energy-update/wasm/Cargo.lock b/energy-integration/energy-update/wasm/Cargo.lock index 559a8a519..e36d78e0b 100644 --- a/energy-integration/energy-update/wasm/Cargo.lock +++ b/energy-integration/energy-update/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common-types" @@ -76,9 +76,9 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "endian-type" @@ -295,32 +295,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -330,9 +332,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -343,18 +345,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -370,9 +372,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -412,18 +414,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -472,15 +474,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -510,6 +512,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" diff --git a/energy-integration/energy-update/wasm/Cargo.toml b/energy-integration/energy-update/wasm/Cargo.toml index 399b3a678..0c9dd6013 100644 --- a/energy-integration/energy-update/wasm/Cargo.toml +++ b/energy-integration/energy-update/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.energy-update] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [workspace] members = ["."] diff --git a/energy-integration/energy-update/wasm/src/lib.rs b/energy-integration/energy-update/wasm/src/lib.rs index b4de939ec..7d5e5998a 100644 --- a/energy-integration/energy-update/wasm/src/lib.rs +++ b/energy-integration/energy-update/wasm/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 2 +// Upgrade: 1 +// Endpoints: 1 // Async Callback (empty): 1 // Total number of exported functions: 4 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); diff --git a/energy-integration/farm-boosted-yields/Cargo.toml b/energy-integration/farm-boosted-yields/Cargo.toml index 5a75c8b80..e3e8bb0c0 100644 --- a/energy-integration/farm-boosted-yields/Cargo.toml +++ b/energy-integration/farm-boosted-yields/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" 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 931c58f9d..739907b2c 100644 --- a/energy-integration/farm-boosted-yields/src/lib.rs +++ b/energy-integration/farm-boosted-yields/src/lib.rs @@ -44,14 +44,6 @@ pub trait FarmBoostedYieldsModule: + weekly_rewards_splitting::update_claim_progress_energy::UpdateClaimProgressEnergyModule + energy_query::EnergyQueryModule { - #[endpoint(setBoostedYieldsRewardsPercentage)] - fn set_boosted_yields_rewards_percentage(&self, percentage: u64) { - self.require_caller_has_admin_permissions(); - require!(percentage <= MAX_PERCENT, "Invalid percentage"); - - self.boosted_yields_rewards_percentage().set(percentage); - } - #[endpoint(collectUndistributedBoostedRewards)] fn collect_undistributed_boosted_rewards(&self) { self.require_caller_has_admin_permissions(); @@ -131,12 +123,12 @@ pub trait FarmBoostedYieldsModule: fn clear_user_energy_if_needed(&self, original_caller: &ManagedAddress) { let opt_config = self.try_get_boosted_yields_config(); - let user_total_farm_position = self.get_user_total_farm_position(original_caller); + let user_total_farm_position = self.user_total_farm_position(original_caller).get(); if let Some(config) = opt_config { let boosted_yields_factors = config.get_latest_factors(); self.clear_user_energy( original_caller, - &user_total_farm_position.total_farm_position, + &user_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 1b233b7f6..df169e2c7 100644 --- a/energy-integration/fees-collector/Cargo.toml +++ b/energy-integration/fees-collector/Cargo.toml @@ -9,11 +9,11 @@ publish = false path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" [dependencies.energy-query] path = "../common-modules/energy-query" @@ -49,7 +49,7 @@ path = "../../common/common_errors" num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" [dev-dependencies.sc_whitelist_module] path = "../../common/modules/sc_whitelist_module" diff --git a/energy-integration/fees-collector/meta/Cargo.toml b/energy-integration/fees-collector/meta/Cargo.toml index c91986348..4a593cb5d 100644 --- a/energy-integration/fees-collector/meta/Cargo.toml +++ b/energy-integration/fees-collector/meta/Cargo.toml @@ -10,6 +10,6 @@ authors = ["MultiversX "] [dependencies.fees-collector] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/energy-integration/fees-collector/meta/src/main.rs b/energy-integration/fees-collector/meta/src/main.rs index bb6376b4d..6be62c753 100644 --- a/energy-integration/fees-collector/meta/src/main.rs +++ b/energy-integration/fees-collector/meta/src/main.rs @@ -1,3 +1,3 @@ fn main() { - multiversx_sc_meta::cli_main::(); + multiversx_sc_meta_lib::cli_main::(); } diff --git a/energy-integration/fees-collector/src/config.rs b/energy-integration/fees-collector/src/config.rs index a21dc6d6b..72fa1fc70 100644 --- a/energy-integration/fees-collector/src/config.rs +++ b/energy-integration/fees-collector/src/config.rs @@ -60,13 +60,6 @@ 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; @@ -86,6 +79,7 @@ pub trait ConfigModule { #[storage_mapper("allTokens")] fn all_tokens(&self) -> SingleValueMapper>; + // Update for this storage disabled for this version of the exchange #[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 b5a37d7fb..e78ed6812 100644 --- a/energy-integration/fees-collector/src/lib.rs +++ b/energy-integration/fees-collector/src/lib.rs @@ -44,7 +44,7 @@ pub trait FeesCollector: self.energy_factory_address().set(&energy_factory_address); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[endpoint(claimRewards)] diff --git a/energy-integration/fees-collector/wasm/Cargo.lock b/energy-integration/fees-collector/wasm/Cargo.lock index d31ccf2dc..d962ee257 100644 --- a/energy-integration/fees-collector/wasm/Cargo.lock +++ b/energy-integration/fees-collector/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common-types" @@ -154,32 +154,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -189,9 +191,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -202,18 +204,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -229,27 +231,27 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -283,15 +285,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -304,6 +306,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" diff --git a/energy-integration/fees-collector/wasm/Cargo.toml b/energy-integration/fees-collector/wasm/Cargo.toml index 67ff1cdc8..6c004828a 100644 --- a/energy-integration/fees-collector/wasm/Cargo.toml +++ b/energy-integration/fees-collector/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.fees-collector] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [workspace] members = ["."] diff --git a/energy-integration/fees-collector/wasm/src/lib.rs b/energy-integration/fees-collector/wasm/src/lib.rs index 75812bfb1..77034bd4a 100644 --- a/energy-integration/fees-collector/wasm/src/lib.rs +++ b/energy-integration/fees-collector/wasm/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 39 +// Upgrade: 1 +// Endpoints: 37 // Async Callback (empty): 1 -// Total number of exported functions: 41 +// Total number of exported functions: 40 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -27,7 +26,6 @@ multiversx_sc_wasm_adapter::endpoints! { 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 diff --git a/energy-integration/governance-v2/Cargo.toml b/energy-integration/governance-v2/Cargo.toml index 1b190cd64..4ebea1437 100644 --- a/energy-integration/governance-v2/Cargo.toml +++ b/energy-integration/governance-v2/Cargo.toml @@ -12,7 +12,7 @@ path = "src/lib.rs" path = "../common-modules/energy-query" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.permissions_module] @@ -28,7 +28,7 @@ path = "../common-modules/weekly-rewards-splitting" num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" [dev-dependencies.energy-factory-mock] path = "../energy-factory-mock" diff --git a/energy-integration/governance-v2/meta/Cargo.toml b/energy-integration/governance-v2/meta/Cargo.toml index ca5a80d29..b0f3544fe 100644 --- a/energy-integration/governance-v2/meta/Cargo.toml +++ b/energy-integration/governance-v2/meta/Cargo.toml @@ -10,6 +10,6 @@ authors = ["MultiversX "] [dependencies.governance-v2] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/energy-integration/governance-v2/meta/src/main.rs b/energy-integration/governance-v2/meta/src/main.rs index 6b82b6292..f4db3e0b9 100644 --- a/energy-integration/governance-v2/meta/src/main.rs +++ b/energy-integration/governance-v2/meta/src/main.rs @@ -1,3 +1,3 @@ fn main() { - multiversx_sc_meta::cli_main::(); + multiversx_sc_meta_lib::cli_main::(); } diff --git a/energy-integration/governance-v2/src/lib.rs b/energy-integration/governance-v2/src/lib.rs index 0fcb53dca..2014b3a53 100644 --- a/energy-integration/governance-v2/src/lib.rs +++ b/energy-integration/governance-v2/src/lib.rs @@ -61,7 +61,7 @@ pub trait GovernanceV2: self.try_change_fee_token_id(fee_token); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} /// Propose a list of actions. diff --git a/energy-integration/governance-v2/tests/gov_test_setup/mod.rs b/energy-integration/governance-v2/tests/gov_test_setup/mod.rs index 489fec3b3..c1d448442 100644 --- a/energy-integration/governance-v2/tests/gov_test_setup/mod.rs +++ b/energy-integration/governance-v2/tests/gov_test_setup/mod.rs @@ -34,13 +34,6 @@ 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 { - pub token: Vec, - pub nonce: u64, - pub amount: u64, -} - pub struct GovSetup where GovBuilder: 'static + Copy + Fn() -> governance_v2::ContractObj, diff --git a/energy-integration/governance-v2/wasm/Cargo.lock b/energy-integration/governance-v2/wasm/Cargo.lock index 71cf78cfd..5853e1198 100644 --- a/energy-integration/governance-v2/wasm/Cargo.lock +++ b/energy-integration/governance-v2/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common-types" @@ -165,32 +165,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -200,9 +202,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -213,18 +215,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -240,9 +242,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -258,18 +260,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -303,15 +305,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -324,6 +326,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" diff --git a/energy-integration/governance-v2/wasm/Cargo.toml b/energy-integration/governance-v2/wasm/Cargo.toml index 02189aabe..59d23c81c 100644 --- a/energy-integration/governance-v2/wasm/Cargo.toml +++ b/energy-integration/governance-v2/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.governance-v2] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [workspace] members = ["."] diff --git a/energy-integration/governance-v2/wasm/src/lib.rs b/energy-integration/governance-v2/wasm/src/lib.rs index bb977bc97..0211fca5a 100644 --- a/energy-integration/governance-v2/wasm/src/lib.rs +++ b/energy-integration/governance-v2/wasm/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 30 +// Upgrade: 1 +// Endpoints: 29 // Async Callback (empty): 1 // Total number of exported functions: 32 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); diff --git a/farm-staking/farm-staking-proxy/Cargo.toml b/farm-staking/farm-staking-proxy/Cargo.toml index 7e986d221..34ee079f9 100644 --- a/farm-staking/farm-staking-proxy/Cargo.toml +++ b/farm-staking/farm-staking-proxy/Cargo.toml @@ -12,11 +12,11 @@ path = "src/lib.rs" hex-literal = "0.3.1" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" [dependencies.farm] path = "../../dex/farm" @@ -67,7 +67,7 @@ path = "../../energy-integration/common-modules/energy-query" num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" [dev-dependencies.farm_token] path = "../../common/modules/farm/farm_token" diff --git a/farm-staking/farm-staking-proxy/meta/Cargo.toml b/farm-staking/farm-staking-proxy/meta/Cargo.toml index 404e23810..df373e257 100644 --- a/farm-staking/farm-staking-proxy/meta/Cargo.toml +++ b/farm-staking/farm-staking-proxy/meta/Cargo.toml @@ -10,6 +10,6 @@ authors = ["MultiversX "] [dependencies.farm-staking-proxy] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/farm-staking/farm-staking-proxy/meta/src/main.rs b/farm-staking/farm-staking-proxy/meta/src/main.rs index 3d6b55dbc..ba0dc8fa3 100644 --- a/farm-staking/farm-staking-proxy/meta/src/main.rs +++ b/farm-staking/farm-staking-proxy/meta/src/main.rs @@ -1,3 +1,3 @@ fn main() { - multiversx_sc_meta::cli_main::(); + multiversx_sc_meta_lib::cli_main::(); } 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 f8048d66b..00df4c3ce 100644 --- a/farm-staking/farm-staking-proxy/src/external_contracts_interactions.rs +++ b/farm-staking/farm-staking-proxy/src/external_contracts_interactions.rs @@ -34,7 +34,7 @@ pub trait ExternalContractsInteractionsModule: let lp_farm_address = self.lp_farm_address().get(); let lp_farm_result: ClaimRewardsResultType = self .lp_farm_proxy_obj(lp_farm_address) - .claim_rewards_endpoint(orig_caller) + .claim_rewards_endpoint(OptionalValue::Some(orig_caller)) .with_esdt_transfer((lp_farm_token_id, lp_farm_token_nonce, lp_farm_token_amount)) .execute_on_dest_context(); let (new_lp_farm_tokens, lp_farm_rewards) = lp_farm_result.into_tuple(); @@ -55,7 +55,7 @@ pub trait ExternalContractsInteractionsModule: 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(orig_caller) + .exit_farm_endpoint(OptionalValue::Some(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) = exit_farm_result.into_tuple(); @@ -82,7 +82,7 @@ pub trait ExternalContractsInteractionsModule: let lp_farm_address = self.lp_farm_address().get(); self.lp_farm_proxy_obj(lp_farm_address) - .merge_farm_tokens_endpoint(orig_caller) + .merge_farm_tokens_endpoint(OptionalValue::Some(orig_caller)) .with_multi_token_transfer(additional_lp_farm_tokens) .execute_on_dest_context() } diff --git a/farm-staking/farm-staking-proxy/src/lib.rs b/farm-staking/farm-staking-proxy/src/lib.rs index bd8ef7013..7bfc66bab 100644 --- a/farm-staking/farm-staking-proxy/src/lib.rs +++ b/farm-staking/farm-staking-proxy/src/lib.rs @@ -58,6 +58,6 @@ pub trait FarmStakingProxy: self.lp_token_id().set_if_empty(&lp_token_id); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} } diff --git a/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp.rs b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp.rs index d7ee78e8d..50b62cb93 100644 --- a/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp.rs +++ b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp.rs @@ -7,13 +7,22 @@ pub mod staking_farm_with_lp_staking_contract_setup; multiversx_sc::imports!(); +use config::ConfigModule; use constants::*; use farm_staking_proxy::dual_yield_token::DualYieldTokenAttributes; use farm_staking_proxy::proxy_actions::unstake::ProxyUnstakeModule; +use farm_staking::{ + claim_only_boosted_staking_rewards::ClaimOnlyBoostedStakingRewardsModule, FarmStaking, +}; +use farm_with_locked_rewards::Farm; use multiversx_sc::codec::Empty; -use multiversx_sc_scenario::{managed_biguint, managed_token_id, rust_biguint, DebugApi}; +use multiversx_sc_scenario::{ + managed_address, managed_biguint, managed_token_id, rust_biguint, DebugApi, +}; +use pair::pair_actions::swap::SwapModule; +use simple_lock::locked_token::LockedTokenAttributes; use staking_farm_with_lp_staking_contract_interactions::*; #[test] @@ -625,3 +634,585 @@ fn test_farm_stake_proxy_merging_boosted_rewards() { ) }); } + +#[test] +fn original_caller_negative_test() { + let mut setup = FarmStakingSetup::new( + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + farm_staking::contract_obj, + farm_staking_proxy::contract_obj, + ); + + let user = setup.user_addr.clone(); + let random_user = setup.b_mock.create_user_account(&rust_biguint!(0u64)); + setup + .stake_farm_for_other_user(&user, &random_user, 1, USER_TOTAL_LP_TOKENS) + .assert_error(4, "Item not whitelisted"); + + setup + .stake_farm_for_other_user(&user, &user, 1, USER_TOTAL_LP_TOKENS) + .assert_ok(); + + setup + .b_mock + .set_block_nonce(BLOCK_NONCE_AFTER_PAIR_SETUP + 20); + setup.b_mock.set_block_epoch(20); + + setup + .claim_dual_yield_for_other_user(&user, &random_user, 1, USER_TOTAL_LP_TOKENS) + .assert_error(4, "Item not whitelisted"); + + setup + .claim_dual_yield_for_other_user(&user, &user, 1, USER_TOTAL_LP_TOKENS) + .assert_ok(); + + setup + .unstake_dual_yield_for_other_user(&user, &random_user, 2, USER_TOTAL_LP_TOKENS) + .assert_error(4, "Item not whitelisted"); + + setup + .unstake_dual_yield_for_other_user(&user, &user, 2, USER_TOTAL_LP_TOKENS) + .assert_ok(); +} + +#[test] +fn claim_for_others_positive_test() { + let mut setup = FarmStakingSetup::new( + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + farm_staking::contract_obj, + farm_staking_proxy::contract_obj, + ); + + // Boosted rewards setup + setup + .b_mock + .execute_tx( + &setup.owner_addr, + &setup.staking_farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + }, + ) + .assert_ok(); + + setup.set_lp_farm_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + let farm_amount = 50_000_000u64; + let user_address = setup.user_addr.clone(); + let temp_user = setup + .b_mock + .create_user_account(&rust_biguint!(100_000_000)); + setup.exit_lp_farm(&user_address, 1, USER_TOTAL_LP_TOKENS); + setup.b_mock.set_esdt_balance( + &setup.user_addr, + LP_TOKEN_ID, + &rust_biguint!(farm_amount * 2), + ); + setup + .b_mock + .set_esdt_balance(&temp_user, LP_TOKEN_ID, &rust_biguint!(1)); + + setup.b_mock.set_block_epoch(2); + + setup.set_user_energy(&user_address, 1_000, 2, 1); + let farm_token_nonce = setup.enter_lp_farm(&user_address, farm_amount); + + // User enters Metastaking + let first_dual_yield_token_nonce = + setup.stake_farm_lp_proxy(farm_token_nonce, farm_amount, 1, farm_amount); + setup.b_mock.execute_in_managed_environment(|| { + setup.b_mock.check_nft_balance( + &setup.user_addr, + DUAL_YIELD_TOKEN_ID, + first_dual_yield_token_nonce, + &rust_biguint!(farm_amount), + Some(&DualYieldTokenAttributes:: { + lp_farm_token_nonce: farm_token_nonce, + lp_farm_token_amount: managed_biguint!(farm_amount), + staking_farm_token_nonce: 1, + staking_farm_token_amount: managed_biguint!(farm_amount), + }), + ) + }); + // User claims rewards to get his energy registered + setup + .claim_dual_yield_for_other_user(&user_address, &user_address, 1, farm_amount) + .assert_ok(); + + // advance blocks - 10 blocks - 10 * 5_000 = 50_000 total rewards + // 37_500 base farm, 12_500 boosted yields + let boosted_rewards = 12_500u64; + setup.b_mock.set_block_nonce(110); + + // farm staking boosted rewards + let farm_staking_boosted_rewards = 10u64; + + // random tx on end of week 1, to cummulate rewards + setup.b_mock.set_block_epoch(6); + setup.set_user_energy(&user_address, 1_000, 6, 1); + setup.set_user_energy(&temp_user, 1, 6, 1); + let temp_user_farm_token_nonce = setup.enter_lp_farm(&temp_user, 1); + setup.exit_lp_farm(&temp_user, temp_user_farm_token_nonce, 1); + + setup.stake_farm(9000000, 9000000); + setup.staking_farm_unstake(3, 9000000, 0, 9000000); + + // advance 1 week + setup.b_mock.set_block_epoch(10); + setup.set_user_energy(&user_address, 1_000, 10, 1); + + // User allows claiming of boosted rewards by other users + setup + .b_mock + .execute_tx( + &user_address, + &setup.lp_farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.allow_external_claim(&managed_address!(&user_address)) + .set(true); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_tx( + &user_address, + &setup.staking_farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.allow_external_claim(&managed_address!(&user_address)) + .set(true); + }, + ) + .assert_ok(); + + // Random user claims boosted rewards for the user + let user_initial_farm_staking_tokens_balance = 990000000; + setup + .b_mock + .check_esdt_balance(&temp_user, RIDE_TOKEN_ID, &rust_biguint!(0)); + setup.b_mock.check_esdt_balance( + &user_address, + RIDE_TOKEN_ID, + &rust_biguint!(user_initial_farm_staking_tokens_balance), + ); + setup + .b_mock + .check_nft_balance::>( + &temp_user, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(0), + None, + ); + setup + .b_mock + .check_nft_balance::>( + &user_address, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(0), + None, + ); + + setup + .b_mock + .execute_tx( + &temp_user, + &setup.lp_farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.claim_boosted_rewards(OptionalValue::Some(managed_address!(&user_address))); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_tx( + &temp_user, + &setup.staking_farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.claim_boosted_rewards(OptionalValue::Some(managed_address!(&user_address))); + }, + ) + .assert_ok(); + + setup + .b_mock + .check_esdt_balance(&temp_user, RIDE_TOKEN_ID, &rust_biguint!(0)); + setup.b_mock.check_esdt_balance( + &user_address, + RIDE_TOKEN_ID, + &rust_biguint!(user_initial_farm_staking_tokens_balance + farm_staking_boosted_rewards), + ); + setup + .b_mock + .check_nft_balance::>( + &temp_user, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(0), + None, + ); + setup + .b_mock + .check_nft_balance::>( + &user_address, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(boosted_rewards), + None, + ); +} + +#[test] +fn stake_farm_through_proxy_migration_test() { + let mut setup = FarmStakingSetup::new( + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + farm_staking::contract_obj, + farm_staking_proxy::contract_obj, + ); + + let user = setup.user_addr.clone(); + let mut user_total_staking_farm_position = 0; + let mut user_total_lp_farm_position = 0; + let farm_amount = 100_000_000; + + setup.check_user_total_staking_farm_position(&user, user_total_staking_farm_position); + setup.check_user_total_lp_farm_position(&user, user_total_lp_farm_position); + let dual_yield_token_nonce1 = setup.stake_farm_lp_proxy(1, farm_amount, 1, farm_amount); + let dual_yield_token_nonce2 = setup.stake_farm_lp_proxy(1, farm_amount, 2, farm_amount); + let dual_yield_token_nonce3 = setup.stake_farm_lp_proxy(1, farm_amount, 3, farm_amount); + + setup.b_mock.execute_in_managed_environment(|| { + setup.b_mock.check_nft_balance( + &user, + DUAL_YIELD_TOKEN_ID, + dual_yield_token_nonce1, + &rust_biguint!(farm_amount), + Some(&DualYieldTokenAttributes:: { + lp_farm_token_nonce: 1, + lp_farm_token_amount: managed_biguint!(farm_amount), + staking_farm_token_nonce: 1, + staking_farm_token_amount: managed_biguint!(farm_amount), + }), + ) + }); + + user_total_staking_farm_position += farm_amount * 3; + user_total_lp_farm_position += 1001000000; + setup.check_user_total_staking_farm_position(&user, user_total_staking_farm_position); + setup.check_user_total_lp_farm_position(&user, user_total_lp_farm_position); + + // Simulate the current position as old positions + setup.set_user_total_staking_farm_position(&user, 0); + setup.set_user_total_lp_farm_position(&user, 0); + setup.set_staking_farm_migration_nonce(4); + setup.set_lp_farm_migration_nonce(2); + + user_total_staking_farm_position = 0; + user_total_lp_farm_position = 0; + setup.check_user_total_staking_farm_position(&user, user_total_staking_farm_position); + setup.check_user_total_lp_farm_position(&user, user_total_lp_farm_position); + + let dual_yield_token_payments = vec![NonceAmountPair { + nonce: dual_yield_token_nonce1, + amount: farm_amount, + }]; + + // User enters with new farming tokens + 1 old position + let enter_dual_yield_token_nonce = + setup.stake_farm_lp_proxy_multiple(1, farm_amount, dual_yield_token_payments); + + // check user staking farm tokens + setup.b_mock.execute_in_managed_environment(|| { + setup.b_mock.check_nft_balance( + &user, + DUAL_YIELD_TOKEN_ID, + enter_dual_yield_token_nonce, + &rust_biguint!(farm_amount * 2), + Some(&DualYieldTokenAttributes:: { + lp_farm_token_nonce: 2, + lp_farm_token_amount: managed_biguint!(farm_amount * 2), + staking_farm_token_nonce: 4, + staking_farm_token_amount: managed_biguint!(farm_amount * 2), + }), + ) + }); + + // check proxy SC tokens + setup.b_mock.execute_in_managed_environment(|| { + setup.b_mock.check_nft_balance::( + setup.proxy_wrapper.address_ref(), + LP_FARM_TOKEN_ID, + 2, + &rust_biguint!(farm_amount * 2), + None, //current attributes + ) + }); + + user_total_staking_farm_position += farm_amount * 2; + user_total_lp_farm_position += farm_amount * 2; + setup.check_user_total_staking_farm_position(&user, user_total_staking_farm_position); + setup.check_user_total_lp_farm_position(&user, user_total_lp_farm_position); + + // User claim with 1 old position + let claim_dual_yield_token_nonce = + setup.claim_rewards_proxy(dual_yield_token_nonce2, farm_amount, 0, 0, farm_amount); + + // check user staking farm tokens + setup.b_mock.execute_in_managed_environment(|| { + setup.b_mock.check_nft_balance( + &user, + DUAL_YIELD_TOKEN_ID, + claim_dual_yield_token_nonce, + &rust_biguint!(farm_amount), + Some(&DualYieldTokenAttributes:: { + lp_farm_token_nonce: 3, + lp_farm_token_amount: managed_biguint!(farm_amount), + staking_farm_token_nonce: 5, + staking_farm_token_amount: managed_biguint!(farm_amount), + }), + ) + }); + + user_total_staking_farm_position += farm_amount; + user_total_lp_farm_position += farm_amount; + setup.check_user_total_staking_farm_position(&user, user_total_staking_farm_position); + setup.check_user_total_lp_farm_position(&user, user_total_lp_farm_position); + + // User exits with 1 half old position + setup.unstake_proxy( + dual_yield_token_nonce3, + farm_amount / 2, + 49950000, + 0, + 0, + 49950000, + 10, + ); + + // Total positions should remain the same + setup.check_user_total_staking_farm_position(&user, user_total_staking_farm_position); + setup.check_user_total_lp_farm_position(&user, user_total_lp_farm_position); +} + +#[test] +fn total_farm_position_after_claim_and_exit_metastaking_test() { + let mut setup = FarmStakingSetup::new( + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + farm_staking::contract_obj, + farm_staking_proxy::contract_obj, + ); + + // Boosted rewards setup + setup + .b_mock + .execute_tx( + &setup.owner_addr, + &setup.staking_farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + }, + ) + .assert_ok(); + + setup.set_lp_farm_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + let farm_amount = 100_000_000u64; + let user_address = setup.user_addr.clone(); + let temp_user = setup + .b_mock + .create_user_account(&rust_biguint!(farm_amount)); + setup.exit_lp_farm(&user_address, 1, USER_TOTAL_LP_TOKENS); + setup + .b_mock + .set_esdt_balance(&setup.user_addr, LP_TOKEN_ID, &rust_biguint!(farm_amount)); + setup + .b_mock + .set_esdt_balance(&temp_user, LP_TOKEN_ID, &rust_biguint!(1)); + + setup.b_mock.set_block_epoch(2); + + setup.set_user_energy(&user_address, 1_000, 2, 1); + let farm_token_nonce = setup.enter_lp_farm(&user_address, farm_amount); + + setup.check_user_total_staking_farm_position(&user_address, 0); + + // User enters Metastaking + setup.stake_farm_lp_proxy(farm_token_nonce, farm_amount, 1, farm_amount); + + // User has his total position saved + setup.check_user_total_staking_farm_position(&user_address, farm_amount); + + // User claims rewards to get his energy registered + setup + .claim_dual_yield_for_other_user(&user_address, &user_address, 1, farm_amount) + .assert_ok(); + + // User total farm position should be the same, as no swaps happened + setup.check_user_total_staking_farm_position(&user_address, farm_amount); + + // Random swaps to change the LP ratio + setup + .b_mock + .set_esdt_balance(&temp_user, WEGLD_TOKEN_ID, &rust_biguint!(300_000_000u64)); + + setup.b_mock.set_block_nonce(700); + setup.b_mock.set_block_round(700); + setup + .b_mock + .execute_esdt_transfer( + &temp_user, + &setup.pair_wrapper, + WEGLD_TOKEN_ID, + 0, + &rust_biguint!(100_000_000u64), + |sc| { + sc.swap_tokens_fixed_input(managed_token_id!(RIDE_TOKEN_ID), managed_biguint!(1)); + }, + ) + .assert_ok(); + + setup.b_mock.set_block_nonce(800); + setup.b_mock.set_block_round(800); + setup + .b_mock + .execute_esdt_transfer( + &temp_user, + &setup.pair_wrapper, + WEGLD_TOKEN_ID, + 0, + &rust_biguint!(100_000_000u64), + |sc| { + sc.swap_tokens_fixed_input(managed_token_id!(RIDE_TOKEN_ID), managed_biguint!(1)); + }, + ) + .assert_ok(); + + setup.b_mock.set_block_nonce(1250); + setup.b_mock.set_block_round(1250); + setup + .b_mock + .execute_esdt_transfer( + &temp_user, + &setup.pair_wrapper, + WEGLD_TOKEN_ID, + 0, + &rust_biguint!(100_000_000u64), + |sc| { + sc.swap_tokens_fixed_input(managed_token_id!(RIDE_TOKEN_ID), managed_biguint!(1)); + }, + ) + .assert_ok(); + + // random tx on end of week 1, to cummulate rewards + setup.b_mock.set_block_epoch(6); + setup.set_user_energy(&user_address, 1_000, 6, 1); + setup.set_user_energy(&temp_user, 1, 6, 1); + let temp_user_farm_token_nonce = setup.enter_lp_farm(&temp_user, 1); + setup.exit_lp_farm(&temp_user, temp_user_farm_token_nonce, 1); + + setup.stake_farm(9000000, 9000000); + setup.staking_farm_unstake(3, 9000000, 0, 9000000); + + // advance 1 week + setup.b_mock.set_block_epoch(10); + setup.set_user_energy(&user_address, 1_000, 10, 1); + + // User total farm position should still be the same + setup.check_user_total_staking_farm_position(&user_address, farm_amount); + + // User claims rewards + setup + .b_mock + .check_nft_balance::>( + &user_address, + DUAL_YIELD_TOKEN_ID, + 2, + &rust_biguint!(farm_amount), + None, + ); + + setup + .claim_dual_yield_for_other_user(&user_address, &user_address, 2, farm_amount) + .assert_ok(); + + // Total farm position should be updated after claim, as a few swaps happened + let new_expected_token_amount = 92_416_406u64; + setup.check_user_total_staking_farm_position(&user_address, new_expected_token_amount); + + // User does not have any dual yield tokens with the before the claim token nonce + setup + .b_mock + .check_nft_balance::>( + &user_address, + DUAL_YIELD_TOKEN_ID, + 2, + &rust_biguint!(0), + None, + ); + + setup + .b_mock + .check_nft_balance::>( + &user_address, + DUAL_YIELD_TOKEN_ID, + 3, + &rust_biguint!(new_expected_token_amount), + None, + ); + + // User exits with partial position + let user_remaining_position = 50_000_000u64; + setup + .unstake_dual_yield_for_other_user( + &user_address, + &user_address, + 3, + new_expected_token_amount - user_remaining_position, + ) + .assert_ok(); + + setup + .b_mock + .check_nft_balance::>( + &user_address, + DUAL_YIELD_TOKEN_ID, + 3, + &rust_biguint!(user_remaining_position), + None, + ); + + setup.check_user_total_staking_farm_position(&user_address, user_remaining_position); + + // User exits with remaining position + setup + .unstake_dual_yield_for_other_user(&user_address, &user_address, 3, user_remaining_position) + .assert_ok(); + + setup + .b_mock + .check_nft_balance::>( + &user_address, + DUAL_YIELD_TOKEN_ID, + 3, + &rust_biguint!(0), + None, + ); + + // Total farm position should be 0 after full unstake + setup.check_user_total_staking_farm_position(&user_address, 0); +} diff --git a/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_interactions/mod.rs b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_interactions/mod.rs index 8860a604e..aba5f5713 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,8 @@ #![allow(deprecated)] +use config::ConfigModule; 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, @@ -10,6 +10,7 @@ use multiversx_sc::{ }; use multiversx_sc_scenario::{ managed_address, managed_biguint, managed_token_id, rust_biguint, + testing_framework::TxResult, whitebox_legacy::TxTokenTransfer, whitebox_legacy::{BlockchainStateWrapper, ContractObjWrapper}, DebugApi, @@ -112,8 +113,12 @@ where lp_farm_builder, USER_TOTAL_LP_TOKENS, ); - let staking_farm_wrapper = - setup_staking_farm(&owner_addr, &mut b_mock, staking_farm_builder); + let staking_farm_wrapper = setup_staking_farm( + &owner_addr, + energy_factory_wrapper.address_ref(), + &mut b_mock, + staking_farm_builder, + ); let proxy_wrapper = setup_proxy( &owner_addr, lp_farm_wrapper.address_ref(), @@ -519,6 +524,85 @@ where new_farm_token_nonce } + pub fn stake_farm_for_other_user( + &mut self, + caller: &Address, + original_caller: &Address, + lp_farm_token_nonce: u64, + lp_farm_token_stake_amount: u64, + ) -> TxResult { + self.b_mock.execute_esdt_transfer( + caller, + &self.proxy_wrapper, + LP_FARM_TOKEN_ID, + lp_farm_token_nonce, + &rust_biguint!(lp_farm_token_stake_amount), + |sc| { + if caller == original_caller { + sc.stake_farm_tokens(OptionalValue::None); + } else { + sc.stake_farm_tokens(OptionalValue::Some(managed_address!(original_caller))); + } + }, + ) + } + + pub fn claim_dual_yield_for_other_user( + &mut self, + caller: &Address, + original_caller: &Address, + dual_yield_token_nonce: u64, + dual_yield_token_amount: u64, + ) -> TxResult { + self.b_mock.execute_esdt_transfer( + caller, + &self.proxy_wrapper, + DUAL_YIELD_TOKEN_ID, + dual_yield_token_nonce, + &rust_biguint!(dual_yield_token_amount), + |sc| { + if caller == original_caller { + sc.claim_dual_yield_endpoint(OptionalValue::None); + } else { + sc.claim_dual_yield_endpoint(OptionalValue::Some(managed_address!( + original_caller + ))); + } + }, + ) + } + + pub fn unstake_dual_yield_for_other_user( + &mut self, + caller: &Address, + original_caller: &Address, + dual_yield_token_nonce: u64, + dual_yield_token_amount: u64, + ) -> TxResult { + self.b_mock.execute_esdt_transfer( + caller, + &self.proxy_wrapper, + DUAL_YIELD_TOKEN_ID, + dual_yield_token_nonce, + &rust_biguint!(dual_yield_token_amount), + |sc| { + if caller == original_caller { + sc.unstake_farm_tokens( + managed_biguint!(1u64), + managed_biguint!(1u64), + OptionalValue::None, + ); + } else { + sc.unstake_farm_tokens( + managed_biguint!(1u64), + managed_biguint!(1u64), + OptionalValue::Some(managed_address!(original_caller)), + ); + } + }, + ) + } + pub fn set_user_energy( &mut self, user: &Address, @@ -557,4 +641,96 @@ where ) .assert_ok(); } + + pub fn set_staking_farm_migration_nonce(&mut self, migration_nonce: u64) { + self.b_mock + .execute_tx( + &self.owner_addr, + &self.staking_farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.farm_position_migration_nonce().set(migration_nonce); + }, + ) + .assert_ok(); + } + + pub fn set_lp_farm_migration_nonce(&mut self, migration_nonce: u64) { + self.b_mock + .execute_tx( + &self.owner_addr, + &self.lp_farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.farm_position_migration_nonce().set(migration_nonce); + }, + ) + .assert_ok(); + } + + pub fn set_user_total_staking_farm_position( + &mut self, + user_addr: &Address, + new_farm_position: u64, + ) { + self.b_mock + .execute_tx( + &self.owner_addr, + &self.staking_farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.user_total_farm_position(&managed_address!(user_addr)) + .set(managed_biguint!(new_farm_position)); + }, + ) + .assert_ok(); + } + + pub fn set_user_total_lp_farm_position(&mut self, user_addr: &Address, new_farm_position: u64) { + self.b_mock + .execute_tx( + &self.owner_addr, + &self.lp_farm_wrapper, + &rust_biguint!(0), + |sc| { + sc.user_total_farm_position(&managed_address!(user_addr)) + .set(managed_biguint!(new_farm_position)); + }, + ) + .assert_ok(); + } + + pub fn check_user_total_staking_farm_position( + &mut self, + user_addr: &Address, + expected_amount: u64, + ) { + self.b_mock + .execute_query(&self.staking_farm_wrapper, |sc| { + let user_total_farm_position_mapper = + sc.user_total_farm_position(&managed_address!(user_addr)); + if expected_amount > 0 && !user_total_farm_position_mapper.is_empty() { + assert_eq!( + managed_biguint!(expected_amount), + user_total_farm_position_mapper.get() + ); + } + }) + .assert_ok(); + } + + pub fn check_user_total_lp_farm_position(&mut self, user_addr: &Address, expected_amount: u64) { + self.b_mock + .execute_query(&self.lp_farm_wrapper, |sc| { + let user_total_farm_position_mapper = + sc.user_total_farm_position(&managed_address!(user_addr)); + if expected_amount > 0 && !user_total_farm_position_mapper.is_empty() { + assert_eq!( + managed_biguint!(expected_amount), + user_total_farm_position_mapper.get() + ); + } + }) + .assert_ok(); + } } diff --git a/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_setup/mod.rs b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_setup/mod.rs index 2c67d2714..81bb78dbd 100644 --- a/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_setup/mod.rs +++ b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_setup/mod.rs @@ -1,5 +1,7 @@ #![allow(deprecated)] +use energy_query::EnergyQueryModule; +use farm_boosted_yields::boosted_yields_factors::BoostedYieldsFactorsModule; use multiversx_sc::storage::mappers::StorageTokenWrapper; use multiversx_sc::types::{Address, EsdtLocalRole, ManagedAddress, MultiValueEncoded}; use multiversx_sc_scenario::{ @@ -24,6 +26,7 @@ use crate::constants::*; pub fn setup_staking_farm( owner_addr: &Address, + energy_factory_address: &Address, b_mock: &mut BlockchainStateWrapper, builder: StakingContractObjBuilder, ) -> ContractObjWrapper, StakingContractObjBuilder> @@ -49,6 +52,8 @@ where MultiValueEncoded::new(), ); + sc.energy_factory_address() + .set(managed_address!(energy_factory_address)); sc.farm_token() .set_token_id(managed_token_id!(STAKING_FARM_TOKEN_ID)); @@ -62,6 +67,18 @@ where }) .assert_ok(); + b_mock + .execute_tx(owner_addr, &farm_staking_wrapper, &rust_zero, |sc| { + sc.set_boosted_yields_factors( + managed_biguint!(USER_REWARDS_BASE_CONST), + managed_biguint!(USER_REWARDS_ENERGY_CONST), + managed_biguint!(USER_REWARDS_FARM_CONST), + managed_biguint!(MIN_ENERGY_AMOUNT_FOR_BOOSTED_YIELDS), + managed_biguint!(MIN_FARM_AMOUNT_FOR_BOOSTED_YIELDS), + ); + }) + .assert_ok(); + b_mock.set_esdt_balance( farm_staking_wrapper.address_ref(), STAKING_REWARD_TOKEN_ID, diff --git a/farm-staking/farm-staking-proxy/wasm/Cargo.lock b/farm-staking/farm-staking-proxy/wasm/Cargo.lock index feded38ab..1f79bbe16 100644 --- a/farm-staking/farm-staking-proxy/wasm/Cargo.lock +++ b/farm-staking/farm-staking-proxy/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common-types" @@ -76,9 +76,9 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "endian-type" @@ -376,32 +376,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal 0.4.1", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -411,9 +413,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -424,18 +426,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -451,9 +453,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -493,18 +495,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -553,15 +555,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -591,6 +593,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" diff --git a/farm-staking/farm-staking-proxy/wasm/Cargo.toml b/farm-staking/farm-staking-proxy/wasm/Cargo.toml index b95744497..dc496fd7e 100644 --- a/farm-staking/farm-staking-proxy/wasm/Cargo.toml +++ b/farm-staking/farm-staking-proxy/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.farm-staking-proxy] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [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 ee8a50b10..3f9abd0a4 100644 --- a/farm-staking/farm-staking-proxy/wasm/src/lib.rs +++ b/farm-staking/farm-staking-proxy/wasm/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 18 +// Upgrade: 1 +// Endpoints: 17 // Async Callback: 1 // Total number of exported functions: 20 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); diff --git a/farm-staking/farm-staking/Cargo.toml b/farm-staking/farm-staking/Cargo.toml index c4db81ca1..8f1817a89 100644 --- a/farm-staking/farm-staking/Cargo.toml +++ b/farm-staking/farm-staking/Cargo.toml @@ -78,14 +78,14 @@ path = "../../common/common_structs" path = "../../common/common_errors" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" diff --git a/farm-staking/farm-staking/meta/Cargo.toml b/farm-staking/farm-staking/meta/Cargo.toml index 20d07fb79..247b430c3 100644 --- a/farm-staking/farm-staking/meta/Cargo.toml +++ b/farm-staking/farm-staking/meta/Cargo.toml @@ -8,6 +8,6 @@ publish = false [dependencies.farm-staking] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/farm-staking/farm-staking/meta/src/main.rs b/farm-staking/farm-staking/meta/src/main.rs index de7773d55..b7990d697 100644 --- a/farm-staking/farm-staking/meta/src/main.rs +++ b/farm-staking/farm-staking/meta/src/main.rs @@ -1,3 +1,3 @@ fn main() { - multiversx_sc_meta::cli_main::(); + multiversx_sc_meta_lib::cli_main::(); } diff --git a/farm-staking/farm-staking/src/base_impl_wrapper.rs b/farm-staking/farm-staking/src/base_impl_wrapper.rs index 2b671677f..21d98f5bc 100644 --- a/farm-staking/farm-staking/src/base_impl_wrapper.rs +++ b/farm-staking/farm-staking/src/base_impl_wrapper.rs @@ -9,15 +9,29 @@ use multiversx_sc_modules::transfer_role_proxy::PaymentsVec; use crate::token_attributes::StakingFarmTokenAttributes; -pub trait FarmStakingTraits = +pub trait FarmStakingTraits: crate::custom_rewards::CustomRewardsModule + + rewards::RewardsModule + + config::ConfigModule + + farm_token::FarmTokenModule + + pausable::PausableModule + + permissions_module::PermissionsModule + + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + + farm_boosted_yields::FarmBoostedYieldsModule +{ +} + +impl FarmStakingTraits for T where + T: crate::custom_rewards::CustomRewardsModule + rewards::RewardsModule + config::ConfigModule + farm_token::FarmTokenModule + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule - + farm_boosted_yields::FarmBoostedYieldsModule; + + farm_boosted_yields::FarmBoostedYieldsModule +{ +} pub struct FarmStakingWrapper where @@ -48,15 +62,9 @@ where sc: &::FarmSc, caller: &ManagedAddress<<::FarmSc as ContractBase>::Api>, ) -> BigUint<<::FarmSc as ContractBase>::Api> { - 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(); + let user_total_farm_position = sc.user_total_farm_position(caller).get(); - if user_farm_position > 0 { - boosted_rewards = sc.claim_boosted_yields_rewards(caller, user_farm_position); - } - - boosted_rewards + sc.claim_boosted_yields_rewards(caller, user_total_farm_position) } } @@ -214,10 +222,8 @@ where 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); + .update(|total_farm_position| *total_farm_position += increase_farm_position_amount); } fn decrease_user_farm_position( @@ -232,13 +238,15 @@ where 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(); - } - }); + let user_total_farm_position_mapper = + sc.user_total_farm_position(&token_attributes.original_owner); + let mut user_total_farm_position = user_total_farm_position_mapper.get(); + + if user_total_farm_position > farm_position.amount { + user_total_farm_position -= &farm_position.amount; + user_total_farm_position_mapper.set(user_total_farm_position); + } else { + user_total_farm_position_mapper.clear(); + } } } 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 b13ccc62d..c5b903e0b 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 @@ -1,3 +1,6 @@ +use contexts::storage_cache::StorageCache; +use farm_base_impl::base_traits_impl::FarmContract; + use crate::base_impl_wrapper::FarmStakingWrapper; multiversx_sc::imports!(); @@ -16,6 +19,7 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: + weekly_rewards_splitting::global_info::WeeklyRewardsGlobalInfo + weekly_rewards_splitting::locked_token_buckets::WeeklyRewardsLockedTokenBucketsModule + weekly_rewards_splitting::update_claim_progress_energy::UpdateClaimProgressEnergyModule + + farm_base_impl::base_farm_validation::BaseFarmValidationModule + energy_query::EnergyQueryModule + token_send::TokenSendModule + events::EventsModule @@ -31,18 +35,28 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: 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, + self.allow_external_claim(user).get(), "Cannot claim rewards for this address" ); } + require!( + !self.user_total_farm_position(user).is_empty(), + "User total farm position is empty!" + ); + + let mut storage_cache = StorageCache::new(self); + self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); + FarmStakingWrapper::::generate_aggregated_rewards(self, &mut storage_cache); + let boosted_rewards = self.claim_only_boosted_payment(user); let boosted_rewards_payment = EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards); + self.set_farm_supply_for_current_week(&storage_cache.farm_token_supply); + self.send_payment_non_zero(user, &boosted_rewards_payment); boosted_rewards_payment @@ -62,10 +76,8 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: } 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); + .update(|total_farm_position| *total_farm_position += &migrated_amount); } migrated_amount @@ -75,10 +87,16 @@ pub trait ClaimOnlyBoostedStakingRewardsModule: 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; - }); + + let user_total_farm_position_mapper = self.user_total_farm_position(caller); + let mut user_total_farm_position = user_total_farm_position_mapper.get(); + + if user_total_farm_position > migrated_amount { + user_total_farm_position -= &migrated_amount; + user_total_farm_position_mapper.set(user_total_farm_position); + } else { + user_total_farm_position_mapper.clear(); + } } // Cannot import the one from farm, as the Wrapper struct has different dependencies diff --git a/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs b/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs index e3d0b1dc4..e2ba49fe4 100644 --- a/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs +++ b/farm-staking/farm-staking/src/claim_stake_farm_rewards.rs @@ -74,12 +74,18 @@ pub trait ClaimStakeFarmRewardsModule: claim_result.storage_cache.farm_token_supply -= &virtual_farm_token.payment.amount; claim_result.storage_cache.farm_token_supply += &new_amount; + self.user_total_farm_position(&original_caller) + .update(|total_farm_position| { + *total_farm_position -= &virtual_farm_token.payment.amount; + *total_farm_position += &new_amount; + }); + virtual_farm_token.payment.amount = new_amount.clone(); virtual_farm_token.attributes.current_farm_amount = new_amount; - - self.set_farm_supply_for_current_week(&claim_result.storage_cache.farm_token_supply); } + self.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( diff --git a/farm-staking/farm-staking/src/lib.rs b/farm-staking/farm-staking/src/lib.rs index e517d2aa6..f783c7831 100644 --- a/farm-staking/farm-staking/src/lib.rs +++ b/farm-staking/farm-staking/src/lib.rs @@ -1,13 +1,12 @@ #![no_std] #![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_functions::DoubleMultiPayment, MAX_PERCENT}; use farm_base_impl::base_traits_impl::FarmContract; use fixed_supply_token::FixedSupplyToken; use token_attributes::StakingFarmTokenAttributes; @@ -97,7 +96,7 @@ pub trait FarmStaking: self.try_set_farm_position_migration_nonce(farm_token_mapper); } - #[endpoint] + #[upgrade] fn upgrade(&self) { let current_epoch = self.blockchain().get_block_epoch(); self.first_week_start_epoch().set_if_empty(current_epoch); @@ -117,19 +116,48 @@ pub trait FarmStaking: let boosted_rewards_payment = EsdtTokenPayment::new(self.reward_token_id().get(), 0, boosted_rewards); - let payments = self.get_non_empty_payments(); - let token_mapper = self.farm_token(); - let output_attributes: StakingFarmTokenAttributes = - self.merge_from_payments_and_burn(payments, &token_mapper); - let new_token_amount = output_attributes.get_total_supply(); + let merged_farm_token = self.merge_and_update_farm_tokens(caller.clone()); - let merged_farm_token = token_mapper.nft_create(new_token_amount, &output_attributes); self.send_payment_non_zero(&caller, &merged_farm_token); self.send_payment_non_zero(&caller, &boosted_rewards_payment); (merged_farm_token, boosted_rewards_payment).into() } + fn merge_and_update_farm_tokens(&self, orig_caller: ManagedAddress) -> EsdtTokenPayment { + let mut output_attributes = + self.merge_farm_tokens::>(&orig_caller); + output_attributes.original_owner = orig_caller; + + let new_token_amount = output_attributes.get_total_supply(); + self.farm_token() + .nft_create(new_token_amount, &output_attributes) + } + + fn merge_farm_tokens>( + &self, + orig_caller: &ManagedAddress, + ) -> FC::AttributesType { + let payments = self.get_non_empty_payments(); + let token_mapper = self.farm_token(); + token_mapper.require_all_same_token(&payments); + + FC::check_and_update_user_farm_position(self, orig_caller, &payments); + + self.merge_from_payments_and_burn(payments, &token_mapper) + } + + #[endpoint(setBoostedYieldsRewardsPercentage)] + fn set_boosted_yields_rewards_percentage(&self, percentage: u64) { + self.require_caller_has_admin_permissions(); + require!(percentage <= MAX_PERCENT, "Invalid percentage"); + + let mut storage_cache = StorageCache::new(self); + FarmStakingWrapper::::generate_aggregated_rewards(self, &mut storage_cache); + + self.boosted_yields_rewards_percentage().set(percentage); + } + #[view(calculateRewardsForGivenPosition)] fn calculate_rewards_for_given_position( &self, diff --git a/farm-staking/farm-staking/src/token_attributes.rs b/farm-staking/farm-staking/src/token_attributes.rs index 54074a958..59f8c6326 100644 --- a/farm-staking/farm-staking/src/token_attributes.rs +++ b/farm-staking/farm-staking/src/token_attributes.rs @@ -108,8 +108,8 @@ impl FixedSupplyToken for StakingFarmTokenAttributes { impl Mergeable for StakingFarmTokenAttributes { #[inline] - fn can_merge_with(&self, other: &Self) -> bool { - self.original_owner == other.original_owner + fn can_merge_with(&self, _other: &Self) -> bool { + true } fn merge_with(&mut self, other: Self) { diff --git a/farm-staking/farm-staking/src/unbond_farm.rs b/farm-staking/farm-staking/src/unbond_farm.rs index 7e85a2a2c..0e661616e 100644 --- a/farm-staking/farm-staking/src/unbond_farm.rs +++ b/farm-staking/farm-staking/src/unbond_farm.rs @@ -16,7 +16,6 @@ pub trait UnbondFarmModule: + pausable::PausableModule + permissions_module::PermissionsModule + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule - + farm_base_impl::base_farm_init::BaseFarmInitModule + farm_base_impl::base_farm_validation::BaseFarmValidationModule + utils::UtilsModule + farm_boosted_yields::FarmBoostedYieldsModule diff --git a/farm-staking/farm-staking/tests/farm_staking_energy_test.rs b/farm-staking/farm-staking/tests/farm_staking_energy_test.rs index 230d84747..a4046f03e 100644 --- a/farm-staking/farm-staking/tests/farm_staking_energy_test.rs +++ b/farm-staking/farm-staking/tests/farm_staking_energy_test.rs @@ -1,13 +1,20 @@ #![allow(deprecated)] pub mod farm_staking_setup; +use config::ConfigModule; use farm_staking::{ - claim_stake_farm_rewards::ClaimStakeFarmRewardsModule, stake_farm::StakeFarmModule, + claim_only_boosted_staking_rewards::ClaimOnlyBoostedStakingRewardsModule, + claim_stake_farm_rewards::ClaimStakeFarmRewardsModule, + stake_farm::StakeFarmModule, + token_attributes::{StakingFarmTokenAttributes, UnbondSftAttributes}, unstake_farm::UnstakeFarmModule, + FarmStaking, }; use farm_staking_setup::*; use multiversx_sc::codec::multi_types::OptionalValue; -use multiversx_sc_scenario::{rust_biguint, DebugApi}; +use multiversx_sc_scenario::{ + managed_address, managed_biguint, rust_biguint, testing_framework::TxTokenTransfer, DebugApi, +}; #[test] fn farm_staking_with_energy_setup_test() { @@ -24,12 +31,21 @@ fn farm_staking_boosted_rewards_no_energy_test() { let mut fs_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = fs_setup.user_address.clone(); + fs_setup.set_boosted_yields_factors(); fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); let farm_in_amount = 100_000_000; let expected_farm_token_nonce = 1; - fs_setup.stake_farm(farm_in_amount, &[], expected_farm_token_nonce, 0, 0); + fs_setup.stake_farm( + &user_address, + farm_in_amount, + &[], + expected_farm_token_nonce, + 0, + 0, + ); fs_setup.check_farm_token_supply(farm_in_amount); fs_setup.set_block_epoch(5); @@ -43,6 +59,7 @@ fn farm_staking_boosted_rewards_no_energy_test() { rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out); let expected_reward_per_share = 300_000; // from 400_000 -> 300_000 fs_setup.claim_rewards( + &user_address, farm_in_amount, expected_farm_token_nonce, expected_reward_token_out, @@ -54,26 +71,77 @@ fn farm_staking_boosted_rewards_no_energy_test() { fs_setup.check_farm_token_supply(farm_in_amount); } +#[test] +fn farm_staking_other_user_enter_negative_test() { + DebugApi::dummy(); + let mut fs_setup = + FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + + let user_address = fs_setup.user_address.clone(); + let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); + + fs_setup.set_boosted_yields_factors(); + fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + + let farm_in_amount = 100_000_000; + fs_setup + .stake_farm_for_other_user(&rand_user, &user_address, farm_in_amount, &[]) + .assert_error(4, "Item not whitelisted"); + + let expected_farm_token_nonce = 1; + fs_setup.stake_farm( + &user_address, + farm_in_amount, + &[], + expected_farm_token_nonce, + 0, + 0, + ); + + fs_setup + .claim_farm_for_other_user( + &rand_user, + &user_address, + expected_farm_token_nonce, + farm_in_amount, + ) + .assert_error(4, "Item not whitelisted"); + + fs_setup + .unstake_farm_for_other_user( + &rand_user, + &user_address, + expected_farm_token_nonce, + farm_in_amount, + ) + .assert_error(4, "Item not whitelisted"); +} + #[test] fn farm_staking_boosted_rewards_with_energy_test() { DebugApi::dummy(); let mut fs_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = fs_setup.user_address.clone(); + let user_address2 = fs_setup.user_address2.clone(); + fs_setup.set_boosted_yields_factors(); fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); - fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 0, 10); + fs_setup.set_user_energy(&user_address, 9_800, 0, 100); + fs_setup.set_user_energy(&user_address2, 4_900, 0, 350); let farm_in_amount = 100_000_000; - fs_setup.stake_farm(farm_in_amount, &[], 1, 0, 0); - fs_setup.check_farm_token_supply(farm_in_amount); + fs_setup.stake_farm(&user_address, farm_in_amount, &[], 1, 0, 0); + fs_setup.stake_farm(&user_address2, farm_in_amount, &[], 2, 0, 0); + fs_setup.check_farm_token_supply(farm_in_amount * 2); // claim to get energy registered fs_setup .b_mock .execute_esdt_transfer( - &fs_setup.user_address, + &user_address, &fs_setup.farm_wrapper, FARM_TOKEN_ID, 1, @@ -84,10 +152,21 @@ fn farm_staking_boosted_rewards_with_energy_test() { ) .assert_ok(); - fs_setup.set_block_nonce(10); - - // random user tx to collect rewards + fs_setup + .b_mock + .execute_esdt_transfer( + &user_address2, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 2, + &rust_biguint!(farm_in_amount), + |sc| { + let _ = sc.claim_rewards(OptionalValue::None); + }, + ) + .assert_ok(); + // random user tx to collect rewards - week 1 let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); fs_setup.b_mock.set_esdt_balance( &rand_user, @@ -95,8 +174,9 @@ fn farm_staking_boosted_rewards_with_energy_test() { &rust_biguint!(USER_TOTAL_RIDE_TOKENS), ); - fs_setup.set_user_energy(&rand_user, 1, 5, 1); - fs_setup.set_block_epoch(5); + fs_setup.set_user_energy(&rand_user, 1, 6, 1); + fs_setup.set_block_epoch(6); + fs_setup.set_block_nonce(10); fs_setup .b_mock @@ -118,7 +198,7 @@ fn farm_staking_boosted_rewards_with_energy_test() { &rand_user, &fs_setup.farm_wrapper, FARM_TOKEN_ID, - 3, + 5, &rust_biguint!(10), |sc| { let _ = sc.unstake_farm(OptionalValue::None); @@ -126,51 +206,164 @@ fn farm_staking_boosted_rewards_with_energy_test() { ) .assert_ok(); - fs_setup.set_block_epoch(8); + // random user tx to collect rewards - week 2 + fs_setup.set_user_energy(&rand_user, 1, 13, 1); + fs_setup.set_block_epoch(13); + fs_setup.set_block_nonce(20); - fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 8, 10); + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); - // value taken from the "test_unstake_farm" test - // originally, it was 40, but since 25% of the rewards go to boosted yields - // rewards are now only 3/4 * 40 = 30 - // - // 10 reserved for boosted yields -> 30 + 10 - let expected_reward_token_out = 40; - let expected_farming_token_balance = - rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out); - let expected_reward_per_share = 300_000; // from 400_000 -> 300_000 + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 7, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + // random user tx to collect rewards - week 3 + fs_setup.set_user_energy(&rand_user, 1, 20, 1); + fs_setup.set_block_epoch(20); + fs_setup.set_block_nonce(30); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 9, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + // random user tx to collect rewards - week 4 + fs_setup.set_user_energy(&rand_user, 1, 27, 1); + fs_setup.set_block_epoch(27); + fs_setup.set_block_nonce(40); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 11, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(28); + fs_setup.update_energy_for_user(&user_address); + fs_setup.update_energy_for_user(&user_address2); + + let base_rewards = 136; + let boosted_rewards_user = 61; + let boosted_rewards_user2 = 15; // ~ 1/4 rewards than user1 (half the energy for only 2 weeks) + let expected_reward_token_out_user = base_rewards + boosted_rewards_user; + let expected_reward_token_out_user2 = base_rewards + boosted_rewards_user2; + let expected_farming_token_balance_user = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out_user); + let expected_farming_token_balance_user2 = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out_user2); + let expected_reward_per_share = 1_360_000; fs_setup.claim_rewards( + &user_address, farm_in_amount, - 2, - expected_reward_token_out, - &expected_farming_token_balance, - &expected_farming_token_balance, - 5, + 3, + expected_reward_token_out_user, + &expected_farming_token_balance_user, + &expected_farming_token_balance_user, + 13, expected_reward_per_share, ); - fs_setup.check_farm_token_supply(farm_in_amount); + fs_setup.claim_rewards( + &user_address2, + farm_in_amount, + 4, + expected_reward_token_out_user2, + &expected_farming_token_balance_user2, + &expected_farming_token_balance_user2, + 14, + expected_reward_per_share, + ); + fs_setup.check_farm_token_supply(farm_in_amount * 2); } #[test] -fn farm_staking_claim_boosted_rewards_for_user_test() { +fn farm_staking_partial_position_handling_test() { DebugApi::dummy(); let mut fs_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = fs_setup.user_address.clone(); + fs_setup.set_boosted_yields_factors(); fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); - fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 0, 10); + fs_setup.set_user_energy(&user_address, 10_000, 0, 10); let farm_in_amount = 100_000_000; - fs_setup.stake_farm(farm_in_amount, &[], 1, 0, 0); + fs_setup.stake_farm(&user_address, farm_in_amount, &[], 1, 0, 0); fs_setup.check_farm_token_supply(farm_in_amount); // claim to get energy registered fs_setup .b_mock .execute_esdt_transfer( - &fs_setup.user_address, + &user_address, &fs_setup.farm_wrapper, FARM_TOKEN_ID, 1, @@ -184,6 +377,7 @@ fn farm_staking_claim_boosted_rewards_for_user_test() { fs_setup.set_block_nonce(10); // random user tx to collect rewards + let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); fs_setup.b_mock.set_esdt_balance( &rand_user, @@ -224,43 +418,108 @@ fn farm_staking_claim_boosted_rewards_for_user_test() { fs_setup.set_block_epoch(8); - fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 8, 10); + fs_setup.set_user_energy(&user_address, 10_000, 8, 10); - // value taken from the "test_unstake_farm" test - // originally, it was 40, but since 25% of the rewards go to boosted yields - // rewards are now only 3/4 * 40 = 30 - // - // 10 reserved for boosted yields -> 30 + 10 - let expected_boosted_reward_token_out = 10; - let expected_farming_token_balance = - rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_boosted_reward_token_out); + let full_position_base_rewards = 30; + let boosted_rewards_user = 10; + let half_position_expected_rewards = full_position_base_rewards / 2 + boosted_rewards_user; + let expected_farming_token_balance_user = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + half_position_expected_rewards); - // Random_user claim boosted rewards for user - fs_setup.allow_external_claim_rewards(&fs_setup.user_address.clone()); - fs_setup.claim_boosted_rewards_for_user( - &fs_setup.user_address.clone(), + fs_setup.unstake_farm( + &user_address, + farm_in_amount / 2, + 2, + half_position_expected_rewards, + &expected_farming_token_balance_user, + &expected_farming_token_balance_user, + 5, + farm_in_amount / 2, + &UnbondSftAttributes { + unlock_epoch: 8 + MIN_UNBOND_EPOCHS, + }, + ); + + fs_setup.set_block_nonce(20); + + // random user tx to collect rewards + + let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); + fs_setup.b_mock.set_esdt_balance( &rand_user, - expected_boosted_reward_token_out, - &expected_farming_token_balance, + FARMING_TOKEN_ID, + &rust_biguint!(USER_TOTAL_RIDE_TOKENS), + ); + + fs_setup.set_user_energy(&rand_user, 1, 12, 1); + fs_setup.set_block_epoch(12); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 6, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(15); + + fs_setup.set_user_energy(&user_address, 10_000, 15, 10); + + let expected_rewards_amount = full_position_base_rewards / 2 * 2; // half remaining position * 2 times the 10 block period + let half_position_boosted_rewards = boosted_rewards_user / 2; + let remaining_expected_rewards = expected_rewards_amount + half_position_boosted_rewards; + let final_expected_farming_token_balance_user = + expected_farming_token_balance_user + rust_biguint!(remaining_expected_rewards); + let expected_reward_per_share = 600_000; + fs_setup.claim_rewards( + &user_address, + farm_in_amount / 2, + 2, + remaining_expected_rewards, + &final_expected_farming_token_balance_user, + &final_expected_farming_token_balance_user, + 8, + expected_reward_per_share, ); - fs_setup.check_farm_token_supply(farm_in_amount); } #[test] -fn farm_staking_full_position_boosted_rewards_test() { +fn farm_staking_claim_boosted_rewards_for_user_test() { DebugApi::dummy(); let mut fs_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = fs_setup.user_address.clone(); + fs_setup.set_boosted_yields_factors(); fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 0, 10); - let farm_in_amount = 50_000_000; - fs_setup.stake_farm(farm_in_amount, &[], 1, 0, 0); - fs_setup.stake_farm(farm_in_amount, &[], 2, 0, 0); - fs_setup.check_farm_token_supply(farm_in_amount * 2); + let farm_in_amount = 100_000_000; + fs_setup.stake_farm(&user_address, farm_in_amount, &[], 1, 0, 0); + fs_setup.check_farm_token_supply(farm_in_amount); // claim to get energy registered fs_setup @@ -280,8 +539,8 @@ fn farm_staking_full_position_boosted_rewards_test() { fs_setup.set_block_nonce(10); // random user tx to collect rewards - let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); + let user_address = fs_setup.user_address.clone(); fs_setup.b_mock.set_esdt_balance( &rand_user, FARMING_TOKEN_ID, @@ -311,7 +570,7 @@ fn farm_staking_full_position_boosted_rewards_test() { &rand_user, &fs_setup.farm_wrapper, FARM_TOKEN_ID, - 4, + 3, &rust_biguint!(10), |sc| { let _ = sc.unstake_farm(OptionalValue::None); @@ -321,21 +580,137 @@ fn farm_staking_full_position_boosted_rewards_test() { fs_setup.set_block_epoch(8); - fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 8, 10); + fs_setup.set_user_energy(&user_address, 10_000, 8, 10); - let expected_base_rewards = 15; - let expected_boosted_rewards = 10; - let mut expected_farming_token_balance = rust_biguint!( - USER_TOTAL_RIDE_TOKENS - (farm_in_amount * 2) - + expected_base_rewards - + expected_boosted_rewards - ); - let expected_reward_per_share = 300_000; // from 400_000 -> 300_000 + // value taken from the "test_unstake_farm" test + // originally, it was 40, but since 25% of the rewards go to boosted yields + // rewards are now only 3/4 * 40 = 30 + // + // 10 reserved for boosted yields -> 30 + 10 + let expected_boosted_reward_token_out = 10; + let expected_farming_token_balance = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_boosted_reward_token_out); - // Should receive half base rewards and full boosted rewards - fs_setup.claim_rewards( - farm_in_amount, - 2, + // Random_user claim boosted rewards for user + let rand_user_reward_balance = 4_999_999_990u64; + fs_setup.b_mock.check_esdt_balance( + &rand_user, + REWARD_TOKEN_ID, + &rust_biguint!(rand_user_reward_balance), + ); + fs_setup.allow_external_claim_rewards(&user_address, true); + fs_setup.claim_boosted_rewards_for_user( + &user_address, + &rand_user, + expected_boosted_reward_token_out, + &expected_farming_token_balance, + ); + fs_setup.b_mock.check_esdt_balance( + &rand_user, + REWARD_TOKEN_ID, + &rust_biguint!(rand_user_reward_balance), + ); + + fs_setup.check_farm_token_supply(farm_in_amount); + + // User removes the allowance of claim boosted rewards + fs_setup.allow_external_claim_rewards(&user_address, false); + fs_setup.claim_boosted_rewards_for_user_expect_error(&user_address, &rand_user); +} + +#[test] +fn farm_staking_full_position_boosted_rewards_test() { + DebugApi::dummy(); + let mut fs_setup = + FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + + let user_address = fs_setup.user_address.clone(); + + fs_setup.set_boosted_yields_factors(); + fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + + fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 0, 10); + + let farm_in_amount = 50_000_000; + fs_setup.stake_farm(&user_address, farm_in_amount, &[], 1, 0, 0); + fs_setup.stake_farm(&user_address, farm_in_amount, &[], 2, 0, 0); + fs_setup.check_farm_token_supply(farm_in_amount * 2); + + // claim to get energy registered + fs_setup + .b_mock + .execute_esdt_transfer( + &fs_setup.user_address, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 1, + &rust_biguint!(farm_in_amount), + |sc| { + let _ = sc.claim_rewards(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_nonce(10); + + // random user tx to collect rewards + + let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); + fs_setup.b_mock.set_esdt_balance( + &rand_user, + FARMING_TOKEN_ID, + &rust_biguint!(USER_TOTAL_RIDE_TOKENS), + ); + + fs_setup.set_user_energy(&rand_user, 1, 5, 1); + fs_setup.set_block_epoch(5); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 4, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(8); + + fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 8, 10); + + let expected_base_rewards = 15; + let expected_boosted_rewards = 10; + let mut expected_farming_token_balance = rust_biguint!( + USER_TOTAL_RIDE_TOKENS - (farm_in_amount * 2) + + expected_base_rewards + + expected_boosted_rewards + ); + let expected_reward_per_share = 300_000; // from 400_000 -> 300_000 + + // Should receive half base rewards and full boosted rewards + fs_setup.claim_rewards( + &user_address, + farm_in_amount, + 2, expected_base_rewards + expected_boosted_rewards, &expected_farming_token_balance, &expected_farming_token_balance, @@ -346,6 +721,7 @@ fn farm_staking_full_position_boosted_rewards_test() { // Should receive half base rewards and no boosted rewards expected_farming_token_balance += expected_base_rewards; fs_setup.claim_rewards( + &user_address, farm_in_amount, 3, expected_base_rewards, @@ -356,3 +732,988 @@ fn farm_staking_full_position_boosted_rewards_test() { ); fs_setup.check_farm_token_supply(farm_in_amount * 2); } + +#[test] +fn position_owner_change_test() { + DebugApi::dummy(); + let mut fs_setup = + FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + + let first_user = fs_setup.user_address.clone(); + let second_user = fs_setup.user_address2.clone(); + + fs_setup.set_boosted_yields_factors(); + fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + + fs_setup.set_user_energy(&first_user, 10_000, 0, 10); + fs_setup.set_user_energy(&second_user, 5_000, 0, 10); + + let farm_in_amount = 10_000_000; + let half_farm_in_amount = farm_in_amount / 2; + fs_setup.stake_farm(&first_user, farm_in_amount, &[], 1, 0, 0); + fs_setup.stake_farm(&first_user, farm_in_amount, &[], 2, 0, 0); + fs_setup.stake_farm(&first_user, farm_in_amount, &[], 3, 0, 0); + fs_setup.stake_farm(&first_user, farm_in_amount, &[], 4, 0, 0); + fs_setup.stake_farm(&first_user, farm_in_amount, &[], 5, 0, 0); + + fs_setup.check_farm_token_supply(farm_in_amount * 5); + + fs_setup.check_user_total_farm_position(&first_user, farm_in_amount * 5); + fs_setup.check_user_total_farm_position(&second_user, 0); + + // First user transfers 5 position to second user + fs_setup.send_position(&first_user, &second_user, 1, farm_in_amount, 0); + fs_setup.send_position(&first_user, &second_user, 2, farm_in_amount, 0); + fs_setup.send_position(&first_user, &second_user, 3, farm_in_amount, 0); + fs_setup.send_position(&first_user, &second_user, 4, farm_in_amount, 0); + fs_setup.send_position(&first_user, &second_user, 5, farm_in_amount, 0); + + // Total farm position unchanged as users only transfered the farm positions + fs_setup.check_user_total_farm_position(&first_user, half_farm_in_amount * 10); + fs_setup.check_user_total_farm_position(&second_user, 0); + + let additional_farm_tokens = [TxTokenTransfer { + token_identifier: FARM_TOKEN_ID.to_vec(), + nonce: 1, + value: rust_biguint!(half_farm_in_amount), + }]; + + fs_setup.stake_farm( + &second_user, + farm_in_amount, + &additional_farm_tokens, + 6, + 0, + 0, + ); + + fs_setup.check_user_total_farm_position(&first_user, half_farm_in_amount * 9); + fs_setup.check_user_total_farm_position(&second_user, farm_in_amount + half_farm_in_amount); + + let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); + fs_setup.b_mock.set_esdt_balance( + &rand_user, + FARMING_TOKEN_ID, + &rust_biguint!(USER_TOTAL_RIDE_TOKENS), + ); + + // random user tx to collect rewards + + fs_setup.set_user_energy(&rand_user, 1, 5, 1); + fs_setup.set_block_epoch(5); + fs_setup.set_block_nonce(10); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 7, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(8); + + fs_setup.set_user_energy(&first_user, 10_000, 8, 10); + fs_setup.set_user_energy(&second_user, 5_000, 8, 10); + + // Second user claims with half position from first user + let mut rewards = 2; + let mut expected_farming_token_balance = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + rewards); + fs_setup.claim_rewards( + &second_user, + half_farm_in_amount, + 2, + rewards, + &expected_farming_token_balance, + &expected_farming_token_balance, + 9, + 250_000, + ); + + fs_setup.check_user_total_farm_position(&first_user, half_farm_in_amount * 8); + fs_setup.check_user_total_farm_position(&second_user, farm_in_amount + half_farm_in_amount * 2); + + // random user tx to collect rewards + fs_setup.set_user_energy(&rand_user, 1, 12, 1); + fs_setup.set_block_epoch(12); + fs_setup.set_block_nonce(20); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 10, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(15); + + fs_setup.set_user_energy(&first_user, 10_000, 15, 10); + fs_setup.set_user_energy(&second_user, 5_000, 15, 10); + + // Second user exits with half position from first user + fs_setup + .b_mock + .execute_esdt_transfer( + &second_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 3, + &rust_biguint!(half_farm_in_amount), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + rewards += 3; + expected_farming_token_balance = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + rewards); + fs_setup.b_mock.check_esdt_balance( + &second_user, + REWARD_TOKEN_ID, + &expected_farming_token_balance, + ); + + fs_setup.check_user_total_farm_position(&first_user, half_farm_in_amount * 7); + fs_setup.check_user_total_farm_position(&second_user, farm_in_amount + half_farm_in_amount * 2); + + // First user claim boosted rewards + let first_user_expected_boosted_reward_token_out = 5; + let first_user_expected_farming_token_balance = rust_biguint!( + USER_TOTAL_RIDE_TOKENS - farm_in_amount * 5 + first_user_expected_boosted_reward_token_out + ); + fs_setup.claim_boosted_rewards_for_user( + &first_user, + &first_user, + first_user_expected_boosted_reward_token_out, + &first_user_expected_farming_token_balance, + ); + + fs_setup.check_user_total_farm_position(&first_user, half_farm_in_amount * 7); + fs_setup.check_user_total_farm_position(&second_user, farm_in_amount + half_farm_in_amount * 2); + + // random user tx to collect rewards + fs_setup.set_user_energy(&rand_user, 1, 12, 1); + fs_setup.set_block_epoch(20); + fs_setup.set_block_nonce(30); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 13, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(22); + + fs_setup.set_user_energy(&first_user, 10_000, 22, 10); + fs_setup.set_user_energy(&second_user, 5_000, 22, 10); + + // Second user merges half own position with 2 x half position from first user + // We send the payment from first user first, + // to see that the original caller is correctly updated as second user + let farm_tokens = [ + TxTokenTransfer { + token_identifier: FARM_TOKEN_ID.to_vec(), + nonce: 4, + value: rust_biguint!(half_farm_in_amount), + }, + TxTokenTransfer { + token_identifier: FARM_TOKEN_ID.to_vec(), + nonce: 6, + value: rust_biguint!(half_farm_in_amount), + }, + TxTokenTransfer { + token_identifier: FARM_TOKEN_ID.to_vec(), + nonce: 5, + value: rust_biguint!(half_farm_in_amount), + }, + ]; + fs_setup + .b_mock + .execute_esdt_multi_transfer(&second_user, &fs_setup.farm_wrapper, &farm_tokens, |sc| { + let _ = sc.merge_farm_tokens_endpoint(); + }) + .assert_ok(); + + let expected_attributes = StakingFarmTokenAttributes:: { + reward_per_share: managed_biguint!(0), + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(half_farm_in_amount * 3), + original_owner: managed_address!(&second_user), // Check that second user is original owner + }; + fs_setup.b_mock.check_nft_balance( + &second_user, + FARM_TOKEN_ID, + 15, + &rust_biguint!(half_farm_in_amount * 3), + Some(&expected_attributes), + ); + rewards += 1; + expected_farming_token_balance = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + rewards); + fs_setup.b_mock.check_esdt_balance( + &second_user, + REWARD_TOKEN_ID, + &expected_farming_token_balance, + ); + + fs_setup.check_user_total_farm_position(&first_user, half_farm_in_amount * 5); + fs_setup.check_user_total_farm_position(&second_user, farm_in_amount + half_farm_in_amount * 4); +} + +#[test] +fn farm_staking_farm_position_migration_test() { + DebugApi::dummy(); + let mut fs_setup = + FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + + let user = fs_setup.user_address.clone(); + + let farm_in_amount = 10_000_000; + let half_farm_in_amount = farm_in_amount / 2; + fs_setup.stake_farm(&user, farm_in_amount, &[], 1, 0, 0); + fs_setup.stake_farm(&user, farm_in_amount, &[], 2, 0, 0); + fs_setup.stake_farm(&user, farm_in_amount, &[], 3, 0, 0); + fs_setup.stake_farm(&user, farm_in_amount, &[], 4, 0, 0); + fs_setup.check_user_total_farm_position(&user, farm_in_amount * 4); + + // Simulate migration by resetting the user total farm position + fs_setup + .b_mock + .execute_esdt_transfer( + &user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + sc.user_total_farm_position(&managed_address!(&user)) + .set(managed_biguint!(0u64)); + + sc.farm_position_migration_nonce().set(5); + }, + ) + .assert_ok(); + + fs_setup.check_user_total_farm_position(&user, 0); + + let mut expected_total_farm_position = 0u64; + let additional_farm_tokens = [TxTokenTransfer { + token_identifier: FARM_TOKEN_ID.to_vec(), + nonce: 1, + value: rust_biguint!(half_farm_in_amount), + }]; + + // Check enter farm with half old position additional payment + fs_setup.stake_farm(&user, farm_in_amount, &additional_farm_tokens, 5, 0, 0); + expected_total_farm_position += farm_in_amount + half_farm_in_amount; + fs_setup.check_user_total_farm_position(&user, expected_total_farm_position); + + // Check claim with half old position + let expected_farming_token_balance = rust_biguint!(4_949_999_990u64); + fs_setup.claim_rewards( + &user, + half_farm_in_amount, + 2, + 0, + &expected_farming_token_balance, + &expected_farming_token_balance, + 6, + 0, + ); + expected_total_farm_position += half_farm_in_amount; + fs_setup.check_user_total_farm_position(&user, expected_total_farm_position); + + // Check exit with half old position + fs_setup.unstake_farm( + &user, + half_farm_in_amount, + 3, + 0, + &expected_farming_token_balance, + &expected_farming_token_balance, + 7, + half_farm_in_amount, + &UnbondSftAttributes { + unlock_epoch: MIN_UNBOND_EPOCHS, + }, + ); + fs_setup.check_user_total_farm_position(&user, expected_total_farm_position); + + // Check compound with half old position + fs_setup.compound_rewards( + &user, + 4, + half_farm_in_amount, + &[], + 8, + half_farm_in_amount, + 0, + 0, + ); + expected_total_farm_position += half_farm_in_amount; + fs_setup.check_user_total_farm_position(&user, expected_total_farm_position); +} + +#[test] +fn boosted_rewards_config_change_test() { + DebugApi::dummy(); + let mut fs_setup = + FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + + let first_user = fs_setup.user_address.clone(); + let second_user = fs_setup.user_address2.clone(); + let third_user = fs_setup + .b_mock + .create_user_account(&rust_biguint!(100_000_000)); + fs_setup.b_mock.set_esdt_balance( + &third_user, + FARMING_TOKEN_ID, + &rust_biguint!(USER_TOTAL_RIDE_TOKENS), + ); + + let mut first_user_total_rewards = 0u64; + let mut second_user_total_rewards = 0u64; + let mut third_user_total_rewards = 0u64; + + let farm_in_amount = 10_000_000; + fs_setup.stake_farm(&first_user, farm_in_amount, &[], 1, 0, 0); + fs_setup.stake_farm(&second_user, farm_in_amount, &[], 2, 0, 0); + fs_setup.stake_farm(&third_user, farm_in_amount, &[], 3, 0, 0); + + fs_setup.set_user_energy(&first_user, 10_000, 0, 10); + fs_setup.set_user_energy(&second_user, 10_000, 0, 10); + fs_setup.set_user_energy(&third_user, 10_000, 0, 10); + + // claim to get energy registered + fs_setup + .b_mock + .execute_esdt_transfer( + &first_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 1, + &rust_biguint!(farm_in_amount), + |sc| { + let _ = sc.claim_rewards(OptionalValue::None); + }, + ) + .assert_ok(); + fs_setup + .b_mock + .execute_esdt_transfer( + &second_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 2, + &rust_biguint!(farm_in_amount), + |sc| { + let _ = sc.claim_rewards(OptionalValue::None); + }, + ) + .assert_ok(); + fs_setup + .b_mock + .execute_esdt_transfer( + &third_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 3, + &rust_biguint!(farm_in_amount), + |sc| { + let _ = sc.claim_rewards(OptionalValue::None); + }, + ) + .assert_ok(); + + // random user tx to collect rewards + let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); + fs_setup.b_mock.set_esdt_balance( + &rand_user, + FARMING_TOKEN_ID, + &rust_biguint!(USER_TOTAL_RIDE_TOKENS), + ); + + fs_setup.set_user_energy(&rand_user, 1, 6, 1); + fs_setup.set_block_epoch(6); + fs_setup.set_block_nonce(100); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 7, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(7); + fs_setup.set_user_energy(&first_user, 10_000, 7, 10); + fs_setup.set_user_energy(&second_user, 10_000, 7, 10); + fs_setup.set_user_energy(&third_user, 10_000, 7, 10); + + // First user claims + let mut base_rewards1 = 33; + let mut boosted_rewards1 = 0; + let mut expected_reward_token_out = base_rewards1 + boosted_rewards1; + first_user_total_rewards += expected_reward_token_out; + let mut expected_farming_token_balance = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out); + let mut expected_reward_per_share = 3_333_333u64; + fs_setup.claim_rewards( + &first_user, + farm_in_amount, + 4, + expected_reward_token_out, + &expected_farming_token_balance, + &expected_farming_token_balance, + 9, + expected_reward_per_share, + ); + + // Boosted rewards config is added + fs_setup.set_boosted_yields_factors(); + fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + + // random user tx to collect rewards + fs_setup.set_user_energy(&rand_user, 1, 13, 1); + fs_setup.set_block_epoch(13); + fs_setup.set_block_nonce(200); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 10, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(14); + fs_setup.set_user_energy(&first_user, 10_000, 14, 10); + fs_setup.set_user_energy(&second_user, 10_000, 14, 10); + fs_setup.set_user_energy(&third_user, 10_000, 14, 10); + + // First and second users claim + base_rewards1 = 25; + boosted_rewards1 = 8; + expected_reward_token_out = base_rewards1 + boosted_rewards1; + first_user_total_rewards += expected_reward_token_out; + expected_farming_token_balance += expected_reward_token_out; + expected_reward_per_share = 5_833_333u64; + fs_setup.claim_rewards( + &first_user, + farm_in_amount, + 9, + expected_reward_token_out, + &expected_farming_token_balance, + &expected_farming_token_balance, + 12, + expected_reward_per_share, + ); + + let mut base_rewards2 = 33 + 25; + let mut boosted_rewards2 = 8; + let mut expected_reward_token_out2 = base_rewards2 + boosted_rewards2; + second_user_total_rewards += expected_reward_token_out2; + let mut expected_farming_token_balance2 = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out2); + fs_setup.claim_rewards( + &second_user, + farm_in_amount, + 5, + expected_reward_token_out2, + &expected_farming_token_balance2, + &expected_farming_token_balance2, + 13, + expected_reward_per_share, + ); + + // Boosted rewards config is updated + fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE * 2); // 50% + + // random user tx to collect rewards + fs_setup.set_user_energy(&rand_user, 1, 20, 1); + fs_setup.set_block_epoch(20); + fs_setup.set_block_nonce(300); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 14, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(21); + fs_setup.set_user_energy(&first_user, 10_000, 21, 10); + fs_setup.set_user_energy(&second_user, 10_000, 21, 10); + fs_setup.set_user_energy(&third_user, 10_000, 21, 10); + + // All users claim - boosted rewards 50% + base_rewards1 = 16; + boosted_rewards1 = 16; + expected_reward_token_out = base_rewards1 + boosted_rewards1; + first_user_total_rewards += expected_reward_token_out; + expected_farming_token_balance += expected_reward_token_out; + expected_reward_per_share = 7_499_999u64; + fs_setup.claim_rewards( + &first_user, + farm_in_amount, + 12, + expected_reward_token_out, + &expected_farming_token_balance, + &expected_farming_token_balance, + 16, + expected_reward_per_share, + ); + + base_rewards2 = 16; + boosted_rewards2 = 16; + expected_reward_token_out2 = base_rewards2 + boosted_rewards2; + second_user_total_rewards += expected_reward_token_out2; + expected_farming_token_balance2 += expected_reward_token_out2; + fs_setup.claim_rewards( + &second_user, + farm_in_amount, + 13, + expected_reward_token_out2, + &expected_farming_token_balance2, + &expected_farming_token_balance2, + 17, + expected_reward_per_share, + ); + + let base_rewards3 = 74; + let boosted_rewards3 = 24; + let expected_reward_token_out3 = base_rewards3 + boosted_rewards3; + third_user_total_rewards += expected_reward_token_out3; + let expected_farming_token_balance3 = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out3); + fs_setup.claim_rewards( + &third_user, + farm_in_amount, + 6, + expected_reward_token_out3, + &expected_farming_token_balance3, + &expected_farming_token_balance3, + 18, + expected_reward_per_share, + ); + + assert!( + first_user_total_rewards == second_user_total_rewards + && first_user_total_rewards == third_user_total_rewards + ); +} + +#[test] +fn claim_only_boosted_rewards_per_week_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); + + let first_user = fs_setup.user_address.clone(); + let farm_in_amount = 100_000_000; + + fs_setup.set_user_energy(&first_user, 10_000, 0, 10); + fs_setup.stake_farm(&first_user, farm_in_amount, &[], 1, 0, 0); + + fs_setup.check_farm_token_supply(farm_in_amount); + fs_setup.check_farm_rps(0u64); + + fs_setup.b_mock.set_block_nonce(100); + fs_setup.b_mock.set_block_epoch(6); + fs_setup.set_user_energy(&first_user, 1_000, 6, 1); + + // Reset user balance + fs_setup + .b_mock + .set_esdt_balance(&first_user, FARMING_TOKEN_ID, &rust_biguint!(0)); + + // random user tx to collect rewards + let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); + fs_setup.b_mock.set_esdt_balance( + &rand_user, + FARMING_TOKEN_ID, + &rust_biguint!(USER_TOTAL_RIDE_TOKENS), + ); + + fs_setup.set_user_energy(&rand_user, 1, 6, 1); + fs_setup.stake_farm(&rand_user, 10, &[], 2, 3_000_000u64, 0); + fs_setup.unstake_farm_no_checks(&rand_user, 10, 2); + + let farm_rps_increase = 3_000_000u64; + let mut current_farm_rps = 0; + current_farm_rps += farm_rps_increase; + fs_setup.check_farm_rps(current_farm_rps); + + // advance 1 week + fs_setup.set_user_energy(&first_user, 1_000, 13, 1); + fs_setup.b_mock.set_block_nonce(200); + fs_setup.b_mock.set_block_epoch(13); + + let boosted_rewards_for_week = 100; + fs_setup.claim_boosted_rewards_for_user( + &first_user, + &first_user, + boosted_rewards_for_week, + &rust_biguint!(boosted_rewards_for_week), + ); + + current_farm_rps += farm_rps_increase; + fs_setup.check_farm_rps(current_farm_rps); + + // advance 1 week + fs_setup.set_user_energy(&first_user, 1_000, 15, 1); + fs_setup.b_mock.set_block_nonce(300); + fs_setup.b_mock.set_block_epoch(15); + fs_setup.claim_boosted_rewards_for_user( + &first_user, + &first_user, + boosted_rewards_for_week, + &rust_biguint!(boosted_rewards_for_week * 2), + ); + + current_farm_rps += farm_rps_increase; + fs_setup.check_farm_rps(current_farm_rps); + fs_setup.b_mock.check_esdt_balance( + &first_user, + REWARD_TOKEN_ID, + &rust_biguint!(boosted_rewards_for_week * 2), + ); + + let expected_attributes = StakingFarmTokenAttributes:: { + reward_per_share: managed_biguint!(0), + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(farm_in_amount), + original_owner: managed_address!(&first_user), + }; + + fs_setup.b_mock.check_nft_balance( + &first_user, + FARM_TOKEN_ID, + 1, + &rust_biguint!(farm_in_amount), + Some(&expected_attributes), + ); +} + +#[test] +fn claim_rewards_per_week_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); + + let first_user = fs_setup.user_address.clone(); + let farm_in_amount = 100_000_000; + + fs_setup.set_user_energy(&first_user, 10_000, 0, 10); + fs_setup.stake_farm(&first_user, farm_in_amount, &[], 1, 0, 0); + + fs_setup.check_farm_token_supply(farm_in_amount); + fs_setup.check_farm_rps(0u64); + + fs_setup.b_mock.set_block_nonce(100); + fs_setup.b_mock.set_block_epoch(6); + fs_setup.set_user_energy(&first_user, 1_000, 6, 1); + + // Reset user balance + fs_setup + .b_mock + .set_esdt_balance(&first_user, FARMING_TOKEN_ID, &rust_biguint!(0)); + + // random user tx to collect rewards + let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); + fs_setup.b_mock.set_esdt_balance( + &rand_user, + FARMING_TOKEN_ID, + &rust_biguint!(USER_TOTAL_RIDE_TOKENS), + ); + + fs_setup.set_user_energy(&rand_user, 1, 6, 1); + fs_setup.stake_farm(&rand_user, 10, &[], 2, 3_000_000u64, 0); + fs_setup.unstake_farm_no_checks(&rand_user, 10, 2); + + let farm_rps_increase = 3_000_000u64; + let mut current_farm_rps = 0; + current_farm_rps += farm_rps_increase; + fs_setup.check_farm_rps(current_farm_rps); + + // advance 1 week + fs_setup.set_user_energy(&first_user, 1_000, 13, 1); + fs_setup.b_mock.set_block_nonce(200); + fs_setup.b_mock.set_block_epoch(13); + + let base_rewards_for_week = 300; + let boosted_rewards_for_week = 100; + + current_farm_rps += farm_rps_increase; + let mut user_rewards_balance = base_rewards_for_week * 2 + boosted_rewards_for_week; + fs_setup.claim_rewards( + &first_user, + farm_in_amount, + 1, + base_rewards_for_week * 2 + boosted_rewards_for_week, + &rust_biguint!(user_rewards_balance), + &rust_biguint!(user_rewards_balance), // user balance has bet set to 0 at the start + 4, + current_farm_rps, + ); + + fs_setup.check_farm_rps(current_farm_rps); + + // advance 1 week + fs_setup.set_user_energy(&first_user, 1_000, 15, 1); + fs_setup.b_mock.set_block_nonce(300); + fs_setup.b_mock.set_block_epoch(15); + + current_farm_rps += farm_rps_increase; + user_rewards_balance += base_rewards_for_week + boosted_rewards_for_week; + fs_setup.claim_rewards( + &first_user, + farm_in_amount, + 4, + base_rewards_for_week + boosted_rewards_for_week, + &rust_biguint!(user_rewards_balance), + &rust_biguint!(user_rewards_balance), + 5, + current_farm_rps, + ); + + fs_setup.check_farm_rps(current_farm_rps); + + fs_setup.b_mock.check_esdt_balance( + &first_user, + REWARD_TOKEN_ID, + &rust_biguint!(user_rewards_balance), + ); +} + +#[test] +fn claim_boosted_rewards_with_zero_position_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); + + let first_user = fs_setup.user_address.clone(); + let farm_in_amount = 100_000_000; + + fs_setup.set_user_energy(&first_user, 10_000, 0, 10); + fs_setup.stake_farm(&first_user, farm_in_amount, &[], 1, 0, 0); + + fs_setup.check_farm_token_supply(farm_in_amount); + fs_setup.check_farm_rps(0u64); + + fs_setup.b_mock.set_block_nonce(100); + fs_setup.b_mock.set_block_epoch(6); + fs_setup.set_user_energy(&first_user, 1_000, 6, 1); + + // Reset user balance + fs_setup + .b_mock + .set_esdt_balance(&first_user, FARMING_TOKEN_ID, &rust_biguint!(0)); + + // tx to collect rewards + let second_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); + fs_setup.b_mock.set_esdt_balance( + &second_user, + FARMING_TOKEN_ID, + &rust_biguint!(USER_TOTAL_RIDE_TOKENS), + ); + + fs_setup.set_user_energy(&second_user, 1, 6, 1); + fs_setup.stake_farm(&second_user, 10, &[], 2, 3_000_000u64, 0); + fs_setup.unstake_farm_no_checks(&second_user, 10, 2); + + let farm_rps_increase = 3_000_000u64; + let mut current_farm_rps = 0; + current_farm_rps += farm_rps_increase; + fs_setup.check_farm_rps(current_farm_rps); + + // advance 1 week + fs_setup.set_user_energy(&first_user, 1_000, 13, 1); + fs_setup.b_mock.set_block_nonce(200); + fs_setup.b_mock.set_block_epoch(13); + + let boosted_rewards_for_week = 100; + + fs_setup + .b_mock + .execute_tx( + &second_user, + &fs_setup.farm_wrapper, + &rust_biguint!(0u64), + |sc| { + sc.claim_boosted_rewards(OptionalValue::Some(managed_address!(&second_user))); + }, + ) + .assert_error(4, "User total farm position is empty!"); + + fs_setup.check_farm_rps(current_farm_rps); + + // advance 1 week + fs_setup.set_user_energy(&first_user, 1_000, 15, 1); + fs_setup.b_mock.set_block_nonce(300); + fs_setup.b_mock.set_block_epoch(15); + fs_setup.claim_boosted_rewards_for_user( + &first_user, + &first_user, + boosted_rewards_for_week, + &rust_biguint!(boosted_rewards_for_week), + ); + + current_farm_rps += farm_rps_increase * 2; + fs_setup.check_farm_rps(current_farm_rps); + fs_setup.b_mock.check_esdt_balance( + &first_user, + REWARD_TOKEN_ID, + &rust_biguint!(boosted_rewards_for_week), + ); + + let expected_attributes = StakingFarmTokenAttributes:: { + reward_per_share: managed_biguint!(0), + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(farm_in_amount), + original_owner: managed_address!(&first_user), + }; + + fs_setup.b_mock.check_nft_balance( + &first_user, + FARM_TOKEN_ID, + 1, + &rust_biguint!(farm_in_amount), + Some(&expected_attributes), + ); +} 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 d8cfc9a46..a27b2d0d0 100644 --- a/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs +++ b/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs @@ -1,6 +1,7 @@ #![allow(deprecated)] use farm_staking::claim_only_boosted_staking_rewards::ClaimOnlyBoostedStakingRewardsModule; +use farm_staking::compound_stake_farm_rewards::CompoundStakeFarmRewardsModule; use multiversx_sc::codec::multi_types::OptionalValue; use multiversx_sc::storage::mappers::StorageTokenWrapper; use multiversx_sc::types::{Address, BigInt, EsdtLocalRole, ManagedAddress, MultiValueEncoded}; @@ -15,7 +16,6 @@ use config::*; use energy_factory::energy::EnergyModule; use energy_query::{Energy, EnergyQueryModule}; use farm_boosted_yields::boosted_yields_factors::BoostedYieldsFactorsModule; -use farm_boosted_yields::FarmBoostedYieldsModule; use farm_staking::claim_stake_farm_rewards::ClaimStakeFarmRewardsModule; use farm_staking::custom_rewards::CustomRewardsModule; use farm_staking::stake_farm::StakeFarmModule; @@ -25,6 +25,7 @@ use farm_staking::unstake_farm::UnstakeFarmModule; use farm_staking::*; use farm_token::FarmTokenModule; use pausable::{PausableModule, State}; +use rewards::RewardsModule; pub static REWARD_TOKEN_ID: &[u8] = b"RIDE-abcdef"; // reward token ID pub static FARMING_TOKEN_ID: &[u8] = b"RIDE-abcdef"; // farming token ID @@ -46,6 +47,11 @@ 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 NonceAmountPair { + pub nonce: u64, + pub amount: u64, +} + pub struct FarmStakingSetup where FarmObjBuilder: 'static + Copy + Fn() -> farm_staking::ContractObj, @@ -54,6 +60,7 @@ where pub b_mock: BlockchainStateWrapper, pub owner_address: Address, pub user_address: Address, + pub user_address2: Address, pub farm_wrapper: ContractObjWrapper, FarmObjBuilder>, pub energy_factory_wrapper: ContractObjWrapper, EnergyFactoryBuilder>, @@ -146,11 +153,18 @@ where FARMING_TOKEN_ID, &rust_biguint!(USER_TOTAL_RIDE_TOKENS), ); + let user_addr2 = b_mock.create_user_account(&rust_biguint!(100_000_000)); + b_mock.set_esdt_balance( + &user_addr2, + FARMING_TOKEN_ID, + &rust_biguint!(USER_TOTAL_RIDE_TOKENS), + ); FarmStakingSetup { b_mock, owner_address: owner_addr, user_address: user_addr, + user_address2: user_addr2, farm_wrapper, energy_factory_wrapper, } @@ -158,6 +172,7 @@ where pub fn stake_farm( &mut self, + user: &Address, farm_in_amount: u64, additional_farm_tokens: &[TxTokenTransfer], expected_farm_token_nonce: u64, @@ -178,7 +193,7 @@ where } self.b_mock - .execute_esdt_multi_transfer(&self.user_address, &self.farm_wrapper, &payments, |sc| { + .execute_esdt_multi_transfer(user, &self.farm_wrapper, &payments, |sc| { let (new_farm_token_payment, _) = sc.stake_farm_endpoint(OptionalValue::None).into_tuple(); assert_eq!( @@ -200,10 +215,10 @@ where reward_per_share: managed_biguint!(expected_reward_per_share), compounded_reward: managed_biguint!(expected_compounded_reward), current_farm_amount: managed_biguint!(expected_total_out_amount), - original_owner: managed_address!(&self.user_address), + original_owner: managed_address!(&user), }; self.b_mock.check_nft_balance( - &self.user_address, + user, FARM_TOKEN_ID, expected_farm_token_nonce, &rust_biguint!(expected_total_out_amount), @@ -211,9 +226,74 @@ where ); } + pub fn stake_farm_for_other_user( + &mut self, + user: &Address, + broker: &Address, + farm_in_amount: u64, + additional_farm_tokens: &[TxTokenTransfer], + ) -> TxResult { + let mut payments = Vec::with_capacity(1 + additional_farm_tokens.len()); + payments.push(TxTokenTransfer { + token_identifier: FARMING_TOKEN_ID.to_vec(), + nonce: 0, + value: rust_biguint!(farm_in_amount), + }); + payments.extend_from_slice(additional_farm_tokens); + + self.b_mock + .execute_esdt_multi_transfer(broker, &self.farm_wrapper, &payments, |sc| { + sc.stake_farm_endpoint(OptionalValue::Some(managed_address!(user))) + .into_tuple(); + }) + } + + pub fn claim_farm_for_other_user( + &mut self, + user: &Address, + broker: &Address, + farm_in_nonce: u64, + farm_in_amount: u64, + ) -> TxResult { + let mut payments = vec![]; + payments.push(TxTokenTransfer { + token_identifier: FARM_TOKEN_ID.to_vec(), + nonce: farm_in_nonce, + value: rust_biguint!(farm_in_amount), + }); + + self.b_mock + .execute_esdt_multi_transfer(broker, &self.farm_wrapper, &payments, |sc| { + sc.claim_rewards(OptionalValue::Some(managed_address!(user))) + .into_tuple(); + }) + } + + pub fn unstake_farm_for_other_user( + &mut self, + user: &Address, + broker: &Address, + farm_in_nonce: u64, + farm_in_amount: u64, + ) -> TxResult { + let mut payments = vec![]; + payments.push(TxTokenTransfer { + token_identifier: FARM_TOKEN_ID.to_vec(), + nonce: farm_in_nonce, + value: rust_biguint!(farm_in_amount), + }); + + self.b_mock + .execute_esdt_multi_transfer(broker, &self.farm_wrapper, &payments, |sc| { + sc.unstake_farm(OptionalValue::Some(managed_address!(user))) + .into_tuple(); + }) + } + #[allow(clippy::too_many_arguments)] pub fn claim_rewards( &mut self, + user: &Address, farm_token_amount: u64, farm_token_nonce: u64, expected_reward_token_out: u64, @@ -224,7 +304,7 @@ where ) { self.b_mock .execute_esdt_transfer( - &self.user_address, + user, &self.farm_wrapper, FARM_TOKEN_ID, farm_token_nonce, @@ -257,26 +337,20 @@ where reward_per_share: managed_biguint!(expected_reward_per_share), compounded_reward: managed_biguint!(0), current_farm_amount: managed_biguint!(farm_token_amount), - original_owner: managed_address!(&self.user_address), + original_owner: managed_address!(user), }; self.b_mock.check_nft_balance( - &self.user_address, + user, FARM_TOKEN_ID, expected_farm_token_nonce_out, &rust_biguint!(farm_token_amount), Some(&expected_attributes), ); - self.b_mock.check_esdt_balance( - &self.user_address, - REWARD_TOKEN_ID, - expected_user_reward_token_balance, - ); - self.b_mock.check_esdt_balance( - &self.user_address, - FARMING_TOKEN_ID, - expected_user_farming_token_balance, - ); + self.b_mock + .check_esdt_balance(user, REWARD_TOKEN_ID, expected_user_reward_token_balance); + self.b_mock + .check_esdt_balance(user, FARMING_TOKEN_ID, expected_user_farming_token_balance); } pub fn claim_boosted_rewards_for_user( @@ -310,9 +384,77 @@ where ); } + pub fn claim_boosted_rewards_for_user_expect_error( + &mut self, + owner: &Address, + broker: &Address, + ) { + self.b_mock + .execute_tx(broker, &self.farm_wrapper, &rust_biguint!(0), |sc| { + let _ = sc.claim_boosted_rewards(OptionalValue::Some(managed_address!(owner))); + }) + .assert_error(4, "Cannot claim rewards for this address"); + } + + #[allow(clippy::too_many_arguments)] + pub fn compound_rewards( + &mut self, + user: &Address, + farm_in_nonce: u64, + farm_in_amount: u64, + additional_farm_tokens: &[TxTokenTransfer], + expected_farm_token_nonce: u64, + expected_farm_token_amount: u64, + expected_reward_per_share: u64, + expected_compounded_reward: u64, + ) { + let mut payments = Vec::with_capacity(1 + additional_farm_tokens.len()); + payments.push(TxTokenTransfer { + token_identifier: FARM_TOKEN_ID.to_vec(), + nonce: farm_in_nonce, + value: rust_biguint!(farm_in_amount), + }); + payments.extend_from_slice(additional_farm_tokens); + + self.b_mock + .execute_esdt_multi_transfer(user, &self.farm_wrapper, &payments, |sc| { + let new_farm_token_payment = sc.compound_rewards(); + assert_eq!( + new_farm_token_payment.token_identifier, + managed_token_id!(FARM_TOKEN_ID) + ); + assert_eq!( + new_farm_token_payment.token_nonce, + expected_farm_token_nonce + ); + assert_eq!( + new_farm_token_payment.amount, + managed_biguint!(expected_farm_token_amount) + ); + }) + .assert_ok(); + + let expected_attributes = StakingFarmTokenAttributes:: { + reward_per_share: managed_biguint!(expected_reward_per_share), + compounded_reward: managed_biguint!(expected_compounded_reward), + current_farm_amount: managed_biguint!( + expected_farm_token_amount + expected_compounded_reward + ), + original_owner: managed_address!(&user), + }; + self.b_mock.check_nft_balance( + user, + FARM_TOKEN_ID, + expected_farm_token_nonce, + &rust_biguint!(expected_farm_token_amount + expected_compounded_reward), + Some(&expected_attributes), + ); + } + #[allow(clippy::too_many_arguments)] pub fn unstake_farm( &mut self, + user: &Address, farm_token_amount: u64, farm_token_nonce: u64, expected_rewards_out: u64, @@ -324,7 +466,7 @@ where ) { self.b_mock .execute_esdt_transfer( - &self.user_address, + user, &self.farm_wrapper, FARM_TOKEN_ID, farm_token_nonce, @@ -373,6 +515,24 @@ where ); } + pub fn unstake_farm_no_checks( + &mut self, + user: &Address, + farm_token_amount: u64, + farm_token_nonce: u64, + ) { + let _ = self.b_mock.execute_esdt_transfer( + user, + &self.farm_wrapper, + FARM_TOKEN_ID, + farm_token_nonce, + &rust_biguint!(farm_token_amount), + |sc| { + sc.unstake_farm(OptionalValue::None); + }, + ); + } + pub fn unbond_farm( &mut self, farm_token_nonce: u64, @@ -418,6 +578,15 @@ where .assert_ok(); } + pub fn check_farm_rps(&mut self, expected_amount: u64) { + self.b_mock + .execute_query(&self.farm_wrapper, |sc| { + let current_rps = sc.reward_per_share().get(); + assert_eq!(managed_biguint!(expected_amount), current_rps); + }) + .assert_ok(); + } + pub fn check_rewards_capacity(&mut self, expected_farm_token_supply: u64) { self.b_mock .execute_query(&self.farm_wrapper, |sc| { @@ -430,14 +599,11 @@ where .assert_ok(); } - pub fn allow_external_claim_rewards(&mut self, user: &Address) { + pub fn allow_external_claim_rewards(&mut self, user: &Address, allow_claim: bool) { self.b_mock .execute_tx(user, &self.farm_wrapper, &rust_biguint!(0), |sc| { - sc.user_total_farm_position(&managed_address!(user)).update( - |user_total_farm_position| { - user_total_farm_position.allow_external_claim_boosted_rewards = true; - }, - ); + sc.allow_external_claim(&managed_address!(user)) + .set(allow_claim); }) .assert_ok(); } @@ -535,4 +701,113 @@ where ) .assert_error(expected_status, expected_message) } + + pub fn send_position( + &mut self, + sender: &Address, + receiver: &Address, + nonce: u64, + amount: u64, + attr_reward_per_share: u64, + ) { + self.b_mock.check_nft_balance( + sender, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(amount), + Some(&StakingFarmTokenAttributes:: { + reward_per_share: managed_biguint!(attr_reward_per_share), + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(amount), + original_owner: managed_address!(&sender), + }), + ); + + self.b_mock + .check_nft_balance::>( + receiver, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(0), + None, + ); + + self.b_mock.set_nft_balance( + sender, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(0), + &StakingFarmTokenAttributes:: { + reward_per_share: managed_biguint!(attr_reward_per_share), + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(amount), + original_owner: managed_address!(&sender), + }, + ); + + self.b_mock.set_nft_balance( + receiver, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(amount), + &StakingFarmTokenAttributes:: { + reward_per_share: managed_biguint!(attr_reward_per_share), + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(amount), + original_owner: managed_address!(&sender), + }, + ); + + self.b_mock + .check_nft_balance::>( + sender, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(0), + None, + ); + + self.b_mock.check_nft_balance( + receiver, + FARM_TOKEN_ID, + nonce, + &rust_biguint!(amount), + Some(&StakingFarmTokenAttributes:: { + reward_per_share: managed_biguint!(attr_reward_per_share), + compounded_reward: managed_biguint!(0), + current_farm_amount: managed_biguint!(amount), + original_owner: managed_address!(&sender), + }), + ); + } + + pub fn check_user_total_farm_position(&mut self, user_addr: &Address, expected_amount: u64) { + self.b_mock + .execute_query(&self.farm_wrapper, |sc| { + let user_total_farm_position_mapper = + sc.user_total_farm_position(&managed_address!(user_addr)); + if expected_amount > 0 && !user_total_farm_position_mapper.is_empty() { + assert_eq!( + managed_biguint!(expected_amount), + user_total_farm_position_mapper.get() + ); + } + }) + .assert_ok(); + } + + pub fn update_energy_for_user(&mut self, user_addr: &Address) { + self.b_mock + .execute_tx( + user_addr, + &self.energy_factory_wrapper, + &rust_biguint!(0), + |sc| { + let user_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(user_addr)); + sc.set_energy_entry(&managed_address!(user_addr), user_energy); + }, + ) + .assert_ok(); + } } diff --git a/farm-staking/farm-staking/tests/farm_staking_test.rs b/farm-staking/farm-staking/tests/farm_staking_test.rs index 89192a6a1..26a9d065b 100644 --- a/farm-staking/farm-staking/tests/farm_staking_test.rs +++ b/farm-staking/farm-staking/tests/farm_staking_test.rs @@ -20,9 +20,18 @@ fn test_enter_farm() { let mut farm_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = farm_setup.user_address.clone(); + let farm_in_amount = 100_000_000; let expected_farm_token_nonce = 1; - farm_setup.stake_farm(farm_in_amount, &[], expected_farm_token_nonce, 0, 0); + farm_setup.stake_farm( + &user_address, + farm_in_amount, + &[], + expected_farm_token_nonce, + 0, + 0, + ); farm_setup.check_farm_token_supply(farm_in_amount); } @@ -32,9 +41,18 @@ fn test_unstake_farm() { let mut farm_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = farm_setup.user_address.clone(); + let farm_in_amount = 100_000_000; let expected_farm_token_nonce = 1; - farm_setup.stake_farm(farm_in_amount, &[], expected_farm_token_nonce, 0, 0); + farm_setup.stake_farm( + &user_address, + farm_in_amount, + &[], + expected_farm_token_nonce, + 0, + 0, + ); farm_setup.check_farm_token_supply(farm_in_amount); let current_block = 10; @@ -54,6 +72,7 @@ fn test_unstake_farm() { let expected_ride_token_balance = rust_biguint!(USER_TOTAL_RIDE_TOKENS) - farm_in_amount + expected_rewards; farm_setup.unstake_farm( + &user_address, farm_in_amount, expected_farm_token_nonce, expected_rewards, @@ -74,9 +93,18 @@ fn test_claim_rewards() { let mut farm_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = farm_setup.user_address.clone(); + let farm_in_amount = 100_000_000; let expected_farm_token_nonce = 1; - farm_setup.stake_farm(farm_in_amount, &[], expected_farm_token_nonce, 0, 0); + farm_setup.stake_farm( + &user_address, + farm_in_amount, + &[], + expected_farm_token_nonce, + 0, + 0, + ); farm_setup.check_farm_token_supply(farm_in_amount); farm_setup.set_block_epoch(5); @@ -88,6 +116,7 @@ fn test_claim_rewards() { rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out); let expected_reward_per_share = 400_000; farm_setup.claim_rewards( + &user_address, farm_in_amount, expected_farm_token_nonce, expected_reward_token_out, @@ -109,9 +138,18 @@ where { let mut farm_setup = FarmStakingSetup::new(farm_builder, energy_factory_builder); + let user_address = farm_setup.user_address.clone(); + let farm_in_amount = 100_000_000; let expected_farm_token_nonce = 1; - farm_setup.stake_farm(farm_in_amount, &[], expected_farm_token_nonce, 0, 0); + farm_setup.stake_farm( + &user_address, + farm_in_amount, + &[], + expected_farm_token_nonce, + 0, + 0, + ); farm_setup.check_farm_token_supply(farm_in_amount); farm_setup.set_block_epoch(5); @@ -134,6 +172,7 @@ where / total_amount; farm_setup.stake_farm( + &user_address, second_farm_in_amount, &prev_farm_tokens, expected_farm_token_nonce + 1, @@ -156,6 +195,9 @@ fn test_exit_farm_after_enter_twice() { DebugApi::dummy(); let mut farm_setup = steps_enter_farm_twice(farm_staking::contract_obj, energy_factory::contract_obj); + + let user_address = farm_setup.user_address.clone(); + let farm_in_amount = 100_000_000; let second_farm_in_amount = 200_000_000; @@ -167,6 +209,7 @@ fn test_exit_farm_after_enter_twice() { rust_biguint!(USER_TOTAL_RIDE_TOKENS) - farm_in_amount - second_farm_in_amount + expected_rewards; farm_setup.unstake_farm( + &user_address, farm_in_amount, 2, expected_rewards, @@ -187,9 +230,18 @@ fn test_unbond() { let mut farm_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = farm_setup.user_address.clone(); + let farm_in_amount = 100_000_000; let expected_farm_token_nonce = 1; - farm_setup.stake_farm(farm_in_amount, &[], expected_farm_token_nonce, 0, 0); + farm_setup.stake_farm( + &user_address, + farm_in_amount, + &[], + expected_farm_token_nonce, + 0, + 0, + ); farm_setup.check_farm_token_supply(farm_in_amount); let current_block = 10; @@ -209,6 +261,7 @@ fn test_unbond() { let expected_ride_token_balance = rust_biguint!(USER_TOTAL_RIDE_TOKENS) - farm_in_amount + expected_rewards; farm_setup.unstake_farm( + &user_address, farm_in_amount, expected_farm_token_nonce, expected_rewards, @@ -254,12 +307,21 @@ fn test_withdraw_after_produced_rewards() { let mut farm_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = farm_setup.user_address.clone(); + let initial_rewards_capacity = 1_000_000_000_000u64; farm_setup.check_rewards_capacity(initial_rewards_capacity); let farm_in_amount = 100_000_000; let expected_farm_token_nonce = 1; - farm_setup.stake_farm(farm_in_amount, &[], expected_farm_token_nonce, 0, 0); + farm_setup.stake_farm( + &user_address, + farm_in_amount, + &[], + expected_farm_token_nonce, + 0, + 0, + ); farm_setup.check_farm_token_supply(farm_in_amount); farm_setup.set_block_epoch(5); diff --git a/farm-staking/farm-staking/wasm/Cargo.lock b/farm-staking/farm-staking/wasm/Cargo.lock index 88d4b1bba..465de9d30 100644 --- a/farm-staking/farm-staking/wasm/Cargo.lock +++ b/farm-staking/farm-staking/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common-types" @@ -76,9 +76,9 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "endian-type" @@ -316,32 +316,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -351,9 +353,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -364,18 +366,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -391,9 +393,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -433,18 +435,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -493,15 +495,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -531,6 +533,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" diff --git a/farm-staking/farm-staking/wasm/Cargo.toml b/farm-staking/farm-staking/wasm/Cargo.toml index 0dbb347b9..9b6328d70 100644 --- a/farm-staking/farm-staking/wasm/Cargo.toml +++ b/farm-staking/farm-staking/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.farm-staking] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [workspace] members = ["."] diff --git a/farm-staking/farm-staking/wasm/src/lib.rs b/farm-staking/farm-staking/wasm/src/lib.rs index 02de33846..9489b1d7e 100644 --- a/farm-staking/farm-staking/wasm/src/lib.rs +++ b/farm-staking/farm-staking/wasm/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 71 +// Upgrade: 1 +// Endpoints: 69 // Async Callback: 1 -// Total number of exported functions: 73 +// Total number of exported functions: 72 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -22,6 +21,7 @@ multiversx_sc_wasm_adapter::endpoints! { init => init upgrade => upgrade mergeFarmTokens => merge_farm_tokens_endpoint + setBoostedYieldsRewardsPercentage => set_boosted_yields_rewards_percentage calculateRewardsForGivenPosition => calculate_rewards_for_given_position topUpRewards => top_up_rewards withdrawRewards => withdraw_rewards @@ -36,14 +36,13 @@ multiversx_sc_wasm_adapter::endpoints! { 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 + getAllowExternalClaim => allow_external_claim getFarmPositionMigrationNonce => farm_position_migration_nonce registerFarmToken => register_farm_token getFarmTokenId => farm_token @@ -70,7 +69,6 @@ multiversx_sc_wasm_adapter::endpoints! { 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 diff --git a/farm-staking/metabonding-staking/README.md b/farm-staking/metabonding-staking/README.md deleted file mode 100644 index dd18a194d..000000000 --- a/farm-staking/metabonding-staking/README.md +++ /dev/null @@ -1,57 +0,0 @@ -# Metabonding Staking Contract - -## Abstract - -Metabonding is a new community bootstrapping product, that allows users to receive tokens from projects enrolled in the Metabonding program, based on their staked eGLD and locked tokens. - -## Introduction - -The Metabonding staking contract works in conjunction with the main Metabonding contract. -The workflow can be summarized like so: -- Projects apply to the Metabonding program, by allocating a fixed number of tokens that will be distributed to users based on weekly snapshots. -- The user can stake his locked assets, along with his staked eGLD that is included by default in the snapshots, in order to get a portion of the allocated tokens. -- Daily snapshots are taken, with weekly reward distribution based on the average staked balance. - -The Metabonding staking contract takes care of the staking part of the workflow, by storing the staked locked token amounts. - -## Endpoints - -### stakeLockedAsset - -```rust - #[payable("*")] - #[endpoint(stakeLockedAsset)] - fn stake_locked_asset(&self); -``` - -Payable endpoint that allows the user to stake his locked assets. If the user already has a staking position, the tokens are merged through the locked asset factory contract. An user entry is stored, containing the information as shown below, along with the total locked asset staked supply. - -```rust -pub struct UserEntry { - pub token_nonce: u64, - pub stake_amount: BigUint, - pub unstake_amount: BigUint, - pub unbond_epoch: u64, -} -``` - -### unstake - -```rust - #[endpoint] - fn unstake( - &self, - amount: BigUint - ); -``` - -Endpoint that allows the user to specify how many locked assets he wants to unstake. When calling the endpoint, the user does not actually receive the tokens back, but he sort of states the intention to take back the tokens. Based on the current unbond duration, the user storage entry is updated with the amount he wants to unstake and the unbonding duration. In case of a second unstake, if the unbonding period is not finished, the unbonding counter is reset. - -### unbond - -```rust - #[endpoint] - fn unbond(&self); -``` - -Endpoint the allows the user to receive his tokens, considering the unbonding period is over. He receives the amount that he previously unstaked, with the corresponding token nonce. diff --git a/farm-staking/metabonding-staking/meta/src/main.rs b/farm-staking/metabonding-staking/meta/src/main.rs deleted file mode 100644 index 481297930..000000000 --- a/farm-staking/metabonding-staking/meta/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - multiversx_sc_meta::cli_main::(); -} diff --git a/farm-staking/metabonding-staking/src/events.rs b/farm-staking/metabonding-staking/src/events.rs deleted file mode 100644 index 5614ab534..000000000 --- a/farm-staking/metabonding-staking/src/events.rs +++ /dev/null @@ -1,27 +0,0 @@ -multiversx_sc::imports!(); - -use crate::locked_asset_token::UserEntry; - -#[multiversx_sc::module] -pub trait EventsModule { - #[event("stakeEvent")] - fn stake_event( - &self, - #[indexed] user_address: &ManagedAddress, - entry_after_action: &UserEntry, - ); - - #[event("unstakeEvent")] - fn unstake_event( - &self, - #[indexed] user_address: &ManagedAddress, - entry_after_action: &UserEntry, - ); - - #[event("unbondEvent")] - fn unbond_event( - &self, - #[indexed] user_address: &ManagedAddress, - opt_entry_after_action: Option<&UserEntry>, - ); -} diff --git a/farm-staking/metabonding-staking/src/lib.rs b/farm-staking/metabonding-staking/src/lib.rs deleted file mode 100644 index 94be22193..000000000 --- a/farm-staking/metabonding-staking/src/lib.rs +++ /dev/null @@ -1,152 +0,0 @@ -#![no_std] - -multiversx_sc::imports!(); - -pub mod events; -pub mod locked_asset_token; - -use locked_asset_token::UserEntry; - -pub type SnapshotEntry = MultiValue2, BigUint>; -pub const UNBOND_EPOCHS: u64 = 3; - -#[multiversx_sc::contract] -pub trait MetabondingStaking: - locked_asset_token::LockedAssetTokenModule + events::EventsModule -{ - #[init] - fn init( - &self, - locked_asset_token_id: TokenIdentifier, - locked_asset_factory_address: ManagedAddress, - ) { - self.locked_asset_token_id() - .set_if_empty(&locked_asset_token_id); - self.locked_asset_factory_address() - .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().clone_value(); - self.require_all_locked_asset_payments(&payments); - - let caller = self.blockchain().get_caller(); - let entry_mapper = self.entry_for_user(&caller); - let new_entry = self.create_new_entry_by_merging_tokens(&entry_mapper, payments); - - self.total_locked_asset_supply() - .update(|total_supply| *total_supply += new_entry.get_total_amount()); - - self.stake_event(&caller, &new_entry); - - entry_mapper.set(&new_entry); - let _ = self.user_list().insert(caller); - } - - #[endpoint] - fn unstake(&self, amount: BigUint) { - let caller = self.blockchain().get_caller(); - let entry_mapper = self.entry_for_user(&caller); - require!(!entry_mapper.is_empty(), "Must stake first"); - - let mut user_entry: UserEntry = entry_mapper.get(); - require!( - amount <= user_entry.stake_amount, - "Trying to unstake too much" - ); - - let current_epoch = self.blockchain().get_block_epoch(); - user_entry.unbond_epoch = current_epoch + UNBOND_EPOCHS; - user_entry.stake_amount -= &amount; - user_entry.unstake_amount += amount; - - self.unstake_event(&caller, &user_entry); - - entry_mapper.set(&user_entry); - } - - #[endpoint] - fn unbond(&self) { - let caller = self.blockchain().get_caller(); - let entry_mapper = self.entry_for_user(&caller); - require!(!entry_mapper.is_empty(), "Must stake first"); - - let mut user_entry: UserEntry = entry_mapper.get(); - let unstake_amount = user_entry.unstake_amount; - require!(unstake_amount > 0, "Must unstake first"); - - let current_epoch = self.blockchain().get_block_epoch(); - require!( - current_epoch >= user_entry.unbond_epoch, - "Unbond period in progress" - ); - - self.total_locked_asset_supply() - .update(|total_supply| *total_supply -= &unstake_amount); - - let opt_entry_after_action = if user_entry.stake_amount == 0 { - entry_mapper.clear(); - self.user_list().swap_remove(&caller); - - None - } else { - user_entry.unstake_amount = BigUint::zero(); - user_entry.unbond_epoch = u64::MAX; - entry_mapper.set(&user_entry); - - Some(&user_entry) - }; - - let locked_asset_token_id = self.locked_asset_token_id().get(); - self.send().direct_esdt( - &caller, - &locked_asset_token_id, - user_entry.token_nonce, - &unstake_amount, - ); - - self.unbond_event(&caller, opt_entry_after_action); - } - - #[view(getStakedAmountForUser)] - fn get_staked_amount_for_user(&self, user_address: ManagedAddress) -> BigUint { - let entry_mapper = self.entry_for_user(&user_address); - if entry_mapper.is_empty() { - BigUint::zero() - } else { - let entry: UserEntry = entry_mapper.get(); - - entry.stake_amount - } - } - - #[view(getUserEntry)] - fn get_user_entry(&self, user_address: ManagedAddress) -> OptionalValue> { - let entry_mapper = self.entry_for_user(&user_address); - - if !entry_mapper.is_empty() { - OptionalValue::Some(entry_mapper.get()) - } else { - OptionalValue::None - } - } - - #[view(getSnapshot)] - fn get_snapshot(&self) -> MultiValueEncoded> { - let mut result = MultiValueEncoded::new(); - - for user_address in self.user_list().iter() { - let entry: UserEntry = self.entry_for_user(&user_address).get(); - if entry.stake_amount > 0 { - result.push((user_address, entry.stake_amount).into()); - } - } - - result - } -} diff --git a/farm-staking/metabonding-staking/src/locked_asset_token.rs b/farm-staking/metabonding-staking/src/locked_asset_token.rs deleted file mode 100644 index c5c354fab..000000000 --- a/farm-staking/metabonding-staking/src/locked_asset_token.rs +++ /dev/null @@ -1,118 +0,0 @@ -multiversx_sc::imports!(); -multiversx_sc::derive_imports!(); - -use factory::locked_asset_token_merge::ProxyTrait as _; - -pub type PaymentsVec = ManagedVec>; - -#[derive(TypeAbi, TopEncode, TopDecode, NestedEncode, Debug, PartialEq)] -pub struct UserEntry { - pub token_nonce: u64, - pub stake_amount: BigUint, - pub unstake_amount: BigUint, - pub unbond_epoch: u64, -} - -impl UserEntry { - pub fn new(token_nonce: u64, stake_amount: BigUint) -> Self { - Self { - token_nonce, - stake_amount, - unstake_amount: BigUint::zero(), - unbond_epoch: u64::MAX, - } - } - - pub fn get_total_amount(&self) -> BigUint { - &self.stake_amount + &self.unstake_amount - } -} - -#[multiversx_sc::module] -pub trait LockedAssetTokenModule { - fn require_all_locked_asset_payments(&self, payments: &PaymentsVec) { - require!(!payments.is_empty(), "No payments"); - - let locked_asset_token_id = self.locked_asset_token_id().get(); - for p in payments { - require!( - p.token_identifier == locked_asset_token_id, - "Invalid payment" - ); - } - } - - fn create_new_entry_by_merging_tokens( - &self, - entry_mapper: &SingleValueMapper>, - mut new_tokens: PaymentsVec, - ) -> UserEntry { - if entry_mapper.is_empty() { - let merged_tokens = self.merge_locked_asset_tokens(new_tokens); - - return UserEntry::new(merged_tokens.token_nonce, merged_tokens.amount); - } - - let mut prev_entry: UserEntry = entry_mapper.get(); - let prev_entry_total_tokens = prev_entry.get_total_amount(); - self.total_locked_asset_supply() - .update(|total_supply| *total_supply -= &prev_entry_total_tokens); - - let prev_entry_as_payment = EsdtTokenPayment::new( - self.locked_asset_token_id().get(), - prev_entry.token_nonce, - prev_entry_total_tokens, - ); - new_tokens.push(prev_entry_as_payment); - - let merged_tokens = self.merge_locked_asset_tokens(new_tokens); - prev_entry.token_nonce = merged_tokens.token_nonce; - prev_entry.stake_amount = &merged_tokens.amount - &prev_entry.unstake_amount; - - prev_entry - } - - fn merge_locked_asset_tokens( - &self, - tokens: PaymentsVec, - ) -> EsdtTokenPayment { - if tokens.len() == 1 { - return tokens.get(0); - } - - let locked_asset_factory_address = self.locked_asset_factory_address().get(); - self.locked_asset_factory_proxy(locked_asset_factory_address) - .merge_tokens() - .with_multi_token_transfer(tokens) - .execute_on_dest_context() - } - - // proxies - - #[proxy] - fn locked_asset_factory_proxy(&self, sc_address: ManagedAddress) -> factory::Proxy; - - // storage - - #[view(getLockedAssetTokenId)] - #[storage_mapper("lockedAssetTokenId")] - fn locked_asset_token_id(&self) -> SingleValueMapper; - - #[view(getLockedAssetFactoryAddress)] - #[storage_mapper("lockedAssetFactoryAddress")] - fn locked_asset_factory_address(&self) -> SingleValueMapper; - - #[view(getTotalLockedAssetSupply)] - #[storage_mapper("totalLockedAssetSupply")] - fn total_locked_asset_supply(&self) -> SingleValueMapper; - - #[storage_mapper("entryForUser")] - fn entry_for_user( - &self, - user_address: &ManagedAddress, - ) -> SingleValueMapper>; - - #[view(getUserList)] - #[storage_mapper("userList")] - fn user_list(&self) -> UnorderedSetMapper; -} diff --git a/farm-staking/metabonding-staking/tests/metabonding_staking_setup/mod.rs b/farm-staking/metabonding-staking/tests/metabonding_staking_setup/mod.rs deleted file mode 100644 index a4b8effeb..000000000 --- a/farm-staking/metabonding-staking/tests/metabonding_staking_setup/mod.rs +++ /dev/null @@ -1,251 +0,0 @@ -#![allow(deprecated)] - -use common_structs::{ - LockedAssetTokenAttributesEx, UnlockMilestone, UnlockMilestoneEx, UnlockScheduleEx, -}; -use factory::locked_asset::LockedAssetModule; -use factory::*; -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_legacy::{TxResult, TxTokenTransfer}; -use multiversx_sc_scenario::{ - managed_address, managed_biguint, managed_token_id, rust_biguint, whitebox_legacy::*, DebugApi, -}; - -pub const METABONDING_STAKING_WASM_PATH: &str = "1.wasm"; -pub const LOCKED_ASSET_FACTORY_WASM_PATH: &str = "2.wasm"; -pub const ASSET_TOKEN_ID: &[u8] = b"MEX-123456"; -pub const LOCKED_ASSET_TOKEN_ID: &[u8] = b"LKMEX-123456"; - -pub struct MetabondingStakingSetup -where - MetabondingStakingObjBuilder: - 'static + Copy + Fn() -> metabonding_staking::ContractObj, - LockedAssetFactoryObjBuilder: 'static + Copy + Fn() -> factory::ContractObj, -{ - pub b_mock: BlockchainStateWrapper, - pub owner_address: Address, - pub user_address: Address, - pub mbs_wrapper: ContractObjWrapper< - metabonding_staking::ContractObj, - MetabondingStakingObjBuilder, - >, - pub laf_wrapper: - ContractObjWrapper, LockedAssetFactoryObjBuilder>, -} - -impl - MetabondingStakingSetup -where - MetabondingStakingObjBuilder: - 'static + Copy + Fn() -> metabonding_staking::ContractObj, - LockedAssetFactoryObjBuilder: 'static + Copy + Fn() -> factory::ContractObj, -{ - pub fn new( - mbs_builder: MetabondingStakingObjBuilder, - laf_builder: LockedAssetFactoryObjBuilder, - ) -> Self { - DebugApi::dummy(); - - let rust_zero = rust_biguint!(0u64); - let mut b_mock = BlockchainStateWrapper::new(); - let owner_addr = b_mock.create_user_account(&rust_zero); - let user_addr = b_mock.create_user_account(&rust_zero); - - let laf_wrapper = b_mock.create_sc_account( - &rust_zero, - Some(&owner_addr), - laf_builder, - LOCKED_ASSET_FACTORY_WASM_PATH, - ); - let mbs_wrapper = b_mock.create_sc_account( - &rust_zero, - Some(&owner_addr), - mbs_builder, - METABONDING_STAKING_WASM_PATH, - ); - - // set initial user balance - - // 100_000_000 - let attr1 = LockedAssetTokenAttributesEx:: { - unlock_schedule: UnlockScheduleEx { - unlock_milestones: ManagedVec::from(vec![ - UnlockMilestoneEx { - unlock_epoch: 0, - unlock_percent: 10_000, - }, - UnlockMilestoneEx { - unlock_epoch: 360, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 390, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 420, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 450, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 480, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 510, - unlock_percent: 15_000, - }, - ]), - }, - is_merged: false, - }; - // 1_000_000 - let attr2 = LockedAssetTokenAttributesEx:: { - unlock_schedule: UnlockScheduleEx { - unlock_milestones: ManagedVec::from(vec![ - UnlockMilestoneEx { - unlock_epoch: 360, - unlock_percent: 16_000, - }, - UnlockMilestoneEx { - unlock_epoch: 390, - unlock_percent: 16_000, - }, - UnlockMilestoneEx { - unlock_epoch: 420, - unlock_percent: 17_000, - }, - UnlockMilestoneEx { - unlock_epoch: 450, - unlock_percent: 17_000, - }, - UnlockMilestoneEx { - unlock_epoch: 480, - unlock_percent: 17_000, - }, - UnlockMilestoneEx { - unlock_epoch: 510, - unlock_percent: 17_000, - }, - ]), - }, - is_merged: false, - }; - - b_mock.set_nft_balance( - &user_addr, - LOCKED_ASSET_TOKEN_ID, - 3, - &rust_biguint!(100_000_000), - &attr1, - ); - b_mock.set_nft_balance( - &user_addr, - LOCKED_ASSET_TOKEN_ID, - 4, - &rust_biguint!(1_000_000), - &attr2, - ); - - // init Locked Asset Factory contract - - b_mock - .execute_tx(&owner_addr, &laf_wrapper, &rust_zero, |sc| { - let asset_token_id = managed_token_id!(ASSET_TOKEN_ID); - let unlocked_percents = ManagedVec::from_single_item(UnlockMilestone { - unlock_epoch: 5, - unlock_percent: 100, - }); - - sc.init(asset_token_id, unlocked_percents.into()); - - let locked_asset_token_id = managed_token_id!(LOCKED_ASSET_TOKEN_ID); - sc.locked_asset_token().set_token_id(locked_asset_token_id); - - sc.set_paused(false); - }) - .assert_ok(); - - let locked_asset_token_roles = [ - EsdtLocalRole::NftCreate, - EsdtLocalRole::NftAddQuantity, - EsdtLocalRole::NftBurn, - ]; - b_mock.set_esdt_local_roles( - laf_wrapper.address_ref(), - LOCKED_ASSET_TOKEN_ID, - &locked_asset_token_roles[..], - ); - - // init Metabonding Staking contract - - b_mock - .execute_tx(&owner_addr, &mbs_wrapper, &rust_zero, |sc| { - let locked_asset_token_id = managed_token_id!(LOCKED_ASSET_TOKEN_ID); - let locked_asset_factory_addr = managed_address!(laf_wrapper.address_ref()); - - sc.init(locked_asset_token_id, locked_asset_factory_addr); - }) - .assert_ok(); - - Self { - b_mock, - laf_wrapper, - mbs_wrapper, - owner_address: owner_addr, - user_address: user_addr, - } - } - - pub fn call_stake_locked_asset(&mut self, token_nonce: u64, amount: u64) -> TxResult { - self.b_mock.execute_esdt_transfer( - &self.user_address, - &self.mbs_wrapper, - LOCKED_ASSET_TOKEN_ID, - token_nonce, - &rust_biguint!(amount), - |sc| { - sc.stake_locked_asset(); - }, - ) - } - - pub fn call_stake_locked_asset_multiple(&mut self, payments: &[TxTokenTransfer]) -> TxResult { - self.b_mock.execute_esdt_multi_transfer( - &self.user_address, - &self.mbs_wrapper, - payments, - |sc| { - sc.stake_locked_asset(); - }, - ) - } - - pub fn call_unstake(&mut self, amount: u64) -> TxResult { - self.b_mock.execute_tx( - &self.user_address, - &self.mbs_wrapper, - &rust_biguint!(0), - |sc| { - sc.unstake(managed_biguint!(amount)); - }, - ) - } - - pub fn call_unbond(&mut self) -> TxResult { - self.b_mock.execute_tx( - &self.user_address, - &self.mbs_wrapper, - &rust_biguint!(0), - |sc| { - sc.unbond(); - }, - ) - } -} diff --git a/farm-staking/metabonding-staking/tests/metabonding_staking_test.rs b/farm-staking/metabonding-staking/tests/metabonding_staking_test.rs deleted file mode 100644 index c83be6726..000000000 --- a/farm-staking/metabonding-staking/tests/metabonding_staking_test.rs +++ /dev/null @@ -1,342 +0,0 @@ -#![allow(deprecated)] - -pub mod metabonding_staking_setup; -use metabonding_staking::{ - locked_asset_token::{LockedAssetTokenModule, UserEntry}, - UNBOND_EPOCHS, -}; -use metabonding_staking_setup::*; -use multiversx_sc_scenario::{ - managed_address, managed_biguint, rust_biguint, whitebox_legacy::TxTokenTransfer, -}; - -#[test] -fn test_init() { - let _ = MetabondingStakingSetup::new(metabonding_staking::contract_obj, factory::contract_obj); -} - -#[test] -fn test_stake_first() { - let mut setup = - MetabondingStakingSetup::new(metabonding_staking::contract_obj, factory::contract_obj); - setup.call_stake_locked_asset(3, 100_000_000).assert_ok(); - - let user_addr = setup.user_address.clone(); - setup - .b_mock - .execute_query(&setup.mbs_wrapper, |sc| { - let expected_entry = UserEntry::new(3, managed_biguint!(100_000_000)); - let actual_entry = sc.entry_for_user(&managed_address!(&user_addr)).get(); - assert_eq!(actual_entry, expected_entry); - }) - .assert_ok(); -} - -#[test] -fn test_stake_second() { - let mut setup = - MetabondingStakingSetup::new(metabonding_staking::contract_obj, factory::contract_obj); - setup.call_stake_locked_asset(3, 100_000_000).assert_ok(); - - setup - .b_mock - .execute_query(&setup.mbs_wrapper, |sc| { - let expected_supply = managed_biguint!(100_000_000); - let actual_supply = sc.total_locked_asset_supply().get(); - assert_eq!(actual_supply, expected_supply); - }) - .assert_ok(); - - setup.call_stake_locked_asset(4, 1_000_000).assert_ok(); - - setup - .b_mock - .execute_query(&setup.mbs_wrapper, |sc| { - let expected_supply = managed_biguint!(101_000_000); - let actual_supply = sc.total_locked_asset_supply().get(); - assert_eq!(actual_supply, expected_supply); - }) - .assert_ok(); - - // tokens are merged into a single one - let user_addr = setup.user_address.clone(); - setup - .b_mock - .execute_query(&setup.mbs_wrapper, |sc| { - let expected_entry = UserEntry::new(1, managed_biguint!(101_000_000)); - let actual_entry = sc.entry_for_user(&managed_address!(&user_addr)).get(); - assert_eq!(actual_entry, expected_entry); - }) - .assert_ok(); -} - -#[test] -fn test_stake_multiple() { - let mut setup = - MetabondingStakingSetup::new(metabonding_staking::contract_obj, factory::contract_obj); - let payments = [ - TxTokenTransfer { - token_identifier: LOCKED_ASSET_TOKEN_ID.to_vec(), - nonce: 3, - value: rust_biguint!(100_000_000), - }, - TxTokenTransfer { - token_identifier: LOCKED_ASSET_TOKEN_ID.to_vec(), - nonce: 4, - value: rust_biguint!(1_000_000), - }, - ]; - - setup - .call_stake_locked_asset_multiple(&payments) - .assert_ok(); - - // tokens are merged into a single one - let user_addr = setup.user_address.clone(); - setup - .b_mock - .execute_query(&setup.mbs_wrapper, |sc| { - let expected_entry = UserEntry::new(1, managed_biguint!(101_000_000)); - let actual_entry = sc.entry_for_user(&managed_address!(&user_addr)).get(); - assert_eq!(actual_entry, expected_entry); - }) - .assert_ok(); -} - -#[test] -fn test_unstake() { - let mut setup = - MetabondingStakingSetup::new(metabonding_staking::contract_obj, factory::contract_obj); - setup.call_stake_locked_asset(3, 100_000_000).assert_ok(); - setup.call_stake_locked_asset(4, 1_000_000).assert_ok(); - - // tokens are merged into a single one - let user_addr = setup.user_address.clone(); - setup - .b_mock - .execute_query(&setup.mbs_wrapper, |sc| { - let expected_entry = UserEntry::new(1, managed_biguint!(101_000_000)); - let actual_entry = sc.entry_for_user(&managed_address!(&user_addr)).get(); - assert_eq!(actual_entry, expected_entry); - }) - .assert_ok(); - - setup.call_unstake(101_000_000).assert_ok(); - setup - .b_mock - .execute_query(&setup.mbs_wrapper, |sc| { - let expected_entry = UserEntry { - token_nonce: 1, - stake_amount: managed_biguint!(0), - unstake_amount: managed_biguint!(101_000_000), - unbond_epoch: 3, - }; - let actual_entry = sc.entry_for_user(&managed_address!(&user_addr)).get(); - assert_eq!(actual_entry, expected_entry); - }) - .assert_ok(); - - // try unstake again - setup - .call_unstake(101_000_000) - .assert_user_error("Trying to unstake too much"); -} - -#[test] -fn test_partial_unstake() { - let mut setup = - MetabondingStakingSetup::new(metabonding_staking::contract_obj, factory::contract_obj); - setup.call_stake_locked_asset(3, 90_000_000).assert_ok(); - setup.call_stake_locked_asset(4, 1_000_000).assert_ok(); - - // tokens are merged into a single one - let user_addr = setup.user_address.clone(); - setup - .b_mock - .execute_query(&setup.mbs_wrapper, |sc| { - let expected_entry = UserEntry::new(1, managed_biguint!(91_000_000)); - let actual_entry = sc.entry_for_user(&managed_address!(&user_addr)).get(); - assert_eq!(actual_entry, expected_entry); - }) - .assert_ok(); - - setup.call_unstake(51_000_000).assert_ok(); - setup - .b_mock - .execute_query(&setup.mbs_wrapper, |sc| { - let expected_entry = UserEntry { - token_nonce: 1, - stake_amount: managed_biguint!(40_000_000), - unstake_amount: managed_biguint!(51_000_000), - unbond_epoch: 3, - }; - let actual_entry = sc.entry_for_user(&managed_address!(&user_addr)).get(); - assert_eq!(actual_entry, expected_entry); - }) - .assert_ok(); - - // unstake too much - setup - .call_unstake(101_000_000) - .assert_user_error("Trying to unstake too much"); - - // unstake ok - setup.b_mock.set_block_epoch(5); - setup.call_unstake(30_000_000).assert_ok(); - - setup - .b_mock - .execute_query(&setup.mbs_wrapper, |sc| { - let expected_entry = UserEntry { - token_nonce: 1, - stake_amount: managed_biguint!(10_000_000), - unstake_amount: managed_biguint!(81_000_000), - unbond_epoch: 8, - }; - let actual_entry = sc.entry_for_user(&managed_address!(&user_addr)).get(); - assert_eq!(actual_entry, expected_entry); - }) - .assert_ok(); - - // stake after unstake - setup.call_stake_locked_asset(3, 10_000_000).assert_ok(); - - setup - .b_mock - .execute_query(&setup.mbs_wrapper, |sc| { - let expected_entry = UserEntry { - token_nonce: 2, - stake_amount: managed_biguint!(20_000_000), - unstake_amount: managed_biguint!(81_000_000), - unbond_epoch: 8, - }; - let actual_entry = sc.entry_for_user(&managed_address!(&user_addr)).get(); - assert_eq!(actual_entry, expected_entry); - }) - .assert_ok(); - - // unbond - - setup.b_mock.set_block_epoch(15); - setup.call_unbond().assert_ok(); - - setup - .b_mock - .execute_query(&setup.mbs_wrapper, |sc| { - let expected_entry = UserEntry { - token_nonce: 2, - stake_amount: managed_biguint!(20_000_000), - unstake_amount: managed_biguint!(0), - unbond_epoch: u64::MAX, - }; - let actual_entry = sc.entry_for_user(&managed_address!(&user_addr)).get(); - assert_eq!(actual_entry, expected_entry); - }) - .assert_ok(); - - // checking attributes for LKMEX tokens is out of scope - // so we just check with the raw expected value - let attributes: Vec = vec![ - 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 38, 173, 0, 0, 0, 0, 0, 0, 1, 104, 0, - 0, 0, 0, 0, 0, 58, 162, 0, 0, 0, 0, 0, 0, 1, 134, 0, 0, 0, 0, 0, 0, 58, 162, 0, 0, 0, 0, 0, - 0, 1, 164, 0, 0, 0, 0, 0, 0, 58, 171, 0, 0, 0, 0, 0, 0, 1, 194, 0, 0, 0, 0, 0, 0, 58, 172, - 0, 0, 0, 0, 0, 0, 1, 224, 0, 0, 0, 0, 0, 0, 58, 172, 0, 0, 0, 0, 0, 0, 1, 254, 0, 0, 0, 0, - 0, 0, 58, 172, 1, - ]; - setup.b_mock.check_nft_balance( - &setup.user_address, - LOCKED_ASSET_TOKEN_ID, - 2, - &rust_biguint!(81_000_000), - Some(&attributes), - ); -} - -#[test] -fn test_unbond() { - let mut setup = - MetabondingStakingSetup::new(metabonding_staking::contract_obj, factory::contract_obj); - - setup.call_stake_locked_asset(3, 100_000_000).assert_ok(); - setup.call_stake_locked_asset(4, 1_000_000).assert_ok(); - - // tokens are merged into a single one - let user_addr = setup.user_address.clone(); - setup - .b_mock - .execute_query(&setup.mbs_wrapper, |sc| { - let expected_entry = UserEntry::new(1, managed_biguint!(101_000_000)); - let actual_entry = sc.entry_for_user(&managed_address!(&user_addr)).get(); - assert_eq!(actual_entry, expected_entry); - }) - .assert_ok(); - - // try unbond before unstake - setup.call_unbond().assert_user_error("Must unstake first"); - - setup.call_unstake(101_000_000).assert_ok(); - setup - .b_mock - .execute_query(&setup.mbs_wrapper, |sc| { - let expected_entry = UserEntry { - token_nonce: 1, - stake_amount: managed_biguint!(0), - unstake_amount: managed_biguint!(101_000_000), - unbond_epoch: 3, - }; - let actual_entry = sc.entry_for_user(&managed_address!(&user_addr)).get(); - assert_eq!(actual_entry, expected_entry); - }) - .assert_ok(); - - setup - .b_mock - .execute_query(&setup.mbs_wrapper, |sc| { - let expected_supply = managed_biguint!(101_000_000); - let actual_supply = sc.total_locked_asset_supply().get(); - assert_eq!(actual_supply, expected_supply); - }) - .assert_ok(); - - // try unbond too early - setup - .call_unbond() - .assert_user_error("Unbond period in progress"); - - setup.b_mock.set_block_epoch(UNBOND_EPOCHS); - setup.call_unbond().assert_ok(); - - setup - .b_mock - .execute_query(&setup.mbs_wrapper, |sc| { - let expected_supply = managed_biguint!(0); - let actual_supply = sc.total_locked_asset_supply().get(); - assert_eq!(actual_supply, expected_supply); - }) - .assert_ok(); - - // checking attributes for LKMEX tokens is out of scope - // so we just check with the raw expected value - let attributes: Vec = vec![ - 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 38, 173, 0, 0, 0, 0, 0, 0, 1, 104, 0, - 0, 0, 0, 0, 0, 58, 162, 0, 0, 0, 0, 0, 0, 1, 134, 0, 0, 0, 0, 0, 0, 58, 162, 0, 0, 0, 0, 0, - 0, 1, 164, 0, 0, 0, 0, 0, 0, 58, 171, 0, 0, 0, 0, 0, 0, 1, 194, 0, 0, 0, 0, 0, 0, 58, 172, - 0, 0, 0, 0, 0, 0, 1, 224, 0, 0, 0, 0, 0, 0, 58, 172, 0, 0, 0, 0, 0, 0, 1, 254, 0, 0, 0, 0, - 0, 0, 58, 172, 1, - ]; - setup.b_mock.check_nft_balance( - &setup.user_address, - LOCKED_ASSET_TOKEN_ID, - 1, - &rust_biguint!(101_000_000), - Some(&attributes), - ); - - setup - .b_mock - .execute_query(&setup.mbs_wrapper, |sc| { - let entry_is_empty = sc.entry_for_user(&managed_address!(&user_addr)).is_empty(); - assert!(entry_is_empty); - }) - .assert_ok(); -} diff --git a/locked-asset/distribution/.gitignore b/legacy-contracts/factory-legacy/.gitignore similarity index 100% rename from locked-asset/distribution/.gitignore rename to legacy-contracts/factory-legacy/.gitignore diff --git a/legacy-contracts/factory-legacy/Cargo.toml b/legacy-contracts/factory-legacy/Cargo.toml new file mode 100644 index 000000000..f2f530ddb --- /dev/null +++ b/legacy-contracts/factory-legacy/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "factory-legacy" +publish = false +version = "0.0.0" +edition = "2018" + +[lib] +path = "src/lib.rs" + +[dependencies.multiversx-sc] +version = "=0.53.2" +features = ["esdt-token-payment-legacy-decode"] + +[dependencies.multiversx-sc-modules] +version = "=0.53.2" + +[dependencies.common_structs] +path = "../../common/common_structs" + +[dependencies.common_errors] +path = "../../common/common_errors" + +[dependencies.token_merge_helper] +path = "../../common/modules/token_merge_helper" + +[dependencies.energy-factory] +path = "../../locked-asset/energy-factory" + +[dev-dependencies.multiversx-sc-scenario] +version = "=0.53.2" diff --git a/legacy-contracts/factory-legacy/README.md b/legacy-contracts/factory-legacy/README.md new file mode 100644 index 000000000..b61d85ad8 --- /dev/null +++ b/legacy-contracts/factory-legacy/README.md @@ -0,0 +1,26 @@ +# Locked Asset Factory Smart Contract + +This document presents how one can deploy and configure a Locked Asset Factory Contract. +The bigger picture about what a Locked Asset Factory Contract can do can be found in the Repository's Root Readme. + +## Deployment + +The Locked Asset Factory contract can be deployed using `erdpy` and using the interraction 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. + +- default_unlock_period. A vector of unlock milestones. This represents a period since each epoch in the vector will be added with a starting epoch. + +The Contract requires LocalMint and LocalBurn for asset token. + +## Creating and Forwarding SFTs + +Before creating LockedAssetLockens, the owner has to issue those tokens using `issueLockedAssetToken` and after this he also has to give the NftCreate, NftAddQuantity and NftBurn roles to the contract unsing `setLocalRolesLockedAssetToken`. + +The Contract has an endpoint `createAndForward` that can be called in order to request an amount of Locked MEX. Only those addresses in the `whitelisted_contracts` set can call this endpoint. This whitelist can be configured by the admin using `whitelist` and `removeWhitelist` endpoints. + +## Unlocking MEX + +A user that has Locked MEX can unlock it and can receive the Locked MEX "remaining" and the unlocked MEX amount. The newly created Locked MEX will have its unlock milestones re-calculated such that the percents unlocking schedule will be updated to the new locked amount. For example: if default_unlock_period is `0x000000000000000232`, `0x000000000000000432` it would mean that after `0000000000000002` epochs, should unlock `32`.to_dec() (`50`) percent of the amount. After the first unlock at epoch 3 let's say, the next unlock milestone will be recalculated as `0x000000000000000464`. Notice the `50%` become `100%`. diff --git a/legacy-contracts/factory-legacy/meta/Cargo.toml b/legacy-contracts/factory-legacy/meta/Cargo.toml new file mode 100644 index 000000000..494ceb42f --- /dev/null +++ b/legacy-contracts/factory-legacy/meta/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "factory-legacy-meta" +version = "0.0.0" +authors = ["you"] +edition = "2018" +publish = false + +[dependencies.factory-legacy] +path = ".." + +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" +default-features = false diff --git a/legacy-contracts/factory-legacy/meta/src/main.rs b/legacy-contracts/factory-legacy/meta/src/main.rs new file mode 100644 index 000000000..dd22822dc --- /dev/null +++ b/legacy-contracts/factory-legacy/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta_lib::cli_main::(); +} \ No newline at end of file diff --git a/legacy-contracts/factory-legacy/multiversx.json b/legacy-contracts/factory-legacy/multiversx.json new file mode 100644 index 000000000..c2cab7433 --- /dev/null +++ b/legacy-contracts/factory-legacy/multiversx.json @@ -0,0 +1,4 @@ +{ + "language": "rust" +} + diff --git a/locked-asset/factory/src/attr_ex_helper.rs b/legacy-contracts/factory-legacy/src/attr_ex_helper.rs similarity index 74% rename from locked-asset/factory/src/attr_ex_helper.rs rename to legacy-contracts/factory-legacy/src/attr_ex_helper.rs index 19cf16aa1..322bb0b73 100644 --- a/locked-asset/factory/src/attr_ex_helper.rs +++ b/legacy-contracts/factory-legacy/src/attr_ex_helper.rs @@ -1,11 +1,16 @@ +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + use common_structs::LockedAssetTokenAttributes; use common_structs::LockedAssetTokenAttributesEx; use common_structs::UnlockMilestoneEx; use common_structs::UnlockScheduleEx; -use common_structs::PRECISION_EX_INCREASE; -multiversx_sc::imports!(); -multiversx_sc::derive_imports!(); +// 1% = 1_000; +pub const _PRECISION_EXTENDED: u64 = 100_000u64; + +// From 1 to 1_000; +pub const PRECISION_EX_INCREASE: u64 = 1_000u64; #[multiversx_sc::module] pub trait AttrExHelper { @@ -13,6 +18,7 @@ pub trait AttrExHelper { &self, token_id: &TokenIdentifier, token_nonce: u64, + attr_ex_activation: u64, ) -> LockedAssetTokenAttributesEx { let token_info = self.blockchain().get_esdt_token_data( &self.blockchain().get_sc_address(), @@ -20,12 +26,18 @@ pub trait AttrExHelper { token_nonce, ); - let attr_ex_activation = self.extended_attributes_activation_nonce().get(); if token_nonce < attr_ex_activation { - let attr: LockedAssetTokenAttributes = token_info.decode_attributes(); + let attr = self + .serializer() + .top_decode_from_managed_buffer::>( + &token_info.attributes, + ); self.convert_attr_to_attr_ex(&attr) } else { - token_info.decode_attributes() + self.serializer() + .top_decode_from_managed_buffer::>( + &token_info.attributes, + ) } } diff --git a/locked-asset/factory/src/cache.rs b/legacy-contracts/factory-legacy/src/cache.rs similarity index 91% rename from locked-asset/factory/src/cache.rs rename to legacy-contracts/factory-legacy/src/cache.rs index 456011acf..24d1a031d 100644 --- a/locked-asset/factory/src/cache.rs +++ b/legacy-contracts/factory-legacy/src/cache.rs @@ -8,9 +8,7 @@ use crate::attr_ex_helper; use super::locked_asset; #[multiversx_sc::module] -pub trait CacheModule: - locked_asset::LockedAssetModule + token_send::TokenSendModule + attr_ex_helper::AttrExHelper -{ +pub trait CacheModule: locked_asset::LockedAssetModule + attr_ex_helper::AttrExHelper { #[inline(always)] fn get_sft_nonce_for_unlock_schedule( &self, diff --git a/locked-asset/factory/src/events.rs b/legacy-contracts/factory-legacy/src/events.rs similarity index 68% rename from locked-asset/factory/src/events.rs rename to legacy-contracts/factory-legacy/src/events.rs index 6507cece0..149c7af5c 100644 --- a/locked-asset/factory/src/events.rs +++ b/legacy-contracts/factory-legacy/src/events.rs @@ -41,10 +41,10 @@ pub trait EventsModule { self, caller: &ManagedAddress, destination: &ManagedAddress, - locked_asset_token_id: TokenIdentifier, + locked_asset_token_id: &TokenIdentifier, locked_asset_token_nonce: u64, - locked_asset_token_amount: BigUint, - locked_assets_attributes: LockedAssetTokenAttributesEx, + locked_asset_token_amount: &BigUint, + locked_assets_attributes: &LockedAssetTokenAttributesEx, start_epoch: u64, ) { let epoch = self.blockchain().get_block_epoch(); @@ -55,10 +55,10 @@ pub trait EventsModule { &CreateAndForwardEvent { caller: caller.clone(), destination: destination.clone(), - locked_asset_token_id, + locked_asset_token_id: locked_asset_token_id.clone(), locked_asset_token_nonce, - locked_asset_token_amount, - locked_assets_attributes, + locked_asset_token_amount: locked_asset_token_amount.clone(), + locked_assets_attributes: locked_assets_attributes.clone(), start_epoch, block: self.blockchain().get_block_nonce(), epoch, @@ -70,16 +70,16 @@ pub trait EventsModule { fn emit_unlock_assets_event( self, caller: &ManagedAddress, - input_locked_assets_token_id: TokenIdentifier, + input_locked_assets_token_id: &TokenIdentifier, input_locked_assets_token_nonce: u64, - input_locked_assets_token_amount: BigUint, - output_locked_assets_token_id: TokenIdentifier, + input_locked_assets_token_amount: &BigUint, + output_locked_assets_token_id: &TokenIdentifier, output_locked_assets_token_nonce: u64, - output_locked_assets_token_amount: BigUint, - asset_token_id: TokenIdentifier, - asset_token_amount: BigUint, - input_assets_attributes: LockedAssetTokenAttributesEx, - output_assets_attributes: LockedAssetTokenAttributesEx, + output_locked_assets_token_amount: &BigUint, + asset_token_id: &TokenIdentifier, + asset_token_amount: &BigUint, + input_assets_attributes: &LockedAssetTokenAttributesEx, + output_assets_attributes: &LockedAssetTokenAttributesEx, ) { let epoch = self.blockchain().get_block_epoch(); self.unlock_assets_event( @@ -87,16 +87,16 @@ pub trait EventsModule { epoch, &UnlockAssetsEvent { caller: caller.clone(), - input_locked_assets_token_id, + input_locked_assets_token_id: input_locked_assets_token_id.clone(), input_locked_assets_token_nonce, - input_locked_assets_token_amount, - output_locked_assets_token_id, + input_locked_assets_token_amount: input_locked_assets_token_amount.clone(), + output_locked_assets_token_id: output_locked_assets_token_id.clone(), output_locked_assets_token_nonce, - output_locked_assets_token_amount, - asset_token_id, - asset_token_amount, - input_assets_attributes, - output_assets_attributes, + output_locked_assets_token_amount: output_locked_assets_token_amount.clone(), + asset_token_id: asset_token_id.clone(), + asset_token_amount: asset_token_amount.clone(), + input_assets_attributes: input_assets_attributes.clone(), + output_assets_attributes: output_assets_attributes.clone(), block: self.blockchain().get_block_nonce(), epoch, timestamp: self.blockchain().get_block_timestamp(), diff --git a/locked-asset/factory/src/lib.rs b/legacy-contracts/factory-legacy/src/lib.rs similarity index 52% rename from locked-asset/factory/src/lib.rs rename to legacy-contracts/factory-legacy/src/lib.rs index d8de993b4..1a5f01ad3 100644 --- a/locked-asset/factory/src/lib.rs +++ b/legacy-contracts/factory-legacy/src/lib.rs @@ -1,101 +1,69 @@ #![no_std] -#![feature(exact_size_is_empty)] -mod attr_ex_helper; +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +use attr_ex_helper::PRECISION_EX_INCREASE; +use common_structs::{ + Epoch, LockedAssetTokenAttributesEx, UnlockMilestoneEx, UnlockPeriod, UnlockScheduleEx, +}; + +pub mod attr_ex_helper; mod cache; mod events; pub mod locked_asset; pub mod locked_asset_token_merge; pub mod migration; -multiversx_sc::imports!(); -multiversx_sc::derive_imports!(); - const ADDITIONAL_AMOUNT_TO_CREATE: u64 = 1; -const FIRST_TOKEN_NONCE: u64 = 1; const EPOCHS_IN_MONTH: u64 = 30; -use common_structs::{ - Epoch, LockedAssetTokenAttributesEx, UnlockMilestone, UnlockMilestoneEx, UnlockPeriod, - UnlockSchedule, UnlockScheduleEx, PRECISION_EX_INCREASE, -}; +#[derive(TypeAbi, TopEncode, TopDecode)] +pub struct OldEsdtTokenPayment { + pub token_type: EsdtTokenType, + pub payment: EsdtTokenPayment, +} + +impl OldEsdtTokenPayment { + pub fn new(payment: EsdtTokenPayment) -> Self { + Self { + token_type: payment.token_type(), + payment, + } + } +} #[multiversx_sc::contract] pub trait LockedAssetFactory: locked_asset::LockedAssetModule + cache::CacheModule - + token_send::TokenSendModule + token_merge_helper::TokenMergeHelperModule + locked_asset_token_merge::LockedAssetTokenMergeModule + events::EventsModule + attr_ex_helper::AttrExHelper - + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule + migration::LockedTokenMigrationModule + multiversx_sc_modules::pause::PauseModule { #[init] - fn init( - &self, - asset_token_id: TokenIdentifier, - default_unlock_period: MultiValueEncoded, - ) { - require!( - asset_token_id.is_valid_esdt_identifier(), - "Asset token ID is not a valid esdt identifier" - ); - - let unlock_milestones = default_unlock_period.to_vec(); - self.validate_unlock_milestones(&unlock_milestones); - - let is_sc_deploy = self.init_epoch().is_empty(); - if is_sc_deploy { - let current_epoch = self.blockchain().get_block_epoch(); - self.init_epoch().set(current_epoch); - } - self.set_extended_attributes_activation_nonce(!is_sc_deploy); - - if self.asset_token_id().is_empty() { - self.asset_token_id().set(&asset_token_id); - } - self.default_unlock_period() - .set(&UnlockPeriod { unlock_milestones }); - + fn init(&self) { self.set_paused(true); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} - fn set_extended_attributes_activation_nonce(&self, is_sc_upgrade: bool) { - if !self.extended_attributes_activation_nonce().is_empty() { - return; - } - - if is_sc_upgrade { - let token_id = self.locked_asset_token().get_token_id(); - let own_sc_address = self.blockchain().get_sc_address(); - let current_nonce = self - .blockchain() - .get_current_esdt_nft_nonce(&own_sc_address, &token_id); - - self.extended_attributes_activation_nonce() - .set(current_nonce + 1); - } else { - self.extended_attributes_activation_nonce() - .set(FIRST_TOKEN_NONCE); - } - } - #[only_owner] #[endpoint] fn whitelist(&self, address: ManagedAddress) { - let _ = self.whitelisted_contracts().insert(address); + let is_new = self.whitelisted_contracts().insert(address); + require!(is_new, "ManagedAddress already whitelisted"); } #[only_owner] #[endpoint(removeWhitelist)] fn remove_whitelist(&self, address: ManagedAddress) { - let _ = self.whitelisted_contracts().remove(&address); + let is_removed = self.whitelisted_contracts().remove(&address); + require!(is_removed, "ManagedAddresss not whitelisted"); } #[endpoint(createAndForwardCustomPeriod)] @@ -105,7 +73,7 @@ pub trait LockedAssetFactory: address: ManagedAddress, start_epoch: Epoch, unlock_period: UnlockPeriod, - ) -> EsdtTokenPayment { + ) -> OldEsdtTokenPayment { self.require_not_paused(); let caller = self.blockchain().get_caller(); @@ -115,7 +83,25 @@ pub trait LockedAssetFactory: ); require!(!unlock_period.unlock_milestones.is_empty(), "Empty arg"); - self.common_create_and_forward(amount, &address, &caller, start_epoch, unlock_period) + let month_start_epoch = self.get_month_start_epoch(start_epoch); + let attr = LockedAssetTokenAttributesEx { + unlock_schedule: self.create_unlock_schedule(month_start_epoch, unlock_period), + is_merged: false, + }; + + let new_token = self.produce_tokens_and_send(&amount, &attr, &address); + + self.emit_create_and_forward_event( + &caller, + &address, + &new_token.token_identifier, + new_token.token_nonce, + &new_token.amount, + &attr, + month_start_epoch, + ); + + OldEsdtTokenPayment::new(new_token) } #[endpoint(createAndForward)] @@ -124,7 +110,7 @@ pub trait LockedAssetFactory: amount: BigUint, address: ManagedAddress, start_epoch: Epoch, - ) -> EsdtTokenPayment { + ) -> OldEsdtTokenPayment { self.require_not_paused(); let caller = self.blockchain().get_caller(); @@ -133,19 +119,31 @@ pub trait LockedAssetFactory: "Permission denied" ); require!( - !self.locked_asset_token().is_empty(), + !self.locked_asset_token_id().is_empty(), "Locked Asset Token not registered" ); require!(amount > 0, "Zero input amount"); - let default_unlock_period = self.default_unlock_period().get(); - self.common_create_and_forward( - amount, - &address, + let month_start_epoch = self.get_month_start_epoch(start_epoch); + let unlock_period = self.default_unlock_period().get(); + let attr = LockedAssetTokenAttributesEx { + unlock_schedule: self.create_unlock_schedule(month_start_epoch, unlock_period), + is_merged: false, + }; + + let new_token = self.produce_tokens_and_send(&amount, &attr, &address); + + self.emit_create_and_forward_event( &caller, + &address, + &new_token.token_identifier, + new_token.token_nonce, + &new_token.amount, + &attr, start_epoch, - default_unlock_period, - ) + ); + + OldEsdtTokenPayment::new(new_token) } #[payable("*")] @@ -154,13 +152,20 @@ pub trait LockedAssetFactory: self.require_not_paused(); let (token_id, token_nonce, amount) = self.call_value().single_esdt().into_tuple(); - let locked_token_id = self.locked_asset_token().get_token_id(); + let locked_token_id = self.locked_asset_token_id().get(); require!(token_id == locked_token_id, "Bad payment token"); + let attr_ex_activation = self.extended_attributes_activation_nonce().get(); + let attributes = self.get_attributes_ex(&token_id, token_nonce, attr_ex_activation); + let unlock_schedule = &attributes.unlock_schedule; + let month_start_epoch = self.get_month_start_epoch(self.blockchain().get_block_epoch()); - let attributes = self.get_attributes_ex(&token_id, token_nonce); - let amounts_per_epoch = attributes.get_unlock_amounts_per_epoch(&amount); - let unlock_amount = amounts_per_epoch.get_total_unlockable_amount(month_start_epoch); + let unlock_amount = self.get_unlock_amount( + &amount, + month_start_epoch, + &unlock_schedule.unlock_milestones, + ); + require!(amount >= unlock_amount, "Cannot unlock more than locked"); require!(unlock_amount > 0u64, "Method called too soon"); let caller = self.blockchain().get_caller(); @@ -177,14 +182,16 @@ pub trait LockedAssetFactory: let locked_remaining = &amount - &unlock_amount; if locked_remaining > 0u64 { - output_locked_asset_attributes = attributes.clone(); - output_locked_asset_attributes - .unlock_schedule - .clear_unlockable_entries(month_start_epoch); - output_locked_asset_attributes - .unlock_schedule - .reallocate_percentages(); - + let new_unlock_milestones = self.create_new_unlock_milestones( + month_start_epoch, + &unlock_schedule.unlock_milestones, + ); + output_locked_asset_attributes = LockedAssetTokenAttributesEx { + unlock_schedule: UnlockScheduleEx { + unlock_milestones: new_unlock_milestones, + }, + is_merged: attributes.is_merged, + }; output_locked_assets_token_amount = self.produce_tokens_and_send( &locked_remaining, &output_locked_asset_attributes, @@ -206,86 +213,23 @@ pub trait LockedAssetFactory: self.emit_unlock_assets_event( &caller, - token_id, + &token_id, token_nonce, - amount, - output_locked_assets_token_amount.token_identifier, + &amount, + &output_locked_assets_token_amount.token_identifier, output_locked_assets_token_amount.token_nonce, - output_locked_assets_token_amount.amount, - self.asset_token_id().get(), - unlock_amount, - attributes, - output_locked_asset_attributes, + &output_locked_assets_token_amount.amount, + &self.asset_token_id().get(), + &unlock_amount, + &attributes, + &output_locked_asset_attributes, ); } - #[payable("*")] - #[endpoint(lockAssets)] - fn lock_assets(&self) -> EsdtTokenPayment { - self.require_not_paused(); - - let (payment_token, payment_amount) = self.call_value().single_fungible_esdt(); - let caller = self.blockchain().get_caller(); - - let asset_token_id = self.asset_token_id().get(); - require!(payment_token == asset_token_id, "INVALID TOKEN PAYMENT"); - let block_epoch = self.blockchain().get_block_epoch(); - - self.send() - .esdt_local_burn(&payment_token, 0, &payment_amount); - - let default_unlock_period = self.default_unlock_period().get(); - self.common_create_and_forward( - payment_amount, - &caller, - &caller, - block_epoch, - default_unlock_period, - ) - } - - #[only_owner] - #[endpoint(setUnlockPeriod)] - fn set_unlock_period(&self, milestones: MultiValueEncoded) { - let unlock_milestones = milestones.to_vec(); - self.validate_unlock_milestones(&unlock_milestones); - self.default_unlock_period() - .set(&UnlockPeriod { unlock_milestones }); - } - fn get_month_start_epoch(&self, epoch: Epoch) -> Epoch { epoch - (epoch - self.init_epoch().get()) % EPOCHS_IN_MONTH } - fn common_create_and_forward( - &self, - amount: BigUint, - address: &ManagedAddress, - caller: &ManagedAddress, - start_epoch: Epoch, - unlock_period: UnlockSchedule, - ) -> EsdtTokenPayment { - let month_start_epoch = self.get_month_start_epoch(start_epoch); - let attr = LockedAssetTokenAttributesEx { - unlock_schedule: self.create_unlock_schedule(month_start_epoch, unlock_period), - is_merged: false, - }; - - let new_token = self.produce_tokens_and_send(&amount, &attr, address); - - self.emit_create_and_forward_event( - caller, - address, - new_token.token_identifier.clone(), - new_token.token_nonce, - new_token.amount.clone(), - attr, - start_epoch, - ); - - new_token - } - fn produce_tokens_and_send( &self, amount: &BigUint, @@ -293,9 +237,10 @@ pub trait LockedAssetFactory: address: &ManagedAddress, ) -> EsdtTokenPayment { let result = self.get_sft_nonce_for_unlock_schedule(&attributes.unlock_schedule); - match result { + let sent_nonce = match result { Option::Some(cached_nonce) => { - self.add_quantity_and_send_locked_assets(amount.clone(), cached_nonce, address) + self.add_quantity_and_send_locked_assets(amount, cached_nonce, address); + cached_nonce } Option::None => { let do_cache_result = !attributes.is_merged; @@ -306,7 +251,7 @@ pub trait LockedAssetFactory: BigUint::zero() }; - let new_tokens = self.create_and_send_locked_assets( + let new_nonce = self.create_and_send_locked_assets( amount, &additional_amount_to_create, address, @@ -314,35 +259,68 @@ pub trait LockedAssetFactory: ); if do_cache_result { - self.cache_unlock_schedule_and_nonce( - &attributes.unlock_schedule, - new_tokens.token_nonce, - ); + self.cache_unlock_schedule_and_nonce(&attributes.unlock_schedule, new_nonce); } - - new_tokens + new_nonce } - } + }; + + let token_id = self.locked_asset_token_id().get(); + EsdtTokenPayment::new(token_id, sent_nonce, amount.clone()) } #[only_owner] - #[payable("EGLD")] - #[endpoint(registerLockedAssetToken)] - fn register_locked_asset_token( - &self, - token_display_name: ManagedBuffer, - token_ticker: ManagedBuffer, - num_decimals: usize, - ) { - let payment_amount = self.call_value().egld_value().clone_value(); - self.locked_asset_token().issue_and_set_all_roles( - EsdtTokenType::Meta, - payment_amount, - token_display_name, - token_ticker, - num_decimals, - None, - ); + #[endpoint(setTransferRoleForAddress)] + fn set_transfer_role_for_address(&self, opt_address: OptionalValue) { + let address = match opt_address { + OptionalValue::Some(addr) => addr, + OptionalValue::None => self.blockchain().get_sc_address(), + }; + + self.send() + .esdt_system_sc_proxy() + .set_special_roles( + &address, + &self.locked_asset_token_id().get(), + [EsdtLocalRole::Transfer][..].iter().cloned(), + ) + .async_call_and_exit() + } + + #[only_owner] + #[endpoint(unsetTransferRoleForAddress)] + fn unset_transfer_role_for_address(&self, opt_address: OptionalValue) { + let address = match opt_address { + OptionalValue::Some(addr) => addr, + OptionalValue::None => self.blockchain().get_sc_address(), + }; + + self.send() + .esdt_system_sc_proxy() + .unset_special_roles( + &address, + &self.locked_asset_token_id().get(), + [EsdtLocalRole::Transfer][..].iter().cloned(), + ) + .async_call_and_exit() + } + + #[only_owner] + #[endpoint(setBurnRoleForAddress)] + fn set_burn_role_for_address(&self, opt_address: OptionalValue) { + let address = match opt_address { + OptionalValue::Some(addr) => addr, + OptionalValue::None => self.blockchain().get_sc_address(), + }; + + self.send() + .esdt_system_sc_proxy() + .set_special_roles( + &address, + &self.locked_asset_token_id().get(), + [EsdtLocalRole::NftBurn][..].iter().cloned(), + ) + .async_call_and_exit() } fn create_unlock_schedule( @@ -362,20 +340,26 @@ pub trait LockedAssetFactory: } } - #[only_owner] - #[endpoint(setInitEpoch)] - fn set_init_epoch(&self, init_epoch: Epoch) { - self.init_epoch().set(init_epoch); - } + #[view(getLastErrorMessage)] + #[storage_mapper("last_error_message")] + fn last_error_message(&self) -> SingleValueMapper; #[view(getInitEpoch)] #[storage_mapper("init_epoch")] fn init_epoch(&self) -> SingleValueMapper; - #[view(getWhitelistedContracts)] #[storage_mapper("whitelist")] fn whitelisted_contracts(&self) -> SetMapper; + #[view(getWhitelistedContracts)] + fn get_whitelisted_contracts(&self) -> MultiValueEncoded { + let mut result = MultiValueEncoded::new(); + for pair in self.whitelisted_contracts().iter() { + result.push(pair); + } + result + } + #[view(getDefaultUnlockPeriod)] #[storage_mapper("default_unlock_period")] fn default_unlock_period(&self) -> SingleValueMapper>; diff --git a/locked-asset/factory/src/locked_asset.rs b/legacy-contracts/factory-legacy/src/locked_asset.rs similarity index 76% rename from locked-asset/factory/src/locked_asset.rs rename to legacy-contracts/factory-legacy/src/locked_asset.rs index 85eb51636..a1e02cc8d 100644 --- a/locked-asset/factory/src/locked_asset.rs +++ b/legacy-contracts/factory-legacy/src/locked_asset.rs @@ -3,52 +3,70 @@ multiversx_sc::derive_imports!(); use common_structs::*; +use crate::attr_ex_helper::{self, PRECISION_EX_INCREASE}; + pub const ONE_MILLION: u64 = 1_000_000u64; pub const TEN_THOUSAND: u64 = 10_000u64; +pub const PERCENTAGE_TOTAL_EX: u64 = 100_000u64; +pub const MAX_MILESTONES_IN_SCHEDULE: usize = 64; pub const DOUBLE_MAX_MILESTONES_IN_SCHEDULE: usize = 2 * MAX_MILESTONES_IN_SCHEDULE; +use core::fmt::Debug; + #[derive(ManagedVecItem)] pub struct LockedTokenEx { pub token_amount: EsdtTokenPayment, pub attributes: LockedAssetTokenAttributesEx, } +#[derive(ManagedVecItem, Clone, Debug)] +pub struct EpochAmountPair { + pub epoch: u64, + pub amount: BigUint, +} + #[multiversx_sc::module] -pub trait LockedAssetModule: - token_send::TokenSendModule + crate::attr_ex_helper::AttrExHelper -{ +pub trait LockedAssetModule: attr_ex_helper::AttrExHelper { fn create_and_send_locked_assets( &self, amount: &BigUint, additional_amount_to_create: &BigUint, address: &ManagedAddress, attributes: &LockedAssetTokenAttributesEx, - ) -> EsdtTokenPayment { - let total_amount = amount + additional_amount_to_create; - let mut created_tokens = self - .locked_asset_token() - .nft_create(total_amount, attributes); - created_tokens.amount -= additional_amount_to_create; - - self.send().direct_esdt( - address, - &created_tokens.token_identifier, - created_tokens.token_nonce, - &created_tokens.amount, + ) -> Nonce { + let token_id = self.locked_asset_token_id().get(); + let last_created_nonce = self.send().esdt_nft_create_compact( + &token_id, + &(amount + additional_amount_to_create), + attributes, ); + self.send() + .direct_esdt(address, &token_id, last_created_nonce, amount); - created_tokens + last_created_nonce } - #[inline] fn add_quantity_and_send_locked_assets( &self, - amount: BigUint, + amount: &BigUint, sft_nonce: Nonce, address: &ManagedAddress, - ) -> EsdtTokenPayment { - self.locked_asset_token() - .nft_add_quantity_and_send(address, sft_nonce, amount) + ) { + let token_id = self.locked_asset_token_id().get(); + self.send().esdt_local_mint(&token_id, sft_nonce, amount); + + self.send() + .direct_esdt(address, &token_id, sft_nonce, amount); + } + + fn get_unlock_amount( + &self, + amount: &BigUint, + current_epoch: Epoch, + unlock_milestones: &ManagedVec, + ) -> BigUint { + amount * &BigUint::from(self.get_unlock_percent(current_epoch, unlock_milestones)) + / PERCENTAGE_TOTAL_EX } fn get_unlock_percent( @@ -64,11 +82,10 @@ pub trait LockedAssetModule: } } - if unlock_percent > PERCENTAGE_TOTAL_EX { - let mut err = self.error().new_error(); - err.append_bytes(&b"unlock percent greater than max"[..]); - err.exit_now(); - } + require!( + unlock_percent <= PERCENTAGE_TOTAL_EX, + "unlock percent greater than max" + ); unlock_percent } @@ -92,12 +109,10 @@ pub trait LockedAssetModule: let new_unlock_percent = old_milestone.unlock_percent * PRECISION_EX_INCREASE * ONE_MILLION / unlock_percent_remaining; - unsafe { - unlock_milestones_merged.push_unchecked(UnlockMilestoneEx { - unlock_epoch: old_milestone.unlock_epoch, - unlock_percent: new_unlock_percent, - }); - } + unlock_milestones_merged.push(UnlockMilestoneEx { + unlock_epoch: old_milestone.unlock_epoch, + unlock_percent: new_unlock_percent, + }); } } @@ -186,7 +201,7 @@ pub trait LockedAssetModule: #[view(getLockedAssetTokenId)] #[storage_mapper("locked_asset_token_id")] - fn locked_asset_token(&self) -> NonFungibleTokenMapper; + fn locked_asset_token_id(&self) -> SingleValueMapper; #[view(getAssetTokenId)] #[storage_mapper("asset_token_id")] diff --git a/locked-asset/factory/src/locked_asset_token_merge.rs b/legacy-contracts/factory-legacy/src/locked_asset_token_merge.rs similarity index 64% rename from locked-asset/factory/src/locked_asset_token_merge.rs rename to legacy-contracts/factory-legacy/src/locked_asset_token_merge.rs index 995d13528..8cb637658 100644 --- a/locked-asset/factory/src/locked_asset_token_merge.rs +++ b/legacy-contracts/factory-legacy/src/locked_asset_token_merge.rs @@ -3,42 +3,21 @@ multiversx_sc::derive_imports!(); use common_structs::*; -use crate::attr_ex_helper; +use crate::attr_ex_helper::{self, PRECISION_EX_INCREASE}; use super::locked_asset; -use super::locked_asset::{LockedTokenEx, DOUBLE_MAX_MILESTONES_IN_SCHEDULE, ONE_MILLION}; +use super::locked_asset::{ + EpochAmountPair, LockedTokenEx, DOUBLE_MAX_MILESTONES_IN_SCHEDULE, MAX_MILESTONES_IN_SCHEDULE, + ONE_MILLION, PERCENTAGE_TOTAL_EX, +}; #[multiversx_sc::module] pub trait LockedAssetTokenMergeModule: locked_asset::LockedAssetModule - + token_send::TokenSendModule + token_merge_helper::TokenMergeHelperModule + attr_ex_helper::AttrExHelper - + multiversx_sc_modules::pause::PauseModule { - #[payable("*")] - #[endpoint(mergeTokens)] - fn merge_tokens(&self) -> EsdtTokenPayment { - self.require_not_paused(); - - let caller = self.blockchain().get_caller(); - let payments_vec = self.call_value().all_esdt_transfers(); - require!(!payments_vec.is_empty(), "Empty payment vec"); - let payments_iter = payments_vec.iter(); - - let (amount, attrs) = - self.get_merged_locked_asset_token_amount_and_attributes(payments_iter.clone()); - - self.burn_tokens_from_payments(payments_iter); - - self.locked_asset_token() - .nft_create_and_send(&caller, amount, &attrs) - } - - fn burn_tokens_from_payments( - &self, - payments: ManagedVecRefIterator>, - ) { + fn burn_tokens_from_payments(&self, payments: &ManagedVec) { for entry in payments { self.send() .esdt_local_burn(&entry.token_identifier, entry.token_nonce, &entry.amount); @@ -47,32 +26,38 @@ pub trait LockedAssetTokenMergeModule: fn get_merged_locked_asset_token_amount_and_attributes( &self, - payments: ManagedVecRefIterator>, + payments: &ManagedVec, ) -> (BigUint, LockedAssetTokenAttributesEx) { require!(!payments.is_empty(), "Cannot merge with 0 tokens"); let mut tokens = ManagedVec::new(); let mut sum_amount = BigUint::zero(); - let locked_asset_token_id = self.locked_asset_token().get_token_id(); - + let locked_asset_token_id = self.locked_asset_token_id().get(); + let attr_ex_activation = self.extended_attributes_activation_nonce().get(); for entry in payments { require!( entry.token_identifier == locked_asset_token_id, "Bad token id" ); - sum_amount += &entry.amount; - - let attributes = self.get_attributes_ex(&entry.token_identifier, entry.token_nonce); tokens.push(LockedTokenEx { - token_amount: entry, - attributes, + token_amount: EsdtTokenPayment::new( + entry.token_identifier.clone(), + entry.token_nonce, + entry.amount.clone(), + ), + attributes: self.get_attributes_ex( + &entry.token_identifier, + entry.token_nonce, + attr_ex_activation, + ), }); + sum_amount += &entry.amount; } if tokens.len() == 1 { let token_0 = tokens.get(0); - return (token_0.token_amount.amount, token_0.attributes); + return (token_0.token_amount.amount.clone(), token_0.attributes); } let attrs = LockedAssetTokenAttributesEx { @@ -98,12 +83,10 @@ pub trait LockedAssetTokenMergeModule: let unlock_percent = &(&el.amount * PRECISION_EX_INCREASE * ONE_MILLION) / amount_total; // Accumulate even the percents of 0 - unsafe { - unlock_milestones_merged.push_unchecked(UnlockMilestoneEx { - unlock_epoch: el.epoch, - unlock_percent: unlock_percent.to_u64().unwrap_unchecked(), - }); - } + unlock_milestones_merged.push(UnlockMilestoneEx { + unlock_epoch: el.epoch, + unlock_percent: unlock_percent.to_u64().unwrap(), + }) } self.distribute_leftover(&mut unlock_milestones_merged); @@ -129,16 +112,14 @@ pub trait LockedAssetTokenMergeModule: array.len() < DOUBLE_MAX_MILESTONES_IN_SCHEDULE, "too many unlock milestones" ); - unsafe { - array.push_unchecked(EpochAmountPair { - epoch: milestone.unlock_epoch, - amount: self.rule_of_three( - &BigUint::from(milestone.unlock_percent), - &BigUint::from(PERCENTAGE_TOTAL_EX), - &locked_token.token_amount.amount, - ), - }); - } + array.push(EpochAmountPair { + epoch: milestone.unlock_epoch, + amount: self.rule_of_three( + &BigUint::from(milestone.unlock_percent), + &BigUint::from(PERCENTAGE_TOTAL_EX), + &locked_token.token_amount.amount, + ), + }); } sum += &locked_token.token_amount.amount; } @@ -159,13 +140,9 @@ pub trait LockedAssetTokenMergeModule: amount: &last.amount + &elem.amount, }; unlock_epoch_amount_merged.pop(); - unsafe { - unlock_epoch_amount_merged.push_unchecked(new_elem); - } + unlock_epoch_amount_merged.push(new_elem); } else { - unsafe { - unlock_epoch_amount_merged.push_unchecked(elem.clone()); - } + unlock_epoch_amount_merged.push(elem.clone()); } } require!(sum != 0u64, "Sum cannot be zero"); diff --git a/locked-asset/factory/src/migration.rs b/legacy-contracts/factory-legacy/src/migration.rs similarity index 55% rename from locked-asset/factory/src/migration.rs rename to legacy-contracts/factory-legacy/src/migration.rs index 590af2e3a..653b93aa0 100644 --- a/locked-asset/factory/src/migration.rs +++ b/legacy-contracts/factory-legacy/src/migration.rs @@ -5,38 +5,8 @@ use energy_factory::migration::ProxyTrait as _; #[multiversx_sc::module] pub trait LockedTokenMigrationModule: - crate::locked_asset::LockedAssetModule - + token_send::TokenSendModule - + crate::attr_ex_helper::AttrExHelper + crate::locked_asset::LockedAssetModule + crate::attr_ex_helper::AttrExHelper { - /// The new factory will need the burn role for the migrated tokens - #[only_owner] - #[endpoint(setLockedTokenBurnRoleForAddress)] - fn set_locked_token_burn_role_for_address(&self, address: ManagedAddress) { - self.locked_asset_token().set_local_roles_for_address( - &address, - &[EsdtLocalRole::NftBurn], - None, - ); - } - - /// Sets the transfer role for the given address. Defaults to own address. - /// The new factory will also need this role. - #[only_owner] - #[endpoint(setTransferRoleOldLockedToken)] - fn set_transfer_role_old_locked_token(&self, opt_address: OptionalValue) { - let address = match opt_address { - OptionalValue::Some(addr) => addr, - OptionalValue::None => self.blockchain().get_sc_address(), - }; - - self.locked_asset_token().set_local_roles_for_address( - &address, - &[EsdtLocalRole::Transfer], - None, - ); - } - #[only_owner] #[endpoint(setNewFactoryAddress)] fn set_new_factory_address(&self, sc_address: ManagedAddress) { diff --git a/farm-staking/metabonding-staking/testnet.toml b/legacy-contracts/factory-legacy/testnet.toml similarity index 100% rename from farm-staking/metabonding-staking/testnet.toml rename to legacy-contracts/factory-legacy/testnet.toml diff --git a/locked-asset/factory/wasm/Cargo.lock b/legacy-contracts/factory-legacy/wasm/Cargo.lock similarity index 59% rename from locked-asset/factory/wasm/Cargo.lock rename to legacy-contracts/factory-legacy/wasm/Cargo.lock index 39d478ef4..f9d78eed7 100644 --- a/locked-asset/factory/wasm/Cargo.lock +++ b/legacy-contracts/factory-legacy/wasm/Cargo.lock @@ -4,27 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" - -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common_errors" @@ -44,12 +38,6 @@ dependencies = [ "unwrappable", ] -[[package]] -name = "either" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" - [[package]] name = "endian-type" version = "0.1.2" @@ -73,26 +61,22 @@ dependencies = [ ] [[package]] -name = "factory" +name = "factory-legacy" version = "0.0.0" dependencies = [ - "arrayvec", "common_errors", "common_structs", "energy-factory", - "itertools", "multiversx-sc", "multiversx-sc-modules", "token_merge_helper", - "token_send", - "wee_alloc", ] [[package]] -name = "factory-wasm" +name = "factory-legacy-wasm" version = "0.0.0" dependencies = [ - "factory", + "factory-legacy", "multiversx-sc-wasm-adapter", ] @@ -115,15 +99,6 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" -[[package]] -name = "itertools" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", -] - [[package]] name = "legacy_token_decode_module" version = "0.0.0" @@ -133,12 +108,6 @@ dependencies = [ "utils", ] -[[package]] -name = "libc" -version = "0.2.151" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" - [[package]] name = "math" version = "0.0.0" @@ -146,12 +115,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" @@ -161,32 +124,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -196,9 +161,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -209,18 +174,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -236,27 +201,27 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -290,15 +255,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -313,21 +278,18 @@ dependencies = [ "multiversx-sc", ] -[[package]] -name = "token_send" -version = "0.0.0" -dependencies = [ - "common_errors", - "common_structs", - "multiversx-sc", -] - [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" @@ -344,37 +306,3 @@ dependencies = [ "mergeable", "multiversx-sc", ] - -[[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" -dependencies = [ - "cfg-if", - "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/legacy-contracts/factory-legacy/wasm/Cargo.toml b/legacy-contracts/factory-legacy/wasm/Cargo.toml new file mode 100644 index 000000000..48e47ca70 --- /dev/null +++ b/legacy-contracts/factory-legacy/wasm/Cargo.toml @@ -0,0 +1,34 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + +[package] +name = "factory-legacy-wasm" +version = "0.0.0" +edition = "2018" +publish = false + +[lib] +crate-type = ["cdylib"] + +[profile.release] +codegen-units = 1 +opt-level = "z" +lto = true +debug = false +panic = "abort" +overflow-checks = false + +[profile.dev] +panic = "abort" + +[dependencies.factory-legacy] +path = ".." + +[dependencies.multiversx-sc-wasm-adapter] +version = "=0.53.2" + +[workspace] +members = ["."] diff --git a/locked-asset/factory/wasm/src/lib.rs b/legacy-contracts/factory-legacy/wasm/src/lib.rs similarity index 61% rename from locked-asset/factory/wasm/src/lib.rs rename to legacy-contracts/factory-legacy/wasm/src/lib.rs index 7ad9e4ac0..80a5bf559 100644 --- a/locked-asset/factory/wasm/src/lib.rs +++ b/legacy-contracts/factory-legacy/wasm/src/lib.rs @@ -5,19 +5,18 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 25 -// Async Callback: 1 -// Total number of exported functions: 27 +// Upgrade: 1 +// Endpoints: 21 +// Async Callback (empty): 1 +// Total number of exported functions: 24 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { - factory + factory_legacy ( init => init upgrade => upgrade @@ -26,21 +25,18 @@ multiversx_sc_wasm_adapter::endpoints! { 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 + setTransferRoleForAddress => set_transfer_role_for_address + unsetTransferRoleForAddress => unset_transfer_role_for_address + setBurnRoleForAddress => set_burn_role_for_address + getLastErrorMessage => last_error_message getInitEpoch => init_epoch - getWhitelistedContracts => whitelisted_contracts + getWhitelistedContracts => get_whitelisted_contracts getDefaultUnlockPeriod => default_unlock_period - getLockedAssetTokenId => locked_asset_token + getLockedAssetTokenId => locked_asset_token_id 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 @@ -48,4 +44,4 @@ multiversx_sc_wasm_adapter::endpoints! { ) } -multiversx_sc_wasm_adapter::async_callback! { factory } +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/locked-asset/factory/.gitignore b/legacy-contracts/farm-staking-proxy-v13/.gitignore similarity index 100% rename from locked-asset/factory/.gitignore rename to legacy-contracts/farm-staking-proxy-v13/.gitignore diff --git a/legacy-contracts/farm-staking-proxy-v13/Cargo.toml b/legacy-contracts/farm-staking-proxy-v13/Cargo.toml new file mode 100644 index 000000000..a7d6a99a0 --- /dev/null +++ b/legacy-contracts/farm-staking-proxy-v13/Cargo.toml @@ -0,0 +1,60 @@ +[package] +name = "farm-staking-proxy-v13" +version = "0.0.0" +authors = ["MultiversX "] +edition = "2021" +publish = false + +[lib] +path = "src/lib.rs" + +[dependencies.multiversx-sc] +version = "=0.53.2" +features = ["esdt-token-payment-legacy-decode"] + +[dependencies.multiversx-sc-modules] +version = "=0.53.2" + +[dependencies.token_merge_helper] +path = "../../common/modules/token_merge_helper" + +[dependencies.common_structs] +path = "../../common/common_structs" + +[dependencies.farm-staking] +path = "../../farm-staking/farm-staking" + +[dependencies.pair] +path = "../../dex/pair" + +[dependencies.farm-v13-locked-rewards] +path = "../farm-v13-locked-rewards" + +[dev-dependencies] +num-bigint = "0.4.2" +num-traits = "0.2" +hex = "0.4" + +[dev-dependencies.energy-factory] +path = "../../locked-asset/energy-factory" + +[dev-dependencies.energy-query] +path = "../../energy-integration/common-modules/energy-query" + +[dev-dependencies.simple-lock] +path = "../../locked-asset/simple-lock" + +[dev-dependencies.farm_token] +path = "../../common/modules/farm/farm_token" + +[dev-dependencies.locking_module] +path = "../../common/modules/locking_module" + +[dev-dependencies.pausable] +path = "../../common/modules/pausable" + +[dev-dependencies.sc_whitelist_module] +path = "../../common/modules/sc_whitelist_module" + +[dev-dependencies.multiversx-sc-scenario] +version = "=0.53.2" diff --git a/locked-asset/factory/meta/Cargo.toml b/legacy-contracts/farm-staking-proxy-v13/meta/Cargo.toml similarity index 53% rename from locked-asset/factory/meta/Cargo.toml rename to legacy-contracts/farm-staking-proxy-v13/meta/Cargo.toml index d81d3bb85..7b8d7d1d1 100644 --- a/locked-asset/factory/meta/Cargo.toml +++ b/legacy-contracts/farm-staking-proxy-v13/meta/Cargo.toml @@ -1,13 +1,13 @@ [package] -name = "factory-abi" +name = "farm-staking-proxy-v13-meta" version = "0.0.0" -authors = ["MultiversX "] edition = "2021" publish = false +authors = ["MultiversX "] -[dependencies.factory] +[dependencies.farm-staking-proxy-v13] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/legacy-contracts/farm-staking-proxy-v13/meta/src/main.rs b/legacy-contracts/farm-staking-proxy-v13/meta/src/main.rs new file mode 100644 index 000000000..0b8a13cf2 --- /dev/null +++ b/legacy-contracts/farm-staking-proxy-v13/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta_lib::cli_main::(); +} diff --git a/farm-staking/metabonding-staking/multiversx.json b/legacy-contracts/farm-staking-proxy-v13/multiversx.json similarity index 100% rename from farm-staking/metabonding-staking/multiversx.json rename to legacy-contracts/farm-staking-proxy-v13/multiversx.json diff --git a/legacy-contracts/farm-staking-proxy-v13/src/dual_yield_token.rs b/legacy-contracts/farm-staking-proxy-v13/src/dual_yield_token.rs new file mode 100644 index 000000000..0c57f52ca --- /dev/null +++ b/legacy-contracts/farm-staking-proxy-v13/src/dual_yield_token.rs @@ -0,0 +1,108 @@ +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +#[derive(TypeAbi, TopEncode, TopDecode, PartialEq, Debug)] +pub struct DualYieldTokenAttributes { + pub lp_farm_token_nonce: u64, + pub lp_farm_token_amount: BigUint, + pub staking_farm_token_nonce: u64, + pub staking_farm_token_amount: BigUint, +} + +impl DualYieldTokenAttributes { + /// dual yield tokens are always created with an amount equal to staking_farm_token_amount, + /// so we just return this field instead of duplicating + #[inline] + pub fn get_total_dual_yield_tokens_for_position(&self) -> &BigUint { + &self.staking_farm_token_amount + } +} + +#[multiversx_sc::module] +pub trait DualYieldTokenModule: token_merge_helper::TokenMergeHelperModule { + #[only_owner] + #[endpoint(setTransferRoleDualYieldToken)] + fn set_transfer_role_dual_yield_token(&self, opt_address: OptionalValue) { + let address = self.resolve_address(opt_address); + let token_id = self.dual_yield_token_id().get(); + let roles = [EsdtLocalRole::Transfer]; + + self.send() + .esdt_system_sc_proxy() + .set_special_roles(&address, &token_id, roles.iter().cloned()) + .async_call_and_exit() + } + + fn resolve_address(&self, opt_address: OptionalValue) -> ManagedAddress { + match opt_address { + OptionalValue::Some(addr) => addr, + OptionalValue::None => self.blockchain().get_sc_address(), + } + } + + fn require_dual_yield_token(&self, token_id: &TokenIdentifier) { + let dual_yield_token_id = self.dual_yield_token_id().get(); + require!(token_id == &dual_yield_token_id, "Invalid payment token"); + } + + fn require_all_payments_dual_yield_tokens( + &self, + payments: &ManagedVec>, + ) { + if payments.is_empty() { + return; + } + + let dual_yield_token_id = self.dual_yield_token_id().get(); + for p in payments { + require!( + p.token_identifier == dual_yield_token_id, + "Invalid payment token" + ); + } + } + + fn burn_dual_yield_tokens(&self, sft_nonce: u64, amount: &BigUint) { + let dual_yield_token_id = self.dual_yield_token_id().get(); + self.send() + .esdt_local_burn(&dual_yield_token_id, sft_nonce, amount); + } + + fn get_dual_yield_token_attributes( + &self, + dual_yield_token_nonce: u64, + ) -> DualYieldTokenAttributes { + let own_sc_address = self.blockchain().get_sc_address(); + let dual_yield_token_id = self.dual_yield_token_id().get(); + let token_info = self.blockchain().get_esdt_token_data( + &own_sc_address, + &dual_yield_token_id, + dual_yield_token_nonce, + ); + + token_info.decode_attributes() + } + + fn get_lp_farm_token_amount_equivalent( + &self, + attributes: &DualYieldTokenAttributes, + amount: &BigUint, + ) -> BigUint { + self.rule_of_three_non_zero_result( + amount, + attributes.get_total_dual_yield_tokens_for_position(), + &attributes.lp_farm_token_amount, + ) + } + + #[inline] + fn get_staking_farm_token_amount_equivalent(&self, amount: &BigUint) -> BigUint { + // since staking_farm_token_amount is equal to the total dual yield tokens, + // we simply return the amount + amount.clone() + } + + #[view(getDualYieldTokenId)] + #[storage_mapper("dualYieldTokenId")] + fn dual_yield_token_id(&self) -> SingleValueMapper; +} diff --git a/legacy-contracts/farm-staking-proxy-v13/src/external_contracts_interactions.rs b/legacy-contracts/farm-staking-proxy-v13/src/external_contracts_interactions.rs new file mode 100644 index 000000000..69f250578 --- /dev/null +++ b/legacy-contracts/farm-staking-proxy-v13/src/external_contracts_interactions.rs @@ -0,0 +1,163 @@ +multiversx_sc::imports!(); + +use common_structs::{RawResultWrapper, RawResultsType}; +use farm_staking::unstake_farm::ProxyTrait as _; +use pair::pair_actions::remove_liq::ProxyTrait as _; + +use crate::result_types::*; + +#[multiversx_sc::module] +pub trait ExternalContractsInteractionsModule: + crate::lp_farm_token::LpFarmTokenModule + token_merge_helper::TokenMergeHelperModule +{ + // lp farm + + fn lp_farm_exit( + &self, + lp_farm_token_nonce: u64, + lp_farm_token_amount: BigUint, + ) -> LpFarmExitResult { + let lp_farm_token_id = self.lp_farm_token_id().get(); + let lp_farm_address = self.lp_farm_address().get(); + let raw_results: RawResultsType = self + .lp_farm_proxy_obj(lp_farm_address) + .exit_farm(OptionalValue::::None) + .with_esdt_transfer((lp_farm_token_id, lp_farm_token_nonce, lp_farm_token_amount)) + .execute_on_dest_context(); + + let mut results_wrapper = RawResultWrapper::new(raw_results); + results_wrapper.trim_results_front(2); + + let mut lp_tokens: EsdtTokenPayment = results_wrapper.decode_next_result(); + let mut lp_farm_rewards: EsdtTokenPayment = results_wrapper.decode_next_result(); + + let received_lp_token_identifier = lp_tokens.token_identifier.clone(); + let lp_token_identifier = self.get_lp_farming_token_identifier(); + + if lp_token_identifier != received_lp_token_identifier { + core::mem::swap(&mut lp_tokens, &mut lp_farm_rewards); + } + + LpFarmExitResult { + lp_tokens, + lp_farm_rewards, + } + } + + fn get_lp_farming_token_identifier(&self) -> TokenIdentifier { + let lp_farm_address = self.lp_farm_address().get(); + self.lp_farm_proxy_obj(lp_farm_address) + .farming_token_id() + .execute_on_dest_context() + } + + // staking farm + + fn staking_farm_unstake( + &self, + orig_caller: ManagedAddress, + staking_tokens: EsdtTokenPayment, + farm_token_nonce: u64, + farm_token_amount: BigUint, + ) -> StakingFarmExitResult { + let staking_farm_token_id = self.staking_farm_token_id().get(); + let mut payments = ManagedVec::from_single_item(staking_tokens); + payments.push(EsdtTokenPayment::new( + staking_farm_token_id, + farm_token_nonce, + farm_token_amount, + )); + + let staking_farm_address = self.staking_farm_address().get(); + let raw_results: RawResultsType = self + .staking_farm_proxy_obj(staking_farm_address) + .unstake_farm_through_proxy(orig_caller) + .with_multi_token_transfer(payments) + .execute_on_dest_context(); + + let mut results_wrapper = RawResultWrapper::new(raw_results); + results_wrapper.trim_results_front(2); + + let unbond_staking_farm_token = results_wrapper.decode_next_result(); + let staking_rewards = results_wrapper.decode_next_result(); + + StakingFarmExitResult { + unbond_staking_farm_token, + staking_rewards, + } + } + + // pair + + fn pair_remove_liquidity( + &self, + lp_tokens: EsdtTokenPayment, + pair_first_token_min_amount: BigUint, + pair_second_token_min_amount: BigUint, + ) -> PairRemoveLiquidityResult { + let pair_address = self.pair_address().get(); + let raw_results: RawResultsType = self + .pair_proxy_obj(pair_address) + .remove_liquidity(pair_first_token_min_amount, pair_second_token_min_amount) + .with_esdt_transfer(( + lp_tokens.token_identifier, + lp_tokens.token_nonce, + lp_tokens.amount, + )) + .execute_on_dest_context(); + + let mut results_wrapper = RawResultWrapper::new(raw_results); + results_wrapper.trim_results_front(2); + + let pair_first_token_payment: EsdtTokenPayment = results_wrapper.decode_next_result(); + let pair_second_token_payment: EsdtTokenPayment = results_wrapper.decode_next_result(); + + let staking_token_id = self.staking_token_id().get(); + let (staking_token_payment, other_token_payment) = + if pair_first_token_payment.token_identifier == staking_token_id { + (pair_first_token_payment, pair_second_token_payment) + } else if pair_second_token_payment.token_identifier == staking_token_id { + (pair_second_token_payment, pair_first_token_payment) + } else { + sc_panic!("Invalid payments received from Pair"); + }; + + PairRemoveLiquidityResult { + staking_token_payment, + other_token_payment, + } + } + + // proxies + + #[proxy] + fn staking_farm_proxy_obj(&self, sc_address: ManagedAddress) -> farm_staking::Proxy; + + #[proxy] + fn lp_farm_proxy_obj(&self, sc_address: ManagedAddress) -> farm_v13_locked_rewards::Proxy; + + #[proxy] + fn pair_proxy_obj(&self, sc_address: ManagedAddress) -> pair::Proxy; + + // storage + + #[view(getLpFarmAddress)] + #[storage_mapper("lpFarmAddress")] + fn lp_farm_address(&self) -> SingleValueMapper; + + #[view(getStakingFarmAddress)] + #[storage_mapper("stakingFarmAddress")] + fn staking_farm_address(&self) -> SingleValueMapper; + + #[view(getPairAddress)] + #[storage_mapper("pairAddress")] + fn pair_address(&self) -> SingleValueMapper; + + #[view(getStakingTokenId)] + #[storage_mapper("stakingTokenId")] + fn staking_token_id(&self) -> SingleValueMapper; + + #[view(getFarmTokenId)] + #[storage_mapper("farmTokenId")] + fn staking_farm_token_id(&self) -> SingleValueMapper; +} diff --git a/legacy-contracts/farm-staking-proxy-v13/src/lib.rs b/legacy-contracts/farm-staking-proxy-v13/src/lib.rs new file mode 100644 index 000000000..361338441 --- /dev/null +++ b/legacy-contracts/farm-staking-proxy-v13/src/lib.rs @@ -0,0 +1,94 @@ +#![no_std] + +multiversx_sc::imports!(); + +pub mod dual_yield_token; +pub mod external_contracts_interactions; +pub mod lp_farm_token; +pub mod result_types; + +pub type UnstakeResult = MultiValueEncoded>; + +#[multiversx_sc::contract] +pub trait FarmStakingProxy: + dual_yield_token::DualYieldTokenModule + + external_contracts_interactions::ExternalContractsInteractionsModule + + lp_farm_token::LpFarmTokenModule + + token_merge_helper::TokenMergeHelperModule +{ + #[init] + fn init(&self) {} + + #[upgrade] + fn upgrade(&self) {} + + #[payable("*")] + #[endpoint(unstakeFarmTokens)] + fn unstake_farm_tokens( + &self, + pair_first_token_min_amount: BigUint, + pair_second_token_min_amount: BigUint, + ) -> UnstakeResult { + let caller = self.blockchain().get_caller(); + let (payment_token, payment_nonce, payment_amount) = + self.call_value().single_esdt().into_tuple(); + self.require_dual_yield_token(&payment_token); + + let attributes = self.get_dual_yield_token_attributes(payment_nonce); + let lp_farm_token_amount = + self.get_lp_farm_token_amount_equivalent(&attributes, &payment_amount); + let lp_farm_exit_result = + self.lp_farm_exit(attributes.lp_farm_token_nonce, lp_farm_token_amount); + + let remove_liq_result = self.pair_remove_liquidity( + lp_farm_exit_result.lp_tokens, + pair_first_token_min_amount, + pair_second_token_min_amount, + ); + + let staking_farm_token_amount = + self.get_staking_farm_token_amount_equivalent(&payment_amount); + let staking_farm_exit_result = self.staking_farm_unstake( + caller.clone(), + remove_liq_result.staking_token_payment, + attributes.staking_farm_token_nonce, + staking_farm_token_amount, + ); + let unstake_result = self.send_unstake_payments( + &caller, + remove_liq_result.other_token_payment, + lp_farm_exit_result.lp_farm_rewards, + staking_farm_exit_result.staking_rewards, + staking_farm_exit_result.unbond_staking_farm_token, + ); + + self.burn_dual_yield_tokens(payment_nonce, &payment_amount); + + unstake_result + } + + fn send_unstake_payments( + &self, + caller: &ManagedAddress, + other_token_payment: EsdtTokenPayment, + lp_farm_rewards: EsdtTokenPayment, + staking_rewards: EsdtTokenPayment, + unbond_staking_farm_token: EsdtTokenPayment, + ) -> UnstakeResult { + let mut user_payments = ManagedVec::new(); + if other_token_payment.amount > 0 { + user_payments.push(other_token_payment); + } + if lp_farm_rewards.amount > 0 { + user_payments.push(lp_farm_rewards); + } + if staking_rewards.amount > 0 { + user_payments.push(staking_rewards); + } + user_payments.push(unbond_staking_farm_token); + + self.send().direct_multi(caller, &user_payments); + + user_payments.into() + } +} diff --git a/legacy-contracts/farm-staking-proxy-v13/src/lp_farm_token.rs b/legacy-contracts/farm-staking-proxy-v13/src/lp_farm_token.rs new file mode 100644 index 000000000..d917a0f99 --- /dev/null +++ b/legacy-contracts/farm-staking-proxy-v13/src/lp_farm_token.rs @@ -0,0 +1,50 @@ +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +#[derive( + ManagedVecItem, + TopEncode, + TopDecode, + NestedEncode, + NestedDecode, + TypeAbi, + Clone, + PartialEq, + Debug, +)] +pub struct FarmTokenAttributes { + pub reward_per_share: BigUint, + pub original_entering_epoch: u64, + pub entering_epoch: u64, + pub initial_farming_amount: BigUint, + pub compounded_reward: BigUint, + pub current_farm_amount: BigUint, +} + +#[multiversx_sc::module] +pub trait LpFarmTokenModule: token_merge_helper::TokenMergeHelperModule { + fn get_lp_tokens_in_farm_position( + &self, + farm_token_nonce: u64, + farm_token_amount: &BigUint, + ) -> BigUint { + let own_sc_address = self.blockchain().get_sc_address(); + let lp_farm_token_id = self.lp_farm_token_id().get(); + let token_data = self.blockchain().get_esdt_token_data( + &own_sc_address, + &lp_farm_token_id, + farm_token_nonce, + ); + let attributes = token_data.decode_attributes::>(); + + self.rule_of_three_non_zero_result( + farm_token_amount, + &attributes.current_farm_amount, + &attributes.initial_farming_amount, + ) + } + + #[view(getLpFarmTokenId)] + #[storage_mapper("lpFarmTokenId")] + fn lp_farm_token_id(&self) -> SingleValueMapper; +} diff --git a/legacy-contracts/farm-staking-proxy-v13/src/result_types.rs b/legacy-contracts/farm-staking-proxy-v13/src/result_types.rs new file mode 100644 index 000000000..a27c2e1f2 --- /dev/null +++ b/legacy-contracts/farm-staking-proxy-v13/src/result_types.rs @@ -0,0 +1,38 @@ +multiversx_sc::imports!(); + +pub type PaymentsVec = ManagedVec>; + +// lp farm + +pub struct LpFarmClaimRewardsResult { + pub new_lp_farm_tokens: EsdtTokenPayment, + pub lp_farm_rewards: EsdtTokenPayment, +} + +pub struct LpFarmExitResult { + pub lp_tokens: EsdtTokenPayment, + pub lp_farm_rewards: EsdtTokenPayment, +} + +// staking farm + +pub struct StakingFarmEnterResult { + pub received_staking_farm_token: EsdtTokenPayment, +} + +pub struct StakingFarmClaimRewardsResult { + pub new_staking_farm_tokens: EsdtTokenPayment, + pub staking_farm_rewards: EsdtTokenPayment, +} + +pub struct StakingFarmExitResult { + pub unbond_staking_farm_token: EsdtTokenPayment, + pub staking_rewards: EsdtTokenPayment, +} + +// pair + +pub struct PairRemoveLiquidityResult { + pub staking_token_payment: EsdtTokenPayment, + pub other_token_payment: EsdtTokenPayment, +} diff --git a/legacy-contracts/farm-staking-proxy-v13/tests/constants/mod.rs b/legacy-contracts/farm-staking-proxy-v13/tests/constants/mod.rs new file mode 100644 index 000000000..f59a14a45 --- /dev/null +++ b/legacy-contracts/farm-staking-proxy-v13/tests/constants/mod.rs @@ -0,0 +1,48 @@ +// // Pair constants + +// pub const PAIR_WASM_PATH: &str = "pair/output/pair.wasm"; +// pub const WEGLD_TOKEN_ID: &[u8] = b"WEGLD-abcdef"; +// pub const RIDE_TOKEN_ID: &[u8] = b"RIDE-abcdef"; +// pub const LP_TOKEN_ID: &[u8] = b"LPTOK-abcdef"; // also farming token ID for LP farm + +// pub const USER_TOTAL_WEGLD_TOKENS: u64 = 2_000_000_000; +// pub const USER_TOTAL_RIDE_TOKENS: u64 = 2_000_000_000; +// pub const USER_TOTAL_LP_TOKENS: u64 = 1_001_000_000; + +// pub const BLOCK_NONCE_FIRST_ADD_LIQ: u64 = 5; +// pub const BLOCK_NONCE_SECOND_ADD_LIQ: u64 = 6; +// pub const BLOCK_NONCE_AFTER_PAIR_SETUP: u64 = 100; + +// // LP farm constants + +// pub const FARM_WASM_PATH: &str = "farm/output/farm.wasm"; +// pub const LP_FARM_TOKEN_ID: &[u8] = b"LPFARM-abcdef"; +// pub const DIVISION_SAFETY_CONSTANT: u64 = 1_000_000_000_000; +// pub const MIN_FARMING_EPOCHS: u8 = 2; +// pub const PENALTY_PERCENT: u64 = 10; +// pub const LP_FARM_PER_BLOCK_REWARD_AMOUNT: u64 = 5_000; + +// // 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]; + +// // Staking farm constants + +// pub const STAKING_FARM_WASM_PATH: &str = "farm-staking/output/farm-staking.wasm"; +// pub const STAKING_REWARD_TOKEN_ID: &[u8] = RIDE_TOKEN_ID; +// pub const STAKING_TOKEN_ID: &[u8] = RIDE_TOKEN_ID; +// pub const STAKING_FARM_TOKEN_ID: &[u8] = b"STKFARM-abcdef"; +// pub const MAX_APR: u64 = 5_000; // 50% +// pub const UNBOND_EPOCHS: u64 = 10; +// pub const STAKING_FARM_PER_BLOCK_REWARD_AMOUNT: u64 = 1_000; +// pub const REWARD_CAPACITY: u64 = 1_000_000_000_000; + +// // Proxy constants + +// pub const PROXY_WASM_PATH: &str = "farm-staking-proxy/output/farm-staking-proxy"; +// pub const DUAL_YIELD_TOKEN_ID: &[u8] = b"DYIELD-abcdef"; diff --git a/legacy-contracts/farm-staking-proxy-v13/tests/staking_farm_with_lp.rs b/legacy-contracts/farm-staking-proxy-v13/tests/staking_farm_with_lp.rs new file mode 100644 index 000000000..faad624a7 --- /dev/null +++ b/legacy-contracts/farm-staking-proxy-v13/tests/staking_farm_with_lp.rs @@ -0,0 +1,147 @@ +// #![allow(deprecated)] + +// 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 common_structs::FarmTokenAttributes; +// use constants::*; +// use farm_staking_proxy_legacy::dual_yield_token::DualYieldTokenAttributes; + +// use farm_staking::stake_farm::StakeFarmModule; +// use farm_with_locked_rewards::Farm; +// use multiversx_sc_scenario::{ +// imports::TxTokenTransfer, managed_address, managed_biguint, rust_biguint, DebugApi, +// }; +// use pair::pair_actions::add_liq::AddLiquidityModule; +// use staking_farm_with_lp_staking_contract_interactions::*; + +// #[test] +// fn test_all_setup() { +// let _ = FarmStakingSetup::new( +// pair::contract_obj, +// farm_with_locked_rewards::contract_obj, +// energy_factory::contract_obj, +// farm_staking::contract_obj, +// farm_staking_proxy_legacy::contract_obj, +// ); +// } + +// #[test] +// fn test_unstake_from_legacy_proxy() { +// 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_legacy::contract_obj, +// ); + +// DebugApi::dummy(); +// setup +// .b_mock +// .set_block_nonce(BLOCK_NONCE_AFTER_PAIR_SETUP + 20); +// setup.b_mock.set_block_epoch(20); + +// let token_amount = 1_000_000_000u64; + +// let payments = vec![ +// TxTokenTransfer { +// token_identifier: WEGLD_TOKEN_ID.to_vec(), +// nonce: 0, +// value: rust_biguint!(token_amount), +// }, +// TxTokenTransfer { +// token_identifier: RIDE_TOKEN_ID.to_vec(), +// nonce: 0, +// value: rust_biguint!(token_amount), +// }, +// ]; +// setup +// .b_mock +// .execute_esdt_multi_transfer(&setup.user_addr, &setup.pair_wrapper, &payments, |sc| { +// sc.add_liquidity(managed_biguint!(1u64), managed_biguint!(1u64)); +// }) +// .assert_ok(); + +// setup +// .b_mock +// .execute_esdt_transfer( +// &setup.user_addr, +// &setup.lp_farm_wrapper, +// LP_TOKEN_ID, +// 0, +// &rust_biguint!(token_amount), +// |sc| { +// sc.enter_farm_endpoint(OptionalValue::None); +// }, +// ) +// .assert_ok(); + +// // Simulate enter proxy staking contract +// let lp_farm_token_attributes: FarmTokenAttributes = FarmTokenAttributes { +// reward_per_share: managed_biguint!(0), +// entering_epoch: 20, +// compounded_reward: managed_biguint!(0), +// current_farm_amount: managed_biguint!(token_amount), +// original_owner: managed_address!(&setup.user_addr), +// }; +// setup.b_mock.set_nft_balance( +// setup.proxy_wrapper.address_ref(), +// LP_FARM_TOKEN_ID, +// 1, +// &rust_biguint!(token_amount), +// &lp_farm_token_attributes, +// ); +// setup.b_mock.set_esdt_balance( +// setup.proxy_wrapper.address_ref(), +// RIDE_TOKEN_ID, +// &rust_biguint!(token_amount), +// ); + +// setup +// .b_mock +// .execute_tx( +// setup.proxy_wrapper.address_ref(), +// &setup.staking_farm_wrapper, +// &rust_biguint!(0u64), +// |sc| { +// sc.stake_farm_through_proxy( +// managed_biguint!(token_amount), +// managed_address!(&setup.user_addr), +// ); +// }, +// ) +// .assert_ok(); + +// let dual_yield_token_amount = token_amount; +// let dual_yield_token_attributes: DualYieldTokenAttributes = +// DualYieldTokenAttributes { +// lp_farm_token_nonce: 1, +// lp_farm_token_amount: managed_biguint!(dual_yield_token_amount), +// staking_farm_token_nonce: 1, +// staking_farm_token_amount: managed_biguint!(dual_yield_token_amount), +// }; +// setup.b_mock.set_nft_balance( +// &setup.user_addr, +// DUAL_YIELD_TOKEN_ID, +// 1, +// &rust_biguint!(dual_yield_token_amount), +// &dual_yield_token_attributes, +// ); + +// let expected_token_amount = 990_000_000u64; +// setup.unstake_proxy( +// 1, +// dual_yield_token_amount, +// expected_token_amount, +// expected_token_amount, +// 30, +// ); + +// setup.b_mock.set_block_epoch(30); +// setup.unbond_proxy(2, expected_token_amount, expected_token_amount); +// } diff --git a/legacy-contracts/farm-staking-proxy-v13/tests/staking_farm_with_lp_external_contracts/mod.rs b/legacy-contracts/farm-staking-proxy-v13/tests/staking_farm_with_lp_external_contracts/mod.rs new file mode 100644 index 000000000..ffd3c9313 --- /dev/null +++ b/legacy-contracts/farm-staking-proxy-v13/tests/staking_farm_with_lp_external_contracts/mod.rs @@ -0,0 +1,253 @@ +// use energy_factory::token_whitelist::TokenWhitelistModule; +// use energy_factory::SimpleLockEnergy; +// use energy_query::EnergyQueryModule; +// use farm_token::FarmTokenModule; +// use farm_with_locked_rewards::Farm; +// use multiversx_sc::imports::StorageTokenWrapper; +// use multiversx_sc::types::{Address, EsdtLocalRole, MultiValueEncoded}; +// use multiversx_sc_modules::pause::PauseModule; +// use multiversx_sc_scenario::{ +// managed_address, managed_biguint, managed_token_id, rust_biguint, testing_framework::*, +// DebugApi, +// }; + +// use pair::config as pair_config; +// use pair::*; +// use pair_actions::add_liq::AddLiquidityModule; +// use pair_actions::initial_liq::InitialLiquidityModule; +// use pair_config::ConfigModule as _; + +// use pausable::{PausableModule, State}; +// use simple_lock::locked_token::LockedTokenModule as _; + +// use crate::constants::*; + +// pub fn setup_pair( +// owner_addr: &Address, +// user_addr: &Address, +// b_mock: &mut BlockchainStateWrapper, +// pair_builder: PairObjBuilder, +// ) -> ContractObjWrapper, PairObjBuilder> +// where +// PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, +// { +// let rust_zero = rust_biguint!(0u64); +// let pair_wrapper = +// b_mock.create_sc_account(&rust_zero, Some(owner_addr), pair_builder, PAIR_WASM_PATH); + +// b_mock +// .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!(RIDE_TOKEN_ID); +// let router_address = managed_address!(owner_addr); +// let router_owner_address = managed_address!(owner_addr); +// let initial_liquidity_adder = 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, +// initial_liquidity_adder, +// MultiValueEncoded::new(), +// ); + +// let lp_token_id = managed_token_id!(LP_TOKEN_ID); +// sc.lp_token_identifier().set(&lp_token_id); +// }) +// .assert_ok(); + +// let lp_token_roles = [EsdtLocalRole::Mint, EsdtLocalRole::Burn]; +// b_mock.set_esdt_local_roles(pair_wrapper.address_ref(), LP_TOKEN_ID, &lp_token_roles[..]); + +// // set user balance +// b_mock.set_esdt_balance( +// user_addr, +// WEGLD_TOKEN_ID, +// &rust_biguint!(USER_TOTAL_WEGLD_TOKENS), +// ); +// b_mock.set_esdt_balance( +// user_addr, +// RIDE_TOKEN_ID, +// &rust_biguint!(USER_TOTAL_RIDE_TOKENS), +// ); + +// b_mock.set_block_nonce(BLOCK_NONCE_FIRST_ADD_LIQ); + +// b_mock.set_esdt_balance( +// owner_addr, +// WEGLD_TOKEN_ID, +// &rust_biguint!(USER_TOTAL_WEGLD_TOKENS), +// ); +// b_mock.set_esdt_balance( +// owner_addr, +// RIDE_TOKEN_ID, +// &rust_biguint!(USER_TOTAL_RIDE_TOKENS), +// ); + +// let payments = vec![ +// TxTokenTransfer { +// token_identifier: WEGLD_TOKEN_ID.to_vec(), +// nonce: 0, +// value: rust_biguint!(1_000_000_000), +// }, +// TxTokenTransfer { +// token_identifier: RIDE_TOKEN_ID.to_vec(), +// nonce: 0, +// value: rust_biguint!(1_000_000_000), +// }, +// ]; +// b_mock +// .execute_esdt_multi_transfer(owner_addr, &pair_wrapper, &payments, |sc| { +// sc.add_initial_liquidity(); +// }) +// .assert_ok(); + +// b_mock.set_block_nonce(BLOCK_NONCE_SECOND_ADD_LIQ); + +// b_mock +// .execute_esdt_multi_transfer(owner_addr, &pair_wrapper, &payments, |sc| { +// sc.add_liquidity(managed_biguint!(1u64), managed_biguint!(1u64)); +// }) +// .assert_ok(); + +// b_mock.set_block_nonce(BLOCK_NONCE_AFTER_PAIR_SETUP); + +// pair_wrapper +// } + +// pub fn setup_lp_farm( +// owner_addr: &Address, +// energy_factory_address: &Address, +// b_mock: &mut BlockchainStateWrapper, +// farm_builder: FarmObjBuilder, +// ) -> ContractObjWrapper, FarmObjBuilder> +// where +// FarmObjBuilder: 'static + Copy + Fn() -> farm_with_locked_rewards::ContractObj, +// { +// let rust_zero = rust_biguint!(0u64); +// let farm_wrapper = +// b_mock.create_sc_account(&rust_zero, Some(owner_addr), farm_builder, FARM_WASM_PATH); + +// // init farm contract + +// b_mock +// .execute_tx(owner_addr, &farm_wrapper, &rust_zero, |sc| { +// let reward_token_id = managed_token_id!(RIDE_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()); + +// sc.init( +// reward_token_id, +// farming_token_id, +// division_safety_constant, +// pair_address, +// managed_address!(owner_addr), +// MultiValueEncoded::new(), +// ); + +// let farm_token_id = managed_token_id!(LP_FARM_TOKEN_ID); +// sc.farm_token().set_token_id(farm_token_id); + +// sc.energy_factory_address() +// .set(managed_address!(energy_factory_address)); + +// sc.state().set(State::Active); +// }) +// .assert_ok(); + +// let farm_token_roles = [ +// EsdtLocalRole::NftCreate, +// EsdtLocalRole::NftAddQuantity, +// EsdtLocalRole::NftBurn, +// ]; +// b_mock.set_esdt_local_roles( +// farm_wrapper.address_ref(), +// LP_FARM_TOKEN_ID, +// &farm_token_roles[..], +// ); + +// let farming_token_roles = [EsdtLocalRole::Burn]; +// b_mock.set_esdt_local_roles( +// farm_wrapper.address_ref(), +// LP_TOKEN_ID, +// &farming_token_roles[..], +// ); + +// let reward_token_roles = [EsdtLocalRole::Mint]; +// b_mock.set_esdt_local_roles( +// farm_wrapper.address_ref(), +// RIDE_TOKEN_ID, +// &reward_token_roles[..], +// ); + +// 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 +// } diff --git a/legacy-contracts/farm-staking-proxy-v13/tests/staking_farm_with_lp_staking_contract_interactions/mod.rs b/legacy-contracts/farm-staking-proxy-v13/tests/staking_farm_with_lp_staking_contract_interactions/mod.rs new file mode 100644 index 000000000..7073690b5 --- /dev/null +++ b/legacy-contracts/farm-staking-proxy-v13/tests/staking_farm_with_lp_staking_contract_interactions/mod.rs @@ -0,0 +1,201 @@ +// use multiversx_sc::types::Address; +// use multiversx_sc_scenario::{ +// managed_biguint, rust_biguint, +// testing_framework::{BlockchainStateWrapper, ContractObjWrapper}, +// DebugApi, +// }; + +// use farm_staking::*; +// use farm_staking_proxy_legacy::*; +// use token_attributes::UnbondSftAttributes; +// use unbond_farm::UnbondFarmModule; + +// use crate::{ +// constants::*, +// 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, +// }, +// }; + +// pub struct FarmStakingSetup< +// PairObjBuilder, +// FarmObjBuilder, +// EnergyFactoryObjBuilder, +// StakingContractObjBuilder, +// ProxyContractObjBuilder, +// > where +// PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, +// FarmObjBuilder: 'static + Copy + Fn() -> farm_with_locked_rewards::ContractObj, +// EnergyFactoryObjBuilder: 'static + Copy + Fn() -> energy_factory::ContractObj, +// StakingContractObjBuilder: 'static + Copy + Fn() -> farm_staking::ContractObj, +// ProxyContractObjBuilder: +// 'static + Copy + Fn() -> farm_staking_proxy_legacy::ContractObj, +// { +// pub owner_addr: Address, +// pub user_addr: Address, +// pub b_mock: BlockchainStateWrapper, +// pub pair_wrapper: ContractObjWrapper, PairObjBuilder>, +// pub lp_farm_wrapper: +// ContractObjWrapper, FarmObjBuilder>, +// pub energy_factory_wrapper: +// ContractObjWrapper, EnergyFactoryObjBuilder>, +// pub staking_farm_wrapper: +// ContractObjWrapper, StakingContractObjBuilder>, +// pub proxy_wrapper: ContractObjWrapper< +// farm_staking_proxy_legacy::ContractObj, +// ProxyContractObjBuilder, +// >, +// } + +// impl< +// PairObjBuilder, +// FarmObjBuilder, +// EnergyFactoryObjBuilder, +// StakingContractObjBuilder, +// ProxyContractObjBuilder, +// > +// FarmStakingSetup< +// PairObjBuilder, +// FarmObjBuilder, +// EnergyFactoryObjBuilder, +// StakingContractObjBuilder, +// ProxyContractObjBuilder, +// > +// where +// PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj, +// FarmObjBuilder: 'static + Copy + Fn() -> farm_with_locked_rewards::ContractObj, +// EnergyFactoryObjBuilder: 'static + Copy + Fn() -> energy_factory::ContractObj, +// StakingContractObjBuilder: 'static + Copy + Fn() -> farm_staking::ContractObj, +// ProxyContractObjBuilder: +// 'static + Copy + Fn() -> farm_staking_proxy_legacy::ContractObj, +// { +// pub fn new( +// pair_builder: PairObjBuilder, +// lp_farm_builder: FarmObjBuilder, +// energy_factory_builder: EnergyFactoryObjBuilder, +// staking_farm_builder: StakingContractObjBuilder, +// proxy_builder: ProxyContractObjBuilder, +// ) -> Self { +// let rust_zero = rust_biguint!(0u64); +// let mut b_mock = BlockchainStateWrapper::new(); +// let owner_addr = b_mock.create_user_account(&rust_zero); +// let user_addr = b_mock.create_user_account(&rust_biguint!(100_000_000)); + +// let pair_wrapper = setup_pair(&owner_addr, &user_addr, &mut b_mock, pair_builder); +// let energy_factory_wrapper = +// setup_energy_factory(&owner_addr, &mut b_mock, energy_factory_builder); +// let lp_farm_wrapper = setup_lp_farm( +// &owner_addr, +// energy_factory_wrapper.address_ref(), +// &mut b_mock, +// lp_farm_builder, +// ); + +// let staking_farm_wrapper = +// setup_staking_farm(&owner_addr, &mut b_mock, staking_farm_builder); +// let proxy_wrapper = setup_proxy( +// &owner_addr, +// lp_farm_wrapper.address_ref(), +// staking_farm_wrapper.address_ref(), +// pair_wrapper.address_ref(), +// &mut b_mock, +// proxy_builder, +// ); + +// add_proxy_to_whitelist( +// &owner_addr, +// proxy_wrapper.address_ref(), +// &mut b_mock, +// &lp_farm_wrapper, +// &staking_farm_wrapper, +// ); + +// FarmStakingSetup { +// owner_addr, +// user_addr, +// b_mock, +// pair_wrapper, +// lp_farm_wrapper, +// energy_factory_wrapper, +// staking_farm_wrapper, +// proxy_wrapper, +// } +// } + +// pub fn unstake_proxy( +// &mut self, +// dual_yield_token_nonce: u64, +// dual_yield_token_amount: u64, +// expected_wegld_amount: u64, +// expected_unbond_token_amount: u64, +// expected_unbond_token_unlock_epoch: u64, +// ) -> u64 { +// let mut unbond_token_nonce = 0; + +// self.b_mock +// .execute_esdt_transfer( +// &self.user_addr, +// &self.proxy_wrapper, +// DUAL_YIELD_TOKEN_ID, +// dual_yield_token_nonce, +// &rust_biguint!(dual_yield_token_amount), +// |sc| { +// let received_tokens = sc +// .unstake_farm_tokens(managed_biguint!(1), managed_biguint!(1)) +// .to_vec(); +// let mut vec_index = 0; + +// if expected_wegld_amount > 0 { +// let wegld_payment = received_tokens.get(vec_index); +// assert_eq!(wegld_payment.amount, expected_wegld_amount); + +// vec_index += 1; +// } + +// let unbond_tokens = received_tokens.get(vec_index); +// assert_eq!(unbond_tokens.amount, expected_unbond_token_amount); + +// unbond_token_nonce = unbond_tokens.token_nonce; +// }, +// ) +// .assert_ok(); + +// self.b_mock.execute_in_managed_environment(|| { +// let expected_attributes = UnbondSftAttributes { +// unlock_epoch: expected_unbond_token_unlock_epoch, +// }; + +// self.b_mock.check_nft_balance( +// &self.user_addr, +// STAKING_FARM_TOKEN_ID, +// unbond_token_nonce, +// &rust_biguint!(expected_unbond_token_amount), +// Some(&expected_attributes), +// ); +// }); + +// unbond_token_nonce +// } + +// pub fn unbond_proxy( +// &mut self, +// unbond_token_nonce: u64, +// unbond_token_amount: u64, +// expected_token_out_amount: u64, +// ) { +// self.b_mock +// .execute_esdt_transfer( +// &self.user_addr, +// &self.staking_farm_wrapper, +// STAKING_FARM_TOKEN_ID, +// unbond_token_nonce, +// &rust_biguint!(unbond_token_amount), +// |sc| { +// let received_tokens = sc.unbond_farm(); +// assert_eq!(received_tokens.amount, expected_token_out_amount); +// }, +// ) +// .assert_ok(); +// } +// } diff --git a/legacy-contracts/farm-staking-proxy-v13/tests/staking_farm_with_lp_staking_contract_setup/mod.rs b/legacy-contracts/farm-staking-proxy-v13/tests/staking_farm_with_lp_staking_contract_setup/mod.rs new file mode 100644 index 000000000..2cb4d6e97 --- /dev/null +++ b/legacy-contracts/farm-staking-proxy-v13/tests/staking_farm_with_lp_staking_contract_setup/mod.rs @@ -0,0 +1,153 @@ +// use external_contracts_interactions::ExternalContractsInteractionsModule; +// use farm_token::FarmTokenModule; +// use lp_farm_token::LpFarmTokenModule; +// use multiversx_sc::{ +// imports::StorageTokenWrapper, +// types::{Address, EsdtLocalRole, MultiValueEncoded}, +// }; +// use multiversx_sc_scenario::{ +// managed_address, managed_biguint, managed_token_id, rust_biguint, +// testing_framework::{BlockchainStateWrapper, ContractObjWrapper}, +// DebugApi, +// }; + +// use farm_staking::*; + +// use farm_staking_proxy_legacy::dual_yield_token::DualYieldTokenModule; +// use farm_staking_proxy_legacy::*; +// use pausable::{PausableModule, State}; +// use sc_whitelist_module::SCWhitelistModule; + +// use crate::constants::*; + +// pub fn setup_staking_farm( +// owner_addr: &Address, +// b_mock: &mut BlockchainStateWrapper, +// builder: StakingContractObjBuilder, +// ) -> ContractObjWrapper, StakingContractObjBuilder> +// where +// StakingContractObjBuilder: 'static + Copy + Fn() -> farm_staking::ContractObj, +// { +// let rust_zero = rust_biguint!(0u64); +// let farm_staking_wrapper = +// b_mock.create_sc_account(&rust_zero, Some(owner_addr), builder, PROXY_WASM_PATH); + +// b_mock +// .execute_tx(owner_addr, &farm_staking_wrapper, &rust_zero, |sc| { +// let farming_token_id = managed_token_id!(STAKING_TOKEN_ID); +// let div_const = managed_biguint!(DIVISION_SAFETY_CONSTANT); +// let max_apr = managed_biguint!(MAX_APR); + +// sc.init( +// farming_token_id, +// div_const, +// max_apr, +// UNBOND_EPOCHS, +// managed_address!(owner_addr), +// MultiValueEncoded::new(), +// ); + +// sc.farm_token() +// .set_token_id(managed_token_id!(STAKING_FARM_TOKEN_ID)); + +// sc.state().set(State::Active); +// }) +// .assert_ok(); + +// b_mock.set_esdt_balance( +// farm_staking_wrapper.address_ref(), +// STAKING_REWARD_TOKEN_ID, +// &rust_biguint!(REWARD_CAPACITY), +// ); + +// let farm_token_roles = [ +// EsdtLocalRole::NftCreate, +// EsdtLocalRole::NftAddQuantity, +// EsdtLocalRole::NftBurn, +// ]; +// b_mock.set_esdt_local_roles( +// farm_staking_wrapper.address_ref(), +// STAKING_FARM_TOKEN_ID, +// &farm_token_roles[..], +// ); + +// farm_staking_wrapper +// } + +// pub fn add_proxy_to_whitelist( +// owner_addr: &Address, +// proxy_address: &Address, +// b_mock: &mut BlockchainStateWrapper, +// lp_farm_builder: &ContractObjWrapper< +// farm_with_locked_rewards::ContractObj, +// FarmObjBuilder, +// >, +// staking_farm_builder: &ContractObjWrapper< +// farm_staking::ContractObj, +// StakingContractObjBuilder, +// >, +// ) where +// FarmObjBuilder: 'static + Copy + Fn() -> farm_with_locked_rewards::ContractObj, +// StakingContractObjBuilder: 'static + Copy + Fn() -> farm_staking::ContractObj, +// { +// let rust_zero = rust_biguint!(0u64); +// b_mock +// .execute_tx(owner_addr, lp_farm_builder, &rust_zero, |sc| { +// sc.add_sc_address_to_whitelist(managed_address!(proxy_address)); +// }) +// .assert_ok(); +// b_mock +// .execute_tx(owner_addr, staking_farm_builder, &rust_zero, |sc| { +// sc.add_sc_address_to_whitelist(managed_address!(proxy_address)); +// }) +// .assert_ok(); +// } + +// pub fn setup_proxy( +// owner_addr: &Address, +// lp_farm_address: &Address, +// staking_farm_address: &Address, +// pair_address: &Address, +// b_mock: &mut BlockchainStateWrapper, +// builder: ProxyContractObjBuilder, +// ) -> ContractObjWrapper, ProxyContractObjBuilder> +// where +// ProxyContractObjBuilder: +// 'static + Copy + Fn() -> farm_staking_proxy_legacy::ContractObj, +// { +// let rust_zero = rust_biguint!(0u64); +// let proxy_wrapper = +// b_mock.create_sc_account(&rust_zero, Some(owner_addr), builder, PROXY_WASM_PATH); + +// b_mock +// .execute_tx(owner_addr, &proxy_wrapper, &rust_zero, |sc| { +// sc.init(); + +// sc.pair_address().set(managed_address!(pair_address)); +// sc.lp_farm_address().set(managed_address!(lp_farm_address)); +// sc.lp_farm_token_id() +// .set(managed_token_id!(LP_FARM_TOKEN_ID)); +// sc.staking_farm_address() +// .set(managed_address!(staking_farm_address)); +// sc.staking_token_id() +// .set(managed_token_id!(STAKING_TOKEN_ID)); +// sc.staking_farm_token_id() +// .set(managed_token_id!(STAKING_FARM_TOKEN_ID)); +// sc.dual_yield_token_id() +// .set(&managed_token_id!(DUAL_YIELD_TOKEN_ID)); +// }) +// .assert_ok(); + +// let dual_yield_token_roles = [ +// EsdtLocalRole::NftCreate, +// EsdtLocalRole::NftAddQuantity, +// EsdtLocalRole::NftBurn, +// ]; +// b_mock.set_esdt_local_roles( +// proxy_wrapper.address_ref(), +// DUAL_YIELD_TOKEN_ID, +// &dual_yield_token_roles[..], +// ); + +// proxy_wrapper +// } diff --git a/locked-asset/distribution/wasm/Cargo.lock b/legacy-contracts/farm-staking-proxy-v13/wasm/Cargo.lock similarity index 51% rename from locked-asset/distribution/wasm/Cargo.lock rename to legacy-contracts/farm-staking-proxy-v13/wasm/Cargo.lock index fce0d3ebe..ff771930d 100644 --- a/locked-asset/distribution/wasm/Cargo.lock +++ b/legacy-contracts/farm-staking-proxy-v13/wasm/Cargo.lock @@ -4,27 +4,28 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[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 = "common_errors" @@ -45,27 +46,39 @@ dependencies = [ ] [[package]] -name = "distribution" +name = "config" version = "0.0.0" dependencies = [ + "common_errors", "common_structs", - "factory", "multiversx-sc", + "pausable", + "permissions_module", + "token_send", ] [[package]] -name = "distribution-wasm" +name = "contexts" version = "0.0.0" dependencies = [ - "distribution", - "multiversx-sc-wasm-adapter", + "common_errors", + "common_structs", + "config", + "farm_token", + "multiversx-sc", + "multiversx-sc-modules", + "pausable", + "permissions_module", + "rewards", + "token_merge_helper", + "token_send", ] [[package]] name = "either" -version = "1.9.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "endian-type" @@ -90,19 +103,175 @@ dependencies = [ ] [[package]] -name = "factory" +name = "energy-query" +version = "0.0.0" +dependencies = [ + "energy-factory", + "multiversx-sc", +] + +[[package]] +name = "events" +version = "0.0.0" +dependencies = [ + "common_structs", + "contexts", + "multiversx-sc", +] + +[[package]] +name = "farm" version = "0.0.0" dependencies = [ - "arrayvec", "common_errors", "common_structs", + "config", + "contexts", + "energy-query", + "events", + "farm-boosted-yields", + "farm_base_impl", + "farm_token", + "fixed-supply-token", + "mergeable", + "multiversx-sc", + "multiversx-sc-modules", + "pair", + "pausable", + "permissions_module", + "rewards", + "sc_whitelist_module", + "token_send", + "utils", + "week-timekeeping", + "weekly-rewards-splitting", +] + +[[package]] +name = "farm-boosted-yields" +version = "0.0.0" +dependencies = [ + "common-types", + "config", + "energy-query", + "multiversx-sc", + "pausable", + "permissions_module", + "week-timekeeping", + "weekly-rewards-splitting", +] + +[[package]] +name = "farm-staking" +version = "0.0.0" +dependencies = [ + "common_errors", + "common_structs", + "config", + "contexts", "energy-factory", - "itertools", + "energy-query", + "events", + "farm", + "farm-boosted-yields", + "farm_base_impl", + "farm_token", + "fixed-supply-token", + "math", + "mergeable", + "multiversx-sc", + "multiversx-sc-modules", + "pair", + "pausable", + "permissions_module", + "rewards", + "sc_whitelist_module", + "token_send", + "utils", + "week-timekeeping", + "weekly-rewards-splitting", +] + +[[package]] +name = "farm-staking-proxy-v13" +version = "0.0.0" +dependencies = [ + "common_structs", + "farm-staking", + "farm-v13-locked-rewards", + "multiversx-sc", + "multiversx-sc-modules", + "pair", + "token_merge_helper", +] + +[[package]] +name = "farm-staking-proxy-v13-wasm" +version = "0.0.0" +dependencies = [ + "farm-staking-proxy-v13", + "multiversx-sc-wasm-adapter", +] + +[[package]] +name = "farm-v13-locked-rewards" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "farm_base_impl" +version = "0.0.0" +dependencies = [ + "common_errors", + "common_structs", + "config", + "contexts", + "events", + "farm_token", + "fixed-supply-token", + "mergeable", "multiversx-sc", "multiversx-sc-modules", + "pausable", + "permissions_module", + "rewards", "token_merge_helper", "token_send", - "wee_alloc", + "utils", +] + +[[package]] +name = "farm_token" +version = "0.0.0" +dependencies = [ + "common_errors", + "common_structs", + "config", + "multiversx-sc", + "multiversx-sc-modules", + "pausable", + "permissions_module", + "token_send", +] + +[[package]] +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]] @@ -143,10 +312,13 @@ dependencies = [ ] [[package]] -name = "libc" -version = "0.2.151" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +name = "locking_module" +version = "0.0.0" +dependencies = [ + "energy-factory", + "multiversx-sc", + "simple-lock", +] [[package]] name = "math" @@ -155,12 +327,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" @@ -170,32 +336,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -205,9 +373,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -218,18 +386,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -245,27 +413,60 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] +[[package]] +name = "pair" +version = "0.0.0" +dependencies = [ + "common_errors", + "common_structs", + "fees-collector", + "itertools", + "multiversx-sc", + "pausable", + "permissions_module", + "simple-lock", + "token_send", + "utils", +] + +[[package]] +name = "pausable" +version = "0.0.0" +dependencies = [ + "multiversx-sc", + "permissions_module", +] + +[[package]] +name = "permissions_module" +version = "0.0.0" +dependencies = [ + "bitflags", + "common_errors", + "multiversx-sc", +] + [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -280,6 +481,21 @@ dependencies = [ "nibble_vec", ] +[[package]] +name = "rewards" +version = "0.0.0" +dependencies = [ + "common_errors", + "common_structs", + "config", + "farm_token", + "multiversx-sc", + "multiversx-sc-modules", + "pausable", + "permissions_module", + "token_send", +] + [[package]] name = "sc_whitelist_module" version = "0.0.0" @@ -299,15 +515,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -337,6 +553,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" @@ -355,35 +577,21 @@ dependencies = [ ] [[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" +name = "week-timekeeping" +version = "0.0.0" dependencies = [ - "cfg-if", - "libc", - "memory_units", - "winapi", + "common-types", + "multiversx-sc", ] [[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +name = "weekly-rewards-splitting" +version = "0.0.0" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "common-types", + "energy-query", + "math", + "multiversx-sc", + "unwrappable", + "week-timekeeping", ] - -[[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/legacy-contracts/farm-staking-proxy-v13/wasm/Cargo.toml b/legacy-contracts/farm-staking-proxy-v13/wasm/Cargo.toml new file mode 100644 index 000000000..1cd7e5663 --- /dev/null +++ b/legacy-contracts/farm-staking-proxy-v13/wasm/Cargo.toml @@ -0,0 +1,34 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + +[package] +name = "farm-staking-proxy-v13-wasm" +version = "0.0.0" +edition = "2021" +publish = false + +[lib] +crate-type = ["cdylib"] + +[profile.release] +codegen-units = 1 +opt-level = "z" +lto = true +debug = false +panic = "abort" +overflow-checks = false + +[profile.dev] +panic = "abort" + +[dependencies.farm-staking-proxy-v13] +path = ".." + +[dependencies.multiversx-sc-wasm-adapter] +version = "=0.53.2" + +[workspace] +members = ["."] diff --git a/legacy-contracts/farm-staking-proxy-v13/wasm/src/lib.rs b/legacy-contracts/farm-staking-proxy-v13/wasm/src/lib.rs new file mode 100644 index 000000000..28c215d78 --- /dev/null +++ b/legacy-contracts/farm-staking-proxy-v13/wasm/src/lib.rs @@ -0,0 +1,35 @@ +// Code generated by the multiversx-sc build system. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +// Init: 1 +// Upgrade: 1 +// Endpoints: 9 +// Async Callback (empty): 1 +// Total number of exported functions: 12 + +#![no_std] + +multiversx_sc_wasm_adapter::allocator!(); +multiversx_sc_wasm_adapter::panic_handler!(); + +multiversx_sc_wasm_adapter::endpoints! { + farm_staking_proxy_v13 + ( + init => init + upgrade => upgrade + unstakeFarmTokens => unstake_farm_tokens + setTransferRoleDualYieldToken => set_transfer_role_dual_yield_token + getDualYieldTokenId => dual_yield_token_id + getLpFarmAddress => lp_farm_address + getStakingFarmAddress => staking_farm_address + getPairAddress => pair_address + getStakingTokenId => staking_token_id + getFarmTokenId => staking_farm_token_id + getLpFarmTokenId => lp_farm_token_id + ) +} + +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/legacy-contracts/farm-v12/Cargo.toml b/legacy-contracts/farm-v12/Cargo.toml new file mode 100644 index 000000000..17b883d4d --- /dev/null +++ b/legacy-contracts/farm-v12/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "farm-v12" +version = "0.0.0" +authors = ["you"] +edition = "2021" +publish = false + +[lib] +path = "src/lib.rs" + +[dependencies.multiversx-sc] +version = "0.53.2" + +[dev-dependencies] +num-bigint = "0.4" + +[dev-dependencies.multiversx-sc-scenario] +version = "0.53.2" diff --git a/legacy-contracts/farm-v12/meta/Cargo.toml b/legacy-contracts/farm-v12/meta/Cargo.toml new file mode 100644 index 000000000..8251ed66d --- /dev/null +++ b/legacy-contracts/farm-v12/meta/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "farm-v12-meta" +version = "0.0.0" +edition = "2021" +publish = false + +[dependencies.farm-v12] +path = ".." + +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" +default-features = false diff --git a/legacy-contracts/farm-v12/meta/src/main.rs b/legacy-contracts/farm-v12/meta/src/main.rs new file mode 100644 index 000000000..5aeb346f1 --- /dev/null +++ b/legacy-contracts/farm-v12/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta_lib::cli_main::(); +} diff --git a/locked-asset/distribution/multiversx.json b/legacy-contracts/farm-v12/multiversx.json similarity index 100% rename from locked-asset/distribution/multiversx.json rename to legacy-contracts/farm-v12/multiversx.json diff --git a/legacy-contracts/farm-v12/src/lib.rs b/legacy-contracts/farm-v12/src/lib.rs new file mode 100644 index 000000000..b575e6b8e --- /dev/null +++ b/legacy-contracts/farm-v12/src/lib.rs @@ -0,0 +1,218 @@ +#![no_std] +#![allow(deprecated)] + +use multiversx_sc::derive_imports::*; +use multiversx_sc::imports::*; + +type Nonce = u64; +type ExitFarmResultType = + MultiValue2, EsdtTokenPayment>; +type INCORRECTReturnType = ManagedBuffer; + +#[derive(TopEncode, TopDecode, PartialEq, TypeAbi)] +pub enum State { + Inactive, + Active, + Migrate, +} + +static ERROR_LEGACY_CONTRACT: &[u8] = b"This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."; + +#[multiversx_sc::contract] +pub trait FarmV12 { + #[init] + fn init(&self) {} + + #[payable("*")] + #[endpoint(acceptFee)] + fn accept_fee(&self) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(calculateRewardsForGivenPosition)] + fn calculate_rewards_for_given_position( + &self, + _amount: BigUint, + _attributes_raw: ManagedBuffer, + ) -> SCResult { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(end_produce_rewards_as_owner)] + fn end_produce_rewards_as_owner(&self) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[payable("*")] + #[endpoint(exitFarm)] + fn exit_farm( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> SCResult> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getBurnedTokenAmount)] + fn burned_tokens(&self) -> BigUint { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getCurrentBlockFee)] + fn current_block_fee_storage(&self) -> Option<(Nonce, BigUint)> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getDivisionSafetyConstant)] + fn division_safety_constant(&self) -> BigUint { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getFarmTokenId)] + fn farm_token_id(&self) -> TokenIdentifier { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getFarmTokenSupply)] + fn get_farm_token_supply(&self) -> BigUint { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getFarmingTokenId)] + fn farming_token_id(&self) -> TokenIdentifier { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getFarmingTokenReserve)] + fn farming_token_reserve(&self) -> BigUint { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getLastErrorMessage)] + fn last_error_message(&self) -> ManagedBuffer { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getLastRewardBlockNonce)] + fn last_reward_block_nonce(&self) -> Nonce { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getLockedAssetFactoryManagedAddress)] + fn locked_asset_factory_address(&self) -> ManagedAddress { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getLockedRewardAprMuliplier)] + fn locked_rewards_apr_multiplier(&self) -> u8 { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getMinimumFarmingEpoch)] + fn minimum_farming_epoch(&self) -> u8 { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getOwner)] + fn owner(&self) -> ManagedAddress { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getPairContractManagedAddress)] + fn pair_contract_address(&self) -> ManagedAddress { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getPenaltyPercent)] + fn penalty_percent(&self) -> u64 { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getPerBlockRewardAmount)] + fn per_block_reward_amount(&self) -> BigUint { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getRewardPerShare)] + fn reward_per_share(&self) -> BigUint { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getRewardReserve)] + fn reward_reserve(&self) -> BigUint { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getRewardTokenId)] + fn reward_token_id(&self) -> TokenIdentifier { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getRouterManagedAddress)] + fn router_address(&self) -> ManagedAddress { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getState)] + fn state(&self) -> State { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getTransferExecGasLimit)] + fn transfer_exec_gas_limit(&self) -> u64 { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getUndistributedFees)] + fn undistributed_fee_storage(&self) -> BigUint { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(pause)] + fn pause(&self) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(resume)] + fn resume(&self) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(setPerBlockRewardAmount)] + fn set_per_block_reward_amount(&self, _per_block_amount: BigUint) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint(setTransferRoleFarmToken)] + fn set_transfer_role_farm_token( + &self, + _opt_address: OptionalValue, + ) -> INCORRECTReturnType { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(set_locked_rewards_apr_multiplier)] + fn set_locked_rewards_apr_multiplier(&self, _muliplier: u8) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(set_minimum_farming_epochs)] + fn set_minimum_farming_epochs(&self, _epochs: u8) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(set_penalty_percent)] + fn set_penalty_percent(&self, _percent: u64) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(set_transfer_exec_gas_limit)] + fn set_transfer_exec_gas_limit(&self, _gas_limit: u64) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(start_produce_rewards)] + fn start_produce_rewards(&self) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } +} diff --git a/legacy-contracts/farm-v12/wasm/Cargo.lock b/legacy-contracts/farm-v12/wasm/Cargo.lock new file mode 100644 index 000000000..279bae584 --- /dev/null +++ b/legacy-contracts/farm-v12/wasm/Cargo.lock @@ -0,0 +1,188 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + +[[package]] +name = "farm-v12" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "farm-v12-wasm" +version = "0.0.0" +dependencies = [ + "farm-v12", + "multiversx-sc-wasm-adapter", +] + +[[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.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "multiversx-sc" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "nibble_vec" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" +dependencies = [ + "smallvec", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radix_trie" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" +dependencies = [ + "endian-type", + "nibble_vec", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" diff --git a/locked-asset/factory/wasm/Cargo.toml b/legacy-contracts/farm-v12/wasm/Cargo.toml similarity index 83% rename from locked-asset/factory/wasm/Cargo.toml rename to legacy-contracts/farm-v12/wasm/Cargo.toml index eb8c084a5..304603369 100644 --- a/locked-asset/factory/wasm/Cargo.toml +++ b/legacy-contracts/farm-v12/wasm/Cargo.toml @@ -5,7 +5,7 @@ # ########################################## [package] -name = "factory-wasm" +name = "farm-v12-wasm" version = "0.0.0" edition = "2021" publish = false @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false -[dependencies.factory] +[profile.dev] +panic = "abort" + +[dependencies.farm-v12] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "0.53.2" [workspace] members = ["."] diff --git a/legacy-contracts/farm-v12/wasm/src/lib.rs b/legacy-contracts/farm-v12/wasm/src/lib.rs new file mode 100644 index 000000000..90db50ccf --- /dev/null +++ b/legacy-contracts/farm-v12/wasm/src/lib.rs @@ -0,0 +1,60 @@ +// Code generated by the multiversx-sc build system. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +// Init: 1 +// Endpoints: 36 +// Async Callback (empty): 1 +// Total number of exported functions: 38 + +#![no_std] + +multiversx_sc_wasm_adapter::allocator!(); +multiversx_sc_wasm_adapter::panic_handler!(); + +multiversx_sc_wasm_adapter::endpoints! { + farm_v12 + ( + init => init + acceptFee => accept_fee + calculateRewardsForGivenPosition => calculate_rewards_for_given_position + end_produce_rewards_as_owner => end_produce_rewards_as_owner + exitFarm => exit_farm + getBurnedTokenAmount => burned_tokens + getCurrentBlockFee => current_block_fee_storage + getDivisionSafetyConstant => division_safety_constant + getFarmTokenId => farm_token_id + getFarmTokenSupply => get_farm_token_supply + getFarmingTokenId => farming_token_id + getFarmingTokenReserve => farming_token_reserve + getLastErrorMessage => last_error_message + getLastRewardBlockNonce => last_reward_block_nonce + getLockedAssetFactoryManagedAddress => locked_asset_factory_address + getLockedRewardAprMuliplier => locked_rewards_apr_multiplier + getMinimumFarmingEpoch => minimum_farming_epoch + getOwner => owner + getPairContractManagedAddress => pair_contract_address + getPenaltyPercent => penalty_percent + getPerBlockRewardAmount => per_block_reward_amount + getRewardPerShare => reward_per_share + getRewardReserve => reward_reserve + getRewardTokenId => reward_token_id + getRouterManagedAddress => router_address + getState => state + getTransferExecGasLimit => transfer_exec_gas_limit + getUndistributedFees => undistributed_fee_storage + pause => pause + resume => resume + setPerBlockRewardAmount => set_per_block_reward_amount + setTransferRoleFarmToken => set_transfer_role_farm_token + set_locked_rewards_apr_multiplier => set_locked_rewards_apr_multiplier + set_minimum_farming_epochs => set_minimum_farming_epochs + set_penalty_percent => set_penalty_percent + set_transfer_exec_gas_limit => set_transfer_exec_gas_limit + start_produce_rewards => start_produce_rewards + ) +} + +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/legacy-contracts/farm-v13-custom-rewards/Cargo.toml b/legacy-contracts/farm-v13-custom-rewards/Cargo.toml new file mode 100644 index 000000000..722f71885 --- /dev/null +++ b/legacy-contracts/farm-v13-custom-rewards/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "farm-v13-custom-rewards" +version = "0.0.0" +authors = ["you"] +edition = "2021" +publish = false + +[lib] +path = "src/lib.rs" + +[dependencies.multiversx-sc] +version = "0.53.2" + +[dev-dependencies] +num-bigint = "0.4" + +[dev-dependencies.multiversx-sc-scenario] +version = "0.53.2" diff --git a/legacy-contracts/farm-v13-custom-rewards/meta/Cargo.toml b/legacy-contracts/farm-v13-custom-rewards/meta/Cargo.toml new file mode 100644 index 000000000..2b8199137 --- /dev/null +++ b/legacy-contracts/farm-v13-custom-rewards/meta/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "farm-v13-custom-rewards-meta" +version = "0.0.0" +edition = "2021" +publish = false + +[dependencies.farm-v13-custom-rewards] +path = ".." + +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" +default-features = false diff --git a/legacy-contracts/farm-v13-custom-rewards/meta/src/main.rs b/legacy-contracts/farm-v13-custom-rewards/meta/src/main.rs new file mode 100644 index 000000000..5ee01436e --- /dev/null +++ b/legacy-contracts/farm-v13-custom-rewards/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta_lib::cli_main::(); +} diff --git a/locked-asset/factory/multiversx.json b/legacy-contracts/farm-v13-custom-rewards/multiversx.json similarity index 100% rename from locked-asset/factory/multiversx.json rename to legacy-contracts/farm-v13-custom-rewards/multiversx.json diff --git a/legacy-contracts/farm-v13-custom-rewards/src/lib.rs b/legacy-contracts/farm-v13-custom-rewards/src/lib.rs new file mode 100644 index 000000000..c5f4b5134 --- /dev/null +++ b/legacy-contracts/farm-v13-custom-rewards/src/lib.rs @@ -0,0 +1,260 @@ +#![no_std] +#![allow(deprecated)] + +use multiversx_sc::derive_imports::*; +use multiversx_sc::imports::*; + +type Nonce = u64; +type EnterFarmResultType = EsdtTokenPayment; +type ClaimRewardsResultType = + MultiValue2, EsdtTokenPayment>; +type ExitFarmResultType = + MultiValue2, EsdtTokenPayment>; +type INCORRECTReturnType = ManagedBuffer; + +#[derive(TopEncode, TopDecode, PartialEq, TypeAbi)] +pub enum State { + Inactive, + Active, +} + +#[derive(ManagedVecItem, TopEncode, TopDecode, NestedEncode, NestedDecode, TypeAbi, Clone)] +pub struct FarmTokenAttributes { + pub reward_per_share: BigUint, + pub original_entering_epoch: u64, + pub entering_epoch: u64, + pub initial_farming_amount: BigUint, + pub compounded_reward: BigUint, + pub current_farm_amount: BigUint, +} + +static ERROR_LEGACY_CONTRACT: &[u8] = b"This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."; + +#[multiversx_sc::contract] +pub trait FarmV13CustomRewards { + #[init] + fn init(&self) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint(addAddressToWhitelist)] + fn add_address_to_whitelist(&self, _address: ManagedAddress) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(calculateRewardsForGivenPosition)] + fn calculate_rewards_for_given_position( + &self, + _amount: BigUint, + _attributes: FarmTokenAttributes, + ) -> SCResult { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[payable("*")] + #[endpoint(claimRewards)] + fn claim_rewards( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> SCResult> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[payable("*")] + #[endpoint(depositRewards)] + fn deposit_rewards(&self) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(end_produce_rewards)] + fn end_produce_rewards(&self) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[payable("*")] + #[endpoint(enterFarm)] + fn enter_farm( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> SCResult> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[payable("*")] + #[endpoint(exitFarm)] + fn exit_farm( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> SCResult> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getBlockForEndRewards)] + fn block_for_end_rewards(&self) -> u64 { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getBurnGasLimit)] + fn burn_gas_limit(&self) -> u64 { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getDivisionSafetyConstant)] + fn division_safety_constant(&self) -> BigUint { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getFarmTokenId)] + fn farm_token_id(&self) -> TokenIdentifier { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getFarmTokenSupply)] + fn farm_token_supply(&self) -> BigUint { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getFarmingTokenId)] + fn farming_token_id(&self) -> TokenIdentifier { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getLastErrorMessage)] + fn last_error_message(&self) -> ManagedBuffer { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getLastRewardBlockNonce)] + fn last_reward_block_nonce(&self) -> Nonce { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getMinimumFarmingEpoch)] + fn minimum_farming_epochs(&self) -> u8 { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getOwner)] + fn owner(&self) -> ManagedAddress { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getPenaltyPercent)] + fn penalty_percent(&self) -> u64 { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getPerBlockRewardAmount)] + fn per_block_reward_amount(&self) -> BigUint { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getRewardPerShare)] + fn reward_per_share(&self) -> BigUint { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getRewardReserve)] + fn reward_reserve(&self) -> BigUint { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getRewardTokenId)] + fn reward_token_id(&self) -> TokenIdentifier { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getState)] + fn state(&self) -> State { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getTransferExecGasLimit)] + fn transfer_exec_gas_limit(&self) -> u64 { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getWhitelist)] + fn whitelist(&self) -> UnorderedSetMapper { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[payable("*")] + #[endpoint(mergeFarmTokens)] + fn merge_farm_tokens( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> SCResult> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(pause)] + fn pause(&self) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[payable("EGLD")] + #[endpoint(registerFarmToken)] + fn register_farm_token( + &self, + _token_display_name: ManagedBuffer, + _token_ticker: ManagedBuffer, + _num_decimals: usize, + ) -> INCORRECTReturnType { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint(removeAddressFromWhitelist)] + fn remove_address_from_whitelist(&self, _address: ManagedAddress) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(resume)] + fn resume(&self) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint(setBlockForEndRewards)] + fn set_block_for_end_rewards(&self, _block_end: u64) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(setLocalRolesFarmToken)] + fn set_local_roles_farm_token(&self) -> INCORRECTReturnType { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(setPerBlockRewardAmount)] + fn set_per_block_reward_amount(&self, _per_block_amount: BigUint) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(set_burn_gas_limit)] + fn set_burn_gas_limit(&self, _gas_limit: u64) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(set_minimum_farming_epochs)] + fn set_minimum_farming_epochs(&self, _epochs: u8) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(set_penalty_percent)] + fn set_penalty_percent(&self, _percent: u64) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(set_transfer_exec_gas_limit)] + fn set_transfer_exec_gas_limit(&self, _gas_limit: u64) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(startProduceRewards)] + fn start_produce_rewards(&self) -> SCResult<()> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } +} diff --git a/legacy-contracts/farm-v13-custom-rewards/wasm/Cargo.lock b/legacy-contracts/farm-v13-custom-rewards/wasm/Cargo.lock new file mode 100644 index 000000000..ce3ccf8cf --- /dev/null +++ b/legacy-contracts/farm-v13-custom-rewards/wasm/Cargo.lock @@ -0,0 +1,188 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + +[[package]] +name = "farm-v13-custom-rewards" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "farm-v13-custom-rewards-wasm" +version = "0.0.0" +dependencies = [ + "farm-v13-custom-rewards", + "multiversx-sc-wasm-adapter", +] + +[[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.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "multiversx-sc" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "nibble_vec" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" +dependencies = [ + "smallvec", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radix_trie" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" +dependencies = [ + "endian-type", + "nibble_vec", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" diff --git a/legacy-contracts/farm-v13-custom-rewards/wasm/Cargo.toml b/legacy-contracts/farm-v13-custom-rewards/wasm/Cargo.toml new file mode 100644 index 000000000..23b1394e1 --- /dev/null +++ b/legacy-contracts/farm-v13-custom-rewards/wasm/Cargo.toml @@ -0,0 +1,34 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + +[package] +name = "farm-v13-custom-rewards-wasm" +version = "0.0.0" +edition = "2021" +publish = false + +[lib] +crate-type = ["cdylib"] + +[profile.release] +codegen-units = 1 +opt-level = "z" +lto = true +debug = false +panic = "abort" +overflow-checks = false + +[profile.dev] +panic = "abort" + +[dependencies.farm-v13-custom-rewards] +path = ".." + +[dependencies.multiversx-sc-wasm-adapter] +version = "0.53.2" + +[workspace] +members = ["."] diff --git a/legacy-contracts/farm-v13-custom-rewards/wasm/src/lib.rs b/legacy-contracts/farm-v13-custom-rewards/wasm/src/lib.rs new file mode 100644 index 000000000..1c377fcbd --- /dev/null +++ b/legacy-contracts/farm-v13-custom-rewards/wasm/src/lib.rs @@ -0,0 +1,62 @@ +// Code generated by the multiversx-sc build system. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +// Init: 1 +// Endpoints: 38 +// Async Callback (empty): 1 +// Total number of exported functions: 40 + +#![no_std] + +multiversx_sc_wasm_adapter::allocator!(); +multiversx_sc_wasm_adapter::panic_handler!(); + +multiversx_sc_wasm_adapter::endpoints! { + farm_v13_custom_rewards + ( + init => init + addAddressToWhitelist => add_address_to_whitelist + calculateRewardsForGivenPosition => calculate_rewards_for_given_position + claimRewards => claim_rewards + depositRewards => deposit_rewards + end_produce_rewards => end_produce_rewards + enterFarm => enter_farm + exitFarm => exit_farm + getBlockForEndRewards => block_for_end_rewards + getBurnGasLimit => burn_gas_limit + getDivisionSafetyConstant => division_safety_constant + getFarmTokenId => farm_token_id + getFarmTokenSupply => farm_token_supply + getFarmingTokenId => farming_token_id + getLastErrorMessage => last_error_message + getLastRewardBlockNonce => last_reward_block_nonce + getMinimumFarmingEpoch => minimum_farming_epochs + getOwner => owner + getPenaltyPercent => penalty_percent + getPerBlockRewardAmount => per_block_reward_amount + getRewardPerShare => reward_per_share + getRewardReserve => reward_reserve + getRewardTokenId => reward_token_id + getState => state + getTransferExecGasLimit => transfer_exec_gas_limit + getWhitelist => whitelist + mergeFarmTokens => merge_farm_tokens + pause => pause + registerFarmToken => register_farm_token + removeAddressFromWhitelist => remove_address_from_whitelist + resume => resume + setBlockForEndRewards => set_block_for_end_rewards + setLocalRolesFarmToken => set_local_roles_farm_token + setPerBlockRewardAmount => set_per_block_reward_amount + set_burn_gas_limit => set_burn_gas_limit + set_minimum_farming_epochs => set_minimum_farming_epochs + set_penalty_percent => set_penalty_percent + set_transfer_exec_gas_limit => set_transfer_exec_gas_limit + startProduceRewards => start_produce_rewards + ) +} + +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/legacy-contracts/farm-v13-locked-rewards/Cargo.toml b/legacy-contracts/farm-v13-locked-rewards/Cargo.toml new file mode 100644 index 000000000..a9a171d50 --- /dev/null +++ b/legacy-contracts/farm-v13-locked-rewards/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "farm-v13-locked-rewards" +version = "0.0.0" +authors = ["you"] +edition = "2021" +publish = false + +[lib] +path = "src/lib.rs" + +[dependencies.multiversx-sc] +version = "0.53.2" + +[dev-dependencies] +num-bigint = "0.4" + +[dev-dependencies.multiversx-sc-scenario] +version = "0.53.2" diff --git a/legacy-contracts/farm-v13-locked-rewards/meta/Cargo.toml b/legacy-contracts/farm-v13-locked-rewards/meta/Cargo.toml new file mode 100644 index 000000000..17f06671c --- /dev/null +++ b/legacy-contracts/farm-v13-locked-rewards/meta/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "farm-v13-locked-rewards-meta" +version = "0.0.0" +edition = "2021" +publish = false + +[dependencies.farm-v13-locked-rewards] +path = ".." + +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" +default-features = false diff --git a/legacy-contracts/farm-v13-locked-rewards/meta/src/main.rs b/legacy-contracts/farm-v13-locked-rewards/meta/src/main.rs new file mode 100644 index 000000000..48a6d6e77 --- /dev/null +++ b/legacy-contracts/farm-v13-locked-rewards/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta_lib::cli_main::(); +} diff --git a/locked-asset/simple-lock-whitelist/multiversx.json b/legacy-contracts/farm-v13-locked-rewards/multiversx.json similarity index 100% rename from locked-asset/simple-lock-whitelist/multiversx.json rename to legacy-contracts/farm-v13-locked-rewards/multiversx.json diff --git a/legacy-contracts/farm-v13-locked-rewards/src/lib.rs b/legacy-contracts/farm-v13-locked-rewards/src/lib.rs new file mode 100644 index 000000000..adc122425 --- /dev/null +++ b/legacy-contracts/farm-v13-locked-rewards/src/lib.rs @@ -0,0 +1,274 @@ +#![no_std] + +use multiversx_sc::derive_imports::*; +use multiversx_sc::imports::*; + +type Nonce = u64; +pub type ExitFarmResultType = + MultiValue2, EsdtTokenPayment>; + +#[derive(TopEncode, TopDecode, PartialEq, TypeAbi)] +pub enum State { + Inactive, + Active, +} + +#[derive( + ManagedVecItem, + TopEncode, + TopDecode, + NestedEncode, + NestedDecode, + TypeAbi, + Clone, + PartialEq, + Debug, +)] +pub struct FarmTokenAttributes { + pub reward_per_share: BigUint, + pub original_entering_epoch: u64, + pub entering_epoch: u64, + pub initial_farming_amount: BigUint, + pub compounded_reward: BigUint, + pub current_farm_amount: BigUint, +} + +#[derive(ManagedVecItem, TopEncode, TopDecode, NestedEncode, NestedDecode, TypeAbi, Clone)] +pub struct FarmTokenAttributesV1_2 { + pub reward_per_share: BigUint, + pub original_entering_epoch: u64, + pub entering_epoch: u64, + pub apr_multiplier: u8, + pub with_locked_rewards: bool, + pub initial_farming_amount: BigUint, + pub compounded_reward: BigUint, + pub current_farm_amount: BigUint, +} + +#[derive(TypeAbi, TopEncode, TopDecode, NestedEncode, NestedDecode, PartialEq)] +pub enum FarmMigrationRole { + Old, + New, + NewWithLock, +} + +#[derive(TypeAbi, TopEncode, TopDecode)] +pub struct FarmMigrationConfig { + migration_role: FarmMigrationRole, + old_farm_address: ManagedAddress, + old_farm_token_id: TokenIdentifier, +} + +static ERROR_LEGACY_CONTRACT: &[u8] = b"This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."; + +#[multiversx_sc::contract] +pub trait FarmV13LockedRewards { + #[init] + fn init(&self) {} + + #[payable("*")] + #[endpoint(exitFarm)] + fn exit_farm( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> ExitFarmResultType { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[payable("*")] + #[endpoint(mergeFarmTokens)] + fn merge_farm_tokens( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> EsdtTokenPayment { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(calculateRewardsForGivenPosition)] + fn calculate_rewards_for_given_position( + &self, + _amount: BigUint, + _attributes: FarmTokenAttributes, + ) -> BigUint { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint] + fn end_produce_rewards(&self) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint(setPerBlockRewardAmount)] + fn set_per_block_rewards(&self, _per_block_amount: BigUint) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint] + fn set_penalty_percent(&self, _percent: u64) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint] + fn set_minimum_farming_epochs(&self, _epochs: u8) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint] + fn set_transfer_exec_gas_limit(&self, _gas_limit: u64) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint] + fn set_burn_gas_limit(&self, _gas_limit: u64) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(setRpsAndStartRewards)] + fn set_rps_and_start_rewards(&self, _rps: BigUint) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint] + fn pause(&self) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint] + fn resume(&self) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(startProduceRewards)] + fn start_produce_rewards_as_owner(&self) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint(setFarmTokenSupply)] + fn set_farm_token_supply(&self, _supply: BigUint) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint(setFarmMigrationConfig)] + fn set_farm_migration_config( + &self, + _old_farm_address: ManagedAddress, + _old_farm_token_id: TokenIdentifier, + _new_farm_address: ManagedAddress, + _new_farm_with_lock_address: ManagedAddress, + ) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[payable("EGLD")] + #[endpoint(registerFarmToken)] + fn register_farm_token( + &self, + _token_display_name: ManagedBuffer, + _token_ticker: ManagedBuffer, + _num_decimals: usize, + ) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint(setLocalRolesFarmToken)] + fn set_local_roles_farm_token(&self) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[payable("*")] + #[endpoint(migrateFromV1_2Farm)] + fn migrate_from_v1_2_farm( + &self, + _old_attrs: FarmTokenAttributesV1_2, + _orig_caller: ManagedAddress, + ) -> EsdtTokenPayment { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getFarmMigrationConfiguration)] + #[storage_mapper("farm_migration_config")] + fn farm_migration_config(&self) -> SingleValueMapper>; + + #[view(getFarmTokenSupply)] + #[storage_mapper("farm_token_supply")] + fn farm_token_supply(&self) -> SingleValueMapper; + + #[view(getLastErrorMessage)] + #[storage_mapper("last_error_message")] + fn last_error_message(&self) -> SingleValueMapper; + + #[view(getState)] + #[storage_mapper("state")] + fn state(&self) -> SingleValueMapper; + + #[view(getFarmingTokenId)] + #[storage_mapper("farming_token_id")] + fn farming_token_id(&self) -> SingleValueMapper; + + #[view(getRewardTokenId)] + #[storage_mapper("reward_token_id")] + fn reward_token_id(&self) -> SingleValueMapper; + + #[view(getPenaltyPercent)] + #[storage_mapper("penalty_percent")] + fn penalty_percent(&self) -> SingleValueMapper; + + #[view(getMinimumFarmingEpoch)] + #[storage_mapper("minimum_farming_epochs")] + fn minimum_farming_epochs(&self) -> SingleValueMapper; + + #[view(getPerBlockRewardAmount)] + #[storage_mapper("per_block_reward_amount")] + fn per_block_reward_amount(&self) -> SingleValueMapper; + + #[storage_mapper("produce_rewards_enabled")] + fn produce_rewards_enabled(&self) -> SingleValueMapper; + + #[view(getLastRewardBlockNonce)] + #[storage_mapper("last_reward_block_nonce")] + fn last_reward_block_nonce(&self) -> SingleValueMapper; + + #[view(getFarmTokenId)] + #[storage_mapper("farm_token_id")] + fn farm_token_id(&self) -> SingleValueMapper; + + #[view(getDivisionSafetyConstant)] + #[storage_mapper("division_safety_constant")] + fn division_safety_constant(&self) -> SingleValueMapper; + + #[view(getPairContractManagedAddress)] + #[storage_mapper("pair_contract_address")] + fn pair_contract_address(&self) -> SingleValueMapper; + + #[view(getBurnGasLimit)] + #[storage_mapper("burn_gas_limit")] + fn burn_gas_limit(&self) -> SingleValueMapper; + + #[view(getLockedAssetFactoryManagedAddress)] + #[storage_mapper("locked_asset_factory_address")] + fn locked_asset_factory_address(&self) -> SingleValueMapper; + + #[view(getRewardPerShare)] + #[storage_mapper("reward_per_share")] + fn reward_per_share(&self) -> SingleValueMapper; + + #[view(getRewardReserve)] + #[storage_mapper("reward_reserve")] + fn reward_reserve(&self) -> SingleValueMapper; + + #[view(getTransferExecGasLimit)] + #[storage_mapper("transfer_exec_gas_limit")] + fn transfer_exec_gas_limit(&self) -> SingleValueMapper; +} diff --git a/legacy-contracts/farm-v13-locked-rewards/wasm/Cargo.lock b/legacy-contracts/farm-v13-locked-rewards/wasm/Cargo.lock new file mode 100644 index 000000000..be30bee74 --- /dev/null +++ b/legacy-contracts/farm-v13-locked-rewards/wasm/Cargo.lock @@ -0,0 +1,188 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + +[[package]] +name = "farm-v13-locked-rewards" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "farm-v13-locked-rewards-wasm" +version = "0.0.0" +dependencies = [ + "farm-v13-locked-rewards", + "multiversx-sc-wasm-adapter", +] + +[[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.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "multiversx-sc" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "nibble_vec" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" +dependencies = [ + "smallvec", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radix_trie" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" +dependencies = [ + "endian-type", + "nibble_vec", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" diff --git a/legacy-contracts/farm-v13-locked-rewards/wasm/Cargo.toml b/legacy-contracts/farm-v13-locked-rewards/wasm/Cargo.toml new file mode 100644 index 000000000..0009f0580 --- /dev/null +++ b/legacy-contracts/farm-v13-locked-rewards/wasm/Cargo.toml @@ -0,0 +1,34 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + +[package] +name = "farm-v13-locked-rewards-wasm" +version = "0.0.0" +edition = "2021" +publish = false + +[lib] +crate-type = ["cdylib"] + +[profile.release] +codegen-units = 1 +opt-level = "z" +lto = true +debug = false +panic = "abort" +overflow-checks = false + +[profile.dev] +panic = "abort" + +[dependencies.farm-v13-locked-rewards] +path = ".." + +[dependencies.multiversx-sc-wasm-adapter] +version = "0.53.2" + +[workspace] +members = ["."] diff --git a/legacy-contracts/farm-v13-locked-rewards/wasm/src/lib.rs b/legacy-contracts/farm-v13-locked-rewards/wasm/src/lib.rs new file mode 100644 index 000000000..f45431ebf --- /dev/null +++ b/legacy-contracts/farm-v13-locked-rewards/wasm/src/lib.rs @@ -0,0 +1,60 @@ +// Code generated by the multiversx-sc build system. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +// Init: 1 +// Endpoints: 36 +// Async Callback (empty): 1 +// Total number of exported functions: 38 + +#![no_std] + +multiversx_sc_wasm_adapter::allocator!(); +multiversx_sc_wasm_adapter::panic_handler!(); + +multiversx_sc_wasm_adapter::endpoints! { + farm_v13_locked_rewards + ( + init => init + exitFarm => exit_farm + mergeFarmTokens => merge_farm_tokens + calculateRewardsForGivenPosition => calculate_rewards_for_given_position + end_produce_rewards => end_produce_rewards + setPerBlockRewardAmount => set_per_block_rewards + set_penalty_percent => set_penalty_percent + set_minimum_farming_epochs => set_minimum_farming_epochs + set_transfer_exec_gas_limit => set_transfer_exec_gas_limit + set_burn_gas_limit => set_burn_gas_limit + setRpsAndStartRewards => set_rps_and_start_rewards + pause => pause + resume => resume + startProduceRewards => start_produce_rewards_as_owner + setFarmTokenSupply => set_farm_token_supply + setFarmMigrationConfig => set_farm_migration_config + registerFarmToken => register_farm_token + setLocalRolesFarmToken => set_local_roles_farm_token + migrateFromV1_2Farm => migrate_from_v1_2_farm + getFarmMigrationConfiguration => farm_migration_config + getFarmTokenSupply => farm_token_supply + getLastErrorMessage => last_error_message + getState => state + getFarmingTokenId => farming_token_id + getRewardTokenId => reward_token_id + getPenaltyPercent => penalty_percent + getMinimumFarmingEpoch => minimum_farming_epochs + getPerBlockRewardAmount => per_block_reward_amount + getLastRewardBlockNonce => last_reward_block_nonce + getFarmTokenId => farm_token_id + getDivisionSafetyConstant => division_safety_constant + getPairContractManagedAddress => pair_contract_address + getBurnGasLimit => burn_gas_limit + getLockedAssetFactoryManagedAddress => locked_asset_factory_address + getRewardPerShare => reward_per_share + getRewardReserve => reward_reserve + getTransferExecGasLimit => transfer_exec_gas_limit + ) +} + +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/legacy-contracts/farm-v13/Cargo.toml b/legacy-contracts/farm-v13/Cargo.toml new file mode 100644 index 000000000..1d0cb3293 --- /dev/null +++ b/legacy-contracts/farm-v13/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "farm-v13" +version = "0.0.0" +authors = ["you"] +edition = "2021" +publish = false + +[lib] +path = "src/lib.rs" + +[dependencies.multiversx-sc] +version = "0.53.2" + +[dev-dependencies] +num-bigint = "0.4" + +[dev-dependencies.multiversx-sc-scenario] +version = "0.53.2" diff --git a/legacy-contracts/farm-v13/meta/Cargo.toml b/legacy-contracts/farm-v13/meta/Cargo.toml new file mode 100644 index 000000000..a2f61190b --- /dev/null +++ b/legacy-contracts/farm-v13/meta/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "farm-v13-meta" +version = "0.0.0" +edition = "2021" +publish = false + +[dependencies.farm-v13] +path = ".." + +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" +default-features = false diff --git a/legacy-contracts/farm-v13/meta/src/main.rs b/legacy-contracts/farm-v13/meta/src/main.rs new file mode 100644 index 000000000..b7c87b3f2 --- /dev/null +++ b/legacy-contracts/farm-v13/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta_lib::cli_main::(); +} diff --git a/dex/pair-mock/elrond.json b/legacy-contracts/farm-v13/multiversx.json similarity index 100% rename from dex/pair-mock/elrond.json rename to legacy-contracts/farm-v13/multiversx.json diff --git a/legacy-contracts/farm-v13/src/lib.rs b/legacy-contracts/farm-v13/src/lib.rs new file mode 100644 index 000000000..81461625b --- /dev/null +++ b/legacy-contracts/farm-v13/src/lib.rs @@ -0,0 +1,305 @@ +#![no_std] + +use multiversx_sc::derive_imports::*; +use multiversx_sc::imports::*; + +type Nonce = u64; +type EnterFarmResultType = EsdtTokenPayment; +type CompoundRewardsResultType = EsdtTokenPayment; +type ClaimRewardsResultType = + MultiValue2, EsdtTokenPayment>; +type ExitFarmResultType = + MultiValue2, EsdtTokenPayment>; + +#[derive(TopEncode, TopDecode, PartialEq, TypeAbi)] +pub enum State { + Inactive, + Active, +} + +#[derive( + ManagedVecItem, + TopEncode, + TopDecode, + NestedEncode, + NestedDecode, + TypeAbi, + Clone, + PartialEq, + Debug, +)] +pub struct FarmTokenAttributes { + pub reward_per_share: BigUint, + pub original_entering_epoch: u64, + pub entering_epoch: u64, + pub initial_farming_amount: BigUint, + pub compounded_reward: BigUint, + pub current_farm_amount: BigUint, +} + +#[derive(ManagedVecItem, TopEncode, TopDecode, NestedEncode, NestedDecode, TypeAbi, Clone)] +pub struct FarmTokenAttributesV1_2 { + pub reward_per_share: BigUint, + pub original_entering_epoch: u64, + pub entering_epoch: u64, + pub apr_multiplier: u8, + pub with_locked_rewards: bool, + pub initial_farming_amount: BigUint, + pub compounded_reward: BigUint, + pub current_farm_amount: BigUint, +} + +#[derive(TypeAbi, TopEncode, TopDecode, NestedEncode, NestedDecode, PartialEq)] +pub enum FarmMigrationRole { + Old, + New, + NewWithLock, +} + +#[derive(TypeAbi, TopEncode, TopDecode)] +pub struct FarmMigrationConfig { + migration_role: FarmMigrationRole, + old_farm_address: ManagedAddress, + old_farm_token_id: TokenIdentifier, +} + +static ERROR_LEGACY_CONTRACT: &[u8] = b"This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."; + +#[multiversx_sc::contract] +pub trait FarmV13 { + #[init] + fn init(&self) {} + + #[payable("*")] + #[endpoint(enterFarm)] + fn enter_farm( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> EnterFarmResultType { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[payable("*")] + #[endpoint(exitFarm)] + fn exit_farm( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> ExitFarmResultType { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[payable("*")] + #[endpoint(claimRewards)] + fn claim_rewards( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> ClaimRewardsResultType { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[payable("*")] + #[endpoint(compoundRewards)] + fn compound_rewards( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> CompoundRewardsResultType { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[payable("*")] + #[endpoint(mergeFarmTokens)] + fn merge_farm_tokens( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> EsdtTokenPayment { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(calculateRewardsForGivenPosition)] + fn calculate_rewards_for_given_position( + &self, + _amount: BigUint, + _attributes: FarmTokenAttributes, + ) -> BigUint { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint] + fn end_produce_rewards(&self) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint(setPerBlockRewardAmount)] + fn set_per_block_rewards(&self, _per_block_amount: BigUint) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint] + fn set_penalty_percent(&self, _percent: u64) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint] + fn set_minimum_farming_epochs(&self, _epochs: u8) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint] + fn set_transfer_exec_gas_limit(&self, _gas_limit: u64) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint] + fn set_burn_gas_limit(&self, _gas_limit: u64) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint] + fn pause(&self) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint] + fn resume(&self) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(startProduceRewards)] + fn start_produce_rewards_as_owner(&self) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint(setFarmTokenSupply)] + fn set_farm_token_supply(&self, _supply: BigUint) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint(setFarmMigrationConfig)] + fn set_farm_migration_config( + &self, + _old_farm_address: ManagedAddress, + _old_farm_token_id: TokenIdentifier, + _new_farm_address: ManagedAddress, + _new_farm_with_lock_address: ManagedAddress, + ) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[payable("EGLD")] + #[endpoint(registerFarmToken)] + fn register_farm_token( + &self, + _token_display_name: ManagedBuffer, + _token_ticker: ManagedBuffer, + _num_decimals: usize, + ) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint(setLocalRolesFarmToken)] + fn set_local_roles_farm_token(&self) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint(setRpsAndStartRewards)] + fn set_rps_and_start_rewards(&self, _rps: BigUint) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[payable("*")] + #[endpoint(migrateFromV1_2Farm)] + fn migrate_from_v1_2_farm( + &self, + _old_attrs: FarmTokenAttributesV1_2, + _orig_caller: ManagedAddress, + ) -> EsdtTokenPayment { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getFarmMigrationConfiguration)] + #[storage_mapper("farm_migration_config")] + fn farm_migration_config(&self) -> SingleValueMapper>; + + #[view(getFarmTokenSupply)] + #[storage_mapper("farm_token_supply")] + fn farm_token_supply(&self) -> SingleValueMapper; + + #[view(getLastErrorMessage)] + #[storage_mapper("last_error_message")] + fn last_error_message(&self) -> SingleValueMapper; + + #[view(getState)] + #[storage_mapper("state")] + fn state(&self) -> SingleValueMapper; + + #[view(getFarmingTokenId)] + #[storage_mapper("farming_token_id")] + fn farming_token_id(&self) -> SingleValueMapper; + + #[view(getRewardTokenId)] + #[storage_mapper("reward_token_id")] + fn reward_token_id(&self) -> SingleValueMapper; + + #[view(getPenaltyPercent)] + #[storage_mapper("penalty_percent")] + fn penalty_percent(&self) -> SingleValueMapper; + + #[view(getMinimumFarmingEpoch)] + #[storage_mapper("minimum_farming_epochs")] + fn minimum_farming_epochs(&self) -> SingleValueMapper; + + #[view(getPerBlockRewardAmount)] + #[storage_mapper("per_block_reward_amount")] + fn per_block_reward_amount(&self) -> SingleValueMapper; + + #[storage_mapper("produce_rewards_enabled")] + fn produce_rewards_enabled(&self) -> SingleValueMapper; + + #[view(getLastRewardBlockNonce)] + #[storage_mapper("last_reward_block_nonce")] + fn last_reward_block_nonce(&self) -> SingleValueMapper; + + #[view(getFarmTokenId)] + #[storage_mapper("farm_token_id")] + fn farm_token_id(&self) -> SingleValueMapper; + + #[view(getDivisionSafetyConstant)] + #[storage_mapper("division_safety_constant")] + fn division_safety_constant(&self) -> SingleValueMapper; + + #[view(getPairContractManagedAddress)] + #[storage_mapper("pair_contract_address")] + fn pair_contract_address(&self) -> SingleValueMapper; + + #[view(getBurnGasLimit)] + #[storage_mapper("burn_gas_limit")] + fn burn_gas_limit(&self) -> SingleValueMapper; + + #[view(getLockedAssetFactoryManagedAddress)] + #[storage_mapper("locked_asset_factory_address")] + fn locked_asset_factory_address(&self) -> SingleValueMapper; + + #[view(getRewardPerShare)] + #[storage_mapper("reward_per_share")] + fn reward_per_share(&self) -> SingleValueMapper; + + #[view(getRewardReserve)] + #[storage_mapper("reward_reserve")] + fn reward_reserve(&self) -> SingleValueMapper; + + #[view(getTransferExecGasLimit)] + #[storage_mapper("transfer_exec_gas_limit")] + fn transfer_exec_gas_limit(&self) -> SingleValueMapper; +} diff --git a/legacy-contracts/farm-v13/wasm/Cargo.lock b/legacy-contracts/farm-v13/wasm/Cargo.lock new file mode 100644 index 000000000..9a53ce3f3 --- /dev/null +++ b/legacy-contracts/farm-v13/wasm/Cargo.lock @@ -0,0 +1,188 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + +[[package]] +name = "farm-v13" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "farm-v13-wasm" +version = "0.0.0" +dependencies = [ + "farm-v13", + "multiversx-sc-wasm-adapter", +] + +[[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.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "multiversx-sc" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "nibble_vec" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" +dependencies = [ + "smallvec", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radix_trie" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" +dependencies = [ + "endian-type", + "nibble_vec", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" diff --git a/locked-asset/distribution/wasm/Cargo.toml b/legacy-contracts/farm-v13/wasm/Cargo.toml similarity index 83% rename from locked-asset/distribution/wasm/Cargo.toml rename to legacy-contracts/farm-v13/wasm/Cargo.toml index f1cc0ae57..580a514c5 100644 --- a/locked-asset/distribution/wasm/Cargo.toml +++ b/legacy-contracts/farm-v13/wasm/Cargo.toml @@ -5,7 +5,7 @@ # ########################################## [package] -name = "distribution-wasm" +name = "farm-v13-wasm" version = "0.0.0" edition = "2021" publish = false @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false -[dependencies.distribution] +[profile.dev] +panic = "abort" + +[dependencies.farm-v13] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "0.53.2" [workspace] members = ["."] diff --git a/legacy-contracts/farm-v13/wasm/src/lib.rs b/legacy-contracts/farm-v13/wasm/src/lib.rs new file mode 100644 index 000000000..2fef50415 --- /dev/null +++ b/legacy-contracts/farm-v13/wasm/src/lib.rs @@ -0,0 +1,63 @@ +// Code generated by the multiversx-sc build system. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +// Init: 1 +// Endpoints: 39 +// Async Callback (empty): 1 +// Total number of exported functions: 41 + +#![no_std] + +multiversx_sc_wasm_adapter::allocator!(); +multiversx_sc_wasm_adapter::panic_handler!(); + +multiversx_sc_wasm_adapter::endpoints! { + farm_v13 + ( + init => init + enterFarm => enter_farm + exitFarm => exit_farm + claimRewards => claim_rewards + compoundRewards => compound_rewards + mergeFarmTokens => merge_farm_tokens + calculateRewardsForGivenPosition => calculate_rewards_for_given_position + end_produce_rewards => end_produce_rewards + setPerBlockRewardAmount => set_per_block_rewards + set_penalty_percent => set_penalty_percent + set_minimum_farming_epochs => set_minimum_farming_epochs + set_transfer_exec_gas_limit => set_transfer_exec_gas_limit + set_burn_gas_limit => set_burn_gas_limit + pause => pause + resume => resume + startProduceRewards => start_produce_rewards_as_owner + setFarmTokenSupply => set_farm_token_supply + setFarmMigrationConfig => set_farm_migration_config + registerFarmToken => register_farm_token + setLocalRolesFarmToken => set_local_roles_farm_token + setRpsAndStartRewards => set_rps_and_start_rewards + migrateFromV1_2Farm => migrate_from_v1_2_farm + getFarmMigrationConfiguration => farm_migration_config + getFarmTokenSupply => farm_token_supply + getLastErrorMessage => last_error_message + getState => state + getFarmingTokenId => farming_token_id + getRewardTokenId => reward_token_id + getPenaltyPercent => penalty_percent + getMinimumFarmingEpoch => minimum_farming_epochs + getPerBlockRewardAmount => per_block_reward_amount + getLastRewardBlockNonce => last_reward_block_nonce + getFarmTokenId => farm_token_id + getDivisionSafetyConstant => division_safety_constant + getPairContractManagedAddress => pair_contract_address + getBurnGasLimit => burn_gas_limit + getLockedAssetFactoryManagedAddress => locked_asset_factory_address + getRewardPerShare => reward_per_share + getRewardReserve => reward_reserve + getTransferExecGasLimit => transfer_exec_gas_limit + ) +} + +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/locked-asset/simple-lock-whitelist/.gitignore b/legacy-contracts/locked-asset-distribution/.gitignore similarity index 100% rename from locked-asset/simple-lock-whitelist/.gitignore rename to legacy-contracts/locked-asset-distribution/.gitignore diff --git a/locked-asset/distribution/Cargo.toml b/legacy-contracts/locked-asset-distribution/Cargo.toml similarity index 72% rename from locked-asset/distribution/Cargo.toml rename to legacy-contracts/locked-asset-distribution/Cargo.toml index 3ebf0939b..6e81aa03a 100644 --- a/locked-asset/distribution/Cargo.toml +++ b/legacy-contracts/locked-asset-distribution/Cargo.toml @@ -1,6 +1,6 @@ [package] edition = "2021" -name = "distribution" +name = "locked-asset-distribution" publish = false version = "0.0.0" @@ -10,12 +10,9 @@ path = "src/lib.rs" [dependencies.common_structs] path = "../../common/common_structs" -[dependencies.factory] -path = "../factory" - [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" diff --git a/locked-asset/distribution/README.md b/legacy-contracts/locked-asset-distribution/README.md similarity index 100% rename from locked-asset/distribution/README.md rename to legacy-contracts/locked-asset-distribution/README.md diff --git a/farm-staking/metabonding-staking/meta/Cargo.toml b/legacy-contracts/locked-asset-distribution/meta/Cargo.toml similarity index 51% rename from farm-staking/metabonding-staking/meta/Cargo.toml rename to legacy-contracts/locked-asset-distribution/meta/Cargo.toml index 71df2c0ba..800a737f6 100644 --- a/farm-staking/metabonding-staking/meta/Cargo.toml +++ b/legacy-contracts/locked-asset-distribution/meta/Cargo.toml @@ -1,15 +1,13 @@ [package] -name = "metabonding-staking-meta" +name = "locked-asset-distribution-abi" version = "0.0.0" +authors = ["MultiversX "] edition = "2021" publish = false -authors = ["MultiversX "] - -[dev-dependencies] -[dependencies.metabonding-staking] +[dependencies.locked-asset-distribution] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/legacy-contracts/locked-asset-distribution/meta/src/main.rs b/legacy-contracts/locked-asset-distribution/meta/src/main.rs new file mode 100644 index 000000000..6b03650e9 --- /dev/null +++ b/legacy-contracts/locked-asset-distribution/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta_lib::cli_main::(); +} diff --git a/dex/price-discovery/elrond.json b/legacy-contracts/locked-asset-distribution/multiversx.json similarity index 100% rename from dex/price-discovery/elrond.json rename to legacy-contracts/locked-asset-distribution/multiversx.json diff --git a/legacy-contracts/locked-asset-distribution/src/lib.rs b/legacy-contracts/locked-asset-distribution/src/lib.rs new file mode 100644 index 000000000..0103fbf09 --- /dev/null +++ b/legacy-contracts/locked-asset-distribution/src/lib.rs @@ -0,0 +1,92 @@ +#![no_std] +#![allow(clippy::type_complexity)] + +use common_structs::UnlockPeriod; + +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +#[derive(ManagedVecItem)] +pub struct BigUintEpochPair { + pub biguint: BigUint, + pub epoch: u64, +} + +#[derive(ManagedVecItem, TopEncode, TopDecode, NestedEncode, NestedDecode, PartialEq, TypeAbi)] +pub struct UserLockedAssetKey { + pub caller: ManagedAddress, + pub spread_epoch: u64, +} + +#[derive(TopEncode, TopDecode, NestedEncode, NestedDecode, PartialEq, TypeAbi, Clone)] +pub struct CommunityDistribution { + pub total_amount: BigUint, + pub spread_epoch: u64, + pub after_planning_amount: BigUint, +} + +#[multiversx_sc::contract] +pub trait Distribution { + #[init] + fn init(&self) {} + + #[upgrade] + fn upgrade(&self) {} + + #[endpoint(clearSingleValueMappers)] + fn clear_single_value_mappers(&self) { + self.unlock_period().clear(); + self.locked_asset_factory_address().clear(); + self.asset_token_id().clear(); + self.global_op_is_ongoing().clear(); + } + + // Returns the number of entries deleted and entries remaining in the storage. + #[endpoint(clearCommunityDistributionList)] + fn clear_community_distribution_list(&self, entries_to_delete: u64) -> (u64, usize) { + let mut counter = 0; + for node in self.community_distribution_list().iter() { + if counter >= entries_to_delete { + break; + } + self.community_distribution_list().remove_node(&node); + counter += 1; + } + (counter, self.community_distribution_list().len()) + } + + // Returns the number of entries deleted and entries remaining in the storage. + #[endpoint(clearUserLockedAssetMap)] + fn clear_user_locked_asset_map(&self, entries_to_delete: u64) -> (u64, usize) { + let mut counter = 0; + for key in self.user_locked_asset_map().keys() { + if counter >= entries_to_delete { + break; + } + self.user_locked_asset_map().remove(&key); + counter += 1; + } + (counter, self.user_locked_asset_map().len()) + } + + #[view(getUnlockPeriod)] + #[storage_mapper("unlock_period")] + fn unlock_period(&self) -> SingleValueMapper>; + + #[view(getCommunityDistributionList)] + #[storage_mapper("community_distribution_list")] + fn community_distribution_list(&self) -> LinkedListMapper>; + + #[storage_mapper("user_locked_asset_map")] + fn user_locked_asset_map(&self) -> MapMapper, BigUint>; + + #[storage_mapper("locked_asset_factory_address")] + fn locked_asset_factory_address(&self) -> SingleValueMapper; + + #[view(getAssetTokenId)] + #[storage_mapper("asset_token_id")] + fn asset_token_id(&self) -> SingleValueMapper; + + #[storage_mapper("global_operation_ongoing")] + fn global_op_is_ongoing(&self) -> SingleValueMapper; +} diff --git a/legacy-contracts/locked-asset-distribution/wasm/Cargo.lock b/legacy-contracts/locked-asset-distribution/wasm/Cargo.lock new file mode 100644 index 000000000..47a5d2e4b --- /dev/null +++ b/legacy-contracts/locked-asset-distribution/wasm/Cargo.lock @@ -0,0 +1,228 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "common_structs" +version = "0.0.0" +dependencies = [ + "fixed-supply-token", + "math", + "mergeable", + "multiversx-sc", + "unwrappable", +] + +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + +[[package]] +name = "fixed-supply-token" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[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.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "locked-asset-distribution" +version = "0.0.0" +dependencies = [ + "common_structs", + "multiversx-sc", +] + +[[package]] +name = "locked-asset-distribution-wasm" +version = "0.0.0" +dependencies = [ + "locked-asset-distribution", + "multiversx-sc-wasm-adapter", +] + +[[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.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "nibble_vec" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" +dependencies = [ + "smallvec", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radix_trie" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" +dependencies = [ + "endian-type", + "nibble_vec", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + +[[package]] +name = "unwrappable" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] diff --git a/legacy-contracts/locked-asset-distribution/wasm/Cargo.toml b/legacy-contracts/locked-asset-distribution/wasm/Cargo.toml new file mode 100644 index 000000000..0a3916d83 --- /dev/null +++ b/legacy-contracts/locked-asset-distribution/wasm/Cargo.toml @@ -0,0 +1,34 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + +[package] +name = "locked-asset-distribution-wasm" +version = "0.0.0" +edition = "2021" +publish = false + +[lib] +crate-type = ["cdylib"] + +[profile.release] +codegen-units = 1 +opt-level = "z" +lto = true +debug = false +panic = "abort" +overflow-checks = false + +[profile.dev] +panic = "abort" + +[dependencies.locked-asset-distribution] +path = ".." + +[dependencies.multiversx-sc-wasm-adapter] +version = "=0.53.2" + +[workspace] +members = ["."] diff --git a/legacy-contracts/locked-asset-distribution/wasm/src/lib.rs b/legacy-contracts/locked-asset-distribution/wasm/src/lib.rs new file mode 100644 index 000000000..b0bc90188 --- /dev/null +++ b/legacy-contracts/locked-asset-distribution/wasm/src/lib.rs @@ -0,0 +1,32 @@ +// Code generated by the multiversx-sc build system. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +// Init: 1 +// Upgrade: 1 +// Endpoints: 6 +// Async Callback (empty): 1 +// Total number of exported functions: 9 + +#![no_std] + +multiversx_sc_wasm_adapter::allocator!(); +multiversx_sc_wasm_adapter::panic_handler!(); + +multiversx_sc_wasm_adapter::endpoints! { + locked_asset_distribution + ( + init => init + upgrade => upgrade + clearSingleValueMappers => clear_single_value_mappers + clearCommunityDistributionList => clear_community_distribution_list + clearUserLockedAssetMap => clear_user_locked_asset_map + getUnlockPeriod => unlock_period + getCommunityDistributionList => community_distribution_list + getAssetTokenId => asset_token_id + ) +} + +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/legacy-contracts/metabonding-staking-legacy/Cargo.toml b/legacy-contracts/metabonding-staking-legacy/Cargo.toml new file mode 100644 index 000000000..18fb97a80 --- /dev/null +++ b/legacy-contracts/metabonding-staking-legacy/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "metabonding-staking-legacy" +version = "0.0.0" +authors = ["you"] +edition = "2021" +publish = false + +[lib] +path = "src/lib.rs" + +[dependencies.multiversx-sc] +version = "0.53.2" + +[dev-dependencies] +num-bigint = "0.4" + +[dev-dependencies.multiversx-sc-scenario] +version = "0.53.2" diff --git a/legacy-contracts/metabonding-staking-legacy/meta/Cargo.toml b/legacy-contracts/metabonding-staking-legacy/meta/Cargo.toml new file mode 100644 index 000000000..38850a856 --- /dev/null +++ b/legacy-contracts/metabonding-staking-legacy/meta/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "metabonding-staking-legacy-meta" +version = "0.0.0" +edition = "2021" +publish = false + +[dependencies.metabonding-staking-legacy] +path = ".." + +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" +default-features = false diff --git a/legacy-contracts/metabonding-staking-legacy/meta/src/main.rs b/legacy-contracts/metabonding-staking-legacy/meta/src/main.rs new file mode 100644 index 000000000..74e71b129 --- /dev/null +++ b/legacy-contracts/metabonding-staking-legacy/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta_lib::cli_main::(); +} diff --git a/energy-integration/energy-update/elrond.json b/legacy-contracts/metabonding-staking-legacy/multiversx.json similarity index 100% rename from energy-integration/energy-update/elrond.json rename to legacy-contracts/metabonding-staking-legacy/multiversx.json diff --git a/legacy-contracts/metabonding-staking-legacy/src/lib.rs b/legacy-contracts/metabonding-staking-legacy/src/lib.rs new file mode 100644 index 000000000..1d78ee973 --- /dev/null +++ b/legacy-contracts/metabonding-staking-legacy/src/lib.rs @@ -0,0 +1,96 @@ +#![no_std] + +use multiversx_sc::derive_imports::*; +use multiversx_sc::imports::*; + +pub type SnapshotEntry = MultiValue2, BigUint>; + +#[derive(TypeAbi, TopEncode, TopDecode, NestedEncode, Debug, PartialEq)] +pub struct UserEntry { + pub token_nonce: u64, + pub stake_amount: BigUint, + pub unstake_amount: BigUint, + pub unbond_epoch: u64, +} + +static ERROR_LEGACY_CONTRACT: &[u8] = b"This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."; + +#[multiversx_sc::contract] +pub trait MetabondingStakingLegacy { + #[init] + fn init(&self) {} + + #[upgrade] + fn upgrade(&self) {} + + #[payable("*")] + #[endpoint(stakeLockedAsset)] + fn stake_locked_asset(&self) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint] + fn unstake(&self, _amount: BigUint) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[endpoint] + fn unbond(&self) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint(pause)] + fn pause_endpoint(&self) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint(unpause)] + fn unpause_endpoint(&self) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getStakedAmountForUser)] + fn get_staked_amount_for_user(&self, _user_address: ManagedAddress) -> BigUint { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getUserEntry)] + fn get_user_entry(&self, _user_address: ManagedAddress) -> OptionalValue> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getSnapshot)] + fn get_snapshot(&self) -> MultiValueEncoded> { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + // storage + + #[view(getLockedAssetTokenId)] + #[storage_mapper("lockedAssetTokenId")] + fn locked_asset_token_id(&self) -> SingleValueMapper; + + #[view(getLockedAssetFactoryAddress)] + #[storage_mapper("lockedAssetFactoryAddress")] + fn locked_asset_factory_address(&self) -> SingleValueMapper; + + #[view(getTotalLockedAssetSupply)] + #[storage_mapper("totalLockedAssetSupply")] + fn total_locked_asset_supply(&self) -> SingleValueMapper; + + #[storage_mapper("entryForUser")] + fn entry_for_user( + &self, + user_address: &ManagedAddress, + ) -> SingleValueMapper>; + + #[view(getUserList)] + #[storage_mapper("userList")] + fn user_list(&self) -> UnorderedSetMapper; + + #[view(isPaused)] + #[storage_get("pause_module:paused")] + fn is_paused(&self) -> bool; +} diff --git a/legacy-contracts/metabonding-staking-legacy/wasm/Cargo.lock b/legacy-contracts/metabonding-staking-legacy/wasm/Cargo.lock new file mode 100644 index 000000000..99e3afe7b --- /dev/null +++ b/legacy-contracts/metabonding-staking-legacy/wasm/Cargo.lock @@ -0,0 +1,188 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + +[[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.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "metabonding-staking-legacy" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "metabonding-staking-legacy-wasm" +version = "0.0.0" +dependencies = [ + "metabonding-staking-legacy", + "multiversx-sc-wasm-adapter", +] + +[[package]] +name = "multiversx-sc" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "nibble_vec" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" +dependencies = [ + "smallvec", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radix_trie" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" +dependencies = [ + "endian-type", + "nibble_vec", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" diff --git a/legacy-contracts/metabonding-staking-legacy/wasm/Cargo.toml b/legacy-contracts/metabonding-staking-legacy/wasm/Cargo.toml new file mode 100644 index 000000000..9563f9772 --- /dev/null +++ b/legacy-contracts/metabonding-staking-legacy/wasm/Cargo.toml @@ -0,0 +1,34 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + +[package] +name = "metabonding-staking-legacy-wasm" +version = "0.0.0" +edition = "2021" +publish = false + +[lib] +crate-type = ["cdylib"] + +[profile.release] +codegen-units = 1 +opt-level = "z" +lto = true +debug = false +panic = "abort" +overflow-checks = false + +[profile.dev] +panic = "abort" + +[dependencies.metabonding-staking-legacy] +path = ".." + +[dependencies.multiversx-sc-wasm-adapter] +version = "0.53.2" + +[workspace] +members = ["."] diff --git a/farm-staking/metabonding-staking/wasm/src/lib.rs b/legacy-contracts/metabonding-staking-legacy/wasm/src/lib.rs similarity index 79% rename from farm-staking/metabonding-staking/wasm/src/lib.rs rename to legacy-contracts/metabonding-staking-legacy/wasm/src/lib.rs index b8e948d22..e175e4eec 100644 --- a/farm-staking/metabonding-staking/wasm/src/lib.rs +++ b/legacy-contracts/metabonding-staking-legacy/wasm/src/lib.rs @@ -5,25 +5,26 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 11 +// Upgrade: 1 +// Endpoints: 13 // Async Callback (empty): 1 -// Total number of exported functions: 13 +// Total number of exported functions: 16 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); multiversx_sc_wasm_adapter::endpoints! { - metabonding_staking + metabonding_staking_legacy ( init => init upgrade => upgrade stakeLockedAsset => stake_locked_asset unstake => unstake unbond => unbond + pause => pause_endpoint + unpause => unpause_endpoint getStakedAmountForUser => get_staked_amount_for_user getUserEntry => get_user_entry getSnapshot => get_snapshot @@ -31,6 +32,7 @@ multiversx_sc_wasm_adapter::endpoints! { getLockedAssetFactoryAddress => locked_asset_factory_address getTotalLockedAssetSupply => total_locked_asset_supply getUserList => user_list + isPaused => is_paused ) } diff --git a/legacy-contracts/price-discovery-v1/Cargo.toml b/legacy-contracts/price-discovery-v1/Cargo.toml new file mode 100644 index 000000000..963d663e3 --- /dev/null +++ b/legacy-contracts/price-discovery-v1/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "price-discovery-v1" +version = "0.0.0" +authors = ["you"] +edition = "2021" +publish = false + +[lib] +path = "src/lib.rs" + +[dependencies.multiversx-sc] +version = "0.53.2" + +[dev-dependencies] +num-bigint = "0.4" + +[dev-dependencies.multiversx-sc-scenario] +version = "0.53.2" diff --git a/legacy-contracts/price-discovery-v1/meta/Cargo.toml b/legacy-contracts/price-discovery-v1/meta/Cargo.toml new file mode 100644 index 000000000..d9f0bf53a --- /dev/null +++ b/legacy-contracts/price-discovery-v1/meta/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "price-discovery-v1-meta" +version = "0.0.0" +edition = "2021" +publish = false + +[dependencies.price-discovery-v1] +path = ".." + +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" +default-features = false diff --git a/legacy-contracts/price-discovery-v1/meta/src/main.rs b/legacy-contracts/price-discovery-v1/meta/src/main.rs new file mode 100644 index 000000000..5f289fdfc --- /dev/null +++ b/legacy-contracts/price-discovery-v1/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta_lib::cli_main::(); +} diff --git a/farm-staking/metabonding-staking/elrond.json b/legacy-contracts/price-discovery-v1/multiversx.json similarity index 100% rename from farm-staking/metabonding-staking/elrond.json rename to legacy-contracts/price-discovery-v1/multiversx.json diff --git a/legacy-contracts/price-discovery-v1/src/lib.rs b/legacy-contracts/price-discovery-v1/src/lib.rs new file mode 100644 index 000000000..d0378ba9b --- /dev/null +++ b/legacy-contracts/price-discovery-v1/src/lib.rs @@ -0,0 +1,152 @@ +#![no_std] + +use multiversx_sc::derive_imports::*; +use multiversx_sc::imports::*; + +#[derive(TypeAbi, TopEncode, TopDecode, NestedEncode, PartialEq)] +pub enum Phase { + Idle, + NoPenalty, + LinearIncreasingPenalty { penalty_percentage: BigUint }, + OnlyWithdrawFixedPenalty { penalty_percentage: BigUint }, + Redeem, +} + +static ERROR_LEGACY_CONTRACT: &[u8] = b"This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."; + +#[multiversx_sc::contract] +pub trait PriceDiscoveryV1 { + #[init] + fn init(&self) {} + + #[payable("*")] + #[endpoint] + fn deposit(&self) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[payable("*")] + #[endpoint] + fn withdraw(&self) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[payable("*")] + #[endpoint] + fn redeem(&self) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getCurrentPrice)] + fn calculate_price(&self) -> BigUint { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getCurrentPhase)] + fn get_current_phase(&self) -> Phase { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[payable("EGLD")] + #[endpoint(issueRedeemToken)] + fn issue_redeem_token( + &self, + _token_name: ManagedBuffer, + _token_ticker: ManagedBuffer, + _nr_decimals: usize, + ) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint(createInitialRedeemTokens)] + fn create_initial_redeem_tokens(&self) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint(setLockingScAddress)] + fn set_locking_sc_address(&self, _new_address: ManagedAddress) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint(setUnlockEpoch)] + fn set_unlock_epoch(&self, _new_epoch: u64) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getLaunchedTokenId)] + #[storage_mapper("launchedTokenId")] + fn launched_token_id(&self) -> SingleValueMapper; + + #[view(getAcceptedTokenId)] + #[storage_mapper("acceptedTokenId")] + fn accepted_token_id(&self) -> SingleValueMapper; + + #[view(getLaunchedTokenBalance)] + #[storage_mapper("launchedTokenBalance")] + fn launched_token_balance(&self) -> SingleValueMapper; + + #[view(getAcceptedTokenBalance)] + #[storage_mapper("acceptedTokenBalance")] + fn accepted_token_balance(&self) -> SingleValueMapper; + + #[view(getStartBlock)] + #[storage_mapper("startBlock")] + fn start_block(&self) -> SingleValueMapper; + + #[view(getEndBlock)] + #[storage_mapper("endBlock")] + fn end_block(&self) -> SingleValueMapper; + + #[view(getRedeemTokenId)] + #[storage_mapper("redeemTokenId")] + fn redeem_token_id(&self) -> SingleValueMapper; + + #[view(getRedeemTokenTotalCirculatingSupply)] + #[storage_mapper("totalCirculatingSupply")] + fn redeem_token_total_circulating_supply(&self, token_nonce: u64) + -> SingleValueMapper; + + #[view(getMinLaunchedTokenPrice)] + #[storage_mapper("minLaunchedTokenPrice")] + fn min_launched_token_price(&self) -> SingleValueMapper; + + #[view(getPricePrecision)] + #[storage_mapper("pricePrecision")] + fn price_precision(&self) -> SingleValueMapper; + + #[view(getNoLimitPhaseDurationBlocks)] + #[storage_mapper("noLimitPhaseDurationBlocks")] + fn no_limit_phase_duration_blocks(&self) -> SingleValueMapper; + + #[view(getLinearPenaltyPhaseDurationBlocks)] + #[storage_mapper("linearPenaltyPhaseDurationBlocks")] + fn linear_penalty_phase_duration_blocks(&self) -> SingleValueMapper; + + #[view(getFixedPenaltyPhaseDurationBlocks)] + #[storage_mapper("fixedPenaltyPhaseDurationBlocks")] + fn fixed_penalty_phase_duration_blocks(&self) -> SingleValueMapper; + + #[view(getPenaltyMinPercentage)] + #[storage_mapper("penaltyMinPercentage")] + fn penalty_min_percentage(&self) -> SingleValueMapper; + + #[view(getPenaltyMaxPercentage)] + #[storage_mapper("penaltyMaxPercentage")] + fn penalty_max_percentage(&self) -> SingleValueMapper; + + #[view(getFixedPenaltyPercentage)] + #[storage_mapper("fixedPenaltyPercentage")] + fn fixed_penalty_percentage(&self) -> SingleValueMapper; + + #[view(getLockingScAddress)] + #[storage_mapper("lockingScAddress")] + fn locking_sc_address(&self) -> SingleValueMapper; + + #[view(getUnlockEpoch)] + #[storage_mapper("unlockEpoch")] + fn unlock_epoch(&self) -> SingleValueMapper; +} diff --git a/legacy-contracts/price-discovery-v1/wasm/Cargo.lock b/legacy-contracts/price-discovery-v1/wasm/Cargo.lock new file mode 100644 index 000000000..03532cfc3 --- /dev/null +++ b/legacy-contracts/price-discovery-v1/wasm/Cargo.lock @@ -0,0 +1,188 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + +[[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.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "multiversx-sc" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "nibble_vec" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" +dependencies = [ + "smallvec", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "price-discovery-v1" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "price-discovery-v1-wasm" +version = "0.0.0" +dependencies = [ + "multiversx-sc-wasm-adapter", + "price-discovery-v1", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radix_trie" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" +dependencies = [ + "endian-type", + "nibble_vec", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" diff --git a/locked-asset/simple-lock-whitelist/wasm/Cargo.toml b/legacy-contracts/price-discovery-v1/wasm/Cargo.toml similarity index 80% rename from locked-asset/simple-lock-whitelist/wasm/Cargo.toml rename to legacy-contracts/price-discovery-v1/wasm/Cargo.toml index 068857df3..a70638e54 100644 --- a/locked-asset/simple-lock-whitelist/wasm/Cargo.toml +++ b/legacy-contracts/price-discovery-v1/wasm/Cargo.toml @@ -5,7 +5,7 @@ # ########################################## [package] -name = "simple-lock-whitelist-wasm" +name = "price-discovery-v1-wasm" version = "0.0.0" edition = "2021" publish = false @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false -[dependencies.simple-lock-whitelist] +[profile.dev] +panic = "abort" + +[dependencies.price-discovery-v1] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "0.53.2" [workspace] members = ["."] diff --git a/legacy-contracts/price-discovery-v1/wasm/src/lib.rs b/legacy-contracts/price-discovery-v1/wasm/src/lib.rs new file mode 100644 index 000000000..b056de3a2 --- /dev/null +++ b/legacy-contracts/price-discovery-v1/wasm/src/lib.rs @@ -0,0 +1,51 @@ +// Code generated by the multiversx-sc build system. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +// Init: 1 +// Endpoints: 27 +// Async Callback (empty): 1 +// Total number of exported functions: 29 + +#![no_std] + +multiversx_sc_wasm_adapter::allocator!(); +multiversx_sc_wasm_adapter::panic_handler!(); + +multiversx_sc_wasm_adapter::endpoints! { + price_discovery_v1 + ( + init => init + deposit => deposit + withdraw => withdraw + redeem => redeem + getCurrentPrice => calculate_price + getCurrentPhase => get_current_phase + issueRedeemToken => issue_redeem_token + createInitialRedeemTokens => create_initial_redeem_tokens + setLockingScAddress => set_locking_sc_address + setUnlockEpoch => set_unlock_epoch + getLaunchedTokenId => launched_token_id + getAcceptedTokenId => accepted_token_id + getLaunchedTokenBalance => launched_token_balance + getAcceptedTokenBalance => accepted_token_balance + getStartBlock => start_block + getEndBlock => end_block + getRedeemTokenId => redeem_token_id + getRedeemTokenTotalCirculatingSupply => redeem_token_total_circulating_supply + getMinLaunchedTokenPrice => min_launched_token_price + getPricePrecision => price_precision + 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 + getLockingScAddress => locking_sc_address + getUnlockEpoch => unlock_epoch + ) +} + +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/legacy-contracts/price-discovery-v2/Cargo.toml b/legacy-contracts/price-discovery-v2/Cargo.toml new file mode 100644 index 000000000..d0c9faf2b --- /dev/null +++ b/legacy-contracts/price-discovery-v2/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "price-discovery-v2" +version = "0.0.0" +authors = ["you"] +edition = "2021" +publish = false + +[lib] +path = "src/lib.rs" + +[dependencies.multiversx-sc] +version = "0.53.2" + +[dev-dependencies] +num-bigint = "0.4" + +[dev-dependencies.multiversx-sc-scenario] +version = "0.53.2" diff --git a/legacy-contracts/price-discovery-v2/meta/Cargo.toml b/legacy-contracts/price-discovery-v2/meta/Cargo.toml new file mode 100644 index 000000000..3e35bdd3e --- /dev/null +++ b/legacy-contracts/price-discovery-v2/meta/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "price-discovery-v2-meta" +version = "0.0.0" +edition = "2021" +publish = false + +[dependencies.price-discovery-v2] +path = ".." + +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" +default-features = false diff --git a/legacy-contracts/price-discovery-v2/meta/src/main.rs b/legacy-contracts/price-discovery-v2/meta/src/main.rs new file mode 100644 index 000000000..b7083d3ef --- /dev/null +++ b/legacy-contracts/price-discovery-v2/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta_lib::cli_main::(); +} diff --git a/locked-asset/distribution/elrond.json b/legacy-contracts/price-discovery-v2/multiversx.json similarity index 100% rename from locked-asset/distribution/elrond.json rename to legacy-contracts/price-discovery-v2/multiversx.json diff --git a/legacy-contracts/price-discovery-v2/src/lib.rs b/legacy-contracts/price-discovery-v2/src/lib.rs new file mode 100644 index 000000000..fdd441300 --- /dev/null +++ b/legacy-contracts/price-discovery-v2/src/lib.rs @@ -0,0 +1,152 @@ +#![no_std] + +use multiversx_sc::derive_imports::*; +use multiversx_sc::imports::*; + +#[derive(TypeAbi, TopEncode, TopDecode, NestedEncode, PartialEq)] +pub enum Phase { + Idle, + NoPenalty, + LinearIncreasingPenalty { penalty_percentage: BigUint }, + OnlyWithdrawFixedPenalty { penalty_percentage: BigUint }, + Redeem, +} + +static ERROR_LEGACY_CONTRACT: &[u8] = b"This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."; + +#[multiversx_sc::contract] +pub trait PriceDiscoveryV2 { + #[init] + fn init(&self) {} + + #[payable("*")] + #[endpoint] + fn deposit(&self) -> EsdtTokenPayment { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[payable("*")] + #[endpoint] + fn withdraw(&self) -> EgldOrEsdtTokenPayment { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[payable("*")] + #[endpoint] + fn redeem(&self) -> EgldOrEsdtTokenPayment { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getCurrentPrice)] + fn calculate_price(&self) -> BigUint { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getCurrentPhase)] + fn get_current_phase(&self) -> Phase { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[payable("EGLD")] + #[endpoint(issueRedeemToken)] + fn issue_redeem_token( + &self, + _token_name: ManagedBuffer, + _token_ticker: ManagedBuffer, + _nr_decimals: usize, + ) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint(createInitialRedeemTokens)] + fn create_initial_redeem_tokens(&self) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint(setLockingScAddress)] + fn set_locking_sc_address(&self, _new_address: ManagedAddress) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[only_owner] + #[endpoint(setUnlockEpoch)] + fn set_unlock_epoch(&self, _new_epoch: u64) { + sc_panic!(ERROR_LEGACY_CONTRACT); + } + + #[view(getLaunchedTokenId)] + #[storage_mapper("launchedTokenId")] + fn launched_token_id(&self) -> SingleValueMapper; + + #[view(getAcceptedTokenId)] + #[storage_mapper("acceptedTokenId")] + fn accepted_token_id(&self) -> SingleValueMapper; + + #[view(getLaunchedTokenBalance)] + #[storage_mapper("launchedTokenBalance")] + fn launched_token_balance(&self) -> SingleValueMapper; + + #[view(getAcceptedTokenBalance)] + #[storage_mapper("acceptedTokenBalance")] + fn accepted_token_balance(&self) -> SingleValueMapper; + + #[view(getStartBlock)] + #[storage_mapper("startBlock")] + fn start_block(&self) -> SingleValueMapper; + + #[view(getEndBlock)] + #[storage_mapper("endBlock")] + fn end_block(&self) -> SingleValueMapper; + + #[view(getMinLaunchedTokenPrice)] + #[storage_mapper("minLaunchedTokenPrice")] + fn min_launched_token_price(&self) -> SingleValueMapper; + + #[view(getPricePrecision)] + #[storage_mapper("pricePrecision")] + fn price_precision(&self) -> SingleValueMapper; + + #[view(getNoLimitPhaseDurationBlocks)] + #[storage_mapper("noLimitPhaseDurationBlocks")] + fn no_limit_phase_duration_blocks(&self) -> SingleValueMapper; + + #[view(getLinearPenaltyPhaseDurationBlocks)] + #[storage_mapper("linearPenaltyPhaseDurationBlocks")] + fn linear_penalty_phase_duration_blocks(&self) -> SingleValueMapper; + + #[view(getFixedPenaltyPhaseDurationBlocks)] + #[storage_mapper("fixedPenaltyPhaseDurationBlocks")] + fn fixed_penalty_phase_duration_blocks(&self) -> SingleValueMapper; + + #[view(getPenaltyMinPercentage)] + #[storage_mapper("penaltyMinPercentage")] + fn penalty_min_percentage(&self) -> SingleValueMapper; + + #[view(getPenaltyMaxPercentage)] + #[storage_mapper("penaltyMaxPercentage")] + fn penalty_max_percentage(&self) -> SingleValueMapper; + + #[view(getFixedPenaltyPercentage)] + #[storage_mapper("fixedPenaltyPercentage")] + fn fixed_penalty_percentage(&self) -> SingleValueMapper; + + #[view(getRedeemTokenId)] + #[storage_mapper("redeemTokenId")] + fn redeem_token(&self) -> NonFungibleTokenMapper; + + #[view(getRedeemTokenTotalCirculatingSupply)] + #[storage_mapper("totalCirculatingSupply")] + fn redeem_token_total_circulating_supply(&self, token_nonce: u64) + -> SingleValueMapper; + + #[view(getLockingScAddress)] + #[storage_mapper("lockingScAddress")] + fn locking_sc_address(&self) -> SingleValueMapper; + + #[view(getUnlockEpoch)] + #[storage_mapper("unlockEpoch")] + fn unlock_epoch(&self) -> SingleValueMapper; +} diff --git a/legacy-contracts/price-discovery-v2/wasm/Cargo.lock b/legacy-contracts/price-discovery-v2/wasm/Cargo.lock new file mode 100644 index 000000000..ab4be20ac --- /dev/null +++ b/legacy-contracts/price-discovery-v2/wasm/Cargo.lock @@ -0,0 +1,188 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + +[[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.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "multiversx-sc" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "nibble_vec" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" +dependencies = [ + "smallvec", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "price-discovery-v2" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "price-discovery-v2-wasm" +version = "0.0.0" +dependencies = [ + "multiversx-sc-wasm-adapter", + "price-discovery-v2", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radix_trie" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" +dependencies = [ + "endian-type", + "nibble_vec", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" diff --git a/farm-staking/metabonding-staking/wasm/Cargo.toml b/legacy-contracts/price-discovery-v2/wasm/Cargo.toml similarity index 80% rename from farm-staking/metabonding-staking/wasm/Cargo.toml rename to legacy-contracts/price-discovery-v2/wasm/Cargo.toml index fe2a7c6c2..c1d10b2a0 100644 --- a/farm-staking/metabonding-staking/wasm/Cargo.toml +++ b/legacy-contracts/price-discovery-v2/wasm/Cargo.toml @@ -5,7 +5,7 @@ # ########################################## [package] -name = "metabonding-staking-wasm" +name = "price-discovery-v2-wasm" version = "0.0.0" edition = "2021" publish = false @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false -[dependencies.metabonding-staking] +[profile.dev] +panic = "abort" + +[dependencies.price-discovery-v2] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "0.53.2" [workspace] members = ["."] diff --git a/legacy-contracts/price-discovery-v2/wasm/src/lib.rs b/legacy-contracts/price-discovery-v2/wasm/src/lib.rs new file mode 100644 index 000000000..e4ac1662c --- /dev/null +++ b/legacy-contracts/price-discovery-v2/wasm/src/lib.rs @@ -0,0 +1,51 @@ +// Code generated by the multiversx-sc build system. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +// Init: 1 +// Endpoints: 27 +// Async Callback (empty): 1 +// Total number of exported functions: 29 + +#![no_std] + +multiversx_sc_wasm_adapter::allocator!(); +multiversx_sc_wasm_adapter::panic_handler!(); + +multiversx_sc_wasm_adapter::endpoints! { + price_discovery_v2 + ( + init => init + deposit => deposit + withdraw => withdraw + redeem => redeem + getCurrentPrice => calculate_price + getCurrentPhase => get_current_phase + issueRedeemToken => issue_redeem_token + createInitialRedeemTokens => create_initial_redeem_tokens + setLockingScAddress => set_locking_sc_address + setUnlockEpoch => set_unlock_epoch + getLaunchedTokenId => launched_token_id + getAcceptedTokenId => accepted_token_id + getLaunchedTokenBalance => launched_token_balance + getAcceptedTokenBalance => accepted_token_balance + getStartBlock => start_block + getEndBlock => end_block + getMinLaunchedTokenPrice => min_launched_token_price + getPricePrecision => price_precision + 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 + getRedeemTokenId => redeem_token + getRedeemTokenTotalCirculatingSupply => redeem_token_total_circulating_supply + getLockingScAddress => locking_sc_address + getUnlockEpoch => unlock_epoch + ) +} + +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/farm-staking/metabonding-staking/.gitignore b/legacy-contracts/proxy-dex-legacy/.gitignore similarity index 92% rename from farm-staking/metabonding-staking/.gitignore rename to legacy-contracts/proxy-dex-legacy/.gitignore index 920d759a2..eaf5915bd 100644 --- a/farm-staking/metabonding-staking/.gitignore +++ b/legacy-contracts/proxy-dex-legacy/.gitignore @@ -4,4 +4,4 @@ */target/ # The erdpy output -output* +output diff --git a/legacy-contracts/proxy-dex-legacy/Cargo.toml b/legacy-contracts/proxy-dex-legacy/Cargo.toml new file mode 100644 index 000000000..ec860c2b1 --- /dev/null +++ b/legacy-contracts/proxy-dex-legacy/Cargo.toml @@ -0,0 +1,36 @@ +[package] +name = "proxy-dex-legacy" +version = "0.0.0" +edition = "2018" +publish = false + +[lib] +path = "src/lib.rs" + +[dependencies.multiversx-sc] +version = "=0.53.2" +features = ["esdt-token-payment-legacy-decode"] + +[dependencies.common_structs] +path = "../../common/common_structs" + +[dependencies.token_merge_helper] +path = "../../common/modules/token_merge_helper" + +[dependencies.factory-legacy] +path = "../factory-legacy" + +[dependencies.energy-factory] +path = "../../locked-asset/energy-factory" + +[dependencies.energy-query] +path = "../../energy-integration/common-modules/energy-query" + +[dependencies.farm-v13-locked-rewards] +path = "../farm-v13-locked-rewards" + +[dependencies.pair] +path = "../../dex/pair" + +[dev-dependencies.multiversx-sc-scenario] +version = "=0.53.2" diff --git a/legacy-contracts/proxy-dex-legacy/README.md b/legacy-contracts/proxy-dex-legacy/README.md new file mode 100644 index 000000000..cfa338037 --- /dev/null +++ b/legacy-contracts/proxy-dex-legacy/README.md @@ -0,0 +1,24 @@ +# DEX Proxy Smart Contract + +This document presents how one can deploy and configure a DEX Proxy Contract. +The bigger picture about what a DEX Proxy Contract can do can be found in the Repository's Root Readme. + +## Deployment + +The DEX Proxy contract can be deployed using `erdpy` and using the interraction 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. + +- locked_asset_token_id. The TokenId of the locked asset represents. In case of Maiar Exchange it will be Locked MEX. + +## Configuration workflow + +1. In order to complete the setup of the dex proxy contracts, Wrapped LP Token and Wrapped Farm token must be issued via `issueSftProxyPair` and `issueSftProxyFarm`. After this, setLocalRoles has to be called once for each of the two tokens, using for address the Proxy Address itself. + +2. In order to add a pair to intermediate, meaning a pair that is eligible to function with MEX, the admin should use `addPairToIntermediate` and `removeIntermediatedPair`. + +3. In order to add a farm to intermediate, meaning a farm that is eligible to function with MEX or with Wrapped LP Tokens, the admin should use `addFarmToIntermediate` and `removeIntermediatedFarm`. + +4. In order for the Setup to be complete, LocalMint + LocalBurn roles for MEX and NftBurn role for Locked MEX should be granted to the Proxy Contract. diff --git a/legacy-contracts/proxy-dex-legacy/meta/Cargo.toml b/legacy-contracts/proxy-dex-legacy/meta/Cargo.toml new file mode 100644 index 000000000..d092a265d --- /dev/null +++ b/legacy-contracts/proxy-dex-legacy/meta/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "proxy-dex-legacy-meta" +version = "0.0.0" +authors = ["you"] +edition = "2018" +publish = false + +[dependencies.proxy-dex-legacy] +path = ".." + +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" +default-features = false diff --git a/legacy-contracts/proxy-dex-legacy/meta/src/main.rs b/legacy-contracts/proxy-dex-legacy/meta/src/main.rs new file mode 100644 index 000000000..75bd5a52b --- /dev/null +++ b/legacy-contracts/proxy-dex-legacy/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta_lib::cli_main::(); +} \ No newline at end of file diff --git a/legacy-contracts/proxy-dex-legacy/multiversx.json b/legacy-contracts/proxy-dex-legacy/multiversx.json new file mode 100644 index 000000000..c2cab7433 --- /dev/null +++ b/legacy-contracts/proxy-dex-legacy/multiversx.json @@ -0,0 +1,4 @@ +{ + "language": "rust" +} + diff --git a/legacy-contracts/proxy-dex-legacy/src/energy_update.rs b/legacy-contracts/proxy-dex-legacy/src/energy_update.rs new file mode 100644 index 000000000..b4e30f9bf --- /dev/null +++ b/legacy-contracts/proxy-dex-legacy/src/energy_update.rs @@ -0,0 +1,73 @@ +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +use common_structs::LockedAssetTokenAttributesEx; +use energy_factory::{energy::Energy, locked_token_transfer::ProxyTrait as _}; +use factory_legacy::attr_ex_helper; + +use crate::proxy_common; + +static LEGACY_LOCKED_TOKEN_ID_STORAGE_KEY: &[u8] = b"legacyLockedTokenId"; +static EXTENDED_ATTRIBUTES_ACTIVATION_NONCE_KEY: &[u8] = b"extended_attributes_activation_nonce"; + +#[multiversx_sc::module] +pub trait EnergyUpdateModule: + proxy_common::ProxyCommonModule + attr_ex_helper::AttrExHelper + energy_query::EnergyQueryModule +{ + fn deduct_energy_from_user( + &self, + user: &ManagedAddress, + token_id: &TokenIdentifier, + token_nonce: u64, + token_amount: &BigUint, + ) { + let energy_factory_addr = self.energy_factory_address().get(); + let legacy_locked_token_id = self.get_legacy_locked_token_id(&energy_factory_addr); + if token_id != &legacy_locked_token_id { + return; + } + + let mut energy = self.get_energy_entry(user); + let current_epoch = self.blockchain().get_block_epoch(); + let extended_attributes_activation_nonce = self.get_extended_attributes_activation_nonce(); + let attributes: LockedAssetTokenAttributesEx = + self.get_attributes_ex(token_id, token_nonce, extended_attributes_activation_nonce); + let amounts_per_epoch = attributes.get_unlock_amounts_per_epoch(token_amount); + for epoch_amount_pair in &amounts_per_epoch.pairs { + energy.update_after_unlock_any( + &epoch_amount_pair.amount, + epoch_amount_pair.epoch, + current_epoch, + ); + } + + self.set_energy_in_factory(user.clone(), energy, energy_factory_addr); + } + + fn set_energy_in_factory( + &self, + user: ManagedAddress, + energy: Energy, + energy_factory_addr: ManagedAddress, + ) { + let _: () = self + .energy_factory_proxy(energy_factory_addr) + .set_user_energy_after_locked_token_transfer(user, energy) + .execute_on_dest_context(); + } + + fn get_legacy_locked_token_id(&self, energy_factory_addr: &ManagedAddress) -> TokenIdentifier { + self.storage_raw().read_from_address( + energy_factory_addr, + ManagedBuffer::new_from_bytes(LEGACY_LOCKED_TOKEN_ID_STORAGE_KEY), + ) + } + + fn get_extended_attributes_activation_nonce(&self) -> u64 { + let sc_address = self.locked_asset_factory_address().get(); + self.storage_raw().read_from_address( + &sc_address, + ManagedBuffer::new_from_bytes(EXTENDED_ATTRIBUTES_ACTIVATION_NONCE_KEY), + ) + } +} diff --git a/legacy-contracts/proxy-dex-legacy/src/events.rs b/legacy-contracts/proxy-dex-legacy/src/events.rs new file mode 100644 index 000000000..3fefd8fb1 --- /dev/null +++ b/legacy-contracts/proxy-dex-legacy/src/events.rs @@ -0,0 +1,149 @@ +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +use crate::proxy_common::{WrappedFarmTokenAttributes, WrappedLpTokenAttributes}; + +#[derive(TypeAbi, TopEncode)] +pub struct RemoveLiquidityProxyEvent { + caller: ManagedAddress, + pair_address: ManagedAddress, + wrapped_lp_token_id: TokenIdentifier, + wrapped_lp_token_nonce: u64, + wrapped_lp_token_amount: BigUint, + wrapped_lp_attributes: WrappedLpTokenAttributes, + first_token_id: TokenIdentifier, + first_token_nonce: u64, + first_token_amount: BigUint, + second_token_id: TokenIdentifier, + second_token_nonce: u64, + second_token_amount: BigUint, + block: u64, + epoch: u64, + timestamp: u64, +} + +#[derive(TypeAbi, TopEncode)] +pub struct ExitFarmProxyEvent { + caller: ManagedAddress, + farm_address: ManagedAddress, + wrapped_farm_token_id: TokenIdentifier, + wrapped_farm_token_nonce: u64, + wrapped_farm_token_amount: BigUint, + wrapped_farm_attributes: WrappedFarmTokenAttributes, + farming_token_id: TokenIdentifier, + farming_token_nonce: u64, + farming_token_amount: BigUint, + reward_token_id: TokenIdentifier, + reward_token_nonce: u64, + reward_token_amount: BigUint, + block: u64, + epoch: u64, + timestamp: u64, +} + +#[multiversx_sc::module] +pub trait EventsModule { + fn emit_remove_liquidity_proxy_event( + self, + caller: &ManagedAddress, + pair_address: &ManagedAddress, + wrapped_lp_token_id: &TokenIdentifier, + wrapped_lp_token_nonce: u64, + wrapped_lp_token_amount: &BigUint, + wrapped_lp_attributes: &WrappedLpTokenAttributes, + first_token_id: &TokenIdentifier, + first_token_nonce: u64, + first_token_amount: &BigUint, + second_token_id: &TokenIdentifier, + second_token_nonce: u64, + second_token_amount: &BigUint, + ) { + let epoch = self.blockchain().get_block_epoch(); + self.remove_liquidity_proxy_event( + first_token_id, + second_token_id, + caller, + pair_address, + epoch, + &RemoveLiquidityProxyEvent { + caller: caller.clone(), + pair_address: pair_address.clone(), + first_token_id: first_token_id.clone(), + first_token_nonce, + first_token_amount: first_token_amount.clone(), + second_token_id: second_token_id.clone(), + second_token_nonce, + second_token_amount: second_token_amount.clone(), + wrapped_lp_token_id: wrapped_lp_token_id.clone(), + wrapped_lp_token_nonce, + wrapped_lp_token_amount: wrapped_lp_token_amount.clone(), + wrapped_lp_attributes: wrapped_lp_attributes.clone(), + block: self.blockchain().get_block_nonce(), + epoch, + timestamp: self.blockchain().get_block_timestamp(), + }, + ) + } + + fn emit_exit_farm_proxy_event( + self, + caller: &ManagedAddress, + farm_address: &ManagedAddress, + wrapped_farm_token_id: &TokenIdentifier, + wrapped_farm_token_nonce: u64, + wrapped_farm_token_amount: &BigUint, + wrapped_farm_attributes: &WrappedFarmTokenAttributes, + farming_token_id: &TokenIdentifier, + farming_token_nonce: u64, + farming_token_amount: &BigUint, + reward_token_id: &TokenIdentifier, + reward_token_nonce: u64, + reward_token_amount: &BigUint, + ) { + let epoch = self.blockchain().get_block_epoch(); + self.exit_farm_proxy_event( + farming_token_id, + caller, + farm_address, + epoch, + &ExitFarmProxyEvent { + caller: caller.clone(), + farm_address: farm_address.clone(), + farming_token_id: farming_token_id.clone(), + farming_token_nonce, + farming_token_amount: farming_token_amount.clone(), + wrapped_farm_token_id: wrapped_farm_token_id.clone(), + wrapped_farm_token_nonce, + wrapped_farm_token_amount: wrapped_farm_token_amount.clone(), + wrapped_farm_attributes: wrapped_farm_attributes.clone(), + reward_token_id: reward_token_id.clone(), + reward_token_nonce, + reward_token_amount: reward_token_amount.clone(), + block: self.blockchain().get_block_nonce(), + epoch, + timestamp: self.blockchain().get_block_timestamp(), + }, + ) + } + + #[event("remove_liquidity_proxy")] + fn remove_liquidity_proxy_event( + self, + #[indexed] first_token: &TokenIdentifier, + #[indexed] second_token: &TokenIdentifier, + #[indexed] caller: &ManagedAddress, + #[indexed] pair_address: &ManagedAddress, + #[indexed] epoch: u64, + remove_liquidity_proxy_event: &RemoveLiquidityProxyEvent, + ); + + #[event("exit_farm_proxy")] + fn exit_farm_proxy_event( + self, + #[indexed] farm_token: &TokenIdentifier, + #[indexed] caller: &ManagedAddress, + #[indexed] farm_address: &ManagedAddress, + #[indexed] epoch: u64, + exit_farm_proxy_event: &ExitFarmProxyEvent, + ); +} diff --git a/legacy-contracts/proxy-dex-legacy/src/lib.rs b/legacy-contracts/proxy-dex-legacy/src/lib.rs new file mode 100644 index 000000000..a93923c71 --- /dev/null +++ b/legacy-contracts/proxy-dex-legacy/src/lib.rs @@ -0,0 +1,32 @@ +#![no_std] + +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +mod energy_update; +mod events; +pub mod proxy_common; +pub mod proxy_farm; +mod proxy_pair; +pub mod transfer_role; + +use factory_legacy::attr_ex_helper; + +#[multiversx_sc::contract] +pub trait ProxyDexImpl: + proxy_common::ProxyCommonModule + + proxy_pair::ProxyPairModule + + proxy_farm::ProxyFarmModule + + token_merge_helper::TokenMergeHelperModule + + events::EventsModule + + energy_update::EnergyUpdateModule + + transfer_role::TransferRoleModule + + attr_ex_helper::AttrExHelper + + energy_query::EnergyQueryModule +{ + #[init] + fn init(&self) {} + + #[upgrade] + fn upgrade(&self) {} +} diff --git a/legacy-contracts/proxy-dex-legacy/src/proxy_common.rs b/legacy-contracts/proxy-dex-legacy/src/proxy_common.rs new file mode 100644 index 000000000..105f3cbc1 --- /dev/null +++ b/legacy-contracts/proxy-dex-legacy/src/proxy_common.rs @@ -0,0 +1,129 @@ +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +use common_structs::Nonce; + +#[derive(ManagedVecItem, TopEncode, TopDecode, NestedEncode, NestedDecode, TypeAbi, Clone)] +pub struct WrappedLpTokenAttributes { + pub lp_token_id: TokenIdentifier, + pub lp_token_total_amount: BigUint, + pub locked_assets_invested: BigUint, + pub locked_assets_nonce: Nonce, +} + +#[derive(ManagedVecItem, TopEncode, TopDecode, NestedEncode, NestedDecode, TypeAbi, Clone)] +pub struct WrappedFarmTokenAttributes { + pub farm_token_id: TokenIdentifier, + pub farm_token_nonce: Nonce, + pub farm_token_amount: BigUint, + pub farming_token_id: TokenIdentifier, + pub farming_token_nonce: Nonce, + pub farming_token_amount: BigUint, +} + +#[multiversx_sc::module] +pub trait ProxyCommonModule { + fn get_wrapped_lp_token_attributes( + &self, + token_id: &TokenIdentifier, + token_nonce: Nonce, + ) -> WrappedLpTokenAttributes { + let token_info = self.blockchain().get_esdt_token_data( + &self.blockchain().get_sc_address(), + token_id, + token_nonce, + ); + + token_info.decode_attributes() + } + + fn get_wrapped_farm_token_attributes( + &self, + token_id: &TokenIdentifier, + token_nonce: Nonce, + ) -> WrappedFarmTokenAttributes { + let token_info = self.blockchain().get_esdt_token_data( + &self.blockchain().get_sc_address(), + token_id, + token_nonce, + ); + + token_info.decode_attributes() + } + + fn burn_payment_tokens( + &self, + payments: ManagedVecRefIterator>, + ) { + for payment in payments { + self.send().esdt_local_burn( + &payment.token_identifier, + payment.token_nonce, + &payment.amount, + ); + } + } + + fn send_multiple_tokens_if_not_zero( + &self, + destination: &ManagedAddress, + payments: &ManagedVec>, + ) { + let mut non_zero_payments = ManagedVec::new(); + for payment in payments { + if payment.amount > 0u32 { + non_zero_payments.push(payment); + } + } + + if !non_zero_payments.is_empty() { + self.send().direct_multi(destination, &non_zero_payments) + } + } + + #[storage_mapper("current_tx_accepted_funds")] + fn current_tx_accepted_funds(&self) -> MapMapper<(TokenIdentifier, Nonce), BigUint>; + + #[view(getAssetTokenId)] + #[storage_mapper("asset_token_id")] + fn asset_token_id(&self) -> SingleValueMapper; + + #[view(getLockedAssetTokenId)] + #[storage_mapper("locked_asset_token_id")] + fn locked_asset_token_id(&self) -> SingleValueMapper; + + #[view(getWrappedLpTokenId)] + #[storage_mapper("wrapped_lp_token_id")] + fn wrapped_lp_token_id(&self) -> SingleValueMapper; + + #[view(getWrappedFarmTokenId)] + #[storage_mapper("wrapped_farm_token_id")] + fn wrapped_farm_token_id(&self) -> SingleValueMapper; + + #[storage_mapper("locked_asset_factory_address")] + fn locked_asset_factory_address(&self) -> SingleValueMapper; + + #[storage_mapper("intermediated_farms")] + fn intermediated_farms(&self) -> SetMapper; + + #[view(getIntermediatedFarms)] + fn get_intermediated_farms(&self) -> MultiValueEncoded { + let mut result = MultiValueEncoded::new(); + for pair in self.intermediated_farms().iter() { + result.push(pair); + } + result + } + + #[storage_mapper("intermediated_pairs")] + fn intermediated_pairs(&self) -> SetMapper; + + #[view(getIntermediatedPairs)] + fn get_intermediated_pairs(&self) -> MultiValueEncoded { + let mut result = MultiValueEncoded::new(); + for pair in self.intermediated_pairs().iter() { + result.push(pair); + } + result + } +} diff --git a/legacy-contracts/proxy-dex-legacy/src/proxy_farm.rs b/legacy-contracts/proxy-dex-legacy/src/proxy_farm.rs new file mode 100644 index 000000000..faa105228 --- /dev/null +++ b/legacy-contracts/proxy-dex-legacy/src/proxy_farm.rs @@ -0,0 +1,148 @@ +#![allow(clippy::too_many_arguments)] + +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +use common_structs::Nonce; +use common_structs::{RawResultWrapper, RawResultsType}; +use factory_legacy::attr_ex_helper; + +use crate::energy_update; +use crate::proxy_common::WrappedFarmTokenAttributes; + +use super::events; +use super::proxy_common; +use super::proxy_pair; + +use farm_v13_locked_rewards::ExitFarmResultType; + +#[derive(ManagedVecItem, Clone)] +pub struct WrappedFarmToken { + pub token_amount: EsdtTokenPayment, + pub attributes: WrappedFarmTokenAttributes, +} + +#[multiversx_sc::module] +pub trait ProxyFarmModule: + proxy_common::ProxyCommonModule + + proxy_pair::ProxyPairModule + + token_merge_helper::TokenMergeHelperModule + + events::EventsModule + + energy_update::EnergyUpdateModule + + attr_ex_helper::AttrExHelper + + energy_query::EnergyQueryModule +{ + #[only_owner] + #[endpoint(addFarmToIntermediate)] + fn add_farm_to_intermediate(&self, farm_address: ManagedAddress) { + self.intermediated_farms().insert(farm_address); + } + + #[only_owner] + #[endpoint(removeIntermediatedFarm)] + fn remove_intermediated_farm(&self, farm_address: ManagedAddress) { + self.require_is_intermediated_farm(&farm_address); + self.intermediated_farms().remove(&farm_address); + } + + #[payable("*")] + #[endpoint(exitFarmProxy)] + fn exit_farm_proxy(&self, farm_address: &ManagedAddress) { + self.require_is_intermediated_farm(farm_address); + self.require_wrapped_farm_token_id_not_empty(); + self.require_wrapped_lp_token_id_not_empty(); + + let (token_id, token_nonce, amount) = self.call_value().single_esdt().into_tuple(); + + require!(amount != 0, "Payment amount cannot be zero"); + require!( + token_id == self.wrapped_farm_token_id().get(), + "Should only be used with wrapped farm tokens" + ); + + let wrapped_farm_token_attrs = + self.get_wrapped_farm_token_attributes(&token_id, token_nonce); + let farm_token_id = wrapped_farm_token_attrs.farm_token_id.clone(); + let farm_token_nonce = wrapped_farm_token_attrs.farm_token_nonce; + + let farm_result = self + .actual_exit_farm(farm_address, &farm_token_id, farm_token_nonce, &amount) + .into_tuple(); + let farming_token_returned = farm_result.0; + let reward_token_returned = farm_result.1; + + let caller = self.blockchain().get_caller(); + let mut payments_vec = ManagedVec::new(); + payments_vec.push(EsdtTokenPayment::new( + wrapped_farm_token_attrs.farming_token_id.clone(), + wrapped_farm_token_attrs.farming_token_nonce, + farming_token_returned.amount.clone(), + )); + payments_vec.push(EsdtTokenPayment::new( + reward_token_returned.token_identifier.clone(), + reward_token_returned.token_nonce, + reward_token_returned.amount.clone(), + )); + self.send_multiple_tokens_if_not_zero(&caller, &payments_vec); + self.send().esdt_local_burn(&token_id, token_nonce, &amount); + + if farming_token_returned.token_identifier == self.asset_token_id().get() { + self.send().esdt_local_burn( + &farming_token_returned.token_identifier, + 0, + &farming_token_returned.amount, + ); + } + + self.emit_exit_farm_proxy_event( + &caller, + farm_address, + &token_id, + token_nonce, + &amount, + &wrapped_farm_token_attrs, + &wrapped_farm_token_attrs.farming_token_id, + wrapped_farm_token_attrs.farming_token_nonce, + &farming_token_returned.amount, + &reward_token_returned.token_identifier, + reward_token_returned.token_nonce, + &reward_token_returned.amount, + ); + } + + fn actual_exit_farm( + &self, + farm_address: &ManagedAddress, + farm_token_id: &TokenIdentifier, + farm_token_nonce: Nonce, + amount: &BigUint, + ) -> ExitFarmResultType { + let raw_results: RawResultsType = self + .farm_contract_proxy(farm_address.clone()) + .exit_farm(OptionalValue::::None) + .with_esdt_transfer((farm_token_id.clone(), farm_token_nonce, amount.clone())) + .execute_on_dest_context(); + + let mut results_wrapper = RawResultWrapper::new(raw_results); + results_wrapper.trim_results_front(2); + + let farming_tokens = results_wrapper.decode_next_result(); + let reward_tokens = results_wrapper.decode_next_result(); + + (farming_tokens, reward_tokens).into() + } + + fn require_is_intermediated_farm(&self, address: &ManagedAddress) { + require!( + self.intermediated_farms().contains(address), + "Not an intermediated farm" + ); + } + + fn require_wrapped_farm_token_id_not_empty(&self) { + require!(!self.wrapped_farm_token_id().is_empty(), "Empty token id"); + } + + #[proxy] + fn farm_contract_proxy(&self, to: ManagedAddress) -> farm_v13_locked_rewards::Proxy; +} diff --git a/legacy-contracts/proxy-dex-legacy/src/proxy_pair.rs b/legacy-contracts/proxy-dex-legacy/src/proxy_pair.rs new file mode 100644 index 000000000..279343cf4 --- /dev/null +++ b/legacy-contracts/proxy-dex-legacy/src/proxy_pair.rs @@ -0,0 +1,203 @@ +#![allow(clippy::too_many_arguments)] +#![allow(clippy::comparison_chain)] +#![allow(clippy::vec_init_then_push)] + +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +use common_structs::{RawResultWrapper, RawResultsType}; +use factory_legacy::attr_ex_helper; +use pair::config::ProxyTrait as _; +use pair::pair_actions::common_result_types::RemoveLiquidityResultType; +use pair::pair_actions::remove_liq::ProxyTrait as _; + +use crate::energy_update; +use crate::proxy_common::WrappedLpTokenAttributes; + +use super::events; +use super::proxy_common; + +#[derive(ManagedVecItem, Clone)] +pub struct WrappedLpToken { + pub token_amount: EsdtTokenPayment, + pub attributes: WrappedLpTokenAttributes, +} + +#[multiversx_sc::module] +pub trait ProxyPairModule: + proxy_common::ProxyCommonModule + + token_merge_helper::TokenMergeHelperModule + + events::EventsModule + + energy_update::EnergyUpdateModule + + attr_ex_helper::AttrExHelper + + energy_query::EnergyQueryModule +{ + #[only_owner] + #[endpoint(addPairToIntermediate)] + fn add_pair_to_intermediate(&self, pair_address: ManagedAddress) { + self.intermediated_pairs().insert(pair_address); + } + + #[only_owner] + #[endpoint(removeIntermediatedPair)] + fn remove_intermediated_pair(&self, pair_address: ManagedAddress) { + self.require_is_intermediated_pair(&pair_address); + self.intermediated_pairs().remove(&pair_address); + } + + #[payable("*")] + #[endpoint(removeLiquidityProxy)] + fn remove_liquidity_proxy( + &self, + pair_address: ManagedAddress, + first_token_amount_min: BigUint, + second_token_amount_min: BigUint, + ) { + self.require_is_intermediated_pair(&pair_address); + self.require_wrapped_lp_token_id_not_empty(); + + let (token_id, token_nonce, amount) = self.call_value().single_esdt().into_tuple(); + require!(token_nonce != 0, "Can only be called with an SFT"); + require!(amount != 0, "Payment amount cannot be zero"); + + let wrapped_lp_token_id = self.wrapped_lp_token_id().get(); + require!(token_id == wrapped_lp_token_id, "Wrong input token"); + + let caller = self.blockchain().get_caller(); + let lp_token_id = self.ask_for_lp_token_id(&pair_address); + let attributes = self.get_wrapped_lp_token_attributes(&token_id, token_nonce); + require!(lp_token_id == attributes.lp_token_id, "Bad input address"); + + let locked_asset_token_id = self.locked_asset_token_id().get(); + let asset_token_id = self.asset_token_id().get(); + + let tokens_for_position = self + .actual_remove_liquidity( + &pair_address, + &lp_token_id, + &amount, + &first_token_amount_min, + &second_token_amount_min, + ) + .into_tuple(); + + let fungible_token_id: TokenIdentifier; + let fungible_token_amount: BigUint; + let assets_received: BigUint; + let locked_assets_invested = self.rule_of_three_non_zero_result( + &amount, + &attributes.lp_token_total_amount, + &attributes.locked_assets_invested, + ); + + if tokens_for_position.1.token_identifier == asset_token_id { + assets_received = tokens_for_position.1.amount.clone(); + fungible_token_id = tokens_for_position.0.token_identifier.clone(); + fungible_token_amount = tokens_for_position.0.amount.clone(); + } else { + sc_panic!("Bad tokens received from pair SC"); + } + + // Send back the tokens removed from pair sc. + let locked_assets_to_send = + core::cmp::min(assets_received.clone(), locked_assets_invested.clone()); + let mut payments_vec = ManagedVec::new(); + payments_vec.push(EsdtTokenPayment::new( + fungible_token_id.clone(), + 0, + fungible_token_amount.clone(), + )); + payments_vec.push(EsdtTokenPayment::new( + locked_asset_token_id.clone(), + attributes.locked_assets_nonce, + locked_assets_to_send.clone(), + )); + self.send_multiple_tokens_if_not_zero(&caller, &payments_vec); + + // Do cleanup + if assets_received > locked_assets_invested { + let difference = assets_received - locked_assets_invested; + self.send() + .direct_esdt(&caller, &asset_token_id, 0, &difference); + } else if assets_received < locked_assets_invested { + let difference = locked_assets_invested - assets_received; + self.deduct_energy_from_user( + &caller, + &locked_asset_token_id, + attributes.locked_assets_nonce, + &difference, + ); + self.send().esdt_local_burn( + &locked_asset_token_id, + attributes.locked_assets_nonce, + &difference, + ); + } + + self.send() + .esdt_local_burn(&asset_token_id, 0, &locked_assets_to_send); + self.send() + .esdt_local_burn(&wrapped_lp_token_id, token_nonce, &amount); + + self.emit_remove_liquidity_proxy_event( + &caller, + &pair_address, + &token_id, + token_nonce, + &amount, + &attributes, + &tokens_for_position.0.token_identifier, + 0, + &tokens_for_position.0.amount, + &tokens_for_position.1.token_identifier, + 0, + &tokens_for_position.1.amount, + ); + } + + fn actual_remove_liquidity( + &self, + pair_address: &ManagedAddress, + lp_token_id: &TokenIdentifier, + liquidity: &BigUint, + first_token_amount_min: &BigUint, + second_token_amount_min: &BigUint, + ) -> RemoveLiquidityResultType { + let raw_results: RawResultsType = self + .pair_contract_proxy(pair_address.clone()) + .remove_liquidity( + first_token_amount_min.clone(), + second_token_amount_min.clone(), + ) + .with_esdt_transfer((lp_token_id.clone(), 0, liquidity.clone())) + .execute_on_dest_context(); + + let mut results_wrapper = RawResultWrapper::new(raw_results); + results_wrapper.trim_results_front(2); + + let first_token = results_wrapper.decode_next_result(); + let second_token = results_wrapper.decode_next_result(); + + (first_token, second_token).into() + } + + fn ask_for_lp_token_id(&self, pair_address: &ManagedAddress) -> TokenIdentifier { + self.pair_contract_proxy(pair_address.clone()) + .get_lp_token_identifier() + .execute_on_dest_context() + } + + fn require_is_intermediated_pair(&self, address: &ManagedAddress) { + require!( + self.intermediated_pairs().contains(address), + "Not an intermediated pair" + ); + } + + fn require_wrapped_lp_token_id_not_empty(&self) { + require!(!self.wrapped_lp_token_id().is_empty(), "Empty token id"); + } + + #[proxy] + fn pair_contract_proxy(&self, to: ManagedAddress) -> pair::Proxy; +} diff --git a/legacy-contracts/proxy-dex-legacy/src/transfer_role.rs b/legacy-contracts/proxy-dex-legacy/src/transfer_role.rs new file mode 100644 index 000000000..ad0787e4e --- /dev/null +++ b/legacy-contracts/proxy-dex-legacy/src/transfer_role.rs @@ -0,0 +1,90 @@ +multiversx_sc::imports!(); + +use super::proxy_common; + +#[multiversx_sc::module] +pub trait TransferRoleModule: proxy_common::ProxyCommonModule { + /// Sets the transfer role for the given address. Defaults to own SC address. + #[only_owner] + #[endpoint(setTransferRoleLockedLpToken)] + fn set_transfer_role_locked_lp_token(&self, opt_address: OptionalValue) { + let locked_lp_token_id = self.wrapped_lp_token_id().get(); + let role_dest_address = match opt_address { + OptionalValue::Some(addr) => addr, + OptionalValue::None => self.blockchain().get_sc_address(), + }; + let roles = [EsdtLocalRole::Transfer]; + + self.send() + .esdt_system_sc_proxy() + .set_special_roles( + &role_dest_address, + &locked_lp_token_id, + roles.iter().cloned(), + ) + .async_call_and_exit() + } + + /// Removes the transfer role for the given address. Defaults to own SC address. + #[only_owner] + #[endpoint(unsetTransferRoleLockedLpToken)] + fn unset_transfer_role_locked_lp_token(&self, opt_address: OptionalValue) { + let locked_lp_token_id = self.wrapped_lp_token_id().get(); + let role_dest_address = match opt_address { + OptionalValue::Some(addr) => addr, + OptionalValue::None => self.blockchain().get_sc_address(), + }; + let roles = [EsdtLocalRole::Transfer]; + + self.send() + .esdt_system_sc_proxy() + .unset_special_roles( + &role_dest_address, + &locked_lp_token_id, + roles.iter().cloned(), + ) + .async_call_and_exit() + } + + /// Sets the transfer role for the given address. Defaults to own SC address. + #[only_owner] + #[endpoint(setTransferRoleLockedFarmToken)] + fn set_transfer_role_locked_farm_token(&self, opt_address: OptionalValue) { + let locked_farm_token_id = self.wrapped_farm_token_id().get(); + let role_dest_address = match opt_address { + OptionalValue::Some(addr) => addr, + OptionalValue::None => self.blockchain().get_sc_address(), + }; + let roles = [EsdtLocalRole::Transfer]; + + self.send() + .esdt_system_sc_proxy() + .set_special_roles( + &role_dest_address, + &locked_farm_token_id, + roles.iter().cloned(), + ) + .async_call_and_exit() + } + + /// Removes the transfer role for the given address. Defaults to own SC address. + #[only_owner] + #[endpoint(unsetTransferRoleLockedFarmToken)] + fn unset_transfer_role_locked_farm_token(&self, opt_address: OptionalValue) { + let locked_farm_token_id = self.wrapped_farm_token_id().get(); + let role_dest_address = match opt_address { + OptionalValue::Some(addr) => addr, + OptionalValue::None => self.blockchain().get_sc_address(), + }; + let roles = [EsdtLocalRole::Transfer]; + + self.send() + .esdt_system_sc_proxy() + .unset_special_roles( + &role_dest_address, + &locked_farm_token_id, + roles.iter().cloned(), + ) + .async_call_and_exit() + } +} diff --git a/locked-asset/factory/testnet.toml b/legacy-contracts/proxy-dex-legacy/testnet.toml similarity index 100% rename from locked-asset/factory/testnet.toml rename to legacy-contracts/proxy-dex-legacy/testnet.toml diff --git a/farm-staking/metabonding-staking/wasm/Cargo.lock b/legacy-contracts/proxy-dex-legacy/wasm/Cargo.lock similarity index 64% rename from farm-staking/metabonding-staking/wasm/Cargo.lock rename to legacy-contracts/proxy-dex-legacy/wasm/Cargo.lock index 739fec429..d45260ddb 100644 --- a/farm-staking/metabonding-staking/wasm/Cargo.lock +++ b/legacy-contracts/proxy-dex-legacy/wasm/Cargo.lock @@ -4,27 +4,28 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[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 = "common_errors" @@ -46,9 +47,9 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "endian-type" @@ -73,19 +74,48 @@ dependencies = [ ] [[package]] -name = "factory" +name = "energy-query" +version = "0.0.0" +dependencies = [ + "energy-factory", + "multiversx-sc", +] + +[[package]] +name = "factory-legacy" version = "0.0.0" dependencies = [ - "arrayvec", "common_errors", "common_structs", "energy-factory", - "itertools", "multiversx-sc", "multiversx-sc-modules", "token_merge_helper", - "token_send", - "wee_alloc", +] + +[[package]] +name = "farm-v13-locked-rewards" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +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]] @@ -126,76 +156,58 @@ dependencies = [ ] [[package]] -name = "libc" -version = "0.2.151" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" - -[[package]] -name = "math" +name = "locking_module" version = "0.0.0" dependencies = [ + "energy-factory", "multiversx-sc", + "simple-lock", ] [[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - -[[package]] -name = "mergeable" +name = "math" version = "0.0.0" dependencies = [ "multiversx-sc", ] [[package]] -name = "metabonding-staking" +name = "mergeable" version = "0.0.0" dependencies = [ - "factory", "multiversx-sc", - "multiversx-sc-modules", -] - -[[package]] -name = "metabonding-staking-wasm" -version = "0.0.0" -dependencies = [ - "metabonding-staking", - "multiversx-sc-wasm-adapter", ] [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -205,9 +217,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -218,18 +230,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -245,27 +257,82 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] +[[package]] +name = "pair" +version = "0.0.0" +dependencies = [ + "common_errors", + "common_structs", + "fees-collector", + "itertools", + "multiversx-sc", + "pausable", + "permissions_module", + "simple-lock", + "token_send", + "utils", +] + +[[package]] +name = "pausable" +version = "0.0.0" +dependencies = [ + "multiversx-sc", + "permissions_module", +] + +[[package]] +name = "permissions_module" +version = "0.0.0" +dependencies = [ + "bitflags", + "common_errors", + "multiversx-sc", +] + [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] +[[package]] +name = "proxy-dex-legacy" +version = "0.0.0" +dependencies = [ + "common_structs", + "energy-factory", + "energy-query", + "factory-legacy", + "farm-v13-locked-rewards", + "multiversx-sc", + "pair", + "token_merge_helper", +] + +[[package]] +name = "proxy-dex-legacy-wasm" +version = "0.0.0" +dependencies = [ + "multiversx-sc-wasm-adapter", + "proxy-dex-legacy", +] + [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -299,15 +366,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -337,6 +404,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" @@ -355,35 +428,21 @@ dependencies = [ ] [[package]] -name = "wee_alloc" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" +name = "week-timekeeping" +version = "0.0.0" dependencies = [ - "cfg-if", - "libc", - "memory_units", - "winapi", + "common-types", + "multiversx-sc", ] [[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +name = "weekly-rewards-splitting" +version = "0.0.0" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "common-types", + "energy-query", + "math", + "multiversx-sc", + "unwrappable", + "week-timekeeping", ] - -[[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/legacy-contracts/proxy-dex-legacy/wasm/Cargo.toml b/legacy-contracts/proxy-dex-legacy/wasm/Cargo.toml new file mode 100644 index 000000000..2fb6c25c8 --- /dev/null +++ b/legacy-contracts/proxy-dex-legacy/wasm/Cargo.toml @@ -0,0 +1,34 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + +[package] +name = "proxy-dex-legacy-wasm" +version = "0.0.0" +edition = "2018" +publish = false + +[lib] +crate-type = ["cdylib"] + +[profile.release] +codegen-units = 1 +opt-level = "z" +lto = true +debug = false +panic = "abort" +overflow-checks = false + +[profile.dev] +panic = "abort" + +[dependencies.proxy-dex-legacy] +path = ".." + +[dependencies.multiversx-sc-wasm-adapter] +version = "=0.53.2" + +[workspace] +members = ["."] diff --git a/legacy-contracts/proxy-dex-legacy/wasm/src/lib.rs b/legacy-contracts/proxy-dex-legacy/wasm/src/lib.rs new file mode 100644 index 000000000..4711ddb98 --- /dev/null +++ b/legacy-contracts/proxy-dex-legacy/wasm/src/lib.rs @@ -0,0 +1,45 @@ +// Code generated by the multiversx-sc build system. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +// Init: 1 +// Upgrade: 1 +// Endpoints: 19 +// Async Callback (empty): 1 +// Total number of exported functions: 22 + +#![no_std] + +multiversx_sc_wasm_adapter::allocator!(); +multiversx_sc_wasm_adapter::panic_handler!(); + +multiversx_sc_wasm_adapter::endpoints! { + proxy_dex_legacy + ( + init => init + upgrade => upgrade + getAssetTokenId => asset_token_id + getLockedAssetTokenId => locked_asset_token_id + getWrappedLpTokenId => wrapped_lp_token_id + getWrappedFarmTokenId => wrapped_farm_token_id + getIntermediatedFarms => get_intermediated_farms + getIntermediatedPairs => get_intermediated_pairs + addPairToIntermediate => add_pair_to_intermediate + removeIntermediatedPair => remove_intermediated_pair + removeLiquidityProxy => remove_liquidity_proxy + addFarmToIntermediate => add_farm_to_intermediate + removeIntermediatedFarm => remove_intermediated_farm + exitFarmProxy => exit_farm_proxy + setTransferRoleLockedLpToken => set_transfer_role_locked_lp_token + unsetTransferRoleLockedLpToken => unset_transfer_role_locked_lp_token + setTransferRoleLockedFarmToken => set_transfer_role_locked_farm_token + unsetTransferRoleLockedFarmToken => unset_transfer_role_locked_farm_token + getExtendedAttributesActivationNonce => extended_attributes_activation_nonce + setEnergyFactoryAddress => set_energy_factory_address + getEnergyFactoryAddress => energy_factory_address + ) +} + +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/legacy-contracts/simple-lock-legacy/.gitignore b/legacy-contracts/simple-lock-legacy/.gitignore new file mode 100644 index 000000000..eaf5915bd --- /dev/null +++ b/legacy-contracts/simple-lock-legacy/.gitignore @@ -0,0 +1,7 @@ +# Generated by Cargo +# will have compiled files and executables +/target/ +*/target/ + +# The erdpy output +output diff --git a/farm-staking/metabonding-staking/Cargo.toml b/legacy-contracts/simple-lock-legacy/Cargo.toml similarity index 67% rename from farm-staking/metabonding-staking/Cargo.toml rename to legacy-contracts/simple-lock-legacy/Cargo.toml index de3c1ff97..057957d73 100644 --- a/farm-staking/metabonding-staking/Cargo.toml +++ b/legacy-contracts/simple-lock-legacy/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "metabonding-staking" +name = "simple-lock-legacy" version = "0.0.0" authors = ["MultiversX "] edition = "2021" @@ -9,20 +9,19 @@ publish = false path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" -[dependencies.factory] -path = "../../locked-asset/factory" +[dependencies.common_structs] +path = "../../common/common_structs" [dev-dependencies] num-bigint = "0.4.2" +num-traits = "0.2" +hex = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" - -[dev-dependencies.common_structs] -path = "../../common/common_structs" +version = "=0.53.2" diff --git a/locked-asset/distribution/meta/Cargo.toml b/legacy-contracts/simple-lock-legacy/meta/Cargo.toml similarity index 54% rename from locked-asset/distribution/meta/Cargo.toml rename to legacy-contracts/simple-lock-legacy/meta/Cargo.toml index 76c13747b..b664c256b 100644 --- a/locked-asset/distribution/meta/Cargo.toml +++ b/legacy-contracts/simple-lock-legacy/meta/Cargo.toml @@ -1,13 +1,13 @@ [package] -name = "distribution-abi" +name = "simple-lock-legacy-meta" version = "0.0.0" -authors = ["MultiversX "] edition = "2021" publish = false +authors = ["MultiversX "] -[dependencies.distribution] +[dependencies.simple-lock-legacy] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/legacy-contracts/simple-lock-legacy/meta/src/main.rs b/legacy-contracts/simple-lock-legacy/meta/src/main.rs new file mode 100644 index 000000000..5c69ad39f --- /dev/null +++ b/legacy-contracts/simple-lock-legacy/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta_lib::cli_main::(); +} diff --git a/locked-asset/factory/elrond.json b/legacy-contracts/simple-lock-legacy/multiversx.json similarity index 100% rename from locked-asset/factory/elrond.json rename to legacy-contracts/simple-lock-legacy/multiversx.json diff --git a/legacy-contracts/simple-lock-legacy/src/basic_lock_unlock.rs b/legacy-contracts/simple-lock-legacy/src/basic_lock_unlock.rs new file mode 100644 index 000000000..0585da9a6 --- /dev/null +++ b/legacy-contracts/simple-lock-legacy/src/basic_lock_unlock.rs @@ -0,0 +1,61 @@ +multiversx_sc::imports!(); + +use crate::{ + error_messages::{CANNOT_UNLOCK_YET_ERR_MSG, NO_PAYMENT_ERR_MSG}, + locked_token::LockedTokenAttributes, +}; + +#[multiversx_sc::module] +pub trait BasicLockUnlock: + crate::locked_token::LockedTokenModule +{ + fn unlock_and_send( + &self, + to: &ManagedAddress, + payment: EsdtTokenPayment, + ) -> EgldOrEsdtTokenPayment { + let out_payment = self.unlock_tokens(payment); + self.send().direct( + to, + &out_payment.token_identifier, + out_payment.token_nonce, + &out_payment.amount, + ); + + out_payment + } + + fn unlock_tokens( + &self, + payment: EsdtTokenPayment, + ) -> EgldOrEsdtTokenPayment { + let locked_token_mapper = self.locked_token(); + locked_token_mapper.require_same_token(&payment.token_identifier); + + let attributes: LockedTokenAttributes = + locked_token_mapper.get_token_attributes(payment.token_nonce); + let current_epoch = self.blockchain().get_block_epoch(); + require!( + current_epoch >= attributes.unlock_epoch, + CANNOT_UNLOCK_YET_ERR_MSG + ); + + locked_token_mapper.nft_burn(payment.token_nonce, &payment.amount); + + self.unlock_tokens_unchecked(payment, &attributes) + } + + fn unlock_tokens_unchecked( + &self, + payment: EsdtTokenPayment, + attributes: &LockedTokenAttributes, + ) -> EgldOrEsdtTokenPayment { + require!(payment.amount > 0, NO_PAYMENT_ERR_MSG); + + EgldOrEsdtTokenPayment::new( + attributes.original_token_id.clone(), + attributes.original_token_nonce, + payment.amount, + ) + } +} diff --git a/legacy-contracts/simple-lock-legacy/src/error_messages.rs b/legacy-contracts/simple-lock-legacy/src/error_messages.rs new file mode 100644 index 000000000..345e5a015 --- /dev/null +++ b/legacy-contracts/simple-lock-legacy/src/error_messages.rs @@ -0,0 +1,2 @@ +pub static NO_PAYMENT_ERR_MSG: &[u8] = b"No payment"; +pub static CANNOT_UNLOCK_YET_ERR_MSG: &[u8] = b"Cannot unlock yet"; diff --git a/legacy-contracts/simple-lock-legacy/src/lib.rs b/legacy-contracts/simple-lock-legacy/src/lib.rs new file mode 100644 index 000000000..4f0abbe0c --- /dev/null +++ b/legacy-contracts/simple-lock-legacy/src/lib.rs @@ -0,0 +1,41 @@ +#![no_std] + +multiversx_sc::imports!(); + +pub mod basic_lock_unlock; +pub mod error_messages; +pub mod locked_token; +pub mod proxy_farm; +pub mod proxy_lp; + +#[multiversx_sc::contract] +pub trait SimpleLockLegacy: + basic_lock_unlock::BasicLockUnlock + + locked_token::LockedTokenModule + + proxy_lp::ProxyLpModule + + proxy_farm::ProxyFarmModule +{ + #[init] + fn init(&self) {} + + #[upgrade] + fn upgrade(&self) {} + + #[payable("*")] + #[endpoint(unlockTokens)] + fn unlock_tokens_endpoint( + &self, + opt_destination: OptionalValue, + ) -> EgldOrEsdtTokenPayment { + let payment = self.call_value().single_esdt(); + let dest_address = self.dest_from_optional(opt_destination); + self.unlock_and_send(&dest_address, payment) + } + + fn dest_from_optional(&self, opt_destination: OptionalValue) -> ManagedAddress { + match opt_destination { + OptionalValue::Some(dest) => dest, + OptionalValue::None => self.blockchain().get_caller(), + } + } +} diff --git a/legacy-contracts/simple-lock-legacy/src/locked_token.rs b/legacy-contracts/simple-lock-legacy/src/locked_token.rs new file mode 100644 index 000000000..69c20142c --- /dev/null +++ b/legacy-contracts/simple-lock-legacy/src/locked_token.rs @@ -0,0 +1,16 @@ +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +#[derive(TypeAbi, TopEncode, TopDecode, NestedDecode, NestedEncode, PartialEq, Debug, Clone)] +pub struct LockedTokenAttributes { + pub original_token_id: EgldOrEsdtTokenIdentifier, + pub original_token_nonce: u64, + pub unlock_epoch: u64, +} + +#[multiversx_sc::module] +pub trait LockedTokenModule { + #[view(getLockedTokenId)] + #[storage_mapper("lockedTokenId")] + fn locked_token(&self) -> NonFungibleTokenMapper; +} diff --git a/legacy-contracts/simple-lock-legacy/src/proxy_farm.rs b/legacy-contracts/simple-lock-legacy/src/proxy_farm.rs new file mode 100644 index 000000000..6cdcac9f5 --- /dev/null +++ b/legacy-contracts/simple-lock-legacy/src/proxy_farm.rs @@ -0,0 +1,92 @@ +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +use crate::error_messages::*; + +#[derive( + TypeAbi, TopEncode, TopDecode, NestedEncode, NestedDecode, PartialEq, Debug, Clone, Copy, +)] +pub enum FarmType { + SimpleFarm, + FarmWithLockedRewards, + FarmWithBoostedRewards +} + +#[derive(TypeAbi, TopEncode, TopDecode, NestedEncode, NestedDecode, PartialEq, Debug)] +pub struct FarmProxyTokenAttributes { + pub farm_type: FarmType, + pub farm_token_id: TokenIdentifier, + pub farm_token_nonce: u64, + pub farming_token_id: TokenIdentifier, + pub farming_token_locked_nonce: u64, +} + +#[multiversx_sc::module] +pub trait ProxyFarmModule: + crate::locked_token::LockedTokenModule + crate::proxy_lp::ProxyLpModule +{ + /// Output payments: the underlying farm tokens + #[payable("*")] + #[endpoint(exitFarmLockedToken)] + fn exit_farm_locked_token(&self) -> EsdtTokenPayment { + let payment: EsdtTokenPayment = self.call_value().single_esdt(); + let caller = self.blockchain().get_caller(); + + let farm_proxy_token_attributes: FarmProxyTokenAttributes = + self.validate_payment_and_get_farm_proxy_token_attributes(&payment); + + let _ = self.check_and_get_unlocked_lp_token( + &self.lp_proxy_token().get_token_id(), + farm_proxy_token_attributes.farming_token_locked_nonce, + ); + + self.send().esdt_local_burn( + &self.lp_proxy_token().get_token_id(), + farm_proxy_token_attributes.farming_token_locked_nonce, + &payment.amount, + ); + + let output_token_payment = EsdtTokenPayment::new( + farm_proxy_token_attributes.farm_token_id, + farm_proxy_token_attributes.farm_token_nonce, + payment.amount, + ); + + self.send().direct_esdt( + &caller, + &output_token_payment.token_identifier, + output_token_payment.token_nonce, + &output_token_payment.amount, + ); + + output_token_payment + } + + /// Output payments: the underlying farm tokens + #[payable("*")] + #[endpoint(farmClaimRewardsLockedToken)] + fn farm_claim_rewards_locked_token(&self) -> EsdtTokenPayment { + self.exit_farm_locked_token() + } + + fn validate_payment_and_get_farm_proxy_token_attributes( + &self, + payment: &EsdtTokenPayment, + ) -> FarmProxyTokenAttributes { + require!(payment.amount > 0, NO_PAYMENT_ERR_MSG); + + let farm_proxy_token_mapper = self.farm_proxy_token(); + farm_proxy_token_mapper.require_same_token(&payment.token_identifier); + + 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, &payment.amount); + + farm_proxy_token_attributes + } + + #[view(getFarmProxyTokenId)] + #[storage_mapper("farmProxyTokenId")] + fn farm_proxy_token(&self) -> NonFungibleTokenMapper; +} diff --git a/legacy-contracts/simple-lock-legacy/src/proxy_lp.rs b/legacy-contracts/simple-lock-legacy/src/proxy_lp.rs new file mode 100644 index 000000000..60145ad5e --- /dev/null +++ b/legacy-contracts/simple-lock-legacy/src/proxy_lp.rs @@ -0,0 +1,62 @@ +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +#[derive(TypeAbi, TopEncode, TopDecode, NestedEncode, NestedDecode, PartialEq, Debug)] +pub struct LpProxyTokenAttributes { + pub lp_token_id: TokenIdentifier, + pub first_token_id: TokenIdentifier, + pub first_token_locked_nonce: u64, + pub second_token_id: TokenIdentifier, + pub second_token_locked_nonce: u64, +} + +#[multiversx_sc::module] +pub trait ProxyLpModule: crate::locked_token::LockedTokenModule { + #[payable("*")] + #[endpoint(removeLiquidityLockedToken)] + fn remove_liquidity_locked_token( + &self, + _first_token_amount_min: BigUint, + _second_token_amount_min: BigUint, + ) -> EsdtTokenPayment { + let payment = self.call_value().single_esdt(); + let caller = self.blockchain().get_caller(); + + let unlocked_lp_token_id = + self.check_and_get_unlocked_lp_token(&payment.token_identifier, payment.token_nonce); + + self.send().esdt_local_burn( + &payment.token_identifier, + payment.token_nonce, + &payment.amount, + ); + + let output_token_payment = EsdtTokenPayment::new(unlocked_lp_token_id, 0, payment.amount); + self.send().direct_esdt( + &caller, + &output_token_payment.token_identifier, + output_token_payment.token_nonce, + &output_token_payment.amount, + ); + + output_token_payment + } + + fn check_and_get_unlocked_lp_token( + &self, + token_id: &TokenIdentifier, + token_nonce: u64, + ) -> TokenIdentifier { + let lp_proxy_token_mapper: NonFungibleTokenMapper = self.lp_proxy_token(); + lp_proxy_token_mapper.require_same_token(token_id); + + let lp_proxy_token_attributes: LpProxyTokenAttributes = + lp_proxy_token_mapper.get_token_attributes(token_nonce); + + lp_proxy_token_attributes.lp_token_id + } + + #[view(getLpProxyTokenId)] + #[storage_mapper("lpProxyTokenId")] + fn lp_proxy_token(&self) -> NonFungibleTokenMapper; +} diff --git a/legacy-contracts/simple-lock-legacy/tests/rust_test.rs b/legacy-contracts/simple-lock-legacy/tests/rust_test.rs new file mode 100644 index 000000000..568605b0b --- /dev/null +++ b/legacy-contracts/simple-lock-legacy/tests/rust_test.rs @@ -0,0 +1,521 @@ +#![allow(deprecated)] + +use common_structs::FarmTokenAttributes; +use multiversx_sc::codec::multi_types::OptionalValue; +use multiversx_sc::imports::ContractBase; +use multiversx_sc::types::EsdtLocalRole; +use multiversx_sc_scenario::{ + managed_address, managed_biguint, managed_token_id, rust_biguint, DebugApi, +}; +use multiversx_sc_scenario::{managed_token_id_wrapped, whitebox_legacy::*}; + +use multiversx_sc::storage::mappers::StorageTokenWrapper; +use simple_lock_legacy::proxy_farm::{FarmProxyTokenAttributes, FarmType, ProxyFarmModule}; +use simple_lock_legacy::proxy_lp::{LpProxyTokenAttributes, ProxyLpModule}; +use simple_lock_legacy::{locked_token::*, SimpleLockLegacy}; + +const FREE_TOKEN_ID: &[u8] = b"FREEEEE-123456"; +const WEGLD_TOKEN_ID: &[u8] = b"WEGLD-123456"; +const LOCKED_TOKEN_ID: &[u8] = b"NOOO0-123456"; +const LP_TOKEN_ID: &[u8] = b"LPTOK-123456"; +const LP_PROXY_TOKEN_ID: &[u8] = b"LPPROXY-123456"; +const FARM_TOKEN_ID: &[u8] = b"FARMTOK-123456"; +const FARM_PROXY_TOKEN_ID: &[u8] = b"FARMPROXY-123456"; + +#[test] +fn unlock_token_test() { + let rust_zero = rust_biguint!(0); + let mut b_mock = BlockchainStateWrapper::new(); + + let user_addr = b_mock.create_user_account(&rust_zero); + let owner_addr = b_mock.create_user_account(&rust_zero); + let sc_wrapper = b_mock.create_sc_account( + &rust_zero, + Some(&owner_addr), + simple_lock_legacy::contract_obj, + "Some path", + ); + + b_mock.set_block_epoch(5); + + b_mock + .execute_tx(&owner_addr, &sc_wrapper, &rust_zero, |sc| { + sc.init(); + sc.locked_token() + .set_token_id(managed_token_id!(LOCKED_TOKEN_ID)); + sc.lp_proxy_token() + .set_token_id(managed_token_id!(LP_PROXY_TOKEN_ID)); + sc.farm_proxy_token() + .set_token_id(managed_token_id!(FARM_PROXY_TOKEN_ID)); + }) + .assert_ok(); + + b_mock.set_esdt_local_roles( + sc_wrapper.address_ref(), + LOCKED_TOKEN_ID, + &[ + EsdtLocalRole::NftCreate, + EsdtLocalRole::NftAddQuantity, + EsdtLocalRole::NftBurn, + ], + ); + b_mock.set_esdt_local_roles( + sc_wrapper.address_ref(), + LP_PROXY_TOKEN_ID, + &[ + EsdtLocalRole::NftCreate, + EsdtLocalRole::NftAddQuantity, + EsdtLocalRole::NftBurn, + ], + ); + b_mock.set_esdt_local_roles( + sc_wrapper.address_ref(), + FARM_PROXY_TOKEN_ID, + &[ + EsdtLocalRole::NftCreate, + EsdtLocalRole::NftAddQuantity, + EsdtLocalRole::NftBurn, + ], + ); + + let lock_token_nonce = 1u64; + let lock_amount = rust_biguint!(1_000); + + DebugApi::dummy(); + b_mock.set_esdt_balance(sc_wrapper.address_ref(), FREE_TOKEN_ID, &lock_amount); + let locked_token_attributes: LockedTokenAttributes = LockedTokenAttributes { + original_token_id: managed_token_id_wrapped!(FREE_TOKEN_ID), + original_token_nonce: 0, + unlock_epoch: 10u64, + }; + b_mock.set_nft_balance( + &user_addr, + LOCKED_TOKEN_ID, + lock_token_nonce, + &lock_amount, + &locked_token_attributes, + ); + + b_mock.check_nft_balance( + &user_addr, + LOCKED_TOKEN_ID, + lock_token_nonce, + &lock_amount, + Some(&locked_token_attributes), + ); + b_mock.check_esdt_balance(sc_wrapper.address_ref(), FREE_TOKEN_ID, &lock_amount); + b_mock.check_esdt_balance(&user_addr, FREE_TOKEN_ID, &rust_zero); + + // unlock ok + b_mock.set_block_epoch(10); + b_mock + .execute_esdt_transfer( + &user_addr, + &sc_wrapper, + LOCKED_TOKEN_ID, + lock_token_nonce, + &lock_amount, + |sc| { + sc.unlock_tokens_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + b_mock.check_esdt_balance(&user_addr, FREE_TOKEN_ID, &lock_amount); + b_mock.check_nft_balance( + &user_addr, + LOCKED_TOKEN_ID, + lock_token_nonce, + &rust_zero, + Some(&locked_token_attributes), + ); + b_mock.check_esdt_balance(sc_wrapper.address_ref(), FREE_TOKEN_ID, &rust_zero); + b_mock.check_nft_balance( + sc_wrapper.address_ref(), + LOCKED_TOKEN_ID, + lock_token_nonce, + &rust_zero, + Some(&locked_token_attributes), + ); +} + +#[test] +fn exit_lp_test() { + let rust_zero = rust_biguint!(0); + let mut b_mock = BlockchainStateWrapper::new(); + + let user_addr = b_mock.create_user_account(&rust_zero); + let owner_addr = b_mock.create_user_account(&rust_zero); + let sc_wrapper = b_mock.create_sc_account( + &rust_zero, + Some(&owner_addr), + simple_lock_legacy::contract_obj, + "Some path", + ); + + b_mock.set_block_epoch(5); + + b_mock + .execute_tx(&owner_addr, &sc_wrapper, &rust_zero, |sc| { + sc.init(); + sc.locked_token() + .set_token_id(managed_token_id!(LOCKED_TOKEN_ID)); + sc.lp_proxy_token() + .set_token_id(managed_token_id!(LP_PROXY_TOKEN_ID)); + sc.farm_proxy_token() + .set_token_id(managed_token_id!(FARM_PROXY_TOKEN_ID)); + }) + .assert_ok(); + + b_mock.set_esdt_local_roles( + sc_wrapper.address_ref(), + LOCKED_TOKEN_ID, + &[ + EsdtLocalRole::NftCreate, + EsdtLocalRole::NftAddQuantity, + EsdtLocalRole::NftBurn, + ], + ); + b_mock.set_esdt_local_roles( + sc_wrapper.address_ref(), + LP_PROXY_TOKEN_ID, + &[ + EsdtLocalRole::NftCreate, + EsdtLocalRole::NftAddQuantity, + EsdtLocalRole::NftBurn, + ], + ); + b_mock.set_esdt_local_roles( + sc_wrapper.address_ref(), + FARM_PROXY_TOKEN_ID, + &[ + EsdtLocalRole::NftCreate, + EsdtLocalRole::NftAddQuantity, + EsdtLocalRole::NftBurn, + ], + ); + + let lock_token_nonce = 1u64; + let lock_amount = rust_biguint!(1_000); + + DebugApi::dummy(); + // Simulate the user add liquidity step by setting the SC balance manually + b_mock.set_esdt_balance(sc_wrapper.address_ref(), LP_TOKEN_ID, &lock_amount); + + b_mock + .execute_tx(&owner_addr, &sc_wrapper, &rust_zero, |sc| { + let lp_proxy_token_amount = managed_biguint!(1_000u64); + // Needed to be able to read the token attributes + sc.send().esdt_nft_create_compact( + &managed_token_id!(LOCKED_TOKEN_ID), + &managed_biguint!(1u64), + &LockedTokenAttributes:: { + original_token_id: managed_token_id_wrapped!(FREE_TOKEN_ID), + original_token_nonce: 0, + unlock_epoch: 10, + }, + ); + let lp_proxy_token_nonce = sc.send().esdt_nft_create_compact( + &managed_token_id!(LP_PROXY_TOKEN_ID), + &lp_proxy_token_amount, + &LpProxyTokenAttributes:: { + lp_token_id: managed_token_id!(LP_TOKEN_ID), + first_token_id: managed_token_id!(FREE_TOKEN_ID), + first_token_locked_nonce: 1, + second_token_id: managed_token_id!(WEGLD_TOKEN_ID), + second_token_locked_nonce: 0, + }, + ); + + sc.send().direct_esdt( + &managed_address!(&user_addr), + &managed_token_id!(LP_PROXY_TOKEN_ID), + lp_proxy_token_nonce, + &lp_proxy_token_amount, + ); + }) + .assert_ok(); + + let locked_lp_token_attributes: LpProxyTokenAttributes = LpProxyTokenAttributes { + lp_token_id: managed_token_id!(LP_TOKEN_ID), + first_token_id: managed_token_id!(FREE_TOKEN_ID), + first_token_locked_nonce: 1, + second_token_id: managed_token_id!(WEGLD_TOKEN_ID), + second_token_locked_nonce: 0, + }; + b_mock.check_nft_balance( + &user_addr, + LP_PROXY_TOKEN_ID, + lock_token_nonce, + &lock_amount, + Some(&locked_lp_token_attributes), + ); + + // unlock ok + b_mock.set_block_epoch(10); + b_mock + .execute_esdt_transfer( + &user_addr, + &sc_wrapper, + LP_PROXY_TOKEN_ID, + lock_token_nonce, + &lock_amount, + |sc| { + sc.remove_liquidity_locked_token(managed_biguint!(0u64), managed_biguint!(0u64)); + }, + ) + .assert_ok(); + b_mock.check_esdt_balance(&user_addr, LP_TOKEN_ID, &lock_amount); + b_mock.check_esdt_balance(sc_wrapper.address_ref(), LP_TOKEN_ID, &rust_zero); + b_mock.check_nft_balance( + &user_addr, + LP_PROXY_TOKEN_ID, + lock_token_nonce, + &rust_zero, + Some(&locked_lp_token_attributes), + ); + b_mock.check_nft_balance( + sc_wrapper.address_ref(), + LP_PROXY_TOKEN_ID, + lock_token_nonce, + &rust_zero, + Some(&locked_lp_token_attributes), + ); +} + +#[test] +fn exit_farm_test() { + let rust_zero = rust_biguint!(0); + let mut b_mock = BlockchainStateWrapper::new(); + + let user_addr = b_mock.create_user_account(&rust_zero); + let owner_addr = b_mock.create_user_account(&rust_zero); + let sc_wrapper = b_mock.create_sc_account( + &rust_zero, + Some(&owner_addr), + simple_lock_legacy::contract_obj, + "Some path", + ); + + b_mock.set_block_epoch(5); + + b_mock + .execute_tx(&owner_addr, &sc_wrapper, &rust_zero, |sc| { + sc.init(); + sc.locked_token() + .set_token_id(managed_token_id!(LOCKED_TOKEN_ID)); + sc.lp_proxy_token() + .set_token_id(managed_token_id!(LP_PROXY_TOKEN_ID)); + sc.farm_proxy_token() + .set_token_id(managed_token_id!(FARM_PROXY_TOKEN_ID)); + }) + .assert_ok(); + + b_mock.set_esdt_local_roles( + sc_wrapper.address_ref(), + LOCKED_TOKEN_ID, + &[ + EsdtLocalRole::NftCreate, + EsdtLocalRole::NftAddQuantity, + EsdtLocalRole::NftBurn, + ], + ); + b_mock.set_esdt_local_roles( + sc_wrapper.address_ref(), + LP_PROXY_TOKEN_ID, + &[ + EsdtLocalRole::NftCreate, + EsdtLocalRole::NftAddQuantity, + EsdtLocalRole::NftBurn, + ], + ); + b_mock.set_esdt_local_roles( + sc_wrapper.address_ref(), + FARM_PROXY_TOKEN_ID, + &[ + EsdtLocalRole::NftCreate, + EsdtLocalRole::NftAddQuantity, + EsdtLocalRole::NftBurn, + ], + ); + + let lock_token_nonce = 1u64; + let lock_amount = rust_biguint!(2_000u64); + + DebugApi::dummy(); + b_mock + .execute_tx(&owner_addr, &sc_wrapper, &rust_zero, |sc| { + let farm_proxy_token_amount = managed_biguint!(2_000u64); + // Needed to be able to read the token attributes + sc.send().esdt_nft_create_compact( + &managed_token_id!(LOCKED_TOKEN_ID), + &managed_biguint!(1u64), + &LockedTokenAttributes:: { + original_token_id: managed_token_id_wrapped!(FREE_TOKEN_ID), + original_token_nonce: 0, + unlock_epoch: 10, + }, + ); + sc.send().esdt_nft_create_compact( + &managed_token_id!(LP_PROXY_TOKEN_ID), + &farm_proxy_token_amount, + &LpProxyTokenAttributes:: { + lp_token_id: managed_token_id!(LP_TOKEN_ID), + first_token_id: managed_token_id!(FREE_TOKEN_ID), + first_token_locked_nonce: 1, + second_token_id: managed_token_id!(WEGLD_TOKEN_ID), + second_token_locked_nonce: 0, + }, + ); + let farm_proxy_token_nonce = sc.send().esdt_nft_create_compact( + &managed_token_id!(FARM_PROXY_TOKEN_ID), + &farm_proxy_token_amount, + &FarmProxyTokenAttributes:: { + farm_type: FarmType::FarmWithLockedRewards, + farm_token_id: managed_token_id!(FARM_TOKEN_ID), + farm_token_nonce: 1, + farming_token_id: managed_token_id!(LP_TOKEN_ID), + farming_token_locked_nonce: 1, + }, + ); + + sc.send().direct_esdt( + &managed_address!(&user_addr), + &managed_token_id!(FARM_PROXY_TOKEN_ID), + farm_proxy_token_nonce, + &farm_proxy_token_amount, + ); + }) + .assert_ok(); + + let locked_farm_token_attributes: FarmProxyTokenAttributes = + FarmProxyTokenAttributes { + farm_type: FarmType::FarmWithLockedRewards, + farm_token_id: managed_token_id!(FARM_TOKEN_ID), + farm_token_nonce: 1, + farming_token_id: managed_token_id!(LP_TOKEN_ID), + farming_token_locked_nonce: 1, + }; + b_mock.check_nft_balance( + &user_addr, + FARM_PROXY_TOKEN_ID, + lock_token_nonce, + &lock_amount, + Some(&locked_farm_token_attributes), + ); + + let farm_attributes: FarmTokenAttributes = FarmTokenAttributes { + reward_per_share: managed_biguint!(0u64), + entering_epoch: 5u64, + compounded_reward: managed_biguint!(0u64), + current_farm_amount: managed_biguint!(2_000u64), + original_owner: managed_address!(&user_addr), + }; + b_mock.set_nft_balance( + sc_wrapper.address_ref(), + FARM_TOKEN_ID, + 1, + &lock_amount, + &farm_attributes, + ); + b_mock.check_nft_balance::>( + &user_addr, + FARM_TOKEN_ID, + 1, + &rust_zero, + None, + ); + b_mock.check_nft_balance( + sc_wrapper.address_ref(), + FARM_TOKEN_ID, + 1, + &lock_amount, + Some(&farm_attributes), + ); + + // unlock ok + let half_lock_amount = rust_biguint!(1_000u64); + b_mock.set_block_epoch(10); + b_mock + .execute_esdt_transfer( + &user_addr, + &sc_wrapper, + FARM_PROXY_TOKEN_ID, + lock_token_nonce, + &half_lock_amount, + |sc| { + sc.farm_claim_rewards_locked_token(); + }, + ) + .assert_ok(); + + b_mock.check_nft_balance::>( + sc_wrapper.address_ref(), + FARM_TOKEN_ID, + lock_token_nonce, + &half_lock_amount, + Some(&farm_attributes), + ); + b_mock.check_nft_balance( + &user_addr, + FARM_TOKEN_ID, + lock_token_nonce, + &half_lock_amount, + Some(&farm_attributes), + ); + b_mock.check_nft_balance::>( + sc_wrapper.address_ref(), + FARM_PROXY_TOKEN_ID, + lock_token_nonce, + &rust_zero, + None, + ); + b_mock.check_nft_balance::>( + &user_addr, + FARM_PROXY_TOKEN_ID, + lock_token_nonce, + &half_lock_amount, + Some(&locked_farm_token_attributes), + ); + + b_mock + .execute_esdt_transfer( + &user_addr, + &sc_wrapper, + FARM_PROXY_TOKEN_ID, + lock_token_nonce, + &half_lock_amount, + |sc| { + sc.exit_farm_locked_token(); + }, + ) + .assert_ok(); + + b_mock.check_nft_balance::>( + sc_wrapper.address_ref(), + FARM_TOKEN_ID, + lock_token_nonce, + &rust_zero, + None, + ); + b_mock.check_nft_balance( + &user_addr, + FARM_TOKEN_ID, + lock_token_nonce, + &lock_amount, + Some(&farm_attributes), + ); + b_mock.check_nft_balance::>( + sc_wrapper.address_ref(), + FARM_PROXY_TOKEN_ID, + lock_token_nonce, + &rust_zero, + None, + ); + b_mock.check_nft_balance::>( + &user_addr, + FARM_PROXY_TOKEN_ID, + lock_token_nonce, + &rust_zero, + None, + ); +} diff --git a/locked-asset/simple-lock-whitelist/wasm/Cargo.lock b/legacy-contracts/simple-lock-legacy/wasm/Cargo.lock similarity index 70% rename from locked-asset/simple-lock-whitelist/wasm/Cargo.lock rename to legacy-contracts/simple-lock-legacy/wasm/Cargo.lock index e6300116a..9d97e44e0 100644 --- a/locked-asset/simple-lock-whitelist/wasm/Cargo.lock +++ b/legacy-contracts/simple-lock-legacy/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common_structs" @@ -72,32 +72,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -107,9 +109,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -120,18 +122,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -147,27 +149,27 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -183,7 +185,7 @@ dependencies = [ ] [[package]] -name = "simple-lock" +name = "simple-lock-legacy" version = "0.0.0" dependencies = [ "common_structs", @@ -192,34 +194,24 @@ dependencies = [ ] [[package]] -name = "simple-lock-whitelist" -version = "0.0.0" -dependencies = [ - "multiversx-sc", - "multiversx-sc-modules", - "simple-lock", - "utils", -] - -[[package]] -name = "simple-lock-whitelist-wasm" +name = "simple-lock-legacy-wasm" version = "0.0.0" dependencies = [ "multiversx-sc-wasm-adapter", - "simple-lock-whitelist", + "simple-lock-legacy", ] [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -233,18 +225,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] -name = "unwrappable" -version = "0.0.0" -dependencies = [ - "multiversx-sc", -] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" [[package]] -name = "utils" +name = "unwrappable" version = "0.0.0" dependencies = [ - "common_structs", - "fixed-supply-token", - "mergeable", "multiversx-sc", ] diff --git a/legacy-contracts/simple-lock-legacy/wasm/Cargo.toml b/legacy-contracts/simple-lock-legacy/wasm/Cargo.toml new file mode 100644 index 000000000..35fad85cd --- /dev/null +++ b/legacy-contracts/simple-lock-legacy/wasm/Cargo.toml @@ -0,0 +1,34 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + +[package] +name = "simple-lock-legacy-wasm" +version = "0.0.0" +edition = "2021" +publish = false + +[lib] +crate-type = ["cdylib"] + +[profile.release] +codegen-units = 1 +opt-level = "z" +lto = true +debug = false +panic = "abort" +overflow-checks = false + +[profile.dev] +panic = "abort" + +[dependencies.simple-lock-legacy] +path = ".." + +[dependencies.multiversx-sc-wasm-adapter] +version = "=0.53.2" + +[workspace] +members = ["."] diff --git a/legacy-contracts/simple-lock-legacy/wasm/src/lib.rs b/legacy-contracts/simple-lock-legacy/wasm/src/lib.rs new file mode 100644 index 000000000..996a3fd22 --- /dev/null +++ b/legacy-contracts/simple-lock-legacy/wasm/src/lib.rs @@ -0,0 +1,33 @@ +// Code generated by the multiversx-sc build system. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +// Init: 1 +// Upgrade: 1 +// Endpoints: 7 +// Async Callback (empty): 1 +// Total number of exported functions: 10 + +#![no_std] + +multiversx_sc_wasm_adapter::allocator!(); +multiversx_sc_wasm_adapter::panic_handler!(); + +multiversx_sc_wasm_adapter::endpoints! { + simple_lock_legacy + ( + init => init + upgrade => upgrade + unlockTokens => unlock_tokens_endpoint + getLockedTokenId => locked_token + removeLiquidityLockedToken => remove_liquidity_locked_token + getLpProxyTokenId => lp_proxy_token + exitFarmLockedToken => exit_farm_locked_token + farmClaimRewardsLockedToken => farm_claim_rewards_locked_token + getFarmProxyTokenId => farm_proxy_token + ) +} + +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/locked-asset/Cargo.toml b/locked-asset/Cargo.toml index d7ba66a4c..b8c2b5512 100644 --- a/locked-asset/Cargo.toml +++ b/locked-asset/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" publish = false [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.farm] @@ -17,12 +17,6 @@ path = "../dex/pair" [dependencies.router] path = "../dex/router" -[dependencies.distribution] -path = "distribution" - -[dependencies.factory] -path = "factory" - [dependencies.simple-lock] path = "simple-lock" @@ -50,7 +44,7 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" diff --git a/locked-asset/distribution/meta/src/main.rs b/locked-asset/distribution/meta/src/main.rs deleted file mode 100644 index 5dc92d871..000000000 --- a/locked-asset/distribution/meta/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - multiversx_sc_meta::cli_main::(); -} diff --git a/locked-asset/distribution/src/global_op.rs b/locked-asset/distribution/src/global_op.rs deleted file mode 100644 index 619b88550..000000000 --- a/locked-asset/distribution/src/global_op.rs +++ /dev/null @@ -1,42 +0,0 @@ -multiversx_sc::imports!(); -multiversx_sc::derive_imports!(); - -#[multiversx_sc::module] -pub trait GlobalOperationModule { - #[only_owner] - #[endpoint(startGlobalOperation)] - fn global_op_start(&self) { - require!( - !self.global_op_is_ongoing().get(), - "Global operation already ongoing" - ); - self.global_op_is_ongoing().set(true); - } - - #[only_owner] - #[endpoint(endGlobalOperation)] - fn global_op_stop(&self) { - require!( - self.global_op_is_ongoing().get(), - "Global operation not ongoing" - ); - self.global_op_is_ongoing().set(false); - } - - #[storage_mapper("global_operation_ongoing")] - fn global_op_is_ongoing(&self) -> SingleValueMapper; - - fn require_global_op_not_ongoing(&self) { - require!( - !self.global_op_is_ongoing().get(), - "Global operation ongoing" - ); - } - - fn require_global_op_ongoing(&self) { - require!( - self.global_op_is_ongoing().get(), - "Global operation not ongoing" - ); - } -} diff --git a/locked-asset/distribution/src/lib.rs b/locked-asset/distribution/src/lib.rs deleted file mode 100644 index 93187154e..000000000 --- a/locked-asset/distribution/src/lib.rs +++ /dev/null @@ -1,363 +0,0 @@ -#![no_std] -#![allow(clippy::type_complexity)] - -use common_structs::{UnlockMilestone, UnlockPeriod}; - -multiversx_sc::imports!(); -multiversx_sc::derive_imports!(); - -mod global_op; - -const GAS_THRESHOLD: u64 = 100_000; -const MAX_CLAIMABLE_DISTRIBUTION_ROUNDS: usize = 4; - -#[derive(ManagedVecItem)] -pub struct BigUintEpochPair { - pub biguint: BigUint, - pub epoch: u64, -} - -#[derive(ManagedVecItem, TopEncode, TopDecode, NestedEncode, NestedDecode, PartialEq, TypeAbi)] -pub struct UserLockedAssetKey { - pub caller: ManagedAddress, - pub spread_epoch: u64, -} - -#[derive(TopEncode, TopDecode, NestedEncode, NestedDecode, PartialEq, TypeAbi, Clone)] -pub struct CommunityDistribution { - pub total_amount: BigUint, - pub spread_epoch: u64, - pub after_planning_amount: BigUint, -} - -#[multiversx_sc::contract] -pub trait Distribution: global_op::GlobalOperationModule { - #[proxy] - fn locked_asset_factory_proxy(&self, to: ManagedAddress) -> factory::Proxy; - - #[init] - fn init(&self, asset_token_id: TokenIdentifier, locked_asset_factory_address: ManagedAddress) { - require!( - asset_token_id.is_valid_esdt_identifier(), - "Asset token ID is not a valid esdt identifier" - ); - - self.asset_token_id().set_if_empty(&asset_token_id); - self.locked_asset_factory_address() - .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) { - self.require_global_op_ongoing(); - require!(total_amount > 0, "Zero amount"); - require!( - spread_epoch >= self.blockchain().get_block_epoch(), - "Spread epoch in the past" - ); - require!( - self.community_distribution_list() - .front() - .map(|community_distrib| community_distrib.get_value_as_ref().spread_epoch) - .unwrap_or_default() - < spread_epoch, - "Community distribution should be added in chronological order" - ); - - let distrib = CommunityDistribution { - total_amount: total_amount.clone(), - spread_epoch, - after_planning_amount: total_amount, - }; - self.community_distribution_list().push_front(distrib); - } - - #[only_owner] - #[endpoint(setPerUserDistributedLockedAssets)] - fn set_per_user_distributed_locked_assets( - &self, - spread_epoch: u64, - user_locked_assets: MultiValueEncoded>, - ) { - self.require_global_op_ongoing(); - self.require_community_distribution_list_not_empty(); - - require!(!user_locked_assets.is_empty(), "Empty assets vec"); - self.add_all_user_assets_to_map(spread_epoch, user_locked_assets) - } - - #[endpoint(claimLockedAssets)] - fn claim_locked_assets(&self) -> BigUint { - self.require_global_op_not_ongoing(); - self.require_unlock_period_not_empty(); - self.require_community_distribution_list_not_empty(); - - let caller = self.blockchain().get_caller(); - let mut cummulated_amount = BigUint::zero(); - - let locked_assets = self.calculate_user_locked_assets(&caller, true); - if locked_assets.is_empty() { - return cummulated_amount; - } - - let to = self.locked_asset_factory_address().get(); - let gas_limit_per_execute = - self.blockchain().get_gas_left() / (locked_assets.len() as u64 + 1); - - let unlock_period = self.unlock_period().get(); - for elem in locked_assets.iter() { - let amount = elem.biguint; - let spread_epoch = elem.epoch; - let _: IgnoreValue = self - .locked_asset_factory_proxy(to.clone()) - .create_and_forward_custom_period( - amount.clone(), - caller.clone(), - spread_epoch, - unlock_period.clone(), - ) - .with_gas_limit(gas_limit_per_execute) - .execute_on_dest_context(); - - cummulated_amount += amount; - } - - cummulated_amount - } - - #[endpoint(clearUnclaimableAssets)] - fn clear_unclaimable_assets(&self) -> usize { - let biggest_unclaimable_asset_epoch = self.get_biggest_unclaimable_asset_epoch(); - self.undo_user_assets_between_epochs(0, biggest_unclaimable_asset_epoch) - } - - #[only_owner] - #[endpoint(undoLastCommunityDistribution)] - fn undo_last_community_distrib(&self) { - self.require_global_op_ongoing(); - self.require_community_distribution_list_not_empty(); - self.community_distribution_list().pop_front(); - } - - #[only_owner] - #[endpoint(undoUserDistributedAssetsBetweenEpochs)] - fn undo_user_assets_between_epochs(&self, lower: u64, higher: u64) -> usize { - self.require_global_op_ongoing(); - self.require_community_distribution_list_not_empty(); - require!(lower <= higher, "Bad input values"); - self.remove_asset_entries_between_epochs(lower, higher) - } - - #[only_owner] - #[endpoint(setUnlockPeriod)] - fn set_unlock_period(&self, milestones: MultiValueEncoded) { - let unlock_milestones = milestones.to_vec(); - self.validate_unlock_milestones(&unlock_milestones); - self.unlock_period() - .set(&UnlockPeriod { unlock_milestones }); - } - - #[view(calculateLockedAssets)] - fn calculate_locked_assets_view(&self, address: ManagedAddress) -> BigUint { - self.require_global_op_not_ongoing(); - self.require_community_distribution_list_not_empty(); - let locked_assets = self.calculate_user_locked_assets(&address, false); - - let mut cummulated_amount = BigUint::zero(); - for elem in locked_assets.iter() { - cummulated_amount += elem.biguint; - } - cummulated_amount - } - - fn validate_unlock_milestones(&self, unlock_milestones: &ManagedVec) { - require!(!unlock_milestones.is_empty(), "Empty param"); - - let mut percents_sum: u8 = 0; - let mut last_milestone_unlock_epoch: u64 = 0; - - for milestone in unlock_milestones.into_iter() { - require!( - milestone.unlock_epoch >= last_milestone_unlock_epoch, - "Unlock epochs not in order" - ); - require!( - milestone.unlock_percent <= 100, - "Unlock percent more than 100" - ); - last_milestone_unlock_epoch = milestone.unlock_epoch; - percents_sum += milestone.unlock_percent; - } - - require!(percents_sum == 100, "Percents do not sum up to 100"); - } - - fn add_all_user_assets_to_map( - &self, - spread_epoch: u64, - user_assets: MultiValueEncoded>, - ) { - let mut last_community_distrib = self - .community_distribution_list() - .front() - .unwrap() - .get_value_cloned(); - require!( - spread_epoch == last_community_distrib.spread_epoch, - "Bad spread epoch" - ); - - for user_asset_multiarg in user_assets.into_iter() { - let (caller, asset_amount) = user_asset_multiarg.into_tuple(); - require!(asset_amount > 0, "Zero amount"); - require!( - last_community_distrib.after_planning_amount >= asset_amount, - "User assets sums above community total assets" - ); - last_community_distrib.after_planning_amount -= &asset_amount; - self.add_user_locked_asset_entry(caller, asset_amount, spread_epoch); - } - - self.community_distribution_list().pop_front(); - self.community_distribution_list() - .push_front(last_community_distrib); - } - - fn add_user_locked_asset_entry( - &self, - caller: ManagedAddress, - asset_amount: BigUint, - spread_epoch: u64, - ) { - let key = UserLockedAssetKey { - caller, - spread_epoch, - }; - require!( - !self.user_locked_asset_map().contains_key(&key), - "Vector has duplicates" - ); - self.user_locked_asset_map().insert(key, asset_amount); - } - - fn calculate_user_locked_assets( - &self, - address: &ManagedAddress, - delete_after_visit: bool, - ) -> ManagedVec> { - let current_epoch = self.blockchain().get_block_epoch(); - let mut locked_assets = ManagedVec::new(); - - for community_distrib in self - .community_distribution_list() - .iter() - .take(MAX_CLAIMABLE_DISTRIBUTION_ROUNDS) - .filter(|x| x.get_value_as_ref().spread_epoch <= current_epoch) - { - let user_asset_key = UserLockedAssetKey { - caller: address.clone(), - spread_epoch: community_distrib.get_value_as_ref().spread_epoch, - }; - - if let Some(asset_amount) = self.user_locked_asset_map().get(&user_asset_key) { - locked_assets.push(BigUintEpochPair { - biguint: asset_amount, - epoch: user_asset_key.spread_epoch, - }); - - if delete_after_visit { - self.user_locked_asset_map().remove(&user_asset_key); - } - } - } - locked_assets - } - - fn get_biggest_unclaimable_asset_epoch(&self) -> u64 { - self.community_distribution_list() - .iter() - .nth(MAX_CLAIMABLE_DISTRIBUTION_ROUNDS) - .map(|community_distrib| community_distrib.get_value_as_ref().spread_epoch) - .unwrap_or_default() - } - - fn remove_asset_entries_between_epochs(&self, lower: u64, higher: u64) -> usize { - if higher == 0 { - return 0; - } - - if higher < lower { - return 0; - } - - let mut to_remove_keys = ManagedVec::>::new(); - let search_gas_limit = self.blockchain().get_gas_left() / 2; - for user_asset_key in self.user_locked_asset_map().keys() { - if self.blockchain().get_gas_left() < search_gas_limit { - break; - } - - if lower <= user_asset_key.spread_epoch && user_asset_key.spread_epoch <= higher { - to_remove_keys.push(user_asset_key); - } - } - - let map_len_before = self.user_locked_asset_map().len(); - for key in to_remove_keys.iter() { - if self.blockchain().get_gas_left() < GAS_THRESHOLD { - break; - } - - self.user_locked_asset_map().remove(&key); - } - map_len_before - self.user_locked_asset_map().len() - } - - fn require_community_distribution_list_not_empty(&self) { - require!( - !self.community_distribution_list().is_empty(), - "Empty community assets list" - ); - } - - fn require_unlock_period_not_empty(&self) { - require!(!self.unlock_period().is_empty(), "Empty unlock schedule"); - } - - #[only_owner] - #[endpoint(deleteUserDistributedLockedAssets)] - fn delete_user_distributed_locked_assets(&self, spread_epoch: u64, address: ManagedAddress) { - self.require_global_op_ongoing(); - self.user_locked_asset_map().remove(&UserLockedAssetKey { - caller: address, - spread_epoch, - }); - } - - #[view(getUsersDistributedLockedAssetsLength)] - fn get_users_distributed_locked_assets_length(&self) -> usize { - self.user_locked_asset_map().len() - } - - #[view(getUnlockPeriod)] - #[storage_mapper("unlock_period")] - fn unlock_period(&self) -> SingleValueMapper>; - - #[view(getCommunityDistributionList)] - #[storage_mapper("community_distribution_list")] - fn community_distribution_list(&self) -> LinkedListMapper>; - - #[storage_mapper("user_locked_asset_map")] - fn user_locked_asset_map(&self) -> MapMapper, BigUint>; - - #[storage_mapper("locked_asset_factory_address")] - fn locked_asset_factory_address(&self) -> SingleValueMapper; - - #[view(getAssetTokenId)] - #[storage_mapper("asset_token_id")] - fn asset_token_id(&self) -> SingleValueMapper; -} diff --git a/locked-asset/distribution/wasm/src/lib.rs b/locked-asset/distribution/wasm/src/lib.rs deleted file mode 100644 index 87c728bb7..000000000 --- a/locked-asset/distribution/wasm/src/lib.rs +++ /dev/null @@ -1,42 +0,0 @@ -// Code generated by the multiversx-sc build system. DO NOT EDIT. - -//////////////////////////////////////////////////// -////////////////// AUTO-GENERATED ////////////////// -//////////////////////////////////////////////////// - -// Init: 1 -// Endpoints: 16 -// Async Callback (empty): 1 -// Total number of exported functions: 18 - -#![no_std] -#![allow(internal_features)] -#![feature(lang_items)] - -multiversx_sc_wasm_adapter::allocator!(); -multiversx_sc_wasm_adapter::panic_handler!(); - -multiversx_sc_wasm_adapter::endpoints! { - distribution - ( - 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::async_callback_empty! {} diff --git a/locked-asset/energy-factory/Cargo.toml b/locked-asset/energy-factory/Cargo.toml index 74e3cbea9..feb1470b4 100644 --- a/locked-asset/energy-factory/Cargo.toml +++ b/locked-asset/energy-factory/Cargo.toml @@ -33,11 +33,11 @@ path = "../../common/traits/unwrappable" path = "../../common/modules/legacy_token_decode_module" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" [dev-dependencies] num-bigint = "0.4.2" @@ -45,4 +45,4 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" diff --git a/locked-asset/energy-factory/meta/Cargo.toml b/locked-asset/energy-factory/meta/Cargo.toml index 6365191f0..0f95b5590 100644 --- a/locked-asset/energy-factory/meta/Cargo.toml +++ b/locked-asset/energy-factory/meta/Cargo.toml @@ -10,6 +10,6 @@ authors = ["MultiversX "] [dependencies.energy-factory] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/locked-asset/energy-factory/meta/src/main.rs b/locked-asset/energy-factory/meta/src/main.rs index 2eca0970a..74eed8b7c 100644 --- a/locked-asset/energy-factory/meta/src/main.rs +++ b/locked-asset/energy-factory/meta/src/main.rs @@ -1,3 +1,3 @@ fn main() { - multiversx_sc_meta::cli_main::(); + multiversx_sc_meta_lib::cli_main::(); } diff --git a/locked-asset/energy-factory/src/lib.rs b/locked-asset/energy-factory/src/lib.rs index d146566d6..a8cd96be4 100644 --- a/locked-asset/energy-factory/src/lib.rs +++ b/locked-asset/energy-factory/src/lib.rs @@ -91,7 +91,7 @@ pub trait SimpleLockEnergy: self.set_paused(true); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} /// Locks a whitelisted token until `unlock_epoch` and receive meta ESDT LOCKED tokens @@ -230,4 +230,33 @@ pub trait SimpleLockEnergy: output_tokens } + + #[only_owner] + #[endpoint(adjustUserEnergy)] + fn adjust_user_energy( + &self, + args: MultiValueEncoded>, + ) { + for arg in args { + let (user, energy_amount, token_amount) = arg.into_tuple(); + require!(!self.user_energy(&user).is_empty(), "User energy not found"); + let old_energy = self.get_updated_energy_entry_for_user(&user); + let new_energy_amount = old_energy.get_energy_amount_raw() + &energy_amount; + let new_total_locked_tokens = if token_amount >= 0 { + old_energy.get_total_locked_tokens() + &token_amount.magnitude() + } else { + let token_amount_magnitude = token_amount.magnitude(); + require!( + old_energy.get_total_locked_tokens() >= &token_amount_magnitude, + "Insufficient locked tokens" + ); + old_energy.get_total_locked_tokens() - &token_amount_magnitude + }; + + let current_epoch = self.blockchain().get_block_epoch(); + let new_energy = Energy::new(new_energy_amount, current_epoch, new_total_locked_tokens); + + self.set_energy_entry(&user, new_energy); + } + } } diff --git a/locked-asset/energy-factory/src/locked_token_transfer.rs b/locked-asset/energy-factory/src/locked_token_transfer.rs index a233fa336..8e9397e48 100644 --- a/locked-asset/energy-factory/src/locked_token_transfer.rs +++ b/locked-asset/energy-factory/src/locked_token_transfer.rs @@ -4,7 +4,10 @@ use crate::energy::Energy; #[multiversx_sc::module] pub trait LockedTokenTransferModule: - utils::UtilsModule + crate::energy::EnergyModule + crate::events::EventsModule + utils::UtilsModule + + crate::energy::EnergyModule + + crate::events::EventsModule + + multiversx_sc_modules::pause::PauseModule { #[only_owner] #[endpoint(addToTokenTransferWhitelist)] @@ -34,6 +37,7 @@ pub trait LockedTokenTransferModule: user: ManagedAddress, energy: Energy, ) { + self.require_not_paused(); let caller = self.blockchain().get_caller(); self.token_transfer_whitelist().require_whitelisted(&caller); diff --git a/locked-asset/energy-factory/src/unlock_with_penalty.rs b/locked-asset/energy-factory/src/unlock_with_penalty.rs index a59ca05e2..102565ed5 100644 --- a/locked-asset/energy-factory/src/unlock_with_penalty.rs +++ b/locked-asset/energy-factory/src/unlock_with_penalty.rs @@ -38,6 +38,7 @@ pub trait UnlockWithPenaltyModule: #[payable("*")] #[endpoint(unlockEarly)] fn unlock_early(&self) { + self.require_not_paused(); let caller = self.blockchain().get_caller(); let payment = self.call_value().single_esdt(); let reduce_result = self.reduce_lock_period_common(&caller, payment.clone(), None); @@ -59,6 +60,7 @@ pub trait UnlockWithPenaltyModule: #[payable("*")] #[endpoint(reduceLockPeriod)] fn reduce_lock_period(&self, new_lock_period: Epoch) -> EsdtTokenPayment { + self.require_not_paused(); self.require_is_listed_lock_option(new_lock_period); let caller = self.blockchain().get_caller(); diff --git a/locked-asset/energy-factory/src/unstake.rs b/locked-asset/energy-factory/src/unstake.rs index 9f0409e00..9d9df5f8d 100644 --- a/locked-asset/energy-factory/src/unstake.rs +++ b/locked-asset/energy-factory/src/unstake.rs @@ -45,6 +45,7 @@ pub trait UnstakeModule: #[payable("*")] #[endpoint(revertUnstake)] fn revert_unstake(&self, user: ManagedAddress, new_energy: Energy) { + self.require_not_paused(); self.require_caller_unstake_sc(); self.set_energy_entry(&user, new_energy); diff --git a/locked-asset/energy-factory/src/virtual_lock.rs b/locked-asset/energy-factory/src/virtual_lock.rs index 9d7172989..94aa0abf5 100644 --- a/locked-asset/energy-factory/src/virtual_lock.rs +++ b/locked-asset/energy-factory/src/virtual_lock.rs @@ -29,6 +29,7 @@ pub trait VirtualLockModule: dest_address: ManagedAddress, energy_address: ManagedAddress, ) -> EsdtTokenPayment { + self.require_not_paused(); require!( self.is_base_asset_token(&token_id), "May only lock the base asset token" diff --git a/locked-asset/energy-factory/tests/energy_factory_setup/mod.rs b/locked-asset/energy-factory/tests/energy_factory_setup/mod.rs index de10068c0..4f3abf678 100644 --- a/locked-asset/energy-factory/tests/energy_factory_setup/mod.rs +++ b/locked-asset/energy-factory/tests/energy_factory_setup/mod.rs @@ -10,7 +10,7 @@ use energy_factory::{ use multiversx_sc::{ codec::multi_types::OptionalValue, storage::mappers::StorageTokenWrapper, - types::{Address, EsdtLocalRole, MultiValueEncoded}, + types::{Address, BigInt, EsdtLocalRole, MultiValueEncoded}, }; use multiversx_sc_modules::pause::PauseModule; use multiversx_sc_scenario::{ @@ -19,6 +19,8 @@ use multiversx_sc_scenario::{ whitebox_legacy::{BlockchainStateWrapper, ContractObjWrapper}, DebugApi, }; + +use num_bigint::Sign; use simple_lock::locked_token::LockedTokenModule; use unbond_sc_mock::*; @@ -173,6 +175,7 @@ where token_nonce: u64, amount: u64, lock_epochs: u64, + opt_address: Option
, ) -> TxResult { self.b_mock.execute_esdt_transfer( caller, @@ -181,7 +184,15 @@ where token_nonce, &rust_biguint!(amount), |sc| { - sc.lock_tokens_endpoint(lock_epochs, OptionalValue::None); + if opt_address.is_some() { + let address = opt_address.unwrap(); + sc.lock_tokens_endpoint( + lock_epochs, + OptionalValue::Some(managed_address!(&address)), + ); + } else { + sc.lock_tokens_endpoint(lock_epochs, OptionalValue::None); + } }, ) } @@ -263,6 +274,47 @@ where result } + + pub fn get_user_energy_raw(&mut self, user: &Address) -> num_bigint::BigInt { + let mut result = num_bigint::BigInt::from_biguint(Sign::NoSign, rust_biguint!(0)); + self.b_mock + .execute_query(&self.sc_wrapper, |sc| { + let user_energy = sc.get_updated_energy_entry_for_user(&managed_address!(user)); + result = to_rust_bigint(user_energy.get_energy_amount_raw().clone()); + }) + .assert_ok(); + + result + } + + pub fn get_user_locked_tokens(&mut self, user: &Address) -> num_bigint::BigUint { + let mut result = rust_biguint!(0); + self.b_mock + .execute_query(&self.sc_wrapper, |sc| { + let user_energy = sc.get_updated_energy_entry_for_user(&managed_address!(user)); + result = to_rust_biguint(user_energy.get_total_locked_tokens().clone()); + }) + .assert_ok(); + + result + } + + pub fn adjust_user_energy(&mut self, user: &Address, energy_amount: i64, token_amount: i64) { + self.b_mock + .execute_tx(&self.owner, &self.sc_wrapper, &rust_biguint!(0), |sc| { + let mut args = MultiValueEncoded::new(); + args.push( + ( + managed_address!(user), + BigInt::from(energy_amount), + BigInt::from(token_amount), + ) + .into(), + ); + sc.adjust_user_energy(args); + }) + .assert_ok(); + } } pub fn to_rust_biguint( @@ -271,6 +323,16 @@ pub fn to_rust_biguint( num_bigint::BigUint::from_bytes_be(managed_biguint.to_bytes_be().as_slice()) } +pub fn to_rust_bigint( + managed_biguint: multiversx_sc::types::BigInt, +) -> num_bigint::BigInt { + if managed_biguint < 0 { + num_bigint::BigInt::from_biguint(Sign::Minus, to_rust_biguint(managed_biguint.magnitude())) + } else { + num_bigint::BigInt::from_biguint(Sign::Plus, to_rust_biguint(managed_biguint.magnitude())) + } +} + pub fn to_start_of_month(unlock_epoch: u64) -> u64 { unlock_epoch - unlock_epoch % 30 } diff --git a/locked-asset/energy-factory/tests/simple_lock_energy_test.rs b/locked-asset/energy-factory/tests/simple_lock_energy_test.rs index 823a8eb56..530a906cc 100644 --- a/locked-asset/energy-factory/tests/simple_lock_energy_test.rs +++ b/locked-asset/energy-factory/tests/simple_lock_energy_test.rs @@ -2,9 +2,13 @@ mod energy_factory_setup; -use energy_factory::energy::EnergyModule; +use energy_factory::{ + energy::EnergyModule, locked_token_transfer::LockedTokenTransferModule, SimpleLockEnergy, +}; use energy_factory_setup::*; use multiversx_sc::types::BigUint; +use num_bigint::BigInt; +use num_traits::{FromPrimitive, Zero}; use simple_lock::locked_token::LockedTokenAttributes; use multiversx_sc_scenario::{ @@ -315,6 +319,7 @@ fn reduce_lock_period_test() { fn extend_locking_period_test() { let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); let first_user = setup.first_user.clone(); + let random_user = setup.b_mock.create_user_account(&rust_biguint!(0u64)); let half_balance = USER_BALANCE / 2; let current_epoch = 1; @@ -329,7 +334,7 @@ fn extend_locking_period_test() { ) .assert_ok(); - // extend to 3 years - unsupported option + // extend to a random period - unsupported option setup .extend_locking_period( &first_user, @@ -337,10 +342,11 @@ fn extend_locking_period_test() { 1, half_balance, 3 * EPOCHS_IN_YEAR, + None, ) .assert_user_error("Invalid lock choice"); - // extend to 10 years + // extend to a whitelisted period, but for a different user setup .extend_locking_period( &first_user, @@ -348,8 +354,33 @@ fn extend_locking_period_test() { 1, half_balance, LOCK_OPTIONS[1], + Some(random_user), + ) + .assert_user_error("May not use the optional destination argument here"); + + // extend to the second option - should work as intended + // 1 epoch has passed + let energy_per_epoch = rust_biguint!(500_000_000_000_000_000u64); + let energy_before = setup.get_user_energy(&first_user); // 179_500_000_000_000_000_000 + assert_eq!( + energy_before, + LOCK_OPTIONS[0] * energy_per_epoch.clone() - energy_per_epoch.clone() + ); + setup + .extend_locking_period( + &first_user, + LOCKED_TOKEN_ID, + 1, + half_balance, + LOCK_OPTIONS[1], + None, ) .assert_ok(); + let energy_after = setup.get_user_energy(&first_user); // 359_500_000_000_000_000_000 + assert_eq!( + energy_after, + LOCK_OPTIONS[1] * energy_per_epoch.clone() - energy_per_epoch.clone() + ); let new_unlock_epoch = to_start_of_month(current_epoch + LOCK_OPTIONS[1]); setup.b_mock.check_nft_balance( @@ -376,6 +407,7 @@ fn extend_locking_period_test() { 2, half_balance, LOCK_OPTIONS[0], + None, ) .assert_user_error("New lock period must be longer than the current one"); } @@ -461,3 +493,238 @@ fn energy_deplete_test() { }) .assert_ok(); } + +#[test] +fn extend_lock_period_endpoint_test() { + let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); + let first_user = setup.first_user.clone(); + + let current_epoch = 1; + setup.b_mock.set_block_epoch(current_epoch); + + setup + .lock( + &first_user, + BASE_ASSET_TOKEN_ID, + USER_BALANCE, + LOCK_OPTIONS[0], + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.sc_wrapper, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.extend_lock_period(100, managed_address!(&first_user)); + }, + ) + .assert_user_error("Invalid lock choice"); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.sc_wrapper, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.extend_lock_period(LOCK_OPTIONS[0], managed_address!(&first_user)); + }, + ) + .assert_user_error("May not call this endpoint. Use lockTokens instead"); + + let energy_per_epoch = rust_biguint!(USER_BALANCE); + let energy_before = setup.get_user_energy(&first_user); + assert_eq!( + energy_before, + LOCK_OPTIONS[0] * energy_per_epoch.clone() - energy_per_epoch.clone() + ); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.sc_wrapper, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.token_transfer_whitelist() + .add(&managed_address!(&first_user)); + sc.extend_lock_period(LOCK_OPTIONS[1], managed_address!(&first_user)); + }, + ) + .assert_ok(); + + let energy_after = setup.get_user_energy(&first_user); + assert_eq!( + energy_after, + LOCK_OPTIONS[1] * energy_per_epoch.clone() - energy_per_epoch.clone() + ); +} + +#[test] +fn adjust_user_energy_test() { + let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); + let user = setup.first_user.clone(); + let user_balance = 1_000_000u64; + + // Initial lock to create user energy + setup + .lock(&user, BASE_ASSET_TOKEN_ID, user_balance, LOCK_OPTIONS[0]) + .assert_ok(); + + // Check initial energy + let initial_locked_tokens = rust_biguint!(user_balance); + let initial_energy = initial_locked_tokens.clone() * LOCK_OPTIONS[0]; + assert_eq!(setup.get_user_locked_tokens(&user), initial_locked_tokens); + assert_eq!(setup.get_user_energy(&user), initial_energy); + + // Case 1: Positive energy, positive token amount + let adjustment1_energy = 1_000_000i64; + let adjustment1_tokens = 500_000i64; + setup.adjust_user_energy(&user, adjustment1_energy, adjustment1_tokens); + + let locked_tokens1 = setup.get_user_locked_tokens(&user); + let energy1 = setup.get_user_energy(&user); + assert_eq!( + locked_tokens1, + &initial_locked_tokens + &rust_biguint!(adjustment1_tokens) + ); + assert_eq!( + energy1, + &initial_energy + &rust_biguint!(adjustment1_energy) + ); + + // Case 2: Positive energy, negative token amount + let adjustment2_energy = 800_000i64; + let adjustment2_tokens = -300_000i64; + setup.adjust_user_energy(&user, adjustment2_energy, adjustment2_tokens); + + let locked_tokens2 = setup.get_user_locked_tokens(&user); + let energy2 = setup.get_user_energy(&user); + assert_eq!( + locked_tokens2, + &locked_tokens1 - &rust_biguint!(adjustment2_tokens.unsigned_abs()) + ); + assert_eq!(energy2, &energy1 + &rust_biguint!(adjustment2_energy)); + + // Case 3: Negative energy, positive token amount + let adjustment3_energy = -1_500_000i64; + let adjustment3_tokens = 200_000i64; + setup.adjust_user_energy(&user, adjustment3_energy, adjustment3_tokens); + + let locked_tokens3 = setup.get_user_locked_tokens(&user); + let energy3 = setup.get_user_energy(&user); + assert_eq!( + locked_tokens3, + &locked_tokens2 + &rust_biguint!(adjustment3_tokens) + ); + assert_eq!( + energy3, + &energy2 - &rust_biguint!(adjustment3_energy.unsigned_abs()) + ); + + // Case 4: Negative energy, negative token amount + let adjustment4_energy = -700_000i64; + let adjustment4_tokens = -100_000i64; + setup.adjust_user_energy(&user, adjustment4_energy, adjustment4_tokens); + + let locked_tokens4 = setup.get_user_locked_tokens(&user); + let energy4 = setup.get_user_energy(&user); + assert_eq!( + locked_tokens4, + &locked_tokens3 - &rust_biguint!(adjustment4_tokens.unsigned_abs()) + ); + assert_eq!( + energy4, + &energy3 - &rust_biguint!(adjustment4_energy.unsigned_abs()) + ); + + // Bring energy to negative value + let adjustment5_energy = -500_000_000i64; // Adjust to negative energy + let adjustment5_tokens = 0i64; // Positive token amount + setup.adjust_user_energy(&user, adjustment5_energy, adjustment5_tokens); + + let locked_tokens5 = setup.get_user_locked_tokens(&user); + let energy5 = setup.get_user_energy_raw(&user); + assert_eq!( + locked_tokens5, + &locked_tokens4 + &rust_biguint!(adjustment5_tokens) + ); + assert!(energy5 < BigInt::zero()); // Energy should be negative + + // Replay Case 1 on negative energy + let adjustment6_energy = 500_000i64; + let adjustment6_tokens = 200_000i64; + setup.adjust_user_energy(&user, adjustment6_energy, adjustment6_tokens); + + let locked_tokens6 = setup.get_user_locked_tokens(&user); + let energy6 = setup.get_user_energy_raw(&user); + assert_eq!( + locked_tokens6, + &locked_tokens5 + &rust_biguint!(adjustment6_tokens) + ); + assert_eq!( + energy6, + &energy5 + &BigInt::from_i64(adjustment6_energy).unwrap() + ); + assert!(energy6 < BigInt::zero()); // Energy should remain negative + + // Replay Case 2 on negative energy + let adjustment7_energy = 300_000i64; + let adjustment7_tokens = -100_000i64; + setup.adjust_user_energy(&user, adjustment7_energy, adjustment7_tokens); + + let locked_tokens7 = setup.get_user_locked_tokens(&user); + let energy7 = setup.get_user_energy_raw(&user); + assert_eq!( + locked_tokens7, + &locked_tokens6 - &rust_biguint!(adjustment7_tokens.unsigned_abs()) + ); + assert_eq!( + energy7, + &energy6 + &BigInt::from_i64(adjustment7_energy).unwrap() + ); + assert!(energy7 < BigInt::zero()); // Energy should remain negative + + // Replay Case 3 on negative energy + let adjustment8_energy = -500_000i64; + let adjustment8_tokens = 100_000i64; + setup.adjust_user_energy(&user, adjustment8_energy, adjustment8_tokens); + + let locked_tokens8 = setup.get_user_locked_tokens(&user); + let energy8 = setup.get_user_energy_raw(&user); + assert_eq!( + locked_tokens8, + &locked_tokens7 + &rust_biguint!(adjustment8_tokens) + ); + assert_eq!( + energy8, + &energy7 + &BigInt::from_i64(adjustment8_energy).unwrap() + ); + assert!(energy8 < BigInt::zero()); // Energy should remain negative + + // Replay Case 4 on negative energy + let adjustment9_energy = -300_000i64; + let adjustment9_tokens = -50_000i64; + setup.adjust_user_energy(&user, adjustment9_energy, adjustment9_tokens); + + let locked_tokens9 = setup.get_user_locked_tokens(&user); + let energy9 = setup.get_user_energy_raw(&user); + assert_eq!( + locked_tokens9, + &locked_tokens8 - &rust_biguint!(adjustment9_tokens.unsigned_abs()) + ); + assert_eq!( + energy9, + &energy8 + &BigInt::from_i64(adjustment9_energy).unwrap() + ); + assert!(energy9 < BigInt::zero()); // Energy should remain negative +} diff --git a/locked-asset/energy-factory/wasm/Cargo.lock b/locked-asset/energy-factory/wasm/Cargo.lock index b7f42af38..93a271e50 100644 --- a/locked-asset/energy-factory/wasm/Cargo.lock +++ b/locked-asset/energy-factory/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common_errors" @@ -112,32 +112,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -147,9 +149,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -160,18 +162,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -187,27 +189,27 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -241,15 +243,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -262,6 +264,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" diff --git a/locked-asset/energy-factory/wasm/Cargo.toml b/locked-asset/energy-factory/wasm/Cargo.toml index 944055b38..f66b75da6 100644 --- a/locked-asset/energy-factory/wasm/Cargo.toml +++ b/locked-asset/energy-factory/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.energy-factory] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [workspace] members = ["."] diff --git a/locked-asset/energy-factory/wasm/src/lib.rs b/locked-asset/energy-factory/wasm/src/lib.rs index 7393a9e97..181f50f1a 100644 --- a/locked-asset/energy-factory/wasm/src/lib.rs +++ b/locked-asset/energy-factory/wasm/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 +// Upgrade: 1 // Endpoints: 34 // Async Callback: 1 -// Total number of exported functions: 36 +// Total number of exported functions: 37 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); @@ -24,6 +23,7 @@ multiversx_sc_wasm_adapter::endpoints! { lockTokens => lock_tokens_endpoint unlockTokens => unlock_tokens_endpoint extendLockPeriod => extend_lock_period + adjustUserEnergy => adjust_user_energy issueLockedToken => issue_locked_token getLockedTokenId => locked_token getBaseAssetTokenId => base_asset_token_id diff --git a/locked-asset/factory/Cargo.toml b/locked-asset/factory/Cargo.toml deleted file mode 100644 index 6996881d1..000000000 --- a/locked-asset/factory/Cargo.toml +++ /dev/null @@ -1,52 +0,0 @@ -[package] -name = "factory" -publish = false -version = "0.0.0" -edition = "2021" - -[lib] -path = "src/lib.rs" - -[dependencies] -wee_alloc = "0.4" - -[dependencies.common_structs] -path = "../../common/common_structs" - -[dependencies.common_errors] -path = "../../common/common_errors" - -[dependencies.token_send] -path = "../../common/modules/token_send" - -[dependencies.token_merge_helper] -path = "../../common/modules/token_merge_helper" - -[dependencies.energy-factory] -path = "../energy-factory" - -[dependencies.multiversx-sc] -version = "=0.46.1" -features = ["esdt-token-payment-legacy-decode"] - -[dependencies.multiversx-sc-modules] -version = "=0.46.1" - -[dependencies.arrayvec] -version = "0.7.1" -default-features = false - -[dependencies.itertools] -version = "0.10.1" -default-features = false - -[dev-dependencies] -num-bigint = "0.4.2" -num-traits = "0.2" -hex = "0.4" - -[dev-dependencies.simple-lock] -path = "../simple-lock" - -[dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" diff --git a/locked-asset/factory/README.md b/locked-asset/factory/README.md deleted file mode 100644 index d31f3fce1..000000000 --- a/locked-asset/factory/README.md +++ /dev/null @@ -1,92 +0,0 @@ -# Locked Asset Factory Smart Contract - -## Abstract - -This smart contract is the 'father' of all Locked MEX tokens as any contract that needs those tokens, must request them here. - -## Introduction - -This smart contract has the role of creating Locked MEX tokens. The rule is that only one contract per shard can hold the 'create' role for a META esdt, and because many contracts needed to mint/create Locked MEX, this factory was created so it can serve these requests from only one place. - -## Endpoints - -### init - -```rust - #[init] - fn init( - &self, - asset_token_id: TokenIdentifier, - default_unlock_period: MultiValueEncoded, - ); -``` - -The arguments are: - -- __asset_token_id__ - MEX token ID -- __default_unlock_period__ - each Locked MEX has an unlock schedule that is an array of unlock milestones. An unlock milestone is a combination of Unlock Epoch + Unlock Percent. An unlock schedule is created usually using a starting epoch combined with an unlock period. - -### createAndForward - -```rust - #[endpoint(createAndForward)] - fn create_and_forward( - &self, - amount: BigUint, - address: ManagedAddress, - start_epoch: Epoch, - ) -``` - -This is the endpoint called by other smart contracts when in need of creating Locked MEX. The contract will use the arguments and will create and send the __amount__ of Locked MEX to __address__ having the unlock schedule starting at __start_epoch__ with the __default_unlock_period__. - -### unlockAssets - -```rust - #[payable("*")] - #[endpoint(unlockAssets)] - fn unlock_assets( - &self, - #[payment_token] token_id: TokenIdentifier, - #[payment_amount] amount: BigUint, - #[payment_nonce] token_nonce: Nonce, - ); -``` - -This endpoint receives Locked MEX as payment and returns, if possible (if at least one Unlock Milestone was reached), regular Fungible MEX and the leftover Locked MEX, with updated Unlock Milestones. - -### lockAssets - -```rust - #[payable("*")] - #[endpoint(lockAssets)] - fn lock_assets( - &self, - #[payment_token] payment_token: TokenIdentifier, - #[payment_amount] payment_amount: BigUint, - ) -``` - -This endpoint receives MEX tokens as payment and returns Locked MEX tokens. The reason why someone would do this is because Locked MEX is used in different mechanisms where MEX cannot be used. Furthermore, Locking is beneficial to the Ecosystem. - -### mergeLockedAssetTokens - -```rust - #[payable("*")] - #[endpoint(mergeLockedAssetTokens)] - fn merge_locked_asset_tokens(&self) -``` - -The endpoint merges two or more Locked MEX tokens with different nonces together. It handles reconstructing the Unlock Schedule in a fair manner and with high precision. - -## Testing - -This contract has its own test suite in its subdirectory and it is included in most scenarios that include Locked MEX (Proxy SC, Farm SC with Lock and so on). - -## Interaction - -The interaction scripts for this contract are located in the dex subdirectory of the root project directory. - -## Deployment - -The deployment of this contract is done using interaction scripts and it is managed by its admin (regular wallet at the moment, yet soon to be governance smart contract). diff --git a/locked-asset/factory/meta/src/main.rs b/locked-asset/factory/meta/src/main.rs deleted file mode 100644 index db03496aa..000000000 --- a/locked-asset/factory/meta/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - multiversx_sc_meta::cli_main::(); -} diff --git a/locked-asset/factory/tests/factory_setup/mod.rs b/locked-asset/factory/tests/factory_setup/mod.rs deleted file mode 100644 index 633805223..000000000 --- a/locked-asset/factory/tests/factory_setup/mod.rs +++ /dev/null @@ -1,152 +0,0 @@ -#![allow(dead_code)] -#![allow(deprecated)] - -use common_structs::UnlockMilestone; -use energy_factory::SimpleLockEnergy; -use factory::{ - locked_asset::LockedAssetModule, migration::LockedTokenMigrationModule, LockedAssetFactory, -}; -use multiversx_sc::{ - storage::mappers::StorageTokenWrapper, - types::{Address, EsdtLocalRole, MultiValueEncoded}, -}; -use multiversx_sc_scenario::{ - managed_address, managed_token_id, rust_biguint, - whitebox_legacy::{BlockchainStateWrapper, ContractObjWrapper}, - DebugApi, -}; -use simple_lock::locked_token::LockedTokenModule; - -pub const EPOCHS_IN_YEAR: u64 = 360; -pub const EPOCHS_IN_WEEK: u64 = 7; -pub const USER_BALANCE: u64 = 1_000_000_000_000_000_000; - -pub static BASE_ASSET_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, 2 * EPOCHS_IN_YEAR, 4 * EPOCHS_IN_YEAR]; // 1, 2 or 4 years -pub static PENALTY_PERCENTAGES: &[u64] = &[4_000, 6_000, 8_000]; - -pub struct FactorySetup -where - FactoryBuilder: 'static + Copy + Fn() -> factory::ContractObj, - EnergyFactoryBuilder: 'static + Copy + Fn() -> energy_factory::ContractObj, -{ - pub b_mock: BlockchainStateWrapper, - pub owner: Address, - pub first_user: Address, - pub factory_wrapper: ContractObjWrapper, FactoryBuilder>, - pub energy_factory_wrapper: - ContractObjWrapper, EnergyFactoryBuilder>, -} - -impl FactorySetup -where - FactoryBuilder: 'static + Copy + Fn() -> factory::ContractObj, - EnergyFactoryBuilder: 'static + Copy + Fn() -> energy_factory::ContractObj, -{ - pub fn new( - factory_builder: FactoryBuilder, - energy_factory_builder: EnergyFactoryBuilder, - ) -> Self { - DebugApi::dummy(); - let rust_zero = rust_biguint!(0u64); - 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 energy_factory_wrapper = b_mock.create_sc_account( - &rust_zero, - Some(&owner), - energy_factory_builder, - "energy factory", - ); - let factory_wrapper = - b_mock.create_sc_account(&rust_zero, Some(&owner), factory_builder, "factory"); - - b_mock - .execute_tx(&owner, &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!(BASE_ASSET_TOKEN_ID), - managed_token_id!(LEGACY_LOCKED_TOKEN_ID), - managed_address!(factory_wrapper.address_ref()), - 0, - lock_options, - ); - - sc.locked_token() - .set_token_id(managed_token_id!(LOCKED_TOKEN_ID)); - }) - .assert_ok(); - - b_mock - .execute_tx(&owner, &factory_wrapper, &rust_zero, |sc| { - let mut default_unlock_period = MultiValueEncoded::new(); - default_unlock_period.push(UnlockMilestone { - unlock_epoch: 0, - unlock_percent: 100, - }); - - sc.init( - managed_token_id!(BASE_ASSET_TOKEN_ID), - default_unlock_period, - ); - sc.new_factory_address() - .set(managed_address!(energy_factory_wrapper.address_ref())); - sc.locked_asset_token() - .set_token_id(managed_token_id!(LEGACY_LOCKED_TOKEN_ID)); - }) - .assert_ok(); - - // set energy factory roles - b_mock.set_esdt_local_roles( - energy_factory_wrapper.address_ref(), - BASE_ASSET_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], - ); - - // set factory roles - b_mock.set_esdt_local_roles( - factory_wrapper.address_ref(), - BASE_ASSET_TOKEN_ID, - &[EsdtLocalRole::Mint, EsdtLocalRole::Burn], - ); - b_mock.set_esdt_local_roles( - factory_wrapper.address_ref(), - LEGACY_LOCKED_TOKEN_ID, - &[ - EsdtLocalRole::NftCreate, - EsdtLocalRole::NftAddQuantity, - EsdtLocalRole::NftBurn, - EsdtLocalRole::Transfer, - ], - ); - - Self { - b_mock, - owner, - first_user, - factory_wrapper, - energy_factory_wrapper, - } - } -} diff --git a/locked-asset/factory/tests/lock_test.rs b/locked-asset/factory/tests/lock_test.rs deleted file mode 100644 index 556642eef..000000000 --- a/locked-asset/factory/tests/lock_test.rs +++ /dev/null @@ -1,105 +0,0 @@ -#![allow(deprecated)] - -use common_structs::{ - LockedAssetTokenAttributesEx, UnlockMilestone, UnlockMilestoneEx, UnlockScheduleEx, -}; -use multiversx_sc::{ - storage::mappers::StorageTokenWrapper, - types::{EsdtLocalRole, ManagedVec, MultiValueEncoded}, -}; -use multiversx_sc_scenario::{ - managed_biguint, managed_token_id, rust_biguint, whitebox_legacy::*, DebugApi, -}; - -const SC_WASM_PATH: &str = "output/factory.wasm"; - -use factory::{locked_asset::LockedAssetModule, LockedAssetFactory}; -use multiversx_sc_modules::pause::PauseModule; - -const ASSET_TOKEN_ID: &[u8] = b"MEX-123456"; -const LOCKED_ASSET_TOKEN_ID: &[u8] = b"LKMEX-123456"; - -#[test] -fn test_lock_assets() { - let mut blockchain_wrapper = BlockchainStateWrapper::new(); - - let owner_addr = blockchain_wrapper.create_user_account(&rust_biguint!(0)); - let factory = blockchain_wrapper.create_sc_account( - &rust_biguint!(0), - Option::Some(&owner_addr), - factory::contract_obj, - SC_WASM_PATH, - ); - - blockchain_wrapper - .execute_tx(&owner_addr, &factory, &rust_biguint!(0), |sc| { - let asset_token_id = managed_token_id!(ASSET_TOKEN_ID); - let mut unlock_period = MultiValueEncoded::new(); - unlock_period.push(UnlockMilestone { - unlock_epoch: 1, - unlock_percent: 100, - }); - sc.init(asset_token_id, unlock_period); - sc.locked_asset_token() - .set_token_id(managed_token_id!(LOCKED_ASSET_TOKEN_ID)); - sc.set_paused(false); - }) - .assert_ok(); - - let asset_token_roles = [EsdtLocalRole::Burn]; - let locked_asset_token_roles = [ - EsdtLocalRole::NftCreate, - EsdtLocalRole::NftAddQuantity, - EsdtLocalRole::NftBurn, - ]; - - blockchain_wrapper.set_esdt_local_roles( - factory.address_ref(), - ASSET_TOKEN_ID, - &asset_token_roles[..], - ); - blockchain_wrapper.set_esdt_local_roles( - factory.address_ref(), - LOCKED_ASSET_TOKEN_ID, - &locked_asset_token_roles[..], - ); - - let mut locked_assets_nonce = 0; - - blockchain_wrapper.set_esdt_balance(&owner_addr, ASSET_TOKEN_ID, &rust_biguint!(2000)); - - blockchain_wrapper - .execute_esdt_transfer( - &owner_addr, - &factory, - ASSET_TOKEN_ID, - 0, - &rust_biguint!(1000), - |sc| { - let locked_assets = sc.lock_assets(); - locked_assets_nonce = locked_assets.token_nonce; - assert_eq!(locked_assets.amount, managed_biguint!(1000)); - }, - ) - .assert_ok(); - - blockchain_wrapper.execute_in_managed_environment(|| { - let expected_attributes = LockedAssetTokenAttributesEx:: { - unlock_schedule: UnlockScheduleEx { - unlock_milestones: ManagedVec::from(vec![UnlockMilestoneEx { - unlock_epoch: 1, - unlock_percent: 100_000, - }]), - }, - is_merged: false, - }; - - blockchain_wrapper.check_nft_balance( - &owner_addr, - LOCKED_ASSET_TOKEN_ID, - locked_assets_nonce, - &rust_biguint!(1000), - Some(&expected_attributes), - ); - }); -} diff --git a/locked-asset/factory/tests/unlock_test.rs b/locked-asset/factory/tests/unlock_test.rs deleted file mode 100644 index 057cf409c..000000000 --- a/locked-asset/factory/tests/unlock_test.rs +++ /dev/null @@ -1,941 +0,0 @@ -#![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_legacy::*, DebugApi, -}; - -const SC_WASM_PATH: &str = "output/factory.wasm"; - -use energy_factory::energy::{Energy, EnergyModule}; -use energy_factory::migration::SimpleLockMigrationModule; -use factory::locked_asset_token_merge::*; -use factory::{locked_asset::*, LockedAssetFactory}; -use factory_setup::*; -use multiversx_sc_modules::pause::PauseModule; - -mod factory_setup; - -#[test] -fn test_unlock_100mil_1mil() { - let mut blockchain_wrapper = BlockchainStateWrapper::new(); - let factory = blockchain_wrapper.create_sc_account( - &rust_biguint!(0), - None, - factory::contract_obj, - SC_WASM_PATH, - ); - - blockchain_wrapper - .execute_query(&factory, |sc| { - let mut tokens = ManagedVec::new(); - let token1 = LockedTokenEx:: { - token_amount: EsdtTokenPayment { - token_identifier: TokenIdentifier::from_esdt_bytes(&[]), //placeholder - token_nonce: 0, //placeholder - amount: managed_biguint!(100_000_000), - }, - attributes: LockedAssetTokenAttributesEx { - unlock_schedule: UnlockScheduleEx { - unlock_milestones: ManagedVec::from(vec![ - UnlockMilestoneEx { - unlock_epoch: 0, - unlock_percent: 10_000, - }, - UnlockMilestoneEx { - unlock_epoch: 360, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 390, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 420, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 450, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 480, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 510, - unlock_percent: 15_000, - }, - ]), - }, - is_merged: false, - }, - }; - let token2 = LockedTokenEx:: { - token_amount: EsdtTokenPayment { - token_identifier: TokenIdentifier::from_esdt_bytes(&[]), //placeholder - token_nonce: 0, //placeholder - amount: managed_biguint!(1_000_000), - }, - attributes: LockedAssetTokenAttributesEx { - unlock_schedule: UnlockScheduleEx { - unlock_milestones: ManagedVec::from(vec![ - UnlockMilestoneEx { - unlock_epoch: 360, - unlock_percent: 16_000, - }, - UnlockMilestoneEx { - unlock_epoch: 390, - unlock_percent: 16_000, - }, - UnlockMilestoneEx { - unlock_epoch: 420, - unlock_percent: 17_000, - }, - UnlockMilestoneEx { - unlock_epoch: 450, - unlock_percent: 17_000, - }, - UnlockMilestoneEx { - unlock_epoch: 480, - unlock_percent: 17_000, - }, - UnlockMilestoneEx { - unlock_epoch: 510, - unlock_percent: 17_000, - }, - ]), - }, - is_merged: false, - }, - }; - - tokens.push(token1); - tokens.push(token2); - - let result = sc.aggregated_unlock_schedule(&tokens); - let result = result.unlock_milestones; - - let el = result.get(0); - assert_eq!(el.unlock_epoch, 0); - assert_eq!(el.unlock_percent, 9_901); - - let el = result.get(1); - assert_eq!(el.unlock_epoch, 360); - assert_eq!(el.unlock_percent, 15_010); - - let el = result.get(2); - assert_eq!(el.unlock_epoch, 390); - assert_eq!(el.unlock_percent, 15_010); - - let el = result.get(3); - assert_eq!(el.unlock_epoch, 420); - assert_eq!(el.unlock_percent, 15_019); - - let el = result.get(4); - assert_eq!(el.unlock_epoch, 450); - assert_eq!(el.unlock_percent, 15_020); - - let el = result.get(5); - assert_eq!(el.unlock_epoch, 480); - assert_eq!(el.unlock_percent, 15_020); - - let el = result.get(6); - assert_eq!(el.unlock_epoch, 510); - assert_eq!(el.unlock_percent, 15_020); - }) - .assert_ok(); -} - -#[test] -fn test_unlock_1mil_100mil() { - let mut blockchain_wrapper = BlockchainStateWrapper::new(); - let factory = blockchain_wrapper.create_sc_account( - &rust_biguint!(0), - None, - factory::contract_obj, - SC_WASM_PATH, - ); - - blockchain_wrapper - .execute_query(&factory, |sc| { - let mut tokens = ManagedVec::new(); - let token1 = LockedTokenEx:: { - token_amount: EsdtTokenPayment { - token_identifier: TokenIdentifier::from_esdt_bytes(&[]), //placeholder - token_nonce: 0, //placeholder - amount: managed_biguint!(1_000_000), - }, - attributes: LockedAssetTokenAttributesEx { - unlock_schedule: UnlockScheduleEx { - unlock_milestones: ManagedVec::from(vec![ - UnlockMilestoneEx { - unlock_epoch: 0, - unlock_percent: 10_000, - }, - UnlockMilestoneEx { - unlock_epoch: 360, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 390, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 420, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 450, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 480, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 510, - unlock_percent: 15_000, - }, - ]), - }, - is_merged: false, - }, - }; - let token2 = LockedTokenEx:: { - token_amount: EsdtTokenPayment { - token_identifier: TokenIdentifier::from_esdt_bytes(&[]), //placeholder - token_nonce: 0, //placeholder - amount: managed_biguint!(100_000_000), - }, - attributes: LockedAssetTokenAttributesEx { - unlock_schedule: UnlockScheduleEx { - unlock_milestones: ManagedVec::from(vec![ - UnlockMilestoneEx { - unlock_epoch: 360, - unlock_percent: 16_000, - }, - UnlockMilestoneEx { - unlock_epoch: 390, - unlock_percent: 16_000, - }, - UnlockMilestoneEx { - unlock_epoch: 420, - unlock_percent: 17_000, - }, - UnlockMilestoneEx { - unlock_epoch: 450, - unlock_percent: 17_000, - }, - UnlockMilestoneEx { - unlock_epoch: 480, - unlock_percent: 17_000, - }, - UnlockMilestoneEx { - unlock_epoch: 510, - unlock_percent: 17_000, - }, - ]), - }, - is_merged: false, - }, - }; - - tokens.push(token1); - tokens.push(token2); - - let result = sc.aggregated_unlock_schedule(&tokens); - let result = result.unlock_milestones; - - let el = result.get(0); - assert_eq!(el.unlock_epoch, 0); - assert_eq!(el.unlock_percent, 99); - - let el = result.get(1); - assert_eq!(el.unlock_epoch, 360); - assert_eq!(el.unlock_percent, 15_990); - - let el = result.get(2); - assert_eq!(el.unlock_epoch, 390); - assert_eq!(el.unlock_percent, 15_990); - - let el = result.get(3); - assert_eq!(el.unlock_epoch, 420); - assert_eq!(el.unlock_percent, 16_980); - - let el = result.get(4); - assert_eq!(el.unlock_epoch, 450); - assert_eq!(el.unlock_percent, 16_980); - - let el = result.get(5); - assert_eq!(el.unlock_epoch, 480); - assert_eq!(el.unlock_percent, 16_980); - - let el = result.get(6); - assert_eq!(el.unlock_epoch, 510); - assert_eq!(el.unlock_percent, 16981); - }) - .assert_ok(); -} - -#[test] -fn test_unlock_60_40() { - let mut blockchain_wrapper = BlockchainStateWrapper::new(); - let factory = blockchain_wrapper.create_sc_account( - &rust_biguint!(0), - None, - factory::contract_obj, - SC_WASM_PATH, - ); - - blockchain_wrapper - .execute_query(&factory, |sc| { - let mut tokens = ManagedVec::new(); - let token1 = LockedTokenEx:: { - token_amount: EsdtTokenPayment { - token_identifier: TokenIdentifier::from_esdt_bytes(&[]), //placeholder - token_nonce: 0, //placeholder - amount: managed_biguint!(60_000), - }, - attributes: LockedAssetTokenAttributesEx { - unlock_schedule: UnlockScheduleEx { - unlock_milestones: ManagedVec::from(vec![ - UnlockMilestoneEx { - unlock_epoch: 0, - unlock_percent: 10_000, - }, - UnlockMilestoneEx { - unlock_epoch: 360, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 390, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 420, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 450, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 480, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 510, - unlock_percent: 15_000, - }, - ]), - }, - is_merged: false, - }, - }; - let token2 = LockedTokenEx:: { - token_amount: EsdtTokenPayment { - token_identifier: TokenIdentifier::from_esdt_bytes(&[]), //placeholder - token_nonce: 0, //placeholder - amount: managed_biguint!(40_000), - }, - attributes: LockedAssetTokenAttributesEx { - unlock_schedule: UnlockScheduleEx { - unlock_milestones: ManagedVec::from(vec![ - UnlockMilestoneEx { - unlock_epoch: 360, - unlock_percent: 16_000, - }, - UnlockMilestoneEx { - unlock_epoch: 390, - unlock_percent: 16_000, - }, - UnlockMilestoneEx { - unlock_epoch: 420, - unlock_percent: 17_000, - }, - UnlockMilestoneEx { - unlock_epoch: 450, - unlock_percent: 17_000, - }, - UnlockMilestoneEx { - unlock_epoch: 480, - unlock_percent: 17_000, - }, - UnlockMilestoneEx { - unlock_epoch: 510, - unlock_percent: 17_000, - }, - ]), - }, - is_merged: false, - }, - }; - - tokens.push(token1); - tokens.push(token2); - - let result = sc.aggregated_unlock_schedule(&tokens); - let result = result.unlock_milestones; - - let el = result.get(0); - assert_eq!(el.unlock_epoch, 0); - assert_eq!(el.unlock_percent, 6_000); - - let el = result.get(1); - assert_eq!(el.unlock_epoch, 360); - assert_eq!(el.unlock_percent, 15_400); - - let el = result.get(2); - assert_eq!(el.unlock_epoch, 390); - assert_eq!(el.unlock_percent, 15_400); - - let el = result.get(3); - assert_eq!(el.unlock_epoch, 420); - assert_eq!(el.unlock_percent, 15_800); - - let el = result.get(4); - assert_eq!(el.unlock_epoch, 450); - assert_eq!(el.unlock_percent, 15_800); - - let el = result.get(5); - assert_eq!(el.unlock_epoch, 480); - assert_eq!(el.unlock_percent, 15_800); - - let el = result.get(6); - assert_eq!(el.unlock_epoch, 510); - assert_eq!(el.unlock_percent, 15_800); - }) - .assert_ok(); -} - -#[test] -fn test_unlock_40_60() { - let mut blockchain_wrapper = BlockchainStateWrapper::new(); - let factory = blockchain_wrapper.create_sc_account( - &rust_biguint!(0), - None, - factory::contract_obj, - SC_WASM_PATH, - ); - - blockchain_wrapper - .execute_query(&factory, |sc| { - let mut tokens = ManagedVec::new(); - let token1 = LockedTokenEx:: { - token_amount: EsdtTokenPayment { - token_identifier: TokenIdentifier::from_esdt_bytes(&[]), //placeholder - token_nonce: 0, //placeholder - amount: managed_biguint!(40_000), - }, - attributes: LockedAssetTokenAttributesEx { - unlock_schedule: UnlockScheduleEx { - unlock_milestones: ManagedVec::from(vec![ - UnlockMilestoneEx { - unlock_epoch: 0, - unlock_percent: 10_000, - }, - UnlockMilestoneEx { - unlock_epoch: 360, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 390, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 420, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 450, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 480, - unlock_percent: 15_000, - }, - UnlockMilestoneEx { - unlock_epoch: 510, - unlock_percent: 15_000, - }, - ]), - }, - is_merged: false, - }, - }; - let token2 = LockedTokenEx:: { - token_amount: EsdtTokenPayment { - token_identifier: TokenIdentifier::from_esdt_bytes(&[]), //placeholder - token_nonce: 0, //placeholder - amount: managed_biguint!(60_000), - }, - attributes: LockedAssetTokenAttributesEx { - unlock_schedule: UnlockScheduleEx { - unlock_milestones: ManagedVec::from(vec![ - UnlockMilestoneEx { - unlock_epoch: 360, - unlock_percent: 16_000, - }, - UnlockMilestoneEx { - unlock_epoch: 390, - unlock_percent: 16_000, - }, - UnlockMilestoneEx { - unlock_epoch: 420, - unlock_percent: 17_000, - }, - UnlockMilestoneEx { - unlock_epoch: 450, - unlock_percent: 17_000, - }, - UnlockMilestoneEx { - unlock_epoch: 480, - unlock_percent: 17_000, - }, - UnlockMilestoneEx { - unlock_epoch: 510, - unlock_percent: 17_000, - }, - ]), - }, - is_merged: false, - }, - }; - - tokens.push(token1); - tokens.push(token2); - - let result = sc.aggregated_unlock_schedule(&tokens); - let result = result.unlock_milestones; - - let el = result.get(0); - assert_eq!(el.unlock_epoch, 0); - assert_eq!(el.unlock_percent, 4_000); - - let el = result.get(1); - assert_eq!(el.unlock_epoch, 360); - assert_eq!(el.unlock_percent, 15_600); - - let el = result.get(2); - assert_eq!(el.unlock_epoch, 390); - assert_eq!(el.unlock_percent, 15_600); - - let el = result.get(3); - assert_eq!(el.unlock_epoch, 420); - assert_eq!(el.unlock_percent, 16_200); - - let el = result.get(4); - assert_eq!(el.unlock_epoch, 450); - assert_eq!(el.unlock_percent, 16_200); - - let el = result.get(5); - assert_eq!(el.unlock_epoch, 480); - assert_eq!(el.unlock_percent, 16_200); - - let el = result.get(6); - assert_eq!(el.unlock_epoch, 510); - assert_eq!(el.unlock_percent, 16_200); - }) - .assert_ok(); -} - -#[test] -fn test_aggregated_unlock_schedule() { - let mut blockchain_wrapper = BlockchainStateWrapper::new(); - let factory = blockchain_wrapper.create_sc_account( - &rust_biguint!(0), - None, - factory::contract_obj, - SC_WASM_PATH, - ); - - blockchain_wrapper - .execute_query(&factory, |sc| { - let mut tokens = ManagedVec::new(); - let token1 = LockedTokenEx:: { - token_amount: EsdtTokenPayment { - token_identifier: TokenIdentifier::from_esdt_bytes(&[]), //placeholder - token_nonce: 0, //placeholder - amount: managed_biguint!(608_212_266_882_971_044), - }, - attributes: LockedAssetTokenAttributesEx { - unlock_schedule: UnlockScheduleEx { - unlock_milestones: ManagedVec::from(vec![ - UnlockMilestoneEx { - unlock_epoch: 468, - unlock_percent: 14_00, - }, - UnlockMilestoneEx { - unlock_epoch: 348, - unlock_percent: 14_00, - }, - UnlockMilestoneEx { - unlock_epoch: 408, - unlock_percent: 14_00, - }, - UnlockMilestoneEx { - unlock_epoch: 318, - unlock_percent: 14_00, - }, - UnlockMilestoneEx { - unlock_epoch: 0, - unlock_percent: 16_00, - }, - UnlockMilestoneEx { - unlock_epoch: 378, - unlock_percent: 14_00, - }, - UnlockMilestoneEx { - unlock_epoch: 438, - unlock_percent: 14_00, - }, - ]), - }, - is_merged: false, - }, - }; - let token2 = LockedTokenEx:: { - token_amount: EsdtTokenPayment { - token_identifier: TokenIdentifier::from_esdt_bytes(&[]), //placeholder - token_nonce: 0, //placeholder - amount: managed_biguint!(700_000_000_000_000_000), - }, - attributes: LockedAssetTokenAttributesEx { - unlock_schedule: UnlockScheduleEx { - unlock_milestones: ManagedVec::from(vec![ - UnlockMilestoneEx { - unlock_epoch: 378, - unlock_percent: 17_00, - }, - UnlockMilestoneEx { - unlock_epoch: 408, - unlock_percent: 17_00, - }, - UnlockMilestoneEx { - unlock_epoch: 438, - unlock_percent: 17_00, - }, - UnlockMilestoneEx { - unlock_epoch: 468, - unlock_percent: 16_00, - }, - UnlockMilestoneEx { - unlock_epoch: 498, - unlock_percent: 16_00, - }, - UnlockMilestoneEx { - unlock_epoch: 528, - unlock_percent: 16_00, - }, - ]), - }, - is_merged: false, - }, - }; - - tokens.push(token1); - tokens.push(token2); - - let result = sc.aggregated_unlock_schedule(&tokens); - let result = result.unlock_milestones; - - // if de-duplication fails, there will be 13 results (9 unique + 4 duplicates) - assert_eq!(result.len(), 9); - }) - .assert_ok(); -} - -#[test] -fn test_aggregated_unlock_schedule_with_1_offset() { - let mut blockchain_wrapper = BlockchainStateWrapper::new(); - let factory = blockchain_wrapper.create_sc_account( - &rust_biguint!(0), - None, - factory::contract_obj, - SC_WASM_PATH, - ); - - blockchain_wrapper - .execute_query(&factory, |sc| { - let mut tokens = ManagedVec::new(); - let token1 = LockedTokenEx:: { - token_amount: EsdtTokenPayment { - token_identifier: TokenIdentifier::from_esdt_bytes(&[]), //placeholder - token_nonce: 0, //placeholder - amount: managed_biguint!(608_212_266_882_971_044), - }, - attributes: LockedAssetTokenAttributesEx { - unlock_schedule: UnlockScheduleEx { - unlock_milestones: ManagedVec::from(vec![ - UnlockMilestoneEx { - unlock_epoch: 468, - unlock_percent: 14_00, - }, - UnlockMilestoneEx { - unlock_epoch: 348, - unlock_percent: 14_00, - }, - UnlockMilestoneEx { - unlock_epoch: 408, - unlock_percent: 14_00, - }, - UnlockMilestoneEx { - unlock_epoch: 318, - unlock_percent: 14_00, - }, - UnlockMilestoneEx { - unlock_epoch: 0, - unlock_percent: 16_00, - }, - UnlockMilestoneEx { - unlock_epoch: 378, - unlock_percent: 14_00, - }, - UnlockMilestoneEx { - unlock_epoch: 438, - unlock_percent: 14_00, - }, - ]), - }, - is_merged: false, - }, - }; - let token2 = LockedTokenEx:: { - token_amount: EsdtTokenPayment { - token_identifier: TokenIdentifier::from_esdt_bytes(&[]), //placeholder - token_nonce: 0, //placeholder - amount: managed_biguint!(700_000_000_000_000_000), - }, - attributes: LockedAssetTokenAttributesEx { - unlock_schedule: UnlockScheduleEx { - unlock_milestones: ManagedVec::from(vec![ - UnlockMilestoneEx { - unlock_epoch: 378 + 1, //Notice the +1 - unlock_percent: 17_00, - }, - UnlockMilestoneEx { - unlock_epoch: 408 + 1, //Notice the +1 - unlock_percent: 17_00, - }, - UnlockMilestoneEx { - unlock_epoch: 438 + 1, //Notice the +1 - unlock_percent: 17_00, - }, - UnlockMilestoneEx { - unlock_epoch: 468, - unlock_percent: 16_00, - }, - UnlockMilestoneEx { - unlock_epoch: 498, - unlock_percent: 16_00, - }, - UnlockMilestoneEx { - unlock_epoch: 528, - unlock_percent: 16_00, - }, - ]), - }, - is_merged: false, - }, - }; - - tokens.push(token1); - tokens.push(token2); - - let result = sc.aggregated_unlock_schedule(&tokens); - let result = result.unlock_milestones; - - //In the end, the milestones with {$epoch, and ($epoch + 1)} should be placed under ($epoch + 1). - - assert_eq!(result.len(), 9); - - let el = result.get(0); - assert_eq!(el.unlock_epoch, 0); - - let el = result.get(1); - assert_eq!(el.unlock_epoch, 318); - - let el = result.get(2); - assert_eq!(el.unlock_epoch, 348); - - let el = result.get(3); - assert_eq!(el.unlock_epoch, 378 + 1); - - let el = result.get(4); - assert_eq!(el.unlock_epoch, 408 + 1); - - let el = result.get(5); - assert_eq!(el.unlock_epoch, 438 + 1); - }) - .assert_ok(); -} - -#[test] -fn update_energy_after_old_token_unlock_test() { - DebugApi::dummy(); - let rust_zero = rust_biguint!(0); - let mut setup = FactorySetup::new(factory::contract_obj, energy_factory::contract_obj); - - let mut current_epoch = 1_441; - setup.b_mock.set_block_epoch(current_epoch); - - let first_unlock_epoch = 1_531; - let second_unlock_epoch = 1_621; - let third_unlock_epoch = 1_711; - let forth_unlock_epoch = 1_801; - let mut unlock_milestones = ManagedVec::::new(); - unlock_milestones.push(UnlockMilestoneEx { - unlock_percent: 20_000, - unlock_epoch: first_unlock_epoch, - }); - unlock_milestones.push(UnlockMilestoneEx { - unlock_percent: 20_000, - unlock_epoch: second_unlock_epoch, - }); - unlock_milestones.push(UnlockMilestoneEx { - unlock_percent: 20_000, - unlock_epoch: third_unlock_epoch, - }); - unlock_milestones.push(UnlockMilestoneEx { - unlock_percent: 40_000, - unlock_epoch: forth_unlock_epoch, - }); - let old_token_attributes = LockedAssetTokenAttributesEx { - is_merged: false, - unlock_schedule: UnlockScheduleEx { unlock_milestones }, - }; - - let first_user = setup.first_user.clone(); - setup.b_mock.set_nft_balance( - &first_user, - LEGACY_LOCKED_TOKEN_ID, - 3, // higher random nonce to avoid nonce caching conflicts - &rust_biguint!(USER_BALANCE), - &old_token_attributes, - ); - - 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 += - managed_biguint!(20_000) * USER_BALANCE * (second_unlock_epoch - current_epoch) - / 100_000u32; - user_energy_amount += - managed_biguint!(20_000) * USER_BALANCE * (third_unlock_epoch - current_epoch) / 100_000u32; - 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( - &first_user, - &setup.energy_factory_wrapper, - &rust_zero, - |sc| { - sc.set_paused(true); - - let mut users_energy = MultiValueEncoded::new(); - let user_energy = ( - managed_address!(&first_user), - managed_biguint!(USER_BALANCE), - 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_signed_bytes_be(&expected_energy_vec), - 1441, - managed_biguint!(USER_BALANCE), - ); - let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); - assert_eq!(expected_energy, actual_energy); - sc.set_paused(false); - }, - ) - .assert_ok(); - - current_epoch = 1_650; - setup.b_mock.set_block_epoch(current_epoch); - - setup - .b_mock - .execute_esdt_transfer( - &first_user, - &setup.factory_wrapper, - LEGACY_LOCKED_TOKEN_ID, - 3, - &rust_biguint!(USER_BALANCE), - |sc| { - sc.set_paused(false); - sc.unlock_assets(); - }, - ) - .assert_ok(); - - // check user balance after unlocking the first two milestones - let unlock_amount = USER_BALANCE / 100_000 * 20_000 + USER_BALANCE / 100_000 * 20_000; - let remaining_locked_token_balace = USER_BALANCE - unlock_amount; - - setup.b_mock.check_esdt_balance( - &first_user, - BASE_ASSET_TOKEN_ID, - &rust_biguint!(unlock_amount), - ); - - let mut new_unlock_milestones = ManagedVec::::new(); - new_unlock_milestones.push(UnlockMilestoneEx { - unlock_percent: 33_333, - unlock_epoch: third_unlock_epoch, - }); - new_unlock_milestones.push(UnlockMilestoneEx { - unlock_percent: 66_667, - unlock_epoch: forth_unlock_epoch, - }); - let new_locked_token_attributes = LockedAssetTokenAttributesEx { - is_merged: false, - unlock_schedule: UnlockScheduleEx { - unlock_milestones: new_unlock_milestones, - }, - }; - - setup.b_mock.check_nft_balance( - &first_user, - LEGACY_LOCKED_TOKEN_ID, - 1, // new generated nonce (different from the initial randomly allocated nonce) - &rust_biguint!(remaining_locked_token_balace), - Some(&new_locked_token_attributes), - ); - - 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) - / 100_000u32; - final_user_energy_amount += managed_biguint!(66_667) - * remaining_locked_token_balace - * (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_signed_bytes_be(&final_amount_vec), - current_epoch, - managed_biguint!(remaining_locked_token_balace), - ); - let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); - assert_eq!(expected_energy, actual_energy); - }) - .assert_ok(); -} diff --git a/locked-asset/lkmex-transfer/Cargo.toml b/locked-asset/lkmex-transfer/Cargo.toml index a6fb9ca95..9ba8540ae 100644 --- a/locked-asset/lkmex-transfer/Cargo.toml +++ b/locked-asset/lkmex-transfer/Cargo.toml @@ -30,14 +30,14 @@ path = "../energy-factory" path = "../../energy-integration/common-modules/energy-query" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" [dev-dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" diff --git a/locked-asset/lkmex-transfer/meta/Cargo.toml b/locked-asset/lkmex-transfer/meta/Cargo.toml index e0c0588d1..c288344c0 100644 --- a/locked-asset/lkmex-transfer/meta/Cargo.toml +++ b/locked-asset/lkmex-transfer/meta/Cargo.toml @@ -8,6 +8,6 @@ publish = false [dependencies.lkmex-transfer] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/locked-asset/lkmex-transfer/meta/src/main.rs b/locked-asset/lkmex-transfer/meta/src/main.rs index d5cc7ad21..bc5614448 100644 --- a/locked-asset/lkmex-transfer/meta/src/main.rs +++ b/locked-asset/lkmex-transfer/meta/src/main.rs @@ -1,3 +1,3 @@ fn main() { - multiversx_sc_meta::cli_main::(); + multiversx_sc_meta_lib::cli_main::(); } diff --git a/locked-asset/lkmex-transfer/src/lib.rs b/locked-asset/lkmex-transfer/src/lib.rs index 7c187882e..126e740b8 100644 --- a/locked-asset/lkmex-transfer/src/lib.rs +++ b/locked-asset/lkmex-transfer/src/lib.rs @@ -56,7 +56,7 @@ pub trait LkmexTransfer: self.add_permissions(caller, Permissions::OWNER); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[endpoint] diff --git a/locked-asset/lkmex-transfer/wasm/Cargo.lock b/locked-asset/lkmex-transfer/wasm/Cargo.lock index 503d067d7..d269860db 100644 --- a/locked-asset/lkmex-transfer/wasm/Cargo.lock +++ b/locked-asset/lkmex-transfer/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common_errors" @@ -134,32 +134,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -169,9 +171,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -182,18 +184,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -209,9 +211,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -227,18 +229,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -272,15 +274,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -293,6 +295,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" diff --git a/locked-asset/lkmex-transfer/wasm/Cargo.toml b/locked-asset/lkmex-transfer/wasm/Cargo.toml index dee74ceae..f77ddab32 100644 --- a/locked-asset/lkmex-transfer/wasm/Cargo.toml +++ b/locked-asset/lkmex-transfer/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.lkmex-transfer] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [workspace] members = ["."] diff --git a/locked-asset/lkmex-transfer/wasm/src/lib.rs b/locked-asset/lkmex-transfer/wasm/src/lib.rs index 6df953b3e..24d976e2b 100644 --- a/locked-asset/lkmex-transfer/wasm/src/lib.rs +++ b/locked-asset/lkmex-transfer/wasm/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 12 +// Upgrade: 1 +// Endpoints: 11 // Async Callback (empty): 1 // Total number of exported functions: 14 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); diff --git a/locked-asset/locked-token-wrapper/Cargo.toml b/locked-asset/locked-token-wrapper/Cargo.toml index 787914eeb..b89fc108b 100644 --- a/locked-asset/locked-token-wrapper/Cargo.toml +++ b/locked-asset/locked-token-wrapper/Cargo.toml @@ -9,10 +9,10 @@ publish = false path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" [dependencies.utils] path = "../../common/modules/utils" @@ -44,4 +44,4 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" diff --git a/locked-asset/locked-token-wrapper/meta/Cargo.toml b/locked-asset/locked-token-wrapper/meta/Cargo.toml index 6de0a4093..987c0f65d 100644 --- a/locked-asset/locked-token-wrapper/meta/Cargo.toml +++ b/locked-asset/locked-token-wrapper/meta/Cargo.toml @@ -10,6 +10,6 @@ authors = ["MultiversX "] [dependencies.locked-token-wrapper] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/locked-asset/locked-token-wrapper/meta/src/main.rs b/locked-asset/locked-token-wrapper/meta/src/main.rs index fb820b88e..fe7de3557 100644 --- a/locked-asset/locked-token-wrapper/meta/src/main.rs +++ b/locked-asset/locked-token-wrapper/meta/src/main.rs @@ -1,3 +1,3 @@ fn main() { - multiversx_sc_meta::cli_main::(); + multiversx_sc_meta_lib::cli_main::(); } diff --git a/locked-asset/locked-token-wrapper/src/lib.rs b/locked-asset/locked-token-wrapper/src/lib.rs index 980736f63..0724260e6 100644 --- a/locked-asset/locked-token-wrapper/src/lib.rs +++ b/locked-asset/locked-token-wrapper/src/lib.rs @@ -1,4 +1,5 @@ #![no_std] +#![allow(deprecated)] multiversx_sc::imports!(); @@ -20,7 +21,7 @@ pub trait LockedTokenWrapper: self.energy_factory_address().set(&energy_factory_address); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[payable("*")] @@ -44,11 +45,6 @@ pub trait LockedTokenWrapper: #[endpoint(unwrapLockedToken)] fn unwrap_locked_token_endpoint(&self) -> EsdtTokenPayment { let caller = self.blockchain().get_caller(); - require!( - !self.blockchain().is_smart_contract(&caller), - "SCs cannot unwrap locked tokens" - ); - let payment = self.call_value().single_esdt(); let locked_token_id = self.get_locked_token_id(); let original_locked_tokens = self.unwrap_locked_token(locked_token_id, payment); diff --git a/locked-asset/locked-token-wrapper/wasm/Cargo.lock b/locked-asset/locked-token-wrapper/wasm/Cargo.lock index eb6ca7c6e..98b8ba9bc 100644 --- a/locked-asset/locked-token-wrapper/wasm/Cargo.lock +++ b/locked-asset/locked-token-wrapper/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common_errors" @@ -158,32 +158,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -193,9 +195,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -206,18 +208,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -233,9 +235,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -251,18 +253,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -296,15 +298,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -317,6 +319,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" diff --git a/locked-asset/locked-token-wrapper/wasm/Cargo.toml b/locked-asset/locked-token-wrapper/wasm/Cargo.toml index 0d10a2666..32d3b3f11 100644 --- a/locked-asset/locked-token-wrapper/wasm/Cargo.toml +++ b/locked-asset/locked-token-wrapper/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.locked-token-wrapper] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [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 6c59af09c..97c8b9704 100644 --- a/locked-asset/locked-token-wrapper/wasm/src/lib.rs +++ b/locked-asset/locked-token-wrapper/wasm/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 9 +// Upgrade: 1 +// Endpoints: 8 // Async Callback: 1 // Total number of exported functions: 11 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); diff --git a/locked-asset/proxy_dex/Cargo.toml b/locked-asset/proxy_dex/Cargo.toml index 5c52745d9..e5023a79d 100644 --- a/locked-asset/proxy_dex/Cargo.toml +++ b/locked-asset/proxy_dex/Cargo.toml @@ -45,11 +45,11 @@ path = "../../common/traits/mergeable" path = "../../common/traits/fixed-supply-token" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" [dependencies.energy-factory] path = "../energy-factory" @@ -69,7 +69,7 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" [dev-dependencies.pausable] path = "../../common/modules/pausable" diff --git a/locked-asset/proxy_dex/meta/Cargo.toml b/locked-asset/proxy_dex/meta/Cargo.toml index 41fea1fc8..6ceff01ef 100644 --- a/locked-asset/proxy_dex/meta/Cargo.toml +++ b/locked-asset/proxy_dex/meta/Cargo.toml @@ -8,6 +8,6 @@ publish = false [dependencies.proxy_dex] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/locked-asset/proxy_dex/meta/src/main.rs b/locked-asset/proxy_dex/meta/src/main.rs index a07d23de1..528567935 100644 --- a/locked-asset/proxy_dex/meta/src/main.rs +++ b/locked-asset/proxy_dex/meta/src/main.rs @@ -1,3 +1,3 @@ fn main() { - multiversx_sc_meta::cli_main::(); + multiversx_sc_meta_lib::cli_main::(); } diff --git a/locked-asset/proxy_dex/src/external_merging.rs b/locked-asset/proxy_dex/src/external_merging.rs index 30ef3eb88..6d1428411 100644 --- a/locked-asset/proxy_dex/src/external_merging.rs +++ b/locked-asset/proxy_dex/src/external_merging.rs @@ -1,3 +1,5 @@ +#![allow(deprecated)] + multiversx_sc::imports!(); use common_structs::PaymentsVec; diff --git a/locked-asset/proxy_dex/src/farm_interactions.rs b/locked-asset/proxy_dex/src/farm_interactions.rs index dab9a7825..cabd55f8d 100644 --- a/locked-asset/proxy_dex/src/farm_interactions.rs +++ b/locked-asset/proxy_dex/src/farm_interactions.rs @@ -27,7 +27,7 @@ pub trait FarmInteractionsModule { ) -> EnterFarmResultWrapper { let enter_farm_result: EnterFarmResultType = self .farm_contract_proxy(farm_address) - .enter_farm_endpoint(user) + .enter_farm_endpoint(OptionalValue::Some(user)) .with_esdt_transfer((farming_token_id, 0, farming_token_amount)) .execute_on_dest_context(); @@ -47,7 +47,7 @@ pub trait FarmInteractionsModule { ) -> ExitFarmResultWrapper { let raw_result: ExitFarmWithPartialPosResultType = self .farm_contract_proxy(farm_address) - .exit_farm_endpoint(user) + .exit_farm_endpoint(OptionalValue::Some(user)) .with_esdt_transfer(farm_token) .execute_on_dest_context(); let (farming_tokens, reward_tokens) = raw_result.into_tuple(); @@ -66,7 +66,7 @@ pub trait FarmInteractionsModule { ) -> ClaimRewardsResultWrapper { let raw_result: ClaimRewardsResultType = self .farm_contract_proxy(farm_address) - .claim_rewards_endpoint(user) + .claim_rewards_endpoint(OptionalValue::Some(user)) .with_esdt_transfer(farm_token) .execute_on_dest_context(); let (new_farm_token, rewards) = raw_result.into_tuple(); diff --git a/locked-asset/proxy_dex/src/lib.rs b/locked-asset/proxy_dex/src/lib.rs index 810cd3640..047b087e8 100644 --- a/locked-asset/proxy_dex/src/lib.rs +++ b/locked-asset/proxy_dex/src/lib.rs @@ -1,6 +1,4 @@ #![no_std] -#![allow(clippy::too_many_arguments)] -#![feature(exact_size_is_empty)] multiversx_sc::imports!(); multiversx_sc::derive_imports!(); @@ -58,7 +56,7 @@ pub trait ProxyDexImpl: .set_if_empty(&energy_factory_address); } - #[endpoint] + #[upgrade] fn upgrade(&self, old_locked_token_id: TokenIdentifier, old_factory_address: ManagedAddress) { require!( old_locked_token_id.is_valid_esdt_identifier(), diff --git a/locked-asset/proxy_dex/tests/proxy_dex_test_setup/mod.rs b/locked-asset/proxy_dex/tests/proxy_dex_test_setup/mod.rs index 2ab0326d4..73dd9d9c9 100644 --- a/locked-asset/proxy_dex/tests/proxy_dex_test_setup/mod.rs +++ b/locked-asset/proxy_dex/tests/proxy_dex_test_setup/mod.rs @@ -1,5 +1,7 @@ +#![allow(dead_code)] #![allow(deprecated)] +use common_structs::{LockedAssetTokenAttributesEx, UnlockMilestoneEx, UnlockScheduleEx}; use config::ConfigModule; use energy_factory::{locked_token_transfer::LockedTokenTransferModule, SimpleLockEnergy}; use energy_query::EnergyQueryModule; @@ -11,7 +13,7 @@ use multiversx_sc::{ codec::multi_types::OptionalValue, contract_base::{CallableContract, ContractBase}, storage::mappers::StorageTokenWrapper, - types::{Address, EsdtLocalRole, ManagedAddress, MultiValueEncoded}, + types::{Address, EsdtLocalRole, ManagedAddress, ManagedVec, MultiValueEncoded}, }; use multiversx_sc_modules::pause::PauseModule; use multiversx_sc_scenario::{ @@ -151,6 +153,24 @@ where b_mock.set_esdt_balance(&second_user, MEX_TOKEN_ID, &user_balance); b_mock.set_esdt_balance(&second_user, WEGLD_TOKEN_ID, &user_balance); + let mut unlock_milestones = ManagedVec::::new(); + unlock_milestones.push(UnlockMilestoneEx { + unlock_percent: 10_000, + unlock_epoch: LOCK_OPTIONS[0], + }); + + let old_token_attributes = LockedAssetTokenAttributesEx { + is_merged: false, + unlock_schedule: UnlockScheduleEx { unlock_milestones }, + }; + b_mock.set_nft_balance( + &first_user, + LEGACY_LOCKED_TOKEN_ID, + 3, // higher random nonce to avoid nonce caching conflicts + &rust_biguint!(USER_BALANCE), + &old_token_attributes, + ); + // users lock tokens b_mock .execute_esdt_transfer( diff --git a/locked-asset/proxy_dex/tests/proxy_farm_test.rs b/locked-asset/proxy_dex/tests/proxy_farm_test.rs index b2acafc94..8e162a1e4 100644 --- a/locked-asset/proxy_dex/tests/proxy_farm_test.rs +++ b/locked-asset/proxy_dex/tests/proxy_farm_test.rs @@ -6,7 +6,8 @@ use common_structs::FarmTokenAttributes; use config::ConfigModule; use energy_factory::{energy::EnergyModule, SimpleLockEnergy}; use energy_query::Energy; -use farm::exit_penalty::{DEFAULT_PENALTY_PERCENT, MAX_PERCENT}; +use farm::exit_penalty::DEFAULT_PENALTY_PERCENT; +use farm::MAX_PERCENT; use multiversx_sc::{ codec::{multi_types::OptionalValue, Empty}, types::{BigInt, EsdtLocalRole, EsdtTokenPayment}, @@ -354,7 +355,8 @@ fn farm_with_wrapped_lp_test() { block_epoch, managed_biguint!(user_balance), ); - let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); assert_eq!(expected_energy, actual_energy); }) .assert_ok(); @@ -1180,6 +1182,237 @@ fn different_farm_locked_token_nonce_merging_test() { ); } +#[test] +fn total_farm_mechanism_test() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + let first_user = setup.first_user.clone(); + let farm_addr = setup.farm_locked_wrapper.address_ref().clone(); + let user_balance = rust_biguint!(USER_BALANCE); + setup + .b_mock + .set_esdt_balance(&first_user, MEX_TOKEN_ID, &user_balance); + + // users lock tokens + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.simple_lock_wrapper, + MEX_TOKEN_ID, + 0, + &user_balance, + |sc| { + let user_payment = sc.lock_tokens_endpoint(LOCK_OPTIONS[1], OptionalValue::None); + assert_eq!(user_payment.token_nonce, 2); + assert_eq!(user_payment.amount, managed_biguint!(USER_BALANCE)); + }, + ) + .assert_ok(); + + let mut block_epoch = 1; + setup.b_mock.set_block_epoch(block_epoch); + + // Check total farm position + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = sc + .user_total_farm_position(&managed_address!(&first_user)) + .get(); + assert_eq!(first_user_total_farm_position, managed_biguint!(0)); + }) + .assert_ok(); + + //////////////////////////////////////////// ENTER FARM ///////////////////////////////////// + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + // Check total farm position + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = sc + .user_total_farm_position(&managed_address!(&first_user)) + .get(); + assert_eq!( + first_user_total_farm_position, + managed_biguint!(USER_BALANCE) + ); + }) + .assert_ok(); + + block_epoch += 7; + setup.b_mock.set_block_epoch(block_epoch); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 2, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + // Check total farm position + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = sc + .user_total_farm_position(&managed_address!(&first_user)) + .get(); + assert_eq!( + first_user_total_farm_position, + managed_biguint!(USER_BALANCE * 2) + ); + }) + .assert_ok(); + + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_FARM_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + Some(&WrappedFarmTokenAttributes:: { + proxy_farming_token: EsdtTokenPayment { + token_identifier: managed_token_id!(LOCKED_TOKEN_ID), + token_nonce: 1, + amount: managed_biguint!(USER_BALANCE), + }, + farm_token: EsdtTokenPayment { + token_identifier: managed_token_id!(FARM_LOCKED_TOKEN_ID), + token_nonce: 1, + amount: managed_biguint!(USER_BALANCE), + }, + }), + ); + + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_FARM_TOKEN_ID, + 2, + &rust_biguint!(USER_BALANCE), + Some(&WrappedFarmTokenAttributes:: { + proxy_farming_token: EsdtTokenPayment { + token_identifier: managed_token_id!(LOCKED_TOKEN_ID), + token_nonce: 2, + amount: managed_biguint!(USER_BALANCE), + }, + farm_token: EsdtTokenPayment { + token_identifier: managed_token_id!(FARM_LOCKED_TOKEN_ID), + token_nonce: 2, + amount: managed_biguint!(USER_BALANCE), + }, + }), + ); + + //////////////////////////////////////////// CLAIM REWARDS ///////////////////////////////////// + + // claim rewards + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_FARM_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.claim_rewards_proxy(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + // Check total farm position + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = sc + .user_total_farm_position(&managed_address!(&first_user)) + .get(); + assert_eq!( + first_user_total_farm_position, + managed_biguint!(USER_BALANCE * 2) + ); + }) + .assert_ok(); + + // check user balance + setup.b_mock.check_nft_balance::( + &first_user, + LOCKED_TOKEN_ID, + 2, + &rust_biguint!(0), + None, + ); + setup.b_mock.check_nft_balance::( + &first_user, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(0), + None, + ); + + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_FARM_TOKEN_ID, + 3, + &rust_biguint!(USER_BALANCE), + Some(&WrappedFarmTokenAttributes:: { + proxy_farming_token: EsdtTokenPayment { + token_identifier: managed_token_id!(LOCKED_TOKEN_ID), + token_nonce: 1, + amount: managed_biguint!(USER_BALANCE), + }, + farm_token: EsdtTokenPayment { + token_identifier: managed_token_id!(FARM_LOCKED_TOKEN_ID), + token_nonce: 3, + amount: managed_biguint!(USER_BALANCE), + }, + }), + ); + // new NFT + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_FARM_TOKEN_ID, + 2, + &rust_biguint!(USER_BALANCE), + Some(&WrappedFarmTokenAttributes:: { + proxy_farming_token: EsdtTokenPayment { + token_identifier: managed_token_id!(LOCKED_TOKEN_ID), + token_nonce: 2, + amount: managed_biguint!(USER_BALANCE), + }, + farm_token: EsdtTokenPayment { + token_identifier: managed_token_id!(FARM_LOCKED_TOKEN_ID), + token_nonce: 2, + amount: managed_biguint!(USER_BALANCE), + }, + }), + ); +} + #[test] fn increase_proxy_farm_lkmex_energy() { let mut setup = ProxySetup::new( @@ -1221,7 +1454,8 @@ fn increase_proxy_farm_lkmex_energy() { block_epoch, managed_biguint!(USER_BALANCE), ); - let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); assert_eq!(expected_energy, actual_energy); }) .assert_ok(); @@ -1253,7 +1487,8 @@ fn increase_proxy_farm_lkmex_energy() { block_epoch, managed_biguint!(USER_BALANCE), ); - let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); assert_eq!(expected_energy, actual_energy); }) .assert_ok(); @@ -1349,7 +1584,8 @@ fn increase_proxy_farm_proxy_lp_energy() { block_epoch, managed_biguint!(user_balance), ); - let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); assert_eq!(expected_energy, actual_energy); }) .assert_ok(); @@ -1442,6 +1678,17 @@ fn increase_proxy_farm_proxy_lp_energy() { ) .assert_ok(); + // check old tokens were burned + setup + .b_mock + .check_nft_balance::>( + setup.proxy_wrapper.address_ref(), + WRAPPED_FARM_TOKEN_ID, + 4, + &rust_biguint!(0u64), + None, + ); + // check energy after // lp tokens recharged = total tokens / 4 - 500 let user_locked_tokens_in_lp = locked_token_amount.to_u64().unwrap() / 4 - 500; @@ -1459,7 +1706,8 @@ fn increase_proxy_farm_proxy_lp_energy() { block_epoch, managed_biguint!(USER_BALANCE), ); - let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); assert_eq!(expected_energy, actual_energy); }) .assert_ok(); @@ -1485,3 +1733,1031 @@ fn increase_proxy_farm_proxy_lp_energy() { }), ); } + +#[test] +fn increase_proxy_farm_proxy_lp_energy_unlocked_tokens() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + + setup + .b_mock + .execute_tx( + &setup.owner, + &setup.farm_locked_wrapper, + &rust_biguint!(0), + |sc| { + sc.farming_token_id().set(&managed_token_id!(LP_TOKEN_ID)); + + // set produce rewards to false for easier calculation + sc.produce_rewards_enabled().set(false); + }, + ) + .assert_ok(); + + setup.b_mock.set_esdt_local_roles( + setup.farm_locked_wrapper.address_ref(), + LP_TOKEN_ID, + &[EsdtLocalRole::Burn], + ); + + let first_user = setup.first_user.clone(); + let locked_token_amount = rust_biguint!(1_000_000_000); + let other_token_amount = rust_biguint!(500_000_000); + let expected_lp_token_amount = rust_biguint!(499_999_000); + + // set the price to 1 EGLD = 2 MEX + let payments = vec![ + TxTokenTransfer { + token_identifier: LOCKED_TOKEN_ID.to_vec(), + nonce: 1, + value: locked_token_amount.clone(), + }, + TxTokenTransfer { + token_identifier: WEGLD_TOKEN_ID.to_vec(), + nonce: 0, + value: other_token_amount.clone(), + }, + ]; + + // add liquidity twice, to have 2 nonces + let pair_addr = setup.pair_wrapper.address_ref().clone(); + setup + .b_mock + .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &payments, |sc| { + sc.add_liquidity_proxy( + managed_address!(&pair_addr), + managed_biguint!(locked_token_amount.to_u64().unwrap() / 2), + managed_biguint!(other_token_amount.to_u64().unwrap() / 2), + ); + }) + .assert_ok(); + + let pair_addr = setup.pair_wrapper.address_ref().clone(); + setup + .b_mock + .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &payments, |sc| { + sc.add_liquidity_proxy( + managed_address!(&pair_addr), + managed_biguint!(locked_token_amount.to_u64().unwrap() / 2), + managed_biguint!(other_token_amount.to_u64().unwrap() / 2), + ); + }) + .assert_ok(); + + let mut block_epoch = 1u64; + let user_balance = USER_BALANCE; + + // check energy before + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let unlock_epoch = LOCK_OPTIONS[0]; + let lock_epochs = unlock_epoch - block_epoch; + let expected_energy_amount = + BigInt::from((user_balance) as i64) * BigInt::from(lock_epochs as i64); + let expected_energy = Energy::new( + expected_energy_amount, + block_epoch, + managed_biguint!(user_balance), + ); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); + + let farm_locked_addr = setup.farm_locked_wrapper.address_ref().clone(); + + //////////////////////////////////////////// ENTER FARM ///////////////////////////////////// + + // Enter multiple times, to distribute the nonces + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 1, + &(&expected_lp_token_amount / &rust_biguint!(4u64)), + |sc| { + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_locked_addr), + OptionalValue::None, + ); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 2, + &(&expected_lp_token_amount / &rust_biguint!(4u64)), + |sc| { + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_locked_addr), + OptionalValue::None, + ); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 1, + &(&expected_lp_token_amount / &rust_biguint!(4u64)), + |sc| { + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_locked_addr), + OptionalValue::None, + ); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 2, + &(&expected_lp_token_amount / &rust_biguint!(4u64)), + |sc| { + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_locked_addr), + OptionalValue::None, + ); + }, + ) + .assert_ok(); + + ////////////////////////////// Wait for tokens to unlock ///////////////////////////////////// + block_epoch += LOCK_OPTIONS[0]; + setup.b_mock.set_block_epoch(block_epoch); + + //////////////////////////////////////////// INCREASE ENERGY ///////////////////////////////////// + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_FARM_TOKEN_ID, + 4, + &(&expected_lp_token_amount / &rust_biguint!(4u64)), + |sc| { + sc.increase_proxy_farm_token_energy_endpoint(LOCK_OPTIONS[1]); + }, + ) + .assert_ok(); + + // check old tokens were burned + setup + .b_mock + .check_nft_balance::>( + setup.proxy_wrapper.address_ref(), + WRAPPED_FARM_TOKEN_ID, + 4, + &rust_biguint!(0u64), + None, + ); + + // check energy after + // lp tokens recharged = total tokens / 4 - 500 + let user_locked_tokens_in_lp = locked_token_amount.to_u64().unwrap() / 4 - 500; + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let first_lock_epochs = LOCK_OPTIONS[1] - 1u64; + let second_lock_epochs = + BigInt::from(LOCK_OPTIONS[0] as i64) - BigInt::from(block_epoch as i64); + let expected_energy_amount = BigInt::from((user_locked_tokens_in_lp) as i64) + * BigInt::from(first_lock_epochs as i64) + + BigInt::from((USER_BALANCE - user_locked_tokens_in_lp) as i64) + * second_lock_epochs; + let expected_energy = Energy::new( + expected_energy_amount, + block_epoch, + managed_biguint!(USER_BALANCE), + ); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); + + // check user token after increase energy + // new farm token was created + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_FARM_TOKEN_ID, + 5, + &(&expected_lp_token_amount / &rust_biguint!(4u64)), + Some(&WrappedFarmTokenAttributes:: { + proxy_farming_token: EsdtTokenPayment { + token_identifier: managed_token_id!(WRAPPED_LP_TOKEN_ID), + token_nonce: 3, + amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap() / 4u64), + }, + farm_token: EsdtTokenPayment { + token_identifier: managed_token_id!(FARM_LOCKED_TOKEN_ID), + token_nonce: 4, + amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap() / 4u64), + }, + }), + ); +} + +#[test] +fn increase_proxy_farm_proxy_lp_energy_partially_unlocked_tokens() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + + setup + .b_mock + .execute_tx( + &setup.owner, + &setup.farm_locked_wrapper, + &rust_biguint!(0), + |sc| { + sc.farming_token_id().set(&managed_token_id!(LP_TOKEN_ID)); + + // set produce rewards to false for easier calculation + sc.produce_rewards_enabled().set(false); + }, + ) + .assert_ok(); + + setup.b_mock.set_esdt_local_roles( + setup.farm_locked_wrapper.address_ref(), + LP_TOKEN_ID, + &[EsdtLocalRole::Burn], + ); + + let first_user = setup.first_user.clone(); + let locked_token_amount = rust_biguint!(1_000_000_000); + let other_token_amount = rust_biguint!(500_000_000); + let expected_lp_token_amount = rust_biguint!(499_999_000); + + // set the price to 1 EGLD = 2 MEX + let payments = vec![ + TxTokenTransfer { + token_identifier: LOCKED_TOKEN_ID.to_vec(), + nonce: 1, + value: locked_token_amount.clone(), + }, + TxTokenTransfer { + token_identifier: WEGLD_TOKEN_ID.to_vec(), + nonce: 0, + value: other_token_amount.clone(), + }, + ]; + + // add liquidity twice, to have 2 nonces + let pair_addr = setup.pair_wrapper.address_ref().clone(); + setup + .b_mock + .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &payments, |sc| { + sc.add_liquidity_proxy( + managed_address!(&pair_addr), + managed_biguint!(locked_token_amount.to_u64().unwrap() / 2), + managed_biguint!(other_token_amount.to_u64().unwrap() / 2), + ); + }) + .assert_ok(); + + let pair_addr = setup.pair_wrapper.address_ref().clone(); + setup + .b_mock + .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &payments, |sc| { + sc.add_liquidity_proxy( + managed_address!(&pair_addr), + managed_biguint!(locked_token_amount.to_u64().unwrap() / 2), + managed_biguint!(other_token_amount.to_u64().unwrap() / 2), + ); + }) + .assert_ok(); + + let block_epoch = 1u64; + let user_balance = USER_BALANCE; + + // check energy before + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let unlock_epoch = LOCK_OPTIONS[0]; + let lock_epochs = unlock_epoch - block_epoch; + let expected_energy_amount = + BigInt::from((user_balance) as i64) * BigInt::from(lock_epochs as i64); + let expected_energy = Energy::new( + expected_energy_amount, + block_epoch, + managed_biguint!(user_balance), + ); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); + + let farm_locked_addr = setup.farm_locked_wrapper.address_ref().clone(); + + //////////////////////////////////////////// ENTER FARM ///////////////////////////////////// + + // Enter multiple times, to distribute the nonces + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 1, + &(&expected_lp_token_amount / &rust_biguint!(4u64)), + |sc| { + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_locked_addr), + OptionalValue::None, + ); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 2, + &(&expected_lp_token_amount / &rust_biguint!(4u64)), + |sc| { + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_locked_addr), + OptionalValue::None, + ); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 1, + &(&expected_lp_token_amount / &rust_biguint!(4u64)), + |sc| { + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_locked_addr), + OptionalValue::None, + ); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 2, + &(&expected_lp_token_amount / &rust_biguint!(4u64)), + |sc| { + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_locked_addr), + OptionalValue::None, + ); + }, + ) + .assert_ok(); + + //////////////////////////////////////////// INCREASE ENERGY ///////////////////////////////////// + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_FARM_TOKEN_ID, + 4, + &(&expected_lp_token_amount / &rust_biguint!(8u64)), + |sc| { + sc.increase_proxy_farm_token_energy_endpoint(LOCK_OPTIONS[1]); + }, + ) + .assert_ok(); + + // check old tokens were burned + setup + .b_mock + .check_nft_balance::>( + setup.proxy_wrapper.address_ref(), + WRAPPED_FARM_TOKEN_ID, + 4, + &rust_biguint!(0u64), + None, + ); + + // check energy after + // lp tokens recharged = total tokens / 4 - 500 + let user_locked_tokens_in_lp = locked_token_amount.to_u64().unwrap() / 4 - 500; + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let first_lock_epochs = LOCK_OPTIONS[1] - 1u64; + let second_lock_epochs = + BigInt::from(LOCK_OPTIONS[0] as i64) - BigInt::from(block_epoch as i64); + let expected_energy_amount = BigInt::from((user_locked_tokens_in_lp / 2) as i64) + * BigInt::from(first_lock_epochs as i64) + + BigInt::from((USER_BALANCE) as i64) * second_lock_epochs.clone() + - BigInt::from((user_locked_tokens_in_lp / 2u64) as i64) * second_lock_epochs; + + let expected_energy = Energy::new( + expected_energy_amount, + block_epoch, + managed_biguint!(USER_BALANCE), + ); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); + + // check user token after increase energy + // new farm token was created + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_FARM_TOKEN_ID, + 5, + &(&expected_lp_token_amount / &rust_biguint!(8u64)), + Some(&WrappedFarmTokenAttributes:: { + proxy_farming_token: EsdtTokenPayment { + token_identifier: managed_token_id!(WRAPPED_LP_TOKEN_ID), + token_nonce: 3, + amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap() / 8u64), + }, + farm_token: EsdtTokenPayment { + token_identifier: managed_token_id!(FARM_LOCKED_TOKEN_ID), + token_nonce: 4, + amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap() / 8u64), + }, + }), + ); +} + +#[test] +fn original_caller_negative_test() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + let first_user = setup.first_user.clone(); + let farm_addr = setup.farm_locked_wrapper.address_ref().clone(); + let user_balance = rust_biguint!(USER_BALANCE); + setup + .b_mock + .set_esdt_balance(&first_user, MEX_TOKEN_ID, &user_balance); + + // users lock tokens + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.simple_lock_wrapper, + MEX_TOKEN_ID, + 0, + &user_balance, + |sc| { + let user_payment = sc.lock_tokens_endpoint(LOCK_OPTIONS[1], OptionalValue::None); + assert_eq!(user_payment.token_nonce, 2); + assert_eq!(user_payment.amount, managed_biguint!(USER_BALANCE)); + }, + ) + .assert_ok(); + + //////////////////////////////////////////// ENTER FARM ///////////////////////////////////// + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint( + managed_address!(&farm_addr), + Some(managed_address!(&first_user)).into(), + ); + }, + ) + .assert_error(4, "Item not whitelisted"); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + // claim rewards with half position + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_FARM_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE / 2), + |sc| { + sc.claim_rewards_proxy( + managed_address!(&farm_addr), + Some(managed_address!(&first_user)).into(), + ); + }, + ) + .assert_error(4, "Item not whitelisted"); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_FARM_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + let output = sc.exit_farm_proxy( + managed_address!(&farm_addr), + Some(managed_address!(&first_user)).into(), + ); + let output_lp_token = output.0 .0; + assert_eq!(output_lp_token.token_nonce, 1); + assert_eq!(output_lp_token.amount, USER_BALANCE); + }, + ) + .assert_error(4, "Item not whitelisted"); +} + +#[test] +fn total_farm_position_migration_through_proxy_dex_test() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + let first_user = setup.first_user.clone(); + let farm_addr = setup.farm_locked_wrapper.address_ref().clone(); + let user_balance = rust_biguint!(USER_BALANCE); + setup + .b_mock + .set_esdt_balance(&first_user, MEX_TOKEN_ID, &user_balance); + + // user locks tokens + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.simple_lock_wrapper, + MEX_TOKEN_ID, + 0, + &user_balance, + |sc| { + let user_payment = sc.lock_tokens_endpoint(LOCK_OPTIONS[1], OptionalValue::None); + assert_eq!(user_payment.token_nonce, 2); + assert_eq!(user_payment.amount, managed_biguint!(USER_BALANCE)); + }, + ) + .assert_ok(); + + // User enter farm before migration + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + // Simulate contract upgrade - total farm position is reset and migration nonce set + setup + .b_mock + .execute_tx( + &setup.owner, + &setup.farm_locked_wrapper, + &rust_biguint!(0), + |sc| { + sc.user_total_farm_position(&managed_address!(&first_user)) + .set(managed_biguint!(0u64)); + sc.farm_position_migration_nonce().set(2u64); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = sc + .user_total_farm_position(&managed_address!(&first_user)) + .get(); + assert_eq!(first_user_total_farm_position, managed_biguint!(0)); + }) + .assert_ok(); + + // User enters farm again after migration + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 2, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = sc + .user_total_farm_position(&managed_address!(&first_user)) + .get(); + assert_eq!( + first_user_total_farm_position, + managed_biguint!(USER_BALANCE) + ); + }) + .assert_ok(); + + // Merge user tokens + let payments = vec![ + TxTokenTransfer { + token_identifier: WRAPPED_FARM_TOKEN_ID.to_vec(), + nonce: 1, + value: rust_biguint!(USER_BALANCE), + }, + TxTokenTransfer { + token_identifier: WRAPPED_FARM_TOKEN_ID.to_vec(), + nonce: 2, + value: rust_biguint!(USER_BALANCE), + }, + ]; + setup + .b_mock + .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &payments, |sc| { + sc.merge_wrapped_farm_tokens_endpoint(managed_address!(&farm_addr)); + }) + .assert_ok(); + + // Total farm position should be correct + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = sc + .user_total_farm_position(&managed_address!(&first_user)) + .get(); + assert_eq!( + first_user_total_farm_position, + managed_biguint!(USER_BALANCE * 2) + ); + }) + .assert_ok(); +} + +#[test] +fn increase_proxy_farm_legacy_token_energy_negative_test() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + let first_user = setup.first_user.clone(); + let farm_addr = setup.farm_locked_wrapper.address_ref().clone(); + + //////////////////////////////////////////// ENTER FARM ///////////////////////////////////// + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LEGACY_LOCKED_TOKEN_ID, + 3, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + //////////////////////////////////////////// INCREASE ENERGY ///////////////////////////////////// + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_FARM_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.increase_proxy_farm_token_energy_endpoint(LOCK_OPTIONS[1]); + }, + ) + .assert_user_error("Invalid payments"); +} + +#[test] +fn total_farm_position_migration_mechanism_test() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + let first_user = setup.first_user.clone(); + let farm_addr = setup.farm_locked_wrapper.address_ref().clone(); + let user_balance = rust_biguint!(USER_BALANCE * 6); + setup + .b_mock + .set_esdt_balance(&first_user, MEX_TOKEN_ID, &user_balance); + + // user locks tokens + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.simple_lock_wrapper, + MEX_TOKEN_ID, + 0, + &user_balance, + |sc| { + let user_payment = sc.lock_tokens_endpoint(LOCK_OPTIONS[1], OptionalValue::None); + assert_eq!(user_payment.token_nonce, 2); + assert_eq!(user_payment.amount, managed_biguint!(USER_BALANCE * 6)); + }, + ) + .assert_ok(); + + // User enter farm 5 times before migration + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 2, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 2, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 2, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 2, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + LOCKED_TOKEN_ID, + 2, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + // Simulate contract upgrade - total farm position is reset and migration nonce set + setup + .b_mock + .execute_tx( + &setup.owner, + &setup.farm_locked_wrapper, + &rust_biguint!(0), + |sc| { + sc.user_total_farm_position(&managed_address!(&first_user)) + .set(managed_biguint!(0u64)); + sc.farm_position_migration_nonce().set(6u64); + }, + ) + .assert_ok(); + + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = sc + .user_total_farm_position(&managed_address!(&first_user)) + .get(); + assert_eq!(first_user_total_farm_position, managed_biguint!(0)); + }) + .assert_ok(); + + // User enters farm again after migration + let enter_payments = vec![ + TxTokenTransfer { + token_identifier: LOCKED_TOKEN_ID.to_vec(), + nonce: 2, + value: rust_biguint!(USER_BALANCE), + }, + TxTokenTransfer { + token_identifier: WRAPPED_FARM_TOKEN_ID.to_vec(), + nonce: 1, + value: rust_biguint!(USER_BALANCE / 2), + }, + ]; + setup + .b_mock + .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &enter_payments, |sc| { + sc.enter_farm_proxy_endpoint(managed_address!(&farm_addr), OptionalValue::None); + }) + .assert_ok(); + + // Check total farm position + let mut user_total_farm_position = USER_BALANCE + (USER_BALANCE / 2); + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = sc + .user_total_farm_position(&managed_address!(&first_user)) + .get(); + assert_eq!( + first_user_total_farm_position, + managed_biguint!(user_total_farm_position) + ); + }) + .assert_ok(); + + // Claim rewards with half old position + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_FARM_TOKEN_ID, + 2, + &rust_biguint!(USER_BALANCE / 2), + |sc| { + sc.claim_rewards_proxy(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + // Check total farm position + user_total_farm_position += USER_BALANCE / 2; + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = sc + .user_total_farm_position(&managed_address!(&first_user)) + .get(); + assert_eq!( + first_user_total_farm_position, + managed_biguint!(user_total_farm_position) + ); + }) + .assert_ok(); + + // Exit farm with half old position + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.proxy_wrapper, + WRAPPED_FARM_TOKEN_ID, + 3, + &rust_biguint!(USER_BALANCE / 2), + |sc| { + sc.exit_farm_proxy(managed_address!(&farm_addr), OptionalValue::None); + }, + ) + .assert_ok(); + + // Total farm position stays the same + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = sc + .user_total_farm_position(&managed_address!(&first_user)) + .get(); + assert_eq!( + first_user_total_farm_position, + managed_biguint!(user_total_farm_position) + ); + }) + .assert_ok(); + + // Merge 2 partial old farm positions + let merge_payments = vec![ + TxTokenTransfer { + token_identifier: WRAPPED_FARM_TOKEN_ID.to_vec(), + nonce: 4, + value: rust_biguint!(USER_BALANCE / 2), + }, + TxTokenTransfer { + token_identifier: WRAPPED_FARM_TOKEN_ID.to_vec(), + nonce: 5, + value: rust_biguint!(USER_BALANCE / 4 * 3), + }, + ]; + setup + .b_mock + .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &merge_payments, |sc| { + sc.merge_wrapped_farm_tokens_endpoint(managed_address!(&farm_addr)); + }) + .assert_ok(); + + // Check final total farm position + user_total_farm_position += USER_BALANCE / 2; + user_total_farm_position += USER_BALANCE / 4 * 3; + setup + .b_mock + .execute_query(&setup.farm_locked_wrapper, |sc| { + let first_user_total_farm_position = sc + .user_total_farm_position(&managed_address!(&first_user)) + .get(); + assert_eq!( + first_user_total_farm_position, + managed_biguint!(user_total_farm_position) + ); + }) + .assert_ok(); +} diff --git a/locked-asset/proxy_dex/tests/proxy_lp_test.rs b/locked-asset/proxy_dex/tests/proxy_lp_test.rs index 9c3710bb7..5d524ba3a 100644 --- a/locked-asset/proxy_dex/tests/proxy_lp_test.rs +++ b/locked-asset/proxy_dex/tests/proxy_lp_test.rs @@ -133,7 +133,8 @@ fn add_remove_liquidity_proxy_test() { block_epoch, managed_biguint!(user_balance), ); - let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); assert_eq!(expected_energy, actual_energy); }) .assert_ok(); @@ -190,7 +191,8 @@ fn add_remove_liquidity_proxy_test() { block_epoch, managed_biguint!(user_balance), ); - let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); assert_eq!(expected_energy, actual_energy); }) .assert_ok(); @@ -884,7 +886,8 @@ fn increase_proxy_lp_token_energy() { block_epoch, managed_biguint!(USER_BALANCE), ); - let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); assert_eq!(expected_energy, actual_energy); }) .assert_ok(); @@ -904,6 +907,17 @@ fn increase_proxy_lp_token_energy() { ) .assert_ok(); + // check old tokens were burned + setup + .b_mock + .check_nft_balance::>( + setup.proxy_wrapper.address_ref(), + WRAPPED_LP_TOKEN_ID, + 1, + &rust_biguint!(0u64), + None, + ); + // chceck new wrapped lp token setup.b_mock.check_nft_balance( &first_user, @@ -936,8 +950,455 @@ fn increase_proxy_lp_token_energy() { block_epoch, managed_biguint!(USER_BALANCE), ); - let actual_energy = sc.user_energy(&managed_address!(&first_user)).get(); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); +} + +#[test] +fn increase_proxy_lp_token_energy_unlocked_tokens() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + let first_user = setup.first_user.clone(); + let full_balance = rust_biguint!(USER_BALANCE); + let locked_token_amount = rust_biguint!(1_000_000_000); + let other_token_amount = rust_biguint!(500_000_000); + let expected_lp_token_amount = rust_biguint!(499_999_000); + + // set the price to 1 EGLD = 2 MEX + let payments = vec![ + TxTokenTransfer { + token_identifier: LOCKED_TOKEN_ID.to_vec(), + nonce: 1, + value: locked_token_amount.clone(), + }, + TxTokenTransfer { + token_identifier: WEGLD_TOKEN_ID.to_vec(), + nonce: 0, + value: other_token_amount.clone(), + }, + ]; + + // add liquidity + let pair_addr = setup.pair_wrapper.address_ref().clone(); + setup + .b_mock + .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &payments, |sc| { + sc.add_liquidity_proxy( + managed_address!(&pair_addr), + managed_biguint!(locked_token_amount.to_u64().unwrap()), + managed_biguint!(other_token_amount.to_u64().unwrap()), + ); + }) + .assert_ok(); + + // check user's balance + setup.b_mock.check_nft_balance::( + &first_user, + LOCKED_TOKEN_ID, + 1, + &(&full_balance - &locked_token_amount), + None, + ); + setup.b_mock.check_esdt_balance( + &first_user, + WEGLD_TOKEN_ID, + &(&full_balance - &other_token_amount), + ); + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_LP_TOKEN_ID, + 1, + &expected_lp_token_amount, + Some(&WrappedLpTokenAttributes:: { + locked_tokens: EsdtTokenPayment { + token_identifier: managed_token_id!(LOCKED_TOKEN_ID), + token_nonce: 1, + amount: managed_biguint!(locked_token_amount.to_u64().unwrap()), + }, + lp_token_id: managed_token_id!(LP_TOKEN_ID), + lp_token_amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap()), + }), + ); + + let mut block_epoch = 1; + let user_locked_tokens_in_lp = locked_token_amount.to_u64().unwrap(); + + // check user energy before + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let lock_epochs = LOCK_OPTIONS[0] - block_epoch; + let expected_energy_amount = + BigInt::from((USER_BALANCE) as i64) * BigInt::from(lock_epochs as i64); + let expected_energy = Energy::new( + expected_energy_amount, + block_epoch, + managed_biguint!(USER_BALANCE), + ); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); + + // Wait for tokens to unlock + block_epoch += LOCK_OPTIONS[0]; + + setup.b_mock.set_block_epoch(block_epoch); + + // call increase energy + setup + .b_mock + .execute_esdt_transfer( + &setup.first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 1, + &expected_lp_token_amount, + |sc| { + let _ = sc.increase_proxy_pair_token_energy_endpoint(LOCK_OPTIONS[1]); + }, + ) + .assert_ok(); + + // check new wrapped lp token + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_LP_TOKEN_ID, + 2, + &expected_lp_token_amount, + Some(&WrappedLpTokenAttributes:: { + locked_tokens: EsdtTokenPayment { + token_identifier: managed_token_id!(LOCKED_TOKEN_ID), + // Nonce increases + token_nonce: 3, + amount: managed_biguint!(locked_token_amount.to_u64().unwrap()), + }, + lp_token_id: managed_token_id!(LP_TOKEN_ID), + lp_token_amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap()), + }), + ); + + // check old tokens were burned + setup + .b_mock + .check_nft_balance::>( + setup.proxy_wrapper.address_ref(), + WRAPPED_LP_TOKEN_ID, + 1, + &rust_biguint!(0u64), + None, + ); + + // check user energy after + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let first_lock_epochs = LOCK_OPTIONS[1] - 1u64; + let second_lock_epochs = + BigInt::from(LOCK_OPTIONS[0] as i64) - BigInt::from(block_epoch as i64); + + let expected_energy_amount = BigInt::from((user_locked_tokens_in_lp) as i64) + * BigInt::from(first_lock_epochs as i64) + + BigInt::from((USER_BALANCE - user_locked_tokens_in_lp) as i64) + * second_lock_epochs; + let expected_energy = Energy::new( + expected_energy_amount, + block_epoch, + managed_biguint!(USER_BALANCE), + ); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); +} + +#[test] +fn increase_proxy_lp_token_energy_partially_unlocked_tokens() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + let first_user = setup.first_user.clone(); + let full_balance = rust_biguint!(USER_BALANCE); + let locked_token_amount = rust_biguint!(1_000_000_000); + let other_token_amount = rust_biguint!(500_000_000); + let expected_lp_token_amount = rust_biguint!(499_999_000); + + // set the price to 1 EGLD = 2 MEX + let payments = vec![ + TxTokenTransfer { + token_identifier: LOCKED_TOKEN_ID.to_vec(), + nonce: 1, + value: locked_token_amount.clone(), + }, + TxTokenTransfer { + token_identifier: WEGLD_TOKEN_ID.to_vec(), + nonce: 0, + value: other_token_amount.clone(), + }, + ]; + + // add liquidity + let pair_addr = setup.pair_wrapper.address_ref().clone(); + setup + .b_mock + .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &payments, |sc| { + sc.add_liquidity_proxy( + managed_address!(&pair_addr), + managed_biguint!(locked_token_amount.to_u64().unwrap()), + managed_biguint!(other_token_amount.to_u64().unwrap()), + ); + }) + .assert_ok(); + + // check user's balance + setup.b_mock.check_nft_balance::( + &first_user, + LOCKED_TOKEN_ID, + 1, + &(&full_balance - &locked_token_amount), + None, + ); + setup.b_mock.check_esdt_balance( + &first_user, + WEGLD_TOKEN_ID, + &(&full_balance - &other_token_amount), + ); + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_LP_TOKEN_ID, + 1, + &expected_lp_token_amount, + Some(&WrappedLpTokenAttributes:: { + locked_tokens: EsdtTokenPayment { + token_identifier: managed_token_id!(LOCKED_TOKEN_ID), + token_nonce: 1, + amount: managed_biguint!(locked_token_amount.to_u64().unwrap()), + }, + lp_token_id: managed_token_id!(LP_TOKEN_ID), + lp_token_amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap()), + }), + ); + + let block_epoch = 1; + let user_locked_tokens_in_lp = locked_token_amount.to_u64().unwrap(); + + // check user energy before + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let lock_epochs = LOCK_OPTIONS[0] - block_epoch; + let expected_energy_amount = + BigInt::from((USER_BALANCE) as i64) * BigInt::from(lock_epochs as i64); + let expected_energy = Energy::new( + expected_energy_amount, + block_epoch, + managed_biguint!(USER_BALANCE), + ); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); assert_eq!(expected_energy, actual_energy); }) .assert_ok(); + + // call increase energy + setup + .b_mock + .execute_esdt_transfer( + &setup.first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 1, + &(&expected_lp_token_amount / 2u64), + |sc| { + let _ = sc.increase_proxy_pair_token_energy_endpoint(LOCK_OPTIONS[1]); + }, + ) + .assert_ok(); + + // check old tokens were burned + setup + .b_mock + .check_nft_balance::>( + setup.proxy_wrapper.address_ref(), + WRAPPED_LP_TOKEN_ID, + 1, + &rust_biguint!(0u64), + None, + ); + + // check remaining old wrapped lp token + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_LP_TOKEN_ID, + 1, + &(&expected_lp_token_amount / 2u64), + Some(&WrappedLpTokenAttributes:: { + locked_tokens: EsdtTokenPayment { + token_identifier: managed_token_id!(LOCKED_TOKEN_ID), + // Nonce increases + token_nonce: 1, + amount: managed_biguint!(locked_token_amount.to_u64().unwrap()), + }, + lp_token_id: managed_token_id!(LP_TOKEN_ID), + lp_token_amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap()), + }), + ); + + // check new wrapped lp token + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_LP_TOKEN_ID, + 2, + &(&expected_lp_token_amount / 2u64), + Some(&WrappedLpTokenAttributes:: { + locked_tokens: EsdtTokenPayment { + token_identifier: managed_token_id!(LOCKED_TOKEN_ID), + token_nonce: 2, + amount: managed_biguint!(locked_token_amount.to_u64().unwrap() / 2u64), + }, + lp_token_id: managed_token_id!(LP_TOKEN_ID), + lp_token_amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap() / 2u64), + }), + ); + + // check user energy after + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let first_lock_epochs = LOCK_OPTIONS[1] - 1u64; + let second_lock_epochs = + BigInt::from(LOCK_OPTIONS[0] as i64) - BigInt::from(block_epoch as i64); + + let expected_energy_amount = BigInt::from((user_locked_tokens_in_lp / 2u64) as i64) + * BigInt::from(first_lock_epochs as i64) + + BigInt::from((USER_BALANCE) as i64) * second_lock_epochs.clone() + - BigInt::from((user_locked_tokens_in_lp / 2u64) as i64) * second_lock_epochs; + let expected_energy = Energy::new( + expected_energy_amount, + block_epoch, + managed_biguint!(USER_BALANCE), + ); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); +} + +#[test] +fn increase_proxy_lp_legacy_token_energy() { + let mut setup = ProxySetup::new( + proxy_dex::contract_obj, + pair::contract_obj, + farm_with_locked_rewards::contract_obj, + energy_factory::contract_obj, + ); + let first_user = setup.first_user.clone(); + let full_balance = rust_biguint!(USER_BALANCE); + let locked_token_amount = rust_biguint!(1_000_000_000); + let other_token_amount = rust_biguint!(500_000_000); + let expected_lp_token_amount = rust_biguint!(499_999_000); + + // set the price to 1 EGLD = 2 MEX + let payments = vec![ + TxTokenTransfer { + token_identifier: LEGACY_LOCKED_TOKEN_ID.to_vec(), + nonce: 3, + value: locked_token_amount.clone(), + }, + TxTokenTransfer { + token_identifier: WEGLD_TOKEN_ID.to_vec(), + nonce: 0, + value: other_token_amount.clone(), + }, + ]; + + // add liquidity + let pair_addr = setup.pair_wrapper.address_ref().clone(); + setup + .b_mock + .execute_esdt_multi_transfer(&first_user, &setup.proxy_wrapper, &payments, |sc| { + sc.add_liquidity_proxy( + managed_address!(&pair_addr), + managed_biguint!(locked_token_amount.to_u64().unwrap()), + managed_biguint!(other_token_amount.to_u64().unwrap()), + ); + }) + .assert_ok(); + + // check user's balance + setup.b_mock.check_nft_balance::( + &first_user, + LEGACY_LOCKED_TOKEN_ID, + 3, + &(&full_balance - &locked_token_amount), + None, + ); + setup.b_mock.check_esdt_balance( + &first_user, + WEGLD_TOKEN_ID, + &(&full_balance - &other_token_amount), + ); + setup.b_mock.check_nft_balance( + &first_user, + WRAPPED_LP_TOKEN_ID, + 1, + &expected_lp_token_amount, + Some(&WrappedLpTokenAttributes:: { + locked_tokens: EsdtTokenPayment { + token_identifier: managed_token_id!(LEGACY_LOCKED_TOKEN_ID), + token_nonce: 3, + amount: managed_biguint!(locked_token_amount.to_u64().unwrap()), + }, + lp_token_id: managed_token_id!(LP_TOKEN_ID), + lp_token_amount: managed_biguint!(expected_lp_token_amount.to_u64().unwrap()), + }), + ); + + let block_epoch = 1; + + // check user energy before + setup + .b_mock + .execute_query(&setup.simple_lock_wrapper, |sc| { + let lock_epochs = LOCK_OPTIONS[0] - block_epoch; + let expected_energy_amount = + BigInt::from((USER_BALANCE) as i64) * BigInt::from(lock_epochs as i64); + let expected_energy = Energy::new( + expected_energy_amount, + block_epoch, + managed_biguint!(USER_BALANCE), + ); + let actual_energy = + sc.get_updated_energy_entry_for_user(&managed_address!(&first_user)); + assert_eq!(expected_energy, actual_energy); + }) + .assert_ok(); + + // call increase energy + setup + .b_mock + .execute_esdt_transfer( + &setup.first_user, + &setup.proxy_wrapper, + WRAPPED_LP_TOKEN_ID, + 1, + &expected_lp_token_amount, + |sc| { + let _ = sc.increase_proxy_pair_token_energy_endpoint(LOCK_OPTIONS[1]); + }, + ) + .assert_error(4, "Invalid payment"); } diff --git a/locked-asset/proxy_dex/wasm/Cargo.lock b/locked-asset/proxy_dex/wasm/Cargo.lock index 7cc65eaa5..3330a21d1 100644 --- a/locked-asset/proxy_dex/wasm/Cargo.lock +++ b/locked-asset/proxy_dex/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common-types" @@ -76,9 +76,9 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "endian-type" @@ -307,32 +307,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -342,9 +344,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -355,18 +357,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -382,9 +384,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -424,9 +426,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -465,9 +467,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -516,15 +518,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -554,6 +556,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" diff --git a/locked-asset/proxy_dex/wasm/Cargo.toml b/locked-asset/proxy_dex/wasm/Cargo.toml index b0753d94f..e7d8de4c3 100644 --- a/locked-asset/proxy_dex/wasm/Cargo.toml +++ b/locked-asset/proxy_dex/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.proxy_dex] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [workspace] members = ["."] diff --git a/locked-asset/proxy_dex/wasm/src/lib.rs b/locked-asset/proxy_dex/wasm/src/lib.rs index 29b3ab709..c04d97990 100644 --- a/locked-asset/proxy_dex/wasm/src/lib.rs +++ b/locked-asset/proxy_dex/wasm/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 31 +// Upgrade: 1 +// Endpoints: 30 // Async Callback: 1 // Total number of exported functions: 33 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); diff --git a/locked-asset/simple-lock-whitelist/Cargo.toml b/locked-asset/simple-lock-whitelist/Cargo.toml deleted file mode 100644 index a8d637a5c..000000000 --- a/locked-asset/simple-lock-whitelist/Cargo.toml +++ /dev/null @@ -1,30 +0,0 @@ -[package] -name = "simple-lock-whitelist" -version = "0.0.0" -authors = ["Dorin Iancu "] -edition = "2021" -publish = false - -[lib] -path = "src/lib.rs" - -[dependencies.simple-lock] -path = "../simple-lock" - -[dependencies.utils] -path = "../../common/modules/utils" - -[dependencies.multiversx-sc] -version = "=0.46.1" -features = ["esdt-token-payment-legacy-decode"] - -[dependencies.multiversx-sc-modules] -version = "=0.46.1" - -[dev-dependencies] -num-bigint = "0.4.2" -num-traits = "0.2" -hex = "0.4" - -[dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" diff --git a/locked-asset/simple-lock-whitelist/meta/Cargo.toml b/locked-asset/simple-lock-whitelist/meta/Cargo.toml deleted file mode 100644 index 8b95c8a50..000000000 --- a/locked-asset/simple-lock-whitelist/meta/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "simple-lock-whitelist-meta" -version = "0.0.0" -edition = "2021" -publish = false -authors = ["Dorin Iancu "] - -[dependencies.simple-lock-whitelist] -path = ".." - -[dependencies.multiversx-sc-meta] -version = "0.46.1" -default-features = false diff --git a/locked-asset/simple-lock-whitelist/meta/src/main.rs b/locked-asset/simple-lock-whitelist/meta/src/main.rs deleted file mode 100644 index c58ebf7a8..000000000 --- a/locked-asset/simple-lock-whitelist/meta/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - multiversx_sc_meta::cli_main::(); -} diff --git a/locked-asset/simple-lock-whitelist/scenarios/factory_old.wasm b/locked-asset/simple-lock-whitelist/scenarios/factory_old.wasm deleted file mode 100644 index 3c6ca8c4e..000000000 Binary files a/locked-asset/simple-lock-whitelist/scenarios/factory_old.wasm and /dev/null differ diff --git a/locked-asset/simple-lock-whitelist/scenarios/old-farm.wasm b/locked-asset/simple-lock-whitelist/scenarios/old-farm.wasm deleted file mode 100644 index 0ffa046e3..000000000 Binary files a/locked-asset/simple-lock-whitelist/scenarios/old-farm.wasm and /dev/null differ diff --git a/locked-asset/simple-lock-whitelist/scenarios/old-farm_locked_rewards.wasm b/locked-asset/simple-lock-whitelist/scenarios/old-farm_locked_rewards.wasm deleted file mode 100644 index 064e2a887..000000000 Binary files a/locked-asset/simple-lock-whitelist/scenarios/old-farm_locked_rewards.wasm and /dev/null differ diff --git a/locked-asset/simple-lock-whitelist/scenarios/simple_lock_whitelist.scen.json b/locked-asset/simple-lock-whitelist/scenarios/simple_lock_whitelist.scen.json deleted file mode 100644 index b89bdaec0..000000000 --- a/locked-asset/simple-lock-whitelist/scenarios/simple_lock_whitelist.scen.json +++ /dev/null @@ -1,605 +0,0 @@ -{ - "name": "Simple lock whitelist", - "comment": "", - "steps": [ - { - "step": "setState", - "accounts": { - "address:owner": { - "nonce": "0", - "balance": "0", - "esdt": { - "str:ASHEGLD-123456": { - "balance": "1000000000000000000" - }, - "str:ASHUSDC-123456": { - "balance": "1000000000000000000" - }, - "str:LKLP-123456": { - "instances": [ - { - "nonce": "1", - "balance": "1000000000000000000", - "attributes": "nested:str:ASHEGLD-123456|nested:str:ASH-1234|u64:0|nested:str:WEGLD-123456|u64:0", - "creator": "sc:simple_lock" - }, - { - "nonce": "2", - "balance": "1000000000000000000", - "attributes": "nested:str:ASHUSDC-123456|nested:str:ASH-1234|u64:0|nested:str:USDC-123456|u64:0", - "creator": "sc:simple_lock" - } - ] - } - } - }, - "sc:farm_old": { - "nonce": "0", - "code": "file:./old-farm.wasm", - "esdt": { - "str:ASHEGLDF-123456": { - "roles": [ - "ESDTRoleNFTCreate", - "ESDTRoleNFTAddQuantity", - "ESDTRoleNFTBurn" - ] - }, - "str:MEX-123456": { - "roles": [ - "ESDTRoleLocalMint" - ] - } - }, - "storage": { - "str:state": "1", - "str:farming_token_id": "str:ASHEGLD-123456", - "str:reward_token_id": "str:MEX-123456", - "str:farm_token_id": "str:ASHEGLDF-123456", - "str:division_safety_constant": "1000000000000", - "str:per_block_reward_amount": "1000000000000000000", - "str:produce_rewards_enabled": "0x01" - }, - "owner": "address:owner" - }, - "sc:farm-locked-rewards_old": { - "nonce": "0", - "code": "file:./old-farm_locked_rewards.wasm", - "esdt": { - "str:ASHEGLDFL-123456": { - "roles": [ - "ESDTRoleNFTCreate", - "ESDTRoleNFTAddQuantity", - "ESDTRoleNFTBurn" - ] - } - }, - "storage": { - "str:state": "1", - "str:farming_token_id": "str:ASHEGLD-123456", - "str:reward_token_id": "str:MEX-123456", - "str:farm_token_id": "str:ASHEGLDFL-123456", - "str:division_safety_constant": "1000000000000", - "str:per_block_reward_amount": "1000000000000000000", - "str:produce_rewards_enabled": "0x01", - "str:penalty_percent": "u64:0", - "str:minimum_farming_epochs": "u8:0", - "str:locked_asset_factory_address": "sc:factory", - "str:transfer_exec_gas_limit": "50000000" - }, - "owner": "address:owner" - }, - "sc:farm": { - "nonce": "0", - "code": "file:../../../dex/farm/output/farm.wasm", - "esdt": { - "str:ASHUSDCF-abcdef": { - "roles": [ - "ESDTRoleNFTCreate", - "ESDTRoleNFTAddQuantity", - "ESDTRoleNFTBurn" - ] - }, - "str:MEX-123456": { - "roles": [ - "ESDTRoleLocalMint" - ] - } - }, - "storage": { - "str:state": "1", - "str:farming_token_id": "str:ASHUSDC-123456", - "str:reward_token_id": "str:MEX-123456", - "str:farm_token_id": "str:ASHUSDCF-abcdef", - "str:division_safety_constant": "1000000000000", - "str:per_block_reward_amount": "1000000000000000000", - "str:produce_rewards_enabled": "0x01", - "str:boostedYieldsRewardsPercentage": "0x00" - }, - "owner": "address:owner" - }, - "sc:simple_lock": { - "nonce": "0", - "code": "file:../output/simple-lock-whitelist.wasm", - "owner": "address:owner", - "esdt": { - "str:LKASH-123456": { - "roles": [ - "ESDTRoleNFTCreate", - "ESDTRoleNFTAddQuantity", - "ESDTRoleNFTBurn" - ] - }, - "str:LKLP-123456": { - "roles": [ - "ESDTRoleNFTCreate", - "ESDTRoleNFTAddQuantity", - "ESDTRoleNFTBurn" - ] - }, - "str:LKFARM-123456": { - "roles": [ - "ESDTRoleNFTCreate", - "ESDTRoleNFTAddQuantity", - "ESDTRoleNFTBurn" - ] - }, - "str:ASHEGLD-123456": "1000000000000000000", - "str:ASHUSDC-123456": "1000000000000000000" - }, - "storage": { - "str:tokenWhitelist": ["str:ASH-123456"], - "str:knownFarms": ["sc:farm_old", "sc:farm-locked-rewards_old", "sc:farm"], - "str:farmAddressForToken|nested:str:ASHEGLD-123456|u8:0": ["sc:farm_old"], - "str:farmAddressForToken|nested:str:ASHEGLD-123456|u8:1": ["sc:farm-locked-rewards_old"], - "str:farmAddressForToken|nested:str:ASHUSDC-123456|u8:0": ["sc:farm"], - "str:lpProxyTokenId": "str:LKLP-123456", - "str:farmProxyTokenId": "str:LKFARM-123456" - } - }, - "sc:factory": { - "nonce": "0", - "code": "file:./factory_old.wasm", - "owner": "address:owner", - "esdt": { - "str:LKMEX-abcdef": { - "roles": [ - "ESDTRoleNFTCreate", - "ESDTRoleNFTAddQuantity", - "ESDTRoleNFTBurn" - ] - }, - "str:MEX-123456": { - "roles": [ - "ESDTRoleLocalMint", - "ESDTRoleLocalBurn" - ] - } - }, - "storage": { - "str:init_epoch": "u64:1", - "str:extended_attributes_activation_nonce": "u64:10", - "str:asset_token_id": "str:MEX-123456", - "str:locked_asset_token_id": "str:LKMEX-abcdef", - "str:default_unlock_period": "0x00000002000000000000001b32000000000000002c32", - "str:transfer_exec_gas_limit": "50000000" - } - } - } - }, - { - "step": "scCall", - "txId": "factory-whitelist-farm", - "tx": { - "from": "address:owner", - "to": "sc:factory", - "egldValue": "0", - "function": "whitelist", - "arguments": ["sc:farm-locked-rewards_old"], - "gasLimit": "25,000,000" - }, - "expect": { - "status": "0", - "out": [] - } - }, - { - "step": "scCall", - "txId": "enter-old-farm_locked_rewards-tx", - "tx": { - "from": "address:owner", - "to": "sc:farm-locked-rewards_old", - "egldValue": "0", - "esdtValue": [ - { - "tokenIdentifier": "str:ASHEGLD-123456", - "value": "1000000000000000000" - } - ], - "function": "enterFarm", - "gasLimit": "25,000,000" - }, - "expect": { - "status": "0", - "out": [ - "1", - "0x020000001041534845474c44464c2d3132333435360000000000000001000000080de0b6b3a7640000" - ] - } - }, - { - "step": "scCall", - "txId": "enter-farm-tx", - "tx": { - "from": "address:owner", - "to": "sc:farm", - "egldValue": "0", - "esdtValue": [ - { - "tokenIdentifier": "str:ASHUSDC-123456", - "value": "1000000000000000000" - } - ], - "function": "enterFarm", - "gasLimit": "25,000,000" - }, - "expect": { - "status": "0", - "out": [ - "0x0000000f41534855534443462d6162636465660000000000000001000000080de0b6b3a7640000" - ] - } - }, - { - "step": "setState", - "comment": "increase block nonce", - "currentBlockInfo": { - "blockNonce": "2" - } - }, - { - "step": "scCall", - "txId": "exit-old-farm_locked_rewards-tx", - "tx": { - "from": "address:owner", - "to": "sc:farm-locked-rewards_old", - "egldValue": "0", - "esdtValue": [ - { - "tokenIdentifier": "str:ASHEGLDFL-123456", - "value": "1000000000000000000", - "nonce": "1" - } - ], - "function": "exitFarm", - "gasLimit": "25,000,000" - }, - "expect": { - "status": "0", - "out": [ - "1", - "0x020000000c4c4b4d45582d6162636465660000000000000001000000081bc16d674ec80000", - "0x000000000e41534845474c442d3132333435360000000000000000000000080de0b6b3a7640000", - "0x020000000c4c4b4d45582d6162636465660000000000000001000000081bc16d674ec80000" - ] - } - }, - { - "step": "scCall", - "txId": "enter-old-farm-locked-token-tx", - "tx": { - "from": "address:owner", - "to": "sc:simple_lock", - "egldValue": "0", - "esdtValue": [ - { - "tokenIdentifier": "str:LKLP-123456", - "value": "1000000000000000000", - "nonce": "1" - } - ], - "function": "enterFarmLockedToken", - "arguments": ["0"], - "gasLimit": "25,000,000" - }, - "expect": { - "status": "0", - "out": [ - "0x0000000d4c4b4641524d2d3132333435360000000000000001000000080de0b6b3a7640000" - ] - } - }, - { - "step": "scCall", - "txId": "enter-farm-locked-token-tx", - "tx": { - "from": "address:owner", - "to": "sc:simple_lock", - "egldValue": "0", - "esdtValue": [ - { - "tokenIdentifier": "str:LKLP-123456", - "value": "1000000000000000000", - "nonce": "2" - } - ], - "function": "enterFarmLockedToken", - "arguments": ["0"], - "gasLimit": "25,000,000" - }, - "expect": { - "status": "0", - "out": [ - "0x0000000d4c4b4641524d2d3132333435360000000000000002000000080de0b6b3a7640000" - ] - } - }, - { - "step": "setState", - "comment": "increase block nonce", - "currentBlockInfo": { - "blockNonce": "3" - } - }, - { - "step": "scCall", - "txId": "exit-old-farm-locked-token-tx", - "tx": { - "from": "address:owner", - "to": "sc:simple_lock", - "egldValue": "0", - "esdtValue": [ - { - "tokenIdentifier": "str:LKFARM-123456", - "value": "1000000000000000000", - "nonce": "1" - } - ], - "function": "exitFarmLockedToken", - "gasLimit": "30,000,000" - }, - "expect": { - "status": "0", - "refund": "*", - "out": [ - "0x0000000b4c4b4c502d3132333435360000000000000001000000080de0b6b3a7640000", - "0x0000000a4d45582d3132333435360000000000000000000000080de0b6b3a7640000" - ] - } - }, - { - "step": "scCall", - "txId": "exit-farm-locked-token-tx", - "tx": { - "from": "address:owner", - "to": "sc:simple_lock", - "egldValue": "0", - "esdtValue": [ - { - "tokenIdentifier": "str:LKFARM-123456", - "value": "1000000000000000000", - "nonce": "2" - } - ], - "function": "exitFarmLockedToken", - "gasLimit": "30,000,000" - }, - "expect": { - "status": "0", - "refund": "*", - "out": [ - "0x0000000b4c4b4c502d3132333435360000000000000002000000080de0b6b3a7640000", - "0x0000000a4d45582d31323334353600000000000000000000000806f05b59d3b20000" - ] - } - }, - { - "step": "scCall", - "txId": "enter-old-farm_locked_rewards-locked-token-tx", - "tx": { - "from": "address:owner", - "to": "sc:simple_lock", - "egldValue": "0", - "esdtValue": [ - { - "tokenIdentifier": "str:LKLP-123456", - "value": "1000000000000000000", - "nonce": "1" - } - ], - "function": "enterFarmLockedToken", - "arguments": ["1"], - "gasLimit": "25,000,000" - }, - "expect": { - "status": "0", - "out": [ - "0x0000000d4c4b4641524d2d3132333435360000000000000003000000080de0b6b3a7640000" - ] - } - }, - { - "step": "checkState", - "accounts": { - "address:owner": { - "nonce": "9", - "balance": "0", - "esdt": { - "str:ASHEGLD-123456": { - "lastNonce": "0", - "balance": "1000000000000000000" - }, - "str:ASHUSDC-123456": { - "lastNonce": "0" - }, - "str:ASHUSDCF-abcdef": { - "instances": [ - { - "nonce": "1", - "balance": "1000000000000000000", - "creator": "sc:farm", - "uri": [ - "str:" - ], - "attributes": "0x0000000000000000000000000000000000000000000000080de0b6b3a764000000000000000000080de0b6b3a7640000" - } - ], - "lastNonce": "0" - }, - "str:LKLP-123456": { - "instances": [ - { - "nonce": "2", - "balance": "1000000000000000000", - "creator": "sc:simple_lock", - "attributes": "nested:str:ASHUSDC-123456|nested:str:ASH-1234|u64:0|nested:str:USDC-123456|u64:0" - } - ], - "lastNonce": "0" - }, - "str:MEX-123456": { - "instances": [ - { - "nonce": "0", - "balance": "1500000000000000000" - } - ], - "lastNonce": "0" - }, - "str:LKFARM-123456": { - "instances": [ - { - "nonce": "3", - "balance": "1000000000000000000", - "creator": "sc:simple_lock", - "attributes": "u8:1|nested:str:ASHEGLDFL-123456|u64:2|nested:str:ASHEGLD-123456|u64:1" - } - ], - "lastNonce": "0" - }, - "str:LKMEX-abcdef": { - "instances": [ - { - "nonce": "1", - "balance": "2000000000000000000", - "creator": "sc:factory", - "uri": [ - "str:" - ], - "attributes": "0x00000002000000000000000c000000000000c350000000000000001d000000000000c35000" - } - ], - "lastNonce": "0" - } - } - }, - "+": "" - } - }, - { - "step": "setState", - "comment": "increase block nonce", - "currentBlockInfo": { - "blockNonce": "4" - } - }, - { - "step": "scCall", - "txId": "exit-old-farm_locked_rewards-locked-token-tx", - "tx": { - "from": "address:owner", - "to": "sc:simple_lock", - "egldValue": "0", - "esdtValue": [ - { - "tokenIdentifier": "str:LKFARM-123456", - "value": "1000000000000000000", - "nonce": "3" - } - ], - "function": "exitFarmLockedToken", - "gasLimit": "30,000,000" - }, - "expect": { - "status": "0", - "refund": "*", - "out": [ - "0x0000000b4c4b4c502d3132333435360000000000000001000000080de0b6b3a7640000", - "0x0000000c4c4b4d45582d6162636465660000000000000001000000080de0b6b3a7640000" - ] - } - }, - { - "step": "checkState", - "accounts": { - "address:owner": { - "nonce": "10", - "balance": "0", - "esdt": { - "str:ASHEGLD-123456": { - "lastNonce": "0", - "balance": "1000000000000000000" - }, - "str:ASHUSDC-123456": { - "lastNonce": "0" - }, - "str:ASHUSDCF-abcdef": { - "instances": [ - { - "nonce": "1", - "balance": "1000000000000000000", - "creator": "sc:farm", - "uri": [ - "str:" - ], - "attributes": "0x0000000000000000000000000000000000000000000000080de0b6b3a764000000000000000000080de0b6b3a7640000" - } - ], - "lastNonce": "0" - }, - "str:LKLP-123456": { - "instances": [ - { - "nonce": "1", - "balance": "1000000000000000000", - "creator": "sc:simple_lock", - "attributes": "nested:str:ASHEGLD-123456|nested:str:ASH-1234|u64:0|nested:str:WEGLD-123456|u64:0" - }, - { - "nonce": "2", - "balance": "1000000000000000000", - "creator": "sc:simple_lock", - "attributes": "nested:str:ASHUSDC-123456|nested:str:ASH-1234|u64:0|nested:str:USDC-123456|u64:0" - } - ], - "lastNonce": "0" - }, - "str:MEX-123456": { - "instances": [ - { - "nonce": "0", - "balance": "1500000000000000000" - } - ], - "lastNonce": "0" - }, - "str:LKMEX-abcdef": { - "instances": [ - { - "nonce": "1", - "balance": "3000000000000000000", - "creator": "sc:factory", - "uri": [ - "str:" - ], - "attributes": "0x00000002000000000000000c000000000000c350000000000000001d000000000000c35000" - } - ], - "lastNonce": "0" - } - } - }, - "+": "" - } - } - ] -} diff --git a/locked-asset/simple-lock-whitelist/src/lib.rs b/locked-asset/simple-lock-whitelist/src/lib.rs deleted file mode 100644 index 48192fb15..000000000 --- a/locked-asset/simple-lock-whitelist/src/lib.rs +++ /dev/null @@ -1,141 +0,0 @@ -#![no_std] - -use simple_lock::error_messages::INVALID_PAYMENTS_ERR_MSG; - -multiversx_sc::imports!(); - -#[multiversx_sc::contract] -pub trait SimpleLockWhitelist: - simple_lock::basic_lock_unlock::BasicLockUnlock - + simple_lock::locked_token::LockedTokenModule - + multiversx_sc_modules::default_issue_callbacks::DefaultIssueCallbacksModule - + simple_lock::proxy_lp::ProxyLpModule - + simple_lock::proxy_farm::ProxyFarmModule - + simple_lock::lp_interactions::LpInteractionsModule - + simple_lock::farm_interactions::FarmInteractionsModule - + simple_lock::token_attributes::TokenAttributesModule - + utils::UtilsModule -{ - /// Args: Token IDs that are accepted for the `lock` endpoint. - /// Any other token is rejected. - #[init] - fn init(&self, token_whitelist: MultiValueEncoded) { - let mut whitelist = self.token_whitelist(); - for token_id in token_whitelist { - self.require_valid_token_id(&token_id); - - let _ = whitelist.insert(token_id); - } - } - - #[endpoint] - fn upgrade(&self) {} - - /// Sets the transfer role for the given address. Defaults to own address. - #[only_owner] - #[endpoint(setTransferRoleLockedToken)] - fn set_transfer_role(&self, opt_address: OptionalValue) { - let address = match opt_address { - OptionalValue::Some(addr) => addr, - OptionalValue::None => self.blockchain().get_sc_address(), - }; - - self.locked_token() - .set_local_roles_for_address(&address, &[EsdtLocalRole::Transfer], None); - } - - #[only_owner] - #[endpoint(setTransferRoleProxyLpToken)] - fn set_transfer_role_proxy_lp(&self, opt_address: OptionalValue) { - let address = match opt_address { - OptionalValue::Some(addr) => addr, - OptionalValue::None => self.blockchain().get_sc_address(), - }; - - self.lp_proxy_token().set_local_roles_for_address( - &address, - &[EsdtLocalRole::Transfer], - None, - ); - } - - #[only_owner] - #[endpoint(setTransferRoleProxyFarmToken)] - fn set_transfer_role_proxy_farm(&self, opt_address: OptionalValue) { - let address = match opt_address { - OptionalValue::Some(addr) => addr, - OptionalValue::None => self.blockchain().get_sc_address(), - }; - - self.farm_proxy_token().set_local_roles_for_address( - &address, - &[EsdtLocalRole::Transfer], - None, - ); - } - - #[only_owner] - #[endpoint(setLockedToken)] - fn set_locked_token(&self, token_id: TokenIdentifier) { - require!(token_id.is_valid_esdt_identifier(), "Token id is not valid"); - self.locked_token().set_token_id(token_id); - } - - /// Locks a whitelisted token 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. - /// - /// Expected payment: A whitelisted token - /// - /// Arguments: - /// - unlock epoch - the epoch from which the LOCKED token holder may call the unlock endpoint - /// - opt_destination - OPTIONAL: destination address for the LOCKED tokens. Default is caller. - /// - /// Output payments: LOCKED tokens (or original payment if current_epoch >= unlock_epoch) - #[payable("*")] - #[endpoint(lockTokens)] - fn lock_tokens_endpoint( - &self, - unlock_epoch: u64, - opt_destination: OptionalValue, - ) -> EgldOrEsdtTokenPayment { - let payment = self.call_value().single_esdt(); - self.require_token_in_whitelist(&payment.token_identifier); - - let dest_address = self.dest_from_optional(opt_destination); - self.lock_and_send( - &dest_address, - EgldOrEsdtTokenPayment::from(payment), - unlock_epoch, - ) - } - - /// Unlock tokens, previously locked with the `lockTokens` endpoint - /// - /// Expected payment: LOCKED tokens - /// - /// Arguments: - /// - opt_destination - OPTIONAL: destination address for the unlocked tokens - /// - /// Output payments: the originally locked tokens - #[payable("*")] - #[endpoint(unlockTokens)] - fn unlock_tokens_endpoint( - &self, - opt_destination: OptionalValue, - ) -> EgldOrEsdtTokenPayment { - let payment = self.call_value().single_esdt(); - let dest_address = self.dest_from_optional(opt_destination); - self.unlock_and_send(&dest_address, payment) - } - - fn require_token_in_whitelist(&self, token_id: &TokenIdentifier) { - require!( - self.token_whitelist().contains(token_id), - INVALID_PAYMENTS_ERR_MSG - ); - } - - #[view(getTokenWhitelist)] - #[storage_mapper("tokenWhitelist")] - fn token_whitelist(&self) -> UnorderedSetMapper; -} diff --git a/locked-asset/simple-lock-whitelist/testnet.toml b/locked-asset/simple-lock-whitelist/testnet.toml deleted file mode 100644 index e69de29bb..000000000 diff --git a/locked-asset/simple-lock-whitelist/tests/whitelist_test.rs b/locked-asset/simple-lock-whitelist/tests/whitelist_test.rs deleted file mode 100644 index 54bb650a5..000000000 --- a/locked-asset/simple-lock-whitelist/tests/whitelist_test.rs +++ /dev/null @@ -1,97 +0,0 @@ -#![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_legacy::*}; - -use multiversx_sc::storage::mappers::StorageTokenWrapper; -use simple_lock::locked_token::*; -use simple_lock_whitelist::SimpleLockWhitelist; - -static FREE_TOKEN_ID: &[u8] = b"FREEEEE-123456"; -static OTHER_TOKEN_ID: &[u8] = b"ILLEGAL-123456"; -static LOCKED_TOKEN_ID: &[u8] = b"NOOO0-123456"; - -#[test] -fn lock_whitelist_test() { - let rust_zero = rust_biguint!(0); - let mut b_mock = BlockchainStateWrapper::new(); - - let user_addr = b_mock.create_user_account(&rust_zero); - let owner_addr = b_mock.create_user_account(&rust_zero); - let sc_wrapper = b_mock.create_sc_account( - &rust_zero, - Some(&owner_addr), - simple_lock_whitelist::contract_obj, - "Some path", - ); - - b_mock.set_block_epoch(5); - - b_mock - .execute_tx(&owner_addr, &sc_wrapper, &rust_zero, |sc| { - let mut whitelist = MultiValueEncoded::new(); - whitelist.push(managed_token_id!(FREE_TOKEN_ID)); - - sc.init(whitelist); - sc.locked_token() - .set_token_id(managed_token_id!(LOCKED_TOKEN_ID)); - }) - .assert_ok(); - - b_mock.set_esdt_local_roles( - sc_wrapper.address_ref(), - LOCKED_TOKEN_ID, - &[ - EsdtLocalRole::NftCreate, - EsdtLocalRole::NftAddQuantity, - EsdtLocalRole::NftBurn, - ], - ); - - let lock_amount = rust_biguint!(1_000); - b_mock.set_esdt_balance(&user_addr, FREE_TOKEN_ID, &lock_amount); - b_mock.set_esdt_balance(&user_addr, OTHER_TOKEN_ID, &lock_amount); - - // lock wrong token - b_mock - .execute_esdt_transfer( - &user_addr, - &sc_wrapper, - OTHER_TOKEN_ID, - 0, - &lock_amount, - |sc| { - let _ = sc.lock_tokens_endpoint(10, OptionalValue::None); - }, - ) - .assert_user_error("Invalid payments"); - - // lock ok - b_mock - .execute_esdt_transfer( - &user_addr, - &sc_wrapper, - FREE_TOKEN_ID, - 0, - &lock_amount, - |sc| { - let _ = sc.lock_tokens_endpoint(10, OptionalValue::None); - }, - ) - .assert_ok(); - - DebugApi::dummy(); - b_mock.check_nft_balance( - &user_addr, - LOCKED_TOKEN_ID, - 1, - &lock_amount, - Some(&LockedTokenAttributes:: { - original_token_id: managed_token_id_wrapped!(FREE_TOKEN_ID), - original_token_nonce: 0, - unlock_epoch: 10, - }), - ); -} diff --git a/locked-asset/simple-lock-whitelist/wasm/src/lib.rs b/locked-asset/simple-lock-whitelist/wasm/src/lib.rs deleted file mode 100644 index d82101ff8..000000000 --- a/locked-asset/simple-lock-whitelist/wasm/src/lib.rs +++ /dev/null @@ -1,51 +0,0 @@ -// Code generated by the multiversx-sc build system. DO NOT EDIT. - -//////////////////////////////////////////////////// -////////////////// AUTO-GENERATED ////////////////// -//////////////////////////////////////////////////// - -// Init: 1 -// Endpoints: 25 -// Async Callback: 1 -// Total number of exported functions: 27 - -#![no_std] -#![allow(internal_features)] -#![feature(lang_items)] - -multiversx_sc_wasm_adapter::allocator!(); -multiversx_sc_wasm_adapter::panic_handler!(); - -multiversx_sc_wasm_adapter::endpoints! { - simple_lock_whitelist - ( - 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 8f6b5bd1d..b867f2aa3 100644 --- a/locked-asset/simple-lock/Cargo.toml +++ b/locked-asset/simple-lock/Cargo.toml @@ -9,11 +9,11 @@ publish = false path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" [dependencies.common_structs] path = "../../common/common_structs" @@ -24,4 +24,4 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" diff --git a/locked-asset/simple-lock/meta/Cargo.toml b/locked-asset/simple-lock/meta/Cargo.toml index 889dce931..390737bda 100644 --- a/locked-asset/simple-lock/meta/Cargo.toml +++ b/locked-asset/simple-lock/meta/Cargo.toml @@ -8,6 +8,6 @@ authors = ["Dorin Iancu "] [dependencies.simple-lock] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/locked-asset/simple-lock/meta/src/main.rs b/locked-asset/simple-lock/meta/src/main.rs index d1db27a97..15afadd8a 100644 --- a/locked-asset/simple-lock/meta/src/main.rs +++ b/locked-asset/simple-lock/meta/src/main.rs @@ -1,3 +1,3 @@ fn main() { - multiversx_sc_meta::cli_main::(); + multiversx_sc_meta_lib::cli_main::(); } diff --git a/locked-asset/simple-lock/src/farm_interactions.rs b/locked-asset/simple-lock/src/farm_interactions.rs index 2579a7531..58ea1ae0d 100644 --- a/locked-asset/simple-lock/src/farm_interactions.rs +++ b/locked-asset/simple-lock/src/farm_interactions.rs @@ -74,7 +74,7 @@ pub trait FarmInteractionsModule { ) -> EnterFarmResultWrapper { let mut contract_call = self .farm_proxy(farm_address) - .enter_farm(caller) + .enter_farm(OptionalValue::Some(caller)) .with_esdt_transfer(EsdtTokenPayment::new( farming_token, 0, @@ -108,7 +108,7 @@ pub trait FarmInteractionsModule { ) -> ExitFarmResultWrapper { let raw_results: RawResultsType = self .farm_proxy(farm_address) - .exit_farm(caller) + .exit_farm(OptionalValue::Some(caller)) .with_esdt_transfer(EsdtTokenPayment::new( farm_token, farm_token_nonce, @@ -138,7 +138,7 @@ pub trait FarmInteractionsModule { ) -> FarmClaimRewardsResultWrapper { let raw_results: RawResultsType = self .farm_proxy(farm_address) - .claim_rewards(caller) + .claim_rewards(OptionalValue::Some(caller)) .with_esdt_transfer(EsdtTokenPayment::new( farm_token, farm_token_nonce, diff --git a/locked-asset/simple-lock/src/lib.rs b/locked-asset/simple-lock/src/lib.rs index 5db24f38e..fb59b792c 100644 --- a/locked-asset/simple-lock/src/lib.rs +++ b/locked-asset/simple-lock/src/lib.rs @@ -25,7 +25,7 @@ pub trait SimpleLock: #[init] fn init(&self) {} - #[endpoint] + #[upgrade] fn upgrade(&self) {} /// Locks any token (including EGLD) until `unlock_epoch` and receive meta ESDT LOCKED tokens. diff --git a/locked-asset/simple-lock/src/proxy_farm.rs b/locked-asset/simple-lock/src/proxy_farm.rs index 1d1a918d2..9defead0c 100644 --- a/locked-asset/simple-lock/src/proxy_farm.rs +++ b/locked-asset/simple-lock/src/proxy_farm.rs @@ -214,7 +214,7 @@ pub trait ProxyFarmModule: farm_address, farm_proxy_token_attributes.farm_token_id, farm_proxy_token_attributes.farm_token_nonce, - payment.amount, + payment.amount.clone(), caller.clone(), ); require!( @@ -236,6 +236,15 @@ pub trait ProxyFarmModule: &lp_proxy_token_payment.amount, ); + if payment.amount > lp_proxy_token_payment.amount { + let penalty_amount = &payment.amount - &lp_proxy_token_payment.amount; + + self.lp_proxy_token().nft_burn( + farm_proxy_token_attributes.farming_token_locked_nonce, + &penalty_amount, + ); + } + if exit_farm_result.reward_tokens.amount > 0 { self.send().direct_esdt( &caller, diff --git a/locked-asset/simple-lock/wasm/Cargo.lock b/locked-asset/simple-lock/wasm/Cargo.lock index e5957696c..8e5ac6f77 100644 --- a/locked-asset/simple-lock/wasm/Cargo.lock +++ b/locked-asset/simple-lock/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common_structs" @@ -72,32 +72,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -107,9 +109,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -120,18 +122,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -147,27 +149,27 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -201,15 +203,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -222,6 +224,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" diff --git a/locked-asset/simple-lock/wasm/Cargo.toml b/locked-asset/simple-lock/wasm/Cargo.toml index cc2cf0244..1fba97b63 100644 --- a/locked-asset/simple-lock/wasm/Cargo.toml +++ b/locked-asset/simple-lock/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.simple-lock] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [workspace] members = ["."] diff --git a/locked-asset/simple-lock/wasm/src/lib.rs b/locked-asset/simple-lock/wasm/src/lib.rs index 4e1b87c7d..eeafb6cb1 100644 --- a/locked-asset/simple-lock/wasm/src/lib.rs +++ b/locked-asset/simple-lock/wasm/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 20 +// Upgrade: 1 +// Endpoints: 19 // Async Callback: 1 // Total number of exported functions: 22 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); diff --git a/locked-asset/token-unstake/Cargo.toml b/locked-asset/token-unstake/Cargo.toml index da727566e..c196d7267 100644 --- a/locked-asset/token-unstake/Cargo.toml +++ b/locked-asset/token-unstake/Cargo.toml @@ -9,7 +9,7 @@ publish = false path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.mergeable] @@ -39,7 +39,7 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" [dev-dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" diff --git a/locked-asset/token-unstake/meta/Cargo.toml b/locked-asset/token-unstake/meta/Cargo.toml index fb4914c3d..ae328f839 100644 --- a/locked-asset/token-unstake/meta/Cargo.toml +++ b/locked-asset/token-unstake/meta/Cargo.toml @@ -8,6 +8,6 @@ publish = false [dependencies.token-unstake] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/locked-asset/token-unstake/meta/src/main.rs b/locked-asset/token-unstake/meta/src/main.rs index 06c11e497..874c422c1 100644 --- a/locked-asset/token-unstake/meta/src/main.rs +++ b/locked-asset/token-unstake/meta/src/main.rs @@ -1,3 +1,3 @@ fn main() { - multiversx_sc_meta::cli_main::(); + multiversx_sc_meta_lib::cli_main::(); } diff --git a/locked-asset/token-unstake/src/lib.rs b/locked-asset/token-unstake/src/lib.rs index 6295d46a2..985e91be9 100644 --- a/locked-asset/token-unstake/src/lib.rs +++ b/locked-asset/token-unstake/src/lib.rs @@ -42,6 +42,6 @@ pub trait TokenUnstakeModule: self.fees_burn_percentage().set(fees_burn_percentage); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} } diff --git a/locked-asset/token-unstake/wasm/Cargo.lock b/locked-asset/token-unstake/wasm/Cargo.lock index d74f133fa..788eb7478 100644 --- a/locked-asset/token-unstake/wasm/Cargo.lock +++ b/locked-asset/token-unstake/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common-types" @@ -119,32 +119,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -154,9 +156,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -167,18 +169,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -194,27 +196,27 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -248,15 +250,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -291,6 +293,12 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + [[package]] name = "unwrappable" version = "0.0.0" diff --git a/locked-asset/token-unstake/wasm/Cargo.toml b/locked-asset/token-unstake/wasm/Cargo.toml index f3e21bb9b..11bdee610 100644 --- a/locked-asset/token-unstake/wasm/Cargo.toml +++ b/locked-asset/token-unstake/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.token-unstake] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [workspace] members = ["."] diff --git a/locked-asset/token-unstake/wasm/src/lib.rs b/locked-asset/token-unstake/wasm/src/lib.rs index 396d02ba0..ea93ce423 100644 --- a/locked-asset/token-unstake/wasm/src/lib.rs +++ b/locked-asset/token-unstake/wasm/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 11 +// Upgrade: 1 +// Endpoints: 10 // Async Callback (empty): 1 // Total number of exported functions: 13 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); diff --git a/pause-all/Cargo.toml b/pause-all/Cargo.toml index 30046978d..6f03bfb68 100644 --- a/pause-all/Cargo.toml +++ b/pause-all/Cargo.toml @@ -12,14 +12,14 @@ path = "src/lib.rs" path = "../common/modules/pausable" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.53.2" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.53.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.53.2" [dev-dependencies.farm] path = "../dex/farm" diff --git a/pause-all/meta/Cargo.toml b/pause-all/meta/Cargo.toml index f6be6643e..0dbb64a9e 100644 --- a/pause-all/meta/Cargo.toml +++ b/pause-all/meta/Cargo.toml @@ -10,6 +10,6 @@ authors = ["MultiversX "] [dependencies.pause-all] path = ".." -[dependencies.multiversx-sc-meta] -version = "0.46.1" +[dependencies.multiversx-sc-meta-lib] +version = "0.53.2" default-features = false diff --git a/pause-all/meta/src/main.rs b/pause-all/meta/src/main.rs index b23720203..38584f572 100644 --- a/pause-all/meta/src/main.rs +++ b/pause-all/meta/src/main.rs @@ -1,3 +1,3 @@ fn main() { - multiversx_sc_meta::cli_main::(); + multiversx_sc_meta_lib::cli_main::(); } diff --git a/pause-all/src/lib.rs b/pause-all/src/lib.rs index 6e9bcd823..05f7fe541 100644 --- a/pause-all/src/lib.rs +++ b/pause-all/src/lib.rs @@ -28,7 +28,7 @@ pub trait PauseAll: #[init] fn init(&self) {} - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[only_owner] diff --git a/pause-all/wasm/Cargo.lock b/pause-all/wasm/Cargo.lock index d1b8021d6..789d6a687 100644 --- a/pause-all/wasm/Cargo.lock +++ b/pause-all/wasm/Cargo.lock @@ -4,21 +4,21 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "common_errors" @@ -47,32 +47,34 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "75ea89a26f0aacda21437a8ae5ccfbefab99d8191942b3d2eddbcbf84f9866d7" dependencies = [ "bitflags", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", "num-traits", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -82,9 +84,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "4c17fdf90fafca2f19085ae67b0502d9f71bf8ab1be3c83808eb88e02a8c18b9" dependencies = [ "hex", "proc-macro2", @@ -95,18 +97,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "daeb48acbd39255868a3241798df2f85050f0ae8d82d6417bd2cd0e30a241855" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.53.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "20659915a4377d375c46d7f237e810053a03f7e084fad6362dd5748a7233defb" dependencies = [ "multiversx-sc", ] @@ -122,9 +124,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -165,18 +167,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.75" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -193,15 +195,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.48" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -213,3 +215,9 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" diff --git a/pause-all/wasm/Cargo.toml b/pause-all/wasm/Cargo.toml index ccffee39c..b0301f784 100644 --- a/pause-all/wasm/Cargo.toml +++ b/pause-all/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.pause-all] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.53.2" [workspace] members = ["."] diff --git a/pause-all/wasm/src/lib.rs b/pause-all/wasm/src/lib.rs index 2302b1e6a..88f01cb87 100644 --- a/pause-all/wasm/src/lib.rs +++ b/pause-all/wasm/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 8 +// Upgrade: 1 +// Endpoints: 7 // Async Callback (empty): 1 // Total number of exported functions: 10 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!();