Skip to content

Commit d32dc2c

Browse files
committed
Added to async subtensor
1 parent f859a0a commit d32dc2c

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

bittensor/core/async_subtensor.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,72 @@ async def get_stake(
15751575

15761576
return Balance.from_rao(int(stake)).set_unit(netuid=netuid)
15771577

1578+
async def get_stake_fee(
1579+
self,
1580+
origin_hotkey_ss58: Optional[str],
1581+
origin_netuid: Optional[int],
1582+
origin_coldkey_ss58: str,
1583+
destination_hotkey_ss58: Optional[str],
1584+
destination_netuid: Optional[int],
1585+
destination_coldkey_ss58: str,
1586+
amount: int,
1587+
block_hash: Optional[str] = None,
1588+
) -> Balance:
1589+
"""
1590+
Calculates the fee for a staking operation.
1591+
1592+
:param origin_hotkey_ss58: SS58 address of source hotkey (None for new stake)
1593+
:param origin_netuid: Netuid of source subnet (None for new stake)
1594+
:param origin_coldkey_ss58: SS58 address of source coldkey
1595+
:param destination_hotkey_ss58: SS58 address of destination hotkey (None for removing stake)
1596+
:param destination_netuid: Netuid of destination subnet (None for removing stake)
1597+
:param destination_coldkey_ss58: SS58 address of destination coldkey
1598+
:param amount: Amount of stake to transfer in RAO
1599+
:param block_hash: Optional block hash at which to perform the calculation
1600+
1601+
:return: The calculated stake fee as a Balance object
1602+
1603+
When to use None:
1604+
1605+
1. Adding new stake (default fee):
1606+
- origin_hotkey_ss58 = None
1607+
- origin_netuid = None
1608+
- All other fields required
1609+
1610+
2. Removing stake (default fee):
1611+
- destination_hotkey_ss58 = None
1612+
- destination_netuid = None
1613+
- All other fields required
1614+
1615+
For all other operations, no None values - provide all parameters:
1616+
3. Moving between subnets
1617+
4. Moving between hotkeys
1618+
5. Moving between coldkeys
1619+
"""
1620+
1621+
origin = None
1622+
if origin_hotkey_ss58 is not None and origin_netuid is not None:
1623+
origin = (origin_hotkey_ss58, origin_netuid)
1624+
1625+
destination = None
1626+
if destination_hotkey_ss58 is not None and destination_netuid is not None:
1627+
destination = (destination_hotkey_ss58, destination_netuid)
1628+
1629+
result = await self.query_runtime_api(
1630+
runtime_api="StakeInfoRuntimeApi",
1631+
method="get_stake_fee",
1632+
params=[
1633+
origin,
1634+
origin_coldkey_ss58,
1635+
destination,
1636+
destination_coldkey_ss58,
1637+
amount,
1638+
],
1639+
block_hash=block_hash,
1640+
)
1641+
1642+
return Balance.from_rao(result if result is not None else 0)
1643+
15781644
async def get_stake_for_coldkey_and_hotkey(
15791645
self,
15801646
coldkey_ss58: str,

0 commit comments

Comments
 (0)