@lightconexyz/lightcone-sdk 0.1.0 → 0.2.0

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 (373) hide show
  1. package/README.md +33 -206
  2. package/dist/auth/client.d.ts +25 -0
  3. package/dist/auth/client.d.ts.map +1 -0
  4. package/dist/auth/client.js +120 -0
  5. package/dist/auth/client.js.map +1 -0
  6. package/dist/auth/index.d.ts +73 -0
  7. package/dist/auth/index.d.ts.map +1 -0
  8. package/dist/auth/index.js +42 -0
  9. package/dist/auth/index.js.map +1 -0
  10. package/dist/auth/native.d.ts +8 -0
  11. package/dist/auth/native.d.ts.map +1 -0
  12. package/dist/auth/native.js +19 -0
  13. package/dist/auth/native.js.map +1 -0
  14. package/dist/auth.d.ts +1 -79
  15. package/dist/auth.d.ts.map +1 -1
  16. package/dist/auth.js +15 -145
  17. package/dist/auth.js.map +1 -1
  18. package/dist/client.d.ts +69 -0
  19. package/dist/client.d.ts.map +1 -0
  20. package/dist/client.js +158 -0
  21. package/dist/client.js.map +1 -0
  22. package/dist/domain/admin/client.d.ts +17 -0
  23. package/dist/domain/admin/client.d.ts.map +1 -0
  24. package/dist/domain/admin/client.js +32 -0
  25. package/dist/domain/admin/client.js.map +1 -0
  26. package/dist/domain/admin/index.d.ts +7 -0
  27. package/dist/domain/admin/index.d.ts.map +1 -0
  28. package/dist/domain/admin/index.js +19 -0
  29. package/dist/domain/admin/index.js.map +1 -0
  30. package/dist/domain/admin/wire.d.ts +117 -0
  31. package/dist/domain/admin/wire.d.ts.map +1 -0
  32. package/dist/domain/admin/wire.js +3 -0
  33. package/dist/domain/admin/wire.js.map +1 -0
  34. package/dist/domain/index.d.ts +9 -0
  35. package/dist/domain/index.d.ts.map +1 -0
  36. package/dist/domain/index.js +45 -0
  37. package/dist/domain/index.js.map +1 -0
  38. package/dist/domain/market/client.d.ts +21 -0
  39. package/dist/domain/market/client.d.ts.map +1 -0
  40. package/dist/domain/market/client.js +70 -0
  41. package/dist/domain/market/client.js.map +1 -0
  42. package/dist/domain/market/convert.d.ts +8 -0
  43. package/dist/domain/market/convert.d.ts.map +1 -0
  44. package/dist/domain/market/convert.js +96 -0
  45. package/dist/domain/market/convert.js.map +1 -0
  46. package/dist/domain/market/index.d.ts +47 -0
  47. package/dist/domain/market/index.d.ts.map +1 -0
  48. package/dist/domain/market/index.js +58 -0
  49. package/dist/domain/market/index.js.map +1 -0
  50. package/dist/domain/market/outcome.d.ts +12 -0
  51. package/dist/domain/market/outcome.d.ts.map +1 -0
  52. package/dist/domain/market/outcome.js +28 -0
  53. package/dist/domain/market/outcome.js.map +1 -0
  54. package/dist/domain/market/tokens.d.ts +42 -0
  55. package/dist/domain/market/tokens.d.ts.map +1 -0
  56. package/dist/domain/market/tokens.js +106 -0
  57. package/dist/domain/market/tokens.js.map +1 -0
  58. package/dist/domain/market/wire.d.ts +116 -0
  59. package/dist/domain/market/wire.d.ts.map +1 -0
  60. package/dist/domain/market/wire.js +3 -0
  61. package/dist/domain/market/wire.js.map +1 -0
  62. package/dist/domain/order/client.d.ts +187 -0
  63. package/dist/domain/order/client.d.ts.map +1 -0
  64. package/dist/domain/order/client.js +122 -0
  65. package/dist/domain/order/client.js.map +1 -0
  66. package/dist/domain/order/convert.d.ts +8 -0
  67. package/dist/domain/order/convert.d.ts.map +1 -0
  68. package/dist/domain/order/convert.js +80 -0
  69. package/dist/domain/order/convert.js.map +1 -0
  70. package/dist/domain/order/index.d.ts +48 -0
  71. package/dist/domain/order/index.d.ts.map +1 -0
  72. package/dist/domain/order/index.js +41 -0
  73. package/dist/domain/order/index.js.map +1 -0
  74. package/dist/domain/order/state.d.ts +26 -0
  75. package/dist/domain/order/state.d.ts.map +1 -0
  76. package/dist/domain/order/state.js +85 -0
  77. package/dist/domain/order/state.js.map +1 -0
  78. package/dist/domain/order/wire.d.ts +123 -0
  79. package/dist/domain/order/wire.d.ts.map +1 -0
  80. package/dist/domain/order/wire.js +3 -0
  81. package/dist/domain/order/wire.js.map +1 -0
  82. package/dist/domain/orderbook/client.d.ts +20 -0
  83. package/dist/domain/orderbook/client.d.ts.map +1 -0
  84. package/dist/domain/orderbook/client.js +30 -0
  85. package/dist/domain/orderbook/client.js.map +1 -0
  86. package/dist/domain/orderbook/convert.d.ts +5 -0
  87. package/dist/domain/orderbook/convert.d.ts.map +1 -0
  88. package/dist/domain/orderbook/convert.js +34 -0
  89. package/dist/domain/orderbook/convert.js.map +1 -0
  90. package/dist/domain/orderbook/index.d.ts +36 -0
  91. package/dist/domain/orderbook/index.d.ts.map +1 -0
  92. package/dist/domain/orderbook/index.js +63 -0
  93. package/dist/domain/orderbook/index.js.map +1 -0
  94. package/dist/domain/orderbook/state.d.ts +19 -0
  95. package/dist/domain/orderbook/state.d.ts.map +1 -0
  96. package/dist/domain/orderbook/state.js +86 -0
  97. package/dist/domain/orderbook/state.js.map +1 -0
  98. package/dist/domain/orderbook/ticker.d.ts +8 -0
  99. package/dist/domain/orderbook/ticker.d.ts.map +1 -0
  100. package/dist/domain/orderbook/ticker.js +3 -0
  101. package/dist/domain/orderbook/ticker.js.map +1 -0
  102. package/dist/domain/orderbook/wire.d.ts +61 -0
  103. package/dist/domain/orderbook/wire.d.ts.map +1 -0
  104. package/dist/domain/orderbook/wire.js +3 -0
  105. package/dist/domain/orderbook/wire.js.map +1 -0
  106. package/dist/domain/position/client.d.ts +13 -0
  107. package/dist/domain/position/client.d.ts.map +1 -0
  108. package/dist/domain/position/client.js +20 -0
  109. package/dist/domain/position/client.js.map +1 -0
  110. package/dist/domain/position/index.d.ts +66 -0
  111. package/dist/domain/position/index.d.ts.map +1 -0
  112. package/dist/domain/position/index.js +19 -0
  113. package/dist/domain/position/index.js.map +1 -0
  114. package/dist/domain/position/wire.d.ts +29 -0
  115. package/dist/domain/position/wire.d.ts.map +1 -0
  116. package/dist/domain/position/wire.js +3 -0
  117. package/dist/domain/position/wire.js.map +1 -0
  118. package/dist/domain/price_history/client.d.ts +12 -0
  119. package/dist/domain/price_history/client.d.ts.map +1 -0
  120. package/dist/domain/price_history/client.js +24 -0
  121. package/dist/domain/price_history/client.js.map +1 -0
  122. package/dist/domain/price_history/index.d.ts +14 -0
  123. package/dist/domain/price_history/index.d.ts.map +1 -0
  124. package/dist/domain/price_history/index.js +27 -0
  125. package/dist/domain/price_history/index.js.map +1 -0
  126. package/dist/domain/price_history/state.d.ts +11 -0
  127. package/dist/domain/price_history/state.d.ts.map +1 -0
  128. package/dist/domain/price_history/state.js +35 -0
  129. package/dist/domain/price_history/state.js.map +1 -0
  130. package/dist/domain/price_history/wire.d.ts +47 -0
  131. package/dist/domain/price_history/wire.d.ts.map +1 -0
  132. package/dist/domain/price_history/wire.js +3 -0
  133. package/dist/domain/price_history/wire.js.map +1 -0
  134. package/dist/domain/referral/client.d.ts +13 -0
  135. package/dist/domain/referral/client.d.ts.map +1 -0
  136. package/dist/domain/referral/client.js +34 -0
  137. package/dist/domain/referral/client.js.map +1 -0
  138. package/dist/domain/referral/index.d.ts +17 -0
  139. package/dist/domain/referral/index.d.ts.map +1 -0
  140. package/dist/domain/referral/index.js +19 -0
  141. package/dist/domain/referral/index.js.map +1 -0
  142. package/dist/domain/referral/wire.d.ts +22 -0
  143. package/dist/domain/referral/wire.d.ts.map +1 -0
  144. package/dist/domain/referral/wire.js +3 -0
  145. package/dist/domain/referral/wire.js.map +1 -0
  146. package/dist/domain/trade/client.d.ts +12 -0
  147. package/dist/domain/trade/client.d.ts.map +1 -0
  148. package/dist/domain/trade/client.js +27 -0
  149. package/dist/domain/trade/client.js.map +1 -0
  150. package/dist/domain/trade/convert.d.ts +5 -0
  151. package/dist/domain/trade/convert.d.ts.map +1 -0
  152. package/dist/domain/trade/convert.js +25 -0
  153. package/dist/domain/trade/convert.js.map +1 -0
  154. package/dist/domain/trade/index.d.ts +19 -0
  155. package/dist/domain/trade/index.d.ts.map +1 -0
  156. package/dist/domain/trade/index.js +24 -0
  157. package/dist/domain/trade/index.js.map +1 -0
  158. package/dist/domain/trade/state.d.ts +16 -0
  159. package/dist/domain/trade/state.d.ts.map +1 -0
  160. package/dist/domain/trade/state.js +40 -0
  161. package/dist/domain/trade/state.js.map +1 -0
  162. package/dist/domain/trade/wire.d.ts +34 -0
  163. package/dist/domain/trade/wire.d.ts.map +1 -0
  164. package/dist/domain/trade/wire.js +3 -0
  165. package/dist/domain/trade/wire.js.map +1 -0
  166. package/dist/error.d.ts +44 -0
  167. package/dist/error.d.ts.map +1 -0
  168. package/dist/error.js +126 -0
  169. package/dist/error.js.map +1 -0
  170. package/dist/http/client.d.ts +16 -0
  171. package/dist/http/client.d.ts.map +1 -0
  172. package/dist/http/client.js +146 -0
  173. package/dist/http/client.js.map +1 -0
  174. package/dist/http/index.d.ts +3 -0
  175. package/dist/http/index.d.ts.map +1 -0
  176. package/dist/http/index.js +12 -0
  177. package/dist/http/index.js.map +1 -0
  178. package/dist/http/retry.d.ts +30 -0
  179. package/dist/http/retry.d.ts.map +1 -0
  180. package/dist/http/retry.js +48 -0
  181. package/dist/http/retry.js.map +1 -0
  182. package/dist/index.d.ts +13 -51
  183. package/dist/index.d.ts.map +1 -1
  184. package/dist/index.js +22 -68
  185. package/dist/index.js.map +1 -1
  186. package/dist/network.d.ts +4 -4
  187. package/dist/network.d.ts.map +1 -1
  188. package/dist/network.js +4 -4
  189. package/dist/network.js.map +1 -1
  190. package/dist/prelude.d.ts +41 -0
  191. package/dist/prelude.d.ts.map +1 -0
  192. package/dist/prelude.js +55 -0
  193. package/dist/prelude.js.map +1 -0
  194. package/dist/privy/client.d.ts +17 -0
  195. package/dist/privy/client.d.ts.map +1 -0
  196. package/dist/privy/client.js +66 -0
  197. package/dist/privy/client.js.map +1 -0
  198. package/dist/privy/index.d.ts +57 -0
  199. package/dist/privy/index.d.ts.map +1 -0
  200. package/dist/privy/index.js +80 -0
  201. package/dist/privy/index.js.map +1 -0
  202. package/dist/program/accounts.d.ts +19 -2
  203. package/dist/program/accounts.d.ts.map +1 -1
  204. package/dist/program/accounts.js +52 -2
  205. package/dist/program/accounts.js.map +1 -1
  206. package/dist/program/builder.d.ts +15 -11
  207. package/dist/program/builder.d.ts.map +1 -1
  208. package/dist/program/builder.js +30 -22
  209. package/dist/program/builder.js.map +1 -1
  210. package/dist/program/client.d.ts +40 -1
  211. package/dist/program/client.d.ts.map +1 -1
  212. package/dist/program/client.js +87 -2
  213. package/dist/program/client.js.map +1 -1
  214. package/dist/program/constants.d.ts +10 -1
  215. package/dist/program/constants.d.ts.map +1 -1
  216. package/dist/program/constants.js +11 -2
  217. package/dist/program/constants.js.map +1 -1
  218. package/dist/program/envelope.d.ts +94 -0
  219. package/dist/program/envelope.d.ts.map +1 -0
  220. package/dist/program/envelope.js +258 -0
  221. package/dist/program/envelope.js.map +1 -0
  222. package/dist/program/error.d.ts +8 -0
  223. package/dist/program/error.d.ts.map +1 -0
  224. package/dist/program/error.js +20 -0
  225. package/dist/program/error.js.map +1 -0
  226. package/dist/program/index.d.ts +8 -5
  227. package/dist/program/index.d.ts.map +1 -1
  228. package/dist/program/index.js +29 -3
  229. package/dist/program/index.js.map +1 -1
  230. package/dist/program/instructions.d.ts +124 -1
  231. package/dist/program/instructions.d.ts.map +1 -1
  232. package/dist/program/instructions.js +439 -4
  233. package/dist/program/instructions.js.map +1 -1
  234. package/dist/program/orders.d.ts +26 -8
  235. package/dist/program/orders.d.ts.map +1 -1
  236. package/dist/program/orders.js +58 -31
  237. package/dist/program/orders.js.map +1 -1
  238. package/dist/program/pda.d.ts +19 -0
  239. package/dist/program/pda.d.ts.map +1 -1
  240. package/dist/program/pda.js +28 -0
  241. package/dist/program/pda.js.map +1 -1
  242. package/dist/program/types.d.ts +93 -9
  243. package/dist/program/types.d.ts.map +1 -1
  244. package/dist/program/types.js.map +1 -1
  245. package/dist/shared/fmt/decimal.d.ts +5 -0
  246. package/dist/shared/fmt/decimal.d.ts.map +1 -0
  247. package/dist/shared/fmt/decimal.js +54 -0
  248. package/dist/shared/fmt/decimal.js.map +1 -0
  249. package/dist/shared/fmt/index.d.ts +3 -0
  250. package/dist/shared/fmt/index.d.ts.map +1 -0
  251. package/dist/shared/fmt/index.js +39 -0
  252. package/dist/shared/fmt/index.js.map +1 -0
  253. package/dist/shared/fmt/num.d.ts +6 -0
  254. package/dist/shared/fmt/num.d.ts.map +1 -0
  255. package/dist/shared/fmt/num.js +44 -0
  256. package/dist/shared/fmt/num.js.map +1 -0
  257. package/dist/shared/index.d.ts +4 -7
  258. package/dist/shared/index.d.ts.map +1 -1
  259. package/dist/shared/index.js +19 -7
  260. package/dist/shared/index.js.map +1 -1
  261. package/dist/shared/price.d.ts +5 -33
  262. package/dist/shared/price.d.ts.map +1 -1
  263. package/dist/shared/price.js +11 -39
  264. package/dist/shared/price.js.map +1 -1
  265. package/dist/shared/scaling.d.ts +17 -30
  266. package/dist/shared/scaling.d.ts.map +1 -1
  267. package/dist/shared/scaling.js +88 -57
  268. package/dist/shared/scaling.js.map +1 -1
  269. package/dist/shared/types.d.ts +66 -16
  270. package/dist/shared/types.d.ts.map +1 -1
  271. package/dist/shared/types.js +81 -17
  272. package/dist/shared/types.js.map +1 -1
  273. package/dist/ws/client.d.ts +35 -0
  274. package/dist/ws/client.d.ts.map +1 -0
  275. package/dist/ws/client.js +226 -0
  276. package/dist/ws/client.js.map +1 -0
  277. package/dist/ws/index.d.ts +109 -0
  278. package/dist/ws/index.d.ts.map +1 -0
  279. package/dist/ws/index.js +181 -0
  280. package/dist/ws/index.js.map +1 -0
  281. package/dist/ws/subscriptions.d.ts +51 -0
  282. package/dist/ws/subscriptions.d.ts.map +1 -0
  283. package/dist/ws/subscriptions.js +44 -0
  284. package/dist/ws/subscriptions.js.map +1 -0
  285. package/package.json +3 -11
  286. package/dist/api/client.d.ts +0 -225
  287. package/dist/api/client.d.ts.map +0 -1
  288. package/dist/api/client.js +0 -452
  289. package/dist/api/client.js.map +0 -1
  290. package/dist/api/error.d.ts +0 -58
  291. package/dist/api/error.d.ts.map +0 -1
  292. package/dist/api/error.js +0 -98
  293. package/dist/api/error.js.map +0 -1
  294. package/dist/api/index.d.ts +0 -23
  295. package/dist/api/index.d.ts.map +0 -1
  296. package/dist/api/index.js +0 -51
  297. package/dist/api/index.js.map +0 -1
  298. package/dist/api/types/admin.d.ts +0 -49
  299. package/dist/api/types/admin.d.ts.map +0 -1
  300. package/dist/api/types/admin.js +0 -13
  301. package/dist/api/types/admin.js.map +0 -1
  302. package/dist/api/types/index.d.ts +0 -14
  303. package/dist/api/types/index.d.ts.map +0 -1
  304. package/dist/api/types/index.js +0 -13
  305. package/dist/api/types/index.js.map +0 -1
  306. package/dist/api/types/market.d.ts +0 -186
  307. package/dist/api/types/market.d.ts.map +0 -1
  308. package/dist/api/types/market.js +0 -6
  309. package/dist/api/types/market.js.map +0 -1
  310. package/dist/api/types/order.d.ts +0 -190
  311. package/dist/api/types/order.d.ts.map +0 -1
  312. package/dist/api/types/order.js +0 -6
  313. package/dist/api/types/order.js.map +0 -1
  314. package/dist/api/types/orderbook.d.ts +0 -36
  315. package/dist/api/types/orderbook.d.ts.map +0 -1
  316. package/dist/api/types/orderbook.js +0 -6
  317. package/dist/api/types/orderbook.js.map +0 -1
  318. package/dist/api/types/position.d.ts +0 -60
  319. package/dist/api/types/position.d.ts.map +0 -1
  320. package/dist/api/types/position.js +0 -6
  321. package/dist/api/types/position.js.map +0 -1
  322. package/dist/api/types/price_history.d.ts +0 -68
  323. package/dist/api/types/price_history.d.ts.map +0 -1
  324. package/dist/api/types/price_history.js +0 -13
  325. package/dist/api/types/price_history.js.map +0 -1
  326. package/dist/api/types/trade.d.ts +0 -67
  327. package/dist/api/types/trade.d.ts.map +0 -1
  328. package/dist/api/types/trade.js +0 -13
  329. package/dist/api/types/trade.js.map +0 -1
  330. package/dist/api/validation.d.ts +0 -24
  331. package/dist/api/validation.d.ts.map +0 -1
  332. package/dist/api/validation.js +0 -53
  333. package/dist/api/validation.js.map +0 -1
  334. package/dist/websocket/client.d.ts +0 -238
  335. package/dist/websocket/client.d.ts.map +0 -1
  336. package/dist/websocket/client.js +0 -580
  337. package/dist/websocket/client.js.map +0 -1
  338. package/dist/websocket/error.d.ts +0 -47
  339. package/dist/websocket/error.d.ts.map +0 -1
  340. package/dist/websocket/error.js +0 -83
  341. package/dist/websocket/error.js.map +0 -1
  342. package/dist/websocket/handlers.d.ts +0 -97
  343. package/dist/websocket/handlers.d.ts.map +0 -1
  344. package/dist/websocket/handlers.js +0 -277
  345. package/dist/websocket/handlers.js.map +0 -1
  346. package/dist/websocket/index.d.ts +0 -38
  347. package/dist/websocket/index.d.ts.map +0 -1
  348. package/dist/websocket/index.js +0 -75
  349. package/dist/websocket/index.js.map +0 -1
  350. package/dist/websocket/state/index.d.ts +0 -7
  351. package/dist/websocket/state/index.d.ts.map +0 -1
  352. package/dist/websocket/state/index.js +0 -14
  353. package/dist/websocket/state/index.js.map +0 -1
  354. package/dist/websocket/state/orderbook.d.ts +0 -107
  355. package/dist/websocket/state/orderbook.d.ts.map +0 -1
  356. package/dist/websocket/state/orderbook.js +0 -293
  357. package/dist/websocket/state/orderbook.js.map +0 -1
  358. package/dist/websocket/state/price.d.ts +0 -108
  359. package/dist/websocket/state/price.d.ts.map +0 -1
  360. package/dist/websocket/state/price.js +0 -243
  361. package/dist/websocket/state/price.js.map +0 -1
  362. package/dist/websocket/state/user.d.ts +0 -83
  363. package/dist/websocket/state/user.d.ts.map +0 -1
  364. package/dist/websocket/state/user.js +0 -228
  365. package/dist/websocket/state/user.js.map +0 -1
  366. package/dist/websocket/subscriptions.d.ts +0 -143
  367. package/dist/websocket/subscriptions.d.ts.map +0 -1
  368. package/dist/websocket/subscriptions.js +0 -244
  369. package/dist/websocket/subscriptions.js.map +0 -1
  370. package/dist/websocket/types.d.ts +0 -417
  371. package/dist/websocket/types.d.ts.map +0 -1
  372. package/dist/websocket/types.js +0 -195
  373. package/dist/websocket/types.js.map +0 -1
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.num = exports.decimal = void 0;
37
+ exports.decimal = __importStar(require("./decimal"));
38
+ exports.num = __importStar(require("./num"));
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/shared/fmt/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAqC;AACrC,6CAA6B","sourcesContent":["export * as decimal from \"./decimal\";\nexport * as num from \"./num\";\n"]}
@@ -0,0 +1,6 @@
1
+ export declare function displayFormattedString(input: string): string;
2
+ export declare function displayWithDecimals(value: number, decimals: number): string;
3
+ export declare function display(value: number): string;
4
+ export declare function toDecimalValue(value: bigint, decimals: number): number;
5
+ export declare function fromDecimalValue(value: number, decimals: number): bigint;
6
+ //# sourceMappingURL=num.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"num.d.ts","sourceRoot":"","sources":["../../../src/shared/fmt/num.ts"],"names":[],"mappings":"AAAA,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAa5D;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE3E;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAe7C;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAExE"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.displayFormattedString = displayFormattedString;
4
+ exports.displayWithDecimals = displayWithDecimals;
5
+ exports.display = display;
6
+ exports.toDecimalValue = toDecimalValue;
7
+ exports.fromDecimalValue = fromDecimalValue;
8
+ function displayFormattedString(input) {
9
+ const [rawInteger, rawFraction] = input.split(".");
10
+ const negative = rawInteger.startsWith("-");
11
+ const integer = negative ? rawInteger.slice(1) : rawInteger;
12
+ const withCommas = integer.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
13
+ const fraction = rawFraction?.replace(/0+$/, "");
14
+ const prefix = negative ? "-" : "";
15
+ if (!fraction) {
16
+ return `${prefix}${withCommas}`;
17
+ }
18
+ return `${prefix}${withCommas}.${fraction}`;
19
+ }
20
+ function displayWithDecimals(value, decimals) {
21
+ return displayFormattedString(value.toFixed(decimals));
22
+ }
23
+ function display(value) {
24
+ if (Math.abs(value) >= 100) {
25
+ return displayWithDecimals(value, 0);
26
+ }
27
+ if (Math.abs(value) >= 1) {
28
+ return displayWithDecimals(value, 2);
29
+ }
30
+ if (value === 0) {
31
+ return "0";
32
+ }
33
+ const abs = Math.abs(value);
34
+ const exponent = Math.floor(Math.log10(abs));
35
+ const decimals = Math.min(Math.max(Math.abs(exponent) + 2, 2), 8);
36
+ return displayWithDecimals(value, decimals);
37
+ }
38
+ function toDecimalValue(value, decimals) {
39
+ return Number(value) / 10 ** decimals;
40
+ }
41
+ function fromDecimalValue(value, decimals) {
42
+ return BigInt(Math.trunc(value * 10 ** decimals));
43
+ }
44
+ //# sourceMappingURL=num.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"num.js","sourceRoot":"","sources":["../../../src/shared/fmt/num.ts"],"names":[],"mappings":";;AAAA,wDAaC;AAED,kDAEC;AAED,0BAeC;AAED,wCAEC;AAED,4CAEC;AA1CD,SAAgB,sBAAsB,CAAC,KAAa;IAClD,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnD,MAAM,QAAQ,GAAG,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;IAC5D,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,uBAAuB,EAAE,GAAG,CAAC,CAAC;IACjE,MAAM,QAAQ,GAAG,WAAW,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAEnC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,GAAG,MAAM,GAAG,UAAU,EAAE,CAAC;IAClC,CAAC;IAED,OAAO,GAAG,MAAM,GAAG,UAAU,IAAI,Q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","sourcesContent":["export function displayFormattedString(input: string): string {\n const [rawInteger, rawFraction] = input.split(\".\");\n const negative = rawInteger.startsWith(\"-\");\n const integer = negative ? rawInteger.slice(1) : rawInteger;\n const withCommas = integer.replace(/\\B(?=(\\d{3})+(?!\\d))/g, \",\");\n const fraction = rawFraction?.replace(/0+$/, \"\");\n const prefix = negative ? \"-\" : \"\";\n\n if (!fraction) {\n return `${prefix}${withCommas}`;\n }\n\n return `${prefix}${withCommas}.${fraction}`;\n}\n\nexport function displayWithDecimals(value: number, decimals: number): string {\n return displayFormattedString(value.toFixed(decimals));\n}\n\nexport function display(value: number): string {\n if (Math.abs(value) >= 100) {\n return displayWithDecimals(value, 0);\n }\n if (Math.abs(value) >= 1) {\n return displayWithDecimals(value, 2);\n }\n if (value === 0) {\n return \"0\";\n }\n\n const abs = Math.abs(value);\n const exponent = Math.floor(Math.log10(abs));\n const decimals = Math.min(Math.max(Math.abs(exponent) + 2, 2), 8);\n return displayWithDecimals(value, decimals);\n}\n\nexport function toDecimalValue(value: bigint, decimals: number): number {\n return Number(value) / 10 ** decimals;\n}\n\nexport function fromDecimalValue(value: number, decimals: number): bigint {\n return BigInt(Math.trunc(value * 10 ** decimals));\n}\n"]}
@@ -1,8 +1,5 @@
1
- /**
2
- * Shared utilities used across API and WebSocket modules.
3
- */
4
- export { Resolution } from "./types";
5
- export { parseDecimal, formatDecimal, isZero } from "./price";
6
- export { scalePriceSize, ScalingError, } from "./scaling";
7
- export type { OrderbookDecimals, ScaledAmounts } from "./scaling";
1
+ export { asOrderBookId, asPubkeyStr, deriveOrderbookId, resolutionSeconds, sideLabel, OrderUpdateType, Resolution, Side, TimeInForce, TriggerResultStatus, TriggerStatus, TriggerType, TriggerUpdateType, type Branded, type OrderBookId, type PubkeyStr, type SubmitOrderRequest, } from "./types";
2
+ export { formatDecimal, isZero, parseDecimal } from "./price";
3
+ export { alignPriceToTick, scalePriceSize, scalePriceSizeLegacy, ScalingError, type LegacyScaledAmounts, type OrderbookDecimals, type ScaledAmounts, } from "./scaling";
4
+ export { scalePriceSizeLegacy as scalePriceSizeV1 } from "./scaling";
8
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EACL,cAAc,EACd,YAAY,GACb,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,SAAS,EACT,eAAe,EACf,UAAU,EACV,IAAI,EACJ,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,kBAAkB,GACxB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE9D,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,YAAY,EACZ,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,aAAa,GACnB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,oBAAoB,IAAI,gBAAgB,EAAE,MAAM,WAAW,CAAC"}
@@ -1,18 +1,30 @@
1
1
  "use strict";
