@nktkas/hyperliquid 0.22.1 → 0.23.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 (230) hide show
  1. package/README.md +125 -70
  2. package/esm/mod.d.ts +1 -1
  3. package/esm/mod.d.ts.map +1 -1
  4. package/esm/src/base.d.ts +4 -1
  5. package/esm/src/base.d.ts.map +1 -1
  6. package/esm/src/base.js +2 -2
  7. package/esm/src/clients/exchange.d.ts +420 -368
  8. package/esm/src/clients/exchange.d.ts.map +1 -1
  9. package/esm/src/clients/exchange.js +721 -551
  10. package/esm/src/clients/info.d.ts +137 -41
  11. package/esm/src/clients/info.d.ts.map +1 -1
  12. package/esm/src/clients/info.js +124 -28
  13. package/esm/src/clients/multiSign.d.ts +406 -484
  14. package/esm/src/clients/multiSign.d.ts.map +1 -1
  15. package/esm/src/clients/multiSign.js +639 -734
  16. package/esm/src/clients/subscription.d.ts +38 -3
  17. package/esm/src/clients/subscription.d.ts.map +1 -1
  18. package/esm/src/clients/subscription.js +36 -3
  19. package/esm/src/signing/_signTypedData/ethers.d.ts +33 -0
  20. package/esm/src/signing/_signTypedData/ethers.d.ts.map +1 -0
  21. package/esm/src/signing/_signTypedData/ethers.js +12 -0
  22. package/esm/src/signing/_signTypedData/mod.d.ts +35 -0
  23. package/esm/src/signing/_signTypedData/mod.d.ts.map +1 -0
  24. package/esm/src/signing/_signTypedData/mod.js +59 -0
  25. package/esm/src/signing/_signTypedData/private_key.d.ts +26 -0
  26. package/esm/src/signing/_signTypedData/private_key.d.ts.map +1 -0
  27. package/esm/src/signing/_signTypedData/private_key.js +144 -0
  28. package/esm/src/signing/_signTypedData/viem.d.ts +23 -0
  29. package/esm/src/signing/_signTypedData/viem.d.ts.map +1 -0
  30. package/esm/src/signing/_signTypedData/viem.js +6 -0
  31. package/esm/src/signing/_signTypedData/window.d.ts +29 -0
  32. package/esm/src/signing/_signTypedData/window.d.ts.map +1 -0
  33. package/esm/src/signing/_signTypedData/window.js +30 -0
  34. package/esm/src/signing/_sorter.d.ts +128 -0
  35. package/esm/src/signing/_sorter.d.ts.map +1 -0
  36. package/esm/src/{signing.js → signing/_sorter.js} +36 -449
  37. package/esm/src/signing/mod.d.ts +272 -0
  38. package/esm/src/signing/mod.d.ts.map +1 -0
  39. package/esm/src/signing/mod.js +306 -0
  40. package/esm/src/transports/base.d.ts +1 -1
  41. package/esm/src/transports/base.d.ts.map +1 -1
  42. package/esm/src/transports/base.js +2 -2
  43. package/esm/src/transports/http/http_transport.d.ts +9 -15
  44. package/esm/src/transports/http/http_transport.d.ts.map +1 -1
  45. package/esm/src/transports/http/http_transport.js +64 -59
  46. package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +1 -1
  47. package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
  48. package/esm/src/transports/websocket/_hyperliquid_event_target.js +1 -1
  49. package/esm/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
  50. package/esm/src/transports/websocket/_reconnecting_websocket.js +17 -4
  51. package/esm/src/transports/websocket/_websocket_async_request.d.ts +0 -9
  52. package/esm/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
  53. package/esm/src/transports/websocket/_websocket_async_request.js +14 -20
  54. package/esm/src/transports/websocket/websocket_transport.d.ts +8 -4
  55. package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  56. package/esm/src/transports/websocket/websocket_transport.js +83 -54
  57. package/esm/src/types/exchange/requests.d.ts +27 -51
  58. package/esm/src/types/exchange/requests.d.ts.map +1 -1
  59. package/esm/src/types/explorer/requests.d.ts +5 -8
  60. package/esm/src/types/explorer/requests.d.ts.map +1 -1
  61. package/esm/src/types/info/accounts.d.ts +5 -5
  62. package/esm/src/types/info/accounts.d.ts.map +1 -1
  63. package/esm/src/types/info/delegations.d.ts +1 -1
  64. package/esm/src/types/info/delegations.d.ts.map +1 -1
  65. package/esm/src/types/info/orders.d.ts +1 -1
  66. package/esm/src/types/info/orders.d.ts.map +1 -1
  67. package/esm/src/types/info/requests.d.ts +49 -96
  68. package/esm/src/types/info/requests.d.ts.map +1 -1
  69. package/esm/src/types/subscriptions/requests.d.ts +72 -18
  70. package/esm/src/types/subscriptions/requests.d.ts.map +1 -1
  71. package/esm/src/types/subscriptions/responses.d.ts +2 -0
  72. package/esm/src/types/subscriptions/responses.d.ts.map +1 -1
  73. package/package.json +12 -8
  74. package/script/mod.d.ts +1 -1
  75. package/script/mod.d.ts.map +1 -1
  76. package/script/mod.js +13 -23
  77. package/script/src/base.d.ts +4 -1
  78. package/script/src/base.d.ts.map +1 -1
  79. package/script/src/base.js +10 -20
  80. package/script/src/clients/exchange.d.ts +420 -368
  81. package/script/src/clients/exchange.d.ts.map +1 -1
  82. package/script/src/clients/exchange.js +2000 -1840
  83. package/script/src/clients/info.d.ts +137 -41
  84. package/script/src/clients/info.d.ts.map +1 -1
  85. package/script/src/clients/info.js +1296 -1210
  86. package/script/src/clients/multiSign.d.ts +406 -484
  87. package/script/src/clients/multiSign.d.ts.map +1 -1
  88. package/script/src/clients/multiSign.js +2043 -2148
  89. package/script/src/clients/subscription.d.ts +38 -3
  90. package/script/src/clients/subscription.d.ts.map +1 -1
  91. package/script/src/clients/subscription.js +568 -545
  92. package/script/src/signing/_signTypedData/ethers.d.ts +33 -0
  93. package/script/src/signing/_signTypedData/ethers.d.ts.map +1 -0
  94. package/script/src/signing/_signTypedData/ethers.js +16 -0
  95. package/script/src/signing/_signTypedData/mod.d.ts +35 -0
  96. package/script/src/signing/_signTypedData/mod.d.ts.map +1 -0
  97. package/script/src/signing/_signTypedData/mod.js +67 -0
  98. package/script/src/signing/_signTypedData/private_key.d.ts +26 -0
  99. package/script/src/signing/_signTypedData/private_key.d.ts.map +1 -0
  100. package/script/src/signing/_signTypedData/private_key.js +148 -0
  101. package/script/src/signing/_signTypedData/viem.d.ts +23 -0
  102. package/script/src/signing/_signTypedData/viem.d.ts.map +1 -0
  103. package/script/src/signing/_signTypedData/viem.js +9 -0
  104. package/script/src/signing/_signTypedData/window.d.ts +29 -0
  105. package/script/src/signing/_signTypedData/window.d.ts.map +1 -0
  106. package/script/src/signing/_signTypedData/window.js +34 -0
  107. package/script/src/signing/_sorter.d.ts +128 -0
  108. package/script/src/signing/_sorter.d.ts.map +1 -0
  109. package/script/src/signing/_sorter.js +698 -0
  110. package/script/src/signing/mod.d.ts +272 -0
  111. package/script/src/signing/mod.d.ts.map +1 -0
  112. package/script/src/signing/mod.js +331 -0
  113. package/script/src/transports/base.d.ts +1 -1
  114. package/script/src/transports/base.d.ts.map +1 -1
  115. package/script/src/transports/base.js +11 -21
  116. package/script/src/transports/http/http_transport.d.ts +9 -15
  117. package/script/src/transports/http/http_transport.d.ts.map +1 -1
  118. package/script/src/transports/http/http_transport.js +97 -102
  119. package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +1 -1
  120. package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
  121. package/script/src/transports/websocket/_hyperliquid_event_target.js +51 -61
  122. package/script/src/transports/websocket/_reconnecting_websocket.d.ts.map +1 -1
  123. package/script/src/transports/websocket/_reconnecting_websocket.js +271 -268
  124. package/script/src/transports/websocket/_websocket_async_request.d.ts +0 -9
  125. package/script/src/transports/websocket/_websocket_async_request.d.ts.map +1 -1
  126. package/script/src/transports/websocket/_websocket_async_request.js +157 -174
  127. package/script/src/transports/websocket/websocket_transport.d.ts +8 -4
  128. package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  129. package/script/src/transports/websocket/websocket_transport.js +209 -189
  130. package/script/src/types/exchange/requests.d.ts +27 -51
  131. package/script/src/types/exchange/requests.d.ts.map +1 -1
  132. package/script/src/types/exchange/requests.js +2 -12
  133. package/script/src/types/exchange/responses.js +2 -12
  134. package/script/src/types/explorer/requests.d.ts +5 -8
  135. package/script/src/types/explorer/requests.d.ts.map +1 -1
  136. package/script/src/types/explorer/requests.js +2 -12
  137. package/script/src/types/explorer/responses.js +2 -12
  138. package/script/src/types/info/accounts.d.ts +5 -5
  139. package/script/src/types/info/accounts.d.ts.map +1 -1
  140. package/script/src/types/info/accounts.js +2 -12
  141. package/script/src/types/info/assets.js +2 -12
  142. package/script/src/types/info/delegations.d.ts +1 -1
  143. package/script/src/types/info/delegations.d.ts.map +1 -1
  144. package/script/src/types/info/delegations.js +2 -12
  145. package/script/src/types/info/markets.js +2 -12
  146. package/script/src/types/info/orders.d.ts +1 -1
  147. package/script/src/types/info/orders.d.ts.map +1 -1
  148. package/script/src/types/info/orders.js +2 -12
  149. package/script/src/types/info/requests.d.ts +49 -96
  150. package/script/src/types/info/requests.d.ts.map +1 -1
  151. package/script/src/types/info/requests.js +2 -12
  152. package/script/src/types/info/vaults.js +2 -12
  153. package/script/src/types/mod.js +2 -12
  154. package/script/src/types/subscriptions/requests.d.ts +72 -18
  155. package/script/src/types/subscriptions/requests.d.ts.map +1 -1
  156. package/script/src/types/subscriptions/requests.js +2 -12
  157. package/script/src/types/subscriptions/responses.d.ts +2 -0
  158. package/script/src/types/subscriptions/responses.d.ts.map +1 -1
  159. package/script/src/types/subscriptions/responses.js +2 -12
  160. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts +0 -2
  161. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts.map +0 -1
  162. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +0 -1
  163. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts +0 -95
  164. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts.map +0 -1
  165. package/esm/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +0 -10
  166. package/esm/deps/jsr.io/@std/async/1.0.13/delay.d.ts +0 -43
  167. package/esm/deps/jsr.io/@std/async/1.0.13/delay.d.ts.map +0 -1
  168. package/esm/deps/jsr.io/@std/async/1.0.13/delay.js +0 -63
  169. package/esm/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts +0 -9
  170. package/esm/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts.map +0 -1
  171. package/esm/deps/jsr.io/@std/bytes/1.0.6/_types.js +0 -2
  172. package/esm/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts +0 -21
  173. package/esm/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts.map +0 -1
  174. package/esm/deps/jsr.io/@std/bytes/1.0.6/concat.js +0 -32
  175. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
  176. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
  177. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -51
  178. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
  179. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
  180. package/esm/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -13
  181. package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
  182. package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
  183. package/esm/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -2
  184. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
  185. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
  186. package/esm/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -87
  187. package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +0 -9
  188. package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +0 -1
  189. package/esm/deps/jsr.io/@std/msgpack/1.0.3/_types.js +0 -2
  190. package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts +0 -39
  191. package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +0 -1
  192. package/esm/deps/jsr.io/@std/msgpack/1.0.3/encode.js +0 -237
  193. package/esm/src/signing.d.ts +0 -463
  194. package/esm/src/signing.d.ts.map +0 -1
  195. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts +0 -2
  196. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.d.ts.map +0 -1
  197. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/mod.js +0 -27
  198. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts +0 -95
  199. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.d.ts.map +0 -1
  200. package/script/deps/jsr.io/@derzade/typescript-event-target/1.1.1/src/TypedEventTarget.js +0 -24
  201. package/script/deps/jsr.io/@std/async/1.0.13/delay.d.ts +0 -43
  202. package/script/deps/jsr.io/@std/async/1.0.13/delay.d.ts.map +0 -1
  203. package/script/deps/jsr.io/@std/async/1.0.13/delay.js +0 -76
  204. package/script/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts +0 -9
  205. package/script/deps/jsr.io/@std/bytes/1.0.6/_types.d.ts.map +0 -1
  206. package/script/deps/jsr.io/@std/bytes/1.0.6/_types.js +0 -13
  207. package/script/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts +0 -21
  208. package/script/deps/jsr.io/@std/bytes/1.0.6/concat.d.ts.map +0 -1
  209. package/script/deps/jsr.io/@std/bytes/1.0.6/concat.js +0 -45
  210. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts +0 -23
  211. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.d.ts.map +0 -1
  212. package/script/deps/jsr.io/@std/encoding/1.0.10/_common16.js +0 -67
  213. package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts +0 -4
  214. package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.d.ts.map +0 -1
  215. package/script/deps/jsr.io/@std/encoding/1.0.10/_common_detach.js +0 -26
  216. package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts +0 -9
  217. package/script/deps/jsr.io/@std/encoding/1.0.10/_types.d.ts.map +0 -1
  218. package/script/deps/jsr.io/@std/encoding/1.0.10/_types.js +0 -13
  219. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts +0 -39
  220. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.d.ts.map +0 -1
  221. package/script/deps/jsr.io/@std/encoding/1.0.10/hex.js +0 -101
  222. package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts +0 -9
  223. package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.d.ts.map +0 -1
  224. package/script/deps/jsr.io/@std/msgpack/1.0.3/_types.js +0 -13
  225. package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts +0 -39
  226. package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.d.ts.map +0 -1
  227. package/script/deps/jsr.io/@std/msgpack/1.0.3/encode.js +0 -250
  228. package/script/src/signing.d.ts +0 -463
  229. package/script/src/signing.d.ts.map +0 -1
  230. package/script/src/signing.js +0 -1129
