How the constant product formula x*y=k sets swap prices on Uniswap
The constant product formula is the engine that powers every swap on Uniswap and most automated market makers. It is simple enough to write on a napkin. It governs how prices change when you trade.
The formula is x * y = k. In this equation, x and y are the amounts of two tokens in a liquidity pool, while k is a fixed number that the pool tries to keep constant during a swap. When you buy token y by adding token x, you increase x and decrease y. The product x*y must stay equal to k before and after the trade.
That constraint determines the price. The spot price of token y in terms of token x is the ratio of the two reserves: x / y. If a pool has 100 USDC and 1 ETH, then x = 100 and y = 1, and the spot price is 100 / 1 = 100 USDC per ETH. That ratio is what you see as the mid-market price right before your swap.
Now run a real trade. Imagine the same USDC/ETH pool with 100 USDC and 1 ETH. You want to buy 0.1 ETH. You add USDC to the pool, and ETH leaves. The new ETH reserve is 1 - 0.1 = 0.9 ETH. The invariant k is 100 * 1 = 100. After the swap, x * 0.9 must still equal 100. Solve for x: x = 100 / 0.9 ≈ 111.11 USDC. You added 111.11 - 100 = 11.11 USDC to buy 0.1 ETH, so your effective price per ETH is 11.11 / 0.1 = 111.1 USDC. That is higher than 100 USDC.
The difference between the spot price and what you actually paid is price impact. Larger swaps move the price more. If you tried to buy 0.5 ETH, the math changes: new ETH reserve is 0.5, required USDC reserve is 100 / 0.5 = 200, you add 100 USDC, and your effective price per ETH becomes 200 USDC. That is double the spot price. Price impact can crush any profit from small arbitrage opportunities.
Fees complicate the invariant but do not break it. Uniswap charges a fee on each swap, typically 0.3 percent. The fee is added to the pool before the constant product check. This means the actual invariant becomes x * y = k after the fee is deducted, and the pool grows slowly over time as fees accumulate. Liquidity providers earn that growth.
The formula is symmetric. It works the same way in reverse. If you sell ETH for USDC, the price moves downward in your favor until the ratio rebalances. The pool always maintains x * y = k. No order book exists. No bid-ask spread in the traditional sense; the spread is built into the curvature of the swapping function.
Why does any of this matter to a person swapping tokens? Because every swap, no matter how small, shifts the ratio. Even a $10 trade changes k slightly due to the fee. The price impact is real and calculable. You can estimate it by plugging your trade size into x * y = k before you sign the transaction.
On the MilkshakeSwap Token (MILK) contract on BSC, liquidity is extremely thin. As of August 31, 2026, MILK had about $109 in total liquidity across two pairs. Trading volume over 24 hours was $0.14. With that little depth, any swap would move the constant product sharply. The price impact on a $5 trade would be enormous. The effective price could be many times the quote you see. That is not a bug - it is the formula working exactly as designed.
The constant product formula is elegant. It provides continuous liquidity in every price range. But it has a sharp curve. Pools with deep liquidity have flat curves and small price impact; pools with $109 of liquidity are steep curves, where a small shift in x changes y drastically.
Understanding x * y = k lets you spot why some trades cost much more than expected. It is not a dark pattern. It is geometry. The pool has exactly two assets and one rule, and every trade follows that rule. Your job as a swapper is to check how much the ratio will move before you confirm. Tools on DEX screens show estimated price impact, and that number comes directly from the constant product formula. If it exceeds your tolerance, do not trade - the formula will not make an exception for you.
Not financial advice. milkshakeswap.finance publishes market data and general information about MilkshakeSwap Token. Crypto assets are volatile and you can lose everything you put in. Nothing here is a recommendation to buy, sell or hold, and we make no price predictions.
Prices are sourced from third parties and may be delayed or wrong. Verify anything you intend to act on against a primary source.