What is a Decentralized Exchange (DEX)?
Anyone who is looking at DeFi, will quickly come across the canonical example of what it can do – a Decentralized Exchange (DEX). So, what is a DEX?
As context, DEXs exist because until DeFi technologies, the only way to exchange between crypto currencies was on a Centralized Exchange (CEX), such as Coinbase, Binance, etc. This created a somewhat contradiction -- that blockchain technologies promised to be decentralized, but in order to transact or exchange, they needed to be centralized, and often custodied somewhere else. This centralization came with all the arguments against blockchain technologies: need to trust the third party, counterparty risk, not final, etc.
So, DEXs sprung up. At their core, DEXs enable exchanging crypto-assets, without centralizing currencies. They work because of a core concept called a liquidity pool. Let's do an example, because it's easier to understand them in practice than in theory:
Example of a DEX liquidity pool:
Eth is at $4,000.
USDC is at $1 (stable coin)
There is a liquidity pool for USDC/ETH and it has: 100,000 USDC and 25 ETH. As seen, the dollar value of the two assets in the pool has to be the same. Now, if someone wants to trade between USDC and ETH (often thought of as buying or selling ETH), the would go on the exchange and enter the asset they wanted to trade, say, sell 1 eth.
In this scenario, the pool would increase by 1 eth, and reduce by ~4,000 USDC. In practice, it would reduce by a bit more than $4,000 USDC and the buyer would pay an exchange fee.
The exact pricing would depend on a mathematical formula which governs the flow between the two assets. As the quantities change, the buy/sell offer for USDC and ETH would change accordingly. When the prices offered get out of whack with other exchanges, arbitragers come in a buy the cheap one and sell the expensive one until they match up again. This has worked very well in practice, and arbitragers are a major component of DEXs.
When enough liquidity is on both sides, the price changes very little.
For providing liquidity, the liquidity providers are paid some of the exchange fees, which incents them to allow their liquidity to be used.
There are some risks here, which we'll go into next time. If you want to see a DEX in practice, check out uniswap, sushi swap or orca, among others.