2
- /**
3
- * Shared utilities used across API and WebSocket modules.
4
- */
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ScalingError = exports.scalePriceSize = exports.isZero = exports.formatDecimal = exports.parseDecimal = exports.Resolution = void 0;
3
+ exports.scalePriceSizeV1 = exports.ScalingError = exports.scalePriceSizeLegacy = exports.scalePriceSize = exports.alignPriceToTick = exports.parseDecimal = exports.isZero = exports.formatDecimal = exports.TriggerUpdateType = exports.TriggerType = exports.TriggerStatus = exports.TriggerResultStatus = exports.TimeInForce = exports.Side = exports.Resolution = exports.OrderUpdateType = exports.sideLabel = exports.resolutionSeconds = exports.deriveOrderbookId = exports.asPubkeyStr = exports.asOrderBookId = void 0;
7
4
  var types_1 = require("./types");
5
+ Object.defineProperty(exports, "asOrderBookId", { enumerable: true, get: function () { return types_1.asOrderBookId; } });
6
+ Object.defineProperty(exports, "asPubkeyStr", { enumerable: true, get: function () { return types_1.asPubkeyStr; } });
7
+ Object.defineProperty(exports, "deriveOrderbookId", { enumerable: true, get: function () { return types_1.deriveOrderbookId; } });
8
+ Object.defineProperty(exports, "resolutionSeconds", { enumerable: true, get: function () { return types_1.resolutionSeconds; } });
9
+ Object.defineProperty(exports, "sideLabel", { enumerable: true, get: function () { return types_1.sideLabel; } });
10
+ Object.defineProperty(exports, "OrderUpdateType", { enumerable: true, get: function () { return types_1.OrderUpdateType; } });
8
11
  Object.defineProperty(exports, "Resolution", { enumerable: true, get: function () { return types_1.Resolution; } });
