@metamask-previews/perps-controller 0.0.0-preview-685dbf46b → 1.0.0-preview-bc00f2c

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 (482) hide show
  1. package/CHANGELOG.md +30 -2
  2. package/dist/PerpsController.cjs +3077 -65
  3. package/dist/PerpsController.cjs.map +1 -1
  4. package/dist/PerpsController.d.cts +969 -82
  5. package/dist/PerpsController.d.cts.map +1 -1
  6. package/dist/PerpsController.d.mts +969 -82
  7. package/dist/PerpsController.d.mts.map +1 -1
  8. package/dist/PerpsController.mjs +3073 -62
  9. package/dist/PerpsController.mjs.map +1 -1
  10. package/dist/aggregation/SubscriptionMultiplexer.cjs +441 -0
  11. package/dist/aggregation/SubscriptionMultiplexer.cjs.map +1 -0
  12. package/dist/aggregation/SubscriptionMultiplexer.d.cts +171 -0
  13. package/dist/aggregation/SubscriptionMultiplexer.d.cts.map +1 -0
  14. package/dist/aggregation/SubscriptionMultiplexer.d.mts +171 -0
  15. package/dist/aggregation/SubscriptionMultiplexer.d.mts.map +1 -0
  16. package/dist/aggregation/SubscriptionMultiplexer.mjs +437 -0
  17. package/dist/aggregation/SubscriptionMultiplexer.mjs.map +1 -0
  18. package/dist/aggregation/index.cjs +9 -0
  19. package/dist/aggregation/index.cjs.map +1 -0
  20. package/dist/aggregation/index.d.cts +6 -0
  21. package/dist/aggregation/index.d.cts.map +1 -0
  22. package/dist/aggregation/index.d.mts +6 -0
  23. package/dist/aggregation/index.d.mts.map +1 -0
  24. package/dist/aggregation/index.mjs +5 -0
  25. package/dist/aggregation/index.mjs.map +1 -0
  26. package/dist/constants/chartConfig.cjs +227 -0
  27. package/dist/constants/chartConfig.cjs.map +1 -0
  28. package/dist/constants/chartConfig.d.cts +216 -0
  29. package/dist/constants/chartConfig.d.cts.map +1 -0
  30. package/dist/constants/chartConfig.d.mts +216 -0
  31. package/dist/constants/chartConfig.d.mts.map +1 -0
  32. package/dist/constants/chartConfig.mjs +221 -0
  33. package/dist/constants/chartConfig.mjs.map +1 -0
  34. package/dist/constants/eventNames.cjs +436 -0
  35. package/dist/constants/eventNames.cjs.map +1 -0
  36. package/dist/constants/eventNames.d.cts +387 -0
  37. package/dist/constants/eventNames.d.cts.map +1 -0
  38. package/dist/constants/eventNames.d.mts +387 -0
  39. package/dist/constants/eventNames.d.mts.map +1 -0
  40. package/dist/constants/eventNames.mjs +433 -0
  41. package/dist/constants/eventNames.mjs.map +1 -0
  42. package/dist/constants/hyperLiquidConfig.cjs +380 -0
  43. package/dist/constants/hyperLiquidConfig.cjs.map +1 -0
  44. package/dist/constants/hyperLiquidConfig.d.cts +236 -0
  45. package/dist/constants/hyperLiquidConfig.d.cts.map +1 -0
  46. package/dist/constants/hyperLiquidConfig.d.mts +236 -0
  47. package/dist/constants/hyperLiquidConfig.d.mts.map +1 -0
  48. package/dist/constants/hyperLiquidConfig.mjs +371 -0
  49. package/dist/constants/hyperLiquidConfig.mjs.map +1 -0
  50. package/dist/constants/index.cjs +28 -0
  51. package/dist/constants/index.cjs.map +1 -0
  52. package/dist/constants/index.d.cts +12 -0
  53. package/dist/constants/index.d.cts.map +1 -0
  54. package/dist/constants/index.d.mts +12 -0
  55. package/dist/constants/index.d.mts.map +1 -0
  56. package/dist/constants/index.mjs +12 -0
  57. package/dist/constants/index.mjs.map +1 -0
  58. package/dist/constants/myxConfig.cjs +229 -0
  59. package/dist/constants/myxConfig.cjs.map +1 -0
  60. package/dist/constants/myxConfig.d.cts +106 -0
  61. package/dist/constants/myxConfig.d.cts.map +1 -0
  62. package/dist/constants/myxConfig.d.mts +106 -0
  63. package/dist/constants/myxConfig.d.mts.map +1 -0
  64. package/dist/constants/myxConfig.mjs +219 -0
  65. package/dist/constants/myxConfig.mjs.map +1 -0
  66. package/dist/constants/orderTypes.cjs +31 -0
  67. package/dist/constants/orderTypes.cjs.map +1 -0
  68. package/dist/constants/orderTypes.d.cts +19 -0
  69. package/dist/constants/orderTypes.d.cts.map +1 -0
  70. package/dist/constants/orderTypes.d.mts +19 -0
  71. package/dist/constants/orderTypes.d.mts.map +1 -0
  72. package/dist/constants/orderTypes.mjs +27 -0
  73. package/dist/constants/orderTypes.mjs.map +1 -0
  74. package/dist/constants/performanceMetrics.cjs +63 -0
  75. package/dist/constants/performanceMetrics.cjs.map +1 -0
  76. package/dist/constants/performanceMetrics.d.cts +46 -0
  77. package/dist/constants/performanceMetrics.d.cts.map +1 -0
  78. package/dist/constants/performanceMetrics.d.mts +46 -0
  79. package/dist/constants/performanceMetrics.d.mts.map +1 -0
  80. package/dist/constants/performanceMetrics.mjs +60 -0
  81. package/dist/constants/performanceMetrics.mjs.map +1 -0
  82. package/dist/constants/perpsConfig.cjs +295 -0
  83. package/dist/constants/perpsConfig.cjs.map +1 -0
  84. package/dist/constants/perpsConfig.d.cts +221 -0
  85. package/dist/constants/perpsConfig.d.cts.map +1 -0
  86. package/dist/constants/perpsConfig.d.mts +221 -0
  87. package/dist/constants/perpsConfig.d.mts.map +1 -0
  88. package/dist/constants/perpsConfig.mjs +292 -0
  89. package/dist/constants/perpsConfig.mjs.map +1 -0
  90. package/dist/constants/transactionsHistoryConfig.cjs +19 -0
  91. package/dist/constants/transactionsHistoryConfig.cjs.map +1 -0
  92. package/dist/constants/transactionsHistoryConfig.d.cts +16 -0
  93. package/dist/constants/transactionsHistoryConfig.d.cts.map +1 -0
  94. package/dist/constants/transactionsHistoryConfig.d.mts +16 -0
  95. package/dist/constants/transactionsHistoryConfig.d.mts.map +1 -0
  96. package/dist/constants/transactionsHistoryConfig.mjs +16 -0
  97. package/dist/constants/transactionsHistoryConfig.mjs.map +1 -0
  98. package/dist/index.cjs +63 -1
  99. package/dist/index.cjs.map +1 -1
  100. package/dist/index.d.cts +38 -2
  101. package/dist/index.d.cts.map +1 -1
  102. package/dist/index.d.mts +38 -2
  103. package/dist/index.d.mts.map +1 -1
  104. package/dist/index.mjs +46 -1
  105. package/dist/index.mjs.map +1 -1
  106. package/dist/perpsErrorCodes.cjs +80 -0
  107. package/dist/perpsErrorCodes.cjs.map +1 -0
  108. package/dist/perpsErrorCodes.d.cts +65 -0
  109. package/dist/perpsErrorCodes.d.cts.map +1 -0
  110. package/dist/perpsErrorCodes.d.mts +65 -0
  111. package/dist/perpsErrorCodes.d.mts.map +1 -0
  112. package/dist/perpsErrorCodes.mjs +77 -0
  113. package/dist/perpsErrorCodes.mjs.map +1 -0
  114. package/dist/providers/AggregatedPerpsProvider.cjs +508 -0
  115. package/dist/providers/AggregatedPerpsProvider.cjs.map +1 -0
  116. package/dist/providers/AggregatedPerpsProvider.d.cts +171 -0
  117. package/dist/providers/AggregatedPerpsProvider.d.cts.map +1 -0
  118. package/dist/providers/AggregatedPerpsProvider.d.mts +171 -0
  119. package/dist/providers/AggregatedPerpsProvider.d.mts.map +1 -0
  120. package/dist/providers/AggregatedPerpsProvider.mjs +504 -0
  121. package/dist/providers/AggregatedPerpsProvider.mjs.map +1 -0
  122. package/dist/providers/HyperLiquidProvider.cjs +5679 -0
  123. package/dist/providers/HyperLiquidProvider.cjs.map +1 -0
  124. package/dist/providers/HyperLiquidProvider.d.cts +516 -0
  125. package/dist/providers/HyperLiquidProvider.d.cts.map +1 -0
  126. package/dist/providers/HyperLiquidProvider.d.mts +516 -0
  127. package/dist/providers/HyperLiquidProvider.d.mts.map +1 -0
  128. package/dist/providers/HyperLiquidProvider.mjs +5675 -0
  129. package/dist/providers/HyperLiquidProvider.mjs.map +1 -0
  130. package/dist/providers/MYXProvider.cjs +514 -0
  131. package/dist/providers/MYXProvider.cjs.map +1 -0
  132. package/dist/providers/MYXProvider.d.cts +105 -0
  133. package/dist/providers/MYXProvider.d.cts.map +1 -0
  134. package/dist/providers/MYXProvider.d.mts +105 -0
  135. package/dist/providers/MYXProvider.d.mts.map +1 -0
  136. package/dist/providers/MYXProvider.mjs +510 -0
  137. package/dist/providers/MYXProvider.mjs.map +1 -0
  138. package/dist/routing/ProviderRouter.cjs +154 -0
  139. package/dist/routing/ProviderRouter.cjs.map +1 -0
  140. package/dist/routing/ProviderRouter.d.cts +112 -0
  141. package/dist/routing/ProviderRouter.d.cts.map +1 -0
  142. package/dist/routing/ProviderRouter.d.mts +112 -0
  143. package/dist/routing/ProviderRouter.d.mts.map +1 -0
  144. package/dist/routing/ProviderRouter.mjs +150 -0
  145. package/dist/routing/ProviderRouter.mjs.map +1 -0
  146. package/dist/routing/index.cjs +9 -0
  147. package/dist/routing/index.cjs.map +1 -0
  148. package/dist/routing/index.d.cts +6 -0
  149. package/dist/routing/index.d.cts.map +1 -0
  150. package/dist/routing/index.d.mts +6 -0
  151. package/dist/routing/index.d.mts.map +1 -0
  152. package/dist/routing/index.mjs +5 -0
  153. package/dist/routing/index.mjs.map +1 -0
  154. package/dist/selectors.cjs +166 -0
  155. package/dist/selectors.cjs.map +1 -0
  156. package/dist/selectors.d.cts +362 -0
  157. package/dist/selectors.d.cts.map +1 -0
  158. package/dist/selectors.d.mts +362 -0
  159. package/dist/selectors.d.mts.map +1 -0
  160. package/dist/selectors.mjs +158 -0
  161. package/dist/selectors.mjs.map +1 -0
  162. package/dist/services/AccountService.cjs +324 -0
  163. package/dist/services/AccountService.cjs.map +1 -0
  164. package/dist/services/AccountService.d.cts +56 -0
  165. package/dist/services/AccountService.d.cts.map +1 -0
  166. package/dist/services/AccountService.d.mts +56 -0
  167. package/dist/services/AccountService.d.mts.map +1 -0
  168. package/dist/services/AccountService.mjs +320 -0
  169. package/dist/services/AccountService.mjs.map +1 -0
  170. package/dist/services/DataLakeService.cjs +233 -0
  171. package/dist/services/DataLakeService.cjs.map +1 -0
  172. package/dist/services/DataLakeService.d.cts +51 -0
  173. package/dist/services/DataLakeService.d.cts.map +1 -0
  174. package/dist/services/DataLakeService.d.mts +51 -0
  175. package/dist/services/DataLakeService.d.mts.map +1 -0
  176. package/dist/services/DataLakeService.mjs +229 -0
  177. package/dist/services/DataLakeService.mjs.map +1 -0
  178. package/dist/services/DepositService.cjs +98 -0
  179. package/dist/services/DepositService.cjs.map +1 -0
  180. package/dist/services/DepositService.d.cts +39 -0
  181. package/dist/services/DepositService.d.cts.map +1 -0
  182. package/dist/services/DepositService.d.mts +39 -0
  183. package/dist/services/DepositService.d.mts.map +1 -0
  184. package/dist/services/DepositService.mjs +94 -0
  185. package/dist/services/DepositService.mjs.map +1 -0
  186. package/dist/services/EligibilityService.cjs +173 -0
  187. package/dist/services/EligibilityService.cjs.map +1 -0
  188. package/dist/services/EligibilityService.d.cts +39 -0
  189. package/dist/services/EligibilityService.d.cts.map +1 -0
  190. package/dist/services/EligibilityService.d.mts +39 -0
  191. package/dist/services/EligibilityService.d.mts.map +1 -0
  192. package/dist/services/EligibilityService.mjs +169 -0
  193. package/dist/services/EligibilityService.mjs.map +1 -0
  194. package/dist/services/FeatureFlagConfigurationService.cjs +257 -0
  195. package/dist/services/FeatureFlagConfigurationService.cjs.map +1 -0
  196. package/dist/services/FeatureFlagConfigurationService.d.cts +73 -0
  197. package/dist/services/FeatureFlagConfigurationService.d.cts.map +1 -0
  198. package/dist/services/FeatureFlagConfigurationService.d.mts +73 -0
  199. package/dist/services/FeatureFlagConfigurationService.d.mts.map +1 -0
  200. package/dist/services/FeatureFlagConfigurationService.mjs +253 -0
  201. package/dist/services/FeatureFlagConfigurationService.mjs.map +1 -0
  202. package/dist/services/HyperLiquidClientService.cjs +867 -0
  203. package/dist/services/HyperLiquidClientService.cjs.map +1 -0
  204. package/dist/services/HyperLiquidClientService.d.cts +214 -0
  205. package/dist/services/HyperLiquidClientService.d.cts.map +1 -0
  206. package/dist/services/HyperLiquidClientService.d.mts +214 -0
  207. package/dist/services/HyperLiquidClientService.d.mts.map +1 -0
  208. package/dist/services/HyperLiquidClientService.mjs +862 -0
  209. package/dist/services/HyperLiquidClientService.mjs.map +1 -0
  210. package/dist/services/HyperLiquidSubscriptionService.cjs +2199 -0
  211. package/dist/services/HyperLiquidSubscriptionService.cjs.map +1 -0
  212. package/dist/services/HyperLiquidSubscriptionService.d.cts +187 -0
  213. package/dist/services/HyperLiquidSubscriptionService.d.cts.map +1 -0
  214. package/dist/services/HyperLiquidSubscriptionService.d.mts +187 -0
  215. package/dist/services/HyperLiquidSubscriptionService.d.mts.map +1 -0
  216. package/dist/services/HyperLiquidSubscriptionService.mjs +2195 -0
  217. package/dist/services/HyperLiquidSubscriptionService.mjs.map +1 -0
  218. package/dist/services/HyperLiquidWalletService.cjs +163 -0
  219. package/dist/services/HyperLiquidWalletService.cjs.map +1 -0
  220. package/dist/services/HyperLiquidWalletService.d.cts +78 -0
  221. package/dist/services/HyperLiquidWalletService.d.cts.map +1 -0
  222. package/dist/services/HyperLiquidWalletService.d.mts +78 -0
  223. package/dist/services/HyperLiquidWalletService.d.mts.map +1 -0
  224. package/dist/services/HyperLiquidWalletService.mjs +159 -0
  225. package/dist/services/HyperLiquidWalletService.mjs.map +1 -0
  226. package/dist/services/MYXClientService.cjs +304 -0
  227. package/dist/services/MYXClientService.cjs.map +1 -0
  228. package/dist/services/MYXClientService.d.cts +81 -0
  229. package/dist/services/MYXClientService.d.cts.map +1 -0
  230. package/dist/services/MYXClientService.d.mts +81 -0
  231. package/dist/services/MYXClientService.d.mts.map +1 -0
  232. package/dist/services/MYXClientService.mjs +300 -0
  233. package/dist/services/MYXClientService.mjs.map +1 -0
  234. package/dist/services/MarketDataService.cjs +848 -0
  235. package/dist/services/MarketDataService.cjs.map +1 -0
  236. package/dist/services/MarketDataService.d.cts +291 -0
  237. package/dist/services/MarketDataService.d.cts.map +1 -0
  238. package/dist/services/MarketDataService.d.mts +291 -0
  239. package/dist/services/MarketDataService.d.mts.map +1 -0
  240. package/dist/services/MarketDataService.mjs +844 -0
  241. package/dist/services/MarketDataService.mjs.map +1 -0
  242. package/dist/services/RewardsIntegrationService.cjs +120 -0
  243. package/dist/services/RewardsIntegrationService.cjs.map +1 -0
  244. package/dist/services/RewardsIntegrationService.d.cts +28 -0
  245. package/dist/services/RewardsIntegrationService.d.cts.map +1 -0
  246. package/dist/services/RewardsIntegrationService.d.mts +28 -0
  247. package/dist/services/RewardsIntegrationService.d.mts.map +1 -0
  248. package/dist/services/RewardsIntegrationService.mjs +116 -0
  249. package/dist/services/RewardsIntegrationService.mjs.map +1 -0
  250. package/dist/services/ServiceContext.cjs +3 -0
  251. package/dist/services/ServiceContext.cjs.map +1 -0
  252. package/dist/services/ServiceContext.d.cts +86 -0
  253. package/dist/services/ServiceContext.d.cts.map +1 -0
  254. package/dist/services/ServiceContext.d.mts +86 -0
  255. package/dist/services/ServiceContext.d.mts.map +1 -0
  256. package/dist/services/ServiceContext.mjs +2 -0
  257. package/dist/services/ServiceContext.mjs.map +1 -0
  258. package/dist/services/TradingReadinessCache.cjs +288 -0
  259. package/dist/services/TradingReadinessCache.cjs.map +1 -0
  260. package/dist/services/TradingReadinessCache.d.cts +174 -0
  261. package/dist/services/TradingReadinessCache.d.cts.map +1 -0
  262. package/dist/services/TradingReadinessCache.d.mts +174 -0
  263. package/dist/services/TradingReadinessCache.d.mts.map +1 -0
  264. package/dist/services/TradingReadinessCache.mjs +285 -0
  265. package/dist/services/TradingReadinessCache.mjs.map +1 -0
  266. package/dist/services/TradingService.cjs +1457 -0
  267. package/dist/services/TradingService.cjs.map +1 -0
  268. package/dist/services/TradingService.d.cts +195 -0
  269. package/dist/services/TradingService.d.cts.map +1 -0
  270. package/dist/services/TradingService.d.mts +195 -0
  271. package/dist/services/TradingService.d.mts.map +1 -0
  272. package/dist/services/TradingService.mjs +1453 -0
  273. package/dist/services/TradingService.mjs.map +1 -0
  274. package/dist/types/config.cjs +3 -0
  275. package/dist/types/config.cjs.map +1 -0
  276. package/dist/types/config.d.cts +49 -0
  277. package/dist/types/config.d.cts.map +1 -0
  278. package/dist/types/config.d.mts +49 -0
  279. package/dist/types/config.d.mts.map +1 -0
  280. package/dist/types/config.mjs +2 -0
  281. package/dist/types/config.mjs.map +1 -0
  282. package/dist/types/hyperliquid-types.cjs +3 -0
  283. package/dist/types/hyperliquid-types.cjs.map +1 -0
  284. package/dist/types/hyperliquid-types.d.cts +20 -0
  285. package/dist/types/hyperliquid-types.d.cts.map +1 -0
  286. package/dist/types/hyperliquid-types.d.mts +20 -0
  287. package/dist/types/hyperliquid-types.d.mts.map +1 -0
  288. package/dist/types/hyperliquid-types.mjs +2 -0
  289. package/dist/types/hyperliquid-types.mjs.map +1 -0
  290. package/dist/types/index.cjs +115 -0
  291. package/dist/types/index.cjs.map +1 -0
  292. package/dist/types/index.d.cts +1262 -0
  293. package/dist/types/index.d.cts.map +1 -0
  294. package/dist/types/index.d.mts +1262 -0
  295. package/dist/types/index.d.mts.map +1 -0
  296. package/dist/types/index.mjs +97 -0
  297. package/dist/types/index.mjs.map +1 -0
  298. package/dist/types/messenger.cjs +3 -0
  299. package/dist/types/messenger.cjs.map +1 -0
  300. package/dist/types/messenger.d.cts +27 -0
  301. package/dist/types/messenger.d.cts.map +1 -0
  302. package/dist/types/messenger.d.mts +27 -0
  303. package/dist/types/messenger.d.mts.map +1 -0
  304. package/dist/types/messenger.mjs +2 -0
  305. package/dist/types/messenger.mjs.map +1 -0
  306. package/dist/types/myx-types.cjs +25 -0
  307. package/dist/types/myx-types.cjs.map +1 -0
  308. package/dist/types/myx-types.d.cts +63 -0
  309. package/dist/types/myx-types.d.cts.map +1 -0
  310. package/dist/types/myx-types.d.mts +63 -0
  311. package/dist/types/myx-types.d.mts.map +1 -0
  312. package/dist/types/myx-types.mjs +22 -0
  313. package/dist/types/myx-types.mjs.map +1 -0
  314. package/dist/types/perps-types.cjs +4 -0
  315. package/dist/types/perps-types.cjs.map +1 -0
  316. package/dist/types/perps-types.d.cts +105 -0
  317. package/dist/types/perps-types.d.cts.map +1 -0
  318. package/dist/types/perps-types.d.mts +105 -0
  319. package/dist/types/perps-types.d.mts.map +1 -0
  320. package/dist/types/perps-types.mjs +2 -0
  321. package/dist/types/perps-types.mjs.map +1 -0
  322. package/dist/types/token.cjs +3 -0
  323. package/dist/types/token.cjs.map +1 -0
  324. package/dist/types/token.d.cts +25 -0
  325. package/dist/types/token.d.cts.map +1 -0
  326. package/dist/types/token.d.mts +25 -0
  327. package/dist/types/token.d.mts.map +1 -0
  328. package/dist/types/token.mjs +2 -0
  329. package/dist/types/token.mjs.map +1 -0
  330. package/dist/types/transactionTypes.cjs +28 -0
  331. package/dist/types/transactionTypes.cjs.map +1 -0
  332. package/dist/types/transactionTypes.d.cts +64 -0
  333. package/dist/types/transactionTypes.d.cts.map +1 -0
  334. package/dist/types/transactionTypes.d.mts +64 -0
  335. package/dist/types/transactionTypes.d.mts.map +1 -0
  336. package/dist/types/transactionTypes.mjs +23 -0
  337. package/dist/types/transactionTypes.mjs.map +1 -0
  338. package/dist/utils/accountUtils.cjs +100 -0
  339. package/dist/utils/accountUtils.cjs.map +1 -0
  340. package/dist/utils/accountUtils.d.cts +30 -0
  341. package/dist/utils/accountUtils.d.cts.map +1 -0
  342. package/dist/utils/accountUtils.d.mts +30 -0
  343. package/dist/utils/accountUtils.d.mts.map +1 -0
  344. package/dist/utils/accountUtils.mjs +92 -0
  345. package/dist/utils/accountUtils.mjs.map +1 -0
  346. package/dist/utils/errorUtils.cjs +35 -0
  347. package/dist/utils/errorUtils.cjs.map +1 -0
  348. package/dist/utils/errorUtils.d.cts +15 -0
  349. package/dist/utils/errorUtils.d.cts.map +1 -0
  350. package/dist/utils/errorUtils.d.mts +15 -0
  351. package/dist/utils/errorUtils.d.mts.map +1 -0
  352. package/dist/utils/errorUtils.mjs +31 -0
  353. package/dist/utils/errorUtils.mjs.map +1 -0
  354. package/dist/utils/hyperLiquidAdapter.cjs +331 -0
  355. package/dist/utils/hyperLiquidAdapter.cjs.map +1 -0
  356. package/dist/utils/hyperLiquidAdapter.d.cts +42 -0
  357. package/dist/utils/hyperLiquidAdapter.d.cts.map +1 -0
  358. package/dist/utils/hyperLiquidAdapter.d.mts +42 -0
  359. package/dist/utils/hyperLiquidAdapter.d.mts.map +1 -0
  360. package/dist/utils/hyperLiquidAdapter.mjs +316 -0
  361. package/dist/utils/hyperLiquidAdapter.mjs.map +1 -0
  362. package/dist/utils/hyperLiquidOrderBookProcessor.cjs +83 -0
  363. package/dist/utils/hyperLiquidOrderBookProcessor.cjs.map +1 -0
  364. package/dist/utils/hyperLiquidOrderBookProcessor.d.cts +55 -0
  365. package/dist/utils/hyperLiquidOrderBookProcessor.d.cts.map +1 -0
  366. package/dist/utils/hyperLiquidOrderBookProcessor.d.mts +55 -0
  367. package/dist/utils/hyperLiquidOrderBookProcessor.d.mts.map +1 -0
  368. package/dist/utils/hyperLiquidOrderBookProcessor.mjs +78 -0
  369. package/dist/utils/hyperLiquidOrderBookProcessor.mjs.map +1 -0
  370. package/dist/utils/hyperLiquidValidation.cjs +426 -0
  371. package/dist/utils/hyperLiquidValidation.cjs.map +1 -0
  372. package/dist/utils/hyperLiquidValidation.d.cts +143 -0
  373. package/dist/utils/hyperLiquidValidation.d.cts.map +1 -0
  374. package/dist/utils/hyperLiquidValidation.d.mts +143 -0
  375. package/dist/utils/hyperLiquidValidation.d.mts.map +1 -0
  376. package/dist/utils/hyperLiquidValidation.mjs +413 -0
  377. package/dist/utils/hyperLiquidValidation.mjs.map +1 -0
  378. package/dist/utils/idUtils.cjs +18 -0
  379. package/dist/utils/idUtils.cjs.map +1 -0
  380. package/dist/utils/idUtils.d.cts +6 -0
  381. package/dist/utils/idUtils.d.cts.map +1 -0
  382. package/dist/utils/idUtils.d.mts +6 -0
  383. package/dist/utils/idUtils.d.mts.map +1 -0
  384. package/dist/utils/idUtils.mjs +10 -0
  385. package/dist/utils/idUtils.mjs.map +1 -0
  386. package/dist/utils/index.cjs +59 -0
  387. package/dist/utils/index.cjs.map +1 -0
  388. package/dist/utils/index.d.cts +25 -0
  389. package/dist/utils/index.d.cts.map +1 -0
  390. package/dist/utils/index.d.mts +25 -0
  391. package/dist/utils/index.d.mts.map +1 -0
  392. package/dist/utils/index.mjs +30 -0
  393. package/dist/utils/index.mjs.map +1 -0
  394. package/dist/utils/marketDataTransform.cjs +211 -0
  395. package/dist/utils/marketDataTransform.cjs.map +1 -0
  396. package/dist/utils/marketDataTransform.d.cts +40 -0
  397. package/dist/utils/marketDataTransform.d.cts.map +1 -0
  398. package/dist/utils/marketDataTransform.d.mts +40 -0
  399. package/dist/utils/marketDataTransform.d.mts.map +1 -0
  400. package/dist/utils/marketDataTransform.mjs +205 -0
  401. package/dist/utils/marketDataTransform.mjs.map +1 -0
  402. package/dist/utils/marketUtils.cjs +151 -0
  403. package/dist/utils/marketUtils.cjs.map +1 -0
  404. package/dist/utils/marketUtils.d.cts +30 -0
  405. package/dist/utils/marketUtils.d.cts.map +1 -0
  406. package/dist/utils/marketUtils.d.mts +30 -0
  407. package/dist/utils/marketUtils.d.mts.map +1 -0
  408. package/dist/utils/marketUtils.mjs +138 -0
  409. package/dist/utils/marketUtils.mjs.map +1 -0
  410. package/dist/utils/myxAdapter.cjs +224 -0
  411. package/dist/utils/myxAdapter.cjs.map +1 -0
  412. package/dist/utils/myxAdapter.d.cts +81 -0
  413. package/dist/utils/myxAdapter.d.cts.map +1 -0
  414. package/dist/utils/myxAdapter.d.mts +81 -0
  415. package/dist/utils/myxAdapter.d.mts.map +1 -0
  416. package/dist/utils/myxAdapter.mjs +213 -0
  417. package/dist/utils/myxAdapter.mjs.map +1 -0
  418. package/dist/utils/orderCalculations.cjs +283 -0
  419. package/dist/utils/orderCalculations.cjs.map +1 -0
  420. package/dist/utils/orderCalculations.d.cts +107 -0
  421. package/dist/utils/orderCalculations.d.cts.map +1 -0
  422. package/dist/utils/orderCalculations.d.mts +107 -0
  423. package/dist/utils/orderCalculations.d.mts.map +1 -0
  424. package/dist/utils/orderCalculations.mjs +274 -0
  425. package/dist/utils/orderCalculations.mjs.map +1 -0
  426. package/dist/utils/rewardsUtils.cjs +98 -0
  427. package/dist/utils/rewardsUtils.cjs.map +1 -0
  428. package/dist/utils/rewardsUtils.d.cts +33 -0
  429. package/dist/utils/rewardsUtils.d.cts.map +1 -0
  430. package/dist/utils/rewardsUtils.d.mts +33 -0
  431. package/dist/utils/rewardsUtils.d.mts.map +1 -0
  432. package/dist/utils/rewardsUtils.mjs +92 -0
  433. package/dist/utils/rewardsUtils.mjs.map +1 -0
  434. package/dist/utils/significantFigures.cjs +88 -0
  435. package/dist/utils/significantFigures.cjs.map +1 -0
  436. package/dist/utils/significantFigures.d.cts +25 -0
  437. package/dist/utils/significantFigures.d.cts.map +1 -0
  438. package/dist/utils/significantFigures.d.mts +25 -0
  439. package/dist/utils/significantFigures.d.mts.map +1 -0
  440. package/dist/utils/significantFigures.mjs +82 -0
  441. package/dist/utils/significantFigures.mjs.map +1 -0
  442. package/dist/utils/sortMarkets.cjs +93 -0
  443. package/dist/utils/sortMarkets.cjs.map +1 -0
  444. package/dist/utils/sortMarkets.d.cts +27 -0
  445. package/dist/utils/sortMarkets.d.cts.map +1 -0
  446. package/dist/utils/sortMarkets.d.mts +27 -0
  447. package/dist/utils/sortMarkets.d.mts.map +1 -0
  448. package/dist/utils/sortMarkets.mjs +88 -0
  449. package/dist/utils/sortMarkets.mjs.map +1 -0
  450. package/dist/utils/standaloneInfoClient.cjs +70 -0
  451. package/dist/utils/standaloneInfoClient.cjs.map +1 -0
  452. package/dist/utils/standaloneInfoClient.d.cts +37 -0
  453. package/dist/utils/standaloneInfoClient.d.cts.map +1 -0
  454. package/dist/utils/standaloneInfoClient.d.mts +37 -0
  455. package/dist/utils/standaloneInfoClient.d.mts.map +1 -0
  456. package/dist/utils/standaloneInfoClient.mjs +64 -0
  457. package/dist/utils/standaloneInfoClient.mjs.map +1 -0
  458. package/dist/utils/stringParseUtils.cjs +18 -0
  459. package/dist/utils/stringParseUtils.cjs.map +1 -0
  460. package/dist/utils/stringParseUtils.d.cts +3 -0
  461. package/dist/utils/stringParseUtils.d.cts.map +1 -0
  462. package/dist/utils/stringParseUtils.d.mts +3 -0
  463. package/dist/utils/stringParseUtils.d.mts.map +1 -0
  464. package/dist/utils/stringParseUtils.mjs +13 -0
  465. package/dist/utils/stringParseUtils.mjs.map +1 -0
  466. package/dist/utils/transferData.cjs +33 -0
  467. package/dist/utils/transferData.cjs.map +1 -0
  468. package/dist/utils/transferData.d.cts +9 -0
  469. package/dist/utils/transferData.d.cts.map +1 -0
  470. package/dist/utils/transferData.d.mts +9 -0
  471. package/dist/utils/transferData.d.mts.map +1 -0
  472. package/dist/utils/transferData.mjs +29 -0
  473. package/dist/utils/transferData.mjs.map +1 -0
  474. package/dist/utils/wait.cjs +6 -0
  475. package/dist/utils/wait.cjs.map +1 -0
  476. package/dist/utils/wait.d.cts +2 -0
  477. package/dist/utils/wait.d.cts.map +1 -0
  478. package/dist/utils/wait.d.mts +2 -0
  479. package/dist/utils/wait.d.mts.map +1 -0
  480. package/dist/utils/wait.mjs +2 -0
  481. package/dist/utils/wait.mjs.map +1 -0
  482. package/package.json +16 -2
