@nktkas/hyperliquid 0.22.2 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/README.md +47 -49
  2. package/esm/src/base.d.ts +4 -1
  3. package/esm/src/base.d.ts.map +1 -1
  4. package/esm/src/base.js +2 -2
  5. package/esm/src/clients/exchange.d.ts +289 -207
  6. package/esm/src/clients/exchange.d.ts.map +1 -1
  7. package/esm/src/clients/exchange.js +605 -410
  8. package/esm/src/clients/info.d.ts +137 -41
  9. package/esm/src/clients/info.d.ts.map +1 -1
  10. package/esm/src/clients/info.js +124 -28
  11. package/esm/src/clients/multiSign.d.ts +285 -204
  12. package/esm/src/clients/multiSign.d.ts.map +1 -1
  13. package/esm/src/clients/multiSign.js +521 -493
  14. package/esm/src/clients/subscription.d.ts +38 -3
  15. package/esm/src/clients/subscription.d.ts.map +1 -1
  16. package/esm/src/clients/subscription.js +36 -3
  17. package/esm/src/signing/{_ethers.d.ts → _signTypedData/ethers.d.ts} +1 -1
  18. package/esm/src/signing/_signTypedData/ethers.d.ts.map +1 -0
  19. package/esm/src/signing/_signTypedData/mod.d.ts +35 -0
  20. package/esm/src/signing/_signTypedData/mod.d.ts.map +1 -0
  21. package/esm/src/signing/_signTypedData/mod.js +59 -0
  22. package/esm/src/signing/_signTypedData/private_key.d.ts +26 -0
  23. package/esm/src/signing/_signTypedData/private_key.d.ts.map +1 -0
  24. package/esm/src/signing/_signTypedData/private_key.js +144 -0
  25. package/esm/src/signing/{_viem.d.ts → _signTypedData/viem.d.ts} +2 -2
  26. package/esm/src/signing/_signTypedData/viem.d.ts.map +1 -0
  27. package/{script/src/signing/_window.d.ts → esm/src/signing/_signTypedData/window.d.ts} +18 -12
  28. package/esm/src/signing/_signTypedData/window.d.ts.map +1 -0
  29. package/esm/src/signing/{_window.js → _signTypedData/window.js} +3 -2
  30. package/esm/src/signing/_sorter.d.ts +56 -82
  31. package/esm/src/signing/_sorter.d.ts.map +1 -1
  32. package/esm/src/signing/_sorter.js +36 -49
  33. package/esm/src/signing/mod.d.ts +151 -130
  34. package/esm/src/signing/mod.d.ts.map +1 -1
  35. package/esm/src/signing/mod.js +182 -228
  36. package/esm/src/transports/base.d.ts +1 -1
  37. package/esm/src/transports/base.d.ts.map +1 -1
  38. package/esm/src/transports/base.js +2 -2
  39. package/esm/src/transports/http/http_transport.d.ts +9 -15
  40. package/esm/src/transports/http/http_transport.d.ts.map +1 -1
  41. package/esm/src/transports/http/http_transport.js +64 -59
  42. package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +1 -1
  43. package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
  44. package/esm/src/transports/websocket/_hyperliquid_event_target.js +1 -1
  45. package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
  46. package/esm/src/transports/websocket/_reconnecting_websocket.js +17 -4
  47. package/esm/src/transports/websocket/_websocket_async_request.d.ts +0 -9
  48. package/esm/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
  49. package/esm/src/transports/websocket/_websocket_async_request.js +14 -20
  50. package/esm/src/transports/websocket/websocket_transport.d.ts +8 -4
  51. package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  52. package/esm/src/transports/websocket/websocket_transport.js +83 -54
  53. package/esm/src/types/exchange/requests.d.ts +27 -51
  54. package/esm/src/types/exchange/requests.d.ts.map +1 -1
  55. package/esm/src/types/explorer/requests.d.ts +5 -8
  56. package/esm/src/types/explorer/requests.d.ts.map +1 -1
  57. package/esm/src/types/info/accounts.d.ts +5 -5
  58. package/esm/src/types/info/accounts.d.ts.map +1 -1
  59. package/esm/src/types/info/delegations.d.ts +1 -1
  60. package/esm/src/types/info/delegations.d.ts.map +1 -1
  61. package/esm/src/types/info/orders.d.ts +1 -1
  62. package/esm/src/types/info/orders.d.ts.map +1 -1
  63. package/esm/src/types/info/requests.d.ts +49 -96
  64. package/esm/src/types/info/requests.d.ts.map +1 -1
  65. package/esm/src/types/subscriptions/requests.d.ts +72 -18
  66. package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
  67. package/esm/src/types/subscriptions/responses.d.ts +2 -0
  68. package/esm/src/types/subscriptions/responses.d.ts.map +1 -1
  69. package/package.json +8 -5
  70. package/script/mod.js +13 -23
  71. package/script/src/base.d.ts +4 -1
  72. package/script/src/base.d.ts.map +1 -1
  73. package/script/src/base.js +10 -20
  74. package/script/src/clients/exchange.d.ts +289 -207
  75. package/script/src/clients/exchange.d.ts.map +1 -1
  76. package/script/src/clients/exchange.js +2000 -1815
  77. package/script/src/clients/info.d.ts +137 -41
  78. package/script/src/clients/info.d.ts.map +1 -1
  79. package/script/src/clients/info.js +1296 -1210
  80. package/script/src/clients/multiSign.d.ts +285 -204
  81. package/script/src/clients/multiSign.d.ts.map +1 -1
  82. package/script/src/clients/multiSign.js +2043 -2025
  83. package/script/src/clients/subscription.d.ts +38 -3
  84. package/script/src/clients/subscription.d.ts.map +1 -1
  85. package/script/src/clients/subscription.js +568 -545
  86. package/script/src/signing/{_ethers.d.ts → _signTypedData/ethers.d.ts} +1 -1
  87. package/script/src/signing/_signTypedData/ethers.d.ts.map +1 -0
  88. package/script/src/signing/_signTypedData/ethers.js +16 -0
  89. package/script/src/signing/_signTypedData/mod.d.ts +35 -0
  90. package/script/src/signing/_signTypedData/mod.d.ts.map +1 -0
  91. package/script/src/signing/_signTypedData/mod.js +67 -0
  92. package/script/src/signing/_signTypedData/private_key.d.ts +26 -0
  93. package/script/src/signing/_signTypedData/private_key.d.ts.map +1 -0
  94. package/script/src/signing/_signTypedData/private_key.js +148 -0
  95. package/script/src/signing/{_viem.d.ts → _signTypedData/viem.d.ts} +2 -2
  96. package/script/src/signing/_signTypedData/viem.d.ts.map +1 -0
  97. package/script/src/signing/_signTypedData/viem.js +9 -0
  98. package/{esm/src/signing/_window.d.ts → script/src/signing/_signTypedData/window.d.ts} +18 -12
  99. package/script/src/signing/_signTypedData/window.d.ts.map +1 -0
  100. package/script/src/signing/_signTypedData/window.js +34 -0
  101. package/script/src/signing/_sorter.d.ts +56 -82
  102. package/script/src/signing/_sorter.d.ts.map +1 -1
  103. package/script/src/signing/_sorter.js +655 -678
  104. package/script/src/signing/mod.d.ts +151 -130
  105. package/script/src/signing/mod.d.ts.map +1 -1
  106. package/script/src/signing/mod.js +286 -342
  107. package/script/src/transports/base.d.ts +1 -1
  108. package/script/src/transports/base.d.ts.map +1 -1
  109. package/script/src/transports/base.js +11 -21
  110. package/script/src/transports/http/http_transport.d.ts +9 -15
  111. package/script/src/transports/http/http_transport.d.ts.map +1 -1
  112. package/script/src/transports/http/http_transport.js +97 -102
  113. package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +1 -1
  114. package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
  115. package/script/src/transports/websocket/_hyperliquid_event_target.js +51 -61
  116. package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
  117. package/script/src/transports/websocket/_reconnecting_websocket.js +271 -268
  118. package/script/src/transports/websocket/_websocket_async_request.d.ts +0 -9
  119. package/script/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
  120. package/script/src/transports/websocket/_websocket_async_request.js +157 -174
  121. package/script/src/transports/websocket/websocket_transport.d.ts +8 -4
  122. package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  123. package/script/src/transports/websocket/websocket_transport.js +209 -189
  124. package/script/src/types/exchange/requests.d.ts +27 -51
  125. package/script/src/types/exchange/requests.d.ts.map +1 -1
  126. package/script/src/types/exchange/requests.js +2 -12
  127. package/script/src/types/exchange/responses.js +2 -12
  128. package/script/src/types/explorer/requests.d.ts +5 -8
  129. package/script/src/types/explorer/requests.d.ts.map +1 -1
  130. package/script/src/types/explorer/requests.js +2 -12
  131. package/script/src/types/explorer/responses.js +2 -12
  132. package/script/src/types/info/accounts.d.ts +5 -5
  133. package/script/src/types/info/accounts.d.ts.map +1 -1
  134. package/script/src/types/info/accounts.js +2 -12
  135. package/script/src/types/info/assets.js +2 -12
  136. package/script/src/types/info/delegations.d.ts +1 -1
  137. package/script/src/types/info/delegations.d.ts.map +1 -1
  138. package/script/src/types/info/delegations.js +2 -12
  139. package/script/src/types/info/markets.js +2 -12
  140. package/script/src/types/info/orders.d.ts +1 -1
  141. package/script/src/types/info/orders.d.ts.map +1 -1
  142. package/script/src/types/info/orders.js +2 -12
  143. package/script/src/types/info/requests.d.ts +49 -96
  144. package/script/src/types/info/requests.d.ts.map +1 -1
  145. package/script/src/types/info/requests.js +2 -12
  146. package/script/src/types/info/vaults.js +2 -12
  147. package/script/src/types/mod.js +2 -12
  148. package/script/src/types/subscriptions/requests.d.ts +72 -18
  149. package/script/src/types/subscriptions/requests.d.ts.map +1 -1
  150. package/script/src/types/subscriptions/requests.js +2 -12
  151. package/script/src/types/subscriptions/responses.d.ts +2 -0
  152. package/script/src/types/subscriptions/responses.d.ts.map +1 -1
  153. package/script/src/types/subscriptions/responses.js +2 -12
  154. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts +0 -2
  155. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts.map +0 -1
  156. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +0 -1
  157. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts +0 -95
  158. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts.map +0 -1
  159. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +0 -10
  160. package/esm/deps/jsr.io/@std/async/1.0.13/delay.d.ts +0 -43
  161. package/esm/deps/jsr.io/@std/async/1.0.13/delay.d.ts.map +0 -1
  162. package/esm/deps/jsr.io/@std/async/1.0.13/delay.js +0 -63
  163. package/esm/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts +0 -9
  164. package/esm/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts.map +0 -1
  165. package/esm/deps/jsr.io/@std/bytes/1.0.6/_types.js +0 -2
  166. package/esm/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts +0 -21
  167. package/esm/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts.map +0 -1
  168. package/esm/deps/jsr.io/@std/bytes/1.0.6/concat.js +0 -32
  169. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
  170. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
  171. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -51
  172. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
  173. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
  174. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -13
  175. package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
  176. package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
  177. package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -2
  178. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
  179. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
  180. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -87
  181. package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +0 -9
  182. package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +0 -1
  183. package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.js +0 -2
  184. package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts +0 -39
  185. package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +0 -1
  186. package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.js +0 -237
  187. package/esm/src/signing/_ethers.d.ts.map +0 -1
  188. package/esm/src/signing/_private_key.d.ts +0 -22
  189. package/esm/src/signing/_private_key.d.ts.map +0 -1
  190. package/esm/src/signing/_private_key.js +0 -124
  191. package/esm/src/signing/_viem.d.ts.map +0 -1
  192. package/esm/src/signing/_window.d.ts.map +0 -1
  193. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts +0 -2
  194. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts.map +0 -1
  195. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +0 -27
  196. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts +0 -95
  197. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts.map +0 -1
  198. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +0 -24
  199. package/script/deps/jsr.io/@std/async/1.0.13/delay.d.ts +0 -43
  200. package/script/deps/jsr.io/@std/async/1.0.13/delay.d.ts.map +0 -1
  201. package/script/deps/jsr.io/@std/async/1.0.13/delay.js +0 -76
  202. package/script/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts +0 -9
  203. package/script/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts.map +0 -1
  204. package/script/deps/jsr.io/@std/bytes/1.0.6/_types.js +0 -13
  205. package/script/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts +0 -21
  206. package/script/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts.map +0 -1
  207. package/script/deps/jsr.io/@std/bytes/1.0.6/concat.js +0 -45
  208. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
  209. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
  210. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -67
  211. package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
  212. package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
  213. package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -26
  214. package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
  215. package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
  216. package/script/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -13
  217. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
  218. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
  219. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -101
  220. package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +0 -9
  221. package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +0 -1
  222. package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.js +0 -13
  223. package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts +0 -39
  224. package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +0 -1
  225. package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.js +0 -250
  226. package/script/src/signing/_ethers.d.ts.map +0 -1
  227. package/script/src/signing/_ethers.js +0 -26
  228. package/script/src/signing/_private_key.d.ts +0 -22
  229. package/script/src/signing/_private_key.d.ts.map +0 -1
  230. package/script/src/signing/_private_key.js +0 -138
  231. package/script/src/signing/_viem.d.ts.map +0 -1
  232. package/script/src/signing/_viem.js +0 -19
  233. package/script/src/signing/_window.d.ts.map +0 -1
  234. package/script/src/signing/_window.js +0 -43
  235. /package/esm/src/signing/{_ethers.js → _signTypedData/ethers.js} +0 -0
  236. /package/esm/src/signing/{_viem.js → _signTypedData/viem.js} +0 -0
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Hyperliquid API TypeScript SDK
2
2
 
