Skip to content

Commit 9c97f2f

Browse files
authored
Merge pull request #3296 from opentensor/feat/coldkey-swap-clear
Feat/coldkey swap clear
2 parents 6b12be8 + 2fd38e0 commit 9c97f2f

File tree

8 files changed

+476
-14
lines changed

8 files changed

+476
-14
lines changed

bittensor/core/async_subtensor.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
)
5757
from bittensor.core.extrinsics.asyncex.coldkey_swap import (
5858
announce_coldkey_swap_extrinsic,
59+
clear_coldkey_swap_announcement_extrinsic,
5960
dispute_coldkey_swap_extrinsic,
6061
swap_coldkey_announced_extrinsic,
6162
)
@@ -7115,6 +7116,50 @@ async def dispute_coldkey_swap(
71157116
wait_for_revealed_execution=wait_for_revealed_execution,
71167117
)
71177118

7119+
async def clear_coldkey_swap_announcement(
7120+
self,
7121+
wallet: "Wallet",
7122+
*,
7123+
mev_protection: bool = DEFAULT_MEV_PROTECTION,
7124+
period: Optional[int] = DEFAULT_PERIOD,
7125+
raise_error: bool = False,
7126+
wait_for_inclusion: bool = True,
7127+
wait_for_finalization: bool = True,
7128+
wait_for_revealed_execution: bool = True,
7129+
) -> ExtrinsicResponse:
7130+
"""
7131+
Clears (withdraws) a pending coldkey swap announcement.
7132+
7133+
Callable by the coldkey that has an active, undisputed swap announcement. The reannouncement delay must have
7134+
elapsed past the execution block before the announcement can be cleared.
7135+
7136+
Parameters:
7137+
wallet: Bittensor wallet object (should be the current coldkey with an active announcement).
7138+
mev_protection: If ``True``, encrypts and submits the transaction through the MEV Shield pallet.
7139+
period: The number of blocks during which the transaction will remain valid.
7140+
raise_error: Raises a relevant exception rather than returning ``False`` if unsuccessful.
7141+
wait_for_inclusion: Whether to wait for the inclusion of the transaction.
7142+
wait_for_finalization: Whether to wait for the finalization of the transaction.
7143+
wait_for_revealed_execution: Whether to wait for the revealed execution if mev_protection used.
7144+
7145+
Returns:
7146+
ExtrinsicResponse: The result object of the extrinsic execution.
7147+
7148+
Notes:
7149+
- The coldkey must have an active, undisputed swap announcement.
7150+
- The reannouncement delay must have elapsed past the execution block.
7151+
"""
7152+
return await clear_coldkey_swap_announcement_extrinsic(
7153+
subtensor=self,
7154+
wallet=wallet,
7155+
mev_protection=mev_protection,
7156+
period=period,
7157+
raise_error=raise_error,
7158+
wait_for_inclusion=wait_for_inclusion,
7159+
wait_for_finalization=wait_for_finalization,
7160+
wait_for_revealed_execution=wait_for_revealed_execution,
7161+
)
7162+
71187163
async def dissolve_crowdloan(
71197164
self,
71207165
wallet: "Wallet",

bittensor/core/extrinsics/asyncex/coldkey_swap.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,75 @@ async def dispute_coldkey_swap_extrinsic(
184184
return ExtrinsicResponse.from_exception(raise_error=raise_error, error=error)
185185

186186

187+
async def clear_coldkey_swap_announcement_extrinsic(
188+
subtensor: "AsyncSubtensor",
189+
wallet: "Wallet",
190+
*,
191+
mev_protection: bool = DEFAULT_MEV_PROTECTION,
192+
period: Optional[int] = None,
193+
raise_error: bool = False,
194+
wait_for_inclusion: bool = True,
195+
wait_for_finalization: bool = True,
196+
wait_for_revealed_execution: bool = True,
197+
) -> ExtrinsicResponse:
198+
"""
199+
Clears (withdraws) a pending coldkey swap announcement.
200+
201+
Callable by the coldkey that has an active, undisputed swap announcement. The reannouncement delay must have
202+
elapsed past the execution block before the announcement can be cleared.
203+
204+
Parameters:
205+
subtensor: AsyncSubtensor instance with the connection to the chain.
206+
wallet: Bittensor wallet object (should be the current coldkey with an active announcement).
207+
mev_protection: If ``True``, encrypts and submits the transaction through the MEV Shield pallet.
208+
period: The number of blocks during which the transaction will remain valid.
209+
raise_error: Raises a relevant exception rather than returning ``False`` if unsuccessful.
210+
wait_for_inclusion: Whether to wait for the inclusion of the transaction.
211+
wait_for_finalization: Whether to wait for the finalization of the transaction.
212+
wait_for_revealed_execution: Whether to wait for the revealed execution if mev_protection used.
213+
214+
Returns:
215+
ExtrinsicResponse: The result object of the extrinsic execution.
216+
217+
Notes:
218+
- The coldkey must have an active, undisputed swap announcement.
219+
- The reannouncement delay must have elapsed past the execution block.
220+
"""
221+
try:
222+
if not (
223+
unlocked := ExtrinsicResponse.unlock_wallet(wallet, raise_error)
224+
).success:
225+
return unlocked
226+
227+
call = await SubtensorModule(subtensor).clear_coldkey_swap_announcement()
228+
229+
if mev_protection:
230+
response = await submit_encrypted_extrinsic(
231+
subtensor=subtensor,
232+
wallet=wallet,
233+
call=call,
234+
period=period,
235+
raise_error=raise_error,
236+
wait_for_inclusion=wait_for_inclusion,
237+
wait_for_finalization=wait_for_finalization,
238+
wait_for_revealed_execution=wait_for_revealed_execution,
239+
)
240+
else:
241+
response = await subtensor.sign_and_send_extrinsic(
242+
call=call,
243+
wallet=wallet,
244+
wait_for_inclusion=wait_for_inclusion,
245+
wait_for_finalization=wait_for_finalization,
246+
period=period,
247+
raise_error=raise_error,
248+
)
249+
250+
return response
251+
252+
except Exception as error:
253+
return ExtrinsicResponse.from_exception(raise_error=raise_error, error=error)
254+
255+
187256
async def swap_coldkey_announced_extrinsic(
188257
subtensor: "AsyncSubtensor",
189258
wallet: "Wallet",

bittensor/core/extrinsics/coldkey_swap.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,75 @@ def dispute_coldkey_swap_extrinsic(
186186
return ExtrinsicResponse.from_exception(raise_error=raise_error, error=error)
187187

188188

189+
def clear_coldkey_swap_announcement_extrinsic(
190+
subtensor: "Subtensor",
191+
wallet: "Wallet",
192+
*,
193+
mev_protection: bool = DEFAULT_MEV_PROTECTION,
194+
period: Optional[int] = None,
195+
raise_error: bool = False,
196+
wait_for_inclusion: bool = True,
197+
wait_for_finalization: bool = True,
198+
wait_for_revealed_execution: bool = True,
199+
) -> ExtrinsicResponse:
200+
"""
201+
Clears (withdraws) a pending coldkey swap announcement.
202+
203+
Callable by the coldkey that has an active, undisputed swap announcement. The reannouncement delay must have
204+
elapsed past the execution block before the announcement can be cleared.
205+
206+
Parameters:
207+
subtensor: Subtensor instance with the connection to the chain.
208+
wallet: Bittensor wallet object (should be the current coldkey with an active announcement).
209+
mev_protection: If `True`, encrypts and submits the transaction through the MEV Shield pallet.
210+
period: The number of blocks during which the transaction will remain valid.
211+
raise_error: Raises a relevant exception rather than returning `False` if unsuccessful.
212+
wait_for_inclusion: Whether to wait for the inclusion of the transaction.
213+
wait_for_finalization: Whether to wait for the finalization of the transaction.
214+
wait_for_revealed_execution: Whether to wait for the revealed execution if mev_protection used.
215+
216+
Returns:
217+
ExtrinsicResponse: The result object of the extrinsic execution.
218+
219+
Notes:
220+
- The coldkey must have an active, undisputed swap announcement.
221+
- The reannouncement delay must have elapsed past the execution block.
222+
"""
223+
try:
224+
if not (
225+
unlocked := ExtrinsicResponse.unlock_wallet(wallet, raise_error)
226+
).success:
227+
return unlocked
228+
229+
call = SubtensorModule(subtensor).clear_coldkey_swap_announcement()
230+
231+
if mev_protection:
232+
response = submit_encrypted_extrinsic(
233+
subtensor=subtensor,
234+
wallet=wallet,
235+
call=call,
236+
period=period,
237+
raise_error=raise_error,
238+
wait_for_inclusion=wait_for_inclusion,
239+
wait_for_finalization=wait_for_finalization,
240+
wait_for_revealed_execution=wait_for_revealed_execution,
241+
)
242+
else:
243+
response = subtensor.sign_and_send_extrinsic(
244+
call=call,
245+
wallet=wallet,
246+
wait_for_inclusion=wait_for_inclusion,
247+
wait_for_finalization=wait_for_finalization,
248+
period=period,
249+
raise_error=raise_error,
250+
)
251+
252+
return response
253+
254+
except Exception as error:
255+
return ExtrinsicResponse.from_exception(raise_error=raise_error, error=error)
256+
257+
189258
def swap_coldkey_announced_extrinsic(
190259
subtensor: "Subtensor",
191260
wallet: "Wallet",

bittensor/core/extrinsics/pallets/subtensor_module.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,17 @@ def dispute_coldkey_swap(self) -> Call:
366366
"""
367367
return self.create_composed_call()
368368

369+
def clear_coldkey_swap_announcement(self) -> Call:
370+
"""Returns GenericCall instance for Subtensor function SubtensorModule.clear_coldkey_swap_announcement.
371+
372+
Callable by the coldkey that has an active swap announcement. Withdraws the announcement
373+
after the reannouncement delay has elapsed past the execution block.
374+
375+
Returns:
376+
GenericCall instance.
377+
"""
378+
return self.create_composed_call()
379+
369380
def reset_coldkey_swap(self, coldkey: str) -> Call:
370381
"""Returns GenericCall instance for Subtensor function SubtensorModule.reset_coldkey_swap.
371382

bittensor/core/subtensor.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
)
5656
from bittensor.core.extrinsics.coldkey_swap import (
5757
announce_coldkey_swap_extrinsic,
58+
clear_coldkey_swap_announcement_extrinsic,
5859
dispute_coldkey_swap_extrinsic,
5960
swap_coldkey_announced_extrinsic,
6061
)
@@ -5924,6 +5925,50 @@ def dispute_coldkey_swap(
59245925
wait_for_revealed_execution=wait_for_revealed_execution,
59255926
)
59265927

5928+
def clear_coldkey_swap_announcement(
5929+
self,
5930+
wallet: "Wallet",
5931+
*,
5932+
mev_protection: bool = DEFAULT_MEV_PROTECTION,
5933+
period: Optional[int] = DEFAULT_PERIOD,
5934+
raise_error: bool = False,
5935+
wait_for_inclusion: bool = True,
5936+
wait_for_finalization: bool = True,
5937+
wait_for_revealed_execution: bool = True,
5938+
) -> ExtrinsicResponse:
5939+
"""
5940+
Clears (withdraws) a pending coldkey swap announcement.
5941+
5942+
Callable by the coldkey that has an active, undisputed swap announcement. The reannouncement delay must have
5943+
elapsed past the execution block before the announcement can be cleared.
5944+
5945+
Parameters:
5946+
wallet: Bittensor wallet object (should be the current coldkey with an active announcement).
5947+
mev_protection: If `True`, encrypts and submits the transaction through the MEV Shield pallet.
5948+
period: The number of blocks during which the transaction will remain valid.
5949+
raise_error: Raises a relevant exception rather than returning `False` if unsuccessful.
5950+
wait_for_inclusion: Whether to wait for the inclusion of the transaction.
5951+
wait_for_finalization: Whether to wait for the finalization of the transaction.
5952+
wait_for_revealed_execution: Whether to wait for the revealed execution if mev_protection used.
5953+
5954+
Returns:
5955+
ExtrinsicResponse: The result object of the extrinsic execution.
5956+
5957+
Notes:
5958+
- The coldkey must have an active, undisputed swap announcement.
5959+
- The reannouncement delay must have elapsed past the execution block.
5960+
"""
5961+
return clear_coldkey_swap_announcement_extrinsic(
5962+
subtensor=self,
5963+
wallet=wallet,
5964+
mev_protection=mev_protection,
5965+
period=period,
5966+
raise_error=raise_error,
5967+
wait_for_inclusion=wait_for_inclusion,
5968+
wait_for_finalization=wait_for_finalization,
5969+
wait_for_revealed_execution=wait_for_revealed_execution,
5970+
)
5971+
59275972
def dissolve_crowdloan(
59285973
self,
59295974
wallet: "Wallet",

bittensor/extras/subtensor_api/extrinsics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def __init__(self, subtensor: Union["_Subtensor", "_AsyncSubtensor"]):
1313
self.add_stake_burn = subtensor.add_stake_burn
1414
self.add_stake_multiple = subtensor.add_stake_multiple
1515
self.announce_coldkey_swap = subtensor.announce_coldkey_swap
16+
self.clear_coldkey_swap_announcement = subtensor.clear_coldkey_swap_announcement
1617
self.dispute_coldkey_swap = subtensor.dispute_coldkey_swap
1718
self.burned_register = subtensor.burned_register
1819
self.claim_root = subtensor.claim_root

0 commit comments

Comments
 (0)