@nktkas/hyperliquid 0.24.0 → 0.24.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 (56) hide show
  1. package/README.md +44 -44
  2. package/esm/mod.d.ts +1 -0
  3. package/esm/mod.d.ts.map +1 -1
  4. package/esm/src/clients/exchange.d.ts +101 -45
  5. package/esm/src/clients/exchange.d.ts.map +1 -1
  6. package/esm/src/clients/exchange.js +108 -43
  7. package/esm/src/clients/info.d.ts +23 -2
  8. package/esm/src/clients/info.d.ts.map +1 -1
  9. package/esm/src/clients/info.js +23 -1
  10. package/esm/src/clients/subscription.d.ts +6 -6
  11. package/esm/src/clients/subscription.js +8 -8
  12. package/esm/src/signing/_sorter.d.ts +9 -1
  13. package/esm/src/signing/_sorter.d.ts.map +1 -1
  14. package/esm/src/signing/_sorter.js +31 -0
  15. package/esm/src/signing/mod.d.ts +6 -6
  16. package/esm/src/signing/mod.js +6 -6
  17. package/esm/src/transports/http/http_transport.js +1 -1
  18. package/esm/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
  19. package/esm/src/transports/websocket/_websocket_async_request.js +4 -0
  20. package/esm/src/transports/websocket/websocket_transport.js +3 -3
  21. package/esm/src/types/exchange/requests.d.ts +56 -1
  22. package/esm/src/types/exchange/requests.d.ts.map +1 -1
  23. package/esm/src/types/info/accounts.d.ts +2 -0
  24. package/esm/src/types/info/accounts.d.ts.map +1 -1
  25. package/esm/src/types/info/orders.d.ts +2 -0
  26. package/esm/src/types/info/orders.d.ts.map +1 -1
  27. package/esm/src/types/info/requests.d.ts +9 -0
  28. package/esm/src/types/info/requests.d.ts.map +1 -1
  29. package/package.json +1 -1
  30. package/script/mod.d.ts +1 -0
  31. package/script/mod.d.ts.map +1 -1
  32. package/script/src/clients/exchange.d.ts +101 -45
  33. package/script/src/clients/exchange.d.ts.map +1 -1
  34. package/script/src/clients/exchange.js +108 -43
  35. package/script/src/clients/info.d.ts +23 -2
  36. package/script/src/clients/info.d.ts.map +1 -1
  37. package/script/src/clients/info.js +23 -1
  38. package/script/src/clients/subscription.d.ts +6 -6
  39. package/script/src/clients/subscription.js +8 -8
  40. package/script/src/signing/_sorter.d.ts +9 -1
  41. package/script/src/signing/_sorter.d.ts.map +1 -1
  42. package/script/src/signing/_sorter.js +31 -0
  43. package/script/src/signing/mod.d.ts +6 -6
  44. package/script/src/signing/mod.js +6 -6
  45. package/script/src/transports/http/http_transport.js +1 -1
  46. package/script/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
  47. package/script/src/transports/websocket/_websocket_async_request.js +4 -0
  48. package/script/src/transports/websocket/websocket_transport.js +3 -3
  49. package/script/src/types/exchange/requests.d.ts +56 -1
  50. package/script/src/types/exchange/requests.d.ts.map +1 -1
  51. package/script/src/types/info/accounts.d.ts +2 -0
  52. package/script/src/types/info/accounts.d.ts.map +1 -1
  53. package/script/src/types/info/orders.d.ts +2 -0
  54. package/script/src/types/info/orders.d.ts.map +1 -1
  55. package/script/src/types/info/requests.d.ts +9 -0
  56. package/script/src/types/info/requests.d.ts.map +1 -1
package/README.md CHANGED
@@ -53,16 +53,11 @@ deno add jsr:@nktkas/hyperliquid
53
53
  <summary>For React Native, you need to import polyfills before importing the SDK:</summary>
54
54
 
