@lifi/perps-sdk-provider-hyperliquid 25.0.0 → 27.0.0

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 (245) hide show
  1. package/dist/cjs/accountSummary.d.ts.map +1 -1
  2. package/dist/cjs/accountSummary.js +8 -14
  3. package/dist/cjs/accountSummary.js.map +1 -1
  4. package/dist/cjs/services/getAccount.d.ts.map +1 -1
  5. package/dist/cjs/services/getAccount.js +18 -16
  6. package/dist/cjs/services/getAccount.js.map +1 -1
  7. package/dist/cjs/services/getFills.d.ts.map +1 -1
  8. package/dist/cjs/services/getFills.js +2 -1
  9. package/dist/cjs/services/getFills.js.map +1 -1
  10. package/dist/cjs/services/getMarketSettings.d.ts.map +1 -1
  11. package/dist/cjs/services/getMarketSettings.js +1 -1
  12. package/dist/cjs/services/getMarketSettings.js.map +1 -1
  13. package/dist/cjs/services/getOrder.d.ts.map +1 -1
  14. package/dist/cjs/services/getOrder.js +14 -4
  15. package/dist/cjs/services/getOrder.js.map +1 -1
  16. package/dist/cjs/services/getOrders.d.ts.map +1 -1
  17. package/dist/cjs/services/getOrders.js +8 -28
  18. package/dist/cjs/services/getOrders.js.map +1 -1
  19. package/dist/cjs/services/getPortfolioHistory.d.ts.map +1 -1
  20. package/dist/cjs/services/getPortfolioHistory.js +17 -6
  21. package/dist/cjs/services/getPortfolioHistory.js.map +1 -1
  22. package/dist/cjs/services/getPositions.d.ts.map +1 -1
  23. package/dist/cjs/services/getPositions.js +4 -1
  24. package/dist/cjs/services/getPositions.js.map +1 -1
  25. package/dist/cjs/types/ws.d.ts +3 -2
  26. package/dist/cjs/types/ws.d.ts.map +1 -1
  27. package/dist/cjs/utils/index.d.ts +1 -1
  28. package/dist/cjs/utils/index.d.ts.map +1 -1
  29. package/dist/cjs/utils/index.js +3 -1
  30. package/dist/cjs/utils/index.js.map +1 -1
  31. package/dist/cjs/utils/liquidation.d.ts +5 -2
  32. package/dist/cjs/utils/liquidation.d.ts.map +1 -1
  33. package/dist/cjs/utils/liquidation.js +8 -8
  34. package/dist/cjs/utils/liquidation.js.map +1 -1
  35. package/dist/cjs/utils/mapActivity.d.ts.map +1 -1
  36. package/dist/cjs/utils/mapActivity.js +38 -23
  37. package/dist/cjs/utils/mapActivity.js.map +1 -1
  38. package/dist/cjs/utils/mapFill.d.ts +1 -1
  39. package/dist/cjs/utils/mapFill.d.ts.map +1 -1
  40. package/dist/cjs/utils/mapFill.js +17 -6
  41. package/dist/cjs/utils/mapFill.js.map +1 -1
  42. package/dist/cjs/utils/mapMarket.d.ts.map +1 -1
  43. package/dist/cjs/utils/mapMarket.js +9 -13
  44. package/dist/cjs/utils/mapMarket.js.map +1 -1
  45. package/dist/cjs/utils/mapMarketContext.d.ts.map +1 -1
  46. package/dist/cjs/utils/mapMarketContext.js +3 -12
  47. package/dist/cjs/utils/mapMarketContext.js.map +1 -1
  48. package/dist/cjs/utils/mapOrder.d.ts +3 -1
  49. package/dist/cjs/utils/mapOrder.d.ts.map +1 -1
  50. package/dist/cjs/utils/mapOrder.js +73 -19
  51. package/dist/cjs/utils/mapOrder.js.map +1 -1
  52. package/dist/cjs/utils/mapPosition.d.ts +1 -1
  53. package/dist/cjs/utils/mapPosition.d.ts.map +1 -1
  54. package/dist/cjs/utils/mapPosition.js +41 -15
  55. package/dist/cjs/utils/mapPosition.js.map +1 -1
  56. package/dist/cjs/utils/rowTimestamp.d.ts +2 -0
  57. package/dist/cjs/utils/rowTimestamp.d.ts.map +1 -0
  58. package/dist/cjs/utils/rowTimestamp.js +14 -0
  59. package/dist/cjs/utils/rowTimestamp.js.map +1 -0
  60. package/dist/cjs/utils/spotBalance.d.ts +3 -3
  61. package/dist/cjs/utils/spotBalance.d.ts.map +1 -1
  62. package/dist/cjs/utils/spotBalance.js +6 -5
  63. package/dist/cjs/utils/spotBalance.js.map +1 -1
  64. package/dist/cjs/utils/spotCollateral.d.ts.map +1 -1
  65. package/dist/cjs/utils/spotCollateral.js +3 -2
  66. package/dist/cjs/utils/spotCollateral.js.map +1 -1
  67. package/dist/cjs/utils/transferMargin.d.ts.map +1 -1
  68. package/dist/cjs/utils/transferMargin.js +16 -19
  69. package/dist/cjs/utils/transferMargin.js.map +1 -1
  70. package/dist/cjs/utils/venueTotals.d.ts +4 -5
  71. package/dist/cjs/utils/venueTotals.d.ts.map +1 -1
  72. package/dist/cjs/utils/venueTotals.js +18 -10
  73. package/dist/cjs/utils/venueTotals.js.map +1 -1
  74. package/dist/cjs/utils/withdrawableBalances.d.ts.map +1 -1
  75. package/dist/cjs/utils/withdrawableBalances.js +10 -10
  76. package/dist/cjs/utils/withdrawableBalances.js.map +1 -1
  77. package/dist/cjs/websocket/HyperliquidWsProvider.d.ts +1 -0
  78. package/dist/cjs/websocket/HyperliquidWsProvider.d.ts.map +1 -1
  79. package/dist/cjs/websocket/HyperliquidWsProvider.js +144 -115
  80. package/dist/cjs/websocket/HyperliquidWsProvider.js.map +1 -1
  81. package/dist/esm/accountSummary.d.ts +2 -1
  82. package/dist/esm/accountSummary.d.ts.map +1 -1
  83. package/dist/esm/accountSummary.js +11 -13
  84. package/dist/esm/accountSummary.js.map +1 -1
  85. package/dist/esm/services/getAccount.d.ts.map +1 -1
  86. package/dist/esm/services/getAccount.js +23 -21
  87. package/dist/esm/services/getAccount.js.map +1 -1
  88. package/dist/esm/services/getFills.d.ts.map +1 -1
  89. package/dist/esm/services/getFills.js +2 -1
  90. package/dist/esm/services/getFills.js.map +1 -1
  91. package/dist/esm/services/getMarketSettings.d.ts.map +1 -1
  92. package/dist/esm/services/getMarketSettings.js +2 -2
  93. package/dist/esm/services/getMarketSettings.js.map +1 -1
  94. package/dist/esm/services/getOrder.d.ts.map +1 -1
  95. package/dist/esm/services/getOrder.js +14 -4
  96. package/dist/esm/services/getOrder.js.map +1 -1
  97. package/dist/esm/services/getOrders.d.ts.map +1 -1
  98. package/dist/esm/services/getOrders.js +12 -37
  99. package/dist/esm/services/getOrders.js.map +1 -1
  100. package/dist/esm/services/getPortfolioHistory.d.ts.map +1 -1
  101. package/dist/esm/services/getPortfolioHistory.js +19 -7
  102. package/dist/esm/services/getPortfolioHistory.js.map +1 -1
  103. package/dist/esm/services/getPositions.d.ts.map +1 -1
  104. package/dist/esm/services/getPositions.js +4 -1
  105. package/dist/esm/services/getPositions.js.map +1 -1
  106. package/dist/esm/services/getWithdrawableBalances.d.ts +1 -1
  107. package/dist/esm/services/getWithdrawableBalances.js +1 -1
  108. package/dist/esm/types/ws.d.ts +3 -2
  109. package/dist/esm/types/ws.d.ts.map +1 -1
  110. package/dist/esm/utils/index.d.ts +1 -1
  111. package/dist/esm/utils/index.d.ts.map +1 -1
  112. package/dist/esm/utils/index.js +1 -1
  113. package/dist/esm/utils/index.js.map +1 -1
  114. package/dist/esm/utils/liquidation.d.ts +23 -24
  115. package/dist/esm/utils/liquidation.d.ts.map +1 -1
  116. package/dist/esm/utils/liquidation.js +26 -31
  117. package/dist/esm/utils/liquidation.js.map +1 -1
  118. package/dist/esm/utils/mapActivity.d.ts +2 -1
  119. package/dist/esm/utils/mapActivity.d.ts.map +1 -1
  120. package/dist/esm/utils/mapActivity.js +41 -22
  121. package/dist/esm/utils/mapActivity.js.map +1 -1
  122. package/dist/esm/utils/mapFill.d.ts +3 -2
  123. package/dist/esm/utils/mapFill.d.ts.map +1 -1
  124. package/dist/esm/utils/mapFill.js +21 -9
  125. package/dist/esm/utils/mapFill.js.map +1 -1
  126. package/dist/esm/utils/mapMarket.d.ts +2 -2
  127. package/dist/esm/utils/mapMarket.d.ts.map +1 -1
  128. package/dist/esm/utils/mapMarket.js +12 -13
  129. package/dist/esm/utils/mapMarket.js.map +1 -1
  130. package/dist/esm/utils/mapMarketContext.d.ts.map +1 -1
  131. package/dist/esm/utils/mapMarketContext.js +3 -9
  132. package/dist/esm/utils/mapMarketContext.js.map +1 -1
  133. package/dist/esm/utils/mapOrder.d.ts +12 -2
  134. package/dist/esm/utils/mapOrder.d.ts.map +1 -1
  135. package/dist/esm/utils/mapOrder.js +81 -17
  136. package/dist/esm/utils/mapOrder.js.map +1 -1
  137. package/dist/esm/utils/mapPosition.d.ts +4 -2
  138. package/dist/esm/utils/mapPosition.d.ts.map +1 -1
  139. package/dist/esm/utils/mapPosition.js +44 -13
  140. package/dist/esm/utils/mapPosition.js.map +1 -1
  141. package/dist/esm/utils/rowTimestamp.d.ts +6 -0
  142. package/dist/esm/utils/rowTimestamp.d.ts.map +1 -0
  143. package/dist/esm/utils/rowTimestamp.js +14 -0
  144. package/dist/esm/utils/rowTimestamp.js.map +1 -0
  145. package/dist/esm/utils/spotBalance.d.ts +5 -5
  146. package/dist/esm/utils/spotBalance.d.ts.map +1 -1
  147. package/dist/esm/utils/spotBalance.js +9 -8
  148. package/dist/esm/utils/spotBalance.js.map +1 -1
  149. package/dist/esm/utils/spotCollateral.d.ts.map +1 -1
  150. package/dist/esm/utils/spotCollateral.js +3 -2
  151. package/dist/esm/utils/spotCollateral.js.map +1 -1
  152. package/dist/esm/utils/transferMargin.d.ts +2 -1
  153. package/dist/esm/utils/transferMargin.d.ts.map +1 -1
  154. package/dist/esm/utils/transferMargin.js +19 -18
  155. package/dist/esm/utils/transferMargin.js.map +1 -1
  156. package/dist/esm/utils/venueTotals.d.ts +7 -6
  157. package/dist/esm/utils/venueTotals.d.ts.map +1 -1
  158. package/dist/esm/utils/venueTotals.js +21 -8
  159. package/dist/esm/utils/venueTotals.js.map +1 -1
  160. package/dist/esm/utils/withdrawableBalances.d.ts +6 -4
  161. package/dist/esm/utils/withdrawableBalances.d.ts.map +1 -1
  162. package/dist/esm/utils/withdrawableBalances.js +17 -15
  163. package/dist/esm/utils/withdrawableBalances.js.map +1 -1
  164. package/dist/esm/websocket/HyperliquidWsProvider.d.ts +3 -0
  165. package/dist/esm/websocket/HyperliquidWsProvider.d.ts.map +1 -1
  166. package/dist/esm/websocket/HyperliquidWsProvider.js +155 -115
  167. package/dist/esm/websocket/HyperliquidWsProvider.js.map +1 -1
  168. package/dist/types/accountSummary.d.ts +2 -1
  169. package/dist/types/accountSummary.d.ts.map +1 -1
  170. package/dist/types/services/getAccount.d.ts.map +1 -1
  171. package/dist/types/services/getFills.d.ts.map +1 -1
  172. package/dist/types/services/getMarketSettings.d.ts.map +1 -1
  173. package/dist/types/services/getOrder.d.ts.map +1 -1
  174. package/dist/types/services/getOrders.d.ts.map +1 -1
  175. package/dist/types/services/getPortfolioHistory.d.ts.map +1 -1
  176. package/dist/types/services/getPositions.d.ts.map +1 -1
  177. package/dist/types/services/getWithdrawableBalances.d.ts +1 -1
  178. package/dist/types/types/ws.d.ts +3 -2
  179. package/dist/types/types/ws.d.ts.map +1 -1
  180. package/dist/types/utils/index.d.ts +1 -1
  181. package/dist/types/utils/index.d.ts.map +1 -1
  182. package/dist/types/utils/liquidation.d.ts +23 -24
  183. package/dist/types/utils/liquidation.d.ts.map +1 -1
  184. package/dist/types/utils/mapActivity.d.ts +2 -1
  185. package/dist/types/utils/mapActivity.d.ts.map +1 -1
  186. package/dist/types/utils/mapFill.d.ts +3 -2
  187. package/dist/types/utils/mapFill.d.ts.map +1 -1
  188. package/dist/types/utils/mapMarket.d.ts +2 -2
  189. package/dist/types/utils/mapMarket.d.ts.map +1 -1
  190. package/dist/types/utils/mapMarketContext.d.ts.map +1 -1
  191. package/dist/types/utils/mapOrder.d.ts +12 -2
  192. package/dist/types/utils/mapOrder.d.ts.map +1 -1
  193. package/dist/types/utils/mapPosition.d.ts +4 -2
  194. package/dist/types/utils/mapPosition.d.ts.map +1 -1
  195. package/dist/types/utils/rowTimestamp.d.ts +6 -0
  196. package/dist/types/utils/rowTimestamp.d.ts.map +1 -0
  197. package/dist/types/utils/spotBalance.d.ts +5 -5
  198. package/dist/types/utils/spotBalance.d.ts.map +1 -1
  199. package/dist/types/utils/spotCollateral.d.ts.map +1 -1
  200. package/dist/types/utils/transferMargin.d.ts +2 -1
  201. package/dist/types/utils/transferMargin.d.ts.map +1 -1
  202. package/dist/types/utils/venueTotals.d.ts +7 -6
  203. package/dist/types/utils/venueTotals.d.ts.map +1 -1
  204. package/dist/types/utils/withdrawableBalances.d.ts +6 -4
  205. package/dist/types/utils/withdrawableBalances.d.ts.map +1 -1
  206. package/dist/types/websocket/HyperliquidWsProvider.d.ts +3 -0
  207. package/dist/types/websocket/HyperliquidWsProvider.d.ts.map +1 -1
  208. package/package.json +3 -3
  209. package/src/HyperliquidProvider.ts +1 -1
  210. package/src/accountSummary.ts +35 -23
  211. package/src/services/getAccount.ts +50 -33
  212. package/src/services/getFills.ts +2 -1
  213. package/src/services/getMarketSettings.ts +6 -2
  214. package/src/services/getOrder.ts +18 -7
  215. package/src/services/getOrders.ts +14 -46
  216. package/src/services/getPortfolioHistory.ts +34 -7
  217. package/src/services/getPositions.ts +4 -3
  218. package/src/services/getWithdrawableBalances.ts +1 -1
  219. package/src/types/ws.ts +3 -2
  220. package/src/utils/index.ts +2 -0
  221. package/src/utils/liquidation.ts +46 -34
  222. package/src/utils/mapActivity.ts +48 -20
  223. package/src/utils/mapFill.ts +25 -9
  224. package/src/utils/mapMarket.ts +16 -12
  225. package/src/utils/mapMarketContext.ts +6 -8
  226. package/src/utils/mapOrder.ts +107 -20
  227. package/src/utils/mapPosition.ts +72 -14
  228. package/src/utils/rowTimestamp.ts +15 -0
  229. package/src/utils/spotBalance.ts +19 -16
  230. package/src/utils/spotCollateral.ts +15 -2
  231. package/src/utils/transferMargin.ts +40 -18
  232. package/src/utils/venueTotals.ts +51 -17
  233. package/src/utils/withdrawableBalances.ts +33 -15
  234. package/src/websocket/HyperliquidWsProvider.ts +224 -133
  235. package/dist/cjs/utils/decimal.d.ts +0 -3
  236. package/dist/cjs/utils/decimal.d.ts.map +0 -1
  237. package/dist/cjs/utils/decimal.js +0 -19
  238. package/dist/cjs/utils/decimal.js.map +0 -1
  239. package/dist/esm/utils/decimal.d.ts +0 -10
  240. package/dist/esm/utils/decimal.d.ts.map +0 -1
  241. package/dist/esm/utils/decimal.js +0 -19
  242. package/dist/esm/utils/decimal.js.map +0 -1
  243. package/dist/types/utils/decimal.d.ts +0 -10
  244. package/dist/types/utils/decimal.d.ts.map +0 -1
  245. package/src/utils/decimal.ts +0 -21
