@metamask-previews/perps-controller 16.1.0-preview-abca9bcea → 17.0.0-preview-0a30e47

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 (891) hide show
  1. package/CHANGELOG.md +35 -1
  2. package/README.md +17 -0
  3. package/dist/PerpsController-method-action-types.d.ts +1235 -0
  4. package/dist/PerpsController-method-action-types.d.ts.map +1 -0
  5. package/dist/PerpsController-method-action-types.js +6 -0
  6. package/dist/PerpsController-method-action-types.js.map +1 -0
  7. package/dist/PerpsController.d.ts +1313 -0
  8. package/dist/PerpsController.d.ts.map +1 -0
  9. package/dist/PerpsController.js +5331 -0
  10. package/dist/PerpsController.js.map +1 -0
  11. package/dist/aggregation/SubscriptionMultiplexer.d.ts +171 -0
  12. package/dist/aggregation/SubscriptionMultiplexer.d.ts.map +1 -0
  13. package/dist/aggregation/SubscriptionMultiplexer.js +451 -0
  14. package/dist/aggregation/SubscriptionMultiplexer.js.map +1 -0
  15. package/dist/aggregation/index.d.ts +6 -0
  16. package/dist/aggregation/index.d.ts.map +1 -0
  17. package/dist/aggregation/index.js +5 -0
  18. package/dist/aggregation/index.js.map +1 -0
  19. package/dist/constants/chartConfig.d.ts +228 -0
  20. package/dist/constants/chartConfig.d.ts.map +1 -0
  21. package/dist/constants/chartConfig.js +233 -0
  22. package/dist/constants/chartConfig.js.map +1 -0
  23. package/dist/constants/eventNames.d.ts +565 -0
  24. package/dist/constants/eventNames.d.ts.map +1 -0
  25. package/dist/constants/eventNames.js +657 -0
  26. package/dist/constants/eventNames.js.map +1 -0
  27. package/dist/constants/hyperLiquidConfig.d.ts +280 -0
  28. package/dist/constants/hyperLiquidConfig.d.ts.map +1 -0
  29. package/dist/constants/hyperLiquidConfig.js +596 -0
  30. package/dist/constants/hyperLiquidConfig.js.map +1 -0
  31. package/dist/constants/index.d.ts +12 -0
  32. package/dist/constants/index.d.ts.map +1 -0
  33. package/dist/constants/index.js +12 -0
  34. package/dist/constants/index.js.map +1 -0
  35. package/dist/constants/lighterConfig.d.ts +204 -0
  36. package/dist/constants/lighterConfig.d.ts.map +1 -0
  37. package/dist/constants/lighterConfig.js +317 -0
  38. package/dist/constants/lighterConfig.js.map +1 -0
  39. package/dist/constants/orderTypes.d.ts +19 -0
  40. package/dist/constants/orderTypes.d.ts.map +1 -0
  41. package/dist/constants/orderTypes.js +27 -0
  42. package/dist/constants/orderTypes.js.map +1 -0
  43. package/dist/constants/performanceMetrics.d.ts +46 -0
  44. package/dist/constants/performanceMetrics.d.ts.map +1 -0
  45. package/dist/constants/performanceMetrics.js +60 -0
  46. package/dist/constants/performanceMetrics.js.map +1 -0
  47. package/dist/constants/perpsConfig.d.ts +480 -0
  48. package/dist/constants/perpsConfig.d.ts.map +1 -0
  49. package/dist/constants/perpsConfig.js +555 -0
  50. package/dist/constants/perpsConfig.js.map +1 -0
  51. package/dist/constants/transactionsHistoryConfig.d.ts +35 -0
  52. package/dist/constants/transactionsHistoryConfig.d.ts.map +1 -0
  53. package/dist/constants/transactionsHistoryConfig.js +35 -0
  54. package/dist/constants/transactionsHistoryConfig.js.map +1 -0
  55. package/dist/index.d.ts +95 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +80 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/perpsErrorCodes.d.ts +113 -0
  60. package/dist/perpsErrorCodes.d.ts.map +1 -0
  61. package/dist/perpsErrorCodes.js +133 -0
  62. package/dist/perpsErrorCodes.js.map +1 -0
  63. package/dist/providers/AggregatedPerpsProvider.d.ts +277 -0
  64. package/dist/providers/AggregatedPerpsProvider.d.ts.map +1 -0
  65. package/dist/providers/AggregatedPerpsProvider.js +827 -0
  66. package/dist/providers/AggregatedPerpsProvider.js.map +1 -0
  67. package/dist/providers/HyperLiquidProvider.d.ts +656 -0
  68. package/dist/providers/HyperLiquidProvider.d.ts.map +1 -0
  69. package/dist/providers/HyperLiquidProvider.js +11308 -0
  70. package/dist/providers/HyperLiquidProvider.js.map +1 -0
  71. package/dist/providers/LighterProvider.d.ts +179 -0
  72. package/dist/providers/LighterProvider.d.ts.map +1 -0
  73. package/dist/providers/LighterProvider.js +6599 -0
  74. package/dist/providers/LighterProvider.js.map +1 -0
  75. package/dist/routing/ProviderRouter.d.ts +112 -0
  76. package/dist/routing/ProviderRouter.d.ts.map +1 -0
  77. package/dist/routing/ProviderRouter.js +137 -0
  78. package/dist/routing/ProviderRouter.js.map +1 -0
  79. package/dist/routing/index.d.ts +6 -0
  80. package/dist/routing/index.d.ts.map +1 -0
  81. package/dist/routing/index.js +5 -0
  82. package/dist/routing/index.js.map +1 -0
  83. package/dist/selectors.d.ts +336 -0
  84. package/dist/selectors.d.ts.map +1 -0
  85. package/dist/selectors.js +249 -0
  86. package/dist/selectors.js.map +1 -0
  87. package/dist/services/AccountService.d.ts +56 -0
  88. package/dist/services/AccountService.d.ts.map +1 -0
  89. package/dist/services/AccountService.js +307 -0
  90. package/dist/services/AccountService.js.map +1 -0
  91. package/dist/services/AggregatedOrderBookConnection.d.ts +106 -0
  92. package/dist/services/AggregatedOrderBookConnection.d.ts.map +1 -0
  93. package/dist/services/AggregatedOrderBookConnection.js +388 -0
  94. package/dist/services/AggregatedOrderBookConnection.js.map +1 -0
  95. package/dist/services/DataLakeService.d.ts +51 -0
  96. package/dist/services/DataLakeService.d.ts.map +1 -0
  97. package/dist/services/DataLakeService.js +215 -0
  98. package/dist/services/DataLakeService.js.map +1 -0
  99. package/dist/services/DepositService.d.ts +39 -0
  100. package/dist/services/DepositService.d.ts.map +1 -0
  101. package/dist/services/DepositService.js +88 -0
  102. package/dist/services/DepositService.js.map +1 -0
  103. package/dist/services/DexDiscoveryCacheManager.d.ts +52 -0
  104. package/dist/services/DexDiscoveryCacheManager.d.ts.map +1 -0
  105. package/dist/services/DexDiscoveryCacheManager.js +130 -0
  106. package/dist/services/DexDiscoveryCacheManager.js.map +1 -0
  107. package/dist/services/EligibilityService.d.ts +28 -0
  108. package/dist/services/EligibilityService.d.ts.map +1 -0
  109. package/dist/services/EligibilityService.js +61 -0
  110. package/dist/services/EligibilityService.js.map +1 -0
  111. package/dist/services/FeatureFlagConfigurationService.d.ts +73 -0
  112. package/dist/services/FeatureFlagConfigurationService.d.ts.map +1 -0
  113. package/dist/services/FeatureFlagConfigurationService.js +266 -0
  114. package/dist/services/FeatureFlagConfigurationService.js.map +1 -0
  115. package/dist/services/HyperLiquidClientService.d.ts +252 -0
  116. package/dist/services/HyperLiquidClientService.d.ts.map +1 -0
  117. package/dist/services/HyperLiquidClientService.js +1152 -0
  118. package/dist/services/HyperLiquidClientService.js.map +1 -0
  119. package/dist/services/HyperLiquidSubscriptionService.d.ts +265 -0
  120. package/dist/services/HyperLiquidSubscriptionService.d.ts.map +1 -0
  121. package/dist/services/HyperLiquidSubscriptionService.js +3874 -0
  122. package/dist/services/HyperLiquidSubscriptionService.js.map +1 -0
  123. package/dist/services/HyperLiquidWalletService.d.ts +84 -0
  124. package/dist/services/HyperLiquidWalletService.d.ts.map +1 -0
  125. package/dist/services/HyperLiquidWalletService.js +168 -0
  126. package/dist/services/HyperLiquidWalletService.js.map +1 -0
  127. package/dist/services/LighterClientService.d.ts +200 -0
  128. package/dist/services/LighterClientService.d.ts.map +1 -0
  129. package/dist/services/LighterClientService.js +634 -0
  130. package/dist/services/LighterClientService.js.map +1 -0
  131. package/dist/services/LighterWalletService.d.ts +51 -0
  132. package/dist/services/LighterWalletService.d.ts.map +1 -0
  133. package/dist/services/LighterWalletService.js +92 -0
  134. package/dist/services/LighterWalletService.js.map +1 -0
  135. package/dist/services/MarketDataService.d.ts +350 -0
  136. package/dist/services/MarketDataService.d.ts.map +1 -0
  137. package/dist/services/MarketDataService.js +1165 -0
  138. package/dist/services/MarketDataService.js.map +1 -0
  139. package/dist/services/RewardsIntegrationService.d.ts +84 -0
  140. package/dist/services/RewardsIntegrationService.d.ts.map +1 -0
  141. package/dist/services/RewardsIntegrationService.js +380 -0
  142. package/dist/services/RewardsIntegrationService.js.map +1 -0
  143. package/dist/services/ServiceContext.d.ts +102 -0
  144. package/dist/services/ServiceContext.d.ts.map +1 -0
  145. package/dist/services/ServiceContext.js +2 -0
  146. package/dist/services/ServiceContext.js.map +1 -0
  147. package/dist/services/TerminalMarketService.d.ts +45 -0
  148. package/dist/services/TerminalMarketService.d.ts.map +1 -0
  149. package/dist/services/TerminalMarketService.js +640 -0
  150. package/dist/services/TerminalMarketService.js.map +1 -0
  151. package/dist/services/TradingReadinessCache.d.ts +204 -0
  152. package/dist/services/TradingReadinessCache.d.ts.map +1 -0
  153. package/dist/services/TradingReadinessCache.js +313 -0
  154. package/dist/services/TradingReadinessCache.js.map +1 -0
  155. package/dist/services/TradingService.d.ts +201 -0
  156. package/dist/services/TradingService.d.ts.map +1 -0
  157. package/dist/services/TradingService.js +1967 -0
  158. package/dist/services/TradingService.js.map +1 -0
  159. package/dist/types/config.d.ts +49 -0
  160. package/dist/types/config.d.ts.map +1 -0
  161. package/dist/types/config.js +2 -0
  162. package/dist/types/config.js.map +1 -0
  163. package/dist/types/hyperliquid-types.d.ts +67 -0
  164. package/dist/types/hyperliquid-types.d.ts.map +1 -0
  165. package/dist/types/hyperliquid-types.js +41 -0
  166. package/dist/types/hyperliquid-types.js.map +1 -0
  167. package/dist/types/index.d.ts +2192 -0
  168. package/dist/types/index.d.ts.map +1 -0
  169. package/dist/types/index.js +133 -0
  170. package/dist/types/index.js.map +1 -0
  171. package/dist/types/lighter-types.d.ts +772 -0
  172. package/dist/types/lighter-types.d.ts.map +1 -0
  173. package/dist/types/lighter-types.js +10 -0
  174. package/dist/types/lighter-types.js.map +1 -0
  175. package/dist/types/messenger.d.ts +30 -0
  176. package/dist/types/messenger.d.ts.map +1 -0
  177. package/dist/types/messenger.js +2 -0
  178. package/dist/types/messenger.js.map +1 -0
  179. package/dist/types/perps-types.d.ts +184 -0
  180. package/dist/types/perps-types.d.ts.map +1 -0
  181. package/dist/types/perps-types.js +2 -0
  182. package/dist/types/perps-types.js.map +1 -0
  183. package/dist/types/token.d.ts +25 -0
  184. package/dist/types/token.d.ts.map +1 -0
  185. package/dist/types/token.js +2 -0
  186. package/dist/types/token.js.map +1 -0
  187. package/dist/types/transactionTypes.d.ts +60 -0
  188. package/dist/types/transactionTypes.d.ts.map +1 -0
  189. package/dist/types/transactionTypes.js +24 -0
  190. package/dist/types/transactionTypes.js.map +1 -0
  191. package/dist/utils/accountUtils.d.ts +72 -0
  192. package/dist/utils/accountUtils.d.ts.map +1 -0
  193. package/dist/utils/accountUtils.js +223 -0
  194. package/dist/utils/accountUtils.js.map +1 -0
  195. package/dist/utils/capabilitySymbols.d.ts +15 -0
  196. package/dist/utils/capabilitySymbols.d.ts.map +1 -0
  197. package/dist/utils/capabilitySymbols.js +21 -0
  198. package/dist/utils/capabilitySymbols.js.map +1 -0
  199. package/dist/utils/coalescePerpsRestRequest.d.ts +32 -0
  200. package/dist/utils/coalescePerpsRestRequest.d.ts.map +1 -0
  201. package/dist/utils/coalescePerpsRestRequest.js +66 -0
  202. package/dist/utils/coalescePerpsRestRequest.js.map +1 -0
  203. package/dist/utils/errorUtils.d.ts +50 -0
  204. package/dist/utils/errorUtils.d.ts.map +1 -0
  205. package/dist/utils/errorUtils.js +96 -0
  206. package/dist/utils/errorUtils.js.map +1 -0
  207. package/dist/utils/hyperLiquidAbstraction.d.ts +11 -0
  208. package/dist/utils/hyperLiquidAbstraction.d.ts.map +1 -0
  209. package/dist/utils/hyperLiquidAbstraction.js +19 -0
  210. package/dist/utils/hyperLiquidAbstraction.js.map +1 -0
  211. package/dist/utils/hyperLiquidAdapter.d.ts +77 -0
  212. package/dist/utils/hyperLiquidAdapter.d.ts.map +1 -0
  213. package/dist/utils/hyperLiquidAdapter.js +495 -0
  214. package/dist/utils/hyperLiquidAdapter.js.map +1 -0
  215. package/dist/utils/hyperLiquidOrderBookProcessor.d.ts +55 -0
  216. package/dist/utils/hyperLiquidOrderBookProcessor.d.ts.map +1 -0
  217. package/dist/utils/hyperLiquidOrderBookProcessor.js +78 -0
  218. package/dist/utils/hyperLiquidOrderBookProcessor.js.map +1 -0
  219. package/dist/utils/hyperLiquidPositionPreview.d.ts +124 -0
  220. package/dist/utils/hyperLiquidPositionPreview.d.ts.map +1 -0
  221. package/dist/utils/hyperLiquidPositionPreview.js +347 -0
  222. package/dist/utils/hyperLiquidPositionPreview.js.map +1 -0
  223. package/dist/utils/hyperLiquidValidation.d.ts +192 -0
  224. package/dist/utils/hyperLiquidValidation.d.ts.map +1 -0
  225. package/dist/utils/hyperLiquidValidation.js +786 -0
  226. package/dist/utils/hyperLiquidValidation.js.map +1 -0
  227. package/dist/utils/idUtils.d.ts +6 -0
  228. package/dist/utils/idUtils.d.ts.map +1 -0
  229. package/dist/utils/idUtils.js +10 -0
  230. package/dist/utils/idUtils.js.map +1 -0
  231. package/dist/utils/index.d.ts +29 -0
  232. package/dist/utils/index.d.ts.map +1 -0
  233. package/dist/utils/index.js +34 -0
  234. package/dist/utils/index.js.map +1 -0
  235. package/dist/utils/lighterAdapter.d.ts +117 -0
  236. package/dist/utils/lighterAdapter.d.ts.map +1 -0
  237. package/dist/utils/lighterAdapter.js +562 -0
  238. package/dist/utils/lighterAdapter.js.map +1 -0
  239. package/dist/utils/marketDataTransform.d.ts +71 -0
  240. package/dist/utils/marketDataTransform.d.ts.map +1 -0
  241. package/dist/utils/marketDataTransform.js +243 -0
  242. package/dist/utils/marketDataTransform.js.map +1 -0
  243. package/dist/utils/marketSearch.d.ts +48 -0
  244. package/dist/utils/marketSearch.d.ts.map +1 -0
  245. package/dist/utils/marketSearch.js +106 -0
  246. package/dist/utils/marketSearch.js.map +1 -0
  247. package/dist/utils/marketUtils.d.ts +73 -0
  248. package/dist/utils/marketUtils.d.ts.map +1 -0
  249. package/dist/utils/marketUtils.js +248 -0
  250. package/dist/utils/marketUtils.js.map +1 -0
  251. package/dist/utils/orderCalculations.d.ts +306 -0
  252. package/dist/utils/orderCalculations.d.ts.map +1 -0
  253. package/dist/utils/orderCalculations.js +833 -0
  254. package/dist/utils/orderCalculations.js.map +1 -0
  255. package/dist/utils/orderTypes.d.ts +166 -0
  256. package/dist/utils/orderTypes.d.ts.map +1 -0
  257. package/dist/utils/orderTypes.js +287 -0
  258. package/dist/utils/orderTypes.js.map +1 -0
  259. package/dist/utils/perpsConnectionAttemptContext.d.ts +7 -0
  260. package/dist/utils/perpsConnectionAttemptContext.d.ts.map +1 -0
  261. package/dist/utils/perpsConnectionAttemptContext.js +15 -0
  262. package/dist/utils/perpsConnectionAttemptContext.js.map +1 -0
  263. package/dist/utils/perpsDiskPersistence.d.ts +112 -0
  264. package/dist/utils/perpsDiskPersistence.d.ts.map +1 -0
  265. package/dist/utils/perpsDiskPersistence.js +251 -0
  266. package/dist/utils/perpsDiskPersistence.js.map +1 -0
  267. package/dist/utils/perpsFormatters.d.ts +204 -0
  268. package/dist/utils/perpsFormatters.d.ts.map +1 -0
  269. package/dist/utils/perpsFormatters.js +500 -0
  270. package/dist/utils/perpsFormatters.js.map +1 -0
  271. package/dist/utils/rewardsUtils.d.ts +33 -0
  272. package/dist/utils/rewardsUtils.d.ts.map +1 -0
  273. package/dist/utils/rewardsUtils.js +92 -0
  274. package/dist/utils/rewardsUtils.js.map +1 -0
  275. package/dist/utils/significantFigures.d.ts +25 -0
  276. package/dist/utils/significantFigures.d.ts.map +1 -0
  277. package/dist/utils/significantFigures.js +82 -0
  278. package/dist/utils/significantFigures.js.map +1 -0
  279. package/dist/utils/sortMarkets.d.ts +25 -0
  280. package/dist/utils/sortMarkets.d.ts.map +1 -0
  281. package/dist/utils/sortMarkets.js +88 -0
  282. package/dist/utils/sortMarkets.js.map +1 -0
  283. package/dist/utils/standaloneInfoClient.d.ts +37 -0
  284. package/dist/utils/standaloneInfoClient.d.ts.map +1 -0
  285. package/dist/utils/standaloneInfoClient.js +64 -0
  286. package/dist/utils/standaloneInfoClient.js.map +1 -0
  287. package/dist/utils/stringParseUtils.d.ts +11 -0
  288. package/dist/utils/stringParseUtils.d.ts.map +1 -0
  289. package/dist/utils/stringParseUtils.js +28 -0
  290. package/dist/utils/stringParseUtils.js.map +1 -0
  291. package/dist/utils/transferData.d.ts +9 -0
  292. package/dist/utils/transferData.d.ts.map +1 -0
  293. package/dist/utils/transferData.js +29 -0
  294. package/dist/utils/transferData.js.map +1 -0
  295. package/dist/utils/wait.d.ts +2 -0
  296. package/dist/utils/wait.d.ts.map +1 -0
  297. package/dist/utils/wait.js +2 -0
  298. package/dist/utils/wait.js.map +1 -0
  299. package/package.json +33 -61
  300. package/dist/PerpsController-method-action-types.cjs +0 -7
  301. package/dist/PerpsController-method-action-types.cjs.map +0 -1
  302. package/dist/PerpsController-method-action-types.d.cts +0 -1235
  303. package/dist/PerpsController-method-action-types.d.cts.map +0 -1
  304. package/dist/PerpsController-method-action-types.d.mts +0 -1235
  305. package/dist/PerpsController-method-action-types.d.mts.map +0 -1
  306. package/dist/PerpsController-method-action-types.mjs +0 -6
  307. package/dist/PerpsController-method-action-types.mjs.map +0 -1
  308. package/dist/PerpsController.cjs +0 -5154
  309. package/dist/PerpsController.cjs.map +0 -1
  310. package/dist/PerpsController.d.cts +0 -1313
  311. package/dist/PerpsController.d.cts.map +0 -1
  312. package/dist/PerpsController.d.mts +0 -1313
  313. package/dist/PerpsController.d.mts.map +0 -1
  314. package/dist/PerpsController.mjs +0 -5142
  315. package/dist/PerpsController.mjs.map +0 -1
  316. package/dist/aggregation/SubscriptionMultiplexer.cjs +0 -441
  317. package/dist/aggregation/SubscriptionMultiplexer.cjs.map +0 -1
  318. package/dist/aggregation/SubscriptionMultiplexer.d.cts +0 -171
  319. package/dist/aggregation/SubscriptionMultiplexer.d.cts.map +0 -1
  320. package/dist/aggregation/SubscriptionMultiplexer.d.mts +0 -171
  321. package/dist/aggregation/SubscriptionMultiplexer.d.mts.map +0 -1
  322. package/dist/aggregation/SubscriptionMultiplexer.mjs +0 -437
  323. package/dist/aggregation/SubscriptionMultiplexer.mjs.map +0 -1
  324. package/dist/aggregation/index.cjs +0 -9
  325. package/dist/aggregation/index.cjs.map +0 -1
  326. package/dist/aggregation/index.d.cts +0 -6
  327. package/dist/aggregation/index.d.cts.map +0 -1
  328. package/dist/aggregation/index.d.mts +0 -6
  329. package/dist/aggregation/index.d.mts.map +0 -1
  330. package/dist/aggregation/index.mjs +0 -5
  331. package/dist/aggregation/index.mjs.map +0 -1
  332. package/dist/constants/chartConfig.cjs +0 -239
  333. package/dist/constants/chartConfig.cjs.map +0 -1
  334. package/dist/constants/chartConfig.d.cts +0 -228
  335. package/dist/constants/chartConfig.d.cts.map +0 -1
  336. package/dist/constants/chartConfig.d.mts +0 -228
  337. package/dist/constants/chartConfig.d.mts.map +0 -1
  338. package/dist/constants/chartConfig.mjs +0 -233
  339. package/dist/constants/chartConfig.mjs.map +0 -1
  340. package/dist/constants/eventNames.cjs +0 -660
  341. package/dist/constants/eventNames.cjs.map +0 -1
  342. package/dist/constants/eventNames.d.cts +0 -565
  343. package/dist/constants/eventNames.d.cts.map +0 -1
  344. package/dist/constants/eventNames.d.mts +0 -565
  345. package/dist/constants/eventNames.d.mts.map +0 -1
  346. package/dist/constants/eventNames.mjs +0 -657
  347. package/dist/constants/eventNames.mjs.map +0 -1
  348. package/dist/constants/hyperLiquidConfig.cjs +0 -607
  349. package/dist/constants/hyperLiquidConfig.cjs.map +0 -1
  350. package/dist/constants/hyperLiquidConfig.d.cts +0 -280
  351. package/dist/constants/hyperLiquidConfig.d.cts.map +0 -1
  352. package/dist/constants/hyperLiquidConfig.d.mts +0 -280
  353. package/dist/constants/hyperLiquidConfig.d.mts.map +0 -1
  354. package/dist/constants/hyperLiquidConfig.mjs +0 -596
  355. package/dist/constants/hyperLiquidConfig.mjs.map +0 -1
  356. package/dist/constants/index.cjs +0 -28
  357. package/dist/constants/index.cjs.map +0 -1
  358. package/dist/constants/index.d.cts +0 -12
  359. package/dist/constants/index.d.cts.map +0 -1
  360. package/dist/constants/index.d.mts +0 -12
  361. package/dist/constants/index.d.mts.map +0 -1
  362. package/dist/constants/index.mjs +0 -12
  363. package/dist/constants/index.mjs.map +0 -1
  364. package/dist/constants/lighterConfig.cjs +0 -328
  365. package/dist/constants/lighterConfig.cjs.map +0 -1
  366. package/dist/constants/lighterConfig.d.cts +0 -204
  367. package/dist/constants/lighterConfig.d.cts.map +0 -1
  368. package/dist/constants/lighterConfig.d.mts +0 -204
  369. package/dist/constants/lighterConfig.d.mts.map +0 -1
  370. package/dist/constants/lighterConfig.mjs +0 -317
  371. package/dist/constants/lighterConfig.mjs.map +0 -1
  372. package/dist/constants/orderTypes.cjs +0 -31
  373. package/dist/constants/orderTypes.cjs.map +0 -1
  374. package/dist/constants/orderTypes.d.cts +0 -19
  375. package/dist/constants/orderTypes.d.cts.map +0 -1
  376. package/dist/constants/orderTypes.d.mts +0 -19
  377. package/dist/constants/orderTypes.d.mts.map +0 -1
  378. package/dist/constants/orderTypes.mjs +0 -27
  379. package/dist/constants/orderTypes.mjs.map +0 -1
  380. package/dist/constants/performanceMetrics.cjs +0 -63
  381. package/dist/constants/performanceMetrics.cjs.map +0 -1
  382. package/dist/constants/performanceMetrics.d.cts +0 -46
  383. package/dist/constants/performanceMetrics.d.cts.map +0 -1
  384. package/dist/constants/performanceMetrics.d.mts +0 -46
  385. package/dist/constants/performanceMetrics.d.mts.map +0 -1
  386. package/dist/constants/performanceMetrics.mjs +0 -60
  387. package/dist/constants/performanceMetrics.mjs.map +0 -1
  388. package/dist/constants/perpsConfig.cjs +0 -560
  389. package/dist/constants/perpsConfig.cjs.map +0 -1
  390. package/dist/constants/perpsConfig.d.cts +0 -480
  391. package/dist/constants/perpsConfig.d.cts.map +0 -1
  392. package/dist/constants/perpsConfig.d.mts +0 -480
  393. package/dist/constants/perpsConfig.d.mts.map +0 -1
  394. package/dist/constants/perpsConfig.mjs +0 -555
  395. package/dist/constants/perpsConfig.mjs.map +0 -1
  396. package/dist/constants/transactionsHistoryConfig.cjs +0 -38
  397. package/dist/constants/transactionsHistoryConfig.cjs.map +0 -1
  398. package/dist/constants/transactionsHistoryConfig.d.cts +0 -35
  399. package/dist/constants/transactionsHistoryConfig.d.cts.map +0 -1
  400. package/dist/constants/transactionsHistoryConfig.d.mts +0 -35
  401. package/dist/constants/transactionsHistoryConfig.d.mts.map +0 -1
  402. package/dist/constants/transactionsHistoryConfig.mjs +0 -35
  403. package/dist/constants/transactionsHistoryConfig.mjs.map +0 -1
  404. package/dist/index.cjs +0 -334
  405. package/dist/index.cjs.map +0 -1
  406. package/dist/index.d.cts +0 -95
  407. package/dist/index.d.cts.map +0 -1
  408. package/dist/index.d.mts +0 -95
  409. package/dist/index.d.mts.map +0 -1
  410. package/dist/index.mjs +0 -80
  411. package/dist/index.mjs.map +0 -1
  412. package/dist/perpsErrorCodes.cjs +0 -128
  413. package/dist/perpsErrorCodes.cjs.map +0 -1
  414. package/dist/perpsErrorCodes.d.cts +0 -105
  415. package/dist/perpsErrorCodes.d.cts.map +0 -1
  416. package/dist/perpsErrorCodes.d.mts +0 -105
  417. package/dist/perpsErrorCodes.d.mts.map +0 -1
  418. package/dist/perpsErrorCodes.mjs +0 -125
  419. package/dist/perpsErrorCodes.mjs.map +0 -1
  420. package/dist/providers/AggregatedPerpsProvider.cjs +0 -810
  421. package/dist/providers/AggregatedPerpsProvider.cjs.map +0 -1
  422. package/dist/providers/AggregatedPerpsProvider.d.cts +0 -277
  423. package/dist/providers/AggregatedPerpsProvider.d.cts.map +0 -1
  424. package/dist/providers/AggregatedPerpsProvider.d.mts +0 -277
  425. package/dist/providers/AggregatedPerpsProvider.d.mts.map +0 -1
  426. package/dist/providers/AggregatedPerpsProvider.mjs +0 -805
  427. package/dist/providers/AggregatedPerpsProvider.mjs.map +0 -1
  428. package/dist/providers/HyperLiquidProvider.cjs +0 -10963
  429. package/dist/providers/HyperLiquidProvider.cjs.map +0 -1
  430. package/dist/providers/HyperLiquidProvider.d.cts +0 -656
  431. package/dist/providers/HyperLiquidProvider.d.cts.map +0 -1
  432. package/dist/providers/HyperLiquidProvider.d.mts +0 -656
  433. package/dist/providers/HyperLiquidProvider.d.mts.map +0 -1
  434. package/dist/providers/HyperLiquidProvider.mjs +0 -10959
  435. package/dist/providers/HyperLiquidProvider.mjs.map +0 -1
  436. package/dist/providers/LighterProvider.cjs +0 -6575
  437. package/dist/providers/LighterProvider.cjs.map +0 -1
  438. package/dist/providers/LighterProvider.d.cts +0 -179
  439. package/dist/providers/LighterProvider.d.cts.map +0 -1
  440. package/dist/providers/LighterProvider.d.mts +0 -179
  441. package/dist/providers/LighterProvider.d.mts.map +0 -1
  442. package/dist/providers/LighterProvider.mjs +0 -6571
  443. package/dist/providers/LighterProvider.mjs.map +0 -1
  444. package/dist/routing/ProviderRouter.cjs +0 -154
  445. package/dist/routing/ProviderRouter.cjs.map +0 -1
  446. package/dist/routing/ProviderRouter.d.cts +0 -112
  447. package/dist/routing/ProviderRouter.d.cts.map +0 -1
  448. package/dist/routing/ProviderRouter.d.mts +0 -112
  449. package/dist/routing/ProviderRouter.d.mts.map +0 -1
  450. package/dist/routing/ProviderRouter.mjs +0 -150
  451. package/dist/routing/ProviderRouter.mjs.map +0 -1
  452. package/dist/routing/index.cjs +0 -9
  453. package/dist/routing/index.cjs.map +0 -1
  454. package/dist/routing/index.d.cts +0 -6
  455. package/dist/routing/index.d.cts.map +0 -1
  456. package/dist/routing/index.d.mts +0 -6
  457. package/dist/routing/index.d.mts.map +0 -1
  458. package/dist/routing/index.mjs +0 -5
  459. package/dist/routing/index.mjs.map +0 -1
  460. package/dist/selectors.cjs +0 -264
  461. package/dist/selectors.cjs.map +0 -1
  462. package/dist/selectors.d.cts +0 -336
  463. package/dist/selectors.d.cts.map +0 -1
  464. package/dist/selectors.d.mts +0 -336
  465. package/dist/selectors.d.mts.map +0 -1
  466. package/dist/selectors.mjs +0 -249
  467. package/dist/selectors.mjs.map +0 -1
  468. package/dist/services/AccountService.cjs +0 -324
  469. package/dist/services/AccountService.cjs.map +0 -1
  470. package/dist/services/AccountService.d.cts +0 -56
  471. package/dist/services/AccountService.d.cts.map +0 -1
  472. package/dist/services/AccountService.d.mts +0 -56
  473. package/dist/services/AccountService.d.mts.map +0 -1
  474. package/dist/services/AccountService.mjs +0 -320
  475. package/dist/services/AccountService.mjs.map +0 -1
  476. package/dist/services/AggregatedOrderBookConnection.cjs +0 -405
  477. package/dist/services/AggregatedOrderBookConnection.cjs.map +0 -1
  478. package/dist/services/AggregatedOrderBookConnection.d.cts +0 -106
  479. package/dist/services/AggregatedOrderBookConnection.d.cts.map +0 -1
  480. package/dist/services/AggregatedOrderBookConnection.d.mts +0 -106
  481. package/dist/services/AggregatedOrderBookConnection.d.mts.map +0 -1
  482. package/dist/services/AggregatedOrderBookConnection.mjs +0 -400
  483. package/dist/services/AggregatedOrderBookConnection.mjs.map +0 -1
  484. package/dist/services/DataLakeService.cjs +0 -233
  485. package/dist/services/DataLakeService.cjs.map +0 -1
  486. package/dist/services/DataLakeService.d.cts +0 -51
  487. package/dist/services/DataLakeService.d.cts.map +0 -1
  488. package/dist/services/DataLakeService.d.mts +0 -51
  489. package/dist/services/DataLakeService.d.mts.map +0 -1
  490. package/dist/services/DataLakeService.mjs +0 -229
  491. package/dist/services/DataLakeService.mjs.map +0 -1
  492. package/dist/services/DepositService.cjs +0 -105
  493. package/dist/services/DepositService.cjs.map +0 -1
  494. package/dist/services/DepositService.d.cts +0 -39
  495. package/dist/services/DepositService.d.cts.map +0 -1
  496. package/dist/services/DepositService.d.mts +0 -39
  497. package/dist/services/DepositService.d.mts.map +0 -1
  498. package/dist/services/DepositService.mjs +0 -101
  499. package/dist/services/DepositService.mjs.map +0 -1
  500. package/dist/services/DexDiscoveryCacheManager.cjs +0 -147
  501. package/dist/services/DexDiscoveryCacheManager.cjs.map +0 -1
  502. package/dist/services/DexDiscoveryCacheManager.d.cts +0 -52
  503. package/dist/services/DexDiscoveryCacheManager.d.cts.map +0 -1
  504. package/dist/services/DexDiscoveryCacheManager.d.mts +0 -52
  505. package/dist/services/DexDiscoveryCacheManager.d.mts.map +0 -1
  506. package/dist/services/DexDiscoveryCacheManager.mjs +0 -143
  507. package/dist/services/DexDiscoveryCacheManager.mjs.map +0 -1
  508. package/dist/services/EligibilityService.cjs +0 -78
  509. package/dist/services/EligibilityService.cjs.map +0 -1
  510. package/dist/services/EligibilityService.d.cts +0 -28
  511. package/dist/services/EligibilityService.d.cts.map +0 -1
  512. package/dist/services/EligibilityService.d.mts +0 -28
  513. package/dist/services/EligibilityService.d.mts.map +0 -1
  514. package/dist/services/EligibilityService.mjs +0 -74
  515. package/dist/services/EligibilityService.mjs.map +0 -1
  516. package/dist/services/FeatureFlagConfigurationService.cjs +0 -257
  517. package/dist/services/FeatureFlagConfigurationService.cjs.map +0 -1
  518. package/dist/services/FeatureFlagConfigurationService.d.cts +0 -73
  519. package/dist/services/FeatureFlagConfigurationService.d.cts.map +0 -1
  520. package/dist/services/FeatureFlagConfigurationService.d.mts +0 -73
  521. package/dist/services/FeatureFlagConfigurationService.d.mts.map +0 -1
  522. package/dist/services/FeatureFlagConfigurationService.mjs +0 -253
  523. package/dist/services/FeatureFlagConfigurationService.mjs.map +0 -1
  524. package/dist/services/HyperLiquidClientService.cjs +0 -1114
  525. package/dist/services/HyperLiquidClientService.cjs.map +0 -1
  526. package/dist/services/HyperLiquidClientService.d.cts +0 -252
  527. package/dist/services/HyperLiquidClientService.d.cts.map +0 -1
  528. package/dist/services/HyperLiquidClientService.d.mts +0 -252
  529. package/dist/services/HyperLiquidClientService.d.mts.map +0 -1
  530. package/dist/services/HyperLiquidClientService.mjs +0 -1109
  531. package/dist/services/HyperLiquidClientService.mjs.map +0 -1
  532. package/dist/services/HyperLiquidSubscriptionService.cjs +0 -3594
  533. package/dist/services/HyperLiquidSubscriptionService.cjs.map +0 -1
  534. package/dist/services/HyperLiquidSubscriptionService.d.cts +0 -265
  535. package/dist/services/HyperLiquidSubscriptionService.d.cts.map +0 -1
  536. package/dist/services/HyperLiquidSubscriptionService.d.mts +0 -265
  537. package/dist/services/HyperLiquidSubscriptionService.d.mts.map +0 -1
  538. package/dist/services/HyperLiquidSubscriptionService.mjs +0 -3590
  539. package/dist/services/HyperLiquidSubscriptionService.mjs.map +0 -1
  540. package/dist/services/HyperLiquidWalletService.cjs +0 -186
  541. package/dist/services/HyperLiquidWalletService.cjs.map +0 -1
  542. package/dist/services/HyperLiquidWalletService.d.cts +0 -84
  543. package/dist/services/HyperLiquidWalletService.d.cts.map +0 -1
  544. package/dist/services/HyperLiquidWalletService.d.mts +0 -84
  545. package/dist/services/HyperLiquidWalletService.d.mts.map +0 -1
  546. package/dist/services/HyperLiquidWalletService.mjs +0 -182
  547. package/dist/services/HyperLiquidWalletService.mjs.map +0 -1
  548. package/dist/services/LighterClientService.cjs +0 -643
  549. package/dist/services/LighterClientService.cjs.map +0 -1
  550. package/dist/services/LighterClientService.d.cts +0 -200
  551. package/dist/services/LighterClientService.d.cts.map +0 -1
  552. package/dist/services/LighterClientService.d.mts +0 -200
  553. package/dist/services/LighterClientService.d.mts.map +0 -1
  554. package/dist/services/LighterClientService.mjs +0 -637
  555. package/dist/services/LighterClientService.mjs.map +0 -1
  556. package/dist/services/LighterWalletService.cjs +0 -109
  557. package/dist/services/LighterWalletService.cjs.map +0 -1
  558. package/dist/services/LighterWalletService.d.cts +0 -51
  559. package/dist/services/LighterWalletService.d.cts.map +0 -1
  560. package/dist/services/LighterWalletService.d.mts +0 -51
  561. package/dist/services/LighterWalletService.d.mts.map +0 -1
  562. package/dist/services/LighterWalletService.mjs +0 -105
  563. package/dist/services/LighterWalletService.mjs.map +0 -1
  564. package/dist/services/MarketDataService.cjs +0 -1171
  565. package/dist/services/MarketDataService.cjs.map +0 -1
  566. package/dist/services/MarketDataService.d.cts +0 -350
  567. package/dist/services/MarketDataService.d.cts.map +0 -1
  568. package/dist/services/MarketDataService.d.mts +0 -350
  569. package/dist/services/MarketDataService.d.mts.map +0 -1
  570. package/dist/services/MarketDataService.mjs +0 -1167
  571. package/dist/services/MarketDataService.mjs.map +0 -1
  572. package/dist/services/RewardsIntegrationService.cjs +0 -391
  573. package/dist/services/RewardsIntegrationService.cjs.map +0 -1
  574. package/dist/services/RewardsIntegrationService.d.cts +0 -84
  575. package/dist/services/RewardsIntegrationService.d.cts.map +0 -1
  576. package/dist/services/RewardsIntegrationService.d.mts +0 -84
  577. package/dist/services/RewardsIntegrationService.d.mts.map +0 -1
  578. package/dist/services/RewardsIntegrationService.mjs +0 -387
  579. package/dist/services/RewardsIntegrationService.mjs.map +0 -1
  580. package/dist/services/ServiceContext.cjs +0 -3
  581. package/dist/services/ServiceContext.cjs.map +0 -1
  582. package/dist/services/ServiceContext.d.cts +0 -102
  583. package/dist/services/ServiceContext.d.cts.map +0 -1
  584. package/dist/services/ServiceContext.d.mts +0 -102
  585. package/dist/services/ServiceContext.d.mts.map +0 -1
  586. package/dist/services/ServiceContext.mjs +0 -2
  587. package/dist/services/ServiceContext.mjs.map +0 -1
  588. package/dist/services/TerminalMarketService.cjs +0 -623
  589. package/dist/services/TerminalMarketService.cjs.map +0 -1
  590. package/dist/services/TerminalMarketService.d.cts +0 -45
  591. package/dist/services/TerminalMarketService.d.cts.map +0 -1
  592. package/dist/services/TerminalMarketService.d.mts +0 -45
  593. package/dist/services/TerminalMarketService.d.mts.map +0 -1
  594. package/dist/services/TerminalMarketService.mjs +0 -619
  595. package/dist/services/TerminalMarketService.mjs.map +0 -1
  596. package/dist/services/TradingReadinessCache.cjs +0 -329
  597. package/dist/services/TradingReadinessCache.cjs.map +0 -1
  598. package/dist/services/TradingReadinessCache.d.cts +0 -204
  599. package/dist/services/TradingReadinessCache.d.cts.map +0 -1
  600. package/dist/services/TradingReadinessCache.d.mts +0 -204
  601. package/dist/services/TradingReadinessCache.d.mts.map +0 -1
  602. package/dist/services/TradingReadinessCache.mjs +0 -326
  603. package/dist/services/TradingReadinessCache.mjs.map +0 -1
  604. package/dist/services/TradingService.cjs +0 -1895
  605. package/dist/services/TradingService.cjs.map +0 -1
  606. package/dist/services/TradingService.d.cts +0 -201
  607. package/dist/services/TradingService.d.cts.map +0 -1
  608. package/dist/services/TradingService.d.mts +0 -201
  609. package/dist/services/TradingService.d.mts.map +0 -1
  610. package/dist/services/TradingService.mjs +0 -1891
  611. package/dist/services/TradingService.mjs.map +0 -1
  612. package/dist/types/config.cjs +0 -3
  613. package/dist/types/config.cjs.map +0 -1
  614. package/dist/types/config.d.cts +0 -49
  615. package/dist/types/config.d.cts.map +0 -1
  616. package/dist/types/config.d.mts +0 -49
  617. package/dist/types/config.d.mts.map +0 -1
  618. package/dist/types/config.mjs +0 -2
  619. package/dist/types/config.mjs.map +0 -1
  620. package/dist/types/hyperliquid-types.cjs +0 -45
  621. package/dist/types/hyperliquid-types.cjs.map +0 -1
  622. package/dist/types/hyperliquid-types.d.cts +0 -67
  623. package/dist/types/hyperliquid-types.d.cts.map +0 -1
  624. package/dist/types/hyperliquid-types.d.mts +0 -67
  625. package/dist/types/hyperliquid-types.d.mts.map +0 -1
  626. package/dist/types/hyperliquid-types.mjs +0 -41
  627. package/dist/types/hyperliquid-types.mjs.map +0 -1
  628. package/dist/types/index.cjs +0 -151
  629. package/dist/types/index.cjs.map +0 -1
  630. package/dist/types/index.d.cts +0 -2183
  631. package/dist/types/index.d.cts.map +0 -1
  632. package/dist/types/index.d.mts +0 -2183
  633. package/dist/types/index.d.mts.map +0 -1
  634. package/dist/types/index.mjs +0 -133
  635. package/dist/types/index.mjs.map +0 -1
  636. package/dist/types/lighter-types.cjs +0 -11
  637. package/dist/types/lighter-types.cjs.map +0 -1
  638. package/dist/types/lighter-types.d.cts +0 -763
  639. package/dist/types/lighter-types.d.cts.map +0 -1
  640. package/dist/types/lighter-types.d.mts +0 -763
  641. package/dist/types/lighter-types.d.mts.map +0 -1
  642. package/dist/types/lighter-types.mjs +0 -10
  643. package/dist/types/lighter-types.mjs.map +0 -1
  644. package/dist/types/messenger.cjs +0 -3
  645. package/dist/types/messenger.cjs.map +0 -1
  646. package/dist/types/messenger.d.cts +0 -30
  647. package/dist/types/messenger.d.cts.map +0 -1
  648. package/dist/types/messenger.d.mts +0 -30
  649. package/dist/types/messenger.d.mts.map +0 -1
  650. package/dist/types/messenger.mjs +0 -2
  651. package/dist/types/messenger.mjs.map +0 -1
  652. package/dist/types/perps-types.cjs +0 -7
  653. package/dist/types/perps-types.cjs.map +0 -1
  654. package/dist/types/perps-types.d.cts +0 -184
  655. package/dist/types/perps-types.d.cts.map +0 -1
  656. package/dist/types/perps-types.d.mts +0 -184
  657. package/dist/types/perps-types.d.mts.map +0 -1
  658. package/dist/types/perps-types.mjs +0 -5
  659. package/dist/types/perps-types.mjs.map +0 -1
  660. package/dist/types/token.cjs +0 -3
  661. package/dist/types/token.cjs.map +0 -1
  662. package/dist/types/token.d.cts +0 -25
  663. package/dist/types/token.d.cts.map +0 -1
  664. package/dist/types/token.d.mts +0 -25
  665. package/dist/types/token.d.mts.map +0 -1
  666. package/dist/types/token.mjs +0 -2
  667. package/dist/types/token.mjs.map +0 -1
  668. package/dist/types/transactionTypes.cjs +0 -29
  669. package/dist/types/transactionTypes.cjs.map +0 -1
  670. package/dist/types/transactionTypes.d.cts +0 -60
  671. package/dist/types/transactionTypes.d.cts.map +0 -1
  672. package/dist/types/transactionTypes.d.mts +0 -60
  673. package/dist/types/transactionTypes.d.mts.map +0 -1
  674. package/dist/types/transactionTypes.mjs +0 -24
  675. package/dist/types/transactionTypes.mjs.map +0 -1
  676. package/dist/utils/accountUtils.cjs +0 -236
  677. package/dist/utils/accountUtils.cjs.map +0 -1
  678. package/dist/utils/accountUtils.d.cts +0 -72
  679. package/dist/utils/accountUtils.d.cts.map +0 -1
  680. package/dist/utils/accountUtils.d.mts +0 -72
  681. package/dist/utils/accountUtils.d.mts.map +0 -1
  682. package/dist/utils/accountUtils.mjs +0 -223
  683. package/dist/utils/accountUtils.mjs.map +0 -1
  684. package/dist/utils/capabilitySymbols.cjs +0 -25
  685. package/dist/utils/capabilitySymbols.cjs.map +0 -1
  686. package/dist/utils/capabilitySymbols.d.cts +0 -15
  687. package/dist/utils/capabilitySymbols.d.cts.map +0 -1
  688. package/dist/utils/capabilitySymbols.d.mts +0 -15
  689. package/dist/utils/capabilitySymbols.d.mts.map +0 -1
  690. package/dist/utils/capabilitySymbols.mjs +0 -21
  691. package/dist/utils/capabilitySymbols.mjs.map +0 -1
  692. package/dist/utils/coalescePerpsRestRequest.cjs +0 -71
  693. package/dist/utils/coalescePerpsRestRequest.cjs.map +0 -1
  694. package/dist/utils/coalescePerpsRestRequest.d.cts +0 -32
  695. package/dist/utils/coalescePerpsRestRequest.d.cts.map +0 -1
  696. package/dist/utils/coalescePerpsRestRequest.d.mts +0 -32
  697. package/dist/utils/coalescePerpsRestRequest.d.mts.map +0 -1
  698. package/dist/utils/coalescePerpsRestRequest.mjs +0 -66
  699. package/dist/utils/coalescePerpsRestRequest.mjs.map +0 -1
  700. package/dist/utils/errorUtils.cjs +0 -104
  701. package/dist/utils/errorUtils.cjs.map +0 -1
  702. package/dist/utils/errorUtils.d.cts +0 -50
  703. package/dist/utils/errorUtils.d.cts.map +0 -1
  704. package/dist/utils/errorUtils.d.mts +0 -50
  705. package/dist/utils/errorUtils.d.mts.map +0 -1
  706. package/dist/utils/errorUtils.mjs +0 -96
  707. package/dist/utils/errorUtils.mjs.map +0 -1
  708. package/dist/utils/hyperLiquidAbstraction.cjs +0 -23
  709. package/dist/utils/hyperLiquidAbstraction.cjs.map +0 -1
  710. package/dist/utils/hyperLiquidAbstraction.d.cts +0 -11
  711. package/dist/utils/hyperLiquidAbstraction.d.cts.map +0 -1
  712. package/dist/utils/hyperLiquidAbstraction.d.mts +0 -11
  713. package/dist/utils/hyperLiquidAbstraction.d.mts.map +0 -1
  714. package/dist/utils/hyperLiquidAbstraction.mjs +0 -19
  715. package/dist/utils/hyperLiquidAbstraction.mjs.map +0 -1
  716. package/dist/utils/hyperLiquidAdapter.cjs +0 -512
  717. package/dist/utils/hyperLiquidAdapter.cjs.map +0 -1
  718. package/dist/utils/hyperLiquidAdapter.d.cts +0 -77
  719. package/dist/utils/hyperLiquidAdapter.d.cts.map +0 -1
  720. package/dist/utils/hyperLiquidAdapter.d.mts +0 -77
  721. package/dist/utils/hyperLiquidAdapter.d.mts.map +0 -1
  722. package/dist/utils/hyperLiquidAdapter.mjs +0 -494
  723. package/dist/utils/hyperLiquidAdapter.mjs.map +0 -1
  724. package/dist/utils/hyperLiquidOrderBookProcessor.cjs +0 -83
  725. package/dist/utils/hyperLiquidOrderBookProcessor.cjs.map +0 -1
  726. package/dist/utils/hyperLiquidOrderBookProcessor.d.cts +0 -55
  727. package/dist/utils/hyperLiquidOrderBookProcessor.d.cts.map +0 -1
  728. package/dist/utils/hyperLiquidOrderBookProcessor.d.mts +0 -55
  729. package/dist/utils/hyperLiquidOrderBookProcessor.d.mts.map +0 -1
  730. package/dist/utils/hyperLiquidOrderBookProcessor.mjs +0 -78
  731. package/dist/utils/hyperLiquidOrderBookProcessor.mjs.map +0 -1
  732. package/dist/utils/hyperLiquidPositionPreview.cjs +0 -355
  733. package/dist/utils/hyperLiquidPositionPreview.cjs.map +0 -1
  734. package/dist/utils/hyperLiquidPositionPreview.d.cts +0 -124
  735. package/dist/utils/hyperLiquidPositionPreview.d.cts.map +0 -1
  736. package/dist/utils/hyperLiquidPositionPreview.d.mts +0 -124
  737. package/dist/utils/hyperLiquidPositionPreview.d.mts.map +0 -1
  738. package/dist/utils/hyperLiquidPositionPreview.mjs +0 -347
  739. package/dist/utils/hyperLiquidPositionPreview.mjs.map +0 -1
  740. package/dist/utils/hyperLiquidValidation.cjs +0 -799
  741. package/dist/utils/hyperLiquidValidation.cjs.map +0 -1
  742. package/dist/utils/hyperLiquidValidation.d.cts +0 -192
  743. package/dist/utils/hyperLiquidValidation.d.cts.map +0 -1
  744. package/dist/utils/hyperLiquidValidation.d.mts +0 -192
  745. package/dist/utils/hyperLiquidValidation.d.mts.map +0 -1
  746. package/dist/utils/hyperLiquidValidation.mjs +0 -786
  747. package/dist/utils/hyperLiquidValidation.mjs.map +0 -1
  748. package/dist/utils/idUtils.cjs +0 -18
  749. package/dist/utils/idUtils.cjs.map +0 -1
  750. package/dist/utils/idUtils.d.cts +0 -6
  751. package/dist/utils/idUtils.d.cts.map +0 -1
  752. package/dist/utils/idUtils.d.mts +0 -6
  753. package/dist/utils/idUtils.d.mts.map +0 -1
  754. package/dist/utils/idUtils.mjs +0 -10
  755. package/dist/utils/idUtils.mjs.map +0 -1
  756. package/dist/utils/index.cjs +0 -66
  757. package/dist/utils/index.cjs.map +0 -1
  758. package/dist/utils/index.d.cts +0 -29
  759. package/dist/utils/index.d.cts.map +0 -1
  760. package/dist/utils/index.d.mts +0 -29
  761. package/dist/utils/index.d.mts.map +0 -1
  762. package/dist/utils/index.mjs +0 -34
  763. package/dist/utils/index.mjs.map +0 -1
  764. package/dist/utils/lighterAdapter.cjs +0 -575
  765. package/dist/utils/lighterAdapter.cjs.map +0 -1
  766. package/dist/utils/lighterAdapter.d.cts +0 -117
  767. package/dist/utils/lighterAdapter.d.cts.map +0 -1
  768. package/dist/utils/lighterAdapter.d.mts +0 -117
  769. package/dist/utils/lighterAdapter.d.mts.map +0 -1
  770. package/dist/utils/lighterAdapter.mjs +0 -562
  771. package/dist/utils/lighterAdapter.mjs.map +0 -1
  772. package/dist/utils/marketDataTransform.cjs +0 -250
  773. package/dist/utils/marketDataTransform.cjs.map +0 -1
  774. package/dist/utils/marketDataTransform.d.cts +0 -71
  775. package/dist/utils/marketDataTransform.d.cts.map +0 -1
  776. package/dist/utils/marketDataTransform.d.mts +0 -71
  777. package/dist/utils/marketDataTransform.d.mts.map +0 -1
  778. package/dist/utils/marketDataTransform.mjs +0 -243
  779. package/dist/utils/marketDataTransform.mjs.map +0 -1
  780. package/dist/utils/marketSearch.cjs +0 -111
  781. package/dist/utils/marketSearch.cjs.map +0 -1
  782. package/dist/utils/marketSearch.d.cts +0 -48
  783. package/dist/utils/marketSearch.d.cts.map +0 -1
  784. package/dist/utils/marketSearch.d.mts +0 -48
  785. package/dist/utils/marketSearch.d.mts.map +0 -1
  786. package/dist/utils/marketSearch.mjs +0 -106
  787. package/dist/utils/marketSearch.mjs.map +0 -1
  788. package/dist/utils/marketUtils.cjs +0 -266
  789. package/dist/utils/marketUtils.cjs.map +0 -1
  790. package/dist/utils/marketUtils.d.cts +0 -73
  791. package/dist/utils/marketUtils.d.cts.map +0 -1
  792. package/dist/utils/marketUtils.d.mts +0 -73
  793. package/dist/utils/marketUtils.d.mts.map +0 -1
  794. package/dist/utils/marketUtils.mjs +0 -248
  795. package/dist/utils/marketUtils.mjs.map +0 -1
  796. package/dist/utils/orderCalculations.cjs +0 -849
  797. package/dist/utils/orderCalculations.cjs.map +0 -1
  798. package/dist/utils/orderCalculations.d.cts +0 -306
  799. package/dist/utils/orderCalculations.d.cts.map +0 -1
  800. package/dist/utils/orderCalculations.d.mts +0 -306
  801. package/dist/utils/orderCalculations.d.mts.map +0 -1
  802. package/dist/utils/orderCalculations.mjs +0 -833
  803. package/dist/utils/orderCalculations.mjs.map +0 -1
  804. package/dist/utils/orderTypes.cjs +0 -301
  805. package/dist/utils/orderTypes.cjs.map +0 -1
  806. package/dist/utils/orderTypes.d.cts +0 -166
  807. package/dist/utils/orderTypes.d.cts.map +0 -1
  808. package/dist/utils/orderTypes.d.mts +0 -166
  809. package/dist/utils/orderTypes.d.mts.map +0 -1
  810. package/dist/utils/orderTypes.mjs +0 -287
  811. package/dist/utils/orderTypes.mjs.map +0 -1
  812. package/dist/utils/perpsConnectionAttemptContext.cjs +0 -20
  813. package/dist/utils/perpsConnectionAttemptContext.cjs.map +0 -1
  814. package/dist/utils/perpsConnectionAttemptContext.d.cts +0 -7
  815. package/dist/utils/perpsConnectionAttemptContext.d.cts.map +0 -1
  816. package/dist/utils/perpsConnectionAttemptContext.d.mts +0 -7
  817. package/dist/utils/perpsConnectionAttemptContext.d.mts.map +0 -1
  818. package/dist/utils/perpsConnectionAttemptContext.mjs +0 -15
  819. package/dist/utils/perpsConnectionAttemptContext.mjs.map +0 -1
  820. package/dist/utils/perpsDiskPersistence.cjs +0 -259
  821. package/dist/utils/perpsDiskPersistence.cjs.map +0 -1
  822. package/dist/utils/perpsDiskPersistence.d.cts +0 -112
  823. package/dist/utils/perpsDiskPersistence.d.cts.map +0 -1
  824. package/dist/utils/perpsDiskPersistence.d.mts +0 -112
  825. package/dist/utils/perpsDiskPersistence.d.mts.map +0 -1
  826. package/dist/utils/perpsDiskPersistence.mjs +0 -251
  827. package/dist/utils/perpsDiskPersistence.mjs.map +0 -1
  828. package/dist/utils/perpsFormatters.cjs +0 -509
  829. package/dist/utils/perpsFormatters.cjs.map +0 -1
  830. package/dist/utils/perpsFormatters.d.cts +0 -204
  831. package/dist/utils/perpsFormatters.d.cts.map +0 -1
  832. package/dist/utils/perpsFormatters.d.mts +0 -204
  833. package/dist/utils/perpsFormatters.d.mts.map +0 -1
  834. package/dist/utils/perpsFormatters.mjs +0 -500
  835. package/dist/utils/perpsFormatters.mjs.map +0 -1
  836. package/dist/utils/rewardsUtils.cjs +0 -98
  837. package/dist/utils/rewardsUtils.cjs.map +0 -1
  838. package/dist/utils/rewardsUtils.d.cts +0 -33
  839. package/dist/utils/rewardsUtils.d.cts.map +0 -1
  840. package/dist/utils/rewardsUtils.d.mts +0 -33
  841. package/dist/utils/rewardsUtils.d.mts.map +0 -1
  842. package/dist/utils/rewardsUtils.mjs +0 -92
  843. package/dist/utils/rewardsUtils.mjs.map +0 -1
  844. package/dist/utils/significantFigures.cjs +0 -88
  845. package/dist/utils/significantFigures.cjs.map +0 -1
  846. package/dist/utils/significantFigures.d.cts +0 -25
  847. package/dist/utils/significantFigures.d.cts.map +0 -1
  848. package/dist/utils/significantFigures.d.mts +0 -25
  849. package/dist/utils/significantFigures.d.mts.map +0 -1
  850. package/dist/utils/significantFigures.mjs +0 -82
  851. package/dist/utils/significantFigures.mjs.map +0 -1
  852. package/dist/utils/sortMarkets.cjs +0 -93
  853. package/dist/utils/sortMarkets.cjs.map +0 -1
  854. package/dist/utils/sortMarkets.d.cts +0 -25
  855. package/dist/utils/sortMarkets.d.cts.map +0 -1
  856. package/dist/utils/sortMarkets.d.mts +0 -25
  857. package/dist/utils/sortMarkets.d.mts.map +0 -1
  858. package/dist/utils/sortMarkets.mjs +0 -88
  859. package/dist/utils/sortMarkets.mjs.map +0 -1
  860. package/dist/utils/standaloneInfoClient.cjs +0 -70
  861. package/dist/utils/standaloneInfoClient.cjs.map +0 -1
  862. package/dist/utils/standaloneInfoClient.d.cts +0 -37
  863. package/dist/utils/standaloneInfoClient.d.cts.map +0 -1
  864. package/dist/utils/standaloneInfoClient.d.mts +0 -37
  865. package/dist/utils/standaloneInfoClient.d.mts.map +0 -1
  866. package/dist/utils/standaloneInfoClient.mjs +0 -64
  867. package/dist/utils/standaloneInfoClient.mjs.map +0 -1
  868. package/dist/utils/stringParseUtils.cjs +0 -34
  869. package/dist/utils/stringParseUtils.cjs.map +0 -1
  870. package/dist/utils/stringParseUtils.d.cts +0 -11
  871. package/dist/utils/stringParseUtils.d.cts.map +0 -1
  872. package/dist/utils/stringParseUtils.d.mts +0 -11
  873. package/dist/utils/stringParseUtils.d.mts.map +0 -1
  874. package/dist/utils/stringParseUtils.mjs +0 -28
  875. package/dist/utils/stringParseUtils.mjs.map +0 -1
  876. package/dist/utils/transferData.cjs +0 -33
  877. package/dist/utils/transferData.cjs.map +0 -1
  878. package/dist/utils/transferData.d.cts +0 -9
  879. package/dist/utils/transferData.d.cts.map +0 -1
  880. package/dist/utils/transferData.d.mts +0 -9
  881. package/dist/utils/transferData.d.mts.map +0 -1
  882. package/dist/utils/transferData.mjs +0 -29
  883. package/dist/utils/transferData.mjs.map +0 -1
  884. package/dist/utils/wait.cjs +0 -6
  885. package/dist/utils/wait.cjs.map +0 -1
  886. package/dist/utils/wait.d.cts +0 -2
  887. package/dist/utils/wait.d.cts.map +0 -1
  888. package/dist/utils/wait.d.mts +0 -2
  889. package/dist/utils/wait.d.mts.map +0 -1
  890. package/dist/utils/wait.mjs +0 -2
  891. package/dist/utils/wait.mjs.map +0 -1
