owned this note
owned this note
Published
Linked with GitHub
# Margin Staking: A Comprehensive Guide [DRAFT]
**This is a draft writeup for informational purposes only**
## Introduction
This piece explores the potential risks and rewards associated with employing a **Margined Staking strategy**. The objective of this strategy is to collect more blockchain staking rewards while minimizing the initial capital investment required. To achieve this, the strategy involves utilizing a Liquid Staking Token (LST), which serves as a tradable token representing locked or staked cryptocurrency, thereby granting liquidity to the previously illiquid tokens.
### screenshot from this [Margined Staking Calculator](https://driftv2.streamlit.app/?tab=SuperStake)

**note: these are constantly varying rates**
"Margined Staking" is also under terms like:
- "Super Staking"
- "Levered Staking"
on Solana, an example could include
- acquire SOL to stake and recieve a LST (e.g. mSOL)
- deposit the LST in a DeFi program and access margin to borrow additional SOL
- call recursively until desired target (or once through a single flash loan)
This recursive process, while amplifying the potential rewards, also compounds the risks associated with leverage. We explore both the user and defi program risks associated with this.
The math for calculating the projected returns is available in the [Appendix](#Appendix)
## User Risks

Leverage staking, while offering high projected returns, also comes with a fair share of risks. Users interested in this strategy should take several key considerations into account:
* **Liquid Staking Rewards**: returns anticipated from staking tokens with network validators.
* **Borrow Rates**: The sustainable execution of leverage staking relies on the premise that the projected borrow rates will remain lower than the staking rewards.
* **Miscellaneous Fees**: Operating in DeFi involves various transaction fees. The most common include Layer 1 (L1) transaction fees, borrow origination fees, implicit rounding fees, and those incurred while unwinding positions, which might require asset swaps or other additional procedures. These costs need to be factored into the strategy to ensure profitability, which may require a sufficiently long time horizon.
* **Duration Mismatch**: the staking rewards and borrow rates are applied at during frequencies (epoch changes (2days) and continuous). Timing of entering / exiting around epochs can alter returns.
* **Finite Capacity**: Implementing a leverage staking strategy requires borrowing assets, effectively putting them to use within the network. If the interest paid to borrow the asset exceeds the staking reward, the strategy becomes unprofitable. It's essential to note that these rates are dynamic, which means that the profitability of the strategy will fluctuate over time.
* **Crowding Risk**: This term refers to the risk associated with the liquidity of leveraged staking tokens (e.g., mSOL). In the event of mass exits during market downturns, these tokens could trade at a discount. The discount could be severe enough to trigger liquidation for a levered staker.
* **Withdraw Risk**: DeFi programs often implement withdrawal limits which may hinder the timely execution of withdrawals or even unwinding one asset into another (if it requires external liquidity).
* **Oracle Reliablity**: The DeFi program utilizing an external oracle price for the token borrows. In cases where these oracles falter or inaccurately report prices, it may lead to challenges in withdrawals, unwinding, or even cause unexpected liquidation losses.
Considering these factors, we can develop a risk spectrum associated with different activities involving a token:
| Risk Level | Activity |
|------------------|--------------------|
| High Risk | Leverage Speculation |
| High Risk | Leverage Staking |
| Medium Risk | Lending |
| Medium Risk | Staking |
| Low Risk | Hodl |
Although leverage staking is a high-risk activity, the correlation between lent and borrowed assets for the position tends to decrease the likelihood of liquidation compared to other forms of leverage speculation. However, it combines the risks of lending and staking, with the primary concern being the divergence in tail events. Additionally, DeFi programs offering leverage or lending may themselves become insolvent, posing a further risk.
To help mitigate these risks, active management and monitoring are recommended, ideally with the assistance of a well-structured bot or other tooling. These tools can increase reaction speed in times of market distress and provide a more resilient strategy without reliance on external client interfaces.
Lastly, one requires strong conviction in the DeFi program, the blockchain, and the liquid staking token program. If the margining risk parameters are dynamic or adjustable, or if the blockchain experiences downtime or costly state contention, the strategy may face liquidation or unexpected losses. The realm of possibilities for things that can reasonably go wrong seems endless, but all margin strategy carry similar tail risks. Less leverage decreases (but never eliminates) these risks.
## Margin Protocol Risks

*"Whales" here is used loosely, consider yourself fortunate if you classify*
Important aspects to consider for a base layer protocol offering margin through a borrow-lend model are:
* **Avoid excessive utilization**: At high utilization rates, lenders can face difficulties withdrawing their funds. If margined stakers are lending their Liquid Staking Tokens (LSTs), they could be unable to unwind their positions if utilization is too high. Although it may be unlikely for someone to fully borrow an LST except in the event of an LST implementation flaw, this risk still exists for lenders.
* **Prevent bankruptcy**: The best way for a protocol avoid bankruptcies is by offering lower leverage for large positions and sourcing sufficient liquidity for the market's open interest, even in tail events. Adding borrow liquidity limits can help ensure these boundaries do not get crossed too far.
* **Ensure robust insurance for lenders**: An insurance fund can be built using a portion of the borrow fees from DeFi programs. For example, a fraction of SOL borrow fees can be directed towards the SOL market's insurance fund. To help bootstrap the fund to a sufficient size, external stakers can be allowed to participate, earning a portion of the fund's revenue. It's crucial to ensure that insurance is in the same denomination as the debt to avoid potential price issues.
Isolating risks across different markets is a valuable safety feature. If one market experiences a failure – for instance, significant losses due to high leverage – it should not adversely impact the insurance or integrity of another market, assuming all other conditions remain the same. This approach ensures that risks do not spread across markets and that losses are contained within the market in which they occurred.
If the event of bankruptcy and insufficient insurance, its important for the program to gracefully handle these losses. Typically, this is done through socializing the loss across all the lenders for an asset where a counterparty ended up bankrupt.
## LST Token Risks
Holding an LST token can underperform direct staking in a few ways.
For example: mSOL is issued by Marinade Finance, which charges a flat 6% fee over all the pool's rewards from staking. This is on top of the already custom and alterable validator fees.
Additionally, all mSOL holders socialize all the validators staking performance (rewards + slashes). That is, one user direct staking with a single validator and recieving mSOL means every mSOL holder gets a sliver of that validator's performance.
Given the [warmup/cooldown period rules with staking](#SOL-Stake-Delegation-Rules) large enter and exits into mSOL can degrade performance for holders. This issue has been explored and discussed in [Marinade's forum](https://forum.marinade.finance/t/mdao-proposal-introduce-delay-unstake-fee-0-1/481) with potential solutions involving fee changes. Since the LST program and parameters are mutable, any fee structure can change over time and should be considered.
Other details in the mechanics of the staking pool may lead to unexpected performance. mSOL operates of shares of SOL available, so all acrued value shows up in the mSOL "share" price and balances remain unchanged. This is opposed to [Lido's stETH](https://stake.lido.fi/) which periodically rebases a holder's balances.
> stETH is a transferable rebasing utility token representing a share of the total ETH staked through the protocol, which consists of user deposits and staking rewards. Because stETH rebases daily, it communicates the position of the share daily.
## Example Calculations for Margin Staking
In early development stage is [this calculator](https://driftv2.streamlit.app/?tab=SuperStake) ([source code here](https://github.com/0xbigz/drift-v2-streamlit/blob/main/superstake.py)), where one can assess detailed information about the leverage staking rewards / risks.
This calculator considers the "impact" (borrow rates, margin, etc) of proposed stakes using drift protocol-v2 and calculates the expected annualized rewards in SOL for a given size / leverage. [This v2-teacher documentation](https://drift-labs.github.io/v2-teacher/#margin-system) describes the margin system formulation.
### small position size
- divergence amounts. at 3x leverage of a small position size @ ~20% depeg, while lower leverage allows for much more room on depeg.

18.5% decrease in mSOL price OR 22.7% increase in SOL price (all else equal)
This depeg in price can be viewed as a mSOL/SOL ratio. if mSOL denominated in SOL falls to the liquidation price line. Be sure to inspect for relevant size, as the liquidation price would get more strict.

### larger position size
- the calculator also incorporates size discount factors (IMF factors) for large size positions
- for larger sizes, [the IMF factors](https://twitter.com/bigz_Pubkey/status/1656647671325622273) kick in liquidate at smaller diverges than ordinary.
For example, paying with the calculator, the liquidation divergence gap becomes more strict at larger sizes (30k mSOL after leverage -> ~13% divergence).
With the aid of this calculator, you can observe how the liquidation divergence becomes narrower at larger sizes. For example, a very large position size may not even accommodate 3x leverage, as even minor divergences could trigger liquidation.
Plot showing how larger size increases the Liquidation Price (at 2x leverage). Starting with ~80k mSOL, and then attempting 2x leverage (160k mSOL with >80k SOL borrow), puts the liquidation price very close to the current price.

Note that the price level change of mSOL or SOL would not impact these protocol size discounts factors (since they are applied to the token sizes). However, when permitted, a DEX could update these risk parameter factors, so always be cautious and monitor at larger sizes.
## Historical Analysis of Margin Staking
### Rates
[historical stake yields](https://hackmd.io/izS7KqSPQJ-cnVHyFSa6xQ?both#Appendix) for mSOL

SOL token's annualized interest rate curve from drift protocol-v2 (as of June 22, 2023). Above 60% utilization makes the marginal value of the strategy unprofitable (where heading to 100% is painful for borrows).

Looking back many months, drift-v2 SOL utilization has varied between 0-30%.

A rough estimation based on these plots suggests that the staking yield on mSOL is ~6%, while SOL borrow rates have averaged ~1-2% on drift-v2. This implies that leveraged staking would have had a positive marginal value.
Clearly the borrow rates are volatility so actively monitoring is important for any profit sensitive margining. While incentives should be aligned for unprofitability to never to way too high (lending SOL yields exceed staking), the attention + contract-risk premium to statistical arbitrage on-chain activity should never assumed.
### Price
Unfortunately the [Pyth Oracle for mSOL](https://pyth.network/price-feeds/crypto-msol-usd?range=1M&cluster=mainnet-beta) doesn't show history beyond a month (and even so their chart's grouping method used for lower resolution may smooth or high high/low values).
but looking through other historical data sources of LP pools and a [personal account by @0xSoju](https://twitter.com/0xSoju/status/1671076506200850434) and reveal that a depeg of about 15% was realized around November 9th, 2022 (FTX insolvency news event).

Can see that the [fair value of mSOL](https://stats.marinade.finance/d/sqUQd1Onk/marinade-kpi-dashboard?orgId=1&refresh=1m&from=now-1y&to=now) is stable, and "up only" (without Solana blockchain slashing), so this depeg was primarily a liquidity discount (and perhaps also a broader Solana blockchain concern).

Zooming out, we see the actual mSOL appreciation comes from epoch changes (~2 days).

The liquidity discount arises because the staking and unstaking processes isn't atomic, and necessitate warmup and cooldown periods.
#### SOL Stake Delegation Rules
Staking requires a waiting period spanning multiple epochs before rewards can be accrued. Staking and unstaking activities are formally conducted at epoch boundaries, which typically span 2-4 days on average. The duration of these processes varies depending on the specific timing within an epoch and the length of the epoch itself.
You can read more and see examples in the technical docs around [Stake Delegation and Rewards](https://docs.solana.com/cluster/stake-delegation-and-rewards).
### Liquidity
Below is the instant unstake pool by Marinade. After the November 9, 2022 event, the Marinade DAO [proposed](https://forum.marinade.finance/t/dao-proposal-liquid-unstake-pool-parameters-change/423) and updated to a stricter [dynamic fast withdraw fee structure](
https://docs.marinade.finance/faq/faq#unstake-now).

## Conclusion

Key observations highlight that this is a low-capacity strategy, highly dependent on the availability of cheap SOL for lending. Since SOL utilization can fluctuate, crowding can lead to this strategy becoming unprofitable. Additionally, a lot of conviction must to placed in both the margining and the LST token programs.
Many DeFi strategies have limited capacity. Hence, savvy users often keep a low profile and avoid stretching the limits too far due to diminishing marginal returns. Passive participation in this strategy could work, but only if it remains niche and does not gain wide-spread popularity.
## Appendix
let $LST$, be the liquid staked token, $T$ be the unstaked token, and $Price_{LST/T}$ is the price of `LST` denominated in `T`. This price should grow over time as staking rewards accumulate.
Also assume $leverage$ = 1 means no borrow is opened.
**LST Deposit Amount:**
$$
LST_{levered} = LST_{collateral} \times leverage
$$
**Token Borrow Amount:**
$$ T_{borrowed} = LST_{collateral} \times (leverage - 1) \times Price_{LST/T} $$
**Leverage Stake Yield**
- Inflows:
$$
inflows_{LST} = LST_{levered} \times (r_{stake} + r_{lend_{LST}})
$$
- Outflows:
$$
outflows_{T} = T_{borrowed} \times r_{borrow_{T}}
$$
- Token Net Reward:
$$
NetReward_{T} = (inflows_{LST} \times Price_{LST/T}) - outflows_{T}
$$
- Token Yield:
$$
Y_{T} = \frac{NetReward_{T}}{LST_{collateral} \times Price_{LST/T}}
$$