Liquidity Pools Explained
Liquidity pools are an important concept in DeFi. In 5 minutes, you'll learn exactly what liquidity pools are and why they are necessary for DeFi.
A huge idea of Web3 and crypto in general is the idea of decentralization, having no body of governance. In decentralized finance (DeFi), this means to remove the need for financial institutions such as banks and giving consumers the opportunity to automate and drive financial services. A key mechanism in DeFi is the idea of a liquidity pool, which allows investors to lock funds in exchange for interest-like rewards for facilitating trades. The success DeFi have allowed liquidity pools to be adopted by other Web3 concepts such as yield farming, blockchain gaming, and NFTs.
But in order to better understand what are liquidity pools, we should first understand why decentralized exchanges (DEXs) and DeFi require them.
Centralized Exchange vs Decentralized Exchange
In particular, we can take a look at Coinbase, which is a centralized exchange where we can trade fiat and crypto. Particularly, Coinbase is the entity responsible for the conversion and uses principles from the traditional finance system. For instance, all of the transactions on Coinbase are handled by the exchange using the order book method, which establishes a price of a cryptocurrency based on a current buy and sell order. If this method sounds familiar, it's what stock exchanges like Nasdaq use when trading stocks.
What happens if no buy or sell orders converge at a fair price? In the stock trading world, market makers are created where each market maker will both buy and sell stocks at a publicly quoted price. Market makers will profit from this bid-spread but act as both buyer to create liquidity and ensure traders and investors will always have a transaction fulfilled.
In a decentralized exchange, the traditional fiat to cryptocurrency transactions do not exist. Instead, DEXs use smart contracts to facilitate trading between cryptocurrencies and provide instant trades that do not have to apply traditional finance rules such as market hours, ACH transfer waiting periods, etc.
The Order Book Model in DeFi
Naturally, the first generation of DEXs and DeFi products copied the order book model used in traditional finance. Each order book would compile a record of all buy and sell orders for a particular asset, and trade information would be held on-chain while your funds would be off-chain in a wallet.
But as we just mentioned before, order books require market makers in order to keep liquidity and trades active. In a liquid market where the cryptocurrency is trading at a high volume, this might not be an issue. But in an illiquid market where there is both a lack of market maker entities and trading volume, then the order book model is suspect to price manipulation, extreme price volatility, etc.
Gas fees, block sizes, and other concepts in blockchains such as Ethereum could be a strong reason why market makers would be reluctant to provide liquidity (as both the buyer and seller) for certain tokens.
Liquidity Pools
In the newer generation of DEXs, platforms moved away from the order book model and instead relied on automated marketing makers, which allowed digital assets to be traded freely and automatically using liquidity pools. Rather than having a set of buyers and sellers like in the order book method, trading on AMMs instead trade against a liquidity pool, or a pool of tokens. We can think of this pool as a pot of tokens with a math formula dictating the price, and by changing this formula, we can optimize the pot of tokens for various purposes.
AMMs act as a peer-to-contract (P2C). Trades happen between users and smart contracts, which means there is no need for a counter-party to buy/sell a token at the exact moment. Instead, liquidity in these smart contracts are provided by users called liquidity providers (LPs).
The role of a liquidity provider is to provide funds to the pool. Generally theses start off as two different stable coins with a 50/50 split. This pool is a big pile of funds that traders can trade against. In return for providing liquidity to the pool, LPs can earn fees from the trades that occur in the liquidity pool often in the form of liquidity tokens such as $SUSHI.
Practical Example
Let's take a look at a practical example of how liquidity pools work today. Specifically, let's use Uniswap as our example, one of the leading DEX platforms that allow you to swap any two Ethereum-built assets.
Remember how I said that a mathematical formula dictates the price of the tokens? Well, Uniswap uses a constant product formula of the equation:
Here, x and y denote the two tokens that you are trying to swap while k is a constant the dictates the total liquidity in the pool. Since the total liquidity in the pool must remain constant, changing a value of x will have to change a value of y. If we were trying to purchase $MANA using $ETH, the example above would mean that the price of $MANA would increase since there is now more $ETH and less $MANA in the liquidity pool.
This model doesn't scale linearly and in fact only works well for certain size transactions. The reason is that large orders can be extremely expensive, and if there is not enough liquidity at the moment then you may experience slippage, where a trade would be filled at a much higher difference than the rest due to volatility or low liquidity.
Arbitrage trading
Okay, so swapping tokens changes the mathematical value of each one assuming the total liquidity remains the same. Wouldn't this mean that people could take advantage of swapping tokens if the price on a centralized exchange such as Coinbase was much higher? Exactly. This concept is known as arbitrage trading, where traders exploit the differences in assets between two or more markets. In a way, these can help balance the price of AMMs such as Uniswap to reflect prices similar to ones found in a centralized exchange like Coinbase along with the algorithms used by AMMs.