Skip to content

Commit

Permalink
revert old matching clear logic (#1711)
Browse files Browse the repository at this point in the history
Signed-off-by: Cheng JIANG <[email protected]>
  • Loading branch information
GopherJ authored May 4, 2022
1 parent 9453ff5 commit df016aa
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions pallets/liquid-staking/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,22 @@ impl<Balance: BalanceT + FixedPointOperand> MatchingLedger<Balance> {
}

fn clear(&mut self) -> DispatchResult {
if !self.total_stake_amount.reserved.is_zero()
|| !self.total_unstake_amount.reserved.is_zero()
{
return Ok(());
}

if self.total_stake_amount.total != self.total_unstake_amount.total {
let total_free_stake_amount = self.total_stake_amount.free()?;
let total_free_unstake_amount = self.total_unstake_amount.free()?;
if total_free_stake_amount != total_free_unstake_amount {
return Ok(());
}

self.total_stake_amount.total = Zero::zero();
self.total_unstake_amount.total = Zero::zero();

self.total_stake_amount.total = self
.total_stake_amount
.total
.checked_sub(&total_free_stake_amount)
.ok_or(ArithmeticError::Underflow)?;
self.total_unstake_amount.total = self
.total_unstake_amount
.total
.checked_sub(&total_free_stake_amount)
.ok_or(ArithmeticError::Underflow)?;
Ok(())
}
}
Expand Down

0 comments on commit df016aa

Please sign in to comment.