@nktkas/hyperliquid 0.16.0 → 0.17.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 (68) hide show
  1. package/README.md +58 -106
  2. package/esm/src/clients/event.d.ts.map +1 -1
  3. package/esm/src/clients/event.js +0 -1
  4. package/esm/src/clients/public.d.ts +4 -4
  5. package/esm/src/clients/public.d.ts.map +1 -1
  6. package/esm/src/clients/public.js +4 -7
  7. package/esm/src/clients/wallet.d.ts +129 -132
  8. package/esm/src/clients/wallet.d.ts.map +1 -1
  9. package/esm/src/clients/wallet.js +290 -268
  10. package/esm/src/signing.d.ts +149 -32
  11. package/esm/src/signing.d.ts.map +1 -1
  12. package/esm/src/signing.js +123 -15
  13. package/esm/src/transports/http/http_transport.d.ts +14 -24
  14. package/esm/src/transports/http/http_transport.d.ts.map +1 -1
  15. package/esm/src/transports/http/http_transport.js +20 -15
  16. package/esm/src/transports/websocket/websocket_transport.d.ts +6 -2
  17. package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  18. package/esm/src/types/exchange/requests.d.ts +52 -38
  19. package/esm/src/types/exchange/requests.d.ts.map +1 -1
  20. package/esm/src/types/info/accounts.d.ts +4 -0
  21. package/esm/src/types/info/accounts.d.ts.map +1 -1
  22. package/esm/src/types/info/assets.d.ts +4 -6
  23. package/esm/src/types/info/assets.d.ts.map +1 -1
  24. package/esm/src/types/info/orders.d.ts +28 -20
  25. package/esm/src/types/info/orders.d.ts.map +1 -1
  26. package/esm/src/types/info/requests.d.ts +8 -8
  27. package/esm/src/types/info/requests.d.ts.map +1 -1
  28. package/esm/src/types/info/vaults.d.ts +2 -0
  29. package/esm/src/types/info/vaults.d.ts.map +1 -1
  30. package/esm/src/types/mod.d.ts +21 -0
  31. package/esm/src/types/mod.d.ts.map +1 -1
  32. package/esm/src/types/mod.js +21 -0
  33. package/esm/src/types/subscriptions/requests.d.ts +5 -14
  34. package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
  35. package/package.json +4 -1
  36. package/script/src/clients/event.d.ts.map +1 -1
  37. package/script/src/clients/event.js +0 -1
  38. package/script/src/clients/public.d.ts +4 -4
  39. package/script/src/clients/public.d.ts.map +1 -1
  40. package/script/src/clients/public.js +4 -7
  41. package/script/src/clients/wallet.d.ts +129 -132
  42. package/script/src/clients/wallet.d.ts.map +1 -1
  43. package/script/src/clients/wallet.js +290 -268
  44. package/script/src/signing.d.ts +149 -32
  45. package/script/src/signing.d.ts.map +1 -1
  46. package/script/src/signing.js +124 -16
  47. package/script/src/transports/http/http_transport.d.ts +14 -24
  48. package/script/src/transports/http/http_transport.d.ts.map +1 -1
  49. package/script/src/transports/http/http_transport.js +20 -15
  50. package/script/src/transports/websocket/websocket_transport.d.ts +6 -2
  51. package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  52. package/script/src/types/exchange/requests.d.ts +52 -38
  53. package/script/src/types/exchange/requests.d.ts.map +1 -1
  54. package/script/src/types/info/accounts.d.ts +4 -0
  55. package/script/src/types/info/accounts.d.ts.map +1 -1
  56. package/script/src/types/info/assets.d.ts +4 -6
  57. package/script/src/types/info/assets.d.ts.map +1 -1
  58. package/script/src/types/info/orders.d.ts +28 -20
  59. package/script/src/types/info/orders.d.ts.map +1 -1
  60. package/script/src/types/info/requests.d.ts +8 -8
  61. package/script/src/types/info/requests.d.ts.map +1 -1
  62. package/script/src/types/info/vaults.d.ts +2 -0
  63. package/script/src/types/info/vaults.d.ts.map +1 -1
  64. package/script/src/types/mod.d.ts +21 -0
  65. package/script/src/types/mod.d.ts.map +1 -1
  66. package/script/src/types/mod.js +21 -0
  67. package/script/src/types/subscriptions/requests.d.ts +5 -14
  68. package/script/src/types/subscriptions/requests.d.ts.map +1 -1
@@ -12,7 +12,6 @@
12
12
  exports.WalletClient = exports.ApiRequestError = void 0;
13
13
  const base_js_1 = require("../base.js");
14
14
  const signing_js_1 = require("../signing.js");
15
- // ——————————————— Errors ———————————————
16
15
  /** Error thrown when the API returns an error response. */
17
16
  class ApiRequestError extends base_js_1.HyperliquidError {
18
17
  constructor(response) {
@@ -52,24 +51,38 @@
52
51
  }
53
52
  }
54
53
  exports.ApiRequestError = ApiRequestError;
