What are Liquidity Pools & How do they work?
Dive into the underlying crux of DEXs and AMMs called Liquidity Pools. Understand how they work, terms like slippage and impermanent loss and ways to deal with them.
Introduction
Ever wondered how Jupiter's UI looks so clean and easy to use while centralized exchanges or CEXs like Binance etc. have those flashing books? Well, this is due to something known as Liquidity Pools that power your decentralised exchanges or DEXs.
In this blog, we'll cover the underlying mechanism that powers up your favourite DEX including GooseFX and a few factors that you should be wary of namely Impermanent Loss.
Let's get started!
Automated Market Makers (AMMs)
Firstly, why do DEXs not have those same flashy books? Well, because CEXs run on a CLOB based model or a Central Limit Order Book based model while DEXs typically run on an Automated Market Maker or AMM based model. Let's dissect these terms up.
Market Makers or MMs are the entities that create markets by putting liquidity in the books to help users trade easily. How they achieve this is putting limit orders, that you see in those flashy books to help you trade at the best market price.
How do Market Makers Benefit? Well, giving you the best prices helps them earn fee rebates something which you get at GooseFX as well 👀 on top of making a few points off of the spreads i.e the difference in price of selling and buying that they constantly do.
To earn not only fee rebates but various rewards for trading perps, head over to GooseFX!
While this is feasible on CEXs, it's not really feasible on DEXs due to transaction fees and speed. Every time prices move, MMs have to cancel their orders and re-enter them. As their ideal goal is to just profit off of the spreads and not take any additional net long or short position.
Now, imagine doing this every second for maybe well over 50 orders. Not only it will cost humongous amounts of fees if you're on ETH but also re-entering would be an issue due to signing each transaction then waiting for it to get verified and all of the other stuff.
Thus, Vitalik Buterin came up with the idea of AMMs or Automated Market Makers. AMMs operate on a different model utilizing something known as Liquidity Pools.
Note that, while generally DEXs are AMM based, there also are CLOB based DEXs such as Phoenix Trade on Solana!
Liquidity Pools
Liquidity pools as the name suggests are - well, pools of liquidity of primarily two assets. These pools are guided by mathematical models that determine the ratio of those assets in the pool thus changing the price of the asset given the supply in the pool relative to the other asset.
How these liquidity pools work is that initially these pools are filled via anyone who would like to deposit into them. They are called as Liquidity Providers or LPs. The users are then able to trade against this pool of liquidity which is similar to how users trade against MMs on order books thus the term Automated Market Makerss or AMMs.
Let's take an example of the famous equation that guides the liquidity pools on Uniswap called Constant Product Market Maker or CPMM model. The formula in this case is x * y = k where x and y are the amount of tokens of each asset.
We've covered all of these various types of AMM models in another blog which you should definitely take a look at!
Assume that we have 10 SOL and 10000 USDC
in one liquidity pool leading to an initial price of SOL to be 10000/10 = 1000 USDC
. Also, according to the above equation 10 * 10000 = k.
After a few trades, let's assume that the USDC balance changes to 8000 USDC. Thus, the SOL balance would become 10*10000/8000 = 12.5 SOL leading to a new price of 8000/12.5 = 640 USDC
.
This is how liquidity pools are governed thus changing the price of an asset relative to the other one in the pool. A game of basic supply some might say!
However, it is crucial to note that bigger the liquidity pool, better is it for the user to trade. Why? Because of Slippage.
Slippage
Slippage refers to the price impact when users buy or sell tokens. Bigger transactions relative to the pool's total tokens can significantly affect prices, causing losses making it highly capital inefficient.
As you can see in the above example that since I'm selling my SOL notice the increase in SOL and decrease in USDC implying that I sold SOL rather than buying it , I have sold 2.5 SOL and got 2000 USDC when according to the initial price of 1000 USDC, I should have gotten 2.5 * 1000 = 2500 USDC
leading to a 500 USDC loss for me. This loss is known as slippage.
Slippage as mentioned above occurs either due to low liquidity in these pools or if you're making a big transaction relative to the total amount of tokens in the pool and thus it is crucial to have higher amount of liquidity as much as possible for allowing best swaps.
Well, since users get a portion of the fees generated then they have an incentive to pool a lot of money in these pools to earn yield right? That is correct but there is one thing that LPs should be vary of when it comes to providing liquidity which is known as Impermanent Loss.
Impermanent Loss (IL)
Impermanent loss or IL refers to the difference in token value when held in a Liquidity Pool compared to holding them in your wallet. To understand let's continue the above example with some modifications.
Assume that the initial liquidity in the pool is 10 SOL and 10000 USDC
and a user wants to add SOL and USDC to it. Since these liquidity pools are generally 50/50 weight i.e you have to put equal amount of SOL and USDC in USD value, thus if this user wants to add 5 SOL into it he has to add 5000 USDC into this as well. Thus the total amount he is putting in USD is 5*1000 + 5000 = 10000 USD
. Assuming he does, the final liquidity in the pool is 15 SOL and 15000 USDC
. Thus the user has an equivalent of 33% of the assets in the pool.
After a few trades, let's say there are 18000 USDC and thus according to the x * y = k
equation, the total SOL left would be 15*15000/18000 = 12.5 SOL
. This also implies that price of 1 SOL is now 18000/12.5 = 1440 USDC
. Now, if the user withdraws his share of pool i.e 1/3rd, he will have 4.167 SOL and 6000 USDC along with some fees that he had earned which we're gonna set aside for this example.
Now, if we find the USD value of the user's final holdings, it would come out to be 4.167 *1440 + 6000 = 12000 USD
which is an increase from the initial value of 10000 USDC so all happy days right? Well, not really.
If the user had held his initial 5 SOL and 5000 USDC, the total at current price of 1440 USDC per SOL to be, 5*1440 + 5000 = 12200 USDC
. Thus, the user would have outperformed the yield by simply holding the tokens by 200 USDC. While the effect might seem less pronounced here, imagine what might happen after 1000 trades and a lot of price fluctuations? That's right, Impermanent Loss.
IL is often dubbed as the worst enemy of any liquidity provider
While this is still a recurring issue for any AMM, there have been newer AMM models that have improved upon the first version to help reduce impermanent loss and slippage thus making your capital more efficient. We've covered those different types of AMMs in another blog.
Are there any ways to remove IL?
Well, technically its impossible to remove it. However, there are ways to reduce IL.
The simplest approach is to exclusively supply liquidity with stablecoins since impermanent loss stems from price fluctuations. You could also consider providing liquidity with coins that have relatively stable prices or little fluctuations like bigger market cap assets such as BTC or ETH, although this may result in lower yields. A final way involves utilising very high APY pools such that earning fees from liquidity provision can potentially mitigate these losses.
So, if this is such a persistent issue then why do people still trade on DEXs even on Solana? Well, DEXs have certain advantages against CEXs or CLOB based exchanges.
Firstly, they are resistant against Market manipulation which can easily be done on order books by setting huge limit orders to move the market in their favour. This is called spoofing something which is illegal in traditional markets.
Secondly, DEXs can also facilitate trades at current market price even when there is low liquidity for assets which isn't possible on CEXs as low liquidity on CEXs generally lead to wider spreads. However, the user has to be wary of slippage as discussed above when trading on DEXs.
Ending Thoughts
So, in this blog, we delved a bit into the underlying crux of DEXs or AMMs- Liquidity Pools. We also learnt that while they are vital to how DEXs work, there are other ways to power up an exchange as well which is the CLOB based model. We also understood what the vital issues are with AMMs namely slippage and IL or impermanent loss and how AMMs are advantageous over CLOB based exchanges in a few ways.
I hope you learnt something new today!
Intern out!
Stay Tuned with #GooseAcademy
Website | Twitter | Telegram | Discord | Docs
Disclaimer: The statements, proposals, and details above are informational only, and subject to change. We are in early-stage development and may need to change dates, details, or the project as a whole based on the protocol, team, legal or regulatory needs, or due to developments of Solana/Serum. Nothing above should be construed as financial, legal, or investment advice.
Comments ()