impermax-sdk 2.1.266 → 2.1.267

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.
@@ -60,6 +60,8 @@ class OffchainAccountNftlpUniswapV3 extends offchainAccountNftlp_1.default {
60
60
  priceB: await this.getPriceB(tokenId),
61
61
  safetyMargin: await this.getLendingPool().getSafetyMargin(),
62
62
  liquidationPenalty: await this.getLendingPool().getLiquidationPenalty(),
63
+ borrowableX: await this.getNftlp().getLendingPool().getBorrowableA().createBorrowableObject(),
64
+ borrowableY: await this.getNftlp().getLendingPool().getBorrowableB().createBorrowableObject(),
63
65
  });
64
66
  }
65
67
  async getPositionObject(tokenId) {
@@ -17,6 +17,6 @@ export default class OffchainAccountCollateralV2 extends OffchainAccountPoolToke
17
17
  getTokens(): Promise<number>;
18
18
  getAmount(): Promise<number>;
19
19
  private getLiquidity;
20
- createPositionObject(lockStateChange?: boolean): Promise<UniswapV2Position>;
20
+ createPositionObject(): Promise<UniswapV2Position>;
21
21
  getPositionObject(): Promise<UniswapV2Position>;
22
22
  }
@@ -33,7 +33,7 @@ class OffchainAccountCollateralV2 extends offchainAccountPoolToken_1.default {
33
33
  return await this.getTokens() * await this.getCollateral().getGrowthFactor();
34
34
  }
35
35
  // Notice: createNewPositionObject is not needed for V2
36
- async createPositionObject(lockStateChange = false) {
36
+ async createPositionObject() {
37
37
  //if (await this.getLendingPool().getLendingPool().isStable()) {
38
38
  // TODO return stablePosition
39
39
  //} else {
@@ -45,6 +45,8 @@ class OffchainAccountCollateralV2 extends offchainAccountPoolToken_1.default {
45
45
  oraclePrice: await this.getLendingPool().getLendingPool().getMarketPrice(),
46
46
  safetyMargin: await this.getLendingPool().getSafetyMargin(),
47
47
  liquidationPenalty: await this.getLendingPool().getLiquidationPenalty(),
48
+ borrowableX: await this.getLendingPool().getLendingPool().getBorrowableA().createBorrowableObject(),
49
+ borrowableY: await this.getLendingPool().getLendingPool().getBorrowableB().createBorrowableObject(),
48
50
  });
49
51
  //}
50
52
  }
@@ -99,8 +99,8 @@ class OnchainAccountNftlpUniswapV3 extends onchainAccountNftlp_1.default {
99
99
  priceB: await this.getPriceB(tokenId),
100
100
  safetyMargin: await this.getLendingPool().getSafetyMargin(),
101
101
  liquidationPenalty: await this.getLendingPool().getLiquidationPenalty(),
102
- availableToBorrowX: await this.getNftlp().getLendingPool().getBorrowableA().getAvailableToBorrow(),
103
- availableToBorrowY: await this.getNftlp().getLendingPool().getBorrowableB().getAvailableToBorrow(),
102
+ borrowableX: await this.getNftlp().getLendingPool().getBorrowableA().createBorrowableObject(lockStateChange),
103
+ borrowableY: await this.getNftlp().getLendingPool().getBorrowableB().createBorrowableObject(lockStateChange),
104
104
  lockStateChange,
105
105
  });
106
106
  }
@@ -117,8 +117,8 @@ class OnchainAccountNftlpUniswapV3 extends onchainAccountNftlp_1.default {
117
117
  priceB: await this.getNftlp().nearestUsableTickPrice(priceB, fee),
118
118
  safetyMargin: await this.getLendingPool().getSafetyMargin(),
119
119
  liquidationPenalty: await this.getLendingPool().getLiquidationPenalty(),
120
- availableToBorrowX: await this.getNftlp().getLendingPool().getBorrowableA().getAvailableToBorrow(),
121
- availableToBorrowY: await this.getNftlp().getLendingPool().getBorrowableB().getAvailableToBorrow(),
120
+ borrowableX: await this.getNftlp().getLendingPool().getBorrowableA().createBorrowableObject(lockStateChange),
121
+ borrowableY: await this.getNftlp().getLendingPool().getBorrowableB().createBorrowableObject(lockStateChange),
122
122
  lockStateChange,
123
123
  });
124
124
  }
@@ -45,8 +45,8 @@ class OnchainAccountCollateralV2 extends onchainAccountPoolToken_1.default {
45
45
  oraclePrice: await this.getLendingPool().getLendingPool().getTWAPPrice(),
46
46
  safetyMargin: await this.getLendingPool().getSafetyMargin(),
47
47
  liquidationPenalty: await this.getLendingPool().getLiquidationPenalty(),
48
- availableToBorrowX: await this.getLendingPool().getLendingPool().getBorrowableA().getAvailableToBorrow(),
49
- availableToBorrowY: await this.getLendingPool().getLendingPool().getBorrowableB().getAvailableToBorrow(),
48
+ borrowableX: await this.getLendingPool().getLendingPool().getBorrowableA().createBorrowableObject(lockStateChange),
49
+ borrowableY: await this.getLendingPool().getLendingPool().getBorrowableB().createBorrowableObject(lockStateChange),
50
50
  lockStateChange,
51
51
  });
52
52
  //}
@@ -1,4 +1,5 @@
1
1
  import Position from "./interface";
2
+ import { BorrowableEntity } from "../borrowableEntity";
2
3
  export interface GenericPositionParams {
3
4
  liquidity: number;
4
5
  debtX: number;
@@ -7,8 +8,8 @@ export interface GenericPositionParams {
7
8
  oraclePrice: number;
8
9
  safetyMargin: number;
9
10
  liquidationPenalty: number;
10
- availableToBorrowX?: number;
11
- availableToBorrowY?: number;
11
+ borrowableX: BorrowableEntity;
12
+ borrowableY: BorrowableEntity;
12
13
  lockStateChange?: boolean;
13
14
  }
14
15
  export declare abstract class GenericPosition implements Position {
@@ -30,8 +31,8 @@ export declare abstract class GenericPosition implements Position {
30
31
  oraclePrice: number;
31
32
  safetyMargin: number;
32
33
  liquidationPenalty: number;
33
- availableToBorrowX: number;
34
- availableToBorrowY: number;
34
+ borrowableX: BorrowableEntity;
35
+ borrowableY: BorrowableEntity;
35
36
  constructor(params: GenericPositionParams);
36
37
  protected checkLock(): void;
37
38
  /**
@@ -15,8 +15,8 @@ class GenericPosition {
15
15
  this.oraclePrice = params.oraclePrice;
16
16
  this.safetyMargin = params.safetyMargin;
17
17
  this.liquidationPenalty = params.liquidationPenalty;
18
- this.availableToBorrowX = params.availableToBorrowX ?? 0;
19
- this.availableToBorrowY = params.availableToBorrowY ?? 0;
18
+ this.borrowableX = params.borrowableX;
19
+ this.borrowableY = params.borrowableY;
20
20
  this.lockStateChange = params.lockStateChange ?? true;
21
21
  this.state = 0;
22
22
  }
@@ -237,26 +237,30 @@ class GenericPosition {
237
237
  this.setLiquidity(this.initialLiquidity * (1 - percentageToRemove));
238
238
  }
239
239
  borrowX(amount) {
240
- if (amount > this.availableToBorrowX) {
240
+ if (amount > this.borrowableX.getInitialAvailableToBorrow()) {
241
241
  throw new Error("Trying to borrow more than available liquidity");
242
242
  }
243
243
  else {
244
244
  this.setDebtX(this.initialDebtX + amount);
245
+ this.borrowableX.borrow(amount);
245
246
  }
246
247
  }
247
248
  borrowY(amount) {
248
- if (amount > this.availableToBorrowY) {
249
+ if (amount > this.borrowableY.getInitialAvailableToBorrow()) {
249
250
  throw new Error("Trying to borrow more than available liquidity");
250
251
  }
251
252
  else {
252
253
  this.setDebtY(this.initialDebtY + amount);
254
+ this.borrowableY.borrow(amount);
253
255
  }
254
256
  }
255
257
  repayX(amount) {
256
258
  this.setDebtX(Math.max(this.initialDebtX - amount, 0));
259
+ this.borrowableX.repay(amount);
257
260
  }
258
261
  repayY(amount) {
259
262
  this.setDebtY(Math.max(this.initialDebtY - amount, 0));
263
+ this.borrowableY.repay(amount);
260
264
  }
261
265
  /**
262
266
  * PUBLIC GETTERS
@@ -399,8 +403,8 @@ class GenericPosition {
399
403
  const realY = this.getRealY();
400
404
  let maxDeltaX = realX * highLeverage / currentLeverage;
401
405
  let maxDeltaY = realY * highLeverage / currentLeverage;
402
- const actualAvailableToBorrowX = this.availableToBorrowX - (this.debtX - this.initialDebtX);
403
- const actualAvailableToBorrowY = this.availableToBorrowY - (this.debtY - this.initialDebtY);
406
+ const actualAvailableToBorrowX = this.borrowableX.getAvailableToBorrow();
407
+ const actualAvailableToBorrowY = this.borrowableY.getAvailableToBorrow();
404
408
  if (maxDeltaX > actualAvailableToBorrowX) {
405
409
  maxDeltaY *= actualAvailableToBorrowX / maxDeltaX;
406
410
  maxDeltaX = actualAvailableToBorrowX;
@@ -453,7 +457,7 @@ class GenericPosition {
453
457
  const equityValue = this.getEquityValue();
454
458
  const highDebtX = this.getAmountXGivenValue(equityValue);
455
459
  const [debtX,] = this.getMaxDeltaDebtInRange(0, 0, highDebtX, 0);
456
- return Math.min(debtX + this.debtX - this.initialDebtX, this.availableToBorrowX);
460
+ return Math.min(debtX + this.debtX - this.initialDebtX, this.borrowableX.getAvailableToBorrow());
457
461
  }
458
462
  getMaxBorrowableY() {
459
463
  if (this.isLiquidatable())
@@ -461,7 +465,7 @@ class GenericPosition {
461
465
  const equityValue = this.getEquityValue();
462
466
  const highDebtY = this.getAmountYGivenValue(equityValue);
463
467
  const [, debtY] = this.getMaxDeltaDebtInRange(0, 0, 0, highDebtY);
464
- return Math.min(debtY + this.debtY - this.initialDebtY, this.availableToBorrowY);
468
+ return Math.min(debtY + this.debtY - this.initialDebtY, this.borrowableY.getAvailableToBorrow());
465
469
  }
466
470
  }
467
471
  exports.GenericPosition = GenericPosition;
@@ -1,4 +1,5 @@
1
1
  import GenericPosition from "../genericPosition";
2
+ import { BorrowableEntity } from "../../borrowableEntity";
2
3
  export interface UniswapV2PositionParams {
3
4
  liquidity: number;
4
5
  debtX: number;
@@ -7,8 +8,8 @@ export interface UniswapV2PositionParams {
7
8
  oraclePrice: number;
8
9
  safetyMargin: number;
9
10
  liquidationPenalty: number;
10
- availableToBorrowX?: number;
11
- availableToBorrowY?: number;
11
+ borrowableX: BorrowableEntity;
12
+ borrowableY: BorrowableEntity;
12
13
  lockStateChange?: boolean;
13
14
  }
14
15
  export declare class UniswapV2Position extends GenericPosition {
@@ -1,4 +1,5 @@
1
1
  import GenericPosition from "../genericPosition";
2
+ import { BorrowableEntity } from "../../borrowableEntity";
2
3
  export interface UniswapV3PositionParams {
3
4
  liquidity: number;
4
5
  unclaimedFeesX: number;
@@ -11,8 +12,8 @@ export interface UniswapV3PositionParams {
11
12
  oraclePrice: number;
12
13
  safetyMargin: number;
13
14
  liquidationPenalty: number;
14
- availableToBorrowX?: number;
15
- availableToBorrowY?: number;
15
+ borrowableX: BorrowableEntity;
16
+ borrowableY: BorrowableEntity;
16
17
  lockStateChange?: boolean;
17
18
  }
18
19
  export declare class UniswapV3Position extends GenericPosition {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.266",
3
+ "version": "2.1.267",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",