@nktkas/hyperliquid 0.25.6 → 0.25.8

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 (544) hide show
  1. package/CONTRIBUTING.md +26 -19
  2. package/README.md +106 -9
  3. package/esm/bin/cli.js +1 -0
  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.map +1 -1
  73. package/esm/src/api/exchange/multiSig.js +17 -16
  74. package/esm/src/api/exchange/multiSig.js.map +1 -1
  75. package/esm/src/api/exchange/noop.d.ts.map +1 -1
  76. package/esm/src/api/exchange/noop.js +14 -7
  77. package/esm/src/api/exchange/noop.js.map +1 -1
  78. package/esm/src/api/exchange/order.d.ts.map +1 -1
  79. package/esm/src/api/exchange/order.js +16 -10
  80. package/esm/src/api/exchange/order.js.map +1 -1
  81. package/esm/src/api/exchange/perpDeploy.d.ts.map +1 -1
  82. package/esm/src/api/exchange/perpDeploy.js +15 -8
  83. package/esm/src/api/exchange/perpDeploy.js.map +1 -1
  84. package/esm/src/api/exchange/registerReferrer.d.ts.map +1 -1
  85. package/esm/src/api/exchange/registerReferrer.js +15 -8
  86. package/esm/src/api/exchange/registerReferrer.js.map +1 -1
  87. package/esm/src/api/exchange/reserveRequestWeight.d.ts.map +1 -1
  88. package/esm/src/api/exchange/reserveRequestWeight.js +15 -8
  89. package/esm/src/api/exchange/reserveRequestWeight.js.map +1 -1
  90. package/esm/src/api/exchange/scheduleCancel.js +16 -10
  91. package/esm/src/api/exchange/scheduleCancel.js.map +1 -1
  92. package/esm/src/api/exchange/sendAsset.d.ts.map +1 -1
  93. package/esm/src/api/exchange/sendAsset.js +16 -8
  94. package/esm/src/api/exchange/sendAsset.js.map +1 -1
  95. package/esm/src/api/exchange/setDisplayName.d.ts.map +1 -1
  96. package/esm/src/api/exchange/setDisplayName.js +15 -8
  97. package/esm/src/api/exchange/setDisplayName.js.map +1 -1
  98. package/esm/src/api/exchange/setReferrer.d.ts.map +1 -1
  99. package/esm/src/api/exchange/setReferrer.js +15 -8
  100. package/esm/src/api/exchange/setReferrer.js.map +1 -1
  101. package/esm/src/api/exchange/spotDeploy.d.ts.map +1 -1
  102. package/esm/src/api/exchange/spotDeploy.js +15 -8
  103. package/esm/src/api/exchange/spotDeploy.js.map +1 -1
  104. package/esm/src/api/exchange/spotSend.d.ts.map +1 -1
  105. package/esm/src/api/exchange/spotSend.js +16 -8
  106. package/esm/src/api/exchange/spotSend.js.map +1 -1
  107. package/esm/src/api/exchange/spotUser.d.ts.map +1 -1
  108. package/esm/src/api/exchange/spotUser.js +15 -8
  109. package/esm/src/api/exchange/spotUser.js.map +1 -1
  110. package/esm/src/api/exchange/subAccountModify.d.ts.map +1 -1
  111. package/esm/src/api/exchange/subAccountModify.js +15 -8
  112. package/esm/src/api/exchange/subAccountModify.js.map +1 -1
  113. package/esm/src/api/exchange/subAccountSpotTransfer.d.ts.map +1 -1
  114. package/esm/src/api/exchange/subAccountSpotTransfer.js +15 -8
  115. package/esm/src/api/exchange/subAccountSpotTransfer.js.map +1 -1
  116. package/esm/src/api/exchange/subAccountTransfer.d.ts.map +1 -1
  117. package/esm/src/api/exchange/subAccountTransfer.js +15 -8
  118. package/esm/src/api/exchange/subAccountTransfer.js.map +1 -1
  119. package/esm/src/api/exchange/tokenDelegate.d.ts.map +1 -1
  120. package/esm/src/api/exchange/tokenDelegate.js +16 -8
  121. package/esm/src/api/exchange/tokenDelegate.js.map +1 -1
  122. package/esm/src/api/exchange/twapCancel.d.ts.map +1 -1
  123. package/esm/src/api/exchange/twapCancel.js +16 -10
  124. package/esm/src/api/exchange/twapCancel.js.map +1 -1
  125. package/esm/src/api/exchange/twapOrder.d.ts.map +1 -1
  126. package/esm/src/api/exchange/twapOrder.js +16 -10
  127. package/esm/src/api/exchange/twapOrder.js.map +1 -1
  128. package/esm/src/api/exchange/updateIsolatedMargin.d.ts.map +1 -1
  129. package/esm/src/api/exchange/updateIsolatedMargin.js +16 -10
  130. package/esm/src/api/exchange/updateIsolatedMargin.js.map +1 -1
  131. package/esm/src/api/exchange/updateLeverage.d.ts.map +1 -1
  132. package/esm/src/api/exchange/updateLeverage.js +16 -10
  133. package/esm/src/api/exchange/updateLeverage.js.map +1 -1
  134. package/esm/src/api/exchange/usdClassTransfer.d.ts.map +1 -1
  135. package/esm/src/api/exchange/usdClassTransfer.js +16 -8
  136. package/esm/src/api/exchange/usdClassTransfer.js.map +1 -1
  137. package/esm/src/api/exchange/usdSend.d.ts.map +1 -1
  138. package/esm/src/api/exchange/usdSend.js +16 -8
  139. package/esm/src/api/exchange/usdSend.js.map +1 -1
  140. package/esm/src/api/exchange/userDexAbstraction.d.ts.map +1 -1
  141. package/esm/src/api/exchange/userDexAbstraction.js +16 -8
  142. package/esm/src/api/exchange/userDexAbstraction.js.map +1 -1
  143. package/esm/src/api/exchange/vaultDistribute.d.ts.map +1 -1
  144. package/esm/src/api/exchange/vaultDistribute.js +15 -8
  145. package/esm/src/api/exchange/vaultDistribute.js.map +1 -1
  146. package/esm/src/api/exchange/vaultModify.d.ts.map +1 -1
  147. package/esm/src/api/exchange/vaultModify.js +15 -8
  148. package/esm/src/api/exchange/vaultModify.js.map +1 -1
  149. package/esm/src/api/exchange/vaultTransfer.d.ts.map +1 -1
  150. package/esm/src/api/exchange/vaultTransfer.js +15 -8
  151. package/esm/src/api/exchange/vaultTransfer.js.map +1 -1
  152. package/esm/src/api/exchange/withdraw3.d.ts.map +1 -1
  153. package/esm/src/api/exchange/withdraw3.js +16 -8
  154. package/esm/src/api/exchange/withdraw3.js.map +1 -1
  155. package/esm/src/api/exchange/~client.d.ts +31 -3
  156. package/esm/src/api/exchange/~client.d.ts.map +1 -1
  157. package/esm/src/api/exchange/~client.js +27 -4
  158. package/esm/src/api/exchange/~client.js.map +1 -1
  159. package/esm/src/api/exchange/~mod.d.ts +1 -0
  160. package/esm/src/api/exchange/~mod.d.ts.map +1 -1
  161. package/esm/src/api/exchange/~mod.js +1 -0
  162. package/esm/src/api/exchange/~mod.js.map +1 -1
  163. package/esm/src/api/info/allPerpMetas.d.ts +5 -0
  164. package/esm/src/api/info/allPerpMetas.d.ts.map +1 -1
  165. package/esm/src/api/info/meta.d.ts +5 -0
  166. package/esm/src/api/info/meta.d.ts.map +1 -1
  167. package/esm/src/api/info/meta.js +2 -0
  168. package/esm/src/api/info/meta.js.map +1 -1
  169. package/esm/src/api/info/metaAndAssetCtxs.d.ts +5 -0
  170. package/esm/src/api/info/metaAndAssetCtxs.d.ts.map +1 -1
  171. package/esm/src/api/info/perpDexs.d.ts +4 -0
  172. package/esm/src/api/info/perpDexs.d.ts.map +1 -1
  173. package/esm/src/api/info/perpDexs.js +5 -0
  174. package/esm/src/api/info/perpDexs.js.map +1 -1
  175. package/esm/src/api/info/spotClearinghouseState.d.ts +0 -5
  176. package/esm/src/api/info/spotClearinghouseState.d.ts.map +1 -1
  177. package/esm/src/api/info/spotClearinghouseState.js +2 -14
  178. package/esm/src/api/info/spotClearinghouseState.js.map +1 -1
  179. package/esm/src/api/info/userFees.d.ts +27 -2
  180. package/esm/src/api/info/userFees.d.ts.map +1 -1
  181. package/esm/src/api/info/userFees.js +29 -1
  182. package/esm/src/api/info/userFees.js.map +1 -1
  183. package/esm/src/api/info/webData2.d.ts +152 -23
  184. package/esm/src/api/info/webData2.d.ts.map +1 -1
  185. package/esm/src/api/info/webData2.js +3 -54
  186. package/esm/src/api/info/webData2.js.map +1 -1
  187. package/esm/src/api/info/~client.d.ts +11 -3
  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/webData2.d.ts +9 -4
  194. package/esm/src/api/subscription/webData2.d.ts.map +1 -1
  195. package/esm/src/api/subscription/webData2.js +1 -1
  196. package/esm/src/api/subscription/webData2.js.map +1 -1
  197. package/esm/src/api/subscription/webData3.d.ts +541 -0
  198. package/esm/src/api/subscription/webData3.d.ts.map +1 -0
  199. package/esm/src/api/subscription/webData3.js +94 -0
  200. package/esm/src/api/subscription/webData3.js.map +1 -0
  201. package/esm/src/api/subscription/~client.d.ts +44 -0
  202. package/esm/src/api/subscription/~client.d.ts.map +1 -1
  203. package/esm/src/api/subscription/~client.js +46 -0
  204. package/esm/src/api/subscription/~client.js.map +1 -1
  205. package/esm/src/api/subscription/~mod.d.ts +2 -0
  206. package/esm/src/api/subscription/~mod.d.ts.map +1 -1
  207. package/esm/src/api/subscription/~mod.js +2 -0
  208. package/esm/src/api/subscription/~mod.js.map +1 -1
  209. package/esm/src/signing/_signTypedData.d.ts +1 -1
  210. package/esm/src/signing/_signTypedData.d.ts.map +1 -1
  211. package/esm/src/signing/_signTypedData.js +1 -1
  212. package/esm/src/signing/_signTypedData.js.map +1 -1
  213. package/esm/src/utils/{_minimalEIP712Signer.d.ts → _eip712.d.ts} +16 -1
  214. package/esm/src/utils/_eip712.d.ts.map +1 -0
  215. package/esm/src/utils/{_minimalEIP712Signer.js → _eip712.js} +14 -11
  216. package/esm/src/utils/_eip712.js.map +1 -0
  217. package/esm/src/utils/_format.d.ts +28 -0
  218. package/esm/src/utils/_format.d.ts.map +1 -0
  219. package/esm/src/utils/_format.js +157 -0
  220. package/esm/src/utils/_format.js.map +1 -0
  221. package/esm/src/utils/_recover.d.ts +89 -0
  222. package/esm/src/utils/_recover.d.ts.map +1 -0
  223. package/esm/src/utils/_recover.js +119 -0
  224. package/esm/src/utils/_recover.js.map +1 -0
  225. package/esm/src/utils/_symbolConverter.d.ts +13 -0
  226. package/esm/src/utils/_symbolConverter.d.ts.map +1 -1
  227. package/esm/src/utils/_symbolConverter.js +17 -0
  228. package/esm/src/utils/_symbolConverter.js.map +1 -1
  229. package/esm/src/utils/mod.d.ts +2 -0
  230. package/esm/src/utils/mod.d.ts.map +1 -1
  231. package/esm/src/utils/mod.js +2 -0
  232. package/esm/src/utils/mod.js.map +1 -1
  233. package/package.json +3 -2
  234. package/script/bin/cli.js +1 -0
  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.map +1 -1
  304. package/script/src/api/exchange/multiSig.js +17 -16
  305. package/script/src/api/exchange/multiSig.js.map +1 -1
  306. package/script/src/api/exchange/noop.d.ts.map +1 -1
  307. package/script/src/api/exchange/noop.js +14 -7
  308. package/script/src/api/exchange/noop.js.map +1 -1
  309. package/script/src/api/exchange/order.d.ts.map +1 -1
  310. package/script/src/api/exchange/order.js +16 -10
  311. package/script/src/api/exchange/order.js.map +1 -1
  312. package/script/src/api/exchange/perpDeploy.d.ts.map +1 -1
  313. package/script/src/api/exchange/perpDeploy.js +15 -8
  314. package/script/src/api/exchange/perpDeploy.js.map +1 -1
  315. package/script/src/api/exchange/registerReferrer.d.ts.map +1 -1
  316. package/script/src/api/exchange/registerReferrer.js +15 -8
  317. package/script/src/api/exchange/registerReferrer.js.map +1 -1
  318. package/script/src/api/exchange/reserveRequestWeight.d.ts.map +1 -1
  319. package/script/src/api/exchange/reserveRequestWeight.js +15 -8
  320. package/script/src/api/exchange/reserveRequestWeight.js.map +1 -1
  321. package/script/src/api/exchange/scheduleCancel.js +16 -10
  322. package/script/src/api/exchange/scheduleCancel.js.map +1 -1
  323. package/script/src/api/exchange/sendAsset.d.ts.map +1 -1
  324. package/script/src/api/exchange/sendAsset.js +15 -7
  325. package/script/src/api/exchange/sendAsset.js.map +1 -1
  326. package/script/src/api/exchange/setDisplayName.d.ts.map +1 -1
  327. package/script/src/api/exchange/setDisplayName.js +15 -8
  328. package/script/src/api/exchange/setDisplayName.js.map +1 -1
  329. package/script/src/api/exchange/setReferrer.d.ts.map +1 -1
  330. package/script/src/api/exchange/setReferrer.js +15 -8
  331. package/script/src/api/exchange/setReferrer.js.map +1 -1
  332. package/script/src/api/exchange/spotDeploy.d.ts.map +1 -1
  333. package/script/src/api/exchange/spotDeploy.js +15 -8
  334. package/script/src/api/exchange/spotDeploy.js.map +1 -1
  335. package/script/src/api/exchange/spotSend.d.ts.map +1 -1
  336. package/script/src/api/exchange/spotSend.js +15 -7
  337. package/script/src/api/exchange/spotSend.js.map +1 -1
  338. package/script/src/api/exchange/spotUser.d.ts.map +1 -1
  339. package/script/src/api/exchange/spotUser.js +15 -8
  340. package/script/src/api/exchange/spotUser.js.map +1 -1
  341. package/script/src/api/exchange/subAccountModify.d.ts.map +1 -1
  342. package/script/src/api/exchange/subAccountModify.js +15 -8
  343. package/script/src/api/exchange/subAccountModify.js.map +1 -1
  344. package/script/src/api/exchange/subAccountSpotTransfer.d.ts.map +1 -1
  345. package/script/src/api/exchange/subAccountSpotTransfer.js +15 -8
  346. package/script/src/api/exchange/subAccountSpotTransfer.js.map +1 -1
  347. package/script/src/api/exchange/subAccountTransfer.d.ts.map +1 -1
  348. package/script/src/api/exchange/subAccountTransfer.js +15 -8
  349. package/script/src/api/exchange/subAccountTransfer.js.map +1 -1
  350. package/script/src/api/exchange/tokenDelegate.d.ts.map +1 -1
  351. package/script/src/api/exchange/tokenDelegate.js +15 -7
  352. package/script/src/api/exchange/tokenDelegate.js.map +1 -1
  353. package/script/src/api/exchange/twapCancel.d.ts.map +1 -1
  354. package/script/src/api/exchange/twapCancel.js +16 -10
  355. package/script/src/api/exchange/twapCancel.js.map +1 -1
  356. package/script/src/api/exchange/twapOrder.d.ts.map +1 -1
  357. package/script/src/api/exchange/twapOrder.js +16 -10
  358. package/script/src/api/exchange/twapOrder.js.map +1 -1
  359. package/script/src/api/exchange/updateIsolatedMargin.d.ts.map +1 -1
  360. package/script/src/api/exchange/updateIsolatedMargin.js +16 -10
  361. package/script/src/api/exchange/updateIsolatedMargin.js.map +1 -1
  362. package/script/src/api/exchange/updateLeverage.d.ts.map +1 -1
  363. package/script/src/api/exchange/updateLeverage.js +16 -10
  364. package/script/src/api/exchange/updateLeverage.js.map +1 -1
  365. package/script/src/api/exchange/usdClassTransfer.d.ts.map +1 -1
  366. package/script/src/api/exchange/usdClassTransfer.js +15 -7
  367. package/script/src/api/exchange/usdClassTransfer.js.map +1 -1
  368. package/script/src/api/exchange/usdSend.d.ts.map +1 -1
  369. package/script/src/api/exchange/usdSend.js +15 -7
  370. package/script/src/api/exchange/usdSend.js.map +1 -1
  371. package/script/src/api/exchange/userDexAbstraction.d.ts.map +1 -1
  372. package/script/src/api/exchange/userDexAbstraction.js +15 -7
  373. package/script/src/api/exchange/userDexAbstraction.js.map +1 -1
  374. package/script/src/api/exchange/vaultDistribute.d.ts.map +1 -1
  375. package/script/src/api/exchange/vaultDistribute.js +15 -8
  376. package/script/src/api/exchange/vaultDistribute.js.map +1 -1
  377. package/script/src/api/exchange/vaultModify.d.ts.map +1 -1
  378. package/script/src/api/exchange/vaultModify.js +15 -8
  379. package/script/src/api/exchange/vaultModify.js.map +1 -1
  380. package/script/src/api/exchange/vaultTransfer.d.ts.map +1 -1
  381. package/script/src/api/exchange/vaultTransfer.js +15 -8
  382. package/script/src/api/exchange/vaultTransfer.js.map +1 -1
  383. package/script/src/api/exchange/withdraw3.d.ts.map +1 -1
  384. package/script/src/api/exchange/withdraw3.js +15 -7
  385. package/script/src/api/exchange/withdraw3.js.map +1 -1
  386. package/script/src/api/exchange/~client.d.ts +31 -3
  387. package/script/src/api/exchange/~client.d.ts.map +1 -1
  388. package/script/src/api/exchange/~client.js +29 -6
  389. package/script/src/api/exchange/~client.js.map +1 -1
  390. package/script/src/api/exchange/~mod.d.ts +1 -0
  391. package/script/src/api/exchange/~mod.d.ts.map +1 -1
  392. package/script/src/api/exchange/~mod.js +1 -0
  393. package/script/src/api/exchange/~mod.js.map +1 -1
  394. package/script/src/api/info/allPerpMetas.d.ts +5 -0
  395. package/script/src/api/info/allPerpMetas.d.ts.map +1 -1
  396. package/script/src/api/info/meta.d.ts +5 -0
  397. package/script/src/api/info/meta.d.ts.map +1 -1
  398. package/script/src/api/info/meta.js +2 -0
  399. package/script/src/api/info/meta.js.map +1 -1
  400. package/script/src/api/info/metaAndAssetCtxs.d.ts +5 -0
  401. package/script/src/api/info/metaAndAssetCtxs.d.ts.map +1 -1
  402. package/script/src/api/info/perpDexs.d.ts +4 -0
  403. package/script/src/api/info/perpDexs.d.ts.map +1 -1
  404. package/script/src/api/info/perpDexs.js +5 -0
  405. package/script/src/api/info/perpDexs.js.map +1 -1
  406. package/script/src/api/info/spotClearinghouseState.d.ts +0 -5
  407. package/script/src/api/info/spotClearinghouseState.d.ts.map +1 -1
  408. package/script/src/api/info/spotClearinghouseState.js +2 -14
  409. package/script/src/api/info/spotClearinghouseState.js.map +1 -1
  410. package/script/src/api/info/userFees.d.ts +27 -2
  411. package/script/src/api/info/userFees.d.ts.map +1 -1
  412. package/script/src/api/info/userFees.js +29 -1
  413. package/script/src/api/info/userFees.js.map +1 -1
  414. package/script/src/api/info/webData2.d.ts +152 -23
  415. package/script/src/api/info/webData2.d.ts.map +1 -1
  416. package/script/src/api/info/webData2.js +2 -53
  417. package/script/src/api/info/webData2.js.map +1 -1
  418. package/script/src/api/info/~client.d.ts +11 -3
  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/webData2.d.ts +9 -4
  425. package/script/src/api/subscription/webData2.d.ts.map +1 -1
  426. package/script/src/api/subscription/webData2.js +1 -1
  427. package/script/src/api/subscription/webData2.js.map +1 -1
  428. package/script/src/api/subscription/webData3.d.ts +541 -0
  429. package/script/src/api/subscription/webData3.d.ts.map +1 -0
  430. package/script/src/api/subscription/webData3.js +131 -0
  431. package/script/src/api/subscription/webData3.js.map +1 -0
  432. package/script/src/api/subscription/~client.d.ts +44 -0
  433. package/script/src/api/subscription/~client.d.ts.map +1 -1
  434. package/script/src/api/subscription/~client.js +46 -0
  435. package/script/src/api/subscription/~client.js.map +1 -1
  436. package/script/src/api/subscription/~mod.d.ts +2 -0
  437. package/script/src/api/subscription/~mod.d.ts.map +1 -1
  438. package/script/src/api/subscription/~mod.js +2 -0
  439. package/script/src/api/subscription/~mod.js.map +1 -1
  440. package/script/src/signing/_signTypedData.d.ts +1 -1
  441. package/script/src/signing/_signTypedData.d.ts.map +1 -1
  442. package/script/src/signing/_signTypedData.js +1 -1
  443. package/script/src/signing/_signTypedData.js.map +1 -1
  444. package/script/src/utils/{_minimalEIP712Signer.d.ts → _eip712.d.ts} +16 -1
  445. package/script/src/utils/_eip712.d.ts.map +1 -0
  446. package/script/src/utils/{_minimalEIP712Signer.js → _eip712.js} +14 -9
  447. package/script/src/utils/_eip712.js.map +1 -0
  448. package/script/src/utils/_format.d.ts +28 -0
  449. package/script/src/utils/_format.d.ts.map +1 -0
  450. package/script/src/utils/_format.js +161 -0
  451. package/script/src/utils/_format.js.map +1 -0
  452. package/script/src/utils/_recover.d.ts +89 -0
  453. package/script/src/utils/_recover.d.ts.map +1 -0
  454. package/script/src/utils/_recover.js +156 -0
  455. package/script/src/utils/_recover.js.map +1 -0
  456. package/script/src/utils/_symbolConverter.d.ts +13 -0
  457. package/script/src/utils/_symbolConverter.d.ts.map +1 -1
  458. package/script/src/utils/_symbolConverter.js +17 -0
  459. package/script/src/utils/_symbolConverter.js.map +1 -1
  460. package/script/src/utils/mod.d.ts +2 -0
  461. package/script/src/utils/mod.d.ts.map +1 -1
  462. package/script/src/utils/mod.js +2 -0
  463. package/script/src/utils/mod.js.map +1 -1
  464. package/src/bin/cli.ts +1 -0
  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 +15 -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/info/webData2.ts +3 -104
  521. package/src/src/api/subscription/spotState.ts +96 -0
  522. package/src/src/api/subscription/webData2.ts +1 -1
  523. package/src/src/api/subscription/webData3.ts +179 -0
  524. package/src/src/api/subscription/~client.ts +50 -0
  525. package/src/src/api/subscription/~mod.ts +2 -0
  526. package/src/src/signing/_signTypedData.ts +1 -1
  527. package/src/src/utils/{_minimalEIP712Signer.ts → _eip712.ts} +22 -29
  528. package/src/src/utils/_format.ts +173 -0
  529. package/src/src/utils/_recover.ts +178 -0
  530. package/src/src/utils/_symbolConverter.ts +18 -0
  531. package/src/src/utils/mod.ts +2 -0
  532. package/esm/src/api/exchange/_base/_sequential.d.ts +0 -30
  533. package/esm/src/api/exchange/_base/_sequential.d.ts.map +0 -1
  534. package/esm/src/api/exchange/_base/_sequential.js +0 -69
  535. package/esm/src/api/exchange/_base/_sequential.js.map +0 -1
  536. package/esm/src/utils/_minimalEIP712Signer.d.ts.map +0 -1
  537. package/esm/src/utils/_minimalEIP712Signer.js.map +0 -1
  538. package/script/src/api/exchange/_base/_sequential.d.ts +0 -30
  539. package/script/src/api/exchange/_base/_sequential.d.ts.map +0 -1
  540. package/script/src/api/exchange/_base/_sequential.js +0 -72
  541. package/script/src/api/exchange/_base/_sequential.js.map +0 -1
  542. package/script/src/utils/_minimalEIP712Signer.d.ts.map +0 -1
  543. package/script/src/utils/_minimalEIP712Signer.js.map +0 -1
  544. package/src/src/api/exchange/_base/_sequential.ts +0 -82
