Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
9acdcc5
Adds Tao emissions to subnets list
ibraheem-abe Feb 12, 2025
c9aed03
Edge case alpha formatting.
thewhaleking Feb 14, 2025
3402c15
Allows setting hyperparams arbitrarily, as long as they exist in the …
thewhaleking Feb 14, 2025
4b9c78b
We switched to `subtensor.query` which already decodes the value.
thewhaleking Feb 14, 2025
0857ef8
Updates balance command
ibraheem-abe Feb 15, 2025
5325871
remove version
Feb 16, 2025
f12c6d5
Merge pull request #321 from opentensor/fix/thewhaleking/stake-child-…
thewhaleking Feb 18, 2025
1fc4656
merge staging
ibraheem-abe Feb 18, 2025
a6abc8e
More efficient method.
thewhaleking Feb 18, 2025
c27246f
merges staging
ibraheem-abe Feb 18, 2025
de235ac
Handles div by zero
ibraheem-abe Feb 18, 2025
44e124f
Updates chain_data -> cls()
ibraheem-abe Feb 18, 2025
747efa1
fix feedback
Feb 18, 2025
8477eb8
Merge pull request #318 from opentensor/fix/thewhaleking/alpha-str-fo…
ibraheem-abe Feb 18, 2025
2f2e366
Merge pull request #300 from opentensor/feat/add-tao-dividends-stake-…
ibraheem-abe Feb 18, 2025
bfc8756
Updates return type
ibraheem-abe Feb 18, 2025
de2988e
Merge pull request #322 from opentensor/feat/update-btcli-w-balance
ibraheem-abe Feb 18, 2025
600676f
Adds unstaking from all hotkeys + tests
ibraheem-abe Feb 19, 2025
c2d7e7c
Cleanup
ibraheem-abe Feb 19, 2025
01a69d9
Merge branch 'main' into backmerge-main-staging-101
ibraheem-abe Feb 19, 2025
7c528d5
Merge pull request #326 from opentensor/backmerge-main-staging-101
ibraheem-abe Feb 19, 2025
8031834
removes outdated calculation + adds swap value
ibraheem-abe Feb 19, 2025
55215ff
Merge pull request #327 from opentensor/improve/stake-list-calc
ibraheem-abe Feb 19, 2025
72910f9
Merge pull request #325 from opentensor/feat/unstaking-all-hotkeys
ibraheem-abe Feb 19, 2025
c9930e7
Merge branch 'staging' into fix/igorsyl/version
igorsyl Feb 19, 2025
0d22301
fix: remove double conversion in stake swap functionality [--swap_all]
ashikshafi08 Feb 19, 2025
64397e6
Merge branch 'staging' into feat/thewhaleking/allow-arbitrary-hyperpa…
thewhaleking Feb 19, 2025
d31fd04
Adds better helper text for mnemonic option + ruff.
thewhaleking Feb 19, 2025
556c7d8
Merge pull request #329 from opentensor/feat/thewhaleking/mnemonic-he…
thewhaleking Feb 19, 2025
b8ae46e
Made it actually work.
thewhaleking Feb 19, 2025
7a0c8e4
fix feedback
igorsyl Feb 19, 2025
cea472e
fix feedback
igorsyl Feb 19, 2025
b1ec144
fix feedback
Feb 19, 2025
2bb818c
fix feedback
Feb 19, 2025
3bd79b8
Update "network_registration_allowed" to match the SubnetHyperparamet…
thewhaleking Feb 19, 2025
1149ecd
Merge pull request #328 from ashikshafi08/fix/stake-swap-conversion
thewhaleking Feb 19, 2025
87034b2
Readability improved
thewhaleking Feb 19, 2025
1a91049
Typing.
thewhaleking Feb 19, 2025
ebc2404
String to bool conversion.
thewhaleking Feb 19, 2025
a88531d
Spacing
thewhaleking Feb 19, 2025
dc16459
Merge pull request #320 from opentensor/feat/thewhaleking/allow-arbit…
ibraheem-abe Feb 20, 2025
d8b9ef7
Bumps deps for btcli
ibraheem-abe Feb 20, 2025
be092f5
Refactor the logic for the SubtensorInterface.__aenter__ so that it d…
thewhaleking Feb 20, 2025
b2beed5
Merge branch 'staging' of https://github.com/opentensor/btcli into fi…
Feb 20, 2025
25c2acb
Bumps requirements
ibraheem-abe Feb 20, 2025
34ab9e5
cleanup
ibraheem-abe Feb 20, 2025
fa4008d
more cleanup
ibraheem-abe Feb 20, 2025
a962a1d
ruff
ibraheem-abe Feb 20, 2025
8e9afc7
Merge pull request #330 from opentensor/update/requirements-902
ibraheem-abe Feb 20, 2025
323d0ef
Merge pull request #331 from opentensor/feat/thewhaleking/aenter-logic
ibraheem-abe Feb 20, 2025
4c6a4b0
Merge pull request #323 from igorsyl/fix/igorsyl/version
ibraheem-abe Feb 20, 2025
9692d50
Bumps version and changelog
ibraheem-abe Feb 20, 2025
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
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog

## 9.0.2 /2025-02-20

## What's Changed
* Fix stake child get by @thewhaleking in https://github.com/opentensor/btcli/pull/321
* Edge case alpha formatting by @thewhaleking in https://github.com/opentensor/btcli/pull/318
* Adds Tao emissions to stake list by @ibraheem-opentensor in https://github.com/opentensor/btcli/pull/300
* Updates balance command by @ibraheem-opentensor in https://github.com/opentensor/btcli/pull/322
* Backmerge main to staging 101 by @ibraheem-opentensor in https://github.com/opentensor/btcli/pull/326
* Updates stake list (with swap value) by @ibraheem-opentensor in https://github.com/opentensor/btcli/pull/327
* Adds unstaking from all hotkeys + tests by @ibraheem-opentensor in https://github.com/opentensor/btcli/pull/325
* Mnemonic helper text by @thewhaleking in https://github.com/opentensor/btcli/pull/329
* fix: remove double conversion in stake swap functionality [--swap_all] by @ashikshafi08 in https://github.com/opentensor/btcli/pull/328
* Arbitrary Hyperparams Setting by @thewhaleking in https://github.com/opentensor/btcli/pull/320
* Bumps deps for btcli by @ibraheem-opentensor in https://github.com/opentensor/btcli/pull/330
* SubtensorInterface async with logic by @thewhaleking in https://github.com/opentensor/btcli/pull/331
* remove __version__ from cli.py by @igorsyl in https://github.com/opentensor/btcli/pull/323

## New Contributors
* @ashikshafi08 made their first contribution in https://github.com/opentensor/btcli/pull/328
* @igorsyl made their first contribution in https://github.com/opentensor/btcli/pull/323

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

## 9.0.1 /2025-02-13

## What's Changed
Expand Down
5 changes: 2 additions & 3 deletions bittensor_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
# DEALINGS IN THE SOFTWARE.

from .cli import CLIManager
from .version import __version__, __version_as_int__


__version__ = "9.0.1"

__all__ = ["CLIManager", "__version__"]
__all__ = ["CLIManager"]
60 changes: 38 additions & 22 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
WalletValidationTypes as WV,
Constants,
COLOR_PALETTE,
HYPERPARAMS,
)
from bittensor_cli.version import __version__, __version_as_int__
from bittensor_cli.src.bittensor import utils
from bittensor_cli.src.bittensor.balances import Balance
from async_substrate_interface.errors import SubstrateRequestException
Expand Down Expand Up @@ -72,21 +74,8 @@ class GitError(Exception):
pass


__version__ = "9.0.1"


_core_version = re.match(r"^\d+\.\d+\.\d+", __version__).group(0)
_version_split = _core_version.split(".")
__version_info__ = tuple(int(part) for part in _version_split)
_version_int_base = 1000
assert max(__version_info__) < _version_int_base

__version_as_int__: int = sum(
e * (_version_int_base**i) for i, e in enumerate(reversed(__version_info__))
)
assert __version_as_int__ < 2**31 # fits in int32
__new_signature_version__ = 360

_epilog = "Made with [bold red]:heart:[/bold red] by The Openτensor Foundaτion"

