@lifi/perps-sdk-provider-hyperliquid 25.0.0 → 26.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 (233) 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 +19 -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 +3 -1
  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 +15 -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/liquidation.d.ts +1 -1
  28. package/dist/cjs/utils/liquidation.d.ts.map +1 -1
  29. package/dist/cjs/utils/liquidation.js +3 -4
  30. package/dist/cjs/utils/liquidation.js.map +1 -1
  31. package/dist/cjs/utils/mapActivity.d.ts.map +1 -1
  32. package/dist/cjs/utils/mapActivity.js +32 -23
  33. package/dist/cjs/utils/mapActivity.js.map +1 -1
  34. package/dist/cjs/utils/mapFill.d.ts +1 -1
  35. package/dist/cjs/utils/mapFill.d.ts.map +1 -1
  36. package/dist/cjs/utils/mapFill.js +14 -6
  37. package/dist/cjs/utils/mapFill.js.map +1 -1
  38. package/dist/cjs/utils/mapMarket.d.ts.map +1 -1
  39. package/dist/cjs/utils/mapMarket.js +8 -12
  40. package/dist/cjs/utils/mapMarket.js.map +1 -1
  41. package/dist/cjs/utils/mapMarketContext.d.ts.map +1 -1
  42. package/dist/cjs/utils/mapMarketContext.js +3 -12
  43. package/dist/cjs/utils/mapMarketContext.js.map +1 -1
  44. package/dist/cjs/utils/mapOrder.d.ts +1 -1
  45. package/dist/cjs/utils/mapOrder.d.ts.map +1 -1
  46. package/dist/cjs/utils/mapOrder.js +60 -18
  47. package/dist/cjs/utils/mapOrder.js.map +1 -1
  48. package/dist/cjs/utils/mapPosition.d.ts +1 -1
  49. package/dist/cjs/utils/mapPosition.d.ts.map +1 -1
  50. package/dist/cjs/utils/mapPosition.js +40 -14
  51. package/dist/cjs/utils/mapPosition.js.map +1 -1
  52. package/dist/cjs/utils/rowTimestamp.d.ts +2 -0
  53. package/dist/cjs/utils/rowTimestamp.d.ts.map +1 -0
  54. package/dist/cjs/utils/rowTimestamp.js +14 -0
  55. package/dist/cjs/utils/rowTimestamp.js.map +1 -0
  56. package/dist/cjs/utils/spotBalance.d.ts +3 -3
  57. package/dist/cjs/utils/spotBalance.d.ts.map +1 -1
  58. package/dist/cjs/utils/spotBalance.js +6 -5
  59. package/dist/cjs/utils/spotBalance.js.map +1 -1
  60. package/dist/cjs/utils/spotCollateral.d.ts.map +1 -1
  61. package/dist/cjs/utils/spotCollateral.js +3 -2
  62. package/dist/cjs/utils/spotCollateral.js.map +1 -1
  63. package/dist/cjs/utils/transferMargin.d.ts.map +1 -1
  64. package/dist/cjs/utils/transferMargin.js +16 -19
  65. package/dist/cjs/utils/transferMargin.js.map +1 -1
  66. package/dist/cjs/utils/venueTotals.d.ts +5 -5
  67. package/dist/cjs/utils/venueTotals.d.ts.map +1 -1
  68. package/dist/cjs/utils/venueTotals.js +10 -11
  69. package/dist/cjs/utils/venueTotals.js.map +1 -1
  70. package/dist/cjs/utils/withdrawableBalances.d.ts.map +1 -1
  71. package/dist/cjs/utils/withdrawableBalances.js +10 -10
  72. package/dist/cjs/utils/withdrawableBalances.js.map +1 -1
  73. package/dist/cjs/websocket/HyperliquidWsProvider.d.ts.map +1 -1
  74. package/dist/cjs/websocket/HyperliquidWsProvider.js +109 -89
  75. package/dist/cjs/websocket/HyperliquidWsProvider.js.map +1 -1
  76. package/dist/esm/accountSummary.d.ts +2 -1
  77. package/dist/esm/accountSummary.d.ts.map +1 -1
  78. package/dist/esm/accountSummary.js +11 -13
  79. package/dist/esm/accountSummary.js.map +1 -1
  80. package/dist/esm/services/getAccount.d.ts.map +1 -1
  81. package/dist/esm/services/getAccount.js +24 -21
  82. package/dist/esm/services/getAccount.js.map +1 -1
  83. package/dist/esm/services/getFills.d.ts.map +1 -1
  84. package/dist/esm/services/getFills.js +2 -1
  85. package/dist/esm/services/getFills.js.map +1 -1
  86. package/dist/esm/services/getMarketSettings.d.ts.map +1 -1
  87. package/dist/esm/services/getMarketSettings.js +2 -2
  88. package/dist/esm/services/getMarketSettings.js.map +1 -1
  89. package/dist/esm/services/getOrder.d.ts.map +1 -1
  90. package/dist/esm/services/getOrder.js +14 -4
  91. package/dist/esm/services/getOrder.js.map +1 -1
  92. package/dist/esm/services/getOrders.d.ts.map +1 -1
  93. package/dist/esm/services/getOrders.js +5 -2
  94. package/dist/esm/services/getOrders.js.map +1 -1
  95. package/dist/esm/services/getPortfolioHistory.d.ts.map +1 -1
  96. package/dist/esm/services/getPortfolioHistory.js +17 -7
  97. package/dist/esm/services/getPortfolioHistory.js.map +1 -1
  98. package/dist/esm/services/getPositions.d.ts.map +1 -1
  99. package/dist/esm/services/getPositions.js +4 -1
  100. package/dist/esm/services/getPositions.js.map +1 -1
  101. package/dist/esm/services/getWithdrawableBalances.d.ts +1 -1
  102. package/dist/esm/services/getWithdrawableBalances.js +1 -1
  103. package/dist/esm/types/ws.d.ts +3 -2
  104. package/dist/esm/types/ws.d.ts.map +1 -1
  105. package/dist/esm/utils/liquidation.d.ts +1 -1
  106. package/dist/esm/utils/liquidation.d.ts.map +1 -1
  107. package/dist/esm/utils/liquidation.js +4 -5
  108. package/dist/esm/utils/liquidation.js.map +1 -1
  109. package/dist/esm/utils/mapActivity.d.ts +2 -1
  110. package/dist/esm/utils/mapActivity.d.ts.map +1 -1
  111. package/dist/esm/utils/mapActivity.js +35 -22
  112. package/dist/esm/utils/mapActivity.js.map +1 -1
  113. package/dist/esm/utils/mapFill.d.ts +3 -2
  114. package/dist/esm/utils/mapFill.d.ts.map +1 -1
  115. package/dist/esm/utils/mapFill.js +18 -9
  116. package/dist/esm/utils/mapFill.js.map +1 -1
  117. package/dist/esm/utils/mapMarket.d.ts +2 -2
  118. package/dist/esm/utils/mapMarket.d.ts.map +1 -1
  119. package/dist/esm/utils/mapMarket.js +10 -11
  120. package/dist/esm/utils/mapMarket.js.map +1 -1
  121. package/dist/esm/utils/mapMarketContext.d.ts.map +1 -1
  122. package/dist/esm/utils/mapMarketContext.js +3 -9
  123. package/dist/esm/utils/mapMarketContext.js.map +1 -1
  124. package/dist/esm/utils/mapOrder.d.ts +5 -2
  125. package/dist/esm/utils/mapOrder.d.ts.map +1 -1
  126. package/dist/esm/utils/mapOrder.js +65 -17
  127. package/dist/esm/utils/mapOrder.js.map +1 -1
  128. package/dist/esm/utils/mapPosition.d.ts +4 -2
  129. package/dist/esm/utils/mapPosition.d.ts.map +1 -1
  130. package/dist/esm/utils/mapPosition.js +43 -12
  131. package/dist/esm/utils/mapPosition.js.map +1 -1
  132. package/dist/esm/utils/rowTimestamp.d.ts +6 -0
  133. package/dist/esm/utils/rowTimestamp.d.ts.map +1 -0
  134. package/dist/esm/utils/rowTimestamp.js +14 -0
  135. package/dist/esm/utils/rowTimestamp.js.map +1 -0
  136. package/dist/esm/utils/spotBalance.d.ts +5 -5
  137. package/dist/esm/utils/spotBalance.d.ts.map +1 -1
  138. package/dist/esm/utils/spotBalance.js +9 -8
  139. package/dist/esm/utils/spotBalance.js.map +1 -1
  140. package/dist/esm/utils/spotCollateral.d.ts.map +1 -1
  141. package/dist/esm/utils/spotCollateral.js +3 -2
  142. package/dist/esm/utils/spotCollateral.js.map +1 -1
  143. package/dist/esm/utils/transferMargin.d.ts +2 -1
  144. package/dist/esm/utils/transferMargin.d.ts.map +1 -1
  145. package/dist/esm/utils/transferMargin.js +19 -18
  146. package/dist/esm/utils/transferMargin.js.map +1 -1
  147. package/dist/esm/utils/venueTotals.d.ts +10 -5
  148. package/dist/esm/utils/venueTotals.d.ts.map +1 -1
  149. package/dist/esm/utils/venueTotals.js +13 -7
  150. package/dist/esm/utils/venueTotals.js.map +1 -1
  151. package/dist/esm/utils/withdrawableBalances.d.ts +6 -4
  152. package/dist/esm/utils/withdrawableBalances.d.ts.map +1 -1
  153. package/dist/esm/utils/withdrawableBalances.js +17 -15
  154. package/dist/esm/utils/withdrawableBalances.js.map +1 -1
  155. package/dist/esm/websocket/HyperliquidWsProvider.d.ts +2 -0
  156. package/dist/esm/websocket/HyperliquidWsProvider.d.ts.map +1 -1
  157. package/dist/esm/websocket/HyperliquidWsProvider.js +119 -88
  158. package/dist/esm/websocket/HyperliquidWsProvider.js.map +1 -1
  159. package/dist/types/accountSummary.d.ts +2 -1
  160. package/dist/types/accountSummary.d.ts.map +1 -1
  161. package/dist/types/services/getAccount.d.ts.map +1 -1
  162. package/dist/types/services/getFills.d.ts.map +1 -1
  163. package/dist/types/services/getMarketSettings.d.ts.map +1 -1
  164. package/dist/types/services/getOrder.d.ts.map +1 -1
  165. package/dist/types/services/getOrders.d.ts.map +1 -1
  166. package/dist/types/services/getPortfolioHistory.d.ts.map +1 -1
  167. package/dist/types/services/getPositions.d.ts.map +1 -1
  168. package/dist/types/services/getWithdrawableBalances.d.ts +1 -1
  169. package/dist/types/types/ws.d.ts +3 -2
  170. package/dist/types/types/ws.d.ts.map +1 -1
  171. package/dist/types/utils/liquidation.d.ts +1 -1
  172. package/dist/types/utils/liquidation.d.ts.map +1 -1
  173. package/dist/types/utils/mapActivity.d.ts +2 -1
  174. package/dist/types/utils/mapActivity.d.ts.map +1 -1
  175. package/dist/types/utils/mapFill.d.ts +3 -2
  176. package/dist/types/utils/mapFill.d.ts.map +1 -1
  177. package/dist/types/utils/mapMarket.d.ts +2 -2
  178. package/dist/types/utils/mapMarket.d.ts.map +1 -1
  179. package/dist/types/utils/mapMarketContext.d.ts.map +1 -1
  180. package/dist/types/utils/mapOrder.d.ts +5 -2
  181. package/dist/types/utils/mapOrder.d.ts.map +1 -1
  182. package/dist/types/utils/mapPosition.d.ts +4 -2
  183. package/dist/types/utils/mapPosition.d.ts.map +1 -1
  184. package/dist/types/utils/rowTimestamp.d.ts +6 -0
  185. package/dist/types/utils/rowTimestamp.d.ts.map +1 -0
  186. package/dist/types/utils/spotBalance.d.ts +5 -5
  187. package/dist/types/utils/spotBalance.d.ts.map +1 -1
  188. package/dist/types/utils/spotCollateral.d.ts.map +1 -1
  189. package/dist/types/utils/transferMargin.d.ts +2 -1
  190. package/dist/types/utils/transferMargin.d.ts.map +1 -1
  191. package/dist/types/utils/venueTotals.d.ts +10 -5
  192. package/dist/types/utils/venueTotals.d.ts.map +1 -1
  193. package/dist/types/utils/withdrawableBalances.d.ts +6 -4
  194. package/dist/types/utils/withdrawableBalances.d.ts.map +1 -1
  195. package/dist/types/websocket/HyperliquidWsProvider.d.ts +2 -0
  196. package/dist/types/websocket/HyperliquidWsProvider.d.ts.map +1 -1
  197. package/package.json +3 -3
  198. package/src/HyperliquidProvider.ts +1 -1
  199. package/src/accountSummary.ts +35 -23
  200. package/src/services/getAccount.ts +50 -33
  201. package/src/services/getFills.ts +2 -1
  202. package/src/services/getMarketSettings.ts +6 -2
  203. package/src/services/getOrder.ts +18 -7
  204. package/src/services/getOrders.ts +6 -3
  205. package/src/services/getPortfolioHistory.ts +38 -7
  206. package/src/services/getPositions.ts +4 -3
  207. package/src/services/getWithdrawableBalances.ts +1 -1
  208. package/src/types/ws.ts +3 -2
  209. package/src/utils/liquidation.ts +14 -8
  210. package/src/utils/mapActivity.ts +42 -20
  211. package/src/utils/mapFill.ts +22 -9
  212. package/src/utils/mapMarket.ts +12 -10
  213. package/src/utils/mapMarketContext.ts +6 -8
  214. package/src/utils/mapOrder.ts +81 -20
  215. package/src/utils/mapPosition.ts +67 -13
  216. package/src/utils/rowTimestamp.ts +15 -0
  217. package/src/utils/spotBalance.ts +19 -16
  218. package/src/utils/spotCollateral.ts +15 -2
  219. package/src/utils/transferMargin.ts +40 -18
  220. package/src/utils/venueTotals.ts +54 -13
  221. package/src/utils/withdrawableBalances.ts +33 -15
  222. package/src/websocket/HyperliquidWsProvider.ts +169 -102
  223. package/dist/cjs/utils/decimal.d.ts +0 -3
  224. package/dist/cjs/utils/decimal.d.ts.map +0 -1
  225. package/dist/cjs/utils/decimal.js +0 -19
  226. package/dist/cjs/utils/decimal.js.map +0 -1
  227. package/dist/esm/utils/decimal.d.ts +0 -10
  228. package/dist/esm/utils/decimal.d.ts.map +0 -1
  229. package/dist/esm/utils/decimal.js +0 -19
  230. package/dist/esm/utils/decimal.js.map +0 -1
  231. package/dist/types/utils/decimal.d.ts +0 -10
  232. package/dist/types/utils/decimal.d.ts.map +0 -1
  233. package/src/utils/decimal.ts +0 -21
