Skip to content

Commit

Permalink
Merge pull request #107 from AurevoirXavier/fix-bug
Browse files Browse the repository at this point in the history
fix bug and update logic for `deposit_extra`
  • Loading branch information
hackfisher authored Nov 23, 2019
2 parents 88fc3f1 + a66a57d commit 2e7b2b0
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions srml/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,40 +583,35 @@ decl_module! {
/// called by controller
fn deposit_extra(origin, value: RingBalanceOf<T>, promise_month: u32) {
let controller = ensure_signed(origin)?;

ensure!(promise_month <= 36, "months at most is 36.");
let mut ledger = Self::ledger(&controller).ok_or("not a controller")?;

ensure!(promise_month >= 3 && promise_month <= 36, "months at least is 3 and at most is 36.");

Self::clear_mature_deposits(&controller);

let now = <timestamp::Module<T>>::now();
let StakingLedger {
stash,
active_ring,
active_deposit_ring,
deposit_items,
stash,
..
} = &mut ledger;

Self::clear_mature_deposits(&controller);

let value = value.min(*active_ring - *active_deposit_ring); // active_normal_ring
// for now, kton_return is free
// mint kton
let kton_return = inflation::compute_kton_return::<T>(value, promise_month);
let kton_positive_imbalance = T::Kton::deposit_creating(stash, kton_return);

let now = <timestamp::Module<T>>::now();
T::KtonReward::on_unbalanced(kton_positive_imbalance);
*active_deposit_ring += value;
deposit_items.push(TimeDepositItem {
value,
start_time: now,
expire_time: now + (MONTH_IN_SECONDS * promise_month).into(),
});

if promise_month >= 3 {
// update active_deposit_ring
*active_deposit_ring += value;

// for now, kton_return is free
// mint kton
let kton_return = inflation::compute_kton_return::<T>(value, promise_month);
let kton_positive_imbalance = T::Kton::deposit_creating(stash, kton_return);
T::KtonReward::on_unbalanced(kton_positive_imbalance);

let expire_time = now + (MONTH_IN_SECONDS * promise_month).into();
deposit_items.push(TimeDepositItem {
value,
start_time: now,
expire_time,
});
}
<Ledger<T>>::insert(&controller, ledger);
}

fn claim_mature_deposits(origin) {
Expand Down

0 comments on commit 2e7b2b0

Please sign in to comment.