impermax-sdk 1.1.61 → 1.1.63

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.
@@ -202,17 +202,19 @@ class OnchainAccountLendingPool {
202
202
  const collateralB = actualCollateral / (1 + reservesRatio) / priceB;
203
203
  let priceSwingA, priceSwingB;
204
204
  if (factories_1.STABLE_FACTORIES.includes(this.lendingPool.getImpermaxFactory().getFactory())) {
205
+ console.log(collateralA, collateralB, debtA, debtB, safetyMargin);
205
206
  priceSwingA = (0, lliquidity_math_1.solidlyStable_getLiquidatableXPriceDecrease)(collateralA, collateralB, debtA, debtB) * safetyMargin;
206
207
  priceSwingB = (0, lliquidity_math_1.solidlyStable_getLiquidatableXPriceDecrease)(collateralB, collateralA, debtB, debtA) * safetyMargin;
208
+ console.log(priceSwingA, priceSwingB);
207
209
  }
208
210
  else {
209
211
  priceSwingA = (0, lliquidity_math_1.uniswapV2_getLiquidatableXPriceDecrease)(collateralA, collateralB, debtA, debtB) * safetyMargin;
210
212
  priceSwingB = (0, lliquidity_math_1.uniswapV2_getLiquidatableXPriceDecrease)(collateralB, collateralA, debtB, debtA) * safetyMargin;
211
213
  }
212
- const currentPrice = yield this.lendingPool.getTWAPPrice();
214
+ const twapPrice = yield this.lendingPool.getTWAPPrice();
213
215
  return !this.account.getOnchain().priceInverted
214
- ? [currentPrice * priceSwingA, currentPrice / priceSwingB]
215
- : [currentPrice * priceSwingB, currentPrice / priceSwingA];
216
+ ? [twapPrice * priceSwingA, twapPrice / priceSwingB]
217
+ : [twapPrice * priceSwingB, twapPrice / priceSwingA];
216
218
  });
217
219
  }
218
220
  // Max Leverage
@@ -248,10 +248,10 @@ class OnchainLendingPool {
248
248
  return __awaiter(this, void 0, void 0, function* () {
249
249
  if (factories_1.STABLE_FACTORIES.includes(this.impermaxFactory.getFactory())) {
250
250
  const collateral = yield this.getCollateral().getPoolToken();
251
- const decimalsA = yield this.getBorrowableA().getDecimals();
252
- const decimalsB = yield this.getBorrowableB().getDecimals();
253
- const { twapReserve0, twapReserve1 } = yield collateral.methods.getTwapReserves().call();
251
+ let { twapReserve0, twapReserve1 } = yield collateral.methods.getTwapReserves().call();
254
252
  const [price0, price1] = yield this.getPriceDenomLP();
253
+ twapReserve0 = yield this.getBorrowableA().normalize(twapReserve0);
254
+ twapReserve1 = yield this.getBorrowableB().normalize(twapReserve1);
255
255
  return twapReserve0 * price0 / (twapReserve1 * price1);
256
256
  }
257
257
  else {
@@ -261,17 +261,9 @@ class OnchainLendingPool {
261
261
  }
262
262
  getReservesValueRatio() {
263
263
  return __awaiter(this, void 0, void 0, function* () {
264
- if (factories_1.STABLE_FACTORIES.includes(this.impermaxFactory.getFactory())) {
265
- const collateral = yield this.getCollateral().getPoolToken();
266
- const decimalsA = yield this.getBorrowableA().getDecimals();
267
- const decimalsB = yield this.getBorrowableB().getDecimals();
268
- const { twapReserve0, twapReserve1 } = yield collateral.methods.getTwapReserves().call();
269
- const [price0, price1] = yield this.getPriceDenomLP();
270
- return twapReserve0 * price0 / (twapReserve1 * price1);
271
- }
272
- else {
273
- return 1;
274
- }
264
+ if (!this.cache.reservesValueRatio)
265
+ this.cache.reservesValueRatio = this.initializeReservesValueRatio();
266
+ return this.cache.reservesValueRatio;
275
267
  });
276
268
  }
277
269
  initializeTWAPPrice() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "1.1.61",
3
+ "version": "1.1.63",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",