@nktkas/hyperliquid 0.13.0 → 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 (206) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +42 -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 +15 -14
  24. package/esm/mod.d.ts.map +1 -1
  25. package/esm/src/clients/event.d.ts +64 -21
  26. package/esm/src/clients/event.d.ts.map +1 -1
  27. package/esm/src/clients/event.js +76 -18
  28. package/esm/src/clients/public.d.ts +244 -52
  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 +122 -53
  32. package/esm/src/clients/wallet.d.ts.map +1 -1
  33. package/esm/src/clients/wallet.js +201 -65
  34. package/esm/src/transports/http/http_transport.d.ts.map +1 -1
  35. package/esm/src/transports/http/http_transport.js +4 -1
  36. package/esm/src/transports/websocket/hyperliquid_event_target.d.ts +27 -21
  37. package/esm/src/transports/websocket/hyperliquid_event_target.d.ts.map +1 -1
  38. package/esm/src/transports/websocket/hyperliquid_event_target.js +37 -0
  39. package/esm/src/transports/websocket/websocket_request_dispatcher.d.ts.map +1 -1
  40. package/esm/src/transports/websocket/websocket_request_dispatcher.js +4 -4
  41. package/esm/src/transports/websocket/websocket_transport.d.ts +7 -10
  42. package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  43. package/esm/src/transports/websocket/websocket_transport.js +41 -35
  44. package/esm/src/types/common.d.ts +3 -0
  45. package/esm/src/types/common.d.ts.map +1 -0
  46. package/esm/src/types/common.js +1 -0
  47. package/esm/src/types/exchange/common.d.ts +36 -0
  48. package/esm/src/types/exchange/common.d.ts.map +1 -0
  49. package/esm/src/types/exchange/common.js +1 -0
  50. package/esm/src/types/exchange/requests.d.ts +502 -0
  51. package/esm/src/types/exchange/requests.d.ts.map +1 -0
  52. package/esm/src/types/exchange/requests.js +1 -0
  53. package/esm/src/types/exchange/responses.d.ts +141 -0
  54. package/esm/src/types/exchange/responses.d.ts.map +1 -0
  55. package/esm/src/types/exchange/responses.js +1 -0
  56. package/esm/src/types/explorer/common.d.ts +37 -0
  57. package/esm/src/types/explorer/common.d.ts.map +1 -0
  58. package/esm/src/types/explorer/common.js +1 -0
  59. package/esm/src/types/explorer/requests.d.ts +35 -0
  60. package/esm/src/types/explorer/requests.d.ts.map +1 -0
  61. package/esm/src/types/explorer/requests.js +1 -0
  62. package/esm/src/types/explorer/responses.d.ts +23 -0
  63. package/esm/src/types/explorer/responses.d.ts.map +1 -0
  64. package/esm/src/types/explorer/responses.js +1 -0
  65. package/esm/src/types/info/accounts.d.ts +489 -0
  66. package/esm/src/types/info/accounts.d.ts.map +1 -0
  67. package/esm/src/types/info/accounts.js +1 -0
  68. package/esm/src/types/info/assets.d.ts +275 -0
  69. package/esm/src/types/info/assets.d.ts.map +1 -0
  70. package/esm/src/types/info/assets.js +1 -0
  71. package/esm/src/types/info/delegations.d.ts +117 -0
  72. package/esm/src/types/info/delegations.d.ts.map +1 -0
  73. package/esm/src/types/info/delegations.js +1 -0
  74. package/esm/src/types/info/orders.d.ts +209 -0
  75. package/esm/src/types/info/orders.d.ts.map +1 -0
  76. package/esm/src/types/info/orders.js +1 -0
  77. package/esm/src/types/info/requests.d.ts +445 -0
  78. package/esm/src/types/info/requests.d.ts.map +1 -0
  79. package/esm/src/types/info/requests.js +1 -0
  80. package/esm/src/types/info/vaults.d.ts +90 -0
  81. package/esm/src/types/info/vaults.d.ts.map +1 -0
  82. package/esm/src/types/info/vaults.js +1 -0
  83. package/esm/src/types/subscriptions/common.d.ts +208 -0
  84. package/esm/src/types/subscriptions/common.d.ts.map +1 -0
  85. package/esm/src/types/subscriptions/common.js +1 -0
  86. package/esm/src/types/subscriptions/requests.d.ts +134 -0
  87. package/esm/src/types/subscriptions/requests.d.ts.map +1 -0
  88. package/esm/src/types/subscriptions/requests.js +1 -0
  89. package/esm/src/utils/key_sort.d.ts +3 -3
  90. package/esm/src/utils/key_sort.d.ts.map +1 -1
  91. package/esm/src/utils/signing.d.ts +1 -1
  92. package/esm/src/utils/signing.js +2 -2
  93. package/package.json +2 -2
  94. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +13 -3
  95. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +23 -13
  96. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.js +55 -45
  97. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.js +97 -87
  98. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.js +14 -4
  99. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js +288 -278
  100. package/script/deps/jsr.io/@noble/hashes/1.7.1/src/utils.js +238 -228
  101. package/script/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts +9 -0
  102. package/script/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts.map +1 -0
  103. package/script/deps/jsr.io/@std/bytes/1.0.5/_types.js +13 -0
  104. package/script/deps/jsr.io/@std/bytes/{1.0.4 → 1.0.5}/concat.d.ts +3 -1
  105. package/script/deps/jsr.io/@std/bytes/1.0.5/concat.d.ts.map +1 -0
  106. package/script/deps/jsr.io/@std/bytes/1.0.5/concat.js +45 -0
  107. package/script/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts +9 -0
  108. package/script/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts.map +1 -0
  109. package/script/deps/jsr.io/@std/encoding/1.0.7/_types.js +13 -0
  110. package/script/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts.map +1 -1
  111. package/script/deps/jsr.io/@std/encoding/1.0.7/_validate_binary_like.js +39 -0
  112. package/{esm/deps/jsr.io/@std/encoding/1.0.6 → script/deps/jsr.io/@std/encoding/1.0.7}/hex.d.ts +3 -1
  113. package/script/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +1 -0
  114. package/script/deps/jsr.io/@std/encoding/1.0.7/hex.js +123 -0
  115. package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +9 -0
  116. package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +1 -0
  117. package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.js +13 -0
  118. package/script/deps/jsr.io/@std/msgpack/{1.0.2 → 1.0.3}/encode.d.ts +3 -1
  119. package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +1 -0
  120. package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.js +250 -0
  121. package/script/mod.d.ts +15 -14
  122. package/script/mod.d.ts.map +1 -1
  123. package/script/mod.js +23 -13
  124. package/script/src/clients/event.d.ts +64 -21
  125. package/script/src/clients/event.d.ts.map +1 -1
  126. package/script/src/clients/event.js +551 -483
  127. package/script/src/clients/public.d.ts +244 -52
  128. package/script/src/clients/public.d.ts.map +1 -1
  129. package/script/src/clients/public.js +914 -708
  130. package/script/src/clients/wallet.d.ts +122 -53
  131. package/script/src/clients/wallet.d.ts.map +1 -1
  132. package/script/src/clients/wallet.js +1121 -975
  133. package/script/src/transports/base.js +25 -15
  134. package/script/src/transports/http/http_transport.d.ts.map +1 -1
  135. package/script/src/transports/http/http_transport.js +174 -161
  136. package/script/src/transports/websocket/hyperliquid_event_target.d.ts +27 -21
  137. package/script/src/transports/websocket/hyperliquid_event_target.d.ts.map +1 -1
  138. package/script/src/transports/websocket/hyperliquid_event_target.js +80 -33
  139. package/script/src/transports/websocket/reconnecting_websocket.js +364 -354
  140. package/script/src/transports/websocket/websocket_request_dispatcher.d.ts.map +1 -1
  141. package/script/src/transports/websocket/websocket_request_dispatcher.js +196 -186
  142. package/script/src/transports/websocket/websocket_transport.d.ts +7 -10
  143. package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  144. package/script/src/transports/websocket/websocket_transport.js +236 -220
  145. package/script/src/types/common.d.ts +3 -0
  146. package/script/src/types/common.d.ts.map +1 -0
  147. package/script/src/types/common.js +12 -0
  148. package/script/src/types/exchange/common.d.ts +36 -0
  149. package/script/src/types/exchange/common.d.ts.map +1 -0
  150. package/script/src/types/exchange/common.js +12 -0
  151. package/script/src/types/exchange/requests.d.ts +502 -0
  152. package/script/src/types/exchange/requests.d.ts.map +1 -0
  153. package/script/src/types/exchange/requests.js +12 -0
  154. package/script/src/types/exchange/responses.d.ts +141 -0
  155. package/script/src/types/exchange/responses.d.ts.map +1 -0
  156. package/script/src/types/exchange/responses.js +12 -0
  157. package/script/src/types/explorer/common.d.ts +37 -0
  158. package/script/src/types/explorer/common.d.ts.map +1 -0
  159. package/script/src/types/explorer/common.js +12 -0
  160. package/script/src/types/explorer/requests.d.ts +35 -0
  161. package/script/src/types/explorer/requests.d.ts.map +1 -0
  162. package/script/src/types/explorer/requests.js +12 -0
  163. package/script/src/types/explorer/responses.d.ts +23 -0
  164. package/script/src/types/explorer/responses.d.ts.map +1 -0
  165. package/script/src/types/explorer/responses.js +12 -0
  166. package/script/src/types/info/accounts.d.ts +489 -0
  167. package/script/src/types/info/accounts.d.ts.map +1 -0
  168. package/script/src/types/info/accounts.js +12 -0
  169. package/script/src/types/info/assets.d.ts +275 -0
  170. package/script/src/types/info/assets.d.ts.map +1 -0
  171. package/script/src/types/info/assets.js +12 -0
  172. package/script/src/types/info/delegations.d.ts +117 -0
  173. package/script/src/types/info/delegations.d.ts.map +1 -0
  174. package/script/src/types/info/delegations.js +12 -0
  175. package/script/src/types/info/orders.d.ts +209 -0
  176. package/script/src/types/info/orders.d.ts.map +1 -0
  177. package/script/src/types/info/orders.js +12 -0
  178. package/script/src/types/info/requests.d.ts +445 -0
  179. package/script/src/types/info/requests.d.ts.map +1 -0
  180. package/script/src/types/info/requests.js +12 -0
  181. package/script/src/types/info/vaults.d.ts +90 -0
  182. package/script/src/types/info/vaults.d.ts.map +1 -0
  183. package/script/src/types/info/vaults.js +12 -0
  184. package/script/src/types/subscriptions/common.d.ts +208 -0
  185. package/script/src/types/subscriptions/common.d.ts.map +1 -0
  186. package/script/src/types/subscriptions/common.js +12 -0
  187. package/script/src/types/subscriptions/requests.d.ts +134 -0
  188. package/script/src/types/subscriptions/requests.d.ts.map +1 -0
  189. package/script/src/types/subscriptions/requests.js +12 -0
  190. package/script/src/utils/key_sort.d.ts +3 -3
  191. package/script/src/utils/key_sort.d.ts.map +1 -1
  192. package/script/src/utils/key_sort.js +133 -123
  193. package/script/src/utils/signing.d.ts +1 -1
  194. package/script/src/utils/signing.js +172 -162
  195. package/esm/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +0 -1
  196. package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +0 -1
  197. package/esm/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +0 -1
  198. package/script/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +0 -1
  199. package/script/deps/jsr.io/@std/bytes/1.0.4/concat.js +0 -35
  200. package/script/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.js +0 -29
  201. package/script/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +0 -1
  202. package/script/deps/jsr.io/@std/encoding/1.0.6/hex.js +0 -113
  203. package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +0 -1
  204. package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.js +0 -240
  205. /package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts +0 -0
  206. /package/script/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts +0 -0
