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
|
|
334
|
-
amountX:
|
|
335
|
-
amountY:
|
|
335
|
+
liquidity,
|
|
336
|
+
amountX: this.getRealXGivenLiquidity(liquidity),
|
|
337
|
+
amountY: this.getRealYGivenLiquidity(liquidity),
|
|
336
338
|
};
|
|
337
339
|
}
|
|
338
340
|
getOptimalWithdraw(amountX, amountY, withdrawAtLeast = true) {
|