How DEXes Work
Lesson by Uvin Vindula
What is a Decentralized Exchange (DEX)?
A DEX (Decentralized Exchange) is a platform that allows you to trade cryptocurrencies directly from your wallet, without depositing funds into a centralized platform. Unlike Binance or Coinbase where the company holds your crypto while you trade, on a DEX you always maintain control of your assets.
The two most well-known DEXes are Uniswap (on Ethereum) and PancakeSwap (on BNB Smart Chain). PancakeSwap is particularly popular among Sri Lankan users due to BNB Chain's lower fees.
How Traditional Exchanges Work (Order Books)
On a traditional exchange like Binance, trading works through an order book — buyers place bids (the price they're willing to pay) and sellers place asks (the price they want to sell at). When a bid matches an ask, a trade happens. This requires lots of buyers and sellers to work well.
How DEXes Work — Automated Market Makers (AMMs)
Most DEXes use a completely different mechanism called an Automated Market Maker (AMM). Instead of matching buyers and sellers, AMMs use liquidity pools.
Here's how it works, step by step:
- Liquidity providers (LPs) deposit pairs of tokens into a pool. For example, you might deposit $500 worth of ETH and $500 worth of USDC into the ETH/USDC pool.
- The smart contract uses a mathematical formula (typically x × y = k, where x and y are the quantities of each token) to determine the exchange rate.
- When a trader wants to swap ETH for USDC, they trade against the pool, not against another person. The pool gives them USDC and takes their ETH.
- Each trade shifts the ratio of tokens in the pool, which automatically adjusts the price. If many people buy ETH from the pool, ETH becomes scarcer in the pool and its price goes up.
- Liquidity providers earn a small fee from every trade (typically 0.3%) as compensation for providing their assets.
Visual Example
Imagine a pool with 10 ETH and 30,000 USDC (k = 300,000):
- Current price: 1 ETH = 3,000 USDC
- A trader swaps 1 ETH into the pool. The pool now has 11 ETH.
- To maintain k = 300,000, the USDC in the pool must be 300,000 ÷ 11 = 27,272.7 USDC
- The trader receives 30,000 - 27,272.7 = 2,727.3 USDC for their 1 ETH
- Notice: the trader received less than 3,000 USDC. This difference is called price impact or slippage
Impermanent Loss — The Hidden Risk
If you provide liquidity to a pool, you face a risk called impermanent loss. This occurs when the price ratio of your deposited tokens changes compared to when you deposited them. The larger the price change, the greater the loss.
For example: if you deposit ETH and USDC into a pool, and ETH's price doubles, you would have been better off simply holding your ETH rather than providing liquidity. The pool automatically rebalances by selling your appreciating ETH for USDC.
The loss is called "impermanent" because it reverses if prices return to the original ratio. However, if you withdraw while prices are different, the loss becomes permanent.
Advantages of DEXes
- Self-custody: Your tokens never leave your wallet until the moment of the swap
- No KYC: No identity verification required (though regulatory changes may affect this)
- Access to new tokens: Tokens are often available on DEXes before centralized exchanges list them
- Censorship-resistant: No company can block your trades or freeze your account
Disadvantages of DEXes
- Gas fees: On Ethereum, DEX trades can cost $5-50+ in gas fees. BNB Chain and Solana are much cheaper.
- Slippage: Large trades in small pools suffer significant price impact
- Scam tokens: Anyone can create a token and add it to a DEX — many are scams
- Complexity: More technical knowledge required compared to centralized exchanges
Sri Lankan Context
For Sri Lankan users, PancakeSwap on BNB Smart Chain is the most accessible DEX due to its low fees (often just a few cents per transaction). Uniswap on Ethereum can be expensive for smaller trades. When using DEXes, always verify the correct token contract address — scam tokens with similar names are extremely common.
⚠️ Disclaimer: Using DEXes involves risks including smart contract vulnerabilities, impermanent loss, scam tokens, and irreversible transactions. Always verify token contract addresses. This is educational content only — IAMUVIN and uvin.lk do not recommend any specific DEX or trading strategy.
Key Takeaways
- •DEXes let you trade crypto directly from your wallet using Automated Market Makers (AMMs) and liquidity pools instead of order books
- •Liquidity providers deposit token pairs into pools and earn fees from every trade, but face impermanent loss risk
- •The AMM formula (x * y = k) automatically determines prices based on the ratio of tokens in the pool
- •DEX advantages include self-custody, no KYC, and censorship resistance, but risks include scam tokens and gas fees
- •PancakeSwap on BNB Chain is popular among Sri Lankan users due to very low transaction fees
Quick Quiz
Question 1 of 3
0 correct so far
How do most decentralized exchanges determine the price of a trade?