> ## Documentation Index
> Fetch the complete documentation index at: https://docs.soroswap.finance/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Soroswap Aggregator API: base URL https://api.soroswap.finance, pick the network with ?network=mainnet or ?network=testnet (omitted means mainnet).
> Auth: Authorization: Bearer sk_... on every call. Get a key at https://console.soroswap.finance/register. A missing or invalid key returns 401 with code and registerUrl (POST /send returns 403 instead); an expired JWT or a missing role returns 403. Free plan 1 request/s; see https://docs.soroswap.finance/api/plans.md.
> Flow: POST /quote (assetIn, assetOut as C... contract addresses, amount as an integer string in the smallest unit, tradeType, protocols) -> POST /quote/build with the unchanged quote and from -> the user signs the XDR -> POST /send. Build right after quoting: a Soroban XDR is valid for 180 seconds. Submit it as is, never re-simulate it.
> Partner id: every account has one (9 hex chars, permanent). Read partnerId from GET /partner, or in the console at https://console.soroswap.finance under Fees & payouts. The partner fee itself is switched on by Soroswap; see https://docs.soroswap.finance/api/fees.md.
> AI tools: docs MCP at https://docs.soroswap.finance/mcp (claude mcp add --transport http soroswap-docs https://docs.soroswap.finance/mcp), skill with npx skills add https://docs.soroswap.finance. Other clients: https://docs.soroswap.finance/api/build-with-ai.md.
> Units and Stellar pitfalls: https://docs.soroswap.finance/api/stellar-gotchas.md. Errors and retries: https://docs.soroswap.finance/api/errors.md.

# How Soroswap AMM works

> Soroswap AMM basics: constant product formula, liquidity pools, pool tokens, and the 0.30% fee.

### Quick Reference

![](https://mintcdn.com/soroswap/1xzCGA5zGx88_Gb9/images/captura-de-pantalla-2025-04-24-a-las-15-07-19.png?fit=max\&auto=format\&n=1xzCGA5zGx88_Gb9\&q=85\&s=e188b853fb4c215e1e35471ab87e833b)

Soroswap AMM is an *automated liquidity protocol* powered by a [constant product formula](https://docs.soroswap.finance/amm/glossary.md#constant-product-formula) and implemented in a system of non-upgradeable smart contracts on the [Soroban](https://developers.stellar.org/docs/smart-contracts) blockchain. It obviates the need for trusted intermediaries, prioritizing **decentralization**, **censorship resistance**, and **security**. Soroswap is **open-source software** licensed under the [Apache 2.0 Licence](https://github.com/soroswap/core/blob/main/LICENSE).

Each Soroswap Pair smart contract, manages a liquidity pool made up of reserves of two tokens. These can be either (1) Soroban native tokens implemeting the [Soroban Token Interface](https://developers.stellar.org/docs/smart-contracts/tokens/token-interface), or (2) [Stellar Assets](https://developers.stellar.org/docs/issuing-assets/anatomy-of-an-asset)

Anyone can become a liquidity provider (LP) for a pool by depositing an equivalent value of each underlying token in return for pool tokens. These tokens track pro-rata LP shares of the total reserves, and can be redeemed for the underlying assets at any time.

![](https://mintcdn.com/soroswap/1xzCGA5zGx88_Gb9/images/captura-de-pantalla-2024-09-20-a-las-15-42-48.png?fit=max\&auto=format\&n=1xzCGA5zGx88_Gb9\&q=85\&s=578e07ef1ac52b08a3449de1580c6472)

Pairs act as automated market makers, standing ready to accept one token for the other as long as the “constant product” formula is preserved. This formula, most simply expressed as `x * y = k`, states that trades must not change the product (`k`) of a pair’s reserve balances (`x` and `y`). Because `k` remains unchanged from the reference frame of a trade, it is often referred to as the invariant. This formula has the desirable property that larger trades (relative to reserves) execute at exponentially worse rates than smaller ones.

In practice, Soroswap applies a 0.30% fee to trades, which is added to reserves. As a result, each trade actually increases `k`. This functions as a payout to LPs, which is realized when they burn their pool tokens to withdraw their portion of total reserves. In the future, this fee may be reduced to 0.25%, with the remaining 0.05% withheld as a protocol-wide charge. This is the only change that the protocol accepts. The total 0.30% fee it's hardcoded in the code and cannot be changed.

![](https://mintcdn.com/soroswap/1xzCGA5zGx88_Gb9/images/captura-de-pantalla-2024-09-20-a-las-16-20-55.png?fit=max\&auto=format\&n=1xzCGA5zGx88_Gb9\&q=85\&s=36ba47644699b8511c34069376a97821)

Because the relative price of the two pair assets can only be changed through trading, divergences between the Soroswap price and external prices create arbitrage opportunities. This mechanism ensures that Soroswap prices always trend toward the market-clearing price.

## Further reading

To see how token swaps work in practice, and to walk through the lifecycle of a swap, check out [Swaps](https://docs.soroswap.finance/concepts/swap.md). Or, to see how liquidity pools work, see [Pools](https://docs.soroswap.finance/concepts/liquidity-pools.md).

Ultimately, of course, the Soroswap protocol is just smart contract code running on Soroban. To understand how they work, head over to [The Soroban Home Page](https://developers.stellar.org/docs/smart-contracts).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.