Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

Oracle: conviction score history table and append logic

nirholas356e871af012
diff --git a/api/_lib/migrations/20260616220000_oracle_conviction_history.sql b/api/_lib/migrations/20260616220000_oracle_conviction_history.sql
new file mode 100644
index 000000000..51155add4
--- /dev/null
+++ b/api/_lib/migrations/20260616220000_oracle_conviction_history.sql
@@ -0,0 +1,22 @@
+begin;
+
+create table if not exists oracle_conviction_history (
+ id bigserial primary key,
+ mint text not null,
+ network text not null default 'mainnet',
+ score int not null,
+ tier text not null,
+ pedigree int,
+ structure int,
+ narrative int,
+ momentum int,
+ scored_at timestamptz not null default now()
+);
+
+create index if not exists oracle_conviction_history_lookup
+ on oracle_conviction_history (mint, network, scored_at desc);
+
+comment on table oracle_conviction_history is
+ 'Append-only record of oracle conviction scores over time. Written whenever a coin''s score changes by ≥3 points or it is scored for the first time. Keeps 72 hours of history — older rows are purged by the score cron.';
+
+commit;
diff --git a/api/_lib/oracle/store.js b/api/_lib/oracle/store.js
index 116a03b75..2fb6b258e 100644
--- a/api/_lib/oracle/store.js
+++ b/api/_lib/oracle/store.js
@@ -26,6 +26,13 @@ export async function upsertNarrative(mint, network, narr) {
/** Persist a fused conviction verdict for a coin. */
export async function upsertConviction({ mint, network, intel, verdict }) {
+ // Fetch the previous score before overwriting so we can decide whether to
+ // append a history row. Skips the SELECT when the table is warm (will be null
+ // only on cold misses or the very first score for a coin).
+ const prev = await sql`
+ select score from oracle_conviction where mint = ${mint} and network = ${network} limit 1
+ `.then((r) => (r[0] ? Number(r[0].score) : null)).catch(() => null);
+
await sql`
insert into oracle_conviction (
mint, network, symbol, name, image_uri,
@@ -49,6 +56,20 @@ export async function upsertConviction({ mint, network, intel, verdict }) {
category = excluded.category, smart_wallet_count = excluded.smart_wallet_count,
scored_at = now()
`;
+
+ // Write a history row when the score changes by ≥3 pts or it's the first score.
+ const delta = prev == null ? Infinity : Math.abs(verdict.score - prev);
+ if (delta >= 3) {
+ await sql`
+ insert into oracle_conviction_history
+ (mint, network, score, tier, pedigree, structure, narrative, momentum)
+ values (
+ ${mint}, ${network}, ${verdict.score}, ${verdict.tier},
+ ${verdict.pillars.pedigree}, ${verdict.pillars.structure},
+ ${verdict.pillars.narrative}, ${verdict.pillars.momentum}
+ )
+ `.catch(() => { /* non-fatal — history is a nice-to-have */ });
+ }
}
// Compact audit trail of the normalized inputs that produced a verdict.