@continuumdao/ctm-mpc-defi 0.2.16 → 0.2.17

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.
@@ -0,0 +1,1026 @@
1
+ import { parseAbi, getAddress, formatUnits, parseUnits, defineChain, createPublicClient, http, pad, encodeFunctionData, parseGwei, serializeTransaction, keccak256 } from 'viem';
2
+ import { fetchChainFeeParams, gasLimitFromEstimateAndChainConfig, gweiToDecimalString, proposalTxParamsToFeeSnapshot, alignEip1559FeesWithLatestBase, getClientIdFromKeyGenResult } from '@continuumdao/continuum-node-sdk';
3
+
4
+ // src/core/registry.ts
5
+ var modules = [];
6
+ function registerProtocolModule(mod) {
7
+ const existing = modules.findIndex((m) => m.id === mod.id);
8
+ if (existing >= 0) {
9
+ modules[existing] = mod;
10
+ } else {
11
+ modules.push(mod);
12
+ }
13
+ }
14
+
15
+ // src/protocols/evm/circle-cctp/constants.ts
16
+ var CIRCLE_CCTP_PROTOCOL_ID = "circle-cctp";
17
+ var IRIS_API_MAINNET = "https://iris-api.circle.com";
18
+ var IRIS_API_SANDBOX = "https://iris-api-sandbox.circle.com";
19
+ var TOKEN_MESSENGER_V2_MAINNET = "0x28b5a0e9C621a5BadaA536219b3a228C8168cf5d";
20
+ var TOKEN_MESSENGER_V2_TESTNET = "0x8FE6B999Dc680CcFDD5Bf7EB0974218be2542DAA";
21
+ var FORWARDING_SERVICE_HOOK_DATA = "0x636374702d666f72776172640000000000000000000000000000000000000000";
22
+ var CCTP_DEFAULT_MIN_FINALITY_THRESHOLD = 1e3;
23
+ var CCTP_USDC_DECIMALS = 6;
24
+ var CCTP_ERC20_APPROVE_FALLBACK_GAS = 100000n;
25
+ var CCTP_DEPOSIT_FOR_BURN_FALLBACK_GAS = 350000n;
26
+ var CCTP_EVM_CHAINS = [
27
+ {
28
+ chainId: 1,
29
+ domain: 0,
30
+ network: "mainnet",
31
+ usdc: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
32
+ tokenMessenger: TOKEN_MESSENGER_V2_MAINNET,
33
+ label: "Ethereum"
34
+ },
35
+ {
36
+ chainId: 43114,
37
+ domain: 1,
38
+ network: "mainnet",
39
+ usdc: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
40
+ tokenMessenger: TOKEN_MESSENGER_V2_MAINNET,
41
+ label: "Avalanche"
42
+ },
43
+ {
44
+ chainId: 10,
45
+ domain: 2,
46
+ network: "mainnet",
47
+ usdc: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
48
+ tokenMessenger: TOKEN_MESSENGER_V2_MAINNET,
49
+ label: "OP Mainnet"
50
+ },
51
+ {
52
+ chainId: 42161,
53
+ domain: 3,
54
+ network: "mainnet",
55
+ usdc: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
56
+ tokenMessenger: TOKEN_MESSENGER_V2_MAINNET,
57
+ label: "Arbitrum"
58
+ },
59
+ {
60
+ chainId: 8453,
61
+ domain: 6,
62
+ network: "mainnet",
63
+ usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
64
+ tokenMessenger: TOKEN_MESSENGER_V2_MAINNET,
65
+ label: "Base"
66
+ },
67
+ {
68
+ chainId: 137,
69
+ domain: 7,
70
+ network: "mainnet",
71
+ usdc: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
72
+ tokenMessenger: TOKEN_MESSENGER_V2_MAINNET,
73
+ label: "Polygon PoS"
74
+ },
75
+ {
76
+ chainId: 11155111,
77
+ domain: 0,
78
+ network: "testnet",
79
+ usdc: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238",
80
+ tokenMessenger: TOKEN_MESSENGER_V2_TESTNET,
81
+ label: "Ethereum Sepolia"
82
+ },
83
+ {
84
+ chainId: 43113,
85
+ domain: 1,
86
+ network: "testnet",
87
+ usdc: "0x5425890298aed601595a70AB815c96711a31Bc65",
88
+ tokenMessenger: TOKEN_MESSENGER_V2_TESTNET,
89
+ label: "Avalanche Fuji"
90
+ },
91
+ {
92
+ chainId: 11155420,
93
+ domain: 2,
94
+ network: "testnet",
95
+ usdc: "0x5fd84259d66Cd46123540766Be93DFE6D43130D7",
96
+ tokenMessenger: TOKEN_MESSENGER_V2_TESTNET,
97
+ label: "OP Sepolia"
98
+ },
99
+ {
100
+ chainId: 421614,
101
+ domain: 3,
102
+ network: "testnet",
103
+ usdc: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d",
104
+ tokenMessenger: TOKEN_MESSENGER_V2_TESTNET,
105
+ label: "Arbitrum Sepolia"
106
+ },
107
+ {
108
+ chainId: 84532,
109
+ domain: 6,
110
+ network: "testnet",
111
+ usdc: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
112
+ tokenMessenger: TOKEN_MESSENGER_V2_TESTNET,
113
+ label: "Base Sepolia"
114
+ },
115
+ {
116
+ chainId: 80002,
117
+ domain: 7,
118
+ network: "testnet",
119
+ usdc: "0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582",
120
+ tokenMessenger: TOKEN_MESSENGER_V2_TESTNET,
121
+ label: "Polygon Amoy"
122
+ }
123
+ ];
124
+ function cctpChainConfig(chainId) {
125
+ return CCTP_EVM_CHAINS.find((c) => c.chainId === chainId) ?? null;
126
+ }
127
+ function parseCctpEvmChainId(chainId) {
128
+ if (typeof chainId === "number") {
129
+ return Number.isFinite(chainId) ? chainId : Number.NaN;
130
+ }
131
+ const t = String(chainId).trim();
132
+ if (!t) return Number.NaN;
133
+ const low = t.toLowerCase();
134
+ if (low.startsWith("eip155:")) {
135
+ const n2 = Number.parseInt(t.slice("eip155:".length).trim(), 10);
136
+ return Number.isFinite(n2) ? n2 : Number.NaN;
137
+ }
138
+ if (low.startsWith("0x")) {
139
+ const n2 = Number.parseInt(t, 16);
140
+ return Number.isFinite(n2) ? n2 : Number.NaN;
141
+ }
142
+ const n = Number.parseInt(t, 10);
143
+ return Number.isFinite(n) ? n : Number.NaN;
144
+ }
145
+ function isCctpSourceChainSupported(chainId) {
146
+ const n = parseCctpEvmChainId(chainId);
147
+ return Number.isFinite(n) && cctpChainConfig(n) != null;
148
+ }
149
+ function cctpCanonicalUsdcAddress(chainId) {
150
+ const n = parseCctpEvmChainId(chainId);
151
+ if (!Number.isFinite(n)) return null;
152
+ const raw = cctpChainConfig(n)?.usdc;
153
+ if (!raw) return null;
154
+ try {
155
+ return getAddress(raw);
156
+ } catch {
157
+ return null;
158
+ }
159
+ }
160
+ function isCctpCanonicalUsdcRow(chainId, contractAddress) {
161
+ const n = parseCctpEvmChainId(chainId);
162
+ if (!Number.isFinite(n)) return false;
163
+ const canonical = cctpCanonicalUsdcAddress(n);
164
+ if (!canonical) return false;
165
+ try {
166
+ return getAddress(contractAddress).toLowerCase() === canonical.toLowerCase();
167
+ } catch {
168
+ return false;
169
+ }
170
+ }
171
+ function chainIdToDomain(chainId) {
172
+ return cctpChainConfig(chainId)?.domain ?? null;
173
+ }
174
+ function domainToChainId(domain, network) {
175
+ const row = CCTP_EVM_CHAINS.find((c) => c.domain === domain && c.network === network);
176
+ return row?.chainId ?? null;
177
+ }
178
+ function isCctpRouteSupported(sourceChainId, destChainId) {
179
+ const src = cctpChainConfig(sourceChainId);
180
+ const dst = cctpChainConfig(destChainId);
181
+ if (!src || !dst) return false;
182
+ if (src.network !== dst.network) return false;
183
+ if (src.chainId === dst.chainId) return false;
184
+ return true;
185
+ }
186
+ function irisApiBaseForChainId(chainId) {
187
+ const cfg = cctpChainConfig(chainId);
188
+ if (!cfg) throw new Error(`Chain ${chainId} is not a supported CCTP EVM chain.`);
189
+ return cfg.network === "mainnet" ? IRIS_API_MAINNET : IRIS_API_SANDBOX;
190
+ }
191
+ function cctpSupportedRoutes(network) {
192
+ const chains = network ? CCTP_EVM_CHAINS.filter((c) => c.network === network) : [...CCTP_EVM_CHAINS];
193
+ const out = [];
194
+ for (const src of chains) {
195
+ for (const dst of chains) {
196
+ if (src.chainId === dst.chainId) continue;
197
+ if (src.network !== dst.network) continue;
198
+ out.push({
199
+ sourceChainId: src.chainId,
200
+ destChainId: dst.chainId,
201
+ sourceDomain: src.domain,
202
+ destDomain: dst.domain,
203
+ sourceLabel: src.label,
204
+ destLabel: dst.label,
205
+ network: src.network
206
+ });
207
+ }
208
+ }
209
+ return out;
210
+ }
211
+
212
+ // src/protocols/evm/circle-cctp/fees.ts
213
+ function pickForwardFeeTier(row, tier) {
214
+ const forwardFee = row.forwardFee;
215
+ if (forwardFee && typeof forwardFee === "object") {
216
+ const key = tier === "low" ? "low" : tier === "high" ? "high" : "med";
217
+ const v = forwardFee[key];
218
+ if (v != null) return BigInt(String(v));
219
+ }
220
+ const maxFee = row.maximumFee ?? row.maxFee ?? row.forwardFee;
221
+ if (maxFee != null) return BigInt(String(maxFee));
222
+ throw new Error("Iris fee response missing forwardFee tiers.");
223
+ }
224
+ async function fetchCctpBurnFees(args) {
225
+ const tier = args.feeTier ?? "med";
226
+ const base = irisApiBaseForChainId(args.sourceChainId);
227
+ const url = `${base}/v2/burn/USDC/fees/${args.sourceDomain}/${args.destDomain}?forward=true`;
228
+ const res = await fetch(url, { headers: { Accept: "application/json" } });
229
+ if (!res.ok) {
230
+ const text = await res.text().catch(() => "");
231
+ throw new Error(`Iris fee quote failed (${res.status}): ${text.slice(0, 200)}`);
232
+ }
233
+ const json = await res.json();
234
+ const rows = Array.isArray(json) ? json : Array.isArray(json.data) ? json.data : [json];
235
+ const row = rows[0] ?? {};
236
+ const low = pickForwardFeeTier(row, "low");
237
+ const med = pickForwardFeeTier(row, "med");
238
+ const high = pickForwardFeeTier(row, "high");
239
+ const maxFee = tier === "low" ? low : tier === "high" ? high : med;
240
+ return {
241
+ sourceDomain: args.sourceDomain,
242
+ destDomain: args.destDomain,
243
+ maxFee,
244
+ forwardFeeLow: low,
245
+ forwardFeeMed: med,
246
+ forwardFeeHigh: high,
247
+ feeTierUsed: tier
248
+ };
249
+ }
250
+ function formatCctpUsdcHuman(wei) {
251
+ const raw = formatUnits(wei, CCTP_USDC_DECIMALS);
252
+ if (!raw.includes(".")) return raw;
253
+ return raw.replace(/\.?0+$/, "") || "0";
254
+ }
255
+
256
+ // src/core/purpose.ts
257
+ function mergePurposeText(purposeText, purposeSuffix) {
258
+ const t = (purposeText ?? "").trim();
259
+ const suffix = (purposeSuffix ?? "").trim();
260
+ if (!suffix) return t;
261
+ return t ? `${t}
262
+
263
+ ${suffix}` : suffix;
264
+ }
265
+
266
+ // src/core/envelope.ts
267
+ function finalizeMultisign(input) {
268
+ const { keyGen, destinationChainID, legs } = input;
269
+ if (legs.length === 0) {
270
+ throw new Error("finalizeMultisign requires at least one leg");
271
+ }
272
+ const ph = (keyGen.pubkeyhex ?? "").trim();
273
+ if (!ph) throw new Error("keyGen pubKey (pubkeyhex) is required");
274
+ const keyList = keyGen.keylist ?? [];
275
+ const clientId = getClientIdFromKeyGenResult(keyGen);
276
+ const first = legs[0];
277
+ const messageHashes = legs.map((l) => l.msgHash);
278
+ const messageRawBatch = legs.map((l) => l.msgRaw);
279
+ const batchMeta = legs.map((l) => ({
280
+ destinationAddress: l.destinationAddress,
281
+ signatureText: l.signatureText,
282
+ ...l.audit
283
+ }));
284
+ const proposalTxParams = legs.map((l) => l.proposalTxParams).filter((p) => p != null && typeof p === "object");
285
+ const extraPayload = {
286
+ batchMeta,
287
+ ...input.extraJSON ?? {}
288
+ };
289
+ const extraJSON = JSON.stringify(extraPayload);
290
+ const bodyForSign = {
291
+ keyList,
292
+ pubKey: ph,
293
+ msgHash: messageHashes[0],
294
+ msgRaw: first.msgRaw,
295
+ destinationChainID,
296
+ destinationAddress: input.destinationAddress ?? first.destinationAddress,
297
+ extraJSON,
298
+ signatureText: first.signatureText,
299
+ purpose: mergePurposeText(input.purposeText, input.purposeSuffix),
300
+ ...first.feeSnapshot
301
+ };
302
+ if (legs.length > 1) {
303
+ bodyForSign.messageHashes = messageHashes;
304
+ bodyForSign.messageRawBatch = messageRawBatch;
305
+ }
306
+ if (proposalTxParams.length > 0) {
307
+ bodyForSign.proposalTxParams = proposalTxParams;
308
+ }
309
+ const valueWei = first.valueWei;
310
+ if (valueWei != null && valueWei > 0n) {
311
+ bodyForSign.value = valueWei.toString();
312
+ }
313
+ if (clientId) bodyForSign.clientId = clientId;
314
+ return { bodyForSign, messageToSign: JSON.stringify(bodyForSign) };
315
+ }
316
+ function routerSwapGasLimitFromEstimate(estimatedGas, chainGasLimit) {
317
+ if (chainGasLimit != null && Number.isFinite(chainGasLimit) && chainGasLimit > 0) {
318
+ return gasLimitFromEstimateAndChainConfig(estimatedGas, chainGasLimit);
319
+ }
320
+ return (estimatedGas * 12n + 9n) / 10n;
321
+ }
322
+
323
+ // src/chains/evm/buildBatch.ts
324
+ async function buildEvmMultisignBatch(args) {
325
+ const { context, steps } = args;
326
+ const {
327
+ chainId,
328
+ rpcUrl,
329
+ executorAddress,
330
+ chainDetail,
331
+ useCustomGas,
332
+ customGasChainDetails,
333
+ keyGen,
334
+ purposeText
335
+ } = context;
336
+ if (steps.length === 0) throw new Error("buildEvmMultisignBatch requires at least one step");
337
+ const ch = defineChain({
338
+ id: chainId,
339
+ name: "Destination",
340
+ nativeCurrency: { decimals: 18, name: "Ether", symbol: "ETH" },
341
+ rpcUrls: { default: { http: [rpcUrl] } }
342
+ });
343
+ const publicClient = createPublicClient({ chain: ch, transport: http(rpcUrl) });
344
+ const feeParams = await fetchChainFeeParams(rpcUrl, chainId);
345
+ const legacy = Boolean(chainDetail?.legacy) || !feeParams.isEip1559;
346
+ const latestBaseFeeWei = !legacy ? (await publicClient.getBlock({ blockTag: "latest" })).baseFeePerGas ?? 0n : 0n;
347
+ const gasLimitConfig = useCustomGas && chainDetail?.gasLimit != null ? Number(chainDetail.gasLimit) : void 0;
348
+ const chainGasLimitRouter = chainDetail?.gasLimit != null && Number.isFinite(Number(chainDetail.gasLimit)) && Number(chainDetail.gasLimit) > 0 ? Number(chainDetail.gasLimit) : void 0;
349
+ const gasFeeMultiplier = useCustomGas && chainDetail?.gasMultiplier != null ? Number(chainDetail.gasMultiplier) : void 0;
350
+ const executor = getAddress(executorAddress);
351
+ const baseNonce = await publicClient.getTransactionCount({ address: executor, blockTag: "pending" });
352
+ const legs = [];
353
+ for (let i = 0; i < steps.length; i++) {
354
+ const step = steps[i];
355
+ const currentNonce = baseNonce + i;
356
+ let estimatedGas;
357
+ if (args.estimateGasForStep) {
358
+ estimatedGas = await args.estimateGasForStep({ step, index: i, publicClient, executor });
359
+ } else {
360
+ try {
361
+ estimatedGas = await publicClient.estimateGas({
362
+ to: step.to,
363
+ data: step.data,
364
+ value: step.value,
365
+ account: executor
366
+ });
367
+ } catch {
368
+ estimatedGas = step.fallbackGas ?? 100000n;
369
+ }
370
+ }
371
+ let gasLimitI;
372
+ if (args.resolveGasLimit) {
373
+ gasLimitI = await args.resolveGasLimit({ step, index: i, estimatedGas, publicClient });
374
+ } else if (step.routerSwap) {
375
+ gasLimitI = routerSwapGasLimitFromEstimate(estimatedGas, chainGasLimitRouter);
376
+ } else {
377
+ gasLimitI = useCustomGas ? gasLimitFromEstimateAndChainConfig(estimatedGas, gasLimitConfig) : estimatedGas;
378
+ }
379
+ let proposalTxParams;
380
+ let feeSnapshot;
381
+ let serialized;
382
+ if (legacy) {
383
+ let gasPriceWei = await publicClient.getGasPrice();
384
+ if (useCustomGas && gasFeeMultiplier != null && gasFeeMultiplier > 0) {
385
+ gasPriceWei = gasPriceWei * BigInt(100 + gasFeeMultiplier) / 100n;
386
+ }
387
+ if (useCustomGas && chainDetail?.gasPrice != null && chainDetail.gasPrice > 0) {
388
+ const configured = parseGwei(gweiToDecimalString(Number(chainDetail.gasPrice)));
389
+ if (configured > gasPriceWei) gasPriceWei = configured;
390
+ }
391
+ serialized = serializeTransaction({
392
+ type: "legacy",
393
+ to: step.to,
394
+ data: step.data,
395
+ value: step.value,
396
+ gas: gasLimitI,
397
+ gasPrice: gasPriceWei,
398
+ nonce: currentNonce,
399
+ chainId
400
+ });
401
+ proposalTxParams = {
402
+ nonce: currentNonce,
403
+ gasLimit: gasLimitI.toString(),
404
+ txType: "legacy",
405
+ gasPrice: gasPriceWei.toString()
406
+ };
407
+ feeSnapshot = proposalTxParamsToFeeSnapshot(proposalTxParams);
408
+ } else {
409
+ const fetchedBase = feeParams.baseFeeGwei ?? 0;
410
+ const fetchedPriority = feeParams.priorityFeeGwei ?? 0;
411
+ const configuredBase = useCustomGas && chainDetail?.baseFee != null ? Number(chainDetail.baseFee) : 0;
412
+ const configuredPriority = useCustomGas && chainDetail?.priorityFee != null ? Number(chainDetail.priorityFee) : 0;
413
+ const effectiveBaseFeeGwei = Math.max(fetchedBase, configuredBase);
414
+ const effectivePriorityFeeGwei = Math.max(fetchedPriority, configuredPriority);
415
+ const baseFeeMultiplierPct = useCustomGas && chainDetail?.baseFeeMultiplier != null ? Math.max(100, Number(chainDetail.baseFeeMultiplier)) : 100;
416
+ const baseComponentGwei = effectiveBaseFeeGwei * baseFeeMultiplierPct / 100;
417
+ const maxFeePerGasGwei = baseComponentGwei + effectivePriorityFeeGwei;
418
+ let maxPriorityFeePerGas = effectivePriorityFeeGwei > 0 ? parseGwei(gweiToDecimalString(effectivePriorityFeeGwei)) : parseGwei("1");
419
+ let maxFeePerGas = parseGwei(gweiToDecimalString(maxFeePerGasGwei));
420
+ if (useCustomGas && gasFeeMultiplier != null && gasFeeMultiplier > 0) {
421
+ maxPriorityFeePerGas = maxPriorityFeePerGas * BigInt(100 + gasFeeMultiplier) / 100n;
422
+ maxFeePerGas = maxFeePerGas * BigInt(100 + gasFeeMultiplier) / 100n;
423
+ }
424
+ ({ maxFeePerGas, maxPriorityFeePerGas } = alignEip1559FeesWithLatestBase(
425
+ maxFeePerGas,
426
+ maxPriorityFeePerGas,
427
+ latestBaseFeeWei
428
+ ));
429
+ serialized = serializeTransaction({
430
+ type: "eip1559",
431
+ to: step.to,
432
+ data: step.data,
433
+ value: step.value,
434
+ gas: gasLimitI,
435
+ maxFeePerGas,
436
+ maxPriorityFeePerGas,
437
+ nonce: currentNonce,
438
+ chainId
439
+ });
440
+ proposalTxParams = {
441
+ nonce: currentNonce,
442
+ gasLimit: gasLimitI.toString(),
443
+ txType: "eip1559",
444
+ maxFeePerGas: maxFeePerGas.toString(),
445
+ maxPriorityFeePerGas: maxPriorityFeePerGas.toString()
446
+ };
447
+ feeSnapshot = i === 0 ? proposalTxParamsToFeeSnapshot(proposalTxParams) : {};
448
+ }
449
+ const h = keccak256(serialized);
450
+ const msgHash = h.startsWith("0x") ? h.slice(2) : h;
451
+ const batchMetaExtra = args.buildBatchMeta({ step, index: i, gasLimit: gasLimitI });
452
+ legs.push({
453
+ msgHash,
454
+ msgRaw: i === 0 && args.firstMsgRawNo0x != null ? args.firstMsgRawNo0x : serialized,
455
+ destinationAddress: step.to,
456
+ signatureText: typeof batchMetaExtra.signatureText === "string" ? batchMetaExtra.signatureText : JSON.stringify(batchMetaExtra.signatureText ?? {}),
457
+ audit: batchMetaExtra,
458
+ feeSnapshot: i === 0 ? feeSnapshot : {},
459
+ proposalTxParams,
460
+ valueWei: i === 0 ? step.value : void 0
461
+ });
462
+ if (i === 0 && args.firstMsgRawNo0x != null) {
463
+ legs[0].msgRaw = args.firstMsgRawNo0x;
464
+ }
465
+ }
466
+ const extraJSON = {};
467
+ if (useCustomGas && customGasChainDetails && Object.keys(customGasChainDetails).length > 0) {
468
+ extraJSON.customGasChainDetails = customGasChainDetails;
469
+ }
470
+ const result = finalizeMultisign({
471
+ keyGen,
472
+ purposeText,
473
+ purposeSuffix: args.purposeSuffix,
474
+ destinationChainID: String(chainId),
475
+ destinationAddress: args.destinationAddress ?? steps[0].to,
476
+ legs,
477
+ extraJSON: Object.keys(extraJSON).length > 0 ? extraJSON : void 0
478
+ });
479
+ const pv = args.payableValueWei;
480
+ if (pv != null && pv > 0n) {
481
+ result.bodyForSign.value = pv.toString();
482
+ }
483
+ return result;
484
+ }
485
+ var erc20BalanceAbi = parseAbi(["function balanceOf(address account) view returns (uint256)"]);
486
+ async function cctpAssertBurnPreconditions(args) {
487
+ if (!isCctpRouteSupported(args.sourceChainId, args.destChainId)) {
488
+ throw new Error("CCTP route is not supported for the selected source and destination chains.");
489
+ }
490
+ const src = cctpChainConfig(args.sourceChainId);
491
+ if (!src) throw new Error("Unsupported CCTP source chain.");
492
+ const transferAmount = parseUnits(args.transferAmountHuman.trim(), CCTP_USDC_DECIMALS);
493
+ if (transferAmount <= 0n) throw new Error("Transfer amount must be greater than zero.");
494
+ const totalBurn = transferAmount + args.maxFee;
495
+ const ch = defineChain({
496
+ id: args.sourceChainId,
497
+ name: src.label,
498
+ nativeCurrency: { decimals: 18, name: "Ether", symbol: "ETH" },
499
+ rpcUrls: { default: { http: [args.rpcUrl.trim()] } }
500
+ });
501
+ const client = createPublicClient({ chain: ch, transport: http(args.rpcUrl.trim()) });
502
+ const owner = getAddress(args.executorAddress);
503
+ const balance = await client.readContract({
504
+ address: getAddress(src.usdc),
505
+ abi: erc20BalanceAbi,
506
+ functionName: "balanceOf",
507
+ args: [owner]
508
+ });
509
+ if (balance < totalBurn) {
510
+ throw new Error(
511
+ `Insufficient USDC on source chain: need ${totalBurn.toString()} (transfer + maxFee), have ${balance.toString()}.`
512
+ );
513
+ }
514
+ return { transferAmount, totalBurn };
515
+ }
516
+
517
+ // src/protocols/evm/circle-cctp/multisign.ts
518
+ var erc20ApproveAbi = parseAbi(["function approve(address spender, uint256 amount) returns (bool)"]);
519
+ var tokenMessengerAbi = parseAbi([
520
+ "function depositForBurnWithHook(uint256 amount, uint32 destinationDomain, bytes32 mintRecipient, address burnToken, bytes32 destinationCaller, uint256 maxFee, uint32 minFinalityThreshold, bytes hookData)"
521
+ ]);
522
+ function buildCctpBurnExtraJSON(args) {
523
+ return {
524
+ version: 1,
525
+ sourceChainId: args.sourceChainId,
526
+ sourceDomain: args.sourceDomain,
527
+ destDomain: args.destDomain,
528
+ destChainId: args.destChainId,
529
+ transferAmount: args.transferAmount.toString(),
530
+ mintRecipient: pad(args.mintRecipient, { size: 32 }),
531
+ burnToken: args.burnToken,
532
+ tokenMessenger: args.tokenMessenger,
533
+ useForwardingService: true,
534
+ forwardingHookData: FORWARDING_SERVICE_HOOK_DATA,
535
+ minFinalityThreshold: args.minFinalityThreshold,
536
+ proposalMaxFee: args.proposalMaxFee.toString(),
537
+ feeTier: args.feeTier
538
+ };
539
+ }
540
+ function buildCctpBurnSteps(args) {
541
+ const src = cctpChainConfig(args.sourceChainId);
542
+ const dst = cctpChainConfig(args.destChainId);
543
+ if (!src || !dst) throw new Error("Unsupported CCTP source or destination chain.");
544
+ const usdc = getAddress(src.usdc);
545
+ const tokenMessenger = getAddress(src.tokenMessenger);
546
+ const totalBurn = args.transferAmount + args.maxFee;
547
+ const mintRecipientBytes32 = pad(args.mintRecipient, { size: 32 });
548
+ const destinationCaller = pad("0x", { size: 32 });
549
+ const steps = [];
550
+ const allowance = args.currentAllowance ?? 0n;
551
+ if (allowance < totalBurn) {
552
+ if (allowance > 0n) {
553
+ steps.push({
554
+ kind: "approve",
555
+ to: usdc,
556
+ data: encodeFunctionData({ abi: erc20ApproveAbi, functionName: "approve", args: [tokenMessenger, 0n] }),
557
+ value: 0n,
558
+ fallbackGas: CCTP_ERC20_APPROVE_FALLBACK_GAS
559
+ });
560
+ }
561
+ steps.push({
562
+ kind: "approve",
563
+ to: usdc,
564
+ data: encodeFunctionData({
565
+ abi: erc20ApproveAbi,
566
+ functionName: "approve",
567
+ args: [tokenMessenger, totalBurn]
568
+ }),
569
+ value: 0n,
570
+ fallbackGas: CCTP_ERC20_APPROVE_FALLBACK_GAS
571
+ });
572
+ }
573
+ steps.push({
574
+ kind: "depositForBurnWithHook",
575
+ to: tokenMessenger,
576
+ data: encodeFunctionData({
577
+ abi: tokenMessengerAbi,
578
+ functionName: "depositForBurnWithHook",
579
+ args: [
580
+ totalBurn,
581
+ dst.domain,
582
+ mintRecipientBytes32,
583
+ usdc,
584
+ destinationCaller,
585
+ args.maxFee,
586
+ args.minFinalityThreshold,
587
+ FORWARDING_SERVICE_HOOK_DATA
588
+ ]
589
+ }),
590
+ value: 0n,
591
+ fallbackGas: CCTP_DEPOSIT_FOR_BURN_FALLBACK_GAS
592
+ });
593
+ return steps;
594
+ }
595
+ async function buildEvmMultisignBodyCctpBurnBatch(args) {
596
+ const src = cctpChainConfig(args.sourceChainId);
597
+ const dst = cctpChainConfig(args.destChainId);
598
+ if (!src || !dst) throw new Error("Unsupported CCTP source or destination chain.");
599
+ const executor = getAddress(args.executorAddress);
600
+ const mintRecipient = getAddress(args.mintRecipient ?? executor);
601
+ const minFinality = args.minFinalityThreshold ?? CCTP_DEFAULT_MIN_FINALITY_THRESHOLD;
602
+ let maxFee = args.maxFee;
603
+ let proposalMaxFee = args.proposalMaxFee ?? maxFee;
604
+ if (maxFee == null) {
605
+ const fees = await fetchCctpBurnFees({
606
+ sourceChainId: args.sourceChainId,
607
+ sourceDomain: src.domain,
608
+ destDomain: dst.domain,
609
+ feeTier: args.feeTier
610
+ });
611
+ maxFee = fees.maxFee;
612
+ proposalMaxFee = fees.maxFee;
613
+ } else if (proposalMaxFee == null) {
614
+ proposalMaxFee = maxFee;
615
+ }
616
+ const { transferAmount } = await cctpAssertBurnPreconditions({
617
+ sourceChainId: args.sourceChainId,
618
+ destChainId: args.destChainId,
619
+ transferAmountHuman: args.transferAmountHuman,
620
+ maxFee,
621
+ rpcUrl: args.rpcUrl,
622
+ executorAddress: executor
623
+ });
624
+ const steps = buildCctpBurnSteps({
625
+ sourceChainId: args.sourceChainId,
626
+ destChainId: args.destChainId,
627
+ mintRecipient,
628
+ transferAmount,
629
+ maxFee,
630
+ minFinalityThreshold: minFinality,
631
+ currentAllowance: 0n
632
+ });
633
+ const cctpBurn = buildCctpBurnExtraJSON({
634
+ sourceChainId: args.sourceChainId,
635
+ sourceDomain: src.domain,
636
+ destDomain: dst.domain,
637
+ destChainId: dst.chainId,
638
+ transferAmount,
639
+ mintRecipient,
640
+ burnToken: getAddress(src.usdc),
641
+ tokenMessenger: getAddress(src.tokenMessenger),
642
+ minFinalityThreshold: minFinality,
643
+ proposalMaxFee,
644
+ feeTier: args.feeTier ?? "med"
645
+ });
646
+ const transferHuman = args.transferAmountHuman.trim();
647
+ const totalBurn = transferAmount + maxFee;
648
+ const purposeSuffix = `CCTP (Forwarding Service): ${transferHuman} USDC ${src.label} \u2192 ${dst.label}.`;
649
+ const firstDataNo0x = steps[0].data.startsWith("0x") ? steps[0].data.slice(2) : steps[0].data;
650
+ const result = await buildEvmMultisignBatch({
651
+ context: {
652
+ chainCategory: "evm",
653
+ keyGen: args.keyGen,
654
+ purposeText: args.purposeText,
655
+ chainId: args.sourceChainId,
656
+ rpcUrl: args.rpcUrl,
657
+ executorAddress: executor,
658
+ chainDetail: args.chainDetail,
659
+ useCustomGas: args.useCustomGas,
660
+ customGasChainDetails: args.customGasChainDetails
661
+ },
662
+ steps,
663
+ purposeSuffix,
664
+ firstMsgRawNo0x: firstDataNo0x,
665
+ destinationAddress: steps[0].to,
666
+ buildBatchMeta: ({ step }) => {
667
+ const s = step;
668
+ if (s.kind === "approve") {
669
+ return {
670
+ signatureText: JSON.stringify({
671
+ kind: "CircleCCTP",
672
+ name: "USDC.approve",
673
+ spender: src.tokenMessenger,
674
+ amount: totalBurn.toString()
675
+ }),
676
+ evm: { type: "cctp_erc20_approve", version: 1, chainId: String(args.sourceChainId) }
677
+ };
678
+ }
679
+ return {
680
+ signatureText: JSON.stringify({
681
+ kind: "CircleCCTP",
682
+ name: "TokenMessengerV2.depositForBurnWithHook",
683
+ destDomain: dst.domain,
684
+ destChainId: dst.chainId,
685
+ mintRecipient,
686
+ transferAmount: transferAmount.toString(),
687
+ maxFee: maxFee.toString()
688
+ }),
689
+ evm: { type: "cctp_deposit_for_burn_forward", version: 1, chainId: String(args.sourceChainId) }
690
+ };
691
+ }
692
+ });
693
+ const body = result.bodyForSign;
694
+ const existingExtra = typeof body.extraJSON === "string" ? JSON.parse(body.extraJSON) : body.extraJSON ?? {};
695
+ body.extraJSON = JSON.stringify({ ...existingExtra, cctpBurn });
696
+ return result;
697
+ }
698
+ async function buildEvmMultisignBodyCctpBurnBatchFromMcp(args) {
699
+ let maxFee;
700
+ let proposalMaxFee;
701
+ if (args.feeSnapshot?.maxFee != null) {
702
+ maxFee = BigInt(String(args.feeSnapshot.maxFee));
703
+ proposalMaxFee = maxFee;
704
+ }
705
+ return buildEvmMultisignBodyCctpBurnBatch({
706
+ keyGen: args.keyGen,
707
+ sourceChainId: args.chainId,
708
+ destChainId: args.destChainId,
709
+ rpcUrl: args.rpcUrl,
710
+ chainDetail: args.chainDetail,
711
+ useCustomGas: args.useCustomGas,
712
+ customGasChainDetails: args.customGasChainDetails,
713
+ transferAmountHuman: args.transferAmountHuman,
714
+ mintRecipient: args.mintRecipient ? getAddress(args.mintRecipient) : void 0,
715
+ executorAddress: args.executorAddress,
716
+ purposeText: args.purposeText,
717
+ maxFee,
718
+ proposalMaxFee,
719
+ feeTier: args.feeTier,
720
+ minFinalityThreshold: args.minFinalityThreshold
721
+ });
722
+ }
723
+
724
+ // src/protocols/evm/circle-cctp/executeHelpers.ts
725
+ function parseExtraJsonObject(detail) {
726
+ if (!detail) return null;
727
+ const raw = detail.ExtraJSON ?? detail.extraJSON;
728
+ if (raw == null) return null;
729
+ if (typeof raw === "object" && !Array.isArray(raw)) return raw;
730
+ if (typeof raw === "string" && raw.trim()) {
731
+ try {
732
+ const p = JSON.parse(raw);
733
+ if (p && typeof p === "object" && !Array.isArray(p)) return p;
734
+ } catch {
735
+ return null;
736
+ }
737
+ }
738
+ return null;
739
+ }
740
+ function parseCctpBurnExtraJSON(detail) {
741
+ const ex = parseExtraJsonObject(detail);
742
+ const raw = ex?.cctpBurn;
743
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
744
+ const c = raw;
745
+ if (c.useForwardingService !== true) return null;
746
+ const version = Number(c.version ?? 0);
747
+ if (version !== 1) return null;
748
+ return {
749
+ version: 1,
750
+ sourceChainId: Number(c.sourceChainId ?? 0),
751
+ sourceDomain: Number(c.sourceDomain),
752
+ destDomain: Number(c.destDomain),
753
+ destChainId: Number(c.destChainId),
754
+ transferAmount: String(c.transferAmount ?? ""),
755
+ mintRecipient: String(c.mintRecipient ?? ""),
756
+ burnToken: String(c.burnToken ?? ""),
757
+ tokenMessenger: String(c.tokenMessenger ?? ""),
758
+ useForwardingService: true,
759
+ forwardingHookData: String(c.forwardingHookData ?? FORWARDING_SERVICE_HOOK_DATA),
760
+ minFinalityThreshold: Number(c.minFinalityThreshold ?? 1e3),
761
+ proposalMaxFee: String(c.proposalMaxFee ?? "0"),
762
+ feeTier: c.feeTier === "low" || c.feeTier === "high" || c.feeTier === "med" ? c.feeTier : void 0
763
+ };
764
+ }
765
+ function isCctpBurnEvmSignRequest(detail, batchIndex) {
766
+ if (parseCctpBurnExtraJSON(detail)) return true;
767
+ const ex = parseExtraJsonObject(detail);
768
+ if (batchIndex != null && batchIndex >= 0 && ex) {
769
+ const bm = ex.batchMeta;
770
+ if (Array.isArray(bm) && bm[batchIndex] && typeof bm[batchIndex] === "object" && !Array.isArray(bm[batchIndex])) {
771
+ const evm0 = bm[batchIndex].evm;
772
+ if (evm0 && typeof evm0 === "object" && !Array.isArray(evm0)) {
773
+ const t2 = String(evm0.type ?? "");
774
+ return t2 === "cctp_deposit_for_burn_forward" || t2 === "cctp_erc20_approve";
775
+ }
776
+ }
777
+ }
778
+ const evm = ex?.evm;
779
+ if (!evm || typeof evm !== "object" || Array.isArray(evm)) return false;
780
+ const t = String(evm.type ?? "");
781
+ return t === "cctp_deposit_for_burn_forward";
782
+ }
783
+ function isCctpErc20ApproveEvmSignRequest(detail, batchIndex) {
784
+ const ex = parseExtraJsonObject(detail);
785
+ const index = batchIndex != null && batchIndex >= 0 ? batchIndex : 0;
786
+ const bm = ex?.batchMeta;
787
+ if (Array.isArray(bm) && bm[index] && typeof bm[index] === "object" && !Array.isArray(bm[index])) {
788
+ const evm0 = bm[index].evm;
789
+ if (evm0 && typeof evm0 === "object" && !Array.isArray(evm0)) {
790
+ return String(evm0.type ?? "") === "cctp_erc20_approve";
791
+ }
792
+ }
793
+ return false;
794
+ }
795
+ function resolveCctpBatchStepGasFromSignRequest(detail, batchIndex) {
796
+ const index = batchIndex != null && batchIndex >= 0 ? batchIndex : 0;
797
+ if (isCctpErc20ApproveEvmSignRequest(detail, index)) return CCTP_ERC20_APPROVE_FALLBACK_GAS;
798
+ if (isCctpBurnEvmSignRequest(detail, index)) return CCTP_DEPOSIT_FOR_BURN_FALLBACK_GAS;
799
+ return null;
800
+ }
801
+ function rebuildCctpBurnCalldataAtGetSig(args) {
802
+ const transferAmount = BigInt(args.cctpBurn.transferAmount);
803
+ const mintRecipient = cctpMintRecipientAddressFromExtra(args.cctpBurn);
804
+ const steps = buildCctpBurnSteps({
805
+ sourceChainId: args.cctpBurn.sourceChainId,
806
+ destChainId: args.cctpBurn.destChainId,
807
+ executorAddress: args.executorAddress,
808
+ mintRecipient,
809
+ transferAmount,
810
+ maxFee: args.freshMaxFee,
811
+ minFinalityThreshold: args.cctpBurn.minFinalityThreshold,
812
+ currentAllowance: args.forceApprove ? 0n : void 0
813
+ });
814
+ return steps.map((s) => ({ to: s.to, data: s.data }));
815
+ }
816
+ function cctpMintRecipientAddressFromExtra(cctpBurn) {
817
+ const hex = cctpBurn.mintRecipient.startsWith("0x") ? cctpBurn.mintRecipient.slice(2) : cctpBurn.mintRecipient;
818
+ return getAddress(`0x${hex.slice(-40)}`);
819
+ }
820
+
821
+ // src/protocols/evm/circle-cctp/reads.ts
822
+ var erc20BalanceAbi2 = parseAbi(["function balanceOf(address account) view returns (uint256)"]);
823
+ async function cctpFetchSupportedRoutes(args) {
824
+ return { routes: cctpSupportedRoutes(args?.network) };
825
+ }
826
+ function buildCctpMcpFeeFields(args) {
827
+ const { fees, transferAmount, transferAmountHuman } = args;
828
+ const maxFeeHuman = formatCctpUsdcHuman(fees.maxFee);
829
+ const forwardFeeLowHuman = formatCctpUsdcHuman(fees.forwardFeeLow);
830
+ const forwardFeeMedHuman = formatCctpUsdcHuman(fees.forwardFeeMed);
831
+ const forwardFeeHighHuman = formatCctpUsdcHuman(fees.forwardFeeHigh);
832
+ let totalBurn;
833
+ let totalBurnHuman;
834
+ if (transferAmount != null) {
835
+ totalBurn = transferAmount + fees.maxFee;
836
+ totalBurnHuman = formatCctpUsdcHuman(totalBurn);
837
+ }
838
+ const recipientPart = transferAmountHuman != null ? ` Recipient receives ${transferAmountHuman} USDC; wallet burns ${totalBurnHuman} USDC total (transfer + max fee).` : "";
839
+ const feeSummary = `Forwarding Service max fee (${fees.feeTierUsed} tier): ${maxFeeHuman} USDC.${recipientPart} Fee tiers \u2014 low: ${forwardFeeLowHuman}, med: ${forwardFeeMedHuman}, high: ${forwardFeeHighHuman} USDC. Fees refresh again at Get Sig.`;
840
+ return {
841
+ feeTierUsed: fees.feeTierUsed,
842
+ maxFee: fees.maxFee.toString(),
843
+ maxFeeHuman,
844
+ forwardFeeLow: fees.forwardFeeLow.toString(),
845
+ forwardFeeLowHuman,
846
+ forwardFeeMed: fees.forwardFeeMed.toString(),
847
+ forwardFeeMedHuman,
848
+ forwardFeeHigh: fees.forwardFeeHigh.toString(),
849
+ forwardFeeHighHuman,
850
+ ...transferAmount != null ? { transferAmount: transferAmount.toString() } : {},
851
+ ...transferAmountHuman != null ? { transferAmountHuman } : {},
852
+ ...totalBurn != null ? { totalBurn: totalBurn.toString() } : {},
853
+ ...totalBurnHuman != null ? { totalBurnHuman } : {},
854
+ feeSummary
855
+ };
856
+ }
857
+ function cctpFeeSummaryFromBodyForSign(bodyForSign) {
858
+ const cctpBurn = parseCctpBurnExtraJSON(bodyForSign);
859
+ if (!cctpBurn) return null;
860
+ const transferAmount = BigInt(cctpBurn.transferAmount);
861
+ const maxFee = BigInt(cctpBurn.proposalMaxFee);
862
+ const totalBurn = transferAmount + maxFee;
863
+ const transferAmountHuman = formatCctpUsdcHuman(transferAmount);
864
+ const maxFeeHuman = formatCctpUsdcHuman(maxFee);
865
+ const totalBurnHuman = formatCctpUsdcHuman(totalBurn);
866
+ const tier = cctpBurn.feeTier ?? "med";
867
+ const src = cctpChainConfig(cctpBurn.sourceChainId);
868
+ const dst = cctpChainConfig(cctpBurn.destChainId);
869
+ const routePart = src && dst ? ` Route: ${src.label} \u2192 ${dst.label}.` : "";
870
+ return {
871
+ feeTierUsed: tier,
872
+ maxFee: maxFee.toString(),
873
+ maxFeeHuman,
874
+ forwardFeeLow: maxFee.toString(),
875
+ forwardFeeLowHuman: maxFeeHuman,
876
+ forwardFeeMed: maxFee.toString(),
877
+ forwardFeeMedHuman: maxFeeHuman,
878
+ forwardFeeHigh: maxFee.toString(),
879
+ forwardFeeHighHuman: maxFeeHuman,
880
+ transferAmount: transferAmount.toString(),
881
+ transferAmountHuman,
882
+ totalBurn: totalBurn.toString(),
883
+ totalBurnHuman,
884
+ feeSummary: `Proposed CCTP burn.${routePart} Recipient receives ${transferAmountHuman} USDC; proposal max fee (${tier} tier): ${maxFeeHuman} USDC; total burn ${totalBurnHuman} USDC. Max fee refreshes at Get Sig.`
885
+ };
886
+ }
887
+ async function cctpFetchUsdcBalance(args) {
888
+ const cfg = cctpChainConfig(args.chainId);
889
+ if (!cfg) throw new Error(`Chain ${args.chainId} is not CCTP-supported.`);
890
+ const ch = defineChain({
891
+ id: args.chainId,
892
+ name: cfg.label,
893
+ nativeCurrency: { decimals: 18, name: "Ether", symbol: "ETH" },
894
+ rpcUrls: { default: { http: [args.rpcUrl.trim()] } }
895
+ });
896
+ const client = createPublicClient({ chain: ch, transport: http(args.rpcUrl.trim()) });
897
+ const owner = getAddress(args.executorAddress);
898
+ const balanceRaw = await client.readContract({
899
+ address: getAddress(cfg.usdc),
900
+ abi: erc20BalanceAbi2,
901
+ functionName: "balanceOf",
902
+ args: [owner]
903
+ });
904
+ const out = {
905
+ balanceRaw: balanceRaw.toString(),
906
+ balanceUsdcHuman: formatCctpUsdcHuman(balanceRaw),
907
+ usdcAddress: cfg.usdc
908
+ };
909
+ const transferHuman = args.transferAmountHuman?.trim();
910
+ const maxFeeRaw = args.feeSnapshot?.maxFee;
911
+ if (transferHuman && maxFeeRaw != null) {
912
+ const transferAmount = parseUnits(transferHuman, CCTP_USDC_DECIMALS);
913
+ const maxFee = BigInt(String(maxFeeRaw));
914
+ const totalRequired = transferAmount + maxFee;
915
+ out.requiredTotalBurnRaw = totalRequired.toString();
916
+ out.requiredTotalBurnHuman = formatCctpUsdcHuman(totalRequired);
917
+ out.sufficientForTransfer = balanceRaw >= totalRequired;
918
+ out.feeSummary = `Wallet holds ${out.balanceUsdcHuman} USDC; transfer requires ${formatCctpUsdcHuman(totalRequired)} USDC (${transferHuman} + ${formatCctpUsdcHuman(maxFee)} max fee).`;
919
+ }
920
+ return out;
921
+ }
922
+ async function cctpFetchTransferStatus(args) {
923
+ const base = irisApiBaseForChainId(args.sourceChainId);
924
+ const hash = args.burnTxHash.trim().replace(/^0x/, "");
925
+ const url = `${base}/v2/messages/${args.sourceDomain}?transactionHash=0x${hash}`;
926
+ const res = await fetch(url, { headers: { Accept: "application/json" } });
927
+ if (!res.ok) {
928
+ const text = await res.text().catch(() => "");
929
+ throw new Error(`Iris message lookup failed (${res.status}): ${text.slice(0, 200)}`);
930
+ }
931
+ const json = await res.json();
932
+ const messages = json.messages ?? json.data ?? [];
933
+ const first = messages[0] ?? json;
934
+ return {
935
+ status: String(first.status ?? "unknown"),
936
+ attestation: typeof first.attestation === "string" ? first.attestation : void 0,
937
+ message: first.message,
938
+ eventNonce: first.eventNonce
939
+ };
940
+ }
941
+ async function cctpFetchBurnFeesForRoute(args) {
942
+ const src = cctpChainConfig(args.sourceChainId);
943
+ const dst = cctpChainConfig(args.destChainId);
944
+ if (!src || !dst) throw new Error("Unsupported source or destination chain for CCTP.");
945
+ if (src.network !== dst.network) throw new Error("Source and destination must be on the same network (mainnet or testnet).");
946
+ if (src.chainId === dst.chainId) throw new Error("Source and destination must differ.");
947
+ const fees = await fetchCctpBurnFees({
948
+ sourceChainId: args.sourceChainId,
949
+ sourceDomain: src.domain,
950
+ destDomain: dst.domain,
951
+ feeTier: args.feeTier
952
+ });
953
+ const transferHuman = args.transferAmountHuman?.trim();
954
+ const transferAmount = transferHuman ? parseUnits(transferHuman, CCTP_USDC_DECIMALS) : void 0;
955
+ const feeFields = buildCctpMcpFeeFields({
956
+ fees,
957
+ transferAmount,
958
+ transferAmountHuman: transferHuman || void 0
959
+ });
960
+ return {
961
+ sourceChainId: args.sourceChainId,
962
+ destChainId: args.destChainId,
963
+ sourceDomain: src.domain,
964
+ destDomain: dst.domain,
965
+ sourceLabel: src.label,
966
+ destLabel: dst.label,
967
+ network: src.network,
968
+ fees: feeFields,
969
+ ...feeFields
970
+ };
971
+ }
972
+
973
+ // src/protocols/evm/circle-cctp/index.ts
974
+ var circleCctpProtocolModule = {
975
+ id: CIRCLE_CCTP_PROTOCOL_ID,
976
+ chainCategory: "evm",
977
+ isChainSupported(ctx) {
978
+ if (ctx.chainCategory !== "evm") return false;
979
+ return isCctpSourceChainSupported(ctx.chainId);
980
+ },
981
+ isTokenSupported(token) {
982
+ return token.category === "evm" && token.kind === "erc20";
983
+ },
984
+ actions: [
985
+ {
986
+ id: "circle-cctp.fetch-routes",
987
+ protocolId: CIRCLE_CCTP_PROTOCOL_ID,
988
+ chainCategory: "evm",
989
+ description: "List supported CCTP Forwarding Service routes (EVM)",
990
+ commonParams: [],
991
+ params: {
992
+ network: { type: "string", required: false, description: "mainnet | testnet" }
993
+ }
994
+ },
995
+ {
996
+ id: "circle-cctp.fetch-fees",
997
+ protocolId: CIRCLE_CCTP_PROTOCOL_ID,
998
+ chainCategory: "evm",
999
+ description: "Quote Iris Forwarding Service burn fees for a route",
1000
+ commonParams: [],
1001
+ params: {
1002
+ sourceChainId: { type: "number", required: true, description: "Source EIP-155 chain id" },
1003
+ destChainId: { type: "number", required: true, description: "Destination EIP-155 chain id" },
1004
+ transferAmountHuman: { type: "string", required: true, description: "USDC amount recipient receives" }
1005
+ }
1006
+ },
1007
+ {
1008
+ id: "circle-cctp.burn-forward",
1009
+ protocolId: CIRCLE_CCTP_PROTOCOL_ID,
1010
+ chainCategory: "evm",
1011
+ description: "Burn USDC on source chain via CCTP Forwarding Service (approve + depositForBurnWithHook batch)",
1012
+ commonParams: ["keyGen", "purposeText", "useCustomGas"],
1013
+ params: {
1014
+ sourceChainId: { type: "number", required: true, description: "Source EIP-155 chain id" },
1015
+ destChainId: { type: "number", required: true, description: "Destination EIP-155 chain id" },
1016
+ transferAmountHuman: { type: "string", required: true, description: "USDC amount recipient receives" },
1017
+ mintRecipient: { type: "address", required: false, description: "Destination mint recipient (default executor)" }
1018
+ }
1019
+ }
1020
+ ]
1021
+ };
1022
+ registerProtocolModule(circleCctpProtocolModule);
1023
+
1024
+ export { CCTP_DEFAULT_MIN_FINALITY_THRESHOLD, CCTP_DEPOSIT_FOR_BURN_FALLBACK_GAS, CCTP_ERC20_APPROVE_FALLBACK_GAS, CCTP_EVM_CHAINS, CCTP_USDC_DECIMALS, CIRCLE_CCTP_PROTOCOL_ID, FORWARDING_SERVICE_HOOK_DATA, IRIS_API_MAINNET, IRIS_API_SANDBOX, TOKEN_MESSENGER_V2_MAINNET, TOKEN_MESSENGER_V2_TESTNET, buildCctpBurnExtraJSON, buildCctpBurnSteps, buildEvmMultisignBodyCctpBurnBatch, buildEvmMultisignBodyCctpBurnBatchFromMcp, cctpAssertBurnPreconditions, cctpCanonicalUsdcAddress, cctpChainConfig, cctpFeeSummaryFromBodyForSign, cctpFetchBurnFeesForRoute, cctpFetchSupportedRoutes, cctpFetchTransferStatus, cctpFetchUsdcBalance, cctpMintRecipientAddressFromExtra, cctpSupportedRoutes, chainIdToDomain, circleCctpProtocolModule, domainToChainId, fetchCctpBurnFees, formatCctpUsdcHuman, irisApiBaseForChainId, isCctpBurnEvmSignRequest, isCctpCanonicalUsdcRow, isCctpErc20ApproveEvmSignRequest, isCctpRouteSupported, isCctpSourceChainSupported, parseCctpBurnExtraJSON, parseCctpEvmChainId, rebuildCctpBurnCalldataAtGetSig, resolveCctpBatchStepGasFromSignRequest };
1025
+ //# sourceMappingURL=index.js.map
1026
+ //# sourceMappingURL=index.js.map