@@ -245,12 +245,12 @@ async def stake_extrinsic(
245
245
# Get subnet data and stake information for coldkey
246
246
chain_head = await subtensor .substrate .get_chain_head ()
247
247
_all_subnets , _stake_info , current_wallet_balance = await asyncio .gather (
248
- subtensor .all_subnets (),
248
+ subtensor .all_subnets (block_hash = chain_head ),
249
249
subtensor .get_stake_for_coldkey (
250
250
coldkey_ss58 = wallet .coldkeypub .ss58_address ,
251
251
block_hash = chain_head ,
252
252
),
253
- subtensor .get_balance (wallet .coldkeypub .ss58_address ),
253
+ subtensor .get_balance (wallet .coldkeypub .ss58_address , block_hash = chain_head ),
254
254
)
255
255
all_subnets = {di .netuid : di for di in _all_subnets }
256
256
@@ -307,6 +307,7 @@ async def stake_extrinsic(
307
307
return False
308
308
remaining_wallet_balance -= amount_to_stake
309
309
310
+ # TODO this should be asyncio gathered before the for loop
310
311
stake_fee = await subtensor .get_stake_fee (
311
312
origin_hotkey_ss58 = None ,
312
313
origin_netuid = None ,
@@ -318,14 +319,20 @@ async def stake_extrinsic(
318
319
)
319
320
320
321
# Calculate slippage
321
- try :
322
- received_amount , slippage_pct , slippage_pct_float , rate = (
323
- _calculate_slippage (subnet_info , amount_to_stake , stake_fee )
324
- )
325
- except ValueError :
326
- return False
327
-
328
- max_slippage = max (slippage_pct_float , max_slippage )
322
+ # TODO: Update for V3, slippage calculation is significantly different in v3
323
+ # try:
324
+ # received_amount, slippage_pct, slippage_pct_float, rate = (
325
+ # _calculate_slippage(subnet_info, amount_to_stake, stake_fee)
326
+ # )
327
+ # except ValueError:
328
+ # return False
329
+ #
330
+ # max_slippage = max(slippage_pct_float, max_slippage)
331
+
332
+ # Temporary workaround - calculations without slippage
333
+ current_price_float = float (subnet_info .price .tao )
334
+ rate = 1.0 / current_price_float
335
+ received_amount = rate * amount_to_stake
329
336
330
337
# Add rows for the table
331
338
base_row = [
@@ -336,19 +343,19 @@ async def stake_extrinsic(
336
343
+ f" { Balance .get_unit (netuid )} /{ Balance .get_unit (0 )} " , # rate
337
344
str (received_amount .set_unit (netuid )), # received
338
345
str (stake_fee ), # fee
339
- str (slippage_pct ), # slippage
346
+ # str(slippage_pct), # slippage
340
347
]
341
348
342
349
# If we are staking safe, add price tolerance
343
350
if safe_staking :
344
351
if subnet_info .is_dynamic :
345
- rate = amount_to_stake . rao / received_amount . rao
346
- _rate_with_tolerance = rate * (
347
- 1 + rate_tolerance
352
+ price_with_tolerance = current_price_float * ( 1 + rate_tolerance )
353
+ _rate_with_tolerance = (
354
+ 1.0 / price_with_tolerance
348
355
) # Rate only for display
349
356
rate_with_tolerance = f"{ _rate_with_tolerance :.4f} "
350
357
price_with_tolerance = Balance .from_tao (
351
- _rate_with_tolerance
358
+ price_with_tolerance
352
359
).rao # Actual price to pass to extrinsic
353
360
else :
354
361
rate_with_tolerance = "1"
@@ -581,9 +588,10 @@ def _define_stake_table(
581
588
justify = "center" ,
582
589
style = COLOR_PALETTE ["STAKE" ]["STAKE_AMOUNT" ],
583
590
)
584
- table .add_column (
585
- "Slippage" , justify = "center" , style = COLOR_PALETTE ["STAKE" ]["SLIPPAGE_PERCENT" ]
586
- )
591
+ # TODO: Uncomment when slippage is reimplemented for v3
592
+ # table.add_column(
593
+ # "Slippage", justify="center", style=COLOR_PALETTE["STAKE"]["SLIPPAGE_PERCENT"]
594
+ # )
587
595
588
596
if safe_staking :
589
597
table .add_column (
@@ -628,8 +636,8 @@ def _print_table_and_slippage(table: Table, max_slippage: float, safe_staking: b
628
636
- [bold white]Hotkey[/bold white]: The ss58 address of the hotkey you are staking to.
629
637
- [bold white]Amount[/bold white]: The TAO you are staking into this subnet onto this hotkey.
630
638
- [bold white]Rate[/bold white]: The rate of exchange between your TAO and the subnet's stake.
631
- - [bold white]Received[/bold white]: The amount of stake you will receive on this subnet after slippage.
632
- - [bold white]Slippage[/bold white]: The slippage percentage of the stake operation. (0% if the subnet is not dynamic i.e. root)."""
639
+ - [bold white]Received[/bold white]: The amount of stake you will receive on this subnet after slippage."""
640
+ # - [bold white]Slippage[/bold white]: The slippage percentage of the stake operation. (0% if the subnet is not dynamic i.e. root)."""
633
641
634
642
safe_staking_description = """
635
643
- [bold white]Rate Tolerance[/bold white]: Maximum acceptable alpha rate. If the rate exceeds this tolerance, the transaction will be limited or rejected.
@@ -654,6 +662,9 @@ def _calculate_slippage(
654
662
- slippage_str: Formatted slippage percentage string
655
663
- slippage_float: Raw slippage percentage value
656
664
- rate: Exchange rate string
665
+
666
+ TODO: Update to v3. This method only works for protocol-liquidity-only
667
+ mode (user liquidity disabled)
657
668
"""
658
669
amount_after_fee = amount - stake_fee
659
670
@@ -670,6 +681,7 @@ def _calculate_slippage(
670
681
slippage_str = f"{ slippage_pct_float :.4f} %"
671
682
rate = f"{ (1 / subnet_info .price .tao or 1 ):.4f} "
672
683
else :
684
+ # TODO: Fix this. Slippage is always zero for static networks.
673
685
slippage_pct_float = (
674
686
100 * float (stake_fee .tao ) / float (amount .tao ) if amount .tao != 0 else 0
675
687
)
0 commit comments