diff --git a/bridge-proxy/src/bridge-proxy.rs b/bridge-proxy/src/bridge-proxy.rs index e45f49ef..1fc6c2bd 100644 --- a/bridge-proxy/src/bridge-proxy.rs +++ b/bridge-proxy/src/bridge-proxy.rs @@ -8,9 +8,9 @@ pub mod config; use transaction::{EthTransaction, EthTransactionPayment}; #[multiversx_sc::contract] -pub trait BridgeProxyContract: - config::ConfigModule - + multiversx_sc_modules::pause::PauseModule { +pub trait BridgeProxyContract: + config::ConfigModule + multiversx_sc_modules::pause::PauseModule +{ #[init] fn init(&self, opt_multi_transfer_address: OptionalValue) { self.set_multi_transfer_contract_address(opt_multi_transfer_address); @@ -38,11 +38,17 @@ pub trait BridgeProxyContract: .unwrap_or_else(|| sc_panic!("Invalid ETH transaction!")); let tx = tx_node.get_value_as_ref(); + require!(tx.eth_tx.call_data.is_some(), "There is no data for a SC call!"); + + let call_data = unsafe { tx.eth_tx.call_data.clone().unwrap_unchecked() }; self.send() - .contract_call::(tx.eth_tx.to.clone(), tx.eth_tx.data.clone()) - .with_raw_arguments(tx.eth_tx.args.clone().into()) + .contract_call::( + tx.eth_tx.to.clone(), + call_data.endpoint.clone(), + ) + .with_raw_arguments(call_data.args.clone().into()) .with_esdt_transfer((tx.token_id.clone(), tx.nonce, tx.amount.clone())) - .with_gas_limit(tx.eth_tx.gas_limit) + .with_gas_limit(call_data.gas_limit) .async_call() .with_callback(self.callbacks().failed_execution_callback(tx)) .call_and_exit(); @@ -56,7 +62,7 @@ pub trait BridgeProxyContract: ) { if result.is_err() { self.eth_failed_transaction_list().push_back(tx.clone()); - } + } } #[endpoint(refundTransactions)] diff --git a/bridge-proxy/tests/bridge_proxy_blackbox_test.rs b/bridge-proxy/tests/bridge_proxy_blackbox_test.rs index c00ab5e4..d3d93981 100644 --- a/bridge-proxy/tests/bridge_proxy_blackbox_test.rs +++ b/bridge-proxy/tests/bridge_proxy_blackbox_test.rs @@ -27,7 +27,7 @@ use multiversx_sc_scenario::{ }; use eth_address::*; -use transaction::{EthTransaction, EthTransactionPayment}; +use transaction::{CallData, EthTransaction, EthTransactionPayment}; const BRIDGE_TOKEN_ID: &[u8] = b"BRIDGE-123456"; const GAS_LIMIT: u64 = 1_000_000; @@ -131,9 +131,11 @@ fn deploy_deposit_test() { token_id: TokenIdentifier::from_esdt_bytes(BRIDGE_TOKEN_ID), amount: BigUint::from(500u64), tx_nonce: 1u64, - data: ManagedBuffer::from(b"add"), - gas_limit: GAS_LIMIT, - args, + call_data: Some(CallData { + endpoint: ManagedBuffer::from(b"add"), + gas_limit: GAS_LIMIT, + args, + }), }; test.world.set_state_step(SetStateStep::new().put_account( @@ -188,9 +190,11 @@ fn multiple_deposit_test() { token_id: TokenIdentifier::from_esdt_bytes(BRIDGE_TOKEN_ID), amount: BigUint::from(500u64), tx_nonce: 1u64, - data: ManagedBuffer::from(b"add"), - gas_limit: GAS_LIMIT, - args: args1, + call_data: Some(CallData { + endpoint: ManagedBuffer::from(b"add"), + gas_limit: GAS_LIMIT, + args: args1, + }), }; let mut args2 = ManagedVec::new(); @@ -202,9 +206,11 @@ fn multiple_deposit_test() { token_id: TokenIdentifier::from_esdt_bytes(BRIDGE_TOKEN_ID), amount: BigUint::zero(), tx_nonce: 1u64, - data: ManagedBuffer::from(b"add"), - gas_limit: GAS_LIMIT, - args: args2, + call_data: Some(CallData { + endpoint: ManagedBuffer::from(b"add"), + gas_limit: GAS_LIMIT, + args: args2, + }), }; test.world.set_state_step(SetStateStep::new().put_account( diff --git a/bridge-proxy/wasm/src/lib.rs b/bridge-proxy/wasm/src/lib.rs index 13b818c8..c0ad78af 100644 --- a/bridge-proxy/wasm/src/lib.rs +++ b/bridge-proxy/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!(); diff --git a/common/transaction/src/lib.rs b/common/transaction/src/lib.rs index fcd9de72..11a6a501 100644 --- a/common/transaction/src/lib.rs +++ b/common/transaction/src/lib.rs @@ -4,8 +4,6 @@ multiversx_sc::imports!(); multiversx_sc::derive_imports!(); use eth_address::EthAddress; -use multiversx_sc::codec::{EncodeErrorHandler, NestedDecodeInput, TopEncodeOutput}; - pub mod transaction_status; // revert protection @@ -28,97 +26,39 @@ pub type PaymentsVec = ManagedVec>; pub type TxBatchSplitInFields = MultiValue2>>; #[derive(NestedEncode, NestedDecode, TypeAbi, Clone, ManagedVecItem)] -pub struct EthTransaction { - pub from: EthAddress, - pub to: ManagedAddress, - pub token_id: TokenIdentifier, - pub amount: BigUint, - pub tx_nonce: TxNonce, - pub data: ManagedBuffer, +pub struct CallData { + pub endpoint: ManagedBuffer, pub gas_limit: u64, pub args: ManagedVec>, } -impl TopEncode for EthTransaction { - fn top_encode_or_handle_err(&self, output: O, h: H) -> Result<(), H::HandledErr> - where - O: TopEncodeOutput, - H: EncodeErrorHandler, - { - let mut nested_buffer = output.start_nested_encode(); - self.from.dep_encode_or_handle_err(&mut nested_buffer, h)?; - self.to.dep_encode_or_handle_err(&mut nested_buffer, h)?; - self.token_id - .dep_encode_or_handle_err(&mut nested_buffer, h)?; - self.amount - .dep_encode_or_handle_err(&mut nested_buffer, h)?; - self.tx_nonce - .dep_encode_or_handle_err(&mut nested_buffer, h)?; - self.data.dep_encode_or_handle_err(&mut nested_buffer, h)?; - self.gas_limit - .dep_encode_or_handle_err(&mut nested_buffer, h)?; - for arg in &self.args { - arg.dep_encode_or_handle_err(&mut nested_buffer, h)?; +impl Default for CallData { + #[inline] + fn default() -> Self { + Self { + endpoint: ManagedBuffer::new(), + gas_limit: 0, + args: ManagedVec::new(), } - output.finalize_nested_encode(nested_buffer); - Result::Ok(()) } } - -impl TopDecode for EthTransaction { - fn top_decode_or_handle_err(input: I, h: H) -> Result - where - I: codec::TopDecodeInput, - H: codec::DecodeErrorHandler, - { - let mut nested_buffer = input.into_nested_buffer(); - let from = EthAddress::dep_decode_or_handle_err(&mut nested_buffer, h)?; - let to = ManagedAddress::dep_decode_or_handle_err(&mut nested_buffer, h)?; - let token_id = TokenIdentifier::dep_decode_or_handle_err(&mut nested_buffer, h)?; - let amount = BigUint::dep_decode_or_handle_err(&mut nested_buffer, h)?; - let tx_nonce = TxNonce::dep_decode_or_handle_err(&mut nested_buffer, h)?; - - let mut data = ManagedBuffer::new(); - let mut gas_limit = 0u64; - let mut args = ManagedVec::new(); - - if !nested_buffer.is_depleted() { - data = ManagedBuffer::dep_decode_or_handle_err(&mut nested_buffer, h)?; - gas_limit = u64::dep_decode_or_handle_err(&mut nested_buffer, h)?; - args = ManagedVec::new(); - - while !nested_buffer.is_depleted() { - args.push(ManagedBuffer::dep_decode_or_handle_err( - &mut nested_buffer, - h, - )?); - } - - } - - - Result::Ok(EthTransaction { - from, - to, - token_id, - amount, - tx_nonce, - data, - gas_limit, - args, - }) - } +#[derive(TopDecode, TopEncode, NestedEncode, NestedDecode, TypeAbi, Clone, ManagedVecItem)] +pub struct EthTransaction { + pub from: EthAddress, + pub to: ManagedAddress, + pub token_id: TokenIdentifier, + pub amount: BigUint, + pub tx_nonce: TxNonce, + pub call_data: Option>, } -pub type EthTxAsMultiValue = MultiValue8< +pub type EthTxAsMultiValue = MultiValue6< EthAddress, ManagedAddress, TokenIdentifier, BigUint, TxNonce, - ManagedBuffer, - u64, - ManagedVec>, + Option>, >; #[derive(TopEncode, TopDecode, NestedEncode, NestedDecode, TypeAbi, Clone)] diff --git a/multi-transfer-esdt/scenarios/batch_transfer_both_executed.scen.json b/multi-transfer-esdt/scenarios/batch_transfer_both_executed.scen.json index b4417975..b8368ec4 100644 --- a/multi-transfer-esdt/scenarios/batch_transfer_both_executed.scen.json +++ b/multi-transfer-esdt/scenarios/batch_transfer_both_executed.scen.json @@ -15,8 +15,8 @@ "function": "batchTransferEsdtToken", "arguments": [ "1", - "0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1|nested:str:data|u64:10000000", - "0x0102030405060708091011121314151617181920|address:user2|nested:str:WRAPPED-123456|biguint:500|u64:2|nested:str:data|u64:10000000" + "0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1|0x01|nested:str:data|u64:10000000|u32:0", + "0x0102030405060708091011121314151617181920|address:user2|nested:str:WRAPPED-123456|biguint:500|u64:2|0x01|nested:str:data|u64:10000000|u32:0" ], "gasLimit": "50,000,000", "gasPrice": "0" diff --git a/multi-transfer-esdt/scenarios/batch_transfer_both_failed.scen.json b/multi-transfer-esdt/scenarios/batch_transfer_both_failed.scen.json index 9b6d48e1..6b3b18f7 100644 --- a/multi-transfer-esdt/scenarios/batch_transfer_both_failed.scen.json +++ b/multi-transfer-esdt/scenarios/batch_transfer_both_failed.scen.json @@ -15,8 +15,8 @@ "function": "batchTransferEsdtToken", "arguments": [ "1", - "0x0102030405060708091011121314151617181920|sc:multi_transfer_esdt|nested:str:BRIDGE-123456|biguint:100,200|u64:1|nested:str:data|u64:2000000", - "0x0102030405060708091011121314151617181920|sc:multi_transfer_esdt|nested:str:WRAPPED-123456|biguint:100,500|u64:2|nested:str:data|u64:2000000" + "0x0102030405060708091011121314151617181920|sc:multi_transfer_esdt|nested:str:BRIDGE-123456|biguint:100,200|u64:1||0x0", + "0x0102030405060708091011121314151617181920|sc:multi_transfer_esdt|nested:str:WRAPPED-123456|biguint:100,500|u64:2||0x01|nested:str:data|u64:90|u32:0" ], "gasLimit": "50,000,000", "gasPrice": "0" diff --git a/multi-transfer-esdt/scenarios/batch_transfer_one_executed_one_failed.scen.json b/multi-transfer-esdt/scenarios/batch_transfer_one_executed_one_failed.scen.json index b6420639..2b080673 100644 --- a/multi-transfer-esdt/scenarios/batch_transfer_one_executed_one_failed.scen.json +++ b/multi-transfer-esdt/scenarios/batch_transfer_one_executed_one_failed.scen.json @@ -15,8 +15,8 @@ "function": "batchTransferEsdtToken", "arguments": [ "1", - "0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1|nested:str:data|u64:1000000", - "0x0102030405060708091011121314151617181920|sc:multi_transfer_esdt|nested:str:WRAPPED-123456|biguint:500|u64:2|nested:str:data|u64:1000000" + "0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1||0x01|nested:str:data|u64:10000000|u32:0", + "0x0102030405060708091011121314151617181920|sc:multi_transfer_esdt|nested:str:WRAPPED-123456|biguint:500|u64:2||0x0" ], "gasLimit": "50,000,000", "gasPrice": "0" diff --git a/multi-transfer-esdt/scenarios/batch_transfer_to_frozen_account.scen.json b/multi-transfer-esdt/scenarios/batch_transfer_to_frozen_account.scen.json index dcf91222..19a7f35f 100644 --- a/multi-transfer-esdt/scenarios/batch_transfer_to_frozen_account.scen.json +++ b/multi-transfer-esdt/scenarios/batch_transfer_to_frozen_account.scen.json @@ -35,8 +35,8 @@ "function": "batchTransferEsdtToken", "arguments": [ "1", - "0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1|nested:str:data|u64:10000000", - "0x0102030405060708091011121314151617181920|address:frozen_user|nested:str:BRIDGE-123456|biguint:500|u64:2|nested:str:data|u64:10000000" + "0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1||0x01|nested:str:data|u64:10000000|u32:0", + "0x0102030405060708091011121314151617181920|address:frozen_user|nested:str:BRIDGE-123456|biguint:500|u64:2||0x01|nested:str:data|u64:10000000|u32:0" ], "gasLimit": "50,000,000", "gasPrice": "0" diff --git a/multi-transfer-esdt/scenarios/batch_transfer_with_wrapping.scen.json b/multi-transfer-esdt/scenarios/batch_transfer_with_wrapping.scen.json index c08275c1..3f3e31de 100644 --- a/multi-transfer-esdt/scenarios/batch_transfer_with_wrapping.scen.json +++ b/multi-transfer-esdt/scenarios/batch_transfer_with_wrapping.scen.json @@ -284,9 +284,9 @@ "function": "batchTransferEsdtToken", "arguments": [ "1", - "0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1|nested:str:data|u64:2000000", - "0x0102030405060708091011121314151617181920|address:user2|nested:str:USDC-aaaaaa|biguint:500,000,000,000,000|u64:2|nested:str:data|u64:2000000", - "0x0102030405060708091011121314151617181920|address:user1|nested:str:USDC-cccccc|biguint:1,000,000,000,000,000|u64:3|nested:str:data|u64:2000000" + "0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1||0x01|nested:str:data|u64:10000000|u32:0", + "0x0102030405060708091011121314151617181920|address:user2|nested:str:USDC-aaaaaa|biguint:500,000,000,000,000|u64:2||0x01|nested:str:data|u64:10000000|u32:0", + "0x0102030405060708091011121314151617181920|address:user1|nested:str:USDC-cccccc|biguint:1,000,000,000,000,000|u64:3||0x01|nested:str:data|u64:10000000|u32:0" ], "gasLimit": "50,000,000", "gasPrice": "0" diff --git a/multi-transfer-esdt/scenarios/transfer_fail_mint_burn_not_allowed.scen.json b/multi-transfer-esdt/scenarios/transfer_fail_mint_burn_not_allowed.scen.json index 40b66ec5..be7aebf1 100644 --- a/multi-transfer-esdt/scenarios/transfer_fail_mint_burn_not_allowed.scen.json +++ b/multi-transfer-esdt/scenarios/transfer_fail_mint_burn_not_allowed.scen.json @@ -36,7 +36,7 @@ "function": "batchTransferEsdtToken", "arguments": [ "1", - "0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1|nested:str:data|u64:10000000" + "0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1||0x01|nested:str:data|u64:10000000|u32:0" ], "gasLimit": "50,000,000", "gasPrice": "0" diff --git a/multi-transfer-esdt/scenarios/transfer_ok.scen.json b/multi-transfer-esdt/scenarios/transfer_ok.scen.json index 4768ca5e..01630df1 100644 --- a/multi-transfer-esdt/scenarios/transfer_ok.scen.json +++ b/multi-transfer-esdt/scenarios/transfer_ok.scen.json @@ -15,7 +15,7 @@ "function": "batchTransferEsdtToken", "arguments": [ "1", - "0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1|nested:str:data|u64:10000000" + "0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1||0x01|nested:str:data|u64:10000000|u32:0" ], "gasLimit": "50,000,000", "gasPrice": "0" diff --git a/multi-transfer-esdt/scenarios/two_transfers_same_token.scen.json b/multi-transfer-esdt/scenarios/two_transfers_same_token.scen.json index 02d29c99..01d65316 100644 --- a/multi-transfer-esdt/scenarios/two_transfers_same_token.scen.json +++ b/multi-transfer-esdt/scenarios/two_transfers_same_token.scen.json @@ -15,8 +15,8 @@ "function": "batchTransferEsdtToken", "arguments": [ "1", - "0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1|nested:str:data|u64:10000000", - "0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:2|nested:str:data|u64:10000000" + "0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1||0x01|nested:str:data|u64:10000000|u32:0", + "0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:2||0x01|nested:str:data|u64:10000000|u32:0" ], "gasLimit": "50,000,000", "gasPrice": "0" diff --git a/multi-transfer-esdt/src/lib.rs b/multi-transfer-esdt/src/lib.rs index 5b362caf..9d887a3a 100644 --- a/multi-transfer-esdt/src/lib.rs +++ b/multi-transfer-esdt/src/lib.rs @@ -53,6 +53,7 @@ pub trait MultiTransferEsdt: for eth_tx in transfers { let mut must_refund = false; + if eth_tx.to.is_zero() { self.transfer_failed_invalid_destination(batch_id, eth_tx.tx_nonce); must_refund = true; @@ -63,9 +64,15 @@ pub trait MultiTransferEsdt: self.transfer_failed_frozen_destination_account(batch_id, eth_tx.tx_nonce); must_refund = true; } else if self.blockchain().is_smart_contract(ð_tx.to) - && (eth_tx.data.is_empty() || eth_tx.gas_limit < MIN_GAS_LIMIT_FOR_SC_CALL) { - must_refund = true; + match ð_tx.call_data { + Some(call_data) => { + if call_data.gas_limit < MIN_GAS_LIMIT_FOR_SC_CALL { + must_refund = true; + } + } + None => must_refund = true, + } } if must_refund { diff --git a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs index 553f5ed8..3d445c3d 100644 --- a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs +++ b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs @@ -27,7 +27,7 @@ use multiversx_sc_scenario::{ use eth_address::*; use token_module::ProxyTrait as _; -use transaction::{EthTransaction, EthTransactionPayment}; +use transaction::{CallData, EthTransaction, EthTransactionPayment}; const BRIDGE_TOKEN_ID: &[u8] = b"BRIDGE-123456"; const BRIDGE_TOKEN_ID_EXPR: &str = "str:BRIDGE-123456"; @@ -277,9 +277,11 @@ fn basic_setup_test() { token_id: TokenIdentifier::from_esdt_bytes(BRIDGE_TOKEN_ID), amount: BigUint::from(500u64), tx_nonce: 1u64, - data: ManagedBuffer::from("data"), - gas_limit: GAS_LIMIT, - args: ManagedVec::new(), + call_data: Some(CallData { + endpoint: ManagedBuffer::from("data"), + gas_limit: GAS_LIMIT, + args: ManagedVec::new(), + }), }; test.world.check_state_step( @@ -314,9 +316,11 @@ fn basic_transfer_test() { token_id: TokenIdentifier::from_esdt_bytes(BRIDGE_TOKEN_ID), amount: token_amount.clone(), tx_nonce: 1u64, - data: ManagedBuffer::from("data"), - gas_limit: GAS_LIMIT, - args: ManagedVec::new(), + call_data: Some(CallData { + endpoint: ManagedBuffer::from("data"), + gas_limit: GAS_LIMIT, + args: ManagedVec::new(), + }), }; test.world.check_state_step( diff --git a/multi-transfer-esdt/wasm/Cargo1.lock b/multi-transfer-esdt/wasm/Cargo1.lock new file mode 100644 index 00000000..582d24db --- /dev/null +++ b/multi-transfer-esdt/wasm/Cargo1.lock @@ -0,0 +1,446 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "adder" +version = "0.0.0" +source = "git+https://github.com/multiversx/mx-contracts-rs?rev=64e8926#64e892655f9c59b2aafe07800af61d0fa41c6ddc" +dependencies = [ + "multiversx-sc", +] + +[[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 = "2.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" + +[[package]] +name = "bridge-proxy" +version = "0.0.0" +dependencies = [ + "adder", + "eth-address", + "multiversx-sc", + "transaction", +] + +[[package]] +name = "bridged-tokens-wrapper" +version = "0.0.0" +dependencies = [ + "multiversx-sc", + "multiversx-sc-modules", + "transaction", +] + +[[package]] +name = "bumpalo" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" + +[[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 = "esdt-safe" +version = "0.0.0" +dependencies = [ + "eth-address", + "fee-estimator-module", + "max-bridged-amount-module", + "multiversx-price-aggregator-sc", + "multiversx-sc", + "multiversx-sc-modules", + "token-module", + "transaction", + "tx-batch-module", +] + +[[package]] +name = "eth-address" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "fee-estimator-module" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "getrandom" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[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 = "js-sys" +version = "0.3.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "max-bridged-amount-module" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "multi-transfer-esdt" +version = "0.0.0" +dependencies = [ + "bridge-proxy", + "bridged-tokens-wrapper", + "esdt-safe", + "eth-address", + "max-bridged-amount-module", + "multiversx-sc", + "multiversx-sc-modules", + "token-module", + "transaction", + "tx-batch-module", +] + +[[package]] +name = "multi-transfer-esdt-wasm" +version = "0.0.0" +dependencies = [ + "multi-transfer-esdt", + "multiversx-sc-wasm-adapter", +] + +[[package]] +name = "multiversx-price-aggregator-sc" +version = "0.46.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8de03c6796bd16c39cafafd13da688d9f64d30965866d1c0d0badd2071235f9" +dependencies = [ + "arrayvec", + "getrandom", + "multiversx-sc", + "multiversx-sc-modules", + "rand", +] + +[[package]] +name = "multiversx-sc" +version = "0.46.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c94b173dc5ff0e157f767275fe6b7a1b4d2ad343bef7b66cd22a6353e016b93" +dependencies = [ + "bitflags", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.18.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19908153158c03df4582af08f47c0eb39fb52a7dff4736b301a66acbbb9955d3" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.18.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3b03b43f9cad320992f54ed162de2ed63e3ec83ed01361e57ee9c1865fba5a2" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.46.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b78945957036c281ad6ee21bb5120dcefa2017688adf43ec94e3e7c982efb09" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn", +] + +[[package]] +name = "multiversx-sc-modules" +version = "0.46.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c63ffaba95e630ff75981e2f5f50da64f523219b52f484234c66f3adc248885f" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.46.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9579f40c00da56a5a68e010ff851fa48ac7b9c6a16ad4314795cb32d889d9e78" +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.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro2" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radix_trie" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" +dependencies = [ + "endian-type", + "nibble_vec", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "smallvec" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" + +[[package]] +name = "syn" +version = "2.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "token-module" +version = "0.0.0" +dependencies = [ + "fee-estimator-module", + "multiversx-sc", +] + +[[package]] +name = "transaction" +version = "0.0.0" +dependencies = [ + "eth-address", + "multiversx-sc", +] + +[[package]] +name = "tx-batch-module" +version = "0.0.0" +dependencies = [ + "multiversx-sc", + "transaction", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" diff --git a/multisig/scenarios/ethereum_to_multiversx_tx_batch_ok.scen.json b/multisig/scenarios/ethereum_to_multiversx_tx_batch_ok.scen.json index 81310661..b3e63255 100644 --- a/multisig/scenarios/ethereum_to_multiversx_tx_batch_ok.scen.json +++ b/multisig/scenarios/ethereum_to_multiversx_tx_batch_ok.scen.json @@ -15,8 +15,8 @@ "function": "proposeMultiTransferEsdtBatch", "arguments": [ "1", - "0x0102030405060708091011121314151617181920", "address:user", "str:WEGLD-123456", "76,000,000,000", "1", "str:data", "u64:20000000", "0", - "0x0102030405060708091011121314151617181920", "address:user", "str:ETH-123456", "76,000,000,000", "2", "str:data", "u64:20000000", "0" + "0x0102030405060708091011121314151617181920", "address:user", "str:WEGLD-123456", "76,000,000,000", "1", "0x01|nested:str:data|u64:20000000|u32:0", + "0x0102030405060708091011121314151617181920", "address:user", "str:ETH-123456", "76,000,000,000", "2", "0x01|nested:str:data|u64:20000000|u32:0" ], "gasLimit": "50,000,000", "gasPrice": "0" @@ -49,9 +49,7 @@ "3-token_id": "nested:str:WEGLD-123456", "4-amount": "biguint:76,000,000,000", "5-tx_nonce": "u64:1", - "6-data": "nested:str:data", - "7-gas_limit": "u64:20000000", - "8-args": "nested:0" + "6-call_data": "0x01|nested:str:data|u64:20000000|u32:0" }, { "1-from": "0x0102030405060708091011121314151617181920", @@ -59,9 +57,7 @@ "3-token_id": "nested:str:ETH-123456", "4-amount": "biguint:76,000,000,000", "5-tx_nonce": "u64:2", - "6-data": "nested:str:data", - "7-gas_limit": "u64:20000000", - "8-args": "nested:0" + "6-call_data": "0x01|nested:str:data|u64:20000000|u32:0" } ] }, diff --git a/multisig/scenarios/ethereum_to_multiversx_tx_batch_rejected.scen.json b/multisig/scenarios/ethereum_to_multiversx_tx_batch_rejected.scen.json index 1c1076c6..742b3511 100644 --- a/multisig/scenarios/ethereum_to_multiversx_tx_batch_rejected.scen.json +++ b/multisig/scenarios/ethereum_to_multiversx_tx_batch_rejected.scen.json @@ -20,17 +20,13 @@ "str:WEGLD-123456", "76,000,000,000", "str:data", - "u64:2,000,000", - "u64:1", - "0", + "0x01|nested:str:data|u64:2,000,000|u32:0", "0x0102030405060708091011121314151617181920", "sc:egld_esdt_swap", "str:ETH-123456", "76,000,000,000", "u64:2", - "str:data", - "u64:2,000,000", - "0" + "0x01|nested:str:data|u64:2,000,000|u32:0" ], "gasLimit": "50,000,000", "gasPrice": "0" @@ -58,17 +54,13 @@ "str:WEGLD-123456", "76,000,000,000", "u64:2", - "str:data", - "u64:2,000,000", - "0", + "0x01|nested:str:data|u64:2,000,000|u32:0", "0x0102030405060708091011121314151617181920", "sc:egld_esdt_swap", "str:ETH-123456", "76,000,000,000", "u64:3", - "str:data", - "u64:2,000,000", - "0" + "0x01|nested:str:data|u64:2,000,000|u32:0" ], "gasLimit": "50,000,000", "gasPrice": "0" @@ -96,17 +88,13 @@ "str:WEGLD-123456", "76,000,000,000", "u64:1", - "str:data", - "u64:2,000,000", - "0", + "0x01|nested:str:data|u64:2,000,000|u32:0", "0x0102030405060708091011121314151617181920", "sc:egld_esdt_swap", "str:ETH-123456", "76,000,000,000", "u64:2", - "str:data", - "u64:2,000,000", - "0" + "0x01|nested:str:data|u64:2,000,000|u32:0" ], "gasLimit": "50,000,000", "gasPrice": "0" @@ -139,9 +127,7 @@ "3-token_id": "nested:str:WEGLD-123456", "4-amount": "biguint:76,000,000,000", "5-tx_id": "u64:1", - "6-data": "nested:str:data", - "7-gas_limit": "u64:2,000,000", - "8-args": "nested:0" + "6-call_data": "0x01|nested:str:data|u64:2,000,000|u32:0" }, { "1-from": "0x0102030405060708091011121314151617181920", @@ -149,9 +135,7 @@ "3-token_id": "nested:str:ETH-123456", "4-amount": "biguint:76,000,000,000", "5-tx_id": "u64:2", - "6-data": "nested:str:data", - "7-gas_limit": "u64:2,000,000", - "8-args": "nested:0" + "6-call_data": "0x01|nested:str:data|u64:2,000,000|u32:0" } ] }, diff --git a/multisig/scenarios/ethereum_to_multiversx_tx_batch_without_data.scen.json b/multisig/scenarios/ethereum_to_multiversx_tx_batch_without_data.scen.json new file mode 100644 index 00000000..beefca1a --- /dev/null +++ b/multisig/scenarios/ethereum_to_multiversx_tx_batch_without_data.scen.json @@ -0,0 +1,73 @@ +{ + "name": "create ethereum to MultiversX tx batch", + "steps": [ + { + "step": "externalSteps", + "path": "setup.scen.json" + }, + { + "step": "scCall", + "txId": "propose-transfer-ok", + "tx": { + "from": "address:relayer1", + "to": "sc:multisig", + "value": "0", + "function": "proposeMultiTransferEsdtBatch", + "arguments": [ + "1", + "0x0102030405060708091011121314151617181920", + "address:user", + "str:WEGLD-123456", + "76,000,000,000", + "1", + "0x", + "0x0102030405060708091011121314151617181920", + "address:user", + "str:ETH-123456", + "76,000,000,000", + "2", + "0x" + ], + "gasLimit": "50,000,000", + "gasPrice": "0" + }, + "expect": { + "status": "0", + "message": "", + "out": [ + "1" + ], + "gas": "*", + "refund": "*" + } + }, + { + "step": "scQuery", + "txId": "get-current-tx-batch", + "tx": { + "to": "sc:multisig", + "function": "wasTransferActionProposed", + "arguments": [ + "1", + "0x0102030405060708091011121314151617181920", + "address:user", + "str:WEGLD-123456", + "76,000,000,000", + "1", + "0x", + "0x0102030405060708091011121314151617181920", + "address:user", + "str:ETH-123456", + "76,000,000,000", + "2", + "0x" + ] + }, + "expect": { + "out": [ + "1" + ] + } + } + ] +} \ No newline at end of file diff --git a/multisig/scenarios/execute_multiversx_to_ethereum_tx_batch.scen.json b/multisig/scenarios/execute_multiversx_to_ethereum_tx_batch.scen.json index 6a7acfa9..acffeca5 100644 --- a/multisig/scenarios/execute_multiversx_to_ethereum_tx_batch.scen.json +++ b/multisig/scenarios/execute_multiversx_to_ethereum_tx_batch.scen.json @@ -51,6 +51,7 @@ "+": {} } }, + { "step": "scCall", "txId": "second-relayer-sign", diff --git a/multisig/src/queries.rs b/multisig/src/queries.rs index dc5c15ad..9d0e120d 100644 --- a/multisig/src/queries.rs +++ b/multisig/src/queries.rs @@ -55,7 +55,7 @@ pub trait QueriesModule: crate::storage::StorageModule + crate::util::UtilModule self.is_valid_action_id(action_id) } - /// Used for Ethereum -> Elrond batches. + /// Used for Ethereum -> MultiversX batches. /// If `wasActionExecuted` returns true, then this can be used to get the action ID. /// Will return 0 if the transfers were not proposed #[view(getActionIdForTransferBatch)] @@ -72,7 +72,7 @@ pub trait QueriesModule: crate::storage::StorageModule + crate::util::UtilModule .unwrap_or(0) } - /// Used for Elrond -> Ethereum batches. + /// Used for MultiversX -> Ethereum batches. /// Returns "true" if an action was already proposed for the given batch, /// with these exact transaction statuses, in this exact order #[view(wasSetCurrentTransactionBatchStatusActionProposed)] diff --git a/multisig/src/util.rs b/multisig/src/util.rs index f44eba1d..eb3dd6ba 100644 --- a/multisig/src/util.rs +++ b/multisig/src/util.rs @@ -49,8 +49,7 @@ pub trait UtilModule: crate::storage::StorageModule { ) -> ManagedVec> { let mut transfers_as_eth_tx = ManagedVec::new(); for transfer in transfers { - let (from, to, token_id, amount, tx_nonce, data, gas_limit, args) = - transfer.into_tuple(); + let (from, to, token_id, amount, tx_nonce, call_data) = transfer.into_tuple(); transfers_as_eth_tx.push(EthTransaction { from, @@ -58,9 +57,7 @@ pub trait UtilModule: crate::storage::StorageModule { token_id, amount, tx_nonce, - data, - gas_limit, - args, + call_data, }); } diff --git a/multisig/tests/multisig_scenario_rs_test.rs b/multisig/tests/multisig_scenario_rs_test.rs index 0a950c5a..41227f9d 100644 --- a/multisig/tests/multisig_scenario_rs_test.rs +++ b/multisig/tests/multisig_scenario_rs_test.rs @@ -41,6 +41,11 @@ fn ethereum_to_multiversx_tx_batch_rejected_rs() { world().run("scenarios/ethereum_to_multiversx_tx_batch_rejected.scen.json"); } +#[test] +fn ethereum_to_multiversx_tx_batch_without_data_rs() { + world().run("scenarios/ethereum_to_multiversx_tx_batch_without_data.scen.json"); +} + #[test] fn execute_multiversx_to_ethereum_tx_batch_rs() { world().run("scenarios/execute_multiversx_to_ethereum_tx_batch.scen.json");