# AMM Swap

## The concept

The constant product market maker is the most common AMM invariant that was made popular with Uniswap. It can be simply modeled as x \* y = k . X and Y are the reserves for each asset, as assets are traded through this function X and Y increase or decrease in their reserves in a way that keeps a constant K (not counting fees charged).

![Constant Product Market Maker](https://lh7-us.googleusercontent.com/3KmxSWE13rMeO7ZuD80lm5b8h_6PUddODif1VWIkQX45N3UE4PSYi08YCEA8aByojxyVsvD_VVb8pPw-DM-EEojCF31oGSU3SgBgxmwotF-scjYjYPxj17n-YoSuixG5UvPu7fTKM3ooJP-uqFaz2bY)

Constant Product

<figure><img src="/files/DDxBwBScVUMm6GzMPqQ1" alt=""><figcaption><p>Swap Page</p></figcaption></figure>

### Example — Trader Swap Tokens

Assume there are two BRC20 tokens: ORDI and SATS, and there is a ORDI/SATS Uniswap liquidity pool created. Let’s say this ORDI/SATS liquidity pool currently has 10 ORDI and 40 SATS in it, so the ratio is 1 ORDI : 4 SATS. Assuming that’s the current market ratio, 1 ORDI is now worth 4 SATS.

Now if John swaps his 1 ORDI for SATS, the pool will take his 1 ORDI, transfer a certain amount of SATS from the pool to him.

Uniswap determines the output token amount by using a constant product formula:

x \* y = k

Instead of 4 SATS, John will actually receive a bit less: 3.626444 SATS.

The constant product formula requires the trades should not change the product (K) of a pair’s reserved balances (X and Y). Let’s walk through the calculation step by step.

Originally, the liquidity pool has 10 ORDI and 40 SATS, so X = 10 and Y = 40. When John swaps 1 ORDI , he will pay a 0.3% fee first, which is 0.003 ORDI (0.3% \* 1). After the fee is paid, the remaining ORDI, which is 0.997 ORDI, will be swapped for SATS, so the new X becomes 10.997 ORDI. Since K must remain unchanged, the new Y can be calculated from the formula X \* Y = newX \* newY. So newY is 36.373556 (X \* Y / newX = 10 \* 40 / 10.997 = 36.373556). This means the pool will hold 36.373556 SATS, the remaining SATS will be sent to John, which means John will receive 3.626444 SATS(Y — newY = 40 – 36.373556 = 3.626444). After the swap, the pool has 11 ORDI and 36.373556 SATS.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.corridor.finance/overview/amm-swap.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
