impermax-sdk 2.1.229 → 2.1.230
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.
|
@@ -67,25 +67,11 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
|
|
|
67
67
|
else if (depositADelta < 0 || depositBDelta < 0) {
|
|
68
68
|
const currentDepositA = positionObject.getDepositedX();
|
|
69
69
|
const currentDepositB = positionObject.getDepositedY();
|
|
70
|
-
console.log("Withdrawing...", currentDepositA, currentDepositB, depositADelta, depositBDelta);
|
|
71
70
|
percentageToRemove = currentDepositA == 0 ? -depositBDelta / currentDepositB : -depositADelta / currentDepositA;
|
|
72
71
|
percentageToRemove = Math.min(percentageToRemove * this.getDust(), 1);
|
|
73
72
|
depositADelta = -currentDepositA * percentageToRemove;
|
|
74
73
|
depositBDelta = -currentDepositB * percentageToRemove;
|
|
75
|
-
console.log("Withdrawing...", percentageToRemove, depositADelta, depositBDelta);
|
|
76
74
|
}
|
|
77
|
-
// slightly increase repayAmount if we are repaying 100%
|
|
78
|
-
// TODO this is NOT working
|
|
79
|
-
// also, what if we are deleveraging? Repay amount should not be increased if userAmount is 0
|
|
80
|
-
// but at the same time how can we repay 100% if the borrow amount is constantly increasing?
|
|
81
|
-
// (it's better if the ui works before testing this)
|
|
82
|
-
console.log("slightly increase repayAmount");
|
|
83
|
-
console.log(borrowADelta, positionObject.debtX);
|
|
84
|
-
console.log(borrowBDelta, positionObject.debtY);
|
|
85
|
-
if (-borrowADelta * this.getDust() > positionObject.debtX)
|
|
86
|
-
borrowADelta *= 1.0001;
|
|
87
|
-
if (-borrowBDelta * this.getDust() > positionObject.debtY)
|
|
88
|
-
borrowBDelta *= 1.0001;
|
|
89
75
|
const borrowableA = this.getLendingPool().getLendingPool().getBorrowableA();
|
|
90
76
|
const borrowableB = this.getLendingPool().getLendingPool().getBorrowableB();
|
|
91
77
|
const isEthA = await borrowableA.isETH();
|
|
@@ -93,8 +79,8 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
|
|
|
93
79
|
// Borrow and mint
|
|
94
80
|
if ((borrowADelta > 0 && depositADelta > 0) || (borrowBDelta > 0 && depositBDelta > 0)) {
|
|
95
81
|
// slightly increase borrowDelta in order to avoid amountUser to be dust
|
|
96
|
-
const actualBorrowADelta = Math.max(borrowADelta *
|
|
97
|
-
const actualBorrowBDelta = Math.max(borrowBDelta *
|
|
82
|
+
const actualBorrowADelta = Math.max(borrowADelta * 1.0001, 0);
|
|
83
|
+
const actualBorrowBDelta = Math.max(borrowBDelta * 1.0001, 0);
|
|
98
84
|
const amountAUser = Math.max(depositADelta - actualBorrowADelta, 0);
|
|
99
85
|
const amountBUser = Math.max(depositBDelta - actualBorrowBDelta, 0);
|
|
100
86
|
if (isEthA) {
|
|
@@ -154,9 +140,15 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
|
|
|
154
140
|
doWithdrawEth = true;
|
|
155
141
|
// withdraw or repay tokenA
|
|
156
142
|
if (borrowADelta < 0) {
|
|
143
|
+
// if we are repaying what we're withdrawing, round the repay amount to the withdraw amount
|
|
144
|
+
if (borrowADelta * 1.0001 < depositADelta && depositADelta * 1.0001 < borrowADelta)
|
|
145
|
+
borrowADelta = depositADelta;
|
|
146
|
+
// if we are repaying 100%, slightly increase the repay amount
|
|
147
|
+
else if (-borrowADelta * 1.0001 > positionObject.debtX)
|
|
148
|
+
borrowADelta *= 1.0001;
|
|
157
149
|
// if repay >= redeem, we can repay MAX_UINT in order to use every redeemed fund for repaying
|
|
158
150
|
// otherwise we can set a repay limit in order to withdraw the funds not used to repay
|
|
159
|
-
const maximizeRepay = (-borrowADelta)
|
|
151
|
+
const maximizeRepay = (-borrowADelta) >= (-depositADelta);
|
|
160
152
|
actions.push(await actionsGetter.methods.getRepayRouterAction(0, maximizeRepay ? general_1.MAX_UINT : await borrowableA.toBigNumber(-borrowADelta), isEthA ? router._address : this.getAccountAddress()).call());
|
|
161
153
|
// after repayRouter, we need to call repayUser only if repay > redeem and the token is not ETH
|
|
162
154
|
// (for ETH we've already repaid since repayETH is done through repayRouter)
|
|
@@ -175,7 +167,11 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
|
|
|
175
167
|
}
|
|
176
168
|
// withdraw or repay tokenB (same logic as tokenA)
|
|
177
169
|
if (borrowBDelta < 0) {
|
|
178
|
-
|
|
170
|
+
if (borrowBDelta * 1.0001 < depositBDelta && depositBDelta * 1.0001 < borrowBDelta)
|
|
171
|
+
borrowBDelta = depositBDelta;
|
|
172
|
+
else if (-borrowBDelta * 1.0001 > positionObject.debtY)
|
|
173
|
+
borrowBDelta *= 1.0001;
|
|
174
|
+
const maximizeRepay = (-borrowBDelta) > (-depositBDelta);
|
|
179
175
|
actions.push(await actionsGetter.methods.getRepayRouterAction(1, maximizeRepay ? general_1.MAX_UINT : await borrowableB.toBigNumber(-borrowBDelta), isEthB ? router._address : this.getAccountAddress()).call());
|
|
180
176
|
if (!maximizeRepay)
|
|
181
177
|
borrowBDelta = 0;
|
|
@@ -193,6 +189,8 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
|
|
|
193
189
|
}
|
|
194
190
|
// Repay
|
|
195
191
|
if (borrowADelta < 0) {
|
|
192
|
+
if (-borrowADelta * 1.0001 > positionObject.debtX)
|
|
193
|
+
borrowADelta *= 1.0001;
|
|
196
194
|
if (isEthA) {
|
|
197
195
|
actions.push(await actionsGetter.methods.getRepayRouterAction(0, general_1.MAX_UINT, router._address).call());
|
|
198
196
|
ethValue -= borrowADelta;
|
|
@@ -204,6 +202,8 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
|
|
|
204
202
|
}
|
|
205
203
|
}
|
|
206
204
|
if (borrowBDelta < 0) {
|
|
205
|
+
if (-borrowBDelta * 1.0001 > positionObject.debtY)
|
|
206
|
+
borrowBDelta *= 1.0001;
|
|
207
207
|
if (isEthB) {
|
|
208
208
|
actions.push(await actionsGetter.methods.getRepayRouterAction(1, general_1.MAX_UINT, router._address).call());
|
|
209
209
|
ethValue -= borrowBDelta;
|