← Back to Blog

How Automated Market Makers Work: Uniswap, Curves & the x*y=k Formula

January 5, 2026 · 16 min read

Automated market makers (AMMs) are the backbone of decentralized finance. They replaced traditional order books with elegant mathematical formulas, enabling anyone to trade tokens 24/7 without intermediaries. But this same mathematical predictability is what makes AMMs exploitable by MEV bots like JaredFromSubway. In this comprehensive guide, we break down how AMMs work from first principles, walk through the constant product formula with real numbers, and explain why AMM mechanics create some of the most profitable MEV extraction opportunities in crypto.

What is an Automated Market Maker (AMM)?

An automated market maker is a type of decentralized exchange (DEX) protocol that uses a mathematical formula to price assets instead of relying on a traditional order book with buyers and sellers. Liquidity providers deposit pairs of tokens into smart contract pools, and traders swap against these pools at prices determined algorithmically. The most well-known AMM is Uniswap, which uses the constant product formula x * y = k. Other AMM designs include Curve's StableSwap and Balancer's weighted pools, each optimized for different trading use cases.

Traditional Order Books vs. AMMs

In traditional finance and on centralized exchanges like Binance and Coinbase, trading uses an order book model. Buyers place bids at prices they're willing to pay, sellers place asks at prices they're willing to sell, and trades execute when a bid matches an ask. This requires active market makers — professional firms that constantly quote buy and sell prices to provide liquidity. The spread between bid and ask is how market makers profit.

Order books work well on centralized platforms with high throughput and low latency, but they are impractical on blockchains. Ethereum processes roughly 15 transactions per second with 12-second block times. Maintaining an on-chain order book would be prohibitively expensive in gas fees and too slow for professional market makers to update their quotes.

AMMs solved this problem entirely. Instead of matching individual orders, they pool liquidity into a smart contract and use a deterministic formula to calculate the exchange rate for every trade. Anyone can become a liquidity provider by depositing tokens into the pool, and anyone can trade against the pool at any time. There are no order books, no bid-ask spreads in the traditional sense, and no need for professional market makers.

This innovation unlocked permissionless trading for thousands of tokens that would never be listed on centralized exchanges. But it also introduced a critical vulnerability: because pricing is deterministic and transparent, bots like JaredFromSubway can predict exactly how any trade will affect the price and exploit that predictability for profit.

The Constant Product Formula: x * y = k

The constant product formula is the mathematical heart of Uniswap and most AMMs. It states that the product of the reserves of two tokens in a liquidity pool must remain constant before and after every trade (excluding fees). If a pool holds x units of Token A and y units of Token B, then x * y = k, where k is a constant.

When a trader wants to buy Token A, they deposit Token B into the pool. The pool's supply of Token B increases, and to maintain the constant product, the pool's supply of Token A must decrease. The trader receives the difference in Token A. The exchange rate emerges naturally from the ratio of reserves.

Numerical Example: ETH/USDC Pool

Imagine a Uniswap pool with 100 ETH and 200,000 USDC. The constant product k is:

x = 100 ETH

y = 200,000 USDC

k = 100 * 200,000 = 20,000,000

Implied price: 200,000 / 100 = 2,000 USDC per ETH

Now suppose a trader wants to buy 5 ETH. The pool needs to maintain k = 20,000,000. After the trade, the pool will have 95 ETH, so the new USDC reserve must be:

New USDC reserve = k / new ETH reserve

New USDC reserve = 20,000,000 / 95 = 210,526.32 USDC

USDC the trader pays = 210,526.32 - 200,000 = 10,526.32 USDC

Effective price per ETH = 10,526.32 / 5 = 2,105.26 USDC

Notice the trader paid an effective price of 2,105.26 USDC per ETH, not the initial spot price of 2,000 USDC. That 5.26% premium is the price impact — the cost of moving the pool's reserves. This is the fundamental mechanic that slippage refers to, and it is precisely what MEV bots exploit.

Price Impact: Why Larger Trades Move Prices More

Price impact is nonlinear in constant product AMMs. A trade that is twice as large does not simply cost twice as much in slippage — it costs disproportionately more. This is because the constant product curve is a hyperbola, and as you move further along it, prices change more rapidly.

Using our ETH/USDC pool example:

Buying 1 ETH: costs 2,020.20 USDC (effective price: 2,020.20, impact: 1.01%)

Buying 5 ETH: costs 10,526.32 USDC (effective price: 2,105.26, impact: 5.26%)

Buying 10 ETH: costs 22,222.22 USDC (effective price: 2,222.22, impact: 11.11%)

Buying 20 ETH: costs 50,000.00 USDC (effective price: 2,500.00, impact: 25.00%)

