impermax-sdk 2.1.233 → 2.1.236
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 (!
|
|
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();
|
package/lib/offchain/offchain.js
CHANGED
|
@@ -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];
|
|
@@ -461,13 +461,15 @@ class UniswapV3Position {
|
|
|
461
461
|
const realY = this.getRealY();
|
|
462
462
|
let maxDeltaX = realX * highLeverage / currentLeverage;
|
|
463
463
|
let maxDeltaY = realY * highLeverage / currentLeverage;
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
464
|
+
const actualAvailableToBorrowX = this.availableToBorrowX - (this.debtX - this.initialDebtX);
|
|
465
|
+
const actualAvailableToBorrowY = this.availableToBorrowY - (this.debtY - this.initialDebtY);
|
|
466
|
+
if (maxDeltaX > actualAvailableToBorrowX) {
|
|
467
|
+
maxDeltaY *= actualAvailableToBorrowX / maxDeltaX;
|
|
468
|
+
maxDeltaX = actualAvailableToBorrowX;
|
|
467
469
|
}
|
|
468
|
-
if (maxDeltaY >
|
|
469
|
-
maxDeltaX *=
|
|
470
|
-
maxDeltaY =
|
|
470
|
+
if (maxDeltaY > actualAvailableToBorrowY) {
|
|
471
|
+
maxDeltaX *= actualAvailableToBorrowY / maxDeltaY;
|
|
472
|
+
maxDeltaY = actualAvailableToBorrowY;
|
|
471
473
|
}
|
|
472
474
|
const [deltaX, deltaY] = this.getMaxDeltaLeverageInRange(0, 0, maxDeltaX, maxDeltaY);
|
|
473
475
|
const collateralValue = this.getCollateralValue();
|
|
@@ -511,17 +513,17 @@ class UniswapV3Position {
|
|
|
511
513
|
if (this.isLiquidatable())
|
|
512
514
|
return 0;
|
|
513
515
|
const equityValue = this.getEquityValue();
|
|
514
|
-
const highDebtX =
|
|
516
|
+
const highDebtX = this.getAmountXGivenValue(equityValue);
|
|
515
517
|
const [debtX,] = this.getMaxDeltaDebtInRange(0, 0, highDebtX, 0);
|
|
516
|
-
return debtX + this.debtX - this.initialDebtX;
|
|
518
|
+
return Math.min(debtX + this.debtX - this.initialDebtX, this.availableToBorrowX);
|
|
517
519
|
}
|
|
518
520
|
getMaxBorrowableY() {
|
|
519
521
|
if (this.isLiquidatable())
|
|
520
522
|
return 0;
|
|
521
523
|
const equityValue = this.getEquityValue();
|
|
522
|
-
const highDebtY =
|
|
524
|
+
const highDebtY = this.getAmountYGivenValue(equityValue);
|
|
523
525
|
const [, debtY] = this.getMaxDeltaDebtInRange(0, 0, 0, highDebtY);
|
|
524
|
-
return debtY + this.debtY - this.initialDebtY;
|
|
526
|
+
return Math.min(debtY + this.debtY - this.initialDebtY, this.availableToBorrowY);
|
|
525
527
|
}
|
|
526
528
|
}
|
|
527
529
|
exports.UniswapV3Position = UniswapV3Position;
|