117
117
price_to_tick ,
118
118
LiquidityPosition ,
119
119
)
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
+ )
121
125
122
126
if TYPE_CHECKING :
123
127
from async_substrate_interface .types import ScaleObj
@@ -2522,6 +2526,7 @@ async def get_stake(
2522
2526
2523
2527
return Balance .from_rao (int (stake )).set_unit (netuid = netuid )
2524
2528
2529
+ # TODO: remove unused parameters in SDK.v10
2525
2530
async def get_stake_add_fee (
2526
2531
self ,
2527
2532
amount : Balance ,
@@ -2543,19 +2548,9 @@ async def get_stake_add_fee(
2543
2548
Returns:
2544
2549
The calculated stake fee as a Balance object
2545
2550
"""
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
2557
2553
)
2558
- return Balance .from_rao (result )
2559
2554
2560
2555
async def get_subnet_info (
2561
2556
self ,
@@ -2669,6 +2664,7 @@ async def get_subnet_prices(
2669
2664
prices .update ({0 : Balance .from_tao (1 )})
2670
2665
return prices
2671
2666
2667
+ # TODO: remove unused parameters in SDK.v10
2672
2668
async def get_unstake_fee (
2673
2669
self ,
2674
2670
amount : Balance ,
@@ -2690,20 +2686,11 @@ async def get_unstake_fee(
2690
2686
Returns:
2691
2687
The calculated stake fee as a Balance object
2692
2688
"""
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
2704
2691
)
2705
- return Balance .from_rao (result )
2706
2692
2693
+ # TODO: remove unused parameters in SDK.v10
2707
2694
async def get_stake_movement_fee (
2708
2695
self ,
2709
2696
amount : Balance ,
@@ -2731,19 +2718,9 @@ async def get_stake_movement_fee(
2731
2718
Returns:
2732
2719
The calculated stake fee as a Balance object
2733
2720
"""
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
2745
2723
)
2746
- return Balance .from_rao (result )
2747
2724
2748
2725
async def get_stake_for_coldkey_and_hotkey (
2749
2726
self ,
@@ -2864,6 +2841,39 @@ async def get_stake_for_hotkey(
2864
2841
2865
2842
get_hotkey_stake = get_stake_for_hotkey
2866
2843
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
+
2867
2877
async def get_subnet_burn_cost (
2868
2878
self ,
2869
2879
block : Optional [int ] = None ,
0 commit comments