@continuumdao/ctm-mpc-defi 0.2.3 → 0.2.4

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.
@@ -90,9 +90,55 @@ var MAX_UINT160 = (1n << 160n) - 1n;
90
90
  var MAX_UINT48 = (1n << 48n) - 1n;
91
91
  var UNISWAP_UNIVERSAL_ROUTER_DEFAULT_GAS_UNITS = 1500000n;
92
92
  var UNISWAP_TRADE_BASE_DEFAULT = "https://trade-api.gateway.uniswap.org/v1";
93
+ var UNISWAP_LP_API_BASE_DEFAULT = "https://api.uniswap.org";
93
94
  var UNISWAP_UNIVERSAL_ROUTER_VERSION_DEFAULT = "2.0";
94
95
  var UNISWAP_SWAP_DEFAULT_EXPIRY_MINUTES = 30;
95
96
  var UNISWAP_SWAP_DEFAULT_DEADLINE_SEC_OFFSET = UNISWAP_SWAP_DEFAULT_EXPIRY_MINUTES * 60;
97
+ var UNISWAP_LP_DEFAULT_EXPIRY_MINUTES = 30;
98
+ var UNISWAP_LP_DEFAULT_DEADLINE_SEC_OFFSET = UNISWAP_LP_DEFAULT_EXPIRY_MINUTES * 60;
99
+ var UNISWAP_LP_DEFAULT_SLIPPAGE_PERCENT = 0.5;
100
+ var POSITION_MANAGER_BY_CHAIN = {
101
+ 1: "0xbd216513d74c8cf14cf4747e6aaa6420ff64ee9e",
102
+ 10: "0x3c3ea4b57a46241e54610e5f022e5c45859a1017",
103
+ 137: "0x1ec2ebf4f37e7363fdfe3551602425af0b3ceef9",
104
+ 42161: "0xd88f38f930b7952f2db2432cb002e7abbf3dd869",
105
+ 8453: "0x7C5f5A4bBd8fD63184577525326123B519429bDc",
106
+ 11155111: "0x4B2C77d209D3405F41a037Ec6c77F7F5b8e2ca80",
107
+ 130: "0x0d97dc33264bfc1c226207428a79b26757fb9dc3",
108
+ 1868: "0x0e2850543f69f678257266e0907ff9a58b3f13de",
109
+ 59144: "0x661e93cca42afacb172121ef892830ca3b70f08d"
110
+ };
111
+ function getUniswapV4PositionManagerOrThrow(chainId) {
112
+ const raw = POSITION_MANAGER_BY_CHAIN[chainId];
113
+ if (!raw || !raw.startsWith("0x") || raw.length !== 42) {
114
+ throw new Error(
115
+ `No Uniswap V4 PositionManager is configured for chainId ${chainId}. Add this chain to uniswap-v4/constants or pass position manager from LP API response.`
116
+ );
117
+ }
118
+ return viem.getAddress(raw);
119
+ }
120
+ function tryGetUniswapV4PositionManager(chainId) {
121
+ try {
122
+ return getUniswapV4PositionManagerOrThrow(chainId);
123
+ } catch {
124
+ return null;
125
+ }
126
+ }
127
+ var POSITION_MANAGER_DEPLOY_BLOCK_BY_CHAIN = {
128
+ /** Ethereum mainnet — Uniswap v4 launch (Jan 2025). */
129
+ 1: 22938741n
130
+ };
131
+ var UNISWAP_V4_LP_LOG_CHUNK_SIZE_DEFAULT = 200n;
132
+ var UNISWAP_V4_LP_LOG_CHUNK_SIZE_MIN = 10n;
133
+ function getUniswapV4PositionManagerDeployBlock(chainId) {
134
+ return POSITION_MANAGER_DEPLOY_BLOCK_BY_CHAIN[chainId];
135
+ }
136
+ var UNISWAP_V4_LP_MINT_DEFAULT_GAS_UNITS = 1800000n;
137
+ var UNISWAP_V4_LP_INCREASE_DEFAULT_GAS_UNITS = 1500000n;
138
+ var UNISWAP_V4_LP_DECREASE_DEFAULT_GAS_UNITS = 1200000n;
139
+ var UNISWAP_V4_LP_COLLECT_DEFAULT_GAS_UNITS = 900000n;
140
+ var UNISWAP_V4_LP_ERC20_APPROVE_FALLBACK = 100000n;
141
+ var UNISWAP_V4_LP_WETH_DEPOSIT_FALLBACK = 120000n;
96
142
  var DEFAULT_TRADE_BASE = "https://trade-api.gateway.uniswap.org/v1";
