Yearn Workshop: Coding Yearn DeFi Strategies with HardHat with GTON team

ETHDubai 2022 · 30 Mar 2022 · 2:35:51

This workshop explains Yearn vaults, Curve-based yield strategies, compounding, keeper automation, and the strategy lifecycle. The instructor demonstrates JavaScript tests, account switching, and mock contracts in Hardhat, then sketches how staking operations map to Yearn strategy methods.

Speakers

Topics

From ETHDubai 2022, hosted by DeFi Dubai.

Transcript

my life hi guys can you hear me go cool thank you okay sorry for some delay please put your hands up who already familiar with the g5 strategies young strategies or implemented one okay

not so many but but a few right so you guys will help us to understand what's going on and uh we'll ask questions anyway yes let's start so uh those who can do those who can't teach you know this uh it's a bernard show and uh i'm alex i'm developer and dao labor in uh several daos jiton capital dao and lobster dao you probably know about lobster chat with the defy researchers so this is a link to my twitter and uh i can't build the file and strategies yet so let's learn how to build device strategies today the workshop will have three parts uh with two breaks for 20 minutes uh first

part will be about defy strategies in general uh yarn finance goals and different examples here we'll work together in terms of like what kind of strategies we can build the part 2 will be hard hat who is familiar with hardhat so ok the health is familiar so another half it will be helpful for you to uh to use it it's a very powerful framework and tool for uh for smart contract development and especially test driven development because they have good integration with the test test frameworks environments and the part three will be mocking our strategies with solidity and so what we need for the workshop

especially for the uh part two and part three laptop node.js and tension engagement so let's start what is defy strategy who knows who can explain like simple explanation yeah you can you can explain okay good it's actually a good definition so basically defy strategies can be considered as a flow and uh with this flow we always have some like initial point where user interacting

with the uh with the smart contracts uh with funds uh such smart contracts they called volt so we'll consider volts and the basic interface of volts and the user is interacting with volts so basically volts is also keeping the the funds from the user and somehow manage it this divorce is uh communicating with the strategy so strategy is uh basically the the controller which is trying to maximize yield and do some kind of automation uh working with the user funds right so it's basically like um another another component of the of the um

of the flow and uh to automate some some operations because you know there is no uh auto triggers within the smart contracts blockchain is a closed system we need keeper oracles so keeper oracles they are mostly doing automation those are external external operators external machines which are triggering smart contracts to execute some operations right and uh we'll consider some examples later and uh the most important part for the for the default strategies is is basically dub sold up i mean like something which is generating money and you can you can see here uh we have money from the thin air uh basically this is how uh d5 works most often uh

the strategies around around g5 they are somehow connected with the with the inflation uh of course it's a money from the sorry uh of course it's the money from the thin air because there is inflation but uh it's just you know joke here because sometimes uh the money can be generated from the uh from the uh trading activity from the borrowing lending and and stuff but anyway um we can call it uh veneer so basically uh strategy is integra is communicating with the dub and then uh the profit the money is going to the uh to the user then uh he is um by drawing the funds right so basically uh this is

the all defy strategies can be uh can be explained by this framework so the the three main components here and uh who knows what is curve finance uh yeah so i will talk about many different types of strategies but still young finance is mostly using the curve as a main source of of uh dub with the muni right so uh this this is basically um a curve at the moment and the curve uh is an imm like an automated market maker uh where you can exchange uh semi-packed assets same effect can be a stable coins or synthetic assets or wrapped assets with

a peg to the same value like bitcoin ethereum or whatever and uh we have pools where uh both assets are uh can be can be exchanged to each other and the the curve formula is good for uh semi-packed assets why just because it's not parabolic there is no parabolic bonding curve it means that uh the slippage for exchanging semi-peg assets is is pretty low and there is a a parameter if you're increasing it uh the the slope is going to you know flood until uh rockpool because if there will be a huge imbalance between both tokens there will be a huge

imbalance in terms of price so uh curve is basically an exchange so people they can provide some liquidity in stable coins and they can write really liquidity in in some proportion depends on how many uh token a for example usdt and udc within the pool and before uh before the token of the curve curve has its own governance token which is crv uh before that it was just an exchange where people you know exchanged uh exchange stable coin to to um to each other but after some time they they created the governance token which is crv and the government's talking is

incentivizing people to provide more and more liquidity in that pools so basically before the the sierra token the whole the whole like the whole incentive to provide liquidity on curve was uh trading rewards like you know you have uh you have taxation for any trade operation and if you're a liquidity provider if you are putting the liquidity into uh in the curve you can be rewarded in in that after crv uh some pools they have uh they have some emission which is designated to specific pools and uh and uh it is much more popular uh way to incentivize people to you know to provide liquidity and uh the question here is uh the device strategy with

curve is basically if you have stable coin you can just put it and you are farming crv right and you are also mining the the trading uh trading fees so basically uh it is very simple strategy just you know you have stable coin you put it and you are earning rewards um but um curve has extra incentive approach uh the cv token is a governance token it has its main utility is basically governance and the one example of garments is actually uh the decisions about uh in which pool which proportion of crv must be must be distributed right so if you have uh if you have crv if you have a

majority of cv you can actually uh boost the pools you are you know if in favor for example uh if you are a fan of meme coin uh you can boost some some um you know uh rewards in that pool and it's incentivize people to to bring more liquidity in that pool which is which is kind of good so um of course it it is very uh strange system because you have kind of worthless governance talking which is uh the main function is to somehow control how to redistribute this uh the same token right but uh it is working good uh especially in the beginning for most of the stable coins it was kind of um kind of a silver bullet to to actually find

product market fit for most of the stable coins i have some experience with the creating of stable coins i probably heard about the usdn neutrino protocol so i can say that the changes the fundamental changes for the neutrino protocol was after uh crv after listing on curve and then there were a lot of liquidity uh added within short time so this approach works as a liquidity bootstrap thing and uh um because crv has this functionality like you can vote for each pool must be must have more and more uh profits uh this is they also have uh some um

incentive incentive approach uh how to prevent uh people to always constantly sell this token so it's basically uh it's basically an approach there some siri tokens can be locked for different times for different wasting periods like one year two year three year four year whatever and then you are locking your uh you know farmed governance token you are actually increasing the the way uh how uh how much you can you can get extra crv for the providing liquidity so basically if you are accumulating cv and not selling it and even more you are looking it uh

for uh into governance you have boost for your rewards and the basic strategy of yarn as we can see shortly we will see that most of the pools are somehow somehow connected to the classical yarn farming strategy and the automation of this procedure like automation of a cv token lock to boost the liquidity and so this is basically how it works um what's next let's go to the uh to the yarn finance and here you will find um the volts right we we were talking about walls it's a entry point for any

user to uh to do something and here we'll find on the official young finance website a lot of uh pools for different assets i mentioned usdn so it's here uh pretty good pretty good apr uh and here we can see uh the pools so of course there are stable coins and also another volatile assets but you see the uh the icon of curve on most of them let me make it bigger you see it right so uh this icon means that this pool somehow working with the with the with the curve so let's look at the terra for example

let's open it yarn has a good navigation because then you open the vault you can check everything you can check how many assets here this this is not good uh and you can check how it works you can deposit you can buy drew so basic operations are here right and of course before doing something you have to approve the token so uh every smart contract every volt smart contract which is on the mainnet can be easily uh easily checked by the um following the ezr scan so here you can find uh the the source code of the vault so vault is a smart contract we can read the code unfortunately most of the pools they are

using wiper i'm not familiar with wiper but we will consider how to build the strategy on solidity of course later but uh um a lot of existing pools there using wiper and uh here we can see uh vault contract and its main its main functions so we have read functions what we can do with the with the pool most often uh those are functions which which let you to use the defaults as a simple token as a you know receipt 20 token you can transfer it you can do whatever you want so basically it is a good opportunity for um for project builders uh to somehow reuse the

existing vault in a different types of another particles you know like use it as a collateral for uh for lensing or whatever why just because uh the um the the interface for the volt is the same as crc 20 token so you have allowance you have total supply you have balance off you have decimal like you know all the basic uh functions we have for uh for uh esti 20 token so one the most important thing is if you are using one account and you are depositing into curve and you wanna uh you know you wanna change your account you don't have to you know why do and do some stuff you can just transfer the token and basically it works also this

