Kish
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # How to Become a Mighty Strategist <iframe width="560" height="315" src="https://www.youtube.com/embed/6og7NV7lzUk" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> ``` *Authors note: This is a transcription of a talk given by Facu Ameal at Eth Denver 2022* ![](https://i.imgur.com/P9fnIbE.jpg) **What’s a Strategist?** Hello, everyone. I'm Facu from Yearn Finance. I'm pumped to be here and to be doing this workshop. This is going to be a high-level overview on how to create a new investment strategy for Yearn. And then afterwards we'll share a code so you can join office hours. Let's start from the beginning. What's a strategist? A strategist is just a big-brain guy or girl or whatever. We don't care. We encourage the anonymous community actually, you don't need to be a hardcore developer or anything. You need to understand how things work, how things connect. That's the most important thing. Programing and languages, you can learn them. That's not a problem at all. **Vaults and Strategies? What’s that?** ![](https://i.imgur.com/pPxVD6V.jpg) So let's see what's a vault? A vault is just a container of tokens, like a piggy bank where you drop your tokens and those tokens are taken by the strategies. Those are the ones that are going to be doing all the heavy lifting of the strategy. Those vaults are going to send the funds to the strategy which is going to invest those funds. It's going to collect the rewards and recycle them into the same token, compounding your investment. All the vaults run multiple strategies. That's an important thing to take into account because with $500 million you cannot deploy them all on the same place. And we're also Keep3rs integrated. We decided to do the strategies in Solidity because you're able to inherit from other contracts, and that's important because you are going to see all the interactions between the strategy and the vault are already coded. So it's super simple to create a new strategy.They manage the accounting and invest, univest and recycle the rewards into "want token". Also, they take care of harvest, they check the slippage and they keep the collateral ratio healthy. That's to say you can manage a CDP position. A collateralized position using a strategy per vault. And it's perfectly safe. So it's safer to do it this way than a user doing it manually. Let's take a look at how it looks, a vault today. This is the yvUSDC. And as you can see, has lot of strategies, important things to take into account. All of them have different percentages. The strategist is the one who runs simulations and those simulations are the ones we decide how much percentage of capital all those strategies are going to get. ![](https://i.imgur.com/6iNtXOB.jpg) It's always different because it changes depending on the status of the underlying protocol. And the other important thing to take into account is that we have strategies with 0% capital allocation. They are ready to run, but right now they might not be profitable, its not the right moment to enable them. **How do Vaults and Strategies interact?** For me, the most important part, is to call the strategy. It's understanding how this whole system works. It has five parts, the keepers, which are the the the centralized bot network, they're going to run the harvest. The harvest is the function that collects and recycles the rewards. The vault, the strategy, the identify protocol. It can be any DEFI protocol, AAVE, Compound, whatever. An index, to exchange the tokens that you receive as rewards for the "want token", the token that the user deposited. So the keeper is going to be monitoring a view function that's called the harvestTrigger. When it becomes true, it's going to execute the harvest function that harvestTrigger is important because we want to collect the rewards and recycle them when it's profitable to do so because in Ethereum gas costs are high. So we have to take that into account. When it happens, what the strategy has to do is to claim the rewards and swap them. That's it. It's going to receive the "want token" is going to send the report to the vault because the strategy has to inform the vault what's going on with the underlying protocol to change the price per share. It's going to adjust the credit available. And this is an important concept. The strategies are taking a loan. So we call it debt. The strategy has a debt with a vault that is got to return at some point. OK, that's just conceptual. Then it's going to adjust position, we're going to see what that does afterwards and send a success to the keeper and that's it. Well, this is just like high level overview, let's see how how the process looks like. I'm going to do like a fast run through the non-technical parts and we're going to see more in depth the technical parts of the process. **What do I need to write a Strategy?** OK, first, what do you need? Basic stuff. Git, eth-brownie, ganache. It's what we use, the brownie mix repository. This is actually a template that you can use and has a lot of work already done. On VS code, when I wrote my strategy, I had some programing experience. I only did cryptozombies on base level four, that was my solidity knowledge, pretty basic. So anyone can do it. I understood how things interacted at the vault and strategy level and I used a ton of willpower because you need to spend some time coding and then reviewing especially. **Let’s write a Strategy** ![](https://i.imgur.com/GbASzKQ.jpg) Well, let's go for it. This is our process. We're super security oriented. So for us it's super important to actually test in test, and then test in prod. Both things are important. So we have a due diligence part with the strategy, you have to do an investigation of the underlying protocol and present a report so the security analysts can check it out and validate that everything is perfectly safe. It's like a mini-audit. Then you're going to code your strategy. Then it's going to go through a peer review, because we all know that audits take time and a lot of money. And then you go to an experimental website we have, that's the part we test in prod, then the core devs are going to review it. Safe Farming Committee is going to review again, do its due diligence and it's going to give the green light to go to production. **Due Diligence** Let's go step by step. This is the due diligence process. You can check, I will just say some highlights about it, like the rug-ability section that it's not about the code, but about who is governing those contracts. That's super important because when you check it, you see multisigs. So we tell the protocols, "hey, we need this to be changed", and they usually accept it and they're very, very glad to do it, so these are the things that we check before starting to code a strategy, it's nonsense to start coding a strategy, using an on-site protocol. Prepare your environment Basic stuff to start coding. First, the tools needed. You're going to eth-brownie and ganache. You've got use the brownie-strategy-mix template and clone your repo. That's basic stuff, super simple. ![](https://i.imgur.com/r4nfTAp.jpg) Well, where do you have to take a look, strategy.sol, is where all of the work is going to be done or a big part of it because tests are also important. Most of the stuff in the directions we already have package them and it's in the baseStrategy.sol so you don't have to take care of it, you only have to code the custom interactions with the protocol that you're going to farm. **Strategy.sol** Let's take a look at the three functions that you have to code. If you code these three functions, the strategy is going to work. You may need more to implement your custom protocol, but these are the three functions that you need. adjustPosition, is just going to invest the funds. So if it's a staking protocol, it's going to stake those funds. That's it. That funding parameter, it's how much it has to invest. liquidatePosition is going to do the reverse, its going to withdraw from the underlying protocol, or to liquidate the position if it's an LP or whatever. prepareReturn, thats where the heavy lifting happens. That's where you have to pay more attention and that where you have to calculate profit, losses and also free up assets when the vaults need to withdraw, because the principle is that every user has to be able to withdraw at any time, at any point in time. /Tests, test, test, test! That's super important for us because we cannot test in testnet, we need the protocol to be light. So you need to write tests, this is the repository, the brownie mix. We already have some basic tests all ready for you, so that you can use them. But this is a production strategy, it looks very different, so you have to spend a lot of time testing because it's going to be useful to not have any issues when you have real money in the vault. Well, this is almost the last step. Two peers, two strategists have to review your strategy. Then you have to choose a name, this is the fun part. Choose a name and two emojis and go to experimental. This is a real vault that was an experimental some time ago. This is the part that we test in prod but we have a deposit limit just in case. **Safe Farming Committee + Core Team Review** Part of the procedure, I'm going to go fast over this, is the Safe Farming Committee. It's a committee of people that is assessing if the strategy is ready to go to production or not, is going to take into account the due diligence and also if the peer reviews and everything has been done. The core team review, it's reviewed by our security specialists. ![](https://i.imgur.com/34HzU2p.jpg) They do an in-depth review of the strategy or what we do to do the process faster, if you're ready to review the protocol and it's a fork, we check the differences. We do a diff check. OK, you made it, you did the strategy and it's in production... but it's not done. Strategies need maintenance and monitoring. ![](https://i.imgur.com/KS0Slfz.jpg) **Stay and help manage the strategy** We monitor the harvest, we monitor debt ratio, the APR and especially the state of the underlying protocol because if something changes, the strategy needs to adapt or we need to adapt it. So it's super important to stay and monitor. That's all guys, and since the workshop is short, we're going to hold office hours in half an hour, this is our telegram group [QR code] for new strategies. So if you scan it, you are going to join what we call the boarding school. The strategists are always there answering questions. So if you are building something and you have questions, that's the best place to do it , like 24/7. If you have any questions you can ask now also and then we can continue online. OK, one more thing I love POAPs, so if you came here, you can click that POAP, it's a really nice one. It's the first event that Yearn is sponsoring, so for us, it's a special one. So claim it. So have a nice one, thank you!

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully