@continuumdao/ctm-mpc-defi 0.2.13 → 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.
- package/dist/agent/catalog.cjs +1149 -287
- package/dist/agent/catalog.cjs.map +1 -1
- package/dist/agent/catalog.d.ts +1655 -306
- package/dist/agent/catalog.js +1144 -288
- package/dist/agent/catalog.js.map +1 -1
- package/dist/agent/skills/_shared/multisign-mcp-gas.md +7 -4
- package/dist/agent/skills/circle-cctp/SKILL.md +63 -0
- package/dist/chains/evm/index.cjs +75 -0
- package/dist/chains/evm/index.cjs.map +1 -1
- package/dist/chains/evm/index.d.ts +31 -1
- package/dist/chains/evm/index.js +73 -2
- package/dist/chains/evm/index.js.map +1 -1
- package/dist/index.cjs +140 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +138 -34
- package/dist/index.js.map +1 -1
- package/dist/protocols/evm/circle-cctp/index.cjs +1067 -0
- package/dist/protocols/evm/circle-cctp/index.cjs.map +1 -0
- package/dist/protocols/evm/circle-cctp/index.d.ts +281 -0
- package/dist/protocols/evm/circle-cctp/index.js +1026 -0
- package/dist/protocols/evm/circle-cctp/index.js.map +1 -0
- package/dist/protocols/evm/euler-v2/index.cjs +29 -2
- package/dist/protocols/evm/euler-v2/index.cjs.map +1 -1
- package/dist/protocols/evm/euler-v2/index.d.ts +23 -1
- package/dist/protocols/evm/euler-v2/index.js +29 -3
- package/dist/protocols/evm/euler-v2/index.js.map +1 -1
- package/dist/protocols/evm/gmx/index.cjs +42 -8
- package/dist/protocols/evm/gmx/index.cjs.map +1 -1
- package/dist/protocols/evm/gmx/index.d.ts +20 -4
- package/dist/protocols/evm/gmx/index.js +42 -9
- package/dist/protocols/evm/gmx/index.js.map +1 -1
- package/dist/protocols/evm/maple/index.cjs +9 -1
- package/dist/protocols/evm/maple/index.cjs.map +1 -1
- package/dist/protocols/evm/maple/index.d.ts +2 -1
- package/dist/protocols/evm/maple/index.js +9 -1
- package/dist/protocols/evm/maple/index.js.map +1 -1
- package/dist/protocols/evm/morpho/index.cjs +56 -0
- package/dist/protocols/evm/morpho/index.cjs.map +1 -1
- package/dist/protocols/evm/morpho/index.d.ts +28 -1
- package/dist/protocols/evm/morpho/index.js +56 -1
- package/dist/protocols/evm/morpho/index.js.map +1 -1
- package/dist/protocols/evm/uniswap-v4/index.cjs +98 -26
- package/dist/protocols/evm/uniswap-v4/index.cjs.map +1 -1
- package/dist/protocols/evm/uniswap-v4/index.js +99 -27
- package/dist/protocols/evm/uniswap-v4/index.js.map +1 -1
- package/package.json +6 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parseAbi, parseAbiParameters, parseAbiItem, getAddress, zeroAddress, formatUnits, parseUnits, createPublicClient, http, defineChain, encodeFunctionData, keccak256, encodeAbiParameters, decodeEventLog, decodeFunctionData, parseGwei, serializeTransaction, erc20Abi } from 'viem';
|
|
2
2
|
import { nodeFetchWithReadAuth, fetchChainFeeParams, gasLimitFromEstimateAndChainConfig, gweiToDecimalString, proposalTxParamsToFeeSnapshot, alignEip1559FeesWithLatestBase, getClientIdFromKeyGenResult } from '@continuumdao/continuum-node-sdk';
|
|
3
3
|
|
|
4
4
|
// src/core/registry.ts
|
|
@@ -498,6 +498,45 @@ function formatUniswapQuoteForDisplay(res, args) {
|
|
|
498
498
|
if (requestId) lines.push(`Request: ${requestId}`);
|
|
499
499
|
return { title: "Quote received", lines, rawJson };
|
|
500
500
|
}
|
|
501
|
+
var erc20AllowanceAbi = parseAbi([
|
|
502
|
+
"function allowance(address owner, address spender) view returns (uint256)",
|
|
503
|
+
"function decimals() view returns (uint8)"
|
|
504
|
+
]);
|
|
505
|
+
var erc20ApproveAbi = parseAbi(["function approve(address spender, uint256 amount) returns (bool)"]);
|
|
506
|
+
async function buildConditionalErc20ApproveSteps(args) {
|
|
507
|
+
if (args.amountWei <= 0n) return [];
|
|
508
|
+
const token = getAddress(args.token);
|
|
509
|
+
const spender = getAddress(args.spender);
|
|
510
|
+
const owner = getAddress(args.owner);
|
|
511
|
+
const fallback = args.fallbackGas ?? 100000n;
|
|
512
|
+
const allowance = await args.publicClient.readContract({
|
|
513
|
+
address: token,
|
|
514
|
+
abi: erc20AllowanceAbi,
|
|
515
|
+
functionName: "allowance",
|
|
516
|
+
args: [owner, spender]
|
|
517
|
+
});
|
|
518
|
+
if (allowance >= args.amountWei) return [];
|
|
519
|
+
const steps = [];
|
|
520
|
+
if (allowance > 0n) {
|
|
521
|
+
steps.push({
|
|
522
|
+
to: token,
|
|
523
|
+
data: encodeFunctionData({ abi: erc20ApproveAbi, functionName: "approve", args: [spender, 0n] }),
|
|
524
|
+
value: 0n,
|
|
525
|
+
fallbackGas: fallback
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
steps.push({
|
|
529
|
+
to: token,
|
|
530
|
+
data: encodeFunctionData({
|
|
531
|
+
abi: erc20ApproveAbi,
|
|
532
|
+
functionName: "approve",
|
|
533
|
+
args: [spender, args.amountWei]
|
|
534
|
+
}),
|
|
535
|
+
value: 0n,
|
|
536
|
+
fallbackGas: fallback
|
|
537
|
+
});
|
|
538
|
+
return steps;
|
|
539
|
+
}
|
|
501
540
|
|
|
502
541
|
// src/core/purpose.ts
|
|
503
542
|
function mergePurposeText(purposeText, purposeSuffix) {
|
|
@@ -1185,10 +1224,23 @@ async function buildEvmMultisignBodyUniswapV4SkipPermit2Batch(args) {
|
|
|
1185
1224
|
if (expiration48 > MAX_UINT48) expiration48 = MAX_UINT48;
|
|
1186
1225
|
}
|
|
1187
1226
|
const erc20ApproveSpender = usePermit2Triple ? PERMIT2_ADDRESS : toRouter;
|
|
1188
|
-
const
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1227
|
+
const executor = getAddress(args.executorAddress);
|
|
1228
|
+
const publicClient = createPublicClient({
|
|
1229
|
+
chain: defineChain({
|
|
1230
|
+
id: args.chainId,
|
|
1231
|
+
name: `uniswap-swap-${args.chainId}`,
|
|
1232
|
+
nativeCurrency: { decimals: 18, name: "Ether", symbol: "ETH" },
|
|
1233
|
+
rpcUrls: { default: { http: [args.rpcUrl] } }
|
|
1234
|
+
}),
|
|
1235
|
+
transport: http(args.rpcUrl)
|
|
1236
|
+
});
|
|
1237
|
+
const erc20ApproveSteps = await buildConditionalErc20ApproveSteps({
|
|
1238
|
+
publicClient,
|
|
1239
|
+
token: tokenIn,
|
|
1240
|
+
spender: erc20ApproveSpender,
|
|
1241
|
+
owner: executor,
|
|
1242
|
+
amountWei: approveAmountWei,
|
|
1243
|
+
fallbackGas: 100000n
|
|
1192
1244
|
});
|
|
1193
1245
|
const valueWei = (() => {
|
|
1194
1246
|
const v = args.swap.value;
|
|
@@ -1200,13 +1252,16 @@ async function buildEvmMultisignBodyUniswapV4SkipPermit2Batch(args) {
|
|
|
1200
1252
|
}
|
|
1201
1253
|
})();
|
|
1202
1254
|
const swapRecord = args.swap;
|
|
1203
|
-
const swapMsgIndex = usePermit2Triple ?
|
|
1255
|
+
const swapMsgIndex = usePermit2Triple ? erc20ApproveSteps.length + 1 : erc20ApproveSteps.length;
|
|
1204
1256
|
let gasBuildSource = "rpcEstimate";
|
|
1205
1257
|
let estimateGasError;
|
|
1206
1258
|
let swapBaseGasUnits = DEFAULT_UNIVERSAL_ROUTER_GAS_FALLBACK;
|
|
1207
|
-
const steps =
|
|
1208
|
-
|
|
1209
|
-
|
|
1259
|
+
const steps = erc20ApproveSteps.map((s) => ({
|
|
1260
|
+
to: s.to,
|
|
1261
|
+
data: s.data,
|
|
1262
|
+
value: s.value,
|
|
1263
|
+
fallbackGas: s.fallbackGas
|
|
1264
|
+
}));
|
|
1210
1265
|
if (usePermit2Triple) {
|
|
1211
1266
|
const permit2ApproveData = encodeFunctionData({
|
|
1212
1267
|
abi: permit2ApproveRouterAbi,
|
|
@@ -1223,8 +1278,9 @@ async function buildEvmMultisignBodyUniswapV4SkipPermit2Batch(args) {
|
|
|
1223
1278
|
fallbackGas: DEFAULT_UNIVERSAL_ROUTER_GAS_FALLBACK
|
|
1224
1279
|
});
|
|
1225
1280
|
const swapStepIndex = steps.length - 1;
|
|
1226
|
-
const approveMsgRawNo0x =
|
|
1227
|
-
const
|
|
1281
|
+
const approveMsgRawNo0x = erc20ApproveSteps.length > 0 && erc20ApproveSteps[erc20ApproveSteps.length - 1].data.startsWith("0x") ? erc20ApproveSteps[erc20ApproveSteps.length - 1].data.slice(2) : dataHex.startsWith("0x") ? dataHex.slice(2) : dataHex;
|
|
1282
|
+
const approveCount = erc20ApproveSteps.length;
|
|
1283
|
+
const purposeSuffix = usePermit2Triple ? `Uniswap V4: ${approveCount > 0 ? "3" : "2"}-tx batch (classic allowance) \u2014 ERC-20 approve allowance hub when needed, hub approve(Universal Router), swap.` : approveCount > 0 ? "Uniswap V4: 2-tx batch (classic allowance, dispatcher) \u2014 ERC-20 approve swap.to when needed, then swap." : "Uniswap V4: 1-tx batch \u2014 swap only (ERC-20 allowance already sufficient).";
|
|
1228
1284
|
const buildSwapAudit = () => ({
|
|
1229
1285
|
skipPermit2Batch: true,
|
|
1230
1286
|
approvalPath: usePermit2Triple ? "permit2_triple" : "dispatcher",
|
|
@@ -1301,18 +1357,18 @@ async function buildEvmMultisignBodyUniswapV4SkipPermit2Batch(args) {
|
|
|
1301
1357
|
firstMsgRawNo0x: approveMsgRawNo0x,
|
|
1302
1358
|
destinationAddress: tokenIn,
|
|
1303
1359
|
payableValueWei: valueWei > 0n ? valueWei : void 0,
|
|
1304
|
-
estimateGasForStep: async ({ step, index, publicClient, executor }) => {
|
|
1360
|
+
estimateGasForStep: async ({ step, index, publicClient: publicClient2, executor: executor2 }) => {
|
|
1305
1361
|
if (index !== swapStepIndex) {
|
|
1306
|
-
return
|
|
1362
|
+
return publicClient2.estimateGas({
|
|
1307
1363
|
to: step.to,
|
|
1308
1364
|
data: step.data,
|
|
1309
1365
|
value: step.value,
|
|
1310
|
-
account:
|
|
1366
|
+
account: executor2
|
|
1311
1367
|
});
|
|
1312
1368
|
}
|
|
1313
1369
|
const r = await estimateUniswapRouterSwapGas({
|
|
1314
|
-
publicClient,
|
|
1315
|
-
executor,
|
|
1370
|
+
publicClient: publicClient2,
|
|
1371
|
+
executor: executor2,
|
|
1316
1372
|
to: toRouter,
|
|
1317
1373
|
data: dataHex,
|
|
1318
1374
|
value: valueWei,
|
|
@@ -2197,7 +2253,7 @@ function isNativeUniswapLpTokenAddress(token) {
|
|
|
2197
2253
|
|
|
2198
2254
|
// src/protocols/evm/uniswap-v4/liquidityMultisign.ts
|
|
2199
2255
|
var wethDepositAbi = parseAbi(["function deposit() payable"]);
|
|
2200
|
-
var
|
|
2256
|
+
var erc20AllowanceAbi2 = parseAbi([
|
|
2201
2257
|
"function allowance(address owner, address spender) view returns (uint256)",
|
|
2202
2258
|
"function decimals() view returns (uint8)"
|
|
2203
2259
|
]);
|
|
@@ -2307,7 +2363,7 @@ async function resolveApproveTargets(args) {
|
|
|
2307
2363
|
}
|
|
2308
2364
|
const allowance = await args.publicClient.readContract({
|
|
2309
2365
|
address: row.token,
|
|
2310
|
-
abi:
|
|
2366
|
+
abi: erc20AllowanceAbi2,
|
|
2311
2367
|
functionName: "allowance",
|
|
2312
2368
|
args: [args.executor, args.spender]
|
|
2313
2369
|
});
|
|
@@ -2349,16 +2405,32 @@ async function buildEvmMultisignBodyUniswapV4LiquidityBatchInternal(args) {
|
|
|
2349
2405
|
value: target.amount,
|
|
2350
2406
|
fallbackGas: UNISWAP_V4_LP_WETH_DEPOSIT_FALLBACK
|
|
2351
2407
|
});
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
args: [spender, target.amount]
|
|
2358
|
-
}),
|
|
2359
|
-
value: 0n,
|
|
2360
|
-
fallbackGas: UNISWAP_V4_LP_ERC20_APPROVE_FALLBACK
|
|
2408
|
+
const wethAllowance = await publicClient.readContract({
|
|
2409
|
+
address: target.token,
|
|
2410
|
+
abi: erc20AllowanceAbi2,
|
|
2411
|
+
functionName: "allowance",
|
|
2412
|
+
args: [executor, spender]
|
|
2361
2413
|
});
|
|
2414
|
+
if (wethAllowance < target.amount) {
|
|
2415
|
+
if (wethAllowance > 0n) {
|
|
2416
|
+
steps.push({
|
|
2417
|
+
to: target.token,
|
|
2418
|
+
data: encodeFunctionData({ abi: erc20Abi, functionName: "approve", args: [spender, 0n] }),
|
|
2419
|
+
value: 0n,
|
|
2420
|
+
fallbackGas: UNISWAP_V4_LP_ERC20_APPROVE_FALLBACK
|
|
2421
|
+
});
|
|
2422
|
+
}
|
|
2423
|
+
steps.push({
|
|
2424
|
+
to: target.token,
|
|
2425
|
+
data: encodeFunctionData({
|
|
2426
|
+
abi: erc20Abi,
|
|
2427
|
+
functionName: "approve",
|
|
2428
|
+
args: [spender, target.amount]
|
|
2429
|
+
}),
|
|
2430
|
+
value: 0n,
|
|
2431
|
+
fallbackGas: UNISWAP_V4_LP_ERC20_APPROVE_FALLBACK
|
|
2432
|
+
});
|
|
2433
|
+
}
|
|
2362
2434
|
} else {
|
|
2363
2435
|
steps.push({
|
|
2364
2436
|
to: target.token,
|