Skip to content

samuelpeter/ystarter-hardhat-kit

 
 

Repository files navigation

Yearn Hardhat Starter Kit

All code in this repository is meant for instructional purposes only. Is not audited or considered safe for production.

This repository is fa hardhat fork of storming0x ystarter-foundry-kit you can find it here

What you'll find here

  • 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)

Yearn Vault -> ERC4626 Adapter

(contracts/VaultWrapper.sol)

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.

Contract Example that works with compatible ERC4626 tokens and Yearn V2 VaultsAPI

(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.

Example functionality

  • 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.

Possible Features to hack

  • 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.

Hardhat Configuration

  • typescript support enabled
  • typechain plugin installed (typescript type bindings are generated from smart contracts)/check Typechain docs
  • hardhat-deploy plugin enabled (use deployments from deploy folder, order and tag them; multi-network)
  • hardhat console enabled - to allow console.log usage within solidity code
  • testing environment configured and operational

Installation and Setup

  1. Fork this repository.

  2. Clone your newly created repository recursively to include modules.

git clone --recursive https://github.com/AlexNi245/ystarter-hardhat-kit

cd ystarter-hardhat-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

  1. Install Dependencies

yarn install

  1. Sign up for Infura and generate an API key and copy your RPC url. Store it in the RINKEBY_RPC_URL environment variable. NOTE: you can use other services.

  2. Use .env file

  3. Make a copy of .env.example

  4. Add the values for RINKEBY_RPC_URL and other example vars NOTE: If you set up a global environment variable, that will take precedence.

  5. Run tests yarn test

Usage

Run yarn install and then:

  • hh compile - to compile smart contract and generate typechain ts bindings
  • hh test - to run tests
  • hh deploy - to deploy to local network (see options for more)
  • hh TABTAB - to use autocomplete
  • hh node - to run a localhost node

Check package.json scripts for more options. Use .env.example file and adapt it to you values and settings.

Testing

Tests run in fork environment, you need to complete Installation and Setup step 6 to be able to run these commands.

yarn test

Resources

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Solidity 69.7%
  • TypeScript 30.2%
  • Shell 0.1%