The Ultimate Guide to Leveraged Yield Farming
--
Leveraged Yield Farming is a widely used investment strategy across DeFi because it can provide higher returns and lower risks if used properly. In general, leverage can give 2–3 times more APY than a simple deposit.
I will explain everything you need to know about leveraged yield farming and give an example of such an investment strategy. We will focus on a specific type of strategy, leveraged lending. We researched this strategy during preparation for the development of Eonian — our yield aggregator.
This post is not financial advice and is made for informational purposes only. You should not construe any such information or other material as legal, tax, investment, financial, or other advice. Do your own research before making any investments in crypto. Any investment involves risks, including investments in DeFi.
To start to use leveraged crypto lending, we first need to understand how to make simple lending and where the returns are coming from.
How do Lending Protocols work?
Lending Protocols in DeFi, like Compound and Aave, work the same way as banks in traditional finances. Lenders provide tokens to the protocol to earn interest. At the same time, borrowers receive tokens and pay this interest in return. The only difference is that in DeFi, borrowing is always overcollateralized.
To take a loan from Lending Protocols, you need to provide a deposit bigger than the loan you are going to get. This is also called collateral. In practice, this would mean borrowing $150 worth of USDT will require putting up at least $300 worth of Bitcoin.
But what if the Bitcoin price drops? Lending protocols have a specific mechanism to close positions where the collateral is not enough to support the loan. It is named liquidation. Liquidation will take all collateral from the borrower to repay lenders' deposits.
How to earn in the Lending Protocol?
In lending protocols, you can already earn a small APY by providing liquidity to the protocol. In other term, become a lender. You will receive part of the interest paid by borrowers.
We will take a look at ApeSwap Lending, the fork of Compound on the BSC blockchain. At the moment, the protocol does not have any fees for deposits and withdraws, which makes calculations of returns much easier for us. And it provides a few options to earn a relatively high APY for a lending protocol.
None of the markets give a really big reward, but for us, it is only a start. We will deposit a few USDT to earn 3.8% APY.
Connect your wallet
Click on the “Connect” button and choose your wallet to connect it.
Choose USDT Supply Market
Click in the USDT row in the Supply Markets list. It will open a popup for approving USDT.
Allow protocol access to your tokens
Click on the “Approve” button, then confirm the transaction in your wallet to give ApeSwap access to your USDT.
Wait some time while the transaction is processed, and you will see a new popup where you can choose how much to deposit.
Chose some amount to deposit
In our case, we will deposit 100 USDT. You can see there is +3.84% Supply APY and 0% Distribution APY. First means that you will receive 3.84 USDT per year into your deposit balance. Distribution APY, on the other hand, means how much BANANA token you will get additionally to your main APY. In the current case, it is zero, so we will take a look at it later.
Deposit your tokens
Click on the “Supply” button, then approve the transaction in your wallet and wait until it is completed. You will see that your supplied amount has been increased.
On top of the page, you will see your total balance and expected APY.
Now, as we earn 3.84% APY, we can take a look at how we can increase it. Let’s start with an understanding of how leverage works.
What Is Leverage?
In finance, leverage is a strategy that relies on using borrowed money to increase the potential return on investment. In simple terms, an investor or a trader borrows funds to amplify the exposure to a specific type of assets, projects, or instruments, more so than would be possible by relying only on his capital. Usually, with leverages, investors can multiply their buying power in the market.
The basic idea of leverage is to provide bigger capital efficiency or get the best bang for your buck.
Leverage in DeFi
In DeFi, Leverage working a similar way. We need to borrow tokens while using the already deposited amount as collateral. Then newly borrowed tokens we can deposit to earn additional tokens, like if we initially deposited more.
But how can it be profitable? We are taking a loan whose interest must be bigger than the interest that we will receive from a deposit, or in another way, where will it get money to pay us? We will use a few important aspects of Compound-like protocols to make it profitable.
Collateral Generates Reward
While we borrow, collateral still generates rewards as it was before. Together with the fact that the amount that we borrow is always less than the amount that we deposit. (It is a requirement of protocol, in another case, we were already liquidated). Allow us to estimate the real APY that we will generate.
We need to multiply high borrowing interest on smaller borrowing amounts and multiply the lower deposit interest on the bigger deposited amounts to get it. For example, if we deposit tokens worth $100 for 3% APY, we can borrow a maximum of $70, which have an interest of 5%. Real APY will be calculated like this:
($100 * 3%) - ($70 * 5%) = $3 - $3.5 = -$0.5
That means we will require to pay only $0.5 over the year. Then if we deposit this $70, we will earn interest over it also, which changes our calculations accordingly.
($170 * 3%) - ($70 * 5%) = $5.1 - $3.5 = $1.6
As a result, we have a small profit over a year. This doesn’t make sense so far, as it is less than $3, which we earned before borrowing, but let’s continue.
Incentivize Token
Protocols like Compound use their own protocol token to incentivize users to borrow tokens on the platform by paying additional rewards in their protocol token to borrowers. It is exactly Distribution APY mentioned earlier. In most cases, this APY little bit decreases loan interest for borrowers and sometimes even makes this interest positive. Which means you will be paid if you take the loan.
For us, it means that we can have markets that have lower borrow interest than deposit interest. For example like, in a previous case, we made a $100 deposit with 3% APY and a $70 loan with 2% APY. The result APY will be
($170 * 3%) - ($70 * 2%) = $5.1 - $1.4 = $3.7
That gives a bigger APY than we had initially when deposited.
The biggest part of this APY will be paid in protocols tokens, while our credit will increase directly in tokens that we borrowed.
It means that to grow our portfolio in the initially invested tokens and maintain the initial deposit/credit ratio, we need to claim acquired incentivized tokens and sell them periodically.
Сyclical deposits and borrows
The last part which gives us the ability to earn higher APY is the fact that newly deposited tokens from our loan are also treated as collateral, which allows us to borrow more tokens.
Like in the previous example, where the borrowing ratio is 0.7. When we deposit $100, we take only $70 credit. But when we deposited this $70, our total collateral was $170. It increases our total limit to up to $170 * 0.7 = $119.
This gives us the ability to take in credit an additional $119-$70 = $49. We can then deposit them again and increase our limit again. We can continue doing these iterations until we will have an increase in limit per iteration lower than 10–5%.
Example of Strategy Step by Step
We will go through discussed strategy step-by-step from the point where we stopped earlier. We deposited $100 in the supply market, now we need to enable it as collateral.
Enable USDT as collateral
Toggle Switch on the USDT row to allow the use of it as collateral.
We see a warning popup that explains that we will have a borrowing limit of around $70. Also, if will go over the limit, our collateral will be seized. I will explain the exact risks below in the post.
Click on “Enable USDT as Collateral’. Confirm the transaction in your wallet and wait. After that, you will see that switch was activated.
If you are attentive enough 👀, you will see APY slightly changed because I continue to write this post on a different day, but for strategy profit, it is not critical.
Chose asset to borrow
We already discussed that we would borrow the same asset if it has a lower interest for borrowing than our deposit. Take a looks at the list of Borrow Markets available for us.
Chose USDT borrow market
Click on USDT asset in the borrow markets list. You will see an asset form for borrowing.
You see that we will have Borrow APY equal to 6.85%, which we will pay in USDT. Also, we will have a Distribution APY equal to 5.11%, which we will receive in the $BANANA tokens.
Let’s do a little math
As you remember, we are already receiving 3.64% APY in USDT from our deposit. If we will borrow 70 USDT and deposit them, we will have 170 USDT in the supply market and 70 USDT in the borrowing market. Let’s calculate the result APY.
($170 in USDT * 3.64%) - ($70 in USDT * 6.85%) + ($70 * 5.11% BANANA) =
$6.188 in USDT - $4.795 in USDT + $3.577 in BANANA =
$1.393 in USDT + $3.577 in BABANA = $4.97
That means, from an initial USDT worth $100, we will get around $4.97 per year. As $4.97 / $100 unexpectedly equals 4.97%, we will get 4.97% APY. But only 1.39% APY will be paid in USDT, and 3.57% APY will be paid in BANANA. It is good, but we can do better. Take a look at the USDC market.
USDC borrow APY is positive. It has 0.1876% interest.
Chose USDC Borrow Market
Click on the USDC row to see how it can have such APY.
You can see USDC has a lower Borrow APY equal to 5.59% and a higher Distribution APY equal to 5.78%. This makes the total APY for us positive and equal small 0.19%.
Let’s do math again
If we borrow 70 USDC, exchange it for 70 USDT, and deposit. We can make similar calculations.
($170 in USDT * 3.64%) - ($70 in USDC * 5.59%) + ($70 * 5.78% BANANA) =
$6.188 in USDT - $3.913 in USDC + $4.046 in BANANA =
$2.275 (Direct) + $4.046 BANANA = $6.321 (Direct and BANANA)
Now we have a much higher APY, 2 times higher than the initial deposit APY. Again 6.32% will be paid partially in USDT and BANANA. But there we also see 3.91% interest which we must pay in USDC.
While our deposit generates higher results (in dollars) than our loan is taking, we can not think about it, but if their price changes drastically, it can cause a liquidation. That's why we chose USDC.
USDC, the same way as USDT, is a stablecoin. It means that, at least in theory, they both must have a price of $1. That solves the problem of unexpected liquidation.
Liquidation can happen, for example, in the case of borrowing Bitcoin. If the Bitcoin price increase, our collateral USDT will have the same price. That means when our supply/borrow ratio changes too much, we will be liquidated, and all our collateral will be taken.
We still have some rare cases of liquidation, which I will explain at the bottom of the post. For now, let’s continue.
Borrow USDC
We will borrow 68 USDC as it is around 97% of our limit. We cannot borrow 70 USDC as it will cause immediate liquidation, but we know that we will invest them, which will increase our limit, so borrowing less doesn’t have a point.
Input 68 in the form and click on the borrow button.
Confirm the transaction in your wallet and wait until it is completed. In the USDC row, you will see the amount that you borrowed.
Exchange USDC to USDT
We need to sell USDC for USDT. We can do it at any DEX, but for example, I will use the ApeSwap exchange itself. Go to it through the “Trade” button on top. Connect your wallet and fill swap form.
We will lose a few cents on an exchange, mainly for fees and also some part for price disproportion.
It is small, in proportion to the expected APY, but we need to wait until our strategy will pay even this small fee before withdrawing tokens from the strategy.
Approve USDC for exchange and swap them.
Deposit USDT
After we bought USDT, we must deposit it the same way as before
After the deposit, we see that our limit has changed, and now we used only 54% of it.
Continue the cycle
Now we need to make the same operations: borrow, exchange, and deposit, a few more times until we will have used between 80–90% of our liquidation limit.
Calculate the expected return
We will calculate the expected APY the same way as we were doing it before. We know that a USDT deposit worth $250.5 dollars has a 3.64% APY, a USDC loan for $151.01 have an interest of 5.59%, and a BANANA APY of 5.75%. This gives us…
($250.5 in USDT * 3.64%) - ($151.01 in USDC * 5.59%) + ($151.01 * 5.78% BANANA) =
$9.11 in USDT - $8.44 in USDC + $8.72 in BANANA =
$0.67 (Direct) + $8.72 in BABANA = $9.39 (Direct and BANANA)
In the end, we can expect to earn around $9.39 per year. This means we reached around 10% APY for an initial 100 USDT. But there in this strategy, we have pluses and minuses which you need to consider before you start investing.
Pros and Cons
The main minus of this strategy is that we will receive most of the profit not in the token which we are interested in. It means that we periodically will need to claim a BANANA token, exchange it for USDT and reinvest.
On the one hand, if the BANANA token will be failing, our APY will also fail. On the other hand, if it grows, our APY will grow, also. To make it more predictable, we need to go through this cycle as often as possible but do not forget about transaction commissions, which will eat a big amount of profit on small amounts of exchange.
The risk of liquidation is still present in our strategy. If our deposit APY will not be enough to cover the loan interest, and we will not reinvest BANANA tokens often enough. Our borrowed amount will slowly increase and can go over the liquidation limit.
To prevent this from happening, we borrow only 80% of the limit. Even if our loan interest increases 2 times, we will have around a year to come and reinvest the tokens.
Liquidation also can happen if the price of our deposit assets changes in comparison to borrowed assets. Simples way to solve it is to deposit and borrow the same asset. But we take advantage of stablecoins, as they try to maintain the same price over time, to increase our profit.
Anyway, sometimes even stablecoins go down in comparison to $1. We can forecast what will be with our strategy in such cases:
- If the USDC price goes down, it means our borrowed amount in dollars goes down also. It means we have an even better situation, as our deposit balance keeps the same, but loans start to disappear.
- If the USDT price goes down, we can get the liquidation. If it goes down by 10–20%, we must maintain the same buffer in the liquidation limit to prevent liquidation. But if it goes down more, the stablecoin will probably continue to fail, and we will lose this $100 USDT anyway, the same way as if we were holding it. If you save money in USDT, then this risk after investment stays the same.
I cannot remember when any stablecoin started to grow too much upper $1, but we can estimate even these rare cases:
- If the USDT price goes up, we have the same positive situations, like with a case if USDC goes down.
- If USDC goes up, then we can get the liquidation, but it is really a rare case.
The main plus of this strategy is that we can manually maintain the level of risk and APY suitable to us by balancing the liquidation limit.
We also need to remember that we cannot withdraw all money in one transaction. As we have borrowed more than we deposited initially, the full withdrawal will cause liquidation. To prevent it, we need firstly to withdraw part of USDT, exchange it for USDC and then deposit it back to pay the loan. Repeat this operation a few more times until we will fully cover the loan.
We want to automate it
We are building the yield aggregator to automate such strategies, but if you need help with them or want to know more about our protocol. You can ask any questions in our telegram, discord, or twitter.