@agenticmail/enterprise 0.5.441 → 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.
- package/CHANGELOG.md +34 -0
- package/README.md +3 -2
- package/dist/agent-heartbeat-QJ3WTWUK.js +518 -0
- package/dist/agent-status-CS5NNYIO.js +11 -0
- package/dist/agent-tools-3MD7EPO6.js +14629 -0
- package/dist/agent-tools-62HGQYDL.js +14629 -0
- package/dist/agent-tools-BTUVVOWT.js +14629 -0
- package/dist/agent-tools-BV3JMJPN.js +14629 -0
- package/dist/agent-tools-JVNQ4RPM.js +14629 -0
- package/dist/agent-tools-LD7LELVT.js +14629 -0
- package/dist/agent-tools-NRKQ5NMW.js +14629 -0
- package/dist/agent-tools-OXZJOD4D.js +14629 -0
- package/dist/agent-tools-PT2ES6G5.js +14629 -0
- package/dist/agent-tools-SS335E2E.js +14629 -0
- package/dist/chunk-2ACTQSPC.js +1728 -0
- package/dist/chunk-2XZE5NT3.js +5387 -0
- package/dist/chunk-325NTNE6.js +2180 -0
- package/dist/chunk-3AHKVWCO.js +5387 -0
- package/dist/chunk-3DM6QDVR.js +1728 -0
- package/dist/chunk-3L2N6LR2.js +7517 -0
- package/dist/chunk-3XP7VYIS.js +7437 -0
- package/dist/chunk-3ZD3XOV6.js +1728 -0
- package/dist/chunk-44VXWYPE.js +2570 -0
- package/dist/chunk-4UOSUXFR.js +7529 -0
- package/dist/chunk-54SHHX2S.js +2180 -0
- package/dist/chunk-5DVY3CNK.js +1728 -0
- package/dist/chunk-5F5DGV63.js +5596 -0
- package/dist/chunk-6IUUOWZY.js +7526 -0
- package/dist/chunk-77LFFLQX.js +7526 -0
- package/dist/chunk-7BKNDBSA.js +2191 -0
- package/dist/chunk-7BS2XPLW.js +5359 -0
- package/dist/chunk-7GCSGDXQ.js +1636 -0
- package/dist/chunk-7IAI45PR.js +4735 -0
- package/dist/chunk-7QPZGO27.js +4976 -0
- package/dist/chunk-7S5XAXRD.js +4747 -0
- package/dist/chunk-AD6ZR3QD.js +5357 -0
- package/dist/chunk-AO556OXZ.js +2570 -0
- package/dist/chunk-APUWQHXC.js +7437 -0
- package/dist/chunk-BKSSHV6C.js +1728 -0
- package/dist/chunk-BMUNQHLU.js +1208 -0
- package/dist/chunk-BPF5DKUM.js +392 -0
- package/dist/chunk-CFR5OSMI.js +1220 -0
- package/dist/chunk-CM4GUHXP.js +1728 -0
- package/dist/chunk-CVFIM72Q.js +501 -0
- package/dist/chunk-DFXVJNKW.js +4734 -0
- package/dist/chunk-DJ7LHRL7.js +2214 -0
- package/dist/chunk-DJFI6NR6.js +1624 -0
- package/dist/chunk-DJHYV5VY.js +1624 -0
- package/dist/chunk-DYM4PQO3.js +4727 -0
- package/dist/chunk-DZ75RF35.js +1728 -0
- package/dist/chunk-E5H64U5H.js +472 -0
- package/dist/chunk-EOD4EGFI.js +1728 -0
- package/dist/chunk-EP74QR5B.js +4980 -0
- package/dist/chunk-FE2M4FV5.js +5273 -0
- package/dist/chunk-FQWJMPKW.js +305 -0
- package/dist/chunk-FUH6NWIX.js +7540 -0
- package/dist/chunk-G5ADHHAD.js +1728 -0
- package/dist/chunk-GAYLPSM7.js +7529 -0
- package/dist/chunk-GDAFZJTJ.js +7540 -0
- package/dist/chunk-GLAN2JBA.js +1636 -0
- package/dist/chunk-GNAEBGU7.js +4812 -0
- package/dist/chunk-HDDA2Q3Q.js +1728 -0
- package/dist/chunk-HG62FWWQ.js +7437 -0
- package/dist/chunk-HV5VIS5K.js +1624 -0
- package/dist/chunk-IEVA23WK.js +4976 -0
- package/dist/chunk-IFMZ2IYC.js +7540 -0
- package/dist/chunk-IN7VIORK.js +2641 -0
- package/dist/chunk-KAX3ZDP2.js +7529 -0
- package/dist/chunk-KECO53GP.js +1728 -0
- package/dist/chunk-KGZ74UMA.js +1728 -0
- package/dist/chunk-M2ZLRUMX.js +7540 -0
- package/dist/chunk-MKQWC6KF.js +5374 -0
- package/dist/chunk-MQ3JBGLU.js +1636 -0
- package/dist/chunk-MVB6JARX.js +7529 -0
- package/dist/chunk-N37MOOFE.js +2210 -0
- package/dist/chunk-NELCAZUQ.js +5357 -0
- package/dist/chunk-NHLOKTUV.js +26305 -0
- package/dist/chunk-OPAO5QQS.js +1728 -0
- package/dist/chunk-OUHU3VW6.js +1728 -0
- package/dist/chunk-OWEXZVZ6.js +1728 -0
- package/dist/chunk-P4DHSJJY.js +7437 -0
- package/dist/chunk-Q7QA6MNJ.js +1728 -0
- package/dist/chunk-QKKTNPGV.js +7592 -0
- package/dist/chunk-REMMXZVU.js +7529 -0
- package/dist/chunk-RK3KATD4.js +4756 -0
- package/dist/chunk-RQ33L5T3.js +5374 -0
- package/dist/chunk-RU77F65Q.js +1728 -0
- package/dist/chunk-SAM3CVIU.js +5374 -0
- package/dist/chunk-SFMXIKWZ.js +1728 -0
- package/dist/chunk-SPZ5JBGW.js +1624 -0
- package/dist/chunk-TDOC6WSK.js +7529 -0
- package/dist/chunk-TPMT5WTW.js +5357 -0
- package/dist/chunk-TVXUR3PB.js +2180 -0
- package/dist/chunk-TZEEVEKG.js +5343 -0
- package/dist/chunk-U327O3ZR.js +7540 -0
- package/dist/chunk-ULD6C5DB.js +2180 -0
- package/dist/chunk-ULVRCJZV.js +5374 -0
- package/dist/chunk-UOCDOM2S.js +1624 -0
- package/dist/chunk-VINDZLLX.js +1636 -0
- package/dist/chunk-VODW5GJL.js +2180 -0
- package/dist/chunk-WEWL7Z3C.js +2180 -0
- package/dist/chunk-WG2MEMS6.js +5343 -0
- package/dist/chunk-WYV6QWOJ.js +1188 -0
- package/dist/chunk-X5AIAD77.js +1636 -0
- package/dist/chunk-XUETIRDV.js +2214 -0
- package/dist/chunk-XWSMX7RK.js +7529 -0
- package/dist/chunk-YUSYXHKB.js +1728 -0
- package/dist/chunk-ZC2RMHQD.js +5374 -0
- package/dist/chunk-ZDZQQGFG.js +5374 -0
- package/dist/chunk-ZJ2HCWKF.js +1728 -0
- package/dist/chunk-ZK4QCOJ5.js +5273 -0
- package/dist/chunk-ZMKVEJKR.js +392 -0
- package/dist/cli-agent-2UFGFO24.js +2761 -0
- package/dist/cli-agent-5FPUCFPG.js +2761 -0
- package/dist/cli-agent-7AB6NIYQ.js +2761 -0
- package/dist/cli-agent-7CAFSYOM.js +2761 -0
- package/dist/cli-agent-7OVOINHR.js +2757 -0
- package/dist/cli-agent-AWKBFIRS.js +2761 -0
- package/dist/cli-agent-ES3XOPHJ.js +2757 -0
- package/dist/cli-agent-FSO2N7I6.js +2757 -0
- package/dist/cli-agent-KPXZN5JK.js +2761 -0
- package/dist/cli-agent-LGTCFHGS.js +2757 -0
- package/dist/cli-agent-LLUYUHHF.js +2757 -0
- package/dist/cli-agent-NHZWYX5Q.js +2761 -0
- package/dist/cli-agent-TYUOTYCO.js +2757 -0
- package/dist/cli-agent-VQO6HI65.js +2757 -0
- package/dist/cli-agent-VV5JWRU7.js +2757 -0
- package/dist/cli-agent-Z5B23XED.js +2757 -0
- package/dist/cli-serve-2FLQXJW7.js +322 -0
- package/dist/cli-serve-34YFCCUX.js +322 -0
- package/dist/cli-serve-3NS6MNUS.js +322 -0
- package/dist/cli-serve-4PWFEPNA.js +322 -0
- package/dist/cli-serve-4VIBMXMT.js +322 -0
- package/dist/cli-serve-5ZUF5MGH.js +322 -0
- package/dist/cli-serve-6HGL56GB.js +322 -0
- package/dist/cli-serve-BBBWEKKW.js +322 -0
- package/dist/cli-serve-D2HQC4SB.js +322 -0
- package/dist/cli-serve-IKCMNUNM.js +322 -0
- package/dist/cli-serve-LTUKYMEF.js +322 -0
- package/dist/cli-serve-MIWI5PBE.js +322 -0
- package/dist/cli-serve-R6K4SZ3L.js +322 -0
- package/dist/cli-serve-RQIOBQGF.js +322 -0
- package/dist/cli-serve-S57ROYQ6.js +322 -0
- package/dist/cli-serve-WVSLOISY.js +322 -0
- package/dist/cli-serve-XDFSJIQV.js +322 -0
- package/dist/cli-serve-YKZSNR3P.js +322 -0
- package/dist/cli-serve-ZGKXWDMZ.js +322 -0
- package/dist/cli-serve-ZZOJWREY.js +322 -0
- package/dist/cli.js +3 -3
- package/dist/dashboard/components/utils.js +1 -1
- package/dist/dashboard/docs/polymarket.html +1 -1
- package/dist/dashboard/pages/polymarket.js +222 -80
- package/dist/index.js +12 -12
- package/dist/pipeline-C4C3ZF4X.js +15 -0
- package/dist/pipeline-DAF3EV7Q.js +15 -0
- package/dist/pipeline-MMESLRQG.js +15 -0
- package/dist/polymarket-3LGJSQZK.js +17 -0
- package/dist/polymarket-4OIWQFBO.js +17 -0
- package/dist/polymarket-AZEV7C6E.js +17 -0
- package/dist/polymarket-DBQYJC57.js +7 -0
- package/dist/polymarket-EVTKWLUO.js +7 -0
- package/dist/polymarket-GMKDVVQH.js +17 -0
- package/dist/polymarket-HZOAD4W4.js +17 -0
- package/dist/polymarket-PKGRF7ID.js +17 -0
- package/dist/polymarket-QUNR2H7U.js +17 -0
- package/dist/polymarket-TM624BN5.js +17 -0
- package/dist/polymarket-VT2EDGD7.js +17 -0
- package/dist/polymarket-W7B4TLP3.js +17 -0
- package/dist/polymarket-WS4VE6U7.js +7 -0
- package/dist/polymarket-runtime-772ADZJW.js +108 -0
- package/dist/polymarket-runtime-AIYHQKYQ.js +108 -0
- package/dist/polymarket-runtime-APJ5HW4Y.js +108 -0
- package/dist/polymarket-runtime-BX3ODZZD.js +108 -0
- package/dist/polymarket-runtime-ISD4CKKL.js +108 -0
- package/dist/polymarket-runtime-JU4PQZGJ.js +108 -0
- package/dist/polymarket-runtime-OFLBSPCK.js +108 -0
- package/dist/polymarket-runtime-POJRRWFS.js +108 -0
- package/dist/polymarket-runtime-XN5TVHU5.js +108 -0
- package/dist/polymarket-runtime-ZYFTKEJ4.js +108 -0
- package/dist/polymarket-watcher-2CKLTIXI.js +23 -0
- package/dist/polymarket-watcher-3C72X36B.js +23 -0
- package/dist/polymarket-watcher-IHRZ2URM.js +23 -0
- package/dist/polymarket-watcher-J7UWIN7I.js +23 -0
- package/dist/polymarket-watcher-M6CDW63Y.js +23 -0
- package/dist/polymarket-watcher-OSI73EDX.js +23 -0
- package/dist/polymarket-watcher-PN4JJV3V.js +23 -0
- package/dist/polymarket-watcher-PXK4NS5F.js +23 -0
- package/dist/polymarket-watcher-VDJ4SVHP.js +23 -0
- package/dist/polymarket-watcher-W4BV6JTG.js +23 -0
- package/dist/routes-PRBWZ4MQ.js +94 -0
- package/dist/runtime-22E2WCL6.js +46 -0
- package/dist/runtime-7GYS4FQU.js +46 -0
- package/dist/runtime-7OVDHKNW.js +46 -0
- package/dist/runtime-BR6K3Q3N.js +46 -0
- package/dist/runtime-CTTRDVJ6.js +46 -0
- package/dist/runtime-GIIPTHK5.js +46 -0
- package/dist/runtime-HYAKLZWI.js +46 -0
- package/dist/runtime-IQ2KIV2L.js +50 -0
- package/dist/runtime-ISXECIAB.js +46 -0
- package/dist/runtime-IV4BY7S4.js +46 -0
- package/dist/runtime-O65GGHL2.js +46 -0
- package/dist/runtime-PKHEGQYK.js +50 -0
- package/dist/runtime-RFKPIFK4.js +46 -0
- package/dist/runtime-S35B6PIY.js +46 -0
- package/dist/runtime-WEZJ4YRK.js +46 -0
- package/dist/runtime-WLWB62ZI.js +46 -0
- package/dist/screener-FB47G4YX.js +26 -0
- package/dist/screener-WQVQO4WF.js +26 -0
- package/dist/server-6GWGIGBH.js +36 -0
- package/dist/server-7VZ6XXBC.js +36 -0
- package/dist/server-7XBTD3FW.js +36 -0
- package/dist/server-BN56IMC4.js +36 -0
- package/dist/server-GD6SPDER.js +36 -0
- package/dist/server-IJHU2FIK.js +36 -0
- package/dist/server-J5WZGZX3.js +36 -0
- package/dist/server-JVUH2E3H.js +36 -0
- package/dist/server-MYXWTXSE.js +36 -0
- package/dist/server-ORGV7O7L.js +36 -0
- package/dist/server-QPE3WVUQ.js +36 -0
- package/dist/server-SUBGS5BJ.js +36 -0
- package/dist/server-SWAYJTFF.js +36 -0
- package/dist/server-TFIWDU2H.js +36 -0
- package/dist/server-VH4W6LWW.js +36 -0
- package/dist/server-WQXRTEKF.js +36 -0
- package/dist/server-X5UMJJ3J.js +36 -0
- package/dist/server-XOK5LHNU.js +36 -0
- package/dist/server-ZLK24KFY.js +36 -0
- package/dist/server-ZNSQGCRM.js +36 -0
- package/dist/setup-32ZRMW7R.js +20 -0
- package/dist/setup-3WF7PBIS.js +20 -0
- package/dist/setup-4TM64QG4.js +20 -0
- package/dist/setup-5SGUMKN7.js +20 -0
- package/dist/setup-7ENTPINX.js +20 -0
- package/dist/setup-AGYKOCIU.js +20 -0
- package/dist/setup-EIP4IHZN.js +20 -0
- package/dist/setup-F5SAGQJJ.js +20 -0
- package/dist/setup-LMF76UUM.js +20 -0
- package/dist/setup-MA5QR3J4.js +20 -0
- package/dist/setup-MLIPR2U3.js +20 -0
- package/dist/setup-MLIZYTT6.js +20 -0
- package/dist/setup-OPVZ3GM7.js +20 -0
- package/dist/setup-PWFHUXOK.js +20 -0
- package/dist/setup-QF5GCTPE.js +20 -0
- package/dist/setup-SGF4OX3A.js +20 -0
- package/dist/setup-TLWKGWC6.js +20 -0
- package/dist/setup-TYCRH63P.js +20 -0
- package/dist/setup-USUBKTVX.js +20 -0
- package/dist/setup-VMNTNEB4.js +20 -0
- package/dist/shared-S5ROHYCX.js +69 -0
- package/dist/shared-TLWZZZSK.js +69 -0
- package/dist/system-prompts-7ZRL27FN.js +69 -0
- package/dist/system-prompts-CNXUF2AV.js +69 -0
- package/dist/system-prompts-SYGQRBRG.js +69 -0
- package/logs/cloudflared-error.log +4 -57
- package/logs/cloudflared-error__2026-03-11_00-00-00.log +289 -0
- package/package.json +1 -1
- package/logs/cloudflared-error__2026-03-06_00-00-00.log +0 -245
|
@@ -0,0 +1,501 @@
|
|
|
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
|
+
// US Politics
|
|
425
|
+
/\b(trump|desantis|vance|newsom|rfk|kennedy|obama|pence|haley|ramaswamy|whitmer|shapiro)\b/gi,
|
|
426
|
+
/\b(election|vote|poll|primary|caucus|electoral|congress|senate|house|midterm|inauguration|impeach|indictment|scotus|supreme\s*court)\b/gi,
|
|
427
|
+
/\b(republican|democrat|gop|dnc|rnc|maga|progressive|conservative|liberal)\b/gi,
|
|
428
|
+
// Global Politics & Geopolitics
|
|
429
|
+
/\b(putin|zelensky|xi\s*jinping|modi|macron|starmer|trudeau|netanyahu|erdogan|lula|milei|bukele|maduro)\b/gi,
|
|
430
|
+
/\b(nato|eu|un|brics|g7|g20|opec|who|imf|world\s*bank)\b/gi,
|
|
431
|
+
/\b(war|conflict|peace|treaty|sanctions|ceasefire|invasion|annexation|coup|regime|refugee|nuclear|missile|drone)\b/gi,
|
|
432
|
+
/\b(ukraine|russia|china|taiwan|israel|palestine|gaza|iran|north\s*korea|syria|yemen|sudan|venezuela)\b/gi,
|
|
433
|
+
// Economics & Finance
|
|
434
|
+
/\b(fed|federal\s*reserve|rate\s*cut|rate\s*hike|inflation|cpi|ppi|gdp|jobs|unemployment|payroll|nonfarm|recession|stagflation|deficit|debt\s*ceiling)\b/gi,
|
|
435
|
+
/\b(stock|s&p|nasdaq|dow|russell|vix|bond|yield|treasury|commodity|oil|gold|silver|copper)\b/gi,
|
|
436
|
+
/\b(tariff|trade\s*war|sanctions|embargo|subsidy|stimulus|bailout|default)\b/gi,
|
|
437
|
+
// Crypto & Web3
|
|
438
|
+
/\b(bitcoin|btc|ethereum|eth|solana|sol|xrp|ripple|cardano|ada|polygon|matic|avalanche|avax|chainlink|link)\b/gi,
|
|
439
|
+
/\b(crypto|defi|nft|web3|blockchain|stablecoin|usdc|usdt|tether|binance|coinbase|sec\s*crypto|etf|halving|altcoin|memecoin|doge|shib|pepe)\b/gi,
|
|
440
|
+
// Tech & AI
|
|
441
|
+
/\b(ai|artificial\s*intelligence|openai|chatgpt|gpt|claude|anthropic|gemini|llama|meta\s*ai|deepseek|mistral|copilot)\b/gi,
|
|
442
|
+
/\b(google|microsoft|apple|nvidia|amazon|meta|tesla|spacex|neuralink|twitter|tiktok|bytedance|samsung|tsmc|intel|amd)\b/gi,
|
|
443
|
+
/\b(agi|superintelligence|robotics|autonomous|self-driving|quantum|fusion|biotech|crispr|mrna)\b/gi,
|
|
444
|
+
// Sports
|
|
445
|
+
/\b(nfl|nba|mlb|nhl|mls|premier\s*league|champions\s*league|world\s*cup|olympics|super\s*bowl|march\s*madness|wimbledon|us\s*open)\b/gi,
|
|
446
|
+
/\b(lebron|curry|mahomes|messi|ronaldo|haaland|ohtani|djokovic|verstappen|hamilton)\b/gi,
|
|
447
|
+
/\b(ufc|mma|boxing|f1|formula\s*1|pga|golf|tennis|soccer|football|basketball|baseball|hockey)\b/gi,
|
|
448
|
+
// Entertainment & Culture
|
|
449
|
+
/\b(oscars|grammys|emmys|golden\s*globe|box\s*office|netflix|disney|spotify|youtube|twitch|podcast)\b/gi,
|
|
450
|
+
/\b(taylor\s*swift|drake|kanye|beyonce|rihanna|elon\s*musk|zuckerberg|bezos|mrbeast)\b/gi,
|
|
451
|
+
// Science, Health & Climate
|
|
452
|
+
/\b(covid|pandemic|vaccine|fda|who|bird\s*flu|mpox|outbreak|epidemic)\b/gi,
|
|
453
|
+
/\b(climate|hurricane|earthquake|wildfire|flood|drought|tornado|emissions|carbon|renewable|solar|wind\s*energy)\b/gi,
|
|
454
|
+
/\b(nasa|spacex|mars|moon|asteroid|satellite|rocket|launch|starship|artemis)\b/gi,
|
|
455
|
+
// Polymarket-specific
|
|
456
|
+
/\b(polymarket|prediction\s*market|odds|probability|resolve|resolution|outcome)\b/gi,
|
|
457
|
+
// Regulation & Legal
|
|
458
|
+
/\b(regulation|legislation|ban|legalize|antitrust|monopoly|privacy|surveillance|whistleblower|classified|espionage)\b/gi
|
|
459
|
+
];
|
|
460
|
+
const topics = /* @__PURE__ */ new Set();
|
|
461
|
+
for (const p of patterns) {
|
|
462
|
+
const matches = text.match(p) || [];
|
|
463
|
+
for (const m of matches) topics.add(m.toLowerCase().trim());
|
|
464
|
+
}
|
|
465
|
+
return Array.from(topics);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
export {
|
|
469
|
+
CLOB_API,
|
|
470
|
+
GAMMA_API,
|
|
471
|
+
DATA_API,
|
|
472
|
+
POLYGON_RPC,
|
|
473
|
+
CTF_ADDRESS,
|
|
474
|
+
USDC_ADDRESS,
|
|
475
|
+
getCached,
|
|
476
|
+
setCache,
|
|
477
|
+
checkRateLimit,
|
|
478
|
+
setProxyFetchHook,
|
|
479
|
+
apiFetch,
|
|
480
|
+
cachedFetchJSON,
|
|
481
|
+
cachedFetchText,
|
|
482
|
+
parallelFetch,
|
|
483
|
+
normalCDF,
|
|
484
|
+
normalPDF,
|
|
485
|
+
normalInv,
|
|
486
|
+
linearRegression,
|
|
487
|
+
ewma,
|
|
488
|
+
sma,
|
|
489
|
+
std,
|
|
490
|
+
pearsonCorrelation,
|
|
491
|
+
calculateHurst,
|
|
492
|
+
calculateVolatility,
|
|
493
|
+
parseMarket,
|
|
494
|
+
fetchPriceSeries,
|
|
495
|
+
fetchPriceHistory,
|
|
496
|
+
parseRSSItems,
|
|
497
|
+
POSITIVE_WORDS,
|
|
498
|
+
NEGATIVE_WORDS,
|
|
499
|
+
scoreSentiment,
|
|
500
|
+
extractTopics
|
|
501
|
+
};
|