bittensor-cli 9.1.2__py3-none-any.whl → 9.1.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bittensor_cli/cli.py +22 -18
- bittensor_cli/src/__init__.py +105 -58
- bittensor_cli/src/bittensor/chain_data.py +3 -1
- bittensor_cli/src/bittensor/subtensor_interface.py +13 -5
- bittensor_cli/src/bittensor/utils.py +2 -3
- bittensor_cli/src/commands/stake/__init__.py +0 -154
- bittensor_cli/src/commands/stake/add.py +19 -23
- bittensor_cli/src/commands/stake/children_hotkeys.py +18 -15
- bittensor_cli/src/commands/stake/list.py +93 -95
- bittensor_cli/src/commands/stake/move.py +0 -3
- bittensor_cli/src/commands/stake/remove.py +38 -33
- bittensor_cli/src/commands/subnets/subnets.py +14 -14
- bittensor_cli/src/commands/sudo.py +1 -2
- bittensor_cli/src/commands/wallets.py +4 -3
- bittensor_cli/version.py +2 -1
- {bittensor_cli-9.1.2.dist-info → bittensor_cli-9.1.4.dist-info}/METADATA +2 -2
- bittensor_cli-9.1.4.dist-info/RECORD +35 -0
- bittensor_cli-9.1.2.dist-info/RECORD +0 -35
- {bittensor_cli-9.1.2.dist-info → bittensor_cli-9.1.4.dist-info}/WHEEL +0 -0
- {bittensor_cli-9.1.2.dist-info → bittensor_cli-9.1.4.dist-info}/entry_points.txt +0 -0
- {bittensor_cli-9.1.2.dist-info → bittensor_cli-9.1.4.dist-info}/top_level.txt +0 -0
@@ -46,9 +46,7 @@ async def stake_add(
|
|
46
46
|
netuid: the netuid to stake to (None indicates all subnets)
|
47
47
|
stake_all: whether to stake all available balance
|
48
48
|
amount: specified amount of balance to stake
|
49
|
-
delegate: whether to delegate stake, currently unused
|
50
49
|
prompt: whether to prompt the user
|
51
|
-
max_stake: maximum amount to stake (used in combination with stake_all), currently unused
|
52
50
|
all_hotkeys: whether to stake all hotkeys
|
53
51
|
include_hotkeys: list of hotkeys to include in staking process (if not specifying `--all`)
|
54
52
|
exclude_hotkeys: list of hotkeys to exclude in staking (if specifying `--all`)
|
@@ -61,18 +59,16 @@ async def stake_add(
|
|
61
59
|
"""
|
62
60
|
|
63
61
|
async def safe_stake_extrinsic(
|
64
|
-
|
65
|
-
|
62
|
+
netuid_: int,
|
63
|
+
amount_: Balance,
|
66
64
|
current_stake: Balance,
|
67
|
-
|
65
|
+
hotkey_ss58_: str,
|
68
66
|
price_limit: Balance,
|
69
|
-
wallet: Wallet,
|
70
|
-
subtensor: "SubtensorInterface",
|
71
67
|
status=None,
|
72
68
|
) -> None:
|
73
69
|
err_out = partial(print_error, status=status)
|
74
70
|
failure_prelude = (
|
75
|
-
f":cross_mark: [red]Failed[/red] to stake {
|
71
|
+
f":cross_mark: [red]Failed[/red] to stake {amount_} on Netuid {netuid_}"
|
76
72
|
)
|
77
73
|
current_balance = await subtensor.get_balance(wallet.coldkeypub.ss58_address)
|
78
74
|
next_nonce = await subtensor.substrate.get_account_next_index(
|
@@ -82,9 +78,9 @@ async def stake_add(
|
|
82
78
|
call_module="SubtensorModule",
|
83
79
|
call_function="add_stake_limit",
|
84
80
|
call_params={
|
85
|
-
"hotkey":
|
86
|
-
"netuid":
|
87
|
-
"amount_staked":
|
81
|
+
"hotkey": hotkey_ss58_,
|
82
|
+
"netuid": netuid_,
|
83
|
+
"amount_staked": amount_.rao,
|
88
84
|
"limit_price": price_limit,
|
89
85
|
"allow_partial": allow_partial_stake,
|
90
86
|
},
|
@@ -119,30 +115,30 @@ async def stake_add(
|
|
119
115
|
new_balance, new_stake = await asyncio.gather(
|
120
116
|
subtensor.get_balance(wallet.coldkeypub.ss58_address, block_hash),
|
121
117
|
subtensor.get_stake(
|
122
|
-
hotkey_ss58=
|
118
|
+
hotkey_ss58=hotkey_ss58_,
|
123
119
|
coldkey_ss58=wallet.coldkeypub.ss58_address,
|
124
|
-
netuid=
|
120
|
+
netuid=netuid_,
|
125
121
|
block_hash=block_hash,
|
126
122
|
),
|
127
123
|
)
|
128
124
|
console.print(
|
129
|
-
f":white_heavy_check_mark: [dark_sea_green3]Finalized. Stake added to netuid: {
|
125
|
+
f":white_heavy_check_mark: [dark_sea_green3]Finalized. Stake added to netuid: {netuid_}[/dark_sea_green3]"
|
130
126
|
)
|
131
127
|
console.print(
|
132
128
|
f"Balance:\n [blue]{current_balance}[/blue] :arrow_right: [{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}]{new_balance}"
|
133
129
|
)
|
134
130
|
|
135
131
|
amount_staked = current_balance - new_balance
|
136
|
-
if allow_partial_stake and (amount_staked !=
|
132
|
+
if allow_partial_stake and (amount_staked != amount_):
|
137
133
|
console.print(
|
138
134
|
"Partial stake transaction. Staked:\n"
|
139
135
|
f" [{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}]{amount_staked}[/{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}] "
|
140
136
|
f"instead of "
|
141
|
-
f"[blue]{
|
137
|
+
f"[blue]{amount_}[/blue]"
|
142
138
|
)
|
143
139
|
|
144
140
|
console.print(
|
145
|
-
f"Subnet: [{COLOR_PALETTE['GENERAL']['SUBHEADING']}]{
|
141
|
+
f"Subnet: [{COLOR_PALETTE['GENERAL']['SUBHEADING']}]{netuid_}[/{COLOR_PALETTE['GENERAL']['SUBHEADING']}] "
|
146
142
|
f"Stake:\n"
|
147
143
|
f" [blue]{current_stake}[/blue] "
|
148
144
|
f":arrow_right: "
|
@@ -361,13 +357,11 @@ async def stake_add(
|
|
361
357
|
else:
|
362
358
|
stake_coroutines.append(
|
363
359
|
safe_stake_extrinsic(
|
364
|
-
|
365
|
-
|
360
|
+
netuid_=ni,
|
361
|
+
amount_=am,
|
366
362
|
current_stake=curr,
|
367
|
-
|
363
|
+
hotkey_ss58_=staking_address,
|
368
364
|
price_limit=price_with_tolerance,
|
369
|
-
wallet=wallet,
|
370
|
-
subtensor=subtensor,
|
371
365
|
)
|
372
366
|
)
|
373
367
|
else:
|
@@ -590,7 +584,9 @@ The columns are as follows:
|
|
590
584
|
console.print(base_description + (safe_staking_description if safe_staking else ""))
|
591
585
|
|
592
586
|
|
593
|
-
def _calculate_slippage(
|
587
|
+
def _calculate_slippage(
|
588
|
+
subnet_info, amount: Balance
|
589
|
+
) -> tuple[Balance, str, float, str]:
|
594
590
|
"""Calculate slippage when adding stake.
|
595
591
|
|
596
592
|
Args:
|
@@ -190,7 +190,7 @@ async def set_childkey_take_extrinsic(
|
|
190
190
|
f":satellite: Setting childkey take on [white]{subtensor.network}[/white] ..."
|
191
191
|
):
|
192
192
|
try:
|
193
|
-
if 0
|
193
|
+
if 0 <= take <= 0.18:
|
194
194
|
take_u16 = float_to_u16(take)
|
195
195
|
else:
|
196
196
|
return False, "Invalid take value"
|
@@ -313,9 +313,12 @@ async def get_children(
|
|
313
313
|
"""
|
314
314
|
Get the take value for a given subtensor, hotkey, and netuid.
|
315
315
|
|
316
|
-
|
316
|
+
Arguments:
|
317
|
+
child: The hotkey to retrieve the take value for.
|
318
|
+
netuid__: the netuid to retrieve the take value for.
|
317
319
|
|
318
|
-
|
320
|
+
Returns:
|
321
|
+
The take value as a float. If the take value is not available, it returns 0.
|
319
322
|
|
320
323
|
"""
|
321
324
|
child_hotkey = child[1]
|
@@ -383,7 +386,7 @@ async def get_children(
|
|
383
386
|
f"The total stake of parent hotkey '{parent_hotkey}'{insert_text}is {parent_total}."
|
384
387
|
)
|
385
388
|
|
386
|
-
for index, (
|
389
|
+
for index, (child_netuid, children_) in enumerate(netuid_children_):
|
387
390
|
# calculate totals
|
388
391
|
total_proportion_per_netuid = 0
|
389
392
|
total_stake_weight_per_netuid = 0
|
@@ -393,7 +396,7 @@ async def get_children(
|
|
393
396
|
|
394
397
|
children_info = []
|
395
398
|
child_takes = await asyncio.gather(
|
396
|
-
*[get_take(c,
|
399
|
+
*[get_take(c, child_netuid) for c in children_]
|
397
400
|
)
|
398
401
|
for child, child_take in zip(children_, child_takes):
|
399
402
|
proportion = child[0]
|
@@ -408,7 +411,7 @@ async def get_children(
|
|
408
411
|
(
|
409
412
|
converted_proportion,
|
410
413
|
child_hotkey,
|
411
|
-
hotkey_stake_dict[child_hotkey][
|
414
|
+
hotkey_stake_dict[child_hotkey][child_netuid],
|
412
415
|
child_take,
|
413
416
|
)
|
414
417
|
)
|
@@ -420,7 +423,7 @@ async def get_children(
|
|
420
423
|
for proportion_, hotkey, stake, child_take in children_info:
|
421
424
|
proportion_percent = proportion_ * 100 # Proportion in percent
|
422
425
|
proportion_tao = (
|
423
|
-
hotkey_stake[
|
426
|
+
hotkey_stake[child_netuid].tao * proportion_
|
424
427
|
) # Proportion in TAO
|
425
428
|
|
426
429
|
total_proportion_per_netuid += proportion_percent
|
@@ -433,7 +436,7 @@ async def get_children(
|
|
433
436
|
|
434
437
|
hotkey = Text(hotkey, style="italic red" if proportion_ == 0 else "")
|
435
438
|
table.add_row(
|
436
|
-
str(
|
439
|
+
str(child_netuid),
|
437
440
|
hotkey,
|
438
441
|
proportion_str,
|
439
442
|
take_str,
|
@@ -661,28 +664,28 @@ async def childkey_take(
|
|
661
664
|
table.add_column("Netuid", justify="center", style="cyan")
|
662
665
|
table.add_column("Take (%)", justify="right", style="magenta")
|
663
666
|
|
664
|
-
for
|
665
|
-
table.add_row(str(
|
667
|
+
for take_netuid, take_value in takes:
|
668
|
+
table.add_row(str(take_netuid), f"{take_value:.2f}%")
|
666
669
|
|
667
670
|
console.print(table)
|
668
671
|
|
669
|
-
async def display_chk_take(ss58,
|
672
|
+
async def display_chk_take(ss58, take_netuid):
|
670
673
|
"""Print single key take for hotkey and netuid"""
|
671
674
|
chk_take = await get_childkey_take(
|
672
|
-
subtensor=subtensor, netuid=
|
675
|
+
subtensor=subtensor, netuid=take_netuid, hotkey=ss58
|
673
676
|
)
|
674
677
|
if chk_take is None:
|
675
678
|
chk_take = 0
|
676
679
|
chk_take = u16_to_float(chk_take)
|
677
680
|
console.print(
|
678
|
-
f"Child take for {ss58} is: {chk_take * 100:.2f}% on netuid {
|
681
|
+
f"Child take for {ss58} is: {chk_take * 100:.2f}% on netuid {take_netuid}."
|
679
682
|
)
|
680
683
|
|
681
684
|
async def chk_all_subnets(ss58):
|
682
685
|
"""Aggregate data for childkey take from all subnets"""
|
683
|
-
|
686
|
+
all_netuids = await subtensor.get_all_subnet_netuids()
|
684
687
|
takes = []
|
685
|
-
for subnet in
|
688
|
+
for subnet in all_netuids:
|
686
689
|
if subnet == 0:
|
687
690
|
continue
|
688
691
|
curr_take = await get_childkey_take(
|
@@ -34,38 +34,37 @@ async def stake_list(
|
|
34
34
|
):
|
35
35
|
coldkey_address = coldkey_ss58 if coldkey_ss58 else wallet.coldkeypub.ss58_address
|
36
36
|
|
37
|
-
async def get_stake_data(
|
37
|
+
async def get_stake_data(block_hash_: str = None):
|
38
38
|
(
|
39
|
-
|
40
|
-
|
39
|
+
sub_stakes_,
|
40
|
+
registered_delegate_info_,
|
41
41
|
_dynamic_info,
|
42
42
|
) = await asyncio.gather(
|
43
43
|
subtensor.get_stake_for_coldkey(
|
44
|
-
coldkey_ss58=coldkey_address, block_hash=
|
44
|
+
coldkey_ss58=coldkey_address, block_hash=block_hash_
|
45
45
|
),
|
46
|
-
subtensor.get_delegate_identities(block_hash=
|
47
|
-
subtensor.all_subnets(block_hash=
|
46
|
+
subtensor.get_delegate_identities(block_hash=block_hash_),
|
47
|
+
subtensor.all_subnets(block_hash=block_hash_),
|
48
48
|
)
|
49
49
|
# sub_stakes = substakes[coldkey_address]
|
50
|
-
|
50
|
+
dynamic_info__ = {info.netuid: info for info in _dynamic_info}
|
51
51
|
return (
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
sub_stakes_,
|
53
|
+
registered_delegate_info_,
|
54
|
+
dynamic_info__,
|
55
55
|
)
|
56
56
|
|
57
57
|
def define_table(
|
58
|
-
|
58
|
+
hotkey_name_: str,
|
59
59
|
rows: list[list[str]],
|
60
|
-
|
61
|
-
|
62
|
-
live: bool = False,
|
60
|
+
total_tao_value_: Balance,
|
61
|
+
total_swapped_tao_value_: Balance,
|
63
62
|
):
|
64
|
-
title = f"\n[{COLOR_PALETTE['GENERAL']['HEADER']}]Hotkey: {
|
63
|
+
title = f"\n[{COLOR_PALETTE['GENERAL']['HEADER']}]Hotkey: {hotkey_name_}\nNetwork: {subtensor.network}\n\n"
|
65
64
|
# TODO: Add hint back in after adding columns descriptions
|
66
65
|
# if not live:
|
67
66
|
# title += f"[{COLOR_PALETTE['GENERAL']['HINT']}]See below for an explanation of the columns\n"
|
68
|
-
|
67
|
+
defined_table = Table(
|
69
68
|
title=title,
|
70
69
|
show_footer=True,
|
71
70
|
show_edge=False,
|
@@ -76,74 +75,74 @@ async def stake_list(
|
|
76
75
|
show_lines=False,
|
77
76
|
pad_edge=True,
|
78
77
|
)
|
79
|
-
|
78
|
+
defined_table.add_column(
|
80
79
|
"[white]Netuid",
|
81
80
|
footer=f"{len(rows)}",
|
82
81
|
footer_style="overline white",
|
83
82
|
style="grey89",
|
84
83
|
)
|
85
|
-
|
84
|
+
defined_table.add_column(
|
86
85
|
"[white]Name",
|
87
86
|
style="cyan",
|
88
87
|
justify="left",
|
89
88
|
no_wrap=True,
|
90
89
|
)
|
91
|
-
|
90
|
+
defined_table.add_column(
|
92
91
|
f"[white]Value \n({Balance.get_unit(1)} x {Balance.unit}/{Balance.get_unit(1)})",
|
93
92
|
footer_style="overline white",
|
94
93
|
style=COLOR_PALETTE["STAKE"]["TAO"],
|
95
94
|
justify="right",
|
96
|
-
footer=f"τ {millify_tao(
|
95
|
+
footer=f"τ {millify_tao(total_tao_value_.tao)}"
|
97
96
|
if not verbose
|
98
|
-
else f"{
|
97
|
+
else f"{total_tao_value_}",
|
99
98
|
)
|
100
|
-
|
99
|
+
defined_table.add_column(
|
101
100
|
f"[white]Stake ({Balance.get_unit(1)})",
|
102
101
|
footer_style="overline white",
|
103
102
|
style=COLOR_PALETTE["STAKE"]["STAKE_ALPHA"],
|
104
103
|
justify="center",
|
105
104
|
)
|
106
|
-
|
105
|
+
defined_table.add_column(
|
107
106
|
f"[white]Price \n({Balance.unit}_in/{Balance.get_unit(1)}_in)",
|
108
107
|
footer_style="white",
|
109
108
|
style=COLOR_PALETTE["POOLS"]["RATE"],
|
110
109
|
justify="center",
|
111
110
|
)
|
112
|
-
|
111
|
+
defined_table.add_column(
|
113
112
|
f"[white]Swap ({Balance.get_unit(1)} -> {Balance.unit})",
|
114
113
|
footer_style="overline white",
|
115
114
|
style=COLOR_PALETTE["STAKE"]["STAKE_SWAP"],
|
116
115
|
justify="right",
|
117
|
-
footer=f"τ {millify_tao(
|
116
|
+
footer=f"τ {millify_tao(total_swapped_tao_value_.tao)}"
|
118
117
|
if not verbose
|
119
|
-
else f"{
|
118
|
+
else f"{total_swapped_tao_value_}",
|
120
119
|
)
|
121
|
-
|
120
|
+
defined_table.add_column(
|
122
121
|
"[white]Registered",
|
123
122
|
style=COLOR_PALETTE["STAKE"]["STAKE_ALPHA"],
|
124
123
|
justify="right",
|
125
124
|
)
|
126
|
-
|
125
|
+
defined_table.add_column(
|
127
126
|
f"[white]Emission \n({Balance.get_unit(1)}/block)",
|
128
127
|
style=COLOR_PALETTE["POOLS"]["EMISSION"],
|
129
128
|
justify="right",
|
130
129
|
)
|
131
|
-
|
130
|
+
defined_table.add_column(
|
132
131
|
f"[white]Emission \n({Balance.get_unit(0)}/block)",
|
133
132
|
style=COLOR_PALETTE["POOLS"]["EMISSION"],
|
134
133
|
justify="right",
|
135
134
|
)
|
136
|
-
return
|
135
|
+
return defined_table
|
137
136
|
|
138
137
|
def create_table(hotkey_: str, substakes: list[StakeInfo]):
|
139
|
-
|
138
|
+
name_ = (
|
140
139
|
f"{registered_delegate_info[hotkey_].display} ({hotkey_})"
|
141
140
|
if hotkey_ in registered_delegate_info
|
142
141
|
else hotkey_
|
143
142
|
)
|
144
143
|
rows = []
|
145
|
-
|
146
|
-
|
144
|
+
total_tao_value_ = Balance(0)
|
145
|
+
total_swapped_tao_value_ = Balance(0)
|
147
146
|
root_stakes = [s for s in substakes if s.netuid == 0]
|
148
147
|
other_stakes = sorted(
|
149
148
|
[s for s in substakes if s.netuid != 0],
|
@@ -162,14 +161,14 @@ async def stake_list(
|
|
162
161
|
alpha_value = Balance.from_rao(int(substake_.stake.rao)).set_unit(netuid)
|
163
162
|
|
164
163
|
# TAO value cell
|
165
|
-
|
166
|
-
|
164
|
+
tao_value_ = pool.alpha_to_tao(alpha_value)
|
165
|
+
total_tao_value_ += tao_value_
|
167
166
|
|
168
167
|
# Swapped TAO value and slippage cell
|
169
|
-
|
168
|
+
swapped_tao_value_, _, slippage_percentage_ = (
|
170
169
|
pool.alpha_to_tao_with_slippage(substake_.stake)
|
171
170
|
)
|
172
|
-
|
171
|
+
total_swapped_tao_value_ += swapped_tao_value_
|
173
172
|
|
174
173
|
# Slippage percentage cell
|
175
174
|
if pool.is_dynamic:
|
@@ -181,9 +180,9 @@ async def stake_list(
|
|
181
180
|
swap_value = f"[{COLOR_PALETTE['STAKE']['NOT_REGISTERED']}]N/A[/{COLOR_PALETTE['STAKE']['NOT_REGISTERED']}] ({slippage_percentage})"
|
182
181
|
else:
|
183
182
|
swap_value = (
|
184
|
-
f"τ {millify_tao(
|
183
|
+
f"τ {millify_tao(swapped_tao_value_.tao)} ({slippage_percentage})"
|
185
184
|
if not verbose
|
186
|
-
else f"{
|
185
|
+
else f"{swapped_tao_value_} ({slippage_percentage})"
|
187
186
|
)
|
188
187
|
|
189
188
|
# Per block emission cell
|
@@ -202,9 +201,9 @@ async def stake_list(
|
|
202
201
|
[
|
203
202
|
str(netuid), # Number
|
204
203
|
subnet_name_cell, # Symbol + name
|
205
|
-
f"τ {millify_tao(
|
204
|
+
f"τ {millify_tao(tao_value_.tao)}"
|
206
205
|
if not verbose
|
207
|
-
else f"{
|
206
|
+
else f"{tao_value_}", # Value (α x τ/α)
|
208
207
|
f"{stake_value} {symbol}"
|
209
208
|
if netuid != 0
|
210
209
|
else f"{symbol} {stake_value}", # Stake (a)
|
@@ -221,27 +220,33 @@ async def stake_list(
|
|
221
220
|
str(Balance.from_tao(per_block_tao_emission)),
|
222
221
|
]
|
223
222
|
)
|
224
|
-
|
223
|
+
created_table = define_table(
|
224
|
+
name_, rows, total_tao_value_, total_swapped_tao_value_
|
225
|
+
)
|
225
226
|
for row in rows:
|
226
|
-
|
227
|
-
console.print(
|
228
|
-
return
|
227
|
+
created_table.add_row(*row)
|
228
|
+
console.print(created_table)
|
229
|
+
return total_tao_value_, total_swapped_tao_value_
|
229
230
|
|
230
231
|
def create_live_table(
|
231
232
|
substakes: list,
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
) -> tuple[Table, dict, Balance, Balance, Balance]:
|
233
|
+
dynamic_info_for_lt: dict,
|
234
|
+
hotkey_name_: str,
|
235
|
+
previous_data_: Optional[dict] = None,
|
236
|
+
) -> tuple[Table, dict]:
|
237
237
|
rows = []
|
238
|
-
|
238
|
+
current_data_ = {}
|
239
239
|
|
240
|
-
|
241
|
-
|
240
|
+
total_tao_value_ = Balance(0)
|
241
|
+
total_swapped_tao_value_ = Balance(0)
|
242
242
|
|
243
243
|
def format_cell(
|
244
|
-
value,
|
244
|
+
value,
|
245
|
+
previous_value,
|
246
|
+
unit="",
|
247
|
+
unit_first_=False,
|
248
|
+
precision=4,
|
249
|
+
millify=False,
|
245
250
|
):
|
246
251
|
if previous_value is not None:
|
247
252
|
change = value - previous_value
|
@@ -265,7 +270,7 @@ async def stake_list(
|
|
265
270
|
)
|
266
271
|
return (
|
267
272
|
f"{formatted_value} {unit}{change_text}"
|
268
|
-
if not
|
273
|
+
if not unit_first_
|
269
274
|
else f"{unit} {formatted_value}{change_text}"
|
270
275
|
)
|
271
276
|
|
@@ -273,7 +278,7 @@ async def stake_list(
|
|
273
278
|
root_stakes = [s for s in substakes if s.netuid == 0]
|
274
279
|
other_stakes = sorted(
|
275
280
|
[s for s in substakes if s.netuid != 0],
|
276
|
-
key=lambda x:
|
281
|
+
key=lambda x: dynamic_info_for_lt[x.netuid]
|
277
282
|
.alpha_to_tao(Balance.from_rao(int(x.stake.rao)).set_unit(x.netuid))
|
278
283
|
.tao,
|
279
284
|
reverse=True,
|
@@ -281,41 +286,41 @@ async def stake_list(
|
|
281
286
|
sorted_substakes = root_stakes + other_stakes
|
282
287
|
|
283
288
|
# Process each stake
|
284
|
-
for
|
285
|
-
netuid =
|
286
|
-
pool =
|
287
|
-
if
|
289
|
+
for substake_ in sorted_substakes:
|
290
|
+
netuid = substake_.netuid
|
291
|
+
pool = dynamic_info_for_lt.get(netuid)
|
292
|
+
if substake_.stake.rao == 0 or not pool:
|
288
293
|
continue
|
289
294
|
|
290
295
|
# Calculate base values
|
291
296
|
symbol = f"{Balance.get_unit(netuid)}\u200e"
|
292
|
-
alpha_value = Balance.from_rao(int(
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
+
alpha_value = Balance.from_rao(int(substake_.stake.rao)).set_unit(netuid)
|
298
|
+
tao_value_ = pool.alpha_to_tao(alpha_value)
|
299
|
+
total_tao_value_ += tao_value_
|
300
|
+
swapped_tao_value_, slippage, slippage_pct = (
|
301
|
+
pool.alpha_to_tao_with_slippage(substake_.stake)
|
297
302
|
)
|
298
|
-
|
303
|
+
total_swapped_tao_value_ += swapped_tao_value_
|
299
304
|
|
300
305
|
# Store current values for future delta tracking
|
301
|
-
|
306
|
+
current_data_[netuid] = {
|
302
307
|
"stake": alpha_value.tao,
|
303
308
|
"price": pool.price.tao,
|
304
|
-
"tao_value":
|
305
|
-
"swapped_value":
|
306
|
-
"emission":
|
307
|
-
"tao_emission":
|
309
|
+
"tao_value": tao_value_.tao,
|
310
|
+
"swapped_value": swapped_tao_value_.tao,
|
311
|
+
"emission": substake_.emission.tao / (pool.tempo or 1),
|
312
|
+
"tao_emission": substake_.tao_emission.tao / (pool.tempo or 1),
|
308
313
|
}
|
309
314
|
|
310
315
|
# Get previous values for delta tracking
|
311
|
-
prev =
|
316
|
+
prev = previous_data_.get(netuid, {}) if previous_data_ else {}
|
312
317
|
unit_first = True if netuid == 0 else False
|
313
318
|
|
314
319
|
stake_cell = format_cell(
|
315
320
|
alpha_value.tao,
|
316
321
|
prev.get("stake"),
|
317
322
|
unit=symbol,
|
318
|
-
|
323
|
+
unit_first_=unit_first,
|
319
324
|
precision=4,
|
320
325
|
millify=True if not verbose else False,
|
321
326
|
)
|
@@ -324,16 +329,16 @@ async def stake_list(
|
|
324
329
|
pool.price.tao,
|
325
330
|
prev.get("price"),
|
326
331
|
unit=f"τ/{symbol}",
|
327
|
-
|
332
|
+
unit_first_=False,
|
328
333
|
precision=5,
|
329
334
|
millify=True if not verbose else False,
|
330
335
|
)
|
331
336
|
|
332
337
|
exchange_cell = format_cell(
|
333
|
-
|
338
|
+
tao_value_.tao,
|
334
339
|
prev.get("tao_value"),
|
335
340
|
unit="τ",
|
336
|
-
|
341
|
+
unit_first_=True,
|
337
342
|
precision=4,
|
338
343
|
millify=True if not verbose else False,
|
339
344
|
)
|
@@ -341,10 +346,10 @@ async def stake_list(
|
|
341
346
|
if netuid != 0:
|
342
347
|
swap_cell = (
|
343
348
|
format_cell(
|
344
|
-
|
349
|
+
swapped_tao_value_.tao,
|
345
350
|
prev.get("swapped_value"),
|
346
351
|
unit="τ",
|
347
|
-
|
352
|
+
unit_first_=True,
|
348
353
|
precision=4,
|
349
354
|
millify=True if not verbose else False,
|
350
355
|
)
|
@@ -353,27 +358,27 @@ async def stake_list(
|
|
353
358
|
else:
|
354
359
|
swap_cell = f"[{COLOR_PALETTE['STAKE']['NOT_REGISTERED']}]N/A[/{COLOR_PALETTE['STAKE']['NOT_REGISTERED']}] ({slippage_pct}%)"
|
355
360
|
|
356
|
-
emission_value =
|
361
|
+
emission_value = substake_.emission.tao / (pool.tempo or 1)
|
357
362
|
emission_cell = format_cell(
|
358
363
|
emission_value,
|
359
364
|
prev.get("emission"),
|
360
365
|
unit=symbol,
|
361
|
-
|
366
|
+
unit_first_=unit_first,
|
362
367
|
precision=4,
|
363
368
|
)
|
364
369
|
|
365
|
-
tao_emission_value =
|
370
|
+
tao_emission_value = substake_.tao_emission.tao / (pool.tempo or 1)
|
366
371
|
tao_emission_cell = format_cell(
|
367
372
|
tao_emission_value,
|
368
373
|
prev.get("tao_emission"),
|
369
374
|
unit="τ",
|
370
|
-
|
375
|
+
unit_first_=unit_first,
|
371
376
|
precision=4,
|
372
377
|
)
|
373
378
|
|
374
379
|
subnet_name_cell = (
|
375
380
|
f"[{COLOR_PALETTE['GENERAL']['SYMBOL']}]{symbol if netuid != 0 else 'τ'}[/{COLOR_PALETTE['GENERAL']['SYMBOL']}]"
|
376
|
-
f" {get_subnet_name(
|
381
|
+
f" {get_subnet_name(dynamic_info_for_lt[netuid])}"
|
377
382
|
)
|
378
383
|
|
379
384
|
rows.append(
|
@@ -385,25 +390,21 @@ async def stake_list(
|
|
385
390
|
rate_cell, # Rate
|
386
391
|
swap_cell, # Swap value with slippage
|
387
392
|
"YES"
|
388
|
-
if
|
393
|
+
if substake_.is_registered
|
389
394
|
else f"[{COLOR_PALETTE['STAKE']['NOT_REGISTERED']}]NO", # Registration status
|
390
395
|
emission_cell, # Emission rate
|
391
396
|
tao_emission_cell, # TAO emission rate
|
392
397
|
]
|
393
398
|
)
|
394
399
|
|
395
|
-
|
396
|
-
|
397
|
-
rows,
|
398
|
-
total_tao_value,
|
399
|
-
total_swapped_tao_value,
|
400
|
-
live=True,
|
400
|
+
live_table = define_table(
|
401
|
+
hotkey_name_, rows, total_tao_value_, total_swapped_tao_value_
|
401
402
|
)
|
402
403
|
|
403
404
|
for row in rows:
|
404
|
-
|
405
|
+
live_table.add_row(*row)
|
405
406
|
|
406
|
-
return
|
407
|
+
return live_table, current_data_
|
407
408
|
|
408
409
|
# Main execution
|
409
410
|
block_hash = await subtensor.substrate.get_chain_head()
|
@@ -448,10 +449,8 @@ async def stake_list(
|
|
448
449
|
choices=[str(i) for i in range(len(hotkeys_to_substakes))],
|
449
450
|
)
|
450
451
|
selected_hotkey = list(hotkeys_to_substakes.keys())[int(selected_idx)]
|
451
|
-
selected_stakes = hotkeys_to_substakes[selected_hotkey]
|
452
452
|
else:
|
453
453
|
selected_hotkey = list(hotkeys_to_substakes.keys())[0]
|
454
|
-
selected_stakes = hotkeys_to_substakes[selected_hotkey]
|
455
454
|
|
456
455
|
hotkey_name = (
|
457
456
|
f"{registered_delegate_info[selected_hotkey].display} ({selected_hotkey})"
|
@@ -499,7 +498,6 @@ async def stake_list(
|
|
499
498
|
|
500
499
|
table, current_data = create_live_table(
|
501
500
|
selected_stakes,
|
502
|
-
registered_delegate_info,
|
503
501
|
dynamic_info_,
|
504
502
|
hotkey_name,
|
505
503
|
previous_data,
|
@@ -494,7 +494,6 @@ async def move_stake(
|
|
494
494
|
)
|
495
495
|
|
496
496
|
# Determine the amount we are moving.
|
497
|
-
amount_to_move_as_balance = None
|
498
497
|
if amount:
|
499
498
|
amount_to_move_as_balance = Balance.from_tao(amount)
|
500
499
|
elif stake_all:
|
@@ -669,7 +668,6 @@ async def transfer_stake(
|
|
669
668
|
)
|
670
669
|
return False
|
671
670
|
|
672
|
-
amount_to_transfer = None
|
673
671
|
if amount:
|
674
672
|
amount_to_transfer = Balance.from_tao(amount).set_unit(origin_netuid)
|
675
673
|
elif stake_all:
|
@@ -784,7 +782,6 @@ async def swap_stake(
|
|
784
782
|
Args:
|
785
783
|
wallet (Wallet): The wallet to swap stake from.
|
786
784
|
subtensor (SubtensorInterface): Subtensor interface instance.
|
787
|
-
hotkey_ss58 (str): The SS58 address of the hotkey whose stake is being swapped.
|
788
785
|
origin_netuid (int): The netuid from which stake is removed.
|
789
786
|
destination_netuid (int): The netuid to which stake is added.
|
790
787
|
amount (float): The amount to swap.
|