New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Aave 101 on L2

ETHGlobalSat, Oct 9, 2021, 12:00 AM

Transcript

hey everyone uh welcome to the ave 101 for dev specifically focused on l2 so uh for those that have seen my previous top workshops this will be pretty similar but i'll mention a few things around uh l2 as well specifically polygon market so for those who don't know ave is what we call liquidity protocols that means on one side we have depositors and depositors deposit into the protocol they interact with the contracts and they earn interest on the assets they deposit uh based on various protocol parameters and on the other side we have borrowers and borrowers also interact with the rv protocol they earn certain interest rates uh and they can pay back those those loans uh whenever they want so that's that's the special thing about liquidity protocol is that both depositors and borrowers will interact directly with smart contracts uh so far the entire protocol has more than uh six billion dollars of market value uh with the tvo hovering around just above 5.6 billion dollars as of this morning and we recently released uh two new markets the amm market which is an automated market maker market for balancer and uni swap tokens lp tokens which i'll go through in a second and also we just released the polygon market so the polygon also known as matic is the l2 or layer 2 market that i mentioned and so far it's already amassed nearly 10 million dollars of market size very quickly so the main protocol features of rv that you'll be able to play with as developers is earning borrowing credit delegation flashlights and of course the governance features most of these are available on l2 except for the governance features at the moment but we'll go over them each individually all right so for the earning features of the protocol if i was explaining to a five-year-old i'd say that you let others borrow your money while you're not using it if i was explaining to a 15 year old i'd say that you deposit your money and you earn immediate interest on that amount and you can withdraw at any time and and in a defy or crypto native way what we actually do is we tokenize your deposit as a tokens and the account holding those a tokens accrue interest based on the protocol parameters and demand things like utilization or just the type of collateral that you've deposited uh also a tokens are one-to-one pegged with the underlying so that means if you deposit 10 die you receive 10 a day and you can always redeem the 10 a day for 10 day so in graphical form we have depositors they deposit into the protocol and they earn the interest in return as a developer uh these this is the sort of an example of code that you write essentially you say what sort of asset you want to deposit the amount of course in way units on behalf of is we'll go through that in the credit delegation part but for now you'd always send it as message sender so yourself the user that's sending or depositing that amount and the referral code uh which is uh currently on hold as part of our referral program but that should be reconfigured soon under uh the new decentralized governance so the first step you take is you approve the lending pool to pull the amount or to deposit that amount from your wallet into the other protocol once you've made that standard approval uh call then you'd call deposit on the lending pool you can see here it's called letting poor deposit asset amount on behalf of a referral code so the last line is the important bit pretty simple pretty standard and you'll see that throughout the protocol uh that you will call all your functions essentially on the lending pool contract next uh if you want to withdraw your a token so let's say you want to redeem the underlying uh erc20 tokens uh here the same sort of deal you just uh on the letting pool you call withdrawal and then you input the asset the amount that you want to withdraw and the two address so usually that would be the person that's calling this withdrawal method but you can also send it to someone else or a different account the unt minus one that's an old way in solidity to basically say everything or the highest number possible um and will automatically withdraw uh whatever amount you've deposited uh in the latest celebrity i think it's uh something like type type max but you can see the you know documentation we've updated that so the next part is borrowing right so if i was explaining borrowing to a five-year-old i'd say that you borrow money whenever you need it if i was explaining to a 15-year-old i'd say that you're borrowing money and depending on how much you have deposit in the system you can pay it back anytime and to d5 users we use your a tokens that you deposited as collateral and you can borrow any of the supported assets and remember that your borrowing power is per market so if you deposit it in the amm market you can borrow within the amm market and similarly with the polygon l2 market if you deposit in the polygon l2 market you can only borrow you can borrow assets in the polygon l2 market and you have either stable variable interest rate in a diagram form you can see here on the right hand side the borrower can take a loan the important part here is that the depositor the the positive and borrower are the same person or the same address and they've deposited assets therefore they've created some collateral value in the protocol and as a result they can uh take out a loan by calling certain methods on the protocol and those methods would simply be the the last line here is important on the landing pool you call borrow insert the asset the amount the interest rate mode so that's either stable uh debt or variable debt the stable debt is uh for for most uh intensive purposes it is stable at the time that you take that stable debt uh or take that stable interest rate debt and the variable interest rate uh is sort of like a spot price for the interest rate and that can change uh depending on utilization sometimes cheaper sometimes uh costs more and then of course referral code and on behalf of address as well and the same thing you can swap between and variable and interest rate debt depending on you know what debt you currently have you simply call swap borrow rate mode on the lending pool inserting the asset and also the interest rate mode super simple one thing to keep in mind here when you do that is that if you've locked in a really good stable interest rate and then you switch to a variable interest rate then you want to switch back to the stable rate when you switch back to the stable rate that will use the current stable rate so you may not get that really cool or really good stable rate that you maybe had locked in a long time ago so just be aware of that especially for your users in case they don't quite understand that concept yet okay and to uh i mean once you've borrowed you can also repay back that loan at any time pretty simple you call the standard approval method for the lending pool so i can pull those assets and then call lending pool repay and insert the asset amounts interest rate mode and on behalf of address as usual the next feature would be credit delegation so explain to a five-year-old i'd say that and let other people borrow the money uh for a 15 year old it's deposit to earn on rv and you can earn extra interest or funds by managing your own loans to other people and explain to a default crypto person is that essentially you give others access to your credit line by depositing collateral or funds in the protocol you approve a user or certain group of users to draw a credit line and then you let them draw up to that credit amount whenever they want to so in in schematic form we have the depositor let's say the credit delegator they'll deposit assets or funds into the protocol and they'll earn the relevant interest and then on the other side uh the borrower who's a different person or different address will be able to take a loan in in various assets that the delegator has enabled for them so in code how you do this firstly you have to decide what type of depth you want the uh you want to delegate or let's say from the perspective of the delegator um so they'll either want to delegate a stable debt or variable yet um so make sure that's uh you know quite obvious to the user and they have a choice to dedicate a certain type of credit uh so firstly you get the correct address of that debt token because every uh let's say every reserve asset has a different stable debt token and a different variable get token address so make sure you call that on the right asset next uh let's say on this second to last line you'd take the let's say in this case we're doing a stable debt token so on the standard debt token you caught a pr called approve delegation and you'd insert the borrower and the amount that they're allowed to borrow that's the that's the maximum amount of credit they're allowed to borrow and and the same thing with the variable depth uh you just call approve delegation again and set in the borrow borrower and the amount in way uh so the important part here is that you can you can delegate uh sort of like as much credit as you want to multiple users uh and those borrowers will only be able to borrow the credit amount up to the amount that you have delegated to them but if your credit line uh has has maxed out and then some of those users um credit delegations may fail uh because maybe maybe uh let's say you've delegated you have your your delegation power is a 100 day and you've given four people 50 days to borrow and two people have maxed out uh on 50 day borrowers that means a total is a hundred days that means you've maxed out the delegator's borrowing limit so therefore the two other delegates or the two other people with credit lines they won't be able to draw that credit so that's something important to to keep in mind and consider all right so for um borrowing so this is on the perspective of the person or the account that has the delegated credit line is that similar to a normal borrow they were just on the lending pool they would call borrow and they'll say the asset amount interest rate mode they have to make sure that they know which type of debt you've delegated to them and insert the referral code and on behalf of so here's where on behalf of is quite important because they will be borrowing on behalf of the credit delegator so the person that gave them that credit union so the next important step would be repaying so similar to i guess normal borrowers is that you call repay on the lending pool uh so the asset that you want to pay this is the reserve asset they want to repay the amount they want to repay of course the interest rate mode so whether that's stable variable interest rates and the delegator address um so that's the original person that delegated that credit line to that person um so anyone can really uh call this free pay method um to repay someone else's [Music] delegated debt uh which so you can probably create some interesting use cases from that gamify in some way maybe you can help other people pay back your debt in various other use cases like that okay so next is flashlights so if i was describing flash loans to a five-year-old i'd say that it's free money you have to pay back media immediately if i was explaining to a banker type person or a traditional finance person it's an unsecured essentially an unsecured fixed term loan lasts about 14 to 15 seconds which is the block time on ethereum with a low fixed interest rate of 0.09 percent uh the bank in this case the bank would give the ethereum or the rpa protocol you can always collect that expiry so at the end of that block it always collects it um so there's really no risk and on a technical defi level uh it's an uncollateralized loan uh supplied by the the protocol uh where the amount borrowed plus plus a small fee needs to be repaid by the end of the transaction um and the reason why you want to do this is because you can execute nearly any code between the time that the loan is taken and the time and the when it's repaid at the end of just that same block and if the loan is not repaid at the end of that block the the state of the chain just reverts um to the previous state of when before the flashlight was taken out so that's quite special and specific to to crypto uh it doesn't really have a real goal analogy to that um so to explain it in a schematic form uh hit this as an example it doesn't necessarily matter what's actually happening below the purple line but the main thing is that everything above the purple line is what happens definitely happens on chain so that's where it would cost a certain amount of gas or transaction fee for the user to call and then their smart contract would do various actions uh and then if that smart contract at the end of those smart contract actions the flash loan is repaid repaid including the debt uh sorry including the fee flash phone fee and then everything proceeds as normal everyone's happy there's no failed transaction however if the flash loan and the fee is not repeat repaid back by the end of the transaction then everything below the purple line just uh reverts it's like it never happened on the blockchain and then the caller just incurs the the gas cost for for evaluating those that code um so this is an example of what a flashlight looks like on each scan uh the important part here not so much details it's more that we've conducted multiple transactions or multiple let's say state state changes in one transaction and um uh there there wasn't any capital constraint on making this call so here we're moving making our vault we're moving uh funds around closing down involved paying back debt and things like that um and you know there's many different calls and the main thing is that this whole happens in one transaction and the user didn't need to have uh this money to begin with to close down their debt and to move the debt to a different vault another example is what we call like a decentralized exchange arbitrage so essentially buying uh something for for a low price or somewhere and then selling for a higher price somewhere else so you know normal arbitrage important thing here is that uh there's no uh capital constraints um so you know you could do a arbitrage for millions of dollars uh if you if you find that opportunity and specifically uh for version two we also have batch flashlights what that means is that you can uh flashlight multiple assets at you know different um debts debt types interest rate mode types or different amounts all in the one transaction and then you repay them as necessary so if you're developing uh with flashlights it's a bit more involved you need to have your own smart contract deployed um and essentially what you need to do is you have your flashlight function you set up all the relevant parameters for the flashlight so these are some examples parameters so here the receiver address is is this contract uh so that's the contract that will receive the uh the flashlight amount uh we create an array of assets uh so that is the all the addresses of the reserves that we want to flash loan uh it would create uh the amounts of each asset of course you know the asset position zero is indicates the amount at position 0 in the mouse array and same with the modes array right so the mode is whether you want to have no depth so that's a normal flash load or if you want to do a stable variable uh deck and that that's another new feature in v2 an interesting use case in that you can have uh debt incurring flashlights so what that means is that uh you can flip around the traditional way of borrowing so normally as i've explained if you want to borrow you need to deposit collateral in the system first and then you have some borrowing power if you do get incurring flash lines it's reversed so essentially you get to borrow the funds do whatever you need to do and then you can uh then if you've deposited let's say some sort of profit or that that same flashlight into the system then that can serve as collateral and the main use case that i've seen of debt current flash loans is essentially leverage so you flashlight some amount then you redeposit it back in the system then maybe you have some borrowing power and you can borrow some more and draw that credit line to you know essentially leverage long on some asset all right and then you have the other standard parameters on behalf of uh parameters that you can pass into your own function that's in the next step and a referral code and then so on the lending pool you call flash loan uh the flashlight function on the lender and then you pass in all those relevant parameters what will happen is the lending pool will do some sanity checks and if everything checks out it will then call the receiver address which in this case is your smart contract and it will execute the execute operation function which you see here and with all those relevant parameters passed in and once your contract reaches this line or this stage it essentially means that it's it's good good to go um you have the funds uh in in your contract and then of course you do whatever you need to do and then the change in b2 is that instead of you sending the funds back to the lending pool this time now the lending pool will pull those transactions it will pull those amounts from your contract so make sure that you have this little thing where essentially you approve the letting pool support those amounts if you don't have that then your transaction will fail and everything will get reverted and it's wasted time and you pay gas for that so make sure you have that uh the other thing about v2 is that now you can use flashlights within the rv protocol itself so v1 you couldn't do that but now you know you can use flashlights yeah throughout throughout the rv protocol all right next big feature is governance so essentially it means for five year olds that belongs to everyone if i was explaining to a 15 year old it means that anyone who owns ave uh can help govern the protocol and for a d5 person it's a path towards decentralization where token holders can vote and govern the protocol from asset listings protocol upgrades so essentially everything will eventually be done by uh the governance process so here's a little schematic of it i won't go through every little bit uh but the important part is that the rv token holders uh including you know just the raw rba token holders but also the token volumes out of state into the safety module which i'll go through uh able to govern the protocol and vote on certain changes and those changes and go through certain uh processes of what we call a short time lock for long time luck you can have a look at their documentation on docs.rma.com developers or slash governance to find out more about that process but essentially this is an example of the governance process uh charlie from the curve team uh wanted the curve token to be listed on rv so he had made a proposal in the governance forums with the reasoning and some links the um you know there's discussion on the forums and then julian who's also part of the curve team also posted on twitter to essentially ask are they holders to delegate proposal power so they can make this proposal on chain so they did this and you know some rv holders delegated the power so that's one feature of the other governance as well you can delegate just the proposal power and separately from delegation of the voting power um so eventually the curve team were able to get enough proposal power to make progress on chain and then uh that's how the curve token got listed on the ad protocol uh and the screenshot's a bit old so there's uh you know eight million dollars with liquidity um but yeah now uh same thing has happened with the bannister token and various other tokens are still going through the uh this same process and that process is essentially an off-chain process on the governor's forums first the proposal creation on chain and then voting on chain and then the proposal was eventually executed and you know that's that's when you able to use it within uh the protocol so if you're looking to hack on some governance related things uh the the the uh here these are some examples of some features you could uh have a play around with so delegating as i mentioned voting you can delegate voting power and proposition power both together or separately so proposition power is the power to submit proposals right because there's a minimum threshold of uh let's say are they token proposition power that you need so to do that super simple just on the governance token in this case the rv token you just call delegate and you delegate to whatever address if you want to submit or make a vote you just simply call submit votes on the other governance contract and insert the prose id and whether it's you know true or false for your supporting or not supporting it and the next big part of the governance is the staking safety module essentially what it means is that the safety module becomes a backstop for the protocol so in like a protection fund for the protocol in case something happens to the protocol since since releasing the safety module or the staking staking part of the safety module uh it's amassed more than a billion dollars worth of just you know staked ave token then also there's the balance lp token that you can also stake and that's more than 300 million dollars so it's quite a lot of funds that are being staked to help protect or form that backstop for the protocol so if you're looking to integrate this somehow uh firstly what you do is you get whatever token uh that can be staked at the moment it's rvs open and the state army token you would approve that token so that the lending pool can can pull that token and then on that token you'd call stake uh pretty simple and then that will send it to the safety module and you'll start earning interest uh when you want to claim uh the rewards or the interest rewards you simply call claim rewards uh on on the on the on the token and then when you want to withdraw firstly you have to call the cooldown so the cooldown essentially activates the cooldown period which at the moment is about 10 days or exactly 10 days and then after the cooldown period has elapsed then the user can redeem and essentially take back their stake and they have uh currently a two-day period to do that if they didn't redeem it within two days and then they have to call cool down again and wait another 10 days um so keep that in mind all right so just uh to wrap it up uh i'll quickly go through some examples of some other hacks and projects that have come out of some hackathons that we really like and support just uh to give you some idea of what could be created so d5saber.

com uh underlying a lot of their you know d5 management tooling uh flashlights and they make heavy use of rv flashlight specifically um so they're a really cool project and they support you know many different p5 protocols besides rv for a combo is a really cool app that makes it really easy for non-technical users to uh utilize rv flashlights and they just connect essentially lego blocks together of various protocols to to create transactions which is pretty powerful you earned finance in the version one a-link vault they used our first the first version of credit delegation and they enabled their ailing fault to uh to essentially earn higher yield by taking advantage of credit delegation methods and finally we have avigachi which is really cool they marry i guess nfts and d5 so that you can have interest bearing entities within the game and you know as you play the game you're incurring interest so you're earning interest uh so your avalanches become more and more valuable intrinsically valuable which is really cool to see all right so if you want to find out more hit us up on discord or on the hackathon discord um also check out our dev docs they're pretty elaborate so hopefully they answer most if not all your questions um also our governance uh forum and we have a ton of other docs so our documentation portal uh where you can see links to governance and thanks to the economics risk and many other things and that is all i have thanks for listening and good luck with your hacks thanks

Automatic transcript — names and jargon may be misspelled.