bug(trade): missing USD fallback double-scales USTR headline by 10^12 #1512
Labels
No labels
agent:fix_bugfix
agent:fix_conflicts
agent:fix_security
agent:gap_analysis
agent:implement
agent:implement
agent:implement
agent:open_issues
agent:ready
agent:research
agent:security_audit
agent:verify
architecture
backend
blocker:hybrid
blocker:launch
blocker:limit-orders
blocker:v2
block:log_only
block:security
bug
ci
contracts
correctness
deploy
dev
devops
docs
documentation
duplicate
e2e
enhancement
epic
feature
frontend
functional-completion
gas
good first issue
governance
help wanted
high-risk
hooks
hybrid
indexer
infra
infrastructure
integrators
invalid
launch-blocker
limit-orders
localnet
localterra
low priority
missing-implementation
needs-design
ops
performance
priority
high
priority
medium
product
qa
QA
question
ready
ready
research
scripts
security
security-hardening
smartcontracts
tech-debt
testing
ux
UX
v2
verification
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
code/cl8y-dex-terraclassic#1512
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem and why a new implementation is needed
Trade's USTR/UST1 Price (USD) LAST headline can display approximately
0.00000000000001214while the USD candles are around0.005–0.006. The current mixed-decimal fallback double-scales an already humanized trade price whenprice_usdis absent. It also synthesizes USTR USD from a legacy 2.5×USTC assumption, masking the actual absence of a qualified USD mark.Fix the shared price contract and all affected Trade/Charts callers together. This is a deterministic presentation/data-integrity defect, separate from the USTR hub's fixed-reference divergence and missing protocol LP valuation tracked in #1511. It becomes visible when an otherwise normal current trade lacks
price_usd, including during guarded hub rejection. Do not "fix" it by displaying any plausible number or borrowing a stale candle as current USD.This report contains anonymized technical findings and synthetic scalar reproductions only. No supplied conversation/screenshot, reporter identity, real-user wallet or transaction is published.
Investigation baseline and independent reproduction
Source:
c3e216842fe3bac00e2c71bb967950e004b3a6cf, matching the live backend/healthrevision on 2026-10-15. Frontend deployment artifacts have not been separately attested.Public pair metadata confirms the canonical UST1/USTR pair
terra16vxrhpvpcucu05y0nr862vf9hnqeh274uaff4s7hz4n0ea74006qf5hgqyhas UST1 asset_0/6 decimals and USTR asset_1/18 decimals. A bounded public trades read returned a latestprice:"160.756280899197382191"withoutprice_usd; its raw amounts corroborate thatpriceis already human token1/token0. Prior rows containprice_usd; USD candles expose separate human-ratio fields. Only these non-identifying scalars are retained here.The actual source helper was loaded through Vite SSR and called twice, with the same results:
Derivation in current code:
160.756… × 10^(6−18) × (2.5 × 0.0048565), followed by division by160.756…for display inversion. The decimal conversion introduces a factor of10^-12; the result exactly explains the reported tiny headline.2.5 × USTCis a legacy comparison, not an accepted USTR price or an expected safe replacement. With an explicitly supplied synthetic factorypriceUsd:'0.849756570385773539', the same helper returns0.005285992968, demonstrating the different indexed-USD and missing-USD branches. This arithmetic comparison does not certify live fair value.Current codebase and relevant files
TapeUsdInput.priceandresolveTapeLastPriceUsdassume missing-USD input is a pre-#522 raw ratio, multiply by10^(d0-d1), and usequoteTokenUsd. That helper returns UST1=$1 and USTR=2.5×USTC from symbol classification.resolveDisplayTapeLastPriceUsdthen treatsopts.priceas human when callinginvertUsd, so the same field has incompatible units across branches.price, optionalprice_usdand pair decimals into this helper. TraceChartsPage.tsxand every shared-helper caller as well; establish rather than assume each affected surface.frontend-dapp/src/utils/limitOrderPriceReference.ts::tradeToToken1PerToken0Humanalready reconstructs human factory ratio from raw amounts/decimals;pairPriceUsd.ts::resolveTapePriceUsduses that path for tape rows. Unify explicit units without changing factory execution semantics.frontend-dapp/src/utils/tradePairDisplayOrientation.ts::invertUsdexpects factory USD divided by a human token1/token0 ratio.components/charts/priceChartCandles.tsuses per-bar USD/human fields independently.indexer/src/indexer/pair_price_usd.rs,indexer/src/indexer/parser.rs,indexer/src/api/pairs.rs::trade_response_from_swap_row, andindexer/src/db/queries/swap_events.rsestablish the modern humanpriceand optional factory-asset_0price_usdcontract; do not revert the server/storage to the legacy raw representation.frontend-dapp/src/utils/__tests__/pairPriceUsd.test.tscovers the old raw fallback and human inversion separately but misses modern human price + absent USD + mixed decimals + inversion.TradePage.test.tsx,ChartsPage.test.tsxand chart/tape tests need end-to-end coverage of that combination.Related history: #522, #524, #543, #556. These older fixes do not cover the reproduced missing-USD branch.
Recommended direction
price_usd.price_usdis not evidence of an old indexer. Return honest unavailable USD when no eligible source exists. Remove/quarantine the UST1 peg and USTR multiplier from current-data fallback paths; do not introduce new request-triggered oracle/chain reads.Constraints and guardrails
Acceptance criteria
10^12; without a qualified USD source it returns unavailable, not a synthetic peg-derived number.Test plan: all functional and failure paths
price_usdis USD of human asset_0 or absent; missing hub price does not change price units. Preserve decimal/human candle fields and original timestamps.Test plan: attack, hack and abuse vectors
Verification criteria and investigation checks
The actual helper reproduction returned the same failing
1.21412500000e-14on first/retest. The initial SSR probe completed these calls but emitted a dependency-scan shutdown error; a subsequent probe disabled dependency discovery and repeated the calls cleanly. Preserve the reproduced product failure independently of test-runner setup.make verify-issue-524passed all 10 groups, including 181 tests in its main seven-file suite. This demonstrates the existing coverage gap; a green legacy suite is not evidence that this bug is fixed. After implementation add the missing regression, show it failing on the original source and passing on the final source, rerunmake verify-issue-524and relevant 522/543/556/680 chart regressions, run frontend types/lint and any changed backend contract tests. Record exact revision/UTC/commands/counts, first/retest and separately attested deployed frontend/backend artifacts. Desktop/phone screenshots may be newly generated from anonymous test fixtures; do not publish supplied private evidence. Unavailable deployment/device/funded checks remain explicitly unverified and do not block creating or implementing this issue.The missing-USD display fix and focused acceptance are merged through PR #1537 and PR #1542, final main
5b623a04f35bb6b44d3e64df0014e458cad653fc; genuine CI526 passed. Leaving open: the full requested API/abuse/execution matrix remains incomplete.1.21412500000e-14); it fails before and returns unavailable after. Modern ratios remain human asset_1/asset_0; matching indexed historical asset_0 USD is inverted exactly once. Missing USD cannot select legacy raw, UST1 peg, USTR multiplier, ticker/oracle, stale-last-good or candle-close fallback.These browser cases observed frontend
2df4a471a9ca98a8672d911b67d4bd8134f411fdwhile the backend was prior0a3c251755a88ee9cbbbbc222fc747811c9da08c. The frontend remains 2df; backend 5b is now separately deployed and attested, with 55 HTTP200 / zero failures during bounded rolling continuity checks. The earlier price cases were not repeated or misrepresented as post-rollout tests. Initial timer/selector/budget failures and the four raw PASS race attempts lacking browser-completion proof remain retained with explicit qualifications; only corrected completion-witness cases establish delivered-response acceptance. No wallet/signing, screenshots or raw actor/trade export occurred.Unit/provenance invariants, source results, deployed checklist, race/reload receipts and coverage audit. This display repair adds no request-triggered chain/oracle reads or signing permission. Complete the remaining matrix before closure.
Final release evidence and checked acceptance lists: #1543, release checklist in #1543. The exact serving backend remains
5b623a04; this final publication changes documentation only.