Skip to content

Commit

Permalink
Merge pull request #1226 from bifrost-finance/998-fixes-herry
Browse files Browse the repository at this point in the history
998 fixes herry
  • Loading branch information
herryho authored Apr 17, 2024
2 parents 5209901 + a150384 commit 6afe01a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
16 changes: 9 additions & 7 deletions pallets/channel-commission/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,16 +897,18 @@ impl<T: Config> SlpHostingFeeProvider<CurrencyId, BalanceOf<T>, AccountIdOf<T>>

// get the commission token of the staking token
let vtoken = staking_token.to_vtoken().map_err(|_| Error::<T>::ConversionError)?;
let commission_token = CommissionTokens::<T>::get(vtoken)
.ok_or(Error::<T>::VtokenNotConfiguredForCommission)?;

// add to PeriodTotalCommissions
let mut total_commission = PeriodTotalCommissions::<T>::get(commission_token);
// if the vtoken is not configured for commission, just don't record the hosting fee
if let Some(commission_token) = CommissionTokens::<T>::get(vtoken) {
// add to PeriodTotalCommissions
let mut total_commission = PeriodTotalCommissions::<T>::get(commission_token);

let sum_up_amount = total_commission.1.checked_add(&amount).ok_or(Error::<T>::Overflow)?;
let sum_up_amount =
total_commission.1.checked_add(&amount).ok_or(Error::<T>::Overflow)?;

total_commission.1 = sum_up_amount;
PeriodTotalCommissions::<T>::insert(commission_token, total_commission);
total_commission.1 = sum_up_amount;
PeriodTotalCommissions::<T>::insert(commission_token, total_commission);
}

Ok(())
}
Expand Down
11 changes: 5 additions & 6 deletions pallets/slp/src/agents/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,12 @@ impl<T: Config> Pallet<T> {
ensure!(fee <= reserved_fee, Error::<T>::FeeTooHigh);

let source_account = Self::native_multilocation_to_account(&source_location)?;
// ensure the fee source account has the balance of currency_id
T::MultiCurrency::ensure_can_withdraw(currency_id, &source_account, fee)
.map_err(|_| Error::<T>::NotEnoughBalance)?;

// withdraw
T::MultiCurrency::withdraw(currency_id, &source_account, fee)
.map_err(|_| Error::<T>::NotEnoughBalance)?;
// withdraw. If withdraw fails, issue an event and continue.
if let Err(_) = T::MultiCurrency::withdraw(currency_id, &source_account, fee) {
// Deposit event
Self::deposit_event(Event::BurnFeeFailed { currency_id, amount: fee });
}

Ok(())
}
Expand Down
18 changes: 11 additions & 7 deletions pallets/slp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,10 @@ pub mod pallet {
// still to iterate num
num_left: u32,
},
BurnFeeFailed {
currency_id: CurrencyId,
amount: BalanceOf<T>,
},
}

/// The current storage version, we set to 3 our new version(after migrate stroage from vec t
Expand Down Expand Up @@ -2412,14 +2416,14 @@ pub mod pallet {
let token_index = T::StablePoolHandler::get_pool_token_index(pool_id, token)
.ok_or(Error::<T>::StablePoolTokenIndexNotFound)?;

// ensure swap balance not exceed a 10 unit
let metadata = T::AssetIdMaps::get_currency_metadata(token)
.ok_or(Error::<T>::NotSupportedCurrencyId)?;
let decimals = metadata.decimals;
// get the vtoken balance of the treasury account
let source_vtoken_balance =
T::MultiCurrency::free_balance(vtoken, &T::TreasuryAccount::get());

// max_amount is 1% of the vtoken balance of the treasury account
let percentage = Permill::from_percent(1);
let max_amount = percentage.mul_floor(source_vtoken_balance);

// 10 * 10^decimals
let max_amount: u128 =
10u128.pow(decimals.into()).checked_mul(10).ok_or(Error::<T>::OverFlow)?;
ensure!(
amount <= BalanceOf::<T>::unique_saturated_from(max_amount),
Error::<T>::ExceedLimit
Expand Down

0 comments on commit 6afe01a

Please sign in to comment.