From bbf2f1598637263445217fd16c54a275a7f849da Mon Sep 17 00:00:00 2001 From: linning Date: Tue, 3 Dec 2024 20:38:18 +0800 Subject: [PATCH] Minor refatoring to do_finalize_operator_epoch_staking Signed-off-by: linning --- crates/pallet-domains/src/staking_epoch.rs | 23 +++++++++------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/crates/pallet-domains/src/staking_epoch.rs b/crates/pallet-domains/src/staking_epoch.rs index 7a593590d6..fbfdf0f4d3 100644 --- a/crates/pallet-domains/src/staking_epoch.rs +++ b/crates/pallet-domains/src/staking_epoch.rs @@ -246,39 +246,34 @@ pub(crate) fn do_finalize_operator_epoch_staking( return Ok((operator.current_total_stake, false)); } - let total_stake = operator.current_total_stake; - let total_shares = operator.current_total_shares; + let mut total_stake = operator.current_total_stake; + let mut total_shares = operator.current_total_shares; let share_price = SharePrice::new::(total_shares, total_stake); // calculate and subtract total withdrew shares from previous epoch - let (total_stake, total_shares) = if !operator.withdrawals_in_epoch.is_zero() { + if !operator.withdrawals_in_epoch.is_zero() { let withdraw_stake = share_price.shares_to_stake::(operator.withdrawals_in_epoch); - let total_stake = total_stake + total_stake = total_stake .checked_sub(&withdraw_stake) .ok_or(TransitionError::BalanceUnderflow)?; - let total_shares = total_shares + total_shares = total_shares .checked_sub(&operator.withdrawals_in_epoch) .ok_or(TransitionError::ShareUnderflow)?; operator.withdrawals_in_epoch = Zero::zero(); - (total_stake, total_shares) - } else { - (total_stake, total_shares) }; // calculate and add total deposits from the previous epoch - let (total_stake, total_shares) = if !operator.deposits_in_epoch.is_zero() { + if !operator.deposits_in_epoch.is_zero() { let deposited_shares = share_price.stake_to_shares::(operator.deposits_in_epoch); - let total_stake = total_stake + total_stake = total_stake .checked_add(&operator.deposits_in_epoch) .ok_or(TransitionError::BalanceOverflow)?; - let total_shares = total_shares + total_shares = total_shares .checked_add(&deposited_shares) .ok_or(TransitionError::ShareOverflow)?; + operator.deposits_in_epoch = Zero::zero(); - (total_stake, total_shares) - } else { - (total_stake, total_shares) }; // update operator pool epoch share price