Automated market makers explained: how AMMs price trades without an order book

Automated market makers explained: how AMMs price trades without an order book

An automated market maker (AMM) is a DeFi protocol that prices and processes swaps using pooled liquidity and a mathematical formula instead of matching individual buyers and sellers. Here’s how AMMs work, how they set prices and why liquidity depth matters when you swap.

When you swap tokens on a decentralized exchange (DEX), there may be no seller waiting on the other side of your trade. Instead, your swap can happen against a pool of tokens whose price changes automatically as you trade.

That mechanism is an automated market maker, or AMM.

AMMs underpin much of DeFi liquidity. But understanding how they work also explains something important about swapping: the same trade can produce different results across different liquidity pools. Price depends on the AMM design, the assets in the pool, its liquidity depth and the size of your swap.

As the team behind the original DEX aggregator, 1inch deals with this fragmentation directly: its routing algorithm evaluates liquidity from multiple sources to find efficient routes for swaps. Now, let’s see what happens inside an AMM, starting with the math.

What is an automated market maker?

An automated market maker is a set of smart contracts that enables token swaps using pooled liquidity and predefined pricing rules. Unlike a traditional order book, an AMM does not need to match your buy order with somebody else's sell order.

Instead, you trade against a liquidity pool. A basic pool might contain two tokens, such as ETH and USDC. Liquidity providers (LPs) supply those assets to the pool. When you swap USDC for ETH, you add USDC to the pool and remove ETH. The AMM's formula recalculates the price based on the pool's new balances.

An order book records bids and asks at different prices and matches buyers with sellers. An AMM instead, effectively creates prices algorithmically from the assets available in its liquidity pool.

The term can be confusing because "market maker" also has a different meaning in traditional finance. Traditional market makers actively quote buy and sell prices. An AMM automates this function through smart contracts and liquidity supplied on-chain.

Different AMMs use different formulas and liquidity structures, but they share the same basic goal: making assets available for swaps without requiring a direct counterparty for every transaction. 

How AMMs actually price a trade

The classic AMM model uses a simple equation:

x × y = k

Here, x is the amount of one token in the pool, y is the amount of the other and k is a constant.

Suppose an ETH/USDC pool contains:

  • 100 ETH
  • 200,000 USDC

Ignoring fees for simplicity:

100 × 200,000 = 20,000,000

So k = 20,000,000.

The ratio of the reserves gives an initial pool price of:

200,000 / 100 = 2,000 USDC per ETH

Now imagine someone swaps 20,000 USDC for ETH.

The pool receives the 20,000 USDC, increasing that side of the pool to 220,000 USDC. To keep the constant product unchanged:

x × 220,000 = 20,000,000

Therefore:

x ≈ 90.91 ETH

The trader receives roughly:

100 − 90.91 = 9.09 ETH

After the trade, the pool holds approximately 90.91 ETH and 220,000 USDC.

The reserve ratio has changed. The pool's marginal price is now approximately:

220,000 / 90.91 ≈ 2,420 USDC per ETH

This mechanism is known as a constant product AMM. It is closely associated with Uniswap and is one of the most familiar AMM designs.

The curve also ensures that buying increasingly large amounts of one asset becomes progressively more expensive. You cannot simply remove all the ETH at the original price. As ETH leaves the pool, its price relative to USDC rises.

Not every AMM uses the same curve. Stablecoin-focused AMMs can use a flatter curve around the expected price of closely correlated assets, allowing larger swaps with less price impact near that point. Other designs use different bonding curves or asset weights to change how liquidity and prices behave.

But the underlying principle remains: the smart contract determines the terms of the swap based on its rules and the state of its liquidity.

What happens when you swap through an AMM

When your wallet shows you a quote, that is not necessarily the exact price at which every part of the swap will take place.

The AMM price changes as your trade changes the pool. Consider the example above. Before the swap, the reserve ratio implies 2,000 USDC per ETH. But swapping 20,000 USDC does not give you 10 ETH. It gives you roughly 9.09 ETH before accounting for fees.