token can be easily uh shown by services like zerayan or debunk so it's it's a part of the or the ecosystem uh so here in the vault uh we also have uh some extra uh some extra operation some extra functions which are connected to the uh to the strategy which are connected to the um so the admin functions of course every volts they have uh some admins functions uh to prevent i don't know exploits to stop something uh and uh it is okay in defy uh most of the things are working with them we are multisig so volts uh can be uh can be um also working like this so basically yeah volt is a smart

contract uh and user is interacting with it how we can see it on the example uh one of the yarn walls uh is ethereum volts and uh um the the modern version of yarn yarn v2 is letting you to use the the ethereum which is as a fans of the vault uh within several strategies at the same time so basically uh the new versions of of yarn they let you to to build uh not only one strategy for one volt so this is uh somehow accumulating more and more uh funds within uh within um one top one type of walls and you can easily switch between

different strategies after that so no need for users to change the votes for that so you can easily migrate and optimize the strategies this is a good example and let's look how this uh this ethereum volt can actually works um any idea how it can be implemented like if you know the d5 if you know how uh you can generate rewards with ethereum uh like suggest any strategy with the with the ethereum with the iron like how to generate money from ethereum if you have it anyone huh lent

so uh yeah or make it now right so uh yes one of the strategy is basically if you have uh ethereum uh you can um use it as a clutter to mean to the die and then you have die it's a stable coin back to one dollar uh you can put it into the curve uh and the curve generating you uh you uh crv like you know farming rewards and then they are selling back to the ethereum and then it's going back to the to the user so basic strategy here right one second so yeah uh maker dao is a

is a landing protocol which is issuing um a stable coin picked to one dollar so it's easy to uh to change the ethereum to today with some over qualitization of course and then generate reward but it's not only one strategy who knows another strategy on curve you know no one knows let's open the young finance and see uh do we have some some volts with uh with ethereum um let's see okay we have some strategy uh with the ethereum and uh so we have another strategy with

ethereum we can use uh we can use uh pool on the curve finance let's open the curve finance and uh we'll figure out what kind of strategy is here for for ethereum because with the with the lending we already understood how it works but it's only one and we always have to choose the huh yes but but which what kind of pool like uh in any example yeah so you have a theorem you have a theorem like you have nothing more and with ethereum we have this one uh you see this is pool uh for ethereum and stake ethereum with a little finance let me make it a bit bigger you see

so this is a uh as as i told you before on curve we have pools for the same packed assets and even on ethereum we have many version of ethereum it sounds funny but uh it's honest true uh we have synthetics ethereum we have uh staked ethereum we have an another version of different uh you know wrapped ethereum whatever we have a lot of versions of ethereum uh on ethereum chain uh sounds strange especially tries to explain that for uh for uh non-defy or non-crypt people and uh you know they'll ask you questions like why what is going on but uh this is like different approach uh steak ethereum is basically an ethereum which

will be used in the ethereum to zero and it's take by the lead of finance a smart contract and in exchange they have uh they have wrapped or locked version of ethereum so basically this is this is an approach how you can build uh two types of ethereum and uh you can like anyone who has ethereum and staccato theorem or just ethereum uh they can stake it into the curve and curve has rewards so we can see it here uh we can see that we have actually a lot almost one million ethereums and stakeholders on the curve this pool is balanced i mean the same amounts of ethereum and stake ethereum within the pool and

here we have uh here we have some uh some some incentives let's see uh how much how much incentives are for for ethereum so it is here uh so we have uh one percent uh in crv and uh for the firm it's great because ethereum is not stable coin it's volatile assets you are taking risk so this is a way how you can uh you can make rewards and yes the second approach for uh for the yarn strategy is uh you have ethereum uh for example 10 ethereum you are sending that to the um

to the volt volt is uh sending this ethereum into the um into the curve finance and the five ethereum exchanging to the stake differing on the current finance uh and then you have your position within the curve if you have the position on the curve you have rewards those rewards are boosting by locked uh locked crv by you know by the pool because pull is somehow uh connecting the all people who are providing liquidity for this pool and uh we are boosting liquidity so this is the difference between uh between the simple strategy if you have ethereum just put it into the curve or

the strategy then you have ethereum put it into yarn and and get rewards so guys do you have any questions here yes you can ask how much uh it depends on the uh it depends on the number of operations you are doing because uh zap functionality uh is already implemented you don't have to implement it uh it's pretty optimized by zapper so uh subfunctionality which is automating this procedure is already implemented but

it depends depends on how exactly you are interacting on slide back this one this one so uh with each strategy we have some some functionality around around uh improvements of the positions and before the the liquidation happens you have to rebalance you have to uh

uh wait you some some liquidity from uh from the maker because you know uh it should be tracked by by some some keeper oracles it should be tracked by some watchers uh because you don't have to uh be in this situation but uh but uh pools they have sorry uh they have uh some uh some some issues with the with the of course uh exploits with the uh with the protocol uh hacks and you know like flesh loans of course uh it will be uh it will be coded as an um resolution resolution strategy probably you know uh a year ago uh new vaults uh were hacked uh the dive vault were hugged for like five minutes or

millions or something and uh um of course uh the the happens so okay we're gonna say uh any any votes they have any uh strategists and and walls they have admin functionality we will see uh those uh those functions how to manage the operations how to uh keep some balance uh like liquid how to put it back into the system so it's basically uh up to developers up to strategies how to uh how to manage that any more questions if there is no more questions uh let's uh let's look at the fine medics uh who is familiar with findmatics

unfortunately only half of you i'm highly recommended to watch to subscribe for this channel because most of the uh you know popular defy protocols dfi concepts and primitives uh easily explained uh here and for me it's like you know um it's it's the best way uh to to actually on board uh into into new strategies into new type of protocols and you know have a fresh view on on something so here on pharmatics we have yarn finance and it's a bit old video about yarn finance we have actually two videos about how

volts works and the yarn finals and the yarns started before the curve so today we are we we are speaking about curve we are speaking about boosting uh apr and and stuff but the yarn started before curve and uh if you are interested in how it started let's look at this video and then uh we will talk a bit more about walls and and the the smart contracts of walls sorry i didn't pay for for you to premium in this video before we begin if you're interested in learning more about decentralizations

make sure you subscribe to this channel okay let's start with what why earn finance is all about the main element of why earn finance is the y-iron or yearn protocol the earn protocol in essence is a yield optimizer that focuses on maximizing defy capabilities by automatically switching between different landing protocols before we explain the mechanism of the protocol itself let's see how yearn came into existence in early 2020 the author of the yearn protocol andrey cronier started looking into automating his strategy for choosing the

highest paying lending protocol for his stable coins before the first iteration of the protocol andrei had to wake up every day and manually check which protocol pays the best apy on that day and consider moving his funds to that protocol there are always a few options available at the time such as compound other fulcrum or dydx this manual will work so we'll have a pause here sorry again we'll make a pause here and how it's actually started so the yarn finals are created by android crania right and uh the simple explanation of course over

simplified explanation is uh it started because uh there are many a manual operations if you're gonna maximize yield you have to manually uh select the the most profitable protocol for your uh for your assets and then you know deposit then again by june and again deposit and it is basically manual operations and at that time uh early 2020 uh it it were like only a few protocols where you can do it so the basically uh those protocols are about lending so if you are boring or lending assets if you are boring you are generating uh some rewards for those who are lending so um you can you can choose where uh the best

interest uh interest rate for your assets uh in in defy and of course uh it is not something which is uh which is good for developers who manually uh switch between the protocols so uh the basic strategy was let's automate it right and this is how uh yarn started uh who already knew this okay only a few of you right but right now yarn is completely different but uh the story is about uh the choosing different different protocols for optimizing yields quickly became repetitive and boring so andre started coding the first version of the yearn protocol to automate the whole process of choosing the most

optimal strategy for his stablecoins the protocol in essence creates a pool for each stable coin by depositing a stable coin to a pool the user receives their y tokens that are yield bearing equivalents of the coin that was deposited for example if a user deposits die the protocol issues wide eye the die that is pulled together can then be moved between different lending protocols to always maximize the yield for instance if ave offers a better yield on dye than compound the iron protocol can decide to move all or some

of the dye to other the protocol checks if there is a better yield available at the time a user deposits or withdraws money from the pool triggering a rebalance of the pool if necessary if a user wants to withdraw their initial die plus accrued interest they can redeem their wide eye and receive the underlying die one thing that the protocol always assures is to never swap the initially deposited stablecoin to a different stablecoin even if there is a higher yield available so for example if a user deposits die the protocol would never swap it to usdc

