@morpho-org/blue-sdk 3.0.0-next.11 → 3.0.0-next.12

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.
@@ -283,7 +283,7 @@ export declare class Market implements IMarket {
283
283
  getLtv(position: {
284
284
  collateral: bigint;
285
285
  borrowShares: bigint;
286
- }): bigint | undefined;
286
+ }): bigint | null | undefined;
287
287
  /**
288
288
  * Returns the usage ratio of the maximum borrow capacity given a certain borrow position (scaled by WAD).
289
289
  * @param position The borrow position to consider.
@@ -241,6 +241,7 @@ export declare namespace MarketUtils {
241
241
  /**
242
242
  * Returns the loan-to-value ratio of a given borrow position (scaled by WAD).
243
243
  * Returns `undefined` iff the market's price is undefined.
244
+ * Returns null if the position is not a borrow.
244
245
  */
245
246
  function getLtv({ collateral, borrowShares, }: {
246
247
  collateral: BigIntish;
@@ -249,7 +250,7 @@ export declare namespace MarketUtils {
249
250
  totalBorrowAssets: BigIntish;
250
251
  totalBorrowShares: BigIntish;
251
252
  price?: BigIntish;
252
- }): bigint | undefined;
253
+ }): bigint | null | undefined;
253
254
  /**
254
255
  * Returns the usage ratio of the maximum borrow capacity given a certain borrow position (scaled by WAD).
255
256
  * Returns `undefined` iff the market's price is undefined.
@@ -288,8 +288,13 @@ var MarketUtils;
288
288
  /**
289
289
  * Returns the loan-to-value ratio of a given borrow position (scaled by WAD).
290
290
  * Returns `undefined` iff the market's price is undefined.
291
+ * Returns null if the position is not a borrow.
291
292
  */
292
293
  function getLtv({ collateral, borrowShares, }, market) {
294
+ borrowShares = BigInt(borrowShares);
295
+ market.totalBorrowShares = BigInt(market.totalBorrowShares);
296
+ if (borrowShares === 0n || market.totalBorrowShares === 0n)
297
+ return null;
293
298
  const collateralValue = getCollateralValue(collateral, market);
294
299
  if (collateralValue == null)
295
300
  return;
@@ -93,7 +93,7 @@ export declare class AccrualPosition extends Position implements IAccrualPositio
93
93
  * If the collateral price is 0, LTV is `MaxUint256`.
94
94
  * `undefined` if the market's oracle is undefined or reverts.
95
95
  */
96
- get ltv(): bigint | undefined;
96
+ get ltv(): bigint | null | undefined;
97
97
  /**
98
98
  * This position's health factor (collateral power over debt, scaled by WAD).
99
99
  * If the debt is 0, health factor is `MaxUint256`.
@@ -92,7 +92,7 @@ class PreLiquidationPosition extends Position_1.AccrualPosition {
92
92
  return 0n;
93
93
  const { ltv } = this;
94
94
  if (ltv == null)
95
- return ltv;
95
+ return;
96
96
  const quotient = math_1.MathLib.wDivDown(ltv - this.preLiquidationParams.preLltv, this._lltv - this.preLiquidationParams.preLltv);
97
97
  const repayableShares = math_1.MathLib.wMulDown(this.borrowShares, this.preLiquidationParams.getCloseFactor(quotient));
98
98
  const repayableAssets = math_1.MathLib.wMulDown(math_1.SharesMath.toAssets(repayableShares, this._market.totalBorrowAssets, this._market.totalBorrowShares, "Down"), this.preLiquidationParams.getIncentiveFactor(quotient));