12
+ Object.defineProperty(exports, "Side", { enumerable: true, get: function () { return types_1.Side; } });
13
+ Object.defineProperty(exports, "TimeInForce", { enumerable: true, get: function () { return types_1.TimeInForce; } });
14
+ Object.defineProperty(exports, "TriggerResultStatus", { enumerable: true, get: function () { return types_1.TriggerResultStatus; } });
15
+ Object.defineProperty(exports, "TriggerStatus", { enumerable: true, get: function () { return types_1.TriggerStatus; } });
16
+ Object.defineProperty(exports, "TriggerType", { enumerable: true, get: function () { return types_1.TriggerType; } });
17
+ Object.defineProperty(exports, "TriggerUpdateType", { enumerable: true, get: function () { return types_1.TriggerUpdateType; } });
9
18
  var price_1 = require("./price");
10
- Object.defineProperty(exports, "parseDecimal", { enumerable: true, get: function () { return price_1.parseDecimal; } });
11
19
  Object.defineProperty(exports, "formatDecimal", { enumerable: true, get: function () { return price_1.formatDecimal; } });
12
20
  Object.defineProperty(exports, "isZero", { enumerable: true, get: function () { return price_1.isZero; } });
21
+ Object.defineProperty(exports, "parseDecimal", { enumerable: true, get: function () { return price_1.parseDecimal; } });
13
22
  var scaling_1 = require("./scaling");
