Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 10 additions & 1 deletion pallets/subtensor/src/staking/add_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl<T: Config> Pallet<T> {
tao_staked.saturating_to_num::<u64>().into(),
T::SwapInterface::max_price().into(),
true,
false,
)?;

// Ok and return.
Expand Down Expand Up @@ -164,7 +165,15 @@ impl<T: Config> Pallet<T> {

// 6. Swap the stake into alpha on the subnet and increase counters.
// Emit the staking event.
Self::stake_into_subnet(&hotkey, &coldkey, netuid, tao_staked, limit_price, true)?;
Self::stake_into_subnet(
&hotkey,
&coldkey,
netuid,
tao_staked,
limit_price,
true,
false,
)?;

// Ok and return.
Ok(())
Expand Down
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 @@ -350,14 +350,18 @@ impl<T: Config> Pallet<T> {
};

if origin_netuid != destination_netuid {
// Any way to charge fees that works
let drop_fee_origin = origin_netuid == NetUid::ROOT;
let drop_fee_destination = !drop_fee_origin;

// do not pay remove fees to avoid double fees in moves transactions
let tao_unstaked = Self::unstake_from_subnet(
origin_hotkey,
origin_coldkey,
origin_netuid,
move_amount,
T::SwapInterface::min_price().into(),
true,
drop_fee_origin,
)?;

// Stake the unstaked amount into the destination.
Expand All @@ -376,6 +380,7 @@ impl<T: Config> Pallet<T> {
tao_unstaked,
T::SwapInterface::max_price().into(),
set_limit,
drop_fee_destination,
)?;
}

Expand Down
1 change: 1 addition & 0 deletions pallets/subtensor/src/staking/remove_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ impl<T: Config> Pallet<T> {
total_tao_unstaked,
T::SwapInterface::max_price().into(),
false, // no limit for Root subnet
false,
)?;

// 5. Done and ok.
Expand Down
3 changes: 2 additions & 1 deletion pallets/subtensor/src/staking/stake_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,9 +767,10 @@ impl<T: Config> Pallet<T> {
tao: TaoCurrency,
price_limit: TaoCurrency,
set_limit: bool,
drop_fees: bool,
) -> Result<AlphaCurrency, DispatchError> {
// Swap the tao to alpha.
let swap_result = Self::swap_tao_for_alpha(netuid, tao, price_limit, false)?;
let swap_result = Self::swap_tao_for_alpha(netuid, tao, price_limit, drop_fees)?;

ensure!(swap_result.amount_paid_out > 0, Error::<T>::AmountTooLow);

Expand Down
1 change: 1 addition & 0 deletions pallets/subtensor/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,7 @@ pub fn increase_stake_on_coldkey_hotkey_account(
tao_staked,
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();
}
Expand Down
29 changes: 29 additions & 0 deletions pallets/subtensor/src/tests/move_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fn test_do_move_success() {
stake_amount,
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
Expand Down Expand Up @@ -111,6 +112,7 @@ fn test_do_move_different_subnets() {
stake_amount.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
Expand Down Expand Up @@ -180,6 +182,7 @@ fn test_do_move_nonexistent_subnet() {
stake_amount.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
Expand Down Expand Up @@ -283,6 +286,7 @@ fn test_do_move_nonexistent_destination_hotkey() {
stake_amount.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();

Expand Down Expand Up @@ -347,6 +351,7 @@ fn test_do_move_partial_stake() {
total_stake.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
Expand Down Expand Up @@ -415,6 +420,7 @@ fn test_do_move_multiple_times() {
initial_stake.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();
let alpha =
Expand Down Expand Up @@ -486,6 +492,7 @@ fn test_do_move_wrong_origin() {
stake_amount.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
Expand Down Expand Up @@ -552,6 +559,7 @@ fn test_do_move_same_hotkey_fails() {
stake_amount.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();
let alpha =
Expand Down Expand Up @@ -602,6 +610,7 @@ fn test_do_move_event_emission() {
stake_amount.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
Expand Down Expand Up @@ -662,6 +671,7 @@ fn test_do_move_storage_updates() {
stake_amount.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();

Expand Down Expand Up @@ -728,6 +738,7 @@ fn test_move_full_amount_same_netuid() {
stake_amount.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();

Expand Down Expand Up @@ -795,6 +806,7 @@ fn test_do_move_max_values() {
max_stake.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
Expand Down Expand Up @@ -900,6 +912,7 @@ fn test_do_transfer_success() {
stake_amount.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
Expand Down Expand Up @@ -1008,6 +1021,7 @@ fn test_do_transfer_insufficient_stake() {
stake_amount.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();

Expand Down Expand Up @@ -1048,6 +1062,7 @@ fn test_do_transfer_wrong_origin() {
stake_amount.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();

Expand Down Expand Up @@ -1085,6 +1100,7 @@ fn test_do_transfer_minimum_stake_check() {
stake_amount,
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();

Expand Down Expand Up @@ -1132,6 +1148,7 @@ fn test_do_transfer_different_subnets() {
stake_amount.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();

Expand Down Expand Up @@ -1197,6 +1214,7 @@ fn test_do_swap_success() {
stake_amount.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();
let alpha_before = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
Expand Down Expand Up @@ -1304,6 +1322,7 @@ fn test_do_swap_insufficient_stake() {
stake_amount.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();

Expand Down Expand Up @@ -1338,6 +1357,7 @@ fn test_do_swap_wrong_origin() {
stake_amount.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();

Expand Down Expand Up @@ -1375,6 +1395,7 @@ fn test_do_swap_minimum_stake_check() {
total_stake,
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();

Expand Down Expand Up @@ -1410,6 +1431,7 @@ fn test_do_swap_same_subnet() {
stake_amount.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();

Expand Down Expand Up @@ -1454,6 +1476,7 @@ fn test_do_swap_partial_stake() {
total_stake_tao.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();
let total_stake_alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
Expand Down Expand Up @@ -1505,6 +1528,7 @@ fn test_do_swap_storage_updates() {
stake_amount.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();

Expand Down Expand Up @@ -1564,6 +1588,7 @@ fn test_do_swap_multiple_times() {
initial_stake.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();

Expand Down Expand Up @@ -1634,6 +1659,7 @@ fn test_do_swap_allows_non_owned_hotkey() {
stake_amount.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();
let alpha_before = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
Expand Down Expand Up @@ -1781,6 +1807,7 @@ fn test_transfer_stake_rate_limited() {
stake_amount.into(),
<Test as Config>::SwapInterface::max_price().into(),
true,
false,
)
.unwrap();
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
Expand Down Expand Up @@ -1825,6 +1852,7 @@ fn test_transfer_stake_doesnt_limit_destination_coldkey() {
stake_amount.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
Expand Down Expand Up @@ -1870,6 +1898,7 @@ fn test_swap_stake_limits_destination_netuid() {
stake_amount.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
Expand Down
6 changes: 6 additions & 0 deletions pallets/subtensor/src/tests/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ fn test_remove_stake_insufficient_liquidity() {
amount_staked.into(),
<Test as Config>::SwapInterface::max_price().into(),
false,
false,
)
.unwrap();

Expand Down Expand Up @@ -4481,6 +4482,7 @@ fn test_stake_into_subnet_ok() {
amount.into(),
TaoCurrency::MAX,
false,
false,
));
let fee_rate = pallet_subtensor_swap::FeeRate::<Test>::get(NetUid::from(netuid)) as f64
/ u16::MAX as f64;
Expand Down Expand Up @@ -4534,6 +4536,7 @@ fn test_stake_into_subnet_low_amount() {
amount.into(),
TaoCurrency::MAX,
false,
false,
));
let expected_stake = AlphaCurrency::from(((amount as f64) * 0.997 / current_price) as u64);

Expand Down Expand Up @@ -4581,6 +4584,7 @@ fn test_unstake_from_subnet_low_amount() {
amount.into(),
TaoCurrency::MAX,
false,
false,
));

// Remove stake
Expand Down Expand Up @@ -4694,6 +4698,7 @@ fn test_unstake_from_subnet_prohibitive_limit() {
amount.into(),
TaoCurrency::MAX,
false,
false,
));

// Remove stake
Expand Down Expand Up @@ -4769,6 +4774,7 @@ fn test_unstake_full_amount() {
amount.into(),
TaoCurrency::MAX,
false,
false,
));

// Remove stake
Expand Down
Loading