@metamask-previews/perps-controller 16.1.0-preview-abca9bcea → 17.0.0-preview-0a30e47

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 (891) hide show
  1. package/CHANGELOG.md +35 -1
  2. package/README.md +17 -0
  3. package/dist/PerpsController-method-action-types.d.ts +1235 -0
  4. package/dist/PerpsController-method-action-types.d.ts.map +1 -0
  5. package/dist/PerpsController-method-action-types.js +6 -0
  6. package/dist/PerpsController-method-action-types.js.map +1 -0
  7. package/dist/PerpsController.d.ts +1313 -0
  8. package/dist/PerpsController.d.ts.map +1 -0
  9. package/dist/PerpsController.js +5331 -0
  10. package/dist/PerpsController.js.map +1 -0
  11. package/dist/aggregation/SubscriptionMultiplexer.d.ts +171 -0
  12. package/dist/aggregation/SubscriptionMultiplexer.d.ts.map +1 -0
  13. package/dist/aggregation/SubscriptionMultiplexer.js +451 -0
  14. package/dist/aggregation/SubscriptionMultiplexer.js.map +1 -0
  15. package/dist/aggregation/index.d.ts +6 -0
  16. package/dist/aggregation/index.d.ts.map +1 -0
  17. package/dist/aggregation/index.js +5 -0
  18. package/dist/aggregation/index.js.map +1 -0
  19. package/dist/constants/chartConfig.d.ts +228 -0
  20. package/dist/constants/chartConfig.d.ts.map +1 -0
  21. package/dist/constants/chartConfig.js +233 -0
  22. package/dist/constants/chartConfig.js.map +1 -0
  23. package/dist/constants/eventNames.d.ts +565 -0
  24. package/dist/constants/eventNames.d.ts.map +1 -0
  25. package/dist/constants/eventNames.js +657 -0
  26. package/dist/constants/eventNames.js.map +1 -0
  27. package/dist/constants/hyperLiquidConfig.d.ts +280 -0
  28. package/dist/constants/hyperLiquidConfig.d.ts.map +1 -0
  29. package/dist/constants/hyperLiquidConfig.js +596 -0
  30. package/dist/constants/hyperLiquidConfig.js.map +1 -0
  31. package/dist/constants/index.d.ts +12 -0
  32. package/dist/constants/index.d.ts.map +1 -0
  33. package/dist/constants/index.js +12 -0
  34. package/dist/constants/index.js.map +1 -0
  35. package/dist/constants/lighterConfig.d.ts +204 -0
  36. package/dist/constants/lighterConfig.d.ts.map +1 -0
  37. package/dist/constants/lighterConfig.js +317 -0
  38. package/dist/constants/lighterConfig.js.map +1 -0
  39. package/dist/constants/orderTypes.d.ts +19 -0
  40. package/dist/constants/orderTypes.d.ts.map +1 -0
  41. package/dist/constants/orderTypes.js +27 -0
  42. package/dist/constants/orderTypes.js.map +1 -0
  43. package/dist/constants/performanceMetrics.d.ts +46 -0
  44. package/dist/constants/performanceMetrics.d.ts.map +1 -0
  45. package/dist/constants/performanceMetrics.js +60 -0
  46. package/dist/constants/performanceMetrics.js.map +1 -0
  47. package/dist/constants/perpsConfig.d.ts +480 -0
  48. package/dist/constants/perpsConfig.d.ts.map +1 -0
  49. package/dist/constants/perpsConfig.js +555 -0
  50. package/dist/constants/perpsConfig.js.map +1 -0
  51. package/dist/constants/transactionsHistoryConfig.d.ts +35 -0
  52. package/dist/constants/transactionsHistoryConfig.d.ts.map +1 -0
  53. package/dist/constants/transactionsHistoryConfig.js +35 -0
  54. package/dist/constants/transactionsHistoryConfig.js.map +1 -0
  55. package/dist/index.d.ts +95 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +80 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/perpsErrorCodes.d.ts +113 -0
  60. package/dist/perpsErrorCodes.d.ts.map +1 -0
  61. package/dist/perpsErrorCodes.js +133 -0
  62. package/dist/perpsErrorCodes.js.map +1 -0
  63. package/dist/providers/AggregatedPerpsProvider.d.ts +277 -0
  64. package/dist/providers/AggregatedPerpsProvider.d.ts.map +1 -0
  65. package/dist/providers/AggregatedPerpsProvider.js +827 -0
  66. package/dist/providers/AggregatedPerpsProvider.js.map +1 -0
  67. package/dist/providers/HyperLiquidProvider.d.ts +656 -0
  68. package/dist/providers/HyperLiquidProvider.d.ts.map +1 -0
  69. package/dist/providers/HyperLiquidProvider.js +11308 -0
  70. package/dist/providers/HyperLiquidProvider.js.map +1 -0
  71. package/dist/providers/LighterProvider.d.ts +179 -0
  72. package/dist/providers/LighterProvider.d.ts.map +1 -0
  73. package/dist/providers/LighterProvider.js +6599 -0
  74. package/dist/providers/LighterProvider.js.map +1 -0
  75. package/dist/routing/ProviderRouter.d.ts +112 -0
  76. package/dist/routing/ProviderRouter.d.ts.map +1 -0
  77. package/dist/routing/ProviderRouter.js +137 -0
  78. package/dist/routing/ProviderRouter.js.map +1 -0
  79. package/dist/routing/index.d.ts +6 -0
  80. package/dist/routing/index.d.ts.map +1 -0
  81. package/dist/routing/index.js +5 -0
  82. package/dist/routing/index.js.map +1 -0
  83. package/dist/selectors.d.ts +336 -0
  84. package/dist/selectors.d.ts.map +1 -0
  85. package/dist/selectors.js +249 -0
  86. package/dist/selectors.js.map +1 -0
  87. package/dist/services/AccountService.d.ts +56 -0
  88. package/dist/services/AccountService.d.ts.map +1 -0
  89. package/dist/services/AccountService.js +307 -0
  90. package/dist/services/AccountService.js.map +1 -0
  91. package/dist/services/AggregatedOrderBookConnection.d.ts +106 -0
  92. package/dist/services/AggregatedOrderBookConnection.d.ts.map +1 -0
  93. package/dist/services/AggregatedOrderBookConnection.js +388 -0
  94. package/dist/services/AggregatedOrderBookConnection.js.map +1 -0
  95. package/dist/services/DataLakeService.d.ts +51 -0
  96. package/dist/services/DataLakeService.d.ts.map +1 -0
  97. package/dist/services/DataLakeService.js +215 -0
  98. package/dist/services/DataLakeService.js.map +1 -0
  99. package/dist/services/DepositService.d.ts +39 -0
  100. package/dist/services/DepositService.d.ts.map +1 -0
  101. package/dist/services/DepositService.js +88 -0
  102. package/dist/services/DepositService.js.map +1 -0
  103. package/dist/services/DexDiscoveryCacheManager.d.ts +52 -0
  104. package/dist/services/DexDiscoveryCacheManager.d.ts.map +1 -0
  105. package/dist/services/DexDiscoveryCacheManager.js +130 -0
  106. package/dist/services/DexDiscoveryCacheManager.js.map +1 -0
  107. package/dist/services/EligibilityService.d.ts +28 -0
  108. package/dist/services/EligibilityService.d.ts.map +1 -0
  109. package/dist/services/EligibilityService.js +61 -0
  110. package/dist/services/EligibilityService.js.map +1 -0
  111. package/dist/services/FeatureFlagConfigurationService.d.ts +73 -0
  112. package/dist/services/FeatureFlagConfigurationService.d.ts.map +1 -0
  113. package/dist/services/FeatureFlagConfigurationService.js +266 -0
  114. package/dist/services/FeatureFlagConfigurationService.js.map +1 -0
  115. package/dist/services/HyperLiquidClientService.d.ts +252 -0
  116. package/dist/services/HyperLiquidClientService.d.ts.map +1 -0
  117. package/dist/services/HyperLiquidClientService.js +1152 -0
  118. package/dist/services/HyperLiquidClientService.js.map +1 -0
  119. package/dist/services/HyperLiquidSubscriptionService.d.ts +265 -0
  120. package/dist/services/HyperLiquidSubscriptionService.d.ts.map +1 -0
  121. package/dist/services/HyperLiquidSubscriptionService.js +3874 -0
  122. package/dist/services/HyperLiquidSubscriptionService.js.map +1 -0
  123. package/dist/services/HyperLiquidWalletService.d.ts +84 -0
  124. package/dist/services/HyperLiquidWalletService.d.ts.map +1 -0
  125. package/dist/services/HyperLiquidWalletService.js +168 -0
  126. package/dist/services/HyperLiquidWalletService.js.map +1 -0
  127. package/dist/services/LighterClientService.d.ts +200 -0
  128. package/dist/services/LighterClientService.d.ts.map +1 -0
  129. package/dist/services/LighterClientService.js +634 -0
  130. package/dist/services/LighterClientService.js.map +1 -0
  131. package/dist/services/LighterWalletService.d.ts +51 -0
  132. package/dist/services/LighterWalletService.d.ts.map +1 -0
  133. package/dist/services/LighterWalletService.js +92 -0
  134. package/dist/services/LighterWalletService.js.map +1 -0
  135. package/dist/services/MarketDataService.d.ts +350 -0
  136. package/dist/services/MarketDataService.d.ts.map +1 -0
  137. package/dist/services/MarketDataService.js +1165 -0
  138. package/dist/services/MarketDataService.js.map +1 -0
  139. package/dist/services/RewardsIntegrationService.d.ts +84 -0
  140. package/dist/services/RewardsIntegrationService.d.ts.map +1 -0
  141. package/dist/services/RewardsIntegrationService.js +380 -0
  142. package/dist/services/RewardsIntegrationService.js.map +1 -0
  143. package/dist/services/ServiceContext.d.ts +102 -0
  144. package/dist/services/ServiceContext.d.ts.map +1 -0
  145. package/dist/services/ServiceContext.js +2 -0
  146. package/dist/services/ServiceContext.js.map +1 -0
  147. package/dist/services/TerminalMarketService.d.ts +45 -0
  148. package/dist/services/TerminalMarketService.d.ts.map +1 -0
  149. package/dist/services/TerminalMarketService.js +640 -0
  150. package/dist/services/TerminalMarketService.js.map +1 -0
  151. package/dist/services/TradingReadinessCache.d.ts +204 -0
  152. package/dist/services/TradingReadinessCache.d.ts.map +1 -0
  153. package/dist/services/TradingReadinessCache.js +313 -0
  154. package/dist/services/TradingReadinessCache.js.map +1 -0
  155. package/dist/services/TradingService.d.ts +201 -0
  156. package/dist/services/TradingService.d.ts.map +1 -0
  157. package/dist/services/TradingService.js +1967 -0
  158. package/dist/services/TradingService.js.map +1 -0
  159. package/dist/types/config.d.ts +49 -0
  160. package/dist/types/config.d.ts.map +1 -0
  161. package/dist/types/config.js +2 -0
  162. package/dist/types/config.js.map +1 -0
  163. package/dist/types/hyperliquid-types.d.ts +67 -0
  164. package/dist/types/hyperliquid-types.d.ts.map +1 -0
  165. package/dist/types/hyperliquid-types.js +41 -0
  166. package/dist/types/hyperliquid-types.js.map +1 -0
  167. package/dist/types/index.d.ts +2192 -0
  168. package/dist/types/index.d.ts.map +1 -0
  169. package/dist/types/index.js +133 -0
  170. package/dist/types/index.js.map +1 -0
  171. package/dist/types/lighter-types.d.ts +772 -0
  172. package/dist/types/lighter-types.d.ts.map +1 -0
  173. package/dist/types/lighter-types.js +10 -0
  174. package/dist/types/lighter-types.js.map +1 -0
  175. package/dist/types/messenger.d.ts +30 -0
  176. package/dist/types/messenger.d.ts.map +1 -0
  177. package/dist/types/messenger.js +2 -0
  178. package/dist/types/messenger.js.map +1 -0
  179. package/dist/types/perps-types.d.ts +184 -0
  180. package/dist/types/perps-types.d.ts.map +1 -0
  181. package/dist/types/perps-types.js +2 -0
  182. package/dist/types/perps-types.js.map +1 -0
  183. package/dist/types/token.d.ts +25 -0
  184. package/dist/types/token.d.ts.map +1 -0
  185. package/dist/types/token.js +2 -0
  186. package/dist/types/token.js.map +1 -0
  187. package/dist/types/transactionTypes.d.ts +60 -0
  188. package/dist/types/transactionTypes.d.ts.map +1 -0
  189. package/dist/types/transactionTypes.js +24 -0
  190. package/dist/types/transactionTypes.js.map +1 -0
  191. package/dist/utils/accountUtils.d.ts +72 -0
  192. package/dist/utils/accountUtils.d.ts.map +1 -0
  193. package/dist/utils/accountUtils.js +223 -0
  194. package/dist/utils/accountUtils.js.map +1 -0
  195. package/dist/utils/capabilitySymbols.d.ts +15 -0
  196. package/dist/utils/capabilitySymbols.d.ts.map +1 -0
  197. package/dist/utils/capabilitySymbols.js +21 -0
  198. package/dist/utils/capabilitySymbols.js.map +1 -0
  199. package/dist/utils/coalescePerpsRestRequest.d.ts +32 -0
  200. package/dist/utils/coalescePerpsRestRequest.d.ts.map +1 -0
  201. package/dist/utils/coalescePerpsRestRequest.js +66 -0
  202. package/dist/utils/coalescePerpsRestRequest.js.map +1 -0
  203. package/dist/utils/errorUtils.d.ts +50 -0
  204. package/dist/utils/errorUtils.d.ts.map +1 -0
  205. package/dist/utils/errorUtils.js +96 -0
  206. package/dist/utils/errorUtils.js.map +1 -0
  207. package/dist/utils/hyperLiquidAbstraction.d.ts +11 -0
  208. package/dist/utils/hyperLiquidAbstraction.d.ts.map +1 -0
  209. package/dist/utils/hyperLiquidAbstraction.js +19 -0
  210. package/dist/utils/hyperLiquidAbstraction.js.map +1 -0
  211. package/dist/utils/hyperLiquidAdapter.d.ts +77 -0
  212. package/dist/utils/hyperLiquidAdapter.d.ts.map +1 -0
  213. package/dist/utils/hyperLiquidAdapter.js +495 -0
  214. package/dist/utils/hyperLiquidAdapter.js.map +1 -0
  215. package/dist/utils/hyperLiquidOrderBookProcessor.d.ts +55 -0
  216. package/dist/utils/hyperLiquidOrderBookProcessor.d.ts.map +1 -0
  217. package/dist/utils/hyperLiquidOrderBookProcessor.js +78 -0
  218. package/dist/utils/hyperLiquidOrderBookProcessor.js.map +1 -0
  219. package/dist/utils/hyperLiquidPositionPreview.d.ts +124 -0
  220. package/dist/utils/hyperLiquidPositionPreview.d.ts.map +1 -0
  221. package/dist/utils/hyperLiquidPositionPreview.js +347 -0
  222. package/dist/utils/hyperLiquidPositionPreview.js.map +1 -0
  223. package/dist/utils/hyperLiquidValidation.d.ts +192 -0
  224. package/dist/utils/hyperLiquidValidation.d.ts.map +1 -0
  225. package/dist/utils/hyperLiquidValidation.js +786 -0
  226. package/dist/utils/hyperLiquidValidation.js.map +1 -0
  227. package/dist/utils/idUtils.d.ts +6 -0
  228. package/dist/utils/idUtils.d.ts.map +1 -0
  229. package/dist/utils/idUtils.js +10 -0
  230. package/dist/utils/idUtils.js.map +1 -0
  231. package/dist/utils/index.d.ts +29 -0
  232. package/dist/utils/index.d.ts.map +1 -0
  233. package/dist/utils/index.js +34 -0
  234. package/dist/utils/index.js.map +1 -0
  235. package/dist/utils/lighterAdapter.d.ts +117 -0
  236. package/dist/utils/lighterAdapter.d.ts.map +1 -0
  237. package/dist/utils/lighterAdapter.js +562 -0
  238. package/dist/utils/lighterAdapter.js.map +1 -0
  239. package/dist/utils/marketDataTransform.d.ts +71 -0
  240. package/dist/utils/marketDataTransform.d.ts.map +1 -0
  241. package/dist/utils/marketDataTransform.js +243 -0
  242. package/dist/utils/marketDataTransform.js.map +1 -0
  243. package/dist/utils/marketSearch.d.ts +48 -0
  244. package/dist/utils/marketSearch.d.ts.map +1 -0
  245. package/dist/utils/marketSearch.js +106 -0
  246. package/dist/utils/marketSearch.js.map +1 -0
  247. package/dist/utils/marketUtils.d.ts +73 -0
  248. package/dist/utils/marketUtils.d.ts.map +1 -0
  249. package/dist/utils/marketUtils.js +248 -0
  250. package/dist/utils/marketUtils.js.map +1 -0
  251. package/dist/utils/orderCalculations.d.ts +306 -0
  252. package/dist/utils/orderCalculations.d.ts.map +1 -0
  253. package/dist/utils/orderCalculations.js +833 -0
  254. package/dist/utils/orderCalculations.js.map +1 -0
  255. package/dist/utils/orderTypes.d.ts +166 -0
  256. package/dist/utils/orderTypes.d.ts.map +1 -0
  257. package/dist/utils/orderTypes.js +287 -0
  258. package/dist/utils/orderTypes.js.map +1 -0
  259. package/dist/utils/perpsConnectionAttemptContext.d.ts +7 -0
  260. package/dist/utils/perpsConnectionAttemptContext.d.ts.map +1 -0
  261. package/dist/utils/perpsConnectionAttemptContext.js +15 -0
  262. package/dist/utils/perpsConnectionAttemptContext.js.map +1 -0
  263. package/dist/utils/perpsDiskPersistence.d.ts +112 -0
  264. package/dist/utils/perpsDiskPersistence.d.ts.map +1 -0
  265. package/dist/utils/perpsDiskPersistence.js +251 -0
  266. package/dist/utils/perpsDiskPersistence.js.map +1 -0
  267. package/dist/utils/perpsFormatters.d.ts +204 -0
  268. package/dist/utils/perpsFormatters.d.ts.map +1 -0
  269. package/dist/utils/perpsFormatters.js +500 -0
  270. package/dist/utils/perpsFormatters.js.map +1 -0
  271. package/dist/utils/rewardsUtils.d.ts +33 -0
  272. package/dist/utils/rewardsUtils.d.ts.map +1 -0
  273. package/dist/utils/rewardsUtils.js +92 -0
  274. package/dist/utils/rewardsUtils.js.map +1 -0
  275. package/dist/utils/significantFigures.d.ts +25 -0
  276. package/dist/utils/significantFigures.d.ts.map +1 -0
  277. package/dist/utils/significantFigures.js +82 -0
  278. package/dist/utils/significantFigures.js.map +1 -0
  279. package/dist/utils/sortMarkets.d.ts +25 -0
  280. package/dist/utils/sortMarkets.d.ts.map +1 -0
  281. package/dist/utils/sortMarkets.js +88 -0
  282. package/dist/utils/sortMarkets.js.map +1 -0
  283. package/dist/utils/standaloneInfoClient.d.ts +37 -0
  284. package/dist/utils/standaloneInfoClient.d.ts.map +1 -0
  285. package/dist/utils/standaloneInfoClient.js +64 -0
  286. package/dist/utils/standaloneInfoClient.js.map +1 -0
  287. package/dist/utils/stringParseUtils.d.ts +11 -0
  288. package/dist/utils/stringParseUtils.d.ts.map +1 -0
  289. package/dist/utils/stringParseUtils.js +28 -0
  290. package/dist/utils/stringParseUtils.js.map +1 -0
  291. package/dist/utils/transferData.d.ts +9 -0
  292. package/dist/utils/transferData.d.ts.map +1 -0
  293. package/dist/utils/transferData.js +29 -0
  294. package/dist/utils/transferData.js.map +1 -0
  295. package/dist/utils/wait.d.ts +2 -0
  296. package/dist/utils/wait.d.ts.map +1 -0
  297. package/dist/utils/wait.js +2 -0
  298. package/dist/utils/wait.js.map +1 -0
  299. package/package.json +33 -61
  300. package/dist/PerpsController-method-action-types.cjs +0 -7
  301. package/dist/PerpsController-method-action-types.cjs.map +0 -1
  302. package/dist/PerpsController-method-action-types.d.cts +0 -1235
  303. package/dist/PerpsController-method-action-types.d.cts.map +0 -1
  304. package/dist/PerpsController-method-action-types.d.mts +0 -1235
  305. package/dist/PerpsController-method-action-types.d.mts.map +0 -1
  306. package/dist/PerpsController-method-action-types.mjs +0 -6
  307. package/dist/PerpsController-method-action-types.mjs.map +0 -1
  308. package/dist/PerpsController.cjs +0 -5154
  309. package/dist/PerpsController.cjs.map +0 -1
  310. package/dist/PerpsController.d.cts +0 -1313
  311. package/dist/PerpsController.d.cts.map +0 -1
  312. package/dist/PerpsController.d.mts +0 -1313
  313. package/dist/PerpsController.d.mts.map +0 -1
  314. package/dist/PerpsController.mjs +0 -5142
  315. package/dist/PerpsController.mjs.map +0 -1
  316. package/dist/aggregation/SubscriptionMultiplexer.cjs +0 -441
  317. package/dist/aggregation/SubscriptionMultiplexer.cjs.map +0 -1
  318. package/dist/aggregation/SubscriptionMultiplexer.d.cts +0 -171
  319. package/dist/aggregation/SubscriptionMultiplexer.d.cts.map +0 -1
  320. package/dist/aggregation/SubscriptionMultiplexer.d.mts +0 -171
  321. package/dist/aggregation/SubscriptionMultiplexer.d.mts.map +0 -1
  322. package/dist/aggregation/SubscriptionMultiplexer.mjs +0 -437
  323. package/dist/aggregation/SubscriptionMultiplexer.mjs.map +0 -1
  324. package/dist/aggregation/index.cjs +0 -9
  325. package/dist/aggregation/index.cjs.map +0 -1
  326. package/dist/aggregation/index.d.cts +0 -6
  327. package/dist/aggregation/index.d.cts.map +0 -1
  328. package/dist/aggregation/index.d.mts +0 -6
  329. package/dist/aggregation/index.d.mts.map +0 -1
  330. package/dist/aggregation/index.mjs +0 -5
  331. package/dist/aggregation/index.mjs.map +0 -1
  332. package/dist/constants/chartConfig.cjs +0 -239
  333. package/dist/constants/chartConfig.cjs.map +0 -1
  334. package/dist/constants/chartConfig.d.cts +0 -228
  335. package/dist/constants/chartConfig.d.cts.map +0 -1
  336. package/dist/constants/chartConfig.d.mts +0 -228
  337. package/dist/constants/chartConfig.d.mts.map +0 -1
  338. package/dist/constants/chartConfig.mjs +0 -233
  339. package/dist/constants/chartConfig.mjs.map +0 -1
  340. package/dist/constants/eventNames.cjs +0 -660
  341. package/dist/constants/eventNames.cjs.map +0 -1
  342. package/dist/constants/eventNames.d.cts +0 -565
  343. package/dist/constants/eventNames.d.cts.map +0 -1
  344. package/dist/constants/eventNames.d.mts +0 -565
  345. package/dist/constants/eventNames.d.mts.map +0 -1
  346. package/dist/constants/eventNames.mjs +0 -657
  347. package/dist/constants/eventNames.mjs.map +0 -1
  348. package/dist/constants/hyperLiquidConfig.cjs +0 -607
  349. package/dist/constants/hyperLiquidConfig.cjs.map +0 -1
  350. package/dist/constants/hyperLiquidConfig.d.cts +0 -280
  351. package/dist/constants/hyperLiquidConfig.d.cts.map +0 -1
  352. package/dist/constants/hyperLiquidConfig.d.mts +0 -280
  353. package/dist/constants/hyperLiquidConfig.d.mts.map +0 -1
  354. package/dist/constants/hyperLiquidConfig.mjs +0 -596
  355. package/dist/constants/hyperLiquidConfig.mjs.map +0 -1
  356. package/dist/constants/index.cjs +0 -28
  357. package/dist/constants/index.cjs.map +0 -1
  358. package/dist/constants/index.d.cts +0 -12
  359. package/dist/constants/index.d.cts.map +0 -1
  360. package/dist/constants/index.d.mts +0 -12
  361. package/dist/constants/index.d.mts.map +0 -1
  362. package/dist/constants/index.mjs +0 -12
  363. package/dist/constants/index.mjs.map +0 -1
  364. package/dist/constants/lighterConfig.cjs +0 -328
  365. package/dist/constants/lighterConfig.cjs.map +0 -1
  366. package/dist/constants/lighterConfig.d.cts +0 -204
  367. package/dist/constants/lighterConfig.d.cts.map +0 -1
  368. package/dist/constants/lighterConfig.d.mts +0 -204
  369. package/dist/constants/lighterConfig.d.mts.map +0 -1
  370. package/dist/constants/lighterConfig.mjs +0 -317
  371. package/dist/constants/lighterConfig.mjs.map +0 -1
  372. package/dist/constants/orderTypes.cjs +0 -31
  373. package/dist/constants/orderTypes.cjs.map +0 -1
  374. package/dist/constants/orderTypes.d.cts +0 -19
  375. package/dist/constants/orderTypes.d.cts.map +0 -1
  376. package/dist/constants/orderTypes.d.mts +0 -19
  377. package/dist/constants/orderTypes.d.mts.map +0 -1
  378. package/dist/constants/orderTypes.mjs +0 -27
  379. package/dist/constants/orderTypes.mjs.map +0 -1
  380. package/dist/constants/performanceMetrics.cjs +0 -63
  381. package/dist/constants/performanceMetrics.cjs.map +0 -1
  382. package/dist/constants/performanceMetrics.d.cts +0 -46
  383. package/dist/constants/performanceMetrics.d.cts.map +0 -1
  384. package/dist/constants/performanceMetrics.d.mts +0 -46
  385. package/dist/constants/performanceMetrics.d.mts.map +0 -1
  386. package/dist/constants/performanceMetrics.mjs +0 -60
  387. package/dist/constants/performanceMetrics.mjs.map +0 -1
  388. package/dist/constants/perpsConfig.cjs +0 -560
  389. package/dist/constants/perpsConfig.cjs.map +0 -1
  390. package/dist/constants/perpsConfig.d.cts +0 -480
  391. package/dist/constants/perpsConfig.d.cts.map +0 -1
  392. package/dist/constants/perpsConfig.d.mts +0 -480
  393. package/dist/constants/perpsConfig.d.mts.map +0 -1
  394. package/dist/constants/perpsConfig.mjs +0 -555
  395. package/dist/constants/perpsConfig.mjs.map +0 -1
  396. package/dist/constants/transactionsHistoryConfig.cjs +0 -38
  397. package/dist/constants/transactionsHistoryConfig.cjs.map +0 -1
  398. package/dist/constants/transactionsHistoryConfig.d.cts +0 -35
  399. package/dist/constants/transactionsHistoryConfig.d.cts.map +0 -1
  400. package/dist/constants/transactionsHistoryConfig.d.mts +0 -35
  401. package/dist/constants/transactionsHistoryConfig.d.mts.map +0 -1
  402. package/dist/constants/transactionsHistoryConfig.mjs +0 -35
  403. package/dist/constants/transactionsHistoryConfig.mjs.map +0 -1
  404. package/dist/index.cjs +0 -334
  405. package/dist/index.cjs.map +0 -1
  406. package/dist/index.d.cts +0 -95
  407. package/dist/index.d.cts.map +0 -1
  408. package/dist/index.d.mts +0 -95
  409. package/dist/index.d.mts.map +0 -1
  410. package/dist/index.mjs +0 -80
  411. package/dist/index.mjs.map +0 -1
  412. package/dist/perpsErrorCodes.cjs +0 -128
  413. package/dist/perpsErrorCodes.cjs.map +0 -1
  414. package/dist/perpsErrorCodes.d.cts +0 -105
  415. package/dist/perpsErrorCodes.d.cts.map +0 -1
  416. package/dist/perpsErrorCodes.d.mts +0 -105
  417. package/dist/perpsErrorCodes.d.mts.map +0 -1
  418. package/dist/perpsErrorCodes.mjs +0 -125
  419. package/dist/perpsErrorCodes.mjs.map +0 -1
  420. package/dist/providers/AggregatedPerpsProvider.cjs +0 -810
  421. package/dist/providers/AggregatedPerpsProvider.cjs.map +0 -1
  422. package/dist/providers/AggregatedPerpsProvider.d.cts +0 -277
  423. package/dist/providers/AggregatedPerpsProvider.d.cts.map +0 -1
  424. package/dist/providers/AggregatedPerpsProvider.d.mts +0 -277
  425. package/dist/providers/AggregatedPerpsProvider.d.mts.map +0 -1
  426. package/dist/providers/AggregatedPerpsProvider.mjs +0 -805
  427. package/dist/providers/AggregatedPerpsProvider.mjs.map +0 -1
  428. package/dist/providers/HyperLiquidProvider.cjs +0 -10963
  429. package/dist/providers/HyperLiquidProvider.cjs.map +0 -1
  430. package/dist/providers/HyperLiquidProvider.d.cts +0 -656
  431. package/dist/providers/HyperLiquidProvider.d.cts.map +0 -1
  432. package/dist/providers/HyperLiquidProvider.d.mts +0 -656
  433. package/dist/providers/HyperLiquidProvider.d.mts.map +0 -1
  434. package/dist/providers/HyperLiquidProvider.mjs +0 -10959
  435. package/dist/providers/HyperLiquidProvider.mjs.map +0 -1
  436. package/dist/providers/LighterProvider.cjs +0 -6575
  437. package/dist/providers/LighterProvider.cjs.map +0 -1
  438. package/dist/providers/LighterProvider.d.cts +0 -179
  439. package/dist/providers/LighterProvider.d.cts.map +0 -1
  440. package/dist/providers/LighterProvider.d.mts +0 -179
  441. package/dist/providers/LighterProvider.d.mts.map +0 -1
  442. package/dist/providers/LighterProvider.mjs +0 -6571
  443. package/dist/providers/LighterProvider.mjs.map +0 -1
  444. package/dist/routing/ProviderRouter.cjs +0 -154
  445. package/dist/routing/ProviderRouter.cjs.map +0 -1
  446. package/dist/routing/ProviderRouter.d.cts +0 -112
  447. package/dist/routing/ProviderRouter.d.cts.map +0 -1
  448. package/dist/routing/ProviderRouter.d.mts +0 -112
  449. package/dist/routing/ProviderRouter.d.mts.map +0 -1
  450. package/dist/routing/ProviderRouter.mjs +0 -150
  451. package/dist/routing/ProviderRouter.mjs.map +0 -1
  452. package/dist/routing/index.cjs +0 -9
  453. package/dist/routing/index.cjs.map +0 -1
  454. package/dist/routing/index.d.cts +0 -6
  455. package/dist/routing/index.d.cts.map +0 -1
  456. package/dist/routing/index.d.mts +0 -6
  457. package/dist/routing/index.d.mts.map +0 -1
  458. package/dist/routing/index.mjs +0 -5
  459. package/dist/routing/index.mjs.map +0 -1
  460. package/dist/selectors.cjs +0 -264
  461. package/dist/selectors.cjs.map +0 -1
  462. package/dist/selectors.d.cts +0 -336
  463. package/dist/selectors.d.cts.map +0 -1
  464. package/dist/selectors.d.mts +0 -336
  465. package/dist/selectors.d.mts.map +0 -1
  466. package/dist/selectors.mjs +0 -249
  467. package/dist/selectors.mjs.map +0 -1
  468. package/dist/services/AccountService.cjs +0 -324
  469. package/dist/services/AccountService.cjs.map +0 -1
  470. package/dist/services/AccountService.d.cts +0 -56
  471. package/dist/services/AccountService.d.cts.map +0 -1
  472. package/dist/services/AccountService.d.mts +0 -56
  473. package/dist/services/AccountService.d.mts.map +0 -1
  474. package/dist/services/AccountService.mjs +0 -320
  475. package/dist/services/AccountService.mjs.map +0 -1
  476. package/dist/services/AggregatedOrderBookConnection.cjs +0 -405
  477. package/dist/services/AggregatedOrderBookConnection.cjs.map +0 -1
  478. package/dist/services/AggregatedOrderBookConnection.d.cts +0 -106
  479. package/dist/services/AggregatedOrderBookConnection.d.cts.map +0 -1
  480. package/dist/services/AggregatedOrderBookConnection.d.mts +0 -106
  481. package/dist/services/AggregatedOrderBookConnection.d.mts.map +0 -1
  482. package/dist/services/AggregatedOrderBookConnection.mjs +0 -400
  483. package/dist/services/AggregatedOrderBookConnection.mjs.map +0 -1
  484. package/dist/services/DataLakeService.cjs +0 -233
  485. package/dist/services/DataLakeService.cjs.map +0 -1
  486. package/dist/services/DataLakeService.d.cts +0 -51
  487. package/dist/services/DataLakeService.d.cts.map +0 -1
  488. package/dist/services/DataLakeService.d.mts +0 -51
  489. package/dist/services/DataLakeService.d.mts.map +0 -1
  490. package/dist/services/DataLakeService.mjs +0 -229
  491. package/dist/services/DataLakeService.mjs.map +0 -1
  492. package/dist/services/DepositService.cjs +0 -105
  493. package/dist/services/DepositService.cjs.map +0 -1
  494. package/dist/services/DepositService.d.cts +0 -39
  495. package/dist/services/DepositService.d.cts.map +0 -1
  496. package/dist/services/DepositService.d.mts +0 -39
  497. package/dist/services/DepositService.d.mts.map +0 -1
  498. package/dist/services/DepositService.mjs +0 -101
  499. package/dist/services/DepositService.mjs.map +0 -1
  500. package/dist/services/DexDiscoveryCacheManager.cjs +0 -147
  501. package/dist/services/DexDiscoveryCacheManager.cjs.map +0 -1
  502. package/dist/services/DexDiscoveryCacheManager.d.cts +0 -52
  503. package/dist/services/DexDiscoveryCacheManager.d.cts.map +0 -1
  504. package/dist/services/DexDiscoveryCacheManager.d.mts +0 -52
  505. package/dist/services/DexDiscoveryCacheManager.d.mts.map +0 -1
  506. package/dist/services/DexDiscoveryCacheManager.mjs +0 -143
  507. package/dist/services/DexDiscoveryCacheManager.mjs.map +0 -1
  508. package/dist/services/EligibilityService.cjs +0 -78
  509. package/dist/services/EligibilityService.cjs.map +0 -1
  510. package/dist/services/EligibilityService.d.cts +0 -28
  511. package/dist/services/EligibilityService.d.cts.map +0 -1
  512. package/dist/services/EligibilityService.d.mts +0 -28
  513. package/dist/services/EligibilityService.d.mts.map +0 -1
  514. package/dist/services/EligibilityService.mjs +0 -74
  515. package/dist/services/EligibilityService.mjs.map +0 -1
  516. package/dist/services/FeatureFlagConfigurationService.cjs +0 -257
  517. package/dist/services/FeatureFlagConfigurationService.cjs.map +0 -1
  518. package/dist/services/FeatureFlagConfigurationService.d.cts +0 -73
  519. package/dist/services/FeatureFlagConfigurationService.d.cts.map +0 -1
  520. package/dist/services/FeatureFlagConfigurationService.d.mts +0 -73
  521. package/dist/services/FeatureFlagConfigurationService.d.mts.map +0 -1
  522. package/dist/services/FeatureFlagConfigurationService.mjs +0 -253
  523. package/dist/services/FeatureFlagConfigurationService.mjs.map +0 -1
  524. package/dist/services/HyperLiquidClientService.cjs +0 -1114
  525. package/dist/services/HyperLiquidClientService.cjs.map +0 -1
  526. package/dist/services/HyperLiquidClientService.d.cts +0 -252
  527. package/dist/services/HyperLiquidClientService.d.cts.map +0 -1
  528. package/dist/services/HyperLiquidClientService.d.mts +0 -252
  529. package/dist/services/HyperLiquidClientService.d.mts.map +0 -1
  530. package/dist/services/HyperLiquidClientService.mjs +0 -1109
  531. package/dist/services/HyperLiquidClientService.mjs.map +0 -1
  532. package/dist/services/HyperLiquidSubscriptionService.cjs +0 -3594
  533. package/dist/services/HyperLiquidSubscriptionService.cjs.map +0 -1
  534. package/dist/services/HyperLiquidSubscriptionService.d.cts +0 -265
  535. package/dist/services/HyperLiquidSubscriptionService.d.cts.map +0 -1
  536. package/dist/services/HyperLiquidSubscriptionService.d.mts +0 -265
  537. package/dist/services/HyperLiquidSubscriptionService.d.mts.map +0 -1
  538. package/dist/services/HyperLiquidSubscriptionService.mjs +0 -3590
  539. package/dist/services/HyperLiquidSubscriptionService.mjs.map +0 -1
  540. package/dist/services/HyperLiquidWalletService.cjs +0 -186
  541. package/dist/services/HyperLiquidWalletService.cjs.map +0 -1
  542. package/dist/services/HyperLiquidWalletService.d.cts +0 -84
  543. package/dist/services/HyperLiquidWalletService.d.cts.map +0 -1
  544. package/dist/services/HyperLiquidWalletService.d.mts +0 -84
  545. package/dist/services/HyperLiquidWalletService.d.mts.map +0 -1
  546. package/dist/services/HyperLiquidWalletService.mjs +0 -182
  547. package/dist/services/HyperLiquidWalletService.mjs.map +0 -1
  548. package/dist/services/LighterClientService.cjs +0 -643
  549. package/dist/services/LighterClientService.cjs.map +0 -1
  550. package/dist/services/LighterClientService.d.cts +0 -200
  551. package/dist/services/LighterClientService.d.cts.map +0 -1
  552. package/dist/services/LighterClientService.d.mts +0 -200
  553. package/dist/services/LighterClientService.d.mts.map +0 -1
  554. package/dist/services/LighterClientService.mjs +0 -637
  555. package/dist/services/LighterClientService.mjs.map +0 -1
  556. package/dist/services/LighterWalletService.cjs +0 -109
  557. package/dist/services/LighterWalletService.cjs.map +0 -1
  558. package/dist/services/LighterWalletService.d.cts +0 -51
  559. package/dist/services/LighterWalletService.d.cts.map +0 -1
  560. package/dist/services/LighterWalletService.d.mts +0 -51
  561. package/dist/services/LighterWalletService.d.mts.map +0 -1
  562. package/dist/services/LighterWalletService.mjs +0 -105
  563. package/dist/services/LighterWalletService.mjs.map +0 -1
  564. package/dist/services/MarketDataService.cjs +0 -1171
  565. package/dist/services/MarketDataService.cjs.map +0 -1
  566. package/dist/services/MarketDataService.d.cts +0 -350
  567. package/dist/services/MarketDataService.d.cts.map +0 -1
  568. package/dist/services/MarketDataService.d.mts +0 -350
  569. package/dist/services/MarketDataService.d.mts.map +0 -1
  570. package/dist/services/MarketDataService.mjs +0 -1167
  571. package/dist/services/MarketDataService.mjs.map +0 -1
  572. package/dist/services/RewardsIntegrationService.cjs +0 -391
  573. package/dist/services/RewardsIntegrationService.cjs.map +0 -1
  574. package/dist/services/RewardsIntegrationService.d.cts +0 -84
  575. package/dist/services/RewardsIntegrationService.d.cts.map +0 -1
  576. package/dist/services/RewardsIntegrationService.d.mts +0 -84
  577. package/dist/services/RewardsIntegrationService.d.mts.map +0 -1
  578. package/dist/services/RewardsIntegrationService.mjs +0 -387
  579. package/dist/services/RewardsIntegrationService.mjs.map +0 -1
  580. package/dist/services/ServiceContext.cjs +0 -3
  581. package/dist/services/ServiceContext.cjs.map +0 -1
  582. package/dist/services/ServiceContext.d.cts +0 -102
  583. package/dist/services/ServiceContext.d.cts.map +0 -1
  584. package/dist/services/ServiceContext.d.mts +0 -102
  585. package/dist/services/ServiceContext.d.mts.map +0 -1
  586. package/dist/services/ServiceContext.mjs +0 -2
  587. package/dist/services/ServiceContext.mjs.map +0 -1
  588. package/dist/services/TerminalMarketService.cjs +0 -623
  589. package/dist/services/TerminalMarketService.cjs.map +0 -1
  590. package/dist/services/TerminalMarketService.d.cts +0 -45
  591. package/dist/services/TerminalMarketService.d.cts.map +0 -1
  592. package/dist/services/TerminalMarketService.d.mts +0 -45
  593. package/dist/services/TerminalMarketService.d.mts.map +0 -1
  594. package/dist/services/TerminalMarketService.mjs +0 -619
  595. package/dist/services/TerminalMarketService.mjs.map +0 -1
  596. package/dist/services/TradingReadinessCache.cjs +0 -329
  597. package/dist/services/TradingReadinessCache.cjs.map +0 -1
  598. package/dist/services/TradingReadinessCache.d.cts +0 -204
  599. package/dist/services/TradingReadinessCache.d.cts.map +0 -1
  600. package/dist/services/TradingReadinessCache.d.mts +0 -204
  601. package/dist/services/TradingReadinessCache.d.mts.map +0 -1
  602. package/dist/services/TradingReadinessCache.mjs +0 -326
  603. package/dist/services/TradingReadinessCache.mjs.map +0 -1
  604. package/dist/services/TradingService.cjs +0 -1895
  605. package/dist/services/TradingService.cjs.map +0 -1
  606. package/dist/services/TradingService.d.cts +0 -201
  607. package/dist/services/TradingService.d.cts.map +0 -1
  608. package/dist/services/TradingService.d.mts +0 -201
  609. package/dist/services/TradingService.d.mts.map +0 -1
  610. package/dist/services/TradingService.mjs +0 -1891
  611. package/dist/services/TradingService.mjs.map +0 -1
  612. package/dist/types/config.cjs +0 -3
  613. package/dist/types/config.cjs.map +0 -1
  614. package/dist/types/config.d.cts +0 -49
  615. package/dist/types/config.d.cts.map +0 -1
  616. package/dist/types/config.d.mts +0 -49
  617. package/dist/types/config.d.mts.map +0 -1
  618. package/dist/types/config.mjs +0 -2
  619. package/dist/types/config.mjs.map +0 -1
  620. package/dist/types/hyperliquid-types.cjs +0 -45
  621. package/dist/types/hyperliquid-types.cjs.map +0 -1
  622. package/dist/types/hyperliquid-types.d.cts +0 -67
  623. package/dist/types/hyperliquid-types.d.cts.map +0 -1
  624. package/dist/types/hyperliquid-types.d.mts +0 -67
  625. package/dist/types/hyperliquid-types.d.mts.map +0 -1
  626. package/dist/types/hyperliquid-types.mjs +0 -41
  627. package/dist/types/hyperliquid-types.mjs.map +0 -1
  628. package/dist/types/index.cjs +0 -151
  629. package/dist/types/index.cjs.map +0 -1
  630. package/dist/types/index.d.cts +0 -2183
  631. package/dist/types/index.d.cts.map +0 -1
  632. package/dist/types/index.d.mts +0 -2183
  633. package/dist/types/index.d.mts.map +0 -1
  634. package/dist/types/index.mjs +0 -133
  635. package/dist/types/index.mjs.map +0 -1
  636. package/dist/types/lighter-types.cjs +0 -11
  637. package/dist/types/lighter-types.cjs.map +0 -1
  638. package/dist/types/lighter-types.d.cts +0 -763
  639. package/dist/types/lighter-types.d.cts.map +0 -1
  640. package/dist/types/lighter-types.d.mts +0 -763
  641. package/dist/types/lighter-types.d.mts.map +0 -1
  642. package/dist/types/lighter-types.mjs +0 -10
  643. package/dist/types/lighter-types.mjs.map +0 -1
  644. package/dist/types/messenger.cjs +0 -3
  645. package/dist/types/messenger.cjs.map +0 -1
  646. package/dist/types/messenger.d.cts +0 -30
  647. package/dist/types/messenger.d.cts.map +0 -1
  648. package/dist/types/messenger.d.mts +0 -30
  649. package/dist/types/messenger.d.mts.map +0 -1
  650. package/dist/types/messenger.mjs +0 -2
  651. package/dist/types/messenger.mjs.map +0 -1
  652. package/dist/types/perps-types.cjs +0 -7
  653. package/dist/types/perps-types.cjs.map +0 -1
  654. package/dist/types/perps-types.d.cts +0 -184
  655. package/dist/types/perps-types.d.cts.map +0 -1
  656. package/dist/types/perps-types.d.mts +0 -184
  657. package/dist/types/perps-types.d.mts.map +0 -1
  658. package/dist/types/perps-types.mjs +0 -5
  659. package/dist/types/perps-types.mjs.map +0 -1
  660. package/dist/types/token.cjs +0 -3
  661. package/dist/types/token.cjs.map +0 -1
  662. package/dist/types/token.d.cts +0 -25
  663. package/dist/types/token.d.cts.map +0 -1
  664. package/dist/types/token.d.mts +0 -25
  665. package/dist/types/token.d.mts.map +0 -1
  666. package/dist/types/token.mjs +0 -2
  667. package/dist/types/token.mjs.map +0 -1
  668. package/dist/types/transactionTypes.cjs +0 -29
  669. package/dist/types/transactionTypes.cjs.map +0 -1
  670. package/dist/types/transactionTypes.d.cts +0 -60
  671. package/dist/types/transactionTypes.d.cts.map +0 -1
  672. package/dist/types/transactionTypes.d.mts +0 -60
  673. package/dist/types/transactionTypes.d.mts.map +0 -1
  674. package/dist/types/transactionTypes.mjs +0 -24
  675. package/dist/types/transactionTypes.mjs.map +0 -1
  676. package/dist/utils/accountUtils.cjs +0 -236
  677. package/dist/utils/accountUtils.cjs.map +0 -1
  678. package/dist/utils/accountUtils.d.cts +0 -72
  679. package/dist/utils/accountUtils.d.cts.map +0 -1
  680. package/dist/utils/accountUtils.d.mts +0 -72
  681. package/dist/utils/accountUtils.d.mts.map +0 -1
  682. package/dist/utils/accountUtils.mjs +0 -223
  683. package/dist/utils/accountUtils.mjs.map +0 -1
  684. package/dist/utils/capabilitySymbols.cjs +0 -25
  685. package/dist/utils/capabilitySymbols.cjs.map +0 -1
  686. package/dist/utils/capabilitySymbols.d.cts +0 -15
  687. package/dist/utils/capabilitySymbols.d.cts.map +0 -1
  688. package/dist/utils/capabilitySymbols.d.mts +0 -15
  689. package/dist/utils/capabilitySymbols.d.mts.map +0 -1
  690. package/dist/utils/capabilitySymbols.mjs +0 -21
  691. package/dist/utils/capabilitySymbols.mjs.map +0 -1
  692. package/dist/utils/coalescePerpsRestRequest.cjs +0 -71
  693. package/dist/utils/coalescePerpsRestRequest.cjs.map +0 -1
  694. package/dist/utils/coalescePerpsRestRequest.d.cts +0 -32
  695. package/dist/utils/coalescePerpsRestRequest.d.cts.map +0 -1
  696. package/dist/utils/coalescePerpsRestRequest.d.mts +0 -32
  697. package/dist/utils/coalescePerpsRestRequest.d.mts.map +0 -1
  698. package/dist/utils/coalescePerpsRestRequest.mjs +0 -66
  699. package/dist/utils/coalescePerpsRestRequest.mjs.map +0 -1
  700. package/dist/utils/errorUtils.cjs +0 -104
  701. package/dist/utils/errorUtils.cjs.map +0 -1
  702. package/dist/utils/errorUtils.d.cts +0 -50
  703. package/dist/utils/errorUtils.d.cts.map +0 -1
  704. package/dist/utils/errorUtils.d.mts +0 -50
  705. package/dist/utils/errorUtils.d.mts.map +0 -1
  706. package/dist/utils/errorUtils.mjs +0 -96
  707. package/dist/utils/errorUtils.mjs.map +0 -1
  708. package/dist/utils/hyperLiquidAbstraction.cjs +0 -23
  709. package/dist/utils/hyperLiquidAbstraction.cjs.map +0 -1
  710. package/dist/utils/hyperLiquidAbstraction.d.cts +0 -11
  711. package/dist/utils/hyperLiquidAbstraction.d.cts.map +0 -1
  712. package/dist/utils/hyperLiquidAbstraction.d.mts +0 -11
  713. package/dist/utils/hyperLiquidAbstraction.d.mts.map +0 -1
  714. package/dist/utils/hyperLiquidAbstraction.mjs +0 -19
  715. package/dist/utils/hyperLiquidAbstraction.mjs.map +0 -1
  716. package/dist/utils/hyperLiquidAdapter.cjs +0 -512
  717. package/dist/utils/hyperLiquidAdapter.cjs.map +0 -1
  718. package/dist/utils/hyperLiquidAdapter.d.cts +0 -77
  719. package/dist/utils/hyperLiquidAdapter.d.cts.map +0 -1
  720. package/dist/utils/hyperLiquidAdapter.d.mts +0 -77
  721. package/dist/utils/hyperLiquidAdapter.d.mts.map +0 -1
  722. package/dist/utils/hyperLiquidAdapter.mjs +0 -494
  723. package/dist/utils/hyperLiquidAdapter.mjs.map +0 -1
  724. package/dist/utils/hyperLiquidOrderBookProcessor.cjs +0 -83
  725. package/dist/utils/hyperLiquidOrderBookProcessor.cjs.map +0 -1
  726. package/dist/utils/hyperLiquidOrderBookProcessor.d.cts +0 -55
  727. package/dist/utils/hyperLiquidOrderBookProcessor.d.cts.map +0 -1
  728. package/dist/utils/hyperLiquidOrderBookProcessor.d.mts +0 -55
  729. package/dist/utils/hyperLiquidOrderBookProcessor.d.mts.map +0 -1
  730. package/dist/utils/hyperLiquidOrderBookProcessor.mjs +0 -78
  731. package/dist/utils/hyperLiquidOrderBookProcessor.mjs.map +0 -1
  732. package/dist/utils/hyperLiquidPositionPreview.cjs +0 -355
  733. package/dist/utils/hyperLiquidPositionPreview.cjs.map +0 -1
  734. package/dist/utils/hyperLiquidPositionPreview.d.cts +0 -124
  735. package/dist/utils/hyperLiquidPositionPreview.d.cts.map +0 -1
  736. package/dist/utils/hyperLiquidPositionPreview.d.mts +0 -124
  737. package/dist/utils/hyperLiquidPositionPreview.d.mts.map +0 -1
  738. package/dist/utils/hyperLiquidPositionPreview.mjs +0 -347
  739. package/dist/utils/hyperLiquidPositionPreview.mjs.map +0 -1
  740. package/dist/utils/hyperLiquidValidation.cjs +0 -799
  741. package/dist/utils/hyperLiquidValidation.cjs.map +0 -1
  742. package/dist/utils/hyperLiquidValidation.d.cts +0 -192
  743. package/dist/utils/hyperLiquidValidation.d.cts.map +0 -1
  744. package/dist/utils/hyperLiquidValidation.d.mts +0 -192
  745. package/dist/utils/hyperLiquidValidation.d.mts.map +0 -1
  746. package/dist/utils/hyperLiquidValidation.mjs +0 -786
  747. package/dist/utils/hyperLiquidValidation.mjs.map +0 -1
  748. package/dist/utils/idUtils.cjs +0 -18
  749. package/dist/utils/idUtils.cjs.map +0 -1
  750. package/dist/utils/idUtils.d.cts +0 -6
  751. package/dist/utils/idUtils.d.cts.map +0 -1
  752. package/dist/utils/idUtils.d.mts +0 -6
  753. package/dist/utils/idUtils.d.mts.map +0 -1
  754. package/dist/utils/idUtils.mjs +0 -10
  755. package/dist/utils/idUtils.mjs.map +0 -1
  756. package/dist/utils/index.cjs +0 -66
  757. package/dist/utils/index.cjs.map +0 -1
  758. package/dist/utils/index.d.cts +0 -29
  759. package/dist/utils/index.d.cts.map +0 -1
  760. package/dist/utils/index.d.mts +0 -29
  761. package/dist/utils/index.d.mts.map +0 -1
  762. package/dist/utils/index.mjs +0 -34
  763. package/dist/utils/index.mjs.map +0 -1
  764. package/dist/utils/lighterAdapter.cjs +0 -575
  765. package/dist/utils/lighterAdapter.cjs.map +0 -1
  766. package/dist/utils/lighterAdapter.d.cts +0 -117
  767. package/dist/utils/lighterAdapter.d.cts.map +0 -1
  768. package/dist/utils/lighterAdapter.d.mts +0 -117
  769. package/dist/utils/lighterAdapter.d.mts.map +0 -1
  770. package/dist/utils/lighterAdapter.mjs +0 -562
  771. package/dist/utils/lighterAdapter.mjs.map +0 -1
  772. package/dist/utils/marketDataTransform.cjs +0 -250
  773. package/dist/utils/marketDataTransform.cjs.map +0 -1
  774. package/dist/utils/marketDataTransform.d.cts +0 -71
  775. package/dist/utils/marketDataTransform.d.cts.map +0 -1
  776. package/dist/utils/marketDataTransform.d.mts +0 -71
  777. package/dist/utils/marketDataTransform.d.mts.map +0 -1
  778. package/dist/utils/marketDataTransform.mjs +0 -243
  779. package/dist/utils/marketDataTransform.mjs.map +0 -1
  780. package/dist/utils/marketSearch.cjs +0 -111
  781. package/dist/utils/marketSearch.cjs.map +0 -1
  782. package/dist/utils/marketSearch.d.cts +0 -48
  783. package/dist/utils/marketSearch.d.cts.map +0 -1
  784. package/dist/utils/marketSearch.d.mts +0 -48
  785. package/dist/utils/marketSearch.d.mts.map +0 -1
  786. package/dist/utils/marketSearch.mjs +0 -106
  787. package/dist/utils/marketSearch.mjs.map +0 -1
  788. package/dist/utils/marketUtils.cjs +0 -266
  789. package/dist/utils/marketUtils.cjs.map +0 -1
  790. package/dist/utils/marketUtils.d.cts +0 -73
  791. package/dist/utils/marketUtils.d.cts.map +0 -1
  792. package/dist/utils/marketUtils.d.mts +0 -73
  793. package/dist/utils/marketUtils.d.mts.map +0 -1
  794. package/dist/utils/marketUtils.mjs +0 -248
  795. package/dist/utils/marketUtils.mjs.map +0 -1
  796. package/dist/utils/orderCalculations.cjs +0 -849
  797. package/dist/utils/orderCalculations.cjs.map +0 -1
  798. package/dist/utils/orderCalculations.d.cts +0 -306
  799. package/dist/utils/orderCalculations.d.cts.map +0 -1
  800. package/dist/utils/orderCalculations.d.mts +0 -306
  801. package/dist/utils/orderCalculations.d.mts.map +0 -1
  802. package/dist/utils/orderCalculations.mjs +0 -833
  803. package/dist/utils/orderCalculations.mjs.map +0 -1
  804. package/dist/utils/orderTypes.cjs +0 -301
  805. package/dist/utils/orderTypes.cjs.map +0 -1
  806. package/dist/utils/orderTypes.d.cts +0 -166
  807. package/dist/utils/orderTypes.d.cts.map +0 -1
  808. package/dist/utils/orderTypes.d.mts +0 -166
  809. package/dist/utils/orderTypes.d.mts.map +0 -1
  810. package/dist/utils/orderTypes.mjs +0 -287
  811. package/dist/utils/orderTypes.mjs.map +0 -1
  812. package/dist/utils/perpsConnectionAttemptContext.cjs +0 -20
  813. package/dist/utils/perpsConnectionAttemptContext.cjs.map +0 -1
  814. package/dist/utils/perpsConnectionAttemptContext.d.cts +0 -7
  815. package/dist/utils/perpsConnectionAttemptContext.d.cts.map +0 -1
  816. package/dist/utils/perpsConnectionAttemptContext.d.mts +0 -7
  817. package/dist/utils/perpsConnectionAttemptContext.d.mts.map +0 -1
  818. package/dist/utils/perpsConnectionAttemptContext.mjs +0 -15
  819. package/dist/utils/perpsConnectionAttemptContext.mjs.map +0 -1
  820. package/dist/utils/perpsDiskPersistence.cjs +0 -259
  821. package/dist/utils/perpsDiskPersistence.cjs.map +0 -1
  822. package/dist/utils/perpsDiskPersistence.d.cts +0 -112
  823. package/dist/utils/perpsDiskPersistence.d.cts.map +0 -1
  824. package/dist/utils/perpsDiskPersistence.d.mts +0 -112
  825. package/dist/utils/perpsDiskPersistence.d.mts.map +0 -1
  826. package/dist/utils/perpsDiskPersistence.mjs +0 -251
  827. package/dist/utils/perpsDiskPersistence.mjs.map +0 -1
  828. package/dist/utils/perpsFormatters.cjs +0 -509
  829. package/dist/utils/perpsFormatters.cjs.map +0 -1
  830. package/dist/utils/perpsFormatters.d.cts +0 -204
  831. package/dist/utils/perpsFormatters.d.cts.map +0 -1
  832. package/dist/utils/perpsFormatters.d.mts +0 -204
  833. package/dist/utils/perpsFormatters.d.mts.map +0 -1
  834. package/dist/utils/perpsFormatters.mjs +0 -500
  835. package/dist/utils/perpsFormatters.mjs.map +0 -1
  836. package/dist/utils/rewardsUtils.cjs +0 -98
  837. package/dist/utils/rewardsUtils.cjs.map +0 -1
  838. package/dist/utils/rewardsUtils.d.cts +0 -33
  839. package/dist/utils/rewardsUtils.d.cts.map +0 -1
  840. package/dist/utils/rewardsUtils.d.mts +0 -33
  841. package/dist/utils/rewardsUtils.d.mts.map +0 -1
  842. package/dist/utils/rewardsUtils.mjs +0 -92
  843. package/dist/utils/rewardsUtils.mjs.map +0 -1
  844. package/dist/utils/significantFigures.cjs +0 -88
  845. package/dist/utils/significantFigures.cjs.map +0 -1
  846. package/dist/utils/significantFigures.d.cts +0 -25
  847. package/dist/utils/significantFigures.d.cts.map +0 -1
  848. package/dist/utils/significantFigures.d.mts +0 -25
  849. package/dist/utils/significantFigures.d.mts.map +0 -1
  850. package/dist/utils/significantFigures.mjs +0 -82
  851. package/dist/utils/significantFigures.mjs.map +0 -1
  852. package/dist/utils/sortMarkets.cjs +0 -93
  853. package/dist/utils/sortMarkets.cjs.map +0 -1
  854. package/dist/utils/sortMarkets.d.cts +0 -25
  855. package/dist/utils/sortMarkets.d.cts.map +0 -1
  856. package/dist/utils/sortMarkets.d.mts +0 -25
  857. package/dist/utils/sortMarkets.d.mts.map +0 -1
  858. package/dist/utils/sortMarkets.mjs +0 -88
  859. package/dist/utils/sortMarkets.mjs.map +0 -1
  860. package/dist/utils/standaloneInfoClient.cjs +0 -70
  861. package/dist/utils/standaloneInfoClient.cjs.map +0 -1
  862. package/dist/utils/standaloneInfoClient.d.cts +0 -37
  863. package/dist/utils/standaloneInfoClient.d.cts.map +0 -1
  864. package/dist/utils/standaloneInfoClient.d.mts +0 -37
  865. package/dist/utils/standaloneInfoClient.d.mts.map +0 -1
  866. package/dist/utils/standaloneInfoClient.mjs +0 -64
  867. package/dist/utils/standaloneInfoClient.mjs.map +0 -1
  868. package/dist/utils/stringParseUtils.cjs +0 -34
  869. package/dist/utils/stringParseUtils.cjs.map +0 -1
  870. package/dist/utils/stringParseUtils.d.cts +0 -11
  871. package/dist/utils/stringParseUtils.d.cts.map +0 -1
  872. package/dist/utils/stringParseUtils.d.mts +0 -11
  873. package/dist/utils/stringParseUtils.d.mts.map +0 -1
  874. package/dist/utils/stringParseUtils.mjs +0 -28
  875. package/dist/utils/stringParseUtils.mjs.map +0 -1
  876. package/dist/utils/transferData.cjs +0 -33
  877. package/dist/utils/transferData.cjs.map +0 -1
  878. package/dist/utils/transferData.d.cts +0 -9
  879. package/dist/utils/transferData.d.cts.map +0 -1
  880. package/dist/utils/transferData.d.mts +0 -9
  881. package/dist/utils/transferData.d.mts.map +0 -1
  882. package/dist/utils/transferData.mjs +0 -29
  883. package/dist/utils/transferData.mjs.map +0 -1
  884. package/dist/utils/wait.cjs +0 -6
  885. package/dist/utils/wait.cjs.map +0 -1
  886. package/dist/utils/wait.d.cts +0 -2
  887. package/dist/utils/wait.d.cts.map +0 -1
  888. package/dist/utils/wait.d.mts +0 -2
  889. package/dist/utils/wait.d.mts.map +0 -1
  890. package/dist/utils/wait.mjs +0 -2
  891. package/dist/utils/wait.mjs.map +0 -1
