feat: add Curve LP virtual-price fallback to price warmup#11
Open
matheus1lva wants to merge 1 commit into
Open
feat: add Curve LP virtual-price fallback to price warmup#11matheus1lva wants to merge 1 commit into
matheus1lva wants to merge 1 commit into
Conversation
Underlying Curve LP tokens DefiLlama can't price leave gaps that cascade into derived vault prices. Add on-chain fallback pricing the LP from its pool's get_virtual_price * coin0 USD, run as a warmup phase before derived. - src/curve.ts: priceCurveLpUsd resolves pool via Curve AddressProvider, memoized - warmup: warmCurveFallbackPrices phase, skips defillama/curve-filled days - rpc: memoized getChainClient; both phases drop redundant local client/block caches - types: register 'curve' in SOURCE_PRIORITY below market sources, above derived
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
Curve LP tokens that DefiLlama can't price leave a gap in the underlying price
table, and that gap cascades into every derived vault price built on top of
them. This adds an on-chain fallback: when DefiLlama has no price for an
underlying, the warmup prices the Curve LP from its pool's
get_virtual_pricescaled by coin0's USD price, filling the gap before derived prices compute.
Changes
src/curve.ts(new):priceCurveLpUsdresolves a token's Curve pool viathe AddressProvider registry and prices it as
get_virtual_price() / 1e18 * price(coin0). Registry and pool lookups are memoized. Returnsnullfornon-registered LPs or when coin0 has no price, so callers treat it as a clean
miss.
scripts/warmup-prices.ts: newwarmCurveFallbackPricesphase runsbetween the direct and derived phases. It only attempts timestamps that
neither
defillamanor a priorcurverun already filled (today alwaysrefreshes), so repeat runs skip work already on disk.
src/rpc.ts: add memoizedgetChainClient(chainId)that readsRPC_URL_<chainId>. Both warmup phases drop their per-function client andblock-number maps in favor of it and the existing cache inside
estimateBlockByTimestamp, removing two redundant cache layers.src/types.ts: registercurveinSOURCE_PRIORITY, ranked below marketsources and above
derived, so derived vault pricing consumes a curveunderlying when no better source exists.
Testing
bun run typecheckpasses.Curve LP gets a row with
source=curve, and that the derived phase picks upthat underlying when building the vault price.