diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index afa63aa92..6becbecc0 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.2.0 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..352ab4397 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.2.0 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..d5983c1c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,9 +14,9 @@ dependencies = [ [[package]] name = "addr2line" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" dependencies = [ "gimli", ] @@ -27,58 +27,77 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if 1.0.0", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "aho-corasick" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] [[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,9 +105,18 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.79" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" + +[[package]] +name = "arbitrary" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" +dependencies = [ + "derive_arbitrary", +] [[package]] name = "arrayvec" @@ -96,38 +124,38 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[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 = "backtrace" -version = "0.3.69" +version = "0.3.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" dependencies = [ "addr2line", "cc", "cfg-if 1.0.0", "libc", - "miniz_oxide", + "miniz_oxide 0.7.4", "object", "rustc-demangle", ] [[package]] name = "base64" -version = "0.21.7" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" - -[[package]] -name = "base64ct" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bech32" @@ -142,8 +170,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93f2635620bf0b9d4576eb7bb9a38a55df78bd1205d26fa994b25911a69f212f" dependencies = [ "bitcoin_hashes", - "rand", - "rand_core", + "rand 0.8.5", + "rand_core 0.6.4", "serde", "unicode-normalization", ] @@ -156,15 +184,18 @@ checksum = "90064b8dee6815a6470d60bad07bbbaee885c0e12d04177138fa3291a01b7bc4" [[package]] name = "bitflags" -version = "1.3.2" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] -name = "bitflags" -version = "2.4.2" +name = "block-buffer" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] [[package]] name = "block-buffer" @@ -177,9 +208,9 @@ dependencies = [ [[package]] name = "bstr" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c48f0051a4b4c5e0b6d365cd04af53aeaa209e3cc15ec2cdb69e73cc87fbd0dc" +checksum = "40723b8fb387abc38f4f4a37c09073622e41dd12327033091ef8950659e6dc0c" dependencies = [ "memchr", "serde", @@ -187,9 +218,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.14.0" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "byteorder" @@ -199,17 +230,17 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.5.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" [[package]] name = "cc" -version = "1.0.83" +version = "1.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6" dependencies = [ - "libc", + "shlex", ] [[package]] @@ -226,9 +257,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 +267,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 +279,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 +291,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" @@ -323,12 +354,6 @@ dependencies = [ "token_send", ] -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - [[package]] name = "contexts" version = "0.0.0" @@ -376,24 +401,24 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[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" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" dependencies = [ "cfg-if 1.0.0", ] @@ -419,9 +444,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.19" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] name = "crypto-common" @@ -435,42 +460,28 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "4.1.1" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89b8c6a2e4b1f45971ad09761aafb85514a84744b67a95e32c3cc1352d1f65c" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" dependencies = [ - "cfg-if 1.0.0", - "cpufeatures", - "curve25519-dalek-derive", - "digest", - "fiat-crypto", - "platforms", - "rustc_version", + "byteorder", + "digest 0.9.0", + "rand_core 0.5.1", "subtle", "zeroize", ] [[package]] -name = "curve25519-dalek-derive" -version = "0.1.1" +name = "derive_arbitrary" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" dependencies = [ "proc-macro2", "quote", "syn", ] -[[package]] -name = "der" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "dex-tests" version = "0.0.0" @@ -497,17 +508,37 @@ dependencies = [ "simple-lock", ] +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + [[package]] name = "digest" version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer", + "block-buffer 0.10.4", "crypto-common", "subtle", ] +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "distribution" version = "0.0.0" @@ -552,39 +583,38 @@ dependencies = [ [[package]] name = "ed25519" -version = "2.2.3" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" dependencies = [ - "pkcs8", "signature", ] [[package]] name = "ed25519-dalek" -version = "2.1.1" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" +checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" dependencies = [ "curve25519-dalek", "ed25519", + "rand 0.7.3", "serde", - "sha2", - "subtle", + "sha2 0.9.9", "zeroize", ] [[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 = "encoding_rs" -version = "0.8.33" +version = "0.8.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" dependencies = [ "cfg-if 1.0.0", ] @@ -668,6 +698,29 @@ dependencies = [ "multiversx-sc-meta", ] +[[package]] +name = "env_filter" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -676,9 +729,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ "libc", "windows-sys 0.52.0", @@ -722,6 +775,27 @@ dependencies = [ "multiversx-sc-meta", ] +[[package]] +name = "factory-legacy" +version = "0.0.0" +dependencies = [ + "common_errors", + "common_structs", + "energy-factory", + "multiversx-sc", + "multiversx-sc-modules", + "multiversx-sc-scenario", + "token_merge_helper", +] + +[[package]] +name = "factory-legacy-meta" +version = "0.0.0" +dependencies = [ + "factory-legacy", + "multiversx-sc-meta", +] + [[package]] name = "farm" version = "0.0.0" @@ -857,6 +931,106 @@ dependencies = [ "multiversx-sc-meta", ] +[[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", +] + +[[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", +] + +[[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", +] + +[[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", +] + +[[package]] +name = "farm-v13-meta" +version = "0.0.0" +dependencies = [ + "farm-v13", + "multiversx-sc-meta", +] + [[package]] name = "farm-with-locked-rewards" version = "0.0.0" @@ -937,9 +1111,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.1" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" [[package]] name = "fees-collector" @@ -969,12 +1143,6 @@ dependencies = [ "multiversx-sc-meta", ] -[[package]] -name = "fiat-crypto" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1676f435fc1dadde4d03e43f5d62b259e1ce5f40bd4ffb21db2b42ebe59c1382" - [[package]] name = "fixed-supply-token" version = "0.0.0" @@ -984,12 +1152,12 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.28" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +checksum = "324a1be68054ef05ad64b861cc9eaf1d623d2d8cb25b4bf2cb9cdd902b4bf253" dependencies = [ "crc32fast", - "miniz_oxide", + "miniz_oxide 0.8.0", ] [[package]] @@ -1022,6 +1190,21 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + [[package]] name = "futures-channel" version = "0.3.30" @@ -1029,6 +1212,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -1037,12 +1221,34 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + [[package]] name = "futures-io" version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "futures-sink" version = "0.3.30" @@ -1061,8 +1267,11 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ + "futures-channel", "futures-core", "futures-io", + "futures-macro", + "futures-sink", "futures-task", "memchr", "pin-project-lite", @@ -1087,7 +1296,7 @@ dependencies = [ "pair-mock", "pausable", "price-discovery", - "rand", + "rand 0.8.5", "rewards", "router", "simple-lock", @@ -1105,20 +1314,31 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.12" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if 1.0.0", "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", ] [[package]] name = "gimli" -version = "0.28.1" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] name = "globset" @@ -1175,15 +1395,15 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.24" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb2c4422095b67ee78da96fbb51a4cc413b3b25883c7717ff7ca1ab31022c9c9" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" dependencies = [ + "atomic-waker", "bytes", "fnv", "futures-core", "futures-sink", - "futures-util", "http", "indexmap", "slab", @@ -1194,21 +1414,25 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "serde", +] [[package]] name = "heck" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hermit-abi" -version = "0.3.5" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0c62115964e08cb8039170eb33c1d0e2388a256930279edca206fff675f82c3" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "hex" @@ -1234,14 +1458,14 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "digest", + "digest 0.10.7", ] [[package]] name = "http" -version = "0.2.11" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ "bytes", "fnv", @@ -1250,62 +1474,110 @@ dependencies = [ [[package]] name = "http-body" -version = "0.4.6" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ "bytes", "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", "pin-project-lite", ] [[package]] name = "httparse" -version = "1.8.0" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" [[package]] -name = "httpdate" -version = "1.0.3" +name = "humantime" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.28" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ "bytes", "futures-channel", - "futures-core", "futures-util", "h2", "http", "http-body", "httparse", - "httpdate", "itoa", "pin-project-lite", - "socket2", + "smallvec", "tokio", - "tower-service", - "tracing", "want", ] +[[package]] +name = "hyper-rustls" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + [[package]] name = "hyper-tls" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" dependencies = [ "bytes", + "http-body-util", "hyper", + "hyper-util", "native-tls", "tokio", "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cde7055719c54e36e95e8719f95883f22072a48ede39db7fc17a4e1d5281e9b9" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", ] [[package]] @@ -1336,12 +1608,13 @@ dependencies = [ [[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]] @@ -1350,6 +1623,12 @@ version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itertools" version = "0.10.5" @@ -1361,24 +1640,24 @@ 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" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "js-sys" -version = "0.3.68" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ "wasm-bindgen", ] @@ -1394,9 +1673,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 +1688,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.153" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "linux-raw-sys" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "lkmex-transfer" @@ -1446,9 +1725,9 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -1482,6 +1761,12 @@ dependencies = [ "multiversx-sc-meta", ] +[[package]] +name = "lockfree-object-pool" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9374ef4228402d4b7e403e5838cb880d9ee663314b0a900d5a6aabf0c213552e" + [[package]] name = "locking_module" version = "0.0.0" @@ -1493,9 +1778,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,9 +1791,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.1" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "memory_units" @@ -1551,29 +1836,39 @@ checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "miniz_oxide" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" dependencies = [ "adler", ] +[[package]] +name = "miniz_oxide" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +dependencies = [ + "adler2", +] + [[package]] name = "mio" -version = "0.8.10" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ + "hermit-abi", "libc", - "wasi", - "windows-sys 0.48.0", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys 0.52.0", ] [[package]] name = "multiversx-chain-scenario-format" -version = "0.21.1" +version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfc2b1dc76af14c24145672c2779474046ab44ef56bac82a58844328f4b4d2e" +checksum = "921a66f6db5ffff311e355d42a49fd49baf72d7a6a6215b0484dcd9d8dd512a3" dependencies = [ "bech32", "hex", @@ -1586,21 +1881,22 @@ dependencies = [ [[package]] name = "multiversx-chain-vm" -version = "0.7.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75459864359798406a45a7bb2ed221d623b2e39484ec3e4ac6d23167bfc50b33" +checksum = "a8d91b6ce610a3ac1272f0813284a3f03a34d55db2f86cddaff357bf651074ee" 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", - "rand", + "rand 0.8.5", "rand_seeder", - "sha2", + "sha2 0.10.8", "sha3", ] @@ -1612,33 +1908,35 @@ checksum = "b59072fa0624b55ae5ae3fa6bfa91515bbeb4ac440214bc4a509e2c8806d6e9f" [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", "num-bigint", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -1648,9 +1946,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -1661,72 +1959,107 @@ dependencies = [ [[package]] name = "multiversx-sc-meta" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c8250fd72b78dff76fd3789078aee3dec2524ca37250c645dcb2b1bf067551e" +checksum = "df1e5defa15d0195cb93f12b0a09220d9e94fe4fd86f2657c19272402c4083ac" dependencies = [ "clap", "colored", "common-path", "convert_case", "copy_dir", - "hex", - "lazy_static", "multiversx-sc", + "multiversx-sc-meta-lib", + "multiversx-sc-snippets", "pathdiff", "reqwest", "ruplacer", + "semver", + "serde", + "serde_json", + "tokio", + "toml", + "zip", +] + +[[package]] +name = "multiversx-sc-meta-lib" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8deccfcc760b8fd281e2603268fa1a453ed65e4caac7a51a2d71c40cec37ae3" +dependencies = [ + "clap", + "colored", + "convert_case", + "hex", + "lazy_static", + "multiversx-sc", "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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-scenario" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3aa2644018c85caf3cc39a130961e39bd719ff3d75751b60a7394d6eace1c847" +checksum = "5d3024d52e2cb7d455f5a560218be8968e446eabc7c31dc9fc479c329f45e05e" 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", + "sha2 0.10.8", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-snippets" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94bbd06d14e07875e92453bfe19557e1b3f2239af18b9cd3a8f05a19f4111df3" +dependencies = [ + "base64", + "env_logger", + "futures", + "hex", + "log", + "multiversx-chain-scenario-format", + "multiversx-sc-scenario", + "multiversx-sdk", "tokio", ] [[package]] name = "multiversx-sdk" -version = "0.3.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f86d0da66ca2eb334414786a287010bb669b8d815a7d3b690d629a04b86bb80" +checksum = "139f1ac6d82e743dd3ae303e47134ab17b7c3e3c4306f09bed11a6054822596c" dependencies = [ "anyhow", "base64", @@ -1734,15 +2067,16 @@ dependencies = [ "bip39", "hex", "hmac", - "itertools 0.12.1", + "itertools 0.13.0", + "log", "pbkdf2", "pem", - "rand", + "rand 0.8.5", "reqwest", "serde", "serde_json", "serde_repr", - "sha2", + "sha2 0.10.8", "sha3", "tokio", "zeroize", @@ -1750,11 +2084,10 @@ dependencies = [ [[package]] name = "native-tls" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" dependencies = [ - "lazy_static", "libc", "log", "openssl", @@ -1777,49 +2110,37 @@ 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" +version = "0.36.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" dependencies = [ "memchr", ] @@ -1830,13 +2151,19 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "opaque-debug" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" + [[package]] name = "openssl" -version = "0.10.63" +version = "0.10.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c9d69dd87a29568d4d017cfe8ec518706046a05184e5aea92d0af890b803c8" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" dependencies = [ - "bitflags 2.4.2", + "bitflags", "cfg-if 1.0.0", "foreign-types", "libc", @@ -1864,9 +2191,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.99" +version = "0.9.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e1bf214306098e4832460f797824c05d25aacdf896f64a985fb0fd992454ae" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" dependencies = [ "cc", "libc", @@ -1920,9 +2247,9 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", "parking_lot_core", @@ -1930,15 +2257,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.9" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if 1.0.0", "libc", "redox_syscall", "smallvec", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -1981,14 +2308,14 @@ version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" dependencies = [ - "digest", + "digest 0.10.7", ] [[package]] name = "pem" -version = "3.0.3" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8fcc794035347fb64beda2d3b462595dd2753e3f268d89c5aae77e8cf2c310" +checksum = "8e459365e590736a54c3fa561947c84837534b8e9af6fc5bf781307e82658fae" dependencies = [ "base64", "serde", @@ -2004,50 +2331,57 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" 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" +name = "pin-project" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] [[package]] -name = "pin-utils" -version = "0.1.0" +name = "pin-project-internal" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] -name = "pkcs8" -version = "0.10.2" +name = "pin-project-lite" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" [[package]] -name = "pkg-config" -version = "0.3.29" +name = "pin-utils" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] -name = "platforms" -version = "3.3.0" +name = "pkg-config" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "626dec3cac7cc0e1577a2ec3fc496277ec2baa084bebad95bb6fdbfae235f84c" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[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" @@ -2072,11 +2406,45 @@ dependencies = [ "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", + "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", + "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", ] @@ -2102,6 +2470,29 @@ dependencies = [ "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", + "proxy-dex-legacy", +] + [[package]] name = "proxy_dex" version = "0.0.0" @@ -2146,9 +2537,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -2163,6 +2554,19 @@ dependencies = [ "nibble_vec", ] +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom 0.1.16", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc", +] + [[package]] name = "rand" version = "0.8.5" @@ -2170,8 +2574,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha", - "rand_core", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", ] [[package]] @@ -2181,7 +2595,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", ] [[package]] @@ -2190,7 +2613,16 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.15", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", ] [[package]] @@ -2199,23 +2631,23 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf2890aaef0aa82719a50e808de264f9484b74b442e1a3a0e5ee38243ac40bdb" dependencies = [ - "rand_core", + "rand_core 0.6.4", ] [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" dependencies = [ - "bitflags 1.3.2", + "bitflags", ] [[package]] name = "regex" -version = "1.10.3" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", @@ -2225,9 +2657,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.5" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", @@ -2236,26 +2668,30 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.2" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "reqwest" -version = "0.11.24" +version = "0.12.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6920094eb85afde5e4a138be3f2de8bbdf28000f0029e72c45025a56b042251" +checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" dependencies = [ "base64", "bytes", "encoding_rs", + "futures-channel", "futures-core", "futures-util", "h2", "http", "http-body", + "http-body-util", "hyper", + "hyper-rustls", "hyper-tls", + "hyper-util", "ipnet", "js-sys", "log", @@ -2277,7 +2713,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "winreg", + "windows-registry", ] [[package]] @@ -2295,6 +2731,21 @@ dependencies = [ "token_send", ] +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if 1.0.0", + "getrandom 0.2.15", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "router" version = "0.0.0" @@ -2332,46 +2783,77 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[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" +version = "0.38.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" +checksum = "a85d50532239da68e9addb745ba38ff4612a242c1c7ceea689c4bc7c2f43c36f" dependencies = [ - "bitflags 2.4.2", + "bitflags", "errno", "libc", "linux-raw-sys", "windows-sys 0.52.0", ] +[[package]] +name = "rustls" +version = "0.23.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + [[package]] name = "rustls-pemfile" -version = "1.0.4" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" dependencies = [ "base64", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" + +[[package]] +name = "rustls-webpki" +version = "0.102.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84678086bd54edf2b415183ed7a94d0efb049f1b646a33e22a36f3794be6ae56" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", ] [[package]] name = "ryu" -version = "1.0.16" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "same-file" @@ -2407,11 +2889,11 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "security-framework" -version = "2.9.2" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ - "bitflags 1.3.2", + "bitflags", "core-foundation", "core-foundation-sys", "libc", @@ -2420,9 +2902,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.9.1" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" +checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" dependencies = [ "core-foundation-sys", "libc", @@ -2430,24 +2912,24 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.21" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.196" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" +checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.196" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" +checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" dependencies = [ "proc-macro2", "quote", @@ -2456,21 +2938,22 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.113" +version = "1.0.127" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79" +checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" dependencies = [ "indexmap", "itoa", + "memchr", "ryu", "serde", ] [[package]] name = "serde_repr" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb" +checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", @@ -2479,9 +2962,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.5" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" dependencies = [ "serde", ] @@ -2498,6 +2981,19 @@ dependencies = [ "serde", ] +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", +] + [[package]] name = "sha2" version = "0.10.8" @@ -2506,7 +3002,7 @@ checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if 1.0.0", "cpufeatures", - "digest", + "digest 0.10.7", ] [[package]] @@ -2515,27 +3011,36 @@ version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" dependencies = [ - "digest", + "digest 0.10.7", "keccak", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signal-hook-registry" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" dependencies = [ "libc", ] [[package]] name = "signature" -version = "2.2.0" +version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "rand_core", -] +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" + +[[package]] +name = "simd-adler32" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" [[package]] name = "simple-lock" @@ -2551,33 +3056,32 @@ 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", + "simple-lock-legacy", +] + +[[package]] +name = "simple-lock-meta" +version = "0.0.0" +dependencies = [ + "multiversx-sc-meta", + "simple-lock", ] [[package]] @@ -2591,47 +3095,43 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.13.1" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" -version = "0.5.5" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] -name = "spki" -version = "0.7.3" +name = "spin" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", -] +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" dependencies = [ "proc-macro2", "quote", @@ -2640,26 +3140,29 @@ dependencies = [ [[package]] name = "sync_wrapper" -version = "0.1.2" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] [[package]] name = "system-configuration" -version = "0.5.1" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" dependencies = [ - "bitflags 1.3.2", + "bitflags", "core-foundation", "system-configuration-sys", ] [[package]] name = "system-configuration-sys" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" dependencies = [ "core-foundation-sys", "libc", @@ -2667,21 +3170,51 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.10.0" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a365e8cd18e44762ef95d87f284f4b5cd04107fec2ff3052bd6a3e6069669e67" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" dependencies = [ "cfg-if 1.0.0", "fastrand", + "once_cell", "rustix", - "windows-sys 0.52.0", + "windows-sys 0.59.0", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thiserror" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] name = "tinyvec" -version = "1.6.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" dependencies = [ "tinyvec_macros", ] @@ -2738,28 +3271,27 @@ dependencies = [ [[package]] name = "tokio" -version = "1.36.0" +version = "1.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" dependencies = [ "backtrace", "bytes", "libc", "mio", - "num_cpus", "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "tokio-macros" -version = "2.2.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", @@ -2776,25 +3308,35 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + [[package]] name = "tokio-util" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" 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 +3347,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,11 +3367,32 @@ dependencies = [ "winnow", ] +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + [[package]] name = "tower-service" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" [[package]] name = "tracing" @@ -2889,6 +3452,18 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[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" @@ -2898,9 +3473,9 @@ dependencies = [ [[package]] name = "url" -version = "2.5.0" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" dependencies = [ "form_urlencoded", "idna", @@ -2909,9 +3484,9 @@ dependencies = [ [[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" @@ -2931,15 +3506,15 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "walkdir" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" dependencies = [ "same-file", "winapi-util", @@ -2954,6 +3529,12 @@ dependencies = [ "try-lock", ] +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -2962,19 +3543,20 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.91" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" dependencies = [ "cfg-if 1.0.0", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.91" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" dependencies = [ "bumpalo", "log", @@ -2987,9 +3569,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.41" +version = "0.4.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877b9c3f61ceea0e56331985743b13f3d25c406a7098d45180fb5f09bc19ed97" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -2999,9 +3581,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.91" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3009,9 +3591,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.91" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", @@ -3022,46 +3604,40 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.91" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" [[package]] name = "wasmparser" -version = "0.118.1" +version = "0.214.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ee9723b928e735d53000dec9eae7b07a60e490c85ab54abb66659fc61bfcd9" +checksum = "5309c1090e3e84dad0d382f42064e9933fdaedb87e468cc239f0eabea73ddcb6" dependencies = [ + "ahash", + "bitflags", + "hashbrown", "indexmap", "semver", -] - -[[package]] -name = "wasmparser" -version = "0.121.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953cf6a7606ab31382cb1caa5ae403e77ba70c7f8e12eeda167e7040d42bfda8" -dependencies = [ - "bitflags 2.4.2", - "indexmap", - "semver", + "serde", ] [[package]] name = "wasmprinter" -version = "0.2.78" +version = "0.214.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05e32c13c59fdc64d3f6998a1d52eb1d362b6904a88b754190ccb85661ad577a" +checksum = "58d4f2b3f7bd2ba10f99e03f885ff90d5db3455e163bccecebbbf60406bd8980" dependencies = [ "anyhow", - "wasmparser 0.121.0", + "termcolor", + "wasmparser", ] [[package]] name = "web-sys" -version = "0.3.68" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96565907687f7aceb35bc5fc03770a8a0471d82e479f25832f54a0e3f4b28446" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" dependencies = [ "js-sys", "wasm-bindgen", @@ -3117,11 +3693,11 @@ 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]] @@ -3130,6 +3706,36 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -3145,7 +3751,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 +3780,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 +3802,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 +3814,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 +3826,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 = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -3222,9 +3844,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 +3856,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 +3868,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 +3880,87 @@ 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 = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] name = "zeroize" -version = "1.7.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "zip" -version = "0.6.6" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" +checksum = "dc5e4288ea4057ae23afc69a4472434a87a2495cafce6632fd1c4ec9f5cf3494" dependencies = [ - "byteorder", + "arbitrary", "crc32fast", "crossbeam-utils", + "displaydoc", "flate2", + "indexmap", + "memchr", + "thiserror", + "zopfli", +] + +[[package]] +name = "zopfli" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5019f391bac5cf252e93bbcc53d039ffd62c7bfb7c150414d61369afe57e946" +dependencies = [ + "bumpalo", + "crc32fast", + "lockfree-object-pool", + "log", + "once_cell", + "simd-adler32", ] diff --git a/Cargo.toml b/Cargo.toml index dbdd0d3ec..6c3af3ab3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,27 @@ members = [ "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/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", + "locked-asset/", "locked-asset/distribution", "locked-asset/distribution/meta", @@ -50,8 +71,6 @@ members = [ "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..6fee8d60d 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.52.3" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/common_structs/Cargo.toml b/common/common_structs/Cargo.toml index 8e5655f12..e16ae99a1 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.52.3" 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..a23429f55 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.52.3" 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..759895606 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" 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..4da2574ee 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.52.3" 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..67bae38bd 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.52.3" 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..7b8c589a6 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" diff --git a/common/modules/farm/farm_token_merge/Cargo.toml b/common/modules/farm/farm_token_merge/Cargo.toml index 4df9540e8..5c3396d85 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" [workspace] members = ["."] diff --git a/common/modules/farm/rewards/Cargo.toml b/common/modules/farm/rewards/Cargo.toml index 68d37f46d..224f8f83d 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" diff --git a/common/modules/legacy_token_decode_module/Cargo.toml b/common/modules/legacy_token_decode_module/Cargo.toml index 124b2ec02..92ac7fccf 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.52.3" 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..78cc80724 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.52.3" 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..df63fe034 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.52.3" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/pausable/Cargo.toml b/common/modules/pausable/Cargo.toml index 2f258161b..840683ef3 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.52.3" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/permissions_module/Cargo.toml b/common/modules/permissions_module/Cargo.toml index fdc8d7d2e..a64b00a6f 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.52.3" 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..3aa5b143c 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.52.3" 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..92a71b34d 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.52.3" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/token_send/Cargo.toml b/common/modules/token_send/Cargo.toml index 28b005064..30ccb3efa 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.52.3" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/modules/utils/Cargo.toml b/common/modules/utils/Cargo.toml index a18635d6e..e38f8fe90 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.52.3" 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..6e733792a 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.52.3" diff --git a/common/traits/mergeable/Cargo.toml b/common/traits/mergeable/Cargo.toml index 4800de5ca..f5ee4681a 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.52.3" features = ["esdt-token-payment-legacy-decode"] diff --git a/common/traits/unwrappable/Cargo.toml b/common/traits/unwrappable/Cargo.toml index 9ba6e7e73..f4697c4b7 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.52.3" features = ["esdt-token-payment-legacy-decode"] diff --git a/dex/Cargo.toml b/dex/Cargo.toml index 62d9161bf..df2fd1e57 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.52.3" [dev-dependencies.config] path = "../common/modules/farm/config" diff --git a/dex/farm-with-locked-rewards/Cargo.toml b/dex/farm-with-locked-rewards/Cargo.toml index c19480688..02e2190bb 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.52.3" [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..a273b797a 100644 --- a/dex/farm-with-locked-rewards/meta/Cargo.toml +++ b/dex/farm-with-locked-rewards/meta/Cargo.toml @@ -9,5 +9,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false diff --git a/dex/farm-with-locked-rewards/src/lib.rs b/dex/farm-with-locked-rewards/src/lib.rs index a42f6518c..972ddbbd7 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,21 @@ 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" ); } + 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 +260,18 @@ 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); + self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); + 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..6fbeb9cc6 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,7 @@ #![allow(deprecated)] use common_structs::FarmTokenAttributes; +use multiversx_sc::codec::Empty; use multiversx_sc_scenario::{managed_address, managed_biguint, rust_biguint, DebugApi}; use simple_lock::locked_token::LockedTokenAttributes; @@ -335,3 +336,195 @@ 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); + + let second_week_received_reward_amt = + farm_setup.claim_boosted_rewards_for_user(&temp_user, &temp_user, 0); + + assert_eq!(second_week_received_reward_amt, 0); + farm_setup.check_farm_rps(150_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 * 2); // user receives rewards for weeks 1 and 2) + 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, + ); +} diff --git a/dex/farm-with-locked-rewards/wasm/Cargo.lock b/dex/farm-with-locked-rewards/wasm/Cargo.lock index f3af20c87..81b781351 100644 --- a/dex/farm-with-locked-rewards/wasm/Cargo.lock +++ b/dex/farm-with-locked-rewards/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -350,9 +352,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -363,18 +365,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..5e02cdde1 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.52.3" [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..34af0d038 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" [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.52.3" [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..932e0ad31 100644 --- a/dex/farm/meta/Cargo.toml +++ b/dex/farm/meta/Cargo.toml @@ -9,5 +9,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false 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..aeabcaaa0 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,23 @@ 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" ); } + 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 +261,18 @@ 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); + self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id); + 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..9cb7e7e72 100644 --- a/dex/farm/wasm/Cargo.lock +++ b/dex/farm/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -320,9 +322,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -333,18 +335,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..5283ecab3 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.52.3" [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..cd7c3fa7c 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.52.3" [dependencies.pausable] path = "../../common/modules/pausable" diff --git a/dex/fuzz/src/fuzz_data.rs b/dex/fuzz/src/fuzz_data.rs index 14de4e7c3..d7c78c494 100644 --- a/dex/fuzz/src/fuzz_data.rs +++ b/dex/fuzz/src/fuzz_data.rs @@ -151,7 +151,6 @@ pub mod fuzz_data_tests { 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, @@ -297,7 +296,6 @@ pub mod fuzz_data_tests { FuzzerData { rng, - owner_address: owner_addr, fuzz_args, statistics, blockchain_wrapper, @@ -590,7 +588,6 @@ pub mod fuzz_data_tests { { pub pd_wrapper: ContractObjWrapper, PriceDiscObjBuilder>, - pub locking_sc_address: Address, } pub fn setup_price_disc( @@ -705,10 +702,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)] diff --git a/dex/governance/Cargo.toml b/dex/governance/Cargo.toml index 74d9f2849..6ef3a8084 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.52.3" [dev-dependencies.pair-mock] path = "../pair-mock" diff --git a/dex/governance/meta/Cargo.toml b/dex/governance/meta/Cargo.toml index b692c9007..b6328ceaf 100644 --- a/dex/governance/meta/Cargo.toml +++ b/dex/governance/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false diff --git a/dex/governance/src/lib.rs b/dex/governance/src/lib.rs index e9d4147d3..460aabcda 100644 --- a/dex/governance/src/lib.rs +++ b/dex/governance/src/lib.rs @@ -49,7 +49,7 @@ pub trait Governance: self.try_change_price_providers(price_providers); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[payable("*")] diff --git a/dex/governance/wasm/Cargo.lock b/dex/governance/wasm/Cargo.lock index 30ca50940..1bcfc827a 100644 --- a/dex/governance/wasm/Cargo.lock +++ b/dex/governance/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -90,9 +92,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -103,9 +105,9 @@ dependencies = [ [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..22307fd20 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.52.3" [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..8d6627ce9 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.52.3" 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.52.3" diff --git a/dex/pair-mock/meta/Cargo.toml b/dex/pair-mock/meta/Cargo.toml index 673a8fc84..245b01fb9 100644 --- a/dex/pair-mock/meta/Cargo.toml +++ b/dex/pair-mock/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false diff --git a/dex/pair-mock/wasm/Cargo.lock b/dex/pair-mock/wasm/Cargo.lock index 6311e01de..890c8b7c3 100644 --- a/dex/pair-mock/wasm/Cargo.lock +++ b/dex/pair-mock/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -97,9 +99,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -110,9 +112,9 @@ dependencies = [ [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..3fcbc95bf 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.52.3" [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..a183ce778 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.52.3" diff --git a/dex/pair/meta/Cargo.toml b/dex/pair/meta/Cargo.toml index b07218ea1..377f6daf7 100644 --- a/dex/pair/meta/Cargo.toml +++ b/dex/pair/meta/Cargo.toml @@ -9,5 +9,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false diff --git a/dex/pair/src/lib.rs b/dex/pair/src/lib.rs index 98996e34a..e67010d67 100644 --- a/dex/pair/src/lib.rs +++ b/dex/pair/src/lib.rs @@ -12,6 +12,7 @@ pub mod fee; mod liquidity_pool; pub mod locking_wrapper; pub mod pair_actions; +pub mod read_pair_storage; pub mod safe_price; pub mod safe_price_view; @@ -33,6 +34,7 @@ pub trait Pair: + config::ConfigModule + token_send::TokenSendModule + events::EventsModule + + read_pair_storage::ReadPairStorageModule + safe_price::SafePriceModule + safe_price_view::SafePriceViewModule + contexts::output_builder::OutputBuilderModule @@ -99,7 +101,7 @@ pub trait Pair: }; } - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[endpoint(setLpTokenIdentifier)] diff --git a/dex/pair/src/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..3afa89c6d 100644 --- a/dex/pair/wasm-pair-full/Cargo.lock +++ b/dex/pair/wasm-pair-full/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -196,9 +198,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -209,18 +211,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..20504704c 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.52.3" [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..130405e72 100644 --- a/dex/pair/wasm-safe-price-view/Cargo.lock +++ b/dex/pair/wasm-safe-price-view/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -196,9 +198,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -209,18 +211,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..1c372b740 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.52.3" [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..a429c153e 100644 --- a/dex/pair/wasm/Cargo.lock +++ b/dex/pair/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -196,9 +198,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -209,18 +211,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..0aba20357 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.52.3" [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..6425eedbc 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" [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.52.3" diff --git a/dex/price-discovery/meta/Cargo.toml b/dex/price-discovery/meta/Cargo.toml index 176823d06..c8330479e 100644 --- a/dex/price-discovery/meta/Cargo.toml +++ b/dex/price-discovery/meta/Cargo.toml @@ -9,5 +9,5 @@ authors = ["Dorin Iancu "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false diff --git a/dex/price-discovery/src/lib.rs b/dex/price-discovery/src/lib.rs index 32a07acf0..b0c430e52 100644 --- a/dex/price-discovery/src/lib.rs +++ b/dex/price-discovery/src/lib.rs @@ -113,7 +113,7 @@ pub trait PriceDiscovery: self.set_locking_sc_address(locking_sc_address); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} /// Users can deposit either launched_token or accepted_token. diff --git a/dex/price-discovery/wasm/Cargo.lock b/dex/price-discovery/wasm/Cargo.lock index fbcb7ca84..49b291715 100644 --- a/dex/price-discovery/wasm/Cargo.lock +++ b/dex/price-discovery/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -154,9 +156,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -167,18 +169,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..1dcb092a2 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.52.3" [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..1cdb05f73 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.52.3" diff --git a/dex/proxy-deployer/meta/Cargo.toml b/dex/proxy-deployer/meta/Cargo.toml index 629fddbdf..dc7a4d09f 100644 --- a/dex/proxy-deployer/meta/Cargo.toml +++ b/dex/proxy-deployer/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false diff --git a/dex/proxy-deployer/src/lib.rs b/dex/proxy-deployer/src/lib.rs index a05bab7b0..7f7f0c16a 100644 --- a/dex/proxy-deployer/src/lib.rs +++ b/dex/proxy-deployer/src/lib.rs @@ -16,6 +16,6 @@ pub trait ProxyDeployer: farm_deploy::FarmDeployModule { self.farm_template_address().set(&farm_template_address); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} } diff --git a/dex/proxy-deployer/wasm/Cargo.lock b/dex/proxy-deployer/wasm/Cargo.lock index 371955a5f..d6e8501f7 100644 --- a/dex/proxy-deployer/wasm/Cargo.lock +++ b/dex/proxy-deployer/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -312,9 +314,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -325,18 +327,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..a91353591 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.52.3" [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..b542e4196 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.52.3" 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.52.3" diff --git a/dex/router/meta/Cargo.toml b/dex/router/meta/Cargo.toml index c5deaf0be..48160d8b0 100644 --- a/dex/router/meta/Cargo.toml +++ b/dex/router/meta/Cargo.toml @@ -9,5 +9,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false diff --git a/dex/router/src/config.rs b/dex/router/src/config.rs index 25c96a3e6..830d301c8 100644 --- a/dex/router/src/config.rs +++ b/dex/router/src/config.rs @@ -2,18 +2,38 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); use crate::{enable_swap_by_user::EnableSwapByUserConfig, factory::PairTokens}; +use pair::read_pair_storage; #[multiversx_sc::module] -pub trait ConfigModule { +pub trait ConfigModule: read_pair_storage::ReadPairStorageModule { fn is_active(&self) -> bool { self.state().get() } fn check_is_pair_sc(&self, pair_address: &ManagedAddress) { - require!( - self.address_pair_map().contains_key(pair_address), - "Not a pair SC" - ); + let first_token_id = self.get_first_token_id_mapper(pair_address.clone()).get(); + let second_token_id = self.get_second_token_id_mapper(pair_address.clone()).get(); + + let pair_tokens = PairTokens { + first_token_id: first_token_id.clone(), + second_token_id: second_token_id.clone(), + }; + + let mut pair_map_address_opt = self.pair_map().get(&pair_tokens); + if pair_map_address_opt.is_none() { + let reverse_pair_tokens = PairTokens { + first_token_id: second_token_id.clone(), + second_token_id: first_token_id.clone(), + }; + pair_map_address_opt = self.pair_map().get(&reverse_pair_tokens); + } + + require!(pair_map_address_opt.is_some(), "Not a pair SC"); + + unsafe { + let pair_map_address = pair_map_address_opt.unwrap_unchecked(); + require!(&pair_map_address == pair_address, "Not a pair SC"); + } } #[view(getPairCreationEnabled)] @@ -43,9 +63,6 @@ pub trait ConfigModule { #[storage_mapper("pair_map")] fn pair_map(&self) -> MapMapper, ManagedAddress>; - #[storage_mapper("address_pair_map")] - fn address_pair_map(&self) -> MapMapper>; - #[view(getPairTemplateAddress)] #[storage_mapper("pair_template_address")] fn pair_template_address(&self) -> SingleValueMapper; diff --git a/dex/router/src/contract.rs b/dex/router/src/contract.rs index 04b787a03..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/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..1e47378f9 100644 --- a/dex/router/src/multi_pair_swap.rs +++ b/dex/router/src/multi_pair_swap.rs @@ -1,11 +1,9 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); -use pair::pair_actions::swap::ProxyTrait as _; - -use crate::config; - use super::factory; +use crate::config; +use pair::{pair_actions::swap::ProxyTrait as _, read_pair_storage}; type SwapOperationType = MultiValue4, ManagedBuffer, TokenIdentifier, BigUint>; @@ -15,11 +13,17 @@ pub const SWAP_TOKENS_FIXED_OUTPUT_FUNC_NAME: &[u8] = b"swapTokensFixedOutput"; #[multiversx_sc::module] pub trait MultiPairSwap: - config::ConfigModule + factory::FactoryModule + token_send::TokenSendModule + config::ConfigModule + + read_pair_storage::ReadPairStorageModule + + factory::FactoryModule + + token_send::TokenSendModule { #[payable("*")] #[endpoint(multiPairSwap)] - fn multi_pair_swap(&self, swap_operations: MultiValueEncoded>) -> ManagedVec { + fn multi_pair_swap( + &self, + swap_operations: MultiValueEncoded>, + ) -> ManagedVec { require!(self.is_active(), "Not active"); let (token_id, nonce, amount) = self.call_value().single_esdt().into_tuple(); diff --git a/dex/router/tests/router_setup/mod.rs b/dex/router/tests/router_setup/mod.rs index c72b6a971..4339d502d 100644 --- a/dex/router/tests/router_setup/mod.rs +++ b/dex/router/tests/router_setup/mod.rs @@ -284,17 +284,4 @@ where ) .assert_ok(); } - - pub fn migrate_pair_map(&mut self) { - self.blockchain_wrapper - .execute_tx( - &self.owner_address, - &self.router_wrapper, - &rust_biguint!(0u64), - |sc| { - sc.migrate_pair_map(); - }, - ) - .assert_ok(); - } } diff --git a/dex/router/tests/router_test.rs b/dex/router/tests/router_test.rs index 54c73c838..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..7fb52d1e3 100644 --- a/dex/router/wasm/Cargo.lock +++ b/dex/router/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -196,9 +198,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -209,18 +211,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..5f51baac3 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.52.3" [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..f6cddc324 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.52.3" 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..ca761a0ac 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.52.3" 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..769bf1a02 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.52.3" 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..204f503ed 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.52.3" 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..a1786f9f7 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.52.3" diff --git a/energy-integration/energy-factory-mock/meta/Cargo.toml b/energy-integration/energy-factory-mock/meta/Cargo.toml index 94241670d..4dd743ee5 100644 --- a/energy-integration/energy-factory-mock/meta/Cargo.toml +++ b/energy-integration/energy-factory-mock/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false diff --git a/energy-integration/energy-factory-mock/wasm/Cargo.lock b/energy-integration/energy-factory-mock/wasm/Cargo.lock index 0693d6d5f..90e2d715e 100644 --- a/energy-integration/energy-factory-mock/wasm/Cargo.lock +++ b/energy-integration/energy-factory-mock/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -163,9 +165,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -176,18 +178,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..c27927d62 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.52.3" [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..cece1badc 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" [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.52.3" diff --git a/energy-integration/energy-update/meta/Cargo.toml b/energy-integration/energy-update/meta/Cargo.toml index aa816ac82..17921bd41 100644 --- a/energy-integration/energy-update/meta/Cargo.toml +++ b/energy-integration/energy-update/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false diff --git a/energy-integration/energy-update/src/lib.rs b/energy-integration/energy-update/src/lib.rs index a8e10213f..6cb9a7520 100644 --- a/energy-integration/energy-update/src/lib.rs +++ b/energy-integration/energy-update/src/lib.rs @@ -9,7 +9,7 @@ pub trait EnergyUpdate { #[init] fn init(&self) {} - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[endpoint(updateFarmsEnergyForUser)] diff --git a/energy-integration/energy-update/wasm/Cargo.lock b/energy-integration/energy-update/wasm/Cargo.lock index 559a8a519..d589409c8 100644 --- a/energy-integration/energy-update/wasm/Cargo.lock +++ b/energy-integration/energy-update/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -330,9 +332,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -343,18 +345,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..3046000d8 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.52.3" [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..635f6f12e 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.52.3" 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..71246ad74 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" [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.52.3" [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..fdf9fb2d1 100644 --- a/energy-integration/fees-collector/meta/Cargo.toml +++ b/energy-integration/fees-collector/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false 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..aefa2da06 100644 --- a/energy-integration/fees-collector/wasm/Cargo.lock +++ b/energy-integration/fees-collector/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -189,9 +191,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -202,18 +204,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..7fd11ead7 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.52.3" [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..ea148f4ba 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.52.3" 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.52.3" [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..a4d6830a6 100644 --- a/energy-integration/governance-v2/meta/Cargo.toml +++ b/energy-integration/governance-v2/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false diff --git a/energy-integration/governance-v2/src/lib.rs b/energy-integration/governance-v2/src/lib.rs index 0fcb53dca..2014b3a53 100644 --- a/energy-integration/governance-v2/src/lib.rs +++ b/energy-integration/governance-v2/src/lib.rs @@ -61,7 +61,7 @@ pub trait GovernanceV2: self.try_change_fee_token_id(fee_token); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} /// Propose a list of actions. diff --git a/energy-integration/governance-v2/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..822c38060 100644 --- a/energy-integration/governance-v2/wasm/Cargo.lock +++ b/energy-integration/governance-v2/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -200,9 +202,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -213,18 +215,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..ba31902a3 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.52.3" [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..74ee9fdca 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" [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.52.3" [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..c1419832e 100644 --- a/farm-staking/farm-staking-proxy/meta/Cargo.toml +++ b/farm-staking/farm-staking-proxy/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false 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..4944a7735 100644 --- a/farm-staking/farm-staking-proxy/wasm/Cargo.lock +++ b/farm-staking/farm-staking-proxy/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -411,9 +413,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -424,18 +426,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..e10369847 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.52.3" [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..15e0e15ac 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.52.3" diff --git a/farm-staking/farm-staking/meta/Cargo.toml b/farm-staking/farm-staking/meta/Cargo.toml index 20d07fb79..78643b777 100644 --- a/farm-staking/farm-staking/meta/Cargo.toml +++ b/farm-staking/farm-staking/meta/Cargo.toml @@ -9,5 +9,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false diff --git a/farm-staking/farm-staking/src/base_impl_wrapper.rs b/farm-staking/farm-staking/src/base_impl_wrapper.rs index 2b671677f..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..79d433dfe 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!(); @@ -31,18 +34,22 @@ 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" ); } + let mut storage_cache = StorageCache::new(self); + 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 +69,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 +80,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..f22555545 100644 --- a/farm-staking/farm-staking/tests/farm_staking_energy_test.rs +++ b/farm-staking/farm-staking/tests/farm_staking_energy_test.rs @@ -1,13 +1,19 @@ #![allow(deprecated)] pub mod farm_staking_setup; +use config::ConfigModule; use farm_staking::{ - claim_stake_farm_rewards::ClaimStakeFarmRewardsModule, stake_farm::StakeFarmModule, + claim_stake_farm_rewards::ClaimStakeFarmRewardsModule, + stake_farm::StakeFarmModule, + token_attributes::{StakingFarmTokenAttributes, UnbondSftAttributes}, unstake_farm::UnstakeFarmModule, + FarmStaking, }; use farm_staking_setup::*; use multiversx_sc::codec::multi_types::OptionalValue; -use multiversx_sc_scenario::{rust_biguint, DebugApi}; +use multiversx_sc_scenario::{ + managed_address, managed_biguint, rust_biguint, testing_framework::TxTokenTransfer, DebugApi, +}; #[test] fn farm_staking_with_energy_setup_test() { @@ -24,12 +30,21 @@ fn farm_staking_boosted_rewards_no_energy_test() { let mut fs_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = fs_setup.user_address.clone(); + fs_setup.set_boosted_yields_factors(); fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); let farm_in_amount = 100_000_000; let expected_farm_token_nonce = 1; - fs_setup.stake_farm(farm_in_amount, &[], expected_farm_token_nonce, 0, 0); + fs_setup.stake_farm( + &user_address, + farm_in_amount, + &[], + expected_farm_token_nonce, + 0, + 0, + ); fs_setup.check_farm_token_supply(farm_in_amount); fs_setup.set_block_epoch(5); @@ -43,6 +58,7 @@ fn farm_staking_boosted_rewards_no_energy_test() { rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out); let expected_reward_per_share = 300_000; // from 400_000 -> 300_000 fs_setup.claim_rewards( + &user_address, farm_in_amount, expected_farm_token_nonce, expected_reward_token_out, @@ -54,26 +70,77 @@ fn farm_staking_boosted_rewards_no_energy_test() { fs_setup.check_farm_token_supply(farm_in_amount); } +#[test] +fn farm_staking_other_user_enter_negative_test() { + DebugApi::dummy(); + let mut fs_setup = + FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + + let user_address = fs_setup.user_address.clone(); + let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); + + fs_setup.set_boosted_yields_factors(); + fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + + let farm_in_amount = 100_000_000; + fs_setup + .stake_farm_for_other_user(&rand_user, &user_address, farm_in_amount, &[]) + .assert_error(4, "Item not whitelisted"); + + let expected_farm_token_nonce = 1; + fs_setup.stake_farm( + &user_address, + farm_in_amount, + &[], + expected_farm_token_nonce, + 0, + 0, + ); + + fs_setup + .claim_farm_for_other_user( + &rand_user, + &user_address, + expected_farm_token_nonce, + farm_in_amount, + ) + .assert_error(4, "Item not whitelisted"); + + fs_setup + .unstake_farm_for_other_user( + &rand_user, + &user_address, + expected_farm_token_nonce, + farm_in_amount, + ) + .assert_error(4, "Item not whitelisted"); +} + #[test] fn farm_staking_boosted_rewards_with_energy_test() { DebugApi::dummy(); let mut fs_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = fs_setup.user_address.clone(); + let user_address2 = fs_setup.user_address2.clone(); + fs_setup.set_boosted_yields_factors(); fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); - fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 0, 10); + fs_setup.set_user_energy(&user_address, 9_800, 0, 100); + fs_setup.set_user_energy(&user_address2, 4_900, 0, 350); let farm_in_amount = 100_000_000; - fs_setup.stake_farm(farm_in_amount, &[], 1, 0, 0); - fs_setup.check_farm_token_supply(farm_in_amount); + fs_setup.stake_farm(&user_address, farm_in_amount, &[], 1, 0, 0); + fs_setup.stake_farm(&user_address2, farm_in_amount, &[], 2, 0, 0); + fs_setup.check_farm_token_supply(farm_in_amount * 2); // claim to get energy registered fs_setup .b_mock .execute_esdt_transfer( - &fs_setup.user_address, + &user_address, &fs_setup.farm_wrapper, FARM_TOKEN_ID, 1, @@ -84,10 +151,21 @@ fn farm_staking_boosted_rewards_with_energy_test() { ) .assert_ok(); - fs_setup.set_block_nonce(10); - - // random user tx to collect rewards + fs_setup + .b_mock + .execute_esdt_transfer( + &user_address2, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 2, + &rust_biguint!(farm_in_amount), + |sc| { + let _ = sc.claim_rewards(OptionalValue::None); + }, + ) + .assert_ok(); + // random user tx to collect rewards - week 1 let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); fs_setup.b_mock.set_esdt_balance( &rand_user, @@ -95,8 +173,9 @@ fn farm_staking_boosted_rewards_with_energy_test() { &rust_biguint!(USER_TOTAL_RIDE_TOKENS), ); - fs_setup.set_user_energy(&rand_user, 1, 5, 1); - fs_setup.set_block_epoch(5); + fs_setup.set_user_energy(&rand_user, 1, 6, 1); + fs_setup.set_block_epoch(6); + fs_setup.set_block_nonce(10); fs_setup .b_mock @@ -118,7 +197,7 @@ fn farm_staking_boosted_rewards_with_energy_test() { &rand_user, &fs_setup.farm_wrapper, FARM_TOKEN_ID, - 3, + 5, &rust_biguint!(10), |sc| { let _ = sc.unstake_farm(OptionalValue::None); @@ -126,51 +205,164 @@ fn farm_staking_boosted_rewards_with_energy_test() { ) .assert_ok(); - fs_setup.set_block_epoch(8); + // random user tx to collect rewards - week 2 + fs_setup.set_user_energy(&rand_user, 1, 13, 1); + fs_setup.set_block_epoch(13); + fs_setup.set_block_nonce(20); - fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 8, 10); + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); - // value taken from the "test_unstake_farm" test - // originally, it was 40, but since 25% of the rewards go to boosted yields - // rewards are now only 3/4 * 40 = 30 - // - // 10 reserved for boosted yields -> 30 + 10 - let expected_reward_token_out = 40; - let expected_farming_token_balance = - rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out); - let expected_reward_per_share = 300_000; // from 400_000 -> 300_000 + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 7, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + // random user tx to collect rewards - week 3 + fs_setup.set_user_energy(&rand_user, 1, 20, 1); + fs_setup.set_block_epoch(20); + fs_setup.set_block_nonce(30); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 9, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + // random user tx to collect rewards - week 4 + fs_setup.set_user_energy(&rand_user, 1, 27, 1); + fs_setup.set_block_epoch(27); + fs_setup.set_block_nonce(40); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 11, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(28); + fs_setup.update_energy_for_user(&user_address); + fs_setup.update_energy_for_user(&user_address2); + + let base_rewards = 136; + let boosted_rewards_user = 61; + let boosted_rewards_user2 = 15; // ~ 1/4 rewards than user1 (half the energy for only 2 weeks) + let expected_reward_token_out_user = base_rewards + boosted_rewards_user; + let expected_reward_token_out_user2 = base_rewards + boosted_rewards_user2; + let expected_farming_token_balance_user = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out_user); + let expected_farming_token_balance_user2 = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_reward_token_out_user2); + let expected_reward_per_share = 1_360_000; fs_setup.claim_rewards( + &user_address, farm_in_amount, - 2, - expected_reward_token_out, - &expected_farming_token_balance, - &expected_farming_token_balance, - 5, + 3, + expected_reward_token_out_user, + &expected_farming_token_balance_user, + &expected_farming_token_balance_user, + 13, expected_reward_per_share, ); - fs_setup.check_farm_token_supply(farm_in_amount); + fs_setup.claim_rewards( + &user_address2, + farm_in_amount, + 4, + expected_reward_token_out_user2, + &expected_farming_token_balance_user2, + &expected_farming_token_balance_user2, + 14, + expected_reward_per_share, + ); + fs_setup.check_farm_token_supply(farm_in_amount * 2); } #[test] -fn farm_staking_claim_boosted_rewards_for_user_test() { +fn farm_staking_partial_position_handling_test() { DebugApi::dummy(); let mut fs_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = fs_setup.user_address.clone(); + fs_setup.set_boosted_yields_factors(); fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); - fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 0, 10); + fs_setup.set_user_energy(&user_address, 10_000, 0, 10); let farm_in_amount = 100_000_000; - fs_setup.stake_farm(farm_in_amount, &[], 1, 0, 0); + fs_setup.stake_farm(&user_address, farm_in_amount, &[], 1, 0, 0); fs_setup.check_farm_token_supply(farm_in_amount); // claim to get energy registered fs_setup .b_mock .execute_esdt_transfer( - &fs_setup.user_address, + &user_address, &fs_setup.farm_wrapper, FARM_TOKEN_ID, 1, @@ -184,6 +376,7 @@ fn farm_staking_claim_boosted_rewards_for_user_test() { fs_setup.set_block_nonce(10); // random user tx to collect rewards + let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); fs_setup.b_mock.set_esdt_balance( &rand_user, @@ -224,43 +417,108 @@ fn farm_staking_claim_boosted_rewards_for_user_test() { fs_setup.set_block_epoch(8); - fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 8, 10); + fs_setup.set_user_energy(&user_address, 10_000, 8, 10); - // value taken from the "test_unstake_farm" test - // originally, it was 40, but since 25% of the rewards go to boosted yields - // rewards are now only 3/4 * 40 = 30 - // - // 10 reserved for boosted yields -> 30 + 10 - let expected_boosted_reward_token_out = 10; - let expected_farming_token_balance = - rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_boosted_reward_token_out); + let full_position_base_rewards = 30; + let boosted_rewards_user = 10; + let half_position_expected_rewards = full_position_base_rewards / 2 + boosted_rewards_user; + let expected_farming_token_balance_user = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + half_position_expected_rewards); - // Random_user claim boosted rewards for user - fs_setup.allow_external_claim_rewards(&fs_setup.user_address.clone()); - fs_setup.claim_boosted_rewards_for_user( - &fs_setup.user_address.clone(), + fs_setup.unstake_farm( + &user_address, + farm_in_amount / 2, + 2, + half_position_expected_rewards, + &expected_farming_token_balance_user, + &expected_farming_token_balance_user, + 5, + farm_in_amount / 2, + &UnbondSftAttributes { + unlock_epoch: 8 + MIN_UNBOND_EPOCHS, + }, + ); + + fs_setup.set_block_nonce(20); + + // random user tx to collect rewards + + let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); + fs_setup.b_mock.set_esdt_balance( &rand_user, - expected_boosted_reward_token_out, - &expected_farming_token_balance, + FARMING_TOKEN_ID, + &rust_biguint!(USER_TOTAL_RIDE_TOKENS), + ); + + fs_setup.set_user_energy(&rand_user, 1, 12, 1); + fs_setup.set_block_epoch(12); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 6, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(15); + + fs_setup.set_user_energy(&user_address, 10_000, 15, 10); + + let expected_rewards_amount = full_position_base_rewards / 2 * 2; // half remaining position * 2 times the 10 block period + let half_position_boosted_rewards = boosted_rewards_user / 2; + let remaining_expected_rewards = expected_rewards_amount + half_position_boosted_rewards; + let final_expected_farming_token_balance_user = + expected_farming_token_balance_user + rust_biguint!(remaining_expected_rewards); + let expected_reward_per_share = 600_000; + fs_setup.claim_rewards( + &user_address, + farm_in_amount / 2, + 2, + remaining_expected_rewards, + &final_expected_farming_token_balance_user, + &final_expected_farming_token_balance_user, + 8, + expected_reward_per_share, ); - fs_setup.check_farm_token_supply(farm_in_amount); } #[test] -fn farm_staking_full_position_boosted_rewards_test() { +fn farm_staking_claim_boosted_rewards_for_user_test() { DebugApi::dummy(); let mut fs_setup = FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + let user_address = fs_setup.user_address.clone(); + fs_setup.set_boosted_yields_factors(); fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 0, 10); - let farm_in_amount = 50_000_000; - fs_setup.stake_farm(farm_in_amount, &[], 1, 0, 0); - fs_setup.stake_farm(farm_in_amount, &[], 2, 0, 0); - fs_setup.check_farm_token_supply(farm_in_amount * 2); + let farm_in_amount = 100_000_000; + fs_setup.stake_farm(&user_address, farm_in_amount, &[], 1, 0, 0); + fs_setup.check_farm_token_supply(farm_in_amount); // claim to get energy registered fs_setup @@ -280,8 +538,8 @@ fn farm_staking_full_position_boosted_rewards_test() { fs_setup.set_block_nonce(10); // random user tx to collect rewards - let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); + let user_address = fs_setup.user_address.clone(); fs_setup.b_mock.set_esdt_balance( &rand_user, FARMING_TOKEN_ID, @@ -311,7 +569,7 @@ fn farm_staking_full_position_boosted_rewards_test() { &rand_user, &fs_setup.farm_wrapper, FARM_TOKEN_ID, - 4, + 3, &rust_biguint!(10), |sc| { let _ = sc.unstake_farm(OptionalValue::None); @@ -321,21 +579,137 @@ fn farm_staking_full_position_boosted_rewards_test() { fs_setup.set_block_epoch(8); - fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 8, 10); + fs_setup.set_user_energy(&user_address, 10_000, 8, 10); - let expected_base_rewards = 15; - let expected_boosted_rewards = 10; - let mut expected_farming_token_balance = rust_biguint!( - USER_TOTAL_RIDE_TOKENS - (farm_in_amount * 2) - + expected_base_rewards - + expected_boosted_rewards - ); - let expected_reward_per_share = 300_000; // from 400_000 -> 300_000 + // value taken from the "test_unstake_farm" test + // originally, it was 40, but since 25% of the rewards go to boosted yields + // rewards are now only 3/4 * 40 = 30 + // + // 10 reserved for boosted yields -> 30 + 10 + let expected_boosted_reward_token_out = 10; + let expected_farming_token_balance = + rust_biguint!(USER_TOTAL_RIDE_TOKENS - farm_in_amount + expected_boosted_reward_token_out); - // Should receive half base rewards and full boosted rewards - fs_setup.claim_rewards( - farm_in_amount, - 2, + // Random_user claim boosted rewards for user + let rand_user_reward_balance = 4_999_999_990u64; + fs_setup.b_mock.check_esdt_balance( + &rand_user, + REWARD_TOKEN_ID, + &rust_biguint!(rand_user_reward_balance), + ); + fs_setup.allow_external_claim_rewards(&user_address, true); + fs_setup.claim_boosted_rewards_for_user( + &user_address, + &rand_user, + expected_boosted_reward_token_out, + &expected_farming_token_balance, + ); + fs_setup.b_mock.check_esdt_balance( + &rand_user, + REWARD_TOKEN_ID, + &rust_biguint!(rand_user_reward_balance), + ); + + fs_setup.check_farm_token_supply(farm_in_amount); + + // User removes the allowance of claim boosted rewards + fs_setup.allow_external_claim_rewards(&user_address, false); + fs_setup.claim_boosted_rewards_for_user_expect_error(&user_address, &rand_user); +} + +#[test] +fn farm_staking_full_position_boosted_rewards_test() { + DebugApi::dummy(); + let mut fs_setup = + FarmStakingSetup::new(farm_staking::contract_obj, energy_factory::contract_obj); + + let user_address = fs_setup.user_address.clone(); + + fs_setup.set_boosted_yields_factors(); + fs_setup.set_boosted_yields_rewards_percentage(BOOSTED_YIELDS_PERCENTAGE); + + fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 0, 10); + + let farm_in_amount = 50_000_000; + fs_setup.stake_farm(&user_address, farm_in_amount, &[], 1, 0, 0); + fs_setup.stake_farm(&user_address, farm_in_amount, &[], 2, 0, 0); + fs_setup.check_farm_token_supply(farm_in_amount * 2); + + // claim to get energy registered + fs_setup + .b_mock + .execute_esdt_transfer( + &fs_setup.user_address, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 1, + &rust_biguint!(farm_in_amount), + |sc| { + let _ = sc.claim_rewards(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_nonce(10); + + // random user tx to collect rewards + + let rand_user = fs_setup.b_mock.create_user_account(&rust_biguint!(0)); + fs_setup.b_mock.set_esdt_balance( + &rand_user, + FARMING_TOKEN_ID, + &rust_biguint!(USER_TOTAL_RIDE_TOKENS), + ); + + fs_setup.set_user_energy(&rand_user, 1, 5, 1); + fs_setup.set_block_epoch(5); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARMING_TOKEN_ID, + 0, + &rust_biguint!(10), + |sc| { + let _ = sc.stake_farm_endpoint(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup + .b_mock + .execute_esdt_transfer( + &rand_user, + &fs_setup.farm_wrapper, + FARM_TOKEN_ID, + 4, + &rust_biguint!(10), + |sc| { + let _ = sc.unstake_farm(OptionalValue::None); + }, + ) + .assert_ok(); + + fs_setup.set_block_epoch(8); + + fs_setup.set_user_energy(&fs_setup.user_address.clone(), 10_000, 8, 10); + + let expected_base_rewards = 15; + let expected_boosted_rewards = 10; + let mut expected_farming_token_balance = rust_biguint!( + USER_TOTAL_RIDE_TOKENS - (farm_in_amount * 2) + + expected_base_rewards + + expected_boosted_rewards + ); + let expected_reward_per_share = 300_000; // from 400_000 -> 300_000 + + // Should receive half base rewards and full boosted rewards + fs_setup.claim_rewards( + &user_address, + farm_in_amount, + 2, expected_base_rewards + expected_boosted_rewards, &expected_farming_token_balance, &expected_farming_token_balance, @@ -346,6 +720,7 @@ fn farm_staking_full_position_boosted_rewards_test() { // Should receive half base rewards and no boosted rewards expected_farming_token_balance += expected_base_rewards; fs_setup.claim_rewards( + &user_address, farm_in_amount, 3, expected_base_rewards, @@ -356,3 +731,978 @@ 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.claim_boosted_rewards_for_user(&second_user, &second_user, 0, &rust_biguint!(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, 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 * 2, + &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), + ); +} 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..d4cfdd73e 100644 --- a/farm-staking/farm-staking/wasm/Cargo.lock +++ b/farm-staking/farm-staking/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -351,9 +353,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -364,18 +366,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..5b206bdfc 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.52.3" [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/Cargo.toml b/farm-staking/metabonding-staking/Cargo.toml index de3c1ff97..a9678d893 100644 --- a/farm-staking/metabonding-staking/Cargo.toml +++ b/farm-staking/metabonding-staking/Cargo.toml @@ -9,11 +9,11 @@ publish = false path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.52.3" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" [dependencies.factory] path = "../../locked-asset/factory" @@ -22,7 +22,7 @@ path = "../../locked-asset/factory" num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.52.3" [dev-dependencies.common_structs] path = "../../common/common_structs" diff --git a/farm-staking/metabonding-staking/meta/Cargo.toml b/farm-staking/metabonding-staking/meta/Cargo.toml index 71df2c0ba..32bf213be 100644 --- a/farm-staking/metabonding-staking/meta/Cargo.toml +++ b/farm-staking/metabonding-staking/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false diff --git a/farm-staking/metabonding-staking/src/lib.rs b/farm-staking/metabonding-staking/src/lib.rs index 94be22193..d15ce3c90 100644 --- a/farm-staking/metabonding-staking/src/lib.rs +++ b/farm-staking/metabonding-staking/src/lib.rs @@ -26,7 +26,7 @@ pub trait MetabondingStaking: .set_if_empty(&locked_asset_factory_address); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[payable("*")] diff --git a/farm-staking/metabonding-staking/wasm/Cargo.lock b/farm-staking/metabonding-staking/wasm/Cargo.lock index 739fec429..a8675928b 100644 --- a/farm-staking/metabonding-staking/wasm/Cargo.lock +++ b/farm-staking/metabonding-staking/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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" @@ -46,9 +46,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" @@ -127,9 +127,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.151" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "math" @@ -170,32 +170,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -205,9 +207,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -218,18 +220,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" dependencies = [ "multiversx-sc", ] @@ -245,27 +247,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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -299,15 +301,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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" dependencies = [ "proc-macro2", "quote", @@ -337,6 +339,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/metabonding-staking/wasm/Cargo.toml b/farm-staking/metabonding-staking/wasm/Cargo.toml index fe2a7c6c2..1853ff22d 100644 --- a/farm-staking/metabonding-staking/wasm/Cargo.toml +++ b/farm-staking/metabonding-staking/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.metabonding-staking] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.52.3" [workspace] members = ["."] diff --git a/farm-staking/metabonding-staking/wasm/src/lib.rs b/farm-staking/metabonding-staking/wasm/src/lib.rs index b8e948d22..22b6f6de2 100644 --- a/farm-staking/metabonding-staking/wasm/src/lib.rs +++ b/farm-staking/metabonding-staking/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/locked-asset/simple-lock-whitelist/.gitignore b/legacy-contracts/factory-legacy/.gitignore similarity index 100% rename from locked-asset/simple-lock-whitelist/.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..1f17baf8e --- /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.52.3" +features = ["esdt-token-payment-legacy-decode"] + +[dependencies.multiversx-sc-modules] +version = "=0.52.3" + +[dev-dependencies.multiversx-sc-scenario] +version = "=0.52.3" + +[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" \ No newline at end of file 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..99df379a1 --- /dev/null +++ b/legacy-contracts/factory-legacy/meta/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "factory-legacy-meta" + +version = "0.0.0" +authors = [ "you",] +edition = "2018" +publish = false + +[dependencies.factory-legacy] +path = ".." + +[dependencies.multiversx-sc-meta] +version = "0.52.3" +default-features = false \ No newline at end of file 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..64a2b3bb3 --- /dev/null +++ b/legacy-contracts/factory-legacy/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta::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/legacy-contracts/factory-legacy/src/attr_ex_helper.rs b/legacy-contracts/factory-legacy/src/attr_ex_helper.rs new file mode 100644 index 000000000..322bb0b73 --- /dev/null +++ b/legacy-contracts/factory-legacy/src/attr_ex_helper.rs @@ -0,0 +1,68 @@ +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +use common_structs::LockedAssetTokenAttributes; +use common_structs::LockedAssetTokenAttributesEx; +use common_structs::UnlockMilestoneEx; +use common_structs::UnlockScheduleEx; + +// 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 { + fn get_attributes_ex( + &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(), + token_id, + token_nonce, + ); + + if token_nonce < attr_ex_activation { + let attr = self + .serializer() + .top_decode_from_managed_buffer::>( + &token_info.attributes, + ); + self.convert_attr_to_attr_ex(&attr) + } else { + self.serializer() + .top_decode_from_managed_buffer::>( + &token_info.attributes, + ) + } + } + + fn convert_attr_to_attr_ex( + &self, + attr: &LockedAssetTokenAttributes, + ) -> LockedAssetTokenAttributesEx { + let mut new_milestones: ManagedVec = ManagedVec::new(); + + for milestones in attr.unlock_schedule.unlock_milestones.iter() { + new_milestones.push(UnlockMilestoneEx { + unlock_epoch: milestones.unlock_epoch, + unlock_percent: (milestones.unlock_percent as u64) * PRECISION_EX_INCREASE, + }); + } + + LockedAssetTokenAttributesEx { + unlock_schedule: UnlockScheduleEx { + unlock_milestones: new_milestones, + }, + is_merged: attr.is_merged, + } + } + + #[view(getExtendedAttributesActivationNonce)] + #[storage_mapper("extended_attributes_activation_nonce")] + fn extended_attributes_activation_nonce(&self) -> SingleValueMapper; +} diff --git a/legacy-contracts/factory-legacy/src/cache.rs b/legacy-contracts/factory-legacy/src/cache.rs new file mode 100644 index 000000000..24d1a031d --- /dev/null +++ b/legacy-contracts/factory-legacy/src/cache.rs @@ -0,0 +1,49 @@ +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +use common_structs::{Nonce, UnlockScheduleEx}; + +use crate::attr_ex_helper; + +use super::locked_asset; + +#[multiversx_sc::module] +pub trait CacheModule: locked_asset::LockedAssetModule + attr_ex_helper::AttrExHelper { + #[inline(always)] + fn get_sft_nonce_for_unlock_schedule( + &self, + unlock_schedule: &UnlockScheduleEx, + ) -> Option { + self.nonce_cache_ex().get(unlock_schedule) + } + + #[view(getUnlockScheduleForSFTNonce)] + fn get_unlock_schedule_for_sft_nonce( + &self, + nonce: Nonce, + ) -> Option> { + self.unlock_schedule_cache_ex().get(&nonce) + } + + #[inline(always)] + fn cache_unlock_schedule_and_nonce( + &self, + unlock_schedule: &UnlockScheduleEx, + nonce: Nonce, + ) { + self.nonce_cache_ex().insert(unlock_schedule.clone(), nonce); + self.unlock_schedule_cache_ex() + .insert(nonce, unlock_schedule.clone()); + } + + #[view(getCacheSize)] + fn get_cache_size(&self) -> usize { + self.nonce_cache_ex().len() + } + + #[storage_mapper("nonce_cache_ex")] + fn nonce_cache_ex(&self) -> MapMapper, Nonce>; + + #[storage_mapper("unlock_schedule_cache_ex")] + fn unlock_schedule_cache_ex(&self) -> MapMapper>; +} diff --git a/legacy-contracts/factory-legacy/src/events.rs b/legacy-contracts/factory-legacy/src/events.rs new file mode 100644 index 000000000..149c7af5c --- /dev/null +++ b/legacy-contracts/factory-legacy/src/events.rs @@ -0,0 +1,123 @@ +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +use common_structs::LockedAssetTokenAttributesEx; + +#[derive(TypeAbi, TopEncode)] +pub struct CreateAndForwardEvent { + caller: ManagedAddress, + destination: ManagedAddress, + locked_asset_token_id: TokenIdentifier, + locked_asset_token_nonce: u64, + locked_asset_token_amount: BigUint, + locked_assets_attributes: LockedAssetTokenAttributesEx, + start_epoch: u64, + block: u64, + epoch: u64, + timestamp: u64, +} + +#[derive(TypeAbi, TopEncode)] +pub struct UnlockAssetsEvent { + caller: ManagedAddress, + input_locked_assets_token_id: TokenIdentifier, + input_locked_assets_token_nonce: u64, + 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, + block: u64, + epoch: u64, + timestamp: u64, +} + +#[multiversx_sc::module] +pub trait EventsModule { + fn emit_create_and_forward_event( + self, + caller: &ManagedAddress, + destination: &ManagedAddress, + locked_asset_token_id: &TokenIdentifier, + locked_asset_token_nonce: u64, + locked_asset_token_amount: &BigUint, + locked_assets_attributes: &LockedAssetTokenAttributesEx, + start_epoch: u64, + ) { + let epoch = self.blockchain().get_block_epoch(); + self.create_and_forward_event( + caller, + destination, + epoch, + &CreateAndForwardEvent { + caller: caller.clone(), + destination: destination.clone(), + locked_asset_token_id: locked_asset_token_id.clone(), + locked_asset_token_nonce, + 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, + timestamp: self.blockchain().get_block_timestamp(), + }, + ) + } + + fn emit_unlock_assets_event( + self, + caller: &ManagedAddress, + input_locked_assets_token_id: &TokenIdentifier, + input_locked_assets_token_nonce: u64, + 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, + ) { + let epoch = self.blockchain().get_block_epoch(); + self.unlock_assets_event( + caller, + epoch, + &UnlockAssetsEvent { + caller: caller.clone(), + input_locked_assets_token_id: input_locked_assets_token_id.clone(), + input_locked_assets_token_nonce, + 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: 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(), + }, + ) + } + + #[event("create_and_forward")] + fn create_and_forward_event( + self, + #[indexed] caller: &ManagedAddress, + #[indexed] destination: &ManagedAddress, + #[indexed] epoch: u64, + swap_event: &CreateAndForwardEvent, + ); + + #[event("unlock_assets")] + fn unlock_assets_event( + self, + #[indexed] caller: &ManagedAddress, + #[indexed] epoch: u64, + swap_event: &UnlockAssetsEvent, + ); +} diff --git a/legacy-contracts/factory-legacy/src/lib.rs b/legacy-contracts/factory-legacy/src/lib.rs new file mode 100644 index 000000000..1a5f01ad3 --- /dev/null +++ b/legacy-contracts/factory-legacy/src/lib.rs @@ -0,0 +1,366 @@ +#![no_std] + +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; + +const ADDITIONAL_AMOUNT_TO_CREATE: u64 = 1; +const EPOCHS_IN_MONTH: u64 = 30; + +#[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_merge_helper::TokenMergeHelperModule + + locked_asset_token_merge::LockedAssetTokenMergeModule + + events::EventsModule + + attr_ex_helper::AttrExHelper + + migration::LockedTokenMigrationModule + + multiversx_sc_modules::pause::PauseModule +{ + #[init] + fn init(&self) { + self.set_paused(true); + } + + #[upgrade] + fn upgrade(&self) {} + + #[only_owner] + #[endpoint] + fn whitelist(&self, address: ManagedAddress) { + 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 is_removed = self.whitelisted_contracts().remove(&address); + require!(is_removed, "ManagedAddresss not whitelisted"); + } + + #[endpoint(createAndForwardCustomPeriod)] + fn create_and_forward_custom_period( + &self, + amount: BigUint, + address: ManagedAddress, + start_epoch: Epoch, + unlock_period: UnlockPeriod, + ) -> OldEsdtTokenPayment { + self.require_not_paused(); + + let caller = self.blockchain().get_caller(); + require!( + self.whitelisted_contracts().contains(&caller), + "Permission denied" + ); + require!(!unlock_period.unlock_milestones.is_empty(), "Empty arg"); + + 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)] + fn create_and_forward( + &self, + amount: BigUint, + address: ManagedAddress, + start_epoch: Epoch, + ) -> OldEsdtTokenPayment { + self.require_not_paused(); + + let caller = self.blockchain().get_caller(); + require!( + self.whitelisted_contracts().contains(&caller), + "Permission denied" + ); + require!( + !self.locked_asset_token_id().is_empty(), + "Locked Asset Token not registered" + ); + require!(amount > 0, "Zero input amount"); + + 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, + ); + + OldEsdtTokenPayment::new(new_token) + } + + #[payable("*")] + #[endpoint(unlockAssets)] + fn unlock_assets(&self) { + 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_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 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(); + self.mint_and_send_assets(&caller, &unlock_amount); + + let mut output_locked_assets_token_amount = + EsdtTokenPayment::new(token_id.clone(), 0, BigUint::zero()); + let mut output_locked_asset_attributes = LockedAssetTokenAttributesEx { + unlock_schedule: UnlockScheduleEx { + unlock_milestones: ManagedVec::new(), + }, + is_merged: false, + }; + + let locked_remaining = &amount - &unlock_amount; + if locked_remaining > 0u64 { + 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, + &caller, + ); + } + + self.send() + .esdt_local_burn(&locked_token_id, token_nonce, &amount); + + let initial_amounts_per_epoch = attributes.get_unlock_amounts_per_epoch(&amount); + let final_amounts_per_epoch = + output_locked_asset_attributes.get_unlock_amounts_per_epoch(&locked_remaining); + self.update_energy_after_unlock( + caller.clone(), + initial_amounts_per_epoch, + final_amounts_per_epoch, + ); + + self.emit_unlock_assets_event( + &caller, + &token_id, + token_nonce, + &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, + ); + } + + fn get_month_start_epoch(&self, epoch: Epoch) -> Epoch { + epoch - (epoch - self.init_epoch().get()) % EPOCHS_IN_MONTH + } + + fn produce_tokens_and_send( + &self, + amount: &BigUint, + attributes: &LockedAssetTokenAttributesEx, + address: &ManagedAddress, + ) -> EsdtTokenPayment { + let result = self.get_sft_nonce_for_unlock_schedule(&attributes.unlock_schedule); + let sent_nonce = match result { + Option::Some(cached_nonce) => { + self.add_quantity_and_send_locked_assets(amount, cached_nonce, address); + cached_nonce + } + Option::None => { + let do_cache_result = !attributes.is_merged; + + let additional_amount_to_create = if do_cache_result { + BigUint::from(ADDITIONAL_AMOUNT_TO_CREATE) + } else { + BigUint::zero() + }; + + let new_nonce = self.create_and_send_locked_assets( + amount, + &additional_amount_to_create, + address, + attributes, + ); + + if do_cache_result { + self.cache_unlock_schedule_and_nonce(&attributes.unlock_schedule, new_nonce); + } + new_nonce + } + }; + + let token_id = self.locked_asset_token_id().get(); + EsdtTokenPayment::new(token_id, sent_nonce, amount.clone()) + } + + #[only_owner] + #[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( + &self, + start_epoch: Epoch, + unlock_period: UnlockPeriod, + ) -> UnlockScheduleEx { + let mut result = ManagedVec::new(); + for milestone in unlock_period.unlock_milestones.iter() { + result.push(UnlockMilestoneEx { + unlock_epoch: milestone.unlock_epoch + start_epoch, + unlock_percent: milestone.unlock_percent as u64 * PRECISION_EX_INCREASE, + }); + } + UnlockScheduleEx { + unlock_milestones: result, + } + } + + #[view(getLastErrorMessage)] + #[storage_mapper("last_error_message")] + fn last_error_message(&self) -> SingleValueMapper; + + #[view(getInitEpoch)] + #[storage_mapper("init_epoch")] + fn init_epoch(&self) -> SingleValueMapper; + + #[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/legacy-contracts/factory-legacy/src/locked_asset.rs b/legacy-contracts/factory-legacy/src/locked_asset.rs new file mode 100644 index 000000000..a1e02cc8d --- /dev/null +++ b/legacy-contracts/factory-legacy/src/locked_asset.rs @@ -0,0 +1,209 @@ +multiversx_sc::imports!(); +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: attr_ex_helper::AttrExHelper { + fn create_and_send_locked_assets( + &self, + amount: &BigUint, + additional_amount_to_create: &BigUint, + address: &ManagedAddress, + attributes: &LockedAssetTokenAttributesEx, + ) -> 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); + + last_created_nonce + } + + fn add_quantity_and_send_locked_assets( + &self, + amount: &BigUint, + sft_nonce: Nonce, + address: &ManagedAddress, + ) { + 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( + &self, + current_epoch: Epoch, + unlock_milestones: &ManagedVec, + ) -> u64 { + let mut unlock_percent = 0u64; + + for milestone in unlock_milestones.into_iter() { + if milestone.unlock_epoch <= current_epoch { + unlock_percent += milestone.unlock_percent; + } + } + + require!( + unlock_percent <= PERCENTAGE_TOTAL_EX, + "unlock percent greater than max" + ); + + unlock_percent + } + + fn create_new_unlock_milestones( + &self, + current_epoch: Epoch, + old_unlock_milestones: &ManagedVec, + ) -> ManagedVec { + let unlock_percent = self.get_unlock_percent(current_epoch, old_unlock_milestones); + let unlock_percent_remaining = PERCENTAGE_TOTAL_EX - unlock_percent; + + if unlock_percent_remaining == 0 { + return ManagedVec::new(); + } + + let mut unlock_milestones_merged = + ArrayVec::::new(); + for old_milestone in old_unlock_milestones.iter() { + if old_milestone.unlock_epoch > current_epoch { + let new_unlock_percent = + old_milestone.unlock_percent * PRECISION_EX_INCREASE * ONE_MILLION + / unlock_percent_remaining; + unlock_milestones_merged.push(UnlockMilestoneEx { + unlock_epoch: old_milestone.unlock_epoch, + unlock_percent: new_unlock_percent, + }); + } + } + + self.distribute_leftover(&mut unlock_milestones_merged); + self.get_non_zero_percent_milestones_as_vec(&unlock_milestones_merged) + } + + fn distribute_leftover( + &self, + unlock_milestones_merged: &mut ArrayVec, + ) { + let mut sum_of_new_percents = 0u64; + for milestone in unlock_milestones_merged.iter() { + sum_of_new_percents += milestone.unlock_percent / TEN_THOUSAND; + } + let mut leftover = PERCENTAGE_TOTAL_EX - sum_of_new_percents; + + while leftover != 0 { + let mut max_rounding_error = 0; + let mut max_rounding_error_index = 0; + for index in 0..unlock_milestones_merged.len() { + let rounding_error = unlock_milestones_merged[index].unlock_percent % TEN_THOUSAND; + if rounding_error >= max_rounding_error { + max_rounding_error = rounding_error; + max_rounding_error_index = index; + } + } + + leftover -= 1; + unlock_milestones_merged[max_rounding_error_index].unlock_percent = + ((unlock_milestones_merged[max_rounding_error_index].unlock_percent + / TEN_THOUSAND) + + 1) + * TEN_THOUSAND; + } + } + + fn get_non_zero_percent_milestones_as_vec( + &self, + unlock_milestones_merged: &ArrayVec, + ) -> ManagedVec { + let mut new_unlock_milestones = ManagedVec::new(); + + for el in unlock_milestones_merged.iter() { + let percent_rounded = el.unlock_percent / TEN_THOUSAND; + if percent_rounded != 0 { + new_unlock_milestones.push(UnlockMilestoneEx { + unlock_epoch: el.unlock_epoch, + unlock_percent: percent_rounded, + }); + } + } + + new_unlock_milestones + } + + 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 mint_and_send_assets(&self, dest: &ManagedAddress, amount: &BigUint) { + if amount > &0 { + let asset_token_id = self.asset_token_id().get(); + self.send().esdt_local_mint(&asset_token_id, 0, amount); + self.send().direct_esdt(dest, &asset_token_id, 0, amount); + } + } + + #[view(getLockedAssetTokenId)] + #[storage_mapper("locked_asset_token_id")] + fn locked_asset_token_id(&self) -> SingleValueMapper; + + #[view(getAssetTokenId)] + #[storage_mapper("asset_token_id")] + fn asset_token_id(&self) -> SingleValueMapper; +} diff --git a/legacy-contracts/factory-legacy/src/locked_asset_token_merge.rs b/legacy-contracts/factory-legacy/src/locked_asset_token_merge.rs new file mode 100644 index 000000000..8cb637658 --- /dev/null +++ b/legacy-contracts/factory-legacy/src/locked_asset_token_merge.rs @@ -0,0 +1,162 @@ +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +use common_structs::*; + +use crate::attr_ex_helper::{self, PRECISION_EX_INCREASE}; + +use super::locked_asset; +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_merge_helper::TokenMergeHelperModule + + attr_ex_helper::AttrExHelper +{ + 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); + } + } + + fn get_merged_locked_asset_token_amount_and_attributes( + &self, + 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_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" + ); + + tokens.push(LockedTokenEx { + 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.clone(), token_0.attributes); + } + + let attrs = LockedAssetTokenAttributesEx { + unlock_schedule: self.aggregated_unlock_schedule(&tokens), + is_merged: true, + }; + + (sum_amount, attrs) + } + + fn calculate_new_unlock_milestones( + &self, + unlock_epoch_amount_merged: &ArrayVec< + EpochAmountPair, + DOUBLE_MAX_MILESTONES_IN_SCHEDULE, + >, + amount_total: &BigUint, + ) -> ManagedVec { + let mut unlock_milestones_merged = + ArrayVec::::new(); + + for el in unlock_epoch_amount_merged.iter() { + let unlock_percent = &(&el.amount * PRECISION_EX_INCREASE * ONE_MILLION) / amount_total; + + // Accumulate even the percents of 0 + unlock_milestones_merged.push(UnlockMilestoneEx { + unlock_epoch: el.epoch, + unlock_percent: unlock_percent.to_u64().unwrap(), + }) + } + + self.distribute_leftover(&mut unlock_milestones_merged); + self.get_non_zero_percent_milestones_as_vec(&unlock_milestones_merged) + } + + fn aggregated_unlock_schedule( + &self, + tokens: &ManagedVec>, + ) -> UnlockScheduleEx { + let mut array = + ArrayVec::, DOUBLE_MAX_MILESTONES_IN_SCHEDULE>::new(); + + let mut sum = BigUint::zero(); + for locked_token in tokens.iter() { + for milestone in locked_token + .attributes + .unlock_schedule + .unlock_milestones + .iter() + { + require!( + array.len() < DOUBLE_MAX_MILESTONES_IN_SCHEDULE, + "too many unlock milestones" + ); + 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; + } + array.sort_unstable_by(|a, b| a.epoch.cmp(&b.epoch)); + + let default = EpochAmountPair { + epoch: 0u64, + amount: BigUint::zero(), + }; + let mut unlock_epoch_amount_merged = + ArrayVec::, DOUBLE_MAX_MILESTONES_IN_SCHEDULE>::new(); + for elem in array.iter() { + let last = unlock_epoch_amount_merged.last().unwrap_or(&default); + + if elem.epoch == last.epoch || elem.epoch == last.epoch + 1 { + let new_elem = EpochAmountPair { + epoch: elem.epoch, + amount: &last.amount + &elem.amount, + }; + unlock_epoch_amount_merged.pop(); + unlock_epoch_amount_merged.push(new_elem); + } else { + unlock_epoch_amount_merged.push(elem.clone()); + } + } + require!(sum != 0u64, "Sum cannot be zero"); + require!( + unlock_epoch_amount_merged.len() < MAX_MILESTONES_IN_SCHEDULE, + "Too many milestones" + ); + require!(!unlock_epoch_amount_merged.is_empty(), "Empty milestones"); + + let new_unlock_milestones = + self.calculate_new_unlock_milestones(&unlock_epoch_amount_merged, &sum); + + UnlockScheduleEx { + unlock_milestones: new_unlock_milestones, + } + } +} diff --git a/legacy-contracts/factory-legacy/src/migration.rs b/legacy-contracts/factory-legacy/src/migration.rs new file mode 100644 index 000000000..653b93aa0 --- /dev/null +++ b/legacy-contracts/factory-legacy/src/migration.rs @@ -0,0 +1,45 @@ +multiversx_sc::imports!(); + +use common_structs::UnlockEpochAmountPairs; +use energy_factory::migration::ProxyTrait as _; + +#[multiversx_sc::module] +pub trait LockedTokenMigrationModule: + crate::locked_asset::LockedAssetModule + crate::attr_ex_helper::AttrExHelper +{ + #[only_owner] + #[endpoint(setNewFactoryAddress)] + fn set_new_factory_address(&self, sc_address: ManagedAddress) { + require!( + !sc_address.is_zero() && self.blockchain().is_smart_contract(&sc_address), + "Invalid SC address" + ); + self.new_factory_address().set(&sc_address); + } + + fn update_energy_after_unlock( + &self, + caller: ManagedAddress, + initial_epoch_amount_pairs: UnlockEpochAmountPairs, + final_epoch_amount_pairs: UnlockEpochAmountPairs, + ) { + let new_factory_address = self.new_factory_address().get(); + let _: IgnoreValue = self + .new_factory_proxy_builder(new_factory_address) + .update_energy_after_old_token_unlock( + caller, + initial_epoch_amount_pairs, + final_epoch_amount_pairs, + ) + .execute_on_dest_context(); + } + + #[proxy] + fn new_factory_proxy_builder( + &self, + sc_address: ManagedAddress, + ) -> energy_factory::Proxy; + + #[storage_mapper("newFactoryAddress")] + fn new_factory_address(&self) -> SingleValueMapper; +} diff --git a/locked-asset/simple-lock-whitelist/testnet.toml b/legacy-contracts/factory-legacy/testnet.toml similarity index 100% rename from locked-asset/simple-lock-whitelist/testnet.toml rename to legacy-contracts/factory-legacy/testnet.toml diff --git a/legacy-contracts/factory-legacy/wasm/Cargo.lock b/legacy-contracts/factory-legacy/wasm/Cargo.lock new file mode 100644 index 000000000..4437e0091 --- /dev/null +++ b/legacy-contracts/factory-legacy/wasm/Cargo.lock @@ -0,0 +1,308 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[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_errors" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "common_structs" +version = "0.0.0" +dependencies = [ + "fixed-supply-token", + "math", + "mergeable", + "multiversx-sc", + "unwrappable", +] + +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + +[[package]] +name = "energy-factory" +version = "0.0.0" +dependencies = [ + "common_structs", + "legacy_token_decode_module", + "math", + "mergeable", + "multiversx-sc", + "multiversx-sc-modules", + "sc_whitelist_module", + "simple-lock", + "unwrappable", + "utils", +] + +[[package]] +name = "factory-legacy" +version = "0.0.0" +dependencies = [ + "common_errors", + "common_structs", + "energy-factory", + "multiversx-sc", + "multiversx-sc-modules", + "token_merge_helper", +] + +[[package]] +name = "factory-legacy-wasm" +version = "0.0.0" +dependencies = [ + "factory-legacy", + "multiversx-sc-wasm-adapter", +] + +[[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 = "legacy_token_decode_module" +version = "0.0.0" +dependencies = [ + "common_structs", + "multiversx-sc", + "utils", +] + +[[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.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-modules" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" +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.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +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 = "sc_whitelist_module" +version = "0.0.0" +dependencies = [ + "common_errors", + "multiversx-sc", +] + +[[package]] +name = "simple-lock" +version = "0.0.0" +dependencies = [ + "common_structs", + "multiversx-sc", + "multiversx-sc-modules", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "syn" +version = "2.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "token_merge_helper" +version = "0.0.0" +dependencies = [ + "common_errors", + "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" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "utils" +version = "0.0.0" +dependencies = [ + "common_structs", + "fixed-supply-token", + "mergeable", + "multiversx-sc", +] diff --git a/legacy-contracts/factory-legacy/wasm/Cargo.toml b/legacy-contracts/factory-legacy/wasm/Cargo.toml new file mode 100644 index 000000000..e147feb21 --- /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.52.3" + +[workspace] +members = ["."] diff --git a/legacy-contracts/factory-legacy/wasm/src/lib.rs b/legacy-contracts/factory-legacy/wasm/src/lib.rs new file mode 100644 index 000000000..80a5bf559 --- /dev/null +++ b/legacy-contracts/factory-legacy/wasm/src/lib.rs @@ -0,0 +1,47 @@ +// Code generated by the multiversx-sc build system. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +// Init: 1 +// Upgrade: 1 +// Endpoints: 21 +// Async Callback (empty): 1 +// Total number of exported functions: 24 + +#![no_std] + +multiversx_sc_wasm_adapter::allocator!(); +multiversx_sc_wasm_adapter::panic_handler!(); + +multiversx_sc_wasm_adapter::endpoints! { + factory_legacy + ( + init => init + upgrade => upgrade + whitelist => whitelist + removeWhitelist => remove_whitelist + createAndForwardCustomPeriod => create_and_forward_custom_period + createAndForward => create_and_forward + unlockAssets => unlock_assets + 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 => get_whitelisted_contracts + getDefaultUnlockPeriod => default_unlock_period + getLockedAssetTokenId => locked_asset_token_id + getAssetTokenId => asset_token_id + getUnlockScheduleForSFTNonce => get_unlock_schedule_for_sft_nonce + getCacheSize => get_cache_size + getExtendedAttributesActivationNonce => extended_attributes_activation_nonce + setNewFactoryAddress => set_new_factory_address + pause => pause_endpoint + unpause => unpause_endpoint + isPaused => paused_status + ) +} + +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/legacy-contracts/farm-staking-proxy-v13/.gitignore b/legacy-contracts/farm-staking-proxy-v13/.gitignore new file mode 100644 index 000000000..eaf5915bd --- /dev/null +++ b/legacy-contracts/farm-staking-proxy-v13/.gitignore @@ -0,0 +1,7 @@ +# Generated by Cargo +# will have compiled files and executables +/target/ +*/target/ + +# The erdpy output +output 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..4284d329e --- /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.52.3" +features = ["esdt-token-payment-legacy-decode"] + +[dependencies.multiversx-sc-modules] +version = "=0.52.3" + +[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.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] +num-bigint = "0.4.2" +num-traits = "0.2" +hex = "0.4" + +[dev-dependencies.multiversx-sc-scenario] +version = "=0.52.3" diff --git a/legacy-contracts/farm-staking-proxy-v13/meta/Cargo.toml b/legacy-contracts/farm-staking-proxy-v13/meta/Cargo.toml new file mode 100644 index 000000000..e23e8edf5 --- /dev/null +++ b/legacy-contracts/farm-staking-proxy-v13/meta/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "farm-staking-proxy-v13-meta" +version = "0.0.0" +edition = "2021" +publish = false +authors = ["MultiversX "] + +[dependencies.farm-staking-proxy-v13] +path = ".." + +[dependencies.multiversx-sc-meta] +version = "0.52.3" +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..d25b3a0c4 --- /dev/null +++ b/legacy-contracts/farm-staking-proxy-v13/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta::cli_main::(); +} diff --git a/locked-asset/simple-lock-whitelist/multiversx.json b/legacy-contracts/farm-staking-proxy-v13/multiversx.json similarity index 100% rename from locked-asset/simple-lock-whitelist/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/legacy-contracts/farm-staking-proxy-v13/wasm/Cargo.lock b/legacy-contracts/farm-staking-proxy-v13/wasm/Cargo.lock new file mode 100644 index 000000000..edad582f7 --- /dev/null +++ b/legacy-contracts/farm-staking-proxy-v13/wasm/Cargo.lock @@ -0,0 +1,597 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[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-types" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "common_errors" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "common_structs" +version = "0.0.0" +dependencies = [ + "fixed-supply-token", + "math", + "mergeable", + "multiversx-sc", + "unwrappable", +] + +[[package]] +name = "config" +version = "0.0.0" +dependencies = [ + "common_errors", + "common_structs", + "multiversx-sc", + "pausable", + "permissions_module", + "token_send", +] + +[[package]] +name = "contexts" +version = "0.0.0" +dependencies = [ + "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.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + +[[package]] +name = "energy-factory" +version = "0.0.0" +dependencies = [ + "common_structs", + "legacy_token_decode_module", + "math", + "mergeable", + "multiversx-sc", + "multiversx-sc-modules", + "sc_whitelist_module", + "simple-lock", + "unwrappable", + "utils", +] + +[[package]] +name = "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 = [ + "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", + "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", + "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]] +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 = "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" +dependencies = [ + "common_structs", + "multiversx-sc", + "utils", +] + +[[package]] +name = "locking_module" +version = "0.0.0" +dependencies = [ + "energy-factory", + "multiversx-sc", + "simple-lock", +] + +[[package]] +name = "math" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "mergeable" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "multiversx-sc" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-modules" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" +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 = "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.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +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 = "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" +dependencies = [ + "common_errors", + "multiversx-sc", +] + +[[package]] +name = "simple-lock" +version = "0.0.0" +dependencies = [ + "common_structs", + "multiversx-sc", + "multiversx-sc-modules", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "syn" +version = "2.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "token_merge_helper" +version = "0.0.0" +dependencies = [ + "common_errors", + "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" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "utils" +version = "0.0.0" +dependencies = [ + "common_structs", + "fixed-supply-token", + "mergeable", + "multiversx-sc", +] + +[[package]] +name = "week-timekeeping" +version = "0.0.0" +dependencies = [ + "common-types", + "multiversx-sc", +] + +[[package]] +name = "weekly-rewards-splitting" +version = "0.0.0" +dependencies = [ + "common-types", + "energy-query", + "math", + "multiversx-sc", + "unwrappable", + "week-timekeeping", +] 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..71837f035 --- /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.52.3" + +[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..1c5b00b29 --- /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.52.3" + +[dev-dependencies] +num-bigint = "0.4" + +[dev-dependencies.multiversx-sc-scenario] +version = "0.52.3" diff --git a/legacy-contracts/farm-v12/meta/Cargo.toml b/legacy-contracts/farm-v12/meta/Cargo.toml new file mode 100644 index 000000000..a2f55541d --- /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] +version = "0.52.3" +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..bfef42f9b --- /dev/null +++ b/legacy-contracts/farm-v12/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta::cli_main::(); +} diff --git a/dex/pair-mock/elrond.json b/legacy-contracts/farm-v12/multiversx.json similarity index 100% rename from dex/pair-mock/elrond.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..8c0d9a9d1 --- /dev/null +++ b/legacy-contracts/farm-v12/src/lib.rs @@ -0,0 +1,216 @@ +#![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, +} + +#[multiversx_sc::contract] +pub trait FarmV12 { + #[init] + fn init(&self) {} + + #[payable("*")] + #[endpoint(acceptFee)] + fn accept_fee(&self) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(calculateRewardsForGivenPosition)] + fn calculate_rewards_for_given_position( + &self, + _amount: BigUint, + _attributes_raw: ManagedBuffer, + ) -> SCResult { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(end_produce_rewards_as_owner)] + fn end_produce_rewards_as_owner(&self) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[payable("*")] + #[endpoint(exitFarm)] + fn exit_farm( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> SCResult> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getBurnedTokenAmount)] + fn burned_tokens(&self) -> BigUint { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getCurrentBlockFee)] + fn current_block_fee_storage(&self) -> Option<(Nonce, BigUint)> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getDivisionSafetyConstant)] + fn division_safety_constant(&self) -> BigUint { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getFarmTokenId)] + fn farm_token_id(&self) -> TokenIdentifier { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getFarmTokenSupply)] + fn get_farm_token_supply(&self) -> BigUint { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getFarmingTokenId)] + fn farming_token_id(&self) -> TokenIdentifier { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getFarmingTokenReserve)] + fn farming_token_reserve(&self) -> BigUint { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getLastErrorMessage)] + fn last_error_message(&self) -> ManagedBuffer { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getLastRewardBlockNonce)] + fn last_reward_block_nonce(&self) -> Nonce { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getLockedAssetFactoryManagedAddress)] + fn locked_asset_factory_address(&self) -> ManagedAddress { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getLockedRewardAprMuliplier)] + fn locked_rewards_apr_multiplier(&self) -> u8 { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getMinimumFarmingEpoch)] + fn minimum_farming_epoch(&self) -> u8 { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getOwner)] + fn owner(&self) -> ManagedAddress { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getPairContractManagedAddress)] + fn pair_contract_address(&self) -> ManagedAddress { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getPenaltyPercent)] + fn penalty_percent(&self) -> u64 { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getPerBlockRewardAmount)] + fn per_block_reward_amount(&self) -> BigUint { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getRewardPerShare)] + fn reward_per_share(&self) -> BigUint { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getRewardReserve)] + fn reward_reserve(&self) -> BigUint { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getRewardTokenId)] + fn reward_token_id(&self) -> TokenIdentifier { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getRouterManagedAddress)] + fn router_address(&self) -> ManagedAddress { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getState)] + fn state(&self) -> State { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getTransferExecGasLimit)] + fn transfer_exec_gas_limit(&self) -> u64 { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getUndistributedFees)] + fn undistributed_fee_storage(&self) -> BigUint { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(pause)] + fn pause(&self) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(resume)] + fn resume(&self) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(setPerBlockRewardAmount)] + fn set_per_block_reward_amount(&self, _per_block_amount: BigUint) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint(setTransferRoleFarmToken)] + fn set_transfer_role_farm_token( + &self, + _opt_address: OptionalValue, + ) -> INCORRECTReturnType { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(set_locked_rewards_apr_multiplier)] + fn set_locked_rewards_apr_multiplier(&self, _muliplier: u8) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(set_minimum_farming_epochs)] + fn set_minimum_farming_epochs(&self, _epochs: u8) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(set_penalty_percent)] + fn set_penalty_percent(&self, _percent: u64) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(set_transfer_exec_gas_limit)] + fn set_transfer_exec_gas_limit(&self, _gas_limit: u64) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(start_produce_rewards)] + fn start_produce_rewards(&self) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } +} diff --git a/legacy-contracts/farm-v12/wasm/Cargo.lock b/legacy-contracts/farm-v12/wasm/Cargo.lock new file mode 100644 index 000000000..3223f31f4 --- /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.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[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.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" +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.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +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.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +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/farm-v12/wasm/Cargo.toml similarity index 83% rename from locked-asset/simple-lock-whitelist/wasm/Cargo.toml rename to legacy-contracts/farm-v12/wasm/Cargo.toml index 068857df3..a2e35227c 100644 --- a/locked-asset/simple-lock-whitelist/wasm/Cargo.toml +++ b/legacy-contracts/farm-v12/wasm/Cargo.toml @@ -5,7 +5,7 @@ # ########################################## [package] -name = "simple-lock-whitelist-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.simple-lock-whitelist] +[profile.dev] +panic = "abort" + +[dependencies.farm-v12] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "0.52.3" [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..11ee0c4a1 --- /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.52.3" + +[dev-dependencies] +num-bigint = "0.4" + +[dev-dependencies.multiversx-sc-scenario] +version = "0.52.3" 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..19cc6160c --- /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] +version = "0.52.3" +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..d5a799634 --- /dev/null +++ b/legacy-contracts/farm-v13-custom-rewards/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta::cli_main::(); +} diff --git a/dex/price-discovery/elrond.json b/legacy-contracts/farm-v13-custom-rewards/multiversx.json similarity index 100% rename from dex/price-discovery/elrond.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..71cf8cf0d --- /dev/null +++ b/legacy-contracts/farm-v13-custom-rewards/src/lib.rs @@ -0,0 +1,258 @@ +#![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, +} + +#[multiversx_sc::contract] +pub trait FarmV13CustomRewards { + #[init] + fn init(&self) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint(addAddressToWhitelist)] + fn add_address_to_whitelist(&self, _address: ManagedAddress) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(calculateRewardsForGivenPosition)] + fn calculate_rewards_for_given_position( + &self, + _amount: BigUint, + _attributes: FarmTokenAttributes, + ) -> SCResult { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[payable("*")] + #[endpoint(claimRewards)] + fn claim_rewards( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> SCResult> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[payable("*")] + #[endpoint(depositRewards)] + fn deposit_rewards(&self) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(end_produce_rewards)] + fn end_produce_rewards(&self) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[payable("*")] + #[endpoint(enterFarm)] + fn enter_farm( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> SCResult> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[payable("*")] + #[endpoint(exitFarm)] + fn exit_farm( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> SCResult> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getBlockForEndRewards)] + fn block_for_end_rewards(&self) -> u64 { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getBurnGasLimit)] + fn burn_gas_limit(&self) -> u64 { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getDivisionSafetyConstant)] + fn division_safety_constant(&self) -> BigUint { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getFarmTokenId)] + fn farm_token_id(&self) -> TokenIdentifier { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getFarmTokenSupply)] + fn farm_token_supply(&self) -> BigUint { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getFarmingTokenId)] + fn farming_token_id(&self) -> TokenIdentifier { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getLastErrorMessage)] + fn last_error_message(&self) -> ManagedBuffer { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getLastRewardBlockNonce)] + fn last_reward_block_nonce(&self) -> Nonce { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getMinimumFarmingEpoch)] + fn minimum_farming_epochs(&self) -> u8 { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getOwner)] + fn owner(&self) -> ManagedAddress { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getPenaltyPercent)] + fn penalty_percent(&self) -> u64 { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getPerBlockRewardAmount)] + fn per_block_reward_amount(&self) -> BigUint { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getRewardPerShare)] + fn reward_per_share(&self) -> BigUint { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getRewardReserve)] + fn reward_reserve(&self) -> BigUint { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getRewardTokenId)] + fn reward_token_id(&self) -> TokenIdentifier { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getState)] + fn state(&self) -> State { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getTransferExecGasLimit)] + fn transfer_exec_gas_limit(&self) -> u64 { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getWhitelist)] + fn whitelist(&self) -> UnorderedSetMapper { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[payable("*")] + #[endpoint(mergeFarmTokens)] + fn merge_farm_tokens( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> SCResult> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(pause)] + fn pause(&self) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[payable("EGLD")] + #[endpoint(registerFarmToken)] + fn register_farm_token( + &self, + _token_display_name: ManagedBuffer, + _token_ticker: ManagedBuffer, + _num_decimals: usize, + ) -> INCORRECTReturnType { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint(removeAddressFromWhitelist)] + fn remove_address_from_whitelist(&self, _address: ManagedAddress) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(resume)] + fn resume(&self) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint(setBlockForEndRewards)] + fn set_block_for_end_rewards(&self, _block_end: u64) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(setLocalRolesFarmToken)] + fn set_local_roles_farm_token(&self) -> INCORRECTReturnType { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(setPerBlockRewardAmount)] + fn set_per_block_reward_amount(&self, _per_block_amount: BigUint) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(set_burn_gas_limit)] + fn set_burn_gas_limit(&self, _gas_limit: u64) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(set_minimum_farming_epochs)] + fn set_minimum_farming_epochs(&self, _epochs: u8) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(set_penalty_percent)] + fn set_penalty_percent(&self, _percent: u64) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(set_transfer_exec_gas_limit)] + fn set_transfer_exec_gas_limit(&self, _gas_limit: u64) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(startProduceRewards)] + fn start_produce_rewards(&self) -> SCResult<()> { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } +} 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..72579ae25 --- /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.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[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.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" +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.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +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.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +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..6eaa243e8 --- /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.52.3" + +[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..31a1cf1fa --- /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.52.3" + +[dev-dependencies] +num-bigint = "0.4" + +[dev-dependencies.multiversx-sc-scenario] +version = "0.52.3" 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..f4fc5fdb2 --- /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] +version = "0.52.3" +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..09e0655ed --- /dev/null +++ b/legacy-contracts/farm-v13-locked-rewards/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta::cli_main::(); +} diff --git a/energy-integration/energy-update/elrond.json b/legacy-contracts/farm-v13-locked-rewards/multiversx.json similarity index 100% rename from energy-integration/energy-update/elrond.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..1ab7cba04 --- /dev/null +++ b/legacy-contracts/farm-v13-locked-rewards/src/lib.rs @@ -0,0 +1,272 @@ +#![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, +} + +#[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!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[payable("*")] + #[endpoint(mergeFarmTokens)] + fn merge_farm_tokens( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> EsdtTokenPayment { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(calculateRewardsForGivenPosition)] + fn calculate_rewards_for_given_position( + &self, + _amount: BigUint, + _attributes: FarmTokenAttributes, + ) -> BigUint { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint] + fn end_produce_rewards(&self) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint(setPerBlockRewardAmount)] + fn set_per_block_rewards(&self, _per_block_amount: BigUint) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint] + fn set_penalty_percent(&self, _percent: u64) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint] + fn set_minimum_farming_epochs(&self, _epochs: u8) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint] + fn set_transfer_exec_gas_limit(&self, _gas_limit: u64) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint] + fn set_burn_gas_limit(&self, _gas_limit: u64) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(setRpsAndStartRewards)] + fn set_rps_and_start_rewards(&self, _rps: BigUint) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint] + fn pause(&self) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint] + fn resume(&self) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(startProduceRewards)] + fn start_produce_rewards_as_owner(&self) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint(setFarmTokenSupply)] + fn set_farm_token_supply(&self, _supply: BigUint) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[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!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[payable("EGLD")] + #[endpoint(registerFarmToken)] + fn register_farm_token( + &self, + _token_display_name: ManagedBuffer, + _token_ticker: ManagedBuffer, + _num_decimals: usize, + ) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint(setLocalRolesFarmToken)] + fn set_local_roles_farm_token(&self) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[payable("*")] + #[endpoint(migrateFromV1_2Farm)] + fn migrate_from_v1_2_farm( + &self, + _old_attrs: FarmTokenAttributesV1_2, + _orig_caller: ManagedAddress, + ) -> EsdtTokenPayment { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[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..648687653 --- /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.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[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.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" +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.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +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.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +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..6c8dfa0f3 --- /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.52.3" + +[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..196c8b313 --- /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.52.3" + +[dev-dependencies] +num-bigint = "0.4" + +[dev-dependencies.multiversx-sc-scenario] +version = "0.52.3" diff --git a/legacy-contracts/farm-v13/meta/Cargo.toml b/legacy-contracts/farm-v13/meta/Cargo.toml new file mode 100644 index 000000000..ae52d18fb --- /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] +version = "0.52.3" +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..e5e10c77e --- /dev/null +++ b/legacy-contracts/farm-v13/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta::cli_main::(); +} diff --git a/legacy-contracts/farm-v13/multiversx.json b/legacy-contracts/farm-v13/multiversx.json new file mode 100644 index 000000000..736553962 --- /dev/null +++ b/legacy-contracts/farm-v13/multiversx.json @@ -0,0 +1,3 @@ +{ + "language": "rust" +} \ No newline at end of file diff --git a/legacy-contracts/farm-v13/src/lib.rs b/legacy-contracts/farm-v13/src/lib.rs new file mode 100644 index 000000000..9d877876f --- /dev/null +++ b/legacy-contracts/farm-v13/src/lib.rs @@ -0,0 +1,303 @@ +#![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, +} + +#[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!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[payable("*")] + #[endpoint(exitFarm)] + fn exit_farm( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> ExitFarmResultType { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[payable("*")] + #[endpoint(claimRewards)] + fn claim_rewards( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> ClaimRewardsResultType { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[payable("*")] + #[endpoint(compoundRewards)] + fn compound_rewards( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> CompoundRewardsResultType { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[payable("*")] + #[endpoint(mergeFarmTokens)] + fn merge_farm_tokens( + &self, + _opt_accept_funds_func: OptionalValue, + ) -> EsdtTokenPayment { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(calculateRewardsForGivenPosition)] + fn calculate_rewards_for_given_position( + &self, + _amount: BigUint, + _attributes: FarmTokenAttributes, + ) -> BigUint { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint] + fn end_produce_rewards(&self) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint(setPerBlockRewardAmount)] + fn set_per_block_rewards(&self, _per_block_amount: BigUint) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint] + fn set_penalty_percent(&self, _percent: u64) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint] + fn set_minimum_farming_epochs(&self, _epochs: u8) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint] + fn set_transfer_exec_gas_limit(&self, _gas_limit: u64) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint] + fn set_burn_gas_limit(&self, _gas_limit: u64) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint] + fn pause(&self) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint] + fn resume(&self) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(startProduceRewards)] + fn start_produce_rewards_as_owner(&self) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint(setFarmTokenSupply)] + fn set_farm_token_supply(&self, _supply: BigUint) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[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!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[payable("EGLD")] + #[endpoint(registerFarmToken)] + fn register_farm_token( + &self, + _token_display_name: ManagedBuffer, + _token_ticker: ManagedBuffer, + _num_decimals: usize, + ) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint(setLocalRolesFarmToken)] + fn set_local_roles_farm_token(&self) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[endpoint(setRpsAndStartRewards)] + fn set_rps_and_start_rewards(&self, _rps: BigUint) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[payable("*")] + #[endpoint(migrateFromV1_2Farm)] + fn migrate_from_v1_2_farm( + &self, + _old_attrs: FarmTokenAttributesV1_2, + _orig_caller: ManagedAddress, + ) -> EsdtTokenPayment { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[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..2f99076f5 --- /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.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[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.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" +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.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +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.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +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/wasm/Cargo.toml b/legacy-contracts/farm-v13/wasm/Cargo.toml new file mode 100644 index 000000000..12487fd26 --- /dev/null +++ b/legacy-contracts/farm-v13/wasm/Cargo.toml @@ -0,0 +1,34 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + +[package] +name = "farm-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-v13] +path = ".." + +[dependencies.multiversx-sc-wasm-adapter] +version = "0.52.3" + +[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/legacy-contracts/price-discovery-v1/Cargo.toml b/legacy-contracts/price-discovery-v1/Cargo.toml new file mode 100644 index 000000000..d00d06b39 --- /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.52.3" + +[dev-dependencies] +num-bigint = "0.4" + +[dev-dependencies.multiversx-sc-scenario] +version = "0.52.3" 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..8a10570f7 --- /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] +version = "0.52.3" +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..e9b6d8d7e --- /dev/null +++ b/legacy-contracts/price-discovery-v1/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta::cli_main::(); +} diff --git a/legacy-contracts/price-discovery-v1/multiversx.json b/legacy-contracts/price-discovery-v1/multiversx.json new file mode 100644 index 000000000..736553962 --- /dev/null +++ b/legacy-contracts/price-discovery-v1/multiversx.json @@ -0,0 +1,3 @@ +{ + "language": "rust" +} \ No newline at end of file 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..4ac38f975 --- /dev/null +++ b/legacy-contracts/price-discovery-v1/src/lib.rs @@ -0,0 +1,150 @@ +#![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, +} + +#[multiversx_sc::contract] +pub trait PriceDiscoveryV1 { + #[init] + fn init(&self) {} + + #[payable("*")] + #[endpoint] + fn deposit(&self) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[payable("*")] + #[endpoint] + fn withdraw(&self) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[payable("*")] + #[endpoint] + fn redeem(&self) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getCurrentPrice)] + fn calculate_price(&self) -> BigUint { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getCurrentPhase)] + fn get_current_phase(&self) -> Phase { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[payable("EGLD")] + #[endpoint(issueRedeemToken)] + fn issue_redeem_token( + &self, + _token_name: ManagedBuffer, + _token_ticker: ManagedBuffer, + _nr_decimals: usize, + ) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint(createInitialRedeemTokens)] + fn create_initial_redeem_tokens(&self) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint(setLockingScAddress)] + fn set_locking_sc_address(&self, _new_address: ManagedAddress) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint(setUnlockEpoch)] + fn set_unlock_epoch(&self, _new_epoch: u64) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[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..a1b884dc9 --- /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.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[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.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" +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.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +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.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +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/price-discovery-v1/wasm/Cargo.toml b/legacy-contracts/price-discovery-v1/wasm/Cargo.toml new file mode 100644 index 000000000..52fee981c --- /dev/null +++ b/legacy-contracts/price-discovery-v1/wasm/Cargo.toml @@ -0,0 +1,34 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + +[package] +name = "price-discovery-v1-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.price-discovery-v1] +path = ".." + +[dependencies.multiversx-sc-wasm-adapter] +version = "0.52.3" + +[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..e2f00ec89 --- /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.52.3" + +[dev-dependencies] +num-bigint = "0.4" + +[dev-dependencies.multiversx-sc-scenario] +version = "0.52.3" 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..66b16ff3d --- /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] +version = "0.52.3" +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..49e9a3810 --- /dev/null +++ b/legacy-contracts/price-discovery-v2/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta::cli_main::(); +} diff --git a/legacy-contracts/price-discovery-v2/multiversx.json b/legacy-contracts/price-discovery-v2/multiversx.json new file mode 100644 index 000000000..736553962 --- /dev/null +++ b/legacy-contracts/price-discovery-v2/multiversx.json @@ -0,0 +1,3 @@ +{ + "language": "rust" +} \ No newline at end of file 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..34de9499b --- /dev/null +++ b/legacy-contracts/price-discovery-v2/src/lib.rs @@ -0,0 +1,150 @@ +#![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, +} + +#[multiversx_sc::contract] +pub trait PriceDiscoveryV2 { + #[init] + fn init(&self) {} + + #[payable("*")] + #[endpoint] + fn deposit(&self) -> EsdtTokenPayment { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[payable("*")] + #[endpoint] + fn withdraw(&self) -> EgldOrEsdtTokenPayment { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[payable("*")] + #[endpoint] + fn redeem(&self) -> EgldOrEsdtTokenPayment { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getCurrentPrice)] + fn calculate_price(&self) -> BigUint { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[view(getCurrentPhase)] + fn get_current_phase(&self) -> Phase { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[payable("EGLD")] + #[endpoint(issueRedeemToken)] + fn issue_redeem_token( + &self, + _token_name: ManagedBuffer, + _token_ticker: ManagedBuffer, + _nr_decimals: usize, + ) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint(createInitialRedeemTokens)] + fn create_initial_redeem_tokens(&self) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint(setLockingScAddress)] + fn set_locking_sc_address(&self, _new_address: ManagedAddress) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[only_owner] + #[endpoint(setUnlockEpoch)] + fn set_unlock_epoch(&self, _new_epoch: u64) { + sc_panic!("This is a no-code version of a legacy contract. The logic of the endpoints has not been implemented."); + } + + #[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..f1bdaed4b --- /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.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[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.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" +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.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +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.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +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/price-discovery-v2/wasm/Cargo.toml b/legacy-contracts/price-discovery-v2/wasm/Cargo.toml new file mode 100644 index 000000000..c5a34afb0 --- /dev/null +++ b/legacy-contracts/price-discovery-v2/wasm/Cargo.toml @@ -0,0 +1,34 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + +[package] +name = "price-discovery-v2-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.price-discovery-v2] +path = ".." + +[dependencies.multiversx-sc-wasm-adapter] +version = "0.52.3" + +[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/legacy-contracts/proxy-dex-legacy/.gitignore b/legacy-contracts/proxy-dex-legacy/.gitignore new file mode 100644 index 000000000..eaf5915bd --- /dev/null +++ b/legacy-contracts/proxy-dex-legacy/.gitignore @@ -0,0 +1,7 @@ +# Generated by Cargo +# will have compiled files and executables +/target/ +*/target/ + +# The erdpy 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..2567e0195 --- /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.52.3" +features = ["esdt-token-payment-legacy-decode"] + +[dev-dependencies.multiversx-sc-scenario] +version = "=0.52.3" + +[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" \ No newline at end of file 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..7b04c9d2c --- /dev/null +++ b/legacy-contracts/proxy-dex-legacy/meta/Cargo.toml @@ -0,0 +1,14 @@ +[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] +version = "0.52.3" +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..c282d1ab7 --- /dev/null +++ b/legacy-contracts/proxy-dex-legacy/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta::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/legacy-contracts/proxy-dex-legacy/testnet.toml b/legacy-contracts/proxy-dex-legacy/testnet.toml new file mode 100644 index 000000000..e69de29bb diff --git a/legacy-contracts/proxy-dex-legacy/wasm/Cargo.lock b/legacy-contracts/proxy-dex-legacy/wasm/Cargo.lock new file mode 100644 index 000000000..830467f4b --- /dev/null +++ b/legacy-contracts/proxy-dex-legacy/wasm/Cargo.lock @@ -0,0 +1,448 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[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-types" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "common_errors" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "common_structs" +version = "0.0.0" +dependencies = [ + "fixed-supply-token", + "math", + "mergeable", + "multiversx-sc", + "unwrappable", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + +[[package]] +name = "energy-factory" +version = "0.0.0" +dependencies = [ + "common_structs", + "legacy_token_decode_module", + "math", + "mergeable", + "multiversx-sc", + "multiversx-sc-modules", + "sc_whitelist_module", + "simple-lock", + "unwrappable", + "utils", +] + +[[package]] +name = "energy-query" +version = "0.0.0" +dependencies = [ + "energy-factory", + "multiversx-sc", +] + +[[package]] +name = "factory-legacy" +version = "0.0.0" +dependencies = [ + "common_errors", + "common_structs", + "energy-factory", + "multiversx-sc", + "multiversx-sc-modules", + "token_merge_helper", +] + +[[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]] +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 = "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" +dependencies = [ + "common_structs", + "multiversx-sc", + "utils", +] + +[[package]] +name = "locking_module" +version = "0.0.0" +dependencies = [ + "energy-factory", + "multiversx-sc", + "simple-lock", +] + +[[package]] +name = "math" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "mergeable" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "multiversx-sc" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-modules" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" +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 = "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.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +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.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +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 = "sc_whitelist_module" +version = "0.0.0" +dependencies = [ + "common_errors", + "multiversx-sc", +] + +[[package]] +name = "simple-lock" +version = "0.0.0" +dependencies = [ + "common_structs", + "multiversx-sc", + "multiversx-sc-modules", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "syn" +version = "2.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "token_merge_helper" +version = "0.0.0" +dependencies = [ + "common_errors", + "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" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "utils" +version = "0.0.0" +dependencies = [ + "common_structs", + "fixed-supply-token", + "mergeable", + "multiversx-sc", +] + +[[package]] +name = "week-timekeeping" +version = "0.0.0" +dependencies = [ + "common-types", + "multiversx-sc", +] + +[[package]] +name = "weekly-rewards-splitting" +version = "0.0.0" +dependencies = [ + "common-types", + "energy-query", + "math", + "multiversx-sc", + "unwrappable", + "week-timekeeping", +] 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..28c7bfe76 --- /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.52.3" + +[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/locked-asset/simple-lock-whitelist/Cargo.toml b/legacy-contracts/simple-lock-legacy/Cargo.toml similarity index 55% rename from locked-asset/simple-lock-whitelist/Cargo.toml rename to legacy-contracts/simple-lock-legacy/Cargo.toml index a8d637a5c..465b3372e 100644 --- a/locked-asset/simple-lock-whitelist/Cargo.toml +++ b/legacy-contracts/simple-lock-legacy/Cargo.toml @@ -1,25 +1,22 @@ [package] -name = "simple-lock-whitelist" +name = "simple-lock-legacy" version = "0.0.0" -authors = ["Dorin Iancu "] +authors = ["MultiversX "] 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" +version = "=0.52.3" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" + +[dependencies.common_structs] +path = "../../common/common_structs" [dev-dependencies] num-bigint = "0.4.2" @@ -27,4 +24,4 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.52.3" diff --git a/legacy-contracts/simple-lock-legacy/meta/Cargo.toml b/legacy-contracts/simple-lock-legacy/meta/Cargo.toml new file mode 100644 index 000000000..f561fae63 --- /dev/null +++ b/legacy-contracts/simple-lock-legacy/meta/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "simple-lock-legacy-meta" +version = "0.0.0" +edition = "2021" +publish = false +authors = ["MultiversX "] + +[dependencies.simple-lock-legacy] +path = ".." + +[dependencies.multiversx-sc-meta] +version = "0.52.3" +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..8f84e327a --- /dev/null +++ b/legacy-contracts/simple-lock-legacy/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta::cli_main::(); +} diff --git a/legacy-contracts/simple-lock-legacy/multiversx.json b/legacy-contracts/simple-lock-legacy/multiversx.json new file mode 100644 index 000000000..736553962 --- /dev/null +++ b/legacy-contracts/simple-lock-legacy/multiversx.json @@ -0,0 +1,3 @@ +{ + "language": "rust" +} \ No newline at end of file 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 71% rename from locked-asset/simple-lock-whitelist/wasm/Cargo.lock rename to legacy-contracts/simple-lock-legacy/wasm/Cargo.lock index e6300116a..0ce02d62b 100644 --- a/locked-asset/simple-lock-whitelist/wasm/Cargo.lock +++ b/legacy-contracts/simple-lock-legacy/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -107,9 +109,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -120,18 +122,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..208b10e76 --- /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.52.3" + +[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..664556963 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dependencies.farm] @@ -50,7 +50,7 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.52.3" diff --git a/locked-asset/distribution/Cargo.toml b/locked-asset/distribution/Cargo.toml index 3ebf0939b..94a6783ee 100644 --- a/locked-asset/distribution/Cargo.toml +++ b/locked-asset/distribution/Cargo.toml @@ -14,8 +14,8 @@ path = "../../common/common_structs" path = "../factory" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.52.3" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.52.3" diff --git a/locked-asset/distribution/meta/Cargo.toml b/locked-asset/distribution/meta/Cargo.toml index 76c13747b..532a034b9 100644 --- a/locked-asset/distribution/meta/Cargo.toml +++ b/locked-asset/distribution/meta/Cargo.toml @@ -9,5 +9,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false diff --git a/locked-asset/distribution/src/lib.rs b/locked-asset/distribution/src/lib.rs index 93187154e..b996701df 100644 --- a/locked-asset/distribution/src/lib.rs +++ b/locked-asset/distribution/src/lib.rs @@ -47,7 +47,7 @@ pub trait Distribution: global_op::GlobalOperationModule { .set_if_empty(&locked_asset_factory_address); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[only_owner] diff --git a/locked-asset/distribution/wasm/Cargo.lock b/locked-asset/distribution/wasm/Cargo.lock index fce0d3ebe..ff20f5e5a 100644 --- a/locked-asset/distribution/wasm/Cargo.lock +++ b/locked-asset/distribution/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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" @@ -63,9 +63,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" @@ -144,9 +144,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.151" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "math" @@ -170,32 +170,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -205,9 +207,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -218,18 +220,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" dependencies = [ "multiversx-sc", ] @@ -245,27 +247,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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -299,15 +301,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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" dependencies = [ "proc-macro2", "quote", @@ -337,6 +339,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/distribution/wasm/Cargo.toml b/locked-asset/distribution/wasm/Cargo.toml index f1cc0ae57..5c94e6ebb 100644 --- a/locked-asset/distribution/wasm/Cargo.toml +++ b/locked-asset/distribution/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.distribution] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.52.3" [workspace] members = ["."] diff --git a/locked-asset/distribution/wasm/src/lib.rs b/locked-asset/distribution/wasm/src/lib.rs index 87c728bb7..4f919ac08 100644 --- a/locked-asset/distribution/wasm/src/lib.rs +++ b/locked-asset/distribution/wasm/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 16 +// Upgrade: 1 +// Endpoints: 15 // 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!(); diff --git a/locked-asset/energy-factory/Cargo.toml b/locked-asset/energy-factory/Cargo.toml index 74e3cbea9..c41abf0f6 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" [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.52.3" diff --git a/locked-asset/energy-factory/meta/Cargo.toml b/locked-asset/energy-factory/meta/Cargo.toml index 6365191f0..f85c5b818 100644 --- a/locked-asset/energy-factory/meta/Cargo.toml +++ b/locked-asset/energy-factory/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false diff --git a/locked-asset/energy-factory/src/lib.rs b/locked-asset/energy-factory/src/lib.rs index d146566d6..f38c2e0e7 100644 --- a/locked-asset/energy-factory/src/lib.rs +++ b/locked-asset/energy-factory/src/lib.rs @@ -91,7 +91,7 @@ pub trait SimpleLockEnergy: self.set_paused(true); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} /// Locks a whitelisted token until `unlock_epoch` and receive meta ESDT LOCKED tokens diff --git a/locked-asset/energy-factory/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..7d2c17b79 100644 --- a/locked-asset/energy-factory/tests/energy_factory_setup/mod.rs +++ b/locked-asset/energy-factory/tests/energy_factory_setup/mod.rs @@ -173,6 +173,7 @@ where token_nonce: u64, amount: u64, lock_epochs: u64, + opt_address: Option
, ) -> TxResult { self.b_mock.execute_esdt_transfer( caller, @@ -181,7 +182,15 @@ where token_nonce, &rust_biguint!(amount), |sc| { - sc.lock_tokens_endpoint(lock_epochs, OptionalValue::None); + if opt_address.is_some() { + let address = opt_address.unwrap(); + sc.lock_tokens_endpoint( + lock_epochs, + OptionalValue::Some(managed_address!(&address)), + ); + } else { + sc.lock_tokens_endpoint(lock_epochs, OptionalValue::None); + } }, ) } diff --git a/locked-asset/energy-factory/tests/simple_lock_energy_test.rs b/locked-asset/energy-factory/tests/simple_lock_energy_test.rs index 823a8eb56..202630958 100644 --- a/locked-asset/energy-factory/tests/simple_lock_energy_test.rs +++ b/locked-asset/energy-factory/tests/simple_lock_energy_test.rs @@ -2,7 +2,9 @@ mod energy_factory_setup; -use energy_factory::energy::EnergyModule; +use energy_factory::{ + energy::EnergyModule, locked_token_transfer::LockedTokenTransferModule, SimpleLockEnergy, +}; use energy_factory_setup::*; use multiversx_sc::types::BigUint; use simple_lock::locked_token::LockedTokenAttributes; @@ -315,6 +317,7 @@ fn reduce_lock_period_test() { fn extend_locking_period_test() { let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); let first_user = setup.first_user.clone(); + let random_user = setup.b_mock.create_user_account(&rust_biguint!(0u64)); let half_balance = USER_BALANCE / 2; let current_epoch = 1; @@ -329,7 +332,7 @@ fn extend_locking_period_test() { ) .assert_ok(); - // extend to 3 years - unsupported option + // extend to a random period - unsupported option setup .extend_locking_period( &first_user, @@ -337,10 +340,30 @@ fn extend_locking_period_test() { 1, half_balance, 3 * EPOCHS_IN_YEAR, + None, ) .assert_user_error("Invalid lock choice"); - // extend to 10 years + // extend to a whitelisted period, but for a different user + setup + .extend_locking_period( + &first_user, + LOCKED_TOKEN_ID, + 1, + half_balance, + LOCK_OPTIONS[1], + Some(random_user), + ) + .assert_user_error("May not use the optional destination argument here"); + + // extend to the second option - should work as intended + // 1 epoch has passed + let energy_per_epoch = rust_biguint!(500_000_000_000_000_000u64); + let energy_before = setup.get_user_energy(&first_user); // 179_500_000_000_000_000_000 + assert_eq!( + energy_before, + LOCK_OPTIONS[0] * energy_per_epoch.clone() - energy_per_epoch.clone() + ); setup .extend_locking_period( &first_user, @@ -348,8 +371,14 @@ fn extend_locking_period_test() { 1, half_balance, LOCK_OPTIONS[1], + None, ) .assert_ok(); + let energy_after = setup.get_user_energy(&first_user); // 359_500_000_000_000_000_000 + assert_eq!( + energy_after, + LOCK_OPTIONS[1] * energy_per_epoch.clone() - energy_per_epoch.clone() + ); let new_unlock_epoch = to_start_of_month(current_epoch + LOCK_OPTIONS[1]); setup.b_mock.check_nft_balance( @@ -376,6 +405,7 @@ fn extend_locking_period_test() { 2, half_balance, LOCK_OPTIONS[0], + None, ) .assert_user_error("New lock period must be longer than the current one"); } @@ -461,3 +491,78 @@ fn energy_deplete_test() { }) .assert_ok(); } + +#[test] +fn extend_lock_period_endpoint_test() { + let mut setup = SimpleLockEnergySetup::new(energy_factory::contract_obj); + let first_user = setup.first_user.clone(); + + let current_epoch = 1; + setup.b_mock.set_block_epoch(current_epoch); + + setup + .lock( + &first_user, + BASE_ASSET_TOKEN_ID, + USER_BALANCE, + LOCK_OPTIONS[0], + ) + .assert_ok(); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.sc_wrapper, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.extend_lock_period(100, managed_address!(&first_user)); + }, + ) + .assert_user_error("Invalid lock choice"); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.sc_wrapper, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.extend_lock_period(LOCK_OPTIONS[0], managed_address!(&first_user)); + }, + ) + .assert_user_error("May not call this endpoint. Use lockTokens instead"); + + let energy_per_epoch = rust_biguint!(USER_BALANCE); + let energy_before = setup.get_user_energy(&first_user); + assert_eq!( + energy_before, + LOCK_OPTIONS[0] * energy_per_epoch.clone() - energy_per_epoch.clone() + ); + + setup + .b_mock + .execute_esdt_transfer( + &first_user, + &setup.sc_wrapper, + LOCKED_TOKEN_ID, + 1, + &rust_biguint!(USER_BALANCE), + |sc| { + sc.token_transfer_whitelist() + .add(&managed_address!(&first_user)); + sc.extend_lock_period(LOCK_OPTIONS[1], managed_address!(&first_user)); + }, + ) + .assert_ok(); + + let energy_after = setup.get_user_energy(&first_user); + assert_eq!( + energy_after, + LOCK_OPTIONS[1] * energy_per_epoch.clone() - energy_per_epoch.clone() + ); +} diff --git a/locked-asset/energy-factory/wasm/Cargo.lock b/locked-asset/energy-factory/wasm/Cargo.lock index b7f42af38..f1b55e72c 100644 --- a/locked-asset/energy-factory/wasm/Cargo.lock +++ b/locked-asset/energy-factory/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -147,9 +149,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -160,18 +162,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..13119f8cd 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.52.3" [workspace] members = ["."] diff --git a/locked-asset/energy-factory/wasm/src/lib.rs b/locked-asset/energy-factory/wasm/src/lib.rs index 7393a9e97..fafdc534e 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 -// Endpoints: 34 +// Upgrade: 1 +// Endpoints: 33 // Async Callback: 1 // Total number of exported functions: 36 #![no_std] -#![allow(internal_features)] -#![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); multiversx_sc_wasm_adapter::panic_handler!(); diff --git a/locked-asset/factory/Cargo.toml b/locked-asset/factory/Cargo.toml index 6996881d1..72efa530a 100644 --- a/locked-asset/factory/Cargo.toml +++ b/locked-asset/factory/Cargo.toml @@ -26,11 +26,11 @@ path = "../../common/modules/token_merge_helper" path = "../energy-factory" [dependencies.multiversx-sc] -version = "=0.46.1" +version = "=0.52.3" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" [dependencies.arrayvec] version = "0.7.1" @@ -49,4 +49,4 @@ hex = "0.4" path = "../simple-lock" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.52.3" diff --git a/locked-asset/factory/meta/Cargo.toml b/locked-asset/factory/meta/Cargo.toml index d81d3bb85..9c2bc7b20 100644 --- a/locked-asset/factory/meta/Cargo.toml +++ b/locked-asset/factory/meta/Cargo.toml @@ -9,5 +9,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false diff --git a/locked-asset/factory/src/lib.rs b/locked-asset/factory/src/lib.rs index d8de993b4..268ff0c05 100644 --- a/locked-asset/factory/src/lib.rs +++ b/locked-asset/factory/src/lib.rs @@ -1,7 +1,6 @@ #![no_std] -#![feature(exact_size_is_empty)] -mod attr_ex_helper; +pub mod attr_ex_helper; mod cache; mod events; pub mod locked_asset; @@ -63,7 +62,7 @@ pub trait LockedAssetFactory: self.set_paused(true); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} fn set_extended_attributes_activation_nonce(&self, is_sc_upgrade: bool) { diff --git a/locked-asset/factory/src/locked_asset_token_merge.rs b/locked-asset/factory/src/locked_asset_token_merge.rs index 995d13528..f2c76f235 100644 --- a/locked-asset/factory/src/locked_asset_token_merge.rs +++ b/locked-asset/factory/src/locked_asset_token_merge.rs @@ -49,8 +49,6 @@ pub trait LockedAssetTokenMergeModule: &self, payments: ManagedVecRefIterator>, ) -> (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(); @@ -70,6 +68,8 @@ pub trait LockedAssetTokenMergeModule: }); } + require!(!tokens.is_empty(), "Cannot merge with 0 tokens"); + if tokens.len() == 1 { let token_0 = tokens.get(0); return (token_0.token_amount.amount, token_0.attributes); diff --git a/locked-asset/factory/wasm/Cargo.lock b/locked-asset/factory/wasm/Cargo.lock index 39d478ef4..0464466be 100644 --- a/locked-asset/factory/wasm/Cargo.lock +++ b/locked-asset/factory/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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" @@ -46,9 +46,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" @@ -135,9 +135,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.151" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "math" @@ -161,32 +161,34 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -196,9 +198,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -209,18 +211,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" dependencies = [ "multiversx-sc", ] @@ -236,27 +238,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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -290,15 +292,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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" dependencies = [ "proc-macro2", "quote", @@ -328,6 +330,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/factory/wasm/Cargo.toml b/locked-asset/factory/wasm/Cargo.toml index eb8c084a5..4fdf6de1c 100644 --- a/locked-asset/factory/wasm/Cargo.toml +++ b/locked-asset/factory/wasm/Cargo.toml @@ -21,11 +21,14 @@ debug = false panic = "abort" overflow-checks = false +[profile.dev] +panic = "abort" + [dependencies.factory] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.46.1" +version = "=0.52.3" [workspace] members = ["."] diff --git a/locked-asset/factory/wasm/src/lib.rs b/locked-asset/factory/wasm/src/lib.rs index 7ad9e4ac0..8b83df95b 100644 --- a/locked-asset/factory/wasm/src/lib.rs +++ b/locked-asset/factory/wasm/src/lib.rs @@ -5,13 +5,12 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 25 +// Upgrade: 1 +// Endpoints: 24 // 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!(); diff --git a/locked-asset/lkmex-transfer/Cargo.toml b/locked-asset/lkmex-transfer/Cargo.toml index a6fb9ca95..c08031b0e 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.52.3" [dev-dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" diff --git a/locked-asset/lkmex-transfer/meta/Cargo.toml b/locked-asset/lkmex-transfer/meta/Cargo.toml index e0c0588d1..e63c0888a 100644 --- a/locked-asset/lkmex-transfer/meta/Cargo.toml +++ b/locked-asset/lkmex-transfer/meta/Cargo.toml @@ -9,5 +9,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false diff --git a/locked-asset/lkmex-transfer/src/lib.rs b/locked-asset/lkmex-transfer/src/lib.rs index 7c187882e..126e740b8 100644 --- a/locked-asset/lkmex-transfer/src/lib.rs +++ b/locked-asset/lkmex-transfer/src/lib.rs @@ -56,7 +56,7 @@ pub trait LkmexTransfer: self.add_permissions(caller, Permissions::OWNER); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[endpoint] diff --git a/locked-asset/lkmex-transfer/wasm/Cargo.lock b/locked-asset/lkmex-transfer/wasm/Cargo.lock index 503d067d7..6e4c444f9 100644 --- a/locked-asset/lkmex-transfer/wasm/Cargo.lock +++ b/locked-asset/lkmex-transfer/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -169,9 +171,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -182,18 +184,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..2ac287015 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.52.3" [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..f4794c746 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.52.3" [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" [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.52.3" diff --git a/locked-asset/locked-token-wrapper/meta/Cargo.toml b/locked-asset/locked-token-wrapper/meta/Cargo.toml index 6de0a4093..6e95f2dcf 100644 --- a/locked-asset/locked-token-wrapper/meta/Cargo.toml +++ b/locked-asset/locked-token-wrapper/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false 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..e5c97d121 100644 --- a/locked-asset/locked-token-wrapper/wasm/Cargo.lock +++ b/locked-asset/locked-token-wrapper/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -193,9 +195,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -206,18 +208,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..e89aace72 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.52.3" [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..1e4675ccb 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" [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.52.3" [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..c1298c9c8 100644 --- a/locked-asset/proxy_dex/meta/Cargo.toml +++ b/locked-asset/proxy_dex/meta/Cargo.toml @@ -9,5 +9,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false 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..8bdd9ad2b 100644 --- a/locked-asset/proxy_dex/wasm/Cargo.lock +++ b/locked-asset/proxy_dex/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -342,9 +344,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -355,18 +357,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..bab8859ab 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.52.3" [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/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/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..7781b5929 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" [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.52.3" diff --git a/locked-asset/simple-lock/meta/Cargo.toml b/locked-asset/simple-lock/meta/Cargo.toml index 889dce931..e7a939a39 100644 --- a/locked-asset/simple-lock/meta/Cargo.toml +++ b/locked-asset/simple-lock/meta/Cargo.toml @@ -9,5 +9,5 @@ authors = ["Dorin Iancu "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false 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..439762d95 100644 --- a/locked-asset/simple-lock/wasm/Cargo.lock +++ b/locked-asset/simple-lock/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -107,9 +109,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -120,18 +122,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..b749b73db 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.52.3" [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..fbcf1e07c 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.52.3" 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.52.3" [dev-dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" diff --git a/locked-asset/token-unstake/meta/Cargo.toml b/locked-asset/token-unstake/meta/Cargo.toml index fb4914c3d..f3552ba6d 100644 --- a/locked-asset/token-unstake/meta/Cargo.toml +++ b/locked-asset/token-unstake/meta/Cargo.toml @@ -9,5 +9,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false diff --git a/locked-asset/token-unstake/src/lib.rs b/locked-asset/token-unstake/src/lib.rs index 6295d46a2..985e91be9 100644 --- a/locked-asset/token-unstake/src/lib.rs +++ b/locked-asset/token-unstake/src/lib.rs @@ -42,6 +42,6 @@ pub trait TokenUnstakeModule: self.fees_burn_percentage().set(fees_burn_percentage); } - #[endpoint] + #[upgrade] fn upgrade(&self) {} } diff --git a/locked-asset/token-unstake/wasm/Cargo.lock b/locked-asset/token-unstake/wasm/Cargo.lock index d74f133fa..74fdec9ce 100644 --- a/locked-asset/token-unstake/wasm/Cargo.lock +++ b/locked-asset/token-unstake/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -154,9 +156,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -167,18 +169,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..378cdd817 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.52.3" [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..7d9df52ad 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.52.3" features = ["esdt-token-payment-legacy-decode"] [dependencies.multiversx-sc-modules] -version = "=0.46.1" +version = "=0.52.3" [dev-dependencies.multiversx-sc-scenario] -version = "=0.46.1" +version = "=0.52.3" [dev-dependencies.farm] path = "../dex/farm" diff --git a/pause-all/meta/Cargo.toml b/pause-all/meta/Cargo.toml index f6be6643e..67f00b69e 100644 --- a/pause-all/meta/Cargo.toml +++ b/pause-all/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = ["MultiversX "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.46.1" +version = "0.52.3" default-features = false diff --git a/pause-all/src/lib.rs b/pause-all/src/lib.rs index 6e9bcd823..05f7fe541 100644 --- a/pause-all/src/lib.rs +++ b/pause-all/src/lib.rs @@ -28,7 +28,7 @@ pub trait PauseAll: #[init] fn init(&self) {} - #[endpoint] + #[upgrade] fn upgrade(&self) {} #[only_owner] diff --git a/pause-all/wasm/Cargo.lock b/pause-all/wasm/Cargo.lock index d1b8021d6..483da2b83 100644 --- a/pause-all/wasm/Cargo.lock +++ b/pause-all/wasm/Cargo.lock @@ -10,15 +10,15 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[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.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" 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.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", + "unwrap-infallible", ] [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.3" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" dependencies = [ "hex", "proc-macro2", @@ -82,9 +84,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" dependencies = [ "hex", "proc-macro2", @@ -95,18 +97,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +checksum = "61f5c29c6044f3dc9e866858feee625d7fae5604a68ac7bd66dec683eee97563" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.46.1" +version = "0.52.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" 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.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 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.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" 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..019f093a5 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.52.3" [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!();