fix(pricing): validate asset prices before storing and guard the DEX reference amount#4201
Open
Danswar wants to merge 1 commit into
Open
fix(pricing): validate asset prices before storing and guard the DEX reference amount#4201Danswar wants to merge 1 commit into
Danswar wants to merge 1 commit into
Conversation
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.
Why
The hourly asset-pricing job on dev has been failing on every run for 7+ days:
The stored
approxPriceChffor TGT on dev is a degenerate near-zero value (observed:4.24e-60).Asset.minimalPriceReferenceAmountinverts the stored price, so the reference amount used for the quote overflows uint256 and the Uniswap SDK rejects it.Two things make this worse than a single bad quote:
pricing-dex.service), so the failing quote prevents the corrupt price from ever being overwritten. Prod's TGT row is healthy (0.0061 CHF, refreshing hourly), which confirms the pool quote is fine — only the stored dev value is corrupt.approxPriceChfalso feeds the public asset DTO, custody balance values, trading profit estimates, and the persisted daily price history — so it must not be stored in the first place.What
Asset.isSanePrice()with sanity rails (1e-12–1e15): a price outside these is corrupted data, not a real price.minimalPriceReferenceAmount): falls back to a reference amount of1for insane prices instead of inverting them. This breaks the deadlock: the next pricing run can quote again and overwrite the corrupt value.AssetPricesJobService.updatePrices): a degenerate fetched price is no longer stored — the job logs a warning and keeps the last known good price, protecting all downstream consumers at the source.Replaces the asset-price half of #4200, which only guarded the single read site and had no write-path validation.
Test plan
asset.entity.spec.ts(sanity rails + reference-amount fallback) andasset-prices-job.service.spec.ts(stores sane prices, skips degenerate ones, keeps last known good, continues with remaining assets) — 9/9 passingtsc --noEmit/ prettier cleanDexServiceerror stops and TGT's price self-heals