@nktkas/hyperliquid 0.21.1 → 0.22.1

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