@nktkas/hyperliquid 0.13.1 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +33 -17
  3. package/esm/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts +9 -0
  4. package/esm/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts.map +1 -0
  5. package/esm/deps/jsr.io/@std/bytes/1.0.5/_types.js +2 -0
  6. package/esm/deps/jsr.io/@std/bytes/{1.0.4 → 1.0.5}/concat.d.ts +3 -1
  7. package/esm/deps/jsr.io/@std/bytes/1.0.5/concat.d.ts.map +1 -0
  8. package/esm/deps/jsr.io/@std/bytes/{1.0.4 → 1.0.5}/concat.js +1 -1
  9. package/esm/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts +9 -0
  10. package/esm/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts.map +1 -0
  11. package/esm/deps/jsr.io/@std/encoding/1.0.7/_types.js +2 -0
  12. package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts.map +1 -1
  13. package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.js +1 -1
  14. package/{script/deps/jsr.io/@std/encoding/1.0.6 → esm/deps/jsr.io/@std/encoding/1.0.7}/hex.d.ts +3 -1
  15. package/esm/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +1 -0
  16. package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/hex.js +1 -1
  17. package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +9 -0
  18. package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +1 -0
  19. package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.js +2 -0
  20. package/esm/deps/jsr.io/@std/msgpack/{1.0.2 → 1.0.3}/encode.d.ts +3 -1
  21. package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +1 -0
  22. package/esm/deps/jsr.io/@std/msgpack/{1.0.2 → 1.0.3}/encode.js +2 -2
  23. package/esm/mod.d.ts +1 -0
  24. package/esm/mod.d.ts.map +1 -1
  25. package/esm/src/clients/event.d.ts +57 -16
  26. package/esm/src/clients/event.d.ts.map +1 -1
  27. package/esm/src/clients/event.js +72 -16
  28. package/esm/src/clients/public.d.ts +241 -49
  29. package/esm/src/clients/public.d.ts.map +1 -1
  30. package/esm/src/clients/public.js +243 -47
  31. package/esm/src/clients/wallet.d.ts +120 -51
  32. package/esm/src/clients/wallet.d.ts.map +1 -1
  33. package/esm/src/clients/wallet.js +192 -58
  34. package/esm/src/transports/websocket/hyperliquid_event_target.d.ts +27 -21
  35. package/esm/src/transports/websocket/hyperliquid_event_target.d.ts.map +1 -1
  36. package/esm/src/transports/websocket/hyperliquid_event_target.js +37 -0
  37. package/esm/src/transports/websocket/websocket_request_dispatcher.js +3 -3
  38. package/esm/src/transports/websocket/websocket_transport.d.ts +7 -10
  39. package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  40. package/esm/src/transports/websocket/websocket_transport.js +41 -35
  41. package/esm/src/types/exchange/common.d.ts +6 -6
  42. package/esm/src/types/exchange/common.d.ts.map +1 -1
  43. package/esm/src/types/exchange/requests.d.ts +131 -64
  44. package/esm/src/types/exchange/requests.d.ts.map +1 -1
  45. package/esm/src/types/exchange/responses.d.ts +7 -7
  46. package/esm/src/types/exchange/responses.d.ts.map +1 -1
  47. package/esm/src/types/explorer/common.d.ts +15 -15
  48. package/esm/src/types/explorer/common.d.ts.map +1 -1
  49. package/esm/src/types/explorer/requests.d.ts +19 -6
  50. package/esm/src/types/explorer/requests.d.ts.map +1 -1
  51. package/esm/src/types/explorer/responses.d.ts +9 -2
  52. package/esm/src/types/explorer/responses.d.ts.map +1 -1
  53. package/esm/src/types/info/accounts.d.ts +189 -124
  54. package/esm/src/types/info/accounts.d.ts.map +1 -1
  55. package/esm/src/types/info/assets.d.ts +82 -78
  56. package/esm/src/types/info/assets.d.ts.map +1 -1
  57. package/esm/src/types/info/delegations.d.ts +117 -0
  58. package/esm/src/types/info/delegations.d.ts.map +1 -0
  59. package/esm/src/types/info/delegations.js +1 -0
  60. package/esm/src/types/info/orders.d.ts +67 -67
  61. package/esm/src/types/info/orders.d.ts.map +1 -1
  62. package/esm/src/types/info/requests.d.ts +128 -63
  63. package/esm/src/types/info/requests.d.ts.map +1 -1
  64. package/esm/src/types/info/vaults.d.ts +41 -84
  65. package/esm/src/types/info/vaults.d.ts.map +1 -1
  66. package/esm/src/types/subscriptions/common.d.ts +3 -0
  67. package/esm/src/types/subscriptions/common.d.ts.map +1 -1
  68. package/esm/src/types/subscriptions/requests.d.ts +10 -0
  69. package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
  70. package/esm/src/utils/key_sort.d.ts +2 -2
  71. package/esm/src/utils/key_sort.d.ts.map +1 -1
  72. package/esm/src/utils/signing.d.ts +1 -1
  73. package/esm/src/utils/signing.js +2 -2
  74. package/package.json +1 -1
  75. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +13 -3
  76. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +23 -13
  77. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.js +55 -45
  78. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.js +97 -87
  79. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.js +14 -4
  80. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js +288 -278
  81. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/utils.js +238 -228
  82. package/script/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts +9 -0
  83. package/script/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts.map +1 -0
  84. package/script/deps/jsr.io/@std/bytes/1.0.5/_types.js +13 -0
  85. package/script/deps/jsr.io/@std/bytes/{1.0.4 → 1.0.5}/concat.d.ts +3 -1
  86. package/script/deps/jsr.io/@std/bytes/1.0.5/concat.d.ts.map +1 -0
  87. package/script/deps/jsr.io/@std/bytes/1.0.5/concat.js +45 -0
  88. package/script/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts +9 -0
  89. package/script/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts.map +1 -0
  90. package/script/deps/jsr.io/@std/encoding/1.0.7/_types.js +13 -0
  91. package/script/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts.map +1 -1
  92. package/script/deps/jsr.io/@std/encoding/1.0.7/_validate_binary_like.js +39 -0
  93. package/{esm/deps/jsr.io/@std/encoding/1.0.6 → script/deps/jsr.io/@std/encoding/1.0.7}/hex.d.ts +3 -1
  94. package/script/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +1 -0
  95. package/script/deps/jsr.io/@std/encoding/1.0.7/hex.js +123 -0
  96. package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +9 -0
  97. package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +1 -0
  98. package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.js +13 -0
  99. package/script/deps/jsr.io/@std/msgpack/{1.0.2 → 1.0.3}/encode.d.ts +3 -1
  100. package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +1 -0
  101. package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.js +250 -0
  102. package/script/mod.d.ts +1 -0
  103. package/script/mod.d.ts.map +1 -1
  104. package/script/mod.js +23 -13
  105. package/script/src/clients/event.d.ts +57 -16
  106. package/script/src/clients/event.d.ts.map +1 -1
  107. package/script/src/clients/event.js +551 -485
  108. package/script/src/clients/public.d.ts +241 -49
  109. package/script/src/clients/public.d.ts.map +1 -1
  110. package/script/src/clients/public.js +914 -708
  111. package/script/src/clients/wallet.d.ts +120 -51
  112. package/script/src/clients/wallet.d.ts.map +1 -1
  113. package/script/src/clients/wallet.js +1121 -977
  114. package/script/src/transports/base.js +25 -15
  115. package/script/src/transports/http/http_transport.js +174 -164
  116. package/script/src/transports/websocket/hyperliquid_event_target.d.ts +27 -21
  117. package/script/src/transports/websocket/hyperliquid_event_target.d.ts.map +1 -1
  118. package/script/src/transports/websocket/hyperliquid_event_target.js +80 -33
  119. package/script/src/transports/websocket/reconnecting_websocket.js +364 -354
  120. package/script/src/transports/websocket/websocket_request_dispatcher.js +196 -186
  121. package/script/src/transports/websocket/websocket_transport.d.ts +7 -10
  122. package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  123. package/script/src/transports/websocket/websocket_transport.js +236 -220
  124. package/script/src/types/common.js +12 -2
  125. package/script/src/types/exchange/common.d.ts +6 -6
  126. package/script/src/types/exchange/common.d.ts.map +1 -1
  127. package/script/src/types/exchange/common.js +12 -2
  128. package/script/src/types/exchange/requests.d.ts +131 -64
  129. package/script/src/types/exchange/requests.d.ts.map +1 -1
  130. package/script/src/types/exchange/requests.js +12 -2
  131. package/script/src/types/exchange/responses.d.ts +7 -7
  132. package/script/src/types/exchange/responses.d.ts.map +1 -1
  133. package/script/src/types/exchange/responses.js +12 -2
  134. package/script/src/types/explorer/common.d.ts +15 -15
  135. package/script/src/types/explorer/common.d.ts.map +1 -1
  136. package/script/src/types/explorer/common.js +12 -2
  137. package/script/src/types/explorer/requests.d.ts +19 -6
  138. package/script/src/types/explorer/requests.d.ts.map +1 -1
  139. package/script/src/types/explorer/requests.js +12 -2
  140. package/script/src/types/explorer/responses.d.ts +9 -2
  141. package/script/src/types/explorer/responses.d.ts.map +1 -1
  142. package/script/src/types/explorer/responses.js +12 -2
  143. package/script/src/types/info/accounts.d.ts +189 -124
  144. package/script/src/types/info/accounts.d.ts.map +1 -1
  145. package/script/src/types/info/accounts.js +12 -2
  146. package/script/src/types/info/assets.d.ts +82 -78
  147. package/script/src/types/info/assets.d.ts.map +1 -1
  148. package/script/src/types/info/assets.js +12 -2
  149. package/script/src/types/info/delegations.d.ts +117 -0
  150. package/script/src/types/info/delegations.d.ts.map +1 -0
  151. package/script/src/types/info/delegations.js +12 -0
  152. package/script/src/types/info/orders.d.ts +67 -67
  153. package/script/src/types/info/orders.d.ts.map +1 -1
  154. package/script/src/types/info/orders.js +12 -2
  155. package/script/src/types/info/requests.d.ts +128 -63
  156. package/script/src/types/info/requests.d.ts.map +1 -1
  157. package/script/src/types/info/requests.js +12 -2
  158. package/script/src/types/info/vaults.d.ts +41 -84
  159. package/script/src/types/info/vaults.d.ts.map +1 -1
  160. package/script/src/types/info/vaults.js +12 -2
  161. package/script/src/types/subscriptions/common.d.ts +3 -0
  162. package/script/src/types/subscriptions/common.d.ts.map +1 -1
  163. package/script/src/types/subscriptions/common.js +12 -2
  164. package/script/src/types/subscriptions/requests.d.ts +10 -0
  165. package/script/src/types/subscriptions/requests.d.ts.map +1 -1
  166. package/script/src/types/subscriptions/requests.js +12 -2
  167. package/script/src/utils/key_sort.d.ts +2 -2
  168. package/script/src/utils/key_sort.d.ts.map +1 -1
  169. package/script/src/utils/key_sort.js +133 -123
  170. package/script/src/utils/signing.d.ts +1 -1
  171. package/script/src/utils/signing.js +172 -162
  172. package/esm/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +0 -1
  173. package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +0 -1
  174. package/esm/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +0 -1
  175. package/script/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +0 -1
  176. package/script/deps/jsr.io/@std/bytes/1.0.4/concat.js +0 -35
  177. package/script/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.js +0 -29
  178. package/script/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +0 -1
  179. package/script/deps/jsr.io/@std/encoding/1.0.6/hex.js +0 -113
  180. package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +0 -1
  181. package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.js +0 -240
  182. /package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts +0 -0
  183. /package/script/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts +0 -0