97
143
  var UNISWAP_QUOTE_HEADERS_BASE = {
98
144
  "Content-Type": "application/json",
@@ -345,7 +391,16 @@ function parseUniswapQuoteClassicInOut(res) {
345
391
  const input = q.input;
346
392
  const output = q.output;
347
393
  const inAm = input?.amount;
348
- const outAm = output?.amount;
394
+ let outAm = output?.amount;
395
+ if (typeof outAm !== "string" || !outAm) {
396
+ const agg = q.aggregatedOutputs;
397
+ if (Array.isArray(agg) && agg.length > 0) {
398
+ const first = agg[0];
399
+ if (typeof first?.amount === "string" && first.amount) {
400
+ outAm = first.amount;
401
+ }
402
+ }
403
+ }
349
404
  if (typeof inAm !== "string" || !inAm || typeof outAm !== "string" || !outAm) return null;
350
405
  try {
351
406
  return { inputWei: BigInt(inAm), outputWei: BigInt(outAm) };
@@ -1324,6 +1379,858 @@ async function buildEvmMultisignBodyUniswapV4SkipPermit2Batch(args) {
1324
1379
  });
1325
1380
  }
1326
1381
 
1382
+ // src/protocols/evm/uniswap-v4/liquidityApi.ts
1383
+ var LP_HEADERS_BASE = {
1384
+ "Content-Type": "application/json",
1385
+ Accept: "application/json",
1386
+ "User-Agent": "ctm-mpc-defi uniswapLpApi/1.0 (TS)"
1387
+ };
1388
+ function trimAddr2(a) {
1389
+ return a.trim();
1390
+ }
1391
+ function lpDeadlineUnix(nowSec = Math.floor(Date.now() / 1e3)) {
1392
+ return nowSec + UNISWAP_LP_DEFAULT_DEADLINE_SEC_OFFSET;
1393
+ }
1394
+ function resolveLpBaseUrl(baseUrl) {
1395
+ const raw = (baseUrl ?? UNISWAP_TRADE_BASE_DEFAULT).replace(/\/$/, "");
1396
+ return raw;
1397
+ }
1398
+ function resolveLpPath(baseUrl, action) {
1399
+ const normalized = baseUrl.replace(/\/$/, "");
1400
+ if (normalized.includes("api.uniswap.org")) {
1401
+ return `${normalized}/lp/${action}`;
1402
+ }
1403
+ return `${normalized}/lp/${action}`;
1404
+ }
1405
+ async function postUniswapLpApi(args) {
1406
+ const useProxy = args.useServerProxy !== false && typeof globalThis !== "undefined" && typeof globalThis.window !== "undefined";
1407
+ if (useProxy && args.proxyPath) {
1408
+ const fn2 = args.fetchImpl ?? globalThis.fetch;
1409
+ const res2 = await fn2(args.proxyPath, {
1410
+ method: "POST",
1411
+ headers: { "Content-Type": "application/json" },
1412
+ body: JSON.stringify({
1413
+ uniswapApiKey: args.uniswapApiKey,
1414
+ baseUrl: args.baseUrl,
1415
+ body: args.body
1416
+ }),
1417
+ credentials: "same-origin"
1418
+ });
1419
+ const text2 = await res2.text();
1420
+ if (!res2.ok) {
1421
+ let errMsg = res2.statusText;
1422
+ try {
1423
+ const j = JSON.parse(text2);
1424
+ if (j?.error?.trim()) errMsg = j.error.trim();
1425
+ } catch {
1426
+ if (text2.trim()) errMsg = text2.slice(0, 500);
1427
+ }
1428
+ throw new Error(`Uniswap LP proxy failed: ${errMsg}`);
1429
+ }
1430
+ return JSON.parse(text2);
1431
+ }
1432
+ const base = resolveLpBaseUrl(args.baseUrl);
1433
+ const url = resolveLpPath(base, args.path);
1434
+ const fn = args.fetchImpl ?? globalThis.fetch;
1435
+ const res = await fn(url, {
1436
+ method: "POST",
1437
+ headers: {
1438
+ ...LP_HEADERS_BASE,
1439
+ "x-api-key": args.uniswapApiKey.trim()
1440
+ },
1441
+ body: JSON.stringify(args.body)
1442
+ });
1443
+ const text = await res.text();
1444
+ if (!res.ok) {
1445
+ throw new Error(
1446
+ `Uniswap LP POST /${args.path} failed: ${messageFromUniswapHttpResponseBody(text, res.status, res.statusText)}`
1447
+ );
1448
+ }
1449
+ return JSON.parse(text);
1450
+ }
1451
+ function extractUniswapLpTransaction(response, field) {
1452
+ const tx = response[field];
1453
+ if (!tx || typeof tx !== "object" || Array.isArray(tx)) {
1454
+ throw new Error(`Uniswap LP response missing \`${field}\` transaction object.`);
1455
+ }
1456
+ const o = tx;
1457
+ const to = String(o.to ?? "").trim();
1458
+ const data = String(o.data ?? "").trim();
1459
+ if (!to.startsWith("0x") || !data.startsWith("0x") || data === "0x") {
1460
+ throw new Error(`Uniswap LP \`${field}\` transaction has invalid to/data.`);
1461
+ }
1462
+ return {
1463
+ to,
1464
+ from: o.from != null ? String(o.from) : void 0,
1465
+ data,
1466
+ value: String(o.value ?? "0"),
1467
+ chainId: typeof o.chainId === "number" ? o.chainId : void 0,
1468
+ gasLimit: o.gasLimit != null ? String(o.gasLimit) : void 0,
1469
+ gasPrice: o.gasPrice != null ? String(o.gasPrice) : void 0,
1470
+ maxFeePerGas: o.maxFeePerGas != null ? String(o.maxFeePerGas) : void 0,
1471
+ maxPriorityFeePerGas: o.maxPriorityFeePerGas != null ? String(o.maxPriorityFeePerGas) : void 0
1472
+ };
1473
+ }
1474
+ function extractUniswapLpTokenAmounts(response) {
1475
+ const read = (key) => {
1476
+ const raw = response[key];
1477
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
1478
+ const o = raw;
1479
+ const tokenAddress = String(o.tokenAddress ?? o.token ?? "").trim();
1480
+ const amount = String(o.amount ?? "").trim();
1481
+ if (!tokenAddress.startsWith("0x") || !amount) return void 0;
1482
+ return { tokenAddress, amount };
1483
+ };
1484
+ return { token0: read("token0"), token1: read("token1") };
1485
+ }
1486
+ async function uniswapLpCreatePosition(args) {
1487
+ const body = {
1488
+ protocol: "V4",
1489
+ walletAddress: trimAddr2(args.walletAddress),
1490
+ chainId: args.chainId,
1491
+ independentToken: {
1492
+ tokenAddress: trimAddr2(args.independentToken.tokenAddress),
1493
+ amount: String(args.independentToken.amount).trim()
1494
+ },
1495
+ slippageTolerance: args.slippageTolerance ?? UNISWAP_LP_DEFAULT_SLIPPAGE_PERCENT,
1496
+ deadline: args.deadline ?? lpDeadlineUnix(),
1497
+ simulateTransaction: args.simulateTransaction ?? false
1498
+ };
1499
+ if (args.existingPool) {
1500
+ body.existingPool = {
1501
+ token0Address: trimAddr2(args.existingPool.token0Address),
1502
+ token1Address: trimAddr2(args.existingPool.token1Address),
1503
+ poolReference: trimAddr2(args.existingPool.poolReference)
1504
+ };
1505
+ }
1506
+ if (args.newPool) {
1507
+ body.newPool = {
1508
+ token0Address: trimAddr2(args.newPool.token0Address),
1509
+ token1Address: trimAddr2(args.newPool.token1Address),
1510
+ fee: args.newPool.fee,
1511
+ tickSpacing: args.newPool.tickSpacing,
1512
+ initialPrice: String(args.newPool.initialPrice).trim(),
1513
+ ...args.newPool.hooks ? { hooks: trimAddr2(args.newPool.hooks) } : {}
1514
+ };
1515
+ }
1516
+ if (!args.existingPool && !args.newPool) {
1517
+ throw new Error("Provide existingPool or newPool for LP create.");
1518
+ }
1519
+ if (args.priceBounds) {
1520
+ body.priceBounds = {
1521
+ minPrice: String(args.priceBounds.minPrice).trim(),
1522
+ maxPrice: String(args.priceBounds.maxPrice).trim()
1523
+ };
1524
+ }
1525
+ if (args.tickBounds) {
1526
+ body.tickBounds = {
1527
+ tickLower: args.tickBounds.tickLower,
1528
+ tickUpper: args.tickBounds.tickUpper
1529
+ };
1530
+ }
1531
+ if (!args.priceBounds && !args.tickBounds) {
1532
+ throw new Error("Provide priceBounds or tickBounds for LP create.");
1533
+ }
1534
+ if (args.batchPermitData) body.batchPermitData = args.batchPermitData;
1535
+ if (args.signature) body.signature = args.signature;
1536
+ return postUniswapLpApi({
1537
+ uniswapApiKey: args.uniswapApiKey,
1538
+ path: "create",
1539
+ body,
1540
+ baseUrl: args.baseUrl,
1541
+ fetchImpl: args.fetchImpl,
1542
+ useServerProxy: args.useServerProxy,
1543
+ proxyPath: "/api/uniswap/liquidity/create"
1544
+ });
1545
+ }
1546
+ async function uniswapLpIncreasePosition(args) {
1547
+ const body = {
1548
+ protocol: "V4",
1549
+ walletAddress: trimAddr2(args.walletAddress),
1550
+ chainId: args.chainId,
1551
+ token0Address: trimAddr2(args.token0Address),
1552
+ token1Address: trimAddr2(args.token1Address),
1553
+ nftTokenId: String(args.nftTokenId),
1554
+ independentToken: {
1555
+ tokenAddress: trimAddr2(args.independentToken.tokenAddress),
1556
+ amount: String(args.independentToken.amount).trim()
1557
+ },
1558
+ slippageTolerance: args.slippageTolerance ?? UNISWAP_LP_DEFAULT_SLIPPAGE_PERCENT,
1559
+ deadline: args.deadline ?? lpDeadlineUnix(),
1560
+ simulateTransaction: args.simulateTransaction ?? false
1561
+ };
1562
+ if (args.v4BatchPermitData) body.v4BatchPermitData = args.v4BatchPermitData;
1563
+ if (args.signature) body.signature = args.signature;
1564
+ return postUniswapLpApi({
1565
+ uniswapApiKey: args.uniswapApiKey,
1566
+ path: "increase",
1567
+ body,
1568
+ baseUrl: args.baseUrl,
1569
+ fetchImpl: args.fetchImpl,
1570
+ useServerProxy: args.useServerProxy,
1571
+ proxyPath: "/api/uniswap/liquidity/increase"
1572
+ });
1573
+ }
1574
+ async function uniswapLpDecreasePosition(args) {
1575
+ const pct = Math.trunc(args.liquidityPercentageToDecrease);
1576
+ if (!Number.isFinite(pct) || pct < 1 || pct > 100) {
1577
+ throw new Error("liquidityPercentageToDecrease must be an integer from 1 to 100.");
1578
+ }
1579
+ const body = {
1580
+ protocol: "V4",
1581
+ walletAddress: trimAddr2(args.walletAddress),
1582
+ chainId: args.chainId,
1583
+ token0Address: trimAddr2(args.token0Address),
1584
+ token1Address: trimAddr2(args.token1Address),
1585
+ nftTokenId: String(args.nftTokenId),
1586
+ liquidityPercentageToDecrease: pct,
1587
+ slippageTolerance: args.slippageTolerance ?? UNISWAP_LP_DEFAULT_SLIPPAGE_PERCENT,
1588
+ deadline: args.deadline ?? lpDeadlineUnix(),
1589
+ simulateTransaction: args.simulateTransaction ?? false
1590
+ };
1591
+ return postUniswapLpApi({
1592
+ uniswapApiKey: args.uniswapApiKey,
1593
+ path: "decrease",
1594
+ body,
1595
+ baseUrl: args.baseUrl,
1596
+ fetchImpl: args.fetchImpl,
1597
+ useServerProxy: args.useServerProxy,
1598
+ proxyPath: "/api/uniswap/liquidity/decrease"
1599
+ });
1600
+ }
1601
+ async function uniswapLpClaimFees(args) {
1602
+ const body = {
1603
+ protocol: "V4",
1604
+ walletAddress: trimAddr2(args.walletAddress),
1605
+ chainId: args.chainId,
1606
+ tokenId: String(args.tokenId),
1607
+ simulateTransaction: args.simulateTransaction ?? false
1608
+ };
1609
+ return postUniswapLpApi({
1610
+ uniswapApiKey: args.uniswapApiKey,
1611
+ path: "claim",
1612
+ body,
1613
+ baseUrl: args.baseUrl,
1614
+ fetchImpl: args.fetchImpl,
1615
+ useServerProxy: args.useServerProxy,
1616
+ proxyPath: "/api/uniswap/liquidity/claim"
1617
+ });
1618
+ }
1619
+ var TX_FIELD_BY_ACTION = {
1620
+ mint: "create",
1621
+ increase: "increase",
1622
+ decrease: "decrease",
1623
+ collect: "claim"
1624
+ };
1625
+ function uniswapLpTxFieldForAction(action) {
1626
+ return TX_FIELD_BY_ACTION[action];
1627
+ }
1628
+ function parseUniswapLpApiSnapshot(args) {
1629
+ const field = TX_FIELD_BY_ACTION[args.action];
1630
+ const transaction = extractUniswapLpTransaction(args.lpResponse, field);
1631
+ const amounts = extractUniswapLpTokenAmounts(args.lpResponse);
1632
+ const tickLower = typeof args.lpResponse.tickLower === "number" ? args.lpResponse.tickLower : void 0;
1633
+ const tickUpper = typeof args.lpResponse.tickUpper === "number" ? args.lpResponse.tickUpper : void 0;
1634
+ const minPrice = typeof args.lpResponse.minPrice === "string" ? args.lpResponse.minPrice : void 0;
1635
+ const maxPrice = typeof args.lpResponse.maxPrice === "string" ? args.lpResponse.maxPrice : void 0;
1636
+ return {
1637
+ transaction,
1638
+ token0: amounts.token0,
1639
+ token1: amounts.token1,
1640
+ tickLower,
1641
+ tickUpper,
1642
+ minPrice,
1643
+ maxPrice
1644
+ };
1645
+ }
1646
+ function formatUniswapLpAmountHuman(amountWei, decimals) {
1647
+ try {
1648
+ return viem.formatUnits(BigInt(amountWei), decimals);
1649
+ } catch {
1650
+ return amountWei;
1651
+ }
1652
+ }
1653
+ var erc721BalanceAbi = viem.parseAbi([
1654
+ "function balanceOf(address owner) view returns (uint256)",
1655
+ "function ownerOf(uint256 tokenId) view returns (address)"
1656
+ ]);
1657
+ var positionInfoAbi = viem.parseAbi([
1658
+ "function positionInfo(uint256 tokenId) view returns (uint256 info)"
1659
+ ]);
1660
+ var UNISWAP_V4_LP_POSITION_REGISTRY_HINT = "Add the position NFT to the node token registry (tokenType ERC721: Uniswap V4 Position Manager contract + tokenId). MCP: call ctm_uniswap_v4_register_position_nft (by tokenId) or ctm_uniswap_v4_register_position_from_mint_tx (after mint execute). Or use add_to_token_registry. In the Continuum app: Add Token (ERC721), or Manage liquidity \u2192 Refresh positions (blockchain scan).";
1661
+ function formatUniswapV4PositionNotFoundError(args) {
1662
+ return `Uniswap V4 position #${args.tokenId} is not in the node token registry for chain ${args.chainId}. ` + UNISWAP_V4_LP_POSITION_REGISTRY_HINT;
1663
+ }
1664
+ var positionManagerTransferEvent = viem.parseAbiItem(
1665
+ "event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)"
1666
+ );
1667
+ function uniswapV4PositionMintedTokenIdsFromReceipt(receipt, positionManager, owner) {
1668
+ const pm = viem.getAddress(positionManager);
1669
+ const wallet = viem.getAddress(owner);
1670
+ const ids = [];
1671
+ for (const log of receipt.logs) {
1672
+ try {
1673
+ if (viem.getAddress(log.address) !== pm) continue;
1674
+ const decoded = viem.decodeEventLog({
1675
+ abi: [positionManagerTransferEvent],
1676
+ data: log.data,
1677
+ topics: log.topics
1678
+ });
1679
+ if (decoded.eventName !== "Transfer") continue;
1680
+ const from = decoded.args.from;
1681
+ const to = decoded.args.to;
1682
+ const tokenId = decoded.args.tokenId;
1683
+ if (from === viem.zeroAddress && viem.getAddress(to) === wallet) {
1684
+ ids.push(tokenId);
1685
+ }
1686
+ } catch {
1687
+ }
1688
+ }
1689
+ return ids;
1690
+ }
1691
+ function uniswapV4ListPositionsFromRegistryForMcp(args) {
1692
+ const chainId = typeof args.chainId === "number" ? args.chainId : Number.parseInt(String(args.chainId), 10);
1693
+ if (!Number.isFinite(chainId) || chainId <= 0) {
1694
+ throw new Error("chainId must be a positive integer");
1695
+ }
1696
+ const wallet = viem.getAddress(args.walletAddress);
1697
+ const pm = viem.getAddress(
1698
+ args.positionManagerAddress ? String(args.positionManagerAddress) : getUniswapV4PositionManagerOrThrow(chainId)
1699
+ );
1700
+ const pmLower = pm.toLowerCase();
1701
+ const positions = [];
1702
+ for (const row of args.erc721Tokens) {
1703
+ const addr = (row.contractAddress ?? "").trim();
1704
+ const tokenId = (row.tokenId ?? "").trim();
1705
+ if (!addr || !tokenId) continue;
1706
+ try {
1707
+ if (viem.getAddress(addr).toLowerCase() !== pmLower) continue;
1708
+ } catch {
1709
+ continue;
1710
+ }
1711
+ positions.push({
1712
+ tokenId,
1713
+ positionManager: pm,
1714
+ owner: wallet,
1715
+ name: row.name,
1716
+ symbol: row.symbol
1717
+ });
1718
+ }
1719
+ positions.sort((a, b) => BigInt(a.tokenId) < BigInt(b.tokenId) ? -1 : 1);
1720
+ return { positions, source: "token_registry" };
1721
+ }
1722
+ function throwIfScanAborted(signal) {
1723
+ if (signal?.aborted) {
1724
+ throw new DOMException("Position scan aborted.", "AbortError");
1725
+ }
1726
+ }
1727
+ var TRANSFER_EVENT = {
1728
+ type: "event",
1729
+ name: "Transfer",
1730
+ inputs: [
1731
+ { indexed: true, name: "from", type: "address" },
1732
+ { indexed: true, name: "to", type: "address" },
1733
+ { indexed: true, name: "tokenId", type: "uint256" }
1734
+ ]
1735
+ };
1736
+ function isEthGetLogsBlockRangeTooLargeError(err) {
1737
+ const msg = (err instanceof Error ? err.message : String(err)).toLowerCase();
1738
+ 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");
1739
+ }
1740
+ async function getTransferLogsForWalletInRange(args) {
1741
+ const { client, positionManager, wallet, fromBlock, toBlock } = args;
1742
+ let chunkSize = args.chunkSize < UNISWAP_V4_LP_LOG_CHUNK_SIZE_MIN ? UNISWAP_V4_LP_LOG_CHUNK_SIZE_MIN : args.chunkSize;
1743
+ const out = [];
1744
+ let from = fromBlock;
1745
+ while (from <= toBlock) {
1746
+ let to = from + chunkSize - 1n > toBlock ? toBlock : from + chunkSize - 1n;
1747
+ for (; ; ) {
1748
+ try {
1749
+ const [toLogs, fromLogs] = await Promise.all([
1750
+ client.getLogs({
1751
+ address: positionManager,
1752
+ event: TRANSFER_EVENT,
1753
+ args: { to: wallet },
1754
+ fromBlock: from,
1755
+ toBlock: to
1756
+ }),
1757
+ client.getLogs({
1758
+ address: positionManager,
1759
+ event: TRANSFER_EVENT,
1760
+ args: { from: wallet },
1761
+ fromBlock: from,
1762
+ toBlock: to
1763
+ })
1764
+ ]);
1765
+ out.push(...toLogs, ...fromLogs);
1766
+ from = to + 1n;
1767
+ break;
1768
+ } catch (err) {
1769
+ if (!isEthGetLogsBlockRangeTooLargeError(err) || chunkSize <= UNISWAP_V4_LP_LOG_CHUNK_SIZE_MIN) {
1770
+ throw err;
1771
+ }
1772
+ chunkSize = chunkSize / 2n;
1773
+ if (chunkSize < UNISWAP_V4_LP_LOG_CHUNK_SIZE_MIN) {
1774
+ chunkSize = UNISWAP_V4_LP_LOG_CHUNK_SIZE_MIN;
1775
+ }
1776
+ to = from + chunkSize - 1n > toBlock ? toBlock : from + chunkSize - 1n;
1777
+ }
1778
+ }
1779
+ }
1780
+ return out;
1781
+ }
1782
+ function parseUniswapV4ScanFromDateYmd(fromDate) {
1783
+ const trimmed = fromDate.trim();
1784
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(trimmed)) {
1785
+ throw new Error("fromDate must be YYYY-MM-DD");
1786
+ }
1787
+ const ms = Date.parse(`${trimmed}T00:00:00.000Z`);
1788
+ if (!Number.isFinite(ms)) {
1789
+ throw new Error(`Invalid fromDate: ${fromDate}`);
1790
+ }
1791
+ return Math.floor(ms / 1e3);
1792
+ }
1793
+ async function resolveBlockAtOrAfterUnixTime(client, unixTime, bounds) {
1794
+ let lo = bounds.minBlock;
1795
+ let hi = bounds.maxBlock;
1796
+ let ans = hi;
1797
+ while (lo <= hi) {
1798
+ const mid = (lo + hi) / 2n;
1799
+ const block = await client.getBlock({ blockNumber: mid });
1800
+ const ts = Number(block.timestamp);
1801
+ if (ts >= unixTime) {
1802
+ ans = mid;
1803
+ if (mid === 0n) break;
1804
+ hi = mid - 1n;
1805
+ } else {
1806
+ lo = mid + 1n;
1807
+ }
1808
+ }
1809
+ return ans;
1810
+ }
1811
+ async function resolveUniswapV4PositionScanFromDate(args) {
1812
+ const unixTime = parseUniswapV4ScanFromDateYmd(args.fromDate);
1813
+ const chain = viem.defineChain({
1814
+ id: args.chainId,
1815
+ name: `uniswap-v4-${args.chainId}`,
1816
+ nativeCurrency: { name: "ETH", symbol: "ETH", decimals: 18 },
1817
+ rpcUrls: { default: { http: [args.rpcUrl] } }
1818
+ });
1819
+ const client = viem.createPublicClient({ chain, transport: viem.http(args.rpcUrl) });
1820
+ const latest = await client.getBlockNumber();
1821
+ const deploy = getUniswapV4PositionManagerDeployBlock(args.chainId) ?? 0n;
1822
+ const resolved = await resolveBlockAtOrAfterUnixTime(client, unixTime, {
1823
+ minBlock: deploy,
1824
+ maxBlock: latest
1825
+ });
1826
+ return resolved < deploy ? deploy : resolved;
1827
+ }
1828
+ function defaultScanFromBlock(args) {
1829
+ if (args.fromBlock != null) return args.fromBlock;
1830
+ const deploy = getUniswapV4PositionManagerDeployBlock(args.chainId);
1831
+ if (deploy != null) return deploy;
1832
+ return args.latest > args.maxBlocksToScan ? args.latest - args.maxBlocksToScan : 0n;
1833
+ }
1834
+ async function listUniswapV4PositionsForWallet(args) {
1835
+ throwIfScanAborted(args.signal);
1836
+ const wallet = viem.getAddress(args.walletAddress);
1837
+ const pm = viem.getAddress(
1838
+ args.positionManagerAddress ? String(args.positionManagerAddress) : getUniswapV4PositionManagerOrThrow(args.chainId)
1839
+ );
1840
+ const chain = viem.defineChain({
1841
+ id: args.chainId,
1842
+ name: `uniswap-v4-${args.chainId}`,
1843
+ nativeCurrency: { name: "ETH", symbol: "ETH", decimals: 18 },
1844
+ rpcUrls: { default: { http: [args.rpcUrl] } }
1845
+ });
1846
+ const client = viem.createPublicClient({ chain, transport: viem.http(args.rpcUrl) });
1847
+ const latest = await client.getBlockNumber();
1848
+ const maxScan = args.maxBlocksToScan ?? 500000n;
1849
+ const chunkSize = args.chunkSize ?? UNISWAP_V4_LP_LOG_CHUNK_SIZE_DEFAULT;
1850
+ const scanFrom = defaultScanFromBlock({
1851
+ chainId: args.chainId,
1852
+ latest,
1853
+ fromBlock: args.fromBlock,
1854
+ maxBlocksToScan: maxScan
1855
+ });
1856
+ const balance = await client.readContract({
1857
+ address: pm,
1858
+ abi: erc721BalanceAbi,
1859
+ functionName: "balanceOf",
1860
+ args: [wallet]
1861
+ });
1862
+ const targetCount = Number(balance);
1863
+ const emitProgress = (scanningFromBlock, scanningToBlock, foundCount) => {
1864
+ args.onProgress?.({
1865
+ latestBlock: latest.toString(),
1866
+ scanFromBlock: scanFrom.toString(),
1867
+ scanningFromBlock: scanningFromBlock.toString(),
1868
+ scanningToBlock: scanningToBlock.toString(),
1869
+ foundCount,
1870
+ targetCount
1871
+ });
1872
+ };
1873
+ if (balance === 0n) {
1874
+ emitProgress(latest, latest, 0);
1875
+ return [];
1876
+ }
1877
+ const candidates = /* @__PURE__ */ new Set();
1878
+ const verified = /* @__PURE__ */ new Map();
1879
+ let toBlock = latest;
1880
+ while (toBlock >= scanFrom && verified.size < targetCount) {
1881
+ throwIfScanAborted(args.signal);
1882
+ let fromBlock = toBlock >= chunkSize - 1n ? toBlock - chunkSize + 1n : 0n;
1883
+ if (fromBlock < scanFrom) fromBlock = scanFrom;
1884
+ emitProgress(fromBlock, toBlock, verified.size);
1885
+ const logs = await getTransferLogsForWalletInRange({
1886
+ client,
1887
+ positionManager: pm,
1888
+ wallet,
1889
+ fromBlock,
1890
+ toBlock,
1891
+ chunkSize
1892
+ });
1893
+ for (const log of logs) {
1894
+ const tokenId = log.args.tokenId?.toString();
1895
+ if (!tokenId) continue;
1896
+ const to = log.args.to != null ? viem.getAddress(log.args.to) : null;
1897
+ const from = log.args.from != null ? viem.getAddress(log.args.from) : null;
1898
+ if (to === wallet) candidates.add(tokenId);
1899
+ if (from === wallet) candidates.delete(tokenId);
1900
+ }
1901
+ for (const tokenId of candidates) {
1902
+ if (verified.has(tokenId)) continue;
1903
+ try {
1904
+ const owner = await client.readContract({
1905
+ address: pm,
1906
+ abi: erc721BalanceAbi,
1907
+ functionName: "ownerOf",
1908
+ args: [BigInt(tokenId)]
1909
+ });
1910
+ if (viem.getAddress(owner) !== wallet) continue;
1911
+ verified.set(tokenId, { tokenId, positionManager: pm, owner: wallet });
1912
+ if (verified.size >= targetCount) break;
1913
+ } catch {
1914
+ }
1915
+ }
1916
+ if (verified.size >= targetCount) break;
1917
+ if (fromBlock <= scanFrom) break;
1918
+ toBlock = fromBlock - 1n;
1919
+ }
1920
+ const out = [...verified.values()];
1921
+ out.sort((a, b) => BigInt(a.tokenId) < BigInt(b.tokenId) ? -1 : 1);
1922
+ return out;
1923
+ }
1924
+ async function readUniswapV4PositionInfoRaw(args) {
1925
+ const pm = viem.getAddress(
1926
+ args.positionManagerAddress ? String(args.positionManagerAddress) : getUniswapV4PositionManagerOrThrow(args.chainId)
1927
+ );
1928
+ const chain = viem.defineChain({
1929
+ id: args.chainId,
1930
+ name: `uniswap-v4-${args.chainId}`,
1931
+ nativeCurrency: { name: "ETH", symbol: "ETH", decimals: 18 },
1932
+ rpcUrls: { default: { http: [args.rpcUrl] } }
1933
+ });
1934
+ const client = viem.createPublicClient({ chain, transport: viem.http(args.rpcUrl) });
1935
+ const info = await client.readContract({
1936
+ address: pm,
1937
+ abi: positionInfoAbi,
1938
+ functionName: "positionInfo",
1939
+ args: [BigInt(args.tokenId)]
1940
+ });
1941
+ return { info, positionManager: pm };
1942
+ }
1943
+ async function uniswapV4ListPositionsForMcp(args) {
1944
+ const chainId = typeof args.chainId === "number" ? args.chainId : Number.parseInt(String(args.chainId), 10);
1945
+ if (!Number.isFinite(chainId) || chainId <= 0) {
1946
+ throw new Error("chainId must be a positive integer");
1947
+ }
1948
+ const fromBlock = args.fromBlock != null && String(args.fromBlock).trim() !== "" ? BigInt(String(args.fromBlock).trim()) : void 0;
1949
+ const positions = await listUniswapV4PositionsForWallet({
1950
+ chainId,
1951
+ rpcUrl: args.rpcUrl,
1952
+ walletAddress: args.walletAddress,
1953
+ positionManagerAddress: args.positionManagerAddress,
1954
+ fromBlock,
1955
+ onProgress: args.onProgress,
1956
+ signal: args.signal
1957
+ });
1958
+ return { positions };
1959
+ }
1960
+ function uniswapV4ListPositionsRegistryMcpPlaceholder() {
1961
+ throw new Error(
1962
+ "ctm_uniswap_v4_lp_list_positions must run via continuum-node-sdk MCP (token registry, no RPC scan)."
1963
+ );
1964
+ }
1965
+ function uniswapV4RegisterPositionNftPlaceholder() {
1966
+ throw new Error(
1967
+ "ctm_uniswap_v4_register_position_nft must run via continuum-node-sdk MCP (management-signed addToken)."
1968
+ );
1969
+ }
1970
+ function uniswapV4RegisterPositionFromMintTxPlaceholder() {
1971
+ throw new Error(
1972
+ "ctm_uniswap_v4_register_position_from_mint_tx must run via continuum-node-sdk MCP (management-signed addToken)."
1973
+ );
1974
+ }
1975
+ function isNativeUniswapLpTokenAddress(token) {
1976
+ try {
1977
+ return viem.getAddress(token) === viem.zeroAddress;
1978
+ } catch {
1979
+ return token.toLowerCase() === viem.zeroAddress.toLowerCase();
1980
+ }
1981
+ }
1982
+
1983
+ // src/protocols/evm/uniswap-v4/liquidityMultisign.ts
1984
+ var wethDepositAbi = viem.parseAbi(["function deposit() payable"]);
1985
+ var erc20AllowanceAbi = viem.parseAbi([
1986
+ "function allowance(address owner, address spender) view returns (uint256)",
1987
+ "function decimals() view returns (uint8)"
1988
+ ]);
1989
+ function parseOptionalGasLimitString2(raw) {
1990
+ if (raw == null) return null;
1991
+ const s = String(raw).trim();
1992
+ if (!s) return null;
1993
+ try {
1994
+ if (/^0x[0-9a-fA-F]+$/.test(s)) return BigInt(s);
1995
+ return BigInt(s);
1996
+ } catch {
1997
+ return null;
1998
+ }
1999
+ }
2000
+ function parseTxValueWei(tx) {
2001
+ const raw = tx.value ?? "0";
2002
+ try {
2003
+ if (typeof raw === "string" && /^0x[0-9a-fA-F]+$/.test(raw.trim())) return BigInt(raw.trim());
2004
+ return BigInt(String(raw).trim() || "0");
2005
+ } catch {
2006
+ return 0n;
2007
+ }
2008
+ }
2009
+ function dataHexFromTx(tx) {
2010
+ const d = (tx.data ?? "0x").toString().trim();
2011
+ return d.startsWith("0x") ? d : `0x${d}`;
2012
+ }
2013
+ function parseExtraJsonObject2(detail) {
2014
+ if (!detail) return null;
2015
+ const raw = detail.ExtraJSON ?? detail.extraJSON;
2016
+ if (raw == null) return null;
2017
+ if (typeof raw === "object" && !Array.isArray(raw)) return raw;
2018
+ if (typeof raw === "string" && raw.trim()) {
2019
+ try {
2020
+ const p = JSON.parse(raw);
2021
+ if (p && typeof p === "object" && !Array.isArray(p)) return p;
2022
+ } catch {
2023
+ return null;
2024
+ }
2025
+ }
2026
+ return null;
2027
+ }
2028
+ function uniswapV4LiquidityEvmTypeFromBatchMeta(ex, batchIndex) {
2029
+ if (!ex) return false;
2030
+ const bm = ex.batchMeta;
2031
+ if (!Array.isArray(bm) || !bm[batchIndex] || typeof bm[batchIndex] !== "object" || Array.isArray(bm[batchIndex])) {
2032
+ return false;
2033
+ }
2034
+ const evm0 = bm[batchIndex].evm;
2035
+ if (!evm0 || typeof evm0 !== "object" || Array.isArray(evm0)) return false;
2036
+ return String(evm0.type ?? "") === "uniswap_v4_liquidity_tx";
2037
+ }
2038
+ function isUniswapV4LiquidityEvmSignRequest(detail, batchIndex) {
2039
+ const ex = parseExtraJsonObject2(detail);
2040
+ if (batchIndex != null && batchIndex >= 0) {
2041
+ if (uniswapV4LiquidityEvmTypeFromBatchMeta(ex, batchIndex)) return true;
2042
+ } else if (uniswapV4LiquidityEvmTypeFromBatchMeta(ex, 0)) {
2043
+ return true;
2044
+ }
2045
+ const evm = ex?.evm;
2046
+ if (!evm || typeof evm !== "object" || Array.isArray(evm)) return false;
2047
+ return String(evm.type ?? "") === "uniswap_v4_liquidity_tx";
2048
+ }
2049
+ function defaultGasForAction(action) {
2050
+ switch (action) {
2051
+ case "mint":
2052
+ return UNISWAP_V4_LP_MINT_DEFAULT_GAS_UNITS;
2053
+ case "increase":
2054
+ return UNISWAP_V4_LP_INCREASE_DEFAULT_GAS_UNITS;
2055
+ case "decrease":
2056
+ return UNISWAP_V4_LP_DECREASE_DEFAULT_GAS_UNITS;
2057
+ case "collect":
2058
+ return UNISWAP_V4_LP_COLLECT_DEFAULT_GAS_UNITS;
2059
+ default:
2060
+ return UNISWAP_V4_LP_MINT_DEFAULT_GAS_UNITS;
2061
+ }
2062
+ }
2063
+ async function resolveApproveTargets(args) {
2064
+ const out = [];
2065
+ const pairs = [args.token0, args.token1].filter(Boolean);
2066
+ for (const row of pairs) {
2067
+ const amt = BigInt(row.amount);
2068
+ if (amt <= 0n) continue;
2069
+ if (isNativeUniswapLpTokenAddress(row.tokenAddress)) {
2070
+ if (!args.nativeWrapped) {
2071
+ throw new Error("nativeWrapped is required when LP uses native ETH (0x0) token.");
2072
+ }
2073
+ out.push({ token: viem.getAddress(args.nativeWrapped), amount: amt, kind: "weth_deposit" });
2074
+ continue;
2075
+ }
2076
+ out.push({ token: viem.getAddress(row.tokenAddress), amount: amt, kind: "approve" });
2077
+ }
2078
+ const deduped = [];
2079
+ for (const row of out) {
2080
+ const existing = deduped.find((d) => d.token === row.token && d.kind === row.kind);
2081
+ if (existing) {
2082
+ if (row.amount > existing.amount) existing.amount = row.amount;
2083
+ } else {
2084
+ deduped.push({ ...row });
2085
+ }
2086
+ }
2087
+ const steps = [];
2088
+ for (const row of deduped) {
2089
+ if (row.kind === "weth_deposit") {
2090
+ steps.push(row);
2091
+ continue;
2092
+ }
2093
+ const allowance = await args.publicClient.readContract({
2094
+ address: row.token,
2095
+ abi: erc20AllowanceAbi,
2096
+ functionName: "allowance",
2097
+ args: [args.executor, args.spender]
2098
+ });
2099
+ if (allowance < row.amount) {
2100
+ steps.push(row);
2101
+ }
2102
+ }
2103
+ return steps;
2104
+ }
2105
+ async function buildEvmMultisignBodyUniswapV4LiquidityBatchInternal(args) {
2106
+ const parsed = parseUniswapLpApiSnapshot({ action: args.action, lpResponse: args.lpResponse });
2107
+ const tx = parsed.transaction;
2108
+ const to = viem.getAddress(tx.to);
2109
+ const dataHex = dataHexFromTx(tx);
2110
+ const valueWei = parseTxValueWei(tx);
2111
+ const executor = viem.getAddress(args.executorAddress);
2112
+ const spender = to;
2113
+ const chain = viem.defineChain({
2114
+ id: args.chainId,
2115
+ name: `uniswap-v4-lp-${args.chainId}`,
2116
+ nativeCurrency: { name: "ETH", symbol: "ETH", decimals: 18 },
2117
+ rpcUrls: { default: { http: [args.rpcUrl] } }
2118
+ });
2119
+ const publicClient = viem.createPublicClient({ chain, transport: viem.http(args.rpcUrl) });
2120
+ const approveTargets = await resolveApproveTargets({
2121
+ publicClient,
2122
+ executor,
2123
+ spender,
2124
+ token0: parsed.token0,
2125
+ token1: parsed.token1,
2126
+ nativeWrapped: args.nativeWrapped
2127
+ });
2128
+ const steps = [];
2129
+ for (const target of approveTargets) {
2130
+ if (target.kind === "weth_deposit") {
2131
+ steps.push({
2132
+ to: target.token,
2133
+ data: viem.encodeFunctionData({ abi: wethDepositAbi, functionName: "deposit" }),
2134
+ value: target.amount,
2135
+ fallbackGas: UNISWAP_V4_LP_WETH_DEPOSIT_FALLBACK
2136
+ });
2137
+ steps.push({
2138
+ to: target.token,
2139
+ data: viem.encodeFunctionData({
2140
+ abi: viem.erc20Abi,
2141
+ functionName: "approve",
2142
+ args: [spender, target.amount]
2143
+ }),
2144
+ value: 0n,
2145
+ fallbackGas: UNISWAP_V4_LP_ERC20_APPROVE_FALLBACK
2146
+ });
2147
+ } else {
2148
+ steps.push({
2149
+ to: target.token,
2150
+ data: viem.encodeFunctionData({
2151
+ abi: viem.erc20Abi,
2152
+ functionName: "approve",
2153
+ args: [spender, target.amount]
2154
+ }),
2155
+ value: 0n,
2156
+ fallbackGas: UNISWAP_V4_LP_ERC20_APPROVE_FALLBACK
2157
+ });
2158
+ }
2159
+ }
2160
+ const lpFallbackGas = defaultGasForAction(args.action);
2161
+ const fromTradeApi = parseOptionalGasLimitString2(tx.gasLimit) ?? parseOptionalGasLimitString2(tx.gas);
2162
+ steps.push({
2163
+ to,
2164
+ data: dataHex,
2165
+ value: valueWei,
2166
+ fallbackGas: fromTradeApi != null && fromTradeApi > 0n ? fromTradeApi : lpFallbackGas
2167
+ });
2168
+ const actionLabel = args.action === "mint" ? "mint liquidity" : args.action === "increase" ? "increase liquidity" : args.action === "decrease" ? "decrease liquidity" : "collect fees";
2169
+ const dataNo0x = dataHex.startsWith("0x") ? dataHex.slice(2) : dataHex;
2170
+ const lpIndex = steps.length - 1;
2171
+ return buildEvmMultisignBatch({
2172
+ context: {
2173
+ chainCategory: "evm",
2174
+ keyGen: args.keyGen,
2175
+ purposeText: args.purposeText,
2176
+ chainId: args.chainId,
2177
+ rpcUrl: args.rpcUrl,
2178
+ executorAddress: args.executorAddress,
2179
+ chainDetail: args.chainDetail,
2180
+ useCustomGas: args.useCustomGas,
2181
+ customGasChainDetails: args.customGasChainDetails
2182
+ },
2183
+ steps,
2184
+ purposeSuffix: `Uniswap V4: ${steps.length}-tx batch \u2014 ${actionLabel} (classic ERC-20 approve + Position Manager).`,
2185
+ firstMsgRawNo0x: dataNo0x,
2186
+ destinationAddress: to,
2187
+ buildBatchMeta: ({ index }) => {
2188
+ const isLpStep = index === lpIndex;
2189
+ return {
2190
+ signatureText: JSON.stringify({
2191
+ kind: "UniswapV4Liquidity",
2192
+ action: args.action,
2193
+ step: index,
2194
+ lpTx: isLpStep
2195
+ }),
2196
+ ...isLpStep ? {
2197
+ evm: { type: "uniswap_v4_liquidity_tx", version: 1, chainId: String(args.chainId) },
2198
+ uniswapV4Liquidity: {
2199
+ action: args.action,
2200
+ skipPermit2Batch: true,
2201
+ nftTokenId: args.nftTokenId != null ? String(args.nftTokenId) : void 0,
2202
+ poolReference: args.poolReference,
2203
+ lpResponseSnapshot: args.lpResponse,
2204
+ token0: parsed.token0,
2205
+ token1: parsed.token1,
2206
+ tickLower: parsed.tickLower,
2207
+ tickUpper: parsed.tickUpper,
2208
+ transaction: {
2209
+ to: tx.to,
2210
+ value: tx.value,
2211
+ dataNibbles: dataNo0x.length,
2212
+ gasLimit: tx.gasLimit
2213
+ },
2214
+ originalPurpose: args.purposeText
2215
+ }
2216
+ } : {}
2217
+ };
2218
+ }
2219
+ });
2220
+ }
2221
+ async function buildEvmMultisignBodyUniswapV4MintLiquidityBatch(args) {
2222
+ return buildEvmMultisignBodyUniswapV4LiquidityBatchInternal({ ...args, action: "mint" });
2223
+ }
2224
+ async function buildEvmMultisignBodyUniswapV4IncreaseLiquidityBatch(args) {
2225
+ return buildEvmMultisignBodyUniswapV4LiquidityBatchInternal({ ...args, action: "increase" });
2226
+ }
2227
+ async function buildEvmMultisignBodyUniswapV4DecreaseLiquidityBatch(args) {
2228
+ return buildEvmMultisignBodyUniswapV4LiquidityBatchInternal({ ...args, action: "decrease" });
2229
+ }
2230
+ async function buildEvmMultisignBodyUniswapV4CollectFeesBatch(args) {
2231
+ return buildEvmMultisignBodyUniswapV4LiquidityBatchInternal({ ...args, action: "collect" });
2232
+ }
2233
+
1327
2234
  // src/protocols/evm/uniswap-v4/support.ts
