From 958853647a7b0d86fae52a443ecad92242b713a7 Mon Sep 17 00:00:00 2001 From: ibraheem-latent Date: Mon, 16 Mar 2026 16:34:29 -0700 Subject: [PATCH 1/2] update get_stake_for_coldkey_and_hotkey --- .../src/bittensor/subtensor_interface.py | 40 ++++--------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/bittensor_cli/src/bittensor/subtensor_interface.py b/bittensor_cli/src/bittensor/subtensor_interface.py index 09136ca05..5bbdf8057 100644 --- a/bittensor_cli/src/bittensor/subtensor_interface.py +++ b/bittensor_cli/src/bittensor/subtensor_interface.py @@ -297,7 +297,7 @@ 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: """ @@ -305,42 +305,18 @@ async def get_stake_for_coldkey_and_hotkey( :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 From ae54843c7189424d9abe861029f7121c3fbfd4c6 Mon Sep 17 00:00:00 2001 From: ibraheem-latent Date: Mon, 16 Mar 2026 16:37:38 -0700 Subject: [PATCH 2/2] remove old get_stake_for_coldkey_and_hotkey_on_netuid --- .../src/bittensor/subtensor_interface.py | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/bittensor_cli/src/bittensor/subtensor_interface.py b/bittensor_cli/src/bittensor/subtensor_interface.py index 5bbdf8057..41edb1cea 100644 --- a/bittensor_cli/src/bittensor/subtensor_interface.py +++ b/bittensor_cli/src/bittensor/subtensor_interface.py @@ -1467,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]: @@ -2366,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,