even if usdc has a higher yield this is because most users want to withdraw the same stablecoins as they initially deposited after the initial version of the protocol was completed andrei decided to open it up to more people who were also interested in automating their yield strategies from the protocols perspective adding more funds to the pool was beneficial as there were more opportunities for triggering rebalances with more deposits and withdrawals taking place after the initial warm welcome by the community andre started working on improving the protocol itself as the

money in the pools started growing some of the previously obvious strategies like moving coins into the highest paying lending protocol stopped working now the protocol had to also anticipate what would happen to the apy if a large amount of funds are moved in so it would have to also optimize splitting funds between different protocols and choose the most optimal solution at this point andrei also started working with curve on the ycrv liquidity pool ycrv pool contains the following y tokens why die why usdc

why usdt and why tusd making it easy to swap between the y tokens without unwrapping them into their underlying tokens by depositing stable coins to the ycrv pool the users can earn trading fees for providing liquidity on top of getting a return on their yield bearing y tokens up to this point finding out what the best apy on a given stable coin is was fairly easy this changed dramatically with the introduction of liquidity mining with compound's comp token distribution as a prime example

the comp token distribution was also pretty much the time when all the yield farming hype started if you need a recap on yield farming and liquidity mining you can check out this video here comb farming basically changed the whole landscape of finding the best yield and checking the apy of a deposit was no longer sufficient to find out the actual yield you would have to add up all the extra tokens that were being distributed finding the best strategies became more and more complex with all the yield farming craze going on andre together with the yearn community started working on another

idea vaults yearn vols in essence are pools of funds with an associated strategy for maximizing returns on the asset in default vault strategies are more active than just lending out coins in fact most of all strategies can do multiple things to maximize the returns such as farming other tokens and selling them for profit providing liquidity or borrowing stable coins each vault follows a strategy that is voted in by the yearn community the full explanation of the vault's mechanism is outside of the scope of

this video but i'll make another one that focuses just on this super interesting topic so make sure you subscribe to this channel to stay in the loop now let's talk about the iron's token wi-fi to further decentralize the yearn protocol and allow other people to make meaningful decisions on the future of the protocol andre decided to distribute a governance token to the yearn community the token distribution was focused on having a fair launch and rewarding the yearn community to ensure a fair launch the yf token had no pre-mine no vcs allocation and even no team reward

all the tokens were distributed to the users of the protocol a nine-day long token distribution started with allocating 10 000 wifi tokens to the liquidity providers of the y crv pool the lps had to stake their ycrv lp tokens to receive wi-fi rewards shortly after two more balancer pools were added with 10 000 tokens each totaling 30 000 wifi tokens regardless of a disclaimer that the wifey token has zero financial value the money started flowing into the incentivized pools

topping 600 million dollars in locked value also the wi-fi token itself started rapidly appreciating in value this created additional risk as the author of the protocol was in control of the governance admin ki before the governance went live this key could potentially be used to create more wi-fi tokens which would result in collapsing the price of wi-fi this was quickly fixed by changing the single admin key to a multi-seek key requiring multiple signers from the defy yearn community the wifey token as designed is

extensively used in the yearn governance to decide on the future of the protocol with one of the most active and loyal communities in the whole d5 space there's also a lot of speculation on the potential future revenue from the yc tokens that fuels the price appreciation the wi-fi token increased in value from around six dollars when it started trading to over thirty thousand dollars per token less than two months later pretty much a parabolic run although the iron protocol and most recently the vaults are at the core of the urine finance ecosystem

there are also other services such as why swap why trade why borrow and why ensure that are outside of the scope of this video you can look them up by checking some of the links i'll put in the description box below yearn is clearly one of the most interesting protocols indeed okay guys this is how it started uh this is how it was originally um you know created uh the the idea is simple right uh to automate the the different strategies uh not by uh manual switching between between the the profit profitable um doubts but uh somehow you know um

automated and rapid up the original asset and i have some questions to to you guys um like do you know uh like the case it was uh it was a year ago about uh the the new pool uh been hacked like how they solve this issue with with the user funds who knows you remember uh okay but uh they lost some money from the from the pool how they uh recovered the pool they actually recovered yeah if you don't know uh it was simple

uh in this video as as you can see the the fine medics explained that only three three thirty thousand uh young issues at the time but after this this hug people they lost like 5 million so the yarn community they decided to uh to issue more assets uh use them as a collateral in maker daw because it has it has this the pool and issue uh you know using yarn as a collateral wi-fi as a collateral issue five million die and then recover user funds so if you don't know uh this is also possible yeah

it was funny example because uh you know it is only works if the protocol is really accepted by the by the crypto community and it has uh it has a functionality to be as a collateral on the maker dao but yeah it was it was solved uh easy and and and uh and nicely what any any questions yeah you have no questions right so uh what is the main idea of the of the of the votes what is the main idea of the uh of the strategies uh like uh what what do you think around what

andrew is originally created and this thing is actually if you are staking the assets you are getting back the same assets with the rewards and rewards are also in this asset so this is main idea for the for the all strategies you have to somehow manage to to [Music] to exchange rewards into the same assets which was staked in this is a this is the main idea and uh uh another question to you guys uh what do you think what's the difference between liquidity mining and liquidity farming who knows this difference it's basically two different uh two different things who knows who who is ready to answer

so the the difference between liquidity mining and liquidity farming is mining means that if you are providing the token on the mm you are generating rewards which which are coming from the transactions like 0.3 percent from the uni pools or different uh different uh fees from the from the curve uh you are mining your rewards so the more the more volume the more operation within the pool the more money uh you are earning as rewards and of course you can exchange uh the rewards on uh any assets within the within the pool like if you if you're providing uh liquidity to the ethereum and stake ethereum and uh there is rewards which is coming um as a

one or another token depends on the on the trade side uh you can easily exchange one or you know ethereum to s ethereum or s ethereum to ethereum so you can fix your profits in ethereum you are providing ethereum liquidity you are fixing profits in ethereum which is okay but uh this is liquidity mining thing right if you have liquidity farming most often uh you have rewards in the form of new token so we have the new token in the system before we have only two like token nato can be and you provide liquidity with the liquidity farming you have you have free token you have a new one which is coming as a reward and the the biggest

thing the biggest challenge is you have to uh to implement the young strategy for uh liquidity farming not not mining because with mining it's easy you're you exchange back and you are doing rewards but really keeps you mining because then you have the ethereum you have you have stake the film and you are getting some coin you know like reward coin you have to somehow uh by the uh by the strategy automate the procedure then your rewards in in in the pool in the uh in the vault uh will be exchanged to uh to the to the world uh token so the ethereum so you need liquidity with the farming token and uh and some some liquid assets it can be uh

it can be even ethereum or usdc or whatever which has you know proxy liquidity to the uh to the ethereum so this is a biggest challenge and this is why a liquidity mining liquidity farming a difference for uh for strategists and for different approaches you have to change uh the way how you are um automated so let's go next uh let's talk about volts if you if you open the uh the github with the or documentation the documentation is uh here so on the github you you can find uh the base strategy and the the all things uh

about uh how which which methods uh public methods uh uh you have to implement so uh to let your strategy works it is on the github yarn brony strategy mix so you can find this easy and uh here they have uh they have a simple explanation the default functionality so uh then we opened vault already for example here right we opened it uh we noticed uh a lot of functions and of course some of the functions are inherited from the erc20 interface from the uh from the admin manager interface but here uh for the for the user perspective we need only a couple of functionality first of all

alice must approve uh the token um to be to be spent with the spend limit right so everyone knows this functionality it's a standard thing for rc20 tokens if you are building uh dye pools if you are building dive vaults uh we have to uh ask alice to approve uh the the transaction uh with uh with uh the diet token of buy the vault address so the vault address will somehow manage uh the the the die token from the alias and uh of course uh there will be limit like you know uh of course limit is different depends on the decimals but let's this uh this number that has as far as i know

uh 18 decimals so this number will be big and after this approval alice she is communicating with the vote so she is calling the the the the method which is deposit so uh alice uh before she approved for a volt smart contract to use her die right now alice uh she can easily start using the strategy after the approval she is calling deposit so what is going on inside uh inside inside uh the the vault smart contract he has an approval from alice to uh to use those die uh to to to move them to

to put them into different protocols so it's basically uh basically alice approval to uh to spend and uh and transfer funds and here alice is uh interacting with the vault and depositing funds into the vault so um then the funds uh within the vault uh the magic is happening so the strategy starts working like putting it into liquidity pools boring protocols whatever like um any dub which is generating income which is generating rewards uh and after some time alice uh she's able to withdraw uh we drew all funds or you know part of the funds uh by calling draw and uh

