What Is the Formula for the Constant Product Market Maker (CPMM) and How Is It Exploited?
The formula is $x y = k$, where $x$ and $y$ are the reserves of the two tokens in the liquidity pool, and $k$ is a constant. The formula is exploited because every trade must maintain this constant, leading to predictable price changes.
When a large trade dramatically changes the ratio of $x$ and $y$, it causes a price shift that is immediately visible. A front-runner exploits this predictability by placing orders around the victim's trade to profit from the guaranteed price impact.