Skip to content

Commit

Permalink
Merge pull request #1007 from multiversx/token-unstake-helper-functions
Browse files Browse the repository at this point in the history
Token Unstake SC helper functions updates
  • Loading branch information
ovidiuolteanu authored Feb 26, 2025
2 parents 2fb3b5a + 1814b7d commit aa4dd02
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
17 changes: 15 additions & 2 deletions locked-asset/token-unstake/src/fees_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,26 @@ pub trait FeesHandlerModule:
self.burn_penalty(payment);
}

#[only_owner]
#[endpoint(setFeesBurnPercentage)]
fn set_fees_burn_percentage(&self, fees_burn_percentage: u64) {
require!(
fees_burn_percentage <= MAX_PENALTY_PERCENTAGE,
"Fees burn percentage exceeds the maximum allowed percentage"
);
self.fees_burn_percentage().set(fees_burn_percentage);
}

fn burn_penalty(&self, payment: EsdtTokenPayment) {
let fees_burn_percentage = self.fees_burn_percentage().get();
let burn_amount = &payment.amount * fees_burn_percentage / MAX_PENALTY_PERCENTAGE;
let remaining_amount = &payment.amount - &burn_amount;

self.send()
.esdt_local_burn(&payment.token_identifier, payment.token_nonce, &burn_amount);
self.send().esdt_non_zero_local_burn(
&payment.token_identifier,
payment.token_nonce,
&burn_amount,
);

self.send_fees_to_collector(EsdtTokenPayment::new(
payment.token_identifier,
Expand Down
5 changes: 3 additions & 2 deletions locked-asset/token-unstake/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: 10
// Endpoints: 11
// Async Callback (empty): 1
// Total number of exported functions: 13
// Total number of exported functions: 14

#![no_std]

Expand All @@ -26,6 +26,7 @@ multiversx_sc_wasm_adapter::endpoints! {
cancelUnbond => cancel_unbond
depositUserTokens => deposit_user_tokens
depositFees => deposit_fees
setFeesBurnPercentage => set_fees_burn_percentage
getFeesBurnPercentage => fees_burn_percentage
getFeesCollectorAddress => fees_collector_address
setEnergyFactoryAddress => set_energy_factory_address
Expand Down

0 comments on commit aa4dd02

Please sign in to comment.