@nktkas/hyperliquid 0.25.7 → 0.25.9

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 (543) hide show
  1. package/CONTRIBUTING.md +26 -19
  2. package/README.md +57 -5
  3. package/esm/bin/cli.js +2 -1
  4. package/esm/bin/cli.js.map +1 -1
  5. package/esm/src/api/_common_schemas.d.ts +19 -0
  6. package/esm/src/api/_common_schemas.d.ts.map +1 -1
  7. package/esm/src/api/_common_schemas.js +15 -0
  8. package/esm/src/api/_common_schemas.js.map +1 -1
  9. package/esm/src/api/exchange/_base/_execute.d.ts +6 -7
  10. package/esm/src/api/exchange/_base/_execute.d.ts.map +1 -1
  11. package/esm/src/api/exchange/_base/_execute.js +67 -43
  12. package/esm/src/api/exchange/_base/_execute.js.map +1 -1
  13. package/esm/src/api/exchange/_base/_types.d.ts +0 -7
  14. package/esm/src/api/exchange/_base/_types.d.ts.map +1 -1
  15. package/esm/src/api/exchange/_base/mod.d.ts +0 -2
  16. package/esm/src/api/exchange/_base/mod.d.ts.map +1 -1
  17. package/esm/src/api/exchange/_base/mod.js +0 -2
  18. package/esm/src/api/exchange/_base/mod.js.map +1 -1
  19. package/esm/src/api/exchange/agentEnableDexAbstraction.d.ts.map +1 -1
  20. package/esm/src/api/exchange/agentEnableDexAbstraction.js +14 -7
  21. package/esm/src/api/exchange/agentEnableDexAbstraction.js.map +1 -1
  22. package/esm/src/api/exchange/approveAgent.d.ts.map +1 -1
  23. package/esm/src/api/exchange/approveAgent.js +16 -8
  24. package/esm/src/api/exchange/approveAgent.js.map +1 -1
  25. package/esm/src/api/exchange/approveBuilderFee.d.ts.map +1 -1
  26. package/esm/src/api/exchange/approveBuilderFee.js +16 -8
  27. package/esm/src/api/exchange/approveBuilderFee.js.map +1 -1
  28. package/esm/src/api/exchange/batchModify.d.ts.map +1 -1
  29. package/esm/src/api/exchange/batchModify.js +16 -10
  30. package/esm/src/api/exchange/batchModify.js.map +1 -1
  31. package/esm/src/api/exchange/cDeposit.d.ts.map +1 -1
  32. package/esm/src/api/exchange/cDeposit.js +16 -8
  33. package/esm/src/api/exchange/cDeposit.js.map +1 -1
  34. package/esm/src/api/exchange/cSignerAction.d.ts.map +1 -1
  35. package/esm/src/api/exchange/cSignerAction.js +15 -8
  36. package/esm/src/api/exchange/cSignerAction.js.map +1 -1
  37. package/esm/src/api/exchange/cValidatorAction.d.ts.map +1 -1
  38. package/esm/src/api/exchange/cValidatorAction.js +15 -8
  39. package/esm/src/api/exchange/cValidatorAction.js.map +1 -1
  40. package/esm/src/api/exchange/cWithdraw.d.ts.map +1 -1
  41. package/esm/src/api/exchange/cWithdraw.js +16 -8
  42. package/esm/src/api/exchange/cWithdraw.js.map +1 -1
  43. package/esm/src/api/exchange/cancel.d.ts.map +1 -1
  44. package/esm/src/api/exchange/cancel.js +16 -10
  45. package/esm/src/api/exchange/cancel.js.map +1 -1
  46. package/esm/src/api/exchange/cancelByCloid.d.ts.map +1 -1
  47. package/esm/src/api/exchange/cancelByCloid.js +16 -10
  48. package/esm/src/api/exchange/cancelByCloid.js.map +1 -1
  49. package/esm/src/api/exchange/claimRewards.d.ts.map +1 -1
  50. package/esm/src/api/exchange/claimRewards.js +14 -7
  51. package/esm/src/api/exchange/claimRewards.js.map +1 -1
  52. package/esm/src/api/exchange/convertToMultiSigUser.d.ts.map +1 -1
  53. package/esm/src/api/exchange/convertToMultiSigUser.js +16 -8
  54. package/esm/src/api/exchange/convertToMultiSigUser.js.map +1 -1
  55. package/esm/src/api/exchange/createSubAccount.d.ts.map +1 -1
  56. package/esm/src/api/exchange/createSubAccount.js +15 -8
  57. package/esm/src/api/exchange/createSubAccount.js.map +1 -1
  58. package/esm/src/api/exchange/createVault.d.ts.map +1 -1
  59. package/esm/src/api/exchange/createVault.js +15 -8
  60. package/esm/src/api/exchange/createVault.js.map +1 -1
  61. package/esm/src/api/exchange/evmUserModify.d.ts +1 -1
  62. package/esm/src/api/exchange/evmUserModify.d.ts.map +1 -1
  63. package/esm/src/api/exchange/evmUserModify.js +16 -9
  64. package/esm/src/api/exchange/evmUserModify.js.map +1 -1
  65. package/esm/src/api/exchange/linkStakingUser.d.ts +112 -0
  66. package/esm/src/api/exchange/linkStakingUser.d.ts.map +1 -0
  67. package/esm/src/api/exchange/linkStakingUser.js +99 -0
  68. package/esm/src/api/exchange/linkStakingUser.js.map +1 -0
  69. package/esm/src/api/exchange/modify.d.ts.map +1 -1
  70. package/esm/src/api/exchange/modify.js +16 -10
  71. package/esm/src/api/exchange/modify.js.map +1 -1
  72. package/esm/src/api/exchange/multiSig.d.ts +81 -0
  73. package/esm/src/api/exchange/multiSig.d.ts.map +1 -1
  74. package/esm/src/api/exchange/multiSig.js +17 -16
  75. package/esm/src/api/exchange/multiSig.js.map +1 -1
  76. package/esm/src/api/exchange/noop.d.ts.map +1 -1
  77. package/esm/src/api/exchange/noop.js +14 -7
  78. package/esm/src/api/exchange/noop.js.map +1 -1
  79. package/esm/src/api/exchange/order.d.ts.map +1 -1
  80. package/esm/src/api/exchange/order.js +16 -10
  81. package/esm/src/api/exchange/order.js.map +1 -1
  82. package/esm/src/api/exchange/perpDeploy.d.ts +58 -0
  83. package/esm/src/api/exchange/perpDeploy.d.ts.map +1 -1
  84. package/esm/src/api/exchange/perpDeploy.js +33 -8
  85. package/esm/src/api/exchange/perpDeploy.js.map +1 -1
  86. package/esm/src/api/exchange/registerReferrer.d.ts.map +1 -1
  87. package/esm/src/api/exchange/registerReferrer.js +15 -8
  88. package/esm/src/api/exchange/registerReferrer.js.map +1 -1
  89. package/esm/src/api/exchange/reserveRequestWeight.d.ts.map +1 -1
  90. package/esm/src/api/exchange/reserveRequestWeight.js +15 -8
  91. package/esm/src/api/exchange/reserveRequestWeight.js.map +1 -1
  92. package/esm/src/api/exchange/scheduleCancel.js +16 -10
  93. package/esm/src/api/exchange/scheduleCancel.js.map +1 -1
  94. package/esm/src/api/exchange/sendAsset.d.ts.map +1 -1
  95. package/esm/src/api/exchange/sendAsset.js +16 -8
  96. package/esm/src/api/exchange/sendAsset.js.map +1 -1
  97. package/esm/src/api/exchange/setDisplayName.d.ts.map +1 -1
  98. package/esm/src/api/exchange/setDisplayName.js +15 -8
  99. package/esm/src/api/exchange/setDisplayName.js.map +1 -1
  100. package/esm/src/api/exchange/setReferrer.d.ts.map +1 -1
  101. package/esm/src/api/exchange/setReferrer.js +15 -8
  102. package/esm/src/api/exchange/setReferrer.js.map +1 -1
  103. package/esm/src/api/exchange/spotDeploy.d.ts.map +1 -1
  104. package/esm/src/api/exchange/spotDeploy.js +15 -8
  105. package/esm/src/api/exchange/spotDeploy.js.map +1 -1
  106. package/esm/src/api/exchange/spotSend.d.ts.map +1 -1
  107. package/esm/src/api/exchange/spotSend.js +16 -8
  108. package/esm/src/api/exchange/spotSend.js.map +1 -1
  109. package/esm/src/api/exchange/spotUser.d.ts.map +1 -1
  110. package/esm/src/api/exchange/spotUser.js +15 -8
  111. package/esm/src/api/exchange/spotUser.js.map +1 -1
  112. package/esm/src/api/exchange/subAccountModify.d.ts.map +1 -1
  113. package/esm/src/api/exchange/subAccountModify.js +15 -8
  114. package/esm/src/api/exchange/subAccountModify.js.map +1 -1
  115. package/esm/src/api/exchange/subAccountSpotTransfer.d.ts.map +1 -1
  116. package/esm/src/api/exchange/subAccountSpotTransfer.js +15 -8
  117. package/esm/src/api/exchange/subAccountSpotTransfer.js.map +1 -1
  118. package/esm/src/api/exchange/subAccountTransfer.d.ts.map +1 -1
  119. package/esm/src/api/exchange/subAccountTransfer.js +15 -8
  120. package/esm/src/api/exchange/subAccountTransfer.js.map +1 -1
  121. package/esm/src/api/exchange/tokenDelegate.d.ts.map +1 -1
  122. package/esm/src/api/exchange/tokenDelegate.js +16 -8
  123. package/esm/src/api/exchange/tokenDelegate.js.map +1 -1
  124. package/esm/src/api/exchange/twapCancel.d.ts.map +1 -1
  125. package/esm/src/api/exchange/twapCancel.js +16 -10
  126. package/esm/src/api/exchange/twapCancel.js.map +1 -1
  127. package/esm/src/api/exchange/twapOrder.d.ts.map +1 -1
  128. package/esm/src/api/exchange/twapOrder.js +16 -10
  129. package/esm/src/api/exchange/twapOrder.js.map +1 -1
  130. package/esm/src/api/exchange/updateIsolatedMargin.d.ts.map +1 -1
  131. package/esm/src/api/exchange/updateIsolatedMargin.js +16 -10
  132. package/esm/src/api/exchange/updateIsolatedMargin.js.map +1 -1
  133. package/esm/src/api/exchange/updateLeverage.d.ts.map +1 -1
  134. package/esm/src/api/exchange/updateLeverage.js +16 -10
  135. package/esm/src/api/exchange/updateLeverage.js.map +1 -1
  136. package/esm/src/api/exchange/usdClassTransfer.d.ts.map +1 -1
  137. package/esm/src/api/exchange/usdClassTransfer.js +16 -8
  138. package/esm/src/api/exchange/usdClassTransfer.js.map +1 -1
  139. package/esm/src/api/exchange/usdSend.d.ts.map +1 -1
  140. package/esm/src/api/exchange/usdSend.js +16 -8
  141. package/esm/src/api/exchange/usdSend.js.map +1 -1
  142. package/esm/src/api/exchange/userDexAbstraction.d.ts.map +1 -1
  143. package/esm/src/api/exchange/userDexAbstraction.js +16 -8
  144. package/esm/src/api/exchange/userDexAbstraction.js.map +1 -1
  145. package/esm/src/api/exchange/vaultDistribute.d.ts.map +1 -1
  146. package/esm/src/api/exchange/vaultDistribute.js +15 -8
  147. package/esm/src/api/exchange/vaultDistribute.js.map +1 -1
  148. package/esm/src/api/exchange/vaultModify.d.ts.map +1 -1
  149. package/esm/src/api/exchange/vaultModify.js +15 -8
  150. package/esm/src/api/exchange/vaultModify.js.map +1 -1
  151. package/esm/src/api/exchange/vaultTransfer.d.ts.map +1 -1
  152. package/esm/src/api/exchange/vaultTransfer.js +15 -8
  153. package/esm/src/api/exchange/vaultTransfer.js.map +1 -1
  154. package/esm/src/api/exchange/withdraw3.d.ts.map +1 -1
  155. package/esm/src/api/exchange/withdraw3.js +16 -8
  156. package/esm/src/api/exchange/withdraw3.js.map +1 -1
  157. package/esm/src/api/exchange/~client.d.ts +31 -3
  158. package/esm/src/api/exchange/~client.d.ts.map +1 -1
  159. package/esm/src/api/exchange/~client.js +27 -4
  160. package/esm/src/api/exchange/~client.js.map +1 -1
  161. package/esm/src/api/exchange/~mod.d.ts +1 -0
  162. package/esm/src/api/exchange/~mod.d.ts.map +1 -1
  163. package/esm/src/api/exchange/~mod.js +1 -0
  164. package/esm/src/api/exchange/~mod.js.map +1 -1
  165. package/esm/src/api/info/allPerpMetas.d.ts +5 -0
  166. package/esm/src/api/info/allPerpMetas.d.ts.map +1 -1
  167. package/esm/src/api/info/meta.d.ts +5 -0
  168. package/esm/src/api/info/meta.d.ts.map +1 -1
  169. package/esm/src/api/info/meta.js +2 -0
  170. package/esm/src/api/info/meta.js.map +1 -1
  171. package/esm/src/api/info/metaAndAssetCtxs.d.ts +5 -0
  172. package/esm/src/api/info/metaAndAssetCtxs.d.ts.map +1 -1
  173. package/esm/src/api/info/perpDexs.d.ts +4 -0
  174. package/esm/src/api/info/perpDexs.d.ts.map +1 -1
  175. package/esm/src/api/info/perpDexs.js +5 -0
  176. package/esm/src/api/info/perpDexs.js.map +1 -1
  177. package/esm/src/api/info/spotClearinghouseState.d.ts +0 -5
  178. package/esm/src/api/info/spotClearinghouseState.d.ts.map +1 -1
  179. package/esm/src/api/info/spotClearinghouseState.js +2 -14
  180. package/esm/src/api/info/spotClearinghouseState.js.map +1 -1
  181. package/esm/src/api/info/userFees.d.ts +27 -2
  182. package/esm/src/api/info/userFees.d.ts.map +1 -1
  183. package/esm/src/api/info/userFees.js +29 -1
  184. package/esm/src/api/info/userFees.js.map +1 -1
  185. package/esm/src/api/info/webData2.d.ts +6 -0
  186. package/esm/src/api/info/webData2.d.ts.map +1 -1
  187. package/esm/src/api/info/~client.d.ts +9 -1
  188. package/esm/src/api/info/~client.d.ts.map +1 -1
  189. package/esm/src/api/subscription/spotState.d.ts +91 -0
  190. package/esm/src/api/subscription/spotState.d.ts.map +1 -0
  191. package/esm/src/api/subscription/spotState.js +58 -0
  192. package/esm/src/api/subscription/spotState.js.map +1 -0
  193. package/esm/src/api/subscription/userEvents.d.ts +166 -141
  194. package/esm/src/api/subscription/userEvents.d.ts.map +1 -1
  195. package/esm/src/api/subscription/userEvents.js +6 -1
  196. package/esm/src/api/subscription/userEvents.js.map +1 -1
  197. package/esm/src/api/subscription/webData2.d.ts +5 -0
  198. package/esm/src/api/subscription/webData2.d.ts.map +1 -1
  199. package/esm/src/api/subscription/~client.d.ts +22 -0
  200. package/esm/src/api/subscription/~client.d.ts.map +1 -1
  201. package/esm/src/api/subscription/~client.js +23 -0
  202. package/esm/src/api/subscription/~client.js.map +1 -1
  203. package/esm/src/api/subscription/~mod.d.ts +1 -0
  204. package/esm/src/api/subscription/~mod.d.ts.map +1 -1
  205. package/esm/src/api/subscription/~mod.js +1 -0
  206. package/esm/src/api/subscription/~mod.js.map +1 -1
  207. package/esm/src/signing/_signTypedData.d.ts +1 -1
  208. package/esm/src/signing/_signTypedData.d.ts.map +1 -1
  209. package/esm/src/signing/_signTypedData.js +1 -1
  210. package/esm/src/signing/_signTypedData.js.map +1 -1
  211. package/esm/src/transport/websocket/_hyperliquid_event_target.d.ts +7 -0
  212. package/esm/src/transport/websocket/_hyperliquid_event_target.d.ts.map +1 -1
  213. package/esm/src/transport/websocket/_hyperliquid_event_target.js.map +1 -1
  214. package/esm/src/transport/websocket/_websocket_async_request.d.ts.map +1 -1
  215. package/esm/src/transport/websocket/_websocket_async_request.js +6 -0
  216. package/esm/src/transport/websocket/_websocket_async_request.js.map +1 -1
  217. package/esm/src/utils/{_minimalEIP712Signer.d.ts → _eip712.d.ts} +16 -1
  218. package/esm/src/utils/_eip712.d.ts.map +1 -0
  219. package/esm/src/utils/{_minimalEIP712Signer.js → _eip712.js} +14 -11
  220. package/esm/src/utils/_eip712.js.map +1 -0
  221. package/esm/src/utils/_format.d.ts +3 -4
  222. package/esm/src/utils/_format.d.ts.map +1 -1
  223. package/esm/src/utils/_format.js +98 -88
  224. package/esm/src/utils/_format.js.map +1 -1
  225. package/esm/src/utils/_recover.d.ts +89 -0
  226. package/esm/src/utils/_recover.d.ts.map +1 -0
  227. package/esm/src/utils/_recover.js +119 -0
  228. package/esm/src/utils/_recover.js.map +1 -0
  229. package/esm/src/utils/mod.d.ts +1 -0
  230. package/esm/src/utils/mod.d.ts.map +1 -1
  231. package/esm/src/utils/mod.js +1 -0
  232. package/esm/src/utils/mod.js.map +1 -1
  233. package/package.json +3 -2
  234. package/script/bin/cli.js +2 -1
  235. package/script/bin/cli.js.map +1 -1
  236. package/script/src/api/_common_schemas.d.ts +19 -0
  237. package/script/src/api/_common_schemas.d.ts.map +1 -1
  238. package/script/src/api/_common_schemas.js +16 -1
  239. package/script/src/api/_common_schemas.js.map +1 -1
  240. package/script/src/api/exchange/_base/_execute.d.ts +6 -7
  241. package/script/src/api/exchange/_base/_execute.d.ts.map +1 -1
  242. package/script/src/api/exchange/_base/_execute.js +67 -43
  243. package/script/src/api/exchange/_base/_execute.js.map +1 -1
  244. package/script/src/api/exchange/_base/_types.d.ts +0 -7
  245. package/script/src/api/exchange/_base/_types.d.ts.map +1 -1
  246. package/script/src/api/exchange/_base/mod.d.ts +0 -2
  247. package/script/src/api/exchange/_base/mod.d.ts.map +1 -1
  248. package/script/src/api/exchange/_base/mod.js +0 -2
  249. package/script/src/api/exchange/_base/mod.js.map +1 -1
  250. package/script/src/api/exchange/agentEnableDexAbstraction.d.ts.map +1 -1
  251. package/script/src/api/exchange/agentEnableDexAbstraction.js +14 -7
  252. package/script/src/api/exchange/agentEnableDexAbstraction.js.map +1 -1
  253. package/script/src/api/exchange/approveAgent.d.ts.map +1 -1
  254. package/script/src/api/exchange/approveAgent.js +15 -7
  255. package/script/src/api/exchange/approveAgent.js.map +1 -1
  256. package/script/src/api/exchange/approveBuilderFee.d.ts.map +1 -1
  257. package/script/src/api/exchange/approveBuilderFee.js +15 -7
  258. package/script/src/api/exchange/approveBuilderFee.js.map +1 -1
  259. package/script/src/api/exchange/batchModify.d.ts.map +1 -1
  260. package/script/src/api/exchange/batchModify.js +16 -10
  261. package/script/src/api/exchange/batchModify.js.map +1 -1
  262. package/script/src/api/exchange/cDeposit.d.ts.map +1 -1
  263. package/script/src/api/exchange/cDeposit.js +15 -7
  264. package/script/src/api/exchange/cDeposit.js.map +1 -1
  265. package/script/src/api/exchange/cSignerAction.d.ts.map +1 -1
  266. package/script/src/api/exchange/cSignerAction.js +15 -8
  267. package/script/src/api/exchange/cSignerAction.js.map +1 -1
  268. package/script/src/api/exchange/cValidatorAction.d.ts.map +1 -1
  269. package/script/src/api/exchange/cValidatorAction.js +15 -8
  270. package/script/src/api/exchange/cValidatorAction.js.map +1 -1
  271. package/script/src/api/exchange/cWithdraw.d.ts.map +1 -1
  272. package/script/src/api/exchange/cWithdraw.js +15 -7
  273. package/script/src/api/exchange/cWithdraw.js.map +1 -1
  274. package/script/src/api/exchange/cancel.d.ts.map +1 -1
  275. package/script/src/api/exchange/cancel.js +16 -10
  276. package/script/src/api/exchange/cancel.js.map +1 -1
  277. package/script/src/api/exchange/cancelByCloid.d.ts.map +1 -1
  278. package/script/src/api/exchange/cancelByCloid.js +16 -10
  279. package/script/src/api/exchange/cancelByCloid.js.map +1 -1
  280. package/script/src/api/exchange/claimRewards.d.ts.map +1 -1
  281. package/script/src/api/exchange/claimRewards.js +14 -7
  282. package/script/src/api/exchange/claimRewards.js.map +1 -1
  283. package/script/src/api/exchange/convertToMultiSigUser.d.ts.map +1 -1
  284. package/script/src/api/exchange/convertToMultiSigUser.js +15 -7
  285. package/script/src/api/exchange/convertToMultiSigUser.js.map +1 -1
  286. package/script/src/api/exchange/createSubAccount.d.ts.map +1 -1
  287. package/script/src/api/exchange/createSubAccount.js +15 -8
  288. package/script/src/api/exchange/createSubAccount.js.map +1 -1
  289. package/script/src/api/exchange/createVault.d.ts.map +1 -1
  290. package/script/src/api/exchange/createVault.js +15 -8
  291. package/script/src/api/exchange/createVault.js.map +1 -1
  292. package/script/src/api/exchange/evmUserModify.d.ts +1 -1
  293. package/script/src/api/exchange/evmUserModify.d.ts.map +1 -1
  294. package/script/src/api/exchange/evmUserModify.js +16 -9
  295. package/script/src/api/exchange/evmUserModify.js.map +1 -1
  296. package/script/src/api/exchange/linkStakingUser.d.ts +112 -0
  297. package/script/src/api/exchange/linkStakingUser.d.ts.map +1 -0
  298. package/script/src/api/exchange/linkStakingUser.js +136 -0
  299. package/script/src/api/exchange/linkStakingUser.js.map +1 -0
  300. package/script/src/api/exchange/modify.d.ts.map +1 -1
  301. package/script/src/api/exchange/modify.js +16 -10
  302. package/script/src/api/exchange/modify.js.map +1 -1
  303. package/script/src/api/exchange/multiSig.d.ts +81 -0
  304. package/script/src/api/exchange/multiSig.d.ts.map +1 -1
  305. package/script/src/api/exchange/multiSig.js +17 -16
  306. package/script/src/api/exchange/multiSig.js.map +1 -1
  307. package/script/src/api/exchange/noop.d.ts.map +1 -1
  308. package/script/src/api/exchange/noop.js +14 -7
  309. package/script/src/api/exchange/noop.js.map +1 -1
  310. package/script/src/api/exchange/order.d.ts.map +1 -1
  311. package/script/src/api/exchange/order.js +16 -10
  312. package/script/src/api/exchange/order.js.map +1 -1
  313. package/script/src/api/exchange/perpDeploy.d.ts +58 -0
  314. package/script/src/api/exchange/perpDeploy.d.ts.map +1 -1
  315. package/script/src/api/exchange/perpDeploy.js +33 -8
  316. package/script/src/api/exchange/perpDeploy.js.map +1 -1
  317. package/script/src/api/exchange/registerReferrer.d.ts.map +1 -1
  318. package/script/src/api/exchange/registerReferrer.js +15 -8
  319. package/script/src/api/exchange/registerReferrer.js.map +1 -1
  320. package/script/src/api/exchange/reserveRequestWeight.d.ts.map +1 -1
  321. package/script/src/api/exchange/reserveRequestWeight.js +15 -8
  322. package/script/src/api/exchange/reserveRequestWeight.js.map +1 -1
  323. package/script/src/api/exchange/scheduleCancel.js +16 -10
  324. package/script/src/api/exchange/scheduleCancel.js.map +1 -1
  325. package/script/src/api/exchange/sendAsset.d.ts.map +1 -1
  326. package/script/src/api/exchange/sendAsset.js +15 -7
  327. package/script/src/api/exchange/sendAsset.js.map +1 -1
  328. package/script/src/api/exchange/setDisplayName.d.ts.map +1 -1
  329. package/script/src/api/exchange/setDisplayName.js +15 -8
  330. package/script/src/api/exchange/setDisplayName.js.map +1 -1
  331. package/script/src/api/exchange/setReferrer.d.ts.map +1 -1
  332. package/script/src/api/exchange/setReferrer.js +15 -8
  333. package/script/src/api/exchange/setReferrer.js.map +1 -1
  334. package/script/src/api/exchange/spotDeploy.d.ts.map +1 -1
  335. package/script/src/api/exchange/spotDeploy.js +15 -8
  336. package/script/src/api/exchange/spotDeploy.js.map +1 -1
  337. package/script/src/api/exchange/spotSend.d.ts.map +1 -1
  338. package/script/src/api/exchange/spotSend.js +15 -7
  339. package/script/src/api/exchange/spotSend.js.map +1 -1
  340. package/script/src/api/exchange/spotUser.d.ts.map +1 -1
  341. package/script/src/api/exchange/spotUser.js +15 -8
  342. package/script/src/api/exchange/spotUser.js.map +1 -1
  343. package/script/src/api/exchange/subAccountModify.d.ts.map +1 -1
  344. package/script/src/api/exchange/subAccountModify.js +15 -8
  345. package/script/src/api/exchange/subAccountModify.js.map +1 -1
  346. package/script/src/api/exchange/subAccountSpotTransfer.d.ts.map +1 -1
  347. package/script/src/api/exchange/subAccountSpotTransfer.js +15 -8
  348. package/script/src/api/exchange/subAccountSpotTransfer.js.map +1 -1
  349. package/script/src/api/exchange/subAccountTransfer.d.ts.map +1 -1
  350. package/script/src/api/exchange/subAccountTransfer.js +15 -8
  351. package/script/src/api/exchange/subAccountTransfer.js.map +1 -1
  352. package/script/src/api/exchange/tokenDelegate.d.ts.map +1 -1
  353. package/script/src/api/exchange/tokenDelegate.js +15 -7
  354. package/script/src/api/exchange/tokenDelegate.js.map +1 -1
  355. package/script/src/api/exchange/twapCancel.d.ts.map +1 -1
  356. package/script/src/api/exchange/twapCancel.js +16 -10
  357. package/script/src/api/exchange/twapCancel.js.map +1 -1
  358. package/script/src/api/exchange/twapOrder.d.ts.map +1 -1
  359. package/script/src/api/exchange/twapOrder.js +16 -10
  360. package/script/src/api/exchange/twapOrder.js.map +1 -1
  361. package/script/src/api/exchange/updateIsolatedMargin.d.ts.map +1 -1
  362. package/script/src/api/exchange/updateIsolatedMargin.js +16 -10
  363. package/script/src/api/exchange/updateIsolatedMargin.js.map +1 -1
  364. package/script/src/api/exchange/updateLeverage.d.ts.map +1 -1
  365. package/script/src/api/exchange/updateLeverage.js +16 -10
  366. package/script/src/api/exchange/updateLeverage.js.map +1 -1
  367. package/script/src/api/exchange/usdClassTransfer.d.ts.map +1 -1
  368. package/script/src/api/exchange/usdClassTransfer.js +15 -7
  369. package/script/src/api/exchange/usdClassTransfer.js.map +1 -1
  370. package/script/src/api/exchange/usdSend.d.ts.map +1 -1
  371. package/script/src/api/exchange/usdSend.js +15 -7
  372. package/script/src/api/exchange/usdSend.js.map +1 -1
  373. package/script/src/api/exchange/userDexAbstraction.d.ts.map +1 -1
  374. package/script/src/api/exchange/userDexAbstraction.js +15 -7
  375. package/script/src/api/exchange/userDexAbstraction.js.map +1 -1
  376. package/script/src/api/exchange/vaultDistribute.d.ts.map +1 -1
  377. package/script/src/api/exchange/vaultDistribute.js +15 -8
  378. package/script/src/api/exchange/vaultDistribute.js.map +1 -1
  379. package/script/src/api/exchange/vaultModify.d.ts.map +1 -1
  380. package/script/src/api/exchange/vaultModify.js +15 -8
  381. package/script/src/api/exchange/vaultModify.js.map +1 -1
  382. package/script/src/api/exchange/vaultTransfer.d.ts.map +1 -1
  383. package/script/src/api/exchange/vaultTransfer.js +15 -8
  384. package/script/src/api/exchange/vaultTransfer.js.map +1 -1
  385. package/script/src/api/exchange/withdraw3.d.ts.map +1 -1
  386. package/script/src/api/exchange/withdraw3.js +15 -7
  387. package/script/src/api/exchange/withdraw3.js.map +1 -1
  388. package/script/src/api/exchange/~client.d.ts +31 -3
  389. package/script/src/api/exchange/~client.d.ts.map +1 -1
  390. package/script/src/api/exchange/~client.js +29 -6
  391. package/script/src/api/exchange/~client.js.map +1 -1
  392. package/script/src/api/exchange/~mod.d.ts +1 -0
  393. package/script/src/api/exchange/~mod.d.ts.map +1 -1
  394. package/script/src/api/exchange/~mod.js +1 -0
  395. package/script/src/api/exchange/~mod.js.map +1 -1
  396. package/script/src/api/info/allPerpMetas.d.ts +5 -0
  397. package/script/src/api/info/allPerpMetas.d.ts.map +1 -1
  398. package/script/src/api/info/meta.d.ts +5 -0
  399. package/script/src/api/info/meta.d.ts.map +1 -1
  400. package/script/src/api/info/meta.js +2 -0
  401. package/script/src/api/info/meta.js.map +1 -1
  402. package/script/src/api/info/metaAndAssetCtxs.d.ts +5 -0
  403. package/script/src/api/info/metaAndAssetCtxs.d.ts.map +1 -1
  404. package/script/src/api/info/perpDexs.d.ts +4 -0
  405. package/script/src/api/info/perpDexs.d.ts.map +1 -1
  406. package/script/src/api/info/perpDexs.js +5 -0
  407. package/script/src/api/info/perpDexs.js.map +1 -1
  408. package/script/src/api/info/spotClearinghouseState.d.ts +0 -5
  409. package/script/src/api/info/spotClearinghouseState.d.ts.map +1 -1
  410. package/script/src/api/info/spotClearinghouseState.js +2 -14
  411. package/script/src/api/info/spotClearinghouseState.js.map +1 -1
  412. package/script/src/api/info/userFees.d.ts +27 -2
  413. package/script/src/api/info/userFees.d.ts.map +1 -1
  414. package/script/src/api/info/userFees.js +29 -1
  415. package/script/src/api/info/userFees.js.map +1 -1
  416. package/script/src/api/info/webData2.d.ts +6 -0
  417. package/script/src/api/info/webData2.d.ts.map +1 -1
  418. package/script/src/api/info/~client.d.ts +9 -1
  419. package/script/src/api/info/~client.d.ts.map +1 -1
  420. package/script/src/api/subscription/spotState.d.ts +91 -0
  421. package/script/src/api/subscription/spotState.d.ts.map +1 -0
  422. package/script/src/api/subscription/spotState.js +95 -0
  423. package/script/src/api/subscription/spotState.js.map +1 -0
  424. package/script/src/api/subscription/userEvents.d.ts +166 -141
  425. package/script/src/api/subscription/userEvents.d.ts.map +1 -1
  426. package/script/src/api/subscription/userEvents.js +6 -1
  427. package/script/src/api/subscription/userEvents.js.map +1 -1
  428. package/script/src/api/subscription/webData2.d.ts +5 -0
  429. package/script/src/api/subscription/webData2.d.ts.map +1 -1
  430. package/script/src/api/subscription/~client.d.ts +22 -0
  431. package/script/src/api/subscription/~client.d.ts.map +1 -1
  432. package/script/src/api/subscription/~client.js +23 -0
  433. package/script/src/api/subscription/~client.js.map +1 -1
  434. package/script/src/api/subscription/~mod.d.ts +1 -0
  435. package/script/src/api/subscription/~mod.d.ts.map +1 -1
  436. package/script/src/api/subscription/~mod.js +1 -0
  437. package/script/src/api/subscription/~mod.js.map +1 -1
  438. package/script/src/signing/_signTypedData.d.ts +1 -1
  439. package/script/src/signing/_signTypedData.d.ts.map +1 -1
  440. package/script/src/signing/_signTypedData.js +1 -1
  441. package/script/src/signing/_signTypedData.js.map +1 -1
  442. package/script/src/transport/websocket/_hyperliquid_event_target.d.ts +7 -0
  443. package/script/src/transport/websocket/_hyperliquid_event_target.d.ts.map +1 -1
  444. package/script/src/transport/websocket/_hyperliquid_event_target.js.map +1 -1
  445. package/script/src/transport/websocket/_websocket_async_request.d.ts.map +1 -1
  446. package/script/src/transport/websocket/_websocket_async_request.js +6 -0
  447. package/script/src/transport/websocket/_websocket_async_request.js.map +1 -1
  448. package/script/src/utils/{_minimalEIP712Signer.d.ts → _eip712.d.ts} +16 -1
  449. package/script/src/utils/_eip712.d.ts.map +1 -0
  450. package/script/src/utils/{_minimalEIP712Signer.js → _eip712.js} +14 -9
  451. package/script/src/utils/_eip712.js.map +1 -0
  452. package/script/src/utils/_format.d.ts +3 -4
  453. package/script/src/utils/_format.d.ts.map +1 -1
  454. package/script/src/utils/_format.js +98 -88
  455. package/script/src/utils/_format.js.map +1 -1
  456. package/script/src/utils/_recover.d.ts +89 -0
  457. package/script/src/utils/_recover.d.ts.map +1 -0
  458. package/script/src/utils/_recover.js +156 -0
  459. package/script/src/utils/_recover.js.map +1 -0
  460. package/script/src/utils/mod.d.ts +1 -0
  461. package/script/src/utils/mod.d.ts.map +1 -1
  462. package/script/src/utils/mod.js +1 -0
  463. package/script/src/utils/mod.js.map +1 -1
  464. package/src/bin/cli.ts +2 -1
  465. package/src/src/api/_common_schemas.ts +34 -0
  466. package/src/src/api/exchange/_base/_execute.ts +73 -49
  467. package/src/src/api/exchange/_base/_types.ts +0 -7
  468. package/src/src/api/exchange/_base/mod.ts +0 -2
  469. package/src/src/api/exchange/agentEnableDexAbstraction.ts +14 -9
  470. package/src/src/api/exchange/approveAgent.ts +15 -12
  471. package/src/src/api/exchange/approveBuilderFee.ts +15 -12
  472. package/src/src/api/exchange/batchModify.ts +16 -13
  473. package/src/src/api/exchange/cDeposit.ts +15 -12
  474. package/src/src/api/exchange/cSignerAction.ts +15 -10
  475. package/src/src/api/exchange/cValidatorAction.ts +15 -10
  476. package/src/src/api/exchange/cWithdraw.ts +15 -12
  477. package/src/src/api/exchange/cancel.ts +16 -13
  478. package/src/src/api/exchange/cancelByCloid.ts +16 -13
  479. package/src/src/api/exchange/claimRewards.ts +14 -9
  480. package/src/src/api/exchange/convertToMultiSigUser.ts +15 -12
  481. package/src/src/api/exchange/createSubAccount.ts +15 -10
  482. package/src/src/api/exchange/createVault.ts +15 -10
  483. package/src/src/api/exchange/evmUserModify.ts +16 -11
  484. package/src/src/api/exchange/linkStakingUser.ts +157 -0
  485. package/src/src/api/exchange/modify.ts +16 -13
  486. package/src/src/api/exchange/multiSig.ts +17 -23
  487. package/src/src/api/exchange/noop.ts +14 -9
  488. package/src/src/api/exchange/order.ts +16 -13
  489. package/src/src/api/exchange/perpDeploy.ts +61 -10
  490. package/src/src/api/exchange/registerReferrer.ts +15 -10
  491. package/src/src/api/exchange/reserveRequestWeight.ts +15 -10
  492. package/src/src/api/exchange/scheduleCancel.ts +16 -13
  493. package/src/src/api/exchange/sendAsset.ts +15 -12
  494. package/src/src/api/exchange/setDisplayName.ts +15 -10
  495. package/src/src/api/exchange/setReferrer.ts +15 -10
  496. package/src/src/api/exchange/spotDeploy.ts +15 -10
  497. package/src/src/api/exchange/spotSend.ts +15 -12
  498. package/src/src/api/exchange/spotUser.ts +15 -10
  499. package/src/src/api/exchange/subAccountModify.ts +15 -10
  500. package/src/src/api/exchange/subAccountSpotTransfer.ts +15 -10
  501. package/src/src/api/exchange/subAccountTransfer.ts +15 -10
  502. package/src/src/api/exchange/tokenDelegate.ts +15 -12
  503. package/src/src/api/exchange/twapCancel.ts +16 -13
  504. package/src/src/api/exchange/twapOrder.ts +16 -13
  505. package/src/src/api/exchange/updateIsolatedMargin.ts +16 -13
  506. package/src/src/api/exchange/updateLeverage.ts +16 -13
  507. package/src/src/api/exchange/usdClassTransfer.ts +15 -12
  508. package/src/src/api/exchange/usdSend.ts +15 -12
  509. package/src/src/api/exchange/userDexAbstraction.ts +15 -12
  510. package/src/src/api/exchange/vaultDistribute.ts +15 -10
  511. package/src/src/api/exchange/vaultModify.ts +15 -10
  512. package/src/src/api/exchange/vaultTransfer.ts +15 -10
  513. package/src/src/api/exchange/withdraw3.ts +15 -12
  514. package/src/src/api/exchange/~client.ts +30 -5
  515. package/src/src/api/exchange/~mod.ts +1 -0
  516. package/src/src/api/info/meta.ts +7 -0
  517. package/src/src/api/info/perpDexs.ts +10 -0
  518. package/src/src/api/info/spotClearinghouseState.ts +3 -33
  519. package/src/src/api/info/userFees.ts +46 -1
  520. package/src/src/api/subscription/spotState.ts +96 -0
  521. package/src/src/api/subscription/userEvents.ts +11 -1
  522. package/src/src/api/subscription/~client.ts +25 -0
  523. package/src/src/api/subscription/~mod.ts +1 -0
  524. package/src/src/signing/_signTypedData.ts +1 -1
  525. package/src/src/transport/websocket/_hyperliquid_event_target.ts +7 -0
  526. package/src/src/transport/websocket/_websocket_async_request.ts +6 -0
  527. package/src/src/utils/{_minimalEIP712Signer.ts → _eip712.ts} +22 -29
  528. package/src/src/utils/_format.ts +99 -98
  529. package/src/src/utils/_recover.ts +178 -0
  530. package/src/src/utils/mod.ts +1 -0
  531. package/esm/src/api/exchange/_base/_sequential.d.ts +0 -30
  532. package/esm/src/api/exchange/_base/_sequential.d.ts.map +0 -1
  533. package/esm/src/api/exchange/_base/_sequential.js +0 -69
  534. package/esm/src/api/exchange/_base/_sequential.js.map +0 -1
  535. package/esm/src/utils/_minimalEIP712Signer.d.ts.map +0 -1
  536. package/esm/src/utils/_minimalEIP712Signer.js.map +0 -1
  537. package/script/src/api/exchange/_base/_sequential.d.ts +0 -30
  538. package/script/src/api/exchange/_base/_sequential.d.ts.map +0 -1
  539. package/script/src/api/exchange/_base/_sequential.js +0 -72
  540. package/script/src/api/exchange/_base/_sequential.js.map +0 -1
  541. package/script/src/utils/_minimalEIP712Signer.d.ts.map +0 -1
  542. package/script/src/utils/_minimalEIP712Signer.js.map +0 -1
  543. package/src/src/api/exchange/_base/_sequential.ts +0 -82
