impermax-sdk 1.1.57 → 1.1.59

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.
@@ -16,6 +16,7 @@ const types_1 = require("../../../config/types");
16
16
  const onchainCollateral_1 = __importDefault(require("./onchainCollateral"));
17
17
  const onchainBorrowable_1 = __importDefault(require("./onchainBorrowable"));
18
18
  const factories_1 = require("../../../config/factories");
19
+ const price_from_reserves_1 = require("../../../utils/price-from-reserves");
19
20
  class OnchainLendingPool {
20
21
  constructor(impermaxFactory, pairAddress) {
21
22
  this.cache = {};
@@ -181,9 +182,9 @@ class OnchainLendingPool {
181
182
  const [reserve0, reserve1] = yield this.getReserves();
182
183
  const priceInverted = this.impermaxFactory.getOnchain().priceInverted;
183
184
  if (factories_1.STABLE_FACTORIES.includes(this.impermaxFactory.getFactory()))
184
- return getPriceFromReservesSolidlyStable(reserve0, reserve1, priceInverted);
185
+ return (0, price_from_reserves_1.getPriceFromReservesSolidlyStable)(reserve0, reserve1, priceInverted);
185
186
  else
186
- return getPriceFromReservesUniswapV2(reserve0, reserve1, priceInverted);
187
+ return (0, price_from_reserves_1.getPriceFromReservesUniswapV2)(reserve0, reserve1, priceInverted);
187
188
  });
188
189
  }
189
190
  // TWAP Price
@@ -191,9 +192,11 @@ class OnchainLendingPool {
191
192
  return __awaiter(this, void 0, void 0, function* () {
192
193
  try {
193
194
  const collateral = yield this.getCollateral().getPoolToken();
195
+ const decimalsA = yield this.getBorrowableA().getDecimals();
196
+ const decimalsB = yield this.getBorrowableB().getDecimals();
194
197
  if (factories_1.STABLE_FACTORIES.includes(this.impermaxFactory.getFactory())) {
195
198
  const { twapReserve0, twapReserve1 } = yield collateral.methods.getTwapReserves().call();
196
- return getPriceFromReservesSolidlyStable(twapReserve0, twapReserve1);
199
+ return (0, price_from_reserves_1.getPriceFromReservesSolidlyStable)(twapReserve0 / Math.pow(10, decimalsA), twapReserve1 / Math.pow(10, decimalsB));
197
200
  }
198
201
  let price;
199
202
  if (factories_1.SOLIDEX_FACTORIES.includes(this.impermaxFactory.getFactory())) {
@@ -202,8 +205,6 @@ class OnchainLendingPool {
202
205
  else {
203
206
  price = (yield this.impermaxFactory.getSimpleUniswapOracle().methods.getResult(this.pairAddress).call()).price;
204
207
  }
205
- const decimalsA = yield this.getBorrowableA().getDecimals();
206
- const decimalsB = yield this.getBorrowableB().getDecimals();
207
208
  return price / Math.pow(2, 112) * Math.pow(10, decimalsA) / Math.pow(10, decimalsB);
208
209
  }
209
210
  catch (e) {
@@ -1,2 +1,2 @@
1
- declare function getPriceFromReservesUniswapV2(x: number, y: number, priceInverted?: boolean): number;
2
- declare function getPriceFromReservesSolidlyStable(x: number, y: number, priceInverted?: boolean): number;
1
+ export declare function getPriceFromReservesUniswapV2(x: number, y: number, priceInverted?: boolean): number;
2
+ export declare function getPriceFromReservesSolidlyStable(x: number, y: number, priceInverted?: boolean): number;
@@ -1,4 +1,7 @@
1
+ "use strict";
1
2
  // return X/Y price
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getPriceFromReservesSolidlyStable = exports.getPriceFromReservesUniswapV2 = void 0;
2
5
  /*
3
6
  * X/Y price is given by dividing Y reserves by X reserves
4
7
  */
@@ -6,9 +9,12 @@ function getPriceFromReservesUniswapV2(x, y, priceInverted = true) {
6
9
  const price = y / x;
7
10
  return !priceInverted ? price : 1 / price;
8
11
  }
12
+ exports.getPriceFromReservesUniswapV2 = getPriceFromReservesUniswapV2;
9
13
  function getPriceFromReservesSolidlyStable(x, y, priceInverted = false) {
10
14
  const N = 3 * x ^ 2 * y + y ^ 3;
11
15
  const D = 3 * y ^ 2 * x + x ^ 3;
12
16
  const price = N / D;
17
+ console.log(x, y, price);
13
18
  return !priceInverted ? price : 1 / price;
14
19
  }
20
+ exports.getPriceFromReservesSolidlyStable = getPriceFromReservesSolidlyStable;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "1.1.57",
3
+ "version": "1.1.59",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",