@@ -1,11 +1,14 @@
1
1
  import {
2
+ addDecimalString,
2
3
  calculateTransferable,
4
+ compareDecimalStrings,
3
5
  DecodeChain,
4
6
  getMarketRegistry,
5
7
  isActiveMarket,
6
8
  isActiveOrderStatus,
9
+ isDecimalString,
10
+ isDecimalStringZero,
7
11
  type MarketRegistry,
8
- numberToDecimalString,
9
12
  PerpsError,
10
13
  type PerpsSDKClient,
11
14
  type ProviderGetQuoteParams,
@@ -13,8 +16,18 @@ import {
13
16
  ReconnectingWebSocket,
14
17
  resolveSubscribeQuote,
15
18
  type SubscriptionListener,
19
+ safeAddDecimalString,
20
+ safeDecimalStringToNumber,
21
+ safeDivideDecimalString,
22
+ safeIsDecimalStringGreaterThan,
23
+ safeIsDecimalStringZero,
24
+ safeMultiplyDecimalString,
25
+ safeNumberToDecimalString,
26
+ safeSubtractDecimalString,
27
+ subtractDecimalString,
16
28
  toAssetDisplay,
17
29
  toPerpsMarketDisplay,
30
+ unknownToDecimalString,
18
31
  WsProviderBase,
19
32
  type WsProviderFactory,
20
33
  type WsProviderFactoryParams,
@@ -23,6 +36,7 @@ import {
23
36
  } from '@lifi/perps-sdk'
24
37
  import type {
25
38
  Balance,
39
+ DecimalString,
26
40
  MarketContext,
27
41
  Order,
28
42
  OrderbookLevel,
@@ -31,11 +45,11 @@ import type {
31
45
  Subscription,
32
46
  } from '@lifi/perps-types'
33
47
  import { PerpsErrorCode } from '@lifi/perps-types'
34
- import Big from 'big.js'
35
48
  import { type Address, isAddress } from 'viem'
36
49
  import {
37
50
  DEFAULT_HYPERLIQUID_API_URL,
38
51
  HYPERLIQUID_FEE_TIER_FALLBACK,
52
+ PROVIDER_KEY,
39
53
  SPOT_MARKET_ID,
40
54
  } from '../constants.js'
41
55
  import { requireAccountExists } from '../services/getAccountExists.js'
@@ -67,7 +81,6 @@ import type {
67
81
  HlWsUserFillsData,
68
82
  } from '../types/index.js'
69
83
  import { HlAbstractionMode } from '../types/index.js'
70
- import { toWireBig } from '../utils/decimal.js'
71
84
  import {
72
85
  assetIsOutcome,
73
86
  decodeCompressedJson,
@@ -87,6 +100,7 @@ import {
87
100
  spotPriceById,
88
101
  sumUnrealizedPnl,
89
102
  } from '../utils/index.js'
103
+ import { mapOrderRow } from '../utils/mapOrder.js'
90
104
 
91
105
  /** HL's compact `l2` snapshot carries 20 levels per side. */
92
106
  const HL_L2_BOOK_MAX_LEVELS_PER_SIDE = 20
@@ -604,10 +618,15 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
604
618
  if (priceStep === undefined) {
605
619
  return {}
606
620
  }
607
- return priceStepToAggregation(
608
- priceStep,
609
- this.orderbookReferencePrice(marketId)
610
- )
621
+ const referencePrice = this.orderbookReferencePrice(marketId)
622
+ const referencePriceNumber =
623
+ referencePrice === undefined
624
+ ? undefined
625
+ : safeDecimalStringToNumber(referencePrice)
626
+ if (referencePriceNumber === undefined) {
627
+ return {}
628
+ }
629
+ return priceStepToAggregation(priceStep, referencePriceNumber)
611
630
  }
612
631
 
613
632
  private orderbookAggregationKey(
@@ -954,30 +973,31 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
954
973
  }
955
974
 
956
975
  /** Latest mid per `Market.id` across asset-context and fast feeds. */
957
- private mergedMids(): Map<string, number> {
958
- const map = new Map<string, number>()
976
+ /** Latest mid per `Market.id` across asset-context and fast feeds; a mid
977
+ * that does not match the decimal pattern is left out. */
978
+ private mergedMids(): Map<string, DecimalString> {
979
+ const map = new Map<string, DecimalString>()
980
+ const setMid = (id: string, mid: string | number | null | undefined) => {
981
+ const decimal = mid == null ? undefined : wsFigureToDecimalString(mid)
982
+ if (isDecimalString(decimal)) {
983
+ map.set(id, decimal)
984
+ }
985
+ }
959
986
  for (const byMarketId of this.perpCtxBySubDex.values()) {
960
987
  for (const [id, ctx] of Object.entries(byMarketId)) {
961
- const mid = ctx.midPx ?? ctx.markPx
962
- map.set(id, Number(mid))
988
+ setMid(id, ctx.midPx ?? ctx.markPx)
963
989
  }
964
990
  }
965
991
  for (const [id, ctx] of Object.entries(this.spotCtxByMarketId)) {
966
- const mid = ctx.midPx ?? ctx.markPx
967
- if (mid != null) {
968
- map.set(id, Number(mid))
969
- }
992
+ setMid(id, ctx.midPx ?? ctx.markPx)
970
993
  }
971
994
  for (const [id, fast] of Object.entries(this.fastCtxByMarketId)) {
972
- const mid = fast.midPx ?? fast.markPx
973
- if (mid != null) {
974
- map.set(id, Number(mid))
975
- }
995
+ setMid(id, fast.midPx ?? fast.markPx)
976
996
  }
977
997
  return map
978
998
  }
979
999
 
980
- private orderbookReferencePrice(marketId: string): number {
1000
+ private orderbookReferencePrice(marketId: string): DecimalString | undefined {
981
1001
  const mid = this.mergedMids().get(marketId)
982
1002
  if (mid !== undefined) {
983
1003
  return mid
@@ -986,11 +1006,11 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
986
1006
  const book = this.latestOrderbookByMarketId.get(marketId)
987
1007
  const bid = book?.bids[0]?.price
988
1008
  const ask = book?.asks[0]?.price
989
- if (bid !== undefined && ask !== undefined) {
990
- return (Number(bid) + Number(ask)) / 2
1009
+ if (bid === undefined || ask === undefined) {
1010
+ return undefined
991
1011
  }
992
-
993
- return Number.NaN
1012
+ const sum = safeAddDecimalString(bid, ask)
1013
+ return sum === undefined ? undefined : safeDivideDecimalString(sum, '2')
994
1014
  }
995
1015
 
996
1016
  private handleL2Book(data: HlWsL2BookData) {
@@ -998,11 +1018,11 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
998
1018
  provider: this.providerKey,
999
1019
  marketId: data.coin,
1000
1020
  bids: data.levels[0]
1001
- .slice(0, HL_L2_BOOK_MAX_LEVELS_PER_SIDE)
1002
- .map((l) => ({ price: l.px, size: l.sz })),
1021
+ .flatMap((l) => toOrderbookLevel(data.coin, l.px, l.sz))
1022
+ .slice(0, HL_L2_BOOK_MAX_LEVELS_PER_SIDE),
1003
1023
  asks: data.levels[1]
1004
- .slice(0, HL_L2_BOOK_MAX_LEVELS_PER_SIDE)
1005
- .map((l) => ({ price: l.px, size: l.sz })),
1024
+ .flatMap((l) => toOrderbookLevel(data.coin, l.px, l.sz))
1025
+ .slice(0, HL_L2_BOOK_MAX_LEVELS_PER_SIDE),
1006
1026
  timestamp: data.time,
1007
1027
  }
1008
1028
  this.latestOrderbookByMarketId.set(data.coin, book)
@@ -1045,12 +1065,14 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
1045
1065
  provider: this.providerKey,
1046
1066
  marketId: delta.c,
1047
1067
  bids: applyCompressedL2Side(
1068
+ delta.c,
1048
1069
  previous.bids,
1049
1070
  delta.l[0],
1050
1071
  delta.r?.[0] ?? [],
1051
1072
  'bid'
1052
1073
  ),
1053
1074
  asks: applyCompressedL2Side(
1075
+ delta.c,
1054
1076
  previous.asks,
1055
1077
  delta.l[1],
1056
1078
  delta.r?.[1] ?? [],
@@ -1122,48 +1144,33 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
1122
1144
  if (epoch !== this.orderUpdatesEpoch || key !== this.orderUpdatesKey) {
1123
1145
  return
1124
1146
  }
1147
+ const user = key.slice('orderUpdates:'.length)
1125
1148
  const mapped = await Promise.all(
1126
1149
  data.map(async (update) => {
1127
1150
  const basic = update.order
1128
- if (assetIsOutcome(basic.coin)) {
1151
+ if (
1152
+ assetIsOutcome(basic.coin) ||
1153
+ this.registry?.get(basic.coin) === undefined
1154
+ ) {
1129
1155
  return undefined
1130
1156
  }
1131
- const market = this.registry?.get(basic.coin)
1132
- if (market === undefined) {
1157
+ let detail: HlOrderDetail
1158
+ try {
1159
+ detail = await this.readOrderDetail(user, client, update)
1160
+ } catch (error) {
1161
+ if (!(error instanceof PerpsError)) {
1162
+ throw error
1163
+ }
1164
+ wsLog.droppedRow(
1165
+ this.providerKey,
1166
+ 'order',
1167
+ `${basic.oid}: ${error.message}`
1168
+ )
1133
1169
  return undefined
1134
1170
  }
1135
- const response = await infoRequest<HlOrderStatusResponse>(
1136
- this.orderApiUrl,
1137
- {
1138
- type: 'orderStatus',
1139
- user: key.slice('orderUpdates:'.length),
1140
- oid: basic.oid,
1141
- },
1142
- hlInfoOptions(client)
1171
+ return mapOrderRow(basic.coin, this.registry, (resolved) =>
1172
+ mapOrder(detail, resolved)
1143
1173
  )
1144
- if (response.status !== 'order') {
1145
- throw new PerpsError(
1146
- PerpsErrorCode.OrderNotFound,
1147
- `Hyperliquid order metadata not found: ${basic.oid}`
1148
- )
1149
- }
1150
- // REST supplies execution metadata; the stream owns this event's lifecycle and quantities.
1151
- const detail: HlOrderDetail = {
1152
- status: update.status,
1153
- statusTimestamp: update.statusTimestamp,
1154
- order: {
1155
- ...response.order.order,
1156
- coin: basic.coin,
1157
- side: basic.side,
1158
- limitPx: basic.limitPx,
1159
- sz: basic.sz,
1160
- oid: basic.oid,
1161
- timestamp: basic.timestamp,
1162
- origSz: basic.origSz,
1163
- cloid: basic.cloid ?? response.order.order.cloid,
1164
- },
1165
- }
1166
- return mapOrder(detail, market)
1167
1174
  })
1168
1175
  )
1169
1176
  if (epoch !== this.orderUpdatesEpoch || key !== this.orderUpdatesKey) {
@@ -1184,6 +1191,41 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
1184
1191
  })
1185
1192
  }
1186
1193
 
1194
+ // REST supplies execution metadata; the stream owns this event's lifecycle and quantities.
1195
+ private async readOrderDetail(
1196
+ user: string,
1197
+ client: PerpsSDKClient,
1198
+ update: HlWsOrder
1199
+ ): Promise<HlOrderDetail> {
1200
+ const basic = update.order
1201
+ const response = await infoRequest<HlOrderStatusResponse>(
1202
+ this.orderApiUrl,
1203
+ { type: 'orderStatus', user, oid: basic.oid },
1204
+ hlInfoOptions(client)
1205
+ )
1206
+ if (response.status !== 'order') {
1207
+ throw new PerpsError(
1208
+ PerpsErrorCode.OrderNotFound,
1209
+ `Hyperliquid order metadata not found: ${basic.oid}`
1210
+ )
1211
+ }
1212
+ return {
1213
+ status: update.status,
1214
+ statusTimestamp: update.statusTimestamp,
1215
+ order: {
1216
+ ...response.order.order,
1217
+ coin: basic.coin,
1218
+ side: basic.side,
1219
+ limitPx: basic.limitPx,
1220
+ sz: basic.sz,
1221
+ oid: basic.oid,
1222
+ timestamp: basic.timestamp,
1223
+ origSz: basic.origSz,
1224
+ cloid: basic.cloid ?? response.order.order.cloid,
1225
+ },
1226
+ }
1227
+ }
1228
+
1187
1229
  private handleUserFills(data: HlWsUserFillsData) {
1188
1230
  // The snapshot frame carries up to ~2000 historical fills and is replayed
1189
1231
  // on every reconnect via `replaySubs`; emitting them would surface old
@@ -1197,7 +1239,8 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
1197
1239
  return []
1198
1240
  }
1199
1241
  const market = this.registry?.get(f.coin)
1200
- return market ? [mapFill(f as HlUserFill, market)] : []
1242
+ const mapped = market && mapFill(f as HlUserFill, market)
1243
+ return mapped ? [mapped] : []
1201
1244
  })
1202
1245
  this.emit(`userFills:${data.user.toLowerCase()}`, {
1203
1246
  channel: 'fills',
@@ -1217,9 +1260,11 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
1217
1260
  return []
1218
1261
  }
1219
1262
  const market = this.registry?.get(ap.position.coin)
1220
- return market
1221
- ? [mapPosition(ap as HlAssetPosition, toPerpsMarketDisplay(market))]
1222
- : []
1263
+ const position =
1264
+ market === undefined
1265
+ ? undefined
1266
+ : mapPosition(ap as HlAssetPosition, toPerpsMarketDisplay(market))
1267
+ return position === undefined ? [] : [position]
1223
1268
  })
1224
1269
  )
1225
1270
  this.emit(`positions:${data.user.toLowerCase()}`, {
@@ -1232,10 +1277,7 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
1232
1277
  )
1233
1278
 
1234
1279
  const key = data.user.toLowerCase()
1235
- this.latestPerpsByUser.set(key, {
1236
- positions,
1237
- marginUsed: marginUsed.toFixed(),
1238
- })
1280
+ this.latestPerpsByUser.set(key, { positions, marginUsed })
1239
1281
  this.emitUnifiedSummary(key)
1240
1282
 
1241
1283
  // Equity semantics, matching the REST summary: `accountValue` already
@@ -1243,10 +1285,10 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
1243
1285
  // so this portfolio value covers perps equity only — which is why the
1244
1286
  // frame is gated on the abstraction mode below.
1245
1287
  this.emitSummaryIfModeAllows(data.user, {
1246
- portfolioValue: accountValue.toFixed(),
1247
- availableMargin: accountValue.minus(marginUsed).toFixed(),
1248
- marginUsed: marginUsed.toFixed(),
1249
- unrealizedPnl: sumUnrealizedPnl(positions).toFixed(),
1288
+ portfolioValue: accountValue,
1289
+ availableMargin: subtractDecimalString(accountValue, marginUsed),
1290
+ marginUsed,
1291
+ unrealizedPnl: sumUnrealizedPnl(positions),
1250
1292
  })
1251
1293
  }
1252
1294
 
@@ -1353,16 +1395,23 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
1353
1395
  ...pipeline.spot.balances,
1354
1396
  ].reduce(
1355
1397
  (sum, balance) =>
1356
- sum.plus(toWireBig(balance.valueUsd, 'spotBalance.valueUsd')),
1357
- new Big(0)
1398
+ addDecimalString(
1399
+ sum,
1400
+ unknownToDecimalString(
1401
+ balance.valueUsd,
1402
+ 'spotBalance.valueUsd',
1403
+ this.providerKey
1404
+ )
1405
+ ),
1406
+ '0'
1358
1407
  )
1359
1408
  this.emit(`accountSummary:${key}`, {
1360
1409
  channel: 'accountSummary',
1361
1410
  data: {
1362
- portfolioValue: portfolioValue.toFixed(),
1411
+ portfolioValue,
1363
1412
  availableMargin: pipeline.availableMargin,
1364
1413
  marginUsed: perps.marginUsed,
1365
- unrealizedPnl: sumUnrealizedPnl(perps.positions).toFixed(),
1414
+ unrealizedPnl: sumUnrealizedPnl(perps.positions),
1366
1415
  },
1367
1416
  })
1368
1417
  }
@@ -1524,32 +1573,32 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
1524
1573
  }
1525
1574
  const markets = this.registry?.activeMarkets ?? []
1526
1575
  const priceById = spotPriceById(markets, this.mergedMids())
1527
- const balances = data.spotState.balances.filter(
1528
- (balance) =>
1529
- !assetIsOutcome(balance.coin) &&
1530
- toWireBig(balance.total, 'spotState.balances.total').gt(0)
1531
- )
1576
+ const balances = data.spotState.balances
1577
+ .filter((balance) => !assetIsOutcome(balance.coin))
1578
+ .filter(
1579
+ (balance) => safeIsDecimalStringGreaterThan(balance.total, '0') === true
1580
+ )
1581
+ .map((balance) => ({ balance, total: balance.total }))
1532
1582
  const pipeline = this.unifiedSummaryByUser.get(user)
1533
1583
  // Known spot markets await a price; unlisted tokens keep their unpriced balance.
1534
1584
  if (
1535
- balances.some((balance) => priceById.get(String(balance.token)) === 0)
1585
+ balances.some(({ balance }) => {
1586
+ const price = priceById.get(String(balance.token))
1587
+ return price !== undefined && isDecimalStringZero(price)
1588
+ })
1536
1589
  ) {
1537
1590
  if (pipeline !== undefined) {
1538
1591
  pipeline.spot = undefined
1539
1592
  }
1540
1593
  return
1541
1594
  }
1542
- const rows = balances.map((balance) => {
1543
- const total = toWireBig(balance.total, 'spotState.balances.total')
1595
+ const rows = balances.map(({ balance, total }) => {
1596
+ const free = safeSubtractDecimalString(total, balance.hold)
1544
1597
  return {
1545
- ...spotBalance(spotAssetFromToken(balance), balance.total, priceById),
1598
+ ...spotBalance(spotAssetFromToken(balance), total, priceById),
1546
1599
  locked: balance.hold,
1547
- transferable: calculateTransferable(
1548
- total
1549
- .minus(toWireBig(balance.hold, 'spotState.balances.hold'))
1550
- .toFixed(),
1551
- total.toFixed()
1552
- ),
1600
+ transferable:
1601
+ free === undefined ? '0' : calculateTransferable(free, total),
1553
1602
  }
1554
1603
  })
1555
1604
  this.emit(`spotState:${user}`, {
@@ -1609,33 +1658,31 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
1609
1658
  const isObject = (v: unknown): v is Record<string, unknown> =>
1610
1659
  typeof v === 'object' && v !== null
1611
1660
 
1612
- const toMarketContextString = (value: unknown): string | undefined => {
1613
- if (typeof value === 'number') {
1614
- return numberToDecimalString(value)
1615
- }
1616
- return typeof value === 'string' ? value : undefined
1661
+ /** A WebSocket figure as a string; a venue number is spelled as a decimal
1662
+ * string, and a non-finite number gives `undefined`. */
1663
+ function wsFigureToDecimalString(value: string | number): string | undefined {
1664
+ return typeof value === 'number' ? safeNumberToDecimalString(value) : value
1665
+ }
1666
+
1667
+ function optionalWsFigureToDecimalString(
1668
+ value: string | number | null | undefined
1669
+ ): string | undefined {
1670
+ return value == null ? undefined : wsFigureToDecimalString(value)
1617
1671
  }
1618
1672
 
1619
1673
  const toMarketCapString = (
1620
- price: unknown,
1621
- circulatingSupply: unknown
1674
+ price: string,
1675
+ circulatingSupply: string | number | undefined
1622
1676
  ): string | undefined => {
1623
- const priceString = toMarketContextString(price)
1624
- const supplyString = toMarketContextString(circulatingSupply)
1625
- if (priceString === undefined || supplyString === undefined) {
1626
- return undefined
1627
- }
1628
-
1629
- try {
1630
- const parsedPrice = new Big(priceString)
1631
- const parsedSupply = new Big(supplyString)
1632
- if (parsedPrice.lte(0) || parsedSupply.lte(0)) {
1633
- return undefined
1634
- }
1635
- return parsedPrice.times(parsedSupply).toFixed()
1636
- } catch {
1677
+ const supply = optionalWsFigureToDecimalString(circulatingSupply)
1678
+ if (
1679
+ supply === undefined ||
1680
+ safeIsDecimalStringGreaterThan(price, '0') !== true ||
1681
+ safeIsDecimalStringGreaterThan(supply, '0') !== true
1682
+ ) {
1637
1683
  return undefined
1638
1684
  }
1685
+ return safeMultiplyDecimalString(price, supply)
1639
1686
  }
1640
1687
 
1641
1688
  function mergePerpAssetCtx(
@@ -1685,16 +1732,13 @@ function activePerpAssetCtx(
1685
1732
  marketId: string,
1686
1733
  ctx: HlWsActiveAssetCtxData['ctx']
1687
1734
  ): HlWsPerpAssetCtx | undefined {
1688
- const funding = toMarketContextString(ctx.funding)
1689
- const openInterest = toMarketContextString(ctx.openInterest)
1690
- const dayNtlVlm = toMarketContextString(ctx.dayNtlVlm)
1691
- const prevDayPx = toMarketContextString(ctx.prevDayPx)
1692
- const markPx = toMarketContextString(ctx.markPx)
1693
- const midPx =
1694
- ctx.midPx === undefined || ctx.midPx === null
1695
- ? null
1696
- : (toMarketContextString(ctx.midPx) ?? null)
1697
- const oraclePx = toMarketContextString(ctx.oraclePx)
1735
+ const funding = optionalWsFigureToDecimalString(ctx.funding)
1736
+ const openInterest = optionalWsFigureToDecimalString(ctx.openInterest)
1737
+ const dayNtlVlm = optionalWsFigureToDecimalString(ctx.dayNtlVlm)
1738
+ const prevDayPx = optionalWsFigureToDecimalString(ctx.prevDayPx)
1739
+ const markPx = optionalWsFigureToDecimalString(ctx.markPx)
1740
+ const midPx = optionalWsFigureToDecimalString(ctx.midPx) ?? null
1741
+ const oraclePx = optionalWsFigureToDecimalString(ctx.oraclePx)
1698
1742
 
1699
1743
  if (
1700
1744
  funding === undefined ||
@@ -1724,8 +1768,8 @@ function mapSpotMarketContext(
1724
1768
  ctx: HlWsSpotAssetCtx,
1725
1769
  fast?: HlWsFastAssetCtx
1726
1770
  ): MarketContext | undefined {
1727
- const midPrice = toMarketContextString(ctx.midPx ?? ctx.markPx)
1728
- const markPrice = toMarketContextString(ctx.markPx)
1771
+ const midPrice = optionalWsFigureToDecimalString(ctx.midPx ?? ctx.markPx)
1772
+ const markPrice = optionalWsFigureToDecimalString(ctx.markPx)
1729
1773
  if (midPrice === undefined || markPrice === undefined) {
1730
1774
  return undefined
1731
1775
  }
@@ -1735,12 +1779,52 @@ function mapSpotMarketContext(
1735
1779
  marketId,
1736
1780
  midPrice: fast?.midPx != null ? fast.midPx : midPrice,
1737
1781
  markPrice: emittedMarkPrice,
1738
- prevDayPrice: toMarketContextString(ctx.prevDayPx),
1739
- volume24h: toMarketContextString(ctx.dayNtlVlm),
1782
+ prevDayPrice: optionalWsFigureToDecimalString(ctx.prevDayPx),
1783
+ volume24h: optionalWsFigureToDecimalString(ctx.dayNtlVlm),
1740
1784
  marketCap: toMarketCapString(emittedMarkPrice, ctx.circulatingSupply),
1741
1785
  }
1742
1786
  }
1743
1787
 
1788
+ const BOOK_LEVEL_ROW = 'order book level'
1789
+
1790
+ /** The venue price when it is a decimal string, or `undefined` after a logged skip. */
1791
+ function bookLevelPrice(
1792
+ marketId: string,
1793
+ price: string
1794
+ ): DecimalString | undefined {
1795
+ if (!isDecimalString(price)) {
1796
+ wsLog.skippedRow(PROVIDER_KEY, BOOK_LEVEL_ROW, 'price', price, marketId)
1797
+ return undefined
1798
+ }
1799
+ return price
1800
+ }
1801
+
1802
+ /** The venue size when it is a decimal string, or `undefined` after a logged skip. */
1803
+ function bookLevelSize(
1804
+ marketId: string,
1805
+ size: string
1806
+ ): DecimalString | undefined {
1807
+ if (!isDecimalString(size)) {
1808
+ wsLog.skippedRow(PROVIDER_KEY, BOOK_LEVEL_ROW, 'size', size, marketId)
1809
+ return undefined
1810
+ }
1811
+ return size
1812
+ }
1813
+
1814
+ /** One order-book level, or none when the venue price or size is invalid. */
1815
+ function toOrderbookLevel(
1816
+ marketId: string,
1817
+ price: string,
1818
+ size: string
1819
+ ): OrderbookLevel[] {
1820
+ const levelPrice = bookLevelPrice(marketId, price)
1821
+ const levelSize =
1822
+ levelPrice === undefined ? undefined : bookLevelSize(marketId, size)
1823
+ return levelPrice === undefined || levelSize === undefined
1824
+ ? []
1825
+ : [{ price: levelPrice, size: levelSize }]
1826
+ }
1827
+
1744
1828
  function compactRemovalPrice(
1745
1829
  levels: OrderbookLevel[],
1746
1830
  value: number | string | { p: string }
@@ -1752,6 +1836,7 @@ function compactRemovalPrice(
1752
1836
  }
1753
1837
 
1754
1838
  function applyCompressedL2Side(
1839
+ marketId: string,
1755
1840
  previous: OrderbookLevel[],
1756
1841
  updates: HlWsCompressedL2Data['l'][number],
1757
1842
  removals: NonNullable<HlWsCompressedL2Data['r']>[number],
@@ -1765,10 +1850,16 @@ function applyCompressedL2Side(
1765
1850
  }
1766
1851
  }
1767
1852
  for (const update of updates) {
1768
- if (Number(update.s) === 0) {
1769
- byPrice.delete(update.p)
1853
+ const price = bookLevelPrice(marketId, update.p)
1854
+ if (price === undefined) {
1855
+ continue
1856
+ }
1857
+ const size = bookLevelSize(marketId, update.s)
1858
+ // A level whose new size is unknown must not keep its old size.
1859
+ if (size === undefined || safeIsDecimalStringZero(size) !== false) {
1860
+ byPrice.delete(price)
1770
1861
  } else {
1771
- byPrice.set(update.p, update.s)
1862
+ byPrice.set(price, size)
1772
1863
  }
1773
1864
  }
1774
1865
 
@@ -1776,8 +1867,8 @@ function applyCompressedL2Side(
1776
1867
  .map(([price, size]) => ({ price, size }))
1777
1868
  .sort((a, b) =>
1778
1869
  side === 'bid'
1779
- ? Number(b.price) - Number(a.price)
1780
- : Number(a.price) - Number(b.price)
1870
+ ? compareDecimalStrings(b.price, a.price)
1871
+ : compareDecimalStrings(a.price, b.price)
1781
1872
  )
1782
1873
  .slice(0, HL_L2_BOOK_MAX_LEVELS_PER_SIDE)
1783
1874
  }
@@ -1,3 +0,0 @@
1
- import Big from 'big.js';
2
- export declare const toWireBig: (value: string, field: string) => Big;
3
- //# sourceMappingURL=decimal.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../../src/utils/decimal.ts"],"names":[],"mappings":"AAEA,OAAO,GAAG,MAAM,QAAQ,CAAA;AASxB,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,EAAE,OAAO,MAAM,KAAG,GASxD,CAAA"}
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.toWireBig = void 0;
7
- const perps_sdk_1 = require("@lifi/perps-sdk");
8
- const perps_types_1 = require("@lifi/perps-types");
9
- const big_js_1 = __importDefault(require("big.js"));
10
- const toWireBig = (value, field) => {
11
- try {
12
- return new big_js_1.default(value);
13
- }
14
- catch {
15
- throw new perps_sdk_1.PerpsError(perps_types_1.PerpsErrorCode.SDKError, `Hyperliquid field \`${field}\` is not a valid decimal: '${value}'`);
16
- }
17
- };
18
- exports.toWireBig = toWireBig;
19
- //# sourceMappingURL=decimal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decimal.js","sourceRoot":"","sources":["../../../src/utils/decimal.ts"],"names":[],"mappings":";;;;;;AAAA,+CAA4C;AAC5C,mDAAkD;AAClD,oDAAwB;AASjB,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,KAAa,EAAO,EAAE;IAC7D,IAAI,CAAC;QACH,OAAO,IAAI,gBAAG,CAAC,KAAK,CAAC,CAAA;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,sBAAU,CAClB,4BAAc,CAAC,QAAQ,EACvB,uBAAuB,KAAK,+BAA+B,KAAK,GAAG,CACpE,CAAA;IACH,CAAC;AACH,CAAC,CAAA;AATY,QAAA,SAAS,aASrB"}
@@ -1,10 +0,0 @@
1
- import Big from 'big.js';
2
- /**
3
- * Exact-decimal parse of a Hyperliquid wire decimal string. `field` names the
4
- * offending field on failure, so a venue contract breach is diagnosable
5
- * instead of surfacing as an anonymous big.js throw or an `NaN` unit.
6
- *
7
- * @throws {PerpsError} `SDKError` when `value` is not a decimal numeric string.
8
- */
9
- export declare const toWireBig: (value: string, field: string) => Big;
10
- //# sourceMappingURL=decimal.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../../src/utils/decimal.ts"],"names":[],"mappings":"AAEA,OAAO,GAAG,MAAM,QAAQ,CAAA;AAExB;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,EAAE,OAAO,MAAM,KAAG,GASxD,CAAA"}
@@ -1,19 +0,0 @@
1
- import { PerpsError } from '@lifi/perps-sdk';
2
- import { PerpsErrorCode } from '@lifi/perps-types';
3
- import Big from 'big.js';
4
- /**
5
- * Exact-decimal parse of a Hyperliquid wire decimal string. `field` names the
6
- * offending field on failure, so a venue contract breach is diagnosable
7
- * instead of surfacing as an anonymous big.js throw or an `NaN` unit.
8
- *
9
- * @throws {PerpsError} `SDKError` when `value` is not a decimal numeric string.
10
- */
11
- export const toWireBig = (value, field) => {
12
- try {
13
- return new Big(value);
14
- }
15
- catch {
16
- throw new PerpsError(PerpsErrorCode.SDKError, `Hyperliquid field \`${field}\` is not a valid decimal: '${value}'`);
17
- }
18
- };
19
- //# sourceMappingURL=decimal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decimal.js","sourceRoot":"","sources":["../../../src/utils/decimal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,GAAG,MAAM,QAAQ,CAAA;AAExB;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,KAAa,EAAO,EAAE;IAC7D,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAA;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,UAAU,CAClB,cAAc,CAAC,QAAQ,EACvB,uBAAuB,KAAK,+BAA+B,KAAK,GAAG,CACpE,CAAA;IACH,CAAC;AACH,CAAC,CAAA"}
@@ -1,10 +0,0 @@
1
- import Big from 'big.js';
2
- /**
3
- * Exact-decimal parse of a Hyperliquid wire decimal string. `field` names the
4
- * offending field on failure, so a venue contract breach is diagnosable
5
- * instead of surfacing as an anonymous big.js throw or an `NaN` unit.
6
- *
7
- * @throws {PerpsError} `SDKError` when `value` is not a decimal numeric string.
8
- */
9
- export declare const toWireBig: (value: string, field: string) => Big;
10
- //# sourceMappingURL=decimal.d.ts.map