# Constant-product pricing

URL: https://protocols.davidgarciab.com/concepts/constant-product/
Published: 2026-10-13. Updated: 2026-11-26. Sources last verified: 2026-12-01.

Summary: Constant-product pricing keeps the product of two reserves from falling when a swap pays its fee. The spot price is the reserve ratio. The rule is uniform across all prices in v2, only inside a tick range in v3 and v4, and only the outer region of a Curve StableSwap pool.

Constant product means the pool agrees to any trade that does not shrink `x * y` after fees. `x` and `y` are the two reserves. Their product is `k`. The trader who wants more of `y` must leave more of `x`, and the last unit of `y` costs more than the first because the reserve of `y` is shrinking while the reserve of `x` is growing.

The spot price of `y` in units of `x` is `x / y` only as a marginal price, before a finite trade and before the fee. A real trade moves the reserves. The execution price is worse than the spot price by the impact along the curve, then worse again by the fee. Uniswap’s overview states the qualitative part: larger trades relative to the pool move the price more.

## The fee is inside the product check

The v2 flash-swap guide puts the fee at 0.30 percent on the input. The familiar quote multiplies the input by 997 and the reserve by 1000 so that only 99.7 percent of the input counts toward the product. The pool can therefore increase `k` slightly. It must not decrease `k` using the post-fee balances. That increase is the fee, left in the reserves so that each LP token claims a larger inventory. All of it was LP income while the protocol fee was off. [Uniswap’s UNIfication proposal](https://blog.uniswap.org/unification) turns the fee on by splitting the 0.30 percent into 0.25 for LPs and 0.05 for the protocol, and a [later proposal](https://vote.uniswapfoundation.org/proposals/100) says protocol fees are now live on all v2 pools on 11 chains. The trader’s quote is the same either way.

A sketch of the quote, with the rounding made obvious, is on the [Uniswap](https://protocols.davidgarciab.com/protocols/uniswap) page. The deployed pair does not trust the caller’s arithmetic. It measures token balances. If the product check fails, the swap reverts. There is no partial fill.

## A worked swap

Take a v2 pool that holds 100 ETH and 300,000 USDC, and ignore token decimals. The spot price is 300,000 / 100 = 3,000 USDC per ETH. A trader sends 1 ETH. `getAmountOut` in the v2 periphery library ([`UniswapV2Library.sol` at `87edfdca`](https://github.com/Uniswap/v2-periphery/blob/87edfdcaf49ccc52591502993db4c8c08ea9eec0/contracts/libraries/UniswapV2Library.sol), last read on 1 December 2026) multiplies the input by 997 and the reserve by 1,000:

```text
Worked arithmetic for the example above, not contract code.

amountInWithFee = 1 × 997                               = 997
amountOut       = 997 × 300,000 / (100 × 1,000 + 997)
                = 299,100,000 / 100,997                 ≈ 2,961.47 USDC
```

The trader pays an average of 2,961.47 USDC per ETH, 1.28 percent below the 3,000 spot price. Without the fee the same trade would return 2,970.30 USDC, so about 0.99 percentage points of the gap is the curve and the rest is the fee. After the trade the pool holds 101 ETH and 297,038.53 USDC. The new spot price is 2,940.98, and the next buyer of ETH starts from there.

The product moved from 30,000,000 to about 30,000,891, up 0.003 percent. That growth is the 0.003 ETH of fee that the formula did not count toward the trade. It stays in the reserves. Where the protocol fee is on, one sixth of that fee accrues to the protocol and the rest to the LPs.

Size is what changes the picture. A 10 ETH input into the same pool returns 27,198.33 USDC, an average of 2,719.83: 9.34 percent below spot, of which the fee is still only a small part. The trade is a tenth of the ETH reserve, and the curve charges for that.


## Where the rule is local

v3 and v4 do not keep one `k` for the entire price line. The v3 whitepaper gives each range a liquidity `L` that acts like a product curve between two prices. Outside the range the position has no active liquidity. Talking about “the pool’s k” as a single number is a v2 habit.

Curve’s derivation mixes a constant-sum term with a product term. Near equal balances and with a high amplification coefficient, trades barely move the price, which is the constant-sum end. Far from balance, the product term is what still offers a price instead of letting the pool sell the last coin at one-for-one until it is gone. StableSwap is not “constant product with a different fee.” The fee is separate. The invariant is different. The picture on the [Curve](https://protocols.davidgarciab.com/protocols/curve) page is only a sketch of that bend.

## Rounding and the empty pool

Integer reserves round in favor of the pool when the implementation is careful. A quote that uses floating point will not match. A pool with zero of one reserve cannot sell that reserve at any finite price, because the product would require infinite input. v2’s library rejects empty reserves. A concentrated position that has been traded entirely into one asset is the same fact inside its range: there is nothing of the other asset left to buy until the price re-enters and the liquidity is active again.

## Questions

**What does x · y = k mean in a Uniswap v2 pool?**

`x` and `y` are the two reserves and their product is `k`. The pool agrees to any trade that does not shrink `x * y` after fees. The last unit of `y` costs more than the first because the reserve of `y` is shrinking while the reserve of `x` is growing.

**Where does the Uniswap v2 swap fee go?**

The v2 flash-swap guide puts the fee at 0.30 percent on the input, implemented by counting only 99.7 percent of the input toward the product check. The pool can therefore increase `k` slightly, and the fee stays in the reserves. All of it went to LPs while the protocol fee was off. Where governance has turned it on, since December 2025, LPs earn 0.25 percent and 0.05 percent goes to the protocol.

**Does constant-product pricing hold in Uniswap v3 and Curve?**

Not uniformly. The rule is uniform across all prices in v2, only inside a tick range in v3 and v4, and only the outer region of a Curve StableSwap pool.

## Sources

- UNIfication proposal (Uniswap Labs): https://blog.uniswap.org/unification
- Activate v4 Protocol Fees (Part 1/2) (Uniswap): https://vote.uniswapfoundation.org/proposals/100
- UniswapV2Library.sol at 87edfdca (Uniswap): https://github.com/Uniswap/v2-periphery/blob/87edfdcaf49ccc52591502993db4c8c08ea9eec0/contracts/libraries/UniswapV2Library.sol
- How Uniswap works (Uniswap): https://developers.uniswap.org/docs/get-started/concepts/how-uniswap-works
- Using flash swaps (Uniswap): https://developers.uniswap.org/docs/protocols/v2/guides/flash-swaps
- Uniswap v3 Core whitepaper (Uniswap): https://uniswap.org/whitepaper-v3.pdf
- StableSwap derivations (Curve): https://docs.curve.finance/developer/resources/derivations