23
+ Object.defineProperty(exports, "alignPriceToTick", { enumerable: true, get: function () { return scaling_1.alignPriceToTick; } });
14
24
  Object.defineProperty(exports, "scalePriceSize", { enumerable: true, get: function () { return scaling_1.scalePriceSize; } });
25
+ Object.defineProperty(exports, "scalePriceSizeLegacy", { enumerable: true, get: function () { return scaling_1.scalePriceSizeLegacy; } });
15
26
  Object.defineProperty(exports, "ScalingError", { enumerable: true, get: function () { return scaling_1.ScalingError; } });
16
- // deriveOrderbookId is exported from the program module (orders.ts)
17
- // Re-exported here for convenience via the shared module path
27
+ // Backward-compatible name from v1.
28
+ var scaling_2 = require("./scaling");
29
+ Object.defineProperty(exports, "scalePriceSizeV1", { enumerable: true, get: function () { return scaling_2.scalePriceSizeLegacy; } });
18
30
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iCAAqC;AAA5B,mGAAA,UAAU,OAAA;AACnB,iCAA8D;AAArD,qGAAA,YAAY,OAAA;AAAE,sGAAA,aAAa,OAAA;AAAE,+FAAA,MAAM,OAAA;AAC5C,qCAGmB;AAFjB,yGAAA,cAAc,OAAA;AACd,uGAAA,YAAY,OAAA;AAId,oEAAoE;AACpE,8DAA8D","sourcesContent":["/**\n * Shared utilities used across API and WebSocket modules.\n */\n\nexport { Resolution } from \"./types\";\nexport { parseDecimal, formatDecimal, isZero } from \"./price\";\nexport {\n scalePriceSize,\n ScalingError,\n} from \"./scaling\";\nexport type { OrderbookDecimals, ScaledAmounts } from \"./scaling\";\n\n// deriveOrderbookId is exported from the program module (orders.ts)\n// Re-exported here for convenience via the shared module path\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":";;;AAAA,iCAkBiB;AAjBf,sGAAA,aAAa,OAAA;AACb,oGAAA,WAAW,OAAA;AACX,0GAAA,iBAAiB,OAAA;AACjB,0GAAA,iBAAiB,OAAA;AACjB,kGAAA,SAAS,OAAA;AACT,wGAAA,eAAe,OAAA;AACf,mGAAA,UAAU,OAAA;AACV,6FAAA,IAAI,OAAA;AACJ,oGAAA,WAAW,OAAA;AACX,4GAAA,mBAAmB,OAAA;AACnB,sGAAA,aAAa,OAAA;AACb,oGAAA,WAAW,OAAA;AACX,0GAAA,iBAAiB,OAAA;AAOnB,iCAA8D;AAArD,sGAAA,aAAa,OAAA;AAAE,+FAAA,MAAM,OAAA;AAAE,qGAAA,YAAY,OAAA;AAE5C,qCAQmB;AAPjB,2GAAA,gBAAgB,OAAA;AAChB,yGAAA,cAAc,OAAA;AACd,+GAAA,oBAAoB,OAAA;AACpB,uGAAA,YAAY,OAAA;AAMd,oCAAoC;AACpC,qCAAqE;AAA5D,2GAAA,oBAAoB,OAAoB","sourcesContent":["export {\n asOrderBookId,\n asPubkeyStr,\n deriveOrderbookId,\n resolutionSeconds,\n sideLabel,\n OrderUpdateType,\n Resolution,\n Side,\n TimeInForce,\n TriggerResultStatus,\n TriggerStatus,\n TriggerType,\n TriggerUpdateType,\n type Branded,\n type OrderBookId,\n type PubkeyStr,\n type SubmitOrderRequest,\n} from \"./types\";\n\nexport { formatDecimal, isZero, parseDecimal } from \"./price\";\n\nexport {\n alignPriceToTick,\n scalePriceSize,\n scalePriceSizeLegacy,\n ScalingError,\n type LegacyScaledAmounts,\n type OrderbookDecimals,\n type ScaledAmounts,\n} from \"./scaling\";\n\n// Backward-compatible name from v1.\nexport { scalePriceSizeLegacy as scalePriceSizeV1 } from \"./scaling\";\n"]}
@@ -1,41 +1,13 @@
1
1
  /**
2
- * Price utilities for the Lightcone SDK.
3
- *
4
- * This module provides helper functions for working with decimal string prices.
5
- * The SDK uses String types for price/size/balance fields to preserve
6
- * the exact decimal representation from the server, as different tokens
7
- * have different decimal places (USDC=6, SOL=9, BTC=8, etc.).
2
+ * Parse a decimal string to a number.
8
3
  */
