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