Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the ability to moving a portion of a stake from one subnet to another #749

Open
wants to merge 35 commits into
base: rao
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a02c3f1
Adding the ability to moving a portion of a stake from one subnet to …
roman-opentensor Aug 23, 2024
4a500dc
add checker if amount_moved <= origin_alpha
roman-opentensor Aug 23, 2024
110a004
add zero amount_moved and related Error
roman-opentensor Aug 26, 2024
3800307
fix unit test
open-junius Sep 5, 2024
ebe8dc6
fix more clippy
open-junius Sep 5, 2024
b3cfe62
fix clippy
open-junius Sep 5, 2024
490bbb8
fix last reference clippy
open-junius Sep 5, 2024
6456729
fix hotkey reference
open-junius Sep 5, 2024
130e9ca
fix clippy
open-junius Sep 6, 2024
ec31039
fmt code
open-junius Sep 6, 2024
68bc847
fix clippy
open-junius Sep 6, 2024
4b333bd
fix all clippy
open-junius Sep 6, 2024
d8c63b1
fix lint in test files
open-junius Sep 6, 2024
843565a
fix pallet manual inspect
open-junius Sep 6, 2024
044c04a
allow clippy in test
open-junius Sep 6, 2024
2df4df5
fix more clippy in test
open-junius Sep 6, 2024
21c4a0a
fix clippy of pallet in test
open-junius Sep 6, 2024
23b77c8
fix clippy in runtime
open-junius Sep 6, 2024
c18d526
fix test cases
open-junius Sep 6, 2024
2130fb4
fix test case
open-junius Sep 6, 2024
1c8dd97
Merge pull request #782 from opentensor/junius/fix/stake-move-add-amount
open-junius Sep 6, 2024
68e9344
feature set stakes
open-junius Sep 9, 2024
8e2a85b
add doc for set stakes
open-junius Sep 9, 2024
6377c95
keep
open-junius Sep 9, 2024
7e7dbd7
revert set stakes
open-junius Sep 9, 2024
e8f33f8
update extrinsic signature
open-junius Sep 9, 2024
ba76de8
correct extrinsic
open-junius Sep 10, 2024
0a6f45c
fix tests
open-junius Sep 10, 2024
208738e
fix all tests
open-junius Sep 10, 2024
9dc1361
more test cases
open-junius Sep 10, 2024
df66e66
fix wrong locks
open-junius Sep 10, 2024
481c8f4
more unit tests for lock
open-junius Sep 10, 2024
28f4232
complete the pr
open-junius Sep 11, 2024
411af02
update event type
open-junius Sep 20, 2024
8210981
Merge pull request #789 from opentensor/junius/feat/set-stake
open-junius Sep 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,9 @@ mod dispatches {
destination_hotkey: T::AccountId,
origin_netuid: u16,
destination_netuid: u16,
amount_moved: Option<u64>,
) -> DispatchResult {
Self::do_move_stake(origin, origin_hotkey, destination_hotkey, origin_netuid, destination_netuid)
Self::do_move_stake(origin, origin_hotkey, destination_hotkey, origin_netuid, destination_netuid, amount_moved)
}
}
}
9 changes: 8 additions & 1 deletion pallets/subtensor/src/staking/move_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ impl<T: Config> Pallet<T> {
destination_hotkey: T::AccountId,
origin_netuid: u16,
destination_netuid: u16,
amount_moved: Option<u64>,
) -> dispatch::DispatchResult {
// --- 1. Check that the origin is signed by the origin_hotkey.
let coldkey = ensure_signed(origin)?;
Expand Down Expand Up @@ -66,14 +67,20 @@ impl<T: Config> Pallet<T> {
}

// --- 6. Get the current alpha stake for the origin hotkey-coldkey pair in the origin subnet
// or use amount_moved
let origin_alpha = Alpha::<T>::get((origin_hotkey.clone(), coldkey.clone(), origin_netuid));

let move_alpha = match amount_moved {
Some(amount) if amount <= origin_alpha => amount,
_ => origin_alpha,
};

// --- 7. Unstake the full amount of alpha from the origin subnet, converting it to TAO
let origin_tao = Self::unstake_from_subnet(
&origin_hotkey.clone(),
&coldkey.clone(),
origin_netuid,
origin_alpha,
move_alpha,
);

// --- 8. Stake the resulting TAO into the destination subnet for the destination hotkey
Expand Down
Loading