Skip to content

feat(api): block-time pricing + historical provider coverage for rewards - #39

Merged
nimrod-teich merged 1 commit into
mainfrom
feat/historical-rewards-pricing
Apr 20, 2026
Merged

nimrod-teich merged 1 commit into
mainfrom
feat/historical-rewards-pricing

Conversation

@nimrod-teich

Copy link
Copy Markdown
Contributor

Summary

Closes the two remaining gaps between info's /provider-estimated-rewards?block=N and jsinfo's stored monthly JSON snapshots:

  1. Historical pricing — info used to price tokens at the current LAVA price for any block, so rewards drifted as the price moved. Now it uses CoinGecko's /coins/lava-network/history?date=DD-MM-YYYY for the block's date.
  2. Historical provider coverage — info used to iterate the CURRENT provider set, missing providers who've since deregistered. Now it queries chain RPC with x-cosmos-block-height so the pairing list is the one that existed at the block.

Impact (measured against block 4697952, March 17 snapshot)

Before After (expected)
Providers vs jsinfo (48) 34 (misses 14) 48 ✓
USD / LAVA ratio vs jsinfo (74.7% = price ratio) drifts with price 1.00× (block-time price)
LAVA token amounts byte-exact ✓ unchanged ✓

Scope

Historical provider coverage is scoped to the rewards endpoints only (per user ask). fetchProvidersWithSpecs and fetchProvidersForSpec gain an optional blockHeight? parameter that defaults to undefined — meaning all existing callers (/providers, /specs, /all_providers_apr, etc.) keep querying current chain state with no behavior change. Only /provider-estimated-rewards passes a block height through.

Changes

  • rpc/block.ts — fetchBlockTime(height) for height → ISO timestamp
  • rpc/pricing.ts — fetchTokenUsdPriceAt(denom, date) and buildHistoricalPriceMap(date) with indefinite caching (historical prices don't change)
  • rpc/providers.ts — optional blockHeight on both provider fetchers; fetchRest already supports the x-cosmos-block-height header
  • rpc/rewards.ts — optional priceOverrides on fetchRewardsBySpec → threaded into processRewardTokens where it takes precedence over the live cache
  • routes/provider-estimated-rewards.ts — when ?block= is set: fetch block time → build historical price map → pass both through. meta.priceTimestamp becomes the block time (instead of now) and meta.priceLavaUsd becomes the historical price.

Test plan

  • pnpm --filter @info/api typecheck clean
  • pnpm --filter @info/api test — 112 passing (3 new: historical pricing propagation, historical provider snapshot, live-mode doesn't trigger historical helpers)
  • Deploy + re-run the rewards breakdown comparison script against block 4697952 — expect provider count to match jsinfo (48) and USD totals to land within a couple of percent

/provider-estimated-rewards?block=N now produces a self-consistent snapshot
that matches jsinfo's stored monthly JSON: prices are as-of the block, and
the provider set is the chain's pairing list at that block (not today's).

Before this change, a historical-block query:
  • Priced tokens at the CURRENT LAVA price (drifts from jsinfo as price moves)
  • Iterated the CURRENT provider set (missed providers who've since
    unbonded/deregistered — ~14/48 missing on March 17, worth ~$2,922 USD)

After:
  • block-time LAVA price via CoinGecko /coins/lava-network/history, passed
    through as a price-override map down to processRewardTokens
  • provider set fetched with x-cosmos-block-height header so chain RPC
    returns the historical pairing list

Changes:
- rpc/block.ts: export fetchBlockTime(height) for block → ISO timestamp
- rpc/pricing.ts: fetchTokenUsdPriceAt(denom, date) and buildHistoricalPriceMap
  with indefinite caching (historical prices don't change)
- rpc/providers.ts: optional blockHeight on fetchProvidersForSpec +
  fetchProvidersWithSpecs. Default undefined → current state, unchanged for
  every non-rewards caller (/providers, /specs, etc.)
- rpc/rewards.ts: optional priceOverrides on fetchRewardsBySpec. Threads into
  processRewardTokens where it takes precedence over the live price cache.
- routes/provider-estimated-rewards.ts: when ?block= is set, fetches block
  time → builds historical price map → passes both blockHeight and overrides
  down. meta.priceTimestamp = block time; meta.priceLavaUsd = historical price.
- tests: new assertions for block-time pricing, historical provider coverage,
  and that live-mode doesn't accidentally call historical helpers. 112/112.
@nimrod-teich
nimrod-teich merged commit 405879c into main Apr 20, 2026
2 checks passed
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