@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.
- package/LICENSE +20 -20
- package/README.md +33 -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 +1 -0
- package/esm/mod.d.ts.map +1 -1
- package/esm/src/clients/event.d.ts +57 -16
- package/esm/src/clients/event.d.ts.map +1 -1
- package/esm/src/clients/event.js +72 -16
- package/esm/src/clients/public.d.ts +241 -49
- 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 +120 -51
- package/esm/src/clients/wallet.d.ts.map +1 -1
- package/esm/src/clients/wallet.js +192 -58
- 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.js +3 -3
- 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/exchange/common.d.ts +6 -6
- package/esm/src/types/exchange/common.d.ts.map +1 -1
- package/esm/src/types/exchange/requests.d.ts +131 -64
- package/esm/src/types/exchange/requests.d.ts.map +1 -1
- package/esm/src/types/exchange/responses.d.ts +7 -7
- package/esm/src/types/exchange/responses.d.ts.map +1 -1
- package/esm/src/types/explorer/common.d.ts +15 -15
- package/esm/src/types/explorer/common.d.ts.map +1 -1
- package/esm/src/types/explorer/requests.d.ts +19 -6
- package/esm/src/types/explorer/requests.d.ts.map +1 -1
- package/esm/src/types/explorer/responses.d.ts +9 -2
- package/esm/src/types/explorer/responses.d.ts.map +1 -1
- package/esm/src/types/info/accounts.d.ts +189 -124
- package/esm/src/types/info/accounts.d.ts.map +1 -1
- package/esm/src/types/info/assets.d.ts +82 -78
- package/esm/src/types/info/assets.d.ts.map +1 -1
- 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 +67 -67
- package/esm/src/types/info/orders.d.ts.map +1 -1
- package/esm/src/types/info/requests.d.ts +128 -63
- package/esm/src/types/info/requests.d.ts.map +1 -1
- package/esm/src/types/info/vaults.d.ts +41 -84
- package/esm/src/types/info/vaults.d.ts.map +1 -1
- package/esm/src/types/subscriptions/common.d.ts +3 -0
- package/esm/src/types/subscriptions/common.d.ts.map +1 -1
- package/esm/src/types/subscriptions/requests.d.ts +10 -0
- package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
- package/esm/src/utils/key_sort.d.ts +2 -2
- 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 +1 -1
- 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 +1 -0
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +23 -13
- package/script/src/clients/event.d.ts +57 -16
- package/script/src/clients/event.d.ts.map +1 -1
- package/script/src/clients/event.js +551 -485
- package/script/src/clients/public.d.ts +241 -49
- 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 +120 -51
- package/script/src/clients/wallet.d.ts.map +1 -1
- package/script/src/clients/wallet.js +1121 -977
- package/script/src/transports/base.js +25 -15
- package/script/src/transports/http/http_transport.js +174 -164
- 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.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.js +12 -2
- package/script/src/types/exchange/common.d.ts +6 -6
- package/script/src/types/exchange/common.d.ts.map +1 -1
- package/script/src/types/exchange/common.js +12 -2
- package/script/src/types/exchange/requests.d.ts +131 -64
- package/script/src/types/exchange/requests.d.ts.map +1 -1
- package/script/src/types/exchange/requests.js +12 -2
- package/script/src/types/exchange/responses.d.ts +7 -7
- package/script/src/types/exchange/responses.d.ts.map +1 -1
- package/script/src/types/exchange/responses.js +12 -2
- package/script/src/types/explorer/common.d.ts +15 -15
- package/script/src/types/explorer/common.d.ts.map +1 -1
- package/script/src/types/explorer/common.js +12 -2
- package/script/src/types/explorer/requests.d.ts +19 -6
- package/script/src/types/explorer/requests.d.ts.map +1 -1
- package/script/src/types/explorer/requests.js +12 -2
- package/script/src/types/explorer/responses.d.ts +9 -2
- package/script/src/types/explorer/responses.d.ts.map +1 -1
- package/script/src/types/explorer/responses.js +12 -2
- package/script/src/types/info/accounts.d.ts +189 -124
- package/script/src/types/info/accounts.d.ts.map +1 -1
- package/script/src/types/info/accounts.js +12 -2
- package/script/src/types/info/assets.d.ts +82 -78
- package/script/src/types/info/assets.d.ts.map +1 -1
- package/script/src/types/info/assets.js +12 -2
- 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 +67 -67
- package/script/src/types/info/orders.d.ts.map +1 -1
- package/script/src/types/info/orders.js +12 -2
- package/script/src/types/info/requests.d.ts +128 -63
- package/script/src/types/info/requests.d.ts.map +1 -1
- package/script/src/types/info/requests.js +12 -2
- package/script/src/types/info/vaults.d.ts +41 -84
- package/script/src/types/info/vaults.d.ts.map +1 -1
- package/script/src/types/info/vaults.js +12 -2
- package/script/src/types/subscriptions/common.d.ts +3 -0
- package/script/src/types/subscriptions/common.d.ts.map +1 -1
- package/script/src/types/subscriptions/common.js +12 -2
- package/script/src/types/subscriptions/requests.d.ts +10 -0
- package/script/src/types/subscriptions/requests.d.ts.map +1 -1
- package/script/src/types/subscriptions/requests.js +12 -2
- package/script/src/utils/key_sort.d.ts +2 -2
- 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,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,
|
|
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
|
|
124
|
+
* @returns Successful response without specific data.
|
|
126
125
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
127
126
|
*
|
|
128
|
-
* @see
|
|
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
|
|
171
|
+
* @returns Successful response without specific data.
|
|
173
172
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
174
173
|
*
|
|
175
|
-
* @see
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
*
|
|
305
|
+
* Deposit into staking balance.
|
|
307
306
|
* @param args - The parameters for the request.
|
|
308
307
|
* @param signal - An optional abort signal.
|
|
309
|
-
* @returns
|
|
308
|
+
* @returns Successful response without specific data.
|
|
310
309
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
311
310
|
*
|
|
312
|
-
* @see
|
|
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
|
|
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
|
|
468
|
+
* @returns Successful response without specific data.
|
|
383
469
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
384
470
|
*
|
|
385
|
-
* @see
|
|
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
|
|
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
|
|
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
|
|
569
|
+
* @returns Successful response without specific data.
|
|
484
570
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
485
571
|
*
|
|
486
|
-
* @see
|
|
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
|
|
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
|
|
636
|
+
* @returns Successful response without specific data.
|
|
554
637
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
555
638
|
*
|
|
556
|
-
* @see
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
851
|
+
* @returns Successful response without specific data.
|
|
718
852
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
719
853
|
*
|
|
720
|
-
* @see
|
|
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
|
|
889
|
+
* @returns Successful response without specific data.
|
|
756
890
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
757
891
|
*
|
|
758
|
-
* @see
|
|
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
|
|
927
|
+
* @returns Successful response without specific data.
|
|
794
928
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
795
929
|
*
|
|
796
|
-
* @see
|
|
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
|
|
975
|
+
* @returns Successful response without specific data.
|
|
842
976
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
843
977
|
*
|
|
844
|
-
* @see
|
|
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
|
-
*
|
|
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
|
|
1023
|
+
* @returns Successful response without specific data.
|
|
890
1024
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
891
1025
|
*
|
|
892
|
-
* @see
|
|
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
|
|
1060
|
+
* @returns Successful response without specific data.
|
|
927
1061
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
928
1062
|
*
|
|
929
|
-
* @see
|
|
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
|
-
/**
|
|
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"}
|
|
@@ -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
|
+
}
|