@1delta/margin-fetcher 0.0.322 → 0.0.323

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
@@ -19013,7 +19013,15 @@ function normalizeAaveV4(spokeDataList, chainId, spokeLenderKeyArg, prices, addi
19013
19013
  const hubTotalOwed = toTokenNumber(hubTotalOwedRaw, hubDecimals);
19014
19014
  const hubDepositsUSD = hubTotalSupply * price2;
19015
19015
  const hubBorrowsUSD = hubTotalOwed * price2;
19016
- const hubUtilization = hubTotalSupply > 0 ? hubTotalOwed / hubTotalSupply : 0;
19016
+ const drawnRaw = (reserve.hubAsset.drawnShares ?? 0n) * (reserve.hubAsset.drawnIndex ?? 0n) / RAY_BIGINT;
19017
+ const irmDenominatorRaw = (reserve.hubAsset.liquidity ?? 0n) + drawnRaw + (reserve.hubAsset.swept ?? 0n);
19018
+ let irmTotalDebt = toTokenNumber(drawnRaw, hubDecimals);
19019
+ let irmTotalDeposits = toTokenNumber(irmDenominatorRaw, hubDecimals);
19020
+ if (drawnRaw === 0n && hubTotalOwed > 0) {
19021
+ irmTotalDebt = hubTotalOwed;
19022
+ irmTotalDeposits = hubTotalSupply;
19023
+ }
19024
+ const hubUtilization = irmTotalDeposits > 0 ? irmTotalDebt / irmTotalDeposits : 0;
19017
19025
  const feeRate = reserve.hubAsset.liquidityFee ? reserve.hubAsset.liquidityFee / BPS : 0;
19018
19026
  const depositRate = variableBorrowRate * hubUtilization * (1 - feeRate);
19019
19027
  const collateralRiskBps = reserve.config.collateralRisk || reserve.reserve.collateralRisk || 0;
@@ -19095,6 +19103,10 @@ function normalizeAaveV4(spokeDataList, chainId, spokeLenderKeyArg, prices, addi
19095
19103
  variableBorrowRate,
19096
19104
  stableBorrowRate: 0,
19097
19105
  utilization: hubUtilization,
19106
+ // Totals in the hub IRM's own utilization basis — rate-impact
19107
+ // simulations must shift these, not the spoke-local totals.
19108
+ irmTotalDeposits,
19109
+ irmTotalDebt,
19098
19110
  intrinsicYield: additionalYields?.intrinsicYields?.[oracleKey] ?? 0,
19099
19111
  rewards: [],
19100
19112
  decimals,
@@ -20013,6 +20025,10 @@ function parseVault(vault, chainId, prices, additionalYields, tokenList, liquidi
20013
20025
  const borrowRate = scaleFluidRate(rates.borrowRateVault);
20014
20026
  const collateralLiquidity = liquidityByToken[collateralAddress];
20015
20027
  const loanLiquidity = liquidityByToken[loanAddress];
20028
+ const irmTotals = (state, decimals) => state ? {
20029
+ irmTotalDeposits: Number(parseRawAmount(state.totalSupply, decimals)),
20030
+ irmTotalDebt: Number(parseRawAmount(state.totalBorrow, decimals))
20031
+ } : {};
20016
20032
  const data = {};
20017
20033
  const collateralMarketUid = createMarketUid(
20018
20034
  chainId,
@@ -20038,6 +20054,7 @@ function parseVault(vault, chainId, prices, additionalYields, tokenList, liquidi
20038
20054
  // IRM x-coordinate: the collateral token's Liquidity-layer utilization —
20039
20055
  // it drives the supply rate (borrowRate × utilization × (1 - fee)).
20040
20056
  utilization: collateralLiquidity?.utilization ?? 0,
20057
+ ...irmTotals(collateralLiquidity, colDecimals),
20041
20058
  // Share of this vault's collateral currently locked below the LL
20042
20059
  // withdrawal limit (withdrawLimit / totalSupplyVault).
20043
20060
  lockupRatio,
@@ -20089,6 +20106,7 @@ function parseVault(vault, chainId, prices, additionalYields, tokenList, liquidi
20089
20106
  // IRM x-coordinate: the loan token's Liquidity-layer utilization — the
20090
20107
  // exact input the current borrow rate was computed from.
20091
20108
  utilization: loanLiquidity?.utilization ?? 0,
20109
+ ...irmTotals(loanLiquidity, borrowDecimals),
20092
20110
  depositRate: 0,
20093
20111
  variableBorrowRate: borrowRate,
20094
20112
  stableBorrowRate: 0,
@@ -20413,10 +20431,17 @@ var getGearboxV3PublicDataConverter = (_lender, chainId, prices, additionalYield
20413
20431
  underlyingDecimals
20414
20432
  )
20415
20433
  );
20416
- const poolTotalBorrowed = Number(
20417
- parseRawAmount(pool.totalBorrowed?.toString(), underlyingDecimals)
20434
+ const poolAvailableLiquidity = Number(
20435
+ parseRawAmount(
20436
+ pool.availableLiquidity?.toString(),
20437
+ underlyingDecimals
20438
+ )
20439
+ );
20440
+ const poolIrmDebt = Math.max(
20441
+ poolExpectedLiquidity - poolAvailableLiquidity,
20442
+ 0
20418
20443
  );
20419
- const poolUtilization = poolExpectedLiquidity > 0 ? poolTotalBorrowed / poolExpectedLiquidity : 0;
20444
+ const poolUtilization = poolExpectedLiquidity > 0 ? poolIrmDebt / poolExpectedLiquidity : 0;
20420
20445
  for (const cm of m.creditManagers ?? []) {
20421
20446
  const facade = cm?.creditFacade;
20422
20447
  const manager = cm?.creditManager;
@@ -20468,6 +20493,10 @@ var getGearboxV3PublicDataConverter = (_lender, chainId, prices, additionalYield
20468
20493
  totalLiquidityUSD: availableToBorrow * underlyingPrice,
20469
20494
  borrowLiquidityUSD: availableToBorrow * underlyingPrice,
20470
20495
  utilization: poolUtilization,
20496
+ // Pool-level totals — the basis the IRM's utilization is defined
20497
+ // over (shared across all credit managers on this pool).
20498
+ irmTotalDeposits: poolExpectedLiquidity,
20499
+ irmTotalDebt: poolIrmDebt,
20471
20500
  depositRate: supplyRate,
20472
20501
  variableBorrowRate: borrowRate,
20473
20502
  stableBorrowRate: 0,