as we considered before the main principle of yarn volts of yarn strategies are if you are depositing funds you have to withdraw the same funds back like if you are deposing die you have to wait through the die if you're deposing ethereum if you know there is no exception here and uh of course uh we are like if we uh are thinking that uh the strategy is profitable uh the strategy must generate more die than at least a deposit right or anyone in in the pool deposited and of course the the share of the die uh after some time will be bigger than deposited so how to find uh how much die alice uh is able to

withdraw we are using a price per share function it is always growing because we have uh we have profit in the in the world right so the basic idea is pretty simple vault is working like this uh alice depositing like approving then calling deposit then magic happens something with with the funds which is generating more and more die and then alice uh is way drooling she's drinking more funds than she she deposited so this is uh this is a basic uh thing around deposits uh guys do you have any questions around vault around the architecture and the uh the main functions of the vaults i told you before right uh it was a not

a background but it was uh exploit which is also the background because you have no funds to to get users right ah okay sorry um you asked uh what is happening with the with the world if there is a bond translation if there is nothing to uh to to pay back of course this method cannot be uh can it work and they must be decided by the uh by the managers of the vault how to resolve it and uh the case with the exploit the case with the uh with attack uh on the um pool one year ago almost a year ago i don't remember uh exactly uh they stopped the vault and then uh they

issued the die from the you know a new supply of of wi-fi they deposit it back and then start working you know it's like uh it's it's easy to to solve it but again uh as you can see the uh the young finance is not a company it is not company it it is it is a community first of all right of course there is a token there is a uh some admins but anyone can become a strategy uh strategist for the uh for the votes and uh of course you have to understand the basic uh the basic uh ideas of how volts works how you can create the strategies uh there is

there is no there is no criteria about which protocols you can use for your strategy and which is not but if you open the documentation you will find that it's up to the strategist to be sure that the protocol is somehow secure and this is one thing and another thing is uh to be officially accepted by the by the young community there will be walled so uh of course not anyone uh can uh will be able to uh to develop the official uh yarn strategies but uh there is no there is no uh restrictions uh for anyone to uh to use the framework as we we can see now uh to build the strategy based on different protocols and then

it's working and uh so we consider it uh we already explained how volts works uh of course uh any um you know black swan things up to strategists and and the managers uh it can be so so resolved by you know a different way anyone can become a strategist really like if you understand how it works you build the strategy you just you test it uh you can apply it uh for for being accepted and uh as i told you before the volts we will consider walls later uh within the vaults there will be several strategies and uh people uh like and and uh between them there will be easiest

feature because some traditions are more profitable some are not some are more secure some are less secure so it's uh it's up to the up to the uh governance how to how to build it so yeah but basic functionality of volts is very simple like you're depositing you are while driving the same uh the same asset and uh do you know another example pretty classic example for that then you have one asset you are uh deploying somewhere and then you are doing the same assets like uh it's a buzzword anyone this uh anyone knows this buzzword uh please uh uh no no staking

this thing like if you have ethereum and you are getting more ethereum like if you are taking asset a and you are getting more asset a after some time it's basically staking right because you are increasing your stake in the token so one like it's not obvious to be honest then i uh went deep deeply into the yarn strategies i was wondering because uh sometimes uh things are you know on the table and no no no one can see them uh one of the most easiest young strategy is compound staking so most of the protocols they have staking with the apr apr means you then you deposit it 100 with i don't know 50 uh apr after one year you will have a

100 dollar plus 50 dollar right so because of apr uh apr means there is no compounding this is the difference between apr and apu because epu means yield like how much you have in the end uh in in like most optimized strategy or how how can name it uh but apr means just you know rate rate which is uh set up within the smart contracts and or you know another system and uh rate is basically um the the the um the linear the linear function like in the beginning you have 100 after some time you have 150 and then if you are not doing risk taking if you

are not doing uh you know repeating uh procedure uh increasing the um the default balance the balance of the state assets uh you will be you'll have linear rewards for long time and the basic strategy which can be implemented by any protocol and this is very important question because uh as you hear probably you are building protocols you are building staking for your tokens of course uh you can you can start building strategies with a very easy protocol uh with a very easy uh strategy you can create the the staking rewards with the epr just like you know uh computing computing based on the share and the number of block or you can choose whatever uh

implementation already available uh you can find in gcdow already implemented uh fixed uh fixed aprs taking for whatever assets or where there are different uh you know staking implementation with the dilution like if you have for example like a pancake or whatever they have dilution thing uh but you can you can build uh the yarn strategy for for your protocol if you just automate the the staking operation like i don't know every week for all users you will uh risk take the the token um which are coming as the rewards from the staking and then you are increasing the balance for the second right so

you will let users most often for your own users you will automate them the procedure manually go and restake rewards sometimes it's even it's it's not even bigger thing i mean uh for example uh in our dao we have uh uh 23 uh apr and the apu will be like 25 or a bit more there is a uh there is a lot of calculators apr to apo you see uh you can easily uh you can easily compute um the difference between apr apr and apu for any assets and apr means

like you know stable rate of the of the staking rewards and apu means how uh potentially with a different type of reinvesting how you can increase how you can increase the the yields for the users and let's consider the apr like i don't know let's make it bigger uh 100 apr right if we are staking it annually so they are same i mean there is no reinvestments right the strategy uh just by and hold and the stake as a as a token if you if we are risk-taking monthly means that we are is taking 12 times per year right so we are basically

uh reinvesting the the funds which are coming as rewards uh 12 times so for 100 percent apr actually double for the funds we have uh 161 epo right so this is a basic strategy anyone can implement for any protocol if you're going to if you want to start with the writing yarn strategy just find any protocol or your own protocol with the with the apr and without automatization of apu and just build it build the vault uh with the strategy which are just automatically uh for some time i don't know month monthly i think it's uh um it's not so often we need to do that like weekly or also again depends on the chain on the theorem it will be very

expensive to to do it uh often on on another chains like phantom orbit room it's it will be uh less expensive and we can do it even every block blog of course we are paying transactions and we have to uh provide some incentives for the for the oracles but yeah uh basically uh this is the difference and this is a main um and most obvious strategy for any d5 protocol to be implemented by anyone just uh compounds taking uh sorry guys wanna break uh do you have any questions here with the api and apu and and the strategy here no so yeah

apr to apu and uh we'll have the same uh vault functionality for for uh for for staking optimization right one token is going uh into volt uh same token is going out so this is uh this can be implemented into the yam strategy i'm not sure that any uh any proposals will be accepted uh by yarn if you are building that for for your own protocol but you can try uh it's gonna be a good example uh to start um before we'll go uh go ins more into the uh code into the hard cut and the uh and the architecture of the strategy uh uh i wanna show you the um the video again from findmatics about votes

it is it is good to see and i also need some break sorry again so what are your earned vaults all about also how does the heath vault work under the hood and how can it bring over 60 returns we'll be going through all of this in this video before we begin if you're interested in learning more about decentralized finance make sure you subscribe to this channel okay one more thing before we start if you're new to the yarn protocol or if you need a quick recap you can check my other video on yearn and the wifi token

here cool let's start with the vault yarn vaults in essence are pools of funds with an associated strategy for maximizing returns on the asset in the vault vault strategies are more active than just lending out coins like in the standard neon protocol in fact most vault strategies can do multiple things to maximize the returns this can involve supplying collateral and borrowing other assets such as stable coins providing liquidity and collecting trading fees or farming other tokens and selling them for profit each vault follows a strategy that is

voted in by the yearn community yarn vaults were created as a direct response to yield farming and liquidity mining that made searching for the highest yield much more complex than just switching between different landing protocols you can learn more about yield farming and liquidity mining here similarly to the standard yern protocol when tokens are deposited to a vault the user receives their corresponding white tokens that can be redeemed for the underlying tokens one of the important rules when it comes to vaults or yarn protocol in general is the fact that you always withdraw the

same asset that was initially deposited so farm tokens and accrued fees are sold for the main asset in the vault the amount that is withdrawn is the initial amount that was put in plus the pool yield that was earned minus the fees not everything that is deposited into a vault is put in a strategy the vault differentiates between vault holdings and strategy holdings most of the funds are used by an active strategy but there is also an idle amount that just sits in the vault when the user withdraws from a vault the funds first come from the idle portion

