Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Fix interpretation of MinCreateBond
Browse files Browse the repository at this point in the history
  • Loading branch information
kianenigma committed Apr 19, 2022
1 parent 4d389f5 commit cb56178
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions frame/nomination-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,15 @@ impl<T: Config> Delegator<T> {
self.active_points().saturating_add(self.unbonding_points())
}

pub(crate) fn active_balance(&self) -> BalanceOf<T> {
if let Some(pool) = BondedPool::<T>::get(self.pool_id).defensive() {
// TODO: this function is questionable in both name and implementation.
pool.balance_to_unbond(self.points)
} else {
Zero::zero()
}
}

/// Active points of the delegator.
pub(crate) fn active_points(&self) -> BalanceOf<T> {
self.points
Expand Down Expand Up @@ -747,10 +756,15 @@ impl<T: Config> BondedPool<T> {
// only the depositor can partially unbond, and they can only unbond up to the
// threshold.
ensure!(is_permissioned, Error::<T>::DoesNotHavePermission);
let new_depositor_points =
target_delegator.active_points().saturating_sub(unbonding_points);
let balance_after_unbond = {
let new_depositor_points =
target_delegator.active_points().saturating_sub(unbonding_points);
let mut delegator_after_unbond = target_delegator.clone();
delegator_after_unbond.points = new_depositor_points;
delegator_after_unbond.active_balance()
};
ensure!(
new_depositor_points >= MinCreateBond::<T>::get(),
balance_after_unbond >= MinCreateBond::<T>::get(),
Error::<T>::NotOnlyDelegator
);
}
Expand Down

0 comments on commit cb56178

Please sign in to comment.