Giter Club home page Giter Club logo

foundry_strategy_mix's Introduction

Yearn Strategy Foundry Mix

What you'll find here

  • Basic Solidity Smart Contract for creating your own Yearn Strategy (Strategy.sol)

  • Configured github template with Foundry framework for starting your yearn strategy project.

  • Sample test suite. (tests)

How does it work for the User

Let's say Alice holds 100 DAI and wants to start earning yield % on them.

For this Alice needs to DAI.approve(vault.address, 100).

Then Alice will call Vault.deposit(100).

Vault will then transfer 100 DAI from Alice to itself, and mint Alice the corresponding shares.

Alice can then redeem those shares using Vault.withdrawAll() for the corresponding DAI balance (exchanged at Vault.pricePerShare()).

Installation and Setup

  1. To install with Foundry.

  2. Fork this repository (easier) or create a new repository using it as template. Create from template

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

git clone --recursive https://github.com/myuser/foundry-yearn-strategy

cd foundry-yearn-strategy

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. Build the project.
make build
  1. 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.

  2. Use .env file

  3. Make a copy of .env.example

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

  5. Run tests

NOTE: tests run in fork environment, you need to setup step 6 to be able to run these commands.

make test

Run tests with traces (very useful)

make trace

Basic Use

To deploy the demo Yearn Strategy in a development environment:

TODO

Implementing Strategy Logic

contracts/Strategy.sol is where you implement your own logic for your strategy. In particular:

  • Create a descriptive name for your strategy via Strategy.name().
  • Invest your want tokens via Strategy.adjustPosition().
  • Take profits and report losses via Strategy.prepareReturn().
  • Unwind enough of your position to payback withdrawals via Strategy.liquidatePosition().
  • Unwind all of your positions via Strategy.exitPosition().
  • Fill in a way to estimate the total want tokens managed by the strategy via Strategy.estimatedTotalAssets().
  • Migrate all the positions managed by your strategy via Strategy.prepareMigration().
  • Make a list of all position tokens that should be protected against movements via Strategy.protectedTokens().

Testing

To run the tests:

make test

to run tests with traces (using console.sol):

make trace

Resources

foundry_strategy_mix's People

Contributors

anticlimactic avatar storming0x avatar charlesndalton avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.