impermax-sdk 1.1.70 → 1.1.72

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.
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const onchainTypes_1 = require("../../onchainTypes");
16
15
  const types_1 = require("../../../config/types");
17
16
  const onchainAccountPoolToken_1 = __importDefault(require("../onchainAccountPoolToken"));
18
17
  class OnchainAccountBorrowable extends onchainAccountPoolToken_1.default {
@@ -71,19 +70,46 @@ class OnchainAccountBorrowable extends onchainAccountPoolToken_1.default {
71
70
  });
72
71
  }
73
72
  // Max OffchainBorrowable
73
+ /*public async getMaxBorrowable() : Promise<number> {
74
+ const availableCash = await this.poolToken.getTotalBalance();
75
+ const { valueCollateral, valueA, valueB } = await this.lendingPool.getValues(NO_CHANGES);
76
+ const [valueBorrowed, valueOther] = this.getPoolTokenType() == PoolTokenType.BorrowableA ? [valueA, valueB] : [valueB, valueA];
77
+ const safetyMargin = (await this.lendingPool.getSafetyMargin()) * this.getUiMargin();
78
+ const liquidationPenalty = await this.lendingPool.getLiquidationPenalty();
79
+ const actualCollateral = valueCollateral / liquidationPenalty;
80
+ const totalValueBorrowable1 = (actualCollateral * Math.sqrt(safetyMargin) - valueOther) / safetyMargin;
81
+ const totalValueBorrowable2 = (actualCollateral / Math.sqrt(safetyMargin) - valueOther) * safetyMargin;
82
+ const maxValueBorrowable = Math.min(totalValueBorrowable1, totalValueBorrowable2) - valueBorrowed;
83
+ const price = await this.poolToken.getMarketPriceDenomLP();
84
+ return Math.max(0, Math.min(availableCash, maxValueBorrowable / price));
85
+ }*/
86
+ // binary search approach
74
87
  getMaxBorrowable() {
75
88
  return __awaiter(this, void 0, void 0, function* () {
76
89
  const availableCash = yield this.poolToken.getTotalBalance();
77
- const { valueCollateral, valueA, valueB } = yield this.lendingPool.getValues(onchainTypes_1.NO_CHANGES);
78
- const [valueBorrowed, valueOther] = this.getPoolTokenType() == types_1.PoolTokenType.BorrowableA ? [valueA, valueB] : [valueB, valueA];
79
- const safetyMargin = (yield this.lendingPool.getSafetyMargin()) * this.getUiMargin();
80
- const liquidationPenalty = yield this.lendingPool.getLiquidationPenalty();
81
- const actualCollateral = valueCollateral / liquidationPenalty;
82
- const totalValueBorrowable1 = (actualCollateral * Math.sqrt(safetyMargin) - valueOther) / safetyMargin;
83
- const totalValueBorrowable2 = (actualCollateral / Math.sqrt(safetyMargin) - valueOther) * safetyMargin;
84
- const maxValueBorrowable = Math.min(totalValueBorrowable1, totalValueBorrowable2) - valueBorrowed;
85
- const price = yield this.poolToken.getMarketPriceDenomLP();
86
- return Math.max(0, Math.min(availableCash, maxValueBorrowable / price));
90
+ const twapPrice = yield this.lendingPool.getLendingPool().getTWAPPrice();
91
+ // start search
92
+ let borrowAmount = availableCash;
93
+ let borrowAmountPrev = 0;
94
+ let bestAmount = 0;
95
+ for (let i = 0; i < 1000; i++) {
96
+ const jump = Math.abs(borrowAmount - borrowAmountPrev) / 2;
97
+ if (jump / availableCash < 0.001)
98
+ break;
99
+ borrowAmountPrev = borrowAmount;
100
+ const changeCollateral = 0;
101
+ const changeBorrowedA = this.getPoolTokenType() == types_1.PoolTokenType.BorrowableA ? borrowAmount * this.getUiMargin() : 0;
102
+ const changeBorrowedB = this.getPoolTokenType() == types_1.PoolTokenType.BorrowableB ? borrowAmount * this.getUiMargin() : 0;
103
+ const changes = { changeCollateral, changeBorrowedA, changeBorrowedB };
104
+ const [liqPriceA, liqPriceB] = yield this.lendingPool.getLiquidationPrices(changes);
105
+ if (liqPriceA > twapPrice || liqPriceB < twapPrice)
106
+ borrowAmount -= jump;
107
+ else {
108
+ bestAmount = borrowAmount;
109
+ borrowAmount += jump;
110
+ }
111
+ }
112
+ return bestAmount / this.getDust();
87
113
  });
88
114
  }
