|
73 | 73 | from bittensor.core.extrinsics.asyncex.staking import ( |
74 | 74 | add_stake_extrinsic, |
75 | 75 | add_stake_multiple_extrinsic, |
| 76 | + set_auto_stake_extrinsic, |
76 | 77 | ) |
77 | 78 | from bittensor.core.extrinsics.asyncex.start_call import start_call_extrinsic |
78 | 79 | from bittensor.core.extrinsics.asyncex.mechanism import ( |
@@ -1201,6 +1202,42 @@ async def get_all_subnets_info( |
1201 | 1202 |
|
1202 | 1203 | return SubnetInfo.list_from_dicts(result) |
1203 | 1204 |
|
| 1205 | + async def get_auto_stakes( |
| 1206 | + self, |
| 1207 | + coldkey_ss58: str, |
| 1208 | + block: Optional[int] = None, |
| 1209 | + block_hash: Optional[str] = None, |
| 1210 | + reuse_block: bool = False, |
| 1211 | + ) -> dict[int, str]: |
| 1212 | + """Fetches auto stake destinations for a given wallet across all subnets. |
| 1213 | +
|
| 1214 | + Parameters: |
| 1215 | + coldkey_ss58: Coldkey ss58 address. |
| 1216 | + block: The block number for the query. |
| 1217 | + block_hash: The block hash for the query. |
| 1218 | + reuse_block: Whether to reuse the last-used block hash. |
| 1219 | +
|
| 1220 | + Returns: |
| 1221 | + dict[int, str]: |
| 1222 | + - netuid: The unique identifier of the subnet. |
| 1223 | + - hotkey: The hotkey of the wallet. |
| 1224 | + """ |
| 1225 | + block_hash = await self.determine_block_hash(block, block_hash, reuse_block) |
| 1226 | + query = await self.substrate.query_map( |
| 1227 | + module="SubtensorModule", |
| 1228 | + storage_function="AutoStakeDestination", |
| 1229 | + params=[coldkey_ss58], |
| 1230 | + block_hash=block_hash, |
| 1231 | + ) |
| 1232 | + |
| 1233 | + pairs = {} |
| 1234 | + async for netuid, destination in query: |
| 1235 | + hotkey_ss58 = decode_account_id(destination.value[0]) |
| 1236 | + if hotkey_ss58: |
| 1237 | + pairs[int(netuid)] = hotkey_ss58 |
| 1238 | + |
| 1239 | + return pairs |
| 1240 | + |
1204 | 1241 | async def get_balance( |
1205 | 1242 | self, |
1206 | 1243 | address: str, |
@@ -5170,6 +5207,46 @@ async def root_set_weights( |
5170 | 5207 | period=period, |
5171 | 5208 | ) |
5172 | 5209 |
|
| 5210 | + async def set_auto_stake( |
| 5211 | + self, |
| 5212 | + wallet: "Wallet", |
| 5213 | + netuid: int, |
| 5214 | + hotkey_ss58: str, |
| 5215 | + period: Optional[int] = None, |
| 5216 | + raise_error: bool = False, |
| 5217 | + wait_for_inclusion: bool = True, |
| 5218 | + wait_for_finalization: bool = True, |
| 5219 | + ) -> tuple[bool, str]: |
| 5220 | + """Sets the coldkey to automatically stake to the hotkey within specific subnet mechanism. |
| 5221 | +
|
| 5222 | + Parameters: |
| 5223 | + wallet: Bittensor Wallet instance. |
| 5224 | + netuid: The subnet unique identifier. |
| 5225 | + hotkey_ss58: The SS58 address of the validator's hotkey to which the miner automatically stakes all rewards |
| 5226 | + received from the specified subnet immediately upon receipt. |
| 5227 | + period: The number of blocks during which the transaction will remain valid after it's submitted. If the |
| 5228 | + transaction is not included in a block within that number of blocks, it will expire and be rejected. You |
| 5229 | + can think of it as an expiration date for the transaction. |
| 5230 | + raise_error: Raises a relevant exception rather than returning `False` if unsuccessful. |
| 5231 | + wait_for_inclusion: Whether to wait for the inclusion of the transaction. |
| 5232 | + wait_for_finalization: Whether to wait for the finalization of the transaction. |
| 5233 | +
|
| 5234 | + Returns: |
| 5235 | + tuple[bool, str]: |
| 5236 | + `True` if the extrinsic executed successfully, `False` otherwise. |
| 5237 | + `message` is a string value describing the success or potential error. |
| 5238 | + """ |
| 5239 | + return await set_auto_stake_extrinsic( |
| 5240 | + subtensor=self, |
| 5241 | + wallet=wallet, |
| 5242 | + netuid=netuid, |
| 5243 | + hotkey_ss58=hotkey_ss58, |
| 5244 | + period=period, |
| 5245 | + raise_error=raise_error, |
| 5246 | + wait_for_inclusion=wait_for_inclusion, |
| 5247 | + wait_for_finalization=wait_for_finalization, |
| 5248 | + ) |
| 5249 | + |
5173 | 5250 | async def set_children( |
5174 | 5251 | self, |
5175 | 5252 | wallet: "Wallet", |
|
0 commit comments