@anywalletkit/protocol-swap2-cctp

中文文档
0.5.1发布于 2026/11/05Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 2313

Circle CCTP V2 for the swap2 engine: native USDC between EVM chains by burn-and-mint (Fast Transfer or Standard), attestation via Circle's Iris API, two-phase delivery with the user's own receiveMessage claim. Bound to Circle's documented contracts and na

原始使用文档
文档目录5 节
  1. Install
  2. What the provider does
  3. Tests
  4. Status
  5. Activity

@anywalletkit/protocol-swap2-cctp

npm

Circle CCTP V2 as a swap2 provider: native USDC between EVM chains by burn-and-mint — no spread, no aggregator fee; Fast Transfer costs the fee Circle publishes per pair (around 1 bps), Standard is free and waits for source finality.

Install

npm install @anywalletkit/protocol-swap2-cctp @anywalletkit/core
# or: pnpm add @anywalletkit/protocol-swap2-cctp @anywalletkit/core  ·  yarn add @anywalletkit/protocol-swap2-cctp @anywalletkit/core

On npm: @anywalletkit/protocol-swap2-cctp, published from the release workflow with provenance.

CCTP is two-phase. depositForBurn on the source chain burns the USDC; Circle's attestation service signs the message; receiveMessage(message, attestation) on the destination mints — and that second transaction is the user's own, paid in the destination chain's gas. The swap2 engine learned this with the package:

import {cctpProvider} from "@anywalletkit/protocol-swap2-cctp/provider";
import {RouterSwap2Protocol} from "@anywalletkit/protocol-swap2-router/swap2/router";

const swap2 = new RouterSwap2Protocol(baseAccount, {fromChain: "eip155:8453", providers: [cctpProvider({rpcUrls})]});
const res = await swap2.swap2({fromToken: "USDC", toToken: "USDC", toChain: 42161, fromTokenAmount: 10_000_000n, minAmountOut: 9_998_570n});
// … poll …
const status = await swap2.getSwap2Status(res.id);   // "pending" → "action-required" once Circle attested
if (status.status === "action-required") {
  const claimed = await swap2.claimSwap2(res.id, arbitrumAccount);   // receiveMessage on Arbitrum, signed there
  await swap2.getSwap2Status(claimed.id);   // this id carries the claim hash and, once the account saw it succeed, "completed" even without an Arbitrum RPC
}

claimSwap2(id, destinationAccount) is on every swap2 protocol (router or single-provider); providers opt in with buildClaim(ref), which returns the destination transaction or null while the attestation is pending. IntentStatus.claim = {chain, ready} tells the app which chain the claim lives on. The remote provider forwards it as the claim action.

The engine sends a claim only to a contract the provider declares for that chain (claimTargets; CCTP: its MessageTransmitter) and refuses calldata that moves the account's tokens or grants an allowance. A remote stub takes the list from the app, never from the server:

remoteProvider({name: "cctp", baseUrl, ...cctpPins})   // cctpPins from this package: TokenMessenger + MessageTransmitter

cctpPins also pins the burn: the TokenMessenger is the only contract the source leg may call and approve, and cctpVerifyQuote decodes the server's depositForBurn on the device — the input amount, the destination domain, the recipient as mintRecipient, the source USDC, no destination caller, and a maxFee that leaves the quoted minimum. Without the pins the engine refuses the stub's EVM routes.

