@hypurrquant/defi-cli 0.3.0 → 0.3.2

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.
@@ -1208,6 +1208,24 @@ var init_dist2 = __esm({
1208
1208
  if (!token) throw new Error(`Token not found: ${symbol}`);
1209
1209
  return token;
1210
1210
  }
1211
+ /**
1212
+ * Resolve a pool by name (e.g. "WHYPE/USDC") from a protocol's pool list.
1213
+ * Returns the pool info or throws if not found.
1214
+ */
1215
+ resolvePool(protocolSlug, poolName) {
1216
+ const protocol = this.getProtocol(protocolSlug);
1217
+ if (!protocol.pools || protocol.pools.length === 0) {
1218
+ throw new Error(`Protocol ${protocol.name} has no pools configured`);
1219
+ }
1220
+ const pool = protocol.pools.find(
1221
+ (p) => p.name.toLowerCase() === poolName.toLowerCase()
1222
+ );
1223
+ if (!pool) {
1224
+ const available = protocol.pools.map((p) => p.name).join(", ");
1225
+ throw new Error(`Pool '${poolName}' not found in ${protocol.name}. Available: ${available}`);
1226
+ }
1227
+ return pool;
1228
+ }
1211
1229
  };
1212
1230
  }
1213
1231
  });
@@ -1234,7 +1252,9 @@ __export(dist_exports2, {
1234
1252
  GenericOptionsAdapter: () => GenericOptionsAdapter,
1235
1253
  GenericYieldAdapter: () => GenericYieldAdapter,
1236
1254
  HlpVaultAdapter: () => HlpVaultAdapter,
1255
+ HybraGaugeAdapter: () => HybraGaugeAdapter,
1237
1256
  KinetiqAdapter: () => KinetiqAdapter,
1257
+ KittenSwapFarmingAdapter: () => KittenSwapFarmingAdapter,
1238
1258
  MasterChefAdapter: () => MasterChefAdapter,
1239
1259
  MerchantMoeLBAdapter: () => MerchantMoeLBAdapter,
1240
1260
  MorphoBlueAdapter: () => MorphoBlueAdapter,
@@ -1243,6 +1263,7 @@ __export(dist_exports2, {
1243
1263
  SolidlyAdapter: () => SolidlyAdapter,
1244
1264
  SolidlyGaugeAdapter: () => SolidlyGaugeAdapter,
1245
1265
  StHypeAdapter: () => StHypeAdapter,
1266
+ ThenaCLAdapter: () => ThenaCLAdapter,
1246
1267
  UniswapV2Adapter: () => UniswapV2Adapter,
1247
1268
  UniswapV3Adapter: () => UniswapV3Adapter,
1248
1269
  WooFiAdapter: () => WooFiAdapter,
@@ -1250,6 +1271,7 @@ __export(dist_exports2, {
1250
1271
  createDerivatives: () => createDerivatives,
1251
1272
  createDex: () => createDex,
1252
1273
  createGauge: () => createGauge,
1274
+ createKittenSwapFarming: () => createKittenSwapFarming,
1253
1275
  createLending: () => createLending,
1254
1276
  createLiquidStaking: () => createLiquidStaking,
1255
1277
  createMasterChef: () => createMasterChef,
@@ -1267,36 +1289,104 @@ import { encodeFunctionData as encodeFunctionData32, parseAbi as parseAbi32, cre
1267
1289
  import { encodeFunctionData as encodeFunctionData4, parseAbi as parseAbi4, zeroAddress as zeroAddress2 } from "viem";
1268
1290
  import { encodeFunctionData as encodeFunctionData5, parseAbi as parseAbi5 } from "viem";
1269
1291
  import { encodeFunctionData as encodeFunctionData6, parseAbi as parseAbi6, decodeAbiParameters as decodeAbiParameters4 } from "viem";
1270
- import { encodeFunctionData as encodeFunctionData7, parseAbi as parseAbi7, zeroAddress as zeroAddress3 } from "viem";
1271
- import { createPublicClient as createPublicClient4, encodeFunctionData as encodeFunctionData8, http as http4, parseAbi as parseAbi8, zeroAddress as zeroAddress4 } from "viem";
1272
- import { encodeFunctionData as encodeFunctionData9, parseAbi as parseAbi9, createPublicClient as createPublicClient5, http as http5 } from "viem";
1292
+ import { encodeFunctionData as encodeFunctionData7, parseAbi as parseAbi7, createPublicClient as createPublicClient4, http as http4, zeroAddress as zeroAddress3 } from "viem";
1293
+ import { createPublicClient as createPublicClient5, decodeFunctionResult as decodeFunctionResult22, encodeFunctionData as encodeFunctionData8, http as http5, parseAbi as parseAbi8, zeroAddress as zeroAddress4 } from "viem";
1294
+ import { encodeFunctionData as encodeFunctionData9, parseAbi as parseAbi9, zeroAddress as zeroAddress5 } from "viem";
1295
+ import { createPublicClient as createPublicClient6, decodeFunctionResult as decodeFunctionResult3, encodeFunctionData as encodeFunctionData10, http as http6, parseAbi as parseAbi10, zeroAddress as zeroAddress6 } from "viem";
1296
+ import { encodeFunctionData as encodeFunctionData11, parseAbi as parseAbi11, createPublicClient as createPublicClient7, http as http7 } from "viem";
1297
+ import {
1298
+ encodeFunctionData as encodeFunctionData12,
1299
+ decodeFunctionResult as decodeFunctionResult4,
1300
+ parseAbi as parseAbi12,
1301
+ createPublicClient as createPublicClient8,
1302
+ http as http8
1303
+ } from "viem";
1273
1304
  import {
1274
- encodeFunctionData as encodeFunctionData10,
1275
- decodeFunctionResult as decodeFunctionResult22,
1276
- parseAbi as parseAbi10,
1277
- createPublicClient as createPublicClient6,
1278
- http as http6
1305
+ decodeAbiParameters as decodeAbiParameters5,
1306
+ encodeFunctionData as encodeFunctionData13,
1307
+ encodeAbiParameters,
1308
+ http as http9,
1309
+ createPublicClient as createPublicClient9,
1310
+ keccak256,
1311
+ parseAbi as parseAbi13,
1312
+ decodeFunctionResult as decodeFunctionResult5,
1313
+ zeroAddress as zeroAddress7
1279
1314
  } from "viem";
1280
- import { createPublicClient as createPublicClient7, http as http7, parseAbi as parseAbi11, encodeFunctionData as encodeFunctionData11, decodeFunctionResult as decodeFunctionResult3, zeroAddress as zeroAddress5 } from "viem";
1281
- import { createPublicClient as createPublicClient8, http as http8, parseAbi as parseAbi12, encodeFunctionData as encodeFunctionData12, zeroAddress as zeroAddress6 } from "viem";
1282
- import { createPublicClient as createPublicClient9, http as http9, parseAbi as parseAbi13 } from "viem";
1283
- import { createPublicClient as createPublicClient10, http as http10, parseAbi as parseAbi14, encodeFunctionData as encodeFunctionData13 } from "viem";
1284
- import { createPublicClient as createPublicClient11, http as http11, parseAbi as parseAbi15, encodeFunctionData as encodeFunctionData14 } from "viem";
1285
- import { createPublicClient as createPublicClient12, http as http12, parseAbi as parseAbi16, encodeFunctionData as encodeFunctionData15 } from "viem";
1286
- import { parseAbi as parseAbi17, encodeFunctionData as encodeFunctionData16, decodeFunctionResult as decodeFunctionResult4, zeroAddress as zeroAddress7 } from "viem";
1287
- import { createPublicClient as createPublicClient13, http as http13, parseAbi as parseAbi18, encodeFunctionData as encodeFunctionData17, zeroAddress as zeroAddress8 } from "viem";
1288
- import { createPublicClient as createPublicClient14, http as http14, parseAbi as parseAbi19 } from "viem";
1289
- import { createPublicClient as createPublicClient15, http as http15, parseAbi as parseAbi20, encodeFunctionData as encodeFunctionData18 } from "viem";
1290
- import { parseAbi as parseAbi21, encodeFunctionData as encodeFunctionData19 } from "viem";
1291
- import { createPublicClient as createPublicClient16, http as http16, parseAbi as parseAbi222, encodeFunctionData as encodeFunctionData20, zeroAddress as zeroAddress9 } from "viem";
1292
- import { createPublicClient as createPublicClient17, http as http17, parseAbi as parseAbi23, encodeFunctionData as encodeFunctionData21, zeroAddress as zeroAddress10 } from "viem";
1315
+ import { createPublicClient as createPublicClient10, http as http10, parseAbi as parseAbi14, encodeFunctionData as encodeFunctionData14, decodeFunctionResult as decodeFunctionResult6, zeroAddress as zeroAddress8 } from "viem";
1316
+ import { createPublicClient as createPublicClient11, http as http11, parseAbi as parseAbi15, encodeFunctionData as encodeFunctionData15, zeroAddress as zeroAddress9 } from "viem";
1317
+ import { createPublicClient as createPublicClient12, http as http12, parseAbi as parseAbi16 } from "viem";
1318
+ import { createPublicClient as createPublicClient13, http as http13, parseAbi as parseAbi17, encodeFunctionData as encodeFunctionData16 } from "viem";
1319
+ import { createPublicClient as createPublicClient14, http as http14, parseAbi as parseAbi18, encodeFunctionData as encodeFunctionData17 } from "viem";
1320
+ import { createPublicClient as createPublicClient15, http as http15, parseAbi as parseAbi19, encodeFunctionData as encodeFunctionData18 } from "viem";
1321
+ import { parseAbi as parseAbi20, encodeFunctionData as encodeFunctionData19, decodeFunctionResult as decodeFunctionResult7, zeroAddress as zeroAddress10 } from "viem";
1322
+ import { createPublicClient as createPublicClient16, http as http16, parseAbi as parseAbi21, encodeFunctionData as encodeFunctionData20, zeroAddress as zeroAddress11 } from "viem";
1323
+ import { createPublicClient as createPublicClient17, http as http17, parseAbi as parseAbi222 } from "viem";
1324
+ import { createPublicClient as createPublicClient18, http as http18, parseAbi as parseAbi23, encodeFunctionData as encodeFunctionData21 } from "viem";
1293
1325
  import { parseAbi as parseAbi24, encodeFunctionData as encodeFunctionData222 } from "viem";
1294
- import { parseAbi as parseAbi25, encodeFunctionData as encodeFunctionData23 } from "viem";
1295
- import { createPublicClient as createPublicClient18, http as http18, parseAbi as parseAbi26 } from "viem";
1326
+ import { createPublicClient as createPublicClient19, http as http19, parseAbi as parseAbi25, encodeFunctionData as encodeFunctionData23, zeroAddress as zeroAddress12 } from "viem";
1327
+ import { createPublicClient as createPublicClient20, http as http20, parseAbi as parseAbi26, encodeFunctionData as encodeFunctionData24, zeroAddress as zeroAddress13 } from "viem";
1328
+ import { parseAbi as parseAbi27, encodeFunctionData as encodeFunctionData25 } from "viem";
1329
+ import { parseAbi as parseAbi28, encodeFunctionData as encodeFunctionData26 } from "viem";
1330
+ import { createPublicClient as createPublicClient21, http as http21, parseAbi as parseAbi29 } from "viem";
1331
+ function pctToTickDelta(pct) {
1332
+ return Math.round(Math.log(1 + pct / 100) / Math.log(1.0001));
1333
+ }
1334
+ function alignTickDown(tick, tickSpacing) {
1335
+ return Math.floor(tick / tickSpacing) * tickSpacing;
1336
+ }
1337
+ function alignTickUp(tick, tickSpacing) {
1338
+ return Math.ceil(tick / tickSpacing) * tickSpacing;
1339
+ }
1340
+ function rangeToTicks(currentTick, rangePct, tickSpacing) {
1341
+ const delta = pctToTickDelta(rangePct);
1342
+ return {
1343
+ tickLower: alignTickDown(currentTick - delta, tickSpacing),
1344
+ tickUpper: alignTickUp(currentTick + delta, tickSpacing)
1345
+ };
1346
+ }
1347
+ function decodeAddress(data) {
1348
+ if (!data) return null;
1349
+ try {
1350
+ return decodeFunctionResult22({ abi: _addressDecodeAbi, functionName: "f", data });
1351
+ } catch {
1352
+ return null;
1353
+ }
1354
+ }
1355
+ function decodeSymbol(data) {
1356
+ if (!data) return "?";
1357
+ try {
1358
+ return decodeFunctionResult22({ abi: _symbolDecodeAbi, functionName: "symbol", data });
1359
+ } catch {
1360
+ return "?";
1361
+ }
1362
+ }
1363
+ function decodeAddress2(data) {
1364
+ if (!data) return null;
1365
+ try {
1366
+ return decodeFunctionResult3({ abi: _addressDecodeAbi2, functionName: "f", data });
1367
+ } catch {
1368
+ return null;
1369
+ }
1370
+ }
1371
+ function decodeSymbol2(data) {
1372
+ if (!data) return "?";
1373
+ try {
1374
+ return decodeFunctionResult3({ abi: _symbolDecodeAbi2, functionName: "symbol", data });
1375
+ } catch {
1376
+ return "?";
1377
+ }
1378
+ }
1379
+ function decodeBoolean(data) {
1380
+ try {
1381
+ return decodeFunctionResult3({ abi: _boolDecodeAbi, functionName: "f", data });
1382
+ } catch {
1383
+ return false;
1384
+ }
1385
+ }
1296
1386
  function decodeAddressResult(data) {
1297
1387
  if (!data) return null;
1298
1388
  try {
1299
- return decodeFunctionResult22({ abi: _addressAbi, functionName: "f", data });
1389
+ return decodeFunctionResult4({ abi: _addressAbi, functionName: "f", data });
1300
1390
  } catch {
1301
1391
  return null;
1302
1392
  }
@@ -1304,7 +1394,7 @@ function decodeAddressResult(data) {
1304
1394
  function decodeUint256Result(data) {
1305
1395
  if (!data) return null;
1306
1396
  try {
1307
- return decodeFunctionResult22({ abi: _uint256Abi, functionName: "f", data });
1397
+ return decodeFunctionResult4({ abi: _uint256Abi, functionName: "f", data });
1308
1398
  } catch {
1309
1399
  return null;
1310
1400
  }
@@ -1312,7 +1402,7 @@ function decodeUint256Result(data) {
1312
1402
  function decodeBoolResult(data) {
1313
1403
  if (!data) return null;
1314
1404
  try {
1315
- return decodeFunctionResult22({ abi: _boolAbi, functionName: "f", data });
1405
+ return decodeFunctionResult4({ abi: _boolAbi, functionName: "f", data });
1316
1406
  } catch {
1317
1407
  return null;
1318
1408
  }
@@ -1320,7 +1410,7 @@ function decodeBoolResult(data) {
1320
1410
  function decodeStringResult(data) {
1321
1411
  if (!data) return "?";
1322
1412
  try {
1323
- return decodeFunctionResult22({ abi: erc20Abi2, functionName: "symbol", data });
1413
+ return decodeFunctionResult4({ abi: erc20Abi2, functionName: "symbol", data });
1324
1414
  } catch {
1325
1415
  return "?";
1326
1416
  }
@@ -1328,7 +1418,7 @@ function decodeStringResult(data) {
1328
1418
  function decodeRangeResult(data) {
1329
1419
  if (!data) return null;
1330
1420
  try {
1331
- return decodeFunctionResult22({ abi: _rangeAbi, functionName: "f", data });
1421
+ return decodeFunctionResult4({ abi: _rangeAbi, functionName: "f", data });
1332
1422
  } catch {
1333
1423
  return null;
1334
1424
  }
@@ -1336,7 +1426,7 @@ function decodeRangeResult(data) {
1336
1426
  function decodeBinResult(data) {
1337
1427
  if (!data) return null;
1338
1428
  try {
1339
- return decodeFunctionResult22({ abi: _binAbi, functionName: "f", data });
1429
+ return decodeFunctionResult4({ abi: _binAbi, functionName: "f", data });
1340
1430
  } catch {
1341
1431
  return null;
1342
1432
  }
@@ -1344,7 +1434,7 @@ function decodeBinResult(data) {
1344
1434
  function decodeUint256ArrayResult(data) {
1345
1435
  if (!data) return null;
1346
1436
  try {
1347
- return decodeFunctionResult22({ abi: _uint256ArrayAbi, functionName: "f", data });
1437
+ return decodeFunctionResult4({ abi: _uint256ArrayAbi, functionName: "f", data });
1348
1438
  } catch {
1349
1439
  return null;
1350
1440
  }
@@ -1384,19 +1474,76 @@ function buildUniformDistribution(deltaIds) {
1384
1474
  }
1385
1475
  return { distributionX, distributionY };
1386
1476
  }
1477
+ function decodeAddress3(data) {
1478
+ if (!data) return null;
1479
+ try {
1480
+ return decodeFunctionResult5({ abi: _addressDecodeAbi3, functionName: "f", data });
1481
+ } catch {
1482
+ return null;
1483
+ }
1484
+ }
1485
+ function incentiveId(key) {
1486
+ return keccak256(
1487
+ encodeAbiParameters(
1488
+ [
1489
+ { name: "rewardToken", type: "address" },
1490
+ { name: "bonusRewardToken", type: "address" },
1491
+ { name: "pool", type: "address" },
1492
+ { name: "nonce", type: "uint256" }
1493
+ ],
1494
+ [key.rewardToken, key.bonusRewardToken, key.pool, key.nonce]
1495
+ )
1496
+ );
1497
+ }
1498
+ function encodeEnterFarming(key, tokenId) {
1499
+ return encodeFunctionData13({
1500
+ abi: farmingCenterAbi,
1501
+ functionName: "enterFarming",
1502
+ args: [key, tokenId]
1503
+ });
1504
+ }
1505
+ function encodeExitFarming(key, tokenId) {
1506
+ return encodeFunctionData13({
1507
+ abi: farmingCenterAbi,
1508
+ functionName: "exitFarming",
1509
+ args: [key, tokenId]
1510
+ });
1511
+ }
1512
+ function encodeCollectRewards(key, tokenId) {
1513
+ return encodeFunctionData13({
1514
+ abi: farmingCenterAbi,
1515
+ functionName: "collectRewards",
1516
+ args: [key, tokenId]
1517
+ });
1518
+ }
1519
+ function encodeClaimReward(rewardToken, to) {
1520
+ return encodeFunctionData13({
1521
+ abi: farmingCenterAbi,
1522
+ functionName: "claimReward",
1523
+ args: [rewardToken, to, 2n ** 128n - 1n]
1524
+ // max uint128
1525
+ });
1526
+ }
1527
+ function encodeMulticall(calls) {
1528
+ return encodeFunctionData13({
1529
+ abi: farmingCenterAbi,
1530
+ functionName: "multicall",
1531
+ args: [calls]
1532
+ });
1533
+ }
1387
1534
  function u256ToF64(v) {
1388
1535
  const MAX_U128 = (1n << 128n) - 1n;
1389
1536
  if (v > MAX_U128) return Infinity;
1390
1537
  return Number(v);
1391
1538
  }
1392
- function decodeAddress(data) {
1539
+ function decodeAddress4(data) {
1393
1540
  if (!data || data.length < 66) return null;
1394
1541
  return `0x${data.slice(26, 66)}`;
1395
1542
  }
1396
1543
  function decodeAddressArray(data) {
1397
1544
  if (!data) return [];
1398
1545
  try {
1399
- return decodeFunctionResult3({
1546
+ return decodeFunctionResult6({
1400
1547
  abi: REWARDS_CONTROLLER_ABI,
1401
1548
  functionName: "getRewardsByAsset",
1402
1549
  data
@@ -1408,7 +1555,7 @@ function decodeAddressArray(data) {
1408
1555
  function decodeReserveData(data) {
1409
1556
  if (!data) return null;
1410
1557
  try {
1411
- return decodeFunctionResult3({
1558
+ return decodeFunctionResult6({
1412
1559
  abi: POOL_ABI,
1413
1560
  functionName: "getReserveData",
1414
1561
  data
@@ -1420,7 +1567,7 @@ function decodeReserveData(data) {
1420
1567
  function decodeRewardsData(data) {
1421
1568
  if (!data) return null;
1422
1569
  try {
1423
- return decodeFunctionResult3({
1570
+ return decodeFunctionResult6({
1424
1571
  abi: REWARDS_CONTROLLER_ABI,
1425
1572
  functionName: "getRewardsData",
1426
1573
  data
@@ -1434,19 +1581,19 @@ function u256ToF642(v) {
1434
1581
  if (v > MAX_U128) return Infinity;
1435
1582
  return Number(v);
1436
1583
  }
1437
- function defaultMarketParams(loanToken = zeroAddress7) {
1584
+ function defaultMarketParams(loanToken = zeroAddress10) {
1438
1585
  return {
1439
1586
  loanToken,
1440
- collateralToken: zeroAddress7,
1441
- oracle: zeroAddress7,
1442
- irm: zeroAddress7,
1587
+ collateralToken: zeroAddress10,
1588
+ oracle: zeroAddress10,
1589
+ irm: zeroAddress10,
1443
1590
  lltv: 0n
1444
1591
  };
1445
1592
  }
1446
1593
  function decodeMarket(data) {
1447
1594
  if (!data) return null;
1448
1595
  try {
1449
- return decodeFunctionResult4({
1596
+ return decodeFunctionResult7({
1450
1597
  abi: MORPHO_ABI,
1451
1598
  functionName: "market",
1452
1599
  data
@@ -1458,7 +1605,7 @@ function decodeMarket(data) {
1458
1605
  function decodeMarketParams(data) {
1459
1606
  if (!data) return null;
1460
1607
  try {
1461
- return decodeFunctionResult4({
1608
+ return decodeFunctionResult7({
1462
1609
  abi: MORPHO_ABI,
1463
1610
  functionName: "idToMarketParams",
1464
1611
  data
@@ -1482,6 +1629,8 @@ function createDex(entry, rpcUrl) {
1482
1629
  case "solidly_v2":
1483
1630
  case "solidly_cl":
1484
1631
  return new SolidlyAdapter(entry, rpcUrl);
1632
+ case "hybra":
1633
+ return new ThenaCLAdapter(entry, rpcUrl);
1485
1634
  case "curve_stableswap":
1486
1635
  return new CurveStableSwapAdapter(entry);
1487
1636
  case "balancer_v3":
@@ -1542,11 +1691,13 @@ function createLiquidStaking(entry, rpcUrl) {
1542
1691
  }
1543
1692
  }
1544
1693
  function createGauge(entry, rpcUrl) {
1694
+ if (entry.interface === "hybra" || entry.contracts?.["gauge_manager"]) {
1695
+ return new HybraGaugeAdapter(entry, rpcUrl);
1696
+ }
1545
1697
  switch (entry.interface) {
1546
1698
  case "solidly_v2":
1547
1699
  case "solidly_cl":
1548
1700
  case "algebra_v3":
1549
- case "hybra":
1550
1701
  return new SolidlyGaugeAdapter(entry, rpcUrl);
1551
1702
  default:
1552
1703
  throw DefiError.unsupported(`Gauge interface '${entry.interface}' not supported`);
@@ -1609,7 +1760,23 @@ function createOracleFromCdp(entry, _asset, rpcUrl) {
1609
1760
  function createMerchantMoeLB(entry, rpcUrl) {
1610
1761
  return new MerchantMoeLBAdapter(entry, rpcUrl);
1611
1762
  }
1612
- var DEFAULT_FEE, swapRouterAbi, quoterAbi, ramsesQuoterAbi, positionManagerAbi, UniswapV3Adapter, abi, lbQuoterAbi, UniswapV2Adapter, abi2, algebraQuoterAbi, algebraSingleQuoterAbi, algebraPositionManagerAbi, AlgebraV3Adapter, abi3, BalancerV3Adapter, poolAbi, CurveStableSwapAdapter, abi4, abiV2, SolidlyAdapter, abi5, WooFiAdapter, gaugeAbi, veAbi, voterAbi, SolidlyGaugeAdapter, masterchefAbi, MasterChefAdapter, lbRouterAbi, lbFactoryAbi, lbPairAbi, lbRewarderAbi, masterChefAbi, veMoeAbi, lbPairBinAbi, lbQuoterAbi2, erc20Abi2, _addressAbi, _uint256Abi, _boolAbi, _rangeAbi, _binAbi, _uint256ArrayAbi, MerchantMoeLBAdapter, POOL_ABI, ERC20_ABI, INCENTIVES_ABI, REWARDS_CONTROLLER_ABI, POOL_PROVIDER_ABI, ADDRESSES_PROVIDER_ABI, ORACLE_ABI, ERC20_DECIMALS_ABI, AaveV3Adapter, POOL_ABI2, ERC20_ABI2, AaveV2Adapter, ORACLE_ABI2, AaveOracleAdapter, CTOKEN_ABI, BSC_BLOCKS_PER_YEAR, CompoundV2Adapter, COMET_ABI, SECONDS_PER_YEAR, CompoundV3Adapter, EULER_VAULT_ABI, SECONDS_PER_YEAR2, EulerV2Adapter, MORPHO_ABI, META_MORPHO_ABI, IRM_ABI, SECONDS_PER_YEAR3, MorphoBlueAdapter, BORROWER_OPS_ABI, TROVE_MANAGER_ABI, HINT_HELPERS_ABI, SORTED_TROVES_ABI, FelixCdpAdapter, PRICE_FEED_ABI, FelixOracleAdapter, ERC4626_ABI, ERC4626VaultAdapter, GENERIC_LST_ABI, GenericLstAdapter, STHYPE_ABI, ERC20_ABI3, StHypeAdapter, KINETIQ_ABI, ORACLE_ABI3, WHYPE, HYPERLEND_ORACLE, KinetiqAdapter, PendleAdapter, GenericYieldAdapter, HLP_ABI, HlpVaultAdapter, GenericDerivativesAdapter, RYSK_ABI, RyskAdapter, GenericOptionsAdapter, ERC721_ABI, ERC721Adapter, DexSpotPrice;
1763
+ function createKittenSwapFarming(entry, rpcUrl) {
1764
+ const farmingCenter = entry.contracts?.["farming_center"];
1765
+ if (!farmingCenter) {
1766
+ throw new DefiError("CONTRACT_ERROR", `[${entry.name}] Missing 'farming_center' contract address`);
1767
+ }
1768
+ const eternalFarming = entry.contracts?.["eternal_farming"];
1769
+ if (!eternalFarming) {
1770
+ throw new DefiError("CONTRACT_ERROR", `[${entry.name}] Missing 'eternal_farming' contract address`);
1771
+ }
1772
+ const positionManager = entry.contracts?.["position_manager"];
1773
+ if (!positionManager) {
1774
+ throw new DefiError("CONTRACT_ERROR", `[${entry.name}] Missing 'position_manager' contract address`);
1775
+ }
1776
+ const factory = entry.contracts?.["factory"];
1777
+ return new KittenSwapFarmingAdapter(entry.name, farmingCenter, eternalFarming, positionManager, rpcUrl, factory);
1778
+ }
1779
+ var DEFAULT_FEE, swapRouterAbi, quoterAbi, ramsesQuoterAbi, positionManagerAbi, UniswapV3Adapter, abi, lbQuoterAbi, UniswapV2Adapter, abi2, algebraQuoterAbi, algebraSingleQuoterAbi, algebraIntegralPmAbi, algebraV2PmAbi, AlgebraV3Adapter, abi3, BalancerV3Adapter, poolAbi, CurveStableSwapAdapter, abi4, abiV2, SolidlyAdapter, thenaPmAbi, thenaRouterAbi, thenaPoolAbi, thenaFactoryAbi, ThenaCLAdapter, _addressDecodeAbi, _symbolDecodeAbi, gaugeManagerAbi, gaugeCLAbi, nfpmAbi, veAbi, voterAbi, HybraGaugeAdapter, abi5, WooFiAdapter, gaugeAbi, veAbi2, voterAbi2, _addressDecodeAbi2, _symbolDecodeAbi2, _boolDecodeAbi, HYPEREVM_TOKENS, CL_TICK_SPACINGS, SolidlyGaugeAdapter, masterchefAbi, MasterChefAdapter, lbRouterAbi, lbFactoryAbi, lbPairAbi, lbRewarderAbi, masterChefAbi, veMoeAbi, lbPairBinAbi, lbQuoterAbi2, erc20Abi2, _addressAbi, _uint256Abi, _boolAbi, _rangeAbi, _binAbi, _uint256ArrayAbi, MerchantMoeLBAdapter, KITTEN_TOKEN, WHYPE_TOKEN, MAX_NONCE_SCAN, HYPEREVM_TOKENS2, farmingCenterAbi, positionManagerAbi2, eternalFarmingAbi, algebraFactoryAbi, _addressDecodeAbi3, nonceCache, KittenSwapFarmingAdapter, POOL_ABI, ERC20_ABI, INCENTIVES_ABI, REWARDS_CONTROLLER_ABI, POOL_PROVIDER_ABI, ADDRESSES_PROVIDER_ABI, ORACLE_ABI, ERC20_DECIMALS_ABI, AaveV3Adapter, POOL_ABI2, ERC20_ABI2, AaveV2Adapter, ORACLE_ABI2, AaveOracleAdapter, CTOKEN_ABI, BSC_BLOCKS_PER_YEAR, CompoundV2Adapter, COMET_ABI, SECONDS_PER_YEAR, CompoundV3Adapter, EULER_VAULT_ABI, SECONDS_PER_YEAR2, EulerV2Adapter, MORPHO_ABI, META_MORPHO_ABI, IRM_ABI, SECONDS_PER_YEAR3, MorphoBlueAdapter, BORROWER_OPS_ABI, TROVE_MANAGER_ABI, HINT_HELPERS_ABI, SORTED_TROVES_ABI, FelixCdpAdapter, PRICE_FEED_ABI, FelixOracleAdapter, ERC4626_ABI, ERC4626VaultAdapter, GENERIC_LST_ABI, GenericLstAdapter, STHYPE_ABI, ERC20_ABI3, StHypeAdapter, KINETIQ_ABI, ORACLE_ABI3, WHYPE, HYPERLEND_ORACLE, KinetiqAdapter, PendleAdapter, GenericYieldAdapter, HLP_ABI, HlpVaultAdapter, GenericDerivativesAdapter, RYSK_ABI, RyskAdapter, GenericOptionsAdapter, ERC721_ABI, ERC721Adapter, DexSpotPrice;
1613
1780
  var init_dist3 = __esm({
1614
1781
  "../defi-protocols/dist/index.js"() {
1615
1782
  "use strict";
@@ -1644,6 +1811,9 @@ var init_dist3 = __esm({
1644
1811
  init_dist2();
1645
1812
  init_dist2();
1646
1813
  init_dist2();
1814
+ init_dist2();
1815
+ init_dist2();
1816
+ init_dist2();
1647
1817
  DEFAULT_FEE = 3e3;
1648
1818
  swapRouterAbi = parseAbi3([
1649
1819
  "struct ExactInputSingleParams { address tokenIn; address tokenOut; uint24 fee; address recipient; uint256 deadline; uint256 amountIn; uint256 amountOutMinimum; uint160 sqrtPriceLimitX96; }",
@@ -2105,7 +2275,11 @@ var init_dist3 = __esm({
2105
2275
  algebraSingleQuoterAbi = parseAbi32([
2106
2276
  "function quoteExactInputSingle((address tokenIn, address tokenOut, uint256 amountIn, uint160 limitSqrtPrice) params) external returns (uint256 amountOut, uint256 amountIn, uint160 sqrtPriceX96After)"
2107
2277
  ]);
2108
- algebraPositionManagerAbi = parseAbi32([
2278
+ algebraIntegralPmAbi = parseAbi32([
2279
+ "struct MintParams { address token0; address token1; address deployer; int24 tickLower; int24 tickUpper; uint256 amount0Desired; uint256 amount1Desired; uint256 amount0Min; uint256 amount1Min; address recipient; uint256 deadline; }",
2280
+ "function mint(MintParams calldata params) external payable returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1)"
2281
+ ]);
2282
+ algebraV2PmAbi = parseAbi32([
2109
2283
  "struct MintParams { address token0; address token1; int24 tickLower; int24 tickUpper; uint256 amount0Desired; uint256 amount1Desired; uint256 amount0Min; uint256 amount1Min; address recipient; uint256 deadline; }",
2110
2284
  "function mint(MintParams calldata params) external payable returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1)"
2111
2285
  ]);
@@ -2250,36 +2424,58 @@ var init_dist3 = __esm({
2250
2424
  throw new DefiError("CONTRACT_ERROR", "Position manager address not configured");
2251
2425
  }
2252
2426
  const [token0, token1, rawAmount0, rawAmount1] = params.token_a.toLowerCase() < params.token_b.toLowerCase() ? [params.token_a, params.token_b, params.amount_a, params.amount_b] : [params.token_b, params.token_a, params.amount_b, params.amount_a];
2253
- const amount0 = rawAmount0 === 0n && rawAmount1 > 0n ? 1n : rawAmount0;
2254
- const amount1 = rawAmount1 === 0n && rawAmount0 > 0n ? 1n : rawAmount1;
2255
- const data = encodeFunctionData32({
2256
- abi: algebraPositionManagerAbi,
2427
+ let tickLower = params.tick_lower ?? -887220;
2428
+ let tickUpper = params.tick_upper ?? 887220;
2429
+ const isSingleSide = rawAmount0 === 0n || rawAmount1 === 0n;
2430
+ const needsAutoTick = params.range_pct !== void 0 || isSingleSide && !params.tick_lower && !params.tick_upper;
2431
+ if (needsAutoTick) {
2432
+ if (!this.rpcUrl) throw DefiError.rpcError("RPC URL required for auto tick detection");
2433
+ const poolAddr = params.pool;
2434
+ if (!poolAddr) throw new DefiError("CONTRACT_ERROR", "Pool address required (use --pool)");
2435
+ const client = createPublicClient3({ transport: http3(this.rpcUrl) });
2436
+ const algebraPoolAbi = parseAbi32([
2437
+ "function globalState() view returns (uint160 price, int24 tick, uint16 lastFee, uint8 pluginConfig, uint16 communityFee, bool unlocked)",
2438
+ "function tickSpacing() view returns (int24)"
2439
+ ]);
2440
+ const [globalState, spacing] = await Promise.all([
2441
+ client.readContract({ address: poolAddr, abi: algebraPoolAbi, functionName: "globalState" }),
2442
+ client.readContract({ address: poolAddr, abi: algebraPoolAbi, functionName: "tickSpacing" })
2443
+ ]);
2444
+ const currentTick = Number(globalState[1]);
2445
+ const tickSpace = Number(spacing);
2446
+ if (params.range_pct !== void 0) {
2447
+ const range = rangeToTicks(currentTick, params.range_pct, tickSpace);
2448
+ tickLower = range.tickLower;
2449
+ tickUpper = range.tickUpper;
2450
+ } else if (rawAmount0 > 0n && rawAmount1 === 0n) {
2451
+ tickLower = alignTickUp(currentTick + tickSpace, tickSpace);
2452
+ tickUpper = 887220;
2453
+ } else {
2454
+ tickLower = -887220;
2455
+ tickUpper = alignTickDown(currentTick - tickSpace, tickSpace);
2456
+ }
2457
+ }
2458
+ const amount0 = rawAmount0;
2459
+ const amount1 = rawAmount1;
2460
+ const data = this.useSingleQuoter ? encodeFunctionData32({
2461
+ abi: algebraV2PmAbi,
2257
2462
  functionName: "mint",
2258
- args: [
2259
- {
2260
- token0,
2261
- token1,
2262
- tickLower: -887220,
2263
- tickUpper: 887220,
2264
- amount0Desired: amount0,
2265
- amount1Desired: amount1,
2266
- amount0Min: 0n,
2267
- amount1Min: 0n,
2268
- recipient: params.recipient,
2269
- deadline: BigInt("18446744073709551615")
2270
- }
2271
- ]
2463
+ args: [{ token0, token1, tickLower, tickUpper, amount0Desired: amount0, amount1Desired: amount1, amount0Min: 0n, amount1Min: 0n, recipient: params.recipient, deadline: BigInt("18446744073709551615") }]
2464
+ }) : encodeFunctionData32({
2465
+ abi: algebraIntegralPmAbi,
2466
+ functionName: "mint",
2467
+ args: [{ token0, token1, deployer: zeroAddress, tickLower, tickUpper, amount0Desired: amount0, amount1Desired: amount1, amount0Min: 0n, amount1Min: 0n, recipient: params.recipient, deadline: BigInt("18446744073709551615") }]
2272
2468
  });
2469
+ const approvals = [];
2470
+ if (amount0 > 0n) approvals.push({ token: token0, spender: pm, amount: amount0 });
2471
+ if (amount1 > 0n) approvals.push({ token: token1, spender: pm, amount: amount1 });
2273
2472
  return {
2274
- description: `[${this.protocolName}] Add liquidity`,
2473
+ description: `[${this.protocolName}] Add liquidity [${tickLower}, ${tickUpper}]`,
2275
2474
  to: pm,
2276
2475
  data,
2277
2476
  value: 0n,
2278
2477
  gas_estimate: 5e5,
2279
- approvals: [
2280
- { token: token0, spender: pm, amount: amount0 },
2281
- { token: token1, spender: pm, amount: amount1 }
2282
- ]
2478
+ approvals
2283
2479
  };
2284
2480
  }
2285
2481
  async buildRemoveLiquidity(_params) {
@@ -2571,7 +2767,440 @@ var init_dist3 = __esm({
2571
2767
  };
2572
2768
  }
2573
2769
  };
2574
- abi5 = parseAbi7([
2770
+ thenaPmAbi = parseAbi7([
2771
+ "struct MintParams { address token0; address token1; int24 tickSpacing; int24 tickLower; int24 tickUpper; uint256 amount0Desired; uint256 amount1Desired; uint256 amount0Min; uint256 amount1Min; address recipient; uint256 deadline; uint160 sqrtPriceX96; }",
2772
+ "function mint(MintParams calldata params) external payable returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1)"
2773
+ ]);
2774
+ thenaRouterAbi = parseAbi7([
2775
+ "struct ExactInputSingleParams { address tokenIn; address tokenOut; int24 tickSpacing; address recipient; uint256 deadline; uint256 amountIn; uint256 amountOutMinimum; uint160 sqrtPriceLimitX96; }",
2776
+ "function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut)"
2777
+ ]);
2778
+ thenaPoolAbi = parseAbi7([
2779
+ "function slot0() view returns (uint160 sqrtPriceX96, int24 tick, uint16 observationIndex, uint16 observationCardinality, uint16 observationCardinalityNext, bool unlocked)",
2780
+ "function tickSpacing() view returns (int24)",
2781
+ "function token0() view returns (address)",
2782
+ "function token1() view returns (address)"
2783
+ ]);
2784
+ thenaFactoryAbi = parseAbi7([
2785
+ "function getPool(address tokenA, address tokenB, int24 tickSpacing) view returns (address)"
2786
+ ]);
2787
+ ThenaCLAdapter = class {
2788
+ protocolName;
2789
+ router;
2790
+ positionManager;
2791
+ factory;
2792
+ rpcUrl;
2793
+ defaultTickSpacing;
2794
+ constructor(entry, rpcUrl) {
2795
+ this.protocolName = entry.name;
2796
+ const router = entry.contracts?.["router"];
2797
+ if (!router) throw new DefiError("CONTRACT_ERROR", "Missing 'router' contract address");
2798
+ this.router = router;
2799
+ this.positionManager = entry.contracts?.["position_manager"];
2800
+ this.factory = entry.contracts?.["pool_factory"];
2801
+ this.rpcUrl = rpcUrl;
2802
+ this.defaultTickSpacing = 50;
2803
+ }
2804
+ name() {
2805
+ return this.protocolName;
2806
+ }
2807
+ async buildSwap(params) {
2808
+ const data = encodeFunctionData7({
2809
+ abi: thenaRouterAbi,
2810
+ functionName: "exactInputSingle",
2811
+ args: [{
2812
+ tokenIn: params.token_in,
2813
+ tokenOut: params.token_out,
2814
+ tickSpacing: this.defaultTickSpacing,
2815
+ recipient: params.recipient,
2816
+ deadline: BigInt(params.deadline ?? 18446744073709551615n),
2817
+ amountIn: params.amount_in,
2818
+ amountOutMinimum: 0n,
2819
+ sqrtPriceLimitX96: 0n
2820
+ }]
2821
+ });
2822
+ return {
2823
+ description: `[${this.protocolName}] Swap`,
2824
+ to: this.router,
2825
+ data,
2826
+ value: 0n,
2827
+ gas_estimate: 3e5,
2828
+ approvals: [{ token: params.token_in, spender: this.router, amount: params.amount_in }]
2829
+ };
2830
+ }
2831
+ async quote(_params) {
2832
+ throw DefiError.unsupported(`[${this.protocolName}] quote not yet implemented \u2014 use swap router`);
2833
+ }
2834
+ async buildAddLiquidity(params) {
2835
+ const pm = this.positionManager;
2836
+ if (!pm) throw new DefiError("CONTRACT_ERROR", "Position manager not configured");
2837
+ if (!this.rpcUrl) throw DefiError.rpcError("RPC URL required");
2838
+ const [token0, token1, rawAmount0, rawAmount1] = params.token_a.toLowerCase() < params.token_b.toLowerCase() ? [params.token_a, params.token_b, params.amount_a, params.amount_b] : [params.token_b, params.token_a, params.amount_b, params.amount_a];
2839
+ const client = createPublicClient4({ transport: http4(this.rpcUrl) });
2840
+ const poolAddr = params.pool;
2841
+ let tickSpacing = this.defaultTickSpacing;
2842
+ let tickLower = params.tick_lower ?? 0;
2843
+ let tickUpper = params.tick_upper ?? 0;
2844
+ if (poolAddr || !params.tick_lower || !params.tick_upper) {
2845
+ let pool = poolAddr;
2846
+ if (!pool && this.factory) {
2847
+ pool = await client.readContract({
2848
+ address: this.factory,
2849
+ abi: thenaFactoryAbi,
2850
+ functionName: "getPool",
2851
+ args: [token0, token1, tickSpacing]
2852
+ });
2853
+ if (pool === zeroAddress3) throw new DefiError("CONTRACT_ERROR", "Pool not found");
2854
+ }
2855
+ if (pool) {
2856
+ const [slot0, ts] = await Promise.all([
2857
+ client.readContract({ address: pool, abi: thenaPoolAbi, functionName: "slot0" }),
2858
+ client.readContract({ address: pool, abi: thenaPoolAbi, functionName: "tickSpacing" })
2859
+ ]);
2860
+ const currentTick = Number(slot0[1]);
2861
+ tickSpacing = Number(ts);
2862
+ if (params.range_pct !== void 0) {
2863
+ const range = rangeToTicks(currentTick, params.range_pct, tickSpacing);
2864
+ tickLower = range.tickLower;
2865
+ tickUpper = range.tickUpper;
2866
+ } else if (!params.tick_lower && !params.tick_upper) {
2867
+ const isSingleSide = rawAmount0 === 0n || rawAmount1 === 0n;
2868
+ if (isSingleSide) {
2869
+ if (rawAmount0 > 0n) {
2870
+ tickLower = alignTickUp(currentTick + tickSpacing, tickSpacing);
2871
+ tickUpper = Math.floor(887272 / tickSpacing) * tickSpacing;
2872
+ } else {
2873
+ tickLower = Math.ceil(-887272 / tickSpacing) * tickSpacing;
2874
+ tickUpper = alignTickDown(currentTick - tickSpacing, tickSpacing);
2875
+ }
2876
+ } else {
2877
+ tickLower = Math.ceil(-887272 / tickSpacing) * tickSpacing;
2878
+ tickUpper = Math.floor(887272 / tickSpacing) * tickSpacing;
2879
+ }
2880
+ }
2881
+ }
2882
+ }
2883
+ if (params.tick_lower !== void 0) tickLower = params.tick_lower;
2884
+ if (params.tick_upper !== void 0) tickUpper = params.tick_upper;
2885
+ const data = encodeFunctionData7({
2886
+ abi: thenaPmAbi,
2887
+ functionName: "mint",
2888
+ args: [{
2889
+ token0,
2890
+ token1,
2891
+ tickSpacing,
2892
+ tickLower,
2893
+ tickUpper,
2894
+ amount0Desired: rawAmount0,
2895
+ amount1Desired: rawAmount1,
2896
+ amount0Min: 0n,
2897
+ amount1Min: 0n,
2898
+ recipient: params.recipient,
2899
+ deadline: BigInt("18446744073709551615"),
2900
+ sqrtPriceX96: 0n
2901
+ }]
2902
+ });
2903
+ const approvals = [];
2904
+ if (rawAmount0 > 0n) approvals.push({ token: token0, spender: pm, amount: rawAmount0 });
2905
+ if (rawAmount1 > 0n) approvals.push({ token: token1, spender: pm, amount: rawAmount1 });
2906
+ return {
2907
+ description: `[${this.protocolName}] Add liquidity [${tickLower}, ${tickUpper}]`,
2908
+ to: pm,
2909
+ data,
2910
+ value: 0n,
2911
+ gas_estimate: 7e5,
2912
+ approvals
2913
+ };
2914
+ }
2915
+ async buildRemoveLiquidity(_params) {
2916
+ throw DefiError.unsupported(`[${this.protocolName}] remove_liquidity requires tokenId`);
2917
+ }
2918
+ };
2919
+ _addressDecodeAbi = parseAbi8(["function f() external view returns (address)"]);
2920
+ _symbolDecodeAbi = parseAbi8(["function symbol() external view returns (string)"]);
2921
+ gaugeManagerAbi = parseAbi8([
2922
+ "function gauges(address pool) view returns (address gauge)",
2923
+ "function isGauge(address gauge) view returns (bool)",
2924
+ "function isAlive(address gauge) view returns (bool)",
2925
+ "function claimRewards(address gauge, uint256[] tokenIds, uint8 redeemType) external"
2926
+ ]);
2927
+ gaugeCLAbi = parseAbi8([
2928
+ "function deposit(uint256 tokenId) external",
2929
+ "function withdraw(uint256 tokenId, uint8 redeemType) external",
2930
+ "function earned(uint256 tokenId) view returns (uint256)",
2931
+ "function balanceOf(uint256 tokenId) view returns (uint256)",
2932
+ "function rewardToken() view returns (address)"
2933
+ ]);
2934
+ nfpmAbi = parseAbi8([
2935
+ "function approve(address to, uint256 tokenId) external",
2936
+ "function getApproved(uint256 tokenId) view returns (address)"
2937
+ ]);
2938
+ veAbi = parseAbi8([
2939
+ "function create_lock(uint256 value, uint256 lock_duration) external returns (uint256)",
2940
+ "function increase_amount(uint256 tokenId, uint256 value) external",
2941
+ "function increase_unlock_time(uint256 tokenId, uint256 lock_duration) external",
2942
+ "function withdraw(uint256 tokenId) external"
2943
+ ]);
2944
+ voterAbi = parseAbi8([
2945
+ "function vote(uint256 tokenId, address[] pools, uint256[] weights) external",
2946
+ "function claimBribes(address[] bribes, address[][] tokens, uint256 tokenId) external",
2947
+ "function claimFees(address[] fees, address[][] tokens, uint256 tokenId) external"
2948
+ ]);
2949
+ HybraGaugeAdapter = class {
2950
+ protocolName;
2951
+ gaugeManager;
2952
+ veToken;
2953
+ voter;
2954
+ positionManager;
2955
+ poolFactory;
2956
+ rpcUrl;
2957
+ constructor(entry, rpcUrl) {
2958
+ this.protocolName = entry.name;
2959
+ const gm = entry.contracts?.["gauge_manager"];
2960
+ if (!gm) throw new DefiError("CONTRACT_ERROR", "Missing 'gauge_manager' contract");
2961
+ this.gaugeManager = gm;
2962
+ const ve = entry.contracts?.["ve_token"];
2963
+ if (!ve) throw new DefiError("CONTRACT_ERROR", "Missing 've_token' contract");
2964
+ this.veToken = ve;
2965
+ this.voter = entry.contracts?.["voter"] ?? zeroAddress4;
2966
+ this.positionManager = entry.contracts?.["position_manager"] ?? zeroAddress4;
2967
+ this.poolFactory = entry.contracts?.["pool_factory"];
2968
+ this.rpcUrl = rpcUrl;
2969
+ }
2970
+ name() {
2971
+ return this.protocolName;
2972
+ }
2973
+ // ─── Gauge Discovery ──────────────────────────────────────
2974
+ async discoverGaugedPools() {
2975
+ if (!this.rpcUrl) throw DefiError.rpcError("RPC URL required for gauge discovery");
2976
+ if (!this.poolFactory) throw new DefiError("CONTRACT_ERROR", "Missing 'pool_factory' contract");
2977
+ const factoryAbi = parseAbi8([
2978
+ "function allPoolsLength() external view returns (uint256)",
2979
+ "function allPools(uint256) external view returns (address)"
2980
+ ]);
2981
+ const poolAbi2 = parseAbi8([
2982
+ "function token0() external view returns (address)",
2983
+ "function token1() external view returns (address)"
2984
+ ]);
2985
+ const erc20SymbolAbi = parseAbi8(["function symbol() external view returns (string)"]);
2986
+ const gaugesAbi = parseAbi8(["function gauges(address pool) view returns (address gauge)"]);
2987
+ const client = createPublicClient5({ transport: http5(this.rpcUrl) });
2988
+ let poolCount;
2989
+ try {
2990
+ poolCount = await client.readContract({
2991
+ address: this.poolFactory,
2992
+ abi: factoryAbi,
2993
+ functionName: "allPoolsLength"
2994
+ });
2995
+ } catch {
2996
+ return [];
2997
+ }
2998
+ const count = Number(poolCount);
2999
+ if (count === 0) return [];
3000
+ const poolAddressCalls = [];
3001
+ for (let i = 0; i < count; i++) {
3002
+ poolAddressCalls.push([
3003
+ this.poolFactory,
3004
+ encodeFunctionData8({ abi: factoryAbi, functionName: "allPools", args: [BigInt(i)] })
3005
+ ]);
3006
+ }
3007
+ const poolAddressResults = await multicallRead(this.rpcUrl, poolAddressCalls);
3008
+ const pools = poolAddressResults.map((r) => decodeAddress(r)).filter((a) => a !== null && a !== zeroAddress4);
3009
+ if (pools.length === 0) return [];
3010
+ const gaugeCalls = pools.map((pool) => [
3011
+ this.gaugeManager,
3012
+ encodeFunctionData8({ abi: gaugesAbi, functionName: "gauges", args: [pool] })
3013
+ ]);
3014
+ const gaugeResults = await multicallRead(this.rpcUrl, gaugeCalls);
3015
+ const gaugedPools = [];
3016
+ for (let i = 0; i < pools.length; i++) {
3017
+ const gauge = decodeAddress(gaugeResults[i] ?? null);
3018
+ if (gauge && gauge !== zeroAddress4) {
3019
+ gaugedPools.push({ pool: pools[i], gauge });
3020
+ }
3021
+ }
3022
+ if (gaugedPools.length === 0) return [];
3023
+ const tokenCalls = [];
3024
+ for (const { pool } of gaugedPools) {
3025
+ tokenCalls.push([pool, encodeFunctionData8({ abi: poolAbi2, functionName: "token0" })]);
3026
+ tokenCalls.push([pool, encodeFunctionData8({ abi: poolAbi2, functionName: "token1" })]);
3027
+ }
3028
+ const tokenResults = await multicallRead(this.rpcUrl, tokenCalls);
3029
+ const tokenAddrs = /* @__PURE__ */ new Set();
3030
+ for (let i = 0; i < gaugedPools.length; i++) {
3031
+ const t0 = decodeAddress(tokenResults[i * 2] ?? null);
3032
+ const t1 = decodeAddress(tokenResults[i * 2 + 1] ?? null);
3033
+ if (t0 && t0 !== zeroAddress4) tokenAddrs.add(t0);
3034
+ if (t1 && t1 !== zeroAddress4) tokenAddrs.add(t1);
3035
+ }
3036
+ const uniqueTokens = Array.from(tokenAddrs);
3037
+ const symbolCalls = uniqueTokens.map((t) => [
3038
+ t,
3039
+ encodeFunctionData8({ abi: erc20SymbolAbi, functionName: "symbol" })
3040
+ ]);
3041
+ const symbolResults = await multicallRead(this.rpcUrl, symbolCalls);
3042
+ const symbolMap = /* @__PURE__ */ new Map();
3043
+ for (let i = 0; i < uniqueTokens.length; i++) {
3044
+ symbolMap.set(uniqueTokens[i], decodeSymbol(symbolResults[i] ?? null));
3045
+ }
3046
+ const out = [];
3047
+ for (let i = 0; i < gaugedPools.length; i++) {
3048
+ const { pool, gauge } = gaugedPools[i];
3049
+ const t0 = decodeAddress(tokenResults[i * 2] ?? null);
3050
+ const t1 = decodeAddress(tokenResults[i * 2 + 1] ?? null);
3051
+ out.push({
3052
+ pool,
3053
+ gauge,
3054
+ token0: t0 ? symbolMap.get(t0) ?? t0.slice(0, 10) : "?",
3055
+ token1: t1 ? symbolMap.get(t1) ?? t1.slice(0, 10) : "?",
3056
+ type: "CL"
3057
+ });
3058
+ }
3059
+ return out;
3060
+ }
3061
+ // ─── Gauge Lookup ──────────────────────────────────────────
3062
+ async resolveGauge(pool) {
3063
+ if (!this.rpcUrl) throw DefiError.rpcError("RPC required");
3064
+ const client = createPublicClient5({ transport: http5(this.rpcUrl) });
3065
+ const gauge = await client.readContract({
3066
+ address: this.gaugeManager,
3067
+ abi: gaugeManagerAbi,
3068
+ functionName: "gauges",
3069
+ args: [pool]
3070
+ });
3071
+ if (gauge === zeroAddress4) throw new DefiError("CONTRACT_ERROR", `No gauge for pool ${pool}`);
3072
+ return gauge;
3073
+ }
3074
+ // ─── CL Gauge: NFT Deposit/Withdraw ──────────────────────────
3075
+ async buildDeposit(gauge, _amount, tokenId) {
3076
+ if (tokenId === void 0) throw new DefiError("CONTRACT_ERROR", "tokenId required for CL gauge deposit");
3077
+ const approveTx = {
3078
+ description: `[${this.protocolName}] Approve NFT #${tokenId} to gauge`,
3079
+ to: this.positionManager,
3080
+ data: encodeFunctionData8({ abi: nfpmAbi, functionName: "approve", args: [gauge, tokenId] }),
3081
+ value: 0n,
3082
+ gas_estimate: 8e4
3083
+ };
3084
+ return {
3085
+ description: `[${this.protocolName}] Deposit NFT #${tokenId} to gauge`,
3086
+ to: gauge,
3087
+ data: encodeFunctionData8({ abi: gaugeCLAbi, functionName: "deposit", args: [tokenId] }),
3088
+ value: 0n,
3089
+ gas_estimate: 5e5,
3090
+ pre_txs: [approveTx]
3091
+ };
3092
+ }
3093
+ async buildWithdraw(gauge, _amount, tokenId) {
3094
+ if (tokenId === void 0) throw new DefiError("CONTRACT_ERROR", "tokenId required for CL gauge withdraw");
3095
+ return {
3096
+ description: `[${this.protocolName}] Withdraw NFT #${tokenId} from gauge`,
3097
+ to: gauge,
3098
+ data: encodeFunctionData8({ abi: gaugeCLAbi, functionName: "withdraw", args: [tokenId, 1] }),
3099
+ value: 0n,
3100
+ gas_estimate: 1e6
3101
+ };
3102
+ }
3103
+ // ─── Claim: via GaugeManager ──────────────────────────────────
3104
+ async buildClaimRewards(gauge, _account) {
3105
+ throw DefiError.unsupported(`[${this.protocolName}] Use buildClaimRewardsByTokenId for CL gauges`);
3106
+ }
3107
+ async buildClaimRewardsByTokenId(gauge, tokenId) {
3108
+ return {
3109
+ description: `[${this.protocolName}] Claim rewards for NFT #${tokenId}`,
3110
+ to: this.gaugeManager,
3111
+ data: encodeFunctionData8({
3112
+ abi: gaugeManagerAbi,
3113
+ functionName: "claimRewards",
3114
+ args: [gauge, [tokenId], 1]
3115
+ // redeemType=1
3116
+ }),
3117
+ value: 0n,
3118
+ gas_estimate: 1e6
3119
+ };
3120
+ }
3121
+ // ─── Pending Rewards ──────────────────────────────────────────
3122
+ async getPendingRewards(gauge, _user) {
3123
+ throw DefiError.unsupported(`[${this.protocolName}] Use getPendingRewardsByTokenId for CL gauges`);
3124
+ }
3125
+ async getPendingRewardsByTokenId(gauge, tokenId) {
3126
+ if (!this.rpcUrl) throw DefiError.rpcError("RPC required");
3127
+ const client = createPublicClient5({ transport: http5(this.rpcUrl) });
3128
+ return await client.readContract({
3129
+ address: gauge,
3130
+ abi: gaugeCLAbi,
3131
+ functionName: "earned",
3132
+ args: [tokenId]
3133
+ });
3134
+ }
3135
+ // ─── VoteEscrow ──────────────────────────────────────────────
3136
+ async buildCreateLock(amount, lockDuration) {
3137
+ return {
3138
+ description: `[${this.protocolName}] Create veNFT lock`,
3139
+ to: this.veToken,
3140
+ data: encodeFunctionData8({ abi: veAbi, functionName: "create_lock", args: [amount, BigInt(lockDuration)] }),
3141
+ value: 0n,
3142
+ gas_estimate: 3e5
3143
+ };
3144
+ }
3145
+ async buildIncreaseAmount(tokenId, amount) {
3146
+ return {
3147
+ description: `[${this.protocolName}] Increase veNFT #${tokenId}`,
3148
+ to: this.veToken,
3149
+ data: encodeFunctionData8({ abi: veAbi, functionName: "increase_amount", args: [tokenId, amount] }),
3150
+ value: 0n,
3151
+ gas_estimate: 2e5
3152
+ };
3153
+ }
3154
+ async buildIncreaseUnlockTime(tokenId, lockDuration) {
3155
+ return {
3156
+ description: `[${this.protocolName}] Extend veNFT #${tokenId} lock`,
3157
+ to: this.veToken,
3158
+ data: encodeFunctionData8({ abi: veAbi, functionName: "increase_unlock_time", args: [tokenId, BigInt(lockDuration)] }),
3159
+ value: 0n,
3160
+ gas_estimate: 2e5
3161
+ };
3162
+ }
3163
+ async buildWithdrawExpired(tokenId) {
3164
+ return {
3165
+ description: `[${this.protocolName}] Withdraw expired veNFT #${tokenId}`,
3166
+ to: this.veToken,
3167
+ data: encodeFunctionData8({ abi: veAbi, functionName: "withdraw", args: [tokenId] }),
3168
+ value: 0n,
3169
+ gas_estimate: 2e5
3170
+ };
3171
+ }
3172
+ // ─── Voter ──────────────────────────────────────────────────
3173
+ async buildVote(tokenId, pools, weights) {
3174
+ return {
3175
+ description: `[${this.protocolName}] Vote with veNFT #${tokenId}`,
3176
+ to: this.voter,
3177
+ data: encodeFunctionData8({ abi: voterAbi, functionName: "vote", args: [tokenId, pools, weights] }),
3178
+ value: 0n,
3179
+ gas_estimate: 5e5
3180
+ };
3181
+ }
3182
+ async buildClaimBribes(bribes, tokenId) {
3183
+ const tokensPerBribe = bribes.map(() => []);
3184
+ return {
3185
+ description: `[${this.protocolName}] Claim bribes for veNFT #${tokenId}`,
3186
+ to: this.voter,
3187
+ data: encodeFunctionData8({ abi: voterAbi, functionName: "claimBribes", args: [bribes, tokensPerBribe, tokenId] }),
3188
+ value: 0n,
3189
+ gas_estimate: 3e5
3190
+ };
3191
+ }
3192
+ async buildClaimFees(fees, tokenId) {
3193
+ const tokensPerFee = fees.map(() => []);
3194
+ return {
3195
+ description: `[${this.protocolName}] Claim fees for veNFT #${tokenId}`,
3196
+ to: this.voter,
3197
+ data: encodeFunctionData8({ abi: voterAbi, functionName: "claimFees", args: [fees, tokensPerFee, tokenId] }),
3198
+ value: 0n,
3199
+ gas_estimate: 3e5
3200
+ };
3201
+ }
3202
+ };
3203
+ abi5 = parseAbi9([
2575
3204
  "function swap(address fromToken, address toToken, uint256 fromAmount, uint256 minToAmount, address to, address rebateTo) external payable returns (uint256 realToAmount)"
2576
3205
  ]);
2577
3206
  WooFiAdapter = class {
@@ -2590,7 +3219,7 @@ var init_dist3 = __esm({
2590
3219
  }
2591
3220
  async buildSwap(params) {
2592
3221
  const minToAmount = 0n;
2593
- const data = encodeFunctionData7({
3222
+ const data = encodeFunctionData9({
2594
3223
  abi: abi5,
2595
3224
  functionName: "swap",
2596
3225
  args: [
@@ -2599,7 +3228,7 @@ var init_dist3 = __esm({
2599
3228
  params.amount_in,
2600
3229
  minToAmount,
2601
3230
  params.recipient,
2602
- zeroAddress3
3231
+ zeroAddress5
2603
3232
  ]
2604
3233
  });
2605
3234
  return {
@@ -2620,20 +3249,25 @@ var init_dist3 = __esm({
2620
3249
  throw DefiError.unsupported(`[${this.protocolName}] WOOFi does not support LP positions via router`);
2621
3250
  }
2622
3251
  };
2623
- gaugeAbi = parseAbi8([
3252
+ gaugeAbi = parseAbi10([
2624
3253
  "function deposit(uint256 amount) external",
2625
3254
  "function depositFor(uint256 amount, uint256 tokenId) external",
2626
3255
  "function withdraw(uint256 amount) external",
3256
+ "function getReward() external",
2627
3257
  "function getReward(address account) external",
2628
3258
  "function getReward(address account, address[] tokens) external",
3259
+ "function getReward(uint256 tokenId) external",
2629
3260
  "function earned(address account) external view returns (uint256)",
2630
3261
  "function earned(address token, address account) external view returns (uint256)",
3262
+ "function earned(uint256 tokenId) external view returns (uint256)",
2631
3263
  "function rewardRate() external view returns (uint256)",
3264
+ "function rewardToken() external view returns (address)",
2632
3265
  "function totalSupply() external view returns (uint256)",
2633
3266
  "function rewardsListLength() external view returns (uint256)",
2634
- "function isReward(address token) external view returns (bool)"
3267
+ "function rewardData(address token) external view returns (uint256 periodFinish, uint256 rewardRate, uint256 lastUpdateTime, uint256 rewardPerTokenStored)",
3268
+ "function nonfungiblePositionManager() external view returns (address)"
2635
3269
  ]);
2636
- veAbi = parseAbi8([
3270
+ veAbi2 = parseAbi10([
2637
3271
  "function create_lock(uint256 value, uint256 lock_duration) external returns (uint256)",
2638
3272
  "function increase_amount(uint256 tokenId, uint256 value) external",
2639
3273
  "function increase_unlock_time(uint256 tokenId, uint256 lock_duration) external",
@@ -2641,17 +3275,39 @@ var init_dist3 = __esm({
2641
3275
  "function balanceOfNFT(uint256 tokenId) external view returns (uint256)",
2642
3276
  "function locked(uint256 tokenId) external view returns (uint256 amount, uint256 end)"
2643
3277
  ]);
2644
- voterAbi = parseAbi8([
3278
+ voterAbi2 = parseAbi10([
2645
3279
  "function vote(uint256 tokenId, address[] calldata pools, uint256[] calldata weights) external",
2646
3280
  "function claimBribes(address[] calldata bribes, address[][] calldata tokens, uint256 tokenId) external",
2647
3281
  "function claimFees(address[] calldata fees, address[][] calldata tokens, uint256 tokenId) external",
2648
- "function gauges(address pool) external view returns (address)"
3282
+ "function gauges(address pool) external view returns (address)",
3283
+ "function gaugeForPool(address pool) external view returns (address)",
3284
+ "function poolToGauge(address pool) external view returns (address)"
2649
3285
  ]);
3286
+ _addressDecodeAbi2 = parseAbi10(["function f() external view returns (address)"]);
3287
+ _symbolDecodeAbi2 = parseAbi10(["function symbol() external view returns (string)"]);
3288
+ _boolDecodeAbi = parseAbi10(["function f() external view returns (bool)"]);
3289
+ HYPEREVM_TOKENS = {
3290
+ WHYPE: "0x5555555555555555555555555555555555555555",
3291
+ USDC: "0xb88339CB7199b77E23DB6E890353E22632Ba630f",
3292
+ USDT0: "0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb",
3293
+ UETH: "0xBe6727B535545C67d5cAa73dEa54865B92CF7907",
3294
+ UBTC: "0x9FDBdA0A5e284c32744D2f17Ee5c74B284993463",
3295
+ USDH: "0x111111a1a0667d36bD57c0A9f569b98057111111",
3296
+ USDe: "0x5d3a1Ff2b6BAb83b63cd9AD0787074081a52ef34",
3297
+ sUSDe: "0x211Cc4DD073734dA055fbF44a2b4667d5E5fE5d2",
3298
+ XAUt0: "0xf4D9235269a96aaDaFc9aDAe454a0618eBE37949",
3299
+ kHYPE: "0xfD739d4e423301CE9385c1fb8850539D657C296D",
3300
+ RAM: "0x555570a286F15EbDFE42B66eDE2f724Aa1AB5555",
3301
+ hyperRAM: "0xAAAE8378809bb8815c08D3C59Eb0c7D1529aD769"
3302
+ };
3303
+ CL_TICK_SPACINGS = [1, 5, 10, 50, 100, 200];
2650
3304
  SolidlyGaugeAdapter = class {
2651
3305
  protocolName;
2652
3306
  voter;
2653
3307
  veToken;
2654
3308
  rpcUrl;
3309
+ clFactory;
3310
+ v2Factory;
2655
3311
  constructor(entry, rpcUrl) {
2656
3312
  this.protocolName = entry.name;
2657
3313
  const voter = entry.contracts?.["voter"];
@@ -2665,14 +3321,250 @@ var init_dist3 = __esm({
2665
3321
  this.voter = voter;
2666
3322
  this.veToken = veToken;
2667
3323
  this.rpcUrl = rpcUrl;
3324
+ this.clFactory = entry.contracts?.["cl_factory"] ?? entry.contracts?.["factory"];
3325
+ this.v2Factory = entry.contracts?.["pair_factory"] ?? entry.contracts?.["factory"];
2668
3326
  }
2669
3327
  name() {
2670
3328
  return this.protocolName;
2671
3329
  }
3330
+ /** Scan V2 and CL factories for pools that have active emission gauges. */
3331
+ async discoverGaugedPools() {
3332
+ if (!this.rpcUrl) throw DefiError.rpcError("RPC URL required for gauge discovery");
3333
+ const results = [];
3334
+ await Promise.all([
3335
+ this._discoverV2GaugedPools(results),
3336
+ this._discoverCLGaugedPools(results)
3337
+ ]);
3338
+ return results;
3339
+ }
3340
+ async _discoverV2GaugedPools(out) {
3341
+ if (!this.rpcUrl || !this.v2Factory) return;
3342
+ const v2FactoryAbi = parseAbi10([
3343
+ "function allPairsLength() external view returns (uint256)",
3344
+ "function allPairs(uint256) external view returns (address)"
3345
+ ]);
3346
+ const pairAbi = parseAbi10([
3347
+ "function token0() external view returns (address)",
3348
+ "function token1() external view returns (address)",
3349
+ "function stable() external view returns (bool)"
3350
+ ]);
3351
+ const erc20SymbolAbi = parseAbi10(["function symbol() external view returns (string)"]);
3352
+ const client = createPublicClient6({ transport: http6(this.rpcUrl) });
3353
+ let pairCount;
3354
+ try {
3355
+ pairCount = await client.readContract({
3356
+ address: this.v2Factory,
3357
+ abi: v2FactoryAbi,
3358
+ functionName: "allPairsLength"
3359
+ });
3360
+ } catch {
3361
+ return;
3362
+ }
3363
+ const count = Number(pairCount);
3364
+ if (count === 0) return;
3365
+ const pairAddressCalls = [];
3366
+ for (let i = 0; i < count; i++) {
3367
+ pairAddressCalls.push([
3368
+ this.v2Factory,
3369
+ encodeFunctionData10({ abi: v2FactoryAbi, functionName: "allPairs", args: [BigInt(i)] })
3370
+ ]);
3371
+ }
3372
+ const pairAddressResults = await multicallRead(this.rpcUrl, pairAddressCalls);
3373
+ const pairs = pairAddressResults.map((r) => decodeAddress2(r)).filter((a) => a !== null && a !== zeroAddress6);
3374
+ if (pairs.length === 0) return;
3375
+ const gaugeForPoolAbi = parseAbi10(["function gaugeForPool(address) external view returns (address)"]);
3376
+ const poolToGaugeAbi = parseAbi10(["function poolToGauge(address) external view returns (address)"]);
3377
+ const gaugeCalls = pairs.map((pair) => [
3378
+ this.voter,
3379
+ encodeFunctionData10({ abi: gaugeForPoolAbi, functionName: "gaugeForPool", args: [pair] })
3380
+ ]);
3381
+ let gaugeResults = await multicallRead(this.rpcUrl, gaugeCalls);
3382
+ const allNullV2 = gaugeResults.every((r) => !r || decodeAddress2(r) === zeroAddress6 || decodeAddress2(r) === null);
3383
+ if (allNullV2) {
3384
+ const fallbackCalls = pairs.map((pair) => [
3385
+ this.voter,
3386
+ encodeFunctionData10({ abi: poolToGaugeAbi, functionName: "poolToGauge", args: [pair] })
3387
+ ]);
3388
+ gaugeResults = await multicallRead(this.rpcUrl, fallbackCalls);
3389
+ }
3390
+ const gaugedPairs = [];
3391
+ for (let i = 0; i < pairs.length; i++) {
3392
+ const gauge = decodeAddress2(gaugeResults[i] ?? null);
3393
+ if (gauge && gauge !== zeroAddress6) {
3394
+ gaugedPairs.push({ pair: pairs[i], gauge });
3395
+ }
3396
+ }
3397
+ if (gaugedPairs.length === 0) return;
3398
+ const metaCalls = [];
3399
+ for (const { pair } of gaugedPairs) {
3400
+ metaCalls.push([pair, encodeFunctionData10({ abi: pairAbi, functionName: "token0" })]);
3401
+ metaCalls.push([pair, encodeFunctionData10({ abi: pairAbi, functionName: "token1" })]);
3402
+ metaCalls.push([pair, encodeFunctionData10({ abi: pairAbi, functionName: "stable" })]);
3403
+ }
3404
+ const metaResults = await multicallRead(this.rpcUrl, metaCalls);
3405
+ const tokenAddrs = /* @__PURE__ */ new Set();
3406
+ for (let i = 0; i < gaugedPairs.length; i++) {
3407
+ const t0 = decodeAddress2(metaResults[i * 3] ?? null);
3408
+ const t1 = decodeAddress2(metaResults[i * 3 + 1] ?? null);
3409
+ if (t0 && t0 !== zeroAddress6) tokenAddrs.add(t0);
3410
+ if (t1 && t1 !== zeroAddress6) tokenAddrs.add(t1);
3411
+ }
3412
+ const uniqueTokens = Array.from(tokenAddrs);
3413
+ const symbolCalls = uniqueTokens.map((t) => [
3414
+ t,
3415
+ encodeFunctionData10({ abi: erc20SymbolAbi, functionName: "symbol" })
3416
+ ]);
3417
+ const symbolResults = await multicallRead(this.rpcUrl, symbolCalls);
3418
+ const symbolMap = /* @__PURE__ */ new Map();
3419
+ for (let i = 0; i < uniqueTokens.length; i++) {
3420
+ symbolMap.set(uniqueTokens[i], decodeSymbol2(symbolResults[i] ?? null));
3421
+ }
3422
+ for (let i = 0; i < gaugedPairs.length; i++) {
3423
+ const { pair, gauge } = gaugedPairs[i];
3424
+ const t0 = decodeAddress2(metaResults[i * 3] ?? null);
3425
+ const t1 = decodeAddress2(metaResults[i * 3 + 1] ?? null);
3426
+ const stableRaw = metaResults[i * 3 + 2];
3427
+ const stable = stableRaw ? decodeBoolean(stableRaw) : false;
3428
+ out.push({
3429
+ pool: pair,
3430
+ gauge,
3431
+ token0: t0 ? symbolMap.get(t0) ?? t0.slice(0, 10) : "?",
3432
+ token1: t1 ? symbolMap.get(t1) ?? t1.slice(0, 10) : "?",
3433
+ type: "V2",
3434
+ stable
3435
+ });
3436
+ }
3437
+ }
3438
+ async _discoverCLGaugedPools(out) {
3439
+ if (!this.rpcUrl || !this.clFactory) return;
3440
+ const clFactoryAbi = parseAbi10([
3441
+ "function getPool(address tokenA, address tokenB, int24 tickSpacing) external view returns (address pool)"
3442
+ ]);
3443
+ const algebraFactoryAbi2 = parseAbi10([
3444
+ "function poolByPair(address tokenA, address tokenB) external view returns (address pool)"
3445
+ ]);
3446
+ const poolAbi2 = parseAbi10([
3447
+ "function token0() external view returns (address)",
3448
+ "function token1() external view returns (address)"
3449
+ ]);
3450
+ const erc20SymbolAbi = parseAbi10(["function symbol() external view returns (string)"]);
3451
+ const gaugeForPoolAbi = parseAbi10(["function gaugeForPool(address) external view returns (address)"]);
3452
+ const poolToGaugeAbi = parseAbi10(["function poolToGauge(address) external view returns (address)"]);
3453
+ const tokenEntries = Object.entries(HYPEREVM_TOKENS);
3454
+ const tokenAddresses = tokenEntries.map(([, addr]) => addr);
3455
+ const pairs = [];
3456
+ for (let i = 0; i < tokenAddresses.length; i++) {
3457
+ for (let j = i + 1; j < tokenAddresses.length; j++) {
3458
+ pairs.push([tokenAddresses[i], tokenAddresses[j]]);
3459
+ }
3460
+ }
3461
+ const isAlgebra = await (async () => {
3462
+ try {
3463
+ const [result] = await multicallRead(this.rpcUrl, [[
3464
+ this.clFactory,
3465
+ encodeFunctionData10({ abi: algebraFactoryAbi2, functionName: "poolByPair", args: [tokenAddresses[0], tokenAddresses[1]] })
3466
+ ]]);
3467
+ return result !== null && result.length >= 66;
3468
+ } catch {
3469
+ return false;
3470
+ }
3471
+ })();
3472
+ const getPoolCalls = [];
3473
+ const callMeta = [];
3474
+ if (isAlgebra) {
3475
+ for (let p = 0; p < pairs.length; p++) {
3476
+ const [tokenA, tokenB] = pairs[p];
3477
+ getPoolCalls.push([
3478
+ this.clFactory,
3479
+ encodeFunctionData10({ abi: algebraFactoryAbi2, functionName: "poolByPair", args: [tokenA, tokenB] })
3480
+ ]);
3481
+ callMeta.push({ pairIdx: p, tickSpacing: 0 });
3482
+ }
3483
+ } else {
3484
+ for (let p = 0; p < pairs.length; p++) {
3485
+ const [tokenA, tokenB] = pairs[p];
3486
+ for (const ts of CL_TICK_SPACINGS) {
3487
+ getPoolCalls.push([
3488
+ this.clFactory,
3489
+ encodeFunctionData10({ abi: clFactoryAbi, functionName: "getPool", args: [tokenA, tokenB, ts] })
3490
+ ]);
3491
+ callMeta.push({ pairIdx: p, tickSpacing: ts });
3492
+ }
3493
+ }
3494
+ }
3495
+ const getPoolResults = await multicallRead(this.rpcUrl, getPoolCalls);
3496
+ const candidatePools = [];
3497
+ for (let i = 0; i < getPoolCalls.length; i++) {
3498
+ const pool = decodeAddress2(getPoolResults[i] ?? null);
3499
+ if (pool && pool !== zeroAddress6) {
3500
+ const { pairIdx, tickSpacing } = callMeta[i];
3501
+ const [tokenA, tokenB] = pairs[pairIdx];
3502
+ candidatePools.push({ pool, tokenA, tokenB, tickSpacing });
3503
+ }
3504
+ }
3505
+ if (candidatePools.length === 0) return;
3506
+ const gaugeCalls = candidatePools.map(({ pool }) => [
3507
+ this.voter,
3508
+ encodeFunctionData10({ abi: gaugeForPoolAbi, functionName: "gaugeForPool", args: [pool] })
3509
+ ]);
3510
+ let gaugeResults = await multicallRead(this.rpcUrl, gaugeCalls);
3511
+ const allNull = gaugeResults.every((r) => !r || decodeAddress2(r) === zeroAddress6 || decodeAddress2(r) === null);
3512
+ if (allNull) {
3513
+ const fallbackCalls = candidatePools.map(({ pool }) => [
3514
+ this.voter,
3515
+ encodeFunctionData10({ abi: poolToGaugeAbi, functionName: "poolToGauge", args: [pool] })
3516
+ ]);
3517
+ gaugeResults = await multicallRead(this.rpcUrl, fallbackCalls);
3518
+ }
3519
+ const gaugedCL = [];
3520
+ for (let i = 0; i < candidatePools.length; i++) {
3521
+ const gauge = decodeAddress2(gaugeResults[i] ?? null);
3522
+ if (gauge && gauge !== zeroAddress6) {
3523
+ gaugedCL.push({ ...candidatePools[i], gauge });
3524
+ }
3525
+ }
3526
+ if (gaugedCL.length === 0) return;
3527
+ const tokenAddrsInPools = /* @__PURE__ */ new Set();
3528
+ for (const { tokenA, tokenB } of gaugedCL) {
3529
+ tokenAddrsInPools.add(tokenA);
3530
+ tokenAddrsInPools.add(tokenB);
3531
+ }
3532
+ const uniqueTokens = Array.from(tokenAddrsInPools);
3533
+ const symbolCalls = uniqueTokens.map((t) => [
3534
+ t,
3535
+ encodeFunctionData10({ abi: erc20SymbolAbi, functionName: "symbol" })
3536
+ ]);
3537
+ const symbolResults = await multicallRead(this.rpcUrl, symbolCalls);
3538
+ const symbolMap = /* @__PURE__ */ new Map();
3539
+ for (let i = 0; i < uniqueTokens.length; i++) {
3540
+ symbolMap.set(uniqueTokens[i], decodeSymbol2(symbolResults[i] ?? null));
3541
+ }
3542
+ const poolTokenCalls = [];
3543
+ for (const { pool } of gaugedCL) {
3544
+ poolTokenCalls.push([pool, encodeFunctionData10({ abi: poolAbi2, functionName: "token0" })]);
3545
+ poolTokenCalls.push([pool, encodeFunctionData10({ abi: poolAbi2, functionName: "token1" })]);
3546
+ }
3547
+ const poolTokenResults = await multicallRead(this.rpcUrl, poolTokenCalls);
3548
+ for (let i = 0; i < gaugedCL.length; i++) {
3549
+ const { pool, gauge, tokenA, tokenB, tickSpacing } = gaugedCL[i];
3550
+ const rawT0 = decodeAddress2(poolTokenResults[i * 2] ?? null);
3551
+ const rawT1 = decodeAddress2(poolTokenResults[i * 2 + 1] ?? null);
3552
+ const t0 = rawT0 && rawT0 !== zeroAddress6 ? rawT0 : tokenA;
3553
+ const t1 = rawT1 && rawT1 !== zeroAddress6 ? rawT1 : tokenB;
3554
+ out.push({
3555
+ pool,
3556
+ gauge,
3557
+ token0: symbolMap.get(t0) ?? t0.slice(0, 10),
3558
+ token1: symbolMap.get(t1) ?? t1.slice(0, 10),
3559
+ type: "CL",
3560
+ tickSpacing
3561
+ });
3562
+ }
3563
+ }
2672
3564
  // IGauge
2673
3565
  async buildDeposit(gauge, amount, tokenId, lpToken) {
2674
3566
  if (tokenId !== void 0) {
2675
- const data2 = encodeFunctionData8({
3567
+ const data2 = encodeFunctionData10({
2676
3568
  abi: gaugeAbi,
2677
3569
  functionName: "depositFor",
2678
3570
  args: [amount, tokenId]
@@ -2686,7 +3578,7 @@ var init_dist3 = __esm({
2686
3578
  approvals: lpToken ? [{ token: lpToken, spender: gauge, amount }] : void 0
2687
3579
  };
2688
3580
  }
2689
- const data = encodeFunctionData8({
3581
+ const data = encodeFunctionData10({
2690
3582
  abi: gaugeAbi,
2691
3583
  functionName: "deposit",
2692
3584
  args: [amount]
@@ -2701,7 +3593,7 @@ var init_dist3 = __esm({
2701
3593
  };
2702
3594
  }
2703
3595
  async buildWithdraw(gauge, amount) {
2704
- const data = encodeFunctionData8({
3596
+ const data = encodeFunctionData10({
2705
3597
  abi: gaugeAbi,
2706
3598
  functionName: "withdraw",
2707
3599
  args: [amount]
@@ -2714,36 +3606,108 @@ var init_dist3 = __esm({
2714
3606
  gas_estimate: 2e5
2715
3607
  };
2716
3608
  }
2717
- async buildClaimRewards(gauge, account) {
2718
- if (account && this.rpcUrl) {
3609
+ /**
3610
+ * Resolve gauge address from a pool address via voter contract.
3611
+ * Tries gaugeForPool (Ramses), poolToGauge (NEST), gauges (classic Solidly).
3612
+ */
3613
+ async resolveGauge(pool) {
3614
+ if (!this.rpcUrl) throw DefiError.rpcError("RPC URL required for gauge lookup");
3615
+ const client = createPublicClient6({ transport: http6(this.rpcUrl) });
3616
+ for (const fn of ["gaugeForPool", "poolToGauge", "gauges"]) {
2719
3617
  try {
2720
- const client = createPublicClient4({ transport: http4(this.rpcUrl) });
2721
- const listLen = await client.readContract({
2722
- address: gauge,
2723
- abi: gaugeAbi,
2724
- functionName: "rewardsListLength"
3618
+ const gauge = await client.readContract({
3619
+ address: this.voter,
3620
+ abi: voterAbi2,
3621
+ functionName: fn,
3622
+ args: [pool]
2725
3623
  });
2726
- if (listLen > 0n) {
2727
- const data2 = encodeFunctionData8({
2728
- abi: gaugeAbi,
2729
- functionName: "getReward",
2730
- args: [account, []]
2731
- });
2732
- return {
2733
- description: `[${this.protocolName}] Claim gauge rewards`,
2734
- to: gauge,
2735
- data: data2,
2736
- value: 0n,
2737
- gas_estimate: 3e5
2738
- };
2739
- }
3624
+ if (gauge !== zeroAddress6) return gauge;
2740
3625
  } catch {
2741
3626
  }
2742
3627
  }
2743
- const data = encodeFunctionData8({
3628
+ throw new DefiError("CONTRACT_ERROR", `[${this.protocolName}] No gauge found for pool ${pool}`);
3629
+ }
3630
+ /**
3631
+ * Discover reward tokens for a gauge.
3632
+ * Returns { tokens, multiToken } where multiToken indicates getReward(account, tokens[]) support.
3633
+ */
3634
+ async discoverRewardTokens(gauge) {
3635
+ if (!this.rpcUrl) return { tokens: [], multiToken: false };
3636
+ const client = createPublicClient6({ transport: http6(this.rpcUrl) });
3637
+ try {
3638
+ const len = await client.readContract({
3639
+ address: gauge,
3640
+ abi: gaugeAbi,
3641
+ functionName: "rewardsListLength"
3642
+ });
3643
+ if (Number(len) > 0) {
3644
+ const candidates = [
3645
+ "0x5555555555555555555555555555555555555555",
3646
+ // WHYPE
3647
+ "0x555570a286F15EbDFE42B66eDE2f724Aa1AB5555",
3648
+ // xRAM
3649
+ "0x067b0C72aa4C6Bd3BFEFfF443c536DCd6a25a9C8",
3650
+ // HYBR
3651
+ "0x07c57E32a3C29D5659bda1d3EFC2E7BF004E3035"
3652
+ // NEST token
3653
+ ];
3654
+ const found = [];
3655
+ for (const token of candidates) {
3656
+ try {
3657
+ const rd = await client.readContract({
3658
+ address: gauge,
3659
+ abi: gaugeAbi,
3660
+ functionName: "rewardData",
3661
+ args: [token]
3662
+ });
3663
+ if (rd[0] > 0n || rd[1] > 0n) found.push(token);
3664
+ } catch {
3665
+ }
3666
+ }
3667
+ if (found.length > 0) return { tokens: found, multiToken: true };
3668
+ return { tokens: [], multiToken: true };
3669
+ }
3670
+ } catch {
3671
+ }
3672
+ try {
3673
+ const rt = await client.readContract({
3674
+ address: gauge,
3675
+ abi: gaugeAbi,
3676
+ functionName: "rewardToken"
3677
+ });
3678
+ if (rt !== zeroAddress6) return { tokens: [rt], multiToken: false };
3679
+ } catch {
3680
+ }
3681
+ return { tokens: [], multiToken: false };
3682
+ }
3683
+ async buildClaimRewards(gauge, account) {
3684
+ if (!this.rpcUrl || !account) {
3685
+ const data2 = encodeFunctionData10({
3686
+ abi: gaugeAbi,
3687
+ functionName: "getReward",
3688
+ args: [account ?? zeroAddress6]
3689
+ });
3690
+ return { description: `[${this.protocolName}] Claim gauge rewards`, to: gauge, data: data2, value: 0n, gas_estimate: 2e5 };
3691
+ }
3692
+ const { tokens, multiToken } = await this.discoverRewardTokens(gauge);
3693
+ if (multiToken && tokens.length > 0) {
3694
+ const data2 = encodeFunctionData10({
3695
+ abi: gaugeAbi,
3696
+ functionName: "getReward",
3697
+ args: [account, tokens]
3698
+ });
3699
+ return {
3700
+ description: `[${this.protocolName}] Claim gauge rewards (${tokens.length} tokens)`,
3701
+ to: gauge,
3702
+ data: data2,
3703
+ value: 0n,
3704
+ gas_estimate: 3e5
3705
+ };
3706
+ }
3707
+ const data = encodeFunctionData10({
2744
3708
  abi: gaugeAbi,
2745
3709
  functionName: "getReward",
2746
- args: [account ?? zeroAddress4]
3710
+ args: []
2747
3711
  });
2748
3712
  return {
2749
3713
  description: `[${this.protocolName}] Claim gauge rewards`,
@@ -2753,13 +3717,83 @@ var init_dist3 = __esm({
2753
3717
  gas_estimate: 2e5
2754
3718
  };
2755
3719
  }
2756
- async getPendingRewards(_gauge, _user) {
2757
- throw DefiError.unsupported(`[${this.protocolName}] get_pending_rewards requires RPC`);
3720
+ /**
3721
+ * Claim rewards for a CL gauge by NFT tokenId (Hybra V4 style).
3722
+ */
3723
+ async buildClaimRewardsByTokenId(gauge, tokenId) {
3724
+ const data = encodeFunctionData10({
3725
+ abi: gaugeAbi,
3726
+ functionName: "getReward",
3727
+ args: [tokenId]
3728
+ });
3729
+ return {
3730
+ description: `[${this.protocolName}] Claim gauge rewards for NFT #${tokenId}`,
3731
+ to: gauge,
3732
+ data,
3733
+ value: 0n,
3734
+ gas_estimate: 3e5
3735
+ };
3736
+ }
3737
+ async getPendingRewards(gauge, user) {
3738
+ if (!this.rpcUrl) throw DefiError.rpcError("RPC URL required");
3739
+ const client = createPublicClient6({ transport: http6(this.rpcUrl) });
3740
+ const results = [];
3741
+ const { tokens, multiToken } = await this.discoverRewardTokens(gauge);
3742
+ if (multiToken && tokens.length > 0) {
3743
+ for (const token of tokens) {
3744
+ try {
3745
+ const earned = await client.readContract({
3746
+ address: gauge,
3747
+ abi: gaugeAbi,
3748
+ functionName: "earned",
3749
+ args: [token, user]
3750
+ });
3751
+ results.push({ token, symbol: token.slice(0, 10), amount: earned });
3752
+ } catch {
3753
+ }
3754
+ }
3755
+ } else if (tokens.length > 0) {
3756
+ try {
3757
+ const earned = await client.readContract({
3758
+ address: gauge,
3759
+ abi: gaugeAbi,
3760
+ functionName: "earned",
3761
+ args: [user]
3762
+ });
3763
+ results.push({ token: tokens[0], symbol: tokens[0].slice(0, 10), amount: earned });
3764
+ } catch {
3765
+ }
3766
+ } else {
3767
+ try {
3768
+ const earned = await client.readContract({
3769
+ address: gauge,
3770
+ abi: gaugeAbi,
3771
+ functionName: "earned",
3772
+ args: [user]
3773
+ });
3774
+ results.push({ token: zeroAddress6, symbol: "unknown", amount: earned });
3775
+ } catch {
3776
+ }
3777
+ }
3778
+ return results;
3779
+ }
3780
+ /**
3781
+ * Get pending rewards for a CL gauge NFT position (Hybra V4 style).
3782
+ */
3783
+ async getPendingRewardsByTokenId(gauge, tokenId) {
3784
+ if (!this.rpcUrl) throw DefiError.rpcError("RPC URL required");
3785
+ const client = createPublicClient6({ transport: http6(this.rpcUrl) });
3786
+ return await client.readContract({
3787
+ address: gauge,
3788
+ abi: gaugeAbi,
3789
+ functionName: "earned",
3790
+ args: [tokenId]
3791
+ });
2758
3792
  }
2759
3793
  // IVoteEscrow
2760
3794
  async buildCreateLock(amount, lockDuration) {
2761
- const data = encodeFunctionData8({
2762
- abi: veAbi,
3795
+ const data = encodeFunctionData10({
3796
+ abi: veAbi2,
2763
3797
  functionName: "create_lock",
2764
3798
  args: [amount, BigInt(lockDuration)]
2765
3799
  });
@@ -2772,8 +3806,8 @@ var init_dist3 = __esm({
2772
3806
  };
2773
3807
  }
2774
3808
  async buildIncreaseAmount(tokenId, amount) {
2775
- const data = encodeFunctionData8({
2776
- abi: veAbi,
3809
+ const data = encodeFunctionData10({
3810
+ abi: veAbi2,
2777
3811
  functionName: "increase_amount",
2778
3812
  args: [tokenId, amount]
2779
3813
  });
@@ -2786,8 +3820,8 @@ var init_dist3 = __esm({
2786
3820
  };
2787
3821
  }
2788
3822
  async buildIncreaseUnlockTime(tokenId, lockDuration) {
2789
- const data = encodeFunctionData8({
2790
- abi: veAbi,
3823
+ const data = encodeFunctionData10({
3824
+ abi: veAbi2,
2791
3825
  functionName: "increase_unlock_time",
2792
3826
  args: [tokenId, BigInt(lockDuration)]
2793
3827
  });
@@ -2800,8 +3834,8 @@ var init_dist3 = __esm({
2800
3834
  };
2801
3835
  }
2802
3836
  async buildWithdrawExpired(tokenId) {
2803
- const data = encodeFunctionData8({
2804
- abi: veAbi,
3837
+ const data = encodeFunctionData10({
3838
+ abi: veAbi2,
2805
3839
  functionName: "withdraw",
2806
3840
  args: [tokenId]
2807
3841
  });
@@ -2815,8 +3849,8 @@ var init_dist3 = __esm({
2815
3849
  }
2816
3850
  // IVoter
2817
3851
  async buildVote(tokenId, pools, weights) {
2818
- const data = encodeFunctionData8({
2819
- abi: voterAbi,
3852
+ const data = encodeFunctionData10({
3853
+ abi: voterAbi2,
2820
3854
  functionName: "vote",
2821
3855
  args: [tokenId, pools, weights]
2822
3856
  });
@@ -2830,8 +3864,8 @@ var init_dist3 = __esm({
2830
3864
  }
2831
3865
  async buildClaimBribes(bribes, tokenId) {
2832
3866
  const tokensPerBribe = bribes.map(() => []);
2833
- const data = encodeFunctionData8({
2834
- abi: voterAbi,
3867
+ const data = encodeFunctionData10({
3868
+ abi: voterAbi2,
2835
3869
  functionName: "claimBribes",
2836
3870
  args: [bribes, tokensPerBribe, tokenId]
2837
3871
  });
@@ -2845,8 +3879,8 @@ var init_dist3 = __esm({
2845
3879
  }
2846
3880
  async buildClaimFees(fees, tokenId) {
2847
3881
  const tokensPerFee = fees.map(() => []);
2848
- const data = encodeFunctionData8({
2849
- abi: voterAbi,
3882
+ const data = encodeFunctionData10({
3883
+ abi: voterAbi2,
2850
3884
  functionName: "claimFees",
2851
3885
  args: [fees, tokensPerFee, tokenId]
2852
3886
  });
@@ -2859,7 +3893,7 @@ var init_dist3 = __esm({
2859
3893
  };
2860
3894
  }
2861
3895
  };
2862
- masterchefAbi = parseAbi9([
3896
+ masterchefAbi = parseAbi11([
2863
3897
  "function deposit(uint256 pid, uint256 amount) external",
2864
3898
  "function withdraw(uint256 pid, uint256 amount) external",
2865
3899
  "function claim(uint256[] calldata pids) external",
@@ -2890,7 +3924,7 @@ var init_dist3 = __esm({
2890
3924
  */
2891
3925
  async buildDeposit(gauge, amount, tokenId) {
2892
3926
  const pid = tokenId ?? 0n;
2893
- const data = encodeFunctionData9({
3927
+ const data = encodeFunctionData11({
2894
3928
  abi: masterchefAbi,
2895
3929
  functionName: "deposit",
2896
3930
  args: [pid, amount]
@@ -2911,7 +3945,7 @@ var init_dist3 = __esm({
2911
3945
  */
2912
3946
  async buildWithdraw(gauge, amount) {
2913
3947
  const pid = 0n;
2914
- const data = encodeFunctionData9({
3948
+ const data = encodeFunctionData11({
2915
3949
  abi: masterchefAbi,
2916
3950
  functionName: "withdraw",
2917
3951
  args: [pid, amount]
@@ -2926,7 +3960,7 @@ var init_dist3 = __esm({
2926
3960
  }
2927
3961
  /** Withdraw LP tokens specifying a pid explicitly (MasterChef extension beyond IGauge). */
2928
3962
  async buildWithdrawPid(pid, amount) {
2929
- const data = encodeFunctionData9({
3963
+ const data = encodeFunctionData11({
2930
3964
  abi: masterchefAbi,
2931
3965
  functionName: "withdraw",
2932
3966
  args: [pid, amount]
@@ -2942,7 +3976,7 @@ var init_dist3 = __esm({
2942
3976
  /** Claim pending MOE rewards. IGauge interface provides no pid — defaults to pid=0. */
2943
3977
  async buildClaimRewards(gauge) {
2944
3978
  const pid = 0n;
2945
- const data = encodeFunctionData9({
3979
+ const data = encodeFunctionData11({
2946
3980
  abi: masterchefAbi,
2947
3981
  functionName: "claim",
2948
3982
  args: [[pid]]
@@ -2957,7 +3991,7 @@ var init_dist3 = __esm({
2957
3991
  }
2958
3992
  /** Claim pending MOE rewards for a specific pid (MasterChef extension beyond IGauge). */
2959
3993
  async buildClaimRewardsPid(pid) {
2960
- const data = encodeFunctionData9({
3994
+ const data = encodeFunctionData11({
2961
3995
  abi: masterchefAbi,
2962
3996
  functionName: "claim",
2963
3997
  args: [[pid]]
@@ -2975,7 +4009,7 @@ var init_dist3 = __esm({
2975
4009
  if (!this.rpcUrl) {
2976
4010
  throw DefiError.unsupported(`[${this.protocolName}] getPendingRewards requires RPC`);
2977
4011
  }
2978
- const client = createPublicClient5({ transport: http5(this.rpcUrl) });
4012
+ const client = createPublicClient7({ transport: http7(this.rpcUrl) });
2979
4013
  const rewards = await client.readContract({
2980
4014
  address: this.masterchef,
2981
4015
  abi: masterchefAbi,
@@ -2989,16 +4023,16 @@ var init_dist3 = __esm({
2989
4023
  }));
2990
4024
  }
2991
4025
  };
2992
- lbRouterAbi = parseAbi10([
4026
+ lbRouterAbi = parseAbi12([
2993
4027
  "struct LiquidityParameters { address tokenX; address tokenY; uint256 binStep; uint256 amountX; uint256 amountY; uint256 amountXMin; uint256 amountYMin; uint256 activeIdDesired; uint256 idSlippage; int256[] deltaIds; uint256[] distributionX; uint256[] distributionY; address to; address refundTo; uint256 deadline; }",
2994
4028
  "function addLiquidity(LiquidityParameters calldata liquidityParameters) external returns (uint256 amountXAdded, uint256 amountYAdded, uint256 amountXLeft, uint256 amountYLeft, uint256[] memory depositIds, uint256[] memory liquidityMinted)",
2995
4029
  "function removeLiquidity(address tokenX, address tokenY, uint16 binStep, uint256 amountXMin, uint256 amountYMin, uint256[] memory ids, uint256[] memory amounts, address to, uint256 deadline) external returns (uint256 amountX, uint256 amountY)"
2996
4030
  ]);
2997
- lbFactoryAbi = parseAbi10([
4031
+ lbFactoryAbi = parseAbi12([
2998
4032
  "function getNumberOfLBPairs() external view returns (uint256)",
2999
4033
  "function getLBPairAtIndex(uint256 index) external view returns (address)"
3000
4034
  ]);
3001
- lbPairAbi = parseAbi10([
4035
+ lbPairAbi = parseAbi12([
3002
4036
  "function getLBHooksParameters() external view returns (bytes32)",
3003
4037
  "function getActiveId() external view returns (uint24)",
3004
4038
  "function getBinStep() external view returns (uint16)",
@@ -3007,7 +4041,7 @@ var init_dist3 = __esm({
3007
4041
  "function balanceOf(address account, uint256 id) external view returns (uint256)",
3008
4042
  "function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids) external view returns (uint256[] memory)"
3009
4043
  ]);
3010
- lbRewarderAbi = parseAbi10([
4044
+ lbRewarderAbi = parseAbi12([
3011
4045
  "function getRewardToken() external view returns (address)",
3012
4046
  "function getRewardedRange() external view returns (uint256 minBinId, uint256 maxBinId)",
3013
4047
  "function getPendingRewards(address user, uint256[] calldata ids) external view returns (uint256 pendingRewards)",
@@ -3017,33 +4051,33 @@ var init_dist3 = __esm({
3017
4051
  "function getLBPair() external view returns (address)",
3018
4052
  "function getMasterChef() external view returns (address)"
3019
4053
  ]);
3020
- masterChefAbi = parseAbi10([
4054
+ masterChefAbi = parseAbi12([
3021
4055
  "function getMoePerSecond() external view returns (uint256)",
3022
4056
  "function getTreasuryShare() external view returns (uint256)",
3023
4057
  "function getStaticShare() external view returns (uint256)",
3024
4058
  "function getVeMoe() external view returns (address)"
3025
4059
  ]);
3026
- veMoeAbi = parseAbi10([
4060
+ veMoeAbi = parseAbi12([
3027
4061
  "function getWeight(uint256 pid) external view returns (uint256)",
3028
4062
  "function getTotalWeight() external view returns (uint256)",
3029
4063
  "function getTopPoolIds() external view returns (uint256[] memory)"
3030
4064
  ]);
3031
- lbPairBinAbi = parseAbi10([
4065
+ lbPairBinAbi = parseAbi12([
3032
4066
  "function getBin(uint24 id) external view returns (uint128 reserveX, uint128 reserveY)",
3033
4067
  "function getActiveId() external view returns (uint24)"
3034
4068
  ]);
3035
- lbQuoterAbi2 = parseAbi10([
4069
+ lbQuoterAbi2 = parseAbi12([
3036
4070
  "function findBestPathFromAmountIn(address[] calldata route, uint128 amountIn) external view returns ((address[] route, address[] pairs, uint256[] binSteps, uint256[] versions, uint128[] amounts, uint128[] virtualAmountsWithoutSlippage, uint128[] fees))"
3037
4071
  ]);
3038
- erc20Abi2 = parseAbi10([
4072
+ erc20Abi2 = parseAbi12([
3039
4073
  "function symbol() external view returns (string)"
3040
4074
  ]);
3041
- _addressAbi = parseAbi10(["function f() external view returns (address)"]);
3042
- _uint256Abi = parseAbi10(["function f() external view returns (uint256)"]);
3043
- _boolAbi = parseAbi10(["function f() external view returns (bool)"]);
3044
- _rangeAbi = parseAbi10(["function f() external view returns (uint256 minBinId, uint256 maxBinId)"]);
3045
- _binAbi = parseAbi10(["function f() external view returns (uint128 reserveX, uint128 reserveY)"]);
3046
- _uint256ArrayAbi = parseAbi10(["function f() external view returns (uint256[] memory)"]);
4075
+ _addressAbi = parseAbi12(["function f() external view returns (address)"]);
4076
+ _uint256Abi = parseAbi12(["function f() external view returns (uint256)"]);
4077
+ _boolAbi = parseAbi12(["function f() external view returns (bool)"]);
4078
+ _rangeAbi = parseAbi12(["function f() external view returns (uint256 minBinId, uint256 maxBinId)"]);
4079
+ _binAbi = parseAbi12(["function f() external view returns (uint128 reserveX, uint128 reserveY)"]);
4080
+ _uint256ArrayAbi = parseAbi12(["function f() external view returns (uint256[] memory)"]);
3047
4081
  MerchantMoeLBAdapter = class {
3048
4082
  protocolName;
3049
4083
  lbRouter;
@@ -3090,7 +4124,7 @@ var init_dist3 = __esm({
3090
4124
  let activeIdDesired = params.activeIdDesired;
3091
4125
  if (activeIdDesired === void 0) {
3092
4126
  const rpcUrl = this.requireRpc();
3093
- const client = createPublicClient6({ transport: http6(rpcUrl) });
4127
+ const client = createPublicClient8({ transport: http8(rpcUrl) });
3094
4128
  const activeId = await client.readContract({
3095
4129
  address: params.pool,
3096
4130
  abi: lbPairAbi,
@@ -3103,7 +4137,7 @@ var init_dist3 = __esm({
3103
4137
  deltaIds.push(d);
3104
4138
  }
3105
4139
  const { distributionX, distributionY } = buildUniformDistribution(deltaIds);
3106
- const data = encodeFunctionData10({
4140
+ const data = encodeFunctionData12({
3107
4141
  abi: lbRouterAbi,
3108
4142
  functionName: "addLiquidity",
3109
4143
  args: [
@@ -3143,7 +4177,7 @@ var init_dist3 = __esm({
3143
4177
  */
3144
4178
  async buildRemoveLiquidity(params) {
3145
4179
  const deadline = params.deadline ?? BigInt("18446744073709551615");
3146
- const data = encodeFunctionData10({
4180
+ const data = encodeFunctionData12({
3147
4181
  abi: lbRouterAbi,
3148
4182
  functionName: "removeLiquidity",
3149
4183
  args: [
@@ -3172,7 +4206,7 @@ var init_dist3 = __esm({
3172
4206
  */
3173
4207
  async autoDetectBins(pool) {
3174
4208
  const rpcUrl = this.requireRpc();
3175
- const client = createPublicClient6({ transport: http6(rpcUrl) });
4209
+ const client = createPublicClient8({ transport: http8(rpcUrl) });
3176
4210
  const hooksParams = await client.readContract({
3177
4211
  address: pool,
3178
4212
  abi: lbPairAbi,
@@ -3207,7 +4241,7 @@ var init_dist3 = __esm({
3207
4241
  */
3208
4242
  async getPendingRewards(user, pool, binIds) {
3209
4243
  const rpcUrl = this.requireRpc();
3210
- const client = createPublicClient6({ transport: http6(rpcUrl) });
4244
+ const client = createPublicClient8({ transport: http8(rpcUrl) });
3211
4245
  const hooksParams = await client.readContract({
3212
4246
  address: pool,
3213
4247
  abi: lbPairAbi,
@@ -3256,7 +4290,7 @@ var init_dist3 = __esm({
3256
4290
  */
3257
4291
  async buildClaimRewards(user, pool, binIds) {
3258
4292
  const rpcUrl = this.requireRpc();
3259
- const client = createPublicClient6({ transport: http6(rpcUrl) });
4293
+ const client = createPublicClient8({ transport: http8(rpcUrl) });
3260
4294
  const hooksParams = await client.readContract({
3261
4295
  address: pool,
3262
4296
  abi: lbPairAbi,
@@ -3278,7 +4312,7 @@ var init_dist3 = __esm({
3278
4312
  resolvedBinIds = [];
3279
4313
  for (let b = min; b <= max; b++) resolvedBinIds.push(b);
3280
4314
  }
3281
- const data = encodeFunctionData10({
4315
+ const data = encodeFunctionData12({
3282
4316
  abi: lbRewarderAbi,
3283
4317
  functionName: "claim",
3284
4318
  args: [user, resolvedBinIds.map(BigInt)]
@@ -3306,7 +4340,7 @@ var init_dist3 = __esm({
3306
4340
  */
3307
4341
  async discoverRewardedPools() {
3308
4342
  const rpcUrl = this.requireRpc();
3309
- const client = createPublicClient6({ transport: http6(rpcUrl) });
4343
+ const client = createPublicClient8({ transport: http8(rpcUrl) });
3310
4344
  const pairCount = await client.readContract({
3311
4345
  address: this.lbFactory,
3312
4346
  abi: lbFactoryAbi,
@@ -3316,14 +4350,14 @@ var init_dist3 = __esm({
3316
4350
  if (count === 0) return [];
3317
4351
  const batch1Calls = Array.from({ length: count }, (_, i) => [
3318
4352
  this.lbFactory,
3319
- encodeFunctionData10({ abi: lbFactoryAbi, functionName: "getLBPairAtIndex", args: [BigInt(i)] })
4353
+ encodeFunctionData12({ abi: lbFactoryAbi, functionName: "getLBPairAtIndex", args: [BigInt(i)] })
3320
4354
  ]);
3321
4355
  const batch1Results = await multicallRead(rpcUrl, batch1Calls);
3322
4356
  const pairAddresses = batch1Results.map((r) => decodeAddressResult(r)).filter((a) => a !== null);
3323
4357
  if (pairAddresses.length === 0) return [];
3324
4358
  const batch2Calls = pairAddresses.map((pair) => [
3325
4359
  pair,
3326
- encodeFunctionData10({ abi: lbPairAbi, functionName: "getLBHooksParameters" })
4360
+ encodeFunctionData12({ abi: lbPairAbi, functionName: "getLBHooksParameters" })
3327
4361
  ]);
3328
4362
  const batch2Results = await multicallRead(rpcUrl, batch2Calls);
3329
4363
  const rewardedPairs = [];
@@ -3332,8 +4366,8 @@ var init_dist3 = __esm({
3332
4366
  if (!raw) continue;
3333
4367
  let hooksBytes;
3334
4368
  try {
3335
- const _bytes32Abi = parseAbi10(["function f() external view returns (bytes32)"]);
3336
- hooksBytes = decodeFunctionResult22({ abi: _bytes32Abi, functionName: "f", data: raw });
4369
+ const _bytes32Abi = parseAbi12(["function f() external view returns (bytes32)"]);
4370
+ hooksBytes = decodeFunctionResult4({ abi: _bytes32Abi, functionName: "f", data: raw });
3337
4371
  } catch {
3338
4372
  continue;
3339
4373
  }
@@ -3345,17 +4379,17 @@ var init_dist3 = __esm({
3345
4379
  if (rewardedPairs.length === 0) return [];
3346
4380
  const batch3Calls = [];
3347
4381
  for (const { rewarder } of rewardedPairs) {
3348
- batch3Calls.push([rewarder, encodeFunctionData10({ abi: lbRewarderAbi, functionName: "isStopped" })]);
3349
- batch3Calls.push([rewarder, encodeFunctionData10({ abi: lbRewarderAbi, functionName: "getRewardedRange" })]);
3350
- batch3Calls.push([rewarder, encodeFunctionData10({ abi: lbRewarderAbi, functionName: "getRewardToken" })]);
3351
- batch3Calls.push([rewarder, encodeFunctionData10({ abi: lbRewarderAbi, functionName: "getPid" })]);
3352
- batch3Calls.push([rewarder, encodeFunctionData10({ abi: lbRewarderAbi, functionName: "getMasterChef" })]);
4382
+ batch3Calls.push([rewarder, encodeFunctionData12({ abi: lbRewarderAbi, functionName: "isStopped" })]);
4383
+ batch3Calls.push([rewarder, encodeFunctionData12({ abi: lbRewarderAbi, functionName: "getRewardedRange" })]);
4384
+ batch3Calls.push([rewarder, encodeFunctionData12({ abi: lbRewarderAbi, functionName: "getRewardToken" })]);
4385
+ batch3Calls.push([rewarder, encodeFunctionData12({ abi: lbRewarderAbi, functionName: "getPid" })]);
4386
+ batch3Calls.push([rewarder, encodeFunctionData12({ abi: lbRewarderAbi, functionName: "getMasterChef" })]);
3353
4387
  }
3354
4388
  const batch3Results = await multicallRead(rpcUrl, batch3Calls);
3355
4389
  const batch4aCalls = [];
3356
4390
  for (const { pool } of rewardedPairs) {
3357
- batch4aCalls.push([pool, encodeFunctionData10({ abi: lbPairAbi, functionName: "getTokenX" })]);
3358
- batch4aCalls.push([pool, encodeFunctionData10({ abi: lbPairAbi, functionName: "getTokenY" })]);
4391
+ batch4aCalls.push([pool, encodeFunctionData12({ abi: lbPairAbi, functionName: "getTokenX" })]);
4392
+ batch4aCalls.push([pool, encodeFunctionData12({ abi: lbPairAbi, functionName: "getTokenY" })]);
3359
4393
  }
3360
4394
  const batch4aResults = await multicallRead(rpcUrl, batch4aCalls);
3361
4395
  const tokenXAddresses = [];
@@ -3369,7 +4403,7 @@ var init_dist3 = __esm({
3369
4403
  );
3370
4404
  const batch4bCalls = uniqueTokens.map((token) => [
3371
4405
  token,
3372
- encodeFunctionData10({ abi: erc20Abi2, functionName: "symbol" })
4406
+ encodeFunctionData12({ abi: erc20Abi2, functionName: "symbol" })
3373
4407
  ]);
3374
4408
  const batch4bResults = await multicallRead(rpcUrl, batch4bCalls);
3375
4409
  const symbolMap = /* @__PURE__ */ new Map();
@@ -3400,11 +4434,11 @@ var init_dist3 = __esm({
3400
4434
  functionName: "getVeMoe"
3401
4435
  });
3402
4436
  const batch5Calls = [
3403
- [masterChefAddr, encodeFunctionData10({ abi: masterChefAbi, functionName: "getMoePerSecond" })],
3404
- [masterChefAddr, encodeFunctionData10({ abi: masterChefAbi, functionName: "getTreasuryShare" })],
3405
- [masterChefAddr, encodeFunctionData10({ abi: masterChefAbi, functionName: "getStaticShare" })],
3406
- [veMoeAddr, encodeFunctionData10({ abi: veMoeAbi, functionName: "getTotalWeight" })],
3407
- [veMoeAddr, encodeFunctionData10({ abi: veMoeAbi, functionName: "getTopPoolIds" })]
4437
+ [masterChefAddr, encodeFunctionData12({ abi: masterChefAbi, functionName: "getMoePerSecond" })],
4438
+ [masterChefAddr, encodeFunctionData12({ abi: masterChefAbi, functionName: "getTreasuryShare" })],
4439
+ [masterChefAddr, encodeFunctionData12({ abi: masterChefAbi, functionName: "getStaticShare" })],
4440
+ [veMoeAddr, encodeFunctionData12({ abi: veMoeAbi, functionName: "getTotalWeight" })],
4441
+ [veMoeAddr, encodeFunctionData12({ abi: veMoeAbi, functionName: "getTopPoolIds" })]
3408
4442
  ];
3409
4443
  const batch5Results = await multicallRead(rpcUrl, batch5Calls);
3410
4444
  const moePerSecRaw = decodeUint256Result(batch5Results[0] ?? null) ?? 0n;
@@ -3421,7 +4455,7 @@ var init_dist3 = __esm({
3421
4455
  if (veMoeAddr && rewardedPairs.length > 0) {
3422
4456
  const batch6Calls = poolData.map((d) => [
3423
4457
  veMoeAddr,
3424
- encodeFunctionData10({ abi: veMoeAbi, functionName: "getWeight", args: [BigInt(d.pid)] })
4458
+ encodeFunctionData12({ abi: veMoeAbi, functionName: "getWeight", args: [BigInt(d.pid)] })
3425
4459
  ]);
3426
4460
  const batch6Results = await multicallRead(rpcUrl, batch6Calls);
3427
4461
  for (let i = 0; i < poolData.length; i++) {
@@ -3468,7 +4502,7 @@ var init_dist3 = __esm({
3468
4502
  if (binRequests.length > 0) {
3469
4503
  const batch7Calls = binRequests.map(({ poolIdx, binId }) => [
3470
4504
  rewardedPairs[poolIdx].pool,
3471
- encodeFunctionData10({ abi: lbPairBinAbi, functionName: "getBin", args: [binId] })
4505
+ encodeFunctionData12({ abi: lbPairBinAbi, functionName: "getBin", args: [binId] })
3472
4506
  ]);
3473
4507
  const batch7Results = await multicallRead(rpcUrl, batch7Calls);
3474
4508
  for (let j = 0; j < binRequests.length; j++) {
@@ -3560,7 +4594,7 @@ var init_dist3 = __esm({
3560
4594
  */
3561
4595
  async getUserPositions(user, pool, binIds) {
3562
4596
  const rpcUrl = this.requireRpc();
3563
- const client = createPublicClient6({ transport: http6(rpcUrl) });
4597
+ const client = createPublicClient8({ transport: http8(rpcUrl) });
3564
4598
  const resolvedBinIds = binIds && binIds.length > 0 ? binIds : await this.autoDetectBins(pool);
3565
4599
  const accounts = resolvedBinIds.map(() => user);
3566
4600
  const ids = resolvedBinIds.map(BigInt);
@@ -3573,7 +4607,384 @@ var init_dist3 = __esm({
3573
4607
  return resolvedBinIds.map((binId, i) => ({ binId, balance: balances[i] ?? 0n })).filter((p) => p.balance > 0n);
3574
4608
  }
3575
4609
  };
3576
- POOL_ABI = parseAbi11([
4610
+ KITTEN_TOKEN = "0x618275f8efe54c2afa87bfb9f210a52f0ff89364";
4611
+ WHYPE_TOKEN = "0x5555555555555555555555555555555555555555";
4612
+ MAX_NONCE_SCAN = 60;
4613
+ HYPEREVM_TOKENS2 = [
4614
+ "0x5555555555555555555555555555555555555555",
4615
+ // WHYPE
4616
+ "0xb88339CB7199b77E23DB6E890353E22632Ba630f",
4617
+ // USDC
4618
+ "0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb",
4619
+ // USDT0
4620
+ "0xBe6727B535545C67d5cAa73dEa54865B92CF7907",
4621
+ // UETH
4622
+ "0x9FDBdA0A5e284c32744D2f17Ee5c74B284993463",
4623
+ // UBTC
4624
+ "0x111111a1a0667d36bD57c0A9f569b98057111111",
4625
+ // USDH
4626
+ "0x5d3a1Ff2b6BAb83b63cd9AD0787074081a52ef34",
4627
+ // USDe
4628
+ "0x211Cc4DD073734dA055fbF44a2b4667d5E5fE5d2",
4629
+ // sUSDe
4630
+ "0xf4D9235269a96aaDaFc9aDAe454a0618eBE37949",
4631
+ // XAUt0
4632
+ "0xfD739d4e423301CE9385c1fb8850539D657C296D",
4633
+ // kHYPE
4634
+ KITTEN_TOKEN
4635
+ // KITTEN
4636
+ ];
4637
+ farmingCenterAbi = parseAbi13([
4638
+ "function multicall(bytes[] calldata data) external payable returns (bytes[] memory results)",
4639
+ "function enterFarming((address rewardToken, address bonusRewardToken, address pool, uint256 nonce) key, uint256 tokenId) external",
4640
+ "function exitFarming((address rewardToken, address bonusRewardToken, address pool, uint256 nonce) key, uint256 tokenId) external",
4641
+ "function collectRewards((address rewardToken, address bonusRewardToken, address pool, uint256 nonce) key, uint256 tokenId) external",
4642
+ "function claimReward(address rewardToken, address to, uint128 amountRequested) external returns (uint256 reward)"
4643
+ ]);
4644
+ positionManagerAbi2 = parseAbi13([
4645
+ "function approveForFarming(uint256 tokenId, bool approve, address farmingAddress) external",
4646
+ "function farmingApprovals(uint256 tokenId) external view returns (address)"
4647
+ ]);
4648
+ eternalFarmingAbi = parseAbi13([
4649
+ "function incentives(bytes32 incentiveId) external view returns (uint256 totalReward, uint256 bonusReward, address virtualPoolAddress, uint24 minimalPositionWidth, bool deactivated, address pluginAddress)",
4650
+ "function getRewardInfo((address rewardToken, address bonusRewardToken, address pool, uint256 nonce) key, uint256 tokenId) external view returns (uint256 reward, uint256 bonusReward)"
4651
+ ]);
4652
+ algebraFactoryAbi = parseAbi13([
4653
+ "function poolByPair(address tokenA, address tokenB) external view returns (address pool)"
4654
+ ]);
4655
+ _addressDecodeAbi3 = parseAbi13(["function f() external view returns (address)"]);
4656
+ nonceCache = /* @__PURE__ */ new Map();
4657
+ KittenSwapFarmingAdapter = class {
4658
+ protocolName;
4659
+ farmingCenter;
4660
+ eternalFarming;
4661
+ positionManager;
4662
+ rpcUrl;
4663
+ factory;
4664
+ constructor(protocolName, farmingCenter, eternalFarming, positionManager, rpcUrl, factory) {
4665
+ this.protocolName = protocolName;
4666
+ this.farmingCenter = farmingCenter;
4667
+ this.eternalFarming = eternalFarming;
4668
+ this.positionManager = positionManager;
4669
+ this.rpcUrl = rpcUrl;
4670
+ this.factory = factory;
4671
+ }
4672
+ name() {
4673
+ return this.protocolName;
4674
+ }
4675
+ /**
4676
+ * Discover the active IncentiveKey for a given pool.
4677
+ * 1. Check runtime cache
4678
+ * 2. Batch-query nonces 0-60 via single multicall (61 calls)
4679
+ * 3. Return first non-zero incentive (totalReward > 0 and not deactivated)
4680
+ */
4681
+ async discoverIncentiveKey(pool) {
4682
+ const poolLc = pool.toLowerCase();
4683
+ if (nonceCache.has(poolLc)) {
4684
+ return {
4685
+ rewardToken: KITTEN_TOKEN,
4686
+ bonusRewardToken: WHYPE_TOKEN,
4687
+ pool,
4688
+ nonce: nonceCache.get(poolLc)
4689
+ };
4690
+ }
4691
+ const calls = [];
4692
+ const nonces = [];
4693
+ for (let n = 0; n <= MAX_NONCE_SCAN; n++) {
4694
+ const nonce = BigInt(n);
4695
+ nonces.push(nonce);
4696
+ const key = {
4697
+ rewardToken: KITTEN_TOKEN,
4698
+ bonusRewardToken: WHYPE_TOKEN,
4699
+ pool,
4700
+ nonce
4701
+ };
4702
+ calls.push([
4703
+ this.eternalFarming,
4704
+ encodeFunctionData13({
4705
+ abi: eternalFarmingAbi,
4706
+ functionName: "incentives",
4707
+ args: [incentiveId(key)]
4708
+ })
4709
+ ]);
4710
+ }
4711
+ const results = await multicallRead(this.rpcUrl, calls);
4712
+ for (let i = 0; i < results.length; i++) {
4713
+ const data = results[i];
4714
+ if (!data || data.length < 66) continue;
4715
+ try {
4716
+ const decoded = decodeAbiParameters5(
4717
+ [
4718
+ { name: "totalReward", type: "uint256" },
4719
+ { name: "bonusReward", type: "uint256" },
4720
+ { name: "virtualPoolAddress", type: "address" },
4721
+ { name: "minimalPositionWidth", type: "uint24" },
4722
+ { name: "deactivated", type: "bool" },
4723
+ { name: "pluginAddress", type: "address" }
4724
+ ],
4725
+ data
4726
+ );
4727
+ const totalReward = decoded[0];
4728
+ const deactivated = decoded[4];
4729
+ if (totalReward > 0n && !deactivated) {
4730
+ const nonce = nonces[i];
4731
+ nonceCache.set(poolLc, nonce);
4732
+ return {
4733
+ rewardToken: KITTEN_TOKEN,
4734
+ bonusRewardToken: WHYPE_TOKEN,
4735
+ pool,
4736
+ nonce
4737
+ };
4738
+ }
4739
+ } catch {
4740
+ }
4741
+ }
4742
+ return null;
4743
+ }
4744
+ /**
4745
+ * Build approveForFarming tx on the PositionManager.
4746
+ * Required before enterFarming if not already approved.
4747
+ */
4748
+ async buildApproveForFarming(tokenId) {
4749
+ const client = createPublicClient9({ transport: http9(this.rpcUrl) });
4750
+ const currentApproval = await client.readContract({
4751
+ address: this.positionManager,
4752
+ abi: positionManagerAbi2,
4753
+ functionName: "farmingApprovals",
4754
+ args: [tokenId]
4755
+ });
4756
+ if (currentApproval.toLowerCase() === this.farmingCenter.toLowerCase()) {
4757
+ return null;
4758
+ }
4759
+ return {
4760
+ description: `[${this.protocolName}] Approve NFT #${tokenId} for farming`,
4761
+ to: this.positionManager,
4762
+ data: encodeFunctionData13({
4763
+ abi: positionManagerAbi2,
4764
+ functionName: "approveForFarming",
4765
+ args: [tokenId, true, this.farmingCenter]
4766
+ }),
4767
+ value: 0n,
4768
+ gas_estimate: 6e4
4769
+ };
4770
+ }
4771
+ /**
4772
+ * Build enterFarming tx for a position NFT.
4773
+ * Checks farming approval first and returns pre_txs if needed.
4774
+ */
4775
+ async buildEnterFarming(tokenId, pool, _owner) {
4776
+ const key = await this.discoverIncentiveKey(pool);
4777
+ if (!key) {
4778
+ throw new DefiError(
4779
+ "CONTRACT_ERROR",
4780
+ `[${this.protocolName}] No active incentive found for pool ${pool}`
4781
+ );
4782
+ }
4783
+ const approveTx = await this.buildApproveForFarming(tokenId);
4784
+ return {
4785
+ description: `[${this.protocolName}] Enter farming for NFT #${tokenId} in pool ${pool}`,
4786
+ to: this.farmingCenter,
4787
+ data: encodeEnterFarming(key, tokenId),
4788
+ value: 0n,
4789
+ gas_estimate: 4e5,
4790
+ pre_txs: approveTx ? [approveTx] : void 0
4791
+ };
4792
+ }
4793
+ /**
4794
+ * Build a tx that exits farming for a position NFT (unstakes).
4795
+ */
4796
+ async buildExitFarming(tokenId, pool) {
4797
+ const key = await this.discoverIncentiveKey(pool);
4798
+ if (!key) {
4799
+ throw new DefiError(
4800
+ "CONTRACT_ERROR",
4801
+ `[${this.protocolName}] No active incentive found for pool ${pool}`
4802
+ );
4803
+ }
4804
+ return {
4805
+ description: `[${this.protocolName}] Exit farming for NFT #${tokenId} in pool ${pool}`,
4806
+ to: this.farmingCenter,
4807
+ data: encodeExitFarming(key, tokenId),
4808
+ value: 0n,
4809
+ gas_estimate: 3e5
4810
+ };
4811
+ }
4812
+ /**
4813
+ * Build a multicall tx that collects rewards for a staked position and claims them.
4814
+ * Pattern: multicall([collectRewards(key, tokenId), claimReward(KITTEN, owner, max), claimReward(WHYPE, owner, max)])
4815
+ */
4816
+ async buildCollectRewards(tokenId, pool, owner) {
4817
+ const key = await this.discoverIncentiveKey(pool);
4818
+ if (!key) {
4819
+ throw new DefiError(
4820
+ "CONTRACT_ERROR",
4821
+ `[${this.protocolName}] No active incentive found for pool ${pool}`
4822
+ );
4823
+ }
4824
+ const calls = [
4825
+ encodeCollectRewards(key, tokenId),
4826
+ encodeClaimReward(KITTEN_TOKEN, owner),
4827
+ encodeClaimReward(WHYPE_TOKEN, owner)
4828
+ ];
4829
+ return {
4830
+ description: `[${this.protocolName}] Collect + claim rewards for NFT #${tokenId} in pool ${pool}`,
4831
+ to: this.farmingCenter,
4832
+ data: encodeMulticall(calls),
4833
+ value: 0n,
4834
+ gas_estimate: 4e5
4835
+ };
4836
+ }
4837
+ /**
4838
+ * Build a tx that only claims already-accumulated rewards (no position change needed).
4839
+ */
4840
+ async buildClaimReward(owner) {
4841
+ const calls = [
4842
+ encodeClaimReward(KITTEN_TOKEN, owner),
4843
+ encodeClaimReward(WHYPE_TOKEN, owner)
4844
+ ];
4845
+ return {
4846
+ description: `[${this.protocolName}] Claim KITTEN + WHYPE farming rewards to ${owner}`,
4847
+ to: this.farmingCenter,
4848
+ data: encodeMulticall(calls),
4849
+ value: 0n,
4850
+ gas_estimate: 2e5
4851
+ };
4852
+ }
4853
+ /**
4854
+ * Query pending rewards for a staked position NFT.
4855
+ */
4856
+ async getPendingRewards(tokenId, pool) {
4857
+ const key = await this.discoverIncentiveKey(pool);
4858
+ if (!key) {
4859
+ return { reward: 0n, bonusReward: 0n };
4860
+ }
4861
+ const client = createPublicClient9({ transport: http9(this.rpcUrl) });
4862
+ const result = await client.readContract({
4863
+ address: this.eternalFarming,
4864
+ abi: eternalFarmingAbi,
4865
+ functionName: "getRewardInfo",
4866
+ args: [key, tokenId]
4867
+ });
4868
+ return { reward: result[0], bonusReward: result[1] };
4869
+ }
4870
+ /**
4871
+ * Discover all KittenSwap pools with active farming incentives.
4872
+ *
4873
+ * Steps:
4874
+ * 1. Generate all unique token pair combos from HYPEREVM_TOKENS (includes KITTEN)
4875
+ * 2. Batch poolByPair calls via multicall against the Algebra factory
4876
+ * 3. For each found pool, batch-scan nonces 0-60 via multicall
4877
+ * 4. Return enriched FarmingPool[] for pools with active incentives
4878
+ */
4879
+ async discoverFarmingPools() {
4880
+ if (!this.factory) {
4881
+ return [];
4882
+ }
4883
+ const pairs = [];
4884
+ for (let i = 0; i < HYPEREVM_TOKENS2.length; i++) {
4885
+ for (let j = i + 1; j < HYPEREVM_TOKENS2.length; j++) {
4886
+ pairs.push([HYPEREVM_TOKENS2[i], HYPEREVM_TOKENS2[j]]);
4887
+ }
4888
+ }
4889
+ const poolByPairCalls = pairs.map(([tokenA, tokenB]) => [
4890
+ this.factory,
4891
+ encodeFunctionData13({
4892
+ abi: algebraFactoryAbi,
4893
+ functionName: "poolByPair",
4894
+ args: [tokenA, tokenB]
4895
+ })
4896
+ ]);
4897
+ const poolResults = await multicallRead(this.rpcUrl, poolByPairCalls);
4898
+ const poolSet = /* @__PURE__ */ new Set();
4899
+ for (const data of poolResults) {
4900
+ const addr = decodeAddress3(data);
4901
+ if (addr && addr !== zeroAddress7) {
4902
+ poolSet.add(addr.toLowerCase());
4903
+ }
4904
+ }
4905
+ if (poolSet.size === 0) return [];
4906
+ const pools = Array.from(poolSet);
4907
+ const NONCE_COUNT = MAX_NONCE_SCAN + 1;
4908
+ const allNonceCalls = [];
4909
+ for (const pool of pools) {
4910
+ for (let n = 0; n <= MAX_NONCE_SCAN; n++) {
4911
+ const key = {
4912
+ rewardToken: KITTEN_TOKEN,
4913
+ bonusRewardToken: WHYPE_TOKEN,
4914
+ pool,
4915
+ nonce: BigInt(n)
4916
+ };
4917
+ allNonceCalls.push([
4918
+ this.eternalFarming,
4919
+ encodeFunctionData13({
4920
+ abi: eternalFarmingAbi,
4921
+ functionName: "incentives",
4922
+ args: [incentiveId(key)]
4923
+ })
4924
+ ]);
4925
+ }
4926
+ }
4927
+ const allNonceResults = await multicallRead(this.rpcUrl, allNonceCalls);
4928
+ const results = [];
4929
+ for (let pi = 0; pi < pools.length; pi++) {
4930
+ const pool = pools[pi];
4931
+ const poolLc = pool.toLowerCase();
4932
+ const base = pi * NONCE_COUNT;
4933
+ let bestKey = null;
4934
+ let bestTotalReward = 0n;
4935
+ let bestBonusReward = 0n;
4936
+ let bestActive = false;
4937
+ for (let n = 0; n <= MAX_NONCE_SCAN; n++) {
4938
+ const data = allNonceResults[base + n];
4939
+ if (!data || data.length < 66) continue;
4940
+ try {
4941
+ const decoded = decodeAbiParameters5(
4942
+ [
4943
+ { name: "totalReward", type: "uint256" },
4944
+ { name: "bonusReward", type: "uint256" },
4945
+ { name: "virtualPoolAddress", type: "address" },
4946
+ { name: "minimalPositionWidth", type: "uint24" },
4947
+ { name: "deactivated", type: "bool" },
4948
+ { name: "pluginAddress", type: "address" }
4949
+ ],
4950
+ data
4951
+ );
4952
+ const totalReward = decoded[0];
4953
+ const bonusReward = decoded[1];
4954
+ const deactivated = decoded[4];
4955
+ if (totalReward > 0n) {
4956
+ const nonce = BigInt(n);
4957
+ const isActive = !deactivated;
4958
+ if (!bestKey || isActive && !bestActive || isActive === bestActive && nonce > bestKey.nonce) {
4959
+ bestKey = {
4960
+ rewardToken: KITTEN_TOKEN,
4961
+ bonusRewardToken: WHYPE_TOKEN,
4962
+ pool,
4963
+ nonce
4964
+ };
4965
+ bestTotalReward = totalReward;
4966
+ bestBonusReward = bonusReward;
4967
+ bestActive = isActive;
4968
+ }
4969
+ }
4970
+ } catch {
4971
+ }
4972
+ }
4973
+ if (bestKey) {
4974
+ nonceCache.set(poolLc, bestKey.nonce);
4975
+ results.push({
4976
+ pool,
4977
+ key: bestKey,
4978
+ totalReward: bestTotalReward,
4979
+ bonusReward: bestBonusReward,
4980
+ active: bestActive
4981
+ });
4982
+ }
4983
+ }
4984
+ return results;
4985
+ }
4986
+ };
4987
+ POOL_ABI = parseAbi14([
3577
4988
  "function supply(address asset, uint256 amount, address onBehalfOf, uint16 referralCode) external",
3578
4989
  "function borrow(address asset, uint256 amount, uint256 interestRateMode, uint16 referralCode, address onBehalfOf) external",
3579
4990
  "function repay(address asset, uint256 amount, uint256 interestRateMode, address onBehalfOf) external returns (uint256)",
@@ -3581,27 +4992,27 @@ var init_dist3 = __esm({
3581
4992
  "function getUserAccountData(address user) external view returns (uint256 totalCollateralBase, uint256 totalDebtBase, uint256 availableBorrowsBase, uint256 currentLiquidationThreshold, uint256 ltv, uint256 healthFactor)",
3582
4993
  "function getReserveData(address asset) external view returns (uint256 configuration, uint128 liquidityIndex, uint128 currentLiquidityRate, uint128 variableBorrowIndex, uint128 currentVariableBorrowRate, uint128 currentStableBorrowRate, uint40 lastUpdateTimestamp, uint16 id, address aTokenAddress, address stableDebtTokenAddress, address variableDebtTokenAddress, address interestRateStrategyAddress, uint128 accruedToTreasury, uint128 unbacked, uint128 isolationModeTotalDebt)"
3583
4994
  ]);
3584
- ERC20_ABI = parseAbi11([
4995
+ ERC20_ABI = parseAbi14([
3585
4996
  "function totalSupply() external view returns (uint256)"
3586
4997
  ]);
3587
- INCENTIVES_ABI = parseAbi11([
4998
+ INCENTIVES_ABI = parseAbi14([
3588
4999
  "function getIncentivesController() external view returns (address)"
3589
5000
  ]);
3590
- REWARDS_CONTROLLER_ABI = parseAbi11([
5001
+ REWARDS_CONTROLLER_ABI = parseAbi14([
3591
5002
  "function getRewardsByAsset(address asset) external view returns (address[])",
3592
5003
  "function getRewardsData(address asset, address reward) external view returns (uint256 index, uint256 emissionsPerSecond, uint256 lastUpdateTimestamp, uint256 distributionEnd)"
3593
5004
  ]);
3594
- POOL_PROVIDER_ABI = parseAbi11([
5005
+ POOL_PROVIDER_ABI = parseAbi14([
3595
5006
  "function ADDRESSES_PROVIDER() external view returns (address)"
3596
5007
  ]);
3597
- ADDRESSES_PROVIDER_ABI = parseAbi11([
5008
+ ADDRESSES_PROVIDER_ABI = parseAbi14([
3598
5009
  "function getPriceOracle() external view returns (address)"
3599
5010
  ]);
3600
- ORACLE_ABI = parseAbi11([
5011
+ ORACLE_ABI = parseAbi14([
3601
5012
  "function getAssetPrice(address asset) external view returns (uint256)",
3602
5013
  "function BASE_CURRENCY_UNIT() external view returns (uint256)"
3603
5014
  ]);
3604
- ERC20_DECIMALS_ABI = parseAbi11([
5015
+ ERC20_DECIMALS_ABI = parseAbi14([
3605
5016
  "function decimals() external view returns (uint8)"
3606
5017
  ]);
3607
5018
  AaveV3Adapter = class {
@@ -3619,7 +5030,7 @@ var init_dist3 = __esm({
3619
5030
  return this.protocolName;
3620
5031
  }
3621
5032
  async buildSupply(params) {
3622
- const data = encodeFunctionData11({
5033
+ const data = encodeFunctionData14({
3623
5034
  abi: POOL_ABI,
3624
5035
  functionName: "supply",
3625
5036
  args: [params.asset, params.amount, params.on_behalf_of, 0]
@@ -3635,7 +5046,7 @@ var init_dist3 = __esm({
3635
5046
  }
3636
5047
  async buildBorrow(params) {
3637
5048
  const rateMode = params.interest_rate_mode === InterestRateMode.Stable ? 1n : 2n;
3638
- const data = encodeFunctionData11({
5049
+ const data = encodeFunctionData14({
3639
5050
  abi: POOL_ABI,
3640
5051
  functionName: "borrow",
3641
5052
  args: [params.asset, params.amount, rateMode, 0, params.on_behalf_of]
@@ -3650,7 +5061,7 @@ var init_dist3 = __esm({
3650
5061
  }
3651
5062
  async buildRepay(params) {
3652
5063
  const rateMode = params.interest_rate_mode === InterestRateMode.Stable ? 1n : 2n;
3653
- const data = encodeFunctionData11({
5064
+ const data = encodeFunctionData14({
3654
5065
  abi: POOL_ABI,
3655
5066
  functionName: "repay",
3656
5067
  args: [params.asset, params.amount, rateMode, params.on_behalf_of]
@@ -3665,7 +5076,7 @@ var init_dist3 = __esm({
3665
5076
  };
3666
5077
  }
3667
5078
  async buildWithdraw(params) {
3668
- const data = encodeFunctionData11({
5079
+ const data = encodeFunctionData14({
3669
5080
  abi: POOL_ABI,
3670
5081
  functionName: "withdraw",
3671
5082
  args: [params.asset, params.amount, params.to]
@@ -3680,7 +5091,7 @@ var init_dist3 = __esm({
3680
5091
  }
3681
5092
  async getRates(asset) {
3682
5093
  if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
3683
- const reserveCallData = encodeFunctionData11({
5094
+ const reserveCallData = encodeFunctionData14({
3684
5095
  abi: POOL_ABI,
3685
5096
  functionName: "getReserveData",
3686
5097
  args: [asset]
@@ -3707,8 +5118,8 @@ var init_dist3 = __esm({
3707
5118
  const aTokenAddress = result[8];
3708
5119
  const variableDebtTokenAddress = result[10];
3709
5120
  const [supplyRaw, borrowRaw] = await multicallRead(this.rpcUrl, [
3710
- [aTokenAddress, encodeFunctionData11({ abi: ERC20_ABI, functionName: "totalSupply" })],
3711
- [variableDebtTokenAddress, encodeFunctionData11({ abi: ERC20_ABI, functionName: "totalSupply" })]
5121
+ [aTokenAddress, encodeFunctionData14({ abi: ERC20_ABI, functionName: "totalSupply" })],
5122
+ [variableDebtTokenAddress, encodeFunctionData14({ abi: ERC20_ABI, functionName: "totalSupply" })]
3712
5123
  ]);
3713
5124
  const totalSupply = decodeU256(supplyRaw ?? null);
3714
5125
  const totalBorrow = decodeU256(borrowRaw ?? null);
@@ -3719,24 +5130,24 @@ var init_dist3 = __esm({
3719
5130
  const borrowEmissions = [];
3720
5131
  try {
3721
5132
  const [controllerRaw] = await multicallRead(this.rpcUrl, [
3722
- [aTokenAddress, encodeFunctionData11({ abi: INCENTIVES_ABI, functionName: "getIncentivesController" })]
5133
+ [aTokenAddress, encodeFunctionData14({ abi: INCENTIVES_ABI, functionName: "getIncentivesController" })]
3723
5134
  ]);
3724
- const controllerAddr = decodeAddress(controllerRaw ?? null);
3725
- if (controllerAddr && controllerAddr !== zeroAddress5) {
5135
+ const controllerAddr = decodeAddress4(controllerRaw ?? null);
5136
+ if (controllerAddr && controllerAddr !== zeroAddress8) {
3726
5137
  const [supplyRewardsRaw, borrowRewardsRaw] = await multicallRead(this.rpcUrl, [
3727
- [controllerAddr, encodeFunctionData11({ abi: REWARDS_CONTROLLER_ABI, functionName: "getRewardsByAsset", args: [aTokenAddress] })],
3728
- [controllerAddr, encodeFunctionData11({ abi: REWARDS_CONTROLLER_ABI, functionName: "getRewardsByAsset", args: [variableDebtTokenAddress] })]
5138
+ [controllerAddr, encodeFunctionData14({ abi: REWARDS_CONTROLLER_ABI, functionName: "getRewardsByAsset", args: [aTokenAddress] })],
5139
+ [controllerAddr, encodeFunctionData14({ abi: REWARDS_CONTROLLER_ABI, functionName: "getRewardsByAsset", args: [variableDebtTokenAddress] })]
3729
5140
  ]);
3730
5141
  const supplyRewards = decodeAddressArray(supplyRewardsRaw ?? null);
3731
5142
  const borrowRewards = decodeAddressArray(borrowRewardsRaw ?? null);
3732
5143
  const rewardsDataCalls = [
3733
5144
  ...supplyRewards.map((reward) => [
3734
5145
  controllerAddr,
3735
- encodeFunctionData11({ abi: REWARDS_CONTROLLER_ABI, functionName: "getRewardsData", args: [aTokenAddress, reward] })
5146
+ encodeFunctionData14({ abi: REWARDS_CONTROLLER_ABI, functionName: "getRewardsData", args: [aTokenAddress, reward] })
3736
5147
  ]),
3737
5148
  ...borrowRewards.map((reward) => [
3738
5149
  controllerAddr,
3739
- encodeFunctionData11({ abi: REWARDS_CONTROLLER_ABI, functionName: "getRewardsData", args: [variableDebtTokenAddress, reward] })
5150
+ encodeFunctionData14({ abi: REWARDS_CONTROLLER_ABI, functionName: "getRewardsData", args: [variableDebtTokenAddress, reward] })
3740
5151
  ])
3741
5152
  ];
3742
5153
  if (rewardsDataCalls.length > 0) {
@@ -3768,19 +5179,19 @@ var init_dist3 = __esm({
3768
5179
  if ((hasSupplyRewards || hasBorrowRewards) && totalSupply > 0n) {
3769
5180
  try {
3770
5181
  const [providerRaw] = await multicallRead(this.rpcUrl, [
3771
- [this.pool, encodeFunctionData11({ abi: POOL_PROVIDER_ABI, functionName: "ADDRESSES_PROVIDER" })]
5182
+ [this.pool, encodeFunctionData14({ abi: POOL_PROVIDER_ABI, functionName: "ADDRESSES_PROVIDER" })]
3772
5183
  ]);
3773
- const providerAddr = decodeAddress(providerRaw ?? null);
5184
+ const providerAddr = decodeAddress4(providerRaw ?? null);
3774
5185
  if (!providerAddr) throw new Error("No provider address");
3775
5186
  const [oracleRaw] = await multicallRead(this.rpcUrl, [
3776
- [providerAddr, encodeFunctionData11({ abi: ADDRESSES_PROVIDER_ABI, functionName: "getPriceOracle" })]
5187
+ [providerAddr, encodeFunctionData14({ abi: ADDRESSES_PROVIDER_ABI, functionName: "getPriceOracle" })]
3777
5188
  ]);
3778
- const oracleAddr = decodeAddress(oracleRaw ?? null);
5189
+ const oracleAddr = decodeAddress4(oracleRaw ?? null);
3779
5190
  if (!oracleAddr) throw new Error("No oracle address");
3780
5191
  const [assetPriceRaw, baseCurrencyUnitRaw, assetDecimalsRaw] = await multicallRead(this.rpcUrl, [
3781
- [oracleAddr, encodeFunctionData11({ abi: ORACLE_ABI, functionName: "getAssetPrice", args: [asset] })],
3782
- [oracleAddr, encodeFunctionData11({ abi: ORACLE_ABI, functionName: "BASE_CURRENCY_UNIT" })],
3783
- [asset, encodeFunctionData11({ abi: ERC20_DECIMALS_ABI, functionName: "decimals" })]
5192
+ [oracleAddr, encodeFunctionData14({ abi: ORACLE_ABI, functionName: "getAssetPrice", args: [asset] })],
5193
+ [oracleAddr, encodeFunctionData14({ abi: ORACLE_ABI, functionName: "BASE_CURRENCY_UNIT" })],
5194
+ [asset, encodeFunctionData14({ abi: ERC20_DECIMALS_ABI, functionName: "decimals" })]
3784
5195
  ]);
3785
5196
  const assetPrice = decodeU256(assetPriceRaw ?? null);
3786
5197
  const baseCurrencyUnit = decodeU256(baseCurrencyUnitRaw ?? null);
@@ -3790,8 +5201,8 @@ var init_dist3 = __esm({
3790
5201
  const assetDecimalsDivisor = 10 ** assetDecimals;
3791
5202
  const allRewardTokens = Array.from(/* @__PURE__ */ new Set([...supplyRewardTokens, ...borrowRewardTokens]));
3792
5203
  const rewardPriceCalls = allRewardTokens.flatMap((token) => [
3793
- [oracleAddr, encodeFunctionData11({ abi: ORACLE_ABI, functionName: "getAssetPrice", args: [token] })],
3794
- [token, encodeFunctionData11({ abi: ERC20_DECIMALS_ABI, functionName: "decimals" })]
5204
+ [oracleAddr, encodeFunctionData14({ abi: ORACLE_ABI, functionName: "getAssetPrice", args: [token] })],
5205
+ [token, encodeFunctionData14({ abi: ERC20_DECIMALS_ABI, functionName: "decimals" })]
3795
5206
  ]);
3796
5207
  const rewardPriceResults = rewardPriceCalls.length > 0 ? await multicallRead(this.rpcUrl, rewardPriceCalls) : [];
3797
5208
  const rewardPriceMap = /* @__PURE__ */ new Map();
@@ -3864,7 +5275,7 @@ var init_dist3 = __esm({
3864
5275
  }
3865
5276
  async getUserPosition(user) {
3866
5277
  if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
3867
- const client = createPublicClient7({ transport: http7(this.rpcUrl) });
5278
+ const client = createPublicClient10({ transport: http10(this.rpcUrl) });
3868
5279
  const result = await client.readContract({
3869
5280
  address: this.pool,
3870
5281
  abi: POOL_ABI,
@@ -3879,8 +5290,8 @@ var init_dist3 = __esm({
3879
5290
  const collateralUsd = u256ToF64(totalCollateralBase) / 1e8;
3880
5291
  const debtUsd = u256ToF64(totalDebtBase) / 1e8;
3881
5292
  const ltvBps = u256ToF64(ltv);
3882
- const supplies = collateralUsd > 0 ? [{ asset: zeroAddress5, symbol: "Total Collateral", amount: totalCollateralBase, value_usd: collateralUsd }] : [];
3883
- const borrows = debtUsd > 0 ? [{ asset: zeroAddress5, symbol: "Total Debt", amount: totalDebtBase, value_usd: debtUsd }] : [];
5293
+ const supplies = collateralUsd > 0 ? [{ asset: zeroAddress8, symbol: "Total Collateral", amount: totalCollateralBase, value_usd: collateralUsd }] : [];
5294
+ const borrows = debtUsd > 0 ? [{ asset: zeroAddress8, symbol: "Total Debt", amount: totalDebtBase, value_usd: debtUsd }] : [];
3884
5295
  return {
3885
5296
  protocol: this.protocolName,
3886
5297
  user,
@@ -3891,7 +5302,7 @@ var init_dist3 = __esm({
3891
5302
  };
3892
5303
  }
3893
5304
  };
3894
- POOL_ABI2 = parseAbi12([
5305
+ POOL_ABI2 = parseAbi15([
3895
5306
  "function deposit(address asset, uint256 amount, address onBehalfOf, uint16 referralCode) external",
3896
5307
  "function borrow(address asset, uint256 amount, uint256 interestRateMode, uint16 referralCode, address onBehalfOf) external",
3897
5308
  "function repay(address asset, uint256 amount, uint256 rateMode, address onBehalfOf) external returns (uint256)",
@@ -3904,7 +5315,7 @@ var init_dist3 = __esm({
3904
5315
  // [9]=variableDebtTokenAddress, [10]=interestRateStrategyAddress, [11]=id
3905
5316
  "function getReserveData(address asset) external view returns (uint256 configuration, uint128 liquidityIndex, uint128 variableBorrowIndex, uint128 currentLiquidityRate, uint128 currentVariableBorrowRate, uint128 currentStableBorrowRate, uint40 lastUpdateTimestamp, address aTokenAddress, address stableDebtTokenAddress, address variableDebtTokenAddress, address interestRateStrategyAddress, uint8 id)"
3906
5317
  ]);
3907
- ERC20_ABI2 = parseAbi12([
5318
+ ERC20_ABI2 = parseAbi15([
3908
5319
  "function totalSupply() external view returns (uint256)"
3909
5320
  ]);
3910
5321
  AaveV2Adapter = class {
@@ -3922,7 +5333,7 @@ var init_dist3 = __esm({
3922
5333
  return this.protocolName;
3923
5334
  }
3924
5335
  async buildSupply(params) {
3925
- const data = encodeFunctionData12({
5336
+ const data = encodeFunctionData15({
3926
5337
  abi: POOL_ABI2,
3927
5338
  functionName: "deposit",
3928
5339
  args: [params.asset, params.amount, params.on_behalf_of, 0]
@@ -3938,7 +5349,7 @@ var init_dist3 = __esm({
3938
5349
  }
3939
5350
  async buildBorrow(params) {
3940
5351
  const rateMode = params.interest_rate_mode === InterestRateMode.Stable ? 1n : 2n;
3941
- const data = encodeFunctionData12({
5352
+ const data = encodeFunctionData15({
3942
5353
  abi: POOL_ABI2,
3943
5354
  functionName: "borrow",
3944
5355
  args: [params.asset, params.amount, rateMode, 0, params.on_behalf_of]
@@ -3953,7 +5364,7 @@ var init_dist3 = __esm({
3953
5364
  }
3954
5365
  async buildRepay(params) {
3955
5366
  const rateMode = params.interest_rate_mode === InterestRateMode.Stable ? 1n : 2n;
3956
- const data = encodeFunctionData12({
5367
+ const data = encodeFunctionData15({
3957
5368
  abi: POOL_ABI2,
3958
5369
  functionName: "repay",
3959
5370
  args: [params.asset, params.amount, rateMode, params.on_behalf_of]
@@ -3968,7 +5379,7 @@ var init_dist3 = __esm({
3968
5379
  };
3969
5380
  }
3970
5381
  async buildWithdraw(params) {
3971
- const data = encodeFunctionData12({
5382
+ const data = encodeFunctionData15({
3972
5383
  abi: POOL_ABI2,
3973
5384
  functionName: "withdraw",
3974
5385
  args: [params.asset, params.amount, params.to]
@@ -3983,7 +5394,7 @@ var init_dist3 = __esm({
3983
5394
  }
3984
5395
  async getRates(asset) {
3985
5396
  if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
3986
- const client = createPublicClient8({ transport: http8(this.rpcUrl) });
5397
+ const client = createPublicClient11({ transport: http11(this.rpcUrl) });
3987
5398
  const result = await client.readContract({
3988
5399
  address: this.pool,
3989
5400
  abi: POOL_ABI2,
@@ -4029,7 +5440,7 @@ var init_dist3 = __esm({
4029
5440
  }
4030
5441
  async getUserPosition(user) {
4031
5442
  if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
4032
- const client = createPublicClient8({ transport: http8(this.rpcUrl) });
5443
+ const client = createPublicClient11({ transport: http11(this.rpcUrl) });
4033
5444
  const result = await client.readContract({
4034
5445
  address: this.pool,
4035
5446
  abi: POOL_ABI2,
@@ -4044,8 +5455,8 @@ var init_dist3 = __esm({
4044
5455
  const collateralUsd = u256ToF642(totalCollateralBase) / 1e18;
4045
5456
  const debtUsd = u256ToF642(totalDebtBase) / 1e18;
4046
5457
  const ltvBps = u256ToF642(ltv);
4047
- const supplies = collateralUsd > 0 ? [{ asset: zeroAddress6, symbol: "Total Collateral", amount: totalCollateralBase, value_usd: collateralUsd }] : [];
4048
- const borrows = debtUsd > 0 ? [{ asset: zeroAddress6, symbol: "Total Debt", amount: totalDebtBase, value_usd: debtUsd }] : [];
5458
+ const supplies = collateralUsd > 0 ? [{ asset: zeroAddress9, symbol: "Total Collateral", amount: totalCollateralBase, value_usd: collateralUsd }] : [];
5459
+ const borrows = debtUsd > 0 ? [{ asset: zeroAddress9, symbol: "Total Debt", amount: totalDebtBase, value_usd: debtUsd }] : [];
4049
5460
  return {
4050
5461
  protocol: this.protocolName,
4051
5462
  user,
@@ -4056,7 +5467,7 @@ var init_dist3 = __esm({
4056
5467
  };
4057
5468
  }
4058
5469
  };
4059
- ORACLE_ABI2 = parseAbi13([
5470
+ ORACLE_ABI2 = parseAbi16([
4060
5471
  "function getAssetPrice(address asset) external view returns (uint256)",
4061
5472
  "function getAssetsPrices(address[] calldata assets) external view returns (uint256[] memory)",
4062
5473
  "function BASE_CURRENCY_UNIT() external view returns (uint256)"
@@ -4077,7 +5488,7 @@ var init_dist3 = __esm({
4077
5488
  return this.protocolName;
4078
5489
  }
4079
5490
  async getPrice(asset) {
4080
- const client = createPublicClient9({ transport: http9(this.rpcUrl) });
5491
+ const client = createPublicClient12({ transport: http12(this.rpcUrl) });
4081
5492
  const baseUnit = await client.readContract({
4082
5493
  address: this.oracle,
4083
5494
  abi: ORACLE_ABI2,
@@ -4104,7 +5515,7 @@ var init_dist3 = __esm({
4104
5515
  };
4105
5516
  }
4106
5517
  async getPrices(assets) {
4107
- const client = createPublicClient9({ transport: http9(this.rpcUrl) });
5518
+ const client = createPublicClient12({ transport: http12(this.rpcUrl) });
4108
5519
  const baseUnit = await client.readContract({
4109
5520
  address: this.oracle,
4110
5521
  abi: ORACLE_ABI2,
@@ -4133,7 +5544,7 @@ var init_dist3 = __esm({
4133
5544
  });
4134
5545
  }
4135
5546
  };
4136
- CTOKEN_ABI = parseAbi14([
5547
+ CTOKEN_ABI = parseAbi17([
4137
5548
  "function supplyRatePerBlock() external view returns (uint256)",
4138
5549
  "function borrowRatePerBlock() external view returns (uint256)",
4139
5550
  "function totalSupply() external view returns (uint256)",
@@ -4160,7 +5571,7 @@ var init_dist3 = __esm({
4160
5571
  return this.protocolName;
4161
5572
  }
4162
5573
  async buildSupply(params) {
4163
- const data = encodeFunctionData13({
5574
+ const data = encodeFunctionData16({
4164
5575
  abi: CTOKEN_ABI,
4165
5576
  functionName: "mint",
4166
5577
  args: [params.amount]
@@ -4174,7 +5585,7 @@ var init_dist3 = __esm({
4174
5585
  };
4175
5586
  }
4176
5587
  async buildBorrow(params) {
4177
- const data = encodeFunctionData13({
5588
+ const data = encodeFunctionData16({
4178
5589
  abi: CTOKEN_ABI,
4179
5590
  functionName: "borrow",
4180
5591
  args: [params.amount]
@@ -4188,7 +5599,7 @@ var init_dist3 = __esm({
4188
5599
  };
4189
5600
  }
4190
5601
  async buildRepay(params) {
4191
- const data = encodeFunctionData13({
5602
+ const data = encodeFunctionData16({
4192
5603
  abi: CTOKEN_ABI,
4193
5604
  functionName: "repayBorrow",
4194
5605
  args: [params.amount]
@@ -4202,7 +5613,7 @@ var init_dist3 = __esm({
4202
5613
  };
4203
5614
  }
4204
5615
  async buildWithdraw(params) {
4205
- const data = encodeFunctionData13({
5616
+ const data = encodeFunctionData16({
4206
5617
  abi: CTOKEN_ABI,
4207
5618
  functionName: "redeem",
4208
5619
  args: [params.amount]
@@ -4217,7 +5628,7 @@ var init_dist3 = __esm({
4217
5628
  }
4218
5629
  async getRates(asset) {
4219
5630
  if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
4220
- const client = createPublicClient10({ transport: http10(this.rpcUrl) });
5631
+ const client = createPublicClient13({ transport: http13(this.rpcUrl) });
4221
5632
  const [supplyRate, borrowRate, totalSupply, totalBorrows] = await Promise.all([
4222
5633
  client.readContract({ address: this.defaultVtoken, abi: CTOKEN_ABI, functionName: "supplyRatePerBlock" }).catch((e) => {
4223
5634
  throw DefiError.rpcError(`[${this.protocolName}] supplyRatePerBlock failed: ${e}`);
@@ -4251,7 +5662,7 @@ var init_dist3 = __esm({
4251
5662
  );
4252
5663
  }
4253
5664
  };
4254
- COMET_ABI = parseAbi15([
5665
+ COMET_ABI = parseAbi18([
4255
5666
  "function getUtilization() external view returns (uint256)",
4256
5667
  "function getSupplyRate(uint256 utilization) external view returns (uint64)",
4257
5668
  "function getBorrowRate(uint256 utilization) external view returns (uint64)",
@@ -4277,7 +5688,7 @@ var init_dist3 = __esm({
4277
5688
  return this.protocolName;
4278
5689
  }
4279
5690
  async buildSupply(params) {
4280
- const data = encodeFunctionData14({
5691
+ const data = encodeFunctionData17({
4281
5692
  abi: COMET_ABI,
4282
5693
  functionName: "supply",
4283
5694
  args: [params.asset, params.amount]
@@ -4291,7 +5702,7 @@ var init_dist3 = __esm({
4291
5702
  };
4292
5703
  }
4293
5704
  async buildBorrow(params) {
4294
- const data = encodeFunctionData14({
5705
+ const data = encodeFunctionData17({
4295
5706
  abi: COMET_ABI,
4296
5707
  functionName: "withdraw",
4297
5708
  args: [params.asset, params.amount]
@@ -4305,7 +5716,7 @@ var init_dist3 = __esm({
4305
5716
  };
4306
5717
  }
4307
5718
  async buildRepay(params) {
4308
- const data = encodeFunctionData14({
5719
+ const data = encodeFunctionData17({
4309
5720
  abi: COMET_ABI,
4310
5721
  functionName: "supply",
4311
5722
  args: [params.asset, params.amount]
@@ -4319,7 +5730,7 @@ var init_dist3 = __esm({
4319
5730
  };
4320
5731
  }
4321
5732
  async buildWithdraw(params) {
4322
- const data = encodeFunctionData14({
5733
+ const data = encodeFunctionData17({
4323
5734
  abi: COMET_ABI,
4324
5735
  functionName: "withdraw",
4325
5736
  args: [params.asset, params.amount]
@@ -4334,7 +5745,7 @@ var init_dist3 = __esm({
4334
5745
  }
4335
5746
  async getRates(asset) {
4336
5747
  if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
4337
- const client = createPublicClient11({ transport: http11(this.rpcUrl) });
5748
+ const client = createPublicClient14({ transport: http14(this.rpcUrl) });
4338
5749
  const utilization = await client.readContract({
4339
5750
  address: this.comet,
4340
5751
  abi: COMET_ABI,
@@ -4373,7 +5784,7 @@ var init_dist3 = __esm({
4373
5784
  );
4374
5785
  }
4375
5786
  };
4376
- EULER_VAULT_ABI = parseAbi16([
5787
+ EULER_VAULT_ABI = parseAbi19([
4377
5788
  "function deposit(uint256 amount, address receiver) external returns (uint256)",
4378
5789
  "function withdraw(uint256 amount, address receiver, address owner) external returns (uint256)",
4379
5790
  "function borrow(uint256 amount, address receiver) external returns (uint256)",
@@ -4399,7 +5810,7 @@ var init_dist3 = __esm({
4399
5810
  return this.protocolName;
4400
5811
  }
4401
5812
  async buildSupply(params) {
4402
- const data = encodeFunctionData15({
5813
+ const data = encodeFunctionData18({
4403
5814
  abi: EULER_VAULT_ABI,
4404
5815
  functionName: "deposit",
4405
5816
  args: [params.amount, params.on_behalf_of]
@@ -4413,7 +5824,7 @@ var init_dist3 = __esm({
4413
5824
  };
4414
5825
  }
4415
5826
  async buildBorrow(params) {
4416
- const data = encodeFunctionData15({
5827
+ const data = encodeFunctionData18({
4417
5828
  abi: EULER_VAULT_ABI,
4418
5829
  functionName: "borrow",
4419
5830
  args: [params.amount, params.on_behalf_of]
@@ -4427,7 +5838,7 @@ var init_dist3 = __esm({
4427
5838
  };
4428
5839
  }
4429
5840
  async buildRepay(params) {
4430
- const data = encodeFunctionData15({
5841
+ const data = encodeFunctionData18({
4431
5842
  abi: EULER_VAULT_ABI,
4432
5843
  functionName: "repay",
4433
5844
  args: [params.amount, params.on_behalf_of]
@@ -4441,7 +5852,7 @@ var init_dist3 = __esm({
4441
5852
  };
4442
5853
  }
4443
5854
  async buildWithdraw(params) {
4444
- const data = encodeFunctionData15({
5855
+ const data = encodeFunctionData18({
4445
5856
  abi: EULER_VAULT_ABI,
4446
5857
  functionName: "withdraw",
4447
5858
  args: [params.amount, params.to, params.to]
@@ -4456,7 +5867,7 @@ var init_dist3 = __esm({
4456
5867
  }
4457
5868
  async getRates(asset) {
4458
5869
  if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
4459
- const client = createPublicClient12({ transport: http12(this.rpcUrl) });
5870
+ const client = createPublicClient15({ transport: http15(this.rpcUrl) });
4460
5871
  const [totalSupply, totalBorrows, interestRate] = await Promise.all([
4461
5872
  client.readContract({ address: this.euler, abi: EULER_VAULT_ABI, functionName: "totalSupply" }).catch((e) => {
4462
5873
  throw DefiError.rpcError(`[${this.protocolName}] totalSupply failed: ${e}`);
@@ -4490,7 +5901,7 @@ var init_dist3 = __esm({
4490
5901
  );
4491
5902
  }
4492
5903
  };
4493
- MORPHO_ABI = parseAbi17([
5904
+ MORPHO_ABI = parseAbi20([
4494
5905
  "function market(bytes32 id) external view returns (uint128 totalSupplyAssets, uint128 totalSupplyShares, uint128 totalBorrowAssets, uint128 totalBorrowShares, uint128 lastUpdate, uint128 fee)",
4495
5906
  "function idToMarketParams(bytes32 id) external view returns (address loanToken, address collateralToken, address oracle, address irm, uint256 lltv)",
4496
5907
  "function supply((address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, uint256 assets, uint256 shares, address onBehalf, bytes data) external returns (uint256 assetsSupplied, uint256 sharesSupplied)",
@@ -4498,13 +5909,13 @@ var init_dist3 = __esm({
4498
5909
  "function repay((address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, uint256 assets, uint256 shares, address onBehalf, bytes data) external returns (uint256 assetsRepaid, uint256 sharesRepaid)",
4499
5910
  "function withdraw((address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, uint256 assets, uint256 shares, address onBehalf, address receiver) external returns (uint256 assetsWithdrawn, uint256 sharesWithdrawn)"
4500
5911
  ]);
4501
- META_MORPHO_ABI = parseAbi17([
5912
+ META_MORPHO_ABI = parseAbi20([
4502
5913
  "function supplyQueueLength() external view returns (uint256)",
4503
5914
  "function supplyQueue(uint256 index) external view returns (bytes32)",
4504
5915
  "function totalAssets() external view returns (uint256)",
4505
5916
  "function totalSupply() external view returns (uint256)"
4506
5917
  ]);
4507
- IRM_ABI = parseAbi17([
5918
+ IRM_ABI = parseAbi20([
4508
5919
  "function borrowRateView((address loanToken, address collateralToken, address oracle, address irm, uint256 lltv) marketParams, (uint128 totalSupplyAssets, uint128 totalSupplyShares, uint128 totalBorrowAssets, uint128 totalBorrowShares, uint128 lastUpdate, uint128 fee) market) external view returns (uint256)"
4509
5920
  ]);
4510
5921
  SECONDS_PER_YEAR3 = 365.25 * 24 * 3600;
@@ -4527,7 +5938,7 @@ var init_dist3 = __esm({
4527
5938
  }
4528
5939
  async buildSupply(params) {
4529
5940
  const market = defaultMarketParams(params.asset);
4530
- const data = encodeFunctionData16({
5941
+ const data = encodeFunctionData19({
4531
5942
  abi: MORPHO_ABI,
4532
5943
  functionName: "supply",
4533
5944
  args: [market, params.amount, 0n, params.on_behalf_of, "0x"]
@@ -4542,7 +5953,7 @@ var init_dist3 = __esm({
4542
5953
  }
4543
5954
  async buildBorrow(params) {
4544
5955
  const market = defaultMarketParams(params.asset);
4545
- const data = encodeFunctionData16({
5956
+ const data = encodeFunctionData19({
4546
5957
  abi: MORPHO_ABI,
4547
5958
  functionName: "borrow",
4548
5959
  args: [market, params.amount, 0n, params.on_behalf_of, params.on_behalf_of]
@@ -4557,7 +5968,7 @@ var init_dist3 = __esm({
4557
5968
  }
4558
5969
  async buildRepay(params) {
4559
5970
  const market = defaultMarketParams(params.asset);
4560
- const data = encodeFunctionData16({
5971
+ const data = encodeFunctionData19({
4561
5972
  abi: MORPHO_ABI,
4562
5973
  functionName: "repay",
4563
5974
  args: [market, params.amount, 0n, params.on_behalf_of, "0x"]
@@ -4572,7 +5983,7 @@ var init_dist3 = __esm({
4572
5983
  }
4573
5984
  async buildWithdraw(params) {
4574
5985
  const market = defaultMarketParams(params.asset);
4575
- const data = encodeFunctionData16({
5986
+ const data = encodeFunctionData19({
4576
5987
  abi: MORPHO_ABI,
4577
5988
  functionName: "withdraw",
4578
5989
  args: [market, params.amount, 0n, params.to, params.to]
@@ -4591,7 +6002,7 @@ var init_dist3 = __esm({
4591
6002
  throw DefiError.contractError(`[${this.protocolName}] No MetaMorpho vault configured for rate query`);
4592
6003
  }
4593
6004
  const [queueLenRaw] = await multicallRead(this.rpcUrl, [
4594
- [this.defaultVault, encodeFunctionData16({ abi: META_MORPHO_ABI, functionName: "supplyQueueLength" })]
6005
+ [this.defaultVault, encodeFunctionData19({ abi: META_MORPHO_ABI, functionName: "supplyQueueLength" })]
4595
6006
  ]).catch((e) => {
4596
6007
  throw DefiError.rpcError(`[${this.protocolName}] supplyQueueLength failed: ${e}`);
4597
6008
  });
@@ -4608,7 +6019,7 @@ var init_dist3 = __esm({
4608
6019
  };
4609
6020
  }
4610
6021
  const [marketIdRaw] = await multicallRead(this.rpcUrl, [
4611
- [this.defaultVault, encodeFunctionData16({ abi: META_MORPHO_ABI, functionName: "supplyQueue", args: [0n] })]
6022
+ [this.defaultVault, encodeFunctionData19({ abi: META_MORPHO_ABI, functionName: "supplyQueue", args: [0n] })]
4612
6023
  ]).catch((e) => {
4613
6024
  throw DefiError.rpcError(`[${this.protocolName}] supplyQueue(0) failed: ${e}`);
4614
6025
  });
@@ -4617,8 +6028,8 @@ var init_dist3 = __esm({
4617
6028
  }
4618
6029
  const marketId = marketIdRaw.slice(0, 66);
4619
6030
  const [marketRaw, paramsRaw] = await multicallRead(this.rpcUrl, [
4620
- [this.morpho, encodeFunctionData16({ abi: MORPHO_ABI, functionName: "market", args: [marketId] })],
4621
- [this.morpho, encodeFunctionData16({ abi: MORPHO_ABI, functionName: "idToMarketParams", args: [marketId] })]
6031
+ [this.morpho, encodeFunctionData19({ abi: MORPHO_ABI, functionName: "market", args: [marketId] })],
6032
+ [this.morpho, encodeFunctionData19({ abi: MORPHO_ABI, functionName: "idToMarketParams", args: [marketId] })]
4622
6033
  ]).catch((e) => {
4623
6034
  throw DefiError.rpcError(`[${this.protocolName}] market/idToMarketParams failed: ${e}`);
4624
6035
  });
@@ -4635,7 +6046,7 @@ var init_dist3 = __esm({
4635
6046
  const irmMarket = { totalSupplyAssets, totalSupplyShares, totalBorrowAssets, totalBorrowShares, lastUpdate, fee };
4636
6047
  const borrowRatePerSec = await (async () => {
4637
6048
  const [borrowRateRaw] = await multicallRead(this.rpcUrl, [
4638
- [irm, encodeFunctionData16({ abi: IRM_ABI, functionName: "borrowRateView", args: [irmMarketParams, irmMarket] })]
6049
+ [irm, encodeFunctionData19({ abi: IRM_ABI, functionName: "borrowRateView", args: [irmMarketParams, irmMarket] })]
4639
6050
  ]).catch((e) => {
4640
6051
  throw DefiError.rpcError(`[${this.protocolName}] borrowRateView failed: ${e}`);
4641
6052
  });
@@ -4661,18 +6072,18 @@ var init_dist3 = __esm({
4661
6072
  );
4662
6073
  }
4663
6074
  };
4664
- BORROWER_OPS_ABI = parseAbi18([
6075
+ BORROWER_OPS_ABI = parseAbi21([
4665
6076
  "function openTrove(address _owner, uint256 _ownerIndex, uint256 _collAmount, uint256 _boldAmount, uint256 _upperHint, uint256 _lowerHint, uint256 _annualInterestRate, uint256 _maxUpfrontFee, address _addManager, address _removeManager, address _receiver) external returns (uint256)",
4666
6077
  "function adjustTrove(uint256 _troveId, uint256 _collChange, bool _isCollIncrease, uint256 _debtChange, bool _isDebtIncrease, uint256 _upperHint, uint256 _lowerHint, uint256 _maxUpfrontFee) external",
4667
6078
  "function closeTrove(uint256 _troveId) external"
4668
6079
  ]);
4669
- TROVE_MANAGER_ABI = parseAbi18([
6080
+ TROVE_MANAGER_ABI = parseAbi21([
4670
6081
  "function getLatestTroveData(uint256 _troveId) external view returns (uint256 entireDebt, uint256 entireColl, uint256 redistDebtGain, uint256 redistCollGain, uint256 accruedInterest, uint256 recordedDebt, uint256 annualInterestRate, uint256 accruedBatchManagementFee, uint256 weightedRecordedDebt, uint256 lastInterestRateAdjTime)"
4671
6082
  ]);
4672
- HINT_HELPERS_ABI = parseAbi18([
6083
+ HINT_HELPERS_ABI = parseAbi21([
4673
6084
  "function getApproxHint(uint256 _collIndex, uint256 _interestRate, uint256 _numTrials, uint256 _inputRandomSeed) external view returns (uint256 hintId, uint256 diff, uint256 latestRandomSeed)"
4674
6085
  ]);
4675
- SORTED_TROVES_ABI = parseAbi18([
6086
+ SORTED_TROVES_ABI = parseAbi21([
4676
6087
  "function findInsertPosition(uint256 _annualInterestRate, uint256 _prevId, uint256 _nextId) external view returns (uint256 prevId, uint256 nextId)"
4677
6088
  ]);
4678
6089
  FelixCdpAdapter = class {
@@ -4700,7 +6111,7 @@ var init_dist3 = __esm({
4700
6111
  if (!this.hintHelpers || !this.sortedTroves || !this.rpcUrl) {
4701
6112
  return [0n, 0n];
4702
6113
  }
4703
- const client = createPublicClient13({ transport: http13(this.rpcUrl) });
6114
+ const client = createPublicClient16({ transport: http16(this.rpcUrl) });
4704
6115
  const approxResult = await client.readContract({
4705
6116
  address: this.hintHelpers,
4706
6117
  abi: HINT_HELPERS_ABI,
@@ -4723,7 +6134,7 @@ var init_dist3 = __esm({
4723
6134
  const interestRate = 50000000000000000n;
4724
6135
  const [upperHint, lowerHint] = await this.getHints(interestRate);
4725
6136
  const hasHints = upperHint !== 0n || lowerHint !== 0n;
4726
- const data = encodeFunctionData17({
6137
+ const data = encodeFunctionData20({
4727
6138
  abi: BORROWER_OPS_ABI,
4728
6139
  functionName: "openTrove",
4729
6140
  args: [
@@ -4752,7 +6163,7 @@ var init_dist3 = __esm({
4752
6163
  async buildAdjust(params) {
4753
6164
  const collChange = params.collateral_delta ?? 0n;
4754
6165
  const debtChange = params.debt_delta ?? 0n;
4755
- const data = encodeFunctionData17({
6166
+ const data = encodeFunctionData20({
4756
6167
  abi: BORROWER_OPS_ABI,
4757
6168
  functionName: "adjustTrove",
4758
6169
  args: [
@@ -4775,7 +6186,7 @@ var init_dist3 = __esm({
4775
6186
  };
4776
6187
  }
4777
6188
  async buildClose(params) {
4778
- const data = encodeFunctionData17({
6189
+ const data = encodeFunctionData20({
4779
6190
  abi: BORROWER_OPS_ABI,
4780
6191
  functionName: "closeTrove",
4781
6192
  args: [params.cdp_id]
@@ -4791,7 +6202,7 @@ var init_dist3 = __esm({
4791
6202
  async getCdpInfo(cdpId) {
4792
6203
  if (!this.rpcUrl) throw DefiError.rpcError(`[${this.protocolName}] getCdpInfo requires RPC \u2014 set HYPEREVM_RPC_URL`);
4793
6204
  if (!this.troveManager) throw DefiError.contractError(`[${this.protocolName}] trove_manager contract not configured`);
4794
- const client = createPublicClient13({ transport: http13(this.rpcUrl) });
6205
+ const client = createPublicClient16({ transport: http16(this.rpcUrl) });
4795
6206
  const data = await client.readContract({
4796
6207
  address: this.troveManager,
4797
6208
  abi: TROVE_MANAGER_ABI,
@@ -4809,13 +6220,13 @@ var init_dist3 = __esm({
4809
6220
  protocol: this.protocolName,
4810
6221
  cdp_id: cdpId,
4811
6222
  collateral: {
4812
- token: zeroAddress8,
6223
+ token: zeroAddress11,
4813
6224
  symbol: "WHYPE",
4814
6225
  amount: entireColl,
4815
6226
  decimals: 18
4816
6227
  },
4817
6228
  debt: {
4818
- token: zeroAddress8,
6229
+ token: zeroAddress11,
4819
6230
  symbol: "feUSD",
4820
6231
  amount: entireDebt,
4821
6232
  decimals: 18
@@ -4824,7 +6235,7 @@ var init_dist3 = __esm({
4824
6235
  };
4825
6236
  }
4826
6237
  };
4827
- PRICE_FEED_ABI = parseAbi19([
6238
+ PRICE_FEED_ABI = parseAbi222([
4828
6239
  "function fetchPrice() external view returns (uint256 price, bool isNewOracleFailureDetected)",
4829
6240
  "function lastGoodPrice() external view returns (uint256)"
4830
6241
  ]);
@@ -4850,7 +6261,7 @@ var init_dist3 = __esm({
4850
6261
  if (asset !== this.asset && this.asset !== "0x0000000000000000000000000000000000000000") {
4851
6262
  throw DefiError.unsupported(`[${this.protocolName}] Felix PriceFeed only supports asset ${this.asset}`);
4852
6263
  }
4853
- const client = createPublicClient14({ transport: http14(this.rpcUrl) });
6264
+ const client = createPublicClient17({ transport: http17(this.rpcUrl) });
4854
6265
  let priceVal;
4855
6266
  try {
4856
6267
  const result = await client.readContract({
@@ -4889,7 +6300,7 @@ var init_dist3 = __esm({
4889
6300
  return results;
4890
6301
  }
4891
6302
  };
4892
- ERC4626_ABI = parseAbi20([
6303
+ ERC4626_ABI = parseAbi23([
4893
6304
  "function asset() external view returns (address)",
4894
6305
  "function totalAssets() external view returns (uint256)",
4895
6306
  "function totalSupply() external view returns (uint256)",
@@ -4913,7 +6324,7 @@ var init_dist3 = __esm({
4913
6324
  return this.protocolName;
4914
6325
  }
4915
6326
  async buildDeposit(assets, receiver) {
4916
- const data = encodeFunctionData18({
6327
+ const data = encodeFunctionData21({
4917
6328
  abi: ERC4626_ABI,
4918
6329
  functionName: "deposit",
4919
6330
  args: [assets, receiver]
@@ -4927,7 +6338,7 @@ var init_dist3 = __esm({
4927
6338
  };
4928
6339
  }
4929
6340
  async buildWithdraw(assets, receiver, owner) {
4930
- const data = encodeFunctionData18({
6341
+ const data = encodeFunctionData21({
4931
6342
  abi: ERC4626_ABI,
4932
6343
  functionName: "withdraw",
4933
6344
  args: [assets, receiver, owner]
@@ -4942,7 +6353,7 @@ var init_dist3 = __esm({
4942
6353
  }
4943
6354
  async totalAssets() {
4944
6355
  if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
4945
- const client = createPublicClient15({ transport: http15(this.rpcUrl) });
6356
+ const client = createPublicClient18({ transport: http18(this.rpcUrl) });
4946
6357
  return client.readContract({
4947
6358
  address: this.vaultAddress,
4948
6359
  abi: ERC4626_ABI,
@@ -4953,7 +6364,7 @@ var init_dist3 = __esm({
4953
6364
  }
4954
6365
  async convertToShares(assets) {
4955
6366
  if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
4956
- const client = createPublicClient15({ transport: http15(this.rpcUrl) });
6367
+ const client = createPublicClient18({ transport: http18(this.rpcUrl) });
4957
6368
  return client.readContract({
4958
6369
  address: this.vaultAddress,
4959
6370
  abi: ERC4626_ABI,
@@ -4965,7 +6376,7 @@ var init_dist3 = __esm({
4965
6376
  }
4966
6377
  async convertToAssets(shares) {
4967
6378
  if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
4968
- const client = createPublicClient15({ transport: http15(this.rpcUrl) });
6379
+ const client = createPublicClient18({ transport: http18(this.rpcUrl) });
4969
6380
  return client.readContract({
4970
6381
  address: this.vaultAddress,
4971
6382
  abi: ERC4626_ABI,
@@ -4977,7 +6388,7 @@ var init_dist3 = __esm({
4977
6388
  }
4978
6389
  async getVaultInfo() {
4979
6390
  if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
4980
- const client = createPublicClient15({ transport: http15(this.rpcUrl) });
6391
+ const client = createPublicClient18({ transport: http18(this.rpcUrl) });
4981
6392
  const [totalAssets, totalSupply, asset] = await Promise.all([
4982
6393
  client.readContract({ address: this.vaultAddress, abi: ERC4626_ABI, functionName: "totalAssets" }).catch((e) => {
4983
6394
  throw DefiError.rpcError(`[${this.protocolName}] totalAssets failed: ${e}`);
@@ -4998,7 +6409,7 @@ var init_dist3 = __esm({
4998
6409
  };
4999
6410
  }
5000
6411
  };
5001
- GENERIC_LST_ABI = parseAbi21([
6412
+ GENERIC_LST_ABI = parseAbi24([
5002
6413
  "function stake() external payable returns (uint256)",
5003
6414
  "function unstake(uint256 amount) external returns (uint256)"
5004
6415
  ]);
@@ -5015,7 +6426,7 @@ var init_dist3 = __esm({
5015
6426
  return this.protocolName;
5016
6427
  }
5017
6428
  async buildStake(params) {
5018
- const data = encodeFunctionData19({ abi: GENERIC_LST_ABI, functionName: "stake" });
6429
+ const data = encodeFunctionData222({ abi: GENERIC_LST_ABI, functionName: "stake" });
5019
6430
  return {
5020
6431
  description: `[${this.protocolName}] Stake ${params.amount} HYPE`,
5021
6432
  to: this.staking,
@@ -5025,7 +6436,7 @@ var init_dist3 = __esm({
5025
6436
  };
5026
6437
  }
5027
6438
  async buildUnstake(params) {
5028
- const data = encodeFunctionData19({
6439
+ const data = encodeFunctionData222({
5029
6440
  abi: GENERIC_LST_ABI,
5030
6441
  functionName: "unstake",
5031
6442
  args: [params.amount]
@@ -5042,11 +6453,11 @@ var init_dist3 = __esm({
5042
6453
  throw DefiError.unsupported(`[${this.protocolName}] getInfo requires RPC`);
5043
6454
  }
5044
6455
  };
5045
- STHYPE_ABI = parseAbi222([
6456
+ STHYPE_ABI = parseAbi25([
5046
6457
  "function submit(address referral) external payable returns (uint256)",
5047
6458
  "function requestWithdrawals(uint256[] amounts, address owner) external returns (uint256[] requestIds)"
5048
6459
  ]);
5049
- ERC20_ABI3 = parseAbi222([
6460
+ ERC20_ABI3 = parseAbi25([
5050
6461
  "function totalSupply() external view returns (uint256)"
5051
6462
  ]);
5052
6463
  StHypeAdapter = class {
@@ -5066,10 +6477,10 @@ var init_dist3 = __esm({
5066
6477
  return this.protocolName;
5067
6478
  }
5068
6479
  async buildStake(params) {
5069
- const data = encodeFunctionData20({
6480
+ const data = encodeFunctionData23({
5070
6481
  abi: STHYPE_ABI,
5071
6482
  functionName: "submit",
5072
- args: [zeroAddress9]
6483
+ args: [zeroAddress12]
5073
6484
  });
5074
6485
  return {
5075
6486
  description: `[${this.protocolName}] Stake ${params.amount} HYPE for stHYPE`,
@@ -5080,7 +6491,7 @@ var init_dist3 = __esm({
5080
6491
  };
5081
6492
  }
5082
6493
  async buildUnstake(params) {
5083
- const data = encodeFunctionData20({
6494
+ const data = encodeFunctionData23({
5084
6495
  abi: STHYPE_ABI,
5085
6496
  functionName: "requestWithdrawals",
5086
6497
  args: [[params.amount], params.recipient]
@@ -5095,7 +6506,7 @@ var init_dist3 = __esm({
5095
6506
  }
5096
6507
  async getInfo() {
5097
6508
  if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
5098
- const client = createPublicClient16({ transport: http16(this.rpcUrl) });
6509
+ const client = createPublicClient19({ transport: http19(this.rpcUrl) });
5099
6510
  const tokenAddr = this.sthypeToken ?? this.staking;
5100
6511
  const totalSupply = await client.readContract({
5101
6512
  address: tokenAddr,
@@ -5106,19 +6517,19 @@ var init_dist3 = __esm({
5106
6517
  });
5107
6518
  return {
5108
6519
  protocol: this.protocolName,
5109
- staked_token: zeroAddress9,
6520
+ staked_token: zeroAddress12,
5110
6521
  liquid_token: tokenAddr,
5111
6522
  exchange_rate: 1,
5112
6523
  total_staked: totalSupply
5113
6524
  };
5114
6525
  }
5115
6526
  };
5116
- KINETIQ_ABI = parseAbi23([
6527
+ KINETIQ_ABI = parseAbi26([
5117
6528
  "function stake() external payable returns (uint256)",
5118
6529
  "function requestUnstake(uint256 amount) external returns (uint256)",
5119
6530
  "function totalStaked() external view returns (uint256)"
5120
6531
  ]);
5121
- ORACLE_ABI3 = parseAbi23([
6532
+ ORACLE_ABI3 = parseAbi26([
5122
6533
  "function getAssetPrice(address asset) external view returns (uint256)"
5123
6534
  ]);
5124
6535
  WHYPE = "0x5555555555555555555555555555555555555555";
@@ -5140,7 +6551,7 @@ var init_dist3 = __esm({
5140
6551
  return this.protocolName;
5141
6552
  }
5142
6553
  async buildStake(params) {
5143
- const data = encodeFunctionData21({ abi: KINETIQ_ABI, functionName: "stake" });
6554
+ const data = encodeFunctionData24({ abi: KINETIQ_ABI, functionName: "stake" });
5144
6555
  return {
5145
6556
  description: `[${this.protocolName}] Stake ${params.amount} HYPE for kHYPE`,
5146
6557
  to: this.staking,
@@ -5150,7 +6561,7 @@ var init_dist3 = __esm({
5150
6561
  };
5151
6562
  }
5152
6563
  async buildUnstake(params) {
5153
- const data = encodeFunctionData21({
6564
+ const data = encodeFunctionData24({
5154
6565
  abi: KINETIQ_ABI,
5155
6566
  functionName: "requestUnstake",
5156
6567
  args: [params.amount]
@@ -5165,7 +6576,7 @@ var init_dist3 = __esm({
5165
6576
  }
5166
6577
  async getInfo() {
5167
6578
  if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
5168
- const client = createPublicClient17({ transport: http17(this.rpcUrl) });
6579
+ const client = createPublicClient20({ transport: http20(this.rpcUrl) });
5169
6580
  const totalStaked = await client.readContract({
5170
6581
  address: this.staking,
5171
6582
  abi: KINETIQ_ABI,
@@ -5180,7 +6591,7 @@ var init_dist3 = __esm({
5180
6591
  const rateF64 = hypePrice > 0n && khypePrice > 0n ? Number(khypePrice * 10n ** 18n / hypePrice) / 1e18 : 1;
5181
6592
  return {
5182
6593
  protocol: this.protocolName,
5183
- staked_token: zeroAddress10,
6594
+ staked_token: zeroAddress13,
5184
6595
  liquid_token: this.liquidToken,
5185
6596
  exchange_rate: rateF64,
5186
6597
  total_staked: totalStaked
@@ -5236,7 +6647,7 @@ var init_dist3 = __esm({
5236
6647
  );
5237
6648
  }
5238
6649
  };
5239
- HLP_ABI = parseAbi24([
6650
+ HLP_ABI = parseAbi27([
5240
6651
  "function deposit(uint256 amount) external returns (uint256)",
5241
6652
  "function withdraw(uint256 shares) external returns (uint256)"
5242
6653
  ]);
@@ -5253,7 +6664,7 @@ var init_dist3 = __esm({
5253
6664
  return this.protocolName;
5254
6665
  }
5255
6666
  async buildOpenPosition(params) {
5256
- const data = encodeFunctionData222({
6667
+ const data = encodeFunctionData25({
5257
6668
  abi: HLP_ABI,
5258
6669
  functionName: "deposit",
5259
6670
  args: [params.collateral]
@@ -5267,7 +6678,7 @@ var init_dist3 = __esm({
5267
6678
  };
5268
6679
  }
5269
6680
  async buildClosePosition(params) {
5270
- const data = encodeFunctionData222({
6681
+ const data = encodeFunctionData25({
5271
6682
  abi: HLP_ABI,
5272
6683
  functionName: "withdraw",
5273
6684
  args: [params.size]
@@ -5302,7 +6713,7 @@ var init_dist3 = __esm({
5302
6713
  );
5303
6714
  }
5304
6715
  };
5305
- RYSK_ABI = parseAbi25([
6716
+ RYSK_ABI = parseAbi28([
5306
6717
  "function openOption(address underlying, uint256 strikePrice, uint256 expiry, bool isCall, uint256 amount) external returns (uint256 premium)",
5307
6718
  "function closeOption(address underlying, uint256 strikePrice, uint256 expiry, bool isCall, uint256 amount) external returns (uint256 payout)"
5308
6719
  ]);
@@ -5319,7 +6730,7 @@ var init_dist3 = __esm({
5319
6730
  return this.protocolName;
5320
6731
  }
5321
6732
  async buildBuy(params) {
5322
- const data = encodeFunctionData23({
6733
+ const data = encodeFunctionData26({
5323
6734
  abi: RYSK_ABI,
5324
6735
  functionName: "openOption",
5325
6736
  args: [
@@ -5339,7 +6750,7 @@ var init_dist3 = __esm({
5339
6750
  };
5340
6751
  }
5341
6752
  async buildSell(params) {
5342
- const data = encodeFunctionData23({
6753
+ const data = encodeFunctionData26({
5343
6754
  abi: RYSK_ABI,
5344
6755
  functionName: "closeOption",
5345
6756
  args: [
@@ -5380,7 +6791,7 @@ var init_dist3 = __esm({
5380
6791
  );
5381
6792
  }
5382
6793
  };
5383
- ERC721_ABI = parseAbi26([
6794
+ ERC721_ABI = parseAbi29([
5384
6795
  "function name() returns (string)",
5385
6796
  "function symbol() returns (string)",
5386
6797
  "function totalSupply() returns (uint256)",
@@ -5400,7 +6811,7 @@ var init_dist3 = __esm({
5400
6811
  }
5401
6812
  async getCollectionInfo(collection) {
5402
6813
  if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
5403
- const client = createPublicClient18({ transport: http18(this.rpcUrl) });
6814
+ const client = createPublicClient21({ transport: http21(this.rpcUrl) });
5404
6815
  const [collectionName, symbol, totalSupply] = await Promise.all([
5405
6816
  client.readContract({ address: collection, abi: ERC721_ABI, functionName: "name" }).catch((e) => {
5406
6817
  throw DefiError.rpcError(`[${this.protocolName}] name failed: ${e}`);
@@ -5419,7 +6830,7 @@ var init_dist3 = __esm({
5419
6830
  }
5420
6831
  async getTokenInfo(collection, tokenId) {
5421
6832
  if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
5422
- const client = createPublicClient18({ transport: http18(this.rpcUrl) });
6833
+ const client = createPublicClient21({ transport: http21(this.rpcUrl) });
5423
6834
  const [owner, tokenUri] = await Promise.all([
5424
6835
  client.readContract({ address: collection, abi: ERC721_ABI, functionName: "ownerOf", args: [tokenId] }).catch((e) => {
5425
6836
  throw DefiError.rpcError(`[${this.protocolName}] ownerOf failed: ${e}`);
@@ -5435,7 +6846,7 @@ var init_dist3 = __esm({
5435
6846
  }
5436
6847
  async getBalance(owner, collection) {
5437
6848
  if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
5438
- const client = createPublicClient18({ transport: http18(this.rpcUrl) });
6849
+ const client = createPublicClient21({ transport: http21(this.rpcUrl) });
5439
6850
  return client.readContract({ address: collection, abi: ERC721_ABI, functionName: "balanceOf", args: [owner] }).catch((e) => {
5440
6851
  throw DefiError.rpcError(`[${this.protocolName}] balanceOf failed: ${e}`);
5441
6852
  });
@@ -5492,9 +6903,9 @@ import { z } from "zod";
5492
6903
  // src/executor.ts
5493
6904
  init_dist2();
5494
6905
  init_dist2();
5495
- import { createPublicClient as createPublicClient19, createWalletClient, http as http19, parseAbi as parseAbi27, encodeFunctionData as encodeFunctionData24 } from "viem";
6906
+ import { createPublicClient as createPublicClient23, createWalletClient, http as http23, parseAbi as parseAbi30, encodeFunctionData as encodeFunctionData27 } from "viem";
5496
6907
  import { privateKeyToAccount } from "viem/accounts";
5497
- var ERC20_ABI4 = parseAbi27([
6908
+ var ERC20_ABI4 = parseAbi30([
5498
6909
  "function allowance(address owner, address spender) external view returns (uint256)",
5499
6910
  "function approve(address spender, uint256 amount) external returns (bool)"
5500
6911
  ]);
@@ -5530,7 +6941,7 @@ var Executor = class _Executor {
5530
6941
  ` Approving ${amount} of ${token} for ${spender}...
5531
6942
  `
5532
6943
  );
5533
- const approveData = encodeFunctionData24({
6944
+ const approveData = encodeFunctionData27({
5534
6945
  abi: ERC20_ABI4,
5535
6946
  functionName: "approve",
5536
6947
  args: [spender, amount]
@@ -5573,7 +6984,7 @@ var Executor = class _Executor {
5573
6984
  /** Fetch EIP-1559 fee params from the network. Returns [maxFeePerGas, maxPriorityFeePerGas]. */
5574
6985
  async fetchEip1559Fees(rpcUrl) {
5575
6986
  try {
5576
- const client = createPublicClient19({ transport: http19(rpcUrl) });
6987
+ const client = createPublicClient23({ transport: http23(rpcUrl) });
5577
6988
  const gasPrice = await client.getGasPrice();
5578
6989
  let priorityFee = DEFAULT_PRIORITY_FEE_WEI;
5579
6990
  try {
@@ -5589,7 +7000,7 @@ var Executor = class _Executor {
5589
7000
  /** Estimate gas dynamically with buffer, falling back to a hardcoded estimate */
5590
7001
  async estimateGasWithBuffer(rpcUrl, tx, from) {
5591
7002
  try {
5592
- const client = createPublicClient19({ transport: http19(rpcUrl) });
7003
+ const client = createPublicClient23({ transport: http23(rpcUrl) });
5593
7004
  const estimated = await client.estimateGas({
5594
7005
  to: tx.to,
5595
7006
  data: tx.data,
@@ -5601,8 +7012,11 @@ var Executor = class _Executor {
5601
7012
  return buffered > MAX_GAS_LIMIT ? MAX_GAS_LIMIT : buffered;
5602
7013
  }
5603
7014
  } catch {
7015
+ if (tx.gas_estimate) {
7016
+ return _Executor.applyGasBuffer(BigInt(tx.gas_estimate));
7017
+ }
5604
7018
  }
5605
- return tx.gas_estimate ? BigInt(tx.gas_estimate) : 0n;
7019
+ return 0n;
5606
7020
  }
5607
7021
  /** Simulate a transaction via eth_call + eth_estimateGas */
5608
7022
  async simulate(tx) {
@@ -5610,7 +7024,7 @@ var Executor = class _Executor {
5610
7024
  if (!rpcUrl) {
5611
7025
  throw DefiError.rpcError("No RPC URL \u2014 cannot simulate. Set HYPEREVM_RPC_URL.");
5612
7026
  }
5613
- const client = createPublicClient19({ transport: http19(rpcUrl) });
7027
+ const client = createPublicClient23({ transport: http23(rpcUrl) });
5614
7028
  const privateKey = process.env["DEFI_PRIVATE_KEY"];
5615
7029
  const from = privateKey ? privateKeyToAccount(privateKey).address : "0x0000000000000000000000000000000000000001";
5616
7030
  if (tx.approvals && tx.approvals.length > 0) {
@@ -5723,8 +7137,33 @@ var Executor = class _Executor {
5723
7137
  if (!rpcUrl) {
5724
7138
  throw DefiError.rpcError("No RPC URL configured for broadcasting");
5725
7139
  }
5726
- const publicClient = createPublicClient19({ transport: http19(rpcUrl) });
5727
- const walletClient = createWalletClient({ account, transport: http19(rpcUrl) });
7140
+ const publicClient = createPublicClient23({ transport: http23(rpcUrl) });
7141
+ const walletClient = createWalletClient({ account, transport: http23(rpcUrl) });
7142
+ if (tx.pre_txs && tx.pre_txs.length > 0) {
7143
+ for (const preTx of tx.pre_txs) {
7144
+ process.stderr.write(` Pre-tx: ${preTx.description}...
7145
+ `);
7146
+ const preGas = await this.estimateGasWithBuffer(rpcUrl, preTx, account.address);
7147
+ const preTxHash = await walletClient.sendTransaction({
7148
+ chain: null,
7149
+ to: preTx.to,
7150
+ data: preTx.data,
7151
+ value: preTx.value,
7152
+ gas: preGas > 0n ? preGas : void 0
7153
+ });
7154
+ const preTxUrl = this.explorerUrl ? `${this.explorerUrl}/tx/${preTxHash}` : void 0;
7155
+ process.stderr.write(` Pre-tx sent: ${preTxHash}
7156
+ `);
7157
+ if (preTxUrl) process.stderr.write(` Explorer: ${preTxUrl}
7158
+ `);
7159
+ const preReceipt = await publicClient.waitForTransactionReceipt({ hash: preTxHash });
7160
+ if (preReceipt.status !== "success") {
7161
+ throw new DefiError("TX_FAILED", `Pre-transaction failed: ${preTx.description}`);
7162
+ }
7163
+ process.stderr.write(` Pre-tx confirmed
7164
+ `);
7165
+ }
7166
+ }
5728
7167
  if (tx.approvals && tx.approvals.length > 0) {
5729
7168
  for (const approval of tx.approvals) {
5730
7169
  await this.checkAndApprove(
@@ -5762,20 +7201,37 @@ var Executor = class _Executor {
5762
7201
  process.stderr.write("Waiting for confirmation...\n");
5763
7202
  const receipt = await publicClient.waitForTransactionReceipt({ hash: txHash });
5764
7203
  const status = receipt.status === "success" ? "confirmed" : "failed";
7204
+ let mintedTokenId;
7205
+ if (receipt.status === "success" && receipt.logs) {
7206
+ const TRANSFER_TOPIC = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef";
7207
+ const ZERO_TOPIC = "0x0000000000000000000000000000000000000000000000000000000000000000";
7208
+ for (const log of receipt.logs) {
7209
+ if (log.topics.length >= 4 && log.topics[0] === TRANSFER_TOPIC && log.topics[1] === ZERO_TOPIC) {
7210
+ mintedTokenId = BigInt(log.topics[3]).toString();
7211
+ break;
7212
+ }
7213
+ }
7214
+ }
7215
+ const details = {
7216
+ to: tx.to,
7217
+ from: account.address,
7218
+ block_number: receipt.blockNumber?.toString(),
7219
+ gas_limit: gasLimit.toString(),
7220
+ gas_used: receipt.gasUsed?.toString(),
7221
+ explorer_url: txUrl,
7222
+ mode: "broadcast"
7223
+ };
7224
+ if (mintedTokenId) {
7225
+ details.minted_token_id = mintedTokenId;
7226
+ process.stderr.write(` Minted NFT tokenId: ${mintedTokenId}
7227
+ `);
7228
+ }
5765
7229
  return {
5766
7230
  tx_hash: txHash,
5767
7231
  status,
5768
7232
  gas_used: receipt.gasUsed ? Number(receipt.gasUsed) : void 0,
5769
7233
  description: tx.description,
5770
- details: {
5771
- to: tx.to,
5772
- from: account.address,
5773
- block_number: receipt.blockNumber?.toString(),
5774
- gas_limit: gasLimit.toString(),
5775
- gas_used: receipt.gasUsed?.toString(),
5776
- explorer_url: txUrl,
5777
- mode: "broadcast"
5778
- }
7234
+ details
5779
7235
  };
5780
7236
  }
5781
7237
  };
@@ -6363,8 +7819,8 @@ server.tool(
6363
7819
  const user = address;
6364
7820
  const { ProtocolCategory: ProtocolCategory2, multicallRead: multicallRead2 } = await Promise.resolve().then(() => (init_dist2(), dist_exports));
6365
7821
  const { createLending: _createLending } = await Promise.resolve().then(() => (init_dist3(), dist_exports2));
6366
- const { encodeFunctionData: encodeFunctionData25, parseAbi: parseAbi28 } = await import("viem");
6367
- const POOL_ABI3 = parseAbi28([
7822
+ const { encodeFunctionData: encodeFunctionData28, parseAbi: parseAbi31 } = await import("viem");
7823
+ const POOL_ABI3 = parseAbi31([
6368
7824
  "function getUserAccountData(address user) external view returns (uint256 totalCollateralBase, uint256 totalDebtBase, uint256 availableBorrowsBase, uint256 currentLiquidationThreshold, uint256 ltv, uint256 healthFactor)"
6369
7825
  ]);
6370
7826
  const lendingProtos = registry.getProtocolsForChain(chainName).filter((p) => p.category === ProtocolCategory2.Lending);
@@ -6373,7 +7829,7 @@ server.tool(
6373
7829
  const poolAddr = p.contracts?.pool;
6374
7830
  if (!poolAddr) continue;
6375
7831
  try {
6376
- const callData = encodeFunctionData25({ abi: POOL_ABI3, functionName: "getUserAccountData", args: [user] });
7832
+ const callData = encodeFunctionData28({ abi: POOL_ABI3, functionName: "getUserAccountData", args: [user] });
6377
7833
  const results = await multicallRead2(rpcUrl, [[poolAddr, callData]]);
6378
7834
  const raw = results[0];
6379
7835
  if (!raw || raw.length < 2 + 6 * 64) continue;