of the vault so guys what do you think is no withdrawal fee which shared it should be between strategy holdings and the and the idle amount your guesses like if you are building protocols uh you have to decide 20 for idle right but anyway we all agree that uh because you know it's a it's a capital which is using for generations of course but it's a few of the strategies to

decide so of course sometimes we have to at the same time make for user easy to enter it at any time without you know without uh cancelled transactions without um situation there we have uh zero months for our tool because there are strategic holdings and we have to wait through so it should be somehow used and uh the thing is the big like you know the general law uh i found in the d5 is the

more tv the more liquidity within the world the less percent must be keeps almost constant even if the user basically is decreasing the you know empirically the the amount of the funds which are withdrawing uh much less than the the the holdings which are able so of course uh you can start even from fifty percent just to disrupt just to let users deposit and white rule and then when the tbr is growing can make it less and less because in that way you will make it more

efficient you know the whole if there are not enough funds in the idle portion of the vault to cover the withdrawal the funds have to be withdrawn from the strategy which results in a 0.5 fee on top of that some profit earnings strategies will result in a five percent fee to subsidize the gas costs for community-made strategies such as as the eth strategy currently 10 of this fee goes to the strategy creator so creating new vault strategies can be a good opportunity for a skilled developer

fees that don't go to the strategy creator end up in a dedicated treasury contract if the money in the treasury contract exceeds the 500 000 threshold everything over that amount is redirected to the governance taking contract there are currently multiple urine vaults available such as stablecoin vaults dye tusd usdc usdt curve lp volts y busd sbtc non-stable assets link wi-fi ether

now let's have a look at the year in heath vault why it to understand the concept of vault strategies so there are many pools for stable coins for many pools for coins and vault assets but also volatile assets and the the main idea here uh why uh we are you know uh talking here uh the benefits to to develop um yarn strategies is not only about uh doing something good for your projects or on other projects you know and and optimize yield uh with staking or with the more difficult strategy but also you can earn rewards i mean uh

on on the last slides here you can see that a strategist which strategy is approved uh within the system uh can be can earn uh ten percent from there from the profit uh of the protocol which is incentivizing people to uh to be creative with the strategies uh because the the more uh you know more yields they are suggesting the more uh interesting strategies they are uh suggesting to the to the young finance uh the better chance that the funds uh will be um deposited into uh his strategy so the more profit he will uh generate so for developers who are gonna uh who are gonna

uh vent who gonna go into the d5 development it's a good strategy to start because you don't have to run uh you know dow you don't have to raise funds for for something you can just start learning uh how to how to build the strategies uh you can build one and then uh help with the um you know ask for help with the promotion and you can start earning something without you know without uh reason to be employed by somebody so it's a it's easy strategy for anyone from everywhere to to start and this is why i like yarn because uh you know uh it it's a good uh good start point for for for developers a lot of

developers are asking about where to start so this one is a good opportunity sptc non-stable assets link wi-fi ether now let's have a look at the year in east vault why eat to understand the concept of vault strategies better as we mentioned earlier a strategy for each vault is chosen by the community we are focusing on the current running strategy for the wyeth vault that may and will most likely change over time in the current strategy after a user deposits ease into the vault the heat is put into a maker dow landing platform as

collateral by supplying its collateral to make a dao the east strategy can borrow die at 200 percent collateralization ratio creating a collateralized debt position cdp this means that if 100 eat was put into the maker dao with 500 dollars per eat the strategy could borrow up to 25 000 die borrow dye is then put into the yearn die vault that uses a strategy that deposits die to curves white pool that is a pool with stable coins consisting of die usdc usdt

and tusd now because of the current liquidity mining program of the curves crv token providing liquidity to the curves pool and locking lp tokens in the curved gauge result in getting rewarded with extra crv tokens on top of standard trading fees generated by just supplying liquidity to a pool the e-strategy then periodically sells crv tokens for it and uses the trading fees from the wide liquidity pool to accrue even more interest these steps all put together can at the moment result in high returns of around

60 percent on your eth depositors to the why it fault two days after launching the why it vault had already reached 300 and seventy thousand east locked in the vault and it became this is finance nft the nft marketplace with everything you need in one place indicate the largest cdp on the maker dao further deposits to the y eth vault were also temporarily halted to balance between best profits and best risk adjustment why it vault has a great potential of sucking in more and more ease and becoming pretty much a black hole for

ease this should in theory increase the price of heat as more and more eat is taken out of circulation is that 60 percent in the why it vault sustainable probably not it all depends probably not because there are some you know numbers around can you hear me guys of course 60 is not always sustainable but it is good for me to you know to create excellent to put the liquidity but then it's going down most often and there are different

rates for uh within the deep fight we made a distortion like the yields around 25 uh some of them they have small uh small videos like one or two percent if you open the curve you will find those uh but yeah the average one is small and the white he mentioned the black hole here he mentioned that because those holes they are somehow locking the ethereum circulation and for many

protocol builders uh this is something like economics like if you are building protocol and you have a functionality where uh your turkey uh is um somehow extracting from the circulation from circulating supply somewhere this is uh this is a good thing always because you know based on the simple economy with the supply demand we have less circulated supply which is you know how it works to the valuation and instead of learning instead of doing some um you know cheap things uh you can basically uh you know design the system uh to uh to increase this um these

operations like extraction from the from the security supply and this is good your goals made this and it's not only this right now we have another leader which is redefined mining programs available if there are no more programs like curve crv one available or rather there is no interest in the programs so the farm tokens are not worth anything the return on the vault would go down most likely to a single digit or low double digit apy one of the most important benefits of using vaults is automating your yield

farming yield farming can be a pretty time consuming and expensive activity so if you're not willing to spend hours searching for the best yield farming opportunity spend hundreds of dollars in gas fees to move funds around and keep monitoring your collateralization ratio it is probably better to rely on the vaults this all sounds pretty cool but let's not forget about potential risks besides our standard defy risks such as smart contract bugs and stable coins losing their peg to the dollar the heat deposited as collateral on maker dao is susceptible to liquidation

if the collateralization ratio falls below 150 percent in our previous example if the eighth price drops below 375 dollars the collateralization ratio would drop below 150 percent if this happens the eighth volt would have one hour to bring the collateralization ratio back to over 150 percent the reason for this is that maker dao's oracle security module osm gives the cdp owners one hour to put more collateral in so it was a question right about what's

going on so yeah maker has some time for for the for the vault to somehow rebalance uh the position liquidator the eighth vault is directly integrated with this module so it can react to changes in price ahead of time by bringing back the collateralization ratio to around 200 percent every time the heath price drops yarn vaults are clearly one before we'll uh finish the video uh the the the good uh point about uh regulatory

rare capitalization is then you are using your if as a collateral you are basically using the the margin right you are holding it you have some liquidity you can basically buy another if and then if uh if price is going up you will be uh you will be in in the perfect position but uh um here if the ethereum is going down uh you cannot keep um the cdp uh on the previous levels you have to wait do it and you have to stake it back right uh to make it work so and this procedure exactly out automated by the uh by the strategy so

and because of the the strategy is always tracking the the oracles it's always tracking the what is going on uh it can do it you know ahead uh ahead of the of the market ahead of the of the maker dial every time the 8th price drops year involves are clearly one of the most interesting new developments in the defy space but like with pretty much everything else in d5 before deciding to use a particular protocol always make sure to understand the associated risks so what do you think about the iron volts and the it vault in particular do you think it okay guys um

let's finish this part and uh i suggest to have a short break like for 15 minutes just you know to drink to uh to relax and then we'll continue uh so i'm gonna uh finish with the with the questions like uh just you know for you uh uh who who is really interesting into the uh how it's working under the hood well already consider it how the vote works right it's very easy just approve deposit and then why draw like nothing nothing difficult here of course strategies are a bit difficult because the strategy is something which is doing the magic operating with the with the dubs and

somehow solving everything we already discussed we have three main methods within the smart contracts uh for the for the strategy template which is prepare return adjust position and liquidate position what do you think what is uh what does mean prepare return uh so prepare return means that you are extracting profit from the uh dub and uh put it into the into the wall right

and do some kind of you know recommendation just some changes right let's let's see uh are you right now before the uh before the break so uh of course you're right uh it is taking profits and uh somehow reporting loses if there are any um all the strategy you're right let's go next we have uh adjust position what do you think what is adjust position any guesses why you know by the meaning of words rebounds okay so

