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

Loading player…

Building on The Compound Protocol - Adam Bavosa

Ethereum DenverSat, Oct 9, 2021, 12:00 AM

This talk is from ETHDenver & ColoradoJam , the world’s largest Web3 BUIDLathon and Community Gathering. ETHDenver’s content is crypto and blockchain focused. Learn more: ethdenver.com Subscribe to our channel to learn more + connect on Twitter: https://twitter.com/EthereumDenver. Speaker: Adam Bavosa, Compound This talk was recorded Sunday, February 7, 2021. ETHDenver 2021’s content themes included DeFi & Money Legos, NFTs & the Creator Economy, ColoradoJam & the Next Frontier of Statehood, Protocols & Interoperability, Open Source & Public Goods, The Ownership Economy & Digital Orgs, Usability Design & Adoption and Legal, Privacy & Identity. Industry experts also weighed in on topics like decentralization, privacy, identity, non-fungible tokens, scaling, governance, diversity, and arts and culture in blockchain technology. The 2021 event was February 5-12 and hosted virtually in 2021 with 5000+ blockchain enthusiasts, developers and community members from 80 countries and 50 U.S. states. 🔴 SUBSCRIBE ETHDenver’s YouTube https://www.youtube.com/channel/UCgz9NU06t_FkT0Py1Vadczw 💡 LEARN ETHDenver’s Official Website https://www.ethdenver.com/ 👋 CONNECT ETHDenver Twitter https://twitter.com/EthereumDenver 📖 READ ETHDenver News on Medium https://medium.com/ethdenver 🛍️ SHOP ETHDenver Official Merchandise bufficorn.com 💬 CHAT Telegram https://t.me/Ethdenver Discord https://discord.gg/AxFmNdCVnU 📱 FOLLOW LinkedIn https://www.linkedin.com/company/ethdenver Instagram https://www.instagram.com/ethdenver/ Facebook https://www.facebook.com/ETHDenver/

Transcript

is adam here absolutely how you doing there you are adam good to see you man yeah thanks for having me yeah you got it well you got an extra i'm gonna give you an extra minute you want it let's go oh absolutely yeah let's get started okay take it away sweet thank you uh hi everyone i'm adam and i'm working with compound and i'm happy to be here at east denver i have a presentation to show and also some live coding to get you started going towards the compound bounties so i will share my screen here with my slide deck there we go nice all right i am adam and i work with compound labs i am the developer relations lead you can contact me and i will help you out with your protocol related development projects things like working on d5 projects that use the compound protocol i'm here to help you out answer your tech questions help you understand all the concepts and stuff uh i'm here to help you so you can find me on twitter i'm adam vervosa you can find me on discord uh i am adam b and also you can email me at adam at compound.finance so today we are going to talk about the hackathon bounty for compound uh i'll tell you what the compound protocol is if you haven't heard of it before and i will show you the developer resources so you can get started hacking and also do a dev workshop to give you a jump start on what it's like to build an app with compound so i'll tell you about the compound bounty we're calling it the compound composability bounty it is for the most useful new original financial application that is built on top of the compound protocol that is the one requirement it must be built on compound uh in order to be eligible for that five thousand dollars of cusdc prize cool so if you haven't heard of the compound protocol before it is a uh developer infrastructure it's running on the ethereum blockchain it is decentralized it is uh something that enables uh developers to incorporate interest rates for ethereum assets into their application so your users can supply assets to the protocol and they earn an interest apy on those assets when they're in the protocol so there's no kyc there's no custodian it's just a smart contract running on the ethereum blockchain so today there are around 6.6 billion dollars worth of assets in the protocol and the inverse to borrowing is uh supplying is borrowing and there are about 2.8 billion dollars worth of assets being borrowed from the compound protocol right now and those assets are plain old ether and also some erc 20 tokens uh there are nine supported assets currently and at any time more can be added uh for use for supplying and borrowing and getting interest rates the protocol is decentralized so developers can actually create the new features such as adding assets changing interest rates changing collateral factors all that good stuff can be done by developers just like you and you can create those proposals that the whole community votes on so yeah that's compound in a nutshell i will tell you a little bit about governance and how that works so the compound protocol has been decentralized for uh better part of a year and that is controlled by two smart contracts that are uh live on the blockchain it is uh the comp contract and also the governor so comp is a utility token erc20 it is distributed to protocol users in a very slow drip if you are using the protocol such as supplying or borrowing you can earn the comp token and that can be used to vote on governance proposals so governance proposals are actual changes to the protocol uh there are code changes uh you can check out that code on github um audit it yourself before you vote and then if the whole community as a whole votes in favor of a proposal it will go onto the blockchain live so the community can create proposals if you have more than a hundred thousand comp delegated to you you can create a governance proposal so here's the cool logo of the comp token uh here is a flow for voting on proposals uh somebody writes some code uh tries it out on a test net make sure it works in the protocol they create a proposal and once a proposal is created the community can check out the code make sure it works audit it and then the voting sequence becomes active once uh the proposer initializes it there are three days for the entire community to vote ea or nay on the proposal and uh if it succeeds it gets more yes votes than no votes then it becomes queued and it goes into the time lock which can be at minimum two days and that gives applications running on the compound protocol it gives them the opportunity to make any changes to their app to reflect uh the upcoming uh merging changes to the protocol so if something changes they they have some time to fix their app to make sure it doesn't break before the changes go live on the ethereum blockchain so that is a governance in a nutshell uh there is a nice interface on compound.finance you can head over there to see uh proposals that are made proposals that are live past proposals uh you can also vote using your comp token there's a nice interface that uses um web3 to use your delegated votes to vote on proposals here's a cool tool uh it is a leaderboard of all of the top comp delegates uh these are uh folks in the community that build apps on the protocol and they can uh do things like create proposals vote on proposals uh we have a nice descending leaderboard on compound.

finance governance so resources for you to get up and running with development uh you can go to compound.finance and get the docs at slash docs uh everything is linked from the docs uh that homepage in the docs has things like smart contract documentation each method is described there are guides for developers to build an application and get their their environment set up links to medium guides so you can follow along there are uh smart contract addresses uh avis all ready to go there you can find uh the whole community in discord come to compound finance discord that will link you to our discord uh you can hang on the development channel ask any question you can think of uh we got lots of smart folks there including myself and we can help you with your project uh help you debug your code give you feedback on your your ideas all that good stuff um like i said we got a medium blog with developer guides and of course everything is open source on github so check it out this is the workshop that i will be running through today um it's a little app for using the compound protocol take your screenshot right now uh head over to github and check out my demo app as i code along with you all right let's get started on that coding portion so um if you go over to my github here is our uh cool app we're gonna build together uh here is a screenshot i guess it's kind of small we're going to build something like this it's a basic app where you open the web browser you enable ethereum and you can use metamask to supply assets the compound protocol and earn a interest rate uh so that is something you can enable for your users so i have already cloned this repository on my local machine right here uh and i'm going to run it it's just basically a little bit of html a little javascript app that uses an sdk called the compound js sdk that's also open source on github and it's also a little bit of css i'm not going to run through uh everything but i'll show you some cool stuff here i'm going to bring up my terminal uh here is the app folder itself i'm going to do http server this is a node package for running a little web application on your your local machine so this is in the root folder so that index.html will be our app so here it is running i'm going to bring up my developer console so we can see what's going on as i write some code cool so first thing i'm going to do is i'm going to sign into metamask i guess all right my my local host is not running so um for this demo i will run ganache cli and i will do like a fork of mainnet so this is an unlocked wallet here that i use for all of my demo applications uh so we're forking mainnet so we can run like a fake blockchain on our machine here so that is good and i will enable metamask real quick very nice okay so uh metamask you usually have to reset your account so the nonce doesn't mess up um okay cool so we got our local host uh blockchain we got 100 fake eath for free uh and of course i don't have any other assets here these are c tokens um but i have zero of them at the moment uh so what i'm going to do is i'm going to i'm going to disconnect from the app so this what happens when you first visit the app um it tells you the apy of the current uh compound protocol c token smart contract and our number is missing right now because uh we need to actually query the blockchain we need to query the c token contract to find out what the rate is so we can find out the apy uh there's an error in the console because we don't have a web3 provider and that is because i disconnected the app so in order to connect i can click this nice big enable ethereum button i will enable my local host account very cool so when i refresh the page a number should pop up here yep we see uh the apy is currently zero point one three percent and to sanity check this we can head over to company finance markets and we see an ether the supply apy is currently 0.13 so that's that's awesome that works all right so the code for that guy is like my font nice and big for you all um if we use compound vs and do a read on the blockchain we can pass this little abi here of the supply rate per block for the c token contract and use our local provider with window.ethereum and that way we can uh query for this prolate supply rate supply rate per block um and here's a quick little equation we use the blocks approximate blocks in a day and days per year we can come up with the percentage of apy uh with a quick little javascript function all of this is in the documentation by the way in the protocol math section in case you want to write this again from scratch so yeah this is what is is calculated when the page loads so that's how we see this .

