@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,181 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.ReadyState = exports.WS_DEFAULT_CONFIG = void 0;
18
+ exports.readyStateFrom = readyStateFrom;
19
+ exports.ping = ping;
20
+ exports.subscribeBooks = subscribeBooks;
21
+ exports.unsubscribeBooks = unsubscribeBooks;
22
+ exports.subscribeTrades = subscribeTrades;
23
+ exports.unsubscribeTrades = unsubscribeTrades;
24
+ exports.subscribeUser = subscribeUser;
25
+ exports.unsubscribeUser = unsubscribeUser;
26
+ exports.subscribePriceHistory = subscribePriceHistory;
27
+ exports.unsubscribePriceHistory = unsubscribePriceHistory;
28
+ exports.subscribeTicker = subscribeTicker;
29
+ exports.unsubscribeTicker = unsubscribeTicker;
30
+ exports.subscribeMarket = subscribeMarket;
31
+ exports.unsubscribeMarket = unsubscribeMarket;
32
+ exports.parseMessageIn = parseMessageIn;
33
+ const network_1 = require("../network");
34
+ __exportStar(require("./client"), exports);
35
+ __exportStar(require("./subscriptions"), exports);
36
+ exports.WS_DEFAULT_CONFIG = {
37
+ url: network_1.DEFAULT_WS_URL,
38
+ reconnect: true,
39
+ maxReconnectAttempts: 10,
40
+ baseReconnectDelayMs: 1_000,
41
+ pingIntervalMs: 30_000,
42
+ pongTimeoutMs: 1_000,
43
+ };
44
+ var ReadyState;
45
+ (function (ReadyState) {
46
+ ReadyState[ReadyState["Connecting"] = 0] = "Connecting";
47
+ ReadyState[ReadyState["Open"] = 1] = "Open";
48
+ ReadyState[ReadyState["Closing"] = 2] = "Closing";
49
+ ReadyState[ReadyState["Closed"] = 3] = "Closed";
50
+ })(ReadyState || (exports.ReadyState = ReadyState = {}));
51
+ function readyStateFrom(value) {
52
+ switch (value) {
53
+ case 0:
54
+ return ReadyState.Connecting;
55
+ case 1:
56
+ return ReadyState.Open;
57
+ case 2:
58
+ return ReadyState.Closing;
59
+ case 3:
60
+ default:
61
+ return ReadyState.Closed;
62
+ }
63
+ }
64
+ function ping() {
65
+ return { method: "ping" };
66
+ }
67
+ function subscribeBooks(orderbookIds) {
68
+ return {
69
+ method: "subscribe",
70
+ params: {
71
+ type: "book_update",
72
+ orderbook_ids: orderbookIds,
73
+ },
74
+ };
75
+ }
76
+ function unsubscribeBooks(orderbookIds) {
77
+ return {
78
+ method: "unsubscribe",
79
+ params: {
80
+ type: "book_update",
81
+ orderbook_ids: orderbookIds,
82
+ },
83
+ };
84
+ }
85
+ function subscribeTrades(orderbookIds) {
86
+ return {
87
+ method: "subscribe",
88
+ params: {
89
+ type: "trades",
90
+ orderbook_ids: orderbookIds,
91
+ },
92
+ };
93
+ }
94
+ function unsubscribeTrades(orderbookIds) {
95
+ return {
96
+ method: "unsubscribe",
97
+ params: {
98
+ type: "trades",
99
+ orderbook_ids: orderbookIds,
100
+ },
101
+ };
102
+ }
103
+ function subscribeUser(walletAddress) {
104
+ return {
105
+ method: "subscribe",
106
+ params: {
107
+ type: "user",
108
+ wallet_address: walletAddress,
109
+ },
110
+ };
111
+ }
112
+ function unsubscribeUser(walletAddress) {
113
+ return {
114
+ method: "unsubscribe",
115
+ params: {
116
+ type: "user",
117
+ wallet_address: walletAddress,
118
+ },
119
+ };
120
+ }
121
+ function subscribePriceHistory(orderbookId, resolution) {
122
+ return {
123
+ method: "subscribe",
124
+ params: {
125
+ type: "price_history",
126
+ orderbook_id: orderbookId,
127
+ resolution,
128
+ include_ohlcv: false,
129
+ },
130
+ };
131
+ }
132
+ function unsubscribePriceHistory(orderbookId, resolution) {
133
+ return {
134
+ method: "unsubscribe",
135
+ params: {
136
+ type: "price_history",
137
+ orderbook_id: orderbookId,
138
+ resolution,
139
+ },
140
+ };
141
+ }
142
+ function subscribeTicker(orderbookIds) {
143
+ return {
144
+ method: "subscribe",
145
+ params: {
146
+ type: "ticker",
147
+ orderbook_ids: orderbookIds,
148
+ },
149
+ };
150
+ }
151
+ function unsubscribeTicker(orderbookIds) {
152
+ return {
153
+ method: "unsubscribe",
154
+ params: {
155
+ type: "ticker",
156
+ orderbook_ids: orderbookIds,
157
+ },
158
+ };
159
+ }
160
+ function subscribeMarket(marketPubkey) {
161
+ return {
162
+ method: "subscribe",
163
+ params: {
164
+ type: "market",
165
+ market_pubkey: marketPubkey,
166
+ },
167
+ };
168
+ }
169
+ function unsubscribeMarket(marketPubkey) {
170
+ return {
171
+ method: "unsubscribe",
172
+ params: {
173
+ type: "market",
174
+ market_pubkey: marketPubkey,
175
+ },
176
+ };
177
+ }
178
+ function parseMessageIn(input) {
179
+ return JSON.parse(input);
180
+ }
181
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ws/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAsEA,wCAYC;AAED,oBAEC;AAED,wCAQC;AAED,4CAQC;AAED,0CAQC;AAED,8CAQC;AAED,sCAQC;AAED,0CAQC;AAED,sDAUC;AAED,0DASC;AAED,0CAQC;AAED,8CAQC;AAED,0CAQC;AAED,8CAQC;AAED,wCAEC;AAhND,wCAA4C;AAG5C,2CAAyB;AACzB,kDAAgC;AA6CnB,QAAA,iBAAiB,GAAa;IACzC,GAAG,EAAE,wBAAc;IACnB,SAAS,EAAE,IAAI;IACf,oBAAoB,EAAE,EAAE;IACxB,oBAAoB,EAAE,KAAK;IAC3B,cAAc,EAAE,MAAM;IACtB,aAAa,EAAE,KAAK;CACrB,CAAC;AAEF,I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a;QACrB,MAAM,EAAE;YACN,IAAI,EAAE,QAAQ;YACd,aAAa,EAAE,YAAY;SAC5B;KACF,CAAC;AACJ,CAAC;AAED,SAAgB,cAAc,CAAC,KAAa;IAC1C,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAc,CAAC;AACxC,CAAC","sourcesContent":["import type { MarketEvent } from \"../domain/market\";\nimport type { AuthUpdate, UserUpdate } from \"../domain/order\";\nimport type { OrderBook, WsTickerData } from \"../domain/orderbook\";\nimport type { PriceHistory } from \"../domain/price_history\";\nimport type { WsTrade } from \"../domain/trade\";\nimport { DEFAULT_WS_URL } from \"../network\";\nimport type { OrderBookId, PubkeyStr, Resolution } from \"../shared\";\n\nexport * from \"./client\";\nexport * from \"./subscriptions\";\n\nexport type MessageOut =\n | { method: \"subscribe\"; params: import(\"./subscriptions\").SubscribeParams }\n | { method: \"unsubscribe\"; params: import(\"./subscriptions\").UnsubscribeParams }\n | { method: \"ping\" };\n\nexport type MessageIn =\n | { type: \"book_update\"; version: number; data: OrderBook }\n | { type: \"pong\"; version: number; data: Record<string, never> }\n | { type: \"user\"; version: number; data: UserUpdate }\n | { type: \"error\"; version: number; data: WsError }\n | { type: \"price_history\"; version: number; data: PriceHistory }\n | { type: \"trades\"; version: number; data: WsTrade }\n | { type: \"auth\"; version: number; data: AuthUpdate }\n | { type: \"ticker\"; version: number; data: WsTickerData }\n | { type: \"market\"; version: number; data: MarketEvent };\n\nexport type Kind = MessageIn;\n\nexport interface WsError {\n error: string;\n code?: string;\n orderbook_id?: string;\n wallet_address?: string;\n hint?: string;\n details?: string;\n}\n\nexport type WsEvent =\n | { type: \"Message\"; message: MessageIn }\n | { type: \"Connected\" }\n | { type: \"Disconnected\"; code?: number; reason: string }\n | { type: \"Error\"; error: string }\n | { type: \"MaxReconnectReached\" };\n\nexport interface WsConfig {\n url: string;\n reconnect: boolean;\n maxReconnectAttempts: number;\n baseReconnectDelayMs: number;\n pingIntervalMs: number;\n pongTimeoutMs: number;\n}\n\nexport const WS_DEFAULT_CONFIG: WsConfig = {\n url: DEFAULT_WS_URL,\n reconnect: true,\n maxReconnectAttempts: 10,\n baseReconnectDelayMs: 1_000,\n pingIntervalMs: 30_000,\n pongTimeoutMs: 1_000,\n};\n\nexport enum ReadyState {\n Connecting = 0,\n Open = 1,\n Closing = 2,\n Closed = 3,\n}\n\nexport function readyStateFrom(value: number): ReadyState {\n switch (value) {\n case 0:\n return ReadyState.Connecting;\n case 1:\n return ReadyState.Open;\n case 2:\n return ReadyState.Closing;\n case 3:\n default:\n return ReadyState.Closed;\n }\n}\n\nexport function ping(): MessageOut {\n return { method: \"ping\" };\n}\n\nexport function subscribeBooks(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeBooks(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"book_update\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeTrades(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"trades\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeUser(walletAddress: PubkeyStr): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"user\",\n wallet_address: walletAddress,\n },\n };\n}\n\nexport function unsubscribeUser(walletAddress: PubkeyStr): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"user\",\n wallet_address: walletAddress,\n },\n };\n}\n\nexport function subscribePriceHistory(orderbookId: OrderBookId, resolution: Resolution): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"price_history\",\n orderbook_id: orderbookId,\n resolution,\n include_ohlcv: false,\n },\n };\n}\n\nexport function unsubscribePriceHistory(orderbookId: OrderBookId, resolution: Resolution): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"price_history\",\n orderbook_id: orderbookId,\n resolution,\n },\n };\n}\n\nexport function subscribeTicker(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"ticker\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function unsubscribeTicker(orderbookIds: OrderBookId[]): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"ticker\",\n orderbook_ids: orderbookIds,\n },\n };\n}\n\nexport function subscribeMarket(marketPubkey: PubkeyStr): MessageOut {\n return {\n method: \"subscribe\",\n params: {\n type: \"market\",\n market_pubkey: marketPubkey,\n },\n };\n}\n\nexport function unsubscribeMarket(marketPubkey: PubkeyStr): MessageOut {\n return {\n method: \"unsubscribe\",\n params: {\n type: \"market\",\n market_pubkey: marketPubkey,\n },\n };\n}\n\nexport function parseMessageIn(input: string): MessageIn {\n return JSON.parse(input) as MessageIn;\n}\n"]}
@@ -0,0 +1,51 @@
1
+ import type { OrderBookId, PubkeyStr, Resolution } from "../shared";
2
+ export type SubscribeParams = {
3
+ type: "book_update";
4
+ orderbook_ids: OrderBookId[];
5
+ } | {
6
+ type: "trades";
7
+ orderbook_ids: OrderBookId[];
8
+ } | {
9
+ type: "user";
10
+ wallet_address: PubkeyStr;
11
+ } | {
12
+ type: "price_history";
13
+ orderbook_id: OrderBookId;
14
+ resolution: Resolution;
15
+ include_ohlcv?: boolean;
16
+ } | {
17
+ type: "ticker";
18
+ orderbook_ids: OrderBookId[];
19
+ } | {
20
+ type: "market";
21
+ market_pubkey: PubkeyStr;
22
+ };
23
+ export type UnsubscribeParams = {
24
+ type: "book_update";
25
+ orderbook_ids: OrderBookId[];
26
+ } | {
27
+ type: "trades";
28
+ orderbook_ids: OrderBookId[];
29
+ } | {
30
+ type: "user";
31
+ wallet_address: PubkeyStr;
32
+ } | {
33
+ type: "price_history";
34
+ orderbook_id: OrderBookId;
35
+ resolution: Resolution;
36
+ } | {
37
+ type: "ticker";
38
+ orderbook_ids: OrderBookId[];
39
+ } | {
40
+ type: "market";
41
+ market_pubkey: PubkeyStr;
42
+ };
43
+ export interface Subscription {
44
+ toSubscribeParams(): SubscribeParams;
45
+ toUnsubscribeParams(): UnsubscribeParams;
46
+ matchesUnsubscribe(unsubscribe: UnsubscribeParams): boolean;
47
+ subscriptionKey(): string;
48
+ }
49
+ export declare function subscriptionKey(params: SubscribeParams): string;
50
+ export declare function unsubscribeMatches(subscribe: SubscribeParams, unsubscribe: UnsubscribeParams): boolean;
51
+ //# sourceMappingURL=subscriptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscriptions.d.ts","sourceRoot":"","sources":["../../src/ws/subscriptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEpE,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,aAAa,EAAE,WAAW,EAAE,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,aAAa,EAAE,WAAW,EAAE,CAAA;CAAE,GAChD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,SAAS,CAAA;CAAE,GAC3C;IACE,IAAI,EAAE,eAAe,CAAC;IACtB,YAAY,EAAE,WAAW,CAAC;IAC1B,UAAU,EAAE,UAAU,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,GACD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,aAAa,EAAE,WAAW,EAAE,CAAA;CAAE,GAChD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,aAAa,EAAE,SAAS,CAAA;CAAE,CAAC;AAEjD,MAAM,MAAM,iBAAiB,GACzB;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,aAAa,EAAE,WAAW,EAAE,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,aAAa,EAAE,WAAW,EAAE,CAAA;CAAE,GAChD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,SAAS,CAAA;CAAE,GAC3C;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,YAAY,EAAE,WAAW,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAE,GAC5E;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,aAAa,EAAE,WAAW,EAAE,CAAA;CAAE,GAChD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,aAAa,EAAE,SAAS,CAAA;CAAE,CAAC;AAEjD,MAAM,WAAW,YAAY;IAC3B,iBAAiB,IAAI,eAAe,CAAC;IACrC,mBAAmB,IAAI,iBAAiB,CAAC;IACzC,kBAAkB,CAAC,WAAW,EAAE,iBAAiB,GAAG,OAAO,CAAC;IAC5D,eAAe,IAAI,MAAM,CAAC;CAC3B;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAe/D;AAED,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,eAAe,EAC1B,WAAW,EAAE,iBAAiB,GAC7B,OAAO,CAsBT"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.subscriptionKey = subscriptionKey;
4
+ exports.unsubscribeMatches = unsubscribeMatches;
5
+ function subscriptionKey(params) {
6
+ switch (params.type) {
7
+ case "book_update":
8
+ return `book:${idsKey(params.orderbook_ids)}`;
9
+ case "trades":
10
+ return `trades:${idsKey(params.orderbook_ids)}`;
11
+ case "user":
12
+ return `user:${params.wallet_address}`;
13
+ case "price_history":
14
+ return `price_history:${params.orderbook_id}:${params.resolution}`;
15
+ case "ticker":
16
+ return `ticker:${idsKey(params.orderbook_ids)}`;
17
+ case "market":
18
+ return `market:${params.market_pubkey}`;
19
+ }
20
+ }
21
+ function unsubscribeMatches(subscribe, unsubscribe) {
22
+ if (subscribe.type !== unsubscribe.type) {
23
+ return false;
24
+ }
25
+ switch (subscribe.type) {
26
+ case "book_update":
27
+ return idsKey(subscribe.orderbook_ids) === idsKey(unsubscribe.orderbook_ids);
28
+ case "trades":
29
+ return idsKey(subscribe.orderbook_ids) === idsKey(unsubscribe.orderbook_ids);
30
+ case "ticker":
31
+ return idsKey(subscribe.orderbook_ids) === idsKey(unsubscribe.orderbook_ids);
32
+ case "user":
33
+ return subscribe.wallet_address === unsubscribe.wallet_address;
34
+ case "price_history":
35
+ return (subscribe.orderbook_id === unsubscribe.orderbook_id &&
36
+ subscribe.resolution === unsubscribe.resolution);
37
+ case "market":
38
+ return subscribe.market_pubkey === unsubscribe.market_pubkey;
39
+ }
40
+ }
41
+ function idsKey(ids) {
42
+ return [...ids].sort().join(",");
43
+ }
44
+ //# sourceMappingURL=subscriptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscriptions.js","sourceRoot":"","sources":["../../src/ws/subscriptions.ts"],"names":[],"mappings":";;AA8BA,0CAeC;AAED,gDAyBC;AA1CD,SAAgB,eAAe,CAAC,MAAuB;IACrD,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,aAAa;YAChB,OAAO,QAAQ,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;QAChD,KAAK,QAAQ;YACX,OAAO,UAAU,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;QAClD,KAAK,MAAM;YACT,OAAO,QAAQ,MAAM,CAAC,cAAc,EAAE,CAAC;QACzC,KAAK,eAAe;YAClB,OAAO,iBAAiB,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QACrE,KAAK,QAAQ;YACX,OAAO,UAAU,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;QAClD,KAAK,QAAQ;YACX,OAAO,UAAU,MAAM,CAAC,aAAa,EAAE,CAAC;IAC5C,CAAC;AACH,CAAC;AAED,SAAgB,kBAAkB,CAChC,SAA0B,EAC1B,WAA8B;IAE9B,IAAI,SAAS,CAAC,IAAI,KAAK,WAAW,CAAC,IAAI,EAAE,CAAC;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,QAAQ,SAAS,CAAC,IAAI,EAAE,CAAC;QACvB,KAAK,aAAa;YAChB,OAAO,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,MAAM,CAAE,WAAgD,CAAC,aAAa,CAAC,CAAC;QACrH,KAAK,QAAQ;YACX,OAAO,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,MAAM,CAAE,WAAgD,CAAC,aAAa,CAAC,CAAC;QACrH,KAAK,QAAQ;YACX,OAAO,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,MAAM,CAAE,WAAgD,CAAC,aAAa,CAAC,CAAC;QACrH,KAAK,MAAM;YACT,OAAO,SAAS,CAAC,cAAc,KAAM,WAA6C,CAAC,cAAc,CAAC;QACpG,KAAK,eAAe;YAClB,OAAO,CACL,SAAS,CAAC,YAAY,KAAM,WAA6C,CAAC,YAAY;gBACtF,SAAS,CAAC,UAAU,KAAM,WAA0C,CAAC,UAAU,CAChF,CAAC;QACJ,KAAK,QAAQ;YACX,OAAO,SAAS,CAAC,aAAa,KAAM,WAA4C,CAAC,aAAa,CAAC;IACnG,CAAC;AACH,CAAC;AAED,SAAS,MAAM,CAAC,GAAsB;IACpC,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACnC,CAAC","sourcesContent":["import type { OrderBookId, PubkeyStr, Resolution } from \"../shared\";\n\nexport type SubscribeParams =\n | { type: \"book_update\"; orderbook_ids: OrderBookId[] }\n | { type: \"trades\"; orderbook_ids: OrderBookId[] }\n | { type: \"user\"; wallet_address: PubkeyStr }\n | {\n type: \"price_history\";\n orderbook_id: OrderBookId;\n resolution: Resolution;\n include_ohlcv?: boolean;\n }\n | { type: \"ticker\"; orderbook_ids: OrderBookId[] }\n | { type: \"market\"; market_pubkey: PubkeyStr };\n\nexport type UnsubscribeParams =\n | { type: \"book_update\"; orderbook_ids: OrderBookId[] }\n | { type: \"trades\"; orderbook_ids: OrderBookId[] }\n | { type: \"user\"; wallet_address: PubkeyStr }\n | { type: \"price_history\"; orderbook_id: OrderBookId; resolution: Resolution }\n | { type: \"ticker\"; orderbook_ids: OrderBookId[] }\n | { type: \"market\"; market_pubkey: PubkeyStr };\n\nexport interface Subscription {\n toSubscribeParams(): SubscribeParams;\n toUnsubscribeParams(): UnsubscribeParams;\n matchesUnsubscribe(unsubscribe: UnsubscribeParams): boolean;\n subscriptionKey(): string;\n}\n\nexport function subscriptionKey(params: SubscribeParams): string {\n switch (params.type) {\n case \"book_update\":\n return `book:${idsKey(params.orderbook_ids)}`;\n case \"trades\":\n return `trades:${idsKey(params.orderbook_ids)}`;\n case \"user\":\n return `user:${params.wallet_address}`;\n case \"price_history\":\n return `price_history:${params.orderbook_id}:${params.resolution}`;\n case \"ticker\":\n return `ticker:${idsKey(params.orderbook_ids)}`;\n case \"market\":\n return `market:${params.market_pubkey}`;\n }\n}\n\nexport function unsubscribeMatches(\n subscribe: SubscribeParams,\n unsubscribe: UnsubscribeParams\n): boolean {\n if (subscribe.type !== unsubscribe.type) {\n return false;\n }\n\n switch (subscribe.type) {\n case \"book_update\":\n return idsKey(subscribe.orderbook_ids) === idsKey((unsubscribe as { orderbook_ids: OrderBookId[] }).orderbook_ids);\n case \"trades\":\n return idsKey(subscribe.orderbook_ids) === idsKey((unsubscribe as { orderbook_ids: OrderBookId[] }).orderbook_ids);\n case \"ticker\":\n return idsKey(subscribe.orderbook_ids) === idsKey((unsubscribe as { orderbook_ids: OrderBookId[] }).orderbook_ids);\n case \"user\":\n return subscribe.wallet_address === (unsubscribe as { wallet_address: PubkeyStr }).wallet_address;\n case \"price_history\":\n return (\n subscribe.orderbook_id === (unsubscribe as { orderbook_id: OrderBookId }).orderbook_id &&\n subscribe.resolution === (unsubscribe as { resolution: Resolution }).resolution\n );\n case \"market\":\n return subscribe.market_pubkey === (unsubscribe as { market_pubkey: PubkeyStr }).market_pubkey;\n }\n}\n\nfunction idsKey(ids: readonly string[]): string {\n return [...ids].sort().join(\",\");\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightconexyz/lightcone-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "TypeScript SDK for the Lightcone Protocol",
5
5
  "author": "Lightcone",
