Hardhat example: https://github.com/storming0x/ystarter-hardhat-kit
All code in this repository is meant for instructional purposes only. Is not audited or considered safe for production.
-
Basic example Solidity Smart Contracts for integrating with Yearn Vaults. Both V2 and ERC4626 interfaces.
-
ERC4626 adapter to wrap yearn vaults.
-
Example Contracts (
examples
) -
Sample test suite. (
tests
)
VaultWrapper is an ERC4626 adapter interface that makes v2 vaults compatible with the standard. A wrapper is needed per deployed vault. Contracts can interact with the wrapper as they would with any ERC4626 since it adapts the standard completely.
NOTE: This adapter makes all V2 vault operations more gas expensive since its doing additional calls to normal vault methods like deposit/operations to wrap the vault tokens into the ERC4626 adapter.
Given the flexibility, the gas increase tradeoff may be good for integrators using multiple ERC4626 to keep code cohesive for all yield sources.
Also future proofs integrations since V3 vaults will be ERC4626 compatible on launch.
(contracts/examples/SugarVault.sol
)
(contracts/examples/SugarYvault.sol
)
SugarVault is an example contract that works internally with any ERC4626 compatible yield token. SugarYvault has the same functionality but uses Yearn V2 interfaces.
- These contracts accepts donators underlying tokens and deposits it into yield source and configures a receiver.
- The receiver can claim as stream the yield generated by the donator deposits when available.
- The donator can stop yield sharing at any moment and retrieve the underlying token capital deposited plus any unclaimed yields from receiver.
- Tokenized the contract as NFT for donations. Could use two linked NFTs by id, one for donator and one for receiver that can be transfered to claim each part of their funds.
- Add support for migrating yield sources to other ERC4626. Requires same underlying token.
-
To install with Foundry.
-
Fork this repository.
-
Clone your newly created repository recursively to include modules.
git clone --recursive https://github.com/storming0x/ystarter-foundry-kit.git
cd ystarter-foundry-kit
NOTE: if you create from template you may need to run the following command to fetch the git submodules (.gitmodules for exact releases) git submodule init && git submodule update
- Build the project.
make build
-
Sign up for Infura and generate an API key and copy your RPC url. Store it in the
ETH_RPC_URL
environment variable. NOTE: you can use other services. -
Use .env file
-
Make a copy of
.env.example
-
Add the values for
ETH_RPC_URL
,ETHERSCAN_API_KEY
and other example vars NOTE: If you set up a global environment variable, that will take precedence. -
Run tests
make test
To deploy the demo Yearn Vaults and ERC4626 adapter in a development environment:
TODO
Tests run in fork environment, you need to complete Installation and Setup step 6 to be able to run these commands.
make test
Run tests with traces (very useful)
make trace
Run specific test contract (e.g. test/MyTest.t.sol
)
make test-contract contract=MyTest
Run specific test contract with traces (e.g. test/MyTest.t.sol
)
make trace-contract contract=MyTest
See here for some tips on testing Testing Tips