This nonlinear price impact is critical for MEV. When JaredFromSubway detects a large pending swap in the mempool, it calculates the exact price impact that trade will cause. The larger the victim's trade relative to pool liquidity, the more profit a sandwich attack can extract. Small trades in deep pools produce negligible price impact and are not worth sandwiching. Large trades in shallow pools are the most profitable targets.

Concentrated Liquidity: Uniswap V3

Uniswap V2 distributes liquidity uniformly across the entire price range from zero to infinity. This means most of the liquidity in the pool sits at prices that will never be reached — a massive inefficiency. If ETH trades at $2,000, liquidity allocated to the $10 or $50,000 price range is essentially unused capital.

Uniswap V3 introduced concentrated liquidity, allowing liquidity providers (LPs) to allocate their capital to specific price ranges. Instead of spreading liquidity from $0 to infinity, an LP can concentrate their entire position in the $1,800–$2,200 range. Within that range, their capital provides the same depth as a much larger position in Uniswap V2.

Concentrated liquidity is dramatically more capital efficient. An LP concentrating in a narrow range can provide the same effective liquidity as an LP with 100x or even 4,000x more capital in a V2-style pool. This means traders experience lower price impact on their swaps, and LPs earn more fees per dollar of capital deployed.

However, concentrated liquidity also changes the MEV landscape. Narrower ranges mean that price impact can vary significantly across different tick boundaries. Bots like JaredFromSubway must account for the distribution of concentrated liquidity positions when simulating sandwich attacks, making the calculations more complex but the opportunities potentially more lucrative when liquidity is thin just outside popular ranges.

Impermanent Loss Explained Simply

Impermanent loss is the cost of providing liquidity to an AMM compared to simply holding the tokens in your wallet. It occurs whenever the price ratio of the two tokens in the pool changes from the ratio at which you deposited them.

Here is a simplified example. You deposit 1 ETH and 2,000 USDC into a pool when ETH is priced at $2,000. Your total value is $4,000. Now suppose ETH rises to $4,000. If you had just held your tokens, you would have 1 ETH ($4,000) + 2,000 USDC = $6,000. But the AMM rebalanced your position. The constant product formula pushes the pool to hold less ETH and more USDC as ETH's price rises. Your share of the pool is now worth approximately $5,657 — a loss of about $343 or 5.7% compared to holding.

The loss is called "impermanent" because if the price returns to the original ratio, the loss disappears. But in practice, prices rarely return to exactly the same point, and many LPs experience permanent loss of value. The trading fees earned from the pool may or may not compensate for this loss, depending on volume and the magnitude of price changes.

Impermanent loss is especially relevant to MEV because sandwich attacks and arbitrage trades contribute to the price movements that cause impermanent loss for LPs. In a sense, MEV extraction by bots like JaredFromSubway is partially funded by the impermanent loss experienced by liquidity providers.

How AMMs Enable MEV: Price Manipulation Through Large Swaps

The deterministic nature of AMM pricing is both their greatest strength and their biggest vulnerability. Because the constant product formula makes every price movement perfectly predictable, MEV bots can simulate any pending transaction and know exactly what will happen to the price before the transaction is even included in a block.

When a trader submits a large swap on Uniswap, that transaction sits in the public mempool waiting to be included in a block. MEV bots monitor the mempool continuously, decoding every pending transaction. When they detect a large swap, they calculate the exact price impact it will cause using the constant product formula and the current pool reserves.

This predictability enables two primary MEV strategies. First, arbitrage: after a large swap moves the price on one AMM, bots immediately trade on other AMMs or exchanges where the price has not yet adjusted, capturing the difference. Second, sandwich attacks: bots place their own buy transaction before the victim's swap (front-run), let the victim's swap push the price higher, then sell immediately after (back-run) to capture the price difference as profit.

How JaredFromSubway Exploits AMM Math for Sandwich Attacks

JaredFromSubway is arguably the most successful sandwich bot in Ethereum's history, having extracted tens of millions of dollars in MEV profits. The bot's strategy is built directly on top of AMM mathematics. Here is how it works step by step:

  1. Mempool scanning: JaredFromSubway runs infrastructure that monitors every pending transaction on Ethereum. It identifies large swaps on Uniswap and other AMMs by decoding transaction calldata.
  2. Simulation: For each candidate transaction, the bot simulates the trade against the current pool state using the constant product formula. It calculates the exact price impact the victim's swap will cause.
  3. Optimal sizing: The bot determines the optimal size for its front-run transaction. Too large and the victim's transaction reverts due to exceeding slippage tolerance. Too small and the profit is not worth the gas cost. The sweet spot maximizes extracted value while keeping the victim's trade within its slippage bounds.
  4. Bundle submission: Using Flashbots, JaredFromSubway submits a transaction bundle to block builders: front-run buy, victim's swap, back-run sell. The bundle executes atomically — all three transactions in the specified order or none at all.
  5. Profit capture: The back-run sell executes at a higher price than the front-run buy, and the difference (minus gas and builder tips) is pure profit.