13 here very cool all right so next we're going to supply some of our ether to the protocol i'm going to make uh my metamask wallet nice and big so you can all see it um cool so here's our little interface here i'm going to supply three each because we have a lot of ease right now and that's going to go to the protocol i'm going to get a transaction request i don't think i can make this guy bigger but basically what it says is i'm going to be querying the or making a transaction for the uh c ether contract and i'm going to be sending three eth and i'm calling the mint function and what this does is it sends ether to the contract and the contract mints c tokens and of course we're gonna be losing a little bit more than three for the gas fee so the gastey is uh this this little bit here uh so when i hit confirm uh it's going to send that transaction uh based on my code when i um click the supply button we're going to grab the the number that was in that text box call the supply method which is here and uh we're going to call this compound.js very easy supply method one liner uh it tells the um the sdk which asset and how much so we supply three eth and then after that we log in the console what we supplied the underlying ethers.js transaction object because compound js is just a wrapper around ethers js and we also log the transaction hash so we that's what we see in the console here this transaction hash so if we were on mainnet or we're on a test net we'd be able to plug this into etherscan and we'd see our mint transaction running uh so because we're using ganache cli the transaction mines pretty much right away so that means that our wallet will reflect the difference so uh it's a hundred minus three point something each is uh this this number here the 96 and we see we have 96 each and our uh see each balance went up from zero to 149 so uh we have uh c tokens the exchange rate is always changing uh it's about 50 to 1 uh to start with and of course over time that that changes such that you can redeem your ca ce for more east as time goes on so as the block number goes up uh you get more ether in return for your sea ether when you redeem it so now that we have some sea ether let's try and redeem it using the app so i have 149 so i'm going to do 100 and i'm going to click this redeem button so we're running uh pretty much the same sort of function that we saw earlier there's a a button that we click and it takes that value from the text box and we run this this one liner uh for compound js to redeem the asset uh this is a initialized uh instance of the sdk we did that at the very top here uh by calling the the sdk constructor left that part out uh so this is the windowed ethereum that's provided by metamask but yeah uh here's here's the redeem function uh if we you know have a number it's it's not like someone put a letter in the box uh then we we create the transaction if somebody messes up and and does something wrong or the the request fails will alert the user so that they know something went wrong so i'm going to hit that redeem uh and that will give us a meta mask transaction we're going to run the redeem this time uh there's zero eth being subtracted from my wallet uh there is a little bit of a gas fee so it's a little more than zero so when i confirm this we should see my ether go up and we should see my c ether go down to 49. so let's confirm uh again in the console we get a new transaction hash and uh we will see these numbers change in a few seconds there we go we got 98 eath now and so uh for that three eth that we supplied we actually earned a little bit of interest because we had our ether in the protocol for more than a block so we earned some interest and our seats went back down to 49 because we subtracted 100. so cool that's that's uh supplying assets and redeeming them from the compound protocol but what if we want to add more interfaces what if we want to include more of those assets that are listed on compound finance uh we can do that by adding some more code to our project so why don't we try and add usd coin to our project let's do that by going back to the code and let's go to the html uh we got our interface here for ether so we're just going to copy this because we want to have another interface so people can do usdc so i'm going to take away all the things that say ether i'm going to say instead okay cool uh okay so we got two of these um modal sort of not really modal but uh little widgets in our user interface for uh using the compound protocol so when i refresh the page we see we got a usdc one here cool uh but we do not have an apy number because we didn't write any javascript so we should get on that we should write some javascript all right so uh up here we're grabbing each of those elements from the dom uh using getelementbyid i'm just going to copy them do the same old thing and we'll change each of these to usdc yes got my multi cursor here nice sublime feature love sublime all right so now we're going to grab all of those new elements we just made in the html let's make some more button click event handlers uh usdc and these are now on one so let's do that's dc very nice and uh this is a little thing in compound js uh this this resolves to a string that's just plain old like pth like that so it's nice if you don't like having strings in your code you can just do compound dot um asset name so i will do usdc and uh when we're redeeming we're doing that with c usdc cool so we got our click event handlers so those will work when we click those buttons uh we're going to use the same supply method obviously it's generic enough to work for both and calculate apy also works but we need to actually fetch it from the blockchain so when the window loads we're going to grab the usdc apy uh so yeah like i said before we can pass the actual string literal if you'd like and then let's do usdc and usdc okay so we wrote some javascript code that hooks up our interface to blockchain so let's take a quick peek at what the usdc interest rate is it's currently 9.

