@lifi/perps-sdk-provider-hyperliquid 26.0.0 → 27.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.
Files changed (132) hide show
  1. package/dist/cjs/services/getAccount.d.ts.map +1 -1
  2. package/dist/cjs/services/getAccount.js +7 -6
  3. package/dist/cjs/services/getAccount.js.map +1 -1
  4. package/dist/cjs/services/getOrders.d.ts.map +1 -1
  5. package/dist/cjs/services/getOrders.js +5 -27
  6. package/dist/cjs/services/getOrders.js.map +1 -1
  7. package/dist/cjs/services/getPortfolioHistory.d.ts.map +1 -1
  8. package/dist/cjs/services/getPortfolioHistory.js +3 -1
  9. package/dist/cjs/services/getPortfolioHistory.js.map +1 -1
  10. package/dist/cjs/utils/index.d.ts +1 -1
  11. package/dist/cjs/utils/index.d.ts.map +1 -1
  12. package/dist/cjs/utils/index.js +3 -1
  13. package/dist/cjs/utils/index.js.map +1 -1
  14. package/dist/cjs/utils/liquidation.d.ts +4 -1
  15. package/dist/cjs/utils/liquidation.d.ts.map +1 -1
  16. package/dist/cjs/utils/liquidation.js +9 -8
  17. package/dist/cjs/utils/liquidation.js.map +1 -1
  18. package/dist/cjs/utils/mapActivity.d.ts.map +1 -1
  19. package/dist/cjs/utils/mapActivity.js +9 -3
  20. package/dist/cjs/utils/mapActivity.js.map +1 -1
  21. package/dist/cjs/utils/mapFill.d.ts.map +1 -1
  22. package/dist/cjs/utils/mapFill.js +4 -1
  23. package/dist/cjs/utils/mapFill.js.map +1 -1
  24. package/dist/cjs/utils/mapMarket.d.ts.map +1 -1
  25. package/dist/cjs/utils/mapMarket.js +1 -1
  26. package/dist/cjs/utils/mapMarket.js.map +1 -1
  27. package/dist/cjs/utils/mapOrder.d.ts +2 -0
  28. package/dist/cjs/utils/mapOrder.d.ts.map +1 -1
  29. package/dist/cjs/utils/mapOrder.js +31 -19
  30. package/dist/cjs/utils/mapOrder.js.map +1 -1
  31. package/dist/cjs/utils/mapPosition.d.ts.map +1 -1
  32. package/dist/cjs/utils/mapPosition.js +4 -4
  33. package/dist/cjs/utils/mapPosition.js.map +1 -1
  34. package/dist/cjs/utils/spotBalance.d.ts +1 -1
  35. package/dist/cjs/utils/spotBalance.d.ts.map +1 -1
  36. package/dist/cjs/utils/spotBalance.js +4 -1
  37. package/dist/cjs/utils/spotBalance.js.map +1 -1
  38. package/dist/cjs/utils/transferMargin.js +1 -1
  39. package/dist/cjs/utils/transferMargin.js.map +1 -1
  40. package/dist/cjs/utils/venueTotals.d.ts +0 -1
  41. package/dist/cjs/utils/venueTotals.d.ts.map +1 -1
  42. package/dist/cjs/utils/venueTotals.js +13 -4
  43. package/dist/cjs/utils/venueTotals.js.map +1 -1
  44. package/dist/cjs/websocket/HyperliquidWsProvider.d.ts +2 -0
  45. package/dist/cjs/websocket/HyperliquidWsProvider.d.ts.map +1 -1
  46. package/dist/cjs/websocket/HyperliquidWsProvider.js +63 -51
  47. package/dist/cjs/websocket/HyperliquidWsProvider.js.map +1 -1
  48. package/dist/esm/services/getAccount.d.ts.map +1 -1
  49. package/dist/esm/services/getAccount.js +8 -7
  50. package/dist/esm/services/getAccount.js.map +1 -1
  51. package/dist/esm/services/getOrders.d.ts.map +1 -1
  52. package/dist/esm/services/getOrders.js +7 -35
  53. package/dist/esm/services/getOrders.js.map +1 -1
  54. package/dist/esm/services/getPortfolioHistory.d.ts.map +1 -1
  55. package/dist/esm/services/getPortfolioHistory.js +3 -1
  56. package/dist/esm/services/getPortfolioHistory.js.map +1 -1
  57. package/dist/esm/utils/index.d.ts +1 -1
  58. package/dist/esm/utils/index.d.ts.map +1 -1
  59. package/dist/esm/utils/index.js +1 -1
  60. package/dist/esm/utils/index.js.map +1 -1
  61. package/dist/esm/utils/liquidation.d.ts +24 -23
  62. package/dist/esm/utils/liquidation.d.ts.map +1 -1
  63. package/dist/esm/utils/liquidation.js +29 -31
  64. package/dist/esm/utils/liquidation.js.map +1 -1
  65. package/dist/esm/utils/mapActivity.d.ts.map +1 -1
  66. package/dist/esm/utils/mapActivity.js +9 -3
  67. package/dist/esm/utils/mapActivity.js.map +1 -1
  68. package/dist/esm/utils/mapFill.d.ts.map +1 -1
  69. package/dist/esm/utils/mapFill.js +4 -1
  70. package/dist/esm/utils/mapFill.js.map +1 -1
  71. package/dist/esm/utils/mapMarket.d.ts.map +1 -1
  72. package/dist/esm/utils/mapMarket.js +2 -2
  73. package/dist/esm/utils/mapMarket.js.map +1 -1
  74. package/dist/esm/utils/mapOrder.d.ts +7 -0
  75. package/dist/esm/utils/mapOrder.d.ts.map +1 -1
  76. package/dist/esm/utils/mapOrder.js +35 -19
  77. package/dist/esm/utils/mapOrder.js.map +1 -1
  78. package/dist/esm/utils/mapPosition.d.ts.map +1 -1
  79. package/dist/esm/utils/mapPosition.js +4 -4
  80. package/dist/esm/utils/mapPosition.js.map +1 -1
  81. package/dist/esm/utils/spotBalance.d.ts +2 -1
  82. package/dist/esm/utils/spotBalance.d.ts.map +1 -1
  83. package/dist/esm/utils/spotBalance.js +5 -1
  84. package/dist/esm/utils/spotBalance.js.map +1 -1
  85. package/dist/esm/utils/transferMargin.js +1 -1
  86. package/dist/esm/utils/transferMargin.js.map +1 -1
  87. package/dist/esm/utils/venueTotals.d.ts +2 -6
  88. package/dist/esm/utils/venueTotals.d.ts.map +1 -1
  89. package/dist/esm/utils/venueTotals.js +15 -8
  90. package/dist/esm/utils/venueTotals.js.map +1 -1
  91. package/dist/esm/utils/withdrawableBalances.d.ts +2 -2
  92. package/dist/esm/utils/withdrawableBalances.js +2 -2
  93. package/dist/esm/websocket/HyperliquidWsProvider.d.ts +3 -1
  94. package/dist/esm/websocket/HyperliquidWsProvider.d.ts.map +1 -1
  95. package/dist/esm/websocket/HyperliquidWsProvider.js +66 -54
  96. package/dist/esm/websocket/HyperliquidWsProvider.js.map +1 -1
  97. package/dist/types/services/getAccount.d.ts.map +1 -1
  98. package/dist/types/services/getOrders.d.ts.map +1 -1
  99. package/dist/types/services/getPortfolioHistory.d.ts.map +1 -1
  100. package/dist/types/utils/index.d.ts +1 -1
  101. package/dist/types/utils/index.d.ts.map +1 -1
  102. package/dist/types/utils/liquidation.d.ts +24 -23
  103. package/dist/types/utils/liquidation.d.ts.map +1 -1
  104. package/dist/types/utils/mapActivity.d.ts.map +1 -1
  105. package/dist/types/utils/mapFill.d.ts.map +1 -1
  106. package/dist/types/utils/mapMarket.d.ts.map +1 -1
  107. package/dist/types/utils/mapOrder.d.ts +7 -0
  108. package/dist/types/utils/mapOrder.d.ts.map +1 -1
  109. package/dist/types/utils/mapPosition.d.ts.map +1 -1
  110. package/dist/types/utils/spotBalance.d.ts +2 -1
  111. package/dist/types/utils/spotBalance.d.ts.map +1 -1
  112. package/dist/types/utils/venueTotals.d.ts +2 -6
  113. package/dist/types/utils/venueTotals.d.ts.map +1 -1
  114. package/dist/types/utils/withdrawableBalances.d.ts +2 -2
  115. package/dist/types/websocket/HyperliquidWsProvider.d.ts +3 -1
  116. package/dist/types/websocket/HyperliquidWsProvider.d.ts.map +1 -1
  117. package/package.json +3 -3
  118. package/src/services/getAccount.ts +16 -6
  119. package/src/services/getOrders.ts +9 -44
  120. package/src/services/getPortfolioHistory.ts +3 -7
  121. package/src/utils/index.ts +2 -0
  122. package/src/utils/liquidation.ts +42 -34
  123. package/src/utils/mapActivity.ts +9 -3
  124. package/src/utils/mapFill.ts +4 -1
  125. package/src/utils/mapMarket.ts +4 -2
  126. package/src/utils/mapOrder.ts +46 -20
  127. package/src/utils/mapPosition.ts +8 -4
  128. package/src/utils/spotBalance.ts +8 -1
  129. package/src/utils/transferMargin.ts +1 -1
  130. package/src/utils/venueTotals.ts +21 -28
  131. package/src/utils/withdrawableBalances.ts +2 -2
  132. package/src/websocket/HyperliquidWsProvider.ts +105 -69
