fix(#522): scale pair tape to human quote-per-base and persist USD #1055

Merged
PlasticDigits merged 1 commit from fix/522-pair-price-usd into main 2026-08-15 12:00:01 +00:00
PlasticDigits commented 2026-08-15 11:52:32 +00:00 (Migrated from gitlab.com)

Closes #522

Summary

  • Indexer now stores human quote-per-base in swap_events.price (raw × 10^(decimals_base − decimals_quote)) and USD of 1 human base in swap_events.price_usd via the #515 catalog (UST1 = $1, cUSTC/USTC, LUNC, USTR = 2.5× USTC).
  • Trade / Charts / pair Open–Close / limit escrow Price (USD) use price_usd / *_usd — they no longer pass trades[0].price as dollars.
  • Migration backfills historical prices and rebuilds candles so mixed-decimal history is not permanently T-scaled.

Scale note: the issue text had 10^(decimals_quote − decimals_base). That exponent is inverted. UST1(6)/USTR(18) raw ≈7.97e13 becomes human ≈79.72 only with 10^(6−18).

Test plan

  • cd indexer && cargo test --lib pair_price_usd swap_orientation
  • cd indexer && cargo test --test swap_price_human_usd --test swap_price_orientation -- --test-threads=1
  • Frontend pairPriceUsd + Charts/Trade/Limits page tests
  • make verify-issue-522 (pass, then retest pass)
  • After indexer migrate/restart on columbus-5: UST1/cUSTC and UST1/USTR Price (USD) ≈ $1 on dex.cl8y.com
  • Confirm USTC oracle is populated so USD backfill is not NULL

Acceptance (#522)

  • Indexer + frontend so UST1/cUSTC and UST1/USTR can show ~$1 (6/6 and 18/6 fixtures)
  • Same USD helper on Trade, Charts, pair Open/Close, limit escrow headline
  • Mixed-decimal + same-decimal indexer tests; frontend 18/6 fixture
  • Migration backfills prices + rebuilds candles (needs prod indexer migrate/restart)
  • Live dex.cl8y.com visual confirm (needs deployed indexer)

Limit-order mode box on the issue was unchecked; the code path now uses the same USD helper, but it is not live-verified.

Docs / skills

  • Invariant row in docs/indexer-invariants.md
  • Playbook skills/AGENTS_INDEXER_PAIR_PRICE_USD.md (P522-1–P522-5)
  • Crosslinks: AGENTS.md, price chart, limit-order price, UST1 secondary AMM, external oracle
  • make verify-issue-522

Related: #466, #515, #508

Closes #522

Closes #522 ## Summary - Indexer now stores **human** quote-per-base in `swap_events.price` (`raw × 10^(decimals_base − decimals_quote)`) and **USD of 1 human base** in `swap_events.price_usd` via the #515 catalog (UST1 = $1, cUSTC/USTC, LUNC, USTR = 2.5× USTC). - Trade / Charts / pair Open–Close / limit escrow **Price (USD)** use `price_usd` / `*_usd` — they no longer pass `trades[0].price` as dollars. - Migration backfills historical prices and rebuilds candles so mixed-decimal history is not permanently T-scaled. **Scale note:** the issue text had `10^(decimals_quote − decimals_base)`. That exponent is inverted. UST1(6)/USTR(18) raw `≈7.97e13` becomes human `≈79.72` only with `10^(6−18)`. ## Test plan - [x] `cd indexer && cargo test --lib pair_price_usd swap_orientation` - [x] `cd indexer && cargo test --test swap_price_human_usd --test swap_price_orientation -- --test-threads=1` - [x] Frontend `pairPriceUsd` + Charts/Trade/Limits page tests - [x] `make verify-issue-522` (pass, then retest pass) - [ ] After indexer migrate/restart on columbus-5: UST1/cUSTC and UST1/USTR Price (USD) ≈ $1 on dex.cl8y.com - [ ] Confirm USTC oracle is populated so USD backfill is not NULL ## Acceptance (#522) - [x] Indexer + frontend so UST1/cUSTC and UST1/USTR **can** show ~$1 (6/6 and 18/6 fixtures) - [x] Same USD helper on Trade, Charts, pair Open/Close, limit escrow headline - [x] Mixed-decimal + same-decimal indexer tests; frontend 18/6 fixture - [x] Migration backfills prices + rebuilds candles (needs **prod indexer migrate/restart**) - [ ] Live dex.cl8y.com visual confirm (needs deployed indexer) Limit-order mode box on the issue was unchecked; the code path now uses the same USD helper, but it is not live-verified. ## Docs / skills - Invariant row in `docs/indexer-invariants.md` - Playbook `skills/AGENTS_INDEXER_PAIR_PRICE_USD.md` (P522-1–P522-5) - Crosslinks: `AGENTS.md`, price chart, limit-order price, UST1 secondary AMM, external oracle - `make verify-issue-522` Related: #466, #515, #508 Closes #522
PlasticDigits commented 2026-08-15 11:52:41 +00:00 (Migrated from gitlab.com)

marked this merge request as ready

marked this merge request as **ready**
PlasticDigits commented 2026-08-15 11:59:54 +00:00 (Migrated from gitlab.com)

mentioned in issue #522

mentioned in issue #522
PlasticDigits commented 2026-08-15 12:00:01 +00:00 (Migrated from gitlab.com)

mentioned in commit 8ff700ee20

mentioned in commit 8ff700ee20c7ddd2ac17eea8368316b5ab3522e8
PlasticDigits (Migrated from gitlab.com) merged commit 8ff700ee20 into main 2026-08-15 12:00:01 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
code/cl8y-dex-terraclassic!1055
No description provided.