@nktkas/hyperliquid 0.21.0 → 0.22.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/CONTRIBUTING.md +19 -34
- package/README.md +212 -87
- package/esm/mod.d.ts +4 -3
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +3 -2
- package/esm/src/clients/exchange.d.ts +102 -59
- package/esm/src/clients/exchange.d.ts.map +1 -1
- package/esm/src/clients/exchange.js +233 -516
- package/esm/src/clients/info.d.ts +55 -55
- package/esm/src/clients/info.d.ts.map +1 -1
- package/esm/src/clients/info.js +57 -54
- package/esm/src/clients/multiSign.d.ts +1293 -0
- package/esm/src/clients/multiSign.d.ts.map +1 -0
- package/esm/src/clients/multiSign.js +2156 -0
- package/esm/src/clients/subscription.d.ts +19 -19
- package/esm/src/clients/subscription.d.ts.map +1 -1
- package/esm/src/clients/subscription.js +17 -17
- package/esm/src/signing.d.ts +164 -40
- package/esm/src/signing.d.ts.map +1 -1
- package/esm/src/signing.js +710 -9
- package/esm/src/types/exchange/requests.d.ts +240 -245
- package/esm/src/types/exchange/requests.d.ts.map +1 -1
- package/esm/src/types/info/accounts.d.ts +11 -0
- package/esm/src/types/info/accounts.d.ts.map +1 -1
- package/package.json +2 -1
- package/script/mod.d.ts +4 -3
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +4 -3
- package/script/src/clients/exchange.d.ts +102 -59
- package/script/src/clients/exchange.d.ts.map +1 -1
- package/script/src/clients/exchange.js +232 -515
- package/script/src/clients/info.d.ts +55 -55
- package/script/src/clients/info.d.ts.map +1 -1
- package/script/src/clients/info.js +57 -54
- package/script/src/clients/multiSign.d.ts +1293 -0
- package/script/src/clients/multiSign.d.ts.map +1 -0
- package/script/src/clients/multiSign.js +2170 -0
- package/script/src/clients/subscription.d.ts +19 -19
- package/script/src/clients/subscription.d.ts.map +1 -1
- package/script/src/clients/subscription.js +17 -17
- package/script/src/signing.d.ts +164 -40
- package/script/src/signing.d.ts.map +1 -1
- package/script/src/signing.js +711 -10
- package/script/src/types/exchange/requests.d.ts +240 -245
- package/script/src/types/exchange/requests.d.ts.map +1 -1
- package/script/src/types/info/accounts.d.ts +11 -0
- package/script/src/types/info/accounts.d.ts.map +1 -1
|
@@ -16,32 +16,32 @@
|
|
|
16
16
|
class ApiRequestError extends base_js_1.HyperliquidError {
|
|
17
17
|
response;
|
|
18
18
|
constructor(response) {
|
|
19
|
-
let message
|
|
19
|
+
let message;
|
|
20
20
|
if (response.status === "err") {
|
|
21
|
-
//
|
|
22
|
-
message
|
|
21
|
+
// ErrorResponse
|
|
22
|
+
message = response.response;
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
25
|
if ("statuses" in response.response.data) {
|
|
26
|
-
//
|
|
26
|
+
// OrderResponse | CancelResponse
|
|
27
27
|
const errors = response.response.data.statuses.reduce((acc, status, index) => {
|
|
28
28
|
if (typeof status === "object" && "error" in status) {
|
|
29
|
-
acc.push(`Order ${index}
|
|
29
|
+
acc.push(`Order ${index}: ${status.error}`);
|
|
30
30
|
}
|
|
31
31
|
return acc;
|
|
32
32
|
}, []);
|
|
33
33
|
if (errors.length > 0) {
|
|
34
|
-
message
|
|
34
|
+
message = errors.join(", ");
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
|
-
//
|
|
38
|
+
// TwapOrderResponse | TwapCancelResponse
|
|
39
39
|
if (typeof response.response.data.status === "object" && "error" in response.response.data.status) {
|
|
40
|
-
message
|
|
40
|
+
message = response.response.data.status.error;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
super(message);
|
|
44
|
+
super(message || "An unknown error occurred while processing an API request. See `response` for more details.");
|
|
45
45
|
this.response = response;
|
|
46
46
|
this.name = "ApiRequestError";
|
|
47
47
|
}
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
/**
|
|
70
70
|
* Exchange client for interacting with the Hyperliquid API.
|
|
71
71
|
* @typeParam T The transport used to connect to the Hyperliquid API.
|
|
72
|
-
* @typeParam W The
|
|
72
|
+
* @typeParam W The wallet used for signing transactions.
|
|
73
73
|
*/
|
|
74
74
|
class ExchangeClient {
|
|
75
75
|
transport;
|
|
@@ -151,37 +151,33 @@
|
|
|
151
151
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
152
152
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
153
153
|
*
|
|
154
|
-
* const
|
|
154
|
+
* const data = await exchClient.approveAgent({ agentAddress: "0x...", agentName: "agentName" });
|
|
155
155
|
* ```
|
|
156
156
|
*/
|
|
157
157
|
async approveAgent(args, signal) {
|
|
158
|
+
// Destructure the parameters
|
|
159
|
+
const { ...actionArgs } = args;
|
|
158
160
|
// Construct an action
|
|
161
|
+
const nonce = await this.nonceManager();
|
|
159
162
|
const action = {
|
|
160
|
-
...
|
|
163
|
+
...actionArgs,
|
|
161
164
|
agentName: args.agentName ?? "",
|
|
162
165
|
type: "approveAgent",
|
|
163
166
|
hyperliquidChain: this._getHyperliquidChain(),
|
|
164
167
|
signatureChainId: await this._getSignatureChainId(),
|
|
165
|
-
nonce
|
|
168
|
+
nonce,
|
|
166
169
|
};
|
|
167
170
|
// Sign the action
|
|
168
171
|
const signature = await (0, signing_js_1.signUserSignedAction)({
|
|
169
172
|
wallet: this.wallet,
|
|
170
173
|
action,
|
|
171
|
-
types:
|
|
172
|
-
"HyperliquidTransaction:ApproveAgent": [
|
|
173
|
-
{ name: "hyperliquidChain", type: "string" },
|
|
174
|
-
{ name: "agentAddress", type: "address" },
|
|
175
|
-
{ name: "agentName", type: "string" },
|
|
176
|
-
{ name: "nonce", type: "uint64" },
|
|
177
|
-
],
|
|
178
|
-
},
|
|
174
|
+
types: signing_js_1.userSignedActionEip712Types[action.type],
|
|
179
175
|
chainId: parseInt(action.signatureChainId, 16),
|
|
180
176
|
});
|
|
181
177
|
if (action.agentName === "")
|
|
182
178
|
delete action.agentName;
|
|
183
179
|
// Send a request
|
|
184
|
-
return await this._request({ action, signature, nonce
|
|
180
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
185
181
|
}
|
|
186
182
|
/**
|
|
187
183
|
* Approve a maximum fee rate for a builder.
|
|
@@ -200,34 +196,30 @@
|
|
|
200
196
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
201
197
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
202
198
|
*
|
|
203
|
-
* const
|
|
199
|
+
* const data = await exchClient.approveBuilderFee({ maxFeeRate: "0.01%", builder: "0x..." });
|
|
204
200
|
* ```
|
|
205
201
|
*/
|
|
206
202
|
async approveBuilderFee(args, signal) {
|
|
203
|
+
// Destructure the parameters
|
|
204
|
+
const { ...actionArgs } = args;
|
|
207
205
|
// Construct an action
|
|
206
|
+
const nonce = await this.nonceManager();
|
|
208
207
|
const action = {
|
|
209
|
-
...
|
|
208
|
+
...actionArgs,
|
|
210
209
|
type: "approveBuilderFee",
|
|
211
210
|
hyperliquidChain: this._getHyperliquidChain(),
|
|
212
211
|
signatureChainId: await this._getSignatureChainId(),
|
|
213
|
-
nonce
|
|
212
|
+
nonce,
|
|
214
213
|
};
|
|
215
214
|
// Sign the action
|
|
216
215
|
const signature = await (0, signing_js_1.signUserSignedAction)({
|
|
217
216
|
wallet: this.wallet,
|
|
218
217
|
action,
|
|
219
|
-
types:
|
|
220
|
-
"HyperliquidTransaction:ApproveBuilderFee": [
|
|
221
|
-
{ name: "hyperliquidChain", type: "string" },
|
|
222
|
-
{ name: "maxFeeRate", type: "string" },
|
|
223
|
-
{ name: "builder", type: "address" },
|
|
224
|
-
{ name: "nonce", type: "uint64" },
|
|
225
|
-
],
|
|
226
|
-
},
|
|
218
|
+
types: signing_js_1.userSignedActionEip712Types[action.type],
|
|
227
219
|
chainId: parseInt(action.signatureChainId, 16),
|
|
228
220
|
});
|
|
229
221
|
// Send a request
|
|
230
|
-
return await this._request({ action, signature, nonce
|
|
222
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
231
223
|
}
|
|
232
224
|
/**
|
|
233
225
|
* Modify multiple orders.
|
|
@@ -246,7 +238,7 @@
|
|
|
246
238
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
247
239
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
248
240
|
*
|
|
249
|
-
* const
|
|
241
|
+
* const data = await exchClient.batchModify({
|
|
250
242
|
* modifies: [{
|
|
251
243
|
* oid: 123,
|
|
252
244
|
* order: {
|
|
@@ -260,7 +252,7 @@
|
|
|
260
252
|
* tif: "Gtc", // Good-til-cancelled
|
|
261
253
|
* },
|
|
262
254
|
* },
|
|
263
|
-
* c: "0x...", //
|
|
255
|
+
* c: "0x...", // Client Order ID (optional)
|
|
264
256
|
* },
|
|
265
257
|
* }],
|
|
266
258
|
* });
|
|
@@ -273,40 +265,12 @@
|
|
|
273
265
|
const nonce = await this.nonceManager();
|
|
274
266
|
const action = {
|
|
275
267
|
type: "batchModify",
|
|
276
|
-
|
|
277
|
-
const sortedModify = {
|
|
278
|
-
oid: modify.oid,
|
|
279
|
-
order: {
|
|
280
|
-
a: modify.order.a,
|
|
281
|
-
b: modify.order.b,
|
|
282
|
-
p: this._formatDecimal(modify.order.p),
|
|
283
|
-
s: this._formatDecimal(modify.order.s),
|
|
284
|
-
r: modify.order.r,
|
|
285
|
-
t: "limit" in modify.order.t
|
|
286
|
-
? {
|
|
287
|
-
limit: {
|
|
288
|
-
tif: modify.order.t.limit.tif,
|
|
289
|
-
},
|
|
290
|
-
}
|
|
291
|
-
: {
|
|
292
|
-
trigger: {
|
|
293
|
-
isMarket: modify.order.t.trigger.isMarket,
|
|
294
|
-
triggerPx: this._formatDecimal(modify.order.t.trigger.triggerPx),
|
|
295
|
-
tpsl: modify.order.t.trigger.tpsl,
|
|
296
|
-
},
|
|
297
|
-
},
|
|
298
|
-
c: modify.order.c,
|
|
299
|
-
},
|
|
300
|
-
};
|
|
301
|
-
if (sortedModify.order.c === undefined)
|
|
302
|
-
delete sortedModify.order.c;
|
|
303
|
-
return sortedModify;
|
|
304
|
-
}),
|
|
268
|
+
...actionArgs,
|
|
305
269
|
};
|
|
306
270
|
// Sign the action
|
|
307
271
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
308
272
|
wallet: this.wallet,
|
|
309
|
-
action,
|
|
273
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
310
274
|
nonce,
|
|
311
275
|
isTestnet: this.isTestnet,
|
|
312
276
|
vaultAddress,
|
|
@@ -332,7 +296,7 @@
|
|
|
332
296
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
333
297
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
334
298
|
*
|
|
335
|
-
* const
|
|
299
|
+
* const data = await exchClient.cancel({
|
|
336
300
|
* cancels: [{
|
|
337
301
|
* a: 0, // Asset index
|
|
338
302
|
* o: 123, // Order ID
|
|
@@ -347,15 +311,12 @@
|
|
|
347
311
|
const nonce = await this.nonceManager();
|
|
348
312
|
const action = {
|
|
349
313
|
type: "cancel",
|
|
350
|
-
|
|
351
|
-
a: cancel.a,
|
|
352
|
-
o: cancel.o,
|
|
353
|
-
})),
|
|
314
|
+
...actionArgs,
|
|
354
315
|
};
|
|
355
316
|
// Sign the action
|
|
356
317
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
357
318
|
wallet: this.wallet,
|
|
358
|
-
action,
|
|
319
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
359
320
|
nonce,
|
|
360
321
|
isTestnet: this.isTestnet,
|
|
361
322
|
vaultAddress,
|
|
@@ -381,7 +342,7 @@
|
|
|
381
342
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
382
343
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
383
344
|
*
|
|
384
|
-
* const
|
|
345
|
+
* const data = await exchClient.cancelByCloid({
|
|
385
346
|
* cancels: [
|
|
386
347
|
* { asset: 0, cloid: "0x..." },
|
|
387
348
|
* ],
|
|
@@ -395,15 +356,12 @@
|
|
|
395
356
|
const nonce = await this.nonceManager();
|
|
396
357
|
const action = {
|
|
397
358
|
type: "cancelByCloid",
|
|
398
|
-
|
|
399
|
-
asset: cancel.asset,
|
|
400
|
-
cloid: cancel.cloid,
|
|
401
|
-
})),
|
|
359
|
+
...actionArgs,
|
|
402
360
|
};
|
|
403
361
|
// Sign the action
|
|
404
362
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
405
363
|
wallet: this.wallet,
|
|
406
|
-
action,
|
|
364
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
407
365
|
nonce,
|
|
408
366
|
isTestnet: this.isTestnet,
|
|
409
367
|
vaultAddress,
|
|
@@ -429,33 +387,30 @@
|
|
|
429
387
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
430
388
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
431
389
|
*
|
|
432
|
-
* const
|
|
390
|
+
* const data = await exchClient.cDeposit({ wei: 1 * 1e8 });
|
|
433
391
|
* ```
|
|
434
392
|
*/
|
|
435
393
|
async cDeposit(args, signal) {
|
|
394
|
+
// Destructure the parameters
|
|
395
|
+
const { ...actionArgs } = args;
|
|
436
396
|
// Construct an action
|
|
397
|
+
const nonce = await this.nonceManager();
|
|
437
398
|
const action = {
|
|
438
|
-
...
|
|
399
|
+
...actionArgs,
|
|
439
400
|
type: "cDeposit",
|
|
440
401
|
hyperliquidChain: this._getHyperliquidChain(),
|
|
441
402
|
signatureChainId: await this._getSignatureChainId(),
|
|
442
|
-
nonce
|
|
403
|
+
nonce,
|
|
443
404
|
};
|
|
444
405
|
// Sign the action
|
|
445
406
|
const signature = await (0, signing_js_1.signUserSignedAction)({
|
|
446
407
|
wallet: this.wallet,
|
|
447
408
|
action,
|
|
448
|
-
types:
|
|
449
|
-
"HyperliquidTransaction:CDeposit": [
|
|
450
|
-
{ name: "hyperliquidChain", type: "string" },
|
|
451
|
-
{ name: "wei", type: "uint64" },
|
|
452
|
-
{ name: "nonce", type: "uint64" },
|
|
453
|
-
],
|
|
454
|
-
},
|
|
409
|
+
types: signing_js_1.userSignedActionEip712Types[action.type],
|
|
455
410
|
chainId: parseInt(action.signatureChainId, 16),
|
|
456
411
|
});
|
|
457
412
|
// Send a request
|
|
458
|
-
return await this._request({ action, signature, nonce
|
|
413
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
459
414
|
}
|
|
460
415
|
/**
|
|
461
416
|
* Claim rewards from referral program.
|
|
@@ -474,17 +429,19 @@
|
|
|
474
429
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
475
430
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
476
431
|
*
|
|
477
|
-
* const
|
|
432
|
+
* const data = await exchClient.claimRewards();
|
|
478
433
|
* ```
|
|
479
434
|
*/
|
|
480
435
|
async claimRewards(signal) {
|
|
481
436
|
// Construct an action
|
|
482
437
|
const nonce = await this.nonceManager();
|
|
483
|
-
const action = {
|
|
438
|
+
const action = {
|
|
439
|
+
type: "claimRewards",
|
|
440
|
+
};
|
|
484
441
|
// Sign the action
|
|
485
442
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
486
443
|
wallet: this.wallet,
|
|
487
|
-
action,
|
|
444
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
488
445
|
nonce,
|
|
489
446
|
isTestnet: this.isTestnet,
|
|
490
447
|
});
|
|
@@ -492,7 +449,7 @@
|
|
|
492
449
|
return await this._request({ action, signature, nonce }, signal);
|
|
493
450
|
}
|
|
494
451
|
/**
|
|
495
|
-
* Convert a single-signature account to a multi-signature account.
|
|
452
|
+
* Convert a single-signature account to a multi-signature account or vice versa.
|
|
496
453
|
* @param args - The parameters for the request.
|
|
497
454
|
* @param signal - An optional abort signal.
|
|
498
455
|
* @returns Successful response without specific data.
|
|
@@ -508,36 +465,33 @@
|
|
|
508
465
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
509
466
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
510
467
|
*
|
|
511
|
-
* const
|
|
512
|
-
* authorizedUsers: ["0x...", "0x..."],
|
|
468
|
+
* const data = await exchClient.convertToMultiSigUser({ // convert to multi-sig user
|
|
469
|
+
* authorizedUsers: ["0x...", "0x...", "0x..."],
|
|
513
470
|
* threshold: 2,
|
|
514
471
|
* });
|
|
515
472
|
* ```
|
|
516
473
|
*/
|
|
517
474
|
async convertToMultiSigUser(args, signal) {
|
|
475
|
+
// Destructure the parameters
|
|
476
|
+
const { ...actionArgs } = args;
|
|
518
477
|
// Construct an action
|
|
478
|
+
const nonce = await this.nonceManager();
|
|
519
479
|
const action = {
|
|
520
480
|
type: "convertToMultiSigUser",
|
|
521
481
|
hyperliquidChain: this._getHyperliquidChain(),
|
|
522
482
|
signatureChainId: await this._getSignatureChainId(),
|
|
523
|
-
signers: JSON.stringify(
|
|
524
|
-
nonce
|
|
483
|
+
signers: JSON.stringify(actionArgs),
|
|
484
|
+
nonce,
|
|
525
485
|
};
|
|
526
486
|
// Sign the action
|
|
527
487
|
const signature = await (0, signing_js_1.signUserSignedAction)({
|
|
528
488
|
wallet: this.wallet,
|
|
529
489
|
action,
|
|
530
|
-
types:
|
|
531
|
-
"HyperliquidTransaction:ConvertToMultiSigUser": [
|
|
532
|
-
{ name: "hyperliquidChain", type: "string" },
|
|
533
|
-
{ name: "signers", type: "string" },
|
|
534
|
-
{ name: "nonce", type: "uint64" },
|
|
535
|
-
],
|
|
536
|
-
},
|
|
490
|
+
types: signing_js_1.userSignedActionEip712Types[action.type],
|
|
537
491
|
chainId: parseInt(action.signatureChainId, 16),
|
|
538
492
|
});
|
|
539
493
|
// Send a request
|
|
540
|
-
return await this._request({ action, signature, nonce
|
|
494
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
541
495
|
}
|
|
542
496
|
/**
|
|
543
497
|
* Create a sub-account.
|
|
@@ -556,20 +510,22 @@
|
|
|
556
510
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
557
511
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
558
512
|
*
|
|
559
|
-
* const
|
|
513
|
+
* const data = await exchClient.createSubAccount({ name: "subAccountName" });
|
|
560
514
|
* ```
|
|
561
515
|
*/
|
|
562
516
|
async createSubAccount(args, signal) {
|
|
517
|
+
// Destructure the parameters
|
|
518
|
+
const { ...actionArgs } = args;
|
|
563
519
|
// Construct an action
|
|
564
520
|
const nonce = await this.nonceManager();
|
|
565
521
|
const action = {
|
|
566
522
|
type: "createSubAccount",
|
|
567
|
-
|
|
523
|
+
...actionArgs,
|
|
568
524
|
};
|
|
569
525
|
// Sign the action
|
|
570
526
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
571
527
|
wallet: this.wallet,
|
|
572
|
-
action,
|
|
528
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
573
529
|
nonce,
|
|
574
530
|
isTestnet: this.isTestnet,
|
|
575
531
|
});
|
|
@@ -593,27 +549,27 @@
|
|
|
593
549
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
594
550
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
595
551
|
*
|
|
596
|
-
* const
|
|
552
|
+
* const data = await exchClient.createVault({
|
|
597
553
|
* name: "VaultName",
|
|
598
|
-
* description: "
|
|
554
|
+
* description: "Vault description",
|
|
599
555
|
* initialUsd: 100 * 1e6,
|
|
600
556
|
* });
|
|
601
557
|
* ```
|
|
602
558
|
*/
|
|
603
559
|
async createVault(args, signal) {
|
|
560
|
+
// Destructure the parameters
|
|
561
|
+
const { ...actionArgs } = args;
|
|
604
562
|
// Construct an action
|
|
605
563
|
const nonce = await this.nonceManager();
|
|
606
564
|
const action = {
|
|
607
565
|
type: "createVault",
|
|
608
|
-
name: args.name,
|
|
609
|
-
description: args.description,
|
|
610
|
-
initialUsd: args.initialUsd,
|
|
611
566
|
nonce,
|
|
567
|
+
...actionArgs,
|
|
612
568
|
};
|
|
613
569
|
// Sign the action
|
|
614
570
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
615
571
|
wallet: this.wallet,
|
|
616
|
-
action,
|
|
572
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
617
573
|
nonce,
|
|
618
574
|
isTestnet: this.isTestnet,
|
|
619
575
|
});
|
|
@@ -632,7 +588,7 @@
|
|
|
632
588
|
// Sign the action
|
|
633
589
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
634
590
|
wallet: this.wallet,
|
|
635
|
-
action,
|
|
591
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
636
592
|
nonce,
|
|
637
593
|
isTestnet: this.isTestnet,
|
|
638
594
|
expiresAfter,
|
|
@@ -645,48 +601,14 @@
|
|
|
645
601
|
const { expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
|
|
646
602
|
// Construct an action
|
|
647
603
|
const nonce = await this.nonceManager();
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
changeProfile: {
|
|
653
|
-
node_ip: actionArgs.changeProfile.node_ip ?? null,
|
|
654
|
-
name: actionArgs.changeProfile.name ?? null,
|
|
655
|
-
description: actionArgs.changeProfile.description ?? null,
|
|
656
|
-
unjailed: actionArgs.changeProfile.unjailed,
|
|
657
|
-
disable_delegations: actionArgs.changeProfile.disable_delegations ?? null,
|
|
658
|
-
commission_bps: actionArgs.changeProfile.commission_bps ?? null,
|
|
659
|
-
signer: actionArgs.changeProfile.signer?.toLowerCase() ?? null,
|
|
660
|
-
},
|
|
661
|
-
};
|
|
662
|
-
}
|
|
663
|
-
else if ("register" in actionArgs) {
|
|
664
|
-
action = {
|
|
665
|
-
type: "CValidatorAction",
|
|
666
|
-
register: {
|
|
667
|
-
profile: {
|
|
668
|
-
node_ip: { Ip: actionArgs.register.profile.node_ip.Ip },
|
|
669
|
-
name: actionArgs.register.profile.name,
|
|
670
|
-
description: actionArgs.register.profile.description,
|
|
671
|
-
delegations_disabled: actionArgs.register.profile.delegations_disabled,
|
|
672
|
-
commission_bps: actionArgs.register.profile.commission_bps,
|
|
673
|
-
signer: actionArgs.register.profile.signer?.toLowerCase(),
|
|
674
|
-
},
|
|
675
|
-
unjailed: actionArgs.register.unjailed,
|
|
676
|
-
initial_wei: actionArgs.register.initial_wei,
|
|
677
|
-
},
|
|
678
|
-
};
|
|
679
|
-
}
|
|
680
|
-
else {
|
|
681
|
-
action = {
|
|
682
|
-
type: "CValidatorAction",
|
|
683
|
-
unregister: actionArgs.unregister,
|
|
684
|
-
};
|
|
685
|
-
}
|
|
604
|
+
const action = {
|
|
605
|
+
type: "CValidatorAction",
|
|
606
|
+
...actionArgs,
|
|
607
|
+
};
|
|
686
608
|
// Sign the action
|
|
687
609
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
688
610
|
wallet: this.wallet,
|
|
689
|
-
action,
|
|
611
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
690
612
|
nonce,
|
|
691
613
|
isTestnet: this.isTestnet,
|
|
692
614
|
expiresAfter,
|
|
@@ -711,33 +633,30 @@
|
|
|
711
633
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
712
634
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
713
635
|
*
|
|
714
|
-
* const
|
|
636
|
+
* const data = await exchClient.cWithdraw({ wei: 1 * 1e8 });
|
|
715
637
|
* ```
|
|
716
638
|
*/
|
|
717
639
|
async cWithdraw(args, signal) {
|
|
640
|
+
// Destructure the parameters
|
|
641
|
+
const { ...actionArgs } = args;
|
|
718
642
|
// Construct an action
|
|
643
|
+
const nonce = await this.nonceManager();
|
|
719
644
|
const action = {
|
|
720
|
-
...
|
|
645
|
+
...actionArgs,
|
|
721
646
|
type: "cWithdraw",
|
|
722
647
|
hyperliquidChain: this._getHyperliquidChain(),
|
|
723
648
|
signatureChainId: await this._getSignatureChainId(),
|
|
724
|
-
nonce
|
|
649
|
+
nonce,
|
|
725
650
|
};
|
|
726
651
|
// Sign the action
|
|
727
652
|
const signature = await (0, signing_js_1.signUserSignedAction)({
|
|
728
653
|
wallet: this.wallet,
|
|
729
654
|
action,
|
|
730
|
-
types:
|
|
731
|
-
"HyperliquidTransaction:CWithdraw": [
|
|
732
|
-
{ name: "hyperliquidChain", type: "string" },
|
|
733
|
-
{ name: "wei", type: "uint64" },
|
|
734
|
-
{ name: "nonce", type: "uint64" },
|
|
735
|
-
],
|
|
736
|
-
},
|
|
655
|
+
types: signing_js_1.userSignedActionEip712Types[action.type],
|
|
737
656
|
chainId: parseInt(action.signatureChainId, 16),
|
|
738
657
|
});
|
|
739
658
|
// Send a request
|
|
740
|
-
return await this._request({ action, signature, nonce
|
|
659
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
741
660
|
}
|
|
742
661
|
/**
|
|
743
662
|
* Configure block type for EVM transactions.
|
|
@@ -756,20 +675,22 @@
|
|
|
756
675
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
757
676
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
758
677
|
*
|
|
759
|
-
* const
|
|
678
|
+
* const data = await exchClient.evmUserModify({ usingBigBlocks: true });
|
|
760
679
|
* ```
|
|
761
680
|
*/
|
|
762
681
|
async evmUserModify(args, signal) {
|
|
682
|
+
// Destructure the parameters
|
|
683
|
+
const { ...actionArgs } = args;
|
|
763
684
|
// Construct an action
|
|
764
685
|
const nonce = await this.nonceManager();
|
|
765
686
|
const action = {
|
|
766
687
|
type: "evmUserModify",
|
|
767
|
-
|
|
688
|
+
...actionArgs,
|
|
768
689
|
};
|
|
769
690
|
// Sign the action
|
|
770
691
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
771
692
|
wallet: this.wallet,
|
|
772
|
-
action,
|
|
693
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
773
694
|
nonce,
|
|
774
695
|
isTestnet: this.isTestnet,
|
|
775
696
|
});
|
|
@@ -793,7 +714,7 @@
|
|
|
793
714
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
794
715
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
795
716
|
*
|
|
796
|
-
* const
|
|
717
|
+
* const data = await exchClient.modify({
|
|
797
718
|
* oid: 123,
|
|
798
719
|
* order: {
|
|
799
720
|
* a: 0, // Asset index
|
|
@@ -806,7 +727,7 @@
|
|
|
806
727
|
* tif: "Gtc", // Good-til-cancelled
|
|
807
728
|
* },
|
|
808
729
|
* },
|
|
809
|
-
* c: "0x...", //
|
|
730
|
+
* c: "0x...", // Client Order ID (optional)
|
|
810
731
|
* },
|
|
811
732
|
* });
|
|
812
733
|
* ```
|
|
@@ -818,35 +739,12 @@
|
|
|
818
739
|
const nonce = await this.nonceManager();
|
|
819
740
|
const action = {
|
|
820
741
|
type: "modify",
|
|
821
|
-
|
|
822
|
-
order: {
|
|
823
|
-
a: actionArgs.order.a,
|
|
824
|
-
b: actionArgs.order.b,
|
|
825
|
-
p: this._formatDecimal(actionArgs.order.p),
|
|
826
|
-
s: this._formatDecimal(actionArgs.order.s),
|
|
827
|
-
r: actionArgs.order.r,
|
|
828
|
-
t: "limit" in actionArgs.order.t
|
|
829
|
-
? {
|
|
830
|
-
limit: {
|
|
831
|
-
tif: actionArgs.order.t.limit.tif,
|
|
832
|
-
},
|
|
833
|
-
}
|
|
834
|
-
: {
|
|
835
|
-
trigger: {
|
|
836
|
-
isMarket: actionArgs.order.t.trigger.isMarket,
|
|
837
|
-
triggerPx: this._formatDecimal(actionArgs.order.t.trigger.triggerPx),
|
|
838
|
-
tpsl: actionArgs.order.t.trigger.tpsl,
|
|
839
|
-
},
|
|
840
|
-
},
|
|
841
|
-
c: actionArgs.order.c,
|
|
842
|
-
},
|
|
742
|
+
...actionArgs,
|
|
843
743
|
};
|
|
844
|
-
if (action.order.c === undefined)
|
|
845
|
-
delete action.order.c;
|
|
846
744
|
// Sign the action
|
|
847
745
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
848
746
|
wallet: this.wallet,
|
|
849
|
-
action,
|
|
747
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
850
748
|
nonce,
|
|
851
749
|
isTestnet: this.isTestnet,
|
|
852
750
|
vaultAddress,
|
|
@@ -884,7 +782,7 @@
|
|
|
884
782
|
* isTestnet: true,
|
|
885
783
|
* });
|
|
886
784
|
*
|
|
887
|
-
* const
|
|
785
|
+
* const data = await exchClient.multiSig({
|
|
888
786
|
* signatures: [signature],
|
|
889
787
|
* payload: {
|
|
890
788
|
* multiSigUser,
|
|
@@ -894,29 +792,18 @@
|
|
|
894
792
|
* nonce,
|
|
895
793
|
* });
|
|
896
794
|
* ```
|
|
897
|
-
* @unstable May not behave as expected and the interface may change in the future.
|
|
898
795
|
*/
|
|
899
796
|
async multiSig(args, signal) {
|
|
900
797
|
// Destructure the parameters
|
|
901
798
|
const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), nonce, ...actionArgs } = args;
|
|
902
799
|
// Construct an action
|
|
903
|
-
const hyperliquidChain = this._getHyperliquidChain();
|
|
904
800
|
const action = {
|
|
905
801
|
type: "multiSig",
|
|
906
802
|
signatureChainId: await this._getSignatureChainId(),
|
|
907
|
-
|
|
908
|
-
r: signature.r.replace(/^0x0+/, "0x").toLowerCase(),
|
|
909
|
-
s: signature.s.replace(/^0x0+/, "0x").toLowerCase(),
|
|
910
|
-
v: signature.v,
|
|
911
|
-
})),
|
|
912
|
-
payload: {
|
|
913
|
-
multiSigUser: actionArgs.payload.multiSigUser.toLowerCase(),
|
|
914
|
-
outerSigner: actionArgs.payload.outerSigner.toLowerCase(),
|
|
915
|
-
action: actionArgs.payload.action,
|
|
916
|
-
},
|
|
803
|
+
...actionArgs,
|
|
917
804
|
};
|
|
918
805
|
// Sign the action
|
|
919
|
-
const actionForMultiSig =
|
|
806
|
+
const actionForMultiSig = signing_js_1.actionSorter[action.type](action);
|
|
920
807
|
delete actionForMultiSig.type;
|
|
921
808
|
const signature = await (0, signing_js_1.signMultiSigAction)({
|
|
922
809
|
wallet: this.wallet,
|
|
@@ -924,7 +811,7 @@
|
|
|
924
811
|
nonce,
|
|
925
812
|
vaultAddress,
|
|
926
813
|
expiresAfter,
|
|
927
|
-
hyperliquidChain,
|
|
814
|
+
hyperliquidChain: this._getHyperliquidChain(),
|
|
928
815
|
signatureChainId: action.signatureChainId,
|
|
929
816
|
});
|
|
930
817
|
// Send a request
|
|
@@ -947,7 +834,7 @@
|
|
|
947
834
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
948
835
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
949
836
|
*
|
|
950
|
-
* const
|
|
837
|
+
* const data = await exchClient.order({
|
|
951
838
|
* orders: [{
|
|
952
839
|
* a: 0, // Asset index
|
|
953
840
|
* b: true, // Buy order
|
|
@@ -959,7 +846,7 @@
|
|
|
959
846
|
* tif: "Gtc", // Good-til-cancelled
|
|
960
847
|
* },
|
|
961
848
|
* },
|
|
962
|
-
* c: "0x...", //
|
|
849
|
+
* c: "0x...", // Client Order ID (optional)
|
|
963
850
|
* }],
|
|
964
851
|
* grouping: "na", // No grouping
|
|
965
852
|
* });
|
|
@@ -972,46 +859,12 @@
|
|
|
972
859
|
const nonce = await this.nonceManager();
|
|
973
860
|
const action = {
|
|
974
861
|
type: "order",
|
|
975
|
-
|
|
976
|
-
const sortedOrder = {
|
|
977
|
-
a: order.a,
|
|
978
|
-
b: order.b,
|
|
979
|
-
p: this._formatDecimal(order.p),
|
|
980
|
-
s: this._formatDecimal(order.s),
|
|
981
|
-
r: order.r,
|
|
982
|
-
t: "limit" in order.t
|
|
983
|
-
? {
|
|
984
|
-
limit: {
|
|
985
|
-
tif: order.t.limit.tif,
|
|
986
|
-
},
|
|
987
|
-
}
|
|
988
|
-
: {
|
|
989
|
-
trigger: {
|
|
990
|
-
isMarket: order.t.trigger.isMarket,
|
|
991
|
-
triggerPx: this._formatDecimal(order.t.trigger.triggerPx),
|
|
992
|
-
tpsl: order.t.trigger.tpsl,
|
|
993
|
-
},
|
|
994
|
-
},
|
|
995
|
-
c: order.c,
|
|
996
|
-
};
|
|
997
|
-
if (order.c === undefined)
|
|
998
|
-
delete sortedOrder.c;
|
|
999
|
-
return sortedOrder;
|
|
1000
|
-
}),
|
|
1001
|
-
grouping: actionArgs.grouping,
|
|
1002
|
-
builder: actionArgs.builder
|
|
1003
|
-
? {
|
|
1004
|
-
b: actionArgs.builder.b.toLowerCase(),
|
|
1005
|
-
f: actionArgs.builder.f,
|
|
1006
|
-
}
|
|
1007
|
-
: actionArgs.builder,
|
|
862
|
+
...actionArgs,
|
|
1008
863
|
};
|
|
1009
|
-
if (action.builder === undefined)
|
|
1010
|
-
delete action.builder;
|
|
1011
864
|
// Sign the action
|
|
1012
865
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
1013
866
|
wallet: this.wallet,
|
|
1014
|
-
action,
|
|
867
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
1015
868
|
nonce,
|
|
1016
869
|
isTestnet: this.isTestnet,
|
|
1017
870
|
vaultAddress,
|
|
@@ -1021,47 +874,18 @@
|
|
|
1021
874
|
return await this._request({ action, signature, nonce, vaultAddress, expiresAfter }, signal);
|
|
1022
875
|
}
|
|
1023
876
|
async perpDeploy(args, signal) {
|
|
877
|
+
// Destructure the parameters
|
|
878
|
+
const { ...actionArgs } = args;
|
|
1024
879
|
// Construct an action
|
|
1025
880
|
const nonce = await this.nonceManager();
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
registerAsset: {
|
|
1031
|
-
maxGas: args.registerAsset.maxGas ?? null,
|
|
1032
|
-
assetRequest: {
|
|
1033
|
-
coin: args.registerAsset.assetRequest.coin,
|
|
1034
|
-
szDecimals: args.registerAsset.assetRequest.szDecimals,
|
|
1035
|
-
oraclePx: args.registerAsset.assetRequest.oraclePx,
|
|
1036
|
-
marginTableId: args.registerAsset.assetRequest.marginTableId,
|
|
1037
|
-
onlyIsolated: args.registerAsset.assetRequest.onlyIsolated,
|
|
1038
|
-
},
|
|
1039
|
-
dex: args.registerAsset.dex,
|
|
1040
|
-
schema: args.registerAsset.schema
|
|
1041
|
-
? {
|
|
1042
|
-
fullName: args.registerAsset.schema.fullName,
|
|
1043
|
-
collateralToken: args.registerAsset.schema.collateralToken,
|
|
1044
|
-
oracleUpdater: args.registerAsset.schema.oracleUpdater?.toLowerCase() ??
|
|
1045
|
-
null,
|
|
1046
|
-
}
|
|
1047
|
-
: null,
|
|
1048
|
-
},
|
|
1049
|
-
};
|
|
1050
|
-
}
|
|
1051
|
-
else {
|
|
1052
|
-
action = {
|
|
1053
|
-
type: "perpDeploy",
|
|
1054
|
-
setOracle: {
|
|
1055
|
-
dex: args.setOracle.dex,
|
|
1056
|
-
oraclePxs: args.setOracle.oraclePxs,
|
|
1057
|
-
markPxs: args.setOracle.markPxs,
|
|
1058
|
-
},
|
|
1059
|
-
};
|
|
1060
|
-
}
|
|
881
|
+
const action = {
|
|
882
|
+
type: "perpDeploy",
|
|
883
|
+
...actionArgs,
|
|
884
|
+
};
|
|
1061
885
|
// Sign the action
|
|
1062
886
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
1063
887
|
wallet: this.wallet,
|
|
1064
|
-
action,
|
|
888
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
1065
889
|
nonce,
|
|
1066
890
|
isTestnet: this.isTestnet,
|
|
1067
891
|
});
|
|
@@ -1085,7 +909,7 @@
|
|
|
1085
909
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1086
910
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1087
911
|
*
|
|
1088
|
-
* const
|
|
912
|
+
* const data = await exchClient.perpDexClassTransfer({
|
|
1089
913
|
* dex: "test",
|
|
1090
914
|
* token: "USDC",
|
|
1091
915
|
* amount: "1",
|
|
@@ -1094,32 +918,26 @@
|
|
|
1094
918
|
* ```
|
|
1095
919
|
*/
|
|
1096
920
|
async perpDexClassTransfer(args, signal) {
|
|
921
|
+
// Destructure the parameters
|
|
922
|
+
const { ...actionArgs } = args;
|
|
1097
923
|
// Construct an action
|
|
924
|
+
const nonce = await this.nonceManager();
|
|
1098
925
|
const action = {
|
|
1099
|
-
...
|
|
926
|
+
...actionArgs,
|
|
1100
927
|
type: "PerpDexClassTransfer",
|
|
1101
928
|
hyperliquidChain: this._getHyperliquidChain(),
|
|
1102
929
|
signatureChainId: await this._getSignatureChainId(),
|
|
1103
|
-
nonce
|
|
930
|
+
nonce,
|
|
1104
931
|
};
|
|
1105
932
|
// Sign the action
|
|
1106
933
|
const signature = await (0, signing_js_1.signUserSignedAction)({
|
|
1107
934
|
wallet: this.wallet,
|
|
1108
935
|
action,
|
|
1109
|
-
types:
|
|
1110
|
-
"HyperliquidTransaction:PerpDexClassTransfer": [
|
|
1111
|
-
{ name: "hyperliquidChain", type: "string" },
|
|
1112
|
-
{ name: "dex", type: "string" },
|
|
1113
|
-
{ name: "token", type: "string" },
|
|
1114
|
-
{ name: "amount", type: "string" },
|
|
1115
|
-
{ name: "toPerp", type: "bool" },
|
|
1116
|
-
{ name: "nonce", type: "uint64" },
|
|
1117
|
-
],
|
|
1118
|
-
},
|
|
936
|
+
types: signing_js_1.userSignedActionEip712Types[action.type],
|
|
1119
937
|
chainId: parseInt(action.signatureChainId, 16),
|
|
1120
938
|
});
|
|
1121
939
|
// Send a request
|
|
1122
|
-
return await this._request({ action, signature, nonce
|
|
940
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
1123
941
|
}
|
|
1124
942
|
/**
|
|
1125
943
|
* Create a referral code.
|
|
@@ -1138,20 +956,22 @@
|
|
|
1138
956
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1139
957
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1140
958
|
*
|
|
1141
|
-
* const
|
|
959
|
+
* const data = await exchClient.registerReferrer({ code: "TEST" });
|
|
1142
960
|
* ```
|
|
1143
961
|
*/
|
|
1144
962
|
async registerReferrer(args, signal) {
|
|
963
|
+
// Destructure the parameters
|
|
964
|
+
const { ...actionArgs } = args;
|
|
1145
965
|
// Construct an action
|
|
1146
966
|
const nonce = await this.nonceManager();
|
|
1147
967
|
const action = {
|
|
1148
968
|
type: "registerReferrer",
|
|
1149
|
-
|
|
969
|
+
...actionArgs,
|
|
1150
970
|
};
|
|
1151
971
|
// Sign the action
|
|
1152
972
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
1153
973
|
wallet: this.wallet,
|
|
1154
|
-
action,
|
|
974
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
1155
975
|
nonce,
|
|
1156
976
|
isTestnet: this.isTestnet,
|
|
1157
977
|
});
|
|
@@ -1175,7 +995,7 @@
|
|
|
1175
995
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1176
996
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1177
997
|
*
|
|
1178
|
-
* const
|
|
998
|
+
* const data = await exchClient.reserveRequestWeight({ weight: 10 });
|
|
1179
999
|
* ```
|
|
1180
1000
|
*/
|
|
1181
1001
|
async reserveRequestWeight(args, signal) {
|
|
@@ -1185,12 +1005,12 @@
|
|
|
1185
1005
|
const nonce = await this.nonceManager();
|
|
1186
1006
|
const action = {
|
|
1187
1007
|
type: "reserveRequestWeight",
|
|
1188
|
-
|
|
1008
|
+
...actionArgs,
|
|
1189
1009
|
};
|
|
1190
1010
|
// Sign the action
|
|
1191
1011
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
1192
1012
|
wallet: this.wallet,
|
|
1193
|
-
action,
|
|
1013
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
1194
1014
|
nonce,
|
|
1195
1015
|
isTestnet: this.isTestnet,
|
|
1196
1016
|
expiresAfter,
|
|
@@ -1207,14 +1027,12 @@
|
|
|
1207
1027
|
const nonce = await this.nonceManager();
|
|
1208
1028
|
const action = {
|
|
1209
1029
|
type: "scheduleCancel",
|
|
1210
|
-
|
|
1030
|
+
...actionArgs,
|
|
1211
1031
|
};
|
|
1212
|
-
if (action.time === undefined)
|
|
1213
|
-
delete action.time;
|
|
1214
1032
|
// Sign the action
|
|
1215
1033
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
1216
1034
|
wallet: this.wallet,
|
|
1217
|
-
action,
|
|
1035
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
1218
1036
|
nonce,
|
|
1219
1037
|
isTestnet: this.isTestnet,
|
|
1220
1038
|
vaultAddress,
|
|
@@ -1240,20 +1058,22 @@
|
|
|
1240
1058
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1241
1059
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1242
1060
|
*
|
|
1243
|
-
* const
|
|
1061
|
+
* const data = await exchClient.setDisplayName({ displayName: "My Name" });
|
|
1244
1062
|
* ```
|
|
1245
1063
|
*/
|
|
1246
1064
|
async setDisplayName(args, signal) {
|
|
1065
|
+
// Destructure the parameters
|
|
1066
|
+
const { ...actionArgs } = args;
|
|
1247
1067
|
// Construct an action
|
|
1248
1068
|
const nonce = await this.nonceManager();
|
|
1249
1069
|
const action = {
|
|
1250
1070
|
type: "setDisplayName",
|
|
1251
|
-
|
|
1071
|
+
...actionArgs,
|
|
1252
1072
|
};
|
|
1253
1073
|
// Sign the action
|
|
1254
1074
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
1255
1075
|
wallet: this.wallet,
|
|
1256
|
-
action,
|
|
1076
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
1257
1077
|
nonce,
|
|
1258
1078
|
isTestnet: this.isTestnet,
|
|
1259
1079
|
});
|
|
@@ -1277,20 +1097,22 @@
|
|
|
1277
1097
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1278
1098
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1279
1099
|
*
|
|
1280
|
-
* const
|
|
1100
|
+
* const data = await exchClient.setReferrer({ code: "TEST" });
|
|
1281
1101
|
* ```
|
|
1282
1102
|
*/
|
|
1283
1103
|
async setReferrer(args, signal) {
|
|
1104
|
+
// Destructure the parameters
|
|
1105
|
+
const { ...actionArgs } = args;
|
|
1284
1106
|
// Construct an action
|
|
1285
1107
|
const nonce = await this.nonceManager();
|
|
1286
1108
|
const action = {
|
|
1287
1109
|
type: "setReferrer",
|
|
1288
|
-
|
|
1110
|
+
...actionArgs,
|
|
1289
1111
|
};
|
|
1290
1112
|
// Sign the action
|
|
1291
1113
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
1292
1114
|
wallet: this.wallet,
|
|
1293
|
-
action,
|
|
1115
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
1294
1116
|
nonce,
|
|
1295
1117
|
isTestnet: this.isTestnet,
|
|
1296
1118
|
});
|
|
@@ -1298,89 +1120,18 @@
|
|
|
1298
1120
|
return await this._request({ action, signature, nonce }, signal);
|
|
1299
1121
|
}
|
|
1300
1122
|
async spotDeploy(args, signal) {
|
|
1123
|
+
// Destructure the parameters
|
|
1124
|
+
const { ...actionArgs } = args;
|
|
1301
1125
|
// Construct an action
|
|
1302
1126
|
const nonce = await this.nonceManager();
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
registerToken2: {
|
|
1308
|
-
spec: {
|
|
1309
|
-
name: args.registerToken2.spec.name,
|
|
1310
|
-
szDecimals: args.registerToken2.spec.szDecimals,
|
|
1311
|
-
weiDecimals: args.registerToken2.spec.weiDecimals,
|
|
1312
|
-
},
|
|
1313
|
-
maxGas: args.registerToken2.maxGas,
|
|
1314
|
-
fullName: args.registerToken2.fullName,
|
|
1315
|
-
},
|
|
1316
|
-
};
|
|
1317
|
-
if (action.registerToken2.fullName === undefined) {
|
|
1318
|
-
delete action.registerToken2.fullName;
|
|
1319
|
-
}
|
|
1320
|
-
}
|
|
1321
|
-
else if ("userGenesis" in args) {
|
|
1322
|
-
action = {
|
|
1323
|
-
type: "spotDeploy",
|
|
1324
|
-
userGenesis: {
|
|
1325
|
-
token: args.userGenesis.token,
|
|
1326
|
-
userAndWei: args.userGenesis.userAndWei,
|
|
1327
|
-
existingTokenAndWei: args.userGenesis.existingTokenAndWei,
|
|
1328
|
-
blacklistUsers: args.userGenesis.blacklistUsers,
|
|
1329
|
-
},
|
|
1330
|
-
};
|
|
1331
|
-
if (action.userGenesis.blacklistUsers === undefined) {
|
|
1332
|
-
delete action.userGenesis.blacklistUsers;
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
else if ("genesis" in args) {
|
|
1336
|
-
action = {
|
|
1337
|
-
type: "spotDeploy",
|
|
1338
|
-
genesis: {
|
|
1339
|
-
token: args.genesis.token,
|
|
1340
|
-
maxSupply: args.genesis.maxSupply,
|
|
1341
|
-
noHyperliquidity: args.genesis.noHyperliquidity,
|
|
1342
|
-
},
|
|
1343
|
-
};
|
|
1344
|
-
if (action.genesis.noHyperliquidity === undefined) {
|
|
1345
|
-
delete action.genesis.noHyperliquidity;
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
else if ("registerSpot" in args) {
|
|
1349
|
-
action = {
|
|
1350
|
-
type: "spotDeploy",
|
|
1351
|
-
registerSpot: {
|
|
1352
|
-
tokens: args.registerSpot.tokens,
|
|
1353
|
-
},
|
|
1354
|
-
};
|
|
1355
|
-
}
|
|
1356
|
-
else if ("registerHyperliquidity" in args) {
|
|
1357
|
-
action = {
|
|
1358
|
-
type: "spotDeploy",
|
|
1359
|
-
registerHyperliquidity: {
|
|
1360
|
-
spot: args.registerHyperliquidity.spot,
|
|
1361
|
-
startPx: args.registerHyperliquidity.startPx,
|
|
1362
|
-
orderSz: args.registerHyperliquidity.orderSz,
|
|
1363
|
-
nOrders: args.registerHyperliquidity.nOrders,
|
|
1364
|
-
nSeededLevels: args.registerHyperliquidity.nSeededLevels,
|
|
1365
|
-
},
|
|
1366
|
-
};
|
|
1367
|
-
if (action.registerHyperliquidity.nSeededLevels === undefined) {
|
|
1368
|
-
delete action.registerHyperliquidity.nSeededLevels;
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
else {
|
|
1372
|
-
action = {
|
|
1373
|
-
type: "spotDeploy",
|
|
1374
|
-
setDeployerTradingFeeShare: {
|
|
1375
|
-
token: args.setDeployerTradingFeeShare.token,
|
|
1376
|
-
share: args.setDeployerTradingFeeShare.share,
|
|
1377
|
-
},
|
|
1378
|
-
};
|
|
1379
|
-
}
|
|
1127
|
+
const action = {
|
|
1128
|
+
type: "spotDeploy",
|
|
1129
|
+
...actionArgs,
|
|
1130
|
+
};
|
|
1380
1131
|
// Sign the action
|
|
1381
1132
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
1382
1133
|
wallet: this.wallet,
|
|
1383
|
-
action,
|
|
1134
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
1384
1135
|
nonce,
|
|
1385
1136
|
isTestnet: this.isTestnet,
|
|
1386
1137
|
});
|
|
@@ -1404,7 +1155,7 @@
|
|
|
1404
1155
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1405
1156
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1406
1157
|
*
|
|
1407
|
-
* const
|
|
1158
|
+
* const data = await exchClient.spotSend({
|
|
1408
1159
|
* destination: "0x...",
|
|
1409
1160
|
* token: "USDC:0xeb62eee3685fc4c43992febcd9e75443",
|
|
1410
1161
|
* amount: "1",
|
|
@@ -1412,31 +1163,26 @@
|
|
|
1412
1163
|
* ```
|
|
1413
1164
|
*/
|
|
1414
1165
|
async spotSend(args, signal) {
|
|
1166
|
+
// Destructure the parameters
|
|
1167
|
+
const { ...actionArgs } = args;
|
|
1415
1168
|
// Construct an action
|
|
1169
|
+
const nonce = await this.nonceManager();
|
|
1416
1170
|
const action = {
|
|
1417
|
-
...
|
|
1171
|
+
...actionArgs,
|
|
1418
1172
|
type: "spotSend",
|
|
1419
1173
|
hyperliquidChain: this._getHyperliquidChain(),
|
|
1420
1174
|
signatureChainId: await this._getSignatureChainId(),
|
|
1421
|
-
time:
|
|
1175
|
+
time: nonce,
|
|
1422
1176
|
};
|
|
1423
1177
|
// Sign the action
|
|
1424
1178
|
const signature = await (0, signing_js_1.signUserSignedAction)({
|
|
1425
1179
|
wallet: this.wallet,
|
|
1426
1180
|
action,
|
|
1427
|
-
types:
|
|
1428
|
-
"HyperliquidTransaction:SpotSend": [
|
|
1429
|
-
{ name: "hyperliquidChain", type: "string" },
|
|
1430
|
-
{ name: "destination", type: "string" },
|
|
1431
|
-
{ name: "token", type: "string" },
|
|
1432
|
-
{ name: "amount", type: "string" },
|
|
1433
|
-
{ name: "time", type: "uint64" },
|
|
1434
|
-
],
|
|
1435
|
-
},
|
|
1181
|
+
types: signing_js_1.userSignedActionEip712Types[action.type],
|
|
1436
1182
|
chainId: parseInt(action.signatureChainId, 16),
|
|
1437
1183
|
});
|
|
1438
1184
|
// Send a request
|
|
1439
|
-
return await this._request({ action, signature, nonce
|
|
1185
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
1440
1186
|
}
|
|
1441
1187
|
/**
|
|
1442
1188
|
* Opt Out of Spot Dusting.
|
|
@@ -1455,22 +1201,22 @@
|
|
|
1455
1201
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1456
1202
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1457
1203
|
*
|
|
1458
|
-
* const
|
|
1204
|
+
* const data = await exchClient.spotUser({ toggleSpotDusting: { optOut: false } });
|
|
1459
1205
|
* ```
|
|
1460
1206
|
*/
|
|
1461
1207
|
async spotUser(args, signal) {
|
|
1208
|
+
// Destructure the parameters
|
|
1209
|
+
const { ...actionArgs } = args;
|
|
1462
1210
|
// Construct an action
|
|
1463
1211
|
const nonce = await this.nonceManager();
|
|
1464
1212
|
const action = {
|
|
1465
1213
|
type: "spotUser",
|
|
1466
|
-
|
|
1467
|
-
optOut: args.toggleSpotDusting.optOut,
|
|
1468
|
-
},
|
|
1214
|
+
...actionArgs,
|
|
1469
1215
|
};
|
|
1470
1216
|
// Sign the action
|
|
1471
1217
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
1472
1218
|
wallet: this.wallet,
|
|
1473
|
-
action,
|
|
1219
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
1474
1220
|
nonce,
|
|
1475
1221
|
isTestnet: this.isTestnet,
|
|
1476
1222
|
});
|
|
@@ -1494,7 +1240,7 @@
|
|
|
1494
1240
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1495
1241
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1496
1242
|
*
|
|
1497
|
-
* const
|
|
1243
|
+
* const data = await exchClient.subAccountSpotTransfer({
|
|
1498
1244
|
* subAccountUser: "0x...",
|
|
1499
1245
|
* isDeposit: true,
|
|
1500
1246
|
* token: "USDC:0xeb62eee3685fc4c43992febcd9e75443",
|
|
@@ -1503,19 +1249,18 @@
|
|
|
1503
1249
|
* ```
|
|
1504
1250
|
*/
|
|
1505
1251
|
async subAccountSpotTransfer(args, signal) {
|
|
1252
|
+
// Destructure the parameters
|
|
1253
|
+
const { ...actionArgs } = args;
|
|
1506
1254
|
// Construct an action
|
|
1507
1255
|
const nonce = await this.nonceManager();
|
|
1508
1256
|
const action = {
|
|
1509
1257
|
type: "subAccountSpotTransfer",
|
|
1510
|
-
|
|
1511
|
-
isDeposit: args.isDeposit,
|
|
1512
|
-
token: args.token,
|
|
1513
|
-
amount: args.amount,
|
|
1258
|
+
...actionArgs,
|
|
1514
1259
|
};
|
|
1515
1260
|
// Sign the action
|
|
1516
1261
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
1517
1262
|
wallet: this.wallet,
|
|
1518
|
-
action,
|
|
1263
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
1519
1264
|
nonce,
|
|
1520
1265
|
isTestnet: this.isTestnet,
|
|
1521
1266
|
});
|
|
@@ -1539,7 +1284,7 @@
|
|
|
1539
1284
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1540
1285
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1541
1286
|
*
|
|
1542
|
-
* const
|
|
1287
|
+
* const data = await exchClient.subAccountTransfer({
|
|
1543
1288
|
* subAccountUser: "0x...",
|
|
1544
1289
|
* isDeposit: true,
|
|
1545
1290
|
* usd: 1 * 1e6,
|
|
@@ -1547,18 +1292,18 @@
|
|
|
1547
1292
|
* ```
|
|
1548
1293
|
*/
|
|
1549
1294
|
async subAccountTransfer(args, signal) {
|
|
1295
|
+
// Destructure the parameters
|
|
1296
|
+
const { ...actionArgs } = args;
|
|
1550
1297
|
// Construct an action
|
|
1551
1298
|
const nonce = await this.nonceManager();
|
|
1552
1299
|
const action = {
|
|
1553
1300
|
type: "subAccountTransfer",
|
|
1554
|
-
|
|
1555
|
-
isDeposit: args.isDeposit,
|
|
1556
|
-
usd: args.usd,
|
|
1301
|
+
...actionArgs,
|
|
1557
1302
|
};
|
|
1558
1303
|
// Sign the action
|
|
1559
1304
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
1560
1305
|
wallet: this.wallet,
|
|
1561
|
-
action,
|
|
1306
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
1562
1307
|
nonce,
|
|
1563
1308
|
isTestnet: this.isTestnet,
|
|
1564
1309
|
});
|
|
@@ -1582,7 +1327,7 @@
|
|
|
1582
1327
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1583
1328
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1584
1329
|
*
|
|
1585
|
-
* const
|
|
1330
|
+
* const data = await exchClient.tokenDelegate({
|
|
1586
1331
|
* validator: "0x...",
|
|
1587
1332
|
* isUndelegate: true,
|
|
1588
1333
|
* wei: 1 * 1e8,
|
|
@@ -1590,31 +1335,26 @@
|
|
|
1590
1335
|
* ```
|
|
1591
1336
|
*/
|
|
1592
1337
|
async tokenDelegate(args, signal) {
|
|
1338
|
+
// Destructure the parameters
|
|
1339
|
+
const { ...actionArgs } = args;
|
|
1593
1340
|
// Construct an action
|
|
1341
|
+
const nonce = await this.nonceManager();
|
|
1594
1342
|
const action = {
|
|
1595
|
-
...
|
|
1343
|
+
...actionArgs,
|
|
1596
1344
|
type: "tokenDelegate",
|
|
1597
1345
|
hyperliquidChain: this._getHyperliquidChain(),
|
|
1598
1346
|
signatureChainId: await this._getSignatureChainId(),
|
|
1599
|
-
nonce
|
|
1347
|
+
nonce,
|
|
1600
1348
|
};
|
|
1601
1349
|
// Sign the action
|
|
1602
1350
|
const signature = await (0, signing_js_1.signUserSignedAction)({
|
|
1603
1351
|
wallet: this.wallet,
|
|
1604
1352
|
action,
|
|
1605
|
-
types:
|
|
1606
|
-
"HyperliquidTransaction:TokenDelegate": [
|
|
1607
|
-
{ name: "hyperliquidChain", type: "string" },
|
|
1608
|
-
{ name: "validator", type: "address" },
|
|
1609
|
-
{ name: "wei", type: "uint64" },
|
|
1610
|
-
{ name: "isUndelegate", type: "bool" },
|
|
1611
|
-
{ name: "nonce", type: "uint64" },
|
|
1612
|
-
],
|
|
1613
|
-
},
|
|
1353
|
+
types: signing_js_1.userSignedActionEip712Types[action.type],
|
|
1614
1354
|
chainId: parseInt(action.signatureChainId, 16),
|
|
1615
1355
|
});
|
|
1616
1356
|
// Send a request
|
|
1617
|
-
return await this._request({ action, signature, nonce
|
|
1357
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
1618
1358
|
}
|
|
1619
1359
|
/**
|
|
1620
1360
|
* Cancel a TWAP order.
|
|
@@ -1633,7 +1373,7 @@
|
|
|
1633
1373
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1634
1374
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1635
1375
|
*
|
|
1636
|
-
* const
|
|
1376
|
+
* const data = await exchClient.twapCancel({
|
|
1637
1377
|
* a: 0, // Asset index
|
|
1638
1378
|
* t: 1, // TWAP ID
|
|
1639
1379
|
* });
|
|
@@ -1646,13 +1386,12 @@
|
|
|
1646
1386
|
const nonce = await this.nonceManager();
|
|
1647
1387
|
const action = {
|
|
1648
1388
|
type: "twapCancel",
|
|
1649
|
-
|
|
1650
|
-
t: actionArgs.t,
|
|
1389
|
+
...actionArgs,
|
|
1651
1390
|
};
|
|
1652
1391
|
// Sign the action
|
|
1653
1392
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
1654
1393
|
wallet: this.wallet,
|
|
1655
|
-
action,
|
|
1394
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
1656
1395
|
nonce,
|
|
1657
1396
|
isTestnet: this.isTestnet,
|
|
1658
1397
|
vaultAddress,
|
|
@@ -1678,7 +1417,7 @@
|
|
|
1678
1417
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1679
1418
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1680
1419
|
*
|
|
1681
|
-
* const
|
|
1420
|
+
* const data = await exchClient.twapOrder({
|
|
1682
1421
|
* a: 0, // Asset index
|
|
1683
1422
|
* b: true, // Buy order
|
|
1684
1423
|
* s: "1", // Size
|
|
@@ -1696,18 +1435,13 @@
|
|
|
1696
1435
|
const action = {
|
|
1697
1436
|
type: "twapOrder",
|
|
1698
1437
|
twap: {
|
|
1699
|
-
|
|
1700
|
-
b: actionArgs.b,
|
|
1701
|
-
s: this._formatDecimal(actionArgs.s),
|
|
1702
|
-
r: actionArgs.r,
|
|
1703
|
-
m: actionArgs.m,
|
|
1704
|
-
t: actionArgs.t,
|
|
1438
|
+
...actionArgs,
|
|
1705
1439
|
},
|
|
1706
1440
|
};
|
|
1707
1441
|
// Sign the action
|
|
1708
1442
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
1709
1443
|
wallet: this.wallet,
|
|
1710
|
-
action,
|
|
1444
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
1711
1445
|
nonce,
|
|
1712
1446
|
isTestnet: this.isTestnet,
|
|
1713
1447
|
vaultAddress,
|
|
@@ -1733,7 +1467,11 @@
|
|
|
1733
1467
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1734
1468
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1735
1469
|
*
|
|
1736
|
-
* const
|
|
1470
|
+
* const data = await exchClient.updateIsolatedMargin({
|
|
1471
|
+
* asset: 0,
|
|
1472
|
+
* isBuy: true,
|
|
1473
|
+
* ntli: 1 * 1e6,
|
|
1474
|
+
* });
|
|
1737
1475
|
* ```
|
|
1738
1476
|
*/
|
|
1739
1477
|
async updateIsolatedMargin(args, signal) {
|
|
@@ -1743,14 +1481,12 @@
|
|
|
1743
1481
|
const nonce = await this.nonceManager();
|
|
1744
1482
|
const action = {
|
|
1745
1483
|
type: "updateIsolatedMargin",
|
|
1746
|
-
|
|
1747
|
-
isBuy: actionArgs.isBuy,
|
|
1748
|
-
ntli: actionArgs.ntli,
|
|
1484
|
+
...actionArgs,
|
|
1749
1485
|
};
|
|
1750
1486
|
// Sign the action
|
|
1751
1487
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
1752
1488
|
wallet: this.wallet,
|
|
1753
|
-
action,
|
|
1489
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
1754
1490
|
nonce,
|
|
1755
1491
|
isTestnet: this.isTestnet,
|
|
1756
1492
|
vaultAddress,
|
|
@@ -1776,7 +1512,11 @@
|
|
|
1776
1512
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1777
1513
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1778
1514
|
*
|
|
1779
|
-
* const
|
|
1515
|
+
* const data = await exchClient.updateLeverage({
|
|
1516
|
+
* asset: 0,
|
|
1517
|
+
* isCross: true,
|
|
1518
|
+
* leverage: 5,
|
|
1519
|
+
* });
|
|
1780
1520
|
* ```
|
|
1781
1521
|
*/
|
|
1782
1522
|
async updateLeverage(args, signal) {
|
|
@@ -1786,14 +1526,12 @@
|
|
|
1786
1526
|
const nonce = await this.nonceManager();
|
|
1787
1527
|
const action = {
|
|
1788
1528
|
type: "updateLeverage",
|
|
1789
|
-
|
|
1790
|
-
isCross: actionArgs.isCross,
|
|
1791
|
-
leverage: actionArgs.leverage,
|
|
1529
|
+
...actionArgs,
|
|
1792
1530
|
};
|
|
1793
1531
|
// Sign the action
|
|
1794
1532
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
1795
1533
|
wallet: this.wallet,
|
|
1796
|
-
action,
|
|
1534
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
1797
1535
|
nonce,
|
|
1798
1536
|
isTestnet: this.isTestnet,
|
|
1799
1537
|
vaultAddress,
|
|
@@ -1819,34 +1557,30 @@
|
|
|
1819
1557
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1820
1558
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1821
1559
|
*
|
|
1822
|
-
* const
|
|
1560
|
+
* const data = await exchClient.usdClassTransfer({ amount: "1", toPerp: true });
|
|
1823
1561
|
* ```
|
|
1824
1562
|
*/
|
|
1825
1563
|
async usdClassTransfer(args, signal) {
|
|
1564
|
+
// Destructure the parameters
|
|
1565
|
+
const { ...actionArgs } = args;
|
|
1826
1566
|
// Construct an action
|
|
1567
|
+
const nonce = await this.nonceManager();
|
|
1827
1568
|
const action = {
|
|
1828
|
-
...
|
|
1569
|
+
...actionArgs,
|
|
1829
1570
|
type: "usdClassTransfer",
|
|
1830
1571
|
hyperliquidChain: this._getHyperliquidChain(),
|
|
1831
1572
|
signatureChainId: await this._getSignatureChainId(),
|
|
1832
|
-
nonce
|
|
1573
|
+
nonce,
|
|
1833
1574
|
};
|
|
1834
1575
|
// Sign the action
|
|
1835
1576
|
const signature = await (0, signing_js_1.signUserSignedAction)({
|
|
1836
1577
|
wallet: this.wallet,
|
|
1837
1578
|
action,
|
|
1838
|
-
types:
|
|
1839
|
-
"HyperliquidTransaction:UsdClassTransfer": [
|
|
1840
|
-
{ name: "hyperliquidChain", type: "string" },
|
|
1841
|
-
{ name: "amount", type: "string" },
|
|
1842
|
-
{ name: "toPerp", type: "bool" },
|
|
1843
|
-
{ name: "nonce", type: "uint64" },
|
|
1844
|
-
],
|
|
1845
|
-
},
|
|
1579
|
+
types: signing_js_1.userSignedActionEip712Types[action.type],
|
|
1846
1580
|
chainId: parseInt(action.signatureChainId, 16),
|
|
1847
1581
|
});
|
|
1848
1582
|
// Send a request
|
|
1849
|
-
return await this._request({ action, signature, nonce
|
|
1583
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
1850
1584
|
}
|
|
1851
1585
|
/**
|
|
1852
1586
|
* Send usd to another address.
|
|
@@ -1865,34 +1599,30 @@
|
|
|
1865
1599
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1866
1600
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1867
1601
|
*
|
|
1868
|
-
* const
|
|
1602
|
+
* const data = await exchClient.usdSend({ destination: "0x...", amount: "1" });
|
|
1869
1603
|
* ```
|
|
1870
1604
|
*/
|
|
1871
1605
|
async usdSend(args, signal) {
|
|
1606
|
+
// Destructure the parameters
|
|
1607
|
+
const { ...actionArgs } = args;
|
|
1872
1608
|
// Construct an action
|
|
1609
|
+
const nonce = await this.nonceManager();
|
|
1873
1610
|
const action = {
|
|
1874
|
-
...
|
|
1611
|
+
...actionArgs,
|
|
1875
1612
|
type: "usdSend",
|
|
1876
1613
|
hyperliquidChain: this._getHyperliquidChain(),
|
|
1877
1614
|
signatureChainId: await this._getSignatureChainId(),
|
|
1878
|
-
time:
|
|
1615
|
+
time: nonce,
|
|
1879
1616
|
};
|
|
1880
1617
|
// Sign the action
|
|
1881
1618
|
const signature = await (0, signing_js_1.signUserSignedAction)({
|
|
1882
1619
|
wallet: this.wallet,
|
|
1883
1620
|
action,
|
|
1884
|
-
types:
|
|
1885
|
-
"HyperliquidTransaction:UsdSend": [
|
|
1886
|
-
{ name: "hyperliquidChain", type: "string" },
|
|
1887
|
-
{ name: "destination", type: "string" },
|
|
1888
|
-
{ name: "amount", type: "string" },
|
|
1889
|
-
{ name: "time", type: "uint64" },
|
|
1890
|
-
],
|
|
1891
|
-
},
|
|
1621
|
+
types: signing_js_1.userSignedActionEip712Types[action.type],
|
|
1892
1622
|
chainId: parseInt(action.signatureChainId, 16),
|
|
1893
1623
|
});
|
|
1894
1624
|
// Send a request
|
|
1895
|
-
return await this._request({ action, signature, nonce
|
|
1625
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
1896
1626
|
}
|
|
1897
1627
|
/**
|
|
1898
1628
|
* Distribute funds from a vault between followers.
|
|
@@ -1911,21 +1641,22 @@
|
|
|
1911
1641
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1912
1642
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1913
1643
|
*
|
|
1914
|
-
* const
|
|
1644
|
+
* const data = await exchClient.vaultDistribute({ vaultAddress: "0x...", usd: 10 * 1e6 });
|
|
1915
1645
|
* ```
|
|
1916
1646
|
*/
|
|
1917
1647
|
async vaultDistribute(args, signal) {
|
|
1648
|
+
// Destructure the parameters
|
|
1649
|
+
const { ...actionArgs } = args;
|
|
1918
1650
|
// Construct an action
|
|
1919
1651
|
const nonce = await this.nonceManager();
|
|
1920
1652
|
const action = {
|
|
1921
1653
|
type: "vaultDistribute",
|
|
1922
|
-
|
|
1923
|
-
usd: args.usd,
|
|
1654
|
+
...actionArgs,
|
|
1924
1655
|
};
|
|
1925
1656
|
// Sign the action
|
|
1926
1657
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
1927
1658
|
wallet: this.wallet,
|
|
1928
|
-
action,
|
|
1659
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
1929
1660
|
nonce,
|
|
1930
1661
|
isTestnet: this.isTestnet,
|
|
1931
1662
|
});
|
|
@@ -1949,7 +1680,7 @@
|
|
|
1949
1680
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1950
1681
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1951
1682
|
*
|
|
1952
|
-
* const
|
|
1683
|
+
* const data = await exchClient.vaultModify({
|
|
1953
1684
|
* vaultAddress: "0x...",
|
|
1954
1685
|
* allowDeposits: true,
|
|
1955
1686
|
* alwaysCloseOnWithdraw: false,
|
|
@@ -1957,18 +1688,18 @@
|
|
|
1957
1688
|
* ```
|
|
1958
1689
|
*/
|
|
1959
1690
|
async vaultModify(args, signal) {
|
|
1691
|
+
// Destructure the parameters
|
|
1692
|
+
const { ...actionArgs } = args;
|
|
1960
1693
|
// Construct an action
|
|
1961
1694
|
const nonce = await this.nonceManager();
|
|
1962
1695
|
const action = {
|
|
1963
1696
|
type: "vaultModify",
|
|
1964
|
-
|
|
1965
|
-
allowDeposits: args.allowDeposits,
|
|
1966
|
-
alwaysCloseOnWithdraw: args.alwaysCloseOnWithdraw,
|
|
1697
|
+
...actionArgs,
|
|
1967
1698
|
};
|
|
1968
1699
|
// Sign the action
|
|
1969
1700
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
1970
1701
|
wallet: this.wallet,
|
|
1971
|
-
action,
|
|
1702
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
1972
1703
|
nonce,
|
|
1973
1704
|
isTestnet: this.isTestnet,
|
|
1974
1705
|
});
|
|
@@ -1992,7 +1723,7 @@
|
|
|
1992
1723
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
1993
1724
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
1994
1725
|
*
|
|
1995
|
-
* const
|
|
1726
|
+
* const data = await exchClient.vaultTransfer({
|
|
1996
1727
|
* vaultAddress: "0x...",
|
|
1997
1728
|
* isDeposit: true,
|
|
1998
1729
|
* usd: 10 * 1e6,
|
|
@@ -2006,14 +1737,12 @@
|
|
|
2006
1737
|
const nonce = await this.nonceManager();
|
|
2007
1738
|
const action = {
|
|
2008
1739
|
type: "vaultTransfer",
|
|
2009
|
-
|
|
2010
|
-
isDeposit: actionArgs.isDeposit,
|
|
2011
|
-
usd: actionArgs.usd,
|
|
1740
|
+
...actionArgs,
|
|
2012
1741
|
};
|
|
2013
1742
|
// Sign the action
|
|
2014
1743
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
2015
1744
|
wallet: this.wallet,
|
|
2016
|
-
action,
|
|
1745
|
+
action: signing_js_1.actionSorter[action.type](action),
|
|
2017
1746
|
nonce,
|
|
2018
1747
|
isTestnet: this.isTestnet,
|
|
2019
1748
|
expiresAfter,
|
|
@@ -2038,34 +1767,30 @@
|
|
|
2038
1767
|
* const transport = new hl.HttpTransport(); // or WebSocketTransport
|
|
2039
1768
|
* const exchClient = new hl.ExchangeClient({ wallet, transport });
|
|
2040
1769
|
*
|
|
2041
|
-
* const
|
|
1770
|
+
* const data = await exchClient.withdraw3({ destination: "0x...", amount: "1" });
|
|
2042
1771
|
* ```
|
|
2043
1772
|
*/
|
|
2044
1773
|
async withdraw3(args, signal) {
|
|
1774
|
+
// Destructure the parameters
|
|
1775
|
+
const { ...actionArgs } = args;
|
|
2045
1776
|
// Construct an action
|
|
1777
|
+
const nonce = await this.nonceManager();
|
|
2046
1778
|
const action = {
|
|
2047
|
-
...
|
|
1779
|
+
...actionArgs,
|
|
2048
1780
|
type: "withdraw3",
|
|
2049
1781
|
hyperliquidChain: this._getHyperliquidChain(),
|
|
2050
1782
|
signatureChainId: await this._getSignatureChainId(),
|
|
2051
|
-
time:
|
|
1783
|
+
time: nonce,
|
|
2052
1784
|
};
|
|
2053
1785
|
// Sign the action
|
|
2054
1786
|
const signature = await (0, signing_js_1.signUserSignedAction)({
|
|
2055
1787
|
wallet: this.wallet,
|
|
2056
1788
|
action,
|
|
2057
|
-
types:
|
|
2058
|
-
"HyperliquidTransaction:Withdraw": [
|
|
2059
|
-
{ name: "hyperliquidChain", type: "string" },
|
|
2060
|
-
{ name: "destination", type: "string" },
|
|
2061
|
-
{ name: "amount", type: "string" },
|
|
2062
|
-
{ name: "time", type: "uint64" },
|
|
2063
|
-
],
|
|
2064
|
-
},
|
|
1789
|
+
types: signing_js_1.userSignedActionEip712Types[action.type],
|
|
2065
1790
|
chainId: parseInt(action.signatureChainId, 16),
|
|
2066
1791
|
});
|
|
2067
1792
|
// Send a request
|
|
2068
|
-
return await this._request({ action, signature, nonce
|
|
1793
|
+
return await this._request({ action, signature, nonce }, signal);
|
|
2069
1794
|
}
|
|
2070
1795
|
/** Send an API request and validate the response. */
|
|
2071
1796
|
async _request(payload, signal) {
|
|
@@ -2073,18 +1798,10 @@
|
|
|
2073
1798
|
this._validateResponse(response);
|
|
2074
1799
|
return response;
|
|
2075
1800
|
}
|
|
2076
|
-
/** Formats a decimal number as a string, removing trailing zeros. */
|
|
2077
|
-
_formatDecimal(numStr) {
|
|
2078
|
-
if (!numStr.includes("."))
|
|
2079
|
-
return numStr;
|
|
2080
|
-
const [intPart, fracPart] = numStr.split(".");
|
|
2081
|
-
const newFrac = fracPart.replace(/0+$/, "");
|
|
2082
|
-
return newFrac ? `${intPart}.${newFrac}` : intPart;
|
|
2083
|
-
}
|
|
2084
1801
|
/** Guesses the chain ID based on the wallet type or the isTestnet flag. */
|
|
2085
1802
|
async _guessSignatureChainId() {
|
|
2086
1803
|
// Trying to get chain ID of the wallet
|
|
2087
|
-
if ((0, signing_js_1.isAbstractViemWalletClient)(this.wallet)
|
|
1804
|
+
if ((0, signing_js_1.isAbstractViemWalletClient)(this.wallet)) {
|
|
2088
1805
|
if ("getChainId" in this.wallet && typeof this.wallet.getChainId === "function") {
|
|
2089
1806
|
const chainId = await this.wallet.getChainId();
|
|
2090
1807
|
return `0x${chainId.toString(16)}`;
|