BeefyWrapper Contract
Last Update: July 2024
The BeefyWrapper contract is an ERC-4626 adapter interface that makes a Beefy Vault Contract compatible with the ERC-4626 standard. It unlocks the composability of the standard and enables smoother interfacing and interaction with Beefy Vaults by external protocols, without the need for additional adapters and plug-ins.
This page sets out some of the background to the ERC-4626 standard, and the functionality of the BeefyWrapper contract.
Why ERC-4626?
The purpose of the ERC-4626 standard is to solve the problems caused by the diversity of vault designs found across DeFi. Many protocols have incorporated vault concepts into their architecture by reinventing the wheel to suit their own unique architecture and use cases. This means external projects hoping to implement a range of different vaults need to adapt and plug their code to reconcile it with the quirks of each protocol's unique vault design.
The new standard recognises some common functions across the majority of vaults, and suggests that harmonising this functionality into a single standard can help to mitigate the quantity of adaptations and plug-ins required to work with most vaults. For protocols like Beefy, adopting ERC-4626 for our Beefy Vaults helps to facilitate new product development building on our products, and as a result promises to increase the range of use cases available to our users.
Contract Functions
The functionality of the BeefyWrapper contract facilitates the minting and burning of wrapped Beefy Vault tokens in exchange for the transfer of the caller's Beefy Vault tokens. It also overrides the standard deposit and withdraw functions to facilitate deposits to the main Beefy Vault, in exchange for minting and burning of the wrapped Beefy Vault tokens.
wrap()
Transfers the specified amount of the caller's Beefy Vault tokens to the wrapper contract to mint the same quantity of wrapped Beefy Vault tokens to the caller.
wrapAll()
Utilises the wrap() function, but using the full balance of the caller as the "amount" parameter.
unwrap()
Burns the specified amount of the caller's wrapped Beefy Vault tokens, to transfer the same quantity of unwrapped tokens from the wrapper contract back to the caller.
unwrapAll()
Utilises the unwrap() function, but using the full balance of the caller as the "amount" parameter.
_deposit()
Overrides the standard _deposit() function to interact with the wrapper contract and issued wrapped Beefy Vault tokens, in place of the unwrapped version. Otherwise facilitates an ordinary transfer into the Beefy Vault.
_withdraw()
Overrides the standard _withdraw() function to interact with the wrapped Beefy Vault tokens, in place of the unwrapped version. Otherwise facilitates an ordinary withdrawal from the Beefy Vault and returns the underlying tokens to the receiver.
totalAssets()
Overrides the standard totalAssets() function to fetch the total assets held by the vault.
totalSupply()
Overrides the standard totalSupply() function to fetch the total shares issues by the vault.
BeefyWrapperFactory Contract
The BeefyWrapperFactory contract is a factory contract which provides a minimal proxy pattern for use in creating new Beefy Vault wrappers. A factory contract allows users to generate and deploy their own proxy contracts that all point to the same implementation contract, where the logic resides.
Through the BeefyWrapperFactory, BeefyWrapper contracts can be deployed for any vaults. The factory contract has only one key function - clone().
clone()
Uses the OpenZeppelin standard proxy template ClonesUpgradeable.sol to create a proxy contract which is a clone of the BeefyWrapper contract.
Contracts
The template Beefy Vault wrapper contracts are publicly maintained in Beefy's GitHub repositories. See BeefyWrapper.sol and BeefyWrapperFactory.sol.
BeefyWrapperFactory.sol contracts for each Beefy Vault have been deployed separately on the relevant chains at the following addresses:
Last updated