@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
@@ -1473,6 +1473,40 @@ async function buildEvmMultisignBodyAaveV4MerklClaimRewards(args) {
1473
1473
  })
1474
1474
  });
1475
1475
  }
1476
+ async function buildEvmMultisignBodyAaveV4MerklDistributorClaim(args) {
1477
+ const to = viem.getAddress(args.to);
1478
+ const executor = viem.getAddress(args.executorAddress);
1479
+ return buildEvmMultisignBodyAaveV4OneStep({
1480
+ keyGen: args.keyGen,
1481
+ chainId: args.chainId,
1482
+ rpcUrl: args.rpcUrl,
1483
+ chainDetail: args.chainDetail,
1484
+ useCustomGas: args.useCustomGas,
1485
+ customGasChainDetails: args.customGasChainDetails ?? void 0,
1486
+ purposeText: args.purposeText,
1487
+ purposeSuffix: `Aave v4: 1-tx \u2014 wallet-wide Merkl distributor claim (${args.claimLeafCount} reward(s)).`,
1488
+ executorAddress: executor,
1489
+ v: { to, data: args.data, value: args.valueWei },
1490
+ estimateGasFallback: AAVE_MERKL_CLAIM_ESTIMATE_FALLBACK,
1491
+ buildBatchMeta: (ctx) => ({
1492
+ destinationAddress: to,
1493
+ signatureText: JSON.stringify({
1494
+ kind: "AaveV4",
1495
+ name: "Merkl Distributor claim",
1496
+ claimLeafCount: args.claimLeafCount,
1497
+ chainId: args.chainId,
1498
+ valueWei: args.valueWei.toString(),
1499
+ note: "Wallet-wide Merkl API proofs; Distributor.claim(users,tokens,amounts,proofs)."
1500
+ }),
1501
+ evm: { type: "aave_v4_merkl_distributor_claim", version: 1, chainId: String(args.chainId) },
1502
+ aaveV4: {
1503
+ step: "merkl_distributor_claim",
1504
+ claimLeafCount: args.claimLeafCount,
1505
+ gasBuildClaim: { baseGasUnits: ctx.gasLimit.toString() }
1506
+ }
1507
+ })
1508
+ });
1509
+ }
1476
1510
  async function buildEvmMultisignBodyEulerV2MerklDistributorClaim(args) {
1477
1511
  const to = viem.getAddress(args.to);
1478
1512
  const executor = viem.getAddress(args.executorAddress);
@@ -1577,7 +1611,8 @@ var AAVE_V4_EVM_TYPES = /* @__PURE__ */ new Set([
1577
1611
  "aave_v4_spoke_withdraw",
1578
1612
  "aave_v4_spoke_borrow",
1579
1613
  "aave_v4_spoke_repay",
1580
- "aave_v4_merkl_claim_rewards"
1614
+ "aave_v4_merkl_claim_rewards",
1615
+ "aave_v4_merkl_distributor_claim"
1581
1616
  ]);
1582
1617
  function parseExtraJsonObject(detail) {
1583
1618
  if (!detail) return null;
@@ -2546,6 +2581,158 @@ async function aaveV4FetchMarketSummary(args) {
2546
2581
  }
2547
2582
  return out;
2548
2583
  }
2584
+ var MERKL_API_BASE = "https://api.merkl.xyz";
2585
+ var MERKL_DISTRIBUTOR_ADDRESS = "0x3Ef3D8bA38EBe18DB133cEc108f4D14CE00Dd9Ae";
2586
+ var MERKL_DISTRIBUTOR_CLAIM_GAS_FALLBACK = 500000n;
2587
+ 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.";
2588
+ function normHex32(p) {
2589
+ const s = (p ?? "").trim();
2590
+ if (!s) return null;
2591
+ const x = s.startsWith("0x") ? s : `0x${s}`;
2592
+ if (!/^0x[0-9a-fA-F]{64}$/.test(x)) return null;
2593
+ return x;
2594
+ }
2595
+ function merklUserRewardsUrl(addr, chainId) {
2596
+ return `${MERKL_API_BASE}/v4/users/${encodeURIComponent(addr)}/rewards?chainId=${chainId}`;
2597
+ }
2598
+ async function loadMerklUserRewardsJson(args) {
2599
+ const addr = viem.getAddress(args.user);
2600
+ const url = merklUserRewardsUrl(addr, args.chainId);
2601
+ const res = await fetch(url, { cache: "no-store" });
2602
+ if (!res.ok) {
2603
+ let detail = `Merkl API error ${res.status}`;
2604
+ try {
2605
+ const j = await res.json();
2606
+ if (j?.error) {
2607
+ detail = j.details ? `${j.error}: ${j.details}` : j.error;
2608
+ }
2609
+ } catch {
2610
+ }
2611
+ throw new Error(detail);
2612
+ }
2613
+ return res.json();
2614
+ }
2615
+ function parseMerklUserRewardsToLeaves(raw, args) {
2616
+ const addr = viem.getAddress(args.user);
2617
+ if (!Array.isArray(raw)) {
2618
+ throw new Error("Merkl API returned an unexpected rewards shape.");
2619
+ }
2620
+ const collected = [];
2621
+ for (const block of raw) {
2622
+ for (const rw of block.rewards ?? []) {
2623
+ const root = (rw.root ?? "").trim();
2624
+ const dist = rw.distributionChainId;
2625
+ if (!root || dist !== args.chainId) continue;
2626
+ let recipient;
2627
+ try {
2628
+ recipient = viem.getAddress((rw.recipient ?? "").trim());
2629
+ } catch {
2630
+ continue;
2631
+ }
2632
+ if (recipient !== addr) continue;
2633
+ let amt = 0n;
2634
+ let clm = 0n;
2635
+ try {
2636
+ amt = BigInt((rw.amount ?? "0").toString().trim() || "0");
2637
+ clm = BigInt((rw.claimed ?? "0").toString().trim() || "0");
2638
+ } catch {
2639
+ continue;
2640
+ }
2641
+ if (amt <= clm) continue;
2642
+ let tokenAddr;
2643
+ try {
2644
+ tokenAddr = viem.getAddress((rw.token?.address ?? "").trim());
2645
+ } catch {
2646
+ continue;
2647
+ }
2648
+ const proofsRaw = rw.proofs ?? [];
2649
+ const proofs = [];
2650
+ for (const p of proofsRaw) {
2651
+ const h = normHex32(String(p));
2652
+ if (!h) continue;
2653
+ proofs.push(h);
2654
+ }
2655
+ if (proofsRaw.length > 0 && proofs.length !== proofsRaw.length) continue;
2656
+ const sym = (rw.token?.symbol ?? "").trim() || "\u2014";
2657
+ let dec = 18;
2658
+ try {
2659
+ const d = Number(rw.token?.decimals ?? 18);
2660
+ if (Number.isFinite(d) && d >= 0 && d <= 36) dec = d;
2661
+ } catch {
2662
+ dec = 18;
2663
+ }
2664
+ collected.push({ root, token: tokenAddr, amountWei: amt, proofs, symbol: sym, decimals: dec });
2665
+ }
2666
+ }
2667
+ return collected;
2668
+ }
2669
+ function selectFirstRootMerklLeaves(collected) {
2670
+ if (collected.length === 0) return [];
2671
+ const root0 = collected[0].root;
2672
+ return collected.filter((x) => x.root === root0);
2673
+ }
2674
+ function isMerklRewardEulLeaf(leaf) {
2675
+ const s = leaf.symbol.trim().toLowerCase().replace(/\s+/g, " ").trim();
2676
+ return s === "reul" || s === "reward eul";
2677
+ }
2678
+ function selectWalletWideMerklClaimLeaves(collected) {
2679
+ return selectFirstRootMerklLeaves(collected.filter((l) => !isMerklRewardEulLeaf(l)));
2680
+ }
2681
+ async function fetchAllMerklDistributorClaimLeaves(args) {
2682
+ const raw = await loadMerklUserRewardsJson(args);
2683
+ return parseMerklUserRewardsToLeaves(raw, args);
2684
+ }
2685
+ function encodeMerklDistributorClaimData(args) {
2686
+ if (args.leaves.length === 0) throw new Error("No Merkl claim leaves.");
2687
+ const u = viem.getAddress(args.user);
2688
+ const abi = viem.parseAbi([
2689
+ "function claim(address[] users, address[] tokens, uint256[] amounts, bytes32[][] proofs) external"
2690
+ ]);
2691
+ const users = args.leaves.map(() => u);
2692
+ const tokens = args.leaves.map((l) => l.token);
2693
+ const amounts = args.leaves.map((l) => l.amountWei);
2694
+ const proofs = args.leaves.map((l) => [...l.proofs]);
2695
+ return viem.encodeFunctionData({
2696
+ abi,
2697
+ functionName: "claim",
2698
+ args: [users, tokens, amounts, proofs]
2699
+ });
2700
+ }
2701
+ function merklLeafToRow(leaf) {
2702
+ return {
2703
+ symbol: leaf.symbol,
2704
+ token: leaf.token,
2705
+ amountHuman: viem.formatUnits(leaf.amountWei, leaf.decimals),
2706
+ amountWei: leaf.amountWei.toString(),
2707
+ decimals: leaf.decimals,
2708
+ root: leaf.root
2709
+ };
2710
+ }
2711
+ async function fetchMerklRewardsSummary(args) {
2712
+ const user = viem.getAddress(args.user);
2713
+ const chainId = args.chainId;
2714
+ const all = await fetchAllMerklDistributorClaimLeaves({ chainId, user });
2715
+ const skippedReulCount = all.filter(isMerklRewardEulLeaf).length;
2716
+ const display = all.filter((l) => !isMerklRewardEulLeaf(l));
2717
+ const firstRoot = selectFirstRootMerklLeaves(display);
2718
+ const roots = new Set(display.map((l) => l.root));
2719
+ return {
2720
+ chainId,
2721
+ user,
2722
+ distributor: MERKL_DISTRIBUTOR_ADDRESS,
2723
+ claimable: display.map(merklLeafToRow),
2724
+ claimableCount: display.length,
2725
+ firstRootClaimableCount: firstRoot.length,
2726
+ additionalRoots: Math.max(0, roots.size - (firstRoot.length > 0 ? 1 : 0)),
2727
+ skippedReulCount,
2728
+ notes: MERKL_REWARDS_NOTES
2729
+ };
2730
+ }
2731
+
2732
+ // src/protocols/evm/aave-v4/merklRewards.ts
2733
+ async function aaveV4FetchMerklRewardsSummary(args) {
2734
+ return fetchMerklRewardsSummary(args);
2735
+ }
2549
2736
 
2550
2737
  // src/protocols/evm/aave-v4/index.ts
2551
2738
  var AAVE_V4_PROTOCOL_ID = "aave-v4";
@@ -2562,7 +2749,9 @@ var aaveV4ProtocolModule = {
2562
2749
  { id: "aave-v4.deposit", protocolId: AAVE_V4_PROTOCOL_ID, chainCategory: "evm", description: "Supply to Aave v4 Spoke", commonParams: ["keyGen", "purposeText", "useCustomGas"], params: {} },
2563
2750
  { id: "aave-v4.withdraw", protocolId: AAVE_V4_PROTOCOL_ID, chainCategory: "evm", description: "Withdraw from Spoke", commonParams: ["keyGen", "purposeText", "useCustomGas"], params: {} },
2564
2751
  { id: "aave-v4.borrow", protocolId: AAVE_V4_PROTOCOL_ID, chainCategory: "evm", description: "Borrow from Spoke", commonParams: ["keyGen", "purposeText", "useCustomGas"], params: {} },
2565
- { id: "aave-v4.repay", protocolId: AAVE_V4_PROTOCOL_ID, chainCategory: "evm", description: "Repay Spoke debt", commonParams: ["keyGen", "purposeText", "useCustomGas"], params: {} }
2752
+ { id: "aave-v4.repay", protocolId: AAVE_V4_PROTOCOL_ID, chainCategory: "evm", description: "Repay Spoke debt", commonParams: ["keyGen", "purposeText", "useCustomGas"], params: {} },
2753
+ { id: "aave-v4.fetch-merkl-rewards", protocolId: AAVE_V4_PROTOCOL_ID, chainCategory: "evm", description: "List wallet-wide Merkl claimables on a chain", commonParams: [], params: {} },
2754
+ { id: "aave-v4.merkl-claim", protocolId: AAVE_V4_PROTOCOL_ID, chainCategory: "evm", description: "Claim wallet-wide Merkl rewards", commonParams: ["keyGen", "purposeText", "useCustomGas"], params: {} }
2566
2755
  ]
2567
2756
  };
