@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.
@@ -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,EACL,KAAK,aAAa,EAInB,MAAM,mBAAmB,CAAA;AAY1B,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,CA6BpB;AAGD,eAAO,MAAM,6BAA6B,gFAGzC,CAAA"}
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
- const { position } = params;
17
- if (params.marginMode === perps_types_1.MarginMode.CROSS ||
18
- position?.marginMode === perps_types_1.MarginMode.CROSS ||
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":";;;AAwCA,wEAUC;AA0BD,8DAgCC;AA9FD,+CAQwB;AACxB,mDAK0B;AAY1B,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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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 estimateLiquidationPrice} documents.
42
+ * as {@link estimateOrderLiquidationPrice} documents.
43
43
  * @throws {PerpsError} `ValidationError` when `maxLeverage` is not a finite
44
- * number above zero, or on an input that `estimateLiquidationPrice` rejects.
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,EACL,KAAK,aAAa,EAInB,MAAM,mBAAmB,CAAA;AAE1B;;;;;;;;;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,CA6BpB;AAED,cAAc;AACd,eAAO,MAAM,6BAA6B,gFAGzC,CAAA"}
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, estimateLiquidationPrice, numberToDecimalString, PerpsError, subtractDecimalString, } from '@lifi/perps-sdk';
15
- import { MarginMode, PerpsErrorCode, PositionSide, } from '@lifi/perps-types';
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 estimateLiquidationPrice} documents.
47
+ * as {@link estimateOrderLiquidationPrice} documents.
48
48
  * @throws {PerpsError} `ValidationError` when `maxLeverage` is not a finite
49
- * number above zero, or on an input that `estimateLiquidationPrice` rejects.
49
+ * number above zero, or as {@link estimateOrderLiquidationPrice} documents.
50
50
  * @public
51
51
  */
52
52
  export function calculateLiquidationPrice(params, maxLeverage) {
53
- const { position } = params;
54
- if (params.marginMode === MarginMode.CROSS ||
55
- position?.marginMode === MarginMode.CROSS ||
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,wBAAwB,EAExB,qBAAqB,EACrB,UAAU,EACV,qBAAqB,GACtB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAEL,UAAU,EACV,cAAc,EACd,YAAY,GACb,MAAM,mBAAmB,CAAA;AAE1B;;;;;;;;;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,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;IAC3B,IACE,MAAM,CAAC,UAAU,KAAK,UAAU,CAAC,KAAK;QACtC,QAAQ,EAAE,UAAU,KAAK,UAAU,CAAC,KAAK;QACzC,CAAC,QAAQ,KAAK,SAAS;YACrB,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY,CAAC,IAAI,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,EAC1D,CAAC;QACD,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,OA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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 estimateLiquidationPrice} documents.
42
+ * as {@link estimateOrderLiquidationPrice} documents.
43
43
  * @throws {PerpsError} `ValidationError` when `maxLeverage` is not a finite
44
- * number above zero, or on an input that `estimateLiquidationPrice` rejects.
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,EACL,KAAK,aAAa,EAInB,MAAM,mBAAmB,CAAA;AAE1B;;;;;;;;;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,CA6BpB;AAED,cAAc;AACd,eAAO,MAAM,6BAA6B,gFAGzC,CAAA"}
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.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.0.0"
55
+ "@lifi/perps-sdk": "^29.1.0"
56
56
  },
57
57
  "publishConfig": {
58
58
  "access": "public"
@@ -15,18 +15,13 @@
15
15
  import {
16
16
  createSafeFunction,
17
17
  divideDecimalString,
18
- estimateLiquidationPrice,
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 estimateLiquidationPrice} documents.
67
+ * as {@link estimateOrderLiquidationPrice} documents.
73
68
  * @throws {PerpsError} `ValidationError` when `maxLeverage` is not a finite
74
- * number above zero, or on an input that `estimateLiquidationPrice` rejects.
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
- const { position } = params
82
- if (
83
- params.marginMode === MarginMode.CROSS ||
84
- position?.marginMode === MarginMode.CROSS ||
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