@agenticmail/enterprise 0.5.442 → 0.5.443

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 (244) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +3 -2
  3. package/dist/agent-tools-3MD7EPO6.js +14629 -0
  4. package/dist/agent-tools-62HGQYDL.js +14629 -0
  5. package/dist/agent-tools-BTUVVOWT.js +14629 -0
  6. package/dist/agent-tools-BV3JMJPN.js +14629 -0
  7. package/dist/agent-tools-JVNQ4RPM.js +14629 -0
  8. package/dist/agent-tools-LD7LELVT.js +14629 -0
  9. package/dist/agent-tools-NRKQ5NMW.js +14629 -0
  10. package/dist/agent-tools-OXZJOD4D.js +14629 -0
  11. package/dist/agent-tools-PT2ES6G5.js +14629 -0
  12. package/dist/agent-tools-SS335E2E.js +14629 -0
  13. package/dist/chunk-2ACTQSPC.js +1728 -0
  14. package/dist/chunk-2XZE5NT3.js +5387 -0
  15. package/dist/chunk-325NTNE6.js +2180 -0
  16. package/dist/chunk-3AHKVWCO.js +5387 -0
  17. package/dist/chunk-3L2N6LR2.js +7517 -0
  18. package/dist/chunk-3ZD3XOV6.js +1728 -0
  19. package/dist/chunk-44VXWYPE.js +2570 -0
  20. package/dist/chunk-4UOSUXFR.js +7529 -0
  21. package/dist/chunk-54SHHX2S.js +2180 -0
  22. package/dist/chunk-5DVY3CNK.js +1728 -0
  23. package/dist/chunk-5F5DGV63.js +5596 -0
  24. package/dist/chunk-6IUUOWZY.js +7526 -0
  25. package/dist/chunk-77LFFLQX.js +7526 -0
  26. package/dist/chunk-7BKNDBSA.js +2191 -0
  27. package/dist/chunk-7BS2XPLW.js +5359 -0
  28. package/dist/chunk-7GCSGDXQ.js +1636 -0
  29. package/dist/chunk-7IAI45PR.js +4735 -0
  30. package/dist/chunk-7QPZGO27.js +4976 -0
  31. package/dist/chunk-7S5XAXRD.js +4747 -0
  32. package/dist/chunk-AD6ZR3QD.js +5357 -0
  33. package/dist/chunk-AO556OXZ.js +2570 -0
  34. package/dist/chunk-APUWQHXC.js +7437 -0
  35. package/dist/chunk-BKSSHV6C.js +1728 -0
  36. package/dist/chunk-BMUNQHLU.js +1208 -0
  37. package/dist/chunk-BPF5DKUM.js +392 -0
  38. package/dist/chunk-CFR5OSMI.js +1220 -0
  39. package/dist/chunk-CM4GUHXP.js +1728 -0
  40. package/dist/chunk-CVFIM72Q.js +501 -0
  41. package/dist/chunk-DFXVJNKW.js +4734 -0
  42. package/dist/chunk-DJ7LHRL7.js +2214 -0
  43. package/dist/chunk-DJFI6NR6.js +1624 -0
  44. package/dist/chunk-DJHYV5VY.js +1624 -0
  45. package/dist/chunk-DYM4PQO3.js +4727 -0
  46. package/dist/chunk-DZ75RF35.js +1728 -0
  47. package/dist/chunk-E5H64U5H.js +472 -0
  48. package/dist/chunk-EOD4EGFI.js +1728 -0
  49. package/dist/chunk-EP74QR5B.js +4980 -0
  50. package/dist/chunk-FE2M4FV5.js +5273 -0
  51. package/dist/chunk-FUH6NWIX.js +7540 -0
  52. package/dist/chunk-G5ADHHAD.js +1728 -0
  53. package/dist/chunk-GAYLPSM7.js +7529 -0
  54. package/dist/chunk-GDAFZJTJ.js +7540 -0
  55. package/dist/chunk-GLAN2JBA.js +1636 -0
  56. package/dist/chunk-GNAEBGU7.js +4812 -0
  57. package/dist/chunk-HDDA2Q3Q.js +1728 -0
  58. package/dist/chunk-HG62FWWQ.js +7437 -0
  59. package/dist/chunk-HV5VIS5K.js +1624 -0
  60. package/dist/chunk-IEVA23WK.js +4976 -0
  61. package/dist/chunk-IFMZ2IYC.js +7540 -0
  62. package/dist/chunk-IN7VIORK.js +2641 -0
  63. package/dist/chunk-KAX3ZDP2.js +7529 -0
  64. package/dist/chunk-KECO53GP.js +1728 -0
  65. package/dist/chunk-KGZ74UMA.js +1728 -0
  66. package/dist/chunk-M2ZLRUMX.js +7540 -0
  67. package/dist/chunk-MKQWC6KF.js +5374 -0
  68. package/dist/chunk-MQ3JBGLU.js +1636 -0
  69. package/dist/chunk-MVB6JARX.js +7529 -0
  70. package/dist/chunk-N37MOOFE.js +2210 -0
  71. package/dist/chunk-NELCAZUQ.js +5357 -0
  72. package/dist/chunk-OPAO5QQS.js +1728 -0
  73. package/dist/chunk-OUHU3VW6.js +1728 -0
  74. package/dist/chunk-OWEXZVZ6.js +1728 -0
  75. package/dist/chunk-P4DHSJJY.js +7437 -0
  76. package/dist/chunk-Q7QA6MNJ.js +1728 -0
  77. package/dist/chunk-QKKTNPGV.js +7592 -0
  78. package/dist/chunk-REMMXZVU.js +7529 -0
  79. package/dist/chunk-RK3KATD4.js +4756 -0
  80. package/dist/chunk-RQ33L5T3.js +5374 -0
  81. package/dist/chunk-RU77F65Q.js +1728 -0
  82. package/dist/chunk-SAM3CVIU.js +5374 -0
  83. package/dist/chunk-SFMXIKWZ.js +1728 -0
  84. package/dist/chunk-SPZ5JBGW.js +1624 -0
  85. package/dist/chunk-TDOC6WSK.js +7529 -0
  86. package/dist/chunk-TPMT5WTW.js +5357 -0
  87. package/dist/chunk-TVXUR3PB.js +2180 -0
  88. package/dist/chunk-TZEEVEKG.js +5343 -0
  89. package/dist/chunk-U327O3ZR.js +7540 -0
  90. package/dist/chunk-ULD6C5DB.js +2180 -0
  91. package/dist/chunk-ULVRCJZV.js +5374 -0
  92. package/dist/chunk-UOCDOM2S.js +1624 -0
  93. package/dist/chunk-VINDZLLX.js +1636 -0
  94. package/dist/chunk-VODW5GJL.js +2180 -0
  95. package/dist/chunk-WEWL7Z3C.js +2180 -0
  96. package/dist/chunk-WG2MEMS6.js +5343 -0
  97. package/dist/chunk-WYV6QWOJ.js +1188 -0
  98. package/dist/chunk-X5AIAD77.js +1636 -0
  99. package/dist/chunk-XUETIRDV.js +2214 -0
  100. package/dist/chunk-XWSMX7RK.js +7529 -0
  101. package/dist/chunk-YUSYXHKB.js +1728 -0
  102. package/dist/chunk-ZC2RMHQD.js +5374 -0
  103. package/dist/chunk-ZDZQQGFG.js +5374 -0
  104. package/dist/chunk-ZJ2HCWKF.js +1728 -0
  105. package/dist/chunk-ZMKVEJKR.js +392 -0
  106. package/dist/cli-agent-2UFGFO24.js +2761 -0
  107. package/dist/cli-agent-5FPUCFPG.js +2761 -0
  108. package/dist/cli-agent-7AB6NIYQ.js +2761 -0
  109. package/dist/cli-agent-7CAFSYOM.js +2761 -0
  110. package/dist/cli-agent-7OVOINHR.js +2757 -0
  111. package/dist/cli-agent-AWKBFIRS.js +2761 -0
  112. package/dist/cli-agent-ES3XOPHJ.js +2757 -0
  113. package/dist/cli-agent-KPXZN5JK.js +2761 -0
  114. package/dist/cli-agent-LGTCFHGS.js +2757 -0
  115. package/dist/cli-agent-LLUYUHHF.js +2757 -0
  116. package/dist/cli-agent-NHZWYX5Q.js +2761 -0
  117. package/dist/cli-agent-TYUOTYCO.js +2757 -0
  118. package/dist/cli-agent-VQO6HI65.js +2757 -0
  119. package/dist/cli-agent-VV5JWRU7.js +2757 -0
  120. package/dist/cli-agent-Z5B23XED.js +2757 -0
  121. package/dist/cli-serve-2FLQXJW7.js +322 -0
  122. package/dist/cli-serve-34YFCCUX.js +322 -0
  123. package/dist/cli-serve-3NS6MNUS.js +322 -0
  124. package/dist/cli-serve-4PWFEPNA.js +322 -0
  125. package/dist/cli-serve-4VIBMXMT.js +322 -0
  126. package/dist/cli-serve-5ZUF5MGH.js +322 -0
  127. package/dist/cli-serve-6HGL56GB.js +322 -0
  128. package/dist/cli-serve-BBBWEKKW.js +322 -0
  129. package/dist/cli-serve-D2HQC4SB.js +322 -0
  130. package/dist/cli-serve-IKCMNUNM.js +322 -0
  131. package/dist/cli-serve-LTUKYMEF.js +322 -0
  132. package/dist/cli-serve-MIWI5PBE.js +322 -0
  133. package/dist/cli-serve-R6K4SZ3L.js +322 -0
  134. package/dist/cli-serve-RQIOBQGF.js +322 -0
  135. package/dist/cli-serve-S57ROYQ6.js +322 -0
  136. package/dist/cli-serve-WVSLOISY.js +322 -0
  137. package/dist/cli-serve-YKZSNR3P.js +322 -0
  138. package/dist/cli-serve-ZGKXWDMZ.js +322 -0
  139. package/dist/cli-serve-ZZOJWREY.js +322 -0
  140. package/dist/cli.js +3 -3
  141. package/dist/dashboard/components/utils.js +1 -1
  142. package/dist/dashboard/docs/polymarket.html +1 -1
  143. package/dist/dashboard/pages/polymarket.js +222 -80
  144. package/dist/index.js +10 -10
  145. package/dist/pipeline-C4C3ZF4X.js +15 -0
  146. package/dist/pipeline-DAF3EV7Q.js +15 -0
  147. package/dist/pipeline-MMESLRQG.js +15 -0
  148. package/dist/polymarket-3LGJSQZK.js +17 -0
  149. package/dist/polymarket-4OIWQFBO.js +17 -0
  150. package/dist/polymarket-AZEV7C6E.js +17 -0
  151. package/dist/polymarket-DBQYJC57.js +7 -0
  152. package/dist/polymarket-EVTKWLUO.js +7 -0
  153. package/dist/polymarket-GMKDVVQH.js +17 -0
  154. package/dist/polymarket-HZOAD4W4.js +17 -0
  155. package/dist/polymarket-PKGRF7ID.js +17 -0
  156. package/dist/polymarket-QUNR2H7U.js +17 -0
  157. package/dist/polymarket-TM624BN5.js +17 -0
  158. package/dist/polymarket-VT2EDGD7.js +17 -0
  159. package/dist/polymarket-W7B4TLP3.js +17 -0
  160. package/dist/polymarket-WS4VE6U7.js +7 -0
  161. package/dist/polymarket-runtime-772ADZJW.js +108 -0
  162. package/dist/polymarket-runtime-AIYHQKYQ.js +108 -0
  163. package/dist/polymarket-runtime-APJ5HW4Y.js +108 -0
  164. package/dist/polymarket-runtime-BX3ODZZD.js +108 -0
  165. package/dist/polymarket-runtime-ISD4CKKL.js +108 -0
  166. package/dist/polymarket-runtime-JU4PQZGJ.js +108 -0
  167. package/dist/polymarket-runtime-OFLBSPCK.js +108 -0
  168. package/dist/polymarket-runtime-POJRRWFS.js +108 -0
  169. package/dist/polymarket-runtime-XN5TVHU5.js +108 -0
  170. package/dist/polymarket-runtime-ZYFTKEJ4.js +108 -0
  171. package/dist/polymarket-watcher-2CKLTIXI.js +23 -0
  172. package/dist/polymarket-watcher-3C72X36B.js +23 -0
  173. package/dist/polymarket-watcher-IHRZ2URM.js +23 -0
  174. package/dist/polymarket-watcher-J7UWIN7I.js +23 -0
  175. package/dist/polymarket-watcher-M6CDW63Y.js +23 -0
  176. package/dist/polymarket-watcher-OSI73EDX.js +23 -0
  177. package/dist/polymarket-watcher-PN4JJV3V.js +23 -0
  178. package/dist/polymarket-watcher-PXK4NS5F.js +23 -0
  179. package/dist/polymarket-watcher-VDJ4SVHP.js +23 -0
  180. package/dist/polymarket-watcher-W4BV6JTG.js +23 -0
  181. package/dist/runtime-22E2WCL6.js +46 -0
  182. package/dist/runtime-7GYS4FQU.js +46 -0
  183. package/dist/runtime-BR6K3Q3N.js +46 -0
  184. package/dist/runtime-CTTRDVJ6.js +46 -0
  185. package/dist/runtime-GIIPTHK5.js +46 -0
  186. package/dist/runtime-HYAKLZWI.js +46 -0
  187. package/dist/runtime-IQ2KIV2L.js +50 -0
  188. package/dist/runtime-ISXECIAB.js +46 -0
  189. package/dist/runtime-IV4BY7S4.js +46 -0
  190. package/dist/runtime-O65GGHL2.js +46 -0
  191. package/dist/runtime-PKHEGQYK.js +50 -0
  192. package/dist/runtime-RFKPIFK4.js +46 -0
  193. package/dist/runtime-S35B6PIY.js +46 -0
  194. package/dist/runtime-WEZJ4YRK.js +46 -0
  195. package/dist/runtime-WLWB62ZI.js +46 -0
  196. package/dist/screener-FB47G4YX.js +26 -0
  197. package/dist/screener-WQVQO4WF.js +26 -0
  198. package/dist/server-6GWGIGBH.js +36 -0
  199. package/dist/server-7VZ6XXBC.js +36 -0
  200. package/dist/server-7XBTD3FW.js +36 -0
  201. package/dist/server-BN56IMC4.js +36 -0
  202. package/dist/server-GD6SPDER.js +36 -0
  203. package/dist/server-IJHU2FIK.js +36 -0
  204. package/dist/server-J5WZGZX3.js +36 -0
  205. package/dist/server-JVUH2E3H.js +36 -0
  206. package/dist/server-MYXWTXSE.js +36 -0
  207. package/dist/server-ORGV7O7L.js +36 -0
  208. package/dist/server-QPE3WVUQ.js +36 -0
  209. package/dist/server-SUBGS5BJ.js +36 -0
  210. package/dist/server-SWAYJTFF.js +36 -0
  211. package/dist/server-TFIWDU2H.js +36 -0
  212. package/dist/server-VH4W6LWW.js +36 -0
  213. package/dist/server-X5UMJJ3J.js +36 -0
  214. package/dist/server-XOK5LHNU.js +36 -0
  215. package/dist/server-ZLK24KFY.js +36 -0
  216. package/dist/server-ZNSQGCRM.js +36 -0
  217. package/dist/setup-32ZRMW7R.js +20 -0
  218. package/dist/setup-3WF7PBIS.js +20 -0
  219. package/dist/setup-4TM64QG4.js +20 -0
  220. package/dist/setup-5SGUMKN7.js +20 -0
  221. package/dist/setup-AGYKOCIU.js +20 -0
  222. package/dist/setup-EIP4IHZN.js +20 -0
  223. package/dist/setup-F5SAGQJJ.js +20 -0
  224. package/dist/setup-LMF76UUM.js +20 -0
  225. package/dist/setup-MA5QR3J4.js +20 -0
  226. package/dist/setup-MLIPR2U3.js +20 -0
  227. package/dist/setup-MLIZYTT6.js +20 -0
  228. package/dist/setup-OPVZ3GM7.js +20 -0
  229. package/dist/setup-PWFHUXOK.js +20 -0
  230. package/dist/setup-QF5GCTPE.js +20 -0
  231. package/dist/setup-SGF4OX3A.js +20 -0
  232. package/dist/setup-TLWKGWC6.js +20 -0
  233. package/dist/setup-TYCRH63P.js +20 -0
  234. package/dist/setup-USUBKTVX.js +20 -0
  235. package/dist/setup-VMNTNEB4.js +20 -0
  236. package/dist/shared-S5ROHYCX.js +69 -0
  237. package/dist/shared-TLWZZZSK.js +69 -0
  238. package/dist/system-prompts-7ZRL27FN.js +69 -0
  239. package/dist/system-prompts-CNXUF2AV.js +69 -0
  240. package/dist/system-prompts-SYGQRBRG.js +69 -0
  241. package/logs/cloudflared-error.log +4 -89
  242. package/logs/cloudflared-error__2026-03-11_00-00-00.log +289 -0
  243. package/package.json +1 -1
  244. package/logs/cloudflared-error__2026-03-06_00-00-00.log +0 -245
