impermax-sdk 2.1.552 → 2.1.554
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.
|
@@ -20,7 +20,7 @@ export default abstract class OnchainInteractionsNftlpGenericCL extends OnchainI
|
|
|
20
20
|
approveB: number;
|
|
21
21
|
withCollateralTransfer: boolean;
|
|
22
22
|
}>;
|
|
23
|
-
getModifyExistingPositionActions(tokenId: number, depositADelta: number, depositBDelta: number, borrowADelta: number, borrowBDelta: number): Promise<{
|
|
23
|
+
getModifyExistingPositionActions(tokenId: number, depositADelta: number, depositBDelta: number, borrowADelta: number, borrowBDelta: number, isSwapAndClose?: boolean): Promise<{
|
|
24
24
|
actions: any[];
|
|
25
25
|
ethValue: number;
|
|
26
26
|
approveA: number;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const onchainInteractionsNftlp_1 = __importDefault(require("./onchainInteractionsNftlp"));
|
|
7
7
|
const ether_utils_1 = require("../../../../utils/ether-utils");
|
|
8
8
|
const general_1 = require("../../../../config/general");
|
|
9
|
+
const MAX_SWAP_AND_CLOSE_SLIPPAGE = 1.01;
|
|
9
10
|
class OnchainInteractionsNftlpGenericCL extends onchainInteractionsNftlp_1.default {
|
|
10
11
|
constructor() {
|
|
11
12
|
super(...arguments);
|
|
@@ -34,10 +35,10 @@ class OnchainInteractionsNftlpGenericCL extends onchainInteractionsNftlp_1.defau
|
|
|
34
35
|
result.actions.unshift(await this.getMintEmptyAction(tickSpacing, (await this.getNftlp().priceToTick(priceA, tickSpacing)).toString(), (await this.getNftlp().priceToTick(priceB, tickSpacing)).toString()));
|
|
35
36
|
return result;
|
|
36
37
|
}
|
|
37
|
-
async getModifyExistingPositionActions(tokenId, depositADelta, depositBDelta, borrowADelta, borrowBDelta) {
|
|
38
|
-
return this._getUpdatePositionActions(tokenId, await (await this.getAccountNftlp()).getPositionObject(tokenId), depositADelta, depositBDelta, borrowADelta, borrowBDelta);
|
|
38
|
+
async getModifyExistingPositionActions(tokenId, depositADelta, depositBDelta, borrowADelta, borrowBDelta, isSwapAndClose = false) {
|
|
39
|
+
return this._getUpdatePositionActions(tokenId, await (await this.getAccountNftlp()).getPositionObject(tokenId), depositADelta, depositBDelta, borrowADelta, borrowBDelta, isSwapAndClose);
|
|
39
40
|
}
|
|
40
|
-
async _getUpdatePositionActions(tokenId, positionObject, depositADelta, depositBDelta, borrowADelta, borrowBDelta) {
|
|
41
|
+
async _getUpdatePositionActions(tokenId, positionObject, depositADelta, depositBDelta, borrowADelta, borrowBDelta, isSwapAndClose = false) {
|
|
41
42
|
const MIN_AMOUNT = 0.5; // TODO this should be calculated based on slippage and concentration
|
|
42
43
|
let ethValue = 0;
|
|
43
44
|
let approveA = 0;
|
|
@@ -156,10 +157,17 @@ class OnchainInteractionsNftlpGenericCL extends onchainInteractionsNftlp_1.defau
|
|
|
156
157
|
// if repay >= redeem, we can repay MAX_UINT in order to use every redeemed fund for repaying
|
|
157
158
|
// otherwise we can set a repay limit in order to withdraw the funds not used to repay
|
|
158
159
|
const maximizeRepay = (-borrowADelta) >= (-depositADelta);
|
|
160
|
+
// if swap and close is activated and repay >= redeem, we will swap tokenB to tokenA
|
|
161
|
+
if (isSwapAndClose && maximizeRepay) {
|
|
162
|
+
const price = positionObject.marketPrice;
|
|
163
|
+
const amountOut = (-borrowADelta) - (-depositADelta);
|
|
164
|
+
const amountInMaximum = amountOut * price * MAX_SWAP_AND_CLOSE_SLIPPAGE;
|
|
165
|
+
actions.push(await actionsGetter.methods.getSwapAction(0, await borrowableA.toBigNumber(amountOut), await borrowableB.toBigNumber(amountInMaximum)).call());
|
|
166
|
+
}
|
|
159
167
|
actions.push(await actionsGetter.methods.getRepayRouterAction(0, maximizeRepay ? general_1.MAX_UINT : await borrowableA.toBigNumber(-borrowADelta), isEthA ? router._address : this.getAccountAddress()).call());
|
|
160
168
|
// after repayRouter, we need to call repayUser only if repay > redeem and the token is not ETH
|
|
161
169
|
// (for ETH we've already repaid since repayETH is done through repayRouter)
|
|
162
|
-
if (!maximizeRepay)
|
|
170
|
+
if (!maximizeRepay || isSwapAndClose)
|
|
163
171
|
borrowADelta = 0;
|
|
164
172
|
else if (isEthA) {
|
|
165
173
|
ethValue += depositADelta - borrowADelta;
|
|
@@ -179,8 +187,14 @@ class OnchainInteractionsNftlpGenericCL extends onchainInteractionsNftlp_1.defau
|
|
|
179
187
|
else if (-borrowBDelta * 1.0001 > positionObject.debtY)
|
|
180
188
|
borrowBDelta *= 1.0001;
|
|
181
189
|
const maximizeRepay = (-borrowBDelta) > (-depositBDelta);
|
|
190
|
+
if (isSwapAndClose && maximizeRepay) {
|
|
191
|
+
const price = positionObject.marketPrice;
|
|
192
|
+
const amountOut = (-borrowBDelta) - (-depositBDelta);
|
|
193
|
+
const amountInMaximum = amountOut / price * MAX_SWAP_AND_CLOSE_SLIPPAGE;
|
|
194
|
+
actions.push(await actionsGetter.methods.getSwapAction(1, await borrowableB.toBigNumber(amountOut), await borrowableA.toBigNumber(amountInMaximum)).call());
|
|
195
|
+
}
|
|
182
196
|
actions.push(await actionsGetter.methods.getRepayRouterAction(1, maximizeRepay ? general_1.MAX_UINT : await borrowableB.toBigNumber(-borrowBDelta), isEthB ? router._address : this.getAccountAddress()).call());
|
|
183
|
-
if (!maximizeRepay)
|
|
197
|
+
if (!maximizeRepay || isSwapAndClose)
|
|
184
198
|
borrowBDelta = 0;
|
|
185
199
|
else if (isEthB) {
|
|
186
200
|
ethValue += depositBDelta - borrowBDelta;
|