How Does a Constant Product Market Maker (CPMM) Work?

A CPMM, like Uniswap v2, maintains a constant product for the reserves of two assets in a liquidity pool, defined by the formula x y = k. When a user trades, the ratio of x and y changes to maintain k, which determines the new price.

The larger the trade, the more the price shifts (slippage), which is the mechanism exploited by sandwich attacks.

What Are the Trade-Offs between a Constant Product Market Maker and a Constant Sum Market Maker (X+y=k)?
What Is the Difference between a Constant Product Market Maker and a Stable Swap Market Maker?
How Does a ‘Hybrid AMM’ (Like Curve’s Stableswap) Combine Features of Constant Product and Constant Sum?
How Does a Constant Product Market Maker (CPMM) Model Create Arbitrage Opportunities?
What Are the Advantages and Disadvantages of Using a Constant Sum Formula versus a Constant Product Formula in an AMM?
How Does an Automated Market Maker (AMM) Calculate the Price of a Token Pair in a Liquidity Pool?
Explain the Difference between a Constant Product and a Constant Sum AMM Curve
How Is Slippage Calculated in an Automated Market Maker (AMM) Environment?

Glossar