You sell ETH and receive PEPE. Where does the PEPE come from, and who decides how much you get?
In a Uniswap pool, it comes from tokens already deposited by liquidity providers (LPs). A smart contract prices the exchange. You can trade without waiting for someone to place a matching order.
Start with a pool holding 100 ETH and 200,000 PEPE. Its initial price is 2,000 PEPE per ETH. Sell 20 ETH into it: you receive less than 40,000 PEPE because your trade changes that price as it executes.
Increasing the pool to 5× adds both tokens in the same ratio: the starting price stays at 2,000, but the same trade has less impact. Each quote starts from the original reserves.
The examples use invented balances, not market quotes. “ETH” means native ETH in V1/V4 or wrapped ETH (WETH) in V2/V3. The running example sells ETH for PEPE.
Let be the ETH reserve and the PEPE reserve. With fees off, the pool keeps their product constant:
Here, . After you add 20 ETH, the pool must retain enough PEPE to preserve that product:
You receive the difference: 33,333.33 PEPE. That gives three different prices:
| Price | Calculation | PEPE per ETH |
|---|---|---|
| Before the swap | 2,000.00 | |
| Average execution | PEPE received / ETH sold | 1,666.67 |
| After the swap | 1,388.89 |
The starting price applies to a tiny trade. It is not a promise to fill your entire order at that rate. The curve in the experiment is the set of allowed reserve balances; selling ETH moves right and down along it.
V1 charges 0.3% on the input. For input and fee fraction , only counts toward the quote:
But the pool receives all of the input, including the fee. Its actual reserves become and , so their product grows. Turn on the fee in the experiment: the dashed curve shows the larger product after fees.
V1 paired every token with ETH. A token-to-token swap therefore used two pools, with ETH as the intermediate asset. The V1 exchange contract implements this pricing rule and routing through ETH.
V2 lets any two ERC-20 tokens form a pair. A PEPE-to-DAI trade can use a direct pool instead of passing through ETH:
V1 PEPE → ETH → DAI two pools
V2 PEPE → DAI one direct pool, if availableEach pair still uses the same constant-product rule and 0.3% swap fee. Same reserves, same fee, same input: same output. V2 improves which assets can share a pool; it does not make the curve flatter by itself.
A router can still choose several pools when that route offers better execution. A direct pool with little liquidity may quote worse than a deeper indirect route. See the V2 whitepaper for the pair architecture.
A router computes the expected output. The pair checks the balances after the transfers and rejects swaps that violate the fee-adjusted invariant. It does not need an external price feed to accept a swap. The V2 swap documentation explains this balance check.
The remaining limitation is capital allocation: a full-range position provides liquidity from prices approaching zero to prices approaching infinity. LPs cannot choose to use their capital only near the current price.
V3 lets an LP choose a price interval. Capital that previously supported the entire price range can now support trading within a smaller one. With the same starting capital, a narrower position provides more depth inside its range.
The tradeoff is a boundary. As ETH is sold into the position, it accumulates ETH and pays out PEPE. At the lower price limit, its PEPE is exhausted. That position cannot buy any more ETH.
The positions below each start with 100 ETH and 200,000 PEPE at the same price, with fees off. Try Narrow, then sell 120 ETH: only 110 ETH can fill before the position runs out of PEPE.
A real pool combines many LP positions. Their boundaries lie on a discrete price grid called ticks. At the current price, active liquidity is the sum of the positions whose ranges include that price.
The swap moves the price until it reaches the next boundary. Positions ending there leave the active set; positions beginning there enter it. The swap continues using the new active liquidity. Depth can increase or decrease at a boundary, as illustrated in the active liquidity guide.
This is why the path matters: a trade can start in deep liquidity and finish in thin liquidity. A large total deposit does not tell you how much liquidity the trade will meet.
Let be PEPE per ETH and be active liquidity. While stays constant, the virtual reserves are:
For effective ETH input within that interval:
The curve still has constant-product behavior, but virtual reserves are not the tokens actually deposited. A position bounded by and holds, while in range:
These equations power the experiment. It uses a single position and continuous price boundaries to expose the limit clearly; it omits tick rounding, other LPs and fees. In a real pool, other positions can supply further liquidity; the app’s fill requirements determine whether a partial fill is accepted. The V3 whitepaper, sections 2 and 6 derives the model and tick-based execution.
V4 retains a concentrated-liquidity engine and adds hooks: optional contracts called at defined points around swaps and liquidity changes. For example, a hook on a dynamic-fee pool can set the fee before a swap.
Hold the narrow position and 20 ETH input fixed. V3 uses a 0.3% fee; change only the V4 fee to compare output. These are illustrative policies, not V4 defaults.
Hooks can change more than fees, including how amounts are accounted for. A pool's behavior therefore depends on its hook code as well as its liquidity. With equal liquidity and fees, both versions give the same output here. The experiment excludes gas, protocol fees and integer rounding; it does not represent every possible V4 pool. The V4 hooks documentation describes these extension points.
V4 also holds pool state in a shared PoolManager, instead of deploying a separate contract for each pool. Its flash accounting tracks what is owed during an operation and requires those balances to be settled before it finishes. This reduces intermediate token transfers in multi-pool operations. The V4 whitepaper explains the architecture.
These changes allow more kinds of pools and can reduce execution costs. Whether a particular trade gets a better price still depends on the liquidity, fees and hook behavior of the pools it uses.
Price impact is the change caused by your own trade. It is already reflected in the quote. More input relative to available liquidity means worse average execution.
Slippage is the difference between the quote you saw and the execution you actually get. Other swaps may change the pool before your transaction lands. Raising slippage tolerance allows a worse result; it does not improve the price.
If the quote is 33,333.33 PEPE and the tolerance is 1%, a simple minimum-output rule is:
The router reverts if the output falls below the specified minimum; a reverted transaction can still cost gas. Production interfaces must round for token decimals and may apply additional routing rules.
The trader receives PEPE because LPs give it up in exchange for ETH. Fees compensate them for offering that inventory, but fees alone do not measure profit.
If ETH rises relative to PEPE elsewhere, arbitrageurs buy ETH from the pool until its price moves toward the external market. LPs end up with less ETH and more PEPE than they started with. Compared with holding the original tokens, this change in inventory creates a relative shortfall called impermanent loss, measured before fees. Fee income may or may not offset it. The shortfall can persist and becomes realized when the position is closed. See the LP returns explanation.
Concentrating liquidity magnifies the inventory change over a smaller price move. Outside its range, a position holds one token and stops earning swap fees until the price re-enters. Moving the range requires another liquidity action and can incur gas and trading costs.
| Version | New capability | What it does not guarantee |
|---|---|---|
| V1 | Quote from ETH/token reserves | A price that matches the wider market |
| V2 | Direct ERC-20/ERC-20 pools | Less impact for the same reserves and fee |
| V3 | Allocate liquidity to chosen ranges | Depth outside those ranges |
| V4 | Customize pool behavior with hooks | A lower fee or a better quote |
To understand a quote, look at the actual route, liquidity along the trade, and fees. The version number alone cannot tell you how much you will receive.