@@ -629,15 +629,15 @@ where
629
629
return Err ( AccountLedgerError :: UnstakeAmountLargerThanStake ) ;
630
630
}
631
631
632
- self . staked . subtract ( amount, current_period_info . subperiod ) ;
632
+ self . staked . subtract ( amount) ;
633
633
634
634
// Convenience cleanup
635
635
if self . staked . is_empty ( ) {
636
636
self . staked = Default :: default ( ) ;
637
637
}
638
638
639
639
if let Some ( mut stake_amount) = self . staked_future {
640
- stake_amount. subtract ( amount, current_period_info . subperiod ) ;
640
+ stake_amount. subtract ( amount) ;
641
641
642
642
self . staked_future = if stake_amount. is_empty ( ) {
643
643
None
@@ -857,31 +857,22 @@ impl StakeAmount {
857
857
}
858
858
}
859
859
860
- // TODO: remove subperiod argument since it's pointless. If BEP is > 0, then it's build&earn, otherwise it's voting or build&earn but it doesn't matter.
861
-
862
- /// Unstake the specified `amount` for the specified `subperiod`.
863
- ///
864
- /// In case subperiod is `Voting`, the amount is subtracted from the voting subperiod.
860
+ /// Unstake the specified `amount`.
865
861
///
866
- /// In case subperiod is `Build&Earn`, the amount is first subtracted from the
867
- /// build&earn amount, and any rollover is subtracted from the voting subperiod.
868
- pub fn subtract ( & mut self , amount : Balance , subperiod : Subperiod ) {
869
- match subperiod {
870
- Subperiod :: Voting => self . voting . saturating_reduce ( amount) ,
871
- Subperiod :: BuildAndEarn => {
872
- if self . build_and_earn >= amount {
873
- self . build_and_earn . saturating_reduce ( amount) ;
874
- } else {
875
- // Rollover from build&earn to voting, is guaranteed to be larger than zero due to previous check
876
- // E.g. voting = 10, build&earn = 5, amount = 7
877
- // underflow = build&earn - amount = 5 - 7 = -2
878
- // voting = 10 - 2 = 8
879
- // build&earn = 0
880
- let remainder = amount. saturating_sub ( self . build_and_earn ) ;
881
- self . build_and_earn = Balance :: zero ( ) ;
882
- self . voting . saturating_reduce ( remainder) ;
883
- }
884
- }
862
+ /// Attempt to subtract from `Build&Earn` subperiod amount is done first. Any rollover is subtracted from
863
+ /// the `Voting` subperiod amount.
864
+ pub fn subtract ( & mut self , amount : Balance ) {
865
+ if self . build_and_earn >= amount {
866
+ self . build_and_earn . saturating_reduce ( amount) ;
867
+ } else {
868
+ // Rollover from build&earn to voting, is guaranteed to be larger than zero due to previous check
869
+ // E.g. voting = 10, build&earn = 5, amount = 7
870
+ // underflow = build&earn - amount = 5 - 7 = -2
871
+ // voting = 10 - 2 = 8
872
+ // build&earn = 0
873
+ let remainder = amount. saturating_sub ( self . build_and_earn ) ;
874
+ self . build_and_earn = Balance :: zero ( ) ;
875
+ self . voting . saturating_reduce ( remainder) ;
885
876
}
886
877
}
887
878
}
@@ -925,10 +916,10 @@ impl EraInfo {
925
916
self . next_stake_amount . add ( amount, subperiod) ;
926
917
}
927
918
928
- /// Subtract the specified `amount` from the appropriate stake amount, based on the `Subperiod` .
929
- pub fn unstake_amount ( & mut self , amount : Balance , subperiod : Subperiod ) {
930
- self . current_stake_amount . subtract ( amount, subperiod ) ;
931
- self . next_stake_amount . subtract ( amount, subperiod ) ;
919
+ /// Subtract the specified `amount` from the appropriate stake amount.
920
+ pub fn unstake_amount ( & mut self , amount : Balance ) {
921
+ self . current_stake_amount . subtract ( amount) ;
922
+ self . next_stake_amount . subtract ( amount) ;
932
923
}
933
924
934
925
/// Total staked amount in this era.
@@ -1040,7 +1031,7 @@ impl SingularStakingInfo {
1040
1031
. saturating_sub ( self . previous_staked . total ( ) ) ;
1041
1032
1042
1033
// Modify current staked amount
1043
- self . staked . subtract ( amount, subperiod ) ;
1034
+ self . staked . subtract ( amount) ;
1044
1035
let unstaked_amount = snapshot. total ( ) . saturating_sub ( self . staked . total ( ) ) ;
1045
1036
self . staked . era = self . staked . era . max ( current_era) ;
1046
1037
@@ -1263,13 +1254,13 @@ impl ContractStakeAmount {
1263
1254
1264
1255
for ( era, amount) in era_and_amount_pairs {
1265
1256
if self . staked . era == era {
1266
- self . staked . subtract ( amount, period_info . subperiod ) ;
1257
+ self . staked . subtract ( amount) ;
1267
1258
continue ;
1268
1259
}
1269
1260
1270
1261
match self . staked_future . as_mut ( ) {
1271
1262
Some ( future_stake_amount) if future_stake_amount. era == era => {
1272
- future_stake_amount. subtract ( amount, period_info . subperiod ) ;
1263
+ future_stake_amount. subtract ( amount) ;
1273
1264
}
1274
1265
// Otherwise do nothing
1275
1266
_ => ( ) ,
0 commit comments