Brew Money

Chapter 6

Decentralized Exchanges

An exchange is a marketplace where assets such as securities (stocks), commodities, derivatives, and other financial instruments are traded. NASDAQ and New York Stock Exchange are examples of stock exchanges where people trade stocks. Similarly, in the crypto ecosystem, we have exchanges such as Coinbase and Binance that act as a marketplace for crypto traders.
The Amsterdam stock exchange is considered the oldest "modern" securities market in the world, established in 1602.
Decentralized Exchanges are marketplaces that allow users to trade crypto tokens in a non-custodial way without a central intermediary. It leverages smart contract algorithms to build an independent pool of tokens from which users can trade or ‘swap’ assets.

Centralized Exchanges

Traditional Exchanges work on an open order-book system. Order books record entire open orders and match buyers and sellers for the trade to take place. It is not necessary that the buyer and seller’s price expectations match. The difference between the two is called the bid-ask spread. Computer algorithms typically act as matchmakers for the transaction to happen at an agreed price between the buyers and sellers. 

Emergence of Decentralized Exchanges (DEXs)

The initial attempts at building a Decentralized Exchange took inspiration from traditional finance and tried implementing an order book system on blockchain. However, low liquidity coupled with slow transaction speeds on blockchain translated into a subpar user experience. 
In 2016, Vitalik Buterin proposed an alternative on a Reddit Post where he suggested running an on-chain decentralized exchange as a prediction market. Uniswap was the first exchange to implement it. Uniswap was based on two major constructs - Liquidity Pools and Automated Market Makers (AMMs). 
A liquidity pool is a set of digital tokens locked by users into a smart contract that enables trading on a decentralized exchange.
Automated Market Maker algorithms decide the price at which a trade should execute on the DEX based on the ratio of the two assets in the pool.
Uniswap became the first protocol to successfully utilize an automated market maker (AMM) system in 2018.
Uniswap algorithm maintains a pool that holds x no. of tokens of type T1, y no. of tokens of type T2, and, 
x * y = k for some constant k.
Thus, whenever someone buys token T1 by depositing T2, the price of token T1 increases, reflecting its demand.
Since Uniswap, other DEXes have emerged with different approaches catering to different kinds of use cases. Some exchanges allow you to swap between stablecoins very efficiently or borrow data from off-chain sources to determine asset prices. For example, Curve Finance built its niche by enabling the swapping of similar tokens. Example: Swapping DAI for USDC where both of them are stable coins. 
Beyond the fact that DEXes are decentralized and trades execute on blockchain, the permissionless nature of DEXes enables anyone to list a token by creating a liquidity pool and trade without gatekeeping. 
Uniswap was launched in November 2018. In less than four years, the cumulative trading volume on Uniswap has surpassed 1 Trillion Dollars.

Check out how to use Uniswap