π What is an AMM?
An Automated Market Maker (AMM) is a type of decentralized exchange protocol that uses smart contracts and mathematical formulas to price assets and provide liquidity automatically. Unlike traditional exchanges that rely on order books and market makers to facilitate trades, AMMs use liquidity pools β collections of tokens locked in smart contracts β to enable peer-to-pool trading.
The AMM model was pioneered by Uniswap in 2018 and has since become the foundation of the DeFi ecosystem. Instead of matching buyers and sellers, AMMs allow traders to swap tokens directly against a pool of liquidity provided by users. This creates a fully automated, permissionless trading system that operates 24/7 without intermediaries.
An AMM replaces the traditional order book with a mathematical formula. Instead of waiting for a buyer or seller to match your order, you trade directly against a pool of tokens whose price is determined by an algorithm.
βοΈ How Does an AMM Work?
AMMs operate through a combination of smart contracts and liquidity providers. Here's how the process works step by step:
1. Liquidity Providers Deposit Tokens
Users known as Liquidity Providers (LPs) deposit pairs of tokens into a liquidity pool. For example, they might deposit ETH and USDT into a pool. In return, they receive LP tokens that represent their share of the pool and entitle them to a portion of the trading fees.
2. Traders Swap Tokens
When a trader wants to swap Token A for Token B, the smart contract automatically calculates the price based on the pool's current reserves and executes the trade. The trader pays a small fee (typically 0.05% to 0.3%) which is distributed to the liquidity providers.
3. Price Determination via Formula
The price is determined by a mathematical formula. The most common is the constant product formula (x * y = k), which ensures that the product of the two token amounts in the pool remains constant.
Think of an AMM liquidity pool as a vending machine. The vending machine always has some inventory of two items. When you buy one item (swap Token A for Token B), the machine automatically adjusts the price based on how much inventory is left. The more of one item you take, the more expensive the next unit becomes.
π The Constant Product Formula: x * y = k
The constant product formula is the mathematical foundation of the most popular AMMs, including Uniswap. Here's how it works:
y = Amount of Token B in the pool
k = Constant product (remains the same)
When a trade occurs, the pool is rebalanced so that the product of the two token amounts remains constant. For example, if a pool has 100 ETH and 200,000 USDT, k = 100 * 200,000 = 20,000,000. If a trader swaps 1 ETH for USDT, the pool will have 101 ETH and approximately 198,019 USDT, and the product remains 20,000,000 (with slight variance due to fees).
This formula creates an inverse relationship between the two token prices. As the supply of one token in the pool increases, its price decreases relative to the other token. The price is always determined by the current ratio of the two tokens in the pool.
Because the formula uses a constant product, large trades will have a significant price impact β they will move the price unfavorably. This is known as slippage. Traders should always check the expected price and slippage tolerance before executing a trade.
Example Calculation
| Step | ETH in Pool | USDT in Pool | k (constant) | Price of ETH |
|---|---|---|---|---|
| Initial | 100 ETH | 200,000 USDT | 20,000,000 | 2,000 USDT |
| After Swap (1 ETH β USDT) | 101 ETH | ~198,019 USDT | 20,000,000 | ~1,960 USDT |
| After Swap (10 ETH β USDT) | 110 ETH | ~181,818 USDT | 20,000,000 | ~1,653 USDT |
π Liquidity Pools Explained
A liquidity pool is a smart contract that holds reserves of two or more tokens. It is the core component of an AMM system. Here's what you need to know:
- Token Pairs: Each pool typically holds two tokens (e.g., ETH/USDT, BTC/USDT, or stablecoin pairs like USDT/USDC).
- Liquidity Providers: Users who deposit tokens into the pool. In return, they earn a portion of the trading fees (usually 0.05% to 0.3% per trade).
- LP Tokens: Tokens issued to liquidity providers representing their share of the pool. These can be used to redeem the underlying tokens later.
- Pool Value: The value of a liquidity pool fluctuates based on token prices and trading activity.
By providing liquidity, you earn a share of the trading fees generated by the pool. However, you also take on risks such as impermanent loss. It's important to understand these risks before becoming an LP.
β οΈ Impermanent Loss in AMMs
Impermanent loss is one of the most important concepts for liquidity providers to understand. It refers to the temporary loss of value that occurs when the price ratio of two tokens in a liquidity pool changes.
When you deposit tokens into a pool, the AMM automatically rebalances the pool to maintain the constant product. If the price of one token increases relative to the other, the pool will sell some of the appreciating token and buy more of the depreciating token. This means you would have been better off just holding the tokens instead of providing liquidity.
Impermanent loss is only realized if you withdraw your liquidity. If the prices return to the original ratio, the loss disappears β hence the term "impermanent." However, if you withdraw while prices have diverged, the loss becomes permanent.
Impermanent Loss Examples
| Price Change (Token A) | Approximate Impermanent Loss |
|---|---|
| Β± 1.25x (25% change) | ~0.6% |
| Β± 1.5x (50% change) | ~2.0% |
| Β± 2x (100% change) | ~5.7% |
| Β± 3x (200% change) | ~13.4% |
| Β± 5x (400% change) | ~25.5% |
Consider providing liquidity to stablecoin pairs (USDT/USDC) where price divergence is minimal. Alternatively, provide liquidity to pools with tokens you believe will move together. Impermanent loss is also less of a concern during periods of low volatility.
β Popular AMM Platforms
Here are the most widely used AMM platforms in the DeFi ecosystem:
The pioneer of the AMM model on Ethereum. Available on multiple chains including Ethereum, Polygon, Arbitrum, and Optimism.
The leading AMM on BNB Chain, known for low fees, gamified features, and a strong community.
A community-driven AMM with a focus on innovation, cross-chain compatibility, and a strong DAO structure.
Specialized in stablecoin and low-volatility asset trading with minimal slippage and low fees.
A leading AMM on Solana, offering high speed and low transaction costs.
A DEX aggregator that routes through multiple AMMs on Solana to find the best prices.
β Advantages of AMMs
- Permissionless: Anyone can provide liquidity or trade without needing approval.
- 24/7 Operation: AMMs never sleep, unlike traditional market makers.
- No Order Book: Eliminates the need for order books and the complexity of order matching.
- Transparency: All transactions and pool data are on-chain and verifiable.
- Earning Opportunity: Liquidity providers earn passive income from trading fees.
- Asset Accessibility: Enables trading of tokens that might not have enough liquidity on traditional exchanges.
β οΈ Disadvantages & Risks of AMMs
- Impermanent Loss: The most significant risk for liquidity providers.
- Slippage: Large trades can cause significant price slippage, especially in low-liquidity pools.
- Gas Fees: On networks like Ethereum, gas fees can make small trades uneconomical.
- Smart Contract Risks: Bugs or exploits in smart contracts can lead to loss of funds.
- Limited Order Types: Only simple swaps are possible; advanced order types are not available.
- MEV Attacks: Miner Extractable Value (MEV) can be used to front-run or sandwich trade against users.
Always use well-audited AMM platforms with a proven track record. Be aware of the risks of impermanent loss before providing liquidity. Use limit orders via aggregators or consider using AMMs with enhanced security features.
π How to Use an AMM: Step-by-Step Guide
-
1
Connect Your Wallet
Connect a non-custodial wallet like MetaMask, Trust Wallet, or WalletConnect to the AMM platform of your choice (e.g., Uniswap, PancakeSwap).
-
2
Select a Trading Pair
Choose the token you want to swap and the token you want to receive. Make sure you have the correct token contract address if it's not a popular token.
-
3
Set Slippage Tolerance
Set your slippage tolerance β the maximum price change you're willing to accept. A higher tolerance increases the chance of execution but may lead to less favorable prices.
-
4
Enter Amount & Swap
Enter the amount you want to swap. Review the estimated output, fees, and price impact. Click "Swap" and confirm the transaction in your wallet.
-
5
Wait for Confirmation
Wait for the transaction to be confirmed on the blockchain. The swapped tokens will appear in your wallet once the transaction is complete.
π How to Provide Liquidity on an AMM
-
1
Connect Your Wallet
Connect your non-custodial wallet to the AMM platform.
-
2
Select a Pool
Choose a liquidity pool to provide to. Consider factors like trading volume, fees, and the risk of impermanent loss.
-
3
Deposit Tokens
Deposit an equal value of both tokens in the pair (e.g., 50% ETH and 50% USDT). Click "Add Liquidity" and confirm the transaction.
-
4
Receive LP Tokens
You will receive LP tokens representing your share of the pool. These tokens can be used to claim your portion of trading fees and redeem your liquidity.