@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,987 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatDateSection = exports.formatOrderCardDate = exports.formatTransactionDate = exports.parsePercentageString = exports.parseCurrencyString = exports.formatLeverage = exports.formatPositionSize = exports.formatVolume = exports.formatLargeNumber = exports.LARGE_NUMBER_RANGES_DETAILED = exports.DEFAULT_LARGE_NUMBER_RANGES = exports.formatFundingRate = exports.formatPercentage = exports.formatPnl = exports.PRICE_RANGES_UNIVERSAL = exports.DEFAULT_PRICE_RANGES = exports.formatPositiveFiat = exports.formatPerpsFiat = exports.PRICE_RANGES_MINIMAL_VIEW = exports.roundToSignificantFigures = exports.hasExceededSignificantFigures = exports.countSignificantFigures = exports.formatWithSignificantDigits = exports.PRICE_THRESHOLD = void 0;
4
- /**
5
- * Shared formatting utilities for Perps components
6
- */
7
- const bignumber_js_1 = require("bignumber.js");
8
- const perpsConfig_1 = require("../constants/perpsConfig.cjs");
9
- /**
10
- * Price threshold constants for PRICE_RANGES_UNIVERSAL
11
- * These define the boundaries between different formatting ranges
12
- */
13
- exports.PRICE_THRESHOLD = {
14
- /** Very high values boundary (> $100k) */
15
- VERY_HIGH: 100000,
16
- /** High values boundary (> $10k) */
17
- HIGH: 10000,
18
- /** Large values boundary (> $1k) */
19
- LARGE: 1000,
20
- /** Medium values boundary (> $100) */
21
- MEDIUM: 100,
22
- /** Medium-low values boundary (> $10) */
23
- MEDIUM_LOW: 10,
24
- /** Low values boundary (>= $0.01) */
25
- LOW: 0.01,
26
- /**
27
- * Very small values threshold (< $0.01)
28
- * This is the minimum value for formatWithThreshold and should align with
29
- * the 6 decimal maximum (0.000001 is the smallest representable value)
30
- */
31
- VERY_SMALL: 0.000001,
32
- };
33
- /**
34
- * Creates an Intl.NumberFormat formatter with memoization
35
- *
36
- * @param locale - The locale for formatting
37
- * @param options - NumberFormat options
38
- * @returns Formatted number formatter
39
- */
40
- const getIntlNumberFormatter = (locale, options) => {
41
- return new Intl.NumberFormat(locale, options);
42
- };
43
- /**
44
- * Creates an Intl.DateTimeFormat formatter
45
- *
46
- * @param locale - The locale for formatting
47
- * @param options - DateTimeFormat options
48
- * @returns Formatted date/time formatter
49
- */
50
- const getIntlDateTimeFormatter = (locale, options) => {
51
- return new Intl.DateTimeFormat(locale, options);
52
- };
53
- /**
54
- * Formats a value with threshold handling (shows "< threshold" for small values)
55
- *
56
- * @param value - The value to format
57
- * @param threshold - The threshold for showing "< threshold"
58
- * @param locale - The locale for formatting
59
- * @param options - NumberFormat options
60
- * @returns Formatted string
61
- */
62
- const formatWithThreshold = (value, threshold, locale, options) => {
63
- if (Math.abs(value) < threshold && value !== 0) {
64
- const formatter = getIntlNumberFormatter(locale, options);
65
- const formattedThreshold = formatter.format(threshold);
66
- return value < 0 ? `> -${formattedThreshold}` : `< ${formattedThreshold}`;
67
- }
68
- return getIntlNumberFormatter(locale, options).format(value);
69
- };
70
- /**
71
- * Formats a number to a specific number of significant digits
72
- * Strips trailing zeros unless minDecimals requires them
73
- *
74
- * @param value - The numeric value to format
75
- * @param significantDigits - Number of significant digits to maintain
76
- * @param minDecimals - Minimum decimal places to show (may add zeros)
77
- * @param maxDecimals - Maximum decimal places allowed
78
- * @returns Formatted number with appropriate precision, trailing zeros removed
79
- */
80
- function formatWithSignificantDigits(value, significantDigits, minDecimals, maxDecimals) {
81
- // Handle special cases
82
- if (value === 0) {
83
- // Return zero with no trailing decimals by default (matches stripTrailingZeros behavior)
84
- // Can be overridden by explicit minDecimals if needed
85
- return { value: 0, decimals: minDecimals ?? 0 };
86
- }
87
- const absValue = Math.abs(value);
88
- // For numbers >= 1, calculate decimals based on magnitude to achieve target significant figures
89
- // This ensures consistent precision across different price ranges:
90
- // Examples with 4 significant figures:
91
- // $123,456.78 -> $123,456.78 (>=1000: 2 decimals minimum, 8 sig figs)
92
- // $456.12 -> $456.12 (>=10: 2 decimals minimum, 5 sig figs)
93
- // $56.123 -> $56.123 (>=10: 2 decimals minimum, 5 sig figs)
94
- // $5.123 -> $5.123 ($1-$10: 3 decimals = 4 sig figs)
95
- // $2.801 -> $2.801 ($1-$10: 3 decimals = 4 sig figs)
96
- // $1.234 -> $1.234 ($1-$10: 3 decimals = 4 sig figs)
97
- if (absValue >= 1) {
98
- let targetDecimals;
99
- // Calculate decimals needed based on integer digits to achieve target significant figures
100
- // For $38.388 with 5 sig figs: 2 integer digits, need 3 decimals (3,8,3,8,8)
101
- // For $123.45 with 5 sig figs: 3 integer digits, need 2 decimals (1,2,3,4,5)
102
- const integerDigits = Math.floor(Math.log10(absValue)) + 1;
103
- const decimalsNeeded = significantDigits - integerDigits;
104
- targetDecimals = Math.max(decimalsNeeded, 0); // Can't have negative decimals
105
- // Apply explicit minimum decimals constraint if provided (for special cases)
106
- if (minDecimals !== undefined && targetDecimals < minDecimals) {
107
- targetDecimals = minDecimals;
108
- }
109
- // Apply maximum decimals constraint if specified
110
- const finalDecimals = maxDecimals === undefined
111
- ? targetDecimals
112
- : Math.min(targetDecimals, maxDecimals);
113
- // Round to prevent floating-point artifacts (e.g., 2.820000000000003 -> 2.82)
114
- const roundedValue = Number(value.toFixed(finalDecimals));
115
- return {
116
- value: roundedValue,
117
- decimals: finalDecimals,
118
- };
119
- }
120
- // For numbers < 1, use toPrecision to limit to significantDigits
121
- // Examples: 0.1234, 0.01234 should show exactly 4 sig figs
122
- const precisionStr = absValue.toPrecision(significantDigits);
123
- const precisionNum = parseFloat(precisionStr);
124
- // Convert to string to count actual decimals after trailing zeros are removed
125
- const valueStr = precisionNum.toString();
126
- const [, decPart = ''] = valueStr.split('.');
127
- let actualDecimals = decPart.length;
128
- // Apply min/max decimal constraints
129
- if (minDecimals !== undefined && actualDecimals < minDecimals) {
130
- actualDecimals = minDecimals; // Will add zeros if needed
131
- }
132
- if (maxDecimals !== undefined && actualDecimals > maxDecimals) {
133
- actualDecimals = maxDecimals;
134
- }
135
- // Return the value with sign restored and decimal count
136
- return {
137
- value: value < 0 ? -precisionNum : precisionNum,
138
- decimals: actualDecimals,
139
- };
140
- }
141
- exports.formatWithSignificantDigits = formatWithSignificantDigits;
142
- /**
143
- * Counts the number of significant figures in a numeric string
144
- * This matches HyperLiquid's validation rules:
145
- * - Trailing decimal zeros are trimmed first (via parseFloat().toString())
146
- * - Count non-zero integer digits (without leading zeros)
147
- * - Count ALL decimal digits (including leading zeros after decimal point)
148
- *
149
- * @param priceString - The price value as a string (may include $ or ,)
150
- * @returns The count of significant figures
151
- *
152
- * @example
153
- * countSignificantFigures('123.45') // 5 (3 integer + 2 decimal)
154
- * countSignificantFigures('123.4500') // 5 (trailing zeros trimmed first)
155
- * countSignificantFigures('0.000123') // 6 (0 integer + 6 decimal)
156
- * countSignificantFigures('12.345') // 5 (2 integer + 3 decimal)
157
- * countSignificantFigures('12000') // 2 (trailing zeros in integer not counted)
158
- */
159
- const countSignificantFigures = (priceString) => {
160
- if (!priceString) {
161
- return 0;
162
- }
163
- // Clean the string - remove currency symbols and commas
164
- const cleaned = priceString.replace(/[$,]/gu, '').trim();
165
- // Parse and convert back to string to trim trailing decimal zeros
166
- // This matches formatHyperLiquidPrice: parseFloat(formattedPrice).toString()
167
- const parsedValue = parseFloat(cleaned);
168
- if (isNaN(parsedValue) || parsedValue === 0) {
169
- return 0;
170
- }
171
- // Normalize to remove trailing zeros (e.g., "123.4500" -> "123.45")
172
- const normalized = parsedValue.toString();
173
- // Split into integer and decimal parts
174
- const [integerPart, decimalPart = ''] = normalized.split('.');
175
- // Remove leading zeros and negative sign from integer part
176
- const trimmedInteger = integerPart.replace(/^-?0*/u, '') || '';
177
- // For integers without decimal, trailing zeros are ambiguous
178
- // We treat them as not significant (matching HyperLiquid behavior)
179
- const effectiveIntegerLength = decimalPart
180
- ? trimmedInteger.length
181
- : trimmedInteger.replace(/0+$/u, '').length ||
182
- (trimmedInteger.length > 0 ? 1 : 0);
183
- // Count ALL decimal digits (including leading zeros like 0.000123)
184
- // This matches HyperLiquid's validation behavior
185
- return effectiveIntegerLength + decimalPart.length;
186
- };
187
- exports.countSignificantFigures = countSignificantFigures;
188
- /**
189
- * Checks if a price will be rounded due to exceeding significant figures
190
- * Only applies when the price has decimals - integers are never rounded
191
- * This matches the behavior in formatHyperLiquidPrice
192
- *
193
- * @param priceString - The price value as a string
194
- * @param maxSigFigs - Maximum allowed significant figures (default: MAX_SIGNIFICANT_FIGURES from config)
195
- * @returns true if the price will be rounded, false otherwise
196
- */
197
- const hasExceededSignificantFigures = (priceString, maxSigFigs = perpsConfig_1.DECIMAL_PRECISION_CONFIG.MaxSignificantFigures) => {
198
- if (!priceString || priceString.trim() === '') {
199
- return false;
200
- }
201
- // Clean the string and normalize (trim trailing zeros)
202
- const cleaned = priceString.replace(/[$,]/gu, '').trim();
203
- const parsedValue = parseFloat(cleaned);
204
- if (isNaN(parsedValue)) {
205
- return false;
206
- }
207
- // Normalize to check for decimal presence after trimming trailing zeros
208
- const normalized = parsedValue.toString();
209
- // If there's no decimal part after normalization, the price won't be rounded
210
- if (!normalized.includes('.')) {
211
- return false;
212
- }
213
- return (0, exports.countSignificantFigures)(priceString) > maxSigFigs;
214
- };
215
- exports.hasExceededSignificantFigures = hasExceededSignificantFigures;
216
- /**
217
- * Rounds a price string to the maximum allowed significant figures
218
- * Uses the same counting logic as countSignificantFigures:
219
- * - Count non-zero integer digits + ALL decimal digits (including leading zeros)
220
- *
221
- * @param priceString - The price value as a string
222
- * @param maxSigFigs - Maximum allowed significant figures (default: MAX_SIGNIFICANT_FIGURES from config)
223
- * @returns Price string rounded to max significant figures
224
- *
225
- * @example
226
- * roundToSignificantFigures('123.456') // '123.46' (3 int + 2 dec = 5)
227
- * roundToSignificantFigures('0.065242') // '0.06524' (0 int + 5 dec = 5)
228
- * roundToSignificantFigures('12345.67') // '12346' (5 int + 0 dec = 5)
229
- */
230
- const roundToSignificantFigures = (priceString, maxSigFigs = perpsConfig_1.DECIMAL_PRECISION_CONFIG.MaxSignificantFigures) => {
231
- if (!priceString || priceString.trim() === '') {
232
- return priceString;
233
- }
234
- const cleaned = priceString.replace(/[$,]/gu, '').trim();
235
- const parsedValue = Number.parseFloat(cleaned);
236
- if (Number.isNaN(parsedValue) || parsedValue === 0) {
237
- return priceString;
238
- }
239
- // Normalize to remove trailing zeros
240
- const normalized = parsedValue.toString();
241
- const [integerPart, decimalPart = ''] = normalized.split('.');
242
- // Count integer significant digits (without leading zeros)
243
- const trimmedInteger = integerPart.replace(/^-?0*/u, '') || '';
244
- const integerSigFigs = trimmedInteger.length;
245
- // If no decimal, return as is (integers are fine)
246
- if (!decimalPart) {
247
- return normalized;
248
- }
249
- // Calculate how many decimal digits we can keep
250
- const allowedDecimalDigits = maxSigFigs - integerSigFigs;
251
- if (allowedDecimalDigits <= 0) {
252
- // Round to integer
253
- return Math.round(parsedValue).toString();
254
- }
255
- if (decimalPart.length <= allowedDecimalDigits) {
256
- // Already within limit
257
- return normalized;
258
- }
259
- // Round to the allowed number of decimal places
260
- const rounded = parsedValue.toFixed(allowedDecimalDigits);
261
- // Remove trailing zeros
262
- return Number.parseFloat(rounded).toString();
263
- };
264
- exports.roundToSignificantFigures = roundToSignificantFigures;
265
- /**
266
- * Minimal view fiat range configuration
267
- * Uses fiat-style stripping for clean currency display
268
- * Strips only .00 to avoid partial decimals like $1,250.1
269
- */
270
- exports.PRICE_RANGES_MINIMAL_VIEW = [
271
- {
272
- // Large values (>= $1000): Strip .00 only ($5,000 not $5,000.00, but $5,000.10 stays)
273
- condition: (val) => Math.abs(val) >= exports.PRICE_THRESHOLD.LARGE,
274
- minimumDecimals: 2,
275
- maximumDecimals: 2,
276
- threshold: exports.PRICE_THRESHOLD.LARGE,
277
- stripTrailingZeros: true,
278
- fiatStyleStripping: true,
279
- },
280
- {
281
- // Small values (< $1000): Also use fiat-style stripping ($100 not $100.00, but $13.40 stays)
282
- condition: () => true,
283
- minimumDecimals: 2,
284
- maximumDecimals: 2,
285
- threshold: exports.PRICE_THRESHOLD.LOW,
286
- stripTrailingZeros: true,
287
- fiatStyleStripping: true,
288
- },
289
- ];
290
- /**
291
- * Formats a balance value as USD currency with appropriate decimal places
292
- *
293
- * @param balance - Raw numeric balance value (e.g., 1234.56, not token minimal denomination)
294
- * @param options - Optional formatting options
295
- * @param options.minimumDecimals - Global minimum decimal places (overrides range configs)
296
- * @param options.maximumDecimals - Global maximum decimal places (overrides range configs)
297
- * @param options.significantDigits - Global significant digits (overrides decimal settings when set)
298
- * @param options.ranges - Custom range configurations (defaults to PRICE_RANGES_MINIMAL_VIEW)
299
- * @param options.currency - Currency code (default: 'USD')
300
- * @param options.locale - Locale for formatting (default: 'en-US')
301
- * @param options.stripTrailingZeros - Strip trailing zeros from output (default: false via PRICE_RANGES_MINIMAL_VIEW). When true, overrides minimumDecimals constraint.
302
- * @returns Formatted currency string with variable decimals based on configured ranges
303
- * @example
304
- * // Using defaults (preserves trailing zeros for fiat)
305
- * formatPerpsFiat(1234.56) => "$1,234.56"
306
- * formatPerpsFiat(1250.00) => "$1,250.00" // Trailing zeros preserved
307
- * formatPerpsFiat(50000) => "$50,000.00" // Trailing zeros preserved
308
- *
309
- * // Stripping trailing zeros when needed (e.g., for crypto)
310
- * formatPerpsFiat(1250, { stripTrailingZeros: true }) => "$1,250"
311
- *
312
- * // With custom ranges
313
- * formatPerpsFiat(0.00001, {
314
- * ranges: [
315
- * { condition: (val) => val < 0.001, minimumDecimals: 6, maximumDecimals: 8 },
316
- * { condition: () => true, minimumDecimals: 2, maximumDecimals: 2 }
317
- * ]
318
- * }) => "$0.00001" // Trailing zero stripped
319
- *
320
- * // With significant digits
321
- * formatPerpsFiat(1234.56789, { significantDigits: 5 }) => "$1,234.6"
322
- * formatPerpsFiat(0.0001234, { significantDigits: 3 }) => "$0.000123"
323
- */
324
- const formatPerpsFiat = (balance, options) => {
325
- const parsedValue = typeof balance === 'string' ? parseFloat(balance) : balance;
326
- const currency = options?.currency ?? 'USD';
327
- const locale = options?.locale ?? 'en-US';
328
- let formatted;
329
- if (isNaN(parsedValue)) {
330
- // Return placeholder for invalid values to avoid confusion with actual $0 values
331
- return perpsConfig_1.PERPS_CONSTANTS.FallbackPriceDisplay;
332
- }
333
- // Use custom ranges or defaults
334
- const ranges = options?.ranges ?? exports.PRICE_RANGES_MINIMAL_VIEW;
335
- // Find the first matching range configuration
336
- const rangeConfig = ranges.find((range) => range.condition(parsedValue));
337
- if (rangeConfig) {
338
- // Check for significant digits (global or range-specific)
339
- const sigDigits = options?.significantDigits ?? rangeConfig.significantDigits;
340
- // If significant digits are specified, use them
341
- if (sigDigits) {
342
- // Get min/max decimals (global overrides range, range overrides default)
343
- const minDecimals = options?.minimumDecimals ?? rangeConfig.minimumDecimals;
344
- const maxDecimals = options?.maximumDecimals ?? rangeConfig.maximumDecimals;
345
- // Calculate appropriate formatting based on significant digits
346
- const { value: formattedValue, decimals } = formatWithSignificantDigits(parsedValue, sigDigits, minDecimals, maxDecimals);
347
- // Format with the calculated decimal places
348
- formatted = formatWithThreshold(formattedValue, rangeConfig.threshold ?? 0.01, locale, {
349
- style: 'currency',
350
- currency,
351
- minimumFractionDigits: decimals,
352
- maximumFractionDigits: decimals,
353
- });
354
- }
355
- else {
356
- // Standard decimal-based formatting (existing logic)
357
- const minDecimals = options?.minimumDecimals ?? rangeConfig.minimumDecimals;
358
- const maxDecimals = options?.maximumDecimals ?? rangeConfig.maximumDecimals;
359
- // Use custom formatting if provided
360
- if (rangeConfig.customFormat) {
361
- formatted = rangeConfig.customFormat(parsedValue, locale, currency);
362
- }
363
- else {
364
- // Use standard formatting with threshold
365
- formatted = formatWithThreshold(parsedValue, rangeConfig.threshold ?? 0.01, locale, {
366
- style: 'currency',
367
- currency,
368
- minimumFractionDigits: minDecimals,
369
- maximumFractionDigits: maxDecimals,
370
- });
371
- }
372
- }
373
- }
374
- else {
375
- // Fallback if no range matches (shouldn't happen with proper default config)
376
- const fallbackMin = options?.minimumDecimals ?? 2;
377
- const fallbackMax = options?.maximumDecimals ?? 2;
378
- formatted = formatWithThreshold(parsedValue, 0.01, locale, {
379
- style: 'currency',
380
- currency,
381
- minimumFractionDigits: fallbackMin,
382
- maximumFractionDigits: fallbackMax,
383
- });
384
- }
385
- // Post-process: strip trailing zeros unless explicitly disabled
386
- // Priority: explicit options.stripTrailingZeros false > rangeConfig > options default > true
387
- // If options.stripTrailingZeros is explicitly false, skip stripping entirely
388
- if (options?.stripTrailingZeros === false) {
389
- return formatted;
390
- }
391
- // Otherwise check range config or default to true
392
- const shouldStrip = rangeConfig?.stripTrailingZeros ?? options?.stripTrailingZeros ?? true;
393
- if (shouldStrip) {
394
- // Check if fiat-style stripping is enabled (only strips .00)
395
- const useFiatStyle = rangeConfig?.fiatStyleStripping ?? false;
396
- if (useFiatStyle) {
397
- // Fiat-style: Only strip .00 (no meaningful decimals), preserve 2-decimal format
398
- // Examples: $1,250.00 becomes $1,250 | $1,000.10 stays $1,000.10 | $13.40 stays $13.40
399
- return formatted.replace(/\.00$/u, '');
400
- }
401
- // Standard: Strip all trailing zeros after decimal point
402
- // Examples: $1,250.00 becomes $1,250 | $100.0 becomes $100 | $10.5 stays $10.5 | $1.234 stays $1.234
403
- return formatted.replace(/(\.\d*?)0+$/u, '$1').replace(/\.$/u, '');
404
- }
405
- return formatted;
406
- };
407
- exports.formatPerpsFiat = formatPerpsFiat;
408
- /**
409
- * Formats a fee value as USD currency with appropriate decimal places
410
- *
411
- * @param fee - Raw numeric or string fee value (e.g., 1234.56, not token minimal denomination)
412
- * @returns Formatted currency string with variable decimals based on configured ranges
413
- * @example formatPositiveFiat(1234.56) => "$1,234.56"
414
- * @example formatPositiveFiat(0.005) => "< $0.01"
415
- * @example formatPositiveFiat(0) => "$0"
416
- */
417
- const formatPositiveFiat = (fee) => {
418
- const smallFeeThreshold = 0.01;
419
- if ((0, bignumber_js_1.BigNumber)(fee).isEqualTo(0)) {
420
- return '$0';
421
- }
422
- if ((0, bignumber_js_1.BigNumber)(fee).isLessThan(smallFeeThreshold)) {
423
- return '< $0.01';
424
- }
425
- return (0, exports.formatPerpsFiat)(fee);
426
- };
427
- exports.formatPositiveFiat = formatPositiveFiat;
428
- /**
429
- * Default price range configurations
430
- * Applied in order - first matching condition wins
431
- */
432
- exports.DEFAULT_PRICE_RANGES = [
433
- {
434
- // Medium-large numbers (>= 1000)
435
- condition: (val) => Math.abs(val) >= 1000,
436
- minimumDecimals: 2,
437
- maximumDecimals: 4,
438
- threshold: 100,
439
- },
440
- {
441
- // Default range (1 <= val < 1000)
442
- condition: () => true,
443
- minimumDecimals: 2,
444
- maximumDecimals: 4,
445
- threshold: 0.0001,
446
- },
447
- ];
448
- /**
449
- * Universal price range configuration following comprehensive rules from rules-decimals.md
450
- *
451
- * Rules:
452
- * - Max 6 decimals across all ranges (Hyperliquid limit)
453
- * - Strip trailing zeros by default
454
- * - Use |v| (absolute value) for conditions
455
- *
456
- * Significant digits by range:
457
- * - > $100,000: 6 sig digs
458
- * - $100,000 > x > $0.01: 5 sig digs
459
- * - < $0.01: 4 sig digs
460
- *
461
- * Decimal limits by price range:
462
- * - |v| > 10,000: min 0, max 0 decimals; 5 sig digs (6 if >100k)
463
- * - |v| > 1,000: min 0, max 1 decimal; 5 sig digs
464
- * - |v| > 100: min 0, max 2 decimals; 5 sig digs
465
- * - |v| > 10: min 0, max 4 decimals; 5 sig digs
466
- * - |v| >= 0.01: 5 sig digs, min 2, max 6 decimals
467
- * - |v| < 0.01: 4 sig digs, min 2, max 6 decimals
468
- *
469
- * Examples:
470
- * - $123,456.78 becomes $123,457 (>$10k: 0 decimals, 6 sig figs)
471
- * - $12,345.67 becomes $12,346 (>$10k: 0 decimals, 5 sig figs)
472
- * - $1,234.56 becomes $1,234.6 ($1k-$10k: 1 decimal, 5 sig figs)
473
- * - $123.456 becomes $123.46 ($100-$1k: 2 decimals, 5 sig figs)
474
- * - $12.34567 becomes $12.346 ($10-$100: 4 decimals, 5 sig figs)
475
- * - $1.3445555 becomes $1.3446 (>=$0.01: 5 sig figs)
476
- * - $0.333333 becomes $0.33333 (>=$0.01: 5 sig figs)
477
- * - $0.004236 stays $0.004236 (<$0.01: 4 sig figs, max 6 decimals)
478
- * - $0.0000006 becomes $0.000001 (<$0.01: 4 sig figs, rounds with max 6 decimals)
479
- */
480
- exports.PRICE_RANGES_UNIVERSAL = [
481
- {
482
- // Very high values (> $100,000): No decimals, 6 significant figures
483
- // Ex: $123,456.78 becomes $123,457
484
- condition: (val) => Math.abs(val) > exports.PRICE_THRESHOLD.VERY_HIGH,
485
- minimumDecimals: 0,
486
- maximumDecimals: 0,
487
- significantDigits: 6,
488
- threshold: exports.PRICE_THRESHOLD.VERY_HIGH,
489
- },
490
- {
491
- // High values ($10,000-$100,000]: No decimals, 5 significant figures
492
- // Ex: $12,345.67 becomes $12,346
493
- condition: (val) => Math.abs(val) > exports.PRICE_THRESHOLD.HIGH,
494
- minimumDecimals: 0,
495
- maximumDecimals: 0,
496
- significantDigits: 5,
497
- threshold: exports.PRICE_THRESHOLD.HIGH,
498
- },
499
- {
500
- // Large values ($1,000-$10,000]: Max 1 decimal, 5 significant figures
501
- // Ex: $1,234.56 becomes $1,234.6
502
- condition: (val) => Math.abs(val) > exports.PRICE_THRESHOLD.LARGE,
503
- minimumDecimals: 0,
504
- maximumDecimals: 1,
505
- significantDigits: 5,
506
- threshold: exports.PRICE_THRESHOLD.LARGE,
507
- },
508
- {
509
- // Medium values ($100-$1,000]: Max 2 decimals, 5 significant figures
510
- // Ex: $123.456 becomes $123.46
511
- condition: (val) => Math.abs(val) > exports.PRICE_THRESHOLD.MEDIUM,
512
- minimumDecimals: 0,
513
- maximumDecimals: 2,
514
- significantDigits: 5,
515
- threshold: exports.PRICE_THRESHOLD.MEDIUM,
516
- },
517
- {
518
- // Medium-low values ($10-$100]: Max 4 decimals, 5 significant figures
519
- // Ex: $12.34567 becomes $12.346
520
- condition: (val) => Math.abs(val) > exports.PRICE_THRESHOLD.MEDIUM_LOW,
521
- minimumDecimals: 0,
522
- maximumDecimals: 4,
523
- significantDigits: 5,
524
- threshold: exports.PRICE_THRESHOLD.MEDIUM_LOW,
525
- },
526
- {
527
- // Low values ($0.01-$10]: 5 significant figures, min 2 max MAX_PRICE_DECIMALS decimals
528
- // Ex: $1.3445555 becomes $1.3446 | $0.333333 becomes $0.33333
529
- condition: (val) => Math.abs(val) >= exports.PRICE_THRESHOLD.LOW,
530
- significantDigits: 5,
531
- minimumDecimals: 2,
532
- maximumDecimals: perpsConfig_1.DECIMAL_PRECISION_CONFIG.MaxPriceDecimals,
533
- threshold: exports.PRICE_THRESHOLD.LOW,
534
- },
535
- {
536
- // Very small values (< $0.01): 4 significant figures, min 2 max MAX_PRICE_DECIMALS decimals
537
- // Ex: $0.004236 stays $0.004236 | $0.0000006 becomes $0.000001
538
- condition: () => true,
539
- significantDigits: 4,
540
- minimumDecimals: 2,
541
- maximumDecimals: perpsConfig_1.DECIMAL_PRECISION_CONFIG.MaxPriceDecimals,
542
- threshold: exports.PRICE_THRESHOLD.VERY_SMALL,
543
- },
544
- ];
545
- /**
546
- * Formats a PnL (Profit and Loss) value with sign prefix
547
- *
548
- * @param pnl - Raw numeric PnL value (positive for profit, negative for loss)
549
- * @returns Format: "+$X,XXX.XX" or "-$X,XXX.XX" (always shows sign, 2 decimals)
550
- * @example formatPnl(1234.56) => "+$1,234.56"
551
- * @example formatPnl(-500) => "-$500.00"
552
- * @example formatPnl(0) => "+$0.00"
553
- */
554
- const formatPnl = (pnl) => {
555
- const parsedValue = typeof pnl === 'string' ? parseFloat(pnl) : pnl;
556
- if (isNaN(parsedValue)) {
557
- return perpsConfig_1.PERPS_CONSTANTS.ZeroAmountDetailedDisplay;
558
- }
559
- const formatted = getIntlNumberFormatter('en-US', {
560
- style: 'currency',
561
- currency: 'USD',
562
- minimumFractionDigits: 2,
563
- maximumFractionDigits: 2,
564
- }).format(Math.abs(parsedValue));
565
- return parsedValue >= 0 ? `+${formatted}` : `-${formatted}`;
566
- };
567
- exports.formatPnl = formatPnl;
568
- /**
569
- * Formats a percentage value with sign prefix
570
- *
571
- * @param value - Raw percentage value (e.g., 5.25 for 5.25%, not 0.0525)
572
- * @param decimals - Number of decimal places to show (default: 2)
573
- * @returns Format: "+X.XX%" or "-X.XX%" (always shows sign, 2 decimals)
574
- * @example formatPercentage(5.25) => "+5.25%"
575
- * @example formatPercentage(-2.75) => "-2.75%"
576
- * @example formatPercentage(0) => "+0.00%"
577
- */
578
- const formatPercentage = (value, decimals = 2) => {
579
- const parsedValue = typeof value === 'string' ? parseFloat(value) : value;
580
- if (isNaN(parsedValue)) {
581
- return '0.00%';
582
- }
583
- return `${parsedValue >= 0 ? '+' : ''}${parsedValue.toFixed(decimals)}%`;
584
- };
585
- exports.formatPercentage = formatPercentage;
586
- /**
587
- * Formats funding rate for display
588
- *
589
- * @param value - Raw funding rate value (decimal, not percentage)
590
- * @param options - Optional formatting options
591
- * @param options.showZero - Whether to return zero display value for zero/undefined (default: true)
592
- * @returns Formatted funding rate as percentage string
593
- * @example formatFundingRate(0.0005) => "0.0500%"
594
- * @example formatFundingRate(-0.0001) => "-0.0100%"
595
- * @example formatFundingRate(undefined) => "0.0000%"
596
- */
597
- const formatFundingRate = (value, options) => {
598
- const showZero = options?.showZero ?? true;
599
- if (value === undefined || value === null) {
600
- return showZero ? perpsConfig_1.FUNDING_RATE_CONFIG.ZeroDisplay : '';
601
- }
602
- const percentage = value * perpsConfig_1.FUNDING_RATE_CONFIG.PercentageMultiplier;
603
- const formatted = percentage.toFixed(perpsConfig_1.FUNDING_RATE_CONFIG.Decimals);
604
- // Check if the result is effectively zero
605
- if (showZero && parseFloat(formatted) === 0) {
606
- return perpsConfig_1.FUNDING_RATE_CONFIG.ZeroDisplay;
607
- }
608
- return `${formatted}%`;
609
- };
610
- exports.formatFundingRate = formatFundingRate;
611
- /**
612
- * Default large number range configurations
613
- * Applied in order from largest to smallest
614
- */
615
- exports.DEFAULT_LARGE_NUMBER_RANGES = [
616
- {
617
- threshold: 1000000000000, // >= 1T
618
- suffix: 'T',
619
- decimals: 0,
620
- },
621
- {
622
- threshold: 1000000000, // >= 1B
623
- suffix: 'B',
624
- decimals: 0,
625
- },
626
- {
627
- threshold: 1000000, // >= 1M
628
- suffix: 'M',
629
- decimals: 0,
630
- },
631
- {
632
- threshold: 1000, // >= 1K
633
- suffix: 'K',
634
- decimals: 0,
635
- },
636
- {
637
- threshold: 0, // < 1K (all remaining numbers)
638
- suffix: '',
639
- decimals: 2,
640
- },
641
- ];
642
- /**
643
- * Preset for detailed large number formatting with more decimal precision
644
- * Useful for displaying precise statistics or detailed financial data
645
- */
646
- exports.LARGE_NUMBER_RANGES_DETAILED = [
647
- {
648
- threshold: 1000000000000, // >= 1T
649
- suffix: 'T',
650
- decimals: 2,
651
- },
652
- {
653
- threshold: 1000000000, // >= 1B
654
- suffix: 'B',
655
- decimals: 2,
656
- },
657
- {
658
- threshold: 1000000, // >= 1M
659
- suffix: 'M',
660
- decimals: 2,
661
- },
662
- {
663
- threshold: 1000, // >= 1K
664
- suffix: 'K',
665
- decimals: 0,
666
- },
667
- {
668
- threshold: 0, // < 1K (all remaining numbers)
669
- suffix: '',
670
- decimals: 0,
671
- },
672
- ];
673
- /**
674
- * Formats large numbers with magnitude suffixes (K, M, B, T)
675
- *
676
- * @param value - The number to format
677
- * @param options - Optional formatting options
678
- * @param options.decimals - Legacy: Number of decimal places for all suffixed values (overrides range configs)
679
- * @param options.rawDecimals - Legacy: Number of decimal places for numbers below all thresholds (overrides range config for threshold: 0)
680
- * @param options.ranges - Custom range configurations for fine-grained control over decimals per range
681
- * @returns Formatted string with appropriate suffix
682
- * @example
683
- * // Using defaults
684
- * formatLargeNumber(1500000) => "2M"
685
- * formatLargeNumber(1234) => "1K"
686
- * formatLargeNumber(999) => "999.00"
687
- *
688
- * // Legacy: same decimals for all ranges
689
- * formatLargeNumber(1500000, { decimals: 1 }) => "1.5M"
690
- * formatLargeNumber(1234, { decimals: 2 }) => "1.23K"
691
- *
692
- * // New: custom decimals per range (including all remaining numbers)
693
- * formatLargeNumber(1500000, {
694
- * ranges: [
695
- * { threshold: 1000000000000, suffix: 'T', decimals: 2 },
696
- * { threshold: 1000000000, suffix: 'B', decimals: 1 },
697
- * { threshold: 1000000, suffix: 'M', decimals: 1 },
698
- * { threshold: 1000, suffix: 'K', decimals: 0 },
699
- * { threshold: 0, suffix: '', decimals: 4 }, // < 1K (all remaining numbers)
700
- * ]
701
- * }) => "1.5M"
702
- */
703
- const formatLargeNumber = (value, options) => {
704
- const parsedValue = typeof value === 'string' ? parseFloat(value) : value;
705
- const ranges = options?.ranges ?? exports.DEFAULT_LARGE_NUMBER_RANGES;
706
- if (isNaN(parsedValue)) {
707
- return '0';
708
- }
709
- const absValue = Math.abs(parsedValue);
710
- const sign = parsedValue < 0 ? '-' : '';
711
- // Check each range in order
712
- for (const range of ranges) {
713
- if (absValue >= range.threshold) {
714
- // Calculate divisor based on threshold (or 1 for no scaling)
715
- const divisor = range.threshold > 0 ? range.threshold : 1;
716
- const scaledValue = absValue / divisor;
717
- // Determine decimals to use
718
- let decimalPlaces = range.decimals;
719
- // Legacy support: override with options.decimals for suffixed values
720
- if (options?.decimals !== undefined && range.suffix !== '') {
721
- decimalPlaces = options.decimals;
722
- }
723
- // Legacy support: override with options.rawDecimals for non-suffixed values
724
- if (options?.rawDecimals !== undefined && range.suffix === '') {
725
- decimalPlaces = options.rawDecimals;
726
- }
727
- return `${sign}${scaledValue.toFixed(decimalPlaces)}${range.suffix}`;
728
- }
729
- }
730
- // This should never be reached if ranges includes a threshold: 0 entry
731
- // But keep as fallback for safety
732
- return parsedValue.toFixed(options?.rawDecimals ?? 2);
733
- };
734
- exports.formatLargeNumber = formatLargeNumber;
735
- /**
736
- * Formats volume with appropriate magnitude suffixes
737
- *
738
- * @param volume - Raw volume value
739
- * @param decimals - Number of decimal places to show (optional, auto-determined by default)
740
- * @returns Format: "$XB" / "$X.XXM" / "$XK" / "$X.XX"
741
- * @example formatVolume(1234567890) => "$1.23B"
742
- * @example formatVolume(12345678) => "$12.35M"
743
- * @example formatVolume(123456) => "$123K"
744
- */
745
- const formatVolume = (volume, decimals) => {
746
- const parsedValue = typeof volume === 'string' ? parseFloat(volume) : volume;
747
- // Handle invalid inputs - return fallback display for NaN/Infinity
748
- if (isNaN(parsedValue) || !isFinite(parsedValue)) {
749
- return '$---';
750
- }
751
- const absValue = Math.abs(parsedValue);
752
- // Auto-determine decimals based on magnitude if not specified
753
- let autoDecimals;
754
- if (decimals === undefined) {
755
- if (absValue >= 1000000000) {
756
- // Billions: 2 decimals
757
- autoDecimals = 2;
758
- }
759
- else if (absValue >= 1000000) {
760
- // Millions: 2 decimals
761
- autoDecimals = 2;
762
- }
763
- else if (absValue >= 1000) {
764
- // Thousands: 0 decimals
765
- autoDecimals = 0;
766
- }
767
- else {
768
- // Under 1000: 2 decimals
769
- autoDecimals = 2;
770
- }
771
- }
772
- else {
773
- autoDecimals = decimals;
774
- }
775
- const formatted = (0, exports.formatLargeNumber)(volume, {
776
- decimals: autoDecimals,
777
- rawDecimals: autoDecimals,
778
- });
779
- // Handle negative values - ensure dollar sign comes after negative sign
780
- if (formatted.startsWith('-')) {
781
- return `-$${formatted.slice(1)}`;
782
- }
783
- return `$${formatted}`;
784
- };
785
- exports.formatVolume = formatVolume;
786
- /**
787
- * Formats position size with variable decimal precision based on magnitude or asset-specific decimals
788
- * Removes trailing zeros to match task requirements
789
- *
790
- * @param size - Raw position size value
791
- * @param szDecimals - Optional asset-specific decimal precision from Hyperliquid metadata (e.g., BTC=5, ETH=4, DOGE=1)
792
- * @returns Format varies by size or uses asset-specific decimals, with trailing zeros removed:
793
- * If szDecimals provided: Uses exact decimals (e.g., 0.00009 BTC with szDecimals=5 => "0.00009")
794
- * Otherwise falls back to magnitude-based logic:
795
- * - Size < 0.01: Up to 6 decimals (e.g., "0.00009" not "0.000090")
796
- * - Size < 1: Up to 4 decimals (e.g., "0.0024" not "0.002400")
797
- * - Size >= 1: Up to 2 decimals (e.g., "44" not "44.00")
798
- * @example formatPositionSize(0.00009, 5) => "0.00009" (uses szDecimals)
799
- * @example formatPositionSize(44.00, 1) => "44" (uses szDecimals, trailing zeros removed)
800
- * @example formatPositionSize(0.0024) => "0.0024" (no szDecimals, uses magnitude logic)
801
- * @example formatPositionSize(44.00) => "44" (no szDecimals, uses magnitude logic)
802
- */
803
- const formatPositionSize = (size, szDecimals) => {
804
- const parsedValue = typeof size === 'string' ? parseFloat(size) : size;
805
- if (isNaN(parsedValue) || parsedValue === 0) {
806
- return '0';
807
- }
808
- // Use asset-specific decimals if provided (Hyperliquid metadata)
809
- if (szDecimals !== undefined) {
810
- return parsedValue.toFixed(szDecimals).replace(/\.?0+$/u, '');
811
- }
812
- // Fallback: magnitude-based decimal logic for backwards compatibility
813
- const absValue = Math.abs(parsedValue);
814
- let formatted;
815
- if (absValue < 0.01) {
816
- // For very small numbers, use more decimal places
817
- formatted = parsedValue.toFixed(6);
818
- }
819
- else if (absValue < 1) {
820
- // For small numbers, use 4 decimal places
821
- formatted = parsedValue.toFixed(4);
822
- }
823
- else {
824
- // For normal numbers, use 2 decimal places
825
- formatted = parsedValue.toFixed(2);
826
- }
827
- // Remove trailing zeros and unnecessary decimal point
828
- return formatted.replace(/\.?0+$/u, '');
829
- };
830
- exports.formatPositionSize = formatPositionSize;
831
- /**
832
- * Formats leverage value with 'x' suffix
833
- *
834
- * @param leverage - Raw leverage multiplier value
835
- * @returns Format: "X.Xx" (1 decimal place with 'x' suffix)
836
- * @example formatLeverage(5) => "5.0x"
837
- * @example formatLeverage(10.5) => "10.5x"
838
- * @example formatLeverage(1) => "1.0x"
839
- */
840
- const formatLeverage = (leverage) => {
841
- const parsedValue = typeof leverage === 'string' ? parseFloat(leverage) : leverage;
842
- if (isNaN(parsedValue)) {
843
- return '1x';
844
- }
845
- return `${parsedValue.toFixed(1)}x`;
846
- };
847
- exports.formatLeverage = formatLeverage;
848
- /**
849
- * Parses formatted currency strings back to numeric values
850
- *
851
- * @param formattedValue - Formatted currency string (handles $, commas, negative values)
852
- * @returns Raw numeric value
853
- * @example parseCurrencyString("$1,234.56") => 1234.56
854
- * @example parseCurrencyString("-$500.00") => -500
855
- * @example parseCurrencyString("$-123.45") => -123.45
856
- */
857
- const parseCurrencyString = (formattedValue) => {
858
- if (!formattedValue) {
859
- return 0;
860
- }
861
- // Check for negative values (can be -$123.45 or $-123.45)
862
- const isNegative = formattedValue.includes('-');
863
- // Remove all non-numeric characters except dots
864
- // This regex removes currency symbols ($, etc.), commas, minus signs, and other formatting
865
- const cleanedValue = formattedValue
866
- .replace(/[^0-9.]/gu, '') // Remove everything except digits and dots
867
- .trim();
868
- // Handle multiple dots by keeping only the last one as decimal separator
869
- // NOTE: This assumes US format (comma for thousands, dot for decimal)
870
- // Numbers with dots as thousand separators (e.g., European format) will be parsed incorrectly
871
- const parts = cleanedValue.split('.');
872
- const integerPart = parts[0] || '0';
873
- const decimalPart = parts.length > 1 ? parts[parts.length - 1] : '';
874
- const finalValue = decimalPart
875
- ? `${integerPart}.${decimalPart}`
876
- : integerPart;
877
- const parsedResult = parseFloat(finalValue);
878
- if (isNaN(parsedResult)) {
879
- return 0;
880
- }
881
- return isNegative ? -parsedResult : parsedResult;
882
- };
883
- exports.parseCurrencyString = parseCurrencyString;
884
- /**
885
- * Parses formatted percentage strings back to numeric values
886
- *
887
- * @param formattedValue - Formatted percentage string (handles %, +/- signs)
888
- * @returns Raw numeric percentage value
889
- * @example parsePercentageString("+2.50%") => 2.5
890
- * @example parsePercentageString("-10.75%") => -10.75
891
- * @example parsePercentageString("5%") => 5
892
- */
893
- const parsePercentageString = (formattedValue) => {
894
- if (!formattedValue) {
895
- return 0;
896
- }
897
- const cleanedValue = formattedValue
898
- .replace(/%/gu, '')
899
- .replace(/\s/gu, '')
900
- .trim();
901
- const parsedResult = parseFloat(cleanedValue);
902
- return isNaN(parsedResult) ? 0 : parsedResult;
903
- };
904
- exports.parsePercentageString = parsePercentageString;
905
- /**
906
- * Formats a timestamp for transaction detail views with time
907
- *
908
- * @param timestamp - Unix timestamp in milliseconds
909
- * @returns Formatted date string with time (e.g., "July 24, 2025 at 2:30 PM")
910
- * @example formatTransactionDate(1642492800000) => "January 18, 2022 at 12:00 AM"
911
- */
912
- const formatTransactionDate = (timestamp) => {
913
- const date = new Date(timestamp);
914
- const dateStr = getIntlDateTimeFormatter('en-US', {
915
- year: 'numeric',
916
- month: 'long',
917
- day: 'numeric',
918
- }).format(date);
919
- const timeStr = getIntlDateTimeFormatter('en-US', {
920
- hour: 'numeric',
921
- minute: '2-digit',
922
- hour12: true,
923
- }).format(date);
924
- return `${dateStr} at ${timeStr}`;
925
- };
926
- exports.formatTransactionDate = formatTransactionDate;
927
- /**
928
- * Formats a timestamp for order cards with time
929
- *
930
- * @param timestamp - Unix timestamp in milliseconds
931
- * @returns Formatted date string with time (e.g., "Jan 18 at 2:30 PM")
932
- * @example formatOrderCardDate(1642492800000) => "Jan 18 at 12:00 AM"
933
- */
934
- const formatOrderCardDate = (timestamp) => {
935
- const date = new Date(timestamp);
936
- const dateStr = getIntlDateTimeFormatter('en-US', {
937
- month: 'short',
938
- day: 'numeric',
939
- }).format(date);
940
- const timeStr = getIntlDateTimeFormatter('en-US', {
941
- hour: 'numeric',
942
- minute: '2-digit',
943
- hour12: true,
944
- }).format(date);
945
- return `${dateStr} at ${timeStr}`;
946
- };
947
- exports.formatOrderCardDate = formatOrderCardDate;
948
- /**
949
- * Formats a timestamp for transaction section headers
950
- *
951
- * @param timestamp - Unix timestamp in milliseconds
952
- * @param labels - Localized labels for "Today" and "Yesterday"
953
- * @param labels.today - Label text for today
954
- * @param labels.yesterday - Label text for yesterday
955
- * @returns Formatted date section string ("Today", "Yesterday", or "Month Day")
956
- * @example formatDateSection(Date.now(), { today: 'Today', yesterday: 'Yesterday' }) => "Today"
957
- */
958
- const formatDateSection = (timestamp, labels = {
959
- today: 'Today',
960
- yesterday: 'Yesterday',
961
- }) => {
962
- const date = new Date(timestamp);
963
- const today = new Date();
964
- const yesterday = new Date(today);
965
- yesterday.setDate(yesterday.getDate() - 1);
966
- // Check if it's today
967
- if (date.getDate() === today.getDate() &&
968
- date.getMonth() === today.getMonth() &&
969
- date.getFullYear() === today.getFullYear()) {
970
- return labels.today;
971
- }
972
- // Check if it's yesterday
973
- if (date.getDate() === yesterday.getDate() &&
974
- date.getMonth() === yesterday.getMonth() &&
975
- date.getFullYear() === yesterday.getFullYear()) {
976
- return labels.yesterday;
977
- }
978
- const month = getIntlDateTimeFormatter('en-US', {
979
- month: 'short',
980
- }).format(new Date(timestamp));
981
- const day = getIntlDateTimeFormatter('en-US', {
982
- day: 'numeric',
983
- }).format(new Date(timestamp));
984
- return `${month} ${day}`; // 'Jul 26'
985
- };
986
- exports.formatDateSection = formatDateSection;
987
- //# sourceMappingURL=formatUtils.cjs.map