@continuumdao/ctm-mpc-defi 0.2.3 → 0.2.5
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 +451 -31
- package/dist/agent/catalog.cjs.map +1 -1
- package/dist/agent/catalog.d.ts +938 -1
- package/dist/agent/catalog.js +432 -32
- package/dist/agent/catalog.js.map +1 -1
- package/dist/agent/skills/aave-v4/SKILL.md +120 -14
- package/dist/agent/skills/curve-dao/SKILL.md +125 -6
- package/dist/agent/skills/uniswap-v4/SKILL.md +195 -11
- package/dist/index.cjs +757 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +758 -5
- package/dist/index.js.map +1 -1
- package/dist/protocols/evm/curve-dao/index.cjs +15 -2
- package/dist/protocols/evm/curve-dao/index.cjs.map +1 -1
- package/dist/protocols/evm/curve-dao/index.js +15 -2
- package/dist/protocols/evm/curve-dao/index.js.map +1 -1
- package/dist/protocols/evm/uniswap-v4/index.cjs +1231 -1
- package/dist/protocols/evm/uniswap-v4/index.cjs.map +1 -1
- package/dist/protocols/evm/uniswap-v4/index.d.ts +366 -4
- package/dist/protocols/evm/uniswap-v4/index.js +1182 -3
- package/dist/protocols/evm/uniswap-v4/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -473,6 +473,44 @@ var UNISWAP_UNIVERSAL_ROUTER_DEFAULT_GAS_UNITS = 1500000n;
|
|
|
473
473
|
var UNISWAP_TRADE_BASE_DEFAULT = "https://trade-api.gateway.uniswap.org/v1";
|
|
474
474
|
var UNISWAP_UNIVERSAL_ROUTER_VERSION_DEFAULT = "2.0";
|
|
475
475
|
var UNISWAP_SWAP_DEFAULT_EXPIRY_MINUTES = 30;
|
|
476
|
+
var UNISWAP_LP_DEFAULT_EXPIRY_MINUTES = 30;
|
|
477
|
+
var UNISWAP_LP_DEFAULT_DEADLINE_SEC_OFFSET = UNISWAP_LP_DEFAULT_EXPIRY_MINUTES * 60;
|
|
478
|
+
var UNISWAP_LP_DEFAULT_SLIPPAGE_PERCENT = 0.5;
|
|
479
|
+
var POSITION_MANAGER_BY_CHAIN = {
|
|
480
|
+
1: "0xbd216513d74c8cf14cf4747e6aaa6420ff64ee9e",
|
|
481
|
+
10: "0x3c3ea4b57a46241e54610e5f022e5c45859a1017",
|
|
482
|
+
137: "0x1ec2ebf4f37e7363fdfe3551602425af0b3ceef9",
|
|
483
|
+
42161: "0xd88f38f930b7952f2db2432cb002e7abbf3dd869",
|
|
484
|
+
8453: "0x7C5f5A4bBd8fD63184577525326123B519429bDc",
|
|
485
|
+
11155111: "0x4B2C77d209D3405F41a037Ec6c77F7F5b8e2ca80",
|
|
486
|
+
130: "0x0d97dc33264bfc1c226207428a79b26757fb9dc3",
|
|
487
|
+
1868: "0x0e2850543f69f678257266e0907ff9a58b3f13de",
|
|
488
|
+
59144: "0x661e93cca42afacb172121ef892830ca3b70f08d"
|
|
489
|
+
};
|
|
490
|
+
function getUniswapV4PositionManagerOrThrow(chainId) {
|
|
491
|
+
const raw = POSITION_MANAGER_BY_CHAIN[chainId];
|
|
492
|
+
if (!raw || !raw.startsWith("0x") || raw.length !== 42) {
|
|
493
|
+
throw new Error(
|
|
494
|
+
`No Uniswap V4 PositionManager is configured for chainId ${chainId}. Add this chain to uniswap-v4/constants or pass position manager from LP API response.`
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
return viem.getAddress(raw);
|
|
498
|
+
}
|
|
499
|
+
var POSITION_MANAGER_DEPLOY_BLOCK_BY_CHAIN = {
|
|
500
|
+
/** Ethereum mainnet — Uniswap v4 launch (Jan 2025). */
|
|
501
|
+
1: 22938741n
|
|
502
|
+
};
|
|
503
|
+
var UNISWAP_V4_LP_LOG_CHUNK_SIZE_DEFAULT = 200n;
|
|
504
|
+
var UNISWAP_V4_LP_LOG_CHUNK_SIZE_MIN = 10n;
|
|
505
|
+
function getUniswapV4PositionManagerDeployBlock(chainId) {
|
|
506
|
+
return POSITION_MANAGER_DEPLOY_BLOCK_BY_CHAIN[chainId];
|
|
507
|
+
}
|
|
508
|
+
var UNISWAP_V4_LP_MINT_DEFAULT_GAS_UNITS = 1800000n;
|
|
509
|
+
var UNISWAP_V4_LP_INCREASE_DEFAULT_GAS_UNITS = 1500000n;
|
|
510
|
+
var UNISWAP_V4_LP_DECREASE_DEFAULT_GAS_UNITS = 1200000n;
|
|
511
|
+
var UNISWAP_V4_LP_COLLECT_DEFAULT_GAS_UNITS = 900000n;
|
|
512
|
+
var UNISWAP_V4_LP_ERC20_APPROVE_FALLBACK = 100000n;
|
|
513
|
+
var UNISWAP_V4_LP_WETH_DEPOSIT_FALLBACK = 120000n;
|
|
476
514
|
var DEFAULT_TRADE_BASE = "https://trade-api.gateway.uniswap.org/v1";
|
|
477
515
|
var UNISWAP_QUOTE_HEADERS_BASE = {
|
|
478
516
|
"Content-Type": "application/json",
|
|
@@ -722,7 +760,16 @@ function parseUniswapQuoteClassicInOut(res) {
|
|
|
722
760
|
const input = q.input;
|
|
723
761
|
const output = q.output;
|
|
724
762
|
const inAm = input?.amount;
|
|
725
|
-
|
|
763
|
+
let outAm = output?.amount;
|
|
764
|
+
if (typeof outAm !== "string" || !outAm) {
|
|
765
|
+
const agg = q.aggregatedOutputs;
|
|
766
|
+
if (Array.isArray(agg) && agg.length > 0) {
|
|
767
|
+
const first = agg[0];
|
|
768
|
+
if (typeof first?.amount === "string" && first.amount) {
|
|
769
|
+
outAm = first.amount;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
}
|
|
726
773
|
if (typeof inAm !== "string" || !inAm || typeof outAm !== "string" || !outAm) return null;
|
|
727
774
|
try {
|
|
728
775
|
return { inputWei: BigInt(inAm), outputWei: BigInt(outAm) };
|
|
@@ -1289,6 +1336,657 @@ async function buildEvmMultisignBodyUniswapV4SkipPermit2Batch(args) {
|
|
|
1289
1336
|
}
|
|
1290
1337
|
});
|
|
1291
1338
|
}
|
|
1339
|
+
var UNISWAP_V4_LP_POOL_LOOKUP_HINT = "Pool may not be initialized on this chain. Call ctm_uniswap_v4_list_lp_pools for other presets, pass a custom existingPool.poolReference, or use newPool to initialize a pool.";
|
|
1340
|
+
|
|
1341
|
+
// src/protocols/evm/uniswap-v4/liquidityApi.ts
|
|
1342
|
+
var LP_HEADERS_BASE = {
|
|
1343
|
+
"Content-Type": "application/json",
|
|
1344
|
+
Accept: "application/json",
|
|
1345
|
+
"User-Agent": "ctm-mpc-defi uniswapLpApi/1.0 (TS)"
|
|
1346
|
+
};
|
|
1347
|
+
function trimAddr2(a) {
|
|
1348
|
+
return a.trim();
|
|
1349
|
+
}
|
|
1350
|
+
function lpDeadlineUnix(nowSec = Math.floor(Date.now() / 1e3)) {
|
|
1351
|
+
return nowSec + UNISWAP_LP_DEFAULT_DEADLINE_SEC_OFFSET;
|
|
1352
|
+
}
|
|
1353
|
+
function resolveLpBaseUrl(baseUrl) {
|
|
1354
|
+
const raw = (baseUrl ?? UNISWAP_TRADE_BASE_DEFAULT).replace(/\/$/, "");
|
|
1355
|
+
return raw;
|
|
1356
|
+
}
|
|
1357
|
+
function resolveLpPath(baseUrl, action) {
|
|
1358
|
+
const normalized = baseUrl.replace(/\/$/, "");
|
|
1359
|
+
if (normalized.includes("api.uniswap.org")) {
|
|
1360
|
+
return `${normalized}/lp/${action}`;
|
|
1361
|
+
}
|
|
1362
|
+
return `${normalized}/lp/${action}`;
|
|
1363
|
+
}
|
|
1364
|
+
async function postUniswapLpApi(args) {
|
|
1365
|
+
const useProxy = args.useServerProxy !== false && typeof globalThis !== "undefined" && typeof globalThis.window !== "undefined";
|
|
1366
|
+
if (useProxy && args.proxyPath) {
|
|
1367
|
+
const fn2 = args.fetchImpl ?? globalThis.fetch;
|
|
1368
|
+
const res2 = await fn2(args.proxyPath, {
|
|
1369
|
+
method: "POST",
|
|
1370
|
+
headers: { "Content-Type": "application/json" },
|
|
1371
|
+
body: JSON.stringify({
|
|
1372
|
+
uniswapApiKey: args.uniswapApiKey,
|
|
1373
|
+
baseUrl: args.baseUrl,
|
|
1374
|
+
body: args.body
|
|
1375
|
+
}),
|
|
1376
|
+
credentials: "same-origin"
|
|
1377
|
+
});
|
|
1378
|
+
const text2 = await res2.text();
|
|
1379
|
+
if (!res2.ok) {
|
|
1380
|
+
let errMsg = res2.statusText;
|
|
1381
|
+
try {
|
|
1382
|
+
const j = JSON.parse(text2);
|
|
1383
|
+
if (j?.error?.trim()) errMsg = j.error.trim();
|
|
1384
|
+
} catch {
|
|
1385
|
+
if (text2.trim()) errMsg = text2.slice(0, 500);
|
|
1386
|
+
}
|
|
1387
|
+
throw new Error(`Uniswap LP proxy failed: ${errMsg}`);
|
|
1388
|
+
}
|
|
1389
|
+
return JSON.parse(text2);
|
|
1390
|
+
}
|
|
1391
|
+
const base = resolveLpBaseUrl(args.baseUrl);
|
|
1392
|
+
const url = resolveLpPath(base, args.path);
|
|
1393
|
+
const fn = args.fetchImpl ?? globalThis.fetch;
|
|
1394
|
+
const res = await fn(url, {
|
|
1395
|
+
method: "POST",
|
|
1396
|
+
headers: {
|
|
1397
|
+
...LP_HEADERS_BASE,
|
|
1398
|
+
"x-api-key": args.uniswapApiKey.trim()
|
|
1399
|
+
},
|
|
1400
|
+
body: JSON.stringify(args.body)
|
|
1401
|
+
});
|
|
1402
|
+
const text = await res.text();
|
|
1403
|
+
if (!res.ok) {
|
|
1404
|
+
const base2 = messageFromUniswapHttpResponseBody(text, res.status, res.statusText);
|
|
1405
|
+
const hint = args.path === "create" && args.body.existingPool ? ` ${UNISWAP_V4_LP_POOL_LOOKUP_HINT}` : "";
|
|
1406
|
+
throw new Error(`Uniswap LP POST /${args.path} failed: ${base2}${hint}`);
|
|
1407
|
+
}
|
|
1408
|
+
return JSON.parse(text);
|
|
1409
|
+
}
|
|
1410
|
+
function extractUniswapLpTransaction(response, field) {
|
|
1411
|
+
const tx = response[field];
|
|
1412
|
+
if (!tx || typeof tx !== "object" || Array.isArray(tx)) {
|
|
1413
|
+
throw new Error(`Uniswap LP response missing \`${field}\` transaction object.`);
|
|
1414
|
+
}
|
|
1415
|
+
const o = tx;
|
|
1416
|
+
const to = String(o.to ?? "").trim();
|
|
1417
|
+
const data = String(o.data ?? "").trim();
|
|
1418
|
+
if (!to.startsWith("0x") || !data.startsWith("0x") || data === "0x") {
|
|
1419
|
+
throw new Error(`Uniswap LP \`${field}\` transaction has invalid to/data.`);
|
|
1420
|
+
}
|
|
1421
|
+
return {
|
|
1422
|
+
to,
|
|
1423
|
+
from: o.from != null ? String(o.from) : void 0,
|
|
1424
|
+
data,
|
|
1425
|
+
value: String(o.value ?? "0"),
|
|
1426
|
+
chainId: typeof o.chainId === "number" ? o.chainId : void 0,
|
|
1427
|
+
gasLimit: o.gasLimit != null ? String(o.gasLimit) : void 0,
|
|
1428
|
+
gasPrice: o.gasPrice != null ? String(o.gasPrice) : void 0,
|
|
1429
|
+
maxFeePerGas: o.maxFeePerGas != null ? String(o.maxFeePerGas) : void 0,
|
|
1430
|
+
maxPriorityFeePerGas: o.maxPriorityFeePerGas != null ? String(o.maxPriorityFeePerGas) : void 0
|
|
1431
|
+
};
|
|
1432
|
+
}
|
|
1433
|
+
function extractUniswapLpTokenAmounts(response) {
|
|
1434
|
+
const read = (key) => {
|
|
1435
|
+
const raw = response[key];
|
|
1436
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
|
|
1437
|
+
const o = raw;
|
|
1438
|
+
const tokenAddress = String(o.tokenAddress ?? o.token ?? "").trim();
|
|
1439
|
+
const amount = String(o.amount ?? "").trim();
|
|
1440
|
+
if (!tokenAddress.startsWith("0x") || !amount) return void 0;
|
|
1441
|
+
return { tokenAddress, amount };
|
|
1442
|
+
};
|
|
1443
|
+
return { token0: read("token0"), token1: read("token1") };
|
|
1444
|
+
}
|
|
1445
|
+
async function uniswapLpCreatePosition(args) {
|
|
1446
|
+
const body = {
|
|
1447
|
+
protocol: "V4",
|
|
1448
|
+
walletAddress: trimAddr2(args.walletAddress),
|
|
1449
|
+
chainId: args.chainId,
|
|
1450
|
+
independentToken: {
|
|
1451
|
+
tokenAddress: trimAddr2(args.independentToken.tokenAddress),
|
|
1452
|
+
amount: String(args.independentToken.amount).trim()
|
|
1453
|
+
},
|
|
1454
|
+
slippageTolerance: args.slippageTolerance ?? UNISWAP_LP_DEFAULT_SLIPPAGE_PERCENT,
|
|
1455
|
+
deadline: args.deadline ?? lpDeadlineUnix(),
|
|
1456
|
+
simulateTransaction: args.simulateTransaction ?? false
|
|
1457
|
+
};
|
|
1458
|
+
if (args.existingPool) {
|
|
1459
|
+
body.existingPool = {
|
|
1460
|
+
token0Address: trimAddr2(args.existingPool.token0Address),
|
|
1461
|
+
token1Address: trimAddr2(args.existingPool.token1Address),
|
|
1462
|
+
poolReference: trimAddr2(args.existingPool.poolReference)
|
|
1463
|
+
};
|
|
1464
|
+
}
|
|
1465
|
+
if (args.newPool) {
|
|
1466
|
+
body.newPool = {
|
|
1467
|
+
token0Address: trimAddr2(args.newPool.token0Address),
|
|
1468
|
+
token1Address: trimAddr2(args.newPool.token1Address),
|
|
1469
|
+
fee: args.newPool.fee,
|
|
1470
|
+
tickSpacing: args.newPool.tickSpacing,
|
|
1471
|
+
initialPrice: String(args.newPool.initialPrice).trim(),
|
|
1472
|
+
...args.newPool.hooks ? { hooks: trimAddr2(args.newPool.hooks) } : {}
|
|
1473
|
+
};
|
|
1474
|
+
}
|
|
1475
|
+
if (!args.existingPool && !args.newPool) {
|
|
1476
|
+
throw new Error("Provide existingPool or newPool for LP create.");
|
|
1477
|
+
}
|
|
1478
|
+
if (args.priceBounds) {
|
|
1479
|
+
body.priceBounds = {
|
|
1480
|
+
minPrice: String(args.priceBounds.minPrice).trim(),
|
|
1481
|
+
maxPrice: String(args.priceBounds.maxPrice).trim()
|
|
1482
|
+
};
|
|
1483
|
+
}
|
|
1484
|
+
if (args.tickBounds) {
|
|
1485
|
+
body.tickBounds = {
|
|
1486
|
+
tickLower: args.tickBounds.tickLower,
|
|
1487
|
+
tickUpper: args.tickBounds.tickUpper
|
|
1488
|
+
};
|
|
1489
|
+
}
|
|
1490
|
+
if (!args.priceBounds && !args.tickBounds) {
|
|
1491
|
+
throw new Error("Provide priceBounds or tickBounds for LP create.");
|
|
1492
|
+
}
|
|
1493
|
+
if (args.batchPermitData) body.batchPermitData = args.batchPermitData;
|
|
1494
|
+
if (args.signature) body.signature = args.signature;
|
|
1495
|
+
return postUniswapLpApi({
|
|
1496
|
+
uniswapApiKey: args.uniswapApiKey,
|
|
1497
|
+
path: "create",
|
|
1498
|
+
body,
|
|
1499
|
+
baseUrl: args.baseUrl,
|
|
1500
|
+
fetchImpl: args.fetchImpl,
|
|
1501
|
+
useServerProxy: args.useServerProxy,
|
|
1502
|
+
proxyPath: "/api/uniswap/liquidity/create"
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
async function uniswapLpIncreasePosition(args) {
|
|
1506
|
+
const body = {
|
|
1507
|
+
protocol: "V4",
|
|
1508
|
+
walletAddress: trimAddr2(args.walletAddress),
|
|
1509
|
+
chainId: args.chainId,
|
|
1510
|
+
token0Address: trimAddr2(args.token0Address),
|
|
1511
|
+
token1Address: trimAddr2(args.token1Address),
|
|
1512
|
+
nftTokenId: String(args.nftTokenId),
|
|
1513
|
+
independentToken: {
|
|
1514
|
+
tokenAddress: trimAddr2(args.independentToken.tokenAddress),
|
|
1515
|
+
amount: String(args.independentToken.amount).trim()
|
|
1516
|
+
},
|
|
1517
|
+
slippageTolerance: args.slippageTolerance ?? UNISWAP_LP_DEFAULT_SLIPPAGE_PERCENT,
|
|
1518
|
+
deadline: args.deadline ?? lpDeadlineUnix(),
|
|
1519
|
+
simulateTransaction: args.simulateTransaction ?? false
|
|
1520
|
+
};
|
|
1521
|
+
if (args.v4BatchPermitData) body.v4BatchPermitData = args.v4BatchPermitData;
|
|
1522
|
+
if (args.signature) body.signature = args.signature;
|
|
1523
|
+
return postUniswapLpApi({
|
|
1524
|
+
uniswapApiKey: args.uniswapApiKey,
|
|
1525
|
+
path: "increase",
|
|
1526
|
+
body,
|
|
1527
|
+
baseUrl: args.baseUrl,
|
|
1528
|
+
fetchImpl: args.fetchImpl,
|
|
1529
|
+
useServerProxy: args.useServerProxy,
|
|
1530
|
+
proxyPath: "/api/uniswap/liquidity/increase"
|
|
1531
|
+
});
|
|
1532
|
+
}
|
|
1533
|
+
async function uniswapLpDecreasePosition(args) {
|
|
1534
|
+
const pct = Math.trunc(args.liquidityPercentageToDecrease);
|
|
1535
|
+
if (!Number.isFinite(pct) || pct < 1 || pct > 100) {
|
|
1536
|
+
throw new Error("liquidityPercentageToDecrease must be an integer from 1 to 100.");
|
|
1537
|
+
}
|
|
1538
|
+
const body = {
|
|
1539
|
+
protocol: "V4",
|
|
1540
|
+
walletAddress: trimAddr2(args.walletAddress),
|
|
1541
|
+
chainId: args.chainId,
|
|
1542
|
+
token0Address: trimAddr2(args.token0Address),
|
|
1543
|
+
token1Address: trimAddr2(args.token1Address),
|
|
1544
|
+
nftTokenId: String(args.nftTokenId),
|
|
1545
|
+
liquidityPercentageToDecrease: pct,
|
|
1546
|
+
slippageTolerance: args.slippageTolerance ?? UNISWAP_LP_DEFAULT_SLIPPAGE_PERCENT,
|
|
1547
|
+
deadline: args.deadline ?? lpDeadlineUnix(),
|
|
1548
|
+
simulateTransaction: args.simulateTransaction ?? false
|
|
1549
|
+
};
|
|
1550
|
+
return postUniswapLpApi({
|
|
1551
|
+
uniswapApiKey: args.uniswapApiKey,
|
|
1552
|
+
path: "decrease",
|
|
1553
|
+
body,
|
|
1554
|
+
baseUrl: args.baseUrl,
|
|
1555
|
+
fetchImpl: args.fetchImpl,
|
|
1556
|
+
useServerProxy: args.useServerProxy,
|
|
1557
|
+
proxyPath: "/api/uniswap/liquidity/decrease"
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1560
|
+
async function uniswapLpClaimFees(args) {
|
|
1561
|
+
const body = {
|
|
1562
|
+
protocol: "V4",
|
|
1563
|
+
walletAddress: trimAddr2(args.walletAddress),
|
|
1564
|
+
chainId: args.chainId,
|
|
1565
|
+
tokenId: String(args.tokenId),
|
|
1566
|
+
simulateTransaction: args.simulateTransaction ?? false
|
|
1567
|
+
};
|
|
1568
|
+
return postUniswapLpApi({
|
|
1569
|
+
uniswapApiKey: args.uniswapApiKey,
|
|
1570
|
+
path: "claim",
|
|
1571
|
+
body,
|
|
1572
|
+
baseUrl: args.baseUrl,
|
|
1573
|
+
fetchImpl: args.fetchImpl,
|
|
1574
|
+
useServerProxy: args.useServerProxy,
|
|
1575
|
+
proxyPath: "/api/uniswap/liquidity/claim"
|
|
1576
|
+
});
|
|
1577
|
+
}
|
|
1578
|
+
var TX_FIELD_BY_ACTION = {
|
|
1579
|
+
mint: "create",
|
|
1580
|
+
increase: "increase",
|
|
1581
|
+
decrease: "decrease",
|
|
1582
|
+
collect: "claim"
|
|
1583
|
+
};
|
|
1584
|
+
function parseUniswapLpApiSnapshot(args) {
|
|
1585
|
+
const field = TX_FIELD_BY_ACTION[args.action];
|
|
1586
|
+
const transaction = extractUniswapLpTransaction(args.lpResponse, field);
|
|
1587
|
+
const amounts = extractUniswapLpTokenAmounts(args.lpResponse);
|
|
1588
|
+
const tickLower = typeof args.lpResponse.tickLower === "number" ? args.lpResponse.tickLower : void 0;
|
|
1589
|
+
const tickUpper = typeof args.lpResponse.tickUpper === "number" ? args.lpResponse.tickUpper : void 0;
|
|
1590
|
+
const minPrice = typeof args.lpResponse.minPrice === "string" ? args.lpResponse.minPrice : void 0;
|
|
1591
|
+
const maxPrice = typeof args.lpResponse.maxPrice === "string" ? args.lpResponse.maxPrice : void 0;
|
|
1592
|
+
return {
|
|
1593
|
+
transaction,
|
|
1594
|
+
token0: amounts.token0,
|
|
1595
|
+
token1: amounts.token1,
|
|
1596
|
+
tickLower,
|
|
1597
|
+
tickUpper,
|
|
1598
|
+
minPrice,
|
|
1599
|
+
maxPrice
|
|
1600
|
+
};
|
|
1601
|
+
}
|
|
1602
|
+
var erc721BalanceAbi = viem.parseAbi([
|
|
1603
|
+
"function balanceOf(address owner) view returns (uint256)",
|
|
1604
|
+
"function ownerOf(uint256 tokenId) view returns (address)"
|
|
1605
|
+
]);
|
|
1606
|
+
viem.parseAbi([
|
|
1607
|
+
"function positionInfo(uint256 tokenId) view returns (uint256 info)"
|
|
1608
|
+
]);
|
|
1609
|
+
viem.parseAbiItem(
|
|
1610
|
+
"event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)"
|
|
1611
|
+
);
|
|
1612
|
+
function throwIfScanAborted(signal) {
|
|
1613
|
+
if (signal?.aborted) {
|
|
1614
|
+
throw new DOMException("Position scan aborted.", "AbortError");
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
var TRANSFER_EVENT = {
|
|
1618
|
+
type: "event",
|
|
1619
|
+
name: "Transfer",
|
|
1620
|
+
inputs: [
|
|
1621
|
+
{ indexed: true, name: "from", type: "address" },
|
|
1622
|
+
{ indexed: true, name: "to", type: "address" },
|
|
1623
|
+
{ indexed: true, name: "tokenId", type: "uint256" }
|
|
1624
|
+
]
|
|
1625
|
+
};
|
|
1626
|
+
function isEthGetLogsBlockRangeTooLargeError(err) {
|
|
1627
|
+
const msg = (err instanceof Error ? err.message : String(err)).toLowerCase();
|
|
1628
|
+
return msg.includes("block range too large") || msg.includes("maximum allowed") || msg.includes("query returned more than") || msg.includes("exceed maximum block range") || msg.includes("block range is too large");
|
|
1629
|
+
}
|
|
1630
|
+
async function getTransferLogsForWalletInRange(args) {
|
|
1631
|
+
const { client, positionManager, wallet, fromBlock, toBlock } = args;
|
|
1632
|
+
let chunkSize = args.chunkSize < UNISWAP_V4_LP_LOG_CHUNK_SIZE_MIN ? UNISWAP_V4_LP_LOG_CHUNK_SIZE_MIN : args.chunkSize;
|
|
1633
|
+
const out = [];
|
|
1634
|
+
let from = fromBlock;
|
|
1635
|
+
while (from <= toBlock) {
|
|
1636
|
+
let to = from + chunkSize - 1n > toBlock ? toBlock : from + chunkSize - 1n;
|
|
1637
|
+
for (; ; ) {
|
|
1638
|
+
try {
|
|
1639
|
+
const [toLogs, fromLogs] = await Promise.all([
|
|
1640
|
+
client.getLogs({
|
|
1641
|
+
address: positionManager,
|
|
1642
|
+
event: TRANSFER_EVENT,
|
|
1643
|
+
args: { to: wallet },
|
|
1644
|
+
fromBlock: from,
|
|
1645
|
+
toBlock: to
|
|
1646
|
+
}),
|
|
1647
|
+
client.getLogs({
|
|
1648
|
+
address: positionManager,
|
|
1649
|
+
event: TRANSFER_EVENT,
|
|
1650
|
+
args: { from: wallet },
|
|
1651
|
+
fromBlock: from,
|
|
1652
|
+
toBlock: to
|
|
1653
|
+
})
|
|
1654
|
+
]);
|
|
1655
|
+
out.push(...toLogs, ...fromLogs);
|
|
1656
|
+
from = to + 1n;
|
|
1657
|
+
break;
|
|
1658
|
+
} catch (err) {
|
|
1659
|
+
if (!isEthGetLogsBlockRangeTooLargeError(err) || chunkSize <= UNISWAP_V4_LP_LOG_CHUNK_SIZE_MIN) {
|
|
1660
|
+
throw err;
|
|
1661
|
+
}
|
|
1662
|
+
chunkSize = chunkSize / 2n;
|
|
1663
|
+
if (chunkSize < UNISWAP_V4_LP_LOG_CHUNK_SIZE_MIN) {
|
|
1664
|
+
chunkSize = UNISWAP_V4_LP_LOG_CHUNK_SIZE_MIN;
|
|
1665
|
+
}
|
|
1666
|
+
to = from + chunkSize - 1n > toBlock ? toBlock : from + chunkSize - 1n;
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
return out;
|
|
1671
|
+
}
|
|
1672
|
+
function defaultScanFromBlock(args) {
|
|
1673
|
+
if (args.fromBlock != null) return args.fromBlock;
|
|
1674
|
+
const deploy = getUniswapV4PositionManagerDeployBlock(args.chainId);
|
|
1675
|
+
if (deploy != null) return deploy;
|
|
1676
|
+
return args.latest > args.maxBlocksToScan ? args.latest - args.maxBlocksToScan : 0n;
|
|
1677
|
+
}
|
|
1678
|
+
async function listUniswapV4PositionsForWallet(args) {
|
|
1679
|
+
throwIfScanAborted(args.signal);
|
|
1680
|
+
const wallet = viem.getAddress(args.walletAddress);
|
|
1681
|
+
const pm = viem.getAddress(
|
|
1682
|
+
args.positionManagerAddress ? String(args.positionManagerAddress) : getUniswapV4PositionManagerOrThrow(args.chainId)
|
|
1683
|
+
);
|
|
1684
|
+
const chain = viem.defineChain({
|
|
1685
|
+
id: args.chainId,
|
|
1686
|
+
name: `uniswap-v4-${args.chainId}`,
|
|
1687
|
+
nativeCurrency: { name: "ETH", symbol: "ETH", decimals: 18 },
|
|
1688
|
+
rpcUrls: { default: { http: [args.rpcUrl] } }
|
|
1689
|
+
});
|
|
1690
|
+
const client = viem.createPublicClient({ chain, transport: viem.http(args.rpcUrl) });
|
|
1691
|
+
const latest = await client.getBlockNumber();
|
|
1692
|
+
const maxScan = args.maxBlocksToScan ?? 500000n;
|
|
1693
|
+
const chunkSize = args.chunkSize ?? UNISWAP_V4_LP_LOG_CHUNK_SIZE_DEFAULT;
|
|
1694
|
+
const scanFrom = defaultScanFromBlock({
|
|
1695
|
+
chainId: args.chainId,
|
|
1696
|
+
latest,
|
|
1697
|
+
fromBlock: args.fromBlock,
|
|
1698
|
+
maxBlocksToScan: maxScan
|
|
1699
|
+
});
|
|
1700
|
+
const balance = await client.readContract({
|
|
1701
|
+
address: pm,
|
|
1702
|
+
abi: erc721BalanceAbi,
|
|
1703
|
+
functionName: "balanceOf",
|
|
1704
|
+
args: [wallet]
|
|
1705
|
+
});
|
|
1706
|
+
const targetCount = Number(balance);
|
|
1707
|
+
const emitProgress = (scanningFromBlock, scanningToBlock, foundCount) => {
|
|
1708
|
+
args.onProgress?.({
|
|
1709
|
+
latestBlock: latest.toString(),
|
|
1710
|
+
scanFromBlock: scanFrom.toString(),
|
|
1711
|
+
scanningFromBlock: scanningFromBlock.toString(),
|
|
1712
|
+
scanningToBlock: scanningToBlock.toString(),
|
|
1713
|
+
foundCount,
|
|
1714
|
+
targetCount
|
|
1715
|
+
});
|
|
1716
|
+
};
|
|
1717
|
+
if (balance === 0n) {
|
|
1718
|
+
emitProgress(latest, latest, 0);
|
|
1719
|
+
return [];
|
|
1720
|
+
}
|
|
1721
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
1722
|
+
const verified = /* @__PURE__ */ new Map();
|
|
1723
|
+
let toBlock = latest;
|
|
1724
|
+
while (toBlock >= scanFrom && verified.size < targetCount) {
|
|
1725
|
+
throwIfScanAborted(args.signal);
|
|
1726
|
+
let fromBlock = toBlock >= chunkSize - 1n ? toBlock - chunkSize + 1n : 0n;
|
|
1727
|
+
if (fromBlock < scanFrom) fromBlock = scanFrom;
|
|
1728
|
+
emitProgress(fromBlock, toBlock, verified.size);
|
|
1729
|
+
const logs = await getTransferLogsForWalletInRange({
|
|
1730
|
+
client,
|
|
1731
|
+
positionManager: pm,
|
|
1732
|
+
wallet,
|
|
1733
|
+
fromBlock,
|
|
1734
|
+
toBlock,
|
|
1735
|
+
chunkSize
|
|
1736
|
+
});
|
|
1737
|
+
for (const log of logs) {
|
|
1738
|
+
const tokenId = log.args.tokenId?.toString();
|
|
1739
|
+
if (!tokenId) continue;
|
|
1740
|
+
const to = log.args.to != null ? viem.getAddress(log.args.to) : null;
|
|
1741
|
+
const from = log.args.from != null ? viem.getAddress(log.args.from) : null;
|
|
1742
|
+
if (to === wallet) candidates.add(tokenId);
|
|
1743
|
+
if (from === wallet) candidates.delete(tokenId);
|
|
1744
|
+
}
|
|
1745
|
+
for (const tokenId of candidates) {
|
|
1746
|
+
if (verified.has(tokenId)) continue;
|
|
1747
|
+
try {
|
|
1748
|
+
const owner = await client.readContract({
|
|
1749
|
+
address: pm,
|
|
1750
|
+
abi: erc721BalanceAbi,
|
|
1751
|
+
functionName: "ownerOf",
|
|
1752
|
+
args: [BigInt(tokenId)]
|
|
1753
|
+
});
|
|
1754
|
+
if (viem.getAddress(owner) !== wallet) continue;
|
|
1755
|
+
verified.set(tokenId, { tokenId, positionManager: pm, owner: wallet });
|
|
1756
|
+
if (verified.size >= targetCount) break;
|
|
1757
|
+
} catch {
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
if (verified.size >= targetCount) break;
|
|
1761
|
+
if (fromBlock <= scanFrom) break;
|
|
1762
|
+
toBlock = fromBlock - 1n;
|
|
1763
|
+
}
|
|
1764
|
+
const out = [...verified.values()];
|
|
1765
|
+
out.sort((a, b) => BigInt(a.tokenId) < BigInt(b.tokenId) ? -1 : 1);
|
|
1766
|
+
return out;
|
|
1767
|
+
}
|
|
1768
|
+
function isNativeUniswapLpTokenAddress(token) {
|
|
1769
|
+
try {
|
|
1770
|
+
return viem.getAddress(token) === viem.zeroAddress;
|
|
1771
|
+
} catch {
|
|
1772
|
+
return token.toLowerCase() === viem.zeroAddress.toLowerCase();
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
// src/protocols/evm/uniswap-v4/liquidityMultisign.ts
|
|
1777
|
+
var wethDepositAbi = viem.parseAbi(["function deposit() payable"]);
|
|
1778
|
+
var erc20AllowanceAbi = viem.parseAbi([
|
|
1779
|
+
"function allowance(address owner, address spender) view returns (uint256)",
|
|
1780
|
+
"function decimals() view returns (uint8)"
|
|
1781
|
+
]);
|
|
1782
|
+
function parseOptionalGasLimitString2(raw) {
|
|
1783
|
+
if (raw == null) return null;
|
|
1784
|
+
const s = String(raw).trim();
|
|
1785
|
+
if (!s) return null;
|
|
1786
|
+
try {
|
|
1787
|
+
if (/^0x[0-9a-fA-F]+$/.test(s)) return BigInt(s);
|
|
1788
|
+
return BigInt(s);
|
|
1789
|
+
} catch {
|
|
1790
|
+
return null;
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
function parseTxValueWei(tx) {
|
|
1794
|
+
const raw = tx.value ?? "0";
|
|
1795
|
+
try {
|
|
1796
|
+
if (typeof raw === "string" && /^0x[0-9a-fA-F]+$/.test(raw.trim())) return BigInt(raw.trim());
|
|
1797
|
+
return BigInt(String(raw).trim() || "0");
|
|
1798
|
+
} catch {
|
|
1799
|
+
return 0n;
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
function dataHexFromTx(tx) {
|
|
1803
|
+
const d = (tx.data ?? "0x").toString().trim();
|
|
1804
|
+
return d.startsWith("0x") ? d : `0x${d}`;
|
|
1805
|
+
}
|
|
1806
|
+
function defaultGasForAction(action) {
|
|
1807
|
+
switch (action) {
|
|
1808
|
+
case "mint":
|
|
1809
|
+
return UNISWAP_V4_LP_MINT_DEFAULT_GAS_UNITS;
|
|
1810
|
+
case "increase":
|
|
1811
|
+
return UNISWAP_V4_LP_INCREASE_DEFAULT_GAS_UNITS;
|
|
1812
|
+
case "decrease":
|
|
1813
|
+
return UNISWAP_V4_LP_DECREASE_DEFAULT_GAS_UNITS;
|
|
1814
|
+
case "collect":
|
|
1815
|
+
return UNISWAP_V4_LP_COLLECT_DEFAULT_GAS_UNITS;
|
|
1816
|
+
default:
|
|
1817
|
+
return UNISWAP_V4_LP_MINT_DEFAULT_GAS_UNITS;
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
async function resolveApproveTargets(args) {
|
|
1821
|
+
const out = [];
|
|
1822
|
+
const pairs = [args.token0, args.token1].filter(Boolean);
|
|
1823
|
+
for (const row of pairs) {
|
|
1824
|
+
const amt = BigInt(row.amount);
|
|
1825
|
+
if (amt <= 0n) continue;
|
|
1826
|
+
if (isNativeUniswapLpTokenAddress(row.tokenAddress)) {
|
|
1827
|
+
if (!args.nativeWrapped) {
|
|
1828
|
+
throw new Error("nativeWrapped is required when LP uses native ETH (0x0) token.");
|
|
1829
|
+
}
|
|
1830
|
+
out.push({ token: viem.getAddress(args.nativeWrapped), amount: amt, kind: "weth_deposit" });
|
|
1831
|
+
continue;
|
|
1832
|
+
}
|
|
1833
|
+
out.push({ token: viem.getAddress(row.tokenAddress), amount: amt, kind: "approve" });
|
|
1834
|
+
}
|
|
1835
|
+
const deduped = [];
|
|
1836
|
+
for (const row of out) {
|
|
1837
|
+
const existing = deduped.find((d) => d.token === row.token && d.kind === row.kind);
|
|
1838
|
+
if (existing) {
|
|
1839
|
+
if (row.amount > existing.amount) existing.amount = row.amount;
|
|
1840
|
+
} else {
|
|
1841
|
+
deduped.push({ ...row });
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
const steps = [];
|
|
1845
|
+
for (const row of deduped) {
|
|
1846
|
+
if (row.kind === "weth_deposit") {
|
|
1847
|
+
steps.push(row);
|
|
1848
|
+
continue;
|
|
1849
|
+
}
|
|
1850
|
+
const allowance = await args.publicClient.readContract({
|
|
1851
|
+
address: row.token,
|
|
1852
|
+
abi: erc20AllowanceAbi,
|
|
1853
|
+
functionName: "allowance",
|
|
1854
|
+
args: [args.executor, args.spender]
|
|
1855
|
+
});
|
|
1856
|
+
if (allowance < row.amount) {
|
|
1857
|
+
steps.push(row);
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
return steps;
|
|
1861
|
+
}
|
|
1862
|
+
async function buildEvmMultisignBodyUniswapV4LiquidityBatchInternal(args) {
|
|
1863
|
+
const parsed = parseUniswapLpApiSnapshot({ action: args.action, lpResponse: args.lpResponse });
|
|
1864
|
+
const tx = parsed.transaction;
|
|
1865
|
+
const to = viem.getAddress(tx.to);
|
|
1866
|
+
const dataHex = dataHexFromTx(tx);
|
|
1867
|
+
const valueWei = parseTxValueWei(tx);
|
|
1868
|
+
const executor = viem.getAddress(args.executorAddress);
|
|
1869
|
+
const spender = to;
|
|
1870
|
+
const chain = viem.defineChain({
|
|
1871
|
+
id: args.chainId,
|
|
1872
|
+
name: `uniswap-v4-lp-${args.chainId}`,
|
|
1873
|
+
nativeCurrency: { name: "ETH", symbol: "ETH", decimals: 18 },
|
|
1874
|
+
rpcUrls: { default: { http: [args.rpcUrl] } }
|
|
1875
|
+
});
|
|
1876
|
+
const publicClient = viem.createPublicClient({ chain, transport: viem.http(args.rpcUrl) });
|
|
1877
|
+
const approveTargets = await resolveApproveTargets({
|
|
1878
|
+
publicClient,
|
|
1879
|
+
executor,
|
|
1880
|
+
spender,
|
|
1881
|
+
token0: parsed.token0,
|
|
1882
|
+
token1: parsed.token1,
|
|
1883
|
+
nativeWrapped: args.nativeWrapped
|
|
1884
|
+
});
|
|
1885
|
+
const steps = [];
|
|
1886
|
+
for (const target of approveTargets) {
|
|
1887
|
+
if (target.kind === "weth_deposit") {
|
|
1888
|
+
steps.push({
|
|
1889
|
+
to: target.token,
|
|
1890
|
+
data: viem.encodeFunctionData({ abi: wethDepositAbi, functionName: "deposit" }),
|
|
1891
|
+
value: target.amount,
|
|
1892
|
+
fallbackGas: UNISWAP_V4_LP_WETH_DEPOSIT_FALLBACK
|
|
1893
|
+
});
|
|
1894
|
+
steps.push({
|
|
1895
|
+
to: target.token,
|
|
1896
|
+
data: viem.encodeFunctionData({
|
|
1897
|
+
abi: viem.erc20Abi,
|
|
1898
|
+
functionName: "approve",
|
|
1899
|
+
args: [spender, target.amount]
|
|
1900
|
+
}),
|
|
1901
|
+
value: 0n,
|
|
1902
|
+
fallbackGas: UNISWAP_V4_LP_ERC20_APPROVE_FALLBACK
|
|
1903
|
+
});
|
|
1904
|
+
} else {
|
|
1905
|
+
steps.push({
|
|
1906
|
+
to: target.token,
|
|
1907
|
+
data: viem.encodeFunctionData({
|
|
1908
|
+
abi: viem.erc20Abi,
|
|
1909
|
+
functionName: "approve",
|
|
1910
|
+
args: [spender, target.amount]
|
|
1911
|
+
}),
|
|
1912
|
+
value: 0n,
|
|
1913
|
+
fallbackGas: UNISWAP_V4_LP_ERC20_APPROVE_FALLBACK
|
|
1914
|
+
});
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
const lpFallbackGas = defaultGasForAction(args.action);
|
|
1918
|
+
const fromTradeApi = parseOptionalGasLimitString2(tx.gasLimit) ?? parseOptionalGasLimitString2(tx.gas);
|
|
1919
|
+
steps.push({
|
|
1920
|
+
to,
|
|
1921
|
+
data: dataHex,
|
|
1922
|
+
value: valueWei,
|
|
1923
|
+
fallbackGas: fromTradeApi != null && fromTradeApi > 0n ? fromTradeApi : lpFallbackGas
|
|
1924
|
+
});
|
|
1925
|
+
const actionLabel = args.action === "mint" ? "mint liquidity" : args.action === "increase" ? "increase liquidity" : args.action === "decrease" ? "decrease liquidity" : "collect fees";
|
|
1926
|
+
const dataNo0x = dataHex.startsWith("0x") ? dataHex.slice(2) : dataHex;
|
|
1927
|
+
const lpIndex = steps.length - 1;
|
|
1928
|
+
return buildEvmMultisignBatch({
|
|
1929
|
+
context: {
|
|
1930
|
+
chainCategory: "evm",
|
|
1931
|
+
keyGen: args.keyGen,
|
|
1932
|
+
purposeText: args.purposeText,
|
|
1933
|
+
chainId: args.chainId,
|
|
1934
|
+
rpcUrl: args.rpcUrl,
|
|
1935
|
+
executorAddress: args.executorAddress,
|
|
1936
|
+
chainDetail: args.chainDetail,
|
|
1937
|
+
useCustomGas: args.useCustomGas,
|
|
1938
|
+
customGasChainDetails: args.customGasChainDetails
|
|
1939
|
+
},
|
|
1940
|
+
steps,
|
|
1941
|
+
purposeSuffix: `Uniswap V4: ${steps.length}-tx batch \u2014 ${actionLabel} (classic ERC-20 approve + Position Manager).`,
|
|
1942
|
+
firstMsgRawNo0x: dataNo0x,
|
|
1943
|
+
destinationAddress: to,
|
|
1944
|
+
buildBatchMeta: ({ index }) => {
|
|
1945
|
+
const isLpStep = index === lpIndex;
|
|
1946
|
+
return {
|
|
1947
|
+
signatureText: JSON.stringify({
|
|
1948
|
+
kind: "UniswapV4Liquidity",
|
|
1949
|
+
action: args.action,
|
|
1950
|
+
step: index,
|
|
1951
|
+
lpTx: isLpStep
|
|
1952
|
+
}),
|
|
1953
|
+
...isLpStep ? {
|
|
1954
|
+
evm: { type: "uniswap_v4_liquidity_tx", version: 1, chainId: String(args.chainId) },
|
|
1955
|
+
uniswapV4Liquidity: {
|
|
1956
|
+
action: args.action,
|
|
1957
|
+
skipPermit2Batch: true,
|
|
1958
|
+
nftTokenId: args.nftTokenId != null ? String(args.nftTokenId) : void 0,
|
|
1959
|
+
poolReference: args.poolReference,
|
|
1960
|
+
lpResponseSnapshot: args.lpResponse,
|
|
1961
|
+
token0: parsed.token0,
|
|
1962
|
+
token1: parsed.token1,
|
|
1963
|
+
tickLower: parsed.tickLower,
|
|
1964
|
+
tickUpper: parsed.tickUpper,
|
|
1965
|
+
transaction: {
|
|
1966
|
+
to: tx.to,
|
|
1967
|
+
value: tx.value,
|
|
1968
|
+
dataNibbles: dataNo0x.length,
|
|
1969
|
+
gasLimit: tx.gasLimit
|
|
1970
|
+
},
|
|
1971
|
+
originalPurpose: args.purposeText
|
|
1972
|
+
}
|
|
1973
|
+
} : {}
|
|
1974
|
+
};
|
|
1975
|
+
}
|
|
1976
|
+
});
|
|
1977
|
+
}
|
|
1978
|
+
async function buildEvmMultisignBodyUniswapV4MintLiquidityBatch(args) {
|
|
1979
|
+
return buildEvmMultisignBodyUniswapV4LiquidityBatchInternal({ ...args, action: "mint" });
|
|
1980
|
+
}
|
|
1981
|
+
async function buildEvmMultisignBodyUniswapV4IncreaseLiquidityBatch(args) {
|
|
1982
|
+
return buildEvmMultisignBodyUniswapV4LiquidityBatchInternal({ ...args, action: "increase" });
|
|
1983
|
+
}
|
|
1984
|
+
async function buildEvmMultisignBodyUniswapV4DecreaseLiquidityBatch(args) {
|
|
1985
|
+
return buildEvmMultisignBodyUniswapV4LiquidityBatchInternal({ ...args, action: "decrease" });
|
|
1986
|
+
}
|
|
1987
|
+
async function buildEvmMultisignBodyUniswapV4CollectFeesBatch(args) {
|
|
1988
|
+
return buildEvmMultisignBodyUniswapV4LiquidityBatchInternal({ ...args, action: "collect" });
|
|
1989
|
+
}
|
|
1292
1990
|
|
|
1293
1991
|
// src/protocols/evm/uniswap-v4/swap.ts
|
|
1294
1992
|
async function swapFromQuote(args) {
|
|
@@ -1372,6 +2070,52 @@ var uniswapV4ProtocolModule = {
|
|
|
1372
2070
|
amount: { type: "string", required: true, description: "Amount for quote" },
|
|
1373
2071
|
type: { type: "EXACT_INPUT | EXACT_OUTPUT", required: true, description: "Trade type" }
|
|
1374
2072
|
}
|
|
2073
|
+
},
|
|
2074
|
+
{
|
|
2075
|
+
id: "uniswap-v4.mint-liquidity",
|
|
2076
|
+
protocolId: UNISWAP_V4_PROTOCOL_ID,
|
|
2077
|
+
chainCategory: "evm",
|
|
2078
|
+
description: "Mint a new Uniswap V4 concentrated liquidity position (Position Manager NFT)",
|
|
2079
|
+
commonParams: ["keyGen", "purposeText", "useCustomGas"],
|
|
2080
|
+
params: {
|
|
2081
|
+
lpResponse: { type: "object", required: true, description: "Full LP API create response" },
|
|
2082
|
+
nativeWrapped: { type: "address", required: false, description: "WETH when pool uses native ETH" },
|
|
2083
|
+
poolReference: { type: "string", required: false, description: "V4 pool id" },
|
|
2084
|
+
uniswapApiKey: { type: "string", required: true, description: "Uniswap API key" }
|
|
2085
|
+
}
|
|
2086
|
+
},
|
|
2087
|
+
{
|
|
2088
|
+
id: "uniswap-v4.increase-liquidity",
|
|
2089
|
+
protocolId: UNISWAP_V4_PROTOCOL_ID,
|
|
2090
|
+
chainCategory: "evm",
|
|
2091
|
+
description: "Increase liquidity on an existing Uniswap V4 position NFT",
|
|
2092
|
+
commonParams: ["keyGen", "purposeText", "useCustomGas"],
|
|
2093
|
+
params: {
|
|
2094
|
+
nftTokenId: { type: "string", required: true, description: "Position NFT token id" },
|
|
2095
|
+
lpResponse: { type: "object", required: true, description: "Full LP API increase response" }
|
|
2096
|
+
}
|
|
2097
|
+
},
|
|
2098
|
+
{
|
|
2099
|
+
id: "uniswap-v4.decrease-liquidity",
|
|
2100
|
+
protocolId: UNISWAP_V4_PROTOCOL_ID,
|
|
2101
|
+
chainCategory: "evm",
|
|
2102
|
+
description: "Decrease liquidity on an existing Uniswap V4 position NFT",
|
|
2103
|
+
commonParams: ["keyGen", "purposeText", "useCustomGas"],
|
|
2104
|
+
params: {
|
|
2105
|
+
nftTokenId: { type: "string", required: true, description: "Position NFT token id" },
|
|
2106
|
+
lpResponse: { type: "object", required: true, description: "Full LP API decrease response" }
|
|
2107
|
+
}
|
|
2108
|
+
},
|
|
2109
|
+
{
|
|
2110
|
+
id: "uniswap-v4.collect-fees",
|
|
2111
|
+
protocolId: UNISWAP_V4_PROTOCOL_ID,
|
|
2112
|
+
chainCategory: "evm",
|
|
2113
|
+
description: "Collect accrued fees from a Uniswap V4 position NFT",
|
|
2114
|
+
commonParams: ["keyGen", "purposeText", "useCustomGas"],
|
|
2115
|
+
params: {
|
|
2116
|
+
nftTokenId: { type: "string", required: true, description: "Position NFT token id" },
|
|
2117
|
+
lpResponse: { type: "object", required: true, description: "Full LP API claim response" }
|
|
2118
|
+
}
|
|
1375
2119
|
}
|
|
1376
2120
|
]
|
|
1377
2121
|
};
|
|
@@ -1383,6 +2127,15 @@ var uniswapV4 = {
|
|
|
1383
2127
|
swapFromQuote,
|
|
1384
2128
|
buildSwapMultisignBody: buildEvmMultisignBodyUniswapV4SkipPermit2Batch,
|
|
1385
2129
|
quote: uniswapTradeQuote,
|
|
2130
|
+
createLiquidityPosition: uniswapLpCreatePosition,
|
|
2131
|
+
increaseLiquidityPosition: uniswapLpIncreasePosition,
|
|
2132
|
+
decreaseLiquidityPosition: uniswapLpDecreasePosition,
|
|
2133
|
+
claimLiquidityFees: uniswapLpClaimFees,
|
|
2134
|
+
buildMintLiquidityMultisignBody: buildEvmMultisignBodyUniswapV4MintLiquidityBatch,
|
|
2135
|
+
buildIncreaseLiquidityMultisignBody: buildEvmMultisignBodyUniswapV4IncreaseLiquidityBatch,
|
|
2136
|
+
buildDecreaseLiquidityMultisignBody: buildEvmMultisignBodyUniswapV4DecreaseLiquidityBatch,
|
|
2137
|
+
buildCollectFeesMultisignBody: buildEvmMultisignBodyUniswapV4CollectFeesBatch,
|
|
2138
|
+
listPositions: listUniswapV4PositionsForWallet,
|
|
1386
2139
|
isChainSupported: isUniswapV4ChainSupported
|
|
1387
2140
|
};
|
|
1388
2141
|
|
|
@@ -1587,7 +2340,7 @@ async function buildEvmMultisignBodyCurveDaoBatch(args) {
|
|
|
1587
2340
|
rpcUrls: { default: { http: [args.rpcUrl] } }
|
|
1588
2341
|
});
|
|
1589
2342
|
const publicClient = viem.createPublicClient({ chain: ch, transport: viem.http(args.rpcUrl) });
|
|
1590
|
-
const
|
|
2343
|
+
const erc20AllowanceAbi2 = viem.parseAbi([
|
|
1591
2344
|
"function allowance(address owner, address spender) view returns (uint256)",
|
|
1592
2345
|
"function decimals() view returns (uint8)"
|
|
1593
2346
|
]);
|
|
@@ -1596,13 +2349,13 @@ async function buildEvmMultisignBodyCurveDaoBatch(args) {
|
|
|
1596
2349
|
if (!isNativeIn) {
|
|
1597
2350
|
const decimalsN = await publicClient.readContract({
|
|
1598
2351
|
address: tokenIn,
|
|
1599
|
-
abi:
|
|
2352
|
+
abi: erc20AllowanceAbi2,
|
|
1600
2353
|
functionName: "decimals"
|
|
1601
2354
|
});
|
|
1602
2355
|
const amountWei = viem.parseUnits(args.amountHuman, Number(decimalsN));
|
|
1603
2356
|
const currentAllowance = await publicClient.readContract({
|
|
1604
2357
|
address: tokenIn,
|
|
1605
|
-
abi:
|
|
2358
|
+
abi: erc20AllowanceAbi2,
|
|
1606
2359
|
functionName: "allowance",
|
|
1607
2360
|
args: [executor, routerAddr]
|
|
1608
2361
|
});
|