@1delta/margin-fetcher 5.0.7 → 5.0.8

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
@@ -8808,8 +8808,17 @@ interface LiquidationTerms {
8808
8808
  ltv?: number;
8809
8809
  /** Threshold at which liquidation becomes possible. */
8810
8810
  liquidationLtv?: number;
8811
- /** Fraction of repaid debt paid to the liquidator on top of par. */
8812
- penalty: number;
8811
+ /**
8812
+ * Fraction of repaid debt paid to the liquidator on top of par.
8813
+ *
8814
+ * OPTIONAL, and the distinction is load-bearing: `0` means "the liquidator
8815
+ * gets no bonus", `undefined` means "we do not know it". The first cut
8816
+ * defaulted the unknown case to `0` and every market on `/lending/latest`
8817
+ * rendered a confident "Liquidator takes debt repaid + 0%" — the origin's
8818
+ * `market_config` had no penalty column at all, so NOTHING was known. A row
8819
+ * we cannot fill must be absent, not zero.
8820
+ */
8821
+ penalty?: number;
8813
8822
  closeFactor: number;
8814
8823
  targetHealthFactor?: number;
8815
8824
  /**
package/dist/index.js CHANGED
@@ -62540,8 +62540,9 @@ function borrowDescription(b) {
62540
62540
  "Liquidation here is triggered by TIME, not price \u2014 being late is the trigger, and being over-collateralised does not protect you."
62541
62541
  );
62542
62542
  } else if (b.liquidation.liquidationLtv != null) {
62543
+ const pen = b.liquidation.penalty;
62543
62544
  parts.push(
62544
- `Liquidation starts at ${pct(b.liquidation.liquidationLtv * 100)} LTV, with a ${pct(b.liquidation.penalty * 100)} penalty.`
62545
+ `Liquidation starts at ${pct(b.liquidation.liquidationLtv * 100)} LTV` + (pen != null ? `, with a ${pct(pen * 100)} penalty` : "") + "."
62545
62546
  );
62546
62547
  }
62547
62548
  return parts.join(" ");
@@ -63167,7 +63168,20 @@ function buildConstraints(input, siblings, acceptedCollateral) {
63167
63168
  }
63168
63169
  };
63169
63170
  }
63170
- function liquidationFrom(cfg, input) {
63171
+ function marketLltv(input) {
63172
+ const raw = input.market?.lltv;
63173
+ if (raw == null) return void 0;
63174
+ const n = Number(raw);
63175
+ if (!Number.isFinite(n) || n <= 0) return void 0;
63176
+ return n / 1e18;
63177
+ }
63178
+ function liquidationFrom(cfg, input, acceptedCollateral) {
63179
+ const lltv = marketLltv(input);
63180
+ const soleCollateral = acceptedCollateral?.count === 1 ? acceptedCollateral.items[0] : void 0;
63181
+ const isolated = lltv != null || !hasCrossMarginRisk(input.lender) && soleCollateral != null;
63182
+ const ownLtv = cfg?.borrowCollateralFactor;
63183
+ const ownLiqLtv = cfg?.collateralFactor;
63184
+ const ownPenalty = cfg?.liquidationPenalty;
63171
63185
  return {
63172
63186
  // The ordinary model: a liquidator repays part of the debt and takes
63173
63187
  // collateral plus a bonus. Adapters override for the four lenders where
@@ -63175,9 +63189,11 @@ function liquidationFrom(cfg, input) {
63175
63189
  model: "repay-seize",
63176
63190
  absorber: "liquidator",
63177
63191
  trigger: "price",
63178
- ltv: cfg?.borrowCollateralFactor,
63179
- liquidationLtv: cfg?.collateralFactor,
63180
- penalty: cfg?.liquidationPenalty ?? 0,
63192
+ ltv: ownLtv || (isolated ? soleCollateral?.ltv ?? lltv : void 0) || ownLtv,
63193
+ liquidationLtv: ownLiqLtv || (isolated ? soleCollateral?.liquidationLtv ?? lltv : void 0) || ownLiqLtv,
63194
+ // No `?? 0` — see `LiquidationTerms.penalty`. An unknown penalty is
63195
+ // undefined so the row is omitted rather than rendered as "+0%".
63196
+ penalty: ownPenalty || (isolated ? soleCollateral?.liquidationPenalty : void 0) || ownPenalty,
63181
63197
  closeFactor: cfg?.closeFactor ?? input.closeFactor ?? 1,
63182
63198
  targetHealthFactor: cfg?.targetHealthFactor ?? input.targetHealthFactor,
63183
63199
  seizure: "proportional",
@@ -63204,7 +63220,8 @@ function buildModes(input) {
63204
63220
  liquidation: {
63205
63221
  ltv: c.borrowCollateralFactor,
63206
63222
  liquidationLtv: c.collateralFactor,
63207
- penalty: c.liquidationPenalty ?? 0,
63223
+ // Same rule as the top-level penalty: unknown stays unknown.
63224
+ penalty: c.liquidationPenalty,
63208
63225
  closeFactor: c.closeFactor ?? input.closeFactor ?? 1,
63209
63226
  targetHealthFactor: c.targetHealthFactor ?? input.targetHealthFactor
63210
63227
  },
@@ -63299,6 +63316,7 @@ function buildBorrow(input, now, siblings) {
63299
63316
  const rate = buildRate(input, "borrow");
63300
63317
  const maturity = buildMaturity(input, now);
63301
63318
  const fees = buildFees(input, "borrow");
63319
+ const acceptedCollateral = buildExposures2(input, siblings, "accepted");
63302
63320
  const borrow = {
63303
63321
  rate,
63304
63322
  maturity,
@@ -63313,8 +63331,8 @@ function buildBorrow(input, now, siblings) {
63313
63331
  minDebt: resolveMinDebt(input),
63314
63332
  fees: fees.filter((f) => f.when === "exit" || f.when === "late")
63315
63333
  },
63316
- liquidation: liquidationFrom(cfg, input),
63317
- acceptedCollateral: buildExposures2(input, siblings, "accepted"),
63334
+ liquidation: liquidationFrom(cfg, input, acceptedCollateral),
63335
+ acceptedCollateral,
63318
63336
  modes: buildModes(input),
63319
63337
  fees,
63320
63338
  counterparty: { kind: "pool", solvency: "overcollateralized" },
@@ -64939,7 +64957,7 @@ function validateTermSheet(sheet) {
64939
64957
  "full-collateral seizure must surface a tag or an implication"
64940
64958
  );
64941
64959
  }
64942
- if (l.penalty < 0 || l.penalty > 1)
64960
+ if (l.penalty != null && (l.penalty < 0 || l.penalty > 1))
64943
64961
  fail("penalty-range", `liquidation.penalty ${l.penalty} outside 0..1`);
64944
64962
  if (l.closeFactor <= 0 || l.closeFactor > 1)
64945
64963
  fail(