6
6
  "license": "MIT",
@@ -29,14 +29,8 @@
29
29
  "clean": "rm -rf dist",
30
30
  "lint": "eslint src",
31
31
  "lint:fix": "eslint src --fix",
32
- "test": "vitest run",
33
- "test:watch": "vitest",
34
- "test:coverage": "vitest run --coverage",
35
- "test:legacy": "ts-node test/unit.test.ts",
36
- "test:devnet": "ts-node test/devnet.test.ts",
37
- "test:stress": "ts-node test/stress.test.ts",
38
32
  "typecheck": "tsc --noEmit",
39
- "prepublishOnly": "npm run clean && npm run lint && npm run test && npm run build"
33
+ "prepublishOnly": "npm run clean && npm run lint && npm run typecheck && npm run build"
40
34
  },
41
35
  "dependencies": {
42
36
  "@solana/spl-token": "^0.4.14",
@@ -53,9 +47,7 @@
53
47
  "@typescript-eslint/parser": "^7.0.0",
54
48
  "dotenv": "^17.2.3",
55
49
  "eslint": "^8.57.0",
56
- "ts-node": "^10.9.2",
57
- "typescript": "^5.9.3",
58
- "vitest": "^1.6.0"
50
+ "typescript": "^5.9.3"
59
51
  },
