@1delta/margin-fetcher 0.0.276 → 0.0.278

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
@@ -5,7 +5,7 @@ import { Lender, isAaveType, isCompoundV3, isMultiMarket, isSiloV2Type, isSiloV3
5
5
  export { isAaveType, isAaveV2Type, isAaveV32Type, isAaveV3Type, isCompoundV3, isCompoundV3Type, isInit, isMorphoType, isMultiMarket, isYLDR } from '@1delta/lender-registry';
6
6
  import lodash from 'lodash';
7
7
  import { getEvmChain, getEvmClient, getEvmClientUniversal, multicallRetryUniversal, getEvmClientWithCustomRpcsUniversal } from '@1delta/providers';
8
- import { FluidLendingResolverAbi, FluidVaultResolverAbi, MetaMorphoAbi, MoolahVaultAbi, MorphoLensAbi, AaveV4SpokeAbi, AaveV4OracleAbi, AaveV4HubAbi, DolomiteMarginAbi, GearboxMarketCompressorV310Abi, MorphoBlueAbi, GearboxCreditAccountCompressorV310Abi } from '@1delta/abis';
8
+ import { MetaMorphoAbi, FluidLendingResolverAbi, FluidVaultResolverAbi, MoolahVaultAbi, MorphoLensAbi, AaveV4SpokeAbi, AaveV4OracleAbi, AaveV4HubAbi, DolomiteMarginAbi, GearboxMarketCompressorV310Abi, MorphoBlueAbi, GearboxCreditAccountCompressorV310Abi } from '@1delta/abis';
9
9
  export { MorphoLensAbi } from '@1delta/abis';
10
10
  import { prepareDebitDataMulticall, prepareLenderDebitMulticall, parseDebitDataResult, parseLenderDebitResult, getPermit2ContractAddress, getCompoundV3CometAddress as getCompoundV3CometAddress$1, getMorphoAddress, getAaveCollateralTokenAddress, getSiloHalfForUnderlying, InitMarginAddresses, getLstAcceptedInputs } from '@1delta/calldata-sdk';
11
11
  import { proxyNativeFetch } from '@1delta/proxy-fetch';
@@ -36276,6 +36276,52 @@ function computeVaultAllocation(vaultAddress, decimals, totalAssetsFormatted, fe
36276
36276
  liquidityFormatted: Math.min(totalAssetsFormatted, idle + withdrawable)
36277
36277
  };
36278
36278
  }
36279
+ function computeV2Allocation(decimals, totalAssetsFormatted, feePercent, priceUsd, marketAssetsRaw, rateMap, tokenList, uidCtx) {
36280
+ if (totalAssetsFormatted <= 0) {
36281
+ return { depositRate: 0, exposures: [], liquidityFormatted: 0 };
36282
+ }
36283
+ if (marketAssetsRaw.size === 0) {
36284
+ return {
36285
+ depositRate: 0,
36286
+ exposures: withIdleExposure([], totalAssetsFormatted, priceUsd),
36287
+ liquidityFormatted: totalAssetsFormatted
36288
+ };
36289
+ }
36290
+ let weighted = 0;
36291
+ let allocated = 0;
36292
+ let withdrawable = 0;
36293
+ const exposures = [];
36294
+ for (const [id, assetsRaw] of marketAssetsRaw) {
36295
+ const allocAssets = Number(parseRawAmount(assetsRaw.toString(), decimals));
36296
+ if (allocAssets <= 0) continue;
36297
+ const rate = rateMap.get(id);
36298
+ allocated += allocAssets;
36299
+ const supplyApr = rate?.supplyApr ?? 0;
36300
+ weighted += allocAssets * supplyApr;
36301
+ const marketLiquidity = rate?.liquidity != null ? Number(parseRawAmount(rate.liquidity.toString(), decimals)) : allocAssets;
36302
+ withdrawable += Math.min(allocAssets, Math.max(0, marketLiquidity));
36303
+ const marketUid = marketUidFor(uidCtx, id);
36304
+ const collateralAddress = rate?.collateralAddress ?? "";
36305
+ exposures.push({
36306
+ marketId: id,
36307
+ ...marketUid ? { marketUid } : {},
36308
+ collateralAddress,
36309
+ collateral: collateralAddress ? tokenList[collateralAddress] : void 0,
36310
+ assets: allocAssets,
36311
+ assetsUsd: allocAssets * priceUsd,
36312
+ weightPct: allocAssets / totalAssetsFormatted * 100,
36313
+ supplyApr
36314
+ });
36315
+ }
36316
+ exposures.sort((a, b) => b.weightPct - a.weightPct);
36317
+ const grossApr = weighted / totalAssetsFormatted;
36318
+ const idle = Math.max(0, totalAssetsFormatted - allocated);
36319
+ return {
36320
+ depositRate: grossApr * (1 - feePercent / 100),
36321
+ exposures: withIdleExposure(exposures, totalAssetsFormatted, priceUsd),
36322
+ liquidityFormatted: Math.min(totalAssetsFormatted, idle + withdrawable)
36323
+ };
36324
+ }
36279
36325
 
