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
Sniper Experiments: publish every wallet + link every arm's reasoning ledger
nirholasdce121bb0e17
diff --git a/api/sniper/experiments.js b/api/sniper/experiments.jsindex a7f13365e..5072fc7a4 100644--- a/api/sniper/experiments.js+++ b/api/sniper/experiments.js@@ -17,9 +17,44 @@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 { cacheGet, cacheSet } from '../_lib/cache.js';+import { solanaConnection } from '../_lib/solana/connection.js';+import { getSolBalance } from '../_lib/avatar-wallet.js';const NETWORKS = new Set(['mainnet', 'devnet']);const WINDOWS = { '24h': '24 hours', '7d': '7 days', '30d': '30 days', all: null };+const BALANCE_CACHE_TTL_S = 20; // shorter than the page's 30s poll so a refresh sees fresh funding++function solscanAddress(address, network) {+ if (!address) return null;+ return network === 'devnet' ? `https://solscan.io/account/${address}?cluster=devnet` : `https://solscan.io/account/${address}`;+}++// Live SOL balance per wallet, cached briefly so a public, polled endpoint+// doesn't turn into an RPC-balance hammer. A read failure degrades to null+// (never breaks the scoreboard) rather than throwing.+async function walletBalances(addresses, network) {+ const out = new Map();+ const misses = [];+ for (const addr of addresses) {+ const cached = await cacheGet(`sniper:wallet-sol:${network}:${addr}`).catch(() => null);+ if (cached != null) out.set(addr, Number(cached));+ else misses.push(addr);+ }+ if (misses.length) {+ const conn = solanaConnection({ network });+ await Promise.all(misses.map(async (addr) => {+ try {+ const { sol } = await getSolBalance(conn, addr);+ out.set(addr, sol);+ await cacheSet(`sniper:wallet-sol:${network}:${addr}`, sol, BALANCE_CACHE_TTL_S).catch(() => {});+ } catch {+ out.set(addr, null);+ }+ }));+ }+ return out;+}function lamportsToSol(v) {return v == null ? null : Number((Number(BigInt(v)) / 1e9).toFixed(6));@@ -65,7 +100,7 @@ export default wrap(async (req, res) => {s.min_market_cap_usd, s.max_market_cap_usd, s.require_socials,s.min_oracle_score, s.min_quality_score, s.max_bundle_score, s.require_smart_money,s.stop_loss_pct, s.trailing_stop_pct, s.take_profit_pct, s.max_hold_seconds,- a.id as agent_id, a.name as agent_name,+ a.id as agent_id, a.name as agent_name, a.meta->>'solana_address' as wallet_address,count(p.id) filter (where p.status = 'closed' and p.buy_sig <> 'SIMULATED') as closed,count(p.id) filter (where p.status = 'closed' and p.buy_sig <> 'SIMULATED' and p.realized_pnl_lamports > 0) as wins,count(p.id) filter (where p.status = 'open' and p.buy_sig <> 'SIMULATED') as open,@@ -89,7 +124,7 @@ export default wrap(async (req, res) => {and (${interval}::text is null or p.opened_at > now() - (${interval}::text)::interval)where s.network = ${network}and (s.enabled = true or s.label is not null)- group by s.id, a.id, a.name+ group by s.id, a.id, a.name, a.metaorder by realized_pnl_lamports desc, closed desc`;@@ -102,6 +137,9 @@ export default wrap(async (req, res) => {experiment_group: r.experiment_group || null,agent_id: r.agent_id,agent_name: r.agent_name,+ wallet_address: r.wallet_address || null,+ wallet_explorer_url: solscanAddress(r.wallet_address, network),+ ledger_url: `/reasoning-ledger?agent=${encodeURIComponent(r.agent_id)}&kind=snipe`,decision_mode: r.decision_mode || 'rules',llm_model: r.llm_model || null,trigger: r.trigger || 'new_mint',@@ -138,6 +176,20 @@ export default wrap(async (req, res) => {};});+ // Live wallet transparency: every arm's actual SOL balance, right now, next to+ // its Solscan link — so "is this arm funded" never requires a DB query the+ // public can't run themselves. Best-effort: an RPC hiccup leaves balance_sol+ // null on the affected rows rather than failing the whole scoreboard.+ const wallets = [...new Set(experiments.map((x) => x.wallet_address).filter(Boolean))];+ if (wallets.length) {+ const balances = await walletBalances(wallets, network).catch(() => new Map());+ for (const x of experiments) {+ x.balance_sol = x.wallet_address ? (balances.get(x.wallet_address) ?? null) : null;+ }+ } else {+ for (const x of experiments) x.balance_sol = null;+ }+// Judgment ledger: every LLM verdict (buys AND skips) scored against what the// coin actually did. This measures a model's CALLS, independent of trade size// or simulate mode; `scored` counts verdicts whose coin has an outcome label@@ -185,11 +237,37 @@ export default wrap(async (req, res) => {};});+ // The funding source: one master wallet auto-tops-up every dry arm above.+ // Publishing its address + live balance is the other half of "track the+ // wallets" — you can watch funding flow into the fleet, not just the fleet+ // itself. Reads a PUBLIC-ADDRESS-ONLY env var (SNIPER_MASTER_WALLET_ADDRESS),+ // never a secret key: this route runs on three-ws-api, a different Cloud Run+ // service from agent-sniper, and the two do NOT share which physical wallet+ // LAUNCHER_MASTER_SECRET_KEY_B64 resolves to (three-ws-api's copy funds the+ // autonomous coin launcher; agent-sniper's is the sniper-only wallet below) —+ // deriving a pubkey from either service's secret here would silently show the+ // wrong wallet. Best-effort: unconfigured or unreadable never breaks the board.+ let masterWallet = null;+ try {+ const address = (process.env.SNIPER_MASTER_WALLET_ADDRESS || '').trim();+ if (address) {+ const balance = await walletBalances([address], network);+ masterWallet = {+ address,+ balance_sol: balance.get(address) ?? null,+ explorer_url: solscanAddress(address, network),+ };+ }+ } catch {+ masterWallet = null;+ }+return json(res, 200, {network,window,experiments,judgment: judgmentOut,+ master_wallet: masterWallet,t: Date.now(),}, { 'cache-control': 'public, max-age=15, s-maxage=30' });});diff --git a/data/changelog.json b/data/changelog.jsonindex b19b22650..b6c8760d7 100644--- a/data/changelog.json+++ b/data/changelog.json@@ -15175,6 +15175,16 @@"tags": ["infra"]+ },+ {+ "date": "2026-07-21",+ "title": "Sniper Experiments: every wallet and every decision, in the open",+ "summary": "The /sniper/experiments scoreboard now shows each strategy's live wallet: its address, a Solscan link, and its real-time SOL balance, plus the shared master wallet that auto-funds the fleet. Every arm also links straight to its Reasoning Ledger, a tamper-evident, on-chain-anchored record of every single buy decision: the exact market data and rationale the agent acted on at entry, and once the trade closes, the real outcome (win or loss, by how much). Nothing is hidden or summarized away; wins and losses are published with the same detail.",+ "tags": [+ "feature",+ "improvement"+ ],+ "link": "/sniper/experiments"}]}diff --git a/docs/agent-sniper.md b/docs/agent-sniper.mdindex 6392615c7..abd41903e 100644--- a/docs/agent-sniper.md+++ b/docs/agent-sniper.md@@ -69,6 +69,17 @@ Every layer of the trade above is independently checkable. You do not need our w- The reasoning entry lives in `agent_decisions`, hash-chained to the agent's prior history.- The spend and key-recovery events live in `agent_custody_events`, and the wallet appears in the epoch custody attestations (`custody_attestation_leaves`).+## Track every wallet, every decision++The case study above audits one trade. [/sniper/experiments](/sniper/experiments) is the live version of that audit for the whole fleet, updated every 30 seconds:++- **Every arm's wallet, in the open.** Each row shows its Solana address (truncated, linked to Solscan) and its real-time SOL balance — no login, no DB query, just what the chain says right now. A "Fleet SOL on hand" tile totals it across every armed wallet.+- **The funding source too.** The fleet's dry wallets are kept above their floor by one master wallet (`SNIPER_AUTO_FUND`, `workers/agent-sniper/auto-funder.js`). Its address and live balance are published in the same view, so funding flow into the fleet is as auditable as the fleet itself.+- **A "ledger →" link on every arm** goes straight to that agent's full Reasoning Ledger (`/reasoning-ledger?agent=<id>&kind=snipe`, backed by `GET /api/ledger/:agentId`): the complete, tamper-evident, hash-chained history of every buy decision that agent has made — the trigger, price impact, firewall verdict, and (for LLM-judged arms) the model's thesis and confidence at the moment it decided, plus the reconciled real outcome once the position closes (win or loss, exact SOL, the sell signature). Nothing is aggregated away; a loss is exactly as visible as a win.+- **The judgment ledger** (rendered lower on the same page) scores every LLM verdict — buys AND skips — against what the coin actually did, independent of position size, so a model's calibration is measurable even before its trades close.++This is deliberately the same infrastructure the case study above uses, generalized: `agent_decisions` + `decision_outcomes` (the reasoning ledger), `sniper_llm_verdicts` (the judgment ledger), and `api/cron/reconcile-decisions` (closes the loop from an open prediction to a proven outcome, then anchors the chain head on-chain via SPL-Memo so the history is independently verifiable at `GET /api/ledger/verify/:agentId`).+## Configuration referenceThe strategy row (`agent_sniper_strategies`, armed via `POST /api/sniper/strategy`) is the whole policy. The load-bearing fields:diff --git a/src/sniper-experiments.js b/src/sniper-experiments.jsindex c17950261..d0d7c441e 100644--- a/src/sniper-experiments.js+++ b/src/sniper-experiments.js@@ -63,6 +63,22 @@ function pnlClass(v) {return Number(v) > 0 ? 'xp-pos' : 'xp-neg';}+function shortAddr(a) {+ if (!a) return null;+ return `${a.slice(0, 4)}…${a.slice(-4)}`;+}++function walletLine(x) {+ if (!x.wallet_address) return '<div class="xp-wallet xp-wallet-none">no wallet</div>';+ const bal = x.balance_sol != null ? `${Number(x.balance_sol).toFixed(3)} SOL` : '· SOL';+ const low = x.balance_sol != null && x.balance_sol < 0.02;+ return `+ <div class="xp-wallet">+ <a href="${esc(x.wallet_explorer_url)}" target="_blank" rel="noopener noreferrer" title="View wallet on Solscan">${esc(shortAddr(x.wallet_address))} ↗</a>+ <span class="${low ? 'xp-neg' : ''}">${esc(bal)}</span>+ </div>`;+}+function modeBadge(x) {if (x.decision_mode === 'llm') {return `<span class="xp-badge xp-badge-llm" title="No rule shields: an LLM judges each launch">LLM · ${esc((x.llm_model || 'auto').split('/').pop())}</span>`;@@ -89,18 +105,28 @@ function renderControls() {});}-function renderSummary(experiments) {+function renderSummary(experiments, masterWallet) {const active = experiments.filter((x) => x.enabled);const traded = experiments.filter((x) => x.closed > 0);const totalPnl = experiments.reduce((a, x) => a + (Number(x.realized_pnl_sol) || 0), 0);const totalTrades = experiments.reduce((a, x) => a + x.closed, 0);+ const fleetSol = experiments.reduce((a, x) => a + (Number(x.balance_sol) || 0), 0);const best = traded.slice().sort((a, b) => (b.realized_pnl_sol || 0) - (a.realized_pnl_sol || 0))[0];+ const masterTile = masterWallet+ ? `<div class="cv-card xp-tile">+ <span>Master funding wallet</span>+ <b><a href="${esc(masterWallet.explorer_url)}" target="_blank" rel="noopener noreferrer">${esc(shortAddr(masterWallet.address))} ↗</a></b>+ <i>${masterWallet.balance_sol != null ? `${masterWallet.balance_sol.toFixed(3)} SOL, auto-tops-up dry arms` : 'balance unavailable'}</i>+ </div>`+ : '';$('xp-summary').innerHTML = `<div class="xp-tiles"><div class="cv-card xp-tile"><span>Armed strategies</span><b>${active.length}</b><i>${experiments.length - active.length} paused</i></div><div class="cv-card xp-tile"><span>Closed trades</span><b>${totalTrades}</b><i>${experiments.reduce((a, x) => a + x.open, 0)} open now</i></div><div class="cv-card xp-tile"><span>Fleet realized P&L</span><b class="${pnlClass(totalPnl)}">${esc(sol(totalPnl))}</b><i>window: ${esc(windowKey)}</i></div>+ <div class="cv-card xp-tile"><span>Fleet SOL on hand</span><b>${fleetSol.toFixed(3)} SOL</b><i>across ${experiments.filter((x) => x.wallet_address).length} wallets</i></div><div class="cv-card xp-tile"><span>Best arm</span><b>${best ? esc(best.label) : 'no trades yet'}</b><i>${best ? esc(sol(best.realized_pnl_sol)) : 'waiting on fills'}</i></div>+ ${masterTile}</div>`;}@@ -123,7 +149,8 @@ function renderBoard(experiments) {<tr class="${x.enabled ? '' : 'xp-off'}"><td><div class="xp-label">${esc(x.label)}${x.enabled ? '' : ' <span class="xp-paused">paused</span>'}</div>- <div class="xp-agent"><a href="/a/${esc(x.agent_id)}">${esc(x.agent_name || 'agent')}</a> ${modeBadge(x)}</div>+ <div class="xp-agent"><a href="/a/${esc(x.agent_id)}">${esc(x.agent_name || 'agent')}</a> ${modeBadge(x)} · <a href="${esc(x.ledger_url)}" title="Full decision-by-decision reasoning ledger, tamper-evident and on-chain anchored">ledger →</a></div>+ ${walletLine(x)}</td><td class="xp-cond">${esc(x.conditions)}<div class="xp-cond-sub">${esc(String(x.per_trade_sol ?? '·'))} SOL/trade · SL ${esc(pct(-Math.abs(x.stop_loss_pct ?? 0), false))}${x.trailing_stop_pct != null ? ` · trail ${esc(pct(x.trailing_stop_pct, false))}` : ''}${x.max_hold_seconds != null ? ` · max ${esc(holdFmt(x.max_hold_seconds))}` : ''}</div></td><td>${esc(record)}${x.open > 0 ? ` <span class="xp-open">+${x.open} open</span>` : ''}${paper}</td>@@ -192,7 +219,7 @@ function renderJudgment(judgment) {async function refresh() {try {const data = await getJson(`/api/sniper/experiments?network=mainnet&window=${encodeURIComponent(windowKey)}`);- renderSummary(data.experiments);+ renderSummary(data.experiments, data.master_wallet);renderBoard(data.experiments);renderJudgment(data.judgment);$('xp-updated').textContent = `Updated ${new Date(data.t).toLocaleTimeString()} · real on-chain fills only`;@@ -226,6 +253,10 @@ function injectStyles() {.xp-agent{font-size:12px;color:var(--cv-text-3,#888);margin-top:2px}.xp-agent a{color:inherit}.xp-agent a:hover{color:var(--cv-text,#eee)}+ .xp-wallet{font-size:11px;color:var(--cv-text-3,#888);margin-top:3px;display:flex;gap:6px;align-items:baseline;font-variant-numeric:tabular-nums}+ .xp-wallet a{color:inherit;text-decoration:none;border-bottom:1px dotted var(--cv-border,rgba(255,255,255,.25))}+ .xp-wallet a:hover{color:var(--cv-text,#eee)}+ .xp-wallet-none{opacity:.6}.xp-cond{max-width:300px;color:var(--cv-text-2,#bbb)}.xp-cond-sub{font-size:11.5px;color:var(--cv-text-3,#888);margin-top:3px}.xp-badge{display:inline-block;font-size:10.5px;padding:1px 7px;border-radius:99px;border:1px solid var(--cv-border,rgba(255,255,255,.12));vertical-align:1px}