@nktkas/hyperliquid 0.23.1 → 0.24.1
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 +178 -194
- package/esm/mod.d.ts +2 -1
- 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 +485 -392
- package/esm/src/clients/exchange.d.ts.map +1 -1
- package/esm/src/clients/exchange.js +517 -912
- package/esm/src/clients/info.d.ts +249 -203
- package/esm/src/clients/info.d.ts.map +1 -1
- package/esm/src/clients/info.js +258 -368
- 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 +101 -99
- package/esm/src/clients/subscription.d.ts.map +1 -1
- package/esm/src/clients/subscription.js +107 -152
- 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 +18 -19
- package/esm/src/signing/_sorter.d.ts.map +1 -1
- package/esm/src/signing/_sorter.js +57 -59
- package/esm/src/signing/mod.d.ts +179 -129
- package/esm/src/signing/mod.d.ts.map +1 -1
- package/esm/src/signing/mod.js +184 -132
- 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 +547 -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 +405 -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 +29 -8
- package/esm/src/types/info/markets.d.ts.map +1 -1
- package/esm/src/types/info/orders.d.ts +64 -17
- package/esm/src/types/info/orders.d.ts.map +1 -1
- package/esm/src/types/info/requests.d.ts +126 -51
- package/esm/src/types/info/requests.d.ts.map +1 -1
- package/esm/src/types/info/validators.d.ts +44 -14
- package/esm/src/types/info/validators.d.ts.map +1 -1
- package/esm/src/types/info/vaults.d.ts +25 -10
- package/esm/src/types/info/vaults.d.ts.map +1 -1
- package/esm/src/types/mod.d.ts +1 -1
- 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 -1
- 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 +485 -392
- package/script/src/clients/exchange.d.ts.map +1 -1
- package/script/src/clients/exchange.js +516 -911
- package/script/src/clients/info.d.ts +249 -203
- package/script/src/clients/info.d.ts.map +1 -1
- package/script/src/clients/info.js +258 -368
- 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 +101 -99
- package/script/src/clients/subscription.d.ts.map +1 -1
- package/script/src/clients/subscription.js +107 -152
- 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 +18 -19
- package/script/src/signing/_sorter.d.ts.map +1 -1
- package/script/src/signing/_sorter.js +57 -59
- package/script/src/signing/mod.d.ts +179 -129
- package/script/src/signing/mod.d.ts.map +1 -1
- package/script/src/signing/mod.js +187 -150
- 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 +547 -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 +405 -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 +29 -8
- package/script/src/types/info/markets.d.ts.map +1 -1
- package/script/src/types/info/orders.d.ts +64 -17
- package/script/src/types/info/orders.d.ts.map +1 -1
- package/script/src/types/info/requests.d.ts +126 -51
- package/script/src/types/info/requests.d.ts.map +1 -1
- package/script/src/types/info/validators.d.ts +44 -14
- package/script/src/types/info/validators.d.ts.map +1 -1
- package/script/src/types/info/vaults.d.ts +25 -10
- package/script/src/types/info/vaults.d.ts.map +1 -1
- package/script/src/types/mod.d.ts +1 -1
- 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/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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/src/signing/mod.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/src/signing/mod.ts"],"names":[],"mappings":"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"}
|
|
@@ -7,100 +7,119 @@
|
|
|
7
7
|
* ```ts
|
|
8
8
|
* import { actionSorter, signL1Action } from "@nktkas/hyperliquid/signing";
|
|
9
9
|
*
|
|
10
|
-
* const privateKey = "0x..."; //
|
|
10
|
+
* const privateKey = "0x..."; // `viem`, `ethers`, or private key directly`
|
|
11
11
|
*
|
|
12
|
+
* const action = actionSorter.cancel({
|
|
13
|
+
* type: "cancel",
|
|
14
|
+
* cancels: [
|
|
15
|
+
* { a: 0, o: 12345 },
|
|
16
|
+
* ],
|
|
17
|
+
* });
|
|
12
18
|
* const nonce = Date.now();
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* wallet: privateKey,
|
|
22
|
-
* action: actionSorter[action.type](action),
|
|
23
|
-
* nonce,
|
|
19
|
+
*
|
|
20
|
+
* const signature = await signL1Action({ wallet: privateKey, action, nonce });
|
|
21
|
+
*
|
|
22
|
+
* // Send the signed action to the Hyperliquid API
|
|
23
|
+
* const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
24
|
+
* method: "POST",
|
|
25
|
+
* headers: { "Content-Type": "application/json" },
|
|
26
|
+
* body: JSON.stringify({ action, signature, nonce }), // recommended to send the same formatted action
|
|
24
27
|
* });
|
|
28
|
+
* const body = await response.json();
|
|
25
29
|
* ```
|
|
26
30
|
*
|
|
27
31
|
* @example Signing a user-signed action
|
|
28
32
|
* ```ts
|
|
29
|
-
* import { signUserSignedAction, userSignedActionEip712Types } from "@nktkas/hyperliquid/signing";
|
|
33
|
+
* import { actionSorter, signUserSignedAction, userSignedActionEip712Types } from "@nktkas/hyperliquid/signing";
|
|
30
34
|
*
|
|
31
|
-
* const privateKey = "0x..."; //
|
|
35
|
+
* const privateKey = "0x..."; // `viem`, `ethers`, or private key directly`
|
|
32
36
|
*
|
|
33
|
-
* const action = {
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* }
|
|
37
|
+
* const action = actionSorter.approveAgent({
|
|
38
|
+
* type: "approveAgent",
|
|
39
|
+
* signatureChainId: "0x66eee",
|
|
40
|
+
* hyperliquidChain: "Mainnet",
|
|
41
|
+
* agentAddress: "0x...",
|
|
42
|
+
* agentName: "Agent",
|
|
43
|
+
* nonce: Date.now(),
|
|
44
|
+
* });
|
|
41
45
|
*
|
|
42
46
|
* const signature = await signUserSignedAction({
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
47
|
+
* wallet: privateKey,
|
|
48
|
+
* action,
|
|
49
|
+
* types: userSignedActionEip712Types[action.type],
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* // Send the signed action to the Hyperliquid API
|
|
53
|
+
* const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
54
|
+
* method: "POST",
|
|
55
|
+
* headers: { "Content-Type": "application/json" },
|
|
56
|
+
* body: JSON.stringify({ action, signature, nonce: action.nonce }), // recommended to send the same formatted action
|
|
46
57
|
* });
|
|
58
|
+
* const body = await response.json();
|
|
47
59
|
* ```
|
|
48
60
|
*
|
|
49
61
|
* @example Signing a multi-signature action
|
|
50
62
|
* ```ts
|
|
51
63
|
* import { actionSorter, signL1Action, signMultiSigAction } from "@nktkas/hyperliquid/signing";
|
|
52
|
-
* import { privateKeyToAccount } from "viem/accounts";
|
|
64
|
+
* import { privateKeyToAccount } from "npm:viem/accounts";
|
|
53
65
|
*
|
|
54
|
-
* const wallet = privateKeyToAccount("0x..."); // or `ethers`, private key
|
|
66
|
+
* const wallet = privateKeyToAccount("0x..."); // or `ethers`, private key directly
|
|
55
67
|
* const multiSigUser = "0x...";
|
|
56
68
|
*
|
|
69
|
+
* const action = actionSorter.scheduleCancel({
|
|
70
|
+
* type: "scheduleCancel",
|
|
71
|
+
* time: Date.now() + 10000,
|
|
72
|
+
* });
|
|
57
73
|
* const nonce = Date.now();
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* const signature = await signL1Action({
|
|
65
|
-
* wallet,
|
|
66
|
-
* action: [multiSigUser.toLowerCase(), wallet.address.toLowerCase(), actionSorter[action.type](action)],
|
|
74
|
+
*
|
|
75
|
+
* // Create the required number of signatures
|
|
76
|
+
* const signatures = await Promise.all(["0x...", "0x..."].map(async (signerPrivKey) => {
|
|
77
|
+
* return await signL1Action({
|
|
78
|
+
* wallet: signerPrivKey as `0x${string}`,
|
|
79
|
+
* action: [multiSigUser.toLowerCase(), wallet.address.toLowerCase(), action],
|
|
67
80
|
* nonce,
|
|
68
|
-
*
|
|
81
|
+
* });
|
|
82
|
+
* }));
|
|
83
|
+
*
|
|
84
|
+
* // or user-signed action
|
|
85
|
+
* // const signatures = await Promise.all(["0x...", "0x..."].map(async (signerPrivKey) => {
|
|
86
|
+
* // return await signUserSignedAction({
|
|
87
|
+
* // wallet: signerPrivKey as `0x${string}`,
|
|
88
|
+
* // action: {
|
|
89
|
+
* // ...action,
|
|
90
|
+
* // payloadMultiSigUser: multiSigUser,
|
|
91
|
+
* // outerSigner: wallet.address,
|
|
92
|
+
* // },
|
|
93
|
+
* // types: userSignedActionEip712Types[action.type],
|
|
94
|
+
* // });
|
|
95
|
+
* // }));
|
|
69
96
|
*
|
|
70
97
|
* // Then use signatures in the multi-sig action
|
|
71
|
-
* const
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* },
|
|
81
|
-
* },
|
|
82
|
-
* nonce,
|
|
98
|
+
* const multiSigAction = actionSorter.multiSig({
|
|
99
|
+
* type: "multiSig",
|
|
100
|
+
* signatureChainId: "0x66eee",
|
|
101
|
+
* signatures,
|
|
102
|
+
* payload: {
|
|
103
|
+
* multiSigUser,
|
|
104
|
+
* outerSigner: wallet.address,
|
|
105
|
+
* action,
|
|
106
|
+
* },
|
|
83
107
|
* });
|
|
108
|
+
* const multiSigSignature = await signMultiSigAction({ wallet, action: multiSigAction, nonce });
|
|
109
|
+
*
|
|
110
|
+
* // Send the multi-sig action to the Hyperliquid API
|
|
111
|
+
* const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
112
|
+
* method: "POST",
|
|
113
|
+
* headers: { "Content-Type": "application/json" },
|
|
114
|
+
* body: JSON.stringify({ action: multiSigAction, signature: multiSigSignature, nonce }), // recommended to send the same formatted action
|
|
115
|
+
* });
|
|
116
|
+
* const body = await response.json();
|
|
84
117
|
* ```
|
|
85
118
|
*
|
|
86
119
|
* @module
|
|
87
120
|
*/
|
|
88
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
89
|
-
if (k2 === undefined) k2 = k;
|
|
90
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
91
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
92
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
93
|
-
}
|
|
94
|
-
Object.defineProperty(o, k2, desc);
|
|
95
|
-
}) : (function(o, m, k, k2) {
|
|
96
|
-
if (k2 === undefined) k2 = k;
|
|
97
|
-
o[k2] = m[k];
|
|
98
|
-
}));
|
|
99
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
100
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
101
|
-
};
|
|
102
121
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
103
|
-
exports.
|
|
122
|
+
exports.userSignedActionEip712Types = exports.getWalletChainId = exports.getWalletAddress = exports.actionSorter = void 0;
|
|
104
123
|
exports.createL1ActionHash = createL1ActionHash;
|
|
105
124
|
exports.signL1Action = signL1Action;
|
|
106
125
|
exports.signUserSignedAction = signUserSignedAction;
|
|
@@ -109,32 +128,26 @@ const sha3_1 = require("@noble/hashes/sha3");
|
|
|
109
128
|
const secp256k1_1 = require("@noble/secp256k1");
|
|
110
129
|
const msgpack_1 = require("@msgpack/msgpack");
|
|
111
130
|
const mod_js_1 = require("./_signTypedData/mod.js");
|
|
112
|
-
Object.defineProperty(exports, "
|
|
113
|
-
Object.defineProperty(exports, "
|
|
114
|
-
|
|
115
|
-
Object.defineProperty(exports, "
|
|
116
|
-
Object.defineProperty(exports, "
|
|
117
|
-
__exportStar(require("./_sorter.js"), exports);
|
|
131
|
+
Object.defineProperty(exports, "getWalletAddress", { enumerable: true, get: function () { return mod_js_1.getWalletAddress; } });
|
|
132
|
+
Object.defineProperty(exports, "getWalletChainId", { enumerable: true, get: function () { return mod_js_1.getWalletChainId; } });
|
|
133
|
+
const _sorter_js_1 = require("./_sorter.js");
|
|
134
|
+
Object.defineProperty(exports, "actionSorter", { enumerable: true, get: function () { return _sorter_js_1.actionSorter; } });
|
|
135
|
+
Object.defineProperty(exports, "userSignedActionEip712Types", { enumerable: true, get: function () { return _sorter_js_1.userSignedActionEip712Types; } });
|
|
118
136
|
/**
|
|
119
137
|
* Create a hash of the L1 action.
|
|
120
138
|
* @example
|
|
121
139
|
* ```ts
|
|
122
140
|
* import { actionSorter, createL1ActionHash } from "@nktkas/hyperliquid/signing";
|
|
123
141
|
*
|
|
124
|
-
* const action = {
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* }
|
|
142
|
+
* const action = actionSorter.cancel({
|
|
143
|
+
* type: "cancel",
|
|
144
|
+
* cancels: [
|
|
145
|
+
* { a: 0, o: 12345 },
|
|
146
|
+
* ],
|
|
147
|
+
* });
|
|
130
148
|
* const nonce = Date.now();
|
|
131
149
|
*
|
|
132
|
-
* const actionHash = createL1ActionHash({
|
|
133
|
-
* action: actionSorter[action.type](action),
|
|
134
|
-
* nonce,
|
|
135
|
-
* vaultAddress: "0x...", // optional
|
|
136
|
-
* expiresAfter: Date.now() + 10_000, // optional
|
|
137
|
-
* });
|
|
150
|
+
* const actionHash = createL1ActionHash({ action, nonce });
|
|
138
151
|
* ```
|
|
139
152
|
*/
|
|
140
153
|
function createL1ActionHash(args) {
|
|
@@ -165,27 +178,23 @@ function toUint64Bytes(n) {
|
|
|
165
178
|
* ```ts
|
|
166
179
|
* import { actionSorter, signL1Action } from "@nktkas/hyperliquid/signing";
|
|
167
180
|
*
|
|
168
|
-
* const privateKey = "0x..."; //
|
|
181
|
+
* const privateKey = "0x..."; // `viem`, `ethers`, or private key directly`
|
|
169
182
|
*
|
|
170
|
-
* const
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
* ],
|
|
176
|
-
* } as const;
|
|
177
|
-
*
|
|
178
|
-
* const signature = await signL1Action({
|
|
179
|
-
* wallet: privateKey,
|
|
180
|
-
* action: actionSorter[action.type](action),
|
|
181
|
-
* nonce,
|
|
183
|
+
* const action = actionSorter.cancel({
|
|
184
|
+
* type: "cancel",
|
|
185
|
+
* cancels: [
|
|
186
|
+
* { a: 0, o: 12345 },
|
|
187
|
+
* ],
|
|
182
188
|
* });
|
|
189
|
+
* const nonce = Date.now();
|
|
190
|
+
*
|
|
191
|
+
* const signature = await signL1Action({ wallet: privateKey, action, nonce });
|
|
183
192
|
*
|
|
184
193
|
* // Send the signed action to the Hyperliquid API
|
|
185
194
|
* const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
195
|
+
* method: "POST",
|
|
196
|
+
* headers: { "Content-Type": "application/json" },
|
|
197
|
+
* body: JSON.stringify({ action, signature, nonce }), // recommended to send the same formatted action
|
|
189
198
|
* });
|
|
190
199
|
* const body = await response.json();
|
|
191
200
|
* ```
|
|
@@ -219,36 +228,46 @@ async function signL1Action(args) {
|
|
|
219
228
|
* Sign a user-signed action.
|
|
220
229
|
* @example
|
|
221
230
|
* ```ts
|
|
222
|
-
* import { signUserSignedAction, userSignedActionEip712Types } from "@nktkas/hyperliquid/signing";
|
|
231
|
+
* import { actionSorter, signUserSignedAction, userSignedActionEip712Types } from "@nktkas/hyperliquid/signing";
|
|
223
232
|
*
|
|
224
|
-
* const privateKey = "0x..."; //
|
|
233
|
+
* const privateKey = "0x..."; // `viem`, `ethers`, or private key directly`
|
|
225
234
|
*
|
|
226
|
-
* const action = {
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
* }
|
|
235
|
+
* const action = actionSorter.approveAgent({
|
|
236
|
+
* type: "approveAgent",
|
|
237
|
+
* signatureChainId: "0x66eee",
|
|
238
|
+
* hyperliquidChain: "Mainnet",
|
|
239
|
+
* agentAddress: "0x...",
|
|
240
|
+
* agentName: "Agent",
|
|
241
|
+
* nonce: Date.now(),
|
|
242
|
+
* });
|
|
234
243
|
*
|
|
235
244
|
* const signature = await signUserSignedAction({
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
245
|
+
* wallet: privateKey,
|
|
246
|
+
* action,
|
|
247
|
+
* types: userSignedActionEip712Types[action.type],
|
|
239
248
|
* });
|
|
240
249
|
*
|
|
241
250
|
* // Send the signed action to the Hyperliquid API
|
|
242
251
|
* const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
252
|
+
* method: "POST",
|
|
253
|
+
* headers: { "Content-Type": "application/json" },
|
|
254
|
+
* body: JSON.stringify({ action, signature, nonce: action.nonce }), // recommended to send the same formatted action
|
|
246
255
|
* });
|
|
247
256
|
* const body = await response.json();
|
|
248
257
|
* ```
|
|
249
258
|
*/
|
|
250
259
|
async function signUserSignedAction(args) {
|
|
251
|
-
|
|
260
|
+
let { wallet, action, types } = args;
|
|
261
|
+
if (action.type === "approveAgent" && !action.agentName) { // special case for `approveAgent`
|
|
262
|
+
action = { ...action, agentName: "" }; // set to empty string instead of null
|
|
263
|
+
}
|
|
264
|
+
if ("payloadMultiSigUser" in action && "outerSigner" in action) { // special case for multi-sign payload
|
|
265
|
+
types = structuredClone(types); // for safe mutation
|
|
266
|
+
Object.values(types)[0].splice(// array mutation
|
|
267
|
+
1, // after `hyperliquidChain`
|
|
268
|
+
0, // do not remove any elements
|
|
269
|
+
{ name: "payloadMultiSigUser", type: "address" }, { name: "outerSigner", type: "address" });
|
|
270
|
+
}
|
|
252
271
|
return await (0, mod_js_1.signTypedData)({
|
|
253
272
|
wallet,
|
|
254
273
|
domain: {
|
|
@@ -267,45 +286,69 @@ async function signUserSignedAction(args) {
|
|
|
267
286
|
* @example
|
|
268
287
|
* ```ts
|
|
269
288
|
* import { actionSorter, signL1Action, signMultiSigAction } from "@nktkas/hyperliquid/signing";
|
|
270
|
-
* import { privateKeyToAccount } from "viem/accounts";
|
|
289
|
+
* import { privateKeyToAccount } from "npm:viem/accounts";
|
|
271
290
|
*
|
|
272
|
-
* const wallet = privateKeyToAccount("0x..."); // or
|
|
291
|
+
* const wallet = privateKeyToAccount("0x..."); // or ethers, private key directly
|
|
273
292
|
* const multiSigUser = "0x...";
|
|
274
293
|
*
|
|
294
|
+
* const action = actionSorter.scheduleCancel({
|
|
295
|
+
* type: "scheduleCancel",
|
|
296
|
+
* time: Date.now() + 10000,
|
|
297
|
+
* });
|
|
275
298
|
* const nonce = Date.now();
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
* const signature = await signL1Action({
|
|
283
|
-
* wallet,
|
|
284
|
-
* action: [multiSigUser.toLowerCase(), wallet.address.toLowerCase(), actionSorter[action.type](action)],
|
|
299
|
+
*
|
|
300
|
+
* // Create the required number of signatures
|
|
301
|
+
* const signatures = await Promise.all(["0x...", "0x..."].map(async (signerPrivKey) => {
|
|
302
|
+
* return await signL1Action({
|
|
303
|
+
* wallet: signerPrivKey as `0x${string}`,
|
|
304
|
+
* action: [multiSigUser.toLowerCase(), wallet.address.toLowerCase(), action],
|
|
285
305
|
* nonce,
|
|
286
|
-
*
|
|
306
|
+
* });
|
|
307
|
+
* }));
|
|
308
|
+
*
|
|
309
|
+
* // or user-signed action
|
|
310
|
+
* // const signatures = await Promise.all(["0x...", "0x..."].map(async (signerPrivKey) => {
|
|
311
|
+
* // return await signUserSignedAction({
|
|
312
|
+
* // wallet: signerPrivKey as `0x${string}`,
|
|
313
|
+
* // action: {
|
|
314
|
+
* // ...action,
|
|
315
|
+
* // payloadMultiSigUser: multiSigUser,
|
|
316
|
+
* // outerSigner: wallet.address,
|
|
317
|
+
* // },
|
|
318
|
+
* // types: userSignedActionEip712Types[action.type],
|
|
319
|
+
* // });
|
|
320
|
+
* // }));
|
|
287
321
|
*
|
|
288
322
|
* // Then use signatures in the multi-sig action
|
|
289
|
-
* const
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
* },
|
|
299
|
-
* },
|
|
300
|
-
* nonce,
|
|
323
|
+
* const multiSigAction = actionSorter.multiSig({
|
|
324
|
+
* type: "multiSig",
|
|
325
|
+
* signatureChainId: "0x66eee",
|
|
326
|
+
* signatures,
|
|
327
|
+
* payload: {
|
|
328
|
+
* multiSigUser,
|
|
329
|
+
* outerSigner: wallet.address,
|
|
330
|
+
* action,
|
|
331
|
+
* },
|
|
301
332
|
* });
|
|
333
|
+
* const multiSigSignature = await signMultiSigAction({ wallet, action: multiSigAction, nonce });
|
|
334
|
+
*
|
|
335
|
+
* // Send the multi-sig action to the Hyperliquid API
|
|
336
|
+
* const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
337
|
+
* method: "POST",
|
|
338
|
+
* headers: { "Content-Type": "application/json" },
|
|
339
|
+
* body: JSON.stringify({ action: multiSigAction, signature: multiSigSignature, nonce }), // recommended to send the same formatted action
|
|
340
|
+
* });
|
|
341
|
+
* const body = await response.json();
|
|
302
342
|
* ```
|
|
303
343
|
*/
|
|
304
344
|
async function signMultiSigAction(args) {
|
|
305
|
-
|
|
345
|
+
let { wallet, action, nonce, isTestnet = false, vaultAddress, expiresAfter, } = args;
|
|
346
|
+
if ("type" in action) {
|
|
347
|
+
action = structuredClone(action); // for safe mutation
|
|
348
|
+
delete action.type;
|
|
349
|
+
}
|
|
306
350
|
const multiSigActionHash = createL1ActionHash({ action, nonce, vaultAddress, expiresAfter });
|
|
307
351
|
const message = {
|
|
308
|
-
signatureChainId: action.signatureChainId,
|
|
309
352
|
hyperliquidChain: isTestnet ? "Testnet" : "Mainnet",
|
|
310
353
|
multiSigActionHash,
|
|
311
354
|
nonce,
|
|
@@ -315,17 +358,11 @@ async function signMultiSigAction(args) {
|
|
|
315
358
|
domain: {
|
|
316
359
|
name: "HyperliquidSignTransaction",
|
|
317
360
|
version: "1",
|
|
318
|
-
chainId: parseInt(
|
|
361
|
+
chainId: parseInt(action.signatureChainId),
|
|
319
362
|
verifyingContract: "0x0000000000000000000000000000000000000000",
|
|
320
363
|
},
|
|
321
|
-
types:
|
|
322
|
-
|
|
323
|
-
{ name: "hyperliquidChain", type: "string" },
|
|
324
|
-
{ name: "multiSigActionHash", type: "bytes32" },
|
|
325
|
-
{ name: "nonce", type: "uint64" },
|
|
326
|
-
],
|
|
327
|
-
},
|
|
328
|
-
primaryType: "HyperliquidTransaction:SendMultiSig",
|
|
364
|
+
types: _sorter_js_1.userSignedActionEip712Types.multiSig,
|
|
365
|
+
primaryType: Object.keys(_sorter_js_1.userSignedActionEip712Types.multiSig)[0],
|
|
329
366
|
message,
|
|
330
367
|
});
|
|
331
368
|
}
|
|
@@ -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,CAAC,EAAE,OAAO,CAAC;IAEpB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAExB;;;OAGG;IACH,MAAM,CAAC,EAAE;QACL,OAAO,CAAC,EAAE;YAAE,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;YAAC,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;SAAE,CAAC;QACrD,OAAO,CAAC,EAAE;YAAE,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;YAAC,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;SAAE,CAAC;KACxD,CAAC;IAEF,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,2DAA2D;AAC3D,qBAAa,aAAc,YAAW,iBAAiB,EAAE,oBAAoB;IACzE,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE;QACJ,OAAO,EAAE;YAAE,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;YAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;SAAE,CAAC;QAClD,OAAO,EAAE;YAAE,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;YAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;SAAE,CAAC;KACrD,CAAC;IACF,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;;;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"}
|
|
@@ -15,7 +15,7 @@ class HttpRequestError extends base_js_1.TransportError {
|
|
|
15
15
|
message += ` - ${body}`;
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
18
|
-
message =
|
|
18
|
+
message = `Unknown error while making an HTTP request: ${options?.cause}`;
|
|
19
19
|
}
|
|
20
20
|
super(message, options);
|
|
21
21
|
this.name = "HttpRequestError";
|
|
@@ -57,7 +57,7 @@ class HttpTransport {
|
|
|
57
57
|
* Sends a request to the Hyperliquid API via fetch.
|
|
58
58
|
* @param endpoint - The API endpoint to send the request to.
|
|
59
59
|
* @param payload - The payload to send with the request.
|
|
60
|
-
* @param signal - An
|
|
60
|
+
* @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}.
|
|
61
61
|
* @returns A promise that resolves with parsed JSON response body.
|
|
62
62
|
*
|
|
63
63
|
* @throws {HttpRequestError} Thrown when the HTTP request fails.
|
|
@@ -114,7 +114,7 @@ class HttpTransport {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
exports.HttpTransport = HttpTransport;
|
|
117
|
-
/** Merges multiple {@linkcode HeadersInit} into one {@linkcode Headers}. */
|
|
117
|
+
/** Merges multiple {@linkcode HeadersInit} into one {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/Headers/Headers | Headers}. */
|
|
118
118
|
function mergeHeadersInit(...inits) {
|
|
119
119
|
if (inits.length === 0 || inits.length === 1) {
|
|
120
120
|
return new Headers(inits[0]);
|
|
@@ -128,7 +128,7 @@ function mergeHeadersInit(...inits) {
|
|
|
128
128
|
}
|
|
129
129
|
return merged;
|
|
130
130
|
}
|
|
131
|
-
/** Merges multiple {@linkcode RequestInit} into one {@linkcode RequestInit}. */
|
|
131
|
+
/** 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}. */
|
|
132
132
|
function mergeRequestInit(...inits) {
|
|
133
133
|
const merged = inits.reduce((acc, init) => ({ ...acc, ...init }), {});
|
|
134
134
|
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,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HyperliquidEventTarget = void 0;
|
|
4
|
-
const typescript_event_target_1 = require("typescript-event-target");
|
|
5
4
|
/** Listens for WebSocket messages and sends them as Hyperliquid typed events. */
|
|
6
|
-
class HyperliquidEventTarget extends
|
|
5
|
+
class HyperliquidEventTarget extends EventTarget {
|
|
7
6
|
constructor(socket) {
|
|
8
7
|
super();
|
|
9
8
|
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
|