fix(swap): explain fair-reference deviation on native wrap routes and suggest wrapped-token alternative #1579

Open
opened 2026-10-29 00:26:43 +00:00 by PlasticDigits · 0 comments
Owner

Summary and reported behavior

An anonymized mobile report shows a native-input Swap route:

USTC → cUSTC → cLUNC → LUNC

with:

  • Slippage <0.01%
  • Fee 1.76%
  • a red Fair-reference deviation 11.32% notice
  • the SWAP button still available

The reporter asked why the deviation is so high when displayed slippage is near zero. The expected answer is that this figure is not order slippage: it includes independent-reference divergence, wrapping/unwrapping loss, chain tax and trading costs. The current UI shows only the aggregate percentage, so a legitimate route looks broken or deceptive. A second, related product request was to recommend receiving/holding the wrapped asset (for example cLUNC instead of LUNC) when the notice is caused by native wrap/unwrap costs, because wrapped assets let active traders avoid paying chain tax on every swap.

This issue bundles the explanation fix and the wrapped-asset advisory. It does not change the risk thresholds or execution policy.

No reporter identity, conversation, screenshot, wallet address, balance or transaction history is included here. The percentages above are the sanitized technical facts needed to reproduce the UI path.

Current codebase

Source reviewed at 38c154958c9eb27a683a27c8dbaa121ccdb83da6 (2026-10-28).

The explanation is computed, validated, passed — and dropped

  • frontend-dapp/src/utils/routeEconomicExplanation.ts validates the original economic_attribution schema (version, status, method, generation, observed_at_ms, expires_at_ms, fair_amount_out, net_amount_out, exact four signed components, exact dominant cause) and returns a fixed, allowlisted string such as Wrapping costs, Trading costs, Selected pool price movement, Independent reference and selected route spot prices differ, Combined costs and pricing, or Matches reference prices.
  • frontend-dapp/src/utils/cw20RouteSolveQuote.ts:116-135 and :248-263 attach that string as economicExplanation to both wrapper-only and general route quotes, alongside orderCosts, spotAmountOut and routeSlippagePercent.
  • frontend-dapp/src/pages/SwapPage.tsx:2102-2115 passes simData?.economicExplanation into SwapImpactAside for the higher-risk notice, and :2213-2220 passes it again for DETAILS.
  • frontend-dapp/src/components/trade/TradeMarketOrderPanel.tsx:952-956 and :1125-1133 do the same for the shared Trade market notice and DETAILS.
  • frontend-dapp/src/components/swap/SwapImpactAside.tsx:5-25 declares economicExplanation?: string but never destructures, renders or uses it. Only routeSlippagePct and tradingRiskNotice() are rendered.

So the documented compact cause explanation is dead data. The prop is accepted and silently ignored.

The documented contract already requires this behavior

docs/route-solver.md:62-67 states:

Actual Swap and Trade use the plain Price difference label and a compact fixed cause explanation only after client schema/reconciliation/quote binding checks.

That contract was implemented around the route-cost work in #1483, refined by #1500, and narrowed by #1560. The current component no longer renders the cause, and existing tests do not catch the regression. SwapImpactAside.test.tsx only covers percentages, thresholds, confirmation and unavailable evidence.

The backend attribution is already sufficient for truthful copy

  • indexer/src/api/local_quote/attribution.rs:55-105 computes signed wrapper_loss, trading_cost, market_movement and reference_divergence in common final-output units. They telescope exactly to fair_amount_out - net_amount_out.
  • indexer/src/api/local_quote/order_economics.rs:61-103 maps those components into wrapper_cost and reference_divergence for the order-cost breakdown.
  • indexer/src/api/local_quote.rs:1394-1419 computes the independent fair output from authorized gross native input and retains wrapper loss once for native wrap/unwrap routes.
  • frontend-dapp/src/components/swap/RouteOrderCostDetails.tsx:16-35 already renders Trading fees, Tax and hook costs, Wrapping costs and Reference price difference inside DETAILS.

The backend can legitimately report a large aggregate for a native-wrap route whose selected pool spot differs from the independent reference and whose unwrap loses chain tax. That is a real economic difference, not an arithmetic failure. The defect is that the user-facing notice does not say so.

The client already has enough information for a wrapped-asset advisory

  • frontend-dapp/src/types/index.ts:988-995 exposes getWrappedEquivalent / getNativeEquivalent.
  • frontend-dapp/src/utils/constants.ts:143-154 maps uluna → cLUNC and uusd → cUSTC, omitting unconfigured addresses.
  • execution_metadata.wrapper already distinguishes wrap_input and unwrap_output, and token_in / token_out identify the requested assets.
  • simData.orderCosts already separates wrapper cost from reference divergence.

No new RPC, quote request, route selection or signing path is needed.

