impermax-sdk 2.1.262 → 2.1.264
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.
|
@@ -65,13 +65,16 @@ export declare abstract class GenericPosition implements Position {
|
|
|
65
65
|
protected getInitialCollateralValue(): number;
|
|
66
66
|
protected getCollateralValueGivenPrice(price: number): number;
|
|
67
67
|
protected getCollateralValueGivenPriceAndDeltaLeverage(price: number, deltaX: number, deltaY: number): number;
|
|
68
|
+
protected getUsableCollateralValueGivenPrice(price: number): number;
|
|
69
|
+
protected getUsableCollateralValueGivenPriceAndDeltaLeverage(price: number, deltaX: number, deltaY: number): number;
|
|
68
70
|
protected getInitialEquityValue(): number;
|
|
69
71
|
protected getEquityValueGivenPrice(price: number): number;
|
|
70
72
|
protected getDebtValue(): number;
|
|
71
73
|
protected getCollateralValue(): number;
|
|
72
74
|
protected getEquityValue(): number;
|
|
73
|
-
protected
|
|
74
|
-
protected
|
|
75
|
+
protected hasEnoughLiquidityGivenPriceAndDebt(price: number, debtX: number, debtY: number): boolean;
|
|
76
|
+
protected hasEnoughUsableLiquidityGivenPriceAndDebt(price: number, debtX: number, debtY: number): boolean;
|
|
77
|
+
protected hasEnoughUsableLiquidityGivenPriceAndDeltaLeverage(price: number, deltaX: number, deltaY: number): boolean;
|
|
75
78
|
protected isLiquidatableGivenPriceAndDebt(price: number, debtX: number, debtY: number): boolean;
|
|
76
79
|
protected isLiquidatableGivenPriceAndDeltaLeverage(price: number, deltaX: number, deltaY: number): boolean;
|
|
77
80
|
protected isLiquidatableGivenDebt(debtX: number, debtY: number): boolean;
|
|
@@ -113,6 +113,12 @@ class GenericPosition {
|
|
|
113
113
|
const { liquidity } = this.getOptimalLiquidity(deltaX, deltaY);
|
|
114
114
|
return this.getValueGivenPriceAndAmounts(price, this.getRealXGivenLiquidityAndPrice(this.liquidity + liquidity, price), this.getRealYGivenLiquidityAndPrice(this.liquidity + liquidity, price));
|
|
115
115
|
}
|
|
116
|
+
getUsableCollateralValueGivenPrice(price) {
|
|
117
|
+
return this.getCollateralValueGivenPrice(price);
|
|
118
|
+
}
|
|
119
|
+
getUsableCollateralValueGivenPriceAndDeltaLeverage(price, deltaX, deltaY) {
|
|
120
|
+
return this.getCollateralValueGivenPriceAndDeltaLeverage(price, deltaX, deltaY);
|
|
121
|
+
}
|
|
116
122
|
getInitialEquityValue() {
|
|
117
123
|
return this.getInitialCollateralValue() - this.getInitialDebtValue();
|
|
118
124
|
}
|
|
@@ -128,25 +134,31 @@ class GenericPosition {
|
|
|
128
134
|
getEquityValue() {
|
|
129
135
|
return this.getEquityValueGivenPrice(this.marketPrice);
|
|
130
136
|
}
|
|
131
|
-
|
|
137
|
+
hasEnoughLiquidityGivenPriceAndDebt(price, debtX, debtY) {
|
|
132
138
|
const debtValue = this.getValueGivenPriceAndAmounts(price, debtX, debtY);
|
|
133
139
|
const collateralValue = this.getCollateralValueGivenPrice(price);
|
|
134
140
|
const collateralNeeded = debtValue * this.liquidationPenalty;
|
|
135
|
-
return collateralValue
|
|
141
|
+
return collateralValue >= collateralNeeded;
|
|
142
|
+
}
|
|
143
|
+
hasEnoughUsableLiquidityGivenPriceAndDebt(price, debtX, debtY) {
|
|
144
|
+
const debtValue = this.getValueGivenPriceAndAmounts(price, debtX, debtY);
|
|
145
|
+
const collateralValue = this.getUsableCollateralValueGivenPrice(price);
|
|
146
|
+
const collateralNeeded = debtValue * this.liquidationPenalty;
|
|
147
|
+
return collateralValue >= collateralNeeded;
|
|
136
148
|
}
|
|
137
|
-
|
|
149
|
+
hasEnoughUsableLiquidityGivenPriceAndDeltaLeverage(price, deltaX, deltaY) {
|
|
138
150
|
const debtValue = this.getDebtValueGivenPrice(price) + this.getValueGivenPriceAndAmounts(price, deltaX, deltaY);
|
|
139
|
-
const collateralValue = this.
|
|
151
|
+
const collateralValue = this.getUsableCollateralValueGivenPriceAndDeltaLeverage(price, deltaX, deltaY);
|
|
140
152
|
const collateralNeeded = debtValue * this.liquidationPenalty;
|
|
141
|
-
return collateralValue
|
|
153
|
+
return collateralValue >= collateralNeeded;
|
|
142
154
|
}
|
|
143
155
|
isLiquidatableGivenPriceAndDebt(price, debtX, debtY) {
|
|
144
|
-
return this.
|
|
145
|
-
|| this.
|
|
156
|
+
return !this.hasEnoughUsableLiquidityGivenPriceAndDebt(price / this.safetyMargin, debtX, debtY)
|
|
157
|
+
|| !this.hasEnoughUsableLiquidityGivenPriceAndDebt(price * this.safetyMargin, debtX, debtY);
|
|
146
158
|
}
|
|
147
159
|
isLiquidatableGivenPriceAndDeltaLeverage(price, deltaX, deltaY) {
|
|
148
|
-
return this.
|
|
149
|
-
|| this.
|
|
160
|
+
return !this.hasEnoughUsableLiquidityGivenPriceAndDeltaLeverage(price / this.safetyMargin, deltaX, deltaY)
|
|
161
|
+
|| !this.hasEnoughUsableLiquidityGivenPriceAndDeltaLeverage(price * this.safetyMargin, deltaX, deltaY);
|
|
150
162
|
}
|
|
151
163
|
isLiquidatableGivenDebt(debtX, debtY) {
|
|
152
164
|
return this.isLiquidatableGivenPriceAndDebt(this.marketPrice, debtX, debtY);
|
|
@@ -158,7 +170,7 @@ class GenericPosition {
|
|
|
158
170
|
return this.isLiquidatableGivenPriceAndDebt(price, this.debtX, this.debtY);
|
|
159
171
|
}
|
|
160
172
|
isUnderwaterGivenPrice(price) {
|
|
161
|
-
return this.
|
|
173
|
+
return !this.hasEnoughLiquidityGivenPriceAndDebt(price, this.debtX, this.debtY);
|
|
162
174
|
}
|
|
163
175
|
getLiquidationPriceInRange(lowPrice, highPrice, lowIsLiquidatable, highIsLiquidatable) {
|
|
164
176
|
if (lowIsLiquidatable == highIsLiquidatable)
|
|
@@ -23,7 +23,6 @@ export declare class UniswapV3Position extends GenericPosition {
|
|
|
23
23
|
priceA: number;
|
|
24
24
|
priceB: number;
|
|
25
25
|
constructor(params: UniswapV3PositionParams);
|
|
26
|
-
protected checkLock(): void;
|
|
27
26
|
/**
|
|
28
27
|
* protected SETTERS
|
|
29
28
|
*/
|
|
@@ -37,12 +36,8 @@ export declare class UniswapV3Position extends GenericPosition {
|
|
|
37
36
|
protected getRealYGivenLiquidityAndPrice(liquidity: number, price: number): number;
|
|
38
37
|
protected getInitialCollateralValue(): number;
|
|
39
38
|
protected getCollateralValueGivenPrice(price: number): number;
|
|
40
|
-
protected
|
|
41
|
-
protected
|
|
42
|
-
protected getWeightedLiquidityPostLiquidationValueGivenPriceAndDebt(price: number, debtX: number, debtY: number): number;
|
|
43
|
-
protected getWeightedLiquidityPostLiquidationValueGivenPriceAndDeltaLeverage(price: number, deltaX: number, deltaY: number): number;
|
|
44
|
-
protected isLiquidatableGivenPriceAndDebt(price: number, debtX: number, debtY: number): boolean;
|
|
45
|
-
protected isLiquidatableGivenPriceAndDeltaLeverage(price: number, deltaX: number, deltaY: number): boolean;
|
|
39
|
+
protected getUsableCollateralValueGivenPrice(price: number): number;
|
|
40
|
+
protected getUsableCollateralValueGivenPriceAndDeltaLeverage(price: number, deltaX: number, deltaY: number): number;
|
|
46
41
|
protected getLiquidityGivenAmounts(amountX: number, amountY: number): number;
|
|
47
42
|
/**
|
|
48
43
|
* PUBLIC GETTERS
|
|
@@ -16,12 +16,6 @@ class UniswapV3Position extends genericPosition_1.default {
|
|
|
16
16
|
this.priceA = params.priceA;
|
|
17
17
|
this.priceB = params.priceB;
|
|
18
18
|
}
|
|
19
|
-
checkLock() {
|
|
20
|
-
if (this.lockStateChange)
|
|
21
|
-
throw Error("Can't change state of original position object");
|
|
22
|
-
else
|
|
23
|
-
this.state++;
|
|
24
|
-
}
|
|
25
19
|
/**
|
|
26
20
|
* protected SETTERS
|
|
27
21
|
*/
|
|
@@ -43,13 +37,13 @@ class UniswapV3Position extends genericPosition_1.default {
|
|
|
43
37
|
return liquidity * Math.sqrt(price);
|
|
44
38
|
}
|
|
45
39
|
getRealXGivenLiquidityAndPrice(liquidity, price) {
|
|
46
|
-
const surplusX = this.getVirtualX(liquidity, this.
|
|
47
|
-
const virtualX = this.getVirtualX(liquidity, Math.max(price, this.
|
|
40
|
+
const surplusX = this.getVirtualX(liquidity, this.priceB);
|
|
41
|
+
const virtualX = this.getVirtualX(liquidity, Math.max(price, this.priceA));
|
|
48
42
|
return Math.max(virtualX - surplusX, 0);
|
|
49
43
|
}
|
|
50
44
|
getRealYGivenLiquidityAndPrice(liquidity, price) {
|
|
51
45
|
const surplusY = this.getVirtualY(liquidity, this.priceA);
|
|
52
|
-
const virtualY = this.getVirtualY(liquidity, Math.min(price, this.
|
|
46
|
+
const virtualY = this.getVirtualY(liquidity, Math.min(price, this.priceB));
|
|
53
47
|
return Math.max(virtualY - surplusY, 0);
|
|
54
48
|
}
|
|
55
49
|
getInitialCollateralValue() {
|
|
@@ -58,34 +52,13 @@ class UniswapV3Position extends genericPosition_1.default {
|
|
|
58
52
|
getCollateralValueGivenPrice(price) {
|
|
59
53
|
return this.getValueGivenPriceAndAmounts(price, this.getRealXGivenPrice(price) + this.unclaimedFeesX, this.getRealYGivenPrice(price) + this.unclaimedFeesY);
|
|
60
54
|
}
|
|
61
|
-
|
|
62
|
-
getWeightedCollateralValueGivenPrice(price) {
|
|
55
|
+
getUsableCollateralValueGivenPrice(price) {
|
|
63
56
|
return this.getValueGivenPriceAndAmounts(price, this.getRealXGivenPrice(price) + this.unclaimedFeesX * FEE_COLLECTED_WEIGHT, this.getRealYGivenPrice(price) + this.unclaimedFeesY * FEE_COLLECTED_WEIGHT);
|
|
64
57
|
}
|
|
65
|
-
|
|
58
|
+
getUsableCollateralValueGivenPriceAndDeltaLeverage(price, deltaX, deltaY) {
|
|
66
59
|
const liquidity = this.getLiquidityGivenAmounts(deltaX, deltaY);
|
|
67
60
|
return this.getValueGivenPriceAndAmounts(price, this.getRealXGivenLiquidityAndPrice(this.liquidity + liquidity, price) + this.unclaimedFeesX * FEE_COLLECTED_WEIGHT, this.getRealYGivenLiquidityAndPrice(this.liquidity + liquidity, price) + this.unclaimedFeesY * FEE_COLLECTED_WEIGHT);
|
|
68
61
|
}
|
|
69
|
-
getWeightedLiquidityPostLiquidationValueGivenPriceAndDebt(price, debtX, debtY) {
|
|
70
|
-
const debtValue = this.getValueGivenPriceAndAmounts(price, debtX, debtY);
|
|
71
|
-
const collateralValue = this.getWeightedCollateralValueGivenPrice(price);
|
|
72
|
-
const collateralNeeded = debtValue * this.liquidationPenalty;
|
|
73
|
-
return collateralValue - collateralNeeded;
|
|
74
|
-
}
|
|
75
|
-
getWeightedLiquidityPostLiquidationValueGivenPriceAndDeltaLeverage(price, deltaX, deltaY) {
|
|
76
|
-
const debtValue = this.getDebtValueGivenPrice(price) + this.getValueGivenPriceAndAmounts(price, deltaX, deltaY);
|
|
77
|
-
const collateralValue = this.getWeightedCollateralValueGivenPriceAndDeltaLeverage(price, deltaX, deltaY);
|
|
78
|
-
const collateralNeeded = debtValue * this.liquidationPenalty;
|
|
79
|
-
return collateralValue - collateralNeeded;
|
|
80
|
-
}
|
|
81
|
-
isLiquidatableGivenPriceAndDebt(price, debtX, debtY) {
|
|
82
|
-
return this.getWeightedLiquidityPostLiquidationValueGivenPriceAndDebt(price / this.safetyMargin, debtX, debtY) < 0
|
|
83
|
-
|| this.getWeightedLiquidityPostLiquidationValueGivenPriceAndDebt(price * this.safetyMargin, debtX, debtY) < 0;
|
|
84
|
-
}
|
|
85
|
-
isLiquidatableGivenPriceAndDeltaLeverage(price, deltaX, deltaY) {
|
|
86
|
-
return this.getWeightedLiquidityPostLiquidationValueGivenPriceAndDeltaLeverage(price / this.safetyMargin, deltaX, deltaY) < 0
|
|
87
|
-
|| this.getWeightedLiquidityPostLiquidationValueGivenPriceAndDeltaLeverage(price * this.safetyMargin, deltaX, deltaY) < 0;
|
|
88
|
-
}
|
|
89
62
|
getLiquidityGivenAmounts(amountX, amountY) {
|
|
90
63
|
if (amountX == 0) {
|
|
91
64
|
return amountY / Math.sqrt(this.priceB);
|