investing 0.1.309 → 0.1.310

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 (286) hide show
  1. package/README.md +167 -123
  2. package/THIRD_PARTY_NOTICES.md +144 -0
  3. package/dist/{archiver-web.es-B69gABHP.js → archiver-web.es-C5dgnXMM.js} +1 -1
  4. package/dist/{archiver-web.es-fg4bLLZa.cjs → archiver-web.es-DLoy_R54.cjs} +1 -1
  5. package/dist/db/index.d.ts +189 -0
  6. package/dist/db/index.d.ts.map +1 -1
  7. package/dist/db/schema.d.ts +200 -0
  8. package/dist/db/schema.d.ts.map +1 -1
  9. package/dist/index-6F5HGB0V.js +15 -0
  10. package/dist/index-kfghRBr2.cjs +13 -0
  11. package/dist/index.d.ts +2 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +1 -1
  14. package/dist/index.mjs +1 -1
  15. package/dist/leaders/zulu.d.ts +35 -5
  16. package/dist/leaders/zulu.d.ts.map +1 -1
  17. package/dist/live-data/dukascopy-client.d.ts +19 -2
  18. package/dist/live-data/dukascopy-client.d.ts.map +1 -1
  19. package/dist/llm/debate-generator.d.ts +7 -0
  20. package/dist/llm/debate-generator.d.ts.map +1 -1
  21. package/dist/prediction/analysis/polymarket-wallet-trust.d.ts +60 -0
  22. package/dist/prediction/analysis/polymarket-wallet-trust.d.ts.map +1 -0
  23. package/dist/prediction/analysis/position-reconstruction.d.ts +130 -0
  24. package/dist/prediction/analysis/position-reconstruction.d.ts.map +1 -0
  25. package/dist/prediction/analysis/position-settlement.d.ts +99 -0
  26. package/dist/prediction/analysis/position-settlement.d.ts.map +1 -0
  27. package/dist/prediction/analysis/r-multiple.d.ts +159 -0
  28. package/dist/prediction/analysis/r-multiple.d.ts.map +1 -0
  29. package/dist/prediction/analysis/trust-score.d.ts +158 -0
  30. package/dist/prediction/analysis/trust-score.d.ts.map +1 -0
  31. package/dist/prediction/api/analytics.d.ts.map +1 -1
  32. package/dist/prediction/api/leaderboard.d.ts +29 -11
  33. package/dist/prediction/api/leaderboard.d.ts.map +1 -1
  34. package/dist/prediction/api/markets.d.ts.map +1 -1
  35. package/dist/prediction/api/prices.d.ts.map +1 -1
  36. package/dist/prediction/db/markets.d.ts +13 -0
  37. package/dist/prediction/db/markets.d.ts.map +1 -1
  38. package/dist/prediction/db/trade-history.d.ts +35 -0
  39. package/dist/prediction/db/trade-history.d.ts.map +1 -1
  40. package/dist/prediction/index.d.ts +7 -0
  41. package/dist/prediction/index.d.ts.map +1 -1
  42. package/dist/prediction/sync/incremental-markets.d.ts.map +1 -1
  43. package/dist/prediction/sync/leaderboard.d.ts +1 -1
  44. package/dist/prediction/sync/leaderboard.d.ts.map +1 -1
  45. package/dist/prediction/sync/markets.d.ts +2 -2
  46. package/dist/prediction/sync/markets.d.ts.map +1 -1
  47. package/dist/prediction/sync/orchestration.d.ts +1 -1
  48. package/dist/prediction/sync/refill-limits.d.ts +9 -0
  49. package/dist/prediction/sync/refill-limits.d.ts.map +1 -0
  50. package/dist/prediction/sync/refill.d.ts +34 -0
  51. package/dist/prediction/sync/refill.d.ts.map +1 -0
  52. package/dist/prediction/sync/trade-history.d.ts.map +1 -1
  53. package/dist/prediction/utils/token-ids.d.ts +17 -0
  54. package/dist/prediction/utils/token-ids.d.ts.map +1 -0
  55. package/dist/prediction-markets/adapters/trading-agents.d.ts +21 -0
  56. package/dist/prediction-markets/adapters/trading-agents.d.ts.map +1 -0
  57. package/dist/prediction-markets/agents/bookmaker-agent.d.ts.map +1 -0
  58. package/dist/prediction-markets/agents/event-analysis-agent.d.ts.map +1 -0
  59. package/dist/{predictos → prediction-markets}/agents/index.d.ts +5 -1
  60. package/dist/prediction-markets/agents/index.d.ts.map +1 -0
  61. package/dist/prediction-markets/agents/kalshi-momentum-agent.d.ts +7 -0
  62. package/dist/prediction-markets/agents/kalshi-momentum-agent.d.ts.map +1 -0
  63. package/dist/prediction-markets/agents/mapper-agent.d.ts.map +1 -0
  64. package/dist/{predictos → prediction-markets}/agents/polyfactual-research.d.ts +1 -1
  65. package/dist/prediction-markets/agents/polyfactual-research.d.ts.map +1 -0
  66. package/dist/prediction-markets/agents/polymarket-position-tracker.d.ts.map +1 -0
  67. package/dist/{predictos → prediction-markets}/agents/polymarket-put-order.d.ts +1 -1
  68. package/dist/prediction-markets/agents/polymarket-put-order.d.ts.map +1 -0
  69. package/dist/prediction-markets/agents/polymarket-updown-15-limit-order-bot.d.ts.map +1 -0
  70. package/dist/prediction-markets/agents/x402-seller.d.ts.map +1 -0
  71. package/dist/prediction-markets/ai/callBlockRun.d.ts.map +1 -0
  72. package/dist/prediction-markets/ai/callGrok.d.ts.map +1 -0
  73. package/dist/prediction-markets/ai/callOpenAI.d.ts.map +1 -0
  74. package/dist/prediction-markets/ai/http.d.ts.map +1 -0
  75. package/dist/{predictos → prediction-markets}/ai/index.d.ts +1 -1
  76. package/dist/prediction-markets/ai/index.d.ts.map +1 -0
  77. package/dist/prediction-markets/ai/prompts/analyzeEventMarkets.d.ts.map +1 -0
  78. package/dist/prediction-markets/ai/prompts/arbitrageAnalysis.d.ts.map +1 -0
  79. package/dist/prediction-markets/ai/prompts/bookmakerAnalysis.d.ts.map +1 -0
  80. package/dist/prediction-markets/ai/prompts/searchQueryGenerator.d.ts.map +1 -0
  81. package/dist/prediction-markets/ai/types.d.ts.map +1 -0
  82. package/dist/prediction-markets/arbitrage.d.ts.map +1 -0
  83. package/dist/{predictos → prediction-markets}/clients/polyfactual.d.ts +1 -1
  84. package/dist/prediction-markets/clients/polyfactual.d.ts.map +1 -0
  85. package/dist/{predictos → prediction-markets}/clients/polymarket.d.ts +1 -1
  86. package/dist/prediction-markets/clients/polymarket.d.ts.map +1 -0
  87. package/dist/{predictos → prediction-markets}/clients/x402.d.ts +1 -1
  88. package/dist/prediction-markets/clients/x402.d.ts.map +1 -0
  89. package/dist/{predictos → prediction-markets}/data/kalshi.d.ts +1 -1
  90. package/dist/prediction-markets/data/kalshi.d.ts.map +1 -0
  91. package/dist/{predictos → prediction-markets}/data/polymarket.d.ts +1 -1
  92. package/dist/prediction-markets/data/polymarket.d.ts.map +1 -0
  93. package/dist/prediction-markets/events.d.ts.map +1 -0
  94. package/dist/prediction-markets/execution/paper.d.ts +19 -0
  95. package/dist/prediction-markets/execution/paper.d.ts.map +1 -0
  96. package/dist/prediction-markets/index.cjs +1 -0
  97. package/dist/{predictos → prediction-markets}/index.d.ts +8 -5
  98. package/dist/prediction-markets/index.d.ts.map +1 -0
  99. package/dist/prediction-markets/index.mjs +1 -0
  100. package/dist/prediction-markets/kalshi-momentum.LICENSE +21 -0
  101. package/dist/prediction-markets/strategies/btc15m-fusion.d.ts +27 -0
  102. package/dist/prediction-markets/strategies/btc15m-fusion.d.ts.map +1 -0
  103. package/dist/prediction-markets/strategies/copy-trade-sizing.d.ts +27 -0
  104. package/dist/prediction-markets/strategies/copy-trade-sizing.d.ts.map +1 -0
  105. package/dist/prediction-markets/strategies/gabagool.d.ts +26 -0
  106. package/dist/prediction-markets/strategies/gabagool.d.ts.map +1 -0
  107. package/dist/prediction-markets/strategies/kalshi-momentum.d.ts +13 -0
  108. package/dist/prediction-markets/strategies/kalshi-momentum.d.ts.map +1 -0
  109. package/dist/{predictos → prediction-markets}/types.d.ts +121 -6
  110. package/dist/prediction-markets/types.d.ts.map +1 -0
  111. package/dist/prediction-markets/validation.d.ts +5 -0
  112. package/dist/prediction-markets/validation.d.ts.map +1 -0
  113. package/dist/scripted-llm-B-UTs08L.js +1 -0
  114. package/dist/scripted-llm-CmDVkhyH.cjs +1 -0
  115. package/dist/stocks/index.d.ts +2 -1
  116. package/dist/stocks/index.d.ts.map +1 -1
  117. package/dist/stocks/quote-cache-service.d.ts +11 -2
  118. package/dist/stocks/quote-cache-service.d.ts.map +1 -1
  119. package/dist/stocks/strategies/bb-rsi-breakout.d.ts +63 -0
  120. package/dist/stocks/strategies/bb-rsi-breakout.d.ts.map +1 -0
  121. package/dist/stocks/strategies/ema-crossover.d.ts +51 -0
  122. package/dist/stocks/strategies/ema-crossover.d.ts.map +1 -0
  123. package/dist/stocks/unified-quote-service.d.ts +15 -6
  124. package/dist/stocks/unified-quote-service.d.ts.map +1 -1
  125. package/dist/stocks/yahoo-finance-wrapper.d.ts +75 -6
  126. package/dist/stocks/yahoo-finance-wrapper.d.ts.map +1 -1
  127. package/dist/strategy-signals/data/fixture-data-provider.d.ts +8 -0
  128. package/dist/strategy-signals/data/fixture-data-provider.d.ts.map +1 -0
  129. package/dist/strategy-signals/data/openbb-mapping.d.ts +7 -0
  130. package/dist/strategy-signals/data/openbb-mapping.d.ts.map +1 -0
  131. package/dist/strategy-signals/demo.d.ts +446 -0
  132. package/dist/strategy-signals/demo.d.ts.map +1 -0
  133. package/dist/strategy-signals/execution.d.ts +18 -0
  134. package/dist/strategy-signals/execution.d.ts.map +1 -0
  135. package/dist/strategy-signals/fixtures/openbb-data/bars.d.ts +10 -0
  136. package/dist/strategy-signals/fixtures/openbb-data/bars.d.ts.map +1 -0
  137. package/dist/strategy-signals/index.d.ts +36 -0
  138. package/dist/strategy-signals/index.d.ts.map +1 -0
  139. package/dist/strategy-signals/indicators/spread-aware-momentum.d.ts +31 -0
  140. package/dist/strategy-signals/indicators/spread-aware-momentum.d.ts.map +1 -0
  141. package/dist/strategy-signals/proposal.d.ts +10 -0
  142. package/dist/strategy-signals/proposal.d.ts.map +1 -0
  143. package/dist/strategy-signals/report.d.ts +6 -0
  144. package/dist/strategy-signals/report.d.ts.map +1 -0
  145. package/dist/strategy-signals/risk-gate.d.ts +3 -0
  146. package/dist/strategy-signals/risk-gate.d.ts.map +1 -0
  147. package/dist/strategy-signals/sources/btc15m-fusion.d.ts +16 -0
  148. package/dist/strategy-signals/sources/btc15m-fusion.d.ts.map +1 -0
  149. package/dist/strategy-signals/sources/copy-trade-sizing.d.ts +15 -0
  150. package/dist/strategy-signals/sources/copy-trade-sizing.d.ts.map +1 -0
  151. package/dist/strategy-signals/sources/gabagool.d.ts +12 -0
  152. package/dist/strategy-signals/sources/gabagool.d.ts.map +1 -0
  153. package/dist/strategy-signals/sources/hedge-fund-technicals.d.ts +42 -0
  154. package/dist/strategy-signals/sources/hedge-fund-technicals.d.ts.map +1 -0
  155. package/dist/strategy-signals/sources/kalshi-momentum.d.ts +10 -0
  156. package/dist/strategy-signals/sources/kalshi-momentum.d.ts.map +1 -0
  157. package/dist/strategy-signals/sources/kalshi-vibe-guards.d.ts +15 -0
  158. package/dist/strategy-signals/sources/kalshi-vibe-guards.d.ts.map +1 -0
  159. package/dist/strategy-signals/sources/kalshi-vibe.d.ts +11 -0
  160. package/dist/strategy-signals/sources/kalshi-vibe.d.ts.map +1 -0
  161. package/dist/strategy-signals/sources/red-flags.d.ts +13 -0
  162. package/dist/strategy-signals/sources/red-flags.d.ts.map +1 -0
  163. package/dist/strategy-signals/sources/spread-aware-momentum.d.ts +11 -0
  164. package/dist/strategy-signals/sources/spread-aware-momentum.d.ts.map +1 -0
  165. package/dist/strategy-signals/survival-posture.d.ts +13 -0
  166. package/dist/strategy-signals/survival-posture.d.ts.map +1 -0
  167. package/dist/strategy-signals/types.d.ts +138 -0
  168. package/dist/strategy-signals/types.d.ts.map +1 -0
  169. package/dist/strategy-signals/validate.d.ts +15 -0
  170. package/dist/strategy-signals/validate.d.ts.map +1 -0
  171. package/dist/strategy-signals/venues/kalshi-venue-mapping.d.ts +3 -0
  172. package/dist/strategy-signals/venues/kalshi-venue-mapping.d.ts.map +1 -0
  173. package/dist/strategy-signals/venues/mock-equity-broker.d.ts +16 -0
  174. package/dist/strategy-signals/venues/mock-equity-broker.d.ts.map +1 -0
  175. package/dist/strategy-signals/venues/mock-venue.d.ts +14 -0
  176. package/dist/strategy-signals/venues/mock-venue.d.ts.map +1 -0
  177. package/dist/strategy-signals/venues/pmxt-venue-mapping.d.ts +7 -0
  178. package/dist/strategy-signals/venues/pmxt-venue-mapping.d.ts.map +1 -0
  179. package/dist/trading-agents/agents/debate-facilitator.d.ts +3 -3
  180. package/dist/trading-agents/agents/debate-facilitator.d.ts.map +1 -1
  181. package/dist/trading-agents/agents/fund-manager.d.ts +4 -2
  182. package/dist/trading-agents/agents/fund-manager.d.ts.map +1 -1
  183. package/dist/trading-agents/agents/improved-researchers.d.ts +3 -3
  184. package/dist/trading-agents/agents/improved-researchers.d.ts.map +1 -1
  185. package/dist/trading-agents/agents/market-analyst.d.ts +2 -2
  186. package/dist/trading-agents/agents/market-analyst.d.ts.map +1 -1
  187. package/dist/trading-agents/agents/news-analyst.d.ts +2 -2
  188. package/dist/trading-agents/agents/news-analyst.d.ts.map +1 -1
  189. package/dist/trading-agents/agents/researchers.d.ts +4 -4
  190. package/dist/trading-agents/agents/researchers.d.ts.map +1 -1
  191. package/dist/trading-agents/agents/risk-judge.d.ts +13 -0
  192. package/dist/trading-agents/agents/risk-judge.d.ts.map +1 -0
  193. package/dist/trading-agents/agents/risk-team.d.ts +4 -4
  194. package/dist/trading-agents/agents/risk-team.d.ts.map +1 -1
  195. package/dist/trading-agents/agents/trader.d.ts +2 -2
  196. package/dist/trading-agents/agents/trader.d.ts.map +1 -1
  197. package/dist/trading-agents/graph/trading-graph.d.ts +28 -2
  198. package/dist/trading-agents/graph/trading-graph.d.ts.map +1 -1
  199. package/dist/trading-agents/index.cjs +1 -0
  200. package/dist/trading-agents/index.d.ts +4 -0
  201. package/dist/trading-agents/index.d.ts.map +1 -1
  202. package/dist/trading-agents/index.mjs +1 -0
  203. package/dist/trading-agents/types/index.d.ts +27 -4
  204. package/dist/trading-agents/types/index.d.ts.map +1 -1
  205. package/dist/trading-agents/utils/llm-client.d.ts +4 -1
  206. package/dist/trading-agents/utils/llm-client.d.ts.map +1 -1
  207. package/dist/trading-agents/utils/parse-final-line.d.ts +7 -0
  208. package/dist/trading-agents/utils/parse-final-line.d.ts.map +1 -0
  209. package/dist/trading-agents/utils/scripted-llm.d.ts +17 -0
  210. package/dist/trading-agents/utils/scripted-llm.d.ts.map +1 -0
  211. package/dist/trading-agents/utils/strategy-prompt.d.ts +6 -0
  212. package/dist/trading-agents/utils/strategy-prompt.d.ts.map +1 -0
  213. package/dist/trading-agents-Bh9OORHe.js +1 -0
  214. package/dist/trading-agents-C8M7tbB0.cjs +1 -0
  215. package/dist/validate-C1MS8RhG.js +1 -0
  216. package/dist/validate-DBxPUXqH.cjs +1 -0
  217. package/package.json +21 -50
  218. package/dist/bookmakerAnalysis-Bfo1zUVm.js +0 -1
  219. package/dist/bookmakerAnalysis-CHn1W8uX.cjs +0 -1
  220. package/dist/callGrok-D0D7zBHK.js +0 -1
  221. package/dist/callGrok-DWO719mN.cjs +0 -1
  222. package/dist/events-BJOyGWeU.cjs +0 -1
  223. package/dist/events-OvBb8rgy.js +0 -1
  224. package/dist/index-D7fsk2gy.js +0 -15
  225. package/dist/index-_V1Ql5Es.cjs +0 -13
  226. package/dist/polymarket-updown-15-limit-order-bot-DCC8HE9Z.cjs +0 -1
  227. package/dist/polymarket-updown-15-limit-order-bot-Dv5oGAF4.js +0 -1
  228. package/dist/predictos/agents/bookmaker-agent.d.ts.map +0 -1
  229. package/dist/predictos/agents/event-analysis-agent.d.ts.map +0 -1
  230. package/dist/predictos/agents/index.d.ts.map +0 -1
  231. package/dist/predictos/agents/index.js +0 -1
  232. package/dist/predictos/agents/index.mjs +0 -1
  233. package/dist/predictos/agents/mapper-agent.d.ts.map +0 -1
  234. package/dist/predictos/agents/polyfactual-research.d.ts.map +0 -1
  235. package/dist/predictos/agents/polymarket-position-tracker.d.ts.map +0 -1
  236. package/dist/predictos/agents/polymarket-put-order.d.ts.map +0 -1
  237. package/dist/predictos/agents/polymarket-updown-15-limit-order-bot.d.ts.map +0 -1
  238. package/dist/predictos/agents/x402-seller.d.ts.map +0 -1
  239. package/dist/predictos/ai/callBlockRun.d.ts.map +0 -1
  240. package/dist/predictos/ai/callGrok.d.ts.map +0 -1
  241. package/dist/predictos/ai/callOpenAI.d.ts.map +0 -1
  242. package/dist/predictos/ai/http.d.ts.map +0 -1
  243. package/dist/predictos/ai/index.d.ts.map +0 -1
  244. package/dist/predictos/ai/index.js +0 -1
  245. package/dist/predictos/ai/index.mjs +0 -1
  246. package/dist/predictos/ai/prompts/analyzeEventMarkets.d.ts.map +0 -1
  247. package/dist/predictos/ai/prompts/arbitrageAnalysis.d.ts.map +0 -1
  248. package/dist/predictos/ai/prompts/bookmakerAnalysis.d.ts.map +0 -1
  249. package/dist/predictos/ai/prompts/searchQueryGenerator.d.ts.map +0 -1
  250. package/dist/predictos/ai/types.d.ts.map +0 -1
  251. package/dist/predictos/arbitrage.d.ts.map +0 -1
  252. package/dist/predictos/arbitrage.js +0 -1
  253. package/dist/predictos/arbitrage.mjs +0 -1
  254. package/dist/predictos/clients/polyfactual.d.ts.map +0 -1
  255. package/dist/predictos/clients/polymarket.d.ts.map +0 -1
  256. package/dist/predictos/clients/x402.d.ts.map +0 -1
  257. package/dist/predictos/data/kalshi.d.ts.map +0 -1
  258. package/dist/predictos/data/kalshi.js +0 -1
  259. package/dist/predictos/data/kalshi.mjs +0 -1
  260. package/dist/predictos/data/polymarket.d.ts.map +0 -1
  261. package/dist/predictos/data/polymarket.js +0 -1
  262. package/dist/predictos/data/polymarket.mjs +0 -1
  263. package/dist/predictos/events.d.ts.map +0 -1
  264. package/dist/predictos/index.d.ts.map +0 -1
  265. package/dist/predictos/index.js +0 -1
  266. package/dist/predictos/index.mjs +0 -1
  267. package/dist/predictos/types.d.ts.map +0 -1
  268. package/dist/searchQueryGenerator-DIIs9xw5.js +0 -1
  269. package/dist/searchQueryGenerator-rCVblXJS.cjs +0 -1
  270. /package/dist/{predictos → prediction-markets}/agents/bookmaker-agent.d.ts +0 -0
  271. /package/dist/{predictos → prediction-markets}/agents/event-analysis-agent.d.ts +0 -0
  272. /package/dist/{predictos → prediction-markets}/agents/mapper-agent.d.ts +0 -0
  273. /package/dist/{predictos → prediction-markets}/agents/polymarket-position-tracker.d.ts +0 -0
  274. /package/dist/{predictos → prediction-markets}/agents/polymarket-updown-15-limit-order-bot.d.ts +0 -0
  275. /package/dist/{predictos → prediction-markets}/agents/x402-seller.d.ts +0 -0
  276. /package/dist/{predictos → prediction-markets}/ai/callBlockRun.d.ts +0 -0
  277. /package/dist/{predictos → prediction-markets}/ai/callGrok.d.ts +0 -0
  278. /package/dist/{predictos → prediction-markets}/ai/callOpenAI.d.ts +0 -0
  279. /package/dist/{predictos → prediction-markets}/ai/http.d.ts +0 -0
  280. /package/dist/{predictos → prediction-markets}/ai/prompts/analyzeEventMarkets.d.ts +0 -0
  281. /package/dist/{predictos → prediction-markets}/ai/prompts/arbitrageAnalysis.d.ts +0 -0
  282. /package/dist/{predictos → prediction-markets}/ai/prompts/bookmakerAnalysis.d.ts +0 -0
  283. /package/dist/{predictos → prediction-markets}/ai/prompts/searchQueryGenerator.d.ts +0 -0
  284. /package/dist/{predictos → prediction-markets}/ai/types.d.ts +0 -0
  285. /package/dist/{predictos → prediction-markets}/arbitrage.d.ts +0 -0
  286. /package/dist/{predictos → prediction-markets}/events.d.ts +0 -0