@@ -1,7 +1,11 @@
1
1
  import {
2
2
  calculateWithdrawMax,
3
+ isDecimalStringGreaterThan,
3
4
  type ProviderWithdrawableBalance,
5
+ subtractDecimalString,
6
+ unknownToDecimalString,
4
7
  } from '@lifi/perps-sdk'
8
+ import { PROVIDER_KEY, SPOT_MARKET_ID } from '../constants.js'
5
9
  import type {
6
10
  HlAbstractionMode,
7
11
  HlClearinghouseState,
@@ -9,19 +13,20 @@ import type {
9
13
  } from '../types/index.js'
10
14
  import { isUnifiedAbstraction } from './abstractionMode.js'
11
15
  import { assetIsOutcome } from './assetId.js'
12
- import { toWireBig } from './decimal.js'
13
16
 
14
17
  /**
15
- * Split a Hyperliquid account's venue figures into the routes a withdrawal
16
- * draws on. A unified or portfolio-margin account holds its collateral in spot,
18
+ * Split a Hyperliquid account's venue figures into the categories a
19
+ * withdrawal draws on. A unified or portfolio-margin account holds its collateral in spot,
17
20
  * so each spot token adds the part of `total` that no order or margin holds. A
18
- * route with nothing left to draw carries no row, and the caller applies the
21
+ * category with nothing left to draw carries no row, and the caller applies the
19
22
  * per-asset venue minimum.
20
23
  *
21
- * @param quoteAssetId - `Asset.id` the perps-route row is keyed by.
24
+ * @param quoteAssetId - `Asset.id` the perps-category row is keyed by.
22
25
  * @param withdrawalFee - Flat venue fee in quote-asset units, set on every
23
26
  * quote-asset row. Hyperliquid deducts it from the requested amount. Absent
24
27
  * leaves every row without a fee.
28
+ * @throws {PerpsError} `SDKError` when the fee or a venue figure is not a
29
+ * decimal.
25
30
  * @public
26
31
  */
27
32
  export const hyperliquidWithdrawableBalances = (
@@ -35,7 +40,11 @@ export const hyperliquidWithdrawableBalances = (
35
40
  const fee =
36
41
  withdrawalFee === undefined
37
42
  ? undefined
38
- : toWireBig(withdrawalFee, 'providers.withdrawalFeeUsd').toFixed()
43
+ : unknownToDecimalString(
44
+ withdrawalFee,
45
+ 'providers.withdrawalFeeUsd',
46
+ PROVIDER_KEY
47
+ )
39
48
  const feeFor = (
40
49
  assetId: string
41
50
  ): Pick<ProviderWithdrawableBalance, 'withdrawalFee' | 'isFeeDeducted'> =>
@@ -48,15 +57,20 @@ export const hyperliquidWithdrawableBalances = (
48
57
  if (assetIsOutcome(balance.coin)) {
49
58
  continue
50
59
  }
51
- const spot = toWireBig(balance.total, 'spotBalance.total').minus(
52
- toWireBig(balance.hold, 'spotBalance.hold')
60
+ const spot = subtractDecimalString(
61
+ unknownToDecimalString(
62
+ balance.total,
63
+ 'spotBalance.total',
64
+ PROVIDER_KEY
65
+ ),
66
+ unknownToDecimalString(balance.hold, 'spotBalance.hold', PROVIDER_KEY)
53
67
  )
54
- if (spot.gt(0)) {
68
+ if (isDecimalStringGreaterThan(spot, '0')) {
55
69
  const assetId = String(balance.token)
56
70
  const row = {
57
71
  assetId,
58
- route: 'spot' as const,
59
- available: spot.toFixed(),
72
+ categoryId: SPOT_MARKET_ID,
73
+ available: spot,
60
74
  ...feeFor(assetId),
61
75
  }
62
76
  rows.push({ ...row, max: calculateWithdrawMax(row) })
@@ -64,12 +78,16 @@ export const hyperliquidWithdrawableBalances = (
64
78
  }
65
79
  }
66
80
 
67
- const perps = toWireBig(state.withdrawable, 'clearinghouseState.withdrawable')
68
- if (perps.gt(0)) {
81
+ const perps = unknownToDecimalString(
82
+ state.withdrawable,
83
+ 'clearinghouseState.withdrawable',
84
+ PROVIDER_KEY
85
+ )
86
+ if (isDecimalStringGreaterThan(perps, '0')) {
69
87
  const row = {
70
88
  assetId: quoteAssetId,
71
- route: 'perps' as const,
72
- available: perps.toFixed(),
89
+ categoryId: PROVIDER_KEY,
90
+ available: perps,
73
91
  ...feeFor(quoteAssetId),
74
92
  }
75
93
  rows.push({ ...row, max: calculateWithdrawMax(row) })
@@ -1,11 +1,15 @@
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
+ isDecimalStringGreaterThan,
11
+ isDecimalStringZero,
7
12
  type MarketRegistry,
8
- numberToDecimalString,
9
13
  PerpsError,
10
14
  type PerpsSDKClient,
11
15
  type ProviderGetQuoteParams,
@@ -13,8 +17,17 @@ import {
13
17
  ReconnectingWebSocket,
14
18
  resolveSubscribeQuote,
15
19
  type SubscriptionListener,
20
+ safeAddDecimalString,
21
+ safeDecimalStringToNumber,
22
+ safeDivideDecimalString,
23
+ safeIsDecimalStringGreaterThan,
24
+ safeIsDecimalStringZero,
25
+ safeMultiplyDecimalString,
26
+ safeNumberToDecimalString,
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,
@@ -604,10 +617,15 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
604
617
  if (priceStep === undefined) {
605
618
  return {}
606
619
  }
607
- return priceStepToAggregation(
608
- priceStep,
609
- this.orderbookReferencePrice(marketId)
610
- )
620
+ const referencePrice = this.orderbookReferencePrice(marketId)
621
+ const referencePriceNumber =
622
+ referencePrice === undefined
623
+ ? undefined
624
+ : safeDecimalStringToNumber(referencePrice)
625
+ if (referencePriceNumber === undefined) {
626
+ return {}
627
+ }
628
+ return priceStepToAggregation(priceStep, referencePriceNumber)
611
629
  }
612
630
 
613
631
  private orderbookAggregationKey(
@@ -954,30 +972,31 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
954
972
  }
955
973
 
956
974
  /** Latest mid per `Market.id` across asset-context and fast feeds. */
957
- private mergedMids(): Map<string, number> {
958
- const map = new Map<string, number>()
975
+ /** Latest mid per `Market.id` across asset-context and fast feeds; a mid
976
+ * that is not a decimal string is left out. */
977
+ private mergedMids(): Map<string, DecimalString> {
978
+ const map = new Map<string, DecimalString>()
979
+ const setMid = (id: string, mid: string | number | null | undefined) => {
980
+ const decimal = mid == null ? undefined : wsFigureToDecimalString(mid)
981
+ if (isDecimalString(decimal)) {
982
+ map.set(id, decimal)
983
+ }
984
+ }
959
985
  for (const byMarketId of this.perpCtxBySubDex.values()) {
960
986
  for (const [id, ctx] of Object.entries(byMarketId)) {
961
- const mid = ctx.midPx ?? ctx.markPx
962
- map.set(id, Number(mid))
987
+ setMid(id, ctx.midPx ?? ctx.markPx)
963
988
  }
964
989
  }
965
990
  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
- }
991
+ setMid(id, ctx.midPx ?? ctx.markPx)
970
992
  }
971
993
  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
- }
994
+ setMid(id, fast.midPx ?? fast.markPx)
976
995
  }
977
996
  return map
978
997
  }
979
998
 
980
- private orderbookReferencePrice(marketId: string): number {
999
+ private orderbookReferencePrice(marketId: string): DecimalString | undefined {
981
1000
  const mid = this.mergedMids().get(marketId)
982
1001
  if (mid !== undefined) {
983
1002
  return mid
@@ -986,11 +1005,11 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
986
1005
  const book = this.latestOrderbookByMarketId.get(marketId)
987
1006
  const bid = book?.bids[0]?.price
988
1007
  const ask = book?.asks[0]?.price
989
- if (bid !== undefined && ask !== undefined) {
990
- return (Number(bid) + Number(ask)) / 2
1008
+ if (bid === undefined || ask === undefined) {
1009
+ return undefined
991
1010
  }
992
-
993
- return Number.NaN
1011
+ const sum = safeAddDecimalString(bid, ask)
1012
+ return sum === undefined ? undefined : safeDivideDecimalString(sum, '2')
994
1013
  }
995
1014
 
996
1015
  private handleL2Book(data: HlWsL2BookData) {
@@ -998,11 +1017,11 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
998
1017
  provider: this.providerKey,
999
1018
  marketId: data.coin,
1000
1019
  bids: data.levels[0]
1001
- .slice(0, HL_L2_BOOK_MAX_LEVELS_PER_SIDE)
1002
- .map((l) => ({ price: l.px, size: l.sz })),
1020
+ .flatMap((l) => toOrderbookLevel(l.px, l.sz))
1021
+ .slice(0, HL_L2_BOOK_MAX_LEVELS_PER_SIDE),
1003
1022
  asks: data.levels[1]
1004
- .slice(0, HL_L2_BOOK_MAX_LEVELS_PER_SIDE)
1005
- .map((l) => ({ price: l.px, size: l.sz })),
1023
+ .flatMap((l) => toOrderbookLevel(l.px, l.sz))
1024
+ .slice(0, HL_L2_BOOK_MAX_LEVELS_PER_SIDE),
1006
1025
  timestamp: data.time,
1007
1026
  }
1008
1027
  this.latestOrderbookByMarketId.set(data.coin, book)
@@ -1197,7 +1216,8 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
1197
1216
  return []
1198
1217
  }
1199
1218
  const market = this.registry?.get(f.coin)
1200
- return market ? [mapFill(f as HlUserFill, market)] : []
1219
+ const mapped = market && mapFill(f as HlUserFill, market)
1220
+ return mapped ? [mapped] : []
1201
1221
  })
1202
1222
  this.emit(`userFills:${data.user.toLowerCase()}`, {
1203
1223
  channel: 'fills',
@@ -1217,9 +1237,11 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
1217
1237
  return []
1218
1238
  }
1219
1239
  const market = this.registry?.get(ap.position.coin)
1220
- return market
1221
- ? [mapPosition(ap as HlAssetPosition, toPerpsMarketDisplay(market))]
1222
- : []
1240
+ const position =
1241
+ market === undefined
1242
+ ? undefined
1243
+ : mapPosition(ap as HlAssetPosition, toPerpsMarketDisplay(market))
1244
+ return position === undefined ? [] : [position]
1223
1245
  })
1224
1246
  )
1225
1247
  this.emit(`positions:${data.user.toLowerCase()}`, {
@@ -1232,10 +1254,7 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
1232
1254
  )
1233
1255
 
1234
1256
  const key = data.user.toLowerCase()
1235
- this.latestPerpsByUser.set(key, {
1236
- positions,
1237
- marginUsed: marginUsed.toFixed(),
1238
- })
1257
+ this.latestPerpsByUser.set(key, { positions, marginUsed })
1239
1258
  this.emitUnifiedSummary(key)
1240
1259
 
1241
1260
  // Equity semantics, matching the REST summary: `accountValue` already
@@ -1243,10 +1262,10 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
1243
1262
  // so this portfolio value covers perps equity only — which is why the
1244
1263
  // frame is gated on the abstraction mode below.
1245
1264
  this.emitSummaryIfModeAllows(data.user, {
1246
- portfolioValue: accountValue.toFixed(),
1247
- availableMargin: accountValue.minus(marginUsed).toFixed(),
1248
- marginUsed: marginUsed.toFixed(),
1249
- unrealizedPnl: sumUnrealizedPnl(positions).toFixed(),
1265
+ portfolioValue: accountValue,
1266
+ availableMargin: subtractDecimalString(accountValue, marginUsed),
1267
+ marginUsed,
1268
+ unrealizedPnl: sumUnrealizedPnl(positions),
1250
1269
  })
1251
1270
  }
1252
1271
 
@@ -1353,16 +1372,23 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
1353
1372
  ...pipeline.spot.balances,
1354
1373
  ].reduce(
1355
1374
  (sum, balance) =>
1356
- sum.plus(toWireBig(balance.valueUsd, 'spotBalance.valueUsd')),
1357
- new Big(0)
1375
+ addDecimalString(
1376
+ sum,
1377
+ unknownToDecimalString(
1378
+ balance.valueUsd,
1379
+ 'spotBalance.valueUsd',
1380
+ this.providerKey
1381
+ )
1382
+ ),
1383
+ '0'
1358
1384
  )
1359
1385
  this.emit(`accountSummary:${key}`, {
1360
1386
  channel: 'accountSummary',
1361
1387
  data: {
1362
- portfolioValue: portfolioValue.toFixed(),
1388
+ portfolioValue,
1363
1389
  availableMargin: pipeline.availableMargin,
1364
1390
  marginUsed: perps.marginUsed,
1365
- unrealizedPnl: sumUnrealizedPnl(perps.positions).toFixed(),
1391
+ unrealizedPnl: sumUnrealizedPnl(perps.positions),
1366
1392
  },
1367
1393
  })
1368
1394
  }
@@ -1524,34 +1550,45 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
1524
1550
  }
1525
1551
  const markets = this.registry?.activeMarkets ?? []
1526
1552
  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
- )
1553
+ const balances = data.spotState.balances
1554
+ .filter((balance) => !assetIsOutcome(balance.coin))
1555
+ .map((balance) => ({
1556
+ balance,
1557
+ total: unknownToDecimalString(
1558
+ balance.total,
1559
+ 'spotState.balances.total',
1560
+ this.providerKey
1561
+ ),
1562
+ }))
1563
+ .filter(({ total }) => isDecimalStringGreaterThan(total, '0'))
1532
1564
  const pipeline = this.unifiedSummaryByUser.get(user)
1533
1565
  // Known spot markets await a price; unlisted tokens keep their unpriced balance.
1534
1566
  if (
1535
- balances.some((balance) => priceById.get(String(balance.token)) === 0)
1567
+ balances.some(({ balance }) => {
1568
+ const price = priceById.get(String(balance.token))
1569
+ return price !== undefined && isDecimalStringZero(price)
1570
+ })
1536
1571
  ) {
1537
1572
  if (pipeline !== undefined) {
1538
1573
  pipeline.spot = undefined
1539
1574
  }
1540
1575
  return
1541
1576
  }
1542
- const rows = balances.map((balance) => {
1543
- const total = toWireBig(balance.total, 'spotState.balances.total')
1544
- return {
1545
- ...spotBalance(spotAssetFromToken(balance), balance.total, priceById),
1546
- locked: balance.hold,
1547
- transferable: calculateTransferable(
1548
- total
1549
- .minus(toWireBig(balance.hold, 'spotState.balances.hold'))
1550
- .toFixed(),
1551
- total.toFixed()
1577
+ const rows = balances.map(({ balance, total }) => ({
1578
+ ...spotBalance(spotAssetFromToken(balance), total, priceById),
1579
+ locked: balance.hold,
1580
+ transferable: calculateTransferable(
1581
+ subtractDecimalString(
1582
+ total,
1583
+ unknownToDecimalString(
1584
+ balance.hold,
1585
+ 'spotState.balances.hold',
1586
+ this.providerKey
1587
+ )
1552
1588
  ),
1553
- }
1554
- })
1589
+ total
1590
+ ),
1591
+ }))
1555
1592
  this.emit(`spotState:${user}`, {
1556
1593
  channel: 'spotBalances',
1557
1594
  data: rows,
@@ -1609,33 +1646,31 @@ export class HyperliquidWsProvider extends WsProviderBase<object> {
1609
1646
  const isObject = (v: unknown): v is Record<string, unknown> =>
1610
1647
  typeof v === 'object' && v !== null
1611
1648
 
1612
- const toMarketContextString = (value: unknown): string | undefined => {
1613
- if (typeof value === 'number') {
1614
- return numberToDecimalString(value)
1615
- }
1616
- return typeof value === 'string' ? value : undefined
1649
+ /** A WebSocket figure as a string; a venue number is spelled as a decimal
1650
+ * string, and a non-finite number gives `undefined`. */
1651
+ function wsFigureToDecimalString(value: string | number): string | undefined {
1652
+ return typeof value === 'number' ? safeNumberToDecimalString(value) : value
1653
+ }
1654
+
1655
+ function optionalWsFigureToDecimalString(
1656
+ value: string | number | null | undefined
1657
+ ): string | undefined {
1658
+ return value == null ? undefined : wsFigureToDecimalString(value)
1617
1659
  }
1618
1660
 
1619
1661
  const toMarketCapString = (
1620
- price: unknown,
1621
- circulatingSupply: unknown
1662
+ price: string,
1663
+ circulatingSupply: string | number | undefined
1622
1664
  ): 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 {
1665
+ const supply = optionalWsFigureToDecimalString(circulatingSupply)
1666
+ if (
1667
+ supply === undefined ||
1668
+ safeIsDecimalStringGreaterThan(price, '0') !== true ||
1669
+ safeIsDecimalStringGreaterThan(supply, '0') !== true
1670
+ ) {
1637
1671
  return undefined
1638
1672
  }
1673
+ return safeMultiplyDecimalString(price, supply)
1639
1674
  }
1640
1675
 
1641
1676
  function mergePerpAssetCtx(
@@ -1685,16 +1720,13 @@ function activePerpAssetCtx(
1685
1720
  marketId: string,
1686
1721
  ctx: HlWsActiveAssetCtxData['ctx']
1687
1722
  ): 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)
1723
+ const funding = optionalWsFigureToDecimalString(ctx.funding)
1724
+ const openInterest = optionalWsFigureToDecimalString(ctx.openInterest)
1725
+ const dayNtlVlm = optionalWsFigureToDecimalString(ctx.dayNtlVlm)
1726
+ const prevDayPx = optionalWsFigureToDecimalString(ctx.prevDayPx)
1727
+ const markPx = optionalWsFigureToDecimalString(ctx.markPx)
1728
+ const midPx = optionalWsFigureToDecimalString(ctx.midPx) ?? null
1729
+ const oraclePx = optionalWsFigureToDecimalString(ctx.oraclePx)
1698
1730
 
1699
1731
  if (
1700
1732
  funding === undefined ||
@@ -1724,8 +1756,8 @@ function mapSpotMarketContext(
1724
1756
  ctx: HlWsSpotAssetCtx,
1725
1757
  fast?: HlWsFastAssetCtx
1726
1758
  ): MarketContext | undefined {
1727
- const midPrice = toMarketContextString(ctx.midPx ?? ctx.markPx)
1728
- const markPrice = toMarketContextString(ctx.markPx)
1759
+ const midPrice = optionalWsFigureToDecimalString(ctx.midPx ?? ctx.markPx)
1760
+ const markPrice = optionalWsFigureToDecimalString(ctx.markPx)
1729
1761
  if (midPrice === undefined || markPrice === undefined) {
1730
1762
  return undefined
1731
1763
  }
@@ -1735,12 +1767,41 @@ function mapSpotMarketContext(
1735
1767
  marketId,
1736
1768
  midPrice: fast?.midPx != null ? fast.midPx : midPrice,
1737
1769
  markPrice: emittedMarkPrice,
1738
- prevDayPrice: toMarketContextString(ctx.prevDayPx),
1739
- volume24h: toMarketContextString(ctx.dayNtlVlm),
1770
+ prevDayPrice: optionalWsFigureToDecimalString(ctx.prevDayPx),
1771
+ volume24h: optionalWsFigureToDecimalString(ctx.dayNtlVlm),
1740
1772
  marketCap: toMarketCapString(emittedMarkPrice, ctx.circulatingSupply),
1741
1773
  }
1742
1774
  }
1743
1775
 
1776
+ const BOOK_LEVEL_ROW = 'order book level'
1777
+
1778
+ /** The venue price when it is a decimal string, or `undefined` after a logged skip. */
1779
+ function bookLevelPrice(price: string): DecimalString | undefined {
1780
+ if (!isDecimalString(price)) {
1781
+ wsLog.skippedRow(PROVIDER_KEY, BOOK_LEVEL_ROW, 'price', price)
1782
+ return undefined
1783
+ }
1784
+ return price
1785
+ }
1786
+
1787
+ /** The venue size when it is a decimal string, or `undefined` after a logged skip. */
1788
+ function bookLevelSize(size: string): DecimalString | undefined {
1789
+ if (!isDecimalString(size)) {
1790
+ wsLog.skippedRow(PROVIDER_KEY, BOOK_LEVEL_ROW, 'size', size)
1791
+ return undefined
1792
+ }
1793
+ return size
1794
+ }
1795
+
1796
+ /** One order-book level, or none when the venue price or size is invalid. */
1797
+ function toOrderbookLevel(price: string, size: string): OrderbookLevel[] {
1798
+ const levelPrice = bookLevelPrice(price)
1799
+ const levelSize = levelPrice === undefined ? undefined : bookLevelSize(size)
1800
+ return levelPrice === undefined || levelSize === undefined
1801
+ ? []
1802
+ : [{ price: levelPrice, size: levelSize }]
1803
+ }
1804
+
1744
1805
  function compactRemovalPrice(
1745
1806
  levels: OrderbookLevel[],
1746
1807
  value: number | string | { p: string }
@@ -1765,10 +1826,16 @@ function applyCompressedL2Side(
1765
1826
  }
1766
1827
  }
1767
1828
  for (const update of updates) {
1768
- if (Number(update.s) === 0) {
1769
- byPrice.delete(update.p)
1829
+ const price = bookLevelPrice(update.p)
1830
+ if (price === undefined) {
1831
+ continue
1832
+ }
1833
+ const size = bookLevelSize(update.s)
1834
+ // A level whose new size is unknown must not keep its old size.
1835
+ if (size === undefined || safeIsDecimalStringZero(size) !== false) {
1836
+ byPrice.delete(price)
1770
1837
  } else {
1771
- byPrice.set(update.p, update.s)
1838
+ byPrice.set(price, size)
1772
1839
  }
1773
1840
  }
1774
1841
 
@@ -1776,8 +1843,8 @@ function applyCompressedL2Side(
1776
1843
  .map(([price, size]) => ({ price, size }))
1777
1844
  .sort((a, b) =>
1778
1845
  side === 'bid'
1779
- ? Number(b.price) - Number(a.price)
1780
- : Number(a.price) - Number(b.price)
1846
+ ? compareDecimalStrings(b.price, a.price)
1847
+ : compareDecimalStrings(a.price, b.price)
1781
1848
  )
1782
1849
  .slice(0, HL_L2_BOOK_MAX_LEVELS_PER_SIDE)
1783
1850
  }
@@ -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
@@ -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,21 +0,0 @@
1
- import { PerpsError } from '@lifi/perps-sdk'
2
- import { PerpsErrorCode } from '@lifi/perps-types'
3
- import Big from 'big.js'
4
-
5
- /**
6
- * Exact-decimal parse of a Hyperliquid wire decimal string. `field` names the
7
- * offending field on failure, so a venue contract breach is diagnosable
8
- * instead of surfacing as an anonymous big.js throw or an `NaN` unit.
9
- *
10
- * @throws {PerpsError} `SDKError` when `value` is not a decimal numeric string.
11
- */
12
- export const toWireBig = (value: string, field: string): Big => {
13
- try {
14
- return new Big(value)
15
- } catch {
16
- throw new PerpsError(
17
- PerpsErrorCode.SDKError,
18
- `Hyperliquid field \`${field}\` is not a valid decimal: '${value}'`
19
- )
20
- }
21
- }