@@ -225,7 +225,52 @@ export const UserFeesResponse = /* @__PURE__ */ (() => {
225
225
  v.nullable(v.unknown()),
226
226
  v.description("Timestamp when next trial becomes available."),
227
227
  ),
228
- stakingLink: v.nullable(v.unknown()),
228
+ /**
229
+ * Permanent link between staking and trading accounts.
230
+ * Staking user gains full control of trading account funds.
231
+ * Staking user forfeits own fee discounts.
232
+ */
233
+ stakingLink: v.pipe(
234
+ v.nullable(
235
+ v.object({
236
+ /**
237
+ * Linked account address:
238
+ * - When queried by staking account: contains trading account address.
239
+ * - When queried by trading account: contains staking account address.
240
+ */
241
+ stakingUser: v.pipe(
242
+ Address,
243
+ v.description(
244
+ "Linked account address:" +
245
+ "\n- When queried by staking account: contains trading account address." +
246
+ "\n- When queried by trading account: contains staking account address.",
247
+ ),
248
+ ),
249
+ /**
250
+ * Link status:
251
+ * - `requested` = link initiated by trading user, awaiting staking user confirmation.
252
+ * - `stakingUser` = response queried by staking account.
253
+ * - `tradingUser` = response queried by trading account.
254
+ */
255
+ type: v.pipe(
256
+ v.union([
257
+ v.literal("requested"),
258
+ v.literal("stakingUser"),
259
+ v.literal("tradingUser"),
260
+ ]),
261
+ v.description(
262
+ "Link status:" +
263
+ "\n- `requested` = link initiated by trading user, awaiting staking user confirmation" +
264
+ "\n- `stakingUser` = response queried by staking account" +
265
+ "\n- `tradingUser` = response queried by trading account",
266
+ ),
267
+ ),
268
+ }),
269
+ ),
270
+ v.description(
271
+ "Permanent link between staking and trading accounts. Staking user gains full control of trading account funds. Staking user forfeits own fee discounts.",
272
+ ),
273
+ ),
229
274
  /** Active staking discount details. */
230
275
  activeStakingDiscount: v.pipe(
231
276
  v.object({
@@ -0,0 +1,96 @@
1
+ import * as v from "valibot";
2
+ import { Address, type DeepImmutable, parser } from "../_base.js";
3
+ import type { SubscriptionRequestConfig } from "./_types.js";
4
+ import type { Subscription } from "../../transport/base.js";
5
+
6
+ import { BalanceSchema } from "../_common_schemas.js";
7
+
8
+ // -------------------- Schemas --------------------
9
+
10
+ /** Subscription to spot state events for a specific user. */
11
+ export const SpotStateRequest = /* @__PURE__ */ (() => {
12
+ return v.pipe(
13
+ v.object({
14
+ /** Type of subscription. */
15
+ type: v.pipe(
16
+ v.literal("spotState"),
17
+ v.description("Type of subscription."),
18
+ ),
19
+ /** User address. */
20
+ user: v.pipe(
21
+ Address,
22
+ v.description("User address."),
23
+ ),
24
+ }),
25
+ v.description("Subscription to spot state events for a specific user."),
26
+ );
27
+ })();
28
+ export type SpotStateRequest = v.InferOutput<typeof SpotStateRequest>;
29
+
30
+ /** Event of user spot state. */
31
+ export const SpotStateEvent = /* @__PURE__ */ (() => {
32
+ return v.pipe(
33
+ v.object({
34
+ /** User address. */
35
+ user: v.pipe(
36
+ Address,
37
+ v.description("User address."),
38
+ ),
39
+ /** Spot state of the user. */
40
+ spotState: v.pipe(
41
+ v.object({
42
+ /** Balance for each token. */
43
+ balances: v.pipe(
44
+ v.array(BalanceSchema),
45
+ v.description("Balance for each token."),
46
+ ),
47
+ }),
48
+ v.description("Spot state of the user."),
49
+ ),
50
+ }),
51
+ v.description("Event of user spot state."),
52
+ );
53
+ })();
54
+ export type SpotStateEvent = v.InferOutput<typeof SpotStateEvent>;
55
+
56
+ // -------------------- Function --------------------
57
+
58
+ /** Request parameters for the {@linkcode spotState} function. */
59
+ export type SpotStateParameters = Omit<v.InferInput<typeof SpotStateRequest>, "type">;
60
+
61
+ /**
62
+ * Subscribe to spot state updates for a specific user.
63
+ * @param config - General configuration for Subscription API subscriptions.
64
+ * @param params - Parameters specific to the API subscription.
65
+ * @param listener - A callback function to be called when the event is received.
66
+ * @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
67
+ *
68
+ * @throws {TransportError} When the transport layer throws an error.
69
+ *
70
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
71
+ * @example
72
+ * ```ts
73
+ * import { WebSocketTransport } from "@nktkas/hyperliquid";
74
+ * import { spotState } from "@nktkas/hyperliquid/api/subscription";
75
+ *
76
+ * const transport = new WebSocketTransport();
77
+ *
78
+ * const sub = await spotState(
79
+ * { transport },
80
+ * { user: "0x..." },
81
+ * (data) => console.log(data),
82
+ * );
83
+ * ```
84
+ */
85
+ export function spotState(
86
+ config: SubscriptionRequestConfig,
87
+ params: DeepImmutable<SpotStateParameters>,
88
+ listener: (data: SpotStateEvent) => void,
89
+ ): Promise<Subscription> {
90
+ const payload = parser(SpotStateRequest)({ type: "spotState", user: params.user });
91
+ return config.transport.subscribe<SpotStateEvent>(payload.type, payload, (e) => {
92
+ if (e.detail.user === payload.user) {
93
+ listener(e.detail);
94
+ }
95
+ });
96
+ }
@@ -198,7 +198,17 @@ export const TwapSliceFillsEvent = /* @__PURE__ */ (() => {
198
198
  v.object({
199
199
  /** Array of TWAP slice fills. */
200
200
  twapSliceFills: v.pipe(
201
- v.array(TwapFillSchema),
201
+ v.array(
202
+ v.object({
203
+ /** Fill details for the TWAP slice. */
204
+ fill: TwapFillSchema,
205
+ /** ID of the TWAP. */
206
+ twapId: v.pipe(
207
+ UnsignedInteger,
208
+ v.description("ID of the TWAP."),
209
+ ),
210
+ }),
211
+ ),
202
212
  v.description("Array of TWAP slice fills."),
203
213
  ),
204
214
  }),
@@ -16,6 +16,7 @@ import { l2Book } from "./l2Book.js";
16
16
  import { notification } from "./notification.js";
17
17
  import { openOrders } from "./openOrders.js";
18
18
  import { orderUpdates } from "./orderUpdates.js";
19
+ import { spotState } from "./spotState.js";
19
20
  import { trades } from "./trades.js";
20
21
  import { userEvents } from "./userEvents.js";
21
22
  import { userFills } from "./userFills.js";
@@ -68,6 +69,7 @@ export type {
68
69
  OrderUpdatesEvent as WsOrderUpdatesEvent,
69
70
  OrderUpdatesParameters as WsOrderUpdatesParameters,
70
71
  } from "./orderUpdates.js";
72
+ export type { SpotStateEvent as WsSpotStateEvent, SpotStateParameters as WsSpotStateParameters } from "./spotState.js";
71
73
  export type { TradesEvent as WsTradesEvent, TradesParameters as WsTradesParameters } from "./trades.js";
72
74
  export type {
73
75
  UserEventsEvent as WsUserEventsEvent,
@@ -454,6 +456,29 @@ export class SubscriptionClient<
454
456
  return orderUpdates(this, ...args);
455
457
  }
456
458
 
459
+ /**
460
+ * Subscribe to spot state updates for a specific user.
461
+ * @param params - Parameters specific to the API subscription.
462
+ * @param listener - A callback function to be called when the event is received.
463
+ * @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
464
+ *
465
+ * @throws {TransportError} When the transport layer throws an error.
466
+ *
467
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
468
+ * @example
469
+ * ```ts
470
+ * import * as hl from "@nktkas/hyperliquid";
471
+ *
472
+ * const transport = new hl.WebSocketTransport();
473
+ *
474
+ * const client = new hl.SubscriptionClient({ transport });
475
+ * const sub = await client.spotState({ user: "0x..." }, (data) => console.log(data));
476
+ * ```
477
+ */
478
+ spotState(...args: OmitFirst<OverloadedParameters<typeof spotState>>) {
479
+ return spotState(this, ...args);
480
+ }
481
+
457
482
  /**
458
483
  * Subscribe to real-time trade updates for a specific asset.
459
484
  * @param params - Parameters specific to the API subscription.
@@ -40,6 +40,7 @@ export * from "./l2Book.js";
40
40
  export * from "./notification.js";
41
41
  export * from "./openOrders.js";
42
42
  export * from "./orderUpdates.js";
43
+ export * from "./spotState.js";
43
44
  export * from "./trades.js";
44
45
  export * from "./userEvents.js";
45
46
  export * from "./userFills.js";
@@ -218,7 +218,7 @@ export async function getWalletChainId(wallet: AbstractWallet): Promise<`0x${str
218
218
  }
219
219
  }
220
220
 
221
- /** Get the wallet address from various wallet types. */
221
+ /** Get the lowercase wallet address from various wallet types. */
222
222
  export async function getWalletAddress(wallet: AbstractWallet): Promise<`0x${string}`> {
223
223
  if (isAbstractViemWallet(wallet)) {
224
224
  if ("address" in wallet && wallet.address) {
@@ -46,6 +46,13 @@ interface PostResponse {
46
46
  }
47
47
  | string;
48
48
  };
49
+ }
50
+ /** Response containing error message. */
51
+ | {
52
+ /** Indicates that this is an action response. */
53
+ type: "error";
54
+ /** Contains the error message, e.g. 429 Too Many Requests */
55
+ payload: string;
49
56
  };
50
57
  }
51
58
 
@@ -52,6 +52,12 @@ export class WebSocketAsyncRequest {
52
52
  this.queue.find((x) => x.id === id)?.resolve(event.detail);
53
53
  });
54
54
  hlEvents.addEventListener("post", (event) => {
55
+ if (event.detail.response.type === "error") {
56
+ this.queue
57
+ .find((x) => x.id === event.detail.id)
58
+ ?.reject(new WebSocketRequestError(event.detail.response.payload));
59
+ return;
60
+ }
55
61
  const data = event.detail.response.type === "info"
56
62
  ? event.detail.response.payload.data
57
63
  : event.detail.response.payload;
@@ -1,5 +1,3 @@
1
- // -------------------- EIP-712 --------------------
2
-
3
1
  import { keccak_256 } from "@noble/hashes/sha3.js";
4
2
  import * as secp from "@noble/secp256k1";
5
3
 
@@ -19,7 +17,7 @@ export interface Domain {
19
17
  }
20
18
 
21
19
  /** Signs typed data with a private key. */
22
- async function signTypedData(args: {
20
+ export async function signTypedData(args: {
23
21
  privateKey: string | Uint8Array;
24
22
  domain?: Domain;
25
23
  types: Types;
@@ -36,20 +34,18 @@ async function signTypedData(args: {
36
34
 
37
35
  const hash = hashTypedData({ domain, types, primaryType, message });
38
36
 
39
- const signature = await secp.signAsync(
40
- hash,
41
- privateKey instanceof Uint8Array ? privateKey : secp.etc.hexToBytes(cleanHex(privateKey)),
42
- { prehash: false, format: "recovered" },
43
- );
37
+ const pk = typeof privateKey === "string" ? secp.etc.hexToBytes(cleanHex(privateKey)) : privateKey;
38
+ const sigr = await secp.signAsync(hash, pk, { prehash: false, format: "recovered" });
44
39
 
45
- const r = secp.etc.bytesToHex(signature.slice(1, 33));
46
- const s = secp.etc.bytesToHex(signature.slice(33, 65));
47
- const v = (signature[0] + 27).toString(16).padStart(2, "0");
40
+ const r = secp.etc.bytesToHex(sigr.slice(1, 33));
41
+ const s = secp.etc.bytesToHex(sigr.slice(33, 65));
42
+ const v = (sigr[0] + 27).toString(16).padStart(2, "0");
48
43
 
49
44
  return `0x${r}${s}${v}`;
50
45
  }
51
46
 
52
- function hashTypedData(args: {
47
+ /** Hashes typed data according to EIP-712. */
48
+ export function hashTypedData(args: {
53
49
  domain: Domain;
54
50
  types: Types;
55
51
  primaryType: string;
@@ -211,7 +207,7 @@ function cleanHex(hex: string): string {
211
207
  return hex.startsWith("0x") ? hex.slice(2) : hex;
212
208
  }
213
209
 
214
- // -------------------- Interaction API --------------------
210
+ // -------------------- For SDK --------------------
215
211
 
216
212
  import type { AbstractViemLocalAccount } from "../signing/mod.js";
217
213
 
@@ -221,30 +217,27 @@ export class PrivateKeyEIP712Signer implements AbstractViemLocalAccount {
221
217
  address: `0x${string}`;
222
218
  constructor(privateKey: string | Uint8Array) {
223
219
  this.#privateKey = privateKey;
224
- this.address = privateKeyToAddress(privateKey); // and validate the key
225
- }
226
- signTypedData(
227
- params: {
228
- domain: Domain;
229
- types: Types;
230
- primaryType: string;
231
- message: Record<string, unknown>;
232
- },
233
- ): Promise<`0x${string}`> {
220
+ this.address = privateKeyToAddress(privateKey); // and validate the private key
221
+ }
222
+ signTypedData(params: {
223
+ domain: Domain;
224
+ types: Types;
225
+ primaryType: string;
226
+ message: Record<string, unknown>;
227
+ }): Promise<`0x${string}`> {
234
228
  return signTypedData({ privateKey: this.#privateKey, ...params });
235
229
  }
236
230
  }
237
231
 
238
232
  function privateKeyToAddress(privateKey: string | Uint8Array): `0x${string}` {
239
233
  const pk = typeof privateKey === "string" ? secp.etc.hexToBytes(cleanHex(privateKey)) : privateKey;
240
-
241
234
  const publicKey = secp.getPublicKey(pk, false);
242
- const publicKeyWithoutPrefix = publicKey.slice(1);
235
+ return publicKeyToAddress(publicKey);
236
+ }
243
237
 
238
+ function publicKeyToAddress(publicKey: Uint8Array): `0x${string}` {
239
+ const publicKeyWithoutPrefix = publicKey.slice(1);
244
240
  const hash = keccak_256(publicKeyWithoutPrefix);
245
-
246
241
  const addressBytes = hash.slice(-20);
247
- const address = secp.etc.bytesToHex(addressBytes);
248
-
249
- return `0x${address}`;
242
+ return `0x${secp.etc.bytesToHex(addressBytes)}`;
250
243
  }
@@ -1,11 +1,8 @@
1
- import { HyperliquidError } from "../_base.js";
2
-
3
1
  /**
4
2
  * Format price according to Hyperliquid {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/tick-and-lot-size | rules}:
5
3
  * - Maximum 5 significant figures
6
- * - Maximum (6 for perp, 8 for spot) - `szDecimals` decimal places
4
+ * - Maximum 6 (for perp) or 8 (for spot) - `szDecimals` decimal places
7
5
  * - Integer prices are always allowed regardless of significant figures
8
- * - Remove trailing zeros
9
6
  * @example
10
7
  * ```ts
11
8
  * import { formatPrice } from "@nktkas/hyperliquid/utils";
@@ -15,158 +12,162 @@ import { HyperliquidError } from "../_base.js";
15
12
  * const price = formatPrice("0.0000123456789", 0, false); // → "0.00001234"
16
13
  * ```
17
14
  */
18
- export function formatPrice(
19
- price: string | number,
20
- szDecimals: number,
21
- isPerp: boolean = true,
22
- ): string {
23
- // Prepare: trim, validate, normalize leading/trailing zeros
24
- let priceStr = prepareNumber(typeof price === "string" ? price : price.toString());
25
-
26
- // Integer prices bypass sig figs limit per spec
27
- if (!priceStr.includes(".")) {
28
- return priceStr;
29
- }
15
+ export function formatPrice(price: string | number, szDecimals: number, isPerp: boolean = true): string {
16
+ price = price.toString().trim();
17
+ assertNumberString(price);
30
18
 
31
- // Apply decimal limit: max (6 for perp, 8 for spot) - `szDecimals` decimals
19
+ // Integer prices are always allowed
20
+ if (/^-?\d+$/.test(price)) return trimZeros(price);
21
+
22
+ // Apply decimal limit: max 6 (perp) or 8 (spot) - szDecimals
32
23
  const maxDecimals = Math.max((isPerp ? 6 : 8) - szDecimals, 0);
33
- priceStr = truncateDecimals(priceStr, maxDecimals);
24
+ price = StringMath.toFixedTruncate(price, maxDecimals);
34
25
 
35
26
  // Apply sig figs limit: max 5 significant figures
36
- priceStr = truncateSigFigs(priceStr, 5);
27
+ price = StringMath.toPrecisionTruncate(price, 5);
37
28
 
38
- return priceStr;
29
+ return price;
39
30
  }
40
31
 
41
32
  /**
42
33
  * Format size according to Hyperliquid {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/tick-and-lot-size | rules}:
43
- * - Truncate to `szDecimals` decimal places
44
- * - Remove trailing zeros
34
+ * - Truncate decimal places to `szDecimals`
45
35
  * @example
46
36
  * ```ts
47
37
  * import { formatSize } from "@nktkas/hyperliquid/utils";
48
38
  *
49
39
  * const size = formatSize("1.23456789", 5); // → "1.23456"
50
40
  * ```
41
+ * @note May return 0 if the value is not suitable, but when closing a position, a size of 0 means the full size.
51
42
  */
52
43
  export function formatSize(size: string | number, szDecimals: number): string {
53
- // Prepare: trim, validate, normalize leading/trailing zeros
54
- let sizeStr = prepareNumber(typeof size === "string" ? size : size.toString());
55
-
56
- // Truncate to `szDecimals` decimal places
57
- sizeStr = truncateDecimals(sizeStr, szDecimals);
58
-
59
- return sizeStr;
60
- }
61
-
62
- /**
63
- * Prepare number string for processing:
64
- * 1. Trim whitespace
65
- * 2. Validate format (decimal number, not hex/scientific)
66
- * 3. Normalize: remove leading zeros from integer part, trailing zeros from decimal part
67
- */
68
- function prepareNumber(numStr: string): string {
69
- const trimmed = numStr.trim();
44
+ size = size.toString().trim();
45
+ assertNumberString(size);
70
46
 
71
- // Validate: only decimal numbers allowed (no hex, scientific notation, etc)
72
- if (!/^-?(\d+\.?\d*|\.\d+)$/.test(trimmed)) {
73
- throw new HyperliquidError(`Invalid number format: ${numStr}`);
74
- }
47
+ // Apply decimal limit: szDecimals
48
+ size = StringMath.toFixedTruncate(size, szDecimals);
75
49
 
76
- // Normalize: remove leading zeros from integer, trailing zeros from decimal
77
- const [int, dec] = trimmed.split(".");
78
- const trimmedInt = int.replace(/^0+/, "") || "0";
79
- const trimmedDec = dec?.replace(/0+$/, "");
80
- return trimmedInt + (trimmedDec ? "." + trimmedDec : "");
50
+ return size;
81
51
  }
82
52
 
83
53
  /** String-based Math operations for arbitrary precision */
84
54
  const StringMath = {
85
- /** Absolute value: remove negative sign if present */
86
- abs(numStr: string): string {
87
- return numStr[0] === "-" ? numStr.slice(1) : numStr;
88
- },
89
-
90
55
  /** Floor log10 (magnitude): position of most significant digit */
91
- log10Floor(numStr: string): number {
92
- const abs = this.abs(numStr);
56
+ log10Floor(value: string): number {
57
+ const abs = value[0] === "-" ? value.slice(1) : value;
58
+
59
+ // Check if zero or invalid
60
+ const num = Number(abs);
61
+ if (num === 0 || isNaN(num)) return -Infinity;
62
+
93
63
  const [int, dec] = abs.split(".");
94
64
 
95
65
  // Number >= 1: magnitude = length of integer part - 1
96
- if (int !== "0") {
66
+ if (Number(int) !== 0) {
97
67
  const trimmed = int.replace(/^0+/, "");
98
68
  return trimmed.length - 1;
99
69
  }
100
70
 
101
71
  // Number < 1: count leading zeros in decimal part
102
- if (!dec) return -Infinity;
103
72
  const leadingZeros = dec.match(/^0*/)?.[0].length ?? 0;
104
73
  return -(leadingZeros + 1);
105
74
  },
106
75
 
107
76
  /** Multiply by 10^exp: shift decimal point left (negative) or right (positive) */
108
- multiplyByPow10(numStr: string, exp: number): string {
109
- if (exp === 0) return numStr;
77
+ multiplyByPow10(value: string, exp: number): string {
78
+ if (!Number.isInteger(exp)) throw new RangeError("Exponent must be an integer");
79
+ if (exp === 0) return trimZeros(value);
110
80
 
111
- const neg = numStr[0] === "-";
112
- const abs = neg ? numStr.slice(1) : numStr;
113
- const [int, dec = ""] = abs.split(".");
81
+ const neg = value[0] === "-";
82
+ const abs = neg ? value.slice(1) : value;
83
+ const [intRaw, dec = ""] = abs.split(".");
84
+ // Normalize empty integer part to "0" (handles ".5" → "0.5")
85
+ const int = intRaw || "0";
86
+
87
+ let result: string;
114
88
 
115
89
  if (exp > 0) {
116
90
  // Shift right: move digits from decimal to integer
117
91
  if (exp >= dec.length) {
118
- return (neg ? "-" : "") + int + dec + "0".repeat(exp - dec.length);
92
+ result = int + dec + "0".repeat(exp - dec.length);
93
+ } else {
94
+ result = int + dec.slice(0, exp) + "." + dec.slice(exp);
119
95
  }
120
- return (neg ? "-" : "") + int + dec.slice(0, exp) + "." + dec.slice(exp);
121
96
  } else {
122
97
  // Shift left: move digits from integer to decimal
123
98
  const absExp = -exp;
124
99
  if (absExp >= int.length) {
125
- return (neg ? "-" : "") + "0." + "0".repeat(absExp - int.length) + int + dec;
100
+ result = "0." + "0".repeat(absExp - int.length) + int + dec;
101
+ } else {
102
+ result = int.slice(0, -absExp) + "." + int.slice(-absExp) + dec;
126
103
  }
127
- return (neg ? "-" : "") + int.slice(0, -absExp) + "." + int.slice(-absExp) + dec;
128
104
  }
105
+
106
+ return trimZeros((neg ? "-" : "") + result);
129
107
  },
130
108
 
131
- /** Truncate: remove decimal part */
132
- trunc(numStr: string): string {
133
- const dotIndex = numStr.indexOf(".");
134
- return dotIndex === -1 ? numStr : numStr.slice(0, dotIndex);
109
+ /** Returns the integer part of a number by removing any fractional digits */
110
+ trunc(value: string): string {
111
+ const dotIndex = value.indexOf(".");
112
+ return dotIndex === -1 ? value : value.slice(0, dotIndex) || "0";
135
113
  },
136
- };
137
114
 
138
- /** Truncate to specified decimal places */
139
- function truncateDecimals(numStr: string, maxDecimals: number): string {
140
- const dotIndex = numStr.indexOf(".");
141
- if (dotIndex === -1) return numStr;
115
+ /** Truncate to a certain number of significant figures */
116
+ toPrecisionTruncate(value: string, precision: number): string {
117
+ if (!Number.isInteger(precision)) throw new RangeError("Precision must be an integer");
118
+ if (precision < 1) throw new RangeError("Precision must be positive");
119
+ if (/^-?0+(\.0*)?$/.test(value)) return "0"; // zero is special case (don't work with log10)
142
120
 
143
- const truncated = numStr.substring(0, dotIndex + maxDecimals + 1);
121
+ const neg = value[0] === "-";
122
+ const abs = neg ? value.slice(1) : value;
144
123
 
145
- // Remove trailing zeros from decimal
146
- const [int, dec] = truncated.split(".");
147
- const trimmedDec = dec?.replace(/0+$/, "");
148
- return trimmedDec ? int + "." + trimmedDec : int;
149
- }
124
+ // Calculate how much to shift: align most significant digit to ones place + (maxSigFigs-1)
125
+ const magnitude = StringMath.log10Floor(abs);
126
+ const shiftAmount = precision - magnitude - 1;
150
127
 
151
- /** Truncate to specified significant figures using string-based math */
152
- function truncateSigFigs(numStr: string, maxSigFigs: number): string {
153
- if (parseFloat(numStr) === 0) return "0";
128
+ // Shift right, truncate integer part, shift back
129
+ const shifted = StringMath.multiplyByPow10(abs, shiftAmount);
130
+ const truncated = StringMath.trunc(shifted);
131
+ const result = StringMath.multiplyByPow10(truncated, -shiftAmount);
154
132
 
155
- const neg = numStr[0] === "-";
156
- const abs = neg ? numStr.slice(1) : numStr;
133
+ // build final result and trim zeros
134
+ return trimZeros(neg ? "-" + result : result);
135
+ },
136
+
137
+ /** Truncate to a certain number of decimal places */
138
+ toFixedTruncate(value: string, decimals: number): string {
139
+ if (!Number.isInteger(decimals)) throw new RangeError("Decimals must be an integer");
140
+ if (decimals < 0) throw new RangeError("Decimals must be non-negative");
157
141
 
158
- // Calculate how much to shift: align most significant digit to ones place + (maxSigFigs-1)
159
- const magnitude = StringMath.log10Floor(abs);
160
- const shiftAmount = maxSigFigs - magnitude - 1;
142
+ // Match number with up to `decimals` decimal places
143
+ const regex = new RegExp(`^-?(?:\\d+)?(?:\\.\\d{0,${decimals}})?`);
144
+ const result = value.match(regex)?.[0];
161
145
 
162
- // Shift right, truncate integer part, shift back
163
- const shifted = StringMath.multiplyByPow10(abs, shiftAmount);
164
- const truncated = StringMath.trunc(shifted);
165
- const result = StringMath.multiplyByPow10(truncated, -shiftAmount);
146
+ if (!result) {
147
+ throw new TypeError("Invalid number format");
148
+ }
166
149
 
167
- // Remove trailing zeros introduced by shifting
168
- const final = neg ? "-" + result : result;
169
- const [int, dec] = final.split(".");
170
- const trimmedDec = dec?.replace(/0+$/, "");
171
- return trimmedDec ? int + "." + trimmedDec : int;
150
+ // Trim zeros after truncation
151
+ return trimZeros(result);
152
+ },
153
+ };
154
+
155
+ function trimZeros(value: string): string {
156
+ return value
157
+ // remove leading zeros
158
+ .replace(/^(-?)0+(?=\d)/, "$1") // "00123" → "123", "-00.5" → "-0.5"
159
+ // remove trailing zeros
160
+ .replace(/\.0*$|(\.\d+?)0+$/, "$1") // "1.2000" → "1.2", "5.0" → "5"
161
+ // add leading zero if starts with decimal point
162
+ .replace(/^(-?)\./, "$10.") // ".5" → "0.5", "-.5" → "-0.5"
163
+ // add "0" if string is empty after trimming
164
+ .replace(/^-?$/, "0") // "" → "0", "-" → "0"
165
+ // normalize negative zero
166
+ .replace(/^-0$/, "0"); // "-0" → "0"
167
+ }
168
+
169
+ function assertNumberString(value: string): void {
170
+ if (!/^-?(\d+\.?\d*|\.\d*)$/.test(value)) {
171
+ throw new TypeError("Invalid number format");
172
+ }
172
173
  }