it's basically uh the balance between the idol and the and the strategy uh strategy funds right like between them let's check uh i know that's just uh interesting to check so um uh we adjust position so the adjust position uh is basically investing uh uh the tokens like dow tokens uh for some reason it's called want in in er but if you are working with dao uh die talking like sable coin uh this this method is actually depositing uh funds yes basically you're right because uh the poison funds in the protocol is somehow rebounding between evil idol

funds and the strategic funds yes you're right and the last one before the break liquidate position it should be easy yes basically uh it is um uh it is uh um enough positions to to to uh for forward rules to uh to increase uh the the idle amount for for for white robots so guys um uh let's have a break uh for 15 minutes let's let's make 15 minutes because we have some parts to continue and uh

let's be there at 3 15 okay we'll start 3 15. see you [Applause] wow um

[Music] uh there is um

percent okay let's come back

uh can we close the door hey guys let's continue uh thanks for closing the door um i see not anyone uh everyone has a laptop but uh those who has will um do something with the hard cut uh i will explain uh the the pros and cons of of the hard cut and uh we'll go

deeply into the into the strategies uh if we'll have enough time it seems like unlikely but uh we'll also will try to implement the the mock for the vault and the strategy so let's go let's come back with the with the uh to the um to the vaults so the the basic functionality of old uh is interacting with user accepting the funds and the after the magic happens as a part of the strategy and the dub logic uh return funds with the with the profit back uh and the basic functionalities are taking as we all uh discovered this this workshop but there are also another opportunities how the strategy can can be built like

using curve using another liquidity mining liquidity farming borrowing landing thing so uh but the idea is simple like depositing and then returning back the same token uh we we also finished with uh with the three main function uh for the uh yarn strategies which are uh prepare return uh actually taking profit from the from the dub to later redistributed and adjust position which is actually depositing funds uh which are coming from user into the up into the protocol into the dap and liquidate position which is you know back operation uh way through and and close this position so basically uh uh then you are writing uh

yarn strategies uh you have to uh be uh you have to care about uh those three functions and uh how uh they should be implemented like how they should be optimized in terms of gas cost and whatever so um before we'll go to the uh to the uh hud uh let's look at the at the all important methods of the of the strategy yard strategy so of course we have uh some descriptor uh just to you know distinguish your strategy from uh other strategies and uh of course we already discussed about just position for uh for deposits funds into the dub uh of course we uh already discussed

about uh that we have to some time way through the uh the profit from the dub uh so later distributed across the users and uh we have uh another approach another methods uh which is liquidate position like you know um which is we're drawing uh funds from the from the dub to later uh redistributed and then uh we have a full exit uh like you know completely exit from the from the dao um and uh we also uh have the approach to understand how many assets strategy has which is uh estimated total assets uh another thing is uh want who knows who you know remember what what mean want

because we will see what yes it's basically the term for the token which is depositing into the vault right so uh within the uh within the strategy uh um smart contract you will operate with this with this variable uh won't so and of course we have uh read function to estimate total assets we can we can always knew how how much funds we have and uh as i told you before those vaults are not um are not immutable uh of course any smart contracts in solidity are immutable but the logic can be uh can be immigrated if you are using one strategy you can uh change it to

more optimized strategy or you know if you found exploit you can you can do migration and strategy has prepared migration uh method for for this operation and uh so um those are basic uh basic uh methods for the uh for the for the yarn volts for the young strategy uh and uh yeah so to implement the uh the yarn strategy we have to uh work with the two smart contracts we have to uh implement or inherit vote operation and implement strategy the strategy working with the dub so the more logic here for the writing

writing strategy is around how you are interacting with the dub itself because money is coming from the dub not from the strategy strategy just a controller which is uh switching between different uh different um you know different strategies uh about what to do with the with the dub interaction and uh so let's go to the hard hat i'm suggesting you to uh to open a laptop to uh prepare the the folders for uh for for the workshop uh let's uh i have this folder

it is if dubai can you see it right now is it okay it's a boring part so you know we are coding we are making mistakes something is not building something is building uh too long so uh this is a boring part but um we you probably already experienced with another approaches to to write smart contracts like remix or you know the previous uh yarn workshop was with brownie right so probably brownie with the python and there are a lot of um ways how how you can uh how you can

write smart contracts i like her hat because her heart is focusing on uh fast uh testing environment so it's basically a good approach if you are building contracts and they are interacting with another contracts you can uh you can build the whole environment with the old dependencies and you can you can easily execute uh multi multi-level interactions with the smart contracts and it's happening very fast one of the fastest framework for that so let me see what we have uh okay i already uh

forked and cloned the repo i want i'm gonna do it with you right now so i have uh empty repo right now uh let's open the the hard hat so it's a hard hat org you can see uh it's a few room development environment for for professionals and uh basically it's uh it's a tool you can do everything because it's including truffle it's including all the libraries for you to create uh to create accounts to uh to imitate some some interaction between them it's everything include you have questions okay so um there are a lot of blah blah blah

stuff and the good thing is they are tutorials uh if you'll go to the tutorial they have a quick start which is a good thing uh because you can easily install hardhat you will see the uh the basic examples but uh uh these examples with the with the javascript uh today unfortunately we don't have time for uh for typescript it's much more complicated in terms of dependencies but uh with the with the javascript we'll see the uh the boilerplate uh anyone can start uh from so uh the boilerplate can be found here it's a easy greater smart contract like you are you know sending message and have a response uh the basic example but it's too simple because

there is there is only one contract and there is no interaction between contracts i prepared uh the i cannot say better version i can say uh the the a bit advanced version uh for uh for showing examples uh what's uh you can do with the hard cut you can find it here on the github let me make it bigger i cannot make it bigger right okay uh i can do it here on the presentation so please open this link and make it bigger you see it so let's uh let's open this

this wrapper and clone it i'll keep here for for one minute just for you to to clone it because in this example we will consider the the all important sides of the hard hat and how easy it is to to start building with my first experience with the with this elite was with remix and it was like pain because you know you can easily write something and deploy but uh then

you're thinking about like uh something which is more complex than greater small contract you understand that you need the tdd approach which is test driven development approach because then you are writing dependencies then you are writing or you are designing the system you have to think think that um you have one contract with one interface another contract with another interface they somehow communicated uh you know and uh you mock one smart contract you are writing a preparation for another smart contract so it's anyway must be like you know standard development not like web edu for deploying tokens it's easy or you know uni uh univ2 pools but for any custom development uh we need something

which is uh closer to the normal development with a you know compiler with a test running system etc so guys uh have you already uh cloned it okay cool let me do it let me do it soon and we'll continue so let's open it sorry for switching between sizes let's fork it i'll try to fork ssh and git clone let's see so it was very fast uh

we have hhcimt template i forgot how to how to explain uh the the the name but of course hardcard uh tutorial template uh it is basically inherited from the original version but uh we added some uh some smart contracts interaction some mock smart contracts and the test smart contracts which are more [Music] comprehensive to to show you what we can do with hardhat and let's go there we can see some some files here like the the basic uh the basic logic here we have uh tests we have scripts we have contracts let's open the uh the visual

studio for that um who is using visual studio visual studio code so most of you right because uh recently they um the hard hard they released the nice tool for for visual studio coders and i haven't tried yet but suggest you to follow their twitter and find it because it's like make it make development uh easy as as possible okay open the folder uh find the uh the the repo okay here it is uh so what we have here uh we have uh the basic uh the basic architecture

i like how it's scaling um we have uh contracts we have scripts and we have tests so uh and this is basic structure here uh contracts you can write here uh interfaces are also smart contracts so you are keeping keeping it inside and uh my approach is to also keep mock uh smart contracts also inside why we need mocks who knows why we are using mocks like in in our development any guesses yes exactly because then we are building the device strategy which is interacting with the yarn and then uni and then you know a lot of things talking one second three

second four like a lot of things we have we don't have to deploy it because it's you know simple logic inside so uh to be absolutely sure that our logic working as as we are expecting and uh to to uh to implement tests which are doing computations because the most most difficult thing during the five developments is actually computations uh you probably know that athlete has no um flawed numbers and and you know any how to say uh respectful approach uh for uh working with the computations you are also always uh working with the uh with the loan number and then you have to keep in mind that the decimals you have to always convert it and uh the the

dissimal logic is is a hell it is i don't know for me it's like um the most difficult thing during the smart contract development despite the fact that it's even uh even easier than the swift development or for ios or mobile development or even a backend but this thing is really annoying so and it's even better if we are using mocks to uh to somehow check ourselves with with the working with the numbers you can just mock any type of corner cases or you know cases in the middle for for for computations and you'll be absolutely sure that your smart contract has no side effects

