@1delta/margin-fetcher 0.0.217 → 0.0.218

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
@@ -8471,18 +8471,18 @@ var populateEModes32 = (borrowCollateralFactor, collateralFactor, collateralBitm
8471
8471
  data[e].borrowCollateralFactor = borrowCollateralFactor;
8472
8472
  data[e].debtDisabled = !!eModeConfigs[e];
8473
8473
  if (eModeConfigs[e]) {
8474
- data[e] = {
8475
- ...data[e],
8476
- category: e,
8477
- borrowCollateralFactor: eModeConfigs[e]?.borrowCollateralFactor ?? 0,
8478
- collateralFactor: eModeConfigs[e]?.collateralFactor ?? 0,
8479
- borrowFactor: 1,
8480
- collateralDisabled: !isReserveEnabledOnBitmap(
8481
- collateralBitmap[e],
8482
- assetIndex
8483
- ),
8484
- debtDisabled: !isReserveEnabledOnBitmap(debtBitmap[e], assetIndex)
8485
- };
8474
+ data[e].category = e;
8475
+ data[e].borrowCollateralFactor = eModeConfigs[e]?.borrowCollateralFactor ?? 0;
8476
+ data[e].collateralFactor = eModeConfigs[e]?.collateralFactor ?? 0;
8477
+ data[e].borrowFactor = 1;
8478
+ data[e].collateralDisabled = !isReserveEnabledOnBitmap(
8479
+ collateralBitmap[e],
8480
+ assetIndex
8481
+ );
8482
+ data[e].debtDisabled = !isReserveEnabledOnBitmap(
8483
+ debtBitmap[e],
8484
+ assetIndex
8485
+ );
8486
8486
  }
8487
8487
  }
8488
8488
  }
@@ -8777,65 +8777,61 @@ var getInitReservesDataConverter = (lender, chainId, prices, additionalYields, t
8777
8777
  return void 0;
8778
8778
  }
8779
8779
  const modeOne = 0;
8780
- let result = Object.assign(
8781
- {},
8782
- ...data[modeOne]?.map((dat) => {
8783
- const asset = dat?.underlying.toLowerCase();
8784
- const meta = tokenList[asset];
8785
- const totalDeposits = parseRawAmount(
8786
- dat?.totalSupply.toString(),
8787
- meta?.decimals
8788
- );
8789
- const totalDebt = parseRawAmount(
8790
- dat?.totalDebt.toString(),
8780
+ const result = {};
8781
+ data[modeOne]?.forEach((dat) => {
8782
+ const asset = dat?.underlying.toLowerCase();
8783
+ const meta = tokenList[asset];
8784
+ const totalDeposits = parseRawAmount(
8785
+ dat?.totalSupply.toString(),
8786
+ meta?.decimals
8787
+ );
8788
+ const totalDebt = parseRawAmount(
8789
+ dat?.totalDebt.toString(),
8790
+ meta.decimals
8791
+ );
8792
+ const oracleKey = toOracleKey(meta?.assetGroup) ?? toGenericPriceKey(asset, chainId);
8793
+ const price = prices[oracleKey];
8794
+ const liquidity = Number(totalDeposits) - Number(totalDebt);
8795
+ const poolId = underlyingToPoolMap.get(asset);
8796
+ const params = !!poolId ? { metadata: { poolId } } : void 0;
8797
+ if (!poolId) return;
8798
+ const marketUid = createMarketUid(chainId, lender, poolId);
8799
+ const name = INIT_POOL_NAME_OVERRIDES[poolId.toLowerCase()] ?? lenderShortName(lender) + " " + (meta?.symbol ?? "");
8800
+ result[asset] = {
8801
+ marketUid,
8802
+ name,
8803
+ poolId: asset,
8804
+ underlying: asset,
8805
+ asset: meta,
8806
+ borrowCap: parseRawAmount(
8807
+ dat?.borrowCap.toString(),
8791
8808
  meta.decimals
8792
- );
8793
- const oracleKey = toOracleKey(meta?.assetGroup) ?? toGenericPriceKey(asset, chainId);
8794
- const price = prices[oracleKey];
8795
- const liquidity = Number(totalDeposits) - Number(totalDebt);
8796
- const poolId = underlyingToPoolMap.get(asset);
8797
- const params = !!poolId ? { metadata: { poolId } } : void 0;
8798
- if (!poolId) return;
8799
- const marketUid = createMarketUid(chainId, lender, poolId);
8800
- const name = INIT_POOL_NAME_OVERRIDES[poolId.toLowerCase()] ?? lenderShortName(lender) + " " + (meta?.symbol ?? "");
8801
- return {
8802
- [asset]: {
8803
- marketUid,
8804
- name,
8805
- poolId: asset,
8806
- underlying: asset,
8807
- asset: meta,
8808
- borrowCap: parseRawAmount(
8809
- dat?.borrowCap.toString(),
8810
- meta.decimals
8811
- ),
8812
- canBurn: Boolean(dat?.canBurn),
8813
- canFlash: Boolean(dat?.canFlash),
8814
- canMint: Boolean(dat?.canMint),
8815
- canRepay: Boolean(dat?.canRepay),
8816
- totalDeposits,
8817
- totalDebt,
8818
- totalDepositsUSD: price * Number(totalDeposits),
8819
- totalDebtUSD: price * Number(totalDebt),
8820
- totalLiquidity: liquidity,
8821
- totalLiquidityUSD: liquidity * price,
8822
- depositRate: convertRateToApr(
8823
- Number(parseRawAmount(dat?.supplyRate.toString(), 18))
8824
- ),
8825
- variableBorrowRate: convertRateToApr(
8826
- Number(parseRawAmount(dat?.borrowRate.toString(), 18))
8827
- ),
8828
- stableBorrowRate: 0,
8829
- collateralActive: true,
8830
- intrinsicYield: additionalYields?.intrinsicYields?.[oracleKey] ?? 0,
8831
- rewards: [],
8832
- config: {},
8833
- borrowingEnabled: totalDebt !== "0",
8834
- params
8835
- }
8836
- };
8837
- })
8838
- );
8809
+ ),
8810
+ canBurn: Boolean(dat?.canBurn),
8811
+ canFlash: Boolean(dat?.canFlash),
8812
+ canMint: Boolean(dat?.canMint),
8813
+ canRepay: Boolean(dat?.canRepay),
8814
+ totalDeposits,
8815
+ totalDebt,
8816
+ totalDepositsUSD: price * Number(totalDeposits),
8817
+ totalDebtUSD: price * Number(totalDebt),
8818
+ totalLiquidity: liquidity,
8819
+ totalLiquidityUSD: liquidity * price,
8820
+ depositRate: convertRateToApr(
8821
+ Number(parseRawAmount(dat?.supplyRate.toString(), 18))
8822
+ ),
8823
+ variableBorrowRate: convertRateToApr(
8824
+ Number(parseRawAmount(dat?.borrowRate.toString(), 18))
8825
+ ),
8826
+ stableBorrowRate: 0,
8827
+ collateralActive: true,
8828
+ intrinsicYield: additionalYields?.intrinsicYields?.[oracleKey] ?? 0,
8829
+ rewards: [],
8830
+ config: {},
8831
+ borrowingEnabled: totalDebt !== "0",
8832
+ params
8833
+ };
8834
+ });
8839
8835
  let eModes = {};
