One of the ultimate questions that crypto developers try to answer everyday is how to automate everything so that no intermediary agents are needed. It was at the very beginning of crypto/blockchains when Bitcoin was established, and back then the question was how to automate payments so they could be done 24/7 without any intermediaries. Many years later, when Ethereum’s developers introduced smart contracts (automated algorithms based on blockchain), the same kind of question arose – how to automate crypto-exchanging so it works 24/7 without any intermediaries. In this article, we introduce the basics of decentralized finance, the decentralized exchanges, and the mechanism under them called liquidity pools.
Centralized Crypto Exchanges
Classic centralized crypto exchanges (CEX), like Binance or Coinbase Pro, work on the concept of order books. It means that both those who want to buy and those who want to sell their crypto post their price offers for a certain asset into the order book. When the highest bid (willingness to buy the asset) and lowest ask (willingness to sell the asset) meet in the middle of the order book (i.e., their price will be the same), then the transaction finalizes, and those offers are removed from the order book.
A centralised crypto exchange based on order books. In this case BTC – USD trading pair.
On exchanges based on order books (not only for crypto), there are players called market makers. They are responsible for providing liquidity to the specific trading pair and for offering bids and asks so that more people can instantly make a trade for the best possible price. The main source of their income comes from the spread between the bid and the offer price (ask).
The problem with making a decentralized exchange (DEX) with an order book is that such an exchange requires very high throughput. There can be thousands of transactions per second if the exchange has multiple different pairs to trade. In the crypto world, it would mean that blockchain has to handle thousands of on-chain transactions per second as well. Currently, Bitcoin has around 7 Tx/sec and Ethereum 15 Tx/sec. There are already chains that can handle such big traffic, but, back in the earlier days, some workaround solutions were needed. This gave rise to decentralized exchanges based on liquidity pools. The latter concept became a foundation of all decentralized finances (DeFi).
How decentralized crypto exchanges work
Firstly, the Liquidity pool (LP) term has to be introduced. LP is a kind of vault where users can deposit their tokens to earn fees from every token exchange going through it.
By knowing how many of each token are locked in the LP, it is possible to count what is the price of the underlying assets. The value of pools A and B must always be equal. Taking the example from the diagram:
BTC – Bitcoin, USDT – token worth 1 USD
It may be hard to believe, but behind the whole idea of DeFi there is just one simple equation – understanding what is crucial to get a concept of DEXes. Based on this equation, the first DeFi services (including exchanges and lending/borrowing protocols) were built. In general, it looks like this:
The result of multiplying the number of A tokens (X) and the number of B tokens (Y) must always be the same (k).
k number in the above example is: 15 * 15,000 = 225,000
Until someone deposits or withdraws tokens from this liquidity pool, the k number must be constant.
Making transactions on DEX
So, on average the person paid 1,500 USDT for 1 BTC (7,500 USDT has been added to LP – was 15,000 USDT and is 22,500 USDT – so 7,500 USDT was equal to 5 BTC). The deeper the liquidity pool is, the lower slippage is (the more it’s possible to exchange for the face price – 1000 USDT in our example).
In this way, exchanges can be done automatically and that’s why it is called an automated market maker.
Over time, there were a lot of modifications to this equation and in some cases (i.e., protocols) it is completely changed. Nevertheless, still many big projects are using it and billions of dollars are automatically managed by it. The biggest ones that are the most recognized are Uniswap and SushiSwap, both built on the Ethereum blockchain.
On the left, you can see the example of exchanging Ethereum (ETH) for USDT on the Uniswap exchange. Price Impact is related to the depth of the liquidity pool – the deeper it is, the smaller the price impact is).
Summary
Liquidity pools are one of the most important innovations in the crypto world. They are based on very simple equations but can operate protocols with billions of dollars in locked value. It’s very important to understand this concept before jumping further into decentralized finance protocols.
Share this post
Written by
RedCompass Labs
You may also like
Resources