Skip to content

Add Soroswap AMM as alternative swap route #24

Description

@MJ-RWA

Complexity: High — 200 pts

Summary

StellarFlow swaps currently use Stellar's native DEX order book. Soroswap is a Soroban-based AMM on Stellar that often has better rates for certain pairs. This issue adds Soroswap as a parallel swap option — both quotes are fetched simultaneously and the user sees which gives a better rate.

Files to Create/Modify

  • Create: src/lib/soroswap.ts — Soroswap API client and Soroban tx builder
  • Modify: src/pages/SwapPage.tsx — dual quote UI and route selection
  • Modify: src/lib/stellar.ts — add Soroban contract invocation helper for Soroswap

Implementation Notes

soroswap.ts

const SOROSWAP_API = 'https://api.soroswap.finance';
export async function getSoroswapQuote(fromAsset, toAsset, amount, fromIssuer?, toIssuer?): Promise<{toAmount, route, contractAddress} | null>
export async function buildSoroswapTx(sourceAddress, contractAddress, ...): Promise<string>

getSoroswapQuote maps asset to Soroswap's format ('native' for XLM, 'ASSET_CODE:ISSUER' for others). buildSoroswapTx invokes the Soroban router contract using StellarSdk.Contract and StellarSdk.nativeToScVal.

SwapPage

const [dexQuote, soroswapQuote] = await Promise.allSettled([getSwapQuote(...), getSoroswapQuote(...)]);

Show both as selectable cards. Highlight the one with a better rate (add a "Best rate" badge). Store user's selection in selectedRoute state. On "Swap", use the selected route's tx builder.

If Soroswap throws or returns null, silently show only the DEX card.

Acceptance Criteria

  • Both DEX and Soroswap quotes fetched in parallel
  • Both quotes displayed as selectable cards with their rates
  • Better rate is highlighted/recommended
  • Both routes execute correctly when selected
  • If Soroswap is unavailable, only DEX quote is shown (no crash)
  • Works on Stellar mainnet

Screen Recording Requirements

  1. Open Swap page → both DEX and Soroswap quotes load simultaneously
  2. One quote shows a better rate — it is highlighted
  3. Select the Soroswap route → sign and execute → success
  4. Select the DEX route → sign and execute → success
  5. Show the transaction on Stellar Expert confirming the correct operation type

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions