Skip to content

Commit

Permalink
fix: fix token vtoken amount
Browse files Browse the repository at this point in the history
  • Loading branch information
Akagi201 committed Jun 30, 2022
1 parent a525561 commit 2ba972b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions pallets/system-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub mod pallet {
use crate::{RoundInfo, TokenInfo};
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use sp_arithmetic::Permill;
use sp_arithmetic::{Perbill, Permill};

pub type RoundIndex = u32;

Expand Down Expand Up @@ -138,7 +138,7 @@ pub mod pallet {
add_or_sub: bool,
system_stakable_base: BalanceOf<T>,
farming_poolids: Vec<PoolId>,
lptoken_rates: Vec<Permill>,
lptoken_rates: Vec<Perbill>,
},
DepositFailed {
token: CurrencyIdOf<T>,
Expand Down Expand Up @@ -293,7 +293,7 @@ pub mod pallet {
add_or_sub: Option<bool>,
system_stakable_base: Option<BalanceOf<T>>,
farming_poolids: Option<Vec<PoolId>>,
lptoken_rates: Option<Vec<Permill>>,
lptoken_rates: Option<Vec<Perbill>>, // TODO, can be > 1
) -> DispatchResultWithPostInfo {
T::EnsureConfirmAsGovernance::ensure_origin(origin)?; // Motion

Expand Down Expand Up @@ -604,8 +604,6 @@ impl<T: Config> Pallet<T> {
<TokenInfo<BalanceOf<T>>>::default()
};

token_info.system_shadow_amount =
token_info.system_shadow_amount.saturating_sub(token_amount);
token_info.pending_redeem_amount =
token_info.pending_redeem_amount.saturating_sub(token_amount);
match T::MultiCurrency::withdraw(token_id, &to, token_amount) {
Expand All @@ -618,6 +616,8 @@ impl<T: Config> Pallet<T> {
system_shadow_amount: token_info.system_shadow_amount,
pending_redeem_amount: token_info.pending_redeem_amount,
});
token_info.system_shadow_amount =
token_info.system_shadow_amount.saturating_sub(token_amount);
},
Err(error) => {
log::warn!("{:?} withdraw error: {:?}", &token_id, error);
Expand Down
2 changes: 1 addition & 1 deletion pallets/system-staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn token_config_should_work() {
assert_eq!(token_info.new_config.system_stakable_farming_rate, Permill::from_percent(80));
assert_eq!(token_info.new_config.system_stakable_base, 100);
assert_eq!(token_info.new_config.farming_poolids, Vec::<PoolId>::new());
assert_eq!(token_info.new_config.lptoken_rates, Vec::<Permill>::new());
assert_eq!(token_info.new_config.lptoken_rates, Vec::<Perbill>::new());
});
}

Expand Down
6 changes: 3 additions & 3 deletions pallets/system-staking/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::RoundIndex;
use codec::{Decode, Encode};
use frame_support::pallet_prelude::*;
use node_primitives::PoolId;
use sp_arithmetic::per_things::Permill;
use sp_arithmetic::per_things::{Perbill, Permill};
use sp_runtime::traits::Zero;
use sp_std::prelude::*;

Expand Down Expand Up @@ -52,7 +52,7 @@ impl<

/// Check exec_delay match
pub fn check_delay(&self, now: B, delay: u32) -> bool {
now - self.first == delay.into()
now - self.first == delay.into() && delay != 0
}
}
impl<
Expand Down Expand Up @@ -102,7 +102,7 @@ impl<Balance: Copy + PartialEq> TokenInfo<Balance> {
pub struct TokenConfig<Balance> {
pub exec_delay: u32,
pub system_stakable_farming_rate: Permill,
pub lptoken_rates: Vec<Permill>,
pub lptoken_rates: Vec<Perbill>,
pub add_or_sub: bool, // true: add, false: sub
pub system_stakable_base: Balance,
pub farming_poolids: Vec<PoolId>,
Expand Down
2 changes: 1 addition & 1 deletion pallets/vtoken-minting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,8 +1181,8 @@ pub mod pallet {
let extra_weight = T::OnRedeemSuccess::on_redeemed(
exchanger.clone(),
token_id,
vtoken_amount,
token_amount,
vtoken_amount,
redeem_fee,
);

Expand Down

0 comments on commit 2ba972b

Please sign in to comment.