Skip to content

Commit 14024fd

Browse files
authored
Merge pull request #2012 from opentensor/fix/fee-bypass
Fix/fee bypass
2 parents 47038b4 + 96c70a2 commit 14024fd

File tree

7 files changed

+55
-3
lines changed

7 files changed

+55
-3
lines changed

pallets/subtensor/src/staking/add_stake.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ impl<T: Config> Pallet<T> {
7676
tao_staked.saturating_to_num::<u64>().into(),
7777
T::SwapInterface::max_price().into(),
7878
true,
79+
false,
7980
)?;
8081

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

165166
// 6. Swap the stake into alpha on the subnet and increase counters.
166167
// Emit the staking event.
167-
Self::stake_into_subnet(&hotkey, &coldkey, netuid, tao_staked, limit_price, true)?;
168+
Self::stake_into_subnet(
169+
&hotkey,
170+
&coldkey,
171+
netuid,
172+
tao_staked,
173+
limit_price,
174+
true,
175+
false,
176+
)?;
168177

169178
// Ok and return.
170179
Ok(())

pallets/subtensor/src/staking/move_stake.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,14 +350,18 @@ impl<T: Config> Pallet<T> {
350350
};
351351

352352
if origin_netuid != destination_netuid {
353+
// Any way to charge fees that works
354+
let drop_fee_origin = origin_netuid == NetUid::ROOT;
355+
let drop_fee_destination = !drop_fee_origin;
356+
353357
// do not pay remove fees to avoid double fees in moves transactions
354358
let tao_unstaked = Self::unstake_from_subnet(
355359
origin_hotkey,
356360
origin_coldkey,
357361
origin_netuid,
358362
move_amount,
359363
T::SwapInterface::min_price().into(),
360-
true,
364+
drop_fee_origin,
361365
)?;
362366

363367
// Stake the unstaked amount into the destination.
@@ -376,6 +380,7 @@ impl<T: Config> Pallet<T> {
376380
tao_unstaked,
377381
T::SwapInterface::max_price().into(),
378382
set_limit,
383+
drop_fee_destination,
379384
)?;
380385
}
381386

pallets/subtensor/src/staking/remove_stake.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ impl<T: Config> Pallet<T> {
281281
total_tao_unstaked,
282282
T::SwapInterface::max_price().into(),
283283
false, // no limit for Root subnet
284+
false,
284285
)?;
285286

286287
// 5. Done and ok.

pallets/subtensor/src/staking/stake_utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,9 +767,10 @@ impl<T: Config> Pallet<T> {
767767
tao: TaoCurrency,
768768
price_limit: TaoCurrency,
769769
set_limit: bool,
770+
drop_fees: bool,
770771
) -> Result<AlphaCurrency, DispatchError> {
771772
// Swap the tao to alpha.
772-
let swap_result = Self::swap_tao_for_alpha(netuid, tao, price_limit, false)?;
773+
let swap_result = Self::swap_tao_for_alpha(netuid, tao, price_limit, drop_fees)?;
773774

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

pallets/subtensor/src/tests/mock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,7 @@ pub fn increase_stake_on_coldkey_hotkey_account(
965965
tao_staked,
966966
<Test as Config>::SwapInterface::max_price().into(),
967967
false,
968+
false,
968969
)
969970
.unwrap();
970971
}

pallets/subtensor/src/tests/move_stake.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ fn test_do_move_success() {
3535
stake_amount,
3636
<Test as Config>::SwapInterface::max_price().into(),
3737
false,
38+
false,
3839
)
3940
.unwrap();
4041
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
@@ -111,6 +112,7 @@ fn test_do_move_different_subnets() {
111112
stake_amount.into(),
112113
<Test as Config>::SwapInterface::max_price().into(),
113114
false,
115+
false,
114116
)
115117
.unwrap();
116118
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
@@ -180,6 +182,7 @@ fn test_do_move_nonexistent_subnet() {
180182
stake_amount.into(),
181183
<Test as Config>::SwapInterface::max_price().into(),
182184
false,
185+
false,
183186
)
184187
.unwrap();
185188
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
@@ -283,6 +286,7 @@ fn test_do_move_nonexistent_destination_hotkey() {
283286
stake_amount.into(),
284287
<Test as Config>::SwapInterface::max_price().into(),
285288
false,
289+
false,
286290
)
287291
.unwrap();
288292

