@1delta/margin-fetcher 5.0.162 → 5.0.163

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.d.ts CHANGED
@@ -237,9 +237,9 @@ interface PoolData {
237
237
  totalDebt: string;
238
238
  totalLiquidity: number;
239
239
  /**
240
- * Cap-adjusted borrow liquidity in token units.
241
- * `min(totalLiquidity, max(0, borrowCap - totalDebt))` when `borrowCap > 0`.
242
- * Equals `totalLiquidity` when no borrow cap is active (`borrowCap === 0`).
240
+ * Cap-adjusted borrow liquidity in token units:
241
+ * `min(totalLiquidity, max(0, borrowCap - totalDebt))` when a cap is set,
242
+ * `totalLiquidity` when `borrowCap` is undefined (uncapped).
243
243
  */
244
244
  borrowLiquidity: number;
245
245
  totalDepositsUSD: number;
@@ -290,14 +290,21 @@ interface PoolData {
290
290
  hasStable: boolean;
291
291
  isActive: boolean;
292
292
  isFrozen: boolean;
293
- borrowCap: number;
293
+ /**
294
+ * Total-debt ceiling in TOKEN units. No cap is `undefined`, never 0:
295
+ * yield-tracer re-caps `borrow_liquidity` at `borrowCap − totalDebt` whenever
296
+ * the field is set, so 0 reads as a CLOSED market (Aave forks, Alchemix and
297
+ * Flex all shipped uncapped debt legs that way, 2026-11-24). 0 is right only
298
+ * where new borrows really are shut (Euler `caps()` raw 6, a matured term).
299
+ */
300
+ borrowCap?: number;
294
301
  /**
295
302
  * Remaining-deposit ceiling in TOKEN units. No cap is `undefined`, never 0:
296
303
  * yield-tracer stores `depositable = supplyCap − totalDeposits` whenever the
297
304
  * field is set, so 0 reads as a FULL cap and the pairs feed drops every pair
298
305
  * on the leg (Flex shipped that way, TODO.md 2026-11-23). 0 is only right on
299
306
  * a leg that is closed to deposits (cap 0 plus the flag) or one nobody
300
- * deposits into (a minted debt token, Compound V3's base).
307
+ * deposits into (a minted debt token).
301
308
  */
302
309
  supplyCap: number;
303
310
  debtCeiling: string;
@@ -5927,7 +5934,9 @@ declare function alchemixRedemptionPace(m: AlchemixMarketRaw, chainId: string):
5927
5934
  * `totalDeposits` is 0. There is NO interest: `variableBorrowRate` is 0
5928
5935
  * with `rateModel: 'zeroInterest'`. The borrower's cost is the redemption
5929
5936
  * fee on EARMARKED debt (a fee per redemption, not an APR — it rides in
5930
- * `alchemix.protocolFeeBps`) plus whatever discount the alAsset trades at.
5937
+ * `alchemix.protocolFeeBps`) plus the discount the alAsset trades at, both
5938
+ * lost on the part a redemption settles at face: a year's worth of that is
5939
+ * the row's `originationFee` (`alchemix.settlementCostPct`).
5931
5940
  * `borrowLiquidity` is the headroom the market could still mint if its
5932
5941
  * deposit cap were filled at max LTV (there is no separate debt ceiling).
5933
5942
  *
@@ -5938,7 +5947,8 @@ declare function alchemixRedemptionPace(m: AlchemixMarketRaw, chainId: string):
5938
5947
  * USD price, so the USD totals and every health figure built on them agree
5939
5948
  * with the contract. The alAsset's MARKET price is lower (alUSD ≈ 0.955,
5940
5949
  * alETH ≈ 0.975 ETH on 2026-10-19); that discount is a borrower cost and a
5941
- * deleverage opportunity, never an input to health. It does enter the
5950
+ * deleverage opportunity, never an input to health. It enters the borrow
5951
+ * cost (`originationFee`, above) and the
5942
5952
  * alAsset's BORROW-CAPACITY weight (`borrowFactor` = face / market, with
5943
5953
  * `liquidationBorrowFactor: 1`), because a loop can only add as much
5944
5954
  * collateral as the sold debt buys.
