impermax-sdk 2.1.85 → 2.1.88

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.
@@ -18,6 +18,7 @@ export default class OnchainNftlpUniswapV3 extends OnchainNftlp {
18
18
  protected initializeNftlp(): any;
19
19
  protected initializeUniswapV3Pool(fee: number): Promise<Contract | null>;
20
20
  getUniswapV3Pool(fee: number): Promise<any>;
21
+ private priceAdjustment;
21
22
  protected initializeMarketPrice(): Promise<number>;
22
23
  protected initializeOraclePrice(): Promise<number>;
23
24
  tickToPrice(tick: number): Promise<number>;
@@ -56,15 +56,24 @@ class OnchainNftlpUniswapV3 extends onchainNftlp_1.default {
56
56
  return this.cache.uniswapV3Pools[fee];
57
57
  });
58
58
  }
59
+ priceAdjustment() {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ const decimalA = yield this.getLendingPool().getBorrowableA().getDecimals();
62
+ const decimalB = yield this.getLendingPool().getBorrowableB().getDecimals();
63
+ const netDecimal = decimalA - decimalB;
64
+ return Math.pow(10, netDecimal);
65
+ });
66
+ }
59
67
  initializeMarketPrice() {
60
68
  return __awaiter(this, void 0, void 0, function* () {
61
69
  let priceCumulative = 0;
62
70
  let liquidityCumulative = 0;
71
+ const priceAdjustment = yield this.priceAdjustment();
63
72
  for (const fee of FEES) {
64
73
  const pool = yield this.getUniswapV3Pool(fee);
65
74
  if (!pool)
66
75
  continue;
67
- const price = Math.pow(((yield pool.methods.slot0().call()).sqrtPriceX96 / Math.pow(2, 96)), 2);
76
+ const price = Math.pow(((yield pool.methods.slot0().call()).sqrtPriceX96 / Math.pow(2, 96)), 2) * priceAdjustment;
68
77
  const liquidity = (yield pool.methods.liquidity().call()) * 1;
69
78
  priceCumulative += price * liquidity;
70
79
  liquidityCumulative += liquidity;
@@ -75,24 +84,21 @@ class OnchainNftlpUniswapV3 extends onchainNftlp_1.default {
75
84
  initializeOraclePrice() {
76
85
  return __awaiter(this, void 0, void 0, function* () {
77
86
  const nftlp = yield this.getNftlp();
78
- return Math.pow((nftlp.methods.oraclePriceSqrtX96().call() / Math.pow(2, 96)), 2);
87
+ const priceAdjustment = yield this.priceAdjustment();
88
+ return Math.pow(((yield nftlp.methods.oraclePriceSqrtX96().call()) / Math.pow(2, 96)), 2) * priceAdjustment;
79
89
  });
80
90
  }
81
91
  tickToPrice(tick) {
82
92
  return __awaiter(this, void 0, void 0, function* () {
83
- const decimalA = yield this.getLendingPool().getBorrowableA().getDecimals();
84
- const decimalB = yield this.getLendingPool().getBorrowableB().getDecimals();
85
- const netDecimal = decimalA - decimalB;
86
- return Math.pow(1.0001, tick) * Math.pow(10, netDecimal);
93
+ const priceAdjustment = yield this.priceAdjustment();
94
+ return Math.pow(1.0001, tick) * priceAdjustment;
87
95
  });
88
96
  }
89
97
  priceToTick(price) {
90
98
  return __awaiter(this, void 0, void 0, function* () {
91
- const decimalA = yield this.getLendingPool().getBorrowableA().getDecimals();
92
- const decimalB = yield this.getLendingPool().getBorrowableB().getDecimals();
93
- const netDecimal = decimalA - decimalB;
99
+ const priceAdjustment = yield this.priceAdjustment();
94
100
  // TODO round to tick precision
95
- return Math.log(price / Math.pow(10, netDecimal)) / Math.log(1.0001);
101
+ return Math.log(price / priceAdjustment) / Math.log(1.0001);
96
102
  });
97
103
  }
98
104
  }
@@ -42,7 +42,11 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
42
42
  const priceB = yield this.getNftlp().tickToPrice(tickUpper);
43
43
  const result = yield this._getUpdatePositionActions(-1, yield this.getAccountNftlp().createNewPositionObject(fee, priceA, priceB), depositADelta, depositBDelta, borrowADelta, borrowBDelta);
44
44
  // TODO check fee and ticks encoding
45
- result.actions.unshift(yield actionsGetter.methods.getMintUniV3EmptyAction(fee.toString(), tickLower.toString(), tickUpper.toString()).call());
45
+ /*result.actions.unshift(await actionsGetter.methods.getMintUniV3EmptyAction(
46
+ fee.toString(),
47
+ tickLower.toString(),
48
+ tickUpper.toString(),
49
+ ).call());*/
46
50
  return result;
47
51
  });
48
52
  }
@@ -115,10 +119,7 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
115
119
  }