3
- [![NPM](https://img.shields.io/npm/v/@nktkas/hyperliquid?style=flat-square&color=blue)](https://www.npmjs.com/package/@nktkas/hyperliquid)
4
- [![JSR](https://img.shields.io/jsr/v/@nktkas/hyperliquid?style=flat-square&color=blue)](https://jsr.io/@nktkas/hyperliquid)
5
- [![Coveralls](https://img.shields.io/coverallsCoverage/github/nktkas/hyperliquid?style=flat-square)](https://coveralls.io/github/nktkas/hyperliquid)
6
- [![bundlejs](https://img.shields.io/bundlejs/size/@nktkas/hyperliquid?style=flat-square)](https://bundlejs.com/?q=@nktkas/hyperliquid)
3
+ [![npm](https://img.shields.io/npm/v/@nktkas/hyperliquid?style=flat-square&color=blue)](https://www.npmjs.com/package/@nktkas/hyperliquid)
4
+ [![jsr](https://img.shields.io/jsr/v/@nktkas/hyperliquid?style=flat-square&color=blue)](https://jsr.io/@nktkas/hyperliquid)
5
+ [![coveralls](https://img.shields.io/coverallsCoverage/github/nktkas/hyperliquid?style=flat-square)](https://coveralls.io/github/nktkas/hyperliquid)
6
+ [![bundlephobia](https://img.shields.io/bundlephobia/minzip/@nktkas/hyperliquid?style=flat-square)](https://bundlephobia.com/package/@nktkas/hyperliquid)
7
7
 
8
8
  Unofficial [Hyperliquid API](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api) SDK for all major JS
9
9
  runtimes, written in TypeScript and provided with tests.
@@ -44,17 +44,18 @@ deno add jsr:@nktkas/hyperliquid
44
44
  ```html
45
45
  <script type="module">
46
46
  import * as hl from "https://esm.sh/jsr/@nktkas/hyperliquid";
47
- // Use hl.InfoClient, hl.ExchangeClient, etc.
48
47
  </script>
49
48
  ```
50
49
 
51
50
  ### React Native
52
51
 
53
52
  <details>
54
- <summary>For React Native, you need to import several polyfills before importing the SDK:</summary>
53
+ <summary>For React Native, you need to import polyfills before importing the SDK:</summary>
55
54
 
56
55
  ```js
57
- // React Native 0.76.3
56
+ // React Native v0.76.3 / Expo v52
57
+ // Issues:
58
+ // - signing: does not support private keys directly, use viem or ethers
58
59
  import { Event, EventTarget } from "event-target-shim";
59
60
 
60
61
  if (!globalThis.EventTarget || !globalThis.Event) {
@@ -174,16 +175,15 @@ const signers = [
174
175
  ] as const;
175
176
 
176
177
  const transport = new hl.HttpTransport();
177
- const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers }); // extends ExchangeClient
178
+ const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers }); // extends `ExchangeClient`
178
179
 
179
- const data = await multiSignClient.approveAgent({ // same API as ExchangeClient
180
+ const data = await multiSignClient.approveAgent({ // same API as `ExchangeClient`
180
181
  agentAddress: "0x...",
181
182
  agentName: "agentName",
182
183
  });
183
184
  ```
184
185
 
185
- <details>
186
- <summary><h2>Usage</h2></summary>
186
+ ## Usage
187
187
 
188
188
  ### 1) Initialize Transport
189
189
 
@@ -192,11 +192,11 @@ First, choose and configure your transport layer (more details in the [API Refer
192
192
  ```ts
193
193
  import * as hl from "@nktkas/hyperliquid";
194
194
 
195
- // HTTP Transport
196
- const httpTransport = new hl.HttpTransport(); // Accepts optional parameters
195
+ // 1. HTTP Transport: suitable for one-time requests or serverless environments
196
+ const httpTransport = new hl.HttpTransport(); // Accepts optional parameters (e.g. isTestnet, timeout, etc.)
197
197
 
198
- // WebSocket Transport
199
- const wsTransport = new hl.WebSocketTransport(); // Accepts optional parameters
198
+ // 2. WebSocket Transport: has better network latency than HTTP transport
199
+ const wsTransport = new hl.WebSocketTransport(); // Accepts optional parameters (e.g. url, timeout, reconnect, etc.)
200
200
  ```
201
201
 
202
202
  ### 2) Initialize Client
@@ -208,7 +208,7 @@ Next, initialize a client with the transport layer (more details in the [API Ref
208
208
  ```ts
209
209
  import * as hl from "@nktkas/hyperliquid";
210
210
 
211
- const transport = new hl.HttpTransport(); // or WebSocketTransport
211
+ const transport = new hl.HttpTransport(); // or `WebSocketTransport`
212
212
  const infoClient = new hl.InfoClient({ transport });
213
213
  ```
214
214
 
@@ -220,17 +220,17 @@ import { createWalletClient, custom } from "viem";
220
220
  import { privateKeyToAccount } from "viem/accounts";
221
221
  import { ethers } from "ethers";
222
222
 
223
- const transport = new hl.HttpTransport(); // or WebSocketTransport
223
+ const transport = new hl.HttpTransport(); // or `WebSocketTransport`
224
224
 
225
- // 1. Using private key
225
+ // 1. Using private key directly
226
226
  const privateKey = "0x...";
227
227
  const exchClient_privateKey = new hl.ExchangeClient({ wallet: privateKey, transport });
228
228
 
229
- // 2. Using Viem with private key
229
+ // 2. Using Viem
230
230
  const viemAccount = privateKeyToAccount("0x...");
231
231
  const exchClient_viem = new hl.ExchangeClient({ wallet: viemAccount, transport });
232
232
 
233
- // 3. Using Ethers (or Ethers V5) with private key
233
+ // 3. Using Ethers (or Ethers V5)
234
234
  const ethersWallet = new ethers.Wallet("0x...");
235
235
  const exchClient_ethers = new hl.ExchangeClient({ wallet: ethersWallet, transport });
236
236
 
@@ -239,7 +239,7 @@ const [account] = await window.ethereum.request({ method: "eth_requestAccounts"
239
239
  const externalWallet = createWalletClient({ account, transport: custom(window.ethereum) });
240
240
  const exchClient_viemMetamask = new hl.ExchangeClient({ wallet: externalWallet, transport });
241
241
 
242
- // 5. Using external wallet (e.g. MetaMask) via `window.ethereum` (EIP-1193)
242
+ // 5. Using external wallet (e.g. MetaMask) via `window.ethereum`
243
243
  const exchClient_windowMetamask = new hl.ExchangeClient({ wallet: window.ethereum, transport });
244
244
  ```
245
245
 
@@ -248,7 +248,7 @@ const exchClient_windowMetamask = new hl.ExchangeClient({ wallet: window.ethereu
248
248
  ```ts
249
249
  import * as hl from "@nktkas/hyperliquid";
250
250
 
251
- const transport = new hl.WebSocketTransport(); // only WebSocketTransport
251
+ const transport = new hl.WebSocketTransport(); // only `WebSocketTransport`
252
252
  const subsClient = new hl.SubscriptionClient({ transport });
253
253
  ```
254
254
 
@@ -264,7 +264,7 @@ const signers = [
264
264
  privateKeyToAccount("0x..."), // first is leader for multi-sign transaction, must contain own address
265
265
  new ethers.Wallet("0x..."),
266
266
  { // can be a custom async wallet
267
- signTypedData(params: {
267
+ async signTypedData(params: {
268
268
  domain: {
269
269
  name: string;
270
270
  version: string;
@@ -281,14 +281,14 @@ const signers = [
281
281
  message: Record<string, unknown>;
282
282
  }): Promise<Hex> {
283
283
  // Custom signer logic
284
- return "0x..."; // return signature
284
+ return "0x..."; // return hex signature
285
285
  },
286
286
  },
287
287
  "0x...", // private key directly
288
288
  ];
289
289
 
290
290
  const transport = new hl.HttpTransport();
291
- const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers }); // extends ExchangeClient
291
+ const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers }); // extends `ExchangeClient`
292
292
  ```
293
293
 
294
294
  ### 3) Use Client
@@ -390,7 +390,7 @@ const signers = [
390
390
  const transport = new hl.HttpTransport();
391
391
  const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
392
392
 
393
- // Interaction is the same as with ExchangeClient
393
+ // Interaction is the same as with `ExchangeClient`
394
394
 
395
395
  // Place an orders
396
396
  const result = await multiSignClient.order({
@@ -422,10 +422,7 @@ const result = await multiSignClient.withdraw3({
422
422
  });
423
423
  ```
424
424
 
425
- </details>
426
-
427
- <details>
428
- <summary><h2>API Reference</h2></summary>
425
+ ## API Reference
429
426
 
430
427
  ### Clients
431
428
 
@@ -513,6 +510,7 @@ class ExchangeClient {
513
510
  constructor(args: {
514
511
  transport: HttpTransport | WebSocketTransport;
515
512
  wallet:
513
+ | Hex // Private key directly
516
514
  | AbstractViemWalletClient // viem
517
515
  | AbstractEthersSigner // ethers
518
516
  | AbstractEthersV5Signer // ethers v5
@@ -550,6 +548,7 @@ class ExchangeClient {
550
548
 
551
549
  // Transfer
552
550
  perpDexClassTransfer(args: PerpDexClassTransferParameters): Promise<SuccessResponse>;
551
+ perpDexTransfer(args: PerpDexTransferParameters): Promise<SuccessResponse>;
553
552
  spotSend(args: SpotSendParameters): Promise<SuccessResponse>;
554
553
  subAccountSpotTransfer(args: SubAccountSpotTransferParameters): Promise<SuccessResponse>;
555
554
  subAccountTransfer(args: SubAccountTransferParameters): Promise<SuccessResponse>;
@@ -635,16 +634,18 @@ class MultiSignClient extends ExchangeClient {
635
634
  },
636
635
  );
637
636
 
638
- // Same methods as ExchangeClient
637
+ // Same methods as `ExchangeClient`
639
638
  }
640
639
  ```
641
640
 
642
641
  ### Transports
643
642
 
644
- Transport acts as a layer between the class and Hyperliquid servers.
643
+ Transport acts as a layer between class requests and Hyperliquid servers.
645
644
 
646
645
  #### HTTP Transport
647
646
 
647
+ HTTP transport is suitable for one-off requests or serverless environments.
648
+
648
649
  ```ts
649
650
  class HttpTransport {
650
651
  constructor(options?: {
@@ -663,6 +664,8 @@ class HttpTransport {
663
664
 
664
665
  #### WebSocket Transport
665
666
 
667
+ WebSocket transport has better network latency than HTTP transport.
668
+
666
669
  ```ts
667
670
  class WebSocketTransport {
668
671
  constructor(options?: {
@@ -686,10 +689,7 @@ class WebSocketTransport {
686
689
  }
687
690
  ```
688
691
 
689
- </details>
690
-
691
- <details>
692
- <summary><h2>Additional Import Points</h2></summary>
692
+ ## Additional Import Points
693
693
 
694
694
  ### `/types`
695
695
 
@@ -709,22 +709,22 @@ import { actionSorter, signL1Action } from "@nktkas/hyperliquid/signing";
709
709
 
710
710
  const privateKey = "0x..."; // or `viem`, `ethers`
711
711
 
712
+ const nonce = Date.now();
712
713
  const action = {
713
714
  type: "cancel",
714
715
  cancels: [
715
716
  { a: 0, o: 12345 },
716
717
  ],
717
- };
718
- const nonce = Date.now();
718
+ } as const;
719
719
 
720
720
  const signature = await signL1Action({
721
721
  wallet: privateKey,
722
- action: actionSorter[action.type](action), // key order affects signature
722
+ action: actionSorter[action.type](action),
723
723
  nonce,
724
- isTestnet: true, // change to `false` for mainnet
725
724
  });
726
725
 
727
- const response = await fetch("https://api.hyperliquid-testnet.xyz/exchange", {
726
+ // Send the signed action to the Hyperliquid API
727
+ const response = await fetch("https://api.hyperliquid.xyz/exchange", {
728
728
  method: "POST",
729
729
  headers: { "Content-Type": "application/json" },
730
730
  body: JSON.stringify({ action, signature, nonce }),
@@ -741,21 +741,21 @@ const privateKey = "0x..."; // or `viem`, `ethers`
741
741
 
742
742
  const action = {
743
743
  type: "approveAgent",
744
- signatureChainId: "0x66eee", // must match the current wallet network
745
- hyperliquidChain: "Testnet", // Mainnet | Testnet
744
+ signatureChainId: "0x66eee",
745
+ hyperliquidChain: "Mainnet",
746
746
  agentAddress: "0x...",
747
747
  agentName: "Agent",
748
748
  nonce: Date.now(),
749
- };
749
+ } as const;
750
750
 
751
751
  const signature = await signUserSignedAction({
752
752
  wallet: privateKey,
753
753
  action,
754
- types: userSignedActionEip712Types[action.type], // key order affects signature
755
- chainId: parseInt(action.signatureChainId, 16),
754
+ types: userSignedActionEip712Types[action.type],
756
755
  });
757
756
 
758
- const response = await fetch("https://api.hyperliquid-testnet.xyz/exchange", {
757
+ // Send the signed action to the Hyperliquid API
758
+ const response = await fetch("https://api.hyperliquid.xyz/exchange", {
759
759
  method: "POST",
760
760
  headers: { "Content-Type": "application/json" },
761
761
  body: JSON.stringify({ action, signature, nonce: action.nonce }),
@@ -763,8 +763,6 @@ const response = await fetch("https://api.hyperliquid-testnet.xyz/exchange", {
763
763
  const body = await response.json();
764
764
  ```
765
765
 
766
- </details>
767
-
768
766
  ## Contributing
769
767
 
770
768
  We appreciate your help! To contribute, please read the [contributing instructions](CONTRIBUTING.md).
package/esm/src/base.d.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  export type Hex = `0x${string}`;
2
2
  export type MaybePromise<T> = T | Promise<T>;
3
+ export type DeepImmutable<T> = {
4
+ readonly [K in keyof T]: DeepImmutable<T[K]>;
5
+ };
3
6
  /** Base error class for all SDK errors. */
4
7
  export declare class HyperliquidError extends Error {
5
- constructor(message?: string);
8
+ constructor(message?: string, options?: ErrorOptions);
6
9
  }
7
10
  //# sourceMappingURL=base.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/src/base.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAEhC,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE7C,2CAA2C;AAC3C,qBAAa,gBAAiB,SAAQ,KAAK;gBAC3B,OAAO,CAAC,EAAE,MAAM;CAI/B"}
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/src/base.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAEhC,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAG7C,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;IAC3B,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC/C,CAAC;AAEF,2CAA2C;AAC3C,qBAAa,gBAAiB,SAAQ,KAAK;gBAC3B,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIvD"}
package/esm/src/base.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /** Base error class for all SDK errors. */
2
2
  export class HyperliquidError extends Error {
3
- constructor(message) {
4
- super(message);
3
+ constructor(message, options) {
4
+ super(message, options);
5
5
  this.name = "HyperliquidError";
6
6
  }
7
7
  }