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,512 @@
|
|
|
1
|
+
import { signalId } from '../core/text.js';
|
|
2
|
+
const LLAMA = 'https://api.llama.fi';
|
|
3
|
+
const PROTOCOLS_URL = `${LLAMA}/protocols`;
|
|
4
|
+
const OVERVIEW_QS = 'excludeTotalDataChart=true&excludeTotalDataChartBreakdown=true';
|
|
5
|
+
const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : null);
|
|
6
|
+
const prevFrom = (tvl, pct) => (pct != null && pct > -100 ? tvl / (1 + pct / 100) : pct === -100 ? Infinity : tvl);
|
|
7
|
+
function slimProtocols(d) {
|
|
8
|
+
if (!Array.isArray(d))
|
|
9
|
+
return [];
|
|
10
|
+
const out = [];
|
|
11
|
+
for (const p of d) {
|
|
12
|
+
const tvl = num(p.tvl) ?? 0;
|
|
13
|
+
const c1d = num(p.change_1d);
|
|
14
|
+
const prev = prevFrom(tvl, c1d);
|
|
15
|
+
// Keep anything that matters now or did a day ago (a drained protocol can sit near zero today).
|
|
16
|
+
if (tvl < 1e5 && !(Number.isFinite(prev) && prev >= 1e6))
|
|
17
|
+
continue;
|
|
18
|
+
out.push({
|
|
19
|
+
name: String(p.name ?? ''),
|
|
20
|
+
slug: String(p.slug ?? ''),
|
|
21
|
+
category: String(p.category ?? ''),
|
|
22
|
+
chains: Array.isArray(p.chains) ? p.chains.slice(0, 30) : [],
|
|
23
|
+
tvl,
|
|
24
|
+
change_1h: num(p.change_1h),
|
|
25
|
+
change_1d: c1d,
|
|
26
|
+
change_7d: num(p.change_7d),
|
|
27
|
+
mcap: num(p.mcap),
|
|
28
|
+
audits: p.audits != null ? String(p.audits) : null,
|
|
29
|
+
audit_links: Array.isArray(p.audit_links) ? p.audit_links.slice(0, 10) : [],
|
|
30
|
+
url: String(p.url ?? ''),
|
|
31
|
+
twitter: p.twitter ?? null,
|
|
32
|
+
parent: p.parentProtocolSlug ?? null,
|
|
33
|
+
oracles: Array.isArray(p.oracles) ? p.oracles : Array.isArray(p.oraclesBreakdown) ? p.oraclesBreakdown.map((o) => o.name) : [],
|
|
34
|
+
forkedFrom: Array.isArray(p.forkedFrom) ? p.forkedFrom : [],
|
|
35
|
+
listedAt: num(p.listedAt),
|
|
36
|
+
rugged: p.rugged === true,
|
|
37
|
+
deadFrom: p.deadFrom ?? null,
|
|
38
|
+
deprecated: p.deprecated === true,
|
|
39
|
+
misrepresentedTokens: p.misrepresentedTokens === true,
|
|
40
|
+
wrongLiquidity: p.wrongLiquidity === true,
|
|
41
|
+
warnings: Array.isArray(p.warningBanners) ? p.warningBanners.map((w) => String(w.message ?? '')).filter(Boolean) : [],
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
export function protocolList(ctx) {
|
|
47
|
+
return ctx.http.get(PROTOCOLS_URL, { source: 'defillama', ttlSec: 600, timeoutMs: 60_000, keep: slimProtocols });
|
|
48
|
+
}
|
|
49
|
+
function flagsOf(p) {
|
|
50
|
+
const f = [];
|
|
51
|
+
if (p.rugged)
|
|
52
|
+
f.push('marked rugged by DefiLlama');
|
|
53
|
+
if (p.deadFrom)
|
|
54
|
+
f.push(`dead since ${p.deadFrom}`);
|
|
55
|
+
if (p.deprecated)
|
|
56
|
+
f.push('deprecated');
|
|
57
|
+
if (p.misrepresentedTokens)
|
|
58
|
+
f.push('misrepresented tokens');
|
|
59
|
+
if (p.wrongLiquidity)
|
|
60
|
+
f.push('liquidity figures flagged as unreliable');
|
|
61
|
+
for (const w of p.warnings)
|
|
62
|
+
f.push(`warning: ${w.slice(0, 160)}`);
|
|
63
|
+
return f;
|
|
64
|
+
}
|
|
65
|
+
function slimHacks(d) {
|
|
66
|
+
if (!Array.isArray(d))
|
|
67
|
+
return [];
|
|
68
|
+
return [...d]
|
|
69
|
+
.sort((a, b) => (b.date ?? 0) - (a.date ?? 0))
|
|
70
|
+
.slice(0, 60)
|
|
71
|
+
.map((h) => ({
|
|
72
|
+
date: Number(h.date) || 0,
|
|
73
|
+
name: String(h.name ?? ''),
|
|
74
|
+
amount: num(h.amount) ?? 0,
|
|
75
|
+
returnedFunds: num(h.returnedFunds),
|
|
76
|
+
classification: String(h.classification ?? ''),
|
|
77
|
+
technique: String(h.technique ?? ''),
|
|
78
|
+
chain: Array.isArray(h.chain) ? h.chain : [],
|
|
79
|
+
bridgeHack: h.bridgeHack === true,
|
|
80
|
+
targetType: String(h.targetType ?? ''),
|
|
81
|
+
source: String(h.source ?? ''),
|
|
82
|
+
description: String(h.description ?? '').slice(0, 400),
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
function toHack(h) {
|
|
86
|
+
return {
|
|
87
|
+
date: new Date(h.date * 1000).toISOString().slice(0, 10),
|
|
88
|
+
name: h.name,
|
|
89
|
+
amount: h.amount,
|
|
90
|
+
returnedFunds: h.returnedFunds,
|
|
91
|
+
classification: h.classification,
|
|
92
|
+
technique: h.technique,
|
|
93
|
+
chains: h.chain,
|
|
94
|
+
bridgeHack: h.bridgeHack,
|
|
95
|
+
targetType: h.targetType,
|
|
96
|
+
description: h.description,
|
|
97
|
+
url: /^https?:\/\//.test(h.source) ? h.source : 'https://defillama.com/hacks',
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function slimOverview(d) {
|
|
101
|
+
const pick = (p) => ({ name: String(p.displayName ?? p.name ?? ''), category: String(p.category ?? ''), total24h: num(p.total24h) ?? 0, change_1d: num(p.change_1d) });
|
|
102
|
+
return {
|
|
103
|
+
total24h: num(d?.total24h),
|
|
104
|
+
change_1d: num(d?.change_1d),
|
|
105
|
+
change_7d: num(d?.change_7d),
|
|
106
|
+
protocols: Array.isArray(d?.protocols) ? d.protocols.filter((p) => (num(p.total24h) ?? 0) >= 1e6).map(pick) : [],
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
const STABLE_YIELD_MIN_TVL = 10e6;
|
|
110
|
+
const STABLE_YIELD_MIN_APY = 20;
|
|
111
|
+
function slimYields(d) {
|
|
112
|
+
const pools = Array.isArray(d?.data) ? d.data : [];
|
|
113
|
+
return pools
|
|
114
|
+
.filter((p) => p.stablecoin === true && (num(p.tvlUsd) ?? 0) >= STABLE_YIELD_MIN_TVL && (num(p.apy) ?? 0) >= STABLE_YIELD_MIN_APY)
|
|
115
|
+
.sort((a, b) => b.apy - a.apy)
|
|
116
|
+
.slice(0, 25)
|
|
117
|
+
.map((p) => ({ chain: String(p.chain), project: String(p.project), symbol: String(p.symbol), tvlUsd: p.tvlUsd, apy: Math.round(p.apy * 100) / 100, apyBase: num(p.apyBase), apyReward: num(p.apyReward), apyChange7d: num(p.apyPct7D) }));
|
|
118
|
+
}
|
|
119
|
+
const pct = (a, b) => (b ? ((a - b) / b) * 100 : null);
|
|
120
|
+
const round = (v, d = 2) => (v == null ? null : Math.round(v * 10 ** d) / 10 ** d);
|
|
121
|
+
const usd = (v) => (v >= 1e9 ? `$${(v / 1e9).toFixed(2)}B` : v >= 1e6 ? `$${(v / 1e6).toFixed(1)}M` : `$${Math.round(v / 1e3)}K`);
|
|
122
|
+
const clamp = (v, lo, hi) => Math.max(lo, Math.min(hi, Math.round(v)));
|
|
123
|
+
export function dropScore(lostUsd, dropPct) {
|
|
124
|
+
return clamp(50 + 10 * Math.log10(Math.max(lostUsd, 1e6) / 1e6) + (dropPct - 20) / 2, 50, 92);
|
|
125
|
+
}
|
|
126
|
+
export function depegScore(circulating, offPct) {
|
|
127
|
+
return clamp(50 + 8 * Math.log10(Math.max(circulating, 5e7) / 5e7) + 3 * offPct, 50, 92);
|
|
128
|
+
}
|
|
129
|
+
export function hackScore(amount, bridge) {
|
|
130
|
+
return clamp(50 + 10 * Math.log10(Math.max(amount, 1e6) / 1e6) + (bridge ? 5 : 0), 50, 90);
|
|
131
|
+
}
|
|
132
|
+
function dropSignal(m, now) {
|
|
133
|
+
return {
|
|
134
|
+
id: signalId('defi', 'tvl-drop', m.slug, now.toISOString().slice(0, 10)),
|
|
135
|
+
module: 'defi',
|
|
136
|
+
title: `${m.name} TVL down ${Math.abs(m.change1d).toFixed(1)}% in 24h (${usd(m.prevTvl)} to ${usd(m.tvl)})`,
|
|
137
|
+
score: m.change1d <= -95 ? Math.min(dropScore(m.lostUsd, -m.change1d), 70) : dropScore(m.lostUsd, -m.change1d),
|
|
138
|
+
entity: m.name,
|
|
139
|
+
evidence: [
|
|
140
|
+
{
|
|
141
|
+
source: 'defillama',
|
|
142
|
+
text: `${m.category || 'protocol'} on ${m.chains.slice(0, 5).join(', ') || 'unknown chains'}; 1h ${m.change1h?.toFixed(1) ?? 'n/a'}%, 7d ${m.change7d?.toFixed(1) ?? 'n/a'}%${m.vsMarketPct != null ? `, ${m.vsMarketPct.toFixed(1)} points worse than the whole market` : ''}. TVL is USD value, so token price moves count too.${m.change1d <= -95 ? ' A near-total drop can also be a data adapter gap.' : ''}${m.flags.length ? ` Flags: ${m.flags.join('; ')}` : ''}`,
|
|
143
|
+
url: `https://defillama.com/protocol/${m.slug}`,
|
|
144
|
+
value: m.lostUsd,
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
createdAt: now.toISOString(),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function toMove(p, marketChange1d) {
|
|
151
|
+
const c1d = p.change_1d ?? 0;
|
|
152
|
+
const prev = prevFrom(p.tvl, c1d);
|
|
153
|
+
const prevTvl = Number.isFinite(prev) ? prev : p.tvl;
|
|
154
|
+
return {
|
|
155
|
+
name: p.name,
|
|
156
|
+
slug: p.slug,
|
|
157
|
+
category: p.category,
|
|
158
|
+
chains: p.chains,
|
|
159
|
+
tvl: Math.round(p.tvl),
|
|
160
|
+
prevTvl: Math.round(prevTvl),
|
|
161
|
+
lostUsd: Math.round(prevTvl - p.tvl),
|
|
162
|
+
change1h: round(p.change_1h),
|
|
163
|
+
change1d: round(c1d),
|
|
164
|
+
change7d: round(p.change_7d),
|
|
165
|
+
vsMarketPct: marketChange1d != null ? round(c1d - marketChange1d) : null,
|
|
166
|
+
flags: flagsOf(p),
|
|
167
|
+
url: p.url,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
// ---------- defi(): the market-wide scan ----------
|
|
171
|
+
export async function defi(ctx, opts = {}) {
|
|
172
|
+
const now = ctx.now();
|
|
173
|
+
const nowMs = now.getTime();
|
|
174
|
+
const minTvl = opts.minTvl ?? 50e6;
|
|
175
|
+
const dropPct = opts.dropPct ?? 20;
|
|
176
|
+
const minPegCap = opts.minPegCap ?? 50e6;
|
|
177
|
+
const depegPct = opts.depegPct ?? 2;
|
|
178
|
+
const chainMovePct = opts.chainMovePct ?? 15;
|
|
179
|
+
const hackDays = opts.hackDays ?? 7;
|
|
180
|
+
const provenance = [];
|
|
181
|
+
const [protocols, chains, hist, hacks, stables, dexs, fees, oi, fng, yields] = await Promise.all([
|
|
182
|
+
protocolList(ctx),
|
|
183
|
+
ctx.http.get(`${LLAMA}/v2/chains`, {
|
|
184
|
+
source: 'defillama',
|
|
185
|
+
ttlSec: 900,
|
|
186
|
+
keep: (d) => (Array.isArray(d) ? d.filter((c) => (num(c.tvl) ?? 0) > 0).map((c) => ({ name: String(c.name), tvl: c.tvl })) : []),
|
|
187
|
+
}),
|
|
188
|
+
ctx.http.get(`${LLAMA}/v2/historicalChainTvl`, { source: 'defillama', ttlSec: 3600, keep: (d) => (Array.isArray(d) ? d.slice(-10) : []) }),
|
|
189
|
+
ctx.http.get(`${LLAMA}/hacks`, { source: 'defillama', ttlSec: 3600, timeoutMs: 45_000, keep: slimHacks }),
|
|
190
|
+
ctx.http.get('https://stablecoins.llama.fi/stablecoins?includePrices=true', {
|
|
191
|
+
source: 'defillama-stablecoins',
|
|
192
|
+
ttlSec: 900,
|
|
193
|
+
timeoutMs: 45_000,
|
|
194
|
+
keep: (d) => (Array.isArray(d?.peggedAssets) ? d.peggedAssets : []).map((a) => {
|
|
195
|
+
const key = String(a.pegType ?? 'peggedUSD');
|
|
196
|
+
return { name: String(a.name), symbol: String(a.symbol), pegType: key, mech: String(a.pegMechanism ?? ''), price: num(a.price), circ: num(a.circulating?.[key]) ?? 0, prevDay: num(a.circulatingPrevDay?.[key]), prevWeek: num(a.circulatingPrevWeek?.[key]) };
|
|
197
|
+
}),
|
|
198
|
+
}),
|
|
199
|
+
ctx.http.get(`${LLAMA}/overview/dexs?${OVERVIEW_QS}`, { source: 'defillama', ttlSec: 1800, timeoutMs: 45_000, keep: slimOverview }),
|
|
200
|
+
ctx.http.get(`${LLAMA}/overview/fees?${OVERVIEW_QS}`, { source: 'defillama', ttlSec: 1800, timeoutMs: 60_000, keep: slimOverview }),
|
|
201
|
+
ctx.http.get(`${LLAMA}/overview/open-interest?${OVERVIEW_QS}`, { source: 'defillama', ttlSec: 1800, timeoutMs: 45_000, keep: slimOverview }),
|
|
202
|
+
ctx.http.get('https://api.alternative.me/fng/?limit=30', { source: 'alternative-me', ttlSec: 3600 }),
|
|
203
|
+
opts.yields === false ? Promise.resolve(null) : ctx.http.get('https://yields.llama.fi/pools', { source: 'defillama-yields', ttlSec: 3600, timeoutMs: 60_000, keep: slimYields }),
|
|
204
|
+
]);
|
|
205
|
+
for (const r of [protocols, chains, hist, hacks, stables, dexs, fees, oi, fng, yields])
|
|
206
|
+
if (r)
|
|
207
|
+
provenance.push(r.prov);
|
|
208
|
+
// Market baseline: total DeFi TVL, last point versus one and seven days earlier.
|
|
209
|
+
const h = hist.data ?? [];
|
|
210
|
+
const last = h.at(-1);
|
|
211
|
+
const at = (days) => (last ? [...h].reverse().find((p) => last.date - p.date >= days * 86_400 - 3600) : undefined);
|
|
212
|
+
const defiTvlChange1d = last && at(1) ? round(pct(last.tvl, at(1).tvl)) : null;
|
|
213
|
+
const defiTvlChange7d = last && at(7) ? round(pct(last.tvl, at(7).tvl)) : null;
|
|
214
|
+
// Protocol TVL drops.
|
|
215
|
+
const tvlDrops = (protocols.data ?? [])
|
|
216
|
+
.filter((p) => p.change_1d != null && p.change_1d <= -dropPct)
|
|
217
|
+
.map((p) => toMove(p, defiTvlChange1d))
|
|
218
|
+
.filter((m) => m.prevTvl >= minTvl)
|
|
219
|
+
.sort((a, b) => b.lostUsd - a.lostUsd);
|
|
220
|
+
// Stablecoins: USD-pegged only (other pegs need an FX rate to judge).
|
|
221
|
+
const usdStables = (stables.data ?? []).filter((s) => s.pegType === 'peggedUSD');
|
|
222
|
+
const asDepeg = (s) => ({
|
|
223
|
+
name: s.name,
|
|
224
|
+
symbol: s.symbol,
|
|
225
|
+
mechanism: s.mech,
|
|
226
|
+
price: s.price ?? NaN,
|
|
227
|
+
offPct: s.price != null ? round(Math.abs(s.price - 1) * 100) : NaN,
|
|
228
|
+
circulating: Math.round(s.circ),
|
|
229
|
+
supplyChange1dPct: s.prevDay ? round(pct(s.circ, s.prevDay)) : null,
|
|
230
|
+
supplyChange7dPct: s.prevWeek ? round(pct(s.circ, s.prevWeek)) : null,
|
|
231
|
+
url: 'https://defillama.com/stablecoins',
|
|
232
|
+
});
|
|
233
|
+
const depegs = usdStables
|
|
234
|
+
.filter((s) => s.circ >= minPegCap && s.price != null && Math.abs(s.price - 1) * 100 > depegPct)
|
|
235
|
+
.map(asDepeg)
|
|
236
|
+
.sort((a, b) => b.offPct * Math.log10(b.circulating) - a.offPct * Math.log10(a.circulating));
|
|
237
|
+
const supplyShocks = usdStables
|
|
238
|
+
.filter((s) => (s.prevDay ?? 0) >= minPegCap && s.prevDay && pct(s.circ, s.prevDay) <= -10)
|
|
239
|
+
.map(asDepeg)
|
|
240
|
+
.sort((a, b) => (a.supplyChange1dPct ?? 0) - (b.supplyChange1dPct ?? 0));
|
|
241
|
+
const stablecoinSupply = usdStables.length ? usdStables.reduce((t, s) => t + s.circ, 0) : null;
|
|
242
|
+
const stablePrev = usdStables.reduce((t, s) => t + (s.prevDay ?? s.circ), 0);
|
|
243
|
+
// Chain TVL: compare with our own observation from 20-48 hours ago.
|
|
244
|
+
const chainList = (chains.data ?? []).sort((a, b) => b.tvl - a.tvl);
|
|
245
|
+
const moves = [];
|
|
246
|
+
let observed = 0;
|
|
247
|
+
for (const c of chainList.filter((c) => c.tvl >= 100e6)) {
|
|
248
|
+
const entity = `chain:${c.name}`;
|
|
249
|
+
const base = ctx.graph.history(entity, 'chain_tvl', 20).find((o) => o.value != null && nowMs - o.observedAt >= 20 * 3600_000 && nowMs - o.observedAt <= 48 * 3600_000);
|
|
250
|
+
ctx.graph.observe(entity, 'defi', 'chain_tvl', c.tvl, 'defillama', {}, nowMs);
|
|
251
|
+
observed++;
|
|
252
|
+
if (!base?.value)
|
|
253
|
+
continue;
|
|
254
|
+
const ch = pct(c.tvl, base.value);
|
|
255
|
+
moves.push({ name: c.name, tvl: Math.round(c.tvl), prevTvl: Math.round(base.value), changePct: round(ch), hoursBetween: Math.round((nowMs - base.observedAt) / 3600_000), vsMarketPct: defiTvlChange1d != null ? round(ch - defiTvlChange1d) : null });
|
|
256
|
+
}
|
|
257
|
+
moves.sort((a, b) => a.changePct - b.changePct);
|
|
258
|
+
// Hacks reported recently.
|
|
259
|
+
const recentHacks = (hacks.data ?? []).filter((x) => nowMs - x.date * 1000 <= hackDays * 86_400_000 + 86_400_000).map(toHack);
|
|
260
|
+
// Fear & Greed (newest first).
|
|
261
|
+
let fearGreed = null;
|
|
262
|
+
const fs = (fng.data?.data ?? []).map((x) => ({ date: new Date(Number(x.timestamp) * 1000).toISOString().slice(0, 10), value: Number(x.value), label: x.value_classification })).filter((x) => Number.isFinite(x.value));
|
|
263
|
+
if (fs.length) {
|
|
264
|
+
const avg = (n) => (fs.length >= n ? round(fs.slice(0, n).reduce((t, x) => t + x.value, 0) / n, 1) : null);
|
|
265
|
+
const change7d = fs[7] ? fs[0].value - fs[7].value : null;
|
|
266
|
+
fearGreed = { value: fs[0].value, label: fs[0].label, date: fs[0].date, avg7d: avg(7), avg30d: avg(30), change7d, trend: change7d == null ? 'unknown' : change7d >= 5 ? 'rising' : change7d <= -5 ? 'falling' : 'flat', series: fs.map(({ date, value }) => ({ date, value })) };
|
|
267
|
+
}
|
|
268
|
+
// Unusual activity: DEX volume or fees more than tripling in a day on a protocol already doing $10M+.
|
|
269
|
+
const activitySpikes = [];
|
|
270
|
+
for (const [kind, r] of [['dex-volume', dexs], ['fees', fees]]) {
|
|
271
|
+
for (const p of r.data?.protocols ?? [])
|
|
272
|
+
if (p.total24h >= 10e6 && (p.change_1d ?? 0) >= 200)
|
|
273
|
+
activitySpikes.push({ kind, name: p.name, category: p.category, total24h: Math.round(p.total24h), change1d: p.change_1d });
|
|
274
|
+
}
|
|
275
|
+
activitySpikes.sort((a, b) => b.change1d - a.change1d);
|
|
276
|
+
const totals = {
|
|
277
|
+
defiTvl: last ? Math.round(last.tvl) : null,
|
|
278
|
+
defiTvlChange1d,
|
|
279
|
+
defiTvlChange7d,
|
|
280
|
+
stablecoinSupply: stablecoinSupply != null ? Math.round(stablecoinSupply) : null,
|
|
281
|
+
stablecoinSupplyChange1d: stablecoinSupply != null && stablePrev ? round(pct(stablecoinSupply, stablePrev), 3) : null,
|
|
282
|
+
dexVolume24h: dexs.data?.total24h ?? null,
|
|
283
|
+
dexVolumeChange1d: dexs.data?.change_1d ?? null,
|
|
284
|
+
dexVolumeChange7d: dexs.data?.change_7d ?? null,
|
|
285
|
+
fees24h: fees.data?.total24h ?? null,
|
|
286
|
+
feesChange1d: fees.data?.change_1d ?? null,
|
|
287
|
+
openInterest: oi.data?.total24h ?? null,
|
|
288
|
+
openInterestChange1d: oi.data?.change_1d ?? null,
|
|
289
|
+
};
|
|
290
|
+
// Signals.
|
|
291
|
+
const day = now.toISOString().slice(0, 10);
|
|
292
|
+
const signals = [];
|
|
293
|
+
for (const m of tvlDrops.slice(0, 10))
|
|
294
|
+
signals.push(dropSignal(m, now));
|
|
295
|
+
for (const d of depegs.slice(0, 8)) {
|
|
296
|
+
signals.push({
|
|
297
|
+
id: signalId('defi', 'depeg', d.symbol, d.name, day),
|
|
298
|
+
module: 'defi',
|
|
299
|
+
title: `${d.name} (${d.symbol}) off its USD peg: $${d.price.toFixed(4)} (${d.offPct.toFixed(1)}% away)`,
|
|
300
|
+
score: depegScore(d.circulating, d.offPct),
|
|
301
|
+
entity: d.name,
|
|
302
|
+
evidence: [{ source: 'defillama-stablecoins', text: `${d.mechanism || 'unknown mechanism'} stablecoin, ${usd(d.circulating)} circulating; supply ${d.supplyChange1dPct ?? 'n/a'}% in 1d, ${d.supplyChange7dPct ?? 'n/a'}% in 7d`, url: d.url, value: d.price }],
|
|
303
|
+
createdAt: now.toISOString(),
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
for (const d of supplyShocks.slice(0, 5)) {
|
|
307
|
+
signals.push({
|
|
308
|
+
id: signalId('defi', 'supply', d.symbol, d.name, day),
|
|
309
|
+
module: 'defi',
|
|
310
|
+
title: `${d.name} (${d.symbol}) supply down ${Math.abs(d.supplyChange1dPct ?? 0).toFixed(1)}% in 24h`,
|
|
311
|
+
score: clamp(50 + Math.abs(d.supplyChange1dPct ?? 0) / 2 + 5 * Math.log10(Math.max(d.circulating, 5e7) / 5e7), 50, 80),
|
|
312
|
+
entity: d.name,
|
|
313
|
+
evidence: [{ source: 'defillama-stablecoins', text: `Mass redemption or burn: ${usd(d.circulating)} circulating now, price $${Number.isFinite(d.price) ? d.price.toFixed(4) : 'n/a'}`, url: d.url, value: d.supplyChange1dPct ?? undefined }],
|
|
314
|
+
createdAt: now.toISOString(),
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
for (const c of moves.filter((m) => m.prevTvl >= 500e6 && m.changePct <= -chainMovePct && (m.vsMarketPct == null || m.vsMarketPct <= -10)).slice(0, 5)) {
|
|
318
|
+
signals.push({
|
|
319
|
+
id: signalId('defi', 'chain', c.name, day),
|
|
320
|
+
module: 'defi',
|
|
321
|
+
title: `${c.name} chain TVL down ${Math.abs(c.changePct).toFixed(1)}% in ${c.hoursBetween}h (${usd(c.prevTvl)} to ${usd(c.tvl)})`,
|
|
322
|
+
score: dropScore(c.prevTvl - c.tvl, -c.changePct) - 5,
|
|
323
|
+
entity: c.name,
|
|
324
|
+
evidence: [{ source: 'defillama', text: `Compared with Oculon's own reading ${c.hoursBetween}h earlier${c.vsMarketPct != null ? `; ${c.vsMarketPct.toFixed(1)} points worse than total DeFi TVL` : ''}`, url: `https://defillama.com/chain/${encodeURIComponent(c.name)}`, value: c.changePct }],
|
|
325
|
+
createdAt: now.toISOString(),
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
for (const x of recentHacks.filter((x) => x.amount >= 1e6).slice(0, 8)) {
|
|
329
|
+
signals.push({
|
|
330
|
+
id: signalId('defi', 'hack', x.name, x.date),
|
|
331
|
+
module: 'defi',
|
|
332
|
+
title: `${x.name} hacked for ${usd(x.amount)} (${x.technique || x.classification || 'exploit'})`,
|
|
333
|
+
score: hackScore(x.amount, x.bridgeHack),
|
|
334
|
+
entity: x.name,
|
|
335
|
+
evidence: [{ source: 'defillama', text: `${x.date}, ${x.chains.join(', ') || 'unknown chain'}, ${x.targetType}${x.returnedFunds ? `, ${usd(x.returnedFunds)} returned` : ''}: ${x.description.slice(0, 220)}`, url: x.url, value: x.amount }],
|
|
336
|
+
createdAt: now.toISOString(),
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
for (const s of signals)
|
|
340
|
+
ctx.graph.saveSignal(s);
|
|
341
|
+
return {
|
|
342
|
+
module: 'defi',
|
|
343
|
+
input: 'defillama + fear & greed',
|
|
344
|
+
generatedAt: now.toISOString(),
|
|
345
|
+
result: {
|
|
346
|
+
totals,
|
|
347
|
+
tvlDrops,
|
|
348
|
+
depegs,
|
|
349
|
+
supplyShocks,
|
|
350
|
+
chains: { top: chainList.slice(0, 15).map((c) => ({ name: c.name, tvl: Math.round(c.tvl) })), moves, observed },
|
|
351
|
+
hacks: recentHacks,
|
|
352
|
+
fearGreed,
|
|
353
|
+
activitySpikes: activitySpikes.slice(0, 15),
|
|
354
|
+
yieldAnomalies: yields?.data ?? [],
|
|
355
|
+
},
|
|
356
|
+
signals,
|
|
357
|
+
provenance,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function slimProtocolDetail(d) {
|
|
361
|
+
if (!d || typeof d !== 'object')
|
|
362
|
+
return null;
|
|
363
|
+
const raw = Array.isArray(d.tvl) ? d.tvl : [];
|
|
364
|
+
// One point per UTC day (the last one), which keeps a multi-year history to a few KB.
|
|
365
|
+
const byDay = new Map();
|
|
366
|
+
for (const p of raw)
|
|
367
|
+
if (num(p?.totalLiquidityUSD) != null)
|
|
368
|
+
byDay.set(new Date(p.date * 1000).toISOString().slice(0, 10), p.totalLiquidityUSD);
|
|
369
|
+
const chains = Object.entries((d.currentChainTvls ?? {}))
|
|
370
|
+
.filter(([k, v]) => !k.includes('-') && /^[A-Z0-9]/.test(k) && num(v) != null)
|
|
371
|
+
.map(([chain, tvl]) => ({ chain, tvl: Math.round(tvl) }))
|
|
372
|
+
.sort((a, b) => b.tvl - a.tvl);
|
|
373
|
+
return {
|
|
374
|
+
name: String(d.name ?? ''),
|
|
375
|
+
category: d.category ?? null,
|
|
376
|
+
description: String(d.description ?? '').slice(0, 500),
|
|
377
|
+
url: String(d.url ?? ''),
|
|
378
|
+
twitter: d.twitter ?? null,
|
|
379
|
+
github: Array.isArray(d.github) ? d.github : [],
|
|
380
|
+
isParent: d.isParentProtocol === true,
|
|
381
|
+
parent: d.parentProtocolSlug ?? null,
|
|
382
|
+
otherProtocols: Array.isArray(d.otherProtocols) ? d.otherProtocols.slice(0, 20) : [],
|
|
383
|
+
chainList: Array.isArray(d.chains) ? d.chains : [],
|
|
384
|
+
chains,
|
|
385
|
+
mcap: num(d.mcap),
|
|
386
|
+
series: [...byDay.entries()].map(([date, tvl]) => ({ date, tvl: Math.round(tvl) })),
|
|
387
|
+
audits: d.audits != null ? String(d.audits) : null,
|
|
388
|
+
auditLinks: Array.isArray(d.audit_links) ? d.audit_links : [],
|
|
389
|
+
oracles: Array.isArray(d.oraclesBreakdown) ? d.oraclesBreakdown.map((o) => o.name) : Array.isArray(d.oracles) ? d.oracles : [],
|
|
390
|
+
forkedFrom: Array.isArray(d.forkedFrom) ? d.forkedFrom : [],
|
|
391
|
+
listedAt: num(d.listedAt),
|
|
392
|
+
hacks: slimHacks(d.hacks),
|
|
393
|
+
raises: (Array.isArray(d.raises) ? d.raises : []).map((r) => ({ date: Number(r.date) || 0, round: String(r.round ?? ''), amount: num(r.amount), leads: Array.isArray(r.leadInvestors) ? r.leadInvestors.slice(0, 5) : [] })),
|
|
394
|
+
hallmarks: (Array.isArray(d.hallmarks) ? d.hallmarks : []).filter((x) => Array.isArray(x)).map((x) => ({ date: Number(Array.isArray(x[0]) ? x[0][0] : x[0]) || 0, event: String(x[1]) })),
|
|
395
|
+
rugged: d.rugged === true,
|
|
396
|
+
deadFrom: d.deadFrom ?? null,
|
|
397
|
+
misrepresentedTokens: d.misrepresentedTokens === true,
|
|
398
|
+
wrongLiquidity: d.wrongLiquidity === true,
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
export const slugify = (s) => s.trim().toLowerCase().replace(/[^a-z0-9.]+/g, '-').replace(/^-+|-+$/g, '');
|
|
402
|
+
/** Resolve a name or slug against the protocol list: exact slug, exact name, then parent slug, then a slugified guess. */
|
|
403
|
+
export function resolveSlug(list, name) {
|
|
404
|
+
const q = name.trim().toLowerCase();
|
|
405
|
+
const s = slugify(name);
|
|
406
|
+
const bySlug = list.find((p) => p.slug === q || p.slug === s);
|
|
407
|
+
if (bySlug)
|
|
408
|
+
return { slug: bySlug.slug, entry: bySlug };
|
|
409
|
+
const byName = list.find((p) => p.name.toLowerCase() === q);
|
|
410
|
+
if (byName)
|
|
411
|
+
return { slug: byName.slug, entry: byName };
|
|
412
|
+
if (list.some((p) => p.parent === s))
|
|
413
|
+
return { slug: s, entry: null };
|
|
414
|
+
return { slug: s, entry: null };
|
|
415
|
+
}
|
|
416
|
+
export async function protocol(ctx, name) {
|
|
417
|
+
const now = ctx.now();
|
|
418
|
+
const nowMs = now.getTime();
|
|
419
|
+
const provenance = [];
|
|
420
|
+
const list = await protocolList(ctx);
|
|
421
|
+
provenance.push(list.prov);
|
|
422
|
+
const { slug, entry } = resolveSlug(list.data ?? [], name);
|
|
423
|
+
const r = await ctx.http.get(`${LLAMA}/protocol/${encodeURIComponent(slug)}`, { source: 'defillama', ttlSec: 1800, timeoutMs: 90_000, keep: slimProtocolDetail });
|
|
424
|
+
provenance.push(r.prov);
|
|
425
|
+
const d = r.data;
|
|
426
|
+
if (!d)
|
|
427
|
+
return { module: 'defi', input: name, generatedAt: now.toISOString(), result: null, signals: [], provenance };
|
|
428
|
+
const series = d.series;
|
|
429
|
+
const lastPt = series.at(-1);
|
|
430
|
+
const back = (days) => {
|
|
431
|
+
if (!lastPt)
|
|
432
|
+
return null;
|
|
433
|
+
const target = Date.parse(lastPt.date) - days * 86_400_000;
|
|
434
|
+
const p = [...series].reverse().find((x) => Date.parse(x.date) <= target);
|
|
435
|
+
return p ? round(pct(lastPt.tvl, p.tvl)) : null;
|
|
436
|
+
};
|
|
437
|
+
const athPt = series.reduce((m, x) => (!m || x.tvl > m.tvl ? x : m), null);
|
|
438
|
+
const tvl = entry?.tvl != null ? Math.round(entry.tvl) : lastPt?.tvl ?? null;
|
|
439
|
+
const children = (list.data ?? []).filter((p) => p.parent === slug);
|
|
440
|
+
const audits = entry?.audits ?? d.audits ?? (children.find((c) => c.audits)?.audits ?? null);
|
|
441
|
+
const auditLinks = [...new Set([...(entry?.audit_links ?? []), ...d.auditLinks, ...children.flatMap((c) => c.audit_links)])].slice(0, 15);
|
|
442
|
+
const oracles = [...new Set([...d.oracles, ...(entry?.oracles ?? []), ...children.flatMap((c) => c.oracles)])];
|
|
443
|
+
const flags = entry ? flagsOf(entry) : [];
|
|
444
|
+
if (!entry) {
|
|
445
|
+
if (d.rugged)
|
|
446
|
+
flags.push('marked rugged by DefiLlama');
|
|
447
|
+
if (d.deadFrom)
|
|
448
|
+
flags.push(`dead since ${d.deadFrom}`);
|
|
449
|
+
if (d.misrepresentedTokens)
|
|
450
|
+
flags.push('misrepresented tokens');
|
|
451
|
+
if (d.wrongLiquidity)
|
|
452
|
+
flags.push('liquidity figures flagged as unreliable');
|
|
453
|
+
}
|
|
454
|
+
if (!audits || audits === '0')
|
|
455
|
+
flags.push('no audit listed on DefiLlama');
|
|
456
|
+
const hacks = d.hacks.map(toHack);
|
|
457
|
+
if (hacks.length)
|
|
458
|
+
flags.push(`${hacks.length} hack${hacks.length > 1 ? 's' : ''} on record (${usd(hacks.reduce((t, x) => t + x.amount, 0))})`);
|
|
459
|
+
const lastRaise = [...d.raises].sort((a, b) => b.date - a.date)[0];
|
|
460
|
+
const detail = {
|
|
461
|
+
name: d.name,
|
|
462
|
+
slug,
|
|
463
|
+
category: entry?.category ?? d.category ?? children[0]?.category ?? '',
|
|
464
|
+
description: d.description,
|
|
465
|
+
url: d.url,
|
|
466
|
+
twitter: d.twitter,
|
|
467
|
+
github: d.github,
|
|
468
|
+
isParent: d.isParent,
|
|
469
|
+
parent: entry?.parent ?? d.parent,
|
|
470
|
+
otherProtocols: d.otherProtocols,
|
|
471
|
+
chains: d.chains.length ? d.chains : d.chainList.map((c) => ({ chain: c, tvl: 0 })),
|
|
472
|
+
tvl,
|
|
473
|
+
mcap: d.mcap,
|
|
474
|
+
mcapToTvl: d.mcap && tvl ? round(d.mcap / tvl) : null,
|
|
475
|
+
change: { d1: entry?.change_1d != null ? round(entry.change_1d) : back(1), d7: entry?.change_7d != null ? round(entry.change_7d) : back(7), d30: back(30), d90: back(90), d365: back(365) },
|
|
476
|
+
ath: athPt ? { tvl: athPt.tvl, date: athPt.date } : null,
|
|
477
|
+
drawdownFromAthPct: athPt && tvl != null ? round(pct(tvl, athPt.tvl)) : null,
|
|
478
|
+
series: series.slice(-90),
|
|
479
|
+
audits,
|
|
480
|
+
auditLinks,
|
|
481
|
+
oracles,
|
|
482
|
+
forkedFrom: [...new Set([...(entry?.forkedFrom ?? []), ...d.forkedFrom])],
|
|
483
|
+
listedAt: d.listedAt ? new Date(d.listedAt * 1000).toISOString().slice(0, 10) : entry?.listedAt ? new Date(entry.listedAt * 1000).toISOString().slice(0, 10) : null,
|
|
484
|
+
hacks,
|
|
485
|
+
raises: { count: d.raises.length, totalUsd: Math.round(d.raises.reduce((t, x) => t + (x.amount ?? 0), 0) * 1e6), last: lastRaise ? { date: new Date(lastRaise.date * 1000).toISOString().slice(0, 10), round: lastRaise.round, amountUsd: lastRaise.amount != null ? Math.round(lastRaise.amount * 1e6) : null, leads: lastRaise.leads } : null },
|
|
486
|
+
hallmarks: d.hallmarks.map((x) => ({ date: new Date(x.date * 1000).toISOString().slice(0, 10), event: x.event })),
|
|
487
|
+
flags,
|
|
488
|
+
};
|
|
489
|
+
const signals = [];
|
|
490
|
+
const d1 = detail.change.d1;
|
|
491
|
+
if (d1 != null && d1 <= -20 && tvl != null) {
|
|
492
|
+
const prev = prevFrom(tvl, d1);
|
|
493
|
+
if (Number.isFinite(prev) && prev >= 50e6) {
|
|
494
|
+
const m = { name: detail.name, slug, category: detail.category, chains: detail.chains.map((c) => c.chain), tvl, prevTvl: Math.round(prev), lostUsd: Math.round(prev - tvl), change1h: entry?.change_1h ?? null, change1d: d1, change7d: detail.change.d7, vsMarketPct: null, flags, url: detail.url };
|
|
495
|
+
signals.push(dropSignal(m, now));
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
for (const x of hacks.filter((x) => nowMs - Date.parse(x.date) <= 31 * 86_400_000 && x.amount >= 1e5).slice(0, 3)) {
|
|
499
|
+
signals.push({
|
|
500
|
+
id: signalId('defi', 'hack', x.name, x.date),
|
|
501
|
+
module: 'defi',
|
|
502
|
+
title: `${x.name} hacked for ${usd(x.amount)} (${x.technique || x.classification || 'exploit'})`,
|
|
503
|
+
score: hackScore(x.amount, x.bridgeHack),
|
|
504
|
+
entity: detail.name,
|
|
505
|
+
evidence: [{ source: 'defillama', text: `${x.date}, ${x.chains.join(', ')}: ${x.description.slice(0, 220)}`, url: x.url, value: x.amount }],
|
|
506
|
+
createdAt: now.toISOString(),
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
for (const s of signals)
|
|
510
|
+
ctx.graph.saveSignal(s);
|
|
511
|
+
return { module: 'defi', input: name, generatedAt: now.toISOString(), result: detail, signals, provenance };
|
|
512
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Email security of a domain: can someone send mail that looks like it comes from it?
|
|
3
|
+
* Reads public DNS over HTTPS (Google Public DNS, no key): MX, SPF, DMARC, common DKIM selectors, MTA-STS,
|
|
4
|
+
* TLS reporting, BIMI, CAA and DNSSEC. Gives a 0-100 score, a plain verdict and the fixes, most important first.
|
|
5
|
+
*/
|
|
6
|
+
import type { Ctx } from '../core/context.js';
|
|
7
|
+
import type { ModuleResult } from '../core/types.js';
|
|
8
|
+
export type SpoofVerdict = 'spoofable' | 'partly protected' | 'protected';
|
|
9
|
+
export interface EmailSecurity {
|
|
10
|
+
domain: string;
|
|
11
|
+
verdict: SpoofVerdict;
|
|
12
|
+
score: number;
|
|
13
|
+
receivesMail: boolean;
|
|
14
|
+
mx: string[];
|
|
15
|
+
spf: {
|
|
16
|
+
record: string | null;
|
|
17
|
+
all: string | null;
|
|
18
|
+
lookups: number;
|
|
19
|
+
problems: string[];
|
|
20
|
+
};
|
|
21
|
+
dmarc: {
|
|
22
|
+
record: string | null;
|
|
23
|
+
policy: string | null;
|
|
24
|
+
subdomainPolicy: string | null;
|
|
25
|
+
pct: number | null;
|
|
26
|
+
reports: boolean;
|
|
27
|
+
problems: string[];
|
|
28
|
+
};
|
|
29
|
+
dkim: {
|
|
30
|
+
selectorsFound: string[];
|
|
31
|
+
checked: string[];
|
|
32
|
+
};
|
|
33
|
+
mtaSts: {
|
|
34
|
+
record: string | null;
|
|
35
|
+
mode: string | null;
|
|
36
|
+
};
|
|
37
|
+
tlsRpt: boolean;
|
|
38
|
+
bimi: boolean;
|
|
39
|
+
caa: string[];
|
|
40
|
+
dnssec: boolean;
|
|
41
|
+
fixes: string[];
|
|
42
|
+
}
|
|
43
|
+
/** SPF details: the "all" qualifier, DNS lookups used (limit 10) and problems. */
|
|
44
|
+
export declare function analyzeSpf(records: string[]): EmailSecurity['spf'];
|
|
45
|
+
/** DMARC details: policy, subdomain policy, percentage, reporting and problems. */
|
|
46
|
+
export declare function analyzeDmarc(records: string[]): EmailSecurity['dmarc'];
|
|
47
|
+
export declare function emailSecurity(ctx: Ctx, input: string): Promise<ModuleResult<EmailSecurity>>;
|