@nktkas/hyperliquid 0.17.0 → 0.17.2

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 (99) hide show
  1. package/README.md +16 -14
  2. package/esm/deps/jsr.io/@std/encoding/1.0.8/_common16.d.ts +21 -0
  3. package/esm/deps/jsr.io/@std/encoding/1.0.8/_common16.d.ts.map +1 -0
  4. package/esm/deps/jsr.io/@std/encoding/1.0.8/_common16.js +45 -0
  5. package/esm/deps/jsr.io/@std/encoding/1.0.8/_common_detach.d.ts +4 -0
  6. package/esm/deps/jsr.io/@std/encoding/1.0.8/_common_detach.d.ts.map +1 -0
  7. package/esm/deps/jsr.io/@std/encoding/1.0.8/_common_detach.js +13 -0
  8. package/{script/deps/jsr.io/@std/encoding/1.0.7 → esm/deps/jsr.io/@std/encoding/1.0.8}/_types.d.ts.map +1 -1
  9. package/esm/deps/jsr.io/@std/encoding/1.0.8/hex.d.ts.map +1 -0
  10. package/esm/deps/jsr.io/@std/encoding/1.0.8/hex.js +87 -0
  11. package/esm/src/clients/event.d.ts +25 -2
  12. package/esm/src/clients/event.d.ts.map +1 -1
  13. package/esm/src/clients/event.js +31 -1
  14. package/esm/src/clients/public.d.ts +9 -9
  15. package/esm/src/clients/public.d.ts.map +1 -1
  16. package/esm/src/clients/public.js +9 -12
  17. package/esm/src/clients/wallet.d.ts +52 -59
  18. package/esm/src/clients/wallet.d.ts.map +1 -1
  19. package/esm/src/clients/wallet.js +69 -62
  20. package/esm/src/signing.d.ts +44 -0
  21. package/esm/src/signing.d.ts.map +1 -1
  22. package/esm/src/signing.js +45 -1
  23. package/esm/src/types/exchange/requests.d.ts +57 -43
  24. package/esm/src/types/exchange/requests.d.ts.map +1 -1
  25. package/esm/src/types/explorer/requests.d.ts +3 -3
  26. package/esm/src/types/info/accounts.d.ts +13 -1
  27. package/esm/src/types/info/accounts.d.ts.map +1 -1
  28. package/esm/src/types/info/assets.d.ts +2 -6
  29. package/esm/src/types/info/assets.d.ts.map +1 -1
  30. package/esm/src/types/info/orders.d.ts +3 -1
  31. package/esm/src/types/info/orders.d.ts.map +1 -1
  32. package/esm/src/types/info/requests.d.ts +10 -10
  33. package/esm/src/types/info/requests.d.ts.map +1 -1
  34. package/esm/src/types/info/vaults.d.ts +22 -17
  35. package/esm/src/types/info/vaults.d.ts.map +1 -1
  36. package/esm/src/types/mod.d.ts +0 -2
  37. package/esm/src/types/mod.d.ts.map +1 -1
  38. package/esm/src/types/mod.js +0 -2
  39. package/esm/src/types/subscriptions/requests.d.ts +34 -36
  40. package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
  41. package/esm/src/types/subscriptions/responses.d.ts +48 -48
  42. package/esm/src/types/subscriptions/responses.d.ts.map +1 -1
  43. package/package.json +1 -1
  44. package/script/deps/jsr.io/@std/encoding/1.0.8/_common16.d.ts +21 -0
  45. package/script/deps/jsr.io/@std/encoding/1.0.8/_common16.d.ts.map +1 -0
  46. package/script/deps/jsr.io/@std/encoding/1.0.8/_common16.js +60 -0
  47. package/script/deps/jsr.io/@std/encoding/1.0.8/_common_detach.d.ts +4 -0
  48. package/script/deps/jsr.io/@std/encoding/1.0.8/_common_detach.d.ts.map +1 -0
  49. package/script/deps/jsr.io/@std/encoding/1.0.8/_common_detach.js +26 -0
  50. package/{esm/deps/jsr.io/@std/encoding/1.0.7 → script/deps/jsr.io/@std/encoding/1.0.8}/_types.d.ts.map +1 -1
  51. package/script/deps/jsr.io/@std/encoding/1.0.8/hex.d.ts.map +1 -0
  52. package/script/deps/jsr.io/@std/encoding/{1.0.7 → 1.0.8}/hex.js +23 -45
  53. package/script/src/clients/event.d.ts +25 -2
  54. package/script/src/clients/event.d.ts.map +1 -1
  55. package/script/src/clients/event.js +31 -1
  56. package/script/src/clients/public.d.ts +9 -9
  57. package/script/src/clients/public.d.ts.map +1 -1
  58. package/script/src/clients/public.js +9 -12
  59. package/script/src/clients/wallet.d.ts +52 -59
  60. package/script/src/clients/wallet.d.ts.map +1 -1
  61. package/script/src/clients/wallet.js +69 -62
  62. package/script/src/signing.d.ts +44 -0
  63. package/script/src/signing.d.ts.map +1 -1
  64. package/script/src/signing.js +46 -2
  65. package/script/src/types/exchange/requests.d.ts +57 -43
  66. package/script/src/types/exchange/requests.d.ts.map +1 -1
  67. package/script/src/types/explorer/requests.d.ts +3 -3
  68. package/script/src/types/info/accounts.d.ts +13 -1
  69. package/script/src/types/info/accounts.d.ts.map +1 -1
  70. package/script/src/types/info/assets.d.ts +2 -6
  71. package/script/src/types/info/assets.d.ts.map +1 -1
  72. package/script/src/types/info/orders.d.ts +3 -1
  73. package/script/src/types/info/orders.d.ts.map +1 -1
  74. package/script/src/types/info/requests.d.ts +10 -10
  75. package/script/src/types/info/requests.d.ts.map +1 -1
  76. package/script/src/types/info/vaults.d.ts +22 -17
  77. package/script/src/types/info/vaults.d.ts.map +1 -1
  78. package/script/src/types/mod.d.ts +0 -2
  79. package/script/src/types/mod.d.ts.map +1 -1
  80. package/script/src/types/mod.js +0 -2
  81. package/script/src/types/subscriptions/requests.d.ts +34 -36
  82. package/script/src/types/subscriptions/requests.d.ts.map +1 -1
  83. package/script/src/types/subscriptions/responses.d.ts +48 -48
  84. package/script/src/types/subscriptions/responses.d.ts.map +1 -1
  85. package/esm/deps/jsr.io/@std/encoding/1.0.7/_validate_binary_like.d.ts +0 -2
  86. package/esm/deps/jsr.io/@std/encoding/1.0.7/_validate_binary_like.d.ts.map +0 -1
  87. package/esm/deps/jsr.io/@std/encoding/1.0.7/_validate_binary_like.js +0 -26
  88. package/esm/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +0 -1
  89. package/esm/deps/jsr.io/@std/encoding/1.0.7/hex.js +0 -109
  90. package/script/deps/jsr.io/@std/encoding/1.0.7/_validate_binary_like.d.ts +0 -2
  91. package/script/deps/jsr.io/@std/encoding/1.0.7/_validate_binary_like.d.ts.map +0 -1
  92. package/script/deps/jsr.io/@std/encoding/1.0.7/_validate_binary_like.js +0 -39
  93. package/script/deps/jsr.io/@std/encoding/1.0.7/hex.d.ts.map +0 -1
  94. /package/esm/deps/jsr.io/@std/encoding/{1.0.7 → 1.0.8}/_types.d.ts +0 -0
  95. /package/esm/deps/jsr.io/@std/encoding/{1.0.7 → 1.0.8}/_types.js +0 -0
  96. /package/esm/deps/jsr.io/@std/encoding/{1.0.7 → 1.0.8}/hex.d.ts +0 -0
  97. /package/script/deps/jsr.io/@std/encoding/{1.0.7 → 1.0.8}/_types.d.ts +0 -0
  98. /package/script/deps/jsr.io/@std/encoding/{1.0.7 → 1.0.8}/_types.js +0 -0
  99. /package/script/deps/jsr.io/@std/encoding/{1.0.7 → 1.0.8}/hex.d.ts +0 -0
