The Hive and Flower contracts form a modular framework for managing and interacting with tokenized assets and yield-bearing protocols.
Hive acts as a central vault and management hub. It inherits from ERC4626
, a standard for tokenized vaults, and Owned
, indicating that it has an owner (aka "Queen") with administrative rights. The primary function of the Hive is to manage deposits and withdrawals from users (aka "Beekeepers") of an ERC20 asset (referred to as "Bees") and to interact with various Flowers, which are external yield-generating protocols or contracts.
-
Token Management: Hive allows for the deposit and redemption of tokens, converting them into shares and managing the total assets within the vault.
-
Flower Integration: Hive manages a list of approved Flowers, which are "bridges" to yield-bearing protocols. These Flowers are added or removed by the owner of the Hive.
-
Pollination: The
pollinate
function enables users to transfer their tokens from the Hive to a Flower, effectively staking their assets to generate yield. -
Harvesting: The
harvest
function allows users to collect the yield generated by the Flowers. This involves interacting with the Flower (via the Hive) to reclaim the staked assets and any accrued rewards, which are then deposited back into the Hive for the user. -
Security: The Hive includes a modifier,
onlyFlower
, ensuring that only authorized Flowers can interact with specific functions, adding a layer of security to prevent unauthorized access.
Flower is an abstract contract designed to be inherited by contracts that exposed yield-generating protocols. It is linked to a Hive and manages interactions with these protocols to generate returns on the assets provided by the Hive.
-
Protocol Interface: Flower provides an interface for specific protocols, like
Synthetix
, to handle the deposited tokens and manage yield generation. -
Pollination and Harvesting: The
pollinate
function handles the initial staking or provision of assets into the yield-generating protocol. Theharvest
function manages the collection of yields, ensuring that the accrued rewards are returned to the Hive. -
Account Management: In the context of protocols like
Synthetix
, Flower manages account creation and collateral delegation to ensure that the assets are efficiently staked and yield is maximized. -
Rewards Management: Some Flowers, like the
Synthetix Flower
, include functionality for harvesting rewards without concluding the staking period, allowing for continuous yield generation and reward collection. -
Compatibility and Flexibility: Flower is designed to be flexible, allowing integration with various protocols and adapting to changes within these protocols.
Overall, the Hive and Flower framework provides a structured and secure way to manage and grow assets through interactions with various DeFi protocols, allowing users to deposit, stake, and harvest their tokens seamlessly.
See script/Deploy.s.sol
for an example of how to deploy the Hive and Flower contracts using Foundry.
Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
Foundry consists of:
- Forge: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- Cast: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
- Anvil: Local Ethereum node, akin to Ganache, Hardhat Network.
- Chisel: Fast, utilitarian, and verbose solidity REPL.
$ forge build
$ forge test
$ forge test --match-test TEST_NAME
$ forge fmt
$ forge snapshot