Skip to content

Commit

Permalink
Re-add move_stake extrinsic and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gztensor committed Jan 15, 2025
1 parent 7bbba0a commit 752abc2
Show file tree
Hide file tree
Showing 6 changed files with 834 additions and 1 deletion.
41 changes: 41 additions & 0 deletions pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1555,5 +1555,46 @@ mod dispatches {
pub fn unstake_all_alpha(origin: OriginFor<T>, hotkey: T::AccountId) -> DispatchResult {
Self::do_unstake_all_alpha(origin, hotkey)
}

/// ---- The implementation for the extrinsic move_stake: Moves specified amount of stake from a hotkey to another across subnets.
///
/// # Args:
/// * `origin` - (<T as frame_system::Config>::Origin):
/// - The signature of the caller's coldkey.
///
/// * `origin_hotkey` (T::AccountId):
/// - The hotkey account to move stake from.
///
/// * `destination_hotkey` (T::AccountId):
/// - The hotkey account to move stake to.
///
/// * `origin_netuid` (T::AccountId):
/// - The subnet ID to move stake from.
///
/// * `destination_netuid` (T::AccountId):
/// - The subnet ID to move stake to.
///
/// * `alpha_amount` (T::AccountId):
/// - The alpha stake amount to move.
///
#[pallet::call_index(85)]
#[pallet::weight((Weight::from_parts(3_000_000, 0).saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))]
pub fn move_stake(
origin: T::RuntimeOrigin,
origin_hotkey: T::AccountId,
destination_hotkey: T::AccountId,
origin_netuid: u16,
destination_netuid: u16,
alpha_amount: u64,
) -> DispatchResult {
Self::do_move_stake(
origin,
origin_hotkey,
destination_hotkey,
origin_netuid,
destination_netuid,
alpha_amount,
)
}
}
}
2 changes: 2 additions & 0 deletions pallets/subtensor/src/macros/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ mod events {
StakeAdded(T::AccountId, T::AccountId, u64, u64, u16),
/// stake has been removed from the hotkey staking account onto the coldkey account.
StakeRemoved(T::AccountId, T::AccountId, u64, u64, u16),
/// stake has been moved from origin (hotkey, subnet ID) to destination (hotkey, subnet ID).
StakeMoved(T::AccountId, T::AccountId, u16, T::AccountId, u16, u64),
/// a caller successfully sets their weights on a subnetwork.
WeightsSet(u16, u16),
/// a new neuron account has been registered to the chain.
Expand Down
1 change: 1 addition & 0 deletions pallets/subtensor/src/staking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod add_stake;
pub mod decrease_take;
pub mod helpers;
pub mod increase_take;
pub mod move_stake;
pub mod remove_stake;
pub mod set_children;
pub mod stake_utils;
7 changes: 6 additions & 1 deletion pallets/subtensor/src/staking/move_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ impl<T: Config> Pallet<T> {
);

// --- 6. Get the current alpha stake for the origin hotkey-coldkey pair in the origin subnet
let origin_alpha = Self::get_stake_for_hotkey_and_coldkey_on_subnet( &origin_hotkey, &coldkey, origin_netuid );
let origin_alpha = Self::get_stake_for_hotkey_and_coldkey_on_subnet(
&origin_hotkey,
&coldkey,
origin_netuid,
);
ensure!(
alpha_amount <= origin_alpha,
Error::<T>::NotEnoughStakeToWithdraw
Expand Down Expand Up @@ -94,6 +98,7 @@ impl<T: Config> Pallet<T> {
origin_netuid,
destination_hotkey,
destination_netuid,
origin_tao,
));

// -- 10. Ok and return.
Expand Down
1 change: 1 addition & 0 deletions pallets/subtensor/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod epoch;
mod math;
mod migration;
mod mock;
mod move_stake;
mod networks;
mod neuron_info;
mod registration;
Expand Down
Loading

0 comments on commit 752abc2

Please sign in to comment.