36280
36326
  // src/vaults/morpho/fetchFromChain.ts
36281
36327
  var { chunk: chunk5 } = lodash;
@@ -36292,13 +36338,36 @@ var VAULT_CALLS = [
36292
36338
  "guardian"
36293
36339
  ];
36294
36340
  var CALLS_PER_VAULT = VAULT_CALLS.length;
36295
- var PHASE1_CALLS = [...VAULT_CALLS, "withdrawQueueLength"];
36341
+ var PHASE1_CALLS = [
36342
+ ...VAULT_CALLS,
36343
+ "withdrawQueueLength",
36344
+ // V1 (MetaMorpho) — reverts on V2
36345
+ "adaptersLength",
36346
+ // V2 (Vaults V2) — reverts on V1
36347
+ "performanceFee"
36348
+ // V2 fee getter (V1 uses `fee()`)
36349
+ ];
36296
36350
  var PHASE1_PER_VAULT = PHASE1_CALLS.length;
36297
36351
  var WITHDRAW_QUEUE_LENGTH_INDEX = CALLS_PER_VAULT;
36352
+ var ADAPTERS_LENGTH_INDEX = CALLS_PER_VAULT + 1;
36353
+ var PERFORMANCE_FEE_INDEX = CALLS_PER_VAULT + 2;
36298
36354
  var MORPHO_LENS_ABI = parseAbi([
36299
36355
  "function getMarketDataCompact(address morpho, bytes32[] calldata marketsIds) external view returns (bytes memory data)"
36300
36356
  ]);
36301
36357
  var MARKET_CHUNK = 100;
36358
+ var VAULT_V2_PHASE1_ABI = parseAbi([
36359
+ "function adaptersLength() view returns (uint256)",
36360
+ "function performanceFee() view returns (uint96)"
36361
+ ]);
36362
+ var VAULT_V2_ABI = parseAbi([
36363
+ "function adapters(uint256) view returns (address)"
36364
+ ]);
36365
+ var VAULT_V2_ADAPTER_ABI = parseAbi([
36366
+ "function marketIdsLength() view returns (uint256)",
36367
+ "function marketIds(uint256) view returns (bytes32)",
36368
+ "function expectedSupplyAssets(bytes32) view returns (uint256)"
36369
+ ]);
36370
+ var PHASE1_ABI = [...MetaMorphoAbi, ...VAULT_V2_PHASE1_ABI];
36302
36371
  var FEE_SCALE = 1e18;
36303
36372
  var isHex40 = (addr) => typeof addr === "string" && /^0x[0-9a-f]{40}$/i.test(addr);
36304
36373
  var isHex64 = (v) => typeof v === "string" && /^0x[0-9a-f]{64}$/i.test(v);
@@ -36312,6 +36381,17 @@ var toStringSafe = (raw, fallback = "") => {
36312
36381
  if (raw === void 0 || raw === null) return fallback;
36313
36382
  return String(raw);
36314
36383
  };
36384
+ var toBigIntSafe2 = (raw) => {
36385
+ if (raw === void 0 || raw === null) return void 0;
36386
+ try {
36387
+ if (typeof raw === "bigint") return raw;
36388
+ if (typeof raw === "number") return BigInt(Math.trunc(raw));
36389
+ if (typeof raw === "string" && /^\d+$/.test(raw)) return BigInt(raw);
36390
+ return void 0;
36391
+ } catch {
36392
+ return void 0;
36393
+ }
36394
+ };
36315
36395
  var toRawAmount = (formatted, decimals) => {
36316
36396
  try {
36317
36397
  return parseUnits(formatted.toFixed(decimals), decimals).toString();
@@ -36350,10 +36430,19 @@ var fetchMorphoVaultsFromChain = async (chainId, multicallRetry, prices = {}, to
36350
36430
  const phase1 = await multicallRetry({
36351
36431
  chain: chainId,
36352
36432
  calls: phase1Calls,
36353
- abi: phase1Calls.map(() => MetaMorphoAbi),
36433
+ abi: phase1Calls.map(() => PHASE1_ABI),
36354
36434
  allowFailure: true
36355
36435
  });
36436
+ const adapterLens = entries.map(
36437
+ (_3, i) => Number(phase1[i * PHASE1_PER_VAULT + ADAPTERS_LENGTH_INDEX])
36438
+ );
36439
+ const isV2 = entries.map(({ entry }, i) => {
36440
+ if (entry.version === "v2") return true;
36441
+ if (entry.version === "v1") return false;
36442
+ return Number.isFinite(adapterLens[i]);
36443
+ });
36356
36444
  const queueLens = entries.map((_3, i) => {
36445
+ if (isV2[i]) return 0;
36357
36446
  const n = Number(phase1[i * PHASE1_PER_VAULT + WITHDRAW_QUEUE_LENGTH_INDEX]);
36358
36447
  return Number.isFinite(n) && n > 0 ? n : 0;
36359
36448
  });
@@ -36397,11 +36486,41 @@ var fetchMorphoVaultsFromChain = async (chainId, multicallRetry, prices = {}, to
36397
36486
  ),
36398
36487
  fetchAssetDecimals(chainId, underlyings, multicallRetry)
36399
36488
  ]);
36489
+ const resolveDecimals = (i) => {
36490
+ const { entry } = entries[i];
36491
+ const underlying = entry.underlying?.toLowerCase() ?? "";
36492
+ const decimalsRaw = phase1[i * PHASE1_PER_VAULT + 2];
36493
+ return assetDecimals.get(underlying) ?? tokenList[underlying]?.decimals ?? Number(decimalsRaw ?? 18);
36494
+ };
36495
+ const v2Inputs = entries.map(({ entry }, i) => ({ entry, i })).filter(({ i }) => isV2[i]).map(({ entry, i }) => {
36496
+ const decimals = resolveDecimals(i);
36497
+ const underlying = entry.underlying?.toLowerCase() ?? "";
36498
+ const totalAssets = toStringSafe(phase1[i * PHASE1_PER_VAULT + 3], "0");
36499
+ const oracleKey = toOracleKey(tokenList[underlying]?.assetGroup) ?? toGenericPriceKey(underlying, chainId);
36500
+ return {
36501
+ vault: entry.vault.toLowerCase(),
36502
+ underlying,
36503
+ decimals,
36504
+ totalAssetsFormatted: Number(parseRawAmount(totalAssets, decimals)),
36505
+ feePercent: toNumberSafe(phase1[i * PHASE1_PER_VAULT + PERFORMANCE_FEE_INDEX]) / FEE_SCALE * 100,
36506
+ priceUsd: prices[oracleKey] ?? prices[underlying] ?? 0,
36507
+ adaptersLength: Math.max(0, Math.trunc(adapterLens[i]) || 0)
36508
+ };
36509
+ });
36510
+ const v2ByVault = await fetchV2Allocations(
36511
+ chainId,
36512
+ multicallRetry,
36513
+ v2Inputs,
36514
+ core,
36515
+ tokenList
36516
+ );
36400
36517
  const out = {};
36401
36518
  for (let i = 0; i < entries.length; i++) {
36402
36519
  const { entry } = entries[i];
36403
36520
  const base = i * PHASE1_PER_VAULT;
36404
36521
  const slice = phase1.slice(base, base + CALLS_PER_VAULT);
36522
+ const v2 = isV2[i] ? v2ByVault.get(entry.vault.toLowerCase()) ?? null : null;
36523
+ const v2FeePercent = isV2[i] ? toNumberSafe(phase1[base + PERFORMANCE_FEE_INDEX]) / FEE_SCALE * 100 : void 0;
36405
36524
  const parsed = parseVault3(
36406
36525
  entry,
36407
36526
  slice,
@@ -36411,12 +36530,132 @@ var fetchMorphoVaultsFromChain = async (chainId, multicallRetry, prices = {}, to
36411
36530
  marketIdsByVault[i],
36412
36531
  rateMap,
36413
36532
  positionMap,
36414
- assetDecimals
36533
+ assetDecimals,
36534
+ v2,
36535
+ v2FeePercent
36415
36536
  );
36416
36537
  if (parsed) out[parsed.address] = parsed;
36417
36538
  }
36418
36539
  return out;
36419
36540
  };
36541
+ async function fetchV2Allocations(chainId, multicallRetry, v2, core, tokenList) {
36542
+ const out = /* @__PURE__ */ new Map();
36543
+ if (v2.length === 0) return out;
36544
+ const aCalls = [];
36545
+ const aVaultIdx = [];
36546
+ v2.forEach((v, vi) => {
36547
+ for (let a = 0; a < v.adaptersLength; a++) {
36548
+ aCalls.push({ address: v.vault, name: "adapters", params: [BigInt(a)] });
36549
+ aVaultIdx.push(vi);
36550
+ }
36551
+ });
36552
+ const adaptersByVault = v2.map(() => []);
36553
+ if (aCalls.length > 0) {
36554
+ const aRes = await multicallRetry({
36555
+ chain: chainId,
36556
+ calls: aCalls,
36557
+ abi: aCalls.map(() => VAULT_V2_ABI),
36558
+ allowFailure: true
36559
+ });
36560
+ aRes.forEach((r, k) => {
36561
+ if (isHex40(r)) adaptersByVault[aVaultIdx[k]].push(r.toLowerCase());
36562
+ });
36563
+ }
36564
+ const allAdapters = [...new Set(adaptersByVault.flat())];
36565
+ if (allAdapters.length === 0) return out;
36566
+ const bRes = await multicallRetry({
36567
+ chain: chainId,
36568
+ calls: allAdapters.map((a) => ({
36569
+ address: a,
36570
+ name: "marketIdsLength",
36571
+ params: []
36572
+ })),
36573
+ abi: allAdapters.map(() => VAULT_V2_ADAPTER_ABI),
36574
+ allowFailure: true
36575
+ });
36576
+ const mkLen = /* @__PURE__ */ new Map();
36577
+ allAdapters.forEach((a, i) => {
36578
+ const n = Number(bRes[i]);
36579
+ mkLen.set(a, Number.isFinite(n) && n > 0 ? n : 0);
36580
+ });
36581
+ const cCalls = [];
36582
+ const cAdapter = [];
36583
+ for (const a of allAdapters) {
36584
+ for (let j = 0; j < (mkLen.get(a) ?? 0); j++) {
36585
+ cCalls.push({ address: a, name: "marketIds", params: [BigInt(j)] });
36586
+ cAdapter.push(a);
36587
+ }
36588
+ }
36589
+ const marketIdsByAdapter = new Map(
36590
+ allAdapters.map((a) => [a, []])
36591
+ );
36592
+ if (cCalls.length > 0) {
36593
+ const cRes = await multicallRetry({
36594
+ chain: chainId,
36595
+ calls: cCalls,
36596
+ abi: cCalls.map(() => VAULT_V2_ADAPTER_ABI),
36597
+ allowFailure: true
36598
+ });
36599
+ cRes.forEach((r, k) => {
36600
+ if (isHex64(r)) marketIdsByAdapter.get(cAdapter[k]).push(r.toLowerCase());
36601
+ });
36602
+ }
36603
+ const dCalls = [];
36604
+ const dMeta = [];
36605
+ for (const a of allAdapters) {
36606
+ for (const mid of marketIdsByAdapter.get(a) ?? []) {
36607
+ dCalls.push({ address: a, name: "expectedSupplyAssets", params: [mid] });
36608
+ dMeta.push({ adapter: a, mid });
36609
+ }
36610
+ }
36611
+ const assetsByAdapter = /* @__PURE__ */ new Map();
36612
+ if (dCalls.length > 0) {
36613
+ const dRes = await multicallRetry({
36614
+ chain: chainId,
36615
+ calls: dCalls,
36616
+ abi: dCalls.map(() => VAULT_V2_ADAPTER_ABI),
36617
+ allowFailure: true
36618
+ });
36619
+ dRes.forEach((r, k) => {
36620
+ const v = toBigIntSafe2(r);
36621
+ if (v === void 0) return;
36622
+ const { adapter, mid } = dMeta[k];
36623
+ if (!assetsByAdapter.has(adapter)) assetsByAdapter.set(adapter, /* @__PURE__ */ new Map());
36624
+ assetsByAdapter.get(adapter).set(mid, v);
36625
+ });
36626
+ }
36627
+ const allMids = [...new Set([...marketIdsByAdapter.values()].flat())];
36628
+ const rateMap = await fetchMorphoMarketRates(
36629
+ chainId,
36630
+ core,
36631
+ allMids,
36632
+ multicallRetry
36633
+ );
36634
+ v2.forEach((v, vi) => {
36635
+ const marketAssetsRaw = /* @__PURE__ */ new Map();
36636
+ for (const a of adaptersByVault[vi]) {
36637
+ const m = assetsByAdapter.get(a);
36638
+ if (!m) continue;
36639
+ for (const [mid, amt] of m) {
36640
+ marketAssetsRaw.set(mid, (marketAssetsRaw.get(mid) ?? 0n) + amt);
36641
+ }
36642
+ }
36643
+ out.set(
36644
+ v.vault,
36645
+ computeV2Allocation(
36646
+ v.decimals,
36647
+ v.totalAssetsFormatted,
36648
+ v.feePercent,
36649
+ v.priceUsd,
36650
+ marketAssetsRaw,
36651
+ rateMap,
36652
+ tokenList,
36653
+ { chainId, underlying: v.underlying, protocol: "MORPHO_BLUE" }
36654
+ )
36655
+ );
36656
+ });
36657
+ return out;
36658
+ }
36420
36659
  async function fetchMorphoMarketRates(chainId, core, marketIds, multicallRetry) {
36421
36660
  const map = /* @__PURE__ */ new Map();
36422
36661
  const lens = MORPHO_LENS[chainId];
@@ -36472,7 +36711,7 @@ async function fetchMorphoMarketRates(chainId, core, marketIds, multicallRetry)
36472
36711
  });