@@ -0,0 +1,472 @@
1
+ // src/polymarket-engines/shared.ts
2
+ var CLOB_API = "https://clob.polymarket.com";
3
+ var GAMMA_API = "https://gamma-api.polymarket.com";
4
+ var DATA_API = "https://data-api.polymarket.com";
5
+ var POLYGON_RPC = "https://polygon-bor-rpc.publicnode.com";
6
+ var CTF_ADDRESS = "0x4D97DCd97eC945f40cF65F87097ACe5EA0476045";
7
+ var USDC_ADDRESS = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
8
+ var responseCache = /* @__PURE__ */ new Map();
9
+ var MAX_CACHE_ENTRIES = 500;
10
+ function getCached(key, ttlMs) {
11
+ const entry = responseCache.get(key);
12
+ if (entry && Date.now() - entry.ts < ttlMs) return entry.data;
13
+ if (entry) responseCache.delete(key);
14
+ return null;
15
+ }
16
+ function setCache(key, data) {
17
+ if (responseCache.size > MAX_CACHE_ENTRIES) {
18
+ const oldest = responseCache.keys().next().value;
19
+ if (oldest) responseCache.delete(oldest);
20
+ }
21
+ responseCache.set(key, { data, ts: Date.now() });
22
+ }
23
+ var rateLimits = /* @__PURE__ */ new Map();
24
+ var DOMAIN_LIMITS = {
25
+ "clob.polymarket.com": 80,
26
+ "gamma-api.polymarket.com": 60,
27
+ "data-api.polymarket.com": 60
28
+ };
29
+ function checkRateLimit(domain, maxPerMinute = 30) {
30
+ const now = Date.now();
31
+ const limit = DOMAIN_LIMITS[domain] || maxPerMinute;
32
+ const times = rateLimits.get(domain) || [];
33
+ const recent = times.filter((t) => now - t < 6e4);
34
+ if (recent.length >= limit) return false;
35
+ recent.push(now);
36
+ rateLimits.set(domain, recent);
37
+ return true;
38
+ }
39
+ var _proxyFetchHook = null;
40
+ function setProxyFetchHook(hook) {
41
+ _proxyFetchHook = hook;
42
+ }
43
+ async function apiFetch(url, timeoutMs = 1e4) {
44
+ const ctrl = new AbortController();
45
+ const t = setTimeout(() => ctrl.abort(), timeoutMs);
46
+ try {
47
+ const fetchOpts = { signal: ctrl.signal, headers: { Accept: "application/json" } };
48
+ const isClobApi = url.includes("clob.polymarket.com");
49
+ const res = isClobApi && _proxyFetchHook ? await _proxyFetchHook(url, fetchOpts) : await fetch(url, fetchOpts);
50
+ if (!res.ok) throw new Error(`API ${res.status}: ${await res.text().catch(() => res.statusText)}`);
51
+ const ct = res.headers.get("content-type") || "";
52
+ return ct.includes("json") ? res.json() : res.text();
53
+ } finally {
54
+ clearTimeout(t);
55
+ }
56
+ }
57
+ async function cachedFetchJSON(url, ttlMs = 3e4, timeoutMs = 1e4) {
58
+ const cached = getCached(url, ttlMs);
59
+ if (cached !== null) return cached;
60
+ const domain = new URL(url).hostname;
61
+ if (!checkRateLimit(domain)) throw new Error(`Rate limited: ${domain}`);
62
+ const data = await apiFetch(url, timeoutMs);
63
+ setCache(url, data);
64
+ return data;
65
+ }
66
+ async function cachedFetchText(url, ttlMs = 6e4, timeoutMs = 1e4) {
67
+ const cacheKey = "txt:" + url;
68
+ const cached = getCached(cacheKey, ttlMs);
69
+ if (cached !== null) return cached;
70
+ const domain = new URL(url).hostname;
71
+ if (!checkRateLimit(domain)) throw new Error(`Rate limited: ${domain}`);
72
+ const ctrl = new AbortController();
73
+ const t = setTimeout(() => ctrl.abort(), timeoutMs);
74
+ try {
75
+ const res = await fetch(url, { signal: ctrl.signal, headers: { "User-Agent": "PolymarketBot/1.0" } });
76
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
77
+ const text = await res.text();
78
+ setCache(cacheKey, text);
79
+ return text;
80
+ } finally {
81
+ clearTimeout(t);
82
+ }
83
+ }
84
+ async function parallelFetch(items, fn, concurrency = 5) {
85
+ const results = [];
86
+ for (let i = 0; i < items.length; i += concurrency) {
87
+ const batch = items.slice(i, i + concurrency);
88
+ const batchResults = await Promise.allSettled(batch.map(fn));
89
+ for (const r of batchResults) {
90
+ if (r.status === "fulfilled") results.push(r.value);
91
+ }
92
+ }
93
+ return results;
94
+ }
95
+ function normalCDF(x) {
96
+ const a1 = 0.254829592, a2 = -0.284496736, a3 = 1.421413741;
97
+ const a4 = -1.453152027, a5 = 1.061405429, p = 0.3275911;
98
+ const sign = x < 0 ? -1 : 1;
99
+ x = Math.abs(x) / Math.SQRT2;
100
+ const t = 1 / (1 + p * x);
101
+ const y = 1 - ((((a5 * t + a4) * t + a3) * t + a2) * t + a1) * t * Math.exp(-x * x);
102
+ return 0.5 * (1 + sign * y);
103
+ }
104
+ function normalPDF(x) {
105
+ return Math.exp(-0.5 * x * x) / Math.sqrt(2 * Math.PI);
106
+ }
107
+ function normalInv(p) {
108
+ if (p <= 0) return -Infinity;
109
+ if (p >= 1) return Infinity;
110
+ if (p === 0.5) return 0;
111
+ const a = [
112
+ -39.69683028665376,
113
+ 220.9460984245205,
114
+ -275.9285104469687,
115
+ 138.357751867269,
116
+ -30.66479806614716,
117
+ 2.506628277459239
118
+ ];
119
+ const b = [
120
+ -54.47609879822406,
121
+ 161.5858368580409,
122
+ -155.6989798598866,
123
+ 66.80131188771972,
124
+ -13.28068155288572
125
+ ];
126
+ const c = [
127
+ -0.007784894002430293,
128
+ -0.3223964580411365,
129
+ -2.400758277161838,
130
+ -2.549732539343734,
131
+ 4.374664141464968,
132
+ 2.938163982698783
133
+ ];
134
+ const d = [0.007784695709041462, 0.3224671290700398, 2.445134137142996, 3.754408661907416];
135
+ const pLow = 0.02425, pHigh = 1 - pLow;
136
+ let q, r;
137
+ if (p < pLow) {
138
+ q = Math.sqrt(-2 * Math.log(p));
139
+ return (((((c[0] * q + c[1]) * q + c[2]) * q + c[3]) * q + c[4]) * q + c[5]) / ((((d[0] * q + d[1]) * q + d[2]) * q + d[3]) * q + 1);
140
+ } else if (p <= pHigh) {
141
+ q = p - 0.5;
142
+ r = q * q;
143
+ return (((((a[0] * r + a[1]) * r + a[2]) * r + a[3]) * r + a[4]) * r + a[5]) * q / (((((b[0] * r + b[1]) * r + b[2]) * r + b[3]) * r + b[4]) * r + 1);
144
+ } else {
145
+ q = Math.sqrt(-2 * Math.log(1 - p));
146
+ return -(((((c[0] * q + c[1]) * q + c[2]) * q + c[3]) * q + c[4]) * q + c[5]) / ((((d[0] * q + d[1]) * q + d[2]) * q + d[3]) * q + 1);
147
+ }
148
+ }
149
+ function linearRegression(xs, ys) {
150
+ const n = xs.length;
151
+ let sumX = 0, sumY = 0, sumXY = 0, sumX2 = 0;
152
+ for (let i = 0; i < n; i++) {
153
+ sumX += xs[i];
154
+ sumY += ys[i];
155
+ sumXY += xs[i] * ys[i];
156
+ sumX2 += xs[i] * xs[i];
157
+ }
158
+ const slope = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX * sumX);
159
+ const intercept = (sumY - slope * sumX) / n;
160
+ const ssRes = ys.reduce((s, y, i) => s + Math.pow(y - (slope * xs[i] + intercept), 2), 0);
161
+ const ssTot = ys.reduce((s, y) => s + Math.pow(y - sumY / n, 2), 0);
162
+ const r2 = ssTot > 0 ? 1 - ssRes / ssTot : 0;
163
+ return { slope, intercept, r2 };
164
+ }
165
+ function ewma(data, span) {
166
+ const alpha = 2 / (span + 1);
167
+ const result = [data[0]];
168
+ for (let i = 1; i < data.length; i++) {
169
+ result.push(alpha * data[i] + (1 - alpha) * result[i - 1]);
170
+ }
171
+ return result;
172
+ }
173
+ function sma(data, window) {
174
+ const result = [];
175
+ for (let i = 0; i < data.length; i++) {
176
+ if (i < window - 1) {
177
+ result.push(NaN);
178
+ continue;
179
+ }
180
+ let sum = 0;
181
+ for (let j = i - window + 1; j <= i; j++) sum += data[j];
182
+ result.push(sum / window);
183
+ }
184
+ return result;
185
+ }
186
+ function std(data) {
187
+ const n = data.length;
188
+ if (n < 2) return 0;
189
+ const mean = data.reduce((s, v) => s + v, 0) / n;
190
+ const variance = data.reduce((s, v) => s + Math.pow(v - mean, 2), 0) / (n - 1);
191
+ return Math.sqrt(variance);
192
+ }
193
+ function pearsonCorrelation(x, y) {
194
+ const n = Math.min(x.length, y.length);
195
+ if (n < 5) return 0;
196
+ const xs = x.slice(-n), ys = y.slice(-n);
197
+ const mx = xs.reduce((s, v) => s + v, 0) / n;
198
+ const my = ys.reduce((s, v) => s + v, 0) / n;
199
+ let num = 0, dx = 0, dy = 0;
200
+ for (let i = 0; i < n; i++) {
201
+ const a = xs[i] - mx, b = ys[i] - my;
202
+ num += a * b;
203
+ dx += a * a;
204
+ dy += b * b;
205
+ }
206
+ const denom = Math.sqrt(dx * dy);
207
+ return denom > 0 ? parseFloat((num / denom).toFixed(4)) : 0;
208
+ }
209
+ function calculateHurst(prices) {
210
+ if (prices.length < 20) return 0.5;
211
+ const returns = prices.slice(1).map((p, i) => Math.log(p / prices[i]));
212
+ const n = returns.length;
213
+ const mean = returns.reduce((s, r) => s + r, 0) / n;
214
+ const deviations = returns.map((r) => r - mean);
215
+ const cumDev = [];
216
+ let sum = 0;
217
+ for (const d of deviations) {
218
+ sum += d;
219
+ cumDev.push(sum);
220
+ }
221
+ const R = Math.max(...cumDev) - Math.min(...cumDev);
222
+ const S = Math.sqrt(deviations.reduce((s, d) => s + d * d, 0) / n);
223
+ if (S === 0) return 0.5;
224
+ const RS = R / S;
225
+ const H = Math.log(RS) / Math.log(n);
226
+ return parseFloat(Math.max(0, Math.min(1, H)).toFixed(4));
227
+ }
228
+ function calculateVolatility(prices) {
229
+ if (prices.length < 2) return 0;
230
+ const returns = prices.slice(1).map((p, i) => Math.log(p / prices[i]));
231
+ const mean = returns.reduce((s, r) => s + r, 0) / returns.length;
232
+ const variance = returns.reduce((s, r) => s + (r - mean) ** 2, 0) / returns.length;
233
+ return parseFloat(Math.sqrt(variance * 252).toFixed(4));
234
+ }
235
+ function parseMarket(m) {
236
+ const prices = (() => {
237
+ try {
238
+ return JSON.parse(m.outcomePrices || "[]").map(Number);
239
+ } catch {
240
+ return [0.5, 0.5];
241
+ }
242
+ })();
243
+ const outcomes = (() => {
244
+ try {
245
+ return JSON.parse(m.outcomes || "[]");
246
+ } catch {
247
+ return ["Yes", "No"];
248
+ }
249
+ })();
250
+ const tokens = (() => {
251
+ try {
252
+ return JSON.parse(m.clobTokenIds || "[]");
253
+ } catch {
254
+ return [];
255
+ }
256
+ })();
257
+ return {
258
+ id: m.conditionId || m.id,
259
+ question: m.question || "",
260
+ slug: m.slug || "",
261
+ category: m.tags?.[0] || m.category || "unknown",
262
+ outcomes,
263
+ outcomePrices: prices,
264
+ clobTokenIds: tokens,
265
+ volume: parseFloat(m.volume || "0"),
266
+ liquidity: parseFloat(m.liquidity || "0"),
267
+ endDate: m.endDate || null,
268
+ active: m.active !== false,
269
+ negRisk: !!m.negRisk,
270
+ tickSize: m.minimumTickSize || "0.01",
271
+ description: m.description,
272
+ startDate: m.startDate
273
+ };
274
+ }
275
+ async function fetchPriceSeries(tokenId, limit = 200) {
276
+ try {
277
+ const trades = await apiFetch(`${CLOB_API}/trades?asset_id=${tokenId}&limit=${limit}`);
278
+ if (!Array.isArray(trades) || trades.length === 0) return [];
279
+ return trades.reverse().map((t) => parseFloat(t.price || "0")).filter((p) => p > 0);
280
+ } catch {
281
+ return [];
282
+ }
283
+ }
284
+ var priceHistoryCache = /* @__PURE__ */ new Map();
285
+ async function fetchPriceHistory(tokenId) {
286
+ const cached = priceHistoryCache.get(tokenId);
287
+ if (cached && Date.now() - cached.ts < 5 * 6e4) return cached.data;
288
+ try {
289
+ const data = await cachedFetchJSON(`${CLOB_API}/prices-history?market=${tokenId}&interval=1h&fidelity=60`);
290
+ const prices = (data?.history || []).map((p) => parseFloat(p.p || p.price || "0")).filter((p) => p > 0);
291
+ priceHistoryCache.set(tokenId, { data: prices, ts: Date.now() });
292
+ return prices;
293
+ } catch {
294
+ return [];
295
+ }
296
+ }
297
+ function parseRSSItems(xml) {
298
+ const items = [];
299
+ const itemRegex = /<item>([\s\S]*?)<\/item>/g;
300
+ let match;
301
+ while ((match = itemRegex.exec(xml)) !== null) {
302
+ const get = (tag) => {
303
+ const m = match[1].match(new RegExp(`<${tag}[^>]*>([\\s\\S]*?)<\\/${tag}>`));
304
+ return m ? m[1].replace(/<!\[CDATA\[|\]\]>/g, "").trim() : "";
305
+ };
306
+ items.push({
307
+ title: get("title"),
308
+ link: get("link"),
309
+ pubDate: get("pubDate"),
310
+ description: get("description").replace(/<[^>]+>/g, "").slice(0, 300),
311
+ source: get("source")
312
+ });
313
+ }
314
+ return items;
315
+ }
316
+ var POSITIVE_WORDS = {
317
+ "bullish": 3,
318
+ "surge": 3,
319
+ "rally": 3,
320
+ "soar": 3,
321
+ "winning": 2,
322
+ "gain": 2,
323
+ "positive": 2,
324
+ "strong": 2,
325
+ "confident": 2,
326
+ "optimistic": 3,
327
+ "breakthrough": 3,
328
+ "success": 2,
329
+ "support": 1,
330
+ "lead": 2,
331
+ "ahead": 2,
332
+ "up": 1,
333
+ "rise": 2,
334
+ "good": 1,
335
+ "great": 2,
336
+ "excellent": 3,
337
+ "profit": 2,
338
+ "growth": 2,
339
+ "boom": 3,
340
+ "likely": 2,
341
+ "certain": 3,
342
+ "confirmed": 3,
343
+ "approved": 2,
344
+ "passed": 2,
345
+ "win": 2,
346
+ "victory": 3,
347
+ "dominate": 2,
348
+ "crush": 2,
349
+ "landslide": 3,
350
+ "definitely": 2,
351
+ "absolutely": 2,
352
+ "obvious": 2,
353
+ "clearly": 2,
354
+ "guaranteed": 3,
355
+ "huge": 2,
356
+ "massive": 2,
357
+ "pump": 2,
358
+ "lock": 2,
359
+ "locked": 2,
360
+ "moon": 3,
361
+ "yes": 1,
362
+ "agree": 1,
363
+ "amazing": 2,
364
+ "love": 2
365
+ };
366
+ var NEGATIVE_WORDS = {
367
+ "bearish": -3,
368
+ "crash": -3,
369
+ "plunge": -3,
370
+ "collapse": -3,
371
+ "losing": -2,
372
+ "negative": -2,
373
+ "weak": -2,
374
+ "fear": -2,
375
+ "pessimistic": -3,
376
+ "failure": -3,
377
+ "risk": -1,
378
+ "down": -1,
379
+ "fall": -2,
380
+ "decline": -2,
381
+ "drop": -2,
382
+ "loss": -2,
383
+ "bad": -1,
384
+ "terrible": -3,
385
+ "crisis": -3,
386
+ "panic": -3,
387
+ "dump": -3,
388
+ "unlikely": -2,
389
+ "doubt": -2,
390
+ "uncertain": -1,
391
+ "rejected": -2,
392
+ "failed": -3,
393
+ "lose": -2,
394
+ "defeat": -3,
395
+ "scandal": -3,
396
+ "fraud": -3,
397
+ "manipulation": -3,
398
+ "no": -1,
399
+ "impossible": -3,
400
+ "never": -3,
401
+ "scam": -3,
402
+ "rug": -3,
403
+ "fake": -3,
404
+ "wrong": -2,
405
+ "fail": -3,
406
+ "short": -1,
407
+ "hate": -2,
408
+ "disagree": -2,
409
+ "risky": -2,
410
+ "behind": -1
411
+ };
412
+ function scoreSentiment(text) {
413
+ const words = text.toLowerCase().split(/\s+/);
414
+ let score = 0;
415
+ for (const w of words) {
416
+ const clean = w.replace(/[^a-z]/g, "");
417
+ if (POSITIVE_WORDS[clean]) score += POSITIVE_WORDS[clean];
418
+ if (NEGATIVE_WORDS[clean]) score += NEGATIVE_WORDS[clean];
419
+ }
420
+ return Math.max(-1, Math.min(1, score / Math.max(words.length * 0.1, 1)));
421
+ }
422
+ function extractTopics(text) {
423
+ const patterns = [
424
+ /\b(trump|biden|harris|election|vote|poll)\b/gi,
425
+ /\b(fed|rate|inflation|gdp|jobs|unemployment)\b/gi,
426
+ /\b(bitcoin|btc|eth|crypto|solana)\b/gi,
427
+ /\b(war|conflict|peace|treaty|sanctions)\b/gi,
428
+ /\b(ai|openai|google|microsoft|apple|nvidia)\b/gi,
429
+ /\b(polymarket|prediction|odds|probability)\b/gi
430
+ ];
431
+ const topics = /* @__PURE__ */ new Set();
432
+ for (const p of patterns) {
433
+ const matches = text.match(p) || [];
434
+ for (const m of matches) topics.add(m.toLowerCase());
435
+ }
436
+ return Array.from(topics);
437
+ }
438
+
439
+ export {
440
+ CLOB_API,
441
+ GAMMA_API,
442
+ DATA_API,
443
+ POLYGON_RPC,
444
+ CTF_ADDRESS,
445
+ USDC_ADDRESS,
446
+ getCached,
447
+ setCache,
448
+ checkRateLimit,
449
+ setProxyFetchHook,
450
+ apiFetch,
451
+ cachedFetchJSON,
452
+ cachedFetchText,
453
+ parallelFetch,
454
+ normalCDF,
455
+ normalPDF,
456
+ normalInv,
457
+ linearRegression,
458
+ ewma,
459
+ sma,
460
+ std,
461
+ pearsonCorrelation,
462
+ calculateHurst,
463
+ calculateVolatility,
464
+ parseMarket,
465
+ fetchPriceSeries,
466
+ fetchPriceHistory,
467
+ parseRSSItems,
468
+ POSITIVE_WORDS,
469
+ NEGATIVE_WORDS,
470
+ scoreSentiment,
471
+ extractTopics
472
+ };