Why the new implementation is needed

  1. A trader cannot distinguish “the selected pool is genuinely worse than the reference” from “the UI is charging hidden slippage”. An unexplained 11.32% red notice next to <0.01% slippage looks like a defect and invites abandonment to another DEX.
  2. Native LUNC/USTC routes intentionally pay chain tax and wrap/unwrap fees. The aggregate fair-reference metric correctly includes them, but the user needs a short cause and a clear statement that these are not slippage.
  3. Active traders can legitimately avoid repeated chain tax by holding/trading cLUNC / cUSTC inside the DEX. The current warning does not surface that option, even though the route context already shows native wrap/unwrap.
  4. The documented “compact fixed cause explanation” contract is currently broken. Leaving the prop dead means future changes can keep adding validated diagnostics that never reach users.
  5. A naive fix that lowers the percentage, hides the warning or switches assets automatically would violate the risk policy. The implementation must explain the existing truthful number without weakening any gate.

1. Render the validated cause inside the existing notice/DETAILS

Use the already-computed economicExplanation only when the same quote evidence has passed the existing checks:

  • In the higher-risk SwapImpactAside notice, add one short static cause clause after the required risk sentence, for example: Fair-reference deviation 11.32%. Mostly wrapping and reference-price difference, not slippage. Keep it to one notice and one live-region announcement.
  • In DETAILS, show the cause next to the percentage and keep the existing RouteOrderCostDetails raw cost list. Do not duplicate or re-derive amounts.
  • Map the fixed backend causes to short retail copy in one place. Never render arbitrary backend text.
  • When economicExplanation is unavailable or invalid, render nothing extra. The required risk notice and all gates remain.

Do not call the aggregate “slippage”. Use “fair-reference deviation” consistently with the current risk policy, and state that network gas is separate.

2. Add a bounded native-wrap advisory

When the selected quote is a supported native route and the validated cost breakdown shows that wrapper_loss and/or reference_divergence dominate the aggregate, add a concise informational line, for example:

Planning to keep trading here? Receiving cLUNC instead of LUNC avoids unwrapping and repeated chain tax on later swaps.

Rules:

  • Only show the advisory for supported native→wrapped or wrapped→native legs using getWrappedEquivalent / execution_metadata.wrapper.
  • Suggest the wrapped asset only when it is actually configured, listed and part of the route context.
  • Never auto-change from / to or the exact input; provide no one-click destructive substitution unless separately reviewed. A plain text hint is sufficient for this issue.
  • Do not make a numeric “save X%” claim unless the exact incremental saving is available from validated evidence. If a number cannot be proven, use qualitative wording.
  • Suppress the advisory when the output is already the wrapped asset, when there is no native leg, when attribution is unavailable, or when the suggested wrapped asset is missing/disabled.
  • The advisory is informational only, never a signing permission, and must not alter ranking, consent, Expert or ≥99% refusal.

3. Preserve the existing risk and accessibility contract

  • Keep evaluateTradingRisk, exact 5/10/30/99 boundaries and assertTradingRiskForSubmit unchanged.
  • Keep one concise named notice; no second live region, no timed toast, no extra confirmation click added by the explanation or advisory.
  • The advisory must not be announced repeatedly on identical refreshes. Keep stable text stable.
  • Ensure the additional line fits at 320–430 px widths without overflowing the fixed CTA/footer layout.

4. Update the contract and tests so this cannot silently regress

  • Update docs/route-solver.md, skills/AGENTS_ROUTE_COST_ATTRIBUTION.md, skills/AGENTS_TRADING_RISK.md, skills/AGENTS_ORDER_SLIPPAGE.md and the relevant QA checklist with the “cause + wrapped alternative” presentation and its advisory-only status.
  • Add component tests that assert the passed explanation is actually rendered and that an invalid/unavailable explanation remains silent.

Constraints and guardrails

  • Do not change route ranking, reference admission, the $10 economic-total / $100 hub-depth floors, slippage tolerance, max_spread, floors, funding or signing.
  • Do not weaken or add a waiver to the >30% Expert or ≥99% nonwaivable rules. Do not change ordinary order >5% OR total >10%.
  • Do not lower or hide a legitimate fair-reference deviation merely to make the UI quieter.
  • Cause copy must come from the fixed allowlist after the existing client schema/reconciliation/quote-binding checks. No raw backend enum, provider string, symbol HTML or user-controlled text.
  • Advisory copy must not claim a savings amount unless the amount is independently available from validated evidence. Native chain tax and wrapper fees must be described as separate from network gas.
  • No additional network/RPC/quote calls on render, toggle or asset change. The flow remains offline and bounded.
  • Do not recommend an unlisted, disabled, unconfigured or unrelated wrapped token. Use the exact configured wrapped equivalent of the route’s native leg.
  • Keep the existing single-notice priority: an operational blocker or unavailable risk evidence continues to win over advisory cost copy.
  • Privacy: do not render actor, wallet, conversation or screenshot data. This issue text is already anonymized.

