@@ -245,12 +245,12 @@ async def stake_extrinsic(
245245 # Get subnet data and stake information for coldkey
246246 chain_head = await subtensor .substrate .get_chain_head ()
247247 _all_subnets , _stake_info , current_wallet_balance = await asyncio .gather (
248- subtensor .all_subnets (),
248+ subtensor .all_subnets (block_hash = chain_head ),
249249 subtensor .get_stake_for_coldkey (
250250 coldkey_ss58 = wallet .coldkeypub .ss58_address ,
251251 block_hash = chain_head ,
252252 ),
253- subtensor .get_balance (wallet .coldkeypub .ss58_address ),
253+ subtensor .get_balance (wallet .coldkeypub .ss58_address , block_hash = chain_head ),
254254 )
255255 all_subnets = {di .netuid : di for di in _all_subnets }
256256
@@ -307,6 +307,7 @@ async def stake_extrinsic(
307307 return False
308308 remaining_wallet_balance -= amount_to_stake
309309
310+ # TODO this should be asyncio gathered before the for loop
310311 stake_fee = await subtensor .get_stake_fee (
311312 origin_hotkey_ss58 = None ,
312313 origin_netuid = None ,
@@ -318,14 +319,20 @@ async def stake_extrinsic(
318319 )
319320
320321 # 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
329336
330337 # Add rows for the table
331338 base_row = [
@@ -336,19 +343,19 @@ async def stake_extrinsic(
336343 + f" { Balance .get_unit (netuid )} /{ Balance .get_unit (0 )} " , # rate
337344 str (received_amount .set_unit (netuid )), # received
338345 str (stake_fee ), # fee
339- str (slippage_pct ), # slippage
346+ # str(slippage_pct), # slippage
340347 ]
341348
342349 # If we are staking safe, add price tolerance
343350 if safe_staking :
344351 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
348355 ) # Rate only for display
349356 rate_with_tolerance = f"{ _rate_with_tolerance :.4f} "
350357 price_with_tolerance = Balance .from_tao (
351- _rate_with_tolerance
358+ price_with_tolerance
352359 ).rao # Actual price to pass to extrinsic
353360 else :
354361 rate_with_tolerance = "1"
@@ -581,9 +588,10 @@ def _define_stake_table(
581588 justify = "center" ,
582589 style = COLOR_PALETTE ["STAKE" ]["STAKE_AMOUNT" ],
583590 )
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+ # )
587595
588596 if safe_staking :
589597 table .add_column (
@@ -628,8 +636,8 @@ def _print_table_and_slippage(table: Table, max_slippage: float, safe_staking: b
628636 - [bold white]Hotkey[/bold white]: The ss58 address of the hotkey you are staking to.
629637 - [bold white]Amount[/bold white]: The TAO you are staking into this subnet onto this hotkey.
630638 - [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)."""
633641
634642 safe_staking_description = """
635643 - [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(
654662 - slippage_str: Formatted slippage percentage string
655663 - slippage_float: Raw slippage percentage value
656664 - rate: Exchange rate string
665+
666+ TODO: Update to v3. This method only works for protocol-liquidity-only
667+ mode (user liquidity disabled)
657668 """
658669 amount_after_fee = amount - stake_fee
659670
@@ -670,6 +681,7 @@ def _calculate_slippage(
670681 slippage_str = f"{ slippage_pct_float :.4f} %"
671682 rate = f"{ (1 / subnet_info .price .tao or 1 ):.4f} "
672683 else :
684+ # TODO: Fix this. Slippage is always zero for static networks.
673685 slippage_pct_float = (
674686 100 * float (stake_fee .tao ) / float (amount .tao ) if amount .tao != 0 else 0
675687 )
0 commit comments