@@ -0,0 +1,159 @@
1
+ /**
2
+ * R-multiple conversion for resolved prediction-market positions.
3
+ *
4
+ * A pure, deterministic utility that turns a list of already-reconstructed,
5
+ * fully-realized positions into the per-trade R-multiples consumed by
6
+ * {@link computeForecasterTrustScore} (see `./trust-score.ts`). An R-multiple
7
+ * expresses a position's realized profit or loss in units of the risk taken:
8
+ *
9
+ * R = netRealizedPnl / initialRisk
10
+ *
11
+ * where `initialRisk` is the net premium paid to open the position (the most
12
+ * that can be lost, since a prediction-market share's downside is bounded at
13
+ * zero). A position that loses its entire stake therefore scores exactly -1R,
14
+ * matching the research paper's convention (§3.2).
15
+ *
16
+ * BOUNDARY: this module sits at the clean edge of the pipeline. It performs NO
17
+ * I/O, DB, network, or clock access; it does NOT reconstruct positions from raw
18
+ * trade history, ingest settlement/redemption events, impute resolution
19
+ * outcomes, size positions, or place orders. All of that is upstream, impure
20
+ * work that produces the {@link ResolvedPosition} array this function consumes.
21
+ * A `cutoff` is passed in, never read from the system clock, so the function
22
+ * stays referentially transparent and leak-free: a Trust Score at a historical
23
+ * cutoff must only see outcomes known by that cutoff, and the caller enforces
24
+ * that by supplying the cutoff here.
25
+ *
26
+ * Error philosophy mirrors `trust-score.ts`: malformed INPUT SHAPES throw
27
+ * (programmer error), while DATA-QUALITY problems in otherwise well-formed
28
+ * records (unresolved, non-finite financials, non-positive risk, timestamps
29
+ * after the cutoff) are reported as soft exclusions, never thrown and never
30
+ * silently coerced. Every value in the returned `rMultiples` is a finite
31
+ * number, so the downstream Trust Score never has to defend against NaN/Infinity.
32
+ */
33
+ /** Why a {@link ResolvedPosition} was dropped from the R-multiple sample. */
34
+ export type RMultipleExclusionReason =
35
+ /** `resolved === false`: the position is still open / not yet realized. */
36
+ "unresolved"
37
+ /**
38
+ * `initialRisk` is at or below the accepted floor (`<= minInitialRisk`,
39
+ * default `0`). Includes the zero-risk divide-by-zero case; no R is emitted
40
+ * rather than an infinite one.
41
+ */
42
+ | "non-positive-risk"
43
+ /**
44
+ * `netRealizedPnl` or `initialRisk` is not a finite number, or the computed
45
+ * R-multiple overflowed to a non-finite value.
46
+ */
47
+ | "non-finite"
48
+ /**
49
+ * A `cutoff` was supplied but the position's `resolutionTimestamp` is `null`
50
+ * or non-finite, so it cannot be placed relative to the cutoff.
51
+ */
52
+ | "missing-timestamp"
53
+ /**
54
+ * A `cutoff` was supplied and `resolutionTimestamp > cutoff`: the outcome was
55
+ * not known by the cutoff, so including it would leak future information.
56
+ */
57
+ | "after-cutoff";
58
+ /** Every exclusion reason, in a fixed order, for zero-filling tallies. */
59
+ export declare const R_MULTIPLE_EXCLUSION_REASONS: readonly RMultipleExclusionReason[];
60
+ /**
61
+ * One completed (fully realized) prediction-market position, already netted by
62
+ * the upstream impure adapter. The YES/NO distinction does not appear here: it
63
+ * is folded into the signed `netRealizedPnl` and the `initialRisk` before this
64
+ * function sees it.
65
+ */
66
+ export interface ResolvedPosition {
67
+ /** Stable identifier, e.g. `${trader}:${conditionId}:${outcomeIndex}`. */
68
+ positionId: string;
69
+ /**
70
+ * Net realized profit or loss in USDC: sale proceeds + settlement redemptions
71
+ * minus entry cost minus fees. May be negative, or exactly `0` (break-even).
72
+ */
73
+ netRealizedPnl: number;
74
+ /**
75
+ * Initial risk in USDC: the net premium paid to open the position. Must be
76
+ * strictly positive (and above `minInitialRisk`) to be usable as the R
77
+ * denominator.
78
+ */
79
+ initialRisk: number;
80
+ /**
81
+ * Whether the position's P&L is fully realized — either the market settled at
82
+ * resolution or the position was fully exited early. Open positions
83
+ * (`false`) are never scored.
84
+ */
85
+ resolved: boolean;
86
+ /**
87
+ * Epoch seconds at which the realized P&L became known (settlement time, or
88
+ * the final exit trade's time). Required (finite) for cutoff gating; `null`
89
+ * when the position is unresolved or the time is unknown.
90
+ */
91
+ resolutionTimestamp: number | null;
92
+ }
93
+ /** A single dropped position and the reason it was dropped. */
94
+ export interface ExcludedPosition {
95
+ positionId: string;
96
+ /** The reason; never the implicit "included" state. */
97
+ reason: RMultipleExclusionReason;
98
+ }
99
+ /** Options for {@link rMultiplesFromResolvedPositions}. */
100
+ export interface RMultipleOptions {
101
+ /**
102
+ * Historical cutoff in epoch seconds. When supplied, only positions whose
103
+ * `resolutionTimestamp` is finite and `<= cutoff` are included; the rest are
104
+ * excluded as `after-cutoff` or `missing-timestamp`. Omitted means no gate.
105
+ */
106
+ cutoff?: number;
107
+ /**
108
+ * Exclusive lower bound on `initialRisk` (USDC). A position is usable only
109
+ * when `initialRisk > minInitialRisk`. Defaults to `0`, so any strictly
110
+ * positive risk is accepted. Must be a finite, non-negative number.
111
+ */
112
+ minInitialRisk?: number;
113
+ }
114
+ /** Result of {@link rMultiplesFromResolvedPositions}. */
115
+ export interface RMultipleConversion {
116
+ /**
117
+ * Finite R-multiples for the included positions, in the order they appeared
118
+ * in the input. Ready to pass straight to `computeForecasterTrustScore`.
119
+ */
120
+ rMultiples: number[];
121
+ /** Number of included positions; always equals `rMultiples.length`. */
122
+ included: number;
123
+ /** One entry per dropped position, in input order, with its reason. */
124
+ excluded: ExcludedPosition[];
125
+ /**
126
+ * Count of exclusions per reason. Every {@link RMultipleExclusionReason} key
127
+ * is present and zero-filled, so callers can read any reason without a guard.
128
+ */
129
+ excludedCounts: Record<RMultipleExclusionReason, number>;
130
+ }
131
+ /**
132
+ * Converts resolved prediction-market positions into per-position R-multiples,
133
+ * reporting every position that is dropped and why.
134
+ *
135
+ * Soft exclusions are evaluated in a fixed precedence; the first failing check
136
+ * wins, so each dropped position carries exactly one reason:
137
+ * 1. `unresolved` — `resolved === false`.
138
+ * 2. `missing-timestamp` — a `cutoff` is set but `resolutionTimestamp` is
139
+ * `null`/non-finite.
140
+ * 3. `after-cutoff` — a `cutoff` is set and `resolutionTimestamp > cutoff`.
141
+ * 4. `non-finite` (risk) — `initialRisk` is NaN or ±Infinity (checked before
142
+ * the threshold, so `+Infinity` cannot slip through).
143
+ * 5. `non-positive-risk` — finite `initialRisk <= minInitialRisk`.
144
+ * 6. `non-finite` (P&L) — `netRealizedPnl` is NaN or ±Infinity.
145
+ * 7. `non-finite` (R) — the finite division overflowed to a non-finite R.
146
+ *
147
+ * @param positions - Completed positions produced by the upstream adapter.
148
+ * @param options - See {@link RMultipleOptions}.
149
+ * @returns A {@link RMultipleConversion}: the finite R-multiples (input order),
150
+ * the included count, the excluded positions with reasons, and a zero-filled
151
+ * per-reason tally.
152
+ * @throws {TypeError} If `positions` is not an array, or any element is not a
153
+ * well-formed {@link ResolvedPosition} (missing/ wrong-typed `positionId`,
154
+ * `netRealizedPnl`, `initialRisk`, `resolved`, or `resolutionTimestamp`).
155
+ * @throws {RangeError} If `cutoff` is supplied and is not finite, or
156
+ * `minInitialRisk` is supplied and is not a finite, non-negative number.
157
+ */
158
+ export declare function rMultiplesFromResolvedPositions(positions: readonly ResolvedPosition[], options?: RMultipleOptions): RMultipleConversion;
159
+ //# sourceMappingURL=r-multiple.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"r-multiple.d.ts","sourceRoot":"","sources":["../../../src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+BAA+B,CAC7C,SAAS,EAAE,SAAS,gBAAgB,EAAE,EACtC,OAAO,GAAE,gBAAqB,GAC7B,mBAAmB,CA2GrB"}
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Forecaster Trust Score.
3
+ *
4
+ * A pure, deterministic implementation of the "Forecaster Trust Score"
5
+ * described in the AI Broker research paper
6
+ * (`apps/ai-broker-web/content/docs/agents/ai-broker-research-paper.md`, §3.2),
7
+ * which extends the per-trade Sharpe ratio with a sample-size confidence term so
8
+ * that a long, consistent track record is trusted more than a short, lucky one.
9
+ *
10
+ * Stated formula (paper §3.2):
11
+ *
12
+ * Trust = (meanR / stdR) * sqrt(N)
13
+ *
14
+ * where
15
+ * - meanR = mean R-multiple per resolved trade (edge per unit of risk),
16
+ * - stdR = standard deviation of R-multiples (consistency),
17
+ * - N = number of resolved trades (sample size).
18
+ *
19
+ * The leading `meanR / stdR` factor is the per-trade Sharpe ratio; `sqrt(N)` is
20
+ * the standard-error amplification that rewards larger samples. A forecaster
21
+ * with zero mean R-multiple scores zero regardless of N (paper §3.2.3), which is
22
+ * the no-edge baseline that distinguishes skill from luck.
23
+ *
24
+ * This module only computes the score. It deliberately does NOT read trades from
25
+ * a database or API, resolve markets, size positions, or place orders — it is a
26
+ * self-contained numeric function with no network, no clock, and no execution
27
+ * side effects, so it can be unit-tested and reasoned about in isolation.
28
+ *
29
+ * NOTE ON THE PAPER'S WORKED TABLE: the example table in §3.2 (forecasters
30
+ * P1–P10) is internally inconsistent for three rows. P5, P6 and P7 print a
31
+ * `Trust` value that disagrees with the paper's own `Sharpe` column and with the
32
+ * stated formula `Sharpe * sqrt(N)` (e.g. P7: 0.46 * sqrt(120) = 5.07, not the
33
+ * printed 4.00). The other seven rows agree with the formula to within rounding.
34
+ * This implementation follows the stated formula; the test file documents each
35
+ * discrepancy explicitly.
36
+ */
37
+ /** Why a score is (or is not) reliable. See {@link ForecasterTrustScore}. */
38
+ export type TrustScoreReason =
39
+ /** Score computed and sample size meets the minimum — safe to rely on. */
40
+ "ok"
41
+ /** No trades supplied; nothing to score. */
42
+ | "empty"
43
+ /** Score computed, but fewer than `minSampleSize` trades — treat as weak. */
44
+ | "insufficient-sample"
45
+ /**
46
+ * R-multiples have zero dispersion while the mean is non-zero, so the
47
+ * Sharpe ratio (and therefore the score) is undefined rather than infinite.
48
+ */
49
+ | "zero-variance"
50
+ /**
51
+ * R-multiples have zero dispersion AND a zero mean (every trade identical,
52
+ * e.g. an all-zero / all-break-even history). There is no edge and no spread
53
+ * to measure, so this carries no information — not a reliable zero.
54
+ */
55
+ | "no-information"
56
+ /**
57
+ * Inputs were individually finite but their sum or dispersion overflowed to
58
+ * a non-finite value, so no finite score exists.
59
+ */
60
+ | "overflow";
61
+ /** Options for {@link computeForecasterTrustScore}. */
62
+ export interface ForecasterTrustScoreOptions {
63
+ /**
64
+ * Minimum number of resolved trades for a score to be considered reliable.
65
+ * Defaults to 25, matching the `N >= 25` threshold used throughout the paper.
66
+ * A score is still computed below this, but is flagged `reliable: false`.
67
+ */
68
+ minSampleSize?: number;
69
+ /**
70
+ * Delta degrees of freedom for the standard deviation of R-multiples:
71
+ * - `1` (default): sample standard deviation (divides the sum of squared
72
+ * deviations by `N - 1`), matching the finance Sharpe-ratio convention the
73
+ * paper's Sharpe column is built on.
74
+ * - `0`: population standard deviation (divides by `N`).
75
+ * With a single trade (`N - ddof <= 0`) the dispersion is not estimable and is
76
+ * treated as zero variance.
77
+ */
78
+ ddof?: 0 | 1;
79
+ }
80
+ /** Result of {@link computeForecasterTrustScore}. */
81
+ export interface ForecasterTrustScore {
82
+ /**
83
+ * The Trust Score `(meanR / stdR) * sqrt(N)`, or `null` when it is not finitely
84
+ * defined (no trades, zero dispersion, or overflow). Never `NaN` or `Infinity`.
85
+ */
86
+ score: number | null;
87
+ /**
88
+ * Whether `score` is a finite number — i.e. the formula is mathematically
89
+ * defined for this input. Independent of sample size. Equivalent to
90
+ * `score !== null`.
91
+ */
92
+ isDefined: boolean;
93
+ /**
94
+ * Whether `sampleSize >= minSampleSize` — i.e. there is enough evidence to
95
+ * trust the number. Independent of whether the score is defined.
96
+ */
97
+ hasSufficientSample: boolean;
98
+ /**
99
+ * Safe to act on: `isDefined && hasSufficientSample`. A single flag for the
100
+ * common "should I use this?" check; inspect `isDefined` / `hasSufficientSample`
101
+ * (or `reason`) to see which condition failed.
102
+ */
103
+ reliable: boolean;
104
+ /** Number of resolved trades used (array length). */
105
+ sampleSize: number;
106
+ /** Mean R-multiple. `0` when there are no trades. */
107
+ meanR: number;
108
+ /** Standard deviation of R-multiples under `ddof`. `0` when undefined. */
109
+ stdR: number;
110
+ /** Per-trade Sharpe ratio `meanR / stdR`, or `null` when `stdR` is `0`. */
111
+ sharpe: number | null;
112
+ /** Machine-readable explanation of `score` / `reliable`. */
113
+ reason: TrustScoreReason;
114
+ /** The effective minimum sample size used for the reliability decision. */
115
+ minSampleSize: number;
116
+ }
117
+ /** Default minimum resolved-trade count for a reliable score (paper: N >= 25). */
118
+ export declare const DEFAULT_MIN_SAMPLE_SIZE = 25;
119
+ /**
120
+ * Computes the Trust Score directly from pre-aggregated moments.
121
+ *
122
+ * This is the exact formula `(meanR / stdR) * sqrt(sampleSize)` with safe
123
+ * handling of the degenerate cases, kept separate from
124
+ * {@link computeForecasterTrustScore} so callers that already have summary
125
+ * statistics (for example, the paper's worked table) can use it without
126
+ * reconstructing a per-trade array.
127
+ *
128
+ * @param meanR - Mean R-multiple.
129
+ * @param stdR - Standard deviation of R-multiples (must be `>= 0`).
130
+ * @param sampleSize - Number of resolved trades (non-negative integer).
131
+ * @returns The finite Trust Score, or `null` when it is undefined: no trades
132
+ * (`sampleSize === 0`) or zero dispersion (`stdR === 0`, including a zero mean
133
+ * — the t-statistic needs non-zero sample variance). A zero mean with POSITIVE
134
+ * variance scores `0` (no edge), per the paper. Never `NaN`/`Infinity`.
135
+ * @throws {TypeError} If any argument is not a finite number.
136
+ * @throws {RangeError} If `sampleSize` is negative or non-integer, or `stdR < 0`.
137
+ */
138
+ export declare function trustScoreFromMoments(meanR: number, stdR: number, sampleSize: number): number | null;
139
+ /**
140
+ * Computes a {@link ForecasterTrustScore} from a forecaster's resolved-trade
141
+ * R-multiples.
142
+ *
143
+ * Each element is one resolved trade's R-multiple (profit or loss expressed in
144
+ * units of the risk taken on that trade). The caller is responsible for turning
145
+ * raw trade history into R-multiples; this function performs no resolution,
146
+ * I/O, or time-dependent work.
147
+ *
148
+ * @param rMultiples - Finite R-multiples, one per resolved trade.
149
+ * @param options - See {@link ForecasterTrustScoreOptions}.
150
+ * @returns A fully populated {@link ForecasterTrustScore}. Insufficient evidence
151
+ * is reported via `reliable`/`reason`, never hidden behind a bare number.
152
+ * @throws {TypeError} If `rMultiples` is not an array or contains a non-finite
153
+ * value.
154
+ * @throws {RangeError} If `minSampleSize` is not a positive integer, or `ddof`
155
+ * is not `0` or `1`.
156
+ */
157
+ export declare function computeForecasterTrustScore(rMultiples: readonly number[], options?: ForecasterTrustScoreOptions): ForecasterTrustScore;
158
+ //# sourceMappingURL=trust-score.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trust-score.d.ts","sourceRoot":"","sources":["../../../src/prediction/analysis/trust-score.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,6EAA6E;AAC7E,MAAM,MAAM,gBAAgB;AAC1B,0EAA0E;AACxE,IAAI;AACN,4CAA4C;GAC1C,OAAO;AACT,6EAA6E;GAC3E,qBAAqB;AACvB;;;GAGG;GACD,eAAe;AACjB;;;;GAIG;GACD,gBAAgB;AAClB;;;GAGG;GACD,UAAU,CAAC;AAEf,uDAAuD;AACvD,MAAM,WAAW,2BAA2B;IAC1C;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;;;OAQG;IACH,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;CACd;AAED,qDAAqD;AACrD,MAAM,WAAW,oBAAoB;IACnC;;;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,EAAE,CAAC,CA4BtC;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,oBAgB1D;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,oBAgBxD;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,MAAM,oBAoBvD;AAED;;;GAGG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,MAAM,oBAoB1D"}
@@ -1,22 +1,40 @@
1
1
  import { PolymarketCategory } from '../constants';
