impermax-sdk 2.1.192 → 2.1.193
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.
|
@@ -58,11 +58,22 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
|
|
|
58
58
|
throw new Error("Opposite depositADelta and depositBDelta signs");
|
|
59
59
|
const router = this.getUniswapV3Router();
|
|
60
60
|
const actionsGetter = this.getActionsGetter();
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
let percentageToRemove = 0;
|
|
62
|
+
if (depositADelta > 0 || depositBDelta > 0) {
|
|
63
|
+
const optimalLiquidity = positionObject.getOptimalLiquidity(depositADelta, depositBDelta);
|
|
64
|
+
depositADelta = optimalLiquidity.amountX;
|
|
65
|
+
depositBDelta = optimalLiquidity.amountY;
|
|
66
|
+
}
|
|
67
|
+
else if (depositADelta < 0 || depositBDelta < 0) {
|
|
68
|
+
const currentDepositA = positionObject.getDepositedX();
|
|
69
|
+
const currentDepositB = positionObject.getDepositedY();
|
|
70
|
+
console.log("Withdrawing...", currentDepositA, currentDepositB, depositADelta, depositBDelta);
|
|
71
|
+
percentageToRemove = currentDepositA == 0 ? -depositBDelta / currentDepositB : -depositADelta / currentDepositA;
|
|
72
|
+
percentageToRemove = Math.min(percentageToRemove * this.getDust(), 1);
|
|
73
|
+
depositADelta = -currentDepositA * percentageToRemove;
|
|
74
|
+
depositBDelta = -currentDepositB * percentageToRemove;
|
|
75
|
+
console.log("Withdrawing...", percentageToRemove, depositADelta, depositBDelta);
|
|
76
|
+
}
|
|
66
77
|
// slightly increase repayAmount if we are repaying 100%
|
|
67
78
|
// TODO this is NOT working
|
|
68
79
|
// also, what if we are deleveraging? Repay amount should not be increased if userAmount is 0
|
|
@@ -138,9 +149,7 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
|
|
|
138
149
|
// Redeem
|
|
139
150
|
if (depositADelta < 0 || depositBDelta < 0) {
|
|
140
151
|
// remove LP and send liquidity to the router
|
|
141
|
-
|
|
142
|
-
const currentLiquidity = await this.getAccountNftlp().getLiquidity(tokenId);
|
|
143
|
-
actions.push(await actionsGetter.methods.getRedeemUniV3Action((0, ether_utils_1.decimalToBalance)(Math.min(liquidityToRemove / currentLiquidity, 1), 18), await borrowableA.toBigNumber(-depositADelta * MIN_AMOUNT), await borrowableB.toBigNumber(-depositBDelta * MIN_AMOUNT), router._address).call());
|
|
152
|
+
actions.push(await actionsGetter.methods.getRedeemUniV3Action((0, ether_utils_1.decimalToBalance)(percentageToRemove, 18), await borrowableA.toBigNumber(-depositADelta * MIN_AMOUNT), await borrowableB.toBigNumber(-depositBDelta * MIN_AMOUNT), router._address).call());
|
|
144
153
|
if (isEthA || isEthB)
|
|
145
154
|
doWithdrawEth = true;
|
|
146
155
|
// withdraw or repay tokenA
|