@@ -11,38 +11,39 @@
11
11
  * - side = 1 (long) or -1 (short)
12
12
  * - margin_available = isolated_margin - maintenance_margin_required
13
13
  */
14
+ import { type DecimalString } from '@lifi/perps-types';
14
15
  /**
15
- * Calculate the maintenance margin fraction for a Hyperliquid asset.
16
- *
17
- * Maintenance margin is half of the initial margin at max leverage.
16
+ * Maintenance margin fraction for a Hyperliquid asset: half of the initial
17
+ * margin at max leverage, `1 / (2 × maxLeverage)`.
18
18
  *
19
19
  * @param maxLeverage - Maximum leverage for the asset (e.g., 50 for BTC)
20
- * @returns Maintenance margin fraction (e.g., 0.01 for 50x max leverage),
21
- * or undefined if maxLeverage is zero
20
+ * @returns Maintenance margin fraction (`'0.01'` for 50x max leverage)
21
+ * @throws {PerpsError} `ValidationError` when `maxLeverage` is not a finite
22
+ * number above zero.
22
23
  * @public
23
24
  */
24
- export declare function calculateMaintenanceMarginRate(maxLeverage: number): number | undefined;
25
+ export declare function calculateMaintenanceMarginRate(maxLeverage: number): DecimalString;
26
+ /** @public */
27
+ export declare const safeCalculateMaintenanceMarginRate: (maxLeverage: number) => string | undefined;
25
28
  /**
26
- * Calculate liquidation price using the exact Hyperliquid formula.
27
- *
28
- * For isolated margin, new position prediction. For existing positions,
29
- * prefer Position.liquidationPrice from the API.
29
+ * Liquidation price of a new isolated position with the exact Hyperliquid
30
+ * formula. For an existing position, prefer `Position.liquidationPrice` from
31
+ * the API.
30
32
  *
31
33
  * Formula derivation (isolated margin, single position):
32
- * margin_per_unit = entryPrice / leverage
33
- * maintenance_per_unit = entryPrice * mmr
34
- * margin_available = margin_per_unit - maintenance_per_unit
35
- * liq_price = entryPrice - side * margin_available / (1 - mmr * side)
36
- *
37
- * Where mmr = 1 / (2 * maxLeverage).
38
- *
39
- * @param entryPrice - Position entry price
40
- * @param leverage - User-selected leverage (e.g., 10)
41
- * @param isLong - True if long position, false if short
42
- * @param maxLeverage - Asset's maximum leverage (e.g., 50 for BTC). Determines
43
- * the maintenance margin rate: mmr = 1 / (2 * maxLeverage)
44
- * @returns Estimated liquidation price, or undefined if inputs are invalid
34
+ * margin_available = entryPrice × (1 / leverage - mmr)
35
+ * liq_price = entryPrice - side × margin_available / (1 - mmr × side)
36
+ *
37
+ * @param leverage - User-selected leverage (e.g., `'10'`)
38
+ * @param maxLeverage - Asset's maximum leverage (e.g., 50 for BTC). Sets
39
+ * mmr = 1 / (2 × maxLeverage).
40
+ * @returns The estimate, or `undefined` when `leverage` is at or above
41
+ * `2 × maxLeverage`, as {@link estimateLiquidationPrice} documents.
42
+ * @throws {PerpsError} `ValidationError` when `maxLeverage` is not a finite
43
+ * number above zero, or on an input that `estimateLiquidationPrice` rejects.
45
44
  * @public
46
45
  */
