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(market): stop one DexScreener or Birdeye blip blanking a token page or an agent dashboard

nirholas29c75e75789a
diff --git a/api/_lib/token-market.js b/api/_lib/token-market.js
index acf1c342a..03e946602 100644
--- a/api/_lib/token-market.js
+++ b/api/_lib/token-market.js
@@ -17,6 +17,7 @@
import { isValidSolanaAddress, isValidEvmAddress } from './validate.js';
import { fetchHoneypot, honeypotChainId } from './honeypot.js';
+import { fetchUpstreamJson, lastGood } from './upstream-fetch.js';
const DEXSCREENER_TOKENS = 'https://api.dexscreener.com/latest/dex/tokens/';
@@ -77,12 +78,26 @@ export async function fetchTokenMarket(ca, opts = {}) {
? fetchHoneypot(ca, { chainId: pinnedHpChain ?? undefined }).catch(() => null)
: Promise.resolve(null);
- const r = await fetch(`${DEXSCREENER_TOKENS}${encodeURIComponent(ca)}`, {
- headers: { Accept: 'application/json' },
- signal: opts.signal ?? AbortSignal.timeout(6000),
- });
- if (!r.ok) return null;
- const data = await r.json().catch(() => null);
+ // One keyless DexScreener read used to decide whether a token exists at all,
+ // so a throttle there made a live token read as "not found" on /ca2x402 and
+ // 503'd the paid token-intel service. The call is now retried behind a
+ // breaker and backed by a last-known-good payload: a few minutes of
+ // staleness beats telling a caller their real token is unknown.
+ let data = null;
+ try {
+ const out = await lastGood(
+ `token-market:${ca.toLowerCase()}`,
+ () => fetchUpstreamJson(
+ `${DEXSCREENER_TOKENS}${encodeURIComponent(ca)}`,
+ { headers: { Accept: 'application/json' }, signal: opts.signal },
+ { name: 'dexscreener:tokens', timeoutMs: 6_000, attempts: 2 },
+ ),
+ { maxAgeMs: 15 * 60_000 },
+ );
+ data = out.value;
+ } catch {
+ return null;
+ }
let pairs = Array.isArray(data?.pairs) ? data.pairs : [];
if (opts.chain) pairs = pairs.filter((p) => p.chainId === opts.chain);
if (!pairs.length) return null;
diff --git a/api/pump/dashboard.js b/api/pump/dashboard.js
index 094d51736..44685795e 100644
--- a/api/pump/dashboard.js
+++ b/api/pump/dashboard.js
@@ -1,6 +1,8 @@
import { sql } from '../_lib/db.js';
import { getSessionUser } from '../_lib/auth.js';
import { json, error, wrap } from '../_lib/http.js';
+import { fetchTokenMarketData } from '../_lib/market/token-market.js';
+import { withBreaker } from '../_lib/resilience.js';
const BIRDEYE_API_KEY = process.env.BIRDEYE_API_KEY;
@@ -59,28 +61,54 @@ export default wrap(async (req, res) => {
if (!tokenMint)
return error(res, 404, 'token_not_launched', 'token not launched for this agent');
- if (!BIRDEYE_API_KEY) {
- return error(res, 503, 'not_configured', 'On-chain data provider is not configured');
- }
+ const headers = BIRDEYE_API_KEY ? { 'X-API-KEY': BIRDEYE_API_KEY } : null;
- const headers = { 'X-API-KEY': BIRDEYE_API_KEY };
+ // The two halves fail independently now. Price comes from the shared market
+ // chain (Birdeye, then tokens.xyz, DexScreener and GeckoTerminal, with its own
+ // stale tier), so it survives a Birdeye outage and works with no Birdeye key
+ // at all, which is why the hard 503 above is gone. The recent-trades list has
+ // no second source, so it degrades to an empty list behind a breaker and says
+ // so, instead of taking the whole dashboard down with it: a price with no
+ // trade feed is most of the page, a 502 is none of it.
+ const [priceResult, historyResult] = await Promise.allSettled([
+ fetchTokenMarketData(tokenMint),
+ headers
+ ? withBreaker(
+ 'birdeye:txs',
+ () => fetchWithCache(`https://public-api.birdeye.so/defi/txs/latest?address=${tokenMint}`, { headers }),
+ { fallback: null },
+ )
+ : Promise.resolve(null),
+ ]);
- try {
- const [price, history] = await Promise.all([
- fetchWithCache(`https://public-api.birdeye.so/defi/price?address=${tokenMint}`, {
- headers,
- }),
- fetchWithCache(`https://public-api.birdeye.so/defi/txs/latest?address=${tokenMint}`, {
- headers,
- }),
- ]);
+ const market = priceResult.status === 'fulfilled' ? priceResult.value : null;
+ const history = historyResult.status === 'fulfilled' ? historyResult.value : null;
+ const degraded = [];
+ if (!market?.price_usd) degraded.push('price');
+ if (!history) degraded.push('history');
- return json(res, 200, {
- price: price.data,
- history: history?.data?.items ?? [],
- });
- } catch (e) {
- console.error(`[pump-dashboard] Error fetching token data for ${tokenMint}:`, e);
- return error(res, 502, 'bad_gateway', 'Failed to fetch on-chain data');
+ if (!market?.price_usd && !history) {
+ console.error(`[pump-dashboard] no market source answered for ${tokenMint}`);
+ res.setHeader('retry-after', '15');
+ return error(res, 503, 'market_unavailable', 'on-chain market data is temporarily unavailable, retry shortly');
}
+
+ return json(res, 200, {
+ price: market?.price_usd == null
+ ? null
+ : {
+ value: market.price_usd,
+ updateUnixTime: Math.floor(Date.now() / 1000),
+ priceChange24h: market.price_change_24h,
+ // The dashboard has always rendered a market cap slot; Birdeye's
+ // price endpoint does not carry one, so it read "N/A" for every
+ // token. The market chain does carry it, so the slot finally means
+ // something.
+ marketCap: market.market_cap,
+ liquidity: market.liquidity,
+ source: market.source,
+ },
+ history: history?.data?.items ?? [],
+ degraded: degraded.length ? degraded : null,
+ });
});