1328
2235
  function computeUniswapV4Session(args) {
1329
2236
  const chainIdNum = typeof args.assetsChainId === "number" ? args.assetsChainId : parseInt(String(args.assetsChainId).trim(), 10);
@@ -1427,6 +2334,52 @@ var uniswapV4ProtocolModule = {
1427
2334
  amount: { type: "string", required: true, description: "Amount for quote" },
1428
2335
  type: { type: "EXACT_INPUT | EXACT_OUTPUT", required: true, description: "Trade type" }
1429
2336
  }
2337
+ },
2338
+ {
2339
+ id: "uniswap-v4.mint-liquidity",
2340
+ protocolId: UNISWAP_V4_PROTOCOL_ID,
2341
+ chainCategory: "evm",
2342
+ description: "Mint a new Uniswap V4 concentrated liquidity position (Position Manager NFT)",
2343
+ commonParams: ["keyGen", "purposeText", "useCustomGas"],
2344
+ params: {
2345
+ lpResponse: { type: "object", required: true, description: "Full LP API create response" },
2346
+ nativeWrapped: { type: "address", required: false, description: "WETH when pool uses native ETH" },
2347
+ poolReference: { type: "string", required: false, description: "V4 pool id" },
2348
+ uniswapApiKey: { type: "string", required: true, description: "Uniswap API key" }
2349
+ }
2350
+ },
2351
+ {
2352
+ id: "uniswap-v4.increase-liquidity",
2353
+ protocolId: UNISWAP_V4_PROTOCOL_ID,
2354
+ chainCategory: "evm",
2355
+ description: "Increase liquidity on an existing Uniswap V4 position NFT",
2356
+ commonParams: ["keyGen", "purposeText", "useCustomGas"],
2357
+ params: {
2358
+ nftTokenId: { type: "string", required: true, description: "Position NFT token id" },
2359
+ lpResponse: { type: "object", required: true, description: "Full LP API increase response" }
2360
+ }
2361
+ },
2362
+ {
2363
+ id: "uniswap-v4.decrease-liquidity",
2364
+ protocolId: UNISWAP_V4_PROTOCOL_ID,
2365
+ chainCategory: "evm",
2366
+ description: "Decrease liquidity on an existing Uniswap V4 position NFT",
2367
+ commonParams: ["keyGen", "purposeText", "useCustomGas"],
2368
+ params: {
2369
+ nftTokenId: { type: "string", required: true, description: "Position NFT token id" },
2370
+ lpResponse: { type: "object", required: true, description: "Full LP API decrease response" }
2371
+ }
2372
+ },
2373
+ {
2374
+ id: "uniswap-v4.collect-fees",
2375
+ protocolId: UNISWAP_V4_PROTOCOL_ID,
2376
+ chainCategory: "evm",
2377
+ description: "Collect accrued fees from a Uniswap V4 position NFT",
2378
+ commonParams: ["keyGen", "purposeText", "useCustomGas"],
2379
+ params: {
2380
+ nftTokenId: { type: "string", required: true, description: "Position NFT token id" },
2381
+ lpResponse: { type: "object", required: true, description: "Full LP API claim response" }
2382
+ }
1430
2383
  }
