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
fix(defi): repair the chain icon URLs DeFiLlama ships broken, and catch the ones that still fail
nirholascc5dbb2115ad
diff --git a/api/_lib/llama-icon.js b/api/_lib/llama-icon.jsnew file mode 100644index 000000000..61c931322--- /dev/null+++ b/api/_lib/llama-icon.js@@ -0,0 +1,32 @@+// @ts-check+// Normalize a DeFiLlama icon URL so it actually resolves.+//+// DeFiLlama serves every icon under https://icons.llamao.fi/icons/<kind>/<slug>,+// but the dimension feeds (fees, revenue, dex volumes) return chain rows whose+// `logo` drops the /icons segment: `https://icons.llamao.fi/chains/rsz_base.jpg`+// 404s, `https://icons.llamao.fi/icons/chains/rsz_base.jpg` is the same image at+// 200. Passed through untouched, that put a broken image behind every chain row+// on /fees and a run of 404s in the console. Protocol rows in the same payload+// already carry the correct /icons form, so this is a targeted repair of the+// upstream inconsistency rather than a rewrite of every URL.+//+// normalizeLlamaLogo('https://icons.llamao.fi/chains/rsz_base.jpg')+// -> 'https://icons.llamao.fi/icons/chains/rsz_base.jpg'+//+// Anything that is not a bare icons.llamao.fi URL missing the segment is+// returned exactly as given, so the helper is safe to apply to every logo field+// and stays a no-op once upstream fixes its own feed.++const HOST = 'https://icons.llamao.fi/';++/**+ * @param {unknown} url+ * @returns {string | null} the repaired URL, the original string, or null+ */+export function normalizeLlamaLogo(url) {+ if (typeof url !== 'string' || !url) return null;+ if (!url.startsWith(HOST)) return url;+ const rest = url.slice(HOST.length);+ if (rest.startsWith('icons/')) return url;+ return HOST + 'icons/' + rest;+}diff --git a/api/defi/chain.js b/api/defi/chain.jsindex 5c62ac096..adbc1c843 100644--- a/api/defi/chain.js+++ b/api/defi/chain.js@@ -24,6 +24,7 @@ import { cors, json, method, wrap, error, rateLimited } from '../_lib/http.js';import { limits, clientIp } from '../_lib/rate-limit.js';import { createCache, cached } from '../_lib/mem-cache.js';import { fetchUpstream, lastGood } from '../_lib/upstream-fetch.js';+import { normalizeLlamaLogo } from '../_lib/llama-icon.js';// DeFiLlama is this page's only upstream. A TTL cache alone still 502s the// moment it expires during an outage, so every loader also keeps its last good@@ -154,7 +155,7 @@ function shapeProtocols(raw, chainName) {onChain.push({name: typeof p.name === 'string' ? p.name : 'Unknown',slug: typeof p.slug === 'string' ? p.slug : null,- logo: typeof p.logo === 'string' ? p.logo : null,+ logo: normalizeLlamaLogo(p.logo),category: typeof p.category === 'string' ? p.category : null,tvl_on_chain: tvl,change_7d: finite(Number(p.change_7d)),diff --git a/api/defi/dex-volumes.js b/api/defi/dex-volumes.jsindex 892cdd5f3..53311ca7a 100644--- a/api/defi/dex-volumes.js+++ b/api/defi/dex-volumes.js@@ -13,6 +13,7 @@ import { cors, json, method, wrap, error, rateLimited } from '../_lib/http.js';import { limits, clientIp } from '../_lib/rate-limit.js';import { createCache, cached } from '../_lib/mem-cache.js';import { fetchUpstream } from '../_lib/upstream-fetch.js';+import { normalizeLlamaLogo } from '../_lib/llama-icon.js';const UPSTREAM = 'https://api.llama.fi/overview/dexs?excludeTotalDataChartBreakdown=true';const TTL_MS = 600_000;@@ -74,7 +75,7 @@ async function loadDexVolumes() {// `slug` is DeFiLlama's canonical protocol key. It resolves at// /protocol/{slug} (verified against uniswap-v3 and peers).slug: typeof p.slug === 'string' && p.slug ? p.slug : null,- logo: typeof p.logo === 'string' ? p.logo : null,+ logo: normalizeLlamaLogo(p.logo),chains,total24h,total7d: finite(Number(p.total7d)),diff --git a/api/defi/fees.js b/api/defi/fees.jsindex 514776136..800e8334e 100644--- a/api/defi/fees.js+++ b/api/defi/fees.js@@ -14,6 +14,7 @@ import { cors, json, method, wrap, error, rateLimited } from '../_lib/http.js';import { limits, clientIp } from '../_lib/rate-limit.js';import { createCache, cached } from '../_lib/mem-cache.js';import { fetchUpstream } from '../_lib/upstream-fetch.js';+import { normalizeLlamaLogo } from '../_lib/llama-icon.js';const TTL_MS = 600_000;const MAX_CHART_POINTS = 200;@@ -73,7 +74,7 @@ async function loadFees(type) {// `slug` is DeFiLlama's canonical protocol key. It resolves at// /protocol/{slug} (verified against tether / circle-usdc / uniswap-v3).slug: typeof p.slug === 'string' && p.slug ? p.slug : null,- logo: typeof p.logo === 'string' ? p.logo : null,+ logo: normalizeLlamaLogo(p.logo),category: typeof p.category === 'string' ? p.category : null,chains,total24h: finite(Number(p.total24h)),diff --git a/api/defi/protocol.js b/api/defi/protocol.jsindex dc72cc0db..5e470166a 100644--- a/api/defi/protocol.js+++ b/api/defi/protocol.js@@ -19,6 +19,7 @@ import { cors, json, method, wrap, error, rateLimited } from '../_lib/http.js';import { limits, clientIp } from '../_lib/rate-limit.js';import { createCache, cached } from '../_lib/mem-cache.js';import { fetchUpstream, lastGood } from '../_lib/upstream-fetch.js';+import { normalizeLlamaLogo } from '../_lib/llama-icon.js';// DeFiLlama is this page's only upstream. A TTL cache alone still 502s the// moment it expires during an outage, so every loader also keeps its last good@@ -224,7 +225,7 @@ function build(slug, proto, fees, revenue, dexs) {slug,name: str(proto.name) || slug,symbol: str(proto.symbol) && proto.symbol !== '-' ? proto.symbol : null,- logo: httpUrl(proto.logo) || httpUrl(meta.logo),+ logo: normalizeLlamaLogo(httpUrl(proto.logo) || httpUrl(meta.logo)),url: httpUrl(proto.url) || httpUrl(meta.url),twitter: str(proto.twitter) || str(meta.twitter),category: str(proto.category) || str(meta.category),diff --git a/api/defi/protocols.js b/api/defi/protocols.jsindex 9be9ae7e8..57f0d87e4 100644--- a/api/defi/protocols.js+++ b/api/defi/protocols.js@@ -10,6 +10,7 @@ import { cors, json, method, wrap, error, rateLimited } from '../_lib/http.js';import { limits, clientIp } from '../_lib/rate-limit.js';import { createCache, cached } from '../_lib/mem-cache.js';import { fetchUpstream } from '../_lib/upstream-fetch.js';+import { normalizeLlamaLogo } from '../_lib/llama-icon.js';const UPSTREAM = 'https://api.llama.fi/protocols';const TTL_MS = 300_000;@@ -63,7 +64,7 @@ async function loadProtocols() {// DeFiLlama protocol slug. The /protocol/:slug detail page keys off it.slug: typeof p.slug === 'string' ? p.slug : null,name: typeof p.name === 'string' ? p.name : 'Unknown',- logo: typeof p.logo === 'string' ? p.logo : null,+ logo: normalizeLlamaLogo(p.logo),symbol: typeof p.symbol === 'string' && p.symbol !== '-' ? p.symbol : null,category: typeof p.category === 'string' ? p.category : null,chains,diff --git a/src/fees.js b/src/fees.jsindex f8fd6baee..2d0a9f70b 100644--- a/src/fees.js+++ b/src/fees.js@@ -364,6 +364,24 @@ function renderTable() {</table></div>`;+ // A protocol icon is fetched from a third-party CDN, so one that has been+ // renamed or pulled answers 404 and the row renders a broken-image glyph.+ // Swap any icon that fails to load for the same neutral disc a logo-less+ // protocol already gets. The error event does not bubble, so this listens in+ // the capture phase on the container rather than per image.+ el.addEventListener(+ 'error',+ (e) => {+ const img = e.target;+ if (!(img instanceof HTMLImageElement) || !img.closest('.name-cell')) return;+ const fallback = document.createElement('span');+ fallback.className = 'fx-logo-fallback';+ fallback.setAttribute('aria-hidden', 'true');+ img.replaceWith(fallback);+ },+ true,+ );+el.querySelectorAll('th[data-key]').forEach((th) => {const activate = () => {const key = th.dataset.key;diff --git a/tests/llama-icon.test.js b/tests/llama-icon.test.jsnew file mode 100644index 000000000..f38a41a29--- /dev/null+++ b/tests/llama-icon.test.js@@ -0,0 +1,45 @@+// DeFiLlama's dimension feeds return chain rows whose logo URL drops the /icons+// path segment, so every chain icon on /fees 404'd and the console filled with+// them. normalizeLlamaLogo repairs exactly that case and leaves everything else+// byte-identical, so it stays correct once upstream fixes its own feed.++import { describe, it, expect } from 'vitest';+import { normalizeLlamaLogo } from '../api/_lib/llama-icon.js';++describe('normalizeLlamaLogo', () => {+ it('inserts the /icons segment a chain logo is missing', () => {+ expect(normalizeLlamaLogo('https://icons.llamao.fi/chains/rsz_base.jpg')).toBe(+ 'https://icons.llamao.fi/icons/chains/rsz_base.jpg',+ );+ });++ it('keeps a percent-encoded chain name intact', () => {+ expect(normalizeLlamaLogo('https://icons.llamao.fi/chains/rsz_robinhood%20chain.jpg')).toBe(+ 'https://icons.llamao.fi/icons/chains/rsz_robinhood%20chain.jpg',+ );+ });++ // Protocol rows in the very same payload are already correct, so the helper+ // has to be a no-op on them rather than doubling the segment.+ it('leaves an already-correct icons URL exactly as it is', () => {+ const good = 'https://icons.llamao.fi/icons/protocols/uniswap-v4';+ expect(normalizeLlamaLogo(good)).toBe(good);+ });++ it('is idempotent, so a repaired URL survives a second pass', () => {+ const once = normalizeLlamaLogo('https://icons.llamao.fi/chains/rsz_solana.jpg');+ expect(normalizeLlamaLogo(once)).toBe(once);+ });++ it('passes a non-llamao host straight through', () => {+ const other = 'https://example.com/chains/rsz_base.jpg';+ expect(normalizeLlamaLogo(other)).toBe(other);+ });++ it('answers null for a missing or non-string logo', () => {+ expect(normalizeLlamaLogo(null)).toBe(null);+ expect(normalizeLlamaLogo(undefined)).toBe(null);+ expect(normalizeLlamaLogo('')).toBe(null);+ expect(normalizeLlamaLogo(42)).toBe(null);+ });+});