@lifi/perps-sdk-provider-hyperliquid 6.0.0 → 6.0.2

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 (203) hide show
  1. package/dist/cjs/HyperliquidProvider.d.ts.map +1 -1
  2. package/dist/cjs/HyperliquidProvider.js.map +1 -1
  3. package/dist/cjs/services/getActivity.d.ts.map +1 -1
  4. package/dist/cjs/services/getActivity.js.map +1 -1
  5. package/dist/cjs/services/getFills.d.ts.map +1 -1
  6. package/dist/cjs/services/getFills.js.map +1 -1
  7. package/dist/cjs/services/getOrders.d.ts.map +1 -1
  8. package/dist/cjs/services/getOrders.js.map +1 -1
  9. package/dist/cjs/signers/HyperliquidAgentStore.d.ts.map +1 -1
  10. package/dist/cjs/signers/HyperliquidAgentStore.js.map +1 -1
  11. package/dist/cjs/signers/signActions.d.ts.map +1 -1
  12. package/dist/cjs/signers/signActions.js.map +1 -1
  13. package/dist/cjs/types/account.d.ts.map +1 -1
  14. package/dist/cjs/types/account.js.map +1 -1
  15. package/dist/cjs/types/action.d.ts.map +1 -1
  16. package/dist/cjs/types/action.js.map +1 -1
  17. package/dist/cjs/types/asset.d.ts.map +1 -1
  18. package/dist/cjs/types/fill.d.ts.map +1 -1
  19. package/dist/cjs/types/ledger.d.ts.map +1 -1
  20. package/dist/cjs/types/ledger.js.map +1 -1
  21. package/dist/cjs/types/order.d.ts.map +1 -1
  22. package/dist/cjs/types/ws.d.ts.map +1 -1
  23. package/dist/cjs/utils/assetId.d.ts.map +1 -1
  24. package/dist/cjs/utils/assetId.js.map +1 -1
  25. package/dist/cjs/utils/assetLogo.d.ts.map +1 -1
  26. package/dist/cjs/utils/assetLogo.js.map +1 -1
  27. package/dist/cjs/utils/decodeFastAssetCtxs.d.ts.map +1 -1
  28. package/dist/cjs/utils/decodeFastAssetCtxs.js.map +1 -1
  29. package/dist/cjs/utils/infoClient.d.ts.map +1 -1
  30. package/dist/cjs/utils/infoClient.js.map +1 -1
  31. package/dist/cjs/utils/mapActivity.d.ts.map +1 -1
  32. package/dist/cjs/utils/mapActivity.js +13 -10
  33. package/dist/cjs/utils/mapActivity.js.map +1 -1
  34. package/dist/cjs/utils/mapFill.d.ts.map +1 -1
  35. package/dist/cjs/utils/mapFill.js.map +1 -1
  36. package/dist/cjs/utils/mapOrder.d.ts.map +1 -1
  37. package/dist/cjs/utils/mapOrder.js.map +1 -1
  38. package/dist/cjs/utils/mapPosition.d.ts.map +1 -1
  39. package/dist/cjs/utils/mapPosition.js.map +1 -1
  40. package/dist/cjs/utils/spotBalance.d.ts.map +1 -1
  41. package/dist/cjs/utils/spotBalance.js.map +1 -1
  42. package/dist/cjs/utils/spotCollateral.d.ts.map +1 -1
  43. package/dist/cjs/utils/spotCollateral.js.map +1 -1
  44. package/dist/cjs/utils/transferMargin.d.ts.map +1 -1
  45. package/dist/cjs/utils/transferMargin.js +1 -2
  46. package/dist/cjs/utils/transferMargin.js.map +1 -1
  47. package/dist/esm/HyperliquidProvider.d.ts +14 -4
  48. package/dist/esm/HyperliquidProvider.d.ts.map +1 -1
  49. package/dist/esm/HyperliquidProvider.js.map +1 -1
  50. package/dist/esm/services/getActivity.d.ts +5 -1
  51. package/dist/esm/services/getActivity.d.ts.map +1 -1
  52. package/dist/esm/services/getActivity.js.map +1 -1
  53. package/dist/esm/services/getFills.d.ts +4 -3
  54. package/dist/esm/services/getFills.d.ts.map +1 -1
  55. package/dist/esm/services/getFills.js.map +1 -1
  56. package/dist/esm/services/getOrders.d.ts +2 -1
  57. package/dist/esm/services/getOrders.d.ts.map +1 -1
  58. package/dist/esm/services/getOrders.js.map +1 -1
  59. package/dist/esm/services/getPositions.d.ts +2 -2
  60. package/dist/esm/services/getPositions.d.ts.map +1 -1
  61. package/dist/esm/signers/HyperliquidAgentStore.d.ts +3 -3
  62. package/dist/esm/signers/HyperliquidAgentStore.d.ts.map +1 -1
  63. package/dist/esm/signers/HyperliquidAgentStore.js +1 -0
  64. package/dist/esm/signers/HyperliquidAgentStore.js.map +1 -1
  65. package/dist/esm/signers/signActions.d.ts +8 -6
  66. package/dist/esm/signers/signActions.d.ts.map +1 -1
  67. package/dist/esm/signers/signActions.js +8 -6
  68. package/dist/esm/signers/signActions.js.map +1 -1
  69. package/dist/esm/types/account.d.ts +51 -8
  70. package/dist/esm/types/account.d.ts.map +1 -1
  71. package/dist/esm/types/account.js.map +1 -1
  72. package/dist/esm/types/action.d.ts +28 -10
  73. package/dist/esm/types/action.d.ts.map +1 -1
  74. package/dist/esm/types/action.js +7 -7
  75. package/dist/esm/types/action.js.map +1 -1
  76. package/dist/esm/types/asset.d.ts +60 -15
  77. package/dist/esm/types/asset.d.ts.map +1 -1
  78. package/dist/esm/types/fill.d.ts +9 -3
  79. package/dist/esm/types/fill.d.ts.map +1 -1
  80. package/dist/esm/types/ledger.d.ts +24 -6
  81. package/dist/esm/types/ledger.d.ts.map +1 -1
  82. package/dist/esm/types/ledger.js.map +1 -1
  83. package/dist/esm/types/order.d.ts +19 -5
  84. package/dist/esm/types/order.d.ts.map +1 -1
  85. package/dist/esm/types/ws.d.ts +43 -14
  86. package/dist/esm/types/ws.d.ts.map +1 -1
  87. package/dist/esm/utils/assetId.d.ts +7 -7
  88. package/dist/esm/utils/assetId.d.ts.map +1 -1
  89. package/dist/esm/utils/assetId.js +7 -7
  90. package/dist/esm/utils/assetId.js.map +1 -1
  91. package/dist/esm/utils/assetLogo.d.ts +15 -13
  92. package/dist/esm/utils/assetLogo.d.ts.map +1 -1
  93. package/dist/esm/utils/assetLogo.js +15 -13
  94. package/dist/esm/utils/assetLogo.js.map +1 -1
  95. package/dist/esm/utils/decodeFastAssetCtxs.d.ts +7 -1
  96. package/dist/esm/utils/decodeFastAssetCtxs.d.ts.map +1 -1
  97. package/dist/esm/utils/decodeFastAssetCtxs.js +7 -1
  98. package/dist/esm/utils/decodeFastAssetCtxs.js.map +1 -1
  99. package/dist/esm/utils/infoClient.d.ts +6 -1
  100. package/dist/esm/utils/infoClient.d.ts.map +1 -1
  101. package/dist/esm/utils/infoClient.js.map +1 -1
  102. package/dist/esm/utils/mapActivity.d.ts +10 -1
  103. package/dist/esm/utils/mapActivity.d.ts.map +1 -1
  104. package/dist/esm/utils/mapActivity.js +23 -11
  105. package/dist/esm/utils/mapActivity.js.map +1 -1
  106. package/dist/esm/utils/mapFill.d.ts +1 -0
  107. package/dist/esm/utils/mapFill.d.ts.map +1 -1
  108. package/dist/esm/utils/mapFill.js +1 -0
  109. package/dist/esm/utils/mapFill.js.map +1 -1
  110. package/dist/esm/utils/mapOrder.d.ts +15 -4
  111. package/dist/esm/utils/mapOrder.d.ts.map +1 -1
  112. package/dist/esm/utils/mapOrder.js +15 -4
  113. package/dist/esm/utils/mapOrder.js.map +1 -1
  114. package/dist/esm/utils/mapPosition.d.ts +6 -1
  115. package/dist/esm/utils/mapPosition.d.ts.map +1 -1
  116. package/dist/esm/utils/mapPosition.js +6 -1
  117. package/dist/esm/utils/mapPosition.js.map +1 -1
  118. package/dist/esm/utils/spotBalance.d.ts +9 -10
  119. package/dist/esm/utils/spotBalance.d.ts.map +1 -1
  120. package/dist/esm/utils/spotBalance.js +9 -10
  121. package/dist/esm/utils/spotBalance.js.map +1 -1
  122. package/dist/esm/utils/spotCollateral.d.ts +9 -5
  123. package/dist/esm/utils/spotCollateral.d.ts.map +1 -1
  124. package/dist/esm/utils/spotCollateral.js +4 -4
  125. package/dist/esm/utils/spotCollateral.js.map +1 -1
  126. package/dist/esm/utils/transferMargin.d.ts.map +1 -1
  127. package/dist/esm/utils/transferMargin.js +2 -3
  128. package/dist/esm/utils/transferMargin.js.map +1 -1
  129. package/dist/types/HyperliquidProvider.d.ts +14 -4
  130. package/dist/types/HyperliquidProvider.d.ts.map +1 -1
  131. package/dist/types/services/getActivity.d.ts +5 -1
  132. package/dist/types/services/getActivity.d.ts.map +1 -1
  133. package/dist/types/services/getFills.d.ts +4 -3
  134. package/dist/types/services/getFills.d.ts.map +1 -1
  135. package/dist/types/services/getOrders.d.ts +2 -1
  136. package/dist/types/services/getOrders.d.ts.map +1 -1
  137. package/dist/types/services/getPositions.d.ts +2 -2
  138. package/dist/types/services/getPositions.d.ts.map +1 -1
  139. package/dist/types/signers/HyperliquidAgentStore.d.ts +3 -3
  140. package/dist/types/signers/HyperliquidAgentStore.d.ts.map +1 -1
  141. package/dist/types/signers/signActions.d.ts +8 -6
  142. package/dist/types/signers/signActions.d.ts.map +1 -1
  143. package/dist/types/types/account.d.ts +51 -8
  144. package/dist/types/types/account.d.ts.map +1 -1
  145. package/dist/types/types/action.d.ts +28 -10
  146. package/dist/types/types/action.d.ts.map +1 -1
  147. package/dist/types/types/asset.d.ts +60 -15
  148. package/dist/types/types/asset.d.ts.map +1 -1
  149. package/dist/types/types/fill.d.ts +9 -3
  150. package/dist/types/types/fill.d.ts.map +1 -1
  151. package/dist/types/types/ledger.d.ts +24 -6
  152. package/dist/types/types/ledger.d.ts.map +1 -1
  153. package/dist/types/types/order.d.ts +19 -5
  154. package/dist/types/types/order.d.ts.map +1 -1
  155. package/dist/types/types/ws.d.ts +43 -14
  156. package/dist/types/types/ws.d.ts.map +1 -1
  157. package/dist/types/utils/assetId.d.ts +7 -7
  158. package/dist/types/utils/assetId.d.ts.map +1 -1
  159. package/dist/types/utils/assetLogo.d.ts +15 -13
  160. package/dist/types/utils/assetLogo.d.ts.map +1 -1
  161. package/dist/types/utils/decodeFastAssetCtxs.d.ts +7 -1
  162. package/dist/types/utils/decodeFastAssetCtxs.d.ts.map +1 -1
  163. package/dist/types/utils/infoClient.d.ts +6 -1
  164. package/dist/types/utils/infoClient.d.ts.map +1 -1
  165. package/dist/types/utils/mapActivity.d.ts +10 -1
  166. package/dist/types/utils/mapActivity.d.ts.map +1 -1
  167. package/dist/types/utils/mapFill.d.ts +1 -0
  168. package/dist/types/utils/mapFill.d.ts.map +1 -1
  169. package/dist/types/utils/mapOrder.d.ts +15 -4
  170. package/dist/types/utils/mapOrder.d.ts.map +1 -1
  171. package/dist/types/utils/mapPosition.d.ts +6 -1
  172. package/dist/types/utils/mapPosition.d.ts.map +1 -1
  173. package/dist/types/utils/spotBalance.d.ts +9 -10
  174. package/dist/types/utils/spotBalance.d.ts.map +1 -1
  175. package/dist/types/utils/spotCollateral.d.ts +9 -5
  176. package/dist/types/utils/spotCollateral.d.ts.map +1 -1
  177. package/dist/types/utils/transferMargin.d.ts.map +1 -1
  178. package/package.json +3 -3
  179. package/src/HyperliquidProvider.ts +14 -4
  180. package/src/services/getActivity.ts +5 -1
  181. package/src/services/getFills.ts +4 -3
  182. package/src/services/getOrders.ts +2 -1
  183. package/src/services/getPositions.ts +2 -2
  184. package/src/signers/HyperliquidAgentStore.ts +3 -3
  185. package/src/signers/signActions.ts +8 -6
  186. package/src/types/account.ts +51 -8
  187. package/src/types/action.ts +28 -10
  188. package/src/types/asset.ts +60 -15
  189. package/src/types/fill.ts +9 -3
  190. package/src/types/ledger.ts +24 -6
  191. package/src/types/order.ts +19 -5
  192. package/src/types/ws.ts +43 -14
  193. package/src/utils/assetId.ts +7 -7
  194. package/src/utils/assetLogo.ts +15 -13
  195. package/src/utils/decodeFastAssetCtxs.ts +7 -1
  196. package/src/utils/infoClient.ts +6 -1
  197. package/src/utils/mapActivity.ts +23 -11
  198. package/src/utils/mapFill.ts +1 -0
  199. package/src/utils/mapOrder.ts +15 -4
  200. package/src/utils/mapPosition.ts +6 -1
  201. package/src/utils/spotBalance.ts +9 -10
  202. package/src/utils/spotCollateral.ts +9 -5
  203. package/src/utils/transferMargin.ts +2 -6
