> For the complete documentation index, see [llms.txt](https://docs.gnoswap.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gnoswap.io/core-concepts/amm/constant-product-market-maker.md).

# Constant Product Market Maker

Liquidity pools on GnoSwap utilize the **Constant Product Formula** to achieve deterministic pricing of any token in a pool, ensuring that trades can occur at any price within the range of (0, ∞). Liquidity pools maintain a constant ***k*** value, which is the product of ***x*** and ***y***, representing the quantity of **token x** and **token y** in the pool, respectively. This mechanism results in the following formula:

$$
x \*y=k
$$

When a trade occurs in a pool, the values of ***x*** and ***y*** change. Let's assume that **∆** represents the change in the quantity of a token. If a trader sells **∆*****x*** amount of **token x**, the pool receives **∆*****x*** amount of **token x** and pays out **∆*****y*** amount of ***token*****&#x20;y** (minus the swap fee) as the output in a way that satisfies the equation below:

$$
(x+∆x)(y-∆y)=k
$$

Based on the above formula, we can plot a graph that illustrates changes in token reserves in a pool after a trade.

<figure><img src="/files/YF5FrGRvv9QyBgpJ89Ba" alt=""><figcaption></figcaption></figure>

To illustrate this concept, let's consider a scenario where Pool A holds 10 $GNOT and 10,000 $USDC. If Alice wishes to exchange 1 $GNOT for $USDC in Pool A, an equation reflecting the current reserves and **∆x** (change in $GNOT) is set up as follows:

$$
k = 10\*10,000 = 100,000 = (10+1)(10,000-∆y)
$$

Solving for ∆y, we get:

$$
∆y = 10,000-(100,000/11) = 909.090909...
$$

Therefore, we can expect Alice would receive 909.090909... $USDC if she were to sell 1 $GNOT in Pool A.

When adding liquidity to an existing pool, liquidity providers must deposit an amount of **token x** and **token y** that is proportional to the current ***x : y*** ratio in the pool. Once liquidity is added, the value of ***k*** adjusts to the new values of ***x*** and ***y***.

As ***k*** is proportional to the liquidity of the pool, this structure can be seen as a virtual order book where liquidity is evenly distributed across the entire price range.

<figure><img src="/files/bTn5FFUlg3DhgLiZRaI2" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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.gnoswap.io/core-concepts/amm/constant-product-market-maker.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.
