How Decentralized Exchanges Work (AMM, Liquidity Pools, Impermanent Loss)
Decentralized Exchanges (DEXs) are one of the biggest breakthroughs in blockchain and decentralized finance (DeFi). They allow anyone to trade crypto without banks, brokers, order books, or centralized intermediaries—all powered by smart contracts.
![]() |
| How Decentralized Exchanges Work |
If you’ve ever used platforms like Uniswap, PancakeSwap, Curve, SushiSwap, Balancer, or Trader Joe, you’ve used a DEX.
But how do these exchanges actually work behind the scenes?
-
How do they set prices without market makers?
-
Where does liquidity come from?
-
What is impermanent loss?
-
How do liquidity providers earn?
-
Why do DEX prices change after your trade?
This article explains everything clearly, from beginner basics to technical mechanics.
1. What Is a Decentralized Exchange (DEX)?
A decentralized exchange is a smart contract-based platform that allows users to trade cryptocurrencies directly from their wallets.
✔ No central company
✔ No KYC
✔ No account needed
✔ No custodial wallet
✔ Your keys = your crypto
DEXs rely on blockchain technology to manage trades automatically.
There are two major types of DEX models:
-
Order Book DEX (rare now)
-
AMM-based DEX (most popular)
The most revolutionary model is the Automated Market Maker (AMM)—used by Uniswap and many others.
2. What Is an AMM (Automated Market Maker)?
Before AMMs existed, exchanges used order books, matching buyers and sellers.
But in crypto, order books didn’t work well on blockchains due to:
-
Slow block times
-
High gas fees
-
Low liquidity
-
Complexity
AMMs solved this problem.
AMM Definition:
An AMM is a smart contract algorithm that automatically sets prices and executes trades using liquidity provided by users.
No human market makers needed—everything is algorithmic.
The most famous AMM formula is the constant product formula:
x * y = k
Where:
-
x = token A reserve
-
y = token B reserve
-
k = constant (cannot change)
This formula keeps the liquidity pool balanced.
3. What Are Liquidity Pools?
A liquidity pool is a smart contract that holds pairs of tokens.
Example:
A USDT–ETH pool contains both:
-
ETH
-
USDT
Users deposit equal value of both assets into the pool to provide liquidity.
These users are called Liquidity Providers (LPs).
Example of providing liquidity:
-
Deposit $500 worth of ETH
-
Deposit $500 worth of USDT
Total contribution: $1,000 liquidity
Liquidity is needed so traders can swap tokens instantly without waiting for a buyer or seller.
4. How Trading Works in an AMM
Let’s use an example:
Pool contains:
-
100 ETH
-
200,000 USDT
Using the AMM formula:
100 * 200,000 = 20,000,000 (k)
Now, someone wants to buy 1 ETH.
They pay the pool USDT, increasing the USDT side and reducing ETH from the pool.
Because x * y = k must stay constant, the price automatically updates based on supply and demand.
This is called:
✔ Algorithmic price adjustment
The fewer tokens left in the pool, the higher their price becomes.
This is why big trades cause slippage.
5. What Is Slippage?
Slippage is the difference between the expected price and actual price during a swap.
In AMMs:
-
Large trades move the pool ratio
-
This changes the price significantly
-
Causing slippage
Low liquidity = high slippage
High liquidity = low slippage
This is why large pools are safer for traders.
6. How Liquidity Providers (LPs) Earn Money
LPs earn from:
1. Trading Fees
Most DEXs charge a fee per trade.
Example from Uniswap:
-
0.3% fee
-
Goes directly to liquidity providers
-
Shared proportionally based on liquidity contribution
If a pool generates $1,000,000 in trading volume per day:
LPs earn 0.3% = $3,000 per day
Distributed among all LPs.
2. Farming Rewards (Optional)
Some DEXs give additional tokens as rewards
(e.g., CAKE on PancakeSwap).
3. Incentive Programs
Some chains incentivize liquidity with native tokens.
7. How LP Tokens Work
When you provide liquidity, you receive LP tokens.
These represent your share of the pool.
Example:
If you provide 10% of liquidity, you receive 10% of LP tokens.
LP tokens can be:
-
Redeemed anytime
-
Staked for extra yield
-
Used as collateral in DeFi
LP tokens = proof of ownership.
8. The Biggest Risk: Impermanent Loss
Impermanent Loss (IL) happens when the price of your deposited assets changes compared to when you added them.
Why it happens:
AMMs rebalance tokens to maintain the x * y = k formula.
If one token’s price rises a lot:
-
The pool sells the expensive token
-
And buys more of the cheaper token
You end up with:
-
Less of the profitable token
-
More of the lower-value token
This causes a loss compared to simply holding the tokens.
9. Impermanent Loss Example (Simple)
You deposit:
-
1 ETH (worth $1,000)
-
1,000 USDT
Total value: $2,000
ETH price then rises from $1,000 to $2,000.
If you held the assets:
-
You’d have $3,000 total value.
But in the liquidity pool:
-
Your ETH amount decreases
-
Your USDT amount increases
-
Total value becomes around $2,828
You lose $172, called impermanent loss.
Why “impermanent”?
Because if ETH returns to its original price, the loss disappears.
If you withdraw at the new price, loss becomes permanent.
10. Why People Still Provide Liquidity?
Because fees + rewards can outweigh impermanent loss.
If the pool has high volume, LPs earn more.
Some pools earn more in fees than they lose in IL.
11. Types of DEX AMM Models
1. Constant Product AMM (x*y=k)
Used by Uniswap V2, PancakeSwap
Best for general token swaps.
2. StableSwap AMM
Used by Curve
Low slippage for stablecoins.
3. Weighted AMM
Used by Balancer
Allows pools with multiple tokens.
4. Concentrated Liquidity AMM
Used by Uniswap V3
Liquidity focused in price ranges
More efficient, higher returns.
Each model optimizes for different use cases.
12. Chain-Specific DEX Differences
Ethereum DEXs
-
High security
-
Higher gas fees
-
Mature ecosystem
BSC DEXs
-
Low fees
-
High volume
-
Popular for farming
Solana DEXs
-
Ultra-fast
-
On-chain order books like Serum
Layer 2 DEXs
-
Cheap fees
-
Fast
-
Ideal for active traders
13. Smart Contracts Are the Backbone of DEXs
Smart contracts handle:
-
Swaps
-
Liquidity deposits
-
Fee distribution
-
Price calculations
-
LP token issuance
-
LP token redemption
No middleman.
No human intervention.
Just code + math.
This transparency is what makes DEXs powerful.
14. Security Risks of DEXs
Despite being decentralized, DEXs are not risk-free.
1. Smart Contract Hacks
Exploits can drain liquidity pools.
2. Flash Loan Attacks
Attackers manipulate pool prices.
3. Rug Pulls
Developers withdraw liquidity.
4. Fake Tokens
Anyone can create scam tokens.
5. Impermanent Loss
LPs suffer value loss during volatility.
Using reputable DEXs and audited pools reduces risk.
15. Why DEXs Are the Future of Trading
DEXs offer:
✔ True decentralization
✔ Full ownership of funds
✔ No verification needed
✔ Open access to global liquidity
✔ Transparency
✔ Passive income opportunities
✔ Freedom to trade any token
As more users choose self-custody, DEXs continue to grow in popularity.
Conclusion
Decentralized exchanges are a cornerstone of DeFi, enabling a trustless, permissionless system where anyone can trade 24/7 using smart contracts and algorithms.
Understanding the key components—
✔ AMMs
✔ Liquidity pools
✔ LP tokens
✔ Impermanent loss
✔ Slippage
✔ Fee rewards
DEXs are not just an innovation; they represent the future of financial independence and on-chain trading.
.png)