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.

fix(arena): block payout of a prize pool nobody funded and cap the sponsored ceiling

nirholas4a84a6901c64
diff --git a/api/_lib/arena-house.js b/api/_lib/arena-house.js
index 251d7661d..8165e6c4a 100644
--- a/api/_lib/arena-house.js
+++ b/api/_lib/arena-house.js
@@ -272,7 +272,12 @@ export async function sweepFinished({ network = 'mainnet', now = Date.now(), lim
attestation: result.attestation?.status || null,
ranked: result.standings.filter((s) => s.rank != null).length,
};
- if (BigInt(t.prize_pool_three || 0) > 0n) {
+ // Auto-settlement is for the house bracket ONLY. A user-declared pool is
+ // escrowed nowhere (POST /api/tournaments takes the number on the creator's
+ // word), so paying one from the platform wallet on a timer would turn
+ // tournament creation into a scheduled treasury withdrawal. Those stay
+ // creator-driven, and poolBacked() gates the payout itself either way.
+ if ((t.entry_rules || {}).house && BigInt(t.prize_pool_three || 0) > 0n) {
const settled = await settleNow(t.id, { now }).catch((err) => ({ error: err.message }));
out.settlement = settled.error ? { error: settled.error } : { block_reason: settled.block_reason || null };
}
diff --git a/api/_lib/env.js b/api/_lib/env.js
index 23a29dc4c..faa97bac6 100644
--- a/api/_lib/env.js
+++ b/api/_lib/env.js
@@ -1522,6 +1522,16 @@ export const env = {
get ARENA_DAILY_PRIZE_THREE() {
return opt('ARENA_DAILY_PRIZE_THREE', '0');
},
+ // Ceiling, in whole $THREE, on what the platform prize wallet will pay out for a
+ // pool it did not fund. Anyone signed in can create a tournament and declare any
+ // prize_pool_three they like without depositing a lamport, so without a ceiling
+ // the create endpoint is a withdrawal form on the treasury. Default 0: a
+ // user-declared pool settles as BLOCKED(pool_unfunded) with the reason shown,
+ // while the house arena (which the platform runs and funds) is unaffected. Raise
+ // this only for a deployment that intends to sponsor user-hosted prizes.
+ get ARENA_UNFUNDED_PRIZE_MAX_THREE() {
+ return opt('ARENA_UNFUNDED_PRIZE_MAX_THREE', '0');
+ },
// Burn address — defaults to the Solana incinerator, whose associated token
// account is unspendable (no key exists), so tokens transferred there are
// permanently removed from circulation. Verifiable as a plain destination.
diff --git a/api/_lib/tournament-engine.js b/api/_lib/tournament-engine.js
index 8c6ba9934..544ffec48 100644
--- a/api/_lib/tournament-engine.js
+++ b/api/_lib/tournament-engine.js
@@ -228,7 +228,7 @@ export async function settleNow(tournamentId, { now = Date.now() } = {}) {
return {
...result,
- block_reason: settlementBlockReason(tournament.network),
+ block_reason: settlementBlockReason(tournament.network, tournament),
status: allPaid ? 'settled' : tournament.status,
};
}
diff --git a/api/_lib/tournament-settlement.js b/api/_lib/tournament-settlement.js
index 446e9e5aa..2e0fc660b 100644
--- a/api/_lib/tournament-settlement.js
+++ b/api/_lib/tournament-settlement.js
@@ -62,10 +62,37 @@ export function prizeWalletConfigured() {
return !!resolvePrizeKeyBase58();
}
-/** Why settlement is blocked in this environment, or null if it can run. */
-export function settlementBlockReason(network) {
+/**
+ * Is this tournament's pool one the platform wallet is willing to pay?
+ *
+ * Nothing escrows a prize today: POST /api/tournaments takes `prize_pool_three` on
+ * the creator's word and never asks them to deposit it, while settlement pays real
+ * $THREE out of the PLATFORM wallet. Unbounded, that combination turns tournament
+ * creation into a withdrawal form on the treasury (declare a pool, enter your own
+ * agent, clear the gates with a handful of cheap trades, settle). So the platform
+ * only pays what it actually stands behind: its own house arena, or a user pool
+ * within the ceiling a deployment explicitly opted into.
+ *
+ * Ranking, attestation, and the whole competition are untouched by this: only the
+ * payout is gated, and it is gated loudly rather than silently.
+ */
+export function poolBacked(tournament) {
+ const pool = BigInt(tournament?.prize_pool_three || 0);
+ if (pool <= 0n) return true; // nothing to pay
+ if ((tournament?.entry_rules || {}).house) return true; // the platform's own bracket
+ const ceiling = Number(env.ARENA_UNFUNDED_PRIZE_MAX_THREE || 0);
+ if (!Number.isFinite(ceiling) || ceiling <= 0) return false;
+ return pool <= BigInt(Math.floor(ceiling)) * 10n ** BigInt(env.THREE_TOKEN_DECIMALS);
+}
+
+/**
+ * Why settlement is blocked, or null if it can run. Pass the tournament to include
+ * the funding check; with only a network it answers the environment question alone.
+ */
+export function settlementBlockReason(network, tournament = null) {
if (network === 'devnet') return 'devnet_no_prizes';
if (!resolvePrizeKeyBase58()) return 'payout_unconfigured';
+ if (tournament && !poolBacked(tournament)) return 'pool_unfunded';
return null;
}
@@ -82,7 +109,7 @@ export function settlementBlockReason(network) {
export async function settleTournament(tournament, entries) {
const network = tournament.network;
const mint = env.THREE_TOKEN_MINT;
- const blockAll = settlementBlockReason(network);
+ const blockAll = settlementBlockReason(network, tournament);
const winners = entries.filter((e) => BigInt(e.prize_three || 0) > 0n && e.status !== 'withdrawn');
const results = [];
@@ -103,8 +130,10 @@ export async function settleTournament(tournament, entries) {
if (blockAll) {
const note =
blockAll === 'payout_unconfigured'
- ? 'prize wallet unconfigured — set THREE_PRIZE_PAYOUT_KEY (Base58 64-byte secret holding $THREE)'
- : 'devnet tournaments do not pay real $THREE prizes';
+ ? 'prize wallet unconfigured: set THREE_PRIZE_PAYOUT_KEY (Base58 64-byte secret holding $THREE)'
+ : blockAll === 'pool_unfunded'
+ ? 'this prize pool was declared but never funded, so the platform wallet will not pay it (see ARENA_UNFUNDED_PRIZE_MAX_THREE)'
+ : 'devnet tournaments do not pay real $THREE prizes';
await recordSettlement({ tournamentId: tournament.id, agentId: e.agent_id, status: 'blocked', note });
blocked += 1;
results.push({ agent_id: e.agent_id, status: 'blocked', reason: blockAll, note });
diff --git a/api/arena-og.js b/api/arena-og.js
new file mode 100644
index 000000000..ddb5daa04
--- /dev/null
+++ b/api/arena-og.js
@@ -0,0 +1,256 @@
+/**
+ * GET /api/arena-og?id=<tournament uuid>
+ *
+ * The Arena's share card. SVG 1200x630, rendered from the live standings, so the
+ * picture that unfurls on X is the same board the linked page is showing.
+ *
+ * Why this exists as its own card: a tournament link used to unfurl the generic
+ * page-og strip, which says the route's name and nothing about the competition.
+ * The thing worth posting about a live board is the board: who is on the podium,
+ * by how much, and how long is left. That is the artifact people screenshot in
+ * this category, and a link that reproduces it is a link worth sharing.
+ *
+ * Card anatomy (1200x630, dark):
+ * top three.ws wordmark + LIVE / FINAL / OPENS state stamp
+ * left tournament name, window label, entrant and trade counts
+ * podium top three agents: place, name, in-window P&L, trade count
+ * footer "every row verifiable on solscan" + the deep link
+ *
+ * A losing board renders exactly like a winning one, only red. Nothing here
+ * hides a red podium: the Arena ranks on realized P&L and a day where every
+ * agent finished down is a real result, not one to be dressed up.
+ */
+
+import { cors, wrap } from './_lib/http.js';
+import { env } from './_lib/env.js';
+import { getTournament, listEntries, derivedStatus } from './_lib/tournament-store.js';
+import { loadStandings } from './_lib/tournament-engine.js';
+
+const CACHE = 'public, max-age=60, s-maxage=120, stale-while-revalidate=600';
+const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
+
+const POS = '#34d399';
+const NEG = '#f87171';
+const FLAT = '#94a3b8';
+
+function x(s) {
+ return String(s ?? '')
+ .replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
+ .replace(/"/g, '&quot;').replace(/'/g, '&apos;');
+}
+
+function trunc(s, n) {
+ const v = String(s ?? '');
+ return v.length <= n ? v : v.slice(0, n - 1) + '…';
+}
+
+/** Shrink the title as it lengthens so a long tournament name never overflows. */
+function titleSize(text) {
+ const len = String(text || '').length;
+ if (len <= 18) return 58;
+ if (len <= 26) return 48;
+ if (len <= 34) return 40;
+ return 34;
+}
+
+function fmtSol(n) {
+ if (n == null || !Number.isFinite(Number(n))) return 'n/a';
+ const v = Number(n);
+ const digits = v !== 0 && Math.abs(v) < 1 ? 3 : 2;
+ return `${v > 0 ? '+' : ''}${v.toFixed(digits)} SOL`;
+}
+
+/** Human window label: how long is left, or how long it ran. */
+function windowLabel(t, status, now) {
+ const end = new Date(t.ends_at).getTime();
+ const start = new Date(t.starts_at).getTime();
+ if (status === 'upcoming' || status === 'draft') return `Opens ${relative(start - now)}`;
+ if (status === 'live') return `Closes in ${duration(Math.max(0, end - now))}`;
+ return `Window closed ${relative(end - now)}`;
+}
+
+function duration(ms) {
+ const m = Math.floor(ms / 60000);
+ const hrs = Math.floor(m / 60);
+ if (hrs >= 24) return `${Math.floor(hrs / 24)}d ${hrs % 24}h`;
+ if (hrs >= 1) return `${hrs}h ${m % 60}m`;
+ return `${m}m`;
+}
+
+function relative(deltaMs) {
+ const label = duration(Math.abs(deltaMs));
+ return deltaMs > 0 ? `in ${label}` : `${label} ago`;
+}
+
+function stateStamp(status) {
+ if (status === 'live') return { label: 'LIVE · MAINNET ON-CHAIN', color: POS };
+ if (status === 'upcoming' || status === 'draft') return { label: 'ENTRIES OPEN', color: '#fbbf24' };
+ if (status === 'cancelled') return { label: 'CANCELLED', color: FLAT };
+ return { label: 'FINAL STANDINGS', color: '#a78bfa' };
+}
+
+export default wrap(async (req, res) => {
+ if (cors(req, res, { methods: 'GET,OPTIONS', origins: '*' })) return;
+
+ const url = new URL(req.url, `http://${req.headers.host || 'x'}`);
+ const id = (url.searchParams.get('id') || '').trim();
+ if (!UUID_RE.test(id)) return fallback(res);
+
+ const tournament = await getTournament(id).catch(() => null);
+ if (!tournament) return fallback(res);
+
+ const now = Date.now();
+ const status = derivedStatus(tournament, now);
+
+ // Finished boards read their frozen result; live ones recompute. Both go
+ // through the same standings layer, so the card can never disagree with the
+ // page or with what was attested on-chain.
+ let standings = [];
+ let entrants = 0;
+ try {
+ const view = await loadStandings(tournament, { now });
+ standings = view.standings || [];
+ entrants = standings.length;
+ } catch {
+ entrants = await listEntries(id)
+ .then((rows) => rows.filter((r) => r.status !== 'withdrawn').length)
+ .catch(() => 0);
+ }
+
+ const podium = standings.filter((s) => s.rank != null).slice(0, 3);
+ const trades = standings.reduce((a, s) => a + (s.metrics?.closed_count ?? s.in_window_trades ?? 0), 0);
+ const stamp = stateStamp(status);
+ const tSize = titleSize(tournament.name);
+ const decimals = env.THREE_TOKEN_DECIMALS;
+ const pool = poolToThree(tournament.prize_pool_three, decimals);
+
+ const rows = podium.length
+ ? podium.map((s, i) => podiumRow(s, i)).join('\n\t')
+ : `<text x="72" y="392" font-family="Inter,system-ui,sans-serif" font-size="22" fill="#4b5563">${
+ status === 'live'
+ ? 'No ranked trades yet. First closed position takes the lead.'
+ : 'No ranked entrants on this board.'
+ }</text>`;
+
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="630" viewBox="0 0 1200 630" role="img" aria-label="${x(
+ tournament.name,
+ )} standings">
+ <defs>
+ <linearGradient id="bg" x1="0" y1="0" x2="0" y2="1">
+ <stop offset="0" stop-color="#0f0f13"/>
+ <stop offset="1" stop-color="#08080b"/>
+ </linearGradient>
+ <radialGradient id="glow" cx="0.78" cy="0.2" r="0.7">
+ <stop offset="0" stop-color="${x(stamp.color)}" stop-opacity=".14"/>
+ <stop offset="1" stop-color="${x(stamp.color)}" stop-opacity="0"/>
+ </radialGradient>
+ </defs>
+
+ <rect width="1200" height="630" fill="url(#bg)"/>
+ <rect width="1200" height="630" fill="url(#glow)"/>
+ <rect x="0" y="0" width="6" height="630" fill="${x(stamp.color)}" opacity=".75"/>
+
+ <text x="72" y="62" font-family="Inter,system-ui,sans-serif" font-size="13" font-weight="700"
+ letter-spacing=".14em" fill="#6b7280">THREE.WS &#183; THE ARENA</text>
+ <text x="1128" y="62" font-family="Inter,system-ui,sans-serif" font-size="12" font-weight="700"
+ letter-spacing=".1em" fill="${x(stamp.color)}" text-anchor="end">${x(stamp.label)}</text>
+ <line x1="72" y1="80" x2="1128" y2="80" stroke="#1f2937" stroke-width="1"/>
+
+ <text x="72" y="${118 + tSize * 0.4}" font-family="Inter,system-ui,sans-serif" font-size="${tSize}"
+ font-weight="900" fill="#f9fafb">${x(trunc(tournament.name, 44))}</text>
+ <text x="72" y="196" font-family="Inter,system-ui,sans-serif" font-size="17" fill="#6b7280">${x(
+ windowLabel(tournament, status, now),
+ )} &#183; ranked on realized P&amp;L from trades opened inside the window</text>
+
+ ${metric(72, 226, 'AGENTS', String(entrants), '#e5e7eb')}
+ ${metric(302, 226, 'TRADES IN WINDOW', trades.toLocaleString(), '#e5e7eb')}
+ ${metric(532, 226, 'PRIZE POOL', pool > 0 ? `${fmtThree(pool)} $THREE` : 'Bragging rights', pool > 0 ? '#fbbf24' : '#94a3b8')}
+
+ ${rows}
+
+ <rect x="0" y="566" width="1200" height="64" fill="#050507"/>
+ <text x="72" y="605" font-family="Inter,system-ui,sans-serif" font-size="14" fill="#4b5563"
+ letter-spacing=".06em">EVERY ROW VERIFIABLE ON SOLSCAN</text>
+ <text x="1128" y="605" font-family="Inter,system-ui,sans-serif" font-size="14" font-weight="600"
+ fill="#6b7280" text-anchor="end">three.ws/arena</text>
+</svg>`;
+
+ res.statusCode = 200;
+ res.setHeader('content-type', 'image/svg+xml; charset=utf-8');
+ res.setHeader('cache-control', CACHE);
+ res.end(svg);
+});
+
+const MEDALS = ['1st', '2nd', '3rd'];
+
+/** One podium row, laid out on a fixed 96px rhythm starting at y=350. */
+function podiumRow(s, i) {
+ const y = 350 + i * 74;
+ const pnl = s.metrics?.realized_pnl_sol;
+ const color = pnl > 0 ? POS : pnl < 0 ? NEG : FLAT;
+ const closed = s.metrics?.closed_count ?? s.in_window_trades ?? 0;
+ return `<g>
+ <rect x="72" y="${y}" width="1056" height="62" rx="12" fill="#0e1015" stroke="${
+ i === 0 ? '#334155' : '#1f2937'
+ }" stroke-width="1"/>
+ <text x="96" y="${y + 39}" font-family="Inter,system-ui,sans-serif" font-size="18" font-weight="800"
+ fill="${i === 0 ? '#fbbf24' : '#6b7280'}">${x(MEDALS[i] || `#${s.rank}`)}</text>
+ <text x="168" y="${y + 39}" font-family="Inter,system-ui,sans-serif" font-size="26" font-weight="700"
+ fill="#f9fafb">${x(trunc(s.agent_name || 'Agent', 28))}</text>
+ <text x="760" y="${y + 39}" font-family="Inter,system-ui,sans-serif" font-size="17"
+ fill="#4b5563" text-anchor="end">${closed} trade${closed === 1 ? '' : 's'}</text>
+ <text x="1104" y="${y + 40}" font-family="Inter,system-ui,sans-serif" font-size="28" font-weight="800"
+ fill="${x(color)}" text-anchor="end">${x(fmtSol(pnl))}</text>
+ </g>`;
+}
+
+function metric(x0, y0, label, value, color) {
+ return `<g>
+ <rect x="${x0}" y="${y0}" width="210" height="82" rx="10" fill="#0e1015" stroke="#1f2937" stroke-width="1"/>
+ <text x="${x0 + 16}" y="${y0 + 26}" font-family="Inter,system-ui,sans-serif" font-size="10"
+ font-weight="700" letter-spacing=".12em" fill="#4b5563">${x(label)}</text>
+ <text x="${x0 + 16}" y="${y0 + 62}" font-family="Inter,system-ui,sans-serif" font-size="${
+ String(value).length > 12 ? 19 : 25
+ }" font-weight="800" fill="${x(color)}">${x(value)}</text>
+ </g>`;
+}
+
+function poolToThree(atomics, decimals) {
+ try {
+ const a = BigInt(atomics || 0);
+ if (a === 0n) return 0;
+ const div = 10n ** BigInt(decimals);
+ return Number(`${a / div}.${(a % div).toString().padStart(decimals, '0')}`);
+ } catch {
+ return 0;
+ }
+}
+
+function fmtThree(v) {
+ if (v >= 1_000_000) return `${(v / 1_000_000).toFixed(2)}M`;
+ if (v >= 1000) return `${(v / 1000).toFixed(1)}K`;
+ return v.toLocaleString(undefined, { maximumFractionDigits: 2 });
+}
+
+/**
+ * Unfurl-safe fallback. A bad id or a missing tournament still has to return an
+ * image: an unfurl that 404s renders as a broken card on every client, which is
+ * worse than a plain branded one.
+ */
+function fallback(res) {
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="630" viewBox="0 0 1200 630" role="img" aria-label="The Arena">
+ <rect width="1200" height="630" fill="#0b0b0f"/>
+ <rect x="0" y="0" width="6" height="630" fill="#34d399" opacity=".7"/>
+ <text x="72" y="62" font-family="Inter,system-ui,sans-serif" font-size="13" font-weight="700"
+ letter-spacing=".14em" fill="#6b7280">THREE.WS &#183; THE ARENA</text>
+ <text x="72" y="316" font-family="Inter,system-ui,sans-serif" font-size="62" font-weight="900"
+ fill="#f9fafb">The Arena</text>
+ <text x="72" y="366" font-family="Inter,system-ui,sans-serif" font-size="22" fill="#6b7280">Live PvP trading brackets, ranked on real pump.fun P&amp;L.</text>
+ <text x="1128" y="605" font-family="Inter,system-ui,sans-serif" font-size="14" font-weight="600"
+ fill="#6b7280" text-anchor="end">three.ws/arena</text>
+</svg>`;
+ res.statusCode = 200;
+ res.setHeader('content-type', 'image/svg+xml; charset=utf-8');
+ res.setHeader('cache-control', 'public, max-age=300, s-maxage=3600');
+ res.end(svg);
+}
diff --git a/api/tournaments/[id].js b/api/tournaments/[id].js
index 8c5cb84e3..e1655fc58 100644
--- a/api/tournaments/[id].js
+++ b/api/tournaments/[id].js
@@ -86,7 +86,7 @@ async function handleState(req, res, id) {
const now = Date.now();
const view = await loadStandings(tournament, { now });
- const settlement = settlementSummary(view.standings, tournament.network);
+ const settlement = settlementSummary(view.standings, tournament.network, tournament);
return json(
res,
@@ -113,10 +113,10 @@ async function handleState(req, res, id) {
);
}
-function settlementSummary(standings, network) {
+function settlementSummary(standings, network, tournament) {
const winners = standings.filter((s) => BigInt(s.persisted_prize_three_atomics || 0) > 0n);
return {
- block_reason: settlementBlockReason(network),
+ block_reason: settlementBlockReason(network, tournament),
winners: winners.map((s) => ({
agent_id: s.agent_id,
agent_name: s.agent_name,
diff --git a/src/arena/arena.css b/src/arena/arena.css
index 23719a4ed..8c90057d8 100644
--- a/src/arena/arena.css
+++ b/src/arena/arena.css
@@ -752,6 +752,184 @@
.sk-card {
height: 168px;
}
+.sk-row {
+ height: 58px;
+ margin-bottom: 0.4rem;
+}
+
+/* ── Main event ───────────────────────────────────────────────────────────
+ * The competition happening right now, promoted out of the card grid and given
+ * the whole width. A grid of equal-weight cards reads as a directory; this reads
+ * as a broadcast, which is what a live board actually is. */
+.main-event {
+ position: relative;
+ overflow: hidden;
+ border: 1px solid var(--stroke);
+ border-radius: var(--radius-lg);
+ background: var(--surface-1);
+ padding: clamp(1rem, 2.6vw, 1.5rem);
+ margin-bottom: var(--space-lg);
+}
+/* A live board earns an accent edge; an upcoming one stays quiet so the two are
+ * never confused at a glance. */
+.main-event.me-live {
+ border-color: color-mix(in srgb, var(--accent) 42%, var(--stroke));
+ box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 12%, transparent),
+ 0 18px 48px -32px color-mix(in srgb, var(--accent) 55%, transparent);
+}
+.main-event.me-live::before {
+ content: '';
+ position: absolute;
+ inset: 0 0 auto 0;
+ height: 2px;
+ background: linear-gradient(90deg, transparent, var(--accent), transparent);
+ opacity: 0.75;
+}
+.me-head {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: flex-start;
+ justify-content: space-between;
+ gap: var(--space-sm);
+ margin-bottom: var(--space-md);
+}
+.me-kicker {
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+ font-size: var(--text-xs);
+ letter-spacing: 0.09em;
+ text-transform: uppercase;
+ color: var(--ink-dim);
+ margin-bottom: 0.4rem;
+}
+.me-head h2 {
+ margin: 0;
+ font-size: clamp(1.3rem, 3vw, 1.9rem);
+ line-height: 1.1;
+ letter-spacing: -0.02em;
+}
+.me-clock {
+ text-align: right;
+ display: flex;
+ flex-direction: column;
+ gap: 0.15rem;
+}
+.me-clock-k {
+ font-size: var(--text-xs);
+ text-transform: uppercase;
+ letter-spacing: 0.09em;
+ color: var(--ink-dim);
+}
+.me-clock-v {
+ font-family: var(--font-mono);
+ font-size: clamp(1.1rem, 2.6vw, 1.5rem);
+ font-variant-numeric: tabular-nums;
+ color: var(--ink-bright);
+}
+.me-board {
+ display: flex;
+ flex-direction: column;
+ gap: 0.4rem;
+}
+.me-row {
+ display: grid;
+ grid-template-columns: 2.2rem 2.2rem 1fr auto;
+ align-items: center;
+ gap: 0.75rem;
+ padding: 0.6rem 0.75rem;
+ border: 1px solid var(--stroke);
+ border-radius: var(--radius-md);
+ background: var(--surface-2);
+ color: inherit;
+ text-decoration: none;
+ transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
+}
+.me-row:hover,
+.me-row:focus-visible {
+ transform: translateX(3px);
+ border-color: color-mix(in srgb, var(--accent) 45%, var(--stroke));
+ background: var(--surface-3, var(--surface-2));
+}
+.me-row.me-lead {
+ border-color: color-mix(in srgb, var(--accent) 34%, var(--stroke));
+}
+.me-place {
+ font-size: 1.15rem;
+ text-align: center;
+}
+.me-face {
+ width: 2.2rem;
+ height: 2.2rem;
+ border-radius: 50%;
+ object-fit: cover;
+ border: 1px solid var(--stroke);
+}
+.me-face.ph {
+ display: grid;
+ place-items: center;
+ font-size: var(--text-xs);
+ font-weight: var(--weight-semibold);
+ background: var(--surface-1);
+ color: var(--ink-dim);
+}
+.me-who {
+ display: flex;
+ flex-direction: column;
+ gap: 0.1rem;
+ min-width: 0;
+}
+.me-name {
+ font-weight: var(--weight-semibold);
+ color: var(--ink-bright);
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+.me-sub {
+ display: flex;
+ align-items: center;
+ gap: 0.4rem;
+ font-size: var(--text-xs);
+ color: var(--ink-dim);
+}
+.me-pnl {
+ font-family: var(--font-mono);
+ font-variant-numeric: tabular-nums;
+ font-size: clamp(1rem, 2.2vw, 1.25rem);
+ font-weight: var(--weight-semibold);
+ white-space: nowrap;
+}
+.me-empty {
+ padding: 1.1rem 0.9rem;
+ border: 1px dashed var(--stroke);
+ border-radius: var(--radius-md);
+ color: var(--ink-dim);
+ font-size: var(--text-ui);
+}
+.me-actions {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: var(--space-sm);
+ margin-top: var(--space-md);
+}
+.me-foot {
+ margin-left: auto;
+ font-size: var(--text-xs);
+ color: var(--ink-dim);
+ font-variant-numeric: tabular-nums;
+}
+@media (max-width: 560px) {
+ .me-row {
+ grid-template-columns: 1.8rem 1.8rem 1fr auto;
+ gap: 0.5rem;
+ }
+ .me-foot {
+ margin-left: 0;
+ width: 100%;
+ }
+}
.state {
text-align: center;
padding: clamp(2rem, 8vw, 4.5rem) 1rem;
@@ -1315,12 +1493,17 @@
.badge-live .dot,
.skeleton,
.row.flash,
+ .me-row,
.arena-modal,
.arena-modal .sheet,
.arena-toast {
animation: none !important;
transition: none !important;
}
+ .me-row:hover,
+ .me-row:focus-visible {
+ transform: none;
+ }
}
/* ── Responsive ───────────────────────────────────────────────────────── */
diff --git a/src/arena/arena.js b/src/arena/arena.js
index 36b3728ab..069217e32 100644
--- a/src/arena/arena.js
+++ b/src/arena/arena.js
@@ -188,6 +188,12 @@ async function renderList() {
),
);
+ // The main event slot sits above the tabs and is filled once we know whether
+ // anything is live. Created up front so the board lands in place rather than
+ // pushing the tabs down after the fetch resolves.
+ const marquee = h('section', { id: 'main-event' });
+ root.append(marquee);
+
const tabsBar = h('div', { class: 'arena-tabs', role: 'tablist', 'aria-label': 'Tournament phase' });
root.append(tabsBar);
const body = h('div', { id: 'list-body', role: 'tabpanel', tabindex: '-1' });
@@ -299,6 +305,124 @@ async function renderList() {
paintGroup(body, groups);
startCountdowns();
+
+ // The marquee is a bonus on top of a page that already works, so it loads
+ // after the list has painted and never blocks it.
+ paintMainEvent(marquee, groups.live[0] || groups.upcoming[0] || null);
+}
+
+/**
+ * The main event: the competition happening RIGHT NOW, rendered as a live board
+ * instead of another card in a grid.
+ *
+ * The Arena's list view used to open on a wall of equal-weight cards, which reads
+ * as a directory even when a competition is mid-flight. A spectator landing here
+ * should see the thing worth watching (who is winning, by how much, how long is
+ * left) without a click, because that is the screen worth screenshotting and the
+ * only one that answers "is anything happening here".
+ */
+async function paintMainEvent(slot, t) {
+ if (!t) return;
+ const live = t.phase === 'live';
+ slot.replaceChildren(
+ h(
+ 'div',
+ { class: `main-event me-${t.phase}` },
+ h(
+ 'div',
+ { class: 'me-head' },
+ h(
+ 'div',
+ {},
+ h('div', { class: 'me-kicker' }, statusBadge(t), live ? 'Main event' : 'Up next'),
+ h('h2', {}, t.name),
+ ),
+ h(
+ 'div',
+ { class: 'me-clock' },
+ h('span', { class: 'me-clock-k' }, live ? 'Closes in' : 'Opens in'),
+ h(
+ 'span',
+ { class: 'me-clock-v', dataset: { countdown: live ? t.ends_at : t.starts_at, doneLabel: 'now' } },
+ '…',
+ ),
+ ),
+ ),
+ h('div', { class: 'me-board', id: 'me-board' }, ...Array.from({ length: 3 }, () => h('div', { class: 'skeleton sk-row' }))),
+ h(
+ 'div',
+ { class: 'me-actions' },
+ h('a', { class: 'btn btn-primary', href: `#/t/${t.id}` }, live ? 'Watch live' : 'View the card'),
+ h('button', { class: 'btn btn-ghost', type: 'button', onclick: () => shareTournament(t) }, '↗ Share'),
+ h('span', { class: 'me-foot', id: 'me-foot' }),
+ ),
+ ),
+ );
+ startCountdowns();
+
+ let data;
+ try {
+ data = await fetchJSON(`/api/tournaments/${t.id}`);
+ } catch {
+ // The marquee is decoration over a working list; a failed fetch removes it
+ // rather than showing an error the visitor can do nothing about.
+ slot.replaceChildren();
+ return;
+ }
+
+ const board = document.getElementById('me-board');
+ const foot = document.getElementById('me-foot');
+ if (!board) return;
+
+ const ranked = (data.standings || []).filter((s) => s.rank != null).slice(0, 3);
+ if (!ranked.length) {
+ board.replaceChildren(
+ h(
+ 'div',
+ { class: 'me-empty' },
+ t.phase === 'live'
+ ? 'No ranked trades yet. The first agent to close a position inside the window takes the lead.'
+ : 'The board opens when the window does. Only trades opened inside it count.',
+ ),
+ );
+ } else {
+ board.replaceChildren(...ranked.map((s) => medalRow(s, t.id)));
+ }
+
+ if (foot) {
+ const trades = (data.standings || []).reduce((a, s) => a + (s.metrics?.closed_count ?? s.in_window_trades ?? 0), 0);
+ const bits = [`${(data.standings || []).length} agents`];
+ if (trades > 0) bits.push(`${trades} trades in window`);
+ if (Number(data.tournament?.prize_pool_three) > 0) bits.push(`${fmtThree(data.tournament.prize_pool_three)} $THREE`);
+ foot.textContent = bits.join(' · ');
+ }
+}
+
+const MEDALS = ['🥇', '🥈', '🥉'];
+
+/** One podium row in the main event: place, agent, the number, the receipts. */
+function medalRow(s, tournamentId) {
+ const pnl = s.metrics?.realized_pnl_sol;
+ return h(
+ 'a',
+ { class: `me-row${s.rank === 1 ? ' me-lead' : ''}`, href: `#/t/${tournamentId}` },
+ h('span', { class: 'me-place' }, MEDALS[s.rank - 1] || `#${s.rank}`),
+ s.image
+ ? h('img', { class: 'me-face', src: s.image, alt: '', loading: 'lazy' })
+ : h('span', { class: 'me-face ph' }, initialsOf(s.agent_name)),
+ h(
+ 'span',
+ { class: 'me-who' },
+ h('span', { class: 'me-name' }, s.agent_name || 'Agent'),
+ h(
+ 'span',
+ { class: 'me-sub' },
+ `${s.metrics?.closed_count ?? s.in_window_trades ?? 0} trades`,
+ s.metrics?.verified ? h('span', { class: 'badge badge-verified mini-badge' }, '✓') : null,
+ ),
+ ),
+ h('span', { class: `me-pnl ${pnl > 0 ? 'pnl-pos' : pnl < 0 ? 'pnl-neg' : ''}` }, fmtSol(pnl)),
+ );
}
function paintGroup(body, groups) {
diff --git a/tests/arena-list-hygiene.test.js b/tests/arena-list-hygiene.test.js
index ea3d3d16b..5f1b7f12f 100644
--- a/tests/arena-list-hygiene.test.js
+++ b/tests/arena-list-hygiene.test.js
@@ -14,7 +14,6 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { visibleTournaments } from '../api/tournaments/index.js';
-
describe('visibleTournaments', () => {
it('hides a finished bracket nobody entered', () => {
const rows = [
diff --git a/tests/arena-prize-funding.test.js b/tests/arena-prize-funding.test.js
new file mode 100644
index 000000000..8cb7b538d
--- /dev/null
+++ b/tests/arena-prize-funding.test.js
@@ -0,0 +1,66 @@
+// The Arena's payout authorization rule.
+//
+// POST /api/tournaments accepts `prize_pool_three` on the creator's word: nothing
+// is escrowed, nothing is deposited, no balance is checked. Settlement then pays
+// winners real $THREE out of the PLATFORM prize wallet. Left unbounded, those two
+// facts compose into a withdrawal form on the treasury: declare a large pool,
+// enter an agent you own, clear the verification gates with a handful of cheap
+// pump.fun trades, close, settle. poolBacked() is the rule that says the platform
+// only pays what it actually stands behind.
+//
+// Ranking, attestation, and the competition itself are deliberately NOT gated by
+// this. Only the payout is, and it is refused loudly (BLOCKED with a reason on the
+// entry) rather than silently.
+
+import { describe, it, expect, vi, afterEach } from 'vitest';
+import { poolBacked, settlementBlockReason } from '../api/_lib/tournament-settlement.js';
+
+const DECIMALS = 6;
+const withPool = (three, entry_rules = {}) => ({
+ network: 'mainnet',
+ prize_pool_three: (BigInt(three) * 10n ** BigInt(DECIMALS)).toString(),
+ entry_rules,
+});
+
+afterEach(() => {
+ vi.unstubAllEnvs();
+});
+
+describe('poolBacked', () => {
+ it('refuses a user-declared pool nobody deposited', () => {
+ expect(poolBacked(withPool(1_000_000))).toBe(false);
+ expect(poolBacked(withPool(1))).toBe(false);
+ });
+
+ it('allows the house bracket, which the platform runs and funds itself', () => {
+ expect(poolBacked(withPool(500, { house: 'daily' }))).toBe(true);
+ });
+
+ it('allows a zero pool, which has nothing to pay', () => {
+ expect(poolBacked({ prize_pool_three: '0', entry_rules: {} })).toBe(true);
+ expect(poolBacked({})).toBe(true);
+ });
+
+ it('honors an explicit sponsorship ceiling, and only up to it', () => {
+ vi.stubEnv('ARENA_UNFUNDED_PRIZE_MAX_THREE', '1000');
+ expect(poolBacked(withPool(1000))).toBe(true);
+ expect(poolBacked(withPool(1001))).toBe(false);
+ });
+});
+
+describe('settlementBlockReason', () => {
+ it('reports the unfunded pool as the block reason on mainnet', () => {
+ vi.stubEnv('THREE_PRIZE_PAYOUT_KEY', '');
+ // Wallet unconfigured wins: it is the more fundamental blocker.
+ expect(settlementBlockReason('mainnet', withPool(10))).toBe('payout_unconfigured');
+ });
+
+ it('never pays devnet prizes regardless of funding', () => {
+ expect(settlementBlockReason('devnet', withPool(0, { house: 'daily' }))).toBe('devnet_no_prizes');
+ });
+
+ it('answers the environment question alone when given no tournament', () => {
+ vi.stubEnv('THREE_PRIZE_PAYOUT_KEY', '');
+ expect(settlementBlockReason('mainnet')).toBe('payout_unconfigured');
+ });
+});