Constant Product Market Maker
Last updated
Was this helpful?
Last updated
Was this helpful?
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:
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 y (minus the swap fee) as the output in a way that satisfies the equation below:
Based on the above formula, we can plot a graph that illustrates changes in token reserves in a pool after a trade.
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:
Solving for ∆y, we get:
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.