@nktkas/hyperliquid 0.15.4 → 0.17.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 -89
- package/esm/src/base.d.ts +1 -0
- package/esm/src/base.d.ts.map +1 -1
- package/esm/src/clients/public.d.ts +6 -6
- package/esm/src/clients/public.d.ts.map +1 -1
- package/esm/src/clients/public.js +237 -54
- package/esm/src/clients/wallet.d.ts +121 -94
- package/esm/src/clients/wallet.d.ts.map +1 -1
- package/esm/src/clients/wallet.js +303 -206
- package/esm/src/signing.d.ts +117 -34
- package/esm/src/signing.d.ts.map +1 -1
- package/esm/src/signing.js +83 -19
- package/esm/src/transports/http/http_transport.d.ts +15 -27
- package/esm/src/transports/http/http_transport.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.js +20 -15
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts +1 -3
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.d.ts +6 -2
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/types/exchange/requests.d.ts +28 -14
- package/esm/src/types/exchange/requests.d.ts.map +1 -1
- package/esm/src/types/info/accounts.d.ts +4 -0
- package/esm/src/types/info/accounts.d.ts.map +1 -1
- package/esm/src/types/info/assets.d.ts +2 -0
- package/esm/src/types/info/assets.d.ts.map +1 -1
- package/esm/src/types/info/orders.d.ts +28 -20
- package/esm/src/types/info/orders.d.ts.map +1 -1
- package/esm/src/types/info/requests.d.ts +36 -18
- package/esm/src/types/info/requests.d.ts.map +1 -1
- package/esm/src/types/info/vaults.d.ts +2 -0
- package/esm/src/types/info/vaults.d.ts.map +1 -1
- package/esm/src/types/mod.d.ts +23 -0
- package/esm/src/types/mod.d.ts.map +1 -1
- package/esm/src/types/mod.js +23 -0
- package/package.json +4 -1
- package/script/src/base.d.ts +1 -0
- package/script/src/base.d.ts.map +1 -1
- package/script/src/clients/public.d.ts +6 -6
- package/script/src/clients/public.d.ts.map +1 -1
- package/script/src/clients/public.js +237 -54
- package/script/src/clients/wallet.d.ts +121 -94
- package/script/src/clients/wallet.d.ts.map +1 -1
- package/script/src/clients/wallet.js +302 -205
- package/script/src/signing.d.ts +117 -34
- package/script/src/signing.d.ts.map +1 -1
- package/script/src/signing.js +84 -15
- package/script/src/transports/http/http_transport.d.ts +15 -27
- package/script/src/transports/http/http_transport.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.js +20 -15
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts +1 -3
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.d.ts +6 -2
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/types/exchange/requests.d.ts +28 -14
- package/script/src/types/exchange/requests.d.ts.map +1 -1
- package/script/src/types/info/accounts.d.ts +4 -0
- package/script/src/types/info/accounts.d.ts.map +1 -1
- package/script/src/types/info/assets.d.ts +2 -0
- package/script/src/types/info/assets.d.ts.map +1 -1
- package/script/src/types/info/orders.d.ts +28 -20
- package/script/src/types/info/orders.d.ts.map +1 -1
- package/script/src/types/info/requests.d.ts +36 -18
- package/script/src/types/info/requests.d.ts.map +1 -1
- package/script/src/types/info/vaults.d.ts +2 -0
- package/script/src/types/info/vaults.d.ts.map +1 -1
- package/script/src/types/mod.d.ts +23 -0
- package/script/src/types/mod.d.ts.map +1 -1
- package/script/src/types/mod.js +23 -0
package/esm/src/signing.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module contains functions for generating Hyperliquid transaction signatures
|
|
3
|
+
* and interfaces to various wallet implementations.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
1
6
|
import { type ValueMap, type ValueType } from "../deps/jsr.io/@std/msgpack/1.0.3/encode.js";
|
|
2
7
|
import type { Hex } from "./base.js";
|
|
3
8
|
export type { Hex };
|
|
@@ -21,25 +26,6 @@ export interface AbstractViemWalletClient {
|
|
|
21
26
|
message: Record<string, unknown>;
|
|
22
27
|
}): Promise<Hex>;
|
|
23
28
|
}
|
|
24
|
-
/** Abstract interface for an extended [viem wallet](https://viem.sh/docs/clients/wallet) (e.g. privy [useSignTypedData](https://docs.privy.io/reference/sdk/react-auth/functions/useSignTypedData#returns)). */
|
|
25
|
-
export interface AbstractExtendedViemWalletClient {
|
|
26
|
-
signTypedData(params: {
|
|
27
|
-
domain: {
|
|
28
|
-
name: string;
|
|
29
|
-
version: string;
|
|
30
|
-
chainId: number;
|
|
31
|
-
verifyingContract: Hex;
|
|
32
|
-
};
|
|
33
|
-
types: {
|
|
34
|
-
[key: string]: {
|
|
35
|
-
name: string;
|
|
36
|
-
type: string;
|
|
37
|
-
}[];
|
|
38
|
-
};
|
|
39
|
-
primaryType: string;
|
|
40
|
-
message: Record<string, unknown>;
|
|
41
|
-
}, options?: unknown): Promise<Hex>;
|
|
42
|
-
}
|
|
43
29
|
/** Abstract interface for an [ethers.js signer](https://docs.ethers.org/v6/api/providers/#Signer). */
|
|
44
30
|
export interface AbstractEthersSigner {
|
|
45
31
|
signTypedData(domain: {
|
|
@@ -68,12 +54,31 @@ export interface AbstractEthersV5Signer {
|
|
|
68
54
|
}[];
|
|
69
55
|
}, value: Record<string, unknown>): Promise<string>;
|
|
70
56
|
}
|
|
57
|
+
/** Abstract interface for an extended [viem wallet](https://viem.sh/docs/clients/wallet) (e.g. privy [useSignTypedData](https://docs.privy.io/reference/sdk/react-auth/functions/useSignTypedData#returns)). */
|
|
58
|
+
export interface AbstractExtendedViemWalletClient {
|
|
59
|
+
signTypedData(params: {
|
|
60
|
+
domain: {
|
|
61
|
+
name: string;
|
|
62
|
+
version: string;
|
|
63
|
+
chainId: number;
|
|
64
|
+
verifyingContract: Hex;
|
|
65
|
+
};
|
|
66
|
+
types: {
|
|
67
|
+
[key: string]: {
|
|
68
|
+
name: string;
|
|
69
|
+
type: string;
|
|
70
|
+
}[];
|
|
71
|
+
};
|
|
72
|
+
primaryType: string;
|
|
73
|
+
message: Record<string, unknown>;
|
|
74
|
+
}, options?: unknown): Promise<Hex>;
|
|
75
|
+
}
|
|
71
76
|
/** Abstract interface for a [window.ethereum](https://eips.ethereum.org/EIPS/eip-1193) object. */
|
|
72
77
|
export interface AbstractWindowEthereum {
|
|
73
|
-
request
|
|
74
|
-
method:
|
|
75
|
-
params:
|
|
76
|
-
})
|
|
78
|
+
request(args: {
|
|
79
|
+
method: any;
|
|
80
|
+
params: any;
|
|
81
|
+
}): Promise<any>;
|
|
77
82
|
}
|
|
78
83
|
/**
|
|
79
84
|
* Create a hash of the L1 action.
|
|
@@ -89,18 +94,48 @@ export declare function createL1ActionHash(action: ValueType, nonce: number, vau
|
|
|
89
94
|
* Sign an L1 action.
|
|
90
95
|
*
|
|
91
96
|
* Note: Signature generation depends on the order of the action keys.
|
|
92
|
-
* @param args
|
|
93
|
-
* @param args.action - The action to be signed.
|
|
94
|
-
* @param args.nonce - Unique request identifier (recommended current timestamp in ms).
|
|
95
|
-
* @param args.isTestnet - Indicates if the action is for the testnet. Default is `false`.
|
|
96
|
-
* @param args.vaultAddress - Optional vault address used in the action.
|
|
97
|
+
* @param args - Arguments for signing the action.
|
|
97
98
|
* @returns The signature components r, s, and v.
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { signL1Action } from "@nktkas/hyperliquid/signing";
|
|
102
|
+
* import { privateKeyToAccount } from "viem/accounts";
|
|
103
|
+
*
|
|
104
|
+
* const wallet = privateKeyToAccount("0x..."); // Change to your private key
|
|
105
|
+
*
|
|
106
|
+
* const action = {
|
|
107
|
+
* type: "cancel",
|
|
108
|
+
* cancels: [
|
|
109
|
+
* { a: 0, o: 12345 }, // Asset index and order ID
|
|
110
|
+
* ],
|
|
111
|
+
* };
|
|
112
|
+
* const nonce = Date.now();
|
|
113
|
+
*
|
|
114
|
+
* const signature = await signL1Action({
|
|
115
|
+
* wallet,
|
|
116
|
+
* action,
|
|
117
|
+
* nonce,
|
|
118
|
+
* isTestnet: true, // Change to false for mainnet
|
|
119
|
+
* });
|
|
120
|
+
*
|
|
121
|
+
* const response = await fetch("https://api.hyperliquid-testnet.xyz/exchange", {
|
|
122
|
+
* method: "POST",
|
|
123
|
+
* headers: { "Content-Type": "application/json" },
|
|
124
|
+
* body: JSON.stringify({ action, signature, nonce }),
|
|
125
|
+
* });
|
|
126
|
+
* const body = await response.json();
|
|
127
|
+
* ```
|
|
98
128
|
*/
|
|
99
129
|
export declare function signL1Action(args: {
|
|
100
|
-
|
|
130
|
+
/** Wallet to sign the action. */
|
|
131
|
+
wallet: AbstractViemWalletClient | AbstractEthersSigner | AbstractEthersV5Signer | AbstractExtendedViemWalletClient | AbstractWindowEthereum;
|
|
132
|
+
/** The action to be signed. */
|
|
101
133
|
action: ValueType;
|
|
134
|
+
/** Unique request identifier (recommended current timestamp in ms). */
|
|
102
135
|
nonce: number;
|
|
136
|
+
/** Indicates if the action is for the testnet. Default is `false`. */
|
|
103
137
|
isTestnet?: boolean;
|
|
138
|
+
/** Optional vault address used in the action. */
|
|
104
139
|
vaultAddress?: Hex;
|
|
105
140
|
}): Promise<{
|
|
106
141
|
r: Hex;
|
|
@@ -111,25 +146,73 @@ export declare function signL1Action(args: {
|
|
|
111
146
|
* Sign a user-signed action.
|
|
112
147
|
*
|
|
113
148
|
* Note: Signature generation depends on the order of types.
|
|
114
|
-
* @param args
|
|
115
|
-
* @param args.action - The action to be signed.
|
|
116
|
-
* @param args.types - The types of the action.
|
|
117
|
-
* @param args.chainId - The chain ID.
|
|
149
|
+
* @param args - Arguments for signing the action.
|
|
118
150
|
* @returns The signature components r, s, and v.
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* import { signUserSignedAction } from "@nktkas/hyperliquid/signing";
|
|
154
|
+
* import { privateKeyToAccount } from "viem/accounts";
|
|
155
|
+
*
|
|
156
|
+
* const wallet = privateKeyToAccount("0x..."); // Change to your private key
|
|
157
|
+
*
|
|
158
|
+
* const action = {
|
|
159
|
+
* type: "approveAgent",
|
|
160
|
+
* hyperliquidChain: "Testnet", // "Mainnet" or "Testnet"
|
|
161
|
+
* signatureChainId: "0x66eee",
|
|
162
|
+
* nonce: Date.now(),
|
|
163
|
+
* agentAddress: "0x...", // Change to your agent address
|
|
164
|
+
* agentName: "Agent",
|
|
165
|
+
* };
|
|
166
|
+
*
|
|
167
|
+
* const signature = await signUserSignedAction({
|
|
168
|
+
* wallet,
|
|
169
|
+
* action,
|
|
170
|
+
* types: {
|
|
171
|
+
* "HyperliquidTransaction:ApproveAgent": [
|
|
172
|
+
* { name: "hyperliquidChain", type: "string" },
|
|
173
|
+
* { name: "agentAddress", type: "address" },
|
|
174
|
+
* { name: "agentName", type: "string" },
|
|
175
|
+
* { name: "nonce", type: "uint64" },
|
|
176
|
+
* ],
|
|
177
|
+
* },
|
|
178
|
+
* chainId: parseInt(action.signatureChainId, 16),
|
|
179
|
+
* });
|
|
180
|
+
*
|
|
181
|
+
* const response = await fetch("https://api.hyperliquid-testnet.xyz/exchange", {
|
|
182
|
+
* method: "POST",
|
|
183
|
+
* headers: { "Content-Type": "application/json" },
|
|
184
|
+
* body: JSON.stringify({ action, signature, nonce: action.nonce }),
|
|
185
|
+
* });
|
|
186
|
+
* const body = await response.json();
|
|
187
|
+
* ```
|
|
119
188
|
*/
|
|
120
189
|
export declare function signUserSignedAction(args: {
|
|
121
|
-
|
|
190
|
+
/** Wallet to sign the action. */
|
|
191
|
+
wallet: AbstractViemWalletClient | AbstractEthersSigner | AbstractEthersV5Signer | AbstractExtendedViemWalletClient | AbstractWindowEthereum;
|
|
192
|
+
/** The action to be signed. */
|
|
122
193
|
action: Record<string, unknown>;
|
|
194
|
+
/** The types of the action. */
|
|
123
195
|
types: {
|
|
124
196
|
[key: string]: {
|
|
125
197
|
name: string;
|
|
126
198
|
type: string;
|
|
127
199
|
}[];
|
|
128
200
|
};
|
|
201
|
+
/** The chain ID. */
|
|
129
202
|
chainId: number;
|
|
130
203
|
}): Promise<{
|
|
131
204
|
r: Hex;
|
|
132
205
|
s: Hex;
|
|
133
206
|
v: number;
|
|
134
207
|
}>;
|
|
208
|
+
/** Checks if the given value is an abstract viem wallet. */
|
|
209
|
+
export declare function isAbstractViemWalletClient(client: unknown): client is AbstractViemWalletClient;
|
|
210
|
+
/** Checks if the given value is an abstract ethers signer. */
|
|
211
|
+
export declare function isAbstractEthersSigner(client: unknown): client is AbstractEthersSigner;
|
|
212
|
+
/** Checks if the given value is an abstract ethers v5 signer. */
|
|
213
|
+
export declare function isAbstractEthersV5Signer(client: unknown): client is AbstractEthersV5Signer;
|
|
214
|
+
/** Checks if the given value is an abstract extended viem wallet (e.g. privy `useSignTypedData`). */
|
|
215
|
+
export declare function isAbstractExtendedViemWalletClient(client: unknown): client is AbstractViemWalletClient;
|
|
216
|
+
/** Checks if the given value is an abstract `window.ethereum` object. */
|
|
217
|
+
export declare function isAbstractWindowEthereum(client: unknown): client is AbstractWindowEthereum;
|
|
135
218
|
//# sourceMappingURL=signing.d.ts.map
|
package/esm/src/signing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../src/src/signing.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../src/src/signing.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAU,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,6CAA6C,CAAC;AAEpG,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAErC,YAAY,EAAE,GAAG,EAAE,CAAC;AACpB,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;AAEpC,mFAAmF;AACnF,MAAM,WAAW,wBAAwB;IACrC,aAAa,CAAC,MAAM,EAAE;QAClB,MAAM,EAAE;YACJ,IAAI,EAAE,MAAM,CAAC;YAC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F"}
|
package/esm/src/signing.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module contains functions for generating Hyperliquid transaction signatures
|
|
3
|
+
* and interfaces to various wallet implementations.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
1
6
|
import { keccak_256 } from "../deps/jsr.io/@noble/hashes/1.7.1/src/sha3.js";
|
|
2
7
|
import { encode } from "../deps/jsr.io/@std/msgpack/1.0.3/encode.js";
|
|
3
8
|
import { decodeHex, encodeHex } from "../deps/jsr.io/@std/encoding/1.0.7/hex.js";
|
|
@@ -50,12 +55,37 @@ function normalizeIntegersForMsgPack(obj) {
|
|
|
50
55
|
* Sign an L1 action.
|
|
51
56
|
*
|
|
52
57
|
* Note: Signature generation depends on the order of the action keys.
|
|
53
|
-
* @param args
|
|
54
|
-
* @param args.action - The action to be signed.
|
|
55
|
-
* @param args.nonce - Unique request identifier (recommended current timestamp in ms).
|
|
56
|
-
* @param args.isTestnet - Indicates if the action is for the testnet. Default is `false`.
|
|
57
|
-
* @param args.vaultAddress - Optional vault address used in the action.
|
|
58
|
+
* @param args - Arguments for signing the action.
|
|
58
59
|
* @returns The signature components r, s, and v.
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { signL1Action } from "@nktkas/hyperliquid/signing";
|
|
63
|
+
* import { privateKeyToAccount } from "viem/accounts";
|
|
64
|
+
*
|
|
65
|
+
* const wallet = privateKeyToAccount("0x..."); // Change to your private key
|
|
66
|
+
*
|
|
67
|
+
* const action = {
|
|
68
|
+
* type: "cancel",
|
|
69
|
+
* cancels: [
|
|
70
|
+
* { a: 0, o: 12345 }, // Asset index and order ID
|
|
71
|
+
* ],
|
|
72
|
+
* };
|
|
73
|
+
* const nonce = Date.now();
|
|
74
|
+
*
|
|
75
|
+
* const signature = await signL1Action({
|
|
76
|
+
* wallet,
|
|
77
|
+
* action,
|
|
78
|
+
* nonce,
|
|
79
|
+
* isTestnet: true, // Change to false for mainnet
|
|
80
|
+
* });
|
|
81
|
+
*
|
|
82
|
+
* const response = await fetch("https://api.hyperliquid-testnet.xyz/exchange", {
|
|
83
|
+
* method: "POST",
|
|
84
|
+
* headers: { "Content-Type": "application/json" },
|
|
85
|
+
* body: JSON.stringify({ action, signature, nonce }),
|
|
86
|
+
* });
|
|
87
|
+
* const body = await response.json();
|
|
88
|
+
* ```
|
|
59
89
|
*/
|
|
60
90
|
export async function signL1Action(args) {
|
|
61
91
|
const { wallet, action, nonce, isTestnet = false, vaultAddress, } = args;
|
|
@@ -83,11 +113,45 @@ export async function signL1Action(args) {
|
|
|
83
113
|
* Sign a user-signed action.
|
|
84
114
|
*
|
|
85
115
|
* Note: Signature generation depends on the order of types.
|
|
86
|
-
* @param args
|
|
87
|
-
* @param args.action - The action to be signed.
|
|
88
|
-
* @param args.types - The types of the action.
|
|
89
|
-
* @param args.chainId - The chain ID.
|
|
116
|
+
* @param args - Arguments for signing the action.
|
|
90
117
|
* @returns The signature components r, s, and v.
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { signUserSignedAction } from "@nktkas/hyperliquid/signing";
|
|
121
|
+
* import { privateKeyToAccount } from "viem/accounts";
|
|
122
|
+
*
|
|
123
|
+
* const wallet = privateKeyToAccount("0x..."); // Change to your private key
|
|
124
|
+
*
|
|
125
|
+
* const action = {
|
|
126
|
+
* type: "approveAgent",
|
|
127
|
+
* hyperliquidChain: "Testnet", // "Mainnet" or "Testnet"
|
|
128
|
+
* signatureChainId: "0x66eee",
|
|
129
|
+
* nonce: Date.now(),
|
|
130
|
+
* agentAddress: "0x...", // Change to your agent address
|
|
131
|
+
* agentName: "Agent",
|
|
132
|
+
* };
|
|
133
|
+
*
|
|
134
|
+
* const signature = await signUserSignedAction({
|
|
135
|
+
* wallet,
|
|
136
|
+
* action,
|
|
137
|
+
* types: {
|
|
138
|
+
* "HyperliquidTransaction:ApproveAgent": [
|
|
139
|
+
* { name: "hyperliquidChain", type: "string" },
|
|
140
|
+
* { name: "agentAddress", type: "address" },
|
|
141
|
+
* { name: "agentName", type: "string" },
|
|
142
|
+
* { name: "nonce", type: "uint64" },
|
|
143
|
+
* ],
|
|
144
|
+
* },
|
|
145
|
+
* chainId: parseInt(action.signatureChainId, 16),
|
|
146
|
+
* });
|
|
147
|
+
*
|
|
148
|
+
* const response = await fetch("https://api.hyperliquid-testnet.xyz/exchange", {
|
|
149
|
+
* method: "POST",
|
|
150
|
+
* headers: { "Content-Type": "application/json" },
|
|
151
|
+
* body: JSON.stringify({ action, signature, nonce: action.nonce }),
|
|
152
|
+
* });
|
|
153
|
+
* const body = await response.json();
|
|
154
|
+
* ```
|
|
91
155
|
*/
|
|
92
156
|
export async function signUserSignedAction(args) {
|
|
93
157
|
const { wallet, action, types, chainId } = args;
|
|
@@ -157,31 +221,31 @@ function splitSignature(signature) {
|
|
|
157
221
|
return { r, s, v };
|
|
158
222
|
}
|
|
159
223
|
/** Checks if the given value is an abstract viem wallet. */
|
|
160
|
-
function isAbstractViemWalletClient(client) {
|
|
224
|
+
export function isAbstractViemWalletClient(client) {
|
|
161
225
|
return typeof client === "object" && client !== null &&
|
|
162
226
|
"signTypedData" in client && typeof client.signTypedData === "function" &&
|
|
163
227
|
client.signTypedData.length === 1;
|
|
164
228
|
}
|
|
165
|
-
/** Checks if the given value is an abstract extended viem wallet (e.g. privy `useSignTypedData`). */
|
|
166
|
-
function isAbstractExtendedViemWalletClient(client) {
|
|
167
|
-
return typeof client === "object" && client !== null &&
|
|
168
|
-
"signTypedData" in client && typeof client.signTypedData === "function" &&
|
|
169
|
-
client.signTypedData.length === 2;
|
|
170
|
-
}
|
|
171
229
|
/** Checks if the given value is an abstract ethers signer. */
|
|
172
|
-
function isAbstractEthersSigner(client) {
|
|
230
|
+
export function isAbstractEthersSigner(client) {
|
|
173
231
|
return typeof client === "object" && client !== null &&
|
|
174
232
|
"signTypedData" in client && typeof client.signTypedData === "function" &&
|
|
175
233
|
client.signTypedData.length === 3;
|
|
176
234
|
}
|
|
177
235
|
/** Checks if the given value is an abstract ethers v5 signer. */
|
|
178
|
-
function isAbstractEthersV5Signer(client) {
|
|
236
|
+
export function isAbstractEthersV5Signer(client) {
|
|
179
237
|
return typeof client === "object" && client !== null &&
|
|
180
238
|
"_signTypedData" in client && typeof client._signTypedData === "function" &&
|
|
181
239
|
client._signTypedData.length === 3;
|
|
182
240
|
}
|
|
241
|
+
/** Checks if the given value is an abstract extended viem wallet (e.g. privy `useSignTypedData`). */
|
|
242
|
+
export function isAbstractExtendedViemWalletClient(client) {
|
|
243
|
+
return typeof client === "object" && client !== null &&
|
|
244
|
+
"signTypedData" in client && typeof client.signTypedData === "function" &&
|
|
245
|
+
client.signTypedData.length === 2;
|
|
246
|
+
}
|
|
183
247
|
/** Checks if the given value is an abstract `window.ethereum` object. */
|
|
184
|
-
function isAbstractWindowEthereum(client) {
|
|
248
|
+
export function isAbstractWindowEthereum(client) {
|
|
185
249
|
return typeof client === "object" && client !== null &&
|
|
186
250
|
"request" in client && typeof client.request === "function" &&
|
|
187
251
|
client.request.length >= 1;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { type IRequestTransport, TransportError } from "../../base.js";
|
|
2
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
1
|
+
import { type IRequestTransport, type MaybePromise, TransportError } from "../../base.js";
|
|
3
2
|
/**
|
|
4
3
|
* Error thrown when an HTTP response is deemed invalid:
|
|
5
4
|
* - Non-200 status code
|
|
@@ -18,28 +17,10 @@ export declare class HttpRequestError extends TransportError {
|
|
|
18
17
|
/** Configuration options for the HTTP transport layer. */
|
|
19
18
|
export interface HttpTransportOptions {
|
|
20
19
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* When given as a string or URL, the URL is modified based on the request type:
|
|
24
|
-
* - For `"info"` and `"exchange"`, the hostname is replaced with `api.<baseDomain>`.
|
|
25
|
-
* - For `"explorer"`, the hostname is replaced with `rpc.<baseDomain>`.
|
|
26
|
-
*
|
|
27
|
-
* Alternatively, you can supply an object to specify separate URLs:
|
|
28
|
-
* ```ts
|
|
29
|
-
* {
|
|
30
|
-
* api: "https://api.hyperliquid.xyz",
|
|
31
|
-
* rpc: "https://rpc.hyperliquid.xyz"
|
|
32
|
-
* }
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* - Mainnet: `https://hyperliquid.xyz`
|
|
36
|
-
* - Testnet: `https://hyperliquid-testnet.xyz`
|
|
37
|
-
* @defaultValue `https://hyperliquid.xyz`
|
|
20
|
+
* Specifies whether to use the testnet API endpoints.
|
|
21
|
+
* @defaultValue `false`
|
|
38
22
|
*/
|
|
39
|
-
|
|
40
|
-
api?: string | URL;
|
|
41
|
-
rpc?: string | URL;
|
|
42
|
-
};
|
|
23
|
+
isTestnet?: boolean;
|
|
43
24
|
/**
|
|
44
25
|
* Request timeout in ms.
|
|
45
26
|
* Set to `null` to disable.
|
|
@@ -63,10 +44,18 @@ export interface HttpTransportOptions {
|
|
|
63
44
|
}
|
|
64
45
|
/** HTTP implementation of the REST transport interface. */
|
|
65
46
|
export declare class HttpTransport implements IRequestTransport, HttpTransportOptions {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
47
|
+
/** API endpoint paths for mainnet and testnet. */
|
|
48
|
+
protected static readonly endpointPaths: {
|
|
49
|
+
mainnet: {
|
|
50
|
+
api: string;
|
|
51
|
+
rpc: string;
|
|
52
|
+
};
|
|
53
|
+
testnet: {
|
|
54
|
+
api: string;
|
|
55
|
+
rpc: string;
|
|
56
|
+
};
|
|
69
57
|
};
|
|
58
|
+
isTestnet: boolean;
|
|
70
59
|
timeout: number | null;
|
|
71
60
|
fetchOptions: Omit<RequestInit, "body" | "method">;
|
|
72
61
|
onRequest?: (request: Request) => MaybePromise<Request | void | null | undefined>;
|
|
@@ -87,5 +76,4 @@ export declare class HttpTransport implements IRequestTransport, HttpTransportOp
|
|
|
87
76
|
*/
|
|
88
77
|
request(endpoint: "info" | "exchange" | "explorer", payload: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
89
78
|
}
|
|
90
|
-
export {};
|
|
91
79
|
//# sourceMappingURL=http_transport.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http_transport.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/http/http_transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"http_transport.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/http/http_transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE1F;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,cAAc;IAM7B,QAAQ,EAAE,QAAQ;IAAS,YAAY,CAAC,EAAE,MAAM;IALnE;;;;OAIG;gBACgB,QAAQ,EAAE,QAAQ,EAAS,YAAY,CAAC,EAAE,MAAM,YAAA;CAOtE;AAED,0DAA0D;AAC1D,MAAM,WAAW,oBAAoB;IACjC;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAExB,2IAA2I;IAC3I,YAAY,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC;IAEpD;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,YAAY,CAAC,OAAO,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IAElF;;;;OAIG;IACH,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,YAAY,CAAC,QAAQ,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;CACzF;AAED,2DAA2D;AAC3D,qBAAa,aAAc,YAAW,iBAAiB,EAAE,oBAAoB;IACzE,kDAAkD;IAClD,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa;;;;;;;;;MASrC;IAEF,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,YAAY,EAAE,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ,CAAC,CAAC;IACnD,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,YAAY,CAAC,OAAO,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IAClF,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,YAAY,CAAC,QAAQ,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IAEtF;;;OAGG;gBACS,OAAO,CAAC,EAAE,oBAAoB;IAQ1C;;;;;;;;OAQG;IACG,OAAO,CACT,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,EAC1C,OAAO,EAAE,OAAO,EAChB,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,OAAO,CAAC;CAiDtB"}
|
|
@@ -37,7 +37,7 @@ export class HttpTransport {
|
|
|
37
37
|
* @param options - Configuration options for the HTTP transport layer.
|
|
38
38
|
*/
|
|
39
39
|
constructor(options) {
|
|
40
|
-
Object.defineProperty(this, "
|
|
40
|
+
Object.defineProperty(this, "isTestnet", {
|
|
41
41
|
enumerable: true,
|
|
42
42
|
configurable: true,
|
|
43
43
|
writable: true,
|
|
@@ -67,7 +67,7 @@ export class HttpTransport {
|
|
|
67
67
|
writable: true,
|
|
68
68
|
value: void 0
|
|
69
69
|
});
|
|
70
|
-
this.
|
|
70
|
+
this.isTestnet = options?.isTestnet ?? false;
|
|
71
71
|
this.timeout = options?.timeout === undefined ? 10_000 : options.timeout;
|
|
72
72
|
this.fetchOptions = options?.fetchOptions ?? {};
|
|
73
73
|
this.onRequest = options?.onRequest;
|
|
@@ -84,19 +84,8 @@ export class HttpTransport {
|
|
|
84
84
|
*/
|
|
85
85
|
async request(endpoint, payload, signal) {
|
|
86
86
|
// Construct a Request
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
// If a string is provided, get the base domain and apply the modification to it
|
|
90
|
-
const parsedUrl = new URL(this.url);
|
|
91
|
-
const parts = parsedUrl.hostname.split(".");
|
|
92
|
-
const baseDomain = parts.slice(-2).join(".");
|
|
93
|
-
const baseUrl = `${parsedUrl.protocol}//${endpoint === "explorer" ? "rpc" : "api"}.${baseDomain}`;
|
|
94
|
-
url = new URL(endpoint, baseUrl);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
// If an object is specified, use the specific url and add a path to it
|
|
98
|
-
url = new URL(endpoint, endpoint === "explorer" ? this.url.rpc : this.url.api);
|
|
99
|
-
}
|
|
87
|
+
const url = new URL(endpoint, HttpTransport
|
|
88
|
+
.endpointPaths[this.isTestnet ? "testnet" : "mainnet"][endpoint === "explorer" ? "rpc" : "api"]);
|
|
100
89
|
const init = mergeRequestInit({
|
|
101
90
|
body: JSON.stringify(payload),
|
|
102
91
|
headers: {
|
|
@@ -133,6 +122,22 @@ export class HttpTransport {
|
|
|
133
122
|
return await response.json();
|
|
134
123
|
}
|
|
135
124
|
}
|
|
125
|
+
/** API endpoint paths for mainnet and testnet. */
|
|
126
|
+
Object.defineProperty(HttpTransport, "endpointPaths", {
|
|
127
|
+
enumerable: true,
|
|
128
|
+
configurable: true,
|
|
129
|
+
writable: true,
|
|
130
|
+
value: {
|
|
131
|
+
mainnet: {
|
|
132
|
+
api: "https://api.hyperliquid.xyz",
|
|
133
|
+
rpc: "https://rpc.hyperliquid.xyz",
|
|
134
|
+
},
|
|
135
|
+
testnet: {
|
|
136
|
+
api: "https://api.hyperliquid-testnet.xyz",
|
|
137
|
+
rpc: "https://rpc.hyperliquid-testnet.xyz",
|
|
138
|
+
},
|
|
139
|
+
}
|
|
140
|
+
});
|
|
136
141
|
/**
|
|
137
142
|
* Merges multiple `HeadersInit` objects into one.
|
|
138
143
|
* @param inits - A list of `HeadersInit` objects to merge.
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { TransportError } from "../../base.js";
|
|
2
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
1
|
+
import { type MaybePromise, TransportError } from "../../base.js";
|
|
3
2
|
/** Configuration options for the `ReconnectingWebSocket`. */
|
|
4
3
|
export interface ReconnectingWebSocketOptions {
|
|
5
4
|
/**
|
|
@@ -136,5 +135,4 @@ export declare class ReconnectingWebSocket implements WebSocket {
|
|
|
136
135
|
}, options?: boolean | EventListenerOptions): void;
|
|
137
136
|
dispatchEvent(event: Event): boolean;
|
|
138
137
|
}
|
|
139
|
-
export {};
|
|
140
138
|
//# sourceMappingURL=_reconnecting_websocket.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_reconnecting_websocket.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/_reconnecting_websocket.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"_reconnecting_websocket.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/_reconnecting_websocket.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAElE,6DAA6D;AAC7D,MAAM,WAAW,4BAA4B;IACzC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAElC;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;IAEvE;;;;;OAKG;IACH,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,YAAY,CAAC,OAAO,CAAC,CAAC;IAE/D;;;OAGG;IACH,aAAa,CAAC,EAAE,qBAAqB,CAAC;CACzC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AAQ,EACF,CAAC,CAAC,IAAI,EAAE,qBAAqB,EAAE,EAAE,EAAE,iBAAiB,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,GAChE;QAAE,WAAW,EAAE,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,KAAK,GAAG,CAAA;KAAE,EAC3D,OAAO,CAAC,EAAE,OAAO,GAAG,oBAAoB,GACzC,IAAI;IAkBP,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;CAGvC"}
|
|
@@ -8,8 +8,12 @@ export { type MessageBufferStrategy, ReconnectingWebSocketError, type Reconnecti
|
|
|
8
8
|
export interface WebSocketTransportOptions {
|
|
9
9
|
/**
|
|
10
10
|
* The WebSocket URL.
|
|
11
|
-
* - Mainnet:
|
|
12
|
-
*
|
|
11
|
+
* - Mainnet:
|
|
12
|
+
* - API: `wss://api.hyperliquid.xyz/ws`
|
|
13
|
+
* - RPC: `wss://rpc.hyperliquid.xyz/ws`
|
|
14
|
+
* - Testnet:
|
|
15
|
+
* - API: `wss://api.hyperliquid-testnet.xyz/ws`
|
|
16
|
+
* - RPC: `wss://rpc.hyperliquid-testnet.xyz/ws`
|
|
13
17
|
* @defaultValue `wss://api.hyperliquid.xyz/ws`
|
|
14
18
|
*/
|
|
15
19
|
url?: string | URL;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket_transport.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/websocket_transport.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,qBAAqB,EAC1B,qBAAqB,EACrB,0BAA0B,EAC1B,KAAK,4BAA4B,EACpC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AACvG,OAAO,KAAK,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7F,OAAO,EAAE,qBAAqB,EAAE,CAAC;AACjC,OAAO,EAAE,KAAK,qBAAqB,EAAE,0BAA0B,EAAE,KAAK,4BAA4B,EAAE,CAAC;AAErG,+DAA+D;AAC/D,MAAM,WAAW,yBAAyB;IACtC
|
|
1
|
+
{"version":3,"file":"websocket_transport.d.ts","sourceRoot":"","sources":["../../../../src/src/transports/websocket/websocket_transport.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,qBAAqB,EAC1B,qBAAqB,EACrB,0BAA0B,EAC1B,KAAK,4BAA4B,EACpC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AACvG,OAAO,KAAK,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7F,OAAO,EAAE,qBAAqB,EAAE,CAAC;AACjC,OAAO,EAAE,KAAK,qBAAqB,EAAE,0BAA0B,EAAE,KAAK,4BAA4B,EAAE,CAAC;AAErG,+DAA+D;AAC/D,MAAM,WAAW,yBAAyB;IACtC;;;;;;;;;OASG;IACH,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IAEnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAExB;;;OAGG;IACH,SAAS,CAAC,EAAE;QACR;;;;WAIG;QACH,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KAC5B,CAAC;IAEF;;OAEG;IACH,SAAS,CAAC,EAAE,4BAA4B,CAAC;CAC5C;AAED,kFAAkF;AAClF,qBAAa,kBAAmB,YAAW,iBAAiB,EAAE,sBAAsB;IAChF,qDAAqD;IACrD,SAAS,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAQ;IAEhD,iDAAiD;IACjD,SAAS,CAAC,YAAY,EAAE,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est extends BaseExchangeRequest {
|
|
|
117
117
|
vaultAddress?: Hex;
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
|
-
* Cancel order(s)
|
|
120
|
+
* Cancel order(s).
|
|
121
121
|
* @returns {CancelResponse}
|
|
122
|
-
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s
|
|
122
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s
|
|
123
123
|
*/
|
|
124
|
-
export interface
|
|
124
|
+
export interface CancelRequest extends BaseExchangeRequest {
|
|
125
125
|
/** Action to be performed. */
|
|
126
126
|
action: {
|
|
127
127
|
/** Type of action. */
|
|
128
|
-
type: "
|
|
128
|
+
type: "cancel";
|
|
129
129
|
/** Orders to cancel. */
|
|
130
130
|
cancels: {
|
|
131
131
|
/** Asset ID. */
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
|
|
132
|
+
a: number;
|
|
133
|
+
/** Order ID. */
|
|
134
|
+
o: number;
|
|
135
135
|
}[];
|
|
136
136
|
};
|
|
137
137
|
/** Vault address (for vault trading). */
|
|
138
138
|
vaultAddress?: Hex;
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
|
-
* Cancel order(s).
|
|
141
|
+
* Cancel order(s) by cloid.
|
|
142
142
|
* @returns {CancelResponse}
|
|
143
|
-
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s
|
|
143
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s-by-cloid
|
|
144
144
|
*/
|
|
145
|
-
export interface
|
|
145
|
+
export interface CancelByCloidRequest extends BaseExchangeRequest {
|
|
146
146
|
/** Action to be performed. */
|
|
147
147
|
action: {
|
|
148
148
|
/** Type of action. */
|
|
149
|
-
type: "
|
|
149
|
+
type: "cancelByCloid";
|
|
150
150
|
/** Orders to cancel. */
|
|
151
151
|
cancels: {
|
|
152
152
|
/** Asset ID. */
|
|
153
|
-
|
|
154
|
-
/** Order ID. */
|
|
155
|
-
|
|
153
|
+
asset: number;
|
|
154
|
+
/** Client Order ID. */
|
|
155
|
+
cloid: Hex;
|
|
156
156
|
}[];
|
|
157
157
|
};
|
|
158
158
|
/** Vault address (for vault trading). */
|
|
@@ -306,6 +306,20 @@ export interface OrderRequest extends BaseExchangeRequest {
|
|
|
306
306
|
/** Vault address (for vault trading). */
|
|
307
307
|
vaultAddress?: Hex;
|
|
308
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Reserve additional rate-limited actions for a fee.
|
|
311
|
+
* @returns {SuccessResponse}
|
|
312
|
+
* @see https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#reserve-additional-actions
|
|
313
|
+
*/
|
|
314
|
+
export interface ReserveRequestWeightRequest extends BaseExchangeRequest {
|
|
315
|
+
/** Action to perform. */
|
|
316
|
+
action: {
|
|
317
|
+
/** Type of action. */
|
|
318
|
+
type: "reserveRequestWeight";
|
|
319
|
+
/** Amount of request weight to reserve. */
|
|
320
|
+
weight: number;
|
|
321
|
+
};
|
|
322
|
+
}
|
|
309
323
|
/**
|
|
310
324
|
* Schedule a time to cancel all open orders.
|
|
311
325
|
* @returns {SuccessResponse}
|