1431
2384
  ]
1432
2385
  };
@@ -1438,48 +2391,101 @@ var uniswapV4 = {
1438
2391
  swapFromQuote,
1439
2392
  buildSwapMultisignBody: buildEvmMultisignBodyUniswapV4SkipPermit2Batch,
1440
2393
  quote: uniswapTradeQuote,
2394
+ createLiquidityPosition: uniswapLpCreatePosition,
2395
+ increaseLiquidityPosition: uniswapLpIncreasePosition,
2396
+ decreaseLiquidityPosition: uniswapLpDecreasePosition,
2397
+ claimLiquidityFees: uniswapLpClaimFees,
2398
+ buildMintLiquidityMultisignBody: buildEvmMultisignBodyUniswapV4MintLiquidityBatch,
2399
+ buildIncreaseLiquidityMultisignBody: buildEvmMultisignBodyUniswapV4IncreaseLiquidityBatch,
2400
+ buildDecreaseLiquidityMultisignBody: buildEvmMultisignBodyUniswapV4DecreaseLiquidityBatch,
2401
+ buildCollectFeesMultisignBody: buildEvmMultisignBodyUniswapV4CollectFeesBatch,
2402
+ listPositions: listUniswapV4PositionsForWallet,
1441
2403
  isChainSupported: isUniswapV4ChainSupported
1442
2404
  };
