Decentralized EXchanges and Uniswap Explained
If you’re someone who has done some digging around in crypto currencies, you’ve definitely come across Uniswap and their token UNI. It’s currently 10th in terms of total market cap among all crypto currencies, and the top token in the DeFi ecosystem. So what exactly is Uniswap?
Uniswap is a decentralized, permissionless exchange allowing users to trade any ERC-20 tokens. To understand what I just said, let’s look at how traditional exchanges ( like Binance, Kraken, Coinbase Pro etc.) work.
KYCs, Order Books and Market Makers
Traditional exchanges maintain centralized databases and trading takes place via an orderbook. Buyers and sellers place their respective bids and asks in the orderbook. When a buyer and seller agree on the same price, a trade is conducted.
Obviously the biggest problem immediately noticeable is having sufficient numbers of buyers and sellers to get matching bids. Basically, these exchanges need to maintain liquidity, and that is hard to maintain with only small buyers and sellers. Enter the market makers. They infuse liquidity into the market by placing large volumes of buy and sell orders simultaneously, profiting off the bid-ask spread. For example, suppose a market maker places a buy order for 100(in real life, this will be a much much larger order) securities at say $10, and simultaneously a sell order for the same securities at $10.5 . Such high volume liquidity infusions by market makers are critical for functioning of these exchanges.
These exchanges also need you to do extensive KYC before you can do any trades. While it is perfectly normal to do so to comply with local anti money laundering laws, some people might feel that this goes against the principle of cryptocurrencies and the supposed pseudonymous transaction benefits that they’re supposed to bring. You also don’t have control over your own funds, and any crypto currencies you buy are actually deposited with the exchange and not your own wallet.
Anonymity, Liquidity Pools, and Automated Market Makers
Enter Decentralized EXchange (DEX). They consist of a set of automated mathematical rules run by independent computers. Smart contracts running on decentralized blockchains. DEXs are open to everyone and anyone can sign up without needing to do any KYC. You retain ownership of your assets, not the exchange. And instead of market makers and order books, DEXs use Liquidity Pools and Automated Market Makers(AMM).
Uniswap and the Constant AMM
What are liquidity pools?
Liquidity pools are shared pot of funds which are used by the exchange. The people who provide these funds are called Liquidity Providers. Imagine it like this, instead of 2–3 big market makers providing most of the liquidity, you have say 200–300 smaller entities coming together and pooling their assets together to provide liquidity. While traditional market makers profit off the bid ask spread, Liquidity Providers profit off pool fees(paid by the traders interacting with the pool), which they get for keeping their funds deposited in the pool. This is called Liquidity Mining. Anyone with an internet connection and in possession of ERC-20 tokens can participate in a pool.
The AMM
AMMs have become the dominant way to trade on DEXs. Consider a liquidity pool having 2 ERC-20 tokens, A and B . The most common form of AMM can be:
(Token_Balance_A) * (Token_Balance_B) = constant
or as popularized by Uniswap:
x*y=k
k ensures that the total value of assets in the liquidity pool remains constant. If someone buys A, the price of A goes up as there is less of A in the pool now. Conversely the price of B has gone down since there is more of B. But the product of the token balances remains constant. The only way a liquidity pool expands in size is if new LPs join the pool.
Here’s an example. Suppose a ETH/USDT liquidity pool consists of 10 ETH and 1000 USDT. So ETH is initially priced at 100 USDT. The product 10*1000=10,000 remains constant. Now suppose I want to buy 2 ETH from the pool. What amount of USDT ‘x’ will I pay?
8*x=10000 ==>x=10000/8=1250.
So I buy 2 ETH for 250 USDT. The price of each ETH has gone up by 25 USDT in the pool now. I have neglected the trading fees paid to the LPs in this example.
There are other forms of AMMs on other DEXs, but Uniswap remains by far the most popular Dapp on Ethereum and one of the most forked projects. Earlier you could only trade ETH/ERC-20 pairs on Uniswap, but now any ERC-20 pair liquidity pools can be created and traded from.
The UNI Token
So what’s the use of the Uniswap token? It was airdropped on September 2020, and is basically a governance token which allows Uniswap users to vote on future developments. The long term plan is that the developers eventually phase out the governing and development decisions to a decentralized community of UNI token holders. The price increase of the UNI token signifies the future value that people believe a DEX like Uniswap will have, and thus they want to be a part of that governance community by owning the UNI token.
Drawbacks of DEX
Scam Coins
Just like no user KYC is needed, similarly anyone can create their own coin and start a liquidity pool for it. Unlike centralized exchanges where the exchange does extensive due diligence on a coin before listing it, a DEX by design has no such checks in place. This allows a lot of people to create scam coins or worthless meme coins. They hype up the price and then dump their own large shares of coins, effectively driving it into the ground and running away with the investors’ money. DYOR ( Do Your Own Research) before investing in any coin on any decentralized exchanges.
Price Slippage
Ethereum for now does lag behind when there’s a high number of transactions on it, as is quite normal on DEXs such as Uniswap. Leaving aside the high gas fees during such times, the delay in transactions can cause the actual price you end up paying for a token to be higher than the expected price, because there were a lot of pending orders already waiting before your order and you could not take them into account.
Impermanent Loss
Suppose you join the earlier ETH USDT pool with 1 ETH and 100 USDT, and the total assets in it are 10 ETH and 1000 USDT. So you’re entitled to a 10% share of the pool. Now suppose the price of ETH increases to 400 USDT in other markets ( say a traditional exchange ) . Arbitrage traders will immediately remove ETH from the pool and add USDT until its price reflects the market price. So now there will be 5 ETH and 2000 USDT in the pool. Now you decide to withdraw your funds from the pool. You’ll receive 10%, i.e. 0.5 ETH and 200 USDT. Your holdings value in terms of USDT is 400 USDT, while you had deposited 200 USDT. However, if you had simply held on to your holdings, you’d have 1 ETH ( now 400 USDT) + 100 USDT = 500 USDT. So you actually lost out on 100 USDT profits by joining the pool.
This is called impermanent loss, because it is not realized until after you withdraw your funds from the pool. The mining fees aim to offset this “loss”.
Centralized order books and AMMs are both here to stay and co exist. Both offer their own set of unique features, and it is up to the user to choose either one, or both if you have the suitable risk taking appetite. Arbitrage traders ( earlier humans, now mainly bots ) are constantly at work to ensure that prices in all markets converge to the same value.