@metamask-previews/perps-controller 0.0.0-preview-b0148922a → 0.0.0-preview-ee1fa5d01

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (482) hide show
  1. package/CHANGELOG.md +0 -25
  2. package/dist/PerpsController.cjs +65 -3077
  3. package/dist/PerpsController.cjs.map +1 -1
  4. package/dist/PerpsController.d.cts +82 -969
  5. package/dist/PerpsController.d.cts.map +1 -1
  6. package/dist/PerpsController.d.mts +82 -969
  7. package/dist/PerpsController.d.mts.map +1 -1
  8. package/dist/PerpsController.mjs +62 -3073
  9. package/dist/PerpsController.mjs.map +1 -1
  10. package/dist/index.cjs +1 -63
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +2 -38
  13. package/dist/index.d.cts.map +1 -1
  14. package/dist/index.d.mts +2 -38
  15. package/dist/index.d.mts.map +1 -1
  16. package/dist/index.mjs +1 -46
  17. package/dist/index.mjs.map +1 -1
  18. package/package.json +2 -16
  19. package/dist/aggregation/SubscriptionMultiplexer.cjs +0 -441
  20. package/dist/aggregation/SubscriptionMultiplexer.cjs.map +0 -1
  21. package/dist/aggregation/SubscriptionMultiplexer.d.cts +0 -171
  22. package/dist/aggregation/SubscriptionMultiplexer.d.cts.map +0 -1
  23. package/dist/aggregation/SubscriptionMultiplexer.d.mts +0 -171
  24. package/dist/aggregation/SubscriptionMultiplexer.d.mts.map +0 -1
  25. package/dist/aggregation/SubscriptionMultiplexer.mjs +0 -437
  26. package/dist/aggregation/SubscriptionMultiplexer.mjs.map +0 -1
  27. package/dist/aggregation/index.cjs +0 -9
  28. package/dist/aggregation/index.cjs.map +0 -1
  29. package/dist/aggregation/index.d.cts +0 -6
  30. package/dist/aggregation/index.d.cts.map +0 -1
  31. package/dist/aggregation/index.d.mts +0 -6
  32. package/dist/aggregation/index.d.mts.map +0 -1
  33. package/dist/aggregation/index.mjs +0 -5
  34. package/dist/aggregation/index.mjs.map +0 -1
  35. package/dist/constants/chartConfig.cjs +0 -227
  36. package/dist/constants/chartConfig.cjs.map +0 -1
  37. package/dist/constants/chartConfig.d.cts +0 -216
  38. package/dist/constants/chartConfig.d.cts.map +0 -1
  39. package/dist/constants/chartConfig.d.mts +0 -216
  40. package/dist/constants/chartConfig.d.mts.map +0 -1
  41. package/dist/constants/chartConfig.mjs +0 -221
  42. package/dist/constants/chartConfig.mjs.map +0 -1
  43. package/dist/constants/eventNames.cjs +0 -436
  44. package/dist/constants/eventNames.cjs.map +0 -1
  45. package/dist/constants/eventNames.d.cts +0 -387
  46. package/dist/constants/eventNames.d.cts.map +0 -1
  47. package/dist/constants/eventNames.d.mts +0 -387
  48. package/dist/constants/eventNames.d.mts.map +0 -1
  49. package/dist/constants/eventNames.mjs +0 -433
  50. package/dist/constants/eventNames.mjs.map +0 -1
  51. package/dist/constants/hyperLiquidConfig.cjs +0 -380
  52. package/dist/constants/hyperLiquidConfig.cjs.map +0 -1
  53. package/dist/constants/hyperLiquidConfig.d.cts +0 -236
  54. package/dist/constants/hyperLiquidConfig.d.cts.map +0 -1
  55. package/dist/constants/hyperLiquidConfig.d.mts +0 -236
  56. package/dist/constants/hyperLiquidConfig.d.mts.map +0 -1
  57. package/dist/constants/hyperLiquidConfig.mjs +0 -371
  58. package/dist/constants/hyperLiquidConfig.mjs.map +0 -1
  59. package/dist/constants/index.cjs +0 -28
  60. package/dist/constants/index.cjs.map +0 -1
  61. package/dist/constants/index.d.cts +0 -12
  62. package/dist/constants/index.d.cts.map +0 -1
  63. package/dist/constants/index.d.mts +0 -12
  64. package/dist/constants/index.d.mts.map +0 -1
  65. package/dist/constants/index.mjs +0 -12
  66. package/dist/constants/index.mjs.map +0 -1
  67. package/dist/constants/myxConfig.cjs +0 -229
  68. package/dist/constants/myxConfig.cjs.map +0 -1
  69. package/dist/constants/myxConfig.d.cts +0 -106
  70. package/dist/constants/myxConfig.d.cts.map +0 -1
  71. package/dist/constants/myxConfig.d.mts +0 -106
  72. package/dist/constants/myxConfig.d.mts.map +0 -1
  73. package/dist/constants/myxConfig.mjs +0 -219
  74. package/dist/constants/myxConfig.mjs.map +0 -1
  75. package/dist/constants/orderTypes.cjs +0 -31
  76. package/dist/constants/orderTypes.cjs.map +0 -1
  77. package/dist/constants/orderTypes.d.cts +0 -19
  78. package/dist/constants/orderTypes.d.cts.map +0 -1
  79. package/dist/constants/orderTypes.d.mts +0 -19
  80. package/dist/constants/orderTypes.d.mts.map +0 -1
  81. package/dist/constants/orderTypes.mjs +0 -27
  82. package/dist/constants/orderTypes.mjs.map +0 -1
  83. package/dist/constants/performanceMetrics.cjs +0 -63
  84. package/dist/constants/performanceMetrics.cjs.map +0 -1
  85. package/dist/constants/performanceMetrics.d.cts +0 -46
  86. package/dist/constants/performanceMetrics.d.cts.map +0 -1
  87. package/dist/constants/performanceMetrics.d.mts +0 -46
  88. package/dist/constants/performanceMetrics.d.mts.map +0 -1
  89. package/dist/constants/performanceMetrics.mjs +0 -60
  90. package/dist/constants/performanceMetrics.mjs.map +0 -1
  91. package/dist/constants/perpsConfig.cjs +0 -295
  92. package/dist/constants/perpsConfig.cjs.map +0 -1
  93. package/dist/constants/perpsConfig.d.cts +0 -221
  94. package/dist/constants/perpsConfig.d.cts.map +0 -1
  95. package/dist/constants/perpsConfig.d.mts +0 -221
  96. package/dist/constants/perpsConfig.d.mts.map +0 -1
  97. package/dist/constants/perpsConfig.mjs +0 -292
  98. package/dist/constants/perpsConfig.mjs.map +0 -1
  99. package/dist/constants/transactionsHistoryConfig.cjs +0 -19
  100. package/dist/constants/transactionsHistoryConfig.cjs.map +0 -1
  101. package/dist/constants/transactionsHistoryConfig.d.cts +0 -16
  102. package/dist/constants/transactionsHistoryConfig.d.cts.map +0 -1
  103. package/dist/constants/transactionsHistoryConfig.d.mts +0 -16
  104. package/dist/constants/transactionsHistoryConfig.d.mts.map +0 -1
  105. package/dist/constants/transactionsHistoryConfig.mjs +0 -16
  106. package/dist/constants/transactionsHistoryConfig.mjs.map +0 -1
  107. package/dist/perpsErrorCodes.cjs +0 -80
  108. package/dist/perpsErrorCodes.cjs.map +0 -1
  109. package/dist/perpsErrorCodes.d.cts +0 -65
  110. package/dist/perpsErrorCodes.d.cts.map +0 -1
  111. package/dist/perpsErrorCodes.d.mts +0 -65
  112. package/dist/perpsErrorCodes.d.mts.map +0 -1
  113. package/dist/perpsErrorCodes.mjs +0 -77
  114. package/dist/perpsErrorCodes.mjs.map +0 -1
  115. package/dist/providers/AggregatedPerpsProvider.cjs +0 -508
  116. package/dist/providers/AggregatedPerpsProvider.cjs.map +0 -1
  117. package/dist/providers/AggregatedPerpsProvider.d.cts +0 -171
  118. package/dist/providers/AggregatedPerpsProvider.d.cts.map +0 -1
  119. package/dist/providers/AggregatedPerpsProvider.d.mts +0 -171
  120. package/dist/providers/AggregatedPerpsProvider.d.mts.map +0 -1
  121. package/dist/providers/AggregatedPerpsProvider.mjs +0 -504
  122. package/dist/providers/AggregatedPerpsProvider.mjs.map +0 -1
  123. package/dist/providers/HyperLiquidProvider.cjs +0 -5679
  124. package/dist/providers/HyperLiquidProvider.cjs.map +0 -1
  125. package/dist/providers/HyperLiquidProvider.d.cts +0 -516
  126. package/dist/providers/HyperLiquidProvider.d.cts.map +0 -1
  127. package/dist/providers/HyperLiquidProvider.d.mts +0 -516
  128. package/dist/providers/HyperLiquidProvider.d.mts.map +0 -1
  129. package/dist/providers/HyperLiquidProvider.mjs +0 -5675
  130. package/dist/providers/HyperLiquidProvider.mjs.map +0 -1
  131. package/dist/providers/MYXProvider.cjs +0 -514
  132. package/dist/providers/MYXProvider.cjs.map +0 -1
  133. package/dist/providers/MYXProvider.d.cts +0 -105
  134. package/dist/providers/MYXProvider.d.cts.map +0 -1
  135. package/dist/providers/MYXProvider.d.mts +0 -105
  136. package/dist/providers/MYXProvider.d.mts.map +0 -1
  137. package/dist/providers/MYXProvider.mjs +0 -510
  138. package/dist/providers/MYXProvider.mjs.map +0 -1
  139. package/dist/routing/ProviderRouter.cjs +0 -154
  140. package/dist/routing/ProviderRouter.cjs.map +0 -1
  141. package/dist/routing/ProviderRouter.d.cts +0 -112
  142. package/dist/routing/ProviderRouter.d.cts.map +0 -1
  143. package/dist/routing/ProviderRouter.d.mts +0 -112
  144. package/dist/routing/ProviderRouter.d.mts.map +0 -1
  145. package/dist/routing/ProviderRouter.mjs +0 -150
  146. package/dist/routing/ProviderRouter.mjs.map +0 -1
  147. package/dist/routing/index.cjs +0 -9
  148. package/dist/routing/index.cjs.map +0 -1
  149. package/dist/routing/index.d.cts +0 -6
  150. package/dist/routing/index.d.cts.map +0 -1
  151. package/dist/routing/index.d.mts +0 -6
  152. package/dist/routing/index.d.mts.map +0 -1
  153. package/dist/routing/index.mjs +0 -5
  154. package/dist/routing/index.mjs.map +0 -1
  155. package/dist/selectors.cjs +0 -166
  156. package/dist/selectors.cjs.map +0 -1
  157. package/dist/selectors.d.cts +0 -362
  158. package/dist/selectors.d.cts.map +0 -1
  159. package/dist/selectors.d.mts +0 -362
  160. package/dist/selectors.d.mts.map +0 -1
  161. package/dist/selectors.mjs +0 -158
  162. package/dist/selectors.mjs.map +0 -1
  163. package/dist/services/AccountService.cjs +0 -324
  164. package/dist/services/AccountService.cjs.map +0 -1
  165. package/dist/services/AccountService.d.cts +0 -56
  166. package/dist/services/AccountService.d.cts.map +0 -1
  167. package/dist/services/AccountService.d.mts +0 -56
  168. package/dist/services/AccountService.d.mts.map +0 -1
  169. package/dist/services/AccountService.mjs +0 -320
  170. package/dist/services/AccountService.mjs.map +0 -1
  171. package/dist/services/DataLakeService.cjs +0 -233
  172. package/dist/services/DataLakeService.cjs.map +0 -1
  173. package/dist/services/DataLakeService.d.cts +0 -51
  174. package/dist/services/DataLakeService.d.cts.map +0 -1
  175. package/dist/services/DataLakeService.d.mts +0 -51
  176. package/dist/services/DataLakeService.d.mts.map +0 -1
  177. package/dist/services/DataLakeService.mjs +0 -229
  178. package/dist/services/DataLakeService.mjs.map +0 -1
  179. package/dist/services/DepositService.cjs +0 -98
  180. package/dist/services/DepositService.cjs.map +0 -1
  181. package/dist/services/DepositService.d.cts +0 -39
  182. package/dist/services/DepositService.d.cts.map +0 -1
  183. package/dist/services/DepositService.d.mts +0 -39
  184. package/dist/services/DepositService.d.mts.map +0 -1
  185. package/dist/services/DepositService.mjs +0 -94
  186. package/dist/services/DepositService.mjs.map +0 -1
  187. package/dist/services/EligibilityService.cjs +0 -173
  188. package/dist/services/EligibilityService.cjs.map +0 -1
  189. package/dist/services/EligibilityService.d.cts +0 -39
  190. package/dist/services/EligibilityService.d.cts.map +0 -1
  191. package/dist/services/EligibilityService.d.mts +0 -39
  192. package/dist/services/EligibilityService.d.mts.map +0 -1
  193. package/dist/services/EligibilityService.mjs +0 -169
  194. package/dist/services/EligibilityService.mjs.map +0 -1
  195. package/dist/services/FeatureFlagConfigurationService.cjs +0 -257
  196. package/dist/services/FeatureFlagConfigurationService.cjs.map +0 -1
  197. package/dist/services/FeatureFlagConfigurationService.d.cts +0 -73
  198. package/dist/services/FeatureFlagConfigurationService.d.cts.map +0 -1
  199. package/dist/services/FeatureFlagConfigurationService.d.mts +0 -73
  200. package/dist/services/FeatureFlagConfigurationService.d.mts.map +0 -1
  201. package/dist/services/FeatureFlagConfigurationService.mjs +0 -253
  202. package/dist/services/FeatureFlagConfigurationService.mjs.map +0 -1
  203. package/dist/services/HyperLiquidClientService.cjs +0 -867
  204. package/dist/services/HyperLiquidClientService.cjs.map +0 -1
  205. package/dist/services/HyperLiquidClientService.d.cts +0 -214
  206. package/dist/services/HyperLiquidClientService.d.cts.map +0 -1
  207. package/dist/services/HyperLiquidClientService.d.mts +0 -214
  208. package/dist/services/HyperLiquidClientService.d.mts.map +0 -1
  209. package/dist/services/HyperLiquidClientService.mjs +0 -862
  210. package/dist/services/HyperLiquidClientService.mjs.map +0 -1
  211. package/dist/services/HyperLiquidSubscriptionService.cjs +0 -2199
  212. package/dist/services/HyperLiquidSubscriptionService.cjs.map +0 -1
  213. package/dist/services/HyperLiquidSubscriptionService.d.cts +0 -187
  214. package/dist/services/HyperLiquidSubscriptionService.d.cts.map +0 -1
  215. package/dist/services/HyperLiquidSubscriptionService.d.mts +0 -187
  216. package/dist/services/HyperLiquidSubscriptionService.d.mts.map +0 -1
  217. package/dist/services/HyperLiquidSubscriptionService.mjs +0 -2195
  218. package/dist/services/HyperLiquidSubscriptionService.mjs.map +0 -1
  219. package/dist/services/HyperLiquidWalletService.cjs +0 -163
  220. package/dist/services/HyperLiquidWalletService.cjs.map +0 -1
  221. package/dist/services/HyperLiquidWalletService.d.cts +0 -78
  222. package/dist/services/HyperLiquidWalletService.d.cts.map +0 -1
  223. package/dist/services/HyperLiquidWalletService.d.mts +0 -78
  224. package/dist/services/HyperLiquidWalletService.d.mts.map +0 -1
  225. package/dist/services/HyperLiquidWalletService.mjs +0 -159
  226. package/dist/services/HyperLiquidWalletService.mjs.map +0 -1
  227. package/dist/services/MYXClientService.cjs +0 -304
  228. package/dist/services/MYXClientService.cjs.map +0 -1
  229. package/dist/services/MYXClientService.d.cts +0 -81
  230. package/dist/services/MYXClientService.d.cts.map +0 -1
  231. package/dist/services/MYXClientService.d.mts +0 -81
  232. package/dist/services/MYXClientService.d.mts.map +0 -1
  233. package/dist/services/MYXClientService.mjs +0 -300
  234. package/dist/services/MYXClientService.mjs.map +0 -1
  235. package/dist/services/MarketDataService.cjs +0 -848
  236. package/dist/services/MarketDataService.cjs.map +0 -1
  237. package/dist/services/MarketDataService.d.cts +0 -291
  238. package/dist/services/MarketDataService.d.cts.map +0 -1
  239. package/dist/services/MarketDataService.d.mts +0 -291
  240. package/dist/services/MarketDataService.d.mts.map +0 -1
  241. package/dist/services/MarketDataService.mjs +0 -844
  242. package/dist/services/MarketDataService.mjs.map +0 -1
  243. package/dist/services/RewardsIntegrationService.cjs +0 -120
  244. package/dist/services/RewardsIntegrationService.cjs.map +0 -1
  245. package/dist/services/RewardsIntegrationService.d.cts +0 -28
  246. package/dist/services/RewardsIntegrationService.d.cts.map +0 -1
  247. package/dist/services/RewardsIntegrationService.d.mts +0 -28
  248. package/dist/services/RewardsIntegrationService.d.mts.map +0 -1
  249. package/dist/services/RewardsIntegrationService.mjs +0 -116
  250. package/dist/services/RewardsIntegrationService.mjs.map +0 -1
  251. package/dist/services/ServiceContext.cjs +0 -3
  252. package/dist/services/ServiceContext.cjs.map +0 -1
  253. package/dist/services/ServiceContext.d.cts +0 -86
  254. package/dist/services/ServiceContext.d.cts.map +0 -1
  255. package/dist/services/ServiceContext.d.mts +0 -86
  256. package/dist/services/ServiceContext.d.mts.map +0 -1
  257. package/dist/services/ServiceContext.mjs +0 -2
  258. package/dist/services/ServiceContext.mjs.map +0 -1
  259. package/dist/services/TradingReadinessCache.cjs +0 -288
  260. package/dist/services/TradingReadinessCache.cjs.map +0 -1
  261. package/dist/services/TradingReadinessCache.d.cts +0 -174
  262. package/dist/services/TradingReadinessCache.d.cts.map +0 -1
  263. package/dist/services/TradingReadinessCache.d.mts +0 -174
  264. package/dist/services/TradingReadinessCache.d.mts.map +0 -1
  265. package/dist/services/TradingReadinessCache.mjs +0 -285
  266. package/dist/services/TradingReadinessCache.mjs.map +0 -1
  267. package/dist/services/TradingService.cjs +0 -1457
  268. package/dist/services/TradingService.cjs.map +0 -1
  269. package/dist/services/TradingService.d.cts +0 -195
  270. package/dist/services/TradingService.d.cts.map +0 -1
  271. package/dist/services/TradingService.d.mts +0 -195
  272. package/dist/services/TradingService.d.mts.map +0 -1
  273. package/dist/services/TradingService.mjs +0 -1453
  274. package/dist/services/TradingService.mjs.map +0 -1
  275. package/dist/types/config.cjs +0 -3
  276. package/dist/types/config.cjs.map +0 -1
  277. package/dist/types/config.d.cts +0 -49
  278. package/dist/types/config.d.cts.map +0 -1
  279. package/dist/types/config.d.mts +0 -49
  280. package/dist/types/config.d.mts.map +0 -1
  281. package/dist/types/config.mjs +0 -2
  282. package/dist/types/config.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 -20
  286. package/dist/types/hyperliquid-types.d.cts.map +0 -1
  287. package/dist/types/hyperliquid-types.d.mts +0 -20
  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 -115
  292. package/dist/types/index.cjs.map +0 -1
  293. package/dist/types/index.d.cts +0 -1262
  294. package/dist/types/index.d.cts.map +0 -1
  295. package/dist/types/index.d.mts +0 -1262
  296. package/dist/types/index.d.mts.map +0 -1
  297. package/dist/types/index.mjs +0 -97
  298. package/dist/types/index.mjs.map +0 -1
  299. package/dist/types/messenger.cjs +0 -3
  300. package/dist/types/messenger.cjs.map +0 -1
  301. package/dist/types/messenger.d.cts +0 -27
  302. package/dist/types/messenger.d.cts.map +0 -1
  303. package/dist/types/messenger.d.mts +0 -27
  304. package/dist/types/messenger.d.mts.map +0 -1
  305. package/dist/types/messenger.mjs +0 -2
  306. package/dist/types/messenger.mjs.map +0 -1
  307. package/dist/types/myx-types.cjs +0 -25
  308. package/dist/types/myx-types.cjs.map +0 -1
  309. package/dist/types/myx-types.d.cts +0 -63
  310. package/dist/types/myx-types.d.cts.map +0 -1
  311. package/dist/types/myx-types.d.mts +0 -63
  312. package/dist/types/myx-types.d.mts.map +0 -1
  313. package/dist/types/myx-types.mjs +0 -22
  314. package/dist/types/myx-types.mjs.map +0 -1
  315. package/dist/types/perps-types.cjs +0 -4
  316. package/dist/types/perps-types.cjs.map +0 -1
  317. package/dist/types/perps-types.d.cts +0 -105
  318. package/dist/types/perps-types.d.cts.map +0 -1
  319. package/dist/types/perps-types.d.mts +0 -105
  320. package/dist/types/perps-types.d.mts.map +0 -1
  321. package/dist/types/perps-types.mjs +0 -2
  322. package/dist/types/perps-types.mjs.map +0 -1
  323. package/dist/types/token.cjs +0 -3
  324. package/dist/types/token.cjs.map +0 -1
  325. package/dist/types/token.d.cts +0 -25
  326. package/dist/types/token.d.cts.map +0 -1
  327. package/dist/types/token.d.mts +0 -25
  328. package/dist/types/token.d.mts.map +0 -1
  329. package/dist/types/token.mjs +0 -2
  330. package/dist/types/token.mjs.map +0 -1
  331. package/dist/types/transactionTypes.cjs +0 -28
  332. package/dist/types/transactionTypes.cjs.map +0 -1
  333. package/dist/types/transactionTypes.d.cts +0 -64
  334. package/dist/types/transactionTypes.d.cts.map +0 -1
  335. package/dist/types/transactionTypes.d.mts +0 -64
  336. package/dist/types/transactionTypes.d.mts.map +0 -1
  337. package/dist/types/transactionTypes.mjs +0 -23
  338. package/dist/types/transactionTypes.mjs.map +0 -1
  339. package/dist/utils/accountUtils.cjs +0 -100
  340. package/dist/utils/accountUtils.cjs.map +0 -1
  341. package/dist/utils/accountUtils.d.cts +0 -30
  342. package/dist/utils/accountUtils.d.cts.map +0 -1
  343. package/dist/utils/accountUtils.d.mts +0 -30
  344. package/dist/utils/accountUtils.d.mts.map +0 -1
  345. package/dist/utils/accountUtils.mjs +0 -92
  346. package/dist/utils/accountUtils.mjs.map +0 -1
  347. package/dist/utils/errorUtils.cjs +0 -35
  348. package/dist/utils/errorUtils.cjs.map +0 -1
  349. package/dist/utils/errorUtils.d.cts +0 -15
  350. package/dist/utils/errorUtils.d.cts.map +0 -1
  351. package/dist/utils/errorUtils.d.mts +0 -15
  352. package/dist/utils/errorUtils.d.mts.map +0 -1
  353. package/dist/utils/errorUtils.mjs +0 -31
  354. package/dist/utils/errorUtils.mjs.map +0 -1
  355. package/dist/utils/hyperLiquidAdapter.cjs +0 -331
  356. package/dist/utils/hyperLiquidAdapter.cjs.map +0 -1
  357. package/dist/utils/hyperLiquidAdapter.d.cts +0 -42
  358. package/dist/utils/hyperLiquidAdapter.d.cts.map +0 -1
  359. package/dist/utils/hyperLiquidAdapter.d.mts +0 -42
  360. package/dist/utils/hyperLiquidAdapter.d.mts.map +0 -1
  361. package/dist/utils/hyperLiquidAdapter.mjs +0 -316
  362. package/dist/utils/hyperLiquidAdapter.mjs.map +0 -1
  363. package/dist/utils/hyperLiquidOrderBookProcessor.cjs +0 -83
  364. package/dist/utils/hyperLiquidOrderBookProcessor.cjs.map +0 -1
  365. package/dist/utils/hyperLiquidOrderBookProcessor.d.cts +0 -55
  366. package/dist/utils/hyperLiquidOrderBookProcessor.d.cts.map +0 -1
  367. package/dist/utils/hyperLiquidOrderBookProcessor.d.mts +0 -55
  368. package/dist/utils/hyperLiquidOrderBookProcessor.d.mts.map +0 -1
  369. package/dist/utils/hyperLiquidOrderBookProcessor.mjs +0 -78
  370. package/dist/utils/hyperLiquidOrderBookProcessor.mjs.map +0 -1
  371. package/dist/utils/hyperLiquidValidation.cjs +0 -426
  372. package/dist/utils/hyperLiquidValidation.cjs.map +0 -1
  373. package/dist/utils/hyperLiquidValidation.d.cts +0 -143
  374. package/dist/utils/hyperLiquidValidation.d.cts.map +0 -1
  375. package/dist/utils/hyperLiquidValidation.d.mts +0 -143
  376. package/dist/utils/hyperLiquidValidation.d.mts.map +0 -1
  377. package/dist/utils/hyperLiquidValidation.mjs +0 -413
  378. package/dist/utils/hyperLiquidValidation.mjs.map +0 -1
  379. package/dist/utils/idUtils.cjs +0 -18
  380. package/dist/utils/idUtils.cjs.map +0 -1
  381. package/dist/utils/idUtils.d.cts +0 -6
  382. package/dist/utils/idUtils.d.cts.map +0 -1
  383. package/dist/utils/idUtils.d.mts +0 -6
  384. package/dist/utils/idUtils.d.mts.map +0 -1
  385. package/dist/utils/idUtils.mjs +0 -10
  386. package/dist/utils/idUtils.mjs.map +0 -1
  387. package/dist/utils/index.cjs +0 -59
  388. package/dist/utils/index.cjs.map +0 -1
  389. package/dist/utils/index.d.cts +0 -25
  390. package/dist/utils/index.d.cts.map +0 -1
  391. package/dist/utils/index.d.mts +0 -25
  392. package/dist/utils/index.d.mts.map +0 -1
  393. package/dist/utils/index.mjs +0 -30
  394. package/dist/utils/index.mjs.map +0 -1
  395. package/dist/utils/marketDataTransform.cjs +0 -211
  396. package/dist/utils/marketDataTransform.cjs.map +0 -1
  397. package/dist/utils/marketDataTransform.d.cts +0 -40
  398. package/dist/utils/marketDataTransform.d.cts.map +0 -1
  399. package/dist/utils/marketDataTransform.d.mts +0 -40
  400. package/dist/utils/marketDataTransform.d.mts.map +0 -1
  401. package/dist/utils/marketDataTransform.mjs +0 -205
  402. package/dist/utils/marketDataTransform.mjs.map +0 -1
  403. package/dist/utils/marketUtils.cjs +0 -151
  404. package/dist/utils/marketUtils.cjs.map +0 -1
  405. package/dist/utils/marketUtils.d.cts +0 -30
  406. package/dist/utils/marketUtils.d.cts.map +0 -1
  407. package/dist/utils/marketUtils.d.mts +0 -30
  408. package/dist/utils/marketUtils.d.mts.map +0 -1
  409. package/dist/utils/marketUtils.mjs +0 -138
  410. package/dist/utils/marketUtils.mjs.map +0 -1
  411. package/dist/utils/myxAdapter.cjs +0 -224
  412. package/dist/utils/myxAdapter.cjs.map +0 -1
  413. package/dist/utils/myxAdapter.d.cts +0 -81
  414. package/dist/utils/myxAdapter.d.cts.map +0 -1
  415. package/dist/utils/myxAdapter.d.mts +0 -81
  416. package/dist/utils/myxAdapter.d.mts.map +0 -1
  417. package/dist/utils/myxAdapter.mjs +0 -213
  418. package/dist/utils/myxAdapter.mjs.map +0 -1
  419. package/dist/utils/orderCalculations.cjs +0 -283
  420. package/dist/utils/orderCalculations.cjs.map +0 -1
  421. package/dist/utils/orderCalculations.d.cts +0 -107
  422. package/dist/utils/orderCalculations.d.cts.map +0 -1
  423. package/dist/utils/orderCalculations.d.mts +0 -107
  424. package/dist/utils/orderCalculations.d.mts.map +0 -1
  425. package/dist/utils/orderCalculations.mjs +0 -274
  426. package/dist/utils/orderCalculations.mjs.map +0 -1
  427. package/dist/utils/rewardsUtils.cjs +0 -98
  428. package/dist/utils/rewardsUtils.cjs.map +0 -1
  429. package/dist/utils/rewardsUtils.d.cts +0 -33
  430. package/dist/utils/rewardsUtils.d.cts.map +0 -1
  431. package/dist/utils/rewardsUtils.d.mts +0 -33
  432. package/dist/utils/rewardsUtils.d.mts.map +0 -1
  433. package/dist/utils/rewardsUtils.mjs +0 -92
  434. package/dist/utils/rewardsUtils.mjs.map +0 -1
  435. package/dist/utils/significantFigures.cjs +0 -88
  436. package/dist/utils/significantFigures.cjs.map +0 -1
  437. package/dist/utils/significantFigures.d.cts +0 -25
  438. package/dist/utils/significantFigures.d.cts.map +0 -1
  439. package/dist/utils/significantFigures.d.mts +0 -25
  440. package/dist/utils/significantFigures.d.mts.map +0 -1
  441. package/dist/utils/significantFigures.mjs +0 -82
  442. package/dist/utils/significantFigures.mjs.map +0 -1
  443. package/dist/utils/sortMarkets.cjs +0 -93
  444. package/dist/utils/sortMarkets.cjs.map +0 -1
  445. package/dist/utils/sortMarkets.d.cts +0 -27
  446. package/dist/utils/sortMarkets.d.cts.map +0 -1
  447. package/dist/utils/sortMarkets.d.mts +0 -27
  448. package/dist/utils/sortMarkets.d.mts.map +0 -1
  449. package/dist/utils/sortMarkets.mjs +0 -88
  450. package/dist/utils/sortMarkets.mjs.map +0 -1
  451. package/dist/utils/standaloneInfoClient.cjs +0 -70
  452. package/dist/utils/standaloneInfoClient.cjs.map +0 -1
  453. package/dist/utils/standaloneInfoClient.d.cts +0 -37
  454. package/dist/utils/standaloneInfoClient.d.cts.map +0 -1
  455. package/dist/utils/standaloneInfoClient.d.mts +0 -37
  456. package/dist/utils/standaloneInfoClient.d.mts.map +0 -1
  457. package/dist/utils/standaloneInfoClient.mjs +0 -64
  458. package/dist/utils/standaloneInfoClient.mjs.map +0 -1
  459. package/dist/utils/stringParseUtils.cjs +0 -18
  460. package/dist/utils/stringParseUtils.cjs.map +0 -1
  461. package/dist/utils/stringParseUtils.d.cts +0 -3
  462. package/dist/utils/stringParseUtils.d.cts.map +0 -1
  463. package/dist/utils/stringParseUtils.d.mts +0 -3
  464. package/dist/utils/stringParseUtils.d.mts.map +0 -1
  465. package/dist/utils/stringParseUtils.mjs +0 -13
  466. package/dist/utils/stringParseUtils.mjs.map +0 -1
  467. package/dist/utils/transferData.cjs +0 -33
  468. package/dist/utils/transferData.cjs.map +0 -1
  469. package/dist/utils/transferData.d.cts +0 -9
  470. package/dist/utils/transferData.d.cts.map +0 -1
  471. package/dist/utils/transferData.d.mts +0 -9
  472. package/dist/utils/transferData.d.mts.map +0 -1
  473. package/dist/utils/transferData.mjs +0 -29
  474. package/dist/utils/transferData.mjs.map +0 -1
  475. package/dist/utils/wait.cjs +0 -6
  476. package/dist/utils/wait.cjs.map +0 -1
  477. package/dist/utils/wait.d.cts +0 -2
  478. package/dist/utils/wait.d.cts.map +0 -1
  479. package/dist/utils/wait.d.mts +0 -2
  480. package/dist/utils/wait.d.mts.map +0 -1
  481. package/dist/utils/wait.mjs +0 -2
  482. package/dist/utils/wait.mjs.map +0 -1