@@ -0,0 +1,698 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.userSignedActionEip712Types = exports.actionSorter = void 0;
4
+ /** Action sorter and formatter for correct signature generation. */
5
+ exports.actionSorter = {
6
+ approveAgent: (action) => {
7
+ return {
8
+ type: action.type,
9
+ signatureChainId: action.signatureChainId,
10
+ hyperliquidChain: action.hyperliquidChain,
11
+ agentAddress: action.agentAddress.toLowerCase(),
12
+ agentName: action.agentName ?? "",
13
+ nonce: action.nonce,
14
+ };
15
+ },
16
+ approveBuilderFee: (action) => {
17
+ return {
18
+ type: action.type,
19
+ signatureChainId: action.signatureChainId,
20
+ hyperliquidChain: action.hyperliquidChain,
21
+ maxFeeRate: action.maxFeeRate,
22
+ builder: action.builder.toLowerCase(),
23
+ nonce: action.nonce,
24
+ };
25
+ },
26
+ batchModify: (action) => {
27
+ return {
28
+ type: action.type,
29
+ modifies: action.modifies.map((modify) => {
30
+ const sortedModify = {
31
+ oid: modify.oid,
32
+ order: {
33
+ a: modify.order.a,
34
+ b: modify.order.b,
35
+ p: formatDecimal(modify.order.p),
36
+ s: formatDecimal(modify.order.s),
37
+ r: modify.order.r,
38
+ t: "limit" in modify.order.t
39
+ ? {
40
+ limit: {
41
+ tif: modify.order.t.limit.tif,
42
+ },
43
+ }
44
+ : {
45
+ trigger: {
46
+ isMarket: modify.order.t.trigger.isMarket,
47
+ triggerPx: formatDecimal(modify.order.t.trigger.triggerPx),
48
+ tpsl: modify.order.t.trigger.tpsl,
49
+ },
50
+ },
51
+ c: modify.order.c,
52
+ },
53
+ };
54
+ if (sortedModify.order.c === undefined)
55
+ delete sortedModify.order.c;
56
+ return sortedModify;
57
+ }),
58
+ };
59
+ },
60
+ cancel: (action) => {
61
+ return {
62
+ type: action.type,
63
+ cancels: action.cancels.map((cancel) => ({
64
+ a: cancel.a,
65
+ o: cancel.o,
66
+ })),
67
+ };
68
+ },
69
+ cancelByCloid: (action) => {
70
+ return {
71
+ type: action.type,
72
+ cancels: action.cancels.map((cancel) => ({
73
+ asset: cancel.asset,
74
+ cloid: cancel.cloid,
75
+ })),
76
+ };
77
+ },
78
+ cDeposit: (action) => {
79
+ return {
80
+ type: action.type,
81
+ signatureChainId: action.signatureChainId,
82
+ hyperliquidChain: action.hyperliquidChain,
83
+ wei: action.wei,
84
+ nonce: action.nonce,
85
+ };
86
+ },
87
+ claimRewards: (action) => {
88
+ return {
89
+ type: action.type,
90
+ };
91
+ },
92
+ convertToMultiSigUser: (action) => {
93
+ return {
94
+ type: action.type,
95
+ signatureChainId: action.signatureChainId,
96
+ hyperliquidChain: action.hyperliquidChain,
97
+ signers: action.signers, // key order is not important
98
+ nonce: action.nonce,
99
+ };
100
+ },
101
+ createSubAccount: (action) => {
102
+ return {
103
+ type: action.type,
104
+ name: action.name,
105
+ };
106
+ },
107
+ createVault: (action) => {
108
+ return {
109
+ type: action.type,
110
+ name: action.name,
111
+ description: action.description,
112
+ initialUsd: action.initialUsd,
113
+ nonce: action.nonce,
114
+ };
115
+ },
116
+ CSignerAction: (action) => {
117
+ if ("jailSelf" in action) {
118
+ return {
119
+ type: action.type,
120
+ jailSelf: action.jailSelf,
121
+ };
122
+ }
123
+ else {
124
+ return {
125
+ type: action.type,
126
+ unjailSelf: action.unjailSelf,
127
+ };
128
+ }
129
+ },
130
+ CValidatorAction: (action) => {
131
+ if ("changeProfile" in action) {
132
+ return {
133
+ type: action.type,
134
+ changeProfile: {
135
+ node_ip: action.changeProfile.node_ip ?? null,
136
+ name: action.changeProfile.name ?? null,
137
+ description: action.changeProfile.description ?? null,
138
+ unjailed: action.changeProfile.unjailed,
139
+ disable_delegations: action.changeProfile.disable_delegations ?? null,
140
+ commission_bps: action.changeProfile.commission_bps ?? null,
141
+ signer: action.changeProfile.signer?.toLowerCase() ?? null,
142
+ },
143
+ };
144
+ }
145
+ else if ("register" in action) {
146
+ return {
147
+ type: action.type,
148
+ register: {
149
+ profile: {
150
+ node_ip: {
151
+ Ip: action.register.profile.node_ip.Ip,
152
+ },
153
+ name: action.register.profile.name,
154
+ description: action.register.profile.description,
155
+ delegations_disabled: action.register.profile.delegations_disabled,
156
+ commission_bps: action.register.profile.commission_bps,
157
+ signer: action.register.profile.signer.toLowerCase(),
158
+ },
159
+ unjailed: action.register.unjailed,
160
+ initial_wei: action.register.initial_wei,
161
+ },
162
+ };
163
+ }
164
+ else { // "unregister" in action
165
+ return {
166
+ type: action.type,
167
+ unregister: action.unregister,
168
+ };
169
+ }
170
+ },
171
+ cWithdraw: (action) => {
172
+ return {
173
+ type: action.type,
174
+ signatureChainId: action.signatureChainId,
175
+ hyperliquidChain: action.hyperliquidChain,
176
+ wei: action.wei,
177
+ nonce: action.nonce,
178
+ };
179
+ },
180
+ evmUserModify: (action) => {
181
+ return {
182
+ type: action.type,
183
+ usingBigBlocks: action.usingBigBlocks,
184
+ };
185
+ },
186
+ modify: (action) => {
187
+ const sortedAction = {
188
+ type: action.type,
189
+ oid: action.oid,
190
+ order: {
191
+ a: action.order.a,
192
+ b: action.order.b,
193
+ p: formatDecimal(action.order.p),
194
+ s: formatDecimal(action.order.s),
195
+ r: action.order.r,
196
+ t: "limit" in action.order.t
197
+ ? {
198
+ limit: {
199
+ tif: action.order.t.limit.tif,
200
+ },
201
+ }
202
+ : {
203
+ trigger: {
204
+ isMarket: action.order.t.trigger.isMarket,
205
+ triggerPx: formatDecimal(action.order.t.trigger.triggerPx),
206
+ tpsl: action.order.t.trigger.tpsl,
207
+ },
208
+ },
209
+ c: action.order.c,
210
+ },
211
+ };
212
+ if (sortedAction.order.c === undefined)
213
+ delete sortedAction.order.c;
214
+ return sortedAction;
215
+ },
216
+ multiSig: (action) => {
217
+ return {
218
+ type: action.type,
219
+ signatureChainId: action.signatureChainId,
220
+ signatures: action.signatures.map((signature) => ({
221
+ r: signature.r.replace(/^0x0+/, "0x").toLowerCase(),
222
+ s: signature.s.replace(/^0x0+/, "0x").toLowerCase(),
223
+ v: signature.v,
224
+ })),
225
+ payload: {
226
+ multiSigUser: action.payload.multiSigUser.toLowerCase(),
227
+ outerSigner: action.payload.outerSigner.toLowerCase(),
228
+ action: structuredClone(action.payload.action),
229
+ },
230
+ };
231
+ },
232
+ order: (action) => {
233
+ const sortedAction = {
234
+ type: action.type,
235
+ orders: action.orders.map((order) => {
236
+ const sortedOrder = {
237
+ a: order.a,
238
+ b: order.b,
239
+ p: formatDecimal(order.p),
240
+ s: formatDecimal(order.s),
241
+ r: order.r,
242
+ t: "limit" in order.t
243
+ ? {
244
+ limit: {
245
+ tif: order.t.limit.tif,
246
+ },
247
+ }
248
+ : {
249
+ trigger: {
250
+ isMarket: order.t.trigger.isMarket,
251
+ triggerPx: formatDecimal(order.t.trigger.triggerPx),
252
+ tpsl: order.t.trigger.tpsl,
253
+ },
254
+ },
255
+ c: order.c,
256
+ };
257
+ if (order.c === undefined)
258
+ delete sortedOrder.c;
259
+ return sortedOrder;
260
+ }),
261
+ grouping: action.grouping,
262
+ builder: action.builder
263
+ ? {
264
+ b: action.builder.b.toLowerCase(),
265
+ f: action.builder.f,
266
+ }
267
+ : action.builder,
268
+ };
269
+ if (sortedAction.builder === undefined)
270
+ delete sortedAction.builder;
271
+ return sortedAction;
272
+ },
273
+ perpDeploy: (action) => {
274
+ if ("registerAsset" in action) {
275
+ return {
276
+ type: action.type,
277
+ registerAsset: {
278
+ maxGas: action.registerAsset.maxGas ?? null,
279
+ assetRequest: {
280
+ coin: action.registerAsset.assetRequest.coin,
281
+ szDecimals: action.registerAsset.assetRequest.szDecimals,
282
+ oraclePx: action.registerAsset.assetRequest.oraclePx,
283
+ marginTableId: action.registerAsset.assetRequest.marginTableId,
284
+ onlyIsolated: action.registerAsset.assetRequest.onlyIsolated,
285
+ },
286
+ dex: action.registerAsset.dex,
287
+ schema: action.registerAsset.schema
288
+ ? {
289
+ fullName: action.registerAsset.schema.fullName,
290
+ collateralToken: action.registerAsset.schema.collateralToken,
291
+ oracleUpdater: action.registerAsset.schema.oracleUpdater?.toLowerCase() ?? null,
292
+ }
293
+ : null,
294
+ },
295
+ };
296
+ }
297
+ else {
298
+ return {
299
+ type: action.type,
300
+ setOracle: {
301
+ dex: action.setOracle.dex,
302
+ oraclePxs: action.setOracle.oraclePxs.map((el) => [...el]),
303
+ markPxs: action.setOracle.markPxs.map((el) => [...el]),
304
+ },
305
+ };
306
+ }
307
+ },
308
+ PerpDexClassTransfer: (action) => {
309
+ return {
310
+ type: action.type,
311
+ signatureChainId: action.signatureChainId,
312
+ hyperliquidChain: action.hyperliquidChain,
313
+ dex: action.dex,
314
+ token: action.token,
315
+ amount: action.amount,
316
+ toPerp: action.toPerp,
317
+ nonce: action.nonce,
318
+ };
319
+ },
320
+ PerpDexTransfer: (action) => {
321
+ return {
322
+ type: action.type,
323
+ signatureChainId: action.signatureChainId,
324
+ hyperliquidChain: action.hyperliquidChain,
325
+ sourceDex: action.sourceDex,
326
+ destinationDex: action.destinationDex,
327
+ amount: action.amount,
328
+ nonce: action.nonce,
329
+ };
330
+ },
331
+ registerReferrer: (action) => {
332
+ return {
333
+ type: action.type,
334
+ code: action.code,
335
+ };
336
+ },
337
+ reserveRequestWeight: (action) => {
338
+ return {
339
+ type: action.type,
340
+ weight: action.weight,
341
+ };
342
+ },
343
+ scheduleCancel: (action) => {
344
+ const sortedAction = {
345
+ type: action.type,
346
+ time: action.time,
347
+ };
348
+ if (sortedAction.time === undefined)
349
+ delete sortedAction.time;
350
+ return sortedAction;
351
+ },
352
+ setDisplayName: (action) => {
353
+ return {
354
+ type: action.type,
355
+ displayName: action.displayName,
356
+ };
357
+ },
358
+ setReferrer: (action) => {
359
+ return {
360
+ type: action.type,
361
+ code: action.code,
362
+ };
363
+ },
364
+ spotDeploy: (action) => {
365
+ if ("genesis" in action) {
366
+ const sortedAction = {
367
+ type: action.type,
368
+ genesis: {
369
+ token: action.genesis.token,
370
+ maxSupply: action.genesis.maxSupply,
371
+ noHyperliquidity: action.genesis.noHyperliquidity,
372
+ },
373
+ };
374
+ if (sortedAction.genesis.noHyperliquidity === undefined) {
375
+ delete sortedAction.genesis.noHyperliquidity;
376
+ }
377
+ return sortedAction;
378
+ }
379
+ else if ("registerHyperliquidity" in action) {
380
+ const sortedAction = {
381
+ type: action.type,
382
+ registerHyperliquidity: {
383
+ spot: action.registerHyperliquidity.spot,
384
+ startPx: action.registerHyperliquidity.startPx,
385
+ orderSz: action.registerHyperliquidity.orderSz,
386
+ nOrders: action.registerHyperliquidity.nOrders,
387
+ nSeededLevels: action.registerHyperliquidity.nSeededLevels,
388
+ },
389
+ };
390
+ if (sortedAction.registerHyperliquidity.nSeededLevels === undefined) {
391
+ delete sortedAction.registerHyperliquidity.nSeededLevels;
392
+ }
393
+ return sortedAction;
394
+ }
395
+ else if ("registerSpot" in action) {
396
+ return {
397
+ type: action.type,
398
+ registerSpot: {
399
+ tokens: [...action.registerSpot.tokens],
400
+ },
401
+ };
402
+ }
403
+ else if ("registerToken2" in action) {
404
+ const sortedAction = {
405
+ type: action.type,
406
+ registerToken2: {
407
+ spec: {
408
+ name: action.registerToken2.spec.name,
409
+ szDecimals: action.registerToken2.spec.szDecimals,
410
+ weiDecimals: action.registerToken2.spec.weiDecimals,
411
+ },
412
+ maxGas: action.registerToken2.maxGas,
413
+ fullName: action.registerToken2.fullName,
414
+ },
415
+ };
416
+ if (sortedAction.registerToken2.fullName === undefined) {
417
+ delete sortedAction.registerToken2.fullName;
418
+ }
419
+ return sortedAction;
420
+ }
421
+ else if ("setDeployerTradingFeeShare" in action) {
422
+ return {
423
+ type: action.type,
424
+ setDeployerTradingFeeShare: {
425
+ token: action.setDeployerTradingFeeShare.token,
426
+ share: action.setDeployerTradingFeeShare.share,
427
+ },
428
+ };
429
+ }
430
+ else { // "userGenesis" in action
431
+ const sortedAction = {
432
+ type: action.type,
433
+ userGenesis: {
434
+ token: action.userGenesis.token,
435
+ userAndWei: action.userGenesis.userAndWei.map((el) => [...el]),
436
+ existingTokenAndWei: action.userGenesis.existingTokenAndWei.map((el) => [...el]),
437
+ blacklistUsers: action.userGenesis.blacklistUsers?.map((el) => [...el]),
438
+ },
439
+ };
440
+ if (sortedAction.userGenesis.blacklistUsers === undefined) {
441
+ delete sortedAction.userGenesis.blacklistUsers;
442
+ }
443
+ return sortedAction;
444
+ }
445
+ },
446
+ spotSend: (action) => {
447
+ return {
448
+ type: action.type,
449
+ signatureChainId: action.signatureChainId,
450
+ hyperliquidChain: action.hyperliquidChain,
451
+ destination: action.destination.toLowerCase(),
452
+ token: action.token,
453
+ amount: action.amount,
454
+ time: action.time,
455
+ };
456
+ },
457
+ spotUser: (action) => {
458
+ return {
459
+ type: action.type,
460
+ toggleSpotDusting: {
461
+ optOut: action.toggleSpotDusting.optOut,
462
+ },
463
+ };
464
+ },
465
+ subAccountSpotTransfer: (action) => {
466
+ return {
467
+ type: action.type,
468
+ subAccountUser: action.subAccountUser.toLowerCase(),
469
+ isDeposit: action.isDeposit,
470
+ token: action.token,
471
+ amount: action.amount,
472
+ };
473
+ },
474
+ subAccountTransfer: (action) => {
475
+ return {
476
+ type: action.type,
477
+ subAccountUser: action.subAccountUser.toLowerCase(),
478
+ isDeposit: action.isDeposit,
479
+ usd: action.usd,
480
+ };
481
+ },
482
+ tokenDelegate: (action) => {
483
+ return {
484
+ type: action.type,
485
+ signatureChainId: action.signatureChainId,
486
+ hyperliquidChain: action.hyperliquidChain,
487
+ validator: action.validator.toLowerCase(),
488
+ wei: action.wei,
489
+ isUndelegate: action.isUndelegate,
490
+ nonce: action.nonce,
491
+ };
492
+ },
493
+ twapCancel: (action) => {
494
+ return {
495
+ type: action.type,
496
+ a: action.a,
497
+ t: action.t,
498
+ };
499
+ },
500
+ twapOrder: (action) => {
501
+ return {
502
+ type: action.type,
503
+ twap: {
504
+ a: action.twap.a,
505
+ b: action.twap.b,
506
+ s: formatDecimal(action.twap.s),
507
+ r: action.twap.r,
508
+ m: action.twap.m,
509
+ t: action.twap.t,
510
+ },
511
+ };
512
+ },
513
+ updateIsolatedMargin: (action) => {
514
+ return {
515
+ type: action.type,
516
+ asset: action.asset,
517
+ isBuy: action.isBuy,
518
+ ntli: action.ntli,
519
+ };
520
+ },
521
+ updateLeverage: (action) => {
522
+ return {
523
+ type: action.type,
524
+ asset: action.asset,
525
+ isCross: action.isCross,
526
+ leverage: action.leverage,
527
+ };
528
+ },
529
+ usdClassTransfer: (action) => {
530
+ return {
531
+ type: action.type,
532
+ signatureChainId: action.signatureChainId,
533
+ hyperliquidChain: action.hyperliquidChain,
534
+ amount: action.amount,
535
+ toPerp: action.toPerp,
536
+ nonce: action.nonce,
537
+ };
538
+ },
539
+ usdSend: (action) => {
540
+ return {
541
+ type: action.type,
542
+ signatureChainId: action.signatureChainId,
543
+ hyperliquidChain: action.hyperliquidChain,
544
+ destination: action.destination.toLowerCase(),
545
+ amount: action.amount,
546
+ time: action.time,
547
+ };
548
+ },
549
+ vaultDistribute: (action) => {
550
+ return {
551
+ type: action.type,
552
+ vaultAddress: action.vaultAddress,
553
+ usd: action.usd,
554
+ };
555
+ },
556
+ vaultModify: (action) => {
557
+ return {
558
+ type: action.type,
559
+ vaultAddress: action.vaultAddress,
560
+ allowDeposits: action.allowDeposits,
561
+ alwaysCloseOnWithdraw: action.alwaysCloseOnWithdraw,
562
+ };
563
+ },
564
+ vaultTransfer: (action) => {
565
+ return {
566
+ type: action.type,
567
+ vaultAddress: action.vaultAddress,
568
+ isDeposit: action.isDeposit,
569
+ usd: action.usd,
570
+ };
571
+ },
572
+ withdraw3: (action) => {
573
+ return {
574
+ type: action.type,
575
+ signatureChainId: action.signatureChainId,
576
+ hyperliquidChain: action.hyperliquidChain,
577
+ destination: action.destination.toLowerCase(),
578
+ amount: action.amount,
579
+ time: action.time,
580
+ };
581
+ },
582
+ };
583
+ /** Removes trailing zeros from decimal string. */
584
+ function formatDecimal(numStr) {
585
+ if (!numStr.includes("."))
586
+ return numStr;
587
+ const [intPart, fracPart] = numStr.split(".");
588
+ const newFrac = fracPart.replace(/0+$/, "");
589
+ return newFrac ? `${intPart}.${newFrac}` : intPart;
590
+ }
591
+ /** EIP-712 type definitions for user-signed actions. */
592
+ exports.userSignedActionEip712Types = {
593
+ approveAgent: {
594
+ "HyperliquidTransaction:ApproveAgent": [
595
+ { name: "hyperliquidChain", type: "string" },
596
+ { name: "agentAddress", type: "address" },
597
+ { name: "agentName", type: "string" },
598
+ { name: "nonce", type: "uint64" },
599
+ ],
600
+ },
601
+ approveBuilderFee: {
602
+ "HyperliquidTransaction:ApproveBuilderFee": [
603
+ { name: "hyperliquidChain", type: "string" },
604
+ { name: "maxFeeRate", type: "string" },
605
+ { name: "builder", type: "address" },
606
+ { name: "nonce", type: "uint64" },
607
+ ],
608
+ },
609
+ cDeposit: {
610
+ "HyperliquidTransaction:CDeposit": [
611
+ { name: "hyperliquidChain", type: "string" },
612
+ { name: "wei", type: "uint64" },
613
+ { name: "nonce", type: "uint64" },
614
+ ],
615
+ },
616
+ convertToMultiSigUser: {
617
+ "HyperliquidTransaction:ConvertToMultiSigUser": [
618
+ { name: "hyperliquidChain", type: "string" },
619
+ { name: "signers", type: "string" },
620
+ { name: "nonce", type: "uint64" },
621
+ ],
622
+ },
623
+ cWithdraw: {
624
+ "HyperliquidTransaction:CWithdraw": [
625
+ { name: "hyperliquidChain", type: "string" },
626
+ { name: "wei", type: "uint64" },
627
+ { name: "nonce", type: "uint64" },
628
+ ],
629
+ },
630
+ PerpDexClassTransfer: {
631
+ "HyperliquidTransaction:PerpDexClassTransfer": [
632
+ { name: "hyperliquidChain", type: "string" },
633
+ { name: "dex", type: "string" },
634
+ { name: "token", type: "string" },
635
+ { name: "amount", type: "string" },
636
+ { name: "toPerp", type: "bool" },
637
+ { name: "nonce", type: "uint64" },
638
+ ],
639
+ },
640
+ PerpDexTransfer: {
641
+ "HyperliquidTransaction:PerpDexTransfer": [
642
+ { name: "hyperliquidChain", type: "string" },
643
+ { name: "sourceDex", type: "string" },
644
+ { name: "destinationDex", type: "string" },
645
+ { name: "amount", type: "string" },
646
+ { name: "nonce", type: "uint64" },
647
+ ],
648
+ },
649
+ multiSig: {
650
+ "HyperliquidTransaction:SendMultiSig": [
651
+ { name: "hyperliquidChain", type: "string" },
652
+ { name: "multiSigActionHash", type: "bytes32" },
653
+ { name: "nonce", type: "uint64" },
654
+ ],
655
+ },
656
+ spotSend: {
657
+ "HyperliquidTransaction:SpotSend": [
658
+ { name: "hyperliquidChain", type: "string" },
659
+ { name: "destination", type: "string" },
660
+ { name: "token", type: "string" },
661
+ { name: "amount", type: "string" },
662
+ { name: "time", type: "uint64" },
663
+ ],
664
+ },
665
+ tokenDelegate: {
666
+ "HyperliquidTransaction:TokenDelegate": [
667
+ { name: "hyperliquidChain", type: "string" },
668
+ { name: "validator", type: "address" },
669
+ { name: "wei", type: "uint64" },
670
+ { name: "isUndelegate", type: "bool" },
671
+ { name: "nonce", type: "uint64" },
672
+ ],
673
+ },
674
+ usdClassTransfer: {
675
+ "HyperliquidTransaction:UsdClassTransfer": [
676
+ { name: "hyperliquidChain", type: "string" },
677
+ { name: "amount", type: "string" },
678
+ { name: "toPerp", type: "bool" },
679
+ { name: "nonce", type: "uint64" },
680
+ ],
681
+ },
682
+ usdSend: {
683
+ "HyperliquidTransaction:UsdSend": [
684
+ { name: "hyperliquidChain", type: "string" },
685
+ { name: "destination", type: "string" },
686
+ { name: "amount", type: "string" },
687
+ { name: "time", type: "uint64" },
688
+ ],
689
+ },
690
+ withdraw3: {
691
+ "HyperliquidTransaction:Withdraw": [
692
+ { name: "hyperliquidChain", type: "string" },
693
+ { name: "destination", type: "string" },
694
+ { name: "amount", type: "string" },
695
+ { name: "time", type: "uint64" },
696
+ ],
697
+ },
698
+ };