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

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

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
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.