@nktkas/hyperliquid 0.23.0 → 0.24.0
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/CONTRIBUTING.md +3 -2
- package/README.md +184 -186
- package/esm/mod.d.ts +2 -2
- package/esm/mod.d.ts.map +1 -1
- package/esm/src/base.d.ts +0 -5
- package/esm/src/base.d.ts.map +1 -1
- package/esm/src/clients/exchange.d.ts +430 -393
- package/esm/src/clients/exchange.d.ts.map +1 -1
- package/esm/src/clients/exchange.js +467 -927
- package/esm/src/clients/info.d.ts +330 -185
- package/esm/src/clients/info.d.ts.map +1 -1
- package/esm/src/clients/info.js +348 -334
- package/esm/src/clients/multiSign.d.ts +14 -1184
- package/esm/src/clients/multiSign.d.ts.map +1 -1
- package/esm/src/clients/multiSign.js +37 -2004
- package/esm/src/clients/subscription.d.ts +95 -93
- package/esm/src/clients/subscription.d.ts.map +1 -1
- package/esm/src/clients/subscription.js +101 -146
- package/esm/src/signing/_signTypedData/ethers.d.ts +16 -4
- package/esm/src/signing/_signTypedData/ethers.d.ts.map +1 -1
- package/esm/src/signing/_signTypedData/ethers.js +1 -1
- package/esm/src/signing/_signTypedData/mod.d.ts +12 -12
- package/esm/src/signing/_signTypedData/mod.d.ts.map +1 -1
- package/esm/src/signing/_signTypedData/mod.js +52 -24
- package/esm/src/signing/_signTypedData/private_key.d.ts +6 -5
- package/esm/src/signing/_signTypedData/private_key.d.ts.map +1 -1
- package/esm/src/signing/_signTypedData/private_key.js +40 -19
- package/esm/src/signing/_signTypedData/viem.d.ts +27 -6
- package/esm/src/signing/_signTypedData/viem.d.ts.map +1 -1
- package/esm/src/signing/_signTypedData/viem.js +1 -1
- package/esm/src/signing/_sorter.d.ts +12 -21
- package/esm/src/signing/_sorter.d.ts.map +1 -1
- package/esm/src/signing/_sorter.js +30 -63
- package/esm/src/signing/mod.d.ts +177 -127
- package/esm/src/signing/mod.d.ts.map +1 -1
- package/esm/src/signing/mod.js +182 -130
- package/esm/src/transports/base.d.ts +2 -1
- package/esm/src/transports/base.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.d.ts +3 -2
- package/esm/src/transports/http/http_transport.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.js +4 -4
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +14 -6
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/esm/src/transports/websocket/_hyperliquid_event_target.js +1 -2
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts +2 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.js +1 -0
- package/esm/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
- package/esm/src/transports/websocket/_websocket_async_request.js +17 -21
- package/esm/src/transports/websocket/websocket_transport.d.ts +4 -4
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.js +6 -6
- package/esm/src/types/exchange/requests.d.ts +492 -306
- package/esm/src/types/exchange/requests.d.ts.map +1 -1
- package/esm/src/types/exchange/responses.d.ts +105 -25
- package/esm/src/types/exchange/responses.d.ts.map +1 -1
- package/esm/src/types/explorer/requests.d.ts +3 -3
- package/esm/src/types/explorer/requests.d.ts.map +1 -1
- package/esm/src/types/explorer/responses.d.ts +1 -1
- package/esm/src/types/explorer/responses.d.ts.map +1 -1
- package/esm/src/types/info/accounts.d.ts +403 -98
- package/esm/src/types/info/accounts.d.ts.map +1 -1
- package/esm/src/types/info/assets.d.ts +131 -35
- package/esm/src/types/info/assets.d.ts.map +1 -1
- package/esm/src/types/info/markets.d.ts +35 -8
- package/esm/src/types/info/markets.d.ts.map +1 -1
- package/esm/src/types/info/orders.d.ts +62 -17
- package/esm/src/types/info/orders.d.ts.map +1 -1
- package/esm/src/types/info/requests.d.ts +194 -76
- package/esm/src/types/info/requests.d.ts.map +1 -1
- package/{script/src/types/info/delegations.d.ts → esm/src/types/info/validators.d.ts} +45 -15
- package/esm/src/types/info/validators.d.ts.map +1 -0
- package/esm/src/types/info/vaults.d.ts +32 -10
- package/esm/src/types/info/vaults.d.ts.map +1 -1
- package/esm/src/types/mod.d.ts +2 -2
- package/esm/src/types/mod.d.ts.map +1 -1
- package/esm/src/types/subscriptions/requests.d.ts +21 -66
- package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
- package/esm/src/types/subscriptions/responses.d.ts +46 -55
- package/esm/src/types/subscriptions/responses.d.ts.map +1 -1
- package/package.json +2 -3
- package/script/mod.d.ts +2 -2
- package/script/mod.d.ts.map +1 -1
- package/script/src/base.d.ts +0 -5
- package/script/src/base.d.ts.map +1 -1
- package/script/src/clients/exchange.d.ts +430 -393
- package/script/src/clients/exchange.d.ts.map +1 -1
- package/script/src/clients/exchange.js +466 -926
- package/script/src/clients/info.d.ts +330 -185
- package/script/src/clients/info.d.ts.map +1 -1
- package/script/src/clients/info.js +348 -334
- package/script/src/clients/multiSign.d.ts +14 -1184
- package/script/src/clients/multiSign.d.ts.map +1 -1
- package/script/src/clients/multiSign.js +38 -2005
- package/script/src/clients/subscription.d.ts +95 -93
- package/script/src/clients/subscription.d.ts.map +1 -1
- package/script/src/clients/subscription.js +101 -146
- package/script/src/signing/_signTypedData/ethers.d.ts +16 -4
- package/script/src/signing/_signTypedData/ethers.d.ts.map +1 -1
- package/script/src/signing/_signTypedData/ethers.js +2 -2
- package/script/src/signing/_signTypedData/mod.d.ts +12 -12
- package/script/src/signing/_signTypedData/mod.d.ts.map +1 -1
- package/script/src/signing/_signTypedData/mod.js +51 -26
- package/script/src/signing/_signTypedData/private_key.d.ts +6 -5
- package/script/src/signing/_signTypedData/private_key.d.ts.map +1 -1
- package/script/src/signing/_signTypedData/private_key.js +40 -18
- package/script/src/signing/_signTypedData/viem.d.ts +27 -6
- package/script/src/signing/_signTypedData/viem.d.ts.map +1 -1
- package/script/src/signing/_signTypedData/viem.js +2 -2
- package/script/src/signing/_sorter.d.ts +12 -21
- package/script/src/signing/_sorter.d.ts.map +1 -1
- package/script/src/signing/_sorter.js +30 -63
- package/script/src/signing/mod.d.ts +177 -127
- package/script/src/signing/mod.d.ts.map +1 -1
- package/script/src/signing/mod.js +185 -148
- package/script/src/transports/base.d.ts +2 -1
- package/script/src/transports/base.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.d.ts +3 -2
- package/script/src/transports/http/http_transport.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.js +4 -4
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +14 -6
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/script/src/transports/websocket/_hyperliquid_event_target.js +1 -2
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts +2 -1
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/script/src/transports/websocket/_reconnecting_websocket.js +1 -0
- package/script/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
- package/script/src/transports/websocket/_websocket_async_request.js +17 -21
- package/script/src/transports/websocket/websocket_transport.d.ts +4 -4
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.js +6 -6
- package/script/src/types/exchange/requests.d.ts +492 -306
- package/script/src/types/exchange/requests.d.ts.map +1 -1
- package/script/src/types/exchange/responses.d.ts +105 -25
- package/script/src/types/exchange/responses.d.ts.map +1 -1
- package/script/src/types/explorer/requests.d.ts +3 -3
- package/script/src/types/explorer/requests.d.ts.map +1 -1
- package/script/src/types/explorer/responses.d.ts +1 -1
- package/script/src/types/explorer/responses.d.ts.map +1 -1
- package/script/src/types/info/accounts.d.ts +403 -98
- package/script/src/types/info/accounts.d.ts.map +1 -1
- package/script/src/types/info/assets.d.ts +131 -35
- package/script/src/types/info/assets.d.ts.map +1 -1
- package/script/src/types/info/markets.d.ts +35 -8
- package/script/src/types/info/markets.d.ts.map +1 -1
- package/script/src/types/info/orders.d.ts +62 -17
- package/script/src/types/info/orders.d.ts.map +1 -1
- package/script/src/types/info/requests.d.ts +194 -76
- package/script/src/types/info/requests.d.ts.map +1 -1
- package/{esm/src/types/info/delegations.d.ts → script/src/types/info/validators.d.ts} +45 -15
- package/script/src/types/info/validators.d.ts.map +1 -0
- package/script/src/types/info/vaults.d.ts +32 -10
- package/script/src/types/info/vaults.d.ts.map +1 -1
- package/script/src/types/mod.d.ts +2 -2
- package/script/src/types/mod.d.ts.map +1 -1
- package/script/src/types/subscriptions/requests.d.ts +21 -66
- package/script/src/types/subscriptions/requests.d.ts.map +1 -1
- package/script/src/types/subscriptions/responses.d.ts +46 -55
- package/script/src/types/subscriptions/responses.d.ts.map +1 -1
- package/esm/src/signing/_signTypedData/window.d.ts +0 -29
- package/esm/src/signing/_signTypedData/window.d.ts.map +0 -1
- package/esm/src/signing/_signTypedData/window.js +0 -30
- package/esm/src/types/info/delegations.d.ts.map +0 -1
- package/script/src/signing/_signTypedData/window.d.ts +0 -29
- package/script/src/signing/_signTypedData/window.d.ts.map +0 -1
- package/script/src/signing/_signTypedData/window.js +0 -34
- package/script/src/types/info/delegations.d.ts.map +0 -1
- /package/esm/src/types/info/{delegations.js → validators.js} +0 -0
- /package/script/src/types/info/{delegations.js → validators.js} +0 -0
package/esm/src/signing/mod.js
CHANGED
|
@@ -6,43 +6,55 @@
|
|
|
6
6
|
* ```ts
|
|
7
7
|
* import { actionSorter, signL1Action } from "@nktkas/hyperliquid/signing";
|
|
8
8
|
*
|
|
9
|
-
* const privateKey = "0x..."; //
|
|
9
|
+
* const privateKey = "0x..."; // `viem`, `ethers`, or private key directly`
|
|
10
10
|
*
|
|
11
|
+
* const action = actionSorter.cancel({
|
|
12
|
+
* type: "cancel",
|
|
13
|
+
* cancels: [
|
|
14
|
+
* { a: 0, o: 12345 },
|
|
15
|
+
* ],
|
|
16
|
+
* });
|
|
11
17
|
* const nonce = Date.now();
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* wallet: privateKey,
|
|
21
|
-
* action: actionSorter[action.type](action),
|
|
22
|
-
* nonce,
|
|
18
|
+
*
|
|
19
|
+
* const signature = await signL1Action({ wallet: privateKey, action, nonce });
|
|
20
|
+
*
|
|
21
|
+
* // Send the signed action to the Hyperliquid API
|
|
22
|
+
* const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
23
|
+
* method: "POST",
|
|
24
|
+
* headers: { "Content-Type": "application/json" },
|
|
25
|
+
* body: JSON.stringify({ action, signature, nonce }), // recommended to send the same formatted action
|
|
23
26
|
* });
|
|
27
|
+
* const body = await response.json();
|
|
24
28
|
* ```
|
|
25
29
|
*
|
|
26
30
|
* @example Signing a user-signed action
|
|
27
31
|
* ```ts
|
|
28
|
-
* import { signUserSignedAction, userSignedActionEip712Types } from "@nktkas/hyperliquid/signing";
|
|
32
|
+
* import { actionSorter, signUserSignedAction, userSignedActionEip712Types } from "@nktkas/hyperliquid/signing";
|
|
29
33
|
*
|
|
30
|
-
* const privateKey = "0x..."; //
|
|
34
|
+
* const privateKey = "0x..."; // `viem`, `ethers`, or private key directly`
|
|
31
35
|
*
|
|
32
|
-
* const action = {
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* }
|
|
36
|
+
* const action = actionSorter.approveAgent({
|
|
37
|
+
* type: "approveAgent",
|
|
38
|
+
* signatureChainId: "0x66eee",
|
|
39
|
+
* hyperliquidChain: "Mainnet",
|
|
40
|
+
* agentAddress: "0x...",
|
|
41
|
+
* agentName: "Agent",
|
|
42
|
+
* nonce: Date.now(),
|
|
43
|
+
* });
|
|
40
44
|
*
|
|
41
45
|
* const signature = await signUserSignedAction({
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
46
|
+
* wallet: privateKey,
|
|
47
|
+
* action,
|
|
48
|
+
* types: userSignedActionEip712Types[action.type],
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* // Send the signed action to the Hyperliquid API
|
|
52
|
+
* const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
53
|
+
* method: "POST",
|
|
54
|
+
* headers: { "Content-Type": "application/json" },
|
|
55
|
+
* body: JSON.stringify({ action, signature, nonce: action.nonce }), // recommended to send the same formatted action
|
|
45
56
|
* });
|
|
57
|
+
* const body = await response.json();
|
|
46
58
|
* ```
|
|
47
59
|
*
|
|
48
60
|
* @example Signing a multi-signature action
|
|
@@ -50,36 +62,57 @@
|
|
|
50
62
|
* import { actionSorter, signL1Action, signMultiSigAction } from "@nktkas/hyperliquid/signing";
|
|
51
63
|
* import { privateKeyToAccount } from "viem/accounts";
|
|
52
64
|
*
|
|
53
|
-
* const wallet = privateKeyToAccount("0x..."); // or `ethers`, private key
|
|
65
|
+
* const wallet = privateKeyToAccount("0x..."); // or `ethers`, private key directly
|
|
54
66
|
* const multiSigUser = "0x...";
|
|
55
67
|
*
|
|
68
|
+
* const action = actionSorter.scheduleCancel({
|
|
69
|
+
* type: "scheduleCancel",
|
|
70
|
+
* time: Date.now() + 10000,
|
|
71
|
+
* });
|
|
56
72
|
* const nonce = Date.now();
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* const signature = await signL1Action({
|
|
64
|
-
* wallet,
|
|
65
|
-
* action: [multiSigUser.toLowerCase(), wallet.address.toLowerCase(), actionSorter[action.type](action)],
|
|
73
|
+
*
|
|
74
|
+
* // Create the required number of signatures
|
|
75
|
+
* const signatures = await Promise.all(["0x...", "0x..."].map(async (signerPrivKey) => {
|
|
76
|
+
* return await signL1Action({
|
|
77
|
+
* wallet: signerPrivKey as `0x${string}`,
|
|
78
|
+
* action: [multiSigUser.toLowerCase(), wallet.address.toLowerCase(), action],
|
|
66
79
|
* nonce,
|
|
67
|
-
*
|
|
80
|
+
* });
|
|
81
|
+
* }));
|
|
82
|
+
*
|
|
83
|
+
* // or user-signed action
|
|
84
|
+
* // const signatures = await Promise.all(["0x...", "0x..."].map(async (signerPrivKey) => {
|
|
85
|
+
* // return await signUserSignedAction({
|
|
86
|
+
* // wallet: signerPrivKey as `0x${string}`,
|
|
87
|
+
* // action: {
|
|
88
|
+
* // ...action,
|
|
89
|
+
* // payloadMultiSigUser: multiSigUser,
|
|
90
|
+
* // outerSigner: wallet.address,
|
|
91
|
+
* // },
|
|
92
|
+
* // types: userSignedActionEip712Types[action.type],
|
|
93
|
+
* // });
|
|
94
|
+
* // }));
|
|
68
95
|
*
|
|
69
96
|
* // Then use signatures in the multi-sig action
|
|
70
|
-
* const
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
97
|
+
* const multiSigAction = actionSorter.multiSig({
|
|
98
|
+
* type: "multiSig",
|
|
99
|
+
* signatureChainId: "0x66eee",
|
|
100
|
+
* signatures,
|
|
101
|
+
* payload: {
|
|
102
|
+
* multiSigUser,
|
|
103
|
+
* outerSigner: wallet.address,
|
|
104
|
+
* action,
|
|
105
|
+
* },
|
|
106
|
+
* });
|
|
107
|
+
* const multiSigSignature = await signMultiSigAction({ wallet, action: multiSigAction, nonce });
|
|
108
|
+
*
|
|
109
|
+
* // Send the multi-sig action to the Hyperliquid API
|
|
110
|
+
* const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
111
|
+
* method: "POST",
|
|
112
|
+
* headers: { "Content-Type": "application/json" },
|
|
113
|
+
* body: JSON.stringify({ action: multiSigAction, signature: multiSigSignature, nonce }), // recommended to send the same formatted action
|
|
82
114
|
* });
|
|
115
|
+
* const body = await response.json();
|
|
83
116
|
* ```
|
|
84
117
|
*
|
|
85
118
|
* @module
|
|
@@ -87,29 +120,24 @@
|
|
|
87
120
|
import { keccak_256 } from "@noble/hashes/sha3";
|
|
88
121
|
import { etc } from "@noble/secp256k1";
|
|
89
122
|
import { encode as encodeMsgpack } from "@msgpack/msgpack";
|
|
90
|
-
import {
|
|
91
|
-
|
|
92
|
-
export
|
|
123
|
+
import { getWalletAddress, getWalletChainId, signTypedData, } from "./_signTypedData/mod.js";
|
|
124
|
+
import { actionSorter, userSignedActionEip712Types } from "./_sorter.js";
|
|
125
|
+
export { actionSorter, getWalletAddress, getWalletChainId, userSignedActionEip712Types, };
|
|
93
126
|
/**
|
|
94
127
|
* Create a hash of the L1 action.
|
|
95
128
|
* @example
|
|
96
129
|
* ```ts
|
|
97
130
|
* import { actionSorter, createL1ActionHash } from "@nktkas/hyperliquid/signing";
|
|
98
131
|
*
|
|
99
|
-
* const action = {
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* }
|
|
132
|
+
* const action = actionSorter.cancel({
|
|
133
|
+
* type: "cancel",
|
|
134
|
+
* cancels: [
|
|
135
|
+
* { a: 0, o: 12345 },
|
|
136
|
+
* ],
|
|
137
|
+
* });
|
|
105
138
|
* const nonce = Date.now();
|
|
106
139
|
*
|
|
107
|
-
* const actionHash = createL1ActionHash({
|
|
108
|
-
* action: actionSorter[action.type](action),
|
|
109
|
-
* nonce,
|
|
110
|
-
* vaultAddress: "0x...", // optional
|
|
111
|
-
* expiresAfter: Date.now() + 10_000, // optional
|
|
112
|
-
* });
|
|
140
|
+
* const actionHash = createL1ActionHash({ action, nonce });
|
|
113
141
|
* ```
|
|
114
142
|
*/
|
|
115
143
|
export function createL1ActionHash(args) {
|
|
@@ -140,27 +168,23 @@ function toUint64Bytes(n) {
|
|
|
140
168
|
* ```ts
|
|
141
169
|
* import { actionSorter, signL1Action } from "@nktkas/hyperliquid/signing";
|
|
142
170
|
*
|
|
143
|
-
* const privateKey = "0x..."; //
|
|
171
|
+
* const privateKey = "0x..."; // `viem`, `ethers`, or private key directly`
|
|
144
172
|
*
|
|
145
|
-
* const
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* ],
|
|
151
|
-
* } as const;
|
|
152
|
-
*
|
|
153
|
-
* const signature = await signL1Action({
|
|
154
|
-
* wallet: privateKey,
|
|
155
|
-
* action: actionSorter[action.type](action),
|
|
156
|
-
* nonce,
|
|
173
|
+
* const action = actionSorter.cancel({
|
|
174
|
+
* type: "cancel",
|
|
175
|
+
* cancels: [
|
|
176
|
+
* { a: 0, o: 12345 },
|
|
177
|
+
* ],
|
|
157
178
|
* });
|
|
179
|
+
* const nonce = Date.now();
|
|
180
|
+
*
|
|
181
|
+
* const signature = await signL1Action({ wallet: privateKey, action, nonce });
|
|
158
182
|
*
|
|
159
183
|
* // Send the signed action to the Hyperliquid API
|
|
160
184
|
* const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
185
|
+
* method: "POST",
|
|
186
|
+
* headers: { "Content-Type": "application/json" },
|
|
187
|
+
* body: JSON.stringify({ action, signature, nonce }), // recommended to send the same formatted action
|
|
164
188
|
* });
|
|
165
189
|
* const body = await response.json();
|
|
166
190
|
* ```
|
|
@@ -194,36 +218,46 @@ export async function signL1Action(args) {
|
|
|
194
218
|
* Sign a user-signed action.
|
|
195
219
|
* @example
|
|
196
220
|
* ```ts
|
|
197
|
-
* import { signUserSignedAction, userSignedActionEip712Types } from "@nktkas/hyperliquid/signing";
|
|
221
|
+
* import { actionSorter, signUserSignedAction, userSignedActionEip712Types } from "@nktkas/hyperliquid/signing";
|
|
198
222
|
*
|
|
199
|
-
* const privateKey = "0x..."; //
|
|
223
|
+
* const privateKey = "0x..."; // `viem`, `ethers`, or private key directly`
|
|
200
224
|
*
|
|
201
|
-
* const action = {
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
* }
|
|
225
|
+
* const action = actionSorter.approveAgent({
|
|
226
|
+
* type: "approveAgent",
|
|
227
|
+
* signatureChainId: "0x66eee",
|
|
228
|
+
* hyperliquidChain: "Mainnet",
|
|
229
|
+
* agentAddress: "0x...",
|
|
230
|
+
* agentName: "Agent",
|
|
231
|
+
* nonce: Date.now(),
|
|
232
|
+
* });
|
|
209
233
|
*
|
|
210
234
|
* const signature = await signUserSignedAction({
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
235
|
+
* wallet: privateKey,
|
|
236
|
+
* action,
|
|
237
|
+
* types: userSignedActionEip712Types[action.type],
|
|
214
238
|
* });
|
|
215
239
|
*
|
|
216
240
|
* // Send the signed action to the Hyperliquid API
|
|
217
241
|
* const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
242
|
+
* method: "POST",
|
|
243
|
+
* headers: { "Content-Type": "application/json" },
|
|
244
|
+
* body: JSON.stringify({ action, signature, nonce: action.nonce }), // recommended to send the same formatted action
|
|
221
245
|
* });
|
|
222
246
|
* const body = await response.json();
|
|
223
247
|
* ```
|
|
224
248
|
*/
|
|
225
249
|
export async function signUserSignedAction(args) {
|
|
226
|
-
|
|
250
|
+
let { wallet, action, types } = args;
|
|
251
|
+
if (action.type === "approveAgent" && !action.agentName) { // special case for `approveAgent`
|
|
252
|
+
action = { ...action, agentName: "" }; // set to empty string instead of null
|
|
253
|
+
}
|
|
254
|
+
if ("payloadMultiSigUser" in action && "outerSigner" in action) { // special case for multi-sign payload
|
|
255
|
+
types = structuredClone(types); // for safe mutation
|
|
256
|
+
Object.values(types)[0].splice(// array mutation
|
|
257
|
+
1, // after `hyperliquidChain`
|
|
258
|
+
0, // do not remove any elements
|
|
259
|
+
{ name: "payloadMultiSigUser", type: "address" }, { name: "outerSigner", type: "address" });
|
|
260
|
+
}
|
|
227
261
|
return await signTypedData({
|
|
228
262
|
wallet,
|
|
229
263
|
domain: {
|
|
@@ -244,43 +278,67 @@ export async function signUserSignedAction(args) {
|
|
|
244
278
|
* import { actionSorter, signL1Action, signMultiSigAction } from "@nktkas/hyperliquid/signing";
|
|
245
279
|
* import { privateKeyToAccount } from "viem/accounts";
|
|
246
280
|
*
|
|
247
|
-
* const wallet = privateKeyToAccount("0x..."); // or
|
|
281
|
+
* const wallet = privateKeyToAccount("0x..."); // or ethers, private key directly
|
|
248
282
|
* const multiSigUser = "0x...";
|
|
249
283
|
*
|
|
284
|
+
* const action = actionSorter.scheduleCancel({
|
|
285
|
+
* type: "scheduleCancel",
|
|
286
|
+
* time: Date.now() + 10000,
|
|
287
|
+
* });
|
|
250
288
|
* const nonce = Date.now();
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
* const signature = await signL1Action({
|
|
258
|
-
* wallet,
|
|
259
|
-
* action: [multiSigUser.toLowerCase(), wallet.address.toLowerCase(), actionSorter[action.type](action)],
|
|
289
|
+
*
|
|
290
|
+
* // Create the required number of signatures
|
|
291
|
+
* const signatures = await Promise.all(["0x...", "0x..."].map(async (signerPrivKey) => {
|
|
292
|
+
* return await signL1Action({
|
|
293
|
+
* wallet: signerPrivKey as `0x${string}`,
|
|
294
|
+
* action: [multiSigUser.toLowerCase(), wallet.address.toLowerCase(), action],
|
|
260
295
|
* nonce,
|
|
261
|
-
*
|
|
296
|
+
* });
|
|
297
|
+
* }));
|
|
298
|
+
*
|
|
299
|
+
* // or user-signed action
|
|
300
|
+
* // const signatures = await Promise.all(["0x...", "0x..."].map(async (signerPrivKey) => {
|
|
301
|
+
* // return await signUserSignedAction({
|
|
302
|
+
* // wallet: signerPrivKey as `0x${string}`,
|
|
303
|
+
* // action: {
|
|
304
|
+
* // ...action,
|
|
305
|
+
* // payloadMultiSigUser: multiSigUser,
|
|
306
|
+
* // outerSigner: wallet.address,
|
|
307
|
+
* // },
|
|
308
|
+
* // types: userSignedActionEip712Types[action.type],
|
|
309
|
+
* // });
|
|
310
|
+
* // }));
|
|
262
311
|
*
|
|
263
312
|
* // Then use signatures in the multi-sig action
|
|
264
|
-
* const
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
313
|
+
* const multiSigAction = actionSorter.multiSig({
|
|
314
|
+
* type: "multiSig",
|
|
315
|
+
* signatureChainId: "0x66eee",
|
|
316
|
+
* signatures,
|
|
317
|
+
* payload: {
|
|
318
|
+
* multiSigUser,
|
|
319
|
+
* outerSigner: wallet.address,
|
|
320
|
+
* action,
|
|
321
|
+
* },
|
|
322
|
+
* });
|
|
323
|
+
* const multiSigSignature = await signMultiSigAction({ wallet, action: multiSigAction, nonce });
|
|
324
|
+
*
|
|
325
|
+
* // Send the multi-sig action to the Hyperliquid API
|
|
326
|
+
* const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
327
|
+
* method: "POST",
|
|
328
|
+
* headers: { "Content-Type": "application/json" },
|
|
329
|
+
* body: JSON.stringify({ action: multiSigAction, signature: multiSigSignature, nonce }), // recommended to send the same formatted action
|
|
276
330
|
* });
|
|
331
|
+
* const body = await response.json();
|
|
277
332
|
* ```
|
|
278
333
|
*/
|
|
279
334
|
export async function signMultiSigAction(args) {
|
|
280
|
-
|
|
335
|
+
let { wallet, action, nonce, isTestnet = false, vaultAddress, expiresAfter, } = args;
|
|
336
|
+
if ("type" in action) {
|
|
337
|
+
action = structuredClone(action); // for safe mutation
|
|
338
|
+
delete action.type;
|
|
339
|
+
}
|
|
281
340
|
const multiSigActionHash = createL1ActionHash({ action, nonce, vaultAddress, expiresAfter });
|
|
282
341
|
const message = {
|
|
283
|
-
signatureChainId: action.signatureChainId,
|
|
284
342
|
hyperliquidChain: isTestnet ? "Testnet" : "Mainnet",
|
|
285
343
|
multiSigActionHash,
|
|
286
344
|
nonce,
|
|
@@ -290,17 +348,11 @@ export async function signMultiSigAction(args) {
|
|
|
290
348
|
domain: {
|
|
291
349
|
name: "HyperliquidSignTransaction",
|
|
292
350
|
version: "1",
|
|
293
|
-
chainId: parseInt(
|
|
351
|
+
chainId: parseInt(action.signatureChainId),
|
|
294
352
|
verifyingContract: "0x0000000000000000000000000000000000000000",
|
|
295
353
|
},
|
|
296
|
-
types:
|
|
297
|
-
|
|
298
|
-
{ name: "hyperliquidChain", type: "string" },
|
|
299
|
-
{ name: "multiSigActionHash", type: "bytes32" },
|
|
300
|
-
{ name: "nonce", type: "uint64" },
|
|
301
|
-
],
|
|
302
|
-
},
|
|
303
|
-
primaryType: "HyperliquidTransaction:SendMultiSig",
|
|
354
|
+
types: userSignedActionEip712Types.multiSig,
|
|
355
|
+
primaryType: Object.keys(userSignedActionEip712Types.multiSig)[0],
|
|
304
356
|
message,
|
|
305
357
|
});
|
|
306
358
|
}
|
|
@@ -13,9 +13,10 @@ export interface IRequestTransport extends Partial<AsyncDisposable> {
|
|
|
13
13
|
* Sends a request to the Hyperliquid API.
|
|
14
14
|
* @param endpoint - The API endpoint to send the request to.
|
|
15
15
|
* @param payload - The payload to send with the request.
|
|
16
|
-
* @param signal - An
|
|
16
|
+
* @param signal - An {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | AbortSignal}. If this option is set, the request can be canceled by calling {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort | abort()} on the corresponding {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/AbortController | AbortController}.
|
|
17
17
|
* @returns A promise that resolves with parsed JSON response body.
|
|
18
18
|
*/
|
|
19
|
+
request<T>(endpoint: "info" | "exchange", payload: unknown, signal?: AbortSignal): Promise<T>;
|
|
19
20
|
request<T>(endpoint: "info" | "exchange" | "explorer", payload: unknown, signal?: AbortSignal): Promise<T>;
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/src/transports/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAkB,SAAQ,OAAO,CAAC,eAAe,CAAC;IAC/D;;;;;;OAMG;IACH,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAC9G;AAED;;;;GAIG;AACH,MAAM,WAAW,sBAAuB,SAAQ,OAAO,CAAC,eAAe,CAAC;IACpE;;;;;;OAMG;IACH,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CACpH;AAED,6CAA6C;AAC7C,MAAM,WAAW,YAAY;IACzB,kFAAkF;IAClF,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,wEAAwE;IACxE,iBAAiB,CAAC,EAAE,WAAW,CAAC;CACnC;AAED,mDAAmD;AACnD,qBAAa,cAAe,SAAQ,gBAAgB;gBACpC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIvD"}
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/src/transports/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAkB,SAAQ,OAAO,CAAC,eAAe,CAAC;IAC/D;;;;;;OAMG;IACH,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC9F,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAC9G;AAED;;;;GAIG;AACH,MAAM,WAAW,sBAAuB,SAAQ,OAAO,CAAC,eAAe,CAAC;IACpE;;;;;;OAMG;IACH,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CACpH;AAED,6CAA6C;AAC7C,MAAM,WAAW,YAAY;IACzB,kFAAkF;IAClF,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,wEAAwE;IACxE,iBAAiB,CAAC,EAAE,WAAW,CAAC;CACnC;AAED,mDAAmD;AACnD,qBAAa,cAAe,SAAQ,gBAAgB;gBACpC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIvD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { MaybePromise } from "../../base.js";
|
|
2
1
|
import { type IRequestTransport, TransportError } from "../base.js";
|
|
2
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
3
3
|
/** Error thrown when an HTTP request fails. */
|
|
4
4
|
export declare class HttpRequestError extends TransportError {
|
|
5
5
|
response?: Response;
|
|
@@ -76,11 +76,12 @@ export declare class HttpTransport implements IRequestTransport, HttpTransportOp
|
|
|
76
76
|
* Sends a request to the Hyperliquid API via fetch.
|
|
77
77
|
* @param endpoint - The API endpoint to send the request to.
|
|
78
78
|
* @param payload - The payload to send with the request.
|
|
79
|
-
* @param signal - An
|
|
79
|
+
* @param signal - An {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | AbortSignal}. If this option is set, the request can be canceled by calling {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort | abort()} on the corresponding {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/AbortController | AbortController}.
|
|
80
80
|
* @returns A promise that resolves with parsed JSON response body.
|
|
81
81
|
*
|
|
82
82
|
* @throws {HttpRequestError} Thrown when the HTTP request fails.
|
|
83
83
|
*/
|
|
84
84
|
request<T>(endpoint: "info" | "exchange" | "explorer", payload: unknown, signal?: AbortSignal): Promise<T>;
|
|
85
85
|
}
|
|
86
|
+
export {};
|
|
86
87
|
//# sourceMappingURL=http_transport.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http_transport.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/http/http_transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
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,+CAA+C;AAC/C,qBAAa,gBAAiB,SAAQ,cAAc;IAChD,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;gBAEF,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,QAAQ,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,OAAO,CAAC,EAAE,YAAY;CAgBpF;AAED,0DAA0D;AAC1D,MAAM,WAAW,oBAAoB;IACjC;;;OAGG;IACH,SAAS,CA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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;;;OAGG;gBACS,OAAO,CAAC,EAAE,oBAAoB;IAkB1C;;;;;;;;OAQG;IACG,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;CA4DnH"}
|
|
@@ -12,7 +12,7 @@ export class HttpRequestError extends TransportError {
|
|
|
12
12
|
message += ` - ${body}`;
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
|
-
message =
|
|
15
|
+
message = `Unknown error while making an HTTP request: ${options?.cause}`;
|
|
16
16
|
}
|
|
17
17
|
super(message, options);
|
|
18
18
|
this.name = "HttpRequestError";
|
|
@@ -53,7 +53,7 @@ export class HttpTransport {
|
|
|
53
53
|
* Sends a request to the Hyperliquid API via fetch.
|
|
54
54
|
* @param endpoint - The API endpoint to send the request to.
|
|
55
55
|
* @param payload - The payload to send with the request.
|
|
56
|
-
* @param signal - An
|
|
56
|
+
* @param signal - An {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | AbortSignal}. If this option is set, the request can be canceled by calling {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort | abort()} on the corresponding {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/AbortController | AbortController}.
|
|
57
57
|
* @returns A promise that resolves with parsed JSON response body.
|
|
58
58
|
*
|
|
59
59
|
* @throws {HttpRequestError} Thrown when the HTTP request fails.
|
|
@@ -109,7 +109,7 @@ export class HttpTransport {
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
/** Merges multiple {@linkcode HeadersInit} into one {@linkcode Headers}. */
|
|
112
|
+
/** Merges multiple {@linkcode HeadersInit} into one {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/Headers/Headers | Headers}. */
|
|
113
113
|
function mergeHeadersInit(...inits) {
|
|
114
114
|
if (inits.length === 0 || inits.length === 1) {
|
|
115
115
|
return new Headers(inits[0]);
|
|
@@ -123,7 +123,7 @@ function mergeHeadersInit(...inits) {
|
|
|
123
123
|
}
|
|
124
124
|
return merged;
|
|
125
125
|
}
|
|
126
|
-
/** Merges multiple {@linkcode RequestInit} into one {@linkcode RequestInit}. */
|
|
126
|
+
/** Merges multiple {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/RequestInit | RequestInit} into one {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/RequestInit | RequestInit}. */
|
|
127
127
|
function mergeRequestInit(...inits) {
|
|
128
128
|
const merged = inits.reduce((acc, init) => ({ ...acc, ...init }), {});
|
|
129
129
|
const headersList = inits.map((init) => init.headers)
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { BlockDetails, TxDetails } from "../../types/explorer/responses.js";
|
|
3
|
-
import type { BaseExchangeResponse } from "../../types/exchange/responses.js";
|
|
1
|
+
import type { BlockDetails, TxDetails } from "../../types/mod.js";
|
|
4
2
|
/** Response to subscribe to or unsubscribe from an event. */
|
|
5
3
|
interface SubscriptionResponse {
|
|
6
4
|
/** Type of subscription operation. */
|
|
@@ -31,11 +29,21 @@ interface PostResponse {
|
|
|
31
29
|
/** Indicates that this is an action response. */
|
|
32
30
|
type: "action";
|
|
33
31
|
/** Action result. */
|
|
34
|
-
payload:
|
|
32
|
+
payload: {
|
|
33
|
+
/** Response status indicating success or failure of the action. */
|
|
34
|
+
status: "ok" | "err";
|
|
35
|
+
/** Success data or error message. */
|
|
36
|
+
response: {
|
|
37
|
+
/** Type of operation. */
|
|
38
|
+
type: string;
|
|
39
|
+
/** Specific data for the action. */
|
|
40
|
+
data?: unknown;
|
|
41
|
+
} | string;
|
|
42
|
+
};
|
|
35
43
|
};
|
|
36
44
|
}
|
|
37
45
|
/** Base system events and dynamic channel events for Hyperliquid WebSocket API. */
|
|
38
|
-
interface HyperliquidEventMap {
|
|
46
|
+
export interface HyperliquidEventMap {
|
|
39
47
|
subscriptionResponse: CustomEvent<SubscriptionResponse>;
|
|
40
48
|
post: CustomEvent<PostResponse>;
|
|
41
49
|
error: CustomEvent<string>;
|
|
@@ -45,7 +53,7 @@ interface HyperliquidEventMap {
|
|
|
45
53
|
[key: string]: CustomEvent<any>;
|
|
46
54
|
}
|
|
47
55
|
/** Listens for WebSocket messages and sends them as Hyperliquid typed events. */
|
|
48
|
-
export declare class HyperliquidEventTarget extends
|
|
56
|
+
export declare class HyperliquidEventTarget extends EventTarget {
|
|
49
57
|
constructor(socket: WebSocket);
|
|
50
58
|
}
|
|
51
59
|
export {};
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"_hyperliquid_event_target.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/_hyperliquid_event_target.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAUlE,6DAA6D;AAC7D,UAAU,oBAAoB;IAC1B,sCAAsC;IACtC,MAAM,EAAE,WAAW,GAAG,aAAa,CAAC;IACpC,qCAAqC;IACrC,YAAY,EAAE,OAAO,CAAC;CACzB;AAED,gCAAgC;AAChC,UAAU,YAAY;IAClB,iCAAiC;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,uBAAuB;IACvB,QAAQ;IACJ,iDAAiD;IAC/C;QACE,wDAAwD;QACxD,IAAI,EAAE,MAAM,CAAC;QACb,qCAAqC;QACrC,OAAO,EAAE;YACL,0CAA0C;YAC1C,IAAI,EAAE,MAAM,CAAC;YACb,iCAAiC;YACjC,IAAI,EAAE,OAAO,CAAC;SACjB,CAAC;KACL;IACD,yCAAyC;OACvC;QACE,iDAAiD;QACjD,IAAI,EAAE,QAAQ,CAAC;QACf,qBAAqB;QACrB,OAAO,EAAE;YACL,mEAAmE;YACnE,MAAM,EAAE,IAAI,GAAG,KAAK,CAAC;YACrB,qCAAqC;YACrC,QAAQ,EACF;gBACE,yBAAyB;gBACzB,IAAI,EAAE,MAAM,CAAC;gBACb,oCAAoC;gBACpC,IAAI,CAAC,EAAE,OAAO,CAAC;aAClB,GACC,MAAM,CAAC;SAChB,CAAC;KACL,CAAC;CACT;AAED,mFAAmF;AACnF,MAAM,WAAW,mBAAmB;IAChC,oBAAoB,EAAE,WAAW,CAAC,oBAAoB,CAAC,CAAC;IACxD,IAAI,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC;IAChC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC3B,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IAC7B,cAAc,EAAE,WAAW,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC;IACzD,YAAY,EAAE,WAAW,CAAC,SAAS,EAAE,CAAC,CAAC;IAEvC,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;CACnC;AAED,iFAAiF;AACjF,qBAAa,sBAAuB,SAAQ,WAAW;gBACvC,MAAM,EAAE,SAAS;CAiBhC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { TypedEventTarget } from "typescript-event-target";
|
|
2
1
|
/** Listens for WebSocket messages and sends them as Hyperliquid typed events. */
|
|
3
|
-
export class HyperliquidEventTarget extends
|
|
2
|
+
export class HyperliquidEventTarget extends EventTarget {
|
|
4
3
|
constructor(socket) {
|
|
5
4
|
super();
|
|
6
5
|
socket.addEventListener("message", (event) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { MaybePromise } from "../../base.js";
|
|
2
1
|
import { TransportError } from "../base.js";
|
|
2
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
3
3
|
/** Configuration options for the `ReconnectingWebSocket`. */
|
|
4
4
|
export interface ReconnectingWebSocketOptions {
|
|
5
5
|
/**
|
|
@@ -107,4 +107,5 @@ export declare class ReconnectingWebSocket implements WebSocket {
|
|
|
107
107
|
}, options?: boolean | EventListenerOptions): void;
|
|
108
108
|
dispatchEvent(event: Event): boolean;
|
|
109
109
|
}
|
|
110
|
+
export {};
|
|
110
111
|
//# sourceMappingURL=_reconnecting_websocket.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_reconnecting_websocket.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/_reconnecting_websocket.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"_reconnecting_websocket.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/_reconnecting_websocket.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEtC,6DAA6D;AAC7D,MAAM,WAAW,4BAA4B;IACzC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAElC;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,KAAK,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;IAE5F;;;;;OAKG;IACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EA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AG,CAAA;KAAE,EAC3D,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,GAC5C,IAAI;IA8CP,mBAAmB,CAAC,CAAC,SAAS,MAAM,iBAAiB,EACjD,IAAI,EAAE,CAAC,EACP,QAAQ,EACF,CAAC,CAAC,IAAI,EAAE,qBAAqB,EAAE,EAAE,EAAE,iBAAiB,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,GAChE;QAAE,WAAW,EAAE,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,KAAK,GAAG,CAAA;KAAE,EAC3D,OAAO,CAAC,EAAE,OAAO,GAAG,oBAAoB,GACzC,IAAI;IAkBP,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;CAGvC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_websocket_async_request.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/_websocket_async_request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"_websocket_async_request.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/_websocket_async_request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,KAAK,EAAuB,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAkBlG;;;GAGG;AACH,qBAAa,qBAAqB;IAgBlB,SAAS,CAAC,MAAM,EAAE,qBAAqB;IAfnD,SAAS,CAAC,MAAM,EAAE,MAAM,CAAK;IAC7B,SAAS,CAAC,KAAK,EAAE;QACb,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;QAEpB,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;QAE/B,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;KAClC,EAAE,CAAM;IACT,eAAe,EAAE,MAAM,CAAK;IAE5B;;;;OAIG;gBACmB,MAAM,EAAE,qBAAqB,EAAE,QAAQ,EAAE,sBAAsB;IAqFrF;;;OAGG;IACG,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAC5D,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,aAAa,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC;IA6ClH,6DAA6D;IAC7D,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM;CAK7C"}
|