@nktkas/hyperliquid 0.23.1 → 0.24.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 (165) hide show
  1. package/CONTRIBUTING.md +3 -2
  2. package/README.md +154 -170
  3. package/esm/mod.d.ts +1 -1
  4. package/esm/mod.d.ts.map +1 -1
  5. package/esm/src/base.d.ts +0 -5
  6. package/esm/src/base.d.ts.map +1 -1
  7. package/esm/src/clients/exchange.d.ts +430 -393
  8. package/esm/src/clients/exchange.d.ts.map +1 -1
  9. package/esm/src/clients/exchange.js +467 -927
  10. package/esm/src/clients/info.d.ts +228 -203
  11. package/esm/src/clients/info.d.ts.map +1 -1
  12. package/esm/src/clients/info.js +236 -368
  13. package/esm/src/clients/multiSign.d.ts +14 -1184
  14. package/esm/src/clients/multiSign.d.ts.map +1 -1
  15. package/esm/src/clients/multiSign.js +37 -2004
  16. package/esm/src/clients/subscription.d.ts +95 -93
  17. package/esm/src/clients/subscription.d.ts.map +1 -1
  18. package/esm/src/clients/subscription.js +101 -146
  19. package/esm/src/signing/_signTypedData/ethers.d.ts +16 -4
  20. package/esm/src/signing/_signTypedData/ethers.d.ts.map +1 -1
  21. package/esm/src/signing/_signTypedData/ethers.js +1 -1
  22. package/esm/src/signing/_signTypedData/mod.d.ts +12 -12
  23. package/esm/src/signing/_signTypedData/mod.d.ts.map +1 -1
  24. package/esm/src/signing/_signTypedData/mod.js +52 -24
  25. package/esm/src/signing/_signTypedData/private_key.d.ts +6 -5
  26. package/esm/src/signing/_signTypedData/private_key.d.ts.map +1 -1
  27. package/esm/src/signing/_signTypedData/private_key.js +40 -19
  28. package/esm/src/signing/_signTypedData/viem.d.ts +27 -6
  29. package/esm/src/signing/_signTypedData/viem.d.ts.map +1 -1
  30. package/esm/src/signing/_signTypedData/viem.js +1 -1
  31. package/esm/src/signing/_sorter.d.ts +12 -21
  32. package/esm/src/signing/_sorter.d.ts.map +1 -1
  33. package/esm/src/signing/_sorter.js +30 -63
  34. package/esm/src/signing/mod.d.ts +177 -127
  35. package/esm/src/signing/mod.d.ts.map +1 -1
  36. package/esm/src/signing/mod.js +182 -130
  37. package/esm/src/transports/base.d.ts +2 -1
  38. package/esm/src/transports/base.d.ts.map +1 -1
  39. package/esm/src/transports/http/http_transport.d.ts +3 -2
  40. package/esm/src/transports/http/http_transport.d.ts.map +1 -1
  41. package/esm/src/transports/http/http_transport.js +4 -4
  42. package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +14 -6
  43. package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
  44. package/esm/src/transports/websocket/_hyperliquid_event_target.js +1 -2
  45. package/esm/src/transports/websocket/_reconnecting_websocket.d.ts +2 -1
  46. package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
  47. package/esm/src/transports/websocket/_reconnecting_websocket.js +1 -0
  48. package/esm/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
  49. package/esm/src/transports/websocket/_websocket_async_request.js +17 -21
  50. package/esm/src/transports/websocket/websocket_transport.d.ts +4 -4
  51. package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  52. package/esm/src/transports/websocket/websocket_transport.js +6 -6
  53. package/esm/src/types/exchange/requests.d.ts +492 -306
  54. package/esm/src/types/exchange/requests.d.ts.map +1 -1
  55. package/esm/src/types/exchange/responses.d.ts +105 -25
  56. package/esm/src/types/exchange/responses.d.ts.map +1 -1
  57. package/esm/src/types/explorer/requests.d.ts +3 -3
  58. package/esm/src/types/explorer/requests.d.ts.map +1 -1
  59. package/esm/src/types/explorer/responses.d.ts +1 -1
  60. package/esm/src/types/explorer/responses.d.ts.map +1 -1
  61. package/esm/src/types/info/accounts.d.ts +403 -98
  62. package/esm/src/types/info/accounts.d.ts.map +1 -1
  63. package/esm/src/types/info/assets.d.ts +131 -35
  64. package/esm/src/types/info/assets.d.ts.map +1 -1
  65. package/esm/src/types/info/markets.d.ts +29 -8
  66. package/esm/src/types/info/markets.d.ts.map +1 -1
  67. package/esm/src/types/info/orders.d.ts +62 -17
  68. package/esm/src/types/info/orders.d.ts.map +1 -1
  69. package/esm/src/types/info/requests.d.ts +117 -51
  70. package/esm/src/types/info/requests.d.ts.map +1 -1
  71. package/esm/src/types/info/validators.d.ts +44 -14
  72. package/esm/src/types/info/validators.d.ts.map +1 -1
  73. package/esm/src/types/info/vaults.d.ts +25 -10
  74. package/esm/src/types/info/vaults.d.ts.map +1 -1
  75. package/esm/src/types/mod.d.ts +1 -1
  76. package/esm/src/types/mod.d.ts.map +1 -1
  77. package/esm/src/types/subscriptions/requests.d.ts +21 -66
  78. package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
  79. package/esm/src/types/subscriptions/responses.d.ts +46 -55
  80. package/esm/src/types/subscriptions/responses.d.ts.map +1 -1
  81. package/package.json +2 -3
  82. package/script/mod.d.ts +1 -1
  83. package/script/mod.d.ts.map +1 -1
  84. package/script/src/base.d.ts +0 -5
  85. package/script/src/base.d.ts.map +1 -1
  86. package/script/src/clients/exchange.d.ts +430 -393
  87. package/script/src/clients/exchange.d.ts.map +1 -1
  88. package/script/src/clients/exchange.js +466 -926
  89. package/script/src/clients/info.d.ts +228 -203
  90. package/script/src/clients/info.d.ts.map +1 -1
  91. package/script/src/clients/info.js +236 -368
  92. package/script/src/clients/multiSign.d.ts +14 -1184
  93. package/script/src/clients/multiSign.d.ts.map +1 -1
  94. package/script/src/clients/multiSign.js +38 -2005
  95. package/script/src/clients/subscription.d.ts +95 -93
  96. package/script/src/clients/subscription.d.ts.map +1 -1
  97. package/script/src/clients/subscription.js +101 -146
  98. package/script/src/signing/_signTypedData/ethers.d.ts +16 -4
  99. package/script/src/signing/_signTypedData/ethers.d.ts.map +1 -1
  100. package/script/src/signing/_signTypedData/ethers.js +2 -2
  101. package/script/src/signing/_signTypedData/mod.d.ts +12 -12
  102. package/script/src/signing/_signTypedData/mod.d.ts.map +1 -1
  103. package/script/src/signing/_signTypedData/mod.js +51 -26
  104. package/script/src/signing/_signTypedData/private_key.d.ts +6 -5
  105. package/script/src/signing/_signTypedData/private_key.d.ts.map +1 -1
  106. package/script/src/signing/_signTypedData/private_key.js +40 -18
  107. package/script/src/signing/_signTypedData/viem.d.ts +27 -6
  108. package/script/src/signing/_signTypedData/viem.d.ts.map +1 -1
  109. package/script/src/signing/_signTypedData/viem.js +2 -2
  110. package/script/src/signing/_sorter.d.ts +12 -21
  111. package/script/src/signing/_sorter.d.ts.map +1 -1
  112. package/script/src/signing/_sorter.js +30 -63
  113. package/script/src/signing/mod.d.ts +177 -127
  114. package/script/src/signing/mod.d.ts.map +1 -1
  115. package/script/src/signing/mod.js +185 -148
  116. package/script/src/transports/base.d.ts +2 -1
  117. package/script/src/transports/base.d.ts.map +1 -1
  118. package/script/src/transports/http/http_transport.d.ts +3 -2
  119. package/script/src/transports/http/http_transport.d.ts.map +1 -1
  120. package/script/src/transports/http/http_transport.js +4 -4
  121. package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +14 -6
  122. package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
  123. package/script/src/transports/websocket/_hyperliquid_event_target.js +1 -2
  124. package/script/src/transports/websocket/_reconnecting_websocket.d.ts +2 -1
  125. package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
  126. package/script/src/transports/websocket/_reconnecting_websocket.js +1 -0
  127. package/script/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
  128. package/script/src/transports/websocket/_websocket_async_request.js +17 -21
  129. package/script/src/transports/websocket/websocket_transport.d.ts +4 -4
  130. package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  131. package/script/src/transports/websocket/websocket_transport.js +6 -6
  132. package/script/src/types/exchange/requests.d.ts +492 -306
  133. package/script/src/types/exchange/requests.d.ts.map +1 -1
  134. package/script/src/types/exchange/responses.d.ts +105 -25
  135. package/script/src/types/exchange/responses.d.ts.map +1 -1
  136. package/script/src/types/explorer/requests.d.ts +3 -3
  137. package/script/src/types/explorer/requests.d.ts.map +1 -1
  138. package/script/src/types/explorer/responses.d.ts +1 -1
  139. package/script/src/types/explorer/responses.d.ts.map +1 -1
  140. package/script/src/types/info/accounts.d.ts +403 -98
  141. package/script/src/types/info/accounts.d.ts.map +1 -1
  142. package/script/src/types/info/assets.d.ts +131 -35
  143. package/script/src/types/info/assets.d.ts.map +1 -1
  144. package/script/src/types/info/markets.d.ts +29 -8
  145. package/script/src/types/info/markets.d.ts.map +1 -1
  146. package/script/src/types/info/orders.d.ts +62 -17
  147. package/script/src/types/info/orders.d.ts.map +1 -1
  148. package/script/src/types/info/requests.d.ts +117 -51
  149. package/script/src/types/info/requests.d.ts.map +1 -1
  150. package/script/src/types/info/validators.d.ts +44 -14
  151. package/script/src/types/info/validators.d.ts.map +1 -1
  152. package/script/src/types/info/vaults.d.ts +25 -10
  153. package/script/src/types/info/vaults.d.ts.map +1 -1
  154. package/script/src/types/mod.d.ts +1 -1
  155. package/script/src/types/mod.d.ts.map +1 -1
  156. package/script/src/types/subscriptions/requests.d.ts +21 -66
  157. package/script/src/types/subscriptions/requests.d.ts.map +1 -1
  158. package/script/src/types/subscriptions/responses.d.ts +46 -55
  159. package/script/src/types/subscriptions/responses.d.ts.map +1 -1
  160. package/esm/src/signing/_signTypedData/window.d.ts +0 -29
  161. package/esm/src/signing/_signTypedData/window.d.ts.map +0 -1
  162. package/esm/src/signing/_signTypedData/window.js +0 -30
  163. package/script/src/signing/_signTypedData/window.d.ts +0 -29
  164. package/script/src/signing/_signTypedData/window.d.ts.map +0 -1
  165. package/script/src/signing/_signTypedData/window.js +0 -34
