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