From 882313facd49824875460292f3a0372a0e8b3dd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Tue, 10 Oct 2023 09:51:36 +0300 Subject: [PATCH 01/10] Paymaster Add test - async call fails --- contracts/paymaster/Cargo.toml | 3 + contracts/paymaster/src/forward_call.rs | 13 ++- .../tests/paymaster_blackbox_test.rs | 81 ++++++++++++++++-- .../multiversx-wegld-swap-sc.wasm | Bin 0 -> 4382 bytes 4 files changed, 86 insertions(+), 11 deletions(-) create mode 100755 contracts/paymaster/tests/test-contracts/multiversx-wegld-swap-sc.wasm diff --git a/contracts/paymaster/Cargo.toml b/contracts/paymaster/Cargo.toml index 0db9c936..0fd30492 100644 --- a/contracts/paymaster/Cargo.toml +++ b/contracts/paymaster/Cargo.toml @@ -21,3 +21,6 @@ version = "0.43.4" [dev-dependencies.adder] path = "../adder" + +[dev-dependencies.multiversx-wegld-swap-sc] +path = "../wegld-swap" diff --git a/contracts/paymaster/src/forward_call.rs b/contracts/paymaster/src/forward_call.rs index 5c29b644..54fb432a 100644 --- a/contracts/paymaster/src/forward_call.rs +++ b/contracts/paymaster/src/forward_call.rs @@ -23,7 +23,7 @@ pub trait ForwardCall { .with_callback(self.callbacks().transfer_callback(original_caller)) .call_and_exit(); } - + #[callback] fn transfer_callback( &self, @@ -33,8 +33,17 @@ pub trait ForwardCall { let initial_payments = self.call_value().all_esdt_transfers(); match result { - ManagedAsyncCallResult::Ok(return_values) => return_values, + ManagedAsyncCallResult::Ok(return_values) => { + // Send the resulted tokens to the original caller + if !initial_payments.is_empty() { + self.send() + .direct_multi(&original_caller, &initial_payments); + } + + return_values + } ManagedAsyncCallResult::Err(err) => { + // Send the original input tokens back to the original caller if !initial_payments.is_empty() { self.send() .direct_multi(&original_caller, &initial_payments); diff --git a/contracts/paymaster/tests/paymaster_blackbox_test.rs b/contracts/paymaster/tests/paymaster_blackbox_test.rs index 65b3f0b6..d259fc61 100644 --- a/contracts/paymaster/tests/paymaster_blackbox_test.rs +++ b/contracts/paymaster/tests/paymaster_blackbox_test.rs @@ -1,7 +1,7 @@ use multiversx_sc::{ codec::{multi_types::MultiValueVec, top_encode_to_vec_u8_or_panic}, storage::mappers::SingleValue, - types::{Address, BigUint}, + types::{Address, BigUint, MultiValueEncoded}, }; use multiversx_sc_scenario::{ api::StaticApi, @@ -13,28 +13,34 @@ use multiversx_sc_scenario::{ }; use adder::ProxyTrait as _; +use multiversx_wegld_swap_sc::ProxyTrait as _; use paymaster::ProxyTrait as _; const PAYMASTER_ADDRESS_EXPR: &str = "sc:paymaster"; const RELAYER_ADDRESS_EXPR: &str = "address:relayer"; const CALLEE_SC_ADDER_ADDRESS_EXPR: &str = "sc:adder"; +const CALLEE_SC_WEGLD_ADDRESS_EXPR: &str = "sc:wegld"; const PAYMASTER_PATH_EXPR: &str = "file:output/paymaster.wasm"; const ADDER_PATH_EXPR: &str = "file:tests/test-contracts/adder.wasm"; +const WEGLD_PATH_EXPR: &str = "file:tests/test-contracts/multiversx-wegld-swap-sc.wasm.wasm"; const CALLER_ADDRESS_EXPR: &str = "address:caller"; const CALLEE_USER_ADDRESS_EXPR: &str = "address:callee_user"; const OWNER_ADDRESS_EXPR: &str = "address:owner"; const BALANCE: &str = "100,000,000"; const PAYMASTER_TOKEN_ID_EXPR: &str = "str:PAYMSTR-123456"; +const WEGLD_TOKEN_ID_EXPR: &str = "str:WEGLD-123456"; +const WEGLD_TOKEN_ID: &[u8] = b"WEGLD-123456"; const FEE_TOKEN_ID_EXPR: &str = "str:FEE-123456"; const ADDITIONAL_TOKEN_ID_EXPR: &str = "str:ADDIT-123456"; const FEE_AMOUNT: &str = "20,000"; const INITIAL_ADD_VALUE: u64 = 5; const ADDITIONAL_ADD_VALUE: u64 = 5; - - +const UNWRAP_ENDPOINT_NAME: &[u8] = b"unwrap"; type PaymasterContract = ContractInfo>; type AdderContract = ContractInfo>; +type WegldContract = ContractInfo>; + fn world() -> ScenarioWorld { let mut blockchain = ScenarioWorld::new(); @@ -42,6 +48,7 @@ fn world() -> ScenarioWorld { blockchain.register_contract(PAYMASTER_PATH_EXPR, paymaster::ContractBuilder); blockchain.register_contract(ADDER_PATH_EXPR, adder::ContractBuilder); + blockchain.register_contract(WEGLD_PATH_EXPR, multiversx_wegld_swap_sc::ContractBuilder); blockchain } @@ -52,6 +59,7 @@ struct PaymasterTestState { paymaster_contract: PaymasterContract, relayer_address: Address, callee_sc_adder_contract: AdderContract, + callee_sc_wegld_address: WegldContract, } impl PaymasterTestState { @@ -66,6 +74,7 @@ impl PaymasterTestState { .nonce(1) .balance(BALANCE) .esdt_balance(PAYMASTER_TOKEN_ID_EXPR, BALANCE) + .esdt_balance(WEGLD_TOKEN_ID_EXPR, BALANCE) .esdt_balance(FEE_TOKEN_ID_EXPR, BALANCE) .esdt_balance(ADDITIONAL_TOKEN_ID_EXPR, BALANCE), ) @@ -81,7 +90,7 @@ impl PaymasterTestState { let relayer_address = AddressValue::from(RELAYER_ADDRESS_EXPR).to_address(); let paymaster_contract = PaymasterContract::new(PAYMASTER_ADDRESS_EXPR); let callee_sc_adder_contract = AdderContract::new(CALLEE_SC_ADDER_ADDRESS_EXPR); - // let callee_sc_adder_address = AddressValue::from(CALLEE_SC_ADDER_ADDRESS_EXPR).to_address(); + let callee_sc_wegld_address = WegldContract::new(CALLEE_SC_WEGLD_ADDRESS_EXPR); Self { world, @@ -89,6 +98,7 @@ impl PaymasterTestState { paymaster_contract, relayer_address, callee_sc_adder_contract, + callee_sc_wegld_address, } } @@ -130,6 +140,25 @@ impl PaymasterTestState { self } + fn deploy_wegld_contract(&mut self) -> &mut Self { + let wegld_code = self.world.code_expression(WEGLD_PATH_EXPR); + + self.world + .set_state_step(SetStateStep::new().new_address( + OWNER_ADDRESS_EXPR, + 3, + CALLEE_SC_WEGLD_ADDRESS_EXPR, + )) + .sc_deploy( + ScDeployStep::new() + .from(OWNER_ADDRESS_EXPR) + .code(wegld_code) + .call(self.callee_sc_wegld_address.init(WEGLD_TOKEN_ID)), + ); + + self + } + fn check_esdt_balance( &mut self, address_expr: &str, @@ -151,6 +180,7 @@ fn test_deploy_paymasters() { let mut state = PaymasterTestState::new(); state.deploy_paymaster_contract(); state.deploy_adder_contract(); + state.deploy_wegld_contract(); } #[test] @@ -164,7 +194,7 @@ fn test_forward_call_no_fee_payment() { .call(state.paymaster_contract.forward_execution( state.relayer_address.clone(), state.callee_user_address.clone(), - b"add" , + b"add", MultiValueVec::>::new(), )) .expect(TxExpect::user_error("str:There is no fee for payment!")), @@ -187,7 +217,7 @@ fn test_forward_call_user() { b"add", MultiValueVec::>::new(), )) - .esdt_transfer(FEE_TOKEN_ID_EXPR, 0, FEE_AMOUNT) + .esdt_transfer(FEE_TOKEN_ID_EXPR, 0, FEE_AMOUNT), ) .check_state_step(CheckStateStep::new().put_account( RELAYER_ADDRESS_EXPR, @@ -214,7 +244,7 @@ fn test_forward_call_sc_adder() { state.callee_sc_adder_contract.to_address(), b"add", MultiValueVec::from([top_encode_to_vec_u8_or_panic(&ADDITIONAL_ADD_VALUE)]), - )) + )), ); let expected_adder_sum = INITIAL_ADD_VALUE + ADDITIONAL_ADD_VALUE; @@ -231,7 +261,6 @@ fn test_forward_call_sc_adder() { ); } - #[test] fn test_forward_call_sc_adder_multiple_payments() { let mut state = PaymasterTestState::new(); @@ -252,7 +281,7 @@ fn test_forward_call_sc_adder_multiple_payments() { state.callee_sc_adder_contract.to_address(), b"add", MultiValueVec::from([top_encode_to_vec_u8_or_panic(&ADDITIONAL_ADD_VALUE)]), - )) + )), ); let expected_adder_sum = INITIAL_ADD_VALUE + ADDITIONAL_ADD_VALUE; @@ -273,3 +302,37 @@ fn test_forward_call_sc_adder_multiple_payments() { FEE_AMOUNT, ); } + +#[test] +fn test_forward_call_fails_wegld() { + let mut state = PaymasterTestState::new(); + state.deploy_paymaster_contract(); + state.deploy_adder_contract(); + + state.check_esdt_balance(CALLER_ADDRESS_EXPR, FEE_TOKEN_ID_EXPR, BALANCE); + state.check_esdt_balance(CALLER_ADDRESS_EXPR, WEGLD_TOKEN_ID_EXPR, BALANCE); + + let failling_amount = 0u64; + + // Call fails because unwrap amount is 0 + state.world.sc_call( + ScCallStep::new() + .from(CALLER_ADDRESS_EXPR) + .esdt_transfer(FEE_TOKEN_ID_EXPR, 0, FEE_AMOUNT) + .esdt_transfer(WEGLD_TOKEN_ID_EXPR, 0, failling_amount) + .call(state.paymaster_contract.forward_execution( + state.relayer_address.clone(), + state.callee_sc_wegld_address.to_address(), + UNWRAP_ENDPOINT_NAME, + MultiValueEncoded::new(), + )) + ); + + // Fee is kept by the relayer + let new_fee_amount: &str = "99980000"; + state.check_esdt_balance(RELAYER_ADDRESS_EXPR, FEE_TOKEN_ID_EXPR, FEE_AMOUNT); + state.check_esdt_balance(CALLER_ADDRESS_EXPR, FEE_TOKEN_ID_EXPR, new_fee_amount); + + // Caller has the original balance + state.check_esdt_balance(CALLER_ADDRESS_EXPR, WEGLD_TOKEN_ID_EXPR, BALANCE); +} diff --git a/contracts/paymaster/tests/test-contracts/multiversx-wegld-swap-sc.wasm b/contracts/paymaster/tests/test-contracts/multiversx-wegld-swap-sc.wasm new file mode 100755 index 0000000000000000000000000000000000000000..8ba9f452f1d2a6fb18068f1445bc8f3880bbc0a1 GIT binary patch literal 4382 zcmai1&5s*N6@S&;w%gP8OeK?qiIatDXR=JlCTx~43A0~QP9`CnWD=3Ua+`GQj^nRx zkKN9PgyMljQ7%ZVv?o|NAS5^hkv{;fR)_-<(n>+%#)TUf5J!X%;rFWBp2sB~e5ATx0f^sI%{eBoVNEkJlY;7}rmc1YfnqlMG8E77a z!y#E_S!#_{dHj4JTefyDtdElLN^~|HCTHR(3GXFT;uUlCZWu)03X{#>%_5a2mgd=gbOL)hA$S{Fws-83PouE4k(`3wG%lTkGjjVC(N3dGQPcJXiw^U zYG;}OgXf-M580{{|QbMFp<{#vu!pmQ^$ zX!>w|4-mc-*E?Z@Cns6`=3a>3$Bup~zaDqO=t6@o- zTSvIHpx&X&GaDNXl-UL<+ZNu&#_cfZZ`=%qp>56lbnnr9LX73%s;H49CGbZQ-`;+R z^)DW}{J&(87M&_BTcpT4PSz@xS(lwvWhv)!S;#Mw$N!2T5S?Yq!AK~(jSXIoRc}7?Lw^XINJ`A4fdWo=wwnXp-m!!o zyV4z&QGxZ=BzULdtz%BnF>-ut*0e&71)QB#{mFCAKvn1uKBX&VOmaS+J#>NJY=vhv zXGZ^?2P*^@Oft$q6?r8&&u%>xmNga+c0f?0Q?`pGr?6xflov0Ud|KLVYgYXYc0yT8 zmQyu9a6rygtTBYNR;G%*st7xn89q{Zf=Jml_wgg&285#RixRSo2<)2pE`q@9FR`?2 zRUp?t`@XAp%N6pp@G@+X!ha)Mvn+jcnk@&}a@Zy8H+*t2@vYG;YO1k7Yi01;Cryk)I&QjjDL9lIU< zqfcp)A-i)C>9OFct(-RSdV7i?14+P-m$JK5vOFaqgO;xY5dgkCeV#z#JrGvruf0gd zH1h*!?l9_flyw1S;dfg(T#;>L^lfDW9sVjA*xoUQnI~+R8Dzw>oDI0Jyi?>smtp(6 z(=@<*YJiad_1FRVs!?xJ!Nzu^BHRDW68SOg*eFINfb`r&!x#kJ(e`FF*Y+KigUIrQ z4LliGW^hIz<`!a6&V@309%8dqt^+OK+pOl>KJY-WxppsipwXN)f2Ce7-Y8G+R z8aRNa;}aJX`DCxA?9lFcm_##cD{8}9)mkfC%KAhXMi5j<7tuga-qd0HW+9L)Ii_Q9 zpEgcGLSEX=>!LT>a(R`kd>Rdr?!=hInv%6H@mv;#+ejn63gx;&tN zh;~z!C(#>@;uJaI7x3@mKZjLIz(>eM(5!rE>W=#<%!VP%a1QGx-V*G~3; z9>gt8^1+frS_{gR2Z6F&RD=eLM$V}d94a?;fs&ZEd2G$<4=|udn-+p5ot;7N$P-M7 z^guf4En5pF&0@Gh2SHxa3*499G*O}b3*!lD%9U@)H{bzgmaGLIaz2UU?_?Bp*A!|DI9w)FTB54ZkPcvxF7(ygt3%{}C!j3?YDT!9c^yuf3uWBC%s z*pAWZCyyRILUZA6jtWEiX`3WSbVd@);56}pIePNvud`9sAfl;oQ=R(9K(xw;a;XE6 z;#Gv>GPkRaJOY{{MPNIQA6b)MLXDMeP#*0Qlm{;jijr1Tj|YRWo~UTl zyBQ8td`s~Hl}xTSw?cCj3`qW&mR zNgS&#Rt(cSoN9#ixDl$5uhlCmT@zy+jKgd**>tUpYEP|d^@-UYf(IE-d2dGfmeNVp;J9pb2Hqjh3^zEUl)uA z8@;$O>V_++J5bVW-Ry=LR_u`q@AZKrE*epz9|Kxdhf{IXz0U^tN)a~H&HF0m3po+> bgQ!(kalJkQ{te>0f>-*8`|*nxWB&giSN+Ut literal 0 HcmV?d00001 From fa1eecd74e6006c143810729301e741f0049aeb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Tue, 10 Oct 2023 09:57:32 +0300 Subject: [PATCH 02/10] Paymaster: Minor fixes after audit --- contracts/paymaster/src/forward_call.rs | 2 -- contracts/paymaster/src/paymaster.rs | 1 - 2 files changed, 3 deletions(-) diff --git a/contracts/paymaster/src/forward_call.rs b/contracts/paymaster/src/forward_call.rs index 54fb432a..72a149db 100644 --- a/contracts/paymaster/src/forward_call.rs +++ b/contracts/paymaster/src/forward_call.rs @@ -53,8 +53,6 @@ pub trait ForwardCall { err_result.push(ManagedBuffer::new_from_bytes(ERR_CALLBACK_MSG)); err_result.push(err.err_msg.clone()); - sc_print!("{}", err.err_msg); - err_result } } diff --git a/contracts/paymaster/src/paymaster.rs b/contracts/paymaster/src/paymaster.rs index e989f204..a5527945 100644 --- a/contracts/paymaster/src/paymaster.rs +++ b/contracts/paymaster/src/paymaster.rs @@ -5,7 +5,6 @@ multiversx_sc::imports!(); pub mod forward_call; const FEE_PAYMENT: usize = 0; -/// An empty contract. To be used as a template when starting a new contract from scratch. #[multiversx_sc::contract] pub trait PaymasterContract: forward_call::ForwardCall { #[init] From 5c3d321571d1d1d0c565a26d6c35297e28decda3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Tue, 10 Oct 2023 11:09:57 +0300 Subject: [PATCH 03/10] Paymaster: Add wegld test --- contracts/paymaster/src/forward_call.rs | 2 +- .../tests/paymaster_blackbox_test.rs | 48 ++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/contracts/paymaster/src/forward_call.rs b/contracts/paymaster/src/forward_call.rs index 72a149db..19fe105d 100644 --- a/contracts/paymaster/src/forward_call.rs +++ b/contracts/paymaster/src/forward_call.rs @@ -51,7 +51,7 @@ pub trait ForwardCall { let mut err_result = MultiValueEncoded::new(); err_result.push(ManagedBuffer::new_from_bytes(ERR_CALLBACK_MSG)); - err_result.push(err.err_msg.clone()); + err_result.push(err.err_msg); err_result } diff --git a/contracts/paymaster/tests/paymaster_blackbox_test.rs b/contracts/paymaster/tests/paymaster_blackbox_test.rs index d259fc61..7d3e06b1 100644 --- a/contracts/paymaster/tests/paymaster_blackbox_test.rs +++ b/contracts/paymaster/tests/paymaster_blackbox_test.rs @@ -173,6 +173,19 @@ impl PaymasterTestState { self } + fn check_egld_balance( + &mut self, + address_expr: &str, + balance_expr: &str, + ) -> &mut Self { + self.world + .check_state_step(CheckStateStep::new().put_account( + address_expr, + CheckAccount::new().balance(balance_expr), + )); + + self + } } #[test] @@ -304,7 +317,40 @@ fn test_forward_call_sc_adder_multiple_payments() { } #[test] -fn test_forward_call_fails_wegld() { +fn test_forward_call_wegld() { + let mut state = PaymasterTestState::new(); + state.deploy_paymaster_contract(); + state.deploy_adder_contract(); + + state.check_esdt_balance(CALLER_ADDRESS_EXPR, FEE_TOKEN_ID_EXPR, BALANCE); + state.check_esdt_balance(CALLER_ADDRESS_EXPR, WEGLD_TOKEN_ID_EXPR, BALANCE); + + // Call fails because unwrap amount is 0 + state.world.sc_call( + ScCallStep::new() + .from(CALLER_ADDRESS_EXPR) + .esdt_transfer(FEE_TOKEN_ID_EXPR, 0, FEE_AMOUNT) + .esdt_transfer(WEGLD_TOKEN_ID_EXPR, 0, BALANCE) + .call(state.paymaster_contract.forward_execution( + state.relayer_address.clone(), + state.callee_sc_wegld_address.to_address(), + UNWRAP_ENDPOINT_NAME, + MultiValueEncoded::new(), + )) + ); + + // Fee is kept by the relayer + let new_fee_amount: &str = "99980000"; + state.check_esdt_balance(RELAYER_ADDRESS_EXPR, FEE_TOKEN_ID_EXPR, FEE_AMOUNT); + state.check_esdt_balance(CALLER_ADDRESS_EXPR, FEE_TOKEN_ID_EXPR, new_fee_amount); + + // Caller has the original balance + state.check_egld_balance(CALLER_ADDRESS_EXPR, BALANCE); +} + + +#[test] +fn test_forward_call_fails_wegld_0_amount() { let mut state = PaymasterTestState::new(); state.deploy_paymaster_contract(); state.deploy_adder_contract(); From c27103752d83dd5c764238aaa18195ec6daff176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Tue, 10 Oct 2023 16:40:43 +0300 Subject: [PATCH 04/10] Fixes after review --- contracts/paymaster/src/forward_call.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/paymaster/src/forward_call.rs b/contracts/paymaster/src/forward_call.rs index 19fe105d..25d4928e 100644 --- a/contracts/paymaster/src/forward_call.rs +++ b/contracts/paymaster/src/forward_call.rs @@ -30,7 +30,8 @@ pub trait ForwardCall { original_caller: ManagedAddress, #[call_result] result: ManagedAsyncCallResult>, ) -> MultiValueEncoded { - let initial_payments = self.call_value().all_esdt_transfers(); + // TODO: use ManagedGetBackTransfers once rc1.6 is activated + let callback_payments = self.call_value().all_esdt_transfers(); match result { ManagedAsyncCallResult::Ok(return_values) => { From 0af3cfa0e65fe12af6ed4831248f355156a2db43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Tue, 10 Oct 2023 16:49:22 +0300 Subject: [PATCH 05/10] Paymaster: fixes after audit --- contracts/paymaster/src/forward_call.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/paymaster/src/forward_call.rs b/contracts/paymaster/src/forward_call.rs index 25d4928e..d4409d02 100644 --- a/contracts/paymaster/src/forward_call.rs +++ b/contracts/paymaster/src/forward_call.rs @@ -36,18 +36,18 @@ pub trait ForwardCall { match result { ManagedAsyncCallResult::Ok(return_values) => { // Send the resulted tokens to the original caller - if !initial_payments.is_empty() { + if !callback_payments.is_empty() { self.send() - .direct_multi(&original_caller, &initial_payments); + .direct_multi(&original_caller, &callback_payments); } return_values } ManagedAsyncCallResult::Err(err) => { // Send the original input tokens back to the original caller - if !initial_payments.is_empty() { + if !callback_payments.is_empty() { self.send() - .direct_multi(&original_caller, &initial_payments); + .direct_multi(&original_caller, &callback_payments); } let mut err_result = MultiValueEncoded::new(); From b638f386742bcb16a8fac959f39c35f5b46559b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Thu, 12 Oct 2023 10:16:36 +0300 Subject: [PATCH 06/10] Paymaster: Fixes after review --- contracts/paymaster/src/forward_call.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/paymaster/src/forward_call.rs b/contracts/paymaster/src/forward_call.rs index d4409d02..a9beec53 100644 --- a/contracts/paymaster/src/forward_call.rs +++ b/contracts/paymaster/src/forward_call.rs @@ -31,7 +31,7 @@ pub trait ForwardCall { #[call_result] result: ManagedAsyncCallResult>, ) -> MultiValueEncoded { // TODO: use ManagedGetBackTransfers once rc1.6 is activated - let callback_payments = self.call_value().all_esdt_transfers(); + let callback_payments = self.call_value().all_esdt_transfers().clone_value(); match result { ManagedAsyncCallResult::Ok(return_values) => { From ce7865515474f28d74e501a4b443b3c69d6ce0a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Wed, 8 Nov 2023 08:41:18 +0200 Subject: [PATCH 07/10] Paymaster: add back-transfers support --- contracts/paymaster/Cargo.toml | 3 + contracts/paymaster/sc-config.toml | 10 + contracts/paymaster/src/forward_call.rs | 4 +- .../wasm-paymaster-back-transfers/Cargo.lock | 251 ++++++++++++++++++ .../wasm-paymaster-back-transfers/Cargo.toml | 26 ++ .../wasm-paymaster-back-transfers/src/lib.rs | 31 +++ contracts/paymaster/wasm/src/lib.rs | 4 +- 7 files changed, 326 insertions(+), 3 deletions(-) create mode 100644 contracts/paymaster/sc-config.toml create mode 100644 contracts/paymaster/wasm-paymaster-back-transfers/Cargo.lock create mode 100644 contracts/paymaster/wasm-paymaster-back-transfers/Cargo.toml create mode 100644 contracts/paymaster/wasm-paymaster-back-transfers/src/lib.rs diff --git a/contracts/paymaster/Cargo.toml b/contracts/paymaster/Cargo.toml index 6ff655aa..bebbe3ad 100644 --- a/contracts/paymaster/Cargo.toml +++ b/contracts/paymaster/Cargo.toml @@ -10,6 +10,9 @@ readme = "README.md" [lib] path = "src/paymaster.rs" +[features] +back-transfers = ["multiversx-sc/back-transfers"] + [dev-dependencies] num-bigint = "0.4.2" diff --git a/contracts/paymaster/sc-config.toml b/contracts/paymaster/sc-config.toml new file mode 100644 index 00000000..ef430477 --- /dev/null +++ b/contracts/paymaster/sc-config.toml @@ -0,0 +1,10 @@ +[settings] +main = "main" + +[contracts.main] +name = "paymaster" + +[contracts.back-transfers] +name = "paymaster-back-transfers" +add-labels = ["back-transfers"] +features = ["back-transfers"] \ No newline at end of file diff --git a/contracts/paymaster/src/forward_call.rs b/contracts/paymaster/src/forward_call.rs index a9beec53..bb39d657 100644 --- a/contracts/paymaster/src/forward_call.rs +++ b/contracts/paymaster/src/forward_call.rs @@ -24,7 +24,8 @@ pub trait ForwardCall { .call_and_exit(); } - #[callback] + #[promises_callback] + #[label("back-transfers")] fn transfer_callback( &self, original_caller: ManagedAddress, @@ -32,6 +33,7 @@ pub trait ForwardCall { ) -> MultiValueEncoded { // TODO: use ManagedGetBackTransfers once rc1.6 is activated let callback_payments = self.call_value().all_esdt_transfers().clone_value(); + // let back_payments = self.blockchain().back match result { ManagedAsyncCallResult::Ok(return_values) => { diff --git a/contracts/paymaster/wasm-paymaster-back-transfers/Cargo.lock b/contracts/paymaster/wasm-paymaster-back-transfers/Cargo.lock new file mode 100644 index 00000000..9aa99c3a --- /dev/null +++ b/contracts/paymaster/wasm-paymaster-back-transfers/Cargo.lock @@ -0,0 +1,251 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +dependencies = [ + "ahash", +] + +[[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.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" + +[[package]] +name = "multiversx-sc" +version = "0.44.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db6c3347b9ebfa2886c866b7740dbeac14d087accd52ec0e71961d54508e819b" +dependencies = [ + "bitflags", + "hashbrown", + "hex-literal", + "multiversx-sc-codec", + "multiversx-sc-derive", + "num-traits", +] + +[[package]] +name = "multiversx-sc-codec" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f1e15b46c17b87c0c7cdd79b041a4abd7f3a2b45f3c993f6ce38c0f233e82b6" +dependencies = [ + "arrayvec", + "multiversx-sc-codec-derive", +] + +[[package]] +name = "multiversx-sc-codec-derive" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a7bc0762cd6d88f8bc54805bc652b042a61cd7fbc2d0a325010f088b78fb2ac" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "multiversx-sc-derive" +version = "0.44.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7624ccef17a2378fb5d5d741497d224ee1650b90504d57988c1fa648f374a5" +dependencies = [ + "hex", + "proc-macro2", + "quote", + "radix_trie", + "syn 1.0.109", +] + +[[package]] +name = "multiversx-sc-wasm-adapter" +version = "0.44.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a23b0a10bf77174c11178d510555cc875e1f557d4256cbbe4d9c2dbf60d00d" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "nibble_vec" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" +dependencies = [ + "smallvec", +] + +[[package]] +name = "num-traits" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "paymaster" +version = "0.0.0" +dependencies = [ + "multiversx-sc", +] + +[[package]] +name = "paymaster-back-transfers-wasm" +version = "0.0.0" +dependencies = [ + "multiversx-sc-wasm-adapter", + "paymaster", +] + +[[package]] +name = "proc-macro2" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radix_trie" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" +dependencies = [ + "endian-type", + "nibble_vec", +] + +[[package]] +name = "smallvec" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "zerocopy" +version = "0.7.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cd369a67c0edfef15010f980c3cbe45d7f651deac2cd67ce097cd801de16557" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2f140bda219a26ccc0cdb03dba58af72590c53b22642577d88a927bc5c87d6b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] diff --git a/contracts/paymaster/wasm-paymaster-back-transfers/Cargo.toml b/contracts/paymaster/wasm-paymaster-back-transfers/Cargo.toml new file mode 100644 index 00000000..8f4d22c3 --- /dev/null +++ b/contracts/paymaster/wasm-paymaster-back-transfers/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "paymaster-back-transfers-wasm" +version = "0.0.0" +edition = "2018" +publish = false +authors = ["you"] + +[lib] +crate-type = ["cdylib"] + +[workspace] +members = ["."] + +[dev-dependencies] +[profile.release] +codegen-units = 1 +opt-level = "z" +lto = true +debug = false +panic = "abort" +[dependencies.paymaster] +path = ".." +features = ["back-transfers"] + +[dependencies.multiversx-sc-wasm-adapter] +version = "0.44.0" diff --git a/contracts/paymaster/wasm-paymaster-back-transfers/src/lib.rs b/contracts/paymaster/wasm-paymaster-back-transfers/src/lib.rs new file mode 100644 index 00000000..8ef7278e --- /dev/null +++ b/contracts/paymaster/wasm-paymaster-back-transfers/src/lib.rs @@ -0,0 +1,31 @@ +// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. + +//////////////////////////////////////////////////// +////////////////// AUTO-GENERATED ////////////////// +//////////////////////////////////////////////////// + +// Init: 1 +// Endpoints: 1 +// Async Callback (empty): 1 +// Promise callbacks: 1 +// Total number of exported functions: 4 + +#![no_std] + +// Configuration that works with rustc < 1.73.0. +// TODO: Recommended rustc version: 1.73.0 or newer. +#![feature(lang_items)] + +multiversx_sc_wasm_adapter::allocator!(); +multiversx_sc_wasm_adapter::panic_handler!(); + +multiversx_sc_wasm_adapter::endpoints! { + paymaster + ( + init => init + forwardExecution => forward_execution + transfer_callback => transfer_callback + ) +} + +multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/contracts/paymaster/wasm/src/lib.rs b/contracts/paymaster/wasm/src/lib.rs index dc78bc29..79e2b070 100644 --- a/contracts/paymaster/wasm/src/lib.rs +++ b/contracts/paymaster/wasm/src/lib.rs @@ -6,7 +6,7 @@ // Init: 1 // Endpoints: 1 -// Async Callback: 1 +// Async Callback (empty): 1 // Total number of exported functions: 3 #![no_std] @@ -26,4 +26,4 @@ multiversx_sc_wasm_adapter::endpoints! { ) } -multiversx_sc_wasm_adapter::async_callback! { paymaster } +multiversx_sc_wasm_adapter::async_callback_empty! {} From 2ff989d19b6663b9c8cdd9e602e82da310d7fd34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Tue, 14 Nov 2023 09:33:52 +0200 Subject: [PATCH 08/10] Add support for back transfers --- contracts/paymaster/Cargo.toml | 5 +- contracts/paymaster/mxsc-template.toml | 18 -- contracts/paymaster/sc-config.toml | 10 - contracts/paymaster/src/forward_call.rs | 27 +- .../wasm-paymaster-back-transfers/Cargo.lock | 251 ------------------ .../wasm-paymaster-back-transfers/Cargo.toml | 26 -- .../wasm-paymaster-back-transfers/src/lib.rs | 31 --- contracts/paymaster/wasm/src/lib.rs | 4 +- 8 files changed, 16 insertions(+), 356 deletions(-) delete mode 100644 contracts/paymaster/mxsc-template.toml delete mode 100644 contracts/paymaster/sc-config.toml delete mode 100644 contracts/paymaster/wasm-paymaster-back-transfers/Cargo.lock delete mode 100644 contracts/paymaster/wasm-paymaster-back-transfers/Cargo.toml delete mode 100644 contracts/paymaster/wasm-paymaster-back-transfers/src/lib.rs diff --git a/contracts/paymaster/Cargo.toml b/contracts/paymaster/Cargo.toml index bebbe3ad..a221a21d 100644 --- a/contracts/paymaster/Cargo.toml +++ b/contracts/paymaster/Cargo.toml @@ -10,14 +10,13 @@ readme = "README.md" [lib] path = "src/paymaster.rs" -[features] -back-transfers = ["multiversx-sc/back-transfers"] - [dev-dependencies] num-bigint = "0.4.2" [dependencies.multiversx-sc] version = "0.44.0" +features = ["back-transfers"] + [dev-dependencies.multiversx-sc-scenario] version = "0.44.0" diff --git a/contracts/paymaster/mxsc-template.toml b/contracts/paymaster/mxsc-template.toml deleted file mode 100644 index 441addd7..00000000 --- a/contracts/paymaster/mxsc-template.toml +++ /dev/null @@ -1,18 +0,0 @@ -name = "empty" -contract_trait = "EmptyContract" -src_file = "empty.rs" -rename_pairs = [ - [ - "blockchain.set_current_dir_from_workspace(\"contracts/examples/empty\");", - "// blockchain.set_current_dir_from_workspace(\"relative path to your workspace, if applicable\");", - ], -] -files_include = [ - "meta", - "scenarios", - "src", - "tests", - "wasm/Cargo.toml", - "Cargo.toml", - "multiversx.json", -] diff --git a/contracts/paymaster/sc-config.toml b/contracts/paymaster/sc-config.toml deleted file mode 100644 index ef430477..00000000 --- a/contracts/paymaster/sc-config.toml +++ /dev/null @@ -1,10 +0,0 @@ -[settings] -main = "main" - -[contracts.main] -name = "paymaster" - -[contracts.back-transfers] -name = "paymaster-back-transfers" -add-labels = ["back-transfers"] -features = ["back-transfers"] \ No newline at end of file diff --git a/contracts/paymaster/src/forward_call.rs b/contracts/paymaster/src/forward_call.rs index bb39d657..9410e1ed 100644 --- a/contracts/paymaster/src/forward_call.rs +++ b/contracts/paymaster/src/forward_call.rs @@ -24,34 +24,31 @@ pub trait ForwardCall { .call_and_exit(); } - #[promises_callback] - #[label("back-transfers")] + #[callback] fn transfer_callback( &self, original_caller: ManagedAddress, #[call_result] result: ManagedAsyncCallResult>, ) -> MultiValueEncoded { // TODO: use ManagedGetBackTransfers once rc1.6 is activated - let callback_payments = self.call_value().all_esdt_transfers().clone_value(); - // let back_payments = self.blockchain().back + let back_transfers = self.blockchain().get_back_transfers(); + + // Send the original input tokens back to the original caller + if !back_transfers.esdt_payments.is_empty() { + self.send() + .direct_multi(&original_caller, &back_transfers.esdt_payments); + } + if back_transfers.total_egld_amount != BigUint::zero() { + self.send() + .direct_egld(&original_caller, &back_transfers.total_egld_amount) + } match result { ManagedAsyncCallResult::Ok(return_values) => { // Send the resulted tokens to the original caller - if !callback_payments.is_empty() { - self.send() - .direct_multi(&original_caller, &callback_payments); - } - return_values } ManagedAsyncCallResult::Err(err) => { - // Send the original input tokens back to the original caller - if !callback_payments.is_empty() { - self.send() - .direct_multi(&original_caller, &callback_payments); - } - let mut err_result = MultiValueEncoded::new(); err_result.push(ManagedBuffer::new_from_bytes(ERR_CALLBACK_MSG)); err_result.push(err.err_msg); diff --git a/contracts/paymaster/wasm-paymaster-back-transfers/Cargo.lock b/contracts/paymaster/wasm-paymaster-back-transfers/Cargo.lock deleted file mode 100644 index 9aa99c3a..00000000 --- a/contracts/paymaster/wasm-paymaster-back-transfers/Cargo.lock +++ /dev/null @@ -1,251 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "ahash" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - -[[package]] -name = "arrayvec" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "endian-type" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" - -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - -[[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.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" - -[[package]] -name = "multiversx-sc" -version = "0.44.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db6c3347b9ebfa2886c866b7740dbeac14d087accd52ec0e71961d54508e819b" -dependencies = [ - "bitflags", - "hashbrown", - "hex-literal", - "multiversx-sc-codec", - "multiversx-sc-derive", - "num-traits", -] - -[[package]] -name = "multiversx-sc-codec" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f1e15b46c17b87c0c7cdd79b041a4abd7f3a2b45f3c993f6ce38c0f233e82b6" -dependencies = [ - "arrayvec", - "multiversx-sc-codec-derive", -] - -[[package]] -name = "multiversx-sc-codec-derive" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a7bc0762cd6d88f8bc54805bc652b042a61cd7fbc2d0a325010f088b78fb2ac" -dependencies = [ - "hex", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "multiversx-sc-derive" -version = "0.44.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7624ccef17a2378fb5d5d741497d224ee1650b90504d57988c1fa648f374a5" -dependencies = [ - "hex", - "proc-macro2", - "quote", - "radix_trie", - "syn 1.0.109", -] - -[[package]] -name = "multiversx-sc-wasm-adapter" -version = "0.44.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25a23b0a10bf77174c11178d510555cc875e1f557d4256cbbe4d9c2dbf60d00d" -dependencies = [ - "multiversx-sc", -] - -[[package]] -name = "nibble_vec" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" -dependencies = [ - "smallvec", -] - -[[package]] -name = "num-traits" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" -dependencies = [ - "autocfg", -] - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "paymaster" -version = "0.0.0" -dependencies = [ - "multiversx-sc", -] - -[[package]] -name = "paymaster-back-transfers-wasm" -version = "0.0.0" -dependencies = [ - "multiversx-sc-wasm-adapter", - "paymaster", -] - -[[package]] -name = "proc-macro2" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "radix_trie" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" -dependencies = [ - "endian-type", - "nibble_vec", -] - -[[package]] -name = "smallvec" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "zerocopy" -version = "0.7.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cd369a67c0edfef15010f980c3cbe45d7f651deac2cd67ce097cd801de16557" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2f140bda219a26ccc0cdb03dba58af72590c53b22642577d88a927bc5c87d6b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.39", -] diff --git a/contracts/paymaster/wasm-paymaster-back-transfers/Cargo.toml b/contracts/paymaster/wasm-paymaster-back-transfers/Cargo.toml deleted file mode 100644 index 8f4d22c3..00000000 --- a/contracts/paymaster/wasm-paymaster-back-transfers/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -name = "paymaster-back-transfers-wasm" -version = "0.0.0" -edition = "2018" -publish = false -authors = ["you"] - -[lib] -crate-type = ["cdylib"] - -[workspace] -members = ["."] - -[dev-dependencies] -[profile.release] -codegen-units = 1 -opt-level = "z" -lto = true -debug = false -panic = "abort" -[dependencies.paymaster] -path = ".." -features = ["back-transfers"] - -[dependencies.multiversx-sc-wasm-adapter] -version = "0.44.0" diff --git a/contracts/paymaster/wasm-paymaster-back-transfers/src/lib.rs b/contracts/paymaster/wasm-paymaster-back-transfers/src/lib.rs deleted file mode 100644 index 8ef7278e..00000000 --- a/contracts/paymaster/wasm-paymaster-back-transfers/src/lib.rs +++ /dev/null @@ -1,31 +0,0 @@ -// Code generated by the multiversx-sc multi-contract system. DO NOT EDIT. - -//////////////////////////////////////////////////// -////////////////// AUTO-GENERATED ////////////////// -//////////////////////////////////////////////////// - -// Init: 1 -// Endpoints: 1 -// Async Callback (empty): 1 -// Promise callbacks: 1 -// Total number of exported functions: 4 - -#![no_std] - -// Configuration that works with rustc < 1.73.0. -// TODO: Recommended rustc version: 1.73.0 or newer. -#![feature(lang_items)] - -multiversx_sc_wasm_adapter::allocator!(); -multiversx_sc_wasm_adapter::panic_handler!(); - -multiversx_sc_wasm_adapter::endpoints! { - paymaster - ( - init => init - forwardExecution => forward_execution - transfer_callback => transfer_callback - ) -} - -multiversx_sc_wasm_adapter::async_callback_empty! {} diff --git a/contracts/paymaster/wasm/src/lib.rs b/contracts/paymaster/wasm/src/lib.rs index 79e2b070..dc78bc29 100644 --- a/contracts/paymaster/wasm/src/lib.rs +++ b/contracts/paymaster/wasm/src/lib.rs @@ -6,7 +6,7 @@ // Init: 1 // Endpoints: 1 -// Async Callback (empty): 1 +// Async Callback: 1 // Total number of exported functions: 3 #![no_std] @@ -26,4 +26,4 @@ multiversx_sc_wasm_adapter::endpoints! { ) } -multiversx_sc_wasm_adapter::async_callback_empty! {} +multiversx_sc_wasm_adapter::async_callback! { paymaster } From ba11a616091d74759e7941fcb6da2ec2f66ebd84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Wed, 22 Nov 2023 15:49:56 +0200 Subject: [PATCH 09/10] Test1 --- contracts/paymaster/src/forward_call.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contracts/paymaster/src/forward_call.rs b/contracts/paymaster/src/forward_call.rs index 9410e1ed..03a60e02 100644 --- a/contracts/paymaster/src/forward_call.rs +++ b/contracts/paymaster/src/forward_call.rs @@ -32,6 +32,9 @@ pub trait ForwardCall { ) -> MultiValueEncoded { // TODO: use ManagedGetBackTransfers once rc1.6 is activated let back_transfers = self.blockchain().get_back_transfers(); + let payments = self.call_value().all_esdt_transfers(); + + self.send().direct_multi(&original_caller, &payments.clone_value()); // Send the original input tokens back to the original caller if !back_transfers.esdt_payments.is_empty() { From e2086b27c71818410f78a7d86236f230c4cfcd10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Costin=20Caraba=C8=99?= Date: Thu, 23 Nov 2023 13:16:05 +0200 Subject: [PATCH 10/10] Paymaster fix --- contracts/paymaster/src/forward_call.rs | 5 +---- contracts/paymaster/src/paymaster.rs | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/contracts/paymaster/src/forward_call.rs b/contracts/paymaster/src/forward_call.rs index 03a60e02..955e59f7 100644 --- a/contracts/paymaster/src/forward_call.rs +++ b/contracts/paymaster/src/forward_call.rs @@ -10,8 +10,8 @@ pub trait ForwardCall { &self, dest: ManagedAddress, endpoint_name: ManagedBuffer, - endpoint_args: MultiValueEncoded, payments: PaymentsVec, + endpoint_args: MultiValueEncoded, ) { let original_caller = self.blockchain().get_caller(); @@ -32,9 +32,6 @@ pub trait ForwardCall { ) -> MultiValueEncoded { // TODO: use ManagedGetBackTransfers once rc1.6 is activated let back_transfers = self.blockchain().get_back_transfers(); - let payments = self.call_value().all_esdt_transfers(); - - self.send().direct_multi(&original_caller, &payments.clone_value()); // Send the original input tokens back to the original caller if !back_transfers.esdt_payments.is_empty() { diff --git a/contracts/paymaster/src/paymaster.rs b/contracts/paymaster/src/paymaster.rs index a5527945..d50bf875 100644 --- a/contracts/paymaster/src/paymaster.rs +++ b/contracts/paymaster/src/paymaster.rs @@ -33,6 +33,6 @@ pub trait PaymasterContract: forward_call::ForwardCall { let mut payments_without_fee = payments.clone_value(); payments_without_fee.remove(FEE_PAYMENT); - self.forward_call(dest, endpoint_name, endpoint_args, payments_without_fee); + self.forward_call(dest, endpoint_name, payments_without_fee, endpoint_args); } }