@@ -1,283 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildOrdersArray = exports.calculateOrderPriceAndSize = exports.calculateFinalPositionSize = exports.getMaxAllowedAmount = exports.calculateMarginRequired = exports.calculatePositionSize = void 0;
4
- const hyperLiquidAdapter_1 = require("./hyperLiquidAdapter.cjs");
5
- const perpsConfig_1 = require("../constants/perpsConfig.cjs");
6
- const perpsErrorCodes_1 = require("../perpsErrorCodes.cjs");
7
- /**
8
- * Calculate position size based on USD amount and asset price
9
- *
10
- * @param params - Amount in USD, current asset price, and required decimal precision
11
- * @returns Position size formatted to the asset's decimal precision
12
- */
13
- function calculatePositionSize(params) {
14
- const { amount, price, szDecimals } = params;
15
- // Validate required parameters
16
- if (szDecimals === undefined || szDecimals === null) {
17
- throw new Error('szDecimals is required for position size calculation');
18
- }
19
- if (szDecimals < 0) {
20
- throw new Error(`szDecimals must be >= 0, got: ${szDecimals}`);
21
- }
22
- const amountNum = parseFloat(amount || '0');
23
- if (isNaN(amountNum) || isNaN(price) || amountNum === 0 || price === 0) {
24
- return (0).toFixed(szDecimals);
25
- }
26
- const positionSize = amountNum / price;
27
- const multiplier = Math.pow(10, szDecimals);
28
- let rounded = Math.round(positionSize * multiplier) / multiplier;
29
- // Ensure rounded size meets requested USD (fix validation gap)
30
- const actualUsd = rounded * price;
31
- if (actualUsd < amountNum) {
32
- rounded += 1 / multiplier;
33
- }
34
- return rounded.toFixed(szDecimals);
35
- }
36
- exports.calculatePositionSize = calculatePositionSize;
37
- /**
38
- * Calculate margin required for a position
39
- *
40
- * @param params - Position amount and leverage
41
- * @returns Margin required formatted to 2 decimal places
42
- */
43
- function calculateMarginRequired(params) {
44
- const { amount, leverage } = params;
45
- const amountNum = parseFloat(amount || '0');
46
- if (isNaN(amountNum) ||
47
- isNaN(leverage) ||
48
- amountNum === 0 ||
49
- leverage === 0) {
50
- return '0.00';
51
- }
52
- return (amountNum / leverage).toFixed(2);
53
- }
54
- exports.calculateMarginRequired = calculateMarginRequired;
55
- function getMaxAllowedAmount(params) {
56
- const { availableBalance, assetPrice, assetSzDecimals, leverage } = params;
57
- if (availableBalance === 0 || !assetPrice || assetSzDecimals === undefined) {
58
- return 0;
59
- }
60
- // The theoretical maximum is simply availableBalance * leverage
61
- const theoreticalMax = availableBalance * leverage;
62
- // But we need to account for position size rounding
63
- // Find the largest whole dollar amount that fits within this limit
64
- let maxAmount = Math.floor(theoreticalMax);
65
- // Verify this amount doesn't exceed available balance after rounding
66
- const testPositionSize = calculatePositionSize({
67
- amount: maxAmount.toString(),
68
- price: assetPrice,
69
- szDecimals: assetSzDecimals,
70
- });
71
- const actualNotionalValue = parseFloat(testPositionSize) * assetPrice;
72
- const requiredMargin = actualNotionalValue / leverage;
73
- // If rounding caused us to exceed available balance, step down by one position increment
74
- if (requiredMargin > availableBalance) {
75
- const minPositionSizeIncrement = 1 / Math.pow(10, assetSzDecimals);
76
- const positionSizeIncrementUsd = Math.ceil(minPositionSizeIncrement * assetPrice);
77
- maxAmount -= positionSizeIncrementUsd;
78
- }
79
- return Math.max(0, maxAmount);
80
- }
81
- exports.getMaxAllowedAmount = getMaxAllowedAmount;
82
- /**
83
- * Calculates final position size using USD as source of truth with price validation
84
- *
85
- * This function implements the hybrid approach where USD is the source of truth,
86
- * but includes price staleness validation and proper rounding to prevent precision loss.
87
- *
88
- * @param params - USD amount, size, prices, and configuration
89
- * @returns Final position size as a number
90
- */
91
- function calculateFinalPositionSize(params) {
92
- const { usdAmount, size, currentPrice, priceAtCalculation, maxSlippageBps, szDecimals, leverage, debugLogger, } = params;
93
- let finalPositionSize;
94
- if (usdAmount && parseFloat(usdAmount) > 0) {
95
- // USD amount provided - use it as source of truth
96
- const usdValue = parseFloat(usdAmount);
97
- // 1. Validate price staleness if priceAtCalculation provided
98
- if (priceAtCalculation) {
99
- const priceDeltaBps = Math.abs(((currentPrice - priceAtCalculation) / priceAtCalculation) * 10000);
100
- const maxSlippageBpsValue = maxSlippageBps ?? perpsConfig_1.ORDER_SLIPPAGE_CONFIG.DefaultMarketSlippageBps;
101
- if (priceDeltaBps > maxSlippageBpsValue) {
102
- throw new Error(`Price moved too much: ${priceDeltaBps.toFixed(0)} bps (max: ${maxSlippageBpsValue} bps). ` +
103
- `Expected: ${priceAtCalculation.toFixed(2)}, Current: ${currentPrice.toFixed(2)}`);
104
- }
105
- debugLogger?.log('Price validation passed:', {
106
- priceAtCalculation,
107
- currentPrice,
108
- deltaBps: priceDeltaBps.toFixed(2),
109
- maxSlippageBps: maxSlippageBpsValue,
110
- });
111
- }
112
- // 2. Recalculate position size with fresh price
113
- finalPositionSize = usdValue / currentPrice;
114
- // 3. Apply size decimals rounding
115
- const multiplier = Math.pow(10, szDecimals);
116
- finalPositionSize = Math.round(finalPositionSize * multiplier) / multiplier;
117
- // 4. Ensure rounded size meets requested USD (fix validation gap)
118
- let actualNotionalValue = finalPositionSize * currentPrice;
119
- if (actualNotionalValue < usdValue) {
120
- // Add 1 minimum increment to meet requested USD
121
- finalPositionSize += 1 / multiplier;
122
- actualNotionalValue = finalPositionSize * currentPrice;
123
- debugLogger?.log('Position size adjusted to meet USD minimum:', {
124
- requestedUsd: usdValue,
125
- beforeAdjustment: finalPositionSize - 1 / multiplier,
126
- afterAdjustment: finalPositionSize,
127
- actualUsd: actualNotionalValue,
128
- });
129
- }
130
- const requiredMargin = actualNotionalValue / (leverage ?? 1);
131
- // Log if rounding caused significant difference
132
- const usdDifference = Math.abs(actualNotionalValue - usdValue);
133
- if (usdDifference > 0.01) {
134
- debugLogger?.log('Position size rounding caused USD difference (acceptable):', {
135
- requestedUsd: usdValue,
136
- actualUsd: actualNotionalValue,
137
- difference: usdDifference,
138
- positionSize: finalPositionSize,
139
- });
140
- }
141
- debugLogger?.log('Recalculated position size with fresh price:', {
142
- usdAmount: usdValue,
143
- priceAtCalculation,
144
- currentPrice,
145
- originalSize: size,
146
- recalculatedSize: finalPositionSize,
147
- requiredMargin,
148
- minIncrement: 1 / multiplier,
149
- });
150
- }
151
- else {
152
- // Legacy: Use provided size (backward compatibility)
153
- finalPositionSize = parseFloat(size ?? '0');
154
- debugLogger?.log('Using legacy size calculation (no USD amount provided):', {
155
- providedSize: size,
156
- finalSize: finalPositionSize,
157
- });
158
- }
159
- return { finalPositionSize };
160
- }
161
- exports.calculateFinalPositionSize = calculateFinalPositionSize;
162
- /**
163
- * Calculates order price and formatted size based on order type
164
- *
165
- * @param params - Order parameters including type, direction, size, and prices
166
- * @returns Formatted order price, size, and price string
167
- */
168
- function calculateOrderPriceAndSize(params) {
169
- const { orderType, isBuy, finalPositionSize, currentPrice, limitPrice, slippage, szDecimals, } = params;
170
- let orderPrice;
171
- let formattedSize;
172
- if (orderType === 'market') {
173
- // Market orders: add slippage (3% conservative default)
174
- const slippageValue = slippage ?? perpsConfig_1.ORDER_SLIPPAGE_CONFIG.DefaultMarketSlippageBps / 10000;
175
- orderPrice = isBuy
176
- ? currentPrice * (1 + slippageValue)
177
- : currentPrice * (1 - slippageValue);
178
- formattedSize = (0, hyperLiquidAdapter_1.formatHyperLiquidSize)({
179
- size: finalPositionSize,
180
- szDecimals,
181
- });
182
- }
183
- else {
184
- // Limit orders: use provided price (no slippage applied)
185
- if (!limitPrice) {
186
- throw new Error(perpsErrorCodes_1.PERPS_ERROR_CODES.ORDER_LIMIT_PRICE_REQUIRED);
187
- }
188
- orderPrice = parseFloat(limitPrice);
189
- formattedSize = (0, hyperLiquidAdapter_1.formatHyperLiquidSize)({
190
- size: finalPositionSize,
191
- szDecimals,
192
- });
193
- }
194
- const formattedPrice = (0, hyperLiquidAdapter_1.formatHyperLiquidPrice)({
195
- price: orderPrice,
196
- szDecimals,
197
- });
198
- return { orderPrice, formattedSize, formattedPrice };
199
- }
200
- exports.calculateOrderPriceAndSize = calculateOrderPriceAndSize;
201
- /**
202
- * Builds orders array including main order and optional TP/SL orders
203
- *
204
- * @param params - Order construction parameters
205
- * @returns Array of SDK order params and grouping type
206
- */
207
- function buildOrdersArray(params) {
208
- const { assetId, isBuy, formattedPrice, formattedSize, reduceOnly, orderType, clientOrderId, takeProfitPrice, stopLossPrice, szDecimals, grouping, } = params;
209
- const orders = [];
210
- // 1. Main order
211
- const mainOrder = {
212
- a: assetId,
213
- b: isBuy,
214
- p: formattedPrice,
215
- s: formattedSize,
216
- r: reduceOnly || false,
217
- t: orderType === 'limit'
218
- ? { limit: { tif: 'Gtc' } }
219
- : { limit: { tif: 'FrontendMarket' } },
220
- c: clientOrderId ? clientOrderId : undefined,
221
- };
222
- orders.push(mainOrder);
223
- // 2. Take Profit order
224
- if (takeProfitPrice) {
225
- const tpOrder = {
226
- a: assetId,
227
- b: !isBuy,
228
- p: (0, hyperLiquidAdapter_1.formatHyperLiquidPrice)({
229
- price: parseFloat(takeProfitPrice),
230
- szDecimals,
231
- }),
232
- s: formattedSize,
233
- r: true,
234
- t: {
235
- trigger: {
236
- isMarket: false,
237
- triggerPx: (0, hyperLiquidAdapter_1.formatHyperLiquidPrice)({
238
- price: parseFloat(takeProfitPrice),
239
- szDecimals,
240
- }),
241
- tpsl: 'tp',
242
- },
243
- },
244
- };
245
- orders.push(tpOrder);
246
- }
247
- // 3. Stop Loss order
248
- if (stopLossPrice) {
249
- // Apply 10% slippage to SL limit price (executes as market order when triggered)
250
- // HyperLiquid recommended: 10% for TP/SL orders
251
- const stopLossPriceNum = parseFloat(stopLossPrice);
252
- const slippageValue = perpsConfig_1.ORDER_SLIPPAGE_CONFIG.DefaultTpslSlippageBps / 10000;
253
- const limitPriceWithSlippage = isBuy
254
- ? stopLossPriceNum * (1 - slippageValue) // Selling to close long: willing to accept LESS (slippage protection)
255
- : stopLossPriceNum * (1 + slippageValue); // Buying to close short: willing to pay MORE (slippage protection)
256
- const slOrder = {
257
- a: assetId,
258
- b: !isBuy,
259
- p: (0, hyperLiquidAdapter_1.formatHyperLiquidPrice)({
260
- price: limitPriceWithSlippage,
261
- szDecimals,
262
- }),
263
- s: formattedSize,
264
- r: true,
265
- t: {
266
- trigger: {
267
- isMarket: true,
268
- triggerPx: (0, hyperLiquidAdapter_1.formatHyperLiquidPrice)({
269
- price: stopLossPriceNum,
270
- szDecimals,
271
- }),
272
- tpsl: 'sl',
273
- },
274
- },
275
- };
276
- orders.push(slOrder);
277
- }
278
- // Determine grouping
279
- const finalGrouping = grouping ?? ((takeProfitPrice ?? stopLossPrice) ? 'normalTpsl' : 'na');
280
- return { orders, grouping: finalGrouping };
281
- }
282
- exports.buildOrdersArray = buildOrdersArray;
283
- //# sourceMappingURL=orderCalculations.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"orderCalculations.cjs","sourceRoot":"","sources":["../../src/utils/orderCalculations.ts"],"names":[],"mappings":";;;AAEA,iEAG8B;AAC9B,8DAAiE;AACjE,4DAAuD;AA+EvD;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAC,MAA0B;IAC9D,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAE7C,+BAA+B;IAC/B,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC1E,CAAC;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AE,CAAC;QAClB,iFAAiF;QACjF,gDAAgD;QAChD,MAAM,gBAAgB,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;QACnD,MAAM,aAAa,GAAG,mCAAqB,CAAC,sBAAsB,GAAG,KAAK,CAAC;QAC3E,MAAM,sBAAsB,GAAG,KAAK;YAClC,CAAC,CAAC,gBAAgB,GAAG,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,sEAAsE;YAC/G,CAAC,CAAC,gBAAgB,GAAG,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,mEAAmE;QAE/G,MAAM,OAAO,GAAmB;YAC9B,CAAC,EAAE,OAAO;YACV,CAAC,EAAE,CAAC,KAAK;YACT,CAAC,EAAE,IAAA,2CAAsB,EAAC;gBACxB,KAAK,EAAE,sBAAsB;gBAC7B,UAAU;aACX,CAAC;YACF,CAAC,EAAE,aAAa;YAChB,CAAC,EAAE,IAAI;YACP,CAAC,EAAE;gBACD,OAAO,EAAE;oBACP,QAAQ,EAAE,IAAI;oBACd,SAAS,EAAE,IAAA,2CAAsB,EAAC;wBAChC,KAAK,EAAE,gBAAgB;wBACvB,UAAU;qBACX,CAAC;oBACF,IAAI,EAAE,IAAI;iBACX;aACF;SACF,CAAC;QACF,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;IAED,qBAAqB;IACrB,MAAM,aAAa,GACjB,QAAQ,IAAI,CAAC,CAAC,eAAe,IAAI,aAAa,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAEzE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC;AAC7C,CAAC;AAjGD,4CAiGC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport {\n formatHyperLiquidPrice,\n formatHyperLiquidSize,\n} from './hyperLiquidAdapter';\nimport { ORDER_SLIPPAGE_CONFIG } from '../constants/perpsConfig';\nimport { PERPS_ERROR_CODES } from '../perpsErrorCodes';\nimport type { PerpsDebugLogger } from '../types';\nimport type { SDKOrderParams } from '../types/hyperliquid-types';\n\n/**\n * Optional debug logger for order calculation functions.\n * When provided, enables detailed logging for debugging.\n */\nexport type OrderCalculationsDebugLogger = PerpsDebugLogger | undefined;\n\ntype PositionSizeParams = {\n amount: string;\n price: number;\n szDecimals: number;\n};\n\ntype MarginRequiredParams = {\n amount: string;\n leverage: number;\n};\n\ntype MaxAllowedAmountParams = {\n availableBalance: number;\n assetPrice: number;\n assetSzDecimals: number;\n leverage: number;\n};\n\n// Advanced order calculation interfaces\nexport type CalculateFinalPositionSizeParams = {\n usdAmount?: string;\n size?: string;\n currentPrice: number;\n priceAtCalculation?: number;\n maxSlippageBps?: number;\n szDecimals: number;\n leverage?: number;\n debugLogger?: OrderCalculationsDebugLogger;\n};\n\nexport type CalculateFinalPositionSizeResult = {\n finalPositionSize: number;\n};\n\nexport type CalculateOrderPriceAndSizeParams = {\n orderType: 'market' | 'limit';\n isBuy: boolean;\n finalPositionSize: number;\n currentPrice: number;\n limitPrice?: string;\n slippage?: number;\n szDecimals: number;\n};\n\nexport type CalculateOrderPriceAndSizeResult = {\n orderPrice: number;\n formattedSize: string;\n formattedPrice: string;\n};\n\nexport type BuildOrdersArrayParams = {\n assetId: number;\n isBuy: boolean;\n formattedPrice: string;\n formattedSize: string;\n reduceOnly: boolean;\n orderType: 'market' | 'limit';\n clientOrderId?: string;\n takeProfitPrice?: string;\n stopLossPrice?: string;\n szDecimals: number;\n grouping?: 'na' | 'normalTpsl' | 'positionTpsl';\n};\n\nexport type BuildOrdersArrayResult = {\n orders: SDKOrderParams[];\n grouping: 'na' | 'normalTpsl' | 'positionTpsl';\n};\n\n/**\n * Calculate position size based on USD amount and asset price\n *\n * @param params - Amount in USD, current asset price, and required decimal precision\n * @returns Position size formatted to the asset's decimal precision\n */\nexport function calculatePositionSize(params: PositionSizeParams): string {\n const { amount, price, szDecimals } = params;\n\n // Validate required parameters\n if (szDecimals === undefined || szDecimals === null) {\n throw new Error('szDecimals is required for position size calculation');\n }\n if (szDecimals < 0) {\n throw new Error(`szDecimals must be >= 0, got: ${szDecimals}`);\n }\n\n const amountNum = parseFloat(amount || '0');\n\n if (isNaN(amountNum) || isNaN(price) || amountNum === 0 || price === 0) {\n return (0).toFixed(szDecimals);\n }\n\n const positionSize = amountNum / price;\n const multiplier = Math.pow(10, szDecimals);\n let rounded = Math.round(positionSize * multiplier) / multiplier;\n\n // Ensure rounded size meets requested USD (fix validation gap)\n const actualUsd = rounded * price;\n if (actualUsd < amountNum) {\n rounded += 1 / multiplier;\n }\n\n return rounded.toFixed(szDecimals);\n}\n\n/**\n * Calculate margin required for a position\n *\n * @param params - Position amount and leverage\n * @returns Margin required formatted to 2 decimal places\n */\nexport function calculateMarginRequired(params: MarginRequiredParams): string {\n const { amount, leverage } = params;\n const amountNum = parseFloat(amount || '0');\n\n if (\n isNaN(amountNum) ||\n isNaN(leverage) ||\n amountNum === 0 ||\n leverage === 0\n ) {\n return '0.00';\n }\n\n return (amountNum / leverage).toFixed(2);\n}\n\nexport function getMaxAllowedAmount(params: MaxAllowedAmountParams): number {\n const { availableBalance, assetPrice, assetSzDecimals, leverage } = params;\n if (availableBalance === 0 || !assetPrice || assetSzDecimals === undefined) {\n return 0;\n }\n\n // The theoretical maximum is simply availableBalance * leverage\n const theoreticalMax = availableBalance * leverage;\n\n // But we need to account for position size rounding\n // Find the largest whole dollar amount that fits within this limit\n let maxAmount = Math.floor(theoreticalMax);\n\n // Verify this amount doesn't exceed available balance after rounding\n const testPositionSize = calculatePositionSize({\n amount: maxAmount.toString(),\n price: assetPrice,\n szDecimals: assetSzDecimals,\n });\n\n const actualNotionalValue = parseFloat(testPositionSize) * assetPrice;\n const requiredMargin = actualNotionalValue / leverage;\n\n // If rounding caused us to exceed available balance, step down by one position increment\n if (requiredMargin > availableBalance) {\n const minPositionSizeIncrement = 1 / Math.pow(10, assetSzDecimals);\n const positionSizeIncrementUsd = Math.ceil(\n minPositionSizeIncrement * assetPrice,\n );\n maxAmount -= positionSizeIncrementUsd;\n }\n\n return Math.max(0, maxAmount);\n}\n\n/**\n * Calculates final position size using USD as source of truth with price validation\n *\n * This function implements the hybrid approach where USD is the source of truth,\n * but includes price staleness validation and proper rounding to prevent precision loss.\n *\n * @param params - USD amount, size, prices, and configuration\n * @returns Final position size as a number\n */\nexport function calculateFinalPositionSize(\n params: CalculateFinalPositionSizeParams,\n): CalculateFinalPositionSizeResult {\n const {\n usdAmount,\n size,\n currentPrice,\n priceAtCalculation,\n maxSlippageBps,\n szDecimals,\n leverage,\n debugLogger,\n } = params;\n\n let finalPositionSize: number;\n\n if (usdAmount && parseFloat(usdAmount) > 0) {\n // USD amount provided - use it as source of truth\n const usdValue = parseFloat(usdAmount);\n\n // 1. Validate price staleness if priceAtCalculation provided\n if (priceAtCalculation) {\n const priceDeltaBps = Math.abs(\n ((currentPrice - priceAtCalculation) / priceAtCalculation) * 10000,\n );\n const maxSlippageBpsValue =\n maxSlippageBps ?? ORDER_SLIPPAGE_CONFIG.DefaultMarketSlippageBps;\n\n if (priceDeltaBps > maxSlippageBpsValue) {\n throw new Error(\n `Price moved too much: ${priceDeltaBps.toFixed(0)} bps (max: ${maxSlippageBpsValue} bps). ` +\n `Expected: ${priceAtCalculation.toFixed(2)}, Current: ${currentPrice.toFixed(2)}`,\n );\n }\n\n debugLogger?.log('Price validation passed:', {\n priceAtCalculation,\n currentPrice,\n deltaBps: priceDeltaBps.toFixed(2),\n maxSlippageBps: maxSlippageBpsValue,\n });\n }\n\n // 2. Recalculate position size with fresh price\n finalPositionSize = usdValue / currentPrice;\n\n // 3. Apply size decimals rounding\n const multiplier = Math.pow(10, szDecimals);\n finalPositionSize = Math.round(finalPositionSize * multiplier) / multiplier;\n\n // 4. Ensure rounded size meets requested USD (fix validation gap)\n let actualNotionalValue = finalPositionSize * currentPrice;\n if (actualNotionalValue < usdValue) {\n // Add 1 minimum increment to meet requested USD\n finalPositionSize += 1 / multiplier;\n actualNotionalValue = finalPositionSize * currentPrice;\n\n debugLogger?.log('Position size adjusted to meet USD minimum:', {\n requestedUsd: usdValue,\n beforeAdjustment: finalPositionSize - 1 / multiplier,\n afterAdjustment: finalPositionSize,\n actualUsd: actualNotionalValue,\n });\n }\n\n const requiredMargin = actualNotionalValue / (leverage ?? 1);\n\n // Log if rounding caused significant difference\n const usdDifference = Math.abs(actualNotionalValue - usdValue);\n if (usdDifference > 0.01) {\n debugLogger?.log(\n 'Position size rounding caused USD difference (acceptable):',\n {\n requestedUsd: usdValue,\n actualUsd: actualNotionalValue,\n difference: usdDifference,\n positionSize: finalPositionSize,\n },\n );\n }\n\n debugLogger?.log('Recalculated position size with fresh price:', {\n usdAmount: usdValue,\n priceAtCalculation,\n currentPrice,\n originalSize: size,\n recalculatedSize: finalPositionSize,\n requiredMargin,\n minIncrement: 1 / multiplier,\n });\n } else {\n // Legacy: Use provided size (backward compatibility)\n finalPositionSize = parseFloat(size ?? '0');\n\n debugLogger?.log(\n 'Using legacy size calculation (no USD amount provided):',\n {\n providedSize: size,\n finalSize: finalPositionSize,\n },\n );\n }\n\n return { finalPositionSize };\n}\n\n/**\n * Calculates order price and formatted size based on order type\n *\n * @param params - Order parameters including type, direction, size, and prices\n * @returns Formatted order price, size, and price string\n */\nexport function calculateOrderPriceAndSize(\n params: CalculateOrderPriceAndSizeParams,\n): CalculateOrderPriceAndSizeResult {\n const {\n orderType,\n isBuy,\n finalPositionSize,\n currentPrice,\n limitPrice,\n slippage,\n szDecimals,\n } = params;\n\n let orderPrice: number;\n let formattedSize: string;\n\n if (orderType === 'market') {\n // Market orders: add slippage (3% conservative default)\n const slippageValue =\n slippage ?? ORDER_SLIPPAGE_CONFIG.DefaultMarketSlippageBps / 10000;\n orderPrice = isBuy\n ? currentPrice * (1 + slippageValue)\n : currentPrice * (1 - slippageValue);\n formattedSize = formatHyperLiquidSize({\n size: finalPositionSize,\n szDecimals,\n });\n } else {\n // Limit orders: use provided price (no slippage applied)\n if (!limitPrice) {\n throw new Error(PERPS_ERROR_CODES.ORDER_LIMIT_PRICE_REQUIRED);\n }\n orderPrice = parseFloat(limitPrice);\n formattedSize = formatHyperLiquidSize({\n size: finalPositionSize,\n szDecimals,\n });\n }\n\n const formattedPrice = formatHyperLiquidPrice({\n price: orderPrice,\n szDecimals,\n });\n\n return { orderPrice, formattedSize, formattedPrice };\n}\n\n/**\n * Builds orders array including main order and optional TP/SL orders\n *\n * @param params - Order construction parameters\n * @returns Array of SDK order params and grouping type\n */\nexport function buildOrdersArray(\n params: BuildOrdersArrayParams,\n): BuildOrdersArrayResult {\n const {\n assetId,\n isBuy,\n formattedPrice,\n formattedSize,\n reduceOnly,\n orderType,\n clientOrderId,\n takeProfitPrice,\n stopLossPrice,\n szDecimals,\n grouping,\n } = params;\n\n const orders: SDKOrderParams[] = [];\n\n // 1. Main order\n const mainOrder: SDKOrderParams = {\n a: assetId,\n b: isBuy,\n p: formattedPrice,\n s: formattedSize,\n r: reduceOnly || false,\n t:\n orderType === 'limit'\n ? { limit: { tif: 'Gtc' } }\n : { limit: { tif: 'FrontendMarket' } },\n c: clientOrderId ? (clientOrderId as Hex) : undefined,\n };\n orders.push(mainOrder);\n\n // 2. Take Profit order\n if (takeProfitPrice) {\n const tpOrder: SDKOrderParams = {\n a: assetId,\n b: !isBuy,\n p: formatHyperLiquidPrice({\n price: parseFloat(takeProfitPrice),\n szDecimals,\n }),\n s: formattedSize,\n r: true,\n t: {\n trigger: {\n isMarket: false,\n triggerPx: formatHyperLiquidPrice({\n price: parseFloat(takeProfitPrice),\n szDecimals,\n }),\n tpsl: 'tp',\n },\n },\n };\n orders.push(tpOrder);\n }\n\n // 3. Stop Loss order\n if (stopLossPrice) {\n // Apply 10% slippage to SL limit price (executes as market order when triggered)\n // HyperLiquid recommended: 10% for TP/SL orders\n const stopLossPriceNum = parseFloat(stopLossPrice);\n const slippageValue = ORDER_SLIPPAGE_CONFIG.DefaultTpslSlippageBps / 10000;\n const limitPriceWithSlippage = isBuy\n ? stopLossPriceNum * (1 - slippageValue) // Selling to close long: willing to accept LESS (slippage protection)\n : stopLossPriceNum * (1 + slippageValue); // Buying to close short: willing to pay MORE (slippage protection)\n\n const slOrder: SDKOrderParams = {\n a: assetId,\n b: !isBuy,\n p: formatHyperLiquidPrice({\n price: limitPriceWithSlippage,\n szDecimals,\n }),\n s: formattedSize,\n r: true,\n t: {\n trigger: {\n isMarket: true,\n triggerPx: formatHyperLiquidPrice({\n price: stopLossPriceNum,\n szDecimals,\n }),\n tpsl: 'sl',\n },\n },\n };\n orders.push(slOrder);\n }\n\n // Determine grouping\n const finalGrouping: 'na' | 'normalTpsl' | 'positionTpsl' =\n grouping ?? ((takeProfitPrice ?? stopLossPrice) ? 'normalTpsl' : 'na');\n\n return { orders, grouping: finalGrouping };\n}\n"]}
@@ -1,107 +0,0 @@
1
- import type { PerpsDebugLogger } from "../types/index.cjs";
2
- import type { SDKOrderParams } from "../types/hyperliquid-types.cjs";
3
- /**
4
- * Optional debug logger for order calculation functions.
5
- * When provided, enables detailed logging for debugging.
6
- */
7
- export type OrderCalculationsDebugLogger = PerpsDebugLogger | undefined;
8
- type PositionSizeParams = {
9
- amount: string;
10
- price: number;
11
- szDecimals: number;
12
- };
13
- type MarginRequiredParams = {
14
- amount: string;
15
- leverage: number;
16
- };
17
- type MaxAllowedAmountParams = {
18
- availableBalance: number;
19
- assetPrice: number;
20
- assetSzDecimals: number;
21
- leverage: number;
22
- };
23
- export type CalculateFinalPositionSizeParams = {
24
- usdAmount?: string;
25
- size?: string;
26
- currentPrice: number;
27
- priceAtCalculation?: number;
28
- maxSlippageBps?: number;
29
- szDecimals: number;
30
- leverage?: number;
31
- debugLogger?: OrderCalculationsDebugLogger;
32
- };
33
- export type CalculateFinalPositionSizeResult = {
34
- finalPositionSize: number;
35
- };
36
- export type CalculateOrderPriceAndSizeParams = {
37
- orderType: 'market' | 'limit';
38
- isBuy: boolean;
39
- finalPositionSize: number;
40
- currentPrice: number;
41
- limitPrice?: string;
42
- slippage?: number;
43
- szDecimals: number;
44
- };
45
- export type CalculateOrderPriceAndSizeResult = {
46
- orderPrice: number;
47
- formattedSize: string;
48
- formattedPrice: string;
49
- };
50
- export type BuildOrdersArrayParams = {
51
- assetId: number;
52
- isBuy: boolean;
53
- formattedPrice: string;
54
- formattedSize: string;
55
- reduceOnly: boolean;
56
- orderType: 'market' | 'limit';
57
- clientOrderId?: string;
58
- takeProfitPrice?: string;
59
- stopLossPrice?: string;
60
- szDecimals: number;
61
- grouping?: 'na' | 'normalTpsl' | 'positionTpsl';
62
- };
63
- export type BuildOrdersArrayResult = {
64
- orders: SDKOrderParams[];
65
- grouping: 'na' | 'normalTpsl' | 'positionTpsl';
66
- };
67
- /**
68
- * Calculate position size based on USD amount and asset price
69
- *
70
- * @param params - Amount in USD, current asset price, and required decimal precision
71
- * @returns Position size formatted to the asset's decimal precision
72
- */
73
- export declare function calculatePositionSize(params: PositionSizeParams): string;
74
- /**
75
- * Calculate margin required for a position
76
- *
77
- * @param params - Position amount and leverage
78
- * @returns Margin required formatted to 2 decimal places
79
- */
80
- export declare function calculateMarginRequired(params: MarginRequiredParams): string;
81
- export declare function getMaxAllowedAmount(params: MaxAllowedAmountParams): number;
82
- /**
83
- * Calculates final position size using USD as source of truth with price validation
84
- *
85
- * This function implements the hybrid approach where USD is the source of truth,
86
- * but includes price staleness validation and proper rounding to prevent precision loss.
87
- *
88
- * @param params - USD amount, size, prices, and configuration
89
- * @returns Final position size as a number
90
- */
91
- export declare function calculateFinalPositionSize(params: CalculateFinalPositionSizeParams): CalculateFinalPositionSizeResult;
92
- /**
93
- * Calculates order price and formatted size based on order type
94
- *
95
- * @param params - Order parameters including type, direction, size, and prices
96
- * @returns Formatted order price, size, and price string
97
- */
98
- export declare function calculateOrderPriceAndSize(params: CalculateOrderPriceAndSizeParams): CalculateOrderPriceAndSizeResult;
99
- /**
100
- * Builds orders array including main order and optional TP/SL orders
101
- *
102
- * @param params - Order construction parameters
103
- * @returns Array of SDK order params and grouping type
104
- */
105
- export declare function buildOrdersArray(params: BuildOrdersArrayParams): BuildOrdersArrayResult;
106
- export {};
107
- //# sourceMappingURL=orderCalculations.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"orderCalculations.d.cts","sourceRoot":"","sources":["../../src/utils/orderCalculations.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,gBAAgB,EAAE,2BAAiB;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,uCAAmC;AAEjE;;;GAGG;AACH,MAAM,MAAM,4BAA4B,GAAG,gBAAgB,GAAG,SAAS,CAAC;AAExE,KAAK,kBAAkB,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,KAAK,oBAAoB,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAGF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,4BAA4B,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,SAAS,EAAE,QAAQ,G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gCAAgC,GACvC,gCAAgC,CAsGlC;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,gCAAgC,GACvC,gCAAgC,CA2ClC;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,sBAAsB,GAC7B,sBAAsB,CA+FxB"}
@@ -1,107 +0,0 @@
1
- import type { PerpsDebugLogger } from "../types/index.mjs";
2
- import type { SDKOrderParams } from "../types/hyperliquid-types.mjs";
3
- /**
4
- * Optional debug logger for order calculation functions.
5
- * When provided, enables detailed logging for debugging.
6
- */
7
- export type OrderCalculationsDebugLogger = PerpsDebugLogger | undefined;
8
- type PositionSizeParams = {
9
- amount: string;
10
- price: number;
11
- szDecimals: number;
12
- };
13
- type MarginRequiredParams = {
14
- amount: string;
15
- leverage: number;
16
- };
17
- type MaxAllowedAmountParams = {
18
- availableBalance: number;
19
- assetPrice: number;
20
- assetSzDecimals: number;
21
- leverage: number;
22
- };
23
- export type CalculateFinalPositionSizeParams = {
24
- usdAmount?: string;
25
- size?: string;
26
- currentPrice: number;
27
- priceAtCalculation?: number;
28
- maxSlippageBps?: number;
29
- szDecimals: number;
30
- leverage?: number;
31
- debugLogger?: OrderCalculationsDebugLogger;
32
- };
33
- export type CalculateFinalPositionSizeResult = {
34
- finalPositionSize: number;
35
- };
36
- export type CalculateOrderPriceAndSizeParams = {
37
- orderType: 'market' | 'limit';
38
- isBuy: boolean;
39
- finalPositionSize: number;
40
- currentPrice: number;
41
- limitPrice?: string;
42
- slippage?: number;
43
- szDecimals: number;
44
- };
45
- export type CalculateOrderPriceAndSizeResult = {
46
- orderPrice: number;
47
- formattedSize: string;
48
- formattedPrice: string;
49
- };
50
- export type BuildOrdersArrayParams = {
51
- assetId: number;
52
- isBuy: boolean;
53
- formattedPrice: string;
54
- formattedSize: string;
55
- reduceOnly: boolean;
56
- orderType: 'market' | 'limit';
57
- clientOrderId?: string;
58
- takeProfitPrice?: string;
59
- stopLossPrice?: string;
60
- szDecimals: number;
61
- grouping?: 'na' | 'normalTpsl' | 'positionTpsl';
62
- };
63
- export type BuildOrdersArrayResult = {
64
- orders: SDKOrderParams[];
65
- grouping: 'na' | 'normalTpsl' | 'positionTpsl';
66
- };
67
- /**
68
- * Calculate position size based on USD amount and asset price
69
- *
70
- * @param params - Amount in USD, current asset price, and required decimal precision
71
- * @returns Position size formatted to the asset's decimal precision
72
- */
73
- export declare function calculatePositionSize(params: PositionSizeParams): string;
74
- /**
75
- * Calculate margin required for a position
76
- *
77
- * @param params - Position amount and leverage
78
- * @returns Margin required formatted to 2 decimal places
79
- */
80
- export declare function calculateMarginRequired(params: MarginRequiredParams): string;
81
- export declare function getMaxAllowedAmount(params: MaxAllowedAmountParams): number;
82
- /**
83
- * Calculates final position size using USD as source of truth with price validation
84
- *
85
- * This function implements the hybrid approach where USD is the source of truth,
86
- * but includes price staleness validation and proper rounding to prevent precision loss.
87
- *
88
- * @param params - USD amount, size, prices, and configuration
89
- * @returns Final position size as a number
90
- */
91
- export declare function calculateFinalPositionSize(params: CalculateFinalPositionSizeParams): CalculateFinalPositionSizeResult;
92
- /**
93
- * Calculates order price and formatted size based on order type
94
- *
95
- * @param params - Order parameters including type, direction, size, and prices
96
- * @returns Formatted order price, size, and price string
97
- */
98
- export declare function calculateOrderPriceAndSize(params: CalculateOrderPriceAndSizeParams): CalculateOrderPriceAndSizeResult;
99
- /**
100
- * Builds orders array including main order and optional TP/SL orders
101
- *
102
- * @param params - Order construction parameters
103
- * @returns Array of SDK order params and grouping type
104
- */
105
- export declare function buildOrdersArray(params: BuildOrdersArrayParams): BuildOrdersArrayResult;
106
- export {};
107
- //# sourceMappingURL=orderCalculations.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"orderCalculations.d.mts","sourceRoot":"","sources":["../../src/utils/orderCalculations.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,gBAAgB,EAAE,2BAAiB;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,u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