paint-brush
Leveraged Yield Farming: Everything You Need to Know to Get Startedby@leovs09
911 reads
911 reads

Leveraged Yield Farming: Everything You Need to Know to Get Started

by Vladislav GoncharovNovember 18th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Lending Protocols in DeFi work the same way as banks in traditional finances. Lenders provide tokens to the protocol to earn interest. Borrowers receive tokens and pay this interest in return. In general, leverage can give 2–3 times more APY than a simple deposit. Lending protocols give interest to lenders who can increase it by borrowing assets and reinvesting them in cycles. The post is not financial advice and is only for informational purposes.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail

Coins Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Leveraged Yield Farming: Everything You Need to Know to Get Started
Vladislav Goncharov HackerNoon profile picture


Leveraged Yield Farming is a widely used investment strategy across DeFi because it can provide higher returns with low 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 initially researched this strategy during preparation for the development of Eonian — our yield aggregator.


I will cover all risks and advantages of this strategy at the end of the post. But remember, this post is not financial advice and is only for informational purposes. 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 use leveraged crypto lending, we first need to understand how to make simple lending and where the returns come 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 will get. This deposit is also called collateral. In practice, this would mean borrowing $150 worth of USDT will require putting up at least $300 worth of Bitcoin.


Lending Protocol Logic


But what if the Bitcoin price drops? Lending protocols have a specific mechanism to close positions where the collateral is insufficient 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 look at ApeSwap Lending, the fork of Compound on the BSC blockchain. I choose it because, currently, 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.


List of markets available for deposit in ApeSwap Lending


None of the markets give a really big reward, but for us, it is only a start. So we will deposit a few USDT to earn 3.8% APY.


Choose USDT Supply Market

Connect your wallet and click on the USDT row in the Supply Markets list. It will open a popup for approving USDT.


Window to approve access to USDT Token.


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 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

Deposit window in ApeSwap Lending
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 muchBANANA 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, approve the transaction in your wallet and wait until it is completed. You will see that your supplied amount has been increased.


USDT market row with the amount deposited


On top of the page, you will see your total balance and expected APY.


Current total position in all markets


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?

Example of leverage for the trader, which provides $100 in collateral and can trade for up to $3000


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 some essential components 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.


The Example of Borrow


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.


The Example of a deposit of borrowed money


($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.


An example is when Lending Protocol has incentivized token


For us, it means we can have markets with lower borrow interest than deposit interest. For Example, 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 that newly deposited tokens from our loan are also treated as collateral, allowing us to borrow more tokens.


An example is that borrows more than deposited initially.


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. So it increases our total limit to up to $170 * 0.7 = $119.


This allows us 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, and now we need to enable it as collateral.



Our current position in the market


Enable USDT as collateral

Toggle Switch on the USDT row to allow the use of it as collateral.


Warning popup for enabling assets 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”. Then, confirm the transaction in your wallet and wait. After that, you will see that switch was activated.



Activated as collateral USDT deposit


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.


List of markets to borrow


Chose USDT borrow market

Click on USDT asset in the borrow markets list. You will see an asset form for borrowing.


USDT Borrow Form


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 already receive 3.64% APY in USDT from our deposit. If we 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 earn 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 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.


USDC borrow form

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 we will be liquidated when our supply/borrow ratio changes too much, 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, which is around 97% of our limit. Unfortunately, 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.


Borrow 68 USDC form

Confirm the transaction in your wallet and wait until it is completed. In the USDC row, you will see the amount that you borrowed.


USDC borrowed market

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.


Swap form for exchange USDC to USDT

We will lose a few cents on an exchange, mainly for fees and part for price disproportion.


It is small, in proportion to the expected APY, but we need to wait until our strategy pays even this tiny 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


Form to deposit newly bought USDT

After the deposit, we see that our limit has changed, and now we use only 54% of it.


Portfolio balance after deposit

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.


Portfolio balance after a few cycles of borrows/deposits

Calculate the expected return

We will calculate the expected APY the same way we did before. We know that a USDT deposit worth $250.5 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 annually. This means we reached about 10% APY for an initial 100 USDT. But 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 fails, our APY will also fail. But, on the other hand, if it grows, our APY will increase, also. So, to make it more predictable, we need to go through this cycle as often as possible but not forget about transaction commissions, which will eat a significant 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. In that case, our borrowed amount will slowly increase and can surpass the liquidation limit.


To prevent this from happening, we borrow only 80% of the limit. So even if our loan interest increases 2 times, we will have around a year to come and reinvest the tokens.


Liquidation can also happen if the price of our deposit assets changes compared 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. So we can forecast what will be with our strategy in such cases:

  • If the USDC price goes down, 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 must also remember that we cannot withdraw all money in one transaction. As we have borrowed more than we deposited initially, the total 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 several times until we 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 or discord.




Sources