Transactions

swap-coldkey-announced

Execute a previously announced coldkey swap (after the delay has passed).

View as Markdown

Step two of the two-step migration: confirms the new coldkey and moves everything the signing coldkey owns — balance, stake, and subnet ownership — to it (merging with any assets already on the destination). Irreversible once included. The revealed key must hash to exactly what announce_coldkey_swap committed to, and the call fails if the announcement delay has not elapsed, no announcement exists, or the swap is frozen by a dispute. After it succeeds, the old coldkey is empty; all future operations sign with the new coldkey.

SignerOriginPalletWraps
coldkeysigned account (pallet role may apply)SubtensorModuleSubtensorModule.swap_coldkey_announced

Parameters

ParameterTypeRequiredDescription
new_coldkey_ss58stringyesColdkey receiving everything; must match the previously announced hash exactly.

Address parameters (--hotkey, --coldkey, --dest, ...) accept a raw ss58 address, an address-book or proxy-book name, or a local wallet/hotkey name.

CLI

Preview with --dry-run (shows fee, effects, and policy result without submitting), then submit:

btcli tx swap-coldkey-announced \
  --new-coldkey <ss58|name> --dry-run
btcli tx swap-coldkey-announced \
  --new-coldkey <ss58|name> -w my_coldkey

Python

import bittensor as bt
from bittensor.wallet import Wallet

wallet = Wallet(name="my_coldkey", hotkey="my_hotkey")
intent = bt.SwapColdkeyAnnounced(new_coldkey_ss58="5G...destination")

sub = bt.Subtensor()
plan = sub.plan(intent, wallet)   # fee, effects, policy — no submission
result = sub.execute(intent, wallet)
if not result.success:
    print(result.error.code, result.error.remediation)

(bt.Subtensor is also the async client — async with bt.Subtensor() as client: — see The client.) Or build the intent by op name, as an agent would:

result = sub.execute_tool("swap_coldkey_announced", {...}, wallet)

On-chain implementation

SubtensorModule.swap_coldkey_announced — pallets/subtensor/src/macros/dispatches.rs#L2517:

#[pallet::call_index(126)]
#[pallet::weight((Pallet::<T>::swap_coldkey_announced_declared_weight(), DispatchClass::Normal, Pays::Yes))]
pub fn swap_coldkey_announced(
    origin: OriginFor<T>,
    new_coldkey: T::AccountId,
) -> DispatchResultWithPostInfo {
    let who = ensure_signed(origin)?;

    // Announcement checks read the announcement and, for V2, its policy
    // snapshot plus the live reservation; charge those plus the benchmarked
    // base, not the envelope of `MAX_COLDKEY_SWAP_POSITIONS` stake transfers.
    let base = <T as crate::pallet::Config>::WeightInfo::swap_coldkey_announced();
    let announcement_read = T::DbWeight::get().reads(1);
    let initial_precheck = base.saturating_add(announcement_read);
    // Read (do not take) until the swap commits. A failed execute — e.g.
    // destination opt-outs that appeared after announce — must leave the
    // announcement intact so the fee is not silently burned.
    let (when, new_coldkey_hash) =
        ColdkeySwapAnnouncements::<T>::get(who.clone()).ok_or(Self::fail_with_weight(
            Error::<T>::ColdkeySwapAnnouncementNotFound,
            initial_precheck,
        ))?;

    let legacy_hash_matches = new_coldkey_hash == T::Hashing::hash_of(&new_coldkey);
    let snapshot_read = if legacy_hash_matches {
        Weight::zero()
    } else {
        T::DbWeight::get().reads(4)
    };
    let precheck = initial_precheck.saturating_add(snapshot_read);
    let policy_import_mode = if legacy_hash_matches {
        crate::swap::swap_coldkey::ColdkeySwapPolicyImportMode::CurrentDestination
    } else {
        Self::coldkey_swap_v2_policy_snapshot(&who, &new_coldkey, &new_coldkey_hash, when)
            .ok_or(Self::fail_with_weight(
            Error::<T>::AnnouncedColdkeyHashDoesNotMatch,
            precheck,
        ))?
    };

    let now = <frame_system::Pallet<T>>::block_number();
    ensure!(
        now >= when,
        Self::fail_with_weight(Error::<T>::ColdkeySwapTooEarly, precheck)
    );

    let work = Self::do_swap_coldkey_tracked_with_policy_snapshot(
        &who,
        &new_coldkey,
        policy_import_mode,
    )
    .map_err(|(done, error)| {
        Self::fail_with_weight(
            error,
            base.saturating_add(snapshot_read).saturating_add(done),
        )
    })?;

    // A self-swap must not release a root-imposed recovery lock.
    if who != new_coldkey {
        ColdkeySwapDisputes::<T>::remove(&who);
    }
    Self::release_coldkey_swap_destination_reservation(&who);
    ColdkeySwapAnnouncements::<T>::remove(&who);
    ColdkeySwapV2PolicySnapshots::<T>::remove(&who);

    Ok((
        Some(
            Self::swap_coldkey_announced_actual_weight(work).saturating_add(snapshot_read),
        ),
        Pays::Yes,
    )
        .into())
}

Delegates to fail_with_weight, coldkey_swap_v2_policy_snapshot, do_swap_coldkey_tracked_with_policy_snapshot.

Every file is browsable under /code exactly as built into the runtime, or as plain text under /code/raw/<path> (index: /code/index.json).