Skip to content

Commit

Permalink
fix feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
igorsyl authored and igorsyl committed Feb 19, 2025
2 parents 7a0c8e4 + c9930e7 commit 7f5bed0
Show file tree
Hide file tree
Showing 12 changed files with 658 additions and 211 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 9.0.1 /2025-02-13

## What's Changed
* Fixes root tempo being 0 by @ibraheem-opentensor in https://github.com/opentensor/btcli/pull/312
* Backmerge main to staging 900 by @ibraheem-opentensor in https://github.com/opentensor/btcli/pull/313
* Fixes fmt err msg by @ibraheem-opentensor in https://github.com/opentensor/btcli/pull/314
* Adds subnet identities set/get by @ibraheem-opentensor in https://github.com/opentensor/btcli/pull/316
* Fix return type annotation for `alpha_to_tao_with_slippage` by @thewhaleking in https://github.com/opentensor/btcli/pull/311
* Updates live view of btcli stake list

**Full Changelog**: https://github.com/opentensor/btcli/compare/v9.0.0...v9.0.1

## 9.0.0 /2025-02-13

## What's Changed
Expand Down
32 changes: 27 additions & 5 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ def __init__(self):
self.config_app.command("set")(self.set_config)
self.config_app.command("get")(self.get_config)
self.config_app.command("clear")(self.del_config)
self.config_app.command("metagraph", hidden=True)(self.metagraph_config)
# self.config_app.command("metagraph", hidden=True)(self.metagraph_config)

