impermax-sdk 2.1.226 → 2.1.227

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.
@@ -76,6 +76,7 @@ export declare class UniswapV3Position implements Position {
76
76
  private getLiquidationPriceInRange;
77
77
  private getMaxDeltaDebtInRange;
78
78
  private getMaxDeltaLeverageInRange;
79
+ private getMinLeverageInRange;
79
80
  /**
80
81
  * PUBLIC SETTERS
81
82
  */
@@ -252,6 +252,15 @@ class UniswapV3Position {
252
252
  else
253
253
  return this.getMaxDeltaLeverageInRange(avgDeltaX, avgDeltaY, highDeltaX, highDeltaY);
254
254
  }
255
+ getMinLeverageInRange(lowLeverage, highLeverage) {
256
+ if (highLeverage / lowLeverage < 1.001)
257
+ return highLeverage;
258
+ const avgLeverage = (lowLeverage + highLeverage) / 2;
259
+ if (this.getOptimalWithdrawForDeleverage(avgLeverage) !== null)
260
+ return this.getMinLeverageInRange(lowLeverage, avgLeverage);
261
+ else
262
+ return this.getMinLeverageInRange(avgLeverage, lowLeverage);
263
+ }
255
264
  /**
256
265
  * PUBLIC SETTERS
257
266
  */
@@ -421,8 +430,6 @@ class UniswapV3Position {
421
430
  // collateral * (leverage-1) - debt * leverage = delta * (leverage * (1-repayRatio) - 1)
422
431
  // (collateral * (leverage-1) - debt * leverage) / (leverage * (1-repayRatio) - 1) = delta
423
432
  // 4. Return amounts if the leverage is achievable
424
- console.log("deltaValue", deltaValue);
425
- console.log("collateralValue", collateralValue);
426
433
  if (deltaValue < 0 || deltaValue > collateralValue)
427
434
  return null;
428
435
  const percentageToRemove = (deltaValue + maxStraightDeleverageValue) / this.getInitialCollateralValue();
@@ -459,8 +466,7 @@ class UniswapV3Position {
459
466
  const ratioY = this.debtY === 0 ? Infinity : depositedY / this.debtY;
460
467
  if (ratioX >= 1 && ratioY >= 1)
461
468
  return 0;
462
- // TODO do binary search instead
463
- return 1 - Math.min(ratioX, ratioY);
469
+ return this.getMinLeverageInRange(1, this.getInitialLeverage());
464
470
  }
465
471
  getMaxWithdrawable() {
466
472
  const depositedX = this.getDepositedX();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.226",
3
+ "version": "2.1.227",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",