Skip to content

Commit 2886372

Browse files
committed
Updates docstrings + logging
1 parent 2ea04fe commit 2886372

File tree

4 files changed

+35
-21
lines changed

4 files changed

+35
-21
lines changed

bittensor/core/extrinsics/move_stake.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ def swap_stake_extrinsic(
224224

225225
logging.info(
226226
f"Swapping stake with safety for hotkey [blue]{hotkey_ss58}[/blue]\n"
227-
f"Amount: [green]{amount}[/green] from netuid [yellow]{origin_netuid}[/yellow] to netuid "
228-
f"[yellow]{destination_netuid}[/yellow]\n"
227+
f"Amount: [green]{amount}[/green] from netuid [green]{origin_netuid}[/green] to netuid "
228+
f"[green]{destination_netuid}[/green]\n"
229229
f"Current price ratio: [green]{swap_rate_ratio:.4f}[/green], "
230-
f"Ratio with tolerance: [yellow]{swap_rate_ratio_with_tolerance:.4f}[/yellow]"
230+
f"Ratio with tolerance: [green]{swap_rate_ratio_with_tolerance:.4f}[/green]"
231231
)
232232
call_params.update(
233233
{
@@ -239,8 +239,8 @@ def swap_stake_extrinsic(
239239
else:
240240
logging.info(
241241
f"Swapping stake for hotkey [blue]{hotkey_ss58}[/blue]\n"
242-
f"Amount: [green]{amount}[/green] from netuid [yellow]{origin_netuid}[/yellow] to netuid "
243-
f"[yellow]{destination_netuid}[/yellow]"
242+
f"Amount: [green]{amount}[/green] from netuid [green]{origin_netuid}[/green] to netuid "
243+
f"[green]{destination_netuid}[/green]"
244244
)
245245
call_function = "swap_stake"
246246

bittensor/core/extrinsics/staking.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ def add_stake_extrinsic(
114114

115115
logging.info(
116116
f":satellite: [magenta]Safe Staking to:[/magenta] "
117-
f"[blue]netuid: [yellow]{netuid}[/yellow], amount: [green]{staking_balance}[/green], "
118-
f"tolerance percentage: [yellow]{rate_threshold*100}%[/yellow], "
119-
f"price limit: [yellow]{rate_with_tolerance}[/yellow], "
117+
f"[blue]netuid: [green]{netuid}[/green], amount: [green]{staking_balance}[/green], "
118+
f"tolerance percentage: [green]{rate_threshold*100}%[/green], "
119+
f"price limit: [green]{rate_with_tolerance}[/green], "
120120
f"original price: [green]{base_rate}[/green], "
121-
f"with partial stake: [yellow]{allow_partial_stake}[/yellow] "
121+
f"with partial stake: [green]{allow_partial_stake}[/green] "
122122
f"on [blue]{subtensor.network}[/blue][/magenta]...[/magenta]"
123123
)
124124

@@ -132,7 +132,7 @@ def add_stake_extrinsic(
132132
else:
133133
logging.info(
134134
f":satellite: [magenta]Staking to:[/magenta] "
135-
f"[blue]netuid: [yellow]{netuid}[/yellow], amount: [green]{staking_balance}[/green] "
135+
f"[blue]netuid: [green]{netuid}[/green], amount: [green]{staking_balance}[/green] "
136136
f"on [blue]{subtensor.network}[/blue][magenta]...[/magenta]"
137137
)
138138
call_function = "add_stake"

bittensor/core/extrinsics/unstaking.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ def unstake_extrinsic(
102102

103103
logging.info(
104104
f":satellite: [magenta]Safe Unstaking from:[/magenta] "
105-
f"netuid: [yellow]{netuid}[/yellow], amount: [green]{unstaking_balance}[/green], "
106-
f"tolerance percentage: [yellow]{rate_threshold*100}%[/yellow], "
107-
f"price limit: [yellow]{rate_with_tolerance}[/yellow], "
105+
f"netuid: [green]{netuid}[/green], amount: [green]{unstaking_balance}[/green], "
106+
f"tolerance percentage: [green]{rate_threshold*100}%[/green], "
107+
f"price limit: [green]{rate_with_tolerance}[/green], "
108108
f"original price: [green]{base_rate}[/green], "
109-
f"with partial unstake: [yellow]{allow_partial_stake}[/yellow] "
109+
f"with partial unstake: [green]{allow_partial_stake}[/green] "
110110
f"on [blue]{subtensor.network}[/blue][magenta]...[/magenta]"
111111
)
112112

@@ -120,7 +120,7 @@ def unstake_extrinsic(
120120
else:
121121
logging.info(
122122
f":satellite: [magenta]Unstaking from:[/magenta] "
123-
f"netuid: [yellow]{netuid}[/yellow], amount: [green]{unstaking_balance}[/green] "
123+
f"netuid: [green]{netuid}[/green], amount: [green]{unstaking_balance}[/green] "
124124
f"on [blue]{subtensor.network}[/blue][magenta]...[/magenta]"
125125
)
126126
call_function = "remove_stake"

bittensor/core/subtensor.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,15 +2145,21 @@ def add_stake(
21452145
amount (Balance): The amount of TAO to stake.
21462146
wait_for_inclusion (bool): Waits for the transaction to be included in a block.
21472147
wait_for_finalization (bool): Waits for the transaction to be finalized on the blockchain.
2148-
safe_staking (bool): If true, the staking process will have safety checks enabled. .
2149-
allow_partial_stake (bool): If true, partial stake will be allowed in-case full stake doesnt fulfill the threshold.
2150-
rate_threshold (float): The threshold in percentage of price which can be allowed to fluctuate. 0.005 = 0.5% by default.
2148+
safe_staking (bool): If true, enables price safety checks to protect against fluctuating prices. The stake
2149+
will only execute if the price change doesn't exceed the rate threshold. Default is False.
2150+
allow_partial_stake (bool): If true and safe_staking is enabled, allows partial staking when
2151+
the full amount would exceed the price threshold. If false, the entire stake fails if it would
2152+
exceed the threshold. Default is False.
2153+
rate_threshold (float): The maximum allowed price change ratio when staking. For example,
2154+
0.005 = 0.5% maximum price increase. Only used when safe_staking is True. Default is 0.005.
21512155
21522156
Returns:
2153-
bool: ``True`` if the staking is successful, False otherwise.
2157+
bool: True if the staking is successful, False otherwise.
21542158
21552159
This function enables neurons to increase their stake in the network, enhancing their influence and potential
21562160
rewards in line with Bittensor's consensus and reward mechanisms.
2161+
When safe_staking is enabled, it provides protection against price fluctuations during the time stake is
2162+
executed and the time it is actually processed by the chain.
21572163
"""
21582164
amount = check_and_convert_to_balance(amount)
21592165
return add_stake_extrinsic(
@@ -2785,7 +2791,7 @@ def swap_stake(
27852791
amount (Union[Balance, float]): The amount to swap.
27862792
wait_for_inclusion (bool): Waits for the transaction to be included in a block.
27872793
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
2794+
safe_staking (bool): If true, enables price safety checks to protect against fluctuating prices. The swap
27892795
will only execute if the price ratio between subnets doesn't exceed the rate threshold.
27902796
Default is False.
27912797
allow_partial_stake (bool): If true and safe_staking is enabled, allows partial stake swaps when
@@ -2923,12 +2929,20 @@ def unstake(
29232929
amount (Balance): The amount of TAO to unstake. If not specified, unstakes all.
29242930
wait_for_inclusion (bool): Waits for the transaction to be included in a block.
29252931
wait_for_finalization (bool): Waits for the transaction to be finalized on the blockchain.
2932+
safe_staking (bool): If true, enables price safety checks to protect against fluctuating prices. The unstake
2933+
will only execute if the price change doesn't exceed the rate threshold. Default is False.
2934+
allow_partial_stake (bool): If true and safe_staking is enabled, allows partial unstaking when
2935+
the full amount would exceed the price threshold. If false, the entire unstake fails if it would
2936+
exceed the threshold. Default is False.
2937+
rate_threshold (float): The maximum allowed price change ratio when unstaking. For example,
2938+
0.005 = 0.5% maximum price decrease. Only used when safe_staking is True. Default is 0.005.
29262939
29272940
Returns:
29282941
bool: ``True`` if the unstaking process is successful, False otherwise.
29292942
29302943
This function supports flexible stake management, allowing neurons to adjust their network participation and
2931-
potential reward accruals.
2944+
potential reward accruals. When safe_staking is enabled, it provides protection against price fluctuations
2945+
during the time unstake is executed and the time it is actually processed by the chain.
29322946
"""
29332947
amount = check_and_convert_to_balance(amount)
29342948
return unstake_extrinsic(

0 commit comments

Comments
 (0)