agentwallet-sdk 2.4.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/bridge/__tests__/bridge.test.d.ts +2 -0
  2. package/dist/bridge/__tests__/bridge.test.d.ts.map +1 -0
  3. package/dist/bridge/__tests__/bridge.test.js +508 -0
  4. package/dist/bridge/__tests__/bridge.test.js.map +1 -0
  5. package/dist/bridge/abis.d.ts +187 -0
  6. package/dist/bridge/abis.d.ts.map +1 -0
  7. package/dist/bridge/abis.js +129 -0
  8. package/dist/bridge/abis.js.map +1 -0
  9. package/dist/bridge/client.d.ts +106 -0
  10. package/dist/bridge/client.d.ts.map +1 -0
  11. package/dist/bridge/client.js +393 -0
  12. package/dist/bridge/client.js.map +1 -0
  13. package/dist/bridge/index.d.ts +4 -0
  14. package/dist/bridge/index.d.ts.map +1 -0
  15. package/dist/bridge/index.js +4 -0
  16. package/dist/bridge/index.js.map +1 -0
  17. package/dist/bridge/types.d.ts +107 -0
  18. package/dist/bridge/types.d.ts.map +1 -0
  19. package/dist/bridge/types.js +58 -0
  20. package/dist/bridge/types.js.map +1 -0
  21. package/dist/index.d.ts +504 -213
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +7 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/swap/SwapModule.d.ts +75 -0
  26. package/dist/swap/SwapModule.d.ts.map +1 -0
  27. package/dist/swap/SwapModule.js +267 -0
  28. package/dist/swap/SwapModule.js.map +1 -0
  29. package/dist/swap/__tests__/swap.test.d.ts +2 -0
  30. package/dist/swap/__tests__/swap.test.d.ts.map +1 -0
  31. package/dist/swap/__tests__/swap.test.js +272 -0
  32. package/dist/swap/__tests__/swap.test.js.map +1 -0
  33. package/dist/swap/abi.d.ts +169 -0
  34. package/dist/swap/abi.d.ts.map +1 -0
  35. package/dist/swap/abi.js +118 -0
  36. package/dist/swap/abi.js.map +1 -0
  37. package/dist/swap/index.d.ts +5 -0
  38. package/dist/swap/index.d.ts.map +1 -0
  39. package/dist/swap/index.js +5 -0
  40. package/dist/swap/index.js.map +1 -0
  41. package/dist/swap/types.d.ts +79 -0
  42. package/dist/swap/types.d.ts.map +1 -0
  43. package/dist/swap/types.js +18 -0
  44. package/dist/swap/types.js.map +1 -0
  45. package/package.json +1 -1