2
+ export type LeaderboardTimePeriod = "all" | "1d" | "7d" | "30d";
3
+ /** Most rows the data-api leaderboard returns per request. */
4
+ export declare const LEADERBOARD_PAGE_LIMIT = 50;
5
+ /** Highest offset the data-api leaderboard accepts. */
6
+ export declare const LEADERBOARD_MAX_OFFSET = 1000;
2
7
  /**
3
- * Fetches the Polymarket leaderboard with top traders ranked by volume or PnL.
8
+ * Builds the data-api leaderboard URL. The API's enums are upper-case
9
+ * (`timePeriod=ALL`, `category=OVERALL`) and it rejects `limit` above 50 and
10
+ * `offset` above 1000, so the friendlier values callers pass ("all", "Overall",
11
+ * a limit of 100) are normalized here — sending them verbatim made every
12
+ * leaderboard sync fail with a 400.
13
+ */
14
+ export declare function buildLeaderboardUrl(options?: {
15
+ timePeriod?: LeaderboardTimePeriod | string;
16
+ orderBy?: "VOL" | "PNL";
17
+ limit?: number;
18
+ offset?: number;
19
+ category?: PolymarketCategory | Lowercase<PolymarketCategory> | string;
20
+ }): URL;
21
+ /**
22
+ * Fetches one page of the Polymarket leaderboard, ranked by volume or PnL.
4
23
  * @param options - Configuration options for the leaderboard query
5
24
  * @param options.timePeriod - Time period filter: "all", "1d", "7d", or "30d" (default: "all")
6
25
  * @param options.orderBy - Sort order: "VOL" for volume or "PNL" for profit/loss (default: "VOL")
7
- * @param options.limit - Maximum number of entries to retrieve (default: 20)
8
- * @param options.offset - Number of entries to skip for pagination (default: 0)
9
- * @param options.category - Category filter (default: "overall")
26
+ * @param options.limit - Entries to retrieve, at most 50 (default: 20)
27
+ * @param options.offset - Entries to skip for pagination, at most 1000 (default: 0)
28
+ * @param options.category - Category filter (default: "Overall")
10
29
  * @returns Array of leaderboard entries
11
30
  * @throws Error if the API request fails
12
31
  */
