Blueberryfi / blueberry-core

MIT License
7 stars 5 forks source link

blueberry-core v1

Protocol Summary

Blueberry Core v1 is a leveraged yield-farming product. Additional documentation can be found here. Here are some key features:

The protocol is integrated with an existing lending protocol (Blueberry Money Market). Whenever a user wants to borrow funds (on leverage) to yield farm additionally, Blueberry Bank will borrow from the lending protocol (Blueberry Money Market).

Protocol Components

Component Interaction Flow

  1. User -> BlueberryBank. User calls execute to BlueberryBank, specifying which spell and function to use, e.g. `_deposit using IchiSpell.
  2. BlueberryBank -> Spell
  3. Spell may call BlueberryBank to e.g. _doBorrow funds and _doRepay debt. Funders are then sent to Spell. to execute pool interaction.
  4. Spells -> Pools
    Spells interact with Pools (e.g. optimally swap before supplying to Uniswap, or remove liquidity from the pool and pay back some debts).
  5. (Optional) Stake LP tokens in wrapper contracts (e.g. WStakingRewards for Uniswap + Balancer).
  6. Spell may put collateral back to BlueberryBank. If the spell function called is e.g. to open a new position, then the LP tokens will be stored in BlueberryBank.

Example Execution

putCollateral

  1. User calls execute(0, USDT, WETH, data) on BlueberryBank contract. data encodes IchiSpell function call with arguments (including how much of each asset to supply, to borrow, and slippage control settings).
  2. BlueberryBank uses data calls to encode putCollateral function call with arguments to IchiSpell.
  3. IchiSpell executes putCollateralWERC20
    • _doBorrow from the lending protocol
    • Deposit a Single asset into the ICHI vault and receive LP Token
    • Wrap LP tokens to wrapper WERC20 (to get ERC 1155)
    • _doPutCollateral wrapped tokens back to BlueberryBank
    • Refund leftover assets to the user.

Oracle

Prices are determined in USD.

Getting Started

Steps to run the tests: Hardhat version 2.12.4 Block height 17089048 Eth mainnet fork

Copy all the files

Clone the repo

Installs all of the files

yarn install

Required for tests and all other actions to work

Create .env file with env var DEPLOY_ACCOUNT_KEY= , ETHERSCAN_API_KEY=

If needed update the RPC provider in hardhat.config.js and /test/helpers/index.js to your own provider. Currently set to ankr mainnet node.

Compiles all of the contracts

yarn hardhat compile

Runs all of the tests

yarn hardhat test

Displays the coverage of the contracts

yarn hardhat coverage

Runs the foundry tests

forge test