Beefy Finance Protocol Adapter

The Beefy Finance adapter enables the Yieldinator Facet to integrate with Beefy's multi-chain yield optimization vaults, allowing users to earn auto-compounded yields across multiple blockchain networks.

Overview

Beefy Finance is a decentralized, multi-chain yield optimizer platform that allows users to earn compound interest on their crypto holdings. The protocol automates the best yield farming opportunities across 15+ blockchain networks by leveraging different DeFi protocols and strategies. Beefy's vaults auto-harvest rewards and reinvest them to maximize returns while minimizing gas costs.

The Beefy adapter facilitates deposits into Beefy vaults, manages mooToken balances (Beefy's vault tokens), and handles cross-chain yield optimization through a standardized interface.

Implementation Details

Contract: BeefyAdapter.sol

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

contract BeefyAdapter is YieldinatorAdapter {
    using SafeERC20 for IERC20;
    
    // Vault configuration
    struct VaultConfig {
        address vault;        // Beefy vault address
        address mooToken;     // Vault's receipt token (mooToken)
        address want;         // Token the vault accepts (underlying asset)
        uint256 chainId;      // Chain ID where the vault is deployed
        bool active;          // Whether the vault is active
    }
    
    // Mapping from token to vault configuration
    mapping(address => VaultConfig) public tokenToVault;
    
    // Deposited amounts per token
    mapping(address => uint256) public depositedAmount;
    
    // Chain ID registry for cross-chain operations
    mapping(uint256 => bool) public supportedChainIds;
    
    // Cross-chain bridge contracts (if applicable)
    address public bridgeContract;
    
    // Constructor
    constructor(
        address _admin,
        address _bridgeContract
    ) YieldinatorAdapter("Beefy Finance", _admin) {
        require(_bridgeContract != address(0), "BeefyAdapter: bridge contract cannot be zero address");
        bridgeContract = _bridgeContract;
        
        // Add default supported chain (current chain)
        supportedChainIds[block.chainid] = true;
    }
}

Key Functions

Vault Registration

Before using the adapter for a specific token, the vault must be registered:

Deposit

The deposit function handles adding funds to Beefy vaults, with special handling for cross-chain deposits:

Withdraw

The withdraw function handles removing funds from Beefy vaults, with special handling for cross-chain withdrawals:

Harvest Yield

The harvestYield function collects auto-compounded yields from Beefy vaults:

Emergency Withdraw

The emergencyWithdraw function provides a way to recover funds in case of emergencies:

Usage Examples

Registering a Beefy Vault on Ethereum Mainnet

Registering a Beefy Vault on Polygon

Depositing into Beefy

Withdrawing from Beefy

Harvesting Yield

Security Considerations

Cross-Chain Risks

The multi-chain nature of Beefy Finance introduces additional security considerations:

  1. Bridge Security: The adapter relies on cross-chain bridges for non-native chain operations, which introduces counterparty risk. The adapter implements strict validation to ensure only authorized bridge contracts can call cross-chain callback functions.

  2. Asynchronous Operations: Cross-chain operations are inherently asynchronous, which can lead to temporary inconsistencies in reported balances. The adapter implements proper event emissions to track the status of cross-chain operations.

  3. Chain Outages: If a specific blockchain experiences downtime, funds on that chain may be temporarily inaccessible. The adapter includes emergency functions that can be triggered by governance to recover funds in such scenarios.

Auto-Compounding Strategy Risks

Beefy's auto-compounding strategies may interact with multiple protocols, inheriting risks from each:

  1. Strategy Upgrades: Beefy vaults may upgrade their underlying strategies, potentially changing risk profiles. The adapter includes functions to pause specific vaults if needed.

  2. Reward Token Volatility: Auto-compounding strategies sell reward tokens for the underlying asset, which can be affected by market volatility. The adapter focuses on the underlying token value rather than intermediate reward tokens.

Slippage and MEV Protection

When withdrawing from Beefy vaults, the adapter implements slippage protection to ensure users receive a fair amount of tokens:

  1. Minimum Output Validation: The adapter verifies that withdrawals return at least 95% of the expected amount to protect against extreme slippage.

  2. MEV Protection: The adapter uses direct vault interactions rather than routing through DEXes to minimize MEV extraction opportunities.

Conclusion

The Beefy Finance adapter provides comprehensive integration with Beefy's multi-chain yield optimization platform, allowing the Yieldinator Facet to leverage auto-compounding strategies across multiple blockchains. The adapter's cross-chain capabilities significantly expand the yield opportunities available to users, while its security measures ensure robust protection against the additional risks introduced by multi-chain operations.