feat(swap): show the best executable route and hop cost #1330

Open
opened 2026-09-23 11:06:01 +00:00 by PlasticDigits · 5 comments
Owner

Summary

dex.cl8y.com Swap should show the best executable Terra Classic route before the trader signs: hop legs, hop cost, and expected price impact. If that route cannot execute, the page fails with a clear error and a one-tap retry. When a route that uses CL8Y as a middle hop beats a direct Terraswap or Astroport hop, the quote should offer that path. Direct hops on LUNC → UST1 / USTR have been poor enough that a CL8Y middle hop was the better trade.

This is not the fee dashboard on /protocol, and it is not the open research spike on splitting one amount across several paths (#1203).

Current codebase

Routing already has a single-winner solver (GET /route/solve) and a hybrid pool-plus-book split inside a pair. The retail gap is presentation and selection: the trader cannot see legs and expected loss before signing, a hybrid failure can look like a dead click, and a better CL8Y middle hop is not consistently chosen over a bad direct hop.

Why

A route that looks best on spot and then fails, or that hides a large hop loss, is not a usable quote. Campaign links also need to keep their query parameters across that quote and a retry.

Constraints

  • Do not implement multi-path amount splitting here (#1203).
  • The signed message must be the route that was shown. A retry must not silently switch hops.
  • Do not fetch or embed private chat in the issue or the UI.

Extend the pre-trade quote to list legs and expected loss for the chosen executable route, including a CL8Y middle hop when its executable output beats the direct hop. On hybrid or solver failure, show the error and a retry that re-requests the quote. Preserve campaign query parameters on the swap URL.

Given / When / Then

Given a Swap quote on columbus-5 where a CL8Y middle hop returns more than the direct Terraswap or Astroport hop,

When the trader opens the quote,

Then the page shows the legs and expected loss, signs only that route, and a failed execute offers one retry without dropping campaign parameters.

Acceptance criteria

  • Pre-trade quote shows route legs and expected loss.
  • CL8Y-as-middle is selected when its executable output is better than the direct hop, and not when it is worse.
  • Hybrid or solver failure is visible and retryable in one action.
  • Deep-link campaign parameters survive quote and retry.
  • Distinct from /protocol fee tables.

Test plan

  • Frontend test: a two-leg fixture renders legs and loss, and a better CL8Y middle hop wins over a worse direct hop.
  • A failed quote shows the error and the retry control.
  • A URL with campaign parameters is unchanged by opening the quote.

Verification

  • One columbus-5 quote where the CL8Y middle hop is shown because it beats the direct hop, with legs visible before sign.
  • A forced solver failure shows an error and retry, and the campaign query string is still present.

First-pass model recommendation

Recommendation: grok-high

Quote selection touches the solver and the signed swap, and a wrong winner changes what the wallet signs. That is more than a single presentational edit.

## Summary `dex.cl8y.com` Swap should show the best **executable** Terra Classic route before the trader signs: hop legs, hop cost, and expected price impact. If that route cannot execute, the page fails with a clear error and a one-tap retry. When a route that uses CL8Y as a middle hop beats a direct Terraswap or Astroport hop, the quote should offer that path. Direct hops on LUNC → UST1 / USTR have been poor enough that a CL8Y middle hop was the better trade. This is not the fee dashboard on `/protocol`, and it is not the open research spike on splitting one amount across several paths ([#1203](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1203)). ## Current codebase Routing already has a single-winner solver (`GET /route/solve`) and a hybrid pool-plus-book split inside a pair. The retail gap is presentation and selection: the trader cannot see legs and expected loss before signing, a hybrid failure can look like a dead click, and a better CL8Y middle hop is not consistently chosen over a bad direct hop. ## Why A route that looks best on spot and then fails, or that hides a large hop loss, is not a usable quote. Campaign links also need to keep their query parameters across that quote and a retry. ## Constraints - Do not implement multi-path amount splitting here ([#1203](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1203)). - The signed message must be the route that was shown. A retry must not silently switch hops. - Do not fetch or embed private chat in the issue or the UI. ## Recommended direction Extend the pre-trade quote to list legs and expected loss for the chosen executable route, including a CL8Y middle hop when its executable output beats the direct hop. On hybrid or solver failure, show the error and a retry that re-requests the quote. Preserve campaign query parameters on the swap URL. ## Given / When / Then **Given** a Swap quote on columbus-5 where a CL8Y middle hop returns more than the direct Terraswap or Astroport hop, **When** the trader opens the quote, **Then** the page shows the legs and expected loss, signs only that route, and a failed execute offers one retry without dropping campaign parameters. ## Acceptance criteria - Pre-trade quote shows route legs and expected loss. - CL8Y-as-middle is selected when its executable output is better than the direct hop, and not when it is worse. - Hybrid or solver failure is visible and retryable in one action. - Deep-link campaign parameters survive quote and retry. - Distinct from `/protocol` fee tables. ## Test plan - Frontend test: a two-leg fixture renders legs and loss, and a better CL8Y middle hop wins over a worse direct hop. - A failed quote shows the error and the retry control. - A URL with campaign parameters is unchanged by opening the quote. ## Verification - One columbus-5 quote where the CL8Y middle hop is shown because it beats the direct hop, with legs visible before sign. - A forced solver failure shows an error and retry, and the campaign query string is still present. ## First-pass model recommendation Recommendation: grok-high Quote selection touches the solver and the signed swap, and a wrong winner changes what the wallet signs. That is more than a single presentational edit.
Author
Owner

cl8y-agent-control: queued design_author job e132575c-432f-4175-a53f-b9880768251f (not executed; no Hetzner VM).

cl8y-agent-control: queued `design_author` job `e132575c-432f-4175-a53f-b9880768251f` (not executed; no Hetzner VM).
Author
Owner

Routing likely does not yet support terraport/astroport, and when it does it must charge an additional flat (not tiered) 2.9% fee on 3rd party dex such as terraport, astroport, and garuda

Routing likely does not yet support terraport/astroport, and when it does it must charge an additional flat (not tiered) 2.9% fee on 3rd party dex such as terraport, astroport, and garuda
Author
Owner

THis issue should not be implemented until a substantial design/architecture plan as well as security policy for integrating 3rd party dexes is implemented. THere are multiple complexities to handle including unexpected 3rd party dex behavior, lunc/ustc wrap fees, and potential for malicious cw20 codeids on 3rd party dexes

THis issue should not be implemented until a substantial design/architecture plan as well as security policy for integrating 3rd party dexes is implemented. THere are multiple complexities to handle including unexpected 3rd party dex behavior, lunc/ustc wrap fees, and potential for malicious cw20 codeids on 3rd party dexes
Author
Owner

See #690

See #690
Author
Owner

Presentation/campaign repairs are merged through PR #1537 and PR #1542, final main 5b623a04f35bb6b44d3e64df0014e458cad653fc; genuine CI526 passed. Leaving open: third-party execution and the requested live winner comparison are not implemented/verified.

  • Selected route legs, fees and separate loss metrics render in operation order, with accessible “to” narration, separate from /protocol tables.
  • Solver failure exposes one-action Retry. Retry obtains another reviewable quote and never submits a swap. Repeated campaign parameters survive canonicalization, quote failure and retry without entering solver/signing/share payloads.
  • Focused summary/query and page retry tests pass. Deployed desktop/phone cases each injected one solver HTTP503, clicked Retry once and required an actual anonymous backend HTTP200 with positive receive amount (11.521s / 11.932s). The first selector failure is retained as a qualified harness mismatch.
  • Added the substantial architecture/security design requested by the comments, following #690 with its 290-bps correction: pinned identities/schemas, malicious CW20 admission, native wrapping/tax economics, bounded scheduled observations, atomic settlement and final-net ranking. The old queued design job is not claimed as executed.
  • Implement third-party adapters and tier-independent floor(measured foreign-hop ask delta ×290/10000) ask-asset payment to pinned CMM, additional to actual venue/wrapper costs, with at most one foreign hop. A design is not executable support.
  • Prove native foreign-hop authorization/taxes, exact CMM receipt and final user net atomically, with rollback/minimum/refund adversarial tests; complete governed activation and funded settlement acceptance.
  • Demonstrate a live columbus-5 CL8Y middle-hop winner over the external direct alternative, the opposite ranking when worse, and displayed-versus-signed execution alignment. Rendering an already-selected two-leg fixture does not establish these.

Campaign cases used frontend 2df4a471a9ca98a8672d911b67d4bd8134f411fd with prior backend 0a3c251755a88ee9cbbbbc222fc747811c9da08c. The backend is now exactly deployed at 5b623a04…, with deployment/log attestation and a separate bounded rolling monitor recording 55 HTTP200 / zero failures; the served frontend remains 2df4a471…. That rollout does not supply missing external-route acceptance. Unsupported venues/native protocols remain disabled; no multipath splitting or private chat/actor evidence was added.

Completed invariants, receipts and remaining checklist, agent route guidance. Next work is the complete guarded adapter/solver/client integration and its actual-chain criteria; this issue is not complete.

Final release evidence and checked acceptance lists: #1543, release checklist in #1543. The exact serving backend remains 5b623a04; this final publication changes documentation only.

Presentation/campaign repairs are merged through [PR #1537](https://git.cl8y.com/code/cl8y-dex-terraclassic/pulls/1537) and [PR #1542](https://git.cl8y.com/code/cl8y-dex-terraclassic/pulls/1542), final main `5b623a04f35bb6b44d3e64df0014e458cad653fc`; genuine [CI526](https://ci.cl8y.com/repos/7/pipeline/526/1) passed. **Leaving open:** third-party execution and the requested live winner comparison are not implemented/verified. - [x] Selected route legs, fees and separate loss metrics render in operation order, with accessible “to” narration, separate from `/protocol` tables. - [x] Solver failure exposes one-action Retry. Retry obtains another reviewable quote and never submits a swap. Repeated campaign parameters survive canonicalization, quote failure and retry without entering solver/signing/share payloads. - [x] Focused summary/query and page retry tests pass. Deployed desktop/phone cases each injected one solver HTTP503, clicked Retry once and required an actual anonymous backend HTTP200 with positive receive amount (11.521s / 11.932s). The first selector failure is retained as a qualified harness mismatch. - [x] Added the substantial [architecture/security design](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/5b623a04f35bb6b44d3e64df0014e458cad653fc/docs/architecture/third-party-route-adapters.md) requested by the comments, following #690 with its 290-bps correction: pinned identities/schemas, malicious CW20 admission, native wrapping/tax economics, bounded scheduled observations, atomic settlement and final-net ranking. The old queued design job is not claimed as executed. - [ ] Implement third-party adapters and tier-independent **floor(measured foreign-hop ask delta ×290/10000)** ask-asset payment to pinned CMM, additional to actual venue/wrapper costs, with at most one foreign hop. A design is not executable support. - [ ] Prove native foreign-hop authorization/taxes, exact CMM receipt and final user net atomically, with rollback/minimum/refund adversarial tests; complete governed activation and funded settlement acceptance. - [ ] Demonstrate a live columbus-5 CL8Y middle-hop winner over the external direct alternative, the opposite ranking when worse, and displayed-versus-signed execution alignment. Rendering an already-selected two-leg fixture does not establish these. Campaign cases used frontend `2df4a471a9ca98a8672d911b67d4bd8134f411fd` with prior backend `0a3c251755a88ee9cbbbbc222fc747811c9da08c`. The backend is now exactly deployed at `5b623a04…`, with deployment/log attestation and a separate bounded rolling monitor recording 55 HTTP200 / zero failures; the served frontend remains `2df4a471…`. That rollout does not supply missing external-route acceptance. Unsupported venues/native protocols remain disabled; no multipath splitting or private chat/actor evidence was added. [Completed invariants, receipts and remaining checklist](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/5b623a04f35bb6b44d3e64df0014e458cad653fc/docs/qa/issue-1330/README.md), [agent route guidance](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/5b623a04f35bb6b44d3e64df0014e458cad653fc/skills/AGENTS_FRONTEND_SWAP_ROUTE_DISPLAY.md). Next work is the complete guarded adapter/solver/client integration and its actual-chain criteria; this issue is not complete. Final release evidence and checked acceptance lists: [#1543](https://git.cl8y.com/code/cl8y-dex-terraclassic/pulls/1543), [release checklist in #1543](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/2a78ec3303c11c0d1ebd76a19005a02ebba3adff/docs/qa/issues-1206-1512/live-release-20261018.md). The exact serving backend remains `5b623a04`; this final publication changes documentation only.
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#1330
No description provided.