@@ -2769,6 +2769,9 @@ def swap_stake(
2769
2769
amount : Balance ,
2770
2770
wait_for_inclusion : bool = True ,
2771
2771
wait_for_finalization : bool = False ,
2772
+ safe_staking : bool = False ,
2773
+ allow_partial_stake : bool = False ,
2774
+ rate_threshold : float = 0.005 ,
2772
2775
) -> bool :
2773
2776
"""
2774
2777
Moves stake between subnets while keeping the same coldkey-hotkey pair ownership.
@@ -2782,9 +2785,26 @@ def swap_stake(
2782
2785
amount (Union[Balance, float]): The amount to swap.
2783
2786
wait_for_inclusion (bool): Waits for the transaction to be included in a block.
2784
2787
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
+
2785
2798
2786
2799
Returns:
2787
2800
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
2788
2808
"""
2789
2809
amount = check_and_convert_to_balance (amount )
2790
2810
return swap_stake_extrinsic (
@@ -2796,6 +2816,9 @@ def swap_stake(
2796
2816
amount = amount ,
2797
2817
wait_for_inclusion = wait_for_inclusion ,
2798
2818
wait_for_finalization = wait_for_finalization ,
2819
+ safe_staking = safe_staking ,
2820
+ allow_partial_stake = allow_partial_stake ,
2821
+ rate_threshold = rate_threshold ,
2799
2822
)
2800
2823
2801
2824
def transfer (
0 commit comments