Skip to content

Commit

Permalink
handle stake delta in ck swap func
Browse files Browse the repository at this point in the history
  • Loading branch information
camfairchild committed Nov 7, 2024
1 parent 1deb392 commit 9e41db0
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions pallets/subtensor/src/swap/swap_coldkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,20 @@ impl<T: Config> Pallet<T> {
weight.saturating_accrue(T::DbWeight::get().reads_writes(2, 2));
}

// 4. Swap total coldkey stake.
// 4. Swap StakeDeltaSinceLastEmissionDrain
for hotkey in StakingHotkeys::<T>::get(old_coldkey) {
let old_stake_delta = StakeDeltaSinceLastEmissionDrain::<T>::get(&hotkey, old_coldkey);
let new_stake_delta = StakeDeltaSinceLastEmissionDrain::<T>::get(&hotkey, new_coldkey);
StakeDeltaSinceLastEmissionDrain::<T>::insert(
&hotkey,
new_coldkey,
new_stake_delta.saturating_add(old_stake_delta),
);
StakeDeltaSinceLastEmissionDrain::<T>::remove(&hotkey, old_coldkey);
weight.saturating_accrue(T::DbWeight::get().reads_writes(2, 2));
}

// 5. Swap total coldkey stake.
// TotalColdkeyStake: MAP ( coldkey ) --> u64 | Total stake of the coldkey.
let old_coldkey_stake: u64 = TotalColdkeyStake::<T>::get(old_coldkey);
// Get the stake of the new coldkey.
Expand All @@ -183,7 +196,7 @@ impl<T: Config> Pallet<T> {
);
weight.saturating_accrue(T::DbWeight::get().reads_writes(2, 2));

// 5. Swap StakingHotkeys.
// 6. Swap StakingHotkeys.
// StakingHotkeys: MAP ( coldkey ) --> Vec<hotkeys> | Hotkeys staking for the coldkey.
let old_staking_hotkeys: Vec<T::AccountId> = StakingHotkeys::<T>::get(old_coldkey);
let mut new_staking_hotkeys: Vec<T::AccountId> = StakingHotkeys::<T>::get(new_coldkey);
Expand All @@ -197,7 +210,7 @@ impl<T: Config> Pallet<T> {
StakingHotkeys::<T>::insert(new_coldkey, new_staking_hotkeys);
weight.saturating_accrue(T::DbWeight::get().reads_writes(2, 2));

// 6. Swap hotkey owners.
// 7. Swap hotkey owners.
// Owner: MAP ( hotkey ) --> coldkey | Owner of the hotkey.
// OwnedHotkeys: MAP ( coldkey ) --> Vec<hotkeys> | Hotkeys owned by the coldkey.
let old_owned_hotkeys: Vec<T::AccountId> = OwnedHotkeys::<T>::get(old_coldkey);
Expand All @@ -216,7 +229,7 @@ impl<T: Config> Pallet<T> {
OwnedHotkeys::<T>::insert(new_coldkey, new_owned_hotkeys);
weight.saturating_accrue(T::DbWeight::get().reads_writes(2, 2));

// 7. Transfer remaining balance.
// 8. Transfer remaining balance.
// Balance: MAP ( coldkey ) --> u64 | Balance of the coldkey.
// Transfer any remaining balance from old_coldkey to new_coldkey
let remaining_balance = Self::get_coldkey_balance(old_coldkey);
Expand Down

0 comments on commit 9e41db0

Please sign in to comment.