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