Skip to content

Commit bb06f97

Browse files
committed
feat(api): expose icon URL on /lava/specs
Each spec now returns { index, name, icon } where icon is an absolute URL built from INFO_ICONS_BASE_URL — same shared helper /specs already uses, so cross-origin consumers (burn-ui, lava-rewards) can load chain icons directly from the API response without knowing the FE host. Additive: useChainNames hook only reads index/name and is unaffected.
1 parent 43b18d3 commit bb06f97

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

‎CLAUDE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ packages/
180180
| `GET /tvl` | 300s | Chain RPC + CoinGecko | TVL (USD) = bonded tokens + reward pools + subscriptions + DEX liquidity. All components converted to USD via CoinGecko LAVA price |
181181
| `GET /apr` | 1800s | Chain RPC + CoinGecko | Per-entity APR percentiles matching jsinfo. Queries `estimated_{provider,validator}_rewards` for all providers/validators with 10k LAVA benchmark, converts multi-denom rewards to USD, compounds monthly, takes 80th percentile, caps at 30%. Returns `{ restaking_apr_percentile, staking_apr_percentile }`. Uses 7-day weighted Redis history when available |
182182
| `GET /all_providers_apr` | 1800s | Chain RPC + CoinGecko + Indexer MV | Per-provider APR data matching jsinfo. Returns array of providers with: APR, commission, 30d CU/relays, 10k LAVA reward breakdown, per-spec rewards (rewards_last_month), specs, avatar |
183-
| `GET /lava/specs` | 300s | Chain RPC | All chain specs (raw, used by frontend `useChainNames` hook) |
183+
| `GET /lava/specs` | 300s | Chain RPC | All chain specs with `{ index, name, icon }`. Used by frontend `useChainNames` hook; `icon` is an absolute URL (`INFO_ICONS_BASE_URL` + `/chains/<slug>.svg`) for cross-origin consumers |
184184
| `GET /provider-rewards?from=&to=&groupBy=` | 300s | Indexer MV | Per-provider (default) or per-(provider, spec) QoS-adjusted reward shares. Required: `from`, `to` (YYYY-MM-DD, exclusive end, max 6 months). Optional: `specs` (chain filter), `groupBy` (`provider` default, or `spec`). In `provider` mode the GraphQL pools all chains before computing `cbrt(...)` — required for parity with delta's adjustedRewards because the formula is non-linear. In `spec` mode each row is a (provider, spec) pair with within-spec `rewardShare`. Returns `{ meta, data: [{ provider, [spec]?, moniker, relays, cus, qosCus, avgLatency, avgAvailability, avgSync, avgLatencyExc, avgAvailabilityExc, avgSyncExc, adjustedRewards, rewardShare }] }`. Replaces lava-ops Job 1. For USD estimates use `/provider-estimated-rewards` |
185185
| `GET /provider-estimated-rewards?block=&spec=` | 1800s (86400s with `block`) | Chain RPC + CoinGecko | Per-provider actual chain rewards from `estimated_provider_rewards` RPC, grouped by spec. Optional `block=N` for historical queries (requires archive node; threads `x-cosmos-block-height` header). Optional `spec=X` filters response. USD values always use CURRENT CoinGecko price, even for historical blocks (matches lava-ops Job 2 behavior) — `meta.priceLavaUsd` / `meta.priceTimestamp` surface this explicitly. Returns `{ meta: { block, spec, priceLavaUsd, priceTimestamp }, data: [{ provider, moniker, rewards: [{ chain, spec, tokens, total_usd }], total_usd }] }`. Sorted by total_usd descending. Replaces lava-ops Job 2 |
186186
| `GET /provider-estimated-rewards/blocks?count=` | 86400s | Chain RPC | Historical monthly-17th blocks for the block-selector UI. Maps each month's 17th at 15:00 UTC to a block height via `fetchBlockAtTimestamp`. Default 12 months, max 24. Returns `{ data: [{ height, time, date }] }` |

‎apps/api/src/__tests__/routes-lava.test.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async function buildApp() {
1717
}
1818

1919
describe("GET /lava/specs", () => {
20-
it("returns all chain specs from rpc", async () => {
20+
it("returns all chain specs with index, name, and absolute icon URL", async () => {
2121
(fetchAllSpecs as ReturnType<typeof vi.fn>).mockResolvedValue([
2222
{ index: "ETH1", name: "Ethereum Mainnet" },
2323
{ index: "LAVA", name: "Lava Mainnet" },
@@ -27,7 +27,16 @@ describe("GET /lava/specs", () => {
2727
expect(res.statusCode).toBe(200);
2828
const body = JSON.parse(res.body);
2929
expect(body.data).toHaveLength(2);
30-
expect(body.data[0].index).toBe("ETH1");
30+
expect(body.data[0]).toEqual({
31+
index: "ETH1",
32+
name: "Ethereum Mainnet",
33+
icon: expect.stringMatching(/^https?:\/\/[^/]+\/chains\/ethereum\.svg$/),
34+
});
35+
expect(body.data[1]).toEqual({
36+
index: "LAVA",
37+
name: "Lava Mainnet",
38+
icon: expect.stringMatching(/^https?:\/\/[^/]+\/chains\/lava\.svg$/),
39+
});
3140
});
3241

3342
it("returns empty data if rpc returns nothing", async () => {

‎apps/api/src/routes/lava.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
import type { FastifyInstance } from "fastify";
2-
import { CACHE_TTL } from "../config.js";
2+
import { CACHE_TTL, config } from "../config.js";
3+
import { getChainIconUrl } from "@info/shared/utils";
34
import { fetchAllSpecs } from "../rpc/lava.js";
45

56
export async function lavaRoutes(app: FastifyInstance) {
6-
// GET /lava/specs — all chain specs (consumed by frontend useChainNames hook)
7+
// GET /lava/specs — all chain specs with icon URLs (consumed by frontend useChainNames hook)
78
app.get("/specs", {
8-
schema: { tags: ["Lava"], summary: "All chain specs (raw, for frontend chain name lookup)" },
9+
schema: { tags: ["Lava"], summary: "All chain specs with display name and icon URL" },
910
config: { cacheTTL: CACHE_TTL.LIST },
1011
}, async () => {
1112
const specs = await fetchAllSpecs();
12-
return { data: specs };
13+
const iconBase = config.icons.baseUrl;
14+
return {
15+
data: specs.map((s) => ({
16+
index: s.index,
17+
name: s.name,
18+
icon: getChainIconUrl(s.index, iconBase),
19+
})),
20+
};
1321
});
1422
}

0 commit comments

Comments
 (0)