Code-along | Governance & DAOs

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello hello welcome welcome all welcome to another wonderful week of workshops uh and uh our dao and governance workshop uh today's gonna be an absolute blast we have uh some amazing stuff up for today hope everyone's doing well i hope everybody is enjoying the hackathon so far welcome welcome in the chat uh good morning uh good afternoon good evening depending on what part of the planet you are on we are going to jump right into it because we have a lot to go over today per usual we always have a lot to go over uh in these workshops because we're giving a ton of amazing informations and today we're talking about dows and governance and some of the most popular strategies and basically what the current decentralized autonomous organizations uh industry looks like now and uh it's zeta one let's just jump right into it hope everybody is doing well i see you all on the chance yes good morning good morning good morning uh welcome welcome welcome so yes let's jump right into it i got a little slideshow presentation today before we jump into the code we're going to explain some things we're going to go deep into you know what's actually going on here and then we're going to go into um the code here so again for those of you who do not know my name is patrick collins i'm a developer advocate on the chainlink project there's some of my contact information if you'd like to reach out so let's jump into it so what are daos what what is this governance thing that we're going to be talking about now daos are what's known as decentralized autonomous organizations and they're when a community exerts its influence on some type of protocol right and this is incredibly important and and this is something that is incredibly powerful because it allows us to have organizations and groups um uh and excuse me and protocols uh make changes based off of what the community wants because at the end of the day that's exactly how blockchains work blockchains only work um if the if the consensus if the social consensus wants them to work there's actually a really interesting um real life study on uh what was the protocol well i'm drawing a blank now honeycomb no um well i'm drawing a blank but in any case um some uh some users came to the to the organization and they bought up most of the tokens right so all of the users didn't like the people who bought the token so they ended up basically forking and doing their own thing and that fork became the dominant chain so uh the consent of the governed is incredibly powerful and incredibly important uh when you're building these decentralized systems right and even in some even something like bitcoin right or ethereum if you don't like a change that goes into the bitcoin network or the ethereum network you just don't upgrade right you fork it you do your own thing um and to not reach that point you want to make sure you're the way that you do governance the way that you create do votes the way that you upgrade your protocols and do different things is deriving in the most fair way um so that you know the consent of the government stays right and we want these things to be as trustless as possible uh and dow's are pretty new this governance thing um in these in these decentralized systems is surprisingly pretty new now it hasn't been a new idea it's actually been around basically since ethereum's inception but in practice uh these dows and these truly like decentralized dows are are pretty new right there's there's not a whole lot of tooling and um the reason that they're pretty new is because it's definitely very sensitive right you have to keep in mind a lot of things like who votes how many votes when these uh when are the the votes and proposals active um you need to protect against flash loan attacks if you're using some type of token votes upgradeability can be dangerous you need to keep that in mind so there's all these things that need to go into it and we're going to talk about some of the most popular strategies to attack some of these problems so when i look at governance i like to think there's two main kinds of governance there's off chain governance and on-chain governance now often governance typically is going to be paired with uh some database and an oracle on-chain governance is going to be you know 100 on chain it's going to involve maybe token holders nft token holders esc20 etc whatever um and the off chain governance is going to be some type of database and oracle but but some popular methods now actually are some type of database and multi-sig right obviously the the disadvantage there is that the multi-stake has to be a trusted you know member of the community and it does reintroduce that that element of trust that we're trying to uh remove with these contracts but um it can be a little bit easier design wise and and maybe you want for whatever reason but for for all intents and purposes these are kind of the two main forms of governance and the question people you might be asking is well how do you do governance with you know with a database in oracle well um to all uh if if you do a ton of votes all those votes can just be considered data right and so you can put the result of those votes into a blockchain and with cryptography um you know you can sign transactions and just not send them so you'd sign your transactions you'd stick them in you know a decentralized database like ipfs uh and then you'd have you know something like a chain link oracle read the results of those votes and then put them on the blockchain now um when we talk about these tools we want to talk obviously talk about the pros and cons and why do one over another um so the pros of off chain governance is that it's going to be way cheaper gas-wise right if you think about um on-chain governance uh with which again we're going to talk about these strategies in a little bit um but on-chain governance a popular strategy is that everyone has to cast their vote on chain every single person who participates has to spend the gas costs to cast their vote right so if this is the case you have uh you know and you have a a a community of tens of thousands of people each each one of those people is spending you know some amount of gas to cast their vote you as a community are wasting a ton of gas right you as a community are are being less gas efficient versus with offstring governance you can make that uh that vote excuse me that um that delivery of the result of a vote in a single transaction which is going to be you know orders of magnitude like 99 cheaper gas-wise wise because it can be one transaction as opposed to you know tens of thousands so it's much much much cheaper however um right now the on-chain governance has much more mature tooling and you'll see when we go into it and the off-chain governance is a little bit more immature um however there are a number of uh of pieces with the option governments that are fantastic uh that will show you and and here's my favorite part and here's my favorite part uh since all this off-chain governance uh tooling is so immature uh some of you might have noticed there is a chain-link services uh prize so you know hint wink wink nudge nudge um that's all i got to say there anyways um so so those are kind of the two types of toolings here i would love to see more mature tooling in the software governance space and there are a couple of projects really tackling the soft chain governance and making um and also kind of bridging the on chain and off chain governance and doing a lot of really cool things and we'll talk about that um and again i am watching the chat so feel free to ask questions uh um and uh yeah feel free to ask questions as we go along here so um when it comes to on-chain governance uh the most popular and kind of what's becoming easily the standard is the comp governance bravo aka compound governance model right um this is this is the uh uh this is the um this is this has really become the standard for on-chain governance and the way it works is you have an erc20 token like the comp token used to vote on proposals and kind of below here we see and i borrowed this from uh from an uh an open zeppelin video on it and i'll link the opens up on video because it's really good um i'll link it here if you want to see more on kind of like the uh the exact approach that different protocols take definitely check out open zeppelin's video but basically governance users can make proposals and vote on this protocol called governor bravo where people can delegate their votes to to other people as well they make proposals they vote on those proposals and after after a certain time lock has has uh has gone by those governed contracts get executed so uh and this is actually really important that they have this time locked because again um if a proposal passes and somebody doesn't like the proposal and they want to leave the dow a time lock of two days basically says hey this proposal passed it's going to be enacted in two days if you don't like the proposal uh it is time to bounce out so this is kind of the the basic layout here and we'll talk a little bit about um you know how to prevent against uh uh flash loan attacks uh how how these erc20s can be uh made more secure but uh this is this is the basic setup right people vote people create proposals um it goes through these smart contracts goes to the time lock and then it gets executed and everything happens on chain and what's kind of nice is you can create user interfaces on top of these smart contracts to make these easier one of these user interfaces that's becoming really popular is this with tally or this tally application we actually see with with tally.com if you go to it right now you can see like explore governances um and most of these protocols are doing some type of compound governance right they're doing this on chain this fully on chain governance here and if you click um something like compound you'll come in you'll see the proposals you'll see the you know the token the voting power different people and you can kind of see all these really cool things about governance um compound themselves also have their own governance place oh and then you can add new proposals delegate votes compound themselves have a governance page and this is actually what we're going to be looking at to see exactly what one of these is going to look like so if we go to um this this example proposal right um this was something that actually passed this went into effect this was a successful um piece of gum compound legislation and if we scroll down we actually see um exactly the proposal history and how this exactly happened so the first thing that happens in order for um governance to occur is somebody needs to create a proposal so in order to create a proposal you actually call um your the compound governance contract uh you call its proposed function so they have a proposed function um that looks exactly like this and if you use the user interface for example to propose something you know maybe even use with tally like if i hit add new proposal here i'm going to be calling this proposal function anybody can propose something well anybody can i actually i don't remember if they changed it or not but typically anybody can propose anything sometimes they have white listed proposers but you know for the most simple example anybody can propose something and then uh people can vote on it so we scroll down uh and we decode the input data we actually see exactly what this proposed function takes and it's the architecture of these proposed functions is really flexible to really allow anything to go through so they take if we switch back they take 1 2 3 parameters the first one being targets which is going to be the addresses they want to to quote unquote target and the second most important thing is signatures and that's going to be function signatures so um when you make these proposals you say hey here are the contracts that we want to call some function on right so there's uh this proposal saying hey at this this contract right this first one we're going to call this set pending implementation hopefully this is zoomed in enough we're going to call set pending implementation um some address and the input parameters we're going to do is this bytes encoded you know right here so um and then the next thing we want to do is we want to call this address we're going to call become and this is what we're going to pass for parameters third address we're going to call is we're going to call this address we're going to call the the fix bad accruals function and we're gonna pass this one so that's kind of the main set that's how it goes you call the address the function um and then the the encoded uh parameters and you also set like a a large description as well and then you can also send uh values the values obviously being like how much each you're going to send with each with each function call so in this one they send 0 and they have this this really great description here which if you look back at the compound protocol um looks like it's not doesn't show up here or maybe this is it i don't know um detail's not a proposal 64. well in any case um oh yeah details yeah now the proposal 64 had been executed and then it so it shows up here which is pretty cool so once a proposal um uh is in the next step is it becomes active right so proposal goes in uh becomes active this is after a couple of days has passed once it's active that's when people actually start voting now when people start voting um usually what will happen is these these protocols they'll use a previous snapshot a previous like snapshot of how many people have uh have tokens right so uh and and this is really good because if if somebody saw some proposal and they were like oh i really want to influence this and they go out and buy all the tokens you know it doesn't work like that um you have to have held the tokens before the proposal became active in order for it to count but yeah once these proposals once the votes go in um and it passes like enough votes go through it doesn't go get enacted right away it actually first gets queued and we can see that uh that transaction here uh it gets queued and yeah it just gets cued so um it gets cute and then after after about two days or again depending on the time lock it'll get executed this can be called by anybody as long as it's passed and has been queued and um yeah it just executes the proposal 65 right that's it and that's the basics of what like compound uh governance looks like excuse me from end to end now i see a couple questions let me jump into the questions here oh never mind there's no questions is it crazy how everything is open source space yeah it's pretty awesome for sure all right so cool so that's kind of the basic breakdown of how some of these typical governance projects and proposals work oh okay how close is solidity in relation to c um not that close actually solidity absolutely more javascripty all right in any case um so that's tally that's kind of the governance proposal 65. awesome now um that's that was an example of on-chain governance with these erc20 tokens they vote on stuff etc now we'll talk briefly about off-chain governance and for people who want to see um a decent dashboard of kind of what daos are using and where dows are this deep dow dot io is pretty good um it's missing a couple of dowels but i'm like maker for example but um for the most part it gives a decent idea of like what people are using and what stuff looks like so if we look at um the top protocols here you can see a lot of using compound governance but a lot of using this gnosis safe and snapshot governance as well this currently is kind of one of the most popular off-chain governance methods out there so you use this tool called snapshot and a gnosis safe so um use this tool called snapshot and a gnosis safe maybe a multi-sig um or something right so it's it's not it's not exactly using an oracle um uh some do use some type of oracle but some just use like a trusted multi-sig which again it could be considered a little bit less decentralized it depends on how you want to look at it though um but what you can do and here's an example of a dow that i made that's kind of silly uh as you can make a dow um in here and what will happen is when you create a new proposal you can kind of choose you know the question your proposal add some choices whatever you want select the start date select the end date and people with these tokens can actually vote right so if you were to uh if i were to connect my wallet and and launch this dow watch this excuse me launch this proposal um i can only vote on this if i have the token if i have the erc20 or whatever you can actually change kind of in the snapshot interface um what type of governance you do whether it's nft based maybe it's erc20 based and what happens is people actually vote and they sign these transactions and they get saved on ipfs so that's kind of the decentralized database part then once everyone votes all these transactions are on pfs you can use some type of oracle to uh to get the results of all these transactions and put them on chain or you can just say hey you know we have a trusted multi-seg you know we believe you you you can do this um and let the multi-sig actually enact the governance um obviously the um it's you are trusting the multisig to be honest here uh when you do that but the good thing is you know if you still have the list of those transactions you know maybe you even make a backup where you let people actually do the on-chain voting and then you just replay those transactions since they're signed so uh hopefully that was clear but yeah this is this one's really nice um gnosis snap safe is kind of what the the tool is called um and uh and again for those of you who are looking to do some chain link service type stuff this is like the perfect thing to do um where you you you maybe you do your governance um on snapshot and then a chain link oracle delivers the result of that proposal of that dow you know on chain is data or a chain link price fee does it or you know a group of chain link nodes you could do like the um the chain link any api call with multiple nodes in any case there's a lot of different ways to do this that'll be really cool question why the number of voters is miles less than that than the members number uh this is a great question so this is going to basically come back to uh participation rates um so a lot of the times uh partition pace rates are going to be low right like even in traditional voting not everybody votes and sometimes that's just the case so getting people to vote more is important because that's going to give you the most accurate results uh yeah the gnosis multisig is awesome uh if you haven't checked it out if you haven't played with one before definitely check it out uh no sap snap safe is definitely very cool tool and i would love to see you know chain link as an oracle for that snapseeds product so again if you're looking for a services thing there's your alpha leak all right cool any other questions with anything that we've gone over so far that's kind of the basic layout of these dowels uh now we are going to go into the code along we are going to code this uh we are going to code some on-chain governance uh together uh and again if you want to do some offering governance that's going to be way cheaper and pretty much just as safe highly recommend you you do at least the the token deployment part um and maybe connect with snaps and build some type of oracle to connect with ipfs or connect with snapshot uh or even you know knows this to deliver that data on chain which would be really cool all right questions can you take votes from multiple nfts or tokens yes so you can actually design your your dow to do whatever right for the governance and um something else i actually should talk about governance wise is that um token votes are not the only way to do governance in fact vitalik's written about this many times where you know a proof of humanity would be a much better uh or a proof of ownership or a proof of you know whatever would be a much better way to do votes than coin voting right because with coin voting you run into this issue of people just being able to buy votes people are being able to buy the tokens just to buy votes um versus something like a proof of humanity where you know one person one vote that's if you thought about like the current government like in the united states that's kind of what it is right one person one vote you can think of the united states governments as being like a proof of humanity uh which is kind of funny to think about so you can set these up any ways you want um snapshot actually does have some kind of built-in functionality for you to do nfts or g20s or a couple other different ways to show people show how someone has voting power right it doesn't have to be the erc20s that you can hold you can really design your voting power however you want we are going to go over the erc20 version of voting power because that's the most popular method right now but it's not always the best method and i want to stress that it doesn't have to be an ear c20 it doesn't have to be a token how could you implement this in a way voters have the same voting power yeah that that's a great question so that's gonna you're i think you're you're talking a little bit more about that that proof of humanity or that proof of being or that you know that uh that hey i'm i am a somebody my vote should have the exact same with somebody else and um that's another thing that would be cool that would be awesome that's like perfect for this hackathon right to prove somebody somebody you know there's a single human being approve a proof of humanity right because right now it's really hard on chain to prove hey this wallet is this person right and i can go ahead i can make 12 different wallets and it's hard for you to tie them all back to me so a proof of humanity or proof of participation or something like that um is perfect for a chain link hackathon because you do have to connect you know the real world prove that they're a human being to this smart contract uh and in that case you know once you do have that proof of humanity proof of participation or whatever you want to call it that's when you can kind of do that one human one vote uh type deal or same voting power right an easy implementation would be just okay one address one vote but obviously you run to the issue there of people making multiple addresses so is there a way to manipulate who can vote um it depends on on your implementation of the dow right so if you set it up in a way where erc20 token holders are the only people who can vote then not really um hopefully your smart contracts have been audited uh and they're really secure and they're really solid but um that would really depend on the specific implementation great question any other questions here there are no questions i'm going to slowly start setting up so we start setting up the code here yes this is a really cool challenge we solved for future governments and um uh yeah and i think doing uh governance in on a blockchain is actually uh really efficient it's immutable it's um it's hard to dispute and it's uh i'm really excited for the day you know governments use blockchains as their their voting medium so which framework are we using today great question we're using brownie uh if you're unfamiliar with brownie don't worry we're going to be doing a lot of solidity mainly solidity and the contracts are going to be exactly the same as if you were to do this in hard hat and the scripts are pretty similar too right so if you're not familiar with brownie don't worry about it um uh solidity is great right the solidity is going to be exactly the same so let's jump into our code stuff now oh actually before i jump into the code stuff everything we're going to be doing is i'm going to post this in the chat here it's going to be in this dow mix uh repo that i've made um it's really cool it gives kind of the background as well it also talks about some other tooling right we talked about snapshot tally noses safe open zeppelin um is a huge huge piece in this they they have they came out with uh governance contracts that we're actually going to be using and the open zeppelin uh contracts that they have are based heavily on compound the compound governance extremely governor alpha and bravo it's fantastic um there are also some no code tools that i want to talk about real quickly like for example uh dow stack um it's one where you can kind of you know jump in and they will build the dow for you um aragon is one as well uh i thought it was funny and i i played the aragon trailer from 2006. i'm just kidding this is the real link though um it's another one of these protocols that it's kind of this dow for you uh colony dao house um yeah but in any case if you don't have the prerequisites for this you know you don't have python you know brownie definitely check it out um uh definitely check out the prerequisites and get those installed for this um you do need you know yarn node.js python brownie um but again if you want to just you do this in hardhat the contract's going to be the same oh oops uh so we so we talked talked about crypto cities yesterday so the time in this workshop is perfect you're darn too um cool all right so let's jump in here so the first thing that we're going to do is we're going to build our governance token actually first thing we're going to do is we're going to do brownie and knit we're going to create our our browning project and again if you're like hey like i like hard hat no sweat like great you can use hard hat but the first thing we're going to do is we're going to need to create our governance token right that's really going to be the backbone of the majority of the stuff that we're going to do so we're going to call it government's token dot soul and this can really be your typical erc20 token we are just gonna add one piece to it uh to make it a little bit better so first we're gonna do spdx license identifier mit prag solidity 0.8.7 you know the drill unknown pragma uh and then we're gonna do contract governance token like that come on why is he mad at me unknown pragmatic i spell this right all right it's mad at me for something but whatever solidity solidity spelling is important thank you appreciate that listen uh and we are gonna be using these open zeppelin uh contracts so i'm i am going to copy paste this line but i'll tell you what it does um so we're copying this erc20 votes um open zeppelin contract now this erc20 erc20 votes is an erc20 extension which allows us to take those snapshots it allows us to always have a tally of who how many how much people how many tokens different holders hold at different blocks right and this is really important for preventing flash loans this is really important for um [Music] for preventing people just buying votes the incident proposal goes in and to do um and to do brownie uh i have to go to create my brownie config.aml if you're in hard hats you would just do something different but i'll do my dependencies oh that one right i don't know let's find out yeah i swear that one right nice uh and then we're going to do open zeppelin open zeppelin contracts at 4.3.2 do our compiler sulk mappings at open zeppelin slash excuse me equals this okay perfect so now we have this at open zeppelin thing that we can use in our governance token okay cool so yeah and again this is literally the exact same thing as the year 220 it's just uh has that this snapshot thing that you'll see in a second so uh we're going to do a un256 public s max supply we're going to say the max apply this token is going to be hard coded to i don't know 1000 and then we'll do one two three four five six seven eight nine ten one two three four five six seven eight so we're gonna do a thousand here do the constructor here's h20 we'll call it governance token pt then we also need to add this thing called erc20 permit let's call this governance token and then we'll just call the mint function message.sender s max and then this needs a semicolon and then i need to do is erc 20 votes cool so this is my governance token uh this is basically it uh now like i said this erc 20 votes has some built-in functions called um like snapshot takes snapshot uh it also does it also keeps tally of how many votes people have at different uh at different points whenever they transfer tokens now the way we actually have to do this is we have to override um some internal functions like app after token transfer i'm just going to copy paste them you can as well but i do want to just explain what these are doing i just pasted this in so after every token transfer we're going to super call this after uh after token transfer from the erc20 votes token and what this is actually going to do is it's not going to let me click in uh this is what's going to update those balances and and have it so that everybody um that we always know you know how many votes people have depending on the block so there's a couple of those we also have to override the mint function we're also to override the burden function but other than that this is really what we're looking at cool any questions so far should you do government so yes i should is there an easy way to hard code a number and sliding i know ethereum doesn't like take vessels but it's jarring to having to work with 10 to 18 everywhere yeah there is um what you can do is you in 256 public s max supply equals uh 1000 times 10 to the 18th uh and and this is actually what i probably should have done but i've just i've gotten so used to adding the 18 zeros but yeah this is better it's much more readable um good call thanks thanks for calling me out there um but great let's just see if this compiles compile and again if you don't have this browning command definitely check out the readme of here to get everything set up or brownie setup link or follow these setup instructions posting into the entity here um yeah or you can also do you also do a thousand ether there's a couple different ways to do it all right cool now we have our governance token um what do we need to do next so so this is what's going to uh govern it now uh govern govern our protocol now if we wanted to do this with just you know snapshot we could go ahead and just deploy this you know hook hook this protocol into snapshot and build it down right on snapshot with just this right obviously we want to have something that we can govern but this is kind of the minimum thing uh that we need here uh next though uh is we're gonna need um we're gonna need you know the uh uh the contract that we want to govern right so what what is the protocol or the contract we want to govern um this could be like you know the ave contracts this could be the comp contract this is gonna be like how much of each thing that you want to do we're just gonna do a simple box.soul i am just gonna copy paste this because the interesting stuff isn't in here it's a really simple box contract that's ownable and this is the the ownable is really important it's going to be owned by our governance right the instead of a human being being owning this box contract it's going to be owned by the dow that we create okay and there's going to be one function that the dow can kind of call and decide on it's going to be the store function right so we have this store function it's an only owner and it's going to change this our private value variable okay so function store you know new value value his new value and this is going to go through only the governance contract can actually call this right which is incredibly powerful so this is going to be this box that seoul is going to be the contract that we're governing uh which is really powerful a couple more questions silico cuba uh 10 to the 18th how does that translate into 10k uh 10 how does uh 10 to the 18th how does that trend well it's it's not thousand ten to the eighteenth isn't ten thousand do you think 10 to the 18th is ten thousand um [Music] i'm not sure i follow i can just do var equals with one thousand either well i'm forever doing that now 1k times 10k times 18. uh no it's not it's it's a thousand times 10 raised to the 18th um so so this is it's a thousand times ten so this double times is like raised either shorthand for 10 to the 18th yeah the box is from upgrades project isn't it um yes yeah so the box is kind of like opens up one's go to sample and i think it's really good because it's it's really simple i assume that 10 18 is wrong because eth has 18 decimal places so you have to multiply 10 by 18 to get rid of the decimal places when you toss on the blockchain i thought you're doing max supply of 10k uh no it's it's max supply oh okay okay okay i think i think i see what's up so no so if it's a max supply max supply of 1000 and um this is uh 1000 in way so when we do uh blockchain stuff so for example if i do you know heath two-way theorem converter one each is actually represented on the blockchain as this if i wanted to have this be a token supply of one i would do you know i wouldn't come with that recommend this and i would do this and now i would have a token supply of one yep okay now you got it okay perfect perfect perfect so we got to do ten a thousand times ten raised to the eighteenth great good question no thank you thank you for asking okay cool uh yeah i kind of glazed over that see this is the beauty of of having chat here so here's our box here's our our governance thing um and i gotta speed through a little bit because we only have 20 minutes so yeah store is the thing that we're going to be calling um now that we have something that we can govern we have a way to measure voting power in our in our governance token who holds the governance tokens we can actually create our governance standard right our governance uh contracts so uh in here we're gonna create a new file called governance and then if you're if you're in the dow mix i call it governance standard at the moment we might change it uh but we need to actually create we need to create two contracts in here one is going to be our governance contract and this is gonna this is gonna hold all kind of the logic for doing governance but we also have to create our governor nance um time lock and it's this and the time lock is actually the contract that's going to implement the time lock right so whenever a proposal goes through we still have to wait a little bit it's also going to be the one to hold all the funds and hold the ownership and everything so it's going to be the one doing the governance through the governance contract okay so it's really important that the governance time lock is the one that has ownership if you give the governance contract ownership uh your protocol will be ruined so don't do that so let's do the governor contract or the government error ah it's called governor or nor let's do the governor contract first since this one makes a little bit more sense this is going to be the logic that we want to implement now there's a lot of stuff to put in here and what you can do actually is you can do uh you can open the opened up one wizard contract wizard which will help you create these and i'll post this in the chat too uh the opens up and contracts wizard which can help you you know build your contracts and then you can actually just kind of copy paste so they have all these settings on the left here right and if you change the settings maybe i'm going to change my voting delay to 10 blocks right you see voting delay now changes to 10 blocks here maybe i want um this this contract to be upgradable with the uups uh functionality now you have all this stuff for upgradability i will say though if you're unfamiliar with upgradability um don't don't do it uh it adds a ton of layers from complexity uh we're not gonna be going over it in this demo but it it definitely can be really cool uh you change the license and stuff and this is one way you can kind of get this contract uh really easy right and i'm gonna briefly go over it what do i do actually i'm just gonna copy it i'm gonna copy it paste it in here the governor contract and i'm going to briefly go over our you know what this is doing so um we import a bunch of stuff from open zeppelin of course um let's do eight point seven um we do a whole bunch of bunch of stuff and we uh we give this uh our governor contract two constructor parameters we give it the erc20 token and this is gonna be uh obviously you know our token right we're saying hey this is the token we want to be um to govern this and we give it the time lock controller contract which we're going to implement in a second we give the governor a name we say the governor votes token is the token we give it a governor votes quorum uh fraction which um which is like four percent of people need to vote in order for you know it to count and the timeline control obviously is going to be the timeline control and it comes with all these functions like voting delay after one block voting starts voting period is going to be you know uh four thousand five four forty five thousand eight hundred eighteen blocks which is about one week um you definitely want to do your voting period in blocks as opposed to time um and this this is uh based off the current you know block time of ethereum this is about a week but it could change depending on the blockchain you're working on um again and the rest of these just needs overrides quorums getting the votes uh of different addresses at specific blocks so you know how much voting power each account has at different blocks you know propose checking the state of a certain proposal idea we have this proposed function that we talked about we have an execute function that we talked about uh there's a cancel function that you can do um and there's all this other stuff so um so we're just gonna like i said we're gonna use the wizard to grab that in there but that's gonna be the contract that has all those functions like propose like execute like q so that we don't have to reinvent the wheel for them um the time lock is not something that there's a wizard for uh but it's pretty easy to to implement here so we're going to do the license identifier i'm just going to paste that we do the solidity version i'm going to paste that too so i don't spell solidity wrong um and we're also going to import something from open zipline i know i'm copy pasting but it's because we're running a little bit lower time uh opens up and contracts governance timelock controller and this is like i said this is the contract that's going to own uh everything that's gonna have the ownership that's gonna have the money what are you referencing to know what was needed in the constructor uh good question so back up here in the constructor uh our governor contract takes two um two contract addresses as there's gonna be two contracts as their input parameters so it takes um the erc 20 votes token right our the token that asserts the voting power as one input parameter and then the time lock controller as a second voting parameter so when we deploy our governor contract here we say hey people are going to vote with this erc20 token and don't execute anything without going through the time lock so that's how um i know what what it's referencing and because i've gone through the rest of the code and i've seen what it does are the opens up and contract audited yes opens up on themselves is an auditor as well and they do a tremendous job cool anyways back to the um time lock contract so we're going to give this name contract government governance time lock is time lock controller and constructor [Music] oh and maybe this is actually what you're asking uh if you want to see these contracts you can do the opens up on github and this is actually how i learned about them uh as you go to opens up when it opens up with contracts let me paste this in the in the chat here go down to governance um here's the governor kind of the basic governor contract that we're importing from and here's here's the timeline controller that we're importing from um but you can see our timelock controller is going to be a version of this it's going to need a minimum it's going to need these constructor parameters a minimum delay proposers and executors the minimum delay is going to be how long you have to wait before executing proposers is going to be the list of addresses that we can that can propose something we're just going to make it everybody and the list of executors which we're going to make just our our governance contract so um that's actually exactly what we're going to do in our governance time lock we're going to say un256 min delay min delay address array memory proposers address array marie xeq tours then we're just gonna do my controller min delay proposers cute qtors already see executors i think of the pokemon executor oops it goes like this cool and now we have our timelock controller so we're going to deploy this contract and give this address for governor contract right under timelock controller so we have about 12 minutes left um so i'm going to kind of speed through the rest of this but this is all we need right this is our entire dow this is our entire token-based governance here so we have our voting power with governance token we have the contract that we want to govern which is box.sol we have our governor contract which actually kind of has all the logic for the for running governance and we have our governance time lock which delays um these executions uh from happening so we have everything that we need here let's just see them all in action so i just got to write a couple couple scripts got to write a couple scripts now and we'll be good to go so in scripts again this is going to be in python but in hard hat or javascript it'll be really similar we're just going to have a deploy and run that pie and this is going to uh we're going to try to go through everything we only have like five minutes left i want to keep a couple minutes for questions so actually there's there's kind of a lot of functions in here um uh yeah due to time constraints i'm actually going to just copy paste a little bit uh and then we'll leave some time for functions so um so yeah sorry i know we're uh we're not gonna go through kind of what everything's going on but i'll explain kind of what's happening in these scripts we'll run the scripts and um and we'll go from there so let me just uh paste everything in here uh okay so paste it everything in here we'll do brownie run scripts deploy and run see if this works did this work or did i mess it up let's find out right now cannot import governor contract governor let's change my governor to the governor contract let's try now let's pick the two we got five oh it's because i governor contractor deployed because the government contract takes two and i think in my descript i did five get rid of these uh wait actually i i'm just going to copy paste my governor contract from the um from the mix that i sent you just because it's set up to be a little bit more uh variable right i have corn percentage voting period and voting delay all as input parameters that we can change so i'm just gonna use that instead um because that way we can actually run run our governance without having to wait like a a week so i change yeah in this edition i change kind of how long it takes for votes to go through to be like a couple of blocks that way we can run through the whole thing uh like we're doing here okay perfect we can run through the whole thing without having to wait forever up just kidding i ran one more time lock operation not ready okay maybe i didn't operation not ready all right i'm gonna cheat i'm cheating guys just because we're we're like super out of time um he runs grips i'm gonna run on hardhead one more time all right so i totally cheated um but basically the contracts in that dow mix uh and the scripts are pretty much the same they're a little bit different with we added some more configs and everything um so you can just follow along like that and if you just hit run it'll go it'll do a ton of transactions um to go through this entire governance process in like a second right so in this script we actually deployed these contracts we proposed um to change uh the the value in our box uh in our store function to five uh and we executed it so uh really really powerful i'll quickly go over kind of like what the script is doing here and then i'll oh we'll we'll go into questions yeah sorry i know we kind of went low on time but everything is in here so first thing if we scroll the bottom our main function here's here's everything that we did so the first thing that we did is we deployed our governor contract which uh pretty simple um [Music] we go ahead we get an account we get a signer right we deploy our governance token um so i know there's a lot of stuff here but this is literally just deploying the governance token then something that's important is we actually delegate the governance token to ourselves so uh whenever you have one of these tokens you need to delegate it to somebody in order for them to be able to vote with them this includes um usually when you transfer the token you auto delegate however when you mint a token you don't auto delegate you have to delegate it to yourself once you deploy the token great next we actually deploy the governance time lock okay so we gave it a min delay we didn't give it any proposers or any executors we just gave it blank arrays and that's it right so we just set it up to be kind of blanket however we are currently the admins of that timelock contract so we can update these later then we deployed our governor contract and we gave it the governance token and the governance time lock as addresses saying hey here's the token that's going to govern you here's the time lock that's going to you know do all the money and stuff and then we added a couple a couple other parameters like quorum percentage vote and delay whatever this part is a little uh is important okay so uh each one of these roles like the proposer the executor they have a specific bytes bites for their um for their uh for how to define their role so the proposal role is a specific byte area so we get the proposal role by doing governance time locked up proposal role uh these are these are both functions we get the executor role and we get the time lock admin role which right now is just us so on the timelock admin we grant the proposal role to the governor we're saying only the governor um uh yeah excuse me only the governor can propose things right only so if if you call the governor contract and you call propose a governance contract can be the one to actually propose these things and we give everybody um the executor role so we're granting the role execute a role to constantly address zero which is everybody so anytime a proposal passes anybody can execute it and then we revoke the timelock admin role from ourselves this is important because once we call this nobody has authority over the timelock admin now and it's truly decentralized then then only the token holders can actually do things once we deploy it we just we deploy the box this one's really simple we just deploy the box uh then we call our propose function and i do want to go over this briefly because this is a little bit nuanced um but we um uh but yeah so we we get our arguments um uh and we kind of put them like this we put them in like a tuple and we encode them so right so this is the way that we encode our arguments we use this encode input thing in brownie hard hat has something similar um but we encode all of our arguments like this and we create our proposal like so so we do governance contract dot we give it a list of addresses right which for us is just that box addresses we're not going to send any ether so we just do 0 here we add our list of bytes encoded functions here right remember how we did that with comp when we created a proposal right if we scroll down decode input data this is exactly what comp did right they have these these encoded function parameters here and that's exactly what we're doing here and then we give it a proposal description which is going to be like hey you know we did blah blah blah and then we kind of just wait cool after we do the proposal this actually returned a proposal id we go right ahead into voting so i have this move blocks thing which is again because there's a voting delay so i just move the blocks by once we can go ahead and start voting once we vote here we do a vote with the proposal id which is going to be the integer which is going to be whatever number that is and then we cast a vote 0 being against 1 being 4 2 being abstain we go ahead and vote uh we called cast vote with reason there's also just a regular cast vote function but i wanted to say because i like a dude cha-cha um and that will be on chain which is kind of hilarious that i can do that um but so yeah so we vote yes or no for this proposal and we voted yes uh once uh once voting period is over which we moved the blocks because again this is on a local blockchain we move the blocks to the voting period once it's over we can cue and execute it if it passed since we owned all the votes obviously it passed um but we go ahead and we you know we encode the arguments again we call q with the exact same parameters as proposed so this is important in order to queue a proposal for [Music] for execution you just queue the exact same parameters and it like encodes this and that encoding is what it uses to map up the the queuing and then after we wait some time and after we wait the time delay we just call execute with the exact same parameters so i know this was a lot um and we're we have a couple minutes left here for questions um i know that we didn't actually get a chance to code that live however it's all in that dial mix and again if you're like hey like i like hard hat perfect um the script is going to be exactly the same just in javascript right but the solidity contracts are going to be exactly the same and that's how you can do a really minimalistic on-chain governance dow um you know using these opens up on contracts using these tools so i'll jump into these questions now your governance contract is missing some constructor arguments it was yup thank you uh all those scripts and contracts are in github no yes they are on github yes oh thank you should all dapps implement governments if the project is open source and decentralization is a key criteria amazing question um two answers uh maybe and maybe um so so uh so if so there are some protocols that are deployed with no governance intentionally right and that's actually the most secure way to do one of these adapts right because if it has no governance the code will never change it'll always do exactly what you tell it to do right it'll always um i should check to see if i have a meeting after this oh well um it should always do exactly what you tell it to do it'll it'll never get upgraded it'll never get changed which sometimes you might actually want um [Music] some people um so i know i briefly showed hey you can also do these these upgrades in a um excuse me you can also do this dow stuff with upgradeability that also introduces new risks right because if people can do upgrades to uh protocol and maybe you know maybe the new generation doesn't understand the protocol or maybe somebody malicious owns the tokens or buys all the tokens or something maybe that's something that you don't want to happen in the future so um and especially with upgrades upgrades introduce this whole new wave of potential risk vectors so you don't always want dapps to implement governments absolutely not and then in fact sometimes it's much better to not include governance but depending on the protocol is really the answer also the developers would hold the majority of the tokens of a project doesn't that make the vote kind of decentralized i think you mean centralized here but yes and this is where um you know fair drops on your governance token become important we didn't really have time to kind of go into that though how can i update my blockchain without losing the tokens i want i want to move my blockchain from east to polygon or avalanche i'm assuming you're talking about your dap um i don't know if it makes sense to move your blockchain to another blockchain um this is a a much longer answer i'm going to post a link though to upgrading smart contracts open zaplin once again has a really great uh really good blog on hope um on uh updating blockchains and upgradeability in your smart house i just posted a link that i did as well you're talking about something called like the social migration uh upgradability i also called it the you know method because i think i'm funny um but really you want to do some type of social migration to your new application and definitely check out that upgrades video and the opens up and blog on doing upgrades that'll give you pretty much everything you want to know get a proposal to govern a contract but whoever can call the governor contract's purpose method can propose anything amazing question yes so um yes so if i call propose on the governor's contract in this example uh and we gave um yes anybody can propose anything which can be good it can be the way that you want it to be you could restrict that proposed method to being certain addresses right so you 100 could do that um the way we set this up is yes anybody can propose anything uh which might be the best way it might not be is the governance token to security like a share stock with voting right that's that's going to be some legal gray area i do not know how to answer um the precedent is being set you know we see ave we see the uni token we see comp token um i don't know what the sec has said um so i'm i'm unclear um at the moment i would guess no they're not securities because they have this utility but i don't want to say i don't want to say 100 for sure uh anything here but um yeah that would that i would love to get you know um some more legally inclined people to answer that question but from what i've seen it's it's okay but uh but that's just from what i've seen how are governance allocated i'm assuming you're talking about governance tokens uh this really depends on the um the drop uh how how these tokens are dropped right it really depends on um yeah the launch of the token uh some have different protocols have different ways of doing these these launches um i think that um having a fair launch in mind when you launch these governance tokens is really important for the centrality of your project and for the the little yeah the legitimacy of your project so it it really depends it's going to be the answer there the point of these dowels are to propose stuff like third-party contracts like box that sold yes or whatever you want to do like ave for example maybe you want to propose you know adding a new uh adding a new pair to borrow and lend changing reward rates for different uh tokens maybe upgrading or adding you know a different blockchain functionality or you know upgrading to a completely new protocol right can be there can be a whole range of things that you want to do that need some type of governance and having these governance having these dows reduces that centralized authority right because now you have a community collective voting on how to move forward how do i update my smart contract super general question i actually posted a link to upgrading smart contracts in the chat there definitely check that out opens up one's blog on it as well upgrading smart contracts is fantastic uh check those out we do have an upgrades um demo i think today and tomorrow at the end of the day so be sure to watch the upgrades uh we have we have a hard hat one and a brownie one actually so for those who like hard hat uh definitely be sure to check that out their package library for all the elements functions etc in python brownie yes how do we ensure governance is going on the right path and not end up destroying my project um good question and that actually might be might be the answer there right so you said how do i make sure governance is going the way that i wanted to and not destroying my project and that might be the key actually right there right my project once you launch a dao once you launch these governance projects it's no longer your project you created it you founded it but it now the governance belongs to you know the people the token holders so how do i make sure people do what i want um that's a really interesting question right it's it's kind of goes it's the antithesis of what we're trying to accomplish here now obviously you can exert influence and you can you can explain hey here's why i think that it should go like this but met you know typically you know two heads are better than one right um so that's kind of the answer there it's hey you know it could totally be out of your hands now you can obviously introduce back doors to your smart contracts but then you just reintroduce that centralized vector right you are now the centralized point of failure which kind of defeats the purpose of having it down if that's the case what's the point of having governance if you don't have full control of it well uh if you don't if you want to have full control don't do governance um if you want to have truly you know if you want to have a decentralized protocol um you know don't do a smart contract uh yeah if you excuse me if you want to have a centralized protocol don't do a smart contract um it sounds it sounds like what you're trying to do is not a dow it's not governance you could or like a dow theater which could totally be fine it can totally work and if that's what you want to do that you can absolutely do that but if you're saying hey i want to make sure you know the protocol goes where i want to go well then maybe consider not making it a doubt good questions all right cool um well thank you all for coming i hope you all learned a lot this was a blast and this is literally cutting edge stuff here this is one of these never before seen tutorials these never before seen workshops um i hope you all learned a lot um and uh we'll talk to you soon like i said there's we have a fantastic lineup of workshops today the upgrades one later today is going to be out of this world for everybody asking about hey how do i upgrade how do i do this other stuff dowse and upgradability can definitely go hand in hand it can make for really really feature rich really powerful smart contracts uh definitely be sure to check it out and we'll talk to you all next time so uh thank you so much talk to you soon whoops wrong button oh also remember to take the uh the feedback form i'm going to post that in the chat now if you enjoyed this workshop i'll leave some feedback here and talk to you soon all right thanks all bye you
Info
Channel: Chainlink
Views: 11,191
Rating: undefined out of 5
Keywords: Chainlink, chainlink, Chain, Link, chain, link, #chainlink, #Chainlink, CHAINLINK, #CHAINLINK, #Hackathon, CHAIN, LINK, #ChainLink, #Chain, #chain, #CHAIN, #Link, #link, #LINK, Hackathon, hackathon, #hackathon, HACKATHON, #HACKATHON
Id: rD8AxZ_wBA4
Channel Id: undefined
Length: 70min 8sec (4208 seconds)
Published: Tue Nov 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.