@nktkas/hyperliquid 0.24.3 → 0.25.0-beta.2

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 (358) hide show
  1. package/README.md +141 -32
  2. package/esm/mod.d.ts +11 -11
  3. package/esm/mod.d.ts.map +1 -1
  4. package/esm/mod.js +2 -1
  5. package/esm/mod.js.map +1 -0
  6. package/esm/src/clients/exchange.d.ts +29 -25
  7. package/esm/src/clients/exchange.d.ts.map +1 -1
  8. package/esm/src/clients/exchange.js +54 -53
  9. package/esm/src/clients/exchange.js.map +1 -0
  10. package/esm/src/clients/info.d.ts +80 -20
  11. package/esm/src/clients/info.d.ts.map +1 -1
  12. package/esm/src/clients/info.js +312 -73
  13. package/esm/src/clients/info.js.map +1 -0
  14. package/esm/src/clients/multiSign.d.ts +11 -7
  15. package/esm/src/clients/multiSign.d.ts.map +1 -1
  16. package/esm/src/clients/multiSign.js +2 -1
  17. package/esm/src/clients/multiSign.js.map +1 -0
  18. package/esm/src/clients/subscription.d.ts +9 -9
  19. package/esm/src/clients/subscription.d.ts.map +1 -1
  20. package/esm/src/clients/subscription.js +29 -27
  21. package/esm/src/clients/subscription.js.map +1 -0
  22. package/esm/src/{base.d.ts → errors.d.ts} +1 -1
  23. package/esm/src/errors.d.ts.map +1 -0
  24. package/esm/src/{base.js → errors.js} +1 -0
  25. package/esm/src/errors.js.map +1 -0
  26. package/esm/src/schemas/_base.d.ts +14 -0
  27. package/esm/src/schemas/_base.d.ts.map +1 -0
  28. package/esm/src/schemas/_base.js +15 -0
  29. package/esm/src/schemas/_base.js.map +1 -0
  30. package/esm/src/schemas/exchange/requests.d.ts +8953 -0
  31. package/esm/src/schemas/exchange/requests.d.ts.map +1 -0
  32. package/esm/src/schemas/exchange/requests.js +1414 -0
  33. package/esm/src/schemas/exchange/requests.js.map +1 -0
  34. package/esm/src/schemas/exchange/responses.d.ts +567 -0
  35. package/esm/src/schemas/exchange/responses.d.ts.map +1 -0
  36. package/esm/src/schemas/exchange/responses.js +244 -0
  37. package/esm/src/schemas/exchange/responses.js.map +1 -0
  38. package/esm/src/schemas/explorer/requests.d.ts +44 -0
  39. package/esm/src/schemas/explorer/requests.d.ts.map +1 -0
  40. package/esm/src/schemas/explorer/requests.js +33 -0
  41. package/esm/src/schemas/explorer/requests.js.map +1 -0
  42. package/esm/src/schemas/explorer/responses.d.ts +360 -0
  43. package/esm/src/schemas/explorer/responses.d.ts.map +1 -0
  44. package/esm/src/schemas/explorer/responses.js +57 -0
  45. package/esm/src/schemas/explorer/responses.js.map +1 -0
  46. package/esm/src/schemas/info/accounts.d.ts +2159 -0
  47. package/esm/src/schemas/info/accounts.d.ts.map +1 -0
  48. package/esm/src/schemas/info/accounts.js +623 -0
  49. package/esm/src/schemas/info/accounts.js.map +1 -0
  50. package/esm/src/schemas/info/assets.d.ts +974 -0
  51. package/esm/src/schemas/info/assets.d.ts.map +1 -0
  52. package/esm/src/schemas/info/assets.js +285 -0
  53. package/esm/src/schemas/info/assets.js.map +1 -0
  54. package/esm/src/schemas/info/markets.d.ts +155 -0
  55. package/esm/src/schemas/info/markets.d.ts.map +1 -0
  56. package/esm/src/schemas/info/markets.js +70 -0
  57. package/esm/src/schemas/info/markets.js.map +1 -0
  58. package/esm/src/schemas/info/orders.d.ts +957 -0
  59. package/esm/src/schemas/info/orders.d.ts.map +1 -0
  60. package/esm/src/schemas/info/orders.js +298 -0
  61. package/esm/src/schemas/info/orders.js.map +1 -0
  62. package/esm/src/schemas/info/requests.d.ts +924 -0
  63. package/esm/src/schemas/info/requests.d.ts.map +1 -0
  64. package/esm/src/schemas/info/requests.js +687 -0
  65. package/esm/src/schemas/info/requests.js.map +1 -0
  66. package/esm/src/schemas/info/validators.d.ts +326 -0
  67. package/esm/src/schemas/info/validators.d.ts.map +1 -0
  68. package/esm/src/schemas/info/validators.js +126 -0
  69. package/esm/src/schemas/info/validators.js.map +1 -0
  70. package/esm/src/schemas/info/vaults.d.ts +447 -0
  71. package/esm/src/schemas/info/vaults.d.ts.map +1 -0
  72. package/esm/src/schemas/info/vaults.js +111 -0
  73. package/esm/src/schemas/info/vaults.js.map +1 -0
  74. package/esm/src/schemas/mod.d.ts +101 -0
  75. package/esm/src/schemas/mod.d.ts.map +1 -0
  76. package/esm/src/schemas/mod.js +115 -0
  77. package/esm/src/schemas/mod.js.map +1 -0
  78. package/esm/src/schemas/subscriptions/requests.d.ts +332 -0
  79. package/esm/src/schemas/subscriptions/requests.d.ts.map +1 -0
  80. package/esm/src/schemas/subscriptions/requests.js +259 -0
  81. package/esm/src/schemas/subscriptions/requests.js.map +1 -0
  82. package/esm/src/schemas/subscriptions/responses.d.ts +3643 -0
  83. package/esm/src/schemas/subscriptions/responses.d.ts.map +1 -0
  84. package/esm/src/schemas/subscriptions/responses.js +234 -0
  85. package/esm/src/schemas/subscriptions/responses.js.map +1 -0
  86. package/esm/src/signing/_signTypedData/ethers.js +1 -0
  87. package/esm/src/signing/_signTypedData/ethers.js.map +1 -0
  88. package/esm/src/signing/_signTypedData/mod.js +1 -0
  89. package/esm/src/signing/_signTypedData/mod.js.map +1 -0
  90. package/esm/src/signing/_signTypedData/private_key.js +1 -0
  91. package/esm/src/signing/_signTypedData/private_key.js.map +1 -0
  92. package/esm/src/signing/_signTypedData/viem.js +1 -0
  93. package/esm/src/signing/_signTypedData/viem.js.map +1 -0
  94. package/esm/src/signing/mod.d.ts +109 -29
  95. package/esm/src/signing/mod.d.ts.map +1 -1
  96. package/esm/src/signing/mod.js +136 -29
  97. package/esm/src/signing/mod.js.map +1 -0
  98. package/esm/src/transports/base.d.ts +4 -4
  99. package/esm/src/transports/base.d.ts.map +1 -1
  100. package/esm/src/transports/base.js +3 -2
  101. package/esm/src/transports/base.js.map +1 -0
  102. package/esm/src/transports/http/http_transport.d.ts +3 -2
  103. package/esm/src/transports/http/http_transport.d.ts.map +1 -1
  104. package/esm/src/transports/http/http_transport.js +1 -0
  105. package/esm/src/transports/http/http_transport.js.map +1 -0
  106. package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts +1 -1
  107. package/esm/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
  108. package/esm/src/transports/websocket/_hyperliquid_event_target.js +1 -0
  109. package/esm/src/transports/websocket/_hyperliquid_event_target.js.map +1 -0
  110. package/esm/src/transports/websocket/_reconnecting_websocket.js +1 -0
  111. package/esm/src/transports/websocket/_reconnecting_websocket.js.map +1 -0
  112. package/esm/src/transports/websocket/_websocket_async_request.js +1 -0
  113. package/esm/src/transports/websocket/_websocket_async_request.js.map +1 -0
  114. package/esm/src/transports/websocket/websocket_transport.d.ts +9 -1
  115. package/esm/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  116. package/esm/src/transports/websocket/websocket_transport.js +4 -0
  117. package/esm/src/transports/websocket/websocket_transport.js.map +1 -0
  118. package/package.json +6 -5
  119. package/script/mod.d.ts +11 -11
  120. package/script/mod.d.ts.map +1 -1
  121. package/script/mod.js +2 -1
  122. package/script/mod.js.map +1 -0
  123. package/script/src/clients/exchange.d.ts +29 -25
  124. package/script/src/clients/exchange.d.ts.map +1 -1
  125. package/script/src/clients/exchange.js +60 -59
  126. package/script/src/clients/exchange.js.map +1 -0
  127. package/script/src/clients/info.d.ts +80 -20
  128. package/script/src/clients/info.d.ts.map +1 -1
  129. package/script/src/clients/info.js +312 -73
  130. package/script/src/clients/info.js.map +1 -0
  131. package/script/src/clients/multiSign.d.ts +11 -7
  132. package/script/src/clients/multiSign.d.ts.map +1 -1
  133. package/script/src/clients/multiSign.js +2 -1
  134. package/script/src/clients/multiSign.js.map +1 -0
  135. package/script/src/clients/subscription.d.ts +9 -9
  136. package/script/src/clients/subscription.d.ts.map +1 -1
  137. package/script/src/clients/subscription.js +29 -27
  138. package/script/src/clients/subscription.js.map +1 -0
  139. package/script/src/{base.d.ts → errors.d.ts} +1 -1
  140. package/script/src/errors.d.ts.map +1 -0
  141. package/script/src/{base.js → errors.js} +1 -0
  142. package/script/src/errors.js.map +1 -0
  143. package/script/src/schemas/_base.d.ts +14 -0
  144. package/script/src/schemas/_base.d.ts.map +1 -0
  145. package/script/src/schemas/_base.js +51 -0
  146. package/script/src/schemas/_base.js.map +1 -0
  147. package/script/src/schemas/exchange/requests.d.ts +8953 -0
  148. package/script/src/schemas/exchange/requests.d.ts.map +1 -0
  149. package/script/src/schemas/exchange/requests.js +1450 -0
  150. package/script/src/schemas/exchange/requests.js.map +1 -0
  151. package/script/src/schemas/exchange/responses.d.ts +567 -0
  152. package/script/src/schemas/exchange/responses.d.ts.map +1 -0
  153. package/script/src/schemas/exchange/responses.js +280 -0
  154. package/script/src/schemas/exchange/responses.js.map +1 -0
  155. package/script/src/schemas/explorer/requests.d.ts +44 -0
  156. package/script/src/schemas/explorer/requests.d.ts.map +1 -0
  157. package/script/src/schemas/explorer/requests.js +69 -0
  158. package/script/src/schemas/explorer/requests.js.map +1 -0
  159. package/script/src/schemas/explorer/responses.d.ts +360 -0
  160. package/script/src/schemas/explorer/responses.d.ts.map +1 -0
  161. package/script/src/schemas/explorer/responses.js +93 -0
  162. package/script/src/schemas/explorer/responses.js.map +1 -0
  163. package/script/src/schemas/info/accounts.d.ts +2159 -0
  164. package/script/src/schemas/info/accounts.d.ts.map +1 -0
  165. package/script/src/schemas/info/accounts.js +659 -0
  166. package/script/src/schemas/info/accounts.js.map +1 -0
  167. package/script/src/schemas/info/assets.d.ts +974 -0
  168. package/script/src/schemas/info/assets.d.ts.map +1 -0
  169. package/script/src/schemas/info/assets.js +321 -0
  170. package/script/src/schemas/info/assets.js.map +1 -0
  171. package/script/src/schemas/info/markets.d.ts +155 -0
  172. package/script/src/schemas/info/markets.d.ts.map +1 -0
  173. package/script/src/schemas/info/markets.js +106 -0
  174. package/script/src/schemas/info/markets.js.map +1 -0
  175. package/script/src/schemas/info/orders.d.ts +957 -0
  176. package/script/src/schemas/info/orders.d.ts.map +1 -0
  177. package/script/src/schemas/info/orders.js +334 -0
  178. package/script/src/schemas/info/orders.js.map +1 -0
  179. package/script/src/schemas/info/requests.d.ts +924 -0
  180. package/script/src/schemas/info/requests.d.ts.map +1 -0
  181. package/script/src/schemas/info/requests.js +724 -0
  182. package/script/src/schemas/info/requests.js.map +1 -0
  183. package/script/src/schemas/info/validators.d.ts +326 -0
  184. package/script/src/schemas/info/validators.d.ts.map +1 -0
  185. package/script/src/schemas/info/validators.js +162 -0
  186. package/script/src/schemas/info/validators.js.map +1 -0
  187. package/script/src/schemas/info/vaults.d.ts +447 -0
  188. package/script/src/schemas/info/vaults.d.ts.map +1 -0
  189. package/script/src/schemas/info/vaults.js +147 -0
  190. package/script/src/schemas/info/vaults.js.map +1 -0
  191. package/script/src/schemas/mod.d.ts +101 -0
  192. package/script/src/schemas/mod.d.ts.map +1 -0
  193. package/script/src/schemas/mod.js +157 -0
  194. package/script/src/schemas/mod.js.map +1 -0
  195. package/script/src/schemas/subscriptions/requests.d.ts +332 -0
  196. package/script/src/schemas/subscriptions/requests.d.ts.map +1 -0
  197. package/script/src/schemas/subscriptions/requests.js +295 -0
  198. package/script/src/schemas/subscriptions/requests.js.map +1 -0
  199. package/script/src/schemas/subscriptions/responses.d.ts +3643 -0
  200. package/script/src/schemas/subscriptions/responses.d.ts.map +1 -0
  201. package/script/src/schemas/subscriptions/responses.js +270 -0
  202. package/script/src/schemas/subscriptions/responses.js.map +1 -0
  203. package/script/src/signing/_signTypedData/ethers.js +1 -0
  204. package/script/src/signing/_signTypedData/ethers.js.map +1 -0
  205. package/script/src/signing/_signTypedData/mod.js +1 -0
  206. package/script/src/signing/_signTypedData/mod.js.map +1 -0
  207. package/script/src/signing/_signTypedData/private_key.js +1 -0
  208. package/script/src/signing/_signTypedData/private_key.js.map +1 -0
  209. package/script/src/signing/_signTypedData/viem.js +1 -0
  210. package/script/src/signing/_signTypedData/viem.js.map +1 -0
  211. package/script/src/signing/mod.d.ts +109 -29
  212. package/script/src/signing/mod.d.ts.map +1 -1
  213. package/script/src/signing/mod.js +138 -33
  214. package/script/src/signing/mod.js.map +1 -0
  215. package/script/src/transports/base.d.ts +4 -4
  216. package/script/src/transports/base.d.ts.map +1 -1
  217. package/script/src/transports/base.js +4 -3
  218. package/script/src/transports/base.js.map +1 -0
  219. package/script/src/transports/http/http_transport.d.ts +3 -2
  220. package/script/src/transports/http/http_transport.d.ts.map +1 -1
  221. package/script/src/transports/http/http_transport.js +1 -0
  222. package/script/src/transports/http/http_transport.js.map +1 -0
  223. package/script/src/transports/websocket/_hyperliquid_event_target.d.ts +1 -1
  224. package/script/src/transports/websocket/_hyperliquid_event_target.d.ts.map +1 -1
  225. package/script/src/transports/websocket/_hyperliquid_event_target.js +1 -0
  226. package/script/src/transports/websocket/_hyperliquid_event_target.js.map +1 -0
  227. package/script/src/transports/websocket/_reconnecting_websocket.js +1 -0
  228. package/script/src/transports/websocket/_reconnecting_websocket.js.map +1 -0
  229. package/script/src/transports/websocket/_websocket_async_request.js +1 -0
  230. package/script/src/transports/websocket/_websocket_async_request.js.map +1 -0
  231. package/script/src/transports/websocket/websocket_transport.d.ts +9 -1
  232. package/script/src/transports/websocket/websocket_transport.d.ts.map +1 -1
  233. package/script/src/transports/websocket/websocket_transport.js +4 -0
  234. package/script/src/transports/websocket/websocket_transport.js.map +1 -0
  235. package/src/mod.ts +28 -0
  236. package/src/src/clients/exchange.ts +2246 -0
  237. package/src/src/clients/info.ts +2076 -0
  238. package/src/src/clients/multiSign.ts +183 -0
  239. package/src/src/clients/subscription.ts +841 -0
  240. package/src/src/errors.ts +7 -0
  241. package/src/src/schemas/_base.ts +43 -0
  242. package/src/src/schemas/exchange/requests.ts +3057 -0
  243. package/src/src/schemas/exchange/responses.ts +540 -0
  244. package/src/src/schemas/explorer/requests.ts +65 -0
  245. package/src/src/schemas/explorer/responses.ts +138 -0
  246. package/src/src/schemas/info/accounts.ts +1490 -0
  247. package/src/src/schemas/info/assets.ts +693 -0
  248. package/src/src/schemas/info/markets.ts +171 -0
  249. package/src/src/schemas/info/orders.ts +597 -0
  250. package/src/src/schemas/info/requests.ts +1369 -0
  251. package/src/src/schemas/info/validators.ts +299 -0
  252. package/src/src/schemas/info/vaults.ts +262 -0
  253. package/src/src/schemas/mod.ts +121 -0
  254. package/src/src/schemas/subscriptions/requests.ts +504 -0
  255. package/src/src/schemas/subscriptions/responses.ts +576 -0
  256. package/src/src/signing/_signTypedData/ethers.ts +59 -0
  257. package/src/src/signing/_signTypedData/mod.ts +121 -0
  258. package/src/src/signing/_signTypedData/private_key.ts +229 -0
  259. package/src/src/signing/_signTypedData/viem.ts +55 -0
  260. package/src/src/signing/mod.ts +572 -0
  261. package/src/src/transports/base.ts +54 -0
  262. package/src/src/transports/http/http_transport.ts +208 -0
  263. package/src/src/transports/websocket/_hyperliquid_event_target.ts +118 -0
  264. package/src/src/transports/websocket/_reconnecting_websocket.ts +404 -0
  265. package/src/src/transports/websocket/_websocket_async_request.ts +229 -0
  266. package/src/src/transports/websocket/websocket_transport.ts +394 -0
  267. package/esm/src/base.d.ts.map +0 -1
  268. package/esm/src/signing/_sorter.d.ts +0 -127
  269. package/esm/src/signing/_sorter.d.ts.map +0 -1
  270. package/esm/src/signing/_sorter.js +0 -693
  271. package/esm/src/types/exchange/requests.d.ts +0 -1345
  272. package/esm/src/types/exchange/requests.d.ts.map +0 -1
  273. package/esm/src/types/exchange/requests.js +0 -1
  274. package/esm/src/types/exchange/responses.d.ts +0 -233
  275. package/esm/src/types/exchange/responses.d.ts.map +0 -1
  276. package/esm/src/types/exchange/responses.js +0 -1
  277. package/esm/src/types/explorer/requests.d.ts +0 -32
  278. package/esm/src/types/explorer/requests.d.ts.map +0 -1
  279. package/esm/src/types/explorer/requests.js +0 -1
  280. package/esm/src/types/explorer/responses.d.ts +0 -58
  281. package/esm/src/types/explorer/responses.d.ts.map +0 -1
  282. package/esm/src/types/explorer/responses.js +0 -1
  283. package/esm/src/types/info/accounts.d.ts +0 -864
  284. package/esm/src/types/info/accounts.d.ts.map +0 -1
  285. package/esm/src/types/info/accounts.js +0 -1
  286. package/esm/src/types/info/assets.d.ts +0 -354
  287. package/esm/src/types/info/assets.d.ts.map +0 -1
  288. package/esm/src/types/info/assets.js +0 -1
  289. package/esm/src/types/info/markets.d.ts +0 -79
  290. package/esm/src/types/info/markets.d.ts.map +0 -1
  291. package/esm/src/types/info/markets.js +0 -1
  292. package/esm/src/types/info/orders.d.ts +0 -266
  293. package/esm/src/types/info/orders.d.ts.map +0 -1
  294. package/esm/src/types/info/orders.js +0 -1
  295. package/esm/src/types/info/requests.d.ts +0 -640
  296. package/esm/src/types/info/requests.d.ts.map +0 -1
  297. package/esm/src/types/info/requests.js +0 -1
  298. package/esm/src/types/info/validators.d.ts +0 -147
  299. package/esm/src/types/info/validators.d.ts.map +0 -1
  300. package/esm/src/types/info/validators.js +0 -1
  301. package/esm/src/types/info/vaults.d.ts +0 -119
  302. package/esm/src/types/info/vaults.d.ts.map +0 -1
  303. package/esm/src/types/info/vaults.js +0 -1
  304. package/esm/src/types/mod.d.ts +0 -38
  305. package/esm/src/types/mod.d.ts.map +0 -1
  306. package/esm/src/types/mod.js +0 -24
  307. package/esm/src/types/subscriptions/requests.d.ts +0 -154
  308. package/esm/src/types/subscriptions/requests.d.ts.map +0 -1
  309. package/esm/src/types/subscriptions/requests.js +0 -1
  310. package/esm/src/types/subscriptions/responses.d.ts +0 -238
  311. package/esm/src/types/subscriptions/responses.d.ts.map +0 -1
  312. package/esm/src/types/subscriptions/responses.js +0 -1
  313. package/script/src/base.d.ts.map +0 -1
  314. package/script/src/signing/_sorter.d.ts +0 -127
  315. package/script/src/signing/_sorter.d.ts.map +0 -1
  316. package/script/src/signing/_sorter.js +0 -696
  317. package/script/src/types/exchange/requests.d.ts +0 -1345
  318. package/script/src/types/exchange/requests.d.ts.map +0 -1
  319. package/script/src/types/exchange/requests.js +0 -2
  320. package/script/src/types/exchange/responses.d.ts +0 -233
  321. package/script/src/types/exchange/responses.d.ts.map +0 -1
  322. package/script/src/types/exchange/responses.js +0 -2
  323. package/script/src/types/explorer/requests.d.ts +0 -32
  324. package/script/src/types/explorer/requests.d.ts.map +0 -1
  325. package/script/src/types/explorer/requests.js +0 -2
  326. package/script/src/types/explorer/responses.d.ts +0 -58
  327. package/script/src/types/explorer/responses.d.ts.map +0 -1
  328. package/script/src/types/explorer/responses.js +0 -2
  329. package/script/src/types/info/accounts.d.ts +0 -864
  330. package/script/src/types/info/accounts.d.ts.map +0 -1
  331. package/script/src/types/info/accounts.js +0 -2
  332. package/script/src/types/info/assets.d.ts +0 -354
  333. package/script/src/types/info/assets.d.ts.map +0 -1
  334. package/script/src/types/info/assets.js +0 -2
  335. package/script/src/types/info/markets.d.ts +0 -79
  336. package/script/src/types/info/markets.d.ts.map +0 -1
  337. package/script/src/types/info/markets.js +0 -2
  338. package/script/src/types/info/orders.d.ts +0 -266
  339. package/script/src/types/info/orders.d.ts.map +0 -1
  340. package/script/src/types/info/orders.js +0 -2
  341. package/script/src/types/info/requests.d.ts +0 -640
  342. package/script/src/types/info/requests.d.ts.map +0 -1
  343. package/script/src/types/info/requests.js +0 -2
  344. package/script/src/types/info/validators.d.ts +0 -147
  345. package/script/src/types/info/validators.d.ts.map +0 -1
  346. package/script/src/types/info/validators.js +0 -2
  347. package/script/src/types/info/vaults.d.ts +0 -119
  348. package/script/src/types/info/vaults.d.ts.map +0 -1
  349. package/script/src/types/info/vaults.js +0 -2
  350. package/script/src/types/mod.d.ts +0 -38
  351. package/script/src/types/mod.d.ts.map +0 -1
  352. package/script/src/types/mod.js +0 -25
  353. package/script/src/types/subscriptions/requests.d.ts +0 -154
  354. package/script/src/types/subscriptions/requests.d.ts.map +0 -1
  355. package/script/src/types/subscriptions/requests.js +0 -2
  356. package/script/src/types/subscriptions/responses.d.ts +0 -238
  357. package/script/src/types/subscriptions/responses.d.ts.map +0 -1
  358. package/script/src/types/subscriptions/responses.js +0 -2
