Skip to content

fix(warmup): gate implausible prices and cap confidence at ingestion#15

Open
matheus1lva wants to merge 4 commits into
mainfrom
fix/price-gating
Open

fix(warmup): gate implausible prices and cap confidence at ingestion#15
matheus1lva wants to merge 4 commits into
mainfrom
fix/price-gating

Conversation

@matheus1lva

Copy link
Copy Markdown
Collaborator

Summary

DefiLlama returns garbage for some legacy Curve LPs — 0 for a few, and ~1e10
from its stale Curve-LP bug. Those values were entering the price table and
outranking the Curve fallback, so vaults priced off bad data. This guards both
the direct and Curve ingestion paths so only prices in (0, 1_000_000] are
stored, and the Curve fallback now wins when DefiLlama is unusable.

It also caps DefiLlama's confidence at 1 (it occasionally returns 1.01) and
adds --chain / --token filters to the warmup script for targeted backfills.

Changes

  • src/format.ts: add isPlausiblePrice (finite, > 0, <= MAX_PLAUSIBLE_PRICE),
    capConfidence (clamp upper bound to 1), and constants MAX_PLAUSIBLE_PRICE,
    CURVE_CONFIDENCE.
  • scripts/warmup-prices.ts:
    • Drop implausible DefiLlama prices in warmDirectPrices; drop implausible
      Curve prices in warmCurveFallbackPrices. Track counts in guardedDirect /
      guardedCurve and log each skip.
    • Curve fallback no longer skips a timestamp just because DefiLlama already
      wrote one, so a guarded-out DefiLlama row no longer blocks the Curve price.
    • Apply capConfidence to DefiLlama writes; ship Curve writes at
      CURVE_CONFIDENCE with the underlying symbol instead of nulls.
    • Add --chain / --token parsing, filterVaults, and an error when a
      filter matches no vaults.

Testing

Not run. Reviewer should verify:

  • A DefiLlama price of 0 or ~1e10 is skipped and the Curve fallback is
    stored instead.
  • --chain / --token narrow the vault set; an unmatched filter errors out.
  • Stored confidence never exceeds 1.

The ingestion guard only stopped new garbage; rows already in the table
(0, ~1e10) still outranked the Curve fallback when served, since ranking
is source-based with no price check. Filter implausible prices in the
read queries so stored garbage is never served and a good fallback wins.

- queries: drop price<=0 / >MAX rows in batch+range reads (both branches)
- format: clamp capConfidence to [0,1]; correct curve-confidence comment
- add format unit tests; drop stray blank line in warmup
One-time cleanup of pre-guard garbage (price<=0, ~1e10) already in the
table. Read path now filters these, so this only shrinks the table.
Irreversible: down is a no-op.
Read path already filters implausible stored rows; the one-time DELETE
is unnecessary.

@murderteeth murderteeth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DefiLlama returns garbage for some legacy Curve LPs

do we know which LPs defi llama has a problem with? do we know all the addresses

@matheus1lva

Copy link
Copy Markdown
Collaborator Author

DefiLlama returns garbage for some legacy Curve LPs

do we know which LPs defi llama has a problem with? do we know all the addresses

Not all but the pattern have been weird, I don't remember which was the address that originated the first fix I did, but now was the stable 3 - all yearn vault tokens. This case was because the pool had such small liquidity that o think defi llama got confused. The gate is still valid despite

@matheus1lva
matheus1lva requested a review from murderteeth July 7, 2026 15:20
@murderteeth

Copy link
Copy Markdown
Contributor

DefiLlama returns garbage for some legacy Curve LPs

do we know which LPs defi llama has a problem with? do we know all the addresses

Not all but the pattern have been weird, I don't remember which was the address that originated the first fix I did, but now was the stable 3 - all yearn vault tokens. This case was because the pool had such small liquidity that o think defi llama got confused. The gate is still valid despite

can we get them all tho? my point is: if we can hardcode a list of legacy lp tokens that have bad prices, this PR becomes much simpler

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.

2 participants