Relevant files

Frontend:

  • frontend-dapp/src/components/swap/SwapImpactAside.tsx — dead economicExplanation prop; notice/DETAILS rendering.
  • frontend-dapp/src/components/swap/SwapImpactAside.test.tsx — missing cause/advisory coverage.
  • frontend-dapp/src/components/swap/RouteOrderCostDetails.tsx — existing raw cost breakdown.
  • frontend-dapp/src/pages/SwapPage.tsx — notice and DETAILS wiring.
  • frontend-dapp/src/pages/SwapPage.test.tsx — integration coverage.
  • frontend-dapp/src/components/trade/TradeMarketOrderPanel.tsx — shared Trade notice/DETAILS.
  • frontend-dapp/src/components/trade/__tests__/TradeMarketOrderPanel.submitSnapshot.test.tsx — Trade coverage.
  • frontend-dapp/src/utils/cw20RouteSolveQuote.ts — explanation and cost population.
  • frontend-dapp/src/utils/routeEconomicExplanation.ts — fixed allowlisted cause validator/copy.
  • frontend-dapp/src/utils/routeOrderMetrics.ts — validated orderCosts.
  • frontend-dapp/src/utils/tradingRisk.ts — must remain unchanged behaviorally.
  • frontend-dapp/src/types/index.ts, frontend-dapp/src/utils/constants.ts — wrapped/native equivalents.
  • frontend-dapp/src/utils/nativeWrapRouteSolve.ts — native wrap route context.

Backend reference (no behavior change expected unless a pinned fixture proves a defect):

  • indexer/src/api/local_quote.rs
  • indexer/src/api/local_quote/attribution.rs
  • indexer/src/api/local_quote/order_economics.rs
  • indexer/src/api/local_reference_quote.rs
  • indexer/tests/scenarios/route_cost_attribution_1483.rs

Docs/guidance:

  • docs/route-solver.md
  • skills/AGENTS_ROUTE_COST_ATTRIBUTION.md
  • skills/AGENTS_TRADING_RISK.md
  • skills/AGENTS_ORDER_SLIPPAGE.md
  • docs/qa/issue-1483/README.md, docs/qa/issue-1500/README.md, docs/qa/issue-1560/README.md

Acceptance criteria

  • AC1: A validated economicExplanation is rendered in the Swap and Trade price notice and/or DETAILS. The dead prop is either used or removed; no path silently discards it again.
  • AC2: The 11.32%-style case shows a truthful short cause (for example wrapping and/or reference-price difference) and makes clear that the number is not order slippage. The required risk percentage, confirmation, Expert and ≥99% behavior are unchanged.
  • AC3: A supported native→wrapped / wrapped→native route with dominant wrapper/reference cost shows a concise wrapped-asset advisory. The advisory names only configured listed assets and does not auto-substitute them.
  • AC4: Direct pool routes, routes already ending in wrapped assets, unsupported/missing wrapped equivalents, unavailable attribution, and operational blockers do not show the advisory.
  • AC5: No new request, RPC, quote broadcast or signing permission is introduced. Rendering, toggling DETAILS and asset edits remain offline and bounded.
  • AC6: Cause and advisory copy is allowlisted, escaped and stable; invalid/tampered attribution produces no extra copy and never a zero-cost claim.
  • AC7: Mobile layout at 320–430 px keeps the route, notice, advisory and CTA readable without overlap or horizontal overflow; screen readers hear one meaningful status transition, not repeated advisory announcements.
  • AC8: Docs/skills/QA checklists describe the cause + advisory behavior and explicitly preserve TR1560/OS1500/RC1483 risk rules.
  • AC9: Relevant frontend tests, lint/type checks and verifiers pass; unavailable live/funded/device checks are recorded as explicit SKIPs, not PASS.

Test plan — all paths

Unit / component

  • SwapImpactAside:
    • available cause with wrapper_loss → renders the cause text once.
    • available cause with reference_divergence, trading_cost, market_movement, mixed, Matches reference prices → renders the matching fixed copy.
    • unavailable explanation / malformed quote → no cause, no advisory; required risk notice still rendered.
    • ordinary low-risk quote with cause → remains behind DETAILS.
    • higher-risk quote with cause → one notice, no duplicate live region.
    • blocked="expert" and blocked="extreme" → existing copy/CTA preserved; advisory never replaces the blocker.
    • 10/30/99 exact boundaries → no text or rounding regression.
  • Native advisory helper:
    • native input only, wrapped output only, both-leg route, direct pool route, wrapped-to-native, unsupported mapping, empty configured address, same-asset route.
    • dominant wrapper/reference vs dominant market/trading.
    • unavailable orderCosts / execution_metadata identity mismatch → no advisory.
  • RouteOrderCostDetails remains the single numeric breakdown; no duplicate amounts.

