@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.
- package/LICENSE +20 -20
- package/README.md +42 -17
- package/esm/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts +9 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/bytes/1.0.5/_types.js +2 -0
- package/esm/deps/jsr.io/@std/bytes/{1.0.4 → 1.0.5}/concat.d.ts +3 -1
- package/esm/deps/jsr.io/@std/bytes/1.0.5/concat.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/bytes/{1.0.4 → 1.0.5}/concat.js +1 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts +9 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.7/_types.js +2 -0
- package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.js +1 -1
- package/{script/deps/jsr.io/@std/encoding/1.0.6 → esm/deps/jsr.io/@std/encoding/1.0.7}/hex.d.ts +3 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/hex.js +1 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +9 -0
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.js +2 -0
- package/esm/deps/jsr.io/@std/msgpack/{1.0.2 → 1.0.3}/encode.d.ts +3 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/msgpack/{1.0.2 → 1.0.3}/encode.js +2 -2
- package/esm/mod.d.ts +15 -14
- package/esm/mod.d.ts.map +1 -1
- package/esm/src/clients/event.d.ts +64 -21
- package/esm/src/clients/event.d.ts.map +1 -1
- package/esm/src/clients/event.js +76 -18
- package/esm/src/clients/public.d.ts +244 -52
- package/esm/src/clients/public.d.ts.map +1 -1
- package/esm/src/clients/public.js +243 -47
- package/esm/src/clients/wallet.d.ts +122 -53
- package/esm/src/clients/wallet.d.ts.map +1 -1
- package/esm/src/clients/wallet.js +201 -65
- package/esm/src/transports/http/http_transport.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.js +4 -1
- package/esm/src/transports/websocket/hyperliquid_event_target.d.ts +27 -21
- package/esm/src/transports/websocket/hyperliquid_event_target.d.ts.map +1 -1
- package/esm/src/transports/websocket/hyperliquid_event_target.js +37 -0
- package/esm/src/transports/websocket/websocket_request_dispatcher.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_request_dispatcher.js +4 -4
- package/esm/src/transports/websocket/websocket_transport.d.ts +7 -10
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.js +41 -35
- package/esm/src/types/common.d.ts +3 -0
- package/esm/src/types/common.d.ts.map +1 -0
- package/esm/src/types/common.js +1 -0
- package/esm/src/types/exchange/common.d.ts +36 -0
- package/esm/src/types/exchange/common.d.ts.map +1 -0
- package/esm/src/types/exchange/common.js +1 -0
- package/esm/src/types/exchange/requests.d.ts +502 -0
- package/esm/src/types/exchange/requests.d.ts.map +1 -0
- package/esm/src/types/exchange/requests.js +1 -0
- package/esm/src/types/exchange/responses.d.ts +141 -0
- package/esm/src/types/exchange/responses.d.ts.map +1 -0
- package/esm/src/types/exchange/responses.js +1 -0
- package/esm/src/types/explorer/common.d.ts +37 -0
- package/esm/src/types/explorer/common.d.ts.map +1 -0
- package/esm/src/types/explorer/common.js +1 -0
- package/esm/src/types/explorer/requests.d.ts +35 -0
- package/esm/src/types/explorer/requests.d.ts.map +1 -0
- package/esm/src/types/explorer/requests.js +1 -0
- package/esm/src/types/explorer/responses.d.ts +23 -0
- package/esm/src/types/explorer/responses.d.ts.map +1 -0
- package/esm/src/types/explorer/responses.js +1 -0
- package/esm/src/types/info/accounts.d.ts +489 -0
- package/esm/src/types/info/accounts.d.ts.map +1 -0
- package/esm/src/types/info/accounts.js +1 -0
- package/esm/src/types/info/assets.d.ts +275 -0
- package/esm/src/types/info/assets.d.ts.map +1 -0
- package/esm/src/types/info/assets.js +1 -0
- package/esm/src/types/info/delegations.d.ts +117 -0
- package/esm/src/types/info/delegations.d.ts.map +1 -0
- package/esm/src/types/info/delegations.js +1 -0
- package/esm/src/types/info/orders.d.ts +209 -0
- package/esm/src/types/info/orders.d.ts.map +1 -0
- package/esm/src/types/info/orders.js +1 -0
- package/esm/src/types/info/requests.d.ts +445 -0
- package/esm/src/types/info/requests.d.ts.map +1 -0
- package/esm/src/types/info/requests.js +1 -0
- package/esm/src/types/info/vaults.d.ts +90 -0
- package/esm/src/types/info/vaults.d.ts.map +1 -0
- package/esm/src/types/info/vaults.js +1 -0
- package/esm/src/types/subscriptions/common.d.ts +208 -0
- package/esm/src/types/subscriptions/common.d.ts.map +1 -0
- package/esm/src/types/subscriptions/common.js +1 -0
- package/esm/src/types/subscriptions/requests.d.ts +134 -0
- package/esm/src/types/subscriptions/requests.d.ts.map +1 -0
- package/esm/src/types/subscriptions/requests.js +1 -0
- package/esm/src/utils/key_sort.d.ts +3 -3
- package/esm/src/utils/key_sort.d.ts.map +1 -1
- package/esm/src/utils/signing.d.ts +1 -1
- package/esm/src/utils/signing.js +2 -2
- package/package.json +2 -2
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +13 -3
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +23 -13
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_assert.js +55 -45
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/_u64.js +97 -87
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/crypto.js +14 -4
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js +288 -278
- package/script/deps/jsr.io/@noble/hashes/1.7.1/src/utils.js +238 -228
- package/script/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts +9 -0
- package/script/deps/jsr.io/@std/bytes/1.0.5/_types.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/bytes/1.0.5/_types.js +13 -0
- package/script/deps/jsr.io/@std/bytes/{1.0.4 → 1.0.5}/concat.d.ts +3 -1
- package/script/deps/jsr.io/@std/bytes/1.0.5/concat.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/bytes/1.0.5/concat.js +45 -0
- package/script/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts +9 -0
- package/script/deps/jsr.io/@std/encoding/1.0.7/_types.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.7/_types.js +13 -0
- package/script/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts.map +1 -1
- package/script/deps/jsr.io/@std/encoding/1.0.7/_validate_binary_like.js +39 -0
- package/{esm/deps/jsr.io/@std/encoding/1.0.6 → script/deps/jsr.io/@std/encoding/1.0.7}/hex.d.ts +3 -1
- package/script/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.7/hex.js +123 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +9 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.js +13 -0
- package/script/deps/jsr.io/@std/msgpack/{1.0.2 → 1.0.3}/encode.d.ts +3 -1
- package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.js +250 -0
- package/script/mod.d.ts +15 -14
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +23 -13
- package/script/src/clients/event.d.ts +64 -21
- package/script/src/clients/event.d.ts.map +1 -1
- package/script/src/clients/event.js +551 -483
- package/script/src/clients/public.d.ts +244 -52
- package/script/src/clients/public.d.ts.map +1 -1
- package/script/src/clients/public.js +914 -708
- package/script/src/clients/wallet.d.ts +122 -53
- package/script/src/clients/wallet.d.ts.map +1 -1
- package/script/src/clients/wallet.js +1121 -975
- package/script/src/transports/base.js +25 -15
- package/script/src/transports/http/http_transport.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.js +174 -161
- package/script/src/transports/websocket/hyperliquid_event_target.d.ts +27 -21
- package/script/src/transports/websocket/hyperliquid_event_target.d.ts.map +1 -1
- package/script/src/transports/websocket/hyperliquid_event_target.js +80 -33
- package/script/src/transports/websocket/reconnecting_websocket.js +364 -354
- package/script/src/transports/websocket/websocket_request_dispatcher.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_request_dispatcher.js +196 -186
- package/script/src/transports/websocket/websocket_transport.d.ts +7 -10
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.js +236 -220
- package/script/src/types/common.d.ts +3 -0
- package/script/src/types/common.d.ts.map +1 -0
- package/script/src/types/common.js +12 -0
- package/script/src/types/exchange/common.d.ts +36 -0
- package/script/src/types/exchange/common.d.ts.map +1 -0
- package/script/src/types/exchange/common.js +12 -0
- package/script/src/types/exchange/requests.d.ts +502 -0
- package/script/src/types/exchange/requests.d.ts.map +1 -0
- package/script/src/types/exchange/requests.js +12 -0
- package/script/src/types/exchange/responses.d.ts +141 -0
- package/script/src/types/exchange/responses.d.ts.map +1 -0
- package/script/src/types/exchange/responses.js +12 -0
- package/script/src/types/explorer/common.d.ts +37 -0
- package/script/src/types/explorer/common.d.ts.map +1 -0
- package/script/src/types/explorer/common.js +12 -0
- package/script/src/types/explorer/requests.d.ts +35 -0
- package/script/src/types/explorer/requests.d.ts.map +1 -0
- package/script/src/types/explorer/requests.js +12 -0
- package/script/src/types/explorer/responses.d.ts +23 -0
- package/script/src/types/explorer/responses.d.ts.map +1 -0
- package/script/src/types/explorer/responses.js +12 -0
- package/script/src/types/info/accounts.d.ts +489 -0
- package/script/src/types/info/accounts.d.ts.map +1 -0
- package/script/src/types/info/accounts.js +12 -0
- package/script/src/types/info/assets.d.ts +275 -0
- package/script/src/types/info/assets.d.ts.map +1 -0
- package/script/src/types/info/assets.js +12 -0
- package/script/src/types/info/delegations.d.ts +117 -0
- package/script/src/types/info/delegations.d.ts.map +1 -0
- package/script/src/types/info/delegations.js +12 -0
- package/script/src/types/info/orders.d.ts +209 -0
- package/script/src/types/info/orders.d.ts.map +1 -0
- package/script/src/types/info/orders.js +12 -0
- package/script/src/types/info/requests.d.ts +445 -0
- package/script/src/types/info/requests.d.ts.map +1 -0
- package/script/src/types/info/requests.js +12 -0
- package/script/src/types/info/vaults.d.ts +90 -0
- package/script/src/types/info/vaults.d.ts.map +1 -0
- package/script/src/types/info/vaults.js +12 -0
- package/script/src/types/subscriptions/common.d.ts +208 -0
- package/script/src/types/subscriptions/common.d.ts.map +1 -0
- package/script/src/types/subscriptions/common.js +12 -0
- package/script/src/types/subscriptions/requests.d.ts +134 -0
- package/script/src/types/subscriptions/requests.d.ts.map +1 -0
- package/script/src/types/subscriptions/requests.js +12 -0
- package/script/src/utils/key_sort.d.ts +3 -3
- package/script/src/utils/key_sort.d.ts.map +1 -1
- package/script/src/utils/key_sort.js +133 -123
- package/script/src/utils/signing.d.ts +1 -1
- package/script/src/utils/signing.js +172 -162
- package/esm/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/bytes/1.0.4/concat.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/bytes/1.0.4/concat.js +0 -35
- package/script/deps/jsr.io/@std/encoding/1.0.6/_validate_binary_like.js +0 -29
- package/script/deps/jsr.io/@std/encoding/1.0.6/hex.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.6/hex.js +0 -113
- package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/msgpack/1.0.2/encode.js +0 -240
- /package/esm/deps/jsr.io/@std/encoding/{1.0.6 → 1.0.7}/_validate_binary_like.d.ts +0 -0
- /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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
*
|
|
10
|
-
* @param message - The error message.
|
|
11
|
-
* @param options - Additional error options.
|
|
14
|
+
* Base class for all transport-related errors.
|
|
12
15
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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;
|
|
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;CAOtE;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,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,YAAY,CAAC,QAAQ,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;CACzF;AAED;;GAEG;AACH,qBAAa,aAAc,YAAW,iBAAiB,EAAE,oBAAoB;IACzE,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IAClB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,YAAY,EAAE,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC;IACnD,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,YAAY,CAAC,OAAO,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IAClF,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,YAAY,CAAC,QAAQ,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IAEtF,oDAAoD;IACpD,SAAS,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,GAAG,QAAQ,GAAG,UAAU,EAAE,MAAM,CAAC,CAItE;IAEF;;;OAGG;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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
+
* Error thrown when an HTTP response is deemed invalid:
|
|
16
|
+
* - Non-200 status code
|
|
17
|
+
* - Unexpected content type
|
|
15
18
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
*
|
|
40
|
-
* @param options - Configuration options for the HTTP transport layer.
|
|
47
|
+
* HTTP implementation of the REST transport interface.
|
|
41
48
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
*
|
|
92
|
-
* @param
|
|
93
|
-
* @
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
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
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
|
|
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
|
-
/**
|
|
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;
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
23
|
-
|
|
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
|
+
});
|