89
115
  // Farming Shares
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const onchainTypes_1 = require("../../onchainTypes");
16
15
  const onchainAccountPoolToken_1 = __importDefault(require("../onchainAccountPoolToken"));
17
16
  class OnchainAccountCollateral extends onchainAccountPoolToken_1.default {
18
17
  constructor(lendingPool) {
@@ -62,17 +61,44 @@ class OnchainAccountCollateral extends onchainAccountPoolToken_1.default {
62
61
  });
63
62
  }
64
63
  // Max Withdrawable
64
+ /*public async getMaxWithdrawable() : Promise<number> {
65
+ const deposited = await this.getDeposited();
66
+ const availableCash = await this.poolToken.getTotalBalance();
67
+ const { valueCollateral, valueA, valueB } = await this.lendingPool.getValues(NO_CHANGES);
68
+ const safetyMargin = (await this.lendingPool.getSafetyMargin()) * this.getUiMargin();
69
+ const liquidationPenalty = await this.lendingPool.getLiquidationPenalty();
70
+ const actualCollateral = valueCollateral / liquidationPenalty;
71
+ const maxWithdrawable1 = (actualCollateral - (valueA + valueB * safetyMargin) / Math.sqrt(safetyMargin)) * liquidationPenalty / this.getDust();
72
+ const maxWithdrawable2 = (actualCollateral - (valueB + valueA * safetyMargin) / Math.sqrt(safetyMargin)) * liquidationPenalty / this.getDust();
73
+ return Math.max(0, Math.min(deposited, availableCash, maxWithdrawable1, maxWithdrawable2));
74
+ }*/
75
+ // binary search approach
65
76
  getMaxWithdrawable() {
66
77
  return __awaiter(this, void 0, void 0, function* () {
67
- const deposited = yield this.getDeposited();
68
- const availableCash = yield this.poolToken.getTotalBalance();
69
- const { valueCollateral, valueA, valueB } = yield this.lendingPool.getValues(onchainTypes_1.NO_CHANGES);
70
- const safetyMargin = (yield this.lendingPool.getSafetyMargin()) * this.getUiMargin();
71
- const liquidationPenalty = yield this.lendingPool.getLiquidationPenalty();
72
- const actualCollateral = valueCollateral / liquidationPenalty;
73
- const maxWithdrawable1 = (actualCollateral - (valueA + valueB * safetyMargin) / Math.sqrt(safetyMargin)) * liquidationPenalty / this.getDust();
74
- const maxWithdrawable2 = (actualCollateral - (valueB + valueA * safetyMargin) / Math.sqrt(safetyMargin)) * liquidationPenalty / this.getDust();
75
- return Math.max(0, Math.min(deposited, availableCash, maxWithdrawable1, maxWithdrawable2));
78
+ const collateralAmount = yield this.getDeposited();
79
+ const twapPrice = yield this.lendingPool.getLendingPool().getTWAPPrice();
80
+ // start search
81
+ let withdrawAmount = collateralAmount;
82
+ let withdrawAmountPrev = 0;
83
+ let bestAmount = 0;
84
+ for (let i = 0; i < 1000; i++) {
85
+ const jump = Math.abs(withdrawAmount - withdrawAmountPrev) / 2;
86
+ if (jump / collateralAmount < 0.001)
87
+ break;
88
+ withdrawAmountPrev = withdrawAmount;
89
+ const changeCollateral = -1 * withdrawAmount * this.getUiMargin();
90
+ const changeBorrowedA = 0;
91
+ const changeBorrowedB = 0;
92
+ const changes = { changeCollateral, changeBorrowedA, changeBorrowedB };
93
+ const [liqPriceA, liqPriceB] = yield this.lendingPool.getLiquidationPrices(changes);
94
+ if (liqPriceA > twapPrice || liqPriceB < twapPrice)
95
+ withdrawAmount -= jump;
96
+ else {
97
+ bestAmount = withdrawAmount;
98
+ withdrawAmount += jump;
99
+ }
100
+ }
101
+ return bestAmount / this.getDust();
76
102
  });
77
103
  }
78
104
  }
