Lido Protocol Adapter

The Lido adapter enables the Yieldinator Facet to integrate with Lido's liquid staking protocol, allowing vaults to earn staking rewards on ETH while maintaining liquidity through stETH tokens.

Overview

Lido is a liquid staking solution for Ethereum that allows users to stake their ETH without locking assets or maintaining staking infrastructure. When users stake ETH with Lido, they receive stETH tokens that represent their staked ETH plus accrued staking rewards. The stETH token balance automatically increases over time as staking rewards are earned, providing a simple way to earn yield on ETH while maintaining liquidity. The Lido adapter facilitates deposits into Lido's staking protocol, manages stETH positions, and tracks yield from staking rewards.

Implementation Details

Contract: LidoAdapter.sol

The adapter implements the standard YieldinatorAdapter interface with Lido-specific functionality:

contract LidoAdapter is YieldinatorAdapter {
    using SafeERC20 for IERC20;
    
    // Lido contracts
    address public stETH; // Lido's staked ETH token
    address public wstETH; // Wrapped stETH token
    ILido public lido; // Lido staking contract
    IwstETH public wstETHContract; // Wrapped stETH contract
    
    // Staking configuration
    struct StakingConfig {
        bool useWrapped; // Whether to use wrapped stETH (wstETH)
        bool active; // Whether staking is active
    }
    
    // Configuration for ETH staking
    StakingConfig public ethStakingConfig;
    
    // Deposited amounts
    uint256 public depositedAmount;
    
    // Constructor
    constructor(
        address _admin,
        address _stETH,
        address _wstETH,
        address _lido
    ) YieldinatorAdapter("Lido", _admin) {
        require(_stETH != address(0), "LidoAdapter: stETH cannot be zero address");
        require(_wstETH != address(0), "LidoAdapter: wstETH cannot be zero address");
        require(_lido != address(0), "LidoAdapter: Lido cannot be zero address");
        
        stETH = _stETH;
        wstETH = _wstETH;
        lido = ILido(_lido);
        wstETHContract = IwstETH(_wstETH);
    }
}

Key Functions

Configure Staking

Before using the adapter, the staking configuration must be set:

Deposit

The deposit function handles staking ETH with Lido and optionally wrapping stETH:

Withdraw

The withdraw function handles unstaking from Lido by exchanging stETH for ETH:

Harvest Yield

The harvestYield function calculates the yield earned from staking rewards:

Emergency Withdraw

The emergencyWithdraw function provides a safety mechanism to withdraw all funds:

APY Calculation

The getCurrentAPY function calculates the current APY for staking with Lido:

Get Total Deposited

The getTotalDeposited function returns the total amount of ETH deposited:

Usage Example

Here's an example of how to use the Lido adapter with the Yieldinator Facet:

Security Considerations

  • Validator Risk: Lido's staking security depends on the performance and honesty of its validator set.

  • Smart Contract Risk: The adapter interacts with multiple external contracts which may have vulnerabilities.

  • Liquidity Risk: While stETH is designed to be liquid, there may be periods of limited liquidity for converting back to ETH.

  • Slippage Risk: When exchanging stETH for ETH, users may experience slippage depending on market conditions.

Risk Mitigation

  • The adapter implements strict access controls to prevent unauthorized access.

  • Emergency withdrawal functionality is available to recover funds in case of critical issues.

  • The adapter validates all inputs and handles edge cases to prevent unexpected behavior.

  • Option to use wrapped stETH (wstETH) for better composability with other DeFi protocols.

Gas Optimization

  • The adapter minimizes gas usage by batching operations when possible.

  • The adapter avoids unnecessary approvals by only approving tokens when needed.

  • Using wstETH can reduce gas costs for frequent interactions with the position.

Future Improvements

  • Support for Lido on other networks (Polygon, Solana, Kusama)

  • Integration with Lido's governance system for participating in protocol decisions

  • Support for leveraged staking strategies using stETH as collateral

  • Automated reinvestment of staking rewards for compound growth

  • Integration with insurance protocols to hedge against validator slashing risks