#explain-card
## Introduction & Definition
**Automated [[Market maker|Market Makers]] ([[AMM|AMMs]])** are decentralized exchange ([[DEX]]) protocols that rely on mathematical formulas to price assets. Instead of using traditional order books where buyers and sellers place bids and asks, AMMs use **[[Liquidity|liquidity]] pools** — [[Smart contract|smart contracts]] holding reserves of two or more tokens — to facilitate trades. Users trade directly against these pools.
**Analogy/ELI5:** Imagine a vending machine that always has two types of snacks. When you buy one snack, the machine automatically adjusts the price of that snack to be slightly higher (because there's less of it) and the price of the other snack to be slightly lower (because there's relatively more of it). AMMs work similarly with tokens.
**Importance & Purpose:** AMMs are crucial in the [[Decentralized finance|Decentralized Finance]] ([[DeFI|DeFi]]) ecosystem because they:
- Enable permissionless and automated trading of digital assets.
- Provide continuous liquidity, even for less popular tokens.
- Allow anyone to become a liquidity provider and earn fees.
- Form a foundational layer for many other DeFi applications.
**Historical Context & Evolution:** The concept of AMMs was popularized by platforms like Uniswap, drawing inspiration from earlier ideas about on-chain market makers. Since their inception, various AMM designs have emerged, each with different formulas and targeting specific use cases (e.g., Curve for [[Stablecoin|stablecoins]], Balancer for multi-asset pools).
## Core Principles & Detailed Mechanism
**Key Components/Elements:**
- **Liquidity Pools:** These are smart contracts that hold reserves of two or more tokens. Traders swap tokens with these pools.
- **Liquidity Providers (LPs):** Users who deposit their tokens into liquidity pools. In return, they typically receive LP tokens representing their share of the pool and earn a portion of the trading fees.
- **Mathematical Formula (Pricing Algorithm):** This is the core of an AMM. It determines the price of tokens in a pool based on their relative quantities. The most common is the constant product formula (x \* y = k), where 'x' and 'y' are the quantities of two tokens in the pool, and 'k' is a constant. When a trade occurs, the quantities of 'x' and 'y' change, but 'k' must remain constant (excluding fees and new liquidity), thus dictating the new price.
**In-depth Mechanism/How it Works:**
1. **Liquidity Provision:** LPs deposit a pair of assets into a liquidity pool (e.g., ETH and DAI). The initial ratio of these assets sets the initial price.
2. **Trading:** A trader wants to swap Token A for Token B. They send Token A to the liquidity pool. The AMM's formula calculates how much of Token B the trader receives based on the current pool ratio and the size of the trade. The pool now has more of Token A and less of Token B.
3. **Price Adjustment:** Because the ratio of Token A to Token B has changed, the price of Token A (relative to Token B) decreases, and the price of Token B increases. The formula ensures this adjustment.
4. **Fee Collection:** A small fee (e.g., 0.3%) is usually charged on each trade. This fee is added back to the liquidity pool, accruing to the LPs as a reward for providing liquidity.
**Underlying Technical Details:** The most well-known formula is the **constant product formula (x \* y = k)** used by Uniswap.
- `x`: Quantity of Token A in the pool.
- `y`: Quantity of Token B in the pool.
- `k`: A constant value. The product of `x` and `y` must always equal `k` (ignoring fees for simplicity).
This formula creates a hyperbolic price curve, meaning that as the quantity of one asset in the pool decreases, its price increases exponentially relative to the other asset. Large trades can cause significant **slippage**, which is the difference between the expected price of a trade and the price at which it is executed.
**Variations, Types, or Implementations:**
- **Constant Sum Market Makers (CSMMs):** Better for zero-slippage trades but don't offer infinite liquidity (e.g., `x + y = k`).
- **Constant Mean Market Makers (CMMMs):** Allow for more than two assets and different weightings (e.g., Balancer).
- **Hybrid AMMs:** Combine features of different models, often optimized for specific asset types like stablecoins to minimize slippage (e.g., Curve Finance's StableSwap invariant).
## Practical Applications, Use Cases & Implications
**Concrete Examples & Real-World Applications:**
- Uniswap: A pioneering AMM protocol on [[Ethereum]].
- PancakeSwap: A leading AMM on BNB Smart Chain.
- Curve Finance: Specializes in stablecoin swaps, minimizing slippage.
- Balancer: Allows for multi-token pools with custom weightings.
- SushiSwap: A community-driven fork of Uniswap with additional features.
**Benefits & Advantages:**
- **Accessibility:** Anyone can trade or provide liquidity without permission.
- **Continuous Liquidity:** Markets are always available, 24/7.
- **Transparency:** All trades and pool states are recorded on the blockchain.
- **Reduced Reliance on Centralized Entities:** Promotes decentralization.
- **Passive Income for LPs:** Liquidity providers can earn fees.
**Limitations, Challenges & Criticisms:**
- **Impermanent Loss:** A significant risk for LPs. It occurs when the price of tokens inside an AMM diverges from when they were deposited. If an LP withdraws their liquidity, the value of their withdrawn assets might be less than if they had simply held the original tokens.
- **Slippage:** Large trades can result in unfavorable execution prices.
- **Smart Contract Risks:** Bugs or vulnerabilities in the AMM's smart contracts can lead to loss of funds.
- **Capital Inefficiency:** In some AMM models (like the constant product formula), much of the liquidity sits unused unless prices swing dramatically.
**Future Trends & Developments:**
- **Concentrated Liquidity:** AMMs like Uniswap v3 allow LPs to provide liquidity within specific price ranges, improving capital efficiency.
- **[[Layer 2]] Scaling Solutions:** Moving AMM operations to Layer 2 solutions to reduce [[Gas|gas]] fees and improve transaction speed.
- **Cross-Chain AMMs:** Enabling swaps between assets on different blockchains.
- **More Sophisticated Pricing Algorithms:** Development of new formulas to reduce slippage and impermanent loss.
## Related Concepts
- DEX
- Liquidity Pool
- Impermanent Loss
- Slippage
- Decentralized finance