and uh if it's working as you expected and your code with the mock uh testing code with with the smart contracts work working well so uh and you have a mistake or whatever uh you have to find it outside you know with with the integration with the uh any dependencies so here we have uh contracts interfaces mocks uh and the uh most often uh the the main contract which should be executed uh is uh on the on the root of the contract folder uh we also have scripts uh what is scripts uh we'll not uh talk a lot about that but uh uh then you are building um a smart contract system with the many types of you know side jobs you can

implement all all side jobs into the uh into the script uh file so uh this will automate your uh your operations like if you need uh if you have to uh download something or you know change something uh automatically during the during the interaction with the hard hat you can implement all those you know operations here most often i'm not using that because uh my reapers are uh atomic most often like you know if i have a functionality for uh a doing b i'm trying to keep it inside with the all coverage with the all tests and for the integration i'm using that as a dependency so uh it is it is uh it's kind of micro services but there's no

microservices in the in in d5 development but uh you can keep the the repo structure so i'm not using uh sample scripts uh often but some people are using that because their repo is a huge they have many smart contracts huge uh dependencies and they are using that but the most important uh is tests basically uh the tests which you are running and this is simple uh chai test uh from the from the gs you can use the same uh logic with the with the typescript so uh here uh tests are written uh in the in the standard standard approach we have described it's a scope of different different tests

we can do uh we can do some some you know closures with the before and and after uh the test before if we need to uh to do some kind of preparation we have to be always before every every test every atomic test we have to uh be prepared for you know for some state we are not starting from the zero state uh probably we have to create the accounts deposit the funds on on those accounts and then you know do some kind of interaction before every test uh launching so we can do it um in a simple um approach of matcha or chai framework for the testing and each test has some signature you can you can write

the signature here like we have first test which is greater test what we are doing here we are we are um creating the contract factory which will actually deploy the contract so uh and in this test we are uh we have our smart contract greeter as already implemented we can look at this so the gritter has uh uh has a method which called grid right and uh greetings is an approach uh greeting and greeting changing here so uh grit is basically the external view function which is

returning the the internal state with the uh with the text information uh and the text information are coded into the into the smart contract right so uh the good point with the uh with the hard hat is uh you can literally debug your smart contract code same as you are doing that in in the javascript uh you can use console.log within the smart contracts uh it it is actually very uh important thing because uh for many um for many uh many other alternative approaches of smart context development you cannot uh look

deep into the into the you know smart contract what is going on inside into the internal functions or external functions you cannot find uh what's exactly going on but with the console lock you can you can literally print everything every operations and uh it's a good thing i really like to have it because sometimes sometimes uh you can find some issues especially with the computation with this with the computation you can make a decimal error somewhere and because of that your tests cannot be passed so you have to find where uh you accidentally did it or where your variable in correct state so uh yeah we can use

console.log because it's also a smart contract uh from the hard hat console.log and everything is printing um into the uh into the command line and so um yeah back to the tests our grid function is returning uh the variable with the with the grid right so to to run the test we have to uh we have to implement it uh we have to um uh call it as a a as gritter uh we have linker here and the linker works by the by the name of the of the smart contract so if you open the um the test again we are calling greater uh our main

contract also greeter we are importing it and they are they are connected you see right so uh what's next javascript is interacting with the contracts by uh by this by this name and uh we are deploying greater smart contract we are within the constructor of the smart contract we are uh setting up the variable and then um the the smart contract deployed we can uh call the um the grid and if it's equal to uh to what we uh set it up into the uh constructor into the deploy uh test passed so everything

is good uh within the same test we can also check uh something you know different uh we also have uh the uh change function which is uh said greeting we can ch we can change it and uh we can check it again that's uh you know everything works fine so let's just test it how easy it is so uh to work with the with the contract we need only three commands first of all we have to install all dependencies we have to install all dependencies it is npm install uh and we can easily check the dependencies here uh within the boilerplates we have um ethers and waffle

ethers works to to deploy uh the the contracts uh and the waffle is using to uh to create the different accounts interact with them we can see uh the examples later and we have some dependencies here like for for testings uh and uh for interacting with with the contracts so let's install them and uh deploy contracts and then run the tests it is very fast actually because sometime i i tried the chain link um workshops and uh uh sometimes i was waiting like four hours

to uh to install i don't know what what what what's happening sometimes if you have a mac version uh a1 uh core you have some issues with the with the dependencies so uh i have a one uh macbook so but i have no issues with the hard hat in any way which is also good so let's see the changes we have nothing here except node modulus which are installed here so we can uh we can interact with the with the hardhat let's uh call uh the compiler if you have some issues with a with a

smart contract uh you will find the the response uh during the complete uh compilation uh for example if if i will do something uh like which is broken the logic of of compiler i will find the um the response here let's try it uh let's try it for example um we are doing this let's do some something uh let's do something like this or this so uh we are broken our contract and uh look how her heart will show us um okay we have

one issue um we have to save the changes uh let's recompile it and right now it shouldn't compile because we have issues where we have issues we have issues uh here uh the gritter and this this row easy so you can easy debug your contracts and change it to to make it working so this is an example okay you see it it's working so uh you don't have to always compile because uh you know the compilation is basically creating the uh the artifacts which are using for uh

for the uh virtual machine for the tool uh tool uh to uh to later run the scripts and do some uh some some logic with with the smart contracts so uh and you can see the uh the artifacts here uh we have build info it's almost impossible to read because it's kind of you know many dependencies um this information uh can be easily deleted uh and uh by uh by compile you you'll build it again and we have some some wrappers uh some wrappers which are which is using for uh for uh working with smart contracts and yeah you can easily uh you can

easily remove all this information and uh compile again but most important is tests right so we have our smart contract already implemented we have a gritter which is uh returning the the hardcoded recorded variable and we can change this variable by uh set greeting so let's call the tests we have to have uh this test at least uh which is checking to prime uh two things i will comment this side sorry it's a basic thing but uh we have to you know uh understand the the the basic operations uh

those who understand that uh even if they are not blocking developers or even don't understand the blockchain but they know uh the basic of javascript or basic of web development they can easily onboard start com start interacting and you know increase their skills from without the the uh the threshold and threshold so um for me it was important all my team members who are from classical development industry they also came up for this and right now they are pretty experienced developers uh blockchain developers so let's do [Music] let's do the the hard cut test so right now we have to pass one test

and uh we see the the description of the test should return the greeting once it's changed and the test is passed so nice right so basically we we didn't deploy um anything i mean we just you know uh writing code uh without uh without the real blockchain we are doing uh stuff uh which is like classical programming and this is why i like uh i like hakata i like that it's simple what no one asks questions okay so uh our test what just happened uh what just happened um we deployed the gritter uh we called

uh grid and uh everything was fine so let's do some kind of uh kind of logic here let's add some rules into the ins into the logic let's let's change something i'm going to change the smart contract before deployment as you can see here anyone can set up set greetings but what if we want to have it as only owner we will uh we'll create the uh the modifier on the

owner and the only owner will able to set greetings right so uh we'll not do that because we have uh limited time for everything but uh uh the most important thing is here because with the solidity smart contract uh and the admin functionality uh you can find a lot of examples in open zeppelin but uh in the in the hard cut uh it's here we are working um only with one account so uh um unexplicitly the account uh who deployed this the smart contract created we don't we cannot communicate we cannot switch the uh account and who is interacting with with the contracts but we have to uh have to have a

ability to do that right so for that we have another approach we can before the test started we can basically import waffle and create several accounts for for our smart contract for example i don't know let's do it here okay here waffle is creating the several wallets and you see here we can create the one account like eoa account for uh for deployer one eoa account for admin if we need it like you know we we have

to uh differentiate them we can um create the account for keeper as as told you before uh yarn strategies they are automated so uh we can create the special accounts uh for test testing purposes which are working as a keepers and the other most often other account is a user like you know alice we can call her alice and yeah so uh basically uh here we have several accounts we can deploy uh the script from the deployer account it is implicitly uh going on here but let's uh let's make it more explicit i'm using another uh my code for uh for switching between uh between

accounts and uh switching between accounts uh is using the connect uh connect method so all uh smart contracts they have connect method and you can change uh the the account who is interacting with the with the uh with the chain so we can do it here okay deployer automatically deployed um the the gritter right but right now we have to we have to check that alice is able to call a grid function so we have to call connect let me see