@@ -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";
@@ -25,6 +26,7 @@ import { userNonFundingLedgerUpdates } from "./userNonFundingLedgerUpdates.js";
25
26
  import { userTwapHistory } from "./userTwapHistory.js";
26
27
  import { userTwapSliceFills } from "./userTwapSliceFills.js";
27
28
  import { webData2 } from "./webData2.js";
29
+ import { webData3 } from "./webData3.js";
28
30
 
29
31
  export type {
30
32
  ActiveAssetCtxEvent as WsActiveAssetCtxEvent,
@@ -67,6 +69,7 @@ export type {
67
69
  OrderUpdatesEvent as WsOrderUpdatesEvent,
68
70
  OrderUpdatesParameters as WsOrderUpdatesParameters,
69
71
  } from "./orderUpdates.js";
72
+ export type { SpotStateEvent as WsSpotStateEvent, SpotStateParameters as WsSpotStateParameters } from "./spotState.js";
70
73
  export type { TradesEvent as WsTradesEvent, TradesParameters as WsTradesParameters } from "./trades.js";
71
74
  export type {
72
75
  UserEventsEvent as WsUserEventsEvent,
@@ -94,6 +97,7 @@ export type {
94
97
  UserTwapSliceFillsParameters as WsUserTwapSliceFillsParameters,
95
98
  } from "./userTwapSliceFills.js";
96
99
  export type { WebData2Event as WsWebData2Event, WebData2Parameters as WsWebData2Parameters } from "./webData2.js";
100
+ export type { WebData3Event as WsWebData3Event, WebData3Parameters as WsWebData3Parameters } from "./webData3.js";
97
101
 
98
102
  export type { SubscriptionRequestConfig } from "./_types.js";
99
103
 
@@ -452,6 +456,29 @@ export class SubscriptionClient<
452
456
  return orderUpdates(this, ...args);
453
457
  }
454
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
+
455
482
  /**
456
483
  * Subscribe to real-time trade updates for a specific asset.
457
484
  * @param params - Parameters specific to the API subscription.
@@ -660,4 +687,27 @@ export class SubscriptionClient<
660
687
  webData2(...args: OmitFirst<OverloadedParameters<typeof webData2>>) {
661
688
  return webData2(this, ...args);
662
689
  }
690
+
691
+ /**
692
+ * Subscribe to comprehensive user and market data updates.
693
+ * @param params - Parameters specific to the API subscription.
694
+ * @param listener - A callback function to be called when the event is received.
695
+ * @returns A request-promise that resolves with a {@link Subscription} object to manage the subscription lifecycle.
696
+ *
697
+ * @throws {TransportError} When the transport layer throws an error.
698
+ *
699
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/websocket/subscriptions
700
+ * @example
701
+ * ```ts
702
+ * import * as hl from "@nktkas/hyperliquid";
703
+ *
704
+ * const transport = new hl.WebSocketTransport();
705
+ *
706
+ * const client = new hl.SubscriptionClient({ transport });
707
+ * const sub = await client.webData3({ user: "0x..." }, (data) => console.log(data));
708
+ * ```
709
+ */
710
+ webData3(...args: OmitFirst<OverloadedParameters<typeof webData3>>) {
711
+ return webData3(this, ...args);
712
+ }
663
713
  }