np.set_printoptions(precision=8, suppress=True, floatmode="fixed")
Expand Down Expand Up @@ -124,7 +113,7 @@ class Options:
)
mnemonic = typer.Option(
None,
help="Mnemonic used to regenerate your key. For example: horse cart dog ...",
help='Mnemonic used to regenerate your key. For example: "horse cart dog ..."',
)
seed = typer.Option(
None, help="Seed hex string used to regenerate your key. For example: 0x1234..."
Expand Down Expand Up @@ -2130,6 +2119,7 @@ def wallet_regen_hotkey(
# Example usage:

[green]$[/green] btcli wallet regen_hotkey --seed 0x1234...
[green]$[/green] btcli wallet regen-hotkey --mnemonic "word1 word2 ... word12"

[bold]Note[/bold]: This command is essential for users who need to regenerate their hotkey, possibly for security upgrades or key recovery.
It should be used with caution to avoid accidental overwriting of existing keys.
Expand Down Expand Up @@ -3221,11 +3211,23 @@ 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 @@ -3234,6 +3236,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 @@ -3249,6 +3259,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 Expand Up @@ -3961,7 +3974,7 @@ def sudo_set(
param_name: str = typer.Option(
"", "--param", "--parameter", help="The subnet hyperparameter to set"
),
param_value: str = typer.Option(
param_value: Optional[str] = typer.Option(
"", "--value", help="Value to set the hyperparameter to."
),
quiet: bool = Options.quiet,
Expand Down Expand Up @@ -4010,9 +4023,12 @@ def sudo_set(
param_value = f"{low_val},{high_val}"

if not param_value:
param_value = Prompt.ask(
f"Enter the new value for [{COLOR_PALETTE['GENERAL']['SUBHEADING']}]{param_name}[/{COLOR_PALETTE['GENERAL']['SUBHEADING']}] in the VALUE column format"
)
if HYPERPARAMS.get(param_name):
param_value = Prompt.ask(
f"Enter the new value for [{COLOR_PALETTE['GENERAL']['SUBHEADING']}]{param_name}[/{COLOR_PALETTE['GENERAL']['SUBHEADING']}] in the VALUE column format"
)
else:
param_value = None

wallet = self.wallet_ask(
wallet_name, wallet_path, wallet_hotkey, ask_for=[WO.NAME, WO.PATH]
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 @@ -672,7 +672,7 @@ class WalletValidationTypes(Enum):
"commit_reveal_weights_enabled": ("sudo_set_commit_reveal_weights_enabled", False),
"alpha_values": ("sudo_set_alpha_values", False),
"liquid_alpha_enabled": ("sudo_set_liquid_alpha_enabled", False),
"network_registration_allowed": ("sudo_set_network_registration_allowed", False),
"registration_allowed": ("sudo_set_network_registration_allowed", False),
"network_pow_registration_allowed": (
"sudo_set_network_pow_registration_allowed",
False,
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
30 changes: 16 additions & 14 deletions bittensor_cli/src/bittensor/subtensor_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ async def __aenter__(self):
f"[yellow]Connecting to Substrate:[/yellow][bold white] {self}..."
):
try:
async with self.substrate:
return self
await self.substrate.initialize()
return self
except TimeoutError: # TODO verify
err_console.print(
"\n[red]Error[/red]: Timeout occurred connecting to substrate. "
Expand Down 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
8 changes: 2 additions & 6 deletions bittensor_cli/src/commands/stake/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ async def safe_stake_extrinsic(
)
return
else:
err_out(
f"\n{failure_prelude} with error: {format_error_message(e)}"
)
err_out(f"\n{failure_prelude} with error: {format_error_message(e)}")
return
else:
await response.process_events()
Expand Down Expand Up @@ -180,9 +178,7 @@ async def stake_extrinsic(
extrinsic, wait_for_inclusion=True, wait_for_finalization=False
)
except SubstrateRequestException as e:
err_out(
f"\n{failure_prelude} with error: {format_error_message(e)}"
)
err_out(f"\n{failure_prelude} with error: {format_error_message(e)}")
return
else:
await response.process_events()
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
Loading