@@ -1,6 +1,6 @@
1
1
  import { sorters } from "../utils/key_sort.js";
2
2
  import { signL1Action, signUserSignedAction, } from "../utils/signing.js";
3
- // ———————————————Errors———————————————
3
+ // ——————————————— Errors ———————————————
4
4
  /** Error thrown when the API returns an error response. */
5
5
  export class ApiRequestError extends Error {
6
6
  constructor(response) {
@@ -37,7 +37,7 @@ export class ApiRequestError extends Error {
37
37
  this.name = "ApiRequestError";
38
38
  }
39
39
  }
40
- // ———————————————Client———————————————
40
+ // ——————————————— Client ———————————————
41
41
  /**
42
42
  * Wallet client for interacting with the Hyperliquid API.
43
43
  * @typeParam T - The transport used to connect to the Hyperliquid API.
@@ -74,10 +74,9 @@ export class WalletClient {
74
74
  * ```ts
75
75
  * import * as hl from "@nktkas/hyperliquid";
76
76
  * import { createWalletClient, custom } from "viem";
77
- * import { arbitrum } from "viem/chains";
78
77
  *
79
78
  * const [account] = await window.ethereum.request({ method: "eth_requestAccounts" });
80
- * const wallet = createWalletClient({ account, chain: arbitrum, transport: custom(window.ethereum) });
79
+ * const wallet = createWalletClient({ account, transport: custom(window.ethereum) });
81
80
  *
82
81
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
83
82
  * const client = new hl.WalletClient({ wallet, transport });
@@ -122,10 +121,10 @@ export class WalletClient {
122
121
  * Approve an agent to sign on behalf of the master or sub-accounts.
123
122
  * @param args - The parameters for the request.
124
123
  * @param signal - An optional abort signal
125
- * @returns {SuccessResponse} Successful response without specific data.
124
+ * @returns Successful response without specific data.
126
125
  * @throws {ApiRequestError} When the API returns an error response.
127
126
  *
128
- * @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#approve-an-api-wallet | Hyperliquid GitBook}
127
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#approve-an-api-wallet
129
128
  * @example
130
129
  * ```ts
131
130
  * import * as hl from "@nktkas/hyperliquid";
@@ -145,7 +144,7 @@ export class WalletClient {
145
144
  ...args,
146
145
  type: "approveAgent",
147
146
  hyperliquidChain: this.isTestnet ? "Testnet" : "Mainnet",
148
- signatureChainId: args.signatureChainId ?? this.isTestnet ? "0x66eee" : "0xa4b1",
147
+ signatureChainId: args.signatureChainId ?? (this.isTestnet ? "0x66eee" : "0xa4b1"),
149
148
  nonce: args.nonce ?? Date.now(),
150
149
  };
151
150
  const signature = await signUserSignedAction(this.wallet, action, {
@@ -169,10 +168,10 @@ export class WalletClient {
169
168
  * Approve a max fee rate for a builder address.
170
169
  * @param args - The parameters for the request.
171
170
  * @param signal - An optional abort signal.
172
- * @returns {SuccessResponse} Successful response without specific data.
171
+ * @returns Successful response without specific data.
173
172
  * @throws {ApiRequestError} When the API returns an error response.
174
173
  *
175
- * @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#approve-a-builder-fee | Hyperliquid GitBook}
174
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#approve-a-builder-fee
176
175
  * @example
177
176
  * ```ts
178
177
  * import * as hl from "@nktkas/hyperliquid";
@@ -192,7 +191,7 @@ export class WalletClient {
192
191
  ...args,
193
192
  type: "approveBuilderFee",
194
193
  hyperliquidChain: this.isTestnet ? "Testnet" : "Mainnet",
195
- signatureChainId: args.signatureChainId ?? this.isTestnet ? "0x66eee" : "0xa4b1",
194
+ signatureChainId: args.signatureChainId ?? (this.isTestnet ? "0x66eee" : "0xa4b1"),
196
195
  nonce: args.nonce ?? Date.now(),
197
196
  };
198
197
  const signature = await signUserSignedAction(this.wallet, action, {
@@ -216,10 +215,10 @@ export class WalletClient {
216
215
  * Modify multiple orders.
217
216
  * @param args - The parameters for the request.
218
217
  * @param signal - An optional abort signal.
219
- * @returns {OrderResponseSuccess} Successful variant of {@link OrderResponse} without error statuses.
218
+ * @returns Successful variant of {@link OrderResponse} without error statuses.
220
219
  * @throws {ApiRequestError} When the API returns an error response.
221
220
  *
222
- * @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders | Hyperliquid GitBook}
221
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders
223
222
  * @example
224
223
  * ```ts
225
224
  * import * as hl from "@nktkas/hyperliquid";
@@ -267,10 +266,10 @@ export class WalletClient {
267
266
  * Cancel order(s).
268
267
  * @param args - The parameters for the request.
269
268
  * @param signal - An optional abort signal.
270
- * @returns {CancelResponseSuccess} Successful variant of {@link CancelResponse} without error statuses.
269
+ * @returns Successful variant of {@link CancelResponse} without error statuses.
271
270
  * @throws {ApiRequestError} When the API returns an error response.
272
271
  *
273
- * @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s | Hyperliquid GitBook}
272
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s
274
273
  * @example
275
274
  * ```ts
276
275
  * import * as hl from "@nktkas/hyperliquid";
@@ -303,13 +302,57 @@ export class WalletClient {
303
302
  return response;
304
303
  }
305
304
  /**
306
- * Cancel order(s) by Client Order ID.
305
+ * Deposit into staking balance.
307
306
  * @param args - The parameters for the request.
308
307
  * @param signal - An optional abort signal.
309
- * @returns {CancelResponseSuccess} Successful variant of {@link CancelResponse} without error statuses.
308
+ * @returns Successful response without specific data.
310
309
  * @throws {ApiRequestError} When the API returns an error response.
311
310
  *
312
- * @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s-by-cloid | Hyperliquid GitBook}
311
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#deposit-into-staking
312
+ * @example
313
+ * ```ts
314
+ * import * as hl from "@nktkas/hyperliquid";
315
+ * import { privateKeyToAccount } from "viem/accounts";
316
+ *
317
+ * const wallet = privateKeyToAccount("0x...");
318
+ * const transport = new hl.HttpTransport(); // or WebSocketTransport
319
+ * const client = new hl.WalletClient({ wallet, transport });
320
+ *
321
+ * const result = await client.cDeposit({ wei: 100000000 });
322
+ * ```
323
+ */
324
+ async cDeposit(args, signal) {
325
+ const action = {
326
+ ...args,
327
+ type: "cDeposit",
328
+ hyperliquidChain: this.isTestnet ? "Testnet" : "Mainnet",
329
+ signatureChainId: args.signatureChainId ?? (this.isTestnet ? "0x66eee" : "0xa4b1"),
330
+ nonce: args.nonce ?? Date.now(),
331
+ };
332
+ const signature = await signUserSignedAction(this.wallet, action, {
333
+ "HyperliquidTransaction:CDeposit": [
334
+ { name: "hyperliquidChain", type: "string" },
335
+ { name: "wei", type: "uint64" },
336
+ { name: "nonce", type: "uint64" },
337
+ ],
338
+ }, parseInt(action.signatureChainId, 16));
339
+ const request = {
340
+ action,
341
+ signature,
342
+ nonce: action.nonce,
343
+ };
344
+ const response = await this.transport.request("action", request, signal);
345
+ this._validateResponse(response);
346
+ return response;
347
+ }
348
+ /**
349
+ * Cancel order(s) by cloid.
350
+ * @param args - The parameters for the request.
351
+ * @param signal - An optional abort signal.
352
+ * @returns Successful variant of {@link CancelResponse} without error statuses.
353
+ * @throws {ApiRequestError} When the API returns an error response.
354
+ *
355
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s-by-cloid
313
356
  * @example
314
357
  * ```ts
315
358
  * import * as hl from "@nktkas/hyperliquid";
@@ -341,13 +384,58 @@ export class WalletClient {
341
384
  this._validateResponse(response);
342
385
  return response;
343
386
  }
387
+ /**
388
+ * Withdraw from staking balance.
389
+ * @param args - The parameters for the request.
390
+ * @param signal - An optional abort signal.
391
+ * @returns Successful response without specific data.
392
+ * @throws {ApiRequestError} When the API returns an error response.
393
+ *
394
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#withdraw-from-staking
395
+ * @example
396
+ * ```ts
397
+ * import * as hl from "@nktkas/hyperliquid";
398
+ * import { privateKeyToAccount } from "viem/accounts";
399
+ *
400
+ * const wallet = privateKeyToAccount("0x...");
401
+ * const transport = new hl.HttpTransport(); // or WebSocketTransport
402
+ * const client = new hl.WalletClient({ wallet, transport });
403
+ *
404
+ * const result = await client.cWithdraw({ wei: 100000000 });
405
+ * ```
406
+ */
407
+ async cWithdraw(args, signal) {
408
+ const action = {
409
+ ...args,
410
+ type: "cWithdraw",
411
+ hyperliquidChain: this.isTestnet ? "Testnet" : "Mainnet",
412
+ signatureChainId: args.signatureChainId ?? (this.isTestnet ? "0x66eee" : "0xa4b1"),
413
+ nonce: args.nonce ?? Date.now(),
414
+ };
415
+ const signature = await signUserSignedAction(this.wallet, action, {
416
+ "HyperliquidTransaction:CWithdraw": [
417
+ { name: "hyperliquidChain", type: "string" },
418
+ { name: "wei", type: "uint64" },
419
+ { name: "nonce", type: "uint64" },
420
+ ],
421
+ }, parseInt(action.signatureChainId, 16));
422
+ const request = {
423
+ action,
424
+ signature,
425
+ nonce: action.nonce,
426
+ };
427
+ const response = await this.transport.request("action", request, signal);
428
+ this._validateResponse(response);
429
+ return response;
430
+ }
344
431
  /**
345
432
  * Create a sub-account.
346
433
  * @param args - The parameters for the request.
347
434
  * @param signal - An optional abort signal.
348
- * @returns {CreateSubAccountResponse} Response for creating a sub-account.
435
+ * @returns Response for creating a sub-account.
349
436
  * @throws {ApiRequestError} When the API returns an error response.
350
437
  *
438
+ * @see null - no documentation
351
439
  * @example
352
440
  * ```ts
353
441
  * import * as hl from "@nktkas/hyperliquid";
@@ -357,9 +445,7 @@ export class WalletClient {
357
445
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
358
446
  * const client = new hl.WalletClient({ wallet, transport });
359
447
  *
360
- * const result = await client.createSubAccount({
361
- * name: "subAccountName",
362
- * });
448
+ * const result = await client.createSubAccount({ name: "subAccountName" });
363
449
  * ```
364
450
  */
365
451
  async createSubAccount(args, signal) {
@@ -379,10 +465,10 @@ export class WalletClient {
379
465
  * Modify an order.
380
466
  * @param args - The parameters for the request.
381
467
  * @param signal - An optional abort signal.
382
- * @returns {SuccessResponse} Successful response without specific data.
468
+ * @returns Successful response without specific data.
383
469
  * @throws {ApiRequestError} When the API returns an error response.
384
470
  *
385
- * @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-an-order | Hyperliquid GitBook}
471
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-an-order
386
472
  * @example
387
473
  * ```ts
388
474
  * import * as hl from "@nktkas/hyperliquid";
@@ -428,10 +514,10 @@ export class WalletClient {
428
514
  * Place an order(s).
429
515
  * @param args - The parameters for the request.
430
516
  * @param signal - An optional abort signal.
431
- * @returns {OrderResponseSuccess} Successful variant of {@link OrderResponse} without error statuses.
517
+ * @returns Successful variant of {@link OrderResponse} without error statuses.
432
518
  * @throws {ApiRequestError} When the API returns an error response.
433
519
  *
434
- * @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-an-order | Hyperliquid GitBook}
520
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-an-order
435
521
  * @example
436
522
  * ```ts
437
523
  * import * as hl from "@nktkas/hyperliquid";
@@ -480,10 +566,10 @@ export class WalletClient {
480
566
  * Schedule a time to cancel all open orders.
481
567
  * @param args - The parameters for the request.
482
568
  * @param signal - An optional abort signal.
483
- * @returns {SuccessResponse} Successful response without specific data.
569
+ * @returns Successful response without specific data.
484
570
  * @throws {ApiRequestError} When the API returns an error response.
485
571
  *
486
- * @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#schedule-cancel-dead-mans-switch | Hyperliquid GitBook}
572
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#schedule-cancel-dead-mans-switch
487
573
  * @example
488
574
  * ```ts
489
575
  * import * as hl from "@nktkas/hyperliquid";
@@ -493,9 +579,7 @@ export class WalletClient {
493
579
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
494
580
  * const client = new hl.WalletClient({ wallet, transport });
495
581
  *
496
- * const result = await client.scheduleCancel({
497
- * time: Date.now() + 3600000, // Schedule cancellation 1 hour from now
498
- * });
582
+ * const result = await client.scheduleCancel({ time: Date.now() + 3600000 });
499
583
  * ```
500
584
  */
501
585
  async scheduleCancel(args = {}, signal) {
@@ -516,9 +600,10 @@ export class WalletClient {
516
600
  * Set a referral code.
517
601
  * @param args - The parameters for the request.
518
602
  * @param signal - An optional abort signal.
519
- * @returns {SuccessResponse} Successful response without specific data.
603
+ * @returns Successful response without specific data.
520
604
  * @throws {ApiRequestError} When the API returns an error response.
521
605
  *
606
+ * @see null - no documentation
522
607
  * @example
523
608
  * ```ts
524
609
  * import * as hl from "@nktkas/hyperliquid";
@@ -528,9 +613,7 @@ export class WalletClient {
528
613
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
529
614
  * const client = new hl.WalletClient({ wallet, transport });
530
615
  *
531
- * const result = await client.setReferrer({
532
- * code: "TEST",
533
- * });
616
+ * const result = await client.setReferrer({ code: "TEST" });
534
617
  * ```
535
618
  */
536
619
  async setReferrer(args, signal) {
@@ -550,10 +633,10 @@ export class WalletClient {
550
633
  * Transfer a spot asset on L1 to another address.
551
634
  * @param args - The parameters for the request.
552
635
  * @param signal - An optional abort signal.
553
- * @returns {SuccessResponse} Successful response without specific data.
636
+ * @returns Successful response without specific data.
554
637
  * @throws {ApiRequestError} When the API returns an error response.
555
638
  *
556
- * @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#l1-spot-transfer | Hyperliquid GitBook}
639
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#l1-spot-transfer
557
640
  * @example
558
641
  * ```ts
559
642
  * import * as hl from "@nktkas/hyperliquid";
@@ -575,7 +658,7 @@ export class WalletClient {
575
658
  ...args,
576
659
  type: "spotSend",
577
660
  hyperliquidChain: this.isTestnet ? "Testnet" : "Mainnet",
578
- signatureChainId: args.signatureChainId ?? this.isTestnet ? "0x66eee" : "0xa4b1",
661
+ signatureChainId: args.signatureChainId ?? (this.isTestnet ? "0x66eee" : "0xa4b1"),
579
662
  time: args.time ?? Date.now(),
580
663
  };
581
664
  const signature = await signUserSignedAction(this.wallet, action, {
@@ -600,9 +683,10 @@ export class WalletClient {
600
683
  * Transfer between sub-accounts.
601
684
  * @param args - The parameters for the request.
602
685
  * @param signal - An optional abort signal.
603
- * @returns {SuccessResponse} Successful response without specific data.
686
+ * @returns Successful response without specific data.
604
687
  * @throws {ApiRequestError} When the API returns an error response.
605
688
  *
689
+ * @see null - no documentation
606
690
  * @example
607
691
  * ```ts
608
692
  * import * as hl from "@nktkas/hyperliquid";
@@ -632,14 +716,64 @@ export class WalletClient {
632
716
  this._validateResponse(response);
633
717
  return response;
634
718
  }
719
+ /**
720
+ * Delegate or undelegate stake from a validator.
721
+ * @param args - The parameters for the request.
722
+ * @param signal - An optional abort signal.
723
+ * @returns Successful response without specific data.
724
+ * @throws {ApiRequestError} When the API returns an error response.
725
+ *
726
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#delegate-or-undelegate-stake-from-validator
727
+ * @example
728
+ * ```ts
729
+ * import * as hl from "@nktkas/hyperliquid";
730
+ * import { privateKeyToAccount } from "viem/accounts";
731
+ *
732
+ * const wallet = privateKeyToAccount("0x...");
733
+ * const transport = new hl.HttpTransport(); // or WebSocketTransport
734
+ * const client = new hl.WalletClient({ wallet, transport });
735
+ *
736
+ * const result = await client.tokenDelegate({
737
+ * validator: "0x...",
738
+ * isUndelegate: true,
739
+ * wei: 100000000,
740
+ * });
741
+ * ```
742
+ */
743
+ async tokenDelegate(args, signal) {
744
+ const action = {
745
+ ...args,
746
+ type: "tokenDelegate",
747
+ hyperliquidChain: this.isTestnet ? "Testnet" : "Mainnet",
748
+ signatureChainId: args.signatureChainId ?? (this.isTestnet ? "0x66eee" : "0xa4b1"),
749
+ nonce: args.nonce ?? Date.now(),
750
+ };
751
+ const signature = await signUserSignedAction(this.wallet, action, {
752
+ "HyperliquidTransaction:TokenDelegate": [
753
+ { name: "hyperliquidChain", type: "string" },
754
+ { name: "validator", type: "address" },
755
+ { name: "wei", type: "uint64" },
756
+ { name: "isUndelegate", type: "bool" },
757
+ { name: "nonce", type: "uint64" },
758
+ ],
759
+ }, parseInt(action.signatureChainId, 16));
760
+ const request = {
761
+ action,
762
+ signature,
763
+ nonce: action.nonce,
764
+ };
765
+ const response = await this.transport.request("action", request, signal);
766
+ this._validateResponse(response);
767
+ return response;
768
+ }
635
769
  /**
636
770
  * Cancel a TWAP order.
637
771
  * @param args - The parameters for the request.
638
772
  * @param signal - An optional abort signal.
639
- * @returns {TwapCancelResponseSuccess} Successful variant of {@link TwapCancelResponse} without error status.
773
+ * @returns Successful variant of {@link TwapCancelResponse} without error status.
640
774
  * @throws {ApiRequestError} When the API returns an error response.
641
775
  *
642
- * @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-a-twap-order | Hyperliquid GitBook}
776
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-a-twap-order
643
777
  * @example
644
778
  * ```ts
645
779
  * import * as hl from "@nktkas/hyperliquid";
@@ -673,10 +807,10 @@ export class WalletClient {
673
807
  * Place a TWAP order.
674
808
  * @param args - The parameters for the request.
675
809
  * @param signal - An optional abort signal.
676
- * @returns {TwapOrderResponseSuccess} Successful variant of {@link TwapOrderResponse} without error status.
810
+ * @returns Successful variant of {@link TwapOrderResponse} without error status.
677
811
  * @throws {ApiRequestError} When the API returns an error response.
678
812
  *
679
- * @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-a-twap-order | Hyperliquid GitBook}
813
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-a-twap-order
680
814
  * @example
681
815
  * ```ts
682
816
  * import * as hl from "@nktkas/hyperliquid";
@@ -714,10 +848,10 @@ export class WalletClient {
714
848
  * Update isolated margin for a position.
715
849
  * @param args - The parameters for the request.
716
850
  * @param signal - An optional abort signal.
717
- * @returns {SuccessResponse} Successful response without specific data.
851
+ * @returns Successful response without specific data.
718
852
  * @throws {ApiRequestError} When the API returns an error response.
719
853
  *
720
- * @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#update-isolated-margin | Hyperliquid GitBook}
854
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#update-isolated-margin
721
855
  * @example
722
856
  * ```ts
723
857
  * import * as hl from "@nktkas/hyperliquid";
@@ -752,10 +886,10 @@ export class WalletClient {
752
886
  * Update leverage for cross or isolated margin.
753
887
  * @param args - The parameters for the request.
754
888
  * @param signal - An optional abort signal.
755
- * @returns {SuccessResponse} Successful response without specific data.
889
+ * @returns Successful response without specific data.
756
890
  * @throws {ApiRequestError} When the API returns an error response.
757
891
  *
758
- * @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#update-leverage | Hyperliquid GitBook}
892
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#update-leverage
759
893
  * @example
760
894
  * ```ts
761
895
  * import * as hl from "@nktkas/hyperliquid";
@@ -790,10 +924,10 @@ export class WalletClient {
790
924
  * Transfer funds between Spot and Perp accounts.
791
925
  * @param args - The parameters for the request.
792
926
  * @param signal - An optional abort signal.
793
- * @returns {SuccessResponse} Successful response without specific data.
927
+ * @returns Successful response without specific data.
794
928
  * @throws {ApiRequestError} When the API returns an error response.
795
929
  *
796
- * @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#transfer-from-spot-account-to-perp-account-and-vice-versa | Hyperliquid GitBook}
930
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#transfer-from-spot-account-to-perp-account-and-vice-versa
797
931
  * @example
798
932
  * ```ts
799
933
  * import * as hl from "@nktkas/hyperliquid";
@@ -814,7 +948,7 @@ export class WalletClient {
814
948
  ...args,
815
949
  type: "usdClassTransfer",
816
950
  hyperliquidChain: this.isTestnet ? "Testnet" : "Mainnet",
817
- signatureChainId: args.signatureChainId ?? this.isTestnet ? "0x66eee" : "0xa4b1",
951
+ signatureChainId: args.signatureChainId ?? (this.isTestnet ? "0x66eee" : "0xa4b1"),
818
952
  nonce: args.nonce ?? Date.now(),
819
953
  };
820
954
  const signature = await signUserSignedAction(this.wallet, action, {
@@ -838,10 +972,10 @@ export class WalletClient {
838
972
  * Transfer USDC on L1 to another address.
839
973
  * @param args - The parameters for the request.
840
974
  * @param signal - An optional abort signal.
841
- * @returns {SuccessResponse} Successful response without specific data.
975
+ * @returns Successful response without specific data.
842
976
  * @throws {ApiRequestError} When the API returns an error response.
843
977
  *
844
- * @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#l1-usdc-transfer | Hyperliquid GitBook}
978
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#l1-usdc-transfer
845
979
  * @example
846
980
  * ```ts
847
981
  * import * as hl from "@nktkas/hyperliquid";
@@ -862,7 +996,7 @@ export class WalletClient {
862
996
  ...args,
863
997
  type: "usdSend",
864
998
  hyperliquidChain: this.isTestnet ? "Testnet" : "Mainnet",
865
- signatureChainId: args.signatureChainId ?? this.isTestnet ? "0x66eee" : "0xa4b1",
999
+ signatureChainId: args.signatureChainId ?? (this.isTestnet ? "0x66eee" : "0xa4b1"),
866
1000
  time: args.time ?? Date.now(),
867
1001
  };
868
1002
  const signature = await signUserSignedAction(this.wallet, action, {
@@ -883,13 +1017,13 @@ export class WalletClient {
883
1017
  return response;
884
1018
  }
885
1019
  /**
886
- * Transfer funds to/from a vault.
1020
+ * Add or remove funds from a vault.
887
1021
  * @param args - The parameters for the request.
888
1022
  * @param signal - An optional abort signal.
889
- * @returns {SuccessResponse} Successful response without specific data.
1023
+ * @returns Successful response without specific data.
890
1024
  * @throws {ApiRequestError} When the API returns an error response.
891
1025
  *
892
- * @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#deposit-or-withdraw-from-a-vault | Hyperliquid GitBook}
1026
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#deposit-or-withdraw-from-a-vault
893
1027
  * @example
894
1028
  * ```ts
895
1029
  * import * as hl from "@nktkas/hyperliquid";
@@ -923,10 +1057,10 @@ export class WalletClient {
923
1057
  * Initiate a withdrawal request.
924
1058
  * @param args - The parameters for the request.
925
1059
  * @param signal - An optional abort signal.
926
- * @returns {SuccessResponse} Successful response without specific data.
1060
+ * @returns Successful response without specific data.
927
1061
  * @throws {ApiRequestError} When the API returns an error response.
928
1062
  *
929
- * @see {@link https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#initiate-a-withdrawal-request | Hyperliquid GitBook}
1063
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#initiate-a-withdrawal-request
930
1064
  * @example
931
1065
  * ```ts
932
1066
  * import * as hl from "@nktkas/hyperliquid";
@@ -947,7 +1081,7 @@ export class WalletClient {
947
1081
  ...args,
948
1082
  type: "withdraw3",
949
1083
  hyperliquidChain: this.isTestnet ? "Testnet" : "Mainnet",
950
- signatureChainId: args.signatureChainId ?? this.isTestnet ? "0x66eee" : "0xa4b1",
1084
+ signatureChainId: args.signatureChainId ?? (this.isTestnet ? "0x66eee" : "0xa4b1"),
951
1085
  time: args.time ?? Date.now(),
952
1086
  };
953
1087
  const signature = await signUserSignedAction(this.wallet, action, {
@@ -1,56 +1,62 @@
1
1
  import { TypedEventTarget } from "../../../deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js";
2
+ import type { TxDetails } from "../../types/explorer/common.js";
3
+ import type { WsBlockDetails } from "../../types/subscriptions/common.js";
2
4
  /**
3
5
  * Base system events and dynamic channel events for Hyperliquid WebSocket API.
4
6
  */
5
7
  export interface HyperliquidEventMap {
6
- /** Subscription created/removed event */
8
+ /** Subscription created/removed event. */
7
9
  subscriptionResponse: CustomEvent<{
8
- /** Type of subscription operation */
10
+ /** Type of subscription operation. */
9
11
  method: "subscribe" | "unsubscribe";
10
- /** Original subscription request */
12
+ /** Original subscription request. */
11
13
  subscription: unknown;
12
14
  }>;
13
- /** Response to post request event */
15
+ /** Response to post request event. */
14
16
  post: CustomEvent<{
15
- /** Unique request identifier */
17
+ /** Unique request identifier. */
16
18
  id: number;
17
- /** Server response */
19
+ /** Server response. */
18
20
  response:
19
- /** Response containing requested information */
21
+ /** Response containing requested information. */
20
22
  {
21
- /** Indicates that this is an informational response */
23
+ /** Indicates that this is an informational response. */
22
24
  type: "info";
23
- /** Contains the information data */
25
+ /** Contains the information data. */
24
26
  payload: {
25
- /** Type of information being returned */
27
+ /** Type of information being returned. */
26
28
  type: string;
27
- /** Information specific data */
29
+ /** Information specific data. */
28
30
  data: unknown;
29
31
  };
30
32
  }
31
- /** Response containing action result */
33
+ /** Response containing action result. */
32
34
  | {
33
- /** Indicates that this is an action response */
35
+ /** Indicates that this is an action response. */
34
36
  type: "action";
35
- /** Contains the action result data */
37
+ /** Contains the action result data. */
36
38
  payload: {
37
- /** Response status indicating success or failure of the action */
39
+ /** Response status indicating success or failure of the action. */
38
40
  status: "ok" | "err";
39
- /** Success data or error message */
41
+ /** Success data or error message. */
40
42
  response: {
41
- /** Type of operation */
43
+ /** Type of operation. */
42
44
  type: string;
43
- /** Specific data for the operation */
45
+ /** Specific data for the operation. */
44
46
  data?: unknown;
45
47
  } | string;
46
48
  };
47
49
  };
48
50
  }>;
49
- /** Error response for message event */
51
+ /** Error response for message event. */
50
52
  error: CustomEvent<string>;
51
- /** Pong response event */
53
+ /** Pong response event. */
52
54
  pong: CustomEvent<undefined>;
53
- /** Subscribed channel events */
55
+ /** Block explorer update event. */
56
+ _explorerBlock: CustomEvent<WsBlockDetails[]>;
57
+ /** Transaction explorer update event. */
58
+ _explorerTxs: CustomEvent<TxDetails[]>;
59
+ /** Subscribed channel event. */
54
60
  [key: string]: CustomEvent<unknown>;
55
61
  }
56
62
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"hyperliquid_event_target.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/hyperliquid_event_target.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oEAAoE,CAAC;AAYtG;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,yCAAyC;IACzC,oBAAoB,EAAE,WAAW,CAAC;QAC9B,qCAAqC;QACrC,MAAM,EAAE,WAAW,GAAG,aAAa,CAAC;QACpC,oCAAoC;QACpC,YAAY,EAAE,OAAO,CAAC;KACzB,CAAC,CAAC;IAEH,qCAAqC;IACrC,IAAI,EAAE,WAAW,CAAC;QACd,gCAAgC;QAChC,EAAE,EAAE,MAAM,CAAC;QACX,sBAAsB;QACtB,QAAQ;QACJ,gDAAgD;QAC9C;YACE,uDAAuD;YACvD,IAAI,EAAE,MAAM,CAAC;YACb,oCAAoC;YACpC,OAAO,EAAE;gBACL,yCAAyC;gBACzC,IAAI,EAAE,MAAM,CAAC;gBACb,gCAAgC;gBAChC,IAAI,EAAE,OAAO,CAAC;aACjB,CAAC;SACL;QACD,wCAAwC;WACtC;YACE,gDAAgD;YAChD,IAAI,EAAE,QAAQ,CAAC;YACf,sCAAsC;YACtC,OAAO,EAAE;gBACL,kEAAkE;gBAClE,MAAM,EAAE,IAAI,GAAG,KAAK,CAAC;gBACrB,oCAAoC;gBACpC,QAAQ,EACF;oBACE,wBAAwB;oBACxB,IAAI,EAAE,MAAM,CAAC;oBACb,sCAAsC;oBACtC,IAAI,CAAC,EAAE,OAAO,CAAC;iBAClB,GACC,MAAM,CAAC;aAChB,CAAC;SACL,CAAC;KACT,CAAC,CAAC;IAEH,uCAAuC;IACvC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAE3B,0BAA0B;IAC1B,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAE7B,gCAAgC;IAChC,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;CACvC;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,gBAAgB,CAAC,mBAAmB,CAAC;IAC7E;;;OAGG;gBACS,MAAM,EAAE,SAAS;CAahC"}
1
+ {"version":3,"file":"hyperliquid_event_target.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/hyperliquid_event_target.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oEAAoE,CAAC;AACtG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAY1E;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,0CAA0C;IAC1C,oBAAoB,EAAE,WAAW,CAAC;QAC9B,sCAAsC;QACtC,MAAM,EAAE,WAAW,GAAG,aAAa,CAAC;QACpC,qCAAqC;QACrC,YAAY,EAAE,OAAO,CAAC;KACzB,CAAC,CAAC;IAEH,sCAAsC;IACtC,IAAI,EAAE,WAAW,CAAC;QACd,iCAAiC;QACjC,EAAE,EAAE,MAAM,CAAC;QACX,uBAAuB;QACvB,QAAQ;QACJ,iDAAiD;QAC/C;YACE,wDAAwD;YACxD,IAAI,EAAE,MAAM,CAAC;YACb,qCAAqC;YACrC,OAAO,EAAE;gBACL,0CAA0C;gBAC1C,IAAI,EAAE,MAAM,CAAC;gBACb,iCAAiC;gBACjC,IAAI,EAAE,OAAO,CAAC;aACjB,CAAC;SACL;QACD,yCAAyC;WACvC;YACE,iDAAiD;YACjD,IAAI,EAAE,QAAQ,CAAC;YACf,uCAAuC;YACvC,OAAO,EAAE;gBACL,mEAAmE;gBACnE,MAAM,EAAE,IAAI,GAAG,KAAK,CAAC;gBACrB,qCAAqC;gBACrC,QAAQ,EACF;oBACE,yBAAyB;oBACzB,IAAI,EAAE,MAAM,CAAC;oBACb,uCAAuC;oBACvC,IAAI,CAAC,EAAE,OAAO,CAAC;iBAClB,GACC,MAAM,CAAC;aAChB,CAAC;SACL,CAAC;KACT,CAAC,CAAC;IAEH,wCAAwC;IACxC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAE3B,2BAA2B;IAC3B,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAE7B,mCAAmC;IACnC,cAAc,EAAE,WAAW,CAAC,cAAc,EAAE,CAAC,CAAC;IAE9C,yCAAyC;IACzC,YAAY,EAAE,WAAW,CAAC,SAAS,EAAE,CAAC,CAAC;IAEvC,gCAAgC;IAChC,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;CACvC;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,gBAAgB,CAAC,mBAAmB,CAAC;IAC7E;;;OAGG;gBACS,MAAM,EAAE,SAAS;CAiBhC"}
@@ -15,6 +15,12 @@ export class HyperliquidEventTarget extends TypedEventTarget {
15
15
  if (isHyperliquidMsg(msg)) {
16
16
  this.dispatchEvent(new CustomEvent(msg.channel, { detail: msg.data }));
17
17
  }
18
+ else if (isExplorerBlockMsg(msg)) {
19
+ this.dispatchEvent(new CustomEvent("_explorerBlock", { detail: msg }));
20
+ }
21
+ else if (isExplorerTxsMsg(msg)) {
22
+ this.dispatchEvent(new CustomEvent("_explorerTxs", { detail: msg }));
23
+ }
18
24
  }
19
25
  catch {
20
26
  // Ignore JSON parsing errors
@@ -31,3 +37,34 @@ function isHyperliquidMsg(value) {
31
37
  return typeof value === "object" && value !== null &&
32
38
  "channel" in value && typeof value.channel === "string";
33
39
  }
40
+ /**
41
+ * Type guard for explorer block messages.
42
+ * @param value - The value to check.
43
+ * @returns True if the value is an array of block details.
44
+ */
45
+ function isExplorerBlockMsg(value) {
46
+ return Array.isArray(value) && value.length > 0 &&
47
+ value.every((block) => typeof block === "object" && block !== null && !Array.isArray(block) &&
48
+ "height" in block && typeof block.height === "number" &&
49
+ "blockTime" in block && typeof block.blockTime === "number" &&
50
+ "hash" in block && typeof block.hash === "string" &&
51
+ "proposer" in block && typeof block.proposer === "string" &&
52
+ "numTxs" in block && typeof block.numTxs === "number");
53
+ }
54
+ /**
55
+ * Type guard for explorer transactions messages.
56
+ * @param value - The value to check.
57
+ * @returns True if the value is an array of transaction details.
58
+ */
59
+ function isExplorerTxsMsg(value) {
60
+ return Array.isArray(value) && value.length > 0 &&
61
+ value.every((tx) => {
62
+ return typeof tx === "object" && tx !== null && !Array.isArray(tx) &&
63
+ "action" in tx && typeof tx.action === "object" && tx.action !== null &&
64
+ "block" in tx && typeof tx.block === "number" &&
65
+ "error" in tx && (typeof tx.error === "string" || tx.error === null) &&
66
+ "hash" in tx && typeof tx.hash === "string" &&
67
+ "time" in tx && typeof tx.time === "number" &&
68
+ "user" in tx && typeof tx.user === "string";
69
+ });
70
+ }