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.

feat(discover): render the live bonding curve on a launched coin's detail card

nirholas658c441be313
diff --git a/api/_lib/pump-curve-view.js b/api/_lib/pump-curve-view.js
index 938482b04..8efcf7416 100644
--- a/api/_lib/pump-curve-view.js
+++ b/api/_lib/pump-curve-view.js
@@ -31,20 +31,30 @@ export const NON_CURVE_MINTS = new Set([
export const PUMP_TOTAL_SUPPLY = 1_000_000_000;
// Cheap, RPC-free pre-filter for "could this address carry a pump.fun bonding
-// curve?". Two shapes qualify, both decided from the address alone:
+// curve?". It exists to keep a misconfigured (e.g. USDC) mount, or a probe
+// sweep, from turning into an RPC read per request — not to be the last word on
+// what has a curve. Three shapes qualify, all decided from the address alone:
//
// 1. pump.fun's own launcher grinds every mint to end in the literal suffix
// "pump".
-// 2. three.ws grinds its own launches to carry the "3ws" mark as a PREFIX
-// (src/solana/vanity/brand.js) and never the "pump" suffix. Every agent
-// token this platform mints therefore lands here, and the suffix test
+// 2. three.ws grinds its custodial launches to carry the "3ws" mark as a
+// PREFIX (src/solana/vanity/brand.js) and never the "pump" suffix. Every
+// agent token minted that way therefore lands here, and the suffix test
// alone used to reject all of them with a 300s-cached `not_a_pump_mint`
// 404 — the curve read for our own coins could never succeed.
+// 3. Anything on devnet. Nothing grinds a mark on the rehearsal cluster (a
+// launch from the owner's own wallet mints a plain generated address), so
+// an address-shape test there rejects real curves and answers nothing.
+// Devnet traffic is owner rehearsals, not the probe volume the fast-path
+// is defending against.
//
-// A known settlement/native token is excluded outright: it has no curve and
-// never will.
-export function isPumpMint(mint) {
+// A known settlement/native token is excluded outright on every cluster: it has
+// no curve and never will. A mainnet mint of an unrecognized shape is NOT
+// settled here — getCurveView asks the platform's own launch registry before it
+// answers, because a coin launched from a user's wallet has no mark to read.
+export function isPumpMint(mint, network = 'mainnet') {
if (typeof mint !== 'string' || NON_CURVE_MINTS.has(mint)) return false;
+ if (network === 'devnet') return isPlausibleMint(mint);
return mint.endsWith('pump') || hasThreeWsMark(mint);
}
@@ -52,6 +62,54 @@ export function isPlausibleMint(s) {
return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(s);
}
+// Mints the platform's own launch registry has confirmed, and mints it has
+// denied, so an unmarked coin costs at most one DB read per TTL rather than one
+// per request. Small and short-lived on purpose: the answer only changes when a
+// launch lands, and a fresh launch's first curve read may wait out one TTL at
+// worst.
+const _registryAnswers = createCache({ max: 512 });
+const REGISTRY_TTL_MS = 5 * 60_000;
+
+/**
+ * Is this mint a coin three.ws itself launched? Reads pump_agent_mints, the
+ * platform's own launch directory — the same table /launches and the agent
+ * profile's launch history render from.
+ *
+ * A launch from the owner's own wallet (/api/agents/tokens/launch-confirm)
+ * mints a plain generated address with no brand mark, so the shape fast-path
+ * cannot recognize it and this registry is the only authority that can. Any
+ * failure (no database configured, a transient error) answers `false`, which
+ * degrades to exactly the pre-existing behaviour instead of a 500.
+ *
+ * @param {string} mint
+ * @param {'mainnet'|'devnet'} network
+ * @returns {Promise<boolean>}
+ */
+async function isRegisteredPlatformLaunch(mint, network) {
+ const key = `${network}:${mint}`;
+ const hit = _registryAnswers.get(key);
+ if (hit && Date.now() - hit.at < REGISTRY_TTL_MS) return hit.known;
+
+ let known = false;
+ try {
+ // Imported lazily: this module is loaded by pure-function tests and by
+ // routes that never reach this branch, and api/_lib/db.js throws at import
+ // time when DATABASE_URL is unset.
+ const { sql } = await import('./db.js');
+ const rows = await sql`
+ select 1 from pump_agent_mints
+ where mint = ${mint} and network = ${network}
+ limit 1
+ `;
+ known = rows.length > 0;
+ } catch (err) {
+ console.warn('[pump-curve-view] launch-registry lookup unavailable: %s', String(err?.message || err).slice(0, 120));
+ return false;
+ }
+ _registryAnswers.set(key, { known, at: Date.now() });
+ return known;
+}
+
// Last good curve view per network:mint, kept so an RPC flake degrades the read
// to slightly-old real data instead of an unhandled 500. Same serve-stale tier
// as api/pump/price-history: never fabricated, only ever a body a healthy read
@@ -116,7 +174,11 @@ export function serializeBNs(obj) {
* Caller is expected to have already validated `mint` with isPlausibleMint().
*/
export async function getCurveView({ mint, network = 'mainnet' }) {
- if (!isPumpMint(mint)) {
+ // The shape fast-path answers for pump.fun-ground and three.ws-marked mints
+ // without touching anything. An unrecognized mainnet address gets one more
+ // question — is it a coin we launched? — before it is refused, because an
+ // agent token launched from the owner's own wallet carries no mark at all.
+ if (!isPumpMint(mint, network) && !(await isRegisteredPlatformLaunch(mint, network))) {
// Negative-cacheable so the CDN edge serves repeat probes without hitting
// the function at all — no cold start, no RPC reads, no warning spam.
return {
diff --git a/public/discover/detail.css b/public/discover/detail.css
index 34247c064..186e744ab 100644
--- a/public/discover/detail.css
+++ b/public/discover/detail.css
@@ -381,6 +381,130 @@ body.detail-page {
border: 1px solid rgba(255, 255, 255, 0.08);
}
+/* ─── On-chain history ───────────────────────────────────────────────────── */
+/* One row per indexed lifecycle event, newest first, read from the platform's
+ own cross-chain index rather than an RPC scan in the browser. */
+
+.detail-history {
+ list-style: none;
+ margin: 0;
+ padding: 0;
+ display: flex;
+ flex-direction: column;
+ gap: 2px;
+ max-height: 420px;
+ overflow-y: auto;
+}
+
+.detail-history-row {
+ display: grid;
+ grid-template-columns: 132px 1fr auto;
+ gap: 12px;
+ align-items: baseline;
+ padding: 8px 10px;
+ border-radius: 8px;
+ transition: background 0.15s ease;
+}
+
+.detail-history-row:hover {
+ background: rgba(255, 255, 255, 0.04);
+}
+
+@media (max-width: 560px) {
+ .detail-history-row {
+ grid-template-columns: 1fr auto;
+ }
+
+ .detail-history-when {
+ grid-column: 1 / -1;
+ }
+}
+
+.detail-history-when {
+ font-size: 11px;
+ color: rgba(255, 255, 255, 0.35);
+ font-variant-numeric: tabular-nums;
+ white-space: nowrap;
+}
+
+.detail-history-what {
+ font-size: 13px;
+ color: rgba(255, 255, 255, 0.82);
+ display: flex;
+ flex-wrap: wrap;
+ align-items: baseline;
+ gap: 8px;
+}
+
+.detail-history-detail {
+ font-size: 11px;
+ font-family: ui-monospace, SF Mono, Menlo, monospace;
+ color: rgba(255, 255, 255, 0.38);
+ word-break: break-all;
+}
+
+.detail-history-class {
+ font-size: 10px;
+ letter-spacing: 0.04em;
+ text-transform: uppercase;
+ padding: 2px 7px;
+ border-radius: 99px;
+ background: rgba(255, 255, 255, 0.07);
+ border: 1px solid rgba(255, 255, 255, 0.08);
+ color: rgba(255, 255, 255, 0.55);
+ white-space: nowrap;
+}
+
+/* Token launches and reputation are the two classes a reader scans for, so
+ they carry their own accent instead of the neutral chip. */
+.detail-history-class[data-class='token_launch'] {
+ background: rgba(129, 230, 160, 0.12);
+ border-color: rgba(129, 230, 160, 0.28);
+ color: rgba(160, 240, 185, 0.92);
+}
+
+.detail-history-class[data-class='reputation'] {
+ background: rgba(150, 180, 255, 0.12);
+ border-color: rgba(150, 180, 255, 0.28);
+ color: rgba(180, 200, 255, 0.92);
+}
+
+.detail-history-class[data-class='transfer'] {
+ background: rgba(255, 200, 130, 0.1);
+ border-color: rgba(255, 200, 130, 0.24);
+ color: rgba(255, 214, 160, 0.9);
+}
+
+.detail-history-link {
+ font-size: 11px;
+ color: rgba(255, 255, 255, 0.4);
+ text-decoration: none;
+ white-space: nowrap;
+ border-radius: 4px;
+}
+
+.detail-history-link:hover {
+ color: #fff;
+}
+
+.detail-history-link:focus-visible,
+.detail-history-row:focus-visible {
+ outline: 2px solid rgba(150, 180, 255, 0.7);
+ outline-offset: 2px;
+}
+
+.detail-history-foot {
+ margin: 12px 0 0;
+ font-size: 11px;
+ color: rgba(255, 255, 255, 0.3);
+}
+
+.detail-history-empty {
+ font-size: 13px;
+ color: rgba(255, 255, 255, 0.45);
+ margin: 0;
+}
+
/* ─── Definition list ────────────────────────────────────────────────────── */
.detail-dl {
diff --git a/public/discover/detail.js b/public/discover/detail.js
index 374accd61..8bf9bbf8e 100644
--- a/public/discover/detail.js
+++ b/public/discover/detail.js
@@ -217,6 +217,7 @@ function render(item) {
dl.innerHTML = rows.map(([k, v]) => `<dt>${escapeHtml(k)}</dt><dd>${v}</dd>`).join('');
fetchSolanaReputation(item.asset, panel, dl);
+ fetchOnchainHistory({ asset: item.asset }, $);
}
if (item.kind === 'onchain') {
@@ -234,6 +235,7 @@ function render(item) {
rows.push(['Reg. tx', `<a href="${escapeAttr(txUrl)}" target="_blank" rel="noopener">${escapeHtml(shortAddr(item.registeredTx))}</a>`]);
}
dl.innerHTML = rows.map(([k, v]) => `<dt>${escapeHtml(k)}</dt><dd>${v}</dd>`).join('');
+ fetchOnchainHistory({ chain: item.chainId, id: item.agentId }, $);
}
// Avatar details panel
@@ -422,6 +424,120 @@ async function fetchSolanaReputation(asset, panel, dl) {
} catch (_) {}
}
+// ─── On-chain history ────────────────────────────────────────────────────────
+// Reads the platform's own cross-chain index (agent_onchain_events) rather than
+// scanning an RPC in the browser, so an agent's registrations, token launches,
+// reputation attestations, transfers and delegations render on one timeline for
+// both Solana and EVM. Every row links to the transaction on a block explorer,
+// so nothing here has to be taken on trust.
+
+const HISTORY_CLASS_LABEL = {
+ registration: 'Registered',
+ metadata: 'Metadata',
+ transfer: 'Transfer',
+ token_launch: 'Token launch',
+ reputation: 'Reputation',
+ validation: 'Validation',
+ delegation: 'Delegation',
+};
+
+function fmtDateTime(iso) {
+ if (!iso) return '';
+ return new Date(iso).toLocaleString('en-US', {
+ year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit',
+ });
+}
+
+/**
+ * One line of human detail per event class, drawn from the indexed payload.
+ * Returns '' when the payload adds nothing the class name did not already say.
+ */
+function historyDetail(ev) {
+ const p = ev.payload || {};
+ if (ev.eventClass === 'token_launch' && p.mint) return p.mint;
+ if (ev.eventClass === 'transfer' && ev.counterparty) return `→ ${shortAddr(ev.counterparty)}`;
+ if (ev.eventClass === 'metadata' && p.key) return p.value ? `${p.key} = ${p.value}` : p.key;
+ if (ev.eventClass === 'reputation') {
+ if (p.value != null && p.valueDecimals != null) {
+ const scaled = Number(p.value) / 10 ** Number(p.valueDecimals);
+ return Number.isFinite(scaled) ? `${scaled} ${p.tag1 || ''}`.trim() : '';
+ }
+ if (p.score != null) return `${p.score} ★`;
+ }
+ if (ev.eventClass === 'metadata' && p.agentUri) return p.agentUri;
+ return '';
+}
+
+async function fetchOnchainHistory(query, $) {
+ const panel = $('history-panel');
+ if (!panel) return;
+ const list = $('history');
+ const foot = $('history-foot');
+
+ const params = new URLSearchParams(
+ Object.fromEntries(Object.entries(query).filter(([, v]) => v != null && v !== '')),
+ );
+ params.set('limit', '50');
+
+ let data;
+ try {
+ const res = await fetch(`/api/agents/onchain-history?${params}`);
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
+ data = await res.json();
+ } catch (_) {
+ // The index being unreachable is not the agent having no history, and
+ // saying so is the whole point of showing this panel at all.
+ panel.hidden = false;
+ list.innerHTML = '<li class="detail-history-empty">On-chain history is unavailable right now. Reload to try again.</li>';
+ return;
+ }
+
+ panel.hidden = false;
+ const events = Array.isArray(data.events) ? data.events : [];
+ $('history-count').textContent = String(events.length);
+
+ if (!events.length) {
+ list.innerHTML = data.indexLag?.crawled
+ ? '<li class="detail-history-empty">No on-chain events recorded for this agent yet. The indexer has looked and found nothing beyond its registration.</li>'
+ : '<li class="detail-history-empty">This agent has not been crawled yet. Its history will appear here after the next indexer pass.</li>';
+ } else {
+ list.innerHTML = events
+ .map((ev) => {
+ const label = HISTORY_CLASS_LABEL[ev.eventClass] || ev.eventClass;
+ const detail = historyDetail(ev);
+ const link = ev.explorerUrl
+ ? `<a class="detail-history-link" href="${escapeAttr(ev.explorerUrl)}" target="_blank" rel="noopener" title="${escapeAttr(ev.tx)}">${escapeHtml(shortAddr(ev.tx))} ↗</a>`
+ : '';
+ return `<li class="detail-history-row">
+ <time class="detail-history-when" datetime="${escapeAttr(ev.occurredAt)}">${escapeHtml(fmtDateTime(ev.occurredAt))}</time>
+ <span class="detail-history-what">
+ <span class="detail-history-class" data-class="${escapeAttr(ev.eventClass)}">${escapeHtml(label)}</span>
+ <span>${escapeHtml(ev.eventName)}</span>
+ ${detail ? `<span class="detail-history-detail">${escapeHtml(detail)}</span>` : ''}
+ </span>
+ ${link}
+ </li>`;
+ })
+ .join('');
+ }
+
+ // Freshness is part of the answer: "no events" from an index last updated
+ // four hours ago means something different from the same answer live.
+ const lag = data.indexLag || {};
+ if (!lag.crawled) {
+ foot.textContent = 'Not yet crawled by the agent indexer.';
+ } else if (lag.error) {
+ foot.textContent = `Indexer last reported: ${lag.error}`;
+ } else if (lag.lagMinutes != null) {
+ foot.textContent =
+ lag.lagMinutes < 1
+ ? 'Index up to date as of less than a minute ago.'
+ : `Index last updated ${lag.lagMinutes} minute${lag.lagMinutes === 1 ? '' : 's'} ago.`;
+ } else {
+ foot.textContent = '';
+ }
+}
+
function showError(status, onRetry) {
const $ = (role) => document.querySelector(`[data-role="${role}"]`);
$('loading').hidden = true;
diff --git a/src/widgets/bonding-curve.js b/src/widgets/bonding-curve.js
index fe2607e2d..eb0736007 100644
--- a/src/widgets/bonding-curve.js
+++ b/src/widgets/bonding-curve.js
@@ -45,16 +45,25 @@ const NON_CURVE_MINTS = new Set([
// Address-only pre-filter, mirroring the server's gate in
// api/_lib/pump-curve-view.js. A pump.fun-ground mint ends in the literal
-// suffix "pump"; a three.ws-launched mint carries the "3ws" mark as a prefix
-// instead (src/solana/vanity/brand.js) and is just as curve-bearing. Anything
-// else — a settlement token, a misconfigured (e.g. USDC) mount — has no curve,
-// so the widget skips the request entirely and shows its empty state rather
-// than contributing to a /api/pump/curve 404 storm.
-export function isPumpMint(mint) {
+// suffix "pump"; a three.ws custodial launch carries the "3ws" mark as a prefix
+// instead (src/solana/vanity/brand.js) and is just as curve-bearing; and on
+// devnet nothing grinds a mark at all, so the shape says nothing and every
+// plausible address is worth asking about. A settlement token is excluded
+// everywhere. Anything else on mainnet is skipped here rather than contributing
+// to a /api/pump/curve 404 storm from a misconfigured (e.g. USDC) mount — the
+// server still recognizes an unmarked coin of ours from its own launch
+// registry, so a real agent token is never left unrendered by this shortcut.
+export function isPumpMint(mint, network = 'mainnet') {
if (typeof mint !== 'string' || NON_CURVE_MINTS.has(mint)) return false;
+ if (network === 'devnet') return isPlausibleMint(mint);
return mint.endsWith('pump') || hasThreeWsMark(mint);
}
+/** A base58 string of Solana address length — the shape, not the existence. */
+export function isPlausibleMint(s) {
+ return /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(String(s || ''));
+}
+
// SVG geometry. viewBox is fixed; the element scales to its container.
const VB = Object.freeze({ w: 320, h: 150, pl: 14, pr: 14, pt: 18, pb: 18 });
const CURVE_EXP = 1.85; // convex/accelerating — mirrors the pump.fun price curve
@@ -70,6 +79,17 @@ export function lamportsToSol(lamports) {
return n / LAMPORTS_PER_SOL;
}
+/**
+ * Whole tokens behind a curve. `tokenTotalSupply` is atomic and pump.fun mints
+ * with 6 decimals; a payload without it falls back to the fixed 1B supply every
+ * pump.fun coin is created with.
+ */
+export function totalSupplyTokens(curve) {
+ const atomic = Number(curve?.tokenTotalSupply);
+ if (!Number.isFinite(atomic) || atomic <= 0) return PUMP_TOTAL_SUPPLY;
+ return atomic / 1e6;
+}
+
export function clamp01(n) {
if (!Number.isFinite(n)) return 0;
if (n < 0) return 0;
@@ -217,13 +237,19 @@ export function computeView(data, solUsd = null) {
}
const progress = isGraduated ? 1 : clamp01(Number(grad.progressBps) / 10_000);
- // The SDK can report a small negative market cap for a freshly-created
- // curve (real reserves still at zero) — clamp so we never show "-$2".
- const marketCapSol = Math.max(0, lamportsToSol(price.marketCap));
const raisedSol = Math.max(0, lamportsToSol(grad.solAccumulated ?? data.curve.realSolReserves));
const priceSol = Math.max(0, lamportsToSol(price.buyPricePerToken));
const hasUsd = Number.isFinite(Number(solUsd)) && Number(solUsd) > 0;
+ // Market cap is derived here rather than taken from the SDK's `price.marketCap`,
+ // which is not one: on a live devnet curve 95% of the way to graduation it
+ // reports -1.75 SOL while the curve holds 30.3 SOL of virtual reserves. Every
+ // consumer clamped that negative to zero and rendered "◎0" for a coin with a
+ // real price. The curve carries the two honest numbers instead — the current
+ // per-token price and the token's total supply — and pump.fun sells the entire
+ // fixed supply through the curve, so price × supply IS the market cap.
+ const marketCapSol = priceSol * totalSupplyTokens(data.curve);
+
return {
status: isGraduated ? 'graduated' : 'bonding',
progress,
@@ -493,11 +519,13 @@ export function mountBondingCurve(rootEl, opts = {}) {
injectStyles(doc);
const mint = String(opts.mint || '').trim();
- // A mint that can't have a bonding curve (settlement token / non-"pump" mint)
- // is treated like no mint at all: paint the empty state, never poll. This stops
- // a misconfigured mount from firing /api/pump/curve requests that can only 404.
- const pollable = Boolean(mint) && isPumpMint(mint);
const network = opts.network === 'devnet' ? 'devnet' : 'mainnet';
+ // A mint that can't have a bonding curve (a settlement token, or a mainnet
+ // address carrying neither launcher's mark) is treated like no mint at all:
+ // paint the empty state, never poll. This stops a misconfigured mount from
+ // firing /api/pump/curve requests that can only 404. The test is
+ // network-aware because devnet mints carry no mark to test.
+ const pollable = Boolean(mint) && isPumpMint(mint, network);
const refreshMs = Math.max(5_000, Number(opts.refreshMs) || 15_000);
const showUsd = opts.showUsd !== false;
const accent = /^#[0-9a-fA-F]{3,8}$/.test(opts.accent || '') ? opts.accent : '#888888';
diff --git a/tests/pump-curve-mint-gate.test.js b/tests/pump-curve-mint-gate.test.js
index 5e4101d66..1d7757976 100644
--- a/tests/pump-curve-mint-gate.test.js
+++ b/tests/pump-curve-mint-gate.test.js
@@ -49,10 +49,29 @@ describe.each(GATES)('isPumpMint (%s)', (_label, isPumpMint) => {
expect(isPumpMint(WRAPPED_SOL)).toBe(false);
});
- it('rejects an unrelated address so a stray mount cannot start a 404 storm', () => {
+ it('rejects an unmarked mainnet address so a stray mount cannot start a 404 storm', () => {
expect(isPumpMint('9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM')).toBe(false);
});
+ // Nothing grinds a mark on devnet: a rehearsal launch from the owner's own
+ // wallet mints a plain generated address, and every real devnet bonding curve
+ // on the cluster today belongs to a mint of exactly that shape. A shape test
+ // there would refuse real curves and answer nothing useful.
+ it('accepts any plausible devnet address, where no mark is ground', () => {
+ expect(isPumpMint('9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM', 'devnet')).toBe(true);
+ expect(isPumpMint(THREE_WS_LAUNCH, 'devnet')).toBe(true);
+ });
+
+ it('still excludes settlement tokens on devnet', () => {
+ expect(isPumpMint(USDC_DEVNET, 'devnet')).toBe(false);
+ expect(isPumpMint(WRAPPED_SOL, 'devnet')).toBe(false);
+ });
+
+ it('rejects a malformed devnet address rather than asking the cluster', () => {
+ expect(isPumpMint('not-an-address', 'devnet')).toBe(false);
+ expect(isPumpMint('', 'devnet')).toBe(false);
+ });
+
it('rejects non-string input', () => {
expect(isPumpMint('')).toBe(false);
expect(isPumpMint(null)).toBe(false);