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