117117 price_to_tick ,
118118 LiquidityPosition ,
119119)
120- from bittensor .utils .weight_utils import generate_weight_hash , convert_uids_and_weights
120+ from bittensor .utils .weight_utils import (
121+ generate_weight_hash ,
122+ convert_uids_and_weights ,
123+ U16_MAX ,
124+ )
121125
122126if TYPE_CHECKING :
123127 from async_substrate_interface .types import ScaleObj
@@ -2522,6 +2526,7 @@ async def get_stake(
25222526
25232527 return Balance .from_rao (int (stake )).set_unit (netuid = netuid )
25242528
2529+ # TODO: remove unused parameters in SDK.v10
25252530 async def get_stake_add_fee (
25262531 self ,
25272532 amount : Balance ,
@@ -2543,19 +2548,9 @@ async def get_stake_add_fee(
25432548 Returns:
25442549 The calculated stake fee as a Balance object
25452550 """
2546- result = await self .query_runtime_api (
2547- runtime_api = "StakeInfoRuntimeApi" ,
2548- method = "get_stake_fee" ,
2549- params = [
2550- None ,
2551- coldkey_ss58 ,
2552- (hotkey_ss58 , netuid ),
2553- coldkey_ss58 ,
2554- amount .rao ,
2555- ],
2556- block = block ,
2551+ return await self .get_stake_operations_fee (
2552+ amount = amount , netuid = netuid , block = block
25572553 )
2558- return Balance .from_rao (result )
25592554
25602555 async def get_subnet_info (
25612556 self ,
@@ -2669,6 +2664,7 @@ async def get_subnet_prices(
26692664 prices .update ({0 : Balance .from_tao (1 )})
26702665 return prices
26712666
2667+ # TODO: remove unused parameters in SDK.v10
26722668 async def get_unstake_fee (
26732669 self ,
26742670 amount : Balance ,
@@ -2690,20 +2686,11 @@ async def get_unstake_fee(
26902686 Returns:
26912687 The calculated stake fee as a Balance object
26922688 """
2693- result = await self .query_runtime_api (
2694- runtime_api = "StakeInfoRuntimeApi" ,
2695- method = "get_stake_fee" ,
2696- params = [
2697- None ,
2698- coldkey_ss58 ,
2699- (hotkey_ss58 , netuid ),
2700- coldkey_ss58 ,
2701- amount .rao ,
2702- ],
2703- block = block ,
2689+ return await self .get_stake_operations_fee (
2690+ amount = amount , netuid = netuid , block = block
27042691 )
2705- return Balance .from_rao (result )
27062692
2693+ # TODO: remove unused parameters in SDK.v10
27072694 async def get_stake_movement_fee (
27082695 self ,
27092696 amount : Balance ,
@@ -2731,19 +2718,9 @@ async def get_stake_movement_fee(
27312718 Returns:
27322719 The calculated stake fee as a Balance object
27332720 """
2734- result = await self .query_runtime_api (
2735- runtime_api = "StakeInfoRuntimeApi" ,
2736- method = "get_stake_fee" ,
2737- params = [
2738- (origin_hotkey_ss58 , origin_netuid ),
2739- origin_coldkey_ss58 ,
2740- (destination_hotkey_ss58 , destination_netuid ),
2741- destination_coldkey_ss58 ,
2742- amount .rao ,
2743- ],
2744- block = block ,
2721+ return await self .get_stake_operations_fee (
2722+ amount = amount , netuid = origin_netuid , block = block
27452723 )
2746- return Balance .from_rao (result )
27472724
27482725 async def get_stake_for_coldkey_and_hotkey (
27492726 self ,
@@ -2864,6 +2841,39 @@ async def get_stake_for_hotkey(
28642841
28652842 get_hotkey_stake = get_stake_for_hotkey
28662843
2844+ async def get_stake_operations_fee (
2845+ self ,
2846+ amount : Balance ,
2847+ netuid : int ,
2848+ block : Optional [int ] = None ,
2849+ block_hash : Optional [str ] = None ,
2850+ reuse_block : bool = False ,
2851+ ):
2852+ """Returns fee for any stake operation in specified subnet.
2853+
2854+ Args:
2855+ amount: Amount of stake to add in Alpha/TAO.
2856+ netuid: Netuid of subnet.
2857+ block: The block number at which to query the stake information. Do not specify if also specifying
2858+ block_hash or reuse_block.
2859+ block_hash: The hash of the blockchain block number for the query. Do not specify if also specifying block
2860+ or reuse_block.
2861+ reuse_block: Whether to reuse for this query the last-used block. Do not specify if also specifying block
2862+ or block_hash.
2863+ Returns:
2864+ The calculated stake fee as a Balance object.
2865+ """
2866+ block_hash = await self .determine_block_hash (
2867+ block = block , block_hash = block_hash , reuse_block = reuse_block
2868+ )
2869+ result = await self .substrate .query (
2870+ module = "Swap" ,
2871+ storage_function = "FeeRate" ,
2872+ params = [netuid ],
2873+ block_hash = block_hash ,
2874+ )
2875+ return amount * (result .value / U16_MAX )
2876+
28672877 async def get_subnet_burn_cost (
28682878 self ,
28692879 block : Optional [int ] = None ,
0 commit comments