Skip to content

feat(prices): gate price source on USE_PRICE_SERVICE and stop serving table-backed prices#442

Open
matheus1lva wants to merge 9 commits into
mainfrom
decomission-price-table
Open

feat(prices): gate price source on USE_PRICE_SERVICE and stop serving table-backed prices#442
matheus1lva wants to merge 9 commits into
mainfrom
decomission-price-table

Conversation

@matheus1lva

@matheus1lva matheus1lva commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a USE_PRICE_SERVICE flag that routes the indexer's price lookups to the yearn-prices service instead of the Postgres price table, skipping table reads and writes when it's on. The GraphQL/REST read layer stops serving the table-backed per-block prices, which were yDaemon spot snapshots captured at ingestion time rather than historical prices.

How to review

Start in packages/ingest/prices.ts. The fetch path splits into __fetchErc20PriceUsdFromTable (default, unchanged) and __fetchErc20PriceUsdFromService. The service path keys on UTC day: past days come from the price service batchHistorical endpoint at day granularity; current-day and latest fall back to yDaemon then lens, and neither is written back as a historical close. Only a genuine priceservice result is cached under the (chain, token, day) key, so a block-accurate fallback never leaks onto other blocks in the same day. maybePersistPrice is the one gate that skips table writes in service mode.

On the read side, resolvers/prices.ts returns [], and resolvers/tvls.ts drops the price join and keeps priceUsd/priceSource as null/'na' for response-shape compatibility.

The if( to if ( churn in prices.ts is formatter noise, safe to skim.

Test plan

  • Manual: with USE_PRICE_SERVICE=false (default), confirm ingest prices and TVL behave as before.
  • Manual: with USE_PRICE_SERVICE=true, confirm ingest resolves historical prices from the service, the prices resolver returns [], and tvls rows come back with priceUsd: null.
  • Automated: bun --filter ingest test (prices.unit.spec.ts, prices.service-cache.spec.ts), bun --filter web test (prices.spec.ts, tvls.spec.ts).

Risk / impact

USE_PRICE_SERVICE defaults to false, so the table-backed path is unchanged unless the flag is set. Toggling needs a process restart, not a live flip. In service mode the indexer stops writing to the price table. The GraphQL prices field returns empty for everyone, so point consumers at prices.yearn.dev. The field stays for response compatibility, with full removal as a follow-up.

…RICE_SERVICE

Null GraphQL prices/tvls price fields (unusable per-block spot data) and
gate the indexer on USE_PRICE_SERVICE so past-day prices can come from
yearn-prices without writing the Postgres price table.
@vercel

vercel Bot commented Jul 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
kong Ready Ready Preview, Comment Jul 19, 2026 1:47am

Request Review

Cache under the (chain,token,day) key only for genuine price-service results; block-accurate lens/yprice fallbacks and unknowns are no longer reused across other blocks in the same day. Move getBlockTime inside fetchPriceServiceUsd's try so an RPC blip falls through to the fallback. Make cache get/set no-op before init, mirroring wrap, so jobs during startup don't throw.
Remove additions not in the spec: the fail-closed USE_PRICE_SERVICE startup assertion, the priceServiceMetrics/recordServiceOutcome trial instrumentation, and the /api/prices/spot fallback. Spec names fetchPriceServiceUsd (batchHistorical) as the only service lookup; current-day/latest falls back yDaemon -> lens as before.
Accept any-case 'true' instead of JSON.parse (throws on True/yes/on and crashes the hot price path). Skip WaveyDb price-table writes in service mode.
Service mode: price service only, no fallbacks, no mq writes, no utc/day handling. Table mode: unchanged legacy path. Drop day-cache and revert cache init guards.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant