Good Evening everyone!
This is Ray once again. I'm planning to write this article for tomorrow but because of the tip i got today from @TheRandomRewarder, why not write it today. Its a huge boost for me on doing more articles. Hope this won't end today. 😁
This article is about liquidity pools. I knew major users here at read.cash have heard of it and have some knowledge about it. But for the sake of others that don't have any idea what is it and how it works, i'm gonna try my best to explain this as simple as i can.
So, what is liquidity pools? How does1 it work and why it is needed in decentralized finance?
What is Liquidity pools?
Pools of token that are locked in a smart contract
Used to facilitate trading by providing liquidity and are used extinsively by decentralized exchanges also known as DEXES
The first project that used liquidity pool is BANCOR but became popularized by UNISWAP
Why do we need Liquidity Pools?
Exchanges like coinbase and binance based their trading on order book model. This is a also the traditional way of stock exchanges such new york stock exhange (NYSE) and NASDAQ works.
In this order book model, buyers and sellers come together to place an order. The buyers also known as bidders tries to buy an asset for the lowest price possible whereas sellers try to sell the same asset as high as possible. For a trade to happen, buyers and sellers has to converge to a price. This can happen by either a buyer bidding high or a seller lowering its selling price.
What if there is no willing to place an order in a fair price or what if there is not enough token you want to buy?
This is where market makers comes into place.
Market makers are entities that facilitate trading by always willing to buy or sell a particular asset. By doing it, they are providing liquidity. So users can always trade and don't have to wait for another counterpart to show up.
So, why can't we reproduce like this in DeFi?
Yes, we can! But it will be really slow, expensive and may result in poor user experience. The main reason is that order book model relies heavily on the market makers or group of market makers willing to always make a market in a certain asset.
Without market makes, an exchange becomes instantly illiquid and pretty much unusable for normal users. Market makers track the current price and constantly change their prices. This results in a huge number of orders and order cancellation that are being sent to an exchange.
Ethereum with its current throughput of around 12-15 transactions per seconds and a block time between 10-19 seconds, it is not a viable option for an order book exchange. Also, every interaction with a smart contract has a gas fee, making market makers go bankrupt by just updating their orders.
How about second layer scaling?
Some second layer scaling like loopring looks promising, but they still are relying on market makers and can face liquidity issues. On top of that, if a person wants a single trade, they need to move their funds in and out in the second layer which adds two extra steps process.
This is why the need of something new to work in a decentralized world. Thus, liquidity pool is created.
How Liquidity Pools work?
A single liquidity pool holds 2 kinds of token and each pool creates a new market for that particular pair of tokens. A popular good example of this is DAI/ETH liquidity pool in UNISWAP.
When a new pool is created, the first liquidity provider is the one who sets the initial price of the asset in the pool. The liquidity provider is incetivise to supply an equal value of both tokens in the pool.
If the initial price in the pool diverges from the current global market price, it creates an instant arbitrage oppourtunity that can result in lost of capital of the liquidity provider. This concept of supplying a correct ratio remains the same for all the liquidity providers that are willing to add more funds in the pool later.
When liquidity is supplied to a pool, the liquidity provider receives a special tokens called LP tokens in proportion to how much liquidity is supplied to the pool. The trade is facilitated bu the pool. A 0.3% fee is proportionally distributed among all the LP token holders.
If the liquidity provider wants to get their underlying back plus any actual fess, they must burn their LP tokens.
Each token swap that the liquidity facilitates results in a price adjustment according to a deterministic algorithm. This mechanism is also called automated market maker (AMM). Liquidity pools across differents protocols uses slight different algorithm.
Basic liquidity pools that is introduced by UNISWAP are constant product market makers algorithm, that the product of quantities of the two tokens always remain the same. And because of that, their pool can always provide liquidity no matter how large a trade is. The reason behind this is, the algorithm increases the price of the token as the desired quantities increases.
The ratio of the token dictates the price.
When someone buy an ETH to a DAI/ETH pool, they reduce the supply of ETH and add the supply of DAI. This results an increase in the price of ETH and decrease in the price of DAI.
How much the price moves?
It depends on the size of the trade in proportion to the size of the pool. The bigger the pool is in comparison to a trade, the lesser the price impact (slippage) occurs.
Large pools can accomodate larger trades without moving of the price too much.
Because larger liquidity pools creates less slippage and resulting to a better trading experience, some protocols like BALANCER incentivising liquidity providers woth exyra token for suppkying liquidity to a certain pools. This process is called liquidity mining.
The concepts behind liquidity pools and automated market makers are yet simple but extremely powerful as we don't have a centralized order book anymore and we don't have to rely on external market makers to constantly provide liquidity to an exchange.
The liquidity pool are used by UNISWAP and they are the basic form of liquidity pools. Other projects iterated with this concept and came with a few interesting idea.
Curve realize that the automated market making mechanism behind UNISWAP doesn't work very well on assets with similar prices such as stable coins. So by implementing a different algorithm are able to lower fees and lower slippage when exchanging this tokens.
Balancer realized that we don't have to limit two assets in a pool. As a matter of fact, they allow 8 tokens in a single liquidity pool.
Potential Risks
Liqudity pools are still in its early stage, so some problems may still arise like:
Smart contract Bugs
Admin keys
Systemic Risk
Impermament loss
Liquidity pool hack
Any Suggestions or Questions? Please leave a comment.
Hope you learned something informative today. God Bless Everyone!
Great article and happy you have received many good tips from the bot. That empower you to create more and to get more of those.