@@ -197,10 +197,10 @@ class OnchainAccountLendingPool {
197
197
  const safetyMargin = yield this.getSafetyMargin();
198
198
  const liquidationPenalty = yield this.getLiquidationPenalty();
199
199
  const actualCollateral = collateralAmount / liquidationPenalty;
200
- const reservesRatio = yield this.lendingPool.getReservesValueRatio();
200
+ const [reservesWeight0, reservesWeight1] = yield this.lendingPool.getTwapReservesWeights();
201
201
  const [priceA, priceB] = yield this.lendingPool.getPriceDenomLP();
202
- const collateralA = actualCollateral * reservesRatio / (1 + reservesRatio) / priceA;
203
- const collateralB = actualCollateral / (1 + reservesRatio) / priceB;
202
+ const collateralA = actualCollateral * reservesWeight0 / priceA;
203
+ const collateralB = actualCollateral * reservesWeight1 / priceB;
204
204
  let priceSwingA, priceSwingB;
205
205
  if (factories_1.STABLE_FACTORIES.includes(this.lendingPool.getImpermaxFactory().getFactory())) {
206
206
  priceSwingA = (0, lliquidity_math_1.solidlyStable_getLiquidatableXPriceDecrease)(collateralA, collateralB, debtA, debtB) * safetyMargin;
@@ -245,14 +245,14 @@ class OnchainAccountLendingPool {
245
245
  const availableCashA = yield this.getBorrowableA().getPoolToken().getTotalBalance();
246
246
  const availableCashB = yield this.getBorrowableB().getPoolToken().getTotalBalance();
247
247
  const collateralAmount = yield this.getCollateral().getDeposited();
248
- const reservesRatio = yield this.lendingPool.getReservesValueRatio();
248
+ const [reservesWeight0, reservesWeight1] = yield this.lendingPool.getMarketReservesWeights();
249
249
  //const [priceA, priceB] = await this.lendingPool.getPriceDenomLP();
250
- // come posso adattare l'aggiustamento alle stable pairs?
250
+ //TODO come posso adattare l'aggiustamento alle stable pairs?
251
251
  const [priceA, priceB] = yield this.lendingPool.getMarketPriceDenomLP();
252
252
  const [priceATWAP,] = yield this.lendingPool.getPriceDenomLP();
253
253
  const diff = priceA > priceATWAP ? priceA / priceATWAP : priceATWAP / priceA;
254
- const collateralA = collateralAmount * reservesRatio / (1 + reservesRatio) / priceA;
255
- const collateralB = collateralAmount / (1 + reservesRatio) / priceB;
254
+ const collateralA = collateralAmount * reservesWeight0 / priceA;
255
+ const collateralB = collateralAmount * reservesWeight1 / priceB;
256
256
  const twapPrice = yield this.lendingPool.getTWAPPrice();
257
257
  // start search
258
258
  let addLev = 100;
@@ -260,7 +260,7 @@ class OnchainAccountLendingPool {
260
260
  let bestChanges = onchainTypes_1.NO_CHANGES;
261
261
  for (let i = 0; i < 1000; i++) {
262
262
  const jump = Math.abs(addLev - addLevPrev) / 2;
263
- if (jump < 0.001)
263
+ if (jump < 0.01)
264
264
  break;
265
265
  addLevPrev = addLev;
266
266
  const adjustFactor = Math.pow((0, utils_1.impermanentLoss)(Math.pow(diff, 2)), addLev);
@@ -281,21 +281,30 @@ class OnchainAccountLendingPool {
281
281
  addLev += jump;
282
282
  }
283
283
  }
284
- return yield this.getLeverage(bestChanges);
284
+ const maxLeverage = yield this.getLeverage(bestChanges);
285
+ return Math.floor(maxLeverage * 99) / 100;
285
286
  });
286
287
  }
287
288
  // Max Deleverage
288
289
  getMaxDeleverage(slippage) {
289
290
  return __awaiter(this, void 0, void 0, function* () {
290
291
  const { valueCollateral, valueA, valueB } = yield this.getMarketValues(onchainTypes_1.NO_CHANGES);
291
- const minRepayPerSide = valueCollateral / 2 / Math.sqrt(slippage);
292
- if (minRepayPerSide >= valueA && minRepayPerSide >= valueB) {
292
+ const [reservesWeight0, reservesWeight1] = yield this.lendingPool.getMarketReservesWeights();
293
+ const adjCollateralValue = valueCollateral / Math.sqrt(slippage);
294
+ const collateralValueA = valueCollateral * reservesWeight0;
295
+ const collateralValueB = valueCollateral * reservesWeight1;
296
+ if (collateralValueA >= valueA && collateralValueB >= valueB) {
293
297
  return this.getCollateral().getDeposited();
294
298
  }
295
- if (minRepayPerSide * 2 < valueA + valueB) {
299
+ if (adjCollateralValue < valueA + valueB) {
296
300
  return 0;
297
301
  }
298
- return Math.min(valueA, valueB) * 2 * Math.sqrt(slippage);
302
+ if (valueA / collateralValueA < valueB / collateralValueB) {
303
+ return (valueA + valueA / collateralValueA * collateralValueB) * Math.sqrt(slippage);
304
+ }
305
+ else {
306
+ return (valueB + valueB / collateralValueB * collateralValueA) * Math.sqrt(slippage);
307
+ }
299
308
  });
300
309
  }
301
310
  // Available Reward
@@ -39,8 +39,12 @@ export default class OnchainLendingPool {
39
39
  getPriceDenomLP(): Promise<[number, number]>;
40
40
  getMarketPriceDenomLP(): Promise<[number, number]>;
41
41
  getMarketPrice(): Promise<number>;
42
- private initializeReservesValueRatio;
43
- getReservesValueRatio(): Promise<number>;
42
+ private initializeTwapReservesValueRatio;
43
+ getTwapReservesValueRatio(): Promise<number>;
44
+ getTwapReservesWeights(): Promise<[number, number]>;
45
+ private initializeMarketReservesValueRatio;
46
+ getMarketReservesValueRatio(): Promise<number>;
47
+ getMarketReservesWeights(): Promise<[number, number]>;
44
48
  private initializeTWAPPrice;
45
49
  getTWAPPrice(): Promise<number>;
46
50
  private initializeStakedLPExchangeRate;
@@ -170,9 +170,10 @@ class OnchainLendingPool {
170
170
  return __awaiter(this, void 0, void 0, function* () {
171
171
  const [reserve0, reserve1] = yield this.getReserves();
172
172
  const totalSupply = yield this.getLPTotalSupply();
173
+ const [reservesWeight0, reservesWeight1] = yield this.getMarketReservesWeights();
173
174
  return [
174
- totalSupply / reserve0 / 2,
175
- totalSupply / reserve1 / 2,
175
+ totalSupply / reserve0 * reservesWeight0,
176
+ totalSupply / reserve1 * reservesWeight1,
176
177
  ];
177
178
  });
178
179
  }
@@ -187,64 +188,8 @@ class OnchainLendingPool {
187
188
  return (0, lliquidity_math_1.uniswapV2_getPriceFromReserves)(reserve0, reserve1, priceInverted);
188
189
  });
189
190
  }
190
- /*
191
- // TWAP Reserves
192
- // NON VA BENE, voglio tornare le riserve dello stakedLPToken o di tutto? DIPORCO
193
- private async initializeTWAPReserves() : Promise<[number, number] | null> {
194
- try {
195
- const collateral = await this.getCollateral().getPoolToken();
196
- const decimalsA = await this.getBorrowableA().getDecimals();
197
- const decimalsB = await this.getBorrowableB().getDecimals();
198
-
199
- if (STABLE_FACTORIES.includes(this.impermaxFactory.getFactory())) {
200
- const { reserve0, reserve1 } = await collateral.methods.getReserves().call();
201
- return [
202
- reserve0 / Math.pow(10, decimalsA),
203
- reserve1 / Math.pow(10, decimalsB)
204
- ];
205
- }
206
-
207
- const [reserve0, reserve1] = await this.getReserves();
208
- const currentPrice = uniswapV2_getPriceFromReserves(reserve0, reserve1);
209
- let TWAPprice;
210
- if (SOLIDEX_FACTORIES.includes(this.impermaxFactory.getFactory())) {
211
- TWAPprice = await collateral.methods.getTwapPrice112x112().call();
212
- } else {
213
- TWAPprice = (await this.impermaxFactory.getSimpleUniswapOracle().methods.getResult(this.pairAddress).call()).price;
214
- }
215
- TWAPprice = TWAPprice / 2**112 * Math.pow(10, decimalsA) / Math.pow(10, decimalsB);
216
-
217
- const adj = Math.sqrt(currentPrice / TWAPprice);
218
- return [
219
- reserve0 * adj,
220
- reserve1 / adj,
221
- ]
222
- }
223
- catch (e) {
224
- // Oracle is not initialized yet
225
- return null;
226
- }
227
- }
228
- public async getTWAPReserves() : Promise<[number, number] | null> {
229
- if (!this.cache.TWAPReserves) this.cache.TWAPReserves = this.initializeTWAPReserves();
230
- return this.cache.TWAPReserves;
231
- }
232
-
233
- // TWAP Price
234
- private async initializeTWAPPrice() : Promise<number> {
235
- const TWAPReserves = await this.getTWAPReserves();
236
- if (!TWAPReserves) return 0;
237
- const reserve0 = TWAPReserves[0];
238
- const reserve1 = TWAPReserves[1];
239
-
240
- if (STABLE_FACTORIES.includes(this.impermaxFactory.getFactory())) {
241
- return solidlyStable_getPriceFromReserves(reserve0, reserve1);
242
- } else {
243
- return uniswapV2_getPriceFromReserves(reserve0, reserve1);
244
- }
245
- }*/
246
191
  // Value of reserveA / reserveB
247
- initializeReservesValueRatio() {
192
+ initializeTwapReservesValueRatio() {
248
193
  return __awaiter(this, void 0, void 0, function* () {
249
194
  if (factories_1.STABLE_FACTORIES.includes(this.impermaxFactory.getFactory())) {
250
195
  const collateral = yield this.getCollateral().getPoolToken();
@@ -259,13 +204,49 @@ class OnchainLendingPool {
259
204
  }
260
205
  });
261
206
  }
262
- getReservesValueRatio() {
207
+ getTwapReservesValueRatio() {
208
+ return __awaiter(this, void 0, void 0, function* () {
209
+ if (!this.cache.twapReservesValueRatio)
210
+ this.cache.twapReservesValueRatio = this.initializeTwapReservesValueRatio();
211
+ return this.cache.twapReservesValueRatio;
212
+ });
213
+ }
214
+ getTwapReservesWeights() {
215
+ return __awaiter(this, void 0, void 0, function* () {
216
+ const reservesRatio = yield this.getTwapReservesValueRatio();
217
+ const reservesWeight0 = reservesRatio / (1 + reservesRatio);
218
+ const reservesWeight1 = 1 / (1 + reservesRatio);
219
+ return [reservesWeight0, reservesWeight1];
220
+ });
221
+ }
222
+ initializeMarketReservesValueRatio() {
223
+ return __awaiter(this, void 0, void 0, function* () {
224
+ if (factories_1.STABLE_FACTORIES.includes(this.impermaxFactory.getFactory())) {
225
+ const [reserve0, reserve1] = yield this.getReserves();
226
+ const price = (0, lliquidity_math_1.solidlyStable_getPriceFromReserves)(reserve0, reserve1);
227
+ return reserve0 * price / reserve1;
228
+ }
229
+ else {
230
+ return 1;
231
+ }
232
+ });
233
+ }
234
+ getMarketReservesValueRatio() {
235
+ return __awaiter(this, void 0, void 0, function* () {
236
+ if (!this.cache.marketReservesValueRatio)
237
+ this.cache.marketReservesValueRatio = this.initializeMarketReservesValueRatio();
238
+ return this.cache.marketReservesValueRatio;
239
+ });
240
+ }
241
+ getMarketReservesWeights() {
263
242
  return __awaiter(this, void 0, void 0, function* () {
264
- if (!this.cache.reservesValueRatio)
265
- this.cache.reservesValueRatio = this.initializeReservesValueRatio();
266
- return this.cache.reservesValueRatio;
243
+ const reservesRatio = yield this.getMarketReservesValueRatio();
244
+ const reservesWeight0 = reservesRatio / (1 + reservesRatio);
245
+ const reservesWeight1 = 1 / (1 + reservesRatio);
246
+ return [reservesWeight0, reservesWeight1];
267
247
  });
268
248
  }
249
+ // TWAP Price
269
250
  initializeTWAPPrice() {
270
251
  return __awaiter(this, void 0, void 0, function* () {
271
252
  try {
@@ -33,7 +33,7 @@ export default class OnchainInteractionsLendingPool {
33
33
  cAmountMin: number;
34
34
  }>;
35
35
  leverage(amountA: BigNumber, amountB: BigNumber, amountAMin: BigNumber, amountBMin: BigNumber, permitDataA: PermitData, permitDataB: PermitData, onTransactionHash: Function): Promise<any>;
36
- getDeleverageAmounts(changeCollateralAmount: number, slippage: number): Promise<{
36
+ getDeleverageAmounts(changeCollateralValue: number, slippage: number): Promise<{
37
37
  bAmountA: number;
38
38
  bAmountB: number;
39
39
  cAmount: number;
@@ -55,10 +55,11 @@ class OnchainInteractionsLendingPool {
55
55
  const currentLeverage = yield accountLendingPool.getLeverage();
56
56
  const collateralValue = yield accountLendingPool.getCollateral().getDeposited();
57
57
  const changeCollateralValue = (collateralValue * leverage / currentLeverage - collateralValue) * adjustFactor;
58
- // TODO wrong methodology, it's better to use the reserve ratio
59
- const valueForEach = changeCollateralValue / 2;
60
- const bAmountA = priceA > 0 ? valueForEach / priceA : 0;
61
- const bAmountB = priceB > 0 ? valueForEach / priceB : 0;
58
+ const [reservesWeightA, reservesWeightB] = yield this.lendingPool.getMarketReservesWeights();
59
+ const changeValueA = changeCollateralValue * reservesWeightA;
60
+ const changeValueB = changeCollateralValue * reservesWeightB;
61
+ const bAmountA = priceA > 0 ? changeValueA / priceA : 0;
62
+ const bAmountB = priceB > 0 ? changeValueB / priceB : 0;
62
63
  const cAmount = changeCollateralValue ? changeCollateralValue : 0;
63
64
  return {
64
65
  bAmountA: bAmountA,
@@ -83,17 +84,19 @@ class OnchainInteractionsLendingPool {
83
84
  return this.send(router.methods.leverage(pairAddress, amountA, amountB, amountAMin, amountBMin, account, deadline, dataA, dataB), onTransactionHash);
84
85
  });
85
86
  }
86
- getDeleverageAmounts(changeCollateralAmount, slippage) {
87
+ getDeleverageAmounts(changeCollateralValue, slippage) {
87
88
  return __awaiter(this, void 0, void 0, function* () {
88
- changeCollateralAmount = changeCollateralAmount !== null && changeCollateralAmount !== void 0 ? changeCollateralAmount : 0;
89
+ changeCollateralValue = changeCollateralValue !== null && changeCollateralValue !== void 0 ? changeCollateralValue : 0;
89
90
  const [priceA, priceB] = yield this.lendingPool.getMarketPriceDenomLP();
90
- const valueForEach = changeCollateralAmount / 2;
91
- const bAmountA = priceA > 0 ? valueForEach / priceA : 0;
92
- const bAmountB = priceB > 0 ? valueForEach / priceB : 0;
91
+ const [reservesWeightA, reservesWeightB] = yield this.lendingPool.getMarketReservesWeights();
92
+ const changeValueA = changeCollateralValue * reservesWeightA;
93
+ const changeValueB = changeCollateralValue * reservesWeightB;
94
+ const bAmountA = priceA > 0 ? changeValueA / priceA : 0;
95
+ const bAmountB = priceB > 0 ? changeValueB / priceB : 0;
93
96
  return {
94
97
  bAmountA: bAmountA,
95
98
  bAmountB: bAmountB,
96
- cAmount: changeCollateralAmount,
99
+ cAmount: changeCollateralValue,
97
100
  bAmountAMin: bAmountA / Math.sqrt(slippage),
98
101
  bAmountBMin: bAmountB / Math.sqrt(slippage),
99
102
  };
@@ -1,3 +1,6 @@
1
+ /**
2
+ * Calculate X/Y price
3
+ */
1
4
  export declare function uniswapV2_getPriceFromReserves(x: number, y: number, priceInverted?: boolean): number;
2
5
  /**
3
6
  * Find liquidation threshold given X/Y price decrease
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.solidlyStable_getLiquidatableXPriceDecrease = exports.solidlyStable_getXInMargin = exports.solidlyStable_getEquityValue = exports.solidlyStable_yOut = exports.solidlyStable_k = exports.solidlyStable_getPriceFromReserves = exports.uniswapV2_getLiquidatableXPriceDecrease = exports.uniswapV2_getPriceFromReserves = void 0;
4
+ /**
5
+ * Calculate X/Y price
6
+ */
4
7
  function uniswapV2_getPriceFromReserves(x, y, priceInverted = false) {
5
8
  const price = y / x;
6
9
  return !priceInverted ? price : 1 / price;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "1.1.70",
3
+ "version": "1.1.72",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",