Skip to content

Commit 752abc2

Browse files
committed
Re-add move_stake extrinsic and tests
1 parent 7bbba0a commit 752abc2

File tree

6 files changed

+834
-1
lines changed

6 files changed

+834
-1
lines changed

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,5 +1555,46 @@ mod dispatches {
15551555
pub fn unstake_all_alpha(origin: OriginFor<T>, hotkey: T::AccountId) -> DispatchResult {
15561556
Self::do_unstake_all_alpha(origin, hotkey)
15571557
}
1558+
1559+
/// ---- The implementation for the extrinsic move_stake: Moves specified amount of stake from a hotkey to another across subnets.
1560+
///
1561+
/// # Args:
1562+
/// * `origin` - (<T as frame_system::Config>::Origin):
1563+
/// - The signature of the caller's coldkey.
1564+
///
1565+
/// * `origin_hotkey` (T::AccountId):
1566+
/// - The hotkey account to move stake from.
1567+
///
1568+
/// * `destination_hotkey` (T::AccountId):
1569+
/// - The hotkey account to move stake to.
1570+
///
1571+
/// * `origin_netuid` (T::AccountId):
1572+
/// - The subnet ID to move stake from.
1573+
///
1574+
/// * `destination_netuid` (T::AccountId):
1575+
/// - The subnet ID to move stake to.
1576+
///
1577+
/// * `alpha_amount` (T::AccountId):
1578+
/// - The alpha stake amount to move.
1579+
///
1580+
#[pallet::call_index(85)]
1581+
#[pallet::weight((Weight::from_parts(3_000_000, 0).saturating_add(T::DbWeight::get().writes(1)), DispatchClass::Operational, Pays::No))]
1582+
pub fn move_stake(
1583+
origin: T::RuntimeOrigin,
1584+
origin_hotkey: T::AccountId,
1585+
destination_hotkey: T::AccountId,
1586+
origin_netuid: u16,
1587+
destination_netuid: u16,
1588+
alpha_amount: u64,
1589+
) -> DispatchResult {
1590+
Self::do_move_stake(
1591+
origin,
1592+
origin_hotkey,
1593+
destination_hotkey,
1594+
origin_netuid,
1595+
destination_netuid,
1596+
alpha_amount,
1597+
)
1598+
}
15581599
}
15591600
}

pallets/subtensor/src/macros/events.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ mod events {
1717
StakeAdded(T::AccountId, T::AccountId, u64, u64, u16),
1818
/// stake has been removed from the hotkey staking account onto the coldkey account.
1919
StakeRemoved(T::AccountId, T::AccountId, u64, u64, u16),
20+
/// stake has been moved from origin (hotkey, subnet ID) to destination (hotkey, subnet ID).
21+
StakeMoved(T::AccountId, T::AccountId, u16, T::AccountId, u16, u64),
2022
/// a caller successfully sets their weights on a subnetwork.
2123
WeightsSet(u16, u16),
2224
/// a new neuron account has been registered to the chain.

pallets/subtensor/src/staking/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub mod add_stake;
33
pub mod decrease_take;
44
pub mod helpers;
55
pub mod increase_take;
6+
pub mod move_stake;
67
pub mod remove_stake;
78
pub mod set_children;
89
pub mod stake_utils;

pallets/subtensor/src/staking/move_stake.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ impl<T: Config> Pallet<T> {
5757
);
5858

5959
// --- 6. Get the current alpha stake for the origin hotkey-coldkey pair in the origin subnet
60-
let origin_alpha = Self::get_stake_for_hotkey_and_coldkey_on_subnet( &origin_hotkey, &coldkey, origin_netuid );
60+
let origin_alpha = Self::get_stake_for_hotkey_and_coldkey_on_subnet(
61+
&origin_hotkey,
62+
&coldkey,
63+
origin_netuid,
64+
);
6165
ensure!(
6266
alpha_amount <= origin_alpha,
6367
Error::<T>::NotEnoughStakeToWithdraw
@@ -94,6 +98,7 @@ impl<T: Config> Pallet<T> {
9498
origin_netuid,
9599
destination_hotkey,
96100
destination_netuid,
101+
origin_tao,
97102
));
98103

99104
// -- 10. Ok and return.

pallets/subtensor/src/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod epoch;
77
mod math;
88
mod migration;
99
mod mock;
10+
mod move_stake;
1011
mod networks;
1112
mod neuron_info;
1213
mod registration;

0 commit comments

Comments
 (0)