@nktkas/hyperliquid 0.22.2 → 0.23.0

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