@continuumdao/ctm-mpc-defi 0.2.13 → 0.2.16
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 +828 -280
- package/dist/agent/catalog.cjs.map +1 -1
- package/dist/agent/catalog.d.ts +1645 -300
- package/dist/agent/catalog.js +823 -281
- package/dist/agent/catalog.js.map +1 -1
- 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/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 +1 -1
package/dist/index.cjs
CHANGED
|
@@ -371,6 +371,77 @@ function normalizeHumanDecimalAmount(raw, tokenDecimals) {
|
|
|
371
371
|
return viem.formatUnits(wei, tokenDecimals);
|
|
372
372
|
}
|
|
373
373
|
var normalizeCurveRouterAmountString = normalizeHumanDecimalAmount;
|
|
374
|
+
var erc20AllowanceAbi = viem.parseAbi([
|
|
375
|
+
"function allowance(address owner, address spender) view returns (uint256)",
|
|
376
|
+
"function decimals() view returns (uint8)"
|
|
377
|
+
]);
|
|
378
|
+
var erc20ApproveAbi = viem.parseAbi(["function approve(address spender, uint256 amount) returns (bool)"]);
|
|
379
|
+
function publicClientForRpc(chainId, rpcUrl) {
|
|
380
|
+
const ch = viem.defineChain({
|
|
381
|
+
id: chainId,
|
|
382
|
+
name: `chain-${chainId}`,
|
|
383
|
+
nativeCurrency: { decimals: 18, name: "Ether", symbol: "ETH" },
|
|
384
|
+
rpcUrls: { default: { http: [rpcUrl.trim()] } }
|
|
385
|
+
});
|
|
386
|
+
return viem.createPublicClient({ chain: ch, transport: viem.http(rpcUrl.trim()) });
|
|
387
|
+
}
|
|
388
|
+
async function resolveErc20Decimals(args) {
|
|
389
|
+
const token = viem.getAddress(args.token);
|
|
390
|
+
const onChain = await args.publicClient.readContract({
|
|
391
|
+
address: token,
|
|
392
|
+
abi: erc20AllowanceAbi,
|
|
393
|
+
functionName: "decimals"
|
|
394
|
+
});
|
|
395
|
+
const n = typeof onChain === "bigint" ? Number(onChain) : Number(onChain);
|
|
396
|
+
if (!Number.isFinite(n) || n < 0 || n > 36) {
|
|
397
|
+
throw new Error(`Invalid on-chain decimals for ${token}.`);
|
|
398
|
+
}
|
|
399
|
+
for (const hint of [args.registryDecimals, args.apiDecimals]) {
|
|
400
|
+
}
|
|
401
|
+
return n;
|
|
402
|
+
}
|
|
403
|
+
async function buildConditionalErc20ApproveSteps(args) {
|
|
404
|
+
if (args.amountWei <= 0n) return [];
|
|
405
|
+
const token = viem.getAddress(args.token);
|
|
406
|
+
const spender = viem.getAddress(args.spender);
|
|
407
|
+
const owner = viem.getAddress(args.owner);
|
|
408
|
+
const fallback = args.fallbackGas ?? 100000n;
|
|
409
|
+
const allowance = await args.publicClient.readContract({
|
|
410
|
+
address: token,
|
|
411
|
+
abi: erc20AllowanceAbi,
|
|
412
|
+
functionName: "allowance",
|
|
413
|
+
args: [owner, spender]
|
|
414
|
+
});
|
|
415
|
+
if (allowance >= args.amountWei) return [];
|
|
416
|
+
const steps = [];
|
|
417
|
+
if (allowance > 0n) {
|
|
418
|
+
steps.push({
|
|
419
|
+
to: token,
|
|
420
|
+
data: viem.encodeFunctionData({ abi: erc20ApproveAbi, functionName: "approve", args: [spender, 0n] }),
|
|
421
|
+
value: 0n,
|
|
422
|
+
fallbackGas: fallback
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
steps.push({
|
|
426
|
+
to: token,
|
|
427
|
+
data: viem.encodeFunctionData({
|
|
428
|
+
abi: erc20ApproveAbi,
|
|
429
|
+
functionName: "approve",
|
|
430
|
+
args: [spender, args.amountWei]
|
|
431
|
+
}),
|
|
432
|
+
value: 0n,
|
|
433
|
+
fallbackGas: fallback
|
|
434
|
+
});
|
|
435
|
+
return steps;
|
|
436
|
+
}
|
|
437
|
+
function approveStepsToEvmTxSteps(steps) {
|
|
438
|
+
return steps.map((s) => ({
|
|
439
|
+
to: s.to,
|
|
440
|
+
data: s.data,
|
|
441
|
+
value: s.value,
|
|
442
|
+
fallbackGas: s.fallbackGas
|
|
443
|
+
}));
|
|
444
|
+
}
|
|
374
445
|
|
|
375
446
|
// src/chains/evm/coingecko.ts
|
|
376
447
|
var COINGECKO_PLATFORM_BY_CHAIN_ID = {
|
|
@@ -1152,10 +1223,23 @@ async function buildEvmMultisignBodyUniswapV4SkipPermit2Batch(args) {
|
|
|
1152
1223
|
if (expiration48 > MAX_UINT48) expiration48 = MAX_UINT48;
|
|
1153
1224
|
}
|
|
1154
1225
|
const erc20ApproveSpender = usePermit2Triple ? PERMIT2_ADDRESS : toRouter;
|
|
1155
|
-
const
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1226
|
+
const executor = viem.getAddress(args.executorAddress);
|
|
1227
|
+
const publicClient = viem.createPublicClient({
|
|
1228
|
+
chain: viem.defineChain({
|
|
1229
|
+
id: args.chainId,
|
|
1230
|
+
name: `uniswap-swap-${args.chainId}`,
|
|
1231
|
+
nativeCurrency: { decimals: 18, name: "Ether", symbol: "ETH" },
|
|
1232
|
+
rpcUrls: { default: { http: [args.rpcUrl] } }
|
|
1233
|
+
}),
|
|
1234
|
+
transport: viem.http(args.rpcUrl)
|
|
1235
|
+
});
|
|
1236
|
+
const erc20ApproveSteps = await buildConditionalErc20ApproveSteps({
|
|
1237
|
+
publicClient,
|
|
1238
|
+
token: tokenIn,
|
|
1239
|
+
spender: erc20ApproveSpender,
|
|
1240
|
+
owner: executor,
|
|
1241
|
+
amountWei: approveAmountWei,
|
|
1242
|
+
fallbackGas: 100000n
|
|
1159
1243
|
});
|
|
1160
1244
|
const valueWei = (() => {
|
|
1161
1245
|
const v = args.swap.value;
|
|
@@ -1167,13 +1251,16 @@ async function buildEvmMultisignBodyUniswapV4SkipPermit2Batch(args) {
|
|
|
1167
1251
|
}
|
|
1168
1252
|
})();
|
|
1169
1253
|
const swapRecord = args.swap;
|
|
1170
|
-
const swapMsgIndex = usePermit2Triple ?
|
|
1254
|
+
const swapMsgIndex = usePermit2Triple ? erc20ApproveSteps.length + 1 : erc20ApproveSteps.length;
|
|
1171
1255
|
let gasBuildSource = "rpcEstimate";
|
|
1172
1256
|
let estimateGasError;
|
|
1173
1257
|
let swapBaseGasUnits = DEFAULT_UNIVERSAL_ROUTER_GAS_FALLBACK;
|
|
1174
|
-
const steps =
|
|
1175
|
-
|
|
1176
|
-
|
|
1258
|
+
const steps = erc20ApproveSteps.map((s) => ({
|
|
1259
|
+
to: s.to,
|
|
1260
|
+
data: s.data,
|
|
1261
|
+
value: s.value,
|
|
1262
|
+
fallbackGas: s.fallbackGas
|
|
1263
|
+
}));
|
|
1177
1264
|
if (usePermit2Triple) {
|
|
1178
1265
|
const permit2ApproveData = viem.encodeFunctionData({
|
|
1179
1266
|
abi: permit2ApproveRouterAbi,
|
|
@@ -1190,8 +1277,9 @@ async function buildEvmMultisignBodyUniswapV4SkipPermit2Batch(args) {
|
|
|
1190
1277
|
fallbackGas: DEFAULT_UNIVERSAL_ROUTER_GAS_FALLBACK
|
|
1191
1278
|
});
|
|
1192
1279
|
const swapStepIndex = steps.length - 1;
|
|
1193
|
-
const approveMsgRawNo0x =
|
|
1194
|
-
const
|
|
1280
|
+
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;
|
|
1281
|
+
const approveCount = erc20ApproveSteps.length;
|
|
1282
|
+
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).";
|
|
1195
1283
|
const buildSwapAudit = () => ({
|
|
1196
1284
|
skipPermit2Batch: true,
|
|
1197
1285
|
approvalPath: usePermit2Triple ? "permit2_triple" : "dispatcher",
|
|
@@ -1268,18 +1356,18 @@ async function buildEvmMultisignBodyUniswapV4SkipPermit2Batch(args) {
|
|
|
1268
1356
|
firstMsgRawNo0x: approveMsgRawNo0x,
|
|
1269
1357
|
destinationAddress: tokenIn,
|
|
1270
1358
|
payableValueWei: valueWei > 0n ? valueWei : void 0,
|
|
1271
|
-
estimateGasForStep: async ({ step, index, publicClient, executor }) => {
|
|
1359
|
+
estimateGasForStep: async ({ step, index, publicClient: publicClient2, executor: executor2 }) => {
|
|
1272
1360
|
if (index !== swapStepIndex) {
|
|
1273
|
-
return
|
|
1361
|
+
return publicClient2.estimateGas({
|
|
1274
1362
|
to: step.to,
|
|
1275
1363
|
data: step.data,
|
|
1276
1364
|
value: step.value,
|
|
1277
|
-
account:
|
|
1365
|
+
account: executor2
|
|
1278
1366
|
});
|
|
1279
1367
|
}
|
|
1280
1368
|
const r = await estimateUniswapRouterSwapGas({
|
|
1281
|
-
publicClient,
|
|
1282
|
-
executor,
|
|
1369
|
+
publicClient: publicClient2,
|
|
1370
|
+
executor: executor2,
|
|
1283
1371
|
to: toRouter,
|
|
1284
1372
|
data: dataHex,
|
|
1285
1373
|
value: valueWei,
|
|
@@ -1782,7 +1870,7 @@ function isNativeUniswapLpTokenAddress(token) {
|
|
|
1782
1870
|
|
|
1783
1871
|
// src/protocols/evm/uniswap-v4/liquidityMultisign.ts
|
|
1784
1872
|
var wethDepositAbi = viem.parseAbi(["function deposit() payable"]);
|
|
1785
|
-
var
|
|
1873
|
+
var erc20AllowanceAbi2 = viem.parseAbi([
|
|
1786
1874
|
"function allowance(address owner, address spender) view returns (uint256)",
|
|
1787
1875
|
"function decimals() view returns (uint8)"
|
|
1788
1876
|
]);
|
|
@@ -1856,7 +1944,7 @@ async function resolveApproveTargets(args) {
|
|
|
1856
1944
|
}
|
|
1857
1945
|
const allowance = await args.publicClient.readContract({
|
|
1858
1946
|
address: row.token,
|
|
1859
|
-
abi:
|
|
1947
|
+
abi: erc20AllowanceAbi2,
|
|
1860
1948
|
functionName: "allowance",
|
|
1861
1949
|
args: [args.executor, args.spender]
|
|
1862
1950
|
});
|
|
@@ -1898,16 +1986,32 @@ async function buildEvmMultisignBodyUniswapV4LiquidityBatchInternal(args) {
|
|
|
1898
1986
|
value: target.amount,
|
|
1899
1987
|
fallbackGas: UNISWAP_V4_LP_WETH_DEPOSIT_FALLBACK
|
|
1900
1988
|
});
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
args: [spender, target.amount]
|
|
1907
|
-
}),
|
|
1908
|
-
value: 0n,
|
|
1909
|
-
fallbackGas: UNISWAP_V4_LP_ERC20_APPROVE_FALLBACK
|
|
1989
|
+
const wethAllowance = await publicClient.readContract({
|
|
1990
|
+
address: target.token,
|
|
1991
|
+
abi: erc20AllowanceAbi2,
|
|
1992
|
+
functionName: "allowance",
|
|
1993
|
+
args: [executor, spender]
|
|
1910
1994
|
});
|
|
1995
|
+
if (wethAllowance < target.amount) {
|
|
1996
|
+
if (wethAllowance > 0n) {
|
|
1997
|
+
steps.push({
|
|
1998
|
+
to: target.token,
|
|
1999
|
+
data: viem.encodeFunctionData({ abi: viem.erc20Abi, functionName: "approve", args: [spender, 0n] }),
|
|
2000
|
+
value: 0n,
|
|
2001
|
+
fallbackGas: UNISWAP_V4_LP_ERC20_APPROVE_FALLBACK
|
|
2002
|
+
});
|
|
2003
|
+
}
|
|
2004
|
+
steps.push({
|
|
2005
|
+
to: target.token,
|
|
2006
|
+
data: viem.encodeFunctionData({
|
|
2007
|
+
abi: viem.erc20Abi,
|
|
2008
|
+
functionName: "approve",
|
|
2009
|
+
args: [spender, target.amount]
|
|
2010
|
+
}),
|
|
2011
|
+
value: 0n,
|
|
2012
|
+
fallbackGas: UNISWAP_V4_LP_ERC20_APPROVE_FALLBACK
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
1911
2015
|
} else {
|
|
1912
2016
|
steps.push({
|
|
1913
2017
|
to: target.token,
|
|
@@ -2347,36 +2451,36 @@ async function buildEvmMultisignBodyCurveDaoBatch(args) {
|
|
|
2347
2451
|
rpcUrls: { default: { http: [args.rpcUrl] } }
|
|
2348
2452
|
});
|
|
2349
2453
|
const publicClient = viem.createPublicClient({ chain: ch, transport: viem.http(args.rpcUrl) });
|
|
2350
|
-
const
|
|
2454
|
+
const erc20AllowanceAbi3 = viem.parseAbi([
|
|
2351
2455
|
"function allowance(address owner, address spender) view returns (uint256)",
|
|
2352
2456
|
"function decimals() view returns (uint8)"
|
|
2353
2457
|
]);
|
|
2354
|
-
const
|
|
2458
|
+
const erc20ApproveAbi2 = viem.parseAbi(["function approve(address spender, uint256 amount) returns (bool)"]);
|
|
2355
2459
|
const steps = [];
|
|
2356
2460
|
if (!isNativeIn) {
|
|
2357
2461
|
const decimalsN = await publicClient.readContract({
|
|
2358
2462
|
address: tokenIn,
|
|
2359
|
-
abi:
|
|
2463
|
+
abi: erc20AllowanceAbi3,
|
|
2360
2464
|
functionName: "decimals"
|
|
2361
2465
|
});
|
|
2362
2466
|
const amountWei = viem.parseUnits(args.amountHuman, Number(decimalsN));
|
|
2363
2467
|
const currentAllowance = await publicClient.readContract({
|
|
2364
2468
|
address: tokenIn,
|
|
2365
|
-
abi:
|
|
2469
|
+
abi: erc20AllowanceAbi3,
|
|
2366
2470
|
functionName: "allowance",
|
|
2367
2471
|
args: [executor, routerAddr]
|
|
2368
2472
|
});
|
|
2369
2473
|
if (currentAllowance < amountWei) {
|
|
2370
2474
|
if (currentAllowance > 0n) {
|
|
2371
2475
|
const dataReset = viem.encodeFunctionData({
|
|
2372
|
-
abi:
|
|
2476
|
+
abi: erc20ApproveAbi2,
|
|
2373
2477
|
functionName: "approve",
|
|
2374
2478
|
args: [routerAddr, 0n]
|
|
2375
2479
|
});
|
|
2376
2480
|
steps.push({ to: tokenIn, data: dataReset, value: 0n, kind: "approve", fallbackGas: 80000n });
|
|
2377
2481
|
}
|
|
2378
2482
|
const dataApprove = viem.encodeFunctionData({
|
|
2379
|
-
abi:
|
|
2483
|
+
abi: erc20ApproveAbi2,
|
|
2380
2484
|
functionName: "approve",
|
|
2381
2485
|
args: [routerAddr, amountWei]
|
|
2382
2486
|
});
|
|
@@ -2520,6 +2624,8 @@ Object.defineProperty(exports, "firstClientIdFromKeyGen", {
|
|
|
2520
2624
|
exports.COINGECKO_PLATFORM_BY_CHAIN_ID = COINGECKO_PLATFORM_BY_CHAIN_ID;
|
|
2521
2625
|
exports.NEAR_CHAIN_CATEGORY = NEAR_CHAIN_CATEGORY;
|
|
2522
2626
|
exports.SOLANA_CHAIN_CATEGORY = SOLANA_CHAIN_CATEGORY;
|
|
2627
|
+
exports.approveStepsToEvmTxSteps = approveStepsToEvmTxSteps;
|
|
2628
|
+
exports.buildConditionalErc20ApproveSteps = buildConditionalErc20ApproveSteps;
|
|
2523
2629
|
exports.buildEvmMultisignBatch = buildEvmMultisignBatch;
|
|
2524
2630
|
exports.coingeckoPlatformForChainId = coingeckoPlatformForChainId;
|
|
2525
2631
|
exports.coreChainCategoryModule = coreChainCategoryModule;
|
|
@@ -2543,7 +2649,9 @@ exports.normalizeCurveRouterAmountString = normalizeCurveRouterAmountString;
|
|
|
2543
2649
|
exports.normalizeHumanDecimalAmount = normalizeHumanDecimalAmount;
|
|
2544
2650
|
exports.parseEvmChainIdToNumber = parseEvmChainIdToNumber;
|
|
2545
2651
|
exports.postJsonViaOptionalProxy = postJsonViaOptionalProxy;
|
|
2652
|
+
exports.publicClientForRpc = publicClientForRpc;
|
|
2546
2653
|
exports.registerProtocolModule = registerProtocolModule;
|
|
2654
|
+
exports.resolveErc20Decimals = resolveErc20Decimals;
|
|
2547
2655
|
exports.routerSwapGasLimitFromEstimate = routerSwapGasLimitFromEstimate;
|
|
2548
2656
|
exports.setAaveGraphqlProxyUrl = setAaveGraphqlProxyUrl;
|
|
2549
2657
|
exports.setCoingeckoProxyUrl = setCoingeckoProxyUrl;
|