@@ -623,3 +623,152 @@ fn test_try_associate_hotkey() {
623
623
assert_eq ! ( SubtensorModule :: get_owned_hotkeys( & coldkey2) . len( ) , 0 ) ;
624
624
} ) ;
625
625
}
626
+
627
+ #[ test]
628
+ fn test_stake_fee_api ( ) {
629
+ new_test_ext ( 1 ) . execute_with ( || {
630
+ let hotkey1 = U256 :: from ( 1 ) ;
631
+ let coldkey1 = U256 :: from ( 2 ) ;
632
+ let hotkey2 = U256 :: from ( 3 ) ;
633
+ let coldkey2 = U256 :: from ( 4 ) ;
634
+
635
+ let netuid0 = 1 ;
636
+ let netuid1 = 2 ;
637
+ let root_netuid = SubtensorModule :: get_root_netuid ( ) ;
638
+
639
+ let alpha_divs = 100_000_000_000 ;
640
+ let total_hotkey_alpha = 100_000_000_000 ;
641
+ let tao_in = 100_000_000_000 ; // 100 TAO
642
+ let reciprocal_price = 2 ; // 1 / price
643
+ let stake_amount = 100_000_000_000 ;
644
+
645
+ let default_fee = DefaultStakingFee :: < Test > :: get ( ) ;
646
+
647
+ // Setup alpha out
648
+ SubnetAlphaOut :: < Test > :: insert ( netuid0, 100_000_000_000 ) ;
649
+ SubnetAlphaOut :: < Test > :: insert ( netuid1, 100_000_000_000 ) ;
650
+ // Set pools using price
651
+ SubnetAlphaIn :: < Test > :: insert ( netuid0, tao_in * reciprocal_price) ;
652
+ SubnetTAO :: < Test > :: insert ( netuid0, tao_in) ;
653
+ SubnetAlphaIn :: < Test > :: insert ( netuid1, tao_in * reciprocal_price) ;
654
+ SubnetTAO :: < Test > :: insert ( netuid1, tao_in) ;
655
+
656
+ // Setup alpha divs for hotkey1
657
+ AlphaDividendsPerSubnet :: < Test > :: insert ( netuid0, hotkey1, alpha_divs) ;
658
+ AlphaDividendsPerSubnet :: < Test > :: insert ( netuid1, hotkey1, alpha_divs) ;
659
+
660
+ // Setup total hotkey alpha for hotkey1
661
+ TotalHotkeyAlpha :: < Test > :: insert ( hotkey1, netuid0, total_hotkey_alpha) ;
662
+ TotalHotkeyAlpha :: < Test > :: insert ( hotkey1, netuid1, total_hotkey_alpha) ;
663
+
664
+ // Test stake fee for add_stake
665
+ let stake_fee_0 = SubtensorModule :: get_stake_fee (
666
+ None ,
667
+ coldkey1,
668
+ Some ( ( hotkey1, netuid0) ) ,
669
+ coldkey1,
670
+ stake_amount,
671
+ ) ; // Default for adding stake
672
+ assert_eq ! ( stake_fee_0, default_fee) ;
673
+
674
+ // Test stake fee for remove on root
675
+ let stake_fee_1 = SubtensorModule :: get_stake_fee (
676
+ Some ( ( hotkey1, root_netuid) ) ,
677
+ coldkey1,
678
+ None ,
679
+ coldkey1,
680
+ stake_amount,
681
+ ) ; // Default for removing stake from root
682
+ assert_eq ! ( stake_fee_1, default_fee) ;
683
+
684
+ // Test stake fee for move from root to non-root
685
+ let stake_fee_2 = SubtensorModule :: get_stake_fee (
686
+ Some ( ( hotkey1, root_netuid) ) ,
687
+ coldkey1,
688
+ Some ( ( hotkey1, netuid0) ) ,
689
+ coldkey1,
690
+ stake_amount,
691
+ ) ; // Default for moving stake from root to non-root
692
+ assert_eq ! ( stake_fee_2, default_fee) ;
693
+
694
+ // Test stake fee for move between hotkeys on root
695
+ let stake_fee_3 = SubtensorModule :: get_stake_fee (
696
+ Some ( ( hotkey1, root_netuid) ) ,
697
+ coldkey1,
698
+ Some ( ( hotkey2, root_netuid) ) ,
699
+ coldkey1,
700
+ stake_amount,
701
+ ) ; // Default for moving stake between hotkeys on root
702
+ assert_eq ! ( stake_fee_3, default_fee) ;
703
+
704
+ // Test stake fee for move between coldkeys on root
705
+ let stake_fee_4 = SubtensorModule :: get_stake_fee (
706
+ Some ( ( hotkey1, root_netuid) ) ,
707
+ coldkey1,
708
+ Some ( ( hotkey1, root_netuid) ) ,
709
+ coldkey2,
710
+ stake_amount,
711
+ ) ; // Default for moving stake between coldkeys on root
712
+ assert_eq ! ( stake_fee_4, default_fee) ;
713
+
714
+ // Test stake fee for *swap* from non-root to root
715
+ let stake_fee_5 = SubtensorModule :: get_stake_fee (
716
+ Some ( ( hotkey1, netuid0) ) ,
717
+ coldkey1,
718
+ Some ( ( hotkey1, root_netuid) ) ,
719
+ coldkey1,
720
+ stake_amount,
721
+ ) ; // Charged a dynamic fee
722
+ let dynamic_fee_5 = SubtensorModule :: calculate_staking_fee (
723
+ netuid0,
724
+ & hotkey1,
725
+ I96F32 :: from_num ( stake_amount) ,
726
+ ) ;
727
+ assert_eq ! ( stake_fee_5, dynamic_fee_5) ;
728
+
729
+ // Test stake fee for move between hotkeys on non-root
730
+ let stake_fee_6 = SubtensorModule :: get_stake_fee (
731
+ Some ( ( hotkey1, netuid0) ) ,
732
+ coldkey1,
733
+ Some ( ( hotkey2, netuid0) ) ,
734
+ coldkey1,
735
+ stake_amount,
736
+ ) ; // Charged a dynamic fee
737
+ let dynamic_fee_6 = SubtensorModule :: calculate_staking_fee (
738
+ netuid0,
739
+ & hotkey1,
740
+ I96F32 :: from_num ( stake_amount) ,
741
+ ) ;
742
+ assert_eq ! ( stake_fee_6, dynamic_fee_6) ;
743
+
744
+ // Test stake fee for move between coldkeys on non-root
745
+ let stake_fee_7 = SubtensorModule :: get_stake_fee (
746
+ Some ( ( hotkey1, netuid0) ) ,
747
+ coldkey1,
748
+ Some ( ( hotkey1, netuid0) ) ,
749
+ coldkey2,
750
+ stake_amount,
751
+ ) ; // Charged a dynamic fee
752
+ let dynamic_fee_7 = SubtensorModule :: calculate_staking_fee (
753
+ netuid0,
754
+ & hotkey1,
755
+ I96F32 :: from_num ( stake_amount) ,
756
+ ) ;
757
+ assert_eq ! ( stake_fee_7, dynamic_fee_7) ;
758
+
759
+ // Test stake fee for *swap* from non-root to non-root
760
+ let stake_fee_8 = SubtensorModule :: get_stake_fee (
761
+ Some ( ( hotkey1, netuid0) ) ,
762
+ coldkey1,
763
+ Some ( ( hotkey1, netuid1) ) ,
764
+ coldkey1,
765
+ stake_amount,
766
+ ) ; // Charged a dynamic fee
767
+ let dynamic_fee_8 = SubtensorModule :: calculate_staking_fee (
768
+ netuid0,
769
+ & hotkey1,
770
+ I96F32 :: from_num ( stake_amount) ,
771
+ ) ;
772
+ assert_eq ! ( stake_fee_8, dynamic_fee_8) ;
773
+ } ) ;
774
+ }
0 commit comments