impermax-sdk 2.1.233 → 2.1.235

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.
@@ -48,6 +48,8 @@ async function initializeUserData(account) {
48
48
  // Supply positions is same for v2 and v3
49
49
  for (const supplyPosition of userDataOfFactory.supplyPositions) {
50
50
  const lendingPoolId = supplyPosition.borrowable.lendingPool.id;
51
+ if (!this.whitelistedPairs[factory]?.includes(lendingPoolId))
52
+ continue;
51
53
  const underlyingId = supplyPosition.borrowable.underlying.id;
52
54
  const borrowableA = (await this.getLendingPool(factory, lendingPoolId)).getBorrowableA();
53
55
  const addressA = await borrowableA.getUnderlyingAddress();
@@ -8,14 +8,17 @@ async function initializeV2Positions(offchain, factory, rawUserData) {
8
8
  // Collateral positions
9
9
  for (const collateralPosition of rawUserData.collateralPositions) {
10
10
  const lendingPoolId = collateralPosition.collateral.lendingPool.id;
11
- if (!collateralPositions[lendingPoolId]) {
11
+ if (!offchain.whitelistedPairs[factory]?.includes(lendingPoolId))
12
+ continue;
13
+ if (!collateralPositions[lendingPoolId])
12
14
  collateralPositions[lendingPoolId] = [];
13
- }
14
15
  collateralPositions[lendingPoolId].push(collateralPosition);
15
16
  }
16
17
  // Borrow positions
17
18
  for (const borrowPosition of rawUserData.borrowPositions) {
18
19
  const lendingPoolId = borrowPosition.borrowable.lendingPool.id;
20
+ if (!offchain.whitelistedPairs[factory]?.includes(lendingPoolId))
21
+ continue;
19
22
  const underlyingId = borrowPosition.borrowable.underlying.id;
20
23
  const borrowableA = (await offchain.getLendingPool(factory, lendingPoolId)).getBorrowableA();
21
24
  const addressA = await borrowableA.getUnderlyingAddress();
@@ -92,7 +92,7 @@ class Offchain {
92
92
  //this.chainId = cfg.chainId;
93
93
  // TODO: refactor way of doing whitelist, messing up with user query since pairs dont get initialized
94
94
  // this.whitelistedPairs = whitelist ?? {};
95
- this.whitelistedPairs = {};
95
+ this.whitelistedPairs = whitelist ?? {};
96
96
  this.offchainMultichain = offchainMultichain;
97
97
  this.network = network;
98
98
  this.chainId = chainId_1.CHAIN_IDS[network];
@@ -462,11 +462,11 @@ class UniswapV3Position {
462
462
  let maxDeltaX = realX * highLeverage / currentLeverage;
463
463
  let maxDeltaY = realY * highLeverage / currentLeverage;
464
464
  if (maxDeltaX > this.availableToBorrowX) {
465
- maxDeltaY *= maxDeltaX / this.availableToBorrowX;
465
+ maxDeltaY *= this.availableToBorrowX / maxDeltaX;
466
466
  maxDeltaX = this.availableToBorrowX;
467
467
  }
468
468
  if (maxDeltaY > this.availableToBorrowY) {
469
- maxDeltaX *= maxDeltaY / this.availableToBorrowY;
469
+ maxDeltaX *= this.availableToBorrowY / maxDeltaY;
470
470
  maxDeltaY = this.availableToBorrowY;
471
471
  }
472
472
  const [deltaX, deltaY] = this.getMaxDeltaLeverageInRange(0, 0, maxDeltaX, maxDeltaY);
@@ -511,17 +511,17 @@ class UniswapV3Position {
511
511
  if (this.isLiquidatable())
512
512
  return 0;
513
513
  const equityValue = this.getEquityValue();
514
- const highDebtX = Math.max(this.getAmountXGivenValue(equityValue), this.availableToBorrowX);
514
+ const highDebtX = this.getAmountXGivenValue(equityValue);
515
515
  const [debtX,] = this.getMaxDeltaDebtInRange(0, 0, highDebtX, 0);
516
- return debtX + this.debtX - this.initialDebtX;
516
+ return Math.max(debtX + this.debtX - this.initialDebtX, this.availableToBorrowX);
517
517
  }
518
518
  getMaxBorrowableY() {
519
519
  if (this.isLiquidatable())
520
520
  return 0;
521
521
  const equityValue = this.getEquityValue();
522
- const highDebtY = Math.max(this.getAmountYGivenValue(equityValue), this.availableToBorrowY);
522
+ const highDebtY = this.getAmountYGivenValue(equityValue);
523
523
  const [, debtY] = this.getMaxDeltaDebtInRange(0, 0, 0, highDebtY);
524
- return debtY + this.debtY - this.initialDebtY;
524
+ return Math.max(debtY + this.debtY - this.initialDebtY, this.availableToBorrowY);
525
525
  }
526
526
  }
527
527
  exports.UniswapV3Position = UniswapV3Position;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.233",
3
+ "version": "2.1.235",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",