Decentralized Exchanges: A gold mine of liquidity
No liquidity, No scalability period. What is better than exploring one of the biggest protocol in this category to understand the mechanics of decentralized exchanges.
Where do you look when you want a certain crypto asset/token?
Probably to some crypto exchanges like Binance, FTX, Coinbase, and so on. These exchanges are centralized and only support a few tokens from the Web3 ecosystem, as there are compliance, standards, and fees for listing tokens on these exchanges. When it comes to decentralized exchanges, they are super simple to use, no accounts or registration is needed, and also support way more tokens than centralized exchanges.
Decentralized exchanges (DEX) are more than just exchanging the assets, here is an example of how DEXs can help founders establish liquidity for their protocol.
Imagine you are a founder of some web3 protocol and your protocol does have a utility token. You know Liquidity = Scalability, there will be an immense need for liquidity for your protocol’s native token to support the demand and supply created by the usage of your protocol.
You need a place from where a user can get your protocol's utility token and a place where a user can exchange your token for some other asset, catering to this need is usually considered as establishing liquidity.
Being a founder, you have the following options:
1. You can reach out to centralized exchanges like Binance for establishing liquidity
This, in my opinion, is the best way to burn cash and get into more hassle to comply with standards, regulations, and more, which is not needed in the initial phase of your protocol.
2. Buy some assets and provide liquidity yourself
Sounds good right? This option will look inefficient after reading the 3rd option
3. Incentivise people to provide liquidity for you
I told you! This sounds even better than before
Note: Just for the sake of simplicity I not going into deep waters but there are options where Founders can incentivize their liquidity pools by offering a staking/locking position where Liquidity providers (LP) can stake those specific LP tokens to get even more rewards. Founders also have other options to establish liquidity using other protocols like Tokemak, Olympus, etc. I will cover those in future articles.
Well, you might think, is there any platform where you can incentivize people to provide liquidity for you?
Yes! Decentralized exchanges (DEXs) are what you are looking for.
You might ask how DEXs are different from Centralized exchanges?
Well, Centralized exchanges are ledger-based where peers are matched with one another to make trades.
DEXs rely on liquidity pools to execute trades.
Liquidity pools are smart contracts that hold a pair of assets that are supplied by liquidity providers (LP) in exchange for incentives. These pairs of tokens are balanced in a 50-50 ratio of their value (Balancer being one of the exceptions); these pools are used to trade between the two assets.
What happens when a liquidity pool is created?
When a pool contract is created, the balance of each token is 0; someone must seed it with an initial supply of each token. The one who seeds the liquidity sets the initial price of the pool. The initial seeders of liquidity are asked to deposit an equal value of both tokens into the pool.
You may ask why is that?
Consider the case where the first liquidity provider deposits tokens at a ratio different from the current market rate.
For example, I create a liquidity pool of $ABC/ $XYZ, considering the current market price of $ABC is equal to that of $XYZ but I supplied the assets as 1000 quantities of $ABC and 2000 quantities of $XYZ. There would be an immediate arbitrage opportunity where my liquidity pool will show the price of 0.5 for swaps of $ABC/ $XYZ whereas the market will show a price of 1.
Thus imbalance would immediately create a profitable arbitrage opportunity, which is likely to be taken by an external party. When other liquidity providers add to an existing pool, they must deposit pair tokens proportional to the current price. If they don’t, the liquidity they added is at risk of being arbitraged as well.
How does the protocol track how much liquidity you supplied and what are the gains for that liquidity?
Whenever liquidity is deposited into a pool, unique tokens known as liquidity tokens are minted and sent to the provider's address. These tokens represent a given liquidity provider's contribution to a pool. The proportion of the pool's liquidity provided determines the number of liquidity tokens the provider receives.
To retrieve the underlying liquidity, plus any fees accrued, liquidity providers exchange them for their portion of the liquidity pool, plus the proportional fee allocation.
I will constantly refer to Uniswap V2 to explain how DEXs work. You will grasp how DEXs work and how Uniswap V2 operates by the end of this article.
At the very least, every DEX would have participants like Liquidity Providers (LP) and traders.
Balancing the 50% value ratio of individual tokens in a specific liquidity pool is crucial as we discussed above. Also, 50-50 is the most effective ratio, as the traded value peaks when one asset in the pool is fully converted into another. If the ratio is 20-80 the effectiveness will just be 40%, as there will only be 20% of the pool that can be converted to another asset.
Uniswap uses a Constant Product Function to make sure the ratio is balanced.
This function is simply expressed as the product of the reserve quantity of both the assets in the pools should remain constant.
x * y = k, states that trades must not change the product (k) of a pair’s reserve quantity (x and y).
Here is a trader's perspective while making a trade
This graphic by Uniswap, best describes how the pool balance and price change when a trade happens.
You would notice 0.03% swap fees, these fees are taken upfront as input for exchange, and later this would be added to the pool thus increasing liquidity as trades happen over time.
Sometimes your order might not get executed at the price shown to you.
But, Why? Due to slippage.
The price difference (usually in percentage) between the order price and the execution price is known as slippage.
But why does it change?
As we discussed in the previous section about constant market function, when the demand for one of the assets in a specific pool changes, the price will automatically be adjusted to balance the assets due to limited supply.
Continuous trading on these exchanges would result in continuous price fluctuation and the price fluctuation between the time of order placement and the execution will result in price slippage.
Where there is high liquidity the slippage will be less, as there will be fewer adjustments in the price due to greater supply.
Moving towards another participant, Liquidity Provider (LP)
Liquidity providers (LP) are incentivized for providing liquidity on DEXs, but incentives depend on the volatility and risk profile of the particular asset pair.
More volatile assets > High risk of Impermanent loss > High Incentives
On Uniswap, there is a 0.3% fee for swapping tokens. This fee is split by liquidity providers proportional to their contribution to liquidity reserves. Swap fees are immediately deposited into liquidity reserves. This increases the value of liquidity tokens, functioning as a payout to all liquidity providers proportional to their share of the pool.
Whenever you are providing liquidity in a specific pool, you are exposed to a loss called impermanent loss. You might recall that I referred to impermanent loss at the beginning of this article, you might have tough what the hell is impermanent loss, I won't take more of your time.
Impermanent loss is an opportunity cost that may occur while providing liquidity, due to the price shift of one asset of the liquidity pool, versus holding the assets.
I also didn't get it in the first shot. An example is the best way to understand it.
Let’s take an example by providing liquidity for $ABC/$XYZ
$ABC = $10; $XYZ = $100; You provide 50 quantities of $ABC and 5 quantities of $XYZ, thus providing liquidity worth $1000.
Now, if the price of $ABC goes up by 100% i.e. $ABC = $20. Your liquidity pool would now have 35.36 $ABC tokens and 7.07 $XYZ tokens. The total value of your pool would be $1414.21 when Asset1 goes up by 100%.
What if you held those assets rather than providing liquidity?
In that case, the total value of your holdings would be $1500 when Asset1 goes up by 100%. The difference between $1500 and $1414.21 i.e. 5.21% is known as impermanent loss.
Impermanent loss is unrealized until the liquidity is removed.
When someone provides liquidity to a pool, the liquidity is spread towards the whole spectrum of price i.e. 0 to infinity. This allows the liquidity pool to function across the whole price band but at the trade-off of liquidity depth.
As the liquidity in the pool rises the exchange price will be impacted less and less by the frequent trades.
I would like to end this article with one thought to ponder.
"What if you can provide liquidity in the specific price range? How will it change the things?"
This will be covered in my next post about Uniswap V3. Till then, Stay tuned and explore hard. Peace!