@@ -0,0 +1,1152 @@
1
+ import { ExchangeClient, HttpTransport, InfoClient, SubscriptionClient, WebSocketTransport, } from '@nktkas/hyperliquid';
2
+ import { CandlePeriod, calculateCandleCount, } from '../constants/chartConfig.js';
3
+ import { HYPERLIQUID_TRANSPORT_CONFIG } from '../constants/hyperLiquidConfig.js';
4
+ import { PERFORMANCE_CONFIG, PERPS_CONSTANTS, } from '../constants/perpsConfig.js';
5
+ import { PERPS_ERROR_CODES } from '../perpsErrorCodes.js';
6
+ import { WebSocketConnectionState } from '../types/index.js';
7
+ import { coalescePerpsRestRequest } from '../utils/coalescePerpsRestRequest.js';
8
+ import { ensureError, isAbortError } from '../utils/errorUtils.js';
9
+ import { getPerpsConnectionAttemptContext } from '../utils/perpsConnectionAttemptContext.js';
10
+ /**
11
+ * Maximum number of reconnection attempts before giving up.
12
+ */
13
+ const maxReconnectionAttempts = 10;
14
+ // WebSocketConnectionState is now imported from controllers/types
15
+ // Re-export for backward compatibility with existing consumers
16
+ export { WebSocketConnectionState } from '../types/index.js';
17
+ /**
18
+ * Service for managing HyperLiquid SDK clients
19
+ * Handles initialization, transport creation, and client lifecycle
20
+ */
21
+ export class HyperLiquidClientService {
22
+ #exchangeClient;
23
+ #infoClient; // WebSocket transport (default)
24
+ #infoClientHttp; // HTTP transport (fallback)
25
+ #subscriptionClient;
26
+ #wsTransport;
27
+ #httpTransport;
28
+ #walletParams;
29
+ #isTestnet;
30
+ #connectionState = WebSocketConnectionState.Disconnected;
31
+ // Monotonic identifier for the current WebSocket connection.
32
+ //
33
+ // Incremented on every raw socket `close`, which covers SDK-internal
34
+ // automatic reconnects as well as manual teardown — the SDK reconnects
35
+ // underneath us without notifying callers, and `terminate` only fires once
36
+ // retries are exhausted. Consumers stamp cached per-connection data with the
37
+ // epoch that produced it and compare on read, so anything carried over from a
38
+ // previous socket is rejected without any explicit invalidation step.
39
+ //
40
+ // Starts at 1 so a stamp of 0 (or an unstamped default) never matches.
41
+ #connectionEpoch = 1;
42
+ #disconnectionPromise = null;
43
+ // Callback for SDK terminate event (fired when all reconnection attempts exhausted)
44
+ #onTerminateCallback = null;
45
+ #onReconnectCallback;
46
+ // Reconnection attempt counter
47
+ #reconnectionAttempt = 0;
48
+ // Connection state change listeners for event-based notifications
49
+ #connectionStateListeners = new Set();
50
+ // Timeout reference for reconnection retry, tracked to enable cancellation on disconnect
51
+ #reconnectionRetryTimeout = null;
52
+ // Platform dependencies for logging
53
+ #deps;
54
+ constructor(deps, options = {}) {
55
+ this.#deps = deps;
56
+ this.#isTestnet = options.isTestnet ?? false;
57
+ }
58
+ /**
59
+ * Initialize all HyperLiquid SDK clients
60
+ *
61
+ * IMPORTANT: This method awaits transport.ready() to ensure the WebSocket is
62
+ * in OPEN state before marking initialization complete. This prevents race
63
+ * conditions where subscriptions are attempted before the WebSocket handshake
64
+ * completes (which would cause "subscribe error: undefined" errors).
65
+ *
66
+ * @param wallet - The wallet parameters for signing typed data.
67
+ */
68
+ async initialize(wallet) {
69
+ const network = this.#isTestnet ? 'testnet' : 'mainnet';
70
+ const attemptContext = getPerpsConnectionAttemptContext();
71
+ try {
72
+ this.#updateConnectionState(WebSocketConnectionState.Connecting);
73
+ this.#walletParams = wallet;
74
+ this.#createTransports();
75
+ // Ensure transports are created
76
+ if (!this.#httpTransport || !this.#wsTransport) {
77
+ throw new Error('Failed to create transports');
78
+ }
79
+ this.#createAllClients(wallet);
80
+ // Wait for WebSocket to actually be ready before setting CONNECTED
81
+ // This ensures we have a real connection, not just client objects
82
+ await this.#wsTransport.ready();
83
+ this.#updateConnectionState(WebSocketConnectionState.Connected);
84
+ this.#deps.debugLogger.log('HyperLiquid SDK clients initialized', {
85
+ testnet: this.#isTestnet,
86
+ timestamp: new Date().toISOString(),
87
+ connectionState: this.#connectionState,
88
+ note: 'Using WebSocket for InfoClient (default), HTTP fallback available',
89
+ });
90
+ }
91
+ catch (error) {
92
+ // Cleanup on failure to prevent leaks and ensure isInitialized() returns false
93
+ // Clear clients first, then transports
94
+ this.#subscriptionClient = undefined;
95
+ this.#infoClient = undefined;
96
+ this.#infoClientHttp = undefined;
97
+ this.#exchangeClient = undefined;
98
+ // Close WebSocket transport to release resources and event listeners
99
+ if (this.#wsTransport) {
100
+ try {
101
+ this.#wsTransport.close();
102
+ }
103
+ catch {
104
+ // Ignore cleanup errors
105
+ }
106
+ this.#wsTransport = undefined;
107
+ // The transport is gone: retire its epoch so a replacement starts fresh
108
+ // and anything cached against the old connection stops matching.
109
+ this.#retireConnectionEpoch();
110
+ }
111
+ this.#httpTransport = undefined;
112
+ const errorInstance = ensureError(error, 'HyperLiquidClientService.initialize');
113
+ this.#updateConnectionState(WebSocketConnectionState.Disconnected);
114
+ if (attemptContext?.suppressError) {
115
+ this.#deps.debugLogger.log('HyperLiquid initialize failed during suppressed startup attempt', {
116
+ error: errorInstance.message,
117
+ network,
118
+ source: attemptContext.source,
119
+ });
120
+ }
121
+ else {
122
+ this.#deps.logger.error(errorInstance, {
123
+ tags: {
124
+ feature: PERPS_CONSTANTS.FeatureName,
125
+ service: 'HyperLiquidClientService',
126
+ network,
127
+ },
128
+ context: {
129
+ name: 'sdk_initialization',
130
+ data: {
131
+ operation: 'initialize',
132
+ isTestnet: this.#isTestnet,
133
+ source: attemptContext?.source ?? 'unspecified',
134
+ },
135
+ },
136
+ });
137
+ }
138
+ throw error;
139
+ }
140
+ }
141
+ /**
142
+ * Create HTTP and WebSocket transports
143
+ * - HTTP for InfoClient and ExchangeClient (request/response operations)
144
+ * - WebSocket for SubscriptionClient (real-time pub/sub)
145
+ *
146
+ * Both transports use SDK's built-in endpoint resolution via isTestnet flag
147
+ *
148
+ * @returns The created WebSocket transport instance.
149
+ */
150
+ #createTransports() {
151
+ // Prevent duplicate transport creation and listener accumulation
152
+ // This guards against re-entry if initialize() is called multiple times
153
+ // (e.g., after a failed initialization attempt that didn't properly clean up)
154
+ if (this.#wsTransport && this.#httpTransport) {
155
+ this.#deps.debugLogger.log('HyperLiquid: Transports already exist, skipping creation');
156
+ return this.#wsTransport;
157
+ }
158
+ this.#deps.debugLogger.log('HyperLiquid: Creating transports', {
159
+ isTestnet: this.#isTestnet,
160
+ timestamp: new Date().toISOString(),
161
+ note: 'SDK will auto-select endpoints based on isTestnet flag',
162
+ });
163
+ // HTTP transport for request/response operations (InfoClient, ExchangeClient)
164
+ // SDK automatically selects: mainnet (https://api.hyperliquid.xyz) or testnet (https://api.hyperliquid-testnet.xyz)
165
+ this.#httpTransport = new HttpTransport({
166
+ isTestnet: this.#isTestnet,
167
+ timeout: HYPERLIQUID_TRANSPORT_CONFIG.timeout,
168
+ });
169
+ // WebSocket transport for real-time subscriptions (SubscriptionClient)
170
+ // SDK automatically selects: mainnet (wss://api.hyperliquid.xyz/ws) or testnet (wss://api.hyperliquid-testnet.xyz/ws)
171
+ this.#wsTransport = new WebSocketTransport({
172
+ isTestnet: this.#isTestnet,
173
+ ...HYPERLIQUID_TRANSPORT_CONFIG,
174
+ reconnect: HYPERLIQUID_TRANSPORT_CONFIG.reconnect,
175
+ });
176
+ // Retire the connection epoch whenever the raw socket closes.
177
+ //
178
+ // This is the only signal that covers an SDK-internal automatic reconnect:
179
+ // the SDK reopens the socket underneath us without notifying callers, and
180
+ // `terminate` fires only once reconnection attempts are exhausted. rews
181
+ // listeners survive reconnections, so attaching once here observes every
182
+ // subsequent close. Data cached against the old epoch stops matching from
183
+ // this moment, with no invalidation call to place correctly.
184
+ //
185
+ // The listener is bound to the transport it was attached to. A retired
186
+ // transport can still emit `close` after it has been replaced — teardown is
187
+ // asynchronous — and acting on that would retire the CURRENT connection's
188
+ // epoch, discarding live positions for no reason. Replacing a transport
189
+ // retires the outgoing epoch explicitly (see #retireConnectionEpoch), so
190
+ // ignoring these late events loses nothing.
191
+ const owningTransport = this.#wsTransport;
192
+ this.#wsTransport.socket.addEventListener('close', () => {
193
+ if (this.#wsTransport !== owningTransport) {
194
+ this.#deps.debugLogger.log('HyperLiquid: ignoring close from a retired WebSocket transport', { connectionEpoch: this.#connectionEpoch });
195
+ return;
196
+ }
197
+ this.#connectionEpoch += 1;
198
+ this.#deps.debugLogger.log('HyperLiquid: WebSocket closed, epoch retired', {
199
+ connectionEpoch: this.#connectionEpoch,
200
+ });
201
+ });
202
+ // Listen for WebSocket termination (fired when SDK exhausts all reconnection attempts)
203
+ this.#wsTransport.socket.addEventListener('terminate', (event) => {
204
+ const customEvent = event;
205
+ this.#deps.debugLogger.log('HyperLiquid: WebSocket terminated', {
206
+ reason: customEvent.detail?.code,
207
+ timestamp: new Date().toISOString(),
208
+ });
209
+ this.#updateConnectionState(WebSocketConnectionState.Disconnected);
210
+ if (this.#onTerminateCallback) {
211
+ const error = customEvent.detail instanceof Error
212
+ ? customEvent.detail
213
+ : new Error(`WebSocket terminated: ${customEvent.detail?.code ?? 'unknown'}`);
214
+ this.#onTerminateCallback(error);
215
+ }
216
+ });
217
+ return this.#wsTransport;
218
+ }
219
+ /**
220
+ * Create all SDK clients using the current transports.
221
+ * Shared by initialize() and #handleConnectionDrop() to avoid drift.
222
+ *
223
+ * @param wallet - Optional wallet params. Uses stored #walletParams when omitted (reconnection path).
224
+ */
225
+ #createAllClients(wallet) {
226
+ if (!this.#wsTransport || !this.#httpTransport) {
227
+ throw new Error('Transports must be created before clients');
228
+ }
229
+ this.#infoClient = new InfoClient({ transport: this.#wsTransport });
230
+ this.#subscriptionClient = new SubscriptionClient({
231
+ transport: this.#wsTransport,
232
+ });
233
+ this.#createHttpClients(wallet);
234
+ }
235
+ /**
236
+ * Create the HTTP-backed SDK clients.
237
+ *
238
+ * @param wallet - Optional wallet params. Uses stored #walletParams when omitted.
239
+ */
240
+ #createHttpClients(wallet) {
241
+ const effectiveWallet = wallet ?? this.#walletParams;
242
+ if (!this.#httpTransport) {
243
+ throw new Error('HTTP transport must be created before clients');
244
+ }
245
+ this.#infoClientHttp = new InfoClient({ transport: this.#httpTransport });
246
+ if (effectiveWallet) {
247
+ this.#exchangeClient = new ExchangeClient({
248
+ wallet: effectiveWallet, // eslint-disable-line @typescript-eslint/no-explicit-any -- Type widening for SDK compatibility
249
+ transport: this.#httpTransport,
250
+ });
251
+ }
252
+ else {
253
+ this.#exchangeClient = undefined;
254
+ }
255
+ }
256
+ /**
257
+ * Toggle testnet mode and reinitialize clients
258
+ *
259
+ * @param wallet - The wallet parameters for signing typed data.
260
+ * @returns The new network name after toggling.
261
+ */
262
+ async toggleTestnet(wallet) {
263
+ this.#isTestnet = !this.#isTestnet;
264
+ await this.initialize(wallet);
265
+ return this.#isTestnet ? 'testnet' : 'mainnet';
266
+ }
267
+ /**
268
+ * Check if clients are properly initialized
269
+ *
270
+ * @returns True if all SDK clients are initialized.
271
+ */
272
+ isInitialized() {
273
+ return Boolean(this.#exchangeClient &&
274
+ this.#infoClient &&
275
+ this.#infoClientHttp &&
276
+ this.#subscriptionClient);
277
+ }
278
+ /**
279
+ * Ensure clients are initialized, throw if not
280
+ */
281
+ ensureInitialized() {
282
+ if (!this.isInitialized()) {
283
+ throw new Error(PERPS_ERROR_CODES.CLIENT_NOT_INITIALIZED);
284
+ }
285
+ }
286
+ /**
287
+ * Recreate subscription client if needed (for reconnection scenarios)
288
+ *
289
+ * @param wallet - The wallet parameters for signing typed data.
290
+ */
291
+ async ensureSubscriptionClient(wallet) {
292
+ if (!this.#subscriptionClient) {
293
+ // A reconnect publishes its WebSocket clients only after transport.ready().
294
+ // Do not start a competing initialize() while that attempt or its retry
295
+ // backoff is active; callers will observe an unavailable subscription
296
+ // client until the reconnect completes and restores tracked subscriptions.
297
+ if (this.#isReconnecting || this.#reconnectionRetryTimeout) {
298
+ return;
299
+ }
300
+ this.#deps.debugLogger.log('HyperLiquid: Recreating subscription client after disconnect');
301
+ if (this.#walletParams &&
302
+ this.#connectionState === WebSocketConnectionState.Disconnected) {
303
+ await this.reconnect();
304
+ }
305
+ else {
306
+ await this.initialize(wallet);
307
+ }
308
+ }
309
+ }
310
+ /**
311
+ * Get the exchange client
312
+ *
313
+ * @returns The initialized ExchangeClient instance.
314
+ */
315
+ getExchangeClient() {
316
+ if (!this.#exchangeClient) {
317
+ this.ensureInitialized();
318
+ throw new Error(PERPS_ERROR_CODES.EXCHANGE_CLIENT_NOT_AVAILABLE);
319
+ }
320
+ return this.#exchangeClient;
321
+ }
322
+ /**
323
+ * Get the info client
324
+ *
325
+ * @param options - The options for selecting the transport.
326
+ * @param options.useHttp - Force HTTP transport instead of WebSocket (default: false).
327
+ * @returns InfoClient instance with the selected transport.
328
+ */
329
+ getInfoClient(options) {
330
+ if (options?.useHttp) {
331
+ if (!this.#infoClientHttp) {
332
+ this.ensureInitialized();
333
+ throw new Error(PERPS_ERROR_CODES.INFO_CLIENT_NOT_AVAILABLE);
334
+ }
335
+ return this.#infoClientHttp;
336
+ }
337
+ this.ensureInitialized();
338
+ if (!this.#infoClient) {
339
+ throw new Error(PERPS_ERROR_CODES.INFO_CLIENT_NOT_AVAILABLE);
340
+ }
341
+ return this.#infoClient;
342
+ }
343
+ /**
344
+ * Get the subscription client
345
+ *
346
+ * @returns The SubscriptionClient instance, or undefined if not initialized.
347
+ */
348
+ getSubscriptionClient() {
349
+ if (!this.#subscriptionClient) {
350
+ this.#deps.debugLogger.log('SubscriptionClient not initialized');
351
+ return undefined;
352
+ }
353
+ return this.#subscriptionClient;
354
+ }
355
+ /**
356
+ * Ensures the WebSocket transport is in OPEN state and ready for subscriptions.
357
+ * This MUST be called before any subscription operations to prevent race conditions.
358
+ *
359
+ * The SDK's `transport.ready()` method:
360
+ * - Returns immediately if WebSocket is already in OPEN state
361
+ * - Waits for the "open" event if WebSocket is in CONNECTING state
362
+ * - Supports AbortSignal for timeout/cancellation
363
+ *
364
+ * @param options - The options for transport readiness check.
365
+ * @param options.timeoutMs - Maximum time to wait for transport ready (default 5000ms).
366
+ * @throws Error if transport not ready within timeout or subscription client unavailable.
367
+ */
368
+ async ensureTransportReady(options = {}) {
369
+ const { timeoutMs = 5000 } = options;
370
+ const subscriptionClient = this.getSubscriptionClient();
371
+ if (!subscriptionClient) {
372
+ throw new Error('Subscription client not initialized');
373
+ }
374
+ const controller = new AbortController();
375
+ const timeoutId = setTimeout(() => controller.abort(new Error(`WebSocket transport ready timeout after ${timeoutMs}ms`)), timeoutMs);
376
+ try {
377
+ await subscriptionClient.config_.transport.ready(controller.signal);
378
+ }
379
+ catch (error) {
380
+ if (controller.signal.aborted) {
381
+ throw new Error(`WebSocket transport ready timeout after ${timeoutMs}ms`);
382
+ }
383
+ throw ensureError(error, 'HyperLiquidClientService.ensureTransportReady');
384
+ }
385
+ finally {
386
+ clearTimeout(timeoutId);
387
+ }
388
+ }
389
+ /**
390
+ * Get current network state
391
+ *
392
+ * @returns The current HyperLiquid network (mainnet or testnet).
393
+ */
394
+ getNetwork() {
395
+ return this.#isTestnet ? 'testnet' : 'mainnet';
396
+ }
397
+ /**
398
+ * Check if running on testnet
399
+ *
400
+ * @returns True if the service is in testnet mode.
401
+ */
402
+ isTestnetMode() {
403
+ return this.#isTestnet;
404
+ }
405
+ /**
406
+ * Update testnet mode
407
+ *
408
+ * @param isTestnet - Whether to enable testnet mode.
409
+ */
410
+ setTestnetMode(isTestnet) {
411
+ this.#isTestnet = isTestnet;
412
+ }
413
+ /**
414
+ * Fetch historical candle data using the HyperLiquid SDK
415
+ *
416
+ * @param options - The candle fetch configuration.
417
+ * @param options.symbol - The asset symbol (e.g., "BTC", "ETH").
418
+ * @param options.interval - The candle interval (e.g., "1m", "5m", "15m", "1h", "1d").
419
+ * @param options.limit - Number of candles to fetch (default: 100).
420
+ * @param options.endTime - End timestamp in milliseconds (default: now).
421
+ * @param options.signal - Optional AbortSignal to cancel the fetch.
422
+ * @returns The historical candle data, or null if no data is available.
423
+ */
424
+ async fetchHistoricalCandles(options) {
425
+ const { symbol, interval, limit = 100, endTime, signal } = options;
426
+ if (signal?.aborted) {
427
+ const abortError = new Error('Aborted');
428
+ abortError.name = 'AbortError';
429
+ throw abortError;
430
+ }
431
+ // Explicit endTime is a paging call — the caller owns that exact window
432
+ // and expects a fresh page. Coalescing per-millisecond endTimes produces
433
+ // keys that never dedupe and never evict (TTL-miss sweep only fires on
434
+ // re-access with the same key), so route paging straight to the SDK and
435
+ // only coalesce the live-snapshot path where all callers share 'now'.
436
+ if (endTime !== undefined) {
437
+ return this.#runCandleSnapshotFetch({
438
+ symbol,
439
+ interval,
440
+ limit,
441
+ endTime,
442
+ signal,
443
+ });
444
+ }
445
+ // Live snapshot: coalesce across rapid market switches (pass 1 → pass 2
446
+ // of the 10-market stress loop) so callers share one snapshot per
447
+ // (symbol, interval).
448
+ // Signal is intentionally dropped inside the coalesced fetch — the HL
449
+ // SDK charges weight for any request already sent, and dropping a
450
+ // per-caller abort lets the next caller reuse the in-flight/cached
451
+ // result instead of re-firing the REST. The WS stream keeps live
452
+ // candles fresh, so reusing the first-caller snapshot for up to the
453
+ // TTL is acceptable.
454
+ const cacheKey = [
455
+ 'candleSnapshot',
456
+ this.#isTestnet ? 'testnet' : 'mainnet',
457
+ symbol,
458
+ interval,
459
+ limit,
460
+ ].join('|');
461
+ return coalescePerpsRestRequest(cacheKey, () => this.#runCandleSnapshotFetch({ symbol, interval, limit }), { ttlMs: PERFORMANCE_CONFIG.PerpsCandleCoalesceTtlMs });
462
+ }
463
+ async #runCandleSnapshotFetch(options) {
464
+ const { symbol, interval, limit, endTime, signal } = options;
465
+ try {
466
+ const now = endTime ?? Date.now();
467
+ const intervalMs = this.#getIntervalMilliseconds(interval);
468
+ const startTime = now - limit * intervalMs;
469
+ // Use HTTP transport for historical candle snapshots (request/response).
470
+ // This avoids the WebSocket abort race condition that causes 429s
471
+ // during rapid market switching on extension (#TAT-2954).
472
+ const infoClient = this.getInfoClient({ useHttp: true });
473
+ const request = {
474
+ coin: symbol, // Map to HyperLiquid SDK's 'coin' parameter
475
+ interval,
476
+ startTime,
477
+ endTime: now,
478
+ };
479
+ const data = signal
480
+ ? await infoClient.candleSnapshot(request, signal)
481
+ : await infoClient.candleSnapshot(request);
482
+ if (Array.isArray(data) && data.length > 0) {
483
+ const candles = data.map((candle) => ({
484
+ time: candle.t, // open time
485
+ open: candle.o.toString(),
486
+ high: candle.h.toString(),
487
+ low: candle.l.toString(),
488
+ close: candle.c.toString(),
489
+ volume: candle.v.toString(),
490
+ }));
491
+ return {
492
+ symbol,
493
+ interval,
494
+ candles,
495
+ };
496
+ }
497
+ return {
498
+ symbol,
499
+ interval,
500
+ candles: [],
501
+ };
502
+ }
503
+ catch (error) {
504
+ const errorInstance = ensureError(error, 'HyperLiquidClientService.fetchHistoricalCandles');
505
+ if (isAbortError(error)) {
506
+ throw error;
507
+ }
508
+ // Log to Sentry: prevents initial chart data load
509
+ this.#deps.logger.error(errorInstance, {
510
+ tags: {
511
+ feature: PERPS_CONSTANTS.FeatureName,
512
+ service: 'HyperLiquidClientService',
513
+ network: this.#isTestnet ? 'testnet' : 'mainnet',
514
+ },
515
+ context: {
516
+ name: 'historical_candles_api',
517
+ data: {
518
+ operation: 'fetchHistoricalCandles',
519
+ symbol,
520
+ interval,
521
+ limit,
522
+ hasEndTime: endTime !== undefined,
523
+ },
524
+ },
525
+ });
526
+ throw error;
527
+ }
528
+ }
529
+ /**
530
+ * Fetch the user's historical orders via the HyperLiquid SDK, coalesced
531
+ * across concurrent callers and cached for {@link PERFORMANCE_CONFIG.PerpsRestCoalesceTtlMs}.
532
+ *
533
+ * Both getOrders (service layer) and the getUserFills enrichment sidecar
534
+ * (fills→order-type resolution for TP/SL pills in activity) hit the same
535
+ * `historicalOrders` info-post. Routing both through this wrapper means the
536
+ * enrichment path rides the same cache as an explicit activity-page fetch,
537
+ * so rapid market switching never fires redundant HL traffic.
538
+ *
539
+ * Pass `forceRefresh: true` to bypass the coalesce cache end-to-end
540
+ * (hooks → controller → MarketDataService → provider → this method), which
541
+ * is required for pull-to-refresh to fetch fresh data from the network.
542
+ *
543
+ * @param userAddress - The user's 0x address to query.
544
+ * @param options - Optional cache-control options.
545
+ * @param options.forceRefresh - When true, bypasses the coalesce cache.
546
+ * @returns Array of historical orders, empty array on SDK null.
547
+ */
548
+ async fetchHistoricalOrders(userAddress, options) {
549
+ this.ensureInitialized();
550
+ const cacheKey = [
551
+ 'historicalOrders',
552
+ this.#isTestnet ? 'testnet' : 'mainnet',
553
+ userAddress.toLowerCase(),
554
+ ].join('|');
555
+ return coalescePerpsRestRequest(cacheKey, () => this.#runHistoricalOrdersFetch(userAddress), { forceRefresh: options?.forceRefresh });
556
+ }
557
+ async #runHistoricalOrdersFetch(userAddress) {
558
+ const infoClient = this.getInfoClient();
559
+ const result = await infoClient.historicalOrders({ user: userAddress });
560
+ return result ?? [];
561
+ }
562
+ /**
563
+ * Subscribe to candle updates via WebSocket
564
+ *
565
+ * @param root0 - The subscription parameters.
566
+ * @param root0.symbol - The asset symbol (e.g., "BTC", "ETH").
567
+ * @param root0.interval - The candle interval (e.g., "1m", "5m", "15m").
568
+ * @param root0.duration - Optional time duration for calculating initial fetch size.
569
+ * @param root0.callback - Function called with updated candle data.
570
+ * @param root0.onError - Optional function called if subscription initialization fails.
571
+ * @returns Cleanup function to unsubscribe.
572
+ */
573
+ subscribeToCandles({ symbol, interval, duration, callback, onError, }) {
574
+ this.ensureInitialized();
575
+ const subscriptionClient = this.getSubscriptionClient();
576
+ if (!subscriptionClient) {
577
+ throw new Error(PERPS_ERROR_CODES.SUBSCRIPTION_CLIENT_NOT_AVAILABLE);
578
+ }
579
+ let currentCandleData = null;
580
+ let wsUnsubscribe = null;
581
+ let isUnsubscribed = false;
582
+ let hasUnsubscribeStarted = false;
583
+ let subscriptionPromise = null;
584
+ const unsubscribeFromCandles = (subscription) => {
585
+ if (hasUnsubscribeStarted) {
586
+ return;
587
+ }
588
+ hasUnsubscribeStarted = true;
589
+ const logUnsubscribeError = (error) => {
590
+ const errorInstance = ensureError(error, 'HyperLiquidClientService.subscribeToCandles');
591
+ if (errorInstance.message.startsWith('Already unsubscribed')) {
592
+ return;
593
+ }
594
+ this.#deps.logger.error(errorInstance, {
595
+ tags: {
596
+ feature: PERPS_CONSTANTS.FeatureName,
597
+ service: 'HyperLiquidClientService',
598
+ network: this.#isTestnet ? 'testnet' : 'mainnet',
599
+ },
600
+ context: {
601
+ name: 'websocket_unsubscription',
602
+ data: {
603
+ operation: 'subscribeToCandles',
604
+ symbol,
605
+ interval,
606
+ phase: 'ws_unsubscription',
607
+ },
608
+ },
609
+ });
610
+ };
611
+ try {
612
+ Promise.resolve(subscription.unsubscribe()).catch(logUnsubscribeError);
613
+ }
614
+ catch (error) {
615
+ logUnsubscribeError(error);
616
+ }
617
+ };
618
+ // AbortController to cancel in-flight REST calls (candleSnapshot) on cleanup.
619
+ // Prevents rate limit exhaustion when rapidly switching markets (#28141).
620
+ const abortController = new AbortController();
621
+ // Calculate initial fetch size dynamically based on duration and interval
622
+ // Match main branch behavior: up to 500 candles initially
623
+ const initialLimit = duration
624
+ ? Math.min(calculateCandleCount(duration, interval), 500)
625
+ : 100; // Default to 100 if no duration provided
626
+ // 1. Fetch initial historical data, then subscribe to WebSocket updates
627
+ // Using an async IIFE to avoid nested promises and callback-in-promise issues
628
+ const initAndSubscribe = async () => {
629
+ try {
630
+ const initialData = await this.fetchHistoricalCandles({
631
+ symbol,
632
+ interval,
633
+ limit: initialLimit,
634
+ signal: abortController.signal,
635
+ });
636
+ // Don't proceed if already unsubscribed
637
+ if (isUnsubscribed) {
638
+ return;
639
+ }
640
+ currentCandleData = initialData;
641
+ if (currentCandleData) {
642
+ callback(currentCandleData);
643
+ }
644
+ // 2. Subscribe to WebSocket for new candles
645
+ // HyperLiquid SDK uses 'coin' terminology
646
+ // Store the promise so cleanup can wait for it if needed
647
+ subscriptionPromise = subscriptionClient.candle({ coin: symbol, interval }, // Map to HyperLiquid SDK's 'coin' parameter
648
+ (candleEvent) => {
649
+ // Don't process events if already unsubscribed
650
+ if (isUnsubscribed) {
651
+ return;
652
+ }
653
+ // Transform SDK CandleEvent to our Candle format
654
+ const newCandle = {
655
+ time: candleEvent.t,
656
+ open: candleEvent.o.toString(),
657
+ high: candleEvent.h.toString(),
658
+ low: candleEvent.l.toString(),
659
+ close: candleEvent.c.toString(),
660
+ volume: candleEvent.v.toString(),
661
+ };
662
+ if (currentCandleData) {
663
+ // Check if this is an update to the last candle or a new candle
664
+ const { candles } = currentCandleData;
665
+ const lastCandle = candles[candles.length - 1];
666
+ if (lastCandle?.time === newCandle.time) {
667
+ // Update existing candle (live candle update)
668
+ // Create new array with updated last element to trigger React re-render
669
+ currentCandleData = {
670
+ ...currentCandleData,
671
+ candles: [...candles.slice(0, -1), newCandle],
672
+ };
673
+ }
674
+ else {
675
+ // New candle (completed candle)
676
+ // Create new array with added element to trigger React re-render
677
+ currentCandleData = {
678
+ ...currentCandleData,
679
+ candles: [...candles, newCandle],
680
+ };
681
+ }
682
+ }
683
+ else {
684
+ currentCandleData = {
685
+ symbol,
686
+ interval,
687
+ candles: [newCandle],
688
+ };
689
+ }
690
+ callback(currentCandleData);
691
+ });
692
+ // Store cleanup function when subscription resolves
693
+ try {
694
+ const sub = await subscriptionPromise;
695
+ wsUnsubscribe = () => unsubscribeFromCandles(sub);
696
+ // If already unsubscribed while waiting, clean up immediately
697
+ if (isUnsubscribed) {
698
+ wsUnsubscribe();
699
+ wsUnsubscribe = null;
700
+ }
701
+ }
702
+ catch (error) {
703
+ const errorInstance = ensureError(error, 'HyperLiquidClientService.subscribeToCandles');
704
+ // Log to Sentry: WebSocket subscription failure prevents live updates
705
+ this.#deps.logger.error(errorInstance, {
706
+ tags: {
707
+ feature: PERPS_CONSTANTS.FeatureName,
708
+ service: 'HyperLiquidClientService',
709
+ network: this.#isTestnet ? 'testnet' : 'mainnet',
710
+ },
711
+ context: {
712
+ name: 'websocket_subscription',
713
+ data: {
714
+ operation: 'subscribeToCandles',
715
+ symbol,
716
+ interval,
717
+ phase: 'ws_subscription',
718
+ },
719
+ },
720
+ });
721
+ // Notify caller of error
722
+ onError?.(errorInstance);
723
+ }
724
+ }
725
+ catch (error) {
726
+ // Skip logging and notification for intentional abort (user navigated away)
727
+ if (abortController.signal.aborted) {
728
+ return;
729
+ }
730
+ const errorInstance = ensureError(error, 'HyperLiquidClientService.subscribeToCandles');
731
+ // Log to Sentry: initial fetch failure blocks chart completely
732
+ this.#deps.logger.error(errorInstance, {
733
+ tags: {
734
+ feature: PERPS_CONSTANTS.FeatureName,
735
+ service: 'HyperLiquidClientService',
736
+ network: this.#isTestnet ? 'testnet' : 'mainnet',
737
+ },
738
+ context: {
739
+ name: 'initial_candles_fetch',
740
+ data: {
741
+ operation: 'subscribeToCandles',
742
+ symbol,
743
+ interval,
744
+ phase: 'initial_fetch',
745
+ initialLimit,
746
+ },
747
+ },
748
+ });
749
+ // Notify caller of error
750
+ onError?.(errorInstance);
751
+ }
752
+ };
753
+ // Fire-and-forget the async initialization
754
+ initAndSubscribe().catch(() => {
755
+ // Error already handled inside initAndSubscribe
756
+ });
757
+ // Return cleanup function
758
+ return () => {
759
+ isUnsubscribed = true;
760
+ // Cancel any in-flight REST calls (candleSnapshot) to conserve rate limit budget (#28141)
761
+ abortController.abort();
762
+ if (wsUnsubscribe) {
763
+ // Subscription already resolved - unsubscribe directly
764
+ wsUnsubscribe();
765
+ wsUnsubscribe = null;
766
+ }
767
+ else if (subscriptionPromise) {
768
+ // Subscription promise still pending - wait for it and clean up
769
+ // This prevents WebSocket subscription leaks when component unmounts
770
+ // before the subscription promise resolves
771
+ subscriptionPromise
772
+ .then((sub) => unsubscribeFromCandles(sub))
773
+ .catch(() => {
774
+ // Ignore errors during cleanup - subscription may have failed
775
+ });
776
+ subscriptionPromise = null;
777
+ }
778
+ };
779
+ }
780
+ /**
781
+ * Convert interval string to milliseconds
782
+ *
783
+ * @param interval - The candle period interval to convert.
784
+ * @returns The interval duration in milliseconds.
785
+ */
786
+ #getIntervalMilliseconds(interval) {
787
+ const intervalMap = {
788
+ [CandlePeriod.OneMinute]: 1 * 60 * 1000,
789
+ [CandlePeriod.ThreeMinutes]: 3 * 60 * 1000,
790
+ [CandlePeriod.FiveMinutes]: 5 * 60 * 1000,
791
+ [CandlePeriod.FifteenMinutes]: 15 * 60 * 1000,
792
+ [CandlePeriod.ThirtyMinutes]: 30 * 60 * 1000,
793
+ [CandlePeriod.OneHour]: 60 * 60 * 1000,
794
+ [CandlePeriod.TwoHours]: 2 * 60 * 60 * 1000,
795
+ [CandlePeriod.FourHours]: 4 * 60 * 60 * 1000,
796
+ [CandlePeriod.EightHours]: 8 * 60 * 60 * 1000,
797
+ [CandlePeriod.TwelveHours]: 12 * 60 * 60 * 1000,
798
+ [CandlePeriod.OneDay]: 24 * 60 * 60 * 1000,
799
+ [CandlePeriod.ThreeDays]: 3 * 24 * 60 * 60 * 1000,
800
+ [CandlePeriod.OneWeek]: 7 * 24 * 60 * 60 * 1000,
801
+ [CandlePeriod.OneMonth]: 30 * 24 * 60 * 60 * 1000, // Approximate
802
+ };
803
+ return intervalMap[interval];
804
+ }
805
+ /**
806
+ * Disconnect and cleanup all clients
807
+ *
808
+ * @returns A promise that resolves when disconnection is complete.
809
+ */
810
+ async disconnect() {
811
+ // Await existing promise if already disconnecting
812
+ if (this.#disconnectionPromise) {
813
+ await this.#disconnectionPromise;
814
+ return;
815
+ }
816
+ // If already disconnected, return immediately
817
+ if (this.#connectionState === WebSocketConnectionState.Disconnected) {
818
+ return;
819
+ }
820
+ // Create and store the disconnection promise
821
+ this.#disconnectionPromise = this.#performDisconnection();
822
+ try {
823
+ await this.#disconnectionPromise;
824
+ }
825
+ finally {
826
+ this.#disconnectionPromise = null;
827
+ }
828
+ }
829
+ async #performDisconnection() {
830
+ try {
831
+ this.#updateConnectionState(WebSocketConnectionState.Disconnecting);
832
+ this.#deps.debugLogger.log('HyperLiquid: Disconnecting SDK clients', {
833
+ isTestnet: this.#isTestnet,
834
+ timestamp: new Date().toISOString(),
835
+ connectionState: this.#connectionState,
836
+ });
837
+ // Clear callbacks
838
+ this.#onReconnectCallback = undefined;
839
+ this.#onTerminateCallback = null;
840
+ // Cancel any pending reconnection retry timeout
841
+ if (this.#reconnectionRetryTimeout) {
842
+ clearTimeout(this.#reconnectionRetryTimeout);
843
+ this.#reconnectionRetryTimeout = null;
844
+ }
845
+ // Clear connection state listeners to prevent stale callbacks
846
+ this.#connectionStateListeners.clear();
847
+ // Reset reconnection flag to allow future manual retries
848
+ // This prevents a race condition where disconnecting during an active
849
+ // reconnection attempt could leave the flag stuck, blocking subsequent retries
850
+ this.#isReconnecting = false;
851
+ // Close WebSocket transport only (HTTP is stateless)
852
+ if (this.#wsTransport) {
853
+ try {
854
+ this.#wsTransport.close();
855
+ this.#deps.debugLogger.log('HyperLiquid: Closed WebSocket transport', {
856
+ timestamp: new Date().toISOString(),
857
+ });
858
+ }
859
+ catch (error) {
860
+ this.#deps.logger.error(ensureError(error, 'HyperLiquidClientService.performDisconnection'), {
861
+ tags: { feature: PERPS_CONSTANTS.FeatureName },
862
+ context: {
863
+ name: 'HyperLiquidClientService.performDisconnection',
864
+ data: { action: 'close_transport' },
865
+ },
866
+ });
867
+ }
868
+ }
869
+ // Clear client references
870
+ this.#subscriptionClient = undefined;
871
+ this.#exchangeClient = undefined;
872
+ this.#infoClient = undefined;
873
+ this.#infoClientHttp = undefined;
874
+ this.#wsTransport = undefined;
875
+ // The transport is gone: retire its epoch so a replacement starts fresh
876
+ // and anything cached against the old connection stops matching.
877
+ this.#retireConnectionEpoch();
878
+ this.#httpTransport = undefined;
879
+ this.#updateConnectionState(WebSocketConnectionState.Disconnected);
880
+ this.#deps.debugLogger.log('HyperLiquid: SDK clients fully disconnected', {
881
+ timestamp: new Date().toISOString(),
882
+ connectionState: this.#connectionState,
883
+ });
884
+ }
885
+ catch (error) {
886
+ this.#updateConnectionState(WebSocketConnectionState.Disconnected);
887
+ this.#deps.logger.error(ensureError(error, 'HyperLiquidClientService.performDisconnection'), {
888
+ tags: { feature: PERPS_CONSTANTS.FeatureName },
889
+ context: {
890
+ name: 'HyperLiquidClientService.performDisconnection',
891
+ data: { action: 'outer_catch' },
892
+ },
893
+ });
894
+ throw error;
895
+ }
896
+ }
897
+ /**
898
+ * Get current WebSocket connection state
899
+ *
900
+ * @returns The current WebSocket connection state.
901
+ */
902
+ getConnectionState() {
903
+ return this.#connectionState;
904
+ }
905
+ /**
906
+ * Get the identifier of the current WebSocket connection.
907
+ *
908
+ * The value changes whenever the raw socket closes — including an SDK-internal
909
+ * automatic reconnect, which is otherwise invisible to callers. Stamp cached
910
+ * per-connection data with the epoch that produced it and compare on read:
911
+ * anything carried across a reconnect stops matching on its own, so there is
912
+ * no invalidation hook that can be attached at the wrong lifecycle point.
913
+ *
914
+ * @returns The current connection epoch. Never 0, so an unstamped default
915
+ * cannot be mistaken for a live connection.
916
+ */
917
+ getConnectionEpoch() {
918
+ return this.#connectionEpoch;
919
+ }
920
+ /**
921
+ * Retire the current connection epoch.
922
+ *
923
+ * Called when the WebSocket transport is discarded, so a replacement starts on
924
+ * a fresh epoch and everything cached against the old connection stops
925
+ * matching. The socket's own `close` listener cannot be relied on here: it may
926
+ * fire after the transport has already been replaced, at which point it is
927
+ * ignored precisely so it cannot retire the new connection's epoch.
928
+ *
929
+ * Retiring twice for one connection is harmless — the epoch is an identity,
930
+ * not a count — so callers do not need to know whether `close` already fired.
931
+ */
932
+ #retireConnectionEpoch() {
933
+ this.#connectionEpoch += 1;
934
+ this.#deps.debugLogger.log('HyperLiquid: connection epoch retired', {
935
+ connectionEpoch: this.#connectionEpoch,
936
+ });
937
+ }
938
+ /**
939
+ * Check if WebSocket is fully disconnected
940
+ *
941
+ * @returns True if the WebSocket is in disconnected state.
942
+ */
943
+ isDisconnected() {
944
+ return this.#connectionState === WebSocketConnectionState.Disconnected;
945
+ }
946
+ /**
947
+ * Set callback to be invoked when reconnection is needed
948
+ * This allows the service to notify external components (like PerpsConnectionManager)
949
+ * when a connection drop is detected
950
+ *
951
+ * @param callback - The async callback to invoke when reconnection is needed.
952
+ */
953
+ setOnReconnectCallback(callback) {
954
+ this.#onReconnectCallback = callback;
955
+ }
956
+ /**
957
+ * Set callback for WebSocket termination events
958
+ * Called when the SDK exhausts all reconnection attempts
959
+ *
960
+ * @param callback - The callback to invoke on termination, or null to clear.
961
+ */
962
+ setOnTerminateCallback(callback) {
963
+ this.#onTerminateCallback = callback;
964
+ }
965
+ /**
966
+ * Subscribe to connection state changes.
967
+ * The listener will be called immediately with the current state and whenever the state changes.
968
+ *
969
+ * @param listener - Callback function that receives the new connection state and reconnection attempt
970
+ * @returns Unsubscribe function to remove the listener
971
+ */
972
+ subscribeToConnectionState(listener) {
973
+ this.#connectionStateListeners.add(listener);
974
+ // Immediately notify with current state
975
+ // Wrap in try-catch to match notifyConnectionStateListeners behavior
976
+ // This ensures the unsubscribe function is always returned even if listener throws
977
+ try {
978
+ listener(this.#connectionState, this.#reconnectionAttempt);
979
+ }
980
+ catch {
981
+ // Ignore errors in listeners to prevent breaking subscription mechanism
982
+ // If listener throws, it will be removed when unsubscribe is called
983
+ }
984
+ // Return unsubscribe function
985
+ return () => {
986
+ this.#connectionStateListeners.delete(listener);
987
+ };
988
+ }
989
+ /**
990
+ * Update connection state and notify all listeners
991
+ * Always notifies if state changes OR if we're in CONNECTING state (to update attempt count)
992
+ *
993
+ * @param newState - The new WebSocket connection state.
994
+ */
995
+ #updateConnectionState(newState) {
996
+ const previousState = this.#connectionState;
997
+ const stateChanged = previousState !== newState;
998
+ const isReconnectionAttempt = newState === WebSocketConnectionState.Connecting &&
999
+ this.#reconnectionAttempt > 0;
1000
+ this.#connectionState = newState;
1001
+ // Reset reconnection attempt counter when successfully connected
1002
+ if (newState === WebSocketConnectionState.Connected) {
1003
+ this.#reconnectionAttempt = 0;
1004
+ }
1005
+ // Notify if state changed OR if this is a reconnection attempt (to update attempt count)
1006
+ if (stateChanged || isReconnectionAttempt) {
1007
+ this.#notifyConnectionStateListeners();
1008
+ }
1009
+ }
1010
+ /**
1011
+ * Notify all connection state listeners of the current state
1012
+ */
1013
+ #notifyConnectionStateListeners() {
1014
+ this.#connectionStateListeners.forEach((listener) => {
1015
+ try {
1016
+ listener(this.#connectionState, this.#reconnectionAttempt);
1017
+ }
1018
+ catch {
1019
+ // Ignore errors in listeners to prevent breaking other listeners
1020
+ }
1021
+ });
1022
+ }
1023
+ // Flag to prevent concurrent reconnection attempts
1024
+ #isReconnecting = false;
1025
+ /**
1026
+ * Manually trigger a reconnection attempt.
1027
+ * This is exposed for UI retry buttons when user wants to force reconnection.
1028
+ * Resets the reconnection attempt counter to allow retrying after max attempts.
1029
+ */
1030
+ async reconnect() {
1031
+ this.#deps.debugLogger.log('[HyperLiquidClientService] reconnect() called', {
1032
+ previousAttempt: this.#reconnectionAttempt,
1033
+ currentState: this.#connectionState,
1034
+ });
1035
+ // Reset attempt counter when user manually triggers retry
1036
+ this.#reconnectionAttempt = 0;
1037
+ await this.#handleConnectionDrop();
1038
+ this.#deps.debugLogger.log('[HyperLiquidClientService] reconnect() completed', {
1039
+ newState: this.#connectionState,
1040
+ });
1041
+ }
1042
+ /**
1043
+ * Handle detected connection drop
1044
+ * Recreates WebSocket transport and notifies callback to restore subscriptions
1045
+ * Will give up after maxReconnectionAttempts and mark status as disconnected
1046
+ */
1047
+ async #handleConnectionDrop() {
1048
+ // Prevent multiple simultaneous reconnection attempts
1049
+ if (this.#isReconnecting) {
1050
+ return;
1051
+ }
1052
+ this.#isReconnecting = true;
1053
+ // Increment reconnection attempt counter
1054
+ this.#reconnectionAttempt += 1;
1055
+ // Check if we've exceeded max retry attempts
1056
+ if (this.#reconnectionAttempt > maxReconnectionAttempts) {
1057
+ this.#isReconnecting = false;
1058
+ this.#updateConnectionState(WebSocketConnectionState.Disconnected);
1059
+ return;
1060
+ }
1061
+ try {
1062
+ this.#updateConnectionState(WebSocketConnectionState.Connecting);
1063
+ // Close existing WebSocket transport and clear references
1064
+ // so createTransports() will create fresh ones
1065
+ if (this.#wsTransport) {
1066
+ try {
1067
+ this.#wsTransport.close();
1068
+ }
1069
+ catch {
1070
+ // Ignore errors during close - transport may already be dead
1071
+ }
1072
+ }
1073
+ this.#wsTransport = undefined;
1074
+ // The transport is gone: retire its epoch so a replacement starts fresh
1075
+ // and anything cached against the old connection stops matching.
1076
+ this.#retireConnectionEpoch();
1077
+ this.#httpTransport = undefined;
1078
+ // WebSocket clients are unavailable throughout the reconnect. HTTP
1079
+ // clients remain usable while the new socket is staged and verified.
1080
+ this.#subscriptionClient = undefined;
1081
+ this.#infoClient = undefined;
1082
+ // Recreate transports (both WS and HTTP)
1083
+ const newWsTransport = this.#createTransports();
1084
+ const newInfoClient = new InfoClient({ transport: newWsTransport });
1085
+ const newSubscriptionClient = new SubscriptionClient({
1086
+ transport: newWsTransport,
1087
+ });
1088
+ this.#createHttpClients();
1089
+ await newWsTransport.ready();
1090
+ // Publish WebSocket clients only after the transport is usable. This
1091
+ // keeps isInitialized() false and blocks WS-backed access during a
1092
+ // failed or in-flight reconnect without disabling HTTP-backed trading.
1093
+ this.#infoClient = newInfoClient;
1094
+ this.#subscriptionClient = newSubscriptionClient;
1095
+ this.#deps.debugLogger.log('HyperLiquid: Transport ready, restoring subscriptions', { timestamp: new Date().toISOString() });
1096
+ // NOW safe to restore subscriptions
1097
+ if (this.#onReconnectCallback) {
1098
+ await this.#onReconnectCallback();
1099
+ }
1100
+ // Cancel any pending retry timeout from previous failed attempts
1101
+ if (this.#reconnectionRetryTimeout) {
1102
+ clearTimeout(this.#reconnectionRetryTimeout);
1103
+ this.#reconnectionRetryTimeout = null;
1104
+ }
1105
+ this.#updateConnectionState(WebSocketConnectionState.Connected);
1106
+ this.#isReconnecting = false;
1107
+ }
1108
+ catch {
1109
+ // The staged WebSocket clients were never published. Keep the HTTP
1110
+ // clients alive so exchange writes and explicit HTTP info reads remain
1111
+ // available while the WebSocket retry loop continues.
1112
+ this.#subscriptionClient = undefined;
1113
+ this.#infoClient = undefined;
1114
+ if (this.#wsTransport) {
1115
+ try {
1116
+ this.#wsTransport.close();
1117
+ }
1118
+ catch {
1119
+ // Ignore cleanup errors - transport may already be dead
1120
+ }
1121
+ }
1122
+ this.#wsTransport = undefined;
1123
+ // The transport is gone: retire its epoch so a replacement starts fresh
1124
+ // and anything cached against the old connection stops matching.
1125
+ this.#retireConnectionEpoch();
1126
+ // Reset flag before scheduling retry so the next attempt can proceed
1127
+ this.#isReconnecting = false;
1128
+ // Check if we've exceeded max retry attempts
1129
+ if (this.#reconnectionAttempt >= maxReconnectionAttempts) {
1130
+ this.#updateConnectionState(WebSocketConnectionState.Disconnected);
1131
+ return;
1132
+ }
1133
+ // Reconnection failed - schedule a retry after a delay
1134
+ // Store timeout reference so it can be cancelled on intentional disconnect
1135
+ this.#reconnectionRetryTimeout = setTimeout(() => {
1136
+ this.#reconnectionRetryTimeout = null; // Clear reference after execution
1137
+ // Only retry if we haven't been intentionally disconnected
1138
+ // and no manual reconnect() is already in progress
1139
+ // Note: State may be CONNECTING or DISCONNECTED (if terminate event fired during reconnect)
1140
+ if ((this.#connectionState === WebSocketConnectionState.Connecting ||
1141
+ this.#connectionState === WebSocketConnectionState.Disconnected) &&
1142
+ !this.#disconnectionPromise &&
1143
+ !this.#isReconnecting) {
1144
+ this.#handleConnectionDrop().catch(() => {
1145
+ // Error already handled inside #handleConnectionDrop
1146
+ });
1147
+ }
1148
+ }, PERPS_CONSTANTS.ReconnectionRetryDelayMs);
1149
+ }
1150
+ }
1151
+ }
1152
+ //# sourceMappingURL=HyperLiquidClientService.js.map