@@ -1,21 +1,10 @@
1
- import { isAbstractEthersSigner, isAbstractEthersV5Signer, } from "./ethers.js";
2
- import { isValidPrivateKey, signTypedData as signTypedDataWithPrivateKey } from "./private_key.js";
3
- import { isAbstractViemWalletClient } from "./viem.js";
4
- import { isAbstractWindowEthereum, signTypedDataWithWindowEthereum } from "./window.js";
5
- export { isAbstractEthersSigner, isAbstractEthersV5Signer, isAbstractViemWalletClient, isAbstractWindowEthereum, isValidPrivateKey, };
1
+ import { isAbstractEthersV5Signer, isAbstractEthersV6Signer, } from "./ethers.js";
2
+ import { isValidPrivateKey, privateKeyToAddress, signTypedData as signTypedDataWithPrivateKey } from "./private_key.js";
3
+ import { isAbstractViemWallet } from "./viem.js";
6
4
  export async function signTypedData(args) {
7
5
  const { wallet, domain, types, primaryType, message } = args;
8
6
  let signature;
9
- if (isValidPrivateKey(wallet)) {
10
- signature = await signTypedDataWithPrivateKey({
11
- privateKey: wallet,
12
- domain,
13
- types,
14
- primaryType,
15
- message,
16
- });
17
- }
18
- else if (isAbstractViemWalletClient(wallet)) {
7
+ if (isAbstractViemWallet(wallet)) {
19
8
  signature = await wallet.signTypedData({
20
9
  domain,
21
10
  types: {
@@ -31,20 +20,14 @@ export async function signTypedData(args) {
31
20
  message,
32
21
  });
33
22
  }
34
- else if (isAbstractEthersSigner(wallet)) {
23
+ else if (isAbstractEthersV6Signer(wallet)) {
35
24
  signature = await wallet.signTypedData(domain, types, message);
36
25
  }
37
26
  else if (isAbstractEthersV5Signer(wallet)) {
38
27
  signature = await wallet._signTypedData(domain, types, message);
39
28
  }
40
- else if (isAbstractWindowEthereum(wallet)) {
41
- signature = await signTypedDataWithWindowEthereum({
42
- ethereum: wallet,
43
- domain,
44
- types,
45
- primaryType,
46
- message,
47
- });
29
+ else if (isValidPrivateKey(wallet)) {
30
+ signature = await signTypedDataWithPrivateKey({ privateKey: wallet, domain, types, primaryType, message });
48
31
  }
49
32
  else {
50
33
  throw new Error("Unsupported wallet for signing typed data");
@@ -57,3 +40,48 @@ function splitSignature(signature) {
57
40
  const v = parseInt(signature.slice(130, 132), 16);
58
41
  return { r, s, v };
59
42
  }
43
+ /** Get the chain ID of the wallet. */
44
+ export async function getWalletChainId(wallet) {
45
+ if (isAbstractViemWallet(wallet)) {
46
+ if ("getChainId" in wallet && wallet.getChainId) {
47
+ const chainId = await wallet.getChainId();
48
+ return `0x${chainId.toString(16)}`;
49
+ }
50
+ else {
51
+ return "0x1";
52
+ }
53
+ }
54
+ else if (isAbstractEthersV6Signer(wallet) || isAbstractEthersV5Signer(wallet)) {
55
+ if ("provider" in wallet && wallet.provider) {
56
+ const network = await wallet.provider.getNetwork();
57
+ return `0x${network.chainId.toString(16)}`;
58
+ }
59
+ else {
60
+ return "0x1";
61
+ }
62
+ }
63
+ else {
64
+ return "0x1";
65
+ }
66
+ }
67
+ /** Get the wallet address from various wallet types. */
68
+ export async function getWalletAddress(wallet) {
69
+ if (isAbstractViemWallet(wallet)) {
70
+ if ("address" in wallet && wallet.address) {
71
+ return wallet.address;
72
+ }
73
+ else if ("getAddresses" in wallet && wallet.getAddresses) {
74
+ const addresses = await wallet.getAddresses();
75
+ return addresses[0];
76
+ }
77
+ }
78
+ else if (isAbstractEthersV6Signer(wallet) || isAbstractEthersV5Signer(wallet)) {
79
+ if ("getAddress" in wallet && wallet.getAddress) {
80
+ return await wallet.getAddress();
81
+ }
82
+ }
83
+ else if (isValidPrivateKey(wallet)) {
84
+ return privateKeyToAddress(wallet);
85
+ }
86
+ throw new Error("Unsupported wallet for getting address");
87
+ }
@@ -1,4 +1,3 @@
1
- type Hex = `0x${string}`;
2
1
  interface Types {
3
2
  [type: string]: {
4
3
  name: string;
@@ -8,9 +7,9 @@ interface Types {
8
7
  interface Domain extends Record<string, unknown> {
9
8
  name?: string;
10
9
  version?: string;
11
- chainId?: number | string | bigint | Hex;
12
- verifyingContract?: Hex;
13
- salt?: Hex;
10
+ chainId?: number | string | bigint | `0x${string}`;
11
+ verifyingContract?: `0x${string}`;
12
+ salt?: `0x${string}`;
14
13
  }
15
14
  /** Signs typed data with a private key. */
16
15
  export declare function signTypedData(args: {
@@ -19,8 +18,10 @@ export declare function signTypedData(args: {
19
18
  types: Types;
20
19
  primaryType: string;
21
20
  message: Record<string, unknown>;
22
- }): Promise<Hex>;
21
+ }): Promise<`0x${string}`>;
23
22
  /** Validates if a string is a valid secp256k1 private key. */
24
23
  export declare function isValidPrivateKey(privateKey: unknown): privateKey is string;
24
+ /** Converts a private key to an Ethereum address. */
25
+ export declare function privateKeyToAddress(privateKey: string): `0x${string}`;
25
26
  export {};
26
27
  //# sourceMappingURL=private_key.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"private_key.d.ts","sourceRoot":"","sources":["../../../../src/src/signing/_signTypedData/private_key.ts"],"names":[],"mappings":"AAGA,KAAK,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAEzB,UAAU,KAAK;IACX,CAAC,IAAI,EAAE,MAAM,GAAG;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KAChB,EAAE,CAAC;CACP;AAED,UAAU,MAAO,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC5C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;IACzC,iBAAiB,CAAC,EAAE,GAAG,CAAC;IACxB,IAAI,CAAC,EAAE,GAAG,CAAC;CACd;AAED,2CAA2C;AAC3C,wBAAsB,aAAa,CAAC,IAAI,EAAE;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,KAAK,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,GAAG,OAAO,CAAC,GAAG,CAAC,CAkBf;AAuJD,8DAA8D;AAC9D,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,OAAO,GAAG,UAAU,IAAI,MAAM,CAG3E"}
1
+ {"version":3,"file":"private_key.d.ts","sourceRoot":"","sources":["../../../../src/src/signing/_signTypedData/private_key.ts"],"names":[],"mappings":"AAGA,UAAU,KAAK;IACX,CAAC,IAAI,EAAE,MAAM,GAAG;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KAChB,EAAE,CAAC;CACP;AAED,UAAU,MAAO,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC5C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,MAAM,EAAE,CAAC;IACnD,iBAAiB,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;IAClC,IAAI,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;CACxB;AAED,2CAA2C;AAC3C,wBAAsB,aAAa,CAAC,IAAI,EAAE;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,KAAK,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,GAAG,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC,CAkBzB;AAsKD,8DAA8D;AAC9D,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,OAAO,GAAG,UAAU,IAAI,MAAM,CAG3E;AAED,qDAAqD;AACrD,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,KAAK,MAAM,EAAE,CAYrE"}
@@ -1,5 +1,5 @@
1
1
  import { keccak_256 } from "@noble/hashes/sha3";
2
- import { etc, signAsync, utils } from "@noble/secp256k1";
2
+ import { etc, getPublicKey, signAsync, utils } from "@noble/secp256k1";
3
3
  /** Signs typed data with a private key. */
4
4
  export async function signTypedData(args) {
5
5
  const { privateKey, domain = {}, types, primaryType, message, } = args;
@@ -47,20 +47,27 @@ function encodeType(primaryType, types) {
47
47
  const deps = findTypeDependencies(primaryType, types);
48
48
  const sortedDeps = [primaryType, ...deps.filter((d) => d !== primaryType).sort()];
49
49
  return sortedDeps
50
- .map((type) => `${type}(${types[type].map((field) => `${field.type} ${field.name}`).join(",")})`)
50
+ .map((type) => `${type}(${types[type].map((field) => `${resolveTypeAlias(field.type)} ${field.name}`).join(",")})`)
51
51
  .join("");
52
52
  }
53
- function findTypeDependencies(primaryType, types, found = new Set()) {
54
- if (found.has(primaryType) || !types[primaryType])
53
+ function resolveTypeAlias(type) {
54
+ if (type === "uint")
55
+ return "uint256";
56
+ if (type === "int")
57
+ return "int256";
58
+ return type;
59
+ }
60
+ function findTypeDependencies(primaryType, types, _found = new Set()) {
61
+ if (_found.has(primaryType) || !types[primaryType])
55
62
  return [];
56
- found.add(primaryType);
63
+ _found.add(primaryType);
57
64
  for (const field of types[primaryType]) {
58
- const baseType = field.type.replace(/\[\d*\]$/, "");
65
+ const baseType = field.type.replace(/\[.*?\]/g, "");
59
66
  if (types[baseType]) {
60
- findTypeDependencies(baseType, types, found);
67
+ findTypeDependencies(baseType, types, _found);
61
68
  }
62
69
  }
63
- return Array.from(found);
70
+ return Array.from(_found);
64
71
  }
65
72
  function encodeValue(type, value, types) {
66
73
  const arrayMatch = type.match(/^(.*)\[(\d*)\]$/);
@@ -68,10 +75,10 @@ function encodeValue(type, value, types) {
68
75
  // Extract type info: base type and optional length
69
76
  const [, baseType, len] = arrayMatch;
70
77
  if (!Array.isArray(value)) {
71
- throw new Error(`Expected array for ${type}, got ${typeof value}`);
78
+ throw new Error(`Expected array for ${type}. Received: ${typeof value}`);
72
79
  }
73
80
  if (len && value.length !== +len) {
74
- throw new Error(`Invalid length for ${type}: expected ${len}, got ${value.length}`);
81
+ throw new Error(`Invalid length for ${type}: expected ${len}. Received: ${value.length}`);
75
82
  }
76
83
  // Encode each element in the array and hash them together
77
84
  const encodedElements = value.map((v) => encodeValue(baseType, v, types));
@@ -87,8 +94,9 @@ function encodeValue(type, value, types) {
87
94
  }
88
95
  if (type === "address") {
89
96
  const bytes = etc.hexToBytes(cleanHex(value));
90
- if (bytes.length !== 20)
91
- throw new Error("address must be 20 bytes");
97
+ if (bytes.length !== 20) {
98
+ throw new Error(`Address must be 20 bytes.`);
99
+ }
92
100
  const padded = new Uint8Array(32);
93
101
  padded.set(bytes, 12);
94
102
  return padded;
@@ -96,9 +104,10 @@ function encodeValue(type, value, types) {
96
104
  if (type.startsWith("uint") || type.startsWith("int")) {
97
105
  // Extract type info: uint/int and bit size
98
106
  const isUint = type.startsWith("uint");
99
- const bits = parseInt(type.slice(isUint ? 4 : 3) || "256");
107
+ const bitsStr = type.slice(isUint ? 4 : 3);
108
+ const bits = parseInt(bitsStr || "256");
100
109
  if (bits > 256 || bits % 8 !== 0) {
101
- throw new Error(`Unsupported bit size for ${type}: ${bits}`);
110
+ throw new Error(`Invalid ${isUint ? "uint" : "int"} size: ${bitsStr}. Must be 8-256 in steps of 8`);
102
111
  }
103
112
  // Apply Two's complement for specified bit size
104
113
  const bigIntValue = BigInt(value);
@@ -120,18 +129,20 @@ function encodeValue(type, value, types) {
120
129
  if (bytesMatch) {
121
130
  // Extract type info: bytes size
122
131
  const size = parseInt(bytesMatch[1]);
123
- if (size === 0 || size > 32)
124
- throw new Error(`Unsupported bytes size: ${size}`);
132
+ if (size === 0 || size > 32) {
133
+ throw new Error(`bytesN size must be 1-32. Received: ${size}`);
134
+ }
125
135
  // Convert hex to bytes
126
136
  const bytes = etc.hexToBytes(cleanHex(value));
127
- if (bytes.length !== size)
128
- throw new Error(`Invalid length for ${type}: expected ${size}, got ${bytes.length}`);
137
+ if (bytes.length !== size) {
138
+ throw new Error(`${type} requires exactly ${size} bytes. Received: ${bytes.length} from '${value}'`);
139
+ }
129
140
  // Pad to 32 bytes
130
141
  const padded = new Uint8Array(32);
131
142
  padded.set(bytes, 0);
132
143
  return padded;
133
144
  }
134
- throw new Error(`Unsupported type: ${type}`);
145
+ throw new Error(`Unsupported type: '${type}'.`);
135
146
  }
136
147
  function cleanHex(hex) {
137
148
  return hex.startsWith("0x") ? hex.slice(2) : hex;
@@ -142,3 +153,13 @@ export function isValidPrivateKey(privateKey) {
142
153
  return false;
143
154
  return utils.isValidPrivateKey(cleanHex(privateKey));
144
155
  }
156
+ /** Converts a private key to an Ethereum address. */
157
+ export function privateKeyToAddress(privateKey) {
158
+ const cleanPrivKey = cleanHex(privateKey);
159
+ const publicKey = getPublicKey(cleanPrivKey, false);
160
+ const publicKeyWithoutPrefix = publicKey.slice(1);
161
+ const hash = keccak_256(publicKeyWithoutPrefix);
162
+ const addressBytes = hash.slice(-20);
163
+ const address = etc.bytesToHex(addressBytes);
164
+ return `0x${address}`;
165
+ }
@@ -1,12 +1,11 @@
1
- import type { Hex } from "../../base.js";
2
- /** Abstract interface for a [viem wallet](https://viem.sh/docs/clients/wallet). */
3
- export interface AbstractViemWalletClient {
1
+ /** Abstract interface for a viem {@link https://viem.sh/docs/accounts/jsonRpc#json-rpc-account | JSON-RPC Account}. */
2
+ export interface AbstractViemJsonRpcAccount {
4
3
  signTypedData(params: {
5
4
  domain: {
6
5
  name: string;
7
6
  version: string;
8
7
  chainId: number;
9
- verifyingContract: Hex;
8
+ verifyingContract: `0x${string}`;
10
9
  };
11
10
  types: {
12
11
  [key: string]: {
@@ -16,8 +15,30 @@ export interface AbstractViemWalletClient {
16
15
  };
17
16
  primaryType: string;
18
17
  message: Record<string, unknown>;
19
- }, options?: unknown): Promise<Hex>;
18
+ }, options?: unknown): Promise<`0x${string}`>;
19
+ getAddresses?(): Promise<`0x${string}`[]>;
20
+ getChainId?(): Promise<number>;
21
+ }
22
+ /** Abstract interface for a viem {@link https://viem.sh/docs/accounts/local | Local Account}. */
23
+ export interface AbstractViemLocalAccount {
24
+ signTypedData(params: {
25
+ domain: {
26
+ name: string;
27
+ version: string;
28
+ chainId: number;
29
+ verifyingContract: `0x${string}`;
30
+ };
31
+ types: {
32
+ [key: string]: {
33
+ name: string;
34
+ type: string;
35
+ }[];
36
+ };
37
+ primaryType: string;
38
+ message: Record<string, unknown>;
39
+ }, options?: unknown): Promise<`0x${string}`>;
40
+ address?: `0x${string}`;
20
41
  }
21
42
  /** Checks if the given value is an abstract viem wallet. */
22
- export declare function isAbstractViemWalletClient(client: unknown): client is AbstractViemWalletClient;
43
+ export declare function isAbstractViemWallet(client: unknown): client is AbstractViemJsonRpcAccount | AbstractViemLocalAccount;
23
44
  //# sourceMappingURL=viem.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"viem.d.ts","sourceRoot":"","sources":["../../../../src/src/signing/_signTypedData/viem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEzC,mFAAmF;AACnF,MAAM,WAAW,wBAAwB;IACrC,aAAa,CACT,MAAM,EAAE;QACJ,MAAM,EAAE;YACJ,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,MAAM,CAAC;YAChB,OAAO,EAAE,MAAM,CAAC;YAChB,iBAAiB,EAAE,GAAG,CAAC;SAC1B,CAAC;QACF,KAAK,EAAE;YACH,CAAC,GAAG,EAAE,MAAM,GAAG;gBACX,IAAI,EAAE,MAAM,CAAC;gBACb,IAAI,EAAE,MAAM,CAAC;aAChB,EAAE,CAAC;SACP,CAAC;QACF,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACpC,EACD,OAAO,CAAC,EAAE,OAAO,GAClB,OAAO,CAAC,GAAG,CAAC,CAAC;CACnB;AAED,4DAA4D;AAC5D,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,IAAI,wBAAwB,CAI9F"}
1
+ {"version":3,"file":"viem.d.ts","sourceRoot":"","sources":["../../../../src/src/signing/_signTypedData/viem.ts"],"names":[],"mappings":"AAAA,uHAAuH;AACvH,MAAM,WAAW,0BAA0B;IACvC,aAAa,CACT,MAAM,EAAE;QACJ,MAAM,EAAE;YACJ,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,MAAM,CAAC;YAChB,OAAO,EAAE,MAA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,5 +1,5 @@
1
1
  /** Checks if the given value is an abstract viem wallet. */
2
- export function isAbstractViemWalletClient(client) {
2
+ export function isAbstractViemWallet(client) {
3
3
  return typeof client === "object" && client !== null &&
4
4
  "signTypedData" in client && typeof client.signTypedData === "function" &&
5
5
  (client.signTypedData.length === 1 || client.signTypedData.length === 2);
@@ -1,5 +1,8 @@
1
- import type { DeepImmutable } from "../base.js";
2
- import type { ApproveAgentRequest, ApproveBuilderFeeRequest, BatchModifyRequest, CancelByCloidRequest, CancelRequest, CDepositRequest, ClaimRewardsRequest, ConvertToMultiSigUserRequest, CreateSubAccountRequest, CreateVaultRequest, CSignerActionRequest_JailSelf, CSignerActionRequest_UnjailSelf, CValidatorActionRequest_ChangeProfile, CValidatorActionRequest_Register, CValidatorActionRequest_Unregister, CWithdrawRequest, EvmUserModifyRequest, ModifyRequest, MultiSigRequest, OrderRequest, PerpDeployRequest_RegisterAsset, PerpDeployRequest_SetOracle, PerpDexClassTransferRequest, PerpDexTransferRequest, RegisterReferrerRequest, ReserveRequestWeightRequest, ScheduleCancelRequest, SetDisplayNameRequest, SetReferrerRequest, SpotDeployRequest_Genesis, SpotDeployRequest_RegisterHyperliquidity, SpotDeployRequest_RegisterSpot, SpotDeployRequest_RegisterToken2, SpotDeployRequest_SetDeployerTradingFeeShare, SpotDeployRequest_UserGenesis, SpotSendRequest, SpotUserRequest, SubAccountSpotTransferRequest, SubAccountTransferRequest, TokenDelegateRequest, TwapCancelRequest, TwapOrderRequest, UpdateIsolatedMarginRequest, UpdateLeverageRequest, UsdClassTransferRequest, UsdSendRequest, VaultDistributeRequest, VaultModifyRequest, VaultTransferRequest, Withdraw3Request } from "../types/exchange/requests.js";
1
+ import type { ApproveAgentRequest, ApproveBuilderFeeRequest, BatchModifyRequest, CancelByCloidRequest, CancelRequest, CDepositRequest, ClaimRewardsRequest, ConvertToMultiSigUserRequest, ConvertToMultiSigUserRequestWithoutStringify, CreateSubAccountRequest, CreateVaultRequest, CSignerActionRequest, CValidatorActionRequest, CWithdrawRequest, EvmUserModifyRequest, ModifyRequest, MultiSigRequest, OrderRequest, PerpDeployRequest, RegisterReferrerRequest, ReserveRequestWeightRequest, ScheduleCancelRequest, SetDisplayNameRequest, SetReferrerRequest, SpotDeployRequest, SpotSendRequest, SpotUserRequest, SubAccountModifyRequest, SubAccountSpotTransferRequest, SubAccountTransferRequest, TokenDelegateRequest, TwapCancelRequest, TwapOrderRequest, UpdateIsolatedMarginRequest, UpdateLeverageRequest, UsdClassTransferRequest, UsdSendRequest, VaultDistributeRequest, VaultModifyRequest, VaultTransferRequest, Withdraw3Request } from "../types/mod.js";
2
+ /** @see https://github.com/microsoft/TypeScript/issues/13923#issuecomment-2191862501 */
3
+ type DeepImmutable<T> = {
4
+ readonly [K in keyof T]: DeepImmutable<T[K]>;
5
+ };
3
6
  /** Action sorter and formatter for correct signature generation. */
4
7
  export declare const actionSorter: {
5
8
  approveAgent: (action: DeepImmutable<ApproveAgentRequest["action"]>) => ApproveAgentRequest["action"];
@@ -9,27 +12,26 @@ export declare const actionSorter: {
9
12
  cancelByCloid: (action: DeepImmutable<CancelByCloidRequest["action"]>) => CancelByCloidRequest["action"];
10
13
  cDeposit: (action: DeepImmutable<CDepositRequest["action"]>) => CDepositRequest["action"];
11
14
  claimRewards: (action: DeepImmutable<ClaimRewardsRequest["action"]>) => ClaimRewardsRequest["action"];
12
- convertToMultiSigUser: (action: DeepImmutable<ConvertToMultiSigUserRequest["action"]>) => ConvertToMultiSigUserRequest["action"];
15
+ convertToMultiSigUser: (action: DeepImmutable<ConvertToMultiSigUserRequest["action"] | ConvertToMultiSigUserRequestWithoutStringify["action"]>) => ConvertToMultiSigUserRequest["action"];
13
16
  createSubAccount: (action: DeepImmutable<CreateSubAccountRequest["action"]>) => CreateSubAccountRequest["action"];
14
17
  createVault: (action: DeepImmutable<CreateVaultRequest["action"]>) => CreateVaultRequest["action"];
15
- CSignerAction: (action: DeepImmutable<CSignerActionRequest_JailSelf["action"]> | DeepImmutable<CSignerActionRequest_UnjailSelf["action"]>) => CSignerActionRequest_JailSelf["action"] | CSignerActionRequest_UnjailSelf["action"];
16
- CValidatorAction: (action: DeepImmutable<CValidatorActionRequest_ChangeProfile["action"]> | DeepImmutable<CValidatorActionRequest_Register["action"]> | DeepImmutable<CValidatorActionRequest_Unregister["action"]>) => CValidatorActionRequest_ChangeProfile["action"] | CValidatorActionRequest_Register["action"] | CValidatorActionRequest_Unregister["action"];
18
+ CSignerAction: (action: DeepImmutable<CSignerActionRequest["action"]>) => CSignerActionRequest["action"];
19
+ CValidatorAction: (action: DeepImmutable<CValidatorActionRequest["action"]>) => CValidatorActionRequest["action"];
17
20
  cWithdraw: (action: DeepImmutable<CWithdrawRequest["action"]>) => CWithdrawRequest["action"];
18
21
  evmUserModify: (action: DeepImmutable<EvmUserModifyRequest["action"]>) => EvmUserModifyRequest["action"];
19
22
  modify: (action: DeepImmutable<ModifyRequest["action"]>) => ModifyRequest["action"];
20
23
  multiSig: (action: DeepImmutable<MultiSigRequest["action"]>) => MultiSigRequest["action"];
21
24
  order: (action: DeepImmutable<OrderRequest["action"]>) => OrderRequest["action"];
22
- perpDeploy: (action: DeepImmutable<PerpDeployRequest_RegisterAsset["action"]> | DeepImmutable<PerpDeployRequest_SetOracle["action"]>) => PerpDeployRequest_RegisterAsset["action"] | PerpDeployRequest_SetOracle["action"];
23
- PerpDexClassTransfer: (action: DeepImmutable<PerpDexClassTransferRequest["action"]>) => PerpDexClassTransferRequest["action"];
24
- PerpDexTransfer: (action: DeepImmutable<PerpDexTransferRequest["action"]>) => PerpDexTransferRequest["action"];
25
+ perpDeploy: (action: DeepImmutable<PerpDeployRequest["action"]>) => PerpDeployRequest["action"];
25
26
  registerReferrer: (action: DeepImmutable<RegisterReferrerRequest["action"]>) => RegisterReferrerRequest["action"];
26
27
  reserveRequestWeight: (action: DeepImmutable<ReserveRequestWeightRequest["action"]>) => ReserveRequestWeightRequest["action"];
27
28
  scheduleCancel: (action: DeepImmutable<ScheduleCancelRequest["action"]>) => ScheduleCancelRequest["action"];
28
29
  setDisplayName: (action: DeepImmutable<SetDisplayNameRequest["action"]>) => SetDisplayNameRequest["action"];
29
30
  setReferrer: (action: DeepImmutable<SetReferrerRequest["action"]>) => SetReferrerRequest["action"];
30
- spotDeploy: (action: DeepImmutable<SpotDeployRequest_Genesis["action"]> | DeepImmutable<SpotDeployRequest_RegisterHyperliquidity["action"]> | DeepImmutable<SpotDeployRequest_RegisterSpot["action"]> | DeepImmutable<SpotDeployRequest_RegisterToken2["action"]> | DeepImmutable<SpotDeployRequest_SetDeployerTradingFeeShare["action"]> | DeepImmutable<SpotDeployRequest_UserGenesis["action"]>) => SpotDeployRequest_Genesis["action"] | SpotDeployRequest_RegisterHyperliquidity["action"] | SpotDeployRequest_RegisterSpot["action"] | SpotDeployRequest_RegisterToken2["action"] | SpotDeployRequest_SetDeployerTradingFeeShare["action"] | SpotDeployRequest_UserGenesis["action"];
31
+ spotDeploy: (action: DeepImmutable<SpotDeployRequest["action"]>) => SpotDeployRequest["action"];
31
32
  spotSend: (action: DeepImmutable<SpotSendRequest["action"]>) => SpotSendRequest["action"];
32
33
  spotUser: (action: DeepImmutable<SpotUserRequest["action"]>) => SpotUserRequest["action"];
34
+ subAccountModify: (action: DeepImmutable<SubAccountModifyRequest["action"]>) => SubAccountModifyRequest["action"];
33
35
  subAccountSpotTransfer: (action: DeepImmutable<SubAccountSpotTransferRequest["action"]>) => SubAccountSpotTransferRequest["action"];
34
36
  subAccountTransfer: (action: DeepImmutable<SubAccountTransferRequest["action"]>) => SubAccountTransferRequest["action"];
35
37
  tokenDelegate: (action: DeepImmutable<TokenDelegateRequest["action"]>) => TokenDelegateRequest["action"];
@@ -76,18 +78,6 @@ export declare const userSignedActionEip712Types: {
76
78
  type: string;
77
79
  }[];
78
80
  };
79
- PerpDexClassTransfer: {
80
- "HyperliquidTransaction:PerpDexClassTransfer": {
81
- name: string;
82
- type: string;
83
- }[];
84
- };
85
- PerpDexTransfer: {
86
- "HyperliquidTransaction:PerpDexTransfer": {
87
- name: string;
88
- type: string;
89
- }[];
90
- };
91
81
  multiSig: {
92
82
  "HyperliquidTransaction:SendMultiSig": {
93
83
  name: string;
@@ -125,4 +115,5 @@ export declare const userSignedActionEip712Types: {
125
115
  }[];
126
116
  };
127
117
  };
118
+ export {};
128
119
  //# sourceMappingURL=_sorter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_sorter.d.ts","sourceRoot":"","sources":["../../../src/src/signing/_sorter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAO,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EACR,mBAAmB,EACnB,wBAAwB,EACxB,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,4BAA4B,EAC5B,uBAAuB,EACvB,kBAAkB,EAClB,6BAA6B,EAC7B,+BAA+B,EAC/B,qCAAqC,EACrC,gCAAgC,EAChC,kCAAkC,EAClC,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACb,eAAe,EACf,YAAY,EACZ,+BAA+B,EAC/B,2BAA2B,EAC3B,2BAA2B,EAC3B,sBAAsB,EACtB,uBAAuB,EACvB,2BAA2B,EAC3B,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,yBAAyB,EACzB,wCAAwC,EACxC,8BAA8B,EAC9B,gCAAgC,EAChC,4CAA4C,EAC5C,6BAA6B,EAC7B,eAAe,EACf,eAAe,EACf,6BAA6B,EAC7B,yBAAyB,EACzB,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,2BAA2B,EAC3B,qBAAqB,EACrB,uBAAuB,EACvB,cAAc,EACd,sBAAsB,EACtB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EACnB,MAAM,+BAA+B,CAAC;AAEvC,oEAAoE;AACpE,eAAO,MAAM,YAAY;2BACE,aAAa,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC,KAAG,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CAAC,CAAC,KAAG,kBAAkB,CAAC,QAAQ,CAAC;4BAQxE,aAAa,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC,KAAG,oBAAoB,CAAC,QAAQ,CAAC;wBAQlF,aAAa,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,KAAG,gBAAgB,CAAC,QAAQ,CAAC;CAU7F,CAAC;AAYF,wDAAwD;AACxD,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuFvC,CAAC"}
@@ -6,7 +6,7 @@ export const actionSorter = {
6
6
  signatureChainId: action.signatureChainId,
7
7
  hyperliquidChain: action.hyperliquidChain,
8
8
  agentAddress: action.agentAddress.toLowerCase(),
9
- agentName: action.agentName ?? "",
9
+ agentName: action.agentName,
10
10
  nonce: action.nonce,
11
11
  };
12
12
  },
@@ -91,7 +91,10 @@ export const actionSorter = {
91
91
  type: action.type,
92
92
  signatureChainId: action.signatureChainId,
93
93
  hyperliquidChain: action.hyperliquidChain,
94
- signers: action.signers, // key order is not important
94
+ signers: typeof action.signers === "string" ? action.signers : JSON.stringify(action.signers === null ? action.signers : {
95
+ authorizedUsers: action.signers.authorizedUsers,
96
+ threshold: action.signers.threshold,
97
+ }),
95
98
  nonce: action.nonce,
96
99
  };
97
100
  },
@@ -129,13 +132,13 @@ export const actionSorter = {
129
132
  return {
130
133
  type: action.type,
131
134
  changeProfile: {
132
- node_ip: action.changeProfile.node_ip ?? null,
133
- name: action.changeProfile.name ?? null,
134
- description: action.changeProfile.description ?? null,
135
+ node_ip: action.changeProfile.node_ip,
136
+ name: action.changeProfile.name,
137
+ description: action.changeProfile.description,
135
138
  unjailed: action.changeProfile.unjailed,
136
- disable_delegations: action.changeProfile.disable_delegations ?? null,
137
- commission_bps: action.changeProfile.commission_bps ?? null,
138
- signer: action.changeProfile.signer?.toLowerCase() ?? null,
139
+ disable_delegations: action.changeProfile.disable_delegations,
140
+ commission_bps: action.changeProfile.commission_bps,
141
+ signer: action.changeProfile.signer?.toLowerCase(),
139
142
  },
140
143
  };
141
144
  }
@@ -158,7 +161,7 @@ export const actionSorter = {
158
161
  },
159
162
  };
160
163
  }
161
- else { // "unregister" in action
164
+ else {
162
165
  return {
163
166
  type: action.type,
164
167
  unregister: action.unregister,
@@ -222,7 +225,9 @@ export const actionSorter = {
222
225
  payload: {
223
226
  multiSigUser: action.payload.multiSigUser.toLowerCase(),
224
227
  outerSigner: action.payload.outerSigner.toLowerCase(),
225
- action: structuredClone(action.payload.action),
228
+ action: actionSorter[action.payload.action.type](
229
+ // @ts-ignore - TypeScript cannot infer the type correctly
230
+ action.payload.action),
226
231
  },
227
232
  };
228
233
  },
@@ -272,7 +277,7 @@ export const actionSorter = {
272
277
  return {
273
278
  type: action.type,
274
279
  registerAsset: {
275
- maxGas: action.registerAsset.maxGas ?? null,
280
+ maxGas: action.registerAsset.maxGas,
276
281
  assetRequest: {
277
282
  coin: action.registerAsset.assetRequest.coin,
278
283
  szDecimals: action.registerAsset.assetRequest.szDecimals,
@@ -285,9 +290,9 @@ export const actionSorter = {
285
290
  ? {
286
291
  fullName: action.registerAsset.schema.fullName,
287
292
  collateralToken: action.registerAsset.schema.collateralToken,
288
- oracleUpdater: action.registerAsset.schema.oracleUpdater?.toLowerCase() ?? null,
293
+ oracleUpdater: action.registerAsset.schema.oracleUpdater?.toLowerCase(),
289
294
  }
290
- : null,
295
+ : action.registerAsset.schema,
291
296
  },
292
297
  };
293
298
  }
@@ -297,34 +302,11 @@ export const actionSorter = {
297
302
  setOracle: {
298
303
  dex: action.setOracle.dex,
299
304
  oraclePxs: action.setOracle.oraclePxs.map((el) => [...el]),
300
- markPxs: action.setOracle.markPxs.map((el) => [...el]),
305
+ markPxs: action.setOracle.markPxs.map((el) => el.map((el2) => [...el2])),
301
306
  },
302
307
  };
303
308
  }
304
309
  },
305
- PerpDexClassTransfer: (action) => {
306
- return {
307
- type: action.type,
308
- signatureChainId: action.signatureChainId,
309
- hyperliquidChain: action.hyperliquidChain,
310
- dex: action.dex,
311
- token: action.token,
312
- amount: action.amount,
313
- toPerp: action.toPerp,
314
- nonce: action.nonce,
315
- };
316
- },
317
- PerpDexTransfer: (action) => {
318
- return {
319
- type: action.type,
320
- signatureChainId: action.signatureChainId,
321
- hyperliquidChain: action.hyperliquidChain,
322
- sourceDex: action.sourceDex,
323
- destinationDex: action.destinationDex,
324
- amount: action.amount,
325
- nonce: action.nonce,
326
- };
327
- },
328
310
  registerReferrer: (action) => {
329
311
  return {
330
312
  type: action.type,
@@ -368,9 +350,8 @@ export const actionSorter = {
368
350
  noHyperliquidity: action.genesis.noHyperliquidity,
369
351
  },
370
352
  };
371
- if (sortedAction.genesis.noHyperliquidity === undefined) {
353
+ if (sortedAction.genesis.noHyperliquidity === undefined)
372
354
  delete sortedAction.genesis.noHyperliquidity;
373
- }
374
355
  return sortedAction;
375
356
  }
376
357
  else if ("registerHyperliquidity" in action) {
@@ -410,9 +391,8 @@ export const actionSorter = {
410
391
  fullName: action.registerToken2.fullName,
411
392
  },
412
393
  };
413
- if (sortedAction.registerToken2.fullName === undefined) {
394
+ if (sortedAction.registerToken2.fullName === undefined)
414
395
  delete sortedAction.registerToken2.fullName;
415
- }
416
396
  return sortedAction;
417
397
  }
418
398
  else if ("setDeployerTradingFeeShare" in action) {
@@ -424,7 +404,7 @@ export const actionSorter = {
424
404
  },
425
405
  };
426
406
  }
427
- else { // "userGenesis" in action
407
+ else {
428
408
  const sortedAction = {
429
409
  type: action.type,
430
410
  userGenesis: {
@@ -434,9 +414,8 @@ export const actionSorter = {
434
414
  blacklistUsers: action.userGenesis.blacklistUsers?.map((el) => [...el]),
435
415
  },
436
416
  };
437
- if (sortedAction.userGenesis.blacklistUsers === undefined) {
417
+ if (sortedAction.userGenesis.blacklistUsers === undefined)
438
418
  delete sortedAction.userGenesis.blacklistUsers;
439
- }
440
419
  return sortedAction;
441
420
  }
442
421
  },
@@ -459,6 +438,13 @@ export const actionSorter = {
459
438
  },
460
439
  };
461
440
  },
441
+ subAccountModify: (action) => {
442
+ return {
443
+ type: action.type,
444
+ subAccountUser: action.subAccountUser.toLowerCase(),
445
+ name: action.name,
446
+ };
447
+ },
462
448
  subAccountSpotTransfer: (action) => {
463
449
  return {
464
450
  type: action.type,
@@ -624,25 +610,6 @@ export const userSignedActionEip712Types = {
624
610
  { name: "nonce", type: "uint64" },
625
611
  ],
626
612
  },
627
- PerpDexClassTransfer: {
628
- "HyperliquidTransaction:PerpDexClassTransfer": [
629
- { name: "hyperliquidChain", type: "string" },
630
- { name: "dex", type: "string" },
631
- { name: "token", type: "string" },
632
- { name: "amount", type: "string" },
633
- { name: "toPerp", type: "bool" },
634
- { name: "nonce", type: "uint64" },
635
- ],
636
- },
637
- PerpDexTransfer: {
638
- "HyperliquidTransaction:PerpDexTransfer": [
639
- { name: "hyperliquidChain", type: "string" },
640
- { name: "sourceDex", type: "string" },
641
- { name: "destinationDex", type: "string" },
642
- { name: "amount", type: "string" },
643
- { name: "nonce", type: "uint64" },
644
- ],
645
- },
646
613
  multiSig: {
647
614
  "HyperliquidTransaction:SendMultiSig": [
648
615
  { name: "hyperliquidChain", type: "string" },