Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 9 additions & 52 deletions bittensor_cli/src/bittensor/subtensor_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,50 +297,26 @@ async def get_stake_for_coldkey_and_hotkey(
self,
hotkey_ss58: str,
coldkey_ss58: str,
netuid: Optional[int] = None,
netuid: int,
block_hash: Optional[str] = None,
) -> Balance:
"""
Returns the stake under a coldkey - hotkey pairing.

:param hotkey_ss58: The SS58 address of the hotkey.
:param coldkey_ss58: The SS58 address of the coldkey.
:param netuid: The subnet ID to filter by. If provided, only returns stake for this specific
subnet.
:param netuid: The subnet ID for the stake query.
:param block_hash: The block hash at which to query the stake information.

:return: Balance: The stake under the coldkey - hotkey pairing.
"""
alpha_shares, hotkey_alpha, hotkey_shares = await asyncio.gather(
self.query(
module="SubtensorModule",
storage_function="Alpha",
params=[hotkey_ss58, coldkey_ss58, netuid],
block_hash=block_hash,
),
self.query(
module="SubtensorModule",
storage_function="TotalHotkeyAlpha",
params=[hotkey_ss58, netuid],
block_hash=block_hash,
),
self.query(
module="SubtensorModule",
storage_function="TotalHotkeyShares",
params=[hotkey_ss58, netuid],
block_hash=block_hash,
),
result = await self.query_runtime_api(
runtime_api="StakeInfoRuntimeApi",
method="get_stake_info_for_hotkey_coldkey_netuid",
params=[hotkey_ss58, coldkey_ss58, netuid],
block_hash=block_hash,
)

alpha_shares_as_float = fixed_to_float(alpha_shares or 0)
hotkey_shares_as_float = fixed_to_float(hotkey_shares or 0)

if hotkey_shares_as_float == 0:
return Balance.from_rao(0).set_unit(netuid=netuid)

stake = alpha_shares_as_float / hotkey_shares_as_float * (hotkey_alpha or 0)

return Balance.from_rao(int(stake)).set_unit(netuid=netuid)
return StakeInfo.from_any(result).stake

# Alias
get_stake = get_stake_for_coldkey_and_hotkey
Expand Down Expand Up @@ -1491,25 +1467,6 @@ async def get_delegate_identities(

return all_delegates_details

async def get_stake_for_coldkey_and_hotkey_on_netuid(
self,
hotkey_ss58: str,
coldkey_ss58: str,
netuid: int,
block_hash: Optional[str] = None,
) -> "Balance":
"""Returns the stake under a coldkey - hotkey - netuid pairing"""
_result = await self.query(
"SubtensorModule",
"Alpha",
[hotkey_ss58, coldkey_ss58, netuid],
block_hash,
)
if _result is None:
return Balance(0).set_unit(netuid)
else:
return Balance.from_rao(fixed_to_float(_result)).set_unit(int(netuid))

async def get_mechagraph_info(
self, netuid: int, mech_id: int, block_hash: Optional[str] = None
) -> Optional[MetagraphInfo]:
Expand Down Expand Up @@ -2390,7 +2347,7 @@ async def get_claimable_stake_for_netuid(
After manual claim, claimable (available) stake will be added to subnet stake.
"""
root_stake, root_claimable_rate, root_claimed = await asyncio.gather(
self.get_stake_for_coldkey_and_hotkey_on_netuid(
self.get_stake(
coldkey_ss58=coldkey_ss58,
hotkey_ss58=hotkey_ss58,
netuid=0,
Expand Down
Loading