@@ -2810,6 +2810,9 @@ async def add_stake(
2810
2810
amount : Optional [Balance ] = None ,
2811
2811
wait_for_inclusion : bool = True ,
2812
2812
wait_for_finalization : bool = False ,
2813
+ safe_staking : bool = False ,
2814
+ allow_partial_stake : bool = False ,
2815
+ rate_threshold : float = 0.005 ,
2813
2816
) -> bool :
2814
2817
"""
2815
2818
Adds the specified amount of stake to a neuron identified by the hotkey ``SS58`` address.
@@ -2823,12 +2826,20 @@ async def add_stake(
2823
2826
amount (Balance): The amount of TAO to stake.
2824
2827
wait_for_inclusion (bool): Waits for the transaction to be included in a block.
2825
2828
wait_for_finalization (bool): Waits for the transaction to be finalized on the blockchain.
2829
+ safe_staking (bool): If true, enables price safety checks to protect against fluctuating prices. The stake
2830
+ will only execute if the price change doesn't exceed the rate threshold. Default is False.
2831
+ allow_partial_stake (bool): If true and safe_staking is enabled, allows partial staking when
2832
+ the full amount would exceed the price threshold. If false, the entire stake fails if it would
2833
+ exceed the threshold. Default is False.
2834
+ rate_threshold (float): The maximum allowed price change ratio when staking. For example,
2835
+ 0.005 = 0.5% maximum price increase. Only used when safe_staking is True. Default is 0.005.
2826
2836
2827
2837
Returns:
2828
2838
bool: ``True`` if the staking is successful, False otherwise.
2829
2839
2830
- This function enables neurons to increase their stake in the network, enhancing their influence and potential
2831
- rewards in line with Bittensor's consensus and reward mechanisms.
2840
+ This function enables neurons to increase their stake in the network, enhancing their influence and potential.
2841
+ When safe_staking is enabled, it provides protection against price fluctuations during the time stake is
2842
+ executed and the time it is actually processed by the chain.
2832
2843
"""
2833
2844
amount = check_and_convert_to_balance (amount )
2834
2845
return await add_stake_extrinsic (
@@ -2839,6 +2850,9 @@ async def add_stake(
2839
2850
amount = amount ,
2840
2851
wait_for_inclusion = wait_for_inclusion ,
2841
2852
wait_for_finalization = wait_for_finalization ,
2853
+ safe_staking = safe_staking ,
2854
+ allow_partial_stake = allow_partial_stake ,
2855
+ rate_threshold = rate_threshold ,
2842
2856
)
2843
2857
2844
2858
async def add_stake_multiple (
@@ -3439,6 +3453,9 @@ async def swap_stake(
3439
3453
amount : Balance ,
3440
3454
wait_for_inclusion : bool = True ,
3441
3455
wait_for_finalization : bool = False ,
3456
+ safe_staking : bool = False ,
3457
+ allow_partial_stake : bool = False ,
3458
+ rate_threshold : float = 0.005 ,
3442
3459
) -> bool :
3443
3460
"""
3444
3461
Moves stake between subnets while keeping the same coldkey-hotkey pair ownership.
@@ -3452,9 +3469,25 @@ async def swap_stake(
3452
3469
amount (Union[Balance, float]): The amount to swap.
3453
3470
wait_for_inclusion (bool): Waits for the transaction to be included in a block.
3454
3471
wait_for_finalization (bool): Waits for the transaction to be finalized on the blockchain.
3472
+ safe_staking (bool): If true, enables price safety checks to protect against fluctuating prices. The swap
3473
+ will only execute if the price ratio between subnets doesn't exceed the rate threshold.
3474
+ Default is False.
3475
+ allow_partial_stake (bool): If true and safe_staking is enabled, allows partial stake swaps when
3476
+ the full amount would exceed the price threshold. If false, the entire swap fails if it would
3477
+ exceed the threshold. Default is False.
3478
+ rate_threshold (float): The maximum allowed increase in the price ratio between subnets
3479
+ (origin_price/destination_price). For example, 0.005 = 0.5% maximum increase. Only used
3480
+ when safe_staking is True. Default is 0.005.
3455
3481
3456
3482
Returns:
3457
3483
success (bool): True if the extrinsic was successful.
3484
+
3485
+ The price ratio for swap_stake in safe mode is calculated as: origin_subnet_price / destination_subnet_price
3486
+ When safe_staking is enabled, the swap will only execute if:
3487
+ - With allow_partial_stake=False: The entire swap amount can be executed without the price ratio
3488
+ increasing more than rate_threshold
3489
+ - With allow_partial_stake=True: A partial amount will be swapped up to the point where the
3490
+ price ratio would increase by rate_threshold
3458
3491
"""
3459
3492
amount = check_and_convert_to_balance (amount )
3460
3493
return await swap_stake_extrinsic (
@@ -3466,6 +3499,9 @@ async def swap_stake(
3466
3499
amount = amount ,
3467
3500
wait_for_inclusion = wait_for_inclusion ,
3468
3501
wait_for_finalization = wait_for_finalization ,
3502
+ safe_staking = safe_staking ,
3503
+ allow_partial_stake = allow_partial_stake ,
3504
+ rate_threshold = rate_threshold ,
3469
3505
)
3470
3506
3471
3507
async def transfer_stake (
@@ -3554,6 +3590,9 @@ async def unstake(
3554
3590
amount : Optional [Balance ] = None ,
3555
3591
wait_for_inclusion : bool = True ,
3556
3592
wait_for_finalization : bool = False ,
3593
+ safe_staking : bool = False ,
3594
+ allow_partial_stake : bool = False ,
3595
+ rate_threshold : float = 0.005 ,
3557
3596
) -> bool :
3558
3597
"""
3559
3598
Removes a specified amount of stake from a single hotkey account. This function is critical for adjusting
@@ -3563,10 +3602,17 @@ async def unstake(
3563
3602
wallet (bittensor_wallet.wallet): The wallet associated with the neuron from which the stake is being
3564
3603
removed.
3565
3604
hotkey_ss58 (Optional[str]): The ``SS58`` address of the hotkey account to unstake from.
3566
- netuid (Optional[int]): Subnet unique ID .
3605
+ netuid (Optional[int]): The unique identifier of the subnet .
3567
3606
amount (Balance): The amount of TAO to unstake. If not specified, unstakes all.
3568
3607
wait_for_inclusion (bool): Waits for the transaction to be included in a block.
3569
3608
wait_for_finalization (bool): Waits for the transaction to be finalized on the blockchain.
3609
+ safe_staking (bool): If true, enables price safety checks to protect against fluctuating prices. The unstake
3610
+ will only execute if the price change doesn't exceed the rate threshold. Default is False.
3611
+ allow_partial_stake (bool): If true and safe_staking is enabled, allows partial unstaking when
3612
+ the full amount would exceed the price threshold. If false, the entire unstake fails if it would
3613
+ exceed the threshold. Default is False.
3614
+ rate_threshold (float): The maximum allowed price change ratio when unstaking. For example,
3615
+ 0.005 = 0.5% maximum price decrease. Only used when safe_staking is True. Default is 0.005.
3570
3616
3571
3617
Returns:
3572
3618
bool: ``True`` if the unstaking process is successful, False otherwise.
@@ -3583,6 +3629,9 @@ async def unstake(
3583
3629
amount = amount ,
3584
3630
wait_for_inclusion = wait_for_inclusion ,
3585
3631
wait_for_finalization = wait_for_finalization ,
3632
+ safe_staking = safe_staking ,
3633
+ allow_partial_stake = allow_partial_stake ,
3634
+ rate_threshold = rate_threshold ,
3586
3635
)
3587
3636
3588
3637
async def unstake_multiple (
0 commit comments