@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,505 +0,0 @@
1
- "use strict";
2
- /**
3
- * Utility functions for validating Take Profit and Stop Loss prices based on position direction
4
- *
5
- * For Long positions:
6
- * - Take Profit must be above current price (profit when price goes up)
7
- * - Stop Loss must be below current price (loss when price goes down)
8
- *
9
- * For Short positions:
10
- * - Take Profit must be below current price (profit when price goes down)
11
- * - Stop Loss must be above current price (loss when price goes up)
12
- */
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.sanitizePercentageInput = exports.isValidStopLossPercentage = exports.getMaxStopLossPercentage = exports.formatRoEPercentageDisplay = exports.safeParseRoEPercentage = exports.calculateRoEForPrice = exports.calculatePriceForRoE = exports.hasTPSLValuesChanged = exports.calculatePercentageForPrice = exports.calculatePriceForPercentage = exports.getStopLossLiquidationErrorDirection = exports.getStopLossErrorDirection = exports.getTakeProfitErrorDirection = exports.validateTPSLPrices = exports.isStopLossSafeFromLiquidation = exports.isValidStopLossPrice = exports.isValidTakeProfitPrice = exports.roundToSignificantFigures = exports.hasExceededSignificantFigures = exports.countSignificantFigures = void 0;
15
- const perpsConfig_1 = require("../constants/perpsConfig.cjs");
16
- // Re-export significant figures utilities from formatUtils for backwards compatibility
17
- // These utilities are now consolidated in formatUtils.ts to avoid duplication
18
- var formatUtils_1 = require("./formatUtils.cjs");
19
- Object.defineProperty(exports, "countSignificantFigures", { enumerable: true, get: function () { return formatUtils_1.countSignificantFigures; } });
20
- Object.defineProperty(exports, "hasExceededSignificantFigures", { enumerable: true, get: function () { return formatUtils_1.hasExceededSignificantFigures; } });
21
- Object.defineProperty(exports, "roundToSignificantFigures", { enumerable: true, get: function () { return formatUtils_1.roundToSignificantFigures; } });
22
- /**
23
- * Validates if a take profit price is valid for the given direction.
24
- *
25
- * @param price - The take profit price to validate
26
- * @param validationParams - Validation parameters
27
- * @param validationParams.currentPrice - The current market price
28
- * @param validationParams.direction - The position direction (long or short)
29
- * @returns True if the take profit price is valid, false otherwise
30
- */
31
- const isValidTakeProfitPrice = (price, { currentPrice, direction }) => {
32
- if (!currentPrice || !direction || !price) {
33
- return true;
34
- }
35
- const tpPrice = parseFloat(price.replace(/[$,]/gu, ''));
36
- if (isNaN(tpPrice)) {
37
- return true;
38
- }
39
- const isLong = direction === 'long';
40
- return isLong ? tpPrice > currentPrice : tpPrice < currentPrice;
41
- };
42
- exports.isValidTakeProfitPrice = isValidTakeProfitPrice;
43
- /**
44
- * Validates if a stop loss price is valid for the given direction.
45
- *
46
- * @param price - The stop loss price to validate
47
- * @param validationParams - Validation parameters
48
- * @param validationParams.currentPrice - The current market price
49
- * @param validationParams.direction - The position direction (long or short)
50
- * @returns True if the stop loss price is valid, false otherwise
51
- */
52
- const isValidStopLossPrice = (price, { currentPrice, direction }) => {
53
- if (!currentPrice || !direction || !price) {
54
- return true;
55
- }
56
- const slPrice = parseFloat(price.replace(/[$,]/gu, ''));
57
- if (isNaN(slPrice)) {
58
- return true;
59
- }
60
- const isLong = direction === 'long';
61
- return isLong ? slPrice < currentPrice : slPrice > currentPrice;
62
- };
63
- exports.isValidStopLossPrice = isValidStopLossPrice;
64
- /**
65
- * Validates if a stop loss price is within the liquidation price.
66
- * For long positions: stop loss must be ABOVE liquidation price.
67
- * For short positions: stop loss must be BELOW liquidation price.
68
- *
69
- * @param price - The stop loss price to validate
70
- * @param liquidationPrice - The liquidation price threshold
71
- * @param direction - The position direction (long or short)
72
- * @returns True if the stop loss is safe from liquidation, false otherwise
73
- */
74
- const isStopLossSafeFromLiquidation = (price, liquidationPrice, direction) => {
75
- if (!liquidationPrice || !direction || !price) {
76
- return true;
77
- }
78
- // Clean up string values if necessary ($ or ,)
79
- const slPriceNum = parseFloat(price.replace(/[$,]/gu, ''));
80
- const liquidationPriceNum = parseFloat(liquidationPrice.replace(/[$,]/gu, ''));
81
- if (isNaN(slPriceNum) || isNaN(liquidationPriceNum)) {
82
- return true;
83
- }
84
- const isLong = direction === 'long';
85
- return isLong
86
- ? slPriceNum > liquidationPriceNum
87
- : slPriceNum < liquidationPriceNum;
88
- };
89
- exports.isStopLossSafeFromLiquidation = isStopLossSafeFromLiquidation;
90
- /**
91
- * Validates both take profit and stop loss prices.
92
- *
93
- * @param takeProfitPrice - The take profit price to validate
94
- * @param stopLossPrice - The stop loss price to validate
95
- * @param params - Validation parameters including currentPrice, direction, and liquidationPrice
96
- * @returns True if both prices are valid, false otherwise
97
- */
98
- const validateTPSLPrices = (takeProfitPrice, stopLossPrice, params) => {
99
- if (!params.currentPrice || !params.direction) {
100
- return true;
101
- }
102
- let isValid = true;
103
- if (takeProfitPrice) {
104
- isValid = isValid && (0, exports.isValidTakeProfitPrice)(takeProfitPrice, params);
105
- }
106
- if (stopLossPrice) {
107
- isValid = isValid && (0, exports.isValidStopLossPrice)(stopLossPrice, params);
108
- }
109
- if (params.liquidationPrice) {
110
- isValid =
111
- isValid &&
112
- (0, exports.isStopLossSafeFromLiquidation)(stopLossPrice, params.liquidationPrice, params.direction);
113
- }
114
- return isValid;
115
- };
116
- exports.validateTPSLPrices = validateTPSLPrices;
117
- /**
118
- * Gets the direction text for take profit error message.
119
- *
120
- * @param direction - The position direction (long or short)
121
- * @returns Direction text (above/below) or empty string if no direction
122
- */
123
- const getTakeProfitErrorDirection = (direction) => {
124
- if (!direction) {
125
- return '';
126
- }
127
- return direction === 'long' ? 'above' : 'below';
128
- };
129
- exports.getTakeProfitErrorDirection = getTakeProfitErrorDirection;
130
- /**
131
- * Gets the direction text for stop loss error message.
132
- *
133
- * @param direction - The position direction (long or short)
134
- * @returns Direction text (below/above) or empty string if no direction
135
- */
136
- const getStopLossErrorDirection = (direction) => {
137
- if (!direction) {
138
- return '';
139
- }
140
- return direction === 'long' ? 'below' : 'above';
141
- };
142
- exports.getStopLossErrorDirection = getStopLossErrorDirection;
143
- /**
144
- * Gets the direction text for stop loss liquidation error message.
145
- *
146
- * @param direction - The position direction (long or short)
147
- * @returns Direction text (above/below) or empty string if no direction
148
- */
149
- const getStopLossLiquidationErrorDirection = (direction) => {
150
- if (!direction) {
151
- return '';
152
- }
153
- return direction === 'long' ? 'above' : 'below';
154
- };
155
- exports.getStopLossLiquidationErrorDirection = getStopLossLiquidationErrorDirection;
156
- /**
157
- * Calculates price based on percentage change from current price.
158
- *
159
- * @param percentage - The percentage change
160
- * @param isProfit - Whether this is for take profit (true) or stop loss (false)
161
- * @param validationParams - Validation parameters
162
- * @param validationParams.currentPrice - The current market price
163
- * @param validationParams.direction - The position direction (long or short)
164
- * @returns The calculated price as a string
165
- */
166
- const calculatePriceForPercentage = (percentage, isProfit, { currentPrice, direction }) => {
167
- if (!currentPrice) {
168
- return '';
169
- }
170
- // For long positions: profit = price up, loss = price down
171
- // For short positions: profit = price down, loss = price up
172
- const isLong = direction === 'long';
173
- const profitMultiplier = isLong ? 1 + percentage / 100 : 1 - percentage / 100;
174
- const lossMultiplier = isLong ? 1 - percentage / 100 : 1 + percentage / 100;
175
- const multiplier = isProfit ? profitMultiplier : lossMultiplier;
176
- const calculatedPrice = currentPrice * multiplier;
177
- // Return raw number string without formatting
178
- return calculatedPrice.toFixed(2);
179
- };
180
- exports.calculatePriceForPercentage = calculatePriceForPercentage;
181
- /**
182
- * Calculates percentage change based on target price.
183
- *
184
- * @param price - The target price (as string, may include formatting)
185
- * @param isProfit - Whether this is for take profit (true) or stop loss (false)
186
- * @param validationParams - Validation parameters
187
- * @param validationParams.currentPrice - The current market price
188
- * @param validationParams.direction - The position direction (long or short)
189
- * @returns The percentage as a string
190
- */
191
- const calculatePercentageForPrice = (price, isProfit, { currentPrice, direction }) => {
192
- if (!currentPrice || !price) {
193
- return '';
194
- }
195
- const priceNum = parseFloat(price.replace(/[$,]/gu, ''));
196
- if (isNaN(priceNum)) {
197
- return '';
198
- }
199
- const isLong = direction === 'long';
200
- const priceDiff = priceNum - currentPrice;
201
- const percentage = Math.abs((priceDiff / currentPrice) * 100);
202
- // Validate direction consistency
203
- if (isProfit) {
204
- // For profit: long needs higher price, short needs lower price
205
- const isValidDirection = isLong ? priceDiff > 0 : priceDiff < 0;
206
- return isValidDirection
207
- ? percentage.toFixed(2)
208
- : `-${percentage.toFixed(2)}`;
209
- }
210
- // For loss: long needs lower price, short needs higher price
211
- const isValidDirection = isLong ? priceDiff < 0 : priceDiff > 0;
212
- return isValidDirection ? percentage.toFixed(2) : `-${percentage.toFixed(2)}`;
213
- };
214
- exports.calculatePercentageForPrice = calculatePercentageForPrice;
215
- /**
216
- * Checks if take profit or stop loss values have changed from their initial values
217
- *
218
- * @param currentTakeProfitPrice Current take profit price value
219
- * @param currentStopLossPrice Current stop loss price value
220
- * @param initialTakeProfitPrice Initial take profit price value
221
- * @param initialStopLossPrice Initial stop loss price value
222
- * @returns true if either value has changed, false if both are unchanged
223
- */
224
- const hasTPSLValuesChanged = (currentTakeProfitPrice, currentStopLossPrice, initialTakeProfitPrice, initialStopLossPrice) => {
225
- // Normalize values - remove formatting, convert to numbers for comparison
226
- const normalizeValue = (value) => {
227
- if (!value || value.trim() === '') {
228
- return undefined;
229
- }
230
- const cleaned = value.replace(/[$,]/gu, '');
231
- const parsed = parseFloat(cleaned);
232
- return isNaN(parsed) ? undefined : parsed;
233
- };
234
- const normalizedCurrentTP = normalizeValue(currentTakeProfitPrice);
235
- const normalizedCurrentSL = normalizeValue(currentStopLossPrice);
236
- const normalizedInitialTP = normalizeValue(initialTakeProfitPrice);
237
- const normalizedInitialSL = normalizeValue(initialStopLossPrice);
238
- // Check if take profit has changed
239
- const tpChanged = normalizedCurrentTP !== normalizedInitialTP;
240
- // Check if stop loss has changed
241
- const slChanged = normalizedCurrentSL !== normalizedInitialSL;
242
- return tpChanged || slChanged;
243
- };
244
- exports.hasTPSLValuesChanged = hasTPSLValuesChanged;
245
- /**
246
- * Calculates the trigger price for a given RoE percentage.
247
- * RoE% = (PnL / marginUsed) * 100
248
- * PnL = (exitPrice - entryPrice) * size (for long)
249
- * PnL = (entryPrice - exitPrice) * size (for short)
250
- *
251
- * @param roePercentage - The target RoE percentage (e.g., 10 for +10%, -5 for -5%)
252
- * @param isProfit - Whether this is for take profit (true) or stop loss (false)
253
- * @param validationParams - Validation parameters
254
- * @param validationParams.currentPrice - The current market price
255
- * @param validationParams.direction - The position direction (long or short)
256
- * @param validationParams.leverage - The position leverage multiplier
257
- * @param validationParams.entryPrice - The entry price for existing positions
258
- * @returns The calculated trigger price as a string
259
- */
260
- const calculatePriceForRoE = (roePercentage, isProfit, { currentPrice, direction, leverage = 1, entryPrice }) => {
261
- // Use entry price if available (for existing positions), otherwise use current price
262
- const basePrice = entryPrice ?? currentPrice;
263
- if (!basePrice || basePrice <= 0 || !direction) {
264
- return '';
265
- }
266
- const isLong = direction === 'long';
267
- let adjustedRoePercentage = roePercentage;
268
- // Prevent stop loss from exceeding maximum possible loss
269
- // Maximum theoretical loss is 100% * leverage (before liquidation)
270
- // But we'll cap it at 99% to avoid negative prices
271
- if (!isProfit && Math.abs(roePercentage) >= leverage * 99) {
272
- // Cap at 99% of max loss to prevent negative prices
273
- adjustedRoePercentage = -(leverage * 99);
274
- }
275
- // RoE% = (PnL / marginUsed) * 100
276
- // PnL = RoE% * marginUsed / 100
277
- // marginUsed = positionValue / leverage
278
- // positionValue = entryPrice * size
279
- // Therefore: PnL = RoE% * (entryPrice * size) / (leverage * 100)
280
- // Simplifying: PnL/positionValue = RoE% / (leverage * 100)
281
- // priceChange/entryPrice = RoE% / (leverage * 100)
282
- // priceChange = entryPrice * RoE% / (leverage * 100)
283
- const priceChangeRatio = adjustedRoePercentage / (leverage * 100);
284
- let calculatedPrice;
285
- if (isProfit) {
286
- // For take profit
287
- if (isLong) {
288
- // Long TP: price needs to go up
289
- calculatedPrice = basePrice * (1 + priceChangeRatio);
290
- }
291
- else {
292
- // Short TP: price needs to go down
293
- calculatedPrice = basePrice * (1 - priceChangeRatio);
294
- }
295
- }
296
- else if (isLong) {
297
- // For stop loss (negative RoE)
298
- // Long SL: price needs to go down
299
- calculatedPrice = basePrice * (1 - -priceChangeRatio);
300
- // Ensure price never goes negative
301
- if (calculatedPrice <= 0) {
302
- calculatedPrice = basePrice * 0.01; // Minimum 1% of base price
303
- }
304
- }
305
- else {
306
- // Short SL: price needs to go up
307
- calculatedPrice = basePrice * (1 + -priceChangeRatio);
308
- }
309
- // Determine appropriate precision based on the price magnitude
310
- // For very small prices (like PEPE), use more decimal places
311
- let precision = 2;
312
- if (calculatedPrice < 0.01) {
313
- precision = 8; // For prices less than $0.01, use 8 decimal places
314
- }
315
- else if (calculatedPrice < 1) {
316
- precision = perpsConfig_1.DECIMAL_PRECISION_CONFIG.MaxPriceDecimals; // For prices less than $1, use MAX_PRICE_DECIMALS decimal places
317
- }
318
- else if (calculatedPrice < 100) {
319
- precision = 4; // For prices less than $100, use 4 decimal places
320
- }
321
- let finalResult = calculatedPrice.toFixed(precision);
322
- // Apply clean formatting - remove unnecessary trailing zeros and decimal point
323
- const numValue = parseFloat(finalResult);
324
- if (numValue % 1 === 0) {
325
- // If it's a whole number, show without decimals
326
- finalResult = numValue.toString();
327
- }
328
- else {
329
- // Otherwise, use the formatted result but remove trailing zeros
330
- finalResult = parseFloat(finalResult).toString();
331
- }
332
- return finalResult;
333
- };
334
- exports.calculatePriceForRoE = calculatePriceForRoE;
335
- /**
336
- * Calculates the RoE percentage for a given trigger price.
337
- *
338
- * @param price - The trigger price (as string, may include formatting)
339
- * @param isProfit - Whether this is for take profit (true) or stop loss (false)
340
- * @param isForPositionBoundTpsl - Whether this is for position bound TP/SL roe calculation
341
- * @param validationParams - Validation parameters
342
- * @param validationParams.currentPrice - The current market price
343
- * @param validationParams.direction - The position direction (long or short)
344
- * @param validationParams.leverage - The position leverage multiplier
345
- * @param validationParams.entryPrice - The entry price for existing positions
346
- * @returns The RoE percentage as a string
347
- */
348
- const calculateRoEForPrice = (price, isProfit, isForPositionBoundTpsl, { currentPrice, direction, leverage = 1, entryPrice }) => {
349
- // Use entry price if available (for existing positions), otherwise use current price
350
- const basePrice = entryPrice ?? currentPrice;
351
- if (!basePrice || basePrice <= 0 || !price || !direction) {
352
- return '';
353
- }
354
- const priceNum = parseFloat(price.replace(/[$,]/gu, ''));
355
- if (isNaN(priceNum) || priceNum <= 0) {
356
- return '';
357
- }
358
- const isLong = direction === 'long';
359
- // Calculate price change ratio
360
- const priceChangeRatio = (priceNum - basePrice) / basePrice;
361
- // RoE% = priceChangeRatio * leverage * 100
362
- let roePercentage = priceChangeRatio * leverage * 100;
363
- if (!isLong) {
364
- roePercentage = -roePercentage;
365
- }
366
- if (!isForPositionBoundTpsl &&
367
- ((isProfit && roePercentage < 0) || (!isProfit && roePercentage > 0))) {
368
- roePercentage = 0;
369
- }
370
- return roePercentage.toFixed(2);
371
- };
372
- exports.calculateRoEForPrice = calculateRoEForPrice;
373
- /**
374
- * Safely parse RoE percentage to avoid NaN display in UI
375
- *
376
- * @param roePercent - RoE percentage string from calculateRoEForPrice
377
- * @returns Formatted percentage string or empty string for invalid input
378
- */
379
- const safeParseRoEPercentage = (roePercent) => {
380
- if (!roePercent || roePercent.trim() === '') {
381
- return ''; // Return empty string for invalid input
382
- }
383
- const parsed = parseFloat(roePercent);
384
- if (isNaN(parsed)) {
385
- return ''; // Return empty string for NaN
386
- }
387
- // Show clean integers when possible (10% instead of 10.00%)
388
- return parsed % 1 === 0 ? parsed.toFixed(0) : parsed.toFixed(2);
389
- };
390
- exports.safeParseRoEPercentage = safeParseRoEPercentage;
391
- /**
392
- * Format RoE percentage for display based on focus state
393
- *
394
- * @param value - The raw percentage value as string
395
- * @param isFocused - Whether the input is currently focused
396
- * @returns Formatted percentage string for display
397
- */
398
- const formatRoEPercentageDisplay = (value, isFocused) => {
399
- if (!value || value.trim() === '') {
400
- return '';
401
- }
402
- // When focused, preserve the exact user input including signs and decimal points
403
- if (isFocused) {
404
- // Allow valid numeric patterns with optional sign and space
405
- if (value === '.' ||
406
- value === '+' ||
407
- value === '-' ||
408
- /^[+-]?\s?\d*\.?\d*$/u.test(value)) {
409
- return value;
410
- }
411
- }
412
- const parsed = parseFloat(value);
413
- if (isNaN(parsed)) {
414
- return '';
415
- }
416
- if (isFocused) {
417
- // This branch shouldn't be reached now, but keep as fallback
418
- return value;
419
- }
420
- // When not focused, show clean display format with appropriate sign
421
- const absValue = Math.abs(parsed);
422
- const formattedValue = absValue % 1 === 0 ? absValue.toFixed(0) : absValue.toFixed(2);
423
- // Always show sign for display
424
- if (parsed >= 0) {
425
- return `+ ${formattedValue}`;
426
- }
427
- return `- ${formattedValue}`;
428
- };
429
- exports.formatRoEPercentageDisplay = formatRoEPercentageDisplay;
430
- /**
431
- * Calculate the maximum allowed stop loss percentage based on leverage
432
- *
433
- * @param leverage The position leverage
434
- * @returns The maximum stop loss percentage (as a positive number)
435
- */
436
- const getMaxStopLossPercentage = (leverage) =>
437
- // Maximum theoretical loss is 100% * leverage (before liquidation)
438
- // But we cap it at 99% to avoid negative prices and leave room for fees
439
- Math.min(leverage * 99, 999);
440
- exports.getMaxStopLossPercentage = getMaxStopLossPercentage;
441
- /**
442
- * Validate if a stop loss percentage is within allowed bounds
443
- *
444
- * @param percentage The stop loss percentage (as a positive number)
445
- * @param leverage The position leverage
446
- * @returns True if valid, false otherwise
447
- */
448
- const isValidStopLossPercentage = (percentage, leverage) => {
449
- if (percentage <= 0) {
450
- return false;
451
- }
452
- const maxAllowed = (0, exports.getMaxStopLossPercentage)(leverage);
453
- return percentage <= maxAllowed;
454
- };
455
- exports.isValidStopLossPercentage = isValidStopLossPercentage;
456
- /**
457
- * Sanitizes input text for percentage fields by handling signs and decimal points
458
- *
459
- * @param text - Raw input text
460
- * @param currentValue - Current field value for length comparison (optional)
461
- * @param maxDecimalPlaces - Maximum allowed decimal places (default: 5)
462
- * @returns Sanitized text with proper sign and decimal handling, or null if validation fails
463
- */
464
- const sanitizePercentageInput = (text, currentValue, maxDecimalPlaces = 5) => {
465
- // Allow numbers, decimal point, and plus/minus signs
466
- // Also handle en-dash (–) and em-dash (—) which might come from typing --
467
- const sanitized = text.replace(/[–—]/gu, '-').replace(/[^0-9.+-]/gu, '');
468
- // Handle sign placement - only allow at the beginning
469
- let finalValue = sanitized;
470
- if (sanitized.includes('+') || sanitized.includes('-')) {
471
- // Remove duplicate consecutive signs but keep the first one
472
- // e.g., "++" becomes "+", "--" becomes "-"
473
- finalValue = sanitized.replace(/([+-])\1+/gu, '$1');
474
- // Only do mixed sign cleanup if there are actually mixed signs
475
- // Check if there are different types of signs in the string
476
- const hasPlus = finalValue.includes('+');
477
- const hasMinus = finalValue.includes('-');
478
- if (hasPlus && hasMinus) {
479
- // Mixed signs - keep only the first sign
480
- const firstSignMatch = /[+-]/u.exec(finalValue);
481
- if (firstSignMatch) {
482
- const sign = firstSignMatch[0];
483
- const restOfString = finalValue.substring(1);
484
- const numberPart = restOfString.replace(/[+-]/gu, '');
485
- finalValue = numberPart ? sign + numberPart : sign;
486
- }
487
- }
488
- }
489
- // Prevent multiple decimal points
490
- const parts = finalValue.replace(/[+-]/gu, '').split('.');
491
- if (parts.length > 2) {
492
- return null;
493
- } // Return null for invalid input
494
- // Allow erasing but prevent adding when there are more than maxDecimalPlaces decimal places
495
- if (currentValue !== undefined) {
496
- const decimalPart = parts[1];
497
- if (decimalPart?.length > maxDecimalPlaces &&
498
- finalValue.length >= currentValue.length) {
499
- return null; // Return null to prevent the update
500
- }
501
- }
502
- return finalValue;
503
- };
504
- exports.sanitizePercentageInput = sanitizePercentageInput;
505
- //# sourceMappingURL=tpslValidation.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tpslValidation.cjs","sourceRoot":"","sources":["../../src/utils/tpslValidation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAEH,8DAAoE;AACpE,uFAAuF;AACvF,8EAA8E;AAC9E,iDAIuB;AAHrB,sHAAA,uBAAuB,OAAA;AACvB,4HAAA,6BAA6B,OAAA;AAC7B,wHAAA,yBAAyB,OAAA;AAW3B;;;;;;;;GAQG;AACI,MAAM,sBAAsB,GAAG,CACpC,KAAa,EACb,EAAE,YAAY,EAAE,SAAS,EAAoB,EACpC,EAAE;IACX,IAAI,CAAC,YAAY,IAAI,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CAAC,CAAC,CAAC;QAC7B,IACE,WAAW,EAAE,MAAM,GAAG,gBAAgB;YACtC,UAAU,CAAC,MAAM,IAAI,YAAY,CAAC,MAAM,EACxC,CAAC;YACD,OAAO,IAAI,CAAC,CAAC,oCAAoC;QACnD,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAlDW,QAAA,uBAAuB,2BAkDlC","sourcesContent":["/**\n * Utility functions for validating Take Profit and Stop Loss prices based on position direction\n *\n * For Long positions:\n * - Take Profit must be above current price (profit when price goes up)\n * - Stop Loss must be below current price (loss when price goes down)\n *\n * For Short positions:\n * - Take Profit must be below current price (profit when price goes down)\n * - Stop Loss must be above current price (loss when price goes up)\n */\n\nimport { DECIMAL_PRECISION_CONFIG } from '../constants/perpsConfig';\n// Re-export significant figures utilities from formatUtils for backwards compatibility\n// These utilities are now consolidated in formatUtils.ts to avoid duplication\nexport {\n countSignificantFigures,\n hasExceededSignificantFigures,\n roundToSignificantFigures,\n} from './formatUtils';\n\ntype ValidationParams = {\n currentPrice: number;\n direction?: 'long' | 'short';\n leverage?: number;\n entryPrice?: number; // For existing positions\n liquidationPrice?: string;\n};\n\n/**\n * Validates if a take profit price is valid for the given direction.\n *\n * @param price - The take profit price to validate\n * @param validationParams - Validation parameters\n * @param validationParams.currentPrice - The current market price\n * @param validationParams.direction - The position direction (long or short)\n * @returns True if the take profit price is valid, false otherwise\n */\nexport const isValidTakeProfitPrice = (\n price: string,\n { currentPrice, direction }: ValidationParams,\n): boolean => {\n if (!currentPrice || !direction || !price) {\n return true;\n }\n\n const tpPrice = parseFloat(price.replace(/[$,]/gu, ''));\n if (isNaN(tpPrice)) {\n return true;\n }\n\n const isLong = direction === 'long';\n return isLong ? tpPrice > currentPrice : tpPrice < currentPrice;\n};\n\n/**\n * Validates if a stop loss price is valid for the given direction.\n *\n * @param price - The stop loss price to validate\n * @param validationParams - Validation parameters\n * @param validationParams.currentPrice - The current market price\n * @param validationParams.direction - The position direction (long or short)\n * @returns True if the stop loss price is valid, false otherwise\n */\nexport const isValidStopLossPrice = (\n price: string,\n { currentPrice, direction }: ValidationParams,\n): boolean => {\n if (!currentPrice || !direction || !price) {\n return true;\n }\n\n const slPrice = parseFloat(price.replace(/[$,]/gu, ''));\n if (isNaN(slPrice)) {\n return true;\n }\n\n const isLong = direction === 'long';\n return isLong ? slPrice < currentPrice : slPrice > currentPrice;\n};\n\n/**\n * Validates if a stop loss price is within the liquidation price.\n * For long positions: stop loss must be ABOVE liquidation price.\n * For short positions: stop loss must be BELOW liquidation price.\n *\n * @param price - The stop loss price to validate\n * @param liquidationPrice - The liquidation price threshold\n * @param direction - The position direction (long or short)\n * @returns True if the stop loss is safe from liquidation, false otherwise\n */\nexport const isStopLossSafeFromLiquidation = (\n price?: string,\n liquidationPrice?: string,\n direction?: 'long' | 'short',\n): boolean => {\n if (!liquidationPrice || !direction || !price) {\n return true;\n }\n\n // Clean up string values if necessary ($ or ,)\n const slPriceNum = parseFloat(price.replace(/[$,]/gu, ''));\n const liquidationPriceNum = parseFloat(\n liquidationPrice.replace(/[$,]/gu, ''),\n );\n\n if (isNaN(slPriceNum) || isNaN(liquidationPriceNum)) {\n return true;\n }\n\n const isLong = direction === 'long';\n\n return isLong\n ? slPriceNum > liquidationPriceNum\n : slPriceNum < liquidationPriceNum;\n};\n\n/**\n * Validates both take profit and stop loss prices.\n *\n * @param takeProfitPrice - The take profit price to validate\n * @param stopLossPrice - The stop loss price to validate\n * @param params - Validation parameters including currentPrice, direction, and liquidationPrice\n * @returns True if both prices are valid, false otherwise\n */\nexport const validateTPSLPrices = (\n takeProfitPrice: string | undefined,\n stopLossPrice: string | undefined,\n params: ValidationParams,\n): boolean => {\n if (!params.currentPrice || !params.direction) {\n return true;\n }\n\n let isValid = true;\n\n if (takeProfitPrice) {\n isValid = isValid && isValidTakeProfitPrice(takeProfitPrice, params);\n }\n\n if (stopLossPrice) {\n isValid = isValid && isValidStopLossPrice(stopLossPrice, params);\n }\n\n if (params.liquidationPrice) {\n isValid =\n isValid &&\n isStopLossSafeFromLiquidation(\n stopLossPrice,\n params.liquidationPrice,\n params.direction,\n );\n }\n\n return isValid;\n};\n\n/**\n * Gets the direction text for take profit error message.\n *\n * @param direction - The position direction (long or short)\n * @returns Direction text (above/below) or empty string if no direction\n */\nexport const getTakeProfitErrorDirection = (\n direction?: 'long' | 'short',\n): string => {\n if (!direction) {\n return '';\n }\n return direction === 'long' ? 'above' : 'below';\n};\n\n/**\n * Gets the direction text for stop loss error message.\n *\n * @param direction - The position direction (long or short)\n * @returns Direction text (below/above) or empty string if no direction\n */\nexport const getStopLossErrorDirection = (\n direction?: 'long' | 'short',\n): string => {\n if (!direction) {\n return '';\n }\n return direction === 'long' ? 'below' : 'above';\n};\n\n/**\n * Gets the direction text for stop loss liquidation error message.\n *\n * @param direction - The position direction (long or short)\n * @returns Direction text (above/below) or empty string if no direction\n */\nexport const getStopLossLiquidationErrorDirection = (\n direction?: 'long' | 'short',\n): string => {\n if (!direction) {\n return '';\n }\n return direction === 'long' ? 'above' : 'below';\n};\n\n/**\n * Calculates price based on percentage change from current price.\n *\n * @param percentage - The percentage change\n * @param isProfit - Whether this is for take profit (true) or stop loss (false)\n * @param validationParams - Validation parameters\n * @param validationParams.currentPrice - The current market price\n * @param validationParams.direction - The position direction (long or short)\n * @returns The calculated price as a string\n */\nexport const calculatePriceForPercentage = (\n percentage: number,\n isProfit: boolean,\n { currentPrice, direction }: ValidationParams,\n): string => {\n if (!currentPrice) {\n return '';\n }\n\n // For long positions: profit = price up, loss = price down\n // For short positions: profit = price down, loss = price up\n const isLong = direction === 'long';\n const profitMultiplier = isLong ? 1 + percentage / 100 : 1 - percentage / 100;\n const lossMultiplier = isLong ? 1 - percentage / 100 : 1 + percentage / 100;\n const multiplier = isProfit ? profitMultiplier : lossMultiplier;\n\n const calculatedPrice = currentPrice * multiplier;\n // Return raw number string without formatting\n return calculatedPrice.toFixed(2);\n};\n\n/**\n * Calculates percentage change based on target price.\n *\n * @param price - The target price (as string, may include formatting)\n * @param isProfit - Whether this is for take profit (true) or stop loss (false)\n * @param validationParams - Validation parameters\n * @param validationParams.currentPrice - The current market price\n * @param validationParams.direction - The position direction (long or short)\n * @returns The percentage as a string\n */\nexport const calculatePercentageForPrice = (\n price: string,\n isProfit: boolean,\n { currentPrice, direction }: ValidationParams,\n): string => {\n if (!currentPrice || !price) {\n return '';\n }\n\n const priceNum = parseFloat(price.replace(/[$,]/gu, ''));\n if (isNaN(priceNum)) {\n return '';\n }\n\n const isLong = direction === 'long';\n const priceDiff = priceNum - currentPrice;\n const percentage = Math.abs((priceDiff / currentPrice) * 100);\n\n // Validate direction consistency\n if (isProfit) {\n // For profit: long needs higher price, short needs lower price\n const isValidDirection = isLong ? priceDiff > 0 : priceDiff < 0;\n return isValidDirection\n ? percentage.toFixed(2)\n : `-${percentage.toFixed(2)}`;\n }\n // For loss: long needs lower price, short needs higher price\n const isValidDirection = isLong ? priceDiff < 0 : priceDiff > 0;\n return isValidDirection ? percentage.toFixed(2) : `-${percentage.toFixed(2)}`;\n};\n\n/**\n * Checks if take profit or stop loss values have changed from their initial values\n *\n * @param currentTakeProfitPrice Current take profit price value\n * @param currentStopLossPrice Current stop loss price value\n * @param initialTakeProfitPrice Initial take profit price value\n * @param initialStopLossPrice Initial stop loss price value\n * @returns true if either value has changed, false if both are unchanged\n */\nexport const hasTPSLValuesChanged = (\n currentTakeProfitPrice: string | undefined,\n currentStopLossPrice: string | undefined,\n initialTakeProfitPrice: string | undefined,\n initialStopLossPrice: string | undefined,\n): boolean => {\n // Normalize values - remove formatting, convert to numbers for comparison\n const normalizeValue = (value: string | undefined): number | undefined => {\n if (!value || value.trim() === '') {\n return undefined;\n }\n const cleaned = value.replace(/[$,]/gu, '');\n const parsed = parseFloat(cleaned);\n return isNaN(parsed) ? undefined : parsed;\n };\n\n const normalizedCurrentTP = normalizeValue(currentTakeProfitPrice);\n const normalizedCurrentSL = normalizeValue(currentStopLossPrice);\n const normalizedInitialTP = normalizeValue(initialTakeProfitPrice);\n const normalizedInitialSL = normalizeValue(initialStopLossPrice);\n\n // Check if take profit has changed\n const tpChanged = normalizedCurrentTP !== normalizedInitialTP;\n\n // Check if stop loss has changed\n const slChanged = normalizedCurrentSL !== normalizedInitialSL;\n\n return tpChanged || slChanged;\n};\n\n/**\n * Calculates the trigger price for a given RoE percentage.\n * RoE% = (PnL / marginUsed) * 100\n * PnL = (exitPrice - entryPrice) * size (for long)\n * PnL = (entryPrice - exitPrice) * size (for short)\n *\n * @param roePercentage - The target RoE percentage (e.g., 10 for +10%, -5 for -5%)\n * @param isProfit - Whether this is for take profit (true) or stop loss (false)\n * @param validationParams - Validation parameters\n * @param validationParams.currentPrice - The current market price\n * @param validationParams.direction - The position direction (long or short)\n * @param validationParams.leverage - The position leverage multiplier\n * @param validationParams.entryPrice - The entry price for existing positions\n * @returns The calculated trigger price as a string\n */\nexport const calculatePriceForRoE = (\n roePercentage: number,\n isProfit: boolean,\n { currentPrice, direction, leverage = 1, entryPrice }: ValidationParams,\n): string => {\n // Use entry price if available (for existing positions), otherwise use current price\n const basePrice = entryPrice ?? currentPrice;\n if (!basePrice || basePrice <= 0 || !direction) {\n return '';\n }\n\n const isLong = direction === 'long';\n let adjustedRoePercentage = roePercentage;\n\n // Prevent stop loss from exceeding maximum possible loss\n // Maximum theoretical loss is 100% * leverage (before liquidation)\n // But we'll cap it at 99% to avoid negative prices\n if (!isProfit && Math.abs(roePercentage) >= leverage * 99) {\n // Cap at 99% of max loss to prevent negative prices\n adjustedRoePercentage = -(leverage * 99);\n }\n\n // RoE% = (PnL / marginUsed) * 100\n // PnL = RoE% * marginUsed / 100\n // marginUsed = positionValue / leverage\n // positionValue = entryPrice * size\n // Therefore: PnL = RoE% * (entryPrice * size) / (leverage * 100)\n // Simplifying: PnL/positionValue = RoE% / (leverage * 100)\n // priceChange/entryPrice = RoE% / (leverage * 100)\n // priceChange = entryPrice * RoE% / (leverage * 100)\n\n const priceChangeRatio = adjustedRoePercentage / (leverage * 100);\n\n let calculatedPrice: number;\n if (isProfit) {\n // For take profit\n if (isLong) {\n // Long TP: price needs to go up\n calculatedPrice = basePrice * (1 + priceChangeRatio);\n } else {\n // Short TP: price needs to go down\n calculatedPrice = basePrice * (1 - priceChangeRatio);\n }\n } else if (isLong) {\n // For stop loss (negative RoE)\n // Long SL: price needs to go down\n calculatedPrice = basePrice * (1 - -priceChangeRatio);\n // Ensure price never goes negative\n if (calculatedPrice <= 0) {\n calculatedPrice = basePrice * 0.01; // Minimum 1% of base price\n }\n } else {\n // Short SL: price needs to go up\n calculatedPrice = basePrice * (1 + -priceChangeRatio);\n }\n\n // Determine appropriate precision based on the price magnitude\n // For very small prices (like PEPE), use more decimal places\n let precision = 2;\n if (calculatedPrice < 0.01) {\n precision = 8; // For prices less than $0.01, use 8 decimal places\n } else if (calculatedPrice < 1) {\n precision = DECIMAL_PRECISION_CONFIG.MaxPriceDecimals; // For prices less than $1, use MAX_PRICE_DECIMALS decimal places\n } else if (calculatedPrice < 100) {\n precision = 4; // For prices less than $100, use 4 decimal places\n }\n\n let finalResult = calculatedPrice.toFixed(precision);\n\n // Apply clean formatting - remove unnecessary trailing zeros and decimal point\n const numValue = parseFloat(finalResult);\n if (numValue % 1 === 0) {\n // If it's a whole number, show without decimals\n finalResult = numValue.toString();\n } else {\n // Otherwise, use the formatted result but remove trailing zeros\n finalResult = parseFloat(finalResult).toString();\n }\n\n return finalResult;\n};\n\n/**\n * Calculates the RoE percentage for a given trigger price.\n *\n * @param price - The trigger price (as string, may include formatting)\n * @param isProfit - Whether this is for take profit (true) or stop loss (false)\n * @param isForPositionBoundTpsl - Whether this is for position bound TP/SL roe calculation\n * @param validationParams - Validation parameters\n * @param validationParams.currentPrice - The current market price\n * @param validationParams.direction - The position direction (long or short)\n * @param validationParams.leverage - The position leverage multiplier\n * @param validationParams.entryPrice - The entry price for existing positions\n * @returns The RoE percentage as a string\n */\nexport const calculateRoEForPrice = (\n price: string,\n isProfit: boolean,\n isForPositionBoundTpsl: boolean,\n { currentPrice, direction, leverage = 1, entryPrice }: ValidationParams,\n): string => {\n // Use entry price if available (for existing positions), otherwise use current price\n const basePrice = entryPrice ?? currentPrice;\n if (!basePrice || basePrice <= 0 || !price || !direction) {\n return '';\n }\n\n const priceNum = parseFloat(price.replace(/[$,]/gu, ''));\n if (isNaN(priceNum) || priceNum <= 0) {\n return '';\n }\n\n const isLong = direction === 'long';\n\n // Calculate price change ratio\n const priceChangeRatio = (priceNum - basePrice) / basePrice;\n\n // RoE% = priceChangeRatio * leverage * 100\n let roePercentage = priceChangeRatio * leverage * 100;\n if (!isLong) {\n roePercentage = -roePercentage;\n }\n\n if (\n !isForPositionBoundTpsl &&\n ((isProfit && roePercentage < 0) || (!isProfit && roePercentage > 0))\n ) {\n roePercentage = 0;\n }\n\n return roePercentage.toFixed(2);\n};\n\n/**\n * Safely parse RoE percentage to avoid NaN display in UI\n *\n * @param roePercent - RoE percentage string from calculateRoEForPrice\n * @returns Formatted percentage string or empty string for invalid input\n */\nexport const safeParseRoEPercentage = (roePercent: string): string => {\n if (!roePercent || roePercent.trim() === '') {\n return ''; // Return empty string for invalid input\n }\n\n const parsed = parseFloat(roePercent);\n if (isNaN(parsed)) {\n return ''; // Return empty string for NaN\n }\n\n // Show clean integers when possible (10% instead of 10.00%)\n return parsed % 1 === 0 ? parsed.toFixed(0) : parsed.toFixed(2);\n};\n\n/**\n * Format RoE percentage for display based on focus state\n *\n * @param value - The raw percentage value as string\n * @param isFocused - Whether the input is currently focused\n * @returns Formatted percentage string for display\n */\nexport const formatRoEPercentageDisplay = (\n value: string,\n isFocused: boolean,\n): string => {\n if (!value || value.trim() === '') {\n return '';\n }\n\n // When focused, preserve the exact user input including signs and decimal points\n if (isFocused) {\n // Allow valid numeric patterns with optional sign and space\n if (\n value === '.' ||\n value === '+' ||\n value === '-' ||\n /^[+-]?\\s?\\d*\\.?\\d*$/u.test(value)\n ) {\n return value;\n }\n }\n\n const parsed = parseFloat(value);\n if (isNaN(parsed)) {\n return '';\n }\n\n if (isFocused) {\n // This branch shouldn't be reached now, but keep as fallback\n return value;\n }\n\n // When not focused, show clean display format with appropriate sign\n const absValue = Math.abs(parsed);\n const formattedValue =\n absValue % 1 === 0 ? absValue.toFixed(0) : absValue.toFixed(2);\n\n // Always show sign for display\n if (parsed >= 0) {\n return `+ ${formattedValue}`;\n }\n return `- ${formattedValue}`;\n};\n\n/**\n * Calculate the maximum allowed stop loss percentage based on leverage\n *\n * @param leverage The position leverage\n * @returns The maximum stop loss percentage (as a positive number)\n */\nexport const getMaxStopLossPercentage = (leverage: number): number =>\n // Maximum theoretical loss is 100% * leverage (before liquidation)\n // But we cap it at 99% to avoid negative prices and leave room for fees\n Math.min(leverage * 99, 999);\n\n/**\n * Validate if a stop loss percentage is within allowed bounds\n *\n * @param percentage The stop loss percentage (as a positive number)\n * @param leverage The position leverage\n * @returns True if valid, false otherwise\n */\nexport const isValidStopLossPercentage = (\n percentage: number,\n leverage: number,\n): boolean => {\n if (percentage <= 0) {\n return false;\n }\n const maxAllowed = getMaxStopLossPercentage(leverage);\n return percentage <= maxAllowed;\n};\n\n/**\n * Sanitizes input text for percentage fields by handling signs and decimal points\n *\n * @param text - Raw input text\n * @param currentValue - Current field value for length comparison (optional)\n * @param maxDecimalPlaces - Maximum allowed decimal places (default: 5)\n * @returns Sanitized text with proper sign and decimal handling, or null if validation fails\n */\nexport const sanitizePercentageInput = (\n text: string,\n currentValue?: string,\n maxDecimalPlaces: number = 5,\n): string | null => {\n // Allow numbers, decimal point, and plus/minus signs\n // Also handle en-dash (–) and em-dash (—) which might come from typing --\n const sanitized = text.replace(/[–—]/gu, '-').replace(/[^0-9.+-]/gu, '');\n\n // Handle sign placement - only allow at the beginning\n let finalValue = sanitized;\n if (sanitized.includes('+') || sanitized.includes('-')) {\n // Remove duplicate consecutive signs but keep the first one\n // e.g., \"++\" becomes \"+\", \"--\" becomes \"-\"\n finalValue = sanitized.replace(/([+-])\\1+/gu, '$1');\n\n // Only do mixed sign cleanup if there are actually mixed signs\n // Check if there are different types of signs in the string\n const hasPlus = finalValue.includes('+');\n const hasMinus = finalValue.includes('-');\n if (hasPlus && hasMinus) {\n // Mixed signs - keep only the first sign\n const firstSignMatch = /[+-]/u.exec(finalValue);\n if (firstSignMatch) {\n const sign = firstSignMatch[0];\n const restOfString = finalValue.substring(1);\n const numberPart = restOfString.replace(/[+-]/gu, '');\n finalValue = numberPart ? sign + numberPart : sign;\n }\n }\n }\n\n // Prevent multiple decimal points\n const parts = finalValue.replace(/[+-]/gu, '').split('.');\n if (parts.length > 2) {\n return null;\n } // Return null for invalid input\n\n // Allow erasing but prevent adding when there are more than maxDecimalPlaces decimal places\n if (currentValue !== undefined) {\n const decimalPart = parts[1];\n if (\n decimalPart?.length > maxDecimalPlaces &&\n finalValue.length >= currentValue.length\n ) {\n return null; // Return null to prevent the update\n }\n }\n\n return finalValue;\n};\n"]}