@@ -2819,6 +2819,9 @@ async def add_stake(
2819
2819
amount : Optional [Balance ] = None ,
2820
2820
wait_for_inclusion : bool = True ,
2821
2821
wait_for_finalization : bool = False ,
2822
+ safe_staking : bool = False ,
2823
+ allow_partial_stake : bool = False ,
2824
+ rate_threshold : float = 0.005 ,
2822
2825
) -> bool :
2823
2826
"""
2824
2827
Adds the specified amount of stake to a neuron identified by the hotkey ``SS58`` address.
@@ -2832,12 +2835,20 @@ async def add_stake(
2832
2835
amount (Balance): The amount of TAO to stake.
2833
2836
wait_for_inclusion (bool): Waits for the transaction to be included in a block.
2834
2837
wait_for_finalization (bool): Waits for the transaction to be finalized on the blockchain.
2838
+ safe_staking (bool): If true, enables price safety checks to protect against fluctuating prices. The stake
2839
+ will only execute if the price change doesn't exceed the rate threshold. Default is False.
2840
+ allow_partial_stake (bool): If true and safe_staking is enabled, allows partial staking when
2841
+ the full amount would exceed the price threshold. If false, the entire stake fails if it would
2842
+ exceed the threshold. Default is False.
2843
+ rate_threshold (float): The maximum allowed price change ratio when staking. For example,
2844
+ 0.005 = 0.5% maximum price increase. Only used when safe_staking is True. Default is 0.005.
2835
2845
2836
2846
Returns:
2837
2847
bool: ``True`` if the staking is successful, False otherwise.
2838
2848
2839
- This function enables neurons to increase their stake in the network, enhancing their influence and potential
2840
- rewards in line with Bittensor's consensus and reward mechanisms.
2849
+ This function enables neurons to increase their stake in the network, enhancing their influence and potential.
2850
+ When safe_staking is enabled, it provides protection against price fluctuations during the time stake is
2851
+ executed and the time it is actually processed by the chain.
2841
2852
"""
2842
2853
amount = check_and_convert_to_balance (amount )
2843
2854
return await add_stake_extrinsic (
@@ -2848,6 +2859,9 @@ async def add_stake(
2848
2859
amount = amount ,
2849
2860
wait_for_inclusion = wait_for_inclusion ,
2850
2861
wait_for_finalization = wait_for_finalization ,
2862
+ safe_staking = safe_staking ,
2863
+ allow_partial_stake = allow_partial_stake ,
2864
+ rate_threshold = rate_threshold ,
2851
2865
)
2852
2866
2853
2867
async def add_stake_multiple (
@@ -3545,6 +3559,9 @@ async def swap_stake(
3545
3559
amount : Balance ,
3546
3560
wait_for_inclusion : bool = True ,
3547
3561
wait_for_finalization : bool = False ,
3562
+ safe_staking : bool = False ,
3563
+ allow_partial_stake : bool = False ,
3564
+ rate_threshold : float = 0.005 ,
3548
3565
) -> bool :
3549
3566
"""
3550
3567
Moves stake between subnets while keeping the same coldkey-hotkey pair ownership.
@@ -3558,9 +3575,25 @@ async def swap_stake(
3558
3575
amount (Union[Balance, float]): The amount to swap.
3559
3576
wait_for_inclusion (bool): Waits for the transaction to be included in a block.
3560
3577
wait_for_finalization (bool): Waits for the transaction to be finalized on the blockchain.
3578
+ safe_staking (bool): If true, enables price safety checks to protect against fluctuating prices. The swap
3579
+ will only execute if the price ratio between subnets doesn't exceed the rate threshold.
3580
+ Default is False.
3581
+ allow_partial_stake (bool): If true and safe_staking is enabled, allows partial stake swaps when
3582
+ the full amount would exceed the price threshold. If false, the entire swap fails if it would
3583
+ exceed the threshold. Default is False.
3584
+ rate_threshold (float): The maximum allowed increase in the price ratio between subnets
3585
+ (origin_price/destination_price). For example, 0.005 = 0.5% maximum increase. Only used
3586
+ when safe_staking is True. Default is 0.005.
3561
3587
3562
3588
Returns:
3563
3589
success (bool): True if the extrinsic was successful.
3590
+
3591
+ The price ratio for swap_stake in safe mode is calculated as: origin_subnet_price / destination_subnet_price
3592
+ When safe_staking is enabled, the swap will only execute if:
3593
+ - With allow_partial_stake=False: The entire swap amount can be executed without the price ratio
3594
+ increasing more than rate_threshold
3595
+ - With allow_partial_stake=True: A partial amount will be swapped up to the point where the
3596
+ price ratio would increase by rate_threshold
3564
3597
"""
3565
3598
amount = check_and_convert_to_balance (amount )
3566
3599
return await swap_stake_extrinsic (
@@ -3572,6 +3605,9 @@ async def swap_stake(
3572
3605
amount = amount ,
3573
3606
wait_for_inclusion = wait_for_inclusion ,
3574
3607
wait_for_finalization = wait_for_finalization ,
3608
+ safe_staking = safe_staking ,
3609
+ allow_partial_stake = allow_partial_stake ,
3610
+ rate_threshold = rate_threshold ,
3575
3611
)
3576
3612
3577
3613
async def transfer_stake (
@@ -3660,6 +3696,9 @@ async def unstake(
3660
3696
amount : Optional [Balance ] = None ,
3661
3697
wait_for_inclusion : bool = True ,
3662
3698
wait_for_finalization : bool = False ,
3699
+ safe_staking : bool = False ,
3700
+ allow_partial_stake : bool = False ,
3701
+ rate_threshold : float = 0.005 ,
3663
3702
) -> bool :
3664
3703
"""
3665
3704
Removes a specified amount of stake from a single hotkey account. This function is critical for adjusting
@@ -3669,10 +3708,17 @@ async def unstake(
3669
3708
wallet (bittensor_wallet.wallet): The wallet associated with the neuron from which the stake is being
3670
3709
removed.
3671
3710
hotkey_ss58 (Optional[str]): The ``SS58`` address of the hotkey account to unstake from.
3672
- netuid (Optional[int]): Subnet unique ID .
3711
+ netuid (Optional[int]): The unique identifier of the subnet .
3673
3712
amount (Balance): The amount of TAO to unstake. If not specified, unstakes all.
3674
3713
wait_for_inclusion (bool): Waits for the transaction to be included in a block.
3675
3714
wait_for_finalization (bool): Waits for the transaction to be finalized on the blockchain.
3715
+ safe_staking (bool): If true, enables price safety checks to protect against fluctuating prices. The unstake
3716
+ will only execute if the price change doesn't exceed the rate threshold. Default is False.
3717
+ allow_partial_stake (bool): If true and safe_staking is enabled, allows partial unstaking when
3718
+ the full amount would exceed the price threshold. If false, the entire unstake fails if it would
3719
+ exceed the threshold. Default is False.
3720
+ rate_threshold (float): The maximum allowed price change ratio when unstaking. For example,
3721
+ 0.005 = 0.5% maximum price decrease. Only used when safe_staking is True. Default is 0.005.
3676
3722
3677
3723
Returns:
3678
3724
bool: ``True`` if the unstaking process is successful, False otherwise.
@@ -3689,6 +3735,9 @@ async def unstake(
3689
3735
amount = amount ,
3690
3736
wait_for_inclusion = wait_for_inclusion ,
3691
3737
wait_for_finalization = wait_for_finalization ,
3738
+ safe_staking = safe_staking ,
3739
+ allow_partial_stake = allow_partial_stake ,
3740
+ rate_threshold = rate_threshold ,
3692
3741
)
3693
3742
3694
3743
async def unstake_multiple (
0 commit comments