diff --git a/apps/api/src/__tests__/routes-index.test.ts b/apps/api/src/__tests__/routes-index.test.ts index c06e04b..d6acaeb 100644 --- a/apps/api/src/__tests__/routes-index.test.ts +++ b/apps/api/src/__tests__/routes-index.test.ts @@ -7,9 +7,13 @@ vi.mock("../rpc/lava.js", () => ({ fetchLatestBlockHeight: vi.fn(), fetchAllProviders: vi.fn(), })); +vi.mock("../rpc/supply.js", () => ({ + fetchStakingPool: vi.fn(), +})); const { gqlSafe } = await import("../graphql/client.js"); const { fetchLatestBlockHeight, fetchAllProviders } = await import("../rpc/lava.js"); +const { fetchStakingPool } = await import("../rpc/supply.js"); const { indexRoutes } = await import("../routes/index.js"); async function buildApp() { @@ -33,6 +37,10 @@ describe("GET /index/stats", () => { (fetchAllProviders as ReturnType).mockResolvedValue([ { address: "lava@a", totalStake: "1000", totalDelegation: "500" }, ]); + (fetchStakingPool as ReturnType).mockResolvedValue({ + bonded_tokens: "381000000000000", + not_bonded_tokens: "999", + }); const app = await buildApp(); const res = await app.inject({ method: "GET", url: "/index/stats" }); @@ -40,7 +48,7 @@ describe("GET /index/stats", () => { const body = JSON.parse(res.body); expect(body.latestBlock).toBe(12345); expect(body.activeProviderCount).toBe(1); - expect(body.totalStake).toBe("1500"); + expect(body.totalStake).toBe("381000000000000"); }); }); diff --git a/apps/api/src/routes/index.ts b/apps/api/src/routes/index.ts index 40f579f..bbd5556 100644 --- a/apps/api/src/routes/index.ts +++ b/apps/api/src/routes/index.ts @@ -3,6 +3,7 @@ import { CACHE_TTL } from "../config.js"; import { weightedQos } from "@info/shared/utils"; import { gqlSafe } from "../graphql/client.js"; import { fetchLatestBlockHeight, fetchAllProviders } from "../rpc/lava.js"; +import { fetchStakingPool } from "../rpc/supply.js"; export async function indexRoutes(app: FastifyInstance) { app.get("/stats", { @@ -22,7 +23,7 @@ export async function indexRoutes(app: FastifyInstance) { }; } | null; - const [allTimeData, last30dData, latestBlock, providers] = await Promise.all([ + const [allTimeData, last30dData, latestBlock, providers, stakingPool] = await Promise.all([ gqlSafe(`{ allMvRelayDailies { aggregates { sum { cu relays } } @@ -35,12 +36,10 @@ export async function indexRoutes(app: FastifyInstance) { }`, { since: thirtyDaysAgo }, null), fetchLatestBlockHeight(), fetchAllProviders(), + fetchStakingPool(), ]); - const totalStake = providers.reduce( - (sum, p) => sum + BigInt(p.totalStake) + BigInt(p.totalDelegation), - 0n, - ); + const totalStake = BigInt(stakingPool.bonded_tokens); return { totalCu: allTimeData?.allMvRelayDailies.aggregates.sum.cu ?? null,