# wallet commands
self.wallet_app.command(
Expand Down Expand Up @@ -3209,11 +3209,22 @@ def stake_remove(
else:
print_error("Invalid hotkey ss58 address.")
raise typer.Exit()
else:
hotkey_or_ss58 = Prompt.ask(
"Enter the [blue]hotkey[/blue] name or [blue]ss58 address[/blue] to unstake all from",
default=self.config.get("wallet_hotkey") or defaults.wallet.hotkey,
elif all_hotkeys:
wallet = self.wallet_ask(
wallet_name,
wallet_path,
wallet_hotkey,
ask_for=[WO.NAME, WO.PATH],
)
else:
if not hotkey_ss58_address and not wallet_hotkey:
hotkey_or_ss58 = Prompt.ask(
"Enter the [blue]hotkey[/blue] name or [blue]ss58 address[/blue] to unstake all from [dim](or enter 'all' to unstake from all hotkeys)[/dim]",
default=self.config.get("wallet_hotkey") or defaults.wallet.hotkey,
)
else:
hotkey_or_ss58 = hotkey_ss58_address or wallet_hotkey

if is_valid_ss58_address(hotkey_or_ss58):
hotkey_ss58_address = hotkey_or_ss58
wallet = self.wallet_ask(
Expand All @@ -3222,6 +3233,14 @@ def stake_remove(
wallet_hotkey,
ask_for=[WO.NAME, WO.PATH],
)
elif hotkey_or_ss58 == "all":
all_hotkeys = True
wallet = self.wallet_ask(
wallet_name,
wallet_path,
wallet_hotkey,
ask_for=[WO.NAME, WO.PATH],
)
else:
wallet_hotkey = hotkey_or_ss58
wallet = self.wallet_ask(
Expand All @@ -3237,6 +3256,9 @@ def stake_remove(
subtensor=self.initialize_chain(network),
hotkey_ss58_address=hotkey_ss58_address,
unstake_all_alpha=unstake_all_alpha,
all_hotkeys=all_hotkeys,
include_hotkeys=include_hotkeys,
exclude_hotkeys=exclude_hotkeys,
prompt=prompt,
)
)
Expand Down
2 changes: 1 addition & 1 deletion bittensor_cli/src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Constants:
subvortex_entrypoint = "ws://subvortex.info:9944"
local_entrypoint = "ws://127.0.0.1:9944"
rao_entrypoint = "wss://rao.chain.opentensor.ai:443"
dev_entrypoint = "wss://dev.chain.opentensor.ai:443 "
dev_entrypoint = "wss://dev.chain.opentensor.ai:443"
local_entrypoint = "ws://127.0.0.1:9944"
latent_lite_entrypoint = "wss://lite.sub.latent.to:443"
network_map = {
Expand Down
2 changes: 1 addition & 1 deletion bittensor_cli/src/bittensor/balances.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __str__(self):
if self.unit == UNITS[0]:
return f"{self.unit} {float(self.tao):,.4f}"
else:
return f"{float(self.tao):,.4f} {self.unit}\u200e"
return f"\u200e{float(self.tao):,.4f} {self.unit}\u200e"

def __rich__(self):
return "[green]{}[/green][green]{}[/green][green].[/green][dim green]{}[/dim green]".format(
Expand Down
24 changes: 17 additions & 7 deletions bittensor_cli/src/bittensor/chain_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class SubnetHyperparameters(InfoBase):
def _fix_decoded(
cls, decoded: Union[dict, "SubnetHyperparameters"]
) -> "SubnetHyperparameters":
return SubnetHyperparameters(
return cls(
rho=decoded.get("rho"),
kappa=decoded.get("kappa"),
immunity_period=decoded.get("immunity_period"),
Expand Down Expand Up @@ -197,6 +197,7 @@ class StakeInfo(InfoBase):
stake: Balance # Stake for the hotkey-coldkey pair
locked: Balance # Stake which is locked.
emission: Balance # Emission for the hotkey-coldkey pair
tao_emission: Balance # TAO emission for the hotkey-coldkey pair
drain: int
is_registered: bool

Expand All @@ -208,11 +209,20 @@ def _fix_decoded(cls, decoded: Any) -> "StakeInfo":
stake = Balance.from_rao(decoded.get("stake")).set_unit(netuid)
locked = Balance.from_rao(decoded.get("locked")).set_unit(netuid)
emission = Balance.from_rao(decoded.get("emission")).set_unit(netuid)
tao_emission = Balance.from_rao(decoded.get("tao_emission"))
drain = int(decoded.get("drain"))
is_registered = bool(decoded.get("is_registered"))

return StakeInfo(
hotkey, coldkey, netuid, stake, locked, emission, drain, is_registered
return cls(
hotkey,
coldkey,
netuid,
stake,
locked,
emission,
tao_emission,
drain,
is_registered,
)


Expand Down Expand Up @@ -293,7 +303,7 @@ def _fix_decoded(cls, decoded: Any) -> "NeuronInfo":
axon_info = decoded.get("axon_info", {})
coldkey = decode_account_id(decoded.get("coldkey"))
hotkey = decode_account_id(decoded.get("hotkey"))
return NeuronInfo(
return cls(
hotkey=hotkey,
coldkey=coldkey,
uid=decoded.get("uid"),
Expand Down Expand Up @@ -555,7 +565,7 @@ class SubnetInfo(InfoBase):

@classmethod
def _fix_decoded(cls, decoded: "SubnetInfo") -> "SubnetInfo":
return SubnetInfo(
return cls(
netuid=decoded.get("netuid"),
rho=decoded.get("rho"),
kappa=decoded.get("kappa"),
Expand Down Expand Up @@ -594,7 +604,7 @@ class SubnetIdentity(InfoBase):

@classmethod
def _fix_decoded(cls, decoded: dict) -> "SubnetIdentity":
return SubnetIdentity(
return cls(
subnet_name=bytes(decoded["subnet_name"]).decode(),
github_repo=bytes(decoded["github_repo"]).decode(),
subnet_contact=bytes(decoded["subnet_contact"]).decode(),
Expand Down Expand Up @@ -828,7 +838,7 @@ class SubnetState(InfoBase):
@classmethod
def _fix_decoded(cls, decoded: Any) -> "SubnetState":
netuid = decoded.get("netuid")
return SubnetState(
return cls(
netuid=netuid,
hotkeys=[decode_account_id(val) for val in decoded.get("hotkeys")],
coldkeys=[decode_account_id(val) for val in decoded.get("coldkeys")],
Expand Down
26 changes: 14 additions & 12 deletions bittensor_cli/src/bittensor/subtensor_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ async def get_total_stake_for_coldkey(
*ss58_addresses,
block_hash: Optional[str] = None,
reuse_block: bool = False,
) -> dict[str, Balance]:
) -> dict[str, tuple[Balance, Balance]]:
"""
Returns the total stake held on a coldkey.
Expand All @@ -370,7 +370,8 @@ async def get_total_stake_for_coldkey(

results = {}
for ss58, stake_info_list in sub_stakes.items():
all_staked_tao = 0
total_tao_value = Balance(0)
total_swapped_tao_value = Balance(0)
for sub_stake in stake_info_list:
if sub_stake.stake.rao == 0:
continue
Expand All @@ -381,19 +382,20 @@ async def get_total_stake_for_coldkey(
netuid
)

tao_locked = pool.tao_in

issuance = pool.alpha_out if pool.is_dynamic else tao_locked
tao_ownership = Balance(0)
# Without slippage
tao_value = pool.alpha_to_tao(alpha_value)
total_tao_value += tao_value

if alpha_value.tao > 0.00009 and issuance.tao != 0:
tao_ownership = Balance.from_tao(
(alpha_value.tao / issuance.tao) * tao_locked.tao
# With slippage
if netuid == 0:
swapped_tao_value = tao_value
else:
swapped_tao_value, _, _ = pool.alpha_to_tao_with_slippage(
sub_stake.stake
)
total_swapped_tao_value += swapped_tao_value

all_staked_tao += tao_ownership.rao

results[ss58] = Balance.from_rao(all_staked_tao)
results[ss58] = (total_tao_value, total_swapped_tao_value)
return results

async def get_total_stake_for_hotkey(
Expand Down
2 changes: 1 addition & 1 deletion bittensor_cli/src/commands/stake/children_hotkeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ async def get_childkey_take(subtensor, hotkey: str, netuid: int) -> Optional[int
params=[hotkey, netuid],
)
if childkey_take_:
return int(childkey_take_.value)
return int(childkey_take_)

except SubstrateRequestException as e:
err_console.print(f"Error querying ChildKeys: {format_error_message(e)}")
Expand Down
Loading

0 comments on commit 7f5bed0

Please sign in to comment.