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