@@ -0,0 +1,862 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _HyperLiquidClientService_instances, _HyperLiquidClientService_exchangeClient, _HyperLiquidClientService_infoClient, _HyperLiquidClientService_infoClientHttp, _HyperLiquidClientService_subscriptionClient, _HyperLiquidClientService_wsTransport, _HyperLiquidClientService_httpTransport, _HyperLiquidClientService_isTestnet, _HyperLiquidClientService_connectionState, _HyperLiquidClientService_disconnectionPromise, _HyperLiquidClientService_onTerminateCallback, _HyperLiquidClientService_onReconnectCallback, _HyperLiquidClientService_reconnectionAttempt, _HyperLiquidClientService_connectionStateListeners, _HyperLiquidClientService_reconnectionRetryTimeout, _HyperLiquidClientService_deps, _HyperLiquidClientService_createTransports, _HyperLiquidClientService_getIntervalMilliseconds, _HyperLiquidClientService_performDisconnection, _HyperLiquidClientService_updateConnectionState, _HyperLiquidClientService_notifyConnectionStateListeners, _HyperLiquidClientService_isReconnecting, _HyperLiquidClientService_handleConnectionDrop;
13
+ import { ExchangeClient, HttpTransport, InfoClient, SubscriptionClient, WebSocketTransport } from "@nktkas/hyperliquid";
14
+ import { CandlePeriod, calculateCandleCount } from "../constants/chartConfig.mjs";
15
+ import { HYPERLIQUID_TRANSPORT_CONFIG } from "../constants/hyperLiquidConfig.mjs";
16
+ import { PERPS_CONSTANTS } from "../constants/perpsConfig.mjs";
17
+ import { PERPS_ERROR_CODES } from "../perpsErrorCodes.mjs";
18
+ import { WebSocketConnectionState } from "../types/index.mjs";
19
+ import { ensureError } from "../utils/errorUtils.mjs";
20
+ /**
21
+ * Maximum number of reconnection attempts before giving up.
22
+ */
23
+ const maxReconnectionAttempts = 10;
24
+ // WebSocketConnectionState is now imported from controllers/types
25
+ // Re-export for backward compatibility with existing consumers
26
+ export { WebSocketConnectionState } from "../types/index.mjs";
27
+ /**
28
+ * Service for managing HyperLiquid SDK clients
29
+ * Handles initialization, transport creation, and client lifecycle
30
+ */
31
+ export class HyperLiquidClientService {
32
+ constructor(deps, options = {}) {
33
+ _HyperLiquidClientService_instances.add(this);
34
+ _HyperLiquidClientService_exchangeClient.set(this, void 0);
35
+ _HyperLiquidClientService_infoClient.set(this, void 0); // WebSocket transport (default)
36
+ _HyperLiquidClientService_infoClientHttp.set(this, void 0); // HTTP transport (fallback)
37
+ _HyperLiquidClientService_subscriptionClient.set(this, void 0);
38
+ _HyperLiquidClientService_wsTransport.set(this, void 0);
39
+ _HyperLiquidClientService_httpTransport.set(this, void 0);
40
+ _HyperLiquidClientService_isTestnet.set(this, void 0);
41
+ _HyperLiquidClientService_connectionState.set(this, WebSocketConnectionState.Disconnected);
42
+ _HyperLiquidClientService_disconnectionPromise.set(this, null);
43
+ // Callback for SDK terminate event (fired when all reconnection attempts exhausted)
44
+ _HyperLiquidClientService_onTerminateCallback.set(this, null);
45
+ _HyperLiquidClientService_onReconnectCallback.set(this, void 0);
46
+ // Reconnection attempt counter
47
+ _HyperLiquidClientService_reconnectionAttempt.set(this, 0);
48
+ // Connection state change listeners for event-based notifications
49
+ _HyperLiquidClientService_connectionStateListeners.set(this, new Set());
50
+ // Timeout reference for reconnection retry, tracked to enable cancellation on disconnect
51
+ _HyperLiquidClientService_reconnectionRetryTimeout.set(this, null);
52
+ // Platform dependencies for logging
53
+ _HyperLiquidClientService_deps.set(this, void 0);
54
+ // Flag to prevent concurrent reconnection attempts
55
+ _HyperLiquidClientService_isReconnecting.set(this, false);
56
+ __classPrivateFieldSet(this, _HyperLiquidClientService_deps, deps, "f");
57
+ __classPrivateFieldSet(this, _HyperLiquidClientService_isTestnet, options.isTestnet ?? false, "f");
58
+ }
59
+ /**
60
+ * Initialize all HyperLiquid SDK clients
61
+ *
62
+ * IMPORTANT: This method awaits transport.ready() to ensure the WebSocket is
63
+ * in OPEN state before marking initialization complete. This prevents race
64
+ * conditions where subscriptions are attempted before the WebSocket handshake
65
+ * completes (which would cause "subscribe error: undefined" errors).
66
+ *
67
+ * @param wallet - The wallet parameters for signing typed data.
68
+ */
69
+ async initialize(wallet) {
70
+ try {
71
+ __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Connecting);
72
+ __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_createTransports).call(this);
73
+ // Ensure transports are created
74
+ if (!__classPrivateFieldGet(this, _HyperLiquidClientService_httpTransport, "f") || !__classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f")) {
75
+ throw new Error('Failed to create transports');
76
+ }
77
+ // Wallet adapter implements AbstractViemJsonRpcAccount interface with signTypedData method
78
+ // ExchangeClient uses HTTP transport for write operations (orders, approvals, etc.)
79
+ __classPrivateFieldSet(this, _HyperLiquidClientService_exchangeClient, new ExchangeClient({
80
+ wallet: wallet, // eslint-disable-line @typescript-eslint/no-explicit-any -- Type widening for SDK compatibility
81
+ transport: __classPrivateFieldGet(this, _HyperLiquidClientService_httpTransport, "f"),
82
+ }), "f");
83
+ // InfoClient with WebSocket transport (default) - multiplexed requests over single connection
84
+ __classPrivateFieldSet(this, _HyperLiquidClientService_infoClient, new InfoClient({ transport: __classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f") }), "f");
85
+ // InfoClient with HTTP transport (fallback) - for specific calls if WebSocket has issues
86
+ __classPrivateFieldSet(this, _HyperLiquidClientService_infoClientHttp, new InfoClient({ transport: __classPrivateFieldGet(this, _HyperLiquidClientService_httpTransport, "f") }), "f");
87
+ // SubscriptionClient uses WebSocket transport for real-time pub/sub (price feeds, position updates)
88
+ __classPrivateFieldSet(this, _HyperLiquidClientService_subscriptionClient, new SubscriptionClient({
89
+ transport: __classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f"),
90
+ }), "f");
91
+ // Wait for WebSocket to actually be ready before setting CONNECTED
92
+ // This ensures we have a real connection, not just client objects
93
+ await __classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f").ready();
94
+ __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Connected);
95
+ __classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('HyperLiquid SDK clients initialized', {
96
+ testnet: __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f"),
97
+ timestamp: new Date().toISOString(),
98
+ connectionState: __classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f"),
99
+ note: 'Using WebSocket for InfoClient (default), HTTP fallback available',
100
+ });
101
+ }
102
+ catch (error) {
103
+ // Cleanup on failure to prevent leaks and ensure isInitialized() returns false
104
+ // Clear clients first, then transports
105
+ __classPrivateFieldSet(this, _HyperLiquidClientService_subscriptionClient, undefined, "f");
106
+ __classPrivateFieldSet(this, _HyperLiquidClientService_infoClient, undefined, "f");
107
+ __classPrivateFieldSet(this, _HyperLiquidClientService_infoClientHttp, undefined, "f");
108
+ __classPrivateFieldSet(this, _HyperLiquidClientService_exchangeClient, undefined, "f");
109
+ // Close WebSocket transport to release resources and event listeners
110
+ if (__classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f")) {
111
+ try {
112
+ await __classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f").close();
113
+ }
114
+ catch {
115
+ // Ignore cleanup errors
116
+ }
117
+ __classPrivateFieldSet(this, _HyperLiquidClientService_wsTransport, undefined, "f");
118
+ }
119
+ __classPrivateFieldSet(this, _HyperLiquidClientService_httpTransport, undefined, "f");
120
+ const errorInstance = ensureError(error, 'HyperLiquidClientService.initialize');
121
+ __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Disconnected);
122
+ // Log to Sentry: initialization failure blocks all Perps functionality
123
+ __classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").logger.error(errorInstance, {
124
+ tags: {
125
+ feature: PERPS_CONSTANTS.FeatureName,
126
+ service: 'HyperLiquidClientService',
127
+ network: __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f") ? 'testnet' : 'mainnet',
128
+ },
129
+ context: {
130
+ name: 'sdk_initialization',
131
+ data: {
132
+ operation: 'initialize',
133
+ isTestnet: __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f"),
134
+ },
135
+ },
136
+ });
137
+ throw error;
138
+ }
139
+ }
140
+ /**
141
+ * Toggle testnet mode and reinitialize clients
142
+ *
143
+ * @param wallet - The wallet parameters for signing typed data.
144
+ * @returns The new network name after toggling.
145
+ */
146
+ async toggleTestnet(wallet) {
147
+ __classPrivateFieldSet(this, _HyperLiquidClientService_isTestnet, !__classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f"), "f");
148
+ await this.initialize(wallet);
149
+ return __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f") ? 'testnet' : 'mainnet';
150
+ }
151
+ /**
152
+ * Check if clients are properly initialized
153
+ *
154
+ * @returns True if all SDK clients are initialized.
155
+ */
156
+ isInitialized() {
157
+ return Boolean(__classPrivateFieldGet(this, _HyperLiquidClientService_exchangeClient, "f") &&
158
+ __classPrivateFieldGet(this, _HyperLiquidClientService_infoClient, "f") &&
159
+ __classPrivateFieldGet(this, _HyperLiquidClientService_infoClientHttp, "f") &&
160
+ __classPrivateFieldGet(this, _HyperLiquidClientService_subscriptionClient, "f"));
161
+ }
162
+ /**
163
+ * Ensure clients are initialized, throw if not
164
+ */
165
+ ensureInitialized() {
166
+ if (!this.isInitialized()) {
167
+ throw new Error(PERPS_ERROR_CODES.CLIENT_NOT_INITIALIZED);
168
+ }
169
+ }
170
+ /**
171
+ * Recreate subscription client if needed (for reconnection scenarios)
172
+ *
173
+ * @param wallet - The wallet parameters for signing typed data.
174
+ */
175
+ async ensureSubscriptionClient(wallet) {
176
+ if (!__classPrivateFieldGet(this, _HyperLiquidClientService_subscriptionClient, "f")) {
177
+ __classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('HyperLiquid: Recreating subscription client after disconnect');
178
+ await this.initialize(wallet);
179
+ }
180
+ }
181
+ /**
182
+ * Get the exchange client
183
+ *
184
+ * @returns The initialized ExchangeClient instance.
185
+ */
186
+ getExchangeClient() {
187
+ this.ensureInitialized();
188
+ if (!__classPrivateFieldGet(this, _HyperLiquidClientService_exchangeClient, "f")) {
189
+ throw new Error(PERPS_ERROR_CODES.EXCHANGE_CLIENT_NOT_AVAILABLE);
190
+ }
191
+ return __classPrivateFieldGet(this, _HyperLiquidClientService_exchangeClient, "f");
192
+ }
193
+ /**
194
+ * Get the info client
195
+ *
196
+ * @param options - The options for selecting the transport.
197
+ * @param options.useHttp - Force HTTP transport instead of WebSocket (default: false).
198
+ * @returns InfoClient instance with the selected transport.
199
+ */
200
+ getInfoClient(options) {
201
+ this.ensureInitialized();
202
+ if (options?.useHttp) {
203
+ if (!__classPrivateFieldGet(this, _HyperLiquidClientService_infoClientHttp, "f")) {
204
+ throw new Error(PERPS_ERROR_CODES.INFO_CLIENT_NOT_AVAILABLE);
205
+ }
206
+ return __classPrivateFieldGet(this, _HyperLiquidClientService_infoClientHttp, "f");
207
+ }
208
+ if (!__classPrivateFieldGet(this, _HyperLiquidClientService_infoClient, "f")) {
209
+ throw new Error(PERPS_ERROR_CODES.INFO_CLIENT_NOT_AVAILABLE);
210
+ }
211
+ return __classPrivateFieldGet(this, _HyperLiquidClientService_infoClient, "f");
212
+ }
213
+ /**
214
+ * Get the subscription client
215
+ *
216
+ * @returns The SubscriptionClient instance, or undefined if not initialized.
217
+ */
218
+ getSubscriptionClient() {
219
+ if (!__classPrivateFieldGet(this, _HyperLiquidClientService_subscriptionClient, "f")) {
220
+ __classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('SubscriptionClient not initialized');
221
+ return undefined;
222
+ }
223
+ return __classPrivateFieldGet(this, _HyperLiquidClientService_subscriptionClient, "f");
224
+ }
225
+ /**
226
+ * Ensures the WebSocket transport is in OPEN state and ready for subscriptions.
227
+ * This MUST be called before any subscription operations to prevent race conditions.
228
+ *
229
+ * The SDK's `transport.ready()` method:
230
+ * - Returns immediately if WebSocket is already in OPEN state
231
+ * - Waits for the "open" event if WebSocket is in CONNECTING state
232
+ * - Supports AbortSignal for timeout/cancellation
233
+ *
234
+ * @param options - The options for transport readiness check.
235
+ * @param options.timeoutMs - Maximum time to wait for transport ready (default 5000ms).
236
+ * @throws Error if transport not ready within timeout or subscription client unavailable.
237
+ */
238
+ async ensureTransportReady(options = {}) {
239
+ const { timeoutMs = 5000 } = options;
240
+ const subscriptionClient = this.getSubscriptionClient();
241
+ if (!subscriptionClient) {
242
+ throw new Error('Subscription client not initialized');
243
+ }
244
+ const controller = new AbortController();
245
+ const timeoutId = setTimeout(() => controller.abort(new Error(`WebSocket transport ready timeout after ${timeoutMs}ms`)), timeoutMs);
246
+ try {
247
+ await subscriptionClient.config_.transport.ready(controller.signal);
248
+ }
249
+ catch (error) {
250
+ if (controller.signal.aborted) {
251
+ throw new Error(`WebSocket transport ready timeout after ${timeoutMs}ms`);
252
+ }
253
+ throw ensureError(error, 'HyperLiquidClientService.ensureTransportReady');
254
+ }
255
+ finally {
256
+ clearTimeout(timeoutId);
257
+ }
258
+ }
259
+ /**
260
+ * Get current network state
261
+ *
262
+ * @returns The current HyperLiquid network (mainnet or testnet).
263
+ */
264
+ getNetwork() {
265
+ return __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f") ? 'testnet' : 'mainnet';
266
+ }
267
+ /**
268
+ * Check if running on testnet
269
+ *
270
+ * @returns True if the service is in testnet mode.
271
+ */
272
+ isTestnetMode() {
273
+ return __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f");
274
+ }
275
+ /**
276
+ * Update testnet mode
277
+ *
278
+ * @param isTestnet - Whether to enable testnet mode.
279
+ */
280
+ setTestnetMode(isTestnet) {
281
+ __classPrivateFieldSet(this, _HyperLiquidClientService_isTestnet, isTestnet, "f");
282
+ }
283
+ /**
284
+ * Fetch historical candle data using the HyperLiquid SDK
285
+ *
286
+ * @param options - The candle fetch configuration.
287
+ * @param options.symbol - The asset symbol (e.g., "BTC", "ETH").
288
+ * @param options.interval - The candle interval (e.g., "1m", "5m", "15m", "1h", "1d").
289
+ * @param options.limit - Number of candles to fetch (default: 100).
290
+ * @param options.endTime - End timestamp in milliseconds (default: now).
291
+ * @returns The historical candle data, or null if no data is available.
292
+ */
293
+ async fetchHistoricalCandles(options) {
294
+ const { symbol, interval, limit = 100, endTime } = options;
295
+ this.ensureInitialized();
296
+ try {
297
+ // Calculate start and end times based on interval and limit
298
+ const now = endTime ?? Date.now();
299
+ const intervalMs = __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_getIntervalMilliseconds).call(this, interval);
300
+ const startTime = now - limit * intervalMs;
301
+ // Use the SDK's InfoClient to fetch candle data
302
+ // HyperLiquid SDK uses 'coin' terminology
303
+ const infoClient = this.getInfoClient();
304
+ const data = await infoClient.candleSnapshot({
305
+ coin: symbol, // Map to HyperLiquid SDK's 'coin' parameter
306
+ interval,
307
+ startTime,
308
+ endTime: now,
309
+ });
310
+ // Transform API response to match expected format
311
+ if (Array.isArray(data) && data.length > 0) {
312
+ const candles = data.map((candle) => ({
313
+ time: candle.t, // open time
314
+ open: candle.o.toString(),
315
+ high: candle.h.toString(),
316
+ low: candle.l.toString(),
317
+ close: candle.c.toString(),
318
+ volume: candle.v.toString(),
319
+ }));
320
+ return {
321
+ symbol,
322
+ interval,
323
+ candles,
324
+ };
325
+ }
326
+ return {
327
+ symbol,
328
+ interval,
329
+ candles: [],
330
+ };
331
+ }
332
+ catch (error) {
333
+ const errorInstance = ensureError(error, 'HyperLiquidClientService.fetchHistoricalCandles');
334
+ // Log to Sentry: prevents initial chart data load
335
+ __classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").logger.error(errorInstance, {
336
+ tags: {
337
+ feature: PERPS_CONSTANTS.FeatureName,
338
+ service: 'HyperLiquidClientService',
339
+ network: __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f") ? 'testnet' : 'mainnet',
340
+ },
341
+ context: {
342
+ name: 'historical_candles_api',
343
+ data: {
344
+ operation: 'fetchHistoricalCandles',
345
+ symbol,
346
+ interval,
347
+ limit,
348
+ hasEndTime: endTime !== undefined,
349
+ },
350
+ },
351
+ });
352
+ throw error;
353
+ }
354
+ }
355
+ /**
356
+ * Subscribe to candle updates via WebSocket
357
+ *
358
+ * @param root0 - The subscription parameters.
359
+ * @param root0.symbol - The asset symbol (e.g., "BTC", "ETH").
360
+ * @param root0.interval - The candle interval (e.g., "1m", "5m", "15m").
361
+ * @param root0.duration - Optional time duration for calculating initial fetch size.
362
+ * @param root0.callback - Function called with updated candle data.
363
+ * @param root0.onError - Optional function called if subscription initialization fails.
364
+ * @returns Cleanup function to unsubscribe.
365
+ */
366
+ subscribeToCandles({ symbol, interval, duration, callback, onError, }) {
367
+ this.ensureInitialized();
368
+ const subscriptionClient = this.getSubscriptionClient();
369
+ if (!subscriptionClient) {
370
+ throw new Error(PERPS_ERROR_CODES.SUBSCRIPTION_CLIENT_NOT_AVAILABLE);
371
+ }
372
+ let currentCandleData = null;
373
+ let wsUnsubscribe = null;
374
+ let isUnsubscribed = false;
375
+ // Store the subscription promise to enable cleanup even when pending
376
+ // This fixes a race condition where component unmounts before subscription resolves
377
+ let subscriptionPromise = null;
378
+ // Calculate initial fetch size dynamically based on duration and interval
379
+ // Match main branch behavior: up to 500 candles initially
380
+ const initialLimit = duration
381
+ ? Math.min(calculateCandleCount(duration, interval), 500)
382
+ : 100; // Default to 100 if no duration provided
383
+ // 1. Fetch initial historical data, then subscribe to WebSocket updates
384
+ // Using an async IIFE to avoid nested promises and callback-in-promise issues
385
+ const initAndSubscribe = async () => {
386
+ try {
387
+ const initialData = await this.fetchHistoricalCandles({
388
+ symbol,
389
+ interval,
390
+ limit: initialLimit,
391
+ });
392
+ // Don't proceed if already unsubscribed
393
+ if (isUnsubscribed) {
394
+ return;
395
+ }
396
+ currentCandleData = initialData;
397
+ if (currentCandleData) {
398
+ callback(currentCandleData);
399
+ }
400
+ // 2. Subscribe to WebSocket for new candles
401
+ // HyperLiquid SDK uses 'coin' terminology
402
+ // Store the promise so cleanup can wait for it if needed
403
+ subscriptionPromise = subscriptionClient.candle({ coin: symbol, interval }, // Map to HyperLiquid SDK's 'coin' parameter
404
+ (candleEvent) => {
405
+ // Don't process events if already unsubscribed
406
+ if (isUnsubscribed) {
407
+ return;
408
+ }
409
+ // Transform SDK CandleEvent to our Candle format
410
+ const newCandle = {
411
+ time: candleEvent.t,
412
+ open: candleEvent.o.toString(),
413
+ high: candleEvent.h.toString(),
414
+ low: candleEvent.l.toString(),
415
+ close: candleEvent.c.toString(),
416
+ volume: candleEvent.v.toString(),
417
+ };
418
+ if (currentCandleData) {
419
+ // Check if this is an update to the last candle or a new candle
420
+ const { candles } = currentCandleData;
421
+ const lastCandle = candles[candles.length - 1];
422
+ if (lastCandle?.time === newCandle.time) {
423
+ // Update existing candle (live candle update)
424
+ // Create new array with updated last element to trigger React re-render
425
+ currentCandleData = {
426
+ ...currentCandleData,
427
+ candles: [...candles.slice(0, -1), newCandle],
428
+ };
429
+ }
430
+ else {
431
+ // New candle (completed candle)
432
+ // Create new array with added element to trigger React re-render
433
+ currentCandleData = {
434
+ ...currentCandleData,
435
+ candles: [...candles, newCandle],
436
+ };
437
+ }
438
+ }
439
+ else {
440
+ currentCandleData = {
441
+ symbol,
442
+ interval,
443
+ candles: [newCandle],
444
+ };
445
+ }
446
+ callback(currentCandleData);
447
+ });
448
+ // Store cleanup function when subscription resolves
449
+ try {
450
+ const sub = await subscriptionPromise;
451
+ wsUnsubscribe = () => sub.unsubscribe();
452
+ // If already unsubscribed while waiting, clean up immediately
453
+ if (isUnsubscribed) {
454
+ wsUnsubscribe();
455
+ wsUnsubscribe = null;
456
+ }
457
+ }
458
+ catch (error) {
459
+ const errorInstance = ensureError(error, 'HyperLiquidClientService.subscribeToCandles');
460
+ // Log to Sentry: WebSocket subscription failure prevents live updates
461
+ __classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").logger.error(errorInstance, {
462
+ tags: {
463
+ feature: PERPS_CONSTANTS.FeatureName,
464
+ service: 'HyperLiquidClientService',
465
+ network: __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f") ? 'testnet' : 'mainnet',
466
+ },
467
+ context: {
468
+ name: 'websocket_subscription',
469
+ data: {
470
+ operation: 'subscribeToCandles',
471
+ symbol,
472
+ interval,
473
+ phase: 'ws_subscription',
474
+ },
475
+ },
476
+ });
477
+ // Notify caller of error
478
+ onError?.(errorInstance);
479
+ }
480
+ }
481
+ catch (error) {
482
+ const errorInstance = ensureError(error, 'HyperLiquidClientService.subscribeToCandles');
483
+ // Log to Sentry: initial fetch failure blocks chart completely
484
+ __classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").logger.error(errorInstance, {
485
+ tags: {
486
+ feature: PERPS_CONSTANTS.FeatureName,
487
+ service: 'HyperLiquidClientService',
488
+ network: __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f") ? 'testnet' : 'mainnet',
489
+ },
490
+ context: {
491
+ name: 'initial_candles_fetch',
492
+ data: {
493
+ operation: 'subscribeToCandles',
494
+ symbol,
495
+ interval,
496
+ phase: 'initial_fetch',
497
+ initialLimit,
498
+ },
499
+ },
500
+ });
501
+ // Notify caller of error
502
+ onError?.(errorInstance);
503
+ }
504
+ };
505
+ // Fire-and-forget the async initialization
506
+ initAndSubscribe().catch(() => {
507
+ // Error already handled inside initAndSubscribe
508
+ });
509
+ // Return cleanup function
510
+ return () => {
511
+ isUnsubscribed = true;
512
+ if (wsUnsubscribe) {
513
+ // Subscription already resolved - unsubscribe directly
514
+ wsUnsubscribe();
515
+ wsUnsubscribe = null;
516
+ }
517
+ else if (subscriptionPromise) {
518
+ // Subscription promise still pending - wait for it and clean up
519
+ // This prevents WebSocket subscription leaks when component unmounts
520
+ // before the subscription promise resolves
521
+ subscriptionPromise
522
+ .then((sub) => sub.unsubscribe())
523
+ .catch(() => {
524
+ // Ignore errors during cleanup - subscription may have failed
525
+ });
526
+ subscriptionPromise = null;
527
+ }
528
+ };
529
+ }
530
+ /**
531
+ * Disconnect and cleanup all clients
532
+ *
533
+ * @returns A promise that resolves when disconnection is complete.
534
+ */
535
+ async disconnect() {
536
+ // Await existing promise if already disconnecting
537
+ if (__classPrivateFieldGet(this, _HyperLiquidClientService_disconnectionPromise, "f")) {
538
+ await __classPrivateFieldGet(this, _HyperLiquidClientService_disconnectionPromise, "f");
539
+ return;
540
+ }
541
+ // If already disconnected, return immediately
542
+ if (__classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f") === WebSocketConnectionState.Disconnected) {
543
+ return;
544
+ }
545
+ // Create and store the disconnection promise
546
+ __classPrivateFieldSet(this, _HyperLiquidClientService_disconnectionPromise, __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_performDisconnection).call(this), "f");
547
+ try {
548
+ await __classPrivateFieldGet(this, _HyperLiquidClientService_disconnectionPromise, "f");
549
+ }
550
+ finally {
551
+ __classPrivateFieldSet(this, _HyperLiquidClientService_disconnectionPromise, null, "f");
552
+ }
553
+ }
554
+ /**
555
+ * Get current WebSocket connection state
556
+ *
557
+ * @returns The current WebSocket connection state.
558
+ */
559
+ getConnectionState() {
560
+ return __classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f");
561
+ }
562
+ /**
563
+ * Check if WebSocket is fully disconnected
564
+ *
565
+ * @returns True if the WebSocket is in disconnected state.
566
+ */
567
+ isDisconnected() {
568
+ return __classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f") === WebSocketConnectionState.Disconnected;
569
+ }
570
+ /**
571
+ * Set callback to be invoked when reconnection is needed
572
+ * This allows the service to notify external components (like PerpsConnectionManager)
573
+ * when a connection drop is detected
574
+ *
575
+ * @param callback - The async callback to invoke when reconnection is needed.
576
+ */
577
+ setOnReconnectCallback(callback) {
578
+ __classPrivateFieldSet(this, _HyperLiquidClientService_onReconnectCallback, callback, "f");
579
+ }
580
+ /**
581
+ * Set callback for WebSocket termination events
582
+ * Called when the SDK exhausts all reconnection attempts
583
+ *
584
+ * @param callback - The callback to invoke on termination, or null to clear.
585
+ */
586
+ setOnTerminateCallback(callback) {
587
+ __classPrivateFieldSet(this, _HyperLiquidClientService_onTerminateCallback, callback, "f");
588
+ }
589
+ /**
590
+ * Subscribe to connection state changes.
591
+ * The listener will be called immediately with the current state and whenever the state changes.
592
+ *
593
+ * @param listener - Callback function that receives the new connection state and reconnection attempt
594
+ * @returns Unsubscribe function to remove the listener
595
+ */
596
+ subscribeToConnectionState(listener) {
597
+ __classPrivateFieldGet(this, _HyperLiquidClientService_connectionStateListeners, "f").add(listener);
598
+ // Immediately notify with current state
599
+ // Wrap in try-catch to match notifyConnectionStateListeners behavior
600
+ // This ensures the unsubscribe function is always returned even if listener throws
601
+ try {
602
+ listener(__classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f"), __classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionAttempt, "f"));
603
+ }
604
+ catch {
605
+ // Ignore errors in listeners to prevent breaking subscription mechanism
606
+ // If listener throws, it will be removed when unsubscribe is called
607
+ }
608
+ // Return unsubscribe function
609
+ return () => {
610
+ __classPrivateFieldGet(this, _HyperLiquidClientService_connectionStateListeners, "f").delete(listener);
611
+ };
612
+ }
613
+ /**
614
+ * Manually trigger a reconnection attempt.
615
+ * This is exposed for UI retry buttons when user wants to force reconnection.
616
+ * Resets the reconnection attempt counter to allow retrying after max attempts.
617
+ */
618
+ async reconnect() {
619
+ __classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('[HyperLiquidClientService] reconnect() called', {
620
+ previousAttempt: __classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionAttempt, "f"),
621
+ currentState: __classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f"),
622
+ });
623
+ // Reset attempt counter when user manually triggers retry
624
+ __classPrivateFieldSet(this, _HyperLiquidClientService_reconnectionAttempt, 0, "f");
625
+ await __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_handleConnectionDrop).call(this);
626
+ __classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('[HyperLiquidClientService] reconnect() completed', {
627
+ newState: __classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f"),
628
+ });
629
+ }
630
+ }
631
+ _HyperLiquidClientService_exchangeClient = new WeakMap(), _HyperLiquidClientService_infoClient = new WeakMap(), _HyperLiquidClientService_infoClientHttp = new WeakMap(), _HyperLiquidClientService_subscriptionClient = new WeakMap(), _HyperLiquidClientService_wsTransport = new WeakMap(), _HyperLiquidClientService_httpTransport = new WeakMap(), _HyperLiquidClientService_isTestnet = new WeakMap(), _HyperLiquidClientService_connectionState = new WeakMap(), _HyperLiquidClientService_disconnectionPromise = new WeakMap(), _HyperLiquidClientService_onTerminateCallback = new WeakMap(), _HyperLiquidClientService_onReconnectCallback = new WeakMap(), _HyperLiquidClientService_reconnectionAttempt = new WeakMap(), _HyperLiquidClientService_connectionStateListeners = new WeakMap(), _HyperLiquidClientService_reconnectionRetryTimeout = new WeakMap(), _HyperLiquidClientService_deps = new WeakMap(), _HyperLiquidClientService_isReconnecting = new WeakMap(), _HyperLiquidClientService_instances = new WeakSet(), _HyperLiquidClientService_createTransports = function _HyperLiquidClientService_createTransports() {
632
+ // Prevent duplicate transport creation and listener accumulation
633
+ // This guards against re-entry if initialize() is called multiple times
634
+ // (e.g., after a failed initialization attempt that didn't properly clean up)
635
+ if (__classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f") && __classPrivateFieldGet(this, _HyperLiquidClientService_httpTransport, "f")) {
636
+ __classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('HyperLiquid: Transports already exist, skipping creation');
637
+ return __classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f");
638
+ }
639
+ __classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('HyperLiquid: Creating transports', {
640
+ isTestnet: __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f"),
641
+ timestamp: new Date().toISOString(),
642
+ note: 'SDK will auto-select endpoints based on isTestnet flag',
643
+ });
644
+ // HTTP transport for request/response operations (InfoClient, ExchangeClient)
645
+ // SDK automatically selects: mainnet (https://api.hyperliquid.xyz) or testnet (https://api.hyperliquid-testnet.xyz)
646
+ __classPrivateFieldSet(this, _HyperLiquidClientService_httpTransport, new HttpTransport({
647
+ isTestnet: __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f"),
648
+ timeout: HYPERLIQUID_TRANSPORT_CONFIG.timeout,
649
+ }), "f");
650
+ // WebSocket transport for real-time subscriptions (SubscriptionClient)
651
+ // SDK automatically selects: mainnet (wss://api.hyperliquid.xyz/ws) or testnet (wss://api.hyperliquid-testnet.xyz/ws)
652
+ __classPrivateFieldSet(this, _HyperLiquidClientService_wsTransport, new WebSocketTransport({
653
+ isTestnet: __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f"),
654
+ ...HYPERLIQUID_TRANSPORT_CONFIG,
655
+ reconnect: {
656
+ ...HYPERLIQUID_TRANSPORT_CONFIG.reconnect,
657
+ WebSocket: globalThis.WebSocket, // Use React Native's global WebSocket
658
+ },
659
+ }), "f");
660
+ // Listen for WebSocket termination (fired when SDK exhausts all reconnection attempts)
661
+ __classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f").socket.addEventListener('terminate', (event) => {
662
+ const customEvent = event;
663
+ __classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('HyperLiquid: WebSocket terminated', {
664
+ reason: customEvent.detail?.code,
665
+ timestamp: new Date().toISOString(),
666
+ });
667
+ __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Disconnected);
668
+ if (__classPrivateFieldGet(this, _HyperLiquidClientService_onTerminateCallback, "f")) {
669
+ const error = customEvent.detail instanceof Error
670
+ ? customEvent.detail
671
+ : new Error(`WebSocket terminated: ${customEvent.detail?.code ?? 'unknown'}`);
672
+ __classPrivateFieldGet(this, _HyperLiquidClientService_onTerminateCallback, "f").call(this, error);
673
+ }
674
+ });
675
+ return __classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f");
676
+ }, _HyperLiquidClientService_getIntervalMilliseconds = function _HyperLiquidClientService_getIntervalMilliseconds(interval) {
677
+ const intervalMap = {
678
+ [CandlePeriod.OneMinute]: 1 * 60 * 1000,
679
+ [CandlePeriod.ThreeMinutes]: 3 * 60 * 1000,
680
+ [CandlePeriod.FiveMinutes]: 5 * 60 * 1000,
681
+ [CandlePeriod.FifteenMinutes]: 15 * 60 * 1000,
682
+ [CandlePeriod.ThirtyMinutes]: 30 * 60 * 1000,
683
+ [CandlePeriod.OneHour]: 60 * 60 * 1000,
684
+ [CandlePeriod.TwoHours]: 2 * 60 * 60 * 1000,
685
+ [CandlePeriod.FourHours]: 4 * 60 * 60 * 1000,
686
+ [CandlePeriod.EightHours]: 8 * 60 * 60 * 1000,
687
+ [CandlePeriod.TwelveHours]: 12 * 60 * 60 * 1000,
688
+ [CandlePeriod.OneDay]: 24 * 60 * 60 * 1000,
689
+ [CandlePeriod.ThreeDays]: 3 * 24 * 60 * 60 * 1000,
690
+ [CandlePeriod.OneWeek]: 7 * 24 * 60 * 60 * 1000,
691
+ [CandlePeriod.OneMonth]: 30 * 24 * 60 * 60 * 1000, // Approximate
692
+ };
693
+ return intervalMap[interval];
694
+ }, _HyperLiquidClientService_performDisconnection = async function _HyperLiquidClientService_performDisconnection() {
695
+ try {
696
+ __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Disconnecting);
697
+ __classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('HyperLiquid: Disconnecting SDK clients', {
698
+ isTestnet: __classPrivateFieldGet(this, _HyperLiquidClientService_isTestnet, "f"),
699
+ timestamp: new Date().toISOString(),
700
+ connectionState: __classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f"),
701
+ });
702
+ // Clear callbacks
703
+ __classPrivateFieldSet(this, _HyperLiquidClientService_onReconnectCallback, undefined, "f");
704
+ __classPrivateFieldSet(this, _HyperLiquidClientService_onTerminateCallback, null, "f");
705
+ // Cancel any pending reconnection retry timeout
706
+ if (__classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionRetryTimeout, "f")) {
707
+ clearTimeout(__classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionRetryTimeout, "f"));
708
+ __classPrivateFieldSet(this, _HyperLiquidClientService_reconnectionRetryTimeout, null, "f");
709
+ }
710
+ // Clear connection state listeners to prevent stale callbacks
711
+ __classPrivateFieldGet(this, _HyperLiquidClientService_connectionStateListeners, "f").clear();
712
+ // Reset reconnection flag to allow future manual retries
713
+ // This prevents a race condition where disconnecting during an active
714
+ // reconnection attempt could leave the flag stuck, blocking subsequent retries
715
+ __classPrivateFieldSet(this, _HyperLiquidClientService_isReconnecting, false, "f");
716
+ // Close WebSocket transport only (HTTP is stateless)
717
+ if (__classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f")) {
718
+ try {
719
+ await __classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f").close();
720
+ __classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('HyperLiquid: Closed WebSocket transport', {
721
+ timestamp: new Date().toISOString(),
722
+ });
723
+ }
724
+ catch (error) {
725
+ __classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").logger.error(ensureError(error, 'HyperLiquidClientService.performDisconnection'), {
726
+ tags: { feature: PERPS_CONSTANTS.FeatureName },
727
+ context: {
728
+ name: 'HyperLiquidClientService.performDisconnection',
729
+ data: { action: 'close_transport' },
730
+ },
731
+ });
732
+ }
733
+ }
734
+ // Clear client references
735
+ __classPrivateFieldSet(this, _HyperLiquidClientService_subscriptionClient, undefined, "f");
736
+ __classPrivateFieldSet(this, _HyperLiquidClientService_exchangeClient, undefined, "f");
737
+ __classPrivateFieldSet(this, _HyperLiquidClientService_infoClient, undefined, "f");
738
+ __classPrivateFieldSet(this, _HyperLiquidClientService_infoClientHttp, undefined, "f");
739
+ __classPrivateFieldSet(this, _HyperLiquidClientService_wsTransport, undefined, "f");
740
+ __classPrivateFieldSet(this, _HyperLiquidClientService_httpTransport, undefined, "f");
741
+ __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Disconnected);
742
+ __classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('HyperLiquid: SDK clients fully disconnected', {
743
+ timestamp: new Date().toISOString(),
744
+ connectionState: __classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f"),
745
+ });
746
+ }
747
+ catch (error) {
748
+ __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Disconnected);
749
+ __classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").logger.error(ensureError(error, 'HyperLiquidClientService.performDisconnection'), {
750
+ tags: { feature: PERPS_CONSTANTS.FeatureName },
751
+ context: {
752
+ name: 'HyperLiquidClientService.performDisconnection',
753
+ data: { action: 'outer_catch' },
754
+ },
755
+ });
756
+ throw error;
757
+ }
758
+ }, _HyperLiquidClientService_updateConnectionState = function _HyperLiquidClientService_updateConnectionState(newState) {
759
+ const previousState = __classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f");
760
+ const stateChanged = previousState !== newState;
761
+ const isReconnectionAttempt = newState === WebSocketConnectionState.Connecting &&
762
+ __classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionAttempt, "f") > 0;
763
+ __classPrivateFieldSet(this, _HyperLiquidClientService_connectionState, newState, "f");
764
+ // Reset reconnection attempt counter when successfully connected
765
+ if (newState === WebSocketConnectionState.Connected) {
766
+ __classPrivateFieldSet(this, _HyperLiquidClientService_reconnectionAttempt, 0, "f");
767
+ }
768
+ // Notify if state changed OR if this is a reconnection attempt (to update attempt count)
769
+ if (stateChanged || isReconnectionAttempt) {
770
+ __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_notifyConnectionStateListeners).call(this);
771
+ }
772
+ }, _HyperLiquidClientService_notifyConnectionStateListeners = function _HyperLiquidClientService_notifyConnectionStateListeners() {
773
+ __classPrivateFieldGet(this, _HyperLiquidClientService_connectionStateListeners, "f").forEach((listener) => {
774
+ try {
775
+ listener(__classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f"), __classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionAttempt, "f"));
776
+ }
777
+ catch {
778
+ // Ignore errors in listeners to prevent breaking other listeners
779
+ }
780
+ });
781
+ }, _HyperLiquidClientService_handleConnectionDrop =
782
+ /**
783
+ * Handle detected connection drop
784
+ * Recreates WebSocket transport and notifies callback to restore subscriptions
785
+ * Will give up after maxReconnectionAttempts and mark status as disconnected
786
+ */
787
+ async function _HyperLiquidClientService_handleConnectionDrop() {
788
+ // Prevent multiple simultaneous reconnection attempts
789
+ if (__classPrivateFieldGet(this, _HyperLiquidClientService_isReconnecting, "f")) {
790
+ return;
791
+ }
792
+ __classPrivateFieldSet(this, _HyperLiquidClientService_isReconnecting, true, "f");
793
+ // Increment reconnection attempt counter
794
+ __classPrivateFieldSet(this, _HyperLiquidClientService_reconnectionAttempt, __classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionAttempt, "f") + 1, "f");
795
+ // Check if we've exceeded max retry attempts
796
+ if (__classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionAttempt, "f") > maxReconnectionAttempts) {
797
+ __classPrivateFieldSet(this, _HyperLiquidClientService_isReconnecting, false, "f");
798
+ __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Disconnected);
799
+ return;
800
+ }
801
+ try {
802
+ __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Connecting);
803
+ // Close existing WebSocket transport and clear references
804
+ // so createTransports() will create fresh ones
805
+ if (__classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f")) {
806
+ try {
807
+ await __classPrivateFieldGet(this, _HyperLiquidClientService_wsTransport, "f").close();
808
+ }
809
+ catch {
810
+ // Ignore errors during close - transport may already be dead
811
+ }
812
+ }
813
+ __classPrivateFieldSet(this, _HyperLiquidClientService_wsTransport, undefined, "f");
814
+ __classPrivateFieldSet(this, _HyperLiquidClientService_httpTransport, undefined, "f");
815
+ // Recreate WebSocket transport - returns the new transport for type safety
816
+ const newWsTransport = __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_createTransports).call(this);
817
+ // Recreate clients that use WebSocket transport
818
+ __classPrivateFieldSet(this, _HyperLiquidClientService_infoClient, new InfoClient({ transport: newWsTransport }), "f");
819
+ __classPrivateFieldSet(this, _HyperLiquidClientService_subscriptionClient, new SubscriptionClient({
820
+ transport: newWsTransport,
821
+ }), "f");
822
+ await newWsTransport.ready();
823
+ __classPrivateFieldGet(this, _HyperLiquidClientService_deps, "f").debugLogger.log('HyperLiquid: Transport ready, restoring subscriptions', { timestamp: new Date().toISOString() });
824
+ // NOW safe to restore subscriptions
825
+ if (__classPrivateFieldGet(this, _HyperLiquidClientService_onReconnectCallback, "f")) {
826
+ await __classPrivateFieldGet(this, _HyperLiquidClientService_onReconnectCallback, "f").call(this);
827
+ }
828
+ // Cancel any pending retry timeout from previous failed attempts
829
+ if (__classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionRetryTimeout, "f")) {
830
+ clearTimeout(__classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionRetryTimeout, "f"));
831
+ __classPrivateFieldSet(this, _HyperLiquidClientService_reconnectionRetryTimeout, null, "f");
832
+ }
833
+ __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Connected);
834
+ __classPrivateFieldSet(this, _HyperLiquidClientService_isReconnecting, false, "f");
835
+ }
836
+ catch {
837
+ // Reset flag before scheduling retry so the next attempt can proceed
838
+ __classPrivateFieldSet(this, _HyperLiquidClientService_isReconnecting, false, "f");
839
+ // Check if we've exceeded max retry attempts
840
+ if (__classPrivateFieldGet(this, _HyperLiquidClientService_reconnectionAttempt, "f") >= maxReconnectionAttempts) {
841
+ __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_updateConnectionState).call(this, WebSocketConnectionState.Disconnected);
842
+ return;
843
+ }
844
+ // Reconnection failed - schedule a retry after a delay
845
+ // Store timeout reference so it can be cancelled on intentional disconnect
846
+ __classPrivateFieldSet(this, _HyperLiquidClientService_reconnectionRetryTimeout, setTimeout(() => {
847
+ __classPrivateFieldSet(this, _HyperLiquidClientService_reconnectionRetryTimeout, null, "f"); // Clear reference after execution
848
+ // Only retry if we haven't been intentionally disconnected
849
+ // and no manual reconnect() is already in progress
850
+ // Note: State may be CONNECTING or DISCONNECTED (if terminate event fired during reconnect)
851
+ if ((__classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f") === WebSocketConnectionState.Connecting ||
852
+ __classPrivateFieldGet(this, _HyperLiquidClientService_connectionState, "f") === WebSocketConnectionState.Disconnected) &&
853
+ !__classPrivateFieldGet(this, _HyperLiquidClientService_disconnectionPromise, "f") &&
854
+ !__classPrivateFieldGet(this, _HyperLiquidClientService_isReconnecting, "f")) {
855
+ __classPrivateFieldGet(this, _HyperLiquidClientService_instances, "m", _HyperLiquidClientService_handleConnectionDrop).call(this).catch(() => {
856
+ // Error already handled inside #handleConnectionDrop
857
+ });
858
+ }
859
+ }, PERPS_CONSTANTS.ReconnectionRetryDelayMs), "f");
860
+ }
861
+ };
862
+ //# sourceMappingURL=HyperLiquidClientService.mjs.map