@nktkas/hyperliquid 0.23.1 → 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 +154 -170
- package/esm/mod.d.ts +1 -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 +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 +228 -203
- package/esm/src/clients/info.d.ts.map +1 -1
- package/esm/src/clients/info.js +236 -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 +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 +29 -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 +117 -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 +1 -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 +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 +228 -203
- package/script/src/clients/info.d.ts.map +1 -1
- package/script/src/clients/info.js +236 -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 +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 +29 -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 +117 -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
|
@@ -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,64 +62,79 @@
|
|
|
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
|
|
86
119
|
*/
|
|
87
|
-
import type
|
|
88
|
-
import {
|
|
89
|
-
export { type
|
|
90
|
-
export * from "./_sorter.js";
|
|
120
|
+
import { type AbstractWallet, getWalletAddress, getWalletChainId, type Signature } from "./_signTypedData/mod.js";
|
|
121
|
+
import { actionSorter, userSignedActionEip712Types } from "./_sorter.js";
|
|
122
|
+
export { type AbstractWallet, actionSorter, getWalletAddress, getWalletChainId, type Signature, userSignedActionEip712Types, };
|
|
91
123
|
/**
|
|
92
124
|
* Create a hash of the L1 action.
|
|
93
125
|
* @example
|
|
94
126
|
* ```ts
|
|
95
127
|
* import { actionSorter, createL1ActionHash } from "@nktkas/hyperliquid/signing";
|
|
96
128
|
*
|
|
97
|
-
* const action = {
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* }
|
|
129
|
+
* const action = actionSorter.cancel({
|
|
130
|
+
* type: "cancel",
|
|
131
|
+
* cancels: [
|
|
132
|
+
* { a: 0, o: 12345 },
|
|
133
|
+
* ],
|
|
134
|
+
* });
|
|
103
135
|
* const nonce = Date.now();
|
|
104
136
|
*
|
|
105
|
-
* const actionHash = createL1ActionHash({
|
|
106
|
-
* action: actionSorter[action.type](action),
|
|
107
|
-
* nonce,
|
|
108
|
-
* vaultAddress: "0x...", // optional
|
|
109
|
-
* expiresAfter: Date.now() + 10_000, // optional
|
|
110
|
-
* });
|
|
137
|
+
* const actionHash = createL1ActionHash({ action, nonce });
|
|
111
138
|
* ```
|
|
112
139
|
*/
|
|
113
140
|
export declare function createL1ActionHash(args: {
|
|
@@ -116,37 +143,33 @@ export declare function createL1ActionHash(args: {
|
|
|
116
143
|
/** The current timestamp in ms. */
|
|
117
144
|
nonce: number;
|
|
118
145
|
/** Optional vault address used in the action. */
|
|
119
|
-
vaultAddress?:
|
|
146
|
+
vaultAddress?: `0x${string}`;
|
|
120
147
|
/** Optional expiration time of the action in ms since the epoch. */
|
|
121
148
|
expiresAfter?: number;
|
|
122
|
-
}):
|
|
149
|
+
}): `0x${string}`;
|
|
123
150
|
/**
|
|
124
151
|
* Sign an L1 action.
|
|
125
152
|
* @example
|
|
126
153
|
* ```ts
|
|
127
154
|
* import { actionSorter, signL1Action } from "@nktkas/hyperliquid/signing";
|
|
128
155
|
*
|
|
129
|
-
* const privateKey = "0x..."; //
|
|
156
|
+
* const privateKey = "0x..."; // `viem`, `ethers`, or private key directly`
|
|
130
157
|
*
|
|
131
|
-
* const
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* ],
|
|
137
|
-
* } as const;
|
|
138
|
-
*
|
|
139
|
-
* const signature = await signL1Action({
|
|
140
|
-
* wallet: privateKey,
|
|
141
|
-
* action: actionSorter[action.type](action),
|
|
142
|
-
* nonce,
|
|
158
|
+
* const action = actionSorter.cancel({
|
|
159
|
+
* type: "cancel",
|
|
160
|
+
* cancels: [
|
|
161
|
+
* { a: 0, o: 12345 },
|
|
162
|
+
* ],
|
|
143
163
|
* });
|
|
164
|
+
* const nonce = Date.now();
|
|
165
|
+
*
|
|
166
|
+
* const signature = await signL1Action({ wallet: privateKey, action, nonce });
|
|
144
167
|
*
|
|
145
168
|
* // Send the signed action to the Hyperliquid API
|
|
146
169
|
* const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
170
|
+
* method: "POST",
|
|
171
|
+
* headers: { "Content-Type": "application/json" },
|
|
172
|
+
* body: JSON.stringify({ action, signature, nonce }), // recommended to send the same formatted action
|
|
150
173
|
* });
|
|
151
174
|
* const body = await response.json();
|
|
152
175
|
* ```
|
|
@@ -161,7 +184,7 @@ export declare function signL1Action(args: {
|
|
|
161
184
|
/** Indicates if the action is for the testnet. (default: false) */
|
|
162
185
|
isTestnet?: boolean;
|
|
163
186
|
/** Optional vault address used in the action. */
|
|
164
|
-
vaultAddress?:
|
|
187
|
+
vaultAddress?: `0x${string}`;
|
|
165
188
|
/** Optional expiration time of the action in ms since the epoch. */
|
|
166
189
|
expiresAfter?: number;
|
|
167
190
|
}): Promise<Signature>;
|
|
@@ -169,30 +192,30 @@ export declare function signL1Action(args: {
|
|
|
169
192
|
* Sign a user-signed action.
|
|
170
193
|
* @example
|
|
171
194
|
* ```ts
|
|
172
|
-
* import { signUserSignedAction, userSignedActionEip712Types } from "@nktkas/hyperliquid/signing";
|
|
195
|
+
* import { actionSorter, signUserSignedAction, userSignedActionEip712Types } from "@nktkas/hyperliquid/signing";
|
|
173
196
|
*
|
|
174
|
-
* const privateKey = "0x..."; //
|
|
197
|
+
* const privateKey = "0x..."; // `viem`, `ethers`, or private key directly`
|
|
175
198
|
*
|
|
176
|
-
* const action = {
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* }
|
|
199
|
+
* const action = actionSorter.approveAgent({
|
|
200
|
+
* type: "approveAgent",
|
|
201
|
+
* signatureChainId: "0x66eee",
|
|
202
|
+
* hyperliquidChain: "Mainnet",
|
|
203
|
+
* agentAddress: "0x...",
|
|
204
|
+
* agentName: "Agent",
|
|
205
|
+
* nonce: Date.now(),
|
|
206
|
+
* });
|
|
184
207
|
*
|
|
185
208
|
* const signature = await signUserSignedAction({
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
209
|
+
* wallet: privateKey,
|
|
210
|
+
* action,
|
|
211
|
+
* types: userSignedActionEip712Types[action.type],
|
|
189
212
|
* });
|
|
190
213
|
*
|
|
191
214
|
* // Send the signed action to the Hyperliquid API
|
|
192
215
|
* const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
216
|
+
* method: "POST",
|
|
217
|
+
* headers: { "Content-Type": "application/json" },
|
|
218
|
+
* body: JSON.stringify({ action, signature, nonce: action.nonce }), // recommended to send the same formatted action
|
|
196
219
|
* });
|
|
197
220
|
* const body = await response.json();
|
|
198
221
|
* ```
|
|
@@ -200,11 +223,17 @@ export declare function signL1Action(args: {
|
|
|
200
223
|
export declare function signUserSignedAction(args: {
|
|
201
224
|
/** Wallet to sign the action. */
|
|
202
225
|
wallet: AbstractWallet;
|
|
203
|
-
/** The action to be signed. */
|
|
226
|
+
/** The action to be signed (hex strings must be in lower case). */
|
|
204
227
|
action: {
|
|
205
|
-
signatureChainId:
|
|
228
|
+
signatureChainId: `0x${string}`;
|
|
206
229
|
[key: string]: unknown;
|
|
207
|
-
}
|
|
230
|
+
} & ({
|
|
231
|
+
payloadMultiSigUser: `0x${string}`;
|
|
232
|
+
outerSigner: `0x${string}`;
|
|
233
|
+
} | {
|
|
234
|
+
payloadMultiSigUser?: undefined;
|
|
235
|
+
outerSigner?: undefined;
|
|
236
|
+
});
|
|
208
237
|
/** The types of the action (hash depends on key order). */
|
|
209
238
|
types: {
|
|
210
239
|
[key: string]: {
|
|
@@ -220,36 +249,57 @@ export declare function signUserSignedAction(args: {
|
|
|
220
249
|
* import { actionSorter, signL1Action, signMultiSigAction } from "@nktkas/hyperliquid/signing";
|
|
221
250
|
* import { privateKeyToAccount } from "viem/accounts";
|
|
222
251
|
*
|
|
223
|
-
* const wallet = privateKeyToAccount("0x..."); // or
|
|
252
|
+
* const wallet = privateKeyToAccount("0x..."); // or ethers, private key directly
|
|
224
253
|
* const multiSigUser = "0x...";
|
|
225
254
|
*
|
|
255
|
+
* const action = actionSorter.scheduleCancel({
|
|
256
|
+
* type: "scheduleCancel",
|
|
257
|
+
* time: Date.now() + 10000,
|
|
258
|
+
* });
|
|
226
259
|
* const nonce = Date.now();
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
* const signature = await signL1Action({
|
|
234
|
-
* wallet,
|
|
235
|
-
* action: [multiSigUser.toLowerCase(), wallet.address.toLowerCase(), actionSorter[action.type](action)],
|
|
260
|
+
*
|
|
261
|
+
* // Create the required number of signatures
|
|
262
|
+
* const signatures = await Promise.all(["0x...", "0x..."].map(async (signerPrivKey) => {
|
|
263
|
+
* return await signL1Action({
|
|
264
|
+
* wallet: signerPrivKey as `0x${string}`,
|
|
265
|
+
* action: [multiSigUser.toLowerCase(), wallet.address.toLowerCase(), action],
|
|
236
266
|
* nonce,
|
|
237
|
-
*
|
|
267
|
+
* });
|
|
268
|
+
* }));
|
|
269
|
+
*
|
|
270
|
+
* // or user-signed action
|
|
271
|
+
* // const signatures = await Promise.all(["0x...", "0x..."].map(async (signerPrivKey) => {
|
|
272
|
+
* // return await signUserSignedAction({
|
|
273
|
+
* // wallet: signerPrivKey as `0x${string}`,
|
|
274
|
+
* // action: {
|
|
275
|
+
* // ...action,
|
|
276
|
+
* // payloadMultiSigUser: multiSigUser,
|
|
277
|
+
* // outerSigner: wallet.address,
|
|
278
|
+
* // },
|
|
279
|
+
* // types: userSignedActionEip712Types[action.type],
|
|
280
|
+
* // });
|
|
281
|
+
* // }));
|
|
238
282
|
*
|
|
239
283
|
* // Then use signatures in the multi-sig action
|
|
240
|
-
* const
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
* },
|
|
250
|
-
* },
|
|
251
|
-
* nonce,
|
|
284
|
+
* const multiSigAction = actionSorter.multiSig({
|
|
285
|
+
* type: "multiSig",
|
|
286
|
+
* signatureChainId: "0x66eee",
|
|
287
|
+
* signatures,
|
|
288
|
+
* payload: {
|
|
289
|
+
* multiSigUser,
|
|
290
|
+
* outerSigner: wallet.address,
|
|
291
|
+
* action,
|
|
292
|
+
* },
|
|
252
293
|
* });
|
|
294
|
+
* const multiSigSignature = await signMultiSigAction({ wallet, action: multiSigAction, nonce });
|
|
295
|
+
*
|
|
296
|
+
* // Send the multi-sig action to the Hyperliquid API
|
|
297
|
+
* const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
298
|
+
* method: "POST",
|
|
299
|
+
* headers: { "Content-Type": "application/json" },
|
|
300
|
+
* body: JSON.stringify({ action: multiSigAction, signature: multiSigSignature, nonce }), // recommended to send the same formatted action
|
|
301
|
+
* });
|
|
302
|
+
* const body = await response.json();
|
|
253
303
|
* ```
|
|
254
304
|
*/
|
|
255
305
|
export declare function signMultiSigAction(args: {
|
|
@@ -257,7 +307,7 @@ export declare function signMultiSigAction(args: {
|
|
|
257
307
|
wallet: AbstractWallet;
|
|
258
308
|
/** The action to be signed (hash depends on key order). */
|
|
259
309
|
action: {
|
|
260
|
-
signatureChainId:
|
|
310
|
+
signatureChainId: `0x${string}`;
|
|
261
311
|
[key: string]: unknown;
|
|
262
312
|
};
|
|
263
313
|
/** The current timestamp in ms. */
|
|
@@ -265,7 +315,7 @@ export declare function signMultiSigAction(args: {
|
|
|
265
315
|
/** Indicates if the action is for the testnet. (default: false) */
|
|
266
316
|
isTestnet?: boolean;
|
|
267
317
|
/** Optional vault address used in the action. */
|
|
268
|
-
vaultAddress?:
|
|
318
|
+
vaultAddress?: `0x${string}`;
|
|
269
319
|
/** Optional expiration time of the action in ms since the epoch. */
|
|
270
320
|
expiresAfter?: number;
|
|
271
321
|
}): Promise<Signature>;
|
|
@@ -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":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsHG;AAKH,OAAO,EACH,KAAK,cAAc,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,SAAS,EAEjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAEzE,OAAO,EACH,KAAK,cAAc,EACnB,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,SAAS,EACd,2BAA2B,GAC9B,CAAC;AAEF;;;;;;;;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