Skip to content

Commit 3b263e3

Browse files
Merge pull request #2205 from multiversx/composability-payment
composability - new payment objects
2 parents 2a7fc26 + a9c88af commit 3b263e3

File tree

64 files changed

+550
-625
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+550
-625
lines changed

contracts/feature-tests/composability/esdt-contract-pair/first-contract/src/lib.rs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ pub trait FirstContract {
2121
#[payable("*")]
2222
#[endpoint(transferToSecondContractFull)]
2323
fn transfer_to_second_contract_full(&self) {
24-
let (actual_token_identifier, esdt_value) = self.call_value().single_fungible_esdt();
24+
let payment = self.call_value().single();
2525
let expected_token_identifier = self.get_contract_esdt_token_identifier();
2626

2727
require!(
28-
*actual_token_identifier == expected_token_identifier,
28+
payment.token_identifier == expected_token_identifier,
2929
"Wrong esdt token"
3030
);
3131

3232
self.call_esdt_second_contract(
3333
&expected_token_identifier,
34-
&esdt_value,
34+
&payment.amount,
3535
&self.get_second_contract_address(),
3636
&ManagedBuffer::from(SECOND_CONTRACT_ACCEPT_ESDT_PAYMENT),
3737
&ManagedVec::new(),
@@ -41,17 +41,17 @@ pub trait FirstContract {
4141
#[payable("*")]
4242
#[endpoint(transferToSecondContractHalf)]
4343
fn transfer_to_second_contract_half(&self) {
44-
let (actual_token_identifier, esdt_value) = self.call_value().single_fungible_esdt();
44+
let payment = self.call_value().single();
4545
let expected_token_identifier = self.get_contract_esdt_token_identifier();
4646

4747
require!(
48-
*actual_token_identifier == expected_token_identifier,
48+
payment.token_identifier == expected_token_identifier,
4949
"Wrong esdt token"
5050
);
5151

5252
self.call_esdt_second_contract(
5353
&expected_token_identifier,
54-
&(esdt_value.clone() / 2u32),
54+
&(&payment.amount / 2u32),
5555
&self.get_second_contract_address(),
5656
&ManagedBuffer::from(SECOND_CONTRACT_ACCEPT_ESDT_PAYMENT),
5757
&ManagedVec::new(),
@@ -61,17 +61,17 @@ pub trait FirstContract {
6161
#[payable("*")]
6262
#[endpoint(transferToSecondContractRejected)]
6363
fn transfer_to_second_contract_rejected(&self) {
64-
let (actual_token_identifier, esdt_value) = self.call_value().single_fungible_esdt();
64+
let payment = self.call_value().single();
6565
let expected_token_identifier = self.get_contract_esdt_token_identifier();
6666

6767
require!(
68-
*actual_token_identifier == expected_token_identifier,
68+
payment.token_identifier == expected_token_identifier,
6969
"Wrong esdt token"
7070
);
7171

7272
self.call_esdt_second_contract(
7373
&expected_token_identifier,
74-
&esdt_value,
74+
&payment.amount,
7575
&self.get_second_contract_address(),
7676
&ManagedBuffer::from(SECOND_CONTRACT_REJECT_ESDT_PAYMENT),
7777
&ManagedVec::new(),
@@ -81,12 +81,12 @@ pub trait FirstContract {
8181
#[payable("*")]
8282
#[endpoint(transferToSecondContractRejectedWithTransferAndExecute)]
8383
fn transfer_to_second_contract_rejected_with_transfer_and_execute(&self) {
84-
let (actual_token_identifier, esdt_value) = self.call_value().single_fungible_esdt();
84+
let payment = self.call_value().single();
8585
let second_contract_address = self.get_second_contract_address();
8686
let expected_token_identifier = self.get_contract_esdt_token_identifier();
8787

8888
require!(
89-
*actual_token_identifier == expected_token_identifier,
89+
payment.token_identifier == expected_token_identifier,
9090
"Wrong esdt token"
9191
);
9292

@@ -95,19 +95,23 @@ pub trait FirstContract {
9595
.to(&second_contract_address)
9696
.gas(gas_left)
9797
.raw_call(SECOND_CONTRACT_REJECT_ESDT_PAYMENT)
98-
.single_esdt(&expected_token_identifier, 0u64, &esdt_value)
98+
.payment(PaymentRefs::new(
99+
&expected_token_identifier,
100+
0u64,
101+
&payment.amount,
102+
))
99103
.transfer_execute();
100104
}
101105

102106
#[payable("*")]
103107
#[endpoint(transferToSecondContractFullWithTransferAndExecute)]
104108
fn transfer_to_second_contract_full_with_transfer_and_execute(&self) {
105-
let (actual_token_identifier, esdt_value) = self.call_value().single_fungible_esdt();
109+
let payment = self.call_value().single();
106110
let second_contract_address = self.get_second_contract_address();
107111
let expected_token_identifier = self.get_contract_esdt_token_identifier();
108112

109113
require!(
110-
*actual_token_identifier == expected_token_identifier,
114+
payment.token_identifier == expected_token_identifier,
111115
"Wrong esdt token"
112116
);
113117

@@ -116,14 +120,18 @@ pub trait FirstContract {
116120
.to(&second_contract_address)
117121
.gas(gas_left)
118122
.raw_call(SECOND_CONTRACT_ACCEPT_ESDT_PAYMENT)
119-
.single_esdt(&expected_token_identifier, 0u64, &esdt_value)
123+
.payment(PaymentRefs::new(
124+
&expected_token_identifier,
125+
0u64,
126+
&payment.amount,
127+
))
120128
.transfer_execute();
121129
}
122130

123131
fn call_esdt_second_contract(
124132
&self,
125-
esdt_token_identifier: &EsdtTokenIdentifier,
126-
amount: &BigUint,
133+
esdt_token_identifier: &TokenId,
134+
amount: &NonZeroBigUint,
127135
to: &ManagedAddress,
128136
func_name: &ManagedBuffer,
129137
args: &ManagedVec<Self::Api, ManagedBuffer>,
@@ -150,7 +158,7 @@ pub trait FirstContract {
150158

151159
#[view(getesdtTokenName)]
152160
#[storage_get("esdtTokenName")]
153-
fn get_contract_esdt_token_identifier(&self) -> EsdtTokenIdentifier;
161+
fn get_contract_esdt_token_identifier(&self) -> TokenId;
154162

155163
#[storage_set("secondContractAddress")]
156164
fn set_second_contract_address(&self, address: &ManagedAddress);

contracts/feature-tests/composability/esdt-contract-pair/second-contract/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ multiversx_sc::imports!();
55
#[multiversx_sc::contract]
66
pub trait SecondContract {
77
#[init]
8-
fn init(&self, esdt_token_identifier: EgldOrEsdtTokenIdentifier) {
8+
fn init(&self, esdt_token_identifier: TokenId) {
99
self.set_contract_esdt_token_identifier(&esdt_token_identifier);
1010
}
1111

1212
#[payable("*")]
1313
#[endpoint(acceptEsdtPayment)]
1414
fn accept_esdt_payment(&self) {
15-
let actual_token_identifier = self.call_value().egld_or_single_esdt().token_identifier;
15+
let payment = self.call_value().single();
1616
let expected_token_identifier = self.get_contract_esdt_token_identifier();
1717
require!(
18-
actual_token_identifier == expected_token_identifier,
18+
payment.token_identifier == expected_token_identifier,
1919
"Wrong esdt token"
2020
);
2121
}
@@ -29,9 +29,9 @@ pub trait SecondContract {
2929
// storage
3030

3131
#[storage_set("esdtTokenName")]
32-
fn set_contract_esdt_token_identifier(&self, esdt_token_identifier: &EgldOrEsdtTokenIdentifier);
32+
fn set_contract_esdt_token_identifier(&self, esdt_token_identifier: &TokenId);
3333

3434
#[view(getesdtTokenName)]
3535
#[storage_get("esdtTokenName")]
36-
fn get_contract_esdt_token_identifier(&self) -> EgldOrEsdtTokenIdentifier;
36+
fn get_contract_esdt_token_identifier(&self) -> TokenId;
3737
}

contracts/feature-tests/composability/execute-on-dest-esdt-issue-callback/child/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ pub trait Child {
4545

4646
#[callback]
4747
fn esdt_issue_callback(&self, #[call_result] _result: IgnoreValue) {
48-
let (token_identifier, _amount) = self.call_value().single_fungible_esdt();
49-
self.wrapped_egld_token_identifier().set(token_identifier);
48+
let payment = self.call_value().single();
49+
self.wrapped_egld_token_identifier()
50+
.set(&payment.token_identifier);
5051
}
5152

5253
// storage
5354

5455
#[view(getWrappedEgldTokenIdentifier)]
5556
#[storage_mapper("wrappedEgldTokenIdentifier")]
56-
fn wrapped_egld_token_identifier(&self) -> SingleValueMapper<EsdtTokenIdentifier>;
57+
fn wrapped_egld_token_identifier(&self) -> SingleValueMapper<TokenId>;
5758
}

contracts/feature-tests/composability/execute-on-dest-esdt-issue-callback/parent/src/child_proxy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ where
8282

8383
pub fn wrapped_egld_token_identifier(
8484
self,
85-
) -> TxTypedCall<Env, From, To, NotPayable, Gas, EsdtTokenIdentifier<Env::Api>> {
85+
) -> TxTypedCall<Env, From, To, NotPayable, Gas, TokenId<Env::Api>> {
8686
self.wrapped_tx
8787
.payment(NotPayable)
8888
.raw_call("getWrappedEgldTokenIdentifier")

contracts/feature-tests/composability/forwarder-interactor/src/interact.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ pub async fn forwarder_cli() {
7575
"callback_data_at_index" => interact.callback_data_at_index().await,
7676
"clear_callback_data" => interact.clear_callback_data().await,
7777
"forward_transf_exec_accept_funds" => interact.forward_transf_exec_accept_funds().await,
78-
"forward_transf_execu_accept_funds_with_fees" => {
79-
interact.forward_transf_execu_accept_funds_with_fees().await
78+
"forward_transf_exec_accept_funds_with_fees" => {
79+
interact.forward_transf_exec_accept_funds_with_fees().await
8080
}
8181
"forward_transf_exec_accept_funds_twice" => {
8282
interact.forward_transf_exec_accept_funds_twice().await
@@ -406,7 +406,7 @@ impl ContractInteract {
406406
let token_amount = BigUint::<StaticApi>::from(0u128);
407407

408408
let to = Address::zero();
409-
let percentage_fees = BigUint::<StaticApi>::from(0u128);
409+
let percentage_fees = 0u32;
410410

411411
let response = self
412412
.interactor
@@ -636,7 +636,7 @@ impl ContractInteract {
636636
let token_amount = BigUint::<StaticApi>::from(0u128);
637637

638638
let to = Address::zero();
639-
let percentage_fees = BigUint::<StaticApi>::from(0u128);
639+
let percentage_fees = 0u32;
640640

641641
let response = self
642642
.interactor
@@ -799,13 +799,13 @@ impl ContractInteract {
799799
println!("Result: {response:?}");
800800
}
801801

802-
pub async fn forward_transf_execu_accept_funds_with_fees(&mut self) {
802+
pub async fn forward_transf_exec_accept_funds_with_fees(&mut self) {
803803
let token_id = String::new();
804804
let token_nonce = 0u64;
805805
let token_amount = BigUint::<StaticApi>::from(0u128);
806806

807807
let to = Address::zero();
808-
let percentage_fees = BigUint::<StaticApi>::from(0u128);
808+
let percentage_fees = 0u32;
809809

810810
let response = self
811811
.interactor
@@ -814,7 +814,7 @@ impl ContractInteract {
814814
.to(self.state.current_address())
815815
.gas(80_000_000u64)
816816
.typed(proxy::ForwarderProxy)
817-
.forward_transf_execu_accept_funds_with_fees(to, percentage_fees)
817+
.forward_transf_exec_accept_funds_with_fees(to, percentage_fees)
818818
.payment((
819819
EsdtTokenIdentifier::from(token_id.as_str()),
820820
token_nonce,
@@ -1108,7 +1108,7 @@ impl ContractInteract {
11081108
let token_amount = BigUint::<StaticApi>::from(0u128);
11091109

11101110
let to = Address::zero();
1111-
let percentage_fees = BigUint::<StaticApi>::from(0u128);
1111+
let percentage_fees = 0u32;
11121112

11131113
let response = self
11141114
.interactor
@@ -1153,15 +1153,12 @@ impl ContractInteract {
11531153

11541154
pub async fn send_esdt_direct_multi_transfer(&mut self) {
11551155
let to = Address::zero();
1156-
let token_payments = MultiValueVec::from(vec![MultiValue3::<
1157-
EsdtTokenIdentifier<StaticApi>,
1158-
u64,
1159-
BigUint<StaticApi>,
1160-
>::from((
1161-
EsdtTokenIdentifier::from_esdt_bytes(&b""[..]),
1156+
let token_payments = MultiValueVec::from(vec![Payment::new(
1157+
TokenId::new(ManagedBuffer::from(&b""[..])),
11621158
0u64,
1163-
BigUint::<StaticApi>::from(0u128),
1164-
))]);
1159+
NonZeroBigUint::<StaticApi>::try_from(10u128).unwrap(),
1160+
)
1161+
.into_multi_value()]);
11651162

11661163
let response = self
11671164
.interactor

contracts/feature-tests/composability/forwarder-interactor/src/proxy.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ where
158158

159159
pub fn forward_sync_accept_funds_with_fees<
160160
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
161-
Arg1: ProxyArg<BigUint<Env::Api>>,
161+
Arg1: ProxyArg<u32>,
162162
>(
163163
self,
164164
to: Arg0,
@@ -275,6 +275,7 @@ where
275275
.original_result()
276276
}
277277

278+
/// TODO: not tested, investigate
278279
pub fn forward_async_accept_funds_half_payment<
279280
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
280281
>(
@@ -289,7 +290,7 @@ where
289290

290291
pub fn forward_async_accept_funds_with_fees<
291292
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
292-
Arg1: ProxyArg<BigUint<Env::Api>>,
293+
Arg1: ProxyArg<u32>,
293294
>(
294295
self,
295296
to: Arg0,
@@ -399,16 +400,16 @@ where
399400
.original_result()
400401
}
401402

402-
pub fn forward_transf_execu_accept_funds_with_fees<
403+
pub fn forward_transf_exec_accept_funds_with_fees<
403404
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
404-
Arg1: ProxyArg<BigUint<Env::Api>>,
405+
Arg1: ProxyArg<u32>,
405406
>(
406407
self,
407408
to: Arg0,
408409
percentage_fees: Arg1,
409410
) -> TxTypedCall<Env, From, To, (), Gas, ()> {
410411
self.wrapped_tx
411-
.raw_call("forward_transf_execu_accept_funds_with_fees")
412+
.raw_call("forward_transf_exec_accept_funds_with_fees")
412413
.argument(&to)
413414
.argument(&percentage_fees)
414415
.original_result()
@@ -433,7 +434,7 @@ where
433434
>(
434435
self,
435436
to: Arg0,
436-
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue4<u64, u64, BigUint<Env::Api>, EgldOrEsdtTokenIdentifier<Env::Api>>> {
437+
) -> TxTypedCall<Env, From, To, (), Gas, MultiValue3<u64, u64, TokenId<Env::Api>>> {
437438
self.wrapped_tx
438439
.raw_call("forward_transf_exec_accept_funds_return_values")
439440
.argument(&to)
@@ -618,7 +619,7 @@ where
618619

619620
pub fn send_esdt_with_fees<
620621
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
621-
Arg1: ProxyArg<BigUint<Env::Api>>,
622+
Arg1: ProxyArg<u32>,
622623
>(
623624
self,
624625
to: Arg0,
@@ -655,7 +656,7 @@ where
655656

656657
pub fn send_esdt_direct_multi_transfer<
657658
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
658-
Arg1: ProxyArg<MultiValueEncoded<Env::Api, MultiValue3<EsdtTokenIdentifier<Env::Api>, u64, BigUint<Env::Api>>>>,
659+
Arg1: ProxyArg<MultiValueEncoded<Env::Api, PaymentMultiValue<Env::Api>>>,
659660
>(
660661
self,
661662
to: Arg0,
@@ -1662,7 +1663,7 @@ where
16621663

16631664
pub fn forward_sync_retrieve_funds_bt_multi<
16641665
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
1665-
Arg1: ProxyArg<MultiValueEncoded<Env::Api, EgldOrEsdtTokenPaymentMultiValue<Env::Api>>>,
1666+
Arg1: ProxyArg<MultiValueEncoded<Env::Api, PaymentMultiValue<Env::Api>>>,
16661667
>(
16671668
self,
16681669
to: Arg0,
@@ -1679,7 +1680,7 @@ where
16791680
/// Highlights the behavior when calling back transfers **without** reset.
16801681
pub fn forward_sync_retrieve_funds_bt_multi_twice<
16811682
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
1682-
Arg1: ProxyArg<MultiValueEncoded<Env::Api, EgldOrEsdtTokenPaymentMultiValue<Env::Api>>>,
1683+
Arg1: ProxyArg<MultiValueEncoded<Env::Api, PaymentMultiValue<Env::Api>>>,
16831684
>(
16841685
self,
16851686
to: Arg0,
@@ -1696,7 +1697,7 @@ where
16961697
/// Highlights the behavior when calling back transfers **with** reset.
16971698
pub fn forward_sync_retrieve_funds_bt_multi_twice_reset<
16981699
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
1699-
Arg1: ProxyArg<MultiValueEncoded<Env::Api, EgldOrEsdtTokenPaymentMultiValue<Env::Api>>>,
1700+
Arg1: ProxyArg<MultiValueEncoded<Env::Api, PaymentMultiValue<Env::Api>>>,
17001701
>(
17011702
self,
17021703
to: Arg0,

contracts/feature-tests/composability/forwarder-legacy/src/fwd_call_async_legacy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ pub trait ForwarderAsyncCallModule {
8585

8686
#[payable("*")]
8787
#[endpoint]
88-
fn forward_async_accept_funds_with_fees(&self, to: ManagedAddress, percentage_fees: BigUint) {
88+
fn forward_async_accept_funds_with_fees(&self, to: ManagedAddress, percentage_fees: u32) {
8989
let payment = self.call_value().egld_or_single_esdt();
90-
let fees = &payment.amount * &percentage_fees / PERCENTAGE_TOTAL;
90+
let fees = &payment.amount * percentage_fees / PERCENTAGE_TOTAL;
9191
let amount_to_send = &payment.amount - &fees;
9292

9393
self.vault_proxy()

0 commit comments

Comments
 (0)