11import asyncio
2- from typing import TYPE_CHECKING
2+ from typing import TYPE_CHECKING , Optional
33
44from bittensor .utils .balance import Balance
55from bittensor .utils .btlogging import logging
@@ -18,6 +18,7 @@ async def _get_stake_in_origin_and_dest(
1818 origin_netuid : int ,
1919 destination_netuid : int ,
2020) -> tuple [Balance , Balance ]:
21+ """Gets the current stake balances for both origin and destination addresses in their respective subnets."""
2122 block_hash = await subtensor .substrate .get_chain_head ()
2223 stake_in_origin , stake_in_destination = await asyncio .gather (
2324 subtensor .get_stake (
@@ -46,6 +47,7 @@ async def transfer_stake_extrinsic(
4647 amount : Balance ,
4748 wait_for_inclusion : bool = True ,
4849 wait_for_finalization : bool = False ,
50+ period : Optional [int ] = None ,
4951) -> bool :
5052 """
5153 Transfers stake from one coldkey to another in the Bittensor network.
@@ -60,6 +62,9 @@ async def transfer_stake_extrinsic(
6062 amount (Balance): The amount of stake to transfer as a `Balance` object.
6163 wait_for_inclusion (bool): If True, waits for transaction inclusion in a block. Defaults to `True`.
6264 wait_for_finalization (bool): If True, waits for transaction finalization. Defaults to `False`.
65+ period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If
66+ the transaction is not included in a block within that number of blocks, it will expire and be rejected.
67+ You can think of it as an expiration date for the transaction.
6368
6469 Returns:
6570 bool: True if the transfer was successful, False otherwise.
@@ -77,7 +82,7 @@ async def transfer_stake_extrinsic(
7782
7883 # Check sufficient stake
7984 stake_in_origin , stake_in_destination = await _get_stake_in_origin_and_dest (
80- subtensor ,
85+ subtensor = subtensor ,
8186 origin_hotkey_ss58 = hotkey_ss58 ,
8287 destination_hotkey_ss58 = hotkey_ss58 ,
8388 origin_coldkey_ss58 = wallet .coldkeypub .ss58_address ,
@@ -116,6 +121,7 @@ async def transfer_stake_extrinsic(
116121 wallet = wallet ,
117122 wait_for_inclusion = wait_for_inclusion ,
118123 wait_for_finalization = wait_for_finalization ,
124+ period = period ,
119125 )
120126
121127 if success :
@@ -126,7 +132,7 @@ async def transfer_stake_extrinsic(
126132
127133 # Get updated stakes
128134 origin_stake , dest_stake = await _get_stake_in_origin_and_dest (
129- subtensor ,
135+ subtensor = subtensor ,
130136 origin_hotkey_ss58 = hotkey_ss58 ,
131137 destination_hotkey_ss58 = hotkey_ss58 ,
132138 origin_coldkey_ss58 = wallet .coldkeypub .ss58_address ,
@@ -163,6 +169,7 @@ async def swap_stake_extrinsic(
163169 safe_staking : bool = False ,
164170 allow_partial_stake : bool = False ,
165171 rate_tolerance : float = 0.005 ,
172+ period : Optional [int ] = None ,
166173) -> bool :
167174 """
168175 Swaps stake from one subnet to another for a given hotkey in the Bittensor network.
@@ -178,7 +185,10 @@ async def swap_stake_extrinsic(
178185 wait_for_finalization (bool): If True, waits for transaction finalization. Defaults to False.
179186 safe_staking (bool): If true, enables price safety checks to protect against price impact.
180187 allow_partial_stake (bool): If true, allows partial stake swaps when the full amount would exceed the price tolerance.
181- rate_tolerance (float): Maximum allowed increase in price ratio (0.005 = 0.5%).
188+ rate_tolerance (float): Maximum allowed increase in a price ratio (0.005 = 0.5%).
189+ period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If
190+ the transaction is not included in a block within that number of blocks, it will expire and be rejected.
191+ You can think of it as an expiration date for the transaction.
182192
183193 Returns:
184194 bool: True if the swap was successful, False otherwise.
@@ -195,7 +205,7 @@ async def swap_stake_extrinsic(
195205
196206 # Check sufficient stake
197207 stake_in_origin , stake_in_destination = await _get_stake_in_origin_and_dest (
198- subtensor ,
208+ subtensor = subtensor ,
199209 origin_hotkey_ss58 = hotkey_ss58 ,
200210 destination_hotkey_ss58 = hotkey_ss58 ,
201211 origin_coldkey_ss58 = wallet .coldkeypub .ss58_address ,
@@ -259,6 +269,7 @@ async def swap_stake_extrinsic(
259269 wallet = wallet ,
260270 wait_for_inclusion = wait_for_inclusion ,
261271 wait_for_finalization = wait_for_finalization ,
272+ period = period ,
262273 )
263274
264275 if success :
@@ -309,6 +320,7 @@ async def move_stake_extrinsic(
309320 amount : Balance ,
310321 wait_for_inclusion : bool = True ,
311322 wait_for_finalization : bool = False ,
323+ period : Optional [int ] = None ,
312324) -> bool :
313325 """
314326 Moves stake from one hotkey to another within subnets in the Bittensor network.
@@ -323,6 +335,9 @@ async def move_stake_extrinsic(
323335 amount (Balance): The amount of stake to move as a `Balance` object.
324336 wait_for_inclusion (bool): If True, waits for transaction inclusion in a block. Defaults to True.
325337 wait_for_finalization (bool): If True, waits for transaction finalization. Defaults to False.
338+ period (Optional[int]): The number of blocks during which the transaction will remain valid after it's submitted. If
339+ the transaction is not included in a block within that number of blocks, it will expire and be rejected.
340+ You can think of it as an expiration date for the transaction.
326341
327342 Returns:
328343 bool: True if the move was successful, False otherwise.
@@ -331,7 +346,7 @@ async def move_stake_extrinsic(
331346
332347 # Check sufficient stake
333348 stake_in_origin , stake_in_destination = await _get_stake_in_origin_and_dest (
334- subtensor ,
349+ subtensor = subtensor ,
335350 origin_hotkey_ss58 = origin_hotkey ,
336351 destination_hotkey_ss58 = destination_hotkey ,
337352 origin_coldkey_ss58 = wallet .coldkeypub .ss58_address ,
@@ -369,6 +384,7 @@ async def move_stake_extrinsic(
369384 wallet = wallet ,
370385 wait_for_inclusion = wait_for_inclusion ,
371386 wait_for_finalization = wait_for_finalization ,
387+ period = period ,
372388 )
373389
374390 if success :
@@ -379,7 +395,7 @@ async def move_stake_extrinsic(
379395
380396 # Get updated stakes
381397 origin_stake , dest_stake = await _get_stake_in_origin_and_dest (
382- subtensor ,
398+ subtensor = subtensor ,
383399 origin_hotkey_ss58 = origin_hotkey ,
384400 destination_hotkey_ss58 = destination_hotkey ,
385401 origin_coldkey_ss58 = wallet .coldkeypub .ss58_address ,
0 commit comments