oculon 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +344 -2
- package/dist/agent.d.ts +47 -0
- package/dist/agent.js +104 -0
- package/dist/cases.d.ts +68 -0
- package/dist/cases.js +158 -0
- package/dist/cli/main.d.ts +12 -0
- package/dist/cli/main.js +1999 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +15 -0
- package/dist/core/context.d.ts +19 -0
- package/dist/core/context.js +19 -0
- package/dist/core/features.d.ts +22 -0
- package/dist/core/features.js +28 -0
- package/dist/core/graph.d.ts +38 -0
- package/dist/core/graph.js +81 -0
- package/dist/core/http.d.ts +42 -0
- package/dist/core/http.js +266 -0
- package/dist/core/keys.d.ts +8 -0
- package/dist/core/keys.js +22 -0
- package/dist/core/llm.d.ts +93 -0
- package/dist/core/llm.js +180 -0
- package/dist/core/merkle.d.ts +15 -0
- package/dist/core/merkle.js +46 -0
- package/dist/core/paths.d.ts +2 -0
- package/dist/core/paths.js +6 -0
- package/dist/core/png.d.ts +17 -0
- package/dist/core/png.js +101 -0
- package/dist/core/quota.d.ts +15 -0
- package/dist/core/quota.js +90 -0
- package/dist/core/stats.d.ts +24 -0
- package/dist/core/stats.js +67 -0
- package/dist/core/store.d.ts +20 -0
- package/dist/core/store.js +213 -0
- package/dist/core/text.d.ts +9 -0
- package/dist/core/text.js +30 -0
- package/dist/core/types.d.ts +38 -0
- package/dist/core/types.js +1 -0
- package/dist/index.d.ts +342 -0
- package/dist/index.js +495 -0
- package/dist/live.d.ts +53 -0
- package/dist/live.js +236 -0
- package/dist/mcp.d.ts +43 -0
- package/dist/mcp.js +651 -0
- package/dist/modules/airport.d.ts +60 -0
- package/dist/modules/airport.js +111 -0
- package/dist/modules/audit.d.ts +73 -0
- package/dist/modules/audit.js +211 -0
- package/dist/modules/bgp.d.ts +147 -0
- package/dist/modules/bgp.js +206 -0
- package/dist/modules/blackout.d.ts +41 -0
- package/dist/modules/blackout.js +98 -0
- package/dist/modules/brief.d.ts +26 -0
- package/dist/modules/brief.js +99 -0
- package/dist/modules/calendar.d.ts +27 -0
- package/dist/modules/calendar.js +145 -0
- package/dist/modules/calibrate.d.ts +46 -0
- package/dist/modules/calibrate.js +92 -0
- package/dist/modules/cloud.d.ts +32 -0
- package/dist/modules/cloud.js +94 -0
- package/dist/modules/condor.d.ts +66 -0
- package/dist/modules/condor.js +214 -0
- package/dist/modules/connect.d.ts +47 -0
- package/dist/modules/connect.js +114 -0
- package/dist/modules/contradictions.d.ts +27 -0
- package/dist/modules/contradictions.js +76 -0
- package/dist/modules/country.d.ts +82 -0
- package/dist/modules/country.js +136 -0
- package/dist/modules/cricket.d.ts +34 -0
- package/dist/modules/cricket.js +166 -0
- package/dist/modules/darkships.d.ts +219 -0
- package/dist/modules/darkships.js +400 -0
- package/dist/modules/defi.d.ts +237 -0
- package/dist/modules/defi.js +512 -0
- package/dist/modules/emailsec.d.ts +47 -0
- package/dist/modules/emailsec.js +146 -0
- package/dist/modules/exposure.d.ts +43 -0
- package/dist/modules/exposure.js +89 -0
- package/dist/modules/factcheck.d.ts +39 -0
- package/dist/modules/factcheck.js +127 -0
- package/dist/modules/falcon.d.ts +58 -0
- package/dist/modules/falcon.js +219 -0
- package/dist/modules/feedback.d.ts +24 -0
- package/dist/modules/feedback.js +37 -0
- package/dist/modules/fence.d.ts +52 -0
- package/dist/modules/fence.js +128 -0
- package/dist/modules/ferret.d.ts +47 -0
- package/dist/modules/ferret.js +220 -0
- package/dist/modules/filings.d.ts +86 -0
- package/dist/modules/filings.js +166 -0
- package/dist/modules/fires.d.ts +56 -0
- package/dist/modules/fires.js +150 -0
- package/dist/modules/hazards.d.ts +37 -0
- package/dist/modules/hazards.js +83 -0
- package/dist/modules/health.d.ts +24 -0
- package/dist/modules/health.js +82 -0
- package/dist/modules/heron.d.ts +68 -0
- package/dist/modules/heron.js +184 -0
- package/dist/modules/hound.d.ts +100 -0
- package/dist/modules/hound.js +301 -0
- package/dist/modules/impact.d.ts +39 -0
- package/dist/modules/impact.js +63 -0
- package/dist/modules/launches.d.ts +24 -0
- package/dist/modules/launches.js +61 -0
- package/dist/modules/listen.d.ts +48 -0
- package/dist/modules/listen.js +125 -0
- package/dist/modules/lynx.d.ts +43 -0
- package/dist/modules/lynx.js +127 -0
- package/dist/modules/magpie.d.ts +70 -0
- package/dist/modules/magpie.js +174 -0
- package/dist/modules/meerkat.d.ts +42 -0
- package/dist/modules/meerkat.js +293 -0
- package/dist/modules/monitor.d.ts +27 -0
- package/dist/modules/monitor.js +105 -0
- package/dist/modules/narratives.d.ts +33 -0
- package/dist/modules/narratives.js +136 -0
- package/dist/modules/owl.d.ts +71 -0
- package/dist/modules/owl.js +290 -0
- package/dist/modules/papers.d.ts +46 -0
- package/dist/modules/papers.js +135 -0
- package/dist/modules/personal.d.ts +54 -0
- package/dist/modules/personal.js +153 -0
- package/dist/modules/pulse.d.ts +19 -0
- package/dist/modules/pulse.js +59 -0
- package/dist/modules/raven.d.ts +80 -0
- package/dist/modules/raven.js +147 -0
- package/dist/modules/recall.d.ts +44 -0
- package/dist/modules/recall.js +123 -0
- package/dist/modules/regs.d.ts +88 -0
- package/dist/modules/regs.js +142 -0
- package/dist/modules/rewind.d.ts +22 -0
- package/dist/modules/rewind.js +68 -0
- package/dist/modules/sanctions.d.ts +62 -0
- package/dist/modules/sanctions.js +173 -0
- package/dist/modules/scam.d.ts +43 -0
- package/dist/modules/scam.js +111 -0
- package/dist/modules/scoop.d.ts +31 -0
- package/dist/modules/scoop.js +74 -0
- package/dist/modules/ships.d.ts +33 -0
- package/dist/modules/ships.js +113 -0
- package/dist/modules/sky.d.ts +47 -0
- package/dist/modules/sky.js +183 -0
- package/dist/modules/squawk.d.ts +46 -0
- package/dist/modules/squawk.js +106 -0
- package/dist/modules/tortoise.d.ts +40 -0
- package/dist/modules/tortoise.js +104 -0
- package/dist/modules/travel.d.ts +94 -0
- package/dist/modules/travel.js +241 -0
- package/dist/modules/urlcheck.d.ts +63 -0
- package/dist/modules/urlcheck.js +223 -0
- package/dist/modules/vulns.d.ts +142 -0
- package/dist/modules/vulns.js +276 -0
- package/dist/plugins.d.ts +41 -0
- package/dist/plugins.js +70 -0
- package/dist/report.d.ts +12 -0
- package/dist/report.js +90 -0
- package/dist/scheduler.d.ts +22 -0
- package/dist/scheduler.js +139 -0
- package/dist/sources/aircraft.d.ts +76 -0
- package/dist/sources/aircraft.js +107 -0
- package/dist/sources/airports.d.ts +28 -0
- package/dist/sources/airports.js +100 -0
- package/dist/sources/ais.d.ts +32 -0
- package/dist/sources/ais.js +111 -0
- package/dist/sources/apify.d.ts +28 -0
- package/dist/sources/apify.js +80 -0
- package/dist/sources/arxiv.d.ts +13 -0
- package/dist/sources/arxiv.js +27 -0
- package/dist/sources/certs.d.ts +12 -0
- package/dist/sources/certs.js +23 -0
- package/dist/sources/corp.d.ts +46 -0
- package/dist/sources/corp.js +60 -0
- package/dist/sources/earth.d.ts +39 -0
- package/dist/sources/earth.js +76 -0
- package/dist/sources/fda.d.ts +77 -0
- package/dist/sources/fda.js +121 -0
- package/dist/sources/finance.d.ts +181 -0
- package/dist/sources/finance.js +270 -0
- package/dist/sources/gdelt.d.ts +19 -0
- package/dist/sources/gdelt.js +33 -0
- package/dist/sources/github.d.ts +17 -0
- package/dist/sources/github.js +33 -0
- package/dist/sources/hackernews.d.ts +20 -0
- package/dist/sources/hackernews.js +37 -0
- package/dist/sources/labels.d.ts +21 -0
- package/dist/sources/labels.js +87 -0
- package/dist/sources/launch.d.ts +16 -0
- package/dist/sources/launch.js +41 -0
- package/dist/sources/ofac.d.ts +29 -0
- package/dist/sources/ofac.js +86 -0
- package/dist/sources/onchain.d.ts +77 -0
- package/dist/sources/onchain.js +189 -0
- package/dist/sources/opentimestamps.d.ts +44 -0
- package/dist/sources/opentimestamps.js +131 -0
- package/dist/sources/polymarket.d.ts +36 -0
- package/dist/sources/polymarket.js +70 -0
- package/dist/sources/predict.d.ts +18 -0
- package/dist/sources/predict.js +59 -0
- package/dist/sources/press.d.ts +30 -0
- package/dist/sources/press.js +111 -0
- package/dist/sources/resend.d.ts +14 -0
- package/dist/sources/resend.js +29 -0
- package/dist/sources/robinhood.d.ts +109 -0
- package/dist/sources/robinhood.js +129 -0
- package/dist/sources/sec.d.ts +67 -0
- package/dist/sources/sec.js +129 -0
- package/dist/sources/sentinel.d.ts +13 -0
- package/dist/sources/sentinel.js +63 -0
- package/dist/sources/signatures.d.ts +14 -0
- package/dist/sources/signatures.js +103 -0
- package/dist/sources/social.d.ts +22 -0
- package/dist/sources/social.js +56 -0
- package/dist/sources/space.d.ts +160 -0
- package/dist/sources/space.js +230 -0
- package/dist/sources/usgs.d.ts +17 -0
- package/dist/sources/usgs.js +24 -0
- package/dist/sources/wayback.d.ts +10 -0
- package/dist/sources/wayback.js +28 -0
- package/dist/sources/websec.d.ts +19 -0
- package/dist/sources/websec.js +40 -0
- package/dist/sources/wikidata.d.ts +11 -0
- package/dist/sources/wikidata.js +30 -0
- package/dist/sources/wikimedia.d.ts +28 -0
- package/dist/sources/wikimedia.js +52 -0
- package/dist/telegram.d.ts +104 -0
- package/dist/telegram.js +927 -0
- package/dist/web/assets/favicon-32.png +0 -0
- package/dist/web/assets/fx.js +178 -0
- package/dist/web/assets/icon-192.png +0 -0
- package/dist/web/assets/icon-512.png +0 -0
- package/dist/web/assets/icon-maskable-512.png +0 -0
- package/dist/web/assets/night-americas.jpg +0 -0
- package/dist/web/assets/night-emea.jpg +0 -0
- package/dist/web/assets/og.png +0 -0
- package/dist/web/assets/redsea-bm.jpg +0 -0
- package/dist/web/docs.html +263 -0
- package/dist/web/index.html +1828 -0
- package/dist/web/insights.d.ts +100 -0
- package/dist/web/insights.js +134 -0
- package/dist/web/landing.html +1143 -0
- package/dist/web/legal.html +176 -0
- package/dist/web/manifest.webmanifest +20 -0
- package/dist/web/mcp.html +104 -0
- package/dist/web/mcphttp.d.ts +10 -0
- package/dist/web/mcphttp.js +67 -0
- package/dist/web/openapi.d.ts +1 -0
- package/dist/web/openapi.js +51 -0
- package/dist/web/public.d.ts +45 -0
- package/dist/web/public.js +135 -0
- package/dist/web/server.d.ts +69 -0
- package/dist/web/server.js +750 -0
- package/dist/web/share.d.ts +35 -0
- package/dist/web/share.js +132 -0
- package/dist/web/sw.js +28 -0
- package/package.json +60 -4
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Listen: turn audio into evidence. Transcribes any public audio or video file URL with Deepgram (pay per
|
|
3
|
+
* minute; free starting credit), then reports a summary, topics, and every passage that mentions the subject
|
|
4
|
+
* with its timestamp. `podcast()` finds recent episodes about a subject through the iTunes podcast directory
|
|
5
|
+
* and transcribes the newest one.
|
|
6
|
+
*/
|
|
7
|
+
import { enc } from '../core/context.js';
|
|
8
|
+
import { key, missingKey } from '../core/keys.js';
|
|
9
|
+
import { keywords } from '../core/text.js';
|
|
10
|
+
const DG_URL = 'https://api.deepgram.com/v1/listen?model=nova-3&smart_format=true¶graphs=true&summarize=v2&topics=true&detect_language=true';
|
|
11
|
+
export const fmtTime = (s) => `${Math.floor(s / 3600) ? `${Math.floor(s / 3600)}:` : ''}${String(Math.floor((s % 3600) / 60)).padStart(2, '0')}:${String(Math.floor(s % 60)).padStart(2, '0')}`;
|
|
12
|
+
/** Sentences that mention any keyword of the subject, merged when close together. */
|
|
13
|
+
export function findMentions(sentences, subject, max = 12) {
|
|
14
|
+
const keys = [...keywords(subject)];
|
|
15
|
+
if (!keys.length)
|
|
16
|
+
return [];
|
|
17
|
+
const out = [];
|
|
18
|
+
for (let i = 0; i < sentences.length && out.length < max; i++) {
|
|
19
|
+
const s = sentences[i];
|
|
20
|
+
if (!keys.some((k) => new RegExp(`\\b${k.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`, 'i').test(s.text)))
|
|
21
|
+
continue;
|
|
22
|
+
const ctxText = [sentences[i - 1]?.text, s.text, sentences[i + 1]?.text].filter(Boolean).join(' ');
|
|
23
|
+
const last = out[out.length - 1];
|
|
24
|
+
if (last && s.start - last.start < 30)
|
|
25
|
+
continue;
|
|
26
|
+
out.push({ start: Math.max(0, sentences[i - 1]?.start ?? s.start), text: ctxText.slice(0, 600) });
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
export async function transcribe(ctx, url, subject = '', title = null) {
|
|
31
|
+
const now = ctx.now().toISOString();
|
|
32
|
+
const provenance = [];
|
|
33
|
+
const empty = (p) => ({ module: 'listen', input: url, generatedAt: now, result: null, signals: [], provenance: [...provenance, p] });
|
|
34
|
+
const k = key('DEEPGRAM_API_KEY');
|
|
35
|
+
if (!k)
|
|
36
|
+
return empty(missingKey('deepgram', 'DEEPGRAM_API_KEY'));
|
|
37
|
+
if (!/^https?:\/\//.test(url))
|
|
38
|
+
throw new Error('give a public http(s) URL of an audio or video file');
|
|
39
|
+
const cacheKey = `derived:deepgram:${url}`;
|
|
40
|
+
const cached = ctx.store.cacheGet(cacheKey);
|
|
41
|
+
let j;
|
|
42
|
+
if (cached) {
|
|
43
|
+
j = JSON.parse(cached.body);
|
|
44
|
+
provenance.push({ source: 'deepgram', url, status: 'CACHED', fetchedAt: new Date(cached.fetchedAt).toISOString() });
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
// postBytes counts the call against OCULON_QUOTA_DEEPGRAM and labels failures.
|
|
48
|
+
const r = await ctx.http.postBytes(DG_URL, new TextEncoder().encode(JSON.stringify({ url })), { source: 'deepgram', headers: { authorization: `Token ${k}`, 'content-type': 'application/json' }, timeoutMs: 600_000, retries: 0 });
|
|
49
|
+
if (!r.data)
|
|
50
|
+
return empty({ ...r.prov, url });
|
|
51
|
+
try {
|
|
52
|
+
j = JSON.parse(r.data.toString('utf8'));
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return empty({ ...r.prov, url, status: 'ERROR', note: 'invalid response' });
|
|
56
|
+
}
|
|
57
|
+
if (j.err_msg)
|
|
58
|
+
return empty({ ...r.prov, url, status: 'ERROR', note: j.err_msg.slice(0, 200) });
|
|
59
|
+
// Keep the transcript (not the word-level timings) so re-reading is free.
|
|
60
|
+
const alt = j.results?.channels?.[0]?.alternatives?.[0];
|
|
61
|
+
const slim = {
|
|
62
|
+
metadata: { duration: j.metadata?.duration },
|
|
63
|
+
results: {
|
|
64
|
+
channels: [{ detected_language: j.results?.channels?.[0]?.detected_language, alternatives: [{ transcript: alt?.transcript, paragraphs: { paragraphs: alt?.paragraphs?.paragraphs?.map((p) => ({ sentences: p.sentences?.map((s) => ({ text: s.text, start: s.start })) })) } }] }],
|
|
65
|
+
summary: j.results?.summary,
|
|
66
|
+
topics: j.results?.topics,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
ctx.store.cachePut(cacheKey, JSON.stringify(slim));
|
|
70
|
+
j = slim;
|
|
71
|
+
provenance.push({ source: 'deepgram', url, status: 'LIVE', fetchedAt: now, note: `${Math.round(j.metadata?.duration ?? 0)} s of audio` });
|
|
72
|
+
}
|
|
73
|
+
const ch = j.results?.channels?.[0];
|
|
74
|
+
const alt = ch?.alternatives?.[0];
|
|
75
|
+
const sentences = (alt?.paragraphs?.paragraphs ?? []).flatMap((p) => p.sentences ?? []);
|
|
76
|
+
const topics = [...new Set((j.results?.topics?.segments ?? []).flatMap((s) => s.topics?.map((t) => t.topic) ?? []))].slice(0, 12);
|
|
77
|
+
const result = {
|
|
78
|
+
url,
|
|
79
|
+
title,
|
|
80
|
+
durationSec: Math.round(j.metadata?.duration ?? 0),
|
|
81
|
+
language: ch?.detected_language ?? null,
|
|
82
|
+
// Deepgram's summary and topics are English-only; for other languages it returns a notice instead.
|
|
83
|
+
summary: ch?.detected_language && ch.detected_language !== 'en' ? null : (j.results?.summary?.short ?? null),
|
|
84
|
+
topics,
|
|
85
|
+
words: (alt?.transcript ?? '').split(/\s+/).filter(Boolean).length,
|
|
86
|
+
mentions: subject ? findMentions(sentences, subject) : [],
|
|
87
|
+
opening: sentences.slice(0, 4).map((s) => ({ start: s.start, text: s.text })),
|
|
88
|
+
};
|
|
89
|
+
return { module: 'listen', input: url, generatedAt: now, result, signals: [], provenance };
|
|
90
|
+
}
|
|
91
|
+
/** Recent podcast episodes about a subject (iTunes directory, free), newest first. */
|
|
92
|
+
export async function findEpisodes(ctx, subject, max = 8) {
|
|
93
|
+
const r = await ctx.http.get(`https://itunes.apple.com/search?term=${enc(subject)}&media=podcast&entity=podcastEpisode&limit=25`, { source: 'itunes', ttlSec: 3 * 3600 });
|
|
94
|
+
const data = (r.data?.results ?? [])
|
|
95
|
+
.filter((e) => e.episodeUrl && e.trackName)
|
|
96
|
+
.map((e) => ({ show: e.collectionName ?? '?', title: e.trackName, date: e.releaseDate ?? '', audioUrl: e.episodeUrl, pageUrl: e.trackViewUrl ?? null }))
|
|
97
|
+
.sort((a, b) => b.date.localeCompare(a.date))
|
|
98
|
+
.slice(0, max);
|
|
99
|
+
return { data, prov: r.prov };
|
|
100
|
+
}
|
|
101
|
+
/** Titles that announce another language ("- CN:", "(Español)"); skipped when picking automatically. */
|
|
102
|
+
const FOREIGN = { test: (s) => /(^|[\s([-])(CN|ZH|ES|DE|FR|JP|KR|PT)\b/.test(s) || /\b(español|deutsch|français)\b|中文|日本語/i.test(s) };
|
|
103
|
+
export async function podcast(ctx, subject, pick) {
|
|
104
|
+
const eps = await findEpisodes(ctx, subject);
|
|
105
|
+
// Automatic pick: the newest episode that does not announce another language; one retry if it still is not English.
|
|
106
|
+
const order = pick !== undefined ? [pick] : eps.data.map((_, i) => i).filter((i) => !FOREIGN.test(`${eps.data[i].show} ${eps.data[i].title}`));
|
|
107
|
+
let picked = null;
|
|
108
|
+
let t = null;
|
|
109
|
+
for (const i of order.slice(0, pick !== undefined ? 1 : 2)) {
|
|
110
|
+
picked = eps.data[i] ?? null;
|
|
111
|
+
if (!picked)
|
|
112
|
+
break;
|
|
113
|
+
t = await transcribe(ctx, picked.audioUrl, subject, `${picked.show}: ${picked.title}`);
|
|
114
|
+
if (!t.result || t.result.language === 'en' || t.result.language === null)
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
module: 'listen',
|
|
119
|
+
input: subject,
|
|
120
|
+
generatedAt: ctx.now().toISOString(),
|
|
121
|
+
result: { episodes: eps.data, transcript: t?.result ?? null, picked },
|
|
122
|
+
signals: [],
|
|
123
|
+
provenance: [eps.prov, ...(t?.provenance ?? [])],
|
|
124
|
+
};
|
|
125
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lynx: cross-checks Polymarket against Kalshi and Manifold. Keyword matching proposes pairs; an LLM then
|
|
3
|
+
* confirms each pair asks the same question (dates and thresholds included). Big gaps between venues on
|
|
4
|
+
* the same question are signals: one crowd is wrong, or knows something first.
|
|
5
|
+
*/
|
|
6
|
+
import type { Ctx } from '../core/context.js';
|
|
7
|
+
import type { ModuleResult } from '../core/types.js';
|
|
8
|
+
import { type OtherMarket } from '../sources/predict.js';
|
|
9
|
+
export interface Comparison {
|
|
10
|
+
polymarket: {
|
|
11
|
+
question: string;
|
|
12
|
+
probability: number;
|
|
13
|
+
url: string;
|
|
14
|
+
volume24h: number;
|
|
15
|
+
};
|
|
16
|
+
other: OtherMarket;
|
|
17
|
+
gapPp: number;
|
|
18
|
+
similarity: number;
|
|
19
|
+
verified: 'same' | 'unverified';
|
|
20
|
+
}
|
|
21
|
+
export interface LynxResult {
|
|
22
|
+
checked: number;
|
|
23
|
+
comparisons: Comparison[];
|
|
24
|
+
disagreements: Comparison[];
|
|
25
|
+
}
|
|
26
|
+
/** Best keyword match for `q` among candidates, if it clears `min`. */
|
|
27
|
+
export declare function bestMatch<T extends {
|
|
28
|
+
question: string;
|
|
29
|
+
}>(q: string, candidates: T[], min?: number): {
|
|
30
|
+
item: T;
|
|
31
|
+
score: number;
|
|
32
|
+
} | null;
|
|
33
|
+
/** Loose shortlist: the `k` candidates sharing the most keywords with `q` (at least two shared). */
|
|
34
|
+
export declare function shortlist<T extends {
|
|
35
|
+
question: string;
|
|
36
|
+
}>(q: string, candidates: T[], k?: number): T[];
|
|
37
|
+
/** Proper nouns and numbers from a question: the words that make a search specific. */
|
|
38
|
+
export declare function searchTerm(q: string): string;
|
|
39
|
+
export declare function lynx(ctx: Ctx, opts?: {
|
|
40
|
+
limit?: number;
|
|
41
|
+
minGapPp?: number;
|
|
42
|
+
fetchImpl?: typeof fetch;
|
|
43
|
+
}): Promise<ModuleResult<LynxResult>>;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { availableProviders, chat } from '../core/llm.js';
|
|
2
|
+
import { keywords, overlap, signalId } from '../core/text.js';
|
|
3
|
+
import { topMarkets } from '../sources/polymarket.js';
|
|
4
|
+
import { kalshiMarkets, manifoldSearch } from '../sources/predict.js';
|
|
5
|
+
import { isResolving, isSportsLine } from './owl.js';
|
|
6
|
+
/** Best keyword match for `q` among candidates, if it clears `min`. */
|
|
7
|
+
export function bestMatch(q, candidates, min = 0.6) {
|
|
8
|
+
const kq = keywords(q);
|
|
9
|
+
let best = null;
|
|
10
|
+
for (const c of candidates) {
|
|
11
|
+
const s = overlap(kq, keywords(c.question));
|
|
12
|
+
if (s.shared.length < 3)
|
|
13
|
+
continue;
|
|
14
|
+
if (!best || s.score > best.score)
|
|
15
|
+
best = { item: c, score: s.score };
|
|
16
|
+
}
|
|
17
|
+
return best && best.score >= min ? best : null;
|
|
18
|
+
}
|
|
19
|
+
/** Loose shortlist: the `k` candidates sharing the most keywords with `q` (at least two shared). */
|
|
20
|
+
export function shortlist(q, candidates, k = 8) {
|
|
21
|
+
const kq = keywords(q);
|
|
22
|
+
return candidates
|
|
23
|
+
.map((c) => ({ c, s: overlap(kq, keywords(c.question)) }))
|
|
24
|
+
.filter((x) => x.s.shared.length >= 2)
|
|
25
|
+
.sort((a, b) => b.s.score - a.s.score)
|
|
26
|
+
.slice(0, k)
|
|
27
|
+
.map((x) => x.c);
|
|
28
|
+
}
|
|
29
|
+
/** Proper nouns and numbers from a question: the words that make a search specific. */
|
|
30
|
+
export function searchTerm(q) {
|
|
31
|
+
const words = q.replace(/[?'"]/g, ' ').split(/\s+/).filter((w) => /^[A-Z0-9$]/.test(w) && !/^(Will|What|Who|When|Which|How|The|A|An|In|On|By|Before|After)$/.test(w));
|
|
32
|
+
return words.slice(0, 4).join(' ');
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The LLM picks, for each Polymarket question, the one option that asks exactly the same thing (same event,
|
|
36
|
+
* deadline and threshold), or none. Returns option indexes (or -1) per market. Null when no LLM is configured.
|
|
37
|
+
*/
|
|
38
|
+
async function pickSame(groups, fetchImpl) {
|
|
39
|
+
if (!availableProviders().length)
|
|
40
|
+
return null;
|
|
41
|
+
const out = groups.map(() => -1);
|
|
42
|
+
for (let start = 0; start < groups.length; start += 8) {
|
|
43
|
+
const batch = groups.slice(start, start + 8);
|
|
44
|
+
try {
|
|
45
|
+
const r = await chat([
|
|
46
|
+
{
|
|
47
|
+
role: 'system',
|
|
48
|
+
content: 'You match prediction markets. For each market, pick the option that resolves YES in exactly the same situations: same event, same deadline (or very close), same threshold. If none does, use -1. Reply JSON: {"matches":[{"market":n,"option":n}]}. When in doubt, -1.',
|
|
49
|
+
},
|
|
50
|
+
{ role: 'user', content: batch.map((g, i) => `Market ${i}: ${g.question}\n${g.options.map((o, j) => ` option ${j}: ${o}`).join('\n')}`).join('\n\n') },
|
|
51
|
+
], { json: true, temperature: 0, maxTokens: 2000, ...(fetchImpl ? { fetch: fetchImpl } : {}) });
|
|
52
|
+
const ms = JSON.parse(r.message.content ?? '{}').matches ?? [];
|
|
53
|
+
for (const m of ms) {
|
|
54
|
+
const i = Number(m.market);
|
|
55
|
+
const j = Number(m.option);
|
|
56
|
+
if (Number.isInteger(i) && i >= 0 && i < batch.length && Number.isInteger(j) && j >= 0 && j < batch[i].options.length)
|
|
57
|
+
out[start + i] = j;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// leave this batch unmatched
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
export async function lynx(ctx, opts = {}) {
|
|
67
|
+
const nowMs = ctx.now().getTime();
|
|
68
|
+
const provenance = [];
|
|
69
|
+
const [pm, ks] = await Promise.all([topMarkets(ctx, 200), kalshiMarkets(ctx)]);
|
|
70
|
+
provenance.push(pm.prov, ...ks.provs);
|
|
71
|
+
const pool = (pm.data ?? []).filter((m) => !isSportsLine(m) && !isResolving(m, nowMs) && m.volume24h >= 20_000 && m.prices.length === 2).slice(0, opts.limit ?? 40);
|
|
72
|
+
// Per market: a loose shortlist from Kalshi, plus Manifold search results for the 12 highest-volume markets.
|
|
73
|
+
const groups = [];
|
|
74
|
+
for (const [i, m] of pool.entries()) {
|
|
75
|
+
const options = ks.data ? shortlist(m.question, ks.data, 8) : [];
|
|
76
|
+
if (i < 12) {
|
|
77
|
+
const term = searchTerm(m.question);
|
|
78
|
+
if (term) {
|
|
79
|
+
const r = await manifoldSearch(ctx, term, 6);
|
|
80
|
+
provenance.push(r.prov);
|
|
81
|
+
options.push(...(r.data ?? []));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (options.length)
|
|
85
|
+
groups.push({ pm: m, options });
|
|
86
|
+
}
|
|
87
|
+
const picks = await pickSame(groups.map((g) => ({ question: g.pm.question, options: g.options.map((o) => `[${o.venue}] ${o.question}`) })), opts.fetchImpl);
|
|
88
|
+
const comparisons = [];
|
|
89
|
+
groups.forEach((g, i) => {
|
|
90
|
+
let other = null;
|
|
91
|
+
let verified = 'unverified';
|
|
92
|
+
if (picks) {
|
|
93
|
+
if (picks[i] >= 0) {
|
|
94
|
+
other = g.options[picks[i]];
|
|
95
|
+
verified = 'same';
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else
|
|
99
|
+
other = bestMatch(g.pm.question, g.options)?.item ?? null;
|
|
100
|
+
if (!other)
|
|
101
|
+
return;
|
|
102
|
+
comparisons.push({
|
|
103
|
+
polymarket: { question: g.pm.question, probability: g.pm.prices[0], url: g.pm.url, volume24h: g.pm.volume24h },
|
|
104
|
+
other,
|
|
105
|
+
gapPp: Math.round(Math.abs((g.pm.prices[0] ?? 0) - other.probability) * 1000) / 10,
|
|
106
|
+
similarity: Math.round(overlap(keywords(g.pm.question), keywords(other.question)).score * 100) / 100,
|
|
107
|
+
verified,
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
comparisons.sort((a, b) => b.gapPp - a.gapPp);
|
|
111
|
+
const minGap = opts.minGapPp ?? 15;
|
|
112
|
+
const disagreements = comparisons.filter((c) => c.gapPp >= minGap && c.verified === 'same');
|
|
113
|
+
const nowIso = new Date(nowMs).toISOString();
|
|
114
|
+
const signals = disagreements.slice(0, 8).map((d) => ({
|
|
115
|
+
id: signalId('lynx', d.polymarket.url, d.other.url, nowIso.slice(0, 10)),
|
|
116
|
+
module: 'lynx',
|
|
117
|
+
title: `Markets disagree by ${d.gapPp}pp: ${d.polymarket.question.slice(0, 100)}`,
|
|
118
|
+
score: Math.min(85, Math.round(45 + d.gapPp)),
|
|
119
|
+
evidence: [
|
|
120
|
+
{ source: 'polymarket', text: `${Math.round(d.polymarket.probability * 100)}% on Polymarket`, url: d.polymarket.url },
|
|
121
|
+
{ source: d.other.venue, text: `${Math.round(d.other.probability * 100)}% on ${d.other.venue}: ${d.other.question.slice(0, 120)}`, url: d.other.url },
|
|
122
|
+
],
|
|
123
|
+
createdAt: nowIso,
|
|
124
|
+
}));
|
|
125
|
+
signals.forEach((s) => ctx.graph.saveSignal(s));
|
|
126
|
+
return { module: 'lynx', input: 'markets', generatedAt: nowIso, result: { checked: pool.length, comparisons, disagreements }, signals, provenance };
|
|
127
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Magpie: on-chain intelligence.
|
|
3
|
+
* wallet(): portfolio (Zerion), recent and first transactions (Etherscan), risk labels (GoPlus, Webacy),
|
|
4
|
+
* native balance on Robinhood Chain, or SOL balance for Solana addresses (Helius).
|
|
5
|
+
* token(): contract risk (GoPlus: honeypot, taxes, owner powers), DEX pairs and liquidity (DexScreener),
|
|
6
|
+
* price and market cap (CoinGecko).
|
|
7
|
+
*/
|
|
8
|
+
import { type Ctx } from '../core/context.js';
|
|
9
|
+
import type { ModuleResult } from '../core/types.js';
|
|
10
|
+
import { type Pair, type Portfolio, type TokenRisk, type Tx } from '../sources/onchain.js';
|
|
11
|
+
export interface WalletResult {
|
|
12
|
+
address: string;
|
|
13
|
+
kind: 'evm' | 'solana';
|
|
14
|
+
portfolio: Portfolio | null;
|
|
15
|
+
recentTxs: Tx[];
|
|
16
|
+
firstSeen: string | null;
|
|
17
|
+
ageDays: number | null;
|
|
18
|
+
labels: string[];
|
|
19
|
+
/** Who this address is, from the open eth-labels dataset (exchange, protocol, bridge...). */
|
|
20
|
+
knownAs: string | null;
|
|
21
|
+
/** Labeled counterparties among the recent transactions. */
|
|
22
|
+
counterparties: {
|
|
23
|
+
address: string;
|
|
24
|
+
knownAs: string;
|
|
25
|
+
txs: number;
|
|
26
|
+
}[];
|
|
27
|
+
riskScore: number | null;
|
|
28
|
+
riskIssues: string[];
|
|
29
|
+
/** OFAC screening: listed itself, or transacted directly with a listed address. */
|
|
30
|
+
sanctions: {
|
|
31
|
+
verdict: string;
|
|
32
|
+
hits: {
|
|
33
|
+
kind: string;
|
|
34
|
+
entry: {
|
|
35
|
+
name: string;
|
|
36
|
+
program: string;
|
|
37
|
+
};
|
|
38
|
+
}[];
|
|
39
|
+
} | null;
|
|
40
|
+
robinhood: {
|
|
41
|
+
balanceEth: number;
|
|
42
|
+
txCount: number;
|
|
43
|
+
isContract: boolean;
|
|
44
|
+
} | null;
|
|
45
|
+
solana: {
|
|
46
|
+
sol: number;
|
|
47
|
+
tokens: number;
|
|
48
|
+
} | null;
|
|
49
|
+
}
|
|
50
|
+
export declare function wallet(ctx: Ctx, addressInput: string): Promise<ModuleResult<WalletResult>>;
|
|
51
|
+
export interface TokenResult {
|
|
52
|
+
address: string;
|
|
53
|
+
chain: string;
|
|
54
|
+
security: TokenRisk | null;
|
|
55
|
+
pairs: Pair[];
|
|
56
|
+
market: {
|
|
57
|
+
name: string;
|
|
58
|
+
symbol: string;
|
|
59
|
+
priceUsd: number | null;
|
|
60
|
+
marketCapUsd: number | null;
|
|
61
|
+
change24h: number | null;
|
|
62
|
+
} | null;
|
|
63
|
+
verdict: 'DANGER' | 'CAUTION' | 'OK' | 'UNKNOWN';
|
|
64
|
+
reasons: string[];
|
|
65
|
+
}
|
|
66
|
+
export declare function tokenVerdict(sec: TokenRisk | null, pairs: Pair[], marketCapUsd?: number | null): {
|
|
67
|
+
verdict: TokenResult['verdict'];
|
|
68
|
+
reasons: string[];
|
|
69
|
+
};
|
|
70
|
+
export declare function token(ctx: Ctx, addressInput: string, chainName?: string): Promise<ModuleResult<TokenResult>>;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Magpie: on-chain intelligence.
|
|
3
|
+
* wallet(): portfolio (Zerion), recent and first transactions (Etherscan), risk labels (GoPlus, Webacy),
|
|
4
|
+
* native balance on Robinhood Chain, or SOL balance for Solana addresses (Helius).
|
|
5
|
+
* token(): contract risk (GoPlus: honeypot, taxes, owner powers), DEX pairs and liquidity (DexScreener),
|
|
6
|
+
* price and market cap (CoinGecko).
|
|
7
|
+
*/
|
|
8
|
+
import { DAY_MS } from '../core/context.js';
|
|
9
|
+
import { clamp } from '../core/stats.js';
|
|
10
|
+
import { signalId } from '../core/text.js';
|
|
11
|
+
import { coinByContract } from '../sources/finance.js';
|
|
12
|
+
import { describeLabels, ensureLabels, labelsFor } from '../sources/labels.js';
|
|
13
|
+
import { screen } from './sanctions.js';
|
|
14
|
+
import { addressSecurity, CHAINS, dexPairs, etherscanTxs, isEvmAddress, isSolanaAddress, robinhoodAccount, solanaAccount, tokenSecurity, webacyRisk, zerionPortfolio, } from '../sources/onchain.js';
|
|
15
|
+
export async function wallet(ctx, addressInput) {
|
|
16
|
+
const address = addressInput.trim();
|
|
17
|
+
const nowMs = ctx.now().getTime();
|
|
18
|
+
const nowIso = new Date(nowMs).toISOString();
|
|
19
|
+
const provenance = [];
|
|
20
|
+
const signals = [];
|
|
21
|
+
if (isSolanaAddress(address)) {
|
|
22
|
+
const sol = await solanaAccount(ctx, address);
|
|
23
|
+
provenance.push(sol.prov);
|
|
24
|
+
return {
|
|
25
|
+
module: 'magpie',
|
|
26
|
+
input: address,
|
|
27
|
+
generatedAt: nowIso,
|
|
28
|
+
result: { address, kind: 'solana', portfolio: null, recentTxs: [], firstSeen: null, ageDays: null, labels: [], knownAs: null, counterparties: [], riskScore: null, riskIssues: [], robinhood: null, solana: sol.data, sanctions: null },
|
|
29
|
+
signals,
|
|
30
|
+
provenance,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (!isEvmAddress(address))
|
|
34
|
+
throw new Error('not an EVM (0x...) or Solana address');
|
|
35
|
+
const sanc = await screen(ctx, address);
|
|
36
|
+
const [pf, recent, first, labels, risk, rh] = await Promise.all([
|
|
37
|
+
zerionPortfolio(ctx, address),
|
|
38
|
+
etherscanTxs(ctx, address, 1, 'desc', 15),
|
|
39
|
+
etherscanTxs(ctx, address, 1, 'asc', 1),
|
|
40
|
+
addressSecurity(ctx, address),
|
|
41
|
+
webacyRisk(ctx, address),
|
|
42
|
+
robinhoodAccount(ctx, address),
|
|
43
|
+
]);
|
|
44
|
+
provenance.push(pf.prov, recent.prov, first.prov, labels.prov, risk.prov, rh.prov);
|
|
45
|
+
provenance.push(await ensureLabels(ctx));
|
|
46
|
+
const knownAs = describeLabels(labelsFor(ctx, address));
|
|
47
|
+
const cp = new Map();
|
|
48
|
+
for (const t of recent.data ?? [])
|
|
49
|
+
for (const a of [t.from, t.to])
|
|
50
|
+
if (a && a.toLowerCase() !== address.toLowerCase())
|
|
51
|
+
cp.set(a.toLowerCase(), (cp.get(a.toLowerCase()) ?? 0) + 1);
|
|
52
|
+
const counterparties = [...cp].flatMap(([a, txs]) => {
|
|
53
|
+
const k = describeLabels(labelsFor(ctx, a));
|
|
54
|
+
return k ? [{ address: a, knownAs: k, txs }] : [];
|
|
55
|
+
}).sort((x, y) => y.txs - x.txs).slice(0, 10);
|
|
56
|
+
const firstSeen = first.data?.[0]?.time ?? null;
|
|
57
|
+
const ageDays = firstSeen ? Math.floor((nowMs - Date.parse(firstSeen)) / DAY_MS) : null;
|
|
58
|
+
const id = ctx.graph.upsert('event', `wallet:${address.toLowerCase()}`, { totalUsd: pf.data?.totalUsd ?? null });
|
|
59
|
+
if (pf.data)
|
|
60
|
+
ctx.graph.observe(id, 'magpie', 'wallet_usd', pf.data.totalUsd, 'zerion');
|
|
61
|
+
const ev = [];
|
|
62
|
+
if (labels.data?.length)
|
|
63
|
+
ev.push({ source: 'goplus', text: `flagged: ${labels.data.join(', ')}` });
|
|
64
|
+
if (risk.data?.score != null && risk.data.score >= 50)
|
|
65
|
+
ev.push({ source: 'webacy', text: `risk score ${risk.data.score}${risk.data.issues.length ? ` (${risk.data.issues.slice(0, 4).join(', ')})` : ''}` });
|
|
66
|
+
if (pf.data && pf.data.totalUsd >= 10_000_000)
|
|
67
|
+
ev.push({ source: 'zerion', text: `whale wallet: $${Math.round(pf.data.totalUsd).toLocaleString('en-US')}` });
|
|
68
|
+
if (ev.length) {
|
|
69
|
+
signals.push({
|
|
70
|
+
id: signalId('magpie', address, nowIso.slice(0, 10)),
|
|
71
|
+
module: 'magpie',
|
|
72
|
+
title: `Wallet ${address.slice(0, 8)}…: ${ev.map((e) => e.text.split(':')[0]).join(', ')}`,
|
|
73
|
+
score: clamp(40 + (labels.data?.length ? 30 : 0) + ((risk.data?.score ?? 0) >= 75 ? 15 : 0), 0, 95),
|
|
74
|
+
entity: id,
|
|
75
|
+
evidence: ev,
|
|
76
|
+
createdAt: nowIso,
|
|
77
|
+
});
|
|
78
|
+
signals.forEach((s) => ctx.graph.saveSignal(s));
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
module: 'magpie',
|
|
82
|
+
input: address,
|
|
83
|
+
generatedAt: nowIso,
|
|
84
|
+
result: {
|
|
85
|
+
address,
|
|
86
|
+
kind: 'evm',
|
|
87
|
+
portfolio: pf.data,
|
|
88
|
+
recentTxs: recent.data ?? [],
|
|
89
|
+
firstSeen,
|
|
90
|
+
ageDays,
|
|
91
|
+
labels: labels.data ?? [],
|
|
92
|
+
knownAs,
|
|
93
|
+
counterparties,
|
|
94
|
+
riskScore: risk.data?.score ?? null,
|
|
95
|
+
riskIssues: risk.data?.issues ?? [],
|
|
96
|
+
sanctions: sanc ? { verdict: sanc.result.verdict, hits: sanc.result.hits } : null,
|
|
97
|
+
robinhood: rh.data,
|
|
98
|
+
solana: null,
|
|
99
|
+
},
|
|
100
|
+
signals,
|
|
101
|
+
provenance,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const DANGER = new Set(['honeypot', 'cannot sell all', 'hidden owner', 'owner can change balances', 'can take back ownership', 'self-destruct']);
|
|
105
|
+
export function tokenVerdict(sec, pairs, marketCapUsd = null) {
|
|
106
|
+
const reasons = [];
|
|
107
|
+
if (!sec && !pairs.length)
|
|
108
|
+
return { verdict: 'UNKNOWN', reasons: ['no security data and no DEX pairs'] };
|
|
109
|
+
let level = 0;
|
|
110
|
+
for (const f of sec?.flags ?? []) {
|
|
111
|
+
reasons.push(f);
|
|
112
|
+
level = Math.max(level, DANGER.has(f) ? 2 : 1);
|
|
113
|
+
}
|
|
114
|
+
if ((sec?.sellTax ?? 0) >= 0.1) {
|
|
115
|
+
reasons.push(`sell tax ${Math.round((sec.sellTax ?? 0) * 100)}%`);
|
|
116
|
+
level = Math.max(level, (sec.sellTax ?? 0) >= 0.3 ? 2 : 1);
|
|
117
|
+
}
|
|
118
|
+
const liq = pairs.reduce((a, p) => a + (p.liquidityUsd ?? 0), 0);
|
|
119
|
+
// DEX liquidity only tells the story for small tokens; large caps trade mostly elsewhere.
|
|
120
|
+
if (pairs.length && liq < 10_000 && (marketCapUsd ?? 0) < 100_000_000) {
|
|
121
|
+
reasons.push(`thin liquidity ($${Math.round(liq).toLocaleString('en-US')})`);
|
|
122
|
+
level = Math.max(level, 1);
|
|
123
|
+
}
|
|
124
|
+
const youngest = pairs.map((p) => p.createdAt).filter(Boolean).sort().pop();
|
|
125
|
+
if (youngest && Date.now() - Date.parse(youngest) < 2 * DAY_MS) {
|
|
126
|
+
reasons.push('pair created in the last 48h');
|
|
127
|
+
level = Math.max(level, 1);
|
|
128
|
+
}
|
|
129
|
+
// Widely held tokens (USDT, USDC, ...) carry issuer controls by design; flag them, but do not call them scams.
|
|
130
|
+
if (level === 2 && (sec?.holders ?? 0) >= 100_000) {
|
|
131
|
+
level = 1;
|
|
132
|
+
reasons.push(`widely held (${sec.holders.toLocaleString('en-US')} holders): flags describe issuer controls, not a rug`);
|
|
133
|
+
}
|
|
134
|
+
return { verdict: level === 2 ? 'DANGER' : level === 1 ? 'CAUTION' : 'OK', reasons };
|
|
135
|
+
}
|
|
136
|
+
export async function token(ctx, addressInput, chainName = 'eth') {
|
|
137
|
+
const address = addressInput.trim();
|
|
138
|
+
const chain = CHAINS[chainName] ? chainName : 'eth';
|
|
139
|
+
const meta = CHAINS[chain];
|
|
140
|
+
if (!isEvmAddress(address))
|
|
141
|
+
throw new Error('token address must be an EVM contract address (0x...)');
|
|
142
|
+
const nowIso = ctx.now().toISOString();
|
|
143
|
+
const [sec, pairs, cg] = await Promise.all([
|
|
144
|
+
meta.goplus ? tokenSecurity(ctx, meta.goplus, address) : Promise.resolve(null),
|
|
145
|
+
dexPairs(ctx, address, chain),
|
|
146
|
+
meta.coingecko ? coinByContract(ctx, meta.coingecko, address) : Promise.resolve(null),
|
|
147
|
+
]);
|
|
148
|
+
const provenance = [pairs.prov, ...(sec ? [sec.prov] : []), ...(cg ? [cg.prov] : [])];
|
|
149
|
+
const usePairs = pairs.data ?? [];
|
|
150
|
+
const { verdict, reasons } = tokenVerdict(sec?.data ?? null, usePairs, cg?.data?.marketCapUsd ?? null);
|
|
151
|
+
const name = sec?.data?.symbol || cg?.data?.symbol || usePairs[0]?.pair.split('/')[0] || address.slice(0, 10);
|
|
152
|
+
const id = ctx.graph.upsert('event', `token:${chain}:${address.toLowerCase()}`, { symbol: name, verdict });
|
|
153
|
+
const signals = [];
|
|
154
|
+
if (verdict === 'DANGER' || verdict === 'CAUTION') {
|
|
155
|
+
signals.push({
|
|
156
|
+
id: signalId('magpie', 'token', chain, address, nowIso.slice(0, 10)),
|
|
157
|
+
module: 'magpie',
|
|
158
|
+
title: `${name} on ${meta.label}: ${verdict} (${reasons.slice(0, 3).join(', ')})`,
|
|
159
|
+
score: verdict === 'DANGER' ? 85 : 55,
|
|
160
|
+
entity: id,
|
|
161
|
+
evidence: reasons.map((r) => ({ source: r.includes('liquidity') || r.includes('pair') ? 'dexscreener' : 'goplus', text: r })),
|
|
162
|
+
createdAt: nowIso,
|
|
163
|
+
});
|
|
164
|
+
signals.forEach((s) => ctx.graph.saveSignal(s));
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
module: 'magpie',
|
|
168
|
+
input: address,
|
|
169
|
+
generatedAt: nowIso,
|
|
170
|
+
result: { address, chain, security: sec?.data ?? null, pairs: usePairs.slice(0, 10), market: cg?.data ?? null, verdict, reasons },
|
|
171
|
+
signals,
|
|
172
|
+
provenance,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Meerkat: the watchlist. You register targets; Meerkat re-runs the right module on each one and reports
|
|
3
|
+
* only what CHANGED since the previous run. The first run of a target records a baseline and reports nothing.
|
|
4
|
+
*/
|
|
5
|
+
import type { Ctx } from '../core/context.js';
|
|
6
|
+
import type { Signal } from '../core/types.js';
|
|
7
|
+
/** "Tokyo|5.5" is a place with a minimum magnitude; a bare place uses 5.0. */
|
|
8
|
+
export declare function splitQuakeTarget(target: string): {
|
|
9
|
+
place: string;
|
|
10
|
+
min: number;
|
|
11
|
+
};
|
|
12
|
+
export declare const WATCH_KINDS: readonly ['company', 'domain', 'wallet', 'token', 'plane', 'topic', 'lights', 'air', 'port', 'news', 'outage', 'cve', 'quake', 'hazard', 'url', 'package', 'travel'];
|
|
13
|
+
export type WatchKind = (typeof WATCH_KINDS)[number];
|
|
14
|
+
export interface WatchItem {
|
|
15
|
+
id: number;
|
|
16
|
+
kind: WatchKind;
|
|
17
|
+
target: string;
|
|
18
|
+
label: string | null;
|
|
19
|
+
createdAt: string;
|
|
20
|
+
lastRun: string | null;
|
|
21
|
+
}
|
|
22
|
+
export interface WatchRun {
|
|
23
|
+
item: WatchItem;
|
|
24
|
+
baseline: boolean;
|
|
25
|
+
changes: string[];
|
|
26
|
+
error?: string;
|
|
27
|
+
}
|
|
28
|
+
type State = Record<string, unknown>;
|
|
29
|
+
export declare function addWatch(ctx: Ctx, kind: string, target: string, label?: string): WatchItem;
|
|
30
|
+
export declare function listWatch(ctx: Ctx): WatchItem[];
|
|
31
|
+
export declare function removeWatch(ctx: Ctx, id: number): boolean;
|
|
32
|
+
/** Run the module for one item and return its state plus human-readable changes against the previous state. */
|
|
33
|
+
export declare function observe(ctx: Ctx, item: WatchItem, prev: State | null): Promise<{
|
|
34
|
+
state: State;
|
|
35
|
+
changes: string[];
|
|
36
|
+
}>;
|
|
37
|
+
/** Run every watch item (or the given ids) one after another, so free-tier rate limits are respected. */
|
|
38
|
+
export declare function runWatch(ctx: Ctx, ids?: number[]): Promise<{
|
|
39
|
+
runs: WatchRun[];
|
|
40
|
+
signals: Signal[];
|
|
41
|
+
}>;
|
|
42
|
+
export {};
|