From 795cc73cf2939f9e12e92e50fde5174a58f4469f Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Thu, 14 Dec 2023 14:43:18 +0200 Subject: [PATCH 01/24] On Chain Claim contract --- Cargo.toml | 2 + contracts/on-chain-claim/.gitignore | 10 + contracts/on-chain-claim/Cargo.toml | 15 + contracts/on-chain-claim/README.md | 3 + .../interaction/devnet.snippets.sh | 27 ++ .../interaction/testnet.snippets.sh | 27 ++ contracts/on-chain-claim/meta/Cargo.toml | 15 + contracts/on-chain-claim/meta/src/main.rs | 3 + contracts/on-chain-claim/multiversx.json | 3 + contracts/on-chain-claim/mxsc-template.toml | 19 ++ contracts/on-chain-claim/src/address_info.rs | 9 + contracts/on-chain-claim/src/contract.rs | 50 ++++ contracts/on-chain-claim/src/storage.rs | 11 + contracts/on-chain-claim/wasm/Cargo.lock | 258 ++++++++++++++++++ contracts/on-chain-claim/wasm/Cargo.toml | 30 ++ contracts/on-chain-claim/wasm/src/lib.rs | 30 ++ 16 files changed, 512 insertions(+) create mode 100644 contracts/on-chain-claim/.gitignore create mode 100644 contracts/on-chain-claim/Cargo.toml create mode 100644 contracts/on-chain-claim/README.md create mode 100644 contracts/on-chain-claim/interaction/devnet.snippets.sh create mode 100644 contracts/on-chain-claim/interaction/testnet.snippets.sh create mode 100644 contracts/on-chain-claim/meta/Cargo.toml create mode 100644 contracts/on-chain-claim/meta/src/main.rs create mode 100644 contracts/on-chain-claim/multiversx.json create mode 100644 contracts/on-chain-claim/mxsc-template.toml create mode 100644 contracts/on-chain-claim/src/address_info.rs create mode 100644 contracts/on-chain-claim/src/contract.rs create mode 100644 contracts/on-chain-claim/src/storage.rs create mode 100644 contracts/on-chain-claim/wasm/Cargo.lock create mode 100644 contracts/on-chain-claim/wasm/Cargo.toml create mode 100644 contracts/on-chain-claim/wasm/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 05451ba3..5ad3771a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,6 +51,8 @@ members = [ "contracts/nft-minter/meta", "contracts/nft-storage-prepay", "contracts/nft-storage-prepay/meta", + "contracts/on-chain-claim", + "contracts/on-chain-claim/meta", "contracts/order-book/factory", "contracts/order-book/factory/meta", "contracts/order-book/pair", diff --git a/contracts/on-chain-claim/.gitignore b/contracts/on-chain-claim/.gitignore new file mode 100644 index 00000000..dd49a952 --- /dev/null +++ b/contracts/on-chain-claim/.gitignore @@ -0,0 +1,10 @@ +# Generated by Cargo +# will have compiled files and executables +/target/ +*/target/ + +# The mxpy output +/output*/ + +# Mandos test trace +trace*.scen.json diff --git a/contracts/on-chain-claim/Cargo.toml b/contracts/on-chain-claim/Cargo.toml new file mode 100644 index 00000000..bc8716f7 --- /dev/null +++ b/contracts/on-chain-claim/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "on-chain-claim" +version = "0.0.0" +authors = [ "Vlad Bucur "] +edition = "2021" +publish = false + +[lib] +path = "src/contract.rs" + +[dependencies.multiversx-sc] +version = "0.45.1" + +[dev-dependencies.multiversx-sc-scenario] +version = "0.45.1" diff --git a/contracts/on-chain-claim/README.md b/contracts/on-chain-claim/README.md new file mode 100644 index 00000000..d4ccc0af --- /dev/null +++ b/contracts/on-chain-claim/README.md @@ -0,0 +1,3 @@ +# On Chain Claim + +`On Chain Claim` is a simple Smart Contract. diff --git a/contracts/on-chain-claim/interaction/devnet.snippets.sh b/contracts/on-chain-claim/interaction/devnet.snippets.sh new file mode 100644 index 00000000..c3f67bcd --- /dev/null +++ b/contracts/on-chain-claim/interaction/devnet.snippets.sh @@ -0,0 +1,27 @@ +WALLET="${PWD}/wallet.pem" +PROJECT="${PWD}" +PROXY=https://devnet-gateway.multiversx.com +CHAINID=D + +DEPLOY_GAS="25000000" + +deploy() { + mxpy --verbose contract deploy \ + --bytecode="output/onchain-claim.wasm" \ + --pem=${WALLET} \ + --gas-limit=${DEPLOY_GAS} \ + --proxy=${PROXY} \ + --chain=${CHAINID} \ + --recall-nonce \ + --send \ + --outfile="deploy-devnet.interaction.json" || return + + TRANSACTION=$(mxpy data parse --file="deploy-devnet.interaction.json" --expression="data['emittedTransactionHash']") + ADDRESS=$(mxpy data parse --file="deploy-devnet.interaction.json" --expression="data['contractAddress']") + + mxpy data store --key=address-devnet --value=${ADDRESS} + mxpy data store --key=deployTransaction-devnet --value=${TRANSACTION} + + echo "" + echo "Smart contract address: ${ADDRESS}" +} diff --git a/contracts/on-chain-claim/interaction/testnet.snippets.sh b/contracts/on-chain-claim/interaction/testnet.snippets.sh new file mode 100644 index 00000000..0b8d9e42 --- /dev/null +++ b/contracts/on-chain-claim/interaction/testnet.snippets.sh @@ -0,0 +1,27 @@ +WALLET="${PWD}/wallet.pem" +PROJECT="${PWD}" +PROXY=https://testnet-gateway.multiversx.com +CHAINID=D + +DEPLOY_GAS="25000000" + +deploy() { + mxpy --verbose contract deploy \ + --bytecode="output/onchain-claim.wasm" \ + --pem=${WALLET} \ + --gas-limit=${DEPLOY_GAS} \ + --proxy=${PROXY} \ + --chain=${CHAINID} \ + --recall-nonce \ + --send \ + --outfile="deploy-testnet.interaction.json" || return + + TRANSACTION=$(mxpy data parse --file="deploy-testnet.interaction.json" --expression="data['emittedTransactionHash']") + ADDRESS=$(mxpy data parse --file="deploy-testnet.interaction.json" --expression="data['contractAddress']") + + mxpy data store --key=address-testnet --value=${ADDRESS} + mxpy data store --key=deployTransaction-testnet --value=${TRANSACTION} + + echo "" + echo "Smart contract address: ${ADDRESS}" +} diff --git a/contracts/on-chain-claim/meta/Cargo.toml b/contracts/on-chain-claim/meta/Cargo.toml new file mode 100644 index 00000000..0488d955 --- /dev/null +++ b/contracts/on-chain-claim/meta/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "on-chain-claim-meta" +version = "0.0.0" +edition = "2018" +publish = false +authors = [ "you",] + +[dev-dependencies] + +[dependencies.on-chain-claim] +path = ".." + +[dependencies.multiversx-sc-meta] +version = "0.45.1" +default-features = false diff --git a/contracts/on-chain-claim/meta/src/main.rs b/contracts/on-chain-claim/meta/src/main.rs new file mode 100644 index 00000000..6dc8f567 --- /dev/null +++ b/contracts/on-chain-claim/meta/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + multiversx_sc_meta::cli_main::(); +} diff --git a/contracts/on-chain-claim/multiversx.json b/contracts/on-chain-claim/multiversx.json new file mode 100644 index 00000000..73655396 --- /dev/null +++ b/contracts/on-chain-claim/multiversx.json @@ -0,0 +1,3 @@ +{ + "language": "rust" +} \ No newline at end of file diff --git a/contracts/on-chain-claim/mxsc-template.toml b/contracts/on-chain-claim/mxsc-template.toml new file mode 100644 index 00000000..f08a40f4 --- /dev/null +++ b/contracts/on-chain-claim/mxsc-template.toml @@ -0,0 +1,19 @@ +name = "on-chain-claim" +contract_trait = "OnChainClaim" +src_file = "contract.rs" +rename_pairs = [ + [ + "blockchain.set_current_dir_from_workspace(\"contracts/examples/on-chain-claim\");", + "// blockchain.set_current_dir_from_workspace(\"relative path to your workspace, if applicable\");", + ], +] +files_include = [ + "meta", + "scenarios", + "src", + "tests", + "wasm/Cargo.toml", + "Cargo.toml", + "README.md", + "multiversx.json", +] diff --git a/contracts/on-chain-claim/src/address_info.rs b/contracts/on-chain-claim/src/address_info.rs new file mode 100644 index 00000000..6ba9f06e --- /dev/null +++ b/contracts/on-chain-claim/src/address_info.rs @@ -0,0 +1,9 @@ +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +pub struct AddressInfo { + pub current_streak: u64, + pub last_epoch_claimed: u64, + pub total_epochs_claimed: u64, +} diff --git a/contracts/on-chain-claim/src/contract.rs b/contracts/on-chain-claim/src/contract.rs new file mode 100644 index 00000000..f7e65135 --- /dev/null +++ b/contracts/on-chain-claim/src/contract.rs @@ -0,0 +1,50 @@ +#![no_std] +#![allow(unused_attributes)] + +use address_info::AddressInfo; + +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +mod address_info; +mod storage; + +/// An empty contract. To be used as a template when starting a new contract from scratch. +#[multiversx_sc::contract] +pub trait OnchainClaimContract: + storage::StorageModule { + #[init] + fn init(&self) {} + + #[endpoint(claim)] + fn claim(&self) { + let caller = self.blockchain().get_caller(); + + let address_info_mapper = self.address_info(&caller); + if address_info_mapper.is_empty() { + let address_info = AddressInfo { + current_streak: 1, + last_epoch_claimed: self.blockchain().get_block_epoch(), + total_epochs_claimed: 1, + }; + self.address_info(&caller).set(&address_info); + return; + } + + address_info_mapper.update(|address_info| { + require!( + address_info.last_epoch_claimed < self.blockchain().get_block_epoch(), + "epoch already claimed" + ); + + if address_info.last_epoch_claimed + 1 == self.blockchain().get_block_epoch() { + address_info.current_streak += 1; + } else { + address_info.current_streak = 1; + } + + address_info.total_epochs_claimed += 1; + address_info.last_epoch_claimed = self.blockchain().get_block_epoch(); + }); + } +} diff --git a/contracts/on-chain-claim/src/storage.rs b/contracts/on-chain-claim/src/storage.rs new file mode 100644 index 00000000..3c06731b --- /dev/null +++ b/contracts/on-chain-claim/src/storage.rs @@ -0,0 +1,11 @@ +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +use crate::address_info::*; + +#[multiversx_sc::module] +pub trait StorageModule { + #[view(getAddressInfo)] + #[storage_mapper("address_info")] + fn address_info(&self, address: &ManagedAddress) -> SingleValueMapper; +} diff --git a/contracts/on-chain-claim/wasm/Cargo.lock b/contracts/on-chain-claim/wasm/Cargo.lock new file mode 100644 index 00000000..5b8d5f0b --- /dev/null +++ b/contracts/on-chain-claim/wasm/Cargo.lock @@ -0,0 +1,258 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "allocator-api2" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" + +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + +[[package]] +name = "hashbrown" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" +dependencies = [ + "ahash", + "allocator-api2", +] + +[[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.45.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f11b51d6a2ab0218585ed58e100c5ac2218de09490fbfc4243b5ecd0ca7f5cbc" +dependencies = [ + "bitflags", + "hashbrown", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327b0ad1c3477cab0d7c84391439ba302238f738ef3c6e1fcd18e247fba84875" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f444038e0043b8eda816b26952479c2aca3c4a643580f4337f71fb362a586db5" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.45.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "784f0fc505806102fe6f808b368e12fcb13096dd73c5678f09c5663230724d6f" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn 1.0.109", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.45.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5afb8b8cc380eabd82dc8f9b02afbab3dce16fc2b5de1dbc601fcfcf261278ba" +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.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +dependencies = [ + "autocfg", +] + +[[package]] +name = "on-chain-claim" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "on-chain-claim-wasm" +version = "0.0.0" +dependencies = [ + "multiversx-sc-wasm-adapter", + "on-chain-claim", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "proc-macro2" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +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.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "zerocopy" +version = "0.7.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e97e415490559a91254a2979b4829267a57d2fcd741a98eee8b722fb57289aa0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd7e48ccf166952882ca8bd778a43502c64f33bf94c12ebe2a7f08e5a0f6689f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] diff --git a/contracts/on-chain-claim/wasm/Cargo.toml b/contracts/on-chain-claim/wasm/Cargo.toml new file mode 100644 index 00000000..59e71574 --- /dev/null +++ b/contracts/on-chain-claim/wasm/Cargo.toml @@ -0,0 +1,30 @@ +# Code generated by the multiversx-sc build system. DO NOT EDIT. + +# ########################################## +# ############## AUTO-GENERATED ############# +# ########################################## + +[package] +name = "on-chain-claim-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" + +[dependencies.on-chain-claim] +path = ".." + +[dependencies.multiversx-sc-wasm-adapter] +version = "0.45.1" + +[workspace] +members = ["."] diff --git a/contracts/on-chain-claim/wasm/src/lib.rs b/contracts/on-chain-claim/wasm/src/lib.rs new file mode 100644 index 00000000..b4f8c33b --- /dev/null +++ b/contracts/on-chain-claim/wasm/src/lib.rs @@ -0,0 +1,30 @@ +// Code generated by the multiversx-sc build system. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +// Init: 1 +// Endpoints: 2 +// Async Callback (empty): 1 +// Total number of exported functions: 4 + +#![no_std] + +// Configuration that works with rustc < 1.73.0. +// TODO: Recommended rustc version: 1.73.0 or newer. +#![feature(lang_items)] + +multiversx_sc_wasm_adapter::allocator!(); +multiversx_sc_wasm_adapter::panic_handler!(); + +multiversx_sc_wasm_adapter::endpoints! { + on_chain_claim + ( + init => init + claim => claim + getAddressInfo => address_info + ) +} + +multiversx_sc_wasm_adapter::async_callback_empty! {} From fc9867f4def1dc99c9c2512bb08b74a1addcad67 Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Thu, 14 Dec 2023 14:54:22 +0200 Subject: [PATCH 02/24] code review fixes --- contracts/on-chain-claim/src/contract.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/contracts/on-chain-claim/src/contract.rs b/contracts/on-chain-claim/src/contract.rs index f7e65135..d616eb68 100644 --- a/contracts/on-chain-claim/src/contract.rs +++ b/contracts/on-chain-claim/src/contract.rs @@ -19,12 +19,13 @@ pub trait OnchainClaimContract: #[endpoint(claim)] fn claim(&self) { let caller = self.blockchain().get_caller(); + let current_epoch = self.blockchain().get_block_epoch(); let address_info_mapper = self.address_info(&caller); if address_info_mapper.is_empty() { let address_info = AddressInfo { current_streak: 1, - last_epoch_claimed: self.blockchain().get_block_epoch(), + last_epoch_claimed: current_epoch, total_epochs_claimed: 1, }; self.address_info(&caller).set(&address_info); @@ -33,18 +34,18 @@ pub trait OnchainClaimContract: address_info_mapper.update(|address_info| { require!( - address_info.last_epoch_claimed < self.blockchain().get_block_epoch(), + address_info.last_epoch_claimed < current_epoch, "epoch already claimed" ); - if address_info.last_epoch_claimed + 1 == self.blockchain().get_block_epoch() { + if address_info.last_epoch_claimed + 1 == current_epoch { address_info.current_streak += 1; } else { address_info.current_streak = 1; } address_info.total_epochs_claimed += 1; - address_info.last_epoch_claimed = self.blockchain().get_block_epoch(); + address_info.last_epoch_claimed = current_epoch; }); } } From 4209ae81d6789b5087f286bb3e828ee106dab9d0 Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Thu, 14 Dec 2023 14:58:03 +0200 Subject: [PATCH 03/24] code review fixes --- contracts/on-chain-claim/src/contract.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/on-chain-claim/src/contract.rs b/contracts/on-chain-claim/src/contract.rs index d616eb68..ea0b0490 100644 --- a/contracts/on-chain-claim/src/contract.rs +++ b/contracts/on-chain-claim/src/contract.rs @@ -28,7 +28,7 @@ pub trait OnchainClaimContract: last_epoch_claimed: current_epoch, total_epochs_claimed: 1, }; - self.address_info(&caller).set(&address_info); + self.address_info(&caller).set(address_info); return; } From 436768e0b8b5f735df4e0be670b97a3dadc39487 Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Fri, 15 Dec 2023 15:31:18 +0200 Subject: [PATCH 04/24] Added claimAndrepair endpoint and updateState --- contracts/.DS_Store | Bin 0 -> 6148 bytes .../interaction/devnet.snippets.sh | 5 +- .../interaction/testnet.snippets.sh | 5 +- contracts/on-chain-claim/src/config.rs | 1 + contracts/on-chain-claim/src/contract.rs | 90 +++++++++++++++++- contracts/on-chain-claim/src/storage.rs | 4 + contracts/on-chain-claim/src/views.rs | 20 ++++ contracts/on-chain-claim/wasm/src/lib.rs | 8 +- 8 files changed, 123 insertions(+), 10 deletions(-) create mode 100644 contracts/.DS_Store create mode 100644 contracts/on-chain-claim/src/config.rs create mode 100644 contracts/on-chain-claim/src/views.rs diff --git a/contracts/.DS_Store b/contracts/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..6721facd1fb8b84a3fc4c30b63aeac821275399c GIT binary patch literal 6148 zcmeHK%Sr=55Ukc50)ph2-;NOQvckG2@VthIn zVgw-0m=5DQW(i{R1hE&6iOkR}sl=pOjTn}6=3CYE!Z9)Fuo^zBZnm0GEN!2`1 lJ0?au=EmFcGK#XU`I^sr;g}e7=7Ubu&w%S9lLCLOz!wM87G?kd literal 0 HcmV?d00001 diff --git a/contracts/on-chain-claim/interaction/devnet.snippets.sh b/contracts/on-chain-claim/interaction/devnet.snippets.sh index c3f67bcd..28baf31a 100644 --- a/contracts/on-chain-claim/interaction/devnet.snippets.sh +++ b/contracts/on-chain-claim/interaction/devnet.snippets.sh @@ -4,10 +4,11 @@ PROXY=https://devnet-gateway.multiversx.com CHAINID=D DEPLOY_GAS="25000000" - +SFT_IDENTIFIER=0x585354525245504149522d653162363733 #XSTRREPAIR-e1b673 deploy() { mxpy --verbose contract deploy \ - --bytecode="output/onchain-claim.wasm" \ + --bytecode="output/on-chain-claim.wasm" \ + --arguments ${SFT_IDENTIFIER} \ --pem=${WALLET} \ --gas-limit=${DEPLOY_GAS} \ --proxy=${PROXY} \ diff --git a/contracts/on-chain-claim/interaction/testnet.snippets.sh b/contracts/on-chain-claim/interaction/testnet.snippets.sh index 0b8d9e42..4da099cb 100644 --- a/contracts/on-chain-claim/interaction/testnet.snippets.sh +++ b/contracts/on-chain-claim/interaction/testnet.snippets.sh @@ -4,10 +4,11 @@ PROXY=https://testnet-gateway.multiversx.com CHAINID=D DEPLOY_GAS="25000000" - +SFT_IDENTIFIER=0x585354525245504149522d653162363733 #XSTRREPAIR-e1b673 deploy() { mxpy --verbose contract deploy \ - --bytecode="output/onchain-claim.wasm" \ + --bytecode="output/on-chain-claim.wasm" \ + --arguments ${SFT_IDENTIFIER} \ --pem=${WALLET} \ --gas-limit=${DEPLOY_GAS} \ --proxy=${PROXY} \ diff --git a/contracts/on-chain-claim/src/config.rs b/contracts/on-chain-claim/src/config.rs new file mode 100644 index 00000000..6d72c5d4 --- /dev/null +++ b/contracts/on-chain-claim/src/config.rs @@ -0,0 +1 @@ +pub const SFT_AMOUNT: u64 = 1; diff --git a/contracts/on-chain-claim/src/contract.rs b/contracts/on-chain-claim/src/contract.rs index ea0b0490..37abaf9c 100644 --- a/contracts/on-chain-claim/src/contract.rs +++ b/contracts/on-chain-claim/src/contract.rs @@ -6,19 +6,35 @@ use address_info::AddressInfo; multiversx_sc::imports!(); multiversx_sc::derive_imports!(); -mod address_info; +pub mod address_info; mod storage; +mod config; +mod views; + +use crate::config::SFT_AMOUNT; /// An empty contract. To be used as a template when starting a new contract from scratch. #[multiversx_sc::contract] -pub trait OnchainClaimContract: - storage::StorageModule { +pub trait OnChainClaimContract: + storage::StorageModule + + views::ViewsModule { #[init] - fn init(&self) {} + fn init( + &self, + repair_streak_token_id: TokenIdentifier, + ) { + self.repair_streak_token_identifier() + .set(repair_streak_token_id); + } #[endpoint(claim)] fn claim(&self) { let caller = self.blockchain().get_caller(); + require!( + !self.blockchain().is_smart_contract(&caller), + "Only user accounts can open mystery boxes" + ); + let current_epoch = self.blockchain().get_block_epoch(); let address_info_mapper = self.address_info(&caller); @@ -48,4 +64,70 @@ pub trait OnchainClaimContract: address_info.last_epoch_claimed = current_epoch; }); } + + #[payable("*")] + #[endpoint(claimAndRepair)] + fn claim_and_repair(&self) { + let caller = self.blockchain().get_caller(); + require!( + !self.blockchain().is_smart_contract(&caller), + "Only user accounts can open mystery boxes" + ); + let payment = self.call_value().single_esdt(); + let repair_streak_token_identifier = self.repair_streak_token_identifier().get(); + require!( + payment.token_identifier == repair_streak_token_identifier, + "Bad payment token" + ); + require!(payment.amount == SFT_AMOUNT, "Bad payment amount"); + + let current_epoch = self.blockchain().get_block_epoch(); + + let address_info_mapper = self.address_info(&caller); + + require!(!address_info_mapper.is_empty(), "can't repair streak for address"); + + let address_info = address_info_mapper.get(); + + require!(address_info.last_epoch_claimed + 2 == current_epoch, "can't repair streak for current epoch"); + + address_info_mapper.update(|address_info| { + require!( + address_info.last_epoch_claimed + 2 == current_epoch, + "can't repair streak for current epoch" + ); + + address_info.current_streak += 2; + address_info.total_epochs_claimed += 2; + address_info.last_epoch_claimed = current_epoch; + }); + } + + #[only_owner] + #[endpoint(updateState)] + fn update_state( + &self, + address: ManagedAddress, + current_streak: u64, + last_epoch_claimed: u64, + total_epochs_claimed: u64, + ) { + let address_info_mapper = self.address_info(&address); + + if address_info_mapper.is_empty() { + let address_info = AddressInfo { + current_streak: current_streak, + last_epoch_claimed: last_epoch_claimed, + total_epochs_claimed: total_epochs_claimed, + }; + self.address_info(&address).set(address_info); + return; + } + + address_info_mapper.update(|address_info| { + address_info.current_streak = current_streak; + address_info.last_epoch_claimed = last_epoch_claimed; + address_info.total_epochs_claimed = total_epochs_claimed; + }); + } } diff --git a/contracts/on-chain-claim/src/storage.rs b/contracts/on-chain-claim/src/storage.rs index 3c06731b..ea9368c1 100644 --- a/contracts/on-chain-claim/src/storage.rs +++ b/contracts/on-chain-claim/src/storage.rs @@ -8,4 +8,8 @@ pub trait StorageModule { #[view(getAddressInfo)] #[storage_mapper("address_info")] fn address_info(&self, address: &ManagedAddress) -> SingleValueMapper; + + #[view(getRepairStreakTokenIdentifier)] + #[storage_mapper("repair_streak_token_identifier")] + fn repair_streak_token_identifier(&self) -> SingleValueMapper; } diff --git a/contracts/on-chain-claim/src/views.rs b/contracts/on-chain-claim/src/views.rs new file mode 100644 index 00000000..01d3328c --- /dev/null +++ b/contracts/on-chain-claim/src/views.rs @@ -0,0 +1,20 @@ +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +use crate::storage::{self}; + +#[multiversx_sc::module] +pub trait ViewsModule: + storage::StorageModule { + #[view(canBeRepaired)] + fn can_be_repaired(&self, address: &ManagedAddress) -> bool { + let address_info_mapper = self.address_info(address); + if address_info_mapper.is_empty() { + return false; + } + + let address_info = address_info_mapper.get(); + + address_info.last_epoch_claimed + 2 == self.blockchain().get_block_epoch() + } +} diff --git a/contracts/on-chain-claim/wasm/src/lib.rs b/contracts/on-chain-claim/wasm/src/lib.rs index b4f8c33b..b85c26e9 100644 --- a/contracts/on-chain-claim/wasm/src/lib.rs +++ b/contracts/on-chain-claim/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 2 +// Endpoints: 6 // Async Callback (empty): 1 -// Total number of exported functions: 4 +// Total number of exported functions: 8 #![no_std] @@ -23,7 +23,11 @@ multiversx_sc_wasm_adapter::endpoints! { ( init => init claim => claim + claimAndRepair => claim_and_repair + updateState => update_state getAddressInfo => address_info + getRepairStreakTokenIdentifier => repair_streak_token_identifier + canBeRepaired => can_be_repaired ) } From e17dc6126a29428e88e6e873b226bd33cb47de0e Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Fri, 15 Dec 2023 15:32:23 +0200 Subject: [PATCH 05/24] removed ds_store file --- contracts/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 contracts/.DS_Store diff --git a/contracts/.DS_Store b/contracts/.DS_Store deleted file mode 100644 index 6721facd1fb8b84a3fc4c30b63aeac821275399c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%Sr=55Ukc50)ph2-;NOQvckG2@VthIn zVgw-0m=5DQW(i{R1hE&6iOkR}sl=pOjTn}6=3CYE!Z9)Fuo^zBZnm0GEN!2`1 lJ0?au=EmFcGK#XU`I^sr;g}e7=7Ubu&w%S9lLCLOz!wM87G?kd From 9455995641a4702a4ee45332fef1cd7bfe878c87 Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Fri, 15 Dec 2023 16:28:34 +0200 Subject: [PATCH 06/24] code review fixes --- contracts/on-chain-claim/src/address_info.rs | 15 +++++++ contracts/on-chain-claim/src/config.rs | 29 ++++++++++++++ contracts/on-chain-claim/src/contract.rs | 42 +++++--------------- contracts/on-chain-claim/src/storage.rs | 15 ------- contracts/on-chain-claim/src/views.rs | 20 ---------- 5 files changed, 54 insertions(+), 67 deletions(-) delete mode 100644 contracts/on-chain-claim/src/storage.rs delete mode 100644 contracts/on-chain-claim/src/views.rs diff --git a/contracts/on-chain-claim/src/address_info.rs b/contracts/on-chain-claim/src/address_info.rs index 6ba9f06e..4bdeb168 100644 --- a/contracts/on-chain-claim/src/address_info.rs +++ b/contracts/on-chain-claim/src/address_info.rs @@ -7,3 +7,18 @@ pub struct AddressInfo { pub last_epoch_claimed: u64, pub total_epochs_claimed: u64, } + +impl AddressInfo { + #[inline] + pub fn new( + current_streak: u64, + last_epoch_claimed: u64, + total_epochs_claimed: u64, + ) -> Self { + AddressInfo { + current_streak, + last_epoch_claimed, + total_epochs_claimed, + } + } +} diff --git a/contracts/on-chain-claim/src/config.rs b/contracts/on-chain-claim/src/config.rs index 6d72c5d4..eb746fc9 100644 --- a/contracts/on-chain-claim/src/config.rs +++ b/contracts/on-chain-claim/src/config.rs @@ -1 +1,30 @@ +multiversx_sc::imports!(); +multiversx_sc::derive_imports!(); + +use crate::address_info::*; + pub const SFT_AMOUNT: u64 = 1; +pub const MAX_REPAIR_GAP: u64 = 2; + +#[multiversx_sc::module] +pub trait ConfigModule { + #[view(getAddressInfo)] + #[storage_mapper("address_info")] + fn address_info(&self, address: &ManagedAddress) -> SingleValueMapper; + + #[view(getRepairStreakTokenIdentifier)] + #[storage_mapper("repair_streak_token_identifier")] + fn repair_streak_token_identifier(&self) -> SingleValueMapper; + + #[view(canBeRepaired)] + fn can_be_repaired(&self, address: &ManagedAddress) -> bool { + let address_info_mapper = self.address_info(address); + if address_info_mapper.is_empty() { + return false; + } + + let address_info = address_info_mapper.get(); + + address_info.last_epoch_claimed + 2 == self.blockchain().get_block_epoch() + } +} diff --git a/contracts/on-chain-claim/src/contract.rs b/contracts/on-chain-claim/src/contract.rs index 37abaf9c..133fb583 100644 --- a/contracts/on-chain-claim/src/contract.rs +++ b/contracts/on-chain-claim/src/contract.rs @@ -1,23 +1,20 @@ #![no_std] #![allow(unused_attributes)] -use address_info::AddressInfo; +pub use address_info::AddressInfo; multiversx_sc::imports!(); multiversx_sc::derive_imports!(); pub mod address_info; -mod storage; -mod config; -mod views; +pub mod config; -use crate::config::SFT_AMOUNT; +use crate::config::{SFT_AMOUNT, MAX_REPAIR_GAP}; /// An empty contract. To be used as a template when starting a new contract from scratch. #[multiversx_sc::contract] pub trait OnChainClaimContract: - storage::StorageModule - + views::ViewsModule { + config::ConfigModule { #[init] fn init( &self, @@ -32,7 +29,7 @@ pub trait OnChainClaimContract: let caller = self.blockchain().get_caller(); require!( !self.blockchain().is_smart_contract(&caller), - "Only user accounts can open mystery boxes" + "Only user accounts can perform claim" ); let current_epoch = self.blockchain().get_block_epoch(); @@ -87,18 +84,14 @@ pub trait OnChainClaimContract: require!(!address_info_mapper.is_empty(), "can't repair streak for address"); - let address_info = address_info_mapper.get(); - - require!(address_info.last_epoch_claimed + 2 == current_epoch, "can't repair streak for current epoch"); - address_info_mapper.update(|address_info| { require!( - address_info.last_epoch_claimed + 2 == current_epoch, + address_info.last_epoch_claimed + MAX_REPAIR_GAP == current_epoch, "can't repair streak for current epoch" ); - address_info.current_streak += 2; - address_info.total_epochs_claimed += 2; + address_info.current_streak += MAX_REPAIR_GAP; + address_info.total_epochs_claimed += MAX_REPAIR_GAP; address_info.last_epoch_claimed = current_epoch; }); } @@ -112,22 +105,7 @@ pub trait OnChainClaimContract: last_epoch_claimed: u64, total_epochs_claimed: u64, ) { - let address_info_mapper = self.address_info(&address); - - if address_info_mapper.is_empty() { - let address_info = AddressInfo { - current_streak: current_streak, - last_epoch_claimed: last_epoch_claimed, - total_epochs_claimed: total_epochs_claimed, - }; - self.address_info(&address).set(address_info); - return; - } - - address_info_mapper.update(|address_info| { - address_info.current_streak = current_streak; - address_info.last_epoch_claimed = last_epoch_claimed; - address_info.total_epochs_claimed = total_epochs_claimed; - }); + let address_info = AddressInfo::new(current_streak, last_epoch_claimed, total_epochs_claimed); + self.address_info(&address).set(address_info); } } diff --git a/contracts/on-chain-claim/src/storage.rs b/contracts/on-chain-claim/src/storage.rs deleted file mode 100644 index ea9368c1..00000000 --- a/contracts/on-chain-claim/src/storage.rs +++ /dev/null @@ -1,15 +0,0 @@ -multiversx_sc::imports!(); -multiversx_sc::derive_imports!(); - -use crate::address_info::*; - -#[multiversx_sc::module] -pub trait StorageModule { - #[view(getAddressInfo)] - #[storage_mapper("address_info")] - fn address_info(&self, address: &ManagedAddress) -> SingleValueMapper; - - #[view(getRepairStreakTokenIdentifier)] - #[storage_mapper("repair_streak_token_identifier")] - fn repair_streak_token_identifier(&self) -> SingleValueMapper; -} diff --git a/contracts/on-chain-claim/src/views.rs b/contracts/on-chain-claim/src/views.rs deleted file mode 100644 index 01d3328c..00000000 --- a/contracts/on-chain-claim/src/views.rs +++ /dev/null @@ -1,20 +0,0 @@ -multiversx_sc::imports!(); -multiversx_sc::derive_imports!(); - -use crate::storage::{self}; - -#[multiversx_sc::module] -pub trait ViewsModule: - storage::StorageModule { - #[view(canBeRepaired)] - fn can_be_repaired(&self, address: &ManagedAddress) -> bool { - let address_info_mapper = self.address_info(address); - if address_info_mapper.is_empty() { - return false; - } - - let address_info = address_info_mapper.get(); - - address_info.last_epoch_claimed + 2 == self.blockchain().get_block_epoch() - } -} From 8fae39fa9bf7e8a83d67c4da789fc255206345c4 Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Fri, 15 Dec 2023 18:36:31 +0200 Subject: [PATCH 07/24] Code review fixes --- contracts/on-chain-claim/src/config.rs | 16 ++++++++-------- contracts/on-chain-claim/src/contract.rs | 8 ++------ contracts/on-chain-claim/wasm/src/lib.rs | 2 +- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/contracts/on-chain-claim/src/config.rs b/contracts/on-chain-claim/src/config.rs index eb746fc9..c8b28bda 100644 --- a/contracts/on-chain-claim/src/config.rs +++ b/contracts/on-chain-claim/src/config.rs @@ -8,14 +8,6 @@ pub const MAX_REPAIR_GAP: u64 = 2; #[multiversx_sc::module] pub trait ConfigModule { - #[view(getAddressInfo)] - #[storage_mapper("address_info")] - fn address_info(&self, address: &ManagedAddress) -> SingleValueMapper; - - #[view(getRepairStreakTokenIdentifier)] - #[storage_mapper("repair_streak_token_identifier")] - fn repair_streak_token_identifier(&self) -> SingleValueMapper; - #[view(canBeRepaired)] fn can_be_repaired(&self, address: &ManagedAddress) -> bool { let address_info_mapper = self.address_info(address); @@ -27,4 +19,12 @@ pub trait ConfigModule { address_info.last_epoch_claimed + 2 == self.blockchain().get_block_epoch() } + + #[view(getAddressInfo)] + #[storage_mapper("address_info")] + fn address_info(&self, address: &ManagedAddress) -> SingleValueMapper; + + #[view(getRepairStreakTokenIdentifier)] + #[storage_mapper("repair_streak_token_identifier")] + fn repair_streak_token_identifier(&self) -> SingleValueMapper; } diff --git a/contracts/on-chain-claim/src/contract.rs b/contracts/on-chain-claim/src/contract.rs index 133fb583..791dd9a6 100644 --- a/contracts/on-chain-claim/src/contract.rs +++ b/contracts/on-chain-claim/src/contract.rs @@ -36,11 +36,7 @@ pub trait OnChainClaimContract: let address_info_mapper = self.address_info(&caller); if address_info_mapper.is_empty() { - let address_info = AddressInfo { - current_streak: 1, - last_epoch_claimed: current_epoch, - total_epochs_claimed: 1, - }; + let address_info = AddressInfo::new(1, current_epoch, 1); self.address_info(&caller).set(address_info); return; } @@ -68,7 +64,7 @@ pub trait OnChainClaimContract: let caller = self.blockchain().get_caller(); require!( !self.blockchain().is_smart_contract(&caller), - "Only user accounts can open mystery boxes" + "Only user accounts can perform claim and repair" ); let payment = self.call_value().single_esdt(); let repair_streak_token_identifier = self.repair_streak_token_identifier().get(); diff --git a/contracts/on-chain-claim/wasm/src/lib.rs b/contracts/on-chain-claim/wasm/src/lib.rs index b85c26e9..a0dd1d1a 100644 --- a/contracts/on-chain-claim/wasm/src/lib.rs +++ b/contracts/on-chain-claim/wasm/src/lib.rs @@ -25,9 +25,9 @@ multiversx_sc_wasm_adapter::endpoints! { claim => claim claimAndRepair => claim_and_repair updateState => update_state + canBeRepaired => can_be_repaired getAddressInfo => address_info getRepairStreakTokenIdentifier => repair_streak_token_identifier - canBeRepaired => can_be_repaired ) } From 4bddeacf3c819ed2db6d04ace419ef3862e2c422 Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Mon, 18 Dec 2023 13:33:05 +0200 Subject: [PATCH 08/24] Added burn sft for claimAndRepair endpoint --- contracts/on-chain-claim/src/contract.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/contracts/on-chain-claim/src/contract.rs b/contracts/on-chain-claim/src/contract.rs index 791dd9a6..c05efdb6 100644 --- a/contracts/on-chain-claim/src/contract.rs +++ b/contracts/on-chain-claim/src/contract.rs @@ -90,6 +90,12 @@ pub trait OnChainClaimContract: address_info.total_epochs_claimed += MAX_REPAIR_GAP; address_info.last_epoch_claimed = current_epoch; }); + + self.send().esdt_local_burn( + &payment.token_identifier, + payment.token_nonce, + &payment.amount, + ); } #[only_owner] From 42cfed3822cbaf99f19df61d899e53feb269d4f8 Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Mon, 18 Dec 2023 20:27:46 +0200 Subject: [PATCH 09/24] Added tests --- contracts/on-chain-claim/src/contract.rs | 2 +- contracts/on-chain-claim/tests/tests.rs | 579 +++++++++++++++++++++++ 2 files changed, 580 insertions(+), 1 deletion(-) create mode 100644 contracts/on-chain-claim/tests/tests.rs diff --git a/contracts/on-chain-claim/src/contract.rs b/contracts/on-chain-claim/src/contract.rs index c05efdb6..bd7facc4 100644 --- a/contracts/on-chain-claim/src/contract.rs +++ b/contracts/on-chain-claim/src/contract.rs @@ -102,7 +102,7 @@ pub trait OnChainClaimContract: #[endpoint(updateState)] fn update_state( &self, - address: ManagedAddress, + address: &ManagedAddress, current_streak: u64, last_epoch_claimed: u64, total_epochs_claimed: u64, diff --git a/contracts/on-chain-claim/tests/tests.rs b/contracts/on-chain-claim/tests/tests.rs new file mode 100644 index 00000000..6d67cf96 --- /dev/null +++ b/contracts/on-chain-claim/tests/tests.rs @@ -0,0 +1,579 @@ +use multiversx_sc::types::{TokenIdentifier, ManagedAddress}; +use on_chain_claim::*; +use config::ConfigModule; +use multiversx_sc_scenario::{scenario_model::*, *}; + +const ON_CHAIN_CLAIM_PATH_EXPR: &str = "file:output/on-chain-claim.wasm"; +const TOKEN_IDENTIFIER: &str = "XREPAIR-abcdef"; +const OTHER_TOKEN_IDENTIFIER_EXPR: &str = "str:XREPAIRRR-abcdef"; +const TOKEN_IDENTIFIER_EXPR: &str = "str:XREPAIR-abcdef"; +const TOKEN_NONCE: u64 = 1; +const USER1_ADDR: &str = "address:user1"; +const OWNER_ADDR: &str = "address:owner"; +const SC_ADDR: &str = "sc:on-chain-claim"; + +fn world() -> ScenarioWorld { + let mut blockchain = ScenarioWorld::new(); + blockchain.set_current_dir_from_workspace("contracts/on-chain-claim"); + + blockchain.register_contract("file:output/on-chain-claim.wasm", on_chain_claim::ContractBuilder); + blockchain +} + +#[test] +fn check_token_identifier() { + let mut world = world(); + let on_chain_claim_whitebox = WhiteboxContract::new(SC_ADDR, on_chain_claim::contract_obj); + let on_chain_claim_code = world.code_expression(ON_CHAIN_CLAIM_PATH_EXPR); + + let roles: Vec = vec![ + "ESDTRoleNFTBurn".to_string(), + ]; + + world + .set_state_step( + SetStateStep::new() + .put_account(OWNER_ADDR, Account::new().nonce(1)) + .put_account( + USER1_ADDR, + Account::new() + .nonce(1) + .esdt_nft_balance(TOKEN_IDENTIFIER_EXPR, TOKEN_NONCE, "1", Option::Some(())) + ) + .put_account( + SC_ADDR, + Account::new() + .nonce(1) + .code(&on_chain_claim_code) + .owner(OWNER_ADDR) + .esdt_roles(TOKEN_IDENTIFIER_EXPR, roles), + ) + .block_epoch(20) + .new_address(OWNER_ADDR, TOKEN_NONCE, SC_ADDR) + ) + .whitebox_call(&on_chain_claim_whitebox, + ScCallStep::new().from(SC_ADDR), + |sc| { + sc.repair_streak_token_identifier().set(TokenIdentifier::from(TOKEN_IDENTIFIER)); + } + ); +} + +#[test] +fn check_before_claim() { + let mut world = world(); + let on_chain_claim_whitebox = WhiteboxContract::new(SC_ADDR, on_chain_claim::contract_obj); + let on_chain_claim_code = world.code_expression(ON_CHAIN_CLAIM_PATH_EXPR); + + let roles: Vec = vec![ + "ESDTRoleNFTBurn".to_string(), + ]; + + world + .set_state_step( + SetStateStep::new() + .put_account(OWNER_ADDR, Account::new().nonce(1)) + .put_account( + USER1_ADDR, + Account::new() + .nonce(1) + .esdt_nft_balance(TOKEN_IDENTIFIER_EXPR, TOKEN_NONCE, "1", Option::Some(())) + ) + .put_account( + SC_ADDR, + Account::new() + .nonce(1) + .code(&on_chain_claim_code) + .owner(OWNER_ADDR) + .esdt_roles(TOKEN_IDENTIFIER_EXPR, roles), + ) + .block_epoch(20) + .new_address(OWNER_ADDR, TOKEN_NONCE, SC_ADDR) + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + let address_info_mapper = sc.address_info(managed_address); + + assert_eq!(address_info_mapper.is_empty(), true); + }); +} + +#[test] +fn check_update_state() { + let mut world = world(); + let on_chain_claim_whitebox = WhiteboxContract::new(SC_ADDR, on_chain_claim::contract_obj); + let on_chain_claim_code = world.code_expression(ON_CHAIN_CLAIM_PATH_EXPR); + + let roles: Vec = vec![ + "ESDTRoleNFTBurn".to_string(), + ]; + + world + .set_state_step( + SetStateStep::new() + .put_account(OWNER_ADDR, Account::new().nonce(1)) + .put_account( + USER1_ADDR, + Account::new() + .nonce(1) + .esdt_nft_balance(TOKEN_IDENTIFIER_EXPR, TOKEN_NONCE, "1", Option::Some(())) + ) + .put_account( + SC_ADDR, + Account::new() + .nonce(1) + .code(&on_chain_claim_code) + .owner(OWNER_ADDR) + .esdt_roles(TOKEN_IDENTIFIER_EXPR, roles), + ) + .block_epoch(20) + .new_address(OWNER_ADDR, TOKEN_NONCE, SC_ADDR) + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + let address_info_mapper = sc.address_info(managed_address); + + assert_eq!(address_info_mapper.is_empty(), true); + }) + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new().from(OWNER_ADDR), + |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + sc.update_state(managed_address, 5u64, 21u64, 7u64); + } + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + let address_info = sc.address_info(managed_address).get(); + + assert_eq!(address_info.current_streak, 5); + assert_eq!(address_info.last_epoch_claimed, 21); + assert_eq!(address_info.total_epochs_claimed, 7); + }); +} + +#[test] +fn check_after_claim() { + let mut world = world(); + let on_chain_claim_whitebox = WhiteboxContract::new(SC_ADDR, on_chain_claim::contract_obj); + let on_chain_claim_code = world.code_expression(ON_CHAIN_CLAIM_PATH_EXPR); + + let roles: Vec = vec![ + "ESDTRoleNFTBurn".to_string(), + ]; + + world + .set_state_step( + SetStateStep::new() + .put_account(OWNER_ADDR, Account::new().nonce(1)) + .put_account( + USER1_ADDR, + Account::new() + .nonce(1) + .esdt_nft_balance(TOKEN_IDENTIFIER_EXPR, TOKEN_NONCE, "1", Option::Some(())) + ) + .put_account( + SC_ADDR, + Account::new() + .nonce(1) + .code(&on_chain_claim_code) + .owner(OWNER_ADDR) + .esdt_roles(TOKEN_IDENTIFIER_EXPR, roles), + ) + .block_epoch(20) + .new_address(OWNER_ADDR, TOKEN_NONCE, SC_ADDR) + ) + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new().from(USER1_ADDR), + |sc| sc.claim(), + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + let address_info = sc.address_info(managed_address).get(); + + assert_eq!(address_info.current_streak, 1); + assert_eq!(address_info.total_epochs_claimed, 1); + assert_eq!(address_info.last_epoch_claimed, 20); + }) + .set_state_step( + SetStateStep::new() + .block_epoch(21) + ) + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new().from(USER1_ADDR), + |sc| sc.claim(), + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + let address_info = sc.address_info(managed_address).get(); + + assert_eq!(address_info.current_streak, 2); + assert_eq!(address_info.total_epochs_claimed, 2); + assert_eq!(address_info.last_epoch_claimed, 21); + }) + .set_state_step( + SetStateStep::new() + .block_epoch(25) + ) + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new().from(USER1_ADDR), + |sc| sc.claim(), + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + let address_info = sc.address_info(managed_address).get(); + + assert_eq!(address_info.current_streak, 1); + assert_eq!(address_info.total_epochs_claimed, 3); + assert_eq!(address_info.last_epoch_claimed, 25); + }); +} + +#[test] +fn check_claim_and_repair() { + let mut world = world(); + let on_chain_claim_whitebox = WhiteboxContract::new(SC_ADDR, on_chain_claim::contract_obj); + let on_chain_claim_code = world.code_expression(ON_CHAIN_CLAIM_PATH_EXPR); + + let roles: Vec = vec![ + "ESDTRoleNFTBurn".to_string(), + ]; + + world + .set_state_step( + SetStateStep::new() + .put_account(OWNER_ADDR, Account::new().nonce(1)) + .put_account( + USER1_ADDR, + Account::new() + .nonce(1) + .esdt_nft_balance(TOKEN_IDENTIFIER_EXPR, TOKEN_NONCE, "100", Option::Some(())) + .esdt_nft_balance(OTHER_TOKEN_IDENTIFIER_EXPR, TOKEN_NONCE, "1", Option::Some(())) + ) + .put_account( + SC_ADDR, + Account::new() + .nonce(1) + .code(&on_chain_claim_code) + .owner(OWNER_ADDR) + .esdt_roles(TOKEN_IDENTIFIER_EXPR, roles), + ) + .block_epoch(20) + .new_address(OWNER_ADDR, TOKEN_NONCE, SC_ADDR) + ) + .whitebox_call(&on_chain_claim_whitebox, + ScCallStep::new().from(SC_ADDR), + |sc| { + sc.repair_streak_token_identifier().set(TokenIdentifier::from(TOKEN_IDENTIFIER)); + } + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + let address_info_mapper = sc.address_info(managed_address); + + assert_eq!(address_info_mapper.is_empty(), true); + }) + .whitebox_call_check( + &on_chain_claim_whitebox, + ScCallStep::new() + .from(USER1_ADDR) + .to(SC_ADDR) + .esdt_transfer(TOKEN_IDENTIFIER_EXPR, 1, "1") + .no_expect(), + |sc| { + sc.claim_and_repair(); + }, + |r| { + r.assert_user_error("can't repair streak for address"); + }, + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + let address_info_mapper = sc.address_info(managed_address); + + assert_eq!(address_info_mapper.is_empty(), true); + }) + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new().from(USER1_ADDR), + |sc| sc.claim(), + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + let address_info = sc.address_info(managed_address).get(); + + assert_eq!(address_info.current_streak, 1); + assert_eq!(address_info.total_epochs_claimed, 1); + assert_eq!(address_info.last_epoch_claimed, 20); + }) + .set_state_step( + SetStateStep::new() + .block_epoch(21) + ) + .whitebox_call_check( + &on_chain_claim_whitebox, + ScCallStep::new() + .from(USER1_ADDR) + .to(SC_ADDR) + .esdt_transfer(TOKEN_IDENTIFIER_EXPR, TOKEN_NONCE, "1") + .no_expect(), + |sc| { + sc.claim_and_repair(); + }, + |r| { + r.assert_user_error("can't repair streak for current epoch"); + }, + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + let address_info = sc.address_info(managed_address).get(); + + assert_eq!(address_info.current_streak, 1); + assert_eq!(address_info.total_epochs_claimed, 1); + assert_eq!(address_info.last_epoch_claimed, 20); + }) + .set_state_step( + SetStateStep::new() + .block_epoch(22) + ) + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new() + .from(USER1_ADDR) + .to(SC_ADDR) + .esdt_transfer(TOKEN_IDENTIFIER_EXPR, 1, "1"), + |sc| { + sc.claim_and_repair(); + }, + ) + .whitebox_call_check( + &on_chain_claim_whitebox, + ScCallStep::new() + .from(USER1_ADDR) + .to(SC_ADDR) + .esdt_transfer(OTHER_TOKEN_IDENTIFIER_EXPR, 1, "1") + .no_expect(), + |sc| { + sc.claim_and_repair(); + }, + |r| { + r.assert_user_error("Bad payment token"); + }, + ) + .whitebox_call_check( + &on_chain_claim_whitebox, + ScCallStep::new() + .from(USER1_ADDR) + .to(SC_ADDR) + .esdt_transfer(TOKEN_IDENTIFIER_EXPR, TOKEN_NONCE, "2") + .no_expect(), + |sc| { + sc.claim_and_repair(); + }, + |r| { + r.assert_user_error("Bad payment amount"); + }, + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + let address_info = sc.address_info(managed_address).get(); + assert_eq!(address_info.current_streak, 3); + assert_eq!(address_info.total_epochs_claimed, 3); + assert_eq!(address_info.last_epoch_claimed, 22); + }) + .set_state_step( + SetStateStep::new() + .block_epoch(25) + ) + .whitebox_call_check( + &on_chain_claim_whitebox, + ScCallStep::new() + .from(USER1_ADDR) + .to(SC_ADDR) + .esdt_transfer(TOKEN_IDENTIFIER_EXPR, TOKEN_NONCE, "1") + .no_expect(), + |sc| { + sc.claim_and_repair(); + }, + |r| { + r.assert_user_error("can't repair streak for current epoch"); + }, + ); +} + +#[test] +fn on_chain_claim_whitebox() { + let mut world = world(); + let on_chain_claim_whitebox = WhiteboxContract::new(SC_ADDR, on_chain_claim::contract_obj); + let on_chain_claim_code = world.code_expression(ON_CHAIN_CLAIM_PATH_EXPR); + + let roles: Vec = vec![ + "ESDTRoleNFTBurn".to_string(), + ]; + + world + .set_state_step( + SetStateStep::new() + .put_account(OWNER_ADDR, Account::new().nonce(1)) + .put_account( + USER1_ADDR, + Account::new() + .nonce(1) + .esdt_nft_balance(TOKEN_IDENTIFIER_EXPR, TOKEN_NONCE, "1", Option::Some(())) + ) + .put_account( + SC_ADDR, + Account::new() + .nonce(1) + .code(&on_chain_claim_code) + .owner(OWNER_ADDR) + .esdt_roles(TOKEN_IDENTIFIER_EXPR, roles), + ) + .block_epoch(20) + .new_address(OWNER_ADDR, TOKEN_NONCE, SC_ADDR) + ) + .whitebox_call(&on_chain_claim_whitebox, + ScCallStep::new().from(SC_ADDR), + |sc| { + sc.repair_streak_token_identifier().set(TokenIdentifier::from(TOKEN_IDENTIFIER)); + } + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let repair_streak_token_identifier = sc.repair_streak_token_identifier().get(); + let identifier = TokenIdentifier::from(TOKEN_IDENTIFIER); + assert_eq!(repair_streak_token_identifier, identifier); + }) + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new().from(USER1_ADDR), + |sc| sc.claim(), + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + let address_info = sc.address_info(managed_address).get(); + assert_eq!(address_info.current_streak, 1); + assert_eq!(address_info.total_epochs_claimed, 1); + assert_eq!(address_info.last_epoch_claimed, 20); + }) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + let can_be_repaired = sc.can_be_repaired(managed_address); + assert_eq!(can_be_repaired, false); + }) + .set_state_step( + SetStateStep::new() + .block_epoch(21) + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + let can_be_repaired = sc.can_be_repaired(managed_address); + assert_eq!(can_be_repaired, false); + }) + .set_state_step( + SetStateStep::new() + .block_epoch(22) + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + let can_be_repaired = sc.can_be_repaired(managed_address); + assert_eq!(can_be_repaired, true); + }) + .set_state_step( + SetStateStep::new() + .block_epoch(23) + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + let can_be_repaired = sc.can_be_repaired(managed_address); + assert_eq!(can_be_repaired, false); + }) + .whitebox_call_check( + &on_chain_claim_whitebox, + ScCallStep::new() + .from(USER1_ADDR) + .to(SC_ADDR) + .esdt_transfer(TOKEN_IDENTIFIER_EXPR, 1, "1") + .no_expect(), + |sc| { + sc.claim_and_repair(); + }, + |r| { + r.assert_user_error("can't repair streak for current epoch"); + }, + ) + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new().from(USER1_ADDR), + |sc| sc.claim(), + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + let address_info = sc.address_info(managed_address).get(); + assert_eq!(address_info.current_streak, 1); + assert_eq!(address_info.total_epochs_claimed, 2); + assert_eq!(address_info.last_epoch_claimed, 23); + }) + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new().from(OWNER_ADDR), + |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + sc.update_state(managed_address, 5u64, 21u64, 7u64); + } + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + let can_be_repaired = sc.can_be_repaired(managed_address); + assert_eq!(can_be_repaired, true); + }) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + let address_info = sc.address_info(managed_address).get(); + assert_eq!(address_info.current_streak, 5); + assert_eq!(address_info.total_epochs_claimed, 7); + assert_eq!(address_info.last_epoch_claimed, 21); + }) + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new() + .from(USER1_ADDR) + .to(SC_ADDR) + .esdt_transfer(TOKEN_IDENTIFIER_EXPR, 1, "1"), + |sc| { + sc.claim_and_repair(); + }, + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address.clone()); + let address_info = sc.address_info(managed_address).get(); + assert_eq!(address_info.current_streak, 7); + assert_eq!(address_info.total_epochs_claimed, 9); + assert_eq!(address_info.last_epoch_claimed, 23); + }); +} From 424d21ca7562d681a6ad0335f0cdba67b9dda8da Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Mon, 18 Dec 2023 20:31:51 +0200 Subject: [PATCH 10/24] fixes --- contracts/on-chain-claim/src/contract.rs | 2 +- contracts/on-chain-claim/tests/tests.rs | 52 ++++++++++++------------ 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/contracts/on-chain-claim/src/contract.rs b/contracts/on-chain-claim/src/contract.rs index bd7facc4..f49d12d8 100644 --- a/contracts/on-chain-claim/src/contract.rs +++ b/contracts/on-chain-claim/src/contract.rs @@ -108,6 +108,6 @@ pub trait OnChainClaimContract: total_epochs_claimed: u64, ) { let address_info = AddressInfo::new(current_streak, last_epoch_claimed, total_epochs_claimed); - self.address_info(&address).set(address_info); + self.address_info(address).set(address_info); } } diff --git a/contracts/on-chain-claim/tests/tests.rs b/contracts/on-chain-claim/tests/tests.rs index 6d67cf96..6357411f 100644 --- a/contracts/on-chain-claim/tests/tests.rs +++ b/contracts/on-chain-claim/tests/tests.rs @@ -92,10 +92,10 @@ fn check_before_claim() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); let address_info_mapper = sc.address_info(managed_address); - assert_eq!(address_info_mapper.is_empty(), true); + assert!(address_info_mapper.is_empty()); }); } @@ -132,23 +132,23 @@ fn check_update_state() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); let address_info_mapper = sc.address_info(managed_address); - assert_eq!(address_info_mapper.is_empty(), true); + assert!(address_info_mapper.is_empty()); }) .whitebox_call( &on_chain_claim_whitebox, ScCallStep::new().from(OWNER_ADDR), |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); sc.update_state(managed_address, 5u64, 21u64, 7u64); } ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); assert_eq!(address_info.current_streak, 5); @@ -195,7 +195,7 @@ fn check_after_claim() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); assert_eq!(address_info.current_streak, 1); @@ -213,7 +213,7 @@ fn check_after_claim() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); assert_eq!(address_info.current_streak, 2); @@ -231,7 +231,7 @@ fn check_after_claim() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); assert_eq!(address_info.current_streak, 1); @@ -280,10 +280,10 @@ fn check_claim_and_repair() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); let address_info_mapper = sc.address_info(managed_address); - assert_eq!(address_info_mapper.is_empty(), true); + assert!(address_info_mapper.is_empty()); }) .whitebox_call_check( &on_chain_claim_whitebox, @@ -301,10 +301,10 @@ fn check_claim_and_repair() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); let address_info_mapper = sc.address_info(managed_address); - assert_eq!(address_info_mapper.is_empty(), true); + assert!(address_info_mapper.is_empty()); }) .whitebox_call( &on_chain_claim_whitebox, @@ -313,7 +313,7 @@ fn check_claim_and_repair() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); assert_eq!(address_info.current_streak, 1); @@ -340,7 +340,7 @@ fn check_claim_and_repair() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); assert_eq!(address_info.current_streak, 1); @@ -391,7 +391,7 @@ fn check_claim_and_repair() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); assert_eq!(address_info.current_streak, 3); assert_eq!(address_info.total_epochs_claimed, 3); @@ -466,7 +466,7 @@ fn on_chain_claim_whitebox() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); assert_eq!(address_info.current_streak, 1); assert_eq!(address_info.total_epochs_claimed, 1); @@ -474,7 +474,7 @@ fn on_chain_claim_whitebox() { }) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); let can_be_repaired = sc.can_be_repaired(managed_address); assert_eq!(can_be_repaired, false); }) @@ -484,7 +484,7 @@ fn on_chain_claim_whitebox() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); let can_be_repaired = sc.can_be_repaired(managed_address); assert_eq!(can_be_repaired, false); }) @@ -494,7 +494,7 @@ fn on_chain_claim_whitebox() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); let can_be_repaired = sc.can_be_repaired(managed_address); assert_eq!(can_be_repaired, true); }) @@ -504,7 +504,7 @@ fn on_chain_claim_whitebox() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); let can_be_repaired = sc.can_be_repaired(managed_address); assert_eq!(can_be_repaired, false); }) @@ -529,7 +529,7 @@ fn on_chain_claim_whitebox() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); assert_eq!(address_info.current_streak, 1); assert_eq!(address_info.total_epochs_claimed, 2); @@ -540,19 +540,19 @@ fn on_chain_claim_whitebox() { ScCallStep::new().from(OWNER_ADDR), |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); sc.update_state(managed_address, 5u64, 21u64, 7u64); } ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); let can_be_repaired = sc.can_be_repaired(managed_address); assert_eq!(can_be_repaired, true); }) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); assert_eq!(address_info.current_streak, 5); assert_eq!(address_info.total_epochs_claimed, 7); @@ -570,7 +570,7 @@ fn on_chain_claim_whitebox() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address.clone()); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); assert_eq!(address_info.current_streak, 7); assert_eq!(address_info.total_epochs_claimed, 9); From 45fe5d62e17a26ccb455343b989ed39086386b0f Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Mon, 18 Dec 2023 20:34:23 +0200 Subject: [PATCH 11/24] fixes --- contracts/on-chain-claim/tests/tests.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/contracts/on-chain-claim/tests/tests.rs b/contracts/on-chain-claim/tests/tests.rs index 6357411f..ac3cf0d6 100644 --- a/contracts/on-chain-claim/tests/tests.rs +++ b/contracts/on-chain-claim/tests/tests.rs @@ -476,7 +476,7 @@ fn on_chain_claim_whitebox() { let address = AddressValue::from(USER1_ADDR).to_address(); let managed_address = &ManagedAddress::from(address); let can_be_repaired = sc.can_be_repaired(managed_address); - assert_eq!(can_be_repaired, false); + assert!(!can_be_repaired); }) .set_state_step( SetStateStep::new() @@ -486,7 +486,7 @@ fn on_chain_claim_whitebox() { let address = AddressValue::from(USER1_ADDR).to_address(); let managed_address = &ManagedAddress::from(address); let can_be_repaired = sc.can_be_repaired(managed_address); - assert_eq!(can_be_repaired, false); + assert!(!can_be_repaired); }) .set_state_step( SetStateStep::new() @@ -496,7 +496,7 @@ fn on_chain_claim_whitebox() { let address = AddressValue::from(USER1_ADDR).to_address(); let managed_address = &ManagedAddress::from(address); let can_be_repaired = sc.can_be_repaired(managed_address); - assert_eq!(can_be_repaired, true); + assert!(can_be_repaired); }) .set_state_step( SetStateStep::new() @@ -506,7 +506,7 @@ fn on_chain_claim_whitebox() { let address = AddressValue::from(USER1_ADDR).to_address(); let managed_address = &ManagedAddress::from(address); let can_be_repaired = sc.can_be_repaired(managed_address); - assert_eq!(can_be_repaired, false); + assert!(!can_be_repaired); }) .whitebox_call_check( &on_chain_claim_whitebox, @@ -548,7 +548,7 @@ fn on_chain_claim_whitebox() { let address = AddressValue::from(USER1_ADDR).to_address(); let managed_address = &ManagedAddress::from(address); let can_be_repaired = sc.can_be_repaired(managed_address); - assert_eq!(can_be_repaired, true); + assert!(can_be_repaired); }) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); From eeeec3013dcb992f8d055bb4a27df476b3441bc0 Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Fri, 22 Dec 2023 14:06:03 +0200 Subject: [PATCH 12/24] Code review fixes --- contracts/on-chain-claim/src/config.rs | 6 +++--- contracts/on-chain-claim/src/contract.rs | 23 +++++++++++------------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/contracts/on-chain-claim/src/config.rs b/contracts/on-chain-claim/src/config.rs index c8b28bda..8c55c262 100644 --- a/contracts/on-chain-claim/src/config.rs +++ b/contracts/on-chain-claim/src/config.rs @@ -17,13 +17,13 @@ pub trait ConfigModule { let address_info = address_info_mapper.get(); - address_info.last_epoch_claimed + 2 == self.blockchain().get_block_epoch() + address_info.last_epoch_claimed + MAX_REPAIR_GAP == self.blockchain().get_block_epoch() } - + #[view(getAddressInfo)] #[storage_mapper("address_info")] fn address_info(&self, address: &ManagedAddress) -> SingleValueMapper; - + #[view(getRepairStreakTokenIdentifier)] #[storage_mapper("repair_streak_token_identifier")] fn repair_streak_token_identifier(&self) -> SingleValueMapper; diff --git a/contracts/on-chain-claim/src/contract.rs b/contracts/on-chain-claim/src/contract.rs index f49d12d8..3be471c5 100644 --- a/contracts/on-chain-claim/src/contract.rs +++ b/contracts/on-chain-claim/src/contract.rs @@ -9,17 +9,12 @@ multiversx_sc::derive_imports!(); pub mod address_info; pub mod config; -use crate::config::{SFT_AMOUNT, MAX_REPAIR_GAP}; +use crate::config::{MAX_REPAIR_GAP, SFT_AMOUNT}; -/// An empty contract. To be used as a template when starting a new contract from scratch. #[multiversx_sc::contract] -pub trait OnChainClaimContract: - config::ConfigModule { +pub trait OnChainClaimContract: config::ConfigModule { #[init] - fn init( - &self, - repair_streak_token_id: TokenIdentifier, - ) { + fn init(&self, repair_streak_token_id: TokenIdentifier) { self.repair_streak_token_identifier() .set(repair_streak_token_id); } @@ -78,11 +73,14 @@ pub trait OnChainClaimContract: let address_info_mapper = self.address_info(&caller); - require!(!address_info_mapper.is_empty(), "can't repair streak for address"); + require!( + !address_info_mapper.is_empty(), + "can't repair streak for address" + ); address_info_mapper.update(|address_info| { require!( - address_info.last_epoch_claimed + MAX_REPAIR_GAP == current_epoch, + address_info.last_epoch_claimed + MAX_REPAIR_GAP == current_epoch, "can't repair streak for current epoch" ); @@ -101,13 +99,14 @@ pub trait OnChainClaimContract: #[only_owner] #[endpoint(updateState)] fn update_state( - &self, + &self, address: &ManagedAddress, current_streak: u64, last_epoch_claimed: u64, total_epochs_claimed: u64, ) { - let address_info = AddressInfo::new(current_streak, last_epoch_claimed, total_epochs_claimed); + let address_info = + AddressInfo::new(current_streak, last_epoch_claimed, total_epochs_claimed); self.address_info(address).set(address_info); } } From bff6b6a6c101548dbe5cc544dbfec241b5ea6ded Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Mon, 8 Jan 2024 12:35:21 +0200 Subject: [PATCH 13/24] Upgraded packages + new best streak field + increase max gap to 5 --- contracts/on-chain-claim/Cargo.toml | 4 +- contracts/on-chain-claim/meta/Cargo.toml | 4 +- contracts/on-chain-claim/src/address_info.rs | 3 + contracts/on-chain-claim/src/config.rs | 14 +- contracts/on-chain-claim/src/contract.rs | 27 +- contracts/on-chain-claim/tests/tests.rs | 406 +++++++++++++------ contracts/on-chain-claim/wasm/Cargo.lock | 41 +- contracts/on-chain-claim/wasm/Cargo.toml | 3 +- 8 files changed, 335 insertions(+), 167 deletions(-) diff --git a/contracts/on-chain-claim/Cargo.toml b/contracts/on-chain-claim/Cargo.toml index bc8716f7..6cc99a8d 100644 --- a/contracts/on-chain-claim/Cargo.toml +++ b/contracts/on-chain-claim/Cargo.toml @@ -9,7 +9,7 @@ publish = false path = "src/contract.rs" [dependencies.multiversx-sc] -version = "0.45.1" +version = "0.45.2" [dev-dependencies.multiversx-sc-scenario] -version = "0.45.1" +version = "0.45.2" diff --git a/contracts/on-chain-claim/meta/Cargo.toml b/contracts/on-chain-claim/meta/Cargo.toml index 0488d955..1da43155 100644 --- a/contracts/on-chain-claim/meta/Cargo.toml +++ b/contracts/on-chain-claim/meta/Cargo.toml @@ -3,7 +3,7 @@ name = "on-chain-claim-meta" version = "0.0.0" edition = "2018" publish = false -authors = [ "you",] +authors = [ "Vlad Bucur "] [dev-dependencies] @@ -11,5 +11,5 @@ authors = [ "you",] path = ".." [dependencies.multiversx-sc-meta] -version = "0.45.1" +version = "0.45.2" default-features = false diff --git a/contracts/on-chain-claim/src/address_info.rs b/contracts/on-chain-claim/src/address_info.rs index 4bdeb168..4c4a3813 100644 --- a/contracts/on-chain-claim/src/address_info.rs +++ b/contracts/on-chain-claim/src/address_info.rs @@ -6,6 +6,7 @@ pub struct AddressInfo { pub current_streak: u64, pub last_epoch_claimed: u64, pub total_epochs_claimed: u64, + pub best_streak: u64, } impl AddressInfo { @@ -14,11 +15,13 @@ impl AddressInfo { current_streak: u64, last_epoch_claimed: u64, total_epochs_claimed: u64, + best_streak: u64, ) -> Self { AddressInfo { current_streak, last_epoch_claimed, total_epochs_claimed, + best_streak, } } } diff --git a/contracts/on-chain-claim/src/config.rs b/contracts/on-chain-claim/src/config.rs index 8c55c262..67895abf 100644 --- a/contracts/on-chain-claim/src/config.rs +++ b/contracts/on-chain-claim/src/config.rs @@ -4,10 +4,18 @@ multiversx_sc::derive_imports!(); use crate::address_info::*; pub const SFT_AMOUNT: u64 = 1; -pub const MAX_REPAIR_GAP: u64 = 2; +pub const MAX_REPAIR_GAP: u64 = 5; #[multiversx_sc::module] pub trait ConfigModule { + fn get_missed_epochs(&self, current_epoch: u64, last_epoch_claimed: u64) -> u64 { + if current_epoch - last_epoch_claimed <= 1 { + return 0; + } + + current_epoch - last_epoch_claimed - 1 + } + #[view(canBeRepaired)] fn can_be_repaired(&self, address: &ManagedAddress) -> bool { let address_info_mapper = self.address_info(address); @@ -16,8 +24,10 @@ pub trait ConfigModule { } let address_info = address_info_mapper.get(); + let current_epoch = self.blockchain().get_block_epoch(); + let missed_epochs = self.get_missed_epochs(current_epoch, address_info.last_epoch_claimed); - address_info.last_epoch_claimed + MAX_REPAIR_GAP == self.blockchain().get_block_epoch() + missed_epochs > 0 && missed_epochs <= MAX_REPAIR_GAP } #[view(getAddressInfo)] diff --git a/contracts/on-chain-claim/src/contract.rs b/contracts/on-chain-claim/src/contract.rs index 3be471c5..cabb0575 100644 --- a/contracts/on-chain-claim/src/contract.rs +++ b/contracts/on-chain-claim/src/contract.rs @@ -31,7 +31,7 @@ pub trait OnChainClaimContract: config::ConfigModule { let address_info_mapper = self.address_info(&caller); if address_info_mapper.is_empty() { - let address_info = AddressInfo::new(1, current_epoch, 1); + let address_info = AddressInfo::new(1, current_epoch, 1, 1); self.address_info(&caller).set(address_info); return; } @@ -50,6 +50,10 @@ pub trait OnChainClaimContract: config::ConfigModule { address_info.total_epochs_claimed += 1; address_info.last_epoch_claimed = current_epoch; + + if address_info.best_streak < address_info.current_streak { + address_info.best_streak = address_info.current_streak; + } }); } @@ -79,14 +83,20 @@ pub trait OnChainClaimContract: config::ConfigModule { ); address_info_mapper.update(|address_info| { + let missed_epochs = + self.get_missed_epochs(current_epoch, address_info.last_epoch_claimed); + require!( - address_info.last_epoch_claimed + MAX_REPAIR_GAP == current_epoch, + missed_epochs > 0 && missed_epochs <= MAX_REPAIR_GAP, "can't repair streak for current epoch" ); - address_info.current_streak += MAX_REPAIR_GAP; - address_info.total_epochs_claimed += MAX_REPAIR_GAP; + address_info.current_streak += missed_epochs + 1; + address_info.total_epochs_claimed += missed_epochs + 1; address_info.last_epoch_claimed = current_epoch; + if address_info.best_streak < address_info.current_streak { + address_info.best_streak = address_info.current_streak; + } }); self.send().esdt_local_burn( @@ -104,9 +114,14 @@ pub trait OnChainClaimContract: config::ConfigModule { current_streak: u64, last_epoch_claimed: u64, total_epochs_claimed: u64, + best_streak: u64, ) { - let address_info = - AddressInfo::new(current_streak, last_epoch_claimed, total_epochs_claimed); + let address_info = AddressInfo::new( + current_streak, + last_epoch_claimed, + total_epochs_claimed, + best_streak, + ); self.address_info(address).set(address_info); } } diff --git a/contracts/on-chain-claim/tests/tests.rs b/contracts/on-chain-claim/tests/tests.rs index ac3cf0d6..1670328e 100644 --- a/contracts/on-chain-claim/tests/tests.rs +++ b/contracts/on-chain-claim/tests/tests.rs @@ -1,7 +1,7 @@ -use multiversx_sc::types::{TokenIdentifier, ManagedAddress}; -use on_chain_claim::*; use config::ConfigModule; +use multiversx_sc::types::{ManagedAddress, TokenIdentifier}; use multiversx_sc_scenario::{scenario_model::*, *}; +use on_chain_claim::*; const ON_CHAIN_CLAIM_PATH_EXPR: &str = "file:output/on-chain-claim.wasm"; const TOKEN_IDENTIFIER: &str = "XREPAIR-abcdef"; @@ -16,7 +16,10 @@ fn world() -> ScenarioWorld { let mut blockchain = ScenarioWorld::new(); blockchain.set_current_dir_from_workspace("contracts/on-chain-claim"); - blockchain.register_contract("file:output/on-chain-claim.wasm", on_chain_claim::ContractBuilder); + blockchain.register_contract( + "file:output/on-chain-claim.wasm", + on_chain_claim::ContractBuilder, + ); blockchain } @@ -26,9 +29,7 @@ fn check_token_identifier() { let on_chain_claim_whitebox = WhiteboxContract::new(SC_ADDR, on_chain_claim::contract_obj); let on_chain_claim_code = world.code_expression(ON_CHAIN_CLAIM_PATH_EXPR); - let roles: Vec = vec![ - "ESDTRoleNFTBurn".to_string(), - ]; + let roles: Vec = vec!["ESDTRoleNFTBurn".to_string()]; world .set_state_step( @@ -36,9 +37,12 @@ fn check_token_identifier() { .put_account(OWNER_ADDR, Account::new().nonce(1)) .put_account( USER1_ADDR, - Account::new() - .nonce(1) - .esdt_nft_balance(TOKEN_IDENTIFIER_EXPR, TOKEN_NONCE, "1", Option::Some(())) + Account::new().nonce(1).esdt_nft_balance( + TOKEN_IDENTIFIER_EXPR, + TOKEN_NONCE, + "1", + Option::Some(()), + ), ) .put_account( SC_ADDR, @@ -49,13 +53,15 @@ fn check_token_identifier() { .esdt_roles(TOKEN_IDENTIFIER_EXPR, roles), ) .block_epoch(20) - .new_address(OWNER_ADDR, TOKEN_NONCE, SC_ADDR) + .new_address(OWNER_ADDR, TOKEN_NONCE, SC_ADDR), ) - .whitebox_call(&on_chain_claim_whitebox, - ScCallStep::new().from(SC_ADDR), + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new().from(SC_ADDR), |sc| { - sc.repair_streak_token_identifier().set(TokenIdentifier::from(TOKEN_IDENTIFIER)); - } + sc.repair_streak_token_identifier() + .set(TokenIdentifier::from(TOKEN_IDENTIFIER)); + }, ); } @@ -65,9 +71,7 @@ fn check_before_claim() { let on_chain_claim_whitebox = WhiteboxContract::new(SC_ADDR, on_chain_claim::contract_obj); let on_chain_claim_code = world.code_expression(ON_CHAIN_CLAIM_PATH_EXPR); - let roles: Vec = vec![ - "ESDTRoleNFTBurn".to_string(), - ]; + let roles: Vec = vec!["ESDTRoleNFTBurn".to_string()]; world .set_state_step( @@ -75,9 +79,12 @@ fn check_before_claim() { .put_account(OWNER_ADDR, Account::new().nonce(1)) .put_account( USER1_ADDR, - Account::new() - .nonce(1) - .esdt_nft_balance(TOKEN_IDENTIFIER_EXPR, TOKEN_NONCE, "1", Option::Some(())) + Account::new().nonce(1).esdt_nft_balance( + TOKEN_IDENTIFIER_EXPR, + TOKEN_NONCE, + "1", + Option::Some(()), + ), ) .put_account( SC_ADDR, @@ -88,11 +95,11 @@ fn check_before_claim() { .esdt_roles(TOKEN_IDENTIFIER_EXPR, roles), ) .block_epoch(20) - .new_address(OWNER_ADDR, TOKEN_NONCE, SC_ADDR) + .new_address(OWNER_ADDR, TOKEN_NONCE, SC_ADDR), ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); + let managed_address = &ManagedAddress::from(address); let address_info_mapper = sc.address_info(managed_address); assert!(address_info_mapper.is_empty()); @@ -105,9 +112,7 @@ fn check_update_state() { let on_chain_claim_whitebox = WhiteboxContract::new(SC_ADDR, on_chain_claim::contract_obj); let on_chain_claim_code = world.code_expression(ON_CHAIN_CLAIM_PATH_EXPR); - let roles: Vec = vec![ - "ESDTRoleNFTBurn".to_string(), - ]; + let roles: Vec = vec!["ESDTRoleNFTBurn".to_string()]; world .set_state_step( @@ -115,9 +120,12 @@ fn check_update_state() { .put_account(OWNER_ADDR, Account::new().nonce(1)) .put_account( USER1_ADDR, - Account::new() - .nonce(1) - .esdt_nft_balance(TOKEN_IDENTIFIER_EXPR, TOKEN_NONCE, "1", Option::Some(())) + Account::new().nonce(1).esdt_nft_balance( + TOKEN_IDENTIFIER_EXPR, + TOKEN_NONCE, + "1", + Option::Some(()), + ), ) .put_account( SC_ADDR, @@ -128,11 +136,11 @@ fn check_update_state() { .esdt_roles(TOKEN_IDENTIFIER_EXPR, roles), ) .block_epoch(20) - .new_address(OWNER_ADDR, TOKEN_NONCE, SC_ADDR) + .new_address(OWNER_ADDR, TOKEN_NONCE, SC_ADDR), ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); + let managed_address = &ManagedAddress::from(address); let address_info_mapper = sc.address_info(managed_address); assert!(address_info_mapper.is_empty()); @@ -141,14 +149,14 @@ fn check_update_state() { &on_chain_claim_whitebox, ScCallStep::new().from(OWNER_ADDR), |sc| { - let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); - sc.update_state(managed_address, 5u64, 21u64, 7u64); - } + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address); + sc.update_state(managed_address, 5u64, 21u64, 7u64, 5u64); + }, ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); assert_eq!(address_info.current_streak, 5); @@ -163,9 +171,7 @@ fn check_after_claim() { let on_chain_claim_whitebox = WhiteboxContract::new(SC_ADDR, on_chain_claim::contract_obj); let on_chain_claim_code = world.code_expression(ON_CHAIN_CLAIM_PATH_EXPR); - let roles: Vec = vec![ - "ESDTRoleNFTBurn".to_string(), - ]; + let roles: Vec = vec!["ESDTRoleNFTBurn".to_string()]; world .set_state_step( @@ -173,9 +179,12 @@ fn check_after_claim() { .put_account(OWNER_ADDR, Account::new().nonce(1)) .put_account( USER1_ADDR, - Account::new() - .nonce(1) - .esdt_nft_balance(TOKEN_IDENTIFIER_EXPR, TOKEN_NONCE, "1", Option::Some(())) + Account::new().nonce(1).esdt_nft_balance( + TOKEN_IDENTIFIER_EXPR, + TOKEN_NONCE, + "1", + Option::Some(()), + ), ) .put_account( SC_ADDR, @@ -186,7 +195,7 @@ fn check_after_claim() { .esdt_roles(TOKEN_IDENTIFIER_EXPR, roles), ) .block_epoch(20) - .new_address(OWNER_ADDR, TOKEN_NONCE, SC_ADDR) + .new_address(OWNER_ADDR, TOKEN_NONCE, SC_ADDR), ) .whitebox_call( &on_chain_claim_whitebox, @@ -195,17 +204,14 @@ fn check_after_claim() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); assert_eq!(address_info.current_streak, 1); assert_eq!(address_info.total_epochs_claimed, 1); assert_eq!(address_info.last_epoch_claimed, 20); }) - .set_state_step( - SetStateStep::new() - .block_epoch(21) - ) + .set_state_step(SetStateStep::new().block_epoch(21)) .whitebox_call( &on_chain_claim_whitebox, ScCallStep::new().from(USER1_ADDR), @@ -213,17 +219,14 @@ fn check_after_claim() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); assert_eq!(address_info.current_streak, 2); assert_eq!(address_info.total_epochs_claimed, 2); assert_eq!(address_info.last_epoch_claimed, 21); }) - .set_state_step( - SetStateStep::new() - .block_epoch(25) - ) + .set_state_step(SetStateStep::new().block_epoch(25)) .whitebox_call( &on_chain_claim_whitebox, ScCallStep::new().from(USER1_ADDR), @@ -231,7 +234,7 @@ fn check_after_claim() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); assert_eq!(address_info.current_streak, 1); @@ -246,9 +249,7 @@ fn check_claim_and_repair() { let on_chain_claim_whitebox = WhiteboxContract::new(SC_ADDR, on_chain_claim::contract_obj); let on_chain_claim_code = world.code_expression(ON_CHAIN_CLAIM_PATH_EXPR); - let roles: Vec = vec![ - "ESDTRoleNFTBurn".to_string(), - ]; + let roles: Vec = vec!["ESDTRoleNFTBurn".to_string()]; world .set_state_step( @@ -258,8 +259,18 @@ fn check_claim_and_repair() { USER1_ADDR, Account::new() .nonce(1) - .esdt_nft_balance(TOKEN_IDENTIFIER_EXPR, TOKEN_NONCE, "100", Option::Some(())) - .esdt_nft_balance(OTHER_TOKEN_IDENTIFIER_EXPR, TOKEN_NONCE, "1", Option::Some(())) + .esdt_nft_balance( + TOKEN_IDENTIFIER_EXPR, + TOKEN_NONCE, + "100", + Option::Some(()), + ) + .esdt_nft_balance( + OTHER_TOKEN_IDENTIFIER_EXPR, + TOKEN_NONCE, + "1", + Option::Some(()), + ), ) .put_account( SC_ADDR, @@ -270,17 +281,19 @@ fn check_claim_and_repair() { .esdt_roles(TOKEN_IDENTIFIER_EXPR, roles), ) .block_epoch(20) - .new_address(OWNER_ADDR, TOKEN_NONCE, SC_ADDR) + .new_address(OWNER_ADDR, TOKEN_NONCE, SC_ADDR), ) - .whitebox_call(&on_chain_claim_whitebox, - ScCallStep::new().from(SC_ADDR), + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new().from(SC_ADDR), |sc| { - sc.repair_streak_token_identifier().set(TokenIdentifier::from(TOKEN_IDENTIFIER)); - } + sc.repair_streak_token_identifier() + .set(TokenIdentifier::from(TOKEN_IDENTIFIER)); + }, ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); + let managed_address = &ManagedAddress::from(address); let address_info_mapper = sc.address_info(managed_address); assert!(address_info_mapper.is_empty()); @@ -301,7 +314,7 @@ fn check_claim_and_repair() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); + let managed_address = &ManagedAddress::from(address); let address_info_mapper = sc.address_info(managed_address); assert!(address_info_mapper.is_empty()); @@ -313,17 +326,14 @@ fn check_claim_and_repair() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); assert_eq!(address_info.current_streak, 1); assert_eq!(address_info.total_epochs_claimed, 1); assert_eq!(address_info.last_epoch_claimed, 20); }) - .set_state_step( - SetStateStep::new() - .block_epoch(21) - ) + .set_state_step(SetStateStep::new().block_epoch(21)) .whitebox_call_check( &on_chain_claim_whitebox, ScCallStep::new() @@ -340,27 +350,14 @@ fn check_claim_and_repair() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); assert_eq!(address_info.current_streak, 1); assert_eq!(address_info.total_epochs_claimed, 1); assert_eq!(address_info.last_epoch_claimed, 20); }) - .set_state_step( - SetStateStep::new() - .block_epoch(22) - ) - .whitebox_call( - &on_chain_claim_whitebox, - ScCallStep::new() - .from(USER1_ADDR) - .to(SC_ADDR) - .esdt_transfer(TOKEN_IDENTIFIER_EXPR, 1, "1"), - |sc| { - sc.claim_and_repair(); - }, - ) + .set_state_step(SetStateStep::new().block_epoch(22)) .whitebox_call_check( &on_chain_claim_whitebox, ScCallStep::new() @@ -389,18 +386,46 @@ fn check_claim_and_repair() { r.assert_user_error("Bad payment amount"); }, ) + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new() + .from(USER1_ADDR) + .to(SC_ADDR) + .esdt_transfer(TOKEN_IDENTIFIER_EXPR, 1, "1"), + |sc| { + sc.claim_and_repair(); + }, + ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); assert_eq!(address_info.current_streak, 3); assert_eq!(address_info.total_epochs_claimed, 3); assert_eq!(address_info.last_epoch_claimed, 22); + assert_eq!(address_info.best_streak, 3); }) - .set_state_step( - SetStateStep::new() - .block_epoch(25) + .set_state_step(SetStateStep::new().block_epoch(28)) + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new() + .from(USER1_ADDR) + .to(SC_ADDR) + .esdt_transfer(TOKEN_IDENTIFIER_EXPR, 1, "1"), + |sc| { + sc.claim_and_repair(); + }, ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address); + let address_info = sc.address_info(managed_address).get(); + assert_eq!(address_info.current_streak, 9); + assert_eq!(address_info.total_epochs_claimed, 9); + assert_eq!(address_info.last_epoch_claimed, 28); + assert_eq!(address_info.best_streak, 9); + }) + .set_state_step(SetStateStep::new().block_epoch(35)) .whitebox_call_check( &on_chain_claim_whitebox, ScCallStep::new() @@ -418,14 +443,12 @@ fn check_claim_and_repair() { } #[test] -fn on_chain_claim_whitebox() { +fn best_streak() { let mut world = world(); let on_chain_claim_whitebox = WhiteboxContract::new(SC_ADDR, on_chain_claim::contract_obj); let on_chain_claim_code = world.code_expression(ON_CHAIN_CLAIM_PATH_EXPR); - let roles: Vec = vec![ - "ESDTRoleNFTBurn".to_string(), - ]; + let roles: Vec = vec!["ESDTRoleNFTBurn".to_string()]; world .set_state_step( @@ -433,9 +456,133 @@ fn on_chain_claim_whitebox() { .put_account(OWNER_ADDR, Account::new().nonce(1)) .put_account( USER1_ADDR, + Account::new().nonce(1).esdt_nft_balance( + TOKEN_IDENTIFIER_EXPR, + TOKEN_NONCE, + "1", + Option::Some(()), + ), + ) + .put_account( + SC_ADDR, Account::new() .nonce(1) - .esdt_nft_balance(TOKEN_IDENTIFIER_EXPR, TOKEN_NONCE, "1", Option::Some(())) + .code(&on_chain_claim_code) + .owner(OWNER_ADDR) + .esdt_roles(TOKEN_IDENTIFIER_EXPR, roles), + ) + .block_epoch(20) + .new_address(OWNER_ADDR, TOKEN_NONCE, SC_ADDR), + ) + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new().from(SC_ADDR), + |sc| { + sc.repair_streak_token_identifier() + .set(TokenIdentifier::from(TOKEN_IDENTIFIER)); + }, + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let repair_streak_token_identifier = sc.repair_streak_token_identifier().get(); + let identifier = TokenIdentifier::from(TOKEN_IDENTIFIER); + assert_eq!(repair_streak_token_identifier, identifier); + }) + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new().from(USER1_ADDR), + |sc| sc.claim(), + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address); + let address_info = sc.address_info(managed_address).get(); + assert_eq!(address_info.current_streak, 1); + assert_eq!(address_info.total_epochs_claimed, 1); + assert_eq!(address_info.last_epoch_claimed, 20); + assert_eq!(address_info.best_streak, 1); + }) + .set_state_step(SetStateStep::new().block_epoch(21)) + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new().from(USER1_ADDR), + |sc| sc.claim(), + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address); + let address_info = sc.address_info(managed_address).get(); + assert_eq!(address_info.current_streak, 2); + assert_eq!(address_info.total_epochs_claimed, 2); + assert_eq!(address_info.last_epoch_claimed, 21); + assert_eq!(address_info.best_streak, 2); + }) + .set_state_step(SetStateStep::new().block_epoch(25)) + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new().from(USER1_ADDR), + |sc| sc.claim(), + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address); + let address_info = sc.address_info(managed_address).get(); + assert_eq!(address_info.current_streak, 1); + assert_eq!(address_info.total_epochs_claimed, 3); + assert_eq!(address_info.last_epoch_claimed, 25); + assert_eq!(address_info.best_streak, 2); + }) + .set_state_step(SetStateStep::new().block_epoch(26)) + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new().from(USER1_ADDR), + |sc| sc.claim(), + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address); + let address_info = sc.address_info(managed_address).get(); + assert_eq!(address_info.current_streak, 2); + assert_eq!(address_info.total_epochs_claimed, 4); + assert_eq!(address_info.last_epoch_claimed, 26); + assert_eq!(address_info.best_streak, 2); + }) + .set_state_step(SetStateStep::new().block_epoch(27)) + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new().from(USER1_ADDR), + |sc| sc.claim(), + ) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address); + let address_info = sc.address_info(managed_address).get(); + assert_eq!(address_info.current_streak, 3); + assert_eq!(address_info.total_epochs_claimed, 5); + assert_eq!(address_info.last_epoch_claimed, 27); + assert_eq!(address_info.best_streak, 3); + }); +} + +#[test] +fn on_chain_claim_whitebox() { + let mut world = world(); + let on_chain_claim_whitebox = WhiteboxContract::new(SC_ADDR, on_chain_claim::contract_obj); + let on_chain_claim_code = world.code_expression(ON_CHAIN_CLAIM_PATH_EXPR); + + let roles: Vec = vec!["ESDTRoleNFTBurn".to_string()]; + + world + .set_state_step( + SetStateStep::new() + .put_account(OWNER_ADDR, Account::new().nonce(1)) + .put_account( + USER1_ADDR, + Account::new().nonce(1).esdt_nft_balance( + TOKEN_IDENTIFIER_EXPR, + TOKEN_NONCE, + "1", + Option::Some(()), + ), ) .put_account( SC_ADDR, @@ -446,13 +593,15 @@ fn on_chain_claim_whitebox() { .esdt_roles(TOKEN_IDENTIFIER_EXPR, roles), ) .block_epoch(20) - .new_address(OWNER_ADDR, TOKEN_NONCE, SC_ADDR) + .new_address(OWNER_ADDR, TOKEN_NONCE, SC_ADDR), ) - .whitebox_call(&on_chain_claim_whitebox, - ScCallStep::new().from(SC_ADDR), + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new().from(SC_ADDR), |sc| { - sc.repair_streak_token_identifier().set(TokenIdentifier::from(TOKEN_IDENTIFIER)); - } + sc.repair_streak_token_identifier() + .set(TokenIdentifier::from(TOKEN_IDENTIFIER)); + }, ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let repair_streak_token_identifier = sc.repair_streak_token_identifier().get(); @@ -466,7 +615,7 @@ fn on_chain_claim_whitebox() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); assert_eq!(address_info.current_streak, 1); assert_eq!(address_info.total_epochs_claimed, 1); @@ -474,37 +623,35 @@ fn on_chain_claim_whitebox() { }) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); + let managed_address = &ManagedAddress::from(address); let can_be_repaired = sc.can_be_repaired(managed_address); assert!(!can_be_repaired); }) - .set_state_step( - SetStateStep::new() - .block_epoch(21) - ) + .set_state_step(SetStateStep::new().block_epoch(21)) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); + let managed_address = &ManagedAddress::from(address); let can_be_repaired = sc.can_be_repaired(managed_address); assert!(!can_be_repaired); }) - .set_state_step( - SetStateStep::new() - .block_epoch(22) - ) + .set_state_step(SetStateStep::new().block_epoch(22)) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); + let managed_address = &ManagedAddress::from(address); let can_be_repaired = sc.can_be_repaired(managed_address); assert!(can_be_repaired); }) - .set_state_step( - SetStateStep::new() - .block_epoch(23) - ) + .set_state_step(SetStateStep::new().block_epoch(26)) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); + let managed_address = &ManagedAddress::from(address); + let can_be_repaired = sc.can_be_repaired(managed_address); + assert!(can_be_repaired); + }) + .set_state_step(SetStateStep::new().block_epoch(27)) + .whitebox_query(&on_chain_claim_whitebox, |sc| { + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address); let can_be_repaired = sc.can_be_repaired(managed_address); assert!(!can_be_repaired); }) @@ -529,34 +676,36 @@ fn on_chain_claim_whitebox() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); assert_eq!(address_info.current_streak, 1); assert_eq!(address_info.total_epochs_claimed, 2); - assert_eq!(address_info.last_epoch_claimed, 23); + assert_eq!(address_info.last_epoch_claimed, 27); + assert_eq!(address_info.best_streak, 1); }) .whitebox_call( &on_chain_claim_whitebox, ScCallStep::new().from(OWNER_ADDR), |sc| { - let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); - sc.update_state(managed_address, 5u64, 21u64, 7u64); - } + let address = AddressValue::from(USER1_ADDR).to_address(); + let managed_address = &ManagedAddress::from(address); + sc.update_state(managed_address, 5u64, 21u64, 7u64, 5u64); + }, ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); + let managed_address = &ManagedAddress::from(address); let can_be_repaired = sc.can_be_repaired(managed_address); assert!(can_be_repaired); }) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); assert_eq!(address_info.current_streak, 5); assert_eq!(address_info.total_epochs_claimed, 7); assert_eq!(address_info.last_epoch_claimed, 21); + assert_eq!(address_info.best_streak, 5); }) .whitebox_call( &on_chain_claim_whitebox, @@ -570,10 +719,11 @@ fn on_chain_claim_whitebox() { ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let address = AddressValue::from(USER1_ADDR).to_address(); - let managed_address = &ManagedAddress::from(address); + let managed_address = &ManagedAddress::from(address); let address_info = sc.address_info(managed_address).get(); - assert_eq!(address_info.current_streak, 7); - assert_eq!(address_info.total_epochs_claimed, 9); - assert_eq!(address_info.last_epoch_claimed, 23); + assert_eq!(address_info.current_streak, 11); + assert_eq!(address_info.total_epochs_claimed, 13); + assert_eq!(address_info.last_epoch_claimed, 27); + assert_eq!(address_info.best_streak, 11); }); } diff --git a/contracts/on-chain-claim/wasm/Cargo.lock b/contracts/on-chain-claim/wasm/Cargo.lock index 5b8d5f0b..b8fb9937 100644 --- a/contracts/on-chain-claim/wasm/Cargo.lock +++ b/contracts/on-chain-claim/wasm/Cargo.lock @@ -34,9 +34,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "cfg-if" @@ -74,9 +74,9 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "multiversx-sc" -version = "0.45.1" +version = "0.45.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f11b51d6a2ab0218585ed58e100c5ac2218de09490fbfc4243b5ecd0ca7f5cbc" +checksum = "9b2bdb196b3ff2b9f8c744ec2e026c22c8e02bc91e5c6ed09951415c47fef6b8" dependencies = [ "bitflags", "hashbrown", @@ -88,9 +88,9 @@ dependencies = [ [[package]] name = "multiversx-sc-codec" -version = "0.18.2" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327b0ad1c3477cab0d7c84391439ba302238f738ef3c6e1fcd18e247fba84875" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" dependencies = [ "arrayvec", "multiversx-sc-codec-derive", @@ -98,34 +98,34 @@ dependencies = [ [[package]] name = "multiversx-sc-codec-derive" -version = "0.18.2" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f444038e0043b8eda816b26952479c2aca3c4a643580f4337f71fb362a586db5" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" dependencies = [ "hex", "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] name = "multiversx-sc-derive" -version = "0.45.1" +version = "0.45.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "784f0fc505806102fe6f808b368e12fcb13096dd73c5678f09c5663230724d6f" +checksum = "2e60b5dce707f61376f74d713218f75326121d9f6a5f09a3a63de7aea2a92be9" dependencies = [ "hex", "proc-macro2", "quote", "radix_trie", - "syn 1.0.109", + "syn", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.45.1" +version = "0.45.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5afb8b8cc380eabd82dc8f9b02afbab3dce16fc2b5de1dbc601fcfcf261278ba" +checksum = "c4299660d5413d9f120bfddda8105b1f9d28f0345a72f53e5dc90732c4983e45" dependencies = [ "multiversx-sc", ] @@ -203,17 +203,6 @@ version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - [[package]] name = "syn" version = "2.0.39" @@ -254,5 +243,5 @@ checksum = "dd7e48ccf166952882ca8bd778a43502c64f33bf94c12ebe2a7f08e5a0f6689f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn", ] diff --git a/contracts/on-chain-claim/wasm/Cargo.toml b/contracts/on-chain-claim/wasm/Cargo.toml index 59e71574..d538ea84 100644 --- a/contracts/on-chain-claim/wasm/Cargo.toml +++ b/contracts/on-chain-claim/wasm/Cargo.toml @@ -19,12 +19,13 @@ opt-level = "z" lto = true debug = false panic = "abort" +overflow-checks = false [dependencies.on-chain-claim] path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "0.45.1" +version = "0.45.2" [workspace] members = ["."] From 73fc249e68af10cc3299873a0f116eb36e91b505 Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Wed, 10 Jan 2024 12:53:05 +0200 Subject: [PATCH 14/24] Added only admin module --- contracts/on-chain-claim/Cargo.toml | 3 ++ .../interaction/devnet.snippets.sh | 25 +++++++++++++++ contracts/on-chain-claim/src/contract.rs | 13 ++++++-- contracts/on-chain-claim/tests/tests.rs | 31 +++++++++++++++++++ contracts/on-chain-claim/wasm/Cargo.lock | 10 ++++++ contracts/on-chain-claim/wasm/src/lib.rs | 8 +++-- 6 files changed, 85 insertions(+), 5 deletions(-) diff --git a/contracts/on-chain-claim/Cargo.toml b/contracts/on-chain-claim/Cargo.toml index 6cc99a8d..f066fae3 100644 --- a/contracts/on-chain-claim/Cargo.toml +++ b/contracts/on-chain-claim/Cargo.toml @@ -11,5 +11,8 @@ path = "src/contract.rs" [dependencies.multiversx-sc] version = "0.45.2" +[dependencies.multiversx-sc-modules] +version = "0.45.2" + [dev-dependencies.multiversx-sc-scenario] version = "0.45.2" diff --git a/contracts/on-chain-claim/interaction/devnet.snippets.sh b/contracts/on-chain-claim/interaction/devnet.snippets.sh index 28baf31a..72ae2fba 100644 --- a/contracts/on-chain-claim/interaction/devnet.snippets.sh +++ b/contracts/on-chain-claim/interaction/devnet.snippets.sh @@ -5,6 +5,9 @@ CHAINID=D DEPLOY_GAS="25000000" SFT_IDENTIFIER=0x585354525245504149522d653162363733 #XSTRREPAIR-e1b673 + +CONTRACT_ADDRESS="erd1qqqqqqqqqqqqqpgqkm3wla3wk0yqk7lk725wee8yh0e2zeru76ls3gr0nj" + deploy() { mxpy --verbose contract deploy \ --bytecode="output/on-chain-claim.wasm" \ @@ -26,3 +29,25 @@ deploy() { echo "" echo "Smart contract address: ${ADDRESS}" } + +upgrade() { + mxpy --verbose contract upgrade ${CONTRACT_ADDRESS} \ + --bytecode="output/on-chain-claim.wasm" \ + --arguments ${SFT_IDENTIFIER} \ + --pem=${WALLET} \ + --gas-limit=${DEPLOY_GAS} \ + --proxy=${PROXY} \ + --chain=${CHAINID} \ + --recall-nonce \ + --send \ + --outfile="upgrade-devnet.interaction.json" || return + + TRANSACTION=$(mxpy data parse --file="upgrade-devnet.interaction.json" --expression="data['emittedTransactionHash']") + ADDRESS=$(mxpy data parse --file="upgrade-devnet.interaction.json" --expression="data['contractAddress']") + + mxpy data store --key=address-devnet --value=${ADDRESS} + mxpy data store --key=deployTransaction-devnet --value=${TRANSACTION} + + echo "" + echo "Smart contract address: ${ADDRESS}" +} diff --git a/contracts/on-chain-claim/src/contract.rs b/contracts/on-chain-claim/src/contract.rs index cabb0575..4f2a5c2f 100644 --- a/contracts/on-chain-claim/src/contract.rs +++ b/contracts/on-chain-claim/src/contract.rs @@ -2,7 +2,6 @@ #![allow(unused_attributes)] pub use address_info::AddressInfo; - multiversx_sc::imports!(); multiversx_sc::derive_imports!(); @@ -10,13 +9,20 @@ pub mod address_info; pub mod config; use crate::config::{MAX_REPAIR_GAP, SFT_AMOUNT}; +use multiversx_sc_modules::only_admin; #[multiversx_sc::contract] -pub trait OnChainClaimContract: config::ConfigModule { +pub trait OnChainClaimContract: config::ConfigModule + only_admin::OnlyAdminModule { #[init] fn init(&self, repair_streak_token_id: TokenIdentifier) { + require!( + repair_streak_token_id.is_valid_esdt_identifier(), + "Invalid token ID" + ); self.repair_streak_token_identifier() .set(repair_streak_token_id); + let caller = self.blockchain().get_caller(); + self.add_admin(caller); } #[endpoint(claim)] @@ -106,7 +112,6 @@ pub trait OnChainClaimContract: config::ConfigModule { ); } - #[only_owner] #[endpoint(updateState)] fn update_state( &self, @@ -116,6 +121,8 @@ pub trait OnChainClaimContract: config::ConfigModule { total_epochs_claimed: u64, best_streak: u64, ) { + self.require_caller_is_admin(); + let address_info = AddressInfo::new( current_streak, last_epoch_claimed, diff --git a/contracts/on-chain-claim/tests/tests.rs b/contracts/on-chain-claim/tests/tests.rs index 1670328e..6a6a8efe 100644 --- a/contracts/on-chain-claim/tests/tests.rs +++ b/contracts/on-chain-claim/tests/tests.rs @@ -1,5 +1,6 @@ use config::ConfigModule; use multiversx_sc::types::{ManagedAddress, TokenIdentifier}; +use multiversx_sc_modules::only_admin::OnlyAdminModule; use multiversx_sc_scenario::{scenario_model::*, *}; use on_chain_claim::*; @@ -145,6 +146,16 @@ fn check_update_state() { assert!(address_info_mapper.is_empty()); }) + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new().from(SC_ADDR), + |sc| { + let address = AddressValue::from(OWNER_ADDR).to_address(); + let managed_address = ManagedAddress::from(address); + + sc.add_admin(managed_address); + }, + ) .whitebox_call( &on_chain_claim_whitebox, ScCallStep::new().from(OWNER_ADDR), @@ -482,6 +493,16 @@ fn best_streak() { .set(TokenIdentifier::from(TOKEN_IDENTIFIER)); }, ) + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new().from(SC_ADDR), + |sc| { + let address = AddressValue::from(OWNER_ADDR).to_address(); + let managed_address = ManagedAddress::from(address); + + sc.add_admin(managed_address); + }, + ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let repair_streak_token_identifier = sc.repair_streak_token_identifier().get(); let identifier = TokenIdentifier::from(TOKEN_IDENTIFIER); @@ -603,6 +624,16 @@ fn on_chain_claim_whitebox() { .set(TokenIdentifier::from(TOKEN_IDENTIFIER)); }, ) + .whitebox_call( + &on_chain_claim_whitebox, + ScCallStep::new().from(SC_ADDR), + |sc| { + let address = AddressValue::from(OWNER_ADDR).to_address(); + let managed_address = ManagedAddress::from(address); + + sc.add_admin(managed_address); + }, + ) .whitebox_query(&on_chain_claim_whitebox, |sc| { let repair_streak_token_identifier = sc.repair_streak_token_identifier().get(); let identifier = TokenIdentifier::from(TOKEN_IDENTIFIER); diff --git a/contracts/on-chain-claim/wasm/Cargo.lock b/contracts/on-chain-claim/wasm/Cargo.lock index b8fb9937..1d91944e 100644 --- a/contracts/on-chain-claim/wasm/Cargo.lock +++ b/contracts/on-chain-claim/wasm/Cargo.lock @@ -121,6 +121,15 @@ dependencies = [ "syn", ] +[[package]] +name = "multiversx-sc-modules" +version = "0.45.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5833f8bc88104357d38a8952d2a16c3e66080e2e512c0e7001c0c003006c475" +dependencies = [ + "multiversx-sc", +] + [[package]] name = "multiversx-sc-wasm-adapter" version = "0.45.2" @@ -153,6 +162,7 @@ name = "on-chain-claim" version = "0.0.0" dependencies = [ "multiversx-sc", + "multiversx-sc-modules", ] [[package]] diff --git a/contracts/on-chain-claim/wasm/src/lib.rs b/contracts/on-chain-claim/wasm/src/lib.rs index a0dd1d1a..91ca48a9 100644 --- a/contracts/on-chain-claim/wasm/src/lib.rs +++ b/contracts/on-chain-claim/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 6 +// Endpoints: 10 // Async Callback (empty): 1 -// Total number of exported functions: 8 +// Total number of exported functions: 12 #![no_std] @@ -28,6 +28,10 @@ multiversx_sc_wasm_adapter::endpoints! { canBeRepaired => can_be_repaired getAddressInfo => address_info getRepairStreakTokenIdentifier => repair_streak_token_identifier + isAdmin => is_admin + addAdmin => add_admin + removeAdmin => remove_admin + getAdmins => admins ) } From 6140012b212e002230be961194594413ecf397a2 Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Wed, 10 Jan 2024 12:54:08 +0200 Subject: [PATCH 15/24] Fixes --- contracts/on-chain-claim/interaction/devnet.snippets.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/on-chain-claim/interaction/devnet.snippets.sh b/contracts/on-chain-claim/interaction/devnet.snippets.sh index 72ae2fba..b8a32ba7 100644 --- a/contracts/on-chain-claim/interaction/devnet.snippets.sh +++ b/contracts/on-chain-claim/interaction/devnet.snippets.sh @@ -46,7 +46,7 @@ upgrade() { ADDRESS=$(mxpy data parse --file="upgrade-devnet.interaction.json" --expression="data['contractAddress']") mxpy data store --key=address-devnet --value=${ADDRESS} - mxpy data store --key=deployTransaction-devnet --value=${TRANSACTION} + mxpy data store --key=upgradeTransaction-devnet --value=${TRANSACTION} echo "" echo "Smart contract address: ${ADDRESS}" From b5dfbba97946fa1eef58876a84043aed9fb43572 Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Wed, 10 Jan 2024 13:01:27 +0200 Subject: [PATCH 16/24] added upgrade fn --- contracts/on-chain-claim/interaction/devnet.snippets.sh | 1 - contracts/on-chain-claim/src/contract.rs | 3 +++ contracts/on-chain-claim/wasm/src/lib.rs | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/contracts/on-chain-claim/interaction/devnet.snippets.sh b/contracts/on-chain-claim/interaction/devnet.snippets.sh index b8a32ba7..d54534b5 100644 --- a/contracts/on-chain-claim/interaction/devnet.snippets.sh +++ b/contracts/on-chain-claim/interaction/devnet.snippets.sh @@ -33,7 +33,6 @@ deploy() { upgrade() { mxpy --verbose contract upgrade ${CONTRACT_ADDRESS} \ --bytecode="output/on-chain-claim.wasm" \ - --arguments ${SFT_IDENTIFIER} \ --pem=${WALLET} \ --gas-limit=${DEPLOY_GAS} \ --proxy=${PROXY} \ diff --git a/contracts/on-chain-claim/src/contract.rs b/contracts/on-chain-claim/src/contract.rs index 4f2a5c2f..0b9b0794 100644 --- a/contracts/on-chain-claim/src/contract.rs +++ b/contracts/on-chain-claim/src/contract.rs @@ -25,6 +25,9 @@ pub trait OnChainClaimContract: config::ConfigModule + only_admin::OnlyAdminModu self.add_admin(caller); } + #[upgrade] + fn upgrade(&self) {} + #[endpoint(claim)] fn claim(&self) { let caller = self.blockchain().get_caller(); diff --git a/contracts/on-chain-claim/wasm/src/lib.rs b/contracts/on-chain-claim/wasm/src/lib.rs index 91ca48a9..d9e8e6c4 100644 --- a/contracts/on-chain-claim/wasm/src/lib.rs +++ b/contracts/on-chain-claim/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 10 +// Endpoints: 11 // Async Callback (empty): 1 -// Total number of exported functions: 12 +// Total number of exported functions: 13 #![no_std] @@ -22,6 +22,7 @@ multiversx_sc_wasm_adapter::endpoints! { on_chain_claim ( init => init + upgrade => upgrade claim => claim claimAndRepair => claim_and_repair updateState => update_state From 3befdd358c459e33b0f6372043a7e73357697b21 Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Wed, 10 Jan 2024 15:52:00 +0200 Subject: [PATCH 17/24] Fixes --- Cargo.lock | 387 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 268 insertions(+), 119 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9a9a5dc4..87109ce2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,8 +16,8 @@ dependencies = [ name = "adder" version = "0.0.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] @@ -36,7 +36,7 @@ name = "adder-meta" version = "0.0.0" dependencies = [ "adder", - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", ] [[package]] @@ -54,6 +54,18 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "aho-corasick" version = "1.1.2" @@ -63,6 +75,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "allocator-api2" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" + [[package]] name = "anstream" version = "0.6.5" @@ -206,9 +224,9 @@ dependencies = [ name = "bonding-curve-contract" version = "0.0.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-modules", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-modules 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] @@ -216,7 +234,7 @@ name = "bonding-curve-contract-meta" version = "0.0.0" dependencies = [ "bonding-curve-contract", - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", ] [[package]] @@ -266,9 +284,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" name = "check-pause" version = "0.0.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-modules", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-modules 0.46.0", + "multiversx-sc-scenario 0.46.0", "num-bigint", ] @@ -277,7 +295,7 @@ name = "check-pause-meta" version = "0.0.0" dependencies = [ "check-pause", - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", ] [[package]] @@ -430,8 +448,8 @@ name = "crowdfunding-esdt" version = "0.0.0" dependencies = [ "hex", - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", "num-bigint", "num-traits", ] @@ -441,15 +459,15 @@ name = "crowdfunding-esdt-meta" version = "0.0.0" dependencies = [ "crowdfunding-esdt", - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", ] [[package]] name = "crypto-bubbles" version = "0.0.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] @@ -457,7 +475,7 @@ name = "crypto-bubbles-meta" version = "0.0.0" dependencies = [ "crypto-bubbles", - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", ] [[package]] @@ -474,8 +492,8 @@ dependencies = [ name = "crypto-zombies" version = "0.0.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] @@ -483,7 +501,7 @@ name = "crypto-zombies-meta" version = "0.0.0" dependencies = [ "crypto-zombies", - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", ] [[package]] @@ -539,8 +557,8 @@ dependencies = [ name = "digital-cash" version = "0.0.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] @@ -548,7 +566,7 @@ name = "digital-cash-meta" version = "0.0.0" dependencies = [ "digital-cash", - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", ] [[package]] @@ -585,8 +603,8 @@ checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" name = "empty" version = "0.0.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", "num-bigint", ] @@ -595,7 +613,7 @@ name = "empty-meta" version = "0.0.0" dependencies = [ "empty", - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", ] [[package]] @@ -646,8 +664,8 @@ dependencies = [ name = "esdt-transfer-with-fee" version = "0.0.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] @@ -655,15 +673,15 @@ name = "esdt-transfer-with-fee-meta" version = "0.0.0" dependencies = [ "esdt-transfer-with-fee", - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", ] [[package]] name = "factorial" version = "0.0.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] @@ -671,14 +689,14 @@ name = "factorial-meta" version = "0.0.0" dependencies = [ "factorial", - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", ] [[package]] name = "factory-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", "order-book-factory", ] @@ -738,9 +756,9 @@ dependencies = [ name = "fractional-nfts" version = "0.0.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-modules", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-modules 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] @@ -748,7 +766,7 @@ name = "fractional-nfts-meta" version = "0.0.0" dependencies = [ "fractional-nfts", - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", ] [[package]] @@ -904,6 +922,10 @@ name = "hashbrown" version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +dependencies = [ + "ahash", + "allocator-api2", +] [[package]] name = "heck" @@ -1105,7 +1127,7 @@ dependencies = [ name = "kitty" version = "0.0.0" dependencies = [ - "multiversx-sc", + "multiversx-sc 0.46.0", "random", ] @@ -1115,8 +1137,8 @@ version = "0.0.0" dependencies = [ "kitty", "kitty-ownership", - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] @@ -1124,7 +1146,7 @@ name = "kitty-auction-meta" version = "0.0.0" dependencies = [ "kitty-auction", - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", ] [[package]] @@ -1132,8 +1154,8 @@ name = "kitty-genetic-alg" version = "0.0.0" dependencies = [ "kitty", - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", "random", ] @@ -1142,7 +1164,7 @@ name = "kitty-genetic-alg-meta" version = "0.0.0" dependencies = [ "kitty-genetic-alg", - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", ] [[package]] @@ -1151,8 +1173,8 @@ version = "0.0.0" dependencies = [ "kitty", "kitty-genetic-alg", - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", "random", ] @@ -1161,7 +1183,7 @@ name = "kitty-ownership-meta" version = "0.0.0" dependencies = [ "kitty-ownership", - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", ] [[package]] @@ -1186,8 +1208,8 @@ checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" name = "liquid-locking" version = "0.0.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", "num-bigint", ] @@ -1196,7 +1218,7 @@ name = "liquid-locking-meta" version = "0.0.0" dependencies = [ "liquid-locking", - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", ] [[package]] @@ -1219,8 +1241,8 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" name = "lottery-esdt" version = "0.0.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] @@ -1228,7 +1250,7 @@ name = "lottery-esdt-meta" version = "0.0.0" dependencies = [ "lottery-esdt", - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", ] [[package]] @@ -1270,9 +1292,9 @@ dependencies = [ "adder", "factorial", "hex", - "multiversx-sc", - "multiversx-sc-modules", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-modules 0.46.0", + "multiversx-sc-scenario 0.46.0", "multiversx-wegld-swap-sc 0.46.0 (registry+https://github.com/rust-lang/crates.io-index)", "num-bigint", "num-traits", @@ -1284,8 +1306,8 @@ version = "0.0.0" dependencies = [ "clap", "multisig", - "multiversx-sc-modules", - "multiversx-sc-scenario", + "multiversx-sc-modules 0.46.0", + "multiversx-sc-scenario 0.46.0", "multiversx-sc-snippets", "serde", "toml 0.8.8", @@ -1296,7 +1318,7 @@ name = "multisig-meta" version = "0.0.0" dependencies = [ "multisig", - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", ] [[package]] @@ -1345,9 +1367,9 @@ name = "multiversx-price-aggregator-sc" version = "0.46.0" dependencies = [ "arrayvec", - "multiversx-sc", - "multiversx-sc-modules", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-modules 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] @@ -1355,8 +1377,22 @@ name = "multiversx-price-aggregator-sc-meta" version = "0.0.0" dependencies = [ "multiversx-price-aggregator-sc", - "multiversx-sc", - "multiversx-sc-meta", + "multiversx-sc 0.46.0", + "multiversx-sc-meta 0.46.0", +] + +[[package]] +name = "multiversx-sc" +version = "0.45.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b2bdb196b3ff2b9f8c744ec2e026c22c8e02bc91e5c6ed09951415c47fef6b8" +dependencies = [ + "bitflags 2.4.1", + "hashbrown", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive 0.45.2", + "num-traits", ] [[package]] @@ -1368,7 +1404,7 @@ dependencies = [ "bitflags 2.4.1", "hex-literal", "multiversx-sc-codec", - "multiversx-sc-derive", + "multiversx-sc-derive 0.46.0", "num-traits", ] @@ -1395,6 +1431,19 @@ dependencies = [ "syn", ] +[[package]] +name = "multiversx-sc-derive" +version = "0.45.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e60b5dce707f61376f74d713218f75326121d9f6a5f09a3a63de7aea2a92be9" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + [[package]] name = "multiversx-sc-derive" version = "0.46.0" @@ -1408,6 +1457,32 @@ dependencies = [ "syn", ] +[[package]] +name = "multiversx-sc-meta" +version = "0.45.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d48b080d91bb616c9de425454a451464a31873be885d5ac03eaa32534007010c" +dependencies = [ + "clap", + "colored", + "common-path", + "convert_case", + "copy_dir", + "hex", + "lazy_static", + "multiversx-sc 0.45.2", + "pathdiff", + "reqwest", + "ruplacer", + "rustc_version", + "serde", + "serde_json", + "toml 0.8.8", + "wasmparser", + "wasmprinter", + "zip", +] + [[package]] name = "multiversx-sc-meta" version = "0.46.0" @@ -1421,7 +1496,7 @@ dependencies = [ "copy_dir", "hex", "lazy_static", - "multiversx-sc", + "multiversx-sc 0.46.0", "pathdiff", "reqwest", "ruplacer", @@ -1434,13 +1509,50 @@ dependencies = [ "zip", ] +[[package]] +name = "multiversx-sc-modules" +version = "0.45.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5833f8bc88104357d38a8952d2a16c3e66080e2e512c0e7001c0c003006c475" +dependencies = [ + "multiversx-sc 0.45.2", +] + [[package]] name = "multiversx-sc-modules" version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4088eb7642032b69f7b9961b505c2bffce852f795c60dc490e22a6037124f0c0" dependencies = [ - "multiversx-sc", + "multiversx-sc 0.46.0", +] + +[[package]] +name = "multiversx-sc-scenario" +version = "0.45.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2877b9a1da12441be129c349affa5da4aa5c47200db8716d415f973c74603ce" +dependencies = [ + "base64", + "bech32", + "clap", + "colored", + "hex", + "itertools", + "log", + "multiversx-chain-scenario-format", + "multiversx-chain-vm", + "multiversx-chain-vm-executor", + "multiversx-sc 0.45.2", + "multiversx-sc-meta 0.45.2", + "multiversx-sdk", + "num-bigint", + "num-traits", + "pathdiff", + "serde", + "serde_json", + "sha2", + "tokio", ] [[package]] @@ -1459,8 +1571,8 @@ dependencies = [ "multiversx-chain-scenario-format", "multiversx-chain-vm", "multiversx-chain-vm-executor", - "multiversx-sc", - "multiversx-sc-meta", + "multiversx-sc 0.46.0", + "multiversx-sc-meta 0.46.0", "multiversx-sdk", "num-bigint", "num-traits", @@ -1482,7 +1594,7 @@ dependencies = [ "futures", "hex", "log", - "multiversx-sc-scenario", + "multiversx-sc-scenario 0.46.0", "multiversx-sdk", "tokio", ] @@ -1517,9 +1629,9 @@ dependencies = [ name = "multiversx-wegld-swap-sc" version = "0.46.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-modules", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-modules 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] @@ -1528,16 +1640,16 @@ version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "159cdc3a00e55eb82871f9d5b1937c66d575051572d08a3e617896214a5426b8" dependencies = [ - "multiversx-sc", - "multiversx-sc-modules", + "multiversx-sc 0.46.0", + "multiversx-sc-modules 0.46.0", ] [[package]] name = "multiversx-wegld-swap-sc-meta" version = "0.0.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-meta", + "multiversx-sc 0.46.0", + "multiversx-sc-meta 0.46.0", "multiversx-wegld-swap-sc 0.46.0", ] @@ -1545,15 +1657,15 @@ dependencies = [ name = "mvx-game-sc" version = "0.0.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] name = "mvx-game-sc-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", "mvx-game-sc", ] @@ -1561,16 +1673,16 @@ dependencies = [ name = "mystery-box" version = "0.0.1" dependencies = [ - "multiversx-sc", - "multiversx-sc-modules", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-modules 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] name = "mystery-box-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", "mystery-box", ] @@ -1596,15 +1708,15 @@ dependencies = [ name = "nft-escrow" version = "0.0.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] name = "nft-escrow-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", "nft-escrow", ] @@ -1612,15 +1724,15 @@ dependencies = [ name = "nft-minter" version = "0.0.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] name = "nft-minter-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", "nft-minter", ] @@ -1628,15 +1740,15 @@ dependencies = [ name = "nft-storage-prepay" version = "0.0.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] name = "nft-storage-prepay-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", "nft-storage-prepay", ] @@ -1698,6 +1810,23 @@ dependencies = [ "memchr", ] +[[package]] +name = "on-chain-claim" +version = "0.0.0" +dependencies = [ + "multiversx-sc 0.45.2", + "multiversx-sc-modules 0.45.2", + "multiversx-sc-scenario 0.45.2", +] + +[[package]] +name = "on-chain-claim-meta" +version = "0.0.0" +dependencies = [ + "multiversx-sc-meta 0.45.2", + "on-chain-claim", +] + [[package]] name = "once_cell" version = "1.19.0" @@ -1752,23 +1881,23 @@ dependencies = [ name = "order-book-factory" version = "0.0.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] name = "order-book-pair" version = "0.0.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] name = "pair-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", "order-book-pair", ] @@ -1806,8 +1935,8 @@ name = "paymaster" version = "0.0.0" dependencies = [ "adder", - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", "multiversx-wegld-swap-sc 0.46.0", "num-bigint", ] @@ -1816,7 +1945,7 @@ dependencies = [ name = "paymaster-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", "paymaster", ] @@ -1861,15 +1990,15 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" name = "ping-pong-egld" version = "0.0.2" dependencies = [ - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] name = "ping-pong-egld-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", "ping-pong-egld", ] @@ -1915,15 +2044,15 @@ name = "proxy-pause" version = "0.0.0" dependencies = [ "check-pause", - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] name = "proxy-pause-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", "proxy-pause", ] @@ -1989,7 +2118,7 @@ dependencies = [ name = "random" version = "0.0.0" dependencies = [ - "multiversx-sc", + "multiversx-sc 0.46.0", ] [[package]] @@ -2072,16 +2201,16 @@ dependencies = [ name = "rewards-distribution" version = "0.0.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-modules", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-modules 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] name = "rewards-distribution-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", "rewards-distribution", ] @@ -2184,16 +2313,16 @@ dependencies = [ name = "seed-nft-minter" version = "0.0.0" dependencies = [ - "multiversx-sc", - "multiversx-sc-modules", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-modules 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] name = "seed-nft-minter-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", "seed-nft-minter", ] @@ -2426,15 +2555,15 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" name = "token-release" version = "0.0.1" dependencies = [ - "multiversx-sc", - "multiversx-sc-scenario", + "multiversx-sc 0.46.0", + "multiversx-sc-scenario 0.46.0", ] [[package]] name = "token-release-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta", + "multiversx-sc-meta 0.46.0", "token-release", ] @@ -2948,6 +3077,26 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "zeroize" version = "1.7.0" From 1122cae08d252096fa901cf312543226e04b653d Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Wed, 10 Jan 2024 16:08:44 +0200 Subject: [PATCH 18/24] Fixes --- Cargo.lock | 378 ++++++++--------------- contracts/check-pause/wasm/src/lib.rs | 4 +- contracts/on-chain-claim/Cargo.toml | 6 +- contracts/on-chain-claim/meta/Cargo.toml | 2 +- contracts/on-chain-claim/wasm/Cargo.lock | 83 +---- contracts/on-chain-claim/wasm/Cargo.toml | 2 +- 6 files changed, 139 insertions(+), 336 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 87109ce2..baf01e12 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,8 +16,8 @@ dependencies = [ name = "adder" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", ] [[package]] @@ -36,7 +36,7 @@ name = "adder-meta" version = "0.0.0" dependencies = [ "adder", - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", ] [[package]] @@ -54,18 +54,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "ahash" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - [[package]] name = "aho-corasick" version = "1.1.2" @@ -75,12 +63,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "allocator-api2" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" - [[package]] name = "anstream" version = "0.6.5" @@ -224,9 +206,9 @@ dependencies = [ name = "bonding-curve-contract" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-modules 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-modules", + "multiversx-sc-scenario", ] [[package]] @@ -234,7 +216,7 @@ name = "bonding-curve-contract-meta" version = "0.0.0" dependencies = [ "bonding-curve-contract", - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", ] [[package]] @@ -284,9 +266,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" name = "check-pause" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-modules 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-modules", + "multiversx-sc-scenario", "num-bigint", ] @@ -295,7 +277,7 @@ name = "check-pause-meta" version = "0.0.0" dependencies = [ "check-pause", - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", ] [[package]] @@ -448,8 +430,8 @@ name = "crowdfunding-esdt" version = "0.0.0" dependencies = [ "hex", - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", "num-bigint", "num-traits", ] @@ -459,15 +441,15 @@ name = "crowdfunding-esdt-meta" version = "0.0.0" dependencies = [ "crowdfunding-esdt", - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", ] [[package]] name = "crypto-bubbles" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", ] [[package]] @@ -475,7 +457,7 @@ name = "crypto-bubbles-meta" version = "0.0.0" dependencies = [ "crypto-bubbles", - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", ] [[package]] @@ -492,8 +474,8 @@ dependencies = [ name = "crypto-zombies" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", ] [[package]] @@ -501,7 +483,7 @@ name = "crypto-zombies-meta" version = "0.0.0" dependencies = [ "crypto-zombies", - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", ] [[package]] @@ -557,8 +539,8 @@ dependencies = [ name = "digital-cash" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", ] [[package]] @@ -566,7 +548,7 @@ name = "digital-cash-meta" version = "0.0.0" dependencies = [ "digital-cash", - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", ] [[package]] @@ -603,8 +585,8 @@ checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" name = "empty" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", "num-bigint", ] @@ -613,7 +595,7 @@ name = "empty-meta" version = "0.0.0" dependencies = [ "empty", - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", ] [[package]] @@ -664,8 +646,8 @@ dependencies = [ name = "esdt-transfer-with-fee" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", ] [[package]] @@ -673,15 +655,15 @@ name = "esdt-transfer-with-fee-meta" version = "0.0.0" dependencies = [ "esdt-transfer-with-fee", - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", ] [[package]] name = "factorial" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", ] [[package]] @@ -689,14 +671,14 @@ name = "factorial-meta" version = "0.0.0" dependencies = [ "factorial", - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", ] [[package]] name = "factory-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", "order-book-factory", ] @@ -756,9 +738,9 @@ dependencies = [ name = "fractional-nfts" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-modules 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-modules", + "multiversx-sc-scenario", ] [[package]] @@ -766,7 +748,7 @@ name = "fractional-nfts-meta" version = "0.0.0" dependencies = [ "fractional-nfts", - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", ] [[package]] @@ -922,10 +904,6 @@ name = "hashbrown" version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" -dependencies = [ - "ahash", - "allocator-api2", -] [[package]] name = "heck" @@ -1127,7 +1105,7 @@ dependencies = [ name = "kitty" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", + "multiversx-sc", "random", ] @@ -1137,8 +1115,8 @@ version = "0.0.0" dependencies = [ "kitty", "kitty-ownership", - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", ] [[package]] @@ -1146,7 +1124,7 @@ name = "kitty-auction-meta" version = "0.0.0" dependencies = [ "kitty-auction", - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", ] [[package]] @@ -1154,8 +1132,8 @@ name = "kitty-genetic-alg" version = "0.0.0" dependencies = [ "kitty", - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", "random", ] @@ -1164,7 +1142,7 @@ name = "kitty-genetic-alg-meta" version = "0.0.0" dependencies = [ "kitty-genetic-alg", - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", ] [[package]] @@ -1173,8 +1151,8 @@ version = "0.0.0" dependencies = [ "kitty", "kitty-genetic-alg", - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", "random", ] @@ -1183,7 +1161,7 @@ name = "kitty-ownership-meta" version = "0.0.0" dependencies = [ "kitty-ownership", - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", ] [[package]] @@ -1208,8 +1186,8 @@ checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" name = "liquid-locking" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", "num-bigint", ] @@ -1218,7 +1196,7 @@ name = "liquid-locking-meta" version = "0.0.0" dependencies = [ "liquid-locking", - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", ] [[package]] @@ -1241,8 +1219,8 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" name = "lottery-esdt" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", ] [[package]] @@ -1250,7 +1228,7 @@ name = "lottery-esdt-meta" version = "0.0.0" dependencies = [ "lottery-esdt", - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", ] [[package]] @@ -1292,9 +1270,9 @@ dependencies = [ "adder", "factorial", "hex", - "multiversx-sc 0.46.0", - "multiversx-sc-modules 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-modules", + "multiversx-sc-scenario", "multiversx-wegld-swap-sc 0.46.0 (registry+https://github.com/rust-lang/crates.io-index)", "num-bigint", "num-traits", @@ -1306,8 +1284,8 @@ version = "0.0.0" dependencies = [ "clap", "multisig", - "multiversx-sc-modules 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc-modules", + "multiversx-sc-scenario", "multiversx-sc-snippets", "serde", "toml 0.8.8", @@ -1318,7 +1296,7 @@ name = "multisig-meta" version = "0.0.0" dependencies = [ "multisig", - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", ] [[package]] @@ -1367,9 +1345,9 @@ name = "multiversx-price-aggregator-sc" version = "0.46.0" dependencies = [ "arrayvec", - "multiversx-sc 0.46.0", - "multiversx-sc-modules 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-modules", + "multiversx-sc-scenario", ] [[package]] @@ -1377,22 +1355,8 @@ name = "multiversx-price-aggregator-sc-meta" version = "0.0.0" dependencies = [ "multiversx-price-aggregator-sc", - "multiversx-sc 0.46.0", - "multiversx-sc-meta 0.46.0", -] - -[[package]] -name = "multiversx-sc" -version = "0.45.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2bdb196b3ff2b9f8c744ec2e026c22c8e02bc91e5c6ed09951415c47fef6b8" -dependencies = [ - "bitflags 2.4.1", - "hashbrown", - "hex-literal", - "multiversx-sc-codec", - "multiversx-sc-derive 0.45.2", - "num-traits", + "multiversx-sc", + "multiversx-sc-meta", ] [[package]] @@ -1404,7 +1368,7 @@ dependencies = [ "bitflags 2.4.1", "hex-literal", "multiversx-sc-codec", - "multiversx-sc-derive 0.46.0", + "multiversx-sc-derive", "num-traits", ] @@ -1431,19 +1395,6 @@ dependencies = [ "syn", ] -[[package]] -name = "multiversx-sc-derive" -version = "0.45.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e60b5dce707f61376f74d713218f75326121d9f6a5f09a3a63de7aea2a92be9" -dependencies = [ - "hex", - "proc-macro2", - "quote", - "radix_trie", - "syn", -] - [[package]] name = "multiversx-sc-derive" version = "0.46.0" @@ -1457,32 +1408,6 @@ dependencies = [ "syn", ] -[[package]] -name = "multiversx-sc-meta" -version = "0.45.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d48b080d91bb616c9de425454a451464a31873be885d5ac03eaa32534007010c" -dependencies = [ - "clap", - "colored", - "common-path", - "convert_case", - "copy_dir", - "hex", - "lazy_static", - "multiversx-sc 0.45.2", - "pathdiff", - "reqwest", - "ruplacer", - "rustc_version", - "serde", - "serde_json", - "toml 0.8.8", - "wasmparser", - "wasmprinter", - "zip", -] - [[package]] name = "multiversx-sc-meta" version = "0.46.0" @@ -1496,7 +1421,7 @@ dependencies = [ "copy_dir", "hex", "lazy_static", - "multiversx-sc 0.46.0", + "multiversx-sc", "pathdiff", "reqwest", "ruplacer", @@ -1509,50 +1434,13 @@ dependencies = [ "zip", ] -[[package]] -name = "multiversx-sc-modules" -version = "0.45.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5833f8bc88104357d38a8952d2a16c3e66080e2e512c0e7001c0c003006c475" -dependencies = [ - "multiversx-sc 0.45.2", -] - [[package]] name = "multiversx-sc-modules" version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4088eb7642032b69f7b9961b505c2bffce852f795c60dc490e22a6037124f0c0" dependencies = [ - "multiversx-sc 0.46.0", -] - -[[package]] -name = "multiversx-sc-scenario" -version = "0.45.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2877b9a1da12441be129c349affa5da4aa5c47200db8716d415f973c74603ce" -dependencies = [ - "base64", - "bech32", - "clap", - "colored", - "hex", - "itertools", - "log", - "multiversx-chain-scenario-format", - "multiversx-chain-vm", - "multiversx-chain-vm-executor", - "multiversx-sc 0.45.2", - "multiversx-sc-meta 0.45.2", - "multiversx-sdk", - "num-bigint", - "num-traits", - "pathdiff", - "serde", - "serde_json", - "sha2", - "tokio", + "multiversx-sc", ] [[package]] @@ -1571,8 +1459,8 @@ dependencies = [ "multiversx-chain-scenario-format", "multiversx-chain-vm", "multiversx-chain-vm-executor", - "multiversx-sc 0.46.0", - "multiversx-sc-meta 0.46.0", + "multiversx-sc", + "multiversx-sc-meta", "multiversx-sdk", "num-bigint", "num-traits", @@ -1594,7 +1482,7 @@ dependencies = [ "futures", "hex", "log", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc-scenario", "multiversx-sdk", "tokio", ] @@ -1629,9 +1517,9 @@ dependencies = [ name = "multiversx-wegld-swap-sc" version = "0.46.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-modules 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-modules", + "multiversx-sc-scenario", ] [[package]] @@ -1640,16 +1528,16 @@ version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "159cdc3a00e55eb82871f9d5b1937c66d575051572d08a3e617896214a5426b8" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-modules 0.46.0", + "multiversx-sc", + "multiversx-sc-modules", ] [[package]] name = "multiversx-wegld-swap-sc-meta" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-meta 0.46.0", + "multiversx-sc", + "multiversx-sc-meta", "multiversx-wegld-swap-sc 0.46.0", ] @@ -1657,15 +1545,15 @@ dependencies = [ name = "mvx-game-sc" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", ] [[package]] name = "mvx-game-sc-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", "mvx-game-sc", ] @@ -1673,16 +1561,16 @@ dependencies = [ name = "mystery-box" version = "0.0.1" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-modules 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-modules", + "multiversx-sc-scenario", ] [[package]] name = "mystery-box-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", "mystery-box", ] @@ -1708,15 +1596,15 @@ dependencies = [ name = "nft-escrow" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", ] [[package]] name = "nft-escrow-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", "nft-escrow", ] @@ -1724,15 +1612,15 @@ dependencies = [ name = "nft-minter" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", ] [[package]] name = "nft-minter-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", "nft-minter", ] @@ -1740,15 +1628,15 @@ dependencies = [ name = "nft-storage-prepay" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", ] [[package]] name = "nft-storage-prepay-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", "nft-storage-prepay", ] @@ -1814,16 +1702,16 @@ dependencies = [ name = "on-chain-claim" version = "0.0.0" dependencies = [ - "multiversx-sc 0.45.2", - "multiversx-sc-modules 0.45.2", - "multiversx-sc-scenario 0.45.2", + "multiversx-sc", + "multiversx-sc-modules", + "multiversx-sc-scenario", ] [[package]] name = "on-chain-claim-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta 0.45.2", + "multiversx-sc-meta", "on-chain-claim", ] @@ -1881,23 +1769,23 @@ dependencies = [ name = "order-book-factory" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", ] [[package]] name = "order-book-pair" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", ] [[package]] name = "pair-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", "order-book-pair", ] @@ -1935,8 +1823,8 @@ name = "paymaster" version = "0.0.0" dependencies = [ "adder", - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", "multiversx-wegld-swap-sc 0.46.0", "num-bigint", ] @@ -1945,7 +1833,7 @@ dependencies = [ name = "paymaster-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", "paymaster", ] @@ -1990,15 +1878,15 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" name = "ping-pong-egld" version = "0.0.2" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", ] [[package]] name = "ping-pong-egld-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", "ping-pong-egld", ] @@ -2044,15 +1932,15 @@ name = "proxy-pause" version = "0.0.0" dependencies = [ "check-pause", - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", ] [[package]] name = "proxy-pause-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", "proxy-pause", ] @@ -2118,7 +2006,7 @@ dependencies = [ name = "random" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", + "multiversx-sc", ] [[package]] @@ -2201,16 +2089,16 @@ dependencies = [ name = "rewards-distribution" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-modules 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-modules", + "multiversx-sc-scenario", ] [[package]] name = "rewards-distribution-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", "rewards-distribution", ] @@ -2313,16 +2201,16 @@ dependencies = [ name = "seed-nft-minter" version = "0.0.0" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-modules 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-modules", + "multiversx-sc-scenario", ] [[package]] name = "seed-nft-minter-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", "seed-nft-minter", ] @@ -2555,15 +2443,15 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" name = "token-release" version = "0.0.1" dependencies = [ - "multiversx-sc 0.46.0", - "multiversx-sc-scenario 0.46.0", + "multiversx-sc", + "multiversx-sc-scenario", ] [[package]] name = "token-release-meta" version = "0.0.0" dependencies = [ - "multiversx-sc-meta 0.46.0", + "multiversx-sc-meta", "token-release", ] @@ -3077,26 +2965,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "zerocopy" -version = "0.7.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "zeroize" version = "1.7.0" diff --git a/contracts/check-pause/wasm/src/lib.rs b/contracts/check-pause/wasm/src/lib.rs index 550768b6..b3f3bdda 100644 --- a/contracts/check-pause/wasm/src/lib.rs +++ b/contracts/check-pause/wasm/src/lib.rs @@ -10,7 +10,9 @@ // Total number of exported functions: 6 #![no_std] -#![allow(internal_features)] + +// Configuration that works with rustc < 1.73.0. +// TODO: Recommended rustc version: 1.73.0 or newer. #![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); diff --git a/contracts/on-chain-claim/Cargo.toml b/contracts/on-chain-claim/Cargo.toml index f066fae3..675b4ba7 100644 --- a/contracts/on-chain-claim/Cargo.toml +++ b/contracts/on-chain-claim/Cargo.toml @@ -9,10 +9,10 @@ publish = false path = "src/contract.rs" [dependencies.multiversx-sc] -version = "0.45.2" +version = "0.46.0" [dependencies.multiversx-sc-modules] -version = "0.45.2" +version = "0.46.0" [dev-dependencies.multiversx-sc-scenario] -version = "0.45.2" +version = "0.46.0" diff --git a/contracts/on-chain-claim/meta/Cargo.toml b/contracts/on-chain-claim/meta/Cargo.toml index 1da43155..c7114aa0 100644 --- a/contracts/on-chain-claim/meta/Cargo.toml +++ b/contracts/on-chain-claim/meta/Cargo.toml @@ -11,5 +11,5 @@ authors = [ "Vlad Bucur "] path = ".." [dependencies.multiversx-sc-meta] -version = "0.45.2" +version = "0.46.0" default-features = false diff --git a/contracts/on-chain-claim/wasm/Cargo.lock b/contracts/on-chain-claim/wasm/Cargo.lock index 1d91944e..8244ee9c 100644 --- a/contracts/on-chain-claim/wasm/Cargo.lock +++ b/contracts/on-chain-claim/wasm/Cargo.lock @@ -2,24 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ahash" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - -[[package]] -name = "allocator-api2" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" - [[package]] name = "arrayvec" version = "0.7.4" @@ -38,28 +20,12 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - [[package]] name = "endian-type" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" -[[package]] -name = "hashbrown" -version = "0.14.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" -dependencies = [ - "ahash", - "allocator-api2", -] - [[package]] name = "hex" version = "0.4.3" @@ -74,12 +40,11 @@ checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "multiversx-sc" -version = "0.45.2" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2bdb196b3ff2b9f8c744ec2e026c22c8e02bc91e5c6ed09951415c47fef6b8" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" dependencies = [ "bitflags", - "hashbrown", "hex-literal", "multiversx-sc-codec", "multiversx-sc-derive", @@ -110,9 +75,9 @@ dependencies = [ [[package]] name = "multiversx-sc-derive" -version = "0.45.2" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e60b5dce707f61376f74d713218f75326121d9f6a5f09a3a63de7aea2a92be9" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" dependencies = [ "hex", "proc-macro2", @@ -123,18 +88,18 @@ dependencies = [ [[package]] name = "multiversx-sc-modules" -version = "0.45.2" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5833f8bc88104357d38a8952d2a16c3e66080e2e512c0e7001c0c003006c475" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" dependencies = [ "multiversx-sc", ] [[package]] name = "multiversx-sc-wasm-adapter" -version = "0.45.2" +version = "0.46.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4299660d5413d9f120bfddda8105b1f9d28f0345a72f53e5dc90732c4983e45" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" dependencies = [ "multiversx-sc", ] @@ -173,12 +138,6 @@ dependencies = [ "on-chain-claim", ] -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - [[package]] name = "proc-macro2" version = "1.0.69" @@ -229,29 +188,3 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "zerocopy" -version = "0.7.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e97e415490559a91254a2979b4829267a57d2fcd741a98eee8b722fb57289aa0" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd7e48ccf166952882ca8bd778a43502c64f33bf94c12ebe2a7f08e5a0f6689f" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] diff --git a/contracts/on-chain-claim/wasm/Cargo.toml b/contracts/on-chain-claim/wasm/Cargo.toml index d538ea84..de277e3a 100644 --- a/contracts/on-chain-claim/wasm/Cargo.toml +++ b/contracts/on-chain-claim/wasm/Cargo.toml @@ -25,7 +25,7 @@ overflow-checks = false path = ".." [dependencies.multiversx-sc-wasm-adapter] -version = "0.45.2" +version = "0.46.0" [workspace] members = ["."] From 05c5ad5c4066fa055c0e9d6a921454741b243326 Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Wed, 10 Jan 2024 16:17:03 +0200 Subject: [PATCH 19/24] Fixed get address info view --- contracts/on-chain-claim/src/config.rs | 12 +++++++++++- contracts/on-chain-claim/wasm/src/lib.rs | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/contracts/on-chain-claim/src/config.rs b/contracts/on-chain-claim/src/config.rs index 67895abf..3f20a441 100644 --- a/contracts/on-chain-claim/src/config.rs +++ b/contracts/on-chain-claim/src/config.rs @@ -16,6 +16,17 @@ pub trait ConfigModule { current_epoch - last_epoch_claimed - 1 } + #[view(getAddressInfo)] + fn get_address_info(&self, address: &ManagedAddress) -> AddressInfo { + let address_info_mapper = self.address_info(address); + + if address_info_mapper.is_empty() { + return AddressInfo::new(0, 0, 0, 0); + } + + address_info_mapper.get() + } + #[view(canBeRepaired)] fn can_be_repaired(&self, address: &ManagedAddress) -> bool { let address_info_mapper = self.address_info(address); @@ -30,7 +41,6 @@ pub trait ConfigModule { missed_epochs > 0 && missed_epochs <= MAX_REPAIR_GAP } - #[view(getAddressInfo)] #[storage_mapper("address_info")] fn address_info(&self, address: &ManagedAddress) -> SingleValueMapper; diff --git a/contracts/on-chain-claim/wasm/src/lib.rs b/contracts/on-chain-claim/wasm/src/lib.rs index d9e8e6c4..d35f56cd 100644 --- a/contracts/on-chain-claim/wasm/src/lib.rs +++ b/contracts/on-chain-claim/wasm/src/lib.rs @@ -26,8 +26,8 @@ multiversx_sc_wasm_adapter::endpoints! { claim => claim claimAndRepair => claim_and_repair updateState => update_state + getAddressInfo => get_address_info canBeRepaired => can_be_repaired - getAddressInfo => address_info getRepairStreakTokenIdentifier => repair_streak_token_identifier isAdmin => is_admin addAdmin => add_admin From 670a9021f3f28abbbf87d0cd8144fc9f9141c70a Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Thu, 11 Jan 2024 11:26:58 +0200 Subject: [PATCH 20/24] Fixes --- contracts/on-chain-claim/src/config.rs | 8 ++++++++ contracts/on-chain-claim/src/contract.rs | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/contracts/on-chain-claim/src/config.rs b/contracts/on-chain-claim/src/config.rs index 3f20a441..16fc17dc 100644 --- a/contracts/on-chain-claim/src/config.rs +++ b/contracts/on-chain-claim/src/config.rs @@ -8,6 +8,14 @@ pub const MAX_REPAIR_GAP: u64 = 5; #[multiversx_sc::module] pub trait ConfigModule { + fn require_same_shard(&self, address: &ManagedAddress) { + let address_shard = self.blockchain().get_shard_of_address(address); + let sc_address = self.blockchain().get_sc_address(); + let sc_shard = self.blockchain().get_shard_of_address(&sc_address); + + require!(address_shard == sc_shard, "wrong shard"); + } + fn get_missed_epochs(&self, current_epoch: u64, last_epoch_claimed: u64) -> u64 { if current_epoch - last_epoch_claimed <= 1 { return 0; diff --git a/contracts/on-chain-claim/src/contract.rs b/contracts/on-chain-claim/src/contract.rs index 0b9b0794..86479e1f 100644 --- a/contracts/on-chain-claim/src/contract.rs +++ b/contracts/on-chain-claim/src/contract.rs @@ -35,6 +35,7 @@ pub trait OnChainClaimContract: config::ConfigModule + only_admin::OnlyAdminModu !self.blockchain().is_smart_contract(&caller), "Only user accounts can perform claim" ); + self.require_same_shard(&caller); let current_epoch = self.blockchain().get_block_epoch(); @@ -74,6 +75,8 @@ pub trait OnChainClaimContract: config::ConfigModule + only_admin::OnlyAdminModu !self.blockchain().is_smart_contract(&caller), "Only user accounts can perform claim and repair" ); + self.require_same_shard(&caller); + let payment = self.call_value().single_esdt(); let repair_streak_token_identifier = self.repair_streak_token_identifier().get(); require!( @@ -125,6 +128,7 @@ pub trait OnChainClaimContract: config::ConfigModule + only_admin::OnlyAdminModu best_streak: u64, ) { self.require_caller_is_admin(); + self.require_same_shard(address); let address_info = AddressInfo::new( current_streak, From 6cd6133a2543762903e6b058667e9345e7052560 Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Thu, 11 Jan 2024 12:40:37 +0200 Subject: [PATCH 21/24] Fixes --- contracts/on-chain-claim/src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/on-chain-claim/src/config.rs b/contracts/on-chain-claim/src/config.rs index 16fc17dc..59b2f5e4 100644 --- a/contracts/on-chain-claim/src/config.rs +++ b/contracts/on-chain-claim/src/config.rs @@ -15,7 +15,7 @@ pub trait ConfigModule { require!(address_shard == sc_shard, "wrong shard"); } - + fn get_missed_epochs(&self, current_epoch: u64, last_epoch_claimed: u64) -> u64 { if current_epoch - last_epoch_claimed <= 1 { return 0; From d728050b2dc3b16411b683a6b8811edc9b03c1e5 Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Mon, 22 Jan 2024 14:02:55 +0200 Subject: [PATCH 22/24] Code review fixes --- contracts/on-chain-claim/src/address_info.rs | 19 ++++++++++++++++++- contracts/on-chain-claim/src/config.rs | 4 ++-- contracts/on-chain-claim/src/contract.rs | 2 +- contracts/on-chain-claim/wasm/src/lib.rs | 4 +--- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/contracts/on-chain-claim/src/address_info.rs b/contracts/on-chain-claim/src/address_info.rs index 4c4a3813..2ed98a6a 100644 --- a/contracts/on-chain-claim/src/address_info.rs +++ b/contracts/on-chain-claim/src/address_info.rs @@ -10,7 +10,6 @@ pub struct AddressInfo { } impl AddressInfo { - #[inline] pub fn new( current_streak: u64, last_epoch_claimed: u64, @@ -24,4 +23,22 @@ impl AddressInfo { best_streak, } } + + pub fn default() -> Self { + AddressInfo { + current_streak: 0, + last_epoch_claimed: 0, + total_epochs_claimed: 0, + best_streak: 0, + } + } + + pub fn new_with_epoch(current_epoch: u64) -> Self { + AddressInfo { + current_streak: 1, + last_epoch_claimed: current_epoch, + total_epochs_claimed: 1, + best_streak: 1, + } + } } diff --git a/contracts/on-chain-claim/src/config.rs b/contracts/on-chain-claim/src/config.rs index 59b2f5e4..3d5d4c75 100644 --- a/contracts/on-chain-claim/src/config.rs +++ b/contracts/on-chain-claim/src/config.rs @@ -17,7 +17,7 @@ pub trait ConfigModule { } fn get_missed_epochs(&self, current_epoch: u64, last_epoch_claimed: u64) -> u64 { - if current_epoch - last_epoch_claimed <= 1 { + if current_epoch <= last_epoch_claimed { return 0; } @@ -29,7 +29,7 @@ pub trait ConfigModule { let address_info_mapper = self.address_info(address); if address_info_mapper.is_empty() { - return AddressInfo::new(0, 0, 0, 0); + return AddressInfo::default(); } address_info_mapper.get() diff --git a/contracts/on-chain-claim/src/contract.rs b/contracts/on-chain-claim/src/contract.rs index 86479e1f..8a62d79d 100644 --- a/contracts/on-chain-claim/src/contract.rs +++ b/contracts/on-chain-claim/src/contract.rs @@ -41,7 +41,7 @@ pub trait OnChainClaimContract: config::ConfigModule + only_admin::OnlyAdminModu let address_info_mapper = self.address_info(&caller); if address_info_mapper.is_empty() { - let address_info = AddressInfo::new(1, current_epoch, 1, 1); + let address_info = AddressInfo::new_with_epoch(current_epoch); self.address_info(&caller).set(address_info); return; } diff --git a/contracts/on-chain-claim/wasm/src/lib.rs b/contracts/on-chain-claim/wasm/src/lib.rs index d35f56cd..1d6c31c3 100644 --- a/contracts/on-chain-claim/wasm/src/lib.rs +++ b/contracts/on-chain-claim/wasm/src/lib.rs @@ -10,9 +10,7 @@ // Total number of exported functions: 13 #![no_std] - -// Configuration that works with rustc < 1.73.0. -// TODO: Recommended rustc version: 1.73.0 or newer. +#![allow(internal_features)] #![feature(lang_items)] multiversx_sc_wasm_adapter::allocator!(); From aaf636072b8daae9a16841eed0ec8cacdb61cb2f Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Mon, 22 Jan 2024 14:05:25 +0200 Subject: [PATCH 23/24] code review fixes --- contracts/on-chain-claim/src/address_info.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/contracts/on-chain-claim/src/address_info.rs b/contracts/on-chain-claim/src/address_info.rs index 2ed98a6a..9de9c8b5 100644 --- a/contracts/on-chain-claim/src/address_info.rs +++ b/contracts/on-chain-claim/src/address_info.rs @@ -1,7 +1,7 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); -#[derive(NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] +#[derive(Default, NestedEncode, NestedDecode, TopEncode, TopDecode, TypeAbi)] pub struct AddressInfo { pub current_streak: u64, pub last_epoch_claimed: u64, @@ -24,15 +24,6 @@ impl AddressInfo { } } - pub fn default() -> Self { - AddressInfo { - current_streak: 0, - last_epoch_claimed: 0, - total_epochs_claimed: 0, - best_streak: 0, - } - } - pub fn new_with_epoch(current_epoch: u64) -> Self { AddressInfo { current_streak: 1, From e2f3a46a014ecea61b26c78bcb41705cdd485462 Mon Sep 17 00:00:00 2001 From: Vlad Bucur Date: Wed, 7 Feb 2024 11:20:42 +0200 Subject: [PATCH 24/24] Added set repair streak token identifier endpoint --- .../interaction/mainnet.snippets.sh | 52 +++++++++++++++++++ .../interaction/testnet.snippets.sh | 4 +- contracts/on-chain-claim/src/contract.rs | 24 ++++++--- contracts/on-chain-claim/wasm/src/lib.rs | 5 +- 4 files changed, 75 insertions(+), 10 deletions(-) create mode 100644 contracts/on-chain-claim/interaction/mainnet.snippets.sh diff --git a/contracts/on-chain-claim/interaction/mainnet.snippets.sh b/contracts/on-chain-claim/interaction/mainnet.snippets.sh new file mode 100644 index 00000000..5a6b86a3 --- /dev/null +++ b/contracts/on-chain-claim/interaction/mainnet.snippets.sh @@ -0,0 +1,52 @@ +WALLET="${PWD}/wallet.pem" +PROJECT="${PWD}" +PROXY=https://gateway.multiversx.com +CHAINID=D + +DEPLOY_GAS="30000000" +SFT_IDENTIFIER=0x585354525245504149522d653162363733 #XSTRREPAIR-e1b673 + +CONTRACT_ADDRESS="erd1qqqqqqqqqqqqqpgqkm3wla3wk0yqk7lk725wee8yh0e2zeru76ls3gr0nj" + +deploy() { + mxpy --verbose contract deploy \ + --bytecode="output/on-chain-claim.wasm" \ + --arguments ${SFT_IDENTIFIER} \ + --pem=${WALLET} \ + --gas-limit=${DEPLOY_GAS} \ + --proxy=${PROXY} \ + --chain=${CHAINID} \ + --recall-nonce \ + --send \ + --outfile="deploy-mainnet.interaction.json" || return + + TRANSACTION=$(mxpy data parse --file="deploy-mainnet.interaction.json" --expression="data['emittedTransactionHash']") + ADDRESS=$(mxpy data parse --file="deploy-mainnet.interaction.json" --expression="data['contractAddress']") + + mxpy data store --key=address-mainnet --value=${ADDRESS} + mxpy data store --key=deployTransaction-mainnet --value=${TRANSACTION} + + echo "" + echo "Smart contract address: ${ADDRESS}" +} + +upgrade() { + mxpy --verbose contract upgrade ${CONTRACT_ADDRESS} \ + --bytecode="output/on-chain-claim.wasm" \ + --pem=${WALLET} \ + --gas-limit=${DEPLOY_GAS} \ + --proxy=${PROXY} \ + --chain=${CHAINID} \ + --recall-nonce \ + --send \ + --outfile="upgrade-mainnet.interaction.json" || return + + TRANSACTION=$(mxpy data parse --file="upgrade-mainnet.interaction.json" --expression="data['emittedTransactionHash']") + ADDRESS=$(mxpy data parse --file="upgrade-mainnet.interaction.json" --expression="data['contractAddress']") + + mxpy data store --key=address-mainnet --value=${ADDRESS} + mxpy data store --key=upgradeTransaction-mainnet --value=${TRANSACTION} + + echo "" + echo "Smart contract address: ${ADDRESS}" +} diff --git a/contracts/on-chain-claim/interaction/testnet.snippets.sh b/contracts/on-chain-claim/interaction/testnet.snippets.sh index 4da099cb..8342d994 100644 --- a/contracts/on-chain-claim/interaction/testnet.snippets.sh +++ b/contracts/on-chain-claim/interaction/testnet.snippets.sh @@ -3,8 +3,8 @@ PROJECT="${PWD}" PROXY=https://testnet-gateway.multiversx.com CHAINID=D -DEPLOY_GAS="25000000" -SFT_IDENTIFIER=0x585354525245504149522d653162363733 #XSTRREPAIR-e1b673 +DEPLOY_GAS="30000000" +SFT_IDENTIFIER=0x54525245504149522d626435323730 #XSTRREPAIR-e1b673 deploy() { mxpy --verbose contract deploy \ --bytecode="output/on-chain-claim.wasm" \ diff --git a/contracts/on-chain-claim/src/contract.rs b/contracts/on-chain-claim/src/contract.rs index 8a62d79d..bb4caea2 100644 --- a/contracts/on-chain-claim/src/contract.rs +++ b/contracts/on-chain-claim/src/contract.rs @@ -15,12 +15,8 @@ use multiversx_sc_modules::only_admin; pub trait OnChainClaimContract: config::ConfigModule + only_admin::OnlyAdminModule { #[init] fn init(&self, repair_streak_token_id: TokenIdentifier) { - require!( - repair_streak_token_id.is_valid_esdt_identifier(), - "Invalid token ID" - ); - self.repair_streak_token_identifier() - .set(repair_streak_token_id); + self.internal_set_repair_streak_token_id(repair_streak_token_id); + let caller = self.blockchain().get_caller(); self.add_admin(caller); } @@ -138,4 +134,20 @@ pub trait OnChainClaimContract: config::ConfigModule + only_admin::OnlyAdminModu ); self.address_info(address).set(address_info); } + + #[endpoint(setRepairStreakTokenId)] + fn set_repair_streak_token_id(&self, repair_streak_token_id: TokenIdentifier) { + self.require_caller_is_admin(); + + self.internal_set_repair_streak_token_id(repair_streak_token_id); + } + + fn internal_set_repair_streak_token_id(&self, repair_streak_token_id: TokenIdentifier) { + require!( + repair_streak_token_id.is_valid_esdt_identifier(), + "Invalid token ID" + ); + self.repair_streak_token_identifier() + .set(repair_streak_token_id); + } } diff --git a/contracts/on-chain-claim/wasm/src/lib.rs b/contracts/on-chain-claim/wasm/src/lib.rs index 1d6c31c3..44912891 100644 --- a/contracts/on-chain-claim/wasm/src/lib.rs +++ b/contracts/on-chain-claim/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 11 +// Endpoints: 12 // Async Callback (empty): 1 -// Total number of exported functions: 13 +// Total number of exported functions: 14 #![no_std] #![allow(internal_features)] @@ -24,6 +24,7 @@ multiversx_sc_wasm_adapter::endpoints! { claim => claim claimAndRepair => claim_and_repair updateState => update_state + setRepairStreakTokenId => set_repair_streak_token_id getAddressInfo => get_address_info canBeRepaired => can_be_repaired getRepairStreakTokenIdentifier => repair_streak_token_identifier