@@ -0,0 +1,393 @@
1
+ // [MAX-ADDED] BridgeModule — CCTP V2 cross-chain USDC bridge for AgentWallet
2
+ // Supports: Base → Ethereum, Base → Optimism (extensible to any CCTP V2 chain)
3
+ //
4
+ // Architecture:
5
+ // 1. Approve USDC to TokenMessengerV2 on source chain (EOA-level signing)
6
+ // 2. Call depositForBurn → extracts MessageSent bytes + messageHash
7
+ // 3. Poll Circle IRIS API for attestation (~12s for fast, ~15min for finalized)
8
+ // 4. Call receiveMessage on destination MessageTransmitterV2 to mint USDC
9
+ //
10
+ // Non-custodial: all signing is done locally via the agent's WalletClient.
11
+ // No private keys ever leave the caller's environment.
12
+ import { createPublicClient, http, keccak256, pad, getContract, } from 'viem';
13
+ import { base, mainnet, optimism, arbitrum } from 'viem/chains';
14
+ import { TokenMessengerV2Abi, MessageTransmitterV2Abi, ERC20BridgeAbi, } from './abis.js';
15
+ import { CCTP_DOMAIN_IDS, BRIDGE_CHAIN_IDS, USDC_CONTRACT, TOKEN_MESSENGER_V2, MESSAGE_TRANSMITTER_V2, FINALITY_THRESHOLD, CIRCLE_ATTESTATION_API, MAX_ATTESTATION_POLLS, ATTESTATION_POLL_INTERVAL_MS, } from './types.js';
16
+ // Viem chain objects indexed by BridgeChain
17
+ const VIEM_CHAINS = {
18
+ base,
19
+ ethereum: mainnet,
20
+ optimism,
21
+ arbitrum,
22
+ };
23
+ /**
24
+ * BridgeModule — CCTP V2 cross-chain USDC bridge.
25
+ *
26
+ * Usage:
27
+ * ```ts
28
+ * const bridge = new BridgeModule(walletClient, 'base', { rpcUrl: '...' });
29
+ * const result = await bridge.bridge(1_000_000n, 'optimism');
30
+ * console.log('Minted on Optimism:', result.mintTxHash);
31
+ * ```
32
+ */
33
+ export class BridgeModule {
34
+ constructor(walletClient, fromChain = 'base', options = {}) {
35
+ if (!walletClient.account) {
36
+ throw new BridgeError('NO_WALLET_CLIENT', 'WalletClient must have an account attached. ' +
37
+ 'Use privateKeyToAccount() or similar to attach a signer.');
38
+ }
39
+ this.walletClient = walletClient;
40
+ this.fromChain = fromChain;
41
+ this.fromRpcUrl = options.rpcUrl;
42
+ this.publicClient = createPublicClient({
43
+ chain: VIEM_CHAINS[fromChain],
44
+ transport: http(options.rpcUrl),
45
+ });
46
+ }
47
+ // ─── Public API ───
48
+ /**
49
+ * Bridge USDC from the source chain to the destination chain.
50
+ *
51
+ * This is the primary method. It orchestrates the full CCTP V2 flow:
52
+ * approve → burn → attest → mint.
53
+ *
54
+ * @param amount - Amount in USDC base units (6 decimals). e.g. 1_000_000n = 1 USDC
55
+ * @param toChain - Destination chain ('ethereum' | 'optimism' | 'arbitrum')
56
+ * @param options - Optional overrides (finality, fees, destination address)
57
+ *
58
+ * @throws BridgeError with actionable message if anything fails
59
+ */
60
+ async bridge(amount, toChain, options = {}) {
61
+ const startMs = Date.now();
62
+ // 1. Validate inputs
63
+ this.validateBridgeParams(amount, toChain);
64
+ const account = this.walletClient.account;
65
+ const recipient = options.destinationAddress ?? account.address;
66
+ const minFinalityThreshold = options.minFinalityThreshold ?? FINALITY_THRESHOLD.FAST;
67
+ const maxFee = options.maxFee ?? 0n;
68
+ const attestationApiUrl = options.attestationApiUrl ?? CIRCLE_ATTESTATION_API;
69
+ // 2. Approve USDC to TokenMessengerV2 on source chain
70
+ await this.approveUsdc(amount);
71
+ // 3. Burn USDC on source chain
72
+ const burnResult = await this.depositForBurn(amount, toChain, recipient, minFinalityThreshold, maxFee);
73
+ // 4. Poll for Circle attestation
74
+ const attestation = await this.pollForAttestation(burnResult.messageHash, this.fromChain, attestationApiUrl);
75
+ // 5. Mint on destination chain
76
+ const mintTxHash = await this.receiveMessage(burnResult.messageBytes, attestation, toChain, options.destinationRpcUrl);
77
+ return {
78
+ burnTxHash: burnResult.burnTxHash,
79
+ mintTxHash,
80
+ amount,
81
+ fromChain: this.fromChain,
82
+ toChain,
83
+ recipient,
84
+ nonce: burnResult.nonce,
85
+ elapsedMs: Date.now() - startMs,
86
+ };
87
+ }
88
+ /**
89
+ * Step 1 of 3: Burn USDC on the source chain.
90
+ * Returns the burn result including message bytes needed for minting.
91
+ * Use this for manual/split-phase bridging.
92
+ */
93
+ async burn(amount, toChain, options = {}) {
94
+ this.validateBridgeParams(amount, toChain);
95
+ const account = this.walletClient.account;
96
+ const recipient = options.destinationAddress ?? account.address;
97
+ const minFinalityThreshold = options.minFinalityThreshold ?? FINALITY_THRESHOLD.FAST;
98
+ const maxFee = options.maxFee ?? 0n;
99
+ await this.approveUsdc(amount);
100
+ return this.depositForBurn(amount, toChain, recipient, minFinalityThreshold, maxFee);
101
+ }
102
+ /**
103
+ * Step 2 of 3: Poll Circle IRIS API for attestation.
104
+ * Returns the attestation bytes once Circle confirms the message.
105
+ */
106
+ async waitForAttestation(messageHash, apiUrl = CIRCLE_ATTESTATION_API) {
107
+ return this.pollForAttestation(messageHash, this.fromChain, apiUrl);
108
+ }
109
+ /**
110
+ * Step 3 of 3: Mint USDC on the destination chain using the attestation.
111
+ */
112
+ async mint(messageBytes, attestation, toChain, destinationRpcUrl) {
113
+ return this.receiveMessage(messageBytes, attestation, toChain, destinationRpcUrl);
114
+ }
115
+ /**
116
+ * Fetch the current USDC balance on the source chain for the signer's address.
117
+ */
118
+ async getUsdcBalance() {
119
+ const account = this.walletClient.account;
120
+ const usdc = getContract({
121
+ address: USDC_CONTRACT[this.fromChain],
122
+ abi: ERC20BridgeAbi,
123
+ client: this.publicClient,
124
+ });
125
+ return usdc.read.balanceOf([account.address]);
126
+ }
127
+ /**
128
+ * Fetch the current USDC allowance for the TokenMessengerV2 on source chain.
129
+ */
130
+ async getUsdcAllowance() {
131
+ const account = this.walletClient.account;
132
+ const usdc = getContract({
133
+ address: USDC_CONTRACT[this.fromChain],
134
+ abi: ERC20BridgeAbi,
135
+ client: this.publicClient,
136
+ });
137
+ return usdc.read.allowance([
138
+ account.address,
139
+ TOKEN_MESSENGER_V2[this.fromChain],
140
+ ]);
141
+ }
142
+ // ─── Internal Implementation ───
143
+ /**
144
+ * Approve TokenMessengerV2 to spend USDC on behalf of the signer.
145
+ * Skips if existing allowance is sufficient.
146
+ */
147
+ async approveUsdc(amount) {
148
+ const account = this.walletClient.account;
149
+ const spender = TOKEN_MESSENGER_V2[this.fromChain];
150
+ const usdcAddress = USDC_CONTRACT[this.fromChain];
151
+ // Check current allowance
152
+ const usdc = getContract({
153
+ address: usdcAddress,
154
+ abi: ERC20BridgeAbi,
155
+ client: this.publicClient,
156
+ });
157
+ const currentAllowance = await usdc.read.allowance([account.address, spender]);
158
+ if (currentAllowance >= amount) {
159
+ return; // Sufficient allowance, skip approve
160
+ }
161
+ // Execute approve
162
+ const usdcWrite = getContract({
163
+ address: usdcAddress,
164
+ abi: ERC20BridgeAbi,
165
+ client: { public: this.publicClient, wallet: this.walletClient },
166
+ });
167
+ const approveTxHash = await usdcWrite.write.approve([spender, amount], { account, chain: VIEM_CHAINS[this.fromChain] });
168
+ const approveReceipt = await this.publicClient.waitForTransactionReceipt({
169
+ hash: approveTxHash,
170
+ });
171
+ if (approveReceipt.status !== 'success') {
172
+ throw new BridgeError('INSUFFICIENT_ALLOWANCE', `USDC approve failed (tx: ${approveTxHash}). ` +
173
+ `Check that the account has sufficient gas and USDC on ${this.fromChain}.`);
174
+ }
175
+ }
176
+ /**
177
+ * Call TokenMessengerV2.depositForBurn and extract MessageSent data.
178
+ */
179
+ async depositForBurn(amount, toChain, recipient, minFinalityThreshold, maxFee) {
180
+ const account = this.walletClient.account;
181
+ const destinationDomain = CCTP_DOMAIN_IDS[toChain];
182
+ const messengerAddress = TOKEN_MESSENGER_V2[this.fromChain];
183
+ const usdcAddress = USDC_CONTRACT[this.fromChain];
184
+ // CCTP requires mintRecipient as a 32-byte left-padded address
185
+ const mintRecipient = pad(recipient, { size: 32 });
186
+ // destinationCaller = bytes32(0) means anyone can call receiveMessage
187
+ const destinationCaller = pad('0x0', { size: 32 });
188
+ const messenger = getContract({
189
+ address: messengerAddress,
190
+ abi: TokenMessengerV2Abi,
191
+ client: { public: this.publicClient, wallet: this.walletClient },
192
+ });
193
+ let burnTxHash;
194
+ try {
195
+ burnTxHash = await messenger.write.depositForBurn([
196
+ amount,
197
+ destinationDomain,
198
+ mintRecipient,
199
+ usdcAddress,
200
+ destinationCaller,
201
+ maxFee,
202
+ minFinalityThreshold,
203
+ ], { account, chain: VIEM_CHAINS[this.fromChain] });
204
+ }
205
+ catch (err) {
206
+ const msg = err instanceof Error ? err.message : String(err);
207
+ throw new BridgeError('BURN_FAILED', `CCTP depositForBurn failed: ${msg}. ` +
208
+ `Ensure the wallet has sufficient USDC and ETH for gas on ${this.fromChain}.`);
209
+ }
210
+ const receipt = await this.publicClient.waitForTransactionReceipt({
211
+ hash: burnTxHash,
212
+ });
213
+ if (receipt.status !== 'success') {
214
+ throw new BridgeError('BURN_FAILED', `depositForBurn transaction reverted (tx: ${burnTxHash}). ` +
215
+ `Check USDC balance, allowance, and gas on ${this.fromChain}.`);
216
+ }
217
+ // Extract MessageSent event from the receipt logs
218
+ const { messageBytes, messageHash, nonce } = this.extractMessageSent(receipt);
219
+ return {
220
+ burnTxHash,
221
+ nonce,
222
+ messageHash,
223
+ messageBytes,
224
+ sourceDomain: CCTP_DOMAIN_IDS[this.fromChain],
225
+ destinationDomain,
226
+ };
227
+ }
228
+ /**
229
+ * Extract the CCTP MessageSent event from a transaction receipt.
230
+ * The MessageTransmitter emits this event during depositForBurn.
231
+ */
232
+ extractMessageSent(receipt) {
233
+ // MessageSent event topic: keccak256("MessageSent(bytes)")
234
+ const MESSAGE_SENT_TOPIC = '0x8c5261668696ce22758910d05bab8f186d6eb247ceac2af2e82c7dc17669b036';
235
+ for (const log of receipt.logs) {
236
+ if (log.topics[0]?.toLowerCase() === MESSAGE_SENT_TOPIC.toLowerCase()) {
237
+ // The message bytes are ABI-encoded in the log data
238
+ // Format: bytes32 offset (0x20) + bytes32 length + data
239
+ const rawData = log.data;
240
+ // Decode: first 32 bytes = offset, next 32 bytes = length, rest = message
241
+ if (rawData.length < 130)
242
+ continue; // sanity check (0x + 64 hex chars minimum)
243
+ // Parse length from bytes 32-63 (offset 64-127 in hex string)
244
+ const dataHex = rawData.slice(2); // remove 0x
245
+ const lengthHex = dataHex.slice(64, 128); // bytes 32-64
246
+ const messageLength = parseInt(lengthHex, 16);
247
+ if (messageLength === 0)
248
+ continue;
249
+ // Extract message bytes
250
+ const messageBytesHex = dataHex.slice(128, 128 + messageLength * 2);
251
+ const messageBytes = ('0x' + messageBytesHex);
252
+ const messageHash = keccak256(messageBytes);
253
+ // Extract nonce from message bytes (bytes 12-19, after version[4] + sourceDomain[4] + destDomain[4])
254
+ const nonceBytesHex = messageBytesHex.slice(24, 40); // bytes 12-20
255
+ const nonce = BigInt('0x' + nonceBytesHex);
256
+ return { messageBytes, messageHash, nonce };
257
+ }
258
+ }
259
+ throw new BridgeError('BURN_FAILED', 'Could not find MessageSent event in burn transaction receipt. ' +
260
+ 'The transaction may have succeeded but CCTP message was not emitted. ' +
261
+ 'Check the transaction on the block explorer.');
262
+ }
263
+ /**
264
+ * Poll the Circle IRIS API until the attestation is ready.
265
+ * Fast finality: ~12 seconds. Full finality: ~15 minutes on Ethereum.
266
+ */
267
+ async pollForAttestation(messageHash, fromChain, apiUrl) {
268
+ const sourceDomain = CCTP_DOMAIN_IDS[fromChain];
269
+ // Circle V2 API: GET /v2/messages/{sourceDomain}?transactionHash={hash}
270
+ // Note: messageHash and txHash can both be used; we'll use messageHash for direct lookup
271
+ const url = `${apiUrl}/v2/messages/${sourceDomain}/${messageHash}`;
272
+ for (let attempt = 0; attempt < MAX_ATTESTATION_POLLS; attempt++) {
273
+ let response;
274
+ try {
275
+ const res = await fetch(url, {
276
+ headers: { 'Accept': 'application/json' },
277
+ });
278
+ if (!res.ok) {
279
+ if (res.status === 404) {
280
+ // Not yet indexed — keep polling
281
+ await this.sleep(ATTESTATION_POLL_INTERVAL_MS);
282
+ continue;
283
+ }
284
+ const body = await res.text().catch(() => '');
285
+ throw new BridgeError('ATTESTATION_ERROR', `Circle API returned HTTP ${res.status}: ${body}. ` +
286
+ `URL: ${url}. Check Circle API status at status.circle.com.`);
287
+ }
288
+ response = await res.json();
289
+ }
290
+ catch (err) {
291
+ if (err instanceof BridgeError)
292
+ throw err;
293
+ const msg = err instanceof Error ? err.message : String(err);
294
+ throw new BridgeError('ATTESTATION_ERROR', `Failed to reach Circle IRIS API: ${msg}. ` +
295
+ `Ensure network connectivity and try again.`);
296
+ }
297
+ if (response.status === 'complete' && response.attestation) {
298
+ return response.attestation;
299
+ }
300
+ if (response.status === 'error') {
301
+ throw new BridgeError('ATTESTATION_ERROR', `Circle attestation failed: ${response.error ?? 'unknown error'}. ` +
302
+ `Message hash: ${messageHash}. Contact Circle support if this persists.`);
303
+ }
304
+ // Status is 'pending_confirmations' — keep waiting
305
+ await this.sleep(ATTESTATION_POLL_INTERVAL_MS);
306
+ }
307
+ throw new BridgeError('ATTESTATION_TIMEOUT', `Attestation not received after ${MAX_ATTESTATION_POLLS} attempts ` +
308
+ `(${(MAX_ATTESTATION_POLLS * ATTESTATION_POLL_INTERVAL_MS) / 1000}s). ` +
309
+ `Message hash: ${messageHash}. You can retry by calling mint() manually with the message bytes.`);
310
+ }
311
+ /**
312
+ * Call MessageTransmitterV2.receiveMessage on the destination chain to mint USDC.
313
+ */
314
+ async receiveMessage(messageBytes, attestation, toChain, destinationRpcUrl) {
315
+ const account = this.walletClient.account;
316
+ const transmitterAddress = MESSAGE_TRANSMITTER_V2[toChain];
317
+ const destChain = VIEM_CHAINS[toChain];
318
+ const destPublicClient = createPublicClient({
319
+ chain: destChain,
320
+ transport: http(destinationRpcUrl),
321
+ });
322
+ const transmitter = getContract({
323
+ address: transmitterAddress,
324
+ abi: MessageTransmitterV2Abi,
325
+ client: { public: destPublicClient, wallet: this.walletClient },
326
+ });
327
+ let mintTxHash;
328
+ try {
329
+ mintTxHash = await transmitter.write.receiveMessage([messageBytes, attestation], { account, chain: destChain });
330
+ }
331
+ catch (err) {
332
+ const msg = err instanceof Error ? err.message : String(err);
333
+ throw new BridgeError('MINT_FAILED', `CCTP receiveMessage failed on ${toChain}: ${msg}. ` +
334
+ `Ensure the wallet has sufficient ETH for gas on ${toChain}.`);
335
+ }
336
+ const mintReceipt = await destPublicClient.waitForTransactionReceipt({
337
+ hash: mintTxHash,
338
+ });
339
+ if (mintReceipt.status !== 'success') {
340
+ throw new BridgeError('MINT_FAILED', `receiveMessage reverted on ${toChain} (tx: ${mintTxHash}). ` +
341
+ `The message may have already been used (nonce replay). ` +
342
+ `Check ${toChain} block explorer for details.`);
343
+ }
344
+ return mintTxHash;
345
+ }
346
+ // ─── Validation ───
347
+ validateBridgeParams(amount, toChain) {
348
+ if (amount <= 0n) {
349
+ throw new BridgeError('INVALID_AMOUNT', `Bridge amount must be greater than 0. ` +
350
+ `Received: ${amount}. Amount is in USDC base units (6 decimals): 1 USDC = 1_000_000.`);
351
+ }
352
+ if (!(toChain in CCTP_DOMAIN_IDS)) {
353
+ const supported = Object.keys(CCTP_DOMAIN_IDS).join(', ');
354
+ throw new BridgeError('UNSUPPORTED_CHAIN', `Chain '${toChain}' is not supported. Supported chains: ${supported}. ` +
355
+ `To add a new chain, submit a PR to the agentwallet-sdk repository.`);
356
+ }
357
+ if (toChain === this.fromChain) {
358
+ throw new BridgeError('UNSUPPORTED_CHAIN', `Source and destination chains must be different. ` +
359
+ `Both are set to '${toChain}'. Choose a different destination chain.`);
360
+ }
361
+ }
362
+ // ─── Utilities ───
363
+ sleep(ms) {
364
+ return new Promise((resolve) => setTimeout(resolve, ms));
365
+ }
366
+ }
367
+ // ─── BridgeError ───
368
+ /**
369
+ * Structured bridge error with actionable messages and error codes.
370
+ */
371
+ export class BridgeError extends Error {
372
+ constructor(code, message) {
373
+ super(`[BridgeModule:${code}] ${message}`);
374
+ this.code = code;
375
+ this.name = 'BridgeError';
376
+ }
377
+ }
378
+ // ─── Factory Helper ───
379
+ /**
380
+ * Create a BridgeModule from an existing AgentWallet object.
381
+ * Convenience wrapper for wallet.bridge() integration.
382
+ *
383
+ * @example
384
+ * ```ts
385
+ * const bridge = createBridge(wallet.walletClient, 'base', { rpcUrl: BASE_RPC });
386
+ * const result = await bridge.bridge(5_000_000n, 'optimism');
387
+ * ```
388
+ */
389
+ export function createBridge(walletClient, fromChain = 'base', options = {}) {
390
+ return new BridgeModule(walletClient, fromChain, options);
391
+ }
392
+ export { CCTP_DOMAIN_IDS, BRIDGE_CHAIN_IDS, USDC_CONTRACT, TOKEN_MESSENGER_V2, MESSAGE_TRANSMITTER_V2, FINALITY_THRESHOLD, };
393
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/bridge/client.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,+EAA+E;AAC/E,EAAE;AACF,gBAAgB;AAChB,4EAA4E;AAC5E,sEAAsE;AACtE,kFAAkF;AAClF,4EAA4E;AAC5E,EAAE;AACF,2EAA2E;AAC3E,uDAAuD;AAEvD,OAAO,EACL,kBAAkB,EAElB,IAAI,EACJ,SAAS,EACT,GAAG,EACH,WAAW,GAQZ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,cAAc,GAEf,MAAM,WAAW,CAAC;AASnB,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,4BAA4B,GAC7B,MAAM,YAAY,CAAC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AO,0CAA0C,CACtE,CAAC;QACJ,CAAC;IACH,CAAC;IAED,oBAAoB;IAEZ,KAAK,CAAC,EAAU;QACtB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;CACF;AAED,sBAAsB;AAEtB;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,YACkB,IAAY,EAC5B,OAAe;QAEf,KAAK,CAAC,iBAAiB,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;QAH3B,SAAI,GAAJ,IAAI,CAAQ;QAI5B,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED,yBAAyB;AAEzB;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAC1B,YAA0B,EAC1B,YAAyB,MAAM,EAC/B,UAA+B,EAAE;IAEjC,OAAO,IAAI,YAAY,CAAC,YAAY,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AAC5D,CAAC;AAID,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,GACnB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { BridgeModule, BridgeError, createBridge, CCTP_DOMAIN_IDS, BRIDGE_CHAIN_IDS, USDC_CONTRACT, TOKEN_MESSENGER_V2, MESSAGE_TRANSMITTER_V2, FINALITY_THRESHOLD, } from './client.js';
2
+ export type { BridgeChain, BridgeOptions, BurnResult, BridgeResult, AttestationResponse, AttestationStatus, } from './types.js';
3
+ export { TokenMessengerV2Abi, MessageTransmitterV2Abi, ERC20BridgeAbi } from './abis.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bridge/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,WAAW,EACX,aAAa,EACb,UAAU,EACV,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,4 @@
1
+ // [MAX-ADDED] Bridge Module — CCTP V2 Cross-Chain USDC Bridge for AgentWallet
2
+ export { BridgeModule, BridgeError, createBridge, CCTP_DOMAIN_IDS, BRIDGE_CHAIN_IDS, USDC_CONTRACT, TOKEN_MESSENGER_V2, MESSAGE_TRANSMITTER_V2, FINALITY_THRESHOLD, } from './client.js';
3
+ export { TokenMessengerV2Abi, MessageTransmitterV2Abi, ERC20BridgeAbi } from './abis.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bridge/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,OAAO,EACL,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAWrB,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,107 @@
1
+ import type { Address, Hash, Hex } from 'viem';
2
+ /** Supported bridge destination chains */
3
+ export type BridgeChain = 'ethereum' | 'optimism' | 'base' | 'arbitrum';
4
+ /** CCTP V2 domain IDs (Circle's internal chain identifiers) */
5
+ export declare const CCTP_DOMAIN_IDS: Record<BridgeChain, number>;
6
+ /** EVM chain IDs for supported bridge chains */
7
+ export declare const BRIDGE_CHAIN_IDS: Record<BridgeChain, number>;
8
+ /** USDC contract addresses per chain */
9
+ export declare const USDC_CONTRACT: Record<BridgeChain, Address>;
10
+ /**
11
+ * CCTP V2 TokenMessengerV2 addresses (source chain — where burn happens).
12
+ * Base address confirmed per task spec. Other chains are CCTP V2 deployment addresses
13
+ * (verify against https://developers.circle.com/stablecoins/cctp-protocol-contract before mainnet use).
14
+ */
15
+ export declare const TOKEN_MESSENGER_V2: Record<BridgeChain, Address>;
16
+ /** CCTP V2 MessageTransmitterV2 addresses (destination chain — where mint happens) */
17
+ export declare const MESSAGE_TRANSMITTER_V2: Record<BridgeChain, Address>;
18
+ /**
19
+ * CCTP V2 minFinalityThreshold values.
20
+ * - FAST (0): ~12 seconds. Circle fast attestation. Use for most agent workflows.
21
+ * - FINALIZED (1000): Full on-chain finality. Use for large amounts.
22
+ */
23
+ export declare const FINALITY_THRESHOLD: {
24
+ readonly FAST: 0;
25
+ readonly FINALIZED: 1000;
26
+ };
27
+ /** Circle IRIS attestation API base URL */
28
+ export declare const CIRCLE_ATTESTATION_API = "https://iris-api.circle.com";
29
+ /** Max attestation polling attempts before timeout */
30
+ export declare const MAX_ATTESTATION_POLLS = 60;
31
+ /** Polling interval for attestation (milliseconds) */
32
+ export declare const ATTESTATION_POLL_INTERVAL_MS = 5000;
33
+ /** Options for a bridge operation */
34
+ export interface BridgeOptions {
35
+ /**
36
+ * Minimum finality threshold.
37
+ * - 0 (FAST): ~12 seconds using Circle's fast attestation
38
+ * - 1000 (FINALIZED): Full finality (slower but more secure)
39
+ * @default 0 (fast finality)
40
+ */
41
+ minFinalityThreshold?: number;
42
+ /**
43
+ * Maximum fee in USDC base units (6 decimals).
44
+ * Circle uses this as an upper bound for bridging fee.
45
+ * @default 0n (no max fee limit)
46
+ */
47
+ maxFee?: bigint;
48
+ /**
49
+ * Optional override for the destination address.
50
+ * Defaults to the same address as the source wallet.
51
+ */
52
+ destinationAddress?: Address;
53
+ /**
54
+ * RPC URL for the destination chain.
55
+ * Required when minting on destination.
56
+ */
57
+ destinationRpcUrl?: string;
58
+ /**
59
+ * Circle attestation API override (for testing).
60
+ */
61
+ attestationApiUrl?: string;
62
+ }
63
+ /** Result of a bridge.burn() operation */
64
+ export interface BurnResult {
65
+ /** Transaction hash of the burn tx on source chain */
66
+ burnTxHash: Hash;
67
+ /** CCTP nonce for tracking */
68
+ nonce: bigint;
69
+ /** The CCTP message hash (used to fetch attestation) */
70
+ messageHash: Hex;
71
+ /** Raw CCTP message bytes emitted in the MessageSent event */
72
+ messageBytes: Hex;
73
+ /** Source chain domain ID */
74
+ sourceDomain: number;
75
+ /** Destination chain domain ID */
76
+ destinationDomain: number;
77
+ }
78
+ /** Circle attestation status */
79
+ export type AttestationStatus = 'pending_confirmations' | 'complete' | 'error';
80
+ /** Circle IRIS API response for an attestation */
81
+ export interface AttestationResponse {
82
+ status: AttestationStatus;
83
+ attestation: Hex | null;
84
+ error?: string;
85
+ }
86
+ /** Result of the full bridge() operation */
87
+ export interface BridgeResult {
88
+ /** Transaction hash of the burn on source chain */
89
+ burnTxHash: Hash;
90
+ /** Transaction hash of the mint on destination chain */
91
+ mintTxHash: Hash;
92
+ /** Amount bridged in USDC base units (6 decimals) */
93
+ amount: bigint;
94
+ /** Source chain name */
95
+ fromChain: BridgeChain;
96
+ /** Destination chain name */
97
+ toChain: BridgeChain;
98
+ /** Recipient address on destination chain */
99
+ recipient: Address;
100
+ /** CCTP nonce */
101
+ nonce: bigint;
102
+ /** Total time in milliseconds from burn to mint */
103
+ elapsedMs: number;
104
+ }
105
+ /** Error codes for actionable bridge error messages */
106
+ export type BridgeErrorCode = 'UNSUPPORTED_CHAIN' | 'INSUFFICIENT_ALLOWANCE' | 'INSUFFICIENT_BALANCE' | 'BURN_FAILED' | 'ATTESTATION_TIMEOUT' | 'ATTESTATION_ERROR' | 'MINT_FAILED' | 'INVALID_AMOUNT' | 'NO_WALLET_CLIENT';
107
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":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B,sDAAsD;IACtD,UAAU,EAAE,IAAI,CAAC;IACjB,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,WAAW,EAAE,GAAG,CAAC;IACjB,8DAA8D;IAC9D,YAAY,EAAE,GAAG,CAAC;IAClB,6BAA6B;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,gCAAgC;AAChC,MAAM,MAAM,iBAAiB,GAAG,uBAAuB,GAAG,UAAU,GAAG,OAAO,CAAC;AAE/E,kDAAkD;AAClD,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,WAAW,EAAE,GAAG,GAAG,IAAI,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,4CAA4C;AAC5C,MAAM,WAAW,YAAY;IAC3B,mDAAmD;IACnD,UAAU,EAAE,IAAI,CAAC;IACjB,wDAAwD;IACxD,UAAU,EAAE,IAAI,CAAC;IACjB,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;IACf,wBAAwB;IACxB,SAAS,EAAE,WAAW,CAAC;IACvB,6BAA6B;IAC7B,OAAO,EAAE,WAAW,CAAC;IACrB,6CAA6C;IAC7C,SAAS,EAAE,OAAO,CAAC;IACnB,iBAAiB;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,uDAAuD;AACvD,MAAM,MAAM,eAAe,GACvB,mBAAmB,GACnB,wBAAwB,GACxB,sBAAsB,GACtB,aAAa,GACb,qBAAqB,GACrB,mBAAmB,GACnB,aAAa,GACb,gBAAgB,GAChB,kBAAkB,CAAC"}
@@ -0,0 +1,58 @@
1
+ /** CCTP V2 domain IDs (Circle's internal chain identifiers) */
2
+ export const CCTP_DOMAIN_IDS = {
3
+ ethereum: 0,
4
+ optimism: 2,
5
+ arbitrum: 3,
6
+ base: 6,
7
+ };
8
+ /** EVM chain IDs for supported bridge chains */
9
+ export const BRIDGE_CHAIN_IDS = {
10
+ ethereum: 1,
11
+ optimism: 10,
12
+ arbitrum: 42161,
13
+ base: 8453,
14
+ };
15
+ // ─── CCTP V2 Contract Addresses ───
16
+ /** USDC contract addresses per chain */
17
+ export const USDC_CONTRACT = {
18
+ base: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
19
+ ethereum: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
20
+ optimism: '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85',
21
+ arbitrum: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
22
+ };
23
+ /**
24
+ * CCTP V2 TokenMessengerV2 addresses (source chain — where burn happens).
25
+ * Base address confirmed per task spec. Other chains are CCTP V2 deployment addresses
26
+ * (verify against https://developers.circle.com/stablecoins/cctp-protocol-contract before mainnet use).
27
+ */
28
+ export const TOKEN_MESSENGER_V2 = {
29
+ base: '0x8FD3bCdFd9987D7F3C86b67D2f25Dd4e82C80b2B',
30
+ ethereum: '0xbd3fa81b58ba92a82136038b25adec7066af3155',
31
+ optimism: '0x28Bc09B4EFdA1E348a97cA91F16CC43adFF2f50d',
32
+ arbitrum: '0x19330d10D9Cc8751218eaf51E8885D058642E08A',
33
+ };
34
+ /** CCTP V2 MessageTransmitterV2 addresses (destination chain — where mint happens) */
35
+ export const MESSAGE_TRANSMITTER_V2 = {
36
+ base: '0xE737e5cEBEEBa77EFE7EcB0cd46C6b9c1Ce1e8b3',
37
+ ethereum: '0xE737e5cEBEEBa77EFE7EcB0cd46C6b9c1Ce1e8b3',
38
+ optimism: '0xE737e5cEBEEBa77EFE7EcB0cd46C6b9c1Ce1e8b3',
39
+ arbitrum: '0xE737e5cEBEEBa77EFE7EcB0cd46C6b9c1Ce1e8b3',
40
+ };
41
+ // ─── CCTP V2 Finality Thresholds ───
42
+ /**
43
+ * CCTP V2 minFinalityThreshold values.
44
+ * - FAST (0): ~12 seconds. Circle fast attestation. Use for most agent workflows.
45
+ * - FINALIZED (1000): Full on-chain finality. Use for large amounts.
46
+ */
47
+ export const FINALITY_THRESHOLD = {
48
+ FAST: 0,
49
+ FINALIZED: 1000,
50
+ };
51
+ // ─── Circle Attestation API ───
52
+ /** Circle IRIS attestation API base URL */
53
+ export const CIRCLE_ATTESTATION_API = 'https://iris-api.circle.com';
54
+ /** Max attestation polling attempts before timeout */
55
+ export const MAX_ATTESTATION_POLLS = 60;
56
+ /** Polling interval for attestation (milliseconds) */
57
+ export const ATTESTATION_POLL_INTERVAL_MS = 5000;
58
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/bridge/types.ts"],"names":[],"mappings":"AAQA,+DAA+D;AAC/D,MAAM,CAAC,MAAM,eAAe,GAAgC;IAC1D,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC;IACX,IAAI,EAAE,CAAC;CACC,CAAC;AAEX,gDAAgD;AAChD,MAAM,CAAC,MAAM,gBAAgB,GAAgC;IAC3D,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,EAAE;IACZ,QAAQ,EAAE,KAAK;IACf,IAAI,EAAE,IAAI;CACF,CAAC;AAEX,qCAAqC;AAErC,wCAAwC;AACxC,MAAM,CAAC,MAAM,aAAa,GAAiC;IACzD,IAAI,EAAE,4CAA4C;IAClD,QAAQ,EAAE,4CAA4C;IACtD,QAAQ,EAAE,4CAA4C;IACtD,QAAQ,EAAE,4CAA4C;CAC9C,CAAC;AAEX;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAiC;IAC9D,IAAI,EAAE,4CAA4C;IAClD,QAAQ,EAAE,4CAA4C;IACtD,QAAQ,EAAE,4CAA4C;IACtD,QAAQ,EAAE,4CAA4C;CAC9C,CAAC;AAEX,sFAAsF;AACtF,MAAM,CAAC,MAAM,sBAAsB,GAAiC;IACl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