13
- export declare function fetchLeaderboard(options?: {
14
- timePeriod?: "all" | "1d" | "7d" | "30d";
15
- orderBy?: "VOL" | "PNL";
16
- limit?: number;
17
- offset?: number;
18
- category?: PolymarketCategory | Lowercase<PolymarketCategory>;
19
- }): Promise<unknown>;
32
+ export declare function fetchLeaderboard(options?: Parameters<typeof buildLeaderboardUrl>[0]): Promise<any[]>;
33
+ /**
34
+ * Fetches up to `limit` leaderboard entries, paging through the API's
35
+ * 50-row pages until it runs dry or the offset cap is reached.
36
+ */
37
+ export declare function fetchLeaderboardPages(options?: Omit<Parameters<typeof buildLeaderboardUrl>[0] & {}, "offset">): Promise<any[]>;
20
38
  /**
21
39
  * Fetches top traders from Polymarket Analytics API sorted by overall gain.
22
40
  * @param limit - Maximum number of traders to retrieve (default: 50)
@@ -1 +1 @@
1
- {"version":3,"file":"leaderboard.d.ts","sourceRoot":"","sources":["../../../src/prediction/api/leaderboard.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,GAAE;IACP,UAAU,CAAC,EAAE,KAAK,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC;IACzC,OAAO,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC,kBAAkB,CAAC,CAAC;CAC1D,oBAuBP;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,KAAK,SAAK,kBA4C/C;AAED;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AAC,EAAE,OAAO,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,oBAqDA"}
@@ -1 +1 @@
1
- {"version":3,"file":"prices.d.ts","sourceRoot":"","sources":["../../../src/prediction/api/prices.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,oBA2CA"}
1
+ {"version":3,"file":"prices.d.ts","sourceRoot":"","sources":["../../../src/prediction/api/prices.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,oBA2CA"}
@@ -4,6 +4,15 @@
4
4
  * @param marketsData - Array of market objects from the API
5
5
  */