@@ -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";
@@ -49,3 +50,4 @@ export * from "./userNonFundingLedgerUpdates.js";
49
50
  export * from "./userTwapHistory.js";
50
51
  export * from "./userTwapSliceFills.js";
51
52
  export * from "./webData2.js";
53
+ export * from "./webData3.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) {
@@ -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
  }
@@ -0,0 +1,173 @@
1
+ /**
2
+ * Format price according to Hyperliquid {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/tick-and-lot-size | rules}:
3
+ * - Maximum 5 significant figures
4
+ * - Maximum 6 (for perp) or 8 (for spot) - `szDecimals` decimal places
5
+ * - Integer prices are always allowed regardless of significant figures
6
+ * @example
7
+ * ```ts
8
+ * import { formatPrice } from "@nktkas/hyperliquid/utils";
9
+ *
10
+ * // `true` for perp (default), `false` for spot
11
+ * // ⌄⌄⌄⌄⌄
12
+ * const price = formatPrice("0.0000123456789", 0, false); // → "0.00001234"
13
+ * ```
14
+ */
15
+ export function formatPrice(price: string | number, szDecimals: number, isPerp: boolean = true): string {
16
+ price = price.toString().trim();
17
+ assertNumberString(price);
18
+
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
23
+ const maxDecimals = Math.max((isPerp ? 6 : 8) - szDecimals, 0);
24
+ price = StringMath.toFixedTruncate(price, maxDecimals);
25
+
26
+ // Apply sig figs limit: max 5 significant figures
27
+ price = StringMath.toPrecisionTruncate(price, 5);
28
+
29
+ return price;
30
+ }
31
+
32
+ /**
33
+ * Format size according to Hyperliquid {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/tick-and-lot-size | rules}:
34
+ * - Truncate decimal places to `szDecimals`
35
+ * @example
36
+ * ```ts
37
+ * import { formatSize } from "@nktkas/hyperliquid/utils";
38
+ *
39
+ * const size = formatSize("1.23456789", 5); // → "1.23456"
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.
42
+ */
43
+ export function formatSize(size: string | number, szDecimals: number): string {
44
+ size = size.toString().trim();
45
+ assertNumberString(size);
46
+
47
+ // Apply decimal limit: szDecimals
48
+ size = StringMath.toFixedTruncate(size, szDecimals);
49
+
50
+ return size;
51
+ }
52
+
53
+ /** String-based Math operations for arbitrary precision */
54
+ const StringMath = {
55
+ /** Floor log10 (magnitude): position of most significant digit */
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
+
63
+ const [int, dec] = abs.split(".");
64
+
65
+ // Number >= 1: magnitude = length of integer part - 1
66
+ if (Number(int) !== 0) {
67
+ const trimmed = int.replace(/^0+/, "");
68
+ return trimmed.length - 1;
69
+ }
70
+
71
+ // Number < 1: count leading zeros in decimal part
72
+ const leadingZeros = dec.match(/^0*/)?.[0].length ?? 0;
73
+ return -(leadingZeros + 1);
74
+ },
75
+
76
+ /** Multiply by 10^exp: shift decimal point left (negative) or right (positive) */
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);
80
+
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;
88
+
89
+ if (exp > 0) {
90
+ // Shift right: move digits from decimal to integer
91
+ if (exp >= dec.length) {
92
+ result = int + dec + "0".repeat(exp - dec.length);
93
+ } else {
94
+ result = int + dec.slice(0, exp) + "." + dec.slice(exp);
95
+ }
96
+ } else {
97
+ // Shift left: move digits from integer to decimal
98
+ const absExp = -exp;
99
+ if (absExp >= int.length) {
100
+ result = "0." + "0".repeat(absExp - int.length) + int + dec;
101
+ } else {
102
+ result = int.slice(0, -absExp) + "." + int.slice(-absExp) + dec;
103
+ }
104
+ }
105
+
106
+ return trimZeros((neg ? "-" : "") + result);
107
+ },
108
+
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";
113
+ },
114
+
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)
120
+
121
+ const neg = value[0] === "-";
122
+ const abs = neg ? value.slice(1) : value;
123
+
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;
127
+
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);
132
+
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");
141
+
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];
145
+
146
+ if (!result) {
147
+ throw new TypeError("Invalid number format");
148
+ }
149
+
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
+ }
173
+ }
@@ -0,0 +1,178 @@
1
+ import { keccak_256 } from "@noble/hashes/sha3.js";
2
+ import * as secp from "@noble/secp256k1";
3
+ import { createL1ActionHash, type Signature } from "../signing/mod.js";
4
+ import { hashTypedData } from "./_eip712.js";
5
+
6
+ /**
7
+ * Recover the Ethereum address that signed an L1 action.
8
+ * @example
9
+ * ```ts
10
+ * import { recoverUserFromL1Action } from "@nktkas/hyperliquid/utils";
11
+ *
12
+ * const action = {
13
+ * type: "cancel",
14
+ * cancels: [{ a: 0, o: 12345 }],
15
+ * };
16
+ * const nonce = 1700000000000;
17
+ * const signature = {
18
+ * r: "0x...",
19
+ * s: "0x...",
20
+ * v: 27,
21
+ * } as const;
22
+ *
23
+ * const address = await recoverUserFromL1Action({ action, nonce, signature });
24
+ * console.log(`Signer address: ${address}`);
25
+ * ```
26
+ */
27
+ export async function recoverUserFromL1Action(params: {
28
+ /** The action that was signed (hash depends on key order). */
29
+ action: Record<string, unknown>;
30
+ /** The timestamp in ms used when signing. */
31
+ nonce: number;
32
+ /** The signature to recover the address from. */
33
+ signature: Signature;
34
+ /** Indicates if the action is for the testnet. (default: false) */
35
+ isTestnet?: boolean;
36
+ /** Optional vault address used in the action. */
37
+ vaultAddress?: `0x${string}`;
38
+ /** Optional expiration time in ms used in the action. */
39
+ expiresAfter?: number;
40
+ }): Promise<`0x${string}`> {
41
+ const {
42
+ action,
43
+ signature,
44
+ nonce,
45
+ isTestnet = false,
46
+ vaultAddress,
47
+ expiresAfter,
48
+ } = params;
49
+
50
+ // 1. Create the action hash
51
+ const actionHash = createL1ActionHash({ action, nonce, vaultAddress, expiresAfter });
52
+
53
+ // 2. Hash the typed data according to EIP-712
54
+ const hash = hashTypedData({
55
+ domain: {
56
+ name: "Exchange",
57
+ version: "1",
58
+ chainId: 1337,
59
+ verifyingContract: "0x0000000000000000000000000000000000000000",
60
+ },
61
+ types: {
62
+ Agent: [
63
+ { name: "source", type: "string" },
64
+ { name: "connectionId", type: "bytes32" },
65
+ ],
66
+ },
67
+ primaryType: "Agent",
68
+ message: {
69
+ source: isTestnet ? "b" : "a",
70
+ connectionId: actionHash,
71
+ },
72
+ });
73
+
74
+ // 3. Convert signature to recovery format (v, r, s)
75
+ const sigr = secp.etc.concatBytes(
76
+ new Uint8Array([signature.v - 27]),
77
+ secp.etc.hexToBytes(signature.r.slice(2)),
78
+ secp.etc.hexToBytes(signature.s.slice(2)),
79
+ );
80
+
81
+ // 4. Recover the public key from the signature and hash
82
+ const compressedPubKey = await secp.recoverPublicKeyAsync(sigr, hash, { prehash: false });
83
+ const uncompressedPubKey = secp.Point.fromBytes(compressedPubKey).toBytes(false);
84
+
85
+ // 5. Convert the public key to an Ethereum address
86
+ return publicKeyToAddress(uncompressedPubKey);
87
+ }
88
+
89
+ /**
90
+ * Recover the Ethereum address that signed a user-signed action.
91
+ * @example
92
+ * ```ts
93
+ * import { recoverUserFromUserSigned } from "@nktkas/hyperliquid/utils";
94
+ *
95
+ * const action = {
96
+ * type: "approveAgent",
97
+ * signatureChainId: "0x66eee" as const,
98
+ * hyperliquidChain: "Mainnet",
99
+ * agentAddress: "0x...",
100
+ * agentName: "Agent",
101
+ * nonce: 1700000000000,
102
+ * };
103
+ * const types = {
104
+ * HyperliquidTransaction: [
105
+ * { name: "hyperliquidChain", type: "string" },
106
+ * // ... other fields
107
+ * ],
108
+ * };
109
+ * const signature = {
110
+ * r: "0x...",
111
+ * s: "0x...",
112
+ * v: 27,
113
+ * } as const;
114
+ *
115
+ * const address = await recoverUserFromUserSigned({ action, types, signature });
116
+ * console.log(`Signer address: ${address}`);
117
+ * ```
118
+ */
119
+ export async function recoverUserFromUserSigned(params: {
120
+ /** The action that was signed (hex strings must be in lower case). */
121
+ action:
122
+ & {
123
+ signatureChainId: `0x${string}`;
124
+ [key: string]: unknown;
125
+ }
126
+ & (
127
+ | { nonce: number; time?: undefined }
128
+ | { time: number; nonce?: undefined }
129
+ );
130
+ /** The types of the action (hash depends on key order). */
131
+ types: {
132
+ [key: string]: {
133
+ name: string;
134
+ type: string;
135
+ }[];
136
+ };
137
+ /** The signature to recover the address from. */
138
+ signature: Signature;
139
+ }): Promise<`0x${string}`> {
140
+ const { action, types, signature } = params;
141
+
142
+ // 1. Hash the typed data according to EIP-712
143
+ const hash = hashTypedData({
144
+ domain: {
145
+ name: "HyperliquidSignTransaction",
146
+ version: "1",
147
+ chainId: parseInt(action.signatureChainId),
148
+ verifyingContract: "0x0000000000000000000000000000000000000000",
149
+ },
150
+ types,
151
+ primaryType: Object.keys(types)[0],
152
+ message: action,
153
+ });
154
+
155
+ // 2. Convert signature to recovery format (v, r, s)
156
+ const sigr = secp.etc.concatBytes(
157
+ new Uint8Array([signature.v - 27]),
158
+ secp.etc.hexToBytes(signature.r.slice(2)),
159
+ secp.etc.hexToBytes(signature.s.slice(2)),
160
+ );
161
+
162
+ // 3. Recover the public key from the signature and hash
163
+ const compressedPubKey = await secp.recoverPublicKeyAsync(sigr, hash, { prehash: false });
164
+ const uncompressedPubKey = secp.Point.fromBytes(compressedPubKey).toBytes(false);
165
+
166
+ // 4. Convert the public key to an Ethereum address
167
+ return publicKeyToAddress(uncompressedPubKey);
168
+ }
169
+
170
+ /** Convert a public key to an Ethereum address. */
171
+ function publicKeyToAddress(publicKey: Uint8Array): `0x${string}` {
172
+ // Remove the 0x04 prefix from uncompressed public key
173
+ const publicKeyWithoutPrefix = publicKey.slice(1);
174
+ // Hash the public key and take the last 20 bytes as the address
175
+ const hash = keccak_256(publicKeyWithoutPrefix);
176
+ const addressBytes = hash.slice(-20);
177
+ return `0x${secp.etc.bytesToHex(addressBytes)}`;
178
+ }
@@ -25,6 +25,9 @@ export interface SymbolConverterOptions {
25
25
  * const transport = new HttpTransport(); // or `WebSocketTransport`
26
26
  * const converter = await SymbolConverter.create({ transport });
27
27
  *
28
+ * // By default, dexs are not loaded; specify them when creating an instance
29
+ * // const converter = await SymbolConverter.create({ transport, dexs: ["test"] });
30
+ *
28
31
  * const btcId = converter.getAssetId("BTC"); // perpetual → 0
29
32
  * const hypeUsdcId = converter.getAssetId("HYPE/USDC"); // spot market → 10107
30
33
  * const dexAbcId = converter.getAssetId("test:ABC"); // builder dex (if enabled) → 110000
@@ -32,6 +35,8 @@ export interface SymbolConverterOptions {
32
35
  * const btcSzDecimals = converter.getSzDecimals("BTC"); // perpetual → 5
33
36
  * const hypeUsdcSzDecimals = converter.getSzDecimals("HYPE/USDC"); // spot market → 2
34
37
  * const dexAbcSzDecimals = converter.getSzDecimals("test:ABC"); // builder dex (if enabled) → 0
38
+ *
39
+ * const spotPairId = converter.getSpotPairId("HFUN/USDC"); // → "@2"
35
40
  * ```
36
41
  */
37
42
  export class SymbolConverter {
@@ -39,6 +44,7 @@ export class SymbolConverter {
39
44
  private readonly dexOption: DexOption;
40
45
  private readonly nameToAssetId = new Map<string, number>();
41
46
  private readonly nameToSzDecimals = new Map<string, number>();
47
+ private readonly nameToSpotPairId = new Map<string, string>();
42
48
 
43
49
  private constructor(options: SymbolConverterOptions) {
44
50
  this.transport = options.transport;
@@ -86,6 +92,7 @@ export class SymbolConverter {
86
92
 
87
93
  this.nameToAssetId.clear();
88
94
  this.nameToSzDecimals.clear();
95
+ this.nameToSpotPairId.clear();
89
96
 
90
97
  this.processDefaultPerps(perpMetaData);
91
98
  this.processSpotAssets(spotMetaData);
@@ -158,6 +165,7 @@ export class SymbolConverter {
158
165
  const baseQuoteKey = `${baseToken.name}/${quoteToken.name}`;
159
166
  this.nameToAssetId.set(baseQuoteKey, assetId);
160
167
  this.nameToSzDecimals.set(baseQuoteKey, baseToken.szDecimals);
168
+ this.nameToSpotPairId.set(baseQuoteKey, market.name);
161
169
  });
162
170
  }
163
171
 
@@ -182,4 +190,14 @@ export class SymbolConverter {
182
190
  getSzDecimals(name: string): number | undefined {
183
191
  return this.nameToSzDecimals.get(name);
184
192
  }
193
+
194
+ /**
195
+ * Get spot pair ID for info endpoints and subscriptions (e.g., l2book, trades).
196
+ *
197
+ * Accepts spot markets in the "BASE/QUOTE" format (e.g., "HFUN/USDC").
198
+ * @example "HFUN/USDC" → "@2", "PURR/USDC" → "PURR/USDC"
199
+ */
200
+ getSpotPairId(name: string): string | undefined {
201
+ return this.nameToSpotPairId.get(name);
202
+ }
185
203
  }
@@ -1 +1,3 @@
1
1
  export * from "./_symbolConverter.js";
2
+ export * from "./_format.js";
3
+ export * from "./_recover.js";
@@ -1,30 +0,0 @@
1
- /**
2
- * Sequential request execution to prevent nonce race conditions.
3
- *
4
- * Problem: When multiple requests are sent rapidly, they may execute in different order
5
- * on the transport layer, causing nonce errors (e.g., server receives nonce 101 before 100).
6
- *
7
- * Solution: Queue ensures requests execute sequentially in order.
8
- */
9
- import type { ExchangeRequestConfig, MultiSignRequestConfig } from "./_types.js";
10
- /**
11
- * Request queue for sequential execution of requests.
12
- * Ensures that requests are executed in order, preventing them from arriving at the server out of sequence.
13
- */
14
- declare class RequestQueue {
15
- private queue;
16
- /**
17
- * Enqueue a request to be executed sequentially.
18
- * @param fn - The function to execute.
19
- * @returns A promise that resolves with the result of the function.
20
- */
21
- enqueue<T>(fn: () => Promise<T>): Promise<T>;
22
- }
23
- /**
24
- * Get or create a request queue for the given config.
25
- * Uses a global Map keyed by wallet address to ensure the same wallet uses the same queue
26
- * regardless of whether called via client or direct function.
27
- */
28
- export declare function getRequestQueue(config: ExchangeRequestConfig | MultiSignRequestConfig): Promise<RequestQueue | undefined>;
29
- export {};
30
- //# sourceMappingURL=_sequential.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_sequential.d.ts","sourceRoot":"","sources":["../../../../../src/src/api/exchange/_base/_sequential.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAGjF;;;GAGG;AACH,cAAM,YAAY;IAChB,OAAO,CAAC,KAAK,CAAuC;IAEpD;;;;OAIG;IACH,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAK7C;AAmBD;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,qBAAqB,GAAG,sBAAsB,GACrD,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CA0BnC"}