4
+ export declare function parseDecimal(value: string): number;
9
5
  /**
10
- * Parse a decimal string to number for calculations.
11
- *
12
- * @example
13
- * ```typescript
14
- * parseDecimal("0.500000"); // returns 0.5
15
- * parseDecimal("1.000000"); // returns 1.0
16
- * ```
17
- */
18
- export declare function parseDecimal(s: string): number;
19
- /**
20
- * Format a number as a decimal string with specified precision.
21
- *
22
- * @example
23
- * ```typescript
24
- * formatDecimal(0.5, 6); // returns "0.500000"
25
- * formatDecimal(1.0, 6); // returns "1.000000"
26
- * ```
6
+ * Format a number to a fixed decimal string.
27
7
  */
28
8
  export declare function formatDecimal(value: number, precision: number): string;
29
9
  /**
30
- * Check if a decimal string represents zero.
31
- *
32
- * @example
33
- * ```typescript
34
- * isZero("0"); // true
35
- * isZero("0.0"); // true
36
- * isZero("0.000000"); // true
37
- * isZero("0.001"); // false
38
- * ```
10
+ * Whether a decimal string represents numeric zero.
39
11
  */
40
- export declare function isZero(s: string): boolean;
12
+ export declare function isZero(value: string): boolean;
41
13
  //# sourceMappingURL=price.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"price.d.ts","sourceRoot":"","sources":["../../src/shared/price.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAM9C;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAGzC"}
