2 min to read.
DEX
A decentralised exchange: a set of smart contracts that lets users trade tokens directly from their own wallets.
What is a DEX?
A DEX, or decentralised exchange, is a marketplace for crypto tokens that runs on smart contracts. Users trade directly from their own wallets and keep control of their private keys, rather than depositing funds with a company as they would on a centralised exchange.
How it works
There are two main designs.
- Automated market makers (AMMs). Instead of matching buyers with sellers, the exchange holds pools of two tokens supplied by users called liquidity providers. A formula sets the price based on the ratio of the tokens in the pool. A trader adds one token and removes the other, which moves the price.
- Order books. Buy and sell orders are recorded and matched, either on-chain or by an off-chain system with on-chain settlement.
Each trade is a blockchain transaction, so it needs a network fee and is final once confirmed.
Example
A user wants to swap a stablecoin for ether. They connect a wallet to a DEX, enter the amount, approve the token, and confirm the swap. The contract takes the stablecoin, sends ether from the pool, and a small trading fee goes to the liquidity providers.
Why it matters
A DEX does not take custody of user funds, usually requires no account, and lets anyone list a token or provide liquidity. Trades and pool balances are publicly verifiable.
Risks
- Anyone can list a token, including scam tokens and copies of well-known names.
- Slippage: in small pools, a trade can move the price significantly against the trader.
- Front-running: others can see pending trades in the mempool and trade ahead of them.
- Smart contract bugs can drain pools.
- Liquidity providers face impermanent loss when the prices of the two pooled tokens diverge.
- A mistaken transaction cannot be undone, and there is no support desk.
Common misunderstanding
A DEX front end is a normal website that can be taken offline or imitated; the contracts underneath keep running.