Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esdt-safe: Fix withdraw total fees on ethereum #221

Merged
merged 6 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions esdt-safe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,17 @@ pub trait EsdtSafe:
#[only_owner]
#[endpoint(withdrawTotalFeesOnEthereum)]
fn withdraw_total_fees_on_ethereum(&self, token_id: TokenIdentifier) {
let amount_out = self.total_fees_on_ethereum(&token_id).get();
let total_fees_on_ethereum_mapper = self.total_fees_on_ethereum(&token_id);
require!(
!total_fees_on_ethereum_mapper.is_empty(),
"There are no fees to withdraw"
);
let amount_out = total_fees_on_ethereum_mapper.get();
self.tx()
.to(ToCaller)
.single_esdt(&token_id, 0, &amount_out)
.transfer();
total_fees_on_ethereum_mapper.set(BigUint::zero());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

#[view(computeTotalAmmountsFromIndex)]
Expand Down Expand Up @@ -437,8 +443,6 @@ pub trait EsdtSafe:
refund_amounts
}

// views

#[view(getTotalRefundAmounts)]
fn get_total_refund_amounts(&self) -> MultiValueEncoded<MultiValue2<TokenIdentifier, BigUint>> {
let mut refund_amounts = MultiValueEncoded::new();
Expand All @@ -452,6 +456,16 @@ pub trait EsdtSafe:
refund_amounts
}

#[view(getTotalFeesOnEthereum)]
CostinCarabas marked this conversation as resolved.
Show resolved Hide resolved
fn get_total_fees_on_ethereum(&self, token_id: TokenIdentifier) -> BigUint {
let total_fees_on_ethereum_mapper = self.total_fees_on_ethereum(&token_id);
if total_fees_on_ethereum_mapper.is_empty() {
BigUint::zero()
} else {
total_fees_on_ethereum_mapper.get()
}
}

// private

fn rebalance_for_refund(&self, token_id: &TokenIdentifier, amount: &BigUint) {
Expand Down
5 changes: 3 additions & 2 deletions esdt-safe/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

// Init: 1
// Upgrade: 1
// Endpoints: 46
// Endpoints: 47
// Async Callback (empty): 1
// Total number of exported functions: 49
// Total number of exported functions: 50

#![no_std]

Expand All @@ -29,6 +29,7 @@ multiversx_sc_wasm_adapter::endpoints! {
computeTotalAmmountsFromIndex => compute_total_amounts_from_index
getRefundAmounts => get_refund_amounts
getTotalRefundAmounts => get_total_refund_amounts
getTotalFeesOnEthereum => get_total_fees_on_ethereum
getBridgedTokensWrapperAddress => bridged_tokens_wrapper_address
setFeeEstimatorContractAddress => set_fee_estimator_contract_address
setEthTxGasLimit => set_eth_tx_gas_limit
Expand Down
Loading