From e2f0c004d96cec99a54945c0786d8ffee9eedd0c Mon Sep 17 00:00:00 2001 From: dragosrebegea Date: Mon, 21 Oct 2024 11:43:15 +0300 Subject: [PATCH 01/12] fix unwrap_token if native token --- bridge-proxy/src/bridge-proxy.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/bridge-proxy/src/bridge-proxy.rs b/bridge-proxy/src/bridge-proxy.rs index 3c049c91..e96f3310 100644 --- a/bridge-proxy/src/bridge-proxy.rs +++ b/bridge-proxy/src/bridge-proxy.rs @@ -153,9 +153,22 @@ pub trait BridgeProxyContract: let payment = self.payments(tx_id).get(); let bridged_tokens_wrapper_address = self.bridged_tokens_wrapper_address().get(); + let universal_token = self + .tx() + .to(&bridged_tokens_wrapper_address) + .typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy) + .chain_specific_to_universal_mapping(requested_token) + .returns(ReturnsResult) + .sync_call(); + + if universal_token != payment.token_identifier { + return payment; + } + let transfers = self .tx() - .to(bridged_tokens_wrapper_address) .typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy) + .to(&bridged_tokens_wrapper_address) + .typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy) .unwrap_token(requested_token) .single_esdt( &payment.token_identifier, From 0802c222f04e8a6b814d1e8ebe661db713554313 Mon Sep 17 00:00:00 2001 From: dragosrebegea Date: Mon, 21 Oct 2024 13:48:19 +0300 Subject: [PATCH 02/12] improvement --- bridge-proxy/src/bridge-proxy.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/bridge-proxy/src/bridge-proxy.rs b/bridge-proxy/src/bridge-proxy.rs index e96f3310..32913859 100644 --- a/bridge-proxy/src/bridge-proxy.rs +++ b/bridge-proxy/src/bridge-proxy.rs @@ -152,16 +152,8 @@ pub trait BridgeProxyContract: fn unwrap_token(&self, requested_token: &TokenIdentifier, tx_id: usize) -> EsdtTokenPayment { let payment = self.payments(tx_id).get(); let bridged_tokens_wrapper_address = self.bridged_tokens_wrapper_address().get(); - - let universal_token = self - .tx() - .to(&bridged_tokens_wrapper_address) - .typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy) - .chain_specific_to_universal_mapping(requested_token) - .returns(ReturnsResult) - .sync_call(); - if universal_token != payment.token_identifier { + if requested_token == &payment.token_identifier { return payment; } From b6f2723f99e30b60622e4cb102d6679959265f06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Fri, 25 Oct 2024 18:27:33 +0300 Subject: [PATCH 03/12] esdt-safe: fix add_refund_batch --- esdt-safe/src/lib.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/esdt-safe/src/lib.rs b/esdt-safe/src/lib.rs index 327ec158..02e76113 100644 --- a/esdt-safe/src/lib.rs +++ b/esdt-safe/src/lib.rs @@ -20,8 +20,8 @@ pub type PaymentsVec = ManagedVec>; #[derive(TopEncode, TopDecode, NestedEncode, NestedDecode, Clone, ManagedVecItem, PartialEq)] pub struct RefundInfo { pub address: ManagedAddress, - pub initial_batch_id: u64, - pub initial_nonce: u64 + pub initial_batch_id: u64, + pub initial_nonce: u64, } #[multiversx_sc::contract] @@ -80,8 +80,8 @@ pub trait EsdtSafe: .set(&fee_estimator_contract_address); self.multi_transfer_contract_address() .set(&multi_transfer_contract_address); - self.bridge_proxy_contract_address(). - set(&bridge_proxy_contract_address); + self.bridge_proxy_contract_address() + .set(&bridge_proxy_contract_address); self.eth_tx_gas_limit().set(ð_tx_gas_limit); @@ -246,7 +246,7 @@ pub trait EsdtSafe: }); } else { self.total_balances(&refund_token_id).update(|total| { - *total -= &actual_bridged_amount; + *total += &actual_bridged_amount; }); } } @@ -304,7 +304,11 @@ pub trait EsdtSafe: sc_panic!("Cannot specify a refund address from this caller"); } } - OptionalValue::None => RefundInfo{ address: caller, initial_batch_id: 0, initial_nonce: 0}, + OptionalValue::None => RefundInfo { + address: caller, + initial_batch_id: 0, + initial_nonce: 0, + }, }; self.accumulated_transaction_fees(&payment_token) @@ -364,7 +368,6 @@ pub trait EsdtSafe: refund_info.initial_nonce, ); } - } /// Claim funds for failed MultiversX -> Ethereum transactions. From cfd4363c1af35cb67576c0358695d08c820b96c5 Mon Sep 17 00:00:00 2001 From: evelinemolnar Date: Fri, 25 Oct 2024 19:56:02 +0300 Subject: [PATCH 04/12] unit test --- .../tests/multi_transfer_blackbox_test.rs | 80 ++++++++++++++++++- 1 file changed, 76 insertions(+), 4 deletions(-) diff --git a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs index 70f0cc7e..cb4e0c4d 100644 --- a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs +++ b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs @@ -42,6 +42,7 @@ use transaction::{CallData, EthTransaction}; const UNIVERSAL_TOKEN_IDENTIFIER: TestTokenIdentifier = TestTokenIdentifier::new("UNIV-abc123"); const BRIDGE_TOKEN_ID: TestTokenIdentifier = TestTokenIdentifier::new("BRIDGE-123456"); const WRAPPED_TOKEN_ID: TestTokenIdentifier = TestTokenIdentifier::new("WRAPPED-123456"); +const TOKEN_ID: TestTokenIdentifier = TestTokenIdentifier::new("TOKEN"); const USER_ETHEREUM_ADDRESS: &[u8] = b"0x0102030405060708091011121314151617181920"; @@ -69,6 +70,7 @@ const USER1_ADDRESS: TestAddress = TestAddress::new("user1"); const USER2_ADDRESS: TestAddress = TestAddress::new("user2"); const ESDT_SAFE_ETH_TX_GAS_LIMIT: u64 = 150_000; +const MAX_AMOUNT: u64 = 100_000_000_000_000u64; const BALANCE: &str = "2,000,000"; @@ -108,6 +110,7 @@ impl MultiTransferTestState { .account(OWNER_ADDRESS) .nonce(1) .esdt_balance(BRIDGE_TOKEN_ID, 1001u64) + .esdt_balance(TOKEN_ID, MAX_AMOUNT) .esdt_balance(WRAPPED_TOKEN_ID, 1001u64) .esdt_balance(UNIVERSAL_TOKEN_IDENTIFIER, 1001u64) .account(USER1_ADDRESS) @@ -242,6 +245,36 @@ impl MultiTransferTestState { ) .run(); + self.world + .tx() + .from(OWNER_ADDRESS) + .to(ESDT_SAFE_ADDRESS) + .typed(esdt_safe_proxy::EsdtSafeProxy) + .add_token_to_whitelist( + TokenIdentifier::from_esdt_bytes("TOKEN"), + "TOKEN", + false, + true, + BigUint::from(MAX_AMOUNT), + BigUint::zero(), + BigUint::zero(), + OptionalValue::Some(BigUint::from(ESDT_SAFE_ETH_TX_GAS_LIMIT)), + ) + .single_esdt( + &TokenIdentifier::from_esdt_bytes("TOKEN"), + 0, + &BigUint::from(MAX_AMOUNT), + ) + .run(); + + self.world + .tx() + .from(OWNER_ADDRESS) + .to(MULTI_TRANSFER_ADDRESS) + .typed(multi_transfer_proxy::MultiTransferEsdtProxy) + .set_max_bridged_amount(TOKEN_ID, MAX_AMOUNT - 1) + .run(); + self.world .tx() .from(OWNER_ADDRESS) @@ -777,10 +810,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, EthAddress::zero()) .egld_or_single_esdt( &EgldOrEsdtTokenIdentifier::esdt(UNIVERSAL_TOKEN_IDENTIFIER), 0u64, @@ -842,3 +872,45 @@ fn test_unwrap_token_create_transaction_amount_zero() { .returns(ExpectError(ERROR, "Must pay more than 0 tokens!")) .run(); } + +#[test] +fn add_refund_batch_test() { + let mut state = MultiTransferTestState::new(); + + state.multi_transfer_deploy(); + state.bridge_proxy_deploy(); + state.safe_deploy(Address::zero()); + state.bridged_tokens_wrapper_deploy(); + state.config_multi_transfer(); + + let eth_tx = EthTransaction { + from: EthAddress::zero(), + to: ManagedAddress::from(USER1_ADDRESS.eval_to_array()), + token_id: TokenIdentifier::from(TOKEN_ID), + amount: BigUint::from(MAX_AMOUNT), + tx_nonce: 1u64, + call_data: ManagedOption::none(), + }; + + let mut transfers: MultiValueEncoded> = + MultiValueEncoded::new(); + transfers.push(eth_tx.clone()); + + state + .world + .tx() + .from(OWNER_ADDRESS) + .to(MULTI_TRANSFER_ADDRESS) + .typed(multi_transfer_proxy::MultiTransferEsdtProxy) + .batch_transfer_esdt_token(1u32, transfers) + .run(); + + state + .world + .tx() + .from(OWNER_ADDRESS) + .to(MULTI_TRANSFER_ADDRESS) + .typed(multi_transfer_proxy::MultiTransferEsdtProxy) + .move_refund_batch_to_safe() + .run(); +} From e7bd1f01e59e6b2721635672a70d807bf99e4907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Fri, 25 Oct 2024 20:52:52 +0300 Subject: [PATCH 05/12] multi-transfer: add_refund_batch_test: add balances check --- .../tests/multi_transfer_blackbox_test.rs | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs index cb4e0c4d..21354c9c 100644 --- a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs +++ b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs @@ -469,6 +469,58 @@ impl MultiTransferTestState { ) .run(); } + + fn check_balances_on_safe( + &mut self, + total_supply: BigUint, + total_minted: BigUint, + total_burned: BigUint, + ) { + let actual_total_supply = self + .world + .query() + .to(ESDT_SAFE_ADDRESS) + .typed(esdt_safe_proxy::EsdtSafeProxy) + .total_balances(TOKEN_ID) + .returns(ReturnsResult) + .run(); + + assert_eq!( + actual_total_supply, + BigUint::from(total_supply), + "Total supply balance is wrong" + ); + let actual_total_burned = self + .world + .query() + .to(ESDT_SAFE_ADDRESS) + .typed(esdt_safe_proxy::EsdtSafeProxy) + .burn_balances(TOKEN_ID) + .returns(ReturnsResult) + .run(); + + assert_eq!( + actual_total_burned, + BigUint::from(total_burned), + "Total burned balance is wrong" + ); + + let actual_total_minted = self + .world + .query() + .to(ESDT_SAFE_ADDRESS) + .typed(esdt_safe_proxy::EsdtSafeProxy) + .mint_balances(TOKEN_ID) + .returns(ReturnsResult) + .run(); + + assert_eq!( + actual_total_minted, + BigUint::from(total_minted), + "Total minted balance is wrong" + ); + } + fn deploy_contracts(&mut self) { self.multi_transfer_deploy(); self.bridge_proxy_deploy(); @@ -896,6 +948,9 @@ fn add_refund_batch_test() { MultiValueEncoded::new(); transfers.push(eth_tx.clone()); + let fee = 22_500_000_000u64; + state.check_balances_on_safe(BigUint::from(MAX_AMOUNT), BigUint::zero(), BigUint::zero()); + state .world .tx() @@ -904,6 +959,7 @@ fn add_refund_batch_test() { .typed(multi_transfer_proxy::MultiTransferEsdtProxy) .batch_transfer_esdt_token(1u32, transfers) .run(); + state.check_balances_on_safe(BigUint::zero(), BigUint::zero(), BigUint::zero()); state .world @@ -913,4 +969,10 @@ fn add_refund_batch_test() { .typed(multi_transfer_proxy::MultiTransferEsdtProxy) .move_refund_batch_to_safe() .run(); + + state.check_balances_on_safe( + BigUint::from(MAX_AMOUNT) - fee, + BigUint::zero(), + BigUint::zero(), + ); } From afb61cdc787a2bf71264bbef20e64ce9dccdfa5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Fri, 25 Oct 2024 20:58:01 +0300 Subject: [PATCH 06/12] clippy fix --- .../tests/multi_transfer_blackbox_test.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs index 21354c9c..9630c6b4 100644 --- a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs +++ b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs @@ -486,8 +486,7 @@ impl MultiTransferTestState { .run(); assert_eq!( - actual_total_supply, - BigUint::from(total_supply), + actual_total_supply, total_supply, "Total supply balance is wrong" ); let actual_total_burned = self @@ -500,8 +499,7 @@ impl MultiTransferTestState { .run(); assert_eq!( - actual_total_burned, - BigUint::from(total_burned), + actual_total_burned, total_burned, "Total burned balance is wrong" ); @@ -515,8 +513,7 @@ impl MultiTransferTestState { .run(); assert_eq!( - actual_total_minted, - BigUint::from(total_minted), + actual_total_minted, total_minted, "Total minted balance is wrong" ); } From 884f0be87d3116c790f8cfc8c0243d57dc862307 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Fri, 25 Oct 2024 21:05:50 +0300 Subject: [PATCH 07/12] multi-transfer: add_refund_batch_test: query fee --- .../tests/multi_transfer_blackbox_test.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs index 9630c6b4..62482ff5 100644 --- a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs +++ b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs @@ -945,7 +945,15 @@ fn add_refund_batch_test() { MultiValueEncoded::new(); transfers.push(eth_tx.clone()); - let fee = 22_500_000_000u64; + let fee = state + .world + .query() + .to(ESDT_SAFE_ADDRESS) + .typed(esdt_safe_proxy::EsdtSafeProxy) + .calculate_required_fee(TOKEN_ID) + .returns(ReturnsResult) + .run(); + state.check_balances_on_safe(BigUint::from(MAX_AMOUNT), BigUint::zero(), BigUint::zero()); state From 1bd71d92396a150a78f67694cd8e2e5818a32aad Mon Sep 17 00:00:00 2001 From: Eveline Molnar Date: Tue, 29 Oct 2024 15:34:18 +0200 Subject: [PATCH 08/12] fix unwrap and create transaction issue --- bridged-tokens-wrapper/src/lib.rs | 25 +++----- .../tests/multi_transfer_blackbox_test.rs | 59 ++++++++++++++++--- 2 files changed, 61 insertions(+), 23 deletions(-) diff --git a/bridged-tokens-wrapper/src/lib.rs b/bridged-tokens-wrapper/src/lib.rs index 3e4c35f1..16694427 100644 --- a/bridged-tokens-wrapper/src/lib.rs +++ b/bridged-tokens-wrapper/src/lib.rs @@ -248,26 +248,20 @@ pub trait BridgedTokensWrapper: requested_token: TokenIdentifier, to: EthAddress, ) { - let (payment_token, payment_amount) = self.call_value().single_fungible_esdt(); - let universal_token_id = self - .chain_specific_to_universal_mapping(&requested_token) - .get(); - - let converted_amount = if universal_token_id == payment_token { - self.unwrap_token_common(&requested_token) - } else { - payment_amount - }; + let converted_amount = self.unwrap_token_common(&requested_token); let caller = self.blockchain().get_caller(); self.tx() .to(self.esdt_safe_contract_address().get()) .typed(esdt_safe_proxy::EsdtSafeProxy) - .create_transaction(to, OptionalValue::Some(esdt_safe_proxy::RefundInfo { - address: caller, - initial_batch_id: 0, - initial_nonce: 0, - })) + .create_transaction( + to, + OptionalValue::Some(esdt_safe_proxy::RefundInfo { + address: caller, + initial_batch_id: 0, + initial_nonce: 0, + }), + ) .single_esdt(&requested_token, 0, &converted_amount) .sync_call(); } @@ -347,5 +341,4 @@ pub trait BridgedTokensWrapper: #[view(getEsdtSafeContractAddress)] #[storage_mapper("esdtSafeContractAddress")] fn esdt_safe_contract_address(&self) -> SingleValueMapper; - } diff --git a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs index 62482ff5..e9adeee6 100644 --- a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs +++ b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs @@ -815,7 +815,7 @@ fn test_unwrap_token_create_transaction_paused() { 0u64, &BigUint::from(10u64), ) - .returns(ExpectError(ERROR, "Cannot create transaction while paused")) + .returns(ExpectError(ERROR, "Contract is paused")) .run(); } @@ -877,21 +877,66 @@ fn test_unwrap_token_create_transaction_should_work() { state.config_multi_transfer(); state.config_bridged_tokens_wrapper(); + state .world .tx() - .from(BRIDGE_PROXY_ADDRESS) + .from(OWNER_ADDRESS) .to(BRIDGED_TOKENS_WRAPPER_ADDRESS) .typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy) - .unwrap_token_create_transaction( - TokenIdentifier::from(WRAPPED_TOKEN_ID), - EthAddress::zero(), - ) + .deposit_liquidity() .egld_or_single_esdt( &EgldOrEsdtTokenIdentifier::esdt(WRAPPED_TOKEN_ID), 0u64, - &BigUint::from(100u64), + &BigUint::from(1_000u64), + ) + .run(); + + state + .world + .set_esdt_balance(USER1_ADDRESS, b"UNIV-abc123", BigUint::from(5_000u64)); + + state + .world + .tx() + .from(USER1_ADDRESS) + .to(BRIDGED_TOKENS_WRAPPER_ADDRESS) + .typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy) + .unwrap_token_create_transaction(WRAPPED_TOKEN_ID, EthAddress::zero()) + .egld_or_single_esdt( + &EgldOrEsdtTokenIdentifier::esdt(UNIVERSAL_TOKEN_IDENTIFIER), + 0u64, + &BigUint::from(1_000u64), + ) + .run(); +} + +#[test] +fn test_unwrap_token_create_transaction_should_fail() { + let mut state = MultiTransferTestState::new(); + + state.deploy_contracts(); + + state.config_multi_transfer(); + state.config_bridged_tokens_wrapper(); + + state + .world + .set_esdt_balance(USER1_ADDRESS, b"TOKEN", BigUint::from(5_000u64)); + + state + .world + .tx() + .from(USER1_ADDRESS) + .to(BRIDGED_TOKENS_WRAPPER_ADDRESS) + .typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy) + .unwrap_token_create_transaction(WRAPPED_TOKEN_ID, EthAddress::zero()) + .egld_or_single_esdt( + &EgldOrEsdtTokenIdentifier::esdt(TOKEN_ID), + 0u64, + &BigUint::from(1_000u64), ) + .returns(ExpectError(ERROR, "Esdt token unavailable")) .run(); } From 38b32582626daf3d63caf415ba0a6eee27783809 Mon Sep 17 00:00:00 2001 From: Eveline Molnar Date: Tue, 29 Oct 2024 16:05:14 +0200 Subject: [PATCH 09/12] check the transaction is created and balances updated --- .../tests/multi_transfer_blackbox_test.rs | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs index e9adeee6..b4f9fe4b 100644 --- a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs +++ b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs @@ -472,6 +472,7 @@ impl MultiTransferTestState { fn check_balances_on_safe( &mut self, + token_id: TestTokenIdentifier, total_supply: BigUint, total_minted: BigUint, total_burned: BigUint, @@ -481,7 +482,7 @@ impl MultiTransferTestState { .query() .to(ESDT_SAFE_ADDRESS) .typed(esdt_safe_proxy::EsdtSafeProxy) - .total_balances(TOKEN_ID) + .total_balances(token_id) .returns(ReturnsResult) .run(); @@ -494,7 +495,7 @@ impl MultiTransferTestState { .query() .to(ESDT_SAFE_ADDRESS) .typed(esdt_safe_proxy::EsdtSafeProxy) - .burn_balances(TOKEN_ID) + .burn_balances(token_id) .returns(ReturnsResult) .run(); @@ -508,7 +509,7 @@ impl MultiTransferTestState { .query() .to(ESDT_SAFE_ADDRESS) .typed(esdt_safe_proxy::EsdtSafeProxy) - .mint_balances(TOKEN_ID) + .mint_balances(token_id) .returns(ReturnsResult) .run(); @@ -896,6 +897,13 @@ fn test_unwrap_token_create_transaction_should_work() { .world .set_esdt_balance(USER1_ADDRESS, b"UNIV-abc123", BigUint::from(5_000u64)); + state.check_balances_on_safe( + WRAPPED_TOKEN_ID, + BigUint::zero(), + BigUint::from(600000u64), + BigUint::zero(), + ); + state .world .tx() @@ -909,6 +917,13 @@ fn test_unwrap_token_create_transaction_should_work() { &BigUint::from(1_000u64), ) .run(); + + state.check_balances_on_safe( + WRAPPED_TOKEN_ID, + BigUint::zero(), + BigUint::from(600000u64), + BigUint::from(1_000u64), + ); } #[test] @@ -999,7 +1014,12 @@ fn add_refund_batch_test() { .returns(ReturnsResult) .run(); - state.check_balances_on_safe(BigUint::from(MAX_AMOUNT), BigUint::zero(), BigUint::zero()); + state.check_balances_on_safe( + TOKEN_ID, + BigUint::from(MAX_AMOUNT), + BigUint::zero(), + BigUint::zero(), + ); state .world @@ -1009,7 +1029,7 @@ fn add_refund_batch_test() { .typed(multi_transfer_proxy::MultiTransferEsdtProxy) .batch_transfer_esdt_token(1u32, transfers) .run(); - state.check_balances_on_safe(BigUint::zero(), BigUint::zero(), BigUint::zero()); + state.check_balances_on_safe(TOKEN_ID, BigUint::zero(), BigUint::zero(), BigUint::zero()); state .world @@ -1021,6 +1041,7 @@ fn add_refund_batch_test() { .run(); state.check_balances_on_safe( + TOKEN_ID, BigUint::from(MAX_AMOUNT) - fee, BigUint::zero(), BigUint::zero(), From 4b118d74024e00bd77a5bbf9bc3d62564c8662eb Mon Sep 17 00:00:00 2001 From: Eveline Molnar Date: Tue, 29 Oct 2024 16:08:29 +0200 Subject: [PATCH 10/12] check token_liquidity --- .../tests/multi_transfer_blackbox_test.rs | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs index b4f9fe4b..6b8eccc1 100644 --- a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs +++ b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs @@ -903,6 +903,15 @@ fn test_unwrap_token_create_transaction_should_work() { BigUint::from(600000u64), BigUint::zero(), ); + + state + .world + .query() + .to(BRIDGED_TOKENS_WRAPPER_ADDRESS) + .typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy) + .token_liquidity(WRAPPED_TOKEN_ID) + .returns(ExpectValue(BigUint::from(1000u64))) + .run(); state .world @@ -914,15 +923,24 @@ fn test_unwrap_token_create_transaction_should_work() { .egld_or_single_esdt( &EgldOrEsdtTokenIdentifier::esdt(UNIVERSAL_TOKEN_IDENTIFIER), 0u64, - &BigUint::from(1_000u64), + &BigUint::from(900u64), ) .run(); + state + .world + .query() + .to(BRIDGED_TOKENS_WRAPPER_ADDRESS) + .typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy) + .token_liquidity(WRAPPED_TOKEN_ID) + .returns(ExpectValue(BigUint::from(100u64))) + .run(); + state.check_balances_on_safe( WRAPPED_TOKEN_ID, BigUint::zero(), BigUint::from(600000u64), - BigUint::from(1_000u64), + BigUint::from(900u64), ); } From 1476020728aef3224b0cba28bf691e62abae0265 Mon Sep 17 00:00:00 2001 From: Eveline Molnar Date: Tue, 29 Oct 2024 17:03:11 +0200 Subject: [PATCH 11/12] increased min gas to save progress --- bridge-proxy/src/bridge-proxy.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/bridge-proxy/src/bridge-proxy.rs b/bridge-proxy/src/bridge-proxy.rs index 32913859..ac32037f 100644 --- a/bridge-proxy/src/bridge-proxy.rs +++ b/bridge-proxy/src/bridge-proxy.rs @@ -12,11 +12,11 @@ const MIN_GAS_LIMIT_FOR_SC_CALL: u64 = 10_000_000; const MAX_GAS_LIMIT_FOR_SC_CALL: u64 = 249999999; const DEFAULT_GAS_LIMIT_FOR_REFUND_CALLBACK: u64 = 20_000_000; // 20 million const DELAY_BEFORE_OWNER_CAN_CANCEL_TRANSACTION: u64 = 300; -const MIN_GAS_TO_SAVE_PROGRESS: u64 = 100_000; +const MIN_GAS_TO_SAVE_PROGRESS: u64 = 1_000_000; #[multiversx_sc::contract] pub trait BridgeProxyContract: - config::ConfigModule + config::ConfigModule + multiversx_sc_modules::pause::PauseModule + multiversx_sc_modules::ongoing_operation::OngoingOperationModule { @@ -81,7 +81,10 @@ pub trait BridgeProxyContract: } let gas_left = self.blockchain().get_gas_left(); - require!(gas_left > call_data.gas_limit + DEFAULT_GAS_LIMIT_FOR_REFUND_CALLBACK, "Not enough gas to execute"); + require!( + gas_left > call_data.gas_limit + DEFAULT_GAS_LIMIT_FOR_REFUND_CALLBACK, + "Not enough gas to execute" + ); let tx_call = self .tx() @@ -136,11 +139,14 @@ pub trait BridgeProxyContract: self.tx() .to(esdt_safe_contract_address) .typed(esdt_safe_proxy::EsdtSafeProxy) - .create_transaction(tx.from, OptionalValue::Some(esdt_safe_proxy::RefundInfo { - address: tx.to, - initial_batch_id: batch_id, - initial_nonce: tx.tx_nonce, - })) + .create_transaction( + tx.from, + OptionalValue::Some(esdt_safe_proxy::RefundInfo { + address: tx.to, + initial_batch_id: batch_id, + initial_nonce: tx.tx_nonce, + }), + ) .single_esdt( &unwrapped_token.token_identifier, unwrapped_token.token_nonce, @@ -159,7 +165,7 @@ pub trait BridgeProxyContract: let transfers = self .tx() - .to(&bridged_tokens_wrapper_address) + .to(&bridged_tokens_wrapper_address) .typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy) .unwrap_token(requested_token) .single_esdt( From be4c20662ed5a5c87946b7cfc2f41efeb9b37544 Mon Sep 17 00:00:00 2001 From: Eveline Molnar Date: Wed, 30 Oct 2024 09:12:04 +0200 Subject: [PATCH 12/12] fix tests --- .../tests/multi_transfer_blackbox_test.rs | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs index 58527b3b..b975c5a8 100644 --- a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs +++ b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs @@ -1,11 +1,7 @@ #![allow(unused)] -use bridge_proxy::{config::ProxyTrait as _, ProxyTrait as _}; -use bridged_tokens_wrapper::ProxyTrait as _; -use esdt_safe::{EsdtSafe, ProxyTrait as _, RefundInfo}; use esdt_safe_proxy::EsdtSafeProxyMethods; use multi_transfer_esdt::*; - use multiversx_sc::{ api::{HandleConstraints, ManagedTypeApi}, codec::{ @@ -119,7 +115,7 @@ impl MultiTransferTestState { .account(OWNER_ADDRESS) .nonce(1) .esdt_balance(BRIDGE_TOKEN_ID, 1001u64) - .esdt_balance(TOKEN_ID, MAX_AMOUNT) + .esdt_balance(TOKEN_TICKER, MAX_AMOUNT) .esdt_balance(WRAPPED_TOKEN_ID, 1001u64) .esdt_balance(TOKEN_ID, 1_000_000_000_000u64) .esdt_balance(NON_WHITELISTED_TOKEN, 1_000_000u64) @@ -268,8 +264,8 @@ impl MultiTransferTestState { .tx() .from(OWNER_ADDRESS) .to(MULTI_TRANSFER_ADDRESS) - .typed(multi_transfer_proxy::MultiTransferEsdtProxy) - .set_max_bridged_amount(TOKEN_ID, MAX_AMOUNT - 1) + .typed(multi_transfer_esdt_proxy::MultiTransferEsdtProxy) + .set_max_bridged_amount(TOKEN_TICKER, MAX_AMOUNT - 1) .run(); self.world @@ -591,7 +587,10 @@ impl MultiTransferTestState { expected_error: &str, ) { self.esdt_raw_transaction() - .create_transaction(EthAddress::zero(),OptionalValue::None::>) + .create_transaction( + EthAddress::zero(), + OptionalValue::None::>, + ) .egld_or_single_esdt( &EgldOrEsdtTokenIdentifier::esdt(token_id), 0, @@ -603,7 +602,10 @@ impl MultiTransferTestState { fn single_transaction_should_work(&mut self, token_id: TestTokenIdentifier, amount: u64) { self.esdt_raw_transaction() - .create_transaction(EthAddress::zero(), OptionalValue::None::>) + .create_transaction( + EthAddress::zero(), + OptionalValue::None::>, + ) .egld_or_single_esdt( &EgldOrEsdtTokenIdentifier::esdt(token_id), 0, @@ -1496,7 +1498,7 @@ fn test_unwrap_token_create_transaction_should_work() { BigUint::from(600000u64), BigUint::zero(), ); - + state .world .query() @@ -1558,7 +1560,7 @@ fn test_unwrap_token_create_transaction_should_fail() { .typed(bridged_tokens_wrapper_proxy::BridgedTokensWrapperProxy) .unwrap_token_create_transaction(WRAPPED_TOKEN_ID, EthAddress::zero()) .egld_or_single_esdt( - &EgldOrEsdtTokenIdentifier::esdt(TOKEN_ID), + &EgldOrEsdtTokenIdentifier::esdt(TOKEN_TICKER), 0u64, &BigUint::from(1_000u64), ) @@ -1594,7 +1596,7 @@ fn test_unwrap_token_create_transaction_amount_zero() { } #[test] -fn add_refund_batch_test() { +fn add_refund_batch_test_should_work() { let mut state = MultiTransferTestState::new(); state.multi_transfer_deploy(); @@ -1606,7 +1608,7 @@ fn add_refund_batch_test() { let eth_tx = EthTransaction { from: EthAddress::zero(), to: ManagedAddress::from(USER1_ADDRESS.eval_to_array()), - token_id: TokenIdentifier::from(TOKEN_ID), + token_id: TokenIdentifier::from(TOKEN_TICKER), amount: BigUint::from(MAX_AMOUNT), tx_nonce: 1u64, call_data: ManagedOption::none(), @@ -1621,12 +1623,12 @@ fn add_refund_batch_test() { .query() .to(ESDT_SAFE_ADDRESS) .typed(esdt_safe_proxy::EsdtSafeProxy) - .calculate_required_fee(TOKEN_ID) + .calculate_required_fee(TOKEN_TICKER) .returns(ReturnsResult) .run(); state.check_balances_on_safe( - TOKEN_ID, + TOKEN_TICKER, BigUint::from(MAX_AMOUNT), BigUint::zero(), BigUint::zero(), @@ -1637,22 +1639,27 @@ fn add_refund_batch_test() { .tx() .from(OWNER_ADDRESS) .to(MULTI_TRANSFER_ADDRESS) - .typed(multi_transfer_proxy::MultiTransferEsdtProxy) + .typed(multi_transfer_esdt_proxy::MultiTransferEsdtProxy) .batch_transfer_esdt_token(1u32, transfers) .run(); - state.check_balances_on_safe(TOKEN_ID, BigUint::zero(), BigUint::zero(), BigUint::zero()); + state.check_balances_on_safe( + TOKEN_TICKER, + BigUint::zero(), + BigUint::zero(), + BigUint::zero(), + ); state .world .tx() .from(OWNER_ADDRESS) .to(MULTI_TRANSFER_ADDRESS) - .typed(multi_transfer_proxy::MultiTransferEsdtProxy) + .typed(multi_transfer_esdt_proxy::MultiTransferEsdtProxy) .move_refund_batch_to_safe() .run(); state.check_balances_on_safe( - TOKEN_ID, + TOKEN_TICKER, BigUint::from(MAX_AMOUNT) - fee, BigUint::zero(), BigUint::zero(),