The difference results from price impact. Price impact is the effect your own trade has on the price available from the pool. The larger your trade is relative to the pool's liquidity, the greater that impact tends to be.

A 20,000 USDC swap against a pool containing 200,000 USDC is significant. The same swap against a pool holding 20 mln USDC would generally move the price much less.

Slippage is related but different. It refers to the difference between the price you expect when submitting a transaction and the price you actually receive when it is processed.

Prices can move while your transaction is waiting to be included in a block. Other swaps can change the pool's reserves before yours goes through.

A slippage tolerance sets the maximum deterioration in the swap outcome you are willing to accept. If the available outcome moves beyond that limit, the transaction should revert rather than complete under the changed conditions.

The practical takeaway is straightforward: pool depth matters. Larger trades against shallow liquidity can move an AMM's price substantially.

And because liquidity is spread across many pools and AMMs, the depth available for the same token pair can vary considerably from one source to another.

Liquidity providers and AMM pools

AMMs need assets for traders to swap. Those assets come from liquidity providers. In a traditional two-token AMM, LPs deposit both assets into a pool. In return, they receive a claim on their share of the pool and a portion of the fees generated by swaps.

Historically, that claim has often been represented by LP tokens, although newer AMM designs can represent liquidity positions differently.

Providing liquidity therefore creates a trade-off. LPs can collect swap fees, but the composition and value of their position can change as traders interact with the pool.

One important risk is impermanent loss. It can occur when the relative prices of the assets deposited in a pool change, leaving the LP with a different outcome than simply holding the assets outside the pool.

The mechanics depend on the AMM design and can become more complex with concentrated liquidity. See 1inch's guide to impermanent loss for a detailed explanation.

Some DeFi protocols also add incentives such as liquidity mining on top of the fees generated by the underlying AMM. These incentives are separate from the AMM pricing mechanism itself and can introduce additional risks.

Different AMM designs

Comparing modern AMM mathematical models

There is no single AMM model. Different designs change the relationship between liquidity, pricing and capital efficiency. Three important approaches illustrate those differences.

















Balancer, Curve and Uniswap are examples rather than a ranking. Each design makes different trade-offs.

Concentrated Liquidity Mechanics

Concentrated liquidity allows providers to deposit capital within targeted price ranges rather than distributing liquidity from zero to infinity.

  • Enhanced Capital Multipliers: Concentrated pools achieve deeper effective liquidity around active trading ranges with lower overall capital requirements.
  • Out-of-Range Risk: Liquidity positions stop earning swap fees and convert entirely into the depreciating asset if market prices move outside the configured range.
  • Active Rebalancing Overhead: Capital efficiency requires frequent position management, increasing gas costs and operational complexity for passive providers.

AMMs within the broader DEX ecosystem

A single AMM only shows you part of the picture. The same token pair can trade across multiple AMMs, multiple pools, and multiple blockchain networks at once.

No single AMM reliably offers the best price for every swap. A DEX aggregator checks liquidity across all available sources and routes your swap to the best combination, automatically.

Pool conditions vary in three ways:

  • Depth (how much liquidity is available)
  • Fees (what you pay per swap)
  • Pricing curve (how much the price moves as you trade)

A route does not necessarily have to use just one AMM. Depending on the available liquidity, splitting a swap between different sources can produce a more efficient result than sending the entire amount through one pool.

Imagine two ETH/USDC pools. Pool A offers a slightly better starting price but has relatively shallow liquidity. Pool B starts with a slightly worse price but is much deeper.

Sending a large swap entirely through Pool A could move its price sharply. Dividing the trade between the two pools could reduce total price impact.

This is the logic behind aggregation. 1inch's routing technology evaluates available liquidity to find routes for swaps rather than assuming one AMM will always provide the optimal path.

AMMs are not the only model used by decentralized markets. On-chain and hybrid order books also exist and can be useful for particular markets or trade sizes. But AMMs remain a major source of DeFi liquidity, which makes understanding their mechanics important even when an aggregator handles routing for you.