2568
2757
  registerProtocolModule(aaveV4ProtocolModule);
@@ -2573,6 +2762,10 @@ exports.AAVE_V4_SPOKE_BORROW_DEFAULT_GAS_UNITS = AAVE_V4_SPOKE_BORROW_DEFAULT_GA
2573
2762
  exports.AAVE_V4_SPOKE_REPAY_DEFAULT_GAS_UNITS = AAVE_V4_SPOKE_REPAY_DEFAULT_GAS_UNITS;
2574
2763
  exports.AAVE_V4_SPOKE_SUPPLY_DEFAULT_GAS_UNITS = AAVE_V4_SPOKE_SUPPLY_DEFAULT_GAS_UNITS;
2575
2764
  exports.AAVE_V4_SPOKE_WITHDRAW_DEFAULT_GAS_UNITS = AAVE_V4_SPOKE_WITHDRAW_DEFAULT_GAS_UNITS;
2765
+ exports.MERKL_API_BASE = MERKL_API_BASE;
2766
+ exports.MERKL_DISTRIBUTOR_ADDRESS = MERKL_DISTRIBUTOR_ADDRESS;
2767
+ exports.MERKL_DISTRIBUTOR_CLAIM_GAS_FALLBACK = MERKL_DISTRIBUTOR_CLAIM_GAS_FALLBACK;
2768
+ exports.MERKL_REWARDS_NOTES = MERKL_REWARDS_NOTES;
2576
2769
  exports.MIN_AAVE_V4_DEPOSIT_GAS_EXEC = MIN_AAVE_V4_DEPOSIT_GAS_EXEC;
