@lifi/perps-sdk-provider-hyperliquid 31.0.0 → 31.0.1
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.
- package/dist/cjs/utils/liquidation.d.ts.map +1 -1
- package/dist/cjs/utils/liquidation.js +3 -22
- package/dist/cjs/utils/liquidation.js.map +1 -1
- package/dist/esm/utils/liquidation.d.ts +2 -2
- package/dist/esm/utils/liquidation.d.ts.map +1 -1
- package/dist/esm/utils/liquidation.js +7 -26
- package/dist/esm/utils/liquidation.js.map +1 -1
- package/dist/types/utils/liquidation.d.ts +2 -2
- package/dist/types/utils/liquidation.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/utils/liquidation.ts +8 -36
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"liquidation.d.ts","sourceRoot":"","sources":["../../../src/utils/liquidation.ts"],"names":[],"mappings":"AAcA,OAAO,EAIL,KAAK,yBAAyB,EAI/B,MAAM,iBAAiB,CAAA;AACxB,OAAO,
|
|
1
|
+
{"version":3,"file":"liquidation.d.ts","sourceRoot":"","sources":["../../../src/utils/liquidation.ts"],"names":[],"mappings":"AAcA,OAAO,EAIL,KAAK,yBAAyB,EAI/B,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,mBAAmB,CAAA;AAYtE,wBAAgB,8BAA8B,CAC5C,WAAW,EAAE,MAAM,GAClB,aAAa,CAQf;AAGD,eAAO,MAAM,kCAAkC,6CAG9C,CAAA;AAoBD,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,yBAAyB,EACjC,WAAW,EAAE,MAAM,GAClB,MAAM,GAAG,SAAS,CAMpB;AAGD,eAAO,MAAM,6BAA6B,gFAGzC,CAAA"}
|
|
@@ -13,28 +13,9 @@ function calculateMaintenanceMarginRate(maxLeverage) {
|
|
|
13
13
|
}
|
|
14
14
|
exports.safeCalculateMaintenanceMarginRate = (0, perps_sdk_1.createSafeFunction)('calculateMaintenanceMarginRate', calculateMaintenanceMarginRate);
|
|
15
15
|
function calculateLiquidationPrice(params, maxLeverage) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
position
|
|
19
|
-
(position !== undefined &&
|
|
20
|
-
(position.side === perps_types_1.PositionSide.LONG) !== params.isLong)) {
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
return (0, perps_sdk_1.estimateLiquidationPrice)({
|
|
24
|
-
entryPrice: params.entryPrice,
|
|
25
|
-
leverage: params.leverage,
|
|
26
|
-
isLong: params.isLong,
|
|
27
|
-
maintenanceMarginRate: calculateMaintenanceMarginRate(maxLeverage),
|
|
28
|
-
size: params.size,
|
|
29
|
-
...(position === undefined
|
|
30
|
-
? {}
|
|
31
|
-
: {
|
|
32
|
-
current: {
|
|
33
|
-
size: position.size,
|
|
34
|
-
entryPrice: position.entryPrice,
|
|
35
|
-
margin: (0, perps_sdk_1.subtractDecimalString)(position.marginUsed, position.unrealizedPnl),
|
|
36
|
-
},
|
|
37
|
-
}),
|
|
16
|
+
return (0, perps_sdk_1.estimateOrderLiquidationPrice)(params, {
|
|
17
|
+
maintenanceMarginRate: () => calculateMaintenanceMarginRate(maxLeverage),
|
|
18
|
+
positionCollateral: (position) => (0, perps_sdk_1.subtractDecimalString)(position.marginUsed, position.unrealizedPnl),
|
|
38
19
|
});
|
|
39
20
|
}
|
|
40
21
|
exports.safeCalculateLiquidationPrice = (0, perps_sdk_1.createSafeFunction)('calculateLiquidationPrice', calculateLiquidationPrice);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"liquidation.js","sourceRoot":"","sources":["../../../src/utils/liquidation.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"liquidation.js","sourceRoot":"","sources":["../../../src/utils/liquidation.ts"],"names":[],"mappings":";;;AAmCA,wEAUC;AA0BD,8DASC;AAlED,+CAQwB;AACxB,mDAAsE;AAYtE,SAAgB,8BAA8B,CAC5C,WAAmB;IAEnB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,WAAW,IAAI,CAAC,EAAE,CAAC;QACtD,MAAM,IAAI,sBAAU,CAClB,4BAAc,CAAC,eAAe,EAC9B,2DAA2D,WAAW,GAAG,CAC1E,CAAA;IACH,CAAC;IACD,OAAO,IAAA,+BAAmB,EAAC,GAAG,EAAE,IAAA,iCAAqB,EAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAA;AACzE,CAAC;AAGY,QAAA,kCAAkC,GAAG,IAAA,8BAAkB,EAClE,gCAAgC,EAChC,8BAA8B,CAC/B,CAAA;AAoBD,SAAgB,yBAAyB,CACvC,MAAiC,EACjC,WAAmB;IAEnB,OAAO,IAAA,yCAA6B,EAAC,MAAM,EAAE;QAC3C,qBAAqB,EAAE,GAAG,EAAE,CAAC,8BAA8B,CAAC,WAAW,CAAC;QACxE,kBAAkB,EAAE,CAAC,QAAQ,EAAE,EAAE,CAC/B,IAAA,iCAAqB,EAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,aAAa,CAAC;KACrE,CAAC,CAAA;AACJ,CAAC;AAGY,QAAA,6BAA6B,GAAG,IAAA,8BAAkB,EAC7D,2BAA2B,EAC3B,yBAAyB,CAC1B,CAAA"}
|
|
@@ -39,9 +39,9 @@ export declare const safeCalculateMaintenanceMarginRate: (maxLeverage: number) =
|
|
|
39
39
|
* @returns The estimate, or `undefined` when the order or the position is
|
|
40
40
|
* cross (the liquidation depends on the whole account), when the order
|
|
41
41
|
* reduces the position, or when `leverage` is at or above `2 × maxLeverage`,
|
|
42
|
-
* as {@link
|
|
42
|
+
* as {@link estimateOrderLiquidationPrice} documents.
|
|
43
43
|
* @throws {PerpsError} `ValidationError` when `maxLeverage` is not a finite
|
|
44
|
-
* number above zero, or
|
|
44
|
+
* number above zero, or as {@link estimateOrderLiquidationPrice} documents.
|
|
45
45
|
* @public
|
|
46
46
|
*/
|
|
47
47
|
export declare function calculateLiquidationPrice(params: LiquidationEstimateParams, maxLeverage: number): string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"liquidation.d.ts","sourceRoot":"","sources":["../../../src/utils/liquidation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAIL,KAAK,yBAAyB,EAI/B,MAAM,iBAAiB,CAAA;AACxB,OAAO,
|
|
1
|
+
{"version":3,"file":"liquidation.d.ts","sourceRoot":"","sources":["../../../src/utils/liquidation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAIL,KAAK,yBAAyB,EAI/B,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,mBAAmB,CAAA;AAEtE;;;;;;;;;GASG;AACH,wBAAgB,8BAA8B,CAC5C,WAAW,EAAE,MAAM,GAClB,aAAa,CAQf;AAED,cAAc;AACd,eAAO,MAAM,kCAAkC,6CAG9C,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,yBAAyB,EACjC,WAAW,EAAE,MAAM,GAClB,MAAM,GAAG,SAAS,CAMpB;AAED,cAAc;AACd,eAAO,MAAM,6BAA6B,gFAGzC,CAAA"}
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* - side = 1 (long) or -1 (short)
|
|
12
12
|
* - margin_available = isolated_margin - maintenance_margin_required
|
|
13
13
|
*/
|
|
14
|
-
import { createSafeFunction, divideDecimalString,
|
|
15
|
-
import {
|
|
14
|
+
import { createSafeFunction, divideDecimalString, estimateOrderLiquidationPrice, numberToDecimalString, PerpsError, subtractDecimalString, } from '@lifi/perps-sdk';
|
|
15
|
+
import { PerpsErrorCode } from '@lifi/perps-types';
|
|
16
16
|
/**
|
|
17
17
|
* Maintenance margin fraction for a Hyperliquid asset: half of the initial
|
|
18
18
|
* margin at max leverage, `1 / (2 × maxLeverage)`.
|
|
@@ -44,34 +44,15 @@ export const safeCalculateMaintenanceMarginRate = createSafeFunction('calculateM
|
|
|
44
44
|
* @returns The estimate, or `undefined` when the order or the position is
|
|
45
45
|
* cross (the liquidation depends on the whole account), when the order
|
|
46
46
|
* reduces the position, or when `leverage` is at or above `2 × maxLeverage`,
|
|
47
|
-
* as {@link
|
|
47
|
+
* as {@link estimateOrderLiquidationPrice} documents.
|
|
48
48
|
* @throws {PerpsError} `ValidationError` when `maxLeverage` is not a finite
|
|
49
|
-
* number above zero, or
|
|
49
|
+
* number above zero, or as {@link estimateOrderLiquidationPrice} documents.
|
|
50
50
|
* @public
|
|
51
51
|
*/
|
|
52
52
|
export function calculateLiquidationPrice(params, maxLeverage) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
position
|
|
56
|
-
(position !== undefined &&
|
|
57
|
-
(position.side === PositionSide.LONG) !== params.isLong)) {
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
return estimateLiquidationPrice({
|
|
61
|
-
entryPrice: params.entryPrice,
|
|
62
|
-
leverage: params.leverage,
|
|
63
|
-
isLong: params.isLong,
|
|
64
|
-
maintenanceMarginRate: calculateMaintenanceMarginRate(maxLeverage),
|
|
65
|
-
size: params.size,
|
|
66
|
-
...(position === undefined
|
|
67
|
-
? {}
|
|
68
|
-
: {
|
|
69
|
-
current: {
|
|
70
|
-
size: position.size,
|
|
71
|
-
entryPrice: position.entryPrice,
|
|
72
|
-
margin: subtractDecimalString(position.marginUsed, position.unrealizedPnl),
|
|
73
|
-
},
|
|
74
|
-
}),
|
|
53
|
+
return estimateOrderLiquidationPrice(params, {
|
|
54
|
+
maintenanceMarginRate: () => calculateMaintenanceMarginRate(maxLeverage),
|
|
55
|
+
positionCollateral: (position) => subtractDecimalString(position.marginUsed, position.unrealizedPnl),
|
|
75
56
|
});
|
|
76
57
|
}
|
|
77
58
|
/** @public */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"liquidation.js","sourceRoot":"","sources":["../../../src/utils/liquidation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,
|
|
1
|
+
{"version":3,"file":"liquidation.js","sourceRoot":"","sources":["../../../src/utils/liquidation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,6BAA6B,EAE7B,qBAAqB,EACrB,UAAU,EACV,qBAAqB,GACtB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAsB,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAEtE;;;;;;;;;GASG;AACH,MAAM,UAAU,8BAA8B,CAC5C,WAAmB;IAEnB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,WAAW,IAAI,CAAC,EAAE,CAAC;QACtD,MAAM,IAAI,UAAU,CAClB,cAAc,CAAC,eAAe,EAC9B,2DAA2D,WAAW,GAAG,CAC1E,CAAA;IACH,CAAC;IACD,OAAO,mBAAmB,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAA;AACzE,CAAC;AAED,cAAc;AACd,MAAM,CAAC,MAAM,kCAAkC,GAAG,kBAAkB,CAClE,gCAAgC,EAChC,8BAA8B,CAC/B,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,yBAAyB,CACvC,MAAiC,EACjC,WAAmB;IAEnB,OAAO,6BAA6B,CAAC,MAAM,EAAE;QAC3C,qBAAqB,EAAE,GAAG,EAAE,CAAC,8BAA8B,CAAC,WAAW,CAAC;QACxE,kBAAkB,EAAE,CAAC,QAAQ,EAAE,EAAE,CAC/B,qBAAqB,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,aAAa,CAAC;KACrE,CAAC,CAAA;AACJ,CAAC;AAED,cAAc;AACd,MAAM,CAAC,MAAM,6BAA6B,GAAG,kBAAkB,CAC7D,2BAA2B,EAC3B,yBAAyB,CAC1B,CAAA"}
|
|
@@ -39,9 +39,9 @@ export declare const safeCalculateMaintenanceMarginRate: (maxLeverage: number) =
|
|
|
39
39
|
* @returns The estimate, or `undefined` when the order or the position is
|
|
40
40
|
* cross (the liquidation depends on the whole account), when the order
|
|
41
41
|
* reduces the position, or when `leverage` is at or above `2 × maxLeverage`,
|
|
42
|
-
* as {@link
|
|
42
|
+
* as {@link estimateOrderLiquidationPrice} documents.
|
|
43
43
|
* @throws {PerpsError} `ValidationError` when `maxLeverage` is not a finite
|
|
44
|
-
* number above zero, or
|
|
44
|
+
* number above zero, or as {@link estimateOrderLiquidationPrice} documents.
|
|
45
45
|
* @public
|
|
46
46
|
*/
|
|
47
47
|
export declare function calculateLiquidationPrice(params: LiquidationEstimateParams, maxLeverage: number): string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"liquidation.d.ts","sourceRoot":"","sources":["../../../src/utils/liquidation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAIL,KAAK,yBAAyB,EAI/B,MAAM,iBAAiB,CAAA;AACxB,OAAO,
|
|
1
|
+
{"version":3,"file":"liquidation.d.ts","sourceRoot":"","sources":["../../../src/utils/liquidation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAIL,KAAK,yBAAyB,EAI/B,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,mBAAmB,CAAA;AAEtE;;;;;;;;;GASG;AACH,wBAAgB,8BAA8B,CAC5C,WAAW,EAAE,MAAM,GAClB,aAAa,CAQf;AAED,cAAc;AACd,eAAO,MAAM,kCAAkC,6CAG9C,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,yBAAyB,EACjC,WAAW,EAAE,MAAM,GAClB,MAAM,GAAG,SAAS,CAMpB;AAED,cAAc;AACd,eAAO,MAAM,6BAA6B,gFAGzC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/perps-sdk-provider-hyperliquid",
|
|
3
|
-
"version": "31.0.
|
|
3
|
+
"version": "31.0.1",
|
|
4
4
|
"description": "Hyperliquid provider plugin for @lifi/perps-sdk",
|
|
5
5
|
"homepage": "https://github.com/lifinance/perps-sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@lifi/perps-types": "^26.0.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@lifi/perps-sdk": "^29.
|
|
55
|
+
"@lifi/perps-sdk": "^29.1.0"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|
package/src/utils/liquidation.ts
CHANGED
|
@@ -15,18 +15,13 @@
|
|
|
15
15
|
import {
|
|
16
16
|
createSafeFunction,
|
|
17
17
|
divideDecimalString,
|
|
18
|
-
|
|
18
|
+
estimateOrderLiquidationPrice,
|
|
19
19
|
type LiquidationEstimateParams,
|
|
20
20
|
numberToDecimalString,
|
|
21
21
|
PerpsError,
|
|
22
22
|
subtractDecimalString,
|
|
23
23
|
} from '@lifi/perps-sdk'
|
|
24
|
-
import {
|
|
25
|
-
type DecimalString,
|
|
26
|
-
MarginMode,
|
|
27
|
-
PerpsErrorCode,
|
|
28
|
-
PositionSide,
|
|
29
|
-
} from '@lifi/perps-types'
|
|
24
|
+
import { type DecimalString, PerpsErrorCode } from '@lifi/perps-types'
|
|
30
25
|
|
|
31
26
|
/**
|
|
32
27
|
* Maintenance margin fraction for a Hyperliquid asset: half of the initial
|
|
@@ -69,42 +64,19 @@ export const safeCalculateMaintenanceMarginRate = createSafeFunction(
|
|
|
69
64
|
* @returns The estimate, or `undefined` when the order or the position is
|
|
70
65
|
* cross (the liquidation depends on the whole account), when the order
|
|
71
66
|
* reduces the position, or when `leverage` is at or above `2 × maxLeverage`,
|
|
72
|
-
* as {@link
|
|
67
|
+
* as {@link estimateOrderLiquidationPrice} documents.
|
|
73
68
|
* @throws {PerpsError} `ValidationError` when `maxLeverage` is not a finite
|
|
74
|
-
* number above zero, or
|
|
69
|
+
* number above zero, or as {@link estimateOrderLiquidationPrice} documents.
|
|
75
70
|
* @public
|
|
76
71
|
*/
|
|
77
72
|
export function calculateLiquidationPrice(
|
|
78
73
|
params: LiquidationEstimateParams,
|
|
79
74
|
maxLeverage: number
|
|
80
75
|
): string | undefined {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
(position !== undefined &&
|
|
86
|
-
(position.side === PositionSide.LONG) !== params.isLong)
|
|
87
|
-
) {
|
|
88
|
-
return undefined
|
|
89
|
-
}
|
|
90
|
-
return estimateLiquidationPrice({
|
|
91
|
-
entryPrice: params.entryPrice,
|
|
92
|
-
leverage: params.leverage,
|
|
93
|
-
isLong: params.isLong,
|
|
94
|
-
maintenanceMarginRate: calculateMaintenanceMarginRate(maxLeverage),
|
|
95
|
-
size: params.size,
|
|
96
|
-
...(position === undefined
|
|
97
|
-
? {}
|
|
98
|
-
: {
|
|
99
|
-
current: {
|
|
100
|
-
size: position.size,
|
|
101
|
-
entryPrice: position.entryPrice,
|
|
102
|
-
margin: subtractDecimalString(
|
|
103
|
-
position.marginUsed,
|
|
104
|
-
position.unrealizedPnl
|
|
105
|
-
),
|
|
106
|
-
},
|
|
107
|
-
}),
|
|
76
|
+
return estimateOrderLiquidationPrice(params, {
|
|
77
|
+
maintenanceMarginRate: () => calculateMaintenanceMarginRate(maxLeverage),
|
|
78
|
+
positionCollateral: (position) =>
|
|
79
|
+
subtractDecimalString(position.marginUsed, position.unrealizedPnl),
|
|
108
80
|
})
|
|
109
81
|
}
|
|
110
82
|
|