@@ -1,18 +1,28 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TransportError = void 0;
4
- /**
5
- * Base class for all transport-related errors.
6
- */
7
- class TransportError extends Error {
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.TransportError = void 0;
8
13
  /**
9
- * Creates a new transport error.
10
- * @param message - The error message.
11
- * @param options - Additional error options.
14
+ * Base class for all transport-related errors.
12
15
  */
13
- constructor(message, options) {
14
- super(message, options);
15
- this.name = "TransportError";
16
+ class TransportError extends Error {
17
+ /**
18
+ * Creates a new transport error.
19
+ * @param message - The error message.
20
+ * @param options - Additional error options.
21
+ */
22
+ constructor(message, options) {
23
+ super(message, options);
24
+ this.name = "TransportError";
25
+ }
16
26
  }
17
- }
18
- exports.TransportError = TransportError;
27
+ exports.TransportError = TransportError;
28
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"http_transport.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/http/http_transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEpE,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEtC;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,cAAc;IAM7B,QAAQ,EAAE,QAAQ;IAAS,YAAY,CAAC,EAAE,MAAM;IALnE;;;;OAIG;gBACgB,QAAQ,EAAE,QAAQ,EAAS,YAAY,CAAC,EAAE,MAAM,YAAA;CAItE;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IAEnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAExB,2IAA2I;IAC3I,YAAY,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC;IAEpD;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,YAAY,CAAC,OAAO,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IAElF;;;;OAIG;IACH,UAAU,CAAC,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GG;gBACS,OAAO,CAAC,EAAE,oBAAoB;IAQ1C;;;;;;;;OAQG;IACG,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;CA6CpH"}
@@ -1,175 +1,188 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpTransport = exports.HttpRequestError = void 0;
4
- const base_js_1 = require("../base.js");
5
- /**
6
- * Error thrown when an HTTP response is deemed invalid:
7
- * - Non-200 status code
8
- * - Unexpected content type
9
- */
10
- class HttpRequestError extends base_js_1.TransportError {
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "../base.js"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.HttpTransport = exports.HttpRequestError = void 0;
13
+ const base_js_1 = require("../base.js");
11
14
  /**
12
- * Creates a new HTTP request error.
13
- * @param response - The failed HTTP response.
14
- * @param responseBody - The raw response body content, if available.
15
+ * Error thrown when an HTTP response is deemed invalid:
16
+ * - Non-200 status code
17
+ * - Unexpected content type
15
18
  */
16
- constructor(response, responseBody) {
17
- super(`HTTP request failed. Status: ${response.status}. Body: ${responseBody}`);
18
- Object.defineProperty(this, "response", {
19
- enumerable: true,
20
- configurable: true,
21
- writable: true,
22
- value: response
23
- });
24
- Object.defineProperty(this, "responseBody", {
25
- enumerable: true,
26
- configurable: true,
27
- writable: true,
28
- value: responseBody
29
- });
30
- this.name = "HttpRequestError";
19
+ class HttpRequestError extends base_js_1.TransportError {
20
+ /**
21
+ * Creates a new HTTP request error.
22
+ * @param response - The failed HTTP response.
23
+ * @param responseBody - The raw response body content, if available.
24
+ */
25
+ constructor(response, responseBody) {
26
+ let message = `HTTP request failed: status ${response.status}`;
27
+ if (responseBody)
28
+ message += `, body "${responseBody}"`;
29
+ super(message);
30
+ Object.defineProperty(this, "response", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: response
35
+ });
36
+ Object.defineProperty(this, "responseBody", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: responseBody
41
+ });
42
+ this.name = "HttpRequestError";
43
+ }
31
44
  }
