How do automated market makers work: pricing swaps with on-chain inventory
AMMs quote prices from pool reserves, so every swap shifts inventory, creates price impact, and invites arbitrage to realign the pool with external markets.
Automated market makers (AMMs) let traders swap tokens against a smart-contract liquidity pool instead of matching on an order book. The pool’s reserves mechanically imply the spot price, and your trade moves those reserves along a curve that worsens your average fill as size grows.
Key Takeaways
- An automated market maker amm quotes a spot price from its reserve ratio, so price is inventory rather than an order-book “quote.” This topic is part of our broader guide to what is defi a practical definition of decentralized finance.
- In constant product pools, swaps move the pool along x*y=k, which guarantees liquidity but makes execution price worse than spot as trade size grows.
- Arbitrageurs keep AMM prices aligned with external markets, and that rebalancing is what creates impermanent loss for LPs versus holding.
- Concentrated liquidity improves capital efficiency by placing liquidity in a chosen price range, but it turns LPing into active position management.
What an AMM is (and why DEXs use it instead of an order book)
“How do automated market makers work” comes down to one practical idea: a smart contract holds two (or more) token reserves, and traders swap against that inventory at a price implied by the reserves. There is no need to find a direct counterparty. The pool is the counterparty.
That design is a core building block of decentralized exchanges because on-chain order books are expensive and slow relative to centralized matching engines. Real-world DeFi usage tends to favor systems that can quote continuously, clear trades deterministically, and remain permissionless. This explainer is part of a broader guide to what is defi a practical definition of decentralized finance, where AMMs sit alongside lending, stablecoins, and bridges as core primitives.
The key mental model is to treat an AMM as a live risk engine. Every swap is an inventory shift. The pool’s “price” is not discovered by bids and asks. It is mechanically implied by what the pool currently holds, and external markets only influence it through arbitrage.
The core mechanism: liquidity pools, reserves, and formula-based pricing
A liquidity pool is a smart contract that holds reserves of token A and token B. In the most common design, the pool enforces a rule that links the two reserves. For Uniswap v2-style pools, that rule is the constant product formula: x*y=k, where x and y are reserves and k is intended not to decrease during swaps (ignoring how fees slightly alter the path you trade against).
This is where the “price is inventory” thesis becomes concrete. In a constant product pool, the instantaneous spot price is implied by the reserve ratio. Paradigm expresses this directly as price_token_A = reserve_token_B / reserve_token_A. Speedrun Ethereum also frames spot price as y/x at the current point on the curve. So if the pool holds 10 ETH and 20,000 USDC, the spot is 2,000 USDC per ETH before any trade.
A swap updates reserves and moves the pool along the x*y=k curve. Larger trades push the pool further along that curve, which creates more price impact. That price impact is not a fee charged by the DEX. It is the mechanical consequence of taking inventory out of a finite pool.
What is the constant product formula
The constant product formula is the rule x*y=k used by constant product market makers (CPMMs). Here, x is the reserve of one token, y is the reserve of the other token, and k is the product that the pool tries to keep from decreasing during swaps. This is the simplest widely used AMM invariant and the baseline for understanding Uniswap v2-style pools.
In practice, x*y=k creates a curve where liquidity is always available, but the marginal price gets worse as one side of the pool is depleted. As reserves of the token you want approach zero, the implied price approaches infinity, which is why the pool cannot be cleanly “drained” at a fixed price.
MoonPay’s worked CPMM example shows the mechanic without calculus. A pool starts at 10 BTC and 250,000 USDT, so k=2,500,000. If a trader adds 50,000 USDT, the pool’s USDT reserve becomes 300,000. To keep k constant, BTC reserves become about 8.33, meaning the trader receives about 1.67 BTC (10 - 8.33). The “so what” is that the pool paid out less BTC per USDT than the initial ratio because the trade moved the pool along the curve.
How do amms set prices
AMMs set prices by quoting from reserves, not by aggregating opinions from limit orders. For constant product pools, the spot price is the reserve ratio at that moment. Paradigm’s statement price_token_A = reserve_token_B / reserve_token_A is the cleanest way to remember it.
The second price that matters is execution price, which is the average price across the whole swap. Speedrun Ethereum describes spot as the tangent slope (y/x) and execution as the secant line between the starting and ending reserve points. Traders feel this as price impact, which grows nonlinearly with trade size relative to pool depth.
External markets still matter, but indirectly. If the pool’s reserve ratio implies a price that differs from centralized venues or other DEX routes, arbitrageurs trade against the pool until the on-chain price is pulled back toward the broader market. That arbitrage flow is the hidden counterparty that keeps AMM prices “honest.”
How a swap is calculated (with a concrete example)
A swap has simple inputs and outputs: you send amountIn of tokenIn to the pool, the contract computes amountOut of tokenOut using the pool’s invariant and fee rules, then reserves update to the new balances.
Speedrun Ethereum provides the Uniswap-style fee-adjusted output formula used in many CPMMs: amountOut = (reserveOut amountInWithFee) / (reserveIn + amountInWithFee), where amountInWithFee = amountIn 0.997 for a 0.3% fee example. The practical point is that fees do not just add a separate line-item cost. They slightly change the curve you trade against by reducing the effective input that moves reserves.
The worked example makes the spot-versus-execution gap tangible. With reserves 10 ETH and 20,000 USDC, swapping 1 ETH with a 0.3% fee gives amountInWithFee = 0.997. Plugging into the formula yields about 1,814.6 USDC out. The spot implied by reserves was 2,000 USDC per ETH, but the execution price is about 1,814.6 because the trade walked the curve.
Why do amms need liquidity providers
AMMs need liquidity providers because the pool’s inventory has to come from somewhere. LPs deposit tokens into the pool, and the smart contract uses those reserves to quote and settle swaps. Without LP capital, the AMM cannot offer meaningful size without extreme price impact.
LPs receive LP tokens representing their share of the pool. Speedrun Ethereum describes first-liquidity math (LP tokens minted as sqrt(amount0 * amount1)) and notes that later LPs must deposit in the current pool ratio to avoid distorting pricing. When LPs remove liquidity, they burn LP tokens and withdraw a proportional share of both reserves.
The “so what” is that LPs are not passive lenders. They are underwriting the pool’s rebalancing. When price moves externally, arbitrageurs trade against the pool to realign it, and the pool’s inventory mix changes. LP returns are a contest between fee income and the cost of being rebalanced by arbitrage.
Key tradeoffs and risks: slippage, price impact, impermanent loss, and MEV
For traders, the headline risk is slippage, which Speedrun Ethereum defines as the difference between the expected price when submitting a trade and the executed price. Some of that is your own price impact from moving reserves. Some comes from other pending trades being mined before yours, network delays, and MEV behaviors like front-running and sandwich attacks.
DEX UIs typically let users set slippage tolerance, and Speedrun Ethereum notes that if execution exceeds that threshold the transaction can revert. In practice, slippage tolerance is not just a “volatility knob.” It is also a protection against transaction ordering risk and MEV. Tight tolerances reduce the chance of a bad fill, but they increase the chance of reverting during fast-moving blocks.
For LPs, the core risk is impermanent loss, which is the underperformance versus simply holding the two tokens when their relative prices diverge. Speedrun Ethereum gives the 50/50 pool IL formula and an example where if ETH doubles versus USDC, IL is about 5.7% versus holding. The mechanism matters more than the label. Arbitrage is what forces the pool to sell the winner and buy the loser as the external price moves, and that is why LPs are often described as “short volatility” on the relative price.
Speedrun Ethereum also warns against using AMM spot prices as an oracle and suggests TWAPs or Chainlink-style references. The practical implication is simple: AMM spot is easy to move with trades, so treating it as a truth source can turn a swap venue into an attack surface.
What are the biggest amms in defi
The biggest AMMs in DeFi are typically the venues that concentrate the most liquidity and routing flow, because depth reduces price impact for a given trade size. Speedrun Ethereum names Uniswap, SushiSwap, and Balancer as core AMM-based DEX examples.
MoonPay highlights Uniswap, Curve, and Balancer as prominent AMM-based DEXs. It also frames Curve as specializing in low-slippage swaps for stablecoins and Balancer as using multi-token pools. The “so what” for users is that AMM design and pool depth matter as much as the brand name. A deep pool on a smaller venue can beat a shallow pool on a famous one, because execution price is determined by reserves.
AMMs are also a family of designs. Speedrun Ethereum compares constant product (general swaps), constant sum (x+y=k), constant mean (used for multi-asset pools), and hybrid stable-swap designs that target low slippage for correlated assets and revert toward CPMM behavior when assets depeg.
What is concentrated liquidity
Concentrated liquidity is the Uniswap v3-style idea that LPs do not have to provide liquidity across the entire price curve. Instead, they allocate liquidity within a chosen price range. Speedrun Ethereum describes this as improving capital efficiency and fee potential because more liquidity is placed where trading actually happens.
The tradeoff is that concentrated liquidity turns LPing into position management. When price moves outside the chosen range, the position becomes one-sided, stops earning fees, and effectively sits as inventory in a single asset. Speedrun Ethereum notes that this can increase impermanent loss risk compared to v2-style full-range liquidity.
In practice, concentrated liquidity changes what “being an LP” means. It is less like depositing into a passive pool and more like choosing where to be the market maker. The range selection is the bet, and the fee income has to compensate for the risk of getting pushed out of range.
How do amms handle large trades
AMMs handle large trades by letting the trader move further along the pricing curve, which is exactly why large trades get worse average execution. Speedrun Ethereum and Paradigm both emphasize that larger trades push further along x*y=k, increasing price impact. The pool will still quote, but it will quote a progressively worse price as reserves are depleted on the output side.
This is also why “slippage” is not just a market condition. It is often self-inflicted by trading meaningful size versus pool depth. MoonPay notes that large trades relative to pool size can cause the final execution price to deviate from the market price at submission, which is the practical definition of slippage traders actually feel.
AMM design variants exist largely to improve large-trade behavior for specific asset types. Speedrun Ethereum describes hybrid stable-swap designs (like Curve’s approach) as aiming for low slippage for tightly correlated assets, while reverting toward CPMM behavior when assets depeg. That last clause is the key risk control. The pool behaves “flat” near parity, but it cannot promise a fixed price when parity breaks.
AMM design variants and evolution (when different math is used)
“AMM” is an umbrella term. Constant product pools dominate general-purpose swaps, but other invariants exist because different markets have different failure modes. Speedrun Ethereum lays out constant sum (x+y=k) as a design that can look attractive for stable pairs, but it has a critical weakness: if price deviates from 1:1, one side can be drained. MoonPay also describes constant sum and argues slippage risk is low because trade size does not affect the pool’s exchange price, while still flagging liquidity concerns for large trades. Both statements can be true in their own frame. Constant sum can feel like low slippage near the peg, but it can also collapse away from it.
Constant mean designs support multi-asset pools and flexible weights, which is why Balancer-style pools can act like on-chain portfolios. Hybrid designs target the stablecoin use case by blending behaviors to keep execution tight near parity.
Across all variants, the same through-line holds. Price is inventory, swaps are inventory shifts, and arbitrage is the enforcement mechanism that ties pool prices back to external markets. That is the practical bridge back to the main what is defi a practical definition of decentralized finance guide, because AMMs are not just “DEX plumbing.” They are a specific way of packaging liquidity, execution, and risk into a smart contract.
← Back to what is defi a practical definition of decentralized finance
Sources
Frequently Asked Questions
What is the difference between spot price and execution price in an AMM?
Spot price is the pool’s instantaneous implied price from its reserve ratio (often expressed as y/x). Execution price is the average price you get across the whole swap as your trade moves reserves along the curve. The gap between them is price impact, and it grows as trade size becomes large relative to pool liquidity.
Why does slippage happen on Uniswap-style AMMs?
Slippage is the difference between the expected price when you submit a swap and the price you receive when it executes. It can come from your own price impact, other transactions being mined before yours, network delays, and MEV behaviors like front-running and sandwich attacks. Many DEXs let users set a slippage tolerance that can revert the trade if execution is worse than the threshold.
What causes impermanent loss for liquidity providers?
Impermanent loss is underperformance versus holding the tokens when their relative prices diverge. As external prices move, arbitrageurs trade against the pool to bring its implied price back in line, which changes the pool’s inventory mix. That rebalancing is the structural source of impermanent loss, while fees are the main offset.
Is an AMM price a reliable oracle price?
AMM spot prices are not designed to be oracles and can be manipulated by trades. Speedrun Ethereum explicitly warns against using spot price as an oracle and points to TWAPs or Chainlink-style references instead. For builders, the practical takeaway is to separate swap execution from price feeds.
How does concentrated liquidity change LP risk?
Concentrated liquidity lets LPs allocate liquidity within chosen price ranges, improving capital efficiency. When price moves out of range, the position becomes one-sided and stops earning fees. That turns LPing into active position management rather than a set-and-forget deposit.