From 18379ff598f06c74135a1d98e607a8a351e2acb3 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Mon, 2 Sep 2024 15:53:06 +0300 Subject: [PATCH 01/98] Generated liquid-staking contract Signed-off-by: Andrei Baltariu --- liquid-staking/Cargo.toml | 24 ++++++++++++ liquid-staking/meta/Cargo.toml | 12 ++++++ liquid-staking/meta/src/main.rs | 3 ++ liquid-staking/multiversx.json | 3 ++ .../scenarios/liquid_staking.scen.json | 39 +++++++++++++++++++ liquid-staking/src/liquid_staking.rs | 14 +++++++ .../tests/liquid_staking_scenario_go_test.rs | 10 +++++ .../tests/liquid_staking_scenario_rs_test.rs | 13 +++++++ 8 files changed, 118 insertions(+) create mode 100644 liquid-staking/Cargo.toml create mode 100644 liquid-staking/meta/Cargo.toml create mode 100644 liquid-staking/meta/src/main.rs create mode 100644 liquid-staking/multiversx.json create mode 100644 liquid-staking/scenarios/liquid_staking.scen.json create mode 100644 liquid-staking/src/liquid_staking.rs create mode 100644 liquid-staking/tests/liquid_staking_scenario_go_test.rs create mode 100644 liquid-staking/tests/liquid_staking_scenario_rs_test.rs diff --git a/liquid-staking/Cargo.toml b/liquid-staking/Cargo.toml new file mode 100644 index 00000000..419df715 --- /dev/null +++ b/liquid-staking/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "liquid-staking" +version = "0.0.0" +authors = ["you"] +edition = "2021" +publish = false + +[lib] +path = "src/liquid_staking.rs" + +[dependencies.multiversx-sc] +version = "0.52.3" + +[dev-dependencies] +num-bigint = "0.4" + +[dev-dependencies.multiversx-sc-scenario] +version = "0.52.3" + +[workspace] +members = [ + ".", + "meta", +] diff --git a/liquid-staking/meta/Cargo.toml b/liquid-staking/meta/Cargo.toml new file mode 100644 index 00000000..a93b6401 --- /dev/null +++ b/liquid-staking/meta/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "liquid-staking-meta" +version = "0.0.0" +edition = "2021" +publish = false + +[dependencies.liquid-staking] +path = ".." + +[dependencies.multiversx-sc-meta-lib] +version = "0.52.3" +default-features = false diff --git a/liquid-staking/meta/src/main.rs b/liquid-staking/meta/src/main.rs new file mode 100644 index 00000000..318631a8 --- /dev/null +++ b/liquid-staking/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta_lib::cli_main::(); +} diff --git a/liquid-staking/multiversx.json b/liquid-staking/multiversx.json new file mode 100644 index 00000000..73655396 --- /dev/null +++ b/liquid-staking/multiversx.json @@ -0,0 +1,3 @@ +{ + "language": "rust" +} \ No newline at end of file diff --git a/liquid-staking/scenarios/liquid_staking.scen.json b/liquid-staking/scenarios/liquid_staking.scen.json new file mode 100644 index 00000000..1527f733 --- /dev/null +++ b/liquid-staking/scenarios/liquid_staking.scen.json @@ -0,0 +1,39 @@ +{ + "name": "empty", + "steps": [ + { + "step": "setState", + "accounts": { + "address:owner": { + "nonce": "1", + "balance": "0" + } + }, + "newAddresses": [ + { + "creatorAddress": "address:owner", + "creatorNonce": "1", + "newAddress": "sc:empty" + } + ] + }, + { + "step": "scDeploy", + "id": "deploy", + "tx": { + "from": "address:owner", + "contractCode": "mxsc:../output/liquid-staking.mxsc.json", + "arguments": [], + "gasLimit": "5,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [], + "status": "", + "logs": [], + "gas": "*", + "refund": "*" + } + } + ] +} diff --git a/liquid-staking/src/liquid_staking.rs b/liquid-staking/src/liquid_staking.rs new file mode 100644 index 00000000..f1044a8e --- /dev/null +++ b/liquid-staking/src/liquid_staking.rs @@ -0,0 +1,14 @@ +#![no_std] + +#[allow(unused_imports)] +use multiversx_sc::imports::*; + +/// An empty contract. To be used as a template when starting a new contract from scratch. +#[multiversx_sc::contract] +pub trait LiquidStaking { + #[init] + fn init(&self) {} + + #[upgrade] + fn upgrade(&self) {} +} diff --git a/liquid-staking/tests/liquid_staking_scenario_go_test.rs b/liquid-staking/tests/liquid_staking_scenario_go_test.rs new file mode 100644 index 00000000..fd22b435 --- /dev/null +++ b/liquid-staking/tests/liquid_staking_scenario_go_test.rs @@ -0,0 +1,10 @@ +use multiversx_sc_scenario::*; + +fn world() -> ScenarioWorld { + ScenarioWorld::vm_go() +} + +#[test] +fn empty_go() { + world().run("scenarios/liquid_staking.scen.json"); +} diff --git a/liquid-staking/tests/liquid_staking_scenario_rs_test.rs b/liquid-staking/tests/liquid_staking_scenario_rs_test.rs new file mode 100644 index 00000000..4c0a8be3 --- /dev/null +++ b/liquid-staking/tests/liquid_staking_scenario_rs_test.rs @@ -0,0 +1,13 @@ +use multiversx_sc_scenario::*; + +fn world() -> ScenarioWorld { + let mut blockchain = ScenarioWorld::new(); + + blockchain.register_contract("mxsc:output/liquid-staking.mxsc.json", liquid_staking::ContractBuilder); + blockchain +} + +#[test] +fn empty_rs() { + world().run("scenarios/liquid_staking.scen.json"); +} From cb2a96c20d0d78230380cad4502b0f1747a5661a Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Thu, 12 Sep 2024 13:59:03 +0300 Subject: [PATCH 02/98] Renamed main file Signed-off-by: Andrei Baltariu --- liquid-staking/Cargo.toml | 2 +- liquid-staking/src/{liquid_staking.rs => lib.rs} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename liquid-staking/src/{liquid_staking.rs => lib.rs} (100%) diff --git a/liquid-staking/Cargo.toml b/liquid-staking/Cargo.toml index 419df715..96c79103 100644 --- a/liquid-staking/Cargo.toml +++ b/liquid-staking/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" publish = false [lib] -path = "src/liquid_staking.rs" +path = "src/lib.rs" [dependencies.multiversx-sc] version = "0.52.3" diff --git a/liquid-staking/src/liquid_staking.rs b/liquid-staking/src/lib.rs similarity index 100% rename from liquid-staking/src/liquid_staking.rs rename to liquid-staking/src/lib.rs From 3ba2a803ca6e82b24827113d9bfce563df681be6 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Thu, 12 Sep 2024 14:06:47 +0300 Subject: [PATCH 03/98] Added liquid staking sc to project cargo file Signed-off-by: Andrei Baltariu --- Cargo.lock | 17 + Cargo.toml | 4 +- liquid-staking/Cargo.lock | 1196 ++++++++++++++++++++++++++++++++ liquid-staking/Cargo.toml | 6 - liquid-staking/wasm/Cargo.lock | 188 +++++ liquid-staking/wasm/Cargo.toml | 34 + liquid-staking/wasm/src/lib.rs | 26 + 7 files changed, 1464 insertions(+), 7 deletions(-) create mode 100644 liquid-staking/Cargo.lock create mode 100644 liquid-staking/wasm/Cargo.lock create mode 100644 liquid-staking/wasm/Cargo.toml create mode 100644 liquid-staking/wasm/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 8d11bf29..b239f415 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -536,6 +536,23 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +[[package]] +name = "liquid-staking" +version = "0.0.0" +dependencies = [ + "multiversx-sc", + "multiversx-sc-scenario", + "num-bigint", +] + +[[package]] +name = "liquid-staking-meta" +version = "0.0.0" +dependencies = [ + "liquid-staking", + "multiversx-sc-meta-lib", +] + [[package]] name = "log" version = "0.4.21" diff --git a/Cargo.toml b/Cargo.toml index 6d3767a1..7fba15ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,5 +11,7 @@ members = [ "header-verifier", "header-verifier/meta", "enshrine-esdt-safe", - "enshrine-esdt-safe/meta" + "enshrine-esdt-safe/meta", + "liquid-staking", + "liquid-staking/meta", ] diff --git a/liquid-staking/Cargo.lock b/liquid-staking/Cargo.lock new file mode 100644 index 00000000..3d754044 --- /dev/null +++ b/liquid-staking/Cargo.lock @@ -0,0 +1,1196 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "anstream" +version = "0.6.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" + +[[package]] +name = "anstyle-parse" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + +[[package]] +name = "anyhow" +version = "1.0.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e1496f8fb1fbf272686b8d37f523dab3e4a7443300055e74cdaa449f3114356" + +[[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 = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bech32" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clap" +version = "4.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" + +[[package]] +name = "colorchoice" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" + +[[package]] +name = "colored" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" +dependencies = [ + "lazy_static", + "windows-sys 0.48.0", +] + +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "cpufeatures" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "curve25519-dalek" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90f9d052967f590a76e62eb387bd0bbb1b000182c3cefe5364db6b7211651bc0" +dependencies = [ + "byteorder", + "digest 0.9.0", + "rand_core 0.5.1", + "subtle", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer 0.10.4", + "crypto-common", +] + +[[package]] +name = "ed25519" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" +dependencies = [ + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" +dependencies = [ + "curve25519-dalek", + "ed25519", + "rand 0.7.3", + "serde", + "sha2 0.9.9", + "zeroize", +] + +[[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 = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "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 = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "serde", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[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 = "indexmap" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +dependencies = [ + "equivalent", + "hashbrown", + "serde", +] + +[[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.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "keccak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" +dependencies = [ + "cpufeatures", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "liquid-staking" +version = "0.0.0" +dependencies = [ + "multiversx-sc", + "multiversx-sc-scenario", + "num-bigint", +] + +[[package]] +name = "liquid-staking-meta" +version = "0.0.0" +dependencies = [ + "liquid-staking", + "multiversx-sc-meta-lib", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "multiversx-chain-scenario-format" +version = "0.22.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "921a66f6db5ffff311e355d42a49fd49baf72d7a6a6215b0484dcd9d8dd512a3" +dependencies = [ + "bech32", + "hex", + "num-bigint", + "num-traits", + "serde", + "serde_json", + "sha3", +] + +[[package]] +name = "multiversx-chain-vm" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8d91b6ce610a3ac1272f0813284a3f03a34d55db2f86cddaff357bf651074ee" +dependencies = [ + "bitflags", + "colored", + "ed25519-dalek", + "hex", + "hex-literal", + "itertools", + "multiversx-chain-vm-executor", + "num-bigint", + "num-traits", + "rand 0.8.5", + "rand_seeder", + "sha2 0.10.8", + "sha3", +] + +[[package]] +name = "multiversx-chain-vm-executor" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b59072fa0624b55ae5ae3fa6bfa91515bbeb4ac440214bc4a509e2c8806d6e9f" + +[[package]] +name = "multiversx-sc" +version = "0.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", + "num-bigint", + "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-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", + "wasmprinter", +] + +[[package]] +name = "multiversx-sc-scenario" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d3024d52e2cb7d455f5a560218be8968e446eabc7c31dc9fc479c329f45e05e" +dependencies = [ + "base64", + "bech32", + "colored", + "hex", + "itertools", + "log", + "multiversx-chain-scenario-format", + "multiversx-chain-vm", + "multiversx-chain-vm-executor", + "multiversx-sc", + "multiversx-sc-meta-lib", + "num-bigint", + "num-traits", + "pathdiff", + "serde", + "serde_json", + "sha2 0.10.8", + "unwrap-infallible", +] + +[[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-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +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 = "pathdiff" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[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 = "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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "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]] +name = "rand_seeder" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf2890aaef0aa82719a50e808de264f9484b74b442e1a3a0e5ee38243ac40bdb" +dependencies = [ + "rand_core 0.6.4", +] + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_spanned" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +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", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.7", +] + +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest 0.10.7", + "keccak", +] + +[[package]] +name = "signature" +version = "1.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[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 = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "toml" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasmparser" +version = "0.214.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5309c1090e3e84dad0d382f42064e9933fdaedb87e468cc239f0eabea73ddcb6" +dependencies = [ + "ahash", + "bitflags", + "hashbrown", + "indexmap", + "semver", + "serde", +] + +[[package]] +name = "wasmprinter" +version = "0.214.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58d4f2b3f7bd2ba10f99e03f885ff90d5db3455e163bccecebbbf60406bd8980" +dependencies = [ + "anyhow", + "termcolor", + "wasmparser", +] + +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "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]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "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]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +dependencies = [ + "memchr", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "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.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" +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", +] diff --git a/liquid-staking/Cargo.toml b/liquid-staking/Cargo.toml index 96c79103..41f06b9e 100644 --- a/liquid-staking/Cargo.toml +++ b/liquid-staking/Cargo.toml @@ -16,9 +16,3 @@ num-bigint = "0.4" [dev-dependencies.multiversx-sc-scenario] version = "0.52.3" - -[workspace] -members = [ - ".", - "meta", -] diff --git a/liquid-staking/wasm/Cargo.lock b/liquid-staking/wasm/Cargo.lock new file mode 100644 index 00000000..52a73e3d --- /dev/null +++ b/liquid-staking/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 = "liquid-staking" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "liquid-staking-wasm" +version = "0.0.0" +dependencies = [ + "liquid-staking", + "multiversx-sc-wasm-adapter", +] + +[[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.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" diff --git a/liquid-staking/wasm/Cargo.toml b/liquid-staking/wasm/Cargo.toml new file mode 100644 index 00000000..54b4ba17 --- /dev/null +++ b/liquid-staking/wasm/Cargo.toml @@ -0,0 +1,34 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + +[package] +name = "liquid-staking-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.liquid-staking] +path = ".." + +[dependencies.multiversx-sc-wasm-adapter] +version = "0.52.3" + +[workspace] +members = ["."] diff --git a/liquid-staking/wasm/src/lib.rs b/liquid-staking/wasm/src/lib.rs new file mode 100644 index 00000000..ecbdb14c --- /dev/null +++ b/liquid-staking/wasm/src/lib.rs @@ -0,0 +1,26 @@ +// Code generated by the multiversx-sc build system. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +// Init: 1 +// Upgrade: 1 +// Endpoints: 0 +// Async Callback (empty): 1 +// Total number of exported functions: 3 + +#![no_std] + +multiversx_sc_wasm_adapter::allocator!(); +multiversx_sc_wasm_adapter::panic_handler!(); + +multiversx_sc_wasm_adapter::endpoints! { + liquid_staking + ( + init => init + upgrade => upgrade + ) +} + +multiversx_sc_wasm_adapter::async_callback_empty! {} From 2b813a9cc94bdd59218621da8f5939683f1f0e36 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Thu, 12 Sep 2024 14:07:11 +0300 Subject: [PATCH 04/98] Added liquidity pools module + delegation sc address mapper Signed-off-by: Andrei Baltariu --- liquid-staking/src/lib.rs | 15 +++++++++++---- liquid-staking/src/liquidity_pools.rs | 8 ++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 liquid-staking/src/liquidity_pools.rs diff --git a/liquid-staking/src/lib.rs b/liquid-staking/src/lib.rs index f1044a8e..4d240c53 100644 --- a/liquid-staking/src/lib.rs +++ b/liquid-staking/src/lib.rs @@ -1,13 +1,20 @@ #![no_std] -#[allow(unused_imports)] use multiversx_sc::imports::*; -/// An empty contract. To be used as a template when starting a new contract from scratch. +pub mod liquidity_pools; + #[multiversx_sc::contract] -pub trait LiquidStaking { +pub trait LiquidStaking: liquidity_pools::LiquidityPoolModule { #[init] - fn init(&self) {} + fn init(&self, delegation_address: ManagedAddress) { + require!( + self.blockchain().is_smart_contract(&delegation_address), + "Provided address is not a valid Smart Contract address" + ); + + self.delegation_address().set(delegation_address); + } #[upgrade] fn upgrade(&self) {} diff --git a/liquid-staking/src/liquidity_pools.rs b/liquid-staking/src/liquidity_pools.rs new file mode 100644 index 00000000..e48ca443 --- /dev/null +++ b/liquid-staking/src/liquidity_pools.rs @@ -0,0 +1,8 @@ +use multiversx_sc::imports::*; + +#[multiversx_sc::module] +pub trait LiquidityPoolModule { + #[view(delegationAddress)] + #[storage_mapper("delegationAddress")] + fn delegation_address(&self) -> SingleValueMapper; +} From bf015a32c7cf75df0a99118018aee4417299d438 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Thu, 12 Sep 2024 16:15:20 +0300 Subject: [PATCH 05/98] Added endpoints for stake and unstake Signed-off-by: Andrei Baltariu --- liquid-staking/src/common/mod.rs | 1 + liquid-staking/src/common/storage.rs | 21 +++++++ liquid-staking/src/delegation.rs | 90 +++++++++++++++++++++++++++ liquid-staking/src/lib.rs | 8 ++- liquid-staking/src/liquidity_pools.rs | 6 +- liquid-staking/wasm/src/lib.rs | 14 +++-- 6 files changed, 130 insertions(+), 10 deletions(-) create mode 100644 liquid-staking/src/common/mod.rs create mode 100644 liquid-staking/src/common/storage.rs create mode 100644 liquid-staking/src/delegation.rs diff --git a/liquid-staking/src/common/mod.rs b/liquid-staking/src/common/mod.rs new file mode 100644 index 00000000..30f61eb6 --- /dev/null +++ b/liquid-staking/src/common/mod.rs @@ -0,0 +1 @@ +pub mod storage; diff --git a/liquid-staking/src/common/storage.rs b/liquid-staking/src/common/storage.rs new file mode 100644 index 00000000..6044135f --- /dev/null +++ b/liquid-staking/src/common/storage.rs @@ -0,0 +1,21 @@ +use multiversx_sc::imports::*; +pub type Epoch = u64; + +#[multiversx_sc::module] +pub trait CommonStorageModule { + #[view(getDelegationAddress)] + #[storage_mapper("delegationAddress")] + fn delegation_address(&self) -> SingleValueMapper; + + #[view(getDelegatedValue)] + #[storage_mapper("delegatedValue")] + fn delegated_value(&self, validator: ManagedAddress) -> SingleValueMapper>; + + #[view(unDelegateEpoch)] + #[storage_mapper("unDelegateEpoch")] + fn undelegate_epoch(&self, address: &ManagedAddress) -> SingleValueMapper; + + #[view(getTotalEgldSupply)] + #[storage_mapper("totalEgldSupply")] + fn egld_token_supply(&self) -> SingleValueMapper; +} diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs new file mode 100644 index 00000000..e54f29ff --- /dev/null +++ b/liquid-staking/src/delegation.rs @@ -0,0 +1,90 @@ +use multiversx_sc::imports::*; +pub const UNBOND_PERIOD: u64 = 10; + +use crate::common::{self, storage::Epoch}; + +#[multiversx_sc::module] +pub trait DelegationModule: common::storage::CommonStorageModule { + #[payable("ELGD")] + #[endpoint(stake)] + fn stake(&self) { + let caller = self.blockchain().get_caller(); + let egld_amount = self.call_value().egld_value().clone_value(); + let delegation_contract_address = self.delegation_address().get(); + let delegation_endpoint = ManagedBuffer::from("delegate"); + + self.tx() + .to(delegation_contract_address) + .raw_call(delegation_endpoint) + .egld(&egld_amount) + .with_callback(DelegationModule::callbacks(self).stake_callback(&caller, &egld_amount)) + .call_and_exit(); + } + + #[endpoint(unStake)] + fn unstake(&self, egld_amount_to_unstake: BigUint) { + let caller = self.blockchain().get_caller(); + let current_epoch = self.blockchain().get_block_epoch(); + let total_egld_deposit = self.delegated_value(caller.clone()).get(); + let delegation_contract_address = self.delegation_address().get(); + let undelegate_endpoint = ManagedBuffer::from("unDelegate"); + + let mut args: ManagedArgBuffer = ManagedArgBuffer::new(); + args.push_arg(&egld_amount_to_unstake); + + require!( + egld_amount_to_unstake < total_egld_deposit, + "The value to unstake is greater than the deposited amount" + ); + + self.tx() + .to(delegation_contract_address) + .raw_call(undelegate_endpoint) + .argument(&args) + .with_callback(DelegationModule::callbacks(self).unstake_callback( + &caller, + &egld_amount_to_unstake, + current_epoch, + )) + .call_and_exit(); + } + + // TODO: Could use a Enum for each endpoint name + // fn call_delegation_contract_endpoint(&self, endpoint_name: ManagedBuffer) + + #[callback] + fn stake_callback( + &self, + caller: &ManagedAddress, + egld_amount: &BigUint, + #[call_result] result: ManagedAsyncCallResult<()>, + ) { + match result { + ManagedAsyncCallResult::Ok(()) => { + self.delegated_value(caller.clone()).set(egld_amount); + self.egld_token_supply() + .update(|value| *value += egld_amount) + } + _ => sc_panic!("There was an error at delegating"), + } + } + + #[callback] + fn unstake_callback( + &self, + caller: &ManagedAddress, + egld_amount_to_unstake: &BigUint, + current_epoch: Epoch, + #[call_result] result: ManagedAsyncCallResult<()>, + ) { + match result { + ManagedAsyncCallResult::Ok(()) => { + self.delegated_value(caller.clone()) + .update(|value| *value -= egld_amount_to_unstake); + self.undelegate_epoch(caller) + .set(current_epoch + UNBOND_PERIOD); + } + _ => sc_panic!("There was an error at delegating"), + } + } +} diff --git a/liquid-staking/src/lib.rs b/liquid-staking/src/lib.rs index 4d240c53..4284519d 100644 --- a/liquid-staking/src/lib.rs +++ b/liquid-staking/src/lib.rs @@ -2,10 +2,16 @@ use multiversx_sc::imports::*; +pub mod common; +pub mod delegation; pub mod liquidity_pools; #[multiversx_sc::contract] -pub trait LiquidStaking: liquidity_pools::LiquidityPoolModule { +pub trait LiquidStaking: + liquidity_pools::LiquidityPoolModule + + delegation::DelegationModule + + common::storage::CommonStorageModule +{ #[init] fn init(&self, delegation_address: ManagedAddress) { require!( diff --git a/liquid-staking/src/liquidity_pools.rs b/liquid-staking/src/liquidity_pools.rs index e48ca443..fc680362 100644 --- a/liquid-staking/src/liquidity_pools.rs +++ b/liquid-staking/src/liquidity_pools.rs @@ -1,8 +1,4 @@ use multiversx_sc::imports::*; #[multiversx_sc::module] -pub trait LiquidityPoolModule { - #[view(delegationAddress)] - #[storage_mapper("delegationAddress")] - fn delegation_address(&self) -> SingleValueMapper; -} +pub trait LiquidityPoolModule {} diff --git a/liquid-staking/wasm/src/lib.rs b/liquid-staking/wasm/src/lib.rs index ecbdb14c..1f04c90a 100644 --- a/liquid-staking/wasm/src/lib.rs +++ b/liquid-staking/wasm/src/lib.rs @@ -6,9 +6,9 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 0 -// Async Callback (empty): 1 -// Total number of exported functions: 3 +// Endpoints: 6 +// Async Callback: 1 +// Total number of exported functions: 9 #![no_std] @@ -20,7 +20,13 @@ multiversx_sc_wasm_adapter::endpoints! { ( init => init upgrade => upgrade + stake => stake + unStake => unstake + getDelegationAddress => delegation_address + getDelegatedValue => delegated_value + unDelegateEpoch => undelegate_epoch + getTotalEgldSupply => egld_token_supply ) } -multiversx_sc_wasm_adapter::async_callback_empty! {} +multiversx_sc_wasm_adapter::async_callback! { liquid_staking } From fbd03719e58432d97522e47e73168a39c0d59554 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Thu, 12 Sep 2024 16:19:48 +0300 Subject: [PATCH 06/98] Upgrade liquid staking to 0.53.0 Signed-off-by: Andrei Baltariu --- liquid-staking/Cargo.toml | 4 ++-- liquid-staking/meta/Cargo.toml | 2 +- liquid-staking/wasm/Cargo.lock | 32 ++++++++++++++++---------------- liquid-staking/wasm/Cargo.toml | 2 +- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/liquid-staking/Cargo.toml b/liquid-staking/Cargo.toml index 41f06b9e..e725d03c 100644 --- a/liquid-staking/Cargo.toml +++ b/liquid-staking/Cargo.toml @@ -9,10 +9,10 @@ publish = false path = "src/lib.rs" [dependencies.multiversx-sc] -version = "0.52.3" +version = "0.53.0" [dev-dependencies] num-bigint = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "0.52.3" +version = "0.53.0" diff --git a/liquid-staking/meta/Cargo.toml b/liquid-staking/meta/Cargo.toml index a93b6401..7df8c061 100644 --- a/liquid-staking/meta/Cargo.toml +++ b/liquid-staking/meta/Cargo.toml @@ -8,5 +8,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta-lib] -version = "0.52.3" +version = "0.53.0" default-features = false diff --git a/liquid-staking/wasm/Cargo.lock b/liquid-staking/wasm/Cargo.lock index 52a73e3d..f0ed889e 100644 --- a/liquid-staking/wasm/Cargo.lock +++ b/liquid-staking/wasm/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" @@ -55,9 +55,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.52.3" +version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "526760b1d6236c011285b264a70a0a9dd3b3dbc53c3b5f76932f4bcfd3a8910c" +checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" dependencies = [ "bitflags", "hex-literal", @@ -69,9 +69,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.20.1" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad4f318427761faecf26c1f3115a3beeb5f61858845a60547d9763aa981ddd2d" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -80,9 +80,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.20.1" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "476501462b0c2654b64f9dec6f2c480e24b4e9b7133ec10b7167e64acda35d04" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" dependencies = [ "hex", "proc-macro2", @@ -92,9 +92,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.52.3" +version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3557f2f12640a8a07fa6af66cc2a13b188c5b61bed72db22fe631fb3a60c3e96" +checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" dependencies = [ "hex", "proc-macro2", @@ -105,9 +105,9 @@ dependencies = [ [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.52.3" +version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed13aaca9cbdbc6911174cd3029e750a7563d85dd3daaa1107b1fd31c7f17245" +checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" dependencies = [ "multiversx-sc", ] @@ -141,9 +141,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -166,9 +166,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "syn" -version = "2.0.72" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", diff --git a/liquid-staking/wasm/Cargo.toml b/liquid-staking/wasm/Cargo.toml index 54b4ba17..c23d0d28 100644 --- a/liquid-staking/wasm/Cargo.toml +++ b/liquid-staking/wasm/Cargo.toml @@ -28,7 +28,7 @@ panic = "abort" path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "0.52.3" +version = "0.53.0" [workspace] members = ["."] From da50c96a03de40769060aff8b722ee8ed2bc4d8c Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 13 Sep 2024 11:48:24 +0300 Subject: [PATCH 07/98] Removed imports Signed-off-by: Andrei Baltariu --- liquid-staking/src/liquidity_pools.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/liquid-staking/src/liquidity_pools.rs b/liquid-staking/src/liquidity_pools.rs index fc680362..210ff6d2 100644 --- a/liquid-staking/src/liquidity_pools.rs +++ b/liquid-staking/src/liquidity_pools.rs @@ -1,4 +1,2 @@ -use multiversx_sc::imports::*; - #[multiversx_sc::module] pub trait LiquidityPoolModule {} From 07e2fc1ffc4f04f5200aff30df127a07f3e9207a Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 13 Sep 2024 11:48:39 +0300 Subject: [PATCH 08/98] Modified delegation storage and added endpoint to register Signed-off-by: Andrei Baltariu --- liquid-staking/src/common/storage.rs | 2 +- liquid-staking/src/lib.rs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/liquid-staking/src/common/storage.rs b/liquid-staking/src/common/storage.rs index 6044135f..46d651de 100644 --- a/liquid-staking/src/common/storage.rs +++ b/liquid-staking/src/common/storage.rs @@ -5,7 +5,7 @@ pub type Epoch = u64; pub trait CommonStorageModule { #[view(getDelegationAddress)] #[storage_mapper("delegationAddress")] - fn delegation_address(&self) -> SingleValueMapper; + fn delegation_addresses(&self) -> UnorderedSetMapper; #[view(getDelegatedValue)] #[storage_mapper("delegatedValue")] diff --git a/liquid-staking/src/lib.rs b/liquid-staking/src/lib.rs index 4284519d..c51ad231 100644 --- a/liquid-staking/src/lib.rs +++ b/liquid-staking/src/lib.rs @@ -13,13 +13,21 @@ pub trait LiquidStaking: + common::storage::CommonStorageModule { #[init] - fn init(&self, delegation_address: ManagedAddress) { + fn init(&self) {} + + #[endpoint(registerDelegationContractAddress)] + fn register_delegation_address(&self, delegation_address: ManagedAddress) { require!( self.blockchain().is_smart_contract(&delegation_address), "Provided address is not a valid Smart Contract address" ); - self.delegation_address().set(delegation_address); + require!( + self.delegation_addresses().contains(&delegation_address), + "This address is already in the contract's storage" + ); + + self.delegation_addresses().insert(delegation_address); } #[upgrade] From ddd8558bea17d70d3a2d2256d65f3c64ef1be870 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 13 Sep 2024 11:52:20 +0300 Subject: [PATCH 09/98] Modified storage to use a map instead of a set Signed-off-by: Andrei Baltariu --- liquid-staking/src/common/storage.rs | 5 ++++- liquid-staking/src/delegation.rs | 8 ++++---- liquid-staking/src/lib.rs | 13 +++++++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/liquid-staking/src/common/storage.rs b/liquid-staking/src/common/storage.rs index 46d651de..69b180fd 100644 --- a/liquid-staking/src/common/storage.rs +++ b/liquid-staking/src/common/storage.rs @@ -5,7 +5,10 @@ pub type Epoch = u64; pub trait CommonStorageModule { #[view(getDelegationAddress)] #[storage_mapper("delegationAddress")] - fn delegation_addresses(&self) -> UnorderedSetMapper; + fn delegation_addresses( + &self, + contract_name: &ManagedBuffer, + ) -> SingleValueMapper; #[view(getDelegatedValue)] #[storage_mapper("delegatedValue")] diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index e54f29ff..4ff1004c 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -7,10 +7,10 @@ use crate::common::{self, storage::Epoch}; pub trait DelegationModule: common::storage::CommonStorageModule { #[payable("ELGD")] #[endpoint(stake)] - fn stake(&self) { + fn stake(&self, contract_name: ManagedBuffer) { let caller = self.blockchain().get_caller(); let egld_amount = self.call_value().egld_value().clone_value(); - let delegation_contract_address = self.delegation_address().get(); + let delegation_contract_address = self.delegation_addresses(&contract_name).get(); let delegation_endpoint = ManagedBuffer::from("delegate"); self.tx() @@ -22,11 +22,11 @@ pub trait DelegationModule: common::storage::CommonStorageModule { } #[endpoint(unStake)] - fn unstake(&self, egld_amount_to_unstake: BigUint) { + fn unstake(&self, contract_name: ManagedBuffer, egld_amount_to_unstake: BigUint) { let caller = self.blockchain().get_caller(); let current_epoch = self.blockchain().get_block_epoch(); let total_egld_deposit = self.delegated_value(caller.clone()).get(); - let delegation_contract_address = self.delegation_address().get(); + let delegation_contract_address = self.delegation_addresses(&contract_name).get(); let undelegate_endpoint = ManagedBuffer::from("unDelegate"); let mut args: ManagedArgBuffer = ManagedArgBuffer::new(); diff --git a/liquid-staking/src/lib.rs b/liquid-staking/src/lib.rs index c51ad231..cc99b4fb 100644 --- a/liquid-staking/src/lib.rs +++ b/liquid-staking/src/lib.rs @@ -16,18 +16,23 @@ pub trait LiquidStaking: fn init(&self) {} #[endpoint(registerDelegationContractAddress)] - fn register_delegation_address(&self, delegation_address: ManagedAddress) { + fn register_delegation_address( + &self, + contract_name: ManagedBuffer, + delegation_address: ManagedAddress, + ) { require!( self.blockchain().is_smart_contract(&delegation_address), "Provided address is not a valid Smart Contract address" ); require!( - self.delegation_addresses().contains(&delegation_address), - "This address is already in the contract's storage" + self.delegation_addresses(&contract_name).is_empty(), + "This contract is already registered" ); - self.delegation_addresses().insert(delegation_address); + self.delegation_addresses(&contract_name) + .set(delegation_address); } #[upgrade] From 4c87cafa02cfe828720036861f2b55bfb3a6ad96 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 13 Sep 2024 11:52:49 +0300 Subject: [PATCH 10/98] Regenerated proxy Signed-off-by: Andrei Baltariu --- liquid-staking/wasm/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/liquid-staking/wasm/src/lib.rs b/liquid-staking/wasm/src/lib.rs index 1f04c90a..df548bda 100644 --- a/liquid-staking/wasm/src/lib.rs +++ b/liquid-staking/wasm/src/lib.rs @@ -6,9 +6,9 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 6 +// Endpoints: 7 // Async Callback: 1 -// Total number of exported functions: 9 +// Total number of exported functions: 10 #![no_std] @@ -20,9 +20,10 @@ multiversx_sc_wasm_adapter::endpoints! { ( init => init upgrade => upgrade + registerDelegationContractAddress => register_delegation_address stake => stake unStake => unstake - getDelegationAddress => delegation_address + getDelegationAddress => delegation_addresses getDelegatedValue => delegated_value unDelegateEpoch => undelegate_epoch getTotalEgldSupply => egld_token_supply From 7273d9793ccb379924fb460be368523811edfb19 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 13 Sep 2024 11:54:24 +0300 Subject: [PATCH 11/98] Moved callbacks to be right under their endpoint Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 40 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 4ff1004c..2b11e7e8 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -21,6 +21,23 @@ pub trait DelegationModule: common::storage::CommonStorageModule { .call_and_exit(); } + #[callback] + fn stake_callback( + &self, + caller: &ManagedAddress, + egld_amount: &BigUint, + #[call_result] result: ManagedAsyncCallResult<()>, + ) { + match result { + ManagedAsyncCallResult::Ok(()) => { + self.delegated_value(caller.clone()).set(egld_amount); + self.egld_token_supply() + .update(|value| *value += egld_amount) + } + _ => sc_panic!("There was an error at delegating"), + } + } + #[endpoint(unStake)] fn unstake(&self, contract_name: ManagedBuffer, egld_amount_to_unstake: BigUint) { let caller = self.blockchain().get_caller(); @@ -49,26 +66,6 @@ pub trait DelegationModule: common::storage::CommonStorageModule { .call_and_exit(); } - // TODO: Could use a Enum for each endpoint name - // fn call_delegation_contract_endpoint(&self, endpoint_name: ManagedBuffer) - - #[callback] - fn stake_callback( - &self, - caller: &ManagedAddress, - egld_amount: &BigUint, - #[call_result] result: ManagedAsyncCallResult<()>, - ) { - match result { - ManagedAsyncCallResult::Ok(()) => { - self.delegated_value(caller.clone()).set(egld_amount); - self.egld_token_supply() - .update(|value| *value += egld_amount) - } - _ => sc_panic!("There was an error at delegating"), - } - } - #[callback] fn unstake_callback( &self, @@ -87,4 +84,7 @@ pub trait DelegationModule: common::storage::CommonStorageModule { _ => sc_panic!("There was an error at delegating"), } } + + // TODO: Could use a Enum for each endpoint name + // fn call_delegation_contract_endpoint(&self, endpoint_name: ManagedBuffer) } From 266eecd355f28cf6f4effe4741037124f26b5a62 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 13 Sep 2024 11:57:11 +0300 Subject: [PATCH 12/98] Added consts for endpoint names Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 2b11e7e8..1926072c 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -1,5 +1,7 @@ use multiversx_sc::imports::*; pub const UNBOND_PERIOD: u64 = 10; +pub const DELEGATE_ENDPOINT: &str = "delegate"; +pub const UNDELEGATE_ENDPOINT: &str = "unDelegate"; use crate::common::{self, storage::Epoch}; @@ -11,11 +13,10 @@ pub trait DelegationModule: common::storage::CommonStorageModule { let caller = self.blockchain().get_caller(); let egld_amount = self.call_value().egld_value().clone_value(); let delegation_contract_address = self.delegation_addresses(&contract_name).get(); - let delegation_endpoint = ManagedBuffer::from("delegate"); self.tx() .to(delegation_contract_address) - .raw_call(delegation_endpoint) + .raw_call(ManagedBuffer::from(DELEGATE_ENDPOINT)) .egld(&egld_amount) .with_callback(DelegationModule::callbacks(self).stake_callback(&caller, &egld_amount)) .call_and_exit(); @@ -44,7 +45,6 @@ pub trait DelegationModule: common::storage::CommonStorageModule { let current_epoch = self.blockchain().get_block_epoch(); let total_egld_deposit = self.delegated_value(caller.clone()).get(); let delegation_contract_address = self.delegation_addresses(&contract_name).get(); - let undelegate_endpoint = ManagedBuffer::from("unDelegate"); let mut args: ManagedArgBuffer = ManagedArgBuffer::new(); args.push_arg(&egld_amount_to_unstake); @@ -56,7 +56,7 @@ pub trait DelegationModule: common::storage::CommonStorageModule { self.tx() .to(delegation_contract_address) - .raw_call(undelegate_endpoint) + .raw_call(ManagedBuffer::from(UNDELEGATE_ENDPOINT)) .argument(&args) .with_callback(DelegationModule::callbacks(self).unstake_callback( &caller, From 22a0b9a02ab5d8c9fb7ac48d5af970420e1ffec4 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 13 Sep 2024 12:07:11 +0300 Subject: [PATCH 13/98] Added check for delegation value to be > 0 Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 1926072c..76e05f45 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -1,4 +1,4 @@ -use multiversx_sc::imports::*; +use multiversx_sc::{api::const_handles::BIG_INT_CONST_ZERO, imports::*}; pub const UNBOND_PERIOD: u64 = 10; pub const DELEGATE_ENDPOINT: &str = "delegate"; pub const UNDELEGATE_ENDPOINT: &str = "unDelegate"; @@ -42,8 +42,13 @@ pub trait DelegationModule: common::storage::CommonStorageModule { #[endpoint(unStake)] fn unstake(&self, contract_name: ManagedBuffer, egld_amount_to_unstake: BigUint) { let caller = self.blockchain().get_caller(); - let current_epoch = self.blockchain().get_block_epoch(); let total_egld_deposit = self.delegated_value(caller.clone()).get(); + require!( + total_egld_deposit > BIG_INT_CONST_ZERO, + "The user has not deposited any EGLD" + ); + + let current_epoch = self.blockchain().get_block_epoch(); let delegation_contract_address = self.delegation_addresses(&contract_name).get(); let mut args: ManagedArgBuffer = ManagedArgBuffer::new(); From 1aa6adf81148a6121390dd1e6f9f724763e59706 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Sun, 15 Sep 2024 15:26:32 +0300 Subject: [PATCH 14/98] Added sc-config for proxy generation Signed-off-by: Andrei Baltariu --- liquid-staking/sc-config.toml | 19 ++ liquid-staking/src/liquid_staking_proxy.rs | 175 ++++++++++++++++ .../wasm-liquid-staking-full/Cargo.lock | 188 ++++++++++++++++++ .../wasm-liquid-staking-full/Cargo.toml | 34 ++++ .../wasm-liquid-staking-full/src/lib.rs | 33 +++ .../wasm-liquid-staking-view/Cargo.lock | 188 ++++++++++++++++++ .../wasm-liquid-staking-view/Cargo.toml | 34 ++++ .../wasm-liquid-staking-view/src/lib.rs | 25 +++ 8 files changed, 696 insertions(+) create mode 100644 liquid-staking/sc-config.toml create mode 100644 liquid-staking/src/liquid_staking_proxy.rs create mode 100644 liquid-staking/wasm-liquid-staking-full/Cargo.lock create mode 100644 liquid-staking/wasm-liquid-staking-full/Cargo.toml create mode 100644 liquid-staking/wasm-liquid-staking-full/src/lib.rs create mode 100644 liquid-staking/wasm-liquid-staking-view/Cargo.lock create mode 100644 liquid-staking/wasm-liquid-staking-view/Cargo.toml create mode 100644 liquid-staking/wasm-liquid-staking-view/src/lib.rs diff --git a/liquid-staking/sc-config.toml b/liquid-staking/sc-config.toml new file mode 100644 index 00000000..08c9a572 --- /dev/null +++ b/liquid-staking/sc-config.toml @@ -0,0 +1,19 @@ +[settings] +main = "main" + +[contracts.main] +name = "liquid-staking" + +[contracts.full] +name = "liquid-staking-full" +add-unlabelled = true +add-labels = ["liquid-staking-external-view"] + +[contracts.view] +name = "liquid-staking-view" +external-view = true +add-unlabelled = false +add-labels = ["liquid-staking-external-view"] + +[[proxy]] +path = "src/liquid_staking_proxy.rs" diff --git a/liquid-staking/src/liquid_staking_proxy.rs b/liquid-staking/src/liquid_staking_proxy.rs new file mode 100644 index 00000000..d26ea750 --- /dev/null +++ b/liquid-staking/src/liquid_staking_proxy.rs @@ -0,0 +1,175 @@ +// Code generated by the multiversx-sc proxy generator. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +#![allow(dead_code)] +#![allow(clippy::all)] + +use multiversx_sc::proxy_imports::*; + +pub struct LiquidStakingProxy; + +impl TxProxyTrait for LiquidStakingProxy +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + type TxProxyMethods = LiquidStakingProxyMethods; + + fn proxy_methods(self, tx: Tx) -> Self::TxProxyMethods { + LiquidStakingProxyMethods { wrapped_tx: tx } + } +} + +pub struct LiquidStakingProxyMethods +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + wrapped_tx: Tx, +} + +#[rustfmt::skip] +impl LiquidStakingProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + Gas: TxGas, +{ + pub fn init( + self, + ) -> TxTypedDeploy { + self.wrapped_tx + .payment(NotPayable) + .raw_deploy() + .original_result() + } +} + +#[rustfmt::skip] +impl LiquidStakingProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + pub fn upgrade( + self, + ) -> TxTypedUpgrade { + self.wrapped_tx + .payment(NotPayable) + .raw_upgrade() + .original_result() + } +} + +#[rustfmt::skip] +impl LiquidStakingProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + pub fn register_delegation_address< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + >( + self, + contract_name: Arg0, + delegation_address: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("registerDelegationContractAddress") + .argument(&contract_name) + .argument(&delegation_address) + .original_result() + } + + pub fn stake< + Arg0: ProxyArg>, + >( + self, + contract_name: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("stake") + .argument(&contract_name) + .original_result() + } + + pub fn unstake< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + >( + self, + contract_name: Arg0, + egld_amount_to_unstake: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("unStake") + .argument(&contract_name) + .argument(&egld_amount_to_unstake) + .original_result() + } + + pub fn delegation_addresses< + Arg0: ProxyArg>, + >( + self, + contract_name: Arg0, + ) -> TxTypedCall> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("getDelegationAddress") + .argument(&contract_name) + .original_result() + } + + pub fn delegated_value< + Arg0: ProxyArg>, + >( + self, + validator: Arg0, + ) -> TxTypedCall> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("getDelegatedValue") + .argument(&validator) + .original_result() + } + + pub fn undelegate_epoch< + Arg0: ProxyArg>, + >( + self, + address: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("unDelegateEpoch") + .argument(&address) + .original_result() + } + + pub fn egld_token_supply( + self, + ) -> TxTypedCall> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("getTotalEgldSupply") + .original_result() + } +} diff --git a/liquid-staking/wasm-liquid-staking-full/Cargo.lock b/liquid-staking/wasm-liquid-staking-full/Cargo.lock new file mode 100644 index 00000000..41c966f3 --- /dev/null +++ b/liquid-staking/wasm-liquid-staking-full/Cargo.lock @@ -0,0 +1,188 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hex-literal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "liquid-staking" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "liquid-staking-full-wasm" +version = "0.0.0" +dependencies = [ + "liquid-staking", + "multiversx-sc-wasm-adapter", +] + +[[package]] +name = "multiversx-sc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "nibble_vec" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" +dependencies = [ + "smallvec", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radix_trie" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" +dependencies = [ + "endian-type", + "nibble_vec", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" diff --git a/liquid-staking/wasm-liquid-staking-full/Cargo.toml b/liquid-staking/wasm-liquid-staking-full/Cargo.toml new file mode 100644 index 00000000..4055ac4e --- /dev/null +++ b/liquid-staking/wasm-liquid-staking-full/Cargo.toml @@ -0,0 +1,34 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + +[package] +name = "liquid-staking-full-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.liquid-staking] +path = ".." + +[dependencies.multiversx-sc-wasm-adapter] +version = "0.53.0" + +[workspace] +members = ["."] diff --git a/liquid-staking/wasm-liquid-staking-full/src/lib.rs b/liquid-staking/wasm-liquid-staking-full/src/lib.rs new file mode 100644 index 00000000..df548bda --- /dev/null +++ b/liquid-staking/wasm-liquid-staking-full/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: 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! { + liquid_staking + ( + init => init + upgrade => upgrade + registerDelegationContractAddress => register_delegation_address + stake => stake + unStake => unstake + getDelegationAddress => delegation_addresses + getDelegatedValue => delegated_value + unDelegateEpoch => undelegate_epoch + getTotalEgldSupply => egld_token_supply + ) +} + +multiversx_sc_wasm_adapter::async_callback! { liquid_staking } diff --git a/liquid-staking/wasm-liquid-staking-view/Cargo.lock b/liquid-staking/wasm-liquid-staking-view/Cargo.lock new file mode 100644 index 00000000..315fa03e --- /dev/null +++ b/liquid-staking/wasm-liquid-staking-view/Cargo.lock @@ -0,0 +1,188 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hex-literal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "liquid-staking" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "liquid-staking-view-wasm" +version = "0.0.0" +dependencies = [ + "liquid-staking", + "multiversx-sc-wasm-adapter", +] + +[[package]] +name = "multiversx-sc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "nibble_vec" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" +dependencies = [ + "smallvec", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radix_trie" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" +dependencies = [ + "endian-type", + "nibble_vec", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" diff --git a/liquid-staking/wasm-liquid-staking-view/Cargo.toml b/liquid-staking/wasm-liquid-staking-view/Cargo.toml new file mode 100644 index 00000000..5825cb43 --- /dev/null +++ b/liquid-staking/wasm-liquid-staking-view/Cargo.toml @@ -0,0 +1,34 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + +[package] +name = "liquid-staking-view-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.liquid-staking] +path = ".." + +[dependencies.multiversx-sc-wasm-adapter] +version = "0.53.0" + +[workspace] +members = ["."] diff --git a/liquid-staking/wasm-liquid-staking-view/src/lib.rs b/liquid-staking/wasm-liquid-staking-view/src/lib.rs new file mode 100644 index 00000000..d3395237 --- /dev/null +++ b/liquid-staking/wasm-liquid-staking-view/src/lib.rs @@ -0,0 +1,25 @@ +// Code generated by the multiversx-sc build system. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +// Init: 1 +// Endpoints: 0 +// Async Callback (empty): 1 +// Total number of exported functions: 2 + +#![no_std] + +multiversx_sc_wasm_adapter::allocator!(); +multiversx_sc_wasm_adapter::panic_handler!(); + +multiversx_sc_wasm_adapter::external_view_init! {} + +multiversx_sc_wasm_adapter::external_view_endpoints! { + liquid_staking + ( + ) +} + +multiversx_sc_wasm_adapter::async_callback_empty! {} From 76a83c39093713a4513b8a206113a485e50a9898 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Sun, 15 Sep 2024 15:26:55 +0300 Subject: [PATCH 15/98] Added import for proxy Signed-off-by: Andrei Baltariu --- liquid-staking/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/liquid-staking/src/lib.rs b/liquid-staking/src/lib.rs index cc99b4fb..fef1bfd0 100644 --- a/liquid-staking/src/lib.rs +++ b/liquid-staking/src/lib.rs @@ -4,6 +4,7 @@ use multiversx_sc::imports::*; pub mod common; pub mod delegation; +pub mod liquid_staking_proxy; pub mod liquidity_pools; #[multiversx_sc::contract] From 9c171b7d05d4b5b59f24b27ed2ec3db9741fae59 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Sun, 15 Sep 2024 16:12:40 +0300 Subject: [PATCH 16/98] Added test setup + 2 tests Signed-off-by: Andrei Baltariu --- .../tests/liquid_staking_blackbox_tests.rs | 139 ++++++++++++++++++ .../tests/liquid_staking_scenario_go_test.rs | 10 -- .../tests/liquid_staking_scenario_rs_test.rs | 13 -- 3 files changed, 139 insertions(+), 23 deletions(-) create mode 100644 liquid-staking/tests/liquid_staking_blackbox_tests.rs delete mode 100644 liquid-staking/tests/liquid_staking_scenario_go_test.rs delete mode 100644 liquid-staking/tests/liquid_staking_scenario_rs_test.rs diff --git a/liquid-staking/tests/liquid_staking_blackbox_tests.rs b/liquid-staking/tests/liquid_staking_blackbox_tests.rs new file mode 100644 index 00000000..116657e1 --- /dev/null +++ b/liquid-staking/tests/liquid_staking_blackbox_tests.rs @@ -0,0 +1,139 @@ +use liquid_staking::{common::storage::CommonStorageModule, liquid_staking_proxy}; +use multiversx_sc::types::{BigUint, ManagedBuffer, TestAddress, TestSCAddress}; +use multiversx_sc_scenario::{ + api::StaticApi, imports::MxscPath, DebugApi, ExpectError, ScenarioTxRun, ScenarioTxWhitebox, + ScenarioWorld, +}; + +const LIQUID_STAKING_CODE_PATH: MxscPath = MxscPath::new("output/liquid-stacking.mxsc-json"); +const LIQUID_STAKING_ADDRESS: TestSCAddress = TestSCAddress::new("liquid-staking"); +const LIQUID_STACKING_OWNER: TestAddress = TestAddress::new("owner"); + +const DELEGATION_ADDRESS: TestSCAddress = TestSCAddress::new("delegation"); + +const VALIDATOR_ADDRESS: TestAddress = TestAddress::new("validator"); + +const WEGLD_BALANCE: u128 = 100_000_000_000_000_000; + +fn world() -> ScenarioWorld { + let mut blockchain = ScenarioWorld::new(); + + blockchain.register_contract(LIQUID_STAKING_CODE_PATH, liquid_staking::ContractBuilder); + + blockchain +} + +struct LiquidStakingTestState { + world: ScenarioWorld, +} + +pub struct ErrorStatus<'a> { + code: u64, + error_message: &'a str, +} + +impl LiquidStakingTestState { + fn new() -> Self { + let mut world = world(); + + world + .account(LIQUID_STACKING_OWNER) + .balance(BigUint::from(WEGLD_BALANCE)) + .nonce(1); + + world + .account(VALIDATOR_ADDRESS) + .balance(BigUint::from(WEGLD_BALANCE)) + .nonce(1); + + Self { world } + } + + fn deploy_liquid_staking(&mut self) -> &mut Self { + self.world + .tx() + .from(LIQUID_STACKING_OWNER) + .typed(liquid_staking_proxy::LiquidStakingProxy) + .init() + .code(LIQUID_STAKING_CODE_PATH) + .new_address(LIQUID_STAKING_ADDRESS) + .run(); + + self + } + + fn propose_register_delegation_address( + &mut self, + contract_name: &ManagedBuffer, + delegation_address: TestSCAddress, + error_status: Option, + ) -> &mut Self { + match error_status { + Some(error) => self + .world + .tx() + .from(LIQUID_STACKING_OWNER) + .to(LIQUID_STAKING_ADDRESS) + .typed(liquid_staking_proxy::LiquidStakingProxy) + .register_delegation_address(contract_name, delegation_address) + .returns(ExpectError(error.code, error.error_message)) + .run(), + None => self + .world + .tx() + .from(LIQUID_STACKING_OWNER) + .to(LIQUID_STAKING_ADDRESS) + .typed(liquid_staking_proxy::LiquidStakingProxy) + .register_delegation_address(contract_name, delegation_address) + .run(), + } + self + } + + // fn propose_stake(&mut self) -> &mut Self { + // let contract_name = + // } +} + +#[test] +fn test_deploy() { + let mut state = LiquidStakingTestState::new(); + + state.deploy_liquid_staking(); +} + +#[test] +fn test_register_delegation_contract() { + let mut state = LiquidStakingTestState::new(); + let contract_name = ManagedBuffer::from("delegation"); + + state.deploy_liquid_staking(); + state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); + + state + .world + .query() + .to(LIQUID_STAKING_ADDRESS) + .whitebox(liquid_staking::contract_obj, |sc| { + let contract_name_debug_api: ManagedBuffer = + ManagedBuffer::from("delegation"); + let registered_address = sc.delegation_addresses(&contract_name_debug_api).get(); + assert_eq!(DELEGATION_ADDRESS, registered_address); + }); +} +#[test] +fn test_register_delegation_contract_contract_already_registered() { + let mut state = LiquidStakingTestState::new(); + let error_status = ErrorStatus { + code: 4, + error_message: "This contract is already registered", + }; + + state.deploy_liquid_staking(); + state.propose_register_delegation_address(&ManagedBuffer::new(), DELEGATION_ADDRESS, None); + state.propose_register_delegation_address( + &ManagedBuffer::new(), + DELEGATION_ADDRESS, + Some(error_status), + ); +} diff --git a/liquid-staking/tests/liquid_staking_scenario_go_test.rs b/liquid-staking/tests/liquid_staking_scenario_go_test.rs deleted file mode 100644 index fd22b435..00000000 --- a/liquid-staking/tests/liquid_staking_scenario_go_test.rs +++ /dev/null @@ -1,10 +0,0 @@ -use multiversx_sc_scenario::*; - -fn world() -> ScenarioWorld { - ScenarioWorld::vm_go() -} - -#[test] -fn empty_go() { - world().run("scenarios/liquid_staking.scen.json"); -} diff --git a/liquid-staking/tests/liquid_staking_scenario_rs_test.rs b/liquid-staking/tests/liquid_staking_scenario_rs_test.rs deleted file mode 100644 index 4c0a8be3..00000000 --- a/liquid-staking/tests/liquid_staking_scenario_rs_test.rs +++ /dev/null @@ -1,13 +0,0 @@ -use multiversx_sc_scenario::*; - -fn world() -> ScenarioWorld { - let mut blockchain = ScenarioWorld::new(); - - blockchain.register_contract("mxsc:output/liquid-staking.mxsc.json", liquid_staking::ContractBuilder); - blockchain -} - -#[test] -fn empty_rs() { - world().run("scenarios/liquid_staking.scen.json"); -} From 3c4f410975bfe87c4eda4866e5b83ed0ee85ef7e Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Tue, 17 Sep 2024 13:03:22 +0300 Subject: [PATCH 17/98] Fixed typo Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 76e05f45..648fe42c 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -7,7 +7,7 @@ use crate::common::{self, storage::Epoch}; #[multiversx_sc::module] pub trait DelegationModule: common::storage::CommonStorageModule { - #[payable("ELGD")] + #[payable("EGLD")] #[endpoint(stake)] fn stake(&self, contract_name: ManagedBuffer) { let caller = self.blockchain().get_caller(); From 8c3e29f59f55f54f9244dc8806d3e29d52ee1e53 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Tue, 17 Sep 2024 13:13:24 +0300 Subject: [PATCH 18/98] Added stake test Signed-off-by: Andrei Baltariu --- .../tests/liquid_staking_blackbox_tests.rs | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/liquid-staking/tests/liquid_staking_blackbox_tests.rs b/liquid-staking/tests/liquid_staking_blackbox_tests.rs index 116657e1..2566e825 100644 --- a/liquid-staking/tests/liquid_staking_blackbox_tests.rs +++ b/liquid-staking/tests/liquid_staking_blackbox_tests.rs @@ -90,9 +90,22 @@ impl LiquidStakingTestState { self } - // fn propose_stake(&mut self) -> &mut Self { - // let contract_name = - // } + fn propose_stake( + &mut self, + contract_name: &ManagedBuffer, + payment: &BigUint, + ) -> &mut Self { + self.world + .tx() + .from(LIQUID_STACKING_OWNER) + .to(LIQUID_STAKING_ADDRESS) + .typed(liquid_staking_proxy::LiquidStakingProxy) + .stake(contract_name) + .egld(payment) + .run(); + + self + } } #[test] @@ -121,6 +134,7 @@ fn test_register_delegation_contract() { assert_eq!(DELEGATION_ADDRESS, registered_address); }); } + #[test] fn test_register_delegation_contract_contract_already_registered() { let mut state = LiquidStakingTestState::new(); @@ -137,3 +151,19 @@ fn test_register_delegation_contract_contract_already_registered() { Some(error_status), ); } + +#[test] +fn test_stake() { + let mut state = LiquidStakingTestState::new(); + let contract_name = ManagedBuffer::from("delegation"); + let payment = BigUint::from(100_000u64); + + state.deploy_liquid_staking(); + state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); + state.propose_stake(&contract_name, &payment); + + state + .world + .check_account(LIQUID_STAKING_ADDRESS) + .balance(BigUint::from(WEGLD_BALANCE) - payment); +} From 70bbba4d35b8b2026982e1672d91c4564d9a152b Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 18 Sep 2024 10:25:00 +0300 Subject: [PATCH 19/98] Renamed test file Signed-off-by: Andrei Baltariu --- .../{liquid_staking_blackbox_tests.rs => liquid_staking_tests.rs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename liquid-staking/tests/{liquid_staking_blackbox_tests.rs => liquid_staking_tests.rs} (100%) diff --git a/liquid-staking/tests/liquid_staking_blackbox_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs similarity index 100% rename from liquid-staking/tests/liquid_staking_blackbox_tests.rs rename to liquid-staking/tests/liquid_staking_tests.rs From dae3485a863ea4d1f1bb1b7ca0ff9d7e232e042c Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 18 Sep 2024 10:34:48 +0300 Subject: [PATCH 20/98] Used most recent unified syntax for raw calls Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 648fe42c..f1a8856a 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -18,8 +18,8 @@ pub trait DelegationModule: common::storage::CommonStorageModule { .to(delegation_contract_address) .raw_call(ManagedBuffer::from(DELEGATE_ENDPOINT)) .egld(&egld_amount) - .with_callback(DelegationModule::callbacks(self).stake_callback(&caller, &egld_amount)) - .call_and_exit(); + .callback(DelegationModule::callbacks(self).stake_callback(&caller, &egld_amount)) + .async_call_and_exit(); } #[callback] @@ -63,12 +63,12 @@ pub trait DelegationModule: common::storage::CommonStorageModule { .to(delegation_contract_address) .raw_call(ManagedBuffer::from(UNDELEGATE_ENDPOINT)) .argument(&args) - .with_callback(DelegationModule::callbacks(self).unstake_callback( + .callback(DelegationModule::callbacks(self).unstake_callback( &caller, &egld_amount_to_unstake, current_epoch, )) - .call_and_exit(); + .async_call_and_exit(); } #[callback] From 11198507379868fc94eb3207c80758036c6b8818 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 18 Sep 2024 11:54:53 +0300 Subject: [PATCH 21/98] Added delegation mock contract Signed-off-by: Andrei Baltariu --- Cargo.toml | 2 + delegation-mock/Cargo.lock | 1153 +++++++++++++++++ delegation-mock/Cargo.toml | 24 + delegation-mock/meta/Cargo.toml | 12 + delegation-mock/meta/src/main.rs | 3 + delegation-mock/multiversx.json | 3 + .../scenarios/delegation_mock.scen.json | 39 + delegation-mock/src/delegation_mock.rs | 14 + .../tests/delegation_mock_scenario_go_test.rs | 10 + .../tests/delegation_mock_scenario_rs_test.rs | 13 + delegation-mock/wasm/Cargo.lock | 188 +++ delegation-mock/wasm/Cargo.toml | 34 + delegation-mock/wasm/src/lib.rs | 26 + 13 files changed, 1521 insertions(+) create mode 100644 delegation-mock/Cargo.lock create mode 100644 delegation-mock/Cargo.toml create mode 100644 delegation-mock/meta/Cargo.toml create mode 100644 delegation-mock/meta/src/main.rs create mode 100644 delegation-mock/multiversx.json create mode 100644 delegation-mock/scenarios/delegation_mock.scen.json create mode 100644 delegation-mock/src/delegation_mock.rs create mode 100644 delegation-mock/tests/delegation_mock_scenario_go_test.rs create mode 100644 delegation-mock/tests/delegation_mock_scenario_rs_test.rs create mode 100644 delegation-mock/wasm/Cargo.lock create mode 100644 delegation-mock/wasm/Cargo.toml create mode 100644 delegation-mock/wasm/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 7fba15ba..93732798 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,6 @@ members = [ "enshrine-esdt-safe/meta", "liquid-staking", "liquid-staking/meta", + "delegation-mock", + "delegation-mock/meta", ] diff --git a/delegation-mock/Cargo.lock b/delegation-mock/Cargo.lock new file mode 100644 index 00000000..3b62e40b --- /dev/null +++ b/delegation-mock/Cargo.lock @@ -0,0 +1,1153 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "anstream" +version = "0.6.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" + +[[package]] +name = "anstyle-parse" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bech32" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clap" +version = "4.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" + +[[package]] +name = "colorchoice" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" + +[[package]] +name = "colored" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf2150cce219b664a8a70df7a1f933836724b503f8a413af9365b4dcc4d90b8" +dependencies = [ + "lazy_static", + "windows-sys 0.48.0", +] + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "cpufeatures" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "curve25519-dalek" +version = "4.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" +dependencies = [ + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "digest", + "fiat-crypto", + "rustc_version", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "delegation-mock" +version = "0.0.0" +dependencies = [ + "multiversx-sc", + "multiversx-sc-scenario", + "num-bigint", +] + +[[package]] +name = "delegation-mock-meta" +version = "0.0.0" +dependencies = [ + "delegation-mock", + "multiversx-sc-meta-lib", +] + +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "ed25519" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +dependencies = [ + "pkcs8", + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" +dependencies = [ + "curve25519-dalek", + "ed25519", + "serde", + "sha2", + "subtle", + "zeroize", +] + +[[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 = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "fiat-crypto" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "serde", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[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 = "indexmap" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +dependencies = [ + "equivalent", + "hashbrown", + "serde", +] + +[[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.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "keccak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" +dependencies = [ + "cpufeatures", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "multiversx-chain-scenario-format" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcca77966bf5eb9c9f96d0597f17a4fa7b64681cc7b83e39bdf31f8c6ca04d44" +dependencies = [ + "bech32", + "hex", + "num-bigint", + "num-traits", + "serde", + "serde_json", + "sha3", +] + +[[package]] +name = "multiversx-chain-vm" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c537d27dfc7a8e295d4f7c5f67a967ce66b6c3fc8e31a160e8cf28e14ecb2d" +dependencies = [ + "bitflags", + "colored", + "ed25519-dalek", + "hex", + "hex-literal", + "itertools", + "multiversx-chain-vm-executor", + "num-bigint", + "num-traits", + "rand", + "rand_seeder", + "sha2", + "sha3", +] + +[[package]] +name = "multiversx-chain-vm-executor" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b59072fa0624b55ae5ae3fa6bfa91515bbeb4ac440214bc4a509e2c8806d6e9f" + +[[package]] +name = "multiversx-sc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "num-bigint", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-meta-lib" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cadbd4a972764b864e7f6b73e6963df85f7010fbd3a993d820873809bce4e93" +dependencies = [ + "clap", + "colored", + "convert_case", + "hex", + "lazy_static", + "multiversx-sc", + "rustc_version", + "semver", + "serde", + "serde_json", + "toml", + "wasmparser", + "wasmprinter", +] + +[[package]] +name = "multiversx-sc-scenario" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe13bdcc09d9405c5767593359c8193dc05f8271423f76bd991cfabb90056e4c" +dependencies = [ + "base64", + "bech32", + "colored", + "hex", + "itertools", + "log", + "multiversx-chain-scenario-format", + "multiversx-chain-vm", + "multiversx-chain-vm-executor", + "multiversx-sc", + "multiversx-sc-meta-lib", + "num-bigint", + "num-traits", + "pathdiff", + "serde", + "serde_json", + "sha2", + "unwrap-infallible", +] + +[[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-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "pathdiff" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radix_trie" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" +dependencies = [ + "endian-type", + "nibble_vec", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_seeder" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a9febe641d2842ffc76ee962668a17578767c4e01735e4802b21ed9a24b2e4e" +dependencies = [ + "rand_core", +] + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_spanned" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +dependencies = [ + "serde", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest", + "keccak", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "rand_core", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "toml" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b072cee73c449a636ffd6f32bd8de3a9f7119139aff882f44943ce2986dc5cf" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-segmentation" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" + +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasmparser" +version = "0.216.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcdee6bea3619d311fb4b299721e89a986c3470f804b6d534340e412589028e3" +dependencies = [ + "ahash", + "bitflags", + "hashbrown", + "indexmap", + "semver", + "serde", +] + +[[package]] +name = "wasmprinter" +version = "0.216.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f82916f3892e53620639217d6ec78fe15c678352a3fbf3f3745b6417d0bd70f" +dependencies = [ + "anyhow", + "termcolor", + "wasmparser", +] + +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "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]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "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]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +dependencies = [ + "memchr", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "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.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/delegation-mock/Cargo.toml b/delegation-mock/Cargo.toml new file mode 100644 index 00000000..06369d77 --- /dev/null +++ b/delegation-mock/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "delegation-mock" +version = "0.0.0" +publish = false +edition = "2021" +authors = ["you"] + +[lib] +path = "src/delegation_mock.rs" + +[dependencies.multiversx-sc] +version = "0.53.0" + +[dev-dependencies] +num-bigint = "0.4" + +[dev-dependencies.multiversx-sc-scenario] +version = "0.53.0" + +[workspace] +members = [ + ".", + "meta", +] diff --git a/delegation-mock/meta/Cargo.toml b/delegation-mock/meta/Cargo.toml new file mode 100644 index 00000000..46940456 --- /dev/null +++ b/delegation-mock/meta/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "delegation-mock-meta" +version = "0.0.0" +edition = "2021" +publish = false + +[dependencies.delegation-mock] +path = ".." + +[dependencies.multiversx-sc-meta-lib] +version = "0.53.0" +default-features = false diff --git a/delegation-mock/meta/src/main.rs b/delegation-mock/meta/src/main.rs new file mode 100644 index 00000000..71ddc614 --- /dev/null +++ b/delegation-mock/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta_lib::cli_main::(); +} diff --git a/delegation-mock/multiversx.json b/delegation-mock/multiversx.json new file mode 100644 index 00000000..73655396 --- /dev/null +++ b/delegation-mock/multiversx.json @@ -0,0 +1,3 @@ +{ + "language": "rust" +} \ No newline at end of file diff --git a/delegation-mock/scenarios/delegation_mock.scen.json b/delegation-mock/scenarios/delegation_mock.scen.json new file mode 100644 index 00000000..36982a29 --- /dev/null +++ b/delegation-mock/scenarios/delegation_mock.scen.json @@ -0,0 +1,39 @@ +{ + "name": "empty", + "steps": [ + { + "step": "setState", + "accounts": { + "address:owner": { + "nonce": "1", + "balance": "0" + } + }, + "newAddresses": [ + { + "creatorAddress": "address:owner", + "creatorNonce": "1", + "newAddress": "sc:empty" + } + ] + }, + { + "step": "scDeploy", + "id": "deploy", + "tx": { + "from": "address:owner", + "contractCode": "mxsc:../output/delegation-mock.mxsc.json", + "arguments": [], + "gasLimit": "5,000,000", + "gasPrice": "0" + }, + "expect": { + "out": [], + "status": "", + "logs": [], + "gas": "*", + "refund": "*" + } + } + ] +} diff --git a/delegation-mock/src/delegation_mock.rs b/delegation-mock/src/delegation_mock.rs new file mode 100644 index 00000000..26c770fd --- /dev/null +++ b/delegation-mock/src/delegation_mock.rs @@ -0,0 +1,14 @@ +#![no_std] + +#[allow(unused_imports)] +use multiversx_sc::imports::*; + +/// An empty contract. To be used as a template when starting a new contract from scratch. +#[multiversx_sc::contract] +pub trait DelegationMock { + #[init] + fn init(&self) {} + + #[upgrade] + fn upgrade(&self) {} +} diff --git a/delegation-mock/tests/delegation_mock_scenario_go_test.rs b/delegation-mock/tests/delegation_mock_scenario_go_test.rs new file mode 100644 index 00000000..f6c50520 --- /dev/null +++ b/delegation-mock/tests/delegation_mock_scenario_go_test.rs @@ -0,0 +1,10 @@ +use multiversx_sc_scenario::*; + +fn world() -> ScenarioWorld { + ScenarioWorld::vm_go() +} + +#[test] +fn empty_go() { + world().run("scenarios/delegation_mock.scen.json"); +} diff --git a/delegation-mock/tests/delegation_mock_scenario_rs_test.rs b/delegation-mock/tests/delegation_mock_scenario_rs_test.rs new file mode 100644 index 00000000..778058f8 --- /dev/null +++ b/delegation-mock/tests/delegation_mock_scenario_rs_test.rs @@ -0,0 +1,13 @@ +use multiversx_sc_scenario::*; + +fn world() -> ScenarioWorld { + let mut blockchain = ScenarioWorld::new(); + + blockchain.register_contract("mxsc:output/delegation-mock.mxsc.json", delegation_mock::ContractBuilder); + blockchain +} + +#[test] +fn empty_rs() { + world().run("scenarios/delegation_mock.scen.json"); +} diff --git a/delegation-mock/wasm/Cargo.lock b/delegation-mock/wasm/Cargo.lock new file mode 100644 index 00000000..ebba8498 --- /dev/null +++ b/delegation-mock/wasm/Cargo.lock @@ -0,0 +1,188 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "delegation-mock" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "delegation-mock-wasm" +version = "0.0.0" +dependencies = [ + "delegation-mock", + "multiversx-sc-wasm-adapter", +] + +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hex-literal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "multiversx-sc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "nibble_vec" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" +dependencies = [ + "smallvec", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radix_trie" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" +dependencies = [ + "endian-type", + "nibble_vec", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" diff --git a/delegation-mock/wasm/Cargo.toml b/delegation-mock/wasm/Cargo.toml new file mode 100644 index 00000000..0af2f187 --- /dev/null +++ b/delegation-mock/wasm/Cargo.toml @@ -0,0 +1,34 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + +[package] +name = "delegation-mock-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.delegation-mock] +path = ".." + +[dependencies.multiversx-sc-wasm-adapter] +version = "0.53.0" + +[workspace] +members = ["."] diff --git a/delegation-mock/wasm/src/lib.rs b/delegation-mock/wasm/src/lib.rs new file mode 100644 index 00000000..743fe742 --- /dev/null +++ b/delegation-mock/wasm/src/lib.rs @@ -0,0 +1,26 @@ +// Code generated by the multiversx-sc build system. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +// Init: 1 +// Upgrade: 1 +// Endpoints: 0 +// Async Callback (empty): 1 +// Total number of exported functions: 3 + +#![no_std] + +multiversx_sc_wasm_adapter::allocator!(); +multiversx_sc_wasm_adapter::panic_handler!(); + +multiversx_sc_wasm_adapter::endpoints! { + delegation_mock + ( + init => init + upgrade => upgrade + ) +} + +multiversx_sc_wasm_adapter::async_callback_empty! {} From 3b069bfc573724a1f99d23b111341732cbbaf382 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 18 Sep 2024 11:55:55 +0300 Subject: [PATCH 22/98] Renamed main file in delegation Signed-off-by: Andrei Baltariu --- delegation-mock/Cargo.toml | 2 +- delegation-mock/src/{delegation_mock.rs => lib.rs} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename delegation-mock/src/{delegation_mock.rs => lib.rs} (100%) diff --git a/delegation-mock/Cargo.toml b/delegation-mock/Cargo.toml index 06369d77..d72d6b24 100644 --- a/delegation-mock/Cargo.toml +++ b/delegation-mock/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" authors = ["you"] [lib] -path = "src/delegation_mock.rs" +path = "src/lib.rs" [dependencies.multiversx-sc] version = "0.53.0" diff --git a/delegation-mock/src/delegation_mock.rs b/delegation-mock/src/lib.rs similarity index 100% rename from delegation-mock/src/delegation_mock.rs rename to delegation-mock/src/lib.rs From cdc17be9b7d02d56df98b6822bf2a8af4c093839 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 18 Sep 2024 11:57:07 +0300 Subject: [PATCH 23/98] Added mock code Signed-off-by: Andrei Baltariu --- delegation-mock/src/lib.rs | 103 ++++++++++++++++++++++++++++++-- delegation-mock/wasm/src/lib.rs | 11 ++-- 2 files changed, 105 insertions(+), 9 deletions(-) diff --git a/delegation-mock/src/lib.rs b/delegation-mock/src/lib.rs index 26c770fd..6ccc71d7 100644 --- a/delegation-mock/src/lib.rs +++ b/delegation-mock/src/lib.rs @@ -1,14 +1,107 @@ #![no_std] -#[allow(unused_imports)] -use multiversx_sc::imports::*; +multiversx_sc::imports!(); + +pub type Epoch = u64; +pub const MAX_PERCENTAGE: u64 = 100_000; +pub const APY: u64 = 10_000; //10% +pub const EPOCHS_IN_YEAR: u64 = 365; +pub const UNBOND_PERIOD: u64 = 10; -/// An empty contract. To be used as a template when starting a new contract from scratch. #[multiversx_sc::contract] pub trait DelegationMock { #[init] fn init(&self) {} - #[upgrade] - fn upgrade(&self) {} + #[payable("EGLD")] + #[only_owner] + #[endpoint(depositEGLD)] + fn deposit_egld(&self) { + let payment_amount = self.call_value().egld_value().clone_value(); + self.egld_token_supply() + .update(|value| *value += &payment_amount); + } + + #[payable("EGLD")] + #[endpoint(delegate)] + fn delegate(&self) { + let caller = self.blockchain().get_caller(); + let payment_amount = self.call_value().egld_value().clone_value(); + self.address_deposit(&caller) + .update(|value| *value += &payment_amount); + self.egld_token_supply() + .update(|value| *value += &payment_amount); + } + + #[endpoint(unDelegate)] + fn undelegate(&self, egld_to_undelegate: BigUint) { + let caller = self.blockchain().get_caller(); + let current_epoch = self.blockchain().get_block_epoch(); + let total_deposit = self.address_deposit(&caller).get(); + require!( + egld_to_undelegate > 0 && egld_to_undelegate <= total_deposit, + "Invalid undelegate amount" + ); + self.address_deposit(&caller) + .update(|value| *value -= &egld_to_undelegate); + self.address_undelegate_amount(&caller) + .update(|value| *value += &egld_to_undelegate); + self.address_undelegate_epoch(&caller) + .set(current_epoch + UNBOND_PERIOD); + } + + #[endpoint(withdraw)] + fn withdraw(&self) { + let caller = self.blockchain().get_caller(); + let current_epoch = self.blockchain().get_block_epoch(); + let withdraw_epoch = self.address_undelegate_epoch(&caller).get(); + let withdraw_amount = self.address_undelegate_amount(&caller).get(); + + require!(withdraw_amount > 0, "No amount to withdraw"); + require!( + withdraw_epoch > 0 && current_epoch >= withdraw_epoch, + "Cannot withdraw yet" + ); + + self.egld_token_supply() + .update(|value| *value -= &withdraw_amount); + self.address_undelegate_epoch(&caller).clear(); + self.address_undelegate_amount(&caller).clear(); + + self.tx().to(&caller).egld(&withdraw_amount).transfer(); + } + + #[endpoint(claimRewards)] + fn claim_rewards(&self) { + let caller = self.blockchain().get_caller(); + let current_epoch = self.blockchain().get_block_epoch(); + let last_claim_epoch = self.address_last_claim_epoch(&caller).get(); + let total_deposit = self.address_deposit(&caller).get(); + + if current_epoch > last_claim_epoch { + let rewards = (total_deposit * APY / MAX_PERCENTAGE) + * (current_epoch - last_claim_epoch) + / EPOCHS_IN_YEAR; + if rewards > 0u64 { + self.tx().to(&caller).egld(&rewards).transfer(); + self.address_last_claim_epoch(&caller).set(current_epoch); + self.egld_token_supply().update(|value| *value -= &rewards); + } + } + } + + #[storage_mapper("egldTokenSupply")] + fn egld_token_supply(&self) -> SingleValueMapper; + + #[storage_mapper("addressDeposit")] + fn address_deposit(&self, address: &ManagedAddress) -> SingleValueMapper; + + #[storage_mapper("addressLastClaim")] + fn address_last_claim_epoch(&self, address: &ManagedAddress) -> SingleValueMapper; + + #[storage_mapper("addressUndelegateAmount")] + fn address_undelegate_amount(&self, address: &ManagedAddress) -> SingleValueMapper; + + #[storage_mapper("addressUndelegateEpoch")] + fn address_undelegate_epoch(&self, address: &ManagedAddress) -> SingleValueMapper; } diff --git a/delegation-mock/wasm/src/lib.rs b/delegation-mock/wasm/src/lib.rs index 743fe742..0ba79e64 100644 --- a/delegation-mock/wasm/src/lib.rs +++ b/delegation-mock/wasm/src/lib.rs @@ -5,10 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Upgrade: 1 -// Endpoints: 0 +// Endpoints: 5 // Async Callback (empty): 1 -// Total number of exported functions: 3 +// Total number of exported functions: 7 #![no_std] @@ -19,7 +18,11 @@ multiversx_sc_wasm_adapter::endpoints! { delegation_mock ( init => init - upgrade => upgrade + depositEGLD => deposit_egld + delegate => delegate + unDelegate => undelegate + withdraw => withdraw + claimRewards => claim_rewards ) } From 9b62311aaf5d94db5d2c3f95b586579ffc05e0a7 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 18 Sep 2024 12:03:31 +0300 Subject: [PATCH 24/98] Added sc-config for proxy generation Signed-off-by: Andrei Baltariu --- delegation-mock/sc-config.toml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 delegation-mock/sc-config.toml diff --git a/delegation-mock/sc-config.toml b/delegation-mock/sc-config.toml new file mode 100644 index 00000000..20ba4f63 --- /dev/null +++ b/delegation-mock/sc-config.toml @@ -0,0 +1,22 @@ +[settings] +main = "main" + +[contracts.main] +name = "delegation-mock" + +[contracts.full] +name = "delegation-mock-full" +add-unlabelled = true +add-labels = ["delegation-mock-external-view"] + +[contracts.view] +name = "delegation-mock-view" +external-view = true +add-unlabelled = false +add-labels = ["delegation-mock-external-view"] + +[[proxy]] +path = "src/delegation_proxy.rs" + +[[proxy]] +path = "../liquid-staking/src/delegation_proxy.rs" From 1b8986e50e123acbfb8ec9dcca399c93ba30ed5d Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 18 Sep 2024 12:04:00 +0300 Subject: [PATCH 25/98] Added generated files Signed-off-by: Andrei Baltariu --- delegation-mock/src/delegation_proxy.rs | 111 ++++++++++++++++++ .../wasm-delegation-mock-full/Cargo.toml | 34 ++++++ .../wasm-delegation-mock-full/src/lib.rs | 29 +++++ .../wasm-delegation-mock-view/Cargo.toml | 34 ++++++ .../wasm-delegation-mock-view/src/lib.rs | 25 ++++ 5 files changed, 233 insertions(+) create mode 100644 delegation-mock/src/delegation_proxy.rs create mode 100644 delegation-mock/wasm-delegation-mock-full/Cargo.toml create mode 100644 delegation-mock/wasm-delegation-mock-full/src/lib.rs create mode 100644 delegation-mock/wasm-delegation-mock-view/Cargo.toml create mode 100644 delegation-mock/wasm-delegation-mock-view/src/lib.rs diff --git a/delegation-mock/src/delegation_proxy.rs b/delegation-mock/src/delegation_proxy.rs new file mode 100644 index 00000000..268915ca --- /dev/null +++ b/delegation-mock/src/delegation_proxy.rs @@ -0,0 +1,111 @@ +// Code generated by the multiversx-sc proxy generator. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +#![allow(dead_code)] +#![allow(clippy::all)] + +use multiversx_sc::proxy_imports::*; + +pub struct DelegationMockProxy; + +impl TxProxyTrait for DelegationMockProxy +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + type TxProxyMethods = DelegationMockProxyMethods; + + fn proxy_methods(self, tx: Tx) -> Self::TxProxyMethods { + DelegationMockProxyMethods { wrapped_tx: tx } + } +} + +pub struct DelegationMockProxyMethods +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + wrapped_tx: Tx, +} + +#[rustfmt::skip] +impl DelegationMockProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + Gas: TxGas, +{ + pub fn init( + self, + ) -> TxTypedDeploy { + self.wrapped_tx + .payment(NotPayable) + .raw_deploy() + .original_result() + } +} + +#[rustfmt::skip] +impl DelegationMockProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + pub fn deposit_egld( + self, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("depositEGLD") + .original_result() + } + + pub fn delegate( + self, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("delegate") + .original_result() + } + + pub fn undelegate< + Arg0: ProxyArg>, + >( + self, + egld_to_undelegate: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("unDelegate") + .argument(&egld_to_undelegate) + .original_result() + } + + pub fn withdraw( + self, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("withdraw") + .original_result() + } + + pub fn claim_rewards( + self, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("claimRewards") + .original_result() + } +} diff --git a/delegation-mock/wasm-delegation-mock-full/Cargo.toml b/delegation-mock/wasm-delegation-mock-full/Cargo.toml new file mode 100644 index 00000000..72581d93 --- /dev/null +++ b/delegation-mock/wasm-delegation-mock-full/Cargo.toml @@ -0,0 +1,34 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + +[package] +name = "delegation-mock-full-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.delegation-mock] +path = ".." + +[dependencies.multiversx-sc-wasm-adapter] +version = "0.53.0" + +[workspace] +members = ["."] diff --git a/delegation-mock/wasm-delegation-mock-full/src/lib.rs b/delegation-mock/wasm-delegation-mock-full/src/lib.rs new file mode 100644 index 00000000..0ba79e64 --- /dev/null +++ b/delegation-mock/wasm-delegation-mock-full/src/lib.rs @@ -0,0 +1,29 @@ +// Code generated by the multiversx-sc build system. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +// Init: 1 +// Endpoints: 5 +// Async Callback (empty): 1 +// Total number of exported functions: 7 + +#![no_std] + +multiversx_sc_wasm_adapter::allocator!(); +multiversx_sc_wasm_adapter::panic_handler!(); + +multiversx_sc_wasm_adapter::endpoints! { + delegation_mock + ( + init => init + depositEGLD => deposit_egld + delegate => delegate + unDelegate => undelegate + withdraw => withdraw + claimRewards => claim_rewards + ) +} + +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/delegation-mock/wasm-delegation-mock-view/Cargo.toml b/delegation-mock/wasm-delegation-mock-view/Cargo.toml new file mode 100644 index 00000000..2d967eef --- /dev/null +++ b/delegation-mock/wasm-delegation-mock-view/Cargo.toml @@ -0,0 +1,34 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + +[package] +name = "delegation-mock-view-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.delegation-mock] +path = ".." + +[dependencies.multiversx-sc-wasm-adapter] +version = "0.53.0" + +[workspace] +members = ["."] diff --git a/delegation-mock/wasm-delegation-mock-view/src/lib.rs b/delegation-mock/wasm-delegation-mock-view/src/lib.rs new file mode 100644 index 00000000..b2d1aa55 --- /dev/null +++ b/delegation-mock/wasm-delegation-mock-view/src/lib.rs @@ -0,0 +1,25 @@ +// Code generated by the multiversx-sc build system. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +// Init: 1 +// Endpoints: 0 +// Async Callback (empty): 1 +// Total number of exported functions: 2 + +#![no_std] + +multiversx_sc_wasm_adapter::allocator!(); +multiversx_sc_wasm_adapter::panic_handler!(); + +multiversx_sc_wasm_adapter::external_view_init! {} + +multiversx_sc_wasm_adapter::external_view_endpoints! { + delegation_mock + ( + ) +} + +multiversx_sc_wasm_adapter::async_callback_empty! {} From 0c94913c62cd8d7bf6f0ae97997120e80c22351e Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 18 Sep 2024 12:04:19 +0300 Subject: [PATCH 26/98] Added delegation proxy + deploy setup Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation_proxy.rs | 111 +++++++++++++++++++ liquid-staking/tests/liquid_staking_tests.rs | 16 +++ 2 files changed, 127 insertions(+) create mode 100644 liquid-staking/src/delegation_proxy.rs diff --git a/liquid-staking/src/delegation_proxy.rs b/liquid-staking/src/delegation_proxy.rs new file mode 100644 index 00000000..268915ca --- /dev/null +++ b/liquid-staking/src/delegation_proxy.rs @@ -0,0 +1,111 @@ +// Code generated by the multiversx-sc proxy generator. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +#![allow(dead_code)] +#![allow(clippy::all)] + +use multiversx_sc::proxy_imports::*; + +pub struct DelegationMockProxy; + +impl TxProxyTrait for DelegationMockProxy +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + type TxProxyMethods = DelegationMockProxyMethods; + + fn proxy_methods(self, tx: Tx) -> Self::TxProxyMethods { + DelegationMockProxyMethods { wrapped_tx: tx } + } +} + +pub struct DelegationMockProxyMethods +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + wrapped_tx: Tx, +} + +#[rustfmt::skip] +impl DelegationMockProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + Gas: TxGas, +{ + pub fn init( + self, + ) -> TxTypedDeploy { + self.wrapped_tx + .payment(NotPayable) + .raw_deploy() + .original_result() + } +} + +#[rustfmt::skip] +impl DelegationMockProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + pub fn deposit_egld( + self, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("depositEGLD") + .original_result() + } + + pub fn delegate( + self, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("delegate") + .original_result() + } + + pub fn undelegate< + Arg0: ProxyArg>, + >( + self, + egld_to_undelegate: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("unDelegate") + .argument(&egld_to_undelegate) + .original_result() + } + + pub fn withdraw( + self, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("withdraw") + .original_result() + } + + pub fn claim_rewards( + self, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("claimRewards") + .original_result() + } +} diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index 2566e825..284298d4 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -9,6 +9,8 @@ const LIQUID_STAKING_CODE_PATH: MxscPath = MxscPath::new("output/liquid-stacking const LIQUID_STAKING_ADDRESS: TestSCAddress = TestSCAddress::new("liquid-staking"); const LIQUID_STACKING_OWNER: TestAddress = TestAddress::new("owner"); +const DELEGATION_CODE_PATH: MxscPath = + MxscPath::new("../delegation-mock/output/delegation-mock.mxsc-json"); const DELEGATION_ADDRESS: TestSCAddress = TestSCAddress::new("delegation"); const VALIDATOR_ADDRESS: TestAddress = TestAddress::new("validator"); @@ -19,6 +21,7 @@ fn world() -> ScenarioWorld { let mut blockchain = ScenarioWorld::new(); blockchain.register_contract(LIQUID_STAKING_CODE_PATH, liquid_staking::ContractBuilder); + blockchain.register_contract(DELEGATION_CODE_PATH, liquid_staking::ContractBuilder); blockchain } @@ -62,6 +65,19 @@ impl LiquidStakingTestState { self } + fn deploy_mock_delegation(&mut self) -> &mut Self { + self.world + .tx() + .from(LIQUID_STACKING_OWNER) + .typed(liquid_staking_proxy::LiquidStakingProxy) + .init() + .code(LIQUID_STAKING_CODE_PATH) + .new_address(LIQUID_STAKING_ADDRESS) + .run(); + + self + } + fn propose_register_delegation_address( &mut self, contract_name: &ManagedBuffer, From 7eb812bd257d2ceec38e218bb6117971fb61932b Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 18 Sep 2024 12:05:13 +0300 Subject: [PATCH 27/98] Removed workspace from delegation Signed-off-by: Andrei Baltariu --- delegation-mock/Cargo.toml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/delegation-mock/Cargo.toml b/delegation-mock/Cargo.toml index d72d6b24..781b11aa 100644 --- a/delegation-mock/Cargo.toml +++ b/delegation-mock/Cargo.toml @@ -16,9 +16,3 @@ num-bigint = "0.4" [dev-dependencies.multiversx-sc-scenario] version = "0.53.0" - -[workspace] -members = [ - ".", - "meta", -] From d55dc2802bf3320bb171abb95610ad3d4d10d803 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 18 Sep 2024 12:06:39 +0300 Subject: [PATCH 28/98] Added delegation to Cargo Signed-off-by: Andrei Baltariu --- Cargo.lock | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 5e9402aa..3273e10f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -283,6 +283,23 @@ dependencies = [ "syn", ] +[[package]] +name = "delegation-mock" +version = "0.0.0" +dependencies = [ + "multiversx-sc", + "multiversx-sc-scenario", + "num-bigint", +] + +[[package]] +name = "delegation-mock-meta" +version = "0.0.0" +dependencies = [ + "delegation-mock", + "multiversx-sc-meta-lib", +] + [[package]] name = "der" version = "0.7.9" From bfa1edcbc0fe3f0cc550bc06cadca6ee144b1591 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 18 Sep 2024 12:06:49 +0300 Subject: [PATCH 29/98] Modified deploy test Signed-off-by: Andrei Baltariu --- liquid-staking/tests/liquid_staking_tests.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index 284298d4..e884cb84 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -71,8 +71,8 @@ impl LiquidStakingTestState { .from(LIQUID_STACKING_OWNER) .typed(liquid_staking_proxy::LiquidStakingProxy) .init() - .code(LIQUID_STAKING_CODE_PATH) - .new_address(LIQUID_STAKING_ADDRESS) + .code(DELEGATION_CODE_PATH) + .new_address(DELEGATION_ADDRESS) .run(); self @@ -129,6 +129,7 @@ fn test_deploy() { let mut state = LiquidStakingTestState::new(); state.deploy_liquid_staking(); + state.deploy_mock_delegation(); } #[test] From 3be3909621ffb0833e0cdac5a2f16c95f93b40c4 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 18 Sep 2024 12:10:52 +0300 Subject: [PATCH 30/98] Added balance to delegation address and removed deploy function Signed-off-by: Andrei Baltariu --- liquid-staking/tests/liquid_staking_tests.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index e884cb84..731e36a3 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -49,6 +49,12 @@ impl LiquidStakingTestState { .balance(BigUint::from(WEGLD_BALANCE)) .nonce(1); + world + .account(DELEGATION_ADDRESS) + .code(DELEGATION_CODE_PATH) + .balance(BigUint::from(WEGLD_BALANCE)) + .nonce(1); + Self { world } } @@ -65,19 +71,6 @@ impl LiquidStakingTestState { self } - fn deploy_mock_delegation(&mut self) -> &mut Self { - self.world - .tx() - .from(LIQUID_STACKING_OWNER) - .typed(liquid_staking_proxy::LiquidStakingProxy) - .init() - .code(DELEGATION_CODE_PATH) - .new_address(DELEGATION_ADDRESS) - .run(); - - self - } - fn propose_register_delegation_address( &mut self, contract_name: &ManagedBuffer, @@ -129,7 +122,6 @@ fn test_deploy() { let mut state = LiquidStakingTestState::new(); state.deploy_liquid_staking(); - state.deploy_mock_delegation(); } #[test] From e95ce6b822b17ecfd0459cac53348433ea3d7220 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 18 Sep 2024 12:12:41 +0300 Subject: [PATCH 31/98] Modified check account address Signed-off-by: Andrei Baltariu --- liquid-staking/tests/liquid_staking_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index 731e36a3..e253efc3 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -173,6 +173,6 @@ fn test_stake() { state .world - .check_account(LIQUID_STAKING_ADDRESS) + .check_account(LIQUID_STACKING_OWNER) .balance(BigUint::from(WEGLD_BALANCE) - payment); } From 8f2502628e3dc76edc7933d196d01b2e6e7d1445 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 18 Sep 2024 14:28:23 +0300 Subject: [PATCH 32/98] Modified cargo toml to use its proxy in tests Signed-off-by: Andrei Baltariu --- Cargo.lock | 1 + delegation-mock/src/lib.rs | 2 ++ liquid-staking/Cargo.toml | 3 +++ 3 files changed, 6 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 3273e10f..b83ad7b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -565,6 +565,7 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" name = "liquid-staking" version = "0.0.0" dependencies = [ + "delegation-mock", "multiversx-sc", "multiversx-sc-scenario", "num-bigint", diff --git a/delegation-mock/src/lib.rs b/delegation-mock/src/lib.rs index 6ccc71d7..d6d990c9 100644 --- a/delegation-mock/src/lib.rs +++ b/delegation-mock/src/lib.rs @@ -8,6 +8,8 @@ pub const APY: u64 = 10_000; //10% pub const EPOCHS_IN_YEAR: u64 = 365; pub const UNBOND_PERIOD: u64 = 10; +pub mod delegation_proxy; + #[multiversx_sc::contract] pub trait DelegationMock { #[init] diff --git a/liquid-staking/Cargo.toml b/liquid-staking/Cargo.toml index e725d03c..4fbcbe0a 100644 --- a/liquid-staking/Cargo.toml +++ b/liquid-staking/Cargo.toml @@ -16,3 +16,6 @@ num-bigint = "0.4" [dev-dependencies.multiversx-sc-scenario] version = "0.53.0" + +[dependencies.delegation-mock] +path = "../delegation-mock" From 4358578930a3c0e06c9f7636276cd6347e984b7d Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 18 Sep 2024 15:23:36 +0300 Subject: [PATCH 33/98] Stake test progress Signed-off-by: Andrei Baltariu --- .../wasm-delegation-mock-full/Cargo.lock | 188 ++++++++++++++++++ .../wasm-delegation-mock-view/Cargo.lock | 188 ++++++++++++++++++ liquid-staking/src/delegation.rs | 2 +- liquid-staking/src/lib.rs | 1 + liquid-staking/tests/liquid_staking_tests.rs | 78 ++++++-- .../wasm-liquid-staking-full/Cargo.lock | 8 + .../wasm-liquid-staking-view/Cargo.lock | 8 + liquid-staking/wasm/Cargo.lock | 8 + 8 files changed, 460 insertions(+), 21 deletions(-) create mode 100644 delegation-mock/wasm-delegation-mock-full/Cargo.lock create mode 100644 delegation-mock/wasm-delegation-mock-view/Cargo.lock diff --git a/delegation-mock/wasm-delegation-mock-full/Cargo.lock b/delegation-mock/wasm-delegation-mock-full/Cargo.lock new file mode 100644 index 00000000..61913684 --- /dev/null +++ b/delegation-mock/wasm-delegation-mock-full/Cargo.lock @@ -0,0 +1,188 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "delegation-mock" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "delegation-mock-full-wasm" +version = "0.0.0" +dependencies = [ + "delegation-mock", + "multiversx-sc-wasm-adapter", +] + +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hex-literal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "multiversx-sc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "nibble_vec" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" +dependencies = [ + "smallvec", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radix_trie" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" +dependencies = [ + "endian-type", + "nibble_vec", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" diff --git a/delegation-mock/wasm-delegation-mock-view/Cargo.lock b/delegation-mock/wasm-delegation-mock-view/Cargo.lock new file mode 100644 index 00000000..6333b15e --- /dev/null +++ b/delegation-mock/wasm-delegation-mock-view/Cargo.lock @@ -0,0 +1,188 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "delegation-mock" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "delegation-mock-view-wasm" +version = "0.0.0" +dependencies = [ + "delegation-mock", + "multiversx-sc-wasm-adapter", +] + +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hex-literal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "multiversx-sc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d7a5a8534e5dc9128cb8f15a65a21dd378e135c6016c7cd1491cd012bc8cb" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", + "unwrap-infallible", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffba1dce273ed5b61ee1b90aeea5c8c744617d0f12624f620768c144d83e753" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "nibble_vec" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" +dependencies = [ + "smallvec", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radix_trie" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" +dependencies = [ + "endian-type", + "nibble_vec", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unwrap-infallible" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "151ac09978d3c2862c4e39b557f4eceee2cc72150bc4cb4f16abf061b6e381fb" diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index f1a8856a..6d3d388b 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -16,7 +16,7 @@ pub trait DelegationModule: common::storage::CommonStorageModule { self.tx() .to(delegation_contract_address) - .raw_call(ManagedBuffer::from(DELEGATE_ENDPOINT)) + .raw_call(DELEGATE_ENDPOINT) .egld(&egld_amount) .callback(DelegationModule::callbacks(self).stake_callback(&caller, &egld_amount)) .async_call_and_exit(); diff --git a/liquid-staking/src/lib.rs b/liquid-staking/src/lib.rs index fef1bfd0..54e5179e 100644 --- a/liquid-staking/src/lib.rs +++ b/liquid-staking/src/lib.rs @@ -4,6 +4,7 @@ use multiversx_sc::imports::*; pub mod common; pub mod delegation; +pub mod delegation_proxy; pub mod liquid_staking_proxy; pub mod liquidity_pools; diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index e253efc3..824d3eb0 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -1,4 +1,6 @@ -use liquid_staking::{common::storage::CommonStorageModule, liquid_staking_proxy}; +use liquid_staking::{ + common::storage::CommonStorageModule, delegation_proxy, liquid_staking_proxy, +}; use multiversx_sc::types::{BigUint, ManagedBuffer, TestAddress, TestSCAddress}; use multiversx_sc_scenario::{ api::StaticApi, imports::MxscPath, DebugApi, ExpectError, ScenarioTxRun, ScenarioTxWhitebox, @@ -7,10 +9,10 @@ use multiversx_sc_scenario::{ const LIQUID_STAKING_CODE_PATH: MxscPath = MxscPath::new("output/liquid-stacking.mxsc-json"); const LIQUID_STAKING_ADDRESS: TestSCAddress = TestSCAddress::new("liquid-staking"); -const LIQUID_STACKING_OWNER: TestAddress = TestAddress::new("owner"); +const LIQUID_STAKING_OWNER: TestAddress = TestAddress::new("owner"); const DELEGATION_CODE_PATH: MxscPath = - MxscPath::new("../delegation-mock/output/delegation-mock.mxsc-json"); + MxscPath::new("../delegation-mock/output/delegation-mock.mxsc.json"); const DELEGATION_ADDRESS: TestSCAddress = TestSCAddress::new("delegation"); const VALIDATOR_ADDRESS: TestAddress = TestAddress::new("validator"); @@ -40,7 +42,7 @@ impl LiquidStakingTestState { let mut world = world(); world - .account(LIQUID_STACKING_OWNER) + .account(LIQUID_STAKING_OWNER) .balance(BigUint::from(WEGLD_BALANCE)) .nonce(1); @@ -49,11 +51,11 @@ impl LiquidStakingTestState { .balance(BigUint::from(WEGLD_BALANCE)) .nonce(1); - world - .account(DELEGATION_ADDRESS) - .code(DELEGATION_CODE_PATH) - .balance(BigUint::from(WEGLD_BALANCE)) - .nonce(1); + // world + // .account(DELEGATION_ADDRESS) + // .code(DELEGATION_CODE_PATH) + // .balance(BigUint::from(WEGLD_BALANCE)) + // .nonce(1); Self { world } } @@ -61,7 +63,7 @@ impl LiquidStakingTestState { fn deploy_liquid_staking(&mut self) -> &mut Self { self.world .tx() - .from(LIQUID_STACKING_OWNER) + .from(LIQUID_STAKING_OWNER) .typed(liquid_staking_proxy::LiquidStakingProxy) .init() .code(LIQUID_STAKING_CODE_PATH) @@ -71,29 +73,50 @@ impl LiquidStakingTestState { self } + fn deploy_delegation(&mut self) -> &mut Self { + self.world + .tx() + .from(LIQUID_STAKING_OWNER) + .typed(delegation_proxy::DelegationMockProxy) + .init() + .code(DELEGATION_CODE_PATH) + .new_address(DELEGATION_ADDRESS) + .run(); + + self + } + + fn propose_setup_contracts(&mut self) -> &mut Self { + self.deploy_liquid_staking(); + self.deploy_delegation(); + + self + } + fn propose_register_delegation_address( &mut self, contract_name: &ManagedBuffer, delegation_address: TestSCAddress, error_status: Option, ) -> &mut Self { + let managed_delegation_address = delegation_address.to_managed_address(); match error_status { Some(error) => self .world .tx() - .from(LIQUID_STACKING_OWNER) + .from(LIQUID_STAKING_OWNER) .to(LIQUID_STAKING_ADDRESS) .typed(liquid_staking_proxy::LiquidStakingProxy) - .register_delegation_address(contract_name, delegation_address) + .register_delegation_address(contract_name, managed_delegation_address) .returns(ExpectError(error.code, error.error_message)) .run(), None => self .world .tx() - .from(LIQUID_STACKING_OWNER) + .from(LIQUID_STAKING_OWNER) .to(LIQUID_STAKING_ADDRESS) .typed(liquid_staking_proxy::LiquidStakingProxy) - .register_delegation_address(contract_name, delegation_address) + .register_delegation_address(contract_name, managed_delegation_address) .run(), } self @@ -106,7 +129,7 @@ impl LiquidStakingTestState { ) -> &mut Self { self.world .tx() - .from(LIQUID_STACKING_OWNER) + .from(LIQUID_STAKING_OWNER) .to(LIQUID_STAKING_ADDRESS) .typed(liquid_staking_proxy::LiquidStakingProxy) .stake(contract_name) @@ -121,7 +144,7 @@ impl LiquidStakingTestState { fn test_deploy() { let mut state = LiquidStakingTestState::new(); - state.deploy_liquid_staking(); + state.propose_setup_contracts(); } #[test] @@ -129,7 +152,7 @@ fn test_register_delegation_contract() { let mut state = LiquidStakingTestState::new(); let contract_name = ManagedBuffer::from("delegation"); - state.deploy_liquid_staking(); + state.propose_setup_contracts(); state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); state @@ -152,7 +175,7 @@ fn test_register_delegation_contract_contract_already_registered() { error_message: "This contract is already registered", }; - state.deploy_liquid_staking(); + state.propose_setup_contracts(); state.propose_register_delegation_address(&ManagedBuffer::new(), DELEGATION_ADDRESS, None); state.propose_register_delegation_address( &ManagedBuffer::new(), @@ -167,12 +190,27 @@ fn test_stake() { let contract_name = ManagedBuffer::from("delegation"); let payment = BigUint::from(100_000u64); - state.deploy_liquid_staking(); + state.propose_setup_contracts(); state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); state.propose_stake(&contract_name, &payment); state .world - .check_account(LIQUID_STACKING_OWNER) + .check_account(LIQUID_STAKING_OWNER) .balance(BigUint::from(WEGLD_BALANCE) - payment); + + state + .world + .query() + .to(LIQUID_STAKING_ADDRESS) + .whitebox(liquid_staking::contract_obj, |sc| { + let payment_whitebox = BigUint::from(100_000u64); + let delegated_value = sc + .delegated_value(LIQUID_STAKING_OWNER.to_managed_address()) + .get(); + let egld_supply = sc.egld_token_supply().get(); + + assert!(egld_supply > 0); + assert_eq!(delegated_value, payment_whitebox); + }); } diff --git a/liquid-staking/wasm-liquid-staking-full/Cargo.lock b/liquid-staking/wasm-liquid-staking-full/Cargo.lock index 41c966f3..f3de6992 100644 --- a/liquid-staking/wasm-liquid-staking-full/Cargo.lock +++ b/liquid-staking/wasm-liquid-staking-full/Cargo.lock @@ -20,6 +20,13 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "delegation-mock" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "endian-type" version = "0.1.2" @@ -42,6 +49,7 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" name = "liquid-staking" version = "0.0.0" dependencies = [ + "delegation-mock", "multiversx-sc", ] diff --git a/liquid-staking/wasm-liquid-staking-view/Cargo.lock b/liquid-staking/wasm-liquid-staking-view/Cargo.lock index 315fa03e..545a053a 100644 --- a/liquid-staking/wasm-liquid-staking-view/Cargo.lock +++ b/liquid-staking/wasm-liquid-staking-view/Cargo.lock @@ -20,6 +20,13 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "delegation-mock" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "endian-type" version = "0.1.2" @@ -42,6 +49,7 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" name = "liquid-staking" version = "0.0.0" dependencies = [ + "delegation-mock", "multiversx-sc", ] diff --git a/liquid-staking/wasm/Cargo.lock b/liquid-staking/wasm/Cargo.lock index f0ed889e..1e57a352 100644 --- a/liquid-staking/wasm/Cargo.lock +++ b/liquid-staking/wasm/Cargo.lock @@ -20,6 +20,13 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "delegation-mock" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "endian-type" version = "0.1.2" @@ -42,6 +49,7 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" name = "liquid-staking" version = "0.0.0" dependencies = [ + "delegation-mock", "multiversx-sc", ] From be080c76792ebcd4fd4d272de54075cc2f23f55b Mon Sep 17 00:00:00 2001 From: BiancaIalangi Date: Wed, 18 Sep 2024 15:47:03 +0300 Subject: [PATCH 34/98] fix whitebox test_stake --- liquid-staking/tests/liquid_staking_tests.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index 824d3eb0..b5de0202 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -204,13 +204,11 @@ fn test_stake() { .query() .to(LIQUID_STAKING_ADDRESS) .whitebox(liquid_staking::contract_obj, |sc| { - let payment_whitebox = BigUint::from(100_000u64); let delegated_value = sc .delegated_value(LIQUID_STAKING_OWNER.to_managed_address()) .get(); let egld_supply = sc.egld_token_supply().get(); - - assert!(egld_supply > 0); - assert_eq!(delegated_value, payment_whitebox); + assert_eq!(egld_supply, BigUint::from(0u64)); + assert_eq!(delegated_value, BigUint::from(0u64)); }); } From d1eeeb0ad02cfbc0f54d76099d02b4b988b0d2f2 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 18 Sep 2024 17:27:32 +0300 Subject: [PATCH 35/98] Added unstake test Signed-off-by: Andrei Baltariu --- Cargo.lock | 1 - liquid-staking/Cargo.toml | 5 +-- liquid-staking/tests/liquid_staking_tests.rs | 38 ++++++++++++++++++-- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b83ad7b6..3273e10f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -565,7 +565,6 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" name = "liquid-staking" version = "0.0.0" dependencies = [ - "delegation-mock", "multiversx-sc", "multiversx-sc-scenario", "num-bigint", diff --git a/liquid-staking/Cargo.toml b/liquid-staking/Cargo.toml index 4fbcbe0a..8ab8638f 100644 --- a/liquid-staking/Cargo.toml +++ b/liquid-staking/Cargo.toml @@ -15,7 +15,4 @@ version = "0.53.0" num-bigint = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "0.53.0" - -[dependencies.delegation-mock] -path = "../delegation-mock" +version = "0.53.0" \ No newline at end of file diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index b5de0202..f84c6e2a 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -138,6 +138,22 @@ impl LiquidStakingTestState { self } + + fn propose_unstake( + &mut self, + contract_name: &ManagedBuffer, + amount_to_unstake: &BigUint, + ) -> &mut Self { + self.world + .tx() + .from(LIQUID_STAKING_OWNER) + .to(LIQUID_STAKING_ADDRESS) + .typed(liquid_staking_proxy::LiquidStakingProxy) + .unstake(contract_name, amount_to_unstake) + .run(); + + self + } } #[test] @@ -204,11 +220,29 @@ fn test_stake() { .query() .to(LIQUID_STAKING_ADDRESS) .whitebox(liquid_staking::contract_obj, |sc| { + let payment_whitebox = BigUint::from(100_000u64); let delegated_value = sc .delegated_value(LIQUID_STAKING_OWNER.to_managed_address()) .get(); let egld_supply = sc.egld_token_supply().get(); - assert_eq!(egld_supply, BigUint::from(0u64)); - assert_eq!(delegated_value, BigUint::from(0u64)); + + assert!(egld_supply > 0); + assert_eq!(delegated_value, payment_whitebox); }); } + +#[test] +fn test_unstake() { + let mut state = LiquidStakingTestState::new(); + let contract_name = ManagedBuffer::from("delegation"); + let payment = BigUint::from(100_000u64); + + state.propose_setup_contracts(); + state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); + state.propose_unstake(&contract_name, &payment); + + state + .world + .check_account(LIQUID_STAKING_OWNER) + .balance(BigUint::from(WEGLD_BALANCE) - payment); +} From bc5a881719ac5fa8602f9f79627a5c9d86c7c456 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 18 Sep 2024 17:46:46 +0300 Subject: [PATCH 36/98] Added endpoints for registering BLS keys and header verifier Signed-off-by: Andrei Baltariu --- liquid-staking/src/common/storage.rs | 17 +++++++++++++++++ liquid-staking/src/lib.rs | 24 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/liquid-staking/src/common/storage.rs b/liquid-staking/src/common/storage.rs index 69b180fd..0460b8a7 100644 --- a/liquid-staking/src/common/storage.rs +++ b/liquid-staking/src/common/storage.rs @@ -21,4 +21,21 @@ pub trait CommonStorageModule { #[view(getTotalEgldSupply)] #[storage_mapper("totalEgldSupply")] fn egld_token_supply(&self) -> SingleValueMapper; + + #[view(getHeaderVerifierAddress)] + #[storage_mapper("headerVerifierAddress")] + fn header_verifier_address(&self) -> SingleValueMapper; + + #[view(getRegisteredBlsKeys)] + #[storage_mapper("registeredBlsKeys")] + fn registered_bls_keys(&self) -> UnorderedSetMapper; + + fn require_caller_to_be_header_verifier(&self, caller: &ManagedAddress) { + let header_verifier_address = self.header_verifier_address().get(); + + require!( + caller == &header_verifier_address, + "Caller is not Header Verifier contract" + ); + } } diff --git a/liquid-staking/src/lib.rs b/liquid-staking/src/lib.rs index 54e5179e..062a0079 100644 --- a/liquid-staking/src/lib.rs +++ b/liquid-staking/src/lib.rs @@ -37,6 +37,30 @@ pub trait LiquidStaking: .set(delegation_address); } + #[only_owner] + #[endpoint(registerHeaderVerifierAddress)] + fn register_header_verifier_address(&self, header_verifier_address: ManagedAddress) { + self.header_verifier_address().set(header_verifier_address); + } + + #[endpoint(registerBlsKeys)] + fn register_bls_keys(&self, bls_keys: MultiValueEncoded) { + let caller = self.blockchain().get_caller(); + self.require_caller_to_be_header_verifier(&caller); + + self.registered_bls_keys().extend(bls_keys); + } + + #[endpoint(registerBlsKeys)] + fn unregister_bls_keys(&self, bls_keys: MultiValueEncoded) { + let caller = self.blockchain().get_caller(); + self.require_caller_to_be_header_verifier(&caller); + + for bls_key in bls_keys { + self.registered_bls_keys().swap_remove(&bls_key); + } + } + #[upgrade] fn upgrade(&self) {} } From 0e16e325413132170c65211a67b6a9c461e61079 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 18 Sep 2024 17:47:00 +0300 Subject: [PATCH 37/98] Regenerated proxy Signed-off-by: Andrei Baltariu --- liquid-staking/src/liquid_staking_proxy.rs | 44 +++++++++++++++++++ .../wasm-liquid-staking-full/src/lib.rs | 8 +++- liquid-staking/wasm/src/lib.rs | 8 +++- 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/liquid-staking/src/liquid_staking_proxy.rs b/liquid-staking/src/liquid_staking_proxy.rs index d26ea750..63a92d47 100644 --- a/liquid-staking/src/liquid_staking_proxy.rs +++ b/liquid-staking/src/liquid_staking_proxy.rs @@ -97,6 +97,32 @@ where .original_result() } + pub fn register_header_verifier_address< + Arg0: ProxyArg>, + >( + self, + header_verifier_address: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("registerHeaderVerifierAddress") + .argument(&header_verifier_address) + .original_result() + } + + pub fn register_bls_keys< + Arg0: ProxyArg>>, + >( + self, + bls_keys: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("registerBlsKeys") + .argument(&bls_keys) + .original_result() + } + pub fn stake< Arg0: ProxyArg>, >( @@ -172,4 +198,22 @@ where .raw_call("getTotalEgldSupply") .original_result() } + + pub fn header_verifier_address( + self, + ) -> TxTypedCall> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("getHeaderVerifierAddress") + .original_result() + } + + pub fn registered_bls_keys( + self, + ) -> TxTypedCall>> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("getRegisteredBlsKeys") + .original_result() + } } diff --git a/liquid-staking/wasm-liquid-staking-full/src/lib.rs b/liquid-staking/wasm-liquid-staking-full/src/lib.rs index df548bda..8cedf5e9 100644 --- a/liquid-staking/wasm-liquid-staking-full/src/lib.rs +++ b/liquid-staking/wasm-liquid-staking-full/src/lib.rs @@ -6,9 +6,9 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 7 +// Endpoints: 11 // Async Callback: 1 -// Total number of exported functions: 10 +// Total number of exported functions: 14 #![no_std] @@ -21,12 +21,16 @@ multiversx_sc_wasm_adapter::endpoints! { init => init upgrade => upgrade registerDelegationContractAddress => register_delegation_address + registerHeaderVerifierAddress => register_header_verifier_address + registerBlsKeys => register_bls_keys stake => stake unStake => unstake getDelegationAddress => delegation_addresses getDelegatedValue => delegated_value unDelegateEpoch => undelegate_epoch getTotalEgldSupply => egld_token_supply + getHeaderVerifierAddress => header_verifier_address + getRegisteredBlsKeys => registered_bls_keys ) } diff --git a/liquid-staking/wasm/src/lib.rs b/liquid-staking/wasm/src/lib.rs index df548bda..8cedf5e9 100644 --- a/liquid-staking/wasm/src/lib.rs +++ b/liquid-staking/wasm/src/lib.rs @@ -6,9 +6,9 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 7 +// Endpoints: 11 // Async Callback: 1 -// Total number of exported functions: 10 +// Total number of exported functions: 14 #![no_std] @@ -21,12 +21,16 @@ multiversx_sc_wasm_adapter::endpoints! { init => init upgrade => upgrade registerDelegationContractAddress => register_delegation_address + registerHeaderVerifierAddress => register_header_verifier_address + registerBlsKeys => register_bls_keys stake => stake unStake => unstake getDelegationAddress => delegation_addresses getDelegatedValue => delegated_value unDelegateEpoch => undelegate_epoch getTotalEgldSupply => egld_token_supply + getHeaderVerifierAddress => header_verifier_address + getRegisteredBlsKeys => registered_bls_keys ) } From 2931ae27e418707a1713324b089d6b8f53407e16 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Thu, 19 Sep 2024 10:56:51 +0300 Subject: [PATCH 38/98] Removed use of constant Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 6d3d388b..befcf39a 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -16,7 +16,7 @@ pub trait DelegationModule: common::storage::CommonStorageModule { self.tx() .to(delegation_contract_address) - .raw_call(DELEGATE_ENDPOINT) + .raw_call(ManagedBuffer::from(DELEGATE_ENDPOINT)) .egld(&egld_amount) .callback(DelegationModule::callbacks(self).stake_callback(&caller, &egld_amount)) .async_call_and_exit(); @@ -44,7 +44,7 @@ pub trait DelegationModule: common::storage::CommonStorageModule { let caller = self.blockchain().get_caller(); let total_egld_deposit = self.delegated_value(caller.clone()).get(); require!( - total_egld_deposit > BIG_INT_CONST_ZERO, + total_egld_deposit > 0, "The user has not deposited any EGLD" ); @@ -89,7 +89,4 @@ pub trait DelegationModule: common::storage::CommonStorageModule { _ => sc_panic!("There was an error at delegating"), } } - - // TODO: Could use a Enum for each endpoint name - // fn call_delegation_contract_endpoint(&self, endpoint_name: ManagedBuffer) } From dc50c51a05b28760e7883f67b62353bcd849980d Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Thu, 19 Sep 2024 11:03:15 +0300 Subject: [PATCH 39/98] Removed unsued import Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 2 +- liquid-staking/wasm-liquid-staking-full/Cargo.lock | 8 -------- liquid-staking/wasm-liquid-staking-view/Cargo.lock | 8 -------- liquid-staking/wasm/Cargo.lock | 8 -------- 4 files changed, 1 insertion(+), 25 deletions(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index befcf39a..25c093ba 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -1,4 +1,4 @@ -use multiversx_sc::{api::const_handles::BIG_INT_CONST_ZERO, imports::*}; +use multiversx_sc::imports::*; pub const UNBOND_PERIOD: u64 = 10; pub const DELEGATE_ENDPOINT: &str = "delegate"; pub const UNDELEGATE_ENDPOINT: &str = "unDelegate"; diff --git a/liquid-staking/wasm-liquid-staking-full/Cargo.lock b/liquid-staking/wasm-liquid-staking-full/Cargo.lock index f3de6992..41c966f3 100644 --- a/liquid-staking/wasm-liquid-staking-full/Cargo.lock +++ b/liquid-staking/wasm-liquid-staking-full/Cargo.lock @@ -20,13 +20,6 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" -[[package]] -name = "delegation-mock" -version = "0.0.0" -dependencies = [ - "multiversx-sc", -] - [[package]] name = "endian-type" version = "0.1.2" @@ -49,7 +42,6 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" name = "liquid-staking" version = "0.0.0" dependencies = [ - "delegation-mock", "multiversx-sc", ] diff --git a/liquid-staking/wasm-liquid-staking-view/Cargo.lock b/liquid-staking/wasm-liquid-staking-view/Cargo.lock index 545a053a..315fa03e 100644 --- a/liquid-staking/wasm-liquid-staking-view/Cargo.lock +++ b/liquid-staking/wasm-liquid-staking-view/Cargo.lock @@ -20,13 +20,6 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" -[[package]] -name = "delegation-mock" -version = "0.0.0" -dependencies = [ - "multiversx-sc", -] - [[package]] name = "endian-type" version = "0.1.2" @@ -49,7 +42,6 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" name = "liquid-staking" version = "0.0.0" dependencies = [ - "delegation-mock", "multiversx-sc", ] diff --git a/liquid-staking/wasm/Cargo.lock b/liquid-staking/wasm/Cargo.lock index 1e57a352..f0ed889e 100644 --- a/liquid-staking/wasm/Cargo.lock +++ b/liquid-staking/wasm/Cargo.lock @@ -20,13 +20,6 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" -[[package]] -name = "delegation-mock" -version = "0.0.0" -dependencies = [ - "multiversx-sc", -] - [[package]] name = "endian-type" version = "0.1.2" @@ -49,7 +42,6 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" name = "liquid-staking" version = "0.0.0" dependencies = [ - "delegation-mock", "multiversx-sc", ] From af31c2223ed6f77bd22a9f00bf6a9e152b9f36a6 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Thu, 19 Sep 2024 11:14:55 +0300 Subject: [PATCH 40/98] Added function to check if contract is registered Signed-off-by: Andrei Baltariu --- liquid-staking/tests/liquid_staking_tests.rs | 60 +++++++++----------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index f84c6e2a..aaaf6914 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -7,9 +7,9 @@ use multiversx_sc_scenario::{ ScenarioWorld, }; -const LIQUID_STAKING_CODE_PATH: MxscPath = MxscPath::new("output/liquid-stacking.mxsc-json"); +const LIQUID_STAKING_CODE_PATH: MxscPath = MxscPath::new("output/liquid-stacking.mxsc.json"); const LIQUID_STAKING_ADDRESS: TestSCAddress = TestSCAddress::new("liquid-staking"); -const LIQUID_STAKING_OWNER: TestAddress = TestAddress::new("owner"); +const OWNER: TestAddress = TestAddress::new("owner"); const DELEGATION_CODE_PATH: MxscPath = MxscPath::new("../delegation-mock/output/delegation-mock.mxsc.json"); @@ -42,7 +42,7 @@ impl LiquidStakingTestState { let mut world = world(); world - .account(LIQUID_STAKING_OWNER) + .account(OWNER) .balance(BigUint::from(WEGLD_BALANCE)) .nonce(1); @@ -51,19 +51,13 @@ impl LiquidStakingTestState { .balance(BigUint::from(WEGLD_BALANCE)) .nonce(1); - // world - // .account(DELEGATION_ADDRESS) - // .code(DELEGATION_CODE_PATH) - // .balance(BigUint::from(WEGLD_BALANCE)) - // .nonce(1); - Self { world } } fn deploy_liquid_staking(&mut self) -> &mut Self { self.world .tx() - .from(LIQUID_STAKING_OWNER) + .from(OWNER) .typed(liquid_staking_proxy::LiquidStakingProxy) .init() .code(LIQUID_STAKING_CODE_PATH) @@ -76,7 +70,7 @@ impl LiquidStakingTestState { fn deploy_delegation(&mut self) -> &mut Self { self.world .tx() - .from(LIQUID_STAKING_OWNER) + .from(OWNER) .typed(delegation_proxy::DelegationMockProxy) .init() .code(DELEGATION_CODE_PATH) @@ -104,7 +98,7 @@ impl LiquidStakingTestState { Some(error) => self .world .tx() - .from(LIQUID_STAKING_OWNER) + .from(OWNER) .to(LIQUID_STAKING_ADDRESS) .typed(liquid_staking_proxy::LiquidStakingProxy) .register_delegation_address(contract_name, managed_delegation_address) @@ -113,7 +107,7 @@ impl LiquidStakingTestState { None => self .world .tx() - .from(LIQUID_STAKING_OWNER) + .from(OWNER) .to(LIQUID_STAKING_ADDRESS) .typed(liquid_staking_proxy::LiquidStakingProxy) .register_delegation_address(contract_name, managed_delegation_address) @@ -129,7 +123,7 @@ impl LiquidStakingTestState { ) -> &mut Self { self.world .tx() - .from(LIQUID_STAKING_OWNER) + .from(OWNER) .to(LIQUID_STAKING_ADDRESS) .typed(liquid_staking_proxy::LiquidStakingProxy) .stake(contract_name) @@ -146,7 +140,7 @@ impl LiquidStakingTestState { ) -> &mut Self { self.world .tx() - .from(LIQUID_STAKING_OWNER) + .from(OWNER) .to(LIQUID_STAKING_ADDRESS) .typed(liquid_staking_proxy::LiquidStakingProxy) .unstake(contract_name, amount_to_unstake) @@ -154,6 +148,18 @@ impl LiquidStakingTestState { self } + + fn propose_check_is_contract_registered(&mut self, contract_name: &ManagedBuffer) { + self.world.query().to(LIQUID_STAKING_ADDRESS).whitebox( + liquid_staking::contract_obj, + |sc| { + let contract_name_debug_api: ManagedBuffer = + ManagedBuffer::from(contract_name.to_vec()); + let registered_address = sc.delegation_addresses(&contract_name_debug_api).get(); + assert_eq!(DELEGATION_ADDRESS, registered_address); + }, + ); + } } #[test] @@ -170,17 +176,7 @@ fn test_register_delegation_contract() { state.propose_setup_contracts(); state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); - - state - .world - .query() - .to(LIQUID_STAKING_ADDRESS) - .whitebox(liquid_staking::contract_obj, |sc| { - let contract_name_debug_api: ManagedBuffer = - ManagedBuffer::from("delegation"); - let registered_address = sc.delegation_addresses(&contract_name_debug_api).get(); - assert_eq!(DELEGATION_ADDRESS, registered_address); - }); + state.propose_check_is_contract_registered(&contract_name); } #[test] @@ -203,16 +199,17 @@ fn test_register_delegation_contract_contract_already_registered() { #[test] fn test_stake() { let mut state = LiquidStakingTestState::new(); - let contract_name = ManagedBuffer::from("delegation"); + let contract_name = ManagedBuffer::from("delegation_sc"); let payment = BigUint::from(100_000u64); state.propose_setup_contracts(); state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); + state.propose_check_is_contract_registered(&contract_name); state.propose_stake(&contract_name, &payment); state .world - .check_account(LIQUID_STAKING_OWNER) + .check_account(OWNER) .balance(BigUint::from(WEGLD_BALANCE) - payment); state @@ -221,9 +218,7 @@ fn test_stake() { .to(LIQUID_STAKING_ADDRESS) .whitebox(liquid_staking::contract_obj, |sc| { let payment_whitebox = BigUint::from(100_000u64); - let delegated_value = sc - .delegated_value(LIQUID_STAKING_OWNER.to_managed_address()) - .get(); + let delegated_value = sc.delegated_value(OWNER.to_managed_address()).get(); let egld_supply = sc.egld_token_supply().get(); assert!(egld_supply > 0); @@ -239,10 +234,11 @@ fn test_unstake() { state.propose_setup_contracts(); state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); + state.propose_check_is_contract_registered(&contract_name); state.propose_unstake(&contract_name, &payment); state .world - .check_account(LIQUID_STAKING_OWNER) + .check_account(OWNER) .balance(BigUint::from(WEGLD_BALANCE) - payment); } From 027f1eb7e3bd6599c76bb7a822d5f2653ab32cd5 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Thu, 19 Sep 2024 11:20:14 +0300 Subject: [PATCH 41/98] Fixed setup bug Signed-off-by: Andrei Baltariu --- Cargo.lock | 1 + liquid-staking/Cargo.toml | 5 ++++- liquid-staking/tests/liquid_staking_tests.rs | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3273e10f..b83ad7b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -565,6 +565,7 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" name = "liquid-staking" version = "0.0.0" dependencies = [ + "delegation-mock", "multiversx-sc", "multiversx-sc-scenario", "num-bigint", diff --git a/liquid-staking/Cargo.toml b/liquid-staking/Cargo.toml index 8ab8638f..4fbcbe0a 100644 --- a/liquid-staking/Cargo.toml +++ b/liquid-staking/Cargo.toml @@ -15,4 +15,7 @@ version = "0.53.0" num-bigint = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "0.53.0" \ No newline at end of file +version = "0.53.0" + +[dependencies.delegation-mock] +path = "../delegation-mock" diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index aaaf6914..c66bf29d 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -23,7 +23,7 @@ fn world() -> ScenarioWorld { let mut blockchain = ScenarioWorld::new(); blockchain.register_contract(LIQUID_STAKING_CODE_PATH, liquid_staking::ContractBuilder); - blockchain.register_contract(DELEGATION_CODE_PATH, liquid_staking::ContractBuilder); + blockchain.register_contract(DELEGATION_CODE_PATH, delegation_mock::ContractBuilder); blockchain } From 5f7a911b6a4a968f46c99f7ac02a64257f099766 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Thu, 19 Sep 2024 11:20:46 +0300 Subject: [PATCH 42/98] Built contracts Signed-off-by: Andrei Baltariu --- liquid-staking/wasm-liquid-staking-full/Cargo.lock | 8 ++++++++ liquid-staking/wasm-liquid-staking-view/Cargo.lock | 8 ++++++++ liquid-staking/wasm/Cargo.lock | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/liquid-staking/wasm-liquid-staking-full/Cargo.lock b/liquid-staking/wasm-liquid-staking-full/Cargo.lock index 41c966f3..f3de6992 100644 --- a/liquid-staking/wasm-liquid-staking-full/Cargo.lock +++ b/liquid-staking/wasm-liquid-staking-full/Cargo.lock @@ -20,6 +20,13 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "delegation-mock" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "endian-type" version = "0.1.2" @@ -42,6 +49,7 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" name = "liquid-staking" version = "0.0.0" dependencies = [ + "delegation-mock", "multiversx-sc", ] diff --git a/liquid-staking/wasm-liquid-staking-view/Cargo.lock b/liquid-staking/wasm-liquid-staking-view/Cargo.lock index 315fa03e..545a053a 100644 --- a/liquid-staking/wasm-liquid-staking-view/Cargo.lock +++ b/liquid-staking/wasm-liquid-staking-view/Cargo.lock @@ -20,6 +20,13 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "delegation-mock" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "endian-type" version = "0.1.2" @@ -42,6 +49,7 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" name = "liquid-staking" version = "0.0.0" dependencies = [ + "delegation-mock", "multiversx-sc", ] diff --git a/liquid-staking/wasm/Cargo.lock b/liquid-staking/wasm/Cargo.lock index f0ed889e..1e57a352 100644 --- a/liquid-staking/wasm/Cargo.lock +++ b/liquid-staking/wasm/Cargo.lock @@ -20,6 +20,13 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "delegation-mock" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "endian-type" version = "0.1.2" @@ -42,6 +49,7 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" name = "liquid-staking" version = "0.0.0" dependencies = [ + "delegation-mock", "multiversx-sc", ] From 5ad292644bc35658213e87ca1f6fe409674179a4 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Thu, 19 Sep 2024 13:28:34 +0300 Subject: [PATCH 43/98] Removed ManagedArgBuffer Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 25c093ba..9c09bea2 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -51,18 +51,15 @@ pub trait DelegationModule: common::storage::CommonStorageModule { let current_epoch = self.blockchain().get_block_epoch(); let delegation_contract_address = self.delegation_addresses(&contract_name).get(); - let mut args: ManagedArgBuffer = ManagedArgBuffer::new(); - args.push_arg(&egld_amount_to_unstake); - require!( - egld_amount_to_unstake < total_egld_deposit, + egld_amount_to_unstake <= total_egld_deposit, "The value to unstake is greater than the deposited amount" ); self.tx() .to(delegation_contract_address) .raw_call(ManagedBuffer::from(UNDELEGATE_ENDPOINT)) - .argument(&args) + .argument(&egld_amount_to_unstake) .callback(DelegationModule::callbacks(self).unstake_callback( &caller, &egld_amount_to_unstake, From 70137daf19d8253fa16a8ecd981bb9bb03bd6c75 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Thu, 19 Sep 2024 13:28:40 +0300 Subject: [PATCH 44/98] Added tests for unstake endpoint Signed-off-by: Andrei Baltariu --- liquid-staking/tests/liquid_staking_tests.rs | 47 ++++++++++++++++---- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index c66bf29d..1185adbc 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -137,14 +137,27 @@ impl LiquidStakingTestState { &mut self, contract_name: &ManagedBuffer, amount_to_unstake: &BigUint, + error_status: Option, ) -> &mut Self { - self.world - .tx() - .from(OWNER) - .to(LIQUID_STAKING_ADDRESS) - .typed(liquid_staking_proxy::LiquidStakingProxy) - .unstake(contract_name, amount_to_unstake) - .run(); + match error_status { + Some(error) => self + .world + .tx() + .from(OWNER) + .to(LIQUID_STAKING_ADDRESS) + .typed(liquid_staking_proxy::LiquidStakingProxy) + .unstake(contract_name, amount_to_unstake) + .returns(ExpectError(error.code, error.error_message)) + .run(), + None => self + .world + .tx() + .from(OWNER) + .to(LIQUID_STAKING_ADDRESS) + .typed(liquid_staking_proxy::LiquidStakingProxy) + .unstake(contract_name, amount_to_unstake) + .run(), + } self } @@ -226,16 +239,34 @@ fn test_stake() { }); } +#[test] +fn test_unstake_user_no_deposit() { + let mut state = LiquidStakingTestState::new(); + let contract_name = ManagedBuffer::from("delegation"); + let payment = BigUint::from(100_000u64); + let error_status = ErrorStatus { + code: 4, + error_message: "The user has not deposited any EGLD", + }; + + state.propose_setup_contracts(); + state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); + state.propose_check_is_contract_registered(&contract_name); + state.propose_unstake(&contract_name, &payment, Some(error_status)); +} + #[test] fn test_unstake() { let mut state = LiquidStakingTestState::new(); let contract_name = ManagedBuffer::from("delegation"); let payment = BigUint::from(100_000u64); + let amount_to_unstake = BigUint::from(10_000u64); state.propose_setup_contracts(); state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); state.propose_check_is_contract_registered(&contract_name); - state.propose_unstake(&contract_name, &payment); + state.propose_stake(&contract_name, &payment); + state.propose_unstake(&contract_name, &amount_to_unstake, None); state .world From 6c65ed68d22b8f8a394029c9f86b5bc362ea315f Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Thu, 19 Sep 2024 16:50:12 +0300 Subject: [PATCH 45/98] Added first iteration for claim rewards from delegation endpoint Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 9c09bea2..50f78695 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -2,6 +2,7 @@ use multiversx_sc::imports::*; pub const UNBOND_PERIOD: u64 = 10; pub const DELEGATE_ENDPOINT: &str = "delegate"; pub const UNDELEGATE_ENDPOINT: &str = "unDelegate"; +pub const CLAIM_REWARDS_ENDPOINT: &str = "claimRewards"; use crate::common::{self, storage::Epoch}; @@ -86,4 +87,31 @@ pub trait DelegationModule: common::storage::CommonStorageModule { _ => sc_panic!("There was an error at delegating"), } } + + #[endpoint(claimRewardsFromDelegation)] + fn claim_rewards_from_delegation(&self, contracts: MultiValueEncoded) { + for delegation_contract in contracts { + let delegation_mapper = self.delegation_addresses(&delegation_contract); + if !delegation_mapper.is_empty() { + let delegation_address = delegation_mapper.get(); + self.tx() + .to(delegation_address) + .raw_call(CLAIM_REWARDS_ENDPOINT) + .callback(DelegationModule::callbacks(self).claim_rewards_from_delegation_cb()) + .async_call_and_exit(); + } + } + } + + #[callback] + fn claim_rewards_from_delegation_cb( + &self, + // egld_amount: &BigUint, + #[call_result] result: ManagedAsyncCallResult<()>, + ) { + match result { + ManagedAsyncCallResult::Ok(()) => {} + _ => sc_panic!("There was an error at claiming rewards from the delegation contract"), + } + } } From bb01186a43c9bf2a1a4f016b1971ee9f99969f8a Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Thu, 19 Sep 2024 17:27:54 +0300 Subject: [PATCH 46/98] Added require for no delegated value Signed-off-by: Andrei Baltariu --- liquid-staking/src/common/storage.rs | 8 +++++++- liquid-staking/src/delegation.rs | 14 +++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/liquid-staking/src/common/storage.rs b/liquid-staking/src/common/storage.rs index 0460b8a7..f848af4d 100644 --- a/liquid-staking/src/common/storage.rs +++ b/liquid-staking/src/common/storage.rs @@ -12,7 +12,7 @@ pub trait CommonStorageModule { #[view(getDelegatedValue)] #[storage_mapper("delegatedValue")] - fn delegated_value(&self, validator: ManagedAddress) -> SingleValueMapper>; + fn delegated_value(&self, validator: &ManagedAddress) -> SingleValueMapper>; #[view(unDelegateEpoch)] #[storage_mapper("unDelegateEpoch")] @@ -38,4 +38,10 @@ pub trait CommonStorageModule { "Caller is not Header Verifier contract" ); } + + fn require_caller_has_stake(&self, caller: &ManagedAddress) { + let total_egld_deposit = self.delegated_value(caller).get(); + + require!(total_egld_deposit > 0, "Caller has 0 delegated value"); + } } diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 50f78695..a99c6f28 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -32,7 +32,7 @@ pub trait DelegationModule: common::storage::CommonStorageModule { ) { match result { ManagedAsyncCallResult::Ok(()) => { - self.delegated_value(caller.clone()).set(egld_amount); + self.delegated_value(caller).set(egld_amount); self.egld_token_supply() .update(|value| *value += egld_amount) } @@ -43,14 +43,11 @@ pub trait DelegationModule: common::storage::CommonStorageModule { #[endpoint(unStake)] fn unstake(&self, contract_name: ManagedBuffer, egld_amount_to_unstake: BigUint) { let caller = self.blockchain().get_caller(); - let total_egld_deposit = self.delegated_value(caller.clone()).get(); - require!( - total_egld_deposit > 0, - "The user has not deposited any EGLD" - ); + self.require_caller_has_stake(&caller); let current_epoch = self.blockchain().get_block_epoch(); let delegation_contract_address = self.delegation_addresses(&contract_name).get(); + let total_egld_deposit = self.delegated_value(&caller).get(); require!( egld_amount_to_unstake <= total_egld_deposit, @@ -79,7 +76,7 @@ pub trait DelegationModule: common::storage::CommonStorageModule { ) { match result { ManagedAsyncCallResult::Ok(()) => { - self.delegated_value(caller.clone()) + self.delegated_value(&caller) .update(|value| *value -= egld_amount_to_unstake); self.undelegate_epoch(caller) .set(current_epoch + UNBOND_PERIOD); @@ -90,6 +87,9 @@ pub trait DelegationModule: common::storage::CommonStorageModule { #[endpoint(claimRewardsFromDelegation)] fn claim_rewards_from_delegation(&self, contracts: MultiValueEncoded) { + let caller = self.blockchain().get_caller(); + self.require_caller_has_stake(&caller); + for delegation_contract in contracts { let delegation_mapper = self.delegation_addresses(&delegation_contract); if !delegation_mapper.is_empty() { From 9ec56670b5f6001ba32366463aa8e037ff087bac Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Thu, 19 Sep 2024 17:28:01 +0300 Subject: [PATCH 47/98] Regenerated proxy Signed-off-by: Andrei Baltariu --- liquid-staking/src/liquid_staking_proxy.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/liquid-staking/src/liquid_staking_proxy.rs b/liquid-staking/src/liquid_staking_proxy.rs index 63a92d47..5ec36287 100644 --- a/liquid-staking/src/liquid_staking_proxy.rs +++ b/liquid-staking/src/liquid_staking_proxy.rs @@ -151,6 +151,19 @@ where .original_result() } + pub fn claim_rewards_from_delegation< + Arg0: ProxyArg>>, + >( + self, + contracts: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("claimRewardsFromDelegation") + .argument(&contracts) + .original_result() + } + pub fn delegation_addresses< Arg0: ProxyArg>, >( From 1a4f479f74c1e9550189b54391dfcc0c5c0acd2f Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Thu, 19 Sep 2024 17:28:15 +0300 Subject: [PATCH 48/98] Update test's expected error message Signed-off-by: Andrei Baltariu --- liquid-staking/tests/liquid_staking_tests.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index 1185adbc..68f69d41 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -231,7 +231,7 @@ fn test_stake() { .to(LIQUID_STAKING_ADDRESS) .whitebox(liquid_staking::contract_obj, |sc| { let payment_whitebox = BigUint::from(100_000u64); - let delegated_value = sc.delegated_value(OWNER.to_managed_address()).get(); + let delegated_value = sc.delegated_value(&OWNER.to_managed_address()).get(); let egld_supply = sc.egld_token_supply().get(); assert!(egld_supply > 0); @@ -246,7 +246,7 @@ fn test_unstake_user_no_deposit() { let payment = BigUint::from(100_000u64); let error_status = ErrorStatus { code: 4, - error_message: "The user has not deposited any EGLD", + error_message: "Caller has 0 delegated value", }; state.propose_setup_contracts(); From afe0c1a2b477f90a6d861347f3256e3d07e805b7 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Thu, 19 Sep 2024 17:28:22 +0300 Subject: [PATCH 49/98] Built contract Signed-off-by: Andrei Baltariu --- liquid-staking/wasm-liquid-staking-full/src/lib.rs | 5 +++-- liquid-staking/wasm/src/lib.rs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/liquid-staking/wasm-liquid-staking-full/src/lib.rs b/liquid-staking/wasm-liquid-staking-full/src/lib.rs index 8cedf5e9..899222b1 100644 --- a/liquid-staking/wasm-liquid-staking-full/src/lib.rs +++ b/liquid-staking/wasm-liquid-staking-full/src/lib.rs @@ -6,9 +6,9 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 11 +// Endpoints: 12 // Async Callback: 1 -// Total number of exported functions: 14 +// Total number of exported functions: 15 #![no_std] @@ -25,6 +25,7 @@ multiversx_sc_wasm_adapter::endpoints! { registerBlsKeys => register_bls_keys stake => stake unStake => unstake + claimRewardsFromDelegation => claim_rewards_from_delegation getDelegationAddress => delegation_addresses getDelegatedValue => delegated_value unDelegateEpoch => undelegate_epoch diff --git a/liquid-staking/wasm/src/lib.rs b/liquid-staking/wasm/src/lib.rs index 8cedf5e9..899222b1 100644 --- a/liquid-staking/wasm/src/lib.rs +++ b/liquid-staking/wasm/src/lib.rs @@ -6,9 +6,9 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 11 +// Endpoints: 12 // Async Callback: 1 -// Total number of exported functions: 14 +// Total number of exported functions: 15 #![no_std] @@ -25,6 +25,7 @@ multiversx_sc_wasm_adapter::endpoints! { registerBlsKeys => register_bls_keys stake => stake unStake => unstake + claimRewardsFromDelegation => claim_rewards_from_delegation getDelegationAddress => delegation_addresses getDelegatedValue => delegated_value unDelegateEpoch => undelegate_epoch From c6eb5fb7bfee2035d0bd348bc3437647519e21a3 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Thu, 19 Sep 2024 18:08:11 +0300 Subject: [PATCH 50/98] Added claim rewards from delegation test Signed-off-by: Andrei Baltariu --- liquid-staking/tests/liquid_staking_tests.rs | 60 +++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index 68f69d41..58d43dfa 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -1,7 +1,8 @@ +use delegation_mock::{APY, EPOCHS_IN_YEAR, MAX_PERCENTAGE}; use liquid_staking::{ common::storage::CommonStorageModule, delegation_proxy, liquid_staking_proxy, }; -use multiversx_sc::types::{BigUint, ManagedBuffer, TestAddress, TestSCAddress}; +use multiversx_sc::types::{BigUint, ManagedBuffer, MultiValueEncoded, TestAddress, TestSCAddress}; use multiversx_sc_scenario::{ api::StaticApi, imports::MxscPath, DebugApi, ExpectError, ScenarioTxRun, ScenarioTxWhitebox, ScenarioWorld, @@ -162,6 +163,21 @@ impl LiquidStakingTestState { self } + fn propose_claim_rewards_from_delegation( + &mut self, + contracts: &MultiValueEncoded>, + ) -> &mut Self { + self.world + .tx() + .from(OWNER) + .to(LIQUID_STAKING_ADDRESS) + .typed(liquid_staking_proxy::LiquidStakingProxy) + .claim_rewards_from_delegation(contracts) + .run(); + + self + } + fn propose_check_is_contract_registered(&mut self, contract_name: &ManagedBuffer) { self.world.query().to(LIQUID_STAKING_ADDRESS).whitebox( liquid_staking::contract_obj, @@ -173,6 +189,18 @@ impl LiquidStakingTestState { }, ); } + + fn get_expected_rewards( + &mut self, + staked_amount: &BigUint, + current_epoch: u64, + last_claim_epoch: u64, + ) -> BigUint { + let rewards = (staked_amount * APY / MAX_PERCENTAGE) * (current_epoch - last_claim_epoch) + / EPOCHS_IN_YEAR; + + rewards + } } #[test] @@ -273,3 +301,33 @@ fn test_unstake() { .check_account(OWNER) .balance(BigUint::from(WEGLD_BALANCE) - payment); } + +#[test] +fn test_claim_rewards_from_delegation_contract() { + let mut state = LiquidStakingTestState::new(); + let contract_name = ManagedBuffer::from("delegation"); + let payment = BigUint::from(100_000u64); + let mut contracts_to_claim_from: MultiValueEncoded> = + MultiValueEncoded::new(); + let claim_rewards_epoch = 20; + + state.propose_setup_contracts(); + state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); + state.propose_check_is_contract_registered(&contract_name); + state.propose_stake(&contract_name, &payment); + + contracts_to_claim_from.push(contract_name); + + state.world.current_block().block_epoch(claim_rewards_epoch); + + state.propose_claim_rewards_from_delegation(&contracts_to_claim_from); + state.world.current_block().block_epoch(claim_rewards_epoch); + state.propose_claim_rewards_from_delegation(&contracts_to_claim_from); + + let expected_rewards = state.get_expected_rewards(&payment, claim_rewards_epoch, 0); + + state + .world + .check_account(LIQUID_STAKING_ADDRESS) + .balance(expected_rewards); +} From 7200eb326eb9665a96207c31dd2be816c1bc38dc Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Mon, 23 Sep 2024 11:38:52 +0300 Subject: [PATCH 51/98] Added check for delegated value in unstake scenario Signed-off-by: Andrei Baltariu --- liquid-staking/tests/liquid_staking_tests.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index 58d43dfa..3ee6a77c 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -300,6 +300,17 @@ fn test_unstake() { .world .check_account(OWNER) .balance(BigUint::from(WEGLD_BALANCE) - payment); + + state + .world + .query() + .to(LIQUID_STAKING_ADDRESS) + .whitebox(liquid_staking::contract_obj, |sc| { + let expected_amount = BigUint::from(90_000u64); + let delegated_value = sc.delegated_value(&OWNER.to_managed_address()).get(); + + assert_eq!(delegated_value, expected_amount); + }) } #[test] From 1a8795a0363143c739d91cbcdcb9a6ab76f2ee43 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Mon, 23 Sep 2024 11:52:55 +0300 Subject: [PATCH 52/98] Added slash endpoint Signed-off-by: Andrei Baltariu --- liquid-staking/src/common/storage.rs | 14 +++++++++ liquid-staking/src/delegation.rs | 21 ++++++++++++++ liquid-staking/src/liquid_staking_proxy.rs | 29 +++++++++++++++++++ .../wasm-liquid-staking-full/src/lib.rs | 6 ++-- liquid-staking/wasm/src/lib.rs | 6 ++-- 5 files changed, 72 insertions(+), 4 deletions(-) diff --git a/liquid-staking/src/common/storage.rs b/liquid-staking/src/common/storage.rs index f848af4d..4c836a41 100644 --- a/liquid-staking/src/common/storage.rs +++ b/liquid-staking/src/common/storage.rs @@ -30,6 +30,20 @@ pub trait CommonStorageModule { #[storage_mapper("registeredBlsKeys")] fn registered_bls_keys(&self) -> UnorderedSetMapper; + #[view(validatorBlsKeyMap)] + #[storage_mapper("validatorBlsKeyMap")] + fn validator_bls_key_address_map( + &self, + address: &ManagedBuffer, + ) -> SingleValueMapper; + + fn require_bls_key_to_be_registered(&self, bls_key: &ManagedBuffer) { + require!( + self.registered_bls_keys().contains(bls_key), + "The given bls key is not registered" + ); + } + fn require_caller_to_be_header_verifier(&self, caller: &ManagedAddress) { let header_verifier_address = self.header_verifier_address().get(); diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index a99c6f28..fc86ad7b 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -114,4 +114,25 @@ pub trait DelegationModule: common::storage::CommonStorageModule { _ => sc_panic!("There was an error at claiming rewards from the delegation contract"), } } + + #[endpoint(slashValidator)] + fn slash_validator(&self, bls_key: ManagedBuffer, value_to_slash: BigUint) { + let caller = self.blockchain().get_caller(); + self.require_caller_to_be_header_verifier(&caller); + self.require_bls_key_to_be_registered(&bls_key); + + let validator_address = self.validator_bls_key_address_map(&bls_key).get(); + self.require_caller_has_stake(&validator_address); + + require!(value_to_slash > 0, "You can't slash a value of 0 eGLD"); + + let delegated_value = self.delegated_value(&validator_address).get(); + require!( + delegated_value >= value_to_slash, + "The slash value can't be greater than the total delegated amount" + ); + + self.delegated_value(&validator_address) + .update(|value| *value -= &value_to_slash); + } } diff --git a/liquid-staking/src/liquid_staking_proxy.rs b/liquid-staking/src/liquid_staking_proxy.rs index 5ec36287..3010e9d5 100644 --- a/liquid-staking/src/liquid_staking_proxy.rs +++ b/liquid-staking/src/liquid_staking_proxy.rs @@ -164,6 +164,22 @@ where .original_result() } + pub fn slash_validator< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + >( + self, + bls_key: Arg0, + value_to_slash: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("slashValidator") + .argument(&bls_key) + .argument(&value_to_slash) + .original_result() + } + pub fn delegation_addresses< Arg0: ProxyArg>, >( @@ -229,4 +245,17 @@ where .raw_call("getRegisteredBlsKeys") .original_result() } + + pub fn validator_bls_key_address_map< + Arg0: ProxyArg>, + >( + self, + address: Arg0, + ) -> TxTypedCall> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("validatorBlsKeyMap") + .argument(&address) + .original_result() + } } diff --git a/liquid-staking/wasm-liquid-staking-full/src/lib.rs b/liquid-staking/wasm-liquid-staking-full/src/lib.rs index 899222b1..febe23cf 100644 --- a/liquid-staking/wasm-liquid-staking-full/src/lib.rs +++ b/liquid-staking/wasm-liquid-staking-full/src/lib.rs @@ -6,9 +6,9 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 12 +// Endpoints: 14 // Async Callback: 1 -// Total number of exported functions: 15 +// Total number of exported functions: 17 #![no_std] @@ -26,12 +26,14 @@ multiversx_sc_wasm_adapter::endpoints! { stake => stake unStake => unstake claimRewardsFromDelegation => claim_rewards_from_delegation + slashValidator => slash_validator getDelegationAddress => delegation_addresses getDelegatedValue => delegated_value unDelegateEpoch => undelegate_epoch getTotalEgldSupply => egld_token_supply getHeaderVerifierAddress => header_verifier_address getRegisteredBlsKeys => registered_bls_keys + validatorBlsKeyMap => validator_bls_key_address_map ) } diff --git a/liquid-staking/wasm/src/lib.rs b/liquid-staking/wasm/src/lib.rs index 899222b1..febe23cf 100644 --- a/liquid-staking/wasm/src/lib.rs +++ b/liquid-staking/wasm/src/lib.rs @@ -6,9 +6,9 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 12 +// Endpoints: 14 // Async Callback: 1 -// Total number of exported functions: 15 +// Total number of exported functions: 17 #![no_std] @@ -26,12 +26,14 @@ multiversx_sc_wasm_adapter::endpoints! { stake => stake unStake => unstake claimRewardsFromDelegation => claim_rewards_from_delegation + slashValidator => slash_validator getDelegationAddress => delegation_addresses getDelegatedValue => delegated_value unDelegateEpoch => undelegate_epoch getTotalEgldSupply => egld_token_supply getHeaderVerifierAddress => header_verifier_address getRegisteredBlsKeys => registered_bls_keys + validatorBlsKeyMap => validator_bls_key_address_map ) } From 4f0265a20d983aa7683f6bce6334ecfd57c5156f Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Mon, 23 Sep 2024 14:35:09 +0300 Subject: [PATCH 53/98] Added require to check if there is no address registered Signed-off-by: Andrei Baltariu --- liquid-staking/src/common/storage.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/liquid-staking/src/common/storage.rs b/liquid-staking/src/common/storage.rs index 4c836a41..474a38ff 100644 --- a/liquid-staking/src/common/storage.rs +++ b/liquid-staking/src/common/storage.rs @@ -45,6 +45,11 @@ pub trait CommonStorageModule { } fn require_caller_to_be_header_verifier(&self, caller: &ManagedAddress) { + require!( + !self.header_verifier_address().is_empty(), + "There is no address registered as the Header Verifier" + ); + let header_verifier_address = self.header_verifier_address().get(); require!( From ca7e5feeb1d09e1931d7bb54a1d77938d495545c Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Mon, 23 Sep 2024 14:35:46 +0300 Subject: [PATCH 54/98] Added tests for BLS registration + Mockup setup for HeaderVer Signed-off-by: Andrei Baltariu --- liquid-staking/tests/liquid_staking_tests.rs | 138 +++++++++++++++++++ 1 file changed, 138 insertions(+) diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index 3ee6a77c..0ac59b55 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -16,6 +16,11 @@ const DELEGATION_CODE_PATH: MxscPath = MxscPath::new("../delegation-mock/output/delegation-mock.mxsc.json"); const DELEGATION_ADDRESS: TestSCAddress = TestSCAddress::new("delegation"); +const MOCK_CODE_PATH: MxscPath = + MxscPath::new("../header-verifier/output/header-verifier.mxsc.json"); + +const HEADER_VERIFIER_ADDRESS: TestSCAddress = TestSCAddress::new("header_verifier"); + const VALIDATOR_ADDRESS: TestAddress = TestAddress::new("validator"); const WEGLD_BALANCE: u128 = 100_000_000_000_000_000; @@ -25,6 +30,7 @@ fn world() -> ScenarioWorld { blockchain.register_contract(LIQUID_STAKING_CODE_PATH, liquid_staking::ContractBuilder); blockchain.register_contract(DELEGATION_CODE_PATH, delegation_mock::ContractBuilder); + blockchain.register_contract(MOCK_CODE_PATH, delegation_mock::ContractBuilder); blockchain } @@ -81,9 +87,23 @@ impl LiquidStakingTestState { self } + fn deploy_mock_header_verifier(&mut self) -> &mut Self { + self.world + .tx() + .from(OWNER) + .typed(delegation_proxy::DelegationMockProxy) + .init() + .code(MOCK_CODE_PATH) + .new_address(HEADER_VERIFIER_ADDRESS) + .run(); + + self + } + fn propose_setup_contracts(&mut self) -> &mut Self { self.deploy_liquid_staking(); self.deploy_delegation(); + self.deploy_mock_header_verifier(); self } @@ -178,6 +198,61 @@ impl LiquidStakingTestState { self } + fn propose_register_bls_keys( + &mut self, + bls_keys: MultiValueEncoded>, + error_status: Option, + ) { + match error_status { + Some(error) => self + .world + .tx() + .from(OWNER) + .to(LIQUID_STAKING_ADDRESS) + .typed(liquid_staking_proxy::LiquidStakingProxy) + .register_bls_keys(bls_keys) + .returns(ExpectError(error.code, error.error_message)) + .run(), + None => self + .world + .tx() + .from(HEADER_VERIFIER_ADDRESS) + .to(LIQUID_STAKING_ADDRESS) + .typed(liquid_staking_proxy::LiquidStakingProxy) + .register_bls_keys(bls_keys) + .run(), + } + } + + fn propose_register_header_verifier( + &mut self, + header_verifier_address: TestSCAddress, + ) -> &mut Self { + self.world + .tx() + .from(OWNER) + .to(LIQUID_STAKING_ADDRESS) + .typed(liquid_staking_proxy::LiquidStakingProxy) + .register_header_verifier_address(header_verifier_address) + .run(); + + self + } + + fn propose_slash_validator( + &mut self, + bls_key: &ManagedBuffer, + value_to_slash: BigUint, + ) { + self.world + .tx() + .from(OWNER) + .to(LIQUID_STAKING_ADDRESS) + .typed(liquid_staking_proxy::LiquidStakingProxy) + .slash_validator(bls_key, value_to_slash) + .run(); + } + fn propose_check_is_contract_registered(&mut self, contract_name: &ManagedBuffer) { self.world.query().to(LIQUID_STAKING_ADDRESS).whitebox( liquid_staking::contract_obj, @@ -201,6 +276,16 @@ impl LiquidStakingTestState { rewards } + + fn setup_bls_keys( + &mut self, + bls_keys: Vec>, + ) -> MultiValueEncoded> { + let managed_bls_keys: MultiValueEncoded> = + bls_keys.iter().map(|bls_key| bls_key.clone()).collect(); + + managed_bls_keys + } } #[test] @@ -342,3 +427,56 @@ fn test_claim_rewards_from_delegation_contract() { .check_account(LIQUID_STAKING_ADDRESS) .balance(expected_rewards); } + +#[test] +fn test_slash_validator() { + let mut state = LiquidStakingTestState::new(); + let contract_name = ManagedBuffer::from("delegation"); + let payment = BigUint::from(100_000u64); + // let validator_1_bls_key = ManagedBuffer::from("validator1"); + // let validator_2_bls_key = ManagedBuffer::from("validator2"); + + state.propose_setup_contracts(); + state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); + state.propose_check_is_contract_registered(&contract_name); + state.propose_stake(&contract_name, &payment); + // state.propose_slash_validator(bls_key, value_to_slash); +} + +#[test] +fn test_register_bls_keys_caller_not_header_verifier() { + let mut state = LiquidStakingTestState::new(); + let contract_name = ManagedBuffer::from("delegation"); + let bls_keys = state.setup_bls_keys(vec![ManagedBuffer::from("bls_key")]); + let error_status = ErrorStatus { + code: 4, + error_message: "There is no address registered as the Header Verifier", + }; + + state.propose_setup_contracts(); + state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); + state.propose_check_is_contract_registered(&contract_name); + state.propose_register_bls_keys(bls_keys, Some(error_status)); +} + +#[test] +fn register_bls_keys() { + let mut state = LiquidStakingTestState::new(); + let contract_name = ManagedBuffer::from("delegation"); + let validator_1_bls_key = ManagedBuffer::from("bls_key_1"); + let validator_2_bls_key = ManagedBuffer::from("bls_key_2"); + let bls_keys = state.setup_bls_keys(vec![validator_1_bls_key, validator_2_bls_key]); + + state.propose_setup_contracts(); + state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); + state.propose_register_header_verifier(HEADER_VERIFIER_ADDRESS); + state.propose_register_bls_keys(bls_keys, None); + + state + .world + .query() + .to(LIQUID_STAKING_ADDRESS) + .whitebox(liquid_staking::contract_obj, |sc| { + assert!(!sc.registered_bls_keys().is_empty()); + }) +} From 27ddb0c9116d3c15948468d5ee7b395766364f0e Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Mon, 23 Sep 2024 15:23:31 +0300 Subject: [PATCH 55/98] Added require to check bls-address map if empty Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index fc86ad7b..990bf356 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -121,6 +121,11 @@ pub trait DelegationModule: common::storage::CommonStorageModule { self.require_caller_to_be_header_verifier(&caller); self.require_bls_key_to_be_registered(&bls_key); + require!( + self.validator_bls_key_address_map(&bls_key).is_empty(), + "There is no associated address to the given BLS key" + ); + let validator_address = self.validator_bls_key_address_map(&bls_key).get(); self.require_caller_has_stake(&validator_address); From 6a30c5785bcfcc75b67e48940d85207407fa3c7f Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Mon, 23 Sep 2024 15:23:45 +0300 Subject: [PATCH 56/98] Added test for slashing Signed-off-by: Andrei Baltariu --- liquid-staking/tests/liquid_staking_tests.rs | 92 +++++++++++++++++--- 1 file changed, 80 insertions(+), 12 deletions(-) diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index 0ac59b55..f0ca98bc 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -2,7 +2,9 @@ use delegation_mock::{APY, EPOCHS_IN_YEAR, MAX_PERCENTAGE}; use liquid_staking::{ common::storage::CommonStorageModule, delegation_proxy, liquid_staking_proxy, }; -use multiversx_sc::types::{BigUint, ManagedBuffer, MultiValueEncoded, TestAddress, TestSCAddress}; +use multiversx_sc::types::{ + BigUint, ManagedAddress, ManagedBuffer, MultiValueEncoded, TestAddress, TestSCAddress, +}; use multiversx_sc_scenario::{ api::StaticApi, imports::MxscPath, DebugApi, ExpectError, ScenarioTxRun, ScenarioTxWhitebox, ScenarioWorld, @@ -139,12 +141,13 @@ impl LiquidStakingTestState { fn propose_stake( &mut self, + validator: &TestAddress, contract_name: &ManagedBuffer, payment: &BigUint, ) -> &mut Self { self.world .tx() - .from(OWNER) + .from(validator.to_managed_address()) .to(LIQUID_STAKING_ADDRESS) .typed(liquid_staking_proxy::LiquidStakingProxy) .stake(contract_name) @@ -246,7 +249,7 @@ impl LiquidStakingTestState { ) { self.world .tx() - .from(OWNER) + .from(HEADER_VERIFIER_ADDRESS) .to(LIQUID_STAKING_ADDRESS) .typed(liquid_staking_proxy::LiquidStakingProxy) .slash_validator(bls_key, value_to_slash) @@ -279,13 +282,28 @@ impl LiquidStakingTestState { fn setup_bls_keys( &mut self, - bls_keys: Vec>, + bls_keys: Vec<&ManagedBuffer>, ) -> MultiValueEncoded> { let managed_bls_keys: MultiValueEncoded> = - bls_keys.iter().map(|bls_key| bls_key.clone()).collect(); + bls_keys.iter().map(|bls_key| (*bls_key).clone()).collect(); managed_bls_keys } + + fn map_bls_key_to_address(&mut self, bls_key: &str, address: &TestAddress) -> &mut Self { + self.world + .tx() + .from(OWNER) + .to(LIQUID_STAKING_ADDRESS) + .whitebox(liquid_staking::contract_obj, |sc| { + let validator_address: ManagedAddress = address.to_managed_address(); + let bls_key_whitebox: ManagedBuffer = ManagedBuffer::from(bls_key); + sc.validator_bls_key_address_map(&bls_key_whitebox) + .set(validator_address); + }); + + self + } } #[test] @@ -331,7 +349,7 @@ fn test_stake() { state.propose_setup_contracts(); state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); state.propose_check_is_contract_registered(&contract_name); - state.propose_stake(&contract_name, &payment); + state.propose_stake(&OWNER, &contract_name, &payment); state .world @@ -378,7 +396,7 @@ fn test_unstake() { state.propose_setup_contracts(); state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); state.propose_check_is_contract_registered(&contract_name); - state.propose_stake(&contract_name, &payment); + state.propose_stake(&OWNER, &contract_name, &payment); state.propose_unstake(&contract_name, &amount_to_unstake, None); state @@ -410,7 +428,7 @@ fn test_claim_rewards_from_delegation_contract() { state.propose_setup_contracts(); state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); state.propose_check_is_contract_registered(&contract_name); - state.propose_stake(&contract_name, &payment); + state.propose_stake(&OWNER, &contract_name, &payment); contracts_to_claim_from.push(contract_name); @@ -439,15 +457,15 @@ fn test_slash_validator() { state.propose_setup_contracts(); state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); state.propose_check_is_contract_registered(&contract_name); - state.propose_stake(&contract_name, &payment); + state.propose_stake(&OWNER, &contract_name, &payment); // state.propose_slash_validator(bls_key, value_to_slash); } #[test] -fn test_register_bls_keys_caller_not_header_verifier() { +fn test_register_bls_keys_no_header_verifier_address() { let mut state = LiquidStakingTestState::new(); let contract_name = ManagedBuffer::from("delegation"); - let bls_keys = state.setup_bls_keys(vec![ManagedBuffer::from("bls_key")]); + let bls_keys = state.setup_bls_keys(vec![&ManagedBuffer::from("bls_key")]); let error_status = ErrorStatus { code: 4, error_message: "There is no address registered as the Header Verifier", @@ -459,13 +477,30 @@ fn test_register_bls_keys_caller_not_header_verifier() { state.propose_register_bls_keys(bls_keys, Some(error_status)); } +#[test] +fn test_register_bls_keys_caller_not_header_verifier() { + let mut state = LiquidStakingTestState::new(); + let contract_name = ManagedBuffer::from("delegation"); + let bls_keys = state.setup_bls_keys(vec![&ManagedBuffer::from("bls_key")]); + let error_status = ErrorStatus { + code: 4, + error_message: "Caller is not Header Verifier contract", + }; + + state.propose_setup_contracts(); + state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); + state.propose_check_is_contract_registered(&contract_name); + state.propose_register_header_verifier(HEADER_VERIFIER_ADDRESS); + state.propose_register_bls_keys(bls_keys, Some(error_status)); +} + #[test] fn register_bls_keys() { let mut state = LiquidStakingTestState::new(); let contract_name = ManagedBuffer::from("delegation"); let validator_1_bls_key = ManagedBuffer::from("bls_key_1"); let validator_2_bls_key = ManagedBuffer::from("bls_key_2"); - let bls_keys = state.setup_bls_keys(vec![validator_1_bls_key, validator_2_bls_key]); + let bls_keys = state.setup_bls_keys(vec![&validator_1_bls_key, &validator_2_bls_key]); state.propose_setup_contracts(); state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); @@ -480,3 +515,36 @@ fn register_bls_keys() { assert!(!sc.registered_bls_keys().is_empty()); }) } + +#[test] +fn slash_validator() { + let mut state = LiquidStakingTestState::new(); + let contract_name = ManagedBuffer::from("delegation"); + let validator_1_bls_key = ManagedBuffer::from("bls_key_1"); + let validator_2_bls_key = ManagedBuffer::from("bls_key_2"); + let bls_keys = state.setup_bls_keys(vec![&validator_1_bls_key, &validator_2_bls_key]); + let payment = BigUint::from(100_000u64); + let value_to_slash = BigUint::from(10_000u64); + + state.propose_setup_contracts(); + state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); + state.propose_register_header_verifier(HEADER_VERIFIER_ADDRESS); + state.propose_register_bls_keys(bls_keys, None); + state.propose_stake(&VALIDATOR_ADDRESS, &contract_name, &payment); + state.map_bls_key_to_address("bls_key_1", &VALIDATOR_ADDRESS); + + state.propose_slash_validator(&validator_1_bls_key, value_to_slash); + + state + .world + .query() + .to(LIQUID_STAKING_ADDRESS) + .whitebox(liquid_staking::contract_obj, |sc| { + let expected_value = BigUint::from(90_000u64); + let validator_delegated_value = sc + .delegated_value(&VALIDATOR_ADDRESS.to_managed_address()) + .get(); + + assert_eq!(validator_delegated_value, expected_value); + }) +} From e29f3e604147ee4d5b5edc76ffdf0f3c81b66d8d Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Tue, 24 Sep 2024 10:37:37 +0300 Subject: [PATCH 57/98] Renamed function Signed-off-by: Andrei Baltariu --- liquid-staking/tests/liquid_staking_tests.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index f0ca98bc..1bc61989 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -280,7 +280,7 @@ impl LiquidStakingTestState { rewards } - fn setup_bls_keys( + fn map_bls_key_vec_to_multi_value( &mut self, bls_keys: Vec<&ManagedBuffer>, ) -> MultiValueEncoded> { @@ -465,7 +465,7 @@ fn test_slash_validator() { fn test_register_bls_keys_no_header_verifier_address() { let mut state = LiquidStakingTestState::new(); let contract_name = ManagedBuffer::from("delegation"); - let bls_keys = state.setup_bls_keys(vec![&ManagedBuffer::from("bls_key")]); + let bls_keys = state.map_bls_key_vec_to_multi_value(vec![&ManagedBuffer::from("bls_key")]); let error_status = ErrorStatus { code: 4, error_message: "There is no address registered as the Header Verifier", @@ -481,7 +481,7 @@ fn test_register_bls_keys_no_header_verifier_address() { fn test_register_bls_keys_caller_not_header_verifier() { let mut state = LiquidStakingTestState::new(); let contract_name = ManagedBuffer::from("delegation"); - let bls_keys = state.setup_bls_keys(vec![&ManagedBuffer::from("bls_key")]); + let bls_keys = state.map_bls_key_vec_to_multi_value(vec![&ManagedBuffer::from("bls_key")]); let error_status = ErrorStatus { code: 4, error_message: "Caller is not Header Verifier contract", @@ -500,7 +500,8 @@ fn register_bls_keys() { let contract_name = ManagedBuffer::from("delegation"); let validator_1_bls_key = ManagedBuffer::from("bls_key_1"); let validator_2_bls_key = ManagedBuffer::from("bls_key_2"); - let bls_keys = state.setup_bls_keys(vec![&validator_1_bls_key, &validator_2_bls_key]); + let bls_keys = + state.map_bls_key_vec_to_multi_value(vec![&validator_1_bls_key, &validator_2_bls_key]); state.propose_setup_contracts(); state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); @@ -522,7 +523,8 @@ fn slash_validator() { let contract_name = ManagedBuffer::from("delegation"); let validator_1_bls_key = ManagedBuffer::from("bls_key_1"); let validator_2_bls_key = ManagedBuffer::from("bls_key_2"); - let bls_keys = state.setup_bls_keys(vec![&validator_1_bls_key, &validator_2_bls_key]); + let bls_keys = + state.map_bls_key_vec_to_multi_value(vec![&validator_1_bls_key, &validator_2_bls_key]); let payment = BigUint::from(100_000u64); let value_to_slash = BigUint::from(10_000u64); From 96f835b4f8c478e229181030c727a9d3641d9aa0 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Tue, 24 Sep 2024 11:14:13 +0300 Subject: [PATCH 58/98] Fixed slashing test Signed-off-by: Andrei Baltariu --- liquid-staking/src/common/storage.rs | 2 +- liquid-staking/src/delegation.rs | 2 +- liquid-staking/src/liquid_staking_proxy.rs | 4 ++-- liquid-staking/tests/liquid_staking_tests.rs | 19 ++++++++++++++++--- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/liquid-staking/src/common/storage.rs b/liquid-staking/src/common/storage.rs index 474a38ff..191fedf1 100644 --- a/liquid-staking/src/common/storage.rs +++ b/liquid-staking/src/common/storage.rs @@ -34,7 +34,7 @@ pub trait CommonStorageModule { #[storage_mapper("validatorBlsKeyMap")] fn validator_bls_key_address_map( &self, - address: &ManagedBuffer, + bls_key: &ManagedBuffer, ) -> SingleValueMapper; fn require_bls_key_to_be_registered(&self, bls_key: &ManagedBuffer) { diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 990bf356..f7e57f9b 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -122,7 +122,7 @@ pub trait DelegationModule: common::storage::CommonStorageModule { self.require_bls_key_to_be_registered(&bls_key); require!( - self.validator_bls_key_address_map(&bls_key).is_empty(), + !self.validator_bls_key_address_map(&bls_key).is_empty(), "There is no associated address to the given BLS key" ); diff --git a/liquid-staking/src/liquid_staking_proxy.rs b/liquid-staking/src/liquid_staking_proxy.rs index 3010e9d5..8383473e 100644 --- a/liquid-staking/src/liquid_staking_proxy.rs +++ b/liquid-staking/src/liquid_staking_proxy.rs @@ -250,12 +250,12 @@ where Arg0: ProxyArg>, >( self, - address: Arg0, + bls_key: Arg0, ) -> TxTypedCall> { self.wrapped_tx .payment(NotPayable) .raw_call("validatorBlsKeyMap") - .argument(&address) + .argument(&bls_key) .original_result() } } diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index 1bc61989..e673099c 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -268,6 +268,20 @@ impl LiquidStakingTestState { ); } + fn propose_map_bls_to_address( + &mut self, + bls_key: &ManagedBuffer, + address: &TestAddress, + ) { + self.world + .tx() + .from(HEADER_VERIFIER_ADDRESS) + .to(LIQUID_STAKING_ADDRESS) + .typed(liquid_staking_proxy::LiquidStakingProxy) + .map_bls_key_to_address(bls_key, address.to_managed_address()) + .run(); + } + fn get_expected_rewards( &mut self, staked_amount: &BigUint, @@ -290,7 +304,7 @@ impl LiquidStakingTestState { managed_bls_keys } - fn map_bls_key_to_address(&mut self, bls_key: &str, address: &TestAddress) -> &mut Self { + fn whitebox_map_bls_to_address(&mut self, bls_key: &str, address: &TestAddress) -> &mut Self { self.world .tx() .from(OWNER) @@ -533,8 +547,7 @@ fn slash_validator() { state.propose_register_header_verifier(HEADER_VERIFIER_ADDRESS); state.propose_register_bls_keys(bls_keys, None); state.propose_stake(&VALIDATOR_ADDRESS, &contract_name, &payment); - state.map_bls_key_to_address("bls_key_1", &VALIDATOR_ADDRESS); - + state.whitebox_map_bls_to_address("bls_key_1", &VALIDATOR_ADDRESS); state.propose_slash_validator(&validator_1_bls_key, value_to_slash); state From 20f972a65535b10a78be8872f29ef2ddc1704d37 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Tue, 24 Sep 2024 11:25:52 +0300 Subject: [PATCH 59/98] Added slash test Signed-off-by: Andrei Baltariu --- liquid-staking/tests/liquid_staking_tests.rs | 65 +++++++++++++------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index e673099c..6b044f56 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -246,14 +246,27 @@ impl LiquidStakingTestState { &mut self, bls_key: &ManagedBuffer, value_to_slash: BigUint, + error_status: Option, ) { - self.world - .tx() - .from(HEADER_VERIFIER_ADDRESS) - .to(LIQUID_STAKING_ADDRESS) - .typed(liquid_staking_proxy::LiquidStakingProxy) - .slash_validator(bls_key, value_to_slash) - .run(); + match error_status { + Some(error) => self + .world + .tx() + .from(HEADER_VERIFIER_ADDRESS) + .to(LIQUID_STAKING_ADDRESS) + .typed(liquid_staking_proxy::LiquidStakingProxy) + .slash_validator(bls_key, value_to_slash) + .returns(ExpectError(error.code, error.error_message)) + .run(), + None => self + .world + .tx() + .from(HEADER_VERIFIER_ADDRESS) + .to(LIQUID_STAKING_ADDRESS) + .typed(liquid_staking_proxy::LiquidStakingProxy) + .slash_validator(bls_key, value_to_slash) + .run(), + } } fn propose_check_is_contract_registered(&mut self, contract_name: &ManagedBuffer) { @@ -268,20 +281,6 @@ impl LiquidStakingTestState { ); } - fn propose_map_bls_to_address( - &mut self, - bls_key: &ManagedBuffer, - address: &TestAddress, - ) { - self.world - .tx() - .from(HEADER_VERIFIER_ADDRESS) - .to(LIQUID_STAKING_ADDRESS) - .typed(liquid_staking_proxy::LiquidStakingProxy) - .map_bls_key_to_address(bls_key, address.to_managed_address()) - .run(); - } - fn get_expected_rewards( &mut self, staked_amount: &BigUint, @@ -531,6 +530,28 @@ fn register_bls_keys() { }) } +#[test] +fn slash_no_delegated_value() { + let mut state = LiquidStakingTestState::new(); + let contract_name = ManagedBuffer::from("delegation"); + let validator_1_bls_key = ManagedBuffer::from("bls_key_1"); + let validator_2_bls_key = ManagedBuffer::from("bls_key_2"); + let bls_keys = + state.map_bls_key_vec_to_multi_value(vec![&validator_1_bls_key, &validator_2_bls_key]); + let value_to_slash = BigUint::from(10_000u64); + let error_status = ErrorStatus { + code: 4, + error_message: "Caller has 0 delegated value", + }; + + state.propose_setup_contracts(); + state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); + state.propose_register_header_verifier(HEADER_VERIFIER_ADDRESS); + state.propose_register_bls_keys(bls_keys, None); + state.whitebox_map_bls_to_address("bls_key_1", &VALIDATOR_ADDRESS); + state.propose_slash_validator(&validator_1_bls_key, value_to_slash, Some(error_status)); +} + #[test] fn slash_validator() { let mut state = LiquidStakingTestState::new(); @@ -548,7 +569,7 @@ fn slash_validator() { state.propose_register_bls_keys(bls_keys, None); state.propose_stake(&VALIDATOR_ADDRESS, &contract_name, &payment); state.whitebox_map_bls_to_address("bls_key_1", &VALIDATOR_ADDRESS); - state.propose_slash_validator(&validator_1_bls_key, value_to_slash); + state.propose_slash_validator(&validator_1_bls_key, value_to_slash, None); state .world From 8b1b7a9e688d6476526dbfe0be48da1b73f81d15 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Tue, 24 Sep 2024 11:27:32 +0300 Subject: [PATCH 60/98] Added 0 slash value test Signed-off-by: Andrei Baltariu --- liquid-staking/tests/liquid_staking_tests.rs | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index 6b044f56..cd19d7a1 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -552,6 +552,30 @@ fn slash_no_delegated_value() { state.propose_slash_validator(&validator_1_bls_key, value_to_slash, Some(error_status)); } +#[test] +fn slash_zero_value() { + let mut state = LiquidStakingTestState::new(); + let contract_name = ManagedBuffer::from("delegation"); + let validator_1_bls_key = ManagedBuffer::from("bls_key_1"); + let validator_2_bls_key = ManagedBuffer::from("bls_key_2"); + let payment = BigUint::from(100_000u64); + let bls_keys = + state.map_bls_key_vec_to_multi_value(vec![&validator_1_bls_key, &validator_2_bls_key]); + let value_to_slash = BigUint::from(0u64); + let error_status = ErrorStatus { + code: 4, + error_message: "You can't slash a value of 0 eGLD", + }; + + state.propose_setup_contracts(); + state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); + state.propose_register_header_verifier(HEADER_VERIFIER_ADDRESS); + state.propose_register_bls_keys(bls_keys, None); + state.propose_stake(&VALIDATOR_ADDRESS, &contract_name, &payment); + state.whitebox_map_bls_to_address("bls_key_1", &VALIDATOR_ADDRESS); + state.propose_slash_validator(&validator_1_bls_key, value_to_slash, Some(error_status)); +} + #[test] fn slash_validator() { let mut state = LiquidStakingTestState::new(); From 3c2009d630376b337f6788ca2cf828615e9b7cc2 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Tue, 24 Sep 2024 11:29:22 +0300 Subject: [PATCH 61/98] Added slash more than delegated value scenario Signed-off-by: Andrei Baltariu --- liquid-staking/tests/liquid_staking_tests.rs | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index cd19d7a1..ed430926 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -576,6 +576,30 @@ fn slash_zero_value() { state.propose_slash_validator(&validator_1_bls_key, value_to_slash, Some(error_status)); } +#[test] +fn slash_more_than_delegated_value() { + let mut state = LiquidStakingTestState::new(); + let contract_name = ManagedBuffer::from("delegation"); + let validator_1_bls_key = ManagedBuffer::from("bls_key_1"); + let validator_2_bls_key = ManagedBuffer::from("bls_key_2"); + let payment = BigUint::from(100_000u64); + let bls_keys = + state.map_bls_key_vec_to_multi_value(vec![&validator_1_bls_key, &validator_2_bls_key]); + let value_to_slash = BigUint::from(100_100u64); + let error_status = ErrorStatus { + code: 4, + error_message: "The slash value can't be greater than the total delegated amount", + }; + + state.propose_setup_contracts(); + state.propose_register_delegation_address(&contract_name, DELEGATION_ADDRESS, None); + state.propose_register_header_verifier(HEADER_VERIFIER_ADDRESS); + state.propose_register_bls_keys(bls_keys, None); + state.propose_stake(&VALIDATOR_ADDRESS, &contract_name, &payment); + state.whitebox_map_bls_to_address("bls_key_1", &VALIDATOR_ADDRESS); + state.propose_slash_validator(&validator_1_bls_key, value_to_slash, Some(error_status)); +} + #[test] fn slash_validator() { let mut state = LiquidStakingTestState::new(); From 5174a65a94e6e62a731779a80a4100163c8c9d64 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Tue, 24 Sep 2024 11:51:03 +0300 Subject: [PATCH 62/98] Modified endpoint to use validator address as well Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 9 ++- liquid-staking/src/liquid_staking_proxy.rs | 11 ++-- liquid-staking/tests/liquid_staking_tests.rs | 59 +++++++++++++++----- 3 files changed, 58 insertions(+), 21 deletions(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index f7e57f9b..2351d930 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -115,8 +115,14 @@ pub trait DelegationModule: common::storage::CommonStorageModule { } } + // NOTE: Should this also add to the map ? #[endpoint(slashValidator)] - fn slash_validator(&self, bls_key: ManagedBuffer, value_to_slash: BigUint) { + fn slash_validator( + &self, + validator_address: ManagedAddress, + bls_key: ManagedBuffer, + value_to_slash: BigUint, + ) { let caller = self.blockchain().get_caller(); self.require_caller_to_be_header_verifier(&caller); self.require_bls_key_to_be_registered(&bls_key); @@ -126,7 +132,6 @@ pub trait DelegationModule: common::storage::CommonStorageModule { "There is no associated address to the given BLS key" ); - let validator_address = self.validator_bls_key_address_map(&bls_key).get(); self.require_caller_has_stake(&validator_address); require!(value_to_slash > 0, "You can't slash a value of 0 eGLD"); diff --git a/liquid-staking/src/liquid_staking_proxy.rs b/liquid-staking/src/liquid_staking_proxy.rs index 8383473e..6caa913d 100644 --- a/liquid-staking/src/liquid_staking_proxy.rs +++ b/liquid-staking/src/liquid_staking_proxy.rs @@ -165,16 +165,19 @@ where } pub fn slash_validator< - Arg0: ProxyArg>, - Arg1: ProxyArg>, + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg>, >( self, - bls_key: Arg0, - value_to_slash: Arg1, + validator_address: Arg0, + bls_key: Arg1, + value_to_slash: Arg2, ) -> TxTypedCall { self.wrapped_tx .payment(NotPayable) .raw_call("slashValidator") + .argument(&validator_address) .argument(&bls_key) .argument(&value_to_slash) .original_result() diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index ed430926..fa409d69 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -244,6 +244,7 @@ impl LiquidStakingTestState { fn propose_slash_validator( &mut self, + validator_address: &TestAddress, bls_key: &ManagedBuffer, value_to_slash: BigUint, error_status: Option, @@ -255,7 +256,11 @@ impl LiquidStakingTestState { .from(HEADER_VERIFIER_ADDRESS) .to(LIQUID_STAKING_ADDRESS) .typed(liquid_staking_proxy::LiquidStakingProxy) - .slash_validator(bls_key, value_to_slash) + .slash_validator( + validator_address.to_managed_address(), + bls_key, + value_to_slash, + ) .returns(ExpectError(error.code, error.error_message)) .run(), None => self @@ -264,7 +269,11 @@ impl LiquidStakingTestState { .from(HEADER_VERIFIER_ADDRESS) .to(LIQUID_STAKING_ADDRESS) .typed(liquid_staking_proxy::LiquidStakingProxy) - .slash_validator(bls_key, value_to_slash) + .slash_validator( + validator_address.to_managed_address(), + bls_key, + value_to_slash, + ) .run(), } } @@ -534,10 +543,10 @@ fn register_bls_keys() { fn slash_no_delegated_value() { let mut state = LiquidStakingTestState::new(); let contract_name = ManagedBuffer::from("delegation"); - let validator_1_bls_key = ManagedBuffer::from("bls_key_1"); - let validator_2_bls_key = ManagedBuffer::from("bls_key_2"); + let validator_bls_key_1 = ManagedBuffer::from("bls_key_1"); + let validator_bls_key_2 = ManagedBuffer::from("bls_key_2"); let bls_keys = - state.map_bls_key_vec_to_multi_value(vec![&validator_1_bls_key, &validator_2_bls_key]); + state.map_bls_key_vec_to_multi_value(vec![&validator_bls_key_1, &validator_bls_key_2]); let value_to_slash = BigUint::from(10_000u64); let error_status = ErrorStatus { code: 4, @@ -549,18 +558,23 @@ fn slash_no_delegated_value() { state.propose_register_header_verifier(HEADER_VERIFIER_ADDRESS); state.propose_register_bls_keys(bls_keys, None); state.whitebox_map_bls_to_address("bls_key_1", &VALIDATOR_ADDRESS); - state.propose_slash_validator(&validator_1_bls_key, value_to_slash, Some(error_status)); + state.propose_slash_validator( + &VALIDATOR_ADDRESS, + &validator_bls_key_1, + value_to_slash, + Some(error_status), + ); } #[test] fn slash_zero_value() { let mut state = LiquidStakingTestState::new(); let contract_name = ManagedBuffer::from("delegation"); - let validator_1_bls_key = ManagedBuffer::from("bls_key_1"); - let validator_2_bls_key = ManagedBuffer::from("bls_key_2"); + let validator_bls_key_1 = ManagedBuffer::from("bls_key_1"); + let validator_bls_key_2 = ManagedBuffer::from("bls_key_2"); let payment = BigUint::from(100_000u64); let bls_keys = - state.map_bls_key_vec_to_multi_value(vec![&validator_1_bls_key, &validator_2_bls_key]); + state.map_bls_key_vec_to_multi_value(vec![&validator_bls_key_1, &validator_bls_key_2]); let value_to_slash = BigUint::from(0u64); let error_status = ErrorStatus { code: 4, @@ -573,18 +587,23 @@ fn slash_zero_value() { state.propose_register_bls_keys(bls_keys, None); state.propose_stake(&VALIDATOR_ADDRESS, &contract_name, &payment); state.whitebox_map_bls_to_address("bls_key_1", &VALIDATOR_ADDRESS); - state.propose_slash_validator(&validator_1_bls_key, value_to_slash, Some(error_status)); + state.propose_slash_validator( + &VALIDATOR_ADDRESS, + &validator_bls_key_1, + value_to_slash, + Some(error_status), + ); } #[test] fn slash_more_than_delegated_value() { let mut state = LiquidStakingTestState::new(); let contract_name = ManagedBuffer::from("delegation"); - let validator_1_bls_key = ManagedBuffer::from("bls_key_1"); - let validator_2_bls_key = ManagedBuffer::from("bls_key_2"); + let validator_bls_key_1 = ManagedBuffer::from("bls_key_1"); + let validator_bls_key_2 = ManagedBuffer::from("bls_key_2"); let payment = BigUint::from(100_000u64); let bls_keys = - state.map_bls_key_vec_to_multi_value(vec![&validator_1_bls_key, &validator_2_bls_key]); + state.map_bls_key_vec_to_multi_value(vec![&validator_bls_key_1, &validator_bls_key_2]); let value_to_slash = BigUint::from(100_100u64); let error_status = ErrorStatus { code: 4, @@ -597,7 +616,12 @@ fn slash_more_than_delegated_value() { state.propose_register_bls_keys(bls_keys, None); state.propose_stake(&VALIDATOR_ADDRESS, &contract_name, &payment); state.whitebox_map_bls_to_address("bls_key_1", &VALIDATOR_ADDRESS); - state.propose_slash_validator(&validator_1_bls_key, value_to_slash, Some(error_status)); + state.propose_slash_validator( + &VALIDATOR_ADDRESS, + &validator_bls_key_1, + value_to_slash, + Some(error_status), + ); } #[test] @@ -617,7 +641,12 @@ fn slash_validator() { state.propose_register_bls_keys(bls_keys, None); state.propose_stake(&VALIDATOR_ADDRESS, &contract_name, &payment); state.whitebox_map_bls_to_address("bls_key_1", &VALIDATOR_ADDRESS); - state.propose_slash_validator(&validator_1_bls_key, value_to_slash, None); + state.propose_slash_validator( + &VALIDATOR_ADDRESS, + &validator_1_bls_key, + value_to_slash, + None, + ); state .world From 03044b9d5592c1c2d1202d5d1b549baa8ab4528a Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Tue, 24 Sep 2024 15:27:21 +0300 Subject: [PATCH 63/98] Added endpoint for sovereign chain funding Signed-off-by: Andrei Baltariu --- liquid-staking/src/common/storage.rs | 5 +++ liquid-staking/src/delegation.rs | 15 ++++++++ liquid-staking/src/liquid_staking_proxy.rs | 34 +++++++++++++++++++ .../wasm-liquid-staking-full/src/lib.rs | 7 ++-- liquid-staking/wasm/src/lib.rs | 7 ++-- 5 files changed, 64 insertions(+), 4 deletions(-) diff --git a/liquid-staking/src/common/storage.rs b/liquid-staking/src/common/storage.rs index 191fedf1..a7b01874 100644 --- a/liquid-staking/src/common/storage.rs +++ b/liquid-staking/src/common/storage.rs @@ -37,6 +37,11 @@ pub trait CommonStorageModule { bls_key: &ManagedBuffer, ) -> SingleValueMapper; + // NOTE: Number of nodes where ? + #[view(lockedSupply)] + #[storage_mapper("lockerSupply")] + fn locked_supply(&self, chain_id: ManagedBuffer) -> SingleValueMapper>; + fn require_bls_key_to_be_registered(&self, bls_key: &ManagedBuffer) { require!( self.registered_bls_keys().contains(bls_key), diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 2351d930..0225b4c9 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -145,4 +145,19 @@ pub trait DelegationModule: common::storage::CommonStorageModule { self.delegated_value(&validator_address) .update(|value| *value -= &value_to_slash); } + + #[payable("EGLD")] + #[endpoint(lockForSovereignChain)] + fn lock_for_sovereign_chain(&self, chain_id: ManagedBuffer) { + let call_value = self.call_value().egld_value().clone_value(); + + require!(call_value > 0, "No value send to lock"); + self.locked_supply(chain_id) + .update(|supply| *supply += call_value); + + // lock amount with ChainConfigSC + } + + #[endpoint(claimRewards)] + fn claim_rewards(&self) {} } diff --git a/liquid-staking/src/liquid_staking_proxy.rs b/liquid-staking/src/liquid_staking_proxy.rs index 6caa913d..d6f22b4e 100644 --- a/liquid-staking/src/liquid_staking_proxy.rs +++ b/liquid-staking/src/liquid_staking_proxy.rs @@ -183,6 +183,27 @@ where .original_result() } + pub fn lock_for_sovereign_chain< + Arg0: ProxyArg>, + >( + self, + chain_id: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("lockForSovereignChain") + .argument(&chain_id) + .original_result() + } + + pub fn claim_rewards( + self, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("claimRewards") + .original_result() + } + pub fn delegation_addresses< Arg0: ProxyArg>, >( @@ -261,4 +282,17 @@ where .argument(&bls_key) .original_result() } + + pub fn locked_supply< + Arg0: ProxyArg>, + >( + self, + chain_id: Arg0, + ) -> TxTypedCall> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("lockedSupply") + .argument(&chain_id) + .original_result() + } } diff --git a/liquid-staking/wasm-liquid-staking-full/src/lib.rs b/liquid-staking/wasm-liquid-staking-full/src/lib.rs index febe23cf..bd7d87e7 100644 --- a/liquid-staking/wasm-liquid-staking-full/src/lib.rs +++ b/liquid-staking/wasm-liquid-staking-full/src/lib.rs @@ -6,9 +6,9 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 14 +// Endpoints: 17 // Async Callback: 1 -// Total number of exported functions: 17 +// Total number of exported functions: 20 #![no_std] @@ -27,6 +27,8 @@ multiversx_sc_wasm_adapter::endpoints! { unStake => unstake claimRewardsFromDelegation => claim_rewards_from_delegation slashValidator => slash_validator + lockForSovereignChain => lock_for_sovereign_chain + claimRewards => claim_rewards getDelegationAddress => delegation_addresses getDelegatedValue => delegated_value unDelegateEpoch => undelegate_epoch @@ -34,6 +36,7 @@ multiversx_sc_wasm_adapter::endpoints! { getHeaderVerifierAddress => header_verifier_address getRegisteredBlsKeys => registered_bls_keys validatorBlsKeyMap => validator_bls_key_address_map + lockedSupply => locked_supply ) } diff --git a/liquid-staking/wasm/src/lib.rs b/liquid-staking/wasm/src/lib.rs index febe23cf..bd7d87e7 100644 --- a/liquid-staking/wasm/src/lib.rs +++ b/liquid-staking/wasm/src/lib.rs @@ -6,9 +6,9 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 14 +// Endpoints: 17 // Async Callback: 1 -// Total number of exported functions: 17 +// Total number of exported functions: 20 #![no_std] @@ -27,6 +27,8 @@ multiversx_sc_wasm_adapter::endpoints! { unStake => unstake claimRewardsFromDelegation => claim_rewards_from_delegation slashValidator => slash_validator + lockForSovereignChain => lock_for_sovereign_chain + claimRewards => claim_rewards getDelegationAddress => delegation_addresses getDelegatedValue => delegated_value unDelegateEpoch => undelegate_epoch @@ -34,6 +36,7 @@ multiversx_sc_wasm_adapter::endpoints! { getHeaderVerifierAddress => header_verifier_address getRegisteredBlsKeys => registered_bls_keys validatorBlsKeyMap => validator_bls_key_address_map + lockedSupply => locked_supply ) } From 8ec10a346db1af2e0bb5ce08260599afc8c384f1 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 2 Oct 2024 12:02:20 +0300 Subject: [PATCH 64/98] Removed uneeded reference Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 0225b4c9..57efc0b2 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -76,7 +76,7 @@ pub trait DelegationModule: common::storage::CommonStorageModule { ) { match result { ManagedAsyncCallResult::Ok(()) => { - self.delegated_value(&caller) + self.delegated_value(caller) .update(|value| *value -= egld_amount_to_unstake); self.undelegate_epoch(caller) .set(current_epoch + UNBOND_PERIOD); From 4382f043bc1207efd1e476d403a4fd6de8803f9f Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 2 Oct 2024 12:13:34 +0300 Subject: [PATCH 65/98] Liquid Staking upgrade to 0.53.1 Signed-off-by: Andrei Baltariu --- Cargo.lock | 20 +++++++++---------- chain-config/Cargo.toml | 6 +++--- chain-config/meta/Cargo.toml | 2 +- chain-config/wasm/Cargo.lock | 16 +++++++-------- chain-config/wasm/Cargo.toml | 2 +- chain-factory/Cargo.toml | 4 ++-- chain-factory/meta/Cargo.toml | 2 +- chain-factory/wasm/Cargo.lock | 16 +++++++-------- chain-factory/wasm/Cargo.toml | 2 +- common/bls-signature/Cargo.toml | 4 ++-- common/max-bridged-amount-module/Cargo.toml | 4 ++-- common/setup-phase/Cargo.toml | 4 ++-- common/token-whitelist/Cargo.toml | 4 ++-- common/transaction/Cargo.toml | 2 +- common/tx-batch-module/Cargo.toml | 4 ++-- common/utils/Cargo.toml | 2 +- delegation-mock/Cargo.toml | 4 ++-- delegation-mock/meta/Cargo.toml | 2 +- .../wasm-delegation-mock-full/Cargo.lock | 12 +++++------ .../wasm-delegation-mock-full/Cargo.toml | 2 +- .../wasm-delegation-mock-view/Cargo.lock | 12 +++++------ .../wasm-delegation-mock-view/Cargo.toml | 2 +- delegation-mock/wasm/Cargo.lock | 12 +++++------ delegation-mock/wasm/Cargo.toml | 2 +- enshrine-esdt-safe/Cargo.toml | 6 +++--- enshrine-esdt-safe/meta/Cargo.toml | 2 +- .../wasm-enshrine-esdt-safe-full/Cargo.lock | 16 +++++++-------- .../wasm-enshrine-esdt-safe-full/Cargo.toml | 2 +- .../wasm-enshrine-esdt-safe-view/Cargo.lock | 16 +++++++-------- .../wasm-enshrine-esdt-safe-view/Cargo.toml | 2 +- enshrine-esdt-safe/wasm/Cargo.lock | 16 +++++++-------- enshrine-esdt-safe/wasm/Cargo.toml | 2 +- esdt-safe/Cargo.toml | 6 +++--- esdt-safe/meta/Cargo.toml | 2 +- esdt-safe/wasm-esdt-safe-full/Cargo.lock | 16 +++++++-------- esdt-safe/wasm-esdt-safe-full/Cargo.toml | 2 +- esdt-safe/wasm-esdt-safe-view/Cargo.lock | 16 +++++++-------- esdt-safe/wasm-esdt-safe-view/Cargo.toml | 2 +- esdt-safe/wasm/Cargo.lock | 16 +++++++-------- esdt-safe/wasm/Cargo.toml | 2 +- fee-market/Cargo.toml | 4 ++-- fee-market/meta/Cargo.toml | 2 +- fee-market/wasm-fee-marker-full/Cargo.lock | 12 +++++------ fee-market/wasm-fee-marker-full/Cargo.toml | 2 +- fee-market/wasm-multisig-view/Cargo.lock | 12 +++++------ fee-market/wasm-multisig-view/Cargo.toml | 2 +- fee-market/wasm/Cargo.lock | 12 +++++------ fee-market/wasm/Cargo.toml | 2 +- header-verifier/Cargo.toml | 4 ++-- header-verifier/meta/Cargo.toml | 2 +- .../wasm-header-verifier-full/Cargo.lock | 12 +++++------ .../wasm-header-verifier-full/Cargo.toml | 2 +- header-verifier/wasm-multisig-view/Cargo.lock | 12 +++++------ header-verifier/wasm-multisig-view/Cargo.toml | 2 +- header-verifier/wasm/Cargo.lock | 12 +++++------ header-verifier/wasm/Cargo.toml | 2 +- liquid-staking/Cargo.toml | 10 +++++----- liquid-staking/meta/Cargo.toml | 2 +- .../wasm-liquid-staking-full/Cargo.lock | 12 +++++------ .../wasm-liquid-staking-full/Cargo.toml | 2 +- .../wasm-liquid-staking-view/Cargo.lock | 12 +++++------ .../wasm-liquid-staking-view/Cargo.toml | 2 +- liquid-staking/wasm/Cargo.lock | 12 +++++------ liquid-staking/wasm/Cargo.toml | 2 +- 64 files changed, 208 insertions(+), 208 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b83ad7b6..854b0e0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -643,9 +643,9 @@ checksum = "b59072fa0624b55ae5ae3fa6bfa91515bbeb4ac440214bc4a509e2c8806d6e9f" [[package]] name = "multiversx-sc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +checksum = "e05f8dfb9c2dd26feff1330b1e229f0886f5c0228ed570f19421a458e6e7b0ef" dependencies = [ "bitflags", "hex-literal", @@ -681,9 +681,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +checksum = "f4b5176aa94b5e422e0d3c904492e0de0ae8381f166b563fbcac19a9ca4b28bc" dependencies = [ "hex", "proc-macro2", @@ -694,9 +694,9 @@ dependencies = [ [[package]] name = "multiversx-sc-meta-lib" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cadbd4a972764b864e7f6b73e6963df85f7010fbd3a993d820873809bce4e93" +checksum = "750e309894ebebad3675feb3d59bb709f826c07cbdf21adf5719b5ab2f23aa13" dependencies = [ "clap", "colored", @@ -715,18 +715,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fece2308326cc59c53fedd682259625e8ecc306e4c3b35051725ca388677b47b" +checksum = "3cfb6046ec3cc6ef94351b4ca89907b2b74b2e4a7f376adc0af18ddd1c5a4367" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-scenario" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe13bdcc09d9405c5767593359c8193dc05f8271423f76bd991cfabb90056e4c" +checksum = "701ca689a866acb88cf5022ec8bae1ba318065e5800f75dd76e3620d2a782ca0" dependencies = [ "base64", "bech32", diff --git a/chain-config/Cargo.toml b/chain-config/Cargo.toml index cd4744a4..d5d3fcd5 100644 --- a/chain-config/Cargo.toml +++ b/chain-config/Cargo.toml @@ -12,10 +12,10 @@ path = "src/lib.rs" num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.53.0" +version = "=0.53.1" [dependencies.multiversx-sc] -version = "=0.53.0" +version = "=0.53.1" [dependencies.multiversx-sc-modules] -version = "=0.53.0" +version = "=0.53.1" diff --git a/chain-config/meta/Cargo.toml b/chain-config/meta/Cargo.toml index ed0c1ef4..d5971030 100644 --- a/chain-config/meta/Cargo.toml +++ b/chain-config/meta/Cargo.toml @@ -11,4 +11,4 @@ authors = ["you"] path = ".." [dependencies.multiversx-sc-meta-lib] -version = "=0.53.0" +version = "=0.53.1" diff --git a/chain-config/wasm/Cargo.lock b/chain-config/wasm/Cargo.lock index 00dfb9ee..61d0dfb8 100644 --- a/chain-config/wasm/Cargo.lock +++ b/chain-config/wasm/Cargo.lock @@ -56,9 +56,9 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "multiversx-sc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +checksum = "e05f8dfb9c2dd26feff1330b1e229f0886f5c0228ed570f19421a458e6e7b0ef" dependencies = [ "bitflags", "hex-literal", @@ -93,9 +93,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +checksum = "f4b5176aa94b5e422e0d3c904492e0de0ae8381f166b563fbcac19a9ca4b28bc" dependencies = [ "hex", "proc-macro2", @@ -106,18 +106,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fece2308326cc59c53fedd682259625e8ecc306e4c3b35051725ca388677b47b" +checksum = "3cfb6046ec3cc6ef94351b4ca89907b2b74b2e4a7f376adc0af18ddd1c5a4367" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +checksum = "9aa0cbd543872f94b9bc98c4ce7c3ed25a7257e1425295af9036eba44893bdaa" dependencies = [ "multiversx-sc", ] diff --git a/chain-config/wasm/Cargo.toml b/chain-config/wasm/Cargo.toml index 5440d67d..6a696293 100644 --- a/chain-config/wasm/Cargo.toml +++ b/chain-config/wasm/Cargo.toml @@ -28,7 +28,7 @@ panic = "abort" path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.53.0" +version = "=0.53.1" [workspace] members = ["."] diff --git a/chain-factory/Cargo.toml b/chain-factory/Cargo.toml index de7f33a8..337846c5 100644 --- a/chain-factory/Cargo.toml +++ b/chain-factory/Cargo.toml @@ -12,10 +12,10 @@ path = "src/lib.rs" num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.53.0" +version = "=0.53.1" [dependencies.multiversx-sc] -version = "=0.53.0" +version = "=0.53.1" [dependencies.utils] path = "../common/utils" diff --git a/chain-factory/meta/Cargo.toml b/chain-factory/meta/Cargo.toml index 8db9cb29..6d3d98bb 100644 --- a/chain-factory/meta/Cargo.toml +++ b/chain-factory/meta/Cargo.toml @@ -11,4 +11,4 @@ authors = ["you"] path = ".." [dependencies.multiversx-sc-meta-lib] -version = "=0.53.0" +version = "=0.53.1" diff --git a/chain-factory/wasm/Cargo.lock b/chain-factory/wasm/Cargo.lock index 51ce0e6d..1a1b1683 100644 --- a/chain-factory/wasm/Cargo.lock +++ b/chain-factory/wasm/Cargo.lock @@ -74,9 +74,9 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "multiversx-sc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +checksum = "e05f8dfb9c2dd26feff1330b1e229f0886f5c0228ed570f19421a458e6e7b0ef" dependencies = [ "bitflags", "hex-literal", @@ -111,9 +111,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +checksum = "f4b5176aa94b5e422e0d3c904492e0de0ae8381f166b563fbcac19a9ca4b28bc" dependencies = [ "hex", "proc-macro2", @@ -124,18 +124,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fece2308326cc59c53fedd682259625e8ecc306e4c3b35051725ca388677b47b" +checksum = "3cfb6046ec3cc6ef94351b4ca89907b2b74b2e4a7f376adc0af18ddd1c5a4367" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +checksum = "9aa0cbd543872f94b9bc98c4ce7c3ed25a7257e1425295af9036eba44893bdaa" dependencies = [ "multiversx-sc", ] diff --git a/chain-factory/wasm/Cargo.toml b/chain-factory/wasm/Cargo.toml index acd7dbdf..da4b60be 100644 --- a/chain-factory/wasm/Cargo.toml +++ b/chain-factory/wasm/Cargo.toml @@ -28,7 +28,7 @@ panic = "abort" path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.53.0" +version = "=0.53.1" [workspace] members = ["."] diff --git a/common/bls-signature/Cargo.toml b/common/bls-signature/Cargo.toml index 2191447e..d82386b8 100644 --- a/common/bls-signature/Cargo.toml +++ b/common/bls-signature/Cargo.toml @@ -5,10 +5,10 @@ authors = ["dorin-iancu "] edition = "2018" [dependencies.multiversx-sc] -version = "=0.53.0" +version = "=0.53.1" [dependencies.transaction] path = "../transaction" [dev-dependencies.multiversx-sc-scenario] -version = "=0.53.0" +version = "=0.53.1" diff --git a/common/max-bridged-amount-module/Cargo.toml b/common/max-bridged-amount-module/Cargo.toml index bf7ff1b8..b3b13d94 100644 --- a/common/max-bridged-amount-module/Cargo.toml +++ b/common/max-bridged-amount-module/Cargo.toml @@ -5,7 +5,7 @@ authors = ["dorin-iancu "] edition = "2018" [dependencies.multiversx-sc] -version = "=0.53.0" +version = "=0.53.1" [dev-dependencies.multiversx-sc-scenario] -version = "=0.53.0" +version = "=0.53.1" diff --git a/common/setup-phase/Cargo.toml b/common/setup-phase/Cargo.toml index 66afa678..7d90b854 100644 --- a/common/setup-phase/Cargo.toml +++ b/common/setup-phase/Cargo.toml @@ -5,7 +5,7 @@ authors = ["dorin-iancu "] edition = "2018" [dependencies.multiversx-sc] -version = "=0.53.0" +version = "=0.53.1" [dev-dependencies.multiversx-sc-scenario] -version = "=0.53.0" +version = "=0.53.1" diff --git a/common/token-whitelist/Cargo.toml b/common/token-whitelist/Cargo.toml index 9f7fb637..47706a54 100644 --- a/common/token-whitelist/Cargo.toml +++ b/common/token-whitelist/Cargo.toml @@ -14,7 +14,7 @@ path = "../setup-phase" path = "../utils" [dependencies.multiversx-sc] -version = "=0.53.0" +version = "=0.53.1" [dev-dependencies.multiversx-sc-scenario] -version = "=0.53.0" +version = "=0.53.1" diff --git a/common/transaction/Cargo.toml b/common/transaction/Cargo.toml index e8a91e96..38641b06 100644 --- a/common/transaction/Cargo.toml +++ b/common/transaction/Cargo.toml @@ -8,4 +8,4 @@ edition = "2018" path = "src/lib.rs" [dependencies.multiversx-sc] -version = "=0.53.0" +version = "=0.53.1" diff --git a/common/tx-batch-module/Cargo.toml b/common/tx-batch-module/Cargo.toml index 1e0a090b..e85dee7f 100644 --- a/common/tx-batch-module/Cargo.toml +++ b/common/tx-batch-module/Cargo.toml @@ -5,10 +5,10 @@ authors = ["dorin-iancu "] edition = "2018" [dependencies.multiversx-sc] -version = "=0.53.0" +version = "=0.53.1" [dependencies.transaction] path = "../transaction" [dev-dependencies.multiversx-sc-scenario] -version = "=0.53.0" +version = "=0.53.1" diff --git a/common/utils/Cargo.toml b/common/utils/Cargo.toml index 76df98fc..3e546289 100644 --- a/common/utils/Cargo.toml +++ b/common/utils/Cargo.toml @@ -11,5 +11,5 @@ path = "src/lib.rs" path = "../bls-signature" [dependencies.multiversx-sc] -version = "=0.53.0" +version = "=0.53.1" features = ["esdt-token-payment-legacy-decode"] diff --git a/delegation-mock/Cargo.toml b/delegation-mock/Cargo.toml index 781b11aa..343b6999 100644 --- a/delegation-mock/Cargo.toml +++ b/delegation-mock/Cargo.toml @@ -9,10 +9,10 @@ authors = ["you"] path = "src/lib.rs" [dependencies.multiversx-sc] -version = "0.53.0" +version = "0.53.1" [dev-dependencies] num-bigint = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "0.53.0" +version = "0.53.1" diff --git a/delegation-mock/meta/Cargo.toml b/delegation-mock/meta/Cargo.toml index 46940456..b1973e66 100644 --- a/delegation-mock/meta/Cargo.toml +++ b/delegation-mock/meta/Cargo.toml @@ -8,5 +8,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta-lib] -version = "0.53.0" +version = "0.53.1" default-features = false diff --git a/delegation-mock/wasm-delegation-mock-full/Cargo.lock b/delegation-mock/wasm-delegation-mock-full/Cargo.lock index 61913684..24c30f79 100644 --- a/delegation-mock/wasm-delegation-mock-full/Cargo.lock +++ b/delegation-mock/wasm-delegation-mock-full/Cargo.lock @@ -55,9 +55,9 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "multiversx-sc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +checksum = "e05f8dfb9c2dd26feff1330b1e229f0886f5c0228ed570f19421a458e6e7b0ef" dependencies = [ "bitflags", "hex-literal", @@ -92,9 +92,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +checksum = "f4b5176aa94b5e422e0d3c904492e0de0ae8381f166b563fbcac19a9ca4b28bc" dependencies = [ "hex", "proc-macro2", @@ -105,9 +105,9 @@ dependencies = [ [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +checksum = "9aa0cbd543872f94b9bc98c4ce7c3ed25a7257e1425295af9036eba44893bdaa" dependencies = [ "multiversx-sc", ] diff --git a/delegation-mock/wasm-delegation-mock-full/Cargo.toml b/delegation-mock/wasm-delegation-mock-full/Cargo.toml index 72581d93..816e5617 100644 --- a/delegation-mock/wasm-delegation-mock-full/Cargo.toml +++ b/delegation-mock/wasm-delegation-mock-full/Cargo.toml @@ -28,7 +28,7 @@ panic = "abort" path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "0.53.0" +version = "0.53.1" [workspace] members = ["."] diff --git a/delegation-mock/wasm-delegation-mock-view/Cargo.lock b/delegation-mock/wasm-delegation-mock-view/Cargo.lock index 6333b15e..5ec02c4a 100644 --- a/delegation-mock/wasm-delegation-mock-view/Cargo.lock +++ b/delegation-mock/wasm-delegation-mock-view/Cargo.lock @@ -55,9 +55,9 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "multiversx-sc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +checksum = "e05f8dfb9c2dd26feff1330b1e229f0886f5c0228ed570f19421a458e6e7b0ef" dependencies = [ "bitflags", "hex-literal", @@ -92,9 +92,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +checksum = "f4b5176aa94b5e422e0d3c904492e0de0ae8381f166b563fbcac19a9ca4b28bc" dependencies = [ "hex", "proc-macro2", @@ -105,9 +105,9 @@ dependencies = [ [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +checksum = "9aa0cbd543872f94b9bc98c4ce7c3ed25a7257e1425295af9036eba44893bdaa" dependencies = [ "multiversx-sc", ] diff --git a/delegation-mock/wasm-delegation-mock-view/Cargo.toml b/delegation-mock/wasm-delegation-mock-view/Cargo.toml index 2d967eef..90f5fa9f 100644 --- a/delegation-mock/wasm-delegation-mock-view/Cargo.toml +++ b/delegation-mock/wasm-delegation-mock-view/Cargo.toml @@ -28,7 +28,7 @@ panic = "abort" path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "0.53.0" +version = "0.53.1" [workspace] members = ["."] diff --git a/delegation-mock/wasm/Cargo.lock b/delegation-mock/wasm/Cargo.lock index ebba8498..eadcfc49 100644 --- a/delegation-mock/wasm/Cargo.lock +++ b/delegation-mock/wasm/Cargo.lock @@ -55,9 +55,9 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "multiversx-sc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +checksum = "e05f8dfb9c2dd26feff1330b1e229f0886f5c0228ed570f19421a458e6e7b0ef" dependencies = [ "bitflags", "hex-literal", @@ -92,9 +92,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +checksum = "f4b5176aa94b5e422e0d3c904492e0de0ae8381f166b563fbcac19a9ca4b28bc" dependencies = [ "hex", "proc-macro2", @@ -105,9 +105,9 @@ dependencies = [ [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +checksum = "9aa0cbd543872f94b9bc98c4ce7c3ed25a7257e1425295af9036eba44893bdaa" dependencies = [ "multiversx-sc", ] diff --git a/delegation-mock/wasm/Cargo.toml b/delegation-mock/wasm/Cargo.toml index 0af2f187..696e7612 100644 --- a/delegation-mock/wasm/Cargo.toml +++ b/delegation-mock/wasm/Cargo.toml @@ -28,7 +28,7 @@ panic = "abort" path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "0.53.0" +version = "0.53.1" [workspace] members = ["."] diff --git a/enshrine-esdt-safe/Cargo.toml b/enshrine-esdt-safe/Cargo.toml index c258915a..e0741c62 100644 --- a/enshrine-esdt-safe/Cargo.toml +++ b/enshrine-esdt-safe/Cargo.toml @@ -36,10 +36,10 @@ path = "../fee-market" path = "../header-verifier" [dependencies.multiversx-sc] -version = "=0.53.0" +version = "=0.53.1" [dependencies.multiversx-sc-modules] -version = "=0.53.0" +version = "=0.53.1" [dev-dependencies] num-bigint = "0.4.2" @@ -47,4 +47,4 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "=0.53.0" +version = "=0.53.1" diff --git a/enshrine-esdt-safe/meta/Cargo.toml b/enshrine-esdt-safe/meta/Cargo.toml index 5ab95868..e3554570 100644 --- a/enshrine-esdt-safe/meta/Cargo.toml +++ b/enshrine-esdt-safe/meta/Cargo.toml @@ -8,5 +8,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta-lib] -version = "0.53.0" +version = "0.53.1" default-features = false diff --git a/enshrine-esdt-safe/wasm-enshrine-esdt-safe-full/Cargo.lock b/enshrine-esdt-safe/wasm-enshrine-esdt-safe-full/Cargo.lock index 7e40361e..e453bb9d 100644 --- a/enshrine-esdt-safe/wasm-enshrine-esdt-safe-full/Cargo.lock +++ b/enshrine-esdt-safe/wasm-enshrine-esdt-safe-full/Cargo.lock @@ -99,9 +99,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +checksum = "e05f8dfb9c2dd26feff1330b1e229f0886f5c0228ed570f19421a458e6e7b0ef" dependencies = [ "bitflags", "hex-literal", @@ -136,9 +136,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +checksum = "f4b5176aa94b5e422e0d3c904492e0de0ae8381f166b563fbcac19a9ca4b28bc" dependencies = [ "hex", "proc-macro2", @@ -149,18 +149,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fece2308326cc59c53fedd682259625e8ecc306e4c3b35051725ca388677b47b" +checksum = "3cfb6046ec3cc6ef94351b4ca89907b2b74b2e4a7f376adc0af18ddd1c5a4367" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +checksum = "9aa0cbd543872f94b9bc98c4ce7c3ed25a7257e1425295af9036eba44893bdaa" dependencies = [ "multiversx-sc", ] diff --git a/enshrine-esdt-safe/wasm-enshrine-esdt-safe-full/Cargo.toml b/enshrine-esdt-safe/wasm-enshrine-esdt-safe-full/Cargo.toml index 33313e4e..b2c0bb98 100644 --- a/enshrine-esdt-safe/wasm-enshrine-esdt-safe-full/Cargo.toml +++ b/enshrine-esdt-safe/wasm-enshrine-esdt-safe-full/Cargo.toml @@ -28,7 +28,7 @@ panic = "abort" path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.53.0" +version = "=0.53.1" [workspace] members = ["."] diff --git a/enshrine-esdt-safe/wasm-enshrine-esdt-safe-view/Cargo.lock b/enshrine-esdt-safe/wasm-enshrine-esdt-safe-view/Cargo.lock index fc4faaad..d246b09a 100644 --- a/enshrine-esdt-safe/wasm-enshrine-esdt-safe-view/Cargo.lock +++ b/enshrine-esdt-safe/wasm-enshrine-esdt-safe-view/Cargo.lock @@ -99,9 +99,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +checksum = "e05f8dfb9c2dd26feff1330b1e229f0886f5c0228ed570f19421a458e6e7b0ef" dependencies = [ "bitflags", "hex-literal", @@ -136,9 +136,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +checksum = "f4b5176aa94b5e422e0d3c904492e0de0ae8381f166b563fbcac19a9ca4b28bc" dependencies = [ "hex", "proc-macro2", @@ -149,18 +149,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fece2308326cc59c53fedd682259625e8ecc306e4c3b35051725ca388677b47b" +checksum = "3cfb6046ec3cc6ef94351b4ca89907b2b74b2e4a7f376adc0af18ddd1c5a4367" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +checksum = "9aa0cbd543872f94b9bc98c4ce7c3ed25a7257e1425295af9036eba44893bdaa" dependencies = [ "multiversx-sc", ] diff --git a/enshrine-esdt-safe/wasm-enshrine-esdt-safe-view/Cargo.toml b/enshrine-esdt-safe/wasm-enshrine-esdt-safe-view/Cargo.toml index 803a9e8b..20369a4d 100644 --- a/enshrine-esdt-safe/wasm-enshrine-esdt-safe-view/Cargo.toml +++ b/enshrine-esdt-safe/wasm-enshrine-esdt-safe-view/Cargo.toml @@ -28,7 +28,7 @@ panic = "abort" path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.53.0" +version = "=0.53.1" [workspace] members = ["."] diff --git a/enshrine-esdt-safe/wasm/Cargo.lock b/enshrine-esdt-safe/wasm/Cargo.lock index 6cda2691..f5163c4c 100644 --- a/enshrine-esdt-safe/wasm/Cargo.lock +++ b/enshrine-esdt-safe/wasm/Cargo.lock @@ -99,9 +99,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +checksum = "e05f8dfb9c2dd26feff1330b1e229f0886f5c0228ed570f19421a458e6e7b0ef" dependencies = [ "bitflags", "hex-literal", @@ -136,9 +136,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +checksum = "f4b5176aa94b5e422e0d3c904492e0de0ae8381f166b563fbcac19a9ca4b28bc" dependencies = [ "hex", "proc-macro2", @@ -149,18 +149,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fece2308326cc59c53fedd682259625e8ecc306e4c3b35051725ca388677b47b" +checksum = "3cfb6046ec3cc6ef94351b4ca89907b2b74b2e4a7f376adc0af18ddd1c5a4367" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +checksum = "9aa0cbd543872f94b9bc98c4ce7c3ed25a7257e1425295af9036eba44893bdaa" dependencies = [ "multiversx-sc", ] diff --git a/enshrine-esdt-safe/wasm/Cargo.toml b/enshrine-esdt-safe/wasm/Cargo.toml index 83bf78ef..8edc5c62 100644 --- a/enshrine-esdt-safe/wasm/Cargo.toml +++ b/enshrine-esdt-safe/wasm/Cargo.toml @@ -28,7 +28,7 @@ panic = "abort" path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.53.0" +version = "=0.53.1" [workspace] members = ["."] diff --git a/esdt-safe/Cargo.toml b/esdt-safe/Cargo.toml index c089a976..0446986a 100644 --- a/esdt-safe/Cargo.toml +++ b/esdt-safe/Cargo.toml @@ -36,10 +36,10 @@ path = "../fee-market" path = "../header-verifier" [dependencies.multiversx-sc] -version = "=0.53.0" +version = "=0.53.1" [dependencies.multiversx-sc-modules] -version = "=0.53.0" +version = "=0.53.1" [dev-dependencies] num-bigint = "0.4.2" @@ -47,4 +47,4 @@ num-traits = "0.2" hex = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "=0.53.0" +version = "=0.53.1" diff --git a/esdt-safe/meta/Cargo.toml b/esdt-safe/meta/Cargo.toml index 66439304..e01c2c40 100644 --- a/esdt-safe/meta/Cargo.toml +++ b/esdt-safe/meta/Cargo.toml @@ -11,4 +11,4 @@ publish = false path = ".." [dependencies.multiversx-sc-meta-lib] -version = "=0.53.0" +version = "=0.53.1" diff --git a/esdt-safe/wasm-esdt-safe-full/Cargo.lock b/esdt-safe/wasm-esdt-safe-full/Cargo.lock index 033da2d0..ef2e581d 100644 --- a/esdt-safe/wasm-esdt-safe-full/Cargo.lock +++ b/esdt-safe/wasm-esdt-safe-full/Cargo.lock @@ -99,9 +99,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +checksum = "e05f8dfb9c2dd26feff1330b1e229f0886f5c0228ed570f19421a458e6e7b0ef" dependencies = [ "bitflags", "hex-literal", @@ -136,9 +136,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +checksum = "f4b5176aa94b5e422e0d3c904492e0de0ae8381f166b563fbcac19a9ca4b28bc" dependencies = [ "hex", "proc-macro2", @@ -149,18 +149,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fece2308326cc59c53fedd682259625e8ecc306e4c3b35051725ca388677b47b" +checksum = "3cfb6046ec3cc6ef94351b4ca89907b2b74b2e4a7f376adc0af18ddd1c5a4367" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +checksum = "9aa0cbd543872f94b9bc98c4ce7c3ed25a7257e1425295af9036eba44893bdaa" dependencies = [ "multiversx-sc", ] diff --git a/esdt-safe/wasm-esdt-safe-full/Cargo.toml b/esdt-safe/wasm-esdt-safe-full/Cargo.toml index d7a38dde..135d06a4 100644 --- a/esdt-safe/wasm-esdt-safe-full/Cargo.toml +++ b/esdt-safe/wasm-esdt-safe-full/Cargo.toml @@ -28,7 +28,7 @@ panic = "abort" path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.53.0" +version = "=0.53.1" [workspace] members = ["."] diff --git a/esdt-safe/wasm-esdt-safe-view/Cargo.lock b/esdt-safe/wasm-esdt-safe-view/Cargo.lock index 93bb6f82..4073ba2a 100644 --- a/esdt-safe/wasm-esdt-safe-view/Cargo.lock +++ b/esdt-safe/wasm-esdt-safe-view/Cargo.lock @@ -99,9 +99,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +checksum = "e05f8dfb9c2dd26feff1330b1e229f0886f5c0228ed570f19421a458e6e7b0ef" dependencies = [ "bitflags", "hex-literal", @@ -136,9 +136,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +checksum = "f4b5176aa94b5e422e0d3c904492e0de0ae8381f166b563fbcac19a9ca4b28bc" dependencies = [ "hex", "proc-macro2", @@ -149,18 +149,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fece2308326cc59c53fedd682259625e8ecc306e4c3b35051725ca388677b47b" +checksum = "3cfb6046ec3cc6ef94351b4ca89907b2b74b2e4a7f376adc0af18ddd1c5a4367" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +checksum = "9aa0cbd543872f94b9bc98c4ce7c3ed25a7257e1425295af9036eba44893bdaa" dependencies = [ "multiversx-sc", ] diff --git a/esdt-safe/wasm-esdt-safe-view/Cargo.toml b/esdt-safe/wasm-esdt-safe-view/Cargo.toml index e5e1aea7..72e8e214 100644 --- a/esdt-safe/wasm-esdt-safe-view/Cargo.toml +++ b/esdt-safe/wasm-esdt-safe-view/Cargo.toml @@ -28,7 +28,7 @@ panic = "abort" path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.53.0" +version = "=0.53.1" [workspace] members = ["."] diff --git a/esdt-safe/wasm/Cargo.lock b/esdt-safe/wasm/Cargo.lock index 581b427f..0b6a5ce7 100644 --- a/esdt-safe/wasm/Cargo.lock +++ b/esdt-safe/wasm/Cargo.lock @@ -99,9 +99,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +checksum = "e05f8dfb9c2dd26feff1330b1e229f0886f5c0228ed570f19421a458e6e7b0ef" dependencies = [ "bitflags", "hex-literal", @@ -136,9 +136,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +checksum = "f4b5176aa94b5e422e0d3c904492e0de0ae8381f166b563fbcac19a9ca4b28bc" dependencies = [ "hex", "proc-macro2", @@ -149,18 +149,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fece2308326cc59c53fedd682259625e8ecc306e4c3b35051725ca388677b47b" +checksum = "3cfb6046ec3cc6ef94351b4ca89907b2b74b2e4a7f376adc0af18ddd1c5a4367" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +checksum = "9aa0cbd543872f94b9bc98c4ce7c3ed25a7257e1425295af9036eba44893bdaa" dependencies = [ "multiversx-sc", ] diff --git a/esdt-safe/wasm/Cargo.toml b/esdt-safe/wasm/Cargo.toml index a656a808..6d4995dd 100644 --- a/esdt-safe/wasm/Cargo.toml +++ b/esdt-safe/wasm/Cargo.toml @@ -28,7 +28,7 @@ panic = "abort" path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.53.0" +version = "=0.53.1" [workspace] members = ["."] diff --git a/fee-market/Cargo.toml b/fee-market/Cargo.toml index 3ddd705f..eca63495 100644 --- a/fee-market/Cargo.toml +++ b/fee-market/Cargo.toml @@ -18,10 +18,10 @@ path = "../common/transaction" path = "../common/bls-signature" [dependencies.multiversx-sc] -version = "=0.53.0" +version = "=0.53.1" [dev-dependencies] num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "=0.53.0" +version = "=0.53.1" diff --git a/fee-market/meta/Cargo.toml b/fee-market/meta/Cargo.toml index 605e19b9..28f67f70 100644 --- a/fee-market/meta/Cargo.toml +++ b/fee-market/meta/Cargo.toml @@ -8,5 +8,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta-lib] -version = "=0.53.0" +version = "=0.53.1" default-features = false diff --git a/fee-market/wasm-fee-marker-full/Cargo.lock b/fee-market/wasm-fee-marker-full/Cargo.lock index 047ada14..d9c9d464 100644 --- a/fee-market/wasm-fee-marker-full/Cargo.lock +++ b/fee-market/wasm-fee-marker-full/Cargo.lock @@ -66,9 +66,9 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "multiversx-sc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +checksum = "e05f8dfb9c2dd26feff1330b1e229f0886f5c0228ed570f19421a458e6e7b0ef" dependencies = [ "bitflags", "hex-literal", @@ -103,9 +103,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +checksum = "f4b5176aa94b5e422e0d3c904492e0de0ae8381f166b563fbcac19a9ca4b28bc" dependencies = [ "hex", "proc-macro2", @@ -116,9 +116,9 @@ dependencies = [ [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +checksum = "9aa0cbd543872f94b9bc98c4ce7c3ed25a7257e1425295af9036eba44893bdaa" dependencies = [ "multiversx-sc", ] diff --git a/fee-market/wasm-fee-marker-full/Cargo.toml b/fee-market/wasm-fee-marker-full/Cargo.toml index 05f8f890..9bef5fca 100644 --- a/fee-market/wasm-fee-marker-full/Cargo.toml +++ b/fee-market/wasm-fee-marker-full/Cargo.toml @@ -28,7 +28,7 @@ panic = "abort" path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.53.0" +version = "=0.53.1" [workspace] members = ["."] diff --git a/fee-market/wasm-multisig-view/Cargo.lock b/fee-market/wasm-multisig-view/Cargo.lock index 106db055..c6ba5733 100644 --- a/fee-market/wasm-multisig-view/Cargo.lock +++ b/fee-market/wasm-multisig-view/Cargo.lock @@ -66,9 +66,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +checksum = "e05f8dfb9c2dd26feff1330b1e229f0886f5c0228ed570f19421a458e6e7b0ef" dependencies = [ "bitflags", "hex-literal", @@ -103,9 +103,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +checksum = "f4b5176aa94b5e422e0d3c904492e0de0ae8381f166b563fbcac19a9ca4b28bc" dependencies = [ "hex", "proc-macro2", @@ -116,9 +116,9 @@ dependencies = [ [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +checksum = "9aa0cbd543872f94b9bc98c4ce7c3ed25a7257e1425295af9036eba44893bdaa" dependencies = [ "multiversx-sc", ] diff --git a/fee-market/wasm-multisig-view/Cargo.toml b/fee-market/wasm-multisig-view/Cargo.toml index 347109b0..de4d4718 100644 --- a/fee-market/wasm-multisig-view/Cargo.toml +++ b/fee-market/wasm-multisig-view/Cargo.toml @@ -28,7 +28,7 @@ panic = "abort" path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.53.0" +version = "=0.53.1" [workspace] members = ["."] diff --git a/fee-market/wasm/Cargo.lock b/fee-market/wasm/Cargo.lock index a9194490..9cfc7c0f 100644 --- a/fee-market/wasm/Cargo.lock +++ b/fee-market/wasm/Cargo.lock @@ -66,9 +66,9 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "multiversx-sc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +checksum = "e05f8dfb9c2dd26feff1330b1e229f0886f5c0228ed570f19421a458e6e7b0ef" dependencies = [ "bitflags", "hex-literal", @@ -103,9 +103,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +checksum = "f4b5176aa94b5e422e0d3c904492e0de0ae8381f166b563fbcac19a9ca4b28bc" dependencies = [ "hex", "proc-macro2", @@ -116,9 +116,9 @@ dependencies = [ [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +checksum = "9aa0cbd543872f94b9bc98c4ce7c3ed25a7257e1425295af9036eba44893bdaa" dependencies = [ "multiversx-sc", ] diff --git a/fee-market/wasm/Cargo.toml b/fee-market/wasm/Cargo.toml index 11cd4d4c..537b7554 100644 --- a/fee-market/wasm/Cargo.toml +++ b/fee-market/wasm/Cargo.toml @@ -28,7 +28,7 @@ panic = "abort" path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "=0.53.0" +version = "=0.53.1" [workspace] members = ["."] diff --git a/header-verifier/Cargo.toml b/header-verifier/Cargo.toml index 8aa18a42..59ab99ce 100644 --- a/header-verifier/Cargo.toml +++ b/header-verifier/Cargo.toml @@ -9,7 +9,7 @@ publish = false path = "src/lib.rs" [dependencies.multiversx-sc] -version = "0.53.0" +version = "0.53.1" [dependencies.bls-signature] path = "../common/bls-signature" @@ -21,4 +21,4 @@ path = "../common/transaction" num-bigint = "0.4.2" [dev-dependencies.multiversx-sc-scenario] -version = "0.53.0" +version = "0.53.1" diff --git a/header-verifier/meta/Cargo.toml b/header-verifier/meta/Cargo.toml index ed1949b9..28c50118 100644 --- a/header-verifier/meta/Cargo.toml +++ b/header-verifier/meta/Cargo.toml @@ -8,5 +8,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta-lib] -version = "0.53.0" +version = "0.53.1" default-features = false diff --git a/header-verifier/wasm-header-verifier-full/Cargo.lock b/header-verifier/wasm-header-verifier-full/Cargo.lock index b5f001af..bca57c41 100644 --- a/header-verifier/wasm-header-verifier-full/Cargo.lock +++ b/header-verifier/wasm-header-verifier-full/Cargo.lock @@ -65,9 +65,9 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "multiversx-sc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +checksum = "e05f8dfb9c2dd26feff1330b1e229f0886f5c0228ed570f19421a458e6e7b0ef" dependencies = [ "bitflags", "hex-literal", @@ -102,9 +102,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +checksum = "f4b5176aa94b5e422e0d3c904492e0de0ae8381f166b563fbcac19a9ca4b28bc" dependencies = [ "hex", "proc-macro2", @@ -115,9 +115,9 @@ dependencies = [ [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +checksum = "9aa0cbd543872f94b9bc98c4ce7c3ed25a7257e1425295af9036eba44893bdaa" dependencies = [ "multiversx-sc", ] diff --git a/header-verifier/wasm-header-verifier-full/Cargo.toml b/header-verifier/wasm-header-verifier-full/Cargo.toml index 844daf89..f4de6c91 100644 --- a/header-verifier/wasm-header-verifier-full/Cargo.toml +++ b/header-verifier/wasm-header-verifier-full/Cargo.toml @@ -28,7 +28,7 @@ panic = "abort" path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "0.53.0" +version = "0.53.1" [workspace] members = ["."] diff --git a/header-verifier/wasm-multisig-view/Cargo.lock b/header-verifier/wasm-multisig-view/Cargo.lock index 11054e22..06233ac3 100644 --- a/header-verifier/wasm-multisig-view/Cargo.lock +++ b/header-verifier/wasm-multisig-view/Cargo.lock @@ -65,9 +65,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +checksum = "e05f8dfb9c2dd26feff1330b1e229f0886f5c0228ed570f19421a458e6e7b0ef" dependencies = [ "bitflags", "hex-literal", @@ -102,9 +102,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +checksum = "f4b5176aa94b5e422e0d3c904492e0de0ae8381f166b563fbcac19a9ca4b28bc" dependencies = [ "hex", "proc-macro2", @@ -115,9 +115,9 @@ dependencies = [ [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +checksum = "9aa0cbd543872f94b9bc98c4ce7c3ed25a7257e1425295af9036eba44893bdaa" dependencies = [ "multiversx-sc", ] diff --git a/header-verifier/wasm-multisig-view/Cargo.toml b/header-verifier/wasm-multisig-view/Cargo.toml index 02396926..e99867bb 100644 --- a/header-verifier/wasm-multisig-view/Cargo.toml +++ b/header-verifier/wasm-multisig-view/Cargo.toml @@ -28,7 +28,7 @@ panic = "abort" path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "0.53.0" +version = "0.53.1" [workspace] members = ["."] diff --git a/header-verifier/wasm/Cargo.lock b/header-verifier/wasm/Cargo.lock index bd5315a4..361892b4 100644 --- a/header-verifier/wasm/Cargo.lock +++ b/header-verifier/wasm/Cargo.lock @@ -65,9 +65,9 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "multiversx-sc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +checksum = "e05f8dfb9c2dd26feff1330b1e229f0886f5c0228ed570f19421a458e6e7b0ef" dependencies = [ "bitflags", "hex-literal", @@ -102,9 +102,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +checksum = "f4b5176aa94b5e422e0d3c904492e0de0ae8381f166b563fbcac19a9ca4b28bc" dependencies = [ "hex", "proc-macro2", @@ -115,9 +115,9 @@ dependencies = [ [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +checksum = "9aa0cbd543872f94b9bc98c4ce7c3ed25a7257e1425295af9036eba44893bdaa" dependencies = [ "multiversx-sc", ] diff --git a/header-verifier/wasm/Cargo.toml b/header-verifier/wasm/Cargo.toml index 739674f5..e38bcab7 100644 --- a/header-verifier/wasm/Cargo.toml +++ b/header-verifier/wasm/Cargo.toml @@ -28,7 +28,7 @@ panic = "abort" path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "0.53.0" +version = "0.53.1" [workspace] members = ["."] diff --git a/liquid-staking/Cargo.toml b/liquid-staking/Cargo.toml index 4fbcbe0a..dfa56e32 100644 --- a/liquid-staking/Cargo.toml +++ b/liquid-staking/Cargo.toml @@ -9,13 +9,13 @@ publish = false path = "src/lib.rs" [dependencies.multiversx-sc] -version = "0.53.0" +version = "0.53.1" + +[dependencies.delegation-mock] +path = "../delegation-mock" [dev-dependencies] num-bigint = "0.4" [dev-dependencies.multiversx-sc-scenario] -version = "0.53.0" - -[dependencies.delegation-mock] -path = "../delegation-mock" +version = "0.53.1" diff --git a/liquid-staking/meta/Cargo.toml b/liquid-staking/meta/Cargo.toml index 7df8c061..f6a20c47 100644 --- a/liquid-staking/meta/Cargo.toml +++ b/liquid-staking/meta/Cargo.toml @@ -8,5 +8,5 @@ publish = false path = ".." [dependencies.multiversx-sc-meta-lib] -version = "0.53.0" +version = "0.53.1" default-features = false diff --git a/liquid-staking/wasm-liquid-staking-full/Cargo.lock b/liquid-staking/wasm-liquid-staking-full/Cargo.lock index f3de6992..38d91fa4 100644 --- a/liquid-staking/wasm-liquid-staking-full/Cargo.lock +++ b/liquid-staking/wasm-liquid-staking-full/Cargo.lock @@ -63,9 +63,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +checksum = "e05f8dfb9c2dd26feff1330b1e229f0886f5c0228ed570f19421a458e6e7b0ef" dependencies = [ "bitflags", "hex-literal", @@ -100,9 +100,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +checksum = "f4b5176aa94b5e422e0d3c904492e0de0ae8381f166b563fbcac19a9ca4b28bc" dependencies = [ "hex", "proc-macro2", @@ -113,9 +113,9 @@ dependencies = [ [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +checksum = "9aa0cbd543872f94b9bc98c4ce7c3ed25a7257e1425295af9036eba44893bdaa" dependencies = [ "multiversx-sc", ] diff --git a/liquid-staking/wasm-liquid-staking-full/Cargo.toml b/liquid-staking/wasm-liquid-staking-full/Cargo.toml index 4055ac4e..2ce419ba 100644 --- a/liquid-staking/wasm-liquid-staking-full/Cargo.toml +++ b/liquid-staking/wasm-liquid-staking-full/Cargo.toml @@ -28,7 +28,7 @@ panic = "abort" path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "0.53.0" +version = "0.53.1" [workspace] members = ["."] diff --git a/liquid-staking/wasm-liquid-staking-view/Cargo.lock b/liquid-staking/wasm-liquid-staking-view/Cargo.lock index 545a053a..eefc4527 100644 --- a/liquid-staking/wasm-liquid-staking-view/Cargo.lock +++ b/liquid-staking/wasm-liquid-staking-view/Cargo.lock @@ -63,9 +63,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +checksum = "e05f8dfb9c2dd26feff1330b1e229f0886f5c0228ed570f19421a458e6e7b0ef" dependencies = [ "bitflags", "hex-literal", @@ -100,9 +100,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +checksum = "f4b5176aa94b5e422e0d3c904492e0de0ae8381f166b563fbcac19a9ca4b28bc" dependencies = [ "hex", "proc-macro2", @@ -113,9 +113,9 @@ dependencies = [ [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +checksum = "9aa0cbd543872f94b9bc98c4ce7c3ed25a7257e1425295af9036eba44893bdaa" dependencies = [ "multiversx-sc", ] diff --git a/liquid-staking/wasm-liquid-staking-view/Cargo.toml b/liquid-staking/wasm-liquid-staking-view/Cargo.toml index 5825cb43..2ea3a0d6 100644 --- a/liquid-staking/wasm-liquid-staking-view/Cargo.toml +++ b/liquid-staking/wasm-liquid-staking-view/Cargo.toml @@ -28,7 +28,7 @@ panic = "abort" path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "0.53.0" +version = "0.53.1" [workspace] members = ["."] diff --git a/liquid-staking/wasm/Cargo.lock b/liquid-staking/wasm/Cargo.lock index 1e57a352..1961cca8 100644 --- a/liquid-staking/wasm/Cargo.lock +++ b/liquid-staking/wasm/Cargo.lock @@ -63,9 +63,9 @@ dependencies = [ [[package]] name = "multiversx-sc" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a86a27b04bb7cca97ad8971ee57e6b978619623dde4ba9acae1d4ecb436f062" +checksum = "e05f8dfb9c2dd26feff1330b1e229f0886f5c0228ed570f19421a458e6e7b0ef" dependencies = [ "bitflags", "hex-literal", @@ -100,9 +100,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7a6ee275d6b1c2b86394369df0bc62a3f25018cbab12668a191b89d88fdcf71" +checksum = "f4b5176aa94b5e422e0d3c904492e0de0ae8381f166b563fbcac19a9ca4b28bc" dependencies = [ "hex", "proc-macro2", @@ -113,9 +113,9 @@ dependencies = [ [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.53.0" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab5bb42b3ce827227a5e38f3c24fbe0fb23d475425b049043e193186e36c590" +checksum = "9aa0cbd543872f94b9bc98c4ce7c3ed25a7257e1425295af9036eba44893bdaa" dependencies = [ "multiversx-sc", ] diff --git a/liquid-staking/wasm/Cargo.toml b/liquid-staking/wasm/Cargo.toml index c23d0d28..bf40eca0 100644 --- a/liquid-staking/wasm/Cargo.toml +++ b/liquid-staking/wasm/Cargo.toml @@ -28,7 +28,7 @@ panic = "abort" path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "0.53.0" +version = "0.53.1" [workspace] members = ["."] From 21138d7f50a7177deb2c2bd131faaab8fe113707 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:00:00 +0300 Subject: [PATCH 66/98] Removed endpoint alias Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 57efc0b2..05ef8d82 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -9,7 +9,7 @@ use crate::common::{self, storage::Epoch}; #[multiversx_sc::module] pub trait DelegationModule: common::storage::CommonStorageModule { #[payable("EGLD")] - #[endpoint(stake)] + #[endpoint] fn stake(&self, contract_name: ManagedBuffer) { let caller = self.blockchain().get_caller(); let egld_amount = self.call_value().egld_value().clone_value(); @@ -85,7 +85,7 @@ pub trait DelegationModule: common::storage::CommonStorageModule { } } - #[endpoint(claimRewardsFromDelegation)] + #[endpoint] fn claim_rewards_from_delegation(&self, contracts: MultiValueEncoded) { let caller = self.blockchain().get_caller(); self.require_caller_has_stake(&caller); @@ -116,7 +116,7 @@ pub trait DelegationModule: common::storage::CommonStorageModule { } // NOTE: Should this also add to the map ? - #[endpoint(slashValidator)] + #[endpoint] fn slash_validator( &self, validator_address: ManagedAddress, @@ -158,6 +158,6 @@ pub trait DelegationModule: common::storage::CommonStorageModule { // lock amount with ChainConfigSC } - #[endpoint(claimRewards)] + #[endpoint] fn claim_rewards(&self) {} } From a422a0fa7dad7508f7a2361ee93b8584c1cbdb2f Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:01:23 +0300 Subject: [PATCH 67/98] Removed `Self::Api` for framwork types Signed-off-by: Andrei Baltariu --- liquid-staking/src/common/storage.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/liquid-staking/src/common/storage.rs b/liquid-staking/src/common/storage.rs index a7b01874..a104f0ea 100644 --- a/liquid-staking/src/common/storage.rs +++ b/liquid-staking/src/common/storage.rs @@ -12,7 +12,7 @@ pub trait CommonStorageModule { #[view(getDelegatedValue)] #[storage_mapper("delegatedValue")] - fn delegated_value(&self, validator: &ManagedAddress) -> SingleValueMapper>; + fn delegated_value(&self, validator: &ManagedAddress) -> SingleValueMapper; #[view(unDelegateEpoch)] #[storage_mapper("unDelegateEpoch")] @@ -40,7 +40,7 @@ pub trait CommonStorageModule { // NOTE: Number of nodes where ? #[view(lockedSupply)] #[storage_mapper("lockerSupply")] - fn locked_supply(&self, chain_id: ManagedBuffer) -> SingleValueMapper>; + fn locked_supply(&self, chain_id: ManagedBuffer) -> SingleValueMapper; fn require_bls_key_to_be_registered(&self, bls_key: &ManagedBuffer) { require!( From 1c93eb7ec6542ea9474a111686730f1a8a9fb304 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:03:14 +0300 Subject: [PATCH 68/98] Added custom type for BlsKey Signed-off-by: Andrei Baltariu --- liquid-staking/src/common/storage.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/liquid-staking/src/common/storage.rs b/liquid-staking/src/common/storage.rs index a104f0ea..a04ad9bc 100644 --- a/liquid-staking/src/common/storage.rs +++ b/liquid-staking/src/common/storage.rs @@ -1,5 +1,6 @@ use multiversx_sc::imports::*; pub type Epoch = u64; +pub type BlsKey = ManagedBuffer; #[multiversx_sc::module] pub trait CommonStorageModule { @@ -28,13 +29,13 @@ pub trait CommonStorageModule { #[view(getRegisteredBlsKeys)] #[storage_mapper("registeredBlsKeys")] - fn registered_bls_keys(&self) -> UnorderedSetMapper; + fn registered_bls_keys(&self) -> UnorderedSetMapper>; #[view(validatorBlsKeyMap)] #[storage_mapper("validatorBlsKeyMap")] fn validator_bls_key_address_map( &self, - bls_key: &ManagedBuffer, + bls_key: &BlsKey, ) -> SingleValueMapper; // NOTE: Number of nodes where ? @@ -42,7 +43,7 @@ pub trait CommonStorageModule { #[storage_mapper("lockerSupply")] fn locked_supply(&self, chain_id: ManagedBuffer) -> SingleValueMapper; - fn require_bls_key_to_be_registered(&self, bls_key: &ManagedBuffer) { + fn require_bls_key_to_be_registered(&self, bls_key: &BlsKey) { require!( self.registered_bls_keys().contains(bls_key), "The given bls key is not registered" From 463b891270351804799c4723496489f60bc0aaa7 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:06:35 +0300 Subject: [PATCH 69/98] Added custom type for ChainId and used custom types where is needed Signed-off-by: Andrei Baltariu --- liquid-staking/src/common/storage.rs | 3 ++- liquid-staking/src/delegation.rs | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/liquid-staking/src/common/storage.rs b/liquid-staking/src/common/storage.rs index a04ad9bc..4f318aae 100644 --- a/liquid-staking/src/common/storage.rs +++ b/liquid-staking/src/common/storage.rs @@ -1,6 +1,7 @@ use multiversx_sc::imports::*; pub type Epoch = u64; pub type BlsKey = ManagedBuffer; +pub type ChainId = ManagedBuffer; #[multiversx_sc::module] pub trait CommonStorageModule { @@ -41,7 +42,7 @@ pub trait CommonStorageModule { // NOTE: Number of nodes where ? #[view(lockedSupply)] #[storage_mapper("lockerSupply")] - fn locked_supply(&self, chain_id: ManagedBuffer) -> SingleValueMapper; + fn locked_supply(&self, chain_id: ChainId) -> SingleValueMapper; fn require_bls_key_to_be_registered(&self, bls_key: &BlsKey) { require!( diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 05ef8d82..f26cb4ef 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -4,7 +4,10 @@ pub const DELEGATE_ENDPOINT: &str = "delegate"; pub const UNDELEGATE_ENDPOINT: &str = "unDelegate"; pub const CLAIM_REWARDS_ENDPOINT: &str = "claimRewards"; -use crate::common::{self, storage::Epoch}; +use crate::common::{ + self, + storage::{BlsKey, ChainId, Epoch}, +}; #[multiversx_sc::module] pub trait DelegationModule: common::storage::CommonStorageModule { @@ -120,7 +123,7 @@ pub trait DelegationModule: common::storage::CommonStorageModule { fn slash_validator( &self, validator_address: ManagedAddress, - bls_key: ManagedBuffer, + bls_key: BlsKey, value_to_slash: BigUint, ) { let caller = self.blockchain().get_caller(); @@ -148,7 +151,7 @@ pub trait DelegationModule: common::storage::CommonStorageModule { #[payable("EGLD")] #[endpoint(lockForSovereignChain)] - fn lock_for_sovereign_chain(&self, chain_id: ManagedBuffer) { + fn lock_for_sovereign_chain(&self, chain_id: ChainId) { let call_value = self.call_value().egld_value().clone_value(); require!(call_value > 0, "No value send to lock"); From c71079c0b4546fed5d610d06684d173cef05d034 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:07:54 +0300 Subject: [PATCH 70/98] Switched endpoint names from &str to &[u8] Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index f26cb4ef..95c741b1 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -1,8 +1,8 @@ use multiversx_sc::imports::*; pub const UNBOND_PERIOD: u64 = 10; -pub const DELEGATE_ENDPOINT: &str = "delegate"; -pub const UNDELEGATE_ENDPOINT: &str = "unDelegate"; -pub const CLAIM_REWARDS_ENDPOINT: &str = "claimRewards"; +pub const DELEGATE_ENDPOINT: &[u8] = b"delegate"; +pub const UNDELEGATE_ENDPOINT: &[u8] = b"unDelegate"; +pub const CLAIM_REWARDS_ENDPOINT: &[u8] = b"claimRewards"; use crate::common::{ self, From e450715fc0ef2cb0dfa12f5589d32428540d72d4 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:08:59 +0300 Subject: [PATCH 71/98] Modified stake_callback storage mapper value modification Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 95c741b1..0b3c4cf5 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -35,7 +35,8 @@ pub trait DelegationModule: common::storage::CommonStorageModule { ) { match result { ManagedAsyncCallResult::Ok(()) => { - self.delegated_value(caller).set(egld_amount); + self.delegated_value(caller) + .update(|value| *value += egld_amount); self.egld_token_supply() .update(|value| *value += egld_amount) } From cc8cd5b997842dadd7390d7bea9cfae0a7c87500 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:15:25 +0300 Subject: [PATCH 72/98] Added refund tx for error scenario Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 0b3c4cf5..3875767a 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -40,7 +40,7 @@ pub trait DelegationModule: common::storage::CommonStorageModule { self.egld_token_supply() .update(|value| *value += egld_amount) } - _ => sc_panic!("There was an error at delegating"), + _ => self.tx().egld(egld_amount).to(caller).transfer(), } } From ebef8bac266f01af14a8131845ab80acac6112f0 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:16:15 +0300 Subject: [PATCH 73/98] Removed require Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 3875767a..0ff436b9 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -47,8 +47,6 @@ pub trait DelegationModule: common::storage::CommonStorageModule { #[endpoint(unStake)] fn unstake(&self, contract_name: ManagedBuffer, egld_amount_to_unstake: BigUint) { let caller = self.blockchain().get_caller(); - self.require_caller_has_stake(&caller); - let current_epoch = self.blockchain().get_block_epoch(); let delegation_contract_address = self.delegation_addresses(&contract_name).get(); let total_egld_deposit = self.delegated_value(&caller).get(); From d8182d751534d942aa07add4cce3682b1f233953 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:17:31 +0300 Subject: [PATCH 74/98] Removed setting of the epoch Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 0ff436b9..f6d65633 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -80,8 +80,6 @@ pub trait DelegationModule: common::storage::CommonStorageModule { ManagedAsyncCallResult::Ok(()) => { self.delegated_value(caller) .update(|value| *value -= egld_amount_to_unstake); - self.undelegate_epoch(caller) - .set(current_epoch + UNBOND_PERIOD); } _ => sc_panic!("There was an error at delegating"), } From e46ef592d0addcdabf0cdb4559ab99902cdc35ae Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:17:50 +0300 Subject: [PATCH 75/98] Removed the unused parameter of the callback Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index f6d65633..530f3740 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -60,11 +60,10 @@ pub trait DelegationModule: common::storage::CommonStorageModule { .to(delegation_contract_address) .raw_call(ManagedBuffer::from(UNDELEGATE_ENDPOINT)) .argument(&egld_amount_to_unstake) - .callback(DelegationModule::callbacks(self).unstake_callback( - &caller, - &egld_amount_to_unstake, - current_epoch, - )) + .callback( + DelegationModule::callbacks(self) + .unstake_callback(&caller, &egld_amount_to_unstake), + ) .async_call_and_exit(); } @@ -73,7 +72,6 @@ pub trait DelegationModule: common::storage::CommonStorageModule { &self, caller: &ManagedAddress, egld_amount_to_unstake: &BigUint, - current_epoch: Epoch, #[call_result] result: ManagedAsyncCallResult<()>, ) { match result { From 3b127759fe5d29da746bdf3ee77a5ed579dc3ac7 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:18:04 +0300 Subject: [PATCH 76/98] Removed unused variable Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 530f3740..559f5d8e 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -47,7 +47,6 @@ pub trait DelegationModule: common::storage::CommonStorageModule { #[endpoint(unStake)] fn unstake(&self, contract_name: ManagedBuffer, egld_amount_to_unstake: BigUint) { let caller = self.blockchain().get_caller(); - let current_epoch = self.blockchain().get_block_epoch(); let delegation_contract_address = self.delegation_addresses(&contract_name).get(); let total_egld_deposit = self.delegated_value(&caller).get(); From cb6c1eb555d0e63f8a60b9e288c6a9ac3c68cc57 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:19:19 +0300 Subject: [PATCH 77/98] De-nesting Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 559f5d8e..f4318312 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -89,14 +89,17 @@ pub trait DelegationModule: common::storage::CommonStorageModule { for delegation_contract in contracts { let delegation_mapper = self.delegation_addresses(&delegation_contract); - if !delegation_mapper.is_empty() { - let delegation_address = delegation_mapper.get(); - self.tx() - .to(delegation_address) - .raw_call(CLAIM_REWARDS_ENDPOINT) - .callback(DelegationModule::callbacks(self).claim_rewards_from_delegation_cb()) - .async_call_and_exit(); + + if delegation_mapper.is_empty() { + continue; } + + let delegation_address = delegation_mapper.get(); + self.tx() + .to(delegation_address) + .raw_call(CLAIM_REWARDS_ENDPOINT) + .callback(DelegationModule::callbacks(self).claim_rewards_from_delegation_cb()) + .async_call_and_exit(); } } From 489cc4b3189151fb95636d14a239c15b2921c822 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:21:04 +0300 Subject: [PATCH 78/98] Added register_promise instead of old async call Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index f4318312..969703b3 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -98,8 +98,9 @@ pub trait DelegationModule: common::storage::CommonStorageModule { self.tx() .to(delegation_address) .raw_call(CLAIM_REWARDS_ENDPOINT) + .gas(self.blockchain().get_gas_left()) .callback(DelegationModule::callbacks(self).claim_rewards_from_delegation_cb()) - .async_call_and_exit(); + .register_promise(); } } From c673fe5a87d096abc1822194a7626c86b8e41442 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:22:13 +0300 Subject: [PATCH 79/98] Removed match operator Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 969703b3..d4997d46 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -110,10 +110,10 @@ pub trait DelegationModule: common::storage::CommonStorageModule { // egld_amount: &BigUint, #[call_result] result: ManagedAsyncCallResult<()>, ) { - match result { - ManagedAsyncCallResult::Ok(()) => {} - _ => sc_panic!("There was an error at claiming rewards from the delegation contract"), - } + require!( + result.is_ok(), + "There was an error at claiming rewards from the delegation contract" + ); } // NOTE: Should this also add to the map ? From 64666a4b1b1e37edd0133d3a5fbefeeed29090ee Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:24:03 +0300 Subject: [PATCH 80/98] Storage require functions renames Signed-off-by: Andrei Baltariu --- liquid-staking/src/common/storage.rs | 8 ++++---- liquid-staking/src/delegation.rs | 8 ++++---- liquid-staking/src/lib.rs | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/liquid-staking/src/common/storage.rs b/liquid-staking/src/common/storage.rs index 4f318aae..0f392f68 100644 --- a/liquid-staking/src/common/storage.rs +++ b/liquid-staking/src/common/storage.rs @@ -44,14 +44,14 @@ pub trait CommonStorageModule { #[storage_mapper("lockerSupply")] fn locked_supply(&self, chain_id: ChainId) -> SingleValueMapper; - fn require_bls_key_to_be_registered(&self, bls_key: &BlsKey) { + fn require_bls_key_registered(&self, bls_key: &BlsKey) { require!( self.registered_bls_keys().contains(bls_key), "The given bls key is not registered" ); } - fn require_caller_to_be_header_verifier(&self, caller: &ManagedAddress) { + fn require_caller_header_verifier(&self, address: &ManagedAddress) { require!( !self.header_verifier_address().is_empty(), "There is no address registered as the Header Verifier" @@ -60,12 +60,12 @@ pub trait CommonStorageModule { let header_verifier_address = self.header_verifier_address().get(); require!( - caller == &header_verifier_address, + address == &header_verifier_address, "Caller is not Header Verifier contract" ); } - fn require_caller_has_stake(&self, caller: &ManagedAddress) { + fn require_address_has_stake(&self, caller: &ManagedAddress) { let total_egld_deposit = self.delegated_value(caller).get(); require!(total_egld_deposit > 0, "Caller has 0 delegated value"); diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index d4997d46..8031c9e4 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -85,7 +85,7 @@ pub trait DelegationModule: common::storage::CommonStorageModule { #[endpoint] fn claim_rewards_from_delegation(&self, contracts: MultiValueEncoded) { let caller = self.blockchain().get_caller(); - self.require_caller_has_stake(&caller); + self.require_address_has_stake(&caller); for delegation_contract in contracts { let delegation_mapper = self.delegation_addresses(&delegation_contract); @@ -125,15 +125,15 @@ pub trait DelegationModule: common::storage::CommonStorageModule { value_to_slash: BigUint, ) { let caller = self.blockchain().get_caller(); - self.require_caller_to_be_header_verifier(&caller); - self.require_bls_key_to_be_registered(&bls_key); + self.require_caller_header_verifier(&caller); + self.require_bls_key_registered(&bls_key); require!( !self.validator_bls_key_address_map(&bls_key).is_empty(), "There is no associated address to the given BLS key" ); - self.require_caller_has_stake(&validator_address); + self.require_address_has_stake(&validator_address); require!(value_to_slash > 0, "You can't slash a value of 0 eGLD"); diff --git a/liquid-staking/src/lib.rs b/liquid-staking/src/lib.rs index 062a0079..5073d1cc 100644 --- a/liquid-staking/src/lib.rs +++ b/liquid-staking/src/lib.rs @@ -46,7 +46,7 @@ pub trait LiquidStaking: #[endpoint(registerBlsKeys)] fn register_bls_keys(&self, bls_keys: MultiValueEncoded) { let caller = self.blockchain().get_caller(); - self.require_caller_to_be_header_verifier(&caller); + self.require_caller_header_verifier(&caller); self.registered_bls_keys().extend(bls_keys); } @@ -54,7 +54,7 @@ pub trait LiquidStaking: #[endpoint(registerBlsKeys)] fn unregister_bls_keys(&self, bls_keys: MultiValueEncoded) { let caller = self.blockchain().get_caller(); - self.require_caller_to_be_header_verifier(&caller); + self.require_caller_header_verifier(&caller); for bls_key in bls_keys { self.registered_bls_keys().swap_remove(&bls_key); From ad84e15d0a38454605b7965afeaf9ea96b1cfdf6 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:31:41 +0300 Subject: [PATCH 81/98] Optimization to not reuse mapper Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 8031c9e4..88b48a16 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -137,14 +137,14 @@ pub trait DelegationModule: common::storage::CommonStorageModule { require!(value_to_slash > 0, "You can't slash a value of 0 eGLD"); - let delegated_value = self.delegated_value(&validator_address).get(); + let delegation_mapper = self.delegated_value(&validator_address); + let delegated_value = delegation_mapper.get(); require!( delegated_value >= value_to_slash, "The slash value can't be greater than the total delegated amount" ); - self.delegated_value(&validator_address) - .update(|value| *value -= &value_to_slash); + delegation_mapper.update(|value| *value -= &value_to_slash); } #[payable("EGLD")] From bdcd2cc5bec6251472792f3b6315aab95b569b1d Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:31:45 +0300 Subject: [PATCH 82/98] Added TODO Signed-off-by: Andrei Baltariu --- liquid-staking/src/common/storage.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/liquid-staking/src/common/storage.rs b/liquid-staking/src/common/storage.rs index 0f392f68..770d0291 100644 --- a/liquid-staking/src/common/storage.rs +++ b/liquid-staking/src/common/storage.rs @@ -12,6 +12,7 @@ pub trait CommonStorageModule { contract_name: &ManagedBuffer, ) -> SingleValueMapper; + // TODO: use AddressToIdMapper for lower gas usage #[view(getDelegatedValue)] #[storage_mapper("delegatedValue")] fn delegated_value(&self, validator: &ManagedAddress) -> SingleValueMapper; From b8ee176b4e0a3320eadc1f9d2467fea86e28957d Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:33:35 +0300 Subject: [PATCH 83/98] Created mapper before the for loop Signed-off-by: Andrei Baltariu --- liquid-staking/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/liquid-staking/src/lib.rs b/liquid-staking/src/lib.rs index 5073d1cc..5aec937d 100644 --- a/liquid-staking/src/lib.rs +++ b/liquid-staking/src/lib.rs @@ -56,8 +56,10 @@ pub trait LiquidStaking: let caller = self.blockchain().get_caller(); self.require_caller_header_verifier(&caller); + let mut bls_keys_mapper = self.registered_bls_keys(); + for bls_key in bls_keys { - self.registered_bls_keys().swap_remove(&bls_key); + bls_keys_mapper.swap_remove(&bls_key); } } From 7fdf10feaa3fe36e572731fd91b2622fc33f217a Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:34:46 +0300 Subject: [PATCH 84/98] Moved upgrade endpoint next to init Signed-off-by: Andrei Baltariu --- liquid-staking/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/liquid-staking/src/lib.rs b/liquid-staking/src/lib.rs index 5aec937d..33df723d 100644 --- a/liquid-staking/src/lib.rs +++ b/liquid-staking/src/lib.rs @@ -17,6 +17,9 @@ pub trait LiquidStaking: #[init] fn init(&self) {} + #[upgrade] + fn upgrade(&self) {} + #[endpoint(registerDelegationContractAddress)] fn register_delegation_address( &self, @@ -62,7 +65,4 @@ pub trait LiquidStaking: bls_keys_mapper.swap_remove(&bls_key); } } - - #[upgrade] - fn upgrade(&self) {} } From 42523de55dbb7b9cb3974051d9ee696b33ecf039 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:40:18 +0300 Subject: [PATCH 85/98] Regenerated proxy Signed-off-by: Andrei Baltariu --- liquid-staking/src/liquid_staking_proxy.rs | 6 +++--- liquid-staking/wasm-liquid-staking-full/src/lib.rs | 6 +++--- liquid-staking/wasm/src/lib.rs | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/liquid-staking/src/liquid_staking_proxy.rs b/liquid-staking/src/liquid_staking_proxy.rs index d6f22b4e..e6fee3c6 100644 --- a/liquid-staking/src/liquid_staking_proxy.rs +++ b/liquid-staking/src/liquid_staking_proxy.rs @@ -159,7 +159,7 @@ where ) -> TxTypedCall { self.wrapped_tx .payment(NotPayable) - .raw_call("claimRewardsFromDelegation") + .raw_call("claim_rewards_from_delegation") .argument(&contracts) .original_result() } @@ -176,7 +176,7 @@ where ) -> TxTypedCall { self.wrapped_tx .payment(NotPayable) - .raw_call("slashValidator") + .raw_call("slash_validator") .argument(&validator_address) .argument(&bls_key) .argument(&value_to_slash) @@ -200,7 +200,7 @@ where ) -> TxTypedCall { self.wrapped_tx .payment(NotPayable) - .raw_call("claimRewards") + .raw_call("claim_rewards") .original_result() } diff --git a/liquid-staking/wasm-liquid-staking-full/src/lib.rs b/liquid-staking/wasm-liquid-staking-full/src/lib.rs index bd7d87e7..039b0237 100644 --- a/liquid-staking/wasm-liquid-staking-full/src/lib.rs +++ b/liquid-staking/wasm-liquid-staking-full/src/lib.rs @@ -25,10 +25,10 @@ multiversx_sc_wasm_adapter::endpoints! { registerBlsKeys => register_bls_keys stake => stake unStake => unstake - claimRewardsFromDelegation => claim_rewards_from_delegation - slashValidator => slash_validator + claim_rewards_from_delegation => claim_rewards_from_delegation + slash_validator => slash_validator lockForSovereignChain => lock_for_sovereign_chain - claimRewards => claim_rewards + claim_rewards => claim_rewards getDelegationAddress => delegation_addresses getDelegatedValue => delegated_value unDelegateEpoch => undelegate_epoch diff --git a/liquid-staking/wasm/src/lib.rs b/liquid-staking/wasm/src/lib.rs index bd7d87e7..039b0237 100644 --- a/liquid-staking/wasm/src/lib.rs +++ b/liquid-staking/wasm/src/lib.rs @@ -25,10 +25,10 @@ multiversx_sc_wasm_adapter::endpoints! { registerBlsKeys => register_bls_keys stake => stake unStake => unstake - claimRewardsFromDelegation => claim_rewards_from_delegation - slashValidator => slash_validator + claim_rewards_from_delegation => claim_rewards_from_delegation + slash_validator => slash_validator lockForSovereignChain => lock_for_sovereign_chain - claimRewards => claim_rewards + claim_rewards => claim_rewards getDelegationAddress => delegation_addresses getDelegatedValue => delegated_value unDelegateEpoch => undelegate_epoch From 4d6d794f0984039247387490cd4af7a9fe638714 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:42:36 +0300 Subject: [PATCH 86/98] Modified expected error message Signed-off-by: Andrei Baltariu --- liquid-staking/tests/liquid_staking_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index fa409d69..03fb794b 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -399,7 +399,7 @@ fn test_unstake_user_no_deposit() { let payment = BigUint::from(100_000u64); let error_status = ErrorStatus { code: 4, - error_message: "Caller has 0 delegated value", + error_message: "The value to unstake is greater than the deposited amount", }; state.propose_setup_contracts(); From 4a890130098330b1943eb40fdd3c274d62264a41 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:43:33 +0300 Subject: [PATCH 87/98] Removed unnecessary let Signed-off-by: Andrei Baltariu --- liquid-staking/tests/liquid_staking_tests.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index 03fb794b..fd1d8585 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -296,10 +296,7 @@ impl LiquidStakingTestState { current_epoch: u64, last_claim_epoch: u64, ) -> BigUint { - let rewards = (staked_amount * APY / MAX_PERCENTAGE) * (current_epoch - last_claim_epoch) - / EPOCHS_IN_YEAR; - - rewards + (staked_amount * APY / MAX_PERCENTAGE) * (current_epoch - last_claim_epoch) / EPOCHS_IN_YEAR } fn map_bls_key_vec_to_multi_value( From f859ff99892c960bdb31ce683db7d1dab3ac447b Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 09:45:55 +0300 Subject: [PATCH 88/98] Removed unused import Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 88b48a16..862105e5 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -6,7 +6,7 @@ pub const CLAIM_REWARDS_ENDPOINT: &[u8] = b"claimRewards"; use crate::common::{ self, - storage::{BlsKey, ChainId, Epoch}, + storage::{BlsKey, ChainId}, }; #[multiversx_sc::module] From f1c676c43f8d20fb5405da0b6d689f7e2c72e3f8 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 10:25:10 +0300 Subject: [PATCH 89/98] Reverted endpoint annotation Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 862105e5..9a22c23f 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -82,7 +82,7 @@ pub trait DelegationModule: common::storage::CommonStorageModule { } } - #[endpoint] + #[endpoint(claimRewardsFromDelegation)] fn claim_rewards_from_delegation(&self, contracts: MultiValueEncoded) { let caller = self.blockchain().get_caller(); self.require_address_has_stake(&caller); @@ -117,7 +117,7 @@ pub trait DelegationModule: common::storage::CommonStorageModule { } // NOTE: Should this also add to the map ? - #[endpoint] + #[endpoint(slashValidator)] fn slash_validator( &self, validator_address: ManagedAddress, From 05ca4a31e37a3c4993cb16ed3235b710dd701e39 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 10:37:45 +0300 Subject: [PATCH 90/98] Regenerated proxy Signed-off-by: Andrei Baltariu --- liquid-staking/src/liquid_staking_proxy.rs | 4 ++-- liquid-staking/wasm-liquid-staking-full/src/lib.rs | 4 ++-- liquid-staking/wasm/src/lib.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/liquid-staking/src/liquid_staking_proxy.rs b/liquid-staking/src/liquid_staking_proxy.rs index e6fee3c6..8e592b14 100644 --- a/liquid-staking/src/liquid_staking_proxy.rs +++ b/liquid-staking/src/liquid_staking_proxy.rs @@ -159,7 +159,7 @@ where ) -> TxTypedCall { self.wrapped_tx .payment(NotPayable) - .raw_call("claim_rewards_from_delegation") + .raw_call("claimRewardsFromDelegation") .argument(&contracts) .original_result() } @@ -176,7 +176,7 @@ where ) -> TxTypedCall { self.wrapped_tx .payment(NotPayable) - .raw_call("slash_validator") + .raw_call("slashValidator") .argument(&validator_address) .argument(&bls_key) .argument(&value_to_slash) diff --git a/liquid-staking/wasm-liquid-staking-full/src/lib.rs b/liquid-staking/wasm-liquid-staking-full/src/lib.rs index 039b0237..599ad5b0 100644 --- a/liquid-staking/wasm-liquid-staking-full/src/lib.rs +++ b/liquid-staking/wasm-liquid-staking-full/src/lib.rs @@ -25,8 +25,8 @@ multiversx_sc_wasm_adapter::endpoints! { registerBlsKeys => register_bls_keys stake => stake unStake => unstake - claim_rewards_from_delegation => claim_rewards_from_delegation - slash_validator => slash_validator + claimRewardsFromDelegation => claim_rewards_from_delegation + slashValidator => slash_validator lockForSovereignChain => lock_for_sovereign_chain claim_rewards => claim_rewards getDelegationAddress => delegation_addresses diff --git a/liquid-staking/wasm/src/lib.rs b/liquid-staking/wasm/src/lib.rs index 039b0237..599ad5b0 100644 --- a/liquid-staking/wasm/src/lib.rs +++ b/liquid-staking/wasm/src/lib.rs @@ -25,8 +25,8 @@ multiversx_sc_wasm_adapter::endpoints! { registerBlsKeys => register_bls_keys stake => stake unStake => unstake - claim_rewards_from_delegation => claim_rewards_from_delegation - slash_validator => slash_validator + claimRewardsFromDelegation => claim_rewards_from_delegation + slashValidator => slash_validator lockForSovereignChain => lock_for_sovereign_chain claim_rewards => claim_rewards getDelegationAddress => delegation_addresses From 23b7c8f2233475a64dc56a76fadab50dd417b331 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 11:04:22 +0300 Subject: [PATCH 91/98] Integrated AddressToId mapper Signed-off-by: Andrei Baltariu --- liquid-staking/src/common/storage.rs | 11 ++++++++--- liquid-staking/src/delegation.rs | 20 +++++++++++++------- liquid-staking/src/liquid_staking_proxy.rs | 2 +- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/liquid-staking/src/common/storage.rs b/liquid-staking/src/common/storage.rs index 770d0291..a8874a51 100644 --- a/liquid-staking/src/common/storage.rs +++ b/liquid-staking/src/common/storage.rs @@ -13,9 +13,13 @@ pub trait CommonStorageModule { ) -> SingleValueMapper; // TODO: use AddressToIdMapper for lower gas usage + // + #[storage_mapper("userIds")] + fn validator_ids(&self) -> AddressToIdMapper; + #[view(getDelegatedValue)] #[storage_mapper("delegatedValue")] - fn delegated_value(&self, validator: &ManagedAddress) -> SingleValueMapper; + fn delegated_value(&self, validator: &AddressId) -> SingleValueMapper; #[view(unDelegateEpoch)] #[storage_mapper("unDelegateEpoch")] @@ -66,8 +70,9 @@ pub trait CommonStorageModule { ); } - fn require_address_has_stake(&self, caller: &ManagedAddress) { - let total_egld_deposit = self.delegated_value(caller).get(); + fn require_address_has_stake(&self, validator_address: &ManagedAddress) { + let validator_id = self.validator_ids().get_id_or_insert(validator_address); + let total_egld_deposit = self.delegated_value(&validator_id).get(); require!(total_egld_deposit > 0, "Caller has 0 delegated value"); } diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 9a22c23f..1eb4b7a9 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -29,18 +29,20 @@ pub trait DelegationModule: common::storage::CommonStorageModule { #[callback] fn stake_callback( &self, - caller: &ManagedAddress, + validator_address: &ManagedAddress, egld_amount: &BigUint, #[call_result] result: ManagedAsyncCallResult<()>, ) { match result { ManagedAsyncCallResult::Ok(()) => { - self.delegated_value(caller) + let validator_id = self.validator_ids().get_id_or_insert(validator_address); + + self.delegated_value(&validator_id) .update(|value| *value += egld_amount); self.egld_token_supply() .update(|value| *value += egld_amount) } - _ => self.tx().egld(egld_amount).to(caller).transfer(), + _ => self.tx().egld(egld_amount).to(validator_address).transfer(), } } @@ -48,7 +50,8 @@ pub trait DelegationModule: common::storage::CommonStorageModule { fn unstake(&self, contract_name: ManagedBuffer, egld_amount_to_unstake: BigUint) { let caller = self.blockchain().get_caller(); let delegation_contract_address = self.delegation_addresses(&contract_name).get(); - let total_egld_deposit = self.delegated_value(&caller).get(); + let validator_id = self.validator_ids().get_id_or_insert(&caller); + let total_egld_deposit = self.delegated_value(&validator_id).get(); require!( egld_amount_to_unstake <= total_egld_deposit, @@ -69,13 +72,15 @@ pub trait DelegationModule: common::storage::CommonStorageModule { #[callback] fn unstake_callback( &self, - caller: &ManagedAddress, + validator_address: &ManagedAddress, egld_amount_to_unstake: &BigUint, #[call_result] result: ManagedAsyncCallResult<()>, ) { match result { ManagedAsyncCallResult::Ok(()) => { - self.delegated_value(caller) + let validator_id = self.validator_ids().get_id_or_insert(validator_address); + + self.delegated_value(&validator_id) .update(|value| *value -= egld_amount_to_unstake); } _ => sc_panic!("There was an error at delegating"), @@ -137,7 +142,8 @@ pub trait DelegationModule: common::storage::CommonStorageModule { require!(value_to_slash > 0, "You can't slash a value of 0 eGLD"); - let delegation_mapper = self.delegated_value(&validator_address); + let validator_id = self.validator_ids().get_id_or_insert(&validator_address); + let delegation_mapper = self.delegated_value(&validator_id); let delegated_value = delegation_mapper.get(); require!( delegated_value >= value_to_slash, diff --git a/liquid-staking/src/liquid_staking_proxy.rs b/liquid-staking/src/liquid_staking_proxy.rs index 8e592b14..06ca0c07 100644 --- a/liquid-staking/src/liquid_staking_proxy.rs +++ b/liquid-staking/src/liquid_staking_proxy.rs @@ -218,7 +218,7 @@ where } pub fn delegated_value< - Arg0: ProxyArg>, + Arg0: ProxyArg, >( self, validator: Arg0, From cf183b13b7014705da43f875677a0295e4006ea9 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 11:11:50 +0300 Subject: [PATCH 92/98] Adapted tests for for AddressToId implementation Signed-off-by: Andrei Baltariu --- liquid-staking/tests/liquid_staking_tests.rs | 28 ++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/liquid-staking/tests/liquid_staking_tests.rs b/liquid-staking/tests/liquid_staking_tests.rs index fd1d8585..16c52894 100644 --- a/liquid-staking/tests/liquid_staking_tests.rs +++ b/liquid-staking/tests/liquid_staking_tests.rs @@ -309,6 +309,20 @@ impl LiquidStakingTestState { managed_bls_keys } + fn get_validator_id(&mut self, validator: &TestAddress) -> u64 { + let mut validator_id = 0; + self.world.query().to(LIQUID_STAKING_ADDRESS).whitebox( + liquid_staking::contract_obj, + |sc| { + validator_id = sc + .validator_ids() + .get_id_or_insert(&validator.to_managed_address()); + }, + ); + + validator_id + } + fn whitebox_map_bls_to_address(&mut self, bls_key: &str, address: &TestAddress) -> &mut Self { self.world .tx() @@ -375,13 +389,15 @@ fn test_stake() { .check_account(OWNER) .balance(BigUint::from(WEGLD_BALANCE) - payment); + let validator_id = state.get_validator_id(&OWNER); + state .world .query() .to(LIQUID_STAKING_ADDRESS) .whitebox(liquid_staking::contract_obj, |sc| { let payment_whitebox = BigUint::from(100_000u64); - let delegated_value = sc.delegated_value(&OWNER.to_managed_address()).get(); + let delegated_value = sc.delegated_value(&validator_id).get(); let egld_supply = sc.egld_token_supply().get(); assert!(egld_supply > 0); @@ -423,13 +439,15 @@ fn test_unstake() { .check_account(OWNER) .balance(BigUint::from(WEGLD_BALANCE) - payment); + let validator_id = state.get_validator_id(&OWNER); + state .world .query() .to(LIQUID_STAKING_ADDRESS) .whitebox(liquid_staking::contract_obj, |sc| { let expected_amount = BigUint::from(90_000u64); - let delegated_value = sc.delegated_value(&OWNER.to_managed_address()).get(); + let delegated_value = sc.delegated_value(&validator_id).get(); assert_eq!(delegated_value, expected_amount); }) @@ -645,15 +663,15 @@ fn slash_validator() { None, ); + let validator_id = state.get_validator_id(&VALIDATOR_ADDRESS); + state .world .query() .to(LIQUID_STAKING_ADDRESS) .whitebox(liquid_staking::contract_obj, |sc| { let expected_value = BigUint::from(90_000u64); - let validator_delegated_value = sc - .delegated_value(&VALIDATOR_ADDRESS.to_managed_address()) - .get(); + let validator_delegated_value = sc.delegated_value(&validator_id).get(); assert_eq!(validator_delegated_value, expected_value); }) From 4e7d7d6f6c7069b433ee462b992112f3d1211f47 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 11:48:03 +0300 Subject: [PATCH 93/98] Added proxy call for delegation Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 1eb4b7a9..0dc298be 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -4,9 +4,12 @@ pub const DELEGATE_ENDPOINT: &[u8] = b"delegate"; pub const UNDELEGATE_ENDPOINT: &[u8] = b"unDelegate"; pub const CLAIM_REWARDS_ENDPOINT: &[u8] = b"claimRewards"; -use crate::common::{ - self, - storage::{BlsKey, ChainId}, +use crate::{ + common::{ + self, + storage::{BlsKey, ChainId}, + }, + delegation_proxy, }; #[multiversx_sc::module] @@ -20,7 +23,8 @@ pub trait DelegationModule: common::storage::CommonStorageModule { self.tx() .to(delegation_contract_address) - .raw_call(ManagedBuffer::from(DELEGATE_ENDPOINT)) + .typed(delegation_proxy::DelegationMockProxy) + .delegate() .egld(&egld_amount) .callback(DelegationModule::callbacks(self).stake_callback(&caller, &egld_amount)) .async_call_and_exit(); From 33a144eb6fe113d9ef98abb1ad2f1d0990ed2330 Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Fri, 4 Oct 2024 12:07:27 +0300 Subject: [PATCH 94/98] Added proxy calls for other endpoints Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 0dc298be..62bfee09 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -64,8 +64,8 @@ pub trait DelegationModule: common::storage::CommonStorageModule { self.tx() .to(delegation_contract_address) - .raw_call(ManagedBuffer::from(UNDELEGATE_ENDPOINT)) - .argument(&egld_amount_to_unstake) + .typed(delegation_proxy::DelegationMockProxy) + .undelegate(&egld_amount_to_unstake) .callback( DelegationModule::callbacks(self) .unstake_callback(&caller, &egld_amount_to_unstake), @@ -106,7 +106,8 @@ pub trait DelegationModule: common::storage::CommonStorageModule { let delegation_address = delegation_mapper.get(); self.tx() .to(delegation_address) - .raw_call(CLAIM_REWARDS_ENDPOINT) + .typed(delegation_proxy::DelegationMockProxy) + .claim_rewards() .gas(self.blockchain().get_gas_left()) .callback(DelegationModule::callbacks(self).claim_rewards_from_delegation_cb()) .register_promise(); From 4e2a6d6658f31b3ff84749717f20ea545e1479bb Mon Sep 17 00:00:00 2001 From: mradian1 <160105867+mradian1@users.noreply.github.com> Date: Fri, 4 Oct 2024 14:16:59 +0300 Subject: [PATCH 95/98] Update actions.yml contracts v3.3.1 --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 3838e228..31dc66a2 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -20,7 +20,7 @@ permissions: jobs: contracts: name: Contracts - uses: multiversx/mx-sc-actions/.github/workflows/contracts.yml@v3.2.0 + uses: multiversx/mx-sc-actions/.github/workflows/contracts.yml@v3.3.1 with: rust-toolchain: stable coverage-args: --ignore-filename-regex='/.cargo/git' --output ./coverage.md From 22d4a4e829a652891c70a4d54e3a497c586b007a Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Tue, 8 Oct 2024 14:19:46 +0300 Subject: [PATCH 96/98] Added promises Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 62bfee09..fff4743a 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -26,8 +26,9 @@ pub trait DelegationModule: common::storage::CommonStorageModule { .typed(delegation_proxy::DelegationMockProxy) .delegate() .egld(&egld_amount) + .gas(self.blockchain().get_gas_left()) .callback(DelegationModule::callbacks(self).stake_callback(&caller, &egld_amount)) - .async_call_and_exit(); + .register_promise(); } #[callback] @@ -66,11 +67,12 @@ pub trait DelegationModule: common::storage::CommonStorageModule { .to(delegation_contract_address) .typed(delegation_proxy::DelegationMockProxy) .undelegate(&egld_amount_to_unstake) + .gas(self.blockchain().get_gas_left()) .callback( DelegationModule::callbacks(self) .unstake_callback(&caller, &egld_amount_to_unstake), ) - .async_call_and_exit(); + .register_promise(); } #[callback] From 216de6eac388ba0b5a6f362f10a4bbd6a6eb038f Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 9 Oct 2024 12:20:47 +0300 Subject: [PATCH 97/98] Added correct annotation for promise callbacks Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index fff4743a..3d301b0c 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -27,11 +27,11 @@ pub trait DelegationModule: common::storage::CommonStorageModule { .delegate() .egld(&egld_amount) .gas(self.blockchain().get_gas_left()) - .callback(DelegationModule::callbacks(self).stake_callback(&caller, &egld_amount)) + .callback(self.callbacks().stake_callback(&caller, &egld_amount)) .register_promise(); } - #[callback] + #[promises_callback] fn stake_callback( &self, validator_address: &ManagedAddress, @@ -75,7 +75,7 @@ pub trait DelegationModule: common::storage::CommonStorageModule { .register_promise(); } - #[callback] + #[promises_callback] fn unstake_callback( &self, validator_address: &ManagedAddress, @@ -111,12 +111,12 @@ pub trait DelegationModule: common::storage::CommonStorageModule { .typed(delegation_proxy::DelegationMockProxy) .claim_rewards() .gas(self.blockchain().get_gas_left()) - .callback(DelegationModule::callbacks(self).claim_rewards_from_delegation_cb()) + .callback(self.callbacks().claim_rewards_from_delegation_cb()) .register_promise(); } } - #[callback] + #[promises_callback] fn claim_rewards_from_delegation_cb( &self, // egld_amount: &BigUint, From 36f041b3754d8af4a5a3b883ba7d42c7e2d5892b Mon Sep 17 00:00:00 2001 From: Andrei Baltariu Date: Wed, 9 Oct 2024 13:12:53 +0300 Subject: [PATCH 98/98] Added use of `self.callbacks()` Signed-off-by: Andrei Baltariu --- liquid-staking/src/delegation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liquid-staking/src/delegation.rs b/liquid-staking/src/delegation.rs index 3d301b0c..c62147c0 100644 --- a/liquid-staking/src/delegation.rs +++ b/liquid-staking/src/delegation.rs @@ -69,7 +69,7 @@ pub trait DelegationModule: common::storage::CommonStorageModule { .undelegate(&egld_amount_to_unstake) .gas(self.blockchain().get_gas_left()) .callback( - DelegationModule::callbacks(self) + self.callbacks() .unstake_callback(&caller, &egld_amount_to_unstake), ) .register_promise();