@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.
Files changed (169) hide show
  1. package/CONTRIBUTING.md +3 -2
  2. package/README.md +184 -186
  3. package/esm/mod.d.ts +2 -2
  4. package/esm/mod.d.ts.map +1 -1
  5. package/esm/src/base.d.ts +0 -5
  6. package/esm/src/base.d.ts.map +1 -1
  7. package/esm/src/clients/exchange.d.ts +430 -393
  8. package/esm/src/clients/exchange.d.ts.map +1 -1
  9. package/esm/src/clients/exchange.js +467 -927
  10. package/esm/src/clients/info.d.ts +330 -185
  11. package/esm/src/clients/info.d.ts.map +1 -1
  12. package/esm/src/clients/info.js +348 -334
  13. package/esm/src/clients/multiSign.d.ts +14 -1184
  14. package/esm/src/clients/multiSign.d.ts.map +1 -1
  15. package/esm/src/clients/multiSign.js +37 -2004
  16. package/esm/src/clients/subscription.d.ts +95 -93
  17. package/esm/src/clients/subscription.d.ts.map +1 -1
  18. package/esm/src/clients/subscription.js +101 -146
  19. package/esm/src/signing/_signTypedData/ethers.d.ts +16 -4
  20. package/esm/src/signing/_signTypedData/ethers.d.ts.map +1 -1
  21. package/esm/src/signing/_signTypedData/ethers.js +1 -1
  22. package/esm/src/signing/_signTypedData/mod.d.ts +12 -12
  23. package/esm/src/signing/_signTypedData/mod.d.ts.map +1 -1
  24. package/esm/src/signing/_signTypedData/mod.js +52 -24
  25. package/esm/src/signing/_signTypedData/private_key.d.ts +6 -5
  26. package/esm/src/signing/_signTypedData/private_key.d.ts.map +1 -1
  27. package/esm/src/signing/_signTypedData/private_key.js +40 -19
  28. package/esm/src/signing/_signTypedData/viem.d.ts +27 -6
  29. package/esm/src/signing/_signTypedData/viem.d.ts.map +1 -1
  30. package/esm/src/signing/_signTypedData/viem.js +1 -1
  31. package/esm/src/signing/_sorter.d.ts +12 -21
  32. package/esm/src/signing/_sorter.d.ts.map +1 -1
  33. package/esm/src/signing/_sorter.js +30 -63
  34. package/esm/src/signing/mod.d.ts +177 -127
  35. package/esm/src/signing/mod.d.ts.map +1 -1
  36. package/esm/src/signing/mod.js +182 -130
  37. package/esm/src/transports/base.d.ts +2 -1
  38. package/esm/src/transports/base.d.ts.map +1 -1
  39. package/esm/src/transports/http/http_transport.d.ts +3 -2
  40. package/esm/src/transports/http/http_transport.d.ts.map +1 -1
  41. package/esm/src/transports/http/http_transport.js +4 -4
  42. package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +14 -6
  43. package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
  44. package/esm/src/transports/websocket/_hyperliquid_event_target.js +1 -2
  45. package/esm/src/transports/websocket/_reconnecting_websocket.d.ts +2 -1
  46. package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
  47. package/esm/src/transports/websocket/_reconnecting_websocket.js +1 -0
  48. package/esm/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
  49. package/esm/src/transports/websocket/_websocket_async_request.js +17 -21
  50. package/esm/src/transports/websocket/websocket_transport.d.ts +4 -4
  51. package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  52. package/esm/src/transports/websocket/websocket_transport.js +6 -6
  53. package/esm/src/types/exchange/requests.d.ts +492 -306
  54. package/esm/src/types/exchange/requests.d.ts.map +1 -1
  55. package/esm/src/types/exchange/responses.d.ts +105 -25
  56. package/esm/src/types/exchange/responses.d.ts.map +1 -1
  57. package/esm/src/types/explorer/requests.d.ts +3 -3
  58. package/esm/src/types/explorer/requests.d.ts.map +1 -1
  59. package/esm/src/types/explorer/responses.d.ts +1 -1
  60. package/esm/src/types/explorer/responses.d.ts.map +1 -1
  61. package/esm/src/types/info/accounts.d.ts +403 -98
  62. package/esm/src/types/info/accounts.d.ts.map +1 -1
  63. package/esm/src/types/info/assets.d.ts +131 -35
  64. package/esm/src/types/info/assets.d.ts.map +1 -1
  65. package/esm/src/types/info/markets.d.ts +35 -8
  66. package/esm/src/types/info/markets.d.ts.map +1 -1
  67. package/esm/src/types/info/orders.d.ts +62 -17
  68. package/esm/src/types/info/orders.d.ts.map +1 -1
  69. package/esm/src/types/info/requests.d.ts +194 -76
  70. package/esm/src/types/info/requests.d.ts.map +1 -1
  71. package/{script/src/types/info/delegations.d.ts → esm/src/types/info/validators.d.ts} +45 -15
  72. package/esm/src/types/info/validators.d.ts.map +1 -0
  73. package/esm/src/types/info/vaults.d.ts +32 -10
  74. package/esm/src/types/info/vaults.d.ts.map +1 -1
  75. package/esm/src/types/mod.d.ts +2 -2
  76. package/esm/src/types/mod.d.ts.map +1 -1
  77. package/esm/src/types/subscriptions/requests.d.ts +21 -66
  78. package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
  79. package/esm/src/types/subscriptions/responses.d.ts +46 -55
  80. package/esm/src/types/subscriptions/responses.d.ts.map +1 -1
  81. package/package.json +2 -3
  82. package/script/mod.d.ts +2 -2
  83. package/script/mod.d.ts.map +1 -1
  84. package/script/src/base.d.ts +0 -5
  85. package/script/src/base.d.ts.map +1 -1
  86. package/script/src/clients/exchange.d.ts +430 -393
  87. package/script/src/clients/exchange.d.ts.map +1 -1
  88. package/script/src/clients/exchange.js +466 -926
  89. package/script/src/clients/info.d.ts +330 -185
  90. package/script/src/clients/info.d.ts.map +1 -1
  91. package/script/src/clients/info.js +348 -334
  92. package/script/src/clients/multiSign.d.ts +14 -1184
  93. package/script/src/clients/multiSign.d.ts.map +1 -1
  94. package/script/src/clients/multiSign.js +38 -2005
  95. package/script/src/clients/subscription.d.ts +95 -93
  96. package/script/src/clients/subscription.d.ts.map +1 -1
  97. package/script/src/clients/subscription.js +101 -146
  98. package/script/src/signing/_signTypedData/ethers.d.ts +16 -4
  99. package/script/src/signing/_signTypedData/ethers.d.ts.map +1 -1
  100. package/script/src/signing/_signTypedData/ethers.js +2 -2
  101. package/script/src/signing/_signTypedData/mod.d.ts +12 -12
  102. package/script/src/signing/_signTypedData/mod.d.ts.map +1 -1
  103. package/script/src/signing/_signTypedData/mod.js +51 -26
  104. package/script/src/signing/_signTypedData/private_key.d.ts +6 -5
  105. package/script/src/signing/_signTypedData/private_key.d.ts.map +1 -1
  106. package/script/src/signing/_signTypedData/private_key.js +40 -18
  107. package/script/src/signing/_signTypedData/viem.d.ts +27 -6
  108. package/script/src/signing/_signTypedData/viem.d.ts.map +1 -1
  109. package/script/src/signing/_signTypedData/viem.js +2 -2
  110. package/script/src/signing/_sorter.d.ts +12 -21
  111. package/script/src/signing/_sorter.d.ts.map +1 -1
  112. package/script/src/signing/_sorter.js +30 -63
  113. package/script/src/signing/mod.d.ts +177 -127
  114. package/script/src/signing/mod.d.ts.map +1 -1
  115. package/script/src/signing/mod.js +185 -148
  116. package/script/src/transports/base.d.ts +2 -1
  117. package/script/src/transports/base.d.ts.map +1 -1
  118. package/script/src/transports/http/http_transport.d.ts +3 -2
  119. package/script/src/transports/http/http_transport.d.ts.map +1 -1
  120. package/script/src/transports/http/http_transport.js +4 -4
  121. package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +14 -6
  122. package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
  123. package/script/src/transports/websocket/_hyperliquid_event_target.js +1 -2
  124. package/script/src/transports/websocket/_reconnecting_websocket.d.ts +2 -1
  125. package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
  126. package/script/src/transports/websocket/_reconnecting_websocket.js +1 -0
  127. package/script/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
  128. package/script/src/transports/websocket/_websocket_async_request.js +17 -21
  129. package/script/src/transports/websocket/websocket_transport.d.ts +4 -4
  130. package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  131. package/script/src/transports/websocket/websocket_transport.js +6 -6
  132. package/script/src/types/exchange/requests.d.ts +492 -306
  133. package/script/src/types/exchange/requests.d.ts.map +1 -1
  134. package/script/src/types/exchange/responses.d.ts +105 -25
  135. package/script/src/types/exchange/responses.d.ts.map +1 -1
  136. package/script/src/types/explorer/requests.d.ts +3 -3
  137. package/script/src/types/explorer/requests.d.ts.map +1 -1
  138. package/script/src/types/explorer/responses.d.ts +1 -1
  139. package/script/src/types/explorer/responses.d.ts.map +1 -1
  140. package/script/src/types/info/accounts.d.ts +403 -98
  141. package/script/src/types/info/accounts.d.ts.map +1 -1
  142. package/script/src/types/info/assets.d.ts +131 -35
  143. package/script/src/types/info/assets.d.ts.map +1 -1
  144. package/script/src/types/info/markets.d.ts +35 -8
  145. package/script/src/types/info/markets.d.ts.map +1 -1
  146. package/script/src/types/info/orders.d.ts +62 -17
  147. package/script/src/types/info/orders.d.ts.map +1 -1
  148. package/script/src/types/info/requests.d.ts +194 -76
  149. package/script/src/types/info/requests.d.ts.map +1 -1
  150. package/{esm/src/types/info/delegations.d.ts → script/src/types/info/validators.d.ts} +45 -15
  151. package/script/src/types/info/validators.d.ts.map +1 -0
  152. package/script/src/types/info/vaults.d.ts +32 -10
  153. package/script/src/types/info/vaults.d.ts.map +1 -1
  154. package/script/src/types/mod.d.ts +2 -2
  155. package/script/src/types/mod.d.ts.map +1 -1
  156. package/script/src/types/subscriptions/requests.d.ts +21 -66
  157. package/script/src/types/subscriptions/requests.d.ts.map +1 -1
  158. package/script/src/types/subscriptions/responses.d.ts +46 -55
  159. package/script/src/types/subscriptions/responses.d.ts.map +1 -1
  160. package/esm/src/signing/_signTypedData/window.d.ts +0 -29
  161. package/esm/src/signing/_signTypedData/window.d.ts.map +0 -1
  162. package/esm/src/signing/_signTypedData/window.js +0 -30
  163. package/esm/src/types/info/delegations.d.ts.map +0 -1
  164. package/script/src/signing/_signTypedData/window.d.ts +0 -29
  165. package/script/src/signing/_signTypedData/window.d.ts.map +0 -1
  166. package/script/src/signing/_signTypedData/window.js +0 -34
  167. package/script/src/types/info/delegations.d.ts.map +0 -1
  168. /package/esm/src/types/info/{delegations.js → validators.js} +0 -0
  169. /package/script/src/types/info/{delegations.js → validators.js} +0 -0
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MultiSignClient = void 0;
4
- const sha3_1 = require("@noble/hashes/sha3");
5
- const secp256k1_1 = require("@noble/secp256k1");
6
- const mod_js_1 = require("../signing/mod.js");
7
4
  const exchange_js_1 = require("./exchange.js");
