@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
package/script/src/signing.js
CHANGED
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
})(function (require, exports) {
|
|
61
61
|
"use strict";
|
|
62
62
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
63
|
+
exports.userSignedActionEip712Types = exports.actionSorter = void 0;
|
|
63
64
|
exports.createL1ActionHash = createL1ActionHash;
|
|
64
65
|
exports.signL1Action = signL1Action;
|
|
65
66
|
exports.signUserSignedAction = signUserSignedAction;
|
|
@@ -67,7 +68,6 @@
|
|
|
67
68
|
exports.isAbstractViemWalletClient = isAbstractViemWalletClient;
|
|
68
69
|
exports.isAbstractEthersSigner = isAbstractEthersSigner;
|
|
69
70
|
exports.isAbstractEthersV5Signer = isAbstractEthersV5Signer;
|
|
70
|
-
exports.isAbstractExtendedViemWalletClient = isAbstractExtendedViemWalletClient;
|
|
71
71
|
exports.isAbstractWindowEthereum = isAbstractWindowEthereum;
|
|
72
72
|
const sha3_1 = require("@noble/hashes/sha3");
|
|
73
73
|
const encode_js_1 = require("../deps/jsr.io/@std/msgpack/1.0.3/encode.js");
|
|
@@ -303,7 +303,6 @@
|
|
|
303
303
|
* signatureChainId: "0x66eee",
|
|
304
304
|
* });
|
|
305
305
|
* ```
|
|
306
|
-
* @unstable May not behave as expected and the interface may change in the future.
|
|
307
306
|
*/
|
|
308
307
|
async function signMultiSigAction(args) {
|
|
309
308
|
const { wallet, action, nonce, hyperliquidChain, signatureChainId, vaultAddress, expiresAfter, } = args;
|
|
@@ -330,7 +329,7 @@
|
|
|
330
329
|
/** Signs typed data with the provided wallet using EIP-712. */
|
|
331
330
|
async function abstractSignTypedData(args) {
|
|
332
331
|
const { wallet, domain, types, message } = args;
|
|
333
|
-
if (isAbstractViemWalletClient(wallet)
|
|
332
|
+
if (isAbstractViemWalletClient(wallet)) {
|
|
334
333
|
return await wallet.signTypedData({
|
|
335
334
|
domain,
|
|
336
335
|
types: {
|
|
@@ -399,7 +398,7 @@
|
|
|
399
398
|
function isAbstractViemWalletClient(client) {
|
|
400
399
|
return typeof client === "object" && client !== null &&
|
|
401
400
|
"signTypedData" in client && typeof client.signTypedData === "function" &&
|
|
402
|
-
client.signTypedData.length === 1;
|
|
401
|
+
(client.signTypedData.length === 1 || client.signTypedData.length === 2);
|
|
403
402
|
}
|
|
404
403
|
/** Checks if the given value is an abstract ethers signer. */
|
|
405
404
|
function isAbstractEthersSigner(client) {
|
|
@@ -413,16 +412,718 @@
|
|
|
413
412
|
"_signTypedData" in client && typeof client._signTypedData === "function" &&
|
|
414
413
|
client._signTypedData.length === 3;
|
|
415
414
|
}
|
|
416
|
-
/** Checks if the given value is an abstract extended viem wallet (e.g. privy `useSignTypedData`). */
|
|
417
|
-
function isAbstractExtendedViemWalletClient(client) {
|
|
418
|
-
return typeof client === "object" && client !== null &&
|
|
419
|
-
"signTypedData" in client && typeof client.signTypedData === "function" &&
|
|
420
|
-
client.signTypedData.length === 2;
|
|
421
|
-
}
|
|
422
415
|
/** Checks if the given value is an abstract `window.ethereum` object. */
|
|
423
416
|
function isAbstractWindowEthereum(client) {
|
|
424
417
|
return typeof client === "object" && client !== null &&
|
|
425
418
|
"request" in client && typeof client.request === "function" &&
|
|
426
419
|
client.request.length >= 1;
|
|
427
420
|
}
|
|
421
|
+
/** Action sorter for correct signature generation. */
|
|
422
|
+
exports.actionSorter = {
|
|
423
|
+
/** Sorts and formats an `approveAgent` action. */
|
|
424
|
+
approveAgent: (action) => {
|
|
425
|
+
return {
|
|
426
|
+
type: action.type,
|
|
427
|
+
signatureChainId: action.signatureChainId,
|
|
428
|
+
hyperliquidChain: action.hyperliquidChain,
|
|
429
|
+
agentAddress: action.agentAddress.toLowerCase(),
|
|
430
|
+
agentName: action.agentName,
|
|
431
|
+
nonce: action.nonce,
|
|
432
|
+
};
|
|
433
|
+
},
|
|
434
|
+
/** Sorts and formats an `approveBuilderFee` action. */
|
|
435
|
+
approveBuilderFee: (action) => {
|
|
436
|
+
return {
|
|
437
|
+
type: action.type,
|
|
438
|
+
signatureChainId: action.signatureChainId,
|
|
439
|
+
hyperliquidChain: action.hyperliquidChain,
|
|
440
|
+
maxFeeRate: action.maxFeeRate,
|
|
441
|
+
builder: action.builder.toLowerCase(),
|
|
442
|
+
nonce: action.nonce,
|
|
443
|
+
};
|
|
444
|
+
},
|
|
445
|
+
/** Sorts and formats a `batchModify` action. */
|
|
446
|
+
batchModify: (action) => {
|
|
447
|
+
return {
|
|
448
|
+
type: action.type,
|
|
449
|
+
modifies: action.modifies.map((modify) => {
|
|
450
|
+
const sortedModify = {
|
|
451
|
+
oid: modify.oid,
|
|
452
|
+
order: {
|
|
453
|
+
a: modify.order.a,
|
|
454
|
+
b: modify.order.b,
|
|
455
|
+
p: formatDecimal(modify.order.p),
|
|
456
|
+
s: formatDecimal(modify.order.s),
|
|
457
|
+
r: modify.order.r,
|
|
458
|
+
t: "limit" in modify.order.t
|
|
459
|
+
? {
|
|
460
|
+
limit: {
|
|
461
|
+
tif: modify.order.t.limit.tif,
|
|
462
|
+
},
|
|
463
|
+
}
|
|
464
|
+
: {
|
|
465
|
+
trigger: {
|
|
466
|
+
isMarket: modify.order.t.trigger.isMarket,
|
|
467
|
+
triggerPx: formatDecimal(modify.order.t.trigger.triggerPx),
|
|
468
|
+
tpsl: modify.order.t.trigger.tpsl,
|
|
469
|
+
},
|
|
470
|
+
},
|
|
471
|
+
c: modify.order.c,
|
|
472
|
+
},
|
|
473
|
+
};
|
|
474
|
+
if (sortedModify.order.c === undefined)
|
|
475
|
+
delete sortedModify.order.c;
|
|
476
|
+
return sortedModify;
|
|
477
|
+
}),
|
|
478
|
+
};
|
|
479
|
+
},
|
|
480
|
+
/** Sorts and formats a `cancel` action. */
|
|
481
|
+
cancel: (action) => {
|
|
482
|
+
return {
|
|
483
|
+
type: action.type,
|
|
484
|
+
cancels: action.cancels.map((cancel) => ({
|
|
485
|
+
a: cancel.a,
|
|
486
|
+
o: cancel.o,
|
|
487
|
+
})),
|
|
488
|
+
};
|
|
489
|
+
},
|
|
490
|
+
/** Sorts and formats a `cancelByCloid` action. */
|
|
491
|
+
cancelByCloid: (action) => {
|
|
492
|
+
return {
|
|
493
|
+
type: action.type,
|
|
494
|
+
cancels: action.cancels.map((cancel) => ({
|
|
495
|
+
asset: cancel.asset,
|
|
496
|
+
cloid: cancel.cloid,
|
|
497
|
+
})),
|
|
498
|
+
};
|
|
499
|
+
},
|
|
500
|
+
/** Sorts and formats a `cDeposit` action. */
|
|
501
|
+
cDeposit: (action) => {
|
|
502
|
+
return {
|
|
503
|
+
type: action.type,
|
|
504
|
+
signatureChainId: action.signatureChainId,
|
|
505
|
+
hyperliquidChain: action.hyperliquidChain,
|
|
506
|
+
wei: action.wei,
|
|
507
|
+
nonce: action.nonce,
|
|
508
|
+
};
|
|
509
|
+
},
|
|
510
|
+
/** Sorts and formats a `claimRewards` action. */
|
|
511
|
+
claimRewards: (action) => {
|
|
512
|
+
return {
|
|
513
|
+
type: action.type,
|
|
514
|
+
};
|
|
515
|
+
},
|
|
516
|
+
/** Sorts and formats a `convertToMultiSigUser` action. */
|
|
517
|
+
convertToMultiSigUser: (action) => {
|
|
518
|
+
return {
|
|
519
|
+
type: action.type,
|
|
520
|
+
signatureChainId: action.signatureChainId,
|
|
521
|
+
hyperliquidChain: action.hyperliquidChain,
|
|
522
|
+
signers: action.signers,
|
|
523
|
+
nonce: action.nonce,
|
|
524
|
+
};
|
|
525
|
+
},
|
|
526
|
+
/** Sorts and formats a `createSubAccount` action. */
|
|
527
|
+
createSubAccount: (action) => {
|
|
528
|
+
return {
|
|
529
|
+
type: action.type,
|
|
530
|
+
name: action.name,
|
|
531
|
+
};
|
|
532
|
+
},
|
|
533
|
+
/** Sorts and formats a `createVault` action. */
|
|
534
|
+
createVault: (action) => {
|
|
535
|
+
return {
|
|
536
|
+
type: action.type,
|
|
537
|
+
name: action.name,
|
|
538
|
+
description: action.description,
|
|
539
|
+
initialUsd: action.initialUsd,
|
|
540
|
+
nonce: action.nonce,
|
|
541
|
+
};
|
|
542
|
+
},
|
|
543
|
+
/** Sorts and formats a `CSignerAction` action (jail/unjail). */
|
|
544
|
+
CSignerAction: (action) => {
|
|
545
|
+
if ("jailSelf" in action) {
|
|
546
|
+
return {
|
|
547
|
+
type: action.type,
|
|
548
|
+
jailSelf: action.jailSelf,
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
else {
|
|
552
|
+
return {
|
|
553
|
+
type: action.type,
|
|
554
|
+
unjailSelf: action.unjailSelf,
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
},
|
|
558
|
+
/** Sorts and formats a `CValidatorAction` action (register/unregister/change profile). */
|
|
559
|
+
CValidatorAction: (action) => {
|
|
560
|
+
if ("changeProfile" in action) {
|
|
561
|
+
return {
|
|
562
|
+
type: action.type,
|
|
563
|
+
changeProfile: {
|
|
564
|
+
node_ip: action.changeProfile.node_ip ?? null,
|
|
565
|
+
name: action.changeProfile.name ?? null,
|
|
566
|
+
description: action.changeProfile.description ?? null,
|
|
567
|
+
unjailed: action.changeProfile.unjailed,
|
|
568
|
+
disable_delegations: action.changeProfile.disable_delegations ?? null,
|
|
569
|
+
commission_bps: action.changeProfile.commission_bps ?? null,
|
|
570
|
+
signer: action.changeProfile.signer?.toLowerCase() ?? null,
|
|
571
|
+
},
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
else if ("register" in action) {
|
|
575
|
+
return {
|
|
576
|
+
type: action.type,
|
|
577
|
+
register: {
|
|
578
|
+
profile: {
|
|
579
|
+
node_ip: {
|
|
580
|
+
Ip: action.register.profile.node_ip.Ip,
|
|
581
|
+
},
|
|
582
|
+
name: action.register.profile.name,
|
|
583
|
+
description: action.register.profile.description,
|
|
584
|
+
delegations_disabled: action.register.profile.delegations_disabled,
|
|
585
|
+
commission_bps: action.register.profile.commission_bps,
|
|
586
|
+
signer: action.register.profile.signer.toLowerCase(),
|
|
587
|
+
},
|
|
588
|
+
unjailed: action.register.unjailed,
|
|
589
|
+
initial_wei: action.register.initial_wei,
|
|
590
|
+
},
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
else { // "unregister" in action
|
|
594
|
+
return {
|
|
595
|
+
type: action.type,
|
|
596
|
+
unregister: action.unregister,
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
},
|
|
600
|
+
/** Sorts and formats a `cWithdraw` action. */
|
|
601
|
+
cWithdraw: (action) => {
|
|
602
|
+
return {
|
|
603
|
+
type: action.type,
|
|
604
|
+
signatureChainId: action.signatureChainId,
|
|
605
|
+
hyperliquidChain: action.hyperliquidChain,
|
|
606
|
+
wei: action.wei,
|
|
607
|
+
nonce: action.nonce,
|
|
608
|
+
};
|
|
609
|
+
},
|
|
610
|
+
/** Sorts and formats an `evmUserModify` action. */
|
|
611
|
+
evmUserModify: (action) => {
|
|
612
|
+
return {
|
|
613
|
+
type: action.type,
|
|
614
|
+
usingBigBlocks: action.usingBigBlocks,
|
|
615
|
+
};
|
|
616
|
+
},
|
|
617
|
+
/** Sorts and formats a `modify` action. */
|
|
618
|
+
modify: (action) => {
|
|
619
|
+
const sortedAction = {
|
|
620
|
+
type: action.type,
|
|
621
|
+
oid: action.oid,
|
|
622
|
+
order: {
|
|
623
|
+
a: action.order.a,
|
|
624
|
+
b: action.order.b,
|
|
625
|
+
p: formatDecimal(action.order.p),
|
|
626
|
+
s: formatDecimal(action.order.s),
|
|
627
|
+
r: action.order.r,
|
|
628
|
+
t: "limit" in action.order.t
|
|
629
|
+
? {
|
|
630
|
+
limit: {
|
|
631
|
+
tif: action.order.t.limit.tif,
|
|
632
|
+
},
|
|
633
|
+
}
|
|
634
|
+
: {
|
|
635
|
+
trigger: {
|
|
636
|
+
isMarket: action.order.t.trigger.isMarket,
|
|
637
|
+
triggerPx: formatDecimal(action.order.t.trigger.triggerPx),
|
|
638
|
+
tpsl: action.order.t.trigger.tpsl,
|
|
639
|
+
},
|
|
640
|
+
},
|
|
641
|
+
c: action.order.c,
|
|
642
|
+
},
|
|
643
|
+
};
|
|
644
|
+
if (sortedAction.order.c === undefined)
|
|
645
|
+
delete sortedAction.order.c;
|
|
646
|
+
return sortedAction;
|
|
647
|
+
},
|
|
648
|
+
/** Sorts and formats a `multiSig` action. */
|
|
649
|
+
multiSig: (action) => {
|
|
650
|
+
return {
|
|
651
|
+
type: action.type,
|
|
652
|
+
signatureChainId: action.signatureChainId,
|
|
653
|
+
signatures: action.signatures.map((signature) => ({
|
|
654
|
+
r: signature.r.replace(/^0x0+/, "0x").toLowerCase(),
|
|
655
|
+
s: signature.s.replace(/^0x0+/, "0x").toLowerCase(),
|
|
656
|
+
v: signature.v,
|
|
657
|
+
})),
|
|
658
|
+
payload: {
|
|
659
|
+
multiSigUser: action.payload.multiSigUser.toLowerCase(),
|
|
660
|
+
outerSigner: action.payload.outerSigner.toLowerCase(),
|
|
661
|
+
action: action.payload.action,
|
|
662
|
+
},
|
|
663
|
+
};
|
|
664
|
+
},
|
|
665
|
+
/** Sorts and formats an `order` action. */
|
|
666
|
+
order: (action) => {
|
|
667
|
+
const sortedAction = {
|
|
668
|
+
type: action.type,
|
|
669
|
+
orders: action.orders.map((order) => {
|
|
670
|
+
const sortedOrder = {
|
|
671
|
+
a: order.a,
|
|
672
|
+
b: order.b,
|
|
673
|
+
p: formatDecimal(order.p),
|
|
674
|
+
s: formatDecimal(order.s),
|
|
675
|
+
r: order.r,
|
|
676
|
+
t: "limit" in order.t
|
|
677
|
+
? {
|
|
678
|
+
limit: {
|
|
679
|
+
tif: order.t.limit.tif,
|
|
680
|
+
},
|
|
681
|
+
}
|
|
682
|
+
: {
|
|
683
|
+
trigger: {
|
|
684
|
+
isMarket: order.t.trigger.isMarket,
|
|
685
|
+
triggerPx: formatDecimal(order.t.trigger.triggerPx),
|
|
686
|
+
tpsl: order.t.trigger.tpsl,
|
|
687
|
+
},
|
|
688
|
+
},
|
|
689
|
+
c: order.c,
|
|
690
|
+
};
|
|
691
|
+
if (order.c === undefined)
|
|
692
|
+
delete sortedOrder.c;
|
|
693
|
+
return sortedOrder;
|
|
694
|
+
}),
|
|
695
|
+
grouping: action.grouping,
|
|
696
|
+
builder: action.builder
|
|
697
|
+
? {
|
|
698
|
+
b: action.builder.b.toLowerCase(),
|
|
699
|
+
f: action.builder.f,
|
|
700
|
+
}
|
|
701
|
+
: action.builder,
|
|
702
|
+
};
|
|
703
|
+
if (sortedAction.builder === undefined)
|
|
704
|
+
delete sortedAction.builder;
|
|
705
|
+
return sortedAction;
|
|
706
|
+
},
|
|
707
|
+
/** Sorts and formats a `perpDeploy` action. */
|
|
708
|
+
perpDeploy: (action) => {
|
|
709
|
+
if ("registerAsset" in action) {
|
|
710
|
+
return {
|
|
711
|
+
type: action.type,
|
|
712
|
+
registerAsset: {
|
|
713
|
+
maxGas: action.registerAsset.maxGas ?? null,
|
|
714
|
+
assetRequest: {
|
|
715
|
+
coin: action.registerAsset.assetRequest.coin,
|
|
716
|
+
szDecimals: action.registerAsset.assetRequest.szDecimals,
|
|
717
|
+
oraclePx: action.registerAsset.assetRequest.oraclePx,
|
|
718
|
+
marginTableId: action.registerAsset.assetRequest.marginTableId,
|
|
719
|
+
onlyIsolated: action.registerAsset.assetRequest.onlyIsolated,
|
|
720
|
+
},
|
|
721
|
+
dex: action.registerAsset.dex,
|
|
722
|
+
schema: action.registerAsset.schema
|
|
723
|
+
? {
|
|
724
|
+
fullName: action.registerAsset.schema.fullName,
|
|
725
|
+
collateralToken: action.registerAsset.schema.collateralToken,
|
|
726
|
+
oracleUpdater: action.registerAsset.schema.oracleUpdater?.toLowerCase() ?? null,
|
|
727
|
+
}
|
|
728
|
+
: null,
|
|
729
|
+
},
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
else {
|
|
733
|
+
return {
|
|
734
|
+
type: action.type,
|
|
735
|
+
setOracle: {
|
|
736
|
+
dex: action.setOracle.dex,
|
|
737
|
+
oraclePxs: action.setOracle.oraclePxs,
|
|
738
|
+
markPxs: action.setOracle.markPxs,
|
|
739
|
+
},
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
},
|
|
743
|
+
/** Sorts and formats a `PerpDexClassTransfer` action. */
|
|
744
|
+
PerpDexClassTransfer: (action) => {
|
|
745
|
+
return {
|
|
746
|
+
type: action.type,
|
|
747
|
+
signatureChainId: action.signatureChainId,
|
|
748
|
+
hyperliquidChain: action.hyperliquidChain,
|
|
749
|
+
dex: action.dex,
|
|
750
|
+
token: action.token,
|
|
751
|
+
amount: action.amount,
|
|
752
|
+
toPerp: action.toPerp,
|
|
753
|
+
nonce: action.nonce,
|
|
754
|
+
};
|
|
755
|
+
},
|
|
756
|
+
/** Sorts and formats a `registerReferrer` action. */
|
|
757
|
+
registerReferrer: (action) => {
|
|
758
|
+
return {
|
|
759
|
+
type: action.type,
|
|
760
|
+
code: action.code,
|
|
761
|
+
};
|
|
762
|
+
},
|
|
763
|
+
/** Sorts and formats a `reserveRequestWeight` action. */
|
|
764
|
+
reserveRequestWeight: (action) => {
|
|
765
|
+
return {
|
|
766
|
+
type: action.type,
|
|
767
|
+
weight: action.weight,
|
|
768
|
+
};
|
|
769
|
+
},
|
|
770
|
+
/** Sorts and formats a `scheduleCancel` action. */
|
|
771
|
+
scheduleCancel: (action) => {
|
|
772
|
+
const sortedAction = {
|
|
773
|
+
type: action.type,
|
|
774
|
+
time: action.time,
|
|
775
|
+
};
|
|
776
|
+
if (sortedAction.time === undefined)
|
|
777
|
+
delete sortedAction.time;
|
|
778
|
+
return sortedAction;
|
|
779
|
+
},
|
|
780
|
+
/** Sorts and formats a `setDisplayName` action. */
|
|
781
|
+
setDisplayName: (action) => {
|
|
782
|
+
return {
|
|
783
|
+
type: action.type,
|
|
784
|
+
displayName: action.displayName,
|
|
785
|
+
};
|
|
786
|
+
},
|
|
787
|
+
/** Sorts and formats a `setReferrer` action. */
|
|
788
|
+
setReferrer: (action) => {
|
|
789
|
+
return {
|
|
790
|
+
type: action.type,
|
|
791
|
+
code: action.code,
|
|
792
|
+
};
|
|
793
|
+
},
|
|
794
|
+
/** Sorts and formats a `spotDeploy` action. */
|
|
795
|
+
spotDeploy: (action) => {
|
|
796
|
+
if ("genesis" in action) {
|
|
797
|
+
const sortedAction = {
|
|
798
|
+
type: action.type,
|
|
799
|
+
genesis: {
|
|
800
|
+
token: action.genesis.token,
|
|
801
|
+
maxSupply: action.genesis.maxSupply,
|
|
802
|
+
noHyperliquidity: action.genesis.noHyperliquidity,
|
|
803
|
+
},
|
|
804
|
+
};
|
|
805
|
+
if (sortedAction.genesis.noHyperliquidity === undefined) {
|
|
806
|
+
delete sortedAction.genesis.noHyperliquidity;
|
|
807
|
+
}
|
|
808
|
+
return sortedAction;
|
|
809
|
+
}
|
|
810
|
+
else if ("registerHyperliquidity" in action) {
|
|
811
|
+
const sortedAction = {
|
|
812
|
+
type: action.type,
|
|
813
|
+
registerHyperliquidity: {
|
|
814
|
+
spot: action.registerHyperliquidity.spot,
|
|
815
|
+
startPx: action.registerHyperliquidity.startPx,
|
|
816
|
+
orderSz: action.registerHyperliquidity.orderSz,
|
|
817
|
+
nOrders: action.registerHyperliquidity.nOrders,
|
|
818
|
+
nSeededLevels: action.registerHyperliquidity.nSeededLevels,
|
|
819
|
+
},
|
|
820
|
+
};
|
|
821
|
+
if (sortedAction.registerHyperliquidity.nSeededLevels === undefined) {
|
|
822
|
+
delete sortedAction.registerHyperliquidity.nSeededLevels;
|
|
823
|
+
}
|
|
824
|
+
return sortedAction;
|
|
825
|
+
}
|
|
826
|
+
else if ("registerSpot" in action) {
|
|
827
|
+
return {
|
|
828
|
+
type: action.type,
|
|
829
|
+
registerSpot: {
|
|
830
|
+
tokens: action.registerSpot.tokens,
|
|
831
|
+
},
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
else if ("registerToken2" in action) {
|
|
835
|
+
const sortedAction = {
|
|
836
|
+
type: action.type,
|
|
837
|
+
registerToken2: {
|
|
838
|
+
spec: {
|
|
839
|
+
name: action.registerToken2.spec.name,
|
|
840
|
+
szDecimals: action.registerToken2.spec.szDecimals,
|
|
841
|
+
weiDecimals: action.registerToken2.spec.weiDecimals,
|
|
842
|
+
},
|
|
843
|
+
maxGas: action.registerToken2.maxGas,
|
|
844
|
+
fullName: action.registerToken2.fullName,
|
|
845
|
+
},
|
|
846
|
+
};
|
|
847
|
+
if (sortedAction.registerToken2.fullName === undefined) {
|
|
848
|
+
delete sortedAction.registerToken2.fullName;
|
|
849
|
+
}
|
|
850
|
+
return sortedAction;
|
|
851
|
+
}
|
|
852
|
+
else if ("setDeployerTradingFeeShare" in action) {
|
|
853
|
+
return {
|
|
854
|
+
type: action.type,
|
|
855
|
+
setDeployerTradingFeeShare: {
|
|
856
|
+
token: action.setDeployerTradingFeeShare.token,
|
|
857
|
+
share: action.setDeployerTradingFeeShare.share,
|
|
858
|
+
},
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
else { // "userGenesis" in action
|
|
862
|
+
const sortedAction = {
|
|
863
|
+
type: action.type,
|
|
864
|
+
userGenesis: {
|
|
865
|
+
token: action.userGenesis.token,
|
|
866
|
+
userAndWei: action.userGenesis.userAndWei,
|
|
867
|
+
existingTokenAndWei: action.userGenesis.existingTokenAndWei,
|
|
868
|
+
blacklistUsers: action.userGenesis.blacklistUsers,
|
|
869
|
+
},
|
|
870
|
+
};
|
|
871
|
+
if (sortedAction.userGenesis.blacklistUsers === undefined) {
|
|
872
|
+
delete sortedAction.userGenesis.blacklistUsers;
|
|
873
|
+
}
|
|
874
|
+
return sortedAction;
|
|
875
|
+
}
|
|
876
|
+
},
|
|
877
|
+
/** Sorts and formats a `spotSend` action. */
|
|
878
|
+
spotSend: (action) => {
|
|
879
|
+
return {
|
|
880
|
+
type: action.type,
|
|
881
|
+
signatureChainId: action.signatureChainId,
|
|
882
|
+
hyperliquidChain: action.hyperliquidChain,
|
|
883
|
+
destination: action.destination.toLowerCase(),
|
|
884
|
+
token: action.token,
|
|
885
|
+
amount: action.amount,
|
|
886
|
+
time: action.time,
|
|
887
|
+
};
|
|
888
|
+
},
|
|
889
|
+
/** Sorts and formats a `spotUser` action. */
|
|
890
|
+
spotUser: (action) => {
|
|
891
|
+
return {
|
|
892
|
+
type: action.type,
|
|
893
|
+
toggleSpotDusting: {
|
|
894
|
+
optOut: action.toggleSpotDusting.optOut,
|
|
895
|
+
},
|
|
896
|
+
};
|
|
897
|
+
},
|
|
898
|
+
/** Sorts and formats a `subAccountSpotTransfer` action. */
|
|
899
|
+
subAccountSpotTransfer: (action) => {
|
|
900
|
+
return {
|
|
901
|
+
type: action.type,
|
|
902
|
+
subAccountUser: action.subAccountUser.toLowerCase(),
|
|
903
|
+
isDeposit: action.isDeposit,
|
|
904
|
+
token: action.token,
|
|
905
|
+
amount: action.amount,
|
|
906
|
+
};
|
|
907
|
+
},
|
|
908
|
+
/** Sorts and formats a `subAccountTransfer` action. */
|
|
909
|
+
subAccountTransfer: (action) => {
|
|
910
|
+
return {
|
|
911
|
+
type: action.type,
|
|
912
|
+
subAccountUser: action.subAccountUser.toLowerCase(),
|
|
913
|
+
isDeposit: action.isDeposit,
|
|
914
|
+
usd: action.usd,
|
|
915
|
+
};
|
|
916
|
+
},
|
|
917
|
+
/** Sorts and formats a `tokenDelegate` action. */
|
|
918
|
+
tokenDelegate: (action) => {
|
|
919
|
+
return {
|
|
920
|
+
type: action.type,
|
|
921
|
+
signatureChainId: action.signatureChainId,
|
|
922
|
+
hyperliquidChain: action.hyperliquidChain,
|
|
923
|
+
validator: action.validator.toLowerCase(),
|
|
924
|
+
wei: action.wei,
|
|
925
|
+
isUndelegate: action.isUndelegate,
|
|
926
|
+
nonce: action.nonce,
|
|
927
|
+
};
|
|
928
|
+
},
|
|
929
|
+
/** Sorts and formats a `twapCancel` action. */
|
|
930
|
+
twapCancel: (action) => {
|
|
931
|
+
return {
|
|
932
|
+
type: action.type,
|
|
933
|
+
a: action.a,
|
|
934
|
+
t: action.t,
|
|
935
|
+
};
|
|
936
|
+
},
|
|
937
|
+
/** Sorts and formats a `twapOrder` action. */
|
|
938
|
+
twapOrder: (action) => {
|
|
939
|
+
return {
|
|
940
|
+
type: action.type,
|
|
941
|
+
twap: {
|
|
942
|
+
a: action.twap.a,
|
|
943
|
+
b: action.twap.b,
|
|
944
|
+
s: formatDecimal(action.twap.s),
|
|
945
|
+
r: action.twap.r,
|
|
946
|
+
m: action.twap.m,
|
|
947
|
+
t: action.twap.t,
|
|
948
|
+
},
|
|
949
|
+
};
|
|
950
|
+
},
|
|
951
|
+
/** Sorts and formats an `updateIsolatedMargin` action. */
|
|
952
|
+
updateIsolatedMargin: (action) => {
|
|
953
|
+
return {
|
|
954
|
+
type: action.type,
|
|
955
|
+
asset: action.asset,
|
|
956
|
+
isBuy: action.isBuy,
|
|
957
|
+
ntli: action.ntli,
|
|
958
|
+
};
|
|
959
|
+
},
|
|
960
|
+
/** Sorts and formats an `updateLeverage` action. */
|
|
961
|
+
updateLeverage: (action) => {
|
|
962
|
+
return {
|
|
963
|
+
type: action.type,
|
|
964
|
+
asset: action.asset,
|
|
965
|
+
isCross: action.isCross,
|
|
966
|
+
leverage: action.leverage,
|
|
967
|
+
};
|
|
968
|
+
},
|
|
969
|
+
/** Sorts and formats an `usdClassTransfer` action. */
|
|
970
|
+
usdClassTransfer: (action) => {
|
|
971
|
+
return {
|
|
972
|
+
type: action.type,
|
|
973
|
+
signatureChainId: action.signatureChainId,
|
|
974
|
+
hyperliquidChain: action.hyperliquidChain,
|
|
975
|
+
amount: action.amount,
|
|
976
|
+
toPerp: action.toPerp,
|
|
977
|
+
nonce: action.nonce,
|
|
978
|
+
};
|
|
979
|
+
},
|
|
980
|
+
/** Sorts and formats an `usdSend` action. */
|
|
981
|
+
usdSend: (action) => {
|
|
982
|
+
return {
|
|
983
|
+
type: action.type,
|
|
984
|
+
signatureChainId: action.signatureChainId,
|
|
985
|
+
hyperliquidChain: action.hyperliquidChain,
|
|
986
|
+
destination: action.destination.toLowerCase(),
|
|
987
|
+
amount: action.amount,
|
|
988
|
+
time: action.time,
|
|
989
|
+
};
|
|
990
|
+
},
|
|
991
|
+
/** Sorts and formats a `vaultDistribute` action. */
|
|
992
|
+
vaultDistribute: (action) => {
|
|
993
|
+
return {
|
|
994
|
+
type: action.type,
|
|
995
|
+
vaultAddress: action.vaultAddress,
|
|
996
|
+
usd: action.usd,
|
|
997
|
+
};
|
|
998
|
+
},
|
|
999
|
+
/** Sorts and formats a `vaultModify` action. */
|
|
1000
|
+
vaultModify: (action) => {
|
|
1001
|
+
return {
|
|
1002
|
+
type: action.type,
|
|
1003
|
+
vaultAddress: action.vaultAddress,
|
|
1004
|
+
allowDeposits: action.allowDeposits,
|
|
1005
|
+
alwaysCloseOnWithdraw: action.alwaysCloseOnWithdraw,
|
|
1006
|
+
};
|
|
1007
|
+
},
|
|
1008
|
+
/** Sorts and formats a `vaultTransfer` action. */
|
|
1009
|
+
vaultTransfer: (action) => {
|
|
1010
|
+
return {
|
|
1011
|
+
type: action.type,
|
|
1012
|
+
vaultAddress: action.vaultAddress,
|
|
1013
|
+
isDeposit: action.isDeposit,
|
|
1014
|
+
usd: action.usd,
|
|
1015
|
+
};
|
|
1016
|
+
},
|
|
1017
|
+
/** Sorts and formats a `withdraw3` action. */
|
|
1018
|
+
withdraw3: (action) => {
|
|
1019
|
+
return {
|
|
1020
|
+
type: action.type,
|
|
1021
|
+
signatureChainId: action.signatureChainId,
|
|
1022
|
+
hyperliquidChain: action.hyperliquidChain,
|
|
1023
|
+
destination: action.destination.toLowerCase(),
|
|
1024
|
+
amount: action.amount,
|
|
1025
|
+
time: action.time,
|
|
1026
|
+
};
|
|
1027
|
+
},
|
|
1028
|
+
};
|
|
1029
|
+
/** Removes trailing zeros from decimal string. */
|
|
1030
|
+
function formatDecimal(numStr) {
|
|
1031
|
+
if (!numStr.includes("."))
|
|
1032
|
+
return numStr;
|
|
1033
|
+
const [intPart, fracPart] = numStr.split(".");
|
|
1034
|
+
const newFrac = fracPart.replace(/0+$/, "");
|
|
1035
|
+
return newFrac ? `${intPart}.${newFrac}` : intPart;
|
|
1036
|
+
}
|
|
1037
|
+
/** EIP-712 type definitions for user-signed actions. */
|
|
1038
|
+
exports.userSignedActionEip712Types = {
|
|
1039
|
+
approveAgent: {
|
|
1040
|
+
"HyperliquidTransaction:ApproveAgent": [
|
|
1041
|
+
{ name: "hyperliquidChain", type: "string" },
|
|
1042
|
+
{ name: "agentAddress", type: "address" },
|
|
1043
|
+
{ name: "agentName", type: "string" },
|
|
1044
|
+
{ name: "nonce", type: "uint64" },
|
|
1045
|
+
],
|
|
1046
|
+
},
|
|
1047
|
+
approveBuilderFee: {
|
|
1048
|
+
"HyperliquidTransaction:ApproveBuilderFee": [
|
|
1049
|
+
{ name: "hyperliquidChain", type: "string" },
|
|
1050
|
+
{ name: "maxFeeRate", type: "string" },
|
|
1051
|
+
{ name: "builder", type: "address" },
|
|
1052
|
+
{ name: "nonce", type: "uint64" },
|
|
1053
|
+
],
|
|
1054
|
+
},
|
|
1055
|
+
cDeposit: {
|
|
1056
|
+
"HyperliquidTransaction:CDeposit": [
|
|
1057
|
+
{ name: "hyperliquidChain", type: "string" },
|
|
1058
|
+
{ name: "wei", type: "uint64" },
|
|
1059
|
+
{ name: "nonce", type: "uint64" },
|
|
1060
|
+
],
|
|
1061
|
+
},
|
|
1062
|
+
convertToMultiSigUser: {
|
|
1063
|
+
"HyperliquidTransaction:ConvertToMultiSigUser": [
|
|
1064
|
+
{ name: "hyperliquidChain", type: "string" },
|
|
1065
|
+
{ name: "signers", type: "string" },
|
|
1066
|
+
{ name: "nonce", type: "uint64" },
|
|
1067
|
+
],
|
|
1068
|
+
},
|
|
1069
|
+
cWithdraw: {
|
|
1070
|
+
"HyperliquidTransaction:CWithdraw": [
|
|
1071
|
+
{ name: "hyperliquidChain", type: "string" },
|
|
1072
|
+
{ name: "wei", type: "uint64" },
|
|
1073
|
+
{ name: "nonce", type: "uint64" },
|
|
1074
|
+
],
|
|
1075
|
+
},
|
|
1076
|
+
PerpDexClassTransfer: {
|
|
1077
|
+
"HyperliquidTransaction:PerpDexClassTransfer": [
|
|
1078
|
+
{ name: "hyperliquidChain", type: "string" },
|
|
1079
|
+
{ name: "dex", type: "string" },
|
|
1080
|
+
{ name: "token", type: "string" },
|
|
1081
|
+
{ name: "amount", type: "string" },
|
|
1082
|
+
{ name: "toPerp", type: "bool" },
|
|
1083
|
+
{ name: "nonce", type: "uint64" },
|
|
1084
|
+
],
|
|
1085
|
+
},
|
|
1086
|
+
spotSend: {
|
|
1087
|
+
"HyperliquidTransaction:SpotSend": [
|
|
1088
|
+
{ name: "hyperliquidChain", type: "string" },
|
|
1089
|
+
{ name: "destination", type: "string" },
|
|
1090
|
+
{ name: "token", type: "string" },
|
|
1091
|
+
{ name: "amount", type: "string" },
|
|
1092
|
+
{ name: "time", type: "uint64" },
|
|
1093
|
+
],
|
|
1094
|
+
},
|
|
1095
|
+
tokenDelegate: {
|
|
1096
|
+
"HyperliquidTransaction:TokenDelegate": [
|
|
1097
|
+
{ name: "hyperliquidChain", type: "string" },
|
|
1098
|
+
{ name: "validator", type: "address" },
|
|
1099
|
+
{ name: "wei", type: "uint64" },
|
|
1100
|
+
{ name: "isUndelegate", type: "bool" },
|
|
1101
|
+
{ name: "nonce", type: "uint64" },
|
|
1102
|
+
],
|
|
1103
|
+
},
|
|
1104
|
+
usdClassTransfer: {
|
|
1105
|
+
"HyperliquidTransaction:UsdClassTransfer": [
|
|
1106
|
+
{ name: "hyperliquidChain", type: "string" },
|
|
1107
|
+
{ name: "amount", type: "string" },
|
|
1108
|
+
{ name: "toPerp", type: "bool" },
|
|
1109
|
+
{ name: "nonce", type: "uint64" },
|
|
1110
|
+
],
|
|
1111
|
+
},
|
|
1112
|
+
usdSend: {
|
|
1113
|
+
"HyperliquidTransaction:UsdSend": [
|
|
1114
|
+
{ name: "hyperliquidChain", type: "string" },
|
|
1115
|
+
{ name: "destination", type: "string" },
|
|
1116
|
+
{ name: "amount", type: "string" },
|
|
1117
|
+
{ name: "time", type: "uint64" },
|
|
1118
|
+
],
|
|
1119
|
+
},
|
|
1120
|
+
withdraw3: {
|
|
1121
|
+
"HyperliquidTransaction:Withdraw": [
|
|
1122
|
+
{ name: "hyperliquidChain", type: "string" },
|
|
1123
|
+
{ name: "destination", type: "string" },
|
|
1124
|
+
{ name: "amount", type: "string" },
|
|
1125
|
+
{ name: "time", type: "uint64" },
|
|
1126
|
+
],
|
|
1127
|
+
},
|
|
1128
|
+
};
|
|
428
1129
|
});
|