The real risks of AMMs: MEV, frontrunning, and smart contracts

AMMs automate market making, but they do not remove market or technical risk. One important mechanism to understand is arbitrage. Suppose ETH trades at 2,000 USDC in the wider market but an AMM's pool price implies 1,950 USDC. An arbitrageur can buy ETH from the AMM at the lower price and sell it elsewhere.

That activity changes the pool's reserves and moves its price toward the broader market price. Arbitrage is therefore part of how AMM prices remain aligned with external markets. But the same process affects LPs because arbitrageurs trade against the pool when its internal price diverges from the wider market. That relationship is closely connected to the mechanics of impermanent loss.

MEV creates another execution risk. Because blockchain transactions can be visible before they are finalized, another actor may sometimes be able to place transactions around a pending swap. A sandwich attack is a common example.

Anatomy of an AMM Sandwich Attack

Sandwich attacks target pending swaps broadcasting in the public blockchain mempool:

  1. Detection: A predatory searcher bot scans the public mempool and identifies a high-volume pending AMM swap with loose slippage tolerance.
  2. Frontrun Buy: The bot broadcasts a transaction with a higher gas fee to buy the target asset immediately before the victim's trade, intentionally driving up the pool price.
  3. Victim Execution: The victim's transaction executes at the inflated price, absorbing severe price impact.
  4. Backrun Sell: The bot executes a sell transaction within the same block, dumping the inflated asset back into the pool to capture riskless arbitrage profit.

Appropriate slippage settings can limit how far a swap is allowed to move from the expected outcome, although they do not remove every form of MEV risk.

Finally, AMMs depend on smart contracts. Bugs, unexpected interactions and exploits remain possible even when contracts have been audited. An audit can reduce risk and provide information about the system's security posture, but it cannot guarantee that a contract is bug-free.

Anyone providing liquidity should therefore consider both the economic mechanics of the AMM and the technical risks of the protocol holding or managing the assets.

Understanding AMMs makes aggregation easier 

An automated market maker replaces buyer-seller matching with smart contracts, pooled liquidity and mathematical pricing rules. But the exact mechanics vary considerably between AMM designs.

Constant product AMMs adjust prices as the ratio between two reserves changes. Stableswap models optimize their curves for assets expected to trade at similar prices. Weighted pools support different asset compositions and reserve weights. Concentrated liquidity changes where LP capital is available along the price curve.

Those differences affect price impact, capital efficiency and LP risk. They also explain why aggregation matters. A token can have liquidity spread across many pools using different designs, and the most efficient route can change with the size of your swap and current pool conditions.

If you want to explore the mechanics from the LP side, read What is a liquidity provider? and the guide to impermanent loss.

FAQ

What is the difference between an AMM and an order book?

An order book matches individual buy and sell orders between discrete market participants. An AMM executes trades autonomously against a communal liquidity pool using mathematical pricing formulas.

Why do large swaps experience high price impact on AMMs?

AMMs calculate prices using mathematical invariant curves like xy=k. Large transactions deplete a substantial percentage of the pool's token reserves, driving marginal prices higher along the curve during execution.

Can you lose money providing liquidity to an AMM?

Liquidity providers face impermanent loss when the relative prices of their deposited assets diverge from their original deposit ratio. Capital may also be exposed to smart contract bugs, exploit vulnerabilities, or low fee yields during stagnant trading periods.

How do DEX aggregators find better rates than individual AMMs?

DEX aggregators evaluate prices and pool depths across hundreds of decentralized exchanges simultaneously. Rather than sending an entire trade to a single pool, aggregators split orders across multiple venues to minimize price impact and avoid slippage.

Trade across every major AMM design on the 1inch app.

Disclaimer : This content is for general information purposes only and does not constitute financial, investment, tax, or legal advice and is not a recommendation to buy or sell any particular digital asset or to employ any specific investment strategy.