Skip to content

Commit 33a32e7

Browse files
author
Roman
committed
update calls in subtensors
1 parent 688e2d7 commit 33a32e7

File tree

2 files changed

+65
-50
lines changed

2 files changed

+65
-50
lines changed

bittensor/core/async_subtensor.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3380,27 +3380,27 @@ async def add_stake(
33803380
period: Optional[int] = None,
33813381
) -> bool:
33823382
"""
3383-
Adds the specified amount of stake to a neuron identified by the hotkey ``SS58`` address.
3384-
Staking is a fundamental process in the Bittensor network that enables neurons to participate actively and earn
3385-
incentives.
3383+
Adds a stake from the specified wallet to the neuron identified by the SS58 address of its hotkey in specified subnet.
3384+
Staking is a fundamental process in the Bittensor network that enables neurons to participate actively and earn incentives.
33863385
33873386
Args:
3388-
wallet (bittensor_wallet.Wallet): The wallet to be used for staking.
3389-
hotkey_ss58 (Optional[str]): The ``SS58`` address of the hotkey associated with the neuron.
3390-
netuid: subnet UID
3391-
amount (Balance): The amount of TAO to stake.
3392-
wait_for_inclusion (bool): Waits for the transaction to be included in a block.
3393-
wait_for_finalization (bool): Waits for the transaction to be finalized on the blockchain.
3394-
safe_staking (bool): If true, enables price safety checks to protect against fluctuating prices. The stake
3395-
will only execute if the price change doesn't exceed the rate tolerance. Default is False.
3396-
allow_partial_stake (bool): If true and safe_staking is enabled, allows partial staking when
3397-
the full amount would exceed the price threshold. If false, the entire stake fails if it would
3398-
exceed the threshold. Default is False.
3399-
rate_tolerance (float): The maximum allowed price change ratio when staking. For example,
3400-
0.005 = 0.5% maximum price increase. Only used when safe_staking is True. Default is 0.005.
3401-
period (Optional[int]): The number of blocks during which the transaction will remain valid after it's
3402-
submitted. If the transaction is not included in a block within that number of blocks, it will expire
3403-
and be rejected. You can think of it as an expiration date for the transaction.
3387+
wallet: The wallet to be used for staking.
3388+
hotkey_ss58: The SS58 address of the hotkey associated with the neuron to which you intend to delegate your
3389+
stake. If not specified, the wallet's hotkey will be used. Defaults to ``None``.
3390+
netuid: The unique identifier of the subnet to which the neuron belongs.
3391+
amount: The amount of TAO to stake.
3392+
wait_for_inclusion: Waits for the transaction to be included in a block. Defaults to ``True``.
3393+
wait_for_finalization: Waits for the transaction to be finalized on the blockchain. Defaults to ``False``.
3394+
safe_staking: If true, enables price safety checks to protect against fluctuating prices. The stake will
3395+
only execute if the price change doesn't exceed the rate tolerance. Default is ``False``.
3396+
allow_partial_stake: If true and safe_staking is enabled, allows partial staking when the full amount would
3397+
exceed the price tolerance. If false, the entire stake fails if it would exceed the tolerance.
3398+
Default is ``False``.
3399+
rate_tolerance: The maximum allowed price change ratio when staking. For example,
3400+
0.005 = 0.5% maximum price increase. Only used when safe_staking is True. Default is ``0.005``.
3401+
period: The number of blocks during which the transaction will remain valid after it's submitted. If the
3402+
transaction is not included in a block within that number of blocks, it will expire and be rejected. You
3403+
can think of it as an expiration date for the transaction. Defaults to ``None``.
34043404
34053405
Returns:
34063406
bool: ``True`` if the staking is successful, False otherwise.
@@ -4428,6 +4428,7 @@ async def unstake(
44284428
allow_partial_stake: bool = False,
44294429
rate_tolerance: float = 0.005,
44304430
period: Optional[int] = None,
4431+
unstake_all: bool = False,
44314432
) -> bool:
44324433
"""
44334434
Removes a specified amount of stake from a single hotkey account. This function is critical for adjusting
@@ -4451,6 +4452,7 @@ async def unstake(
44514452
period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If
44524453
the transaction is not included in a block within that number of blocks, it will expire and be rejected.
44534454
You can think of it as an expiration date for the transaction.
4455+
unstake_all: If true, unstakes all tokens. Default is ``False``.
44544456
44554457
Returns:
44564458
bool: ``True`` if the unstaking process is successful, False otherwise.
@@ -4471,6 +4473,7 @@ async def unstake(
44714473
allow_partial_stake=allow_partial_stake,
44724474
rate_tolerance=rate_tolerance,
44734475
period=period,
4476+
unstake_all=unstake_all,
44744477
)
44754478

44764479
async def unstake_multiple(
@@ -4482,6 +4485,7 @@ async def unstake_multiple(
44824485
wait_for_inclusion: bool = True,
44834486
wait_for_finalization: bool = False,
44844487
period: Optional[int] = None,
4488+
unstake_all: bool = False,
44854489
) -> bool:
44864490
"""
44874491
Performs batch unstaking from multiple hotkey accounts, allowing a neuron to reduce its staked amounts
@@ -4499,6 +4503,7 @@ async def unstake_multiple(
44994503
period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If
45004504
the transaction is not included in a block within that number of blocks, it will expire and be rejected.
45014505
You can think of it as an expiration date for the transaction.
4506+
unstake_all: If true, unstakes all tokens. Default is ``False``.
45024507
45034508
Returns:
45044509
bool: ``True`` if the batch unstaking is successful, False otherwise.
@@ -4515,6 +4520,7 @@ async def unstake_multiple(
45154520
wait_for_inclusion=wait_for_inclusion,
45164521
wait_for_finalization=wait_for_finalization,
45174522
period=period,
4523+
unstake_all=unstake_all,
45184524
)
45194525

45204526

bittensor/core/subtensor.py

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -610,14 +610,14 @@ def get_all_subnets_info(self, block: Optional[int] = None) -> list["SubnetInfo"
610610

611611
def get_balance(self, address: str, block: Optional[int] = None) -> Balance:
612612
"""
613-
Retrieves the balance for given coldkey.
613+
Retrieves the balance for given coldkey. Always in TAO.
614614
615615
Arguments:
616-
address (str): coldkey address.
616+
address: coldkey address.
617617
block (Optional[int]): The blockchain block number for the query.
618618
619619
Returns:
620-
Balance object.
620+
Balance object in TAO.
621621
"""
622622
balance = self.substrate.query(
623623
module="System",
@@ -1122,15 +1122,15 @@ def get_delegates(self, block: Optional[int] = None) -> list["DelegateInfo"]:
11221122

11231123
def get_existential_deposit(self, block: Optional[int] = None) -> Optional[Balance]:
11241124
"""
1125-
Retrieves the existential deposit amount for the Bittensor blockchain.
1125+
Retrieves the existential deposit amount for the Bittensor blockchain. Always in TAO.
11261126
The existential deposit is the minimum amount of TAO required for an account to exist on the blockchain.
11271127
Accounts with balances below this threshold can be reaped to conserve network resources.
11281128
11291129
Arguments:
11301130
block (Optional[int]): The blockchain block number for the query.
11311131
11321132
Returns:
1133-
The existential deposit amount.
1133+
The existential deposit amount. Always in TAO.
11341134
11351135
The existential deposit is a fundamental economic parameter in the Bittensor network, ensuring efficient use of
11361136
storage and preventing the proliferation of dust accounts.
@@ -1424,16 +1424,19 @@ def get_stake(
14241424
block: Optional[int] = None,
14251425
) -> Balance:
14261426
"""
1427-
Returns the stake under a coldkey - hotkey pairing.
1427+
Returns the amount of Alpha staked by a specific coldkey to a specific hotkey within a given subnet.
1428+
This function retrieves the delegated stake balance, referred to as the 'Alpha' value.
14281429
14291430
Args:
1430-
hotkey_ss58 (str): The SS58 address of the hotkey.
1431-
coldkey_ss58 (str): The SS58 address of the coldkey.
1432-
netuid (int): The subnet ID
1433-
block (Optional[int]): The block number at which to query the stake information.
1431+
coldkey_ss58: The SS58 address of the coldkey that delegated the stake. This address owns the stake.
1432+
hotkey_ss58: The ss58 address of the hotkey which the stake is on.
1433+
netuid: The unique identifier of the subnet to query.
1434+
block: The specific block number at which to retrieve the stake information. If None, the current stake at
1435+
the latest block is returned. Defaults to ``None``.
14341436
14351437
Returns:
1436-
Balance: The stake under the coldkey - hotkey pairing.
1438+
An object representing the amount of Alpha (TAO ONLY if the subnet's netuid is 0) currently staked from the
1439+
specified coldkey to the specified hotkey within the given subnet.
14371440
"""
14381441
alpha_shares_query = self.query_module(
14391442
module="SubtensorModule",
@@ -2632,27 +2635,27 @@ def add_stake(
26322635
period: Optional[int] = None,
26332636
) -> bool:
26342637
"""
2635-
Adds the specified amount of stake to a neuron identified by the hotkey ``SS58`` address.
2636-
Staking is a fundamental process in the Bittensor network that enables neurons to participate actively and earn
2637-
incentives.
2638+
Adds a stake from the specified wallet to the neuron identified by the SS58 address of its hotkey in specified subnet.
2639+
Staking is a fundamental process in the Bittensor network that enables neurons to participate actively and earn incentives.
26382640
26392641
Args:
2640-
wallet (bittensor_wallet.Wallet): The wallet to be used for staking.
2641-
hotkey_ss58 (Optional[str]): The ``SS58`` address of the hotkey associated with the neuron.
2642-
netuid (Optional[int]): The unique identifier of the subnet to which the neuron belongs.
2643-
amount (Balance): The amount of TAO to stake.
2644-
wait_for_inclusion (bool): Waits for the transaction to be included in a block.
2645-
wait_for_finalization (bool): Waits for the transaction to be finalized on the blockchain.
2646-
safe_staking (bool): If true, enables price safety checks to protect against fluctuating prices. The stake
2647-
will only execute if the price change doesn't exceed the rate tolerance. Default is False.
2648-
allow_partial_stake (bool): If true and safe_staking is enabled, allows partial staking when
2649-
the full amount would exceed the price tolerance. If false, the entire stake fails if it would
2650-
exceed the tolerance. Default is False.
2651-
rate_tolerance (float): The maximum allowed price change ratio when staking. For example,
2652-
0.005 = 0.5% maximum price increase. Only used when safe_staking is True. Default is 0.005.
2653-
period (Optional[int]): The number of blocks during which the transaction will remain valid after it's
2654-
submitted. If the transaction is not included in a block within that number of blocks, it will expire
2655-
and be rejected. You can think of it as an expiration date for the transaction.
2642+
wallet: The wallet to be used for staking.
2643+
hotkey_ss58: The SS58 address of the hotkey associated with the neuron to which you intend to delegate your
2644+
stake. If not specified, the wallet's hotkey will be used. Defaults to ``None``.
2645+
netuid: The unique identifier of the subnet to which the neuron belongs.
2646+
amount: The amount of TAO to stake.
2647+
wait_for_inclusion: Waits for the transaction to be included in a block. Defaults to ``True``.
2648+
wait_for_finalization: Waits for the transaction to be finalized on the blockchain. Defaults to ``False``.
2649+
safe_staking: If true, enables price safety checks to protect against fluctuating prices. The stake will
2650+
only execute if the price change doesn't exceed the rate tolerance. Default is ``False``.
2651+
allow_partial_stake: If true and safe_staking is enabled, allows partial staking when the full amount would
2652+
exceed the price tolerance. If false, the entire stake fails if it would exceed the tolerance.
2653+
Default is ``False``.
2654+
rate_tolerance: The maximum allowed price change ratio when staking. For example,
2655+
0.005 = 0.5% maximum price increase. Only used when safe_staking is True. Default is ``0.005``.
2656+
period: The number of blocks during which the transaction will remain valid after it's submitted. If the
2657+
transaction is not included in a block within that number of blocks, it will expire and be rejected. You
2658+
can think of it as an expiration date for the transaction. Defaults to ``None``.
26562659
26572660
Returns:
26582661
bool: True if the staking is successful, False otherwise.
@@ -3668,6 +3671,7 @@ def unstake(
36683671
allow_partial_stake: bool = False,
36693672
rate_tolerance: float = 0.005,
36703673
period: Optional[int] = None,
3674+
unstake_all: bool = False,
36713675
) -> bool:
36723676
"""
36733677
Removes a specified amount of stake from a single hotkey account. This function is critical for adjusting
@@ -3678,7 +3682,7 @@ def unstake(
36783682
removed.
36793683
hotkey_ss58 (Optional[str]): The ``SS58`` address of the hotkey account to unstake from.
36803684
netuid (Optional[int]): The unique identifier of the subnet.
3681-
amount (Balance): The amount of alpha to unstake. If not specified, unstakes all.
3685+
amount (Balance): The amount of alpha to unstake. If not specified, unstakes all. Alpha amount.
36823686
wait_for_inclusion (bool): Waits for the transaction to be included in a block.
36833687
wait_for_finalization (bool): Waits for the transaction to be finalized on the blockchain.
36843688
safe_staking (bool): If true, enables price safety checks to protect against fluctuating prices. The unstake
@@ -3691,6 +3695,7 @@ def unstake(
36913695
period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If
36923696
the transaction is not included in a block within that number of blocks, it will expire and be rejected.
36933697
You can think of it as an expiration date for the transaction.
3698+
unstake_all: If true, unstakes all tokens. Default is ``False``.
36943699
36953700
Returns:
36963701
bool: ``True`` if the unstaking process is successful, False otherwise.
@@ -3712,6 +3717,7 @@ def unstake(
37123717
allow_partial_stake=allow_partial_stake,
37133718
rate_tolerance=rate_tolerance,
37143719
period=period,
3720+
unstake_all=unstake_all,
37153721
)
37163722

37173723
def unstake_multiple(
@@ -3723,6 +3729,7 @@ def unstake_multiple(
37233729
wait_for_inclusion: bool = True,
37243730
wait_for_finalization: bool = False,
37253731
period: Optional[int] = None,
3732+
unstake_all: bool = False,
37263733
) -> bool:
37273734
"""
37283735
Performs batch unstaking from multiple hotkey accounts, allowing a neuron to reduce its staked amounts
@@ -3740,6 +3747,7 @@ def unstake_multiple(
37403747
period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If
37413748
the transaction is not included in a block within that number of blocks, it will expire and be rejected.
37423749
You can think of it as an expiration date for the transaction.
3750+
unstake_all: If true, unstakes all tokens. Default is ``False``.
37433751
37443752
Returns:
37453753
bool: ``True`` if the batch unstaking is successful, False otherwise.
@@ -3756,4 +3764,5 @@ def unstake_multiple(
37563764
wait_for_inclusion=wait_for_inclusion,
37573765
wait_for_finalization=wait_for_finalization,
37583766
period=period,
3767+
unstake_all=unstake_all,
37593768
)

0 commit comments

Comments
 (0)