The Badger adapter enables the Yieldinator Facet to integrate with Badger DAO's yield-generating vaults, allowing users to earn yield on Bitcoin-related assets through Badger's Sett vaults and farming strategies.
Overview
Badger DAO is a decentralized autonomous organization focused on bringing Bitcoin to DeFi. The protocol offers Sett vaults (similar to Yearn vaults) that automatically compound yield from various farming strategies for BTC-related assets like WBTC, renBTC, and various tokenized Bitcoin derivatives. The Badger adapter facilitates deposits into these Sett vaults, manages vault positions, and harvests yield including BADGER token rewards.
Implementation Details
Contract: BadgerAdapter.sol
The adapter implements the standard YieldinatorAdapter interface with Badger-specific functionality:
contractBadgerAdapterisYieldinatorAdapter{usingSafeERC20forIERC20;// Badger contractsaddresspublic badgerToken;// BADGER governance tokenaddresspublic bBadgerToken;// Staked BADGER token IBadgerSett public bBadgerSett;// BADGER staking Sett// Vault configurationstructVaultConfig{address sett;// Badger Sett (vault) addressbool stakeBadger;// Whether to stake BADGER rewardsbool active;// Whether the vault is active}// Mapping from token to vault configurationmapping(address=> VaultConfig)public tokenToVault;// Deposited amounts per tokenmapping(address=>uint256)public depositedAmount;// Constructorconstructor(address_admin,address_badgerToken,address_bBadgerToken,address_bBadgerSett ) YieldinatorAdapter("Badger DAO", _admin) {require(_badgerToken !=address(0),"BadgerAdapter: BADGER token cannot be zero address");require(_bBadgerToken !=address(0),"BadgerAdapter: bBADGER token cannot be zero address");require(_bBadgerSett !=address(0),"BadgerAdapter: bBADGER Sett cannot be zero address"); badgerToken = _badgerToken; bBadgerToken = _bBadgerToken; bBadgerSett =IBadgerSett(_bBadgerSett);}}
Key Functions
Vault Registration
Before using the adapter for a specific token, the Sett vault must be registered:
Deposit
The deposit function handles depositing assets into Badger Sett vaults:
Withdraw
The withdraw function handles withdrawing assets from Badger Sett vaults:
Harvest Yield
The harvestYield function collects BADGER rewards and optionally stakes them:
Emergency Withdraw
The emergencyWithdraw function provides a safety mechanism to withdraw all funds:
APY Calculation
The getCurrentAPY function calculates the current APY for a token in the Badger Sett:
Get Total Deposited
The getTotalDeposited function returns the total amount of tokens deposited:
Usage Example
Here's an example of how to use the Badger adapter with the Yieldinator Facet:
Security Considerations
Strategy Risk: Badger Sett vaults employ complex yield farming strategies that may expose users to additional risks from the underlying protocols.
Smart Contract Risk: The adapter interacts with multiple external contracts which may have vulnerabilities.
Impermanent Loss: Some Badger strategies involve providing liquidity to AMMs, which can lead to impermanent loss.
Reward Distribution: Badger's reward distribution mechanisms may change over time, affecting yield calculations.
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.
Integration with Badger's risk assessment framework to evaluate strategy risks.
Gas Optimization
The adapter minimizes gas usage by batching operations when possible.
For harvesting rewards, users can choose whether to stake BADGER rewards based on gas costs and expected returns.
The adapter avoids unnecessary approvals by only approving tokens when needed.
Future Improvements
Support for Badger's governance system for participating in protocol decisions
Integration with Badger's Digg rebasing token strategies
Support for Badger's cross-chain vaults as they become available
Automated reinvestment of harvested rewards for maximum yield
Integration with Badger's ibBTC (interest-bearing BTC) product