@@ -347,6 +351,7 @@ fn test_do_move_partial_stake() {
347351
total_stake.into(),
348352
<Test as Config>::SwapInterface::max_price().into(),
349353
false,
354+
false,
350355
)
351356
.unwrap();
352357
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
@@ -415,6 +420,7 @@ fn test_do_move_multiple_times() {
415420
initial_stake.into(),
416421
<Test as Config>::SwapInterface::max_price().into(),
417422
false,
423+
false,
418424
)
419425
.unwrap();
420426
let alpha =
@@ -486,6 +492,7 @@ fn test_do_move_wrong_origin() {
486492
stake_amount.into(),
487493
<Test as Config>::SwapInterface::max_price().into(),
488494
false,
495+
false,
489496
)
490497
.unwrap();
491498
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
@@ -552,6 +559,7 @@ fn test_do_move_same_hotkey_fails() {
552559
stake_amount.into(),
553560
<Test as Config>::SwapInterface::max_price().into(),
554561
false,
562+
false,
555563
)
556564
.unwrap();
557565
let alpha =
@@ -602,6 +610,7 @@ fn test_do_move_event_emission() {
602610
stake_amount.into(),
603611
<Test as Config>::SwapInterface::max_price().into(),
604612
false,
613+
false,
605614
)
606615
.unwrap();
607616
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
@@ -662,6 +671,7 @@ fn test_do_move_storage_updates() {
662671
stake_amount.into(),
663672
<Test as Config>::SwapInterface::max_price().into(),
664673
false,
674+
false,
665675
)
666676
.unwrap();
667677

@@ -728,6 +738,7 @@ fn test_move_full_amount_same_netuid() {
728738
stake_amount.into(),
729739
<Test as Config>::SwapInterface::max_price().into(),
730740
false,
741+
false,
731742
)
732743
.unwrap();
733744

@@ -795,6 +806,7 @@ fn test_do_move_max_values() {
795806
max_stake.into(),
796807
<Test as Config>::SwapInterface::max_price().into(),
797808
false,
809+
false,
798810
)
799811
.unwrap();
800812
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
@@ -900,6 +912,7 @@ fn test_do_transfer_success() {
900912
stake_amount.into(),
901913
<Test as Config>::SwapInterface::max_price().into(),
902914
false,
915+
false,
903916
)
904917
.unwrap();
905918
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
@@ -1008,6 +1021,7 @@ fn test_do_transfer_insufficient_stake() {
10081021
stake_amount.into(),
10091022
<Test as Config>::SwapInterface::max_price().into(),
10101023
false,
1024+
false,
10111025
)
10121026
.unwrap();
10131027

@@ -1048,6 +1062,7 @@ fn test_do_transfer_wrong_origin() {
10481062
stake_amount.into(),
10491063
<Test as Config>::SwapInterface::max_price().into(),
10501064
false,
1065+
false,
10511066
)
10521067
.unwrap();
10531068

@@ -1085,6 +1100,7 @@ fn test_do_transfer_minimum_stake_check() {
10851100
stake_amount,
10861101
<Test as Config>::SwapInterface::max_price().into(),
10871102
false,
1103+
false,
10881104
)
10891105
.unwrap();
10901106

@@ -1132,6 +1148,7 @@ fn test_do_transfer_different_subnets() {
11321148
stake_amount.into(),
11331149
<Test as Config>::SwapInterface::max_price().into(),
11341150
false,
1151+
false,
11351152
)
11361153
.unwrap();
11371154

@@ -1197,6 +1214,7 @@ fn test_do_swap_success() {
11971214
stake_amount.into(),
11981215
<Test as Config>::SwapInterface::max_price().into(),
11991216
false,
1217+
false,
12001218
)
12011219
.unwrap();
12021220
let alpha_before = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
@@ -1304,6 +1322,7 @@ fn test_do_swap_insufficient_stake() {
13041322
stake_amount.into(),
13051323
<Test as Config>::SwapInterface::max_price().into(),
13061324
false,
1325+
false,
13071326
)
13081327
.unwrap();
13091328

@@ -1338,6 +1357,7 @@ fn test_do_swap_wrong_origin() {
13381357
stake_amount.into(),
13391358
<Test as Config>::SwapInterface::max_price().into(),
13401359
false,
1360+
false,
13411361
)
13421362
.unwrap();
13431363