@@ -1,6 +1,5 @@
1
1
  import { HyperliquidError } from "../base.js";
2
2
  import { isAbstractEthersSigner, isAbstractEthersV5Signer, isAbstractViemWalletClient, isAbstractWindowEthereum, signL1Action, signUserSignedAction, } from "../signing.js";
3
- // ——————————————— Errors ———————————————
4
3
  /** Error thrown when the API returns an error response. */
5
4
  export class ApiRequestError extends HyperliquidError {
6
5
  constructor(response) {
@@ -39,7 +38,6 @@ export class ApiRequestError extends HyperliquidError {
39
38
  this.name = "ApiRequestError";
40
39
  }
41
40
  }
42
- // ——————————————— Client ———————————————
43
41
  /** Nonce manager for generating unique nonces for signing transactions. */
44
42
  class NonceManager {
45
43
  constructor() {
@@ -171,9 +169,8 @@ export class WalletClient {
171
169
  this.signatureChainId = args.signatureChainId ?? this._guessSignatureChainId;
172
170
  this.nonceManager = args.nonceManager ?? new NonceManager().getNonce;
173
171
  }
174
- // ——————————————— Exchange API ———————————————
175
172
  /**
176
- * Approve an agent to sign on behalf of the master or sub-accounts.
173
+ * Approve an agent to sign on behalf of the master account.
177
174
  * @param args - The parameters for the request.
178
175
  * @param signal - An optional abort signal
179
176
  * @returns Successful response without specific data.
@@ -189,10 +186,7 @@ export class WalletClient {
189
186
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
190
187
  * const client = new hl.WalletClient({ wallet, transport });
191
188
  *
192
- * const result = await client.approveAgent({
193
- * agentAddress: "0x...",
194
- * agentName: "agentName",
195
- * });
189
+ * const result = await client.approveAgent({ agentAddress: "0x...", agentName: "agentName" });
196
190
  * ```
197
191
  */
198
192
  async approveAgent(args, signal) {
@@ -228,7 +222,7 @@ export class WalletClient {
228
222
  return response;
229
223
  }
230
224
  /**
231
- * Approve a max fee rate for a builder address.
225
+ * Approve a maximum fee rate for a builder.
232
226
  * @param args - The parameters for the request.
233
227
  * @param signal - An optional abort signal.
234
228
  * @returns Successful response without specific data.
@@ -244,10 +238,7 @@ export class WalletClient {
244
238
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
245
239
  * const client = new hl.WalletClient({ wallet, transport });
246
240
  *
247
- * const result = await client.approveBuilderFee({
248
- * maxFeeRate: "0.01%",
249
- * builder: "0x...",
250
- * });
241
+ * const result = await client.approveBuilderFee({ maxFeeRate: "0.01%", builder: "0x..." });
251
242
  * ```
252
243
  */
253
244
  async approveBuilderFee(args, signal) {
@@ -301,7 +292,7 @@ export class WalletClient {
301
292
  *
302
293
  * const result = await client.batchModify({
303
294
  * modifies: [{
304
- * oid: 123, // Order ID
295
+ * oid: 123,
305
296
  * order: {
306
297
  * a: 0, // Asset index
307
298
  * b: true, // Buy order
@@ -441,10 +432,9 @@ export class WalletClient {
441
432
  * const client = new hl.WalletClient({ wallet, transport });
442
433
  *
443
434
  * const result = await client.cancelByCloid({
444
- * cancels: [{
445
- * asset: 0,
446
- * cloid: "0x...", // Client Order ID
447
- * }],
435
+ * cancels: [
436
+ * { asset: 0, cloid: "0x..." },
437
+ * ],
448
438
  * });
449
439
  * ```
450
440
  */
@@ -476,7 +466,7 @@ export class WalletClient {
476
466
  return response;
477
467
  }
478
468
  /**
479
- * Deposit into staking balance.
469
+ * Transfer native token from the user's spot account into staking for delegating to validators.
480
470
  * @param args - The parameters for the request.
481
471
  * @param signal - An optional abort signal.
482
472
  * @returns Successful response without specific data.
@@ -654,7 +644,7 @@ export class WalletClient {
654
644
  return response;
655
645
  }
656
646
  /**
657
- * Withdraw from staking balance.
647
+ * Transfer native token from staking into the user's spot account.
658
648
  * @param args - The parameters for the request.
659
649
  * @param signal - An optional abort signal.
660
650
  * @returns Successful response without specific data.
@@ -763,7 +753,7 @@ export class WalletClient {
763
753
  * const client = new hl.WalletClient({ wallet, transport });
764
754
  *
765
755
  * const result = await client.modify({
766
- * oid: 123, // Order ID
756
+ * oid: 123,
767
757
  * order: {
768
758
  * a: 0, // Asset index
769
759
  * b: true, // Buy order
@@ -920,11 +910,52 @@ export class WalletClient {
920
910
  this._validateResponse(response);
921
911
  return response;
922
912
  }
913
+ /**
914
+ * Create a referral code.
915
+ * @param args - The parameters for the request.
916
+ * @param signal - An optional abort signal.
917
+ * @returns Successful response without specific data.
918
+ * @throws {ApiRequestError} When the API returns an error response.
919
+ *
920
+ * @see null - no documentation
921
+ * @example
922
+ * ```ts
923
+ * import * as hl from "@nktkas/hyperliquid";
924
+ * import { privateKeyToAccount } from "viem/accounts";
925
+ *
926
+ * const wallet = privateKeyToAccount("0x...");
927
+ * const transport = new hl.HttpTransport(); // or WebSocketTransport
928
+ * const client = new hl.WalletClient({ wallet, transport });
929
+ *
930
+ * const result = await client.registerReferrer({ code: "TEST" });
931
+ * ```
932
+ */
933
+ async registerReferrer(args, signal) {
934
+ // Construct an action
935
+ const nonce = await this.nonceManager();
936
+ const action = {
937
+ type: "registerReferrer",
938
+ code: args.code,
939
+ };
940
+ // Sign the action
941
+ const signature = await signL1Action({
942
+ wallet: this.wallet,
943
+ action,
944
+ nonce,
945
+ isTestnet: this.isTestnet,
946
+ });
947
+ // Send a request
948
+ const request = { action, signature, nonce };
949
+ const response = await this.transport.request("exchange", request, signal);
950
+ // Validate a response
951
+ this._validateResponse(response);
952
+ return response;
953
+ }
923
954
  /**
924
955
  * Reserve additional rate-limited actions for a fee.
925
956
  * @param args - The parameters for the request.
926
957
  * @param signal - An optional abort signal.
927
- * @returns Successful response indicating the weight reservation.
958
+ * @returns Successful response without specific data.
928
959
  * @throws {ApiRequestError} When the API returns an error response.
929
960
  *
930
961
  * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#reserve-additional-actions
@@ -962,7 +993,7 @@ export class WalletClient {
962
993
  return response;
963
994
  }
964
995
  /**
965
- * Schedule a time to cancel all open orders.
996
+ * Schedule a cancel-all operation at a future time.
966
997
  * @param args - The parameters for the request.
967
998
  * @param signal - An optional abort signal.
968
999
  * @returns Successful response without specific data.
@@ -1107,7 +1138,6 @@ export class WalletClient {
1107
1138
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1108
1139
  * const client = new hl.WalletClient({ wallet, transport });
1109
1140
  *
1110
- * // Unknown what the successful response will be
1111
1141
  * const result = await client.spotDeploy({
1112
1142
  * registerToken2: {
1113
1143
  * spec: {
@@ -1193,13 +1223,13 @@ export class WalletClient {
1193
1223
  return response;
1194
1224
  }
1195
1225
  /**
1196
- * Transfer a spot asset on L1 to another address.
1226
+ * Send spot assets to another address.
1197
1227
  * @param args - The parameters for the request.
1198
1228
  * @param signal - An optional abort signal.
1199
1229
  * @returns Successful response without specific data.
1200
1230
  * @throws {ApiRequestError} When the API returns an error response.
1201
1231
  *
1202
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#l1-spot-transfer
1232
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#core-spot-transfer
1203
1233
  * @example
1204
1234
  * ```ts
1205
1235
  * import * as hl from "@nktkas/hyperliquid";
@@ -1266,9 +1296,7 @@ export class WalletClient {
1266
1296
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1267
1297
  * const client = new hl.WalletClient({ wallet, transport });
1268
1298
  *
1269
- * const result = await client.spotUser({
1270
- * toggleSpotDusting: { optOut: false },
1271
- * });
1299
+ * const result = await client.spotUser({ toggleSpotDusting: { optOut: false } });
1272
1300
  * ```
1273
1301
  */
1274
1302
  async spotUser(args, signal) {
@@ -1391,7 +1419,7 @@ export class WalletClient {
1391
1419
  return response;
1392
1420
  }
1393
1421
  /**
1394
- * Delegate or undelegate stake from a validator.
1422
+ * Delegate or undelegate native tokens to or from a validator.
1395
1423
  * @param args - The parameters for the request.
1396
1424
  * @param signal - An optional abort signal.
1397
1425
  * @returns Successful response without specific data.
@@ -1554,7 +1582,7 @@ export class WalletClient {
1554
1582
  return response;
1555
1583
  }
1556
1584
  /**
1557
- * Update isolated margin for a position.
1585
+ * Add or remove margin from isolated position.
1558
1586
  * @param args - The parameters for the request.
1559
1587
  * @param signal - An optional abort signal.
1560
1588
  * @returns Successful response without specific data.
@@ -1570,11 +1598,7 @@ export class WalletClient {
1570
1598
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1571
1599
  * const client = new hl.WalletClient({ wallet, transport });
1572
1600
  *
1573
- * const result = await client.updateIsolatedMargin({
1574
- * asset: 0,
1575
- * isBuy: true, // Add to long position
1576
- * ntli: 1, // Add 1 USD margin (integer only)
1577
- * });
1601
+ * const result = await client.updateIsolatedMargin({ asset: 0, isBuy: true, ntli: 1 * 1e6 });
1578
1602
  * ```
1579
1603
  */
1580
1604
  async updateIsolatedMargin(args, signal) {
@@ -1604,7 +1628,7 @@ export class WalletClient {
1604
1628
  return response;
1605
1629
  }
1606
1630
  /**
1607
- * Update leverage for cross or isolated margin.
1631
+ * Update cross or isolated leverage on a coin.
1608
1632
  * @param args - The parameters for the request.
1609
1633
  * @param signal - An optional abort signal.
1610
1634
  * @returns Successful response without specific data.
@@ -1620,11 +1644,7 @@ export class WalletClient {
1620
1644
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1621
1645
  * const client = new hl.WalletClient({ wallet, transport });
1622
1646
  *
1623
- * const result = await client.updateLeverage({
1624
- * asset: 0,
1625
- * isCross: true,
1626
- * leverage: 5,
1627
- * });
1647
+ * const result = await client.updateLeverage({ asset: 0, isCross: true, leverage: 5 });
1628
1648
  * ```
1629
1649
  */
1630
1650
  async updateLeverage(args, signal) {
@@ -1670,10 +1690,7 @@ export class WalletClient {
1670
1690
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1671
1691
  * const client = new hl.WalletClient({ wallet, transport });
1672
1692
  *
1673
- * const result = await client.usdClassTransfer({
1674
- * amount: "1",
1675
- * toPerp: true, // Transfer from Spot to Perp
1676
- * });
1693
+ * const result = await client.usdClassTransfer({ amount: "1", toPerp: true });
1677
1694
  * ```
1678
1695
  */
1679
1696
  async usdClassTransfer(args, signal) {
@@ -1709,13 +1726,13 @@ export class WalletClient {
1709
1726
  return response;
1710
1727
  }
1711
1728
  /**
1712
- * Transfer USDC on L1 to another address.
1729
+ * Send usd to another address.
1713
1730
  * @param args - The parameters for the request.
1714
1731
  * @param signal - An optional abort signal.
1715
1732
  * @returns Successful response without specific data.
1716
1733
  * @throws {ApiRequestError} When the API returns an error response.
1717
1734
  *
1718
- * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#l1-usdc-transfer
1735
+ * @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#core-usdc-transfer
1719
1736
  * @example
1720
1737
  * ```ts
1721
1738
  * import * as hl from "@nktkas/hyperliquid";
@@ -1725,10 +1742,7 @@ export class WalletClient {
1725
1742
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1726
1743
  * const client = new hl.WalletClient({ wallet, transport });
1727
1744
  *
1728
- * const result = await client.usdSend({
1729
- * destination: "0x...",
1730
- * amount: "1",
1731
- * });
1745
+ * const result = await client.usdSend({ destination: "0x...", amount: "1" });
1732
1746
  * ```
1733
1747
  */
1734
1748
  async usdSend(args, signal) {
@@ -1780,10 +1794,7 @@ export class WalletClient {
1780
1794
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1781
1795
  * const client = new hl.WalletClient({ wallet, transport });
1782
1796
  *
1783
- * const result = await client.vaultDistribute({
1784
- * vaultAddress: "0x...",
1785
- * usd: 10 * 1e6,
1786
- * });
1797
+ * const result = await client.vaultDistribute({ vaultAddress: "0x...", usd: 10 * 1e6 });
1787
1798
  * ```
1788
1799
  */
1789
1800
  async vaultDistribute(args, signal) {
@@ -1856,7 +1867,7 @@ export class WalletClient {
1856
1867
  return response;
1857
1868
  }
1858
1869
  /**
1859
- * Add or remove funds from a vault.
1870
+ * Deposit or withdraw from a vault.
1860
1871
  * @param args - The parameters for the request.
1861
1872
  * @param signal - An optional abort signal.
1862
1873
  * @returns Successful response without specific data.
@@ -1919,10 +1930,7 @@ export class WalletClient {
1919
1930
  * const transport = new hl.HttpTransport(); // or WebSocketTransport
1920
1931
  * const client = new hl.WalletClient({ wallet, transport });
1921
1932
  *
1922
- * const result = await client.withdraw3({
1923
- * destination: "0x...",
1924
- * amount: "1",
1925
- * });
1933
+ * const result = await client.withdraw3({ destination: "0x...", amount: "1" });
1926
1934
  * ```
1927
1935
  */
1928
1936
  async withdraw3(args, signal) {
@@ -1957,7 +1965,6 @@ export class WalletClient {
1957
1965
  this._validateResponse(response);
1958
1966
  return response;
1959
1967
  }
1960
- // ——————————————— Private methods ———————————————
1961
1968
  /** Formats a decimal number as a string, removing trailing zeros. */
1962
1969
  _formatDecimal(numStr) {
1963
1970
  if (!numStr.includes("."))
@@ -1,6 +1,50 @@
1
1
  /**
2
2
  * This module contains functions for generating Hyperliquid transaction signatures
3
3
  * and interfaces to various wallet implementations.
4
+ * @example
5
+ * ```ts
6
+ * import { signL1Action } from "@nktkas/hyperliquid/signing";
7
+ *
8
+ * const action = {
9
+ * type: "cancel",
10
+ * cancels: [{ a: 0, o: 12345 }],
11
+ * };
12
+ * const nonce = Date.now();
13
+ *
14
+ * const signature = await signL1Action({
15
+ * wallet,
16
+ * action,
17
+ * nonce,
18
+ * isTestnet: true, // Change to false for mainnet
19
+ * });
20
+ * ```
21
+ * @example
22
+ * ```ts
23
+ * import { signUserSignedAction } from "@nktkas/hyperliquid/signing";
24
+ *
25
+ * const action = {
26
+ * type: "approveAgent",
27
+ * hyperliquidChain: "Testnet", // "Mainnet" or "Testnet"
28
+ * signatureChainId: "0x66eee",
29
+ * nonce: Date.now(),
30
+ * agentAddress: "0x...",
31
+ * agentName: "Agent",
32
+ * };
33
+ *
34
+ * const signature = await signUserSignedAction({
35
+ * wallet,
36
+ * action,
37
+ * types: {
38
+ * "HyperliquidTransaction:ApproveAgent": [
39
+ * { name: "hyperliquidChain", type: "string" },
40
+ * { name: "agentAddress", type: "address" },
41
+ * { name: "agentName", type: "string" },
42
+ * { name: "nonce", type: "uint64" },
43
+ * ],
44
+ * },
45
+ * chainId: parseInt(action.signatureChainId, 16),
46
+ * });
47
+ * ```
4
48
  * @module
5
49
  */
6
50
  import { type ValueMap, type ValueType } from "../deps/jsr.io/@std/msgpack/1.0.3/encode.js";
@@ -1 +1 @@
1
- {"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../src/src/signing.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAU,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,6CAA6C,CAAC;AAEpG,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAErC,YAAY,EAAE,GAAG,EAAE,CAAC;AACpB,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;AAEpC,mFAAmF;AACnF,MAAM,WAAW,wBAAwB;IACrC,aAAa,CAAC,MAAM,EAAE;QAClB,MAAM,EAAE;YACJ,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,MAAM,CAAC;YAChB,OAAO,EAAE,MAAM,CAAC;YAChB,iBAAiB,EAAE,GAAG,CAAC;SAC1B,CAAC;QACF,KAAK,EAAE;YACH,CAAC,GAAG,EAAE,MAAM,GAAG;gBACX,IAAI,EAAE,MAAM,CAAC;gBACb,IAAI,EAAE,MAAM,CAAC;aAChB,EAAE,CAAC;SACP,CAAC;QACF,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,C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,kCAAkC,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,wBAAwB,CAItG;AAED,yEAAyE;AACzE,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,sBAAsB,CAI1F"}
@@ -1,11 +1,55 @@
1
1
  /**
2
2
  * This module contains functions for generating Hyperliquid transaction signatures
3
3
  * and interfaces to various wallet implementations.
4
+ * @example
5
+ * ```ts
6
+ * import { signL1Action } from "@nktkas/hyperliquid/signing";
7
+ *
8
+ * const action = {
9
+ * type: "cancel",
10
+ * cancels: [{ a: 0, o: 12345 }],
11
+ * };
12
+ * const nonce = Date.now();
13
+ *
14
+ * const signature = await signL1Action({
15
+ * wallet,
16
+ * action,
17
+ * nonce,
18
+ * isTestnet: true, // Change to false for mainnet
19
+ * });
20
+ * ```
21
+ * @example
22
+ * ```ts
23
+ * import { signUserSignedAction } from "@nktkas/hyperliquid/signing";
24
+ *
25
+ * const action = {
26
+ * type: "approveAgent",
27
+ * hyperliquidChain: "Testnet", // "Mainnet" or "Testnet"
28
+ * signatureChainId: "0x66eee",
29
+ * nonce: Date.now(),
30
+ * agentAddress: "0x...",
31
+ * agentName: "Agent",
32
+ * };
33
+ *
34
+ * const signature = await signUserSignedAction({
35
+ * wallet,
36
+ * action,
37
+ * types: {
38
+ * "HyperliquidTransaction:ApproveAgent": [
39
+ * { name: "hyperliquidChain", type: "string" },
40
+ * { name: "agentAddress", type: "address" },
41
+ * { name: "agentName", type: "string" },
42
+ * { name: "nonce", type: "uint64" },
43
+ * ],
44
+ * },
45
+ * chainId: parseInt(action.signatureChainId, 16),
46
+ * });
47
+ * ```
4
48
  * @module
5
49
  */
6
50
  import { keccak_256 } from "../deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js";
7
51
  import { encode } from "../deps/jsr.io/@std/msgpack/1.0.3/encode.js";
8
- import { decodeHex, encodeHex } from "../deps/jsr.io/@std/encoding/1.0.7/hex.js";
52
+ import { decodeHex, encodeHex } from "../deps/jsr.io/@std/encoding/1.0.8/hex.js";
9
53
  /**
10
54
  * Create a hash of the L1 action.
11
55
  *