From fe5b0fcb02523a1561638de592cbd488f083c8fa Mon Sep 17 00:00:00 2001 From: Ezedike-egwom Collins Date: Sun, 21 Jun 2026 12:25:46 +0100 Subject: [PATCH 1/2] fix: report actual cache hit status instead of hardcoding cached false --- api/v1/vaults/index.ts | 5 +++-- apps/api/src/routes/vaults.ts | 5 +++-- packages/stellar-sdk-helpers/src/vaults.ts | 5 +++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/api/v1/vaults/index.ts b/api/v1/vaults/index.ts index 57b40898..1aacb72a 100644 --- a/api/v1/vaults/index.ts +++ b/api/v1/vaults/index.ts @@ -1,5 +1,5 @@ import type { VercelRequest, VercelResponse } from "@vercel/node"; -import { fetchAllVaults, selectBestVault } from "@meridian/stellar-sdk-helpers"; +import { fetchAllVaults, selectBestVault, isVaultCacheWarm } from "@meridian/stellar-sdk-helpers"; import { APP_ADDRESSES } from "@meridian/shared"; import { applyCors } from "../../_lib/middleware"; @@ -14,6 +14,7 @@ const defindexConfigured = Boolean(process.env.DEFINDEX_VAULT_ID ?? APP_ADDRESSE export default async function handler(req: VercelRequest, res: VercelResponse) { if (applyCors(req, res)) return; try { + const cached = isVaultCacheWarm(); const vaults = await fetchAllVaults(); const best = selectBestVault(vaults, { defindexConfigured }); res.setHeader("Cache-Control", CACHE_CONTROL); @@ -21,7 +22,7 @@ export default async function handler(req: VercelRequest, res: VercelResponse) { vaults, recommendedVaultId: best?.id ?? null, updatedAt: new Date().toISOString(), - cached: false, + cached, }); } catch (err) { console.error("[vaults] fetch error:", err); diff --git a/apps/api/src/routes/vaults.ts b/apps/api/src/routes/vaults.ts index 7d331c85..0b3731a8 100644 --- a/apps/api/src/routes/vaults.ts +++ b/apps/api/src/routes/vaults.ts @@ -1,5 +1,5 @@ import type { FastifyPluginAsync } from "fastify"; -import { selectBestVault } from "@meridian/stellar-sdk-helpers"; +import { selectBestVault, isVaultCacheWarm } from "@meridian/stellar-sdk-helpers"; import { APP_ADDRESSES } from "@meridian/shared"; import { fetchAllVaults } from "../services/vaults.js"; @@ -8,13 +8,14 @@ const defindexConfigured = Boolean(process.env.DEFINDEX_VAULT_ID ?? APP_ADDRESSE export const vaultsRoute: FastifyPluginAsync = async (app) => { app.get("/", async (_req, reply) => { try { + const cached = isVaultCacheWarm(); const vaults = await fetchAllVaults(); const best = selectBestVault(vaults, { defindexConfigured }); return reply.send({ vaults, recommendedVaultId: best?.id ?? null, updatedAt: new Date().toISOString(), - cached: false, + cached, }); } catch (err) { app.log.error(err, "[vaults] failed to fetch vaults"); diff --git a/packages/stellar-sdk-helpers/src/vaults.ts b/packages/stellar-sdk-helpers/src/vaults.ts index f2c50476..29189274 100644 --- a/packages/stellar-sdk-helpers/src/vaults.ts +++ b/packages/stellar-sdk-helpers/src/vaults.ts @@ -24,6 +24,11 @@ export function clearVaultCache(): void { vaultCache = null; } +/** Returns true if a valid cached result exists and will be returned by fetchAllVaults. */ +export function isVaultCacheWarm(): boolean { + return vaultCache !== null && Date.now() < vaultCache.expiresAt; +} + // Every vault in the list is backed by live DeFiLlama market data. Protocols // without a real on-chain rate feed wired up yet are intentionally omitted // rather than shown with placeholder figures. From 9e5ef04a3efe05fcb24e8fb81a0c4effc32b10bf Mon Sep 17 00:00:00 2001 From: Ezedike-egwom Collins Date: Sun, 21 Jun 2026 13:38:25 +0100 Subject: [PATCH 2/2] fix: add isVaultCacheWarm to handlers test mock --- api/__tests__/handlers.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/api/__tests__/handlers.test.ts b/api/__tests__/handlers.test.ts index e89ebaa7..2573e6ee 100644 --- a/api/__tests__/handlers.test.ts +++ b/api/__tests__/handlers.test.ts @@ -11,6 +11,7 @@ vi.mock("@meridian/stellar-sdk-helpers", () => ({ submitTx: vi.fn(async () => ({ hash: "HASH" })), fetchAllVaults: vi.fn(async () => [{ id: "blend-usdc-fixed", protocol: "blend" }]), selectBestVault: vi.fn(() => ({ id: "blend-usdc-fixed" })), + isVaultCacheWarm: vi.fn(() => false), fetchBlendPositions: vi.fn(async () => [ { vaultId: "blend-usdc-fixed", shares: 1, deposited: 1, earned: 0, entryTime: 0 }, ]),