Soroswap.Finance Docs
  • Welcome 👋🏼
    • What is Soroswap Finance?
    • Getting Started
      • Wallet Setup and Connection
      • How to Swap
      • Provide Liquidity
      • How the Aggregator Works
  • Concepts
    • AMM
    • Liquidity Pools
    • Swap
    • Fees
    • Slippage
    • Router
    • SDEX
    • Aggregator
    • Trustlines
    • Advanced Topics
      • Pricing
      • Understanding Returns
      • Security
      • Research
  • Soroswap AMM (DEX)
    • How Soroswap AMM works
    • Ecosystem Participants
    • Audits
    • Technical Reference
      • Smart contracts
        • SoroswapPair
        • SoroswapFactory
        • SoroswapRouter
        • SoroswapLibrary
      • Deployed Addresses
      • Error Codes
      • Using Soroswap with TypeScript
      • Smart Contract Integration
      • Deploy Soroswap Yourself
        • Setup your environment.
        • Experiment the Pair contract
        • Experiment the Factory Contract.
        • Deployments.
        • Using the Soroswap Testnet
    • Glossary
  • Soroswap Aggregator
    • Supported AMMs
    • Audits
    • Technical Reference
      • How Soroswap Aggregator works
      • Design
      • Technical Overview
      • Aggregator Operation
      • Smart Contracts
        • SoroswapAggregator
        • Adapter Trait
        • SoroswapAdapter
      • Inspirations
        • 1inch
      • Other AMMs in Soroban
        • Phoenix
    • Disclaimer
  • Swap Route API
  • Soroswap Info
  • Tutorials
    • Installing Freighter
    • Soroswap sections
    • Adding Liquidity
    • Doing Swap
    • Remove Liquidity
    • Using Stellar Classic Assets
      • Wrapping Stellar Classic Assets
      • Swap Stellar Classic Assets
      • Test Stellar Classic Assets
    • Bridge using Pendulum
    • Conclusions
  • Partnerships
    • Collaboration with Mercury and SubQuery
    • Business Partnerships
  • Support & Resources
    • About Us
    • General FAQ
    • Additional Resources
Powered by GitBook
On this page
  • How does a swap work?
  • 📐 Constant Product Formula
Edit on GitHub
  1. Concepts

Swap

PreviousLiquidity PoolsNextFees

Last updated 29 days ago

A swap is the process of exchanging one Stellar asset for another using liquidity from Soroban-based ). Swaps can be executed directly through the or routed via the which optimally resolves the operation by finding the best available price at the time through an intelligent distribution across supported AMMs. 👉🏽 Follow the

How does a swap work?

User selects two assets – one to sell and one to receive.

  1. Input amount is defined – the app estimates the output based on current pool conditions.

  2. Router SDK scans available pools – if the Aggregator is enabled, it calculates the best distribution DexDistribution.

  3. User confirms the swap – the smart contract receives the input asset and performs the swap.

  4. User receives the new asset – if it's the first time, a trustline must be signed to accept the asset.

📐 Constant Product Formula

Each AMM in Soroswap follows this formula:

x * y = k

Where:

  • x = balance of asset A

  • y = balance of asset B

  • k = constant product (remains unchanged)

When someone swaps A for B:

  • A is deposited into the pool

  • B is withdrawn

  • The price updates to maintain the balance

This model ensures continuous liquidity.

🔜 Next: 🔙 Previous:

Fees
Liquidity Pools
Automated Market Makers (AMMs
Soroswap AMM
Aggregator,
How to Swap
Swap Tutorial
Page cover image