@@ -6,7 +6,7 @@ use frame_support::{
6
6
fungible:: { Balanced as _, Inspect as _, Mutate as _} ,
7
7
Fortitude , Precision , Preservation ,
8
8
} ,
9
- Imbalance ,
9
+ Defensive , Imbalance ,
10
10
} ,
11
11
} ;
12
12
@@ -704,11 +704,14 @@ impl<T: Config> Pallet<T> {
704
704
// TODO: Tech debt: Remove StakingHotkeys entry if stake goes to 0
705
705
}
706
706
707
- /// Empties the stake associated with a given coldkey-hotkey account pairing.
707
+ /// Empties the stake associated with a given coldkey-hotkey account pairing, and moves it to
708
+ /// the coldkey free balance.
709
+ ///
708
710
/// This function retrieves the current stake for the specified coldkey-hotkey pairing,
709
711
/// then subtracts this stake amount from both the TotalColdkeyStake and TotalHotkeyStake.
710
- /// It also removes the stake entry for the hotkey-coldkey pairing and adjusts the TotalStake
711
- /// and TotalIssuance by subtracting the removed stake amount.
712
+ ///
713
+ /// It also removes the stake entry for the hotkey-coldkey pairing and increases the coldkey
714
+ /// free balance by the amount of stake removed.
712
715
///
713
716
/// Returns the amount of stake that was removed.
714
717
///
@@ -725,13 +728,15 @@ impl<T: Config> Pallet<T> {
725
728
TotalHotkeyStake :: < T > :: mutate ( hotkey, |stake| * stake = stake. saturating_sub ( current_stake) ) ;
726
729
Stake :: < T > :: remove ( hotkey, coldkey) ;
727
730
TotalStake :: < T > :: mutate ( |stake| * stake = stake. saturating_sub ( current_stake) ) ;
728
- TotalIssuance :: < T > :: mutate ( |issuance| * issuance = issuance. saturating_sub ( current_stake) ) ;
729
731
730
732
// Update StakingHotkeys map
731
733
let mut staking_hotkeys = StakingHotkeys :: < T > :: get ( coldkey) ;
732
734
staking_hotkeys. retain ( |h| h != hotkey) ;
733
735
StakingHotkeys :: < T > :: insert ( coldkey, staking_hotkeys) ;
734
736
737
+ // Add the amount to the coldkey free balance
738
+ Self :: add_balance_to_coldkey_account ( coldkey, current_stake) ;
739
+
735
740
current_stake
736
741
}
737
742
@@ -745,11 +750,9 @@ impl<T: Config> Pallet<T> {
745
750
if !Self :: coldkey_owns_hotkey ( coldkey, hotkey) {
746
751
// If the stake is below the minimum required, it's considered a small nomination and needs to be cleared.
747
752
if stake < Self :: get_nominator_min_required_stake ( ) {
748
- // Remove the stake from the nominator account. (this is a more forceful unstake operation which )
749
- // Actually deletes the staking account.
750
- let cleared_stake = Self :: empty_stake_on_coldkey_hotkey_account ( coldkey, hotkey) ;
751
- // Add the stake to the coldkey account.
752
- Self :: add_balance_to_coldkey_account ( coldkey, cleared_stake) ;
753
+ // Remove the stake from the nominator account, and moves it to the free balance.
754
+ // This is a more forceful unstake operation which actually deletes the staking account.
755
+ Self :: empty_stake_on_coldkey_hotkey_account ( coldkey, hotkey) ;
753
756
}
754
757
}
755
758
}
@@ -769,8 +772,8 @@ impl<T: Config> Pallet<T> {
769
772
coldkey : & T :: AccountId ,
770
773
amount : <<T as Config >:: Currency as fungible:: Inspect < <T as system:: Config >:: AccountId > >:: Balance ,
771
774
) {
772
- // infallible
773
- let _ = T :: Currency :: deposit ( coldkey , amount , Precision :: BestEffort ) ;
775
+ let _ = T :: Currency :: deposit ( coldkey , amount , Precision :: BestEffort )
776
+ . defensive_proof ( "Account balance should never exceed max balance" ) ;
774
777
}
775
778
776
779
pub fn set_balance_on_coldkey_account (
0 commit comments