1443
2405
 
1444
2406
  exports.MAX_UINT160 = MAX_UINT160;
1445
2407
  exports.MAX_UINT48 = MAX_UINT48;
1446
2408
  exports.PERMIT2_ADDRESS = PERMIT2_ADDRESS;
2409
+ exports.UNISWAP_LP_API_BASE_DEFAULT = UNISWAP_LP_API_BASE_DEFAULT;
2410
+ exports.UNISWAP_LP_DEFAULT_DEADLINE_SEC_OFFSET = UNISWAP_LP_DEFAULT_DEADLINE_SEC_OFFSET;
2411
+ exports.UNISWAP_LP_DEFAULT_EXPIRY_MINUTES = UNISWAP_LP_DEFAULT_EXPIRY_MINUTES;
2412
+ exports.UNISWAP_LP_DEFAULT_SLIPPAGE_PERCENT = UNISWAP_LP_DEFAULT_SLIPPAGE_PERCENT;
1447
2413
  exports.UNISWAP_SWAP_DEFAULT_DEADLINE_SEC_OFFSET = UNISWAP_SWAP_DEFAULT_DEADLINE_SEC_OFFSET;
1448
2414
  exports.UNISWAP_SWAP_DEFAULT_EXPIRY_MINUTES = UNISWAP_SWAP_DEFAULT_EXPIRY_MINUTES;
1449
2415
  exports.UNISWAP_TRADE_BASE_DEFAULT = UNISWAP_TRADE_BASE_DEFAULT;
1450
2416
  exports.UNISWAP_UNIVERSAL_ROUTER_DEFAULT_GAS_UNITS = UNISWAP_UNIVERSAL_ROUTER_DEFAULT_GAS_UNITS;
1451
2417
  exports.UNISWAP_UNIVERSAL_ROUTER_VERSION_DEFAULT = UNISWAP_UNIVERSAL_ROUTER_VERSION_DEFAULT;
2418
+ exports.UNISWAP_V4_LP_COLLECT_DEFAULT_GAS_UNITS = UNISWAP_V4_LP_COLLECT_DEFAULT_GAS_UNITS;
2419
+ exports.UNISWAP_V4_LP_DECREASE_DEFAULT_GAS_UNITS = UNISWAP_V4_LP_DECREASE_DEFAULT_GAS_UNITS;
2420
+ exports.UNISWAP_V4_LP_ERC20_APPROVE_FALLBACK = UNISWAP_V4_LP_ERC20_APPROVE_FALLBACK;
2421
+ exports.UNISWAP_V4_LP_INCREASE_DEFAULT_GAS_UNITS = UNISWAP_V4_LP_INCREASE_DEFAULT_GAS_UNITS;
2422
+ exports.UNISWAP_V4_LP_LOG_CHUNK_SIZE_DEFAULT = UNISWAP_V4_LP_LOG_CHUNK_SIZE_DEFAULT;
2423
+ exports.UNISWAP_V4_LP_LOG_CHUNK_SIZE_MIN = UNISWAP_V4_LP_LOG_CHUNK_SIZE_MIN;
2424
+ exports.UNISWAP_V4_LP_MINT_DEFAULT_GAS_UNITS = UNISWAP_V4_LP_MINT_DEFAULT_GAS_UNITS;
2425
+ exports.UNISWAP_V4_LP_POSITION_REGISTRY_HINT = UNISWAP_V4_LP_POSITION_REGISTRY_HINT;
2426
+ exports.UNISWAP_V4_LP_WETH_DEPOSIT_FALLBACK = UNISWAP_V4_LP_WETH_DEPOSIT_FALLBACK;
1452
2427
  exports.UNISWAP_V4_PROTOCOL_ID = UNISWAP_V4_PROTOCOL_ID;
1453
2428
  exports.applySlippagePercentToApproveWei = applySlippagePercentToApproveWei;
2429
+ exports.buildEvmMultisignBodyUniswapV4CollectFeesBatch = buildEvmMultisignBodyUniswapV4CollectFeesBatch;
2430
+ exports.buildEvmMultisignBodyUniswapV4DecreaseLiquidityBatch = buildEvmMultisignBodyUniswapV4DecreaseLiquidityBatch;
2431
+ exports.buildEvmMultisignBodyUniswapV4IncreaseLiquidityBatch = buildEvmMultisignBodyUniswapV4IncreaseLiquidityBatch;
2432
+ exports.buildEvmMultisignBodyUniswapV4MintLiquidityBatch = buildEvmMultisignBodyUniswapV4MintLiquidityBatch;
1454
2433
  exports.buildEvmMultisignBodyUniswapV4SkipPermit2Batch = buildEvmMultisignBodyUniswapV4SkipPermit2Batch;
1455
2434
  exports.buildUniswapQuoteRequestBody = buildUniswapQuoteRequestBody;
1456
2435
  exports.buildUniswapV4PurposePrefill = buildUniswapV4PurposePrefill;
1457
2436
  exports.computeUniswapV4Session = computeUniswapV4Session;
1458
2437
  exports.createSwap = createSwap;