package/dist/index.js CHANGED
@@ -7558,8 +7558,10 @@ var getAaveV3ReservesDataConverter = (lender, chainId, prices, additionalYields,
7558
7558
  isActive: configData?.[8 /* isActive */],
7559
7559
  isFrozen: configData?.[9 /* isFrozen */],
7560
7560
  // caps
7561
- borrowCap: Number(reserveCaps[0]?.toString()),
7562
- // Aave's 0 = no cap; downstream no cap is undefined (0 reads full)
7561
+ // Aave's 0 = no cap; downstream no cap is undefined — yield-tracer
7562
+ // re-caps borrow_liquidity at `borrow_cap − debt` whenever it is set,
7563
+ // so a 0 zeroed every uncapped reserve (Spark DAI/USDS, Avalon, …)
7564
+ borrowCap: Number(reserveCaps[0]?.toString()) || void 0,
7563
7565
  supplyCap: Number(reserveCaps[1]?.toString()) || void 0,
7564
7566
  debtCeiling: Number(
7565
7567
  parseRawAmount(
@@ -8000,8 +8002,8 @@ function parseAave32(chainId, lender, prices, additionalYields, tokenList) {
8000
8002
  isActive: configData?.[8 /* isActive */],
8001
8003
  isFrozen: configData?.[9 /* isFrozen */],
8002
8004
  // caps
8003
- borrowCap: Number(reserveCaps[0]?.toString()),
8004
- // Aave's 0 = no cap; downstream no cap is undefined (0 reads full)
8005
+ // Aave's 0 = no cap; downstream no cap is undefined (0 reads closed)
8006
+ borrowCap: Number(reserveCaps[0]?.toString()) || void 0,
8005
8007
  supplyCap: Number(reserveCaps[1]?.toString()) || void 0,
8006
8008
  debtCeiling: Number(
8007
8009
  parseRawAmount(
@@ -8092,10 +8094,9 @@ var getInitReservesDataConverter = (lender, chainId, prices, additionalYields, t
8092
8094
  if (!poolId) return;
8093
8095
  const marketUid = createMarketUid(chainId, lender, poolId);
8094
8096
  const name = INIT_POOL_NAME_OVERRIDES[poolId.toLowerCase()] ?? lenderShortName(lender) + " " + (meta?.symbol ?? "");
8095
- const borrowCap = Number(parseRawAmount(
8096
- dat?.borrowCap.toString(),
8097
- meta.decimals
8098
- ));
8097
+ const borrowCap = Number(
8098
+ parseRawAmount(dat?.borrowCap.toString(), meta.decimals)
8099
+ );
8099
8100
  const borrowLiq = borrowCap > 0 ? Math.min(liquidity, Math.max(0, borrowCap - Number(totalDebt))) : liquidity;
8100
8101
  result[asset] = {
8101
8102
  marketUid,
@@ -8103,7 +8104,8 @@ var getInitReservesDataConverter = (lender, chainId, prices, additionalYields, t
8103
8104
  poolId: asset,
8104
8105
  underlying: asset,
8105
8106
  asset: meta,
8106
- borrowCap,
8107
+ // Init's 0 = no cap; downstream no cap is undefined (0 reads closed)
8108
+ borrowCap: borrowCap > 0 ? borrowCap : void 0,
8107
8109
  canBurn: Boolean(dat?.canBurn),
8108
8110
  canFlash: Boolean(dat?.canFlash),
8109
8111
  canMint: Boolean(dat?.canMint),
@@ -8332,7 +8334,9 @@ var getCompoundV3ReservesDataConverter = (lender, chainId, prices, additionalYie
8332
8334
  // collateral factots
8333
8335
  borrowCollateralFactor: 0,
8334
8336
  collateralFactor: 0,
8335
- supplyCap: 0,
8337
+ // Comet caps collateral only — the base (the lend side) has no supply
8338
+ // cap, and 0 reads downstream as a FULL one (`canDeposit: false`).
8339
+ supplyCap: void 0,
8336
8340
  config: {
8337
8341
  [LENDER_MODE_NO_MODE]: {
8338
8342
  category: LENDER_MODE_NO_MODE,
@@ -19786,7 +19790,7 @@ var getEulerV2ReservesDataConverter = (lender, chainId, prices, additionalYields
19786
19790
  totalLiquidity: String(totalLiquidity),
19787
19791
  ...(() => {
19788
19792
  const bc = entry2.borrowCap;
19789
- const bl = bc > 0 ? Math.min(totalLiquidity, Math.max(0, bc - totalDebt)) : totalLiquidity;
19793
+ const bl = Math.min(totalLiquidity, Math.max(0, bc - totalDebt));
19790
19794
  return {
19791
19795
  borrowLiquidity: bl,
19792
19796
  borrowLiquidityUSD: bl * price2
@@ -19971,6 +19975,10 @@ function toTokenNumber(raw, decimals) {
19971
19975
  }
19972
19976
  var RAY3 = 1e27;
19973
19977
  var MAX_SPOKE_CAP = 2 ** 40 - 1;
19978
+ function publishedCap(bindingExists, cap) {
19979
+ if (!bindingExists || cap >= MAX_SPOKE_CAP) return void 0;
19980
+ return cap;
19981
+ }
19974
19982
  var RAY_BIGINT = 10n ** 27n;
19975
19983
  function rayRateToApr(rateRay) {
19976
19984
  if (rateRay === 0n) return 0;
@@ -20154,8 +20162,11 @@ function normalizeAaveV4(spokeDataList, chainId, spokeLenderKeyArg, prices, addi
20154
20162
  hasStable: false,
20155
20163
  isActive: !reserve.config.paused,
20156
20164
  isFrozen: reserve.config.frozen,
20157
- borrowCap,
20158
- supplyCap,
20165
+ // Published caps: 0 only where the binding really blocks (yield-tracer
20166
+ // reads a set cap as `cap − total`, so 0 = closed); MAX_SPOKE_CAP and
20167
+ // an unknown binding are uncapped → undefined.
20168
+ borrowCap: publishedCap(bindingExists, borrowCap),
20169
+ supplyCap: publishedCap(bindingExists, supplyCap),
20159
20170
  debtCeiling: 0,
20160
20171
  // No close factor in V4 — the ceiling is the whole debt.
20161
20172
  closeFactor: 1,
@@ -29303,7 +29314,7 @@ function convertRipeMarketsToResponse(raw, chainId, prices = {}, additionalYield
29303
29314
  const token = tokens[a.address];
29304
29315
  const totalDeposits = toHuman5(a.totalDeposited, decimals);
29305
29316
  const capped2 = a.globalDepositLimit < UNCAPPED;
29306
- const globalCap = capped2 ? toHuman5(a.globalDepositLimit, decimals) : 0;
29317
+ const globalCap = capped2 ? toHuman5(a.globalDepositLimit, decimals) : void 0;
29307
29318
  const roomLeft = capped2 ? Math.max(0, globalCap - totalDeposits) : Infinity;
29308
29319
  const allowlisted = a.whitelist !== zeroAddress;
29309
29320
  const depositsEnabled = protocolCanDeposit && a.canDeposit && !allowlisted && roomLeft > 0;
@@ -29711,6 +29722,9 @@ function convertAlchemixMarketsToResponse(raw, chainId, prices = {}, additionalY
29711
29722
  const borrowLiquidity = borrowingEnabled ? Math.max(0, maxMarketDebt - totalDebt) : 0;
29712
29723
  const pace = alchemixRedemptionPace(m, chainId);
29713
29724
  const t = m.transmuter;
29725
+ const pegDiscount = 1 - debtSaleRatio;
29726
+ const settledPerYear = Math.min(1, pace?.redemptionRate ?? 1);
29727
+ const settlementCost = (pegDiscount + m.protocolFee / BPS3) * settledPerYear * 100;
29714
29728
  const entry2 = { data: {} };
29715
29729
  const collUid = createMarketUid(chainId, lenderKey, myt2);
29716
29730
  entry2.data[collUid] = {
@@ -29788,14 +29802,17 @@ function convertAlchemixMarketsToResponse(raw, chainId, prices = {}, additionalY
29788
29802
  variableBorrowRate: 0,
29789
29803
  stableBorrowRate: 0,
29790
29804
  rateModel: "zeroInterest",
29791
- // No origination fee: the redemption fee is charged later, on the part
29792
- // a redemption settles, and is NOT a percent of the amount borrowed.
29793
- originationFee: 0,
29805
+ // Not charged at open: the expected cost of settling the debt at face
29806
+ // within a year (`settlementCost` above), in the one field the pair book
29807
+ // amortizes into the borrow rate.
29808
+ originationFee: settlementCost,
29794
29809
  intrinsicYield: 0,
29795
29810
  rewards: void 0,
29796
29811
  decimals: debtDecimals,
29797
29812
  supplyCap: 0,
29798
- borrowCap: 0,
29813
+ // The ceiling is already in `borrowLiquidity` (deposit-cap headroom × LTV).
29814
+ // A 0 here is read downstream as a CLOSED cap and zeroes the debt leg.
29815
+ borrowCap: void 0,
29799
29816
  config: {
29800
29817
  0: {
29801
29818
  category: 0,
@@ -29891,6 +29908,12 @@ function convertAlchemixMarketsToResponse(raw, chainId, prices = {}, additionalY
29891
29908
  * redeemed pays `protocolFeeBps` once.
29892
29909
  */
29893
29910
  redemptionRatePerYear: pace?.redemptionRate,
29911
+ /** The alAsset's market price over face (≤ 1; 1 = no market feed). */
29912
+ debtSaleRatio,
29913
+ /** `1 − debtSaleRatio`, PERCENT: lost on each unit settled at face. */
29914
+ pegDiscountPct: pegDiscount * 100,
29915
+ /** Expected cost of a year's redemptions, PERCENT of the debt (= the row's `originationFee`). */
29916
+ settlementCostPct: settlementCost,
29894
29917
  /** alAsset redeemed per year at the current queue, human units. */
29895
29918
  redeemedPerYear: pace?.redeemedPerYear
29896
29919
  }
@@ -30324,7 +30347,9 @@ function convertFlexMarketsToResponse(raw, chainId, prices = {}, additionalYield
30324
30347
  rewards: void 0,
30325
30348
  decimals: borrowDecimals,
30326
30349
  supplyCap: depositRoom !== void 0 ? lenderAssets + depositRoom : void 0,
30327
- borrowCap: 0,
30350
+ // No debt cap: `borrowLiquidity` is the Lender's idle cash. A 0 here is
30351
+ // read downstream as a CLOSED cap and zeroes the borrow leg.
30352
+ borrowCap: void 0,
30328
30353
  config: {
30329
30354
  0: {
30330
30355
  category: 0,
@@ -103794,6 +103819,18 @@ var alchemixAdapter = {
103794
103819
  cap: 1e4,
103795
103820
  description: "Taken from your collateral on the part of your debt that redemptions settle; the rest of the debt pays nothing."
103796
103821
  });
103822
+ const pegDiscountPct = num19(a.pegDiscountPct);
103823
+ if (pegDiscountPct != null && pegDiscountPct > 0)
103824
+ fees2.push({
103825
+ id: "peg-discount",
103826
+ label: "Settled at par",
103827
+ when: "ongoing",
103828
+ unit: "percent",
103829
+ basis: "debt-repaid",
103830
+ value: pegDiscountPct,
103831
+ mutable: true,
103832
+ description: `The debt sells for ${(100 - pegDiscountPct).toFixed(1)}% of face when you borrow it, and redemptions settle it at 100% against your collateral: ${pegDiscountPct.toFixed(1)}% lost on every unit they settle. Repaying it yourself at market costs only the spread.`
103833
+ });
103797
103834
  if (liquidatorFeeBps != null)
103798
103835
  fees2.push({
103799
103836
  id: "liquidation-bonus",
@@ -103889,10 +103926,10 @@ var alchemixAdapter = {
103889
103926
  driver: "below-peg",
103890
103927
  // Earmarks are proportional to debt across EVERY position.
103891
103928
  order: "pro-rata",
103892
- // Debt is cancelled against collateral at face, so the borrower's
103893
- // value moves only by the redemption fee — a loss, but that small.
103929
+ // Debt is cancelled against collateral at face: the borrower loses
103930
+ // the redemption fee and, below peg, the discount on that part.
103894
103931
  valueImpact: "loss",
103895
- defence: "Nothing exempts a position \u2014 redemptions are spread over every borrower in proportion to debt. They settle debt against your collateral at face value, so your LTV does not rise; the cost is the redemption fee on the settled part."
103932
+ defence: "Nothing exempts a position \u2014 redemptions are spread over every borrower in proportion to debt. They settle debt against your collateral at face value, so your LTV does not rise; the cost is the redemption fee on the settled part, plus the discount the debt token trades at while it is below peg."
103896
103933
  }
103897
103934
  },
103898
103935
  fees: fees2,
@@ -103910,6 +103947,8 @@ var alchemixAdapter = {
103910
103947
  debtValuation: "face",
103911
103948
  redemptionFeeBps: protocolFeeBps,
103912
103949
  redemptionRatePerYear: num19(a.redemptionRatePerYear),
103950
+ pegDiscountPct,
103951
+ settlementCostPct: num19(a.settlementCostPct),
103913
103952
  transmuterTermSecs: termSecs,
103914
103953
  transmuterTermBlocks: num19(a.transmuterQueue?.termBlocks)
103915
103954
  }
@@ -103920,9 +103959,12 @@ var alchemixAdapter = {
103920
103959
  positionModel: "nft",
103921
103960
  positionIdMeaning: "The tokenId of the Alchemist\u2019s position NFT \u2014 one isolated position per token, many per wallet. Only the token\u2019s owner can withdraw or borrow from it directly; anyone may deposit into it or repay it."
103922
103961
  },
103923
- coverage: {
103924
- pending: {
103925
- "borrow.marketDiscount": "alasset-market-price-not-wired-debt-is-stated-at-face"
103962
+ // Without a market feed for the alAsset the discount is unknown, not 0.
103963
+ ...num19(a.debtSaleRatio) != null && a.debtSaleRatio < 1 ? {} : {
103964
+ coverage: {
103965
+ pending: {
103966
+ "borrow.marketDiscount": "alasset-market-price-not-wired-debt-is-stated-at-face"
103967
+ }
103926
103968
  }
103927
103969
  }
103928
103970
  };