- Authors
What is an AMM?
An AMM (Automated Market Maker) is a system that uses algorithms to automatically determine asset prices.
In traditional exchanges, you place orders like "I'll sell at this price" or "I'll buy at that price," and trades execute when matching orders are found.
However, in AMMs, algorithms automatically determine prices based on supply and demand:
- If many people buy an asset → its quantity decreases → price goes up
- If many people sell an asset → its quantity increases → price goes down
In essence, it's the law of supply and demand implemented through algorithms.
Traditional Exchange vs AMM
How Traditional Exchanges Work
Traditional exchanges use an Order Book system.
Apple Marketplace Example
You're a potato farmer, and after eating potatoes every day, you crave apples.
There's a marketplace in your village where trading works like this:
Sellers place orders
- Alice: "I'll sell 100 apples at $1.02 each"
- Bob: "I'll sell 200 apples at $1.01 each"
Buyers also place orders
- Charlie: "I'll buy 150 apples at $0.99 each"
- David: "I'll buy 100 apples at $0.98 each"
Trade executes when prices match
- If you say "I'll buy apples at $1.01 each," your order matches with Bob's and the trade is completed.
Problems
- ❌ Both buyer and seller must be present for a trade to happen
- ❌ With low trading volume, you might not get the price you want
- ❌ Requires a centralized exchange
How AMM Works
AMM uses a completely different approach. The key is that there's no order book. Instead, you directly exchange assets in a Liquidity Pool.
The Constant Product Formula: x × y = k
The core of AMM is a very simple mathematical formula:
x × y = k
Where:
- x = Quantity of the first asset (e.g., apples)
- y = Quantity of the second asset (e.g., potatoes)
- k = Constant (always stays the same)
Real Trade Example
The liquidity pool currently has:
- Apples: 100
- Potatoes: 100
- k = 100 × 100 = 10,000
Example 1: Exchanging 10 Potatoes for Apples
You bring 10 potatoes and want to exchange them for apples.
- Add potatoes to the pool: 100 + 10 = 110
- Calculate new apple quantity: k ÷ new potatoes = 10,000 ÷ 110 = 90.9
- Apples you receive: 100 - 90.9 = 9.1 apples
Why do you get only 9.1 when you gave 10?
When you add potatoes, the pool has more potatoes, so potato price drops. When apples are removed, the pool has fewer apples, so apple price rises.
Prices after the exchange:
- Price per apple: 110 ÷ 90.9 = 1.21 potatoes
- Price per potato: 90.9 ÷ 110 = 0.83 apples
Apples went from 1.00 to 1.21 (more expensive), and potatoes went from 1.00 to 0.83 (cheaper).
Example 2: Exchanging 20 More Potatoes
Another person brings 20 potatoes to exchange for apples.
Current pool state:
- Apples: 90.9
- Potatoes: 110
- Add potatoes to the pool: 110 + 20 = 130
- New apple quantity: 10,000 ÷ 130 = 76.9
- Apples received: 90.9 - 76.9 = 14 apples
This time they gave 20 and got 14. A worse ratio than the first person.
Because apples kept decreasing, they became more expensive.
Prices after the exchange:
- Price per apple: 130 ÷ 76.9 = 1.69 potatoes
- Price per potato: 76.9 ÷ 130 = 0.59 apples
Price Impact
Even for the same exchange amount, the pool size makes the price impact completely different.
Why Pool Size Matters
The exchange ratio relative to pool size determines price impact:
- Small pool: 10/100 = 10% exchange → Big price shock
- Medium pool: 10/10,000 = 0.1% exchange → Almost no impact
- Large pool: 10/1,000,000 = 0.001% exchange → Negligible
This is why TVL (Total Value Locked) is important in DEXs.
Greater liquidity provides a better trading environment:
- Reduced price impact: Prices don't change much even with large trades
- Reduced slippage: Difference between expected and actual execution price decreases
- Fairer pricing: Trade at prices closer to market price
What is Slippage?
Slippage refers to the difference between the price you expected when starting a trade and the actual execution price.
For example:
- You see apple price at 1.00 potato and start exchanging 10 potatoes
- You actually receive 9.1 apples (average price 1.10 potatoes)
- Slippage = 10%
Slippage occurs because the pool ratio changes the moment the trade executes. Slippage is especially high when trading large amounts in small pools.
Liquidity Providers (LP)
AMMs require someone to deposit assets into the pool to function. These people are called Liquidity Providers (LPs).
How to Become an LP
Deposit both assets simultaneously
- Example: 100 ETH + 300,000 USDT (at current price ratio)
Receive LP tokens
- Tokens representing your share in the pool
Earn trading fees
- 0.3% of all trades in the pool (Uniswap standard)
- Distributed proportionally to your share
LP Earnings and Risks
Earnings:
- ✅ Trading fee income
- ✅ 24/7 automatic earnings
- ✅ Passive income
Risks:
- ⚠️ Impermanent Loss
- Price changes can result in losses compared to just holding
- If price returns to original, the loss disappears
- ⚠️ Smart Contract Risk
- Possibility of bugs or hacks
Understanding Impermanent Loss
Impermanent loss is the biggest risk for LPs. Let's look at a simple example.
Initial State:
You provide liquidity to an ETH-USDT pool.
- 1 ETH = $5,000
- Deposit 1 ETH + 5,000 USDT (total value $10,000)
Scenario 1: ETH Price Doubles ($10,000)
In an AMM pool, x × y = k must be maintained, so:
- Arbitrageurs buy ETH with USDT, automatically adjusting the pool ratio
- Final pool state: 0.707 ETH + 7,071 USDT
- Your share value: $14,142
If you had just held:
- 1 ETH (15,000
Loss: 14,142 = $858 loss (about 5.7%)
Scenario 2: ETH Price Returns to Original ($5,000)
When the price returns to original:
- Pool returns to original ratio: 1 ETH + 5,000 USDT
- Loss disappears (impermanent)
Key Points:
Greater price changes mean greater losses
- 2x price change: about 5.7% loss
- 4x price change: about 20% loss
- Price change and loss have a non-linear relationship (losses increase rapidly with larger changes)
Loss occurs in both directions
- Whether ETH goes up or down, any change causes loss
- The further from initial price, the greater the loss
- If price returns, loss also disappears (hence "impermanent")
Trading fees can offset losses
LPs receive fees from all trades in the pool. These fee earnings can offset impermanent loss.
Example
- Deposit $10,000 in ETH-USDT pool
- Impermanent loss: $858 (5.7%)
- Daily trading volume: $1,000,000
- Pool size: $10,000,000 (your share 0.1%)
- Daily fees (0.3%): $3,000
- Your fee earnings: $3 (0.1% share)
- Annual fee earnings: $1,095 (about 11%)
In this case, even with a 5.7% impermanent loss, it is sufficiently offset by the fees earned.
Favorable Conditions for LPs
- High trading volume (increases fee income)
- Stable prices (reduces impermanent loss)
- Stablecoin pairs (pairs with low price volatility like USDT-USDC)