This repo will allow you to write, test and deploy V3 "Tokenized Strategies" using Foundry.
You will only need to override the three functions in Strategy.sol of _deployFunds
, _freeFunds
and _harvestAndReport
. With the option to also override _tend
, _tendTrigger
, availableDepositLimit
, availableWithdrawLimit
and _emergencyWithdraw
if desired.
For a more complete overview of how the Tokenized Strategies work please visit the TokenizedStrategy Repo.
- First you will need to install Foundry. NOTE: If you are on a windows machine it is recommended to use WSL
- Install Node.js
git clone --recursive https://github.com/yearn/tokenized-strategy-foundry-mix
cd tokenized-strategy-foundry-mix
yarn
Use the .env.example
template to create a .env
file and store the environement variables. You will need to populate the RPC_URL
for the desired network(s). RPC url can be obtained from various providers, including Ankr (no sign-up required) and Infura.
Use .env file
- Make a copy of
.env.example
- Add the value for
ETH_RPC_URL
and other example vars NOTE: If you set up a global environment variable, that will take precedence.
make build
Run tests
make test
For a complete guide to creating a Tokenized Strategy please visit: https://docs.yearn.fi/developers/v3/strategy_writing_guide
Due to the nature of the BaseStrategy utilizing an external contract for the majority of its logic, the default interface for any tokenized strategy will not allow proper testing of all functions. Testing of your Strategy should utilize the pre-built IStrategyInterface to cast any deployed strategy through for testing, as seen in the Setup example. You can add any external functions that you add for your specific strategy to this interface to be able to test all functions with one variable.
Example:
Strategy _strategy = new Strategy(asset, name);
IStrategyInterface strategy = IStrategyInterface(address(_strategy));
Due to the permissionless nature of the tokenized Strategies, all tests are written without integration with any meta vault funding it. While those tests can be added, all V3 vaults utilize the ERC-4626 standard for deposit/withdraw and accounting, so they can be plugged in easily to any number of different vaults with the same asset.
Tests run in fork environment, you need to complete the full installation and setup to be able to run these commands.
make test
Run tests with traces (very useful)
make trace
Run specific test contract (e.g. test/StrategyOperation.t.sol
)
make test-contract contract=StrategyOperationsTest
Run specific test contract with traces (e.g. test/StrategyOperation.t.sol
)
make trace-contract contract=StrategyOperationsTest
See here for some tips on testing Testing Tips
When testing on chains other than mainnet you will need to make sure a valid CHAIN_RPC_URL
for that chain is set in your .env. You will then need to simply adjust the variable that RPC_URL is set to in the Makefile to match your chain.
To update to a new API version of the TokenizeStrategy you will need to simply remove and reinstall the dependency.
Once the Strategy is fully deployed and verified, you will need to verify the TokenizedStrategy functions. To do this, navigate to the /#code page on Etherscan.
- Click on the
More Options
drop-down menu - Click "is this a proxy?"
- Click the "Verify" button
- Click "Save"
This should add all of the external TokenizedStrategy
functions to the contract interface on Etherscan.
This repo uses GitHub Actions for CI. There are three workflows: lint, test and slither for static analysis.
To enable test workflow you need to add the ETH_RPC_URL
secret to your repo. For more info see GitHub Actions docs.
If the slither finds some issues that you want to suppress, before the issue add comment: //slither-disable-next-line DETECTOR_NAME
. For more info about detectors see Slither docs.