one more time connect i know it's boring uh alice alice is connecting to the contract and calling grid should it work or not who knows should it work i have no idea let's try uh and i never tried uh in this example uh so we changed the smart con we changed the the testing environment right we haven't uh

changed the uh the smart contracts uh we only change the way how uh alice is interacting with the contract so we don't have to compile but then we are calling tests the compilation is automatically starting because it's tracking the code changes yeah you have questions ah uh no it's already imported because uh all dependencies are uh hidden within the hard cut environment so they they're all inside uh you can basically check the uh the look uh file and see all the the dependencies here and you will find uh um everything we already have

experienced with is it's uh it is inside so there is no uh there is no uh forcing you to you know to to switch the habits uh but yeah there are also some some good things like uh waffle to uh to create their accounts and uh uh okay let's let's we we haven't changed the contracts but we um we added some logic into the test so we have to uh so let's try compile right it should say nothing to compile of course uh we we did we didn't we haven't implemented any changes but uh let's call the test and uh test passed what does this mean it means that anyone i mean alice is able to call the greeting function right

most stupid mistake uh developer can do is uh allowing uh for anyone for any external accounts to use the admin uh methods right uh it's easy to check here by the same uh by the same approach um let's imagine that seed greeting is an admin function right we made a mistake uh with uh with a smart contract it's not only owner it's not only admin it's just you know we forgot about that uh modifier so we have um set greeting but it it should be admin only and to check that admin only can do that we have to explicitly connect

check that it works and also check that any other account cannot do that uh but by the same logic we have to connect and then call let's do some short break like uh three minutes i i need to to drink the water and uh uh try to to to uh play with the with the with the accounts if you have any questions you can ask uh again

what in this case they could get the world because and you know i don't have to write even more code for regression uh of course i need several accounts at the same time so the stack of sugar is pretty easy to use because you can see the area it's the same it's basically wrapper on

on existing existing frameworks so uh here you can you can use any um any framework you already have experience with to generate accounts for me it's better of course in sleep development there are a lot of steady sugars for the same thing so it's just the question of taste or question of dependencies i i don't know how uh how much uh uh unnecessary information i'm you know opposing if i'm using another framework so it's a basically a question of choice uh within generation of the accounts there is no magic at all just you know

uh priority so uh actually not probably but because he phrased the uh more fundamental than the private key because private key is coming from which go about is the public end address right so all these things are happening here and uh never there's one thing never use those accounts into the main because uh those things are the communities so those accounts already known for for anyone so uh never use those accounts uh for for maintenance uh or even because sometimes on the desktop you are checking the real cover of the protocol when somebody

can you know influence influence so okay we have it here uh what i'm going to show you uh also is that we have only one smart smart controller here right um what to do if you have uh how to link the another contract uh and we actually have it because we have mods and if you look at remote smart contract can be implemented as you know a production rate smart contract but if you're gonna if you're to check that your logic

and the real logic are same within certain cases you can you can create the greater model most often the balance of the coin and then say hey you have this balance right so uh to work with another contract you can call um greater model and let's implement and run again so here we have a greater contract here we have mobile contracts so you can deploy uh as many contracts as you want in the in the test environment and uh you're deploying

one you are just one second and then you can compare both uh it can be useful if you're gonna check the safe of one contract and another contract uh are they at the same state if you are calling construction right you know if you're gonna construct it you have only one way to to reach one state uh your real account can have you can use some dependencies right uh and uh if you're gonna check that they're actually the same it's just you know a hypothetical example of how you can use it but basically you can check to contracts that they are working the same way uh and again you can just um i can just hold tests

okay so we have uh one scope we have another scope and a look at the time how they are how much time it is it is less than a second this very fast execution we can do a huge logic inside to be very fast guys have another half an hour uh let's let's go into the uh how we can uh implement the strategies here uh which which interfaces we have to implement and uh if you have enough time but we have only one chance to do it is the most like we can basically build some strategies

what kind of strategies we can we can see my case is we can implement the strategy we already already seen here uh as the most this one is uh we can do compound statement right so uh what we need for that we have to open the uh any repo with the already implemented audited statement contracts uh let me find the the contract i know i mean implemented okay here

and taking so we have taken contracts and uh the staking contract has only one on the one contract right and some interfaces dependencies like if you are taking token uh you are basically uh creating another token which is s like s token original work in this block somewhere so you are looking to provide some reports which can be uh taken by uh by calling function harvest and here we can see the stake in smart contract um we are we are inheriting uh year 70 because it can be

a part simple strategy uh if you are safe talking is that your spending token is inherent uh it means that you can easily change the account who is taking because you know because you can transfer so and nothing to change here and of course we are implementing some uh some methods for the uh for the talk we are mentioning some uh it is smart contract which is generating money

which can be sent back to the user and uh in our case taking this smart monitor uh if you if you want to see an example and provide some uh some feedback about mistaking you can also download it here or clone it we can easily edit it into our hard cut it's already covered by tests so we can see the example one example of the data here so you can you can you can uh as well and uh how this second functionality is implemented uh here we have uh depositor which deposits in funds

and we have we have one variable within the within the contract which is epr uh it should be inside the epr and we have internal um internal wearable which is epr i cannot find it right now but it's inside with this epr uh for any amounts

deposited for any amounts of deposits we have a fixed um apr for uh for user why it's important that here we have epr and uh how we can implement the strategy to uh to magically uh bring it as the eq is that we have taken uh rate here and our strategy can just automate the uh two operations first iteration is uh uh is state and harvest so harvest is uh by drawing the rewards and the same is uh increasing the amount of the of the token which so the compounding uh effect we can

reach if we have a strategy uh which is using users us uh to take them into the second smart contract and then after a certain time we are setting up other strategies we can set the uh the interval when we are currently in this approach uh with the method uh we are harvesting awards and then calls uh stake again so basically when you are implementing a strategy uh you have to just create the mocking smart contract for staking uh it's easy you can you can add okay we have it here

we can create the contract uh second the main the main methods we have to use we have to use uh again safe and harvest right now so and we have to map them into uh into the our strategy like prepare to return means harvest right sorry have you lost no it's okay so prepare return we are pulling we are calling harvest

right because harvest is basically the method of the dub which is uh sending back to the caller which is sending back the rewards and uh for another uh we have adjust position and the great position of force for the adjustment yes so basically we are increasing the balance in the staking and the last question is about the liquidate position so

easy right so our contract have to use the existing interface because we don't have to use even existing existing dap for that we can just you know mock the all functionality within the interface within the fake harvest faith and safe and faith safe and then we can write the strategy which is working with this approach because then you are deploying that and you are keeping the interfaces you are keeping everything it will be just automatically integrated and those side

effects of course there will be some uh some issues with the uh if you are writing the tests uh for exact uh i don't know for example api apu you know like those type of things can be can be wrong uh then you are deploying on the main head or on the test net as a part of the real environment but uh you have to be sure on the mocked uh smart contract on the mob uh that your strategy is working as expected and so here we have to create uh we have to create the smart contract which is uh which is up let's call it up uh

of course we have to change here uh we are not inheriting anything we can hard put in here inside and uh you know add all methods inside basically we have to keep the signatures of the of the methods harvest is taking the urine [Music] for a few hours uh i hope

i hope you uh you understand the basic uh basic logic how to implement the contract basically we have to implement the bolt with the with the main approaches with the main methods like uh as we talked before approve and the deposit and the way to go all and price to share and after that we have to map the uh you know the the interface functions the strategic premise functions also how uh we have to integrate we have to um we have to communicate with the double right so uh we already uh saw the example within the second contract the setting has saved unsafe

and the harvest and our contract is just the strategy which is mapping one to another and some uh some automatization functionality from the keeper oracles because there is no way for smart complex to be called by nobody there should be some external external entity who is calling the contract of course in some fields but automating the the operations so guys uh this is uh this is how uh strategies are writing this is how um we can we can start the the development in d5

and uh this is how you can start making money even with the with the building strategies and uh this is a lot of ways of creativity because as you can see we have uh we have exponential explosion of uh financial growth of different types of dots farming services learning protocols and i'm absolutely sure that anyone can you know can find within a couple of hours uh the strategy which can be uh which will make sense to be implemented and then uh suggested uh for the dog proposal to be accepted and you know generate money so uh thank you if you have any questions you can ask yes

any other questions okay guys thank you so much [Applause] yeah guys see you tomorrow tomorrow will be interesting final discussion you