impermax-sdk 2.1.183 → 2.1.185

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.
@@ -46,6 +46,7 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
46
46
  return this._getUpdatePositionActions(tokenId, await this.getAccountNftlp().getPositionObject(tokenId), depositADelta, depositBDelta, borrowADelta, borrowBDelta);
47
47
  }
48
48
  async _getUpdatePositionActions(tokenId, positionObject, depositADelta, depositBDelta, borrowADelta, borrowBDelta) {
49
+ const MIN_AMOUNT = 0.5; // TODO this should be calculated based on slippage and concentration
49
50
  let ethValue = 0;
50
51
  let approveA = 0;
51
52
  let approveB = 0;
@@ -56,6 +57,8 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
56
57
  throw new Error("Opposite depositADelta and depositBDelta signs");
57
58
  const router = this.getUniswapV3Router();
58
59
  const actionsGetter = this.getActionsGetter();
60
+ // TODO this is wrong -> otimalLiquidity is used only for deposit
61
+ // for withdraw we use proportions
59
62
  const optimalLiquidity = positionObject.getOptimalLiquidity(depositADelta, depositBDelta);
60
63
  depositADelta = optimalLiquidity.amountX;
61
64
  depositBDelta = optimalLiquidity.amountY;
@@ -68,9 +71,9 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
68
71
  console.log(borrowADelta, positionObject.debtX);
69
72
  console.log(borrowBDelta, positionObject.debtY);
70
73
  if (-borrowADelta * this.getDust() > positionObject.debtX)
71
- borrowADelta *= this.getUiMargin();
74
+ borrowADelta *= 1.0001;
72
75
  if (-borrowBDelta * this.getDust() > positionObject.debtY)
73
- borrowBDelta *= this.getUiMargin();
76
+ borrowBDelta *= 1.0001;
74
77
  const borrowableA = this.getLendingPool().getLendingPool().getBorrowableA();
75
78
  const borrowableB = this.getLendingPool().getLendingPool().getBorrowableB();
76
79
  const isEthA = await borrowableA.isETH();
@@ -78,6 +81,7 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
78
81
  // Borrow and mint
79
82
  if ((borrowADelta > 0 && depositADelta > 0) || (borrowBDelta > 0 && depositBDelta > 0)) {
80
83
  // slightly increase borrowDelta in order to avoid amountUser to be dust
84
+ // TODO what if one of these is negative?
81
85
  const actualBorrowADelta = Math.max(borrowADelta * this.getDust(), 0);
82
86
  const actualBorrowBDelta = Math.max(borrowBDelta * this.getDust(), 0);
83
87
  const amountAUser = Math.max(depositADelta - actualBorrowADelta, 0);
@@ -94,7 +98,7 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
94
98
  else {
95
99
  approveB += amountBUser;
96
100
  }
97
- actions.push(await actionsGetter.methods.getBorrowAndMintUniV3Action(await borrowableA.toBigNumber(amountAUser), await borrowableB.toBigNumber(amountBUser), await borrowableA.toBigNumber(depositADelta), await borrowableB.toBigNumber(depositBDelta), await borrowableA.toBigNumber(depositADelta / this.getUiMargin()), await borrowableB.toBigNumber(depositBDelta / this.getUiMargin())).call());
101
+ actions.push(await actionsGetter.methods.getBorrowAndMintUniV3Action(await borrowableA.toBigNumber(amountAUser), await borrowableB.toBigNumber(amountBUser), await borrowableA.toBigNumber(depositADelta), await borrowableB.toBigNumber(depositBDelta), await borrowableA.toBigNumber(depositADelta * MIN_AMOUNT), await borrowableB.toBigNumber(depositBDelta * MIN_AMOUNT)).call());
98
102
  depositADelta = 0;
99
103
  depositBDelta = 0;
100
104
  borrowADelta = Math.min(borrowADelta, 0);
@@ -102,7 +106,7 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
102
106
  }
103
107
  // Mint
104
108
  if (depositADelta > 0 || depositBDelta > 0) {
105
- actions.push(await actionsGetter.methods.getMintUniV3Action(await borrowableA.toBigNumber(depositADelta), await borrowableB.toBigNumber(depositBDelta), await borrowableA.toBigNumber(depositADelta / this.getUiMargin()), await borrowableB.toBigNumber(depositBDelta / this.getUiMargin())).call());
109
+ actions.push(await actionsGetter.methods.getMintUniV3Action(await borrowableA.toBigNumber(depositADelta), await borrowableB.toBigNumber(depositBDelta), await borrowableA.toBigNumber(depositADelta * MIN_AMOUNT), await borrowableB.toBigNumber(depositBDelta * MIN_AMOUNT)).call());
106
110
  if (isEthA) {
107
111
  ethValue += depositADelta;
108
112
  }
@@ -136,7 +140,7 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
136
140
  // remove LP and send liquidity to the router
137
141
  const liquidityToRemove = -optimalLiquidity.liquidity * this.getDust();
138
142
  const currentLiquidity = await this.getAccountNftlp().getLiquidity(tokenId);
139
- actions.push(await actionsGetter.methods.getRedeemUniV3Action((0, ether_utils_1.decimalToBalance)(Math.min(liquidityToRemove / currentLiquidity, 1), 18), await borrowableA.toBigNumber(-depositADelta / this.getUiMargin()), await borrowableB.toBigNumber(-depositBDelta / this.getUiMargin()), router._address).call());
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());
140
144
  if (isEthA || isEthB)
141
145
  doWithdrawEth = true;
142
146
  // withdraw or repay tokenA
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.183",
3
+ "version": "2.1.185",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",