Skip to content

Commit

Permalink
fee update for endpoint merge version
Browse files Browse the repository at this point in the history
  • Loading branch information
alyn509 committed Jan 31, 2025
1 parent 59f42cb commit 39959cc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@
"storage": {
"str:deposit|0xdb474a3a065d3f0c0a62ae680ef6435e48eb482899d2ae30ff7a3a4b0ef19c60": {
"0-depositor_address": "address:acc3",
"1-funds": "u32:2|nested:str:CASHTOKEN-778899|u64:0|biguint:47|nested:str:CASHTOKEN-112233|u64:0|biguint:50",
"1-funds": "u32:2|nested:str:CASHTOKEN-778899|u64:0|biguint:44|nested:str:CASHTOKEN-112233|u64:0|biguint:50",
"2-valability": "u64:100",
"3-expiration_round": "u64:16",
"4-fees": {
"0-num_token_to_transfer": "u32:2",
"1-value": {
"0-tokenIdentifier": "nested:str:CASHTOKEN-778899",
"1-nonce": "u64:0",
"2-amount": "biguint:3"
"2-amount": "biguint:6"
}
}
},
Expand Down
12 changes: 9 additions & 3 deletions contracts/examples/digital-cash/src/pay_fee_and_fund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ pub trait PayFeeAndFund: storage::StorageModule + helpers::HelpersModule {
require!(!fee_value_mapper.is_empty(), "invalid fee toke provided");

fee_token.amount = fee_value_mapper.get();

let fee_with_first_token = fee_token.amount.clone() * payments.len() as u32;
let fee_without_first_token = fee_token.amount.clone() * (payments.len() as u32 - 1);

require!(
(provided_fee_token.amount >= fee_token.amount && payments.len() > 1) // case when we have more than 1 type of token transfered
|| (provided_fee_token.amount > fee_token.amount && payments.len() == 1), // case when token transfered is the same with the fee token
(provided_fee_token.amount == fee_without_first_token || // case when first first token is the exact fee amount
provided_fee_token.amount > fee_with_first_token), // case when first token also covers part of the funds
"payment not covering fees"
);

if provided_fee_token.amount > fee_token.amount {
if provided_fee_token.amount > fee_without_first_token {
fee_token.amount = fee_with_first_token;
let extracted_fee = EgldOrEsdtTokenPayment::new(
provided_fee_token.token_identifier,
provided_fee_token.token_nonce,
Expand All @@ -30,6 +35,7 @@ pub trait PayFeeAndFund: storage::StorageModule + helpers::HelpersModule {
let _ = payments.set(0, extracted_fee);
} else {
payments.remove(0);
fee_token.amount = fee_without_first_token;
}

let caller_address = self.blockchain().get_caller();
Expand Down

0 comments on commit 39959cc

Please sign in to comment.