55
55
  ```js
56
- // React Native 0.76.3 / Expo v52
56
+ // React Native v0.79 / Expo v53
57
57
  // Issues:
58
58
  // - signing: does not support private keys directly, use `viem` or `ethers`
59
59
 
60
- import { Event, EventTarget } from "event-target-shim";
61
-
62
- if (!globalThis.EventTarget || !globalThis.Event) {
63
- globalThis.EventTarget = EventTarget;
64
- globalThis.Event = Event;
65
- }
60
+ import "event-target-polyfill";
66
61
 
67
62
  if (!globalThis.CustomEvent) {
68
63
  globalThis.CustomEvent = function (type, params) {
@@ -103,7 +98,7 @@ if (!Promise.withResolvers) {
103
98
  // 1. Import module
104
99
  import * as hl from "@nktkas/hyperliquid";
105
100
 
106
- // 1. Set up client with transport
101
+ // 2. Set up client with transport
107
102
  const infoClient = new hl.InfoClient({
108
103
  transport: new hl.HttpTransport(), // or `WebSocketTransport`
109
104
  });
@@ -166,7 +161,7 @@ await sub.unsubscribe();
166
161
  // 1. Import module
167
162
  import * as hl from "@nktkas/hyperliquid";
168
163
 
169
- // 2. Set up client with
164
+ // 2. Set up client with transport, multi-sign address, and signers
170
165
  const multiSignClient = new hl.MultiSignClient({
171
166
  transport: new hl.HttpTransport(), // or `WebSocketTransport`
172
167
  multiSignAddress: "0x...",
@@ -175,8 +170,8 @@ const multiSignClient = new hl.MultiSignClient({
175
170
  ],
176
171
  });
177
172
 
178
- // 3. Execute an action
179
- const data = await multiSignClient.approveAgent({ agentAddress: "0x..." });
173
+ // 3. Execute an action (same as `ExchangeClient`)
174
+ await multiSignClient.approveAgent({ agentAddress: "0x..." });
180
175
  ```
181
176
 
182
177
  ## Usage
@@ -221,20 +216,20 @@ const transport = new hl.HttpTransport(); // or `WebSocketTransport`
221
216
 
222
217
  // 1. Using private key directly
223
218
  const privateKey = "0x...";
224
- const exchClient_privateKey = new hl.ExchangeClient({ wallet: privateKey, transport });
219
+ const exchClient = new hl.ExchangeClient({ wallet: privateKey, transport });
225
220
 
226
221
  // 2. Using Viem
227
222
  const viemAccount = privateKeyToAccount("0x...");
228
- const exchClient_viem = new hl.ExchangeClient({ wallet: viemAccount, transport });
223
+ const exchClient = new hl.ExchangeClient({ wallet: viemAccount, transport });
229
224
 
230
225
  // 3. Using Ethers (V5 or V6)
231
226
  const ethersWallet = new ethers.Wallet("0x...");
232
- const exchClient_ethers = new hl.ExchangeClient({ wallet: ethersWallet, transport });
227
+ const exchClient = new hl.ExchangeClient({ wallet: ethersWallet, transport });
233
228
 
234
229
  // 4. Using external wallet (e.g. MetaMask) via Viem
235
- const [account] = await window.ethereum.request({ method: "eth_requestAccounts" });
230
+ const [account] = await window.ethereum.request({ method: "eth_requestAccounts" }) as `0x${string}`[];
236
231
  const externalWallet = createWalletClient({ account, transport: custom(window.ethereum) });
237
- const exchClient_viemMetamask = new hl.ExchangeClient({ wallet: externalWallet, transport });
232
+ const exchClient = new hl.ExchangeClient({ wallet: externalWallet, transport });
238
233
  ```
239
234
 
240
235
  #### Create [SubscriptionClient](#subscriptionclient)
@@ -266,7 +261,7 @@ const multiSignClient = new hl.MultiSignClient({
266
261
  name: string;
267
262
  version: string;
268
263
  chainId: number;
269
- verifyingContract: `0x${string}`;
264
+ verifyingContract: Hex;
270
265
  };
271
266
  types: {
272
267
  [key: string]: {
@@ -276,12 +271,13 @@ const multiSignClient = new hl.MultiSignClient({
276
271
  };
277
272
  primaryType: string;
278
273
  message: Record<string, unknown>;
279
- }): Promise<`0x${string}`> {
274
+ }): Promise<Hex> {
280
275
  // Custom signer logic
281
276
  return "0x..."; // return hex signature
282
277
  },
283
278
  },
284
279
  "0x...", // private key directly
280
+ // ... more signers
285
281
  ],
286
282
  });
287
283
  ```
