[Strategy] yDai - Leveraged COMP farming - added yUSDC & yUNI

Summary:

Use Dai in the yDai Vault to supply and borrow Dai on Compound and sell COMP for yield and to pay the fees. Instead of a simple supply and borrow we can maximise yield by leveraging both positions up to the collateral factor.

Abstract:

The vault uses recursion (or flashloans or other means) to supply Compound with dai_vault * 1/(1-collatoral_factor) and borrows dai_vault * (1/(1-collatoral_factor)-1). The position should not be liquidatable because the collateral token and the borrowed token are the same and the ratio is fixed when setting up the position. A safety margin should be applied to the collateral factor, which would decrease yield slightly.

Example with current Compound rates:

100 Dai in Vault
Collateral Factor for Dai is currently 75%
100 Dai * 1/0.25 -> 400 Dai supplied with 5.86% APY
(2.82% supply rate + 3.04% COMP)
100 Dai * 1/0.25-1 -> 300 Dai borrowed with 0.10% APY 
   (-3.90% borrow rate + 4.00% COMP)
-----------------
23.744% APY total
300 Dai borrowed is exactly 75% of the 400

With a safetly margin of 5% (using only a collateral ratio of 70%) we still get 19.7% APY.

Motivation:

Get better yield than currently. This Strategy can also be used for yUSDC vaults (or others e.g yUNI) and for usage in the yETH vault. Once implemented we can use it in v2 Vaults as an alternative strategy for many vaults (basically any profitable token on Compound). Currently there are 1200 million Dai supplied in Compound and about 960 million Dai borrowed out. Imo some 100 million more or less should not impact rates too much - especially since both supply and borrow amout in compound raise in similar proportion.

Specification:

Supply 1/(1-scf) #token_in_vault to COMP and Borrow 1/(1-scf)-1 #token_in_vault from COMP to farm COMP with leverage.
collateral_factor (short cf) is defined by COMP per token_type.
safe_collateral_factor (short scf) is defined by Yearn to ensure no liquidation takes place.
scf = cf - safety_margin

For DAI & USDC:
cf = 0.75
scf = 0.7 (proposed - to be discussed)
For UNI:
cf = 0.6
scf = 0.55 (proposed - to be discussed)

There are multiple options to go into leveraged positions in COMP:

  1. Recursion
  2. Flashloan
  3. Pseudo-Flashloan

Recursion is illustrated in the diagram:

recursive_token (1)
Flashloan utilizes Aaves flashloans for providing the target supply according to the formula without iterating. The borrowed assets are used to pay back the flashloan.

Pseudo-Flashloans could use other funds as collateral (e.g. YFI) to borrow the funds from a lending platform (probably Aave) to reach target supply without paying the fees for a regular flashloan. The debt could be payed back subsequently (even in the same transaction) with the borrowed asset.

For:

  • Better yield than current vault
  • Usable for other Vaults
  • great addition to v2 Vaults as an additional strategy

Against:

  • With large volume it might impact Compounds rates
  • Need to track collateral ratio if Compound community decides to change ratio

Poll:

Should we add this Strategy to out Vaults
  • Cool let’s do it
  • Nah this sucks

0 voters

1 Like

if you open the position exactly at the liquidation ratio, won’t it be vulnerable the second it starts accruing interest, since the borrow rate is higher than the supply rate?

1 Like

How does 400 DAI with a 5.86% APY and 300 DAI with 0.10% APY equal a total of 23.74% APY specified in your example?

Initial investment is 100 Dai - you get 400 Dai with 5,86% and 300 Dai with 0.10% from it.

Absolutely! There probably needs to be a safety margin! There is a safety margin in Compound of 5% additional to the collateral ratio, but I’m not sure it would apply in this case.

safe_collateral_factor = collateral_factor - safety_margin

I added a sentence about a safety margin. With a safetly margin of 5% we still get 19.7% APY.

The APY will be reduced with the volume we would provide, not sure you will be able to leverage yourself that much.

Though, given V2 vault will allow up to 20 strategies, it sounds reasonable to have this one running with limited funds.

I’m currently working on a strategy extremely similar to this with @macarse right now. The relevant forum post is attached.

We decided to start building on Compound instead of Aave at the moment due to the added yield from COMP - but the core concept is nearly identical.

Note: this is all out of date. Apologies. Please ignore!
One important note: You cannot supply and borrow the same asset on Compound. If you supplied DAI you couldn’t borrow it - so this won’t work as written. You’d need to take out a different stablecoin for the leveraging. This introduces liquidation risk to the vault in the unlikely scenario that DAI falls in value compared to the other stablecoin, e.g. USDC.

Edit: it is possible to supply/borrow the same asset on Compound. I was wrong. Womp womp.

2 Likes

It was possible before if you interacted with the smartcontract before - did they fix this?
Personally I borrowed tether and deposited usdc/dai (depending on the rates) switched via SWERVE/CURVE.

Are you absolutely sure its not possible anymore? Because the risk is much higher if you use different stablecoins…

Nope, I was wrong. It looks like you can now! Will edit my previous post.

You can use Instadapp as a second layer to be able to supply the borrowed asset again into comp.

I have a smart contract that does this with my own funds. Have been using it for a few months now. I could probably adapt it for use as a yearn strategy if you’re interested.

Very simply it flash loans into the position leveraging up to 99% of allowed collateral level.

Then to harvest it borrows 1 dai. Lends 1 dai. This triggers the comp airdrop. Sells the comp on uniswap for dai and leverages up again.

To exit it flash loans back out.

99% of the allowed collateral level is pretty safe as we know how much interest is accruing each block and so can set our safety parameters around that. I think I calculated I had about 2 month runway of accrued interest at the higher end of the curve before liquidation. But it has been a while since I did it so don’t remember exactly.

There would be some more considerations because of the amount of liquidity yearn is throwing around. But I’m sure with some help we could work it out.

Edit: to add. The way compound works there is no liquidation risk from price changes when using same token to borrow and lend.

I guess this is where I am still confused. How does 100 DAI get you 400 DAI.

How does 5.86% + 0.10% = 23.74% APY.

Can you break it down step by step?

You start with 100 dai. You flash loan 300 dai so now have 400 dai in balance. You now lend that 400 dai to compound.

You then borrow 300 dai (75% collat ratio) and use it to repay the loan.

Now you have a position where you have 400 lent earning 5.86% (23.44 dai) and 300 borrowed earning 0.1% (0.3 dai). So on the 100 dai you started with you are earning 23.74 dai - or 23.74%

2 Likes

Can you elaborate on the comp airdrop trigger? Is it not a function of time?
I won’t be the one implementing it - but I guess sharing is caring :slight_smile: and I’m curious about your contract.

Comp accrues every block but you have to trigger an airdrop to receive it into your wallet. This can by done by the claim comp function. But it is very expensive (high gas cost).

You can also trigger the airdrop by interacting with the cToken contract. It is triggered by transfer, mint, redeem, borrow or repay. Borrow and lend are treated differently so you need to trigger both.

So a cheap way is to do a borrow/repay and a lend/redeem.

1 Like

@gspoosi Why don’t you send those wrapped coins into the compound curve pool on top of your leverage?
The CRV distribution is currently appealing

Pickle already implemented this strategy…

So we just too slow on the strategy front - imo we should still use it, since yearn is not anon…

1 Like

You can’t move cDAI because they are being used as collateral for borrowing more DAI

1 Like

Does anyone have an interface or guide of what needs to go in a Yearn strategy? I can create this pretty quickly but don’t have experience with yearn strategies so would be best to collaborate with someone who knows yearn better.