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