Skip to content

Cap USD price formatters at MAX_PRICE_E6 (was the stale 1e15) - #2498

Open
0x-SquidSol wants to merge 1 commit into
dcccrypto:playgroundfrom
0x-SquidSol:fix/format-price-cap-max-price-e6
Open

Cap USD price formatters at MAX_PRICE_E6 (was the stale 1e15)#2498
0x-SquidSol wants to merge 1 commit into
dcccrypto:playgroundfrom
0x-SquidSol:fix/format-price-cap-max-price-e6

Conversation

@0x-SquidSol

@0x-SquidSol 0x-SquidSol commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

What

Lower formatUsd / formatUsdPriceE6's absurd-value threshold from 1e15 ($1B)
to MAX_PRICE_E6 (1e12 / $1M), the corrected on-chain price cap.

Why

The formatters rejected only priceE6 > 1e15, so a dust/garbage price between $1M
and $1B (e.g. an uninitialized short liquidation price) rendered as a real dollar
figure instead of "—". Both formatters are price-scale only (prices, spreads);
large USD amounts use separate local formatUsd(number) helpers, so lowering the
cap is safe.

Changes

  • format: import MAX_PRICE_E6 and use it as the threshold in both functions.
  • regression test: value above $1M → dash; at/below → formatted.
  • updated the existing boundary test (it asserted the old 1e15/$1B cap) to $1M.

Testing

  • npx tsc --noEmit — clean.
  • format suite + new test — 2 files, 90 tests, all pass.

Notes

  • Frontend + devnet scope; no program/keeper/mainnet changes.
  • Confirmed the lib formatUsd/formatUsdPriceE6 importers are all price-scale
    (a spread in MarketStatsCard; entry/mark/liq prices elsewhere) — no large-amount
    display uses these.

Summary by CodeRabbit

  • Bug Fixes
    • USD price formatting now consistently rejects values above the $1 million maximum.
    • Values at or below the limit—including zero and the exact cap—continue to format correctly.
  • Tests
    • Added and updated coverage for price-limit boundaries and oversized values.

…1e15

formatUsd / formatUsdPriceE6 rejected only priceE6 > 1e15 ($1B), while the
corrected on-chain price cap is MAX_PRICE_E6 = 1e12 ($1M). So a dust/garbage
price between $1M and $1B (e.g. an uninitialized short liquidation price) rendered
as a real dollar figure instead of "—". Both formatters are price-scale only
(prices, spreads) — large USD amounts use separate local formatters — so aligning
to MAX_PRICE_E6 is safe.

- format: import MAX_PRICE_E6; use it as the absurd-value threshold in both
  formatUsd and formatUsdPriceE6
- add a regression test (value above $1M -> dash; at/below -> formatted)
- update the existing boundary test to the corrected $1M cap (was asserting 1e15)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@0x-SquidSol
0x-SquidSol requested a review from dcccrypto as a code owner August 5, 2026 21:05
@vercel

vercel Bot commented Aug 5, 2026

Copy link
Copy Markdown

@0x-SquidSol is attempting to deploy a commit to the Khubair Nasir's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ab6ed589-7f13-4bda-8c3f-da6d077d2eef

📥 Commits

Reviewing files that changed from the base of the PR and between f2a3bbe and 9a7bb13.

📒 Files selected for processing (3)
  • app/__tests__/lib/format-price-cap.test.ts
  • app/__tests__/lib/format.test.ts
  • app/lib/format.ts

📝 Walkthrough

Walkthrough

The formatter now uses the shared MAX_PRICE_E6 limit. Tests verify rejection above the limit and formatting at, below, and at zero.

Changes

USD price cap

Layer / File(s) Summary
Apply the shared price cap
app/lib/format.ts
formatUsd and formatUsdPriceE6 now use MAX_PRICE_E6 instead of duplicated thresholds.
Verify cap boundaries
app/__tests__/lib/format-price-cap.test.ts, app/__tests__/lib/format.test.ts
Tests cover values above the cap, the exact cap, valid lower values, and zero.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: dcccrypto, v1ktorrr0x

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: replacing the stale USD formatter threshold with the shared MAX_PRICE_E6 cap.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dcccrypto dcccrypto left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Correct — and the first PR in this batch whose tests actually bind the fix.
Suite: 2921 passed / 0 failed.

I checked the "price-scale only" claim exhaustively, because it's the one that bites

Lowering a display threshold from $1B to $1M turns any larger value into , so
a single large-amount consumer would visibly break. Every call site:

Uses the lib/format bigint formatUsd — both price-scale:

site argument
MarketStatsCard.tsx:141 absSpread (bigint price spread)
no others

Every formatUsdPriceE6 site is an entry / mark / index / liquidation /
slippage-bound price. All price-scale.

Large USD amounts all go through different functions — six separate local
formatUsd(n: number) helpers, untouched by this change: stake/page.tsx:105
(TVL, stake, pool caps), ProtocolStatsBar.tsx:29 (24h volume, open interest),
LpPositionsPanel.tsx:11 (TVL, redeemable), StatsBar.tsx:6,
TradeHistory.tsx:29, plus the exported lib/market-meta.ts:41.

One that looks like a counter-example and isn't: app/trade/[slab]/layout.tsx:24
calls formatUsd(market.price) — but it imports from @/lib/market-meta, the
number version, not this one. Worth naming explicitly since a grep for
formatUsd( surfaces it right next to the real ones.

So the claim holds. No consumer regresses.

The cap now agrees with the on-chain guard, which is a stronger argument than the PR makes

MAX_PRICE_E6 isn't just "a smaller number" — it's the bound the rest of the
stack already treats as the validity edge:

lib/oraclePrice.ts:16       if (priceE6 > MAX_PRICE_E6) return 0n;
lib/live-market-state.ts:104 if (e6 > 0n && e6 < MAX_SANE_PRICE_E6) markPriceUsd = 

A price above $1M is already discarded upstream, so the formatter was the only
layer still willing to render it. This isn't tightening a display policy — it's
removing a disagreement between the formatter and everything that feeds it. Worth
putting in the PR body; it's the reason this is safe rather than merely narrow.

Tests — first time in this run I have nothing to complain about

I reverted both thresholds to 1_000_000_000_000_000n (the bug fully restored):

test result
format-price-cap.test.ts (new) 1 of 2 fails
format.test.ts (updated) 1 fails

Both catch it. And the edit to the existing test is a strengthening, not an
accommodation — it moves the boundary assertion to the new cap and adds a
formatUsd(1_000_000_000_001n) === "$—" case that didn't exist before. That's
the right way to touch an existing assertion: when a PR edits a test it didn't
write, the question is whether the test got weaker, and here it got sharper.

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