Skip to content

Commit 050cc61

Browse files
committed
return the actual unlocked amount for events and use zero values if there is no withdrawal
1 parent ca17612 commit 050cc61

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

crates/pallet-domains/src/staking.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ pub(crate) fn do_unlock_funds<T: Config>(
842842
});
843843
}
844844

845-
Ok(amount_to_release)
845+
Ok(amount_to_unlock)
846846
})
847847
}
848848

@@ -886,16 +886,19 @@ pub(crate) fn do_unlock_operator<T: Config>(operator_id: OperatorId) -> Result<(
886886
// if the withdrawals has share price noted, then convert them to SSC
887887
// if no share price, then it must be intitated in the epoch when operator was slashed,
888888
// so get the shares as is and include them in the total staked shares.
889-
let mut withdrawal =
890-
Withdrawals::<T>::take(operator_id, nominator_id.clone()).unwrap_or_default();
891-
do_convert_previous_epoch_withdrawal::<T>(operator_id, &mut withdrawal)?;
892-
let (amount_ready_to_withdraw, shares_withdrew_in_current_epoch) = (
893-
withdrawal.total_withdrawal_amount,
894-
withdrawal
895-
.withdrawal_in_shares
896-
.map(|(_, _, shares)| shares)
897-
.unwrap_or_default(),
898-
);
889+
let (amount_ready_to_withdraw, shares_withdrew_in_current_epoch) =
890+
Withdrawals::<T>::take(operator_id, nominator_id.clone())
891+
.map(|mut withdrawal| {
892+
do_convert_previous_epoch_withdrawal::<T>(operator_id, &mut withdrawal)?;
893+
Ok((
894+
withdrawal.total_withdrawal_amount,
895+
withdrawal
896+
.withdrawal_in_shares
897+
.map(|(_, _, shares)| shares)
898+
.unwrap_or_default(),
899+
))
900+
})
901+
.unwrap_or(Ok((Zero::zero(), Zero::zero())))?;
899902

900903
// include all the known shares and shares that were withdrawn in the current epoch
901904
let nominator_shares = deposit

crates/pallet-domains/src/staking_epoch.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -344,16 +344,22 @@ pub(crate) fn do_finalize_slashed_operators<T: Config>(
344344

345345
// there maybe some withdrawals that are initiated in this epoch where operator was slashed
346346
// then collect and include them to find the final stake amount
347-
let mut withdrawal = Withdrawals::<T>::take(operator_id, nominator_id.clone())
348-
.unwrap_or_default();
349-
do_convert_previous_epoch_withdrawal::<T>(operator_id, &mut withdrawal)?;
350-
let (amount_ready_to_withdraw, shares_withdrew_in_current_epoch) = (
351-
withdrawal.total_withdrawal_amount,
352-
withdrawal
353-
.withdrawal_in_shares
354-
.map(|(_, _, shares)| shares)
355-
.unwrap_or_default(),
356-
);
347+
let (amount_ready_to_withdraw, shares_withdrew_in_current_epoch) =
348+
Withdrawals::<T>::take(operator_id, nominator_id.clone())
349+
.map(|mut withdrawal| {
350+
do_convert_previous_epoch_withdrawal::<T>(
351+
operator_id,
352+
&mut withdrawal,
353+
)?;
354+
Ok((
355+
withdrawal.total_withdrawal_amount,
356+
withdrawal
357+
.withdrawal_in_shares
358+
.map(|(_, _, shares)| shares)
359+
.unwrap_or_default(),
360+
))
361+
})
362+
.unwrap_or(Ok((Zero::zero(), Zero::zero())))?;
357363

358364
// include all the known shares and shares that were withdrawn in the current epoch
359365
let nominator_shares = deposit

0 commit comments

Comments
 (0)