In my previous article, I elaborated on how decentralized exchanges (DEX) function efficiently by tapping on liquidity pools.
Also Read: Demystifying DeFi: What Are Decentralised Exchanges (DEXs) And Why Slippage Occurs
We also understood how slippages occur when utilising a DEX and appreciated the salience of sufficient depth in these pools. In encouraging users to provide their crypto assets into the pools, we recognized that there had to be a financial incentive, and this is manifested in two ways:
- Earning liquidity provider fees when other users utilize the DEX to swap their crypto assets
- Automated Market Makers (AMM) offering liquidity providers a bonus yield in the form of the AMM’s own token
This process of earning by providing liquidity into a liquidity pool is also known as yield farming.
In this article, I shall expound on the intricacies of yield farming in liquidity pools and the risks involved.
Process of yield farming
To start yield farming, you would first need to deposit Liquidity Provider (LP) tokens into the AMM’s pool. This LP token can be obtained by pairing crypto assets in equal value together. To understand this clearly, let’s consider an example:
Similar to the previous article, we shall consider a liquidity pool made up of EGLD and USDC. This is the pool that users will trade against when they want to buy/sell their EGLD for USDC.
As a yield farmer who wants to earn a portion of the transaction fees when other users trade EGLD/USDC, I will first provide liquidity in the form of my own EGLD and USDC tokens. The value of these tokens must be equal.
Assuming 1 EGLD = 200 USDC, for every EGLD that I want to provide, I need to match it with a deposit of 200 USDC. If I have 5 spare EGLD, then I will provide liquidity with 5 EGLD and 1000 USDC.
The value of the tokens must be equal so that the liquidity pool maintains a 50:50 ratio of EGLD and USDC.
After providing liquidity, I will receive an LP token in exchange. This LP token represents my share in the liquidity pool and is proportional to the amount of liquidity that I provided.
Now, when users trade EGLD/USDC, their liquidity provider fees will be consolidated and distributed to liquidity providers based on the amount of LP tokens held.
Ergo, the more EGLD and USDC I provide, the greater my share of the pool, the more LP tokens I receive, and the greater the proportion of rewards allocated to me.
Risks: Impermanent Loss
Impermanent Loss (IL) is arguably the most complex aspect of yield farming that turns people off. Simply put, IL is the phenomenon when HODL-ing your tokens is more beneficial than LP-ing your tokens. To gain some basic intuition on the origin of IL, let’s ignore the math first and consider a broad overview of how the pools work.
When you provide your LP tokens into the pool, the smart contract does not remember the individual amount of assets you LP-ed.
All it remembers is the amount of LP tokens deposited, which is your percentage share of the pool. Hence, when you withdraw your LP tokens to obtain your individual assets, the number of assets you get back may be different from what you provided initially as it is contingent on how the pool’s composition changes over time.
Assuming a pool with 50% EGLD 50% USDC. If the price of EGLD rises, the pool will no longer maintain a 50:50 ratio if the individual amount of each asset stays equal.
As such, arbitrageurs will come in and rebalance the pool by selling some EGLD for USDC, to maintain a 50:50 ratio. Now, when you withdraw your liquidity, your share of the pool contains lesser amount of EGLD and greater amount of USDC than what you provided.
Logically, you will always end up with less of the token that performed better, and more of the token that performed poorer as compared to HODL-ing your tokens, and this is the gist of IL.
Impermanent Loss Calculation
Now, time for the math:
Let 1 EGLD = 200 USDC initially
User provides 5 EGLD and 1000 USDC into the pool
Let X = #EGLD in the pool = 50
Let Y = #USDC in the pool = 10000
k = X * Y = 500,000
User’s share of the pool = 10%
Essentially, to maintain a 50:50 ratio, price of EGLD * #EGLD = price of USDC * #USDC
Simplifying the equation, price of EGLD = 1 * #USDC ÷ #EGLD = Y ÷ X
Now, assume EGLD pumps to 250 USDC
X = Y ÷ Price of EGLD = k ÷ X ÷ 250
X2 = k ÷ 250 = 2000
X = #EGLD = 44.72
Y = Price of EGLD * X = 250 * k ÷ Y
Y2 = 250 * k = 125,000,000
Y = #USDC = 11,180
Now, when the user withdraws his 10% share of the pool, he gets back 4.472 EGLD and 1118 USDC.
This works out to a sum of $2236
In contrast, HODL-ing 5 EGLD and 1000 USDC will be worth $2250
In this case, IL = $14 (0.63%)
Risks: Annual Percentage Rate (APR) vs. Annual Percentage Yield (APY)
This is not a risk per se, but a point to take note of. Some farms boast high APYs, but that is the compounded yield (ie. If you harvest your yield constantly and deposit it back into the pool).
A more realistic expectation is APR, which does not take compounding into account.
Risks: Hard rugs
Malicious anons may create their own yield farms with unreasonably high APYs. When greedy users deposit their LP tokens into these Ponzi farms, the creators can just call the migrator code and migrate the funds from the liquidity pools into their own wallets, and you will never see your funds again.
Risks: Exploits
Liquidity pools may also be compromised by hackers who discover vulnerabilities in the smart contract. They can then drain the pools’ assets and transfer everything into their own wallets.
Risks: Farm tokens going to 0 and soft rugs
The yield issued is typically in the form of the farm token. Because there’s no utility and intrinsic value behind these farm tokens, their price typically goes to 0 when farmers start dumping their yield. This implies that your yield is worthless if you don’t harvest your yield and take profit regularly.
Sometimes, the developers of the farms may also have large amounts of their farm token. After an initial pump in price, they can simply dump it and cause the price to crash (AKA Soft Rug).
Risks: Early withdrawals
This is also not a risk per se, but it is crucial to notice if a pool has a timelock mechanism to discourage early withdrawals.
Some pools have a minimum 24/48/72-hour locked deposit to prevent farmers from hopping from farm to farm. Other pools may implement a withdrawal fee system such that a penalty will be levied on those who withdraw their funds early.
Risks: No withdrawal / no deposit
In some other cases, developers may also implement the withdrawal function as an editable function in the smart contract. This means that halfway through the pool’s lifecycle, the developer can simply set the withdrawal fee to be 100%, such that the liquidity provider can never withdraw his funds.
Alternatively, the deposit fee may be set to 100%. When those who are not observant deposit their funds in the pool, these funds will automatically be transferred into the developer’s wallet instead of going into the pool.
Solutions and evaluation
While risks are prevalent, there are several ways to safeguard one’s funds:
- Choose your farms wisely; it is safer to go for farms that are reputable, audited, have solid backing from investors etc.
- Harvest your yields consistently before it drops too much. It should be noted that there are cases when the yield from farms is locked to ensure sustainability of the farm token’s price. In this case, you should only farm there if you have a long-term mindset.
- If IL is daunting, going for pools that consist of stablecoins will be less stressful since IL is non-existent as stablecoins don’t fluctuate in value. However, it should be noted that IL is not a big deal if the crypto asset pair is relatively stable because the yield can typically cover your IL.
- Manage your expectations, especially since yield is typically proportional to risk. Going for big, audited and reputable farms or pools with stablecoins will likely lead to lower yields. So don’t be greedy and provide liquidity for a shitty pool just because the yield is high. Like any other investments, it is salient to do your own due diligence before investing your hard-earned money.
- If you would like to protect your funds, buying insurance on platforms like Insurace helps too!
I hope this article explains how yield farming works and I wish you all best of luck in your farming endeavours!
Featured Image Credit:
Also read: Demystifying DeFi: What Are Decentralised Exchanges (DEXs) And Why Slippage Occurs