@continuumdao/ctm-mpc-defi 0.2.43 → 0.2.45

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.
Files changed (33) hide show
  1. package/dist/agent/catalog.cjs +276 -11
  2. package/dist/agent/catalog.cjs.map +1 -1
  3. package/dist/agent/catalog.d.ts +780 -9
  4. package/dist/agent/catalog.js +268 -12
  5. package/dist/agent/catalog.js.map +1 -1
  6. package/dist/agent/skills/aave-v4/SKILL.md +9 -1
  7. package/dist/agent/skills/euler-v2/SKILL.md +9 -0
  8. package/dist/agent/skills/hyperliquid/SKILL.md +32 -2
  9. package/dist/agent/skills/morpho/SKILL.md +8 -2
  10. package/dist/agent/skills/yield-compare/SKILL.md +4 -1
  11. package/dist/merklDistributor-CdqtZC9N.d.ts +65 -0
  12. package/dist/multisign-Dr0j9fHm.d.ts +489 -0
  13. package/dist/protocols/evm/aave-v4/index.cjs +207 -2
  14. package/dist/protocols/evm/aave-v4/index.cjs.map +1 -1
  15. package/dist/protocols/evm/aave-v4/index.d.ts +12 -467
  16. package/dist/protocols/evm/aave-v4/index.js +192 -3
  17. package/dist/protocols/evm/aave-v4/index.js.map +1 -1
  18. package/dist/protocols/evm/euler-v2/index.cjs +209 -1
  19. package/dist/protocols/evm/euler-v2/index.cjs.map +1 -1
  20. package/dist/protocols/evm/euler-v2/index.d.ts +9 -1
  21. package/dist/protocols/evm/euler-v2/index.js +208 -2
  22. package/dist/protocols/evm/euler-v2/index.js.map +1 -1
  23. package/dist/protocols/evm/hyperliquid/index.cjs +320 -0
  24. package/dist/protocols/evm/hyperliquid/index.cjs.map +1 -1
  25. package/dist/protocols/evm/hyperliquid/index.d.ts +153 -1
  26. package/dist/protocols/evm/hyperliquid/index.js +303 -1
  27. package/dist/protocols/evm/hyperliquid/index.js.map +1 -1
  28. package/dist/protocols/evm/morpho/index.cjs +169 -1
  29. package/dist/protocols/evm/morpho/index.cjs.map +1 -1
  30. package/dist/protocols/evm/morpho/index.d.ts +9 -1
  31. package/dist/protocols/evm/morpho/index.js +155 -2
  32. package/dist/protocols/evm/morpho/index.js.map +1 -1
  33. package/package.json +1 -1
@@ -1471,6 +1471,40 @@ async function buildEvmMultisignBodyAaveV4MerklClaimRewards(args) {
1471
1471
  })
1472
1472
  });
1473
1473
  }
