@@ -823,3 +823,65 @@ pub fn setup_stake(
823823 ) ) ;
824824 remove_stake_rate_limit_for_tests ( hotkey, coldkey, netuid) ;
825825}
826+
827+ pub ( crate ) fn quote_remove_stake_after_alpha_fee (
828+ coldkey : & U256 ,
829+ hotkey : & U256 ,
830+ netuid : NetUid ,
831+ alpha : AlphaBalance ,
832+ ) -> ( u64 , u64 ) {
833+ if netuid. is_root ( ) {
834+ return ( alpha. into ( ) , 0 ) ;
835+ }
836+
837+ let call: RuntimeCall = RuntimeCall :: SubtensorModule ( pallet_subtensor:: Call :: remove_stake {
838+ hotkey : * hotkey,
839+ netuid,
840+ amount_unstaked : alpha,
841+ } ) ;
842+ let info =
843+ <RuntimeCall as frame_support:: dispatch:: GetDispatchInfo >:: get_dispatch_info ( & call) ;
844+ let tao_fee = pallet_transaction_payment:: Pallet :: < Test > :: compute_fee ( 0 , & info, 0 . into ( ) ) ;
845+
846+ frame_support:: storage:: with_transaction (
847+ || -> frame_support:: storage:: TransactionOutcome <
848+ Result < ( u64 , u64 ) , sp_runtime:: DispatchError > ,
849+ > {
850+ let alpha_balance =
851+ SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet ( hotkey, coldkey, netuid) ;
852+
853+ let mut alpha_fee =
854+ pallet_subtensor_swap:: Pallet :: < Test > :: get_alpha_amount_for_tao (
855+ netuid,
856+ tao_fee. into ( ) ,
857+ ) ;
858+
859+ if alpha_fee. is_zero ( ) {
860+ alpha_fee = alpha_balance;
861+ }
862+
863+ let alpha_fee = alpha_fee. min ( alpha_balance) ;
864+
865+ if !alpha_fee. is_zero ( ) {
866+ assert_ok ! ( SubtensorModule :: unstake_from_subnet(
867+ hotkey,
868+ coldkey,
869+ netuid,
870+ alpha_fee,
871+ 0 . into( ) ,
872+ true ,
873+ ) ) ;
874+ }
875+
876+ let alpha_after_fee =
877+ SubtensorModule :: get_stake_for_hotkey_and_coldkey_on_subnet (
878+ hotkey, coldkey, netuid,
879+ ) ;
880+ let quoted_alpha = alpha. min ( alpha_after_fee) ;
881+
882+ let quote = swap_alpha_to_tao ( netuid, quoted_alpha) ;
883+ frame_support:: storage:: TransactionOutcome :: Rollback ( Ok ( quote) )
884+ } ,
885+ )
886+ . expect ( "transactional quote should not fail" )
887+ }
0 commit comments