1459
2438
  exports.errorMessageFromUniswapJsonBody = errorMessageFromUniswapJsonBody;
2439
+ exports.extractUniswapLpTokenAmounts = extractUniswapLpTokenAmounts;
2440
+ exports.extractUniswapLpTransaction = extractUniswapLpTransaction;
1460
2441
  exports.fetchEthereumAddressForKeyGen = fetchEthereumAddressForKeyGen;
1461
2442
  exports.formatUniswapAmountFieldFromWei = formatUniswapAmountFieldFromWei;
2443
+ exports.formatUniswapLpAmountHuman = formatUniswapLpAmountHuman;
1462
2444
  exports.formatUniswapPercentForUi = formatUniswapPercentForUi;
1463
2445
  exports.formatUniswapQuoteForDisplay = formatUniswapQuoteForDisplay;
2446
+ exports.formatUniswapV4PositionNotFoundError = formatUniswapV4PositionNotFoundError;
1464
2447
  exports.getClassicQuoteFromStoredUniswapResponse = getClassicQuoteFromStoredUniswapResponse;
1465
2448
  exports.getUniswapUniversalRouterSpenderOrThrow = getUniswapUniversalRouterSpenderOrThrow;
2449
+ exports.getUniswapV4PositionManagerDeployBlock = getUniswapV4PositionManagerDeployBlock;
2450
+ exports.getUniswapV4PositionManagerOrThrow = getUniswapV4PositionManagerOrThrow;
2451
+ exports.isEthGetLogsBlockRangeTooLargeError = isEthGetLogsBlockRangeTooLargeError;
2452
+ exports.isNativeUniswapLpTokenAddress = isNativeUniswapLpTokenAddress;
1466
2453
  exports.isUniswapFullQuoteResponseNativeIn = isUniswapFullQuoteResponseNativeIn;
1467
2454
  exports.isUniswapTokenInAddressNative = isUniswapTokenInAddressNative;
1468
2455
  exports.isUniswapV4ChainSupported = isUniswapV4ChainSupported;
2456
+ exports.isUniswapV4LiquidityEvmSignRequest = isUniswapV4LiquidityEvmSignRequest;
1469
2457
  exports.isUniswapV4SwapEvmSignRequest = isUniswapV4SwapEvmSignRequest;
2458
+ exports.listUniswapV4PositionsForWallet = listUniswapV4PositionsForWallet;
1470
2459
  exports.messageFromUniswapHttpResponseBody = messageFromUniswapHttpResponseBody;
1471
2460
  exports.parseUniswapChainId = parseUniswapChainId;
2461
+ exports.parseUniswapLpApiSnapshot = parseUniswapLpApiSnapshot;
1472
2462
  exports.parseUniswapQuoteClassicInOut = parseUniswapQuoteClassicInOut;
1473
2463
  exports.parseUniswapQuoteSlippageInfo = parseUniswapQuoteSlippageInfo;
2464
+ exports.parseUniswapV4ScanFromDateYmd = parseUniswapV4ScanFromDateYmd;
1474
2465
  exports.quoteSwap = quoteSwap;
2466
+ exports.readUniswapV4PositionInfoRaw = readUniswapV4PositionInfoRaw;
2467
+ exports.resolveBlockAtOrAfterUnixTime = resolveBlockAtOrAfterUnixTime;
1475
2468
  exports.resolveRouterSwapGasUnitsFromSignRequest = resolveRouterSwapGasUnitsFromSignRequest;
2469
+ exports.resolveUniswapV4PositionScanFromDate = resolveUniswapV4PositionScanFromDate;
1476
2470
  exports.swapExactInput = swapExactInput;
1477
2471
  exports.swapFromQuote = swapFromQuote;
1478
2472
  exports.swapTransactionDeadlineUnixFromExpiryMinutes = swapTransactionDeadlineUnixFromExpiryMinutes;
2473
+ exports.tryGetUniswapV4PositionManager = tryGetUniswapV4PositionManager;
1479
2474
  exports.uniswapCreateSwap = uniswapCreateSwap;
2475
+ exports.uniswapLpClaimFees = uniswapLpClaimFees;
2476
+ exports.uniswapLpCreatePosition = uniswapLpCreatePosition;
2477
+ exports.uniswapLpDecreasePosition = uniswapLpDecreasePosition;
2478
+ exports.uniswapLpIncreasePosition = uniswapLpIncreasePosition;
2479
+ exports.uniswapLpTxFieldForAction = uniswapLpTxFieldForAction;
1480
2480
  exports.uniswapQuoteToJsonQuoteOneLine = uniswapQuoteToJsonQuoteOneLine;
1481
2481
  exports.uniswapTradeQuote = uniswapTradeQuote;
1482
2482
  exports.uniswapV4 = uniswapV4;
2483
+ exports.uniswapV4ListPositionsForMcp = uniswapV4ListPositionsForMcp;
2484
+ exports.uniswapV4ListPositionsFromRegistryForMcp = uniswapV4ListPositionsFromRegistryForMcp;
2485
+ exports.uniswapV4ListPositionsRegistryMcpPlaceholder = uniswapV4ListPositionsRegistryMcpPlaceholder;
2486
+ exports.uniswapV4PositionMintedTokenIdsFromReceipt = uniswapV4PositionMintedTokenIdsFromReceipt;
1483
2487
  exports.uniswapV4ProtocolModule = uniswapV4ProtocolModule;
2488
+ exports.uniswapV4RegisterPositionFromMintTxPlaceholder = uniswapV4RegisterPositionFromMintTxPlaceholder;
2489
+ exports.uniswapV4RegisterPositionNftPlaceholder = uniswapV4RegisterPositionNftPlaceholder;
1484
2490
  //# sourceMappingURL=index.cjs.map
1485
2491
  //# sourceMappingURL=index.cjs.map