impermax-sdk 2.1.246 → 2.1.248

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.
@@ -44,4 +44,17 @@ export default interface Position {
44
44
  amountX: number;
45
45
  amountY: number;
46
46
  };
47
+ getOptimalLiquidity(maxAmountX: number, maxAmountY: number): {
48
+ liquidity: number;
49
+ amountX: number;
50
+ amountY: number;
51
+ };
52
+ getOptimalWithdraw(amountX: number, amountY: number, withdrawAtLeast?: boolean): {
53
+ amountX: number;
54
+ amountY: number;
55
+ };
56
+ getOptimalWithdrawForDeleverage(targetLeverage: number): {
57
+ amountX: number;
58
+ amountY: number;
59
+ } | null;
47
60
  }
@@ -326,13 +326,15 @@ class UniswapV2Position {
326
326
  }
327
327
  // amountX and amountY are expected to have the same sign
328
328
  getOptimalLiquidity(amountX, amountY) {
329
+ amountX = Number.isNaN(amountX) ? 0 : amountX ?? 0;
330
+ amountY = Number.isNaN(amountY) ? 0 : amountY ?? 0;
329
331
  const liquidityA = amountX * Math.sqrt(this.marketPrice);
330
332
  const liquidityB = amountY / Math.sqrt(this.marketPrice);
331
333
  const liquidity = Math.min(liquidityA, liquidityB);
332
334
  return {
333
- liquidity: Number.isNaN(liquidity) ? 0 : liquidity ?? 0,
334
- amountX: Number.isNaN(amountX) ? 0 : amountX ?? 0,
335
- amountY: Number.isNaN(amountY) ? 0 : amountY ?? 0,
335
+ liquidity,
336
+ amountX: this.getRealXGivenLiquidity(liquidity),
337
+ amountY: this.getRealYGivenLiquidity(liquidity),
336
338
  };
337
339
  }
338
340
  getOptimalWithdraw(amountX, amountY, withdrawAtLeast = true) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.246",
3
+ "version": "2.1.248",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",