feat(explorer): cross-chain token swap saga (/cross-swap) - #70
Open
bachal-mb wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
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 thesaved 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.
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.
Verified: tsc clean (aside from pre-existing build-info.test.ts) and
next buildcompiles /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.