Repository navigation
feat(api): block-time pricing + historical provider coverage for rewards - #39
Merged
Merged
Conversation
/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.
2 of 3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the two remaining gaps between info's
/provider-estimated-rewards?block=Nand jsinfo's stored monthly JSON snapshots:/coins/lava-network/history?date=DD-MM-YYYYfor the block's date.x-cosmos-block-heightso the pairing list is the one that existed at the block.Impact (measured against block 4697952, March 17 snapshot)
Scope
Historical provider coverage is scoped to the rewards endpoints only (per user ask).
fetchProvidersWithSpecsandfetchProvidersForSpecgain an optionalblockHeight?parameter that defaults toundefined— meaning all existing callers (/providers,/specs,/all_providers_apr, etc.) keep querying current chain state with no behavior change. Only/provider-estimated-rewardspasses a block height through.Changes
rpc/block.ts—fetchBlockTime(height)for height → ISO timestamprpc/pricing.ts—fetchTokenUsdPriceAt(denom, date)andbuildHistoricalPriceMap(date)with indefinite caching (historical prices don't change)rpc/providers.ts— optionalblockHeighton both provider fetchers;fetchRestalready supports thex-cosmos-block-heightheaderrpc/rewards.ts— optionalpriceOverridesonfetchRewardsBySpec→ threaded intoprocessRewardTokenswhere it takes precedence over the live cacheroutes/provider-estimated-rewards.ts— when?block=is set: fetch block time → build historical price map → pass both through.meta.priceTimestampbecomes the block time (instead of now) andmeta.priceLavaUsdbecomes the historical price.Test plan
pnpm --filter @info/api typecheckcleanpnpm --filter @info/api test— 112 passing (3 new: historical pricing propagation, historical provider snapshot, live-mode doesn't trigger historical helpers)