Skip to content

Commit

Permalink
query token decimals instead of vtoken (#1219)
Browse files Browse the repository at this point in the history
  • Loading branch information
herryho committed Apr 1, 2024
1 parent 63f81c3 commit a3f8dbb
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pallets/slp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub use primitives::Ledger;
use sp_arithmetic::{per_things::Permill, traits::Zero};
use sp_core::{bounded::BoundedVec, H160};
use sp_io::hashing::blake2_256;
use sp_runtime::traits::{CheckedAdd, CheckedSub, Convert, TrailingZeroInput};
use sp_runtime::traits::{CheckedAdd, CheckedSub, Convert, TrailingZeroInput, UniqueSaturatedFrom};
use sp_std::{boxed::Box, vec, vec::Vec};
pub use weights::WeightInfo;
use xcm::{
Expand Down Expand Up @@ -2413,14 +2413,17 @@ pub mod pallet {
.ok_or(Error::<T>::StablePoolTokenIndexNotFound)?;

// ensure swap balance not exceed a 10 unit
let metadata = T::AssetIdMaps::get_currency_metadata(vtoken)
let metadata = T::AssetIdMaps::get_currency_metadata(token)
.ok_or(Error::<T>::NotSupportedCurrencyId)?;
let decimals = metadata.decimals;

// 10 * 10^decimals
let max_amount =
10u32.pow(decimals.into()).checked_mul(10).ok_or(Error::<T>::OverFlow)?;
ensure!(amount <= BalanceOf::<T>::from(max_amount), Error::<T>::ExceedLimit);
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
);

// swap vtoken from treasury account for token
let treasury = T::TreasuryAccount::get();
Expand Down

0 comments on commit a3f8dbb

Please sign in to comment.