Repository navigation
fix(usd): review findings before the trade-time USD read side ships - #137
Merged
Merged
Conversation
From a strict review of af4e6e5..133fabd (#133, #136): - Community pairs are never stored (usdLedger.capturable). A pair priced from an outside pool can be pushed for a minute, and a captured price stayed in the totals for good. A suspended or delisted pair must show no USD, which a stored value defeated. Their trades keep usd NULL and count at the pair's price now, which follows its listing status. The backfill (apply) clears pair values captured since #133 and drops their ledger rows. - A launch row whose volume is partly unpriced while its quote has no price right now shows its quote amount (launchVolumeUsd: null) instead of a smaller dollar figure that looked complete. - The receipt path (applyLaunchTx, the user is waiting) no longer captures live prices: a capture could wait on Coinbase and Chainlink. Those trades take the hour's price the poller captured, or the heal pass prices them. - Heal pass (usdLedger.healUnpricedUsd), every 5 minutes per chain after a sync: - prices the last 3 days' trades and quote-side fees with no USD whose hour now has a price, and adds them to the launch totals in the same statement - skips pairs and re-tests usd IS NULL inside the UPDATE, so two machines change each row and each total once - Backfill apply is ONE transaction under the rebuild-launch-totals locks: pair cleanup, pricing and the totals recompute commit together. No reader sees rows priced but not yet summed, and a failure changes nothing. The dry run counts pairs as unpriced and stays write-free. - The lists probe one launch at a time (LATERAL u on the new partial index bb_launch_swaps_usd_missing_token_idx) instead of aggregating every unpriced trade per request. The totals' unpriced-fee read gets bb_launch_fee_events_usd_missing_idx. - scripts/rebuild-launch-totals.sql recomputes the USD totals too and reports USD drift before and after. - Wording: the tooltip and the partial note describe what has no recorded value. The backfill retries network errors and timeouts, not only 429/5xx. Deferred, not risky: the pairs pages and the token fee panel still use today's price; the volume sort mixes units during an ETH price outage (pre-existing); per-hour source labels; poolMaps / quoteUsdNow duplication. Verified on a throwaway Postgres 16 with the real migration (3 partial indexes built): - two concurrent heal passes priced the missed trade and fee once (AETH $2,000 → $6,200, not $10,400; fee $21); a rerun and a throttled run changed nothing; the pair stayed NULL - the dry run reported pairs as unpriced and changed nothing - apply (1 BEGIN / 1 COMMIT) cleared the old pair value and its ledger rows and left AETH at $6,200 - the repair script ran with 0 USD drift - the real reads: AETH $6,200, the pair row null (quote amount), sort ok, totals $6,200 and partial tsc and lint clean; npm test 1410 (1399 pass, 11 skipped, 0 fail). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Fixes from a strict review of the trade-time USD work (
af4e6e5..133fabd: #133, #136), before the read side ships.usdLedger.capturable). An outside-pool price can be pushed for a minute, and a captured value stayed in the totals forever. A suspended or delisted pair must show no USD, which a stored value defeated. Pair trades now always count at the pair's price now, which follows its listing status. The next backfill clears pair values captured since feat(usd): price every trade and fee at the time it happened #133.launchVolumeUsd).healUnpricedUsd), every 5 minutes per chain:usd IS NULLinside the UPDATE, so two machines change each row oncerebuild-launch-totals.sqllocks: pair cleanup, pricing and the recompute commit together. No window where values are priced but not summed, and a failure changes nothing. The dry run counts pairs as unpriced and stays write-free.rebuild-launch-totals.sqlrecomputes the USD totals and reports USD drift.Deferred (not risky): the pairs pages and the token fee panel still at today's price; volume-sort units during an ETH outage (pre-existing); per-hour source labels; small duplication cleanups.
Test plan
tsc, lint clean;npm test: 1410 tests, 1399 pass, 0 failnull(shows the quote amount), sort ok, totals $6,200 and partial