8840
8836
  INIT_MODES.forEach((mode, index) => {
8841
8837
  data[index]?.forEach((multicallData) => {
@@ -8859,11 +8855,12 @@ var getInitReservesDataConverter = (lender, chainId, prices, additionalYields, t
8859
8855
  result[asset].config[mode] = modeData;
8860
8856
  });
8861
8857
  });
8862
- Object.entries(eModes).forEach(([modeId, data2]) => {
8863
- Object.entries(result)?.forEach(([key, _3]) => {
8858
+ Object.entries(eModes).forEach(([modeId, modeData]) => {
8859
+ Object.entries(result).forEach(([key, _3]) => {
8864
8860
  if (!result[key].config[modeId]) {
8865
- let mode = {
8866
- ...data2,
8861
+ result[key].config[modeId] = {
8862
+ label: modeData.label,
8863
+ category: modeData.category,
8867
8864
  debtDisabled: true,
8868
8865
  collateralDisabled: true,
8869
8866
  collateralFactor: 0,
@@ -8871,7 +8868,6 @@ var getInitReservesDataConverter = (lender, chainId, prices, additionalYields, t
8871
8868
  borrowFactor: 3402823669209385e5
8872
8869
  // disabled flag
8873
8870
  };
8874
- result[key].config[modeId] = mode;
8875
8871
  }
8876
8872
  });
8877
8873
  });
@@ -17899,6 +17895,7 @@ var getEulerV2ReservesDataConverter = (lender, chainId, prices, additionalYields
17899
17895
  // src/lending/public-data/aave-v4-type/publicCallBuild.ts
17900
17896
  var BASE_CALLS_PER_RESERVE = 5;
17901
17897
  var CALLS_PER_SPOKE_TAIL = 2;
17898
+ var MAX_HUB_ASSETS = 25;
17902
17899
  function isValidAddress(addr) {
17903
17900
  return !!addr && addr !== "0x" && addr.length > 2;
17904
17901
  }
@@ -17914,8 +17911,6 @@ var buildAaveV4LenderReserveCall = (chainId, lender) => {
17914
17911
  const reservesMap = aaveV4Reserves()?.[lender]?.[chainId] ?? {};
17915
17912
  if (spokes.length === 0) return [];
17916
17913
  const calls = [];
17917
- const hubAssetKeys = /* @__PURE__ */ new Set();
17918
- const hubAssetList = [];
17919
17914
  for (const spokeEntry of spokes) {
17920
17915
  if (!isValidAddress(spokeEntry.spoke)) continue;
17921
17916
  const spokeAddr = spokeEntry.spoke;
@@ -17957,17 +17952,6 @@ var buildAaveV4LenderReserveCall = (chainId, lender) => {
17957
17952
  params: [rid, key]
17958
17953
  });
17959
17954
  }
17960
- if (typeof entry === "object" && spokeEntry.hub && entry.assetId !== void 0) {
17961
- const hubLc = spokeEntry.hub.toLowerCase();
17962
- const key = `${hubLc}:${entry.assetId}`;
17963
- if (!hubAssetKeys.has(key)) {
17964
- hubAssetKeys.add(key);
17965
- hubAssetList.push({
17966
- hub: hubLc,
17967
- assetId: entry.assetId
17968
- });
17969
- }
17970
- }
17971
17955
  }
17972
17956
  calls.push(
17973
17957
  {
@@ -17984,10 +17968,7 @@ var buildAaveV4LenderReserveCall = (chainId, lender) => {
17984
17968
  }
17985
17969
  for (const spokeEntry of spokes) {
17986
17970
  if (!isValidAddress(spokeEntry.spoke)) continue;
17987
- const reserves = getSpokeReserves(
17988
- reservesMap,
17989
- spokeEntry.spoke
17990
- );
17971
+ const reserves = getSpokeReserves(reservesMap, spokeEntry.spoke);
17991
17972
  const rids = reserves.map(
17992
17973
  (e) => typeof e === "number" ? e : e.reserveId
17993
17974
  );
@@ -17999,24 +17980,33 @@ var buildAaveV4LenderReserveCall = (chainId, lender) => {
17999
17980
  });
18000
17981
  }
18001
17982
  }
18002
- for (const { hub, assetId } of hubAssetList) {
18003
- calls.push(
18004
- {
18005
- address: hub,
18006
- name: "getAsset",
18007
- params: [assetId]
18008
- },
18009
- {
18010
- address: hub,
18011
- name: "getAddedAssets",
18012
- params: [assetId]
18013
- },
18014
- {
18015
- address: hub,
18016
- name: "getAssetTotalOwed",
18017
- params: [assetId]
18018
- }
18019
- );
17983
+ const hubEntry = aaveV4Hubs()?.[lender]?.[chainId];
17984
+ if (hubEntry?.hub && isValidAddress(hubEntry.hub)) {
17985
+ const hubAddr = hubEntry.hub.toLowerCase();
17986
+ calls.push({
17987
+ address: hubAddr,
17988
+ name: "getAssetCount",
17989
+ params: []
17990
+ });
17991
+ for (let i = 0; i < MAX_HUB_ASSETS; i++) {
17992
+ calls.push(
17993
+ {
17994
+ address: hubAddr,
17995
+ name: "getAsset",
17996
+ params: [i]
17997
+ },
17998
+ {
17999
+ address: hubAddr,
18000
+ name: "getAddedAssets",
18001
+ params: [i]
18002
+ },
18003
+ {
18004
+ address: hubAddr,
18005
+ name: "getAssetTotalOwed",
18006
+ params: [i]
18007
+ }
18008
+ );
18009
+ }
18020
18010
  }
18021
18011
  return calls;
18022
18012
  };
@@ -18024,13 +18014,9 @@ var getAaveV4ExpectedCallCount = (chainId, lender) => {
18024
18014
  const spokes = aaveV4Spokes()?.[lender]?.[chainId] ?? [];
18025
18015
  const reservesMap = aaveV4Reserves()?.[lender]?.[chainId] ?? {};
18026
18016
  let count = 0;
18027
- const hubAssetKeys = /* @__PURE__ */ new Set();
18028
18017
  for (const spokeEntry of spokes) {
18029
18018
  if (!isValidAddress(spokeEntry.spoke)) continue;
18030
- const reserves = getSpokeReserves(
18031
- reservesMap,
18032
- spokeEntry.spoke
18033
- );
18019
+ const reserves = getSpokeReserves(reservesMap, spokeEntry.spoke);
18034
18020
  const dynConfigCount = getDynamicConfigCount(spokeEntry);
18035
18021
  count += reserves.length * (BASE_CALLS_PER_RESERVE + dynConfigCount) + CALLS_PER_SPOKE_TAIL;
18036
18022
  const rids = reserves.map(
@@ -18039,15 +18025,11 @@ var getAaveV4ExpectedCallCount = (chainId, lender) => {
18039
18025
  if (rids.length > 0 && isValidAddress(spokeEntry.oracle)) {
18040
18026
  count += 1;
18041
18027
  }
18042
- for (const entry of reserves) {
18043
- if (typeof entry === "object" && spokeEntry.hub && entry.assetId !== void 0) {
18044
- hubAssetKeys.add(
18045
- `${spokeEntry.hub.toLowerCase()}:${entry.assetId}`
18046
- );
18047
- }
18048
- }
18049
18028
  }
18050
- count += hubAssetKeys.size * 3;
18029
+ const hubEntry = aaveV4Hubs()?.[lender]?.[chainId];
18030
+ if (hubEntry?.hub && isValidAddress(hubEntry.hub)) {
18031
+ count += 1 + MAX_HUB_ASSETS * 3;
18032
+ }
18051
18033
  return count;
18052
18034
  };
18053
18035
 
@@ -18062,9 +18044,10 @@ function toTokenNumber(raw, decimals) {
18062
18044
  return Number(raw) / 10 ** decimals;
18063
18045
  }
18064
18046
  var RAY2 = 1e27;
18047
+ var SECONDS_PER_YEAR4 = 31536e3;
18065
18048
  function rayRateToApr(rateRay) {
18066
18049
  if (rateRay === 0n) return 0;
18067
- return Number(rateRay) / RAY2 * 100;
18050
+ return (Number(rateRay) / RAY2 - 1) * SECONDS_PER_YEAR4 * 100;
18068
18051
  }
18069
18052
  function normalizeAaveV4(spokeDataList, chainId, lender, prices, additionalYields, tokenList, lenderShortNameFn, createMarketUidFn, toOracleKeyFn, toGenericPriceKeyFn, expectedHub) {
18070
18053
  const data = {};
@@ -18098,9 +18081,7 @@ function normalizeAaveV4(spokeDataList, chainId, lender, prices, additionalYield
18098
18081
  continue;
18099
18082
  const underlying = reserve.reserve.underlying.toLowerCase();
18100
18083
  const decimals = reserve.reserve.decimals;
18101
- const hubAddr = reserve.reserve.hub.toLowerCase();
18102
- const refAddress = `${hubAddr}:${underlying}`;
18103
- const marketUid = createMarketUidFn(chainId, lender, refAddress);
18084
+ const marketUid = createMarketUidFn(chainId, lender, underlying);
18104
18085
  const assetMeta = tokenList[underlying];
18105
18086
  const oracleKey = toOracleKeyFn(assetMeta?.assetGroup ?? null) ?? toGenericPriceKeyFn(underlying, chainId);
18106
18087
  let price = 0;
@@ -18162,47 +18143,59 @@ function normalizeAaveV4(spokeDataList, chainId, lender, prices, additionalYield
18162
18143
  debtDisabled: !reserve.config.borrowable || reserve.config.paused
18163
18144
  };
18164
18145
  }
18165
- data[marketUid] = {
18166
- marketUid,
18167
- name: lenderShortNameFn(lender) + " " + (assetMeta?.symbol ?? ""),
18168
- poolId: underlying,
18169
- underlying,
18170
- asset: assetMeta,
18171
- totalDeposits,
18172
- totalDebtStable: "0",
18173
- totalDebt,
18174
- totalLiquidity: liquidity,
18175
- totalDepositsUSD: totalDepositsNum * price,
18176
- totalDebtStableUSD: 0,
18177
- totalDebtUSD: totalDebtNum * price,
18178
- totalLiquidityUSD: liquidity * price,
18179
- depositRate,
18180
- variableBorrowRate,
18181
- stableBorrowRate: 0,
18182
- intrinsicYield: additionalYields?.intrinsicYields?.[oracleKey] ?? 0,
18183
- rewards: [],
18184
- decimals,
18185
- config,
18186
- collateralActive: Object.values(reserve.dynamicConfigs).some(
18187
- (c) => c.collateralFactor > 0
18188
- ),
18189
- borrowingEnabled: reserve.config.borrowable,
18190
- hasStable: false,
18191
- isActive: !reserve.config.paused,
18192
- isFrozen: reserve.config.frozen,
18193
- borrowCap: 0,
18194
- supplyCap: 0,
18195
- debtCeiling: 0,
18196
- params: {
18197
- metadata: {
18198
- spoke: spokeAddr,
18199
- hub: reserve.reserve.hub.toLowerCase(),
18200
- assetId: reserve.reserve.assetId,
18201
- reserveId: reserve.reserveId,
18202
- oracle: spokeData.oracle.toLowerCase()
18203
- }
18146
+ if (data[marketUid]) {
18147
+ Object.assign(data[marketUid].config, config);
18148
+ if (!data[marketUid].collateralActive) {
18149
+ data[marketUid].collateralActive = Object.values(reserve.dynamicConfigs).some(
18150
+ (c) => c.collateralFactor > 0
18151
+ );
18204
18152
  }
18205
- };
18153
+ if (!data[marketUid].borrowingEnabled) {
18154
+ data[marketUid].borrowingEnabled = reserve.config.borrowable;
18155
+ }
18156
+ } else {
18157
+ data[marketUid] = {
18158
+ marketUid,
18159
+ name: lenderShortNameFn(lender) + " " + (assetMeta?.symbol ?? ""),
18160
+ poolId: underlying,
18161
+ underlying,
18162
+ asset: assetMeta,
18163
+ totalDeposits,
18164
+ totalDebtStable: "0",
18165
+ totalDebt,
18166
+ totalLiquidity: liquidity,
18167
+ totalDepositsUSD: totalDepositsNum * price,
18168
+ totalDebtStableUSD: 0,
18169
+ totalDebtUSD: totalDebtNum * price,
18170
+ totalLiquidityUSD: liquidity * price,
18171
+ depositRate,
18172
+ variableBorrowRate,
18173
+ stableBorrowRate: 0,
18174
+ intrinsicYield: additionalYields?.intrinsicYields?.[oracleKey] ?? 0,
18175
+ rewards: [],
18176
+ decimals,
18177
+ config,
18178
+ collateralActive: Object.values(reserve.dynamicConfigs).some(
18179
+ (c) => c.collateralFactor > 0
18180
+ ),
18181
+ borrowingEnabled: reserve.config.borrowable,
18182
+ hasStable: false,
18183
+ isActive: !reserve.config.paused,
18184
+ isFrozen: reserve.config.frozen,
18185
+ borrowCap: 0,
18186
+ supplyCap: 0,
18187
+ debtCeiling: 0,
18188
+ params: {
18189
+ metadata: {
18190
+ spoke: spokeAddr,
18191
+ hub: reserve.reserve.hub.toLowerCase(),
18192
+ assetId: reserve.reserve.assetId,
18193
+ reserveId: reserve.reserveId,
18194
+ oracle: spokeData.oracle.toLowerCase()
18195
+ }
18196
+ }
18197
+ };
18198
+ }
18206
18199
  }
18207
18200
  }
18208
18201
  return { data, chainId, eModes };
@@ -18223,8 +18216,6 @@ var getAaveV4ReservesDataConverter = (lender, chainId, prices, additionalYields,
18223
18216
  const reservesMap = aaveV4Reserves()?.[lender]?.[chainId] ?? {};
18224
18217
  let offset = 0;
18225
18218
  const spokeDataList = [];
18226
- const hubAssetKeys = /* @__PURE__ */ new Set();
18227
- const hubAssetList = [];
18228
18219
  for (const spokeEntry of spokes) {
18229
18220
  if (!isValidAddress2(spokeEntry.spoke)) continue;
18230
18221
  const spokeAddr = spokeEntry.spoke;
@@ -18286,17 +18277,6 @@ var getAaveV4ReservesDataConverter = (lender, chainId, prices, additionalYields,
18286
18277
  } else {
18287
18278
  drawnDebt = BigInt(rawDebt ?? 0);
18288
18279
  }
18289
- if (spokeEntry.hub && typeof entry === "object" && entry.assetId !== void 0) {
18290
- const hubLc = spokeEntry.hub.toLowerCase();
18291
- const key = `${hubLc}:${entry.assetId}`;
18292
- if (!hubAssetKeys.has(key)) {
18293
- hubAssetKeys.add(key);
18294
- hubAssetList.push({
18295
- hub: hubLc,
18296
- assetId: entry.assetId
18297
- });
18298
- }
18299
- }
18300
18280
  parsedReserves.push({
18301
18281
  reserveId,
18302
18282
  reserve,
@@ -18350,40 +18330,51 @@ var getAaveV4ReservesDataConverter = (lender, chainId, prices, additionalYields,
18350
18330
  }
18351
18331
  }
18352
18332
  }
18333
+ const hubEntry = aaveV4Hubs()?.[lender]?.[chainId];
18353
18334
  const hubAssetMap = /* @__PURE__ */ new Map();
18354
- for (let hi = 0; hi < hubAssetList.length; hi++) {
18355
- const baseIdx = offset + hi * 3;
18356
- const rawHubAsset = data[baseIdx];
18357
- const rawAddedAssets = data[baseIdx + 1];
18358
- const rawTotalOwed = data[baseIdx + 2];
18359
- if (!rawHubAsset || rawHubAsset === "0x") continue;
18360
- const underlying = (rawHubAsset?.underlying ?? "").toLowerCase();
18361
- const key = underlying || `${hubAssetList[hi].hub}:${hubAssetList[hi].assetId}`;
18362
- hubAssetMap.set(key, {
18363
- liquidity: BigInt(rawHubAsset?.liquidity ?? 0),
18364
- realizedFees: BigInt(rawHubAsset?.realizedFees ?? 0),
18365
- decimals: Number(rawHubAsset?.decimals ?? 18),
18366
- addedShares: BigInt(rawHubAsset?.addedShares ?? 0),
18367
- swept: BigInt(rawHubAsset?.swept ?? 0),
18368
- premiumOffsetRay: BigInt(
18369
- rawHubAsset?.premiumOffsetRay ?? 0
18370
- ),
18371
- drawnShares: BigInt(rawHubAsset?.drawnShares ?? 0),
18372
- premiumShares: BigInt(rawHubAsset?.premiumShares ?? 0),
18373
- liquidityFee: Number(rawHubAsset?.liquidityFee ?? 0),
18374
- drawnIndex: BigInt(rawHubAsset?.drawnIndex ?? 0),
18375
- drawnRate: BigInt(rawHubAsset?.drawnRate ?? 0),
18376
- lastUpdateTimestamp: Number(
18377
- rawHubAsset?.lastUpdateTimestamp ?? 0
18378
- ),
18379
- underlying: rawHubAsset?.underlying ?? "",
18380
- irStrategy: rawHubAsset?.irStrategy ?? "",
18381
- reinvestmentController: rawHubAsset?.reinvestmentController ?? "",
18382
- feeReceiver: rawHubAsset?.feeReceiver ?? "",
18383
- deficitRay: BigInt(rawHubAsset?.deficitRay ?? 0),
18384
- totalAddedAssets: BigInt(rawAddedAssets ?? 0),
18385
- totalOwedAssets: BigInt(rawTotalOwed ?? 0)
18386
- });
18335
+ if (hubEntry?.hub && isValidAddress2(hubEntry.hub)) {
18336
+ const rawAssetCount = data[offset];
18337
+ offset += 1;
18338
+ const assetCount = Math.min(
18339
+ Number(rawAssetCount ?? 0),
18340
+ MAX_HUB_ASSETS
18341
+ );
18342
+ for (let i = 0; i < MAX_HUB_ASSETS; i++) {
18343
+ const baseIdx = offset + i * 3;
18344
+ const rawHubAsset = data[baseIdx];
18345
+ const rawAddedAssets = data[baseIdx + 1];
18346
+ const rawTotalOwed = data[baseIdx + 2];
18347
+ if (i >= assetCount || !rawHubAsset || rawHubAsset === "0x")
18348
+ continue;
18349
+ const underlying = (rawHubAsset?.underlying ?? "").toLowerCase();
18350
+ if (!underlying) continue;
18351
+ hubAssetMap.set(underlying, {
18352
+ liquidity: BigInt(rawHubAsset?.liquidity ?? 0),
18353
+ realizedFees: BigInt(rawHubAsset?.realizedFees ?? 0),
18354
+ decimals: Number(rawHubAsset?.decimals ?? 18),
18355
+ addedShares: BigInt(rawHubAsset?.addedShares ?? 0),
18356
+ swept: BigInt(rawHubAsset?.swept ?? 0),
18357
+ premiumOffsetRay: BigInt(
18358
+ rawHubAsset?.premiumOffsetRay ?? 0
18359
+ ),
18360
+ drawnShares: BigInt(rawHubAsset?.drawnShares ?? 0),
18361
+ premiumShares: BigInt(rawHubAsset?.premiumShares ?? 0),
18362
+ liquidityFee: Number(rawHubAsset?.liquidityFee ?? 0),
18363
+ drawnIndex: BigInt(rawHubAsset?.drawnIndex ?? 0),
18364
+ drawnRate: BigInt(rawHubAsset?.drawnRate ?? 0),
18365
+ lastUpdateTimestamp: Number(
18366
+ rawHubAsset?.lastUpdateTimestamp ?? 0
18367
+ ),
18368
+ underlying: rawHubAsset?.underlying ?? "",
18369
+ irStrategy: rawHubAsset?.irStrategy ?? "",
18370
+ reinvestmentController: rawHubAsset?.reinvestmentController ?? "",
18371
+ feeReceiver: rawHubAsset?.feeReceiver ?? "",
18372
+ deficitRay: BigInt(rawHubAsset?.deficitRay ?? 0),
18373
+ totalAddedAssets: BigInt(rawAddedAssets ?? 0),
18374
+ totalOwedAssets: BigInt(rawTotalOwed ?? 0)
18375
+ });
18376
+ }
18377
+ offset += MAX_HUB_ASSETS * 3;
18387
18378
  }
18388
18379
  for (const spokeData of spokeDataList) {
18389
18380
  for (const reserve of spokeData.reserves) {
@@ -18396,7 +18387,6 @@ var getAaveV4ReservesDataConverter = (lender, chainId, prices, additionalYields,
18396
18387
  }
18397
18388
  }
18398
18389
  }
18399
- const hubEntry = aaveV4Hubs()?.[lender]?.[chainId];
18400
18390
  const expectedHub = hubEntry?.hub;
18401
18391
  return normalizeAaveV4(
18402
18392
  spokeDataList,
@@ -18549,7 +18539,7 @@ var getLenderPublicData = async (chainId, lenders, prices, additionalYields, mul
18549
18539
  const abi = getAbi(lender);
18550
18540
  const callData = buildLenderCall(chainId, lender);
18551
18541
  const mappedCalls = callData.map((call) => ({ call, abi: call.abi ?? abi }));
18552
- calls = [...calls, ...mappedCalls];
18542
+ calls.push(...mappedCalls);
18553
18543
  }
18554
18544
  const [rawResults, list] = await Promise.all([
18555
18545
  multicallRetry({
@@ -18558,7 +18548,7 @@ var getLenderPublicData = async (chainId, lenders, prices, additionalYields, mul
18558
18548
  abi: calls.map((call) => call.abi),
18559
18549
  batchSize: chainId === Chain.ETHEREUM_MAINNET ? 500 : void 0
18560
18550
  }),
18561
- await tokenList()
18551
+ tokenList()
18562
18552
  ]);
18563
18553
  const invalidLenders = [];
18564
18554
  let lenderData = {};
@@ -18579,7 +18569,7 @@ var getLenderPublicData = async (chainId, lenders, prices, additionalYields, mul
18579
18569
  if (!convertedData) {
18580
18570
  invalidLenders.push(lender);
18581
18571
  } else {
18582
- lenderData = { ...lenderData, ...convertedData };
18572
+ Object.assign(lenderData, convertedData);
18583
18573
  }
18584
18574
  } else {
18585
18575
  if (!convertedData) {
@@ -18652,9 +18642,7 @@ var getLenderPublicDataViaApi = async (chainId, lenders, prices, additionalYield
18652
18642
  additionalYields,
18653
18643
  list
18654
18644
  );
18655
- Object.keys(converted).forEach((marketId) => {
18656
- lenderData[marketId] = converted[marketId];
18657
- });
18645
+ Object.assign(lenderData, converted);
18658
18646
  } else {
18659
18647
  lenderData[lender] = convertLenderDataFromApi(
18660
18648
  lender,
@@ -20283,10 +20271,15 @@ function resolveV4Config(configs, userConfigKey) {
20283
20271
  const spokeAddr = key.split(":")[0];
20284
20272
  return { config, spokeAddr };
20285
20273
  }
20286
- function getConfigScopedPrice(meta, spokeAddr, configPriceMap) {
20274
+ function getConfigScopedPrice(meta, spokeAddr) {
20275
+ if (spokeAddr) {
20276
+ const byConfig = meta?.oraclePrice?.byConfig;
20277
+ const configPrice = byConfig?.[spokeAddr]?.oraclePriceUsd;
20278
+ if (configPrice != null && configPrice > 0) return configPrice;
20279
+ }
20287
20280
  return getOraclePrice(meta);
20288
20281
  }
20289
- function createAaveV4UserState(payload, lenderData, totalDeposits24h = 0, totalDebt24h = 0, configPriceMap) {
20282
+ function createAaveV4UserState(payload, lenderData, totalDeposits24h = 0, totalDebt24h = 0) {
20290
20283
  const assetKeys = getMarketUidsFromMeta(lenderData);
20291
20284
  const { chainId, account } = payload;
20292
20285
  let depositInterest = 0;
@@ -20395,7 +20388,7 @@ function createAaveV4UserState(payload, lenderData, totalDeposits24h = 0, totalD
20395
20388
  configs,
20396
20389
  pos ? pos.userConfigKey : void 0
20397
20390
  );
20398
- const price = getConfigScopedPrice(meta);
20391
+ const price = getConfigScopedPrice(meta, spokeAddr);
20399
20392
  const bcf = config?.borrowCollateralFactor ?? 1;
20400
20393
  const bf = config?.borrowFactor ?? 1;
20401
20394
  if (pos) {
@@ -20490,7 +20483,6 @@ var getAaveV4UserDataConverter = (lender, chainId, account, metaMap) => {
20490
20483
  reserveEntries.push({
20491
20484
  spokeAddr,
20492
20485
  reserveId: rid,
20493
- hub: (spokeEntry.hub ?? "").toLowerCase(),
20494
20486
  underlying
20495
20487
  });
20496
20488
  }
@@ -20512,28 +20504,25 @@ var getAaveV4UserDataConverter = (lender, chainId, account, metaMap) => {
20512
20504
  let totalDebt24h = 0;
20513
20505
  let totalDeposits24h = 0;
20514
20506
  for (let i = 0; i < reserveEntries.length; i++) {
20515
- const { hub, underlying, spokeAddr } = reserveEntries[i];
20516
- let key;
20517
- if (hub) {
20518
- key = createMarketUid(chainId, lender, `${hub}:${underlying}`);
20519
- } else {
20520
- key = underlyingToUid.get(underlying) ?? createMarketUid(chainId, lender, `:${underlying}`);
20521
- }
20507
+ const { underlying, spokeAddr } = reserveEntries[i];
20508
+ const key = underlying ? createMarketUid(chainId, lender, underlying) : underlyingToUid.get(underlying) ?? "";
20522
20509
  const metaEntity = metaMap?.[key];
20523
20510
  if (!metaEntity) continue;
20524
20511
  const base = i * USER_CALLS_PER_RESERVE;
20512
+ const spokeLc = spokeAddr.toLowerCase();
20513
+ const userPositionResult = data[base + 3];
20514
+ const userDynConfigKey = Number(
20515
+ userPositionResult?.dynamicConfigKey ?? 0
20516
+ );
20525
20517
  const { dataForAsset, addedDebt, addedDeposits } = createAaveV4Entry(
20526
20518
  base,
20527
20519
  data,
20528
20520
  key,
20529
- metaEntity
20521
+ metaEntity,
20522
+ spokeLc
20530
20523
  );
20531
20524
  if (!dataForAsset) continue;
20532
- const userPositionResult = data[base + 3];
20533
- const userDynConfigKey = Number(
20534
- userPositionResult?.dynamicConfigKey ?? 0
20535
- );
20536
- dataForAsset.userConfigKey = `${spokeAddr.toLowerCase()}:${userDynConfigKey}`;
20525
+ dataForAsset.userConfigKey = `${spokeLc}:${userDynConfigKey}`;
20537
20526
  totalDebt24h += addedDebt;
20538
20527
  totalDeposits24h += addedDeposits;
20539
20528
  lendingPositions[key] = dataForAsset;
@@ -20554,7 +20543,15 @@ var getAaveV4UserDataConverter = (lender, chainId, account, metaMap) => {
20554
20543
  expectedNumberOfCalls
20555
20544
  ];
20556
20545
  };
20557
- function createAaveV4Entry(base, data, key, meta) {
20546
+ function getConfigOraclePrice(meta, spokeAddr) {
20547
+ if (spokeAddr) {
20548
+ const byConfig = meta?.oraclePrice?.byConfig;
20549
+ const configPrice = byConfig?.[spokeAddr]?.oraclePriceUsd;
20550
+ if (configPrice != null && configPrice > 0) return configPrice;
20551
+ }
20552
+ return getOraclePrice(meta);
20553
+ }
20554
+ function createAaveV4Entry(base, data, key, meta, spokeAddr) {
20558
20555
  const rawSupply = data[base];
20559
20556
  const debtResult = data[base + 1];
20560
20557
  const statusResult = data[base + 2];
@@ -20575,7 +20572,7 @@ function createAaveV4Entry(base, data, key, meta) {
20575
20572
  const currentDebt = parseRawAmount(totalDebtRaw, decimals);
20576
20573
  const collateralEnabled = Boolean(statusResult?.[0]);
20577
20574
  const price = getDisplayPrice(meta);
20578
- const oPrice = getOraclePrice(meta);
20575
+ const oPrice = getConfigOraclePrice(meta, spokeAddr);
20579
20576
  const priceHist = meta?.price?.priceUsd24h ?? price;
20580
20577
  const dataForAsset = {
20581
20578
  marketUid: key,
@@ -25413,19 +25410,20 @@ function unflattenLenderData(pools) {
25413
25410
  return result;
25414
25411
  }
25415
25412
  var getLenderUserDataResult = async (chainId, queriesRaw, getEvmClient3, allowFailure = true, batchSize = MULTICALL_DEFAULT_BATCH_SIZE, retries = 3, logs = false) => {
25416
- let calls = [];
25417
25413
  const queries = organizeUserQueries(queriesRaw);
25418
- for (const query2 of queries) {
25419
- const abi = getAbi2(query2.lender);
25420
- const callData = await buildUserCall(
25421
- chainId,
25422
- query2.lender,
25423
- query2.account,
25424
- query2.params
25425
- );
25426
- const mappedCalls = callData.map((call) => ({ call, abi }));
25427
- calls = [...calls, ...mappedCalls];
25428
- }
25414
+ const builtCalls = await Promise.all(
25415
+ queries.map(async (query2) => {
25416
+ const abi = getAbi2(query2.lender);
25417
+ const callData = await buildUserCall(
25418
+ chainId,
25419
+ query2.lender,
25420
+ query2.account,
25421
+ query2.params
25422
+ );
25423
+ return callData.map((call) => ({ call, abi }));
25424
+ })
25425
+ );
25426
+ const calls = builtCalls.flat();
25429
25427
  return await multicallViemAbiArray(
25430
25428
  chainId,
25431
25429
  calls.map((call) => call.abi),
@@ -25440,20 +25438,21 @@ var getLenderUserDataResult = async (chainId, queriesRaw, getEvmClient3, allowFa
25440
25438
  );
25441
25439
  };
25442
25440
  var prepareLenderUserDataRpcCalls = async (chainId, queriesRaw, batchSize = MULTICALL_DEFAULT_BATCH_SIZE, blockTag = "latest", allowFailure = true) => {
25443
- let calls = [];
25444
25441
  const multicallAddress = getEvmChain(chainId).contracts?.multicall3?.address;
25445
25442
  const queries = organizeUserQueries(queriesRaw);
25446
- for (const query2 of queries) {
25447
- const abi = getAbi2(query2.lender);
25448
- const callData = await buildUserCall(
25449
- chainId,
25450
- query2.lender,
25451
- query2.account,
25452
- query2.params
25453
- );
25454
- const mappedCalls = callData.map((call) => ({ call, abi }));
25455
- calls = [...calls, ...mappedCalls];
25456
- }
25443
+ const builtCalls = await Promise.all(
25444
+ queries.map(async (query2) => {
25445
+ const abi = getAbi2(query2.lender);
25446
+ const callData = await buildUserCall(
25447
+ chainId,
25448
+ query2.lender,
25449
+ query2.account,
25450
+ query2.params
25451
+ );
25452
+ return callData.map((call) => ({ call, abi }));
25453
+ })
25454
+ );
25455
+ const calls = builtCalls.flat();
25457
25456
  const preparedCalls = prepareMulticallInputs(
25458
25457
  calls.map((c) => c.abi),
25459
25458
  calls.map((c) => c.call)