From beb50cd3b61f2f634dbe5dba656f9178ff4cce4a Mon Sep 17 00:00:00 2001 From: Mihai Calin Luca Date: Wed, 20 Nov 2024 18:33:22 +0100 Subject: [PATCH] chain simulator test setup --- .../composability/forwarder/sc-config.toml | 3 + .../forwarder/src/forwarder_proxy.rs | 12 + .../forwarder/src/fwd_call_transf_exec.rs | 15 + .../forwarder/src/vault_proxy.rs | 8 + .../composability/forwarder/wasm/src/lib.rs | 5 +- .../composability/interact/Cargo.toml | 3 + .../composability/interact/config.toml | 6 +- .../interact/src/call_tree_deploy.rs | 7 +- .../interact/src/comp_interact_controller.rs | 6 + .../interact/src/comp_interact_main.rs | 37 + .../interact/src/forwarder_proxy.rs | 1224 +++++++++++++++++ .../composability/interact/src/vault_proxy.rs | 8 + .../promises-features/src/vault_proxy.rs | 8 + .../recursive-caller/src/vault_proxy.rs | 8 + .../composability/vault/src/vault.rs | 14 + .../vault/wasm-vault-promises/src/lib.rs | 5 +- .../composability/vault/wasm/src/lib.rs | 5 +- 17 files changed, 1365 insertions(+), 9 deletions(-) create mode 100644 contracts/feature-tests/composability/interact/src/forwarder_proxy.rs diff --git a/contracts/feature-tests/composability/forwarder/sc-config.toml b/contracts/feature-tests/composability/forwarder/sc-config.toml index b78f0086a5..cff08b647d 100644 --- a/contracts/feature-tests/composability/forwarder/sc-config.toml +++ b/contracts/feature-tests/composability/forwarder/sc-config.toml @@ -1,2 +1,5 @@ [[proxy]] path = "src/forwarder_proxy.rs" + +[[proxy]] +path = "../interact/src/forwarder_proxy.rs" diff --git a/contracts/feature-tests/composability/forwarder/src/forwarder_proxy.rs b/contracts/feature-tests/composability/forwarder/src/forwarder_proxy.rs index d8ef19f3a4..15ff954024 100644 --- a/contracts/feature-tests/composability/forwarder/src/forwarder_proxy.rs +++ b/contracts/feature-tests/composability/forwarder/src/forwarder_proxy.rs @@ -402,6 +402,18 @@ where .original_result() } + pub fn forward_transf_exec_by_user_accept_funds< + Arg0: ProxyArg>, + >( + self, + to: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("forward_transf_exec_by_user_accept_funds") + .argument(&to) + .original_result() + } + pub fn forward_transf_execu_accept_funds_with_fees< Arg0: ProxyArg>, Arg1: ProxyArg>, diff --git a/contracts/feature-tests/composability/forwarder/src/fwd_call_transf_exec.rs b/contracts/feature-tests/composability/forwarder/src/fwd_call_transf_exec.rs index 952f50275c..a12fe0fe2b 100644 --- a/contracts/feature-tests/composability/forwarder/src/fwd_call_transf_exec.rs +++ b/contracts/feature-tests/composability/forwarder/src/fwd_call_transf_exec.rs @@ -18,6 +18,21 @@ pub trait ForwarderTransferExecuteModule { .transfer_execute(); } + #[endpoint] + #[payable("*")] + fn forward_transf_exec_by_user_accept_funds(&self, to: ManagedAddress) { + let payments = self.call_value().all_esdt_transfers().clone_value(); + let caller = self.blockchain().get_caller(); + let _ = self.send_raw().multi_esdt_transfer_execute_by_user( + &caller, + &to, + &payments, + 50_000_000u64, + &ManagedBuffer::from("accept_funds_echo_caller"), + &ManagedArgBuffer::new(), + ); + } + #[endpoint] #[payable("*")] fn forward_transf_execu_accept_funds_with_fees( diff --git a/contracts/feature-tests/composability/forwarder/src/vault_proxy.rs b/contracts/feature-tests/composability/forwarder/src/vault_proxy.rs index 9636e1e5d1..4572a73507 100644 --- a/contracts/feature-tests/composability/forwarder/src/vault_proxy.rs +++ b/contracts/feature-tests/composability/forwarder/src/vault_proxy.rs @@ -117,6 +117,14 @@ where .original_result() } + pub fn accept_funds_echo_caller( + self, + ) -> TxTypedCall> { + self.wrapped_tx + .raw_call("accept_funds_echo_caller") + .original_result() + } + pub fn accept_funds_single_esdt_transfer( self, ) -> TxTypedCall { diff --git a/contracts/feature-tests/composability/forwarder/wasm/src/lib.rs b/contracts/feature-tests/composability/forwarder/wasm/src/lib.rs index 74d50dd752..e6efd342cb 100644 --- a/contracts/feature-tests/composability/forwarder/wasm/src/lib.rs +++ b/contracts/feature-tests/composability/forwarder/wasm/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 69 +// Endpoints: 70 // Async Callback: 1 -// Total number of exported functions: 71 +// Total number of exported functions: 72 #![no_std] @@ -42,6 +42,7 @@ multiversx_sc_wasm_adapter::endpoints! { callback_data_at_index => callback_data_at_index clear_callback_data => clear_callback_data forward_transf_exec_accept_funds => forward_transf_exec_accept_funds + forward_transf_exec_by_user_accept_funds => forward_transf_exec_by_user_accept_funds forward_transf_execu_accept_funds_with_fees => forward_transf_execu_accept_funds_with_fees forward_transf_exec_accept_funds_twice => forward_transf_exec_accept_funds_twice forward_transf_exec_accept_funds_return_values => forward_transf_exec_accept_funds_return_values diff --git a/contracts/feature-tests/composability/interact/Cargo.toml b/contracts/feature-tests/composability/interact/Cargo.toml index 128251aaea..6c4945b9f7 100644 --- a/contracts/feature-tests/composability/interact/Cargo.toml +++ b/contracts/feature-tests/composability/interact/Cargo.toml @@ -22,3 +22,6 @@ path = "../../../../framework/base" [dependencies.multiversx-sc-snippets] version = "0.54.1" path = "../../../../framework/snippets" + +[features] +chain-simulator-tests = [] diff --git a/contracts/feature-tests/composability/interact/config.toml b/contracts/feature-tests/composability/interact/config.toml index 992112c225..65fd266e83 100644 --- a/contracts/feature-tests/composability/interact/config.toml +++ b/contracts/feature-tests/composability/interact/config.toml @@ -1,5 +1,7 @@ -chain_type = 'real' -gateway_uri = 'https://testnet-gateway.multiversx.com' +# chain_type = 'real' +# gateway_uri = 'https://testnet-gateway.multiversx.com' +chain_type = 'simulator' +gateway_uri = 'http://localhost:8085' call_type = "LegacyAsync" # Sync / LegacyAsync / TransferExecute # token_id = "CMPT-4e9332" token_id = "EGLD" diff --git a/contracts/feature-tests/composability/interact/src/call_tree_deploy.rs b/contracts/feature-tests/composability/interact/src/call_tree_deploy.rs index 89d4000c7f..2461992ba9 100644 --- a/contracts/feature-tests/composability/interact/src/call_tree_deploy.rs +++ b/contracts/feature-tests/composability/interact/src/call_tree_deploy.rs @@ -6,7 +6,10 @@ use crate::{ use multiversx_sc_snippets::imports::*; impl ComposabilityInteract { - pub async fn deploy_call_tree_contracts(&mut self, call_state: &CallState) { + pub async fn deploy_call_tree_contracts( + &mut self, + call_state: &CallState, + ) -> (Vec, Vec) { let vault_deploy_addresses = self.typed_sc_deploy_vault(call_state).await; let forwarder_deploy_addresses = self.typed_sc_deploy_forwarder_queue(call_state).await; @@ -27,6 +30,8 @@ impl ComposabilityInteract { fwd.address = Some(address.to_address()); } + + (vault_deploy_addresses, forwarder_deploy_addresses) } pub async fn typed_sc_deploy_vault(&mut self, call_state: &CallState) -> Vec { diff --git a/contracts/feature-tests/composability/interact/src/comp_interact_controller.rs b/contracts/feature-tests/composability/interact/src/comp_interact_controller.rs index 8e480b76c1..b834f0cdad 100644 --- a/contracts/feature-tests/composability/interact/src/comp_interact_controller.rs +++ b/contracts/feature-tests/composability/interact/src/comp_interact_controller.rs @@ -21,12 +21,18 @@ impl ComposabilityInteract { .use_chain_simulator(config.use_chain_simulator()) .with_tracer(INTERACTOR_SCENARIO_TRACE_PATH) .await; + interactor.set_current_dir_from_workspace("contracts/feature-tests/composability/interact"); + let wallet_address = interactor.register_wallet(test_wallets::judy()).await; + + interactor.generate_blocks_until_epoch(1).await.unwrap(); + let forw_queue_code = BytesValue::interpret_from( "mxsc:../forwarder-queue/output/forwarder-queue.mxsc.json", &InterpreterContext::default(), ); + let vault_code = BytesValue::interpret_from( "mxsc:../vault/output/vault.mxsc.json", &InterpreterContext::default(), diff --git a/contracts/feature-tests/composability/interact/src/comp_interact_main.rs b/contracts/feature-tests/composability/interact/src/comp_interact_main.rs index 1652d66b76..0735b12a05 100644 --- a/contracts/feature-tests/composability/interact/src/comp_interact_main.rs +++ b/contracts/feature-tests/composability/interact/src/comp_interact_main.rs @@ -8,13 +8,17 @@ mod comp_interact_config; mod comp_interact_controller; mod comp_interact_state; +mod forwarder_proxy; mod forwarder_queue_proxy; mod vault_proxy; +use call_tree::CallState; use clap::Parser; use comp_interact_controller::ComposabilityInteract; use multiversx_sc_snippets::imports::*; +const FUNGIBLE_TOKEN_ID: TestTokenIdentifier = TestTokenIdentifier::new("TOKEN-0000"); + #[tokio::main] async fn main() { env_logger::init(); @@ -31,3 +35,36 @@ async fn main() { None => {}, } } + +#[tokio::test] +#[cfg_attr(not(feature = "chain-simulator-tests"), ignore)] +pub async fn transf_exec_by_user_cs_test() { + let mut composability_interact = ComposabilityInteract::init().await; + let wallet_address = composability_interact.wallet_address.clone(); + + // set state for wallet address on chain simulator (esdt balance) + + let call_state = CallState::simple_example_1(); + + let (vault, forwarder) = composability_interact + .deploy_call_tree_contracts(&call_state) + .await; + + let logs = composability_interact + .interactor + .tx() + .from(wallet_address) + .to(forwarder.first().unwrap()) + .typed(forwarder_proxy::ForwarderProxy) + .forward_transf_exec_by_user_accept_funds(vault.first().unwrap()) + .single_esdt( + &FUNGIBLE_TOKEN_ID.to_token_identifier(), + 0, + &BigUint::from(100u64), + ) + .returns(ReturnsLogs) + .run() + .await; + + println!("Logs: {logs:?}"); +} diff --git a/contracts/feature-tests/composability/interact/src/forwarder_proxy.rs b/contracts/feature-tests/composability/interact/src/forwarder_proxy.rs new file mode 100644 index 0000000000..15ff954024 --- /dev/null +++ b/contracts/feature-tests/composability/interact/src/forwarder_proxy.rs @@ -0,0 +1,1224 @@ +// Code generated by the multiversx-sc proxy generator. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +#![allow(dead_code)] +#![allow(clippy::all)] + +use multiversx_sc::proxy_imports::*; + +pub struct ForwarderProxy; + +impl TxProxyTrait for ForwarderProxy +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + type TxProxyMethods = ForwarderProxyMethods; + + fn proxy_methods(self, tx: Tx) -> Self::TxProxyMethods { + ForwarderProxyMethods { wrapped_tx: tx } + } +} + +pub struct ForwarderProxyMethods +where + Env: TxEnv, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + wrapped_tx: Tx, +} + +#[rustfmt::skip] +impl ForwarderProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + Gas: TxGas, +{ + pub fn init( + self, + ) -> TxTypedDeploy { + self.wrapped_tx + .payment(NotPayable) + .raw_deploy() + .original_result() + } +} + +#[rustfmt::skip] +impl ForwarderProxyMethods +where + Env: TxEnv, + Env::Api: VMApi, + From: TxFrom, + To: TxTo, + Gas: TxGas, +{ + pub fn send_egld< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + >( + self, + to: Arg0, + amount: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("send_egld") + .argument(&to) + .argument(&amount) + .original_result() + } + + pub fn echo_arguments_sync< + Arg0: ProxyArg>, + Arg1: ProxyArg>>, + >( + self, + to: Arg0, + args: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("echo_arguments_sync") + .argument(&to) + .argument(&args) + .original_result() + } + + pub fn echo_arguments_sync_twice< + Arg0: ProxyArg>, + Arg1: ProxyArg>>, + >( + self, + to: Arg0, + args: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("echo_arguments_sync_twice") + .argument(&to) + .argument(&args) + .original_result() + } + + pub fn forward_sync_accept_funds< + Arg0: ProxyArg>, + >( + self, + to: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("forward_sync_accept_funds") + .argument(&to) + .original_result() + } + + pub fn forward_sync_accept_funds_rh_egld< + Arg0: ProxyArg>, + >( + self, + to: Arg0, + ) -> TxTypedCall> { + self.wrapped_tx + .raw_call("forward_sync_accept_funds_rh_egld") + .argument(&to) + .original_result() + } + + pub fn forward_sync_accept_funds_rh_single_esdt< + Arg0: ProxyArg>, + >( + self, + to: Arg0, + ) -> TxTypedCall> { + self.wrapped_tx + .raw_call("forward_sync_accept_funds_rh_single_esdt") + .argument(&to) + .original_result() + } + + pub fn forward_sync_accept_funds_rh_multi_esdt< + Arg0: ProxyArg>, + >( + self, + to: Arg0, + ) -> TxTypedCall>> { + self.wrapped_tx + .raw_call("forward_sync_accept_funds_rh_multi_esdt") + .argument(&to) + .original_result() + } + + pub fn forward_sync_accept_funds_with_fees< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + >( + self, + to: Arg0, + percentage_fees: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("forward_sync_accept_funds_with_fees") + .argument(&to) + .argument(&percentage_fees) + .original_result() + } + + pub fn forward_sync_accept_funds_then_read< + Arg0: ProxyArg>, + >( + self, + to: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("forward_sync_accept_funds_then_read") + .argument(&to) + .original_result() + } + + pub fn forward_sync_retrieve_funds< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg, + Arg3: ProxyArg>, + >( + self, + to: Arg0, + token: Arg1, + token_nonce: Arg2, + amount: Arg3, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("forward_sync_retrieve_funds") + .argument(&to) + .argument(&token) + .argument(&token_nonce) + .argument(&amount) + .original_result() + } + + pub fn forward_sync_retrieve_funds_with_accept_func< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg>, + >( + self, + to: Arg0, + token: Arg1, + amount: Arg2, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("forward_sync_retrieve_funds_with_accept_func") + .argument(&to) + .argument(&token) + .argument(&amount) + .original_result() + } + + pub fn accept_funds_func( + self, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("accept_funds_func") + .original_result() + } + + pub fn forward_sync_accept_funds_multi_transfer< + Arg0: ProxyArg>, + Arg1: ProxyArg, u64, BigUint>>>, + >( + self, + to: Arg0, + token_payments: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("forward_sync_accept_funds_multi_transfer") + .argument(&to) + .argument(&token_payments) + .original_result() + } + + pub fn echo_args_async< + Arg0: ProxyArg>, + Arg1: ProxyArg>>, + >( + self, + to: Arg0, + args: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("echo_args_async") + .argument(&to) + .argument(&args) + .original_result() + } + + pub fn forward_async_accept_funds< + Arg0: ProxyArg>, + >( + self, + to: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("forward_async_accept_funds") + .argument(&to) + .original_result() + } + + pub fn forward_async_accept_funds_half_payment< + Arg0: ProxyArg>, + >( + self, + to: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("forward_async_accept_funds_half_payment") + .argument(&to) + .original_result() + } + + pub fn forward_async_accept_funds_with_fees< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + >( + self, + to: Arg0, + percentage_fees: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("forward_async_accept_funds_with_fees") + .argument(&to) + .argument(&percentage_fees) + .original_result() + } + + pub fn forward_async_retrieve_funds< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg, + Arg3: ProxyArg>, + >( + self, + to: Arg0, + token: Arg1, + token_nonce: Arg2, + amount: Arg3, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("forward_async_retrieve_funds") + .argument(&to) + .argument(&token) + .argument(&token_nonce) + .argument(&amount) + .original_result() + } + + pub fn send_funds_twice< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg>, + >( + self, + to: Arg0, + token_identifier: Arg1, + amount: Arg2, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("send_funds_twice") + .argument(&to) + .argument(&token_identifier) + .argument(&amount) + .original_result() + } + + pub fn send_async_accept_multi_transfer< + Arg0: ProxyArg>, + Arg1: ProxyArg, u64, BigUint>>>, + >( + self, + to: Arg0, + token_payments: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("send_async_accept_multi_transfer") + .argument(&to) + .argument(&token_payments) + .original_result() + } + + pub fn callback_data( + self, + ) -> TxTypedCall>> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("callback_data") + .original_result() + } + + pub fn callback_data_at_index< + Arg0: ProxyArg, + >( + self, + index: Arg0, + ) -> TxTypedCall, EgldOrEsdtTokenIdentifier, u64, BigUint, MultiValueManagedVec>>> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("callback_data_at_index") + .argument(&index) + .original_result() + } + + pub fn clear_callback_data( + self, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("clear_callback_data") + .original_result() + } + + pub fn forward_transf_exec_accept_funds< + Arg0: ProxyArg>, + >( + self, + to: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("forward_transf_exec_accept_funds") + .argument(&to) + .original_result() + } + + pub fn forward_transf_exec_by_user_accept_funds< + Arg0: ProxyArg>, + >( + self, + to: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("forward_transf_exec_by_user_accept_funds") + .argument(&to) + .original_result() + } + + pub fn forward_transf_execu_accept_funds_with_fees< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + >( + self, + to: Arg0, + percentage_fees: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("forward_transf_execu_accept_funds_with_fees") + .argument(&to) + .argument(&percentage_fees) + .original_result() + } + + pub fn forward_transf_exec_accept_funds_twice< + Arg0: ProxyArg>, + >( + self, + to: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("forward_transf_exec_accept_funds_twice") + .argument(&to) + .original_result() + } + + /// Test that the default gas provided to the transfer_execute call + /// leaves enough in the transaction for finish to happen. + pub fn forward_transf_exec_accept_funds_return_values< + Arg0: ProxyArg>, + >( + self, + to: Arg0, + ) -> TxTypedCall, EgldOrEsdtTokenIdentifier>> { + self.wrapped_tx + .raw_call("forward_transf_exec_accept_funds_return_values") + .argument(&to) + .original_result() + } + + pub fn transf_exec_multi_accept_funds< + Arg0: ProxyArg>, + Arg1: ProxyArg, u64, BigUint>>>, + >( + self, + to: Arg0, + token_payments: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("transf_exec_multi_accept_funds") + .argument(&to) + .argument(&token_payments) + .original_result() + } + + pub fn forward_transf_exec_reject_funds_multi_transfer< + Arg0: ProxyArg>, + Arg1: ProxyArg, u64, BigUint>>>, + >( + self, + to: Arg0, + token_payments: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("forward_transf_exec_reject_funds_multi_transfer") + .argument(&to) + .argument(&token_payments) + .original_result() + } + + pub fn transf_exec_multi_reject_funds< + Arg0: ProxyArg>, + Arg1: ProxyArg, u64, BigUint>>>, + >( + self, + to: Arg0, + token_payments: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("transf_exec_multi_reject_funds") + .argument(&to) + .argument(&token_payments) + .original_result() + } + + pub fn change_owner< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + >( + self, + child_sc_address: Arg0, + new_owner: Arg1, + ) -> TxTypedCall> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("changeOwnerAddress") + .argument(&child_sc_address) + .argument(&new_owner) + .original_result() + } + + pub fn deploy_contract< + Arg0: ProxyArg>, + Arg1: ProxyArg>>, + >( + self, + code: Arg0, + opt_arg: Arg1, + ) -> TxTypedCall, OptionalValue>>> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("deploy_contract") + .argument(&code) + .argument(&opt_arg) + .original_result() + } + + pub fn deploy_two_contracts< + Arg0: ProxyArg>, + >( + self, + code: Arg0, + ) -> TxTypedCall, ManagedAddress>> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("deploy_two_contracts") + .argument(&code) + .original_result() + } + + pub fn deploy_vault_from_source< + Arg0: ProxyArg>, + Arg1: ProxyArg>>, + >( + self, + source_address: Arg0, + opt_arg: Arg1, + ) -> TxTypedCall, OptionalValue>>> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("deploy_vault_from_source") + .argument(&source_address) + .argument(&opt_arg) + .original_result() + } + + pub fn upgrade_vault< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg>>, + >( + self, + child_sc_address: Arg0, + new_code: Arg1, + opt_arg: Arg2, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("upgradeVault") + .argument(&child_sc_address) + .argument(&new_code) + .argument(&opt_arg) + .original_result() + } + + pub fn upgrade_vault_from_source< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg>>, + >( + self, + child_sc_address: Arg0, + source_address: Arg1, + opt_arg: Arg2, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("upgrade_vault_from_source") + .argument(&child_sc_address) + .argument(&source_address) + .argument(&opt_arg) + .original_result() + } + + pub fn get_fungible_esdt_balance< + Arg0: ProxyArg>, + >( + self, + token_identifier: Arg0, + ) -> TxTypedCall> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("getFungibleEsdtBalance") + .argument(&token_identifier) + .original_result() + } + + pub fn get_current_nft_nonce< + Arg0: ProxyArg>, + >( + self, + token_identifier: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("getCurrentNftNonce") + .argument(&token_identifier) + .original_result() + } + + pub fn send_esdt< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg>, + >( + self, + to: Arg0, + token_id: Arg1, + amount: Arg2, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("send_esdt") + .argument(&to) + .argument(&token_id) + .argument(&amount) + .original_result() + } + + pub fn send_esdt_with_fees< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + >( + self, + to: Arg0, + percentage_fees: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("send_esdt_with_fees") + .argument(&to) + .argument(&percentage_fees) + .original_result() + } + + pub fn send_esdt_twice< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg>, + Arg3: ProxyArg>, + >( + self, + to: Arg0, + token_id: Arg1, + amount_first_time: Arg2, + amount_second_time: Arg3, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("send_esdt_twice") + .argument(&to) + .argument(&token_id) + .argument(&amount_first_time) + .argument(&amount_second_time) + .original_result() + } + + pub fn send_esdt_direct_multi_transfer< + Arg0: ProxyArg>, + Arg1: ProxyArg, u64, BigUint>>>, + >( + self, + to: Arg0, + token_payments: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("send_esdt_direct_multi_transfer") + .argument(&to) + .argument(&token_payments) + .original_result() + } + + pub fn issue_fungible_token< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg>, + >( + self, + token_display_name: Arg0, + token_ticker: Arg1, + initial_supply: Arg2, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("issue_fungible_token") + .argument(&token_display_name) + .argument(&token_ticker) + .argument(&initial_supply) + .original_result() + } + + pub fn local_mint< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + >( + self, + token_identifier: Arg0, + amount: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("local_mint") + .argument(&token_identifier) + .argument(&amount) + .original_result() + } + + pub fn local_burn< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + >( + self, + token_identifier: Arg0, + amount: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("local_burn") + .argument(&token_identifier) + .argument(&amount) + .original_result() + } + + pub fn get_esdt_local_roles< + Arg0: ProxyArg>, + >( + self, + token_id: Arg0, + ) -> TxTypedCall>> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("get_esdt_local_roles") + .argument(&token_id) + .original_result() + } + + pub fn get_esdt_token_data< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg, + >( + self, + address: Arg0, + token_id: Arg1, + nonce: Arg2, + ) -> TxTypedCall, bool, ManagedBuffer, ManagedBuffer, ManagedBuffer, ManagedAddress, BigUint, ManagedVec>>> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("get_esdt_token_data") + .argument(&address) + .argument(&token_id) + .argument(&nonce) + .original_result() + } + + pub fn is_esdt_frozen< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg, + >( + self, + address: Arg0, + token_id: Arg1, + nonce: Arg2, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("is_esdt_frozen") + .argument(&address) + .argument(&token_id) + .argument(&nonce) + .original_result() + } + + pub fn is_esdt_paused< + Arg0: ProxyArg>, + >( + self, + token_id: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("is_esdt_paused") + .argument(&token_id) + .original_result() + } + + pub fn is_esdt_limited_transfer< + Arg0: ProxyArg>, + >( + self, + token_id: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("is_esdt_limited_transfer") + .argument(&token_id) + .original_result() + } + + pub fn validate_token_identifier< + Arg0: ProxyArg>, + >( + self, + token_id: Arg0, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("validate_token_identifier") + .argument(&token_id) + .original_result() + } + + pub fn sft_issue< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + >( + self, + token_display_name: Arg0, + token_ticker: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("sft_issue") + .argument(&token_display_name) + .argument(&token_ticker) + .original_result() + } + + pub fn get_nft_balance< + Arg0: ProxyArg>, + Arg1: ProxyArg, + >( + self, + token_identifier: Arg0, + nonce: Arg1, + ) -> TxTypedCall> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("get_nft_balance") + .argument(&token_identifier) + .argument(&nonce) + .original_result() + } + + pub fn buy_nft< + Arg0: ProxyArg>, + Arg1: ProxyArg, + Arg2: ProxyArg>, + >( + self, + nft_id: Arg0, + nft_nonce: Arg1, + nft_amount: Arg2, + ) -> TxTypedCall> { + self.wrapped_tx + .raw_call("buy_nft") + .argument(&nft_id) + .argument(&nft_nonce) + .argument(&nft_amount) + .original_result() + } + + pub fn nft_issue< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + >( + self, + token_display_name: Arg0, + token_ticker: Arg1, + ) -> TxTypedCall { + self.wrapped_tx + .raw_call("nft_issue") + .argument(&token_display_name) + .argument(&token_ticker) + .original_result() + } + + pub fn nft_create< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg>, + Arg3: ProxyArg>, + Arg4: ProxyArg>, + Arg5: ProxyArg, + Arg6: ProxyArg>, + >( + self, + token_identifier: Arg0, + amount: Arg1, + name: Arg2, + royalties: Arg3, + hash: Arg4, + color: Arg5, + uri: Arg6, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("nft_create") + .argument(&token_identifier) + .argument(&amount) + .argument(&name) + .argument(&royalties) + .argument(&hash) + .argument(&color) + .argument(&uri) + .original_result() + } + + pub fn nft_create_compact< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg, + >( + self, + token_identifier: Arg0, + amount: Arg1, + color: Arg2, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("nft_create_compact") + .argument(&token_identifier) + .argument(&amount) + .argument(&color) + .original_result() + } + + pub fn nft_add_uris< + Arg0: ProxyArg>, + Arg1: ProxyArg, + Arg2: ProxyArg>>, + >( + self, + token_identifier: Arg0, + nonce: Arg1, + uris: Arg2, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("nft_add_uris") + .argument(&token_identifier) + .argument(&nonce) + .argument(&uris) + .original_result() + } + + pub fn nft_update_attributes< + Arg0: ProxyArg>, + Arg1: ProxyArg, + Arg2: ProxyArg, + >( + self, + token_identifier: Arg0, + nonce: Arg1, + new_attributes: Arg2, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("nft_update_attributes") + .argument(&token_identifier) + .argument(&nonce) + .argument(&new_attributes) + .original_result() + } + + pub fn nft_decode_complex_attributes< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg>, + Arg3: ProxyArg>, + Arg4: ProxyArg>, + Arg5: ProxyArg>, + Arg6: ProxyArg, ManagedBuffer, TokenIdentifier, bool, ManagedBuffer>>, + >( + self, + token_identifier: Arg0, + amount: Arg1, + name: Arg2, + royalties: Arg3, + hash: Arg4, + uri: Arg5, + attrs_arg: Arg6, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("nft_decode_complex_attributes") + .argument(&token_identifier) + .argument(&amount) + .argument(&name) + .argument(&royalties) + .argument(&hash) + .argument(&uri) + .argument(&attrs_arg) + .original_result() + } + + pub fn nft_add_quantity< + Arg0: ProxyArg>, + Arg1: ProxyArg, + Arg2: ProxyArg>, + >( + self, + token_identifier: Arg0, + nonce: Arg1, + amount: Arg2, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("nft_add_quantity") + .argument(&token_identifier) + .argument(&nonce) + .argument(&amount) + .original_result() + } + + pub fn nft_burn< + Arg0: ProxyArg>, + Arg1: ProxyArg, + Arg2: ProxyArg>, + >( + self, + token_identifier: Arg0, + nonce: Arg1, + amount: Arg2, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("nft_burn") + .argument(&token_identifier) + .argument(&nonce) + .argument(&amount) + .original_result() + } + + pub fn transfer_nft_via_async_call< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg, + Arg3: ProxyArg>, + >( + self, + to: Arg0, + token_identifier: Arg1, + nonce: Arg2, + amount: Arg3, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("transfer_nft_via_async_call") + .argument(&to) + .argument(&token_identifier) + .argument(&nonce) + .argument(&amount) + .original_result() + } + + pub fn transfer_nft_and_execute< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg, + Arg3: ProxyArg>, + Arg4: ProxyArg>, + Arg5: ProxyArg>>, + >( + self, + to: Arg0, + token_identifier: Arg1, + nonce: Arg2, + amount: Arg3, + function: Arg4, + arguments: Arg5, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("transfer_nft_and_execute") + .argument(&to) + .argument(&token_identifier) + .argument(&nonce) + .argument(&amount) + .argument(&function) + .argument(&arguments) + .original_result() + } + + pub fn create_and_send< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg>, + Arg3: ProxyArg>, + Arg4: ProxyArg>, + Arg5: ProxyArg>, + Arg6: ProxyArg, + Arg7: ProxyArg>, + >( + self, + to: Arg0, + token_identifier: Arg1, + amount: Arg2, + name: Arg3, + royalties: Arg4, + hash: Arg5, + color: Arg6, + uri: Arg7, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("create_and_send") + .argument(&to) + .argument(&token_identifier) + .argument(&amount) + .argument(&name) + .argument(&royalties) + .argument(&hash) + .argument(&color) + .argument(&uri) + .original_result() + } + + pub fn set_local_roles< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg>, + >( + self, + address: Arg0, + token_identifier: Arg1, + roles: Arg2, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("setLocalRoles") + .argument(&address) + .argument(&token_identifier) + .argument(&roles) + .original_result() + } + + pub fn unset_local_roles< + Arg0: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg>, + >( + self, + address: Arg0, + token_identifier: Arg1, + roles: Arg2, + ) -> TxTypedCall { + self.wrapped_tx + .payment(NotPayable) + .raw_call("unsetLocalRoles") + .argument(&address) + .argument(&token_identifier) + .argument(&roles) + .original_result() + } + + pub fn last_issued_token( + self, + ) -> TxTypedCall> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("lastIssuedToken") + .original_result() + } + + pub fn last_error_message( + self, + ) -> TxTypedCall> { + self.wrapped_tx + .payment(NotPayable) + .raw_call("lastErrorMessage") + .original_result() + } +} + +#[type_abi] +#[derive(TopEncode, TopDecode)] +pub struct CallbackData +where + Api: ManagedTypeApi, +{ + pub callback_name: ManagedBuffer, + pub token_identifier: EgldOrEsdtTokenIdentifier, + pub token_nonce: u64, + pub token_amount: BigUint, + pub args: ManagedVec>, +} + +#[type_abi] +#[derive(TopEncode, TopDecode, Clone, Copy, PartialEq, Debug)] +pub struct Color { + pub r: u8, + pub g: u8, + pub b: u8, +} diff --git a/contracts/feature-tests/composability/interact/src/vault_proxy.rs b/contracts/feature-tests/composability/interact/src/vault_proxy.rs index 9636e1e5d1..4572a73507 100644 --- a/contracts/feature-tests/composability/interact/src/vault_proxy.rs +++ b/contracts/feature-tests/composability/interact/src/vault_proxy.rs @@ -117,6 +117,14 @@ where .original_result() } + pub fn accept_funds_echo_caller( + self, + ) -> TxTypedCall> { + self.wrapped_tx + .raw_call("accept_funds_echo_caller") + .original_result() + } + pub fn accept_funds_single_esdt_transfer( self, ) -> TxTypedCall { diff --git a/contracts/feature-tests/composability/promises-features/src/vault_proxy.rs b/contracts/feature-tests/composability/promises-features/src/vault_proxy.rs index 9636e1e5d1..4572a73507 100644 --- a/contracts/feature-tests/composability/promises-features/src/vault_proxy.rs +++ b/contracts/feature-tests/composability/promises-features/src/vault_proxy.rs @@ -117,6 +117,14 @@ where .original_result() } + pub fn accept_funds_echo_caller( + self, + ) -> TxTypedCall> { + self.wrapped_tx + .raw_call("accept_funds_echo_caller") + .original_result() + } + pub fn accept_funds_single_esdt_transfer( self, ) -> TxTypedCall { diff --git a/contracts/feature-tests/composability/recursive-caller/src/vault_proxy.rs b/contracts/feature-tests/composability/recursive-caller/src/vault_proxy.rs index 9636e1e5d1..4572a73507 100644 --- a/contracts/feature-tests/composability/recursive-caller/src/vault_proxy.rs +++ b/contracts/feature-tests/composability/recursive-caller/src/vault_proxy.rs @@ -117,6 +117,14 @@ where .original_result() } + pub fn accept_funds_echo_caller( + self, + ) -> TxTypedCall> { + self.wrapped_tx + .raw_call("accept_funds_echo_caller") + .original_result() + } + pub fn accept_funds_single_esdt_transfer( self, ) -> TxTypedCall { diff --git a/contracts/feature-tests/composability/vault/src/vault.rs b/contracts/feature-tests/composability/vault/src/vault.rs index 86ddbe31bb..d2390bde4f 100644 --- a/contracts/feature-tests/composability/vault/src/vault.rs +++ b/contracts/feature-tests/composability/vault/src/vault.rs @@ -82,6 +82,20 @@ pub trait Vault { (egld_value.clone_value(), esdt_transfers_multi).into() } + #[payable("*")] + #[endpoint] + fn accept_funds_echo_caller(&self) -> ManagedAddress { + let egld_value = self.call_value().egld_value(); + let esdt_transfers_multi = self.esdt_transfers_multi(); + let caller = self.blockchain().get_caller(); + self.accept_funds_event(&egld_value, &esdt_transfers_multi); + + self.call_counts(ManagedBuffer::from(b"accept_funds_echo_caller")) + .update(|c| *c += 1); + + caller + } + #[payable("*")] #[endpoint] fn accept_funds_single_esdt_transfer(&self) { diff --git a/contracts/feature-tests/composability/vault/wasm-vault-promises/src/lib.rs b/contracts/feature-tests/composability/vault/wasm-vault-promises/src/lib.rs index efb935753e..9274dd4e91 100644 --- a/contracts/feature-tests/composability/vault/wasm-vault-promises/src/lib.rs +++ b/contracts/feature-tests/composability/vault/wasm-vault-promises/src/lib.rs @@ -5,9 +5,9 @@ //////////////////////////////////////////////////// // Init: 1 -// Endpoints: 19 +// Endpoints: 20 // Async Callback (empty): 1 -// Total number of exported functions: 21 +// Total number of exported functions: 22 #![no_std] @@ -23,6 +23,7 @@ multiversx_sc_wasm_adapter::endpoints! { echo_caller => echo_caller accept_funds => accept_funds accept_funds_echo_payment => accept_funds_echo_payment + accept_funds_echo_caller => accept_funds_echo_caller accept_funds_single_esdt_transfer => accept_funds_single_esdt_transfer reject_funds => reject_funds retrieve_funds_with_transfer_exec => retrieve_funds_with_transfer_exec diff --git a/contracts/feature-tests/composability/vault/wasm/src/lib.rs b/contracts/feature-tests/composability/vault/wasm/src/lib.rs index 8846eba08e..f825b1a428 100644 --- a/contracts/feature-tests/composability/vault/wasm/src/lib.rs +++ b/contracts/feature-tests/composability/vault/wasm/src/lib.rs @@ -6,9 +6,9 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 18 +// Endpoints: 19 // Async Callback (empty): 1 -// Total number of exported functions: 21 +// Total number of exported functions: 22 #![no_std] @@ -25,6 +25,7 @@ multiversx_sc_wasm_adapter::endpoints! { echo_caller => echo_caller accept_funds => accept_funds accept_funds_echo_payment => accept_funds_echo_payment + accept_funds_echo_caller => accept_funds_echo_caller accept_funds_single_esdt_transfer => accept_funds_single_esdt_transfer reject_funds => reject_funds retrieve_funds_with_transfer_exec => retrieve_funds_with_transfer_exec