Skip to content

Commit 7b40887

Browse files
committed
update remove all
1 parent 069234c commit 7b40887

File tree

1 file changed

+16
-74
lines changed

1 file changed

+16
-74
lines changed

bittensor_cli/src/commands/stake/remove.py

Lines changed: 16 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ async def unstake(
232232
str(netuid), # Netuid
233233
staking_address_name, # Hotkey Name
234234
str(amount_to_unstake_as_balance), # Amount to Unstake
235-
str(subnet_info.price.tao)
235+
f"{subnet_info.price.tao:.6f}"
236236
+ f"({Balance.get_unit(0)}/{Balance.get_unit(netuid)})", # Rate
237237
str(stake_fee), # Fee
238238
str(received_amount), # Received Amount
@@ -255,7 +255,7 @@ async def unstake(
255255
base_table_row.extend(
256256
[
257257
# Rate with tolerance
258-
f"{rate_with_tolerance:.4f} {Balance.get_unit(0)}/{Balance.get_unit(netuid)}",
258+
f"{rate_with_tolerance:.6f} {Balance.get_unit(0)}/{Balance.get_unit(netuid)}",
259259
# Partial unstake
260260
f"[{'dark_sea_green3' if allow_partial_stake else 'red'}]"
261261
f"{allow_partial_stake}[/{'dark_sea_green3' if allow_partial_stake else 'red'}]",
@@ -446,8 +446,7 @@ async def unstake_all(
446446
# style=COLOR_PALETTE["STAKE"]["SLIPPAGE_PERCENT"],
447447
# )
448448

449-
# Calculate slippage and total received
450-
max_slippage = 0.0
449+
# Calculate total received
451450
total_received_value = Balance(0)
452451
for stake in stake_info:
453452
if stake.stake.rao == 0:
@@ -465,41 +464,33 @@ async def unstake_all(
465464
destination_coldkey_ss58=wallet.coldkeypub.ss58_address,
466465
amount=stake_amount.rao,
467466
)
467+
468468
try:
469-
received_amount, slippage_pct, slippage_pct_float = _calculate_slippage(
470-
subnet_info=subnet_info, amount=stake_amount, stake_fee=stake_fee
471-
)
472-
except ValueError:
469+
current_price = subnet_info.price.tao
470+
rate = current_price
471+
received_amount = stake_amount * rate - stake_fee
472+
473+
if received_amount < Balance.from_tao(0):
474+
print_error("Not enough Alpha to pay the transaction fee.")
475+
continue
476+
except (AttributeError, ValueError):
473477
continue
474478

475-
max_slippage = max(max_slippage, slippage_pct_float)
476479
total_received_value += received_amount
477480

478481
table.add_row(
479482
str(stake.netuid),
480483
hotkey_display,
481484
str(stake_amount),
482-
str(float(subnet_info.price))
485+
f"{float(subnet_info.price):.6f}"
483486
+ f"({Balance.get_unit(0)}/{Balance.get_unit(stake.netuid)})",
484487
str(stake_fee),
485-
# str(received_amount),
486-
# slippage_pct,
488+
str(received_amount),
487489
)
488490
console.print(table)
489-
if max_slippage > 5:
490-
message = (
491-
f"[{COLOR_PALETTE['STAKE']['SLIPPAGE_TEXT']}]--------------------------------------------------------------"
492-
f"-----------------------------------------------------\n"
493-
f"[bold]WARNING:[/bold] The slippage on one of your operations is high: "
494-
f"[{COLOR_PALETTE['STAKE']['SLIPPAGE_PERCENT']}]{max_slippage:.4f}%"
495-
f"[/{COLOR_PALETTE['STAKE']['SLIPPAGE_PERCENT']}], this may result in a loss of funds.\n"
496-
"----------------------------------------------------------------------------------------------------------"
497-
"---------\n"
498-
)
499-
console.print(message)
500491

501492
console.print(
502-
f"Expected return after slippage: [{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}]{total_received_value}"
493+
f"Total expected return: [{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}]{total_received_value}"
503494
)
504495

505496
if prompt and not Confirm.ask(
@@ -840,55 +831,6 @@ async def _unstake_all_extrinsic(
840831

841832

842833
# Helpers
843-
def _calculate_slippage(
844-
subnet_info, amount: Balance, stake_fee: Balance
845-
) -> tuple[Balance, str, float]:
846-
"""Calculate slippage and received amount for unstaking operation.
847-
848-
Args:
849-
subnet_info: Subnet information containing price data
850-
amount: Amount being unstaked
851-
stake_fee: Stake fee to include in slippage calculation
852-
853-
Returns:
854-
tuple containing:
855-
- received_amount: Balance after slippage deduction
856-
- slippage_pct: Formatted string of slippage percentage
857-
- slippage_pct_float: Float value of slippage percentage
858-
859-
TODO: Update to v3. This method only works for protocol-liquidity-only
860-
mode (user liquidity disabled)
861-
"""
862-
received_amount, _, _ = subnet_info.alpha_to_tao_with_slippage(amount)
863-
received_amount -= stake_fee
864-
865-
if received_amount < Balance.from_tao(0):
866-
print_error("Not enough Alpha to pay the transaction fee.")
867-
raise ValueError
868-
869-
if subnet_info.is_dynamic:
870-
# Ideal amount w/o slippage
871-
ideal_amount = subnet_info.alpha_to_tao(amount)
872-
873-
# Total slippage including fees
874-
total_slippage = ideal_amount - received_amount
875-
slippage_pct_float = (
876-
100 * (float(total_slippage.tao) / float(ideal_amount.tao))
877-
if ideal_amount.tao != 0
878-
else 0
879-
)
880-
slippage_pct = f"{slippage_pct_float:.4f} %"
881-
else:
882-
# TODO: Fix this. Slippage is always zero for static networks.
883-
# Root will only have fee-based slippage
884-
slippage_pct_float = (
885-
100 * float(stake_fee.tao) / float(amount.tao) if amount.tao != 0 else 0
886-
)
887-
slippage_pct = f"{slippage_pct_float:.4f} %"
888-
889-
return received_amount, slippage_pct, slippage_pct_float
890-
891-
892834
async def _unstake_selection(
893835
dynamic_info,
894836
identities,
@@ -996,7 +938,7 @@ async def _unstake_selection(
996938

997939
for netuid_, stake_amount in netuid_stakes.items():
998940
symbol = dynamic_info[netuid_].symbol
999-
rate = f"{dynamic_info[netuid_].price.tao:.4f} τ/{symbol}"
941+
rate = f"{dynamic_info[netuid_].price.tao:.6f} τ/{symbol}"
1000942
table.add_row(str(netuid_), symbol, str(stake_amount), rate)
1001943
console.print("\n", table, "\n")
1002944

0 commit comments

Comments
 (0)