1474
+ async function buildEvmMultisignBodyAaveV4MerklDistributorClaim(args) {
1475
+ const to = getAddress(args.to);
1476
+ const executor = getAddress(args.executorAddress);
1477
+ return buildEvmMultisignBodyAaveV4OneStep({
1478
+ keyGen: args.keyGen,
1479
+ chainId: args.chainId,
1480
+ rpcUrl: args.rpcUrl,
1481
+ chainDetail: args.chainDetail,
1482
+ useCustomGas: args.useCustomGas,
1483
+ customGasChainDetails: args.customGasChainDetails ?? void 0,
1484
+ purposeText: args.purposeText,
1485
+ purposeSuffix: `Aave v4: 1-tx \u2014 wallet-wide Merkl distributor claim (${args.claimLeafCount} reward(s)).`,
1486
+ executorAddress: executor,
1487
+ v: { to, data: args.data, value: args.valueWei },
1488
+ estimateGasFallback: AAVE_MERKL_CLAIM_ESTIMATE_FALLBACK,
1489
+ buildBatchMeta: (ctx) => ({
1490
+ destinationAddress: to,
1491
+ signatureText: JSON.stringify({
1492
+ kind: "AaveV4",
1493
+ name: "Merkl Distributor claim",
1494
+ claimLeafCount: args.claimLeafCount,
1495
+ chainId: args.chainId,
1496
+ valueWei: args.valueWei.toString(),
1497
+ note: "Wallet-wide Merkl API proofs; Distributor.claim(users,tokens,amounts,proofs)."
1498
+ }),
1499
+ evm: { type: "aave_v4_merkl_distributor_claim", version: 1, chainId: String(args.chainId) },
1500
+ aaveV4: {
1501
+ step: "merkl_distributor_claim",
1502
+ claimLeafCount: args.claimLeafCount,
1503
+ gasBuildClaim: { baseGasUnits: ctx.gasLimit.toString() }
1504
+ }
1505
+ })
1506
+ });
1507
+ }
1474
1508
  async function buildEvmMultisignBodyEulerV2MerklDistributorClaim(args) {
1475
1509
  const to = getAddress(args.to);
1476
1510
  const executor = getAddress(args.executorAddress);
@@ -1575,7 +1609,8 @@ var AAVE_V4_EVM_TYPES = /* @__PURE__ */ new Set([
1575
1609
  "aave_v4_spoke_withdraw",
1576
1610
  "aave_v4_spoke_borrow",
1577
1611
  "aave_v4_spoke_repay",
1578
- "aave_v4_merkl_claim_rewards"
1612
+ "aave_v4_merkl_claim_rewards",
1613
+ "aave_v4_merkl_distributor_claim"
1579
1614
  ]);
1580
1615
  function parseExtraJsonObject(detail) {
1581
1616
  if (!detail) return null;
@@ -2544,6 +2579,158 @@ async function aaveV4FetchMarketSummary(args) {
2544
2579
  }
2545
2580
  return out;
2546
2581
  }
2582
+ var MERKL_API_BASE = "https://api.merkl.xyz";
2583
+ var MERKL_DISTRIBUTOR_ADDRESS = "0x3Ef3D8bA38EBe18DB133cEc108f4D14CE00Dd9Ae";
2584
+ var MERKL_DISTRIBUTOR_CLAIM_GAS_FALLBACK = 500000n;
2585
+ var MERKL_REWARDS_NOTES = "Wallet-wide Merkl on this chain (not protocol-filtered). Other venues\u2019 campaigns can appear. Claims the first Merkle root batch; call again if additionalRoots > 0. rEUL is omitted (Euler unlock flow). Merkl updates every 8\u201312 hours.";
2586
+ function normHex32(p) {
2587
+ const s = (p ?? "").trim();
2588
+ if (!s) return null;
2589
+ const x = s.startsWith("0x") ? s : `0x${s}`;
2590
+ if (!/^0x[0-9a-fA-F]{64}$/.test(x)) return null;
2591
+ return x;
2592
+ }
2593
+ function merklUserRewardsUrl(addr, chainId) {
2594
+ return `${MERKL_API_BASE}/v4/users/${encodeURIComponent(addr)}/rewards?chainId=${chainId}`;
2595
+ }
2596
+ async function loadMerklUserRewardsJson(args) {
2597
+ const addr = getAddress(args.user);
2598
+ const url = merklUserRewardsUrl(addr, args.chainId);
2599
+ const res = await fetch(url, { cache: "no-store" });
2600
+ if (!res.ok) {
2601
+ let detail = `Merkl API error ${res.status}`;
2602
+ try {
2603
+ const j = await res.json();
2604
+ if (j?.error) {
2605
+ detail = j.details ? `${j.error}: ${j.details}` : j.error;
2606
+ }
2607
+ } catch {
2608
+ }
2609
+ throw new Error(detail);
2610
+ }
2611
+ return res.json();
2612
+ }
2613
+ function parseMerklUserRewardsToLeaves(raw, args) {
2614
+ const addr = getAddress(args.user);
2615
+ if (!Array.isArray(raw)) {
2616
+ throw new Error("Merkl API returned an unexpected rewards shape.");
2617
+ }
2618
+ const collected = [];
2619
+ for (const block of raw) {
2620
+ for (const rw of block.rewards ?? []) {
2621
+ const root = (rw.root ?? "").trim();
2622
+ const dist = rw.distributionChainId;
2623
+ if (!root || dist !== args.chainId) continue;
2624
+ let recipient;
2625
+ try {
2626
+ recipient = getAddress((rw.recipient ?? "").trim());
2627
+ } catch {
2628
+ continue;
2629
+ }
2630
+ if (recipient !== addr) continue;
2631
+ let amt = 0n;
2632
+ let clm = 0n;
2633
+ try {
2634
+ amt = BigInt((rw.amount ?? "0").toString().trim() || "0");
2635
+ clm = BigInt((rw.claimed ?? "0").toString().trim() || "0");
2636
+ } catch {
2637
+ continue;
2638
+ }
2639
+ if (amt <= clm) continue;
2640
+ let tokenAddr;
2641
+ try {
2642
+ tokenAddr = getAddress((rw.token?.address ?? "").trim());
2643
+ } catch {
2644
+ continue;
2645
+ }
2646
+ const proofsRaw = rw.proofs ?? [];
2647
+ const proofs = [];
2648
+ for (const p of proofsRaw) {
2649
+ const h = normHex32(String(p));
2650
+ if (!h) continue;
2651
+ proofs.push(h);
2652
+ }
2653
+ if (proofsRaw.length > 0 && proofs.length !== proofsRaw.length) continue;
2654
+ const sym = (rw.token?.symbol ?? "").trim() || "\u2014";
2655
+ let dec = 18;
2656
+ try {
2657
+ const d = Number(rw.token?.decimals ?? 18);
2658
+ if (Number.isFinite(d) && d >= 0 && d <= 36) dec = d;
2659
+ } catch {
2660
+ dec = 18;
2661
+ }
2662
+ collected.push({ root, token: tokenAddr, amountWei: amt, proofs, symbol: sym, decimals: dec });
2663
+ }
2664
+ }
2665
+ return collected;
2666
+ }
2667
+ function selectFirstRootMerklLeaves(collected) {
2668
+ if (collected.length === 0) return [];
2669
+ const root0 = collected[0].root;
2670
+ return collected.filter((x) => x.root === root0);
2671
+ }
2672
+ function isMerklRewardEulLeaf(leaf) {
2673
+ const s = leaf.symbol.trim().toLowerCase().replace(/\s+/g, " ").trim();
2674
+ return s === "reul" || s === "reward eul";
2675
+ }
2676
+ function selectWalletWideMerklClaimLeaves(collected) {
2677
+ return selectFirstRootMerklLeaves(collected.filter((l) => !isMerklRewardEulLeaf(l)));
2678
+ }
2679
+ async function fetchAllMerklDistributorClaimLeaves(args) {
2680
+ const raw = await loadMerklUserRewardsJson(args);
2681
+ return parseMerklUserRewardsToLeaves(raw, args);
2682
+ }
2683
+ function encodeMerklDistributorClaimData(args) {
2684
+ if (args.leaves.length === 0) throw new Error("No Merkl claim leaves.");
2685
+ const u = getAddress(args.user);
2686
+ const abi = parseAbi([
2687
+ "function claim(address[] users, address[] tokens, uint256[] amounts, bytes32[][] proofs) external"
2688
+ ]);
2689
+ const users = args.leaves.map(() => u);
2690
+ const tokens = args.leaves.map((l) => l.token);
2691
+ const amounts = args.leaves.map((l) => l.amountWei);
2692
+ const proofs = args.leaves.map((l) => [...l.proofs]);
2693
+ return encodeFunctionData({
2694
+ abi,
2695
+ functionName: "claim",
2696
+ args: [users, tokens, amounts, proofs]
2697
+ });
2698
+ }
2699
+ function merklLeafToRow(leaf) {
2700
+ return {
2701
+ symbol: leaf.symbol,
2702
+ token: leaf.token,
2703
+ amountHuman: formatUnits(leaf.amountWei, leaf.decimals),
2704
+ amountWei: leaf.amountWei.toString(),
2705
+ decimals: leaf.decimals,
2706
+ root: leaf.root
2707
+ };
2708
+ }
2709
+ async function fetchMerklRewardsSummary(args) {
2710
+ const user = getAddress(args.user);
2711
+ const chainId = args.chainId;
2712
+ const all = await fetchAllMerklDistributorClaimLeaves({ chainId, user });
2713
+ const skippedReulCount = all.filter(isMerklRewardEulLeaf).length;
2714
+ const display = all.filter((l) => !isMerklRewardEulLeaf(l));
2715
+ const firstRoot = selectFirstRootMerklLeaves(display);
2716
+ const roots = new Set(display.map((l) => l.root));
2717
+ return {
2718
+ chainId,
2719
+ user,
2720
+ distributor: MERKL_DISTRIBUTOR_ADDRESS,
2721
+ claimable: display.map(merklLeafToRow),
2722
+ claimableCount: display.length,
2723
+ firstRootClaimableCount: firstRoot.length,
2724
+ additionalRoots: Math.max(0, roots.size - (firstRoot.length > 0 ? 1 : 0)),
2725
+ skippedReulCount,
2726
+ notes: MERKL_REWARDS_NOTES
2727
+ };
2728
+ }
2729
+
2730
+ // src/protocols/evm/aave-v4/merklRewards.ts
2731
+ async function aaveV4FetchMerklRewardsSummary(args) {
2732
+ return fetchMerklRewardsSummary(args);
2733
+ }
2547
2734
 
2548
2735
  // src/protocols/evm/aave-v4/index.ts
2549
2736
  var AAVE_V4_PROTOCOL_ID = "aave-v4";
@@ -2560,11 +2747,13 @@ var aaveV4ProtocolModule = {
2560
2747
  { id: "aave-v4.deposit", protocolId: AAVE_V4_PROTOCOL_ID, chainCategory: "evm", description: "Supply to Aave v4 Spoke", commonParams: ["keyGen", "purposeText", "useCustomGas"], params: {} },
2561
2748
  { id: "aave-v4.withdraw", protocolId: AAVE_V4_PROTOCOL_ID, chainCategory: "evm", description: "Withdraw from Spoke", commonParams: ["keyGen", "purposeText", "useCustomGas"], params: {} },
2562
2749
  { id: "aave-v4.borrow", protocolId: AAVE_V4_PROTOCOL_ID, chainCategory: "evm", description: "Borrow from Spoke", commonParams: ["keyGen", "purposeText", "useCustomGas"], params: {} },
2563
- { id: "aave-v4.repay", protocolId: AAVE_V4_PROTOCOL_ID, chainCategory: "evm", description: "Repay Spoke debt", commonParams: ["keyGen", "purposeText", "useCustomGas"], params: {} }
2750
+ { id: "aave-v4.repay", protocolId: AAVE_V4_PROTOCOL_ID, chainCategory: "evm", description: "Repay Spoke debt", commonParams: ["keyGen", "purposeText", "useCustomGas"], params: {} },
2751
+ { id: "aave-v4.fetch-merkl-rewards", protocolId: AAVE_V4_PROTOCOL_ID, chainCategory: "evm", description: "List wallet-wide Merkl claimables on a chain", commonParams: [], params: {} },
2752
+ { id: "aave-v4.merkl-claim", protocolId: AAVE_V4_PROTOCOL_ID, chainCategory: "evm", description: "Claim wallet-wide Merkl rewards", commonParams: ["keyGen", "purposeText", "useCustomGas"], params: {} }
2564
2753
  ]
2565
2754
  };