@@ -300,12 +296,12 @@ const infoClient = new hl.InfoClient({
300
296
  });
301
297
 
302
298
  // L2 Book
303
- const l2Book = await infoClient.l2Book({ coin: "BTC" });
299
+ const l2Book = await infoClient.l2Book({ coin: "ETH" });
304
300
 
305
- // Account clearinghouse state
301
+ // User clearinghouse state
306
302
  const clearinghouseState = await infoClient.clearinghouseState({ user: "0x..." });
307
303
 
308
- // Open orders
304
+ // User open orders
309
305
  const openOrders = await infoClient.openOrders({ user: "0x..." });
310
306
  ```
311
307
 
@@ -353,7 +349,7 @@ const subsClient = new hl.SubscriptionClient({
353
349
  });
354
350
 
355
351
  // L2 Book updates
356
- await subsClient.l2Book({ coin: "BTC" }, (data) => {
352
+ await subsClient.l2Book({ coin: "ETH" }, (data) => {
357
353
  console.log(data);
358
354
  });
359
355
 
@@ -363,7 +359,7 @@ await subsClient.userFills({ user: "0x..." }, (data) => {
363
359
  });
364
360
 
365
361
  // Candle updates
366
- await subsClient.candle({ coin: "BTC", interval: "1h" }, (data) => {
362
+ await subsClient.candle({ coin: "ETH", interval: "1h" }, (data) => {
367
363
  console.log(data);
368
364
  });
369
365
  ```
@@ -378,6 +374,7 @@ const multiSignClient = new hl.MultiSignClient({
378
374
  multiSignAddress: "0x...",
379
375
  signers: [
380
376
  "0x...", // `viem`, `ethers`, or private key directly
377
+ // ... more signers
381
378
  ],
382
379
  });
383
380
 
@@ -415,9 +412,11 @@ class InfoClient {
415
412
  spotDeployState(args: SpotDeployStateParameters): Promise<SpotDeployState>;
416
413
  spotMeta(): Promise<SpotMeta>;
417
414
  spotMetaAndAssetCtxs(): Promise<SpotMetaAndAssetCtxs>;
415
+ spotPairDeployAuctionStatus(): Promise<DeployAuctionStatus>;
418
416
  tokenDetails(args: TokenDetailsParameters): Promise<TokenDetails>;
419
417
 
420
418
  // Account
419
+ activeAssetData(args: ActiveAssetDataParameters): Promise<ActiveAssetData>;
421
420
  clearinghouseState(args: ClearinghouseStateParameters): Promise<PerpsClearinghouseState>;
422
421
  extraAgents(args: ExtraAgentsParameters): Promise<ExtraAgent[]>;
423
422
  isVip(args: IsVipParameters): Promise<boolean>;
@@ -478,8 +477,8 @@ class ExchangeClient {
478
477
  transport: HttpTransport | WebSocketTransport;
479
478
  wallet: AbstractWallet; // `viem`, `ethers` (v5 or v6), or private key directly
480
479
  isTestnet?: boolean; // Whether to use testnet (default: false)
481
- defaultVaultAddress?: `0x${string}`; // Vault address used by default if not provided in method call
482
- signatureChainId?: `0x${string}` | (() => MaybePromise<`0x${string}`>); // Chain ID used for signing (default: get chain id from wallet otherwise `0x1`)
480
+ defaultVaultAddress?: Hex; // Vault address used by default if not provided in method call
481
+ signatureChainId?: Hex | (() => MaybePromise<Hex>); // Chain ID used for signing (default: get chain id from wallet otherwise `0x1`)
483
482
  nonceManager?: () => MaybePromise<number>; // Function to get the next nonce (default: monotonically incrementing `Date.now()`)
484
483
  });
485
484
 
