Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug and update logic for deposit_extra #107

Merged
merged 1 commit into from
Nov 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should get the ledger after clear_mature_deposits.

I'll update this later.


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