Executing trades in a decentralized manner is completely different to placing orders on exchanges.
Instead of relying on an order book, DEXs (decentralized exchanges) use liquidity pools and AMMs (automated market makers).
In this post, I’ll explain how this work in a beginner-friendly way.
Note: this is an educational post, not a recommendation. I’m not a fan of LPing, especially not with your long-term holdings. However, understanding it is crucial if you want to start venturing into DeFi or go airdrop hunting.
Liquidity Pools Explained
A liquidity pool is a smart contract that holds a pair of assets in a balanced position.
When a user buys on a DEX he is not matched with a seller’s order (like in centralized exchanges), but instead he trades against the liquidity pool. As such, liquidity pools enable trading without a centralized intermediary.
To understand how this works, we need to understand the two main roles:
- Liquidity Providers – users that deposit two assets to facilitate trading and earn a % of each trade
- Traders – users that swap via the liquidity pool, paying a % fee for each trade
The liquidity providers get an LP token in return, which is a token representing their share of the pool and is redeemable for the underlying assets.
I’ll use an example to illustrate how this works in a basic sense.
Example: ETH/USDC LP
Let’s say there is a ETH/USDC pool on a DEX such as Uniswap.
A user wants to become a liquidity provider, so he deposits an equal dollar amount of $ETH and $USDC in the liquidity pool. He gets an LP token in return and will earn swap fees. Some protocols also have additional incentives for providing liquidity with them (such as additional APY in the platform’s token etc.).
There’s also a trader that has $ETH and wants to sell it for $USDC.
When initiating a swap, he basically deposits his $ETH in the liquidity pool, and the pool returns the adequate amount of $USDC. The trader also pays some percentage in fees (such as 0.2%), which increases the price of the LP tokens held by the liquidity providers.
But how does the pool know the relative values of both assets? Of course, this is easier to understand when we’re talking about a perfectly balanced pool. However, once a trader deposits $ETH and gets $USDC in return, the pool gets slightly out of balance.
This is where an arbitrage opportunity arises. Because the pool aims to be 50/50, it would “pay more” for someone to rebalance it by depositing more $USDC rather than the other way around.
“Pay more” is in quotes because from the perspective of the pool, it offers the fair market price for both assets. However, in comparison to the whole market (other liquidity pools, centralized exchanges, etc.), the pool is off balance so the price is slightly wrong. This is where users and/or arbitrage bots can choose to swap through this pool for a better price for their $USDC.
Note: the whole DeFi (decentralized finance) market has TVL (total value locked) over $100B. So correcting minor price discrepancies is quite efficient, making them invisible to the user swapping 3-4-5-6 digits worth of assets.
Of course, if the pool is shallow (i.e. you’re swapping $5k in a pool that has $10k in liquidity), it might go wrong as nobody trades or LPs for that pair (and probably one of the tokens is a scam). But for most cases, the process is as explained above.
PS As you become more intermediate, get comfortable using DefiLlama to check the TVL of protocols and the liquidity in each pool thereof.
Impermanent Loss Explained
When it comes to liquidity providing, many beginners get terrified/confused because everyone warns them about “impermanent loss”.
In this section, I want to clarify what IL is and when does it occur in simple terms.
In summary: impermanent loss represents the difference in value when LPing compared to holding the two assets separately.
This can happen when one of the assets from the liquidity pool moves significantly compared to the price of the other.
I think examples always paint the picture much clearly, so here is one:
Example: Impermanent Loss in a USDC/ETH Pool
You provide liquidity in a USDC/ETH pool. Let’s say you provided $500 worth of each. So your distribution is $500 of $USDC / $500 of $ETH.
Let’s say $ETH does a 2x during the year. That means that:
If you held them separately: you would have $1,000 worth of $ETH and $500 worth of $USDC. So $1,500 in total.
If you held them in a pool: As the price of $ETH moves up, the pool will rebalance your position to 50/50. So you’ll still make gains of $ETH’s rise, but a part of the $ETH will be continuously redistributed to $USDC to balance out the pool.
This means that you’ll end up with slightly less $ETH and slightly more $USDC at the end. So you will lose some of the upside from the portion that will get rebalanced into $USDC.
Using the impermanent loss calculator, you would end up with $1,414 in total.
So still up from your initial investment of $1000, but lower compared to not providing liquidity ($1,500).
However, there is also the yield. If this pool yields for example 10% APY, you’ll make around $100 in interest. This covers your “impermanent loss”. Of course, this all depends on the APY and how the assets will perform.
The important thing to notice is how small this so-called “loss” is. So, if an asset doubles, you’re only 5% better by holding the two separately. This means that impermanent loss can be devastating only in situations where assets move significantly from each other.
Use the calculator above to see what it means by providing the initial prices and the future prices.
TLDR:
- $500 of USDC and $500 of ETH held separately, ETH does 2x, you have $1,500.
- $500 of USDC and $500 of ETH in a liquidity pool, ETH does 2x, you have $1,414 + the APY you earned.
Conclusion
There is no conclusion, really.
This is a basic introduction to liquidity pools, LPing, and impermanent loss.
It’s up to you to decide what to do with that information.