@nktkas/hyperliquid 0.17.4 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -36
- package/esm/deps/jsr.io/@std/async/1.0.12/delay.d.ts +43 -0
- package/esm/deps/jsr.io/@std/async/1.0.12/delay.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/async/1.0.12/delay.js +63 -0
- package/esm/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_common16.d.ts +1 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_common16.js +1 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +1 -0
- package/esm/src/base.d.ts +2 -2
- package/esm/src/base.d.ts.map +1 -1
- package/esm/src/clients/event.d.ts +2 -1
- package/esm/src/clients/event.d.ts.map +1 -1
- package/esm/src/clients/event.js +3 -0
- package/esm/src/clients/public.d.ts +2 -1
- package/esm/src/clients/public.d.ts.map +1 -1
- package/esm/src/clients/public.js +3 -0
- package/esm/src/clients/wallet.d.ts +24 -13
- package/esm/src/clients/wallet.d.ts.map +1 -1
- package/esm/src/clients/wallet.js +88 -62
- package/esm/src/signing.d.ts +4 -1
- package/esm/src/signing.d.ts.map +1 -1
- package/esm/src/signing.js +46 -23
- package/esm/src/transports/http/http_transport.d.ts +9 -60
- package/esm/src/transports/http/http_transport.d.ts.map +1 -1
- package/esm/src/transports/http/http_transport.js +9 -57
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +3 -12
- package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts +22 -44
- package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/esm/src/transports/websocket/_reconnecting_websocket.js +127 -193
- package/esm/src/transports/websocket/websocket_transport.d.ts +8 -1
- package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/esm/src/transports/websocket/websocket_transport.js +26 -21
- package/esm/src/types/exchange/requests.d.ts +26 -2
- package/esm/src/types/exchange/requests.d.ts.map +1 -1
- package/esm/src/types/exchange/responses.d.ts +6 -6
- package/esm/src/types/exchange/responses.d.ts.map +1 -1
- package/esm/src/types/info/accounts.d.ts +14 -0
- package/esm/src/types/info/accounts.d.ts.map +1 -1
- package/esm/src/types/info/assets.d.ts +18 -0
- package/esm/src/types/info/assets.d.ts.map +1 -1
- package/package.json +2 -1
- package/script/deps/jsr.io/@std/async/1.0.12/delay.d.ts +43 -0
- package/script/deps/jsr.io/@std/async/1.0.12/delay.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/async/1.0.12/delay.js +76 -0
- package/script/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_common16.d.ts +1 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_common16.js +1 -1
- package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +1 -0
- package/script/src/base.d.ts +2 -2
- package/script/src/base.d.ts.map +1 -1
- package/script/src/clients/event.d.ts +2 -1
- package/script/src/clients/event.d.ts.map +1 -1
- package/script/src/clients/event.js +3 -0
- package/script/src/clients/public.d.ts +2 -1
- package/script/src/clients/public.d.ts.map +1 -1
- package/script/src/clients/public.js +3 -0
- package/script/src/clients/wallet.d.ts +24 -13
- package/script/src/clients/wallet.d.ts.map +1 -1
- package/script/src/clients/wallet.js +88 -62
- package/script/src/signing.d.ts +4 -1
- package/script/src/signing.d.ts.map +1 -1
- package/script/src/signing.js +46 -23
- package/script/src/transports/http/http_transport.d.ts +9 -60
- package/script/src/transports/http/http_transport.d.ts.map +1 -1
- package/script/src/transports/http/http_transport.js +9 -57
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +3 -12
- package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts +22 -44
- package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
- package/script/src/transports/websocket/_reconnecting_websocket.js +129 -195
- package/script/src/transports/websocket/websocket_transport.d.ts +8 -1
- package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
- package/script/src/transports/websocket/websocket_transport.js +26 -21
- package/script/src/types/exchange/requests.d.ts +26 -2
- package/script/src/types/exchange/requests.d.ts.map +1 -1
- package/script/src/types/exchange/responses.d.ts +6 -6
- package/script/src/types/exchange/responses.d.ts.map +1 -1
- package/script/src/types/info/accounts.d.ts +14 -0
- package/script/src/types/info/accounts.d.ts.map +1 -1
- package/script/src/types/info/assets.d.ts +18 -0
- package/script/src/types/info/assets.d.ts.map +1 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.9/_common16.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.9/_common_detach.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.9/_types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/encoding/1.0.9/hex.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.9/_common16.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.9/_common_detach.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.9/_types.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/encoding/1.0.9/hex.d.ts.map +0 -1
- /package/esm/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_common_detach.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_common_detach.js +0 -0
- /package/esm/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_types.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_types.js +0 -0
- /package/esm/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/hex.d.ts +0 -0
- /package/esm/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/hex.js +0 -0
- /package/script/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_common_detach.d.ts +0 -0
- /package/script/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_common_detach.js +0 -0
- /package/script/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_types.d.ts +0 -0
- /package/script/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/_types.js +0 -0
- /package/script/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/hex.d.ts +0 -0
- /package/script/deps/jsr.io/@std/encoding/{1.0.9 → 1.0.10}/hex.js +0 -0
|
@@ -158,6 +158,13 @@
|
|
|
158
158
|
writable: true,
|
|
159
159
|
value: void 0
|
|
160
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
|
+
});
|
|
161
168
|
/**
|
|
162
169
|
* The network that will be used to sign transactions.
|
|
163
170
|
* Must match the network of the {@link wallet}.
|
|
@@ -179,6 +186,7 @@
|
|
|
179
186
|
this.wallet = args.wallet;
|
|
180
187
|
this.isTestnet = args.isTestnet ?? false;
|
|
181
188
|
this.defaultVaultAddress = args.defaultVaultAddress;
|
|
189
|
+
this.defaultExpiresAfter = args.defaultExpiresAfter;
|
|
182
190
|
this.signatureChainId = args.signatureChainId ?? this._guessSignatureChainId;
|
|
183
191
|
this.nonceManager = args.nonceManager ?? new NonceManager().getNonce;
|
|
184
192
|
}
|
|
@@ -206,11 +214,10 @@
|
|
|
206
214
|
// Construct an action
|
|
207
215
|
const action = {
|
|
208
216
|
...args,
|
|
217
|
+
agentName: args.agentName ?? "",
|
|
209
218
|
type: "approveAgent",
|
|
210
|
-
hyperliquidChain: this.
|
|
211
|
-
signatureChainId:
|
|
212
|
-
? this.signatureChainId
|
|
213
|
-
: await this.signatureChainId(),
|
|
219
|
+
hyperliquidChain: this._getHyperliquidChain(),
|
|
220
|
+
signatureChainId: await this._getSignatureChainId(),
|
|
214
221
|
nonce: await this.nonceManager(),
|
|
215
222
|
};
|
|
216
223
|
// Sign the action
|
|
@@ -227,6 +234,8 @@
|
|
|
227
234
|
},
|
|
228
235
|
chainId: parseInt(action.signatureChainId, 16),
|
|
229
236
|
});
|
|
237
|
+
if (action.agentName === "")
|
|
238
|
+
delete action.agentName;
|
|
230
239
|
// Send a request
|
|
231
240
|
const request = { action, signature, nonce: action.nonce };
|
|
232
241
|
const response = await this.transport.request("exchange", request, signal);
|
|
@@ -259,10 +268,8 @@
|
|
|
259
268
|
const action = {
|
|
260
269
|
...args,
|
|
261
270
|
type: "approveBuilderFee",
|
|
262
|
-
hyperliquidChain: this.
|
|
263
|
-
signatureChainId:
|
|
264
|
-
? this.signatureChainId
|
|
265
|
-
: await this.signatureChainId(),
|
|
271
|
+
hyperliquidChain: this._getHyperliquidChain(),
|
|
272
|
+
signatureChainId: await this._getSignatureChainId(),
|
|
266
273
|
nonce: await this.nonceManager(),
|
|
267
274
|
};
|
|
268
275
|
// Sign the action
|
|
@@ -325,7 +332,7 @@
|
|
|
325
332
|
*/
|
|
326
333
|
async batchModify(args, signal) {
|
|
327
334
|
// Destructure the parameters
|
|
328
|
-
const { vaultAddress = this.defaultVaultAddress, ...actionArgs } = args;
|
|
335
|
+
const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
|
|
329
336
|
// Construct an action
|
|
330
337
|
const nonce = await this.nonceManager();
|
|
331
338
|
const action = {
|
|
@@ -367,9 +374,10 @@
|
|
|
367
374
|
nonce,
|
|
368
375
|
isTestnet: this.isTestnet,
|
|
369
376
|
vaultAddress,
|
|
377
|
+
expiresAfter,
|
|
370
378
|
});
|
|
371
379
|
// Send a request
|
|
372
|
-
const request = { action, signature, nonce, vaultAddress };
|
|
380
|
+
const request = { action, signature, nonce, vaultAddress, expiresAfter };
|
|
373
381
|
const response = await this.transport.request("exchange", request, signal);
|
|
374
382
|
// Validate a response
|
|
375
383
|
this._validateResponse(response);
|
|
@@ -402,7 +410,7 @@
|
|
|
402
410
|
*/
|
|
403
411
|
async cancel(args, signal) {
|
|
404
412
|
// Destructure the parameters
|
|
405
|
-
const { vaultAddress = this.defaultVaultAddress, ...actionArgs } = args;
|
|
413
|
+
const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
|
|
406
414
|
// Construct an action
|
|
407
415
|
const nonce = await this.nonceManager();
|
|
408
416
|
const action = {
|
|
@@ -419,9 +427,10 @@
|
|
|
419
427
|
nonce,
|
|
420
428
|
isTestnet: this.isTestnet,
|
|
421
429
|
vaultAddress,
|
|
430
|
+
expiresAfter,
|
|
422
431
|
});
|
|
423
432
|
// Send a request
|
|
424
|
-
const request = { action, signature, nonce, vaultAddress };
|
|
433
|
+
const request = { action, signature, nonce, vaultAddress, expiresAfter };
|
|
425
434
|
const response = await this.transport.request("exchange", request, signal);
|
|
426
435
|
// Validate a response
|
|
427
436
|
this._validateResponse(response);
|
|
@@ -453,7 +462,7 @@
|
|
|
453
462
|
*/
|
|
454
463
|
async cancelByCloid(args, signal) {
|
|
455
464
|
// Destructure the parameters
|
|
456
|
-
const { vaultAddress = this.defaultVaultAddress, ...actionArgs } = args;
|
|
465
|
+
const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
|
|
457
466
|
// Construct an action
|
|
458
467
|
const nonce = await this.nonceManager();
|
|
459
468
|
const action = {
|
|
@@ -470,9 +479,10 @@
|
|
|
470
479
|
nonce,
|
|
471
480
|
isTestnet: this.isTestnet,
|
|
472
481
|
vaultAddress,
|
|
482
|
+
expiresAfter,
|
|
473
483
|
});
|
|
474
484
|
// Send a request
|
|
475
|
-
const request = { action, signature, nonce, vaultAddress };
|
|
485
|
+
const request = { action, signature, nonce, vaultAddress, expiresAfter };
|
|
476
486
|
const response = await this.transport.request("exchange", request, signal);
|
|
477
487
|
// Validate a response
|
|
478
488
|
this._validateResponse(response);
|
|
@@ -503,10 +513,8 @@
|
|
|
503
513
|
const action = {
|
|
504
514
|
...args,
|
|
505
515
|
type: "cDeposit",
|
|
506
|
-
hyperliquidChain: this.
|
|
507
|
-
signatureChainId:
|
|
508
|
-
? this.signatureChainId
|
|
509
|
-
: await this.signatureChainId(),
|
|
516
|
+
hyperliquidChain: this._getHyperliquidChain(),
|
|
517
|
+
signatureChainId: await this._getSignatureChainId(),
|
|
510
518
|
nonce: await this.nonceManager(),
|
|
511
519
|
};
|
|
512
520
|
// Sign the action
|
|
@@ -681,10 +689,8 @@
|
|
|
681
689
|
const action = {
|
|
682
690
|
...args,
|
|
683
691
|
type: "cWithdraw",
|
|
684
|
-
hyperliquidChain: this.
|
|
685
|
-
signatureChainId:
|
|
686
|
-
? this.signatureChainId
|
|
687
|
-
: await this.signatureChainId(),
|
|
692
|
+
hyperliquidChain: this._getHyperliquidChain(),
|
|
693
|
+
signatureChainId: await this._getSignatureChainId(),
|
|
688
694
|
nonce: await this.nonceManager(),
|
|
689
695
|
};
|
|
690
696
|
// Sign the action
|
|
@@ -785,7 +791,7 @@
|
|
|
785
791
|
*/
|
|
786
792
|
async modify(args, signal) {
|
|
787
793
|
// Destructure the parameters
|
|
788
|
-
const { vaultAddress = this.defaultVaultAddress, ...actionArgs } = args;
|
|
794
|
+
const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
|
|
789
795
|
// Construct an action
|
|
790
796
|
const nonce = await this.nonceManager();
|
|
791
797
|
const action = {
|
|
@@ -822,9 +828,10 @@
|
|
|
822
828
|
nonce,
|
|
823
829
|
isTestnet: this.isTestnet,
|
|
824
830
|
vaultAddress,
|
|
831
|
+
expiresAfter,
|
|
825
832
|
});
|
|
826
833
|
// Send a request
|
|
827
|
-
const request = { action, signature, nonce, vaultAddress };
|
|
834
|
+
const request = { action, signature, nonce, vaultAddress, expiresAfter };
|
|
828
835
|
const response = await this.transport.request("exchange", request, signal);
|
|
829
836
|
// Validate a response
|
|
830
837
|
this._validateResponse(response);
|
|
@@ -867,7 +874,7 @@
|
|
|
867
874
|
*/
|
|
868
875
|
async order(args, signal) {
|
|
869
876
|
// Destructure the parameters
|
|
870
|
-
const { vaultAddress = this.defaultVaultAddress, ...actionArgs } = args;
|
|
877
|
+
const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
|
|
871
878
|
// Construct an action
|
|
872
879
|
const nonce = await this.nonceManager();
|
|
873
880
|
const action = {
|
|
@@ -915,9 +922,10 @@
|
|
|
915
922
|
nonce,
|
|
916
923
|
isTestnet: this.isTestnet,
|
|
917
924
|
vaultAddress,
|
|
925
|
+
expiresAfter,
|
|
918
926
|
});
|
|
919
927
|
// Send a request
|
|
920
|
-
const request = { action, signature, nonce, vaultAddress };
|
|
928
|
+
const request = { action, signature, nonce, vaultAddress, expiresAfter };
|
|
921
929
|
const response = await this.transport.request("exchange", request, signal);
|
|
922
930
|
// Validate a response
|
|
923
931
|
this._validateResponse(response);
|
|
@@ -985,11 +993,13 @@
|
|
|
985
993
|
* ```
|
|
986
994
|
*/
|
|
987
995
|
async reserveRequestWeight(args, signal) {
|
|
996
|
+
// Destructure the parameters
|
|
997
|
+
const { expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
|
|
988
998
|
// Construct an action
|
|
989
999
|
const nonce = await this.nonceManager();
|
|
990
1000
|
const action = {
|
|
991
1001
|
type: "reserveRequestWeight",
|
|
992
|
-
weight:
|
|
1002
|
+
weight: actionArgs.weight,
|
|
993
1003
|
};
|
|
994
1004
|
// Sign the action
|
|
995
1005
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
@@ -997,9 +1007,10 @@
|
|
|
997
1007
|
action,
|
|
998
1008
|
nonce,
|
|
999
1009
|
isTestnet: this.isTestnet,
|
|
1010
|
+
expiresAfter,
|
|
1000
1011
|
});
|
|
1001
1012
|
// Send a request
|
|
1002
|
-
const request = { action, signature, nonce };
|
|
1013
|
+
const request = { action, signature, nonce, expiresAfter };
|
|
1003
1014
|
const response = await this.transport.request("exchange", request, signal);
|
|
1004
1015
|
// Validate a response
|
|
1005
1016
|
this._validateResponse(response);
|
|
@@ -1027,7 +1038,7 @@
|
|
|
1027
1038
|
*/
|
|
1028
1039
|
async scheduleCancel(args = {}, signal) {
|
|
1029
1040
|
// Destructure the parameters
|
|
1030
|
-
const { vaultAddress = this.defaultVaultAddress, ...actionArgs } = args;
|
|
1041
|
+
const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
|
|
1031
1042
|
// Construct an action
|
|
1032
1043
|
const nonce = await this.nonceManager();
|
|
1033
1044
|
const action = {
|
|
@@ -1043,9 +1054,10 @@
|
|
|
1043
1054
|
nonce,
|
|
1044
1055
|
isTestnet: this.isTestnet,
|
|
1045
1056
|
vaultAddress,
|
|
1057
|
+
expiresAfter,
|
|
1046
1058
|
});
|
|
1047
1059
|
// Send a request
|
|
1048
|
-
const request = { action, signature, nonce, vaultAddress };
|
|
1060
|
+
const request = { action, signature, nonce, vaultAddress, expiresAfter };
|
|
1049
1061
|
const response = await this.transport.request("exchange", request, signal);
|
|
1050
1062
|
// Validate a response
|
|
1051
1063
|
this._validateResponse(response);
|
|
@@ -1264,10 +1276,8 @@
|
|
|
1264
1276
|
const action = {
|
|
1265
1277
|
...args,
|
|
1266
1278
|
type: "spotSend",
|
|
1267
|
-
hyperliquidChain: this.
|
|
1268
|
-
signatureChainId:
|
|
1269
|
-
? this.signatureChainId
|
|
1270
|
-
: await this.signatureChainId(),
|
|
1279
|
+
hyperliquidChain: this._getHyperliquidChain(),
|
|
1280
|
+
signatureChainId: await this._getSignatureChainId(),
|
|
1271
1281
|
time: await this.nonceManager(),
|
|
1272
1282
|
};
|
|
1273
1283
|
// Sign the action
|
|
@@ -1460,10 +1470,8 @@
|
|
|
1460
1470
|
const action = {
|
|
1461
1471
|
...args,
|
|
1462
1472
|
type: "tokenDelegate",
|
|
1463
|
-
hyperliquidChain: this.
|
|
1464
|
-
signatureChainId:
|
|
1465
|
-
? this.signatureChainId
|
|
1466
|
-
: await this.signatureChainId(),
|
|
1473
|
+
hyperliquidChain: this._getHyperliquidChain(),
|
|
1474
|
+
signatureChainId: await this._getSignatureChainId(),
|
|
1467
1475
|
nonce: await this.nonceManager(),
|
|
1468
1476
|
};
|
|
1469
1477
|
// Sign the action
|
|
@@ -1513,7 +1521,7 @@
|
|
|
1513
1521
|
*/
|
|
1514
1522
|
async twapCancel(args, signal) {
|
|
1515
1523
|
// Destructure the parameters
|
|
1516
|
-
const { vaultAddress = this.defaultVaultAddress, ...actionArgs } = args;
|
|
1524
|
+
const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
|
|
1517
1525
|
// Construct an action
|
|
1518
1526
|
const nonce = await this.nonceManager();
|
|
1519
1527
|
const action = {
|
|
@@ -1528,9 +1536,10 @@
|
|
|
1528
1536
|
nonce,
|
|
1529
1537
|
isTestnet: this.isTestnet,
|
|
1530
1538
|
vaultAddress,
|
|
1539
|
+
expiresAfter,
|
|
1531
1540
|
});
|
|
1532
1541
|
// Send a request
|
|
1533
|
-
const request = { action, signature, nonce, vaultAddress };
|
|
1542
|
+
const request = { action, signature, nonce, vaultAddress, expiresAfter };
|
|
1534
1543
|
const response = await this.transport.request("exchange", request, signal);
|
|
1535
1544
|
// Validate a response
|
|
1536
1545
|
this._validateResponse(response);
|
|
@@ -1565,7 +1574,7 @@
|
|
|
1565
1574
|
*/
|
|
1566
1575
|
async twapOrder(args, signal) {
|
|
1567
1576
|
// Destructure the parameters
|
|
1568
|
-
const { vaultAddress = this.defaultVaultAddress, ...actionArgs } = args;
|
|
1577
|
+
const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
|
|
1569
1578
|
// Construct an action
|
|
1570
1579
|
const nonce = await this.nonceManager();
|
|
1571
1580
|
const action = {
|
|
@@ -1586,9 +1595,10 @@
|
|
|
1586
1595
|
nonce,
|
|
1587
1596
|
isTestnet: this.isTestnet,
|
|
1588
1597
|
vaultAddress,
|
|
1598
|
+
expiresAfter,
|
|
1589
1599
|
});
|
|
1590
1600
|
// Send a request
|
|
1591
|
-
const request = { action, signature, nonce, vaultAddress };
|
|
1601
|
+
const request = { action, signature, nonce, vaultAddress, expiresAfter };
|
|
1592
1602
|
const response = await this.transport.request("exchange", request, signal);
|
|
1593
1603
|
// Validate a response
|
|
1594
1604
|
this._validateResponse(response);
|
|
@@ -1616,7 +1626,7 @@
|
|
|
1616
1626
|
*/
|
|
1617
1627
|
async updateIsolatedMargin(args, signal) {
|
|
1618
1628
|
// Destructure the parameters
|
|
1619
|
-
const { vaultAddress = this.defaultVaultAddress, ...actionArgs } = args;
|
|
1629
|
+
const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
|
|
1620
1630
|
// Construct an action
|
|
1621
1631
|
const nonce = await this.nonceManager();
|
|
1622
1632
|
const action = {
|
|
@@ -1632,9 +1642,10 @@
|
|
|
1632
1642
|
nonce,
|
|
1633
1643
|
isTestnet: this.isTestnet,
|
|
1634
1644
|
vaultAddress,
|
|
1645
|
+
expiresAfter,
|
|
1635
1646
|
});
|
|
1636
1647
|
// Send a request
|
|
1637
|
-
const request = { action, signature, nonce, vaultAddress };
|
|
1648
|
+
const request = { action, signature, nonce, vaultAddress, expiresAfter };
|
|
1638
1649
|
const response = await this.transport.request("exchange", request, signal);
|
|
1639
1650
|
// Validate a response
|
|
1640
1651
|
this._validateResponse(response);
|
|
@@ -1662,7 +1673,7 @@
|
|
|
1662
1673
|
*/
|
|
1663
1674
|
async updateLeverage(args, signal) {
|
|
1664
1675
|
// Destructure the parameters
|
|
1665
|
-
const { vaultAddress = this.defaultVaultAddress, ...actionArgs } = args;
|
|
1676
|
+
const { vaultAddress = this.defaultVaultAddress, expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
|
|
1666
1677
|
// Construct an action
|
|
1667
1678
|
const nonce = await this.nonceManager();
|
|
1668
1679
|
const action = {
|
|
@@ -1678,9 +1689,10 @@
|
|
|
1678
1689
|
nonce,
|
|
1679
1690
|
isTestnet: this.isTestnet,
|
|
1680
1691
|
vaultAddress,
|
|
1692
|
+
expiresAfter,
|
|
1681
1693
|
});
|
|
1682
1694
|
// Send a request
|
|
1683
|
-
const request = { action, signature, nonce, vaultAddress };
|
|
1695
|
+
const request = { action, signature, nonce, vaultAddress, expiresAfter };
|
|
1684
1696
|
const response = await this.transport.request("exchange", request, signal);
|
|
1685
1697
|
// Validate a response
|
|
1686
1698
|
this._validateResponse(response);
|
|
@@ -1711,10 +1723,8 @@
|
|
|
1711
1723
|
const action = {
|
|
1712
1724
|
...args,
|
|
1713
1725
|
type: "usdClassTransfer",
|
|
1714
|
-
hyperliquidChain: this.
|
|
1715
|
-
signatureChainId:
|
|
1716
|
-
? this.signatureChainId
|
|
1717
|
-
: await this.signatureChainId(),
|
|
1726
|
+
hyperliquidChain: this._getHyperliquidChain(),
|
|
1727
|
+
signatureChainId: await this._getSignatureChainId(),
|
|
1718
1728
|
nonce: await this.nonceManager(),
|
|
1719
1729
|
};
|
|
1720
1730
|
// Sign the action
|
|
@@ -1763,10 +1773,8 @@
|
|
|
1763
1773
|
const action = {
|
|
1764
1774
|
...args,
|
|
1765
1775
|
type: "usdSend",
|
|
1766
|
-
hyperliquidChain: this.
|
|
1767
|
-
signatureChainId:
|
|
1768
|
-
? this.signatureChainId
|
|
1769
|
-
: await this.signatureChainId(),
|
|
1776
|
+
hyperliquidChain: this._getHyperliquidChain(),
|
|
1777
|
+
signatureChainId: await this._getSignatureChainId(),
|
|
1770
1778
|
time: await this.nonceManager(),
|
|
1771
1779
|
};
|
|
1772
1780
|
// Sign the action
|
|
@@ -1904,13 +1912,15 @@
|
|
|
1904
1912
|
* ```
|
|
1905
1913
|
*/
|
|
1906
1914
|
async vaultTransfer(args, signal) {
|
|
1915
|
+
// Destructure the parameters
|
|
1916
|
+
const { expiresAfter = await this._getDefaultExpiresAfter(), ...actionArgs } = args;
|
|
1907
1917
|
// Construct an action
|
|
1908
1918
|
const nonce = await this.nonceManager();
|
|
1909
1919
|
const action = {
|
|
1910
1920
|
type: "vaultTransfer",
|
|
1911
|
-
vaultAddress:
|
|
1912
|
-
isDeposit:
|
|
1913
|
-
usd:
|
|
1921
|
+
vaultAddress: actionArgs.vaultAddress,
|
|
1922
|
+
isDeposit: actionArgs.isDeposit,
|
|
1923
|
+
usd: actionArgs.usd,
|
|
1914
1924
|
};
|
|
1915
1925
|
// Sign the action
|
|
1916
1926
|
const signature = await (0, signing_js_1.signL1Action)({
|
|
@@ -1918,9 +1928,10 @@
|
|
|
1918
1928
|
action,
|
|
1919
1929
|
nonce,
|
|
1920
1930
|
isTestnet: this.isTestnet,
|
|
1931
|
+
expiresAfter,
|
|
1921
1932
|
});
|
|
1922
1933
|
// Send a request
|
|
1923
|
-
const request = { action, signature, nonce };
|
|
1934
|
+
const request = { action, signature, nonce, expiresAfter };
|
|
1924
1935
|
const response = await this.transport.request("exchange", request, signal);
|
|
1925
1936
|
// Validate a response
|
|
1926
1937
|
this._validateResponse(response);
|
|
@@ -1951,10 +1962,8 @@
|
|
|
1951
1962
|
const action = {
|
|
1952
1963
|
...args,
|
|
1953
1964
|
type: "withdraw3",
|
|
1954
|
-
hyperliquidChain: this.
|
|
1955
|
-
signatureChainId:
|
|
1956
|
-
? this.signatureChainId
|
|
1957
|
-
: await this.signatureChainId(),
|
|
1965
|
+
hyperliquidChain: this._getHyperliquidChain(),
|
|
1966
|
+
signatureChainId: await this._getSignatureChainId(),
|
|
1958
1967
|
time: await this.nonceManager(),
|
|
1959
1968
|
};
|
|
1960
1969
|
// Sign the action
|
|
@@ -2011,6 +2020,20 @@
|
|
|
2011
2020
|
// Attempt to guess chain ID based on isTestnet
|
|
2012
2021
|
return this.isTestnet ? "0x66eee" : "0xa4b1";
|
|
2013
2022
|
}
|
|
2023
|
+
/** Get the default expiration time for an action. */
|
|
2024
|
+
async _getDefaultExpiresAfter() {
|
|
2025
|
+
return typeof this.defaultExpiresAfter === "number"
|
|
2026
|
+
? this.defaultExpiresAfter
|
|
2027
|
+
: await this.defaultExpiresAfter?.();
|
|
2028
|
+
}
|
|
2029
|
+
/** Get the signature chain ID for the wallet. */
|
|
2030
|
+
async _getSignatureChainId() {
|
|
2031
|
+
return typeof this.signatureChainId === "string" ? this.signatureChainId : await this.signatureChainId();
|
|
2032
|
+
}
|
|
2033
|
+
/** Get the Hyperliquid chain based on the isTestnet flag. */
|
|
2034
|
+
_getHyperliquidChain() {
|
|
2035
|
+
return this.isTestnet ? "Testnet" : "Mainnet";
|
|
2036
|
+
}
|
|
2014
2037
|
/** Validate a response from the API. */
|
|
2015
2038
|
_validateResponse(response) {
|
|
2016
2039
|
if (response.status === "err") {
|
|
@@ -2027,6 +2050,9 @@
|
|
|
2027
2050
|
}
|
|
2028
2051
|
}
|
|
2029
2052
|
}
|
|
2053
|
+
async [Symbol.asyncDispose]() {
|
|
2054
|
+
await this.transport[Symbol.asyncDispose]?.();
|
|
2055
|
+
}
|
|
2030
2056
|
}
|
|
2031
2057
|
exports.WalletClient = WalletClient;
|
|
2032
2058
|
});
|
package/script/src/signing.d.ts
CHANGED
|
@@ -131,9 +131,10 @@ export interface AbstractWindowEthereum {
|
|
|
131
131
|
* @param action - The action to be hashed.
|
|
132
132
|
* @param nonce - Unique request identifier (recommended current timestamp in ms).
|
|
133
133
|
* @param vaultAddress - Optional vault address used in the action.
|
|
134
|
+
* @param expiresAfter - Optional expiration time of the action in milliseconds since the epoch.
|
|
134
135
|
* @returns The hash of the action.
|
|
135
136
|
*/
|
|
136
|
-
export declare function createL1ActionHash(action: ValueType, nonce: number, vaultAddress?: Hex): Hex;
|
|
137
|
+
export declare function createL1ActionHash(action: ValueType, nonce: number, vaultAddress?: Hex, expiresAfter?: number): Hex;
|
|
137
138
|
/**
|
|
138
139
|
* Sign an L1 action.
|
|
139
140
|
*
|
|
@@ -181,6 +182,8 @@ export declare function signL1Action(args: {
|
|
|
181
182
|
isTestnet?: boolean;
|
|
182
183
|
/** Optional vault address used in the action. */
|
|
183
184
|
vaultAddress?: Hex;
|
|
185
|
+
/** Optional expiration time of the action in milliseconds since the epoch. */
|
|
186
|
+
expiresAfter?: number;
|
|
184
187
|
}): Promise<{
|
|
185
188
|
r: Hex;
|
|
186
189
|
s: Hex;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../src/src/signing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAGH,OAAO,
|
|
1
|
+
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../src/src/signing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAGH,OAAO,EAA2B,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,6CAA6C,CAAC;AAGrH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAErC,YAAY,EAAE,GAAG,EAAE,CAAC;AACpB,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;AAEpC,mFAAmF;AACnF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AAED,qGAAqG;AACrG,wBAAgB,kCAAkC,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,wBAAwB,CAItG;AAED,yEAAyE;AACzE,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,sBAAsB,CAI1F"}
|
package/script/src/signing.js
CHANGED
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
if (v !== undefined) module.exports = v;
|
|
54
54
|
}
|
|
55
55
|
else if (typeof define === "function" && define.amd) {
|
|
56
|
-
define(["require", "exports", "../deps/jsr.io/@noble/hashes/1.8.0/src/sha3.js", "../deps/jsr.io/@std/msgpack/1.0.3/encode.js", "../deps/jsr.io/@std/encoding/1.0.
|
|
56
|
+
define(["require", "exports", "../deps/jsr.io/@noble/hashes/1.8.0/src/sha3.js", "../deps/jsr.io/@std/msgpack/1.0.3/encode.js", "../deps/jsr.io/@std/encoding/1.0.10/hex.js", "../deps/jsr.io/@std/bytes/1.0.5/concat.js"], factory);
|
|
57
57
|
}
|
|
58
58
|
})(function (require, exports) {
|
|
59
59
|
"use strict";
|
|
@@ -68,7 +68,8 @@
|
|
|
68
68
|
exports.isAbstractWindowEthereum = isAbstractWindowEthereum;
|
|
69
69
|
const sha3_js_1 = require("../deps/jsr.io/@noble/hashes/1.8.0/src/sha3.js");
|
|
70
70
|
const encode_js_1 = require("../deps/jsr.io/@std/msgpack/1.0.3/encode.js");
|
|
71
|
-
const hex_js_1 = require("../deps/jsr.io/@std/encoding/1.0.
|
|
71
|
+
const hex_js_1 = require("../deps/jsr.io/@std/encoding/1.0.10/hex.js");
|
|
72
|
+
const concat_js_1 = require("../deps/jsr.io/@std/bytes/1.0.5/concat.js");
|
|
72
73
|
/**
|
|
73
74
|
* Create a hash of the L1 action.
|
|
74
75
|
*
|
|
@@ -76,26 +77,36 @@
|
|
|
76
77
|
* @param action - The action to be hashed.
|
|
77
78
|
* @param nonce - Unique request identifier (recommended current timestamp in ms).
|
|
78
79
|
* @param vaultAddress - Optional vault address used in the action.
|
|
80
|
+
* @param expiresAfter - Optional expiration time of the action in milliseconds since the epoch.
|
|
79
81
|
* @returns The hash of the action.
|
|
80
82
|
*/
|
|
81
|
-
function createL1ActionHash(action, nonce, vaultAddress) {
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
83
|
+
function createL1ActionHash(action, nonce, vaultAddress, expiresAfter) {
|
|
84
|
+
// 1. Action
|
|
85
|
+
const actionBytes = (0, encode_js_1.encode)(normalizeIntegersForMsgPack(action));
|
|
86
|
+
// 2. Nonce
|
|
87
|
+
const nonceBytes = new Uint8Array(8);
|
|
88
|
+
new DataView(nonceBytes.buffer).setBigUint64(0, BigInt(nonce));
|
|
89
|
+
// 3. Vault address
|
|
90
|
+
const vaultMarker = Uint8Array.of(vaultAddress ? 0x01 : 0x00);
|
|
91
|
+
const vaultBytes = vaultAddress ? (0, hex_js_1.decodeHex)(vaultAddress.slice(2)) : new Uint8Array();
|
|
92
|
+
// 4. Expires after
|
|
93
|
+
const expiresMarker = new Uint8Array(expiresAfter !== undefined ? 1 : 0);
|
|
94
|
+
const expiresBytes = new Uint8Array(expiresAfter !== undefined ? 8 : 0);
|
|
95
|
+
if (expiresAfter !== undefined) {
|
|
96
|
+
new DataView(expiresBytes.buffer).setBigUint64(0, BigInt(expiresAfter));
|
|
92
97
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
// Create a keccak256 hash
|
|
99
|
+
const chunks = [
|
|
100
|
+
actionBytes,
|
|
101
|
+
nonceBytes,
|
|
102
|
+
vaultMarker,
|
|
103
|
+
vaultBytes,
|
|
104
|
+
expiresMarker,
|
|
105
|
+
expiresBytes,
|
|
106
|
+
];
|
|
107
|
+
const bytes = (0, concat_js_1.concat)(chunks);
|
|
108
|
+
const hash = (0, sha3_js_1.keccak_256)(bytes);
|
|
109
|
+
return `0x${(0, hex_js_1.encodeHex)(hash)}`;
|
|
99
110
|
}
|
|
100
111
|
/** Layer to make {@link https://jsr.io/@std/msgpack | @std/msgpack} compatible with {@link https://github.com/msgpack/msgpack-javascript | @msgpack/msgpack}. */
|
|
101
112
|
function normalizeIntegersForMsgPack(obj) {
|
|
@@ -151,7 +162,7 @@
|
|
|
151
162
|
* ```
|
|
152
163
|
*/
|
|
153
164
|
async function signL1Action(args) {
|
|
154
|
-
const { wallet, action, nonce, isTestnet = false, vaultAddress, } = args;
|
|
165
|
+
const { wallet, action, nonce, isTestnet = false, vaultAddress, expiresAfter, } = args;
|
|
155
166
|
const domain = {
|
|
156
167
|
name: "Exchange",
|
|
157
168
|
version: "1",
|
|
@@ -164,7 +175,7 @@
|
|
|
164
175
|
{ name: "connectionId", type: "bytes32" },
|
|
165
176
|
],
|
|
166
177
|
};
|
|
167
|
-
const actionHash = createL1ActionHash(action, nonce, vaultAddress);
|
|
178
|
+
const actionHash = createL1ActionHash(action, nonce, vaultAddress, expiresAfter);
|
|
168
179
|
const message = {
|
|
169
180
|
source: isTestnet ? "b" : "a",
|
|
170
181
|
connectionId: actionHash,
|
|
@@ -231,8 +242,20 @@
|
|
|
231
242
|
async function abstractSignTypedData(args) {
|
|
232
243
|
const { wallet, domain, types, message } = args;
|
|
233
244
|
if (isAbstractViemWalletClient(wallet) || isAbstractExtendedViemWalletClient(wallet)) {
|
|
234
|
-
|
|
235
|
-
|
|
245
|
+
return await wallet.signTypedData({
|
|
246
|
+
domain,
|
|
247
|
+
types: {
|
|
248
|
+
EIP712Domain: [
|
|
249
|
+
{ name: "name", type: "string" },
|
|
250
|
+
{ name: "version", type: "string" },
|
|
251
|
+
{ name: "chainId", type: "uint256" },
|
|
252
|
+
{ name: "verifyingContract", type: "address" },
|
|
253
|
+
],
|
|
254
|
+
...types,
|
|
255
|
+
},
|
|
256
|
+
primaryType: Object.keys(types)[0],
|
|
257
|
+
message,
|
|
258
|
+
});
|
|
236
259
|
}
|
|
237
260
|
else if (isAbstractEthersSigner(wallet)) {
|
|
238
261
|
return await wallet.signTypedData(domain, types, message);
|