@lifi/perps-sdk-provider-hyperliquid 5.1.0 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (263) hide show
  1. package/dist/cjs/HyperliquidProvider.d.ts.map +1 -1
  2. package/dist/cjs/HyperliquidProvider.js +4 -0
  3. package/dist/cjs/HyperliquidProvider.js.map +1 -1
  4. package/dist/cjs/services/getAccount.d.ts.map +1 -1
  5. package/dist/cjs/services/getAccount.js +1 -1
  6. package/dist/cjs/services/getAccount.js.map +1 -1
  7. package/dist/cjs/services/getActivity.d.ts.map +1 -1
  8. package/dist/cjs/services/getActivity.js.map +1 -1
  9. package/dist/cjs/services/getFills.d.ts.map +1 -1
  10. package/dist/cjs/services/getFills.js.map +1 -1
  11. package/dist/cjs/services/getMarketSettings.d.ts +10 -0
  12. package/dist/cjs/services/getMarketSettings.d.ts.map +1 -0
  13. package/dist/cjs/services/getMarketSettings.js +26 -0
  14. package/dist/cjs/services/getMarketSettings.js.map +1 -0
  15. package/dist/cjs/services/getOrders.d.ts.map +1 -1
  16. package/dist/cjs/services/getOrders.js.map +1 -1
  17. package/dist/cjs/services/getPositions.d.ts.map +1 -1
  18. package/dist/cjs/services/getPositions.js +1 -1
  19. package/dist/cjs/services/getPositions.js.map +1 -1
  20. package/dist/cjs/signers/HyperliquidAgentStore.d.ts.map +1 -1
  21. package/dist/cjs/signers/HyperliquidAgentStore.js.map +1 -1
  22. package/dist/cjs/signers/signActions.d.ts.map +1 -1
  23. package/dist/cjs/signers/signActions.js.map +1 -1
  24. package/dist/cjs/types/account.d.ts +11 -0
  25. package/dist/cjs/types/account.d.ts.map +1 -1
  26. package/dist/cjs/types/account.js.map +1 -1
  27. package/dist/cjs/types/action.d.ts.map +1 -1
  28. package/dist/cjs/types/action.js.map +1 -1
  29. package/dist/cjs/types/asset.d.ts +1 -0
  30. package/dist/cjs/types/asset.d.ts.map +1 -1
  31. package/dist/cjs/types/fill.d.ts.map +1 -1
  32. package/dist/cjs/types/ledger.d.ts.map +1 -1
  33. package/dist/cjs/types/ledger.js.map +1 -1
  34. package/dist/cjs/types/order.d.ts.map +1 -1
  35. package/dist/cjs/types/ws.d.ts.map +1 -1
  36. package/dist/cjs/utils/assetId.d.ts.map +1 -1
  37. package/dist/cjs/utils/assetId.js.map +1 -1
  38. package/dist/cjs/utils/assetLogo.d.ts.map +1 -1
  39. package/dist/cjs/utils/assetLogo.js.map +1 -1
  40. package/dist/cjs/utils/decodeFastAssetCtxs.d.ts.map +1 -1
  41. package/dist/cjs/utils/decodeFastAssetCtxs.js.map +1 -1
  42. package/dist/cjs/utils/index.d.ts +1 -0
  43. package/dist/cjs/utils/index.d.ts.map +1 -1
  44. package/dist/cjs/utils/index.js +3 -1
  45. package/dist/cjs/utils/index.js.map +1 -1
  46. package/dist/cjs/utils/infoClient.d.ts.map +1 -1
  47. package/dist/cjs/utils/infoClient.js.map +1 -1
  48. package/dist/cjs/utils/mapActivity.d.ts.map +1 -1
  49. package/dist/cjs/utils/mapActivity.js +13 -10
  50. package/dist/cjs/utils/mapActivity.js.map +1 -1
  51. package/dist/cjs/utils/mapFill.d.ts.map +1 -1
  52. package/dist/cjs/utils/mapFill.js.map +1 -1
  53. package/dist/cjs/utils/mapMarket.d.ts.map +1 -1
  54. package/dist/cjs/utils/mapMarket.js +6 -1
  55. package/dist/cjs/utils/mapMarket.js.map +1 -1
  56. package/dist/cjs/utils/mapOrder.d.ts.map +1 -1
  57. package/dist/cjs/utils/mapOrder.js.map +1 -1
  58. package/dist/cjs/utils/mapPosition.d.ts +2 -2
  59. package/dist/cjs/utils/mapPosition.d.ts.map +1 -1
  60. package/dist/cjs/utils/mapPosition.js +17 -10
  61. package/dist/cjs/utils/mapPosition.js.map +1 -1
  62. package/dist/cjs/utils/spotBalance.d.ts.map +1 -1
  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.map +1 -1
  66. package/dist/cjs/utils/transferMargin.d.ts +3 -0
  67. package/dist/cjs/utils/transferMargin.d.ts.map +1 -0
  68. package/dist/cjs/utils/transferMargin.js +40 -0
  69. package/dist/cjs/utils/transferMargin.js.map +1 -0
  70. package/dist/cjs/websocket/HyperliquidWsProvider.d.ts.map +1 -1
  71. package/dist/cjs/websocket/HyperliquidWsProvider.js +3 -1
  72. package/dist/cjs/websocket/HyperliquidWsProvider.js.map +1 -1
  73. package/dist/esm/HyperliquidProvider.d.ts +14 -4
  74. package/dist/esm/HyperliquidProvider.d.ts.map +1 -1
  75. package/dist/esm/HyperliquidProvider.js +4 -0
  76. package/dist/esm/HyperliquidProvider.js.map +1 -1
  77. package/dist/esm/services/getAccount.d.ts.map +1 -1
  78. package/dist/esm/services/getAccount.js +2 -2
  79. package/dist/esm/services/getAccount.js.map +1 -1
  80. package/dist/esm/services/getActivity.d.ts +5 -1
  81. package/dist/esm/services/getActivity.d.ts.map +1 -1
  82. package/dist/esm/services/getActivity.js.map +1 -1
  83. package/dist/esm/services/getFills.d.ts +4 -3
  84. package/dist/esm/services/getFills.d.ts.map +1 -1
  85. package/dist/esm/services/getFills.js.map +1 -1
  86. package/dist/esm/services/getMarketSettings.d.ts +21 -0
  87. package/dist/esm/services/getMarketSettings.d.ts.map +1 -0
  88. package/dist/esm/services/getMarketSettings.js +29 -0
  89. package/dist/esm/services/getMarketSettings.js.map +1 -0
  90. package/dist/esm/services/getOrders.d.ts +2 -1
  91. package/dist/esm/services/getOrders.d.ts.map +1 -1
  92. package/dist/esm/services/getOrders.js.map +1 -1
  93. package/dist/esm/services/getPositions.d.ts +2 -2
  94. package/dist/esm/services/getPositions.d.ts.map +1 -1
  95. package/dist/esm/services/getPositions.js +2 -2
  96. package/dist/esm/services/getPositions.js.map +1 -1
  97. package/dist/esm/signers/HyperliquidAgentStore.d.ts +3 -3
  98. package/dist/esm/signers/HyperliquidAgentStore.d.ts.map +1 -1
  99. package/dist/esm/signers/HyperliquidAgentStore.js +1 -0
  100. package/dist/esm/signers/HyperliquidAgentStore.js.map +1 -1
  101. package/dist/esm/signers/signActions.d.ts +8 -6
  102. package/dist/esm/signers/signActions.d.ts.map +1 -1
  103. package/dist/esm/signers/signActions.js +8 -6
  104. package/dist/esm/signers/signActions.js.map +1 -1
  105. package/dist/esm/types/account.d.ts +68 -8
  106. package/dist/esm/types/account.d.ts.map +1 -1
  107. package/dist/esm/types/account.js.map +1 -1
  108. package/dist/esm/types/action.d.ts +28 -10
  109. package/dist/esm/types/action.d.ts.map +1 -1
  110. package/dist/esm/types/action.js +7 -7
  111. package/dist/esm/types/action.js.map +1 -1
  112. package/dist/esm/types/asset.d.ts +62 -15
  113. package/dist/esm/types/asset.d.ts.map +1 -1
  114. package/dist/esm/types/fill.d.ts +9 -3
  115. package/dist/esm/types/fill.d.ts.map +1 -1
  116. package/dist/esm/types/ledger.d.ts +24 -6
  117. package/dist/esm/types/ledger.d.ts.map +1 -1
  118. package/dist/esm/types/ledger.js.map +1 -1
  119. package/dist/esm/types/order.d.ts +19 -5
  120. package/dist/esm/types/order.d.ts.map +1 -1
  121. package/dist/esm/types/ws.d.ts +43 -14
  122. package/dist/esm/types/ws.d.ts.map +1 -1
  123. package/dist/esm/utils/assetId.d.ts +7 -7
  124. package/dist/esm/utils/assetId.d.ts.map +1 -1
  125. package/dist/esm/utils/assetId.js +7 -7
  126. package/dist/esm/utils/assetId.js.map +1 -1
  127. package/dist/esm/utils/assetLogo.d.ts +15 -13
  128. package/dist/esm/utils/assetLogo.d.ts.map +1 -1
  129. package/dist/esm/utils/assetLogo.js +15 -13
  130. package/dist/esm/utils/assetLogo.js.map +1 -1
  131. package/dist/esm/utils/decodeFastAssetCtxs.d.ts +7 -1
  132. package/dist/esm/utils/decodeFastAssetCtxs.d.ts.map +1 -1
  133. package/dist/esm/utils/decodeFastAssetCtxs.js +7 -1
  134. package/dist/esm/utils/decodeFastAssetCtxs.js.map +1 -1
  135. package/dist/esm/utils/index.d.ts +1 -0
  136. package/dist/esm/utils/index.d.ts.map +1 -1
  137. package/dist/esm/utils/index.js +1 -0
  138. package/dist/esm/utils/index.js.map +1 -1
  139. package/dist/esm/utils/infoClient.d.ts +6 -1
  140. package/dist/esm/utils/infoClient.d.ts.map +1 -1
  141. package/dist/esm/utils/infoClient.js.map +1 -1
  142. package/dist/esm/utils/mapActivity.d.ts +10 -1
  143. package/dist/esm/utils/mapActivity.d.ts.map +1 -1
  144. package/dist/esm/utils/mapActivity.js +23 -11
  145. package/dist/esm/utils/mapActivity.js.map +1 -1
  146. package/dist/esm/utils/mapFill.d.ts +1 -0
  147. package/dist/esm/utils/mapFill.d.ts.map +1 -1
  148. package/dist/esm/utils/mapFill.js +1 -0
  149. package/dist/esm/utils/mapFill.js.map +1 -1
  150. package/dist/esm/utils/mapMarket.d.ts.map +1 -1
  151. package/dist/esm/utils/mapMarket.js +8 -1
  152. package/dist/esm/utils/mapMarket.js.map +1 -1
  153. package/dist/esm/utils/mapOrder.d.ts +15 -4
  154. package/dist/esm/utils/mapOrder.d.ts.map +1 -1
  155. package/dist/esm/utils/mapOrder.js +15 -4
  156. package/dist/esm/utils/mapOrder.js.map +1 -1
  157. package/dist/esm/utils/mapPosition.d.ts +8 -3
  158. package/dist/esm/utils/mapPosition.d.ts.map +1 -1
  159. package/dist/esm/utils/mapPosition.js +20 -11
  160. package/dist/esm/utils/mapPosition.js.map +1 -1
  161. package/dist/esm/utils/spotBalance.d.ts +9 -10
  162. package/dist/esm/utils/spotBalance.d.ts.map +1 -1
  163. package/dist/esm/utils/spotBalance.js +9 -10
  164. package/dist/esm/utils/spotBalance.js.map +1 -1
  165. package/dist/esm/utils/spotCollateral.d.ts +9 -5
  166. package/dist/esm/utils/spotCollateral.d.ts.map +1 -1
  167. package/dist/esm/utils/spotCollateral.js +4 -4
  168. package/dist/esm/utils/spotCollateral.js.map +1 -1
  169. package/dist/esm/utils/transferMargin.d.ts +14 -0
  170. package/dist/esm/utils/transferMargin.d.ts.map +1 -0
  171. package/dist/esm/utils/transferMargin.js +45 -0
  172. package/dist/esm/utils/transferMargin.js.map +1 -0
  173. package/dist/esm/websocket/HyperliquidWsProvider.d.ts.map +1 -1
  174. package/dist/esm/websocket/HyperliquidWsProvider.js +4 -2
  175. package/dist/esm/websocket/HyperliquidWsProvider.js.map +1 -1
  176. package/dist/types/HyperliquidProvider.d.ts +14 -4
  177. package/dist/types/HyperliquidProvider.d.ts.map +1 -1
  178. package/dist/types/services/getAccount.d.ts.map +1 -1
  179. package/dist/types/services/getActivity.d.ts +5 -1
  180. package/dist/types/services/getActivity.d.ts.map +1 -1
  181. package/dist/types/services/getFills.d.ts +4 -3
  182. package/dist/types/services/getFills.d.ts.map +1 -1
  183. package/dist/types/services/getMarketSettings.d.ts +21 -0
  184. package/dist/types/services/getMarketSettings.d.ts.map +1 -0
  185. package/dist/types/services/getOrders.d.ts +2 -1
  186. package/dist/types/services/getOrders.d.ts.map +1 -1
  187. package/dist/types/services/getPositions.d.ts +2 -2
  188. package/dist/types/services/getPositions.d.ts.map +1 -1
  189. package/dist/types/signers/HyperliquidAgentStore.d.ts +3 -3
  190. package/dist/types/signers/HyperliquidAgentStore.d.ts.map +1 -1
  191. package/dist/types/signers/signActions.d.ts +8 -6
  192. package/dist/types/signers/signActions.d.ts.map +1 -1
  193. package/dist/types/types/account.d.ts +68 -8
  194. package/dist/types/types/account.d.ts.map +1 -1
  195. package/dist/types/types/action.d.ts +28 -10
  196. package/dist/types/types/action.d.ts.map +1 -1
  197. package/dist/types/types/asset.d.ts +62 -15
  198. package/dist/types/types/asset.d.ts.map +1 -1
  199. package/dist/types/types/fill.d.ts +9 -3
  200. package/dist/types/types/fill.d.ts.map +1 -1
  201. package/dist/types/types/ledger.d.ts +24 -6
  202. package/dist/types/types/ledger.d.ts.map +1 -1
  203. package/dist/types/types/order.d.ts +19 -5
  204. package/dist/types/types/order.d.ts.map +1 -1
  205. package/dist/types/types/ws.d.ts +43 -14
  206. package/dist/types/types/ws.d.ts.map +1 -1
  207. package/dist/types/utils/assetId.d.ts +7 -7
  208. package/dist/types/utils/assetId.d.ts.map +1 -1
  209. package/dist/types/utils/assetLogo.d.ts +15 -13
  210. package/dist/types/utils/assetLogo.d.ts.map +1 -1
  211. package/dist/types/utils/decodeFastAssetCtxs.d.ts +7 -1
  212. package/dist/types/utils/decodeFastAssetCtxs.d.ts.map +1 -1
  213. package/dist/types/utils/index.d.ts +1 -0
  214. package/dist/types/utils/index.d.ts.map +1 -1
  215. package/dist/types/utils/infoClient.d.ts +6 -1
  216. package/dist/types/utils/infoClient.d.ts.map +1 -1
  217. package/dist/types/utils/mapActivity.d.ts +10 -1
  218. package/dist/types/utils/mapActivity.d.ts.map +1 -1
  219. package/dist/types/utils/mapFill.d.ts +1 -0
  220. package/dist/types/utils/mapFill.d.ts.map +1 -1
  221. package/dist/types/utils/mapMarket.d.ts.map +1 -1
  222. package/dist/types/utils/mapOrder.d.ts +15 -4
  223. package/dist/types/utils/mapOrder.d.ts.map +1 -1
  224. package/dist/types/utils/mapPosition.d.ts +8 -3
  225. package/dist/types/utils/mapPosition.d.ts.map +1 -1
  226. package/dist/types/utils/spotBalance.d.ts +9 -10
  227. package/dist/types/utils/spotBalance.d.ts.map +1 -1
  228. package/dist/types/utils/spotCollateral.d.ts +9 -5
  229. package/dist/types/utils/spotCollateral.d.ts.map +1 -1
  230. package/dist/types/utils/transferMargin.d.ts +14 -0
  231. package/dist/types/utils/transferMargin.d.ts.map +1 -0
  232. package/dist/types/websocket/HyperliquidWsProvider.d.ts.map +1 -1
  233. package/package.json +3 -3
  234. package/src/HyperliquidProvider.ts +30 -4
  235. package/src/services/getAccount.ts +7 -1
  236. package/src/services/getActivity.ts +5 -1
  237. package/src/services/getFills.ts +4 -3
  238. package/src/services/getMarketSettings.ts +56 -0
  239. package/src/services/getOrders.ts +2 -1
  240. package/src/services/getPositions.ts +13 -4
  241. package/src/signers/HyperliquidAgentStore.ts +3 -3
  242. package/src/signers/signActions.ts +8 -6
  243. package/src/types/account.ts +66 -8
  244. package/src/types/action.ts +28 -10
  245. package/src/types/asset.ts +62 -15
  246. package/src/types/fill.ts +9 -3
  247. package/src/types/ledger.ts +24 -6
  248. package/src/types/order.ts +19 -5
  249. package/src/types/ws.ts +43 -14
  250. package/src/utils/assetId.ts +7 -7
  251. package/src/utils/assetLogo.ts +15 -13
  252. package/src/utils/decodeFastAssetCtxs.ts +7 -1
  253. package/src/utils/index.ts +1 -0
  254. package/src/utils/infoClient.ts +6 -1
  255. package/src/utils/mapActivity.ts +23 -11
  256. package/src/utils/mapFill.ts +1 -0
  257. package/src/utils/mapMarket.ts +10 -1
  258. package/src/utils/mapOrder.ts +15 -4
  259. package/src/utils/mapPosition.ts +24 -15
  260. package/src/utils/spotBalance.ts +9 -10
  261. package/src/utils/spotCollateral.ts +9 -5
  262. package/src/utils/transferMargin.ts +65 -0
  263. package/src/websocket/HyperliquidWsProvider.ts +4 -1