61 so for each usdc that you supply the protocol uh you'll get a nine percent uh interest rate uh which is awesome uh so let's go back to our app so when i refresh the page here we're going to be using that calculate apy function and getting that nine point something number okay maybe i have a we have some caching going on so i'm gonna hard reload there we go nice okay so we got 9.61 that's what we saw on the other page excellent so i'm going to make sure it works by doing some supplying but i actually don't have any usdc but what's good about having a local host uh test blockchain is we can fake it uh we can steal some usdc uh which is kind of fun so if you actually go over to the compound developers github that's github.com compound developers you can find the compound supply examples repository this goes along with my medium blog post quick start guide and there are some examples here for seeding your account with uh tokens so if you're on localhost you can see your account with some nice tokens so if i go over to usdc i'm going to run this script and basically what it's going to do is it's going to mint some usdc and send it to my address so in order to do that i need to run ganache cli in the background and i need to unlock the usdc address so i can steal some usdc i'm going to steal 50. so i already have this on my machine yep supply gun okay cool so i'm going to do node see seed and usb c so that will run a transaction to my uh ganache cli which is running in this tab and uh we got 50 usdc in our wallet so when we go back over to metamask it should say that i have 50 usdc which it does very nice all right now we have some usdc that we could supply to the protocol using my okay here's my app uh okay so let's uh do 17 let's do a weird number hit supply i get a um would you like for this page to spend your used stc okay so the extra step with erc20 tokens is we have to approve that the compound protocol can spend uh our assets which basically means just take them and put them inside the c token contract so the compound.js method has a way to do these two transactions in one method call you can pass a boolean to actually make it so it doesn't but mine does so i'm going to approve before i actually supply so that first transaction was sent and now the protocol can take the usdc for my wallet so i got another metamask popup and this one is for the actual mint operation which takes the usdc and sends it to the protocol of course this time unlike ether it's zero because uh uh we're not spending any heath besides the gas fee so uh we're taking 17 usdc we're sending it to the c c token contract and minting some c tokens so uh like i said c tokens are about 50 to one so we should see uh our you see usdc number go up uh we got our transaction hash again and we'll give this a few seconds all right so we got 788 cusdc and of course 50 minus 17 is 33.

cool so that worked let's make sure our redeem function works let's redeem 500 of those cosdc so we should have 288 something after this transaction so metamask says we're calling redeem on the cusdc contract hit confirm get another transaction hash here and check out our wallet there we go we got 288 cosdc remaining and 43 usdc so of course um our amount of uh usdc went up a little bit because the interest rate uh allows us to earn a little bit of usdc cool so that is a little demo of adding interest rates to an application with the compound protocol uh and also compounded s which is an sdk that is uh open source it is on github it was written by yours truly it is it works in both the browser and node.js so you can come on over to the repository or the documentation and check out these cool functions for using the compound protocol and also ethereum in general uh if i head over to docs there's a compound.js tab over here this will help you out with uh using that so uh yeah that's uh my presentation uh i'm i'm here to answer your questions as well i have the twitch chat open right now so uh feel free to ask away i'm ready cool thanks adam yeah let's take a look here let's see if you allow borrowers to borrow your ethereum can a lender ever lose it um yes so if uh somebody borrow your ethereum can a lender yes uh once a person who borrows an asset they have they own that asset it's in their wallet uh so they can take that and do whatever they like with it uh so the uh concept that the protocol works on is this over collateralization so in order to borrow an asset they must first supply collateral so uh the way it works is there's more collateral needed than the value of what can be borrowed so let's say i want to um borrow some usdc i could check out the collateral factor for usdc by going to the markets page and the collateral factor is currently 75 so if i supply a hundred dollars worth of ethereum i can borrow up to 75 dollars worth of usdc so that way uh the uh borrow is uh collateralized and if the uh price of the ethereum collateral happens to go down such that it no longer supports the borrow of usdc that would mean that the account is subject to liquidation so a liquidator can repay the borrow so they would repay that usdc and they would be able to take some of the collateral as a bonus uh so that's the incentive for the liquidator so that that's what keeps the protocol healthy in case a borrower's collateral no longer supports their borrow they can get liquidated and their collateral gets uh taken and given to a liquidator who um make sure the protocol stays safe and healthy and and that the uh the assets are able to be supported yeah yeah um five turkey or sturkey one of those two is asking what the biggest challenge in developing the app um this app in particular i'd say the biggest challenge is learning all of the concepts for using the protocol the protocol is definitely not straightforward uh d5 is definitely uh it's challenging to learn the concepts are not trivial so once you understand the concept of supplying and borrowing and minting c tokens and being able to redeem them later then once that makes sense building in the app is actually pretty straightforward some pretty basic javascript i've designed that sdk to be as uh straightforward as possible and have uh these nice one-line methods so if you were to write this with web3js or etherchance this ends up being like a whole file worth of code but using the sdk makes it nice and easy so you could do one-liners like compound.redeem or compound.supply and of course many other methods that i uh made simple for you the developer want to make your life easier excellent excellent looks like all the questions that we have for the moment and uh looks like we're just out of time perfect good timing everyone well done right on time great well uh go after that five thousand dollar cosdc bounty i'm here i'm here to help you come find me in discord message me on twitter uh thanks for having me i'm really happy to be a part of east denver awesome yeah thank you so much adam thank you for sharing compound and we'll see you next time

Automatic transcript — names and jargon may be misspelled.