impermax-sdk 2.1.232 → 2.1.233
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.
|
@@ -278,10 +278,20 @@ class UniswapV3Position {
|
|
|
278
278
|
this.updateLiquidity(this.initialLiquidity * (1 - percentageToRemove));
|
|
279
279
|
}
|
|
280
280
|
borrowX(amount) {
|
|
281
|
-
|
|
281
|
+
if (amount > this.availableToBorrowX) {
|
|
282
|
+
throw new Error("Trying to borrow more than available liquidity");
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
this.setDebtX(this.initialDebtX + amount);
|
|
286
|
+
}
|
|
282
287
|
}
|
|
283
288
|
borrowY(amount) {
|
|
284
|
-
|
|
289
|
+
if (amount > this.availableToBorrowY) {
|
|
290
|
+
throw new Error("Trying to borrow more than available liquidity");
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
this.setDebtY(this.initialDebtY + amount);
|
|
294
|
+
}
|
|
285
295
|
}
|
|
286
296
|
repayX(amount) {
|
|
287
297
|
this.setDebtX(Math.max(this.initialDebtX - amount, 0));
|
|
@@ -449,8 +459,16 @@ class UniswapV3Position {
|
|
|
449
459
|
}
|
|
450
460
|
const realX = this.getRealX();
|
|
451
461
|
const realY = this.getRealY();
|
|
452
|
-
|
|
453
|
-
|
|
462
|
+
let maxDeltaX = realX * highLeverage / currentLeverage;
|
|
463
|
+
let maxDeltaY = realY * highLeverage / currentLeverage;
|
|
464
|
+
if (maxDeltaX > this.availableToBorrowX) {
|
|
465
|
+
maxDeltaY *= maxDeltaX / this.availableToBorrowX;
|
|
466
|
+
maxDeltaX = this.availableToBorrowX;
|
|
467
|
+
}
|
|
468
|
+
if (maxDeltaY > this.availableToBorrowY) {
|
|
469
|
+
maxDeltaX *= maxDeltaY / this.availableToBorrowY;
|
|
470
|
+
maxDeltaY = this.availableToBorrowY;
|
|
471
|
+
}
|
|
454
472
|
const [deltaX, deltaY] = this.getMaxDeltaLeverageInRange(0, 0, maxDeltaX, maxDeltaY);
|
|
455
473
|
const collateralValue = this.getCollateralValue();
|
|
456
474
|
const additionalValue = this.getValueGivenAmounts(deltaX, deltaY);
|
|
@@ -493,7 +511,7 @@ class UniswapV3Position {
|
|
|
493
511
|
if (this.isLiquidatable())
|
|
494
512
|
return 0;
|
|
495
513
|
const equityValue = this.getEquityValue();
|
|
496
|
-
const highDebtX = this.getAmountXGivenValue(equityValue);
|
|
514
|
+
const highDebtX = Math.max(this.getAmountXGivenValue(equityValue), this.availableToBorrowX);
|
|
497
515
|
const [debtX,] = this.getMaxDeltaDebtInRange(0, 0, highDebtX, 0);
|
|
498
516
|
return debtX + this.debtX - this.initialDebtX;
|
|
499
517
|
}
|
|
@@ -501,7 +519,7 @@ class UniswapV3Position {
|
|
|
501
519
|
if (this.isLiquidatable())
|
|
502
520
|
return 0;
|
|
503
521
|
const equityValue = this.getEquityValue();
|
|
504
|
-
const highDebtY = this.getAmountYGivenValue(equityValue);
|
|
522
|
+
const highDebtY = Math.max(this.getAmountYGivenValue(equityValue), this.availableToBorrowY);
|
|
505
523
|
const [, debtY] = this.getMaxDeltaDebtInRange(0, 0, 0, highDebtY);
|
|
506
524
|
return debtY + this.debtY - this.initialDebtY;
|
|
507
525
|
}
|