1
1
import asyncio
2
- from typing import TYPE_CHECKING
2
+ from typing import TYPE_CHECKING , Optional
3
3
4
4
from bittensor .utils .balance import Balance
5
5
from bittensor .utils .btlogging import logging
@@ -18,6 +18,7 @@ async def _get_stake_in_origin_and_dest(
18
18
origin_netuid : int ,
19
19
destination_netuid : int ,
20
20
) -> tuple [Balance , Balance ]:
21
+ """Gets the current stake balances for both origin and destination addresses in their respective subnets."""
21
22
block_hash = await subtensor .substrate .get_chain_head ()
22
23
stake_in_origin , stake_in_destination = await asyncio .gather (
23
24
subtensor .get_stake (
@@ -46,6 +47,7 @@ async def transfer_stake_extrinsic(
46
47
amount : Balance ,
47
48
wait_for_inclusion : bool = True ,
48
49
wait_for_finalization : bool = False ,
50
+ period : Optional [int ] = None ,
49
51
) -> bool :
50
52
"""
51
53
Transfers stake from one coldkey to another in the Bittensor network.
@@ -60,6 +62,9 @@ async def transfer_stake_extrinsic(
60
62
amount (Balance): The amount of stake to transfer as a `Balance` object.
61
63
wait_for_inclusion (bool): If True, waits for transaction inclusion in a block. Defaults to `True`.
62
64
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.
63
68
64
69
Returns:
65
70
bool: True if the transfer was successful, False otherwise.
@@ -77,7 +82,7 @@ async def transfer_stake_extrinsic(
77
82
78
83
# Check sufficient stake
79
84
stake_in_origin , stake_in_destination = await _get_stake_in_origin_and_dest (
80
- subtensor ,
85
+ subtensor = subtensor ,
81
86
origin_hotkey_ss58 = hotkey_ss58 ,
82
87
destination_hotkey_ss58 = hotkey_ss58 ,
83
88
origin_coldkey_ss58 = wallet .coldkeypub .ss58_address ,
@@ -116,6 +121,7 @@ async def transfer_stake_extrinsic(
116
121
wallet = wallet ,
117
122
wait_for_inclusion = wait_for_inclusion ,
118
123
wait_for_finalization = wait_for_finalization ,
124
+ period = period ,
119
125
)
120
126
121
127
if success :
@@ -126,7 +132,7 @@ async def transfer_stake_extrinsic(
126
132
127
133
# Get updated stakes
128
134
origin_stake , dest_stake = await _get_stake_in_origin_and_dest (
129
- subtensor ,
135
+ subtensor = subtensor ,
130
136
origin_hotkey_ss58 = hotkey_ss58 ,
131
137
destination_hotkey_ss58 = hotkey_ss58 ,
132
138
origin_coldkey_ss58 = wallet .coldkeypub .ss58_address ,
@@ -163,6 +169,7 @@ async def swap_stake_extrinsic(
163
169
safe_staking : bool = False ,
164
170
allow_partial_stake : bool = False ,
165
171
rate_tolerance : float = 0.005 ,
172
+ period : Optional [int ] = None ,
166
173
) -> bool :
167
174
"""
168
175
Swaps stake from one subnet to another for a given hotkey in the Bittensor network.
@@ -178,7 +185,10 @@ async def swap_stake_extrinsic(
178
185
wait_for_finalization (bool): If True, waits for transaction finalization. Defaults to False.
179
186
safe_staking (bool): If true, enables price safety checks to protect against price impact.
180
187
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.
182
192
183
193
Returns:
184
194
bool: True if the swap was successful, False otherwise.
@@ -195,7 +205,7 @@ async def swap_stake_extrinsic(
195
205
196
206
# Check sufficient stake
197
207
stake_in_origin , stake_in_destination = await _get_stake_in_origin_and_dest (
198
- subtensor ,
208
+ subtensor = subtensor ,
199
209
origin_hotkey_ss58 = hotkey_ss58 ,
200
210
destination_hotkey_ss58 = hotkey_ss58 ,
201
211
origin_coldkey_ss58 = wallet .coldkeypub .ss58_address ,
@@ -259,6 +269,7 @@ async def swap_stake_extrinsic(
259
269
wallet = wallet ,
260
270
wait_for_inclusion = wait_for_inclusion ,
261
271
wait_for_finalization = wait_for_finalization ,
272
+ period = period ,
262
273
)
263
274
264
275
if success :
@@ -309,6 +320,7 @@ async def move_stake_extrinsic(
309
320
amount : Balance ,
310
321
wait_for_inclusion : bool = True ,
311
322
wait_for_finalization : bool = False ,
323
+ period : Optional [int ] = None ,
312
324
) -> bool :
313
325
"""
314
326
Moves stake from one hotkey to another within subnets in the Bittensor network.
@@ -323,6 +335,9 @@ async def move_stake_extrinsic(
323
335
amount (Balance): The amount of stake to move as a `Balance` object.
324
336
wait_for_inclusion (bool): If True, waits for transaction inclusion in a block. Defaults to True.
325
337
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.
326
341
327
342
Returns:
328
343
bool: True if the move was successful, False otherwise.
@@ -331,7 +346,7 @@ async def move_stake_extrinsic(
331
346
332
347
# Check sufficient stake
333
348
stake_in_origin , stake_in_destination = await _get_stake_in_origin_and_dest (
334
- subtensor ,
349
+ subtensor = subtensor ,
335
350
origin_hotkey_ss58 = origin_hotkey ,
336
351
destination_hotkey_ss58 = destination_hotkey ,
337
352
origin_coldkey_ss58 = wallet .coldkeypub .ss58_address ,
@@ -369,6 +384,7 @@ async def move_stake_extrinsic(
369
384
wallet = wallet ,
370
385
wait_for_inclusion = wait_for_inclusion ,
371
386
wait_for_finalization = wait_for_finalization ,
387
+ period = period ,
372
388
)
373
389
374
390
if success :
@@ -379,7 +395,7 @@ async def move_stake_extrinsic(
379
395
380
396
# Get updated stakes
381
397
origin_stake , dest_stake = await _get_stake_in_origin_and_dest (
382
- subtensor ,
398
+ subtensor = subtensor ,
383
399
origin_hotkey_ss58 = origin_hotkey ,
384
400
destination_hotkey_ss58 = destination_hotkey ,
385
401
origin_coldkey_ss58 = wallet .coldkeypub .ss58_address ,
0 commit comments