โš™๏ธ AMM Mechanics8 min

How AMMs Work

AMM (Automated Market Maker) is the engine that powers DEXes like Uniswap. Understanding AMMs is crucial for advanced DeFi usage.

The Constant Product Formula

Most AMMs use a simple formula:

x ร— y = k

Where:

  • x = quantity of Token A in pool
  • y = quantity of Token B in pool
  • k = constant that never changes

How Trading Works

When you swap, you add tokens to one side and remove from the other - but k must stay constant.

Example:

Pool has 1000 ETH ร— 1,000,000 USDC = 1,000,000,000 (k)

You want to buy ETH with 10,000 USDC:

  • USDC in pool: 1,000,000 + 10,000 = 1,010,000
  • Solve for new ETH: 1,000,000,000 รท 1,010,000 = 990.1
  • ETH you receive: 1000 - 990.1 = 9.9 ETH

Price Impact & Slippage

Larger trades move the price more. This is slippage:

  • Small trades: minimal slippage
  • Large trades: significant slippage

This is why liquidity matters - more liquidity = less slippage for traders.

Impermanent Loss Preview

The math that makes AMMs work also causes impermanent loss for liquidity providers. We'll cover this in depth next.

โš™๏ธ Understanding xร—y=k is the key to understanding all of DeFi.

You have completed all lessons in this module!