@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,27 +1,29 @@
|
|
|
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) {
|
|
7
|
-
let message = "";
|
|
7
|
+
let message = "Cannot process API request";
|
|
8
8
|
if (response.status === "err") {
|
|
9
|
-
message
|
|
9
|
+
message += `: ${response.response}`;
|
|
10
10
|
}
|
|
11
11
|
else {
|
|
12
12
|
if ("statuses" in response.response.data) {
|
|
13
|
-
|
|
13
|
+
const errors = response.response.data.statuses
|
|
14
14
|
.reduce((acc, status, index) => {
|
|
15
15
|
if (typeof status === "object" && "error" in status) {
|
|
16
|
-
acc.push(`
|
|
16
|
+
acc.push(`Order ${index} failed: ${status.error}`);
|
|
17
17
|
}
|
|
18
18
|
return acc;
|
|
19
|
-
}, [])
|
|
20
|
-
|
|
19
|
+
}, []);
|
|
20
|
+
if (errors.length > 0) {
|
|
21
|
+
message += `: ${errors.join(", ")}`;
|
|
22
|
+
}
|
|
21
23
|
}
|
|
22
24
|
else {
|
|
23
25
|
if (typeof response.response.data.status === "object" && "error" in response.response.data.status) {
|
|
24
|
-
message
|
|
26
|
+
message += `: ${response.response.data.status.error}`;
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
}
|
|
@@ -35,7 +37,7 @@ export class ApiRequestError extends Error {
|
|
|
35
37
|
this.name = "ApiRequestError";
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
|
-
// ———————————————Client———————————————
|
|
40
|
+
// ——————————————— Client ———————————————
|
|
39
41
|
/**
|
|
40
42
|
* Wallet client for interacting with the Hyperliquid API.
|
|
41
43
|
* @typeParam T - The transport used to connect to the Hyperliquid API.
|
|
@@ -72,10 +74,9 @@ export class WalletClient {
|
|
|
72
74
|
* ```ts
|
|
73
75
|
* import * as hl from "@nktkas/hyperliquid";
|
|
74
76
|
* import { createWalletClient, custom } from "viem";
|
|
75
|
-
* import { arbitrum } from "viem/chains";
|
|
76
77
|
*
|
|
77
78
|
* const [account] = await window.ethereum.request({ method: "eth_requestAccounts" });
|
|
78
|
-
* const wallet = createWalletClient({ account,
|
|
79
|
+
* const wallet = createWalletClient({ account, transport: custom(window.ethereum) });
|
|
79
80
|
*
|
|
80
81
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
81
82
|
* const client = new hl.WalletClient({ wallet, transport });
|
|
@@ -120,10 +121,10 @@ export class WalletClient {
|
|
|
120
121
|
* Approve an agent to sign on behalf of the master or sub-accounts.
|
|
121
122
|
* @param args - The parameters for the request.
|
|
122
123
|
* @param signal - An optional abort signal
|
|
123
|
-
* @returns
|
|
124
|
+
* @returns Successful response without specific data.
|
|
124
125
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
125
126
|
*
|
|
126
|
-
* @see
|
|
127
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#approve-an-api-wallet
|
|
127
128
|
* @example
|
|
128
129
|
* ```ts
|
|
129
130
|
* import * as hl from "@nktkas/hyperliquid";
|
|
@@ -143,7 +144,7 @@ export class WalletClient {
|
|
|
143
144
|
...args,
|
|
144
145
|
type: "approveAgent",
|
|
145
146
|
hyperliquidChain: this.isTestnet ? "Testnet" : "Mainnet",
|
|
146
|
-
signatureChainId: args.signatureChainId ?? this.isTestnet ? "0x66eee" : "0xa4b1",
|
|
147
|
+
signatureChainId: args.signatureChainId ?? (this.isTestnet ? "0x66eee" : "0xa4b1"),
|
|
147
148
|
nonce: args.nonce ?? Date.now(),
|
|
148
149
|
};
|
|
149
150
|
const signature = await signUserSignedAction(this.wallet, action, {
|
|
@@ -167,10 +168,10 @@ export class WalletClient {
|
|
|
167
168
|
* Approve a max fee rate for a builder address.
|
|
168
169
|
* @param args - The parameters for the request.
|
|
169
170
|
* @param signal - An optional abort signal.
|
|
170
|
-
* @returns
|
|
171
|
+
* @returns Successful response without specific data.
|
|
171
172
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
172
173
|
*
|
|
173
|
-
* @see
|
|
174
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#approve-a-builder-fee
|
|
174
175
|
* @example
|
|
175
176
|
* ```ts
|
|
176
177
|
* import * as hl from "@nktkas/hyperliquid";
|
|
@@ -190,7 +191,7 @@ export class WalletClient {
|
|
|
190
191
|
...args,
|
|
191
192
|
type: "approveBuilderFee",
|
|
192
193
|
hyperliquidChain: this.isTestnet ? "Testnet" : "Mainnet",
|
|
193
|
-
signatureChainId: args.signatureChainId ?? this.isTestnet ? "0x66eee" : "0xa4b1",
|
|
194
|
+
signatureChainId: args.signatureChainId ?? (this.isTestnet ? "0x66eee" : "0xa4b1"),
|
|
194
195
|
nonce: args.nonce ?? Date.now(),
|
|
195
196
|
};
|
|
196
197
|
const signature = await signUserSignedAction(this.wallet, action, {
|
|
@@ -214,10 +215,10 @@ export class WalletClient {
|
|
|
214
215
|
* Modify multiple orders.
|
|
215
216
|
* @param args - The parameters for the request.
|
|
216
217
|
* @param signal - An optional abort signal.
|
|
217
|
-
* @returns
|
|
218
|
+
* @returns Successful variant of {@link OrderResponse} without error statuses.
|
|
218
219
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
219
220
|
*
|
|
220
|
-
* @see
|
|
221
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders
|
|
221
222
|
* @example
|
|
222
223
|
* ```ts
|
|
223
224
|
* import * as hl from "@nktkas/hyperliquid";
|
|
@@ -265,10 +266,10 @@ export class WalletClient {
|
|
|
265
266
|
* Cancel order(s).
|
|
266
267
|
* @param args - The parameters for the request.
|
|
267
268
|
* @param signal - An optional abort signal.
|
|
268
|
-
* @returns
|
|
269
|
+
* @returns Successful variant of {@link CancelResponse} without error statuses.
|
|
269
270
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
270
271
|
*
|
|
271
|
-
* @see
|
|
272
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s
|
|
272
273
|
* @example
|
|
273
274
|
* ```ts
|
|
274
275
|
* import * as hl from "@nktkas/hyperliquid";
|
|
@@ -301,13 +302,57 @@ export class WalletClient {
|
|
|
301
302
|
return response;
|
|
302
303
|
}
|
|
303
304
|
/**
|
|
304
|
-
*
|
|
305
|
+
* Deposit into staking balance.
|
|
305
306
|
* @param args - The parameters for the request.
|
|
306
307
|
* @param signal - An optional abort signal.
|
|
307
|
-
* @returns
|
|
308
|
+
* @returns Successful response without specific data.
|
|
308
309
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
309
310
|
*
|
|
310
|
-
* @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
|
|
311
356
|
* @example
|
|
312
357
|
* ```ts
|
|
313
358
|
* import * as hl from "@nktkas/hyperliquid";
|
|
@@ -339,13 +384,58 @@ export class WalletClient {
|
|
|
339
384
|
this._validateResponse(response);
|
|
340
385
|
return response;
|
|
341
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
|
+
}
|
|
342
431
|
/**
|
|
343
432
|
* Create a sub-account.
|
|
344
433
|
* @param args - The parameters for the request.
|
|
345
434
|
* @param signal - An optional abort signal.
|
|
346
|
-
* @returns
|
|
435
|
+
* @returns Response for creating a sub-account.
|
|
347
436
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
348
437
|
*
|
|
438
|
+
* @see null - no documentation
|
|
349
439
|
* @example
|
|
350
440
|
* ```ts
|
|
351
441
|
* import * as hl from "@nktkas/hyperliquid";
|
|
@@ -355,9 +445,7 @@ export class WalletClient {
|
|
|
355
445
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
356
446
|
* const client = new hl.WalletClient({ wallet, transport });
|
|
357
447
|
*
|
|
358
|
-
* const result = await client.createSubAccount({
|
|
359
|
-
* name: "subAccountName",
|
|
360
|
-
* });
|
|
448
|
+
* const result = await client.createSubAccount({ name: "subAccountName" });
|
|
361
449
|
* ```
|
|
362
450
|
*/
|
|
363
451
|
async createSubAccount(args, signal) {
|
|
@@ -377,10 +465,10 @@ export class WalletClient {
|
|
|
377
465
|
* Modify an order.
|
|
378
466
|
* @param args - The parameters for the request.
|
|
379
467
|
* @param signal - An optional abort signal.
|
|
380
|
-
* @returns
|
|
468
|
+
* @returns Successful response without specific data.
|
|
381
469
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
382
470
|
*
|
|
383
|
-
* @see
|
|
471
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-an-order
|
|
384
472
|
* @example
|
|
385
473
|
* ```ts
|
|
386
474
|
* import * as hl from "@nktkas/hyperliquid";
|
|
@@ -426,10 +514,10 @@ export class WalletClient {
|
|
|
426
514
|
* Place an order(s).
|
|
427
515
|
* @param args - The parameters for the request.
|
|
428
516
|
* @param signal - An optional abort signal.
|
|
429
|
-
* @returns
|
|
517
|
+
* @returns Successful variant of {@link OrderResponse} without error statuses.
|
|
430
518
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
431
519
|
*
|
|
432
|
-
* @see
|
|
520
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-an-order
|
|
433
521
|
* @example
|
|
434
522
|
* ```ts
|
|
435
523
|
* import * as hl from "@nktkas/hyperliquid";
|
|
@@ -478,10 +566,10 @@ export class WalletClient {
|
|
|
478
566
|
* Schedule a time to cancel all open orders.
|
|
479
567
|
* @param args - The parameters for the request.
|
|
480
568
|
* @param signal - An optional abort signal.
|
|
481
|
-
* @returns
|
|
569
|
+
* @returns Successful response without specific data.
|
|
482
570
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
483
571
|
*
|
|
484
|
-
* @see
|
|
572
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#schedule-cancel-dead-mans-switch
|
|
485
573
|
* @example
|
|
486
574
|
* ```ts
|
|
487
575
|
* import * as hl from "@nktkas/hyperliquid";
|
|
@@ -491,9 +579,7 @@ export class WalletClient {
|
|
|
491
579
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
492
580
|
* const client = new hl.WalletClient({ wallet, transport });
|
|
493
581
|
*
|
|
494
|
-
* const result = await client.scheduleCancel({
|
|
495
|
-
* time: Date.now() + 3600000, // Schedule cancellation 1 hour from now
|
|
496
|
-
* });
|
|
582
|
+
* const result = await client.scheduleCancel({ time: Date.now() + 3600000 });
|
|
497
583
|
* ```
|
|
498
584
|
*/
|
|
499
585
|
async scheduleCancel(args = {}, signal) {
|
|
@@ -514,9 +600,10 @@ export class WalletClient {
|
|
|
514
600
|
* Set a referral code.
|
|
515
601
|
* @param args - The parameters for the request.
|
|
516
602
|
* @param signal - An optional abort signal.
|
|
517
|
-
* @returns
|
|
603
|
+
* @returns Successful response without specific data.
|
|
518
604
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
519
605
|
*
|
|
606
|
+
* @see null - no documentation
|
|
520
607
|
* @example
|
|
521
608
|
* ```ts
|
|
522
609
|
* import * as hl from "@nktkas/hyperliquid";
|
|
@@ -526,9 +613,7 @@ export class WalletClient {
|
|
|
526
613
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
527
614
|
* const client = new hl.WalletClient({ wallet, transport });
|
|
528
615
|
*
|
|
529
|
-
* const result = await client.setReferrer({
|
|
530
|
-
* code: "TEST",
|
|
531
|
-
* });
|
|
616
|
+
* const result = await client.setReferrer({ code: "TEST" });
|
|
532
617
|
* ```
|
|
533
618
|
*/
|
|
534
619
|
async setReferrer(args, signal) {
|
|
@@ -548,10 +633,10 @@ export class WalletClient {
|
|
|
548
633
|
* Transfer a spot asset on L1 to another address.
|
|
549
634
|
* @param args - The parameters for the request.
|
|
550
635
|
* @param signal - An optional abort signal.
|
|
551
|
-
* @returns
|
|
636
|
+
* @returns Successful response without specific data.
|
|
552
637
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
553
638
|
*
|
|
554
|
-
* @see
|
|
639
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#l1-spot-transfer
|
|
555
640
|
* @example
|
|
556
641
|
* ```ts
|
|
557
642
|
* import * as hl from "@nktkas/hyperliquid";
|
|
@@ -573,7 +658,7 @@ export class WalletClient {
|
|
|
573
658
|
...args,
|
|
574
659
|
type: "spotSend",
|
|
575
660
|
hyperliquidChain: this.isTestnet ? "Testnet" : "Mainnet",
|
|
576
|
-
signatureChainId: args.signatureChainId ?? this.isTestnet ? "0x66eee" : "0xa4b1",
|
|
661
|
+
signatureChainId: args.signatureChainId ?? (this.isTestnet ? "0x66eee" : "0xa4b1"),
|
|
577
662
|
time: args.time ?? Date.now(),
|
|
578
663
|
};
|
|
579
664
|
const signature = await signUserSignedAction(this.wallet, action, {
|
|
@@ -598,9 +683,10 @@ export class WalletClient {
|
|
|
598
683
|
* Transfer between sub-accounts.
|
|
599
684
|
* @param args - The parameters for the request.
|
|
600
685
|
* @param signal - An optional abort signal.
|
|
601
|
-
* @returns
|
|
686
|
+
* @returns Successful response without specific data.
|
|
602
687
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
603
688
|
*
|
|
689
|
+
* @see null - no documentation
|
|
604
690
|
* @example
|
|
605
691
|
* ```ts
|
|
606
692
|
* import * as hl from "@nktkas/hyperliquid";
|
|
@@ -630,14 +716,64 @@ export class WalletClient {
|
|
|
630
716
|
this._validateResponse(response);
|
|
631
717
|
return response;
|
|
632
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
|
+
}
|
|
633
769
|
/**
|
|
634
770
|
* Cancel a TWAP order.
|
|
635
771
|
* @param args - The parameters for the request.
|
|
636
772
|
* @param signal - An optional abort signal.
|
|
637
|
-
* @returns
|
|
773
|
+
* @returns Successful variant of {@link TwapCancelResponse} without error status.
|
|
638
774
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
639
775
|
*
|
|
640
|
-
* @see
|
|
776
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-a-twap-order
|
|
641
777
|
* @example
|
|
642
778
|
* ```ts
|
|
643
779
|
* import * as hl from "@nktkas/hyperliquid";
|
|
@@ -671,10 +807,10 @@ export class WalletClient {
|
|
|
671
807
|
* Place a TWAP order.
|
|
672
808
|
* @param args - The parameters for the request.
|
|
673
809
|
* @param signal - An optional abort signal.
|
|
674
|
-
* @returns
|
|
810
|
+
* @returns Successful variant of {@link TwapOrderResponse} without error status.
|
|
675
811
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
676
812
|
*
|
|
677
|
-
* @see
|
|
813
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-a-twap-order
|
|
678
814
|
* @example
|
|
679
815
|
* ```ts
|
|
680
816
|
* import * as hl from "@nktkas/hyperliquid";
|
|
@@ -712,10 +848,10 @@ export class WalletClient {
|
|
|
712
848
|
* Update isolated margin for a position.
|
|
713
849
|
* @param args - The parameters for the request.
|
|
714
850
|
* @param signal - An optional abort signal.
|
|
715
|
-
* @returns
|
|
851
|
+
* @returns Successful response without specific data.
|
|
716
852
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
717
853
|
*
|
|
718
|
-
* @see
|
|
854
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#update-isolated-margin
|
|
719
855
|
* @example
|
|
720
856
|
* ```ts
|
|
721
857
|
* import * as hl from "@nktkas/hyperliquid";
|
|
@@ -750,10 +886,10 @@ export class WalletClient {
|
|
|
750
886
|
* Update leverage for cross or isolated margin.
|
|
751
887
|
* @param args - The parameters for the request.
|
|
752
888
|
* @param signal - An optional abort signal.
|
|
753
|
-
* @returns
|
|
889
|
+
* @returns Successful response without specific data.
|
|
754
890
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
755
891
|
*
|
|
756
|
-
* @see
|
|
892
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#update-leverage
|
|
757
893
|
* @example
|
|
758
894
|
* ```ts
|
|
759
895
|
* import * as hl from "@nktkas/hyperliquid";
|
|
@@ -788,10 +924,10 @@ export class WalletClient {
|
|
|
788
924
|
* Transfer funds between Spot and Perp accounts.
|
|
789
925
|
* @param args - The parameters for the request.
|
|
790
926
|
* @param signal - An optional abort signal.
|
|
791
|
-
* @returns
|
|
927
|
+
* @returns Successful response without specific data.
|
|
792
928
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
793
929
|
*
|
|
794
|
-
* @see
|
|
930
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#transfer-from-spot-account-to-perp-account-and-vice-versa
|
|
795
931
|
* @example
|
|
796
932
|
* ```ts
|
|
797
933
|
* import * as hl from "@nktkas/hyperliquid";
|
|
@@ -812,7 +948,7 @@ export class WalletClient {
|
|
|
812
948
|
...args,
|
|
813
949
|
type: "usdClassTransfer",
|
|
814
950
|
hyperliquidChain: this.isTestnet ? "Testnet" : "Mainnet",
|
|
815
|
-
signatureChainId: args.signatureChainId ?? this.isTestnet ? "0x66eee" : "0xa4b1",
|
|
951
|
+
signatureChainId: args.signatureChainId ?? (this.isTestnet ? "0x66eee" : "0xa4b1"),
|
|
816
952
|
nonce: args.nonce ?? Date.now(),
|
|
817
953
|
};
|
|
818
954
|
const signature = await signUserSignedAction(this.wallet, action, {
|
|
@@ -836,10 +972,10 @@ export class WalletClient {
|
|
|
836
972
|
* Transfer USDC on L1 to another address.
|
|
837
973
|
* @param args - The parameters for the request.
|
|
838
974
|
* @param signal - An optional abort signal.
|
|
839
|
-
* @returns
|
|
975
|
+
* @returns Successful response without specific data.
|
|
840
976
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
841
977
|
*
|
|
842
|
-
* @see
|
|
978
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#l1-usdc-transfer
|
|
843
979
|
* @example
|
|
844
980
|
* ```ts
|
|
845
981
|
* import * as hl from "@nktkas/hyperliquid";
|
|
@@ -860,7 +996,7 @@ export class WalletClient {
|
|
|
860
996
|
...args,
|
|
861
997
|
type: "usdSend",
|
|
862
998
|
hyperliquidChain: this.isTestnet ? "Testnet" : "Mainnet",
|
|
863
|
-
signatureChainId: args.signatureChainId ?? this.isTestnet ? "0x66eee" : "0xa4b1",
|
|
999
|
+
signatureChainId: args.signatureChainId ?? (this.isTestnet ? "0x66eee" : "0xa4b1"),
|
|
864
1000
|
time: args.time ?? Date.now(),
|
|
865
1001
|
};
|
|
866
1002
|
const signature = await signUserSignedAction(this.wallet, action, {
|
|
@@ -881,13 +1017,13 @@ export class WalletClient {
|
|
|
881
1017
|
return response;
|
|
882
1018
|
}
|
|
883
1019
|
/**
|
|
884
|
-
*
|
|
1020
|
+
* Add or remove funds from a vault.
|
|
885
1021
|
* @param args - The parameters for the request.
|
|
886
1022
|
* @param signal - An optional abort signal.
|
|
887
|
-
* @returns
|
|
1023
|
+
* @returns Successful response without specific data.
|
|
888
1024
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
889
1025
|
*
|
|
890
|
-
* @see
|
|
1026
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#deposit-or-withdraw-from-a-vault
|
|
891
1027
|
* @example
|
|
892
1028
|
* ```ts
|
|
893
1029
|
* import * as hl from "@nktkas/hyperliquid";
|
|
@@ -921,10 +1057,10 @@ export class WalletClient {
|
|
|
921
1057
|
* Initiate a withdrawal request.
|
|
922
1058
|
* @param args - The parameters for the request.
|
|
923
1059
|
* @param signal - An optional abort signal.
|
|
924
|
-
* @returns
|
|
1060
|
+
* @returns Successful response without specific data.
|
|
925
1061
|
* @throws {ApiRequestError} When the API returns an error response.
|
|
926
1062
|
*
|
|
927
|
-
* @see
|
|
1063
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#initiate-a-withdrawal-request
|
|
928
1064
|
* @example
|
|
929
1065
|
* ```ts
|
|
930
1066
|
* import * as hl from "@nktkas/hyperliquid";
|
|
@@ -945,7 +1081,7 @@ export class WalletClient {
|
|
|
945
1081
|
...args,
|
|
946
1082
|
type: "withdraw3",
|
|
947
1083
|
hyperliquidChain: this.isTestnet ? "Testnet" : "Mainnet",
|
|
948
|
-
signatureChainId: args.signatureChainId ?? this.isTestnet ? "0x66eee" : "0xa4b1",
|
|
1084
|
+
signatureChainId: args.signatureChainId ?? (this.isTestnet ? "0x66eee" : "0xa4b1"),
|
|
949
1085
|
time: args.time ?? Date.now(),
|
|
950
1086
|
};
|
|
951
1087
|
const signature = await signUserSignedAction(this.wallet, action, {
|
|
@@ -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"}
|
|
@@ -11,7 +11,10 @@ export class HttpRequestError extends TransportError {
|
|
|
11
11
|
* @param responseBody - The raw response body content, if available.
|
|
12
12
|
*/
|
|
13
13
|
constructor(response, responseBody) {
|
|
14
|
-
|
|
14
|
+
let message = `HTTP request failed: status ${response.status}`;
|
|
15
|
+
if (responseBody)
|
|
16
|
+
message += `, body "${responseBody}"`;
|
|
17
|
+
super(message);
|
|
15
18
|
Object.defineProperty(this, "response", {
|
|
16
19
|
enumerable: true,
|
|
17
20
|
configurable: true,
|
|
@@ -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
|
/**
|