47
46
  export declare function calculateLiquidationPrice(entryPrice: string, leverage: string, isLong: boolean, maxLeverage: number): string | undefined;
47
+ /** @public */
48
+ export declare const safeCalculateLiquidationPrice: (entryPrice: string, leverage: string, isLong: boolean, maxLeverage: number) => string | undefined;
48
49
  //# sourceMappingURL=liquidation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"liquidation.d.ts","sourceRoot":"","sources":["../../../src/utils/liquidation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAQH;;;;;;;;;GASG;AACH,wBAAgB,8BAA8B,CAC5C,WAAW,EAAE,MAAM,GAClB,MAAM,GAAG,SAAS,CAKpB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,MAAM,GAClB,MAAM,GAAG,SAAS,CAapB"}
1
+ {"version":3,"file":"liquidation.d.ts","sourceRoot":"","sources":["../../../src/utils/liquidation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AASH,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,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,MAAM,GAClB,MAAM,GAAG,SAAS,CAOpB;AAED,cAAc;AACd,eAAO,MAAM,6BAA6B,oGAGzC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"mapActivity.d.ts","sourceRoot":"","sources":["../../../src/utils/mapActivity.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAQnB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EACV,YAAY,EAIZ,eAAe,EACf,mBAAmB,EACnB,aAAa,EAGd,MAAM,mBAAmB,CAAA;AAG1B,OAAO,KAAK,EAEV,eAAe,EACf,cAAc,EACd,UAAU,EACX,MAAM,mBAAmB,CAAA;AA4D1B;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GACzB,OAAO,cAAc,EACrB,aAAa,MAAM,EACnB,gBAAgB,MAAM,EACtB,eAAe,aAAa,EAC5B,eAAe,CAAC,IAAI,EAAE,MAAM,KAAK,aAAa,GAAG,SAAS,KACzD,YAAY,GAAG,IAwMjB,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,GAC7B,OAAO,eAAe,EACtB,aAAa,MAAM,EACnB,eAAe,CAAC,IAAI,EAAE,MAAM,KAAK,aAAa,GAAG,SAAS,KACzD,eAAe,GAAG,IAoBpB,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAC9B,OAAO,UAAU,EAAE,EACnB,aAAa,MAAM,EACnB,gBAAgB,MAAM,EACtB,eAAe,CAAC,IAAI,EAAE,MAAM,KAAK,aAAa,GAAG,SAAS,EAC1D,cAAc,WAAW,CAAC,MAAM,CAAC,KAChC,mBAAmB,EAwDrB,CAAA"}
1
+ {"version":3,"file":"mapActivity.d.ts","sourceRoot":"","sources":["../../../src/utils/mapActivity.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK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AAa,KACpB,IAAI,GAAG,SA+CT,CAAA"}
1
+ {"version":3,"file":"mapFill.d.ts","sourceRoot":"","sources":["../../../src/utils/mapFill.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EAIzB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAQ5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAGnD,0FAA0F;AAC1F,OAAO,EAAE,wBAAwB,EAAE,CAAA;AAEnC;;;;;GAKG;AACH,eAAO,MAAM,OAAO,GAClB,MAAM,UAAU,EAChB,QAAQ,aAAa,KACpB,IAAI,GAAG,SAkDT,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"mapMarket.d.ts","sourceRoot":"","sources":["../../../src/utils/mapMarket.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAGpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAqC7E;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GACpB,UAAU,cAAc,EACxB,YAAY,MAAM,EAClB,qBAAqB,oBAAoB,KACxC,WAuBD,CAAA"}
1
+ {"version":3,"file":"mapMarket.d.ts","sourceRoot":"","sources":["../../../src/utils/mapMarket.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAGpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAqC7E;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GACpB,UAAU,cAAc,EACxB,YAAY,MAAM,EAClB,qBAAqB,oBAAoB,KACxC,WAyBD,CAAA"}
@@ -1,3 +1,4 @@
1
+ import { type MarketRegistry } from '@lifi/perps-sdk';
1
2
  import type { MarketDisplay, Order } from '@lifi/perps-types';
2
3
  import { OrderStatus, OrderType } from '@lifi/perps-types';
3
4
  import type { HlFrontendOpenOrder, HlOrderDetail, HlTwapHistoryEntry } from '../types/index.js';
@@ -7,6 +8,12 @@ export type HlOrderLike = HlFrontendOpenOrder | HlOrderDetail['order'];
7
8
  export declare const mapOrderType: (orderType: string) => Exclude<OrderType, OrderType.TWAP>;
8
9
  /** Translate venue lifecycle statuses; unknown statuses are errors. */
9
10
  export declare const mapOrderStatus: (status: string) => OrderStatus;
11
+ /**
12
+ * Map one venue row, or drop it. An outcome market identity, a coin the backend
13
+ * market list does not hold, and a row the mapper rejects each drop only their
14
+ * own row; each distinct mapper message warns once.
15
+ */
16
+ export declare const mapOrderRow: (coin: string, registry: MarketRegistry | undefined, map: (market: MarketDisplay) => Order | undefined) => Order | undefined;
10
17
  /**
11
18
  * Normalize regular, trigger, and TWAP rows through one lifecycle model. A row
12
19
  * whose filled or remaining size or timestamp cannot be derived gives `undefined`.
@@ -1 +1 @@
1
- {"version":3,"file":"mapOrder.d.ts","sourceRoot":"","sources":["../../../src/utils/mapOrder.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,aAAa,EACb,KAAK,EAGN,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAEL,WAAW,EACX,SAAS,EAGV,MAAM,mBAAmB,CAAA;AAE1B,OAAO,KAAK,EACV,mBAAmB,EACnB,aAAa,EACb,kBAAkB,EACnB,MAAM,mBAAmB,CAAA;AAG1B,4EAA4E;AAC5E,MAAM,MAAM,WAAW,GAAG,mBAAmB,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;AAEtE,gFAAgF;AAChF,eAAO,MAAM,YAAY,GACvB,WAAW,MAAM,KAChB,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,CAiBnC,CAAA;AAED,uEAAuE;AACvE,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,KAAG,WAuC/C,CAAA;AAqBD;;;GAGG;AACH,eAAO,MAAM,QAAQ,GACnB,KAAK,WAAW,GAAG,aAAa,GAAG,kBAAkB,EACrD,QAAQ,aAAa,EACrB,gBAAgB,MAAM,KACrB,KAAK,GAAG,SAmKV,CAAA"}
1
+ {"version":3,"file":"mapOrder.d.ts","sourceRoot":"","sources":["../../../src/utils/mapOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,EAQpB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EACV,aAAa,EACb,KAAK,EAGN,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAEL,WAAW,EACX,SAAS,EAGV,MAAM,mBAAmB,CAAA;AAE1B,OAAO,KAAK,EACV,mBAAmB,EACnB,aAAa,EACb,kBAAkB,EACnB,MAAM,mBAAmB,CAAA;AAI1B,4EAA4E;AAC5E,MAAM,MAAM,WAAW,GAAG,mBAAmB,GAAG,aAAa,CAAC,OAAO,CAAC,CAAA;AAEtE,gFAAgF;AAChF,eAAO,MAAM,YAAY,GACvB,WAAW,MAAM,KAChB,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,CAiBnC,CAAA;AAED,uEAAuE;AACvE,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,KAAG,WAuC/C,CAAA;AAaD;;;;GAIG;AACH,eAAO,MAAM,WAAW,GACtB,MAAM,MAAM,EACZ,UAAU,cAAc,GAAG,SAAS,EACpC,KAAK,CAAC,MAAM,EAAE,aAAa,KAAK,KAAK,GAAG,SAAS,KAChD,KAAK,GAAG,SAkBV,CAAA;AAQD;;;GAGG;AACH,eAAO,MAAM,QAAQ,GACnB,KAAK,WAAW,GAAG,aAAa,GAAG,kBAAkB,EACrD,QAAQ,aAAa,EACrB,gBAAgB,MAAM,KACrB,KAAK,GAAG,SAgKV,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"mapPosition.d.ts","sourceRoot":"","sources":["../../../src/utils/mapPosition.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAGrE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AASxD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAI,IAAI,eAAe,KAAG,OACP,CAAA;AAEnD;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,GACtB,IAAI,eAAe,EACnB,QAAQ,kBAAkB,KACzB,QAAQ,GAAG,SAsDb,CAAA"}
1
+ {"version":3,"file":"mapPosition.d.ts","sourceRoot":"","sources":["../../../src/utils/mapPosition.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAGrE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAaxD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAI,IAAI,eAAe,KAAG,OACP,CAAA;AAEnD;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,GACtB,IAAI,eAAe,EACnB,QAAQ,kBAAkB,KACzB,QAAQ,GAAG,SAsDb,CAAA"}
@@ -11,9 +11,10 @@ export declare const spotPriceById: (markets: readonly Market[], priceByMarketId
11
11
  * Convert a Hyperliquid spot balance's numeric token index into an SDK asset.
12
12
  * The balance payload has no `fullName`, so logo resolution uses the base
13
13
  * `_spot` URI rule rather than Unit-underlying lookup.
14
+ * @param registered - The registry `Asset` with the same `id`; only its `decimals` is copied.
14
15
  * @public
15
16
  */
16
- export declare const spotAssetFromToken: (b: HlSpotBalance) => Asset;
17
+ export declare const spotAssetFromToken: (b: HlSpotBalance, registered?: Asset) => Asset;
17
18
  /** Assemble a typed spot {@link Balance}; `total` is native token units and its unit price and USD value use `priceById`. @public */
18
19
  export declare const spotBalance: (asset: Asset, total: DecimalString, priceById: ReadonlyMap<string, DecimalString>) => Balance;
19
20
  //# sourceMappingURL=spotBalance.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"spotBalance.d.ts","sourceRoot":"","sources":["../../../src/utils/spotBalance.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE9E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAItD;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GACxB,SAAS,SAAS,MAAM,EAAE,EAC1B,iBAAiB,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,KAClD,GAAG,CAAC,MAAM,EAAE,aAAa,CAc3B,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,GAAG,aAAa,KAAG,KAIpD,CAAA;AAEF,qIAAqI;AACrI,eAAO,MAAM,WAAW,GACtB,OAAO,KAAK,EACZ,OAAO,aAAa,EACpB,WAAW,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,KAC5C,OAUF,CAAA"}
1
+ {"version":3,"file":"spotBalance.d.ts","sourceRoot":"","sources":["../../../src/utils/spotBalance.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE9E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAItD;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GACxB,SAAS,SAAS,MAAM,EAAE,EAC1B,iBAAiB,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,KAClD,GAAG,CAAC,MAAM,EAAE,aAAa,CAc3B,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAC7B,GAAG,aAAa,EAChB,aAAa,KAAK,KACjB,KAOD,CAAA;AAEF,qIAAqI;AACrI,eAAO,MAAM,WAAW,GACtB,OAAO,KAAK,EACZ,OAAO,aAAa,EACpB,WAAW,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,KAC5C,OAUF,CAAA"}
@@ -19,13 +19,9 @@ export declare const perpsTotals: (dexStates: readonly DexMarginSummary[]) => {
19
19
  marginUsed: DecimalString;
20
20
  };
21
21
  /**
22
- * Sum the unrealized PnL of every position, in quote-asset units.
22
+ * Sum the unrealized PnL of every position, in quote-asset units. A term that
23
+ * does not match the decimal pattern adds nothing and warns once.
23
24
  * @public
24
25
  */
25
26
  export declare const sumUnrealizedPnl: (positions: readonly Position[]) => DecimalString;
26
- /**
27
- * Sum every term, or `undefined` with a warning when any term is not a
28
- * decimal string. A bad term never gives a partial sum.
29
- */
30
- export declare const safeSumDecimalStrings: (terms: readonly string[]) => DecimalString | undefined;
31
27
  //# sourceMappingURL=venueTotals.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"venueTotals.d.ts","sourceRoot":"","sources":["../../../src/utils/venueTotals.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,aAAa,EACb,wBAAwB,EACxB,QAAQ,EACT,MAAM,mBAAmB,CAAA;AAG1B;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,aAAa,CAAC,EAAE,wBAAwB,CAAA;CACzC;AAED;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GACtB,WAAW,SAAS,gBAAgB,EAAE,KACrC;IAAE,YAAY,EAAE,aAAa,CAAC;IAAC,UAAU,EAAE,aAAa,CAAA;CAyB1D,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAC3B,WAAW,SAAS,QAAQ,EAAE,KAC7B,aAYA,CAAA;AAEH;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAChC,OAAO,SAAS,MAAM,EAAE,KACvB,aAAa,GAAG,SAKhB,CAAA"}
1
+ {"version":3,"file":"venueTotals.d.ts","sourceRoot":"","sources":["../../../src/utils/venueTotals.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,aAAa,EACb,wBAAwB,EACxB,QAAQ,EACT,MAAM,mBAAmB,CAAA;AAG1B;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,aAAa,CAAC,EAAE,wBAAwB,CAAA;CACzC;AAED;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GACtB,WAAW,SAAS,gBAAgB,EAAE,KACrC;IAAE,YAAY,EAAE,aAAa,CAAC;IAAC,UAAU,EAAE,aAAa,CAAA;CAyB1D,CAAA;AAID;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAC3B,WAAW,SAAS,QAAQ,EAAE,KAC7B,aAaF,CAAA"}
@@ -11,8 +11,8 @@ import type { HlAbstractionMode, HlClearinghouseState, HlSpotClearinghouseState
11
11
  * @param withdrawalFee - Flat venue fee in quote-asset units, set on every
12
12
  * quote-asset row. Hyperliquid deducts it from the requested amount. Absent
13
13
  * leaves every row without a fee.
14
- * @throws {PerpsError} `SDKError` when the fee or a venue figure is not a
15
- * decimal.
14
+ * @throws {PerpsError} `SDKError` when the fee or a venue figure does not match the
15
+ * decimal pattern.
16
16
  * @public
17
17
  */
18
18
  export declare const hyperliquidWithdrawableBalances: (abstraction: HlAbstractionMode | null, state: HlClearinghouseState, spotState: HlSpotClearinghouseState, quoteAssetId: string, withdrawalFee?: string) => ProviderWithdrawableBalance[];
@@ -31,6 +31,7 @@ export declare class HyperliquidWsProvider extends WsProviderBase<object> {
31
31
  private readonly clearinghouseRefs;
32
32
  private readonly client;
33
33
  private readonly registry;
34
+ private readonly assetRegistry;
34
35
  private readonly accountChecksByUser;
35
36
  private readonly abstractionByUser;
36
37
  private readonly summaryUsers;
@@ -115,7 +116,7 @@ export declare class HyperliquidWsProvider extends WsProviderBase<object> {
115
116
  private handleActiveSpotAssetCtx;
116
117
  /** Latest mid per `Market.id` across asset-context and fast feeds. */
117
118
  /** Latest mid per `Market.id` across asset-context and fast feeds; a mid
118
- * that is not a decimal string is left out. */
119
+ * that does not match the decimal pattern is left out. */
119
120
  private mergedMids;
120
121
  private orderbookReferencePrice;
121
122
  private handleL2Book;
@@ -125,6 +126,7 @@ export declare class HyperliquidWsProvider extends WsProviderBase<object> {
125
126
  private handleCandle;
126
127
  private handleTrades;
127
128
  private handleOrderUpdates;
129
+ private readOrderDetail;
128
130
  private handleUserFills;
129
131
  private handleAllDexsClearinghouseState;
130
132
  /** Whether the mode's collateral lives per-dex, making the perps-only
@@ -1 +1 @@
1
- {"version":3,"file":"HyperliquidWsProvider.d.ts","sourceRoot":"","sources":["../../../src/websocket/HyperliquidWsProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAaL,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,aAAa,EAGlB,KAAK,oBAAoB,EAYzB,cAAc,EACd,KAAK,iBAAiB,EAEtB,KAAK,gBAAgB,EAEtB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAQV,YAAY,EACb,MAAM,mBAAmB,CAAA;AAyE1B;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,QAAO,iBAKtC,CAAA;AAEH;;;;;;;;;;;;;GAaG;AACH,qBAAa,qBAAsB,SAAQ,cAAc,CAAC,MAAM,CAAC;IAC/D,OAAO,CAAC,eAAe,CAAoB;IAC3C,OAAO,CAAC,iBAAiB,CAAI;IAC7B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;IACpC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA4B;IAC9D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4B;IACnD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA4B;IACrD,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAmC;IAEvE,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAG/B;IACH,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAoB;IACjD,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAA4B;IACnE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA4B;IACrD,OAAO,CAAC,aAAa,CAAI;IACzB,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAuC;IACxE,OAAO,CAAC,QAAQ,CAAC,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nD;;+BAE2B;IAC3B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAM;IAEjD,OAAO,CAAC,uBAAuB;IA4C/B,OAAO,CAAC,oBAAoB;IAsD5B,OAAO,CAAC,qBAAqB;IAqB7B,OAAO,CAAC,eAAe;IAsBvB,OAAO,CAAC,gBAAgB;IAuDxB,0EAA0E;IAC1E,OAAO,CAAC,8BAA8B;CAsCvC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/perps-sdk-provider-hyperliquid",
3
- "version": "26.0.0",
3
+ "version": "27.0.1",
4
4
  "description": "Hyperliquid provider plugin for @lifi/perps-sdk",
5
5
  "homepage": "https://github.com/lifinance/perps-sdk",
6
6
  "bugs": {
@@ -49,10 +49,10 @@
49
49
  "dependencies": {
50
50
  "big.js": "^7.0.1",
51
51
  "viem": "^2.55.18",
52
- "@lifi/perps-types": "^21.0.0"
52
+ "@lifi/perps-types": "^22.0.0"
53
53
  },
54
54
  "peerDependencies": {
55
- "@lifi/perps-sdk": "^24.0.0"
55
+ "@lifi/perps-sdk": "^25.0.1"
56
56
  },
57
57
  "publishConfig": {
58
58
  "access": "public"
@@ -1,10 +1,13 @@
1
1
  import {
2
+ type AssetRegistry,
2
3
  calculateTransferable,
4
+ getAssetRegistry,
3
5
  getMarketRegistry,
4
6
  getMarketsContext,
5
7
  isDecimalStringGreaterThan,
6
8
  type ProviderGetAccountParams,
7
9
  type SDKRequestOptions,
10
+ safeAddDecimalStrings,
8
11
  subtractDecimalString,
9
12
  toPerpsMarketDisplay,
10
13
  unknownToDecimalString,
@@ -38,7 +41,6 @@ import {
38
41
  } from '../utils/index.js'
39
42
  import { hlInfoOptions, infoRequest } from '../utils/infoClient.js'
40
43
  import { isOpenAssetPosition, mapPosition } from '../utils/mapPosition.js'
41
- import { safeSumDecimalStrings } from '../utils/venueTotals.js'
42
44
  import { requireAccountExists } from './getAccountExists.js'
43
45
 
44
46
  /**
@@ -68,7 +70,8 @@ const buildBalances = (
68
70
  stateByDex: Map<string, HlClearinghouseState>,
69
71
  quoteAssetIds: ReadonlySet<string>,
70
72
  priceById: ReadonlyMap<string, DecimalString>,
71
- quoteAssetByCategory: Map<string, Asset>
73
+ quoteAssetByCategory: Map<string, Asset>,
74
+ assetRegistry: AssetRegistry
72
75
  ): BalancePartition => {
73
76
  const { balances, collateralBalances } = partitionSpotBalances(
74
77
  spotState.balances
@@ -85,7 +88,11 @@ const buildBalances = (
85
88
  PROVIDER_KEY
86
89
  )
87
90
  return {
88
- ...spotBalance(spotAssetFromToken(b), total, priceById),
91
+ ...spotBalance(
92
+ spotAssetFromToken(b, assetRegistry.get(String(b.token))),
93
+ total,
94
+ priceById
95
+ ),
89
96
  transferable: calculateTransferable(
90
97
  subtractDecimalString(total, hold),
91
98
  total
@@ -168,6 +175,7 @@ export const getAccount = async (
168
175
  const quoteAssetByCategory = new Map(
169
176
  markets.map((m) => [m.categoryId, m.quoteAsset])
170
177
  )
178
+ const assetRegistry = getAssetRegistry(client, PROVIDER_KEY)
171
179
 
172
180
  const [
173
181
  feesResult,
@@ -214,6 +222,7 @@ export const getAccount = async (
214
222
  )
215
223
  ),
216
224
  getMarketsContext(client, { provider: PROVIDER_KEY }, options),
225
+ assetRegistry.sync(),
217
226
  ])
218
227
 
219
228
  const priceById = spotPriceById(
@@ -271,15 +280,16 @@ export const getAccount = async (
271
280
  stateByDex,
272
281
  quoteAssetIds,
273
282
  priceById,
274
- quoteAssetByCategory
283
+ quoteAssetByCategory,
284
+ assetRegistry
275
285
  )
276
286
 
277
- const marginUsed = safeSumDecimalStrings(
287
+ const marginUsed = safeAddDecimalStrings(
278
288
  dexStates.flatMap(({ marginSummary }) =>
279
289
  marginSummary === undefined ? [] : [marginSummary.totalMarginUsed]
280
290
  )
281
291
  )
282
- const unrealizedPnl = safeSumDecimalStrings(
292
+ const unrealizedPnl = safeAddDecimalStrings(
283
293
  positions.map((position) => position.unrealizedPnl)
284
294
  )
285
295
 
@@ -1,14 +1,11 @@
1
1
  import {
2
2
  ACTIVE_ORDER_STATUSES,
3
- createWarnOnce,
4
3
  getMarketRegistry,
5
4
  isActiveOrderStatus,
6
- type MarketRegistry,
7
- PerpsError,
8
5
  type ProviderGetOrdersParams,
9
6
  type SDKRequestOptions,
10
7
  } from '@lifi/perps-sdk'
11
- import type { MarketDisplay, Order, OrdersResponse } from '@lifi/perps-types'
8
+ import type { Order, OrdersResponse } from '@lifi/perps-types'
12
9
  import { PROVIDER_KEY } from '../constants.js'
13
10
  import type { HyperliquidContext } from '../context.js'
14
11
  import type {
@@ -17,48 +14,14 @@ import type {
17
14
  HlTwapHistoryEntry,
18
15
  } from '../types/index.js'
19
16
  import { withExplorerLinks } from '../utils/explorer.js'
20
- import { assetIsOutcome, mapOrder, perpsDexNames } from '../utils/index.js'
17
+ import { mapOrder, perpsDexNames } from '../utils/index.js'
21
18
  import { hlInfoOptions, infoRequest } from '../utils/infoClient.js'
19
+ import { mapOrderRow } from '../utils/mapOrder.js'
22
20
  import { requireAccountExists } from './getAccountExists.js'
23
21
 
24
22
  /** Parameters for a lifecycle-filtered Hyperliquid order read. */
25
23
  export type GetOrdersParams = ProviderGetOrdersParams
26
24
 
27
- const warn = createWarnOnce()
28
-
29
- const warnOnce = (key: string): void => {
30
- warn(key, `[${PROVIDER_KEY}] ${key}`)
31
- }
32
-
33
- /**
34
- * Map one venue row, or drop it. An outcome market identity, a coin the backend
35
- * market list does not hold, and a row the mapper rejects each drop only their
36
- * own row instead of rejecting the whole page; each distinct mapper message
37
- * warns once.
38
- */
39
- const mapRow = (
40
- coin: string,
41
- registry: MarketRegistry,
42
- map: (market: MarketDisplay) => Order | undefined
43
- ): Order | undefined => {
44
- if (assetIsOutcome(coin)) {
45
- return undefined
46
- }
47
- const market = registry.get(coin)
48
- if (market === undefined) {
49
- return undefined
50
- }
51
- try {
52
- return map(market)
53
- } catch (error) {
54
- if (!(error instanceof PerpsError)) {
55
- throw error
56
- }
57
- warnOnce(`dropped order row: ${error.message}`)
58
- return undefined
59
- }
60
- }
61
-
62
25
  /** Read regular, trigger, and TWAP orders from the requested lifecycle feeds. */
63
26
  export const getOrders = async (
64
27
  { client, apiUrl }: HyperliquidContext,
@@ -127,7 +90,9 @@ export const getOrders = async (
127
90
  seenHistorical.add(key)
128
91
  keep(
129
92
  key,
130
- mapRow(detail.order.coin, registry, (market) => mapOrder(detail, market))
93
+ mapOrderRow(detail.order.coin, registry, (market) =>
94
+ mapOrder(detail, market)
95
+ )
131
96
  )
132
97
  }
133
98
  const raw = open.flat()
@@ -138,13 +103,13 @@ export const getOrders = async (
138
103
  if (!childIds.has(order.oid)) {
139
104
  keep(
140
105
  String(order.oid),
141
- mapRow(order.coin, registry, (market) => mapOrder(order, market))
106
+ mapOrderRow(order.coin, registry, (market) => mapOrder(order, market))
142
107
  )
143
108
  }
144
109
  for (const child of order.children ?? []) {
145
110
  keep(
146
111
  String(child.oid),
147
- mapRow(child.coin, registry, (market) =>
112
+ mapOrderRow(child.coin, registry, (market) =>
148
113
  mapOrder(child, market, String(order.oid))
149
114
  )
150
115
  )
@@ -154,7 +119,7 @@ export const getOrders = async (
154
119
  for (const twap of twaps) {
155
120
  keep(
156
121
  `twap:${twap.twapId}`,
157
- mapRow(twap.state.coin, registry, (market) => mapOrder(twap, market))
122
+ mapOrderRow(twap.state.coin, registry, (market) => mapOrder(twap, market))
158
123
  )
159
124
  }
160
125
  const matching = [...rows.values()].filter(
@@ -53,13 +53,9 @@ const validSamples = (
53
53
  ): [number, DecimalString][] =>
54
54
  samples.flatMap(([timestamp, value]): [number, DecimalString][] => {
55
55
  if (!Number.isFinite(timestamp)) {
56
- warnSkippedVenueRow(
57
- PROVIDER_KEY,
58
- row,
59
- 'timestamp',
60
- timestamp,
61
- 'timestamp'
62
- )
56
+ warnSkippedVenueRow(PROVIDER_KEY, row, 'timestamp', timestamp, {
57
+ expected: 'timestamp',
58
+ })
63
59
  return []
64
60
  }
65
61
  return [[timestamp, value]]
@@ -27,6 +27,8 @@ export { hlInfoOptions, infoRequest } from './infoClient.js'
27
27
  export {
28
28
  calculateLiquidationPrice,
29
29
  calculateMaintenanceMarginRate,
30
+ safeCalculateLiquidationPrice,
31
+ safeCalculateMaintenanceMarginRate,
30
32
  } from './liquidation.js'
31
33
  export {
32
34
  mapFundingActivity,
@@ -13,50 +13,58 @@
13
13
  */
14
14
 
15
15
  import {
16
+ createSafeFunction,
16
17
  divideDecimalString,
18
+ estimateLiquidationPrice,
17
19
  numberToDecimalString,
18
- safeEstimateLiquidationPrice,
20
+ PerpsError,
19
21
  } from '@lifi/perps-sdk'
22
+ import { type DecimalString, PerpsErrorCode } from '@lifi/perps-types'
20
23
 
21
24
  /**
22
- * Calculate the maintenance margin fraction for a Hyperliquid asset.
23
- *
24
- * Maintenance margin is half of the initial margin at max leverage.
25
+ * Maintenance margin fraction for a Hyperliquid asset: half of the initial
26
+ * margin at max leverage, `1 / (2 × maxLeverage)`.
25
27
  *
26
28
  * @param maxLeverage - Maximum leverage for the asset (e.g., 50 for BTC)
27
- * @returns Maintenance margin fraction (e.g., 0.01 for 50x max leverage),
28
- * or undefined if maxLeverage is zero
29
+ * @returns Maintenance margin fraction (`'0.01'` for 50x max leverage)
30
+ * @throws {PerpsError} `ValidationError` when `maxLeverage` is not a finite
31
+ * number above zero.
29
32
  * @public
30
33
  */
31
34
  export function calculateMaintenanceMarginRate(
32
35
  maxLeverage: number
33
- ): number | undefined {
34
- if (maxLeverage === 0) {
35
- return undefined
36
+ ): DecimalString {
37
+ if (!Number.isFinite(maxLeverage) || maxLeverage <= 0) {
38
+ throw new PerpsError(
39
+ PerpsErrorCode.ValidationError,
40
+ `\`maxLeverage\` must be a finite number above zero, got ${maxLeverage}.`
41
+ )
36
42
  }
37
- return 1 / (2 * maxLeverage)
43
+ return divideDecimalString('1', numberToDecimalString(2 * maxLeverage))
38
44
  }
39
45
 
46
+ /** @public */
47
+ export const safeCalculateMaintenanceMarginRate = createSafeFunction(
48
+ 'calculateMaintenanceMarginRate',
49
+ calculateMaintenanceMarginRate
50
+ )
51
+
40
52
  /**
41
- * Calculate liquidation price using the exact Hyperliquid formula.
42
- *
43
- * For isolated margin, new position prediction. For existing positions,
44
- * prefer Position.liquidationPrice from the API.
53
+ * Liquidation price of a new isolated position with the exact Hyperliquid
54
+ * formula. For an existing position, prefer `Position.liquidationPrice` from
55
+ * the API.
45
56
  *
46
57
  * Formula derivation (isolated margin, single position):
47
- * margin_per_unit = entryPrice / leverage
48
- * maintenance_per_unit = entryPrice * mmr
49
- * margin_available = margin_per_unit - maintenance_per_unit
50
- * liq_price = entryPrice - side * margin_available / (1 - mmr * side)
58
+ * margin_available = entryPrice × (1 / leverage - mmr)
59
+ * liq_price = entryPrice - side × margin_available / (1 - mmr × side)
51
60
  *
52
- * Where mmr = 1 / (2 * maxLeverage).
53
- *
54
- * @param entryPrice - Position entry price
55
- * @param leverage - User-selected leverage (e.g., 10)
56
- * @param isLong - True if long position, false if short
57
- * @param maxLeverage - Asset's maximum leverage (e.g., 50 for BTC). Determines
58
- * the maintenance margin rate: mmr = 1 / (2 * maxLeverage)
59
- * @returns Estimated liquidation price, or undefined if inputs are invalid
61
+ * @param leverage - User-selected leverage (e.g., `'10'`)
62
+ * @param maxLeverage - Asset's maximum leverage (e.g., 50 for BTC). Sets
63
+ * mmr = 1 / (2 × maxLeverage).
64
+ * @returns The estimate, or `undefined` when `leverage` is at or above
65
+ * `2 × maxLeverage`, as {@link estimateLiquidationPrice} documents.
66
+ * @throws {PerpsError} `ValidationError` when `maxLeverage` is not a finite
67
+ * number above zero, or on an input that `estimateLiquidationPrice` rejects.
60
68
  * @public
61
69
  */
62
70
  export function calculateLiquidationPrice(
@@ -65,16 +73,16 @@ export function calculateLiquidationPrice(
65
73
  isLong: boolean,
66
74
  maxLeverage: number
67
75
  ): string | undefined {
68
- if (maxLeverage === 0) {
69
- return undefined
70
- }
71
- return safeEstimateLiquidationPrice({
76
+ return estimateLiquidationPrice({
72
77
  entryPrice,
73
78
  leverage,
74
79
  isLong,
75
- maintenanceMarginRate: divideDecimalString(
76
- '1',
77
- numberToDecimalString(2 * maxLeverage)
78
- ),
80
+ maintenanceMarginRate: calculateMaintenanceMarginRate(maxLeverage),
79
81
  })
80
82
  }
83
+
84
+ /** @public */
85
+ export const safeCalculateLiquidationPrice = createSafeFunction(
86
+ 'calculateLiquidationPrice',
87
+ calculateLiquidationPrice
88
+ )
@@ -102,7 +102,9 @@ export const mapLedgerEntry = (
102
102
  const { delta } = entry
103
103
  const timestamp = rowTimestampToIsoStringOrUndefined(entry.time)
104
104
  if (timestamp === undefined) {
105
- warnSkippedVenueRow(providerKey, 'ledger', 'time', entry.time, 'timestamp')
105
+ warnSkippedVenueRow(providerKey, 'ledger', 'time', entry.time, {
106
+ expected: 'timestamp',
107
+ })
106
108
  return null
107
109
  }
108
110
  const base = { id: entry.hash, provider: providerKey, timestamp }
@@ -322,7 +324,9 @@ export const mapFundingActivity = (
322
324
  }
323
325
  const timestamp = rowTimestampToIsoStringOrUndefined(entry.time)
324
326
  if (timestamp === undefined) {
325
- warnSkippedVenueRow(providerKey, 'funding', 'time', entry.time, 'timestamp')
327
+ warnSkippedVenueRow(providerKey, 'funding', 'time', entry.time, {
328
+ expected: 'timestamp',
329
+ })
326
330
  return null
327
331
  }
328
332
  return {
@@ -387,7 +391,9 @@ export const mapLiquidationFills = (
387
391
  const time = Math.max(...group.map((fill) => fill.time))
388
392
  const timestamp = rowTimestampToIsoStringOrUndefined(time)
389
393
  if (timestamp === undefined) {
390
- warnSkippedVenueRow(providerKey, 'liquidation', 'time', time, 'timestamp')
394
+ warnSkippedVenueRow(providerKey, 'liquidation', 'time', time, {
395
+ expected: 'timestamp',
396
+ })
391
397
  return []
392
398
  }
393
399
  const closedSize =
@@ -31,7 +31,10 @@ export const mapFill = (
31
31
  const size = fill.sz
32
32
  const createdAt = rowTimestampToIsoStringOrUndefined(fill.time)
33
33
  if (createdAt === undefined) {
34
- warnSkippedVenueRow(PROVIDER_KEY, 'fill', 'time', fill.time, 'timestamp')
34
+ warnSkippedVenueRow(PROVIDER_KEY, 'fill', 'time', fill.time, {
35
+ marketId: market.id,
36
+ expected: 'timestamp',
37
+ })
35
38
  return undefined
36
39
  }
37
40
  // HL charges the builder portion in the same token as the total fee.
@@ -3,7 +3,7 @@ import type { PerpsMarket } from '@lifi/perps-types'
3
3
  import { PositionMarginAdjustment } from '@lifi/perps-types'
4
4
  import { PROVIDER_KEY } from '../constants.js'
5
5
  import type { HlMaxMarketOrderNtls, HlUniverseItem } from '../types/index.js'
6
- import { calculateMaintenanceMarginRate } from './liquidation.js'
6
+ import { safeCalculateMaintenanceMarginRate } from './liquidation.js'
7
7
  import { coinAsset } from './marketDisplay.js'
8
8
  import { getMaxPriceDecimals } from './orderFormatting.js'
9
9
 
@@ -72,5 +72,7 @@ export const mapMarket = (
72
72
  (universe.marginMode === undefined && universe.onlyIsolated !== true)
73
73
  ? PositionMarginAdjustment.ADD_AND_REMOVE
74
74
  : PositionMarginAdjustment.ADD_ONLY,
75
- maintenanceMarginRate: calculateMaintenanceMarginRate(universe.maxLeverage),
75
+ maintenanceMarginRate: safeCalculateMaintenanceMarginRate(
76
+ universe.maxLeverage
77
+ ),
76
78
  })