What the provider does

  • Mode auto (default) takes Fast when the pair offers it and Circle's Fast allowance covers the amount, else Standard; fast / standard force one. Fees come from GET /v2/burn/USDC/fees/{src}/{dst} (bps), the allowance from GET /v2/fastBurn/USDC/allowance.
  • Output is guaranteed: maxFee in the calldata = published fee + a 10 % buffer (feeBufferPct), and Circle can deduct at most maxFee; the quote's minDestAmount is amount − maxFee. The unused buffer is never charged.
  • Calldata is sealed in the quote (recipient, native USDC of the source domain, destination domain, maxFee, finality threshold) and the engine executes exactly that; approvalAddress is the TokenMessengerV2.
  • Preflight with an RPC (rpcUrls): the TokenMessengerV2 the calldata targets must point at the expected MessageTransmitterV2, whose localDomain() must be the source domain, and getMinFeeAmount(amount) must fit maxFee. Without an RPC the on-chain check is skipped.
  • Tracking: GET /v2/messages/{src}?transactionHash= → pending while confirmations accrue, action-required once status: complete with the attestation, completed once the destination's usedNonces(nonce) is set. Without the destination chain in rpcUrls, completed comes from the id claimSwap2 returns when the destination account's waitForTransaction saw the claim succeed (destTxConfirmed: a successful receiveMessage is the mint, since it reverts once the nonce is used); a bare claim hash stays pending, with the hash in destTxHash. A destination RPC that does not show the mint of a confirmed claim yet reads pending, not action-required.
  • Claim: receiveMessage(message, attestation) on the destination MessageTransmitterV2; the attested message must belong to the route's domains. An expired Fast message (expirationBlock passed) is sent to POST /v2/reattest/{nonce} and reported not-ready until Circle re-signs.
  • Domains: 17 EVM chains (Ethereum, Avalanche, OP, Arbitrum, Base, Polygon, Unichain, Linea, Sonic, World Chain, Monad, Sei, HyperEVM, Ink, Plume, Plasma, X Layer), the same TokenMessengerV2 / MessageTransmitterV2 on all of them, and each domain's native USDC. Chains whose catalog USDC is not Circle's (BSC, Gnosis USDC.e) are refused. Solana (domain 5) is not executed here yet: the engine runs calldata on EVM only.

Tests

pnpm test — provider tests over a fake Circle API + fake JSON-RPC (fee maths, calldata binding, mode fallbacks, preflight refusals, the whole pending → action-required → completed lifecycle, claim building, expiry / re-attestation) and the conformance suite; the engine's claimSwap2 has its own tests in protocol-swap2-core. pnpm verify:live quotes USDC Base → Arbitrum $10 in both modes against the live API and preflights on Base.

Status

2026-10-10: built, tests green, live quote + preflight verified. No funded transfer yet (plan: $10 USDC Base → Arbitrum, Fast and Standard, with the claim from the phone).

Activity

describeActivity(tx, ctx) (on the provider; the protocol class and the router delegate to it) recognizes both halves of a CCTP V2 transfer on every domain in config.ts, by contract + 4-byte selector:

CallContractKindTitle
depositForBurn(uint256,uint32,bytes32,address,bytes32,uint256,uint32) 0x8e0250eeTokenMessengerV2bridge"Bridged USDC"
receiveMessage(bytes,bytes) 0x57ecfd28MessageTransmitterV2bridge"Received USDC via CCTP"

Assets come from the owner's net transfers (the burn leaves the wallet; the mint lands on the mintRecipient even when a relayer paid the claim). Subtitle CCTP · <chain>, counterparty = the contract called. The other leg's hash is only known through the kit's intent journal / Circle's attestation API, so related stays empty. Fixtures in fixtures/activity/ are public Ethereum transactions (two burns, two claims) plus negatives (a LI.FI bridge, a THORChain deposit); the conformance suite runs them through describeActivity.

版本与发布记录

@anywalletkit/protocol-swap2-cctp 共发布 14 个版本,首次发布于 2026/10/25;过去 12 个月发布了 14 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.5.1latest2026/11/052 天前
0.5.02026/11/035 天前
0.4.02026/10/308 天前
0.3.12026/10/309 天前
0.3.02026/10/2910 天前
0.2.12026/10/2811 天前

关于 @anywalletkit/protocol-swap2-cctp 的常见问题

@anywalletkit/protocol-swap2-cctp 是什么?

Circle CCTP V2 for the swap2 engine: native USDC between EVM chains by burn-and-mint (Fast Transfer or Standard), attestation via Circle's Iris API, two-phase delivery with the user's own receiveMessage claim. Bound to Circle's documented contracts and na

如何安装 @anywalletkit/protocol-swap2-cctp?

在项目目录运行 npm install @anywalletkit/protocol-swap2-cctp,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@anywalletkit/core(0.8.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@anywalletkit/protocol-swap2-cctp 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@anywalletkit/protocol-swap2-cctp 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@anywalletkit/protocol-swap2-cctp 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@anywalletkit/protocol-swap2-cctp 可以商用吗?

@anywalletkit/protocol-swap2-cctp 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@anywalletkit/protocol-swap2-cctp 的下载量有多少?

根据 npm 官方下载统计,@anywalletkit/protocol-swap2-cctp 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,313 次,日均约 77 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@anywalletkit/protocol-swap2-cctp 还在维护吗?

最新版本 0.5.1 发布于 2026/11/05(2 天前);至今共发布 14 个版本,其中过去 12 个月发布了 14 个;首次发布于 2026/10/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。