impermax-sdk 1.1.65 → 1.1.67
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.
|
@@ -202,14 +202,13 @@ class OnchainAccountLendingPool {
|
|
|
202
202
|
const collateralB = actualCollateral / (1 + reservesRatio) / priceB;
|
|
203
203
|
let priceSwingA, priceSwingB;
|
|
204
204
|
if (factories_1.STABLE_FACTORIES.includes(this.lendingPool.getImpermaxFactory().getFactory())) {
|
|
205
|
-
console.log(collateralA, collateralB, debtA, debtB, safetyMargin);
|
|
206
205
|
priceSwingA = (0, lliquidity_math_1.solidlyStable_getLiquidatableXPriceDecrease)(collateralA, collateralB, debtA, debtB) * safetyMargin;
|
|
207
206
|
priceSwingB = (0, lliquidity_math_1.solidlyStable_getLiquidatableXPriceDecrease)(collateralB, collateralA, debtB, debtA) * safetyMargin;
|
|
208
|
-
console.log(priceSwingA, priceSwingB);
|
|
209
207
|
}
|
|
210
208
|
else {
|
|
211
209
|
priceSwingA = (0, lliquidity_math_1.uniswapV2_getLiquidatableXPriceDecrease)(collateralA, collateralB, debtA, debtB) * safetyMargin;
|
|
212
210
|
priceSwingB = (0, lliquidity_math_1.uniswapV2_getLiquidatableXPriceDecrease)(collateralB, collateralA, debtB, debtA) * safetyMargin;
|
|
211
|
+
console.log(priceSwingA, priceSwingB);
|
|
213
212
|
}
|
|
214
213
|
const twapPrice = yield this.lendingPool.getTWAPPrice();
|
|
215
214
|
return !this.account.getOnchain().priceInverted
|
|
@@ -270,7 +269,7 @@ class OnchainAccountLendingPool {
|
|
|
270
269
|
changeBorrowedA: changeBorrowedA,
|
|
271
270
|
changeBorrowedB: changeBorrowedB,
|
|
272
271
|
});
|
|
273
|
-
if (liqPriceA > twapPrice || liqPriceB < twapPrice)
|
|
272
|
+
if (liqPriceA > twapPrice || liqPriceB < twapPrice || !liqPriceA || !liqPriceB)
|
|
274
273
|
addLev -= jump;
|
|
275
274
|
else
|
|
276
275
|
addLev += jump;
|
|
@@ -2,6 +2,8 @@ export declare function uniswapV2_getPriceFromReserves(x: number, y: number, pri
|
|
|
2
2
|
/**
|
|
3
3
|
* Find liquidation threshold given X/Y price decrease
|
|
4
4
|
* Returns a price ratio in the [0,1] range
|
|
5
|
+
* - 0 meaning it will never get liquidated
|
|
6
|
+
* - 1 meaning it is liquidatable
|
|
5
7
|
*/
|
|
6
8
|
export declare function uniswapV2_getLiquidatableXPriceDecrease(x0: number, y0: number, debtX: number, debtY: number): number;
|
|
7
9
|
/**
|
|
@@ -1,10 +1,6 @@
|
|
|
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
|
-
*/
|
|
7
|
-
const assert = require("assert");
|
|
8
4
|
function uniswapV2_getPriceFromReserves(x, y, priceInverted = false) {
|
|
9
5
|
const price = y / x;
|
|
10
6
|
return !priceInverted ? price : 1 / price;
|
|
@@ -13,6 +9,8 @@ exports.uniswapV2_getPriceFromReserves = uniswapV2_getPriceFromReserves;
|
|
|
13
9
|
/**
|
|
14
10
|
* Find liquidation threshold given X/Y price decrease
|
|
15
11
|
* Returns a price ratio in the [0,1] range
|
|
12
|
+
* - 0 meaning it will never get liquidated
|
|
13
|
+
* - 1 meaning it is liquidatable
|
|
16
14
|
*/
|
|
17
15
|
function uniswapV2_getLiquidatableXPriceDecrease(x0, y0, debtX, debtY) {
|
|
18
16
|
const k = x0 * y0;
|
|
@@ -22,9 +20,11 @@ function uniswapV2_getLiquidatableXPriceDecrease(x0, y0, debtX, debtY) {
|
|
|
22
20
|
if (x == Infinity)
|
|
23
21
|
return 0;
|
|
24
22
|
const y = k / x;
|
|
23
|
+
console.log(x0, y0, debtX, debtY, x, y);
|
|
25
24
|
const price0 = uniswapV2_getPriceFromReserves(x0, y0);
|
|
26
25
|
const price = uniswapV2_getPriceFromReserves(x, y);
|
|
27
|
-
|
|
26
|
+
if (price >= price0)
|
|
27
|
+
return 1;
|
|
28
28
|
return price / price0;
|
|
29
29
|
}
|
|
30
30
|
exports.uniswapV2_getLiquidatableXPriceDecrease = uniswapV2_getLiquidatableXPriceDecrease;
|
|
@@ -118,7 +118,8 @@ function solidlyStable_getLiquidatableXPriceDecrease(x0, y0, debtX, debtY) {
|
|
|
118
118
|
const y = y0 - solidlyStable_yOut(xIn, x0, y0);
|
|
119
119
|
const price0 = solidlyStable_getPriceFromReserves(x0, y0);
|
|
120
120
|
const price = solidlyStable_getPriceFromReserves(x, y);
|
|
121
|
-
|
|
121
|
+
if (price >= price0)
|
|
122
|
+
return 1;
|
|
122
123
|
return price / price0;
|
|
123
124
|
}
|
|
124
125
|
exports.solidlyStable_getLiquidatableXPriceDecrease = solidlyStable_getLiquidatableXPriceDecrease;
|