PRO: Leverage Bible

Some tips for skilled [degenerate] farmers and traders.

A different understanding of "collateral"

DeFi users are accustomed to think of collateral as "idle asset, sits there and changes my borrowing power for better or worse". With Gearbox, it's not exactly like that. That is because the entire composition of your Credit Account, whatever you have on it - be it WBTC or a farm token - acts as collateral to your debt at the same time. Denominated in the debt asset, of course.
If you go put in ETH and WBTC but then swap all your assets into a stablecoin farm - your collateral now is the ERC20 representation of that stablecoin farm. Your ETH became something else.
Your starting asset(s) are usually not relevant. What is important is your debt asset - and then all of the assets on your Credit Account denominated in that debt asset.
In case you want to keep your asset as truly collateral, for example you want to keep ETH yet borrow stables and grow your borrowing power, then you need to keep it idle on Credit Account:
  • Open a Credit Account with debt in stablecoin (USDC, for example)
  • Put ETH in there as collateral and NOT sell it or not ape it into a position
  • Borrow more stables due to ETH borrowing power
You lose some capital efficiency since not your entire position is "working", but that might be indeed your strategy. ETH goes up and u can borrow even more stables - that could work!

What is the minimum / maximum leverage?

The protocol works without any trust or off-chain mechanisms, so the values are derived from on-chain. Even if the interface sometimes can show that your maximum leverage is reached - in reality, by interacting with the contracts on-chain, you could squeeze to the last bits!
  • Min leverage is only defined by the minimum borrow amount. If $100K is the min: it can be an x2 position if you do it with $100K initial capital [your capital worth $100K where $100K is the minimum limit x2 leverage = $200K total]; or can be an x6 if your initial capital is $20K [your capital is worth $20K and at x6 it means your position will be $120K total, so $100K borrowed].
  • Now, the maximum leverage is more complex than that...

How to calculate max leverage?

First of all, you need to understand how Health Factor works. In a nutshell, all of the assets on your Credit Account are denominated in the debt asset you took as a borrowable asset. In other words, all the assets on your Credit Account in total act as collateral. Whether you have some ERC20s on your CA or farming positions - all of them have LTVs with respect to the debt asset you have chosen.
In case you want simple liquidation levels, you can isolate positions per different debt assets. Like: stablecoin farm vs stablecoin debt asset. Or ETH Lido farms with wstETH or WETH as debt. Then it's much simpler for you to know the liquidation prices. In case you cross-margin a few positions with different assets within a single Credit Account, it becomes harder. But maybe that's your goal after all, like those trying to go delta-neutral or get paying longs Boosted Long/Short or "Free Leverage".
The math for max leverage works as follows:
1/(1LT)1 / (1 – LT)
Let's say you go into Convex GUSD3crv farm [stkcvxgusd3CRV] with debt as USDC. If LTV for that is 90, the max leverage would be: 1/(1-0,90) = 10x. Let's do yvCurve-stETH [Yearn farm for stETH/ETH Curve pool] with WETH as debt. The LTV for either is 90 right now. That means 1/(1-0,90) = 10x as well. If LTVs for some farms become higher, more leverage could be applied.
That's technically the max leverage you can take which will make your HF = 1. If the deviations in assets within a farm [assets on your Credit Account acting as collateral] never occur - then you can remain as is, but that's VERY risky. It's better to count in some fluctuations.
You don't have to assume the worst case scenario right away. You can simply rebalance and reduce leverage [or debt] to avoid liquidations. If you are active in DeFi, you can take changes after sensing a farm could be worsening. No requirement to do it from the start.

How to max out... but kinda "safely"?

These tips are for traders & farmers who are absolutely degenerate. Maximum leverage, maximum risk. Exercise with caution. It's better if you are able to understand Etherscan WRITE functions in case anything goes wrong with the interface. Be careful and read the code!
Keep in mind that in reality you could encounter slippage, fast price changes, and other scenarios - so don't try to squueze every last drop unless you are a MEV guru. It's better to be safe and reduce your desired leverage factor by at least a factor of 0.25 or 0.5 to account for those. It still keeps you maxed out but helps avoid a liquidation.
Let's say you want to go into FRAX3Crv. Out of all the assets inside, you might think that FRAX has some perceived risk. Maybe yes maybe no, doesn't matter for this exercise. Your debt asset is USDC, and you just wanna max out this farm. Let's say LTV is 90. The formula is:
N=1/(1LTp)N = 1 / (1-LT*p)
Where N is the max leverage factor that you are trying to find, and p is the price you think that FRAX price could drop to. Let's say you think that the lowest it could go to is $0.95. So then it is:
6.896=1/(10,900,95)6.896 = 1/(1-0,90*0,95)
That means with leverage of x6.8 you are still fine even if FRAX price drops to $0.95.
Let's look at what price [according to Chainlink oracles specifically] FRAX was has ever dropped to: that would be 0.9871. As such, if you don't expect it to ever go lower than historic, you might apply the following calculations: 1/(1-0,90*0,9871) = 8.959 leverage! You can find all these values on-chain yourself, but check out [copy & edit] this GOOGLE SHEET to play with scenarios.
Here is the link to the sheet above. Copy and play with the values, check scenarios, etc.
Let's try this exercise with Convex steCRV [Curve stETH/ETH pool]. That would be:
1/(10,900,935)=6.31/(1-0,90*0,935) = 6.3
That is max leverage factor you can apply if you are afraid of stETH ever revisiting its lows compared to the debt asset (ETH). In case you think the lows could be 0.90 relative to ETH, then the max leverage would be: 1/(1-0,90*0,90) = 5.26. Still, pretty damn capital efficient to farm with such leverage! FYI, Gearbox Protocol currently uses USD Chainlink or Redstone price feeds, so the ETH debt calculations are using an extra hoop when it comes to conversions.
Check this article about Yearn, Curve, & other oracles. And read code!

