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