2577
2770
  exports.aaveAvailableLiquidityDisplay = aaveAvailableLiquidityDisplay;
2578
2771
  exports.aaveReadSupplyMetrics = aaveReadSupplyMetrics;
@@ -2580,6 +2773,7 @@ exports.aaveUnderlyingAddressForContext = aaveUnderlyingAddressForContext;
2580
2773
  exports.aaveV4BorrowHealthGate = aaveV4BorrowHealthGate;
2581
2774
  exports.aaveV4FetchMarketSummary = aaveV4FetchMarketSummary;
2582
2775
  exports.aaveV4FetchMarketsSummary = aaveV4FetchMarketsSummary;
2776
+ exports.aaveV4FetchMerklRewardsSummary = aaveV4FetchMerklRewardsSummary;
2583
2777
  exports.aaveV4Gql = aaveV4Gql;
2584
2778
  exports.aaveV4KeyForNodeAssetRow = aaveV4KeyForNodeAssetRow;
2585
2779
  exports.aaveV4MarketRowFromHubReserve = aaveV4MarketRowFromHubReserve;
@@ -2593,11 +2787,13 @@ exports.borrowableAssetsFromHubReserves = borrowableAssetsFromHubReserves;
2593
2787
  exports.buildAaveV4BorrowTableRowsFromHub = buildAaveV4BorrowTableRowsFromHub;