@@ -0,0 +1,833 @@
1
+ import { BASIS_POINTS_DIVISOR } from '../constants/hyperLiquidConfig.js';
2
+ import { DECIMAL_PRECISION_CONFIG, MAX_ORDER_MARGIN_BUFFER, ORDER_SLIPPAGE_CONFIG, } from '../constants/perpsConfig.js';
3
+ import { PERPS_ERROR_CODES } from '../perpsErrorCodes.js';
4
+ import { formatHyperLiquidPrice, formatHyperLiquidSize, } from './hyperLiquidAdapter.js';
5
+ import { getTriggerDirection, isLimitExecutionOrderType, isTriggerOrderType, SCALE_ORDER_COUNT, toSDKTimeInForce, } from './orderTypes.js';
6
+ /**
7
+ * Tolerance used when deciding whether a scaled size is already on the size
8
+ * grid, guarding against floating-point representation error.
9
+ */
10
+ const FLOAT_TOLERANCE = 1e-6;
11
+ /**
12
+ * Calculate position size based on USD amount and asset price
13
+ *
14
+ * @param params - Amount in USD, current asset price, and required decimal precision
15
+ * @returns Position size formatted to the asset's decimal precision
16
+ */
17
+ export function calculatePositionSize(params) {
18
+ const { amount, price, szDecimals } = params;
19
+ // Validate required parameters
20
+ if (szDecimals === undefined || szDecimals === null) {
21
+ throw new Error('szDecimals is required for position size calculation');
22
+ }
23
+ if (szDecimals < 0) {
24
+ throw new Error(`szDecimals must be >= 0, got: ${szDecimals}`);
25
+ }
26
+ const amountNum = parseFloat(amount || '0');
27
+ if (isNaN(amountNum) || isNaN(price) || amountNum === 0 || price === 0) {
28
+ return (0).toFixed(szDecimals);
29
+ }
30
+ const positionSize = amountNum / price;
31
+ const multiplier = Math.pow(10, szDecimals);
32
+ let rounded = Math.round(positionSize * multiplier) / multiplier;
33
+ // Ensure rounded size meets requested USD (fix validation gap)
34
+ const actualUsd = rounded * price;
35
+ if (actualUsd < amountNum) {
36
+ rounded += 1 / multiplier;
37
+ }
38
+ return rounded.toFixed(szDecimals);
39
+ }
40
+ /**
41
+ * Calculate margin required for a position
42
+ *
43
+ * @param params - Position amount and leverage
44
+ * @returns Margin required formatted to 2 decimal places
45
+ */
46
+ export function calculateMarginRequired(params) {
47
+ const { amount, leverage } = params;
48
+ const amountNum = parseFloat(amount || '0');
49
+ if (isNaN(amountNum) ||
50
+ isNaN(leverage) ||
51
+ amountNum === 0 ||
52
+ leverage === 0) {
53
+ return '0.00';
54
+ }
55
+ return (amountNum / leverage).toFixed(2);
56
+ }
57
+ export function getMaxAllowedAmount(params) {
58
+ const { spendableBalance, assetPrice, assetSzDecimals, leverage, orderType = 'market', limitPrice, } = params;
59
+ if (spendableBalance === 0 || !assetPrice || assetSzDecimals === undefined) {
60
+ return 0;
61
+ }
62
+ // HyperLiquid reserves initial margin for a RESTING order against the price
63
+ // the order is submitted at, not the market price its size was derived from.
64
+ // A limit order resting above the market price - typically a sell - therefore
65
+ // needs more margin than a market-priced notional budgets for, and the
66
+ // exchange refuses it with "insufficient margin to place order". Price the max
67
+ // off that submitted price instead. A marketable order is charged at the fill
68
+ // price, so it needs no adjustment.
69
+ const executionPriceRatio = orderType === 'limit' && limitPrice && limitPrice > assetPrice
70
+ ? limitPrice / assetPrice
71
+ : 1;
72
+ // The theoretical maximum is spendableBalance * leverage, expressed in the
73
+ // market-price notional the caller works with.
74
+ const theoreticalMax = (spendableBalance * leverage) / executionPriceRatio;
75
+ // But we need to account for position size rounding
76
+ // Find the largest whole dollar amount that fits within this limit
77
+ let maxAmount = Math.floor(theoreticalMax);
78
+ // Verify this amount doesn't exceed available balance after rounding
79
+ const testPositionSize = calculatePositionSize({
80
+ amount: maxAmount.toString(),
81
+ price: assetPrice,
82
+ szDecimals: assetSzDecimals,
83
+ });
84
+ const actualNotionalValue = parseFloat(testPositionSize) * assetPrice * executionPriceRatio;
85
+ const requiredMargin = actualNotionalValue / leverage;
86
+ // If rounding caused us to exceed available balance, step down by one position increment
87
+ if (requiredMargin > spendableBalance) {
88
+ const minPositionSizeIncrement = 1 / Math.pow(10, assetSzDecimals);
89
+ const positionSizeIncrementUsd = Math.ceil(minPositionSizeIncrement * assetPrice);
90
+ maxAmount -= positionSizeIncrementUsd;
91
+ }
92
+ // Apply margin buffer to reduce "Insufficient margin" rejections from the exchange
93
+ // (fees, rounding, and exchange-side checks can make 100% theoretical max fail)
94
+ const bufferedMax = maxAmount * (1 - MAX_ORDER_MARGIN_BUFFER);
95
+ return Math.max(0, Math.floor(bufferedMax));
96
+ }
97
+ /**
98
+ * Round a size down onto the asset's size grid.
99
+ *
100
+ * Used for reduce-only orders, where rounding up would push the size past the
101
+ * live position size. Values already on the grid are snapped rather than
102
+ * truncated, because floating-point math can leave them just below a grid
103
+ * point (0.0123 * 10000 === 122.99999999999999) and truncating would drop a
104
+ * whole increment.
105
+ *
106
+ * The result is never greater than `size`, for negative sizes as well as
107
+ * positive: the snap only ever recovers a grid point the input already
108
+ * represents, so a value genuinely below a grid point is stepped down even when
109
+ * the tolerance would have reached the point above it.
110
+ *
111
+ * A size whose scaled form reaches `2^53` is returned unchanged: doubles cannot
112
+ * represent consecutive integers there, so the grid is finer than the spacing
113
+ * between representable values and there is nothing to round down to.
114
+ *
115
+ * @param size - Size to round down.
116
+ * @param szDecimals - The asset's size decimal precision.
117
+ * @returns The size rounded down onto the size grid, never exceeding `size`.
118
+ */
119
+ export function floorToSizeDecimals(size, szDecimals) {
120
+ const multiplier = Math.pow(10, szDecimals);
121
+ const scaled = size * multiplier;
122
+ // Past 2^53 a double cannot represent consecutive integers, so `units -= 1`
123
+ // below would be a no-op and the step-down loop would never terminate. The
124
+ // size grid is finer than the spacing between representable values at that
125
+ // magnitude, so there is no increment to shave: return the input unchanged.
126
+ if (!Number.isFinite(scaled) || Math.abs(scaled) >= Number.MAX_SAFE_INTEGER) {
127
+ return size;
128
+ }
129
+ const nearest = Math.round(scaled);
130
+ // The tolerance scales with the magnitude, because double-precision error
131
+ // does too: a fixed epsilon would stop absorbing representation error for
132
+ // sizes that scale past ~1e10 and would then shave off a whole increment.
133
+ const tolerance = Math.max(FLOAT_TOLERANCE, Math.abs(scaled) * Number.EPSILON * 8);
134
+ let units = Math.abs(scaled - nearest) < tolerance ? nearest : Math.floor(scaled);
135
+ // Step down until the result no longer exceeds the input. One pass is not
136
+ // enough: a tolerance wide enough to absorb representation error at large
137
+ // magnitudes also reaches the next grid point, and for an input less than half
138
+ // an ulp below a grid point `size * multiplier` evaluates to exactly that grid
139
+ // integer, so flooring the scaled value returns the same too-large result.
140
+ // The comparison alone is the whole termination condition: for a non-negative
141
+ // size the loop stops at or before zero, and for a negative size it stops once
142
+ // the value is no longer above the input. Guarding on `units` instead would
143
+ // skip a negative size below the tolerance, which snaps to `-0` — and
144
+ // `-0 !== 0` is false. The 2^53 bail-out above keeps this bounded.
145
+ while (units / multiplier > size) {
146
+ units -= 1;
147
+ }
148
+ return units / multiplier;
149
+ }
150
+ /**
151
+ * The smallest price increment the venue will represent at a given price.
152
+ *
153
+ * HyperLiquid bounds a perp price two ways at once — a decimal-place cap that
154
+ * depends on the asset's size precision, and a significant-figure cap — so the
155
+ * tick widens as the price grows. Whichever bound is coarser at this price is
156
+ * the tick.
157
+ *
158
+ * @param params - Tick parameters.
159
+ * @param params.price - Price to measure the increment at.
160
+ * @param params.szDecimals - The asset's size decimal precision.
161
+ * @returns The tick size at that price.
162
+ */
163
+ export function getPriceTick(params) {
164
+ const { price, szDecimals } = params;
165
+ const byDecimals = Math.pow(10, -(DECIMAL_PRECISION_CONFIG.MaxPriceDecimals - szDecimals));
166
+ const bySignificantFigures = Math.pow(10, Math.floor(Math.log10(Math.abs(price))) -
167
+ (DECIMAL_PRECISION_CONFIG.MaxSignificantFigures - 1));
168
+ return Math.max(byDecimals, bySignificantFigures);
169
+ }
170
+ /**
171
+ * Price a chase order against the book it is chasing.
172
+ *
173
+ * The venue's own definition: a chase rests one tick *inside* the spread —
174
+ * above the best bid for a buy, below the best ask for a sell — except when the
175
+ * spread is already a single tick, where there is no room to improve and the
176
+ * order joins the touch instead.
177
+ *
178
+ * Rests inside rather than at the touch because a chase is post-only: sitting
179
+ * one tick ahead of the rest of the queue is the whole point, and joining the
180
+ * touch would leave it behind every order already resting there.
181
+ *
182
+ * @param params - Quote parameters.
183
+ * @param params.bestBid - Best bid, excluding the chase's own resting order.
184
+ * @param params.bestAsk - Best ask, excluding the chase's own resting order.
185
+ * @param params.isBuy - Which side the chase rests on.
186
+ * @param params.szDecimals - The asset's size decimal precision.
187
+ * @returns The formatted price the chase should rest at.
188
+ */
189
+ export function computeChaseQuotePrice(params) {
190
+ const { bestBid, bestAsk, isBuy, szDecimals } = params;
191
+ const reference = isBuy ? bestBid : bestAsk;
192
+ const tick = getPriceTick({ price: reference, szDecimals });
193
+ const improved = isBuy ? bestBid + tick : bestAsk - tick;
194
+ // A single-tick spread leaves nowhere to improve to: the improved price would
195
+ // cross, which a post-only order cannot do. Join the touch instead.
196
+ const crosses = isBuy ? improved >= bestAsk : improved <= bestBid;
197
+ return formatHyperLiquidPrice({
198
+ price: crosses ? reference : improved,
199
+ szDecimals,
200
+ });
201
+ }
202
+ /**
203
+ * Compute the price ladder a scale placement fans out over.
204
+ *
205
+ * The ladder is inclusive of both ends — the first rung sits exactly on
206
+ * `minPrice`, the last exactly on `maxPrice` — so the range the caller asked
207
+ * for is the range that actually reaches the exchange.
208
+ *
209
+ * @param params - Ladder parameters.
210
+ * @param params.minPrice - Lowest price in the ladder.
211
+ * @param params.maxPrice - Highest price in the ladder; must exceed `minPrice`.
212
+ * @param params.count - Number of rungs.
213
+ * @returns The rung prices, ascending.
214
+ */
215
+ export function computeScalePriceLadder(params) {
216
+ const { minPrice, maxPrice, count } = params;
217
+ if (!Number.isInteger(count) ||
218
+ count < SCALE_ORDER_COUNT.min ||
219
+ count > SCALE_ORDER_COUNT.max) {
220
+ throw new Error(PERPS_ERROR_CODES.ORDER_SCALE_COUNT_INVALID);
221
+ }
222
+ if (!Number.isFinite(minPrice) ||
223
+ !Number.isFinite(maxPrice) ||
224
+ minPrice <= 0 ||
225
+ maxPrice <= minPrice) {
226
+ throw new Error(PERPS_ERROR_CODES.ORDER_SCALE_RANGE_INVALID);
227
+ }
228
+ const step = (maxPrice - minPrice) / (count - 1);
229
+ // The top rung is assigned rather than accumulated: `minPrice + step * n`
230
+ // drifts, and a ladder that stops short of the caller's maxPrice would quietly
231
+ // narrow the range they asked for.
232
+ return Array.from({ length: count }, (_unused, index) => index === count - 1 ? maxPrice : minPrice + step * index);
233
+ }
234
+ /**
235
+ * Split a scale placement's total size across its ladder rungs.
236
+ *
237
+ * The split is done in whole units of the asset's size grid rather than in
238
+ * decimal sizes: dividing and re-flooring in floating point loses a sub-unit of
239
+ * dust on every rung, and a ladder that submits less than the size that was
240
+ * validated is not the order the caller placed. Either allocation below sums to
241
+ * exactly `totalSize` in grid units.
242
+ *
243
+ * This is the one place the ladder's sizes are decided. Clients previewing a
244
+ * scale placement must call it rather than reproduce the ramp, or the preview
245
+ * and the placement will disagree at the rounding.
246
+ *
247
+ * **Even (no `skew`, or `skew` exactly 1).** Every rung gets `floor(total /
248
+ * count)` units and whatever does not divide evenly goes onto the first rung —
249
+ * 11 units across 3 rungs is `5, 3, 3`, not three equal slices.
250
+ *
251
+ * **Skewed.** Rung weights ramp linearly from 1 at index 0 to `skew` at the last
252
+ * index, in ladder order — which is ascending price, `scaleMinPrice` to
253
+ * `scaleMaxPrice`, for a buy and a sell alike. Each rung takes
254
+ * `floor(weight / sumOfWeights * totalUnits)` units, and the units left over go
255
+ * to the rungs with the largest discarded fraction, ties broken by ascending
256
+ * index. The leftover is deliberately *not* dumped on the first rung the way the
257
+ * even split does it: on a `skew` above 1 that would push size back to the end
258
+ * of the ladder the caller weighted away from.
259
+ *
260
+ * The total is expected to sit on the grid already — `calculateFinalPositionSize`
261
+ * floors it there — so rounding onto the grid here only absorbs representation
262
+ * error. A total too small to give every rung a whole unit is rejected: placing
263
+ * fewer orders than asked for would silently change the strategy. A `skew` far
264
+ * enough from 1 can starve a rung the same way, and is rejected the same way.
265
+ *
266
+ * @param params - Split parameters.
267
+ * @param params.totalSize - Total size to distribute.
268
+ * @param params.count - Number of rungs.
269
+ * @param params.szDecimals - The asset's size decimal precision.
270
+ * @param params.skew - Optional size weighting across the ladder; any finite
271
+ * value above 0, used exactly as given.
272
+ * @returns One size string per rung, in ladder order.
273
+ */
274
+ export function splitScaleSizes(params) {
275
+ const { totalSize, count, szDecimals, skew } = params;
276
+ // Checked here as well as in `computeScalePriceLadder`: this is exported on
277
+ // its own, and a count of zero would otherwise return an empty split while a
278
+ // fractional one would return slices that do not sum to the total.
279
+ if (!Number.isInteger(count) ||
280
+ count < SCALE_ORDER_COUNT.min ||
281
+ count > SCALE_ORDER_COUNT.max) {
282
+ throw new Error(PERPS_ERROR_CODES.ORDER_SCALE_COUNT_INVALID);
283
+ }
284
+ // Checked here rather than left to the arithmetic: a non-finite or
285
+ // non-positive skew produces weights that are NaN or run negative, and either
286
+ // one would come back as a ladder of zero-size rungs instead of a rejection.
287
+ if (skew !== undefined && (!Number.isFinite(skew) || skew <= 0)) {
288
+ throw new Error(PERPS_ERROR_CODES.ORDER_SCALE_RANGE_INVALID);
289
+ }
290
+ const multiplier = Math.pow(10, szDecimals);
291
+ const totalUnits = Math.round(totalSize * multiplier);
292
+ if (!Number.isSafeInteger(totalUnits) || totalUnits < count) {
293
+ throw new Error(PERPS_ERROR_CODES.ORDER_SCALE_SIZE_TOO_SMALL);
294
+ }
295
+ const unitsPerRung = skew === undefined || skew === 1
296
+ ? splitUnitsEvenly({ totalUnits, count })
297
+ : splitUnitsBySkew({ totalUnits, count, skew });
298
+ // A rung the ramp starved of every unit would be submitted as a zero-size
299
+ // order. That is the same failure the total-size check above rejects, and it
300
+ // is reported the same way, so a caller reads one reason for "this ladder
301
+ // cannot be cut this finely" rather than two.
302
+ if (unitsPerRung.some((units) => units === 0)) {
303
+ throw new Error(PERPS_ERROR_CODES.ORDER_SCALE_SIZE_TOO_SMALL);
304
+ }
305
+ return unitsPerRung.map((units) => formatHyperLiquidSize({ size: units / multiplier, szDecimals }));
306
+ }
307
+ /**
308
+ * Spread the ladder's units evenly, leftover on the first rung.
309
+ *
310
+ * @param params - Split parameters.
311
+ * @param params.totalUnits - Total size, in whole size-grid units.
312
+ * @param params.count - Number of rungs.
313
+ * @returns Units per rung, in ladder order.
314
+ */
315
+ function splitUnitsEvenly(params) {
316
+ const { totalUnits, count } = params;
317
+ const sliceUnits = Math.floor(totalUnits / count);
318
+ const remainderUnits = totalUnits - sliceUnits * count;
319
+ return Array.from({ length: count }, (_unused, index) => index === 0 ? sliceUnits + remainderUnits : sliceUnits);
320
+ }
321
+ /**
322
+ * Spread the ladder's units along a linear weight ramp.
323
+ *
324
+ * Flooring every rung leaves up to `count - 1` units unallocated, and they go to
325
+ * the rungs that lost the most to the floor — the standard largest-remainder
326
+ * allocation. Ties go to the lower index, which keeps the result a function of
327
+ * the inputs alone rather than of sort stability.
328
+ *
329
+ * @param params - Split parameters.
330
+ * @param params.totalUnits - Total size, in whole size-grid units.
331
+ * @param params.count - Number of rungs.
332
+ * @param params.skew - Weight of the last rung relative to the first.
333
+ * @returns Units per rung, in ladder order.
334
+ */
335
+ function splitUnitsBySkew(params) {
336
+ const { totalUnits, count, skew } = params;
337
+ const weights = Array.from({ length: count }, (_unused, index) => 1 + ((skew - 1) * index) / (count - 1));
338
+ const weightSum = weights.reduce((sum, weight) => sum + weight, 0);
339
+ const ideal = weights.map((weight) => (weight / weightSum) * totalUnits);
340
+ const unitsPerRung = ideal.map((units) => Math.floor(units));
341
+ const leftoverUnits = totalUnits - unitsPerRung.reduce((sum, units) => sum + units, 0);
342
+ Array.from({ length: count }, (_unused, index) => index)
343
+ .sort((left, right) => {
344
+ const fractionDelta = ideal[right] - unitsPerRung[right] - (ideal[left] - unitsPerRung[left]);
345
+ return fractionDelta === 0 ? left - right : fractionDelta;
346
+ })
347
+ .slice(0, leftoverUnits)
348
+ .forEach((index) => {
349
+ unitsPerRung[index] += 1;
350
+ });
351
+ return unitsPerRung;
352
+ }
353
+ /**
354
+ * Calculates final position size using USD as source of truth with price validation
355
+ *
356
+ * This function implements the hybrid approach where USD is the source of truth,
357
+ * but includes price staleness validation and proper rounding to prevent precision loss.
358
+ *
359
+ * @param params - USD amount, size, prices, and configuration
360
+ * @returns Final position size as a number
361
+ */
362
+ export function calculateFinalPositionSize(params) {
363
+ const { usdAmount, size, currentPrice, priceAtCalculation, maxSlippageBps, szDecimals, leverage, reduceOnly, debugLogger, } = params;
364
+ let finalPositionSize;
365
+ // Validate price staleness whenever the caller supplied a calculation-time
366
+ // price. This runs before the sizing branches on purpose: a full close submits
367
+ // the exact live position size rather than a USD-derived one, and it must still
368
+ // be rejected when the price has moved past the caller's tolerance.
369
+ if (priceAtCalculation) {
370
+ const priceDeltaBps = Math.abs(((currentPrice - priceAtCalculation) / priceAtCalculation) * 10000);
371
+ const maxSlippageBpsValue = maxSlippageBps ?? ORDER_SLIPPAGE_CONFIG.DefaultMarketSlippageBps;
372
+ if (priceDeltaBps > maxSlippageBpsValue) {
373
+ throw new Error(`Price moved too much: ${priceDeltaBps.toFixed(0)} bps (max: ${maxSlippageBpsValue} bps). ` +
374
+ `Expected: ${priceAtCalculation.toFixed(2)}, Current: ${currentPrice.toFixed(2)}`);
375
+ }
376
+ debugLogger?.log('Price validation passed:', {
377
+ priceAtCalculation,
378
+ currentPrice,
379
+ deltaBps: priceDeltaBps.toFixed(2),
380
+ maxSlippageBps: maxSlippageBpsValue,
381
+ });
382
+ }
383
+ if (usdAmount && parseFloat(usdAmount) > 0) {
384
+ // USD amount provided - use it as source of truth
385
+ const usdValue = parseFloat(usdAmount);
386
+ // Recalculate position size with fresh price
387
+ finalPositionSize = usdValue / currentPrice;
388
+ // A reduce-only order may never exceed the size the caller asked to close:
389
+ // that size is already clamped to the live position, while the USD amount was
390
+ // computed against an older price and can imply a larger size after an
391
+ // adverse move. Capping here keeps USD accuracy in the common case and makes
392
+ // the caller's clamp binding.
393
+ if (reduceOnly && size) {
394
+ const requestedSize = parseFloat(size);
395
+ // A supplied size must be positive, or the cap below would submit a
396
+ // zero/negative order. Reject it rather than silently falling back to the
397
+ // USD-derived size, matching how closePosition treats the same input.
398
+ if (!Number.isFinite(requestedSize) || requestedSize <= 0) {
399
+ throw new Error(PERPS_ERROR_CODES.ORDER_SIZE_POSITIVE);
400
+ }
401
+ finalPositionSize = Math.min(finalPositionSize, requestedSize);
402
+ }
403
+ // 3. Apply size decimals rounding (reduce-only never rounds up)
404
+ const multiplier = Math.pow(10, szDecimals);
405
+ const sizeBeforeRounding = finalPositionSize;
406
+ finalPositionSize = reduceOnly
407
+ ? floorToSizeDecimals(finalPositionSize, szDecimals)
408
+ : Math.round(finalPositionSize * multiplier) / multiplier;
409
+ // Rounding down can zero out a reduce-only order whose USD value is worth
410
+ // less than one size increment. Fail with a clear error instead of
411
+ // submitting a size of "0" the exchange will reject.
412
+ if (reduceOnly && finalPositionSize <= 0 && sizeBeforeRounding > 0) {
413
+ throw new Error(PERPS_ERROR_CODES.ORDER_SIZE_POSITIVE);
414
+ }
415
+ // 4. Ensure rounded size meets requested USD (fix validation gap).
416
+ // Skipped for reduce-only orders: adding an increment there would submit
417
+ // more than the position holds and HyperLiquid rejects the order.
418
+ let actualNotionalValue = finalPositionSize * currentPrice;
419
+ if (!reduceOnly && actualNotionalValue < usdValue) {
420
+ // Add 1 minimum increment to meet requested USD
421
+ finalPositionSize += 1 / multiplier;
422
+ actualNotionalValue = finalPositionSize * currentPrice;
423
+ debugLogger?.log('Position size adjusted to meet USD minimum:', {
424
+ requestedUsd: usdValue,
425
+ beforeAdjustment: finalPositionSize - 1 / multiplier,
426
+ afterAdjustment: finalPositionSize,
427
+ actualUsd: actualNotionalValue,
428
+ });
429
+ }
430
+ const requiredMargin = actualNotionalValue / (leverage ?? 1);
431
+ // Log if rounding caused significant difference
432
+ const usdDifference = Math.abs(actualNotionalValue - usdValue);
433
+ if (usdDifference > 0.01) {
434
+ debugLogger?.log('Position size rounding caused USD difference (acceptable):', {
435
+ requestedUsd: usdValue,
436
+ actualUsd: actualNotionalValue,
437
+ difference: usdDifference,
438
+ positionSize: finalPositionSize,
439
+ });
440
+ }
441
+ debugLogger?.log('Recalculated position size with fresh price:', {
442
+ usdAmount: usdValue,
443
+ priceAtCalculation,
444
+ currentPrice,
445
+ originalSize: size,
446
+ recalculatedSize: finalPositionSize,
447
+ requiredMargin,
448
+ minIncrement: 1 / multiplier,
449
+ });
450
+ }
451
+ else {
452
+ // Legacy: Use provided size (backward compatibility)
453
+ finalPositionSize = parseFloat(size ?? '0');
454
+ // Reduce-only sizes are formatted with toFixed() further down, which rounds
455
+ // up; truncate onto the size grid first so a close can never exceed the
456
+ // position it is closing.
457
+ if (reduceOnly) {
458
+ // A supplied size must be positive, or formatHyperLiquidSize would render
459
+ // a zero or negative order size. The USD branch above rejects the same
460
+ // input.
461
+ if (size && !(finalPositionSize > 0)) {
462
+ throw new Error(PERPS_ERROR_CODES.ORDER_SIZE_POSITIVE);
463
+ }
464
+ const sizeBeforeFlooring = finalPositionSize;
465
+ finalPositionSize = floorToSizeDecimals(finalPositionSize, szDecimals);
466
+ // A positive size that floors to zero is worth less than one increment
467
+ if (finalPositionSize <= 0 && sizeBeforeFlooring > 0) {
468
+ throw new Error(PERPS_ERROR_CODES.ORDER_SIZE_POSITIVE);
469
+ }
470
+ }
471
+ debugLogger?.log('Using legacy size calculation (no USD amount provided):', {
472
+ providedSize: size,
473
+ finalSize: finalPositionSize,
474
+ });
475
+ }
476
+ return { finalPositionSize };
477
+ }
478
+ /**
479
+ * Calculates order price and formatted size based on order type
480
+ *
481
+ * @param params - Order parameters including type, direction, size, and prices
482
+ * @returns Formatted order price, size, and price string
483
+ */
484
+ export function calculateOrderPriceAndSize(params) {
485
+ const { orderType, isBuy, finalPositionSize, currentPrice, limitPrice, triggerPrice, maxSlippageBps, szDecimals, } = params;
486
+ let orderPrice;
487
+ let formattedSize;
488
+ if (isTriggerOrderType(orderType)) {
489
+ // Trigger placements price off the trigger, not the live market: the order
490
+ // rests off-book until the trigger fires.
491
+ if (!triggerPrice) {
492
+ throw new Error(PERPS_ERROR_CODES.ORDER_TRIGGER_PRICE_REQUIRED);
493
+ }
494
+ const triggerPriceNum = parseFloat(triggerPrice);
495
+ if (isNaN(triggerPriceNum) || triggerPriceNum <= 0) {
496
+ throw new Error(PERPS_ERROR_CODES.ORDER_TRIGGER_PRICE_POSITIVE);
497
+ }
498
+ if (isLimitExecutionOrderType(orderType)) {
499
+ if (!limitPrice) {
500
+ throw new Error(PERPS_ERROR_CODES.ORDER_LIMIT_PRICE_REQUIRED);
501
+ }
502
+ orderPrice = parseFloat(limitPrice);
503
+ }
504
+ else {
505
+ // Market execution on trigger: HyperLiquid still needs a limit price, used
506
+ // as a slippage cap. The caller's tolerance wins when supplied; otherwise
507
+ // the 10% convention of the existing TP/SL children applies.
508
+ const effectiveBps = maxSlippageBps ?? ORDER_SLIPPAGE_CONFIG.DefaultTpslSlippageBps;
509
+ const slippageValue = effectiveBps / BASIS_POINTS_DIVISOR;
510
+ orderPrice = isBuy
511
+ ? triggerPriceNum * (1 + slippageValue)
512
+ : triggerPriceNum * (1 - slippageValue);
513
+ }
514
+ formattedSize = formatHyperLiquidSize({
515
+ size: finalPositionSize,
516
+ szDecimals,
517
+ });
518
+ }
519
+ else if (orderType === 'market') {
520
+ // Market orders: apply slippage buffer to the live price so HyperLiquid
521
+ // receives a worst-case acceptable limit price. Falls back to the
522
+ // documented default if the caller does not provide one.
523
+ const effectiveBps = maxSlippageBps ?? ORDER_SLIPPAGE_CONFIG.DefaultMarketSlippageBps;
524
+ const slippageValue = effectiveBps / BASIS_POINTS_DIVISOR;
525
+ orderPrice = isBuy
526
+ ? currentPrice * (1 + slippageValue)
527
+ : currentPrice * (1 - slippageValue);
528
+ formattedSize = formatHyperLiquidSize({
529
+ size: finalPositionSize,
530
+ szDecimals,
531
+ });
532
+ }
533
+ else {
534
+ // Limit orders: use provided price (no slippage applied)
535
+ if (!limitPrice) {
536
+ throw new Error(PERPS_ERROR_CODES.ORDER_LIMIT_PRICE_REQUIRED);
537
+ }
538
+ orderPrice = parseFloat(limitPrice);
539
+ formattedSize = formatHyperLiquidSize({
540
+ size: finalPositionSize,
541
+ szDecimals,
542
+ });
543
+ }
544
+ const formattedPrice = formatHyperLiquidPrice({
545
+ price: orderPrice,
546
+ szDecimals,
547
+ });
548
+ return { orderPrice, formattedSize, formattedPrice };
549
+ }
550
+ /**
551
+ * Build the SDK order-type field for the main order.
552
+ *
553
+ * Trigger placements map to the SDK's trigger shape; everything else keeps the
554
+ * existing Gtc/FrontendMarket limit shape.
555
+ *
556
+ * @param params - Order type parameters
557
+ * @param params.orderType - Placement type
558
+ * @param params.timeInForce - Time in force; only limit orders may carry one
559
+ * @param params.triggerPrice - Trigger price (required for trigger placements)
560
+ * @param params.szDecimals - Asset size decimals, for price formatting
561
+ * @returns The SDK `t` field for the main order
562
+ */
563
+ function buildMainOrderTypeField(params) {
564
+ const { orderType, timeInForce, triggerPrice, szDecimals } = params;
565
+ if (!isTriggerOrderType(orderType)) {
566
+ if (orderType === 'limit') {
567
+ return { limit: { tif: toSDKTimeInForce(timeInForce) } };
568
+ }
569
+ if (timeInForce !== undefined) {
570
+ throw new Error(PERPS_ERROR_CODES.ORDER_TIME_IN_FORCE_NOT_SUPPORTED);
571
+ }
572
+ return { limit: { tif: 'FrontendMarket' } };
573
+ }
574
+ if (timeInForce !== undefined) {
575
+ throw new Error(PERPS_ERROR_CODES.ORDER_TIME_IN_FORCE_NOT_SUPPORTED);
576
+ }
577
+ if (!triggerPrice) {
578
+ throw new Error(PERPS_ERROR_CODES.ORDER_TRIGGER_PRICE_REQUIRED);
579
+ }
580
+ return {
581
+ trigger: {
582
+ isMarket: !isLimitExecutionOrderType(orderType),
583
+ triggerPx: formatTriggerPrice({
584
+ price: triggerPrice,
585
+ szDecimals,
586
+ error: PERPS_ERROR_CODES.ORDER_TRIGGER_PRICE_POSITIVE,
587
+ }),
588
+ tpsl: getTriggerDirection(orderType) === 'stop' ? 'sl' : 'tp',
589
+ },
590
+ };
591
+ }
592
+ /**
593
+ * Format a price that becomes a `triggerPx`, rejecting one that disappears at
594
+ * the asset's precision.
595
+ *
596
+ * A positive price below the asset's tick (`0.0004` where the asset quotes to
597
+ * three places) formats to `'0'`, which the exchange rejects. Callers validate
598
+ * this up front via `validateOrderPrecision`; this is the guard on the build
599
+ * path itself, so no caller can assemble an order that cannot be accepted.
600
+ *
601
+ * @param params - Price parameters
602
+ * @param params.price - The requested price
603
+ * @param params.szDecimals - Asset size decimals
604
+ * @param params.error - Typed error to throw when the price rounds away
605
+ * @returns The exchange-formatted price, guaranteed positive.
606
+ */
607
+ function formatTriggerPrice(params) {
608
+ const { price, szDecimals, error } = params;
609
+ const formatted = formatHyperLiquidPrice({ price, szDecimals });
610
+ if (parseFloat(formatted) <= 0) {
611
+ throw new Error(error);
612
+ }
613
+ return formatted;
614
+ }
615
+ /**
616
+ * Resolve the size of an attached TP/SL order.
617
+ *
618
+ * @param params - Size parameters
619
+ * @param params.tpslSize - Requested partial size, if any
620
+ * @param params.formattedSize - Full order size, used when no partial size is given
621
+ * @param params.szDecimals - Asset size decimals
622
+ * @returns The exchange-formatted TP/SL order size
623
+ */
624
+ function formatTpslSize(params) {
625
+ const { tpslSize, formattedSize, szDecimals } = params;
626
+ if (tpslSize === undefined) {
627
+ return formattedSize;
628
+ }
629
+ // Validation compares the requested size against `params.size`, but a
630
+ // usdAmount-based order is finally sized from a fresher price, so the parent
631
+ // can end up smaller than the child that validated cleanly. Clamp so the
632
+ // attached TP/SL never exceeds the order it protects.
633
+ const requested = parseFloat(tpslSize);
634
+ const parentSize = parseFloat(formattedSize);
635
+ const size = Number.isFinite(parentSize) && Number.isFinite(requested)
636
+ ? Math.min(requested, parentSize)
637
+ : requested;
638
+ return formatPartialTpslSize({ size, szDecimals });
639
+ }
640
+ /**
641
+ * Check that an order's prices and partial sizes survive the asset's precision.
642
+ *
643
+ * Validation elsewhere sees the values the caller supplied; this sees what the
644
+ * exchange will actually receive. A positive value below the asset's tick
645
+ * formats to `'0'`, which either changes the order's meaning (a zero-sized
646
+ * trigger covers the whole position) or is rejected outright (a zero
647
+ * `triggerPx`).
648
+ *
649
+ * Callers run this before taking any side effect — cancelling the position's
650
+ * existing triggers, changing leverage, moving HIP-3 margin — so a value that
651
+ * would only fail once the orders are built cannot leave a position stripped of
652
+ * its protection, or an account with leverage moved, for an order that was
653
+ * never going to be accepted.
654
+ *
655
+ * @param params - Price and size parameters
656
+ * @param params.triggerPrice - Trigger price for a trigger placement, if any
657
+ * @param params.takeProfitPrice - Attached take profit price, if any
658
+ * @param params.stopLossPrice - Attached stop loss price, if any
659
+ * @param params.takeProfitSize - Requested partial take profit size, if any
660
+ * @param params.stopLossSize - Requested partial stop loss size, if any
661
+ * @param params.szDecimals - Asset size decimals
662
+ * @returns Validation result with isValid flag and optional error message
663
+ */
664
+ export function validateOrderPrecision(params) {
665
+ const { triggerPrice, takeProfitPrice, stopLossPrice, takeProfitSize, stopLossSize, szDecimals, } = params;
666
+ for (const size of [takeProfitSize, stopLossSize]) {
667
+ if (size === undefined) {
668
+ continue;
669
+ }
670
+ // Mirror how the size is actually submitted. A partial TP/SL size is
671
+ // floored onto the size grid (formatPartialTpslSize) because a reduce-only
672
+ // trigger must not exceed its position, so checking it with the half-up
673
+ // formatter accepted sizes in [0.5, 1) increments here and refused them
674
+ // later — after trading setup had prompted for signatures and written
675
+ // approvals, and after the pre-cancel sweep had cleared the position's
676
+ // existing triggers. Flooring here refuses them before any of that.
677
+ const parsedSize = parseFloat(size);
678
+ const flooredSize = Number.isFinite(parsedSize)
679
+ ? floorToSizeDecimals(parsedSize, szDecimals)
680
+ : parsedSize;
681
+ if (!(flooredSize > 0)) {
682
+ return {
683
+ isValid: false,
684
+ error: PERPS_ERROR_CODES.ORDER_TPSL_SIZE_INVALID,
685
+ };
686
+ }
687
+ }
688
+ // Prices carry their own precision: an asset quotes to
689
+ // `MaxPriceDecimals - szDecimals` places, so a positive price under that tick
690
+ // formats to '0'. Every one of these becomes a `triggerPx` the exchange
691
+ // rejects outright.
692
+ const priceChecks = [
693
+ [triggerPrice, PERPS_ERROR_CODES.ORDER_TRIGGER_PRICE_POSITIVE],
694
+ [takeProfitPrice, PERPS_ERROR_CODES.ORDER_PRICE_POSITIVE],
695
+ [stopLossPrice, PERPS_ERROR_CODES.ORDER_PRICE_POSITIVE],
696
+ ];
697
+ for (const [price, error] of priceChecks) {
698
+ if (price === undefined) {
699
+ continue;
700
+ }
701
+ if (parseFloat(formatHyperLiquidPrice({ price, szDecimals })) <= 0) {
702
+ return { isValid: false, error };
703
+ }
704
+ }
705
+ return { isValid: true };
706
+ }
707
+ /**
708
+ * Format a partial TP/SL size, rejecting one that disappears at the asset
709
+ * precision.
710
+ *
711
+ * Validation only sees the requested size, so a positive value below the
712
+ * asset's precision (0.0004 against `szDecimals: 3`) passes and then formats to
713
+ * `'0'`. HyperLiquid reads a zero-sized trigger as covering the whole position,
714
+ * which would silently turn a partial TP/SL into a full close.
715
+ *
716
+ * The size is floored onto the asset's size grid before formatting. A partial
717
+ * TP/SL is a reduce-only trigger, so it may never exceed the position it
718
+ * protects: `formatHyperLiquidSize` rounds half-up, which turns a size sitting
719
+ * on a half-increment into one the position cannot absorb (0.115 at
720
+ * `szDecimals: 2` becomes '0.12'), and HyperLiquid rejects that with "Reduce
721
+ * only order would increase position". Callers clamp to the position or parent
722
+ * order before calling, so rounding up here would undo their clamp.
723
+ *
724
+ * @param params - Size parameters
725
+ * @param params.size - The requested partial size
726
+ * @param params.szDecimals - Asset size decimals
727
+ * @returns The exchange-formatted size, guaranteed positive.
728
+ */
729
+ export function formatPartialTpslSize(params) {
730
+ const { size, szDecimals } = params;
731
+ const requested = typeof size === 'string' ? parseFloat(size) : size;
732
+ // A non-numeric size cannot be floored; leave it to formatHyperLiquidSize,
733
+ // which renders it as '0' and is rejected just below.
734
+ const flooredSize = Number.isFinite(requested)
735
+ ? floorToSizeDecimals(requested, szDecimals)
736
+ : requested;
737
+ const formatted = formatHyperLiquidSize({ size: flooredSize, szDecimals });
738
+ if (parseFloat(formatted) <= 0) {
739
+ throw new Error(PERPS_ERROR_CODES.ORDER_TPSL_SIZE_INVALID);
740
+ }
741
+ return formatted;
742
+ }
743
+ /**
744
+ * Builds orders array including main order and optional TP/SL orders
745
+ *
746
+ * @param params - Order construction parameters
747
+ * @returns Array of SDK order params and grouping type
748
+ */
749
+ export function buildOrdersArray(params) {
750
+ const { assetId, isBuy, formattedPrice, formattedSize, reduceOnly, orderType, timeInForce, clientOrderId, triggerPrice, takeProfitPrice, stopLossPrice, takeProfitSize, stopLossSize, szDecimals, grouping, } = params;
751
+ const orders = [];
752
+ // 1. Main order
753
+ const mainOrder = {
754
+ a: assetId,
755
+ b: isBuy,
756
+ p: formattedPrice,
757
+ s: formattedSize,
758
+ r: reduceOnly || false,
759
+ t: buildMainOrderTypeField({
760
+ orderType,
761
+ timeInForce,
762
+ triggerPrice,
763
+ szDecimals,
764
+ }),
765
+ c: clientOrderId ? clientOrderId : undefined,
766
+ };
767
+ orders.push(mainOrder);
768
+ // 2. Take Profit order
769
+ if (takeProfitPrice) {
770
+ const tpOrder = {
771
+ a: assetId,
772
+ b: !isBuy,
773
+ p: formatHyperLiquidPrice({
774
+ price: parseFloat(takeProfitPrice),
775
+ szDecimals,
776
+ }),
777
+ s: formatTpslSize({
778
+ tpslSize: takeProfitSize,
779
+ formattedSize,
780
+ szDecimals,
781
+ }),
782
+ r: true,
783
+ t: {
784
+ trigger: {
785
+ isMarket: false,
786
+ triggerPx: formatTriggerPrice({
787
+ price: takeProfitPrice,
788
+ szDecimals,
789
+ error: PERPS_ERROR_CODES.ORDER_PRICE_POSITIVE,
790
+ }),
791
+ tpsl: 'tp',
792
+ },
793
+ },
794
+ };
795
+ orders.push(tpOrder);
796
+ }
797
+ // 3. Stop Loss order
798
+ if (stopLossPrice) {
799
+ // Apply 10% slippage to SL limit price (executes as market order when triggered)
800
+ // HyperLiquid recommended: 10% for TP/SL orders
801
+ const stopLossPriceNum = parseFloat(stopLossPrice);
802
+ const slippageValue = ORDER_SLIPPAGE_CONFIG.DefaultTpslSlippageBps / 10000;
803
+ const limitPriceWithSlippage = isBuy
804
+ ? stopLossPriceNum * (1 - slippageValue) // Selling to close long: willing to accept LESS (slippage protection)
805
+ : stopLossPriceNum * (1 + slippageValue); // Buying to close short: willing to pay MORE (slippage protection)
806
+ const slOrder = {
807
+ a: assetId,
808
+ b: !isBuy,
809
+ p: formatHyperLiquidPrice({
810
+ price: limitPriceWithSlippage,
811
+ szDecimals,
812
+ }),
813
+ s: formatTpslSize({ tpslSize: stopLossSize, formattedSize, szDecimals }),
814
+ r: true,
815
+ t: {
816
+ trigger: {
817
+ isMarket: true,
818
+ triggerPx: formatTriggerPrice({
819
+ price: stopLossPrice,
820
+ szDecimals,
821
+ error: PERPS_ERROR_CODES.ORDER_PRICE_POSITIVE,
822
+ }),
823
+ tpsl: 'sl',
824
+ },
825
+ },
826
+ };
827
+ orders.push(slOrder);
828
+ }
829
+ // Determine grouping
830
+ const finalGrouping = grouping ?? ((takeProfitPrice ?? stopLossPrice) ? 'normalTpsl' : 'na');
831
+ return { orders, grouping: finalGrouping };
832
+ }
833
+ //# sourceMappingURL=orderCalculations.js.map