Aave Labs 🛠️ Deep Dive into the GHO Smart Contracts
ETHGlobal·Wed, Oct 9, 2024, 12:00 AM
Join Emilio Frangella from Aave Labs for a workshop titled, “Deep Dive into the GHO Smart Contracts.” This workshop will be the best opportunity to dive into the GHO architecture, implementation and integration with the Aave protocol. With a week of open learning, hacking, and workshops on all things stablecoin, as well as $75,000+ USD in prizes, LFGHO is a great way to connect with the community from around the world, and help shape the future of Ethereum and DeFi! ----------------- Follow us: https://x.com/ETHGlobal?s=20 Check us out: https://ethglobal.com/ Email us at: hello@ethglobal.com
Transcript
[Music] let's start from the beginning so as I mentioned before go is the native stable coin of the a protocol and of the a governance is pronounced go uh so the age is muted um we uh in wanted to propose to the a governor to introduce an a native stable coin for a variety of reasons uh Native stable coins have much higher Capital efficiency uh so uh with the other protocol like there is the in inherent complexity of having the need for suppliers to step in uh to provide liquidity and therefore for borrower to satisfy the borrowers demand and this is something that is um in immediately uh circumvented immediately um uh satisfied with the possibility of using a native stable coin the complexity there which is a completely different topic is actually being able to scale uh such stable coin especially when a new stable coin is launched like uh um behind the the possibility of and the capability of scaling a stable coin there is always the need for creating um use cases for the stable coin which actually incentivize people to use it and to hold it uh so I always say that like the the first true use case for a for a stable coin when immediately after after it's launched is the capability to SW to swap such stable coin for other stable coins so at the beginning when the stable coin will not be um widely available on different venues like decentralized exchanges uh centralized exchanges off ramps and you mean when you generate the new stable coin um right off the butat uh created stable coin those capabilities like that other more mature stable coins enjoy like again of ramps and uh trading pairs are not available right so what what users typically do is they uh mint the stable coin through the meanings of borrowing on the other protocol for example uh to actually um be able to use use disabl coin to achieve their own goals so I don't know uh trade on other venues rather than leveraging a certain position and usually what happens is that to be able to trade with um convenient with convenient fees and convenient um uh slipage they usually swap to other stable coins uh in order to be able to access the wider Market that the stable coins usually have so for example USD DC uh what happens is that many people actually swapped their debt from usdc to go because go was cheaper to uh uh to generate and other people actually borrow it and immediately SW go to other stable coin to trade on other venues for example so that's usually the first use case that you can create for a stable coin and to do so sustainably uh it required quite a lot of work on on secondary Market to Pro to uh structure the liquidity in a way that is able to absorb uh the cell pressure of users generating such stable coin so uh when we thought of creating go uh we also uh started thinking about possible use cases possible different ways of scaling such stable coins and those actually those thoughts actually kind of shaped the architecture of go itself which is what we are going to explore uh right now so I don't know if you guys can see here let me oh no I don't want to do this why did they do this let me see if I can rotate yeah okay so like if you can see this diagram this diagram highlights the architecture of go uh so the architecture is quite different from other uh stable coins that are the centralized stable coins that are available in the market uh the idea behind go is actually not to um strictly correlate the stable coin one way of generating it which could be for example over collateralized borrowing but actually make that as as much flex flexible as it can be by giving the token itself and the governance the capability to allocate uh the creation of such table coin to different entities okay so what happens in go is that uh we introduce this concept that is called facilitators so uh different entities different protocols can have allowance to actually mint go to a certain amount that we call bucket capacity and uh when such capacity is reached those entities will not have the possibility to mean further until the governance the other governance decides otherwise so uh the goal here is to have the a governance in control on which entities are allowed to generate go and in what size that is the idea uh when we uh when go was launched when go was released and and activated by the other governance the first of this kind the firstc facilitator was the actually the a protocol so the a protocol is at the moment the first and only place where it's possible to generate go but uh uh there will be other ways in the future which might be future versions of a might be other uh protocols completely different uh from the other protocol it might be as you can see here in the diagram uh rwa based uh system so where you have tokenized rwa backing the stable coin as collateral you can have protocols that actually uh generate the stable coin using as collateral delta neutral uh positions uh you can have part of the stable coins backed by different centralized entities so other centralized entities could uh generate part of the goal to to maybe for example help uh sustaining the peg against the the real world assets and so on and so forth so uh the architecture of go itself is very simple but I believe very powerful because it gives the a governance all the flexibility in the world to actually be able to manage and to scale the stable coin as more and more your case appear in the future so as I mentioned here in the the as it mentioned here in the in the tech paper uh the first facilitator is the other protocol uh what's interesting is that the other protocol was not originally designed to be able to generate a stable coin uh which is which can be basically um assimilated to a to a synthetic asset so uh the other protocol doesn't natively have the ability to generate anything that is not actually previously supplied by uh by liquidity providers uh so we had to um kind of work around certain limitations to be able to support uh go within a the protocol I will show this kind of limitations uh later when we look at the code uh so because I because the the go stable coin is generated on the Fly there is no supply side on the other protocol so it's not possible to supply ER go to the other protocol it might be possible to supply uh go to other markets where go is not generated natively so example um we at aabbs are currently working on possible implementation of cross chain go which will use uh ccip uh from chain link and this will allow the other governance to bring go across a variety of networks all the networks where a is deployed and uh ccip supported and by doing this it will be entirely possible to actually list go as a normal asset on other markets for example polygon or Avalanche or arbitrum uh with an expected uh supply side for liquidity providers so liquidity providers could for example U borrow from the Native Market where go can be minted on ethereum move uh the go so minted to polygon and Supply polygon to Arbitrage interest rates for example that's going to be entirely possible and it's also going to be entirely possible to have other facilitators that actually mint natively on other networks so there are this this kind of architecture already gives this flexibility where you the a governance can really decide whether or not the a can be the the the go can natively be generated on what have a market or actually just listed as a normal asset where it can be supplied by liquidity providers uh the borrowing uh what's important is that the contracts that we are going to um explore shortly are the contracts that allow native minting of go so are those are the contracts that are actually being used on the V3 ethereum Market to generate uh go um natively and the borrow again in markets where go is listed uh natively where it can be meain natively is the borrow action that actually generates the go and transfers that go directly to the borrowers against a certain collateral while in markets where it will be listed as a normal assets for example another Market on polygon those will follow exactly the same Dynamics as any other asset or any other stable coin where users borrow from liquidity providers and pay interest to to liquidity providers uh uh that's pretty much hit it this diagram uh kind of uh explains very simply how the borrow process happens so every time someone borrows on the other protocol V3 on ethereum like there is a check that validates if the borrow the if the bucket size is reached if the bucket size is reached it will not be possible to meet any other goal uh if it's not reached it will mint the asset and update the facilitator uh Bucket Level to keep track of the additional amount that has been generated through this particular facilitator uh one interesting aspect of uh the native integration of go on the av3 market is that uh which is also one of the mechanism for that guarantee uh that go can always be generated and redeemed at $1 is that the price on markets where go is natively generated is always $1 so the Oracle that actually provides the price for go always it always has uh a a price for go of $1 and no matter what the price of the stable coin is on the market this basically allows on the long term to maintain the peg of the stable coin even though there can be oscillation like on over the short term uh because like whenever the asset is below Peg there is an incentive for people to actually buy back the token and repay their debt as a profit or for position to be liquidated for a further profit and when the asset is above P there is incent for borrowers uh to to Mint more goal and to Arbitrage the the opportunity that is available on the market so this is also another interesting aspect of uh the integration the native integration with uh the other protocol of the go token uh the interest rates of go are also decide by the governance even though uh we are currently developing a an a kind of Novel mechanism for um Dynamic borrow rates for go which hopefully should also help maintaining the the the stability I just had um on Friday I did a talk on on the topics which is uh the explains basically the the the strategy that we are using for uh that we will be using for uh the managing the go interest rates rather than being governance controlled um another interesting aspect of the a go integration is that um for those of you who don't know like the other protocol as one component is of the other protocol is called the safety module uh the safety module is supposed to be kind of an insurance F fund for uh the a protocol so if there are large um insolvencies because of Market um illation which could leave B bad depth or because of I don't know a technicial issue that might bring bad de to the protocol uh then the safety module can basically be used uh with the assets that are provided being sold on the market and used to repay the bad Dept until now like the safety module has not been used because the other protocol thankfully has not incurred in any meaningful depth since in meaning meaningful insolvency since the Inception but the mechanism is there so part of the integration of go with the a protocol is that it allows participants uh of the uh safety module to actually borrow go at a Discounter rate compared to the nominal rate where other users uh borrow so uh the way it works is actually there is a threshold uh for for each a that you can of of go that you can me discount so I don't remember the current configuration honestly I think it's 100 go per every a apply to the um to the safety module something like that so uh to calculate the discount there is a threshold uh that depends on how many a that were supplied to the safety module and also a discount rate that actually provides uh the amount discounted compared to the nominal rate that normal users that are not providing to the safety module are are paying so here are the formulas for the calculation those are very simple this actually just a weighted average uh I will link later the the URL of the of the TCH paper and here is a definition like there are a few example also of how the interest rate considered the discount is calculated here like there are bit of formal definition of the discount I will not go through this because take a a bit of time but they are very simple so pretty easy to understand price Oracle kind of describes what I already said before uh which means that the the one go is always fixed at $1 within uh the other protocol so I think we are already quite far away in the the workshop so I will go quickly through the code uh I would go first explain a little bit you guys can see the code right and the on the screen yes perfect uh so uh I will describe the code quickly starting from the go token contract which is honestly very very simple it's just an ESC 20 token with a few um interesting uh things uh as I mentioned before there is uh there are the facilitators so here the the this mapping here tracks the facilitators that they have a governance list within um within the uh the go um within the go facilitators uh there is also those are also kept as a list for to give the possibility to query on chain uh we can see here there are the mint and barn function which are only accessible if um a certain asset is a facilitator so like any facilitator is not listed by the a governance that is not activated as a bucket size of zero so if someone tries to meet the the go token and its bucket size is zero uh the meeting will not be allowed so the it will reverse here with this particular error otherwise the meeting will be allowed otherwise if the the the address has an allowance has a bucket SES and the Bucket Level is not crossing the bucket sides then the meeting is allowed and there is a very normal uh meeting process with an an additional event that basically tracks the updated level of the bucket sides of the facilitator burning is exactly the same thing uh it checks like what's the Bucket Level it uh subtracts the amount that is being burned to the Bucket Level and then emits exactly the same uh event as before uh the ad facilitator uh it's this is a permissioned function in the sense that there is a specific role that need needs to be satisfied to be called this function which is the facilitator manager in in the in this case like in our case the facilitator manager is the other governance so only the other governance can call this function here and what this function does is very simply just uh get the structure of the of the storage related to the particular address update uh the the capacity and the and setting the label for the facilitator add it to the list to be able to track and the mid an EV very very simple remove does just the opposite uh action of removing and setting the values to zero removing from the list and then uh set the bucket capacity it will set how much the how much uh is the here it checks if the facilitator exists by validating the label so if the facilitator has a label um then the facilitator exists and it just sets the the bucket capacity to the amount that is uh passed through as a parameter and then a few Getters to just get access the the data that I just uh I just mentioned above so that's pretty much it uh the rest is completely standard ear2 implementation it has like a permit uh it supports permit for uh um gasless approvals and I would say that that's that covers pretty much everything there is to cover about the go token I will go quickly through the implementation within the a protocol and in my opinion is more interesting so uh for those who don't know uh the have a protocol uh the have protocol V3 uh tokenizes the positions of the liquidity providers so whenever you apply an asset to the other protocol you get a token in exchange that is basically a a representation of your deposit We call we call these tokens a tokens and the same happens with the depth so if you take a out certain uh token as a Deb using your collateral you will receive that depth and there is also you will also receive another token that basically tracks your debth balance uh this token is the de token specifically is not transferable because otherwise you would be able to transfer the uh your Deb to someone else and in the particular case of devb tokens is mainly used only for accounting so it doesn't have any other function is just uh the protocol using uh using it internally to account for the Deb uh the part the particular um the interesting thing about a is that they increase in Balance over time so uh depending on the interest that is being paid so if you supply today and 1,000 I don't know uh usdc and uh throughout the year you have an interest rate on 10% after a year you will have 1,100 uh usdc actually a little bit more because it's compounded but uh that's pretty much how it works now uh for the go implementation spe specifically the interesting thing is that because there is no uh supply side so we don't want people to be able to supply go to the other protocol what happens is that and we don't have an act actual support for this particular uh capability within the a protocol what happens here is that we basically forbid people to supply by reverting the operation of meting so all the operations that uh are usually for other assets used to supply and withdraw and liquidate and Etc they revert uh because they do they will not allow uh the the supply the asset supplying the asset in the traditional way because the asset is generating on the on the borrowing side which we are now going to uh going to see all the rest is basically returning zero uh there is one interesting thing that is the handle repayment because like this particular function handle repayment is called with within the other protocol everyone every time someone uh repay that uh which is still the case with within go so if someone repays goep this function is still called and handle repayment uh the interesting thing that this does is that is it basically accounts for um for the balance and it also burns the the corresponding amount of of gold tokens minus the interest because the interest is never burn the interest is earned by the by the by the treasury and what happens is that the interest is AC accumulated within this particular token uh a token contract and then there is this function distribute fees to treasury which Al actually uh gets the go balance of this particular contract which is the total interest that has been paid by go borrowers and transfers it to the address of the other treasury which is tracked uh through this particular internal variable uh the paramit also revers and all other the transfer reverse of course and then there there are a few other accessory uh function to update the go treasury to get the variable dep token and so on and so forth uh let's go to the variable dep token also another thing is that the a protocol has two uh depth modes one is stable and one in variable stable is being deprecated so this it's not possible to borrow a go at a stable rate you can only borrow at variable the variable again is the variable rate is decided by the governance though so it doesn't work it does it does not have the same variability that other assets have like usdc those are P pure variable in the sense that you can get uh borrow at 3% and paying I don't know 60% a day after because it depends on the it's strictly correlated on the supply and demand within the other protocol itself uh this is different this is decided by the governance so the interest is still variable the interest rate but it way less variable because uh of the because there is a governance process behind that is used to actually change the interest rates uh so again this is the variable dep token which is what I mentioned before this particular token in any implementation for any asset is not transferable because we don't uh the the transfer of the debt is not allowed because otherwise you would be able to transfer your dep to someone else and keep your collateral which is something we don't want um there is an initialized function this is for the for the proxy uh there is a map a mapping that that tracks uh all the state for every borrower where the state is the amount of Interest they accumulated and the percent discount percentage that they get as I mentioned before from the SDK a for participation within the safety module uh so again this contracts is relatively simple uh meaning is very very simple it just means it's called during the borrow function and it means means an equivalent amount of uh variable dep token to the to the user that is borrowing the burn is the same it just burns the amount total Supply this is I'm not going to in this details because this is would require much more time this is uh the way that the other protocol calculates uh the depth and the supply side internally to keep track of how much every user has supplied and how much interest the user are has um accumulated if you want more details about how all of these Dynamics within the other protocol work I can link later the um the white papers of the all the three versions of the other protocol where these particular calculations are explained in detail uh here we have a function that essentially sets what's the a token uh for go which is the contract that we saw before this we need it because we have a certain certain information on the a toen that is also needed within the de token and then there are the functions to update the discount rate strategy which is basically the the strategies that calculate that Returns the interest rate set by the governance and the discount rate that is also set by the governance ER and also it keeps track of which is the token that actually uh allows uh um makes you eligible for a discount in this case is the SDK a which is the token that is Meed when someone supplies to the safety module uh so this address in production is um basically SDK the address of STK and here there are all a few functions that allow uh for the the update of the discount whenever the discount is changed on the governance side because like everyone has different discount so um what happens is that when the governance Chang the discount it doesn't change the discount for everyone because everyone keeps the discount at which they borrow it so through this particular set of functions we are able to update the discount of individual users one by one if that necessity arises not it's not always the case and I don't know uh unfortunately I'm already out [Music] I don't know if should I allow yeah hello um thank for the thank for the round has been uh quite useful I wanted to ask something regarding the how to calculate uh dho B Bor interest uh rate okay uh before borrowing uh like I think you showed us um in the you showed us in this contract the go variable Deb token how to uh get the interest rate that's after I have borrowed so I have been issued the variable de Tok right so my question is how can I yeah um yeah no I mean you can do also before only because like again only because the go interest is calculated by the go is set by the governance so you know like compar you know in the other protocol when you borrow usdc for example uh you might borrow a three but your borrow action already changed the interest rates if the supply side Remains the Same you know because uh if uh Supply is 1,000 and you borrow five the base borrow at at the moment that you are borrowing is going to be different uh than the borrow rate after your borrow because you took some liquidity out you know so uh that's a bit harder to predict what it will be because for example in the same block there might be other borrowings or other supplies uh actions which which might alter your calculations okay so if in the same block before you there is a supply for example you are going to pay less than what you calculated in this is talking about a normal asset in the other protocol not not go specifically this is because like the interest rates on usdc for example it depends on uh strictly on the how much liquidity is supplied there and how much borrow demand and what the users are doing if there are users that are withdrawing if there are users that getting liquidated so they are uh refilling the available liquidity if there are user there users there are supplying more so that's way harder to predict in this case you can still do it uh you can fetch the discount rate strategies which is part this particular strategy here uh that is set within the go get the interest rate that is returned by the strategy and also get the discount rate that is also returned by uh by the strategy and depending on how many SDK a the guy are supplied you can exactly calculate how much you're going to pay for your for your amount the details of the formul and detect paper so uh it's not super straightforward there are a few a few edge cases that you need to keep into account but you can do it precisely the only uh variability here is if the governance after you borrow it changes the interest rate that case of course you are not going to be able to uh I mean you will need to do direct calculations how much you going to pay if the interest rate change but if we suppose that um through uh the interval of time time interval your borrowing the the governance does not change the interest rate you can calculate already in advance you don't need to wait until uh the borrowing action is completed all right sorry and just to make sure I'm uh on the same page uh you're referring to interest rates of borrowing go tokens right not about uh all right and the functions to read the current let's assume that there is no uh other Supply or borrowing uh happening in the same block you know let's take a very naive example here um so the functions I would need to call let's say on my front end to uh do some calculations uh would be in this contract in the variable Deb token contract or in some other contract wait this this is we are talking again go or or any other asset go go it's okay yes no all of the all all that you need are in the discount rate strategy so that you can fetch uh from the from this token uh get there must be of the discount rate strategy there must be a getter for this discount rate but you can also fetch you can also fetch it from the other protocol as a get interest rate strategy for an asset uh so basically what happens every every asset has a contra independent contract which sets what's the interest rate strategy okay uh those those contracts are you can be in the particular go implementation you can fetch from the contract here there there there needs to be a get that I cannot find at the moment uh but you can also find from the configurator the a protocol the configurator contract uh there is a get Reserve interest rate strategy um function with you can pass the address of the asset in in this case you can pass the address of go it will return you the address of the interest rate strategy and then at that point like in the documentation everything is explained how to fetch the interest rate how to do the calculations and so on and so forth you find everything there you can do like we use this on the on our front end basically awesome thank you so basically the easy way is to just call the P configurator contract and uh just okay and one short question yeah yeah sorry one more very short question uh I noticed you uh deployed a fresh SEO deployment for go uh but the only asset available to deposit there is eth and the apy is set to 0% um is this for e or for go for E to supply e the yeah uh okay no maybe it's zero because it's empty I don't know I haven't checked yet but if it's empty and nobody nobody's borrowing it's going to be zero so because it's a new Fresh deployment and I think that's probably the case I haven't checked in the last couple of days if someone has already supplied and borrowed but you know when when you I supplied already I supplied already and I can't find from the UI at least uh a way to borrow uh if so I can uh you know artificially pump the apy there to make my application make sense because basically we're trying to build on top of uh the yields that are generated from uh okay I mean this you can this you can ask to the guys in Discord or or in the chat like they manag the deployment like if you have a problem on this this kind of problem you can ask to to the guys that will help you with okay thank you very much I have yeah I haven't checked the the in the last couple of days I was like discussing with the guys about the deployment H but I haven't checked uh in the last couple of days so I don't know what's the state of supply and and borrowing of of the various assets okay I think we are out of time um uh I want to I'm I want to thank you guys everyone for participating in this very short uh smart contracts overview of the Go I mean some of the concept that I try to explain they are a bit more root in the mechanisms that they have a protocol use that are a bit more complicated and they require a bit more time to actually fully explain and fully understand so half an hour is not really enough uh I tried my best I hope it was useful uh we are available of course to explain I just wanted to say that uh what I hope to see for this aaton as well is also uh like ideas for new facilitators that would be amazing new facilitators actually uh allow the have a governance to generate more go that would be very very interesting or come up with in other different ways of I don't know integrating uh the other protocol within go for example different implementation that might be more efficient or I don't know different strategies for managing interest rates all of these kind those would be uh super interesting to to see your contribution on that uh particular uh topic so um thank you everyone for participating and uh good luck for for the rest of the week cheers [Music]
Automatic transcript — names and jargon may be misspelled.