@nktkas/hyperliquid 0.19.2 → 0.21.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 +61 -79
- package/esm/mod.d.ts +5 -3
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +4 -3
- package/esm/src/base.d.ts +1 -47
- package/esm/src/base.d.ts.map +1 -1
- package/esm/src/base.js +1 -8
- package/{script/src/clients/wallet.d.ts → esm/src/clients/exchange.d.ts} +111 -112
- package/esm/src/clients/exchange.d.ts.map +1 -0
- package/esm/src/clients/{wallet.js → exchange.js} +96 -306
- package/esm/src/clients/{public.d.ts → info.d.ts} +121 -102
- package/esm/src/clients/info.d.ts.map +1 -0
- package/esm/src/clients/{public.js → info.js} +73 -57
- package/{script/src/clients/event.d.ts → esm/src/clients/subscription.d.ts} +61 -80
- package/esm/src/clients/subscription.d.ts.map +1 -0
- package/esm/src/clients/{event.js → subscription.js} +106 -136
- package/esm/src/signing.d.ts +4 -0
- package/esm/src/signing.d.ts.map +1 -1
- package/esm/src/signing.js +23 -5
- package/esm/src/transports/base.d.ts +47 -0
- package/esm/src/transports/base.d.ts.map +1 -0
- package/esm/src/transports/base.js +8 -0
- package/esm/src/transports/http/http_transport.d.ts +8 -5
- package/esm/src/transports/http/http_transport.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.js +15 -62
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +36 -39
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts +21 -27
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.js +89 -182
- package/{script/src/transports/websocket/_websocket_request_dispatcher.d.ts → esm/src/transports/websocket/_websocket_async_request.d.ts} +17 -19
- package/esm/src/transports/websocket/_websocket_async_request.d.ts.map +1 -0
- package/esm/src/transports/websocket/_websocket_async_request.js +177 -0
- package/esm/src/transports/websocket/websocket_transport.d.ts +54 -41
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.js +101 -113
- package/esm/src/types/info/accounts.d.ts +1 -0
- package/esm/src/types/info/accounts.d.ts.map +1 -1
- package/esm/src/types/info/assets.d.ts +0 -48
- package/esm/src/types/info/assets.d.ts.map +1 -1
- package/esm/src/types/info/markets.d.ts +52 -0
- package/esm/src/types/info/markets.d.ts.map +1 -0
- package/esm/src/types/info/markets.js +1 -0
- package/esm/src/types/info/requests.d.ts +9 -0
- package/esm/src/types/info/requests.d.ts.map +1 -1
- package/esm/src/types/mod.d.ts +3 -0
- package/esm/src/types/mod.d.ts.map +1 -1
- package/esm/src/types/mod.js +2 -0
- package/package.json +12 -9
- package/script/mod.d.ts +5 -3
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +5 -4
- package/script/src/base.d.ts +1 -47
- package/script/src/base.d.ts.map +1 -1
- package/script/src/base.js +2 -10
- package/{esm/src/clients/wallet.d.ts → script/src/clients/exchange.d.ts} +111 -112
- package/script/src/clients/exchange.d.ts.map +1 -0
- package/script/src/clients/{wallet.js → exchange.js} +98 -308
- package/script/src/clients/{public.d.ts → info.d.ts} +121 -102
- package/script/src/clients/info.d.ts.map +1 -0
- package/script/src/clients/{public.js → info.js} +75 -59
- package/{esm/src/clients/event.d.ts → script/src/clients/subscription.d.ts} +61 -80
- package/script/src/clients/subscription.d.ts.map +1 -0
- package/script/src/clients/{event.js → subscription.js} +108 -138
- package/script/src/signing.d.ts +4 -0
- package/script/src/signing.d.ts.map +1 -1
- package/script/src/signing.js +25 -7
- package/script/src/transports/base.d.ts +47 -0
- package/script/src/transports/base.d.ts.map +1 -0
- package/script/src/transports/base.js +22 -0
- package/script/src/transports/http/http_transport.d.ts +8 -5
- package/script/src/transports/http/http_transport.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.js +16 -63
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +36 -39
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts +21 -27
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/script/src/transports/websocket/_reconnecting_websocket.js +90 -183
- package/{esm/src/transports/websocket/_websocket_request_dispatcher.d.ts → script/src/transports/websocket/_websocket_async_request.d.ts} +17 -19
- package/script/src/transports/websocket/_websocket_async_request.d.ts.map +1 -0
- package/script/src/transports/websocket/_websocket_async_request.js +192 -0
- package/script/src/transports/websocket/websocket_transport.d.ts +54 -41
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.js +103 -115
- package/script/src/types/info/accounts.d.ts +1 -0
- package/script/src/types/info/accounts.d.ts.map +1 -1
- package/script/src/types/info/assets.d.ts +0 -48
- package/script/src/types/info/assets.d.ts.map +1 -1
- package/script/src/types/info/markets.d.ts +52 -0
- package/script/src/types/info/markets.d.ts.map +1 -0
- package/script/{deps/jsr.io/@noble/hashes/1.8.0/src/crypto.js → src/types/info/markets.js} +0 -2
- package/script/src/types/info/requests.d.ts +9 -0
- package/script/src/types/info/requests.d.ts.map +1 -1
- package/script/src/types/mod.d.ts +3 -0
- package/script/src/types/mod.d.ts.map +1 -1
- package/script/src/types/mod.js +2 -0
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.d.ts +0 -55
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.d.ts.map +0 -1
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.js +0 -66
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/crypto.d.ts +0 -2
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/crypto.d.ts.map +0 -1
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/crypto.js +0 -1
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.d.ts +0 -53
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.d.ts.map +0 -1
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.js +0 -294
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/utils.d.ts +0 -161
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/utils.d.ts.map +0 -1
- package/esm/deps/jsr.io/@noble/hashes/1.8.0/src/utils.js +0 -280
- package/esm/src/clients/event.d.ts.map +0 -1
- package/esm/src/clients/public.d.ts.map +0 -1
- package/esm/src/clients/wallet.d.ts.map +0 -1
- package/esm/src/transports/websocket/_websocket_request_dispatcher.d.ts.map +0 -1
- package/esm/src/transports/websocket/_websocket_request_dispatcher.js +0 -191
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.d.ts +0 -55
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.d.ts.map +0 -1
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/_u64.js +0 -99
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/crypto.d.ts +0 -2
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/crypto.d.ts.map +0 -1
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.d.ts +0 -53
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.d.ts.map +0 -1
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/sha3.js +0 -309
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/utils.d.ts +0 -161
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/utils.d.ts.map +0 -1
- package/script/deps/jsr.io/@noble/hashes/1.8.0/src/utils.js +0 -322
- package/script/src/clients/event.d.ts.map +0 -1
- package/script/src/clients/public.d.ts.map +0 -1
- package/script/src/clients/wallet.d.ts.map +0 -1
- package/script/src/transports/websocket/_websocket_request_dispatcher.d.ts.map +0 -1
- package/script/src/transports/websocket/_websocket_request_dispatcher.js +0 -206
|
@@ -9,11 +9,12 @@
|
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.ExchangeClient = exports.ApiRequestError = void 0;
|
|
13
13
|
const base_js_1 = require("../base.js");
|
|
14
14
|
const signing_js_1 = require("../signing.js");
|
|
15
15
|
/** Error thrown when the API returns an error response. */
|
|
16
16
|
class ApiRequestError extends base_js_1.HyperliquidError {
|
|
17
|
+
response;
|
|
17
18
|
constructor(response) {
|
|
18
19
|
let message = "Cannot process API request";
|
|
19
20
|
if (response.status === "err") {
|
|
@@ -41,27 +42,15 @@
|
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
super(message);
|
|
44
|
-
|
|
45
|
-
enumerable: true,
|
|
46
|
-
configurable: true,
|
|
47
|
-
writable: true,
|
|
48
|
-
value: response
|
|
49
|
-
});
|
|
45
|
+
this.response = response;
|
|
50
46
|
this.name = "ApiRequestError";
|
|
51
47
|
}
|
|
52
48
|
}
|
|
53
49
|
exports.ApiRequestError = ApiRequestError;
|
|
54
50
|
/** Nonce manager for generating unique nonces for signing transactions. */
|
|
55
51
|
class NonceManager {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
Object.defineProperty(this, "lastNonce", {
|
|
59
|
-
enumerable: true,
|
|
60
|
-
configurable: true,
|
|
61
|
-
writable: true,
|
|
62
|
-
value: 0
|
|
63
|
-
});
|
|
64
|
-
}
|
|
52
|
+
/** The last nonce used for signing transactions. */
|
|
53
|
+
lastNonce = 0;
|
|
65
54
|
/**
|
|
66
55
|
* Gets the next nonce for signing transactions.
|
|
67
56
|
* @returns The next nonce.
|
|
@@ -78,11 +67,18 @@
|
|
|
78
67
|
}
|
|
79
68
|
}
|
|
80
69
|
/**
|
|
81
|
-
*
|
|
70
|
+
* Exchange client for interacting with the Hyperliquid API.
|
|
82
71
|
* @typeParam T The transport used to connect to the Hyperliquid API.
|
|
83
72
|
* @typeParam W The WalletClient/Account ([viem](https://viem.sh/docs/clients/wallet)) or Signer ([ethers.js](https://docs.ethers.io/v6/api/providers/#Signer)) used for signing transactions.
|
|
84
73
|
*/
|
|
85
|
-
class
|
|
74
|
+
class ExchangeClient {
|
|
75
|
+
transport;
|
|
76
|
+
wallet;
|
|
77
|
+
isTestnet;
|
|
78
|
+
defaultVaultAddress;
|
|
79
|
+
defaultExpiresAfter;
|
|
80
|
+
signatureChainId;
|
|
81
|
+
nonceManager;
|
|
86
82
|
/**
|
|
87
83
|
* Initialises a new instance.
|
|
88
84
|
* @param args - The parameters for the client.
|
|
@@ -95,7 +91,7 @@
|
|
|
95
91
|
* const wallet = privateKeyToAccount("0x...");
|
|
96
92
|
*
|
|
97
93
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
98
|
-
* const
|
|
94
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
99
95
|
* ```
|
|
100
96
|
*
|
|
101
97
|
* @example Private key via [ethers.js](https://docs.ethers.org/v6/api/wallet/#Wallet) or [ethers.js v5](https://docs.ethers.org/v5/api/signer/#Wallet)
|
|
@@ -106,7 +102,7 @@
|
|
|
106
102
|
* const wallet = new ethers.Wallet("0x...");
|
|
107
103
|
*
|
|
108
104
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
109
|
-
* const
|
|
105
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
110
106
|
* ```
|
|
111
107
|
*
|
|
112
108
|
* @example External wallet (e.g. MetaMask) via [viem](https://viem.sh/docs/clients/wallet#optional-hoist-the-account)
|
|
@@ -118,7 +114,7 @@
|
|
|
118
114
|
* const wallet = createWalletClient({ account, transport: custom(window.ethereum) });
|
|
119
115
|
*
|
|
120
116
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
121
|
-
* const
|
|
117
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
122
118
|
* ```
|
|
123
119
|
*
|
|
124
120
|
* @example External wallet (e.g. MetaMask) via `window.ethereum` directly
|
|
@@ -126,62 +122,10 @@
|
|
|
126
122
|
* import * as hl from "@nktkas/hyperliquid";
|
|
127
123
|
*
|
|
128
124
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
129
|
-
* const
|
|
125
|
+
* const exchClient = new hl.ExchangeClient({ wallet: window.ethereum, transport });
|
|
130
126
|
* ```
|
|
131
127
|
*/
|
|
132
128
|
constructor(args) {
|
|
133
|
-
/** The transport used to connect to the Hyperliquid API. */
|
|
134
|
-
Object.defineProperty(this, "transport", {
|
|
135
|
-
enumerable: true,
|
|
136
|
-
configurable: true,
|
|
137
|
-
writable: true,
|
|
138
|
-
value: void 0
|
|
139
|
-
});
|
|
140
|
-
/** The `viem`, `ethers.js`, or `window.ethereum` wallet used for signing transactions. */
|
|
141
|
-
Object.defineProperty(this, "wallet", {
|
|
142
|
-
enumerable: true,
|
|
143
|
-
configurable: true,
|
|
144
|
-
writable: true,
|
|
145
|
-
value: void 0
|
|
146
|
-
});
|
|
147
|
-
/** Specifies whether the client uses testnet. */
|
|
148
|
-
Object.defineProperty(this, "isTestnet", {
|
|
149
|
-
enumerable: true,
|
|
150
|
-
configurable: true,
|
|
151
|
-
writable: true,
|
|
152
|
-
value: void 0
|
|
153
|
-
});
|
|
154
|
-
/** Sets a default vaultAddress to be used if no vaultAddress is explicitly passed to a method. */
|
|
155
|
-
Object.defineProperty(this, "defaultVaultAddress", {
|
|
156
|
-
enumerable: true,
|
|
157
|
-
configurable: true,
|
|
158
|
-
writable: true,
|
|
159
|
-
value: void 0
|
|
160
|
-
});
|
|
161
|
-
/** Sets a default expiresAfter to be used if no expiresAfter is explicitly passed to a method. */
|
|
162
|
-
Object.defineProperty(this, "defaultExpiresAfter", {
|
|
163
|
-
enumerable: true,
|
|
164
|
-
configurable: true,
|
|
165
|
-
writable: true,
|
|
166
|
-
value: void 0
|
|
167
|
-
});
|
|
168
|
-
/**
|
|
169
|
-
* The network that will be used to sign transactions.
|
|
170
|
-
* Must match the network of the {@link wallet}.
|
|
171
|
-
*/
|
|
172
|
-
Object.defineProperty(this, "signatureChainId", {
|
|
173
|
-
enumerable: true,
|
|
174
|
-
configurable: true,
|
|
175
|
-
writable: true,
|
|
176
|
-
value: void 0
|
|
177
|
-
});
|
|
178
|
-
/** Function to get the next nonce for signing transactions. */
|
|
179
|
-
Object.defineProperty(this, "nonceManager", {
|
|
180
|
-
enumerable: true,
|
|
181
|
-
configurable: true,
|
|
182
|
-
writable: true,
|
|
183
|
-
value: void 0
|
|
184
|
-
});
|
|
185
129
|
this.transport = args.transport;
|
|
186
130
|
this.wallet = args.wallet;
|
|
187
131
|
this.isTestnet = args.isTestnet ?? false;
|
|
@@ -205,7 +149,7 @@
|
|
|
205
149
|
*
|
|
206
150
|
* const wallet = privateKeyToAccount("0x...");
|
|
207
151
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
208
|
-
* const
|
|
152
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
209
153
|
*
|
|
210
154
|
* const result = await client.approveAgent({ agentAddress: "0x...", agentName: "agentName" });
|
|
211
155
|
* ```
|
|
@@ -237,11 +181,7 @@
|
|
|
237
181
|
if (action.agentName === "")
|
|
238
182
|
delete action.agentName;
|
|
239
183
|
// Send a request
|
|
240
|
-
|
|
241
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
242
|
-
// Validate a response
|
|
243
|
-
this._validateResponse(response);
|
|
244
|
-
return response;
|
|
184
|
+
return await this._request({ action, signature, nonce: action.nonce }, signal);
|
|
245
185
|
}
|
|
246
186
|
/**
|
|
247
187
|
* Approve a maximum fee rate for a builder.
|
|
@@ -258,7 +198,7 @@
|
|
|
258
198
|
*
|
|
259
199
|
* const wallet = privateKeyToAccount("0x...");
|
|
260
200
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
261
|
-
* const
|
|
201
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
262
202
|
*
|
|
263
203
|
* const result = await client.approveBuilderFee({ maxFeeRate: "0.01%", builder: "0x..." });
|
|
264
204
|
* ```
|
|
@@ -287,11 +227,7 @@
|
|
|
287
227
|
chainId: parseInt(action.signatureChainId, 16),
|
|
288
228
|
});
|
|
289
229
|
// Send a request
|
|
290
|
-
|
|
291
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
292
|
-
// Validate a response
|
|
293
|
-
this._validateResponse(response);
|
|
294
|
-
return response;
|
|
230
|
+
return await this._request({ action, signature, nonce: action.nonce }, signal);
|
|
295
231
|
}
|
|
296
232
|
/**
|
|
297
233
|
* Modify multiple orders.
|
|
@@ -308,7 +244,7 @@
|
|
|
308
244
|
*
|
|
309
245
|
* const wallet = privateKeyToAccount("0x...");
|
|
310
246
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
311
|
-
* const
|
|
247
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
312
248
|
*
|
|
313
249
|
* const result = await client.batchModify({
|
|
314
250
|
* modifies: [{
|
|
@@ -377,11 +313,7 @@
|
|
|
377
313
|
expiresAfter,
|
|
378
314
|
});
|
|
379
315
|
// Send a request
|
|
380
|
-
|
|
381
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
382
|
-
// Validate a response
|
|
383
|
-
this._validateResponse(response);
|
|
384
|
-
return response;
|
|
316
|
+
return await this._request({ action, signature, nonce, vaultAddress, expiresAfter }, signal);
|
|
385
317
|
}
|
|
386
318
|
/**
|
|
387
319
|
* Cancel order(s).
|
|
@@ -398,7 +330,7 @@
|
|
|
398
330
|
*
|
|
399
331
|
* const wallet = privateKeyToAccount("0x...");
|
|
400
332
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
401
|
-
* const
|
|
333
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
402
334
|
*
|
|
403
335
|
* const result = await client.cancel({
|
|
404
336
|
* cancels: [{
|
|
@@ -430,11 +362,7 @@
|
|
|
430
362
|
expiresAfter,
|
|
431
363
|
});
|
|
432
364
|
// Send a request
|
|
433
|
-
|
|
434
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
435
|
-
// Validate a response
|
|
436
|
-
this._validateResponse(response);
|
|
437
|
-
return response;
|
|
365
|
+
return await this._request({ action, signature, nonce, vaultAddress, expiresAfter }, signal);
|
|
438
366
|
}
|
|
439
367
|
/**
|
|
440
368
|
* Cancel order(s) by cloid.
|
|
@@ -451,7 +379,7 @@
|
|
|
451
379
|
*
|
|
452
380
|
* const wallet = privateKeyToAccount("0x...");
|
|
453
381
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
454
|
-
* const
|
|
382
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
455
383
|
*
|
|
456
384
|
* const result = await client.cancelByCloid({
|
|
457
385
|
* cancels: [
|
|
@@ -482,11 +410,7 @@
|
|
|
482
410
|
expiresAfter,
|
|
483
411
|
});
|
|
484
412
|
// Send a request
|
|
485
|
-
|
|
486
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
487
|
-
// Validate a response
|
|
488
|
-
this._validateResponse(response);
|
|
489
|
-
return response;
|
|
413
|
+
return await this._request({ action, signature, nonce, vaultAddress, expiresAfter }, signal);
|
|
490
414
|
}
|
|
491
415
|
/**
|
|
492
416
|
* Transfer native token from the user's spot account into staking for delegating to validators.
|
|
@@ -503,7 +427,7 @@
|
|
|
503
427
|
*
|
|
504
428
|
* const wallet = privateKeyToAccount("0x...");
|
|
505
429
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
506
|
-
* const
|
|
430
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
507
431
|
*
|
|
508
432
|
* const result = await client.cDeposit({ wei: 1 * 1e8 });
|
|
509
433
|
* ```
|
|
@@ -531,11 +455,7 @@
|
|
|
531
455
|
chainId: parseInt(action.signatureChainId, 16),
|
|
532
456
|
});
|
|
533
457
|
// Send a request
|
|
534
|
-
|
|
535
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
536
|
-
// Validate a response
|
|
537
|
-
this._validateResponse(response);
|
|
538
|
-
return response;
|
|
458
|
+
return await this._request({ action, signature, nonce: action.nonce }, signal);
|
|
539
459
|
}
|
|
540
460
|
/**
|
|
541
461
|
* Claim rewards from referral program.
|
|
@@ -552,7 +472,7 @@
|
|
|
552
472
|
*
|
|
553
473
|
* const wallet = privateKeyToAccount("0x...");
|
|
554
474
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
555
|
-
* const
|
|
475
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
556
476
|
*
|
|
557
477
|
* const result = await client.claimRewards();
|
|
558
478
|
* ```
|
|
@@ -569,11 +489,7 @@
|
|
|
569
489
|
isTestnet: this.isTestnet,
|
|
570
490
|
});
|
|
571
491
|
// Send a request
|
|
572
|
-
|
|
573
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
574
|
-
// Validate a response
|
|
575
|
-
this._validateResponse(response);
|
|
576
|
-
return response;
|
|
492
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
577
493
|
}
|
|
578
494
|
/**
|
|
579
495
|
* Convert a single-signature account to a multi-signature account.
|
|
@@ -590,7 +506,7 @@
|
|
|
590
506
|
*
|
|
591
507
|
* const wallet = privateKeyToAccount("0x...");
|
|
592
508
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
593
|
-
* const
|
|
509
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
594
510
|
*
|
|
595
511
|
* const result = await client.convertToMultiSigUser({
|
|
596
512
|
* authorizedUsers: ["0x...", "0x..."],
|
|
@@ -621,11 +537,7 @@
|
|
|
621
537
|
chainId: parseInt(action.signatureChainId, 16),
|
|
622
538
|
});
|
|
623
539
|
// Send a request
|
|
624
|
-
|
|
625
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
626
|
-
// Validate a response
|
|
627
|
-
this._validateResponse(response);
|
|
628
|
-
return response;
|
|
540
|
+
return await this._request({ action, signature, nonce: action.nonce }, signal);
|
|
629
541
|
}
|
|
630
542
|
/**
|
|
631
543
|
* Create a sub-account.
|
|
@@ -642,7 +554,7 @@
|
|
|
642
554
|
*
|
|
643
555
|
* const wallet = privateKeyToAccount("0x...");
|
|
644
556
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
645
|
-
* const
|
|
557
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
646
558
|
*
|
|
647
559
|
* const result = await client.createSubAccount({ name: "subAccountName" });
|
|
648
560
|
* ```
|
|
@@ -662,11 +574,7 @@
|
|
|
662
574
|
isTestnet: this.isTestnet,
|
|
663
575
|
});
|
|
664
576
|
// Send a request
|
|
665
|
-
|
|
666
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
667
|
-
// Validate a response
|
|
668
|
-
this._validateResponse(response);
|
|
669
|
-
return response;
|
|
577
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
670
578
|
}
|
|
671
579
|
/**
|
|
672
580
|
* Create a vault.
|
|
@@ -683,7 +591,7 @@
|
|
|
683
591
|
*
|
|
684
592
|
* const wallet = privateKeyToAccount("0x...");
|
|
685
593
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
686
|
-
* const
|
|
594
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
687
595
|
*
|
|
688
596
|
* const result = await client.createVault({
|
|
689
597
|
* name: "VaultName",
|
|
@@ -710,11 +618,7 @@
|
|
|
710
618
|
isTestnet: this.isTestnet,
|
|
711
619
|
});
|
|
712
620
|
// Send a request
|
|
713
|
-
|
|
714
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
715
|
-
// Validate a response
|
|
716
|
-
this._validateResponse(response);
|
|
717
|
-
return response;
|
|
621
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
718
622
|
}
|
|
719
623
|
async cSignerAction(args, signal) {
|
|
720
624
|
// Destructure the parameters
|
|
@@ -734,11 +638,7 @@
|
|
|
734
638
|
expiresAfter,
|
|
735
639
|
});
|
|
736
640
|
// Send a request
|
|
737
|
-
|
|
738
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
739
|
-
// Validate a response
|
|
740
|
-
this._validateResponse(response);
|
|
741
|
-
return response;
|
|
641
|
+
return await this._request({ action, signature, nonce, expiresAfter }, signal);
|
|
742
642
|
}
|
|
743
643
|
async cValidatorAction(args, signal) {
|
|
744
644
|
// Destructure the parameters
|
|
@@ -792,11 +692,7 @@
|
|
|
792
692
|
expiresAfter,
|
|
793
693
|
});
|
|
794
694
|
// Send a request
|
|
795
|
-
|
|
796
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
797
|
-
// Validate a response
|
|
798
|
-
this._validateResponse(response);
|
|
799
|
-
return response;
|
|
695
|
+
return await this._request({ action, signature, nonce, expiresAfter }, signal);
|
|
800
696
|
}
|
|
801
697
|
/**
|
|
802
698
|
* Transfer native token from staking into the user's spot account.
|
|
@@ -813,7 +709,7 @@
|
|
|
813
709
|
*
|
|
814
710
|
* const wallet = privateKeyToAccount("0x...");
|
|
815
711
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
816
|
-
* const
|
|
712
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
817
713
|
*
|
|
818
714
|
* const result = await client.cWithdraw({ wei: 1 * 1e8 });
|
|
819
715
|
* ```
|
|
@@ -841,11 +737,7 @@
|
|
|
841
737
|
chainId: parseInt(action.signatureChainId, 16),
|
|
842
738
|
});
|
|
843
739
|
// Send a request
|
|
844
|
-
|
|
845
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
846
|
-
// Validate a response
|
|
847
|
-
this._validateResponse(response);
|
|
848
|
-
return response;
|
|
740
|
+
return await this._request({ action, signature, nonce: action.nonce }, signal);
|
|
849
741
|
}
|
|
850
742
|
/**
|
|
851
743
|
* Configure block type for EVM transactions.
|
|
@@ -862,7 +754,7 @@
|
|
|
862
754
|
*
|
|
863
755
|
* const wallet = privateKeyToAccount("0x...");
|
|
864
756
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
865
|
-
* const
|
|
757
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
866
758
|
*
|
|
867
759
|
* const result = await client.evmUserModify({ usingBigBlocks: true });
|
|
868
760
|
* ```
|
|
@@ -882,11 +774,7 @@
|
|
|
882
774
|
isTestnet: this.isTestnet,
|
|
883
775
|
});
|
|
884
776
|
// Send a request
|
|
885
|
-
|
|
886
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
887
|
-
// Validate a response
|
|
888
|
-
this._validateResponse(response);
|
|
889
|
-
return response;
|
|
777
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
890
778
|
}
|
|
891
779
|
/**
|
|
892
780
|
* Modify an order.
|
|
@@ -903,7 +791,7 @@
|
|
|
903
791
|
*
|
|
904
792
|
* const wallet = privateKeyToAccount("0x...");
|
|
905
793
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
906
|
-
* const
|
|
794
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
907
795
|
*
|
|
908
796
|
* const result = await client.modify({
|
|
909
797
|
* oid: 123,
|
|
@@ -965,11 +853,7 @@
|
|
|
965
853
|
expiresAfter,
|
|
966
854
|
});
|
|
967
855
|
// Send a request
|
|
968
|
-
|
|
969
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
970
|
-
// Validate a response
|
|
971
|
-
this._validateResponse(response);
|
|
972
|
-
return response;
|
|
856
|
+
return await this._request({ action, signature, nonce, vaultAddress, expiresAfter }, signal);
|
|
973
857
|
}
|
|
974
858
|
/**
|
|
975
859
|
* A multi-signature request.
|
|
@@ -986,7 +870,7 @@
|
|
|
986
870
|
*
|
|
987
871
|
* const wallet = privateKeyToAccount("0x...");
|
|
988
872
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
989
|
-
* const
|
|
873
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
990
874
|
*
|
|
991
875
|
* const multiSigUser = "0x..."; // Multi-sig user address
|
|
992
876
|
*
|
|
@@ -1044,11 +928,7 @@
|
|
|
1044
928
|
signatureChainId: action.signatureChainId,
|
|
1045
929
|
});
|
|
1046
930
|
// Send a request
|
|
1047
|
-
|
|
1048
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
1049
|
-
// Validate a response
|
|
1050
|
-
this._validateResponse(response);
|
|
1051
|
-
return response;
|
|
931
|
+
return await this._request({ action, signature, nonce, vaultAddress, expiresAfter }, signal);
|
|
1052
932
|
}
|
|
1053
933
|
/**
|
|
1054
934
|
* Place an order(s).
|
|
@@ -1065,7 +945,7 @@
|
|
|
1065
945
|
*
|
|
1066
946
|
* const wallet = privateKeyToAccount("0x...");
|
|
1067
947
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1068
|
-
* const
|
|
948
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1069
949
|
*
|
|
1070
950
|
* const result = await client.order({
|
|
1071
951
|
* orders: [{
|
|
@@ -1138,11 +1018,7 @@
|
|
|
1138
1018
|
expiresAfter,
|
|
1139
1019
|
});
|
|
1140
1020
|
// Send a request
|
|
1141
|
-
|
|
1142
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
1143
|
-
// Validate a response
|
|
1144
|
-
this._validateResponse(response);
|
|
1145
|
-
return response;
|
|
1021
|
+
return await this._request({ action, signature, nonce, vaultAddress, expiresAfter }, signal);
|
|
1146
1022
|
}
|
|
1147
1023
|
async perpDeploy(args, signal) {
|
|
1148
1024
|
// Construct an action
|
|
@@ -1190,11 +1066,7 @@
|
|
|
1190
1066
|
isTestnet: this.isTestnet,
|
|
1191
1067
|
});
|
|
1192
1068
|
// Send a request
|
|
1193
|
-
|
|
1194
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
1195
|
-
// Validate a response
|
|
1196
|
-
this._validateResponse(response);
|
|
1197
|
-
return response;
|
|
1069
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
1198
1070
|
}
|
|
1199
1071
|
/**
|
|
1200
1072
|
* Transfer funds between Spot account and Perp dex account.
|
|
@@ -1211,7 +1083,7 @@
|
|
|
1211
1083
|
*
|
|
1212
1084
|
* const wallet = privateKeyToAccount("0x...");
|
|
1213
1085
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1214
|
-
* const
|
|
1086
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1215
1087
|
*
|
|
1216
1088
|
* const result = await client.perpDexClassTransfer({
|
|
1217
1089
|
* dex: "test",
|
|
@@ -1247,11 +1119,7 @@
|
|
|
1247
1119
|
chainId: parseInt(action.signatureChainId, 16),
|
|
1248
1120
|
});
|
|
1249
1121
|
// Send a request
|
|
1250
|
-
|
|
1251
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
1252
|
-
// Validate a response
|
|
1253
|
-
this._validateResponse(response);
|
|
1254
|
-
return response;
|
|
1122
|
+
return await this._request({ action, signature, nonce: action.nonce }, signal);
|
|
1255
1123
|
}
|
|
1256
1124
|
/**
|
|
1257
1125
|
* Create a referral code.
|
|
@@ -1268,7 +1136,7 @@
|
|
|
1268
1136
|
*
|
|
1269
1137
|
* const wallet = privateKeyToAccount("0x...");
|
|
1270
1138
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1271
|
-
* const
|
|
1139
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1272
1140
|
*
|
|
1273
1141
|
* const result = await client.registerReferrer({ code: "TEST" });
|
|
1274
1142
|
* ```
|
|
@@ -1288,11 +1156,7 @@
|
|
|
1288
1156
|
isTestnet: this.isTestnet,
|
|
1289
1157
|
});
|
|
1290
1158
|
// Send a request
|
|
1291
|
-
|
|
1292
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
1293
|
-
// Validate a response
|
|
1294
|
-
this._validateResponse(response);
|
|
1295
|
-
return response;
|
|
1159
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
1296
1160
|
}
|
|
1297
1161
|
/**
|
|
1298
1162
|
* Reserve additional rate-limited actions for a fee.
|
|
@@ -1309,7 +1173,7 @@
|
|
|
1309
1173
|
*
|
|
1310
1174
|
* const wallet = privateKeyToAccount("0x...");
|
|
1311
1175
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1312
|
-
* const
|
|
1176
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1313
1177
|
*
|
|
1314
1178
|
* const result = await client.reserveRequestWeight({ weight: 10 });
|
|
1315
1179
|
* ```
|
|
@@ -1332,11 +1196,7 @@
|
|
|
1332
1196
|
expiresAfter,
|
|
1333
1197
|
});
|
|
1334
1198
|
// Send a request
|
|
1335
|
-
|
|
1336
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
1337
|
-
// Validate a response
|
|
1338
|
-
this._validateResponse(response);
|
|
1339
|
-
return response;
|
|
1199
|
+
return await this._request({ action, signature, nonce, expiresAfter }, signal);
|
|
1340
1200
|
}
|
|
1341
1201
|
async scheduleCancel(args_or_signal, maybeSignal) {
|
|
1342
1202
|
const args = args_or_signal instanceof AbortSignal ? {} : args_or_signal ?? {};
|
|
@@ -1361,11 +1221,7 @@
|
|
|
1361
1221
|
expiresAfter,
|
|
1362
1222
|
});
|
|
1363
1223
|
// Send a request
|
|
1364
|
-
|
|
1365
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
1366
|
-
// Validate a response
|
|
1367
|
-
this._validateResponse(response);
|
|
1368
|
-
return response;
|
|
1224
|
+
return await this._request({ action, signature, nonce, vaultAddress, expiresAfter }, signal);
|
|
1369
1225
|
}
|
|
1370
1226
|
/**
|
|
1371
1227
|
* Set the display name in the leaderboard.
|
|
@@ -1382,7 +1238,7 @@
|
|
|
1382
1238
|
*
|
|
1383
1239
|
* const wallet = privateKeyToAccount("0x...");
|
|
1384
1240
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1385
|
-
* const
|
|
1241
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1386
1242
|
*
|
|
1387
1243
|
* const result = await client.setDisplayName({ displayName: "My Name" });
|
|
1388
1244
|
* ```
|
|
@@ -1402,11 +1258,7 @@
|
|
|
1402
1258
|
isTestnet: this.isTestnet,
|
|
1403
1259
|
});
|
|
1404
1260
|
// Send a request
|
|
1405
|
-
|
|
1406
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
1407
|
-
// Validate a response
|
|
1408
|
-
this._validateResponse(response);
|
|
1409
|
-
return response;
|
|
1261
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
1410
1262
|
}
|
|
1411
1263
|
/**
|
|
1412
1264
|
* Set a referral code.
|
|
@@ -1423,7 +1275,7 @@
|
|
|
1423
1275
|
*
|
|
1424
1276
|
* const wallet = privateKeyToAccount("0x...");
|
|
1425
1277
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1426
|
-
* const
|
|
1278
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1427
1279
|
*
|
|
1428
1280
|
* const result = await client.setReferrer({ code: "TEST" });
|
|
1429
1281
|
* ```
|
|
@@ -1443,11 +1295,7 @@
|
|
|
1443
1295
|
isTestnet: this.isTestnet,
|
|
1444
1296
|
});
|
|
1445
1297
|
// Send a request
|
|
1446
|
-
|
|
1447
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
1448
|
-
// Validate a response
|
|
1449
|
-
this._validateResponse(response);
|
|
1450
|
-
return response;
|
|
1298
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
1451
1299
|
}
|
|
1452
1300
|
async spotDeploy(args, signal) {
|
|
1453
1301
|
// Construct an action
|
|
@@ -1537,11 +1385,7 @@
|
|
|
1537
1385
|
isTestnet: this.isTestnet,
|
|
1538
1386
|
});
|
|
1539
1387
|
// Send a request
|
|
1540
|
-
|
|
1541
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
1542
|
-
// Validate a response
|
|
1543
|
-
this._validateResponse(response);
|
|
1544
|
-
return response;
|
|
1388
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
1545
1389
|
}
|
|
1546
1390
|
/**
|
|
1547
1391
|
* Send spot assets to another address.
|
|
@@ -1558,7 +1402,7 @@
|
|
|
1558
1402
|
*
|
|
1559
1403
|
* const wallet = privateKeyToAccount("0x...");
|
|
1560
1404
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1561
|
-
* const
|
|
1405
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1562
1406
|
*
|
|
1563
1407
|
* const result = await client.spotSend({
|
|
1564
1408
|
* destination: "0x...",
|
|
@@ -1592,11 +1436,7 @@
|
|
|
1592
1436
|
chainId: parseInt(action.signatureChainId, 16),
|
|
1593
1437
|
});
|
|
1594
1438
|
// Send a request
|
|
1595
|
-
|
|
1596
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
1597
|
-
// Validate a response
|
|
1598
|
-
this._validateResponse(response);
|
|
1599
|
-
return response;
|
|
1439
|
+
return await this._request({ action, signature, nonce: action.time }, signal);
|
|
1600
1440
|
}
|
|
1601
1441
|
/**
|
|
1602
1442
|
* Opt Out of Spot Dusting.
|
|
@@ -1613,7 +1453,7 @@
|
|
|
1613
1453
|
*
|
|
1614
1454
|
* const wallet = privateKeyToAccount("0x...");
|
|
1615
1455
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1616
|
-
* const
|
|
1456
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1617
1457
|
*
|
|
1618
1458
|
* const result = await client.spotUser({ toggleSpotDusting: { optOut: false } });
|
|
1619
1459
|
* ```
|
|
@@ -1635,11 +1475,7 @@
|
|
|
1635
1475
|
isTestnet: this.isTestnet,
|
|
1636
1476
|
});
|
|
1637
1477
|
// Send a request
|
|
1638
|
-
|
|
1639
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
1640
|
-
// Validate a response
|
|
1641
|
-
this._validateResponse(response);
|
|
1642
|
-
return response;
|
|
1478
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
1643
1479
|
}
|
|
1644
1480
|
/**
|
|
1645
1481
|
* Transfer between sub-accounts (spot).
|
|
@@ -1656,7 +1492,7 @@
|
|
|
1656
1492
|
*
|
|
1657
1493
|
* const wallet = privateKeyToAccount("0x...");
|
|
1658
1494
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1659
|
-
* const
|
|
1495
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1660
1496
|
*
|
|
1661
1497
|
* const result = await client.subAccountSpotTransfer({
|
|
1662
1498
|
* subAccountUser: "0x...",
|
|
@@ -1684,11 +1520,7 @@
|
|
|
1684
1520
|
isTestnet: this.isTestnet,
|
|
1685
1521
|
});
|
|
1686
1522
|
// Send a request
|
|
1687
|
-
|
|
1688
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
1689
|
-
// Validate a response
|
|
1690
|
-
this._validateResponse(response);
|
|
1691
|
-
return response;
|
|
1523
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
1692
1524
|
}
|
|
1693
1525
|
/**
|
|
1694
1526
|
* Transfer between sub-accounts (perpetual).
|
|
@@ -1705,7 +1537,7 @@
|
|
|
1705
1537
|
*
|
|
1706
1538
|
* const wallet = privateKeyToAccount("0x...");
|
|
1707
1539
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1708
|
-
* const
|
|
1540
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1709
1541
|
*
|
|
1710
1542
|
* const result = await client.subAccountTransfer({
|
|
1711
1543
|
* subAccountUser: "0x...",
|
|
@@ -1731,11 +1563,7 @@
|
|
|
1731
1563
|
isTestnet: this.isTestnet,
|
|
1732
1564
|
});
|
|
1733
1565
|
// Send a request
|
|
1734
|
-
|
|
1735
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
1736
|
-
// Validate a response
|
|
1737
|
-
this._validateResponse(response);
|
|
1738
|
-
return response;
|
|
1566
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
1739
1567
|
}
|
|
1740
1568
|
/**
|
|
1741
1569
|
* Delegate or undelegate native tokens to or from a validator.
|
|
@@ -1752,7 +1580,7 @@
|
|
|
1752
1580
|
*
|
|
1753
1581
|
* const wallet = privateKeyToAccount("0x...");
|
|
1754
1582
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1755
|
-
* const
|
|
1583
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1756
1584
|
*
|
|
1757
1585
|
* const result = await client.tokenDelegate({
|
|
1758
1586
|
* validator: "0x...",
|
|
@@ -1786,11 +1614,7 @@
|
|
|
1786
1614
|
chainId: parseInt(action.signatureChainId, 16),
|
|
1787
1615
|
});
|
|
1788
1616
|
// Send a request
|
|
1789
|
-
|
|
1790
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
1791
|
-
// Validate a response
|
|
1792
|
-
this._validateResponse(response);
|
|
1793
|
-
return response;
|
|
1617
|
+
return await this._request({ action, signature, nonce: action.nonce }, signal);
|
|
1794
1618
|
}
|
|
1795
1619
|
/**
|
|
1796
1620
|
* Cancel a TWAP order.
|
|
@@ -1807,7 +1631,7 @@
|
|
|
1807
1631
|
*
|
|
1808
1632
|
* const wallet = privateKeyToAccount("0x...");
|
|
1809
1633
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1810
|
-
* const
|
|
1634
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1811
1635
|
*
|
|
1812
1636
|
* const result = await client.twapCancel({
|
|
1813
1637
|
* a: 0, // Asset index
|
|
@@ -1835,11 +1659,7 @@
|
|
|
1835
1659
|
expiresAfter,
|
|
1836
1660
|
});
|
|
1837
1661
|
// Send a request
|
|
1838
|
-
|
|
1839
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
1840
|
-
// Validate a response
|
|
1841
|
-
this._validateResponse(response);
|
|
1842
|
-
return response;
|
|
1662
|
+
return await this._request({ action, signature, nonce, vaultAddress, expiresAfter }, signal);
|
|
1843
1663
|
}
|
|
1844
1664
|
/**
|
|
1845
1665
|
* Place a TWAP order.
|
|
@@ -1856,7 +1676,7 @@
|
|
|
1856
1676
|
*
|
|
1857
1677
|
* const wallet = privateKeyToAccount("0x...");
|
|
1858
1678
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1859
|
-
* const
|
|
1679
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1860
1680
|
*
|
|
1861
1681
|
* const result = await client.twapOrder({
|
|
1862
1682
|
* a: 0, // Asset index
|
|
@@ -1894,11 +1714,7 @@
|
|
|
1894
1714
|
expiresAfter,
|
|
1895
1715
|
});
|
|
1896
1716
|
// Send a request
|
|
1897
|
-
|
|
1898
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
1899
|
-
// Validate a response
|
|
1900
|
-
this._validateResponse(response);
|
|
1901
|
-
return response;
|
|
1717
|
+
return await this._request({ action, signature, nonce, vaultAddress, expiresAfter }, signal);
|
|
1902
1718
|
}
|
|
1903
1719
|
/**
|
|
1904
1720
|
* Add or remove margin from isolated position.
|
|
@@ -1915,7 +1731,7 @@
|
|
|
1915
1731
|
*
|
|
1916
1732
|
* const wallet = privateKeyToAccount("0x...");
|
|
1917
1733
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1918
|
-
* const
|
|
1734
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1919
1735
|
*
|
|
1920
1736
|
* const result = await client.updateIsolatedMargin({ asset: 0, isBuy: true, ntli: 1 * 1e6 });
|
|
1921
1737
|
* ```
|
|
@@ -1941,11 +1757,7 @@
|
|
|
1941
1757
|
expiresAfter,
|
|
1942
1758
|
});
|
|
1943
1759
|
// Send a request
|
|
1944
|
-
|
|
1945
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
1946
|
-
// Validate a response
|
|
1947
|
-
this._validateResponse(response);
|
|
1948
|
-
return response;
|
|
1760
|
+
return await this._request({ action, signature, nonce, vaultAddress, expiresAfter }, signal);
|
|
1949
1761
|
}
|
|
1950
1762
|
/**
|
|
1951
1763
|
* Update cross or isolated leverage on a coin.
|
|
@@ -1962,7 +1774,7 @@
|
|
|
1962
1774
|
*
|
|
1963
1775
|
* const wallet = privateKeyToAccount("0x...");
|
|
1964
1776
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1965
|
-
* const
|
|
1777
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1966
1778
|
*
|
|
1967
1779
|
* const result = await client.updateLeverage({ asset: 0, isCross: true, leverage: 5 });
|
|
1968
1780
|
* ```
|
|
@@ -1988,11 +1800,7 @@
|
|
|
1988
1800
|
expiresAfter,
|
|
1989
1801
|
});
|
|
1990
1802
|
// Send a request
|
|
1991
|
-
|
|
1992
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
1993
|
-
// Validate a response
|
|
1994
|
-
this._validateResponse(response);
|
|
1995
|
-
return response;
|
|
1803
|
+
return await this._request({ action, signature, nonce, vaultAddress, expiresAfter }, signal);
|
|
1996
1804
|
}
|
|
1997
1805
|
/**
|
|
1998
1806
|
* Transfer funds between Spot account and Perp account.
|
|
@@ -2009,7 +1817,7 @@
|
|
|
2009
1817
|
*
|
|
2010
1818
|
* const wallet = privateKeyToAccount("0x...");
|
|
2011
1819
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
2012
|
-
* const
|
|
1820
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
2013
1821
|
*
|
|
2014
1822
|
* const result = await client.usdClassTransfer({ amount: "1", toPerp: true });
|
|
2015
1823
|
* ```
|
|
@@ -2038,11 +1846,7 @@
|
|
|
2038
1846
|
chainId: parseInt(action.signatureChainId, 16),
|
|
2039
1847
|
});
|
|
2040
1848
|
// Send a request
|
|
2041
|
-
|
|
2042
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
2043
|
-
// Validate a response
|
|
2044
|
-
this._validateResponse(response);
|
|
2045
|
-
return response;
|
|
1849
|
+
return await this._request({ action, signature, nonce: action.nonce }, signal);
|
|
2046
1850
|
}
|
|
2047
1851
|
/**
|
|
2048
1852
|
* Send usd to another address.
|
|
@@ -2059,7 +1863,7 @@
|
|
|
2059
1863
|
*
|
|
2060
1864
|
* const wallet = privateKeyToAccount("0x...");
|
|
2061
1865
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
2062
|
-
* const
|
|
1866
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
2063
1867
|
*
|
|
2064
1868
|
* const result = await client.usdSend({ destination: "0x...", amount: "1" });
|
|
2065
1869
|
* ```
|
|
@@ -2088,11 +1892,7 @@
|
|
|
2088
1892
|
chainId: parseInt(action.signatureChainId, 16),
|
|
2089
1893
|
});
|
|
2090
1894
|
// Send a request
|
|
2091
|
-
|
|
2092
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
2093
|
-
// Validate a response
|
|
2094
|
-
this._validateResponse(response);
|
|
2095
|
-
return response;
|
|
1895
|
+
return await this._request({ action, signature, nonce: action.time }, signal);
|
|
2096
1896
|
}
|
|
2097
1897
|
/**
|
|
2098
1898
|
* Distribute funds from a vault between followers.
|
|
@@ -2109,7 +1909,7 @@
|
|
|
2109
1909
|
*
|
|
2110
1910
|
* const wallet = privateKeyToAccount("0x...");
|
|
2111
1911
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
2112
|
-
* const
|
|
1912
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
2113
1913
|
*
|
|
2114
1914
|
* const result = await client.vaultDistribute({ vaultAddress: "0x...", usd: 10 * 1e6 });
|
|
2115
1915
|
* ```
|
|
@@ -2130,11 +1930,7 @@
|
|
|
2130
1930
|
isTestnet: this.isTestnet,
|
|
2131
1931
|
});
|
|
2132
1932
|
// Send a request
|
|
2133
|
-
|
|
2134
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
2135
|
-
// Validate a response
|
|
2136
|
-
this._validateResponse(response);
|
|
2137
|
-
return response;
|
|
1933
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
2138
1934
|
}
|
|
2139
1935
|
/**
|
|
2140
1936
|
* Modify a vault's configuration.
|
|
@@ -2151,7 +1947,7 @@
|
|
|
2151
1947
|
*
|
|
2152
1948
|
* const wallet = privateKeyToAccount("0x...");
|
|
2153
1949
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
2154
|
-
* const
|
|
1950
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
2155
1951
|
*
|
|
2156
1952
|
* const result = await client.vaultModify({
|
|
2157
1953
|
* vaultAddress: "0x...",
|
|
@@ -2177,11 +1973,7 @@
|
|
|
2177
1973
|
isTestnet: this.isTestnet,
|
|
2178
1974
|
});
|
|
2179
1975
|
// Send a request
|
|
2180
|
-
|
|
2181
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
2182
|
-
// Validate a response
|
|
2183
|
-
this._validateResponse(response);
|
|
2184
|
-
return response;
|
|
1976
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
2185
1977
|
}
|
|
2186
1978
|
/**
|
|
2187
1979
|
* Deposit or withdraw from a vault.
|
|
@@ -2198,7 +1990,7 @@
|
|
|
2198
1990
|
*
|
|
2199
1991
|
* const wallet = privateKeyToAccount("0x...");
|
|
2200
1992
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
2201
|
-
* const
|
|
1993
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
2202
1994
|
*
|
|
2203
1995
|
* const result = await client.vaultTransfer({
|
|
2204
1996
|
* vaultAddress: "0x...",
|
|
@@ -2227,11 +2019,7 @@
|
|
|
2227
2019
|
expiresAfter,
|
|
2228
2020
|
});
|
|
2229
2021
|
// Send a request
|
|
2230
|
-
|
|
2231
|
-
const response = await this.transport.request("exchange", request, signal);
|
|
2232
|
-
// Validate a response
|
|
2233
|
-
this._validateResponse(response);
|
|
2234
|
-
return response;
|
|
2022
|
+
return await this._request({ action, signature, nonce, expiresAfter }, signal);
|
|
2235
2023
|
}
|
|
2236
2024
|
/**
|
|
2237
2025
|
* Initiate a withdrawal request.
|
|
@@ -2248,7 +2036,7 @@
|
|
|
2248
2036
|
*
|
|
2249
2037
|
* const wallet = privateKeyToAccount("0x...");
|
|
2250
2038
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
2251
|
-
* const
|
|
2039
|
+
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
2252
2040
|
*
|
|
2253
2041
|
* const result = await client.withdraw3({ destination: "0x...", amount: "1" });
|
|
2254
2042
|
* ```
|
|
@@ -2277,9 +2065,11 @@
|
|
|
2277
2065
|
chainId: parseInt(action.signatureChainId, 16),
|
|
2278
2066
|
});
|
|
2279
2067
|
// Send a request
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2068
|
+
return await this._request({ action, signature, nonce: action.time }, signal);
|
|
2069
|
+
}
|
|
2070
|
+
/** Send an API request and validate the response. */
|
|
2071
|
+
async _request(payload, signal) {
|
|
2072
|
+
const response = await this.transport.request("exchange", payload, signal);
|
|
2283
2073
|
this._validateResponse(response);
|
|
2284
2074
|
return response;
|
|
2285
2075
|
}
|
|
@@ -2350,5 +2140,5 @@
|
|
|
2350
2140
|
await this.transport[Symbol.asyncDispose]?.();
|
|
2351
2141
|
}
|
|
2352
2142
|
}
|
|
2353
|
-
exports.
|
|
2143
|
+
exports.ExchangeClient = ExchangeClient;
|
|
2354
2144
|
});
|