@@ -2769,6 +2769,9 @@ def swap_stake(
27692769 amount : Balance ,
27702770 wait_for_inclusion : bool = True ,
27712771 wait_for_finalization : bool = False ,
2772+ safe_staking : bool = False ,
2773+ allow_partial_stake : bool = False ,
2774+ rate_threshold : float = 0.005 ,
27722775 ) -> bool :
27732776 """
27742777 Moves stake between subnets while keeping the same coldkey-hotkey pair ownership.
@@ -2782,9 +2785,26 @@ def swap_stake(
27822785 amount (Union[Balance, float]): The amount to swap.
27832786 wait_for_inclusion (bool): Waits for the transaction to be included in a block.
27842787 wait_for_finalization (bool): Waits for the transaction to be finalized on the blockchain.
2788+ safe_staking (bool): If true, enables price safety checks to protect against price impact. The swap
2789+ will only execute if the price ratio between subnets doesn't exceed the rate threshold.
2790+ Default is False.
2791+ allow_partial_stake (bool): If true and safe_staking is enabled, allows partial stake swaps when
2792+ the full amount would exceed the price threshold. If false, the entire swap fails if it would
2793+ exceed the threshold. Default is False.
2794+ rate_threshold (float): The maximum allowed increase in the price ratio between subnets
2795+ (origin_price/destination_price). For example, 0.005 = 0.5% maximum increase. Only used
2796+ when safe_staking is True. Default is 0.005.
2797+
27852798
27862799 Returns:
27872800 success (bool): True if the extrinsic was successful.
2801+
2802+ The price ratio for swap_stake in safe mode is calculated as: origin_subnet_price / destination_subnet_price
2803+ When safe_staking is enabled, the swap will only execute if:
2804+ - With allow_partial_stake=False: The entire swap amount can be executed without the price ratio
2805+ increasing more than rate_threshold
2806+ - With allow_partial_stake=True: A partial amount will be swapped up to the point where the
2807+ price ratio would increase by rate_threshold
27882808 """
27892809 amount = check_and_convert_to_balance (amount )
27902810 return swap_stake_extrinsic (
@@ -2796,6 +2816,9 @@ def swap_stake(
27962816 amount = amount ,
27972817 wait_for_inclusion = wait_for_inclusion ,
27982818 wait_for_finalization = wait_for_finalization ,
2819+ safe_staking = safe_staking ,
2820+ allow_partial_stake = allow_partial_stake ,
2821+ rate_threshold = rate_threshold ,
27992822 )
28002823
28012824 def transfer (
0 commit comments