5
+ const mod_js_1 = require("../signing/mod.js");
8
6
  /**
9
7
  * Multi-signature exchange client for interacting with the Hyperliquid API.
10
8
  * @typeParam T The transport used to connect to the Hyperliquid API.
@@ -23,7 +21,7 @@ class MultiSignClient extends exchange_js_1.ExchangeClient {
23
21
  *
24
22
  * const multiSignAddress = "0x...";
25
23
  * const signers = [
26
- * "0x...", // Private key; or any other wallet libraries
24
+ * "0x...", // private key; or any other wallet libraries
27
25
  * ] as const;
28
26
  *
29
27
  * const transport = new hl.HttpTransport();
@@ -45,461 +43,23 @@ class MultiSignClient extends exchange_js_1.ExchangeClient {
45
43
  configurable: true,
46
44
  });
47
45
  }
48
- /**
49
- * Approve an agent to sign on behalf of the master account.
50
- * @param args - The parameters for the request.
51
- * @param signal - An optional abort signal
52
- * @returns Successful response without specific data.
53
- *
54
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
55
- * @throws {TransportError} When the transport layer throws an error.
56
- *
57
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#approve-an-api-wallet
58
- * @example
59
- * ```ts
60
- * import * as hl from "@nktkas/hyperliquid";
61
- *
62
- * const multiSignAddress = "0x...";
63
- * const signers = [
64
- * "0x...", // Private key; or any other wallet libraries
65
- * ] as const;
66
- *
67
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
68
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
69
- *
70
- * await multiSignClient.approveAgent({ agentAddress: "0x...", agentName: "..." });
71
- * ```
72
- */
73
- async approveAgent(...[args, signal]) {
74
- // Destructure the parameters
75
- const { ...actionArgs } = args;
76
- // Construct an action
77
- const nonce = await this.nonceManager();
78
- const action = mod_js_1.actionSorter.approveAgent({
79
- type: "approveAgent",
80
- hyperliquidChain: this._getHyperliquidChain(),
81
- signatureChainId: await this._getSignatureChainId(),
82
- nonce,
83
- ...actionArgs,
84
- });
85
- // Sign the action
86
- const outerSigner = await this._getWalletAddress(this.signers[0]);
87
- const signatures = await this._multiSignUserSignedAction({ action, outerSigner });
88
- if (action.agentName === "")
89
- action.agentName = null;
90
- // Send a multi-sig action
91
- return super.multiSig({
92
- signatures,
93
- payload: {
94
- multiSigUser: this.multiSignAddress,
95
- outerSigner,
96
- action,
97
- },
98
- nonce,
99
- }, signal);
100
- }
101
- /**
102
- * Approve a maximum fee rate for a builder.
103
- * @param args - The parameters for the request.
104
- * @param signal - An optional abort signal.
105
- * @returns Successful response without specific data.
106
- *
107
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
108
- * @throws {TransportError} When the transport layer throws an error.
109
- *
110
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#approve-a-builder-fee
111
- * @example
112
- * ```ts
113
- * import * as hl from "@nktkas/hyperliquid";
114
- *
115
- * const multiSignAddress = "0x...";
116
- * const signers = [
117
- * "0x...", // Private key; or any other wallet libraries
118
- * ] as const;
119
- *
120
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
121
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
122
- *
123
- * await multiSignClient.approveBuilderFee({ maxFeeRate: "0.01%", builder: "0x..." });
124
- * ```
125
- */
126
- async approveBuilderFee(...[args, signal]) {
127
- // Destructure the parameters
128
- const { ...actionArgs } = args;
129
- // Construct an action
130
- const nonce = await this.nonceManager();
131
- const action = mod_js_1.actionSorter.approveBuilderFee({
132
- type: "approveBuilderFee",
133
- hyperliquidChain: this._getHyperliquidChain(),
134
- signatureChainId: await this._getSignatureChainId(),
135
- nonce,
136
- ...actionArgs,
137
- });
138
- // Sign the action
139
- const outerSigner = await this._getWalletAddress(this.signers[0]);
140
- const signatures = await this._multiSignUserSignedAction({ action, outerSigner });
141
- // Send a multi-sig action
142
- return super.multiSig({
143
- signatures,
144
- payload: {
145
- multiSigUser: this.multiSignAddress,
146
- outerSigner,
147
- action,
148
- },
149
- nonce,
150
- }, signal);
151
- }
152
- /**
153
- * Modify multiple orders.
154
- * @param args - The parameters for the request.
155
- * @param signal - An optional abort signal.
156
- * @returns Successful variant of {@link OrderResponse} without error statuses.
157
- *
158
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
159
- * @throws {TransportError} When the transport layer throws an error.
160
- *
161
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders
162
- * @example
163
- * ```ts
164
- * import * as hl from "@nktkas/hyperliquid";
165
- *
166
- * const multiSignAddress = "0x...";
167
- * const signers = [
168
- * "0x...", // Private key; or any other wallet libraries
169
- * ] as const;
170
- *
171
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
172
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
173
- *
174
- * const data = await multiSignClient.batchModify({
175
- * modifies: [
176
- * {
177
- * oid: 123,
178
- * order: {
179
- * a: 0,
180
- * b: true,
181
- * p: "31000",
182
- * s: "0.2",
183
- * r: false,
184
- * t: { limit: { tif: "Gtc" } },
185
- * },
186
- * },
187
- * ],
188
- * });
189
- * ```
190
- */
191
- async batchModify(...[args, signal]) {
192
- // Destructure the parameters
193
- const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
194
- // Construct an action
195
- const nonce = await this.nonceManager();
196
- const action = mod_js_1.actionSorter.batchModify({ type: "batchModify", ...actionArgs });
197
- // Send a multi-sig action
198
- const outerSigner = await this._getWalletAddress(this.signers[0]);
199
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner, vaultAddress, expiresAfter });
200
- // Send a multi-sig action
201
- return super.multiSig({
202
- signatures,
203
- payload: {
204
- multiSigUser: this.multiSignAddress,
205
- outerSigner,
206
- action,
207
- },
208
- nonce,
209
- vaultAddress,
210
- expiresAfter,
211
- }, signal);
212
- }
213
- /**
214
- * Cancel order(s).
215
- * @param args - The parameters for the request.
216
- * @param signal - An optional abort signal.
217
- * @returns Successful variant of {@link CancelResponse} without error statuses.
218
- *
219
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
220
- * @throws {TransportError} When the transport layer throws an error.
221
- *
222
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s
223
- * @example
224
- * ```ts
225
- * import * as hl from "@nktkas/hyperliquid";
226
- *
227
- * const multiSignAddress = "0x...";
228
- * const signers = [
229
- * "0x...", // Private key; or any other wallet libraries
230
- * ] as const;
231
- *
232
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
233
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
234
- *
235
- * const data = await multiSignClient.cancel({
236
- * cancels: [
237
- * { a: 0, o: 123 },
238
- * ],
239
- * });
240
- * ```
241
- */
242
- async cancel(...[args, signal]) {
243
- // Destructure the parameters
244
- const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
245
- // Construct an action
246
- const nonce = await this.nonceManager();
247
- const action = mod_js_1.actionSorter.cancel({ type: "cancel", ...actionArgs });
248
- // Send a multi-sig action
249
- const outerSigner = await this._getWalletAddress(this.signers[0]);
250
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner, vaultAddress, expiresAfter });
251
- // Send a multi-sig action
252
- return super.multiSig({
253
- signatures,
254
- payload: {
255
- multiSigUser: this.multiSignAddress,
256
- outerSigner,
257
- action,
258
- },
259
- nonce,
260
- vaultAddress,
261
- expiresAfter,
262
- }, signal);
263
- }
264
- /**
265
- * Cancel order(s) by cloid.
266
- * @param args - The parameters for the request.
267
- * @param signal - An optional abort signal.
268
- * @returns Successful variant of {@link CancelResponse} without error statuses.
269
- *
270
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
271
- * @throws {TransportError} When the transport layer throws an error.
272
- *
273
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s-by-cloid
274
- * @example
275
- * ```ts
276
- * import * as hl from "@nktkas/hyperliquid";
277
- *
278
- * const multiSignAddress = "0x...";
279
- * const signers = [
280
- * "0x...", // Private key; or any other wallet libraries
281
- * ] as const;
282
- *
283
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
284
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
285
- *
286
- * const data = await multiSignClient.cancelByCloid({
287
- * cancels: [
288
- * { asset: 0, cloid: "0x..." },
289
- * ],
290
- * });
291
- * ```
292
- */
293
- async cancelByCloid(...[args, signal]) {
294
- // Destructure the parameters
295
- const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
296
- // Construct an action
297
- const nonce = await this.nonceManager();
298
- const action = mod_js_1.actionSorter.cancelByCloid({ type: "cancelByCloid", ...actionArgs });
299
- // Send a multi-sig action
300
- const outerSigner = await this._getWalletAddress(this.signers[0]);
301
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner, vaultAddress, expiresAfter });
302
- // Send a multi-sig action
303
- return super.multiSig({
304
- signatures,
305
- payload: {
306
- multiSigUser: this.multiSignAddress,
307
- outerSigner,
308
- action,
309
- },
310
- nonce,
311
- vaultAddress,
312
- expiresAfter,
313
- }, signal);
314
- }
315
- /**
316
- * Transfer native token from the user's spot account into staking for delegating to validators.
317
- * @param args - The parameters for the request.
318
- * @param signal - An optional abort signal.
319
- * @returns Successful response without specific data.
320
- *
321
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
322
- * @throws {TransportError} When the transport layer throws an error.
323
- *
324
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#deposit-into-staking
325
- * @example
326
- * ```ts
327
- * import * as hl from "@nktkas/hyperliquid";
328
- *
329
- * const multiSignAddress = "0x...";
330
- * const signers = [
331
- * "0x...", // Private key; or any other wallet libraries
332
- * ] as const;
333
- *
334
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
335
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
336
- *
337
- * await multiSignClient.cDeposit({ wei: 1 * 1e8 });
338
- * ```
339
- */
340
- async cDeposit(...[args, signal]) {
341
- // Destructure the parameters
342
- const { ...actionArgs } = args;
343
- // Construct an action
344
- const nonce = await this.nonceManager();
345
- const action = mod_js_1.actionSorter.cDeposit({
346
- type: "cDeposit",
347
- hyperliquidChain: this._getHyperliquidChain(),
348
- signatureChainId: await this._getSignatureChainId(),
349
- nonce,
350
- ...actionArgs,
351
- });
352
- // Sign the action
353
- const outerSigner = await this._getWalletAddress(this.signers[0]);
354
- const signatures = await this._multiSignUserSignedAction({ action, outerSigner });
355
- // Send a multi-sig action
356
- return super.multiSig({
357
- signatures,
358
- payload: {
359
- multiSigUser: this.multiSignAddress,
360
- outerSigner,
361
- action,
362
- },
363
- nonce,
364
- }, signal);
365
- }
366
- /**
367
- * Claim rewards from referral program.
368
- * @param args - The parameters for the request.
369
- * @param signal - An optional abort signal.
370
- * @returns Successful response without specific data.
371
- *
372
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
373
- * @throws {TransportError} When the transport layer throws an error.
374
- *
375
- * @see null
376
- * @example
377
- * ```ts
378
- * import * as hl from "@nktkas/hyperliquid";
379
- *
380
- * const multiSignAddress = "0x...";
381
- * const signers = [
382
- * "0x...", // Private key; or any other wallet libraries
383
- * ] as const;
384
- *
385
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
386
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
387
- *
388
- * await multiSignClient.claimRewards();
389
- * ```
390
- */
391
- async claimRewards(...[signal]) {
392
- // Construct an action
393
- const nonce = await this.nonceManager();
394
- const action = mod_js_1.actionSorter.claimRewards({ type: "claimRewards" });
395
- // Send a multi-sig action
396
- const outerSigner = await this._getWalletAddress(this.signers[0]);
397
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner });
398
- // Send a multi-sig action
399
- return super.multiSig({
400
- signatures,
401
- payload: {
402
- multiSigUser: this.multiSignAddress,
403
- outerSigner,
404
- action,
405
- },
406
- nonce,
407
- }, signal);
408
- }
409
- /**
410
- * Convert a single-signature account to a multi-signature account or vice versa.
411
- * @param args - The parameters for the request.
412
- * @param signal - An optional abort signal.
413
- * @returns Successful response without specific data.
414
- *
415
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
416
- * @throws {TransportError} When the transport layer throws an error.
417
- *
418
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/hypercore/multi-sig
419
- * @example
420
- * ```ts
421
- * import * as hl from "@nktkas/hyperliquid";
422
- *
423
- * const multiSignAddress = "0x...";
424
- * const signers = [
425
- * "0x...", // Private key; or any other wallet libraries
426
- * ] as const;
427
- *
428
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
429
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
430
- *
431
- * // Convert to multi-sig user
432
- * await multiSignClient.convertToMultiSigUser({
433
- * authorizedUsers: ["0x...", "0x...", "0x..."],
434
- * threshold: 2,
435
- * });
436
- *
437
- * // Convert to single-sig user
438
- * await multiSignClient.convertToMultiSigUser(null);
439
- * ```
440
- */
441
- async convertToMultiSigUser(...[args, signal]) {
442
- // Destructure the parameters
443
- const actionArgs = args;
444
- // Construct an action
445
- const nonce = await this.nonceManager();
446
- const action = mod_js_1.actionSorter.convertToMultiSigUser({
447
- type: "convertToMultiSigUser",
448
- hyperliquidChain: this._getHyperliquidChain(),
449
- signatureChainId: await this._getSignatureChainId(),
450
- signers: JSON.stringify(actionArgs),
451
- nonce,
452
- });
453
- // Sign the action
454
- const outerSigner = await this._getWalletAddress(this.signers[0]);
455
- const signatures = await this._multiSignUserSignedAction({ action, outerSigner });
456
- // Send a multi-sig action
457
- return super.multiSig({
458
- signatures,
459
- payload: {
460
- multiSigUser: this.multiSignAddress,
461
- outerSigner,
462
- action,
463
- },
464
- nonce,
465
- }, signal);
466
- }
467
- /**
468
- * Create a sub-account.
469
- * @param args - The parameters for the request.
470
- * @param signal - An optional abort signal.
471
- * @returns Response for creating a sub-account.
472
- *
473
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
474
- * @throws {TransportError} When the transport layer throws an error.
475
- *
476
- * @see null
477
- * @example
478
- * ```ts
479
- * import * as hl from "@nktkas/hyperliquid";
480
- *
481
- * const multiSignAddress = "0x...";
482
- * const signers = [
483
- * "0x...", // Private key; or any other wallet libraries
484
- * ] as const;
485
- *
486
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
487
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
488
- *
489
- * const data = await multiSignClient.createSubAccount({ name: "..." });
490
- * ```
491
- */
492
- async createSubAccount(...[args, signal]) {
493
- // Destructure the parameters
494
- const { ...actionArgs } = args;
495
- // Construct an action
46
+ async _executeL1Action(request, signal) {
47
+ const { action, vaultAddress, expiresAfter } = request;
48
+ // Sign an L1 action
496
49
  const nonce = await this.nonceManager();
497
- const action = mod_js_1.actionSorter.createSubAccount({ type: "createSubAccount", ...actionArgs });
498
- // Send a multi-sig action
499
- const outerSigner = await this._getWalletAddress(this.signers[0]);
500
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner });
501
- // Send a multi-sig action
502
- return super.multiSig({
50
+ const outerSigner = await (0, mod_js_1.getWalletAddress)(this.signers[0]);
51
+ const signatures = await Promise.all(this.signers.map(async (signer) => {
52
+ return await (0, mod_js_1.signL1Action)({
53
+ wallet: signer,
54
+ action: [this.multiSignAddress.toLowerCase(), outerSigner.toLowerCase(), action],
55
+ nonce,
56
+ isTestnet: this.isTestnet,
57
+ vaultAddress,
58
+ expiresAfter,
59
+ });
60
+ }));
61
+ // Send a request via multi-sign action
62
+ return await super.multiSig({
503
63
  signatures,
504
64
  payload: {
505
65
  multiSigUser: this.multiSignAddress,
@@ -507,44 +67,26 @@ class MultiSignClient extends exchange_js_1.ExchangeClient {
507
67
  action,
508
68
  },
509
69
  nonce,
510
- }, signal);
70
+ }, { signal, vaultAddress, expiresAfter });
511
71
  }