@@ -501,6 +500,7 @@ class ExchangeClient {
501
500
  claimRewards(): Promise<SuccessResponse>;
502
501
  createSubAccount(args: CreateSubAccountParameters): Promise<CreateSubAccountResponse>;
503
502
  evmUserModify(args: EvmUserModifyParameters): Promise<SuccessResponse>;
503
+ noop(): Promise<SuccessResponse>;
504
504
  registerReferrer(args: RegisterReferrerParameters): Promise<SuccessResponse>;
505
505
  reserveRequestWeight(args: ReserveRequestWeightParameters): Promise<SuccessResponse>;
506
506
  setDisplayName(args: SetDisplayNameParameters): Promise<SuccessResponse>;
@@ -509,6 +509,7 @@ class ExchangeClient {
509
509
  spotUser(args: SpotUserParameters): Promise<SuccessResponse>;
510
510
 
511
511
  // Transfer
512
+ sendAsset(args: SendAssetParameters): Promise<SuccessResponse>;
512
513
  spotSend(args: SpotSendParameters): Promise<SuccessResponse>;
513
514
  subAccountSpotTransfer(args: SubAccountSpotTransferParameters): Promise<SuccessResponse>;
514
515
  subAccountTransfer(args: SubAccountTransferParameters): Promise<SuccessResponse>;
@@ -552,7 +553,6 @@ class SubscriptionClient {
552
553
 
553
554
  // Market
554
555
  activeAssetCtx(args: EventActiveAssetCtxParameters, listener: (data: WsActiveAssetCtx | WsActiveSpotAssetCtx) => void): Promise<Subscription>;
555
- activeAssetData(args: EventActiveAssetDataParameters, listener: (data: ActiveAssetData) => void): Promise<Subscription>;
556
556
  allMids(listener: (data: WsAllMids) => void): Promise<Subscription>;
557
557
  bbo(args: EventBboParameters, listener: (data: WsBbo) => void): Promise<Subscription>;
558
558
  candle(args: EventCandleParameters, listener: (data: Candle) => void): Promise<Subscription>;
@@ -560,6 +560,7 @@ class SubscriptionClient {
560
560
  trades(args: EventTradesParameters, listener: (data: WsTrade[]) => void): Promise<Subscription>;
561
561
 
562
562
  // Account
563
+ activeAssetData(args: EventActiveAssetDataParameters, listener: (data: ActiveAssetData) => void): Promise<Subscription>;
563
564
  notification(args: EventNotificationParameters, listener: (data: WsNotification) => void): Promise<Subscription>;
564
565
  userEvents(args: EventUserEventsParameters, listener: (data: WsUserEvent) => void): Promise<Subscription>;
565
566
  userFundings(args: EventUserFundingsParameters, listener: (data: WsUserFundings) => void): Promise<Subscription>;
@@ -587,8 +588,11 @@ class MultiSignClient extends ExchangeClient {
587
588
  args:
588
589
  & Omit<ExchangeClientParameters, "wallet"> // instead of `wallet`, you should specify the following parameters:
589
590
  & {
590
- multiSignAddress: `0x${string}`;
591
- signers: [AbstractWallet, ...AbstractWallet[]];
591
+ multiSignAddress: Hex;
592
+ signers: [
593
+ AbstractWallet, // first is leader for multi-sign transaction (signs transaction 2 times)
594
+ ...AbstractWallet[], // may be additional signers
595
+ ];
592
596
  },
593
597
  );
594
598
 
@@ -668,22 +672,17 @@ class WebSocketTransport {
668
672
 
669
673
  ### `/types`
670
674
 
671
- The import point gives access to all Hyperliquid-related types, including the base types on which class methods are
672
- based.
675
+ The import point gives access to all request/response types associated with Hyperliquid API.
673
676
 
674
677
  ### `/signing`
675
678
 
676
- The import point gives access to functions that generate signatures for Hyperliquid transactions.
677
-
678
- ### Examples
679
+ The import point gives access to functions that generate signatures for Hyperliquid API actions.
679
680
 
680
- #### Cancel order yourself
681
+ #### L1 Action
681
682
 
682
683
  ```ts
683
684
  import { actionSorter, signL1Action } from "@nktkas/hyperliquid/signing";
684
685
 
685
- const privateKey = "0x..."; // `viem`, `ethers`, or private key directly
686
-
687
686
  const action = actionSorter.cancel({
688
687
  type: "cancel",
689
688
  cancels: [
@@ -692,7 +691,11 @@ const action = actionSorter.cancel({
692
691
  });
693
692
  const nonce = Date.now();
694
693
 
695
- const signature = await signL1Action({ wallet: privateKey, action, nonce });
694
+ const signature = await signL1Action({
695
+ wallet: "0x...", // `viem`, `ethers`, or private key directly
696
+ action,
697
+ nonce,
698
+ });
696
699
 
697
700
  // Send the signed action to the Hyperliquid API
698
701
  const response = await fetch("https://api.hyperliquid.xyz/exchange", {
@@ -703,13 +706,11 @@ const response = await fetch("https://api.hyperliquid.xyz/exchange", {
703
706
  const body = await response.json();
704
707
  ```
705
708
 
706
- #### Approve agent yourself
709
+ #### User Signed Action
707
710
 
708
711
  ```ts
709
712
  import { actionSorter, signUserSignedAction, userSignedActionEip712Types } from "@nktkas/hyperliquid/signing";
710
713
 
711
- const privateKey = "0x..."; // `viem`, `ethers`, or private key directly
712
-
713
714
  const action = actionSorter.approveAgent({
714
715
  type: "approveAgent",
715
716
  signatureChainId: "0x66eee",
@@ -720,7 +721,7 @@ const action = actionSorter.approveAgent({
720
721
  });
721
722
 
722
723
  const signature = await signUserSignedAction({
723
- wallet: privateKey,
724
+ wallet: "0x...", // `viem`, `ethers`, or private key directly
724
725
  action,
725
726
  types: userSignedActionEip712Types[action.type],
726
727
  });
@@ -738,13 +739,12 @@ const body = await response.json();
738
739
 
739
740
  ### How to execute an L1 action via an external wallet (e.g. MetaMask)?
740
741
 
741
- Hyperliquid requires chain `1337` for L1 actions (open order, change leverage, etc.). There are two ways to execute an
742
- L1 action through an external wallet:
742
+ Hyperliquid requires chain `1337` for L1 action signatures. To handle this with external wallets:
743
743
 
744
744
  - (recommended) Create an
745
745
  [Agent Wallet](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/nonces-and-api-wallets#api-wallets)
746
746
  and execute all L1 actions through it
747
- - Change the user's chain to `1337`, however, the user will sign unreadable data
747
+ - Change a user's chain to `1337`, however, the user will sign unreadable data
748
748
 
749
749
  ### How to create a market order?
750
750
 
package/esm/mod.d.ts CHANGED
@@ -7,6 +7,7 @@ export * from "./src/clients/multiSign.js";
7
7
  export * from "./src/clients/subscription.js";
8
8
  export * from "./src/transports/http/http_transport.js";
9
9
  export * from "./src/transports/websocket/websocket_transport.js";
10
+ export type { OrderParams, Signature } from "./src/types/exchange/requests.js";
10
11
  export type * from "./src/types/exchange/responses.js";
11
12
  export type * from "./src/types/explorer/responses.js";
12
13
  export type * from "./src/types/info/accounts.js";
package/esm/mod.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AACA,cAAc,eAAe,CAAC;AAC9B,cAAc,0BAA0B,CAAC;AAGzC,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAG9C,cAAc,yCAAyC,CAAC;AACxD,cAAc,mDAAmD,CAAC;AAGlE,mBAAmB,mCAAmC,CAAC;AACvD,mBAAmB,mCAAmC,CAAC;AACvD,mBAAmB,8BAA8B,CAAC;AAClD,mBAAmB,4BAA4B,CAAC;AAChD,mBAAmB,gCAAgC,CAAC;AACpD,mBAAmB,6BAA6B,CAAC;AACjD,mBAAmB,4BAA4B,CAAC;AAChD,mBAAmB,4BAA4B,CAAC;AAChD,mBAAmB,wCAAwC,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AACA,cAAc,eAAe,CAAC;AAC9B,cAAc,0BAA0B,CAAC;AAGzC,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAG9C,cAAc,yCAAyC,CAAC;AACxD,cAAc,mDAAmD,CAAC;AAGlE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC/E,mBAAmB,mCAAmC,CAAC;AACvD,mBAAmB,mCAAmC,CAAC;AACvD,mBAAmB,8BAA8B,CAAC;AAClD,mBAAmB,4BAA4B,CAAC;AAChD,mBAAmB,gCAAgC,CAAC;AACpD,mBAAmB,6BAA6B,CAAC;AACjD,mBAAmB,4BAA4B,CAAC;AAChD,mBAAmB,4BAA4B,CAAC;AAChD,mBAAmB,wCAAwC,CAAC"}