@@ -232,7 +232,7 @@ async def unstake(
232
232
str (netuid ), # Netuid
233
233
staking_address_name , # Hotkey Name
234
234
str (amount_to_unstake_as_balance ), # Amount to Unstake
235
- str ( subnet_info .price .tao )
235
+ f" { subnet_info .price .tao :.6f } "
236
236
+ f"({ Balance .get_unit (0 )} /{ Balance .get_unit (netuid )} )" , # Rate
237
237
str (stake_fee ), # Fee
238
238
str (received_amount ), # Received Amount
@@ -255,7 +255,7 @@ async def unstake(
255
255
base_table_row .extend (
256
256
[
257
257
# 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 )} " ,
259
259
# Partial unstake
260
260
f"[{ 'dark_sea_green3' if allow_partial_stake else 'red' } ]"
261
261
f"{ allow_partial_stake } [/{ 'dark_sea_green3' if allow_partial_stake else 'red' } ]" ,
@@ -446,8 +446,7 @@ async def unstake_all(
446
446
# style=COLOR_PALETTE["STAKE"]["SLIPPAGE_PERCENT"],
447
447
# )
448
448
449
- # Calculate slippage and total received
450
- max_slippage = 0.0
449
+ # Calculate total received
451
450
total_received_value = Balance (0 )
452
451
for stake in stake_info :
453
452
if stake .stake .rao == 0 :
@@ -465,41 +464,33 @@ async def unstake_all(
465
464
destination_coldkey_ss58 = wallet .coldkeypub .ss58_address ,
466
465
amount = stake_amount .rao ,
467
466
)
467
+
468
468
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 ):
473
477
continue
474
478
475
- max_slippage = max (max_slippage , slippage_pct_float )
476
479
total_received_value += received_amount
477
480
478
481
table .add_row (
479
482
str (stake .netuid ),
480
483
hotkey_display ,
481
484
str (stake_amount ),
482
- str ( float (subnet_info .price ))
485
+ f" { float (subnet_info .price ):.6f } "
483
486
+ f"({ Balance .get_unit (0 )} /{ Balance .get_unit (stake .netuid )} )" ,
484
487
str (stake_fee ),
485
- # str(received_amount),
486
- # slippage_pct,
488
+ str (received_amount ),
487
489
)
488
490
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 )
500
491
501
492
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 } "
503
494
)
504
495
505
496
if prompt and not Confirm .ask (
@@ -840,55 +831,6 @@ async def _unstake_all_extrinsic(
840
831
841
832
842
833
# 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
-
892
834
async def _unstake_selection (
893
835
dynamic_info ,
894
836
identities ,
@@ -996,7 +938,7 @@ async def _unstake_selection(
996
938
997
939
for netuid_ , stake_amount in netuid_stakes .items ():
998
940
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 } "
1000
942
table .add_row (str (netuid_ ), symbol , str (stake_amount ), rate )
1001
943
console .print ("\n " , table , "\n " )
1002
944
0 commit comments