[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6GPSBESV7Y0GFQPMNNQ92P7":3,"skill-same:01M6GPSBESV7Y0GFQPMNNQ92P7":87},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":16,"sourceHtmlUrl":17,"categories":18,"keywords":19,"publishedAt":41,"linkOnly":42,"markdownContent":43,"markdownBody":44,"frontMatter":45,"refName":50,"commitSha":51,"skillDirectory":52,"forksCount":53,"repositoryHtmlUrl":54,"repositoryHomepageUrl":6,"ownerHtmlUrl":55,"ownerBlogUrl":56,"ownerDescription":57,"updatedAt":58,"install":59,"resources":72},"01M6GPSBESV7Y0GFQPMNNQ92P7","ckbtc",null,"Accept, send, and manage ckBTC (chain-key Bitcoin). Covers BTC deposit flow via minter, ckBTC transfers, withdrawal to BTC, subaccount derivation, and UTXO management. Use when integrating Bitcoin, ckBTC, BTC deposits, or BTC withdrawals in a canister. Do NOT use for plain token transfers without BTC minting\u002Fwithdrawal — use icrc-ledger instead.","jiayaoqijia\u002Fcryptoskill","jiayaoqijia","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F1453879?v=4","01M6GMYTX7Q7S504VC6E756ENR","YQ","01M6GMYV1QKJ1CC75MTTGT9PR0",81,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fchains\u002Fdfinity-official-ckbtc\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fchains\u002Fdfinity-official-ckbtc\u002FSKILL.md",[],[5,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40],"token","accept","when","send","for","transfers","ledger","via","chain","icp","cli","btc","deposit","do","manage","use","minting","management","bitcoin","flow","defi","2026-11-10 10:12:30",false,"---\nname: ckbtc\ndescription: \"Accept, send, and manage ckBTC (chain-key Bitcoin). Covers BTC deposit flow via minter, ckBTC transfers, withdrawal to BTC, subaccount derivation, and UTXO management. Use when integrating Bitcoin, ckBTC, BTC deposits, or BTC withdrawals in a canister. Do NOT use for plain token transfers without BTC minting\u002Fwithdrawal — use icrc-ledger instead.\"\nlicense: Apache-2.0\ncompatibility: \"icp-cli >= 0.2.2\"\nmetadata:\n  title: ckBTC (chain-key Bitcoin)\n  category: DeFi\n---\n\n# Chain-Key Bitcoin (ckBTC) Integration\n\n## What This Is\n\nckBTC is a 1:1 BTC-backed token native to the Internet Computer. No bridges, no wrapping, no third-party custodians. The ckBTC minter canister holds real BTC and mints\u002Fburns ckBTC tokens. Transfers settle in 1-2 seconds with a 10 satoshi fee (versus minutes and thousands of satoshis on Bitcoin L1).\n\n## Prerequisites\n\n- For Motoko: `mops` package manager, `core = \"2.0.0\"` in mops.toml\n- For Rust: `ic-cdk`, `icrc-ledger-types`, `candid`, `serde`\n\n## Canister IDs\n\n### Bitcoin Mainnet\n\n| Canister | ID |\n|---|---|\n| ckBTC Ledger | `mxzaz-hqaaa-aaaar-qaada-cai` |\n| ckBTC Minter | `mqygn-kiaaa-aaaar-qaadq-cai` |\n| ckBTC Index | `n5wcd-faaaa-aaaar-qaaea-cai` |\n| ckBTC Checker | `oltsj-fqaaa-aaaar-qal5q-cai` |\n\n### Bitcoin Testnet4\n\n| Canister | ID |\n|---|---|\n| ckBTC Ledger | `mc6ru-gyaaa-aaaar-qaaaq-cai` |\n| ckBTC Minter | `ml52i-qqaaa-aaaar-qaaba-cai` |\n| ckBTC Index | `mm444-5iaaa-aaaar-qaabq-cai` |\n\n## How It Works\n\n### Deposit Flow (BTC -> ckBTC)\n\n1. Call `get_btc_address` on the minter with the user's principal + subaccount. This returns a unique Bitcoin address controlled by the minter.\n2. User sends BTC to that address using any Bitcoin wallet.\n3. Wait for Bitcoin confirmations (the minter requires confirmations before minting).\n4. Call `update_balance` on the minter with the same principal + subaccount. The minter checks for new UTXOs and mints equivalent ckBTC to the user's ICRC-1 account.\n\n### Transfer Flow (ckBTC -> ckBTC)\n\nCall `icrc1_transfer` on the ckBTC ledger. Fee is 10 satoshis. Settles in 1-2 seconds.\n\n### Withdrawal Flow (ckBTC -> BTC)\n\n1. Call `icrc2_approve` on the ckBTC ledger to grant the minter canister an allowance to spend from your account.\n2. Call `retrieve_btc_with_approval` on the minter with `{ address, amount, from_subaccount: null }`.\n3. The minter uses the approval to burn the ckBTC and submits a Bitcoin transaction.\n4. The BTC arrives at the destination address after Bitcoin confirmations.\n\n### Subaccount Generation\n\nEach user gets a unique deposit address derived from their principal + an optional 32-byte subaccount. To give each user a distinct deposit address within your canister, derive subaccounts from a user-specific identifier (their principal or a sequential ID).\n\n## Mistakes That Break Your Build\n\n1. **Using the wrong minter canister ID.** The minter ID is `mqygn-kiaaa-aaaar-qaadq-cai`. Do not confuse it with the ledger (`mxzaz-...`) or index (`n5wcd-...`).\n\n2. **Forgetting the 10 satoshi transfer fee.** Every `icrc1_transfer` deducts 10 satoshis beyond the amount. If the user has exactly 1000 satoshis and you transfer 1000, it fails with `InsufficientFunds`. Transfer `balance - 10` instead.\n\n3. **Not calling `update_balance` after a BTC deposit.** Sending BTC to the deposit address does nothing until you call `update_balance`. The minter does not auto-detect deposits. Your app must call this.\n\n4. **Using Account Identifier instead of ICRC-1 Account.** ckBTC uses the ICRC-1 standard: `{ owner: Principal, subaccount: ?Blob }`. Do NOT use the legacy `AccountIdentifier` (hex string) from the ICP ledger.\n\n5. **Subaccount must be exactly 32 bytes or null.** Passing a subaccount shorter or longer than 32 bytes causes a trap. Pad with leading zeros if deriving from a shorter value.\n\n6. **Calling `retrieve_btc` with amount below the minimum.** The minter has a minimum withdrawal amount (currently 50,000 satoshis \u002F 0.0005 BTC). Below this, you get `AmountTooLow`.\n\n7. **Not checking the `retrieve_btc` response for errors.** The response is a variant: `Ok` contains `{ block_index }`, `Err` contains specific errors like `MalformedAddress`, `InsufficientFunds`, `TemporarilyUnavailable`. Always match both arms.\n\n8. **Forgetting `owner` in `get_btc_address` args.** If you omit `owner`, Candid sub-typing assigns null, and the minter returns the deposit address of the caller (the canister) instead of the user.\n\n9. **Leaving `created_at_time` null on `icrc1_transfer` \u002F `icrc2_approve`.** The ICRC-1 spec says a ledger SHOULD NOT deduplicate a transaction whose `created_at_time` is unset, so a retried transfer executes a second time and moves real BTC-backed value twice. Set it, and retry with the **same** timestamp — the ledger only matches duplicates when every argument is identical, so a fresh `Time.now()` on retry defeats dedup. A retry that was already applied returns `#Err(#Duplicate { duplicate_of })`, which is a success, not a failure.\n\n## Implementation\n\n### Motoko\n\n#### mops.toml\n\n```toml\n[package]\nname = \"ckbtc-app\"\nversion = \"0.1.0\"\n\n[dependencies]\ncore = \"2.0.0\"\nicrc2-types = \"1.1.0\"\n\n[canisters.backend]\nmain = \"src\u002Fbackend\u002Fmain.mo\"\n```\n\nThe `@dfinity\u002Fmotoko@v5+` recipe compiles via `mops build \u003Ccanister-name>`, so `main` lives here — not in `recipe.configuration` in `icp.yaml`. The `[canisters.\u003Cname>]` key must exactly match the canister `name` in `icp.yaml`.\n\n#### icp.yaml\n\nYour backend canister calls the ckBTC ledger and minter by principal directly — no local ckBTC canister deployment needed.\n\n```yaml\ncanisters:\n  - name: backend\n    recipe:\n      type: \"@dfinity\u002Fmotoko@v5.0.0\"\n```\n\n#### src\u002Fbackend\u002Fmain.mo\n\n```motoko\nimport Principal \"mo:core\u002FPrincipal\";\nimport Blob \"mo:core\u002FBlob\";\nimport Nat \"mo:core\u002FNat\";\nimport Nat8 \"mo:core\u002FNat8\";\nimport Nat64 \"mo:core\u002FNat64\";\nimport Int \"mo:core\u002FInt\";\nimport Time \"mo:core\u002FTime\";\nimport Array \"mo:core\u002FArray\";\nimport Result \"mo:core\u002FResult\";\nimport Error \"mo:core\u002FError\";\nimport Runtime \"mo:core\u002FRuntime\";\n\npersistent actor Self {\n\n  \u002F\u002F -- Types --\n\n  type Account = {\n    owner : Principal;\n    subaccount : ?Blob;\n  };\n\n  type TransferArgs = {\n    from_subaccount : ?Blob;\n    to : Account;\n    amount : Nat;\n    fee : ?Nat;\n    memo : ?Blob;\n    created_at_time : ?Nat64;\n  };\n\n  type TransferResult = {\n    #Ok : Nat; \u002F\u002F block index\n    #Err : TransferError;\n  };\n\n  type TransferError = {\n    #BadFee : { expected_fee : Nat };\n    #BadBurn : { min_burn_amount : Nat };\n    #InsufficientFunds : { balance : Nat };\n    #TooOld;\n    #CreatedInFuture : { ledger_time : Nat64 };\n    #Duplicate : { duplicate_of : Nat };\n    #TemporarilyUnavailable;\n    #GenericError : { error_code : Nat; message : Text };\n  };\n\n  type UpdateBalanceResult = {\n    #Ok : [UtxoStatus];\n    #Err : UpdateBalanceError;\n  };\n\n  type UtxoStatus = {\n    #ValueTooSmall : Utxo;\n    #Tainted : Utxo;\n    #Checked : Utxo;\n    #Minted : { block_index : Nat64; minted_amount : Nat64; utxo : Utxo };\n  };\n\n  type Utxo = {\n    outpoint : { txid : Blob; vout : Nat32 };\n    value : Nat64;\n    height : Nat32;\n  };\n\n  type UpdateBalanceError = {\n    #NoNewUtxos : {\n      required_confirmations : Nat32;\n      pending_utxos : ?[PendingUtxo];\n      current_confirmations : ?Nat32;\n    };\n    #AlreadyProcessing;\n    #TemporarilyUnavailable : Text;\n    #GenericError : { error_code : Nat64; error_message : Text };\n  };\n\n  type PendingUtxo = {\n    outpoint : { txid : Blob; vout : Nat32 };\n    value : Nat64;\n    confirmations : Nat32;\n  };\n\n  type ApproveArgs = {\n    from_subaccount : ?Blob;\n    spender : Account;\n    amount : Nat;\n    expected_allowance : ?Nat;\n    expires_at : ?Nat64;\n    fee : ?Nat;\n    memo : ?Blob;\n    created_at_time : ?Nat64;\n  };\n\n  type ApproveError = {\n    #BadFee : { expected_fee : Nat };\n    #InsufficientFunds : { balance : Nat };\n    #AllowanceChanged : { current_allowance : Nat };\n    #Expired : { ledger_time : Nat64 };\n    #TooOld;\n    #CreatedInFuture : { ledger_time : Nat64 };\n    #Duplicate : { duplicate_of : Nat };\n    #TemporarilyUnavailable;\n    #GenericError : { error_code : Nat; message : Text };\n  };\n\n  type RetrieveBtcWithApprovalArgs = {\n    address : Text;\n    amount : Nat64;\n    from_subaccount : ?Blob;\n  };\n\n  type RetrieveBtcResult = {\n    #Ok : { block_index : Nat64 };\n    #Err : RetrieveBtcError;\n  };\n\n  type RetrieveBtcError = {\n    #MalformedAddress : Text;\n    #AlreadyProcessing;\n    #AmountTooLow : Nat64;\n    #InsufficientFunds : { balance : Nat64 };\n    #InsufficientAllowance : { allowance : Nat64 };\n    #TemporarilyUnavailable : Text;\n    #GenericError : { error_code : Nat64; error_message : Text };\n  };\n\n  \u002F\u002F -- Remote canister references (mainnet) --\n\n  transient let ckbtcLedger : actor {\n    icrc1_transfer : shared (TransferArgs) -> async TransferResult;\n    icrc1_balance_of : shared query (Account) -> async Nat;\n    icrc1_fee : shared query () -> async Nat;\n    icrc2_approve : shared (ApproveArgs) -> async { #Ok : Nat; #Err : ApproveError };\n  } = actor \"mxzaz-hqaaa-aaaar-qaada-cai\";\n\n  transient let ckbtcMinter : actor {\n    get_btc_address : shared ({\n      owner : ?Principal;\n      subaccount : ?Blob;\n    }) -> async Text;\n    update_balance : shared ({\n      owner : ?Principal;\n      subaccount : ?Blob;\n    }) -> async UpdateBalanceResult;\n    retrieve_btc_with_approval : shared (RetrieveBtcWithApprovalArgs) -> async RetrieveBtcResult;\n  } = actor \"mqygn-kiaaa-aaaar-qaadq-cai\";\n\n  \u002F\u002F -- Subaccount derivation --\n  \u002F\u002F Derive a 32-byte subaccount from a principal for per-user deposit addresses.\n\n  func principalToSubaccount(p : Principal) : Blob {\n    let bytes = Blob.toArray(Principal.toBlob(p));\n    let size = bytes.size();\n    \u002F\u002F First byte is length, remaining padded to 32 bytes\n    let sub = Array.tabulate\u003CNat8>(32, func(i : Nat) : Nat8 {\n      if (i == 0) { Nat8.fromNat(size) }\n      else if (i \u003C= size) { bytes[i - 1] }\n      else { 0 }\n    });\n    Blob.fromArray(sub)\n  };\n\n  \u002F\u002F -- Deposit: Get user's BTC deposit address --\n\n  public shared ({ caller }) func getDepositAddress() : async Text {\n    if (Principal.isAnonymous(caller)) { Runtime.trap(\"Authentication required\") };\n    let subaccount = principalToSubaccount(caller);\n    await ckbtcMinter.get_btc_address({\n      owner = ?Principal.fromActor(Self);\n      subaccount = ?subaccount;\n    })\n  };\n\n  \u002F\u002F -- Deposit: Check for new BTC and mint ckBTC --\n\n  public shared ({ caller }) func updateBalance() : async UpdateBalanceResult {\n    if (Principal.isAnonymous(caller)) { Runtime.trap(\"Authentication required\") };\n    let subaccount = principalToSubaccount(caller);\n    await ckbtcMinter.update_balance({\n      owner = ?Principal.fromActor(Self);\n      subaccount = ?subaccount;\n    })\n  };\n\n  \u002F\u002F -- Check user's ckBTC balance --\n\n  public shared ({ caller }) func getBalance() : async Nat {\n    if (Principal.isAnonymous(caller)) { Runtime.trap(\"Authentication required\") };\n    let subaccount = principalToSubaccount(caller);\n    await ckbtcLedger.icrc1_balance_of({\n      owner = Principal.fromActor(Self);\n      subaccount = ?subaccount;\n    })\n  };\n\n  \u002F\u002F -- Transfer ckBTC to another user --\n\n  public shared ({ caller }) func transfer(to : Principal, amount : Nat) : async TransferResult {\n    if (Principal.isAnonymous(caller)) { Runtime.trap(\"Authentication required\") };\n    let fromSubaccount = principalToSubaccount(caller);\n    let now = Nat64.fromNat(Int.abs(Time.now()));\n    await ckbtcLedger.icrc1_transfer({\n      from_subaccount = ?fromSubaccount;\n      to = { owner = to; subaccount = null };\n      amount = amount;\n      fee = ?10; \u002F\u002F 10 satoshis\n      memo = null;\n      created_at_time = ?now; \u002F\u002F required for dedup — see Pitfall 9\n    })\n  };\n\n  \u002F\u002F -- Withdraw: Convert ckBTC back to BTC --\n\n  public shared ({ caller }) func withdraw(btcAddress : Text, amount : Nat64) : async RetrieveBtcResult {\n    if (Principal.isAnonymous(caller)) { Runtime.trap(\"Authentication required\") };\n\n    \u002F\u002F Step 1: Approve the minter to spend ckBTC from the user's subaccount\n    let fromSubaccount = principalToSubaccount(caller);\n    let now = Nat64.fromNat(Int.abs(Time.now()));\n    let approveResult = await ckbtcLedger.icrc2_approve({\n      from_subaccount = ?fromSubaccount;\n      spender = {\n        owner = Principal.fromText(\"mqygn-kiaaa-aaaar-qaadq-cai\");\n        subaccount = null;\n      };\n      amount = Nat64.toNat(amount) + 10; \u002F\u002F amount + fee for the minter's burn\n      expected_allowance = null;\n      expires_at = null;\n      fee = ?10;\n      memo = null;\n      created_at_time = ?now; \u002F\u002F required for dedup — see Pitfall 9\n    });\n\n    switch (approveResult) {\n      case (#Err(e)) { return #Err(#GenericError({ error_code = 0; error_message = \"Approve for minter failed\" })) };\n      case (#Ok(_)) {};\n    };\n\n    \u002F\u002F Step 2: Call retrieve_btc_with_approval on the minter\n    await ckbtcMinter.retrieve_btc_with_approval({\n      address = btcAddress;\n      amount = amount;\n      from_subaccount = ?fromSubaccount;\n    })\n  };\n};\n```\n\n### Rust\n\n#### Cargo.toml\n\n```toml\n[package]\nname = \"ckbtc_backend\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[lib]\ncrate-type = [\"cdylib\"]\n\n[dependencies]\nic-cdk = \"0.19\"\nic-cdk-timers = \"1.0\"\ncandid = \"0.10\"\nserde = { version = \"1\", features = [\"derive\"] }\nserde_bytes = \"0.11\"\nicrc-ledger-types = \"0.1\"\n```\n\n#### src\u002Flib.rs\n\n```rust\nuse candid::{CandidType, Deserialize, Nat, Principal};\nuse ic_cdk::update;\nuse ic_cdk::call::Call;\nuse icrc_ledger_types::icrc1::account::Account;\nuse icrc_ledger_types::icrc1::transfer::{TransferArg, TransferError};\nuse icrc_ledger_types::icrc2::approve::{ApproveArgs, ApproveError};\n\n\u002F\u002F -- Canister IDs --\nconst CKBTC_LEDGER: &str = \"mxzaz-hqaaa-aaaar-qaada-cai\";\nconst CKBTC_MINTER: &str = \"mqygn-kiaaa-aaaar-qaadq-cai\";\n\n\u002F\u002F -- Minter types --\n\n#[derive(CandidType, Deserialize, Debug)]\nstruct GetBtcAddressArgs {\n    owner: Option\u003CPrincipal>,\n    subaccount: Option\u003CVec\u003Cu8>>,\n}\n\n#[derive(CandidType, Deserialize, Debug)]\nstruct UpdateBalanceArgs {\n    owner: Option\u003CPrincipal>,\n    subaccount: Option\u003CVec\u003Cu8>>,\n}\n\n#[derive(CandidType, Deserialize, Debug)]\nstruct RetrieveBtcWithApprovalArgs {\n    address: String,\n    amount: u64,\n    from_subaccount: Option\u003CVec\u003Cu8>>,\n}\n\n#[derive(CandidType, Deserialize, Debug)]\nstruct RetrieveBtcOk {\n    block_index: u64,\n}\n\n#[derive(CandidType, Deserialize, Debug)]\nenum RetrieveBtcError {\n    MalformedAddress(String),\n    AlreadyProcessing,\n    AmountTooLow(u64),\n    InsufficientFunds { balance: u64 },\n    InsufficientAllowance { allowance: u64 },\n    TemporarilyUnavailable(String),\n    GenericError { error_code: u64, error_message: String },\n}\n\n#[derive(CandidType, Deserialize, Debug)]\nstruct Utxo {\n    outpoint: OutPoint,\n    value: u64,\n    height: u32,\n}\n\n#[derive(CandidType, Deserialize, Debug)]\nstruct OutPoint {\n    txid: Vec\u003Cu8>,\n    vout: u32,\n}\n\n#[derive(CandidType, Deserialize, Debug)]\nstruct PendingUtxo {\n    outpoint: OutPoint,\n    value: u64,\n    confirmations: u32,\n}\n\n#[derive(CandidType, Deserialize, Debug)]\nenum UtxoStatus {\n    ValueTooSmall(Utxo),\n    Tainted(Utxo),\n    Checked(Utxo),\n    Minted {\n        block_index: u64,\n        minted_amount: u64,\n        utxo: Utxo,\n    },\n}\n\n#[derive(CandidType, Deserialize, Debug)]\nenum UpdateBalanceError {\n    NoNewUtxos {\n        required_confirmations: u32,\n        pending_utxos: Option\u003CVec\u003CPendingUtxo>>,\n        current_confirmations: Option\u003Cu32>,\n    },\n    AlreadyProcessing,\n    TemporarilyUnavailable(String),\n    GenericError { error_code: u64, error_message: String },\n}\n\ntype UpdateBalanceResult = Result\u003CVec\u003CUtxoStatus>, UpdateBalanceError>;\ntype RetrieveBtcResult = Result\u003CRetrieveBtcOk, RetrieveBtcError>;\n\n\u002F\u002F -- Subaccount derivation --\n\u002F\u002F Derive a 32-byte subaccount from a principal for per-user deposit addresses.\n\nfn principal_to_subaccount(principal: &Principal) -> [u8; 32] {\n    let mut subaccount = [0u8; 32];\n    let principal_bytes = principal.as_slice();\n    subaccount[0] = principal_bytes.len() as u8;\n    subaccount[1..1 + principal_bytes.len()].copy_from_slice(principal_bytes);\n    subaccount\n}\n\nfn ledger_id() -> Principal {\n    Principal::from_text(CKBTC_LEDGER).unwrap()\n}\n\nfn minter_id() -> Principal {\n    Principal::from_text(CKBTC_MINTER).unwrap()\n}\n\n\u002F\u002F -- Deposit: Get user's BTC deposit address --\n\n#[update]\nasync fn get_deposit_address() -> String {\n    let caller = ic_cdk::api::msg_caller();\n    assert_ne!(caller, Principal::anonymous(), \"Authentication required\");\n\n    let subaccount = principal_to_subaccount(&caller);\n    let args = GetBtcAddressArgs {\n        owner: Some(ic_cdk::api::canister_self()),\n        subaccount: Some(subaccount.to_vec()),\n    };\n\n    let (address,): (String,) = Call::unbounded_wait(minter_id(), \"get_btc_address\")\n        .with_arg(args)\n        .await\n        .expect(\"Failed to get BTC address\")\n        .candid_tuple()\n        .expect(\"Failed to decode response\");\n\n    address\n}\n\n\u002F\u002F -- Deposit: Check for new BTC and mint ckBTC --\n\n#[update]\nasync fn update_balance() -> UpdateBalanceResult {\n    let caller = ic_cdk::api::msg_caller();\n    assert_ne!(caller, Principal::anonymous(), \"Authentication required\");\n\n    let subaccount = principal_to_subaccount(&caller);\n    let args = UpdateBalanceArgs {\n        owner: Some(ic_cdk::api::canister_self()),\n        subaccount: Some(subaccount.to_vec()),\n    };\n\n    let (result,): (UpdateBalanceResult,) = Call::unbounded_wait(minter_id(), \"update_balance\")\n        .with_arg(args)\n        .await\n        .expect(\"Failed to call update_balance\")\n        .candid_tuple()\n        .expect(\"Failed to decode response\");\n\n    result\n}\n\n\u002F\u002F -- Check user's ckBTC balance --\n\n#[update]\nasync fn get_balance() -> Nat {\n    let caller = ic_cdk::api::msg_caller();\n    assert_ne!(caller, Principal::anonymous(), \"Authentication required\");\n\n    let subaccount = principal_to_subaccount(&caller);\n    let account = Account {\n        owner: ic_cdk::api::canister_self(),\n        subaccount: Some(subaccount),\n    };\n\n    let (balance,): (Nat,) = Call::unbounded_wait(ledger_id(), \"icrc1_balance_of\")\n        .with_arg(account)\n        .await\n        .expect(\"Failed to get balance\")\n        .candid_tuple()\n        .expect(\"Failed to decode response\");\n\n    balance\n}\n\n\u002F\u002F -- Transfer ckBTC to another user --\n\n#[update]\nasync fn transfer(to: Principal, amount: Nat) -> Result\u003CNat, TransferError> {\n    let caller = ic_cdk::api::msg_caller();\n    assert_ne!(caller, Principal::anonymous(), \"Authentication required\");\n\n    let from_subaccount = principal_to_subaccount(&caller);\n    let args = TransferArg {\n        from_subaccount: Some(from_subaccount),\n        to: Account {\n            owner: to,\n            subaccount: None,\n        },\n        amount,\n        fee: Some(Nat::from(10u64)), \u002F\u002F 10 satoshis\n        memo: None,\n        created_at_time: Some(ic_cdk::api::time()), \u002F\u002F required for dedup — see Pitfall 9\n    };\n\n    let (result,): (Result\u003CNat, TransferError>,) = Call::unbounded_wait(ledger_id(), \"icrc1_transfer\")\n            .with_arg(args)\n            .await\n            .expect(\"Failed to call icrc1_transfer\")\n            .candid_tuple()\n            .expect(\"Failed to decode response\");\n\n    result\n}\n\n\u002F\u002F -- Withdraw: Convert ckBTC back to BTC --\n\n#[update]\nasync fn withdraw(btc_address: String, amount: u64) -> RetrieveBtcResult {\n    let caller = ic_cdk::api::msg_caller();\n    assert_ne!(caller, Principal::anonymous(), \"Authentication required\");\n\n    \u002F\u002F Step 1: Approve the minter to spend ckBTC from the user's subaccount\n    let from_subaccount = principal_to_subaccount(&caller);\n    let approve_args = ApproveArgs {\n        from_subaccount: Some(from_subaccount),\n        spender: Account {\n            owner: minter_id(),\n            subaccount: None,\n        },\n        amount: Nat::from(amount) + Nat::from(10u64), \u002F\u002F amount + fee for the minter's burn\n        expected_allowance: None,\n        expires_at: None,\n        fee: Some(Nat::from(10u64)),\n        memo: None,\n        created_at_time: Some(ic_cdk::api::time()), \u002F\u002F required for dedup — see Pitfall 9\n    };\n\n    let (approve_result,): (Result\u003CNat, ApproveError>,) = Call::unbounded_wait(ledger_id(), \"icrc2_approve\")\n            .with_arg(approve_args)\n            .await\n            .expect(\"Failed to call icrc2_approve\")\n            .candid_tuple()\n            .expect(\"Failed to decode response\");\n\n    if let Err(e) = approve_result {\n        return Err(RetrieveBtcError::GenericError {\n            error_code: 0,\n            error_message: format!(\"Approve for minter failed: {:?}\", e),\n        });\n    }\n\n    \u002F\u002F Step 2: Call retrieve_btc_with_approval on the minter\n    let args = RetrieveBtcWithApprovalArgs {\n        address: btc_address,\n        amount,\n        from_subaccount: Some(from_subaccount.to_vec()),\n    };\n\n    let (result,): (RetrieveBtcResult,) = Call::unbounded_wait(minter_id(), \"retrieve_btc_with_approval\")\n            .with_arg(args)\n            .await\n            .expect(\"Failed to call retrieve_btc_with_approval\")\n            .candid_tuple()\n            .expect(\"Failed to decode response\");\n\n    result\n}\n\n\u002F\u002F -- Export Candid interface --\nic_cdk::export_candid!();\n```\n\n## Deploy & Test\n\n### Local Development\n\nThere is no local ckBTC minter. For local testing, mock the minter interface or test against mainnet\u002Ftestnet.\n\n### Deploy to Mainnet\n\n```bash\n# Deploy your backend canister\nicp deploy backend -e ic\n\n# Your canister calls the mainnet ckBTC canisters directly by principal\n```\n\n### Using icp to Interact with ckBTC Directly\n\n```bash\n# Check ckBTC balance for an account\nicp canister call mxzaz-hqaaa-aaaar-qaada-cai icrc1_balance_of \\\n  '(record { owner = principal \"YOUR-PRINCIPAL\"; subaccount = null })' \\\n  -e ic\n\n# Get deposit address\nicp canister call mqygn-kiaaa-aaaar-qaadq-cai get_btc_address \\\n  '(record { owner = opt principal \"YOUR-PRINCIPAL\"; subaccount = null })' \\\n  -e ic\n\n# Check for new deposits and mint ckBTC\nicp canister call mqygn-kiaaa-aaaar-qaadq-cai update_balance \\\n  '(record { owner = opt principal \"YOUR-PRINCIPAL\"; subaccount = null })' \\\n  -e ic\n\n# Transfer ckBTC (amount in e8s — 1 ckBTC = 100_000_000)\n# created_at_time is null here: no dedup, which is fine for a one-off manual\n# call but not for canister code — see Pitfall 9.\nicp canister call mxzaz-hqaaa-aaaar-qaada-cai icrc1_transfer \\\n  '(record {\n    to = record { owner = principal \"RECIPIENT-PRINCIPAL\"; subaccount = null };\n    amount = 100_000;\n    fee = opt 10;\n    memo = null;\n    from_subaccount = null;\n    created_at_time = null;\n  })' -e ic\n\n# Withdraw ckBTC to a BTC address (amount in satoshis, minimum 50_000)\n# Note: In production, use icrc2_approve + retrieve_btc_with_approval (see withdraw function above)\nicp canister call mqygn-kiaaa-aaaar-qaadq-cai retrieve_btc_with_approval \\\n  '(record { address = \"bc1q...your-btc-address\"; amount = 50_000; from_subaccount = null })' \\\n  -e ic\n\n# Check transfer fee\nicp canister call mxzaz-hqaaa-aaaar-qaada-cai icrc1_fee '()' -e ic\n```\n\n## Verify It Works\n\n### Check Balance\n\n```bash\nicp canister call mxzaz-hqaaa-aaaar-qaada-cai icrc1_balance_of \\\n  '(record { owner = principal \"YOUR-PRINCIPAL\"; subaccount = null })' \\\n  -e ic\n# Expected: (AMOUNT : nat) — balance in satoshis (e8s)\n```\n\n### Verify Transfer\n\n```bash\n# Transfer 1000 satoshis\nicp canister call mxzaz-hqaaa-aaaar-qaada-cai icrc1_transfer \\\n  '(record {\n    to = record { owner = principal \"RECIPIENT\"; subaccount = null };\n    amount = 1_000;\n    fee = opt 10;\n    memo = null;\n    from_subaccount = null;\n    created_at_time = null;\n  })' -e ic\n# Expected: (variant { Ok = BLOCK_INDEX : nat })\n\n# Verify recipient received it\nicp canister call mxzaz-hqaaa-aaaar-qaada-cai icrc1_balance_of \\\n  '(record { owner = principal \"RECIPIENT\"; subaccount = null })' \\\n  -e ic\n# Expected: balance increased by 1000\n```\n\n### Verify Deposit Flow\n\n```bash\n# 1. Get deposit address\nicp canister call YOUR-CANISTER getDepositAddress -e ic\n# Expected: \"bc1q...\" or \"3...\" — a valid Bitcoin address\n\n# 2. Send BTC to that address (external wallet)\n\n# 3. Check for new deposits\nicp canister call YOUR-CANISTER updateBalance -e ic\n# Expected: (variant { Ok = vec { variant { Minted = record { ... } } } })\n\n# 4. Check ckBTC balance\nicp canister call YOUR-CANISTER getBalance -e ic\n# Expected: balance reflects minted ckBTC\n```\n\n### Verify Withdrawal\n\n```bash\nicp canister call YOUR-CANISTER withdraw '(\"bc1q...destination\", 50_000 : nat64)' -e ic\n# Expected: (variant { Ok = record { block_index = BLOCK_INDEX : nat64 } })\n# The BTC will arrive at the destination address after Bitcoin confirmations\n```\n","# Chain-Key Bitcoin (ckBTC) Integration\n\n## What This Is\n\nckBTC is a 1:1 BTC-backed token native to the Internet Computer. No bridges, no wrapping, no third-party custodians. The ckBTC minter canister holds real BTC and mints\u002Fburns ckBTC tokens. Transfers settle in 1-2 seconds with a 10 satoshi fee (versus minutes and thousands of satoshis on Bitcoin L1).\n\n## Prerequisites\n\n- For Motoko: `mops` package manager, `core = \"2.0.0\"` in mops.toml\n- For Rust: `ic-cdk`, `icrc-ledger-types`, `candid`, `serde`\n\n## Canister IDs\n\n### Bitcoin Mainnet\n\n| Canister | ID |\n|---|---|\n| ckBTC Ledger | `mxzaz-hqaaa-aaaar-qaada-cai` |\n| ckBTC Minter | `mqygn-kiaaa-aaaar-qaadq-cai` |\n| ckBTC Index | `n5wcd-faaaa-aaaar-qaaea-cai` |\n| ckBTC Checker | `oltsj-fqaaa-aaaar-qal5q-cai` |\n\n### Bitcoin Testnet4\n\n| Canister | ID |\n|---|---|\n| ckBTC Ledger | `mc6ru-gyaaa-aaaar-qaaaq-cai` |\n| ckBTC Minter | `ml52i-qqaaa-aaaar-qaaba-cai` |\n| ckBTC Index | `mm444-5iaaa-aaaar-qaabq-cai` |\n\n## How It Works\n\n### Deposit Flow (BTC -> ckBTC)\n\n1. Call `get_btc_address` on the minter with the user's principal + subaccount. This returns a unique Bitcoin address controlled by the minter.\n2. User sends BTC to that address using any Bitcoin wallet.\n3. Wait for Bitcoin confirmations (the minter requires confirmations before minting).\n4. Call `update_balance` on the minter with the same principal + subaccount. The minter checks for new UTXOs and mints equivalent ckBTC to the user's ICRC-1 account.\n\n### Transfer Flow (ckBTC -> ckBTC)\n\nCall `icrc1_transfer` on the ckBTC ledger. Fee is 10 satoshis. Settles in 1-2 seconds.\n\n### Withdrawal Flow (ckBTC -> BTC)\n\n1. Call `icrc2_approve` on the ckBTC ledger to grant the minter canister an allowance to spend from your account.\n2. Call `retrieve_btc_with_approval` on the minter with `{ address, amount, from_subaccount: null }`.\n3. The minter uses the approval to burn the ckBTC and submits a Bitcoin transaction.\n4. The BTC arrives at the destination address after Bitcoin confirmations.\n\n### Subaccount Generation\n\nEach user gets a unique deposit address derived from their principal + an optional 32-byte subaccount. To give each user a distinct deposit address within your canister, derive subaccounts from a user-specific identifier (their principal or a sequential ID).\n\n## Mistakes That Break Your Build\n\n1. **Using the wrong minter canister ID.** The minter ID is `mqygn-kiaaa-aaaar-qaadq-cai`. Do not confuse it with the ledger (`mxzaz-...`) or index (`n5wcd-...`).\n\n2. **Forgetting the 10 satoshi transfer fee.** Every `icrc1_transfer` deducts 10 satoshis beyond the amount. If the user has exactly 1000 satoshis and you transfer 1000, it fails with `InsufficientFunds`. Transfer `balance - 10` instead.\n\n3. **Not calling `update_balance` after a BTC deposit.** Sending BTC to the deposit address does nothing until you call `update_balance`. The minter does not auto-detect deposits. Your app must call this.\n\n4. **Using Account Identifier instead of ICRC-1 Account.** ckBTC uses the ICRC-1 standard: `{ owner: Principal, subaccount: ?Blob }`. Do NOT use the legacy `AccountIdentifier` (hex string) from the ICP ledger.\n\n5. **Subaccount must be exactly 32 bytes or null.** Passing a subaccount shorter or longer than 32 bytes causes a trap. Pad with leading zeros if deriving from a shorter value.\n\n6. **Calling `retrieve_btc` with amount below the minimum.** The minter has a minimum withdrawal amount (currently 50,000 satoshis \u002F 0.0005 BTC). Below this, you get `AmountTooLow`.\n\n7. **Not checking the `retrieve_btc` response for errors.** The response is a variant: `Ok` contains `{ block_index }`, `Err` contains specific errors like `MalformedAddress`, `InsufficientFunds`, `TemporarilyUnavailable`. Always match both arms.\n\n8. **Forgetting `owner` in `get_btc_address` args.** If you omit `owner`, Candid sub-typing assigns null, and the minter returns the deposit address of the caller (the canister) instead of the user.\n\n9. **Leaving `created_at_time` null on `icrc1_transfer` \u002F `icrc2_approve`.** The ICRC-1 spec says a ledger SHOULD NOT deduplicate a transaction whose `created_at_time` is unset, so a retried transfer executes a second time and moves real BTC-backed value twice. Set it, and retry with the **same** timestamp — the ledger only matches duplicates when every argument is identical, so a fresh `Time.now()` on retry defeats dedup. A retry that was already applied returns `#Err(#Duplicate { duplicate_of })`, which is a success, not a failure.\n\n## Implementation\n\n### Motoko\n\n#### mops.toml\n\n```toml\n[package]\nname = \"ckbtc-app\"\nversion = \"0.1.0\"\n\n[dependencies]\ncore = \"2.0.0\"\nicrc2-types = \"1.1.0\"\n\n[canisters.backend]\nmain = \"src\u002Fbackend\u002Fmain.mo\"\n```\n\nThe `@dfinity\u002Fmotoko@v5+` recipe compiles via `mops build \u003Ccanister-name>`, so `main` lives here — not in `recipe.configuration` in `icp.yaml`. The `[canisters.\u003Cname>]` key must exactly match the canister `name` in `icp.yaml`.\n\n#### icp.yaml\n\nYour backend canister calls the ckBTC ledger and minter by principal directly — no local ckBTC canister deployment needed.\n\n```yaml\ncanisters:\n  - name: backend\n    recipe:\n      type: \"@dfinity\u002Fmotoko@v5.0.0\"\n```\n\n#### src\u002Fbackend\u002Fmain.mo\n\n```motoko\nimport Principal \"mo:core\u002FPrincipal\";\nimport Blob \"mo:core\u002FBlob\";\nimport Nat \"mo:core\u002FNat\";\nimport Nat8 \"mo:core\u002FNat8\";\nimport Nat64 \"mo:core\u002FNat64\";\nimport Int \"mo:core\u002FInt\";\nimport Time \"mo:core\u002FTime\";\nimport Array \"mo:core\u002FArray\";\nimport Result \"mo:core\u002FResult\";\nimport Error \"mo:core\u002FError\";\nimport Runtime \"mo:core\u002FRuntime\";\n\npersistent actor Self {\n\n  \u002F\u002F -- Types --\n\n  type Account = {\n    owner : Principal;\n    subaccount : ?Blob;\n  };\n\n  type TransferArgs = {\n    from_subaccount : ?Blob;\n    to : Account;\n    amount : Nat;\n    fee : ?Nat;\n    memo : ?Blob;\n    created_at_time : ?Nat64;\n  };\n\n  type TransferResult = {\n    #Ok : Nat; \u002F\u002F block index\n    #Err : TransferError;\n  };\n\n  type TransferError = {\n    #BadFee : { expected_fee : Nat };\n    #BadBurn : { min_burn_amount : Nat };\n    #InsufficientFunds : { balance : Nat };\n    #TooOld;\n    #CreatedInFuture : { ledger_time : Nat64 };\n    #Duplicate : { duplicate_of : Nat };\n    #TemporarilyUnavailable;\n    #GenericError : { error_code : Nat; message : Text };\n  };\n\n  type UpdateBalanceResult = {\n    #Ok : [UtxoStatus];\n    #Err : UpdateBalanceError;\n  };\n\n  type UtxoStatus = {\n    #ValueTooSmall : Utxo;\n    #Tainted : Utxo;\n    #Checked : Utxo;\n    #Minted : { block_index : Nat64; minted_amount : Nat64; utxo : Utxo };\n  };\n\n  type Utxo = {\n    outpoint : { txid : Blob; vout : Nat32 };\n    value : Nat64;\n    height : Nat32;\n  };\n\n  type UpdateBalanceError = {\n    #NoNewUtxos : {\n      required_confirmations : Nat32;\n      pending_utxos : ?[PendingUtxo];\n      current_confirmations : ?Nat32;\n    };\n    #AlreadyProcessing;\n    #TemporarilyUnavailable : Text;\n    #GenericError : { error_code : Nat64; error_message : Text };\n  };\n\n  type PendingUtxo = {\n    outpoint : { txid : Blob; vout : Nat32 };\n    value : Nat64;\n    confirmations : Nat32;\n  };\n\n  type ApproveArgs = {\n    from_subaccount : ?Blob;\n    spender : Account;\n    amount : Nat;\n    expected_allowance : ?Nat;\n    expires_at : ?Nat64;\n    fee : ?Nat;\n    memo : ?Blob;\n    created_at_time : ?Nat64;\n  };\n\n  type ApproveError = {\n    #BadFee : { expected_fee : Nat };\n    #InsufficientFunds : { balance : Nat };\n    #AllowanceChanged : { current_allowance : Nat };\n    #Expired : { ledger_time : Nat64 };\n    #TooOld;\n    #CreatedInFuture : { ledger_time : Nat64 };\n    #Duplicate : { duplicate_of : Nat };\n    #TemporarilyUnavailable;\n    #GenericError : { error_code : Nat; message : Text };\n  };\n\n  type RetrieveBtcWithApprovalArgs = {\n    address : Text;\n    amount : Nat64;\n    from_subaccount : ?Blob;\n  };\n\n  type RetrieveBtcResult = {\n    #Ok : { block_index : Nat64 };\n    #Err : RetrieveBtcError;\n  };\n\n  type RetrieveBtcError = {\n    #MalformedAddress : Text;\n    #AlreadyProcessing;\n    #AmountTooLow : Nat64;\n    #InsufficientFunds : { balance : Nat64 };\n    #InsufficientAllowance : { allowance : Nat64 };\n    #TemporarilyUnavailable : Text;\n    #GenericError : { error_code : Nat64; error_message : Text };\n  };\n\n  \u002F\u002F -- Remote canister references (mainnet) --\n\n  transient let ckbtcLedger : actor {\n    icrc1_transfer : shared (TransferArgs) -> async TransferResult;\n    icrc1_balance_of : shared query (Account) -> async Nat;\n    icrc1_fee : shared query () -> async Nat;\n    icrc2_approve : shared (ApproveArgs) -> async { #Ok : Nat; #Err : ApproveError };\n  } = actor \"mxzaz-hqaaa-aaaar-qaada-cai\";\n\n  transient let ckbtcMinter : actor {\n    get_btc_address : shared ({\n      owner : ?Principal;\n      subaccount : ?Blob;\n    }) -> async Text;\n    update_balance : shared ({\n      owner : ?Principal;\n      subaccount : ?Blob;\n    }) -> async UpdateBalanceResult;\n    retrieve_btc_with_approval : shared (RetrieveBtcWithApprovalArgs) -> async RetrieveBtcResult;\n  } = actor \"mqygn-kiaaa-aaaar-qaadq-cai\";\n\n  \u002F\u002F -- Subaccount derivation --\n  \u002F\u002F Derive a 32-byte subaccount from a principal for per-user deposit addresses.\n\n  func principalToSubaccount(p : Principal) : Blob {\n    let bytes = Blob.toArray(Principal.toBlob(p));\n    let size = bytes.size();\n    \u002F\u002F First byte is length, remaining padded to 32 bytes\n    let sub = Array.tabulate\u003CNat8>(32, func(i : Nat) : Nat8 {\n      if (i == 0) { Nat8.fromNat(size) }\n      else if (i \u003C= size) { bytes[i - 1] }\n      else { 0 }\n    });\n    Blob.fromArray(sub)\n  };\n\n  \u002F\u002F -- Deposit: Get user's BTC deposit address --\n\n  public shared ({ caller }) func getDepositAddress() : async Text {\n    if (Principal.isAnonymous(caller)) { Runtime.trap(\"Authentication required\") };\n    let subaccount = principalToSubaccount(caller);\n    await ckbtcMinter.get_btc_address({\n      owner = ?Principal.fromActor(Self);\n      subaccount = ?subaccount;\n    })\n  };\n\n  \u002F\u002F -- Deposit: Check for new BTC and mint ckBTC --\n\n  public shared ({ caller }) func updateBalance() : async UpdateBalanceResult {\n    if (Principal.isAnonymous(caller)) { Runtime.trap(\"Authentication required\") };\n    let subaccount = principalToSubaccount(caller);\n    await ckbtcMinter.update_balance({\n      owner = ?Principal.fromActor(Self);\n      subaccount = ?subaccount;\n    })\n  };\n\n  \u002F\u002F -- Check user's ckBTC balance --\n\n  public shared ({ caller }) func getBalance() : async Nat {\n    if (Principal.isAnonymous(caller)) { Runtime.trap(\"Authentication required\") };\n    let subaccount = principalToSubaccount(caller);\n    await ckbtcLedger.icrc1_balance_of({\n      owner = Principal.fromActor(Self);\n      subaccount = ?subaccount;\n    })\n  };\n\n  \u002F\u002F -- Transfer ckBTC to another user --\n\n  public shared ({ caller }) func transfer(to : Principal, amount : Nat) : async TransferResult {\n    if (Principal.isAnonymous(caller)) { Runtime.trap(\"Authentication required\") };\n    let fromSubaccount = principalToSubaccount(caller);\n    let now = Nat64.fromNat(Int.abs(Time.now()));\n    await ckbtcLedger.icrc1_transfer({\n      from_subaccount = ?fromSubaccount;\n      to = { owner = to; subaccount = null };\n      amount = amount;\n      fee = ?10; \u002F\u002F 10 satoshis\n      memo = null;\n      created_at_time = ?now; \u002F\u002F required for dedup — see Pitfall 9\n    })\n  };\n\n  \u002F\u002F -- Withdraw: Convert ckBTC back to BTC --\n\n  public shared ({ caller }) func withdraw(btcAddress : Text, amount : Nat64) : async RetrieveBtcResult {\n    if (Principal.isAnonymous(caller)) { Runtime.trap(\"Authentication required\") };\n\n    \u002F\u002F Step 1: Approve the minter to spend ckBTC from the user's subaccount\n    let fromSubaccount = principalToSubaccount(caller);\n    let now = Nat64.fromNat(Int.abs(Time.now()));\n    let approveResult = await ckbtcLedger.icrc2_approve({\n      from_subaccount = ?fromSubaccount;\n      spender = {\n        owner = Principal.fromText(\"mqygn-kiaaa-aaaar-qaadq-cai\");\n        subaccount = null;\n      };\n      amount = Nat64.toNat(amount) + 10; \u002F\u002F amount + fee for the minter's burn\n      expected_allowance = null;\n      expires_at = null;\n      fee = ?10;\n      memo = null;\n      created_at_time = ?now; \u002F\u002F required for dedup — see Pitfall 9\n    });\n\n    switch (approveResult) {\n      case (#Err(e)) { return #Err(#GenericError({ error_code = 0; error_message = \"Approve for minter failed\" })) };\n      case (#Ok(_)) {};\n    };\n\n    \u002F\u002F Step 2: Call retrieve_btc_with_approval on the minter\n    await ckbtcMinter.retrieve_btc_with_approval({\n      address = btcAddress;\n      amount = amount;\n      from_subaccount = ?fromSubaccount;\n    })\n  };\n};\n```\n\n### Rust\n\n#### Cargo.toml\n\n```toml\n[package]\nname = \"ckbtc_backend\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[lib]\ncrate-type = [\"cdylib\"]\n\n[dependencies]\nic-cdk = \"0.19\"\nic-cdk-timers = \"1.0\"\ncandid = \"0.10\"\nserde = { version = \"1\", features = [\"derive\"] }\nserde_bytes = \"0.11\"\nicrc-ledger-types = \"0.1\"\n```\n\n#### src\u002Flib.rs\n\n```rust\nuse candid::{CandidType, Deserialize, Nat, Principal};\nuse ic_cdk::update;\nuse ic_cdk::call::Call;\nuse icrc_ledger_types::icrc1::account::Account;\nuse icrc_ledger_types::icrc1::transfer::{TransferArg, TransferError};\nuse icrc_ledger_types::icrc2::approve::{ApproveArgs, ApproveError};\n\n\u002F\u002F -- Canister IDs --\nconst CKBTC_LEDGER: &str = \"mxzaz-hqaaa-aaaar-qaada-cai\";\nconst CKBTC_MINTER: &str = \"mqygn-kiaaa-aaaar-qaadq-cai\";\n\n\u002F\u002F -- Minter types --\n\n#[derive(CandidType, Deserialize, Debug)]\nstruct GetBtcAddressArgs {\n    owner: Option\u003CPrincipal>,\n    subaccount: Option\u003CVec\u003Cu8>>,\n}\n\n#[derive(CandidType, Deserialize, Debug)]\nstruct UpdateBalanceArgs {\n    owner: Option\u003CPrincipal>,\n    subaccount: Option\u003CVec\u003Cu8>>,\n}\n\n#[derive(CandidType, Deserialize, Debug)]\nstruct RetrieveBtcWithApprovalArgs {\n    address: String,\n    amount: u64,\n    from_subaccount: Option\u003CVec\u003Cu8>>,\n}\n\n#[derive(CandidType, Deserialize, Debug)]\nstruct RetrieveBtcOk {\n    block_index: u64,\n}\n\n#[derive(CandidType, Deserialize, Debug)]\nenum RetrieveBtcError {\n    MalformedAddress(String),\n    AlreadyProcessing,\n    AmountTooLow(u64),\n    InsufficientFunds { balance: u64 },\n    InsufficientAllowance { allowance: u64 },\n    TemporarilyUnavailable(String),\n    GenericError { error_code: u64, error_message: String },\n}\n\n#[derive(CandidType, Deserialize, Debug)]\nstruct Utxo {\n    outpoint: OutPoint,\n    value: u64,\n    height: u32,\n}\n\n#[derive(CandidType, Deserialize, Debug)]\nstruct OutPoint {\n    txid: Vec\u003Cu8>,\n    vout: u32,\n}\n\n#[derive(CandidType, Deserialize, Debug)]\nstruct PendingUtxo {\n    outpoint: OutPoint,\n    value: u64,\n    confirmations: u32,\n}\n\n#[derive(CandidType, Deserialize, Debug)]\nenum UtxoStatus {\n    ValueTooSmall(Utxo),\n    Tainted(Utxo),\n    Checked(Utxo),\n    Minted {\n        block_index: u64,\n        minted_amount: u64,\n        utxo: Utxo,\n    },\n}\n\n#[derive(CandidType, Deserialize, Debug)]\nenum UpdateBalanceError {\n    NoNewUtxos {\n        required_confirmations: u32,\n        pending_utxos: Option\u003CVec\u003CPendingUtxo>>,\n        current_confirmations: Option\u003Cu32>,\n    },\n    AlreadyProcessing,\n    TemporarilyUnavailable(String),\n    GenericError { error_code: u64, error_message: String },\n}\n\ntype UpdateBalanceResult = Result\u003CVec\u003CUtxoStatus>, UpdateBalanceError>;\ntype RetrieveBtcResult = Result\u003CRetrieveBtcOk, RetrieveBtcError>;\n\n\u002F\u002F -- Subaccount derivation --\n\u002F\u002F Derive a 32-byte subaccount from a principal for per-user deposit addresses.\n\nfn principal_to_subaccount(principal: &Principal) -> [u8; 32] {\n    let mut subaccount = [0u8; 32];\n    let principal_bytes = principal.as_slice();\n    subaccount[0] = principal_bytes.len() as u8;\n    subaccount[1..1 + principal_bytes.len()].copy_from_slice(principal_bytes);\n    subaccount\n}\n\nfn ledger_id() -> Principal {\n    Principal::from_text(CKBTC_LEDGER).unwrap()\n}\n\nfn minter_id() -> Principal {\n    Principal::from_text(CKBTC_MINTER).unwrap()\n}\n\n\u002F\u002F -- Deposit: Get user's BTC deposit address --\n\n#[update]\nasync fn get_deposit_address() -> String {\n    let caller = ic_cdk::api::msg_caller();\n    assert_ne!(caller, Principal::anonymous(), \"Authentication required\");\n\n    let subaccount = principal_to_subaccount(&caller);\n    let args = GetBtcAddressArgs {\n        owner: Some(ic_cdk::api::canister_self()),\n        subaccount: Some(subaccount.to_vec()),\n    };\n\n    let (address,): (String,) = Call::unbounded_wait(minter_id(), \"get_btc_address\")\n        .with_arg(args)\n        .await\n        .expect(\"Failed to get BTC address\")\n        .candid_tuple()\n        .expect(\"Failed to decode response\");\n\n    address\n}\n\n\u002F\u002F -- Deposit: Check for new BTC and mint ckBTC --\n\n#[update]\nasync fn update_balance() -> UpdateBalanceResult {\n    let caller = ic_cdk::api::msg_caller();\n    assert_ne!(caller, Principal::anonymous(), \"Authentication required\");\n\n    let subaccount = principal_to_subaccount(&caller);\n    let args = UpdateBalanceArgs {\n        owner: Some(ic_cdk::api::canister_self()),\n        subaccount: Some(subaccount.to_vec()),\n    };\n\n    let (result,): (UpdateBalanceResult,) = Call::unbounded_wait(minter_id(), \"update_balance\")\n        .with_arg(args)\n        .await\n        .expect(\"Failed to call update_balance\")\n        .candid_tuple()\n        .expect(\"Failed to decode response\");\n\n    result\n}\n\n\u002F\u002F -- Check user's ckBTC balance --\n\n#[update]\nasync fn get_balance() -> Nat {\n    let caller = ic_cdk::api::msg_caller();\n    assert_ne!(caller, Principal::anonymous(), \"Authentication required\");\n\n    let subaccount = principal_to_subaccount(&caller);\n    let account = Account {\n        owner: ic_cdk::api::canister_self(),\n        subaccount: Some(subaccount),\n    };\n\n    let (balance,): (Nat,) = Call::unbounded_wait(ledger_id(), \"icrc1_balance_of\")\n        .with_arg(account)\n        .await\n        .expect(\"Failed to get balance\")\n        .candid_tuple()\n        .expect(\"Failed to decode response\");\n\n    balance\n}\n\n\u002F\u002F -- Transfer ckBTC to another user --\n\n#[update]\nasync fn transfer(to: Principal, amount: Nat) -> Result\u003CNat, TransferError> {\n    let caller = ic_cdk::api::msg_caller();\n    assert_ne!(caller, Principal::anonymous(), \"Authentication required\");\n\n    let from_subaccount = principal_to_subaccount(&caller);\n    let args = TransferArg {\n        from_subaccount: Some(from_subaccount),\n        to: Account {\n            owner: to,\n            subaccount: None,\n        },\n        amount,\n        fee: Some(Nat::from(10u64)), \u002F\u002F 10 satoshis\n        memo: None,\n        created_at_time: Some(ic_cdk::api::time()), \u002F\u002F required for dedup — see Pitfall 9\n    };\n\n    let (result,): (Result\u003CNat, TransferError>,) = Call::unbounded_wait(ledger_id(), \"icrc1_transfer\")\n            .with_arg(args)\n            .await\n            .expect(\"Failed to call icrc1_transfer\")\n            .candid_tuple()\n            .expect(\"Failed to decode response\");\n\n    result\n}\n\n\u002F\u002F -- Withdraw: Convert ckBTC back to BTC --\n\n#[update]\nasync fn withdraw(btc_address: String, amount: u64) -> RetrieveBtcResult {\n    let caller = ic_cdk::api::msg_caller();\n    assert_ne!(caller, Principal::anonymous(), \"Authentication required\");\n\n    \u002F\u002F Step 1: Approve the minter to spend ckBTC from the user's subaccount\n    let from_subaccount = principal_to_subaccount(&caller);\n    let approve_args = ApproveArgs {\n        from_subaccount: Some(from_subaccount),\n        spender: Account {\n            owner: minter_id(),\n            subaccount: None,\n        },\n        amount: Nat::from(amount) + Nat::from(10u64), \u002F\u002F amount + fee for the minter's burn\n        expected_allowance: None,\n        expires_at: None,\n        fee: Some(Nat::from(10u64)),\n        memo: None,\n        created_at_time: Some(ic_cdk::api::time()), \u002F\u002F required for dedup — see Pitfall 9\n    };\n\n    let (approve_result,): (Result\u003CNat, ApproveError>,) = Call::unbounded_wait(ledger_id(), \"icrc2_approve\")\n            .with_arg(approve_args)\n            .await\n            .expect(\"Failed to call icrc2_approve\")\n            .candid_tuple()\n            .expect(\"Failed to decode response\");\n\n    if let Err(e) = approve_result {\n        return Err(RetrieveBtcError::GenericError {\n            error_code: 0,\n            error_message: format!(\"Approve for minter failed: {:?}\", e),\n        });\n    }\n\n    \u002F\u002F Step 2: Call retrieve_btc_with_approval on the minter\n    let args = RetrieveBtcWithApprovalArgs {\n        address: btc_address,\n        amount,\n        from_subaccount: Some(from_subaccount.to_vec()),\n    };\n\n    let (result,): (RetrieveBtcResult,) = Call::unbounded_wait(minter_id(), \"retrieve_btc_with_approval\")\n            .with_arg(args)\n            .await\n            .expect(\"Failed to call retrieve_btc_with_approval\")\n            .candid_tuple()\n            .expect(\"Failed to decode response\");\n\n    result\n}\n\n\u002F\u002F -- Export Candid interface --\nic_cdk::export_candid!();\n```\n\n## Deploy & Test\n\n### Local Development\n\nThere is no local ckBTC minter. For local testing, mock the minter interface or test against mainnet\u002Ftestnet.\n\n### Deploy to Mainnet\n\n```bash\n# Deploy your backend canister\nicp deploy backend -e ic\n\n# Your canister calls the mainnet ckBTC canisters directly by principal\n```\n\n### Using icp to Interact with ckBTC Directly\n\n```bash\n# Check ckBTC balance for an account\nicp canister call mxzaz-hqaaa-aaaar-qaada-cai icrc1_balance_of \\\n  '(record { owner = principal \"YOUR-PRINCIPAL\"; subaccount = null })' \\\n  -e ic\n\n# Get deposit address\nicp canister call mqygn-kiaaa-aaaar-qaadq-cai get_btc_address \\\n  '(record { owner = opt principal \"YOUR-PRINCIPAL\"; subaccount = null })' \\\n  -e ic\n\n# Check for new deposits and mint ckBTC\nicp canister call mqygn-kiaaa-aaaar-qaadq-cai update_balance \\\n  '(record { owner = opt principal \"YOUR-PRINCIPAL\"; subaccount = null })' \\\n  -e ic\n\n# Transfer ckBTC (amount in e8s — 1 ckBTC = 100_000_000)\n# created_at_time is null here: no dedup, which is fine for a one-off manual\n# call but not for canister code — see Pitfall 9.\nicp canister call mxzaz-hqaaa-aaaar-qaada-cai icrc1_transfer \\\n  '(record {\n    to = record { owner = principal \"RECIPIENT-PRINCIPAL\"; subaccount = null };\n    amount = 100_000;\n    fee = opt 10;\n    memo = null;\n    from_subaccount = null;\n    created_at_time = null;\n  })' -e ic\n\n# Withdraw ckBTC to a BTC address (amount in satoshis, minimum 50_000)\n# Note: In production, use icrc2_approve + retrieve_btc_with_approval (see withdraw function above)\nicp canister call mqygn-kiaaa-aaaar-qaadq-cai retrieve_btc_with_approval \\\n  '(record { address = \"bc1q...your-btc-address\"; amount = 50_000; from_subaccount = null })' \\\n  -e ic\n\n# Check transfer fee\nicp canister call mxzaz-hqaaa-aaaar-qaada-cai icrc1_fee '()' -e ic\n```\n\n## Verify It Works\n\n### Check Balance\n\n```bash\nicp canister call mxzaz-hqaaa-aaaar-qaada-cai icrc1_balance_of \\\n  '(record { owner = principal \"YOUR-PRINCIPAL\"; subaccount = null })' \\\n  -e ic\n# Expected: (AMOUNT : nat) — balance in satoshis (e8s)\n```\n\n### Verify Transfer\n\n```bash\n# Transfer 1000 satoshis\nicp canister call mxzaz-hqaaa-aaaar-qaada-cai icrc1_transfer \\\n  '(record {\n    to = record { owner = principal \"RECIPIENT\"; subaccount = null };\n    amount = 1_000;\n    fee = opt 10;\n    memo = null;\n    from_subaccount = null;\n    created_at_time = null;\n  })' -e ic\n# Expected: (variant { Ok = BLOCK_INDEX : nat })\n\n# Verify recipient received it\nicp canister call mxzaz-hqaaa-aaaar-qaada-cai icrc1_balance_of \\\n  '(record { owner = principal \"RECIPIENT\"; subaccount = null })' \\\n  -e ic\n# Expected: balance increased by 1000\n```\n\n### Verify Deposit Flow\n\n```bash\n# 1. Get deposit address\nicp canister call YOUR-CANISTER getDepositAddress -e ic\n# Expected: \"bc1q...\" or \"3...\" — a valid Bitcoin address\n\n# 2. Send BTC to that address (external wallet)\n\n# 3. Check for new deposits\nicp canister call YOUR-CANISTER updateBalance -e ic\n# Expected: (variant { Ok = vec { variant { Minted = record { ... } } } })\n\n# 4. Check ckBTC balance\nicp canister call YOUR-CANISTER getBalance -e ic\n# Expected: balance reflects minted ckBTC\n```\n\n### Verify Withdrawal\n\n```bash\nicp canister call YOUR-CANISTER withdraw '(\"bc1q...destination\", 50_000 : nat64)' -e ic\n# Expected: (variant { Ok = record { block_index = BLOCK_INDEX : nat64 } })\n# The BTC will arrive at the destination address after Bitcoin confirmations\n```\n",{"name":5,"license":15,"metadata":46,"description":7,"compatibility":49},{"title":47,"category":48},"ckBTC (chain-key Bitcoin)","DeFi","icp-cli >= 0.2.2","main","3df1d0d67b30ff15236561f8c0f9f06d33f42dfd","skills\u002Fchains\u002Fdfinity-official-ckbtc",17,"https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia","https:\u002F\u002Feth2030.com","Hardcore infra. Building @alt-research and applied cryptography.","2026-11-15 02:28:10",{"source":8,"skillName":5,"commands":60,"prompt":70,"zipAvailable":71},[61,64,67],{"tool":62,"command":63},"npx","npx skills add jiayaoqijia\u002Fcryptoskill --skill ckbtc",{"tool":65,"command":66},"bunx","bunx skills add jiayaoqijia\u002Fcryptoskill --skill ckbtc",{"tool":68,"command":69},"pnpm","pnpm dlx skills add jiayaoqijia\u002Fcryptoskill --skill ckbtc","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fchains\u002Fdfinity-official-ckbtc\u002FSKILL.md",true,[73,77,83],{"path":74,"resourceType":74,"resourceTypeDesc":75,"sizeBytes":76,"sourceHtmlUrl":16},"LICENSE","许可证",10770,{"path":78,"resourceType":79,"resourceTypeDesc":80,"sizeBytes":81,"sourceHtmlUrl":82},"SOURCE.md","REFERENCE","参考文档",323,"https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fchains\u002Fdfinity-official-ckbtc\u002FSOURCE.md",{"path":84,"resourceType":79,"resourceTypeDesc":80,"sizeBytes":85,"sourceHtmlUrl":86},"TRUST.auto.yaml",2181,"https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fchains\u002Fdfinity-official-ckbtc\u002FTRUST.auto.yaml",[88,98,106,114,121,129],{"skillNo":89,"name":90,"nameZh":6,"description":91,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":92,"licenseFileUrl":93,"sourceHtmlUrl":94,"categories":95,"keywords":96,"publishedAt":97},"01M7DTKCERMV0RNX3HZJP4CZ26","troves","Deposit and withdraw from Troves DeFi yield vault strategies on Starknet. View available strategies, check positions, and manage vault deposits. Use this skill when the user mentions Troves, vault, yield vault, DeFi vault, strategy, yield farming, vault deposit, vault withdraw, earning yield through vaults, passive yield strategies, or wants to deposit into or withdraw from a yield strategy — even if they don't say \"Troves\" explicitly.","MIT","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fmcp-servers\u002Fahmetenesdur-troves\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fmcp-servers\u002Fahmetenesdur-troves\u002FSKILL.md",[],[],"2026-11-15 14:19:17",{"skillNo":99,"name":100,"nameZh":6,"description":101,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":92,"licenseFileUrl":102,"sourceHtmlUrl":103,"categories":104,"keywords":105,"publishedAt":97},"01M7DTK6CJSMGC8KCQHGNYFZBD","trade","Swap tokens on Starknet via Fibrous DEX aggregator. Supports per-provider selection (avnu, ekubo, or auto to race all). Use this skill when the user wants to swap, exchange, trade, convert, buy, or sell one token for another on Starknet. Also use when the user asks about token prices, exchange rates, DEX routing, best swap route, or wants to check how much they would receive for a given amount — even if they don't explicitly say \"swap\".","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fmcp-servers\u002Fahmetenesdur-trade\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fmcp-servers\u002Fahmetenesdur-trade\u002FSKILL.md",[],[],{"skillNo":107,"name":108,"nameZh":6,"description":109,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":92,"licenseFileUrl":110,"sourceHtmlUrl":111,"categories":112,"keywords":113,"publishedAt":97},"01M7DTJZ6A0X4PAW3Y8W4J9K64","staking","Stake, unstake, claim, and compound rewards for STRK, WBTC, tBTC, SolvBTC, and LBTC on Starknet. View validators, pools, and staking positions. Use this skill when the user mentions staking, delegating, validators, staking pools, rewards, compounding, unstaking, earning yield, passive income on crypto, or wants to earn on their STRK or BTC tokens — even if they don't say \"stake\" explicitly.","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fmcp-servers\u002Fahmetenesdur-staking\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fmcp-servers\u002Fahmetenesdur-staking\u002FSKILL.md",[],[],{"skillNo":115,"name":23,"nameZh":6,"description":116,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":92,"licenseFileUrl":117,"sourceHtmlUrl":118,"categories":119,"keywords":120,"publishedAt":97},"01M7DTJSDZJKCDMW7GHRF4BRH5","Send STRK, ETH, or any ERC-20 token to a Starknet address. Supports simulation (dry-run) before execution. Use this skill when the user wants to send, transfer, pay, tip, or move tokens to another wallet address on Starknet. Also trigger when the user mentions sending funds to someone, making a payment, transferring assets, or moving crypto to a specific address — even if they just say \"pay 10 STRK to 0x...\".","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fmcp-servers\u002Fahmetenesdur-send\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fmcp-servers\u002Fahmetenesdur-send\u002FSKILL.md",[],[],{"skillNo":122,"name":123,"nameZh":6,"description":124,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":92,"licenseFileUrl":125,"sourceHtmlUrl":126,"categories":127,"keywords":128,"publishedAt":97},"01M7DTJG1E480D51ZQ7WKDQ26K","portfolio","View a comprehensive DeFi portfolio dashboard and optimize portfolio allocation via automated rebalancing. Use this skill when the user wants an overview, summary, dashboard, total value, net worth, portfolio rebalancing, target allocation, or wants to see all their DeFi positions across Starknet at once. Also trigger when the user asks \"what do I have\", \"show me everything\", \"how much am I worth\", \"my positions\", \"my investments\", \"rebalance my portfolio\", \"I want 50% ETH\", \"optimize my holdings\", or any request for a holistic view of their Starknet holdings — even if they don't explicitly say \"portfolio\".","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fmcp-servers\u002Fahmetenesdur-portfolio\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fmcp-servers\u002Fahmetenesdur-portfolio\u002FSKILL.md",[],[],{"skillNo":130,"name":131,"nameZh":6,"description":132,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":92,"licenseFileUrl":133,"sourceHtmlUrl":134,"categories":135,"keywords":136,"publishedAt":97},"01M7DTJ7M8TE9R2N36HFBZDGVD","multi-swap","Execute multiple token swaps in a single Starknet transaction via Fibrous (default). Supports per-provider selection (avnu, ekubo, or auto to race all). Supports 2-3 swap pairs bundled into one multicall. Use this skill when the user wants to swap multiple token pairs at once, do batch swaps, execute several trades simultaneously, perform parallel swaps, or do bulk trading in one transaction. Also trigger when the user mentions \"two swaps\", \"three swaps\", \"swap X and Y at the same time\", or wants to convert multiple tokens in a single call.","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fmcp-servers\u002Fahmetenesdur-multi-swap\u002FLICENSE","https:\u002F\u002Fgithub.com\u002Fjiayaoqijia\u002Fcryptoskill\u002Fblob\u002Fmain\u002Fskills\u002Fmcp-servers\u002Fahmetenesdur-multi-swap\u002FSKILL.md",[],[]]