Swap
Last updated
Last updated
A swap is the process of exchanging one Stellar asset for another using liquidity from Soroban-based Automated Market Makers (AMMs). Swaps can be executed directly through the Soroswap AMM or routed via the Aggregator, which optimally resolves the operation by finding the best available price at the time through an intelligent distribution across supported AMMs. 👉🏽 How to Swap Follow the Swap Tutorial
User selects two assets – one to sell and one to receive.
Input amount is defined – the app estimates the output based on current pool conditions.
Router SDK scans available pools – if the Aggregator is enabled, it calculates the best distribution DexDistribution
.
User confirms the swap – the smart contract receives the input asset and performs the swap.
User receives the new asset – if it's the first time, a trustline must be signed to accept the asset.
Each AMM in Soroswap follows this formula:
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: Fees 🔙 Previous: Liquidity Pools