116
120
  // Mint
117
121
  if (depositADelta > 0 || depositBDelta > 0) {
118
- console.log(depositADelta, depositBDelta);
119
- console.log(yield borrowableA.toBigNumber(depositADelta), yield borrowableB.toBigNumber(depositBDelta), yield borrowableA.toBigNumber(depositADelta / this.getUiMargin()), yield borrowableB.toBigNumber(depositBDelta / this.getUiMargin()));
120
- console.log(yield actionsGetter.methods.getMintUniV3Action(yield borrowableA.toBigNumber(depositADelta), yield borrowableB.toBigNumber(depositBDelta), yield borrowableA.toBigNumber(depositADelta / this.getUiMargin()), yield borrowableB.toBigNumber(depositBDelta / this.getUiMargin())).call());
121
- console.log(actions);
122
+ console.log("depositADelta, depositBDelta", depositADelta, depositBDelta);
122
123
  actions.push(yield actionsGetter.methods.getMintUniV3Action(yield borrowableA.toBigNumber(depositADelta), yield borrowableB.toBigNumber(depositBDelta), yield borrowableA.toBigNumber(depositADelta / this.getUiMargin()), yield borrowableB.toBigNumber(depositBDelta / this.getUiMargin())).call());
123
124
  if (isEthA) {
124
125
  ethValue += depositADelta;
@@ -10,7 +10,6 @@ class UniswapV3Position {
10
10
  this.oraclePrice = _oraclePrice;
11
11
  this.priceA = _priceA;
12
12
  this.priceB = _priceB;
13
- console.log("PRICES", _marketPrice, _oraclePrice, _priceA, _priceB);
14
13
  this.safetyMargin = _safetyMargin;
15
14
  this.liquidationPenalty = _liquidationPenalty;
16
15
  this.lockStateChange = _lockStateChange;
@@ -59,11 +58,9 @@ class UniswapV3Position {
59
58
  // amountX and amountY are expected to have the same sign
60
59
  getOptimalLiquidityAtMarketPrice(amountX, amountY) {
61
60
  let liquidity;
62
- console.log("initial", amountX, amountY);
63
61
  if (amountX != 0 && amountY != 0) {
64
62
  const sampleX = this.getRealX(this.marketPrice);
65
63
  const sampleY = this.getRealY(this.marketPrice);
66
- console.log("sample", sampleX, sampleY);
67
64
  if (sampleX == 0)
68
65
  amountX = 0;
69
66
  else if (sampleX == 0)
@@ -76,7 +73,6 @@ class UniswapV3Position {
76
73
  }
77
74
  }
78
75
  liquidity = this.getLiquidity(this.marketPrice, amountX, amountY);
79
- console.log("final", amountX, amountY, liquidity);
80
76
  return { liquidity, amountX, amountY };
81
77
  }
82
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.85",
3
+ "version": "2.1.88",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",