2594
2788
  exports.buildEvmMultisignBodyAaveV4DepositBatch = buildEvmMultisignBodyAaveV4DepositBatch;
2595
2789
  exports.buildEvmMultisignBodyAaveV4MerklClaimRewards = buildEvmMultisignBodyAaveV4MerklClaimRewards;
2790
+ exports.buildEvmMultisignBodyAaveV4MerklDistributorClaim = buildEvmMultisignBodyAaveV4MerklDistributorClaim;
2596
2791
  exports.buildEvmMultisignBodyAaveV4SpokeBorrow = buildEvmMultisignBodyAaveV4SpokeBorrow;
2597
2792
  exports.buildEvmMultisignBodyAaveV4SpokeRepay = buildEvmMultisignBodyAaveV4SpokeRepay;
2598
2793
  exports.buildEvmMultisignBodyAaveV4SpokeWithdraw = buildEvmMultisignBodyAaveV4SpokeWithdraw;
2599
2794
  exports.buildEvmMultisignBodyEulerV2MerklDistributorClaim = buildEvmMultisignBodyEulerV2MerklDistributorClaim;
2600
2795
  exports.buildEvmMultisignBodyEulerV2ReulUnlock = buildEvmMultisignBodyEulerV2ReulUnlock;
2796
+ exports.encodeMerklDistributorClaimData = encodeMerklDistributorClaimData;
2601
2797
  exports.ensureAaveV4ChainTokenCache = ensureAaveV4ChainTokenCache;
