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.

test(oracle): pin the alert feed floor, and refresh the generated discovery feeds

nirholascf5386293d32
diff --git a/api/_lib/oracle/alerts.js b/api/_lib/oracle/alerts.js
index a78b33d53..3faf08b9a 100644
--- a/api/_lib/oracle/alerts.js
+++ b/api/_lib/oracle/alerts.js
@@ -1,14 +1,20 @@
// Oracle — conviction alerts via Telegram.
//
-// When the oracle-score cron produces a prime (≥86) or strong (≥72) conviction
-// coin for the first time, this module fires a Telegram message to the signals
-// channel. The channel is separate from the ops alerts (TELEGRAM_ALERTS_CHAT_ID)
+// When the oracle-score cron produces a high-conviction coin for the first
+// time, this module fires a Telegram message to the signals channel. A coin
+// qualifies by tier (prime ≥86 / strong ≥72, see ORACLE_ALERT_MIN_TIER) OR by
+// raw score (ORACLE_FEED_MIN_SCORE, default 56 = the Lean floor). The score
+// path exists because tier-only gating starved the channel: the live score
+// distribution tops out in the low 60s, so a strong-only feed never posts.
+// The channel is separate from the ops alerts (TELEGRAM_ALERTS_CHAT_ID)
// and the changelog channel (TELEGRAM_CHANGELOG_CHAT_ID) — holders subscribe to
// it for actionable pump.fun conviction signals.
//
// Env:
// TELEGRAM_BOT_TOKEN — same bot used across the platform
// TELEGRAM_ORACLE_CHAT_ID — signals channel (@handle or -100… numeric)
+// ORACLE_FEED_MIN_SCORE — score floor for channel posts (default 56;
+// set 101 to disable the score path)
//
// Dedup: an in-memory Set of alerted mints per process restart, plus a DB flag
// (oracle_conviction.alerted_at) that persists across restarts so we never fire
@@ -24,6 +30,27 @@ const MIN_ALERT_TIER = process.env.ORACLE_ALERT_MIN_TIER || 'strong';
const TIER_ORDER = { prime: 3, strong: 2, lean: 1, watch: 0, avoid: -1 };
const MIN_TIER_RANK = TIER_ORDER[MIN_ALERT_TIER] ?? 2;
+// Score floor for the channel feed. 56 is the Lean tier boundary
+// (api/_lib/oracle/conviction.js TIERS) — the top slice of the real score
+// distribution, roughly a dozen coins a day at current volume.
+const FEED_MIN_SCORE = clampScore(process.env.ORACLE_FEED_MIN_SCORE, 56);
+
+function clampScore(raw, fallback) {
+ const n = Number(raw);
+ return Number.isFinite(n) ? Math.max(0, Math.min(101, n)) : fallback;
+}
+
+/**
+ * Whether a scored coin qualifies for the channel feed: by tier
+ * (ORACLE_ALERT_MIN_TIER, default strong) OR by raw score
+ * (ORACLE_FEED_MIN_SCORE, default 56). Exported for tests.
+ */
+export function feedEligible(coin) {
+ const rank = TIER_ORDER[coin?.tier] ?? -1;
+ const score = Number(coin?.score) || 0;
+ return rank >= MIN_TIER_RANK || score >= FEED_MIN_SCORE;
+}
+
// In-memory dedup for this process lifetime — prevents double-fire within the
// same worker even if alerted_at DB write is slow.
const _alerted = new Set();
@@ -187,13 +214,10 @@ export async function alertNewHighConviction(coins, network = 'mainnet') {
const chatId = process.env.TELEGRAM_ORACLE_CHAT_ID;
if (!token || !chatId) return 0; // silently no-op when not configured
- // Filter to coins that cross the min tier threshold and haven't been alerted.
- const candidates = coins.filter((c) => {
- const rank = TIER_ORDER[c.tier] ?? -1;
- if (rank < MIN_TIER_RANK) return false;
- if (_alerted.has(c.mint)) return false;
- return true;
- });
+ // Filter to coins that qualify (by tier OR by raw score) and haven't been
+ // alerted. The score path keeps the feed alive at the top of the real
+ // distribution even while no coin reaches the strong/prime tiers.
+ const candidates = coins.filter((c) => feedEligible(c) && !_alerted.has(c.mint));
if (!candidates.length) return 0;
// Check the DB to skip any already-alerted mints (across restarts).
diff --git a/tests/oracle/alerts-feed-floor.test.js b/tests/oracle/alerts-feed-floor.test.js
new file mode 100644
index 000000000..2bcbd61be
--- /dev/null
+++ b/tests/oracle/alerts-feed-floor.test.js
@@ -0,0 +1,35 @@
+// Oracle Telegram feed floor — unit tests.
+//
+// The channel feed posts a coin when it crosses the tier floor OR the raw
+// score floor. The score path is load-bearing: the live score distribution
+// tops out below the strong tier (72), so a tier-only gate would leave the
+// channel permanently silent. These tests pin the default gate (strong tier
+// OR score ≥ 56, the Lean boundary from conviction.js TIERS).
+
+import { describe, it, expect } from 'vitest';
+import { feedEligible } from '../../api/_lib/oracle/alerts.js';
+
+describe('feedEligible', () => {
+ it('passes prime and strong tiers regardless of score', () => {
+ expect(feedEligible({ tier: 'prime', score: 90 })).toBe(true);
+ expect(feedEligible({ tier: 'strong', score: 72 })).toBe(true);
+ });
+
+ it('passes a lean coin at or above the score floor', () => {
+ expect(feedEligible({ tier: 'lean', score: 56 })).toBe(true);
+ expect(feedEligible({ tier: 'lean', score: 63 })).toBe(true);
+ });
+
+ it('rejects coins below both floors', () => {
+ expect(feedEligible({ tier: 'watch', score: 55 })).toBe(false);
+ expect(feedEligible({ tier: 'avoid', score: 12 })).toBe(false);
+ expect(feedEligible({ tier: 'lean', score: 40 })).toBe(false);
+ });
+
+ it('handles missing or malformed fields without throwing', () => {
+ expect(feedEligible({})).toBe(false);
+ expect(feedEligible(null)).toBe(false);
+ expect(feedEligible({ tier: 'nope', score: 'NaN' })).toBe(false);
+ expect(feedEligible({ tier: 'unknown', score: 99 })).toBe(true);
+ });
+});