CPMM

Constant Product AMM (CPMM)

Introduction

The Constant Product Market Maker (CPMM) is one of the simplest and most widely used automated market maker models. It operates based on a mathematical invariant:

x * y = k

Here, x and y are the reserve balances of two assets (e.g., BTC and Runes), and k is a constant. Each trade alters the reserve ratios but maintains the constant k, resulting in a continuous price curve. This model is ideal for enabling permissionless swaps without order books.

Benefits

  • Simplicity: Easy to implement and understand.

  • Always Liquid: The pool always has a price for traders.

  • Resilience: Stable and predictable behavior under normal conditions.

Limitations

  • Low Capital Efficiency: Liquidity is spread across all prices.

  • High Slippage: Particularly for large trades.

  • No Range Customization: Liquidity providers cannot optimize for specific market ranges.

Example Scenario

Assume a BTC/Runes pool with the following initial state:

  • 1000 BTC

  • 100,000 Runes

A user sells 50 BTC:

  1. Compute the constant: k = 1000 * 100,000 = 100,000,000

  2. After the trade, the pool has 1050 BTC. To maintain k, the new Runes balance becomes 100,000,000 / 1050 ≈ 95,238.10

  3. The trader receives 100,000 - 95,238.10 = 4,761.90 Runes

  4. Average execution price: 4,761.90 / 50 ≈ 95.24 Runes per BTC

  5. Slippage: (100 - 95.24) / 100 ≈ 4.76%

Last updated