@@ -3885,3 +3885,65 @@ fn test_remove_99_9989_per_cent_stake_leaves_a_little() {
3885
3885
assert_abs_diff_eq ! ( new_alpha, ( alpha as f64 * 0.01 ) as u64 , epsilon = 10 ) ;
3886
3886
} ) ;
3887
3887
}
3888
+
3889
+ #[ test]
3890
+ fn test_move_stake_limit_partial ( ) {
3891
+ new_test_ext ( 1 ) . execute_with ( || {
3892
+ let subnet_owner_coldkey = U256 :: from ( 1001 ) ;
3893
+ let subnet_owner_hotkey = U256 :: from ( 1002 ) ;
3894
+ let coldkey = U256 :: from ( 1 ) ;
3895
+ let hotkey = U256 :: from ( 2 ) ;
3896
+ let stake_amount = 150_000_000_000 ;
3897
+ let move_amount = 150_000_000_000 ;
3898
+
3899
+ // add network
3900
+ let origin_netuid: u16 = add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
3901
+ let destination_netuid: u16 =
3902
+ add_dynamic_network ( & subnet_owner_hotkey, & subnet_owner_coldkey) ;
3903
+ register_ok_neuron ( origin_netuid, hotkey, coldkey, 192213123 ) ;
3904
+ register_ok_neuron ( destination_netuid, hotkey, coldkey, 192213123 ) ;
3905
+
3906
+ // Give the neuron some stake to remove
3907
+ SubtensorModule :: increase_stake_for_hotkey_and_coldkey_on_subnet (
3908
+ & hotkey,
3909
+ & coldkey,
3910
+ origin_netuid,
3911
+ stake_amount,
3912
+ ) ;
3913
+
3914
+ // Forse-set alpha in and tao reserve to make price equal 1.5 on both origin and destination,
3915
+ // but there's much more liquidity on destination, so its price wouldn't go up when restaked
3916
+ let tao_reserve: U96F32 = U96F32 :: from_num ( 150_000_000_000_u64 ) ;
3917
+ let alpha_in: U96F32 = U96F32 :: from_num ( 100_000_000_000_u64 ) ;
3918
+ SubnetTAO :: < Test > :: insert ( origin_netuid, tao_reserve. to_num :: < u64 > ( ) ) ;
3919
+ SubnetAlphaIn :: < Test > :: insert ( origin_netuid, alpha_in. to_num :: < u64 > ( ) ) ;
3920
+ SubnetTAO :: < Test > :: insert ( destination_netuid, ( tao_reserve * 100_000 ) . to_num :: < u64 > ( ) ) ;
3921
+ SubnetAlphaIn :: < Test > :: insert ( destination_netuid, ( alpha_in * 100_000 ) . to_num :: < u64 > ( ) ) ;
3922
+ let current_price: U96F32 =
3923
+ U96F32 :: from_num ( SubtensorModule :: get_alpha_price ( origin_netuid) ) ;
3924
+ assert_eq ! ( current_price, U96F32 :: from_num( 1.5 ) ) ;
3925
+
3926
+ // The relative price between origin and destination subnets is 1.
3927
+ // Setup limit relative price so that it doesn't drop by more than 1% from current price
3928
+ let limit_price = 990_000_000 ;
3929
+
3930
+ // Move stake with slippage safety - executes partially
3931
+ assert_ok ! ( SubtensorModule :: swap_stake_limit(
3932
+ RuntimeOrigin :: signed( coldkey) ,
3933
+ hotkey,
3934
+ origin_netuid,
3935
+ destination_netuid,
3936
+ move_amount,
3937
+ limit_price,
3938
+ true ,
3939
+ ) ) ;
3940
+
3941
+ let new_alpha = SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet (
3942
+ & hotkey,
3943
+ & coldkey,
3944
+ origin_netuid,
3945
+ ) ;
3946
+
3947
+ assert_abs_diff_eq ! ( new_alpha, 149_000_000_000 , epsilon = 100_000_000 , ) ;
3948
+ } ) ;
3949
+ }
0 commit comments