impermax-sdk 2.1.317 → 2.1.319

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.
@@ -267,9 +267,10 @@ class OffchainAccount {
267
267
  pool.getBorrowableA().getPoolToken().getSupplyAPR(),
268
268
  pool.getBorrowableB().getPoolToken().getSupplyAPR()
269
269
  ]);
270
+ const totalBalanceUSD = valueA + valueB;
270
271
  const lending = {
271
- totalBalanceUSD: valueA + valueB,
272
- totalAPR: (valueA * aprA + valueB * aprB) / (valueA + valueB)
272
+ totalBalanceUSD,
273
+ totalAPR: totalBalanceUSD > 0 ? (valueA * aprA + valueB * aprB) / totalBalanceUSD : 0
273
274
  };
274
275
  let collateralBalanceUSD = 0;
275
276
  let collateralAPR = 0;
@@ -302,7 +303,7 @@ class OffchainAccount {
302
303
  pool.getBorrowableB().getPoolToken().getTokenPriceAccurate(),
303
304
  ]);
304
305
  collateralBalanceUSD += (position.getNetX() * priceX + position.getNetY() * priceY);
305
- collateralAPR = position.getLeveragedApr();
306
+ collateralAPR = collateralBalanceUSD > 0 ? position.getLeveragedApr() : 0;
306
307
  }
307
308
  const borrowing = {
308
309
  totalBalanceUSD: collateralBalanceUSD,
@@ -38,6 +38,10 @@ class OffchainNftlpUniswapV3 extends offchainNftlp_1.default {
38
38
  lendingPool.getBorrowableA().getTokenPriceAccurate(),
39
39
  lendingPool.getBorrowableB().getTokenPriceAccurate()
40
40
  ]);
41
+ if (!priceA || !priceB) {
42
+ console.warn("Can't calculate price for", await this.getLendingPool().getBorrowableA().getSymbol(), await this.getLendingPool().getBorrowableB().getSymbol());
43
+ return NaN;
44
+ }
41
45
  return priceA / priceB;
42
46
  }
43
47
  // get basic UniswapV3Pool info given a fee
@@ -69,8 +69,8 @@ class OffchainLendingPool {
69
69
  this.getBorrowableB().getTokenPriceAccurate()
70
70
  ]);
71
71
  if (!priceA || !priceB) {
72
- console.warn("Can't calculate price for", await this.getBorrowableA().getSymbol(), await this.getBorrowableA().getSymbol());
73
- return 0;
72
+ console.warn("Can't calculate price for", await this.getBorrowableA().getSymbol(), await this.getBorrowableB().getSymbol());
73
+ return NaN;
74
74
  }
75
75
  return priceA / priceB;
76
76
  }
@@ -14,6 +14,7 @@ export interface GenericPositionParams {
14
14
  }
15
15
  export declare abstract class GenericPosition implements Position {
16
16
  lockStateChange: boolean;
17
+ containsErrors: boolean;
17
18
  state: number;
18
19
  /**
19
20
  * NOTICE all values inside this class are normalized (no decimals or mantissa to take into account)
@@ -6,9 +6,7 @@ const LOWEST_PRICE = 1 / 1e18;
6
6
  const HIGHEST_PRICE = 1e18;
7
7
  class GenericPosition {
8
8
  constructor(params) {
9
- if (isNaN(params.marketPrice) || params.marketPrice < LOWEST_PRICE || params.marketPrice > HIGHEST_PRICE) {
10
- console.log("Position initialization error: market price =", params.marketPrice);
11
- }
9
+ this.containsErrors = isNaN(params.marketPrice);
12
10
  this.liquidity = params.liquidity;
13
11
  this.debtX = params.debtX;
14
12
  this.debtY = params.debtY;
@@ -3,6 +3,7 @@
3
3
  */
4
4
  export default interface Position {
5
5
  readonly lockStateChange: boolean;
6
+ containsErrors: boolean;
6
7
  state: number;
7
8
  readonly initialDebtX: number;
8
9
  readonly initialDebtY: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.317",
3
+ "version": "2.1.319",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",