55
- // ——————————————— Client ———————————————
56
- /**
57
- * Wallet client for interacting with the Hyperliquid API.
58
- * @typeParam T The transport used to connect to the Hyperliquid API.
59
- * @typeParam W The WalletClient/Account ([viem](https://viem.sh/docs/clients/wallet)) or Signer ([ethers.js](https://docs.ethers.io/v6/api/providers/#Signer)) used for signing transactions.
60
- */
61
- class WalletClient {
62
- /** Gets the next nonce for signing transactions. */
63
- get _nonce() {
54
+ /** Nonce manager for generating unique nonces for signing transactions. */
55
+ class NonceManager {
56
+ constructor() {
57
+ /** The last nonce used for signing transactions. */
58
+ Object.defineProperty(this, "lastNonce", {
59
+ enumerable: true,
60
+ configurable: true,
61
+ writable: true,
62
+ value: 0
63
+ });
64
+ }
65
+ /**
66
+ * Gets the next nonce for signing transactions.
67
+ * @returns The next nonce.
68
+ */
69
+ getNonce() {
64
70
  let nonce = Date.now();
65
- if (nonce <= this._lastNonce) {
66
- nonce = ++this._lastNonce;
71
+ if (nonce <= this.lastNonce) {
72
+ nonce = ++this.lastNonce;
67
73
  }
68
74
  else {
69
- this._lastNonce = nonce;
75
+ this.lastNonce = nonce;
70
76
  }
71
77
  return nonce;
72
78
  }
79
+ }
80
+ /**
81
+ * Wallet client for interacting with the Hyperliquid API.
82
+ * @typeParam T The transport used to connect to the Hyperliquid API.
83
+ * @typeParam W The WalletClient/Account ([viem](https://viem.sh/docs/clients/wallet)) or Signer ([ethers.js](https://docs.ethers.io/v6/api/providers/#Signer)) used for signing transactions.
84
+ */
85
+ class WalletClient {
73
86
  /**
74
87
  * Initialises a new instance.
75
88
  * @param args - The parameters for the client.
@@ -155,43 +168,20 @@
155
168
  writable: true,
156
169
  value: void 0
157
170
  });
158
- /** The last nonce used for signing transactions. */
159
- Object.defineProperty(this, "_lastNonce", {
171
+ /** Function to get the next nonce for signing transactions. */
172
+ Object.defineProperty(this, "nonceManager", {
160
173
  enumerable: true,
161
174
  configurable: true,
162
175
  writable: true,
163
- value: 0
176
+ value: void 0
164
177
  });
165
178
  this.transport = args.transport;
166
179
  this.wallet = args.wallet;
167
180
  this.isTestnet = args.isTestnet ?? false;
168
181
  this.defaultVaultAddress = args.defaultVaultAddress;
169
- this.signatureChainId = args.signatureChainId ?? (async () => {
170
- // Trying to get chain id of the wallet
171
- if ((0, signing_js_1.isAbstractViemWalletClient)(this.wallet)) {
172
- if ("getChainId" in this.wallet && typeof this.wallet.getChainId === "function") {
173
- const chainId = await this.wallet.getChainId();
174
- return `0x${chainId.toString(16)}`;
175
- }
176
- }
177
- else if ((0, signing_js_1.isAbstractEthersSigner)(this.wallet) || (0, signing_js_1.isAbstractEthersV5Signer)(this.wallet)) {
178
- if ("provider" in this.wallet &&
179
- typeof this.wallet.provider === "object" && this.wallet.provider !== null &&
180
- "getNetwork" in this.wallet.provider &&
181
- typeof this.wallet.provider.getNetwork === "function") {
182
- const network = await this.wallet.provider.getNetwork();
183
- return `0x${network.chainId.toString(16)}`;
184
- }
185
- }
186
- else if ((0, signing_js_1.isAbstractWindowEthereum)(this.wallet)) {
187
- const [chainId] = await this.wallet.request({ method: "eth_chainId", params: [] });
188
- return chainId;
189
- }
190
- // Trying to guess chain id based on isTestnet
191
- return this.isTestnet ? "0x66eee" : "0xa4b1";
192
- });
182
+ this.signatureChainId = args.signatureChainId ?? this._guessSignatureChainId;
183
+ this.nonceManager = args.nonceManager ?? new NonceManager().getNonce;
193
184
  }
194
- // ——————————————— Exchange API ———————————————
195
185
  /**
196
186
  * Approve an agent to sign on behalf of the master or sub-accounts.
197
187
  * @param args - The parameters for the request.
@@ -209,10 +199,7 @@
209
199
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
210
200
  * const client = new hl.WalletClient({ wallet, transport });
211
201
  *
212
- * const result = await client.approveAgent({
213
- * agentAddress: "0x...",
214
- * agentName: "agentName",
215
- * });
202
+ * const result = await client.approveAgent({ agentAddress: "0x...", agentName: "agentName" });
216
203
  * ```
217
204
  */
218
205
  async approveAgent(args, signal) {
@@ -224,7 +211,7 @@
224
211
  signatureChainId: typeof this.signatureChainId === "string"
225
212
  ? this.signatureChainId
226
213
  : await this.signatureChainId(),
227
- nonce: args.nonce ?? this._nonce,
214
+ nonce: await this.nonceManager(),
228
215
  };
229
216
  // Sign the action
230
217
  const signature = await (0, signing_js_1.signUserSignedAction)({
@@ -264,10 +251,7 @@
264
251
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
265
252
  * const client = new hl.WalletClient({ wallet, transport });
266
253
  *
267
- * const result = await client.approveBuilderFee({
268
- * maxFeeRate: "0.01%",
269
- * builder: "0x...",
270
- * });
254
+ * const result = await client.approveBuilderFee({ maxFeeRate: "0.01%", builder: "0x..." });
271
255
  * ```
272
256
  */
273
257
  async approveBuilderFee(args, signal) {
@@ -279,7 +263,7 @@
279
263
  signatureChainId: typeof this.signatureChainId === "string"
280
264
  ? this.signatureChainId
281
265
  : await this.signatureChainId(),
282
- nonce: args.nonce ?? this._nonce,
266
+ nonce: await this.nonceManager(),
283
267
  };
284
268
  // Sign the action
285
269
  const signature = await (0, signing_js_1.signUserSignedAction)({
@@ -321,7 +305,7 @@
321
305
  *
322
306
  * const result = await client.batchModify({
323
307
  * modifies: [{
324
- * oid: 123, // Order ID
308
+ * oid: 123,
325
309
  * order: {
326
310
  * a: 0, // Asset index
327
311
  * b: true, // Buy order
@@ -341,8 +325,9 @@
341
325
  */
342
326
  async batchModify(args, signal) {
343
327
  // Destructure the parameters
344
- const { vaultAddress = this.defaultVaultAddress, nonce = this._nonce, ...actionArgs } = args;
328
+ const { vaultAddress = this.defaultVaultAddress, ...actionArgs } = args;
345
329
  // Construct an action
330
+ const nonce = await this.nonceManager();
346
331
  const action = {
347
332
  type: "batchModify",
348
333
  modifies: actionArgs.modifies.map((modify) => {
@@ -417,8 +402,9 @@
417
402
  */
418
403
  async cancel(args, signal) {
419
404
  // Destructure the parameters
420
- const { vaultAddress = this.defaultVaultAddress, nonce = this._nonce, ...actionArgs } = args;
405
+ const { vaultAddress = this.defaultVaultAddress, ...actionArgs } = args;
421
406
  // Construct an action
407
+ const nonce = await this.nonceManager();
422
408
  const action = {
423
409
  type: "cancel",
424
410
  cancels: actionArgs.cancels.map((cancel) => ({
@@ -441,6 +427,57 @@
441
427
  this._validateResponse(response);
442
428
  return response;
443
429
  }
430
+ /**
431
+ * Cancel order(s) by cloid.
432
+ * @param args - The parameters for the request.
433
+ * @param signal - An optional abort signal.
434
+ * @returns Successful variant of {@link CancelResponse} without error statuses.
435
+ * @throws {ApiRequestError} When the API returns an error response.
436
+ *
437
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s-by-cloid
438
+ * @example
439
+ * ```ts
440
+ * import * as hl from "@nktkas/hyperliquid";
441
+ * import { privateKeyToAccount } from "viem/accounts";
442
+ *
443
+ * const wallet = privateKeyToAccount("0x...");
444
+ * const transport = new hl.HttpTransport(); // or WebSocketTransport
445
+ * const client = new hl.WalletClient({ wallet, transport });
446
+ *
447
+ * const result = await client.cancelByCloid({
448
+ * cancels: [
449
+ * { asset: 0, cloid: "0x..." },
450
+ * ],
451
+ * });
452
+ * ```
453
+ */
454
+ async cancelByCloid(args, signal) {
455
+ // Destructure the parameters
456
+ const { vaultAddress = this.defaultVaultAddress, ...actionArgs } = args;
457
+ // Construct an action
458
+ const nonce = await this.nonceManager();
459
+ const action = {
460
+ type: "cancelByCloid",
461
+ cancels: actionArgs.cancels.map((cancel) => ({
462
+ asset: cancel.asset,
463
+ cloid: cancel.cloid,
464
+ })),
465
+ };
466
+ // Sign the action
467
+ const signature = await (0, signing_js_1.signL1Action)({
468
+ wallet: this.wallet,
469
+ action,
470
+ nonce,
471
+ isTestnet: this.isTestnet,
472
+ vaultAddress,
473
+ });
474
+ // Send a request
475
+ const request = { action, signature, nonce, vaultAddress };
476
+ const response = await this.transport.request("exchange", request, signal);
477
+ // Validate a response
478
+ this._validateResponse(response);
479
+ return response;
480
+ }
444
481
  /**
445
482
  * Deposit into staking balance.
446
483
  * @param args - The parameters for the request.
@@ -470,7 +507,7 @@
470
507
  signatureChainId: typeof this.signatureChainId === "string"
471
508
  ? this.signatureChainId
472
509
  : await this.signatureChainId(),
473
- nonce: args.nonce ?? this._nonce,
510
+ nonce: await this.nonceManager(),
474
511
  };
475
512
  // Sign the action
476
513
  const signature = await (0, signing_js_1.signUserSignedAction)({
@@ -512,10 +549,9 @@
512
549
  * const result = await client.claimRewards();
513
550
  * ```
514
551
  */
515
- async claimRewards(args = {}, signal) {
516
- // Destructure the parameters
517
- const { nonce = this._nonce, } = args;
552
+ async claimRewards(signal) {
518
553
  // Construct an action
554
+ const nonce = await this.nonceManager();
519
555
  const sortedAction = { type: "claimRewards" };
520
556
  // Sign the action
521
557
  const signature = await (0, signing_js_1.signL1Action)({
@@ -532,13 +568,13 @@
532
568
  return response;
533
569
  }
534
570
  /**
535
- * Cancel order(s) by cloid.
571
+ * Create a sub-account.
536
572
  * @param args - The parameters for the request.
537
573
  * @param signal - An optional abort signal.
538
- * @returns Successful variant of {@link CancelResponse} without error statuses.
574
+ * @returns Response for creating a sub-account.
539
575
  * @throws {ApiRequestError} When the API returns an error response.
540
576
  *
541
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s-by-cloid
577
+ * @see null - no documentation
542
578
  * @example
543
579
  * ```ts
544
580
  * import * as hl from "@nktkas/hyperliquid";
@@ -548,24 +584,15 @@
548
584
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
549
585
  * const client = new hl.WalletClient({ wallet, transport });
550
586
  *
551
- * const result = await client.cancelByCloid({
552
- * cancels: [{
553
- * asset: 0,
554
- * cloid: "0x...", // Client Order ID
555
- * }],
556
- * });
587
+ * const result = await client.createSubAccount({ name: "subAccountName" });
557
588
  * ```
558
589
  */
559
- async cancelByCloid(args, signal) {
560
- // Destructure the parameters
561
- const { vaultAddress = this.defaultVaultAddress, nonce = this._nonce, ...actionArgs } = args;
590
+ async createSubAccount(args, signal) {
562
591
  // Construct an action
592
+ const nonce = await this.nonceManager();
563
593
  const action = {
564
- type: "cancelByCloid",
565
- cancels: actionArgs.cancels.map((cancel) => ({
566
- asset: cancel.asset,
567
- cloid: cancel.cloid,
568
- })),
594
+ type: "createSubAccount",
595
+ name: args.name,
569
596
  };
570
597
  // Sign the action
571
598
  const signature = await (0, signing_js_1.signL1Action)({
@@ -573,74 +600,22 @@
573
600
  action,
574
601
  nonce,
575
602
  isTestnet: this.isTestnet,
576
- vaultAddress,
577
603
  });
578
604
  // Send a request
579
- const request = { action, signature, nonce, vaultAddress };
580
- const response = await this.transport.request("exchange", request, signal);
581
- // Validate a response
582
- this._validateResponse(response);
583
- return response;
584
- }
585
- /**
586
- * Withdraw from staking balance.
587
- * @param args - The parameters for the request.
588
- * @param signal - An optional abort signal.
589
- * @returns Successful response without specific data.
590
- * @throws {ApiRequestError} When the API returns an error response.
591
- *
592
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#withdraw-from-staking
593
- * @example
594
- * ```ts
595
- * import * as hl from "@nktkas/hyperliquid";
596
- * import { privateKeyToAccount } from "viem/accounts";
597
- *
598
- * const wallet = privateKeyToAccount("0x...");
599
- * const transport = new hl.HttpTransport(); // or WebSocketTransport
600
- * const client = new hl.WalletClient({ wallet, transport });
601
- *
602
- * const result = await client.cWithdraw({ wei: 1 * 1e8 });
603
- * ```
604
- */
605
- async cWithdraw(args, signal) {
606
- // Construct an action
607
- const action = {
608
- ...args,
609
- type: "cWithdraw",
610
- hyperliquidChain: this.isTestnet ? "Testnet" : "Mainnet",
611
- signatureChainId: typeof this.signatureChainId === "string"
612
- ? this.signatureChainId
613
- : await this.signatureChainId(),
614
- nonce: args.nonce ?? this._nonce,
615
- };
616
- // Sign the action
617
- const signature = await (0, signing_js_1.signUserSignedAction)({
618
- wallet: this.wallet,
619
- action,
620
- types: {
621
- "HyperliquidTransaction:CWithdraw": [
622
- { name: "hyperliquidChain", type: "string" },
623
- { name: "wei", type: "uint64" },
624
- { name: "nonce", type: "uint64" },
625
- ],
626
- },
627
- chainId: parseInt(action.signatureChainId, 16),
628
- });
629
- // Send a request
630
- const request = { action, signature, nonce: action.nonce };
605
+ const request = { action, signature, nonce };
631
606
  const response = await this.transport.request("exchange", request, signal);
632
607
  // Validate a response
633
608
  this._validateResponse(response);
634
609
  return response;
635
610
  }
636
611
  /**
637
- * Configure block type for EVM transactions.
612
+ * Create a vault.
638
613
  * @param args - The parameters for the request.
639
614
  * @param signal - An optional abort signal.
640
- * @returns Response for creating a sub-account.
615
+ * @returns Response for creating a vault.
641
616
  * @throws {ApiRequestError} When the API returns an error response.
642
617
  *
643
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/evm/dual-block-architecture
618
+ * @see null - no documentation
644
619
  * @example
645
620
  * ```ts
646
621
  * import * as hl from "@nktkas/hyperliquid";
@@ -650,16 +625,22 @@
650
625
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
651
626
  * const client = new hl.WalletClient({ wallet, transport });
652
627
  *
653
- * const result = await client.evmUserModify({ usingBigBlocks: true });
628
+ * const result = await client.createVault({
629
+ * name: "VaultName",
630
+ * description: "This is an example of a vault description",
631
+ * initialUsd: 100 * 1e6,
632
+ * });
654
633
  * ```
655
634
  */
656
- async evmUserModify(args, signal) {
657
- // Destructure the parameters
658
- const { nonce = this._nonce, ...actionArgs } = args;
635
+ async createVault(args, signal) {
659
636
  // Construct an action
637
+ const nonce = await this.nonceManager();
660
638
  const action = {
661
- type: "evmUserModify",
662
- usingBigBlocks: actionArgs.usingBigBlocks,
639
+ type: "createVault",
640
+ name: args.name,
641
+ description: args.description,
642
+ initialUsd: args.initialUsd,
643
+ nonce,
663
644
  };
664
645
  // Sign the action
665
646
  const signature = await (0, signing_js_1.signL1Action)({
@@ -676,13 +657,13 @@
676
657
  return response;
677
658
  }
678
659
  /**
679
- * Create a sub-account.
660
+ * Withdraw from staking balance.
680
661
  * @param args - The parameters for the request.
681
662
  * @param signal - An optional abort signal.
682
- * @returns Response for creating a sub-account.
663
+ * @returns Successful response without specific data.
683
664
  * @throws {ApiRequestError} When the API returns an error response.
684
665
  *
685
- * @see null - no documentation
666
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#withdraw-from-staking
686
667
  * @example
687
668
  * ```ts
688
669
  * import * as hl from "@nktkas/hyperliquid";
@@ -692,39 +673,48 @@
692
673
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
693
674
  * const client = new hl.WalletClient({ wallet, transport });
694
675
  *
695
- * const result = await client.createSubAccount({ name: "subAccountName" });
676
+ * const result = await client.cWithdraw({ wei: 1 * 1e8 });
696
677
  * ```
697
678
  */
698
- async createSubAccount(args, signal) {
699
- // Destructure the parameters
700
- const { nonce = this._nonce, ...actionArgs } = args;
679
+ async cWithdraw(args, signal) {
701
680
  // Construct an action
702
681
  const action = {
703
- type: "createSubAccount",
704
- name: actionArgs.name,
682
+ ...args,
683
+ type: "cWithdraw",
684
+ hyperliquidChain: this.isTestnet ? "Testnet" : "Mainnet",
685
+ signatureChainId: typeof this.signatureChainId === "string"
686
+ ? this.signatureChainId
687
+ : await this.signatureChainId(),
688
+ nonce: await this.nonceManager(),
705
689
  };
706
690
  // Sign the action
707
- const signature = await (0, signing_js_1.signL1Action)({
691
+ const signature = await (0, signing_js_1.signUserSignedAction)({
708
692
  wallet: this.wallet,
709
693
  action,
710
- nonce,
711
- isTestnet: this.isTestnet,
694
+ types: {
695
+ "HyperliquidTransaction:CWithdraw": [
696
+ { name: "hyperliquidChain", type: "string" },
697
+ { name: "wei", type: "uint64" },
698
+ { name: "nonce", type: "uint64" },
699
+ ],
700
+ },
701
+ chainId: parseInt(action.signatureChainId, 16),
712
702
  });
713
703
  // Send a request
714
- const request = { action, signature, nonce };
704
+ const request = { action, signature, nonce: action.nonce };
715
705
  const response = await this.transport.request("exchange", request, signal);
716
706
  // Validate a response
717
707
  this._validateResponse(response);
718
708
  return response;
719
709
  }
720
710
  /**
721
- * Create a vault.
711
+ * Configure block type for EVM transactions.
722
712
  * @param args - The parameters for the request.
723
713
  * @param signal - An optional abort signal.
724
- * @returns Response for creating a vault.
714
+ * @returns Response for creating a sub-account.
725
715
  * @throws {ApiRequestError} When the API returns an error response.
726
716
  *
727
- * @see null - no documentation
717
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/evm/dual-block-architecture
728
718
  * @example
729
719
  * ```ts
730
720
  * import * as hl from "@nktkas/hyperliquid";
@@ -734,23 +724,15 @@
734
724
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
735
725
  * const client = new hl.WalletClient({ wallet, transport });
736
726
  *
737
- * const result = await client.createVault({
738
- * name: "VaultName",
739
- * description: "This is an example of a vault description",
740
- * initialUsd: 100 * 1e6,
741
- * });
727
+ * const result = await client.evmUserModify({ usingBigBlocks: true });
742
728
  * ```
743
729
  */
744
- async createVault(args, signal) {
745
- // Destructure the parameters
746
- const { nonce = this._nonce, ...actionArgs } = args;
730
+ async evmUserModify(args, signal) {
747
731
  // Construct an action
732
+ const nonce = await this.nonceManager();
748
733
  const action = {
749
- type: "createVault",
750
- name: actionArgs.name,
751
- description: actionArgs.description,
752
- initialUsd: actionArgs.initialUsd,
753
- nonce,
734
+ type: "evmUserModify",
735
+ usingBigBlocks: args.usingBigBlocks,
754
736
  };
755
737
  // Sign the action
756
738
  const signature = await (0, signing_js_1.signL1Action)({
@@ -784,7 +766,7 @@
784
766
  * const client = new hl.WalletClient({ wallet, transport });
785
767
  *
786
768
  * const result = await client.modify({
787
- * oid: 123, // Order ID
769
+ * oid: 123,
788
770
  * order: {
789
771
  * a: 0, // Asset index
790
772
  * b: true, // Buy order
@@ -803,8 +785,9 @@
803
785
  */
804
786
  async modify(args, signal) {
805
787
  // Destructure the parameters
806
- const { vaultAddress = this.defaultVaultAddress, nonce = this._nonce, ...actionArgs } = args;
788
+ const { vaultAddress = this.defaultVaultAddress, ...actionArgs } = args;
807
789
  // Construct an action
790
+ const nonce = await this.nonceManager();
808
791
  const action = {
809
792
  type: "modify",
810
793
  oid: actionArgs.oid,
@@ -884,8 +867,9 @@
884
867
  */
885
868
  async order(args, signal) {
886
869
  // Destructure the parameters
887
- const { vaultAddress = this.defaultVaultAddress, nonce = this._nonce, ...actionArgs } = args;
870
+ const { vaultAddress = this.defaultVaultAddress, ...actionArgs } = args;
888
871
  // Construct an action
872
+ const nonce = await this.nonceManager();
889
873
  const action = {
890
874
  type: "order",
891
875
  orders: actionArgs.orders.map((order) => {
@@ -939,6 +923,47 @@
939
923
  this._validateResponse(response);
940
924
  return response;
941
925
  }
926
+ /**
927
+ * Reserve additional rate-limited actions for a fee.
928
+ * @param args - The parameters for the request.
929
+ * @param signal - An optional abort signal.
930
+ * @returns Successful response indicating the weight reservation.
931
+ * @throws {ApiRequestError} When the API returns an error response.
932
+ *
933
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#reserve-additional-actions
934
+ * @example
935
+ * ```ts
936
+ * import * as hl from "@nktkas/hyperliquid";
937
+ * import { privateKeyToAccount } from "viem/accounts";
938
+ *
939
+ * const wallet = privateKeyToAccount("0x...");
940
+ * const transport = new hl.HttpTransport(); // or WebSocketTransport
941
+ * const client = new hl.WalletClient({ wallet, transport });
942
+ *
943
+ * const result = await client.reserveRequestWeight({ weight: 10 });
944
+ * ```
945
+ */
946
+ async reserveRequestWeight(args, signal) {
947
+ // Construct an action
948
+ const nonce = await this.nonceManager();
949
+ const action = {
950
+ type: "reserveRequestWeight",
951
+ weight: args.weight,
952
+ };
953
+ // Sign the action
954
+ const signature = await (0, signing_js_1.signL1Action)({
955
+ wallet: this.wallet,
956
+ action,
957
+ nonce,
958
+ isTestnet: this.isTestnet,
959
+ });
960
+ // Send a request
961
+ const request = { action, signature, nonce };
962
+ const response = await this.transport.request("exchange", request, signal);
963
+ // Validate a response
964
+ this._validateResponse(response);
965
+ return response;
966
+ }
942
967
  /**
943
968
  * Schedule a time to cancel all open orders.
944
969
  * @param args - The parameters for the request.
@@ -961,8 +986,9 @@
961
986
  */
962
987
  async scheduleCancel(args = {}, signal) {
963
988
  // Destructure the parameters
964
- const { vaultAddress = this.defaultVaultAddress, nonce = this._nonce, ...actionArgs } = args;
989
+ const { vaultAddress = this.defaultVaultAddress, ...actionArgs } = args;
965
990
  // Construct an action
991
+ const nonce = await this.nonceManager();
966
992
  const action = {
967
993
  type: "scheduleCancel",
968
994
  time: actionArgs.time,
@@ -1005,12 +1031,11 @@
1005
1031
  * ```
1006
1032
  */
1007
1033
  async setDisplayName(args, signal) {
1008
- // Destructure the parameters
1009
- const { nonce = this._nonce, ...actionArgs } = args;
1010
1034
  // Construct an action
1035
+ const nonce = await this.nonceManager();
1011
1036
  const action = {
1012
1037
  type: "setDisplayName",
1013
- displayName: actionArgs.displayName,
1038
+ displayName: args.displayName,
1014
1039
  };
1015
1040
  // Sign the action
1016
1041
  const signature = await (0, signing_js_1.signL1Action)({
@@ -1047,12 +1072,11 @@
1047
1072
  * ```
1048
1073
  */
1049
1074
  async setReferrer(args, signal) {
1050
- // Destructure the parameters
1051
- const { nonce = this._nonce, ...actionArgs } = args;
1052
1075
  // Construct an action
1076
+ const nonce = await this.nonceManager();
1053
1077
  const action = {
1054
1078
  type: "setReferrer",
1055
- code: actionArgs.code,
1079
+ code: args.code,
1056
1080
  };
1057
1081
  // Sign the action
1058
1082
  const signature = await (0, signing_js_1.signL1Action)({
@@ -1086,7 +1110,6 @@
1086
1110
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1087
1111
  * const client = new hl.WalletClient({ wallet, transport });
1088
1112
  *
1089
- * // Unknown what the successful response will be
1090
1113
  * const result = await client.spotDeploy({
1091
1114
  * registerToken2: {
1092
1115
  * spec: {
@@ -1101,48 +1124,47 @@
1101
1124
  * ```
1102
1125
  */
1103
1126
  async spotDeploy(args, signal) {
1104
- // Destructure the parameters
1105
- const { nonce = this._nonce, ...actionArgs } = args;
1106
1127
  // Construct an action
1128
+ const nonce = await this.nonceManager();
1107
1129
  let action;
1108
- if ("registerToken2" in actionArgs) {
1130
+ if ("registerToken2" in args) {
1109
1131
  action = {
1110
1132
  type: "spotDeploy",
1111
1133
  registerToken2: {
1112
1134
  spec: {
1113
- name: actionArgs.registerToken2.spec.name,
1114
- szDecimals: actionArgs.registerToken2.spec.szDecimals,
1115
- weiDecimals: actionArgs.registerToken2.spec.weiDecimals,
1135
+ name: args.registerToken2.spec.name,
1136
+ szDecimals: args.registerToken2.spec.szDecimals,
1137
+ weiDecimals: args.registerToken2.spec.weiDecimals,
1116
1138
  },
1117
- maxGas: actionArgs.registerToken2.maxGas,
1118
- fullName: actionArgs.registerToken2.fullName,
1139
+ maxGas: args.registerToken2.maxGas,
1140
+ fullName: args.registerToken2.fullName,
1119
1141
  },
1120
1142
  };
1121
1143
  }
1122
- else if ("userGenesis" in actionArgs) {
1144
+ else if ("userGenesis" in args) {
1123
1145
  action = {
1124
1146
  type: "spotDeploy",
1125
1147
  userGenesis: {
1126
- token: actionArgs.userGenesis.token,
1127
- userAndWei: actionArgs.userGenesis.userAndWei,
1128
- existingTokenAndWei: actionArgs.userGenesis.existingTokenAndWei,
1148
+ token: args.userGenesis.token,
1149
+ userAndWei: args.userGenesis.userAndWei,
1150
+ existingTokenAndWei: args.userGenesis.existingTokenAndWei,
1129
1151
  },
1130
1152
  };
1131
1153
  }
1132
- else if ("genesis" in actionArgs) {
1154
+ else if ("genesis" in args) {
1133
1155
  action = {
1134
1156
  type: "spotDeploy",
1135
1157
  genesis: {
1136
- token: actionArgs.genesis.token,
1137
- maxSupply: actionArgs.genesis.maxSupply,
1158
+ token: args.genesis.token,
1159
+ maxSupply: args.genesis.maxSupply,
1138
1160
  },
1139
1161
  };
1140
1162
  }
1141
- else if ("registerSpot" in actionArgs) {
1163
+ else if ("registerSpot" in args) {
1142
1164
  action = {
1143
1165
  type: "spotDeploy",
1144
1166
  registerSpot: {
1145
- tokens: actionArgs.registerSpot.tokens,
1167
+ tokens: args.registerSpot.tokens,
1146
1168
  },
1147
1169
  };
1148
1170
  }
@@ -1150,11 +1172,11 @@
1150
1172
  action = {
1151
1173
  type: "spotDeploy",
1152
1174
  registerHyperliquidity: {
1153
- spot: actionArgs.registerHyperliquidity.spot,
1154
- startPx: actionArgs.registerHyperliquidity.startPx,
1155
- orderSz: actionArgs.registerHyperliquidity.orderSz,
1156
- nOrders: actionArgs.registerHyperliquidity.nOrders,
1157
- nSeededLevels: actionArgs.registerHyperliquidity.nSeededLevels,
1175
+ spot: args.registerHyperliquidity.spot,
1176
+ startPx: args.registerHyperliquidity.startPx,
1177
+ orderSz: args.registerHyperliquidity.orderSz,
1178
+ nOrders: args.registerHyperliquidity.nOrders,
1179
+ nSeededLevels: args.registerHyperliquidity.nSeededLevels,
1158
1180
  },
1159
1181
  };
1160
1182
  }
@@ -1179,7 +1201,7 @@
1179
1201
  * @returns Successful response without specific data.
1180
1202
  * @throws {ApiRequestError} When the API returns an error response.
1181
1203
  *
1182
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#l1-spot-transfer
1204
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#core-spot-transfer
1183
1205
  * @example
1184
1206
  * ```ts
1185
1207
  * import * as hl from "@nktkas/hyperliquid";
@@ -1205,7 +1227,7 @@
1205
1227
  signatureChainId: typeof this.signatureChainId === "string"
1206
1228
  ? this.signatureChainId
1207
1229
  : await this.signatureChainId(),
1208
- time: args.time ?? this._nonce,
1230
+ time: await this.nonceManager(),
1209
1231
  };
1210
1232
  // Sign the action
1211
1233
  const signature = await (0, signing_js_1.signUserSignedAction)({
@@ -1246,19 +1268,16 @@
1246
1268
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1247
1269
  * const client = new hl.WalletClient({ wallet, transport });
1248
1270
  *
1249
- * const result = await client.spotUser({
1250
- * toggleSpotDusting: { optOut: false },
1251
- * });
1271
+ * const result = await client.spotUser({ toggleSpotDusting: { optOut: false } });
1252
1272
  * ```
1253
1273
  */
1254
1274
  async spotUser(args, signal) {
1255
- // Destructure the parameters
1256
- const { nonce = this._nonce, ...actionArgs } = args;
1257
1275
  // Construct an action
1276
+ const nonce = await this.nonceManager();
1258
1277
  const action = {
1259
1278
  type: "spotUser",
1260
1279
  toggleSpotDusting: {
1261
- optOut: actionArgs.toggleSpotDusting.optOut,
1280
+ optOut: args.toggleSpotDusting.optOut,
1262
1281
  },
1263
1282
  };
1264
1283
  // Sign the action
@@ -1301,15 +1320,14 @@
1301
1320
  * ```
1302
1321
  */
1303
1322
  async subAccountSpotTransfer(args, signal) {
1304
- // Destructure the parameters
1305
- const { nonce = this._nonce, ...actionArgs } = args;
1306
1323
  // Construct an action
1324
+ const nonce = await this.nonceManager();
1307
1325
  const action = {
1308
1326
  type: "subAccountSpotTransfer",
1309
- subAccountUser: actionArgs.subAccountUser,
1310
- isDeposit: actionArgs.isDeposit,
1311
- token: actionArgs.token,
1312
- amount: actionArgs.amount,
1327
+ subAccountUser: args.subAccountUser,
1328
+ isDeposit: args.isDeposit,
1329
+ token: args.token,
1330
+ amount: args.amount,
1313
1331
  };
1314
1332
  // Sign the action
1315
1333
  const signature = await (0, signing_js_1.signL1Action)({
@@ -1350,14 +1368,13 @@
1350
1368
  * ```
1351
1369
  */
1352
1370
  async subAccountTransfer(args, signal) {
1353
- // Destructure the parameters
1354
- const { nonce = this._nonce, ...actionArgs } = args;
1355
1371
  // Construct an action
1372
+ const nonce = await this.nonceManager();
1356
1373
  const action = {
1357
1374
  type: "subAccountTransfer",
1358
- subAccountUser: actionArgs.subAccountUser,
1359
- isDeposit: actionArgs.isDeposit,
1360
- usd: actionArgs.usd,
1375
+ subAccountUser: args.subAccountUser,
1376
+ isDeposit: args.isDeposit,
1377
+ usd: args.usd,
1361
1378
  };
1362
1379
  // Sign the action
1363
1380
  const signature = await (0, signing_js_1.signL1Action)({
@@ -1406,7 +1423,7 @@
1406
1423
  signatureChainId: typeof this.signatureChainId === "string"
1407
1424
  ? this.signatureChainId
1408
1425
  : await this.signatureChainId(),
1409
- nonce: args.nonce ?? this._nonce,
1426
+ nonce: await this.nonceManager(),
1410
1427
  };
1411
1428
  // Sign the action
1412
1429
  const signature = await (0, signing_js_1.signUserSignedAction)({
@@ -1455,8 +1472,9 @@
1455
1472
  */
1456
1473
  async twapCancel(args, signal) {
1457
1474
  // Destructure the parameters
1458
- const { vaultAddress = this.defaultVaultAddress, nonce = this._nonce, ...actionArgs } = args;
1475
+ const { vaultAddress = this.defaultVaultAddress, ...actionArgs } = args;
1459
1476
  // Construct an action
1477
+ const nonce = await this.nonceManager();
1460
1478
  const action = {
1461
1479
  type: "twapCancel",
1462
1480
  a: actionArgs.a,
@@ -1506,8 +1524,9 @@
1506
1524
  */
1507
1525
  async twapOrder(args, signal) {
1508
1526
  // Destructure the parameters
1509
- const { vaultAddress = this.defaultVaultAddress, nonce = this._nonce, ...actionArgs } = args;
1527
+ const { vaultAddress = this.defaultVaultAddress, ...actionArgs } = args;
1510
1528
  // Construct an action
1529
+ const nonce = await this.nonceManager();
1511
1530
  const action = {
1512
1531
  type: "twapOrder",
1513
1532
  twap: {
@@ -1551,17 +1570,14 @@
1551
1570
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1552
1571
  * const client = new hl.WalletClient({ wallet, transport });
1553
1572
  *
1554
- * const result = await client.updateIsolatedMargin({
1555
- * asset: 0,
1556
- * isBuy: true, // Add to long position
1557
- * ntli: 1, // Add 1 USD margin (integer only)
1558
- * });
1573
+ * const result = await client.updateIsolatedMargin({ asset: 0, isBuy: true, ntli: 1 * 1e6 });
1559
1574
  * ```
1560
1575
  */
1561
1576
  async updateIsolatedMargin(args, signal) {
1562
1577
  // Destructure the parameters
1563
- const { vaultAddress = this.defaultVaultAddress, nonce = this._nonce, ...actionArgs } = args;
1578
+ const { vaultAddress = this.defaultVaultAddress, ...actionArgs } = args;
1564
1579
  // Construct an action
1580
+ const nonce = await this.nonceManager();
1565
1581
  const action = {
1566
1582
  type: "updateIsolatedMargin",
1567
1583
  asset: actionArgs.asset,
@@ -1600,17 +1616,14 @@
1600
1616
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1601
1617
  * const client = new hl.WalletClient({ wallet, transport });
1602
1618
  *
1603
- * const result = await client.updateLeverage({
1604
- * asset: 0,
1605
- * isCross: true,
1606
- * leverage: 5,
1607
- * });
1619
+ * const result = await client.updateLeverage({ asset: 0, isCross: true, leverage: 5 });
1608
1620
  * ```
1609
1621
  */
1610
1622
  async updateLeverage(args, signal) {
1611
1623
  // Destructure the parameters
1612
- const { vaultAddress = this.defaultVaultAddress, nonce = this._nonce, ...actionArgs } = args;
1624
+ const { vaultAddress = this.defaultVaultAddress, ...actionArgs } = args;
1613
1625
  // Construct an action
1626
+ const nonce = await this.nonceManager();
1614
1627
  const action = {
1615
1628
  type: "updateLeverage",
1616
1629
  asset: actionArgs.asset,
@@ -1649,10 +1662,7 @@
1649
1662
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1650
1663
  * const client = new hl.WalletClient({ wallet, transport });
1651
1664
  *
1652
- * const result = await client.usdClassTransfer({
1653
- * amount: "1",
1654
- * toPerp: true, // Transfer from Spot to Perp
1655
- * });
1665
+ * const result = await client.usdClassTransfer({ amount: "1", toPerp: true });
1656
1666
  * ```
1657
1667
  */
1658
1668
  async usdClassTransfer(args, signal) {
@@ -1664,7 +1674,7 @@
1664
1674
  signatureChainId: typeof this.signatureChainId === "string"
1665
1675
  ? this.signatureChainId
1666
1676
  : await this.signatureChainId(),
1667
- nonce: args.nonce ?? this._nonce,
1677
+ nonce: await this.nonceManager(),
1668
1678
  };
1669
1679
  // Sign the action
1670
1680
  const signature = await (0, signing_js_1.signUserSignedAction)({
@@ -1694,7 +1704,7 @@
1694
1704
  * @returns Successful response without specific data.
1695
1705
  * @throws {ApiRequestError} When the API returns an error response.
1696
1706
  *
1697
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#l1-usdc-transfer
1707
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#core-usdc-transfer
1698
1708
  * @example
1699
1709
  * ```ts
1700
1710
  * import * as hl from "@nktkas/hyperliquid";
@@ -1704,10 +1714,7 @@
1704
1714
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1705
1715
  * const client = new hl.WalletClient({ wallet, transport });
1706
1716
  *
1707
- * const result = await client.usdSend({
1708
- * destination: "0x...",
1709
- * amount: "1",
1710
- * });
1717
+ * const result = await client.usdSend({ destination: "0x...", amount: "1" });
1711
1718
  * ```
1712
1719
  */
1713
1720
  async usdSend(args, signal) {
@@ -1719,7 +1726,7 @@
1719
1726
  signatureChainId: typeof this.signatureChainId === "string"
1720
1727
  ? this.signatureChainId
1721
1728
  : await this.signatureChainId(),
1722
- time: args.time ?? this._nonce,
1729
+ time: await this.nonceManager(),
1723
1730
  };
1724
1731
  // Sign the action
1725
1732
  const signature = await (0, signing_js_1.signUserSignedAction)({
@@ -1759,20 +1766,16 @@
1759
1766
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1760
1767
  * const client = new hl.WalletClient({ wallet, transport });
1761
1768
  *
1762
- * const result = await client.vaultDistribute({
1763
- * vaultAddress: "0x...",
1764
- * usd: 10 * 1e6,
1765
- * });
1769
+ * const result = await client.vaultDistribute({ vaultAddress: "0x...", usd: 10 * 1e6 });
1766
1770
  * ```
1767
1771
  */
1768
1772
  async vaultDistribute(args, signal) {
1769
- // Destructure the parameters
1770
- const { nonce = this._nonce, ...actionArgs } = args;
1771
1773
  // Construct an action
1774
+ const nonce = await this.nonceManager();
1772
1775
  const action = {
1773
1776
  type: "vaultDistribute",
1774
- vaultAddress: actionArgs.vaultAddress,
1775
- usd: actionArgs.usd,
1777
+ vaultAddress: args.vaultAddress,
1778
+ usd: args.usd,
1776
1779
  };
1777
1780
  // Sign the action
1778
1781
  const signature = await (0, signing_js_1.signL1Action)({
@@ -1813,14 +1816,13 @@
1813
1816
  * ```
1814
1817
  */
1815
1818
  async vaultModify(args, signal) {
1816
- // Destructure the parameters
1817
- const { nonce = this._nonce, ...actionArgs } = args;
1818
1819
  // Construct an action
1820
+ const nonce = await this.nonceManager();
1819
1821
  const action = {
1820
1822
  type: "vaultModify",
1821
- vaultAddress: actionArgs.vaultAddress,
1822
- allowDeposits: actionArgs.allowDeposits,
1823
- alwaysCloseOnWithdraw: actionArgs.alwaysCloseOnWithdraw,
1823
+ vaultAddress: args.vaultAddress,
1824
+ allowDeposits: args.allowDeposits,
1825
+ alwaysCloseOnWithdraw: args.alwaysCloseOnWithdraw,
1824
1826
  };
1825
1827
  // Sign the action
1826
1828
  const signature = await (0, signing_js_1.signL1Action)({
@@ -1861,14 +1863,13 @@
1861
1863
  * ```
1862
1864
  */
1863
1865
  async vaultTransfer(args, signal) {
1864
- // Destructure the parameters
1865
- const { nonce = this._nonce, ...actionArgs } = args;
1866
1866
  // Construct an action
1867
+ const nonce = await this.nonceManager();
1867
1868
  const action = {
1868
1869
  type: "vaultTransfer",
1869
- vaultAddress: actionArgs.vaultAddress,
1870
- isDeposit: actionArgs.isDeposit,
1871
- usd: actionArgs.usd,
1870
+ vaultAddress: args.vaultAddress,
1871
+ isDeposit: args.isDeposit,
1872
+ usd: args.usd,
1872
1873
  };
1873
1874
  // Sign the action
1874
1875
  const signature = await (0, signing_js_1.signL1Action)({
@@ -1901,10 +1902,7 @@
1901
1902
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1902
1903
  * const client = new hl.WalletClient({ wallet, transport });
1903
1904
  *
1904
- * const result = await client.withdraw3({
1905
- * destination: "0x...",
1906
- * amount: "1",
1907
- * });
1905
+ * const result = await client.withdraw3({ destination: "0x...", amount: "1" });
1908
1906
  * ```
1909
1907
  */
1910
1908
  async withdraw3(args, signal) {
@@ -1916,7 +1914,7 @@
1916
1914
  signatureChainId: typeof this.signatureChainId === "string"
1917
1915
  ? this.signatureChainId
1918
1916
  : await this.signatureChainId(),
1919
- time: args.time ?? this._nonce,
1917
+ time: await this.nonceManager(),
1920
1918
  };
1921
1919
  // Sign the action
1922
1920
  const signature = await (0, signing_js_1.signUserSignedAction)({
@@ -1939,7 +1937,6 @@
1939
1937
  this._validateResponse(response);
1940
1938
  return response;
1941
1939
  }
1942
- // ——————————————— Private methods ———————————————
1943
1940
  /** Formats a decimal number as a string, removing trailing zeros. */
1944
1941
  _formatDecimal(numStr) {
1945
1942
  if (!numStr.includes("."))
@@ -1948,6 +1945,31 @@
1948
1945
  const newFrac = fracPart.replace(/0+$/, "");
1949
1946
  return newFrac ? `${intPart}.${newFrac}` : intPart;
1950
1947
  }
1948
+ /** Guesses the chain ID based on the wallet type or the isTestnet flag. */
1949
+ async _guessSignatureChainId() {
1950
+ // Trying to get chain ID of the wallet
1951
+ if ((0, signing_js_1.isAbstractViemWalletClient)(this.wallet)) {
1952
+ if ("getChainId" in this.wallet && typeof this.wallet.getChainId === "function") {
1953
+ const chainId = await this.wallet.getChainId();
1954
+ return `0x${chainId.toString(16)}`;
1955
+ }
1956
+ }
1957
+ else if ((0, signing_js_1.isAbstractEthersSigner)(this.wallet) || (0, signing_js_1.isAbstractEthersV5Signer)(this.wallet)) {
1958
+ if ("provider" in this.wallet &&
1959
+ typeof this.wallet.provider === "object" && this.wallet.provider !== null &&
1960
+ "getNetwork" in this.wallet.provider &&
1961
+ typeof this.wallet.provider.getNetwork === "function") {
1962
+ const network = await this.wallet.provider.getNetwork();
1963
+ return `0x${network.chainId.toString(16)}`;
1964
+ }
1965
+ }
1966
+ else if ((0, signing_js_1.isAbstractWindowEthereum)(this.wallet)) {
1967
+ const [chainId] = await this.wallet.request({ method: "eth_chainId", params: [] });
1968
+ return chainId;
1969
+ }
1970
+ // Attempt to guess chain ID based on isTestnet
1971
+ return this.isTestnet ? "0x66eee" : "0xa4b1";
1972
+ }
1951
1973
  /** Validate a response from the API. */
1952
1974
  _validateResponse(response) {
1953
1975
  if (response.status === "err") {