2566
2755
  registerProtocolModule(aaveV4ProtocolModule);
2567
2756
 
2568
- export { AAVE_V4_GRAPHQL_URL, AAVE_V4_PROTOCOL_ID, AAVE_V4_SPOKE_BORROW_DEFAULT_GAS_UNITS, AAVE_V4_SPOKE_REPAY_DEFAULT_GAS_UNITS, AAVE_V4_SPOKE_SUPPLY_DEFAULT_GAS_UNITS, AAVE_V4_SPOKE_WITHDRAW_DEFAULT_GAS_UNITS, MIN_AAVE_V4_DEPOSIT_GAS_EXEC, aaveAvailableLiquidityDisplay, aaveReadSupplyMetrics, aaveUnderlyingAddressForContext, aaveV4BorrowHealthGate, aaveV4FetchMarketSummary, aaveV4FetchMarketsSummary, aaveV4Gql, aaveV4KeyForNodeAssetRow, aaveV4MarketRowFromHubReserve, aaveV4ProtocolModule, aaveV4RepayHealthGate, aaveV4UiMarketIdForHubName, aaveV4UserHasAvailableBorrowCollateralForContextOnSpoke, aaveV4WithdrawHealthGate, aggregateV4SupplyDisplay, borrowableAssetsFromHubReserves, buildAaveV4BorrowTableRowsFromHub, buildEvmMultisignBodyAaveV4DepositBatch, buildEvmMultisignBodyAaveV4MerklClaimRewards, buildEvmMultisignBodyAaveV4SpokeBorrow, buildEvmMultisignBodyAaveV4SpokeRepay, buildEvmMultisignBodyAaveV4SpokeWithdraw, buildEvmMultisignBodyEulerV2MerklDistributorClaim, buildEvmMultisignBodyEulerV2ReulUnlock, ensureAaveV4ChainTokenCache, fetchAaveV4Chains, fetchAaveV4ClaimRewardsCalldata, fetchAaveV4HubReserves, fetchAaveV4HubsForChain, fetchAaveV4MerklClaimRewardIdsForChain, fetchAaveV4MerklClaimableRewardsForChain, fetchAaveV4NativeWrappedToken, fetchAaveV4ReservesForUnderlying, fetchAaveV4SpokeReserveIdForUnderlying, fetchAaveV4SpokeReserveStatusForUnderlying, fetchAaveV4SupportedUnderlyingAddressSet, fetchAaveV4UserBorrowsDebtByUnderlyingForHub, fetchAaveV4UserPositionById, fetchAaveV4UserPositionsByAssetOnChain, fetchAaveV4UserPositionsForChain, fetchAaveV4UserSuppliesForPosition, filterActiveAaveV4HubReserves, findAaveV4HubReserveForChainUnderlying, findHubReserveForUnderlying, formatAavePercentDisplay, formatAaveV4AmountHumanFromApiString, formatAaveV4ApyPercentLabel, formatAaveV4DecimalString, formatAaveV4ExchangeLabel, formatAaveV4HealthFactor, formatAaveV4PercentDisplay, formatAaveV4PositionHealthFactor, formatAaveV4PositionPercent, formatAaveV4ReserveLiquidityFromSummary, formatAaveV4RiskDisplay, formatAaveV4RiskNotionalString, formatAaveV4TokenAmount, isAaveV4DepositEvmSignRequest, isAaveV4HubReserveActive, isValidAaveChainId, loadAaveV4SupportedChainIds, loadAaveV4SupportedChainIdsFromV4Api, parseAaveV4ApyPercent, parseBigDecimalHf, pickAaveV4ReserveRowForSpoke, previewAaveV4BorrowResultingHf, previewAaveV4RepayResultingHf, previewAaveV4WithdrawResultingHf, resolveAaveV4DepositGasUnitsFromSignRequest, resolveAaveV4HubForUiMarket };
2757
+ export { AAVE_V4_GRAPHQL_URL, AAVE_V4_PROTOCOL_ID, AAVE_V4_SPOKE_BORROW_DEFAULT_GAS_UNITS, AAVE_V4_SPOKE_REPAY_DEFAULT_GAS_UNITS, AAVE_V4_SPOKE_SUPPLY_DEFAULT_GAS_UNITS, AAVE_V4_SPOKE_WITHDRAW_DEFAULT_GAS_UNITS, MERKL_API_BASE, MERKL_DISTRIBUTOR_ADDRESS, MERKL_DISTRIBUTOR_CLAIM_GAS_FALLBACK, MERKL_REWARDS_NOTES, MIN_AAVE_V4_DEPOSIT_GAS_EXEC, aaveAvailableLiquidityDisplay, aaveReadSupplyMetrics, aaveUnderlyingAddressForContext, aaveV4BorrowHealthGate, aaveV4FetchMarketSummary, aaveV4FetchMarketsSummary, aaveV4FetchMerklRewardsSummary, aaveV4Gql, aaveV4KeyForNodeAssetRow, aaveV4MarketRowFromHubReserve, aaveV4ProtocolModule, aaveV4RepayHealthGate, aaveV4UiMarketIdForHubName, aaveV4UserHasAvailableBorrowCollateralForContextOnSpoke, aaveV4WithdrawHealthGate, aggregateV4SupplyDisplay, borrowableAssetsFromHubReserves, buildAaveV4BorrowTableRowsFromHub, buildEvmMultisignBodyAaveV4DepositBatch, buildEvmMultisignBodyAaveV4MerklClaimRewards, buildEvmMultisignBodyAaveV4MerklDistributorClaim, buildEvmMultisignBodyAaveV4SpokeBorrow, buildEvmMultisignBodyAaveV4SpokeRepay, buildEvmMultisignBodyAaveV4SpokeWithdraw, buildEvmMultisignBodyEulerV2MerklDistributorClaim, buildEvmMultisignBodyEulerV2ReulUnlock, encodeMerklDistributorClaimData, ensureAaveV4ChainTokenCache, fetchAaveV4Chains, fetchAaveV4ClaimRewardsCalldata, fetchAaveV4HubReserves, fetchAaveV4HubsForChain, fetchAaveV4MerklClaimRewardIdsForChain, fetchAaveV4MerklClaimableRewardsForChain, fetchAaveV4NativeWrappedToken, fetchAaveV4ReservesForUnderlying, fetchAaveV4SpokeReserveIdForUnderlying, fetchAaveV4SpokeReserveStatusForUnderlying, fetchAaveV4SupportedUnderlyingAddressSet, fetchAaveV4UserBorrowsDebtByUnderlyingForHub, fetchAaveV4UserPositionById, fetchAaveV4UserPositionsByAssetOnChain, fetchAaveV4UserPositionsForChain, fetchAaveV4UserSuppliesForPosition, fetchAllMerklDistributorClaimLeaves, fetchMerklRewardsSummary, filterActiveAaveV4HubReserves, findAaveV4HubReserveForChainUnderlying, findHubReserveForUnderlying, formatAavePercentDisplay, formatAaveV4AmountHumanFromApiString, formatAaveV4ApyPercentLabel, formatAaveV4DecimalString, formatAaveV4ExchangeLabel, formatAaveV4HealthFactor, formatAaveV4PercentDisplay, formatAaveV4PositionHealthFactor, formatAaveV4PositionPercent, formatAaveV4ReserveLiquidityFromSummary, formatAaveV4RiskDisplay, formatAaveV4RiskNotionalString, formatAaveV4TokenAmount, isAaveV4DepositEvmSignRequest, isAaveV4HubReserveActive, isMerklRewardEulLeaf, isValidAaveChainId, loadAaveV4SupportedChainIds, loadAaveV4SupportedChainIdsFromV4Api, loadMerklUserRewardsJson, merklLeafToRow, merklUserRewardsUrl, parseAaveV4ApyPercent, parseBigDecimalHf, parseMerklUserRewardsToLeaves, pickAaveV4ReserveRowForSpoke, previewAaveV4BorrowResultingHf, previewAaveV4RepayResultingHf, previewAaveV4WithdrawResultingHf, resolveAaveV4DepositGasUnitsFromSignRequest, resolveAaveV4HubForUiMarket, selectFirstRootMerklLeaves, selectWalletWideMerklClaimLeaves };
2569
2758
  //# sourceMappingURL=index.js.map
2570
2759
  //# sourceMappingURL=index.js.map