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(charts): add the DEXTools pair chart to /coin and /launches chart switchers

nirholas643f18be43e7
diff --git a/src/coin-page.js b/src/coin-page.js
index 7a2952eb5..aaea60846 100644
--- a/src/coin-page.js
+++ b/src/coin-page.js
@@ -12,7 +12,7 @@ import {
CHART_CHAINS,
CHART_EMBEDS,
chartEmbedUrls,
- resolveGeckoPool,
+ resolveChartPool,
validChartAddress,
} from './shared/chart-embeds.js';
import {
@@ -125,9 +125,10 @@ function renderHead(coin) {
// zero-dependency native line chart (with the time-range selector); the other
// sources lazy-mount a full third-party chart in an iframe only when picked:
// • TradingView advanced candlestick widget, for coins with a ticker.
-// • DexScreener, Birdeye, GMGN, GeckoTerminal: each provider's on-chain chart
-// for the token's contract, built by src/shared/chart-embeds.js so this page
-// and /launches/<mint> embed identically.
+// • DexScreener, Birdeye, GMGN, DEXTools, GeckoTerminal: each provider's
+// on-chain chart for the token's contract, built by
+// src/shared/chart-embeds.js so this page and /launches/<mint> embed
+// identically.
// Each source is offered only when it can actually render for the coin, so the
// switcher never lands on a dead chart. The picked source persists across coins.
const CHART_SOURCE_KEY = 'tws_coin_chart_source';
@@ -187,9 +188,10 @@ const chartState = {
loading: true,
error: null,
source: storedChartSource(),
- // GeckoTerminal pool resolution is async, resolved once per coin.
- gtPool: null,
- gtState: 'idle', // idle | loading | ready | unindexed | error
+ // Pool-keyed providers (DEXTools, GeckoTerminal) resolve their pool async,
+ // once per coin: provider id → { pool, state }, where state is
+ // loading | ready | unindexed | error. A missing entry means not started.
+ pools: {},
};
// The source actually rendered for this coin: the stored preference when it's
@@ -292,24 +294,29 @@ function mountEmbed(host, url, title, fallback) {
host.replaceChildren(iframeEl(url, title, fallback));
}
-// GeckoTerminal embeds are keyed by pool, not token, and 404 for a pool it has
-// not indexed, so resolve and confirm the pool once per coin, then mount. State
-// drives the loading, not-indexed and error UI.
-async function loadGtPool(coin, ref) {
- if (chartState.gtState === 'loading') return;
- chartState.gtState = 'loading';
+// DEXTools and GeckoTerminal embeds are keyed by pool, not token, and each has
+// its own idea of whether it can draw that pool (GeckoTerminal 404s on one it
+// has not indexed), so resolve through the provider once per coin, then mount.
+// State drives the loading, not-indexed and error UI.
+async function loadProviderPool(coin, ref, provider) {
+ if (chartState.pools[provider.id]?.state === 'loading') return;
+ chartState.pools[provider.id] = { pool: null, state: 'loading' };
renderChart(coin);
try {
- const { pool, indexed } = await resolveGeckoPool(ref.platform, ref.address);
- chartState.gtPool = pool;
- chartState.gtState = indexed ? 'ready' : 'unindexed';
+ const { pool, indexed } = await resolveChartPool(provider.id, ref.platform, ref.address);
+ chartState.pools[provider.id] = { pool, state: indexed ? 'ready' : 'unindexed' };
} catch {
- chartState.gtPool = null;
- chartState.gtState = 'error';
+ chartState.pools[provider.id] = { pool: null, state: 'error' };
}
renderChart(coin);
}
+// A chart that can stand in for a pool provider that cannot draw this coin:
+// the first token-keyed provider offered for it.
+function tokenKeyedFallback(coin) {
+ return availableSources(coin).find((s) => s.kind === 'embed' && s.provider.needs === 'token');
+}
+
function setChartSource(coin, id) {
if (id === chartState.source) return;
chartState.source = id;
@@ -411,6 +418,10 @@ function renderChart(coin) {
el.querySelectorAll('.cv-range-btn[data-source]').forEach((btn) => {
btn.addEventListener('click', () => setChartSource(coin, btn.dataset.source));
});
+ el.querySelector('[data-pool-retry]')?.addEventListener('click', () => {
+ delete chartState.pools[active.id];
+ renderChart(coin);
+ });
if (native) wireChartPointer();
else mountActiveEmbed(coin, active);
@@ -477,22 +488,27 @@ function embedChartBody(coin, source) {
const urls = chartEmbedUrls(provider.id, { chain: ref.platform, token: ref.address, theme: chartTheme() });
return `${wrap}<p class="cv-tv-credit"><a href="${esc(urls.page)}" target="_blank" rel="noopener nofollow noreferrer">Open in ${label} ↗</a></p>`;
}
- if (chartState.gtState === 'error') {
- return `<div class="cv-chart-state">${label} could not be reached for this coin's pool.</div>`;
+ const { pool, state } = chartState.pools[provider.id] || {};
+ if (state === 'error') {
+ return `<div class="cv-chart-state col"><p>We could not look up this coin's trading pool for ${label}.</p><button type="button" class="cv-range-btn" data-pool-retry>Try again</button></div>`;
}
- if (chartState.gtState === 'unindexed') {
- return `<div class="cv-chart-state">${label} has not indexed a pool for this coin yet. DexScreener and Birdeye chart it now.</div>`;
+ if (state === 'unindexed') {
+ const alt = tokenKeyedFallback(coin);
+ const altBtn = alt
+ ? `<button type="button" class="cv-range-btn" data-source="${alt.id}" aria-pressed="false">Show ${esc(alt.label)}</button>`
+ : '';
+ return `<div class="cv-chart-state col"><p>${label} has no pool to chart for this coin yet.</p>${altBtn}</div>`;
}
- if (chartState.gtState !== 'ready' || !chartState.gtPool) {
+ if (state !== 'ready' || !pool) {
return `<div class="cv-chart-state"><span class="cv-spinner" aria-hidden="true"></span>Loading ${label}…</div>`;
}
- const urls = chartEmbedUrls(provider.id, { chain: ref.platform, token: ref.address, pool: chartState.gtPool, theme: chartTheme() });
+ const urls = chartEmbedUrls(provider.id, { chain: ref.platform, token: ref.address, pool, theme: chartTheme() });
return `${wrap}<p class="cv-tv-credit"><a href="${esc(urls.page)}" target="_blank" rel="noopener nofollow noreferrer">Open in ${label} ↗</a></p>`;
}
-// Mount the iframe for the active non-native source into #cv-adv. GeckoTerminal
-// first resolves its pool (kicking off the async fetch on the idle→loading
-// transition); the other charts mount synchronously.
+// Mount the iframe for the active non-native source into #cv-adv. A pool-keyed
+// provider first resolves its pool (kicking off the async fetch the first time
+// it is shown); the other charts mount synchronously.
function mountActiveEmbed(coin, source) {
ensureThemeRemount(coin);
// Re-rendering the whole chart panel rebuilds the host node and remounts the
@@ -511,17 +527,18 @@ function mountActiveEmbed(coin, source) {
const ref = onchainRef(coin);
if (!ref) return;
const { provider } = source;
+ const resolved = chartState.pools[provider.id];
if (provider.needs === 'pool') {
- if (chartState.gtState === 'idle') {
- loadGtPool(coin, ref);
+ if (!resolved) {
+ loadProviderPool(coin, ref, provider);
return;
}
- if (chartState.gtState !== 'ready' || !chartState.gtPool) return;
+ if (resolved.state !== 'ready' || !resolved.pool) return;
}
const urls = chartEmbedUrls(provider.id, {
chain: ref.platform,
token: ref.address,
- pool: chartState.gtPool,
+ pool: resolved?.pool,
theme: chartTheme(),
});
if (!urls) return;
diff --git a/src/launch-detail.js b/src/launch-detail.js
index c7ed519c8..fe09dbec1 100644
--- a/src/launch-detail.js
+++ b/src/launch-detail.js
@@ -42,7 +42,7 @@ import { proxiedImageURL } from './ipfs.js';
import { agentAvatarGlb, hasCustomAvatar, seeInWorldHref } from './shared/agent-3d.js';
import { resolveDevR2Url } from './shared/dev-r2-proxy.js';
import { terminalLinks } from './shared/trading-terminals.js';
-import { CHART_EMBEDS, chartEmbedUrls, resolveGeckoPool } from './shared/chart-embeds.js';
+import { CHART_EMBEDS, chartEmbedUrls, resolveChartPool } from './shared/chart-embeds.js';
import { watchEmbed, embedFallbackNode, DEFAULT_EMBED_TIMEOUT_MS } from './shared/embed-guard.js';
import { mountPriceChart } from './mission-control/chart.js';
import { flashValue, rippleOnce, liveDot, setLiveDot } from './ui-juice.js';
@@ -61,7 +61,7 @@ const state = {
chartView: 'native', // a CHART_VIEWS id; hydrated from localStorage in boot()
chartSeq: 0, // bumps on every chart render so a stale async load never paints
chartTeardown: null, // cancels the active view's watchdog, stream or chart
- gecko: null, // { pool, indexed } once resolved for this mint
+ chartPools: {}, // provider id → { pool, indexed } once resolved for this mint
priceTimer: 0,
statsPromise: null, // shared /api/pump/token-stats read (stats + holders panels)
statsWindow: '1h', // selected timeframe tab in the stats panel
@@ -836,8 +836,9 @@ function chartIntervalBar() {
// · TradingView TradingView's charting engine (lightweight-charts) drawing
// real candles from the same OHLCV, ticked live by the trade
// stream. Shared with Mission Control and /trades.
-// · DexScreener, Birdeye, GMGN, GeckoTerminal: each provider's own chart,
-// embedded. URL shapes live in src/shared/chart-embeds.js.
+// · DexScreener, Birdeye, GMGN, DEXTools, GeckoTerminal: each provider's
+// own chart, embedded. URL shapes live in
+// src/shared/chart-embeds.js.
// Only the chosen view loads, so the default stays light.
const CHART_VIEWS = [
{ id: 'native', label: 'three.ws', kind: 'native' },
@@ -955,35 +956,39 @@ async function renderEmbedChart(target, view, seq) {
let pool = null;
if (provider.needs === 'pool') {
try {
- state.gecko ||= await resolveGeckoPool('solana', state.mint, { signal: AbortSignal.timeout(10_000) });
+ state.chartPools[provider.id] ||= await resolveChartPool(provider.id, 'solana', state.mint, {
+ signal: AbortSignal.timeout(10_000),
+ });
} catch {
if (seq !== state.chartSeq) return;
wrap.replaceChildren(
el('div', { class: 'ld-empty ld-empty-sm ld-embed-fallback' }, [
- el('p', { text: `Could not reach ${provider.label} to find this coin's pool.` }),
+ el('p', { text: `We could not look up this coin's trading pool for ${provider.label}.` }),
el('button', { class: 'ld-btn ld-btn-ghost', type: 'button', text: 'Try again', onclick: () => renderChart() }),
]),
);
return;
}
if (seq !== state.chartSeq) return;
- if (!state.gecko.indexed) {
- // GeckoTerminal lists a pump.fun coin once it has traded enough. Until
- // then its embed is a 404 page, so say so and point at charts that
- // already cover the coin.
+ const resolved = state.chartPools[provider.id];
+ if (!resolved.indexed) {
+ // A pool provider cannot draw a coin whose pool it does not know:
+ // GeckoTerminal lists a pump.fun coin only once it has traded enough
+ // (its embed is a 404 page until then), and DEXTools needs a pair to
+ // exist at all. Say so and point at charts that already cover the coin.
wrap.replaceChildren(
el('div', { class: 'ld-empty ld-empty-sm ld-embed-fallback' }, [
- el('p', { class: 'ld-empty-title', text: `${provider.label} has not indexed this coin yet.` }),
- el('p', { text: 'It lists new pump.fun coins once they build trading history. Birdeye, GMGN and DexScreener chart it from the first trade.' }),
+ el('p', { class: 'ld-empty-title', text: `${provider.label} cannot chart this coin yet.` }),
+ el('p', { text: 'It picks up new pump.fun coins once they build trading history. Birdeye, GMGN and DexScreener chart it from the first trade.' }),
el('div', { class: 'ld-dex-fallback-actions' }, [
el('button', { class: 'ld-btn ld-btn-ghost', type: 'button', text: 'Show Birdeye', onclick: () => setChartView('birdeye') }),
- el('button', { class: 'ld-btn ld-btn-ghost', type: 'button', text: 'Check again', onclick: () => { state.gecko = null; renderChart(); } }),
+ el('button', { class: 'ld-btn ld-btn-ghost', type: 'button', text: 'Check again', onclick: () => { delete state.chartPools[provider.id]; renderChart(); } }),
]),
]),
);
return;
}
- pool = state.gecko.pool;
+ pool = resolved.pool;
}
const urls = chartEmbedUrls(provider.id, { chain: 'solana', token: state.mint, pool, theme: currentTheme() });
diff --git a/src/shared/chart-embeds.js b/src/shared/chart-embeds.js
index f387de630..f0571fa60 100644
--- a/src/shared/chart-embeds.js
+++ b/src/shared/chart-embeds.js
@@ -5,15 +5,24 @@
// /coin/:id build identical embeds and a provider changing its embed format is
// a one-file fix.
//
-// Only providers verified to render inside a cross-origin <iframe> without a
-// key are listed. Checked in a real browser, 2026-09-17:
+// Only providers that publish a keyless embed a cross-origin <iframe> can load
+// are listed. Checked in a real browser, 2026-09-17:
// DexScreener token address, resolves the top pair itself
// Birdeye token address (its TradingView-based tv-widget)
// GMGN token address (its kline widget), Solana/ETH/Base/BSC only
// GeckoTerminal pool address, and only once GeckoTerminal indexed that pool
-// Refused framing or needs a key, so deliberately absent: DEXTools
-// (X-Frame-Options), Codex/Defined (frame-ancestors / bot checkpoint), Moralis
-// (key-restricted widget), pump.fun, Jupiter, Photon, Axiom, Solscan.
+// Added 2026-09-18 on its HTTP contract, because its Cloudflare rule refuses the
+// automated browsers this repo can run (so no in-browser check was possible):
+// DEXTools pair address, through its published /widget-chart/ route.
+// That route answers a cross-site framed request 200 with no
+// X-Frame-Options and no frame-ancestors. DEXTools' normal
+// /app/ pages DO refuse framing, and so does the Cloudflare
+// challenge page a flagged client gets instead of the widget,
+// which is what an earlier check here mistook for the widget's
+// own policy. Never embed an /app/ URL.
+// Refused framing or needs a key, so deliberately absent: Codex/Defined
+// (frame-ancestors / bot checkpoint), Moralis (key-restricted widget), pump.fun,
+// Jupiter, Photon, Axiom, Solscan.
//
// Each chain entry holds the slug every provider uses for that chain. A chain a
// provider does not index is simply missing from its field, and the provider is
@@ -24,14 +33,14 @@ const SOL_RE = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
/** Chain id (CoinGecko asset-platform id) → per-provider slug. Solana leads. */
export const CHART_CHAINS = {
- solana: { ds: 'solana', gt: 'solana', be: 'solana', gm: 'sol', evm: false },
- ethereum: { ds: 'ethereum', gt: 'eth', be: 'ethereum', gm: 'eth', evm: true },
- base: { ds: 'base', gt: 'base', be: 'base', gm: 'base', evm: true },
- 'binance-smart-chain': { ds: 'bsc', gt: 'bsc', be: 'bsc', gm: 'bsc', evm: true },
- 'polygon-pos': { ds: 'polygon', gt: 'polygon_pos', be: 'polygon', evm: true },
- 'arbitrum-one': { ds: 'arbitrum', gt: 'arbitrum', be: 'arbitrum', evm: true },
- 'optimistic-ethereum': { ds: 'optimism', gt: 'optimism', be: 'optimism', evm: true },
- avalanche: { ds: 'avalanche', gt: 'avax', be: 'avalanche', evm: true },
+ solana: { ds: 'solana', gt: 'solana', be: 'solana', gm: 'sol', dt: 'solana', evm: false },
+ ethereum: { ds: 'ethereum', gt: 'eth', be: 'ethereum', gm: 'eth', dt: 'ether', evm: true },
+ base: { ds: 'base', gt: 'base', be: 'base', gm: 'base', dt: 'base', evm: true },
+ 'binance-smart-chain': { ds: 'bsc', gt: 'bsc', be: 'bsc', gm: 'bsc', dt: 'bnb', evm: true },
+ 'polygon-pos': { ds: 'polygon', gt: 'polygon_pos', be: 'polygon', dt: 'polygon', evm: true },
+ 'arbitrum-one': { ds: 'arbitrum', gt: 'arbitrum', be: 'arbitrum', dt: 'arbitrum', evm: true },
+ 'optimistic-ethereum': { ds: 'optimism', gt: 'optimism', be: 'optimism', dt: 'optimism', evm: true },
+ avalanche: { ds: 'avalanche', gt: 'avax', be: 'avalanche', dt: 'avalanche', evm: true },
};
/** True when `address` is well-formed for `chain`. */
@@ -47,9 +56,12 @@ const enc = encodeURIComponent;
* The embeddable providers, in the order a switcher shows them.
*
* `needs` is 'token' (keyed by the token address) or 'pool' (keyed by a pool
- * address the caller resolves first). `embed()` returns the iframe URL and
- * `page()` the provider's own page for the same market, used by "open in"
- * links and by the fallback panel when an embed is blocked.
+ * address the caller resolves first, through resolveChartPool()). A pool
+ * provider carries its own `resolvePool`, because "which pool" is shared but
+ * "will this provider draw it" is not: GeckoTerminal 404s on a pool it has not
+ * indexed, DEXTools charts any pair it is handed. `embed()` returns the iframe
+ * URL and `page()` the provider's own page for the same market, used by "open
+ * in" links and by the fallback panel when an embed is blocked.
*/
export const CHART_EMBEDS = [
{
@@ -94,11 +106,29 @@ export const CHART_EMBEDS = [
`https://www.gmgn.cc/kline/${slug}/${enc(token)}?${new URLSearchParams({ theme, interval: '15' })}`,
page: ({ slug, token }) => `https://gmgn.ai/${slug}/token/${enc(token)}`,
},
+ {
+ id: 'dextools',
+ label: 'DEXTools',
+ needs: 'pool',
+ slug: 'dt',
+ resolvePool: resolveTopPool,
+ // chartType 1 is candles; the drawing toolbar is off because it eats a
+ // third of the width at the sizes this chart is embedded at.
+ embed: ({ slug, pool, theme }) =>
+ `https://www.dextools.io/widget-chart/en/${slug}/pe-light/${enc(pool)}?${new URLSearchParams({
+ theme,
+ chartType: '1',
+ chartResolution: '15',
+ drawingToolbars: 'false',
+ })}`,
+ page: ({ slug, pool }) => `https://www.dextools.io/app/${slug}/pair-explorer/${enc(pool)}`,
+ },
{
id: 'geckoterminal',
label: 'GeckoTerminal',
needs: 'pool',
slug: 'gt',
+ resolvePool: resolveGeckoPool,
embed: ({ slug, pool, theme }) =>
`https://www.geckoterminal.com/${slug}/pools/${enc(pool)}?${new URLSearchParams({
embed: '1',
@@ -136,19 +166,17 @@ export function chartEmbedUrls(providerId, { chain, token, pool = null, theme =
}
/**
- * Resolves the pool GeckoTerminal's embed is keyed by, and whether GeckoTerminal
- * has indexed it. /api/coin/pool falls back to DexScreener for a token
- * GeckoTerminal does not know yet (every young pump.fun coin), and GeckoTerminal
- * answers its embed for an unindexed pool with a full-page 404, so the pool is
- * confirmed against GeckoTerminal's own public API (CORS-open, keyless) before
- * the embed is mounted.
+ * The most liquid pool for a token, from /api/coin/pool (GeckoTerminal first,
+ * DexScreener for a token GeckoTerminal does not know yet, which is every young
+ * pump.fun coin). `indexed` here only means "a pool exists": it is the shape
+ * every `resolvePool` returns, so callers treat all pool providers alike.
*
* @param {string} chain
* @param {string} token
* @param {{ signal?: AbortSignal }} [opts]
* @returns {Promise<{ pool: string|null, indexed: boolean }>}
*/
-export async function resolveGeckoPool(chain, token, { signal } = {}) {
+export async function resolveTopPool(chain, token, { signal } = {}) {
const network = CHART_CHAINS[chain]?.gt;
if (!network) return { pool: null, indexed: false };
const r = await fetch(`/api/coin/pool?address=${enc(token)}&network=${enc(network)}`, {
@@ -158,7 +186,24 @@ export async function resolveGeckoPool(chain, token, { signal } = {}) {
if (r.status === 404) return { pool: null, indexed: false };
if (!r.ok) throw new Error(`pool lookup ${r.status}`);
const { pool } = await r.json();
+ return { pool: pool || null, indexed: !!pool };
+}
+
+/**
+ * Resolves the pool GeckoTerminal's embed is keyed by, and whether GeckoTerminal
+ * has indexed it. GeckoTerminal answers its embed for an unindexed pool with a
+ * full-page 404, so the pool is confirmed against GeckoTerminal's own public API
+ * (CORS-open, keyless) before the embed is mounted.
+ *
+ * @param {string} chain
+ * @param {string} token
+ * @param {{ signal?: AbortSignal }} [opts]
+ * @returns {Promise<{ pool: string|null, indexed: boolean }>}
+ */
+export async function resolveGeckoPool(chain, token, { signal } = {}) {
+ const { pool } = await resolveTopPool(chain, token, { signal });
if (!pool) return { pool: null, indexed: false };
+ const network = CHART_CHAINS[chain].gt;
const gt = await fetch(`https://api.geckoterminal.com/api/v2/networks/${enc(network)}/pools/${enc(pool)}`, {
headers: { accept: 'application/json' },
signal,
@@ -167,3 +212,19 @@ export async function resolveGeckoPool(chain, token, { signal } = {}) {
if (!gt.ok) throw new Error(`GeckoTerminal ${gt.status}`);
return { pool, indexed: true };
}
+
+/**
+ * Resolves the pool a pool-keyed provider needs, the way that provider needs it.
+ *
+ * @param {string} providerId
+ * @param {string} chain
+ * @param {string} token
+ * @param {{ signal?: AbortSignal }} [opts]
+ * @returns {Promise<{ pool: string|null, indexed: boolean }>} `indexed: false`
+ * means the provider cannot draw this coin yet; `pool` may still be set.
+ */
+export function resolveChartPool(providerId, chain, token, opts) {
+ const provider = CHART_EMBEDS.find((p) => p.id === providerId);
+ if (provider?.needs !== 'pool') return Promise.resolve({ pool: null, indexed: false });
+ return provider.resolvePool(chain, token, opts);
+}