60
52
  "peerDependencies": {
61
53
  "@solana/web3.js": "^1.90.0"
@@ -1,225 +0,0 @@
1
- /**
2
- * REST API client for Lightcone.
3
- */
4
- import { Keypair } from "@solana/web3.js";
5
- import { type AuthCredentials } from "../auth";
6
- import type { MarketsResponse, MarketInfoResponse, DepositAssetsResponse, OrderbookResponse, SubmitOrderRequest, OrderResponse, CancelResponse, CancelAllResponse, PositionsResponse, MarketPositionsResponse, UserOrdersResponse, PriceHistoryParams, PriceHistoryResponse, TradesParams, TradesResponse, AdminResponse, CreateOrderbookRequest, CreateOrderbookResponse } from "./types";
7
- export { DEFAULT_API_URL } from "../network";
8
- /**
9
- * Configuration for retry behavior.
10
- */
11
- export interface RetryConfig {
12
- /** Maximum number of retry attempts (default: 0 = disabled) */
13
- maxRetries: number;
14
- /** Initial delay in milliseconds (default: 100) */
15
- baseDelayMs: number;
16
- /** Maximum delay cap in milliseconds (default: 10000) */
17
- maxDelayMs: number;
18
- }
19
- /** Default retry configuration (disabled) */
20
- export declare const DEFAULT_RETRY_CONFIG: RetryConfig;
21
- /**
22
- * Configuration for the Lightcone API client.
23
- */
24
- export interface LightconeApiClientConfig {
25
- /** Base URL for the API (default: https://tapi.lightcone.xyz/api) */
26
- baseUrl?: string;
27
- /** Request timeout in milliseconds (default: 30000) */
28
- timeout?: number;
29
- /** Additional headers to include in requests */
30
- headers?: Record<string, string>;
31
- /** Retry configuration for transient failures */
32
- retry?: Partial<RetryConfig>;
33
- /** Authentication token for authenticated endpoints */
34
- authToken?: string;
35
- }
36
- /**
37
- * REST API client for the Lightcone platform.
38
- *
39
- * @example
40
- * ```typescript
41
- * import { LightconeApiClient } from "@lightcone/sdk/api";
42
- *
43
- * const client = new LightconeApiClient();
44
- *
45
- * // Get all markets
46
- * const markets = await client.getMarkets();
47
- *
48
- * // Get orderbook
49
- * const orderbook = await client.getOrderbook("market1:ob1");
50
- * ```
51
- */
52
- export declare class LightconeApiClient {
53
- private readonly baseUrl;
54
- private readonly timeout;
55
- private readonly headers;
56
- private readonly retryConfig;
57
- private authToken?;
58
- constructor(config?: LightconeApiClientConfig);
59
- /**
60
- * Log in with a Solana keypair. Stores the auth token for subsequent requests.
61
- *
62
- * @param keypair - The Solana Keypair for authentication
63
- * @returns AuthCredentials containing the auth token and user info
64
- */
65
- login(keypair: Keypair): Promise<AuthCredentials>;
66
- /**
67
- * Set the authentication token manually.
68
- */
69
- setAuthToken(token: string): void;
70
- /**
71
- * Clear the authentication token.
72
- */
73
- clearAuthToken(): void;
74
- /**
75
- * Check if the client has an authentication token.
76
- */
77
- hasAuthToken(): boolean;
78
- /**
79
- * Make an HTTP request with retry support.
80
- */
81
- private request;
82
- /**
83
- * Check if the API is healthy.
84
- *
85
- * @throws {ApiError} If the health check fails
86
- */
87
- healthCheck(): Promise<void>;
88
- /**
89
- * Get all available markets.
90
- *
91
- * @returns List of markets
92
- */
93
- getMarkets(): Promise<MarketsResponse>;
94
- /**
95
- * Get market information by pubkey.
96
- *
97
- * @param marketPubkey - Market PDA address (Base58)
98
- * @returns Market details
99
- * @throws {ApiError} If marketPubkey is invalid
100
- */
101
- getMarket(marketPubkey: string): Promise<MarketInfoResponse>;
102
- /**
103
- * Get market information by slug.
104
- *
105
- * @param slug - URL-friendly market slug
106
- * @returns Market details
107
- */
108
- getMarketBySlug(slug: string): Promise<MarketInfoResponse>;
109
- /**
110
- * Get deposit assets for a market.
111
- *
112
- * @param marketPubkey - Market PDA address (Base58)
113
- * @returns Deposit assets
114
- * @throws {ApiError} If marketPubkey is invalid
115
- */
116
- getDepositAssets(marketPubkey: string): Promise<DepositAssetsResponse>;
117
- /**
118
- * Get orderbook snapshot.
119
- *
120
- * @param orderbookId - Orderbook identifier
121
- * @param depth - Number of levels (default: 20)
122
- * @returns Orderbook snapshot
123
- */
124
- getOrderbook(orderbookId: string, depth?: number): Promise<OrderbookResponse>;
125
- /**
126
- * Submit a new order.
127
- *
128
- * @param request - Order details
129
- * @returns Order response with hash and fill info
130
- * @throws {ApiError} If any pubkey or signature is invalid
131
- */
132
- submitOrder(request: SubmitOrderRequest): Promise<OrderResponse>;
133
- /**
134
- * Cancel an order with a pre-computed signature.
135
- *
136
- * @param orderHash - Hash of the order to cancel (hex)
137
- * @param maker - Order creator's pubkey (Base58)
138
- * @param signature - Ed25519 signature over the order hash (hex, 128 chars)
139
- * @returns Cancel response
140
- * @throws {ApiError} If maker pubkey or signature is invalid
141
- */
142
- cancelOrderWithSignature(orderHash: string, maker: string, signature: string): Promise<CancelResponse>;
143
- /**
144
- * Cancel an order, auto-signing with the given keypair.
145
- *
146
- * @param orderHash - Hash of the order to cancel (hex)
147
- * @param signer - Keypair to sign the cancellation
148
- * @returns Cancel response
149
- */
150
- cancelOrder(orderHash: string, signer: Keypair): Promise<CancelResponse>;
151
- /**
152
- * Cancel all orders for a user with a pre-computed signature.
153
- *
154
- * @param userPubkey - User's public key (Base58)
155
- * @param signature - Ed25519 signature over "cancel_all:{pubkey}:{timestamp}" (hex, 128 chars)
156
- * @param timestamp - Unix timestamp used in the signed message
157
- * @param orderbookId - Optional orderbook filter
158
- * @returns Cancel all response
159
- * @throws {ApiError} If any pubkey or signature is invalid
160
- */
161
- cancelAllOrdersWithSignature(userPubkey: string, signature: string, timestamp: number, orderbookId?: string): Promise<CancelAllResponse>;
162
- /**
163
- * Cancel all orders for a user, auto-signing with the given keypair.
164
- *
165
- * @param signer - Keypair to sign the cancellation
166
- * @param orderbookId - Optional orderbook filter
167
- * @returns Cancel all response
168
- */
169
- cancelAllOrders(signer: Keypair, orderbookId?: string): Promise<CancelAllResponse>;
170
- /**
171
- * Get user positions across all markets.
172
- *
173
- * @param userPubkey - User's public key (Base58)
174
- * @returns User positions
175
- * @throws {ApiError} If userPubkey is invalid
176
- */
177
- getUserPositions(userPubkey: string): Promise<PositionsResponse>;
178
- /**
179
- * Get user positions in a specific market.
180
- *
181
- * @param userPubkey - User's public key (Base58)
182
- * @param marketPubkey - Market PDA address (Base58)
183
- * @returns Market positions
184
- * @throws {ApiError} If any pubkey is invalid
185
- */
186
- getUserMarketPositions(userPubkey: string, marketPubkey: string): Promise<MarketPositionsResponse>;
187
- /**
188
- * Get user's open orders.
189
- *
190
- * @param userPubkey - User's public key (Base58)
191
- * @returns User orders and balances
192
- * @throws {ApiError} If userPubkey is invalid
193
- */
194
- getUserOrders(userPubkey: string): Promise<UserOrdersResponse>;
195
- /**
196
- * Get historical price data.
197
- *
198
- * @param params - Query parameters
199
- * @returns Price history data
200
- * @throws {ApiError} If limit is out of bounds (1-500)
201
- */
202
- getPriceHistory(params: PriceHistoryParams): Promise<PriceHistoryResponse>;
203
- /**
204
- * Get recent trades.
205
- *
206
- * @param params - Query parameters
207
- * @returns Trade history
208
- * @throws {ApiError} If limit is out of bounds (1-500)
209
- */
210
- getTrades(params: TradesParams): Promise<TradesResponse>;
211
- /**
212
- * Admin health check.
213
- *
214
- * @returns Admin status
215
- */
216
- adminHealthCheck(): Promise<AdminResponse>;
217
- /**
218
- * Create a new orderbook (admin only).
219
- *
220
- * @param request - Orderbook creation request
221
- * @returns Created orderbook info
222
- */
223
- createOrderbook(request: CreateOrderbookRequest): Promise<CreateOrderbookResponse>;
224
- }
225
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAS1C,OAAO,EAAgB,KAAK,eAAe,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EAEb,cAAc,EAEd,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACZ,cAAc,EACd,aAAa,EACb,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,SAAS,CAAC;AAkBjB,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,+DAA+D;IAC/D,UAAU,EAAE,MAAM,CAAC;IACnB,mDAAmD;IACnD,WAAW,EAAE,MAAM,CAAC;IACpB,yDAAyD;IACzD,UAAU,EAAE,MAAM,CAAC;CACpB;AAED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