@metamask-previews/perps-controller 0.0.0-preview-e4aa1532 → 0.0.0-preview-6dfa4aeba

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