32
- }
33
- exports.HttpRequestError = HttpRequestError;
34
- /**
35
- * HTTP implementation of the REST transport interface.
36
- */
37
- class HttpTransport {
45
+ exports.HttpRequestError = HttpRequestError;
38
46
  /**
39
- * Creates a new HTTP transport instance.
40
- * @param options - Configuration options for the HTTP transport layer.
47
+ * HTTP implementation of the REST transport interface.
41
48
  */
42
- constructor(options) {
43
- Object.defineProperty(this, "url", {
44
- enumerable: true,
45
- configurable: true,
46
- writable: true,
47
- value: void 0
48
- });
49
- Object.defineProperty(this, "timeout", {
50
- enumerable: true,
51
- configurable: true,
52
- writable: true,
53
- value: void 0
54
- });
55
- Object.defineProperty(this, "fetchOptions", {
56
- enumerable: true,
57
- configurable: true,
58
- writable: true,
59
- value: void 0
60
- });
61
- Object.defineProperty(this, "onRequest", {
62
- enumerable: true,
63
- configurable: true,
64
- writable: true,
65
- value: void 0
66
- });
67
- Object.defineProperty(this, "onResponse", {
68
- enumerable: true,
69
- configurable: true,
70
- writable: true,
71
- value: void 0
72
- });
73
- /** Mapping of endpoint types to their API paths. */
74
- Object.defineProperty(this, "_endpointPaths", {
75
- enumerable: true,
76
- configurable: true,
77
- writable: true,
78
- value: {
79
- info: "/info",
80
- action: "/exchange",
81
- explorer: "/explorer",
49
+ class HttpTransport {
50
+ /**
51
+ * Creates a new HTTP transport instance.
52
+ * @param options - Configuration options for the HTTP transport layer.
53
+ */
54
+ constructor(options) {
55
+ Object.defineProperty(this, "url", {
56
+ enumerable: true,
57
+ configurable: true,
58
+ writable: true,
59
+ value: void 0
60
+ });
61
+ Object.defineProperty(this, "timeout", {
62
+ enumerable: true,
63
+ configurable: true,
64
+ writable: true,
65
+ value: void 0
66
+ });
67
+ Object.defineProperty(this, "fetchOptions", {
68
+ enumerable: true,
69
+ configurable: true,
70
+ writable: true,
71
+ value: void 0
72
+ });
73
+ Object.defineProperty(this, "onRequest", {
74
+ enumerable: true,
75
+ configurable: true,
76
+ writable: true,
77
+ value: void 0
78
+ });
79
+ Object.defineProperty(this, "onResponse", {
80
+ enumerable: true,
81
+ configurable: true,
82
+ writable: true,
83
+ value: void 0
84
+ });
85
+ /** Mapping of endpoint types to their API paths. */
86
+ Object.defineProperty(this, "_endpointPaths", {
87
+ enumerable: true,
88
+ configurable: true,
89
+ writable: true,
90
+ value: {
91
+ info: "/info",
92
+ action: "/exchange",
93
+ explorer: "/explorer",
94
+ }
95
+ });
96
+ this.url = options?.url ?? "https://api.hyperliquid.xyz";
97
+ this.timeout = options?.timeout === undefined ? 10_000 : options.timeout;
98
+ this.fetchOptions = options?.fetchOptions ?? {};
99
+ this.onRequest = options?.onRequest;
100
+ this.onResponse = options?.onResponse;
101
+ }
102
+ /**
103
+ * Sends a request to the Hyperliquid API via fetch.
104
+ * @param endpoint - The API endpoint to send the request to.
105
+ * @param payload - The payload to send with the request.
106
+ * @param signal - An optional abort signal.
107
+ * @returns A promise that resolves with parsed JSON response body.
108
+ * @throws {HttpRequestError} - Thrown when an HTTP response is deemed invalid.
109
+ * @throws May throw {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch#exceptions | fetch errors}.
110
+ */
111
+ async request(endpoint, payload, signal) {
112
+ // Construct a Request
113
+ const url = new URL(this._endpointPaths[endpoint], this.url);
114
+ const init = mergeRequestInit({
115
+ body: JSON.stringify(payload),
116
+ headers: {
117
+ "Accept-Encoding": "gzip, deflate, br, zstd",
118
+ "Connection": "keep-alive",
119
+ "Content-Type": "application/json",
120
+ },
121
+ keepalive: true,
122
+ method: "POST",
123
+ signal: this.timeout ? AbortSignal.timeout(this.timeout) : undefined,
124
+ }, this.fetchOptions, { signal });
125
+ let request = new Request(url, init);
126
+ // Call the onRequest callback, if provided
127
+ if (this.onRequest) {
128
+ const customRequest = await this.onRequest(request);
129
+ if (customRequest instanceof Request)
130
+ request = customRequest;
82
131
  }
83
- });
84
- this.url = options?.url ?? "https://api.hyperliquid.xyz";
85
- this.timeout = options?.timeout === undefined ? 10_000 : options.timeout;
86
- this.fetchOptions = options?.fetchOptions ?? {};
87
- this.onRequest = options?.onRequest;
88
- this.onResponse = options?.onResponse;
132
+ // Send the Request and wait for a Response
133
+ let response = await fetch(request);
134
+ // Call the onResponse callback, if provided
135
+ if (this.onResponse) {
136
+ const customResponse = await this.onResponse(response);
137
+ if (customResponse instanceof Response)
138
+ response = customResponse;
139
+ }
140
+ // Validate the Response
141
+ if (!response.ok || !response.headers.get("Content-Type")?.includes("application/json")) {
142
+ // Unload the response body to prevent memory leaks
143
+ const body = await response.text().catch(() => undefined);
144
+ throw new HttpRequestError(response, body);
145
+ }
146
+ // Parse and return the response body
147
+ return await response.json();
148
+ }
89
149
  }
150
+ exports.HttpTransport = HttpTransport;
90
151
  /**
91
- * Sends a request to the Hyperliquid API via fetch.
92
- * @param endpoint - The API endpoint to send the request to.
93
- * @param payload - The payload to send with the request.
94
- * @param signal - An optional abort signal.
95
- * @returns A promise that resolves with parsed JSON response body.
96
- * @throws {HttpRequestError} - Thrown when an HTTP response is deemed invalid.
97
- * @throws May throw {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch#exceptions | fetch errors}.
152
+ * Merges multiple `HeadersInit` objects into one.
153
+ * @param inits - A list of `HeadersInit` objects to merge.
154
+ * @returns A new `Headers` object that contains all headers from the input objects.
98
155
  */
99
- async request(endpoint, payload, signal) {
100
- // Construct a Request
101
- const url = new URL(this._endpointPaths[endpoint], this.url);
102
- const init = mergeRequestInit({
103
- body: JSON.stringify(payload),
104
- headers: {
105
- "Accept-Encoding": "gzip, deflate, br, zstd",
106
- "Connection": "keep-alive",
107
- "Content-Type": "application/json",
108
- },
109
- keepalive: true,
110
- method: "POST",
111
- signal: this.timeout ? AbortSignal.timeout(this.timeout) : undefined,
112
- }, this.fetchOptions, { signal });
113
- let request = new Request(url, init);
114
- // Call the onRequest callback, if provided
115
- if (this.onRequest) {
116
- const customRequest = await this.onRequest(request);
117
- if (customRequest instanceof Request)
118
- request = customRequest;
119
- }
120
- // Send the Request and wait for a Response
121
- let response = await fetch(request);
122
- // Call the onResponse callback, if provided
123
- if (this.onResponse) {
124
- const customResponse = await this.onResponse(response);
125
- if (customResponse instanceof Response)
126
- response = customResponse;
156
+ function mergeHeadersInit(...inits) {
157
+ if (inits.length === 0 || inits.length === 1) {
158
+ return new Headers(inits[0]);
127
159
  }
128
- // Validate the Response
129
- if (!response.ok || !response.headers.get("Content-Type")?.includes("application/json")) {
130
- // Unload the response body to prevent memory leaks
131
- const body = await response.text().catch(() => undefined);
132
- throw new HttpRequestError(response, body);
160
+ const merged = new Headers();
161
+ for (const headers of inits) {
162
+ const entries = Symbol.iterator in headers ? headers : Object.entries(headers);
163
+ for (const [key, value] of entries) {
164
+ merged.set(key, value);
165
+ }
133
166
  }
134
- // Parse and return the response body
135
- return await response.json();
136
- }
137
- }
138
- exports.HttpTransport = HttpTransport;
139
- /**
140
- * Merges multiple `HeadersInit` objects into one.
141
- * @param inits - A list of `HeadersInit` objects to merge.
142
- * @returns A new `Headers` object that contains all headers from the input objects.
143
- */
144
- function mergeHeadersInit(...inits) {
145
- if (inits.length === 0 || inits.length === 1) {
146
- return new Headers(inits[0]);
167
+ return merged;
147
168
  }
148
- const merged = new Headers();
149
- for (const headers of inits) {
150
- const entries = Symbol.iterator in headers ? headers : Object.entries(headers);
151
- for (const [key, value] of entries) {
152
- merged.set(key, value);
169
+ /**
170
+ * Merges multiple `RequestInit` objects into one.
171
+ * @param inits - A list of `RequestInit` objects to merge.
172
+ * @returns A new `RequestInit` object that contains all properties from the input objects.
173
+ */
174
+ function mergeRequestInit(...inits) {
175
+ const merged = inits.reduce((acc, init) => ({ ...acc, ...init }), {});
176
+ const headersList = inits.map((init) => init.headers)
177
+ .filter((headers) => typeof headers === "object");
178
+ if (headersList.length > 0) {
179
+ merged.headers = mergeHeadersInit(...headersList);
153
180
  }
181
+ const signals = inits.map((init) => init.signal)
182
+ .filter((signal) => signal instanceof AbortSignal);
183
+ if (signals.length > 0) {
184
+ merged.signal = signals.length > 1 ? AbortSignal.any(signals) : signals[0];
185
+ }
186
+ return merged;
154
187
  }
155
- return merged;
156
- }
157
- /**
158
- * Merges multiple `RequestInit` objects into one.
159
- * @param inits - A list of `RequestInit` objects to merge.
160
- * @returns A new `RequestInit` object that contains all properties from the input objects.
161
- */
162
- function mergeRequestInit(...inits) {
163
- const merged = inits.reduce((acc, init) => ({ ...acc, ...init }), {});
164
- const headersList = inits.map((init) => init.headers)
165
- .filter((headers) => typeof headers === "object");
166
- if (headersList.length > 0) {
167
- merged.headers = mergeHeadersInit(...headersList);
168
- }
169
- const signals = inits.map((init) => init.signal)
170
- .filter((signal) => signal instanceof AbortSignal);
171
- if (signals.length > 0) {
172
- merged.signal = signals.length > 1 ? AbortSignal.any(signals) : signals[0];
173
- }
174
- return merged;
175
- }
188
+ });
@@ -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,E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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"}
@@ -1,37 +1,84 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HyperliquidEventTarget = void 0;
4
- const mod_js_1 = require("../../../deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js");
5
- /**
6
- * A class that listens to WebSocket messages and dispatches them as Hyperliquid typed events.
7
- */
8
- class HyperliquidEventTarget extends mod_js_1.TypedEventTarget {
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "../../../deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.HyperliquidEventTarget = void 0;
13
+ const mod_js_1 = require("../../../deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js");
9
14
  /**
10
- * Creates a new Hyperliquid event target.
11
- * @param socket - The WebSocket to listen to.
15
+ * A class that listens to WebSocket messages and dispatches them as Hyperliquid typed events.
12
16
  */
13
- constructor(socket) {
14
- super();
15
- socket.addEventListener("message", (event) => {
16
- try {
17
- const msg = JSON.parse(event.data);
18
- if (isHyperliquidMsg(msg)) {
19
- this.dispatchEvent(new CustomEvent(msg.channel, { detail: msg.data }));
17
+ class HyperliquidEventTarget extends mod_js_1.TypedEventTarget {
18
+ /**
19
+ * Creates a new Hyperliquid event target.
20
+ * @param socket - The WebSocket to listen to.
21
+ */
22
+ constructor(socket) {
23
+ super();
24
+ socket.addEventListener("message", (event) => {
25
+ try {
26
+ const msg = JSON.parse(event.data);
27
+ if (isHyperliquidMsg(msg)) {
28
+ this.dispatchEvent(new CustomEvent(msg.channel, { detail: msg.data }));
29
+ }
30
+ else if (isExplorerBlockMsg(msg)) {
31
+ this.dispatchEvent(new CustomEvent("_explorerBlock", { detail: msg }));
32
+ }
33
+ else if (isExplorerTxsMsg(msg)) {
34
+ this.dispatchEvent(new CustomEvent("_explorerTxs", { detail: msg }));
35
+ }
36
+ }
37
+ catch {
38
+ // Ignore JSON parsing errors
20
39
  }
21
- }
22
- catch {
23
- // Ignore JSON parsing errors
24
- }
25
- });
40
+ });
41
+ }
42
+ }
43
+ exports.HyperliquidEventTarget = HyperliquidEventTarget;
44
+ /**
45
+ * Type guard for Hyperliquid messages.
46
+ * @param value - The value to check.
47
+ * @returns True if the value is a Hyperliquid message.
48
+ */
49
+ function isHyperliquidMsg(value) {
50
+ return typeof value === "object" && value !== null &&
51
+ "channel" in value && typeof value.channel === "string";
52
+ }
53
+ /**
54
+ * Type guard for explorer block messages.
55
+ * @param value - The value to check.
56
+ * @returns True if the value is an array of block details.
57
+ */
58
+ function isExplorerBlockMsg(value) {
59
+ return Array.isArray(value) && value.length > 0 &&
60
+ value.every((block) => typeof block === "object" && block !== null && !Array.isArray(block) &&
61
+ "height" in block && typeof block.height === "number" &&
62
+ "blockTime" in block && typeof block.blockTime === "number" &&
63
+ "hash" in block && typeof block.hash === "string" &&
64
+ "proposer" in block && typeof block.proposer === "string" &&
65
+ "numTxs" in block && typeof block.numTxs === "number");
66
+ }
67
+ /**
68
+ * Type guard for explorer transactions messages.
69
+ * @param value - The value to check.
70
+ * @returns True if the value is an array of transaction details.
71
+ */
72
+ function isExplorerTxsMsg(value) {
73
+ return Array.isArray(value) && value.length > 0 &&
74
+ value.every((tx) => {
75
+ return typeof tx === "object" && tx !== null && !Array.isArray(tx) &&
76
+ "action" in tx && typeof tx.action === "object" && tx.action !== null &&
77
+ "block" in tx && typeof tx.block === "number" &&
78
+ "error" in tx && (typeof tx.error === "string" || tx.error === null) &&
79
+ "hash" in tx && typeof tx.hash === "string" &&
80
+ "time" in tx && typeof tx.time === "number" &&
81
+ "user" in tx && typeof tx.user === "string";
82
+ });
26
83
  }
27
- }
28
- exports.HyperliquidEventTarget = HyperliquidEventTarget;
29
- /**
30
- * Type guard for Hyperliquid messages.
31
- * @param value - The value to check.
32
- * @returns True if the value is a Hyperliquid message.
33
- */
34
- function isHyperliquidMsg(value) {
35
- return typeof value === "object" && value !== null &&
36
- "channel" in value && typeof value.channel === "string";
37
- }
84
+ });