@1delta/margin-fetcher 0.0.306 → 0.0.307

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
@@ -11413,7 +11413,9 @@ function createBaseTypeUserState(payload, lenderData, totalDeposits24h = 0, tota
11413
11413
  collateralAllActive += (userConfigForAsset?.collateralFactor ?? 1) * depositsUSDOracle;
11414
11414
  }
11415
11415
  depositInterest += depositRate * depositsUSD;
11416
- borrowInterest += debtStableUSD * stableBorrowRate + debtUSD * variableBorrowRate;
11416
+ const posStableRate = Number(pos.stableBorrowRate);
11417
+ const effStableBorrowRate = Number.isFinite(posStableRate) && posStableRate > 0 ? posStableRate : stableBorrowRate;
11418
+ borrowInterest += debtStableUSD * effStableBorrowRate + debtUSD * variableBorrowRate;
11417
11419
  }
11418
11420
  const nav = deposits - debt;
11419
11421
  const balanceData2 = {
@@ -23177,10 +23179,12 @@ function createMorphoEntryFromMarketWithLens(balanceInfo, metaMap, chainId, lend
23177
23179
  };
23178
23180
  };
23179
23181
  let sumFixedRaw = 0n;
23182
+ let weightedAprNumerator = 0;
23180
23183
  for (const loan of brokerData.fixedLoans) {
23181
23184
  const trancheRaw = BigInt(loan.outstanding) + BigInt(loan.accruedInterest);
23182
23185
  sumFixedRaw += trancheRaw;
23183
23186
  const trancheToken = parseRawAmount(trancheRaw.toString(), loanDecimals);
23187
+ weightedAprNumerator += Number(trancheToken) * loan.apr;
23184
23188
  mkTermPosition(`${loanMarketUid}#${loan.posId}`, trancheToken, {
23185
23189
  loanId: loan.posId,
23186
23190
  termId: loan.termId,
@@ -23203,12 +23207,18 @@ function createMorphoEntryFromMarketWithLens(balanceInfo, metaMap, chainId, lend
23203
23207
  dataForLoanAsset.debtStable = fixedToken;
23204
23208
  dataForLoanAsset.debtStableUSD = Number(fixedToken) * priceLoan;
23205
23209
  dataForLoanAsset.debtStableUSDOracle = Number(fixedToken) * oraclePriceLoan;
23210
+ const fixedTokenNum = Number(fixedToken);
23211
+ dataForLoanAsset.stableBorrowRate = fixedTokenNum > 0 ? (weightedAprNumerator / fixedTokenNum).toString() : "0";
23206
23212
  aggregateDebtToken = parseRawAmount(totalRaw.toString(), loanDecimals);
23207
23213
  if (dynRaw > 0n) {
23208
23214
  mkTermPosition(`${loanMarketUid}#dynamic`, dynToken, {
23209
23215
  loanId: LISTA_DYNAMIC_LOAN_ID,
23210
23216
  isDynamic: true,
23211
- debt: dynToken
23217
+ debt: dynToken,
23218
+ // the flexible loan accrues at the underlying Moolah market's variable borrow rate
23219
+ // (PERCENT). Expired fixed positions refinance into this dynamic loan, so without
23220
+ // this the migrated debt would (incorrectly) report a 0% borrow rate.
23221
+ apr: loanAssetMeta?.variableBorrowRate ?? 0
23212
23222
  });
23213
23223
  }
23214
23224
  }