Skip to content

Commit

Permalink
remove all stake wip
Browse files Browse the repository at this point in the history
  • Loading branch information
camfairchild committed Dec 19, 2024
1 parent 5e09c1e commit a480b2f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions pallets/subtensor/src/staking/move_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,42 @@ impl<T: Config> Pallet<T> {
// -- 8. Ok and return.
Ok(())
}

pub fn do_remove_all_stake(
coldkey: T::AccountId,
hotkey: T::AccountId,
netuids: Vec<u16>,
) -> dispatch::DispatchResult {
ensure!(Self::hotkey_account_exists(&hotkey), Error::<T>::HotKeyAccountNotExists);

// Check that all subnets exist
ensure!(netuids.all(|netuid| Self::if_subnet_exist(netuid)), Error::<T>::SubnetNotExists);

// If no subnets are specified, remove all stake from all subnets
if netuids.is_empty() {
netuids = Self::get_all_netuids_for_hotkey_and_coldkey(&hotkey, &coldkey);
}

Self::try_increase_staking_counter(&coldkey, &hotkey)?;

// Set last block for rate limiting
let current_block = Self::get_current_block_as_u64();
Self::set_last_tx_block(&coldkey, current_block);

for netuid in netuids {
// Check alpha on each netuid
let alpha = Alpha::<T>::get((hotkey.clone(), netuid, coldkey.clone()));
if alpha > 0 {
// Unstake the alpha
Self::unstake_from_subnet(
&hotkey.clone(),
&coldkey.clone(),
netuid,
alpha,
);
}
}

Ok(())
}
}

0 comments on commit a480b2f

Please sign in to comment.