1
+ {"version":3,"file":"price.d.ts","sourceRoot":"","sources":["../../src/shared/price.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMlD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAG7C"}
@@ -1,57 +1,29 @@
1
1
  "use strict";
2
- /**
3
- * Price utilities for the Lightcone SDK.
4
- *
5
- * This module provides helper functions for working with decimal string prices.
6
- * The SDK uses String types for price/size/balance fields to preserve
7
- * the exact decimal representation from the server, as different tokens
8
- * have different decimal places (USDC=6, SOL=9, BTC=8, etc.).
9
- */
10
2
  Object.defineProperty(exports, "__esModule", { value: true });
11
3
  exports.parseDecimal = parseDecimal;
12
4
  exports.formatDecimal = formatDecimal;
13
5
  exports.isZero = isZero;
14
6
  /**
15
- * Parse a decimal string to number for calculations.
16
- *
17
- * @example
18
- * ```typescript
19
- * parseDecimal("0.500000"); // returns 0.5
20
- * parseDecimal("1.000000"); // returns 1.0
21
- * ```
7
+ * Parse a decimal string to a number.
22
8
  */
23
- function parseDecimal(s) {
24
- const result = parseFloat(s);
25
- if (isNaN(result)) {
26
- throw new Error(`Invalid decimal string: ${s}`);
9
+ function parseDecimal(value) {
10
+ const parsed = Number.parseFloat(value);
11
+ if (Number.isNaN(parsed)) {
12
+ throw new Error(`Invalid decimal string: ${value}`);
27
13
  }
28
- return result;
14
+ return parsed;
29
15
  }
30
16
  /**
31
- * Format a number as a decimal string with specified precision.
32
- *
33
- * @example
34
- * ```typescript
35
- * formatDecimal(0.5, 6); // returns "0.500000"
36
- * formatDecimal(1.0, 6); // returns "1.000000"
37
- * ```
17
+ * Format a number to a fixed decimal string.
38
18
  */
39
19
  function formatDecimal(value, precision) {
40
20
  return value.toFixed(precision);
41
21
  }
42
22
  /**
43
- * Check if a decimal string represents zero.
44
- *
45
- * @example
46
- * ```typescript
47
- * isZero("0"); // true
48
- * isZero("0.0"); // true
49
- * isZero("0.000000"); // true
50
- * isZero("0.001"); // false
51
- * ```
23
+ * Whether a decimal string represents numeric zero.
52
24
  */
53
- function isZero(s) {
54
- const parsed = parseFloat(s);
55
- return !isNaN(parsed) && parsed === 0;
25
+ function isZero(value) {
26
+ const parsed = Number.parseFloat(value);
27
+ return !Number.isNaN(parsed) && parsed === 0;
56
28
  }
57
29
  //# sourceMappingURL=price.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"price.js","sourceRoot":"","sources":["../../src/shared/price.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AAWH,oCAMC;AAWD,sCAEC;AAaD,wBAGC;AA5CD;;;;;;;;GAQG;AACH,SAAgB,YAAY,CAAC,CAAS;IACpC,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IAC7B,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,EAAE,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,aAAa,CAAC,KAAa,EAAE,SAAiB;IAC5D,OAAO,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,MAAM,CAAC,CAAS;IAC9B,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IAC7B,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,MAAM,KAAK,CAAC,CAAC;AACxC,CAAC","sourcesContent":["/**\n * Price utilities for the Lightcone SDK.\n *\n * This module provides helper functions for working with decimal string prices.\n * The SDK uses String types for price/size/balance fields to preserve\n * the exact decimal representation from the server, as different tokens\n * have different decimal places (USDC=6, SOL=9, BTC=8, etc.).\n */\n\n/**\n * Parse a decimal string to number for calculations.\n *\n * @example\n * ```typescript\n * parseDecimal(\"0.500000\"); // returns 0.5\n * parseDecimal(\"1.000000\"); // returns 1.0\n * ```\n */\nexport function parseDecimal(s: string): number {\n const result = parseFloat(s);\n if (isNaN(result)) {\n throw new Error(`Invalid decimal string: ${s}`);\n }\n return result;\n}\n\n/**\n * Format a number as a decimal string with specified precision.\n *\n * @example\n * ```typescript\n * formatDecimal(0.5, 6); // returns \"0.500000\"\n * formatDecimal(1.0, 6); // returns \"1.000000\"\n * ```\n */\nexport function formatDecimal(value: number, precision: number): string {\n return value.toFixed(precision);\n}\n\n/**\n * Check if a decimal string represents zero.\n *\n * @example\n * ```typescript\n * isZero(\"0\"); // true\n * isZero(\"0.0\"); // true\n * isZero(\"0.000000\"); // true\n * isZero(\"0.001\"); // false\n * ```\n */\nexport function isZero(s: string): boolean {\n const parsed = parseFloat(s);\n return !isNaN(parsed) && parsed === 0;\n}\n\n"]}
1
+ {"version":3,"file":"price.js","sourceRoot":"","sources":["../../src/shared/price.ts"],"names":[],"mappings":";;AAGA,oCAMC;AAKD,sCAEC;AAKD,wBAGC;AAxBD;;GAEG;AACH,SAAgB,YAAY,CAAC,KAAa;IACxC,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACxC,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,2BAA2B,KAAK,EAAE,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,KAAa,EAAE,SAAiB;IAC5D,OAAO,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED;;GAEG;AACH,SAAgB,MAAM,CAAC,KAAa;IAClC,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACxC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,MAAM,KAAK,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["/**\n * Parse a decimal string to a number.\n */\nexport function parseDecimal(value: string): number {\n const parsed = Number.parseFloat(value);\n if (Number.isNaN(parsed)) {\n throw new Error(`Invalid decimal string: ${value}`);\n }\n return parsed;\n}\n\n/**\n * Format a number to a fixed decimal string.\n */\nexport function formatDecimal(value: number, precision: number): string {\n return value.toFixed(precision);\n}\n\n/**\n * Whether a decimal string represents numeric zero.\n */\nexport function isZero(value: string): boolean {\n const parsed = Number.parseFloat(value);\n return !Number.isNaN(parsed) && parsed === 0;\n}\n"]}
@@ -1,45 +1,32 @@
1
+ import Decimal from "decimal.js";
1
2
  import { OrderSide } from "../program/types";
2
- /**
3
- * Orderbook decimal configuration
4
- */
5
3
  export interface OrderbookDecimals {
6
4
  orderbookId: string;
7
5
  baseDecimals: number;
8
6
  quoteDecimals: number;
9
7
  priceDecimals: number;
8
+ tickSize?: bigint;
10
9
  }
11
- /**
12
- * Scaled amounts result
13
- */
14
10
  export interface ScaledAmounts {
11
+ amountIn: bigint;
12
+ amountOut: bigint;
15
13
  makerAmount: bigint;
16
14
  takerAmount: bigint;
17
15
  }
18
- /**
19
- * Error thrown during price/size scaling
20
- */
21
16
  export declare class ScalingError extends Error {
22
17
  constructor(message: string);
23
- static zeroPriceOrSize(): ScalingError;
24
- static negativeValue(field: string): ScalingError;
25
- static overflow(field: string): ScalingError;
18
+ static nonPositivePrice(value: string): ScalingError;
19
+ static nonPositiveSize(value: string): ScalingError;
20
+ static overflow(context: string): ScalingError;
21
+ static zeroAmount(): ScalingError;
22
+ static fractionalAmount(value: string): ScalingError;
23
+ static invalidDecimal(input: string, reason: string): ScalingError;
26
24
  }
27
- /**
28
- * Scale price and size to maker_amount and taker_amount using exact decimal arithmetic.
29
- *
30
- * For BID orders (buying base with quote):
31
- * - maker_amount = price * size * 10^quoteDecimals (what maker gives in quote tokens)
32
- * - taker_amount = size * 10^baseDecimals (what maker receives in base tokens)
33
- *
34
- * For ASK orders (selling base for quote):
35
- * - maker_amount = size * 10^baseDecimals (what maker gives in base tokens)
36
- * - taker_amount = price * size * 10^quoteDecimals (what maker receives in quote tokens)
37
- *
38
- * @param priceStr - Price as a decimal string (e.g., "0.75")
39
- * @param sizeStr - Size as a decimal string (e.g., "100")
40
- * @param side - Order side (BID or ASK)
41
- * @param decimals - Orderbook decimal configuration
42
- * @returns Scaled maker_amount and taker_amount as bigints
43
- */
44
- export declare function scalePriceSize(priceStr: string, sizeStr: string, side: OrderSide, decimals: OrderbookDecimals): ScaledAmounts;
25
+ export declare function alignPriceToTick(price: Decimal, decimals: OrderbookDecimals): Decimal;
26
+ export declare function scalePriceSize(priceInput: string | Decimal, sizeInput: string | Decimal, side: OrderSide, decimals: OrderbookDecimals): ScaledAmounts;
27
+ export interface LegacyScaledAmounts {
28
+ makerAmount: bigint;
29
+ takerAmount: bigint;
30
+ }
31
+ export declare function scalePriceSizeLegacy(price: string, size: string, side: OrderSide, decimals: OrderbookDecimals): LegacyScaledAmounts;
45
32
  //# sourceMappingURL=scaling.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"scaling.d.ts","sourceRoot":"","sources":["../../src/shared/scaling.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;IAK3B,MAAM,CAAC,eAAe,IAAI,YAAY;IAItC,MAAM,CAAC,aAAa,CAAC,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B,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAWrF;AAED,wBAAgB,cAAc,CAC5B,UAAU,EAAE,MAAM,GAAG,OAAO,EAC5B,SAAS,EAAE,MAAM,GAAG,OAAO,EAC3B,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,iBAAiB,GAC1B,aAAa,CA0Cf;AA8BD,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,iBAAiB,GAC1B,mBAAmB,CAMrB"}
@@ -4,81 +4,112 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ScalingError = void 0;
7
+ exports.alignPriceToTick = alignPriceToTick;
7
8
  exports.scalePriceSize = scalePriceSize;
9
+ exports.scalePriceSizeLegacy = scalePriceSizeLegacy;
8
10
  const decimal_js_1 = __importDefault(require("decimal.js"));
9
11
  const types_1 = require("../program/types");
10
- /**
11
- * Error thrown during price/size scaling
12
- */
12
+ const U64_MAX = (1n << 64n) - 1n;
13
13
  class ScalingError extends Error {
14
14
  constructor(message) {
15
15
  super(message);
16
16
  this.name = "ScalingError";
17
17
  }
18
- static zeroPriceOrSize() {
19
- return new ScalingError("Price and size must be non-zero");
18
+ static nonPositivePrice(value) {
19
+ return new ScalingError(`Price must be positive, got ${value}`);
20
+ }
21
+ static nonPositiveSize(value) {
22
+ return new ScalingError(`Size must be positive, got ${value}`);
23
+ }
24
+ static overflow(context) {
25
+ return new ScalingError(`Overflow: ${context}`);
20
26
  }
21
- static negativeValue(field) {
22
- return new ScalingError(`${field} must be positive`);
27
+ static zeroAmount() {
28
+ return new ScalingError("Computed amount is zero");
23
29
  }
24
- static overflow(field) {
25
- return new ScalingError(`${field} exceeds u64 range`);
30
+ static fractionalAmount(value) {
31
+ return new ScalingError(`Fractional lamports not allowed: ${value}`);
32
+ }
33
+ static invalidDecimal(input, reason) {
34
+ return new ScalingError(`Invalid decimal '${input}': ${reason}`);
26
35
  }
27
36
  }
28
37
  exports.ScalingError = ScalingError;
29
- const U64_MAX = (1n << 64n) - 1n;
30
- /**
31
- * Scale price and size to maker_amount and taker_amount using exact decimal arithmetic.
32
- *
33
- * For BID orders (buying base with quote):
34
- * - maker_amount = price * size * 10^quoteDecimals (what maker gives in quote tokens)
35
- * - taker_amount = size * 10^baseDecimals (what maker receives in base tokens)
36
- *
37
- * For ASK orders (selling base for quote):
38
- * - maker_amount = size * 10^baseDecimals (what maker gives in base tokens)
39
- * - taker_amount = price * size * 10^quoteDecimals (what maker receives in quote tokens)
40
- *
41
- * @param priceStr - Price as a decimal string (e.g., "0.75")
42
- * @param sizeStr - Size as a decimal string (e.g., "100")
43
- * @param side - Order side (BID or ASK)
44
- * @param decimals - Orderbook decimal configuration
45
- * @returns Scaled maker_amount and taker_amount as bigints
46
- */
47
- function scalePriceSize(priceStr, sizeStr, side, decimals) {
48
- const price = new decimal_js_1.default(priceStr);
49
- const size = new decimal_js_1.default(sizeStr);
50
- if (price.isZero() || size.isZero()) {
51
- throw ScalingError.zeroPriceOrSize();
52
- }
53
- if (price.isNegative()) {
54
- throw ScalingError.negativeValue("price");
55
- }
56
- if (size.isNegative()) {
57
- throw ScalingError.negativeValue("size");
58
- }
59
- const baseScale = new decimal_js_1.default(10).pow(decimals.baseDecimals);
60
- const quoteScale = new decimal_js_1.default(10).pow(decimals.quoteDecimals);
61
- const baseAmount = size.mul(baseScale).floor();
62
- const quoteAmount = price.mul(size).mul(quoteScale).floor();
63
- const baseAmountBigInt = BigInt(baseAmount.toFixed(0));
64
- const quoteAmountBigInt = BigInt(quoteAmount.toFixed(0));
65
- if (baseAmountBigInt > U64_MAX) {
66
- throw ScalingError.overflow("base amount");
67
- }
68
- if (quoteAmountBigInt > U64_MAX) {
69
- throw ScalingError.overflow("quote amount");
38
+ function alignPriceToTick(price, decimals) {
39
+ const tickSize = decimals.tickSize ?? 0n;
40
+ if (tickSize <= 1n) {
41
+ return price;
42
+ }
43
+ const quoteMultiplier = new decimal_js_1.default(10).pow(decimals.quoteDecimals);
44
+ const tick = new decimal_js_1.default(tickSize.toString());
45
+ const lamports = price.mul(quoteMultiplier).trunc();
46
+ const aligned = lamports.div(tick).trunc().mul(tick);
47
+ return aligned.div(quoteMultiplier);
48
+ }
49
+ function scalePriceSize(priceInput, sizeInput, side, decimals) {
50
+ const price = normalizeDecimal(priceInput, "price");
51
+ const size = normalizeDecimal(sizeInput, "size");
52
+ if (price.lte(0)) {
53
+ throw ScalingError.nonPositivePrice(price.toString());
54
+ }
55
+ if (size.lte(0)) {
56
+ throw ScalingError.nonPositiveSize(size.toString());
57
+ }
58
+ const baseMultiplier = new decimal_js_1.default(10).pow(decimals.baseDecimals);
59
+ const quoteMultiplier = new decimal_js_1.default(10).pow(decimals.quoteDecimals);
60
+ const baseLamports = size.mul(baseMultiplier);
61
+ const quoteLamports = price.mul(size).mul(quoteMultiplier);
62
+ assertWhole(baseLamports, "base_lamports");
63
+ assertWhole(quoteLamports, "quote_lamports");
64
+ const base = toU64(baseLamports, "base_lamports");
65
+ const quote = toU64(quoteLamports, "quote_lamports");
66
+ if (base === 0n || quote === 0n) {
67
+ throw ScalingError.zeroAmount();
70
68
  }
71
69
  if (side === types_1.OrderSide.BID) {
72
70
  return {
73
- makerAmount: quoteAmountBigInt,
74
- takerAmount: baseAmountBigInt,
71
+ amountIn: quote,
72
+ amountOut: base,
73
+ makerAmount: quote,
74
+ takerAmount: base,
75
75
  };
76
76
  }
77
- else {
78
- return {
79
- makerAmount: baseAmountBigInt,
80
- takerAmount: quoteAmountBigInt,
81
- };
77
+ return {
78
+ amountIn: base,
79
+ amountOut: quote,
80
+ makerAmount: base,
81
+ takerAmount: quote,
82
+ };
83
+ }
84
+ function normalizeDecimal(value, field) {
85
+ if (value instanceof decimal_js_1.default) {
86
+ return value;
87
+ }
88
+ try {
89
+ return new decimal_js_1.default(value);
82
90
  }
91
+ catch (error) {
92
+ const reason = error instanceof Error ? error.message : String(error);
93
+ throw ScalingError.invalidDecimal(value, reason || field);
94
+ }
95
+ }
96
+ function assertWhole(value, label) {
97
+ if (!value.isInteger()) {
98
+ throw ScalingError.fractionalAmount(`${label} = ${value.toString()}`);
99
+ }
100
+ }
101
+ function toU64(value, label) {
102
+ const bigint = BigInt(value.toFixed(0));
103
+ if (bigint < 0n || bigint > U64_MAX) {
104
+ throw ScalingError.overflow(`${label} ${value.toString()} does not fit in u64`);
105
+ }
106
+ return bigint;
107
+ }
108
+ function scalePriceSizeLegacy(price, size, side, decimals) {
109
+ const scaled = scalePriceSize(price, size, side, decimals);
110
+ return {
111
+ makerAmount: scaled.amountIn,
112
+ takerAmount: scaled.amountOut,
113
+ };
83
114
  }
84
115
  //# sourceMappingURL=scaling.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"scaling.js","sourceRoot":"","sources":["../../src/shared/scaling.ts"],"names":[],"mappings":";;;;;;AA8DA,wCA8CC;AA5GD,4DAAiC;AACjC,4CAA6C;AAoB7C;;GAEG;AACH,MAAa,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;IAED,MAAM,CAAC,eAAe;QACpB,OAAO,IAAI,YAAY,CAAC,iCAAiC,CAAC,CAAC;IAC7D,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,KAAa;QAChC,OAAO,IAAI,YAAY,CAAC,GAAG,KAAK,mBAAmB,CAAC,CAAC;IACvD,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,KAAa;QAC3B,OAAO,IAAI,YAAY,CAAC,GAAG,KAAK,oBAAoB,CAAC,CAAC;IACxD,CAAC;CACF;AAjBD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,CAAC,CAAC,CAAC;IAEzD,IAAI,gBAAgB,GAAG,OAAO,EAAE,CAAC;QAC/B,MAAM,YAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;IAC7C,CAAC;IACD,IAAI,iBAAiB,GAAG,OAAO,EAAE,CAAC;QAChC,MAAM,YAAY,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,IAAI,KAAK,iBAAS,CAAC,GAAG,EAAE,CAAC;QAC3B,OAAO;YACL,WAAW,EAAE,iBAAiB;YAC9B,WAAW,EAAE,gBAAgB;SAC9B,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,OAAO;YACL,WAAW,EAAE,gBAAgB;YAC7B,WAAW,EAAE,iBAAiB;SAC/B,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import Decimal from \"decimal.js\";\nimport { OrderSide } from \"../program/types\";\n\n/**\n * Orderbook decimal configuration\n */\nexport interface OrderbookDecimals {\n orderbookId: string;\n baseDecimals: number;\n quoteDecimals: number;\n priceDecimals: number;\n}\n\n/**\n * Scaled amounts result\n */\nexport interface ScaledAmounts {\n makerAmount: bigint;\n takerAmount: bigint;\n}\n\n/**\n * Error thrown during price/size scaling\n */\nexport class ScalingError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ScalingError\";\n }\n\n static zeroPriceOrSize(): ScalingError {\n return new ScalingError(\"Price and size must be non-zero\");\n }\n\n static negativeValue(field: string): ScalingError {\n return new ScalingError(`${field} must be positive`);\n }\n\n static overflow(field: string): ScalingError {\n return new ScalingError(`${field} exceeds u64 range`);\n }\n}\n\nconst U64_MAX = (1n << 64n) - 1n;\n\n/**\n * Scale price and size to maker_amount and taker_amount using exact decimal arithmetic.\n *\n * For BID orders (buying base with quote):\n * - maker_amount = price * size * 10^quoteDecimals (what maker gives in quote tokens)\n * - taker_amount = size * 10^baseDecimals (what maker receives in base tokens)\n *\n * For ASK orders (selling base for quote):\n * - maker_amount = size * 10^baseDecimals (what maker gives in base tokens)\n * - taker_amount = price * size * 10^quoteDecimals (what maker receives in quote tokens)\n *\n * @param priceStr - Price as a decimal string (e.g., \"0.75\")\n * @param sizeStr - Size as a decimal string (e.g., \"100\")\n * @param side - Order side (BID or ASK)\n * @param decimals - Orderbook decimal configuration\n * @returns Scaled maker_amount and taker_amount as bigints\n */\nexport function scalePriceSize(\n priceStr: string,\n sizeStr: string,\n side: OrderSide,\n decimals: OrderbookDecimals\n): ScaledAmounts {\n const price = new Decimal(priceStr);\n const size = new Decimal(sizeStr);\n\n if (price.isZero() || size.isZero()) {\n throw ScalingError.zeroPriceOrSize();\n }\n if (price.isNegative()) {\n throw ScalingError.negativeValue(\"price\");\n }\n if (size.isNegative()) {\n throw ScalingError.negativeValue(\"size\");\n }\n\n const baseScale = new Decimal(10).pow(decimals.baseDecimals);\n const quoteScale = new Decimal(10).pow(decimals.quoteDecimals);\n\n const baseAmount = size.mul(baseScale).floor();\n const quoteAmount = price.mul(size).mul(quoteScale).floor();\n\n const baseAmountBigInt = BigInt(baseAmount.toFixed(0));\n const quoteAmountBigInt = BigInt(quoteAmount.toFixed(0));\n\n if (baseAmountBigInt > U64_MAX) {\n throw ScalingError.overflow(\"base amount\");\n }\n if (quoteAmountBigInt > U64_MAX) {\n throw ScalingError.overflow(\"quote amount\");\n }\n\n if (side === OrderSide.BID) {\n return {\n makerAmount: quoteAmountBigInt,\n takerAmount: baseAmountBigInt,\n };\n } else {\n return {\n makerAmount: baseAmountBigInt,\n takerAmount: quoteAmountBigInt,\n };\n }\n}\n"]}
1
+ {"version":3,"file":"scaling.js","sourceRoot":"","sources":["../../src/shared/scaling.ts"],"names":[],"mappings":";;;;;;AAoDA,4CAWC;AAED,wCA+CC;AAmCD,oDAWC;AA9JD,4DAAiC;AACjC,4CAA6C;AAkB7C,MAAM,OAAO,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;AAEjC,MAAa,YAAa,SAAQ,KAAK;IACrC,YAAY,OAA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M,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC,IAAI,MAAM,GAAG,EAAE,IAAI,MAAM,GAAG,OAAO,EAAE,CAAC;QACpC,MAAM,YAAY,CAAC,QAAQ,CAAC,GAAG,KAAK,IAAI,KAAK,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC;IAClF,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAQD,SAAgB,oBAAoB,CAClC,KAAa,EACb,IAAY,EACZ,IAAe,EACf,QAA2B;IAE3B,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC3D,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,QAAQ;QAC5B,WAAW,EAAE,MAAM,CAAC,SAAS;KAC9B,CAAC;AACJ,CAAC","sourcesContent":["import Decimal from \"decimal.js\";\nimport { OrderSide } from \"../program/types\";\n\nexport interface OrderbookDecimals {\n orderbookId: string;\n baseDecimals: number;\n quoteDecimals: number;\n priceDecimals: number;\n tickSize?: bigint;\n}\n\nexport interface ScaledAmounts {\n amountIn: bigint;\n amountOut: bigint;\n // Backward-compatible aliases used by v1 builder code.\n makerAmount: bigint;\n takerAmount: bigint;\n}\n\nconst U64_MAX = (1n << 64n) - 1n;\n\nexport class ScalingError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ScalingError\";\n }\n\n static nonPositivePrice(value: string): ScalingError {\n return new ScalingError(`Price must be positive, got ${value}`);\n }\n\n static nonPositiveSize(value: string): ScalingError {\n return new ScalingError(`Size must be positive, got ${value}`);\n }\n\n static overflow(context: string): ScalingError {\n return new ScalingError(`Overflow: ${context}`);\n }\n\n static zeroAmount(): ScalingError {\n return new ScalingError(\"Computed amount is zero\");\n }\n\n static fractionalAmount(value: string): ScalingError {\n return new ScalingError(`Fractional lamports not allowed: ${value}`);\n }\n\n static invalidDecimal(input: string, reason: string): ScalingError {\n return new ScalingError(`Invalid decimal '${input}': ${reason}`);\n }\n}\n\nexport function alignPriceToTick(price: Decimal, decimals: OrderbookDecimals): Decimal {\n const tickSize = decimals.tickSize ?? 0n;\n if (tickSize <= 1n) {\n return price;\n }\n\n const quoteMultiplier = new Decimal(10).pow(decimals.quoteDecimals);\n const tick = new Decimal(tickSize.toString());\n const lamports = price.mul(quoteMultiplier).trunc();\n const aligned = lamports.div(tick).trunc().mul(tick);\n return aligned.div(quoteMultiplier);\n}\n\nexport function scalePriceSize(\n priceInput: string | Decimal,\n sizeInput: string | Decimal,\n side: OrderSide,\n decimals: OrderbookDecimals\n): ScaledAmounts {\n const price = normalizeDecimal(priceInput, \"price\");\n const size = normalizeDecimal(sizeInput, \"size\");\n\n if (price.lte(0)) {\n throw ScalingError.nonPositivePrice(price.toString());\n }\n if (size.lte(0)) {\n throw ScalingError.nonPositiveSize(size.toString());\n }\n\n const baseMultiplier = new Decimal(10).pow(decimals.baseDecimals);\n const quoteMultiplier = new Decimal(10).pow(decimals.quoteDecimals);\n\n const baseLamports = size.mul(baseMultiplier);\n const quoteLamports = price.mul(size).mul(quoteMultiplier);\n\n assertWhole(baseLamports, \"base_lamports\");\n assertWhole(quoteLamports, \"quote_lamports\");\n\n const base = toU64(baseLamports, \"base_lamports\");\n const quote = toU64(quoteLamports, \"quote_lamports\");\n\n if (base === 0n || quote === 0n) {\n throw ScalingError.zeroAmount();\n }\n\n if (side === OrderSide.BID) {\n return {\n amountIn: quote,\n amountOut: base,\n makerAmount: quote,\n takerAmount: base,\n };\n }\n\n return {\n amountIn: base,\n amountOut: quote,\n makerAmount: base,\n takerAmount: quote,\n };\n}\n\nfunction normalizeDecimal(value: string | Decimal, field: string): Decimal {\n if (value instanceof Decimal) {\n return value;\n }\n\n try {\n return new Decimal(value);\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n throw ScalingError.invalidDecimal(value, reason || field);\n }\n}\n\nfunction assertWhole(value: Decimal, label: string): void {\n if (!value.isInteger()) {\n throw ScalingError.fractionalAmount(`${label} = ${value.toString()}`);\n }\n}\n\nfunction toU64(value: Decimal, label: string): bigint {\n const bigint = BigInt(value.toFixed(0));\n if (bigint < 0n || bigint > U64_MAX) {\n throw ScalingError.overflow(`${label} ${value.toString()} does not fit in u64`);\n }\n return bigint;\n}\n\n// Legacy aliases kept for existing integrations.\nexport interface LegacyScaledAmounts {\n makerAmount: bigint;\n takerAmount: bigint;\n}\n\nexport function scalePriceSizeLegacy(\n price: string,\n size: string,\n side: OrderSide,\n decimals: OrderbookDecimals\n): LegacyScaledAmounts {\n const scaled = scalePriceSize(price, size, side, decimals);\n return {\n makerAmount: scaled.amountIn,\n takerAmount: scaled.amountOut,\n };\n}\n"]}