@1delta/margin-fetcher 0.0.286 → 0.0.300

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -32926,18 +32926,22 @@ var upshiftFetcher = {
32926
32926
  // src/yields/intrinsic/fetchers/monadLst.ts
32927
32927
  var SMON_POOL_ID = "73c511a9-4dc0-4397-babe-e578fd75f0dd";
32928
32928
  var SHMON_POOL_ID = "ee40513c-9356-4c53-9f26-446b484a8ae2";
32929
+ var GMON_POOL_ID = "96f74061-dc9a-4ef7-8117-6cd3935230de";
32929
32930
  var SMON_KEY = "Kintsu Staked Monad::sMON";
32930
32931
  var SHMON_KEY = "ShMonad::shMON";
32932
+ var GMON_KEY = "gMON::gMON";
32931
32933
  var monadLstFetcher = {
32932
32934
  label: "MONAD_LST",
32933
32935
  fetch: async () => {
32934
- const [sMon, shMon] = await Promise.allSettled([
32936
+ const [sMon, shMon, gMon] = await Promise.allSettled([
32935
32937
  fetchDefiLlamaApy(SMON_POOL_ID),
32936
- fetchDefiLlamaApy(SHMON_POOL_ID)
32938
+ fetchDefiLlamaApy(SHMON_POOL_ID),
32939
+ fetchDefiLlamaApy(GMON_POOL_ID)
32937
32940
  ]);
32938
32941
  const out = {};
32939
32942
  if (sMon.status === "fulfilled") out[SMON_KEY] = sMon.value;
32940
32943
  if (shMon.status === "fulfilled") out[SHMON_KEY] = shMon.value;
32944
+ if (gMon.status === "fulfilled") out[GMON_KEY] = gMon.value;
32941
32945
  return out;
32942
32946
  }
32943
32947
  };
@@ -38028,6 +38032,38 @@ var fetchSiloVaults = async (chainId, prices = {}, tokenList = {}, options) => {
38028
38032
  };
38029
38033
 
38030
38034
  // src/vaults/euler-earn/fetchFromSubgraph.ts
38035
+ var DECIMALS_ABI = [
38036
+ {
38037
+ name: "decimals",
38038
+ type: "function",
38039
+ stateMutability: "view",
38040
+ inputs: [],
38041
+ outputs: [{ type: "uint8" }]
38042
+ }
38043
+ ];
38044
+ async function fetchShareDecimals(chainId, vaultAddrs, multicallRetry) {
38045
+ const out = /* @__PURE__ */ new Map();
38046
+ if (!multicallRetry || vaultAddrs.length === 0) return out;
38047
+ try {
38048
+ const res = await multicallRetry({
38049
+ chain: chainId,
38050
+ calls: vaultAddrs.map((address) => ({
38051
+ address,
38052
+ name: "decimals",
38053
+ params: []
38054
+ })),
38055
+ abi: vaultAddrs.map(() => DECIMALS_ABI),
38056
+ allowFailure: true,
38057
+ maxRetries: 2
38058
+ });
38059
+ vaultAddrs.forEach((a, i) => {
38060
+ const d = Number(res?.[i]);
38061
+ if (Number.isFinite(d)) out.set(a.toLowerCase(), d);
38062
+ });
38063
+ } catch {
38064
+ }
38065
+ return out;
38066
+ }
38031
38067
  var EULER_EARN_PROJECT = "project_cm4iagnemt1wp01xn4gh1agft";
38032
38068
  var eulerSubgraphUrl = (slug) => `https://api.goldsky.com/api/public/${EULER_EARN_PROJECT}/subgraphs/${slug}/latest/gn`;
38033
38069
  var EULER_EARN_SUBGRAPH_URLS = {
@@ -38143,16 +38179,19 @@ function computeRealLiquidity(strategies, totalAssetsRaw, evkIndex) {
38143
38179
  const result = idle + withdrawable;
38144
38180
  return result > totalAssets ? totalAssets : result;
38145
38181
  }
38146
- function parseVault6(v, chainId, prices, tokenList, evkIndex) {
38182
+ function parseVault6(v, chainId, prices, tokenList, evkIndex, shareDecimalsByVault) {
38147
38183
  const address = (v?.id ?? "").toLowerCase();
38148
38184
  const assetAddr = (v?.asset ?? "").toLowerCase();
38149
38185
  if (!address || !assetAddr) return null;
38150
38186
  const assetMeta = tokenList[assetAddr];
38151
- const decimals = Number(
38187
+ const assetDecimals = Number(
38152
38188
  evkIndex.decimalsByAsset.get(assetAddr) ?? assetMeta?.decimals ?? 18
38153
38189
  );
38190
+ const decimals = shareDecimalsByVault.get(address) ?? assetDecimals;
38154
38191
  const totalAssetsRaw = v.totalAssets?.toString() ?? "0";
38155
- const totalAssetsFormatted = Number(parseRawAmount(totalAssetsRaw, decimals));
38192
+ const totalAssetsFormatted = Number(
38193
+ parseRawAmount(totalAssetsRaw, assetDecimals)
38194
+ );
38156
38195
  const oracleKey = toOracleKey(assetMeta?.assetGroup) ?? toGenericPriceKey(assetAddr, chainId);
38157
38196
  const priceUsd = prices[oracleKey] ?? prices[assetAddr] ?? 0;
38158
38197
  const fee = parseVaultFee(v);
@@ -38174,13 +38213,14 @@ function parseVault6(v, chainId, prices, tokenList, evkIndex) {
38174
38213
  evkIndex
38175
38214
  );
38176
38215
  const liquidityRaw = liquidityBig.toString();
38177
- const liquidityFormatted = Number(parseRawAmount(liquidityRaw, decimals));
38216
+ const liquidityFormatted = Number(parseRawAmount(liquidityRaw, assetDecimals));
38178
38217
  return {
38179
38218
  address,
38180
38219
  underlying: assetAddr,
38181
38220
  symbol: v.symbol ?? "",
38182
38221
  name: v.name ?? "",
38183
38222
  decimals,
38223
+ assetDecimals,
38184
38224
  totalAssets: totalAssetsRaw,
38185
38225
  totalSupply: totalSupplyRaw,
38186
38226
  convertToAssets,
@@ -38251,21 +38291,34 @@ async function fetchEvkIndex(url, assets) {
38251
38291
  }
38252
38292
  return empty;
38253
38293
  }
38254
- async function fetchEulerEarnVaultsFromSubgraph(chainId, prices = {}, tokenList = {}) {
38294
+ async function fetchEulerEarnVaultsFromSubgraph(chainId, prices = {}, tokenList = {}, multicallRetry) {
38255
38295
  const url = EULER_EARN_SUBGRAPH_URLS[chainId];
38256
38296
  if (!url) return {};
38257
38297
  const json = await postQuery(url, { query: EULER_EARN_VAULTS_QUERY });
38258
38298
  const items = json?.data?.eulerEarnVaults ?? [];
38259
38299
  if (items.length === 0) return {};
38260
38300
  const assets = /* @__PURE__ */ new Set();
38301
+ const vaultAddrs = [];
38261
38302
  for (const v of items) {
38262
38303
  const a = v?.asset?.toLowerCase();
38263
38304
  if (a) assets.add(a);
38305
+ const id = v?.id;
38306
+ if (id) vaultAddrs.push(id);
38264
38307
  }
38265
- const evkIndex = await fetchEvkIndex(url, [...assets]);
38308
+ const [evkIndex, shareDecimalsByVault] = await Promise.all([
38309
+ fetchEvkIndex(url, [...assets]),
38310
+ fetchShareDecimals(chainId, vaultAddrs, multicallRetry)
38311
+ ]);
38266
38312
  const out = {};
38267
38313
  for (const v of items) {
38268
- const parsed = parseVault6(v, chainId, prices, tokenList, evkIndex);
38314
+ const parsed = parseVault6(
38315
+ v,
38316
+ chainId,
38317
+ prices,
38318
+ tokenList,
38319
+ evkIndex,
38320
+ shareDecimalsByVault
38321
+ );
38269
38322
  if (parsed) out[parsed.address] = parsed;
38270
38323
  }
38271
38324
  return out;
@@ -38293,6 +38346,12 @@ function safeBigInt2(v) {
38293
38346
  return 0n;
38294
38347
  }
38295
38348
  }
38349
+ function rescaleExchangeRate(exchangeRate, shareDecimals) {
38350
+ const r = safeBigInt2(exchangeRate);
38351
+ if (r === 0n) return "0";
38352
+ const dec = Math.max(0, Math.round(Number(shareDecimals) || 0));
38353
+ return (r * 10n ** BigInt(dec) / 10n ** 18n).toString();
38354
+ }
38296
38355
  async function getJson(url) {
38297
38356
  const controller = new AbortController();
38298
38357
  const timer = setTimeout(() => controller.abort(), API_TIMEOUT_MS);
@@ -38343,15 +38402,20 @@ function mapApiDetail(d, chainId, prices, tokenList) {
38343
38402
  if (!address || !underlying) return null;
38344
38403
  const assetMeta = tokenList[underlying];
38345
38404
  const decimals = Number(d.decimals ?? d.asset?.decimals ?? 18);
38405
+ const assetDecimals = Number(
38406
+ d.asset?.decimals ?? assetMeta?.decimals ?? decimals
38407
+ );
38346
38408
  const totalAssetsRaw = String(d.totalAssets ?? "0");
38347
38409
  const totalSupplyRaw = String(d.totalShares ?? "0");
38348
- const convertToAssets = d.exchangeRate != null ? String(d.exchangeRate) : deriveConvertToAssets(totalAssetsRaw, totalSupplyRaw, decimals);
38410
+ const convertToAssets = d.exchangeRate != null ? rescaleExchangeRate(d.exchangeRate, decimals) : deriveConvertToAssets(totalAssetsRaw, totalSupplyRaw, decimals);
38349
38411
  const supplyRate = Number(d.supplyApy ?? d.apyCurrent ?? 0) || 0;
38350
38412
  const availableRaw = safeBigInt2(d.availableAssets) || safeBigInt2(totalAssetsRaw);
38351
38413
  const totalAssetsBig = safeBigInt2(totalAssetsRaw);
38352
38414
  const liquidityRaw = (availableRaw > totalAssetsBig ? totalAssetsBig : availableRaw).toString();
38353
- const totalAssetsFormatted = Number(parseRawAmount(totalAssetsRaw, decimals));
38354
- const liquidityFormatted = Number(parseRawAmount(liquidityRaw, decimals));
38415
+ const totalAssetsFormatted = Number(
38416
+ parseRawAmount(totalAssetsRaw, assetDecimals)
38417
+ );
38418
+ const liquidityFormatted = Number(parseRawAmount(liquidityRaw, assetDecimals));
38355
38419
  const oracleKey = toOracleKey(assetMeta?.assetGroup) ?? toGenericPriceKey(underlying, chainId);
38356
38420
  const priceUsd = prices[oracleKey] ?? prices[underlying] ?? 0;
38357
38421
  const totalAssetsUsd = priceUsd ? totalAssetsFormatted * priceUsd : Number(d.totalSupplyUsd ?? 0);
@@ -38362,6 +38426,7 @@ function mapApiDetail(d, chainId, prices, tokenList) {
38362
38426
  symbol: d.symbol ?? "",
38363
38427
  name: d.name ?? "",
38364
38428
  decimals,
38429
+ assetDecimals,
38365
38430
  totalAssets: totalAssetsRaw,
38366
38431
  totalSupply: totalSupplyRaw,
38367
38432
  convertToAssets,
@@ -38425,14 +38490,14 @@ async function fetchEulerEarnVaultsFromApi(chainId, prices = {}, tokenList = {})
38425
38490
 
38426
38491
  // src/vaults/euler-earn/fetchPublic.ts
38427
38492
  var isNonEmpty = (v) => !!v && Object.keys(v).length > 0;
38428
- var fetchEulerEarnVaults = async (chainId, prices = {}, tokenList = {}) => {
38493
+ var fetchEulerEarnVaults = async (chainId, prices = {}, tokenList = {}, multicallRetry) => {
38429
38494
  const subgraphUrl = getEulerEarnSubgraphUrl(chainId);
38430
38495
  if (!subgraphUrl) {
38431
38496
  return await fetchEulerEarnVaultsFromApi(chainId, prices, tokenList) ?? {};
38432
38497
  }
38433
38498
  const [stale, subgraph] = await Promise.all([
38434
38499
  isEulerEarnSubgraphStale(chainId, subgraphUrl).catch(() => false),
38435
- fetchEulerEarnVaultsFromSubgraph(chainId, prices, tokenList).then((r) => ({ ok: true, data: r })).catch(() => ({ ok: false, data: void 0 }))
38500
+ fetchEulerEarnVaultsFromSubgraph(chainId, prices, tokenList, multicallRetry).then((r) => ({ ok: true, data: r })).catch(() => ({ ok: false, data: void 0 }))
38436
38501
  ]);
38437
38502
  if (!stale && subgraph.ok && isNonEmpty(subgraph.data)) {
38438
38503
  return subgraph.data;
@@ -38651,6 +38716,91 @@ var solvBtcPlusFetcher = {
38651
38716
 
38652
38717
  // src/vaults/lst/registry.ts
38653
38718
  var LST_REGISTRY = {
38719
+ // Monad (143) — native-MON LSTs. shMON / aprMON are ERC-4626 over native
38720
+ // MON (asset() = the 0xEeee… native sentinel), with async redemptions
38721
+ // (requestRedeem → claim). Priced via WMON. sMON (Kintsu) is a custom
38722
+ // non-4626 contract and is added separately once its rate-getter ABI is
38723
+ // available.
38724
+ "143": [
38725
+ {
38726
+ address: "0x1b68626dca36c7fe922fd2d55e4f631d962de19c",
38727
+ underlying: "0x0000000000000000000000000000000000000000",
38728
+ priceUnderlying: "0x3bd359c1119da7da1d913d1c4d2b7c461115433a",
38729
+ // WMON
38730
+ symbol: "shMON",
38731
+ brand: "ShMonad",
38732
+ decimals: 18,
38733
+ reader: "erc4626",
38734
+ isErc4626: true,
38735
+ isRebasing: false,
38736
+ isMintable: true,
38737
+ isNativeUnderlying: true,
38738
+ mintContract: "0x1b68626dca36c7fe922fd2d55e4f631d962de19c",
38739
+ mintInputAsset: "native",
38740
+ withdrawalMode: "queued",
38741
+ yieldFetcher: monadLstFetcher,
38742
+ yieldKey: "ShMonad::shMON"
38743
+ },
38744
+ {
38745
+ address: "0x0c65a0bc65a5d819235b71f554d210d3f80e0852",
38746
+ underlying: "0x0000000000000000000000000000000000000000",
38747
+ priceUnderlying: "0x3bd359c1119da7da1d913d1c4d2b7c461115433a",
38748
+ // WMON
38749
+ symbol: "aprMON",
38750
+ brand: "aPriori",
38751
+ decimals: 18,
38752
+ reader: "erc4626",
38753
+ isErc4626: true,
38754
+ isRebasing: false,
38755
+ isMintable: true,
38756
+ isNativeUnderlying: true,
38757
+ mintContract: "0x0c65a0bc65a5d819235b71f554d210d3f80e0852",
38758
+ mintInputAsset: "native",
38759
+ withdrawalMode: "queued"
38760
+ // No DefiLlama pool for aPriori — `supplyRate` is left to the on-chain
38761
+ // exchange-rate path; the ERC-4626 `convertToAssets` rate is surfaced.
38762
+ },
38763
+ {
38764
+ // sMON (Kintsu) — custom (non-4626) native-MON LST. Rate derived from
38765
+ // totalPooled()/totalShares(). Deposit/withdraw mechanics are custom
38766
+ // and not yet wired on the action side (no verified source ABI).
38767
+ address: "0xa3227c5969757783154c60bf0bc1944180ed81b9",
38768
+ underlying: "0x0000000000000000000000000000000000000000",
38769
+ priceUnderlying: "0x3bd359c1119da7da1d913d1c4d2b7c461115433a",
38770
+ // WMON
38771
+ symbol: "sMON",
38772
+ brand: "Kintsu",
38773
+ decimals: 18,
38774
+ reader: "kintsuSMon",
38775
+ isErc4626: false,
38776
+ isRebasing: false,
38777
+ isMintable: true,
38778
+ isNativeUnderlying: true,
38779
+ withdrawalMode: "queued",
38780
+ yieldFetcher: monadLstFetcher,
38781
+ yieldKey: "Kintsu Staked Monad::sMON"
38782
+ },
38783
+ {
38784
+ // gMON (Magma) — ERC-4626 over WMON (ERC-20 underlying, priced
38785
+ // directly). Deposit pulls WMON; redemption is sync/async on-chain.
38786
+ // Action side not yet wired (deposit reverts opaquely without source).
38787
+ address: "0x8498312a6b3cbd158bf0c93abdcf29e6e4f55081",
38788
+ underlying: "0x3bd359c1119da7da1d913d1c4d2b7c461115433a",
38789
+ // WMON
38790
+ symbol: "gMON",
38791
+ brand: "Magma",
38792
+ decimals: 18,
38793
+ reader: "erc4626",
38794
+ isErc4626: true,
38795
+ isRebasing: false,
38796
+ isMintable: true,
38797
+ isNativeUnderlying: false,
38798
+ mintContract: "0x8498312a6b3cbd158bf0c93abdcf29e6e4f55081",
38799
+ withdrawalMode: "queued",
38800
+ yieldFetcher: monadLstFetcher,
38801
+ yieldKey: "gMON::gMON"
38802
+ }
38803
+ ],
38654
38804
  "1": [
38655
38805
  {
38656
38806
  address: "0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0",
@@ -41147,6 +41297,40 @@ var readerStellaStDot = (entry) => ({
41147
41297
  }
41148
41298
  });
41149
41299
 
41300
+ // src/vaults/lst/abis/kintsu.ts
41301
+ var KintsuSMonAbi = [
41302
+ {
41303
+ name: "totalPooled",
41304
+ type: "function",
41305
+ stateMutability: "view",
41306
+ inputs: [],
41307
+ outputs: [{ type: "uint256" }]
41308
+ },
41309
+ {
41310
+ name: "totalShares",
41311
+ type: "function",
41312
+ stateMutability: "view",
41313
+ inputs: [],
41314
+ outputs: [{ type: "uint256" }]
41315
+ }
41316
+ ];
41317
+
41318
+ // src/vaults/lst/readers/kintsu.ts
41319
+ var readerKintsuSMon = (entry) => ({
41320
+ calls: [
41321
+ { address: entry.address, name: "totalPooled", params: [] },
41322
+ { address: entry.address, name: "totalShares", params: [] }
41323
+ ],
41324
+ abis: [KintsuSMonAbi, KintsuSMonAbi],
41325
+ parse: ([pooled, shares]) => {
41326
+ const totalAssets = toBigInt10(pooled);
41327
+ const totalSupply = toBigInt10(shares);
41328
+ if (totalAssets === void 0 || totalSupply === void 0) return void 0;
41329
+ const exchangeRate = totalSupply > 0n ? totalAssets * ONE_E186 / totalSupply : ONE_E186;
41330
+ return { totalAssets, totalSupply, exchangeRate };
41331
+ }
41332
+ });
41333
+
41150
41334
  // src/vaults/lst/readers/index.ts
41151
41335
  var buildReader = (entry) => {
41152
41336
  switch (entry.reader) {
@@ -41206,6 +41390,8 @@ var buildReader = (entry) => {
41206
41390
  return readerCoreStakedRatio(entry);
41207
41391
  case "stellaStDot":
41208
41392
  return readerStellaStDot(entry);
41393
+ case "kintsuSMon":
41394
+ return readerKintsuSMon(entry);
41209
41395
  }
41210
41396
  };
41211
41397
 
@@ -45465,8 +45651,8 @@ function parseVault8(v, chainId, prices, tokenList) {
45465
45651
  );
45466
45652
  const base = num2(v.apy?.apy) ?? 0;
45467
45653
  const campaign = num2(v.apy?.campaignApy);
45468
- const supplyRate = base;
45469
- const rewardsRate = campaign ?? 0;
45654
+ const supplyRate = apyToAprPercent(base);
45655
+ const rewardsRate = campaign != null ? apyToAprPercent(campaign) : 0;
45470
45656
  const oracleKey = toOracleKey(assetMeta?.assetGroup) ?? toGenericPriceKey(assetAddr, chainId);
45471
45657
  const apiTvlUsd = num2(v.latest_reported_tvl) ?? 0;
45472
45658
  const impliedPriceUsd = totalAssetsFormatted > 0 ? apiTvlUsd / totalAssetsFormatted : 0;
@@ -47418,7 +47604,7 @@ var getVaultPublicDataAll = async (chainId, providers, multicallRetry, prices =
47418
47604
  }
47419
47605
  if (requested.has("euler-earn")) {
47420
47606
  tasks.push(
47421
- fetchEulerEarnVaults(chainId, prices, tokenList).then((res) => {
47607
+ fetchEulerEarnVaults(chainId, prices, tokenList, multicallRetry).then((res) => {
47422
47608
  out["euler-earn"] = res;
47423
47609
  }).catch((e) => {
47424
47610
  warn4(