Skip to content

Commit f859a0a

Browse files
committed
Added to subtensor
1 parent 9730f51 commit f859a0a

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

bittensor/core/subtensor.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,69 @@ def get_stake(
12101210

12111211
return Balance.from_rao(int(stake)).set_unit(netuid=netuid)
12121212

1213+
def get_stake_fee(
1214+
self,
1215+
origin_hotkey_ss58: Optional[str],
1216+
origin_netuid: Optional[int],
1217+
origin_coldkey_ss58: str,
1218+
destination_hotkey_ss58: Optional[str],
1219+
destination_netuid: Optional[int],
1220+
destination_coldkey_ss58: str,
1221+
amount: Balance,
1222+
block: Optional[int] = None,
1223+
) -> Balance:
1224+
"""
1225+
Calculates the fee for a staking operation.
1226+
:param origin_hotkey_ss58: SS58 address of source hotkey (None for new stake)
1227+
:param origin_netuid: Netuid of source subnet (None for new stake)
1228+
:param origin_coldkey_ss58: SS58 address of source coldkey
1229+
:param destination_hotkey_ss58: SS58 address of destination hotkey (None for removing stake)
1230+
:param destination_netuid: Netuid of destination subnet (None for removing stake)
1231+
:param destination_coldkey_ss58: SS58 address of destination coldkey
1232+
:param amount: Amount of stake to transfer in RAO
1233+
:param block_hash: Optional block hash at which to perform the calculation
1234+
:return: The calculated stake fee as a Balance object
1235+
When to use None:
1236+
1. Adding new stake (default fee):
1237+
- origin_hotkey_ss58 = None
1238+
- origin_netuid = None
1239+
- All other fields required
1240+
2. Removing stake (default fee):
1241+
- destination_hotkey_ss58 = None
1242+
- destination_netuid = None
1243+
- All other fields required
1244+
For all other operations, no None values - provide all parameters:
1245+
3. Moving between subnets
1246+
4. Moving between hotkeys
1247+
5. Moving between coldkeys
1248+
"""
1249+
1250+
origin = None
1251+
if origin_hotkey_ss58 is not None and origin_netuid is not None:
1252+
origin = (origin_hotkey_ss58, origin_netuid)
1253+
1254+
destination = None
1255+
if destination_hotkey_ss58 is not None and destination_netuid is not None:
1256+
destination = (destination_hotkey_ss58, destination_netuid)
1257+
1258+
result = self.query_runtime_api(
1259+
runtime_api="StakeInfoRuntimeApi",
1260+
method="get_stake_fee",
1261+
params=[
1262+
origin,
1263+
origin_coldkey_ss58,
1264+
destination,
1265+
destination_coldkey_ss58,
1266+
amount,
1267+
],
1268+
block=block,
1269+
)
1270+
1271+
if result is None:
1272+
raise Exception("Unable to retrieve stake fee.")
1273+
1274+
return Balance.from_rao(result)
1275+
12131276
def get_stake_for_coldkey_and_hotkey(
12141277
self,
12151278
coldkey_ss58: str,

0 commit comments

Comments
 (0)