@nktkas/hyperliquid 0.22.2 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -49
- package/esm/src/base.d.ts +4 -1
- package/esm/src/base.d.ts.map +1 -1
- package/esm/src/base.js +2 -2
- package/esm/src/clients/exchange.d.ts +289 -207
- package/esm/src/clients/exchange.d.ts.map +1 -1
- package/esm/src/clients/exchange.js +605 -410
- package/esm/src/clients/info.d.ts +137 -41
- package/esm/src/clients/info.d.ts.map +1 -1
- package/esm/src/clients/info.js +124 -28
- package/esm/src/clients/multiSign.d.ts +285 -204
- package/esm/src/clients/multiSign.d.ts.map +1 -1
- package/esm/src/clients/multiSign.js +521 -493
- package/esm/src/clients/subscription.d.ts +38 -3
- package/esm/src/clients/subscription.d.ts.map +1 -1
- package/esm/src/clients/subscription.js +36 -3
- package/esm/src/signing/{_ethers.d.ts → _signTypedData/ethers.d.ts} +1 -1
- package/esm/src/signing/_signTypedData/ethers.d.ts.map +1 -0
- package/esm/src/signing/_signTypedData/mod.d.ts +35 -0
- package/esm/src/signing/_signTypedData/mod.d.ts.map +1 -0
- package/esm/src/signing/_signTypedData/mod.js +59 -0
- package/esm/src/signing/_signTypedData/private_key.d.ts +26 -0
- package/esm/src/signing/_signTypedData/private_key.d.ts.map +1 -0
- package/esm/src/signing/_signTypedData/private_key.js +144 -0
- package/esm/src/signing/{_viem.d.ts → _signTypedData/viem.d.ts} +2 -2
- package/esm/src/signing/_signTypedData/viem.d.ts.map +1 -0
- package/{script/src/signing/_window.d.ts → esm/src/signing/_signTypedData/window.d.ts} +18 -12
- package/esm/src/signing/_signTypedData/window.d.ts.map +1 -0
- package/esm/src/signing/{_window.js → _signTypedData/window.js} +3 -2
- package/esm/src/signing/_sorter.d.ts +56 -82
- package/esm/src/signing/_sorter.d.ts.map +1 -1
- package/esm/src/signing/_sorter.js +36 -49
- package/esm/src/signing/mod.d.ts +151 -130
- package/esm/src/signing/mod.d.ts.map +1 -1
- package/esm/src/signing/mod.js +182 -228
- package/esm/src/transports/base.d.ts +1 -1
- package/esm/src/transports/base.d.ts.map +1 -1
- package/esm/src/transports/base.js +2 -2
- package/esm/src/transports/http/http_transport.d.ts +9 -15
- package/esm/src/transports/http/http_transport.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.js +64 -59
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +1 -1
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/esm/src/transports/websocket/_hyperliquid_event_target.js +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.js +17 -4
- package/esm/src/transports/websocket/_websocket_async_request.d.ts +0 -9
- package/esm/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
- package/esm/src/transports/websocket/_websocket_async_request.js +14 -20
- package/esm/src/transports/websocket/websocket_transport.d.ts +8 -4
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.js +83 -54
- package/esm/src/types/exchange/requests.d.ts +27 -51
- package/esm/src/types/exchange/requests.d.ts.map +1 -1
- package/esm/src/types/explorer/requests.d.ts +5 -8
- package/esm/src/types/explorer/requests.d.ts.map +1 -1
- package/esm/src/types/info/accounts.d.ts +5 -5
- package/esm/src/types/info/accounts.d.ts.map +1 -1
- package/esm/src/types/info/delegations.d.ts +1 -1
- package/esm/src/types/info/delegations.d.ts.map +1 -1
- package/esm/src/types/info/orders.d.ts +1 -1
- package/esm/src/types/info/orders.d.ts.map +1 -1
- package/esm/src/types/info/requests.d.ts +49 -96
- package/esm/src/types/info/requests.d.ts.map +1 -1
- package/esm/src/types/subscriptions/requests.d.ts +72 -18
- package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
- package/esm/src/types/subscriptions/responses.d.ts +2 -0
- package/esm/src/types/subscriptions/responses.d.ts.map +1 -1
- package/package.json +8 -5
- package/script/mod.js +13 -23
- package/script/src/base.d.ts +4 -1
- package/script/src/base.d.ts.map +1 -1
- package/script/src/base.js +10 -20
- package/script/src/clients/exchange.d.ts +289 -207
- package/script/src/clients/exchange.d.ts.map +1 -1
- package/script/src/clients/exchange.js +2000 -1815
- package/script/src/clients/info.d.ts +137 -41
- package/script/src/clients/info.d.ts.map +1 -1
- package/script/src/clients/info.js +1296 -1210
- package/script/src/clients/multiSign.d.ts +285 -204
- package/script/src/clients/multiSign.d.ts.map +1 -1
- package/script/src/clients/multiSign.js +2043 -2025
- package/script/src/clients/subscription.d.ts +38 -3
- package/script/src/clients/subscription.d.ts.map +1 -1
- package/script/src/clients/subscription.js +568 -545
- package/script/src/signing/{_ethers.d.ts → _signTypedData/ethers.d.ts} +1 -1
- package/script/src/signing/_signTypedData/ethers.d.ts.map +1 -0
- package/script/src/signing/_signTypedData/ethers.js +16 -0
- package/script/src/signing/_signTypedData/mod.d.ts +35 -0
- package/script/src/signing/_signTypedData/mod.d.ts.map +1 -0
- package/script/src/signing/_signTypedData/mod.js +67 -0
- package/script/src/signing/_signTypedData/private_key.d.ts +26 -0
- package/script/src/signing/_signTypedData/private_key.d.ts.map +1 -0
- package/script/src/signing/_signTypedData/private_key.js +148 -0
- package/script/src/signing/{_viem.d.ts → _signTypedData/viem.d.ts} +2 -2
- package/script/src/signing/_signTypedData/viem.d.ts.map +1 -0
- package/script/src/signing/_signTypedData/viem.js +9 -0
- package/{esm/src/signing/_window.d.ts → script/src/signing/_signTypedData/window.d.ts} +18 -12
- package/script/src/signing/_signTypedData/window.d.ts.map +1 -0
- package/script/src/signing/_signTypedData/window.js +34 -0
- package/script/src/signing/_sorter.d.ts +56 -82
- package/script/src/signing/_sorter.d.ts.map +1 -1
- package/script/src/signing/_sorter.js +655 -678
- package/script/src/signing/mod.d.ts +151 -130
- package/script/src/signing/mod.d.ts.map +1 -1
- package/script/src/signing/mod.js +286 -342
- package/script/src/transports/base.d.ts +1 -1
- package/script/src/transports/base.d.ts.map +1 -1
- package/script/src/transports/base.js +11 -21
- package/script/src/transports/http/http_transport.d.ts +9 -15
- package/script/src/transports/http/http_transport.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.js +97 -102
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +1 -1
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/script/src/transports/websocket/_hyperliquid_event_target.js +51 -61
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/script/src/transports/websocket/_reconnecting_websocket.js +271 -268
- package/script/src/transports/websocket/_websocket_async_request.d.ts +0 -9
- package/script/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
- package/script/src/transports/websocket/_websocket_async_request.js +157 -174
- package/script/src/transports/websocket/websocket_transport.d.ts +8 -4
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.js +209 -189
- package/script/src/types/exchange/requests.d.ts +27 -51
- package/script/src/types/exchange/requests.d.ts.map +1 -1
- package/script/src/types/exchange/requests.js +2 -12
- package/script/src/types/exchange/responses.js +2 -12
- package/script/src/types/explorer/requests.d.ts +5 -8
- package/script/src/types/explorer/requests.d.ts.map +1 -1
- package/script/src/types/explorer/requests.js +2 -12
- package/script/src/types/explorer/responses.js +2 -12
- package/script/src/types/info/accounts.d.ts +5 -5
- package/script/src/types/info/accounts.d.ts.map +1 -1
- package/script/src/types/info/accounts.js +2 -12
- package/script/src/types/info/assets.js +2 -12
- package/script/src/types/info/delegations.d.ts +1 -1
- package/script/src/types/info/delegations.d.ts.map +1 -1
- package/script/src/types/info/delegations.js +2 -12
- package/script/src/types/info/markets.js +2 -12
- package/script/src/types/info/orders.d.ts +1 -1
- package/script/src/types/info/orders.d.ts.map +1 -1
- package/script/src/types/info/orders.js +2 -12
- package/script/src/types/info/requests.d.ts +49 -96
- package/script/src/types/info/requests.d.ts.map +1 -1
- package/script/src/types/info/requests.js +2 -12
- package/script/src/types/info/vaults.js +2 -12
- package/script/src/types/mod.js +2 -12
- package/script/src/types/subscriptions/requests.d.ts +72 -18
- package/script/src/types/subscriptions/requests.d.ts.map +1 -1
- package/script/src/types/subscriptions/requests.js +2 -12
- package/script/src/types/subscriptions/responses.d.ts +2 -0
- package/script/src/types/subscriptions/responses.d.ts.map +1 -1
- package/script/src/types/subscriptions/responses.js +2 -12
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts +0 -2
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts.map +0 -1
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +0 -1
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts +0 -95
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts.map +0 -1
- package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +0 -10
- package/esm/deps/jsr.io/@std/async/1.0.13/delay.d.ts +0 -43
- package/esm/deps/jsr.io/@std/async/1.0.13/delay.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/async/1.0.13/delay.js +0 -63
- package/esm/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts +0 -9
- package/esm/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/bytes/1.0.6/_types.js +0 -2
- package/esm/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts +0 -21
- package/esm/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/bytes/1.0.6/concat.js +0 -32
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -51
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -13
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -2
- package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
- package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -87
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +0 -9
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.js +0 -2
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts +0 -39
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.js +0 -237
- package/esm/src/signing/_ethers.d.ts.map +0 -1
- package/esm/src/signing/_private_key.d.ts +0 -22
- package/esm/src/signing/_private_key.d.ts.map +0 -1
- package/esm/src/signing/_private_key.js +0 -124
- package/esm/src/signing/_viem.d.ts.map +0 -1
- package/esm/src/signing/_window.d.ts.map +0 -1
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts +0 -2
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts.map +0 -1
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +0 -27
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts +0 -95
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts.map +0 -1
- package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +0 -24
- package/script/deps/jsr.io/@std/async/1.0.13/delay.d.ts +0 -43
- package/script/deps/jsr.io/@std/async/1.0.13/delay.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/async/1.0.13/delay.js +0 -76
- package/script/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts +0 -9
- package/script/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/bytes/1.0.6/_types.js +0 -13
- package/script/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts +0 -21
- package/script/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/bytes/1.0.6/concat.js +0 -45
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -67
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -26
- package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
- package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -13
- package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
- package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -101
- package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +0 -9
- package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.js +0 -13
- package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts +0 -39
- package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.js +0 -250
- package/script/src/signing/_ethers.d.ts.map +0 -1
- package/script/src/signing/_ethers.js +0 -26
- package/script/src/signing/_private_key.d.ts +0 -22
- package/script/src/signing/_private_key.d.ts.map +0 -1
- package/script/src/signing/_private_key.js +0 -138
- package/script/src/signing/_viem.d.ts.map +0 -1
- package/script/src/signing/_viem.js +0 -19
- package/script/src/signing/_window.d.ts.map +0 -1
- package/script/src/signing/_window.js +0 -43
- /package/esm/src/signing/{_ethers.js → _signTypedData/ethers.js} +0 -0
- /package/esm/src/signing/{_viem.js → _signTypedData/viem.js} +0 -0
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# Hyperliquid API TypeScript SDK
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@nktkas/hyperliquid)
|
|
4
|
+
[](https://jsr.io/@nktkas/hyperliquid)
|
|
5
|
+
[](https://coveralls.io/github/nktkas/hyperliquid)
|
|
6
|
+
[](https://bundlephobia.com/package/@nktkas/hyperliquid)
|
|
7
7
|
|
|
8
8
|
Unofficial [Hyperliquid API](https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api) SDK for all major JS
|
|
9
9
|
runtimes, written in TypeScript and provided with tests.
|
|
@@ -44,17 +44,18 @@ deno add jsr:@nktkas/hyperliquid
|
|
|
44
44
|
```html
|
|
45
45
|
<script type="module">
|
|
46
46
|
import * as hl from "https://esm.sh/jsr/@nktkas/hyperliquid";
|
|
47
|
-
// Use hl.InfoClient, hl.ExchangeClient, etc.
|
|
48
47
|
</script>
|
|
49
48
|
```
|
|
50
49
|
|
|
51
50
|
### React Native
|
|
52
51
|
|
|
53
52
|
<details>
|
|
54
|
-
<summary>For React Native, you need to import
|
|
53
|
+
<summary>For React Native, you need to import polyfills before importing the SDK:</summary>
|
|
55
54
|
|
|
56
55
|
```js
|
|
57
|
-
// React Native
|
|
56
|
+
// React Native v0.76.3 / Expo v52
|
|
57
|
+
// Issues:
|
|
58
|
+
// - signing: does not support private keys directly, use viem or ethers
|
|
58
59
|
import { Event, EventTarget } from "event-target-shim";
|
|
59
60
|
|
|
60
61
|
if (!globalThis.EventTarget || !globalThis.Event) {
|
|
@@ -174,16 +175,15 @@ const signers = [
|
|
|
174
175
|
] as const;
|
|
175
176
|
|
|
176
177
|
const transport = new hl.HttpTransport();
|
|
177
|
-
const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers }); // extends ExchangeClient
|
|
178
|
+
const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers }); // extends `ExchangeClient`
|
|
178
179
|
|
|
179
|
-
const data = await multiSignClient.approveAgent({ // same API as ExchangeClient
|
|
180
|
+
const data = await multiSignClient.approveAgent({ // same API as `ExchangeClient`
|
|
180
181
|
agentAddress: "0x...",
|
|
181
182
|
agentName: "agentName",
|
|
182
183
|
});
|
|
183
184
|
```
|
|
184
185
|
|
|
185
|
-
|
|
186
|
-
<summary><h2>Usage</h2></summary>
|
|
186
|
+
## Usage
|
|
187
187
|
|
|
188
188
|
### 1) Initialize Transport
|
|
189
189
|
|
|
@@ -192,11 +192,11 @@ First, choose and configure your transport layer (more details in the [API Refer
|
|
|
192
192
|
```ts
|
|
193
193
|
import * as hl from "@nktkas/hyperliquid";
|
|
194
194
|
|
|
195
|
-
// HTTP Transport
|
|
196
|
-
const httpTransport = new hl.HttpTransport(); // Accepts optional parameters
|
|
195
|
+
// 1. HTTP Transport: suitable for one-time requests or serverless environments
|
|
196
|
+
const httpTransport = new hl.HttpTransport(); // Accepts optional parameters (e.g. isTestnet, timeout, etc.)
|
|
197
197
|
|
|
198
|
-
// WebSocket Transport
|
|
199
|
-
const wsTransport = new hl.WebSocketTransport(); // Accepts optional parameters
|
|
198
|
+
// 2. WebSocket Transport: has better network latency than HTTP transport
|
|
199
|
+
const wsTransport = new hl.WebSocketTransport(); // Accepts optional parameters (e.g. url, timeout, reconnect, etc.)
|
|
200
200
|
```
|
|
201
201
|
|
|
202
202
|
### 2) Initialize Client
|
|
@@ -208,7 +208,7 @@ Next, initialize a client with the transport layer (more details in the [API Ref
|
|
|
208
208
|
```ts
|
|
209
209
|
import * as hl from "@nktkas/hyperliquid";
|
|
210
210
|
|
|
211
|
-
const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
211
|
+
const transport = new hl.HttpTransport(); // or `WebSocketTransport`
|
|
212
212
|
const infoClient = new hl.InfoClient({ transport });
|
|
213
213
|
```
|
|
214
214
|
|
|
@@ -220,17 +220,17 @@ import { createWalletClient, custom } from "viem";
|
|
|
220
220
|
import { privateKeyToAccount } from "viem/accounts";
|
|
221
221
|
import { ethers } from "ethers";
|
|
222
222
|
|
|
223
|
-
const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
223
|
+
const transport = new hl.HttpTransport(); // or `WebSocketTransport`
|
|
224
224
|
|
|
225
|
-
// 1. Using private key
|
|
225
|
+
// 1. Using private key directly
|
|
226
226
|
const privateKey = "0x...";
|
|
227
227
|
const exchClient_privateKey = new hl.ExchangeClient({ wallet: privateKey, transport });
|
|
228
228
|
|
|
229
|
-
// 2. Using Viem
|
|
229
|
+
// 2. Using Viem
|
|
230
230
|
const viemAccount = privateKeyToAccount("0x...");
|
|
231
231
|
const exchClient_viem = new hl.ExchangeClient({ wallet: viemAccount, transport });
|
|
232
232
|
|
|
233
|
-
// 3. Using Ethers (or Ethers V5)
|
|
233
|
+
// 3. Using Ethers (or Ethers V5)
|
|
234
234
|
const ethersWallet = new ethers.Wallet("0x...");
|
|
235
235
|
const exchClient_ethers = new hl.ExchangeClient({ wallet: ethersWallet, transport });
|
|
236
236
|
|
|
@@ -239,7 +239,7 @@ const [account] = await window.ethereum.request({ method: "eth_requestAccounts"
|
|
|
239
239
|
const externalWallet = createWalletClient({ account, transport: custom(window.ethereum) });
|
|
240
240
|
const exchClient_viemMetamask = new hl.ExchangeClient({ wallet: externalWallet, transport });
|
|
241
241
|
|
|
242
|
-
// 5. Using external wallet (e.g. MetaMask) via `window.ethereum`
|
|
242
|
+
// 5. Using external wallet (e.g. MetaMask) via `window.ethereum`
|
|
243
243
|
const exchClient_windowMetamask = new hl.ExchangeClient({ wallet: window.ethereum, transport });
|
|
244
244
|
```
|
|
245
245
|
|
|
@@ -248,7 +248,7 @@ const exchClient_windowMetamask = new hl.ExchangeClient({ wallet: window.ethereu
|
|
|
248
248
|
```ts
|
|
249
249
|
import * as hl from "@nktkas/hyperliquid";
|
|
250
250
|
|
|
251
|
-
const transport = new hl.WebSocketTransport(); // only WebSocketTransport
|
|
251
|
+
const transport = new hl.WebSocketTransport(); // only `WebSocketTransport`
|
|
252
252
|
const subsClient = new hl.SubscriptionClient({ transport });
|
|
253
253
|
```
|
|
254
254
|
|
|
@@ -264,7 +264,7 @@ const signers = [
|
|
|
264
264
|
privateKeyToAccount("0x..."), // first is leader for multi-sign transaction, must contain own address
|
|
265
265
|
new ethers.Wallet("0x..."),
|
|
266
266
|
{ // can be a custom async wallet
|
|
267
|
-
signTypedData(params: {
|
|
267
|
+
async signTypedData(params: {
|
|
268
268
|
domain: {
|
|
269
269
|
name: string;
|
|
270
270
|
version: string;
|
|
@@ -281,14 +281,14 @@ const signers = [
|
|
|
281
281
|
message: Record<string, unknown>;
|
|
282
282
|
}): Promise<Hex> {
|
|
283
283
|
// Custom signer logic
|
|
284
|
-
return "0x..."; // return signature
|
|
284
|
+
return "0x..."; // return hex signature
|
|
285
285
|
},
|
|
286
286
|
},
|
|
287
287
|
"0x...", // private key directly
|
|
288
288
|
];
|
|
289
289
|
|
|
290
290
|
const transport = new hl.HttpTransport();
|
|
291
|
-
const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers }); // extends ExchangeClient
|
|
291
|
+
const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers }); // extends `ExchangeClient`
|
|
292
292
|
```
|
|
293
293
|
|
|
294
294
|
### 3) Use Client
|
|
@@ -390,7 +390,7 @@ const signers = [
|
|
|
390
390
|
const transport = new hl.HttpTransport();
|
|
391
391
|
const multiSignClient = new hl.MultiSignClient({ transport, multiSignAddress, signers });
|
|
392
392
|
|
|
393
|
-
// Interaction is the same as with ExchangeClient
|
|
393
|
+
// Interaction is the same as with `ExchangeClient`
|
|
394
394
|
|
|
395
395
|
// Place an orders
|
|
396
396
|
const result = await multiSignClient.order({
|
|
@@ -422,10 +422,7 @@ const result = await multiSignClient.withdraw3({
|
|
|
422
422
|
});
|
|
423
423
|
```
|
|
424
424
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
<details>
|
|
428
|
-
<summary><h2>API Reference</h2></summary>
|
|
425
|
+
## API Reference
|
|
429
426
|
|
|
430
427
|
### Clients
|
|
431
428
|
|
|
@@ -513,6 +510,7 @@ class ExchangeClient {
|
|
|
513
510
|
constructor(args: {
|
|
514
511
|
transport: HttpTransport | WebSocketTransport;
|
|
515
512
|
wallet:
|
|
513
|
+
| Hex // Private key directly
|
|
516
514
|
| AbstractViemWalletClient // viem
|
|
517
515
|
| AbstractEthersSigner // ethers
|
|
518
516
|
| AbstractEthersV5Signer // ethers v5
|
|
@@ -550,6 +548,7 @@ class ExchangeClient {
|
|
|
550
548
|
|
|
551
549
|
// Transfer
|
|
552
550
|
perpDexClassTransfer(args: PerpDexClassTransferParameters): Promise<SuccessResponse>;
|
|
551
|
+
perpDexTransfer(args: PerpDexTransferParameters): Promise<SuccessResponse>;
|
|
553
552
|
spotSend(args: SpotSendParameters): Promise<SuccessResponse>;
|
|
554
553
|
subAccountSpotTransfer(args: SubAccountSpotTransferParameters): Promise<SuccessResponse>;
|
|
555
554
|
subAccountTransfer(args: SubAccountTransferParameters): Promise<SuccessResponse>;
|
|
@@ -635,16 +634,18 @@ class MultiSignClient extends ExchangeClient {
|
|
|
635
634
|
},
|
|
636
635
|
);
|
|
637
636
|
|
|
638
|
-
// Same methods as ExchangeClient
|
|
637
|
+
// Same methods as `ExchangeClient`
|
|
639
638
|
}
|
|
640
639
|
```
|
|
641
640
|
|
|
642
641
|
### Transports
|
|
643
642
|
|
|
644
|
-
Transport acts as a layer between
|
|
643
|
+
Transport acts as a layer between class requests and Hyperliquid servers.
|
|
645
644
|
|
|
646
645
|
#### HTTP Transport
|
|
647
646
|
|
|
647
|
+
HTTP transport is suitable for one-off requests or serverless environments.
|
|
648
|
+
|
|
648
649
|
```ts
|
|
649
650
|
class HttpTransport {
|
|
650
651
|
constructor(options?: {
|
|
@@ -663,6 +664,8 @@ class HttpTransport {
|
|
|
663
664
|
|
|
664
665
|
#### WebSocket Transport
|
|
665
666
|
|
|
667
|
+
WebSocket transport has better network latency than HTTP transport.
|
|
668
|
+
|
|
666
669
|
```ts
|
|
667
670
|
class WebSocketTransport {
|
|
668
671
|
constructor(options?: {
|
|
@@ -686,10 +689,7 @@ class WebSocketTransport {
|
|
|
686
689
|
}
|
|
687
690
|
```
|
|
688
691
|
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
<details>
|
|
692
|
-
<summary><h2>Additional Import Points</h2></summary>
|
|
692
|
+
## Additional Import Points
|
|
693
693
|
|
|
694
694
|
### `/types`
|
|
695
695
|
|
|
@@ -709,22 +709,22 @@ import { actionSorter, signL1Action } from "@nktkas/hyperliquid/signing";
|
|
|
709
709
|
|
|
710
710
|
const privateKey = "0x..."; // or `viem`, `ethers`
|
|
711
711
|
|
|
712
|
+
const nonce = Date.now();
|
|
712
713
|
const action = {
|
|
713
714
|
type: "cancel",
|
|
714
715
|
cancels: [
|
|
715
716
|
{ a: 0, o: 12345 },
|
|
716
717
|
],
|
|
717
|
-
};
|
|
718
|
-
const nonce = Date.now();
|
|
718
|
+
} as const;
|
|
719
719
|
|
|
720
720
|
const signature = await signL1Action({
|
|
721
721
|
wallet: privateKey,
|
|
722
|
-
action: actionSorter[action.type](action),
|
|
722
|
+
action: actionSorter[action.type](action),
|
|
723
723
|
nonce,
|
|
724
|
-
isTestnet: true, // change to `false` for mainnet
|
|
725
724
|
});
|
|
726
725
|
|
|
727
|
-
|
|
726
|
+
// Send the signed action to the Hyperliquid API
|
|
727
|
+
const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
728
728
|
method: "POST",
|
|
729
729
|
headers: { "Content-Type": "application/json" },
|
|
730
730
|
body: JSON.stringify({ action, signature, nonce }),
|
|
@@ -741,21 +741,21 @@ const privateKey = "0x..."; // or `viem`, `ethers`
|
|
|
741
741
|
|
|
742
742
|
const action = {
|
|
743
743
|
type: "approveAgent",
|
|
744
|
-
signatureChainId: "0x66eee",
|
|
745
|
-
hyperliquidChain: "
|
|
744
|
+
signatureChainId: "0x66eee",
|
|
745
|
+
hyperliquidChain: "Mainnet",
|
|
746
746
|
agentAddress: "0x...",
|
|
747
747
|
agentName: "Agent",
|
|
748
748
|
nonce: Date.now(),
|
|
749
|
-
};
|
|
749
|
+
} as const;
|
|
750
750
|
|
|
751
751
|
const signature = await signUserSignedAction({
|
|
752
752
|
wallet: privateKey,
|
|
753
753
|
action,
|
|
754
|
-
types: userSignedActionEip712Types[action.type],
|
|
755
|
-
chainId: parseInt(action.signatureChainId, 16),
|
|
754
|
+
types: userSignedActionEip712Types[action.type],
|
|
756
755
|
});
|
|
757
756
|
|
|
758
|
-
|
|
757
|
+
// Send the signed action to the Hyperliquid API
|
|
758
|
+
const response = await fetch("https://api.hyperliquid.xyz/exchange", {
|
|
759
759
|
method: "POST",
|
|
760
760
|
headers: { "Content-Type": "application/json" },
|
|
761
761
|
body: JSON.stringify({ action, signature, nonce: action.nonce }),
|
|
@@ -763,8 +763,6 @@ const response = await fetch("https://api.hyperliquid-testnet.xyz/exchange", {
|
|
|
763
763
|
const body = await response.json();
|
|
764
764
|
```
|
|
765
765
|
|
|
766
|
-
</details>
|
|
767
|
-
|
|
768
766
|
## Contributing
|
|
769
767
|
|
|
770
768
|
We appreciate your help! To contribute, please read the [contributing instructions](CONTRIBUTING.md).
|
package/esm/src/base.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export type Hex = `0x${string}`;
|
|
2
2
|
export type MaybePromise<T> = T | Promise<T>;
|
|
3
|
+
export type DeepImmutable<T> = {
|
|
4
|
+
readonly [K in keyof T]: DeepImmutable<T[K]>;
|
|
5
|
+
};
|
|
3
6
|
/** Base error class for all SDK errors. */
|
|
4
7
|
export declare class HyperliquidError extends Error {
|
|
5
|
-
constructor(message?: string);
|
|
8
|
+
constructor(message?: string, options?: ErrorOptions);
|
|
6
9
|
}
|
|
7
10
|
//# sourceMappingURL=base.d.ts.map
|
package/esm/src/base.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/src/base.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAEhC,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/src/base.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAEhC,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAG7C,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;IAC3B,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC/C,CAAC;AAEF,2CAA2C;AAC3C,qBAAa,gBAAiB,SAAQ,KAAK;gBAC3B,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAIvD"}
|
package/esm/src/base.js
CHANGED