@@ -1375,6 +1395,7 @@ fn test_do_swap_minimum_stake_check() {
13751395
total_stake,
13761396
<Test as Config>::SwapInterface::max_price().into(),
13771397
false,
1398+
false,
13781399
)
13791400
.unwrap();
13801401

@@ -1410,6 +1431,7 @@ fn test_do_swap_same_subnet() {
14101431
stake_amount.into(),
14111432
<Test as Config>::SwapInterface::max_price().into(),
14121433
false,
1434+
false,
14131435
)
14141436
.unwrap();
14151437

@@ -1454,6 +1476,7 @@ fn test_do_swap_partial_stake() {
14541476
total_stake_tao.into(),
14551477
<Test as Config>::SwapInterface::max_price().into(),
14561478
false,
1479+
false,
14571480
)
14581481
.unwrap();
14591482
let total_stake_alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
@@ -1505,6 +1528,7 @@ fn test_do_swap_storage_updates() {
15051528
stake_amount.into(),
15061529
<Test as Config>::SwapInterface::max_price().into(),
15071530
false,
1531+
false,
15081532
)
15091533
.unwrap();
15101534

@@ -1564,6 +1588,7 @@ fn test_do_swap_multiple_times() {
15641588
initial_stake.into(),
15651589
<Test as Config>::SwapInterface::max_price().into(),
15661590
false,
1591+
false,
15671592
)
15681593
.unwrap();
15691594

@@ -1634,6 +1659,7 @@ fn test_do_swap_allows_non_owned_hotkey() {
16341659
stake_amount.into(),
16351660
<Test as Config>::SwapInterface::max_price().into(),
16361661
false,
1662+
false,
16371663
)
16381664
.unwrap();
16391665
let alpha_before = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
@@ -1781,6 +1807,7 @@ fn test_transfer_stake_rate_limited() {
17811807
stake_amount.into(),
17821808
<Test as Config>::SwapInterface::max_price().into(),
17831809
true,
1810+
false,
17841811
)
17851812
.unwrap();
17861813
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
@@ -1825,6 +1852,7 @@ fn test_transfer_stake_doesnt_limit_destination_coldkey() {
18251852
stake_amount.into(),
18261853
<Test as Config>::SwapInterface::max_price().into(),
18271854
false,
1855+
false,
18281856
)
18291857
.unwrap();
18301858
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
@@ -1870,6 +1898,7 @@ fn test_swap_stake_limits_destination_netuid() {
18701898
stake_amount.into(),
18711899
<Test as Config>::SwapInterface::max_price().into(),
18721900
false,
1901+
false,
18731902
)
18741903
.unwrap();
18751904
let alpha = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(

pallets/subtensor/src/tests/staking.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@ fn test_remove_stake_insufficient_liquidity() {
864864
amount_staked.into(),
865865
<Test as Config>::SwapInterface::max_price().into(),
866866
false,
867+
false,
867868
)
868869
.unwrap();
869870

@@ -4481,6 +4482,7 @@ fn test_stake_into_subnet_ok() {
44814482
amount.into(),
44824483
TaoCurrency::MAX,
44834484
false,
4485+
false,
44844486
));
44854487
let fee_rate = pallet_subtensor_swap::FeeRate::<Test>::get(NetUid::from(netuid)) as f64
44864488
/ u16::MAX as f64;
@@ -4534,6 +4536,7 @@ fn test_stake_into_subnet_low_amount() {
45344536
amount.into(),
45354537
TaoCurrency::MAX,
45364538
false,
4539+
false,
45374540
));
45384541
let expected_stake = AlphaCurrency::from(((amount as f64) * 0.997 / current_price) as u64);
45394542

@@ -4581,6 +4584,7 @@ fn test_unstake_from_subnet_low_amount() {
45814584
amount.into(),
45824585
TaoCurrency::MAX,
45834586
false,
4587+
false,
45844588
));
45854589

45864590
// Remove stake
@@ -4694,6 +4698,7 @@ fn test_unstake_from_subnet_prohibitive_limit() {
46944698
amount.into(),
46954699
TaoCurrency::MAX,
46964700
false,
4701+
false,
46974702
));
46984703

46994704
// Remove stake
@@ -4769,6 +4774,7 @@ fn test_unstake_full_amount() {
47694774
amount.into(),
47704775
TaoCurrency::MAX,
47714776
false,
4777+
false,
47724778
));
47734779

47744780
// Remove stake

0 commit comments

Comments
 (0)