36473
36712
  return map;
36474
36713
  }
36475
- function parseVault3(entry, results, chainId, prices, tokenList, marketIds, rateMap, positionMap, assetDecimals) {
36714
+ function parseVault3(entry, results, chainId, prices, tokenList, marketIds, rateMap, positionMap, assetDecimals, v2Allocation, v2FeePercent) {
36476
36715
  const address = entry?.vault?.toLowerCase();
36477
36716
  const underlying = entry?.underlying?.toLowerCase();
36478
36717
  if (!address || !underlying) return null;
@@ -36503,9 +36742,9 @@ function parseVault3(entry, results, chainId, prices, tokenList, marketIds, rate
36503
36742
  const onchainName = toStringSafe(nameRaw).trim();
36504
36743
  const fallbackName = onchainName || (entry.name ?? "").trim();
36505
36744
  const symbol = toStringSafe(symbolRaw);
36506
- const fee = toNumberSafe(feeRaw) / FEE_SCALE * 100;
36745
+ const fee = v2FeePercent !== void 0 ? v2FeePercent : toNumberSafe(feeRaw) / FEE_SCALE * 100;
36507
36746
  const timelock = toNumberSafe(timelockRaw);
36508
- const { depositRate, exposures, liquidityFormatted } = computeVaultAllocation(
36747
+ const { depositRate, exposures, liquidityFormatted } = v2Allocation ?? computeVaultAllocation(
36509
36748
  address,
36510
36749
  decimals,
36511
36750
  totalAssetsFormatted,
@@ -38164,6 +38403,8 @@ var LST_REGISTRY = {
38164
38403
  symbol: "SolvBTC",
38165
38404
  brand: "Solv",
38166
38405
  decimals: 18,
38406
+ underlyingDecimals: 8,
38407
+ // WBTC underlying is 8-dec; share is 18-dec
38167
38408
  reader: "offChain",
38168
38409
  isErc4626: false,
38169
38410
  isRebasing: false,
@@ -38182,6 +38423,8 @@ var LST_REGISTRY = {
38182
38423
  symbol: "xSolvBTC",
38183
38424
  brand: "Solv",
38184
38425
  decimals: 18,
38426
+ underlyingDecimals: 8,
38427
+ // WBTC underlying is 8-dec; share is 18-dec
38185
38428
  reader: "offChain",
38186
38429
  isErc4626: false,
38187
38430
  isRebasing: false,
@@ -38200,6 +38443,8 @@ var LST_REGISTRY = {
38200
38443
  symbol: "BTC+",
38201
38444
  brand: "Solv",
38202
38445
  decimals: 18,
38446
+ underlyingDecimals: 8,
38447
+ // WBTC underlying is 8-dec; share is 18-dec
38203
38448
  reader: "offChain",
38204
38449
  isErc4626: false,
38205
38450
  isRebasing: false,
@@ -38630,6 +38875,8 @@ var LST_REGISTRY = {
38630
38875
  // stake PoL assets in an Infrared vault). Exit is DEX-only.
38631
38876
  address: "0xac03caba51e17c86c921e1f6cbfbdc91f8bb2e6b",
38632
38877
  underlying: "0x656b95e550c07a9ffe548bd4085c72418ceb1dba",
38878
+ // BGT is unpriced; the wrapper is 1:1 redeemable to BERA → price via WBERA.
38879
+ priceUnderlying: "0x6969696969696969696969696969696969696969",
38633
38880
  symbol: "iBGT",
38634
38881
  brand: "Infrared",
38635
38882
  decimals: 18,
@@ -38650,6 +38897,8 @@ var LST_REGISTRY = {
38650
38897
  // queue that pays out native BERA (via BGT.redeem).
38651
38898
  address: "0xbaadcc2962417c01af99fb2b7c75706b9bd6babe",
38652
38899
  underlying: "0x656b95e550c07a9ffe548bd4085c72418ceb1dba",
38900
+ // BGT is unpriced; the wrapper is 1:1 redeemable to BERA → price via WBERA.
38901
+ priceUnderlying: "0x6969696969696969696969696969696969696969",
38653
38902
  symbol: "LBGT",
38654
38903
  brand: "BeraPaw",
38655
38904
  decimals: 18,
@@ -38671,6 +38920,8 @@ var LST_REGISTRY = {
38671
38920
  // native BERA (minus fee).
38672
38921
  address: "0x7e768f47dfdd5dae874aac233f1bc5817137e453",
38673
38922
  underlying: "0x656b95e550c07a9ffe548bd4085c72418ceb1dba",
38923
+ // BGT is unpriced; the wrapper is 1:1 redeemable to BERA → price via WBERA.
38924
+ priceUnderlying: "0x6969696969696969696969696969696969696969",
38674
38925
  symbol: "yBGT",
38675
38926
  brand: "Bearn",
38676
38927
  decimals: 18,
@@ -38689,6 +38940,8 @@ var LST_REGISTRY = {
38689
38940
  // redeem path is unverified, so treated as DEX-only exit.
38690
38941
  address: "0x2cec7f1ac87f5345ced3d6c74bbb61bfae231ffb",
38691
38942
  underlying: "0x656b95e550c07a9ffe548bd4085c72418ceb1dba",
38943
+ // BGT is unpriced; the wrapper is 1:1 redeemable to BERA → price via WBERA.
38944
+ priceUnderlying: "0x6969696969696969696969696969696969696969",
38692
38945
  symbol: "stBGT",
38693
38946
  brand: "Stride",
38694
38947
  decimals: 18,
@@ -38820,6 +39073,8 @@ var LST_REGISTRY = {
38820
39073
  symbol: "pumpBTC",
38821
39074
  brand: "PumpBTC",
38822
39075
  decimals: 8,
39076
+ underlyingDecimals: 18,
39077
+ // SolvBTC.CORE underlying is 18-dec; share is 8-dec
38823
39078
  reader: "offChain",
38824
39079
  isErc4626: false,
38825
39080
  isRebasing: false,
@@ -38934,6 +39189,7 @@ var Erc4626PreviewRedeemAbi = [
38934
39189
 
38935
39190
  // src/vaults/lst/readers/shared.ts
38936
39191
  var ONE_E187 = 10n ** 18n;
39192
+ var rescaleDecimals = (v, fromDec, toDec) => toDec >= fromDec ? v * 10n ** BigInt(toDec - fromDec) : v / 10n ** BigInt(fromDec - toDec);
38937
39193
  var MULTICALL3_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11";
38938
39194
  var Multicall3BalanceAbi = [
38939
39195
  {
@@ -39516,15 +39772,23 @@ var readerMantleMEth = (entry) => {
39516
39772
  };
39517
39773
 
39518
39774
  // src/vaults/lst/readers/offChain.ts
39519
- var readerOffChain = (entry) => ({
39520
- calls: [{ address: entry.address, name: "totalSupply", params: [] }],
39521
- abis: [TotalSupplyAbi],
39522
- parse: ([supply]) => {
39523
- const totalSupply = toBigInt10(supply);
39524
- if (totalSupply === void 0) return void 0;
39525
- return { totalAssets: totalSupply, totalSupply, exchangeRate: ONE_E187 };
39526
- }
39527
- });
39775
+ var readerOffChain = (entry) => {
39776
+ const shareDec = entry.decimals;
39777
+ const underlyingDec = entry.underlyingDecimals ?? entry.decimals;
39778
+ return {
39779
+ calls: [{ address: entry.address, name: "totalSupply", params: [] }],
39780
+ abis: [TotalSupplyAbi],
39781
+ parse: ([supply]) => {
39782
+ const totalSupply = toBigInt10(supply);
39783
+ if (totalSupply === void 0) return void 0;
39784
+ return {
39785
+ totalAssets: rescaleDecimals(totalSupply, shareDec, underlyingDec),
39786
+ totalSupply,
39787
+ exchangeRate: ONE_E187
39788
+ };
39789
+ }
39790
+ };
39791
+ };
39528
39792
 
39529
39793
  // src/vaults/lst/abis/renzo.ts
39530
39794
  var RenzoRestakeManagerAbi = [
@@ -39925,6 +40189,8 @@ var VedaAccountantGetRateAbi = [
39925
40189
  // src/vaults/lst/readers/veda.ts
39926
40190
  var readerVedaAccountant = (entry) => {
39927
40191
  const accountant = entry.readerExtras?.vedaAccountant;
40192
+ const shareDec = entry.decimals;
40193
+ const underlyingDec = entry.underlyingDecimals ?? entry.decimals;
39928
40194
  if (!accountant) {
39929
40195
  return {
39930
40196
  calls: [{ address: entry.address, name: "totalSupply", params: [] }],
@@ -39932,11 +40198,15 @@ var readerVedaAccountant = (entry) => {
39932
40198
  parse: ([supply]) => {
39933
40199
  const totalSupply = toBigInt10(supply);
39934
40200
  if (totalSupply === void 0) return void 0;
39935
- return { totalAssets: totalSupply, totalSupply, exchangeRate: ONE_E187 };
40201
+ return {
40202
+ totalAssets: rescaleDecimals(totalSupply, shareDec, underlyingDec),
40203
+ totalSupply,
40204
+ exchangeRate: ONE_E187
40205
+ };
39936
40206
  }
39937
40207
  };
39938
40208
  }
39939
- const scale = 10n ** BigInt(18 - entry.decimals);
40209
+ const scale = 10n ** BigInt(18 - underlyingDec);
39940
40210
  return {
39941
40211
  calls: [
39942
40212
  { address: entry.address, name: "totalSupply", params: [] },
@@ -39949,7 +40219,11 @@ var readerVedaAccountant = (entry) => {
39949
40219
  if (totalSupply === void 0 || rawRate === void 0) return void 0;
39950
40220
  const exchangeRate = rawRate * scale;
39951
40221
  return {
39952
- totalAssets: totalSupply * exchangeRate / ONE_E187,
40222
+ totalAssets: rescaleDecimals(
40223
+ totalSupply * exchangeRate / ONE_E187,
40224
+ shareDec,
40225
+ underlyingDec
40226
+ ),
39953
40227
  totalSupply,
39954
40228
  exchangeRate
39955
40229
  };
@@ -40295,15 +40569,18 @@ var fetchLstShareTokens = async (chainId, multicallRetry, prices = {}, tokenList
40295
40569
  const addressLc = entry.address.toLowerCase();
40296
40570
  const underlyingLc = entry.underlying.toLowerCase();
40297
40571
  const asset = tokenList[underlyingLc];
40298
- const priceUsd = prices[underlyingLc];
40572
+ const priceUsd = prices[entry.priceUnderlying?.toLowerCase() ?? underlyingLc];
40299
40573
  const supplyRate = aprByAddress[addressLc] ?? 0;
40300
40574
  const rewardsRate = 0;
40301
40575
  const depositRate = supplyRate + rewardsRate;
40302
- const decimalsFactor = 10 ** entry.decimals;
40303
- const totalAssetsFormatted = Number(state.totalAssets) / decimalsFactor;
40576
+ const shareDec = entry.decimals;
40577
+ const underlyingDec = entry.underlyingDecimals ?? entry.decimals;
40578
+ const shareUnit = 10n ** BigInt(shareDec);
40579
+ const underlyingUnit = 10n ** BigInt(underlyingDec);
40580
+ const totalAssetsFormatted = Number(state.totalAssets) / 10 ** underlyingDec;
40304
40581
  const totalAssetsUsd = priceUsd !== void 0 ? totalAssetsFormatted * priceUsd : 0;
40305
- const convertToAssets = state.exchangeRate;
40306
- const convertToShares = state.exchangeRate > 0n ? ONE_E188 * ONE_E188 / state.exchangeRate : 0n;
40582
+ const convertToAssets = state.exchangeRate * underlyingUnit / ONE_E188;
40583
+ const convertToShares = state.exchangeRate > 0n ? ONE_E188 * shareUnit / state.exchangeRate : 0n;
40307
40584
  let liquidityRaw;
40308
40585
  if (state.liquidity !== void 0) {
40309
40586
  liquidityRaw = state.liquidity;
@@ -40311,7 +40588,7 @@ var fetchLstShareTokens = async (chainId, multicallRetry, prices = {}, tokenList
40311
40588
  const idle = idleByAddress.get(addressLc);
40312
40589
  liquidityRaw = idle !== void 0 ? idle > state.totalAssets ? state.totalAssets : idle : 0n;
40313
40590
  }
40314
- const liquidityFormatted = Number(liquidityRaw) / decimalsFactor;
40591
+ const liquidityFormatted = Number(liquidityRaw) / 10 ** underlyingDec;
40315
40592
  const liquidityUsd = priceUsd !== void 0 ? liquidityFormatted * priceUsd : 0;
40316
40593
  const displayName = composeVaultDisplayName(
40317
40594
  entry.brand,
@@ -40331,6 +40608,7 @@ var fetchLstShareTokens = async (chainId, multicallRetry, prices = {}, tokenList
40331
40608
  brand: entry.brand,
40332
40609
  curatorName: entry.brand,
40333
40610
  decimals: entry.decimals,
40611
+ assetDecimals: underlyingDec,
40334
40612
  totalAssets: state.totalAssets.toString(),
40335
40613
  totalSupply: state.totalSupply.toString(),
40336
40614
  convertToShares: convertToShares.toString(),
@@ -43777,6 +44055,7 @@ var fetchSavingsVaults = async (chainId, multicallRetry, prices = {}, tokenList
43777
44055
  brand: entry.brand,
43778
44056
  curatorName: entry.brand,
43779
44057
  decimals: entry.decimals,
44058
+ assetDecimals: underlyingDec,
43780
44059
  totalAssets: state.totalAssets.toString(),
43781
44060
  totalSupply: state.totalSupply.toString(),
43782
44061
  convertToShares: convertToShares.toString(),
@@ -44501,7 +44780,18 @@ var stampVaultClassification = (data, chainId, tokenList = {}) => {
44501
44780
  });
44502
44781
  v.yieldProfile = c.yieldProfile;
44503
44782
  v.denomination = c.denomination;
44504
- v.sharePrice = v.convertToAssets ?? v.pricePerShare;
44783
+ const raw = v.convertToAssets ?? v.pricePerShare;
44784
+ if (raw != null) {
44785
+ v.sharePriceRaw = raw;
44786
+ const assetDec = v.assetDecimals ?? v.decimals;
44787
+ if (assetDec != null) {
44788
+ const formatted = Number(raw) / 10 ** assetDec;
44789
+ if (Number.isFinite(formatted)) {
44790
+ v.sharePrice = formatted;
44791
+ if (v.priceUsd != null) v.sharePriceUSD = formatted * v.priceUsd;
44792
+ }
44793
+ }
44794
+ }
44505
44795
  }
44506
44796
  };
44507
44797
  stampBag(data.fluid, "fluid");
@@ -45775,7 +46065,9 @@ function buildVaultLookup(data) {
45775
46065
  // provider objects before the lookup is built).
45776
46066
  yieldProfile: v.yieldProfile,
45777
46067
  denomination: v.denomination,
45778
- sharePrice: v.sharePrice
46068
+ sharePriceRaw: v.sharePriceRaw,
46069
+ sharePrice: v.sharePrice,
46070
+ sharePriceUSD: v.sharePriceUSD
45779
46071
  });
45780
46072
  }
45781
46073
  };