512
- /**
513
- * Create a vault.
514
- * @param args - The parameters for the request.
515
- * @param signal - An optional abort signal.
516
- * @returns Response for creating a vault.
517
- *
518
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
519
- * @throws {TransportError} When the transport layer throws an error.
520
- *
521
- * @see null
522
- * @example
523
- * ```ts
524
- * import * as hl from "@nktkas/hyperliquid";
525
- *
526
- * const multiSignAddress = "0x...";
527
- * const signers = [
528
- * "0x...", // Private key; or any other wallet libraries
529
- * ] as const;
530
- *
531
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
532
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
533
- *
534
- * const data = await multiSignClient.createVault({ name: "...", description: "...", initialUsd: 100 * 1e6 });
535
- * ```
536
- */
537
- async createVault(...[args, signal]) {
538
- // Destructure the parameters
539
- const { ...actionArgs } = args;
540
- // Construct an action
541
- const nonce = await this.nonceManager();
542
- const action = mod_js_1.actionSorter.createVault({ type: "createVault", nonce, ...actionArgs });
543
- // Send a multi-sig action
544
- const outerSigner = await this._getWalletAddress(this.signers[0]);
545
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner });
546
- // Send a multi-sig action
547
- return super.multiSig({
72
+ async _executeUserSignedAction(request, signal) {
73
+ const { action } = request;
74
+ // Sign a user-signed action
75
+ const nonce = "nonce" in action ? action.nonce : action.time;
76
+ const outerSigner = await (0, mod_js_1.getWalletAddress)(this.signers[0]);
77
+ const signatures = await Promise.all(this.signers.map(async (signer) => {
78
+ return await (0, mod_js_1.signUserSignedAction)({
79
+ wallet: signer,
80
+ action: {
81
+ payloadMultiSigUser: this.multiSignAddress,
82
+ outerSigner,
83
+ ...action,
84
+ },
85
+ types: mod_js_1.userSignedActionEip712Types[action.type],
86
+ });
87
+ }));
88
+ // Send a request via multi-sign action
89
+ return await super.multiSig({
548
90
  signatures,
549
91
  payload: {
550
92
  multiSigUser: this.multiSignAddress,
@@ -552,1516 +94,7 @@ class MultiSignClient extends exchange_js_1.ExchangeClient {
552
94
  action,
553
95
  },
554
96
  nonce,
555
- }, signal);
556
- }
557
- /**
558
- * Jail or unjail self as a validator signer.
559
- * @param args - The parameters for the request.
560
- * @param signal - An optional abort signal.
561
- * @returns Successful response without specific data.
562
- *
563
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
564
- * @throws {TransportError} When the transport layer throws an error.
565
- *
566
- * @see null
567
- * @example
568
- * ```ts
569
- * import * as hl from "@nktkas/hyperliquid";
570
- *
571
- * const multiSignAddress = "0x...";
572
- * const signers = [
573
- * "0x...", // Private key; or any other wallet libraries
574
- * ] as const;
575
- *
576
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
577
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
578
- *
579
- * // Jail self
580
- * await multiSignClient.cSignerAction({ jailSelf: null });
581
- *
582
- * // Unjail self
583
- * await multiSignClient.cSignerAction({ unjailSelf: null });
584
- * ```
585
- */
586
- async cSignerAction(...[args, signal]) {
587
- // Destructure the parameters
588
- const { expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
589
- // Construct an action
590
- const nonce = await this.nonceManager();
591
- const action = mod_js_1.actionSorter.CSignerAction({ type: "CSignerAction", ...actionArgs });
592
- // Send a multi-sig action
593
- const outerSigner = await this._getWalletAddress(this.signers[0]);
594
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner, expiresAfter });
595
- // Send a multi-sig action
596
- return super.multiSig({
597
- signatures,
598
- payload: {
599
- multiSigUser: this.multiSignAddress,
600
- outerSigner,
601
- action,
602
- },
603
- nonce,
604
- expiresAfter,
605
- }, signal);
606
- }
607
- /**
608
- * Action related to validator management.
609
- * @param args - The parameters for the request.
610
- * @param signal - An optional abort signal.
611
- * @returns Successful response without specific data.
612
- *
613
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
614
- * @throws {TransportError} When the transport layer throws an error.
615
- *
616
- * @example
617
- * ```ts
618
- * import * as hl from "@nktkas/hyperliquid";
619
- *
620
- * const multiSignAddress = "0x...";
621
- * const signers = [
622
- * "0x...", // Private key; or any other wallet libraries
623
- * ] as const;
624
- *
625
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
626
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
627
- *
628
- * // Change validator profile
629
- * await multiSignClient.cValidatorAction({
630
- * changeProfile: {
631
- * name: "...",
632
- * description: "...",
633
- * unjailed: true,
634
- * }
635
- * });
636
- *
637
- * // Register a new validator
638
- * await multiSignClient.cValidatorAction({
639
- * register: {
640
- * profile: {
641
- * node_ip: { Ip: "1.2.3.4" },
642
- * name: "...",
643
- * description: "...",
644
- * delegations_disabled: true,
645
- * commission_bps: 1,
646
- * signer: "0x...",
647
- * },
648
- * unjailed: false,
649
- * initial_wei: 1,
650
- * },
651
- * });
652
- *
653
- * // Unregister a validator
654
- * await multiSignClient.cValidatorAction({ unregister: null });
655
- * ```
656
- */
657
- async cValidatorAction(...[args, signal]) {
658
- // Destructure the parameters
659
- const { expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
660
- // Construct an action
661
- const nonce = await this.nonceManager();
662
- const action = mod_js_1.actionSorter.CValidatorAction({ type: "CValidatorAction", ...actionArgs });
663
- // Send a multi-sig action
664
- const outerSigner = await this._getWalletAddress(this.signers[0]);
665
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner, expiresAfter });
666
- // Send a multi-sig action
667
- return super.multiSig({
668
- signatures,
669
- payload: {
670
- multiSigUser: this.multiSignAddress,
671
- outerSigner,
672
- action,
673
- },
674
- nonce,
675
- expiresAfter,
676
- }, signal);
677
- }
678
- /**
679
- * Transfer native token from staking into the user's spot account.
680
- * @param args - The parameters for the request.
681
- * @param signal - An optional abort signal.
682
- * @returns Successful response without specific data.
683
- *
684
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
685
- * @throws {TransportError} When the transport layer throws an error.
686
- *
687
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#withdraw-from-staking
688
- * @example
689
- * ```ts
690
- * import * as hl from "@nktkas/hyperliquid";
691
- *
692
- * const multiSignAddress = "0x...";
693
- * const signers = [
694
- * "0x...", // Private key; or any other wallet libraries
695
- * ] as const;
696
- *
697
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
698
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
699
- *
700
- * await multiSignClient.cWithdraw({ wei: 1 * 1e8 });
701
- * ```
702
- */
703
- async cWithdraw(...[args, signal]) {
704
- // Destructure the parameters
705
- const { ...actionArgs } = args;
706
- // Construct an action
707
- const nonce = await this.nonceManager();
708
- const action = mod_js_1.actionSorter.cWithdraw({
709
- type: "cWithdraw",
710
- hyperliquidChain: this._getHyperliquidChain(),
711
- signatureChainId: await this._getSignatureChainId(),
712
- nonce,
713
- ...actionArgs,
714
- });
715
- // Sign the action
716
- const outerSigner = await this._getWalletAddress(this.signers[0]);
717
- const signatures = await this._multiSignUserSignedAction({ action, outerSigner });
718
- // Send a multi-sig action
719
- return super.multiSig({
720
- signatures,
721
- payload: {
722
- multiSigUser: this.multiSignAddress,
723
- outerSigner,
724
- action,
725
- },
726
- nonce,
727
- }, signal);
728
- }
729
- /**
730
- * Configure block type for EVM transactions.
731
- * @param args - The parameters for the request.
732
- * @param signal - An optional abort signal.
733
- * @returns Response for creating a sub-account.
734
- *
735
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
736
- * @throws {TransportError} When the transport layer throws an error.
737
- *
738
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/evm/dual-block-architecture
739
- * @example
740
- * ```ts
741
- * import * as hl from "@nktkas/hyperliquid";
742
- *
743
- * const multiSignAddress = "0x...";
744
- * const signers = [
745
- * "0x...", // Private key; or any other wallet libraries
746
- * ] as const;
747
- *
748
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
749
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
750
- *
751
- * const data = await multiSignClient.evmUserModify({ usingBigBlocks: true });
752
- * ```
753
- */
754
- async evmUserModify(...[args, signal]) {
755
- // Destructure the parameters
756
- const { ...actionArgs } = args;
757
- // Construct an action
758
- const nonce = await this.nonceManager();
759
- const action = mod_js_1.actionSorter.evmUserModify({ type: "evmUserModify", ...actionArgs });
760
- // Send a multi-sig action
761
- const outerSigner = await this._getWalletAddress(this.signers[0]);
762
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner });
763
- // Send a multi-sig action
764
- return super.multiSig({
765
- signatures,
766
- payload: {
767
- multiSigUser: this.multiSignAddress,
768
- outerSigner,
769
- action,
770
- },
771
- nonce,
772
- }, signal);
773
- }
774
- /**
775
- * Modify an order.
776
- * @param args - The parameters for the request.
777
- * @param signal - An optional abort signal.
778
- * @returns Successful response without specific data.
779
- *
780
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
781
- * @throws {TransportError} When the transport layer throws an error.
782
- *
783
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-an-order
784
- * @example
785
- * ```ts
786
- * import * as hl from "@nktkas/hyperliquid";
787
- *
788
- * const multiSignAddress = "0x...";
789
- * const signers = [
790
- * "0x...", // Private key; or any other wallet libraries
791
- * ] as const;
792
- *
793
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
794
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
795
- *
796
- * await multiSignClient.modify({
797
- * oid: 123,
798
- * order: {
799
- * a: 0,
800
- * b: true,
801
- * p: "31000",
802
- * s: "0.2",
803
- * r: false,
804
- * t: { limit: { tif: "Gtc" } },
805
- * c: "0x...",
806
- * },
807
- * });
808
- * ```
809
- */
810
- async modify(...[args, signal]) {
811
- // Destructure the parameters
812
- const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
813
- // Construct an action
814
- const nonce = await this.nonceManager();
815
- const action = mod_js_1.actionSorter.modify({ type: "modify", ...actionArgs });
816
- // Send a multi-sig action
817
- const outerSigner = await this._getWalletAddress(this.signers[0]);
818
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner, vaultAddress, expiresAfter });
819
- // Send a multi-sig action
820
- return super.multiSig({
821
- signatures,
822
- payload: {
823
- multiSigUser: this.multiSignAddress,
824
- outerSigner,
825
- action,
826
- },
827
- nonce,
828
- vaultAddress,
829
- expiresAfter,
830
- }, signal);
831
- }
832
- /**
833
- * @multisign Not implemented
834
- */
835
- multiSig(...[_args, _signal]) {
836
- throw new Error("Not implemented"); // FIXME
837
- }
838
- /**
839
- * Place an order(s).
840
- * @param args - The parameters for the request.
841
- * @param signal - An optional abort signal.
842
- * @returns Successful variant of {@link OrderResponse} without error statuses.
843
- *
844
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
845
- * @throws {TransportError} When the transport layer throws an error.
846
- *
847
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-an-order
848
- * @example
849
- * ```ts
850
- * import * as hl from "@nktkas/hyperliquid";
851
- *
852
- * const multiSignAddress = "0x...";
853
- * const signers = [
854
- * "0x...", // Private key; or any other wallet libraries
855
- * ] as const;
856
- *
857
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
858
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
859
- *
860
- * const data = await multiSignClient.order({
861
- * orders: [
862
- * {
863
- * a: 0,
864
- * b: true,
865
- * p: "30000",
866
- * s: "0.1",
867
- * r: false,
868
- * t: { limit: { tif: "Gtc" } },
869
- * c: "0x...",
870
- * },
871
- * ],
872
- * grouping: "na",
873
- * });
874
- * ```
875
- */
876
- async order(...[args, signal]) {
877
- // Destructure the parameters
878
- const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
879
- // Construct an action
880
- const nonce = await this.nonceManager();
881
- const action = mod_js_1.actionSorter.order({ type: "order", ...actionArgs });
882
- // Send a multi-sig action
883
- const outerSigner = await this._getWalletAddress(this.signers[0]);
884
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner, vaultAddress, expiresAfter });
885
- // Send a multi-sig action
886
- return super.multiSig({
887
- signatures,
888
- payload: {
889
- multiSigUser: this.multiSignAddress,
890
- outerSigner,
891
- action,
892
- },
893
- nonce,
894
- vaultAddress,
895
- expiresAfter,
896
- }, signal);
897
- }
898
- /**
899
- * Deploying HIP-3 assets.
900
- * @param args - The parameters for the request.
901
- * @param signal - An optional abort signal.
902
- * @returns Successful response without specific data.
903
- *
904
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
905
- * @throws {TransportError} When the transport layer throws an error.
906
- *
907
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/deploying-hip-3-assets
908
- * @example
909
- * ```ts
910
- * import * as hl from "@nktkas/hyperliquid";
911
- *
912
- * const multiSignAddress = "0x...";
913
- * const signers = [
914
- * "0x...", // Private key; or any other wallet libraries
915
- * ] as const;
916
- *
917
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
918
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
919
- *
920
- * await multiSignClient.perpDeploy({
921
- * registerAsset: {
922
- * maxGas: 1000000,
923
- * assetRequest: {
924
- * coin: "USDC",
925
- * szDecimals: 8,
926
- * oraclePx: "1",
927
- * marginTableId: 1,
928
- * onlyIsolated: false,
929
- * },
930
- * dex: "test",
931
- * },
932
- * });
933
- * ```
934
- */
935
- async perpDeploy(...[args, signal]) {
936
- // Destructure the parameters
937
- const { ...actionArgs } = args;
938
- // Construct an action
939
- const nonce = await this.nonceManager();
940
- const action = mod_js_1.actionSorter.perpDeploy({ type: "perpDeploy", ...actionArgs });
941
- // Send a multi-sig action
942
- const outerSigner = await this._getWalletAddress(this.signers[0]);
943
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner });
944
- // Send a multi-sig action
945
- return super.multiSig({
946
- signatures,
947
- payload: {
948
- multiSigUser: this.multiSignAddress,
949
- outerSigner,
950
- action,
951
- },
952
- nonce,
953
- }, signal);
954
- }
955
- /**
956
- * Transfer funds between Spot account and Perp dex account.
957
- * @param args - The parameters for the request.
958
- * @param signal - An optional abort signal.
959
- * @returns Successful response without specific data.
960
- *
961
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
962
- * @throws {TransportError} When the transport layer throws an error.
963
- *
964
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#transfer-from-spot-account-to-perp-account-and-vice-versa
965
- * @example
966
- * ```ts
967
- * import * as hl from "@nktkas/hyperliquid";
968
- *
969
- * const multiSignAddress = "0x...";
970
- * const signers = [
971
- * "0x...", // Private key; or any other wallet libraries
972
- * ] as const;
973
- *
974
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
975
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
976
- *
977
- * await multiSignClient.perpDexClassTransfer({ dex: "test", token: "USDC", amount: "1", toPerp: true });
978
- * ```
979
- */
980
- async perpDexClassTransfer(...[args, signal]) {
981
- // Destructure the parameters
982
- const { ...actionArgs } = args;
983
- // Construct an action
984
- const nonce = await this.nonceManager();
985
- const action = mod_js_1.actionSorter.PerpDexClassTransfer({
986
- type: "PerpDexClassTransfer",
987
- hyperliquidChain: this._getHyperliquidChain(),
988
- signatureChainId: await this._getSignatureChainId(),
989
- nonce,
990
- ...actionArgs,
991
- });
992
- // Sign the action
993
- const outerSigner = await this._getWalletAddress(this.signers[0]);
994
- const signatures = await this._multiSignUserSignedAction({ action, outerSigner });
995
- // Send a multi-sig action
996
- return super.multiSig({
997
- signatures,
998
- payload: {
999
- multiSigUser: this.multiSignAddress,
1000
- outerSigner,
1001
- action,
1002
- },
1003
- nonce,
1004
- }, signal);
1005
- }
1006
- /**
1007
- * Create a referral code.
1008
- * @param args - The parameters for the request.
1009
- * @param signal - An optional abort signal.
1010
- * @returns Successful response without specific data.
1011
- *
1012
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
1013
- * @throws {TransportError} When the transport layer throws an error.
1014
- *
1015
- * @see null
1016
- * @example
1017
- * ```ts
1018
- * import * as hl from "@nktkas/hyperliquid";
1019
- *
1020
- * const multiSignAddress = "0x...";
1021
- * const signers = [
1022
- * "0x...", // Private key; or any other wallet libraries
1023
- * ] as const;
1024
- *
1025
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1026
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1027
- *
1028
- * await multiSignClient.registerReferrer({ code: "..." });
1029
- * ```
1030
- */
1031
- async registerReferrer(...[args, signal]) {
1032
- // Destructure the parameters
1033
- const { ...actionArgs } = args;
1034
- // Construct an action
1035
- const nonce = await this.nonceManager();
1036
- const action = mod_js_1.actionSorter.registerReferrer({ type: "registerReferrer", ...actionArgs });
1037
- // Send a multi-sig action
1038
- const outerSigner = await this._getWalletAddress(this.signers[0]);
1039
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner });
1040
- // Send a multi-sig action
1041
- return super.multiSig({
1042
- signatures,
1043
- payload: {
1044
- multiSigUser: this.multiSignAddress,
1045
- outerSigner,
1046
- action,
1047
- },
1048
- nonce,
1049
- }, signal);
1050
- }
1051
- /**
1052
- * Reserve additional rate-limited actions for a fee.
1053
- * @param args - The parameters for the request.
1054
- * @param signal - An optional abort signal.
1055
- * @returns Successful response without specific data.
1056
- *
1057
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
1058
- * @throws {TransportError} When the transport layer throws an error.
1059
- *
1060
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#reserve-additional-actions
1061
- * @example
1062
- * ```ts
1063
- * import * as hl from "@nktkas/hyperliquid";
1064
- *
1065
- * const multiSignAddress = "0x...";
1066
- * const signers = [
1067
- * "0x...", // Private key; or any other wallet libraries
1068
- * ] as const;
1069
- *
1070
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1071
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1072
- *
1073
- * await multiSignClient.reserveRequestWeight({ weight: 10 });
1074
- * ```
1075
- */
1076
- async reserveRequestWeight(...[args, signal]) {
1077
- // Destructure the parameters
1078
- const { expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
1079
- // Construct an action
1080
- const nonce = await this.nonceManager();
1081
- const action = mod_js_1.actionSorter.reserveRequestWeight({ type: "reserveRequestWeight", ...actionArgs });
1082
- // Send a multi-sig action
1083
- const outerSigner = await this._getWalletAddress(this.signers[0]);
1084
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner, expiresAfter });
1085
- // Send a multi-sig action
1086
- return super.multiSig({
1087
- signatures,
1088
- payload: {
1089
- multiSigUser: this.multiSignAddress,
1090
- outerSigner,
1091
- action,
1092
- },
1093
- nonce,
1094
- expiresAfter,
1095
- }, signal);
1096
- }
1097
- async scheduleCancel(args_or_signal, maybeSignal) {
1098
- const args = args_or_signal instanceof AbortSignal ? {} : args_or_signal ?? {};
1099
- const signal = args_or_signal instanceof AbortSignal ? args_or_signal : maybeSignal;
1100
- // Destructure the parameters
1101
- const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
1102
- // Construct an action
1103
- const nonce = await this.nonceManager();
1104
- const action = mod_js_1.actionSorter.scheduleCancel({ type: "scheduleCancel", ...actionArgs });
1105
- // Send a multi-sig action
1106
- const outerSigner = await this._getWalletAddress(this.signers[0]);
1107
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner, vaultAddress, expiresAfter });
1108
- // Send a multi-sig action
1109
- return super.multiSig({
1110
- signatures,
1111
- payload: {
1112
- multiSigUser: this.multiSignAddress,
1113
- outerSigner,
1114
- action,
1115
- },
1116
- nonce,
1117
- vaultAddress,
1118
- expiresAfter,
1119
- }, signal);
1120
- }
1121
- /**
1122
- * Set the display name in the leaderboard.
1123
- * @param args - The parameters for the request.
1124
- * @param signal - An optional abort signal.
1125
- * @returns Successful response without specific data.
1126
- *
1127
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
1128
- * @throws {TransportError} When the transport layer throws an error.
1129
- *
1130
- * @see null
1131
- * @example
1132
- * ```ts
1133
- * import * as hl from "@nktkas/hyperliquid";
1134
- *
1135
- * const multiSignAddress = "0x...";
1136
- * const signers = [
1137
- * "0x...", // Private key; or any other wallet libraries
1138
- * ] as const;
1139
- *
1140
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1141
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1142
- *
1143
- * await multiSignClient.setDisplayName({ displayName: "..." });
1144
- * ```
1145
- */
1146
- async setDisplayName(...[args, signal]) {
1147
- // Destructure the parameters
1148
- const { ...actionArgs } = args;
1149
- // Construct an action
1150
- const nonce = await this.nonceManager();
1151
- const action = mod_js_1.actionSorter.setDisplayName({ type: "setDisplayName", ...actionArgs });
1152
- // Send a multi-sig action
1153
- const outerSigner = await this._getWalletAddress(this.signers[0]);
1154
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner });
1155
- // Send a multi-sig action
1156
- return super.multiSig({
1157
- signatures,
1158
- payload: {
1159
- multiSigUser: this.multiSignAddress,
1160
- outerSigner,
1161
- action,
1162
- },
1163
- nonce,
1164
- }, signal);
1165
- }
1166
- /**
1167
- * Set a referral code.
1168
- * @param args - The parameters for the request.
1169
- * @param signal - An optional abort signal.
1170
- * @returns Successful response without specific data.
1171
- *
1172
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
1173
- * @throws {TransportError} When the transport layer throws an error.
1174
- *
1175
- * @see null
1176
- * @example
1177
- * ```ts
1178
- * import * as hl from "@nktkas/hyperliquid";
1179
- *
1180
- * const multiSignAddress = "0x...";
1181
- * const signers = [
1182
- * "0x...", // Private key; or any other wallet libraries
1183
- * ] as const;
1184
- *
1185
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1186
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1187
- *
1188
- * await multiSignClient.setReferrer({ code: "..." });
1189
- * ```
1190
- */
1191
- async setReferrer(...[args, signal]) {
1192
- // Destructure the parameters
1193
- const { ...actionArgs } = args;
1194
- // Construct an action
1195
- const nonce = await this.nonceManager();
1196
- const action = mod_js_1.actionSorter.setReferrer({ type: "setReferrer", ...actionArgs });
1197
- // Send a multi-sig action
1198
- const outerSigner = await this._getWalletAddress(this.signers[0]);
1199
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner });
1200
- // Send a multi-sig action
1201
- return super.multiSig({
1202
- signatures,
1203
- payload: {
1204
- multiSigUser: this.multiSignAddress,
1205
- outerSigner,
1206
- action,
1207
- },
1208
- nonce,
1209
- }, signal);
1210
- }
1211
- /**
1212
- * Deploying HIP-1 and HIP-2 assets.
1213
- * @param args - The parameters for the request.
1214
- * @param signal - An optional abort signal.
1215
- * @returns Successful response without specific data.
1216
- *
1217
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
1218
- * @throws {TransportError} When the transport layer throws an error.
1219
- *
1220
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/deploying-hip-1-and-hip-2-assets
1221
- * @example
1222
- * ```ts
1223
- * import * as hl from "@nktkas/hyperliquid";
1224
- *
1225
- * const multiSignAddress = "0x...";
1226
- * const signers = [
1227
- * "0x...", // Private key; or any other wallet libraries
1228
- * ] as const;
1229
- *
1230
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1231
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1232
- *
1233
- * await multiSignClient.spotDeploy({
1234
- * registerToken2: {
1235
- * spec: {
1236
- * name: "USDC",
1237
- * szDecimals: 8,
1238
- * weiDecimals: 8,
1239
- * },
1240
- * maxGas: 1000000,
1241
- * fullName: "USD Coin",
1242
- * },
1243
- * });
1244
- * ```
1245
- */
1246
- async spotDeploy(...[args, signal]) {
1247
- // Destructure the parameters
1248
- const { ...actionArgs } = args;
1249
- // Construct an action
1250
- const nonce = await this.nonceManager();
1251
- const action = mod_js_1.actionSorter.spotDeploy({ type: "spotDeploy", ...actionArgs });
1252
- // Send a multi-sig action
1253
- const outerSigner = await this._getWalletAddress(this.signers[0]);
1254
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner });
1255
- // Send a multi-sig action
1256
- return super.multiSig({
1257
- signatures,
1258
- payload: {
1259
- multiSigUser: this.multiSignAddress,
1260
- outerSigner,
1261
- action,
1262
- },
1263
- nonce,
1264
- }, signal);
1265
- }
1266
- /**
1267
- * Send spot assets to another address.
1268
- * @param args - The parameters for the request.
1269
- * @param signal - An optional abort signal.
1270
- * @returns Successful response without specific data.
1271
- *
1272
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
1273
- * @throws {TransportError} When the transport layer throws an error.
1274
- *
1275
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#core-spot-transfer
1276
- * @example
1277
- * ```ts
1278
- * import * as hl from "@nktkas/hyperliquid";
1279
- *
1280
- * const multiSignAddress = "0x...";
1281
- * const signers = [
1282
- * "0x...", // Private key; or any other wallet libraries
1283
- * ] as const;
1284
- *
1285
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1286
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1287
- *
1288
- * await multiSignClient.spotSend({
1289
- * destination: "0x...",
1290
- * token: "USDC:0xeb62eee3685fc4c43992febcd9e75443",
1291
- * amount: "1",
1292
- * });
1293
- * ```
1294
- */
1295
- async spotSend(...[args, signal]) {
1296
- // Destructure the parameters
1297
- const { ...actionArgs } = args;
1298
- // Construct an action
1299
- const nonce = await this.nonceManager();
1300
- const action = mod_js_1.actionSorter.spotSend({
1301
- type: "spotSend",
1302
- hyperliquidChain: this._getHyperliquidChain(),
1303
- signatureChainId: await this._getSignatureChainId(),
1304
- time: nonce,
1305
- ...actionArgs,
1306
- });
1307
- // Sign the action
1308
- const outerSigner = await this._getWalletAddress(this.signers[0]);
1309
- const signatures = await this._multiSignUserSignedAction({ action, outerSigner });
1310
- // Send a multi-sig action
1311
- return super.multiSig({
1312
- signatures,
1313
- payload: {
1314
- multiSigUser: this.multiSignAddress,
1315
- outerSigner,
1316
- action,
1317
- },
1318
- nonce,
1319
- }, signal);
1320
- }
1321
- /**
1322
- * Opt Out of Spot Dusting.
1323
- * @param args - The parameters for the request.
1324
- * @param signal - An optional abort signal.
1325
- * @returns Successful response without specific data.
1326
- *
1327
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
1328
- * @throws {TransportError} When the transport layer throws an error.
1329
- *
1330
- * @see null
1331
- * @example
1332
- * ```ts
1333
- * import * as hl from "@nktkas/hyperliquid";
1334
- *
1335
- * const multiSignAddress = "0x...";
1336
- * const signers = [
1337
- * "0x...", // Private key; or any other wallet libraries
1338
- * ] as const;
1339
- *
1340
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1341
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1342
- *
1343
- * await multiSignClient.spotUser({ toggleSpotDusting: { optOut: false } });
1344
- * ```
1345
- */
1346
- async spotUser(...[args, signal]) {
1347
- // Destructure the parameters
1348
- const { ...actionArgs } = args;
1349
- // Construct an action
1350
- const nonce = await this.nonceManager();
1351
- const action = mod_js_1.actionSorter.spotUser({ type: "spotUser", ...actionArgs });
1352
- // Send a multi-sig action
1353
- const outerSigner = await this._getWalletAddress(this.signers[0]);
1354
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner });
1355
- // Send a multi-sig action
1356
- return super.multiSig({
1357
- signatures,
1358
- payload: {
1359
- multiSigUser: this.multiSignAddress,
1360
- outerSigner,
1361
- action,
1362
- },
1363
- nonce,
1364
- }, signal);
1365
- }
1366
- /**
1367
- * Transfer between sub-accounts (spot).
1368
- * @param args - The parameters for the request.
1369
- * @param signal - An optional abort signal.
1370
- * @returns Successful response without specific data.
1371
- *
1372
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
1373
- * @throws {TransportError} When the transport layer throws an error.
1374
- *
1375
- * @see null
1376
- * @example
1377
- * ```ts
1378
- * import * as hl from "@nktkas/hyperliquid";
1379
- *
1380
- * const multiSignAddress = "0x...";
1381
- * const signers = [
1382
- * "0x...", // Private key; or any other wallet libraries
1383
- * ] as const;
1384
- *
1385
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1386
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1387
- *
1388
- * await multiSignClient.subAccountSpotTransfer({
1389
- * subAccountUser: "0x...",
1390
- * isDeposit: true,
1391
- * token: "USDC:0xeb62eee3685fc4c43992febcd9e75443",
1392
- * amount: "1",
1393
- * });
1394
- * ```
1395
- */
1396
- async subAccountSpotTransfer(...[args, signal]) {
1397
- // Destructure the parameters
1398
- const { ...actionArgs } = args;
1399
- // Construct an action
1400
- const nonce = await this.nonceManager();
1401
- const action = mod_js_1.actionSorter.subAccountSpotTransfer({ type: "subAccountSpotTransfer", ...actionArgs });
1402
- // Send a multi-sig action
1403
- const outerSigner = await this._getWalletAddress(this.signers[0]);
1404
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner });
1405
- // Send a multi-sig action
1406
- return super.multiSig({
1407
- signatures,
1408
- payload: {
1409
- multiSigUser: this.multiSignAddress,
1410
- outerSigner,
1411
- action,
1412
- },
1413
- nonce,
1414
- }, signal);
1415
- }
1416
- /**
1417
- * Transfer between sub-accounts (perpetual).
1418
- * @param args - The parameters for the request.
1419
- * @param signal - An optional abort signal.
1420
- * @returns Successful response without specific data.
1421
- *
1422
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
1423
- * @throws {TransportError} When the transport layer throws an error.
1424
- *
1425
- * @see null
1426
- * @example
1427
- * ```ts
1428
- * import * as hl from "@nktkas/hyperliquid";
1429
- *
1430
- * const multiSignAddress = "0x...";
1431
- * const signers = [
1432
- * "0x...", // Private key; or any other wallet libraries
1433
- * ] as const;
1434
- *
1435
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1436
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1437
- *
1438
- * await multiSignClient.subAccountTransfer({ subAccountUser: "0x...", isDeposit: true, usd: 1 * 1e6 });
1439
- * ```
1440
- */
1441
- async subAccountTransfer(...[args, signal]) {
1442
- // Destructure the parameters
1443
- const { ...actionArgs } = args;
1444
- // Construct an action
1445
- const nonce = await this.nonceManager();
1446
- const action = mod_js_1.actionSorter.subAccountTransfer({ type: "subAccountTransfer", ...actionArgs });
1447
- // Send a multi-sig action
1448
- const outerSigner = await this._getWalletAddress(this.signers[0]);
1449
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner });
1450
- // Send a multi-sig action
1451
- return super.multiSig({
1452
- signatures,
1453
- payload: {
1454
- multiSigUser: this.multiSignAddress,
1455
- outerSigner,
1456
- action,
1457
- },
1458
- nonce,
1459
- }, signal);
1460
- }
1461
- /**
1462
- * Delegate or undelegate native tokens to or from a validator.
1463
- * @param args - The parameters for the request.
1464
- * @param signal - An optional abort signal.
1465
- * @returns Successful response without specific data.
1466
- *
1467
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
1468
- * @throws {TransportError} When the transport layer throws an error.
1469
- *
1470
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#delegate-or-undelegate-stake-from-validator
1471
- * @example
1472
- * ```ts
1473
- * import * as hl from "@nktkas/hyperliquid";
1474
- *
1475
- * const multiSignAddress = "0x...";
1476
- * const signers = [
1477
- * "0x...", // Private key; or any other wallet libraries
1478
- * ] as const;
1479
- *
1480
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1481
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1482
- *
1483
- * await multiSignClient.tokenDelegate({ validator: "0x...", isUndelegate: true, wei: 1 * 1e8 });
1484
- * ```
1485
- */
1486
- async tokenDelegate(...[args, signal]) {
1487
- // Destructure the parameters
1488
- const { ...actionArgs } = args;
1489
- // Construct an action
1490
- const nonce = await this.nonceManager();
1491
- const action = mod_js_1.actionSorter.tokenDelegate({
1492
- type: "tokenDelegate",
1493
- hyperliquidChain: this._getHyperliquidChain(),
1494
- signatureChainId: await this._getSignatureChainId(),
1495
- nonce,
1496
- ...actionArgs,
1497
- });
1498
- // Sign the action
1499
- const outerSigner = await this._getWalletAddress(this.signers[0]);
1500
- const signatures = await this._multiSignUserSignedAction({ action, outerSigner });
1501
- // Send a multi-sig action
1502
- return super.multiSig({
1503
- signatures,
1504
- payload: {
1505
- multiSigUser: this.multiSignAddress,
1506
- outerSigner,
1507
- action,
1508
- },
1509
- nonce,
1510
- }, signal);
1511
- }
1512
- /**
1513
- * Cancel a TWAP order.
1514
- * @param args - The parameters for the request.
1515
- * @param signal - An optional abort signal.
1516
- * @returns Successful variant of {@link TwapCancelResponse} without error status.
1517
- *
1518
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
1519
- * @throws {TransportError} When the transport layer throws an error.
1520
- *
1521
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-a-twap-order
1522
- * @example
1523
- * ```ts
1524
- * import * as hl from "@nktkas/hyperliquid";
1525
- *
1526
- * const multiSignAddress = "0x...";
1527
- * const signers = [
1528
- * "0x...", // Private key; or any other wallet libraries
1529
- * ] as const;
1530
- *
1531
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1532
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1533
- *
1534
- * const data = await multiSignClient.twapCancel({ a: 0, t: 1 });
1535
- * ```
1536
- */
1537
- async twapCancel(...[args, signal]) {
1538
- // Destructure the parameters
1539
- const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
1540
- // Construct an action
1541
- const nonce = await this.nonceManager();
1542
- const action = mod_js_1.actionSorter.twapCancel({ type: "twapCancel", ...actionArgs });
1543
- // Send a multi-sig action
1544
- const outerSigner = await this._getWalletAddress(this.signers[0]);
1545
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner, vaultAddress, expiresAfter });
1546
- // Send a multi-sig action
1547
- return super.multiSig({
1548
- signatures,
1549
- payload: {
1550
- multiSigUser: this.multiSignAddress,
1551
- outerSigner,
1552
- action,
1553
- },
1554
- nonce,
1555
- vaultAddress,
1556
- expiresAfter,
1557
- }, signal);
1558
- }
1559
- /**
1560
- * Place a TWAP order.
1561
- * @param args - The parameters for the request.
1562
- * @param signal - An optional abort signal.
1563
- * @returns Successful variant of {@link TwapOrderResponse} without error status.
1564
- *
1565
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
1566
- * @throws {TransportError} When the transport layer throws an error.
1567
- *
1568
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-a-twap-order
1569
- * @example
1570
- * ```ts
1571
- * import * as hl from "@nktkas/hyperliquid";
1572
- *
1573
- * const multiSignAddress = "0x...";
1574
- * const signers = [
1575
- * "0x...", // Private key; or any other wallet libraries
1576
- * ] as const;
1577
- *
1578
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1579
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1580
- *
1581
- * const data = await multiSignClient.twapOrder({
1582
- * a: 0,
1583
- * b: true,
1584
- * s: "1",
1585
- * r: false,
1586
- * m: 10,
1587
- * t: true,
1588
- * });
1589
- * ```
1590
- */
1591
- async twapOrder(...[args, signal]) {
1592
- // Destructure the parameters
1593
- const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
1594
- // Construct an action
1595
- const nonce = await this.nonceManager();
1596
- const action = mod_js_1.actionSorter.twapOrder({ type: "twapOrder", twap: { ...actionArgs } });
1597
- // Send a multi-sig action
1598
- const outerSigner = await this._getWalletAddress(this.signers[0]);
1599
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner, vaultAddress, expiresAfter });
1600
- // Send a multi-sig action
1601
- return super.multiSig({
1602
- signatures,
1603
- payload: {
1604
- multiSigUser: this.multiSignAddress,
1605
- outerSigner,
1606
- action,
1607
- },
1608
- nonce,
1609
- vaultAddress,
1610
- expiresAfter,
1611
- }, signal);
1612
- }
1613
- /**
1614
- * Add or remove margin from isolated position.
1615
- * @param args - The parameters for the request.
1616
- * @param signal - An optional abort signal.
1617
- * @returns Successful response without specific data.
1618
- *
1619
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
1620
- * @throws {TransportError} When the transport layer throws an error.
1621
- *
1622
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#update-isolated-margin
1623
- * @example
1624
- * ```ts
1625
- * import * as hl from "@nktkas/hyperliquid";
1626
- *
1627
- * const multiSignAddress = "0x...";
1628
- * const signers = [
1629
- * "0x...", // Private key; or any other wallet libraries
1630
- * ] as const;
1631
- *
1632
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1633
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1634
- *
1635
- * await multiSignClient.updateIsolatedMargin({ asset: 0, isBuy: true, ntli: 1 * 1e6 });
1636
- * ```
1637
- */
1638
- async updateIsolatedMargin(...[args, signal]) {
1639
- // Destructure the parameters
1640
- const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
1641
- // Construct an action
1642
- const nonce = await this.nonceManager();
1643
- const action = mod_js_1.actionSorter.updateIsolatedMargin({ type: "updateIsolatedMargin", ...actionArgs });
1644
- // Send a multi-sig action
1645
- const outerSigner = await this._getWalletAddress(this.signers[0]);
1646
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner, vaultAddress, expiresAfter });
1647
- // Send a multi-sig action
1648
- return super.multiSig({
1649
- signatures,
1650
- payload: {
1651
- multiSigUser: this.multiSignAddress,
1652
- outerSigner,
1653
- action,
1654
- },
1655
- nonce,
1656
- vaultAddress,
1657
- expiresAfter,
1658
- }, signal);
1659
- }
1660
- /**
1661
- * Update cross or isolated leverage on a coin.
1662
- * @param args - The parameters for the request.
1663
- * @param signal - An optional abort signal.
1664
- * @returns Successful response without specific data.
1665
- *
1666
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
1667
- * @throws {TransportError} When the transport layer throws an error.
1668
- *
1669
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#update-leverage
1670
- * @example
1671
- * ```ts
1672
- * import * as hl from "@nktkas/hyperliquid";
1673
- *
1674
- * const multiSignAddress = "0x...";
1675
- * const signers = [
1676
- * "0x...", // Private key; or any other wallet libraries
1677
- * ] as const;
1678
- *
1679
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1680
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1681
- *
1682
- * await multiSignClient.updateLeverage({ asset: 0, isCross: true, leverage: 5 });
1683
- * ```
1684
- */
1685
- async updateLeverage(...[args, signal]) {
1686
- // Destructure the parameters
1687
- const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
1688
- // Construct an action
1689
- const nonce = await this.nonceManager();
1690
- const action = mod_js_1.actionSorter.updateLeverage({ type: "updateLeverage", ...actionArgs });
1691
- // Send a multi-sig action
1692
- const outerSigner = await this._getWalletAddress(this.signers[0]);
1693
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner, vaultAddress, expiresAfter });
1694
- // Send a multi-sig action
1695
- return super.multiSig({
1696
- signatures,
1697
- payload: {
1698
- multiSigUser: this.multiSignAddress,
1699
- outerSigner,
1700
- action,
1701
- },
1702
- nonce,
1703
- vaultAddress,
1704
- expiresAfter,
1705
- }, signal);
1706
- }
1707
- /**
1708
- * Transfer funds between Spot account and Perp account.
1709
- * @param args - The parameters for the request.
1710
- * @param signal - An optional abort signal.
1711
- * @returns Successful response without specific data.
1712
- *
1713
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
1714
- * @throws {TransportError} When the transport layer throws an error.
1715
- *
1716
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#transfer-from-spot-account-to-perp-account-and-vice-versa
1717
- * @example
1718
- * ```ts
1719
- * import * as hl from "@nktkas/hyperliquid";
1720
- *
1721
- * const multiSignAddress = "0x...";
1722
- * const signers = [
1723
- * "0x...", // Private key; or any other wallet libraries
1724
- * ] as const;
1725
- *
1726
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1727
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1728
- *
1729
- * await multiSignClient.usdClassTransfer({ amount: "1", toPerp: true });
1730
- * ```
1731
- */
1732
- async usdClassTransfer(...[args, signal]) {
1733
- // Destructure the parameters
1734
- const { ...actionArgs } = args;
1735
- // Construct an action
1736
- const nonce = await this.nonceManager();
1737
- const action = mod_js_1.actionSorter.usdClassTransfer({
1738
- type: "usdClassTransfer",
1739
- hyperliquidChain: this._getHyperliquidChain(),
1740
- signatureChainId: await this._getSignatureChainId(),
1741
- nonce,
1742
- ...actionArgs,
1743
- });
1744
- // Sign the action
1745
- const outerSigner = await this._getWalletAddress(this.signers[0]);
1746
- const signatures = await this._multiSignUserSignedAction({ action, outerSigner });
1747
- // Send a multi-sig action
1748
- return super.multiSig({
1749
- signatures,
1750
- payload: {
1751
- multiSigUser: this.multiSignAddress,
1752
- outerSigner,
1753
- action,
1754
- },
1755
- nonce,
1756
- }, signal);
1757
- }
1758
- /**
1759
- * Send usd to another address.
1760
- * @param args - The parameters for the request.
1761
- * @param signal - An optional abort signal.
1762
- * @returns Successful response without specific data.
1763
- *
1764
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
1765
- * @throws {TransportError} When the transport layer throws an error.
1766
- *
1767
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#core-usdc-transfer
1768
- * @example
1769
- * ```ts
1770
- * import * as hl from "@nktkas/hyperliquid";
1771
- *
1772
- * const multiSignAddress = "0x...";
1773
- * const signers = [
1774
- * "0x...", // Private key; or any other wallet libraries
1775
- * ] as const;
1776
- *
1777
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1778
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1779
- *
1780
- * await multiSignClient.usdSend({ destination: "0x...", amount: "1" });
1781
- * ```
1782
- */
1783
- async usdSend(...[args, signal]) {
1784
- // Destructure the parameters
1785
- const { ...actionArgs } = args;
1786
- // Construct an action
1787
- const nonce = await this.nonceManager();
1788
- const action = mod_js_1.actionSorter.usdSend({
1789
- type: "usdSend",
1790
- hyperliquidChain: this._getHyperliquidChain(),
1791
- signatureChainId: await this._getSignatureChainId(),
1792
- time: nonce,
1793
- ...actionArgs,
1794
- });
1795
- // Sign the action
1796
- const outerSigner = await this._getWalletAddress(this.signers[0]);
1797
- const signatures = await this._multiSignUserSignedAction({ action, outerSigner });
1798
- // Send a multi-sig action
1799
- return super.multiSig({
1800
- signatures,
1801
- payload: {
1802
- multiSigUser: this.multiSignAddress,
1803
- outerSigner,
1804
- action,
1805
- },
1806
- nonce,
1807
- }, signal);
1808
- }
1809
- /**
1810
- * Distribute funds from a vault between followers.
1811
- * @param args - The parameters for the request.
1812
- * @param signal - An optional abort signal.
1813
- * @returns Successful response without specific data.
1814
- *
1815
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
1816
- * @throws {TransportError} When the transport layer throws an error.
1817
- *
1818
- * @see null
1819
- * @example
1820
- * ```ts
1821
- * import * as hl from "@nktkas/hyperliquid";
1822
- *
1823
- * const multiSignAddress = "0x...";
1824
- * const signers = [
1825
- * "0x...", // Private key; or any other wallet libraries
1826
- * ] as const;
1827
- *
1828
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1829
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1830
- *
1831
- * await multiSignClient.vaultDistribute({ vaultAddress: "0x...", usd: 10 * 1e6 });
1832
- * ```
1833
- */
1834
- async vaultDistribute(...[args, signal]) {
1835
- // Destructure the parameters
1836
- const { ...actionArgs } = args;
1837
- // Construct an action
1838
- const nonce = await this.nonceManager();
1839
- const action = mod_js_1.actionSorter.vaultDistribute({ type: "vaultDistribute", ...actionArgs });
1840
- // Send a multi-sig action
1841
- const outerSigner = await this._getWalletAddress(this.signers[0]);
1842
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner });
1843
- // Send a multi-sig action
1844
- return super.multiSig({
1845
- signatures,
1846
- payload: {
1847
- multiSigUser: this.multiSignAddress,
1848
- outerSigner,
1849
- action,
1850
- },
1851
- nonce,
1852
- }, signal);
1853
- }
1854
- /**
1855
- * Modify a vault's configuration.
1856
- * @param args - The parameters for the request.
1857
- * @param signal - An optional abort signal.
1858
- * @returns Successful response without specific data.
1859
- *
1860
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
1861
- * @throws {TransportError} When the transport layer throws an error.
1862
- *
1863
- * @see null
1864
- * @example
1865
- * ```ts
1866
- * import * as hl from "@nktkas/hyperliquid";
1867
- *
1868
- * const multiSignAddress = "0x...";
1869
- * const signers = [
1870
- * "0x...", // Private key; or any other wallet libraries
1871
- * ] as const;
1872
- *
1873
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1874
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1875
- *
1876
- * await multiSignClient.vaultModify({
1877
- * vaultAddress: "0x...",
1878
- * allowDeposits: true,
1879
- * alwaysCloseOnWithdraw: false,
1880
- * });
1881
- * ```
1882
- */
1883
- async vaultModify(...[args, signal]) {
1884
- // Destructure the parameters
1885
- const { ...actionArgs } = args;
1886
- // Construct an action
1887
- const nonce = await this.nonceManager();
1888
- const action = mod_js_1.actionSorter.vaultModify({ type: "vaultModify", ...actionArgs });
1889
- // Send a multi-sig action
1890
- const outerSigner = await this._getWalletAddress(this.signers[0]);
1891
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner });
1892
- // Send a multi-sig action
1893
- return super.multiSig({
1894
- signatures,
1895
- payload: {
1896
- multiSigUser: this.multiSignAddress,
1897
- outerSigner,
1898
- action,
1899
- },
1900
- nonce,
1901
- }, signal);
1902
- }
1903
- /**
1904
- * Deposit or withdraw from a vault.
1905
- * @param args - The parameters for the request.
1906
- * @param signal - An optional abort signal.
1907
- * @returns Successful response without specific data.
1908
- *
1909
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
1910
- * @throws {TransportError} When the transport layer throws an error.
1911
- *
1912
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#deposit-or-withdraw-from-a-vault
1913
- * @example
1914
- * ```ts
1915
- * import * as hl from "@nktkas/hyperliquid";
1916
- *
1917
- * const multiSignAddress = "0x...";
1918
- * const signers = [
1919
- * "0x...", // Private key; or any other wallet libraries
1920
- * ] as const;
1921
- *
1922
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1923
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1924
- *
1925
- * await multiSignClient.vaultTransfer({ vaultAddress: "0x...", isDeposit: true, usd: 10 * 1e6 });
1926
- * ```
1927
- */
1928
- async vaultTransfer(...[args, signal]) {
1929
- // Destructure the parameters
1930
- const { expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
1931
- // Construct an action
1932
- const nonce = await this.nonceManager();
1933
- const action = mod_js_1.actionSorter.vaultTransfer({ type: "vaultTransfer", ...actionArgs });
1934
- // Send a multi-sig action
1935
- const outerSigner = await this._getWalletAddress(this.signers[0]);
1936
- const signatures = await this._multiSignL1Action({ action, nonce, outerSigner, expiresAfter });
1937
- // Send a multi-sig action
1938
- return super.multiSig({
1939
- signatures,
1940
- payload: {
1941
- multiSigUser: this.multiSignAddress,
1942
- outerSigner,
1943
- action,
1944
- },
1945
- nonce,
1946
- expiresAfter,
1947
- }, signal);
1948
- }
1949
- /**
1950
- * Initiate a withdrawal request.
1951
- * @param args - The parameters for the request.
1952
- * @param signal - An optional abort signal.
1953
- * @returns Successful response without specific data.
1954
- *
1955
- * @throws {ApiRequestError} When the API returns an unsuccessful response.
1956
- * @throws {TransportError} When the transport layer throws an error.
1957
- *
1958
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#initiate-a-withdrawal-request
1959
- * @example
1960
- * ```ts
1961
- * import * as hl from "@nktkas/hyperliquid";
1962
- *
1963
- * const multiSignAddress = "0x...";
1964
- * const signers = [
1965
- * "0x...", // Private key; or any other wallet libraries
1966
- * ] as const;
1967
- *
1968
- * const transport = new hl.HttpTransport(); // or `WebSocketTransport`
1969
- * const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
1970
- *
1971
- * await multiSignClient.withdraw3({ destination: "0x...", amount: "1" });
1972
- * ```
1973
- */
1974
- async withdraw3(...[args, signal]) {
1975
- // Destructure the parameters
1976
- const { ...actionArgs } = args;
1977
- // Construct an action
1978
- const nonce = await this.nonceManager();
1979
- const action = mod_js_1.actionSorter.withdraw3({
1980
- type: "withdraw3",
1981
- hyperliquidChain: this._getHyperliquidChain(),
1982
- signatureChainId: await this._getSignatureChainId(),
1983
- time: nonce,
1984
- ...actionArgs,
1985
- });
1986
- // Sign the action
1987
- const outerSigner = await this._getWalletAddress(this.signers[0]);
1988
- const signatures = await this._multiSignUserSignedAction({ action, outerSigner });
1989
- // Send a multi-sig action
1990
- return super.multiSig({
1991
- signatures,
1992
- payload: {
1993
- multiSigUser: this.multiSignAddress,
1994
- outerSigner,
1995
- action,
1996
- },
1997
- nonce,
1998
- }, signal);
1999
- }
2000
- /** Extracts the wallet address from different wallet types. */
2001
- async _getWalletAddress(wallet) {
2002
- if ((0, mod_js_1.isValidPrivateKey)(wallet)) {
2003
- return privateKeyToAddress(wallet);
2004
- }
2005
- else if ((0, mod_js_1.isAbstractViemWalletClient)(wallet)) {
2006
- return wallet.address;
2007
- }
2008
- else if ((0, mod_js_1.isAbstractEthersSigner)(wallet) || (0, mod_js_1.isAbstractEthersV5Signer)(wallet)) {
2009
- return await wallet.getAddress();
2010
- }
2011
- else if ((0, mod_js_1.isAbstractWindowEthereum)(wallet)) {
2012
- const accounts = await wallet.request({ method: "eth_requestAccounts", params: [] });
2013
- if (!Array.isArray(accounts) || accounts.length === 0) {
2014
- throw new Error("No Ethereum accounts available");
2015
- }
2016
- return accounts[0];
2017
- }
2018
- else {
2019
- throw new Error("Unsupported wallet for getting address");
2020
- }
2021
- }
2022
- /** Signs L1 action with all signers for multi-signature operations. */
2023
- _multiSignL1Action(args) {
2024
- const { action, nonce, outerSigner, vaultAddress, expiresAfter } = args;
2025
- return Promise.all(this.signers.map((signer) => {
2026
- return (0, mod_js_1.signL1Action)({
2027
- wallet: signer,
2028
- action: [this.multiSignAddress.toLowerCase(), outerSigner.toLowerCase(), action],
2029
- nonce,
2030
- isTestnet: this.isTestnet,
2031
- vaultAddress,
2032
- expiresAfter,
2033
- });
2034
- }));
2035
- }
2036
- /** Signs user-signed action with all signers for multi-signature operations. */
2037
- _multiSignUserSignedAction(args) {
2038
- const { action, outerSigner } = args;
2039
- return Promise.all(this.signers.map((signer) => {
2040
- const types = structuredClone(mod_js_1.userSignedActionEip712Types[action.type]); // for safe mutation
2041
- Object.values(types)[0].splice(// array mutation
2042
- 1, // after `hyperliquidChain`
2043
- 0, // do not remove any elements
2044
- { name: "payloadMultiSigUser", type: "address" }, { name: "outerSigner", type: "address" });
2045
- return (0, mod_js_1.signUserSignedAction)({
2046
- wallet: signer,
2047
- action: {
2048
- payloadMultiSigUser: this.multiSignAddress,
2049
- outerSigner,
2050
- ...action,
2051
- },
2052
- types,
2053
- });
2054
- }));
97
+ }, { signal });
2055
98
  }
2056
99
  }
2057
100
  exports.MultiSignClient = MultiSignClient;
2058
- /** Converts a private key to an Ethereum address. */
2059
- function privateKeyToAddress(privateKey) {
2060
- const cleanPrivKey = privateKey.startsWith("0x") ? privateKey.slice(2) : privateKey;
2061
- const publicKey = (0, secp256k1_1.getPublicKey)(cleanPrivKey, false);
2062
- const publicKeyWithoutPrefix = publicKey.slice(1);
2063
- const hash = (0, sha3_1.keccak_256)(publicKeyWithoutPrefix);
2064
- const addressBytes = hash.slice(-20);
2065
- const address = secp256k1_1.etc.bytesToHex(addressBytes);
2066
- return `0x${address}`;
2067
- }