6
6
  export declare function saveMarkets(marketsData: any[]): Promise<void>;
7
+ /** `listing_controls.kind` for a Polymarket market. */
8
+ export declare const PM_MARKET_LISTING_KIND = "pm-market";
9
+ /**
10
+ * Condition matching markets an admin has not unpublished. Markets with no
11
+ * `listing_controls` row are published — new markets from a sync show up
12
+ * without anyone having to approve them — so this is a NOT EXISTS over the
13
+ * unpublished rows rather than a join over published ones.
14
+ */
15
+ export declare function publishedMarketCondition(): import('drizzle-orm').SQL<unknown>;
7
16
  /**
8
17
  * Retrieves markets from the database with filtering and sorting options.
9
18
  * @param options - Query configuration options
@@ -11,6 +20,7 @@ export declare function saveMarkets(marketsData: any[]): Promise<void>;
11
20
  * @param options.sortBy - Sort field: "volume24hr", "volumeTotal", or "createdAt" (default: "volume24hr")
12
21
  * @param options.category - Optional category tag to filter by
13
22
  * @param options.activeOnly - Only include active markets (default: true)
23
+ * @param options.includeUnpublished - Also return markets an admin unpublished (default: false)
14
24
  * @returns Array of market records matching the criteria
15
25
  */