Integration

  • SwapPage.test.tsx: native wrap/unwrap fixture with a large fair-reference deviation and available attribution → cause + advisory; same fixture with unavailable attribution → no advisory; direct route → no advisory.
  • TradeMarketOrderPanel.submitSnapshot.test.tsx: shared notice/DETAILS behavior, consent and Expert paths.
  • Receive-sizing / reverse-quote path: explanation and advisory bind the same original quote; changing intent clears both.
  • Quote refresh while review is open: unchanged text is stable; changed evidence revokes review as before and never preserves stale advisory.
  • Fee/Max/gas and signing review: no layout duplication, no additional gas or asset mutation.

Accessibility / visual

  • Keyboard-only: DETAILS open/close, advisory readable, no new focus trap.
  • Screen reader: one polite status for ordinary risk transition; advisory is not a second alert; stable text does not reannounce on polling.
  • Contrast and font size for the added line in light/dark themes.
  • Mobile widths 320/360/390/430 px, long token symbols and long wrapped names; no overlap with bottom navigation or fixed CTA.
  • Desktop Swap and Trade market; DETAILS open and closed.

Regression / policy

  • order >5 OR total >10 unchanged; equality unchanged.
  • Total >30 Expert and ≥99 nonwaivable unchanged.
  • Favorable order movement and favorable reference divergence still signed/symmetric.
  • Wrapper-only zero order movement still validated by validateWrapperOnlyQuote.
  • No route ranking change: selected route remains best delivered net for the exact amount.

Test plan — attack, hack and abuse vectors

  • Forged/hostile quote injects an arbitrary economicExplanation string or HTML → rejected by fixed allowlist and schema binding; rendered only as escaped text.
  • Malformed component arithmetic (sum ≠ fair − net, non-integer, overflow, negative where disallowed) → explanation unavailable; required risk notice persists; no advisory.
  • Generation/observation/expiry mismatch or stale quote replayed with new UI text → explanation and advisory suppressed; signing and review binding still reject.
  • Mismatched orderCosts, spotAmountOut, estimated_amount_out or execution_metadata.wrapper → no cause/advisory; risk evaluator remains unavailable or blocks.
  • Malicious suggestion path attempts to substitute an unlisted/hostile token or inject a URL/CTA → no substitution, no link, no external navigation; only configured wrapped equivalents may be named.
  • Social-engineering “save X%” claim → no unverified savings number; copy states qualitative chain-tax/wrapper behavior only.
  • Attempt to bypass consent/Expert/≥99 by making the explanation look like an approval or by hiding the percentage → advisory is text only and never a submit permission; assertTradingRiskForSubmit remains the final gate.
  • XSS via token symbol, pair name, wrapped symbol or route label → React text rendering, no dangerouslySetInnerHTML.
  • Very long/huge raw strings in cost fields → existing bounded validators reject or truncate safely; no layout denial of service.
  • Duplicate/adversarial refresh spam → stable text, no repeated live-region announcements, no quote-triggered RPC.
  • Privacy leak attempt via cause/advisory → no actor, wallet, conversation, screenshot or private endpoint data is ever included.

Verification criteria

Run the applicable bounded checks from the repository root:

  • make verify-issue-1560
  • make verify-issue-1500
  • make verify-issue-1483
  • make verify-issue-1498
  • make verify-issue-1452
  • make verify-issue-630 (native ticker display, because the advisory names cLUNC/cUSTC)
  • targeted frontend tests: SwapImpactAside.test.tsx, SwapPage.test.tsx, TradeMarketOrderPanel.submitSnapshot.test.tsx, routeEconomicExplanation.test.ts, routeOrderMetrics.test.ts
  • frontend lint/type/build checks and a production-browser mobile check

Record:

  • exact source commit and any served frontend/indexer artifact hashes;
  • the fixture/quote inputs and the observed cause/percentage;
  • executed failures as FAIL;
  • unavailable live, funded, device or deployment checks as explicit SKIP with overall PASS WITH SKIPS only when executed checks pass;
  • no claim that source/synthetic tests establish production deployment or funded settlement.

Do not close this issue on source-only evidence. Live acceptance requires a served Swap and Trade path with a native wrap/unwrap route, a validated explanation, the wrapped advisory, unchanged risk behavior, and mobile/assistive checks.

  • Warning threshold policy remains #1560.
  • Metric separation and cost disclosure remain #1500.
  • Attribution/reference reconciliation remains #1483.
  • Mobile notice/CTA layout remains #1561.
  • Native quote recovery / wrapper rollout remains #1505 and #1506.
  • This issue does not add a third-party DEX, multi-path splitting, a new oracle, or a change to route selection.
