Image Source- DEX vs CEX
Buying cryptocurrencies directly on a blockchain is beyond the reach of most people. Hence, they use exchanges. The history of cryptocurrency exchanges however has been quite colourful. Mt. Gox (the biggest crypto exchange in 2011) suspended trading and filed for bankruptcy in 2014 after 850,000 bitcoins worth $450mn (at the time), were stolen. $137mn worth of cryptocurrency was lost when the founder of Canadian crypto exchange, QuadrigaCX died without sharing the passwords to his accounts with anyone. In 2018, South Korean crypto exchange, Coinrail was hacked. Several exchanges have been in the radar of regulators for thefts, frauds, market manipulation and operating without licenses,
The basic problem with Centralised Exchanges (CEX) is that you have to give custody of your coins to another party. This means that you have to trust the exchange to not steal your coins. Even if the CEX has honest intentions, it’s security systems may not be up to the mark making it vulnerable to hacks by other malicious characters.
In Decentralised Exchanges (DEX) there’s no middleman taking custody of your coins and hence they don’t suffer from the problems that Centralised Exchanges suffer from. DEX popularity has clearly been rising. On 30 August, the creator of the DEX, Uniswap, Hayden Adams tweeted about Uniswap trading volumes being higher than that Coinbase Pro (the largest CEX in the world) for the first time ever.
This however does not mean that DEXs don’t have their own problems. the success of any exchange is largely dependent on the liquidity it attracts. This makes creating a decentralised exchange with no central authority managing liquidity quite tricky. I describe below the workings of Uniswap and how it uses governance tokens to attract liquidity and code to handle pricing.
To understand how a Uniswap works let’s first look at how a traditional CEX works and then see how the mechanics of Uniswap differ.
How does a CEX work? Buyers place an order stating the quantity of an asset that they’re willing to buy and the price at which they’re willing to buy it. Sellers place an order stating the quantity of an asset that they’re willing to sell and the price they’re willing to sell it at. If the 2 orders match then a trade takes place. Price discovery in an exchange requires liquidity. If liquidity is low then prices will be very volatile and even vulnerable to manipulation.
In case of Uniswap, there is no order book. A decentralised process of price discovery called Constant Product Market Maker (CPMM) is used. Liquidity providers create a liquidity pool by depositing equal values of the two currencies that they want to create a market in. CPMMs are the smart contracts that administer these liquidity pools.
The exchange rate is not based on an order book as described above for a CEX but instead is based on an equation:
x * y = k
x and y are the quantities (not values) of the 2 tokens.
(Total value of the 2 tokens in the pool should be equal)
k is a constant.
For example: Let’s make a market between Tether (USDT) and Ether (ETH). USDC tracks US$. Assume that at the time this market is created, 1 ETH is worth $100. (The exchange ratio between the two cryptos therefore is 100:1 i.e 100USDT=1ETH). A Liquidity Provider must deposit equal value of both tokens into the liquidity pool. In our example the market begins with $1,000 worth of each token. i.e 1000 USDT and 10 ETH.
x= 1000 units of USDT
y= 10 units of ETH
x * y = k
1000 * 10 = 10,000
k=10,000
The value of the pool
= (units of USDT * value of USDT) + (units of ETH * value of ETH)
= (1,000 * $1) + (10 * $100)
=US$2,000
Now, what happens if Tina enters the market and wants to buy 1ETH in exchange for USDT? How would the exchange rate change? The number of ETH in the pool will decrease to 9. k must remain constant. Therefore x (number of units of USDT) must increase. The net impact will be that ETH will become more expensive vs USDT.
If you’re interested in understanding the math then please go through the text in blue below:
x * y = k
x * 9 = 10,000
x= number of units of USDT= 10,000/9=1111.11
The composition of the liquidity pool changes to:
1111.11 units of USDT and 9 units of ETH (from 1000 units of USDT and 10 units of ETH earlier)
Since the value of USDT and ETH must remain equal (1111.11USDT=9ETH), the exchange rate between the 2 changes from 100:1 to 123.46:1
The change in price will be a lot more dramatic when larger trades happen. For example, if Tina wanted to buy 5 ETH instead of 1.
x= number of units of USDT= 10,000/5=2,000
The composition of the liquidity pool changes to:
2,000 units of USDT and 5 units of ETH
Since the value of USDT and ETH must remain equal (2000USDT=5ETH), the exchange rate between the 2 changes from 100:1 to 400:1
So what do the Liquidity Providers gain?
Liquidity Providers in a way are owners of the protocol. The protocol charges 0.3% transaction fees. A part of this is distributed among the Liquidity Providers in proportion to the liquidity provided by them.
So becoming a Liquidity Provider sounds like a riskless way to earn passive income if you own cryptos?
Nothing is ever that straightforward in cryptos. It can earn you passive income but it wont be riskless.
Remember that USDT and ETH prices are constantly moving outside the ecosystem of Uniswap. This means that price changes outside must reflect in the ratio of the Uniswap liquidity pool.
Let’s go back to our original example where 1 ETH=100 USDT. Let us assume that ETH value has appreciated and now 1 ETH=400 USDT. Remember k value must remain constant and the value of both tokens in the pool have to be equal.
Units of USDT = x = 2,000
Units of ETH = y = 5
x * y = k
= 2,000 * 5 = 10,000
Value of this pool is:
=Units of USDT * value of USDT + units of ETH * value of ETH
= (2000 * 1) + (5 * 400) = $4,000
This looks like a healthy jump from the original value of the pool which was $2,000.
So does that mean that liquidity pooling was advantageous to the liquidity providers?
=> NO
What would have been the value of holdings if it had not been provided for pooling? You would still have your original holdings-1,000 units of USDT and 10 units of ETH.
Value of original holdings
=(1,000 * 1) +(10 * 400)
= US$ 5,000
If you had just sat on your holdings, you’d be 25% better off
Does that mean that if ETH had depreciated instead of appreciating then you’d be better of by contributing to liquidity pool?
=> Again NO
Let’s assume that ETH value has depreciated and now 1ETH=25USDT. Remember k value must remain constant and the value of both tokens in the pool have to be equal.
Units of USDT = x = 500
Units of ETH = y = 20
x * y = k
= 500 * 20 = 10,000
Value of this pool is:
= units of USDT * value of USDT + units of ETH * value of ETH
= (500 * 1) + (20 * 25) = $1,000
With depreciation of ETH, the value of the pool has dropped to $1,000 from $2,000 a the beginning.
What would have been the value of holdings if it had not been provided for pooling? You would still have your original holdings-1,000 units of USDT and 10 units of ETH.
Value of original holdings
=(1,000 * 1) + (10 * 25)
= US$ 1,250
If you had just sat on your holdings, you’d still be 25% better off (vs contributing to the liquidity pool)
References:
Uniswap- https://uniswap.org/
Uniswap Explained - https://defiprime.com/uniswap-explained
What is Uniswap? https://decrypt.co/resources/what-is-uniswap
Comments