16
26
  export declare function getMarkets(options?: {
@@ -19,6 +29,7 @@ export declare function getMarkets(options?: {
19
29
  sortBy?: "volume24hr" | "volumeTotal" | "createdAt";
20
30
  category?: string;
21
31
  activeOnly?: boolean;
32
+ includeUnpublished?: boolean;
22
33
  }): Promise<{
23
34
  id: string;
24
35
  conditionId: string | null;
@@ -51,6 +62,7 @@ export declare function getMarkets(options?: {
51
62
  * @param options.sortBy - Sort field: "volume24hr", "volumeTotal", or "createdAt" (default: "volume24hr")
52
63
  * @param options.category - Optional category tag to filter by
53
64
  * @param options.activeOnly - Only include active markets (default: true)
65
+ * @param options.includeUnpublished - Also return markets an admin unpublished (default: false)
54
66
  * @returns Array of market records matching the search term
55
67
  */
56
68
  export declare function searchMarketsInDB(searchTerm: string, options?: {
@@ -59,6 +71,7 @@ export declare function searchMarketsInDB(searchTerm: string, options?: {
59
71
  sortBy?: "volume24hr" | "volumeTotal" | "createdAt";
60
72
  category?: string;
61
73
  activeOnly?: boolean;
74
+ includeUnpublished?: boolean;
62
75
  }): Promise<{
63
76
  id: string;
64
77
  conditionId: string | null;
@@ -1 +1 @@
1
- {"version":3,"file":"markets.d.ts","sourceRoot":"","sources":["../../../src/prediction/db/markets.ts"],"names":[],"mappings":"AAoCA;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,WAAW,EAAE,GAAG,EAAE,iBAwFnD;AAED;;;;;;;;GAQG;AACH,wBAAsB,UAAU,CAC9B,OAAO,GAAE;IACP,KAAK,CAAC,EAAE,MAAM,CA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AAE,MAAM,EAClB,OAAO,GAAE;IACP,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,YAAY,GAAG,aAAa,GAAG,WAAW,CAAC;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CACzB;;;;;;;;;;;;;;;;;;;;;;;KAsDP;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,mCAyBzC"}
@@ -73,6 +73,41 @@ export declare function getTraderTradeHistory(traderId: string, options?: {
73
73
  syncedAt: Date;
74
74
  createdAt: Date;
75
75
  }[]>;
76
+ /**
77
+ * Loads every stored TRADE row for one Polymarket proxy wallet through an
78
+ * inclusive execution-time cutoff.
79
+ *
80
+ * This query intentionally has no pagination limit: position reconstruction
81
+ * needs the opening fills as well as the closing fills. Rows are ordered by
82
+ * execution time and then primary key so same-second activity has a stable
83
+ * caller order.
84
+ *
85
+ * This establishes only what is present in the local table. It does not prove
86
+ * that upstream activity synchronization captured the wallet's complete
87
+ * history.
88
+ */
89
+ export declare function getTraderTradesThroughCutoff(traderId: string, cutoff: Date): Promise<{
90
+ id: string;
91
+ traderId: string;
92
+ transactionHash: string;
93
+ conditionId: string;
94
+ marketTitle: string | null;
95
+ marketSlug: string | null;
96
+ eventSlug: string | null;
97
+ type: string;
98
+ side: string | null;
99
+ outcome: string | null;
100
+ outcomeIndex: number | null;
101
+ size: number;
102
+ usdcSize: number;
103
+ price: number | null;
104
+ traderName: string | null;
105
+ traderBio: string | null;
106
+ traderProfileImage: string | null;
107
+ timestamp: Date;
108
+ syncedAt: Date;
109
+ createdAt: Date;
110
+ }[]>;
76
111
  /**
77
112
  * Gets trade statistics for a trader.
78
113
  * @param traderId - The trader wallet address
@@ -1 +1 @@
1
- {"version":3,"file":"trade-history.d.ts","sourceRoot":"","sources":["../../../src/prediction/db/trade-history.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AmB,CAAC,QAAQ,EAAE,MAAM;;;;;;;;GAezD;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CASxB;AAED;;;GAGG;AACH,wBAAsB,kBAAkB;;;;;;GAuBvC"}
@@ -12,10 +12,16 @@ export * from './db/positions';
12
12
  export * from './db/debates';
13
13
  export * from './db/prices';
14
14
  export * from './db/trade-history';
15
+ export * from './utils/token-ids';
15
16
  export * from './analysis/price-changes';
16
17
  export * from './analysis/categories';
17
18
  export * from './analysis/greeks';
18
19
  export * from './analysis/detector';
20
+ export * from './analysis/trust-score';
21
+ export * from './analysis/r-multiple';
22
+ export * from './analysis/position-reconstruction';
23
+ export * from './analysis/position-settlement';
24
+ export * from './analysis/polymarket-wallet-trust';
19
25
  export * from './sync/markets';
20
26
  export * from './sync/incremental-markets';
21
27
  export * from './sync/leaderboard';
@@ -23,4 +29,5 @@ export * from './sync/prices';
23
29
  export * from './sync/holders';
24
30
  export * from './sync/orchestration';
25
31
  export * from './sync/trade-history';
32
+ export * from './sync/refill';
26
33
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/prediction/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC7E,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AAGvB,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAG5B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AAGnC,c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AAc,eAAe,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"incremental-markets.d.ts","sourceRoot":"","sources":["../../../src/prediction/sync/incremental-markets.ts"],"names":[],"mappings":"AAMA;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAC1C,UAAU,SAAO,EACjB,oBAAoB,UAAO,EAC3B,eAAe,UAAO;;;;;;GAyJvB"}
1
+ {"version":3,"file":"incremental-markets.d.ts","sourceRoot":"","sources":["../../../src/prediction/sync/incremental-markets.ts"],"names":[],"mappings":"AAOA;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAC1C,UAAU,SAAO,EACjB,oBAAoB,UAAO,EAC3B,eAAe,UAAO;;;;;;GAyJvB"}
@@ -11,7 +11,7 @@ export declare function syncLeaderboard(options?: {
11
11
  orderBy?: "VOL" | "PNL";
12
12
  limit?: number;
13
13
  }): Promise<{
14
- leaders: any;
14
+ leaders: number;
15
15
  }>;
16
16
  /**
17
17
  * Syncs top traders, their positions, and category analytics from Polymarket.
@@ -1 +1 @@
1
- {"version":3,"file":"leaderboard.d.ts","sourceRoot":"","sources":["../../../src/prediction/sync/leaderboard.ts"],"names":[],"mappings":"AA0BA;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,OAAO,GAAE;IACP,UAAU,CAAC,EAAE,KAAK,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC;IACzC,OAAO,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;CACX;;GASP;AAED;;;;GAIG;AACH,wBAAsB,wBAAwB;;;GAuB7C"}
1
+ {"version":3,"file":"leaderboard.d.ts","sourceRoot":"","sources":["../../../src/prediction/sync/leaderboard.ts"],"names":[],"mappings":"AA0BA;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACnC,OAAO,GAAE;IACP,UAAU,CAAC,EAAE,KAAK,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC;IACzC,OAAO,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;CACX;;GAUP;AAED;;;;GAIG;AACH,wBAAsB,wBAAwB;;;GAuB7C"}
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Syncs markets from Polymarket API to the database.
3
- * Clears existing markets and fetches fresh data sorted by 24h volume.
3
+ * Upserts fresh data sorted by 24h volume (existing rows are kept).
4
4
  * Also fetches and stores price history for markets with token IDs.
5
5
  * @param limit - Maximum number of markets to sync (default: 200)
6
6
  * @param syncPriceHistoryFlag - Whether to also fetch price history (default: true)
@@ -12,7 +12,7 @@ export declare function syncMarkets(limit?: number, syncPriceHistoryFlag?: boole
12
12
  }>;
13
13
  /**
14
14
  * Syncs all active markets from Polymarket API to the database.
15
- * Clears existing markets and fetches all available data sorted by 24h volume.
15
+ * Upserts all available markets sorted by 24h volume (existing rows are kept).
16
16
  * Also fetches and stores price history for markets with token IDs.
17
17
  * @param maxMarkets - Maximum total number of markets to sync (default: 0 for unlimited, fetches ALL active markets)
18
18
  * @param syncPriceHistoryFlag - Whether to also fetch price history (default: true)
@@ -1 +1 @@
1
- {"version":3,"file":"markets.d.ts","sourceRoot":"","sources":["../../../src/prediction/sync/markets.ts"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAAC,KAAK,SAAM,EAAE,oBAAoB,UAAO;;;GAoEzE;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAClC,UAAU,SAAI,EACd,oBAAoB,UAAO;;;GAqE5B"}
1
+ {"version":3,"file":"markets.d.ts","sourceRoot":"","sources":["../../../src/prediction/sync/markets.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAAC,KAAK,SAAM,EAAE,oBAAoB,UAAO;;;GAiEzE;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAClC,UAAU,SAAI,EACd,oBAAoB,UAAO;;;GA+D5B"}
@@ -5,7 +5,7 @@
5
5
  */
6
6
  export declare function syncAll(): Promise<{
7
7
  markets: any;
8
- leaderboard: any;
8
+ leaderboard: number;
9
9
  leaders: number;
10
10
  positions: number;
11
11
  }>;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Refill size limits, kept apart from refill.ts so callers that only validate
3
+ * input (route handlers, tests) do not import the database client.
4
+ */
5
+ /** Upper bound an admin refill may request, so one click cannot run all night. */
6
+ export declare const MAX_REFILL_MARKETS = 5000;
7
+ /** Clamps a requested refill size to 1…MAX_REFILL_MARKETS (0 or junk → default). */
8
+ export declare function clampRefillSize(value: unknown, fallback?: number): number;
9
+ //# sourceMappingURL=refill-limits.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refill-limits.d.ts","sourceRoot":"","sources":["../../../src/prediction/sync/refill-limits.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,kFAAkF;AAClF,eAAO,MAAM,kBAAkB,OAAO,CAAC;AAEvC,oFAAoF;AACpF,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,SAAM,GAAG,MAAM,CAItE"}