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