2602
2798
  exports.fetchAaveV4Chains = fetchAaveV4Chains;
2603
2799
  exports.fetchAaveV4ClaimRewardsCalldata = fetchAaveV4ClaimRewardsCalldata;
@@ -2615,6 +2811,8 @@ exports.fetchAaveV4UserPositionById = fetchAaveV4UserPositionById;
2615
2811
  exports.fetchAaveV4UserPositionsByAssetOnChain = fetchAaveV4UserPositionsByAssetOnChain;
2616
2812
  exports.fetchAaveV4UserPositionsForChain = fetchAaveV4UserPositionsForChain;
2617
2813
  exports.fetchAaveV4UserSuppliesForPosition = fetchAaveV4UserSuppliesForPosition;
2814
+ exports.fetchAllMerklDistributorClaimLeaves = fetchAllMerklDistributorClaimLeaves;
2815
+ exports.fetchMerklRewardsSummary = fetchMerklRewardsSummary;
2618
2816
  exports.filterActiveAaveV4HubReserves = filterActiveAaveV4HubReserves;
2619
2817
  exports.findAaveV4HubReserveForChainUnderlying = findAaveV4HubReserveForChainUnderlying;
2620
2818
  exports.findHubReserveForUnderlying = findHubReserveForUnderlying;
@@ -2633,16 +2831,23 @@ exports.formatAaveV4RiskNotionalString = formatAaveV4RiskNotionalString;
2633
2831
  exports.formatAaveV4TokenAmount = formatAaveV4TokenAmount;
2634
2832
  exports.isAaveV4DepositEvmSignRequest = isAaveV4DepositEvmSignRequest;
2635
2833
  exports.isAaveV4HubReserveActive = isAaveV4HubReserveActive;
2834
+ exports.isMerklRewardEulLeaf = isMerklRewardEulLeaf;
2636
2835
  exports.isValidAaveChainId = isValidAaveChainId;
2637
2836
  exports.loadAaveV4SupportedChainIds = loadAaveV4SupportedChainIds;
2638
2837
  exports.loadAaveV4SupportedChainIdsFromV4Api = loadAaveV4SupportedChainIdsFromV4Api;
2838
+ exports.loadMerklUserRewardsJson = loadMerklUserRewardsJson;
2839
+ exports.merklLeafToRow = merklLeafToRow;
2840
+ exports.merklUserRewardsUrl = merklUserRewardsUrl;
2639
2841
  exports.parseAaveV4ApyPercent = parseAaveV4ApyPercent;
2640
2842
  exports.parseBigDecimalHf = parseBigDecimalHf;
2843
+ exports.parseMerklUserRewardsToLeaves = parseMerklUserRewardsToLeaves;
2641
2844
  exports.pickAaveV4ReserveRowForSpoke = pickAaveV4ReserveRowForSpoke;
2642
2845
  exports.previewAaveV4BorrowResultingHf = previewAaveV4BorrowResultingHf;
2643
2846
  exports.previewAaveV4RepayResultingHf = previewAaveV4RepayResultingHf;
2644
2847
  exports.previewAaveV4WithdrawResultingHf = previewAaveV4WithdrawResultingHf;
2645
2848
  exports.resolveAaveV4DepositGasUnitsFromSignRequest = resolveAaveV4DepositGasUnitsFromSignRequest;
2646
2849
  exports.resolveAaveV4HubForUiMarket = resolveAaveV4HubForUiMarket;
2850
+ exports.selectFirstRootMerklLeaves = selectFirstRootMerklLeaves;
2851
+ exports.selectWalletWideMerklClaimLeaves = selectWalletWideMerklClaimLeaves;
2647
2852
  //# sourceMappingURL=index.cjs.map
2648
2853
  //# sourceMappingURL=index.cjs.map