@@ -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 = (
@@ -47,7 +47,12 @@ const UNIT_UNDERLYING_SYMBOL: Readonly<Record<string, string>> = {
47
47
  UANSEM: 'ANSEM',
48
48
  }
49
49
 
50
- /** Token `name`s of the Unit-bridged HL spot assets. */
50
+ /**
51
+ * Names of Unit-bridged Hyperliquid spot tokens recognized by the logo
52
+ * resolver. The set is read-only and is intended for callers that need to
53
+ * distinguish Unit balances before resolving their icons.
54
+ * @public
55
+ */
51
56
  export const UNIT_TOKEN_NAMES: ReadonlySet<string> = new Set(
52
57
  Object.keys(UNIT_UNDERLYING_SYMBOL)
53
58
  )
@@ -58,24 +63,21 @@ const unitSpotLogoURI = (name: string): string => {
58
63
  return underlying === undefined ? '' : `${HL_COIN_CDN}/${underlying}.svg`
59
64
  }
60
65
 
61
- /** Return `asset` with its `logoURI` replaced when a display-symbol override exists. */
66
+ /**
67
+ * Apply the provider's known symbol-specific logo corrections to an asset.
68
+ * Returns the original object when no override exists.
69
+ * @public
70
+ */
62
71
  export const applyLogoOverride = (asset: Asset): Asset => {
63
72
  const override = BASE_ASSET_LOGO_OVERRIDES[asset.displaySymbol]
64
73
  return override === undefined ? asset : { ...asset, logoURI: override }
65
74
  }
66
75
 
67
76
  /**
68
- * Override-aware logo URI for a Hyperliquid spot token. Base rule is
69
- * `coins/${name}_spot.svg`; a Unit-bridged token (`fullName` starts with
70
- * "Unit") resolves to its underlying's icon instead; the override table wins
71
- * over both.
72
- *
73
- * When `fullName` is absent — spot *balances* (`HlSpotBalance`) carry no
74
- * `fullName` and this issue deliberately does not fetch `spotMeta` on the
75
- * account path — the derivation degrades to the symbol-keyed override + base
76
- * `_spot` rule, so a Unit-bridged balance uses the base rule rather than its
77
- * underlying's icon. The registry path (which has `fullName`) keeps full Unit
78
- * resolution.
77
+ * Resolve the logo URI for a Hyperliquid spot token. Unit-bridged tokens use
78
+ * the underlying symbol's icon when `fullName` starts with `'Unit'`; otherwise
79
+ * the base URI is `coins/${name}_spot.svg`. Known symbol overrides win.
80
+ * @public
79
81
  */
80
82
  export const spotLogoURI = (name: string, fullName?: string | null): string => {
81
83
  const base = fullName?.startsWith('Unit')
@@ -1,6 +1,11 @@
1
1
  import type { HlWsFastAssetCtx } from '../types/index.js'
2
2
 
3
- /** Decode a base64 + raw-DEFLATE (RFC 1951) payload into parsed JSON. */
3
+ /**
4
+ * Decode a base64-encoded raw-DEFLATE payload and parse its UTF-8 JSON body.
5
+ * @typeParam T - Expected shape of the decoded JSON value.
6
+ * @throws If decompression or JSON parsing fails.
7
+ * @public
8
+ */
4
9
  export async function decodeCompressedJson<T>(base64: string): Promise<T> {
5
10
  const binary = atob(base64)
6
11
  const bytes = new Uint8Array(binary.length)
@@ -24,6 +29,7 @@ export async function decodeCompressedJson<T>(base64: string): Promise<T> {
24
29
  * (Node 18+, modern browsers), so no dependency is needed.
25
30
  *
26
31
  * @throws If the input is not valid base64 / raw-DEFLATE / JSON.
32
+ * @public
27
33
  */
28
34
  export async function decodeFastAssetCtxs(
29
35
  base64: string
@@ -46,3 +46,4 @@ export {
46
46
  spotPriceById,
47
47
  } from './spotBalance.js'
48
48
  export { partitionSpotBalances, type SpotPartition } from './spotCollateral.js'
49
+ export { positionMarginConstraints } from './transferMargin.js'
@@ -50,7 +50,12 @@ export const HYPERLIQUID_RETRY_DEFAULTS: ResolvedRetryPolicy = {
50
50
  },
51
51
  }
52
52
 
53
- /** @public */
53
+ /**
54
+ * Transport options for a direct Hyperliquid `/info` request. `policy`
55
+ * controls retries, `signal` cancels the request, and `fetchImpl` overrides
56
+ * the runtime's global `fetch` implementation.
57
+ * @public
58
+ */
54
59
  export interface InfoRequestOptions {
55
60
  signal?: AbortSignal
56
61
  policy?: ResolvedRetryPolicy
@@ -165,18 +165,30 @@ export const mapLedgerEntry = (
165
165
  }
166
166
  }
167
167
 
168
- /** @public */
168
+ /**
169
+ * Map a Hyperliquid funding ledger update to a normalized funding activity.
170
+ * `amount`, `positionSize`, and `fundingRate` retain the upstream decimal
171
+ * strings; `resolveMarket` supplies the provider-agnostic market metadata.
172
+ *
173
+ * `userFunding` entries all carry the zero hash, so a deterministic
174
+ * `funding:<coin>:<ISO time>` id is synthesized — funding accrues at most
175
+ * once per coin per hourly settlement, so the pair is unique per account.
176
+ * @public
177
+ */
169
178
  export const mapFundingActivity = (
170
179
  entry: HlFundingUpdate,
171
180
  providerKey: string,
172
181
  resolveMarket: (coin: string) => MarketDisplay
173
- ): FundingActivity => ({
174
- id: entry.hash,
175
- provider: providerKey,
176
- timestamp: new Date(entry.time).toISOString(),
177
- type: ActivityType.FUNDING,
178
- market: resolveMarket(entry.delta.coin),
179
- amount: entry.delta.usdc,
180
- positionSize: entry.delta.szi,
181
- fundingRate: entry.delta.fundingRate,
182
- })
182
+ ): FundingActivity => {
183
+ const timestamp = new Date(entry.time).toISOString()
184
+ return {
185
+ id: `funding:${entry.delta.coin}:${timestamp}`,
186
+ provider: providerKey,
187
+ timestamp,
188
+ type: ActivityType.FUNDING,
189
+ market: resolveMarket(entry.delta.coin),
190
+ amount: entry.delta.usdc,
191
+ positionSize: entry.delta.szi,
192
+ fundingRate: entry.delta.fundingRate,
193
+ }
194
+ }
@@ -14,6 +14,7 @@ import {
14
14
  import { SPOT_MARKET_ID } from '../constants.js'
15
15
  import type { HlUserFill } from '../types/index.js'
16
16
 
17
+ /** Re-export the shared fill-position classifier used by Hyperliquid mappings. @public */
17
18
  export { classifyFillFromPosition }
18
19
 
19
20
  /**
@@ -1,4 +1,5 @@
1
1
  import type { PerpsMarket } from '@lifi/perps-types'
2
+ import { PositionMarginAdjustment } from '@lifi/perps-types'
2
3
  import { PROVIDER_KEY } from '../constants.js'
3
4
  import type { HlUniverseItem } from '../types/index.js'
4
5
  import { calculateMaintenanceMarginRate } from './liquidation.js'
@@ -31,6 +32,14 @@ export const mapMarket = (
31
32
  szDecimals: universe.szDecimals,
32
33
  priceDecimals: getMaxPriceDecimals(universe.szDecimals),
33
34
  maxLeverage: universe.maxLeverage,
34
- onlyIsolated: universe.onlyIsolated === true,
35
+ onlyIsolated:
36
+ universe.marginMode !== undefined || universe.onlyIsolated === true,
37
+ // Deprecated `onlyIsolated` cannot distinguish strict-isolated from
38
+ // no-cross, so the ambiguous legacy shape fails closed as add-only.
39
+ positionMarginAdjustment:
40
+ universe.marginMode === 'noCross' ||
41
+ (universe.marginMode === undefined && universe.onlyIsolated !== true)
42
+ ? PositionMarginAdjustment.ADD_AND_REMOVE
43
+ : PositionMarginAdjustment.ADD_ONLY,
35
44
  maintenanceMarginRate: calculateMaintenanceMarginRate(universe.maxLeverage),
36
45
  })
@@ -34,7 +34,7 @@ export const mapOrderType = (orderType: string): OrderType => {
34
34
  }
35
35
  }
36
36
 
37
- /** @public */
37
+ /** Return whether an SDK order type represents a take-profit or stop trigger. @public */
38
38
  export const isTriggerType = (type: OrderType): boolean =>
39
39
  type === OrderType.TAKE_PROFIT_MARKET ||
40
40
  type === OrderType.TAKE_PROFIT_LIMIT ||
@@ -83,7 +83,11 @@ export const isTriggerOrder = (
83
83
  return isTriggerType(mapOrderType(o.orderType))
84
84
  }
85
85
 
86
- /** @public */
86
+ /**
87
+ * Map an open Hyperliquid order to the SDK's normalized open-order shape.
88
+ * Numeric IDs become strings and wire millisecond timestamps become ISO dates.
89
+ * @public
90
+ */
87
91
  export const mapOpenOrder = (
88
92
  o: HlFrontendOpenOrder,
89
93
  market: MarketDisplay
@@ -102,7 +106,10 @@ export const mapOpenOrder = (
102
106
  createdAt: new Date(o.timestamp).toISOString(),
103
107
  })
104
108
 
105
- /** @public */
109
+ /**
110
+ * Map a Hyperliquid trigger/TP-SL order to the SDK's trigger-order shape.
111
+ * @public
112
+ */
106
113
  export const mapTriggerOrder = (
107
114
  o: HlFrontendOpenOrder,
108
115
  market: MarketDisplay
@@ -232,7 +239,11 @@ const mapTimeInForce = (tif: string | undefined): TimeInForce | undefined => {
232
239
  }
233
240
  }
234
241
 
235
- /** @public */
242
+ /**
243
+ * Map an `orderStatus` detail to the SDK's normalized order shape, preserving
244
+ * decimal size/price strings and translating status, side, and time-in-force.
245
+ * @public
246
+ */
236
247
  export const mapOrder = (
237
248
  detail: HlOrderDetail,
238
249
  market: MarketDisplay
@@ -1,5 +1,6 @@
1
- import type { MarketDisplay, Position } from '@lifi/perps-types'
1
+ import type { PerpsMarketDisplay, Position } from '@lifi/perps-types'
2
2
  import { MarginMode, PositionSide } from '@lifi/perps-types'
3
+ import Big from 'big.js'
3
4
  import type { HlAssetPosition } from '../types/index.js'
4
5
 
5
6
  /**
@@ -11,30 +12,38 @@ import type { HlAssetPosition } from '../types/index.js'
11
12
  export const isOpenAssetPosition = (ap: HlAssetPosition): boolean =>
12
13
  Number.parseFloat(ap.position.szi) !== 0
13
14
 
14
- /** @public */
15
+ /**
16
+ * Map a non-zero Hyperliquid position payload to the SDK's normalized
17
+ * position. Signed wire size determines side; decimal strings remain strings
18
+ * in the normalized response.
19
+ * @public
20
+ */
15
21
  export const mapPosition = (
16
22
  ap: HlAssetPosition,
17
- market: MarketDisplay
23
+ market: PerpsMarketDisplay
18
24
  ): Position => {
19
25
  const pos = ap.position
20
- const szi = parseFloat(pos.szi)
26
+ const szi = new Big(pos.szi)
27
+ const positionValue = new Big(pos.positionValue).abs()
28
+ const leverage = new Big(pos.leverage.value)
29
+ const marginMode =
30
+ pos.leverage.type === 'cross' ? MarginMode.CROSS : MarginMode.ISOLATED
31
+ const marginUsed =
32
+ marginMode === MarginMode.ISOLATED
33
+ ? new Big(pos.marginUsed).minus(pos.unrealizedPnl).toFixed()
34
+ : pos.marginUsed
21
35
 
22
36
  return {
23
37
  market,
24
- side: szi >= 0 ? PositionSide.LONG : PositionSide.SHORT,
25
- size: Math.abs(szi).toString(),
38
+ side: szi.gte(0) ? PositionSide.LONG : PositionSide.SHORT,
39
+ size: szi.abs().toFixed(),
26
40
  entryPrice: pos.entryPx ?? '0',
27
- markPrice:
28
- pos.positionValue && szi !== 0
29
- ? (parseFloat(pos.positionValue) / Math.abs(szi)).toString()
30
- : '0',
41
+ markPrice: szi.eq(0) ? '0' : positionValue.div(szi.abs()).toFixed(),
31
42
  liquidationPrice: pos.liquidationPx ?? '0',
32
43
  unrealizedPnl: pos.unrealizedPnl,
33
44
  leverage: ap.position.leverage.value,
34
- marginUsed: pos.marginUsed,
35
- marginMode:
36
- ap.position.leverage.type === 'cross'
37
- ? MarginMode.CROSS
38
- : MarginMode.ISOLATED,
45
+ marginUsed,
46
+ initialMarginRequirement: positionValue.div(leverage).toFixed(),
47
+ marginMode,
39
48
  }
40
49
  }
@@ -6,10 +6,10 @@ import { spotLogoURI } from './assetLogo.js'
6
6
  import { coinAsset } from './marketDisplay.js'
7
7
 
8
8
  /**
9
- * USD price keyed by spot token index: each spot market's live USD price
10
- * (from `priceByMarketId`, keyed by `Market.id`) under its base-asset id, and
11
- * every market's quote-asset id at $1. A spot market absent from
12
- * `priceByMarketId` values its token at 0.
9
+ * Build USD prices keyed by spot token asset ID. Base tokens use the supplied
10
+ * market mark price; quote tokens default to exactly `$1`; missing base prices
11
+ * default to `0`.
12
+ * @public
13
13
  */
14
14
  export const spotPriceById = (
15
15
  markets: readonly Market[],
@@ -30,11 +30,10 @@ export const spotPriceById = (
30
30
  }
31
31
 
32
32
  /**
33
- * The held spot {@link Asset} for an HL balance: the venue token index
34
- * (`b.token`) as `Asset.id` equal to that token's spot `Market.baseAsset.id`
35
- * with display fields derived from the coin and the override-aware spot logo.
36
- * `HlSpotBalance` carries no `fullName`, so Unit-bridged balances take the base
37
- * `_spot` rule (see {@link spotLogoURI}).
33
+ * Convert a Hyperliquid spot balance's numeric token index into an SDK asset.
34
+ * The balance payload has no `fullName`, so logo resolution uses the base
35
+ * `_spot` URI rule rather than Unit-underlying lookup.
36
+ * @public
38
37
  */
39
38
  export const spotAssetFromToken = (b: HlSpotBalance): Asset => ({
40
39
  ...coinAsset(b.coin),
@@ -42,7 +41,7 @@ export const spotAssetFromToken = (b: HlSpotBalance): Asset => ({
42
41
  logoURI: spotLogoURI(b.coin),
43
42
  })
44
43
 
45
- /** Assemble a typed spot {@link Balance} from its resolved asset and raw size. */
44
+ /** Assemble a typed spot {@link Balance}; `total` is native token units and its USD value uses `priceById`. @public */
46
45
  export const spotBalance = (
47
46
  asset: Asset,
48
47
  total: string,
@@ -13,17 +13,21 @@ const PORTFOLIO_MARGIN_LTV: Readonly<Record<string, number>> = {
13
13
  UBTC: 0.5,
14
14
  }
15
15
 
16
- /** @internal */
16
+ /**
17
+ * Result of {@link partitionSpotBalances}: balances that count toward
18
+ * collateral and balances treated as ordinary holdings.
19
+ * @public
20
+ */
17
21
  export interface SpotPartition {
18
22
  collateralBalances: Balance[]
19
23
  balances: Balance[]
20
24
  }
21
25
 
22
26
  /**
23
- * Split spot balances into margin collateral and flat holdings. A balance is
24
- * collateral when its token is a category quote asset (full value) or, under
25
- * portfolio margin, an LTV-weighted asset (HYPE/BTC); everything else is a
26
- * flat holding.
27
+ * Partition spot balances into collateral and ordinary holdings. Quote assets
28
+ * are full-value collateral; portfolio-margin-supported assets retain their
29
+ * LTV as `collateralWeight`.
30
+ * @public
27
31
  */
28
32
  export const partitionSpotBalances = (
29
33
  spotBalances: readonly Balance[],