impermax-sdk 2.1.228 → 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.
@@ -10,8 +10,8 @@ interface PositionData {
10
10
  feeGrowthInside1LastX128: number;
11
11
  unclaimedFees0: number;
12
12
  unclaimedFees1: number;
13
- totalFeesEarned0: number;
14
- totalFeesEarned1: number;
13
+ storedTotalFeesEarned0: number;
14
+ storedTotalFeesEarned1: number;
15
15
  }
16
16
  export type UniswapV3PositionData = NftlpPosition & {
17
17
  nftlp: PositionData;
@@ -81,11 +81,11 @@ class OffchainAccountNftlpUniswapV3 extends offchainAccountNftlp_1.default {
81
81
  }
82
82
  }
83
83
  async getTotalAccruedFees(tokenId) {
84
- const { totalFeesEarned0, totalFeesEarned1 } = (await this.getPositionData(tokenId));
84
+ const { storedTotalFeesEarned0, storedTotalFeesEarned1 } = (await this.getPositionData(tokenId));
85
85
  const { uncollectedFees0, uncollectedFees1 } = await this.getUncollectedFees(tokenId);
86
86
  return {
87
- accruedFees0: Number(totalFeesEarned0) + uncollectedFees0,
88
- accruedFees1: Number(totalFeesEarned1) + uncollectedFees1,
87
+ accruedFees0: Number(storedTotalFeesEarned0) + uncollectedFees0,
88
+ accruedFees1: Number(storedTotalFeesEarned1) + uncollectedFees1,
89
89
  };
90
90
  }
91
91
  }
@@ -467,8 +467,8 @@ class PonderQueryBuilder {
467
467
  tokenId
468
468
  feeGrowthInside0LastX128
469
469
  feeGrowthInside1LastX128
470
- totalFeesEarned0
471
- totalFeesEarned1
470
+ storedTotalFeesEarned0
471
+ storedTotalFeesEarned1
472
472
  id
473
473
  nftlp {
474
474
  factory {
@@ -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 * this.getDust(), 0);
97
- const actualBorrowBDelta = Math.max(borrowBDelta * this.getDust(), 0);
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) > (-depositADelta) / this.getDust();
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
- const maximizeRepay = (-borrowBDelta) > (-depositBDelta) / this.getDust();
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.228",
3
+ "version": "2.1.230",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",