Where do price feeds come from?

Great question, degen! You probably want to leave a bit of a leeway for some price fluctuations... Hold on, where do the prices come from? As a simple reply: currently, only from oracle privders like Chainlink and Redstone. So this is where you should look for the source of truth, it's open to everyone on-chain.
With farming positions it's a bit more tricky. For the implementation of Curve pool oracles [as such, Yearn & Convex positions for these assets respectively too], custom PriceFeeds look at virtualprice * price of the cheapest asset inside the pool. That is because in an event that any one asset inside a Curve pool goes down in price, the pool automatically trades into that asset. So while not a 100% will be traded into it immediately, for the safety of Gearbox Protocol, the worst case scenario is assumed when calculating the position value.
For the avoidance* of Cream-like flash loan attacks, there is a min-max range applied to LP token price shares, which can be observed in the code/audits + mentioned in here.
*That is, unless a new attack vector is found. Security is important, please verify.

A few words about slippage

When swapping large amounts at once, you can encounter slippage. That is totally normal to have, like 0.05% on $1M is not unusual = $500 loss. But you have to keep in mind that you can't socialize losses with the borrowed capital, so that loss is applied to your assets within the Credit Account only. Otherwise it would be an attack vector that would let an attacker "lose" all lender money.
What it means is that if you went x10 leverage on $100K of your capital, you will technically get a 1% loss on your capital, meaning -1% instantly. Sounds scary? Hold on!
That is not really an issue if you are leverage farming, because your larger position also makes back larger APY (per each leverage factor). On a medium to long-term timeline (or even short-term) this is practically negligible. It's the same as if you did not use leverage!
You keep all the profits to yourself. Just don't... trade poorly, ok?!
This is all standard. Just don't be surprised when you ape with size! The interface shows the worst case scenario, in reality you might have not lost anything at all.

Doomer interface numbers

The above happens because the dApps [both the https://app.gearbox.fi/ and https://charts.gearbox.finance/pools] use Chainlink or Redstone oracles to calculate prices in the UI instead of spot prices, and those quite often deviate. So, the interface presents an overly pessimistic scenario. You can check Nansen instead for the prices and value of your Credit Account closer to reality. Just input your Credit Account address into Nansen, and you can see all the positions there.
An even better way is to check on-chain virtual price of the positions you are in. So, the loss you are seeing in the dApps is just an honest max-pessimism scenario. Reality is always better!
The same goes for slippage numbers in the interface when you try to trade & swap assets. In those cases, the interface shows the maximum drop in case your slippage, let's say if it is selected as 0.2%. Try making it lower, and the number will improve.

Claim farming rewards before closing CA

The interface logic doesn't always perfectly claim your unclaimed rewards efficiently, from Curve or Convex, so make sure to claim them before closing your Credit Account. These rewards would not be lost conceptually, but the next user of this particular CA might wake up with a nice present. Unless you are playing a "take 100 bucks, or I double it and pass onto the next" - not recommended.
  • first claim your rewards from Curve / Convex / etc.
  • then close your Credit Account, super easy

PURE liquidation price calculation

Since PURE uses real assets, the slippage and liquidity requirement isn’t just limited to your collateral but the entirety of your position. This leads to the calculation of liquidation price being slightly different than what you are used to on perps, and hence needs more attention while opening a position. It's all visible in the dApp, we are just pointing this out so you are super aware of the differences.
With this being the alpha version, we have been conservative with the LTVs, as the risk framework evolves, the UX on this too should improve. It’s not a protocol “issue”, just a precautionary risk management that should improve as we grow. Trade safe!

Now, go, degen ->
When exercising max leverage - you should keep in mind that even a few-minutes of interface not responding properly [Infura/Alchemy downtime, bugs, whatever it is] can lead to liquidations. Everyone remembers the "oops maintaince mode" of BitMex? Well, in DeFi you can control these cases, because the contracts are onchain / verified - as such, you can interact with them directly without any interface. See the contracts.