## Summary and reported behavior An anonymized mobile report shows a native-input Swap route: `USTC → cUSTC → cLUNC → LUNC` with: - `Slippage <0.01%` - `Fee 1.76%` - a red `Fair-reference deviation 11.32%` notice - the `SWAP` button still available The reporter asked why the deviation is so high when displayed slippage is near zero. The expected answer is that this figure is not order slippage: it includes independent-reference divergence, wrapping/unwrapping loss, chain tax and trading costs. The current UI shows only the aggregate percentage, so a legitimate route looks broken or deceptive. A second, related product request was to recommend receiving/holding the wrapped asset (for example `cLUNC` instead of `LUNC`) when the notice is caused by native wrap/unwrap costs, because wrapped assets let active traders avoid paying chain tax on every swap. This issue bundles the explanation fix and the wrapped-asset advisory. It does not change the risk thresholds or execution policy. No reporter identity, conversation, screenshot, wallet address, balance or transaction history is included here. The percentages above are the sanitized technical facts needed to reproduce the UI path. ## Current codebase Source reviewed at `38c154958c9eb27a683a27c8dbaa121ccdb83da6` (2026-10-28). ### The explanation is computed, validated, passed — and dropped - `frontend-dapp/src/utils/routeEconomicExplanation.ts` validates the original `economic_attribution` schema (`version`, `status`, `method`, `generation`, `observed_at_ms`, `expires_at_ms`, `fair_amount_out`, `net_amount_out`, exact four signed components, exact dominant cause) and returns a fixed, allowlisted string such as `Wrapping costs`, `Trading costs`, `Selected pool price movement`, `Independent reference and selected route spot prices differ`, `Combined costs and pricing`, or `Matches reference prices`. - `frontend-dapp/src/utils/cw20RouteSolveQuote.ts:116-135` and `:248-263` attach that string as `economicExplanation` to both wrapper-only and general route quotes, alongside `orderCosts`, `spotAmountOut` and `routeSlippagePercent`. - `frontend-dapp/src/pages/SwapPage.tsx:2102-2115` passes `simData?.economicExplanation` into `SwapImpactAside` for the higher-risk notice, and `:2213-2220` passes it again for DETAILS. - `frontend-dapp/src/components/trade/TradeMarketOrderPanel.tsx:952-956` and `:1125-1133` do the same for the shared Trade market notice and DETAILS. - `frontend-dapp/src/components/swap/SwapImpactAside.tsx:5-25` declares `economicExplanation?: string` but never destructures, renders or uses it. Only `routeSlippagePct` and `tradingRiskNotice()` are rendered. So the documented compact cause explanation is dead data. The prop is accepted and silently ignored. ### The documented contract already requires this behavior `docs/route-solver.md:62-67` states: > Actual Swap and Trade use the plain **Price difference** label and a compact fixed cause explanation only after client schema/reconciliation/quote binding checks. That contract was implemented around the route-cost work in [#1483](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1483), refined by [#1500](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1500), and narrowed by [#1560](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1560). The current component no longer renders the cause, and existing tests do not catch the regression. `SwapImpactAside.test.tsx` only covers percentages, thresholds, confirmation and unavailable evidence. ### The backend attribution is already sufficient for truthful copy - `indexer/src/api/local_quote/attribution.rs:55-105` computes signed `wrapper_loss`, `trading_cost`, `market_movement` and `reference_divergence` in common final-output units. They telescope exactly to `fair_amount_out - net_amount_out`. - `indexer/src/api/local_quote/order_economics.rs:61-103` maps those components into `wrapper_cost` and `reference_divergence` for the order-cost breakdown. - `indexer/src/api/local_quote.rs:1394-1419` computes the independent fair output from authorized gross native input and retains wrapper loss once for native wrap/unwrap routes. - `frontend-dapp/src/components/swap/RouteOrderCostDetails.tsx:16-35` already renders `Trading fees`, `Tax and hook costs`, `Wrapping costs` and `Reference price difference` inside DETAILS. The backend can legitimately report a large aggregate for a native-wrap route whose selected pool spot differs from the independent reference and whose unwrap loses chain tax. That is a real economic difference, not an arithmetic failure. The defect is that the user-facing notice does not say so. ### The client already has enough information for a wrapped-asset advisory - `frontend-dapp/src/types/index.ts:988-995` exposes `getWrappedEquivalent` / `getNativeEquivalent`. - `frontend-dapp/src/utils/constants.ts:143-154` maps `uluna → cLUNC` and `uusd → cUSTC`, omitting unconfigured addresses. - `execution_metadata.wrapper` already distinguishes `wrap_input` and `unwrap_output`, and `token_in` / `token_out` identify the requested assets. - `simData.orderCosts` already separates wrapper cost from reference divergence. No new RPC, quote request, route selection or signing path is needed. ## Why the new implementation is needed 1. A trader cannot distinguish “the selected pool is genuinely worse than the reference” from “the UI is charging hidden slippage”. An unexplained 11.32% red notice next to `<0.01%` slippage looks like a defect and invites abandonment to another DEX. 2. Native LUNC/USTC routes intentionally pay chain tax and wrap/unwrap fees. The aggregate fair-reference metric correctly includes them, but the user needs a short cause and a clear statement that these are not slippage. 3. Active traders can legitimately avoid repeated chain tax by holding/trading `cLUNC` / `cUSTC` inside the DEX. The current warning does not surface that option, even though the route context already shows native wrap/unwrap. 4. The documented “compact fixed cause explanation” contract is currently broken. Leaving the prop dead means future changes can keep adding validated diagnostics that never reach users. 5. A naive fix that lowers the percentage, hides the warning or switches assets automatically would violate the risk policy. The implementation must explain the existing truthful number without weakening any gate. ## Recommended direction ### 1. Render the validated cause inside the existing notice/DETAILS Use the already-computed `economicExplanation` only when the same quote evidence has passed the existing checks: - In the higher-risk `SwapImpactAside` notice, add one short static cause clause after the required risk sentence, for example: `Fair-reference deviation 11.32%. Mostly wrapping and reference-price difference, not slippage.` Keep it to one notice and one live-region announcement. - In DETAILS, show the cause next to the percentage and keep the existing `RouteOrderCostDetails` raw cost list. Do not duplicate or re-derive amounts. - Map the fixed backend causes to short retail copy in one place. Never render arbitrary backend text. - When `economicExplanation` is unavailable or invalid, render nothing extra. The required risk notice and all gates remain. Do not call the aggregate “slippage”. Use “fair-reference deviation” consistently with the current risk policy, and state that network gas is separate. ### 2. Add a bounded native-wrap advisory When the selected quote is a supported native route and the validated cost breakdown shows that `wrapper_loss` and/or `reference_divergence` dominate the aggregate, add a concise informational line, for example: > Planning to keep trading here? Receiving `cLUNC` instead of `LUNC` avoids unwrapping and repeated chain tax on later swaps. Rules: - Only show the advisory for supported native→wrapped or wrapped→native legs using `getWrappedEquivalent` / `execution_metadata.wrapper`. - Suggest the wrapped asset only when it is actually configured, listed and part of the route context. - Never auto-change `from` / `to` or the exact input; provide no one-click destructive substitution unless separately reviewed. A plain text hint is sufficient for this issue. - Do not make a numeric “save X%” claim unless the exact incremental saving is available from validated evidence. If a number cannot be proven, use qualitative wording. - Suppress the advisory when the output is already the wrapped asset, when there is no native leg, when attribution is unavailable, or when the suggested wrapped asset is missing/disabled. - The advisory is informational only, never a signing permission, and must not alter ranking, consent, Expert or ≥99% refusal. ### 3. Preserve the existing risk and accessibility contract - Keep `evaluateTradingRisk`, exact 5/10/30/99 boundaries and `assertTradingRiskForSubmit` unchanged. - Keep one concise named notice; no second live region, no timed toast, no extra confirmation click added by the explanation or advisory. - The advisory must not be announced repeatedly on identical refreshes. Keep stable text stable. - Ensure the additional line fits at 320–430 px widths without overflowing the fixed CTA/footer layout. ### 4. Update the contract and tests so this cannot silently regress - Update `docs/route-solver.md`, `skills/AGENTS_ROUTE_COST_ATTRIBUTION.md`, `skills/AGENTS_TRADING_RISK.md`, `skills/AGENTS_ORDER_SLIPPAGE.md` and the relevant QA checklist with the “cause + wrapped alternative” presentation and its advisory-only status. - Add component tests that assert the passed explanation is actually rendered and that an invalid/unavailable explanation remains silent. ## Constraints and guardrails - Do not change route ranking, reference admission, the $10 economic-total / $100 hub-depth floors, slippage tolerance, `max_spread`, floors, funding or signing. - Do not weaken or add a waiver to the >30% Expert or ≥99% nonwaivable rules. Do not change ordinary `order >5% OR total >10%`. - Do not lower or hide a legitimate fair-reference deviation merely to make the UI quieter. - Cause copy must come from the fixed allowlist after the existing client schema/reconciliation/quote-binding checks. No raw backend enum, provider string, symbol HTML or user-controlled text. - Advisory copy must not claim a savings amount unless the amount is independently available from validated evidence. Native chain tax and wrapper fees must be described as separate from network gas. - No additional network/RPC/quote calls on render, toggle or asset change. The flow remains offline and bounded. - Do not recommend an unlisted, disabled, unconfigured or unrelated wrapped token. Use the exact configured wrapped equivalent of the route’s native leg. - Keep the existing single-notice priority: an operational blocker or unavailable risk evidence continues to win over advisory cost copy. - Privacy: do not render actor, wallet, conversation or screenshot data. This issue text is already anonymized. ## Relevant files Frontend: - `frontend-dapp/src/components/swap/SwapImpactAside.tsx` — dead `economicExplanation` prop; notice/DETAILS rendering. - `frontend-dapp/src/components/swap/SwapImpactAside.test.tsx` — missing cause/advisory coverage. - `frontend-dapp/src/components/swap/RouteOrderCostDetails.tsx` — existing raw cost breakdown. - `frontend-dapp/src/pages/SwapPage.tsx` — notice and DETAILS wiring. - `frontend-dapp/src/pages/SwapPage.test.tsx` — integration coverage. - `frontend-dapp/src/components/trade/TradeMarketOrderPanel.tsx` — shared Trade notice/DETAILS. - `frontend-dapp/src/components/trade/__tests__/TradeMarketOrderPanel.submitSnapshot.test.tsx` — Trade coverage. - `frontend-dapp/src/utils/cw20RouteSolveQuote.ts` — explanation and cost population. - `frontend-dapp/src/utils/routeEconomicExplanation.ts` — fixed allowlisted cause validator/copy. - `frontend-dapp/src/utils/routeOrderMetrics.ts` — validated `orderCosts`. - `frontend-dapp/src/utils/tradingRisk.ts` — must remain unchanged behaviorally. - `frontend-dapp/src/types/index.ts`, `frontend-dapp/src/utils/constants.ts` — wrapped/native equivalents. - `frontend-dapp/src/utils/nativeWrapRouteSolve.ts` — native wrap route context. Backend reference (no behavior change expected unless a pinned fixture proves a defect): - `indexer/src/api/local_quote.rs` - `indexer/src/api/local_quote/attribution.rs` - `indexer/src/api/local_quote/order_economics.rs` - `indexer/src/api/local_reference_quote.rs` - `indexer/tests/scenarios/route_cost_attribution_1483.rs` Docs/guidance: - `docs/route-solver.md` - `skills/AGENTS_ROUTE_COST_ATTRIBUTION.md` - `skills/AGENTS_TRADING_RISK.md` - `skills/AGENTS_ORDER_SLIPPAGE.md` - `docs/qa/issue-1483/README.md`, `docs/qa/issue-1500/README.md`, `docs/qa/issue-1560/README.md` ## Acceptance criteria - [ ] AC1: A validated `economicExplanation` is rendered in the Swap and Trade price notice and/or DETAILS. The dead prop is either used or removed; no path silently discards it again. - [ ] AC2: The 11.32%-style case shows a truthful short cause (for example wrapping and/or reference-price difference) and makes clear that the number is not order slippage. The required risk percentage, confirmation, Expert and ≥99% behavior are unchanged. - [ ] AC3: A supported native→wrapped / wrapped→native route with dominant wrapper/reference cost shows a concise wrapped-asset advisory. The advisory names only configured listed assets and does not auto-substitute them. - [ ] AC4: Direct pool routes, routes already ending in wrapped assets, unsupported/missing wrapped equivalents, unavailable attribution, and operational blockers do not show the advisory. - [ ] AC5: No new request, RPC, quote broadcast or signing permission is introduced. Rendering, toggling DETAILS and asset edits remain offline and bounded. - [ ] AC6: Cause and advisory copy is allowlisted, escaped and stable; invalid/tampered attribution produces no extra copy and never a zero-cost claim. - [ ] AC7: Mobile layout at 320–430 px keeps the route, notice, advisory and CTA readable without overlap or horizontal overflow; screen readers hear one meaningful status transition, not repeated advisory announcements. - [ ] AC8: Docs/skills/QA checklists describe the cause + advisory behavior and explicitly preserve TR1560/OS1500/RC1483 risk rules. - [ ] AC9: Relevant frontend tests, lint/type checks and verifiers pass; unavailable live/funded/device checks are recorded as explicit SKIPs, not PASS. ## Test plan — all paths ### Unit / component - `SwapImpactAside`: - available cause with `wrapper_loss` → renders the cause text once. - available cause with `reference_divergence`, `trading_cost`, `market_movement`, `mixed`, `Matches reference prices` → renders the matching fixed copy. - unavailable explanation / malformed quote → no cause, no advisory; required risk notice still rendered. - ordinary low-risk quote with cause → remains behind DETAILS. - higher-risk quote with cause → one notice, no duplicate live region. - `blocked="expert"` and `blocked="extreme"` → existing copy/CTA preserved; advisory never replaces the blocker. - 10/30/99 exact boundaries → no text or rounding regression. - Native advisory helper: - native input only, wrapped output only, both-leg route, direct pool route, wrapped-to-native, unsupported mapping, empty configured address, same-asset route. - dominant wrapper/reference vs dominant market/trading. - unavailable `orderCosts` / `execution_metadata` identity mismatch → no advisory. - `RouteOrderCostDetails` remains the single numeric breakdown; no duplicate amounts. ### Integration - `SwapPage.test.tsx`: native wrap/unwrap fixture with a large fair-reference deviation and available attribution → cause + advisory; same fixture with unavailable attribution → no advisory; direct route → no advisory. - `TradeMarketOrderPanel.submitSnapshot.test.tsx`: shared notice/DETAILS behavior, consent and Expert paths. - Receive-sizing / reverse-quote path: explanation and advisory bind the same original quote; changing intent clears both. - Quote refresh while review is open: unchanged text is stable; changed evidence revokes review as before and never preserves stale advisory. - Fee/Max/gas and signing review: no layout duplication, no additional gas or asset mutation. ### Accessibility / visual - Keyboard-only: DETAILS open/close, advisory readable, no new focus trap. - Screen reader: one polite status for ordinary risk transition; advisory is not a second alert; stable text does not reannounce on polling. - Contrast and font size for the added line in light/dark themes. - Mobile widths 320/360/390/430 px, long token symbols and long wrapped names; no overlap with bottom navigation or fixed CTA. - Desktop Swap and Trade market; DETAILS open and closed. ### Regression / policy - `order >5 OR total >10` unchanged; equality unchanged. - Total >30 Expert and ≥99 nonwaivable unchanged. - Favorable order movement and favorable reference divergence still signed/symmetric. - Wrapper-only zero order movement still validated by `validateWrapperOnlyQuote`. - No route ranking change: selected route remains best delivered net for the exact amount. ## Test plan — attack, hack and abuse vectors - Forged/hostile quote injects an arbitrary `economicExplanation` string or HTML → rejected by fixed allowlist and schema binding; rendered only as escaped text. - Malformed component arithmetic (sum ≠ fair − net, non-integer, overflow, negative where disallowed) → explanation unavailable; required risk notice persists; no advisory. - Generation/observation/expiry mismatch or stale quote replayed with new UI text → explanation and advisory suppressed; signing and review binding still reject. - Mismatched `orderCosts`, `spotAmountOut`, `estimated_amount_out` or `execution_metadata.wrapper` → no cause/advisory; risk evaluator remains unavailable or blocks. - Malicious suggestion path attempts to substitute an unlisted/hostile token or inject a URL/CTA → no substitution, no link, no external navigation; only configured wrapped equivalents may be named. - Social-engineering “save X%” claim → no unverified savings number; copy states qualitative chain-tax/wrapper behavior only. - Attempt to bypass consent/Expert/≥99 by making the explanation look like an approval or by hiding the percentage → advisory is text only and never a submit permission; `assertTradingRiskForSubmit` remains the final gate. - XSS via token symbol, pair name, wrapped symbol or route label → React text rendering, no `dangerouslySetInnerHTML`. - Very long/huge raw strings in cost fields → existing bounded validators reject or truncate safely; no layout denial of service. - Duplicate/adversarial refresh spam → stable text, no repeated live-region announcements, no quote-triggered RPC. - Privacy leak attempt via cause/advisory → no actor, wallet, conversation, screenshot or private endpoint data is ever included. ## Verification criteria Run the applicable bounded checks from the repository root: - `make verify-issue-1560` - `make verify-issue-1500` - `make verify-issue-1483` - `make verify-issue-1498` - `make verify-issue-1452` - `make verify-issue-630` (native ticker display, because the advisory names `cLUNC`/`cUSTC`) - targeted frontend tests: `SwapImpactAside.test.tsx`, `SwapPage.test.tsx`, `TradeMarketOrderPanel.submitSnapshot.test.tsx`, `routeEconomicExplanation.test.ts`, `routeOrderMetrics.test.ts` - frontend lint/type/build checks and a production-browser mobile check Record: - exact source commit and any served frontend/indexer artifact hashes; - the fixture/quote inputs and the observed cause/percentage; - executed failures as FAIL; - unavailable live, funded, device or deployment checks as explicit SKIP with overall PASS WITH SKIPS only when executed checks pass; - no claim that source/synthetic tests establish production deployment or funded settlement. Do not close this issue on source-only evidence. Live acceptance requires a served Swap and Trade path with a native wrap/unwrap route, a validated explanation, the wrapped advisory, unchanged risk behavior, and mobile/assistive checks. ## Scope boundaries / cross-links - Warning threshold policy remains [#1560](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1560). - Metric separation and cost disclosure remain [#1500](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1500). - Attribution/reference reconciliation remains [#1483](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1483). - Mobile notice/CTA layout remains [#1561](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1561). - Native quote recovery / wrapper rollout remains [#1505](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1505) and [#1506](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1506). - This issue does not add a third-party DEX, multi-path splitting, a new oracle, or a change to route selection.
Sign in to join this conversation.
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#1579
No description provided.