The entire process relies on the mathematical certainty of AMM pricing. Without the deterministic x * y = k formula, sandwich attacks would be impossible because the bot could not predict the price impact of the victim's trade. This is why AMMs are both revolutionary and exploitable — the same transparency that enables permissionless trading also enables MEV extraction.

Want to Profit from AMM Mechanics?

JaredFromSubway provides automated MEV extraction with real-time mempool monitoring, Flashbots integration, and optimized sandwich execution across Uniswap V2, V3, and other AMMs.

Start Extracting MEV

Different AMM Types: Constant Product, StableSwap, and Weighted Pools

Not all AMMs use the same formula. Different curve designs optimize for different use cases, and understanding these differences is essential for both traders and MEV operators.

Constant Product: Uniswap

Uniswap's x * y = k is the simplest and most widely used AMM formula. It works for any token pair and never runs out of liquidity (prices approach infinity but never reach zero reserves). The tradeoff is high price impact for large trades relative to pool size. Uniswap V2 pools use this formula directly; Uniswap V3 uses it within concentrated liquidity ranges, creating a virtual constant product curve within each tick range.

StableSwap: Curve Finance

Curve Finance designed the StableSwap invariant specifically for tokens that should trade near a 1:1 ratio — stablecoins like USDC/USDT/DAI, or wrapped assets like stETH/ETH. The StableSwap curve behaves like a constant sum formula (x + y = k) near the peg, offering extremely low price impact for trades that keep the ratio close to 1:1. But as the ratio deviates, the curve transitions toward a constant product shape, providing the safety of guaranteed liquidity at all prices.

This design makes Curve the dominant AMM for stablecoin trading, with billions of dollars in liquidity. MEV opportunities on Curve tend to involve arbitrage between Curve pools and other venues rather than sandwich attacks, since the low price impact makes sandwiching less profitable.

Weighted Pools: Balancer

Balancer generalizes the constant product formula to support pools with unequal weightings and more than two tokens. Instead of requiring 50/50 deposits, a Balancer pool can hold 80% ETH and 20% USDC, or even a pool with eight different tokens at varying weights. The formula becomes a weighted geometric mean: x^w1 * y^w2 = k, where w1 and w2 are the token weights.

This flexibility enables use cases like index fund-style portfolios that automatically rebalance. For MEV extraction, Balancer pools present unique opportunities because the multi-token design creates more complex arbitrage paths and the weighted formula produces different price impact characteristics than standard constant product pools.

Frequently Asked Questions

What is an automated market maker (AMM)?

An automated market maker is a decentralized exchange protocol that uses mathematical formulas instead of order books to determine asset prices. Liquidity providers deposit token pairs into smart contract pools, and traders swap against these pools at algorithmically determined rates. The most common formula is the constant product formula x * y = k, used by Uniswap. AMMs enable permissionless, 24/7 trading of any ERC-20 token pair.

How does the constant product formula x*y=k work?

In the x * y = k formula, x and y represent the reserves of two tokens in a liquidity pool, and k is a constant that must remain unchanged after every trade (before fees). When a trader buys Token A, they add Token B to the pool and remove Token A. The formula ensures the product of reserves stays constant, which causes the price to increase as supply of the purchased token decreases. This is why larger trades have proportionally greater price impact.

What is impermanent loss in AMMs?

Impermanent loss is the difference in value between holding tokens in an AMM liquidity pool versus simply holding them in your wallet. It occurs whenever the price ratio of the pooled tokens diverges from the ratio at which you deposited. A 2x price change results in approximately 5.7% impermanent loss; a 5x change results in about 25.5%. The loss is "impermanent" because it reverses if prices return to the original ratio, but in practice many LPs experience permanent value reduction.

How do MEV bots exploit AMMs?

MEV bots exploit the deterministic pricing of AMMs by front-running and sandwich-attacking large trades. Because the constant product formula makes price impact perfectly predictable, bots like JaredFromSubway can calculate exactly how a pending swap will move the price, place a buy order before it (front-run), let the victim's trade push the price higher, then sell immediately after (back-run) to capture the difference as profit. The bot uses Flashbots to guarantee transaction ordering within a block.

Ready to Leverage AMM Mathematics?

JaredFromSubway turns AMM predictability into consistent profits. Access institutional-grade MEV extraction with automated sandwich execution, cross-DEX arbitrage, and Uniswap V3 concentrated liquidity strategies.

Launch Your MEV Bot