From 26e3b46a078afcb3f6ae751e592c1e11e2384749 Mon Sep 17 00:00:00 2001 From: Rebegea Dragos-Alexandru Date: Wed, 6 Nov 2024 11:35:35 +0200 Subject: [PATCH 1/2] remove safe storage from wrapper --- ...ridge_proxy_execute_crowdfunding.scen.json | 17 ------ .../src/bridged_tokens_wrapper_proxy.rs | 29 ++-------- .../tests/bridge_proxy_blackbox_test.rs | 7 --- bridged-tokens-wrapper/src/lib.rs | 18 +------ .../bridged_tokens_wrapper_whitebox_test.rs | 53 +++---------------- bridged-tokens-wrapper/wasm/src/lib.rs | 6 +-- .../src/bridged_tokens_wrapper_proxy.rs | 29 ++-------- .../tests/multi_transfer_blackbox_test.rs | 15 ++---- multisig/src/bridged_tokens_wrapper_proxy.rs | 29 ++-------- 9 files changed, 32 insertions(+), 171 deletions(-) diff --git a/bridge-proxy/scenarios/bridge_proxy_execute_crowdfunding.scen.json b/bridge-proxy/scenarios/bridge_proxy_execute_crowdfunding.scen.json index 92f241d8..f2a48dfc 100644 --- a/bridge-proxy/scenarios/bridge_proxy_execute_crowdfunding.scen.json +++ b/bridge-proxy/scenarios/bridge_proxy_execute_crowdfunding.scen.json @@ -159,23 +159,6 @@ "status": "0" } }, - { - "step": "scCall", - "id": "", - "tx": { - "from": "address:owner", - "to": "sc:bridged-tokens-wrapper", - "function": "setEsdtSafeContractAddress", - "arguments": [ - "0x00000000000000000500657364742d736166655f5f5f5f5f5f5f5f5f5f5f5f5f" - ], - "gasLimit": "5,000,000" - }, - "expect": { - "out": [], - "status": "0" - } - }, { "step": "scCall", "id": "", diff --git a/bridge-proxy/src/bridged_tokens_wrapper_proxy.rs b/bridge-proxy/src/bridged_tokens_wrapper_proxy.rs index df5b7a63..ac306e11 100644 --- a/bridge-proxy/src/bridged_tokens_wrapper_proxy.rs +++ b/bridge-proxy/src/bridged_tokens_wrapper_proxy.rs @@ -205,32 +205,22 @@ where pub fn unwrap_token_create_transaction< Arg0: ProxyArg>, - Arg1: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg>, >( self, requested_token: Arg0, - to: Arg1, + safe_address: Arg1, + to: Arg2, ) -> TxTypedCall { self.wrapped_tx .raw_call("unwrapTokenCreateTransaction") .argument(&requested_token) + .argument(&safe_address) .argument(&to) .original_result() } - pub fn set_esdt_safe_contract_address< - Arg0: ProxyArg>>, - >( - self, - opt_new_address: Arg0, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("setEsdtSafeContractAddress") - .argument(&opt_new_address) - .original_result() - } - pub fn universal_bridged_token_ids( self, ) -> TxTypedCall>> { @@ -279,15 +269,6 @@ where .original_result() } - pub fn esdt_safe_contract_address( - self, - ) -> TxTypedCall> { - self.wrapped_tx - .payment(NotPayable) - .raw_call("getEsdtSafeContractAddress") - .original_result() - } - pub fn pause_endpoint( self, ) -> TxTypedCall { diff --git a/bridge-proxy/tests/bridge_proxy_blackbox_test.rs b/bridge-proxy/tests/bridge_proxy_blackbox_test.rs index 2e542e45..c4693ecc 100644 --- a/bridge-proxy/tests/bridge_proxy_blackbox_test.rs +++ b/bridge-proxy/tests/bridge_proxy_blackbox_test.rs @@ -214,13 +214,6 @@ impl BridgeProxyTestState { ) .run(); - self.world - .tx() - .from(OWNER_ADDRESS) - .to(BRIDGED_TOKENS_WRAPPER_ADDRESS) - .typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy) - .set_esdt_safe_contract_address(OptionalValue::Some(ESDT_SAFE_ADDRESS)) - .run(); self } } diff --git a/bridged-tokens-wrapper/src/lib.rs b/bridged-tokens-wrapper/src/lib.rs index 16694427..15d4fabc 100644 --- a/bridged-tokens-wrapper/src/lib.rs +++ b/bridged-tokens-wrapper/src/lib.rs @@ -246,13 +246,14 @@ pub trait BridgedTokensWrapper: fn unwrap_token_create_transaction( &self, requested_token: TokenIdentifier, + safe_address: ManagedAddress, to: EthAddress, ) { let converted_amount = self.unwrap_token_common(&requested_token); let caller = self.blockchain().get_caller(); self.tx() - .to(self.esdt_safe_contract_address().get()) + .to(safe_address) .typed(esdt_safe_proxy::EsdtSafeProxy) .create_transaction( to, @@ -302,17 +303,6 @@ pub trait BridgedTokensWrapper: ); } - #[only_owner] - #[endpoint(setEsdtSafeContractAddress)] - fn set_esdt_safe_contract_address(&self, opt_new_address: OptionalValue) { - match opt_new_address { - OptionalValue::Some(sc_addr) => { - self.esdt_safe_contract_address().set(&sc_addr); - } - OptionalValue::None => self.esdt_safe_contract_address().clear(), - } - } - #[view(getUniversalBridgedTokenIds)] #[storage_mapper("universalBridgedTokenIds")] fn universal_bridged_token_ids(&self) -> UnorderedSetMapper; @@ -337,8 +327,4 @@ pub trait BridgedTokensWrapper: #[storage_mapper("token_decimals_num")] fn token_decimals_num(&self, token: &TokenIdentifier) -> SingleValueMapper; - - #[view(getEsdtSafeContractAddress)] - #[storage_mapper("esdtSafeContractAddress")] - fn esdt_safe_contract_address(&self) -> SingleValueMapper; } diff --git a/bridged-tokens-wrapper/tests/bridged_tokens_wrapper_whitebox_test.rs b/bridged-tokens-wrapper/tests/bridged_tokens_wrapper_whitebox_test.rs index 965c6dc7..8472a856 100644 --- a/bridged-tokens-wrapper/tests/bridged_tokens_wrapper_whitebox_test.rs +++ b/bridged-tokens-wrapper/tests/bridged_tokens_wrapper_whitebox_test.rs @@ -131,43 +131,6 @@ fn test_require_tokens_have_set_decimals_num_should_work() { ); } -#[test] -fn test_set_esdt_safe_contract_address_should_work() { - let mut world = setup(); - let bridged_tokens_wrapper = WhiteboxContract::new( - BRIDGE_TOKENS_WRAPPER_ADDRESS_EXPR, - bridged_tokens_wrapper::contract_obj, - ); - - let esdt_address_expr = "address:from".to_string(); - let esdt_address = AddressValue::from(esdt_address_expr.as_str()); - - world.whitebox_call( - &bridged_tokens_wrapper, - ScCallStep::new().from(OWNER_ADDRESS_EXPR), - |sc| { - sc.set_esdt_safe_contract_address(OptionalValue::Some(managed_address!( - &esdt_address.to_address() - ))); - }, - ); - - world.whitebox_query(&bridged_tokens_wrapper, |sc| { - let result = sc.esdt_safe_contract_address().get(); - assert_eq!(result, managed_address!(&esdt_address.to_address())); - }); - - world.whitebox_call( - &bridged_tokens_wrapper, - ScCallStep::new().from(OWNER_ADDRESS_EXPR), - |sc| { - sc.set_esdt_safe_contract_address(OptionalValue::None); - let result = sc.esdt_safe_contract_address().is_empty(); - assert!(result); - }, - ); -} - #[test] fn test_require_mint_and_burn_roles_should_fail() { let mut world = setup(); @@ -424,13 +387,13 @@ fn test_unwrap_token_create_transaction_should_fail_case_1() { .expect(TxExpect::user_error("str:Contract is paused")), |sc| { sc.set_paused(true); - sc.set_esdt_safe_contract_address(OptionalValue::Some(ManagedAddress::new_from_bytes( - b"0102030405060708090a0b0c0d0e0f10", - ))); let address = convert_to_eth_address(ETH_ADDRESS); sc.unwrap_token_create_transaction( managed_token_id!(UNIVERSAL_TOKEN_IDENTIFIER), + ManagedAddress::new_from_bytes( + b"0102030405060708090a0b0c0d0e0f10", + ), address, ); }, @@ -468,6 +431,9 @@ fn test_unwrap_token_create_transaction_should_fail_case_2() { let address = convert_to_eth_address(ETH_ADDRESS); sc.unwrap_token_create_transaction( managed_token_id!(UNIVERSAL_TOKEN_IDENTIFIER), + ManagedAddress::new_from_bytes( + b"0102030405060708090a0b0c0d0e0f10", + ), address, ); }, @@ -505,6 +471,7 @@ fn test_unwrap_token_create_transaction_should_fail_case_3() { let address = convert_to_eth_address(ETH_ADDRESS); sc.unwrap_token_create_transaction( managed_token_id!(UNIVERSAL_TOKEN_IDENTIFIER), + ManagedAddress::zero(), address, ); }, @@ -577,6 +544,7 @@ fn test_unwrap_token_create_transaction_should_fail_case_4() { let address = convert_to_eth_address(ETH_ADDRESS); sc.unwrap_token_create_transaction( managed_token_id!(UNIVERSAL_TOKEN_IDENTIFIER), + ManagedAddress::zero(), address, ); }, @@ -621,11 +589,6 @@ fn test_unwrap_token_create_transaction_should_work() { sc.deposit_liquidity(); sc.chain_specific_to_universal_mapping(&managed_token_id!(UNIVERSAL_TOKEN_IDENTIFIER)) .set(managed_token_id!(UNIVERSAL_TOKEN_IDENTIFIER)); - let esdt_address_expr = "sc:esdt_safe".to_string(); - let esdt_address = AddressValue::from(esdt_address_expr.as_str()); - sc.set_esdt_safe_contract_address(OptionalValue::Some(managed_address!( - &esdt_address.to_address() - ))); }, ); } diff --git a/bridged-tokens-wrapper/wasm/src/lib.rs b/bridged-tokens-wrapper/wasm/src/lib.rs index 29f9d9c1..cdad1731 100644 --- a/bridged-tokens-wrapper/wasm/src/lib.rs +++ b/bridged-tokens-wrapper/wasm/src/lib.rs @@ -6,9 +6,9 @@ // Init: 1 // Upgrade: 1 -// Endpoints: 19 +// Endpoints: 17 // Async Callback (empty): 1 -// Total number of exported functions: 22 +// Total number of exported functions: 20 #![no_std] @@ -30,12 +30,10 @@ multiversx_sc_wasm_adapter::endpoints! { wrapTokens => wrap_tokens unwrapToken => unwrap_token unwrapTokenCreateTransaction => unwrap_token_create_transaction - setEsdtSafeContractAddress => set_esdt_safe_contract_address getUniversalBridgedTokenIds => universal_bridged_token_ids getTokenLiquidity => token_liquidity getChainSpecificToUniversalMapping => chain_specific_to_universal_mapping getchainSpecificTokenIds => chain_specific_token_ids - getEsdtSafeContractAddress => esdt_safe_contract_address pause => pause_endpoint unpause => unpause_endpoint isPaused => paused_status diff --git a/multi-transfer-esdt/src/bridged_tokens_wrapper_proxy.rs b/multi-transfer-esdt/src/bridged_tokens_wrapper_proxy.rs index df5b7a63..ac306e11 100644 --- a/multi-transfer-esdt/src/bridged_tokens_wrapper_proxy.rs +++ b/multi-transfer-esdt/src/bridged_tokens_wrapper_proxy.rs @@ -205,32 +205,22 @@ where pub fn unwrap_token_create_transaction< Arg0: ProxyArg>, - Arg1: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg>, >( self, requested_token: Arg0, - to: Arg1, + safe_address: Arg1, + to: Arg2, ) -> TxTypedCall { self.wrapped_tx .raw_call("unwrapTokenCreateTransaction") .argument(&requested_token) + .argument(&safe_address) .argument(&to) .original_result() } - pub fn set_esdt_safe_contract_address< - Arg0: ProxyArg>>, - >( - self, - opt_new_address: Arg0, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("setEsdtSafeContractAddress") - .argument(&opt_new_address) - .original_result() - } - pub fn universal_bridged_token_ids( self, ) -> TxTypedCall>> { @@ -279,15 +269,6 @@ where .original_result() } - pub fn esdt_safe_contract_address( - self, - ) -> TxTypedCall> { - self.wrapped_tx - .payment(NotPayable) - .raw_call("getEsdtSafeContractAddress") - .original_result() - } - pub fn pause_endpoint( self, ) -> TxTypedCall { diff --git a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs index 6b8eccc1..804e150c 100644 --- a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs +++ b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs @@ -318,13 +318,6 @@ impl MultiTransferTestState { } fn config_bridged_tokens_wrapper(&mut self) { - self.world - .tx() - .from(OWNER_ADDRESS) - .to(BRIDGED_TOKENS_WRAPPER_ADDRESS) - .typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy) - .set_esdt_safe_contract_address(OptionalValue::Some(ESDT_SAFE_ADDRESS.to_address())) - .run(); self.world .tx() @@ -809,6 +802,7 @@ fn test_unwrap_token_create_transaction_paused() { .typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy) .unwrap_token_create_transaction( TokenIdentifier::from(UNIVERSAL_TOKEN_IDENTIFIER), + ESDT_SAFE_ADDRESS.to_address(), EthAddress::zero(), ) .egld_or_single_esdt( @@ -860,7 +854,7 @@ fn test_unwrap_token_create_transaction_insufficient_liquidity() { .from(USER1_ADDRESS) .to(BRIDGED_TOKENS_WRAPPER_ADDRESS) .typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy) - .unwrap_token_create_transaction(WRAPPED_TOKEN_ID, EthAddress::zero()) + .unwrap_token_create_transaction(WRAPPED_TOKEN_ID, ESDT_SAFE_ADDRESS.to_address(), EthAddress::zero()) .egld_or_single_esdt( &EgldOrEsdtTokenIdentifier::esdt(UNIVERSAL_TOKEN_IDENTIFIER), 0u64, @@ -919,7 +913,7 @@ fn test_unwrap_token_create_transaction_should_work() { .from(USER1_ADDRESS) .to(BRIDGED_TOKENS_WRAPPER_ADDRESS) .typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy) - .unwrap_token_create_transaction(WRAPPED_TOKEN_ID, EthAddress::zero()) + .unwrap_token_create_transaction(WRAPPED_TOKEN_ID, ESDT_SAFE_ADDRESS.to_address(), EthAddress::zero()) .egld_or_single_esdt( &EgldOrEsdtTokenIdentifier::esdt(UNIVERSAL_TOKEN_IDENTIFIER), 0u64, @@ -963,7 +957,7 @@ fn test_unwrap_token_create_transaction_should_fail() { .from(USER1_ADDRESS) .to(BRIDGED_TOKENS_WRAPPER_ADDRESS) .typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy) - .unwrap_token_create_transaction(WRAPPED_TOKEN_ID, EthAddress::zero()) + .unwrap_token_create_transaction(WRAPPED_TOKEN_ID, ESDT_SAFE_ADDRESS.to_address(), EthAddress::zero()) .egld_or_single_esdt( &EgldOrEsdtTokenIdentifier::esdt(TOKEN_ID), 0u64, @@ -989,6 +983,7 @@ fn test_unwrap_token_create_transaction_amount_zero() { .typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy) .unwrap_token_create_transaction( TokenIdentifier::from(WRAPPED_TOKEN_ID), + ESDT_SAFE_ADDRESS.to_address(), EthAddress::zero(), ) .egld_or_single_esdt( diff --git a/multisig/src/bridged_tokens_wrapper_proxy.rs b/multisig/src/bridged_tokens_wrapper_proxy.rs index df5b7a63..ac306e11 100644 --- a/multisig/src/bridged_tokens_wrapper_proxy.rs +++ b/multisig/src/bridged_tokens_wrapper_proxy.rs @@ -205,32 +205,22 @@ where pub fn unwrap_token_create_transaction< Arg0: ProxyArg>, - Arg1: ProxyArg>, + Arg1: ProxyArg>, + Arg2: ProxyArg>, >( self, requested_token: Arg0, - to: Arg1, + safe_address: Arg1, + to: Arg2, ) -> TxTypedCall { self.wrapped_tx .raw_call("unwrapTokenCreateTransaction") .argument(&requested_token) + .argument(&safe_address) .argument(&to) .original_result() } - pub fn set_esdt_safe_contract_address< - Arg0: ProxyArg>>, - >( - self, - opt_new_address: Arg0, - ) -> TxTypedCall { - self.wrapped_tx - .payment(NotPayable) - .raw_call("setEsdtSafeContractAddress") - .argument(&opt_new_address) - .original_result() - } - pub fn universal_bridged_token_ids( self, ) -> TxTypedCall>> { @@ -279,15 +269,6 @@ where .original_result() } - pub fn esdt_safe_contract_address( - self, - ) -> TxTypedCall> { - self.wrapped_tx - .payment(NotPayable) - .raw_call("getEsdtSafeContractAddress") - .original_result() - } - pub fn pause_endpoint( self, ) -> TxTypedCall { From 0854c953b98ec576d63be562aae24b07a169a629 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Wed, 6 Nov 2024 14:21:54 +0200 Subject: [PATCH 2/2] - script updates --- multisig/interaction/config/menu_functions.cfg | 3 --- multisig/interaction/config/wrapped-snippets.sh | 9 --------- 2 files changed, 12 deletions(-) diff --git a/multisig/interaction/config/menu_functions.cfg b/multisig/interaction/config/menu_functions.cfg index 0d492f78..844dd030 100644 --- a/multisig/interaction/config/menu_functions.cfg +++ b/multisig/interaction/config/menu_functions.cfg @@ -48,8 +48,6 @@ function deploy-bridge-contracts { confirmation-with-skip setMultiTransferOnSCProxy confirmation-with-skip setEsdtSafeOnSCProxy - confirmation-with-skip setEsdtSafeOnWrapper - confirmation-with-skip setBridgedTokensWrapperOnEsdtSafe confirmation-with-skip setSCProxyOnEsdtSafe @@ -179,7 +177,6 @@ function upgrade-aggregator { function upgrade-wrapper { wrapper-upgrade - confirmation-with-skip setEsdtSafeOnWrapper } function upgrade-safe { diff --git a/multisig/interaction/config/wrapped-snippets.sh b/multisig/interaction/config/wrapped-snippets.sh index 7a2ad727..f5740b4c 100644 --- a/multisig/interaction/config/wrapped-snippets.sh +++ b/multisig/interaction/config/wrapped-snippets.sh @@ -136,12 +136,3 @@ wrapper-upgrade() { --gas-limit=50000000 --send \ --outfile="upgrade-bridged-tokens-wrapper.json" --proxy=${PROXY} --chain=${CHAIN_ID} || return } - -setEsdtSafeOnWrapper() { - CHECK_VARIABLES BRIDGED_TOKENS_WRAPPER SAFE - - mxpy --verbose contract call ${BRIDGED_TOKENS_WRAPPER} --recall-nonce --pem=${ALICE} \ - --gas-limit=60000000 --function="setEsdtSafeContractAddress" \ - --arguments ${SAFE} \ - --send --proxy=${PROXY} --chain=${CHAIN_ID} -}