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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
feat(arena): show an agent's winning streak on the Arena board from its closed-position ledger
nirholasd06feb19bed3
diff --git a/api/_lib/win-streak.js b/api/_lib/win-streak.jsnew file mode 100644index 000000000..d1268b63b--- /dev/null+++ b/api/_lib/win-streak.js@@ -0,0 +1,47 @@+/**+ * Hot-streak math for the trading arena.+ *+ * A streak is the number of consecutive winning closed positions ending at an+ * agent's most recent close. A loss (or flat exit) breaks it. Only runs of+ * HOT_STREAK_MIN or more are surfaced as "hot" so one lucky trade is not+ * presented as a trend.+ */++export const HOT_STREAK_MIN = 3;++/**+ * @param {Array<{realized_pnl_lamports: string|number|bigint|null}>} closedNewestFirst+ * closed positions for ONE agent, most recent close first.+ * @returns {number} current consecutive-win count (0 when the latest close lost).+ */+export function currentWinStreak(closedNewestFirst) {+ let streak = 0;+ for (const p of closedNewestFirst || []) {+ if (p?.realized_pnl_lamports == null) break;+ let pnl;+ try {+ pnl = BigInt(p.realized_pnl_lamports);+ } catch {+ break;+ }+ if (pnl <= 0n) break;+ streak += 1;+ }+ return streak;+}++/**+ * Group newest-first closed rows (any agents interleaved) into a map of+ * agent_id -> current win streak.+ * @param {Array<{agent_id: string, realized_pnl_lamports: any}>} rows ordered by closed_at desc+ */+export function winStreaksByAgent(rows) {+ const byAgent = new Map();+ for (const r of rows || []) {+ if (!byAgent.has(r.agent_id)) byAgent.set(r.agent_id, []);+ byAgent.get(r.agent_id).push(r);+ }+ const out = new Map();+ for (const [id, list] of byAgent) out.set(id, currentWinStreak(list));+ return out;+}diff --git a/api/sniper/leaderboard.js b/api/sniper/leaderboard.jsindex bafbf4e12..d6a639240 100644--- a/api/sniper/leaderboard.js+++ b/api/sniper/leaderboard.js@@ -27,6 +27,7 @@ import { cors, json, method, wrap, rateLimited } from '../_lib/http.js';import { limits, clientIp } from '../_lib/rate-limit.js';import { sql } from '../_lib/db.js';import { getLeaderboard, WINDOWS, LEADERBOARD_SORTS } from '../_lib/trader-stats.js';+import { winStreaksByAgent, HOT_STREAK_MIN } from '../_lib/win-streak.js';const NETWORKS = new Set(['mainnet', 'devnet']);@@ -136,6 +137,28 @@ export default wrap(async (req, res) => {`.catch(() => [{}]),]);+ // Hot streaks: consecutive winning closes ending at each board agent's latest+ // close. Derived from the same closed-position ledger the profile shows.+ const boardIds = boardResult.leaderboard.map((r) => r.agent_id).filter(Boolean);+ const streakRows = boardIds.length+ ? await sql`+ select agent_id, realized_pnl_lamports+ from (+ select p.agent_id, p.realized_pnl_lamports,+ row_number() over (partition by p.agent_id order by p.closed_at desc) as rn+ from agent_sniper_positions p+ where p.network = ${network} and p.status = 'closed' and p.agent_id = any(${boardIds})+ ) t+ where rn <= 25+ order by agent_id, rn+ `.catch(() => [])+ : [];+ const streaks = winStreaksByAgent(streakRows);+ const leaderboard = boardResult.leaderboard.map((r) => {+ const win_streak = streaks.get(r.agent_id) || 0;+ return { ...r, win_streak, hot_streak: win_streak >= HOT_STREAK_MIN };+ });+// Real-trade scoreboard (on-chain fills only). Powers the homepage KPIs that// claim "real positions · no simulation" — kept structurally separate from the// trader-stats board (which includes paper fills for track-record continuity).@@ -208,7 +231,7 @@ export default wrap(async (req, res) => {sort,source,sol_usd: boardResult.sol_usd,- leaderboard: boardResult.leaderboard,+ leaderboard,real_stats,live_traders: live,live_window: source === 'live' ? (KOL_WINDOW[window] || '7d') : null,diff --git a/data/changelog.json b/data/changelog.jsonindex f9e0c9274..0121aff39 100644--- a/data/changelog.json+++ b/data/changelog.json@@ -3,12 +3,12 @@"entries": [{"date": "2026-10-23",- "title": "Limit, stop, trailing, ladder, OCO and DCA orders on any Solana token, from any MCP client",- "summary": "Agent orders are no longer limited to pump.fun tokens. Any SPL token can carry a limit, stop, trailing stop, ladder of take-profit levels, OCO pair or DCA schedule, filled through Jupiter or PumpSwap on the same audited path (spend policy, kill switch, rug firewall, one idempotency key per slice, per-agent lock). MCP clients get order_preview and dca_preview, which return what would be placed and when, then create tools that only accept the signed preview plus an explicit confirm flag. Each agent has an order book showing the next fire time and a plain reason for every skip, and you are notified when an order fires, fails or expires. The two DCA systems are now one store, and existing schedules were migrated intact.",+ "title": "Hot streaks on the Arena board",+ "summary": "An agent that has closed three or more winning positions in a row now shows its streak beside its name on the Arena leaderboard. The streak is counted from the same on-chain closed-position ledger as the trader profile, and any loss or flat exit resets it to zero.","tags": ["feature"],- "link": "/docs/mcp"+ "link": "/play/arena"},{"date": "2026-10-23",diff --git a/src/play/arena.js b/src/play/arena.jsindex 0b9b57cc3..1ff110c17 100644--- a/src/play/arena.js+++ b/src/play/arena.js@@ -101,6 +101,7 @@ function normalizeRow(r, kind) {score: r.score,verified: r.verified,copiers: r.copiers ?? 0,+ win_streak: r.hot_streak ? (r.win_streak ?? 0) : 0,image: r.image || '',};}@@ -786,7 +787,7 @@ function renderBoard(rows) {const avatarFallback = `data-fallback="element" data-fallback-tag="span" data-fallback-class="r-av r-av-fb" data-fallback-text="${initial}"`;const sub = r.kind === 'live'? `${r.trades != null ? Number(r.trades).toLocaleString('en-US') + ' trades' : 'live'}${r.win_pct != null ? ' · ' + Math.round(r.win_pct) + '% win' : ''}`- : `${r.open} open · ${r.closed ? Math.round(r.win_pct) + '% win' : 'new'}`;+ : `${r.open} open · ${r.closed ? Math.round(r.win_pct) + '% win' : 'new'}${r.win_streak ? ' · 🔥 ' + r.win_streak + ' wins in a row' : ''}`;// Live wallets have no avatar — use the mono-initial tile directly.const av = r.kind === 'live'? `<span class="r-av r-av-fb">${initial}</span>`diff --git a/tests/win-streak.test.js b/tests/win-streak.test.jsnew file mode 100644index 000000000..aae1a69cf--- /dev/null+++ b/tests/win-streak.test.js@@ -0,0 +1,43 @@+import { describe, it, expect } from 'vitest';+import { currentWinStreak, winStreaksByAgent, HOT_STREAK_MIN } from '../api/_lib/win-streak.js';++const w = (n = '1000') => ({ realized_pnl_lamports: n });+const l = (n = '-500') => ({ realized_pnl_lamports: n });++describe('currentWinStreak', () => {+ it('is 0 for no trades', () => {+ expect(currentWinStreak([])).toBe(0);+ expect(currentWinStreak(undefined)).toBe(0);+ });+ it('counts consecutive wins from the newest close', () => {+ expect(currentWinStreak([w(), w(), w(), l(), w()])).toBe(3);+ });+ it('is 0 when the newest close lost or was flat', () => {+ expect(currentWinStreak([l(), w(), w()])).toBe(0);+ expect(currentWinStreak([w('0'), w()])).toBe(0);+ });+ it('stops at an unrecorded pnl rather than counting through it', () => {+ expect(currentWinStreak([w(), { realized_pnl_lamports: null }, w()])).toBe(1);+ });+ it('handles bigint and numeric lamports', () => {+ expect(currentWinStreak([{ realized_pnl_lamports: 5n }, { realized_pnl_lamports: 7 }])).toBe(2);+ });+});++describe('winStreaksByAgent', () => {+ it('computes per-agent streaks from interleaved newest-first rows', () => {+ const rows = [+ { agent_id: 'a', ...w() },+ { agent_id: 'b', ...l() },+ { agent_id: 'a', ...w() },+ { agent_id: 'b', ...w() },+ { agent_id: 'a', ...l() },+ ];+ const m = winStreaksByAgent(rows);+ expect(m.get('a')).toBe(2);+ expect(m.get('b')).toBe(0);+ });+ it('exposes the hot threshold', () => {+ expect(HOT_STREAK_MIN).toBe(3);+ });+});