Skip to content

Commit 9649cc5

Browse files
author
Roman
committed
improve add_stake_extrinsic (avoid Balance warnings)
1 parent 4112a85 commit 9649cc5

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

bittensor/core/extrinsics/asyncex/staking.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,27 @@ async def add_stake_extrinsic(
2828
period: Optional[int] = None,
2929
) -> bool:
3030
"""
31-
Adds the specified amount of stake to passed hotkey `uid`.
31+
Adds a stake from the specified wallet to the neuron identified by the SS58 address of its hotkey in specified subnet.
32+
Staking is a fundamental process in the Bittensor network that enables neurons to participate actively and earn incentives.
3233
3334
Arguments:
34-
subtensor: the initialized SubtensorInterface object to use
35+
subtensor: Subtensor instance with the connection to the chain.
3536
wallet: Bittensor wallet object.
3637
old_balance: the balance prior to the staking
37-
hotkey_ss58: The `ss58` address of the hotkey account to stake to defaults to the wallet's hotkey.
38-
netuid: The netuid of the stake to be added
39-
amount: Amount to stake as Bittensor balance, `None` if staking all.
38+
hotkey_ss58: The `ss58` address of the hotkey account to stake to default to the wallet's hotkey. If not
39+
specified, the wallet's hotkey will be used. Defaults to ``None``.
40+
netuid: The unique identifier of the subnet to which the neuron belongs.
41+
amount: Amount to stake as Bittensor balance in TAO always, `None` if staking all. Defaults is ``None``.
4042
wait_for_inclusion: If set, waits for the extrinsic to enter a block before returning `True`, or returns
41-
`False` if the extrinsic fails to enter the block within the timeout.
43+
`False` if the extrinsic fails to enter the block within the timeout. Defaults to ``True``.
4244
wait_for_finalization: If set, waits for the extrinsic to be finalized on the chain before returning `True`,
43-
or returns `False` if the extrinsic fails to be finalized within the timeout.
44-
safe_staking: If set, uses safe staking logic
45-
allow_partial_stake: If set, allows partial stake
46-
rate_tolerance: The rate tolerance for safe staking
45+
or returns `False` if the extrinsic fails to be finalized within the timeout. Defaults to ``False``.
46+
safe_staking: If True, enables price safety checks. Default is ``False``.
47+
allow_partial_stake: If True, allows partial unstaking if price tolerance exceeded. Default is ``False``.
48+
rate_tolerance: Maximum allowed price increase percentage (0.005 = 0.5%). Default is ``0.005``.
4749
period: The number of blocks during which the transaction will remain valid after it's submitted. If
4850
the transaction is not included in a block within that number of blocks, it will expire and be rejected.
49-
You can think of it as an expiration date for the transaction.
51+
You can think of it as an expiration date for the transaction. Defaults to ``None``.
5052
5153
Returns:
5254
success: Flag is `True` if extrinsic was finalized or included in the block. If we did not wait for
@@ -93,7 +95,6 @@ async def add_stake_extrinsic(
9395
)
9496
else:
9597
staking_balance = amount
96-
staking_balance.set_unit(netuid)
9798

9899
# Leave existential balance to keep key alive.
99100
if staking_balance > old_balance - existential_deposit:

bittensor/core/extrinsics/staking.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,26 @@ def add_stake_extrinsic(
2626
period: Optional[int] = None,
2727
) -> bool:
2828
"""
29-
Adds the specified amount of stake to passed hotkey `uid`.
29+
Adds a stake from the specified wallet to the neuron identified by the SS58 address of its hotkey in specified subnet.
30+
Staking is a fundamental process in the Bittensor network that enables neurons to participate actively and earn incentives.
3031
3132
Arguments:
32-
subtensor: the Subtensor object to use
33+
subtensor: Subtensor instance with the connection to the chain.
3334
wallet: Bittensor wallet object.
34-
hotkey_ss58: The `ss58` address of the hotkey account to stake to default to the wallet's hotkey.
35-
netuid (Optional[int]): Subnet unique ID.
36-
amount: Amount to stake as Bittensor balance, `None` if staking all.
35+
hotkey_ss58: The `ss58` address of the hotkey account to stake to default to the wallet's hotkey. If not
36+
specified, the wallet's hotkey will be used. Defaults to ``None``.
37+
netuid: The unique identifier of the subnet to which the neuron belongs.
38+
amount: Amount to stake as Bittensor balance in TAO always, `None` if staking all. Defaults is ``None``.
3739
wait_for_inclusion: If set, waits for the extrinsic to enter a block before returning `True`, or returns
38-
`False` if the extrinsic fails to enter the block within the timeout.
40+
`False` if the extrinsic fails to enter the block within the timeout. Defaults to ``True``.
3941
wait_for_finalization: If set, waits for the extrinsic to be finalized on the chain before returning `True`,
40-
or returns `False` if the extrinsic fails to be finalized within the timeout.
41-
safe_staking (bool): If true, enables price safety checks
42-
allow_partial_stake (bool): If true, allows partial unstaking if price tolerance exceeded
43-
rate_tolerance (float): Maximum allowed price increase percentage (0.005 = 0.5%)
42+
or returns `False` if the extrinsic fails to be finalized within the timeout. Defaults to ``False``.
43+
safe_staking: If True, enables price safety checks. Default is ``False``.
44+
allow_partial_stake: If True, allows partial unstaking if price tolerance exceeded. Default is ``False``.
45+
rate_tolerance: Maximum allowed price increase percentage (0.005 = 0.5%). Default is ``0.005``.
4446
period: The number of blocks during which the transaction will remain valid after it's submitted. If
4547
the transaction is not included in a block within that number of blocks, it will expire and be rejected.
46-
You can think of it as an expiration date for the transaction.
48+
You can think of it as an expiration date for the transaction. Defaults to ``None``.
4749
4850
Returns:
4951
success: Flag is `True` if extrinsic was finalized or included in the block. If we did not wait for
@@ -87,14 +89,11 @@ def add_stake_extrinsic(
8789
)
8890
else:
8991
staking_balance = amount
90-
staking_balance.set_unit(netuid)
9192

9293
# Leave existential balance to keep key alive.
9394
if staking_balance > old_balance - existential_deposit:
9495
# If we are staking all, we need to leave at least the existential deposit.
9596
staking_balance = old_balance - existential_deposit
96-
else:
97-
staking_balance = staking_balance
9897

9998
# Check enough to stake.
10099
if staking_balance > old_balance:
@@ -200,7 +199,7 @@ def add_stake_extrinsic(
200199

201200
except SubstrateRequestException as error:
202201
logging.error(
203-
f":cross_mark: [red]Add Stake Error: {format_error_message((error))}[/red]"
202+
f":cross_mark: [red]Add Stake Error: {format_error_message(error)}[/red]"
204203
)
205204
return False
206205

0 commit comments

Comments
 (0)