Video Introduction: https://youtu.be/FVbhgPYW_D0
Example Project: https://github.com/Badger-Finance/wBTC-AAVE-Rewards-Farm-Badger-V1-Strategy
Full Project Walkthrough: https://www.youtube.com/watch?v=lTb0RFJJx2k
1-1 Mentoring (Valid throughout HackMoney and Gitcoin Round 10): https://calendly.com/alex-entreprenerd/badger-hackmoney-1-1
Basic Solidity Smart Contract for creating your own Badger Strategy (contracts/StrategyConvexStakingOptimizer.sol
)
Interfaces for some of the most used DeFi protocols on ethereum mainnet. (interfaces
)
Dependencies for OpenZeppelin and other libraries. (deps
)
Sample test suite that runs on mainnet fork. (tests
)
This mix is configured for use with Ganache on a forked mainnet.
Use this code by clicking on Use This Template
Download the code with git clone URL_FROM_GITHUB
Install Brownie & Ganache-CLI, if you haven't already.
Copy the .env.example
file, and rename it to .env
Sign up for Alchemy and generate an API key. Store it in the ALCHEMYAPI_TOKEN
environment variable.
Sign up for Etherscan and generate an API key. This is required for fetching source codes of the mainnet contracts we will be interacting with. Store the API key in the ETHERSCAN_TOKEN
environment variable.
Install the dependencies in the package
## Javascript dependencies
npm i
## Python Dependencies
pip install virtualenv
virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
To deploy the demo Badger Strategy in a development environment:
brownie console
brownie run scripts/1_production_deploy.py
Deployment will set up a Vault, Controller and deploy your strategy
To ship a valid strategy, that will be evaluated to deploy on mainnet, with potentially $100M + in TVL, you need to:
/config/__init__.py
/config/StrategyResolver.py
so that snapshot testing can verify that operations happened correctlyMost strategies have a:
Set these up in /config/__init__.py
this mix will automatically be set up for testing and deploying after you do so
contracts/StrategyConvexStakingOptimizer.sol
is where you implement your own logic for your strategy. In particular:
initialize
MethodStrategyConvexStakingOptimizer.getName()
StrategyConvexStakingOptimizer.version()
StrategyConvexStakingOptimizer.balanceOfPool()
StrategyConvexStakingOptimizer.isTendable()
StrategyConvexStakingOptimizer.version()
Strategy._deposit()
.Strategy.harvest()
.Strategy._withdrawSome()
.Strategy._withdrawAll()
.Strategy.tend()
.Strategy.protectedTokens()
.In order to snapshot certain balances, we use the Snapshot manager. This class helps with verifying that ordinary procedures (deposit, withdraw, harvest), happened correctly.
See /helpers/StrategyCoreResolver.py
for the base resolver that all strategies use
Edit /config/StrategyResolver.py
to specify and verify how an ordinary harvest should behave
get_strategy_destinations
(e.g. deposit pool, gauge, lpTokens)confirm_harvest
to verify that the harvest was profitableconfirm_tend
to verify that tending will properly rebalance the strategyearn
by setting up hook_after_confirm_withdraw
, hook_after_confirm_deposit
, hook_after_earn
Check the various tests under /tests
The file /tests/test_custom
is already set up for you to write custom tests there
See example tests in /tests/examples
All of the tests need to pass!
If a test doesn't pass, you better have a great reason for it!
To run the tests:
brownie test
Use the --interactive
flag to open a console immediatly after each failing test:
brownie test --interactive
Within the console, transaction data is available in the history
container:
>>> history
[<Transaction '0x50f41e2a3c3f44e5d57ae294a8f872f7b97de0cb79b2a4f43cf9f2b6bac61fb4'>,
<Transaction '0xb05a87885790b579982983e7079d811c1e269b2c678d99ecb0a3a5104a666138'>]
Examine the TransactionReceipt
for the failed test to determine what went wrong. For example, to view a traceback:
>>> tx = history[-1]
>>> tx.traceback()
To view a tree map of how the transaction executed:
>>> tx.call_trace()
See the Brownie documentation for more detailed information on debugging failed transactions.
When you are finished testing and ready to deploy to the mainnet:
scripts/production_deploy.py
with the following command:$ brownie run scripts/production_deploy.py --network mainnet
You will be prompted to enter your desired deployer account and keystore password, and then the contracts will be deployed.
When you are done testing your contracts in production and they are ready for incorporation to the Badger ecosystem, the production_setup
script can be ran to ensure that all parameters are set in compliance to Badger's production entities and contracts. You can run this script by doing the following:
scripts/production_setup.py
file and change the addresses for your strategy and vault mainnet addresses on lines 29 and 30.governance
for your contracts.scripts/production_setup.py
with the following command:$ brownie run scripts/production_setup.py --network mainnet
You will be prompted to enter your governance account and keystore password, and then the the parameter verification and setup process will be executed.
If you are using Ganache to fork a network, then you may have issues with the blockchain archive state every 30 minutes. This is due to your node provider (i.e. Infura) only allowing free users access to 30 minutes of archive state. To solve this, upgrade to a paid plan, or simply restart your ganache instance and redploy your contracts.