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