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: add top-earning coin spotlight to leaderboard — enhance trader metrics with per-coin P&L breakdown
nrpo4f015a8cb90b
diff --git a/api/_lib/trader-stats.js b/api/_lib/trader-stats.jsindex 4020082b3..c2143dbca 100644--- a/api/_lib/trader-stats.js+++ b/api/_lib/trader-stats.js@@ -160,6 +160,11 @@ export function computeTraderMetrics(positions, { solUsd = null, selfDealMints =const winPcts = [], lossPcts = [];const holdSeconds = [];const coins = new Set();+ // Per-coin realized P&L aggregation — the "what they made it on" breakdown. A+ // trader can round-trip the same mint several times, so we sum lamports per mint+ // and pick the winner(s) after the loop. Provable: every lamport traces to a+ // closed position's realized_pnl_lamports.+ const coinAgg = new Map(); // mint -> { pnl, invested, trades, wins, symbol, name }let churn = 0;let bestPct = null, worstPct = null;let firstActive = null, lastActive = null;@@ -179,7 +184,17 @@ export function computeTraderMetrics(positions, { solUsd = null, selfDealMints =equityPnls.push(big(p.realized_pnl_lamports));if (pnl > 0n) { wins += 1; grossProfit += pnl; } else if (pnl < 0n) { losses += 1; grossLoss += -pnl; }invested += BigInt(p.entry_quote_lamports ?? 0);- if (p.mint) coins.add(p.mint);+ if (p.mint) {+ coins.add(p.mint);+ let ca = coinAgg.get(p.mint);+ if (!ca) { ca = { pnl: 0n, invested: 0n, trades: 0, wins: 0, symbol: p.symbol || null, name: p.name || null }; coinAgg.set(p.mint, ca); }+ ca.pnl += pnl;+ ca.invested += BigInt(p.entry_quote_lamports ?? 0);+ ca.trades += 1;+ if (pnl > 0n) ca.wins += 1;+ if (!ca.symbol && p.symbol) ca.symbol = p.symbol;+ if (!ca.name && p.name) ca.name = p.name;+ }const pct = p.realized_pnl_pct != null ? Number(p.realized_pnl_pct) : null;if (pct != null && Number.isFinite(pct)) {@@ -266,6 +281,28 @@ export function computeTraderMetrics(positions, { solUsd = null, selfDealMints =const usd = (sol) => (solUsd != null ? sol * solUsd : null);+ // --- "What they made it on" — per-coin realized P&L, best first ---+ // Ranked by realized SOL contribution. The trades a coin cost them count too+ // (survivorship-honest), so a coin can rank with a negative total; the surfaces+ // only badge `top_coin` as a signature win when it is net-positive.+ const coinPnl = [...coinAgg.entries()]+ .map(([mint, c]) => {+ const pnlSol = big(c.pnl.toString()) / LAMPORTS_PER_SOL;+ const investedSol = big(c.invested.toString()) / LAMPORTS_PER_SOL;+ return {+ mint,+ symbol: c.symbol,+ name: c.name,+ pnl_sol: Number(pnlSol.toFixed(6)),+ pnl_usd: usd(pnlSol) != null ? Number(usd(pnlSol).toFixed(2)) : null,+ roi_pct: investedSol > 0 ? Number(((pnlSol / investedSol) * 100).toFixed(2)) : null,+ trades: c.trades,+ wins: c.wins,+ };+ })+ .sort((a, b) => b.pnl_sol - a.pnl_sol);+ const topCoin = coinPnl.length ? coinPnl[0] : null;+// Self-dealing summary (transparent, never folded into the credited numbers).let selfDealClosed = 0;let selfDealPnlLamports = 0n;@@ -316,6 +353,12 @@ export function computeTraderMetrics(positions, { solUsd = null, selfDealMints =unique_coins: coins.size,churn_pct: Number(churnPct.toFixed(2)),+ // What they made it on — the single top-earning coin plus a short breakdown,+ // each number traceable to the closed positions above. `top_coin` is null+ // only when the trader has no closed positions with a mint in this window.+ top_coin: topCoin,+ top_coins: coinPnl.slice(0, 3),+// Snipe hit-rate — win rate on entries inside SNIPE_WINDOW_MS of a coin's// proven on-chain birth. null until at least one such launch is in the// sample; `snipe_sample` exposes the coverage so the rate is never overclaimed.@@ -845,6 +888,7 @@ export async function getLeaderboard({avg_hold_seconds: m.avg_hold_seconds,unique_coins: m.unique_coins,churn_pct: m.churn_pct,+ top_coin: m.top_coin,snipe_hit_rate: m.snipe_hit_rate,snipe_count: m.snipe_count,self_dealing_count: m.self_dealing_count,diff --git a/pages/leaderboard.html b/pages/leaderboard.htmlindex ade7e0a55..58561833e 100644--- a/pages/leaderboard.html+++ b/pages/leaderboard.html@@ -129,6 +129,8 @@</dl></section>+ <section class="lb-spotlight" id="lb-spotlight" hidden aria-label="Most profitable trader"></section>+<section class="lb-controls" aria-label="Leaderboard filters"><div class="lb-seg" role="tablist" aria-label="Time window" id="lb-window"><button class="lb-seg-btn" data-window="24h" role="tab">24h</button>diff --git a/public/nav-data.js b/public/nav-data.jsindex 89a465db1..0503c72c2 100644--- a/public/nav-data.js+++ b/public/nav-data.js@@ -38,11 +38,6 @@ export const NAV_GROUPS = [{label: 'Start here',items: [- {- title: 'Instant Agent Genesis',- href: '/genesis',- desc: 'Selfie or prompt → 3D agent + funded wallet + on-chain identity in 60s',- },{title: 'Create an avatar',href: '/create-agent',diff --git a/src/leaderboard.css b/src/leaderboard.cssindex 13c970a61..490759ec6 100644--- a/src/leaderboard.css+++ b/src/leaderboard.css@@ -379,6 +379,124 @@}.lb-copiers { color: var(--success); }+/* ---- Signature coin — "what they made it on" (leaderboard rows + profile) ---- */+.sig-coin {+ display: inline-flex;+ align-items: baseline;+ gap: 4px;+ font-family: var(--font-mono);+ font-variant-numeric: tabular-nums;+ max-width: 100%;+ min-width: 0;+}+.sig-coin-lead { color: var(--ink-faint); }+.sig-coin-sym {+ font-weight: var(--weight-semibold);+ color: var(--ink-bright);+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+ max-width: 12ch;+}+.sig-coin.lb-pos .sig-coin-pnl { color: var(--success); }+.sig-coin.lb-neg .sig-coin-pnl { color: var(--danger); }+.sig-coin.lb-muted .sig-coin-pnl { color: var(--ink-faint); }++/* ---- Most Profitable Trader spotlight ---- */+.lb-spotlight { margin: 0 0 var(--space-lg); }+.lb-spot-card {+ display: block;+ text-decoration: none;+ color: inherit;+ border: 1px solid color-mix(in srgb, #fcd34d 26%, var(--stroke));+ border-radius: var(--radius-lg, 16px);+ background:+ radial-gradient(120% 140% at 0% 0%, color-mix(in srgb, #fcd34d 12%, transparent), transparent 60%),+ var(--surface-1, var(--surface-2));+ padding: var(--space-sm) var(--space-md) var(--space-md);+ position: relative;+ overflow: hidden;+ transition: border-color var(--duration-fast) var(--ease-standard), transform var(--duration-fast) var(--ease-standard);+ animation: lb-row-in var(--duration-base) var(--ease-out) both;+}+.lb-spot-card:hover { border-color: color-mix(in srgb, #fcd34d 55%, var(--stroke)); transform: translateY(-1px); }+.lb-spot-card:focus-visible {+ outline: var(--focus-ring-width) solid var(--focus-ring-color);+ outline-offset: 2px;+}+.lb-spot-tag {+ display: inline-flex;+ align-items: center;+ gap: var(--space-3xs);+ font-family: var(--font-mono);+ font-size: var(--text-2xs);+ letter-spacing: 0.06em;+ text-transform: uppercase;+ color: #fcd34d;+ margin-bottom: var(--space-sm);+}+.lb-spot-crown { font-size: 1.05em; line-height: 1; }+.lb-spot-body {+ display: flex;+ align-items: center;+ gap: var(--space-md);+ min-width: 0;+}+.lb-spot-av {+ width: 56px;+ height: 56px;+ border-radius: 50%;+ object-fit: cover;+ border: 2px solid color-mix(in srgb, #fcd34d 40%, var(--stroke));+ background: var(--surface-3);+ flex-shrink: 0;+}+.lb-spot-main { min-width: 0; flex: 1; }+.lb-spot-name {+ display: flex;+ align-items: center;+ gap: var(--space-2xs);+ font-family: var(--font-display);+ font-weight: var(--weight-bold);+ font-size: var(--text-lg);+ min-width: 0;+}+.lb-spot-name .lb-verified svg { width: 16px; height: 16px; }+.lb-spot-coin {+ margin-top: 3px;+ font-size: var(--text-xs);+ display: flex;+ align-items: baseline;+ gap: 5px;+ min-width: 0;+}+.lb-spot-coin-lead { color: var(--ink-dim); font-family: var(--font-mono); font-size: var(--text-2xs); }+.lb-spot-pnl { text-align: right; flex-shrink: 0; }+.lb-spot-pnl-val {+ font-family: var(--font-display);+ font-weight: var(--weight-bold);+ font-size: var(--text-xl);+ font-variant-numeric: tabular-nums;+ line-height: 1.1;+}+.lb-spot-pnl-sub { font-size: var(--text-2xs); color: var(--ink-faint); font-family: var(--font-mono); margin-top: 2px; }+.lb-spot-cta {+ flex-shrink: 0;+ font-size: var(--text-2xs);+ font-weight: var(--weight-semibold);+ color: var(--ink-dim);+ border: 1px solid var(--stroke);+ border-radius: var(--radius-pill);+ padding: var(--space-3xs) var(--space-sm);+ white-space: nowrap;+}+.lb-spot-card:hover .lb-spot-cta { color: var(--ink-bright); border-color: var(--stroke-strong); }+@media (max-width: 640px) {+ .lb-spot-cta { display: none; }+ .lb-spot-pnl-val { font-size: var(--text-lg); }+ .lb-spot-av { width: 46px; height: 46px; }+}+.lb-score {display: inline-flex;align-items: baseline;diff --git a/src/leaderboard.js b/src/leaderboard.jsindex 011228a35..dd0af48b6 100644--- a/src/leaderboard.js+++ b/src/leaderboard.js@@ -9,7 +9,7 @@import {escapeHtml, fmtSol, fmtUsd, fmtPct, pnlClass, shortAddr, holdTime, relTime,- identicon, verifiedBadge,+ identicon, verifiedBadge, signatureCoin,} from './trader-format.js';import { walletChipHTML, wireWalletChips } from './shared/agent-wallet-chip.js';import { updateValue, flipReorder, setLiveDot } from './ui-juice.js';@@ -106,7 +106,7 @@ function rowMarkup(r) {<img class="lb-avatar" src="${escapeHtml(img)}" alt="" loading="lazy" onerror="this.src='${identicon(r.agent_id || r.wallet || '?')}'" /><span class="lb-trader-meta"><span class="lb-trader-name"><span class="lb-trader-nm">${escapeHtml(r.agent_name || 'Unnamed agent')}</span>${verifiedBadge(r.verified)}</span>- <span class="lb-trader-sub">${r.wallet ? walletChipHTML(r, { isOwner: false, showPending: false, link: false }) : escapeHtml(shortAddr(r.wallet))} · ${r.unique_coins} coins${r.copiers ? ` · <span class="lb-copiers">${r.copiers} copying</span>` : ''}</span>+ <span class="lb-trader-sub">${r.wallet ? walletChipHTML(r, { isOwner: false, showPending: false, link: false }) : escapeHtml(shortAddr(r.wallet))} · ${r.unique_coins} coins${r.copiers ? ` · <span class="lb-copiers">${r.copiers} copying</span>` : ''}${r.top_coin ? ` · ${signatureCoin(r.top_coin, { compact: true })}` : ''}</span></span></span><span class="lb-num">@@ -261,6 +261,49 @@ function renderSummary(data) {setSummaryNum($('#lb-sum-top'), top ? top.realized_pnl_sol : null, fmtSol);}+// --- Most Profitable Trader spotlight ----------------------------------------+// A hero card for the single most profitable provable agent in the window —+// avatar, realized P&L, and the coin they made it on. Only shown for real agent+// records with a positive realized P&L; hidden in the live-fallback mode (those+// external wallets have no three.ws profile to spotlight) and when nobody is up.+const WINDOW_LABEL = { '24h': '24h', '7d': '7d', '30d': '30d', all: 'all-time' };++function renderSpotlight(data) {+ const el = document.getElementById('lb-spotlight');+ if (!el) return;+ const agents = data.leaderboard || [];+ const top = [...agents]+ .filter((a) => a.realized_pnl_sol > 0)+ .sort((a, b) => b.realized_pnl_sol - a.realized_pnl_sol)[0];+ if (!top) { el.hidden = true; el.innerHTML = ''; return; }++ const img = top.image || identicon(top.agent_id || top.wallet || top.agent_name || '?');+ const href = `/trader/${encodeURIComponent(top.agent_id)}`;+ const name = escapeHtml(top.agent_name || 'Unnamed agent');+ const usd = top.realized_pnl_usd != null ? ` · ${fmtUsd(top.realized_pnl_usd)}` : '';+ const coin = top.top_coin+ ? `<div class="lb-spot-coin"><span class="lb-spot-coin-lead">Made it on</span> ${signatureCoin(top.top_coin)}</div>`+ : '';+ const label = `Most profitable trader: ${top.agent_name || 'agent'}, ${fmtSol(top.realized_pnl_sol)} realized${top.top_coin && top.top_coin.symbol ? `, made on ${top.top_coin.symbol}` : ''}`;+ el.innerHTML = `+ <a class="lb-spot-card" href="${href}" aria-label="${escapeHtml(label)}">+ <div class="lb-spot-tag"><span class="lb-spot-crown" aria-hidden="true">♛</span> Most profitable trader · ${escapeHtml(WINDOW_LABEL[state.window] || state.window)}</div>+ <div class="lb-spot-body">+ <img class="lb-spot-av" src="${escapeHtml(img)}" alt="" loading="lazy" onerror="this.src='${identicon(top.agent_id || '?')}'" />+ <div class="lb-spot-main">+ <div class="lb-spot-name">${name}${verifiedBadge(top.verified)}</div>+ ${coin}+ </div>+ <div class="lb-spot-pnl">+ <div class="lb-spot-pnl-val ${pnlClass(top.realized_pnl_sol)}">${fmtSol(top.realized_pnl_sol)}</div>+ <div class="lb-spot-pnl-sub">${fmtPct(top.win_rate * 100)} win rate${usd}</div>+ </div>+ <span class="lb-spot-cta">Track record →</span>+ </div>+ </a>`;+ el.hidden = false;+}+function renderTicker(trades) {const el = $('#lb-ticker');// No internal closes (e.g. while the live fallback board is showing) — hide the@@ -353,6 +396,7 @@ async function load() {if (!res.ok) throw new Error(`HTTP ${res.status}`);const data = await res.json();renderSummary(data);+ renderSpotlight(data);renderBoard(data);renderTicker(data.trades);firstLoad = false;diff --git a/src/trader-format.js b/src/trader-format.jsindex 9fe16f9fb..acd73733f 100644--- a/src/trader-format.js+++ b/src/trader-format.js@@ -113,4 +113,21 @@ export function verifiedBadge(verified, label = 'Verified track record') {return `<span class="lb-verified" title="${escapeHtml(label)}" aria-label="${escapeHtml(label)}">${CHECK_SVG}</span>`;}+/**+ * Signature-coin chip — the token a trader made (or lost) the most on. `coin` is a+ * `top_coin` object from the trader-stats truth layer ({ mint, symbol, name,+ * pnl_sol, roi_pct, … }). Renders the ticker + signed realized P&L, tinted by+ * direction. Returns '' when there is nothing to show, so callers can drop it in+ * unconditionally. `compact:true` omits the "made on" lead-in for tight rows.+ */+export function signatureCoin(coin, { compact = false } = {}) {+ if (!coin || (!coin.symbol && !coin.name && !coin.mint)) return '';+ const label = escapeHtml(coin.symbol || coin.name || shortAddr(coin.mint, 4, 4));+ const cls = pnlClass(coin.pnl_sol);+ const pnl = fmtSol(coin.pnl_sol);+ const lead = compact ? '' : '<span class="sig-coin-lead">made on</span>';+ const verb = coin.pnl_sol >= 0 ? 'best coin' : 'biggest hit';+ return `<span class="sig-coin ${cls}" title="${verb}: ${label} · ${escapeHtml(pnl)} realized${coin.roi_pct != null ? ` · ${coin.roi_pct > 0 ? '+' : ''}${coin.roi_pct}% ROI` : ''}">${lead}<span class="sig-coin-sym">${label}</span><span class="sig-coin-pnl">${escapeHtml(pnl)}</span></span>`;+}+export { SOL };diff --git a/src/trader.js b/src/trader.jsindex 5c95fa71c..6152556cc 100644--- a/src/trader.js+++ b/src/trader.js@@ -10,7 +10,7 @@import {escapeHtml, fmtSol, fmtUsd, fmtPct, pnlClass, shortAddr, holdTime, relTime,- identicon, verifiedBadge,+ identicon, verifiedBadge, signatureCoin,} from './trader-format.js';import { mountCopyPanel } from './copy-panel.js';import { walletChipHTML, wireWalletChips } from './shared/agent-wallet-chip.js';diff --git a/tests/trader-stats.test.js b/tests/trader-stats.test.jsindex 6ee1bb27e..276c151c4 100644--- a/tests/trader-stats.test.js+++ b/tests/trader-stats.test.js@@ -116,6 +116,20 @@ describe('computeTraderMetrics', () => {expect(m.first_active_at).toBe('2026-01-01T00:00:00.000Z');expect(m.last_active_at).toBe('2026-01-01T00:15:00.000Z'); // open E opened latest});++ it('surfaces the top-earning coin ("what they made it on")', () => {+ // A made the most: +2 SOL on 1 SOL invested → +200% ROI, priced to USD.+ expect(m.top_coin).toMatchObject({+ mint: 'AAAA', symbol: 'A', pnl_sol: 2, roi_pct: 200, trades: 1, wins: 1,+ });+ expect(m.top_coin.pnl_usd).toBeCloseTo(400, 2); // 2 × 200+ });++ it('ranks the per-coin breakdown best-first, losers included', () => {+ // Best→worst: A (+2), C (+0.5), D (+0.01) — B (−0.5) falls outside the top 3.+ expect(m.top_coins.map((c) => c.symbol)).toEqual(['A', 'C', 'D']);+ expect(m.top_coins[0].pnl_sol).toBe(2);+ });});describe('computeTraderMetrics — degenerate inputs', () => {@@ -128,6 +142,8 @@ describe('computeTraderMetrics — degenerate inputs', () => {expect(m.realized_pnl_usd).toBe(0);expect(m.verified).toBe(false);expect(m.score).toBe(42); // confidence 0 → fully regressed to NEUTRAL_RAW+ expect(m.top_coin).toBeNull(); // no closed positions → no coin to credit+ expect(m.top_coins).toEqual([]);});it('omits USD fields when no SOL price is available', () => {@@ -182,6 +198,13 @@ describe('computeTraderMetrics — self-dealing exclusion (anti-gaming)', () =>expect(m.self_dealing_excluded_pnl_usd).toBeCloseTo(3000, 2); // 15 × 200});+ it('excludes self-dealt coins from the top-coin breakdown', () => {+ const m = computeTraderMetrics(BOOK, { solUsd: 200, selfDealMints });+ // SELF1 (+10) would top the board if credited — the honest top coin is AAAA (+2).+ expect(m.top_coin.mint).toBe('AAAA');+ expect(m.top_coins.map((c) => c.mint)).toEqual(['AAAA', 'BBBB']);+ });+it('accepts a plain object as well as a Set for selfDealMints', () => {const m = computeTraderMetrics(BOOK, { selfDealMints: { SELF1: true, SELF2: true } });expect(m.closed_count).toBe(2);