Skip to content

feat(explorer): cross-chain token swap saga (/cross-swap) - #70

Open
bachal-mb wants to merge 1 commit into
feat/lithoswap-swap-uifrom
feat/cross-chain-swap
Open

feat(explorer): cross-chain token swap saga (/cross-swap)#70
bachal-mb wants to merge 1 commit into
feat/lithoswap-swap-uifrom
feat/cross-chain-swap

Conversation

@bachal-mb

Copy link
Copy Markdown
Collaborator

feat(explorer): cross-chain token swap saga (/cross-swap)

Composes the MultX bridge with the Lithoswap DEX so a user can go from token A
on chain X to token B on chain Y. The DEX is on Makalu and the bridge locks only
on the Lithosphere chains, so a full route is up to three legs:

bridge_in (X → Makalu) → swap (A → B on Makalu) → bridge_out (Makalu → Y)

Legs whose chain is already Makalu are dropped, so Kamet→Makalu is 2 legs,
Makalu→Kamet is 2, Kamet→Sepolia is 3, etc.

  • lib/crossSwap.ts — a persisted state machine: route planner, saga model,
    localStorage persistence, and step executors that reuse lib/bridge.ts
    (lock → wait for validator signatures → claim) and lib/swap.ts (quote →
    approve → swap). currentStep() recomputes the next action purely from the
    saved record, so a user who closes the tab mid-flow resumes exactly where they
    left off. The bridge-out amount is the actual swap output, captured as the
    on-chain balance delta of the received token. External-chain destinations are
    released by the relayer (no user claim); Lithosphere destinations are claimed.
  • pages/cross-swap.tsx — setup form (token/chain in + out, amount, slippage,
    live quote preview + route), then a guided step-runner: a progress rail, a
    single context-aware Continue button, chain-switch gating per leg, and polling
    that auto-unlocks claims once validators sign and auto-completes external
    releases. Env-gated by NEXT_PUBLIC_SWAP_ROUTER (same as /swap) — shows a
    "not live yet" state until the DEX is deployed.
  • /swap gains a link to /cross-swap.

Verified: tsc clean (aside from pre-existing build-info.test.ts) and
next build compiles /cross-swap as a static route.

Note: this is the orchestration + UX. It exercises the same live bridge and
(once deployed) DEX; end-to-end validation on-chain needs the DEX deployed and
pools seeded.

Composes the MultX bridge with the Lithoswap DEX so a user can go from token A
on chain X to token B on chain Y. The DEX is on Makalu and the bridge locks only
on the Lithosphere chains, so a full route is up to three legs:

  bridge_in (X → Makalu) → swap (A → B on Makalu) → bridge_out (Makalu → Y)

Legs whose chain is already Makalu are dropped, so Kamet→Makalu is 2 legs,
Makalu→Kamet is 2, Kamet→Sepolia is 3, etc.

- lib/crossSwap.ts — a persisted state machine: route planner, saga model,
  localStorage persistence, and step executors that reuse lib/bridge.ts
  (lock → wait for validator signatures → claim) and lib/swap.ts (quote →
  approve → swap). `currentStep()` recomputes the next action purely from the
  saved record, so a user who closes the tab mid-flow resumes exactly where they
  left off. The bridge-out amount is the *actual* swap output, captured as the
  on-chain balance delta of the received token. External-chain destinations are
  released by the relayer (no user claim); Lithosphere destinations are claimed.
- pages/cross-swap.tsx — setup form (token/chain in + out, amount, slippage,
  live quote preview + route), then a guided step-runner: a progress rail, a
  single context-aware Continue button, chain-switch gating per leg, and polling
  that auto-unlocks claims once validators sign and auto-completes external
  releases. Env-gated by NEXT_PUBLIC_SWAP_ROUTER (same as /swap) — shows a
  "not live yet" state until the DEX is deployed.
- /swap gains a link to /cross-swap.

Verified: tsc clean (aside from pre-existing build-info.test.ts) and
`next build` compiles /cross-swap as a static route.

Note: this is the orchestration + UX. It exercises the same live bridge and
(once deployed) DEX; end-to-end validation on-chain needs the DEX deployed and
pools seeded.
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.

1 participant