Skip to content

Commit

Permalink
Enhancements: wallet, stake, s show
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheem-opentensor committed Dec 20, 2024
1 parent b352dd7 commit 60ba785
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 41 deletions.
57 changes: 42 additions & 15 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2116,7 +2116,7 @@ def wallet_balance(
"""
self.verbosity_handler(quiet, verbose)

wallet = None
if ss58_addresses:
valid_ss58s = [
ss58 for ss58 in set(ss58_addresses) if is_valid_ss58_address(ss58)
Expand All @@ -2127,20 +2127,44 @@ def wallet_balance(
print_error(f"Incorrect ss58 address: {invalid_ss58}. Skipping.")

if valid_ss58s:
wallet = None
ss58_addresses = valid_ss58s
else:
raise typer.Exit()
else:
ask_for = [WO.PATH] if all_balances else [WO.NAME, WO.PATH]
validate = WV.NONE if all_balances else WV.WALLET
wallet = self.wallet_ask(
wallet_name,
wallet_path,
wallet_hotkey,
ask_for=ask_for,
validate=validate,
)
if wallet_name:
coldkey_or_ss58 = wallet_name
else:
coldkey_or_ss58 = Prompt.ask(
"Enter the [blue]wallet name[/blue] or [blue]coldkey ss58 addresses[/blue] (comma-separated)",
default=self.config.get("wallet_name") or defaults.wallet.name,
)
# Split by comma and strip whitespace
coldkey_or_ss58_list = [x.strip() for x in coldkey_or_ss58.split(",")]

# Check if any entry is a valid SS58 address
if any(is_valid_ss58_address(x) for x in coldkey_or_ss58_list):
valid_ss58s = [
ss58 for ss58 in coldkey_or_ss58_list if is_valid_ss58_address(ss58)
]
invalid_ss58s = set(coldkey_or_ss58_list) - set(valid_ss58s)
for invalid_ss58 in invalid_ss58s:
print_error(f"Incorrect ss58 address: {invalid_ss58}. Skipping.")

if valid_ss58s:
ss58_addresses = valid_ss58s
else:
raise typer.Exit()
else:
wallet_name = coldkey_or_ss58_list[0] if coldkey_or_ss58_list else wallet_name
ask_for = [WO.PATH] if all_balances else [WO.NAME, WO.PATH]
validate = WV.NONE if all_balances else WV.WALLET
wallet = self.wallet_ask(
wallet_name,
wallet_path,
wallet_hotkey,
ask_for=ask_for,
validate=validate,
)
subtensor = self.initialize_chain(network)
return self._run_command(
wallets.wallet_balance(wallet, subtensor, all_balances, ss58_addresses)
Expand Down Expand Up @@ -2430,10 +2454,13 @@ def stake_list(
print_error("You entered an invalid ss58 address")
raise typer.Exit()
else:
coldkey_or_ss58 = Prompt.ask(
"Enter the [blue]wallet name[/blue] or [blue]coldkey ss58 address[/blue]",
default=self.config.get("wallet_name") or defaults.wallet.name,
)
if wallet_name:
coldkey_or_ss58 = wallet_name
else:
coldkey_or_ss58 = Prompt.ask(
"Enter the [blue]wallet name[/blue] or [blue]coldkey ss58 address[/blue]",
default=self.config.get("wallet_name") or defaults.wallet.name,
)
if is_valid_ss58_address(coldkey_or_ss58):
coldkey_ss58 = coldkey_or_ss58
else:
Expand Down
4 changes: 3 additions & 1 deletion bittensor_cli/src/bittensor/subtensor_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,9 @@ async def fetch_coldkey_hotkey_identities(
"""

coldkey_identities = await self.query_all_identities()
identities = {"coldkeys": {}, "hotkeys": {}}
if not coldkey_identities:
return identities
query = await self.substrate.query_multiple(
params=[(ss58) for ss58, _ in coldkey_identities.items()],
module="SubtensorModule",
Expand All @@ -909,7 +912,6 @@ async def fetch_coldkey_hotkey_identities(
reuse_block_hash=reuse_block,
)

identities = {"coldkeys": {}, "hotkeys": {}}
for coldkey_ss58, hotkeys in query.items():
coldkey_identity = coldkey_identities.get(coldkey_ss58)
hotkeys = [decode_account_id(hotkey[0]) for hotkey in hotkeys or []]
Expand Down
24 changes: 5 additions & 19 deletions bittensor_cli/src/commands/stake/stake.py
Original file line number Diff line number Diff line change
Expand Up @@ -1788,10 +1788,7 @@ def table_substakes(hotkey_: str, substakes: list[StakeInfo]):
str(netuid), # Number
symbol, # Symbol
f"{substake_.stake.tao:,.4f} {symbol}", # Stake (a)
f"{pool.tao_in.tao:,.4f} τ", # TAO Reserves (t_in)
f"{pool.alpha_in.tao:,.4f} {symbol}", # Alpha Reserves a_in
f"{pool.price.tao:.4f} τ/{symbol}", # Rate (t/a)
f"{pool.alpha_out.tao:,.4f} {symbol}", # Alpha out (a_out)
f"{tao_ownership}", # TAO equiv
f"{tao_value}", # Exchange Value (α x τ/α)
f"{swapped_tao_value} ({slippage_percentage})", # Swap(α) -> τ
Expand All @@ -1817,7 +1814,11 @@ def table_substakes(hotkey_: str, substakes: list[StakeInfo]):
show_lines=False,
pad_edge=True,
)
table.add_column("[white]Netuid", footer_style="overline white", style="grey89")
table.add_column("[white]Netuid",
footer=f"{len(rows)}",
footer_style="overline white",
style="grey89"
)
table.add_column(
"[white]Symbol",
style=COLOR_PALETTE["GENERAL"]["SYMBOL"],
Expand All @@ -1830,27 +1831,12 @@ def table_substakes(hotkey_: str, substakes: list[StakeInfo]):
style=COLOR_PALETTE["STAKE"]["STAKE_ALPHA"],
justify="center",
)
table.add_column(
f"[white]TAO Reserves ({Balance.unit}_in)",
style=COLOR_PALETTE["STAKE"]["TAO"],
justify="right",
)
table.add_column(
f"[white]Alpha Reserves ({Balance.get_unit(1)}_in)",
style=COLOR_PALETTE["POOLS"]["ALPHA_IN"],
justify="right",
)
table.add_column(
f"[white]Rate \n({Balance.unit}_in/{Balance.get_unit(1)}_in)",
footer_style="white",
style=COLOR_PALETTE["POOLS"]["RATE"],
justify="center",
)
table.add_column(
f"[white]Alpha out ({Balance.get_unit(1)}_out)",
style=COLOR_PALETTE["POOLS"]["ALPHA_OUT"],
justify="right",
)
table.add_column(
f"[white]TAO equiv \n({Balance.unit}_in x {Balance.get_unit(1)}/{Balance.get_unit(1)}_out)",
style=COLOR_PALETTE["POOLS"]["TAO_EQUIV"],
Expand Down
8 changes: 4 additions & 4 deletions bittensor_cli/src/commands/subnets.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ async def _find_event_attributes_in_extrinsic_receipt(
your_balance = your_balance_[wallet.coldkeypub.ss58_address]

print_verbose("Fetching burn_cost")
burn_cost = await burn_cost(subtensor)
if burn_cost > your_balance:
sn_burn_cost = await burn_cost(subtensor)
if sn_burn_cost > your_balance:
err_console.print(
f"Your balance of: [{COLOR_PALETTE['POOLS']['TAO']}]{your_balance}[{COLOR_PALETTE['POOLS']['TAO']}] is not enough to pay the subnet lock cost of: "
f"[{COLOR_PALETTE['POOLS']['TAO']}]{burn_cost}[{COLOR_PALETTE['POOLS']['TAO']}]"
f"[{COLOR_PALETTE['POOLS']['TAO']}]{sn_burn_cost}[{COLOR_PALETTE['POOLS']['TAO']}]"
)
return False

Expand All @@ -108,7 +108,7 @@ async def _find_event_attributes_in_extrinsic_receipt(
f"Your balance is: [{COLOR_PALETTE['POOLS']['TAO']}]{your_balance}"
)
if not Confirm.ask(
f"Do you want to register a subnet for [{COLOR_PALETTE['POOLS']['TAO']}]{burn_cost}?"
f"Do you want to register a subnet for [{COLOR_PALETTE['POOLS']['TAO']}]{sn_burn_cost}?"
):
return False

Expand Down
5 changes: 3 additions & 2 deletions bittensor_cli/src/commands/wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ async def wallet_balance(
"""Retrieves the current balance of the specified wallet"""
if ss58_addresses:
coldkeys = ss58_addresses
wallet_names = [f"Provided Address {i + 1}" for i in range(len(ss58_addresses))]

identities = await subtensor.query_all_identities()
wallet_names = [f"{identities.get(coldkey, {'name': f'Provided address {i}'})['name']}" for i, coldkey in enumerate(coldkeys)]

elif not all_balances:
if not wallet.coldkeypub_file.exists_on_device():
err_console.print("[bold red]No wallets found.[/bold red]")
Expand Down

0 comments on commit 60ba785

Please sign in to comment.