@@ -0,0 +1,576 @@
1
+ import * as v from "valibot";
2
+ import { Hex, UnsignedDecimal, UnsignedInteger } from "../_base.js";
3
+ import {
4
+ FundingUpdate,
5
+ PerpsClearinghouseState,
6
+ SpotClearinghouseState,
7
+ UserFundingUpdate,
8
+ UserNonFundingLedgerUpdate,
9
+ } from "../info/accounts.js";
10
+ import { AllMids, PerpsAssetCtx, PerpsMeta, SpotAssetCtx } from "../info/assets.js";
11
+ import { BookLevel, Fill, FrontendOrder, TwapHistory, TwapSliceFill, TwapState } from "../info/orders.js";
12
+ import { BlockDetails } from "../explorer/responses.js";
13
+
14
+ /** Active perpetual asset context. */
15
+ export const WsActiveAssetCtx = v.pipe(
16
+ v.object({
17
+ /** Asset symbol (e.g., BTC). */
18
+ coin: v.pipe(
19
+ v.string(),
20
+ v.description("Asset symbol (e.g., BTC)."),
21
+ ),
22
+ /** Context information for the perpetual asset. */
23
+ ctx: v.pipe(
24
+ PerpsAssetCtx,
25
+ v.description("Context information for the perpetual asset."),
26
+ ),
27
+ }),
28
+ v.description("Active perpetual asset context."),
29
+ );
30
+ export type WsActiveAssetCtx = v.InferOutput<typeof WsActiveAssetCtx>;
31
+
32
+ /** Active spot asset context. */
33
+ export const WsActiveSpotAssetCtx = v.pipe(
34
+ v.object({
35
+ /** Asset symbol (e.g., BTC). */
36
+ coin: v.pipe(
37
+ v.string(),
38
+ v.description("Asset symbol (e.g., BTC)."),
39
+ ),
40
+ /** Context information for the spot asset. */
41
+ ctx: v.pipe(
42
+ SpotAssetCtx,
43
+ v.description("Context information for the spot asset."),
44
+ ),
45
+ }),
46
+ v.description("Active spot asset context."),
47
+ );
48
+ export type WsActiveSpotAssetCtx = v.InferOutput<typeof WsActiveSpotAssetCtx>;
49
+
50
+ /** Mid prices for all assets. */
51
+ export const WsAllMids = v.pipe(
52
+ v.object({
53
+ /** Mapping of coin symbols to mid prices. */
54
+ mids: v.pipe(
55
+ AllMids,
56
+ v.description("Mapping of coin symbols to mid prices."),
57
+ ),
58
+ }),
59
+ v.description("Mid prices for all assets."),
60
+ );
61
+ export type WsAllMids = v.InferOutput<typeof WsAllMids>;
62
+
63
+ /** Asset contexts for all perpetual assets on a specified DEX. */
64
+ export const WsAssetCtxs = v.pipe(
65
+ v.object({
66
+ /** DEX name (empty string for main dex). */
67
+ dex: v.pipe(
68
+ v.string(),
69
+ v.description("DEX name (empty string for main dex)."),
70
+ ),
71
+ /** Array of context information for each perpetual asset. */
72
+ ctxs: v.pipe(
73
+ v.array(PerpsAssetCtx),
74
+ v.description("Array of context information for each perpetual asset."),
75
+ ),
76
+ }),
77
+ v.description("Asset contexts for all perpetual assets on a specified DEX."),
78
+ );
79
+ export type WsAssetCtxs = v.InferOutput<typeof WsAssetCtxs>;
80
+
81
+ /** Best Bid and Offer. */
82
+ export const WsBbo = v.pipe(
83
+ v.object({
84
+ /** Asset symbol (e.g., BTC). */
85
+ coin: v.pipe(
86
+ v.string(),
87
+ v.description("Asset symbol (e.g., BTC)."),
88
+ ),
89
+ /** Time of the BBO update (in ms since epoch). */
90
+ time: v.pipe(
91
+ UnsignedInteger,
92
+ v.description("Time of the BBO update (in ms since epoch)."),
93
+ ),
94
+ /** Best bid and offer tuple [bid, offer], either can be undefined if unavailable. */
95
+ bbo: v.pipe(
96
+ v.tuple([
97
+ v.union([BookLevel, v.undefined()]),
98
+ v.union([BookLevel, v.undefined()]),
99
+ ]),
100
+ v.description("Best bid and offer tuple [bid, offer], either can be undefined if unavailable."),
101
+ ),
102
+ }),
103
+ v.description("Best Bid and Offer."),
104
+ );
105
+ export type WsBbo = v.InferOutput<typeof WsBbo>;
106
+
107
+ /** Block details. */
108
+ export const WsBlockDetails = v.pipe(
109
+ v.omit(v.object(BlockDetails.entries), ["txs"]),
110
+ v.description("Block details."),
111
+ );
112
+ export type WsBlockDetails = v.InferOutput<typeof WsBlockDetails>;
113
+
114
+ /** Clearinghouse state for a specific user. */
115
+ export const WsClearinghouseState = v.pipe(
116
+ v.object({
117
+ /** DEX name (empty string for main dex). */
118
+ dex: v.pipe(
119
+ v.string(),
120
+ v.description("DEX name (empty string for main dex)."),
121
+ ),
122
+ /** User address. */
123
+ user: v.pipe(
124
+ v.pipe(Hex, v.length(42)),
125
+ v.description("User address."),
126
+ ),
127
+ /** Perpetual clearinghouse state. */
128
+ clearinghouseState: v.pipe(
129
+ PerpsClearinghouseState,
130
+ v.description("Perpetual clearinghouse state."),
131
+ ),
132
+ }),
133
+ v.description("Clearinghouse state for a specific user."),
134
+ );
135
+ export type WsClearinghouseState = v.InferOutput<typeof WsClearinghouseState>;
136
+
137
+ /** User notifications. */
138
+ export const WsNotification = v.pipe(
139
+ v.object({
140
+ /** Notification content. */
141
+ notification: v.pipe(
142
+ v.string(),
143
+ v.description("Notification content."),
144
+ ),
145
+ }),
146
+ v.description("User notifications."),
147
+ );
148
+ export type WsNotification = v.InferOutput<typeof WsNotification>;
149
+
150
+ /** Open orders for a specific user. */
151
+ export const WsOpenOrders = v.pipe(
152
+ v.object({
153
+ /** DEX name (empty string for main dex). */
154
+ dex: v.pipe(
155
+ v.string(),
156
+ v.description("DEX name (empty string for main dex)."),
157
+ ),
158
+ /** User address. */
159
+ user: v.pipe(
160
+ v.pipe(Hex, v.length(42)),
161
+ v.description("User address."),
162
+ ),
163
+ /** Array of open orders. */
164
+ orders: v.pipe(
165
+ v.array(FrontendOrder),
166
+ v.description("Array of open orders."),
167
+ ),
168
+ }),
169
+ v.description("Open orders for a specific user."),
170
+ );
171
+ export type WsOpenOrders = v.InferOutput<typeof WsOpenOrders>;
172
+
173
+ /** Trade information. */
174
+ export const WsTrade = v.pipe(
175
+ v.object({
176
+ /** Asset symbol (e.g., BTC). */
177
+ coin: v.pipe(
178
+ v.string(),
179
+ v.description("Asset symbol (e.g., BTC)."),
180
+ ),
181
+ /** Trade side ("B" = Bid/Buy, "A" = Ask/Sell). */
182
+ side: v.pipe(
183
+ v.union([v.literal("B"), v.literal("A")]),
184
+ v.description('Trade side ("B" = Bid/Buy, "A" = Ask/Sell).'),
185
+ ),
186
+ /** Trade price. */
187
+ px: v.pipe(
188
+ UnsignedDecimal,
189
+ v.description("Trade price."),
190
+ ),
191
+ /** Trade size. */
192
+ sz: v.pipe(
193
+ UnsignedDecimal,
194
+ v.description("Trade size."),
195
+ ),
196
+ /** Trade timestamp (in ms since epoch). */
197
+ time: v.pipe(
198
+ UnsignedInteger,
199
+ v.description("Trade timestamp (in ms since epoch)."),
200
+ ),
201
+ /** Transaction hash. */
202
+ hash: v.pipe(
203
+ v.pipe(Hex, v.length(66)),
204
+ v.description("Transaction hash."),
205
+ ),
206
+ /** Trade ID. */
207
+ tid: v.pipe(
208
+ UnsignedInteger,
209
+ v.description("Trade ID."),
210
+ ),
211
+ /** Addresses of users involved in the trade [Maker, Taker]. */
212
+ users: v.pipe(
213
+ v.tuple([v.pipe(Hex, v.length(42)), v.pipe(Hex, v.length(42))]),
214
+ v.description("Addresses of users involved in the trade [Maker, Taker]."),
215
+ ),
216
+ }),
217
+ v.description("Trade information."),
218
+ );
219
+ export type WsTrade = v.InferOutput<typeof WsTrade>;
220
+
221
+ /** User fill event. */
222
+ export const WsUserEventFill = v.pipe(
223
+ v.object({
224
+ /** Array of trade fills. */
225
+ fills: v.pipe(
226
+ v.array(Fill),
227
+ v.description("Array of trade fills."),
228
+ ),
229
+ }),
230
+ v.description("User fill event."),
231
+ );
232
+ export type WsUserEventFill = v.InferOutput<typeof WsUserEventFill>;
233
+
234
+ /** User funding event. */
235
+ export const WsUserEventFunding = v.pipe(
236
+ v.object({
237
+ /** Funding update details. */
238
+ funding: v.pipe(
239
+ v.omit(v.object(FundingUpdate.entries), ["type"]),
240
+ v.description("Funding update details."),
241
+ ),
242
+ }),
243
+ v.description("User funding event."),
244
+ );
245
+ export type WsUserEventFunding = v.InferOutput<typeof WsUserEventFunding>;
246
+
247
+ /** User liquidation event. */
248
+ export const WsUserEventLiquidation = v.pipe(
249
+ v.object({
250
+ /** Liquidation event details. */
251
+ liquidation: v.pipe(
252
+ v.object({
253
+ /** Unique liquidation ID. */
254
+ lid: v.pipe(
255
+ UnsignedInteger,
256
+ v.description("Unique liquidation ID."),
257
+ ),
258
+ /** Address of the liquidator. */
259
+ liquidator: v.pipe(
260
+ v.pipe(Hex, v.length(42)),
261
+ v.description("Address of the liquidator."),
262
+ ),
263
+ /** Address of the liquidated user. */
264
+ liquidated_user: v.pipe(
265
+ v.pipe(Hex, v.length(42)),
266
+ v.description("Address of the liquidated user."),
267
+ ),
268
+ /** Notional position size that was liquidated. */
269
+ liquidated_ntl_pos: v.pipe(
270
+ UnsignedDecimal,
271
+ v.description("Notional position size that was liquidated."),
272
+ ),
273
+ /** Account value at time of liquidation. */
274
+ liquidated_account_value: v.pipe(
275
+ UnsignedDecimal,
276
+ v.description("Account value at time of liquidation."),
277
+ ),
278
+ }),
279
+ v.description("Liquidation event details."),
280
+ ),
281
+ }),
282
+ v.description("User liquidation event."),
283
+ );
284
+ export type WsUserEventLiquidation = v.InferOutput<typeof WsUserEventLiquidation>;
285
+
286
+ /** Non-user initiated order cancellation event. */
287
+ export const WsUserEventNonUserCancel = v.pipe(
288
+ v.object({
289
+ /** Array of cancelled orders not initiated by the user. */
290
+ nonUserCancel: v.pipe(
291
+ v.array(
292
+ v.object({
293
+ /** Asset symbol (e.g., BTC). */
294
+ coin: v.pipe(
295
+ v.string(),
296
+ v.description("Asset symbol (e.g., BTC)."),
297
+ ),
298
+ /** Order ID. */
299
+ oid: v.pipe(
300
+ UnsignedInteger,
301
+ v.description("Order ID."),
302
+ ),
303
+ }),
304
+ ),
305
+ v.description("Array of cancelled orders not initiated by the user."),
306
+ ),
307
+ }),
308
+ v.description("Non-user initiated order cancellation event."),
309
+ );
310
+ export type WsUserEventNonUserCancel = v.InferOutput<typeof WsUserEventNonUserCancel>;
311
+
312
+ /** User TWAP history event. */
313
+ export const WsUserEventTwapHistory = v.pipe(
314
+ v.object({
315
+ /** Array of historical TWAP fills. */
316
+ twapHistory: v.pipe(
317
+ v.array(TwapHistory),
318
+ v.description("Array of historical TWAP fills."),
319
+ ),
320
+ }),
321
+ v.description("User TWAP history event."),
322
+ );
323
+ export type WsUserEventTwapHistory = v.InferOutput<typeof WsUserEventTwapHistory>;
324
+
325
+ /** User TWAP slice fills event. */
326
+ export const WsUserEventTwapSliceFills = v.pipe(
327
+ v.object({
328
+ /** Array of TWAP slice fills. */
329
+ twapSliceFills: v.pipe(
330
+ v.array(TwapSliceFill),
331
+ v.description("Array of TWAP slice fills."),
332
+ ),
333
+ }),
334
+ v.description("User TWAP slice fills event."),
335
+ );
336
+ export type WsUserEventTwapSliceFills = v.InferOutput<typeof WsUserEventTwapSliceFills>;
337
+
338
+ /** User event. */
339
+ export const WsUserEvent = v.pipe(
340
+ v.union([
341
+ WsUserEventFill,
342
+ WsUserEventFunding,
343
+ WsUserEventLiquidation,
344
+ WsUserEventNonUserCancel,
345
+ WsUserEventTwapHistory,
346
+ WsUserEventTwapSliceFills,
347
+ ]),
348
+ v.description("User event."),
349
+ );
350
+ export type WsUserEvent = v.InferOutput<typeof WsUserEvent>;
351
+
352
+ /** User fills. */
353
+ export const WsUserFills = v.pipe(
354
+ v.object({
355
+ /** User address. */
356
+ user: v.pipe(
357
+ v.pipe(Hex, v.length(42)),
358
+ v.description("User address."),
359
+ ),
360
+ /** Array of fill events. */
361
+ fills: v.pipe(
362
+ v.array(Fill),
363
+ v.description("Array of fill events."),
364
+ ),
365
+ /** Whether this is an initial snapshot. */
366
+ isSnapshot: v.pipe(
367
+ v.optional(v.literal(true)),
368
+ v.description("Whether this is an initial snapshot."),
369
+ ),
370
+ }),
371
+ v.description("User fills."),
372
+ );
373
+ export type WsUserFills = v.InferOutput<typeof WsUserFills>;
374
+
375
+ /** User fundings. */
376
+ export const WsUserFundings = v.pipe(
377
+ v.object({
378
+ /** User address. */
379
+ user: v.pipe(
380
+ v.pipe(Hex, v.length(42)),
381
+ v.description("User address."),
382
+ ),
383
+ /** Array of funding events. */
384
+ fundings: v.pipe(
385
+ v.array(
386
+ v.object({
387
+ ...v.omit(v.object(FundingUpdate.entries), ["type"]).entries,
388
+ ...v.pick(v.object(UserFundingUpdate.entries), ["time"]).entries,
389
+ }),
390
+ ),
391
+ v.description("Array of funding events."),
392
+ ),
393
+ /** Whether this is an initial snapshot. */
394
+ isSnapshot: v.pipe(
395
+ v.optional(v.literal(true)),
396
+ v.description("Whether this is an initial snapshot."),
397
+ ),
398
+ }),
399
+ v.description("User fundings."),
400
+ );
401
+ export type WsUserFundings = v.InferOutput<typeof WsUserFundings>;
402
+
403
+ /** User non-funding ledger updates. */
404
+ export const WsUserNonFundingLedgerUpdates = v.pipe(
405
+ v.object({
406
+ /** User address. */
407
+ user: v.pipe(
408
+ v.pipe(Hex, v.length(42)),
409
+ v.description("User address."),
410
+ ),
411
+ /** Array of non-funding ledger updates. */
412
+ nonFundingLedgerUpdates: v.pipe(
413
+ v.array(UserNonFundingLedgerUpdate),
414
+ v.description("Array of non-funding ledger updates."),
415
+ ),
416
+ /** Whether this is an initial snapshot. */
417
+ isSnapshot: v.pipe(
418
+ v.optional(v.literal(true)),
419
+ v.description("Whether this is an initial snapshot."),
420
+ ),
421
+ }),
422
+ v.description("User non-funding ledger updates."),
423
+ );
424
+ export type WsUserNonFundingLedgerUpdates = v.InferOutput<typeof WsUserNonFundingLedgerUpdates>;
425
+
426
+ /** User TWAP history. */
427
+ export const WsUserTwapHistory = v.pipe(
428
+ v.object({
429
+ /** User address. */
430
+ user: v.pipe(
431
+ v.pipe(Hex, v.length(42)),
432
+ v.description("User address."),
433
+ ),
434
+ /** Array of historical TWAP fills. */
435
+ history: v.pipe(
436
+ v.array(TwapHistory),
437
+ v.description("Array of historical TWAP fills."),
438
+ ),
439
+ /** Whether this is an initial snapshot. */
440
+ isSnapshot: v.pipe(
441
+ v.optional(v.literal(true)),
442
+ v.description("Whether this is an initial snapshot."),
443
+ ),
444
+ }),
445
+ v.description("User TWAP history."),
446
+ );
447
+ export type WsUserTwapHistory = v.InferOutput<typeof WsUserTwapHistory>;
448
+
449
+ /** User TWAP slice fills. */
450
+ export const WsUserTwapSliceFills = v.pipe(
451
+ v.object({
452
+ /** User address. */
453
+ user: v.pipe(
454
+ v.pipe(Hex, v.length(42)),
455
+ v.description("User address."),
456
+ ),
457
+ /** Array of TWAP slice fills. */
458
+ twapSliceFills: v.pipe(
459
+ v.array(TwapSliceFill),
460
+ v.description("Array of TWAP slice fills."),
461
+ ),
462
+ /** Whether this is an initial snapshot. */
463
+ isSnapshot: v.pipe(
464
+ v.optional(v.literal(true)),
465
+ v.description("Whether this is an initial snapshot."),
466
+ ),
467
+ }),
468
+ v.description("User TWAP slice fills."),
469
+ );
470
+ export type WsUserTwapSliceFills = v.InferOutput<typeof WsUserTwapSliceFills>;
471
+
472
+ /** Comprehensive user and market data. */
473
+ export const WsWebData2 = v.pipe(
474
+ v.object({
475
+ /** Account summary for perpetual trading. */
476
+ clearinghouseState: v.pipe(
477
+ PerpsClearinghouseState,
478
+ v.description("Account summary for perpetual trading."),
479
+ ),
480
+ /** Leading vaults information. */
481
+ leadingVaults: v.pipe(
482
+ v.array(
483
+ v.object({
484
+ /** Address of the vault. */
485
+ address: v.pipe(
486
+ v.pipe(Hex, v.length(42)),
487
+ v.description("Address of the vault."),
488
+ ),
489
+ /** Name of the vault. */
490
+ name: v.pipe(
491
+ v.string(),
492
+ v.description("Name of the vault."),
493
+ ),
494
+ }),
495
+ ),
496
+ v.description("Leading vaults information."),
497
+ ),
498
+ /** Total equity in vaults. */
499
+ totalVaultEquity: v.pipe(
500
+ UnsignedDecimal,
501
+ v.description("Total equity in vaults."),
502
+ ),
503
+ /** User open orders with frontend information. */
504
+ openOrders: v.pipe(
505
+ v.array(FrontendOrder),
506
+ v.description("User open orders with frontend information."),
507
+ ),
508
+ /** Agent address if one exists. */
509
+ agentAddress: v.pipe(
510
+ v.union([v.pipe(Hex, v.length(42)), v.null()]),
511
+ v.description("Agent address if one exists."),
512
+ ),
513
+ /** Timestamp until which the agent is valid. */
514
+ agentValidUntil: v.pipe(
515
+ v.union([UnsignedInteger, v.null()]),
516
+ v.description("Timestamp until which the agent is valid."),
517
+ ),
518
+ /** Cumulative ledger value. */
519
+ cumLedger: v.pipe(
520
+ UnsignedDecimal,
521
+ v.description("Cumulative ledger value."),
522
+ ),
523
+ /** Metadata for perpetual assets. */
524
+ meta: v.pipe(
525
+ PerpsMeta,
526
+ v.description("Metadata for perpetual assets."),
527
+ ),
528
+ /** Context information for perpetual assets. */
529
+ assetCtxs: v.pipe(
530
+ v.array(PerpsAssetCtx),
531
+ v.description("Context information for perpetual assets."),
532
+ ),
533
+ /** Server timestamp (in ms since epoch). */
534
+ serverTime: v.pipe(
535
+ UnsignedInteger,
536
+ v.description("Server timestamp (in ms since epoch)."),
537
+ ),
538
+ /** Whether this account is a vault. */
539
+ isVault: v.pipe(
540
+ v.boolean(),
541
+ v.description("Whether this account is a vault."),
542
+ ),
543
+ /** User address. */
544
+ user: v.pipe(
545
+ v.pipe(Hex, v.length(42)),
546
+ v.description("User address."),
547
+ ),
548
+ /** TWAP states. */
549
+ twapStates: v.pipe(
550
+ v.array(v.tuple([UnsignedInteger, TwapState])),
551
+ v.description("TWAP states."),
552
+ ),
553
+ /** Account summary for spot trading. */
554
+ spotState: v.pipe(
555
+ v.optional(SpotClearinghouseState),
556
+ v.description("Account summary for spot trading."),
557
+ ),
558
+ /** Context information for spot assets. */
559
+ spotAssetCtxs: v.pipe(
560
+ v.array(SpotAssetCtx),
561
+ v.description("Context information for spot assets."),
562
+ ),
563
+ /** Whether the user has opted out of spot dusting. */
564
+ optOutOfSpotDusting: v.pipe(
565
+ v.optional(v.literal(true)),
566
+ v.description("Whether the user has opted out of spot dusting."),
567
+ ),
568
+ /** Assets currently at their open interest cap. */
569
+ perpsAtOpenInterestCap: v.pipe(
570
+ v.optional(v.array(v.string())),
571
+ v.description("Assets currently at their open interest cap."),
572
+ ),
573
+ }),
574
+ v.description("Comprehensive user and market data."),
575
+ );
576
+ export type WsWebData2 = v.InferOutput<typeof WsWebData2>;
@@ -0,0 +1,59 @@
1
+ /** Abstract interface for an {@link https://docs.ethers.org/v6/api/providers/#Signer | ethers.js signer}. */
2
+ export interface AbstractEthersV6Signer {
3
+ signTypedData(
4
+ domain: {
5
+ name: string;
6
+ version: string;
7
+ chainId: number;
8
+ verifyingContract: string;
9
+ },
10
+ types: {
11
+ [key: string]: {
12
+ name: string;
13
+ type: string;
14
+ }[];
15
+ },
16
+ value: Record<string, unknown>,
17
+ ): Promise<string>;
18
+ getAddress?(): Promise<string>;
19
+ provider?:
20
+ | { getNetwork(): Promise<{ chainId: number | bigint }> }
21
+ | null;
22
+ }
23
+
24
+ /** Abstract interface for an {@link https://docs.ethers.org/v5/api/signer/ | ethers.js v5 signer}. */
25
+ export interface AbstractEthersV5Signer {
26
+ _signTypedData(
27
+ domain: {
28
+ name: string;
29
+ version: string;
30
+ chainId: number;
31
+ verifyingContract: string;
32
+ },
33
+ types: {
34
+ [key: string]: {
35
+ name: string;
36
+ type: string;
37
+ }[];
38
+ },
39
+ value: Record<string, unknown>,
40
+ ): Promise<string>;
41
+ getAddress?(): Promise<string>;
42
+ provider?:
43
+ | { getNetwork(): Promise<{ chainId: number | bigint }> }
44
+ | null;
45
+ }
46
+
47
+ /** Checks if the given value is an abstract ethers signer. */
48
+ export function isAbstractEthersV6Signer(client: unknown): client is AbstractEthersV6Signer {
49
+ return typeof client === "object" && client !== null &&
50
+ "signTypedData" in client && typeof client.signTypedData === "function" &&
51
+ client.signTypedData.length === 3;
52
+ }
53
+
54
+ /** Checks if the given value is an abstract ethers v5 signer. */
55
+ export function isAbstractEthersV5Signer(client: unknown): client is AbstractEthersV5Signer {
56
+ return typeof client === "object" && client !== null &&
57
+ "_signTypedData" in client && typeof client._signTypedData === "function" &&
58
+ client._signTypedData.length === 3;
59
+ }