@@ -15,12 +15,14 @@ import type { Address, Hex } from 'viem'
15
15
  import type { HyperliquidAgentStore } from './HyperliquidAgentStore.js'
16
16
 
17
17
  /**
18
- * Sign a batch of EIP-712 action steps. Hyperliquid owns both EIP712 arms and
19
- * picks WHO signs from the descriptor's `signers` (forwarded on the context):
20
- * - `AGENT` the user's Hyperliquid agent keypair (provisioned + approved
21
- * during setup; a missing agent throws).
22
- * - `USER` → the end-user's wallet, read from `ctx.userWallet`.
23
- * Hyperliquid declares no WASM_BLOB / EVM_TX actions, so those schemes reject.
18
+ * Sign a batch of Hyperliquid EIP-712 action steps. `AGENT` descriptors use
19
+ * the persisted per-user agent keypair; `USER` descriptors use
20
+ * `ctx.userWallet`. Other signing methods are rejected because Hyperliquid
21
+ * declares no WASM_BLOB or EVM_TX action schemes.
22
+ *
23
+ * @throws {PerpsError} When the method is unsupported, the required agent is
24
+ * missing, or a user-signed action has no wallet.
25
+ * @public
24
26
  */
25
27
  export async function hyperliquidSignActions(
26
28
  agentStore: HyperliquidAgentStore,
@@ -1,26 +1,52 @@
1
1
  // Account-level types returned by Hyperliquid `/info`.
2
2
 
3
- /** @public */
3
+ /**
4
+ * Perpetual position payload from Hyperliquid `clearinghouseState`.
5
+ *
6
+ * Numeric values are decimal strings in quote-asset units except `szi`,
7
+ * which is signed size: positive for long and negative for short. `coin` is
8
+ * the Hyperliquid wire market identifier; `leverage.type` is typically
9
+ * `'cross'` or `'isolated'`.
10
+ * @public
11
+ */
4
12
  export type HlPosition = {
13
+ /** Hyperliquid wire market identifier. */
5
14
  coin: string
15
+ /** Signed position size; positive is long and negative is short. */
6
16
  szi: string
17
+ /** Average entry price as a decimal string. */
7
18
  entryPx: string
19
+ /** Position notional value as a decimal string. */
8
20
  positionValue: string
21
+ /** Estimated liquidation price; may be an empty string when unavailable. */
9
22
  liquidationPx: string
23
+ /** Unrealized PnL in quote-asset units. */
10
24
  unrealizedPnl: string
25
+ /** Margin currently assigned to this position. */
11
26
  marginUsed: string
27
+ /** Leverage mode and numeric leverage multiplier. */
12
28
  leverage: {
13
29
  type: string
14
30
  value: number
15
31
  }
16
32
  }
17
33
 
18
- /** @public */
34
+ /**
35
+ * Wrapper for a position in the `assetPositions` array of a clearinghouse
36
+ * state response.
37
+ * @public
38
+ */
19
39
  export type HlAssetPosition = {
20
40
  position: HlPosition
21
41
  }
22
42
 
23
- /** @public */
43
+ /**
44
+ * Perpetual clearinghouse account state returned by Hyperliquid `/info`.
45
+ * `assetPositions` includes zero-size rows that callers may discard. Monetary
46
+ * fields are decimal strings in the account's quote asset; `marginSummary`
47
+ * covers all positions while `crossMarginSummary` covers cross margin only.
48
+ * @public
49
+ */
24
50
  export type HlClearinghouseState = {
25
51
  assetPositions: HlAssetPosition[]
26
52
  marginSummary: {
@@ -33,7 +59,12 @@ export type HlClearinghouseState = {
33
59
  }
34
60
  }
35
61
 
36
- /** @public */
62
+ /**
63
+ * One spot balance from Hyperliquid `spotClearinghouseState`.
64
+ * `token` is the numeric spot token index, and amounts are decimal strings in
65
+ * the token's native units.
66
+ * @public
67
+ */
37
68
  export type HlSpotBalance = {
38
69
  coin: string
39
70
  token: number
@@ -42,19 +73,31 @@ export type HlSpotBalance = {
42
73
  entryNtl: string
43
74
  }
44
75
 
45
- /** @public */
76
+ /**
77
+ * Spot clearinghouse state returned by Hyperliquid `/info`.
78
+ * @public
79
+ */
46
80
  export type HlSpotClearinghouseState = {
47
81
  balances: HlSpotBalance[]
48
82
  }
49
83
 
50
- /** @public */
84
+ /**
85
+ * User fee rates returned by Hyperliquid `userFees`.
86
+ * Rates are decimal fractions represented as strings, not percentage values
87
+ * (for example, `'0.00045'` is 0.045%).
88
+ * @public
89
+ */
51
90
  export type HlUserFees = {
52
91
  userAddRate: string
53
92
  userCrossRate: string
54
93
  activeReferralDiscount: string
55
94
  }
56
95
 
57
- /** @public */
96
+ /**
97
+ * Entries returned by Hyperliquid `extraAgents`. The endpoint may add fields
98
+ * over time, so the provider retains each entry as an open record.
99
+ * @public
100
+ */
58
101
  export type HlExtraAgents = Record<string, unknown>[]
59
102
 
60
103
  /**
@@ -96,6 +139,6 @@ export const HlAbstractionMode = {
96
139
  DEX_ABSTRACTION: 'dexAbstraction',
97
140
  } as const
98
141
 
99
- /** @public */
142
+ /** Union of the exact `userAbstraction` wire values accepted by Hyperliquid. @public */
100
143
  export type HlAbstractionMode =
101
144
  (typeof HlAbstractionMode)[keyof typeof HlAbstractionMode]
@@ -1,6 +1,13 @@
1
1
  // Hyperliquid `/exchange` request/response shapes + EIP-712 primary types.
2
2
 
3
- /** @public */
3
+ /**
4
+ * EIP-712 `/exchange` request sent to Hyperliquid.
5
+ *
6
+ * `action` is the provider-specific action object; signature fields are the
7
+ * hex `r`/`s` values and recovery byte `v`; `nonce` is milliseconds since the
8
+ * Unix epoch. `vaultAddress` is included only when submitting for a vault.
9
+ * @public
10
+ */
4
11
  export type HlExchangeRequest = {
5
12
  action: Record<string, unknown>
6
13
  signature: {
@@ -12,7 +19,14 @@ export type HlExchangeRequest = {
12
19
  vaultAddress?: string | null
13
20
  }
14
21
 
15
- /** @public */
22
+ /**
23
+ * Response envelope returned by Hyperliquid `/exchange`.
24
+ *
25
+ * A successful response may contain per-order statuses such as `filled`,
26
+ * `resting`, or `error`; the provider keeps the upstream status strings and
27
+ * numeric order IDs unchanged.
28
+ * @public
29
+ */
16
30
  export type HlExchangeResponse = {
17
31
  status: string
18
32
  response?:
@@ -34,28 +48,32 @@ export type HlExchangeResponse = {
34
48
  }
35
49
  }
36
50
 
37
- /** @public */
51
+ /** EIP-712 primary type for user approval of a Hyperliquid agent wallet. @public */
38
52
  export const HL_PRIMARY_TYPE_APPROVE_AGENT =
39
53
  'HyperliquidTransaction:ApproveAgent' as const
40
- /** @public */
54
+ /** EIP-712 primary type for user approval of an integrator builder fee. @public */
41
55
  export const HL_PRIMARY_TYPE_APPROVE_BUILDER_FEE =
42
56
  'HyperliquidTransaction:ApproveBuilderFee' as const
43
- /** @public */
57
+ /** EIP-712 primary type for changing the user's account abstraction mode. @public */
44
58
  export const HL_PRIMARY_TYPE_USER_SET_ABSTRACTION =
45
59
  'HyperliquidTransaction:UserSetAbstraction' as const
46
- /** @public */
60
+ /** EIP-712 primary type for an agent wallet changing abstraction mode. @public */
47
61
  export const HL_PRIMARY_TYPE_AGENT_SET_ABSTRACTION =
48
62
  'HyperliquidTransaction:AgentSetAbstraction' as const
49
- /** @public */
63
+ /** EIP-712 primary type for withdrawing assets from Hyperliquid. @public */
50
64
  export const HL_PRIMARY_TYPE_WITHDRAW =
51
65
  'HyperliquidTransaction:Withdraw' as const
52
- /** @public */
66
+ /** EIP-712 primary type for sending assets between Hyperliquid accounts or DEXes. @public */
53
67
  export const HL_PRIMARY_TYPE_SEND_ASSET =
54
68
  'HyperliquidTransaction:SendAsset' as const
55
- /** @public */
69
+ /** EIP-712 primary type used by the agent wallet authorization payload. @public */
56
70
  export const HL_PRIMARY_TYPE_AGENT = 'Agent' as const
57
71
 
58
- /** @public */
72
+ /**
73
+ * Union of EIP-712 primary type names supported by Hyperliquid signing actions.
74
+ * Values are the exact strings required in the typed-data domain.
75
+ * @public
76
+ */
59
77
  export type HlPrimaryType =
60
78
  | typeof HL_PRIMARY_TYPE_APPROVE_AGENT
61
79
  | typeof HL_PRIMARY_TYPE_APPROVE_BUILDER_FEE
@@ -1,6 +1,10 @@
1
1
  // Asset / market metadata returned by Hyperliquid `/info`.
2
2
 
3
- /** @public */
3
+ /**
4
+ * Perpetual market metadata from Hyperliquid `meta.universe`.
5
+ * `szDecimals` is the lot-size precision; `maxLeverage` is the venue cap.
6
+ * @public
7
+ */
4
8
  export type HlUniverseItem = {
5
9
  name: string
6
10
  szDecimals: number
@@ -11,12 +15,20 @@ export type HlUniverseItem = {
11
15
  isDelisted?: boolean
12
16
  }
13
17
 
14
- /** @public */
18
+ /**
19
+ * Perpetual metadata envelope returned by the Hyperliquid `meta` info query.
20
+ * @public
21
+ */
15
22
  export type HlMeta = {
16
23
  universe: HlUniverseItem[]
17
24
  }
18
25
 
19
- /** @public */
26
+ /**
27
+ * Live perpetual market context from Hyperliquid `metaAndAssetCtxs`.
28
+ * Prices, funding, open interest, and volume are decimal strings; `funding`
29
+ * is a rate and `dayNtlVlm` is 24-hour notional volume.
30
+ * @public
31
+ */
20
32
  export type HlAssetCtx = {
21
33
  funding: string
22
34
  openInterest: string
@@ -25,13 +37,21 @@ export type HlAssetCtx = {
25
37
  markPx: string
26
38
  }
27
39
 
28
- /** @public */
40
+ /**
41
+ * Tuple returned by `metaAndAssetCtxs`: static universe metadata followed by
42
+ * one live context per universe entry.
43
+ * @public
44
+ */
29
45
  export type HlMetaAndAssetCtxs = [HlMeta, HlAssetCtx[]]
30
46
 
31
- /** @public */
47
+ /** Alias for the perpetual universe array in {@link HlMeta}. @public */
32
48
  export type HlUniverse = HlMeta['universe']
33
49
 
34
- /** @public */
50
+ /**
51
+ * OHLCV candle from Hyperliquid's candle feed. `t` is the opening timestamp
52
+ * in milliseconds; prices and volume are decimal strings.
53
+ * @public
54
+ */
35
55
  export type HlCandle = {
36
56
  t: number
37
57
  o: string
@@ -41,26 +61,43 @@ export type HlCandle = {
41
61
  v: string
42
62
  }
43
63
 
44
- /** @public */
64
+ /** Snapshot array of {@link HlCandle} values, ordered by the upstream feed. @public */
45
65
  export type HlCandleSnapshot = HlCandle[]
46
66
 
47
- /** @public */
67
+ /**
68
+ * One L2 order-book level. `px` is price, `sz` is aggregate size, and `n` is
69
+ * the number of orders at that price; numeric values are wire strings except
70
+ * for the order count.
71
+ * @public
72
+ */
48
73
  export type HlLevel = {
49
74
  px: string
50
75
  sz: string
51
76
  n: number
52
77
  }
53
78
 
54
- /** @public */
79
+ /**
80
+ * L2 order-book snapshot with bid levels at index 0 and ask levels at index 1.
81
+ * `time` is the snapshot timestamp in milliseconds.
82
+ * @public
83
+ */
55
84
  export type HlL2Book = {
56
85
  levels: [HlLevel[], HlLevel[]]
57
86
  time: number
58
87
  }
59
88
 
60
- /** @public */
89
+ /**
90
+ * Perpetual DEX descriptors from Hyperliquid `perpDexs`; `null` represents the
91
+ * main DEX and named entries represent HIP-3 sub-DEXes.
92
+ * @public
93
+ */
61
94
  export type HlPerpDexs = (null | { name: string })[]
62
95
 
63
- /** @public */
96
+ /**
97
+ * Spot token metadata. `index` is the numeric token index used by spot
98
+ * clearinghouse balances; `tokenId` is the venue's wire identifier.
99
+ * @public
100
+ */
64
101
  export type HlSpotToken = {
65
102
  name: string
66
103
  index: number
@@ -68,7 +105,11 @@ export type HlSpotToken = {
68
105
  szDecimals: number
69
106
  }
70
107
 
71
- /** @public */
108
+ /**
109
+ * Spot universe entry describing a trading pair. `tokens` contains the two
110
+ * numeric token indexes used by the pair.
111
+ * @public
112
+ */
72
113
  export type HlSpotUniverseEntry = {
73
114
  name: string
74
115
  tokens: [number, number]
@@ -76,13 +117,17 @@ export type HlSpotUniverseEntry = {
76
117
  isCanonical: boolean
77
118
  }
78
119
 
79
- /** @public */
120
+ /** Spot metadata envelope containing token definitions and trading pairs. @public */
80
121
  export type HlSpotMeta = {
81
122
  tokens: HlSpotToken[]
82
123
  universe: HlSpotUniverseEntry[]
83
124
  }
84
125
 
85
- /** @public */
126
+ /**
127
+ * Live spot token context. Prices and 24-hour volume are decimal strings;
128
+ * `midPx` is `null` when the venue has no midpoint for the pair.
129
+ * @public
130
+ */
86
131
  export type HlSpotAssetCtx = {
87
132
  coin: string
88
133
  prevDayPx: string
@@ -91,5 +136,5 @@ export type HlSpotAssetCtx = {
91
136
  midPx: string | null
92
137
  }
93
138
 
94
- /** @public */
139
+ /** Tuple returned by the spot metadata/context info query. @public */
95
140
  export type HlSpotMetaAndAssetCtxs = [HlSpotMeta, HlSpotAssetCtx[]]
package/src/types/fill.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  // Fill shapes returned by Hyperliquid `/info`.
2
2
 
3
- /** @public */
3
+ /**
4
+ * One user trade fill returned by Hyperliquid `userFills` or
5
+ * `userFillsByTime`. Prices, size, fee, PnL, and starting position are decimal
6
+ * strings; `time` is milliseconds since the Unix epoch and `tid`/`oid` are
7
+ * numeric trade and order IDs.
8
+ * @public
9
+ */
4
10
  export type HlUserFill = {
5
11
  tid: number
6
12
  oid: number
@@ -17,8 +23,8 @@ export type HlUserFill = {
17
23
  startPosition: string
18
24
  }
19
25
 
20
- /** @public */
26
+ /** All fills returned by the unbounded `userFills` query. @public */
21
27
  export type HlUserFills = HlUserFill[]
22
28
 
23
- /** @public */
29
+ /** Fills returned by the time-bounded `userFillsByTime` query. @public */
24
30
  export type HlUserFillsByTime = HlUserFill[]
@@ -50,7 +50,11 @@ export type HlSendAssetDelta = {
50
50
  feeToken: string
51
51
  }
52
52
 
53
- /** @public */
53
+ /**
54
+ * Union of known Hyperliquid non-funding ledger deltas plus an open fallback
55
+ * for endpoint variants the provider does not map.
56
+ * @public
57
+ */
54
58
  export type HlLedgerDelta =
55
59
  | HlSpotTransferDelta
56
60
  | HlSendAssetDelta
@@ -81,17 +85,26 @@ export const isSendAssetDelta = (
81
85
  delta: HlLedgerDelta
82
86
  ): delta is HlSendAssetDelta => delta.type === 'send'
83
87
 
84
- /** @public */
88
+ /**
89
+ * One timestamped non-funding ledger update. `time` is milliseconds since
90
+ * epoch and `hash` is the upstream transaction identifier.
91
+ * @public
92
+ */
85
93
  export type HlLedgerUpdate = {
86
94
  time: number
87
95
  hash: string
88
96
  delta: HlLedgerDelta
89
97
  }
90
98
 
91
- /** @public */
99
+ /** Array returned by `userNonFundingLedgerUpdates`. @public */
92
100
  export type HlUserNonFundingLedgerUpdates = HlLedgerUpdate[]
93
101
 
94
- /** @public */
102
+ /**
103
+ * Funding ledger delta returned by Hyperliquid `userFunding`. `usdc` is the
104
+ * funding payment, `szi` is signed position size, and `fundingRate` is a
105
+ * decimal fraction; all are decimal strings.
106
+ * @public
107
+ */
95
108
  export type HlFundingDelta = {
96
109
  type: 'funding'
97
110
  coin: string
@@ -100,12 +113,17 @@ export type HlFundingDelta = {
100
113
  fundingRate: string
101
114
  }
102
115
 
103
- /** @public */
116
+ /**
117
+ * Timestamped funding update. `time` is milliseconds since epoch; `hash` is
118
+ * always the zero hash — funding is a system ledger event with no venue
119
+ * transaction behind it.
120
+ * @public
121
+ */
104
122
  export type HlFundingUpdate = {
105
123
  time: number
106
124
  hash: string
107
125
  delta: HlFundingDelta
108
126
  }
109
127
 
110
- /** @public */
128
+ /** Array returned by the `userFunding` info query. @public */
111
129
  export type HlUserFunding = HlFundingUpdate[]
@@ -1,6 +1,11 @@
1
1
  // Order shapes returned by Hyperliquid `/info`.
2
2
 
3
- /** @public */
3
+ /**
4
+ * Open order payload returned by Hyperliquid `frontendOpenOrders`.
5
+ * Sizes/prices are decimal strings; timestamps are milliseconds. Trigger
6
+ * flags and optional `children` describe attached TP/SL orders.
7
+ * @public
8
+ */
4
9
  export type HlFrontendOpenOrder = {
5
10
  oid: number
6
11
  coin: string
@@ -20,10 +25,15 @@ export type HlFrontendOpenOrder = {
20
25
  cloid: string | null
21
26
  }
22
27
 
23
- /** @public */
28
+ /** Array returned by the `frontendOpenOrders` info query. @public */
24
29
  export type HlFrontendOpenOrders = HlFrontendOpenOrder[]
25
30
 
26
- /** @public */
31
+ /**
32
+ * Order detail nested in an `orderStatus` response. `statusTimestamp` is the
33
+ * last status-change time in milliseconds; `triggerPx` is nullable for orders
34
+ * without a trigger.
35
+ * @public
36
+ */
27
37
  export type HlOrderDetail = {
28
38
  order: {
29
39
  oid: number
@@ -44,13 +54,17 @@ export type HlOrderDetail = {
44
54
  statusTimestamp: number
45
55
  }
46
56
 
47
- /** @public */
57
+ /** Successful `orderStatus` response containing the requested order. @public */
48
58
  export type HlOrderStatusFound = {
49
59
  status: 'order'
50
60
  order: HlOrderDetail
51
61
  }
52
62
 
53
- /** @public */
63
+ /**
64
+ * Result of `orderStatus`: either a found order or the exact `'unknownOid'`
65
+ * sentinel when Hyperliquid has no record for the numeric order ID.
66
+ * @public
67
+ */
54
68
  export type HlOrderStatusResponse =
55
69
  | HlOrderStatusFound
56
70
  | { status: 'unknownOid' }
package/src/types/ws.ts CHANGED
@@ -23,7 +23,11 @@ export type HlWsPerpAssetCtx = {
23
23
  oraclePx: string
24
24
  }
25
25
 
26
- /** @public */
26
+ /**
27
+ * Partial perp context carried by compressed (`pac`) updates. Omitted fields
28
+ * are unchanged from the prior context and must be merged by the consumer.
29
+ * @public
30
+ */
27
31
  export type HlWsPerpAssetCtxPayload = Partial<HlWsPerpAssetCtx>
28
32
 
29
33
  /**
@@ -44,7 +48,7 @@ export type HlWsAllDexsAssetCtxsData = {
44
48
  */
45
49
  export type HlWsPacData = [string, HlWsPerpAssetCtxPayload[]][]
46
50
 
47
- /** @public */
51
+ /** Generic Hyperliquid WS envelope; `channel` identifies the subscription and `data` is channel-specific. @public */
48
52
  export type HlWsMessage = {
49
53
  channel: string
50
54
  data: unknown
@@ -61,7 +65,12 @@ export type HlWsFastAssetCtx = {
61
65
  midPx?: string | null
62
66
  }
63
67
 
64
- /** @public */
68
+ /**
69
+ * Incremental spot asset context. Hyperliquid may encode numeric fields as
70
+ * strings or numbers and omits unchanged fields; `midPx: null` means no book
71
+ * midpoint is available.
72
+ * @public
73
+ */
65
74
  export type HlWsSpotAssetCtx = {
66
75
  dayNtlVlm?: HlWsNumberString
67
76
  prevDayPx?: HlWsNumberString
@@ -71,13 +80,13 @@ export type HlWsSpotAssetCtx = {
71
80
  circulatingSupply?: HlWsNumberString
72
81
  }
73
82
 
74
- /** @public */
83
+ /** Active perp context event keyed by its Hyperliquid wire coin. @public */
75
84
  export type HlWsActiveAssetCtxData = {
76
85
  coin: string
77
86
  ctx: Partial<Record<keyof HlWsPerpAssetCtx, HlWsNumberString | null>>
78
87
  }
79
88
 
80
- /** @public */
89
+ /** Active spot context event keyed by its Hyperliquid wire coin. @public */
81
90
  export type HlWsActiveSpotAssetCtxData = {
82
91
  coin: string
83
92
  ctx: HlWsSpotAssetCtx
@@ -90,23 +99,31 @@ export type HlWsActiveSpotAssetCtxData = {
90
99
  */
91
100
  export type HlWsSacData = Record<string, HlWsSpotAssetCtx>
92
101
 
93
- /** @public */
102
+ /** L2 snapshot envelope with the wire coin attached to {@link HlL2Book}. @public */
94
103
  export type HlWsL2BookData = HlL2Book & { coin: string }
95
104
 
96
- /** @public */
105
+ /**
106
+ * L2 channel payload. `s` is a full snapshot, while `u` is a compressed delta;
107
+ * `c` carries the checksum/control value when present.
108
+ * @public
109
+ */
97
110
  export type HlWsL2Data = {
98
111
  s?: HlL2Book & { coin: string }
99
112
  c?: string
100
113
  u?: HlWsCompressedL2Data
101
114
  }
102
115
 
103
- /** @public */
116
+ /** One level in a compressed L2 update: `p` is price and `s` is size. @public */
104
117
  export type HlWsCompressedL2Level = {
105
118
  p: string
106
119
  s: string
107
120
  }
108
121
 
109
- /** @public */
122
+ /**
123
+ * Compressed L2 delta. `t` is the update timestamp in milliseconds, `l` holds
124
+ * bid/ask levels, and optional `r` describes removals.
125
+ * @public
126
+ */
110
127
  export type HlWsCompressedL2Data = {
111
128
  c: string
112
129
  t: number
@@ -117,7 +134,11 @@ export type HlWsCompressedL2Data = {
117
134
  ]
118
135
  }
119
136
 
120
- /** @public */
137
+ /**
138
+ * Candle event payload. Inherited `t` is candle-open time; `T` is close time,
139
+ * `s` is the symbol, `i` is interval, and `n` is the trade count.
140
+ * @public
141
+ */
121
142
  export type HlWsCandleData = HlCandle & {
122
143
  T: number
123
144
  s: string
@@ -125,7 +146,11 @@ export type HlWsCandleData = HlCandle & {
125
146
  n: number
126
147
  }
127
148
 
128
- /** @public */
149
+ /**
150
+ * Public trade event. Prices and size are decimal strings; `time` is
151
+ * milliseconds since epoch, with optional trade ID and transaction hash.
152
+ * @public
153
+ */
129
154
  export type HlWsTrade = {
130
155
  coin: string
131
156
  side: string
@@ -136,14 +161,18 @@ export type HlWsTrade = {
136
161
  hash?: string
137
162
  }
138
163
 
139
- /** @public */
164
+ /** User fills event; `isSnapshot` distinguishes the initial snapshot from updates. @public */
140
165
  export type HlWsUserFillsData = {
141
166
  isSnapshot: boolean
142
167
  user: string
143
168
  fills: HlUserFill[]
144
169
  }
145
170
 
146
- /** @public */
171
+ /**
172
+ * Per-dex clearinghouse event for one user. Each tuple contains a wire DEX name
173
+ * and the perp positions/equity fields supplied by that DEX.
174
+ * @public
175
+ */
147
176
  export type HlWsAllDexsClearinghouseStateData = {
148
177
  user: string
149
178
  clearinghouseStates: [
@@ -152,7 +181,7 @@ export type HlWsAllDexsClearinghouseStateData = {
152
181
  ][]
153
182
  }
154
183
 
155
- /** @public */
184
+ /** User spot clearinghouse event containing the current spot balances. @public */
156
185
  export type HlWsSpotStateData = {
157
186
  user: string
158
187
  spotState: { balances: HlSpotBalance[] }
@@ -1,15 +1,14 @@
1
1
  /**
2
- * Spot asset IDs use the @pairIndex format (e.g. "@230").
3
- *
2
+ * Return whether a Hyperliquid asset ID identifies spot (`@<pairIndex>`).
3
+ * @param assetId - Raw Hyperliquid asset ID.
4
4
  * @public
5
5
  */
6
6
  export const assetIsSpot = (assetId: string): boolean => assetId.startsWith('@')
7
7
 
8
8
  /**
9
- * Calculate the asset ID for a given provider index and asset index.
10
- *
11
- * Main provider (provider = ''): assetId = indexInProvider
12
- * HIP-3 providers (provider = 'xyz'): assetId = 100_000 + perpDexIndex * 10_000 + indexInProvider
9
+ * Calculate Hyperliquid's numeric asset ID from a perp DEX index and the
10
+ * asset's zero-based index within that DEX. The main DEX uses the index
11
+ * directly; HIP-3 DEXes use `100000 + dexIndex * 10000 + assetIndex`.
13
12
  * @public
14
13
  */
15
14
  export const calculateAssetId = (
@@ -23,7 +22,8 @@ export const calculateAssetId = (
23
22
  }
24
23
 
25
24
  /**
26
- * Get the provider index from the given list of provider names.
25
+ * Find a sub-DEX's zero-based index in the names returned by Hyperliquid.
26
+ * @throws If `provider` is absent from `providerNames`.
27
27
  * @public
28
28
  */
29
29
  export const getProviderIndex = (