This repository contains the base code for the Yearn V3 "Tokenized Strategy" implementation. The V3 strategy implementation utilizes an immutable proxy pattern to allow anyone to easily create their own single strategy 4626 vault. All Tokenized Strategies will use the logic held within the TokenizedStrategy
for their redundant and high risk code. The implementation holds all ERC-20, ERC-4626, profit locking and reporting functionality to make any strategy that uses it a fully permissionless vault without holding any of this logic itself.
The implementation address that calls are delegated to is pre-set to a constant and can never be changed post deployment. The implementation contract itself is ownerless and can never be updated in any way.
NOTE: The master branch has these pre-set addresses set based on the deterministic address that testing on a local device will render. These contracts should NOT be used in production and any live versions should use an official release.
A Strategy contract can become a fully ERC-4626 compliant vault by inheriting the BaseStrategy
contract, that uses the fallback function to delegateCall the previously deployed version of TokenizedStrategy
. A strategist then only needs to override three simple functions in their specific strategy.
TokenizedStrategy - The implementation contract that holds all logic for every strategy.
BaseStrategy - Abstract contract to inherit that communicates with the TokenizedStrategy
.
Full tech spech can be found here
-
First you will need to install Foundry. NOTE: If you are on a windows machine it is recommended to use WSL
-
Fork this repository (easier) or create a new repository using it as template. Create from template
-
Clone your newly created repository recursively to include modules.
git clone --recursive https://github.com/myuser/tokenized-strategy
cd tokenized-strategy
NOTE: if you create from template you may need to run the following command to fetch the git sub modules (.gitmodules for exact releases) git submodule init && git submodule update
- Build the project.
make build
To print the size of each contract
make size
- Run tests NOTE: Tests will take a significant period of time since the fuzzer is set to 10,000 runs.
make test
Run all tests run on a local chain
make test
Run all tests with traces (very useful)
make trace
Run all tests with gas outputs
make gas
Run specific test contract with traces (e.g. test/StrategyOperation.t.sol
)
make trace-contract contract=StrategyOperationsTest
Run specific test with traces (e.g. test/StrategyOperation.t.sol::testStrategy
)
make trace-test test=testStrategy
See here for some tips on testing Testing Tips
To print out the storage layout of any contract (e.g 'test/MockStrategy.sol')
make inspect contract=MockStrategy
Deployments of the TokenizedStrategy are done using create2 to be at a deterministic address on any EVM chain.
Check the docs for the most updated deployment address.
Deployments on new chains can be done permissionlessly by anyone using the included script. First follow the steps to deploy the vault factory from the Vaults V3 repo.
You can then deploy the TokenizedStrategy using the provided script.
forge script script/Deploy.s.sol:Deploy --account ACCOUNT_NAME --rpc-url YOUR_RPC_URL --broadcast
If the deployments do not end at the same address you can also manually send the calldata used in the previous deployments on other chains.