fix(trading): use >5% order slippage or >10% total deviation for risk warnings and reduce alert fatigue #1560
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#1560
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 requested behavior
The trading form raises a red fair-reference warning for an otherwise ordinary quote with expected order slippage 3.34%, trading fee 1.71%, and total fair-reference deviation 6.91%. This creates warning/confirmation fatigue and conflicts with the cognitive-load policy. These are three different metrics; adding the displayed slippage and fee is not the total reference comparison.
Use one consistent warning/review rule across Swap and shared Trade market execution:
This is a targeted change to warning and ordinary review policy, not a general removal of safety controls. The companion #1561 mobile layout and inline-status issue handles rendering.
Current codebase and investigation
Inspected main at b7b08736; the remote main revision matched during investigation on 2026-10-19. Evidence here is sanitized source analysis; no reporter identity, conversation, account, wallet, or attachment is published.
frontend-dapp/src/utils/swapPayAcquireGuidance.ts:SWAP_FUNDED_HIGH_IMPACT_PCT = 5; funded guidance classifiesexpectedSlippagePctabove this aggregate threshold as high impact.frontend-dapp/src/components/swap/SwapImpactAside.tsx: only receivesrouteSlippagePct; uses that 5% constant to emitFair-reference deviation ...withrole="alert". It cannot currently distinguish low order slippage from aggregate loss/reference divergence.frontend-dapp/src/pages/SwapPage.tsx:expectedSlippagePctresolvesrouteSlippagePercentwith a legacy worst-hop fallback. The same >5 aggregate check appears in notice selection, CTA first-click review, and the mutation guard. Updating only the visual component would leave extra confirmation and inconsistent refusal behavior.frontend-dapp/src/components/trade/TradeMarketOrderPanel.tsx: duplicates the >5 aggregate check inneedsImpactConsent, notice selection, review binding, and submission.frontend-dapp/src/utils/routeOrderMetrics.ts: independently validates selected-route fee-free economics and returns signedorderSlippagePercent; its integer ratios are converted to JavaScript numbers. That advisory display number is not yet a safe exact boundary predicate.frontend-dapp/src/utils/swapRouteSlippage.ts:preciseFairDeviationPercentandformatTradingPriceDifferenceexplicitly protect 5/30/99 boundaries; a new 10% transition needs exact handling too.swapQuoteAmountScale.tscontains the independent 30/99 submit rules.indexer/src/api/local_quote/order_economics.rsand the frontend validator already distinguish fee-free order movement from trading/tax/hook/wrapper/reference components. Preserve that contract rather than relabeling the aggregate.Related policy-noise audit findings to address in this bundle:
Nonefor settled no-notice states. Audit transition announcements for duplicate/interruption noise; keep stable reserved geometry without an always-visible no-error message. Announce meaningful state changes once, not on identical background refreshes.slippageSeverityClassmarks values >1% amber, andINDEXER_WALLET_AMOUNT_MISMATCH_WARN_PCTis 0.1%; neither currently has production callers found in this checkout. Record this distinction; do not claim these inactive helpers caused the reported warning or mechanically weaken unrelated validation. Audit any active equivalents before adding new thresholds.ToastContext.tsxhas a 6000ms timer, but both Swap and Trade settoastOnError: falseand retain inline errors. Do not replace these persistent failures with a timed toast. Check duplicate notifications for the touched flows rather than changing unrelated pages speculatively.Relevant tests/policy:
SwapImpactAside.test.tsx,SwapPage.test.tsx,SwapPage.acquireGuidance.test.tsx,TradeMarketOrderPanel.submitSnapshot.test.tsx,swapRouteSlippage.test.ts,routeOrderMetrics.test.ts,utils/tradingNotice.ts,docs/design-system.md,docs/route-solver.md,skills/AGENTS_ORDER_SLIPPAGE.md,skills/AGENTS_ROUTE_COST_ATTRIBUTION.md,skills/AGENTS_SWAP_LAYOUT.md, andskills/AGENTS_FRONTEND_COPY_COGNITIVE_LOAD.md.Source entry points: SwapImpactAside.tsx, swapRouteSlippage.ts, routeOrderMetrics.ts.
Why a new implementation is needed
The previous 5% rule measured total fair/net difference, while the current headline now measures fee-free order slippage. Using the old aggregate threshold for every ordinary warning makes the lower, correctly separated order metric appear inconsistent and makes red errors routine. A single policy evaluator and consistent review behavior are needed so the visible reason, required acknowledgement, and final guard agree.
Recommended direction and guardrails
toFixed, binary floats, tolerance settings, worst-hop spread, or server-provided labels. Extend validated evidence only if needed; do not trust an unvalidated diagnostic as a signing authority.Acceptance criteria
order >5 OR total >10with exact strict boundaries.Test plan: functional paths
Test plan: attacks, hacks and abuse
orderSlippagePercent, strip/alter original order economics, change raw denominators/signs, mismatch hops/generation/direction/account or pair identities, and replay accepted review on a new quote. Reject or remain unavailable without lowering actual risk.Verification criteria
Run updated
make verify-issue-1500,make verify-issue-1498, and applicableverify-issue-1483,1489,1473,1480,1452regression suites, plus frontend types/lint and a production-build Swap/Trade browser check. Verify against the explicit truth table rather than retaining tests that encode the old policy. Run accessibility checks on touched flows and capture sanitized before/after metrics, notice count and review outcomes on the final revision.Executed failures remain failures; unavailable live/device/funded checks are explicitly listed with their scope and do not block filing this issue. Source or synthetic-browser passes do not prove deployed or funded acceptance. No conversation screenshots, reporter data, credentials or wallet/session identifiers belong in receipts. The implementation can proceed without re-requesting product approval for the thresholds specified here.
Related work: #1498 stable layout, #1500 distinct order metrics, and #1330 executable-route presentation. This follow-up does not expand route search or replace net-output ranking.
Investigation verification receipts (2026-10-19)
make verify-issue-1500: FAIL overall on the unmodified revision. First and retest each passed 6 independent order-economics tests, 1 manual-split identity test, and 143 frontend tests in 8 files; frontend types and invariant/documentation checks passed.cargo fmt --checkfailed inindexer/src/api/local_quote.rsandindexer/src/db/queries/hub_prices.rsunder rustfmt 1.10.0. This existing formatting failure is retained, not reclassified as a skip or repaired as part of issue filing. Two declared deployed/funded/device scopes remain unverified.make verify-issue-1498: PASS WITH SKIPS, 9 passed / 0 failed / 1 skipped. First/retest each passed 145 frontend tests in 8 files; the production-build geometry fixture passed 9 scenarios at each of 1440/320/390/430 widths with height 1000, including 200% root text, and types/crosslinks/stable-source checks passed. The declared live-artifact/device/funded scope was skipped. These passes do not exercise the missing 375×667 initial-CTA criterion.Implemented, tested and deployed through PR #1562; PR #1563 records live evidence and fixes the release observer. Frontend deployment
qvplhwapjhqfxd2mm8lfnzuafinished at6a5118ffc2a3bf71b4ad638226d48228bd2eb64a.Completed implementation criteria, within the recorded automated scope:
Live native USTC→CL8Y Swap and wrapped Trade previews pass with no risk notice on the sampled low-risk quotes, zero runtime errors and zero serious/critical axe findings. This does not claim a fresh reproduction of the historical 3.34% quote. Fresh Grafana/Loki/Prometheus checks pass for both exact DEX jobs; API health/serving stayed HTTP200 and backend source is unchanged. Indexer readiness was separately 0 in the final monitoring sample and is retained independently. Coolify started the new frontend at 04:21:33 UTC before removing old containers at 04:21:38 UTC; no outage was observed.
Remaining acceptance:
Both issues remain open because the full verification criteria are not all proven. Physical phone reachability is assigned in cl8y-pm Inbox, card
3fff415d-9cc2-42b1-b635-37e0be4fd0f7, with no transaction signing requested. Results, screenshots, failed loops/retests and exact skipped scopes.Follow-up correction: the previous release still rendered the checked None status despite the audit's stated intent. PR #1564, now deployed, makes the quiet placeholder empty and aria-hidden; real pricing/blocking states retain their announcements. The related mobile footer/centering and compact right-aligned route corrections are live too.
Risk thresholds, original reviewed expiry, pinned consent and execution guards are unchanged. Relevant source tests and live native Swap/wrapped Trade previews pass; zero runtime errors and serious/critical axe findings. Live evidence and precise remaining scope. Full funded/physical/CI acceptance remains unverified; keep this issue open.
PR #1566 implements both follow-up reports: compact all-device error leading, with inline Expert/Cancel actions that retain 44px hit targets; and direction switching that moves the exact current receive amount into the new pay field. Example: 10 CL8Y → 5.40572 SpaceUSD becomes 5.40572 SpaceUSD input for the reverse quote. Missing/expired output clears rather than carrying the old denomination. Old book budgets/review consent are cleared; signing safeguards stay enforced.
Verification checklist:
Exact 6/18-decimal and >2^53 amounts, original expiry, stale drafts/refresh, receive edits and long-value editing.
186 Swap/layout tests and 171 metric tests on each verifier run, 161 Trade tests; types, focused lint and normal commit hooks.
Source-matched production browser status at 375/768/1440 widths: 16.2px leading on 12px text, 32.4–46.3px tested status heights, actual 44px hit tests, keyboard Expert modal/focus return, zero serious/critical axe findings.
Compact mobile centering/footer/route spacing, connected CTA clearance and 200% text regressions.
Coolify frontend
bd2b4ba508d08bf8632b164c82ae02cff1284be0, deploymentwezykqhxcuhuvdilkmbyogla, finished. Public frontend/API health/serving samples stayed HTTP200; backend unchanged.Live phone/desktop switch: output
0.851568201759174334became new pay, reverse request raw851568201759174334, HTTP200. Compact status leading/minimum 16.2/32.4px; mobile footer hidden, form centered and route flush-right. No runtime errors or serious/critical axe findings; wrapped Trade preview also passed.Deployment logs reviewed: 75 entries, two exact cleanup messages. The conservative checker’s one additional keyword FAIL was the exact public merge subject containing “error spacing”; retained and independently classified, with no remaining error tokens. No unexpected deployment fault found.
Fresh exact DEX Prometheus targets and Loki/Grafana observations, plus monitoring source/config verifier 1544. API serving/quote-readiness up; indexer readiness independently 0, so no recovery or traffic-SLO claim.
Full physical-device/funded/all-states acceptance and full repository CI. The explicit user-authorized CI gate override was used while CI was pending; CI is not claimed PASS. Keep both issues open. Physical reachability remains assigned in PM Inbox, card
3fff415d-9cc2-42b1-b635-37e0be4fd0f7.Relevant #1561 criteria verified in the stated scope: AC1/AC7 numerical initial CTA/nav bounds; AC3 compact persistent error and keyboard action; AC4 real full native route; AC5 geometry/one DETAILS/no horizontal overflow; AC6 covered desktop browser keyboard/200% text/accessibility checks. Physical devices and the full matrix remain incomplete. The #1560 risk thresholds, original quote deadlines, raw amounts, floors and offline/signing protections remain enforced.
Invariants, verification scope, live receipts and screenshots and exact direction amount checklist. Agent guidance crosslinked in SL1498 and QL1499. No backend, database or chain reset needed for this frontend-only follow-up.