DAO Hack: Performance Bonds Workshop

DAO Hack 2022 · 10 Mar 2022 · 43:48

Aodhgan Gleeson, a smart contract engineer at Windranger Labs, presents performance bonds, a product built for the BitDAO ecosystem. A DAO treasury funding autonomous entities faces counterparty risk, and a bond backed by collateral returns funds if agreed milestones are missed. The workshop covers the bond lifecycle, user roles, the specification and the Solidity contract architecture, including the bond factory and ERC-20 bond contracts. It ends with a live example wrapping a bond so depositors also receive an NFT.

Speakers

Topics

From DAO Hack 2022, hosted by Encode.

Transcript

great well i think we have most people joining here uh thanks everybody again for joining um right here is going to be the second workshop of our series with the dow hack with bitdow this is going to be the performance bonds workshop today with me i have aegon he's a smart contract engineer for wind ranger labs they currently work creating products in the big dow ecosystem so they're heavily tied with bit down and he kind of has some products and code base he wants to show you today here for this performance bonds workshop so i'm gonna actually turn it over to him he's a very bright guy and

i hope to learn a lot here today even myself so i'll turn it over to him here's aegon yeah thank you steve um yeah so all right so yeah my name is aegon uh i've been doing smart contracts for a few years recently joined windranger which is kind of associated with er tao which is one of the largest stars out there and focused on building like tools and infrastructure for dao's as well as um uh nurturing uh autonomous entities which can are kind of like uh sub-dials so uh one of the uh products that we've been working on is performance uh bonds

and that's what this workshop is going to be focused on so yeah just today i'm going to give a run to you like why we're building performance bonds like how they're used and what problem they solve we're going to have a little look at the specification so this is the initial version of the bronze product and so it's it's a pretty minimal specification and so we can step through that we're gonna have a look at the like smart contract architecture um how we have implemented it and that might give you some insight as to like how you can

use this product and creatively or in a workshop setting and we're going to do a walkthrough of the code base and then we can have a example integration if we have time at the end so why do we want to build performance bonds well um if you have a treasury that wants to fund autonomous entities um you have a lot of counterparty risk in terms of if you start giving away tokens saying that exact in the case of bitdown bit tokens as as you dive as you invest more

and more of your treasury it becomes more and more like uh risky essentially so performance bonds are a way to reduce that risk and reduced that economic risk so uh how it basically works is um and thomas anthony will come along and propose a project so if we we have like a scenario here where a made-up dog called blimp dao wants to buy a blimp and they approach bit dao and they say hey we'll give you some collateral so this the bond can be uh over or under collateralized

um so they'll give you some collateral or something in exchange for a load of these bid tokens and then we're because we're going to buy a blimp and then if they don't buy the blimp after a particular time period um the collateral that the bim blimp dial um supporters provided is uh returned to the bitdown treasury so uh not as much a loss would be realized uh by by bitter is essentially the idea so that reduces the the risk to everybody involved

and so that's the the sad case where they failed to buy the blimp but if they bought the blimp uh the people who who provided the underlying collateral eat in this in this case is like return to them so everybody is is happy so how else would these performance bonds so that's kind of like uh case two here like reducing the ability for a new autonomous entity to kind of rogue pull and it also including like increases community engagement so this is like a product okay so it's mostly built for bit tao but

uh other dios can use it too um so it like gives them a way to incentivize community engagement so if you have a dao and has a token and it's just kind of sitting there and you may be using it for unchained governance maybe you've delegated it or whatever so um it's it's something it gives you some sort of use case or utility for your token as well um as well as kind of like aligning like long-term incentives so if you want people to hold your token for like a longer period of time um why not lock it into one of these performance bonds and um

it just increases a long term alignment and then for use case number three here dow co-investments so like it's kind of like oh there's a lot of ideas floating around and a lot of autonomous entities that could be formed um but this is one of the ways that an autonomous entity could could start um just like blimp that blimped out um otherwise it's kind of it's a it's a good starting or entry point and to becoming an autonomous entity so i'm just going to skip ahead from the slide and maybe come back to it so this is a

a screenshot of like what the product might look like from a actual user's perspective so just looking at the user types right there's three main types there's like a proposer so that's an outside party and autonomous entity that is like looking for funding basically so they're proposing they're going to create a bond and then try and get people to purchase it there's a bond admin uh who kind of and these two priorities can be can be the same where it's like they've created a bond and then they have all of the kind of admin functionality involved around it which we'll we'll look at

in more detail later and then there's a guarantor which is a like a like an end user so a holder of whatever token an investor basically so uh this is like a screenshot of what it might look like a mock-up screenshot um of like what the actual end user might see so you can see here that it's like this is the name of the autonomous entity um this is like the date that the performance bond will expire by so in the case of blimp it blimped out um it would be like the first of june they

must have had purchased the blimp by the first of june this is how much room there is in the bond so as we'll look at in specification there's like um a maximum amount there's like a minimum amount for the for the performance bond to um exist and then you can see there'd be like an input you want to contribute like 100 tokens 1000 tokens um and you can see here in the background that there's like these are all of the different um bonds available to the user at that moment in time so you can see here this is like a a hat tip to the car or lambo project that recently

happened with ebitda as well the nfp project so um yeah so uh as we can see here like so the performance bond is is uh dependent upon certain off-chain criteria or it can be off-chain or entering criteria being met so these performance factors so in the case that this is like a new autonomous entity and they're looking for funding they have like these these are their targets that they have to hit right so they have to have a multi-sig set up by the first of june they have to have a landing page set up by the first of june and any other kind of factors right

and so as we'll see in the specification if they don't reach these factors then some of the bond underlying collateral that the users have provided will be reduced over time so the kind of life cycle of the bond um is that the bond is created first or is proposed is an autonomous entity comes along and says we want funding for this project like blimp doubt so this kind of mostly would happen offline you know and offline meaning like um discord or in some sort of form or some sort of maybe even snapshot

so then the bond is like actually created on chain and after that point users or guarantors can start purchasing the bond any amount of bond that they want so the bond in this case is like as we'll see is represented by a near c20 the bond is filled so this means that the maximum cap the amount of collateral provided has has reached a minimum and is under the maximum so it's kind of it's um it's it's available to be kind of close over time um so no more people can kind of come in and

out and everything is set in stone until the bond uh is assessed so i think and again a little bit limped out go and buy the blimp and then on chain like it's uh assessed whether or not all of the performance criteria has been met and then when it's available uh people can come and start redeeming the bond and so in the happy case the blimp has been bought the collateral people can come and pull their collateral back from the um in the performance bond contract so yeah i think we've we've mostly mostly mentioned these and and these are these these next couple of slides are mostly

here for um for reference after the workshop so won't go into too much detail but um i think maybe as this is like a technical workshop we should step right into the uh the code and then maybe we can come back to the um to the specification as we move along and so just the contract architecture right so um it's a it's a i would say a medium-sized complexity system in terms of smart contracts but the two important smart contracts are the bond factory which has the create bond method on it

and so this will actually create a bond and a bond is a each bond each performance bond is its own smart contract so within create bond we have created this new erc's 20 single collateral bond and so for the first version of performance bonds there is only the ability to provide one e underline ear c20 as collateral um and the we have not yet built a functionality to accept like a erc721 so it's just a simple it takes one erc20 compatible token and so that as the bond itself is near

c20 token uh there's like two methods that users mostly would care about and it's deposit so that's when you are purchasing a bond as a user and then redeem so that's at the end of the life cycle like we just talked about and when you want to get your uh funding back or your collateral back from the um from the the performance bond so i'm going to start sharing a different screen now i think so this um you can see my uh visual yes so this repo is available uh there's a

there'll be a link in the slides but it's available in here and this is wind ranger io and then so this sort of project is related to the treasury so this is a public repo and we're just going to be looking i've obviously cloned this on my machine or whatever um and this in turn actually is i should point out at this stage is like a fork of the template repost we have a if you want to get started on a um smart contract project we have a template a public template that you can fork

and it's set up with all of the it's opinionated so it's set up with all of the kind of stuff we use to develop smart contracts some of the best practices here at wind ranger so just not like a high level we use solidity for most of our contracts we also use typescript and hard hat like extensively um and i think you'll find that there's like a huge focus on quality assurance or testing within all of our smart contracts at wind ranger um as i'm sure everybody is aware of the

risks involved with with immutable writing immutable code so our um our treasury repo is a fork of this in turn so uh we'll be having a look at this this is where the performance bonds so uh the foreign spawn contracts live within here so we have the bond contracts here and this is like the treasury repo is because we are planning more than one um set of a set of contracts so there'll be performance bonds and then it'll also be like a staking product that we are also currently working towards but we'll just focus on the performance bonds

today and so this is uh as you can see so i mentioned earlier that the main entry point into the system is the bond factory so here we were out here we've stepped into bond and then we've gone into bond factory so um we're using solidity eight and above so 0.8 and above so we have all of the nice new safe math stuff and everything we use extensively open zeppelin contracts all of our contracts are actually upgradable um which kind of will facilitate us to move from this mvp that's currently specified out to like a

um more advanced version so as i mentioned oh this is only accepting one erc20 as our collateral and then in future whatever versions are planned where it is accepts more than one token as um collateral so uh the we're using the open zeppelin uups upgradable style proxy contracts and so that's just to note that most of the bonds contracts are also possible um this is like to mitigate risk or whatever we envision is like the first users of the performance bond system to be autonomous entities uh kind of within

the greater bidau um ecosystem so we already have a few uh autonomous entities that are like waiting for this um product suite to launch um so uh so this is yeah this is the main um entry point into the system it's actually not like doesn't have any sort of commissioning on it so anybody can can call it and then the restriction is actually on the um the bond um this sorry the dao must all have already like white listed both its treasury address and it's um the acceptable forms of collateral that

the dao is willing to use but anyone can call this as we can see and we will be creating a new erc single collateral bond contract which is where the actual meat of the system guys so we'll step in and have a look at that it's down here i don't know why my thing isn't working um so we can see it is like a large contract that is also an erc20 so this is how the accounting system for the bond works that when you deposit into this contract you will

tokens will be minted to you um and then when you redeem at the end of the life cycle tokens will be burned and so that's kind of how the counting system works and in the meantime you can do as we'll see we can do all sorts of other things then now that we have this bond erc20 representation in our wallet you can also then kind of send that around a place and show people your balance or whatever of this particular bond so we have like the bond has an associated like time based life cycle and so we have a few

it's in here that shows you when the bond is going to expire like in in unix face time and this is a the interface that it's associated with uh it's got like a place to put some metadata about the bond it's also an ownable contract so that whoever creates the contract has a load of um admin powers so that relates back to uh the user type slide i showed at the start where the bond admin has some particular privileges um such as um

slashing the bond so slashing is a concept where if the performance criteria is not met then the bond admin basically um reduces the amount or slashes the amount of um collateral in within the bond so the if the targets aren't being met that's uh the outcome um so yeah all of our the there's some of the functionalities is possible for safety related reasons um redeemable is a another interface

essentially your abstract contract that um shows you when the that manages when the bond is redeemable or not and then version we've version all of our smart contracts which is literally just like a hair-coded string that shows you um what exact version of the contract you're looking at which can help you ahead of some complicated um scenarios when you're looking at immutable code so let's just move that move along and uh um [Music] have a look at deposit functions so how you actually get in and out of the and bond so this is the main function that

users are expected to call in order to purchase or support a project such as blimp dial so as we can see there is like obviously six insanity checks and there's the concept of minimum deposit size which i've alluded to previously so when the bond is created it'll be say like a minimum amount that you can contribute and once you have met this minimum amount you can continuously buy as many bonds as you want up to the maximum amount of bonds available for that bond so yeah you are and here is where you transfer in

your collateral token and then uh down here we can see that we are internally transferring this erc20 token to whoever has called this function and we're emitting events and we're doing some uh some checks so this yes this is the main entry point and you can obviously see that it wouldn't make sense that to be able to call this when the contract is is paused and also when it's redeemable so when it moves into a redeemable state this means that the kind of bond is it's over everything is finished so you wouldn't be able to

deposit in at that stage so let's look at that the completely end of the life cycle and function oops and so this is the redeem function again you specify the amount that you want to redeem which is probably just your full balance of and some more sanity checks and then this is actually where things get a little bit interesting because the um in the meantime over the life cycle of the bond some of some slashing may have occurred if the performance criteria was not met

so we calculate how much slashing occurred if it did and uh so say if there was a hundred each worth of collateral and there was a slashing event that slashed 10 of all of the collateral so now there's only 90 each of where collateral back in in the performance bond and that could be because blimpdow failed to launch their landing page for their website in time or something like that and so proportionally everybody will get back less so there's a reduction of 10 each so only 90 each will get paid back

to everyone so this is where the kind of proportional calculation is happening and then we are burning the ear this bond e or c 20 proportionally for for the user for their for their full amount because they can't redeem again but they will only get the amount the proportional amount that they are entitled to and so yeah that's a kind of the performance bonds in contract in a nutshell and how to get in and out we'll look at a little integration example uh shortly um but i think it might be worth having

a look at the other functions involved here so this is the slash function that i've been talking about so slashing is only only the owner can do it um so in version one of this um product a lot of trust is based on the on the owner or the admin of the the dao admin that has created this bond um so if it's kind of like a self self policing in a way that the performance criteria has not been reached and they'll still slash for a particular amount and reduce the amount of collateral in the system transferring

out to the pre-specified treasury for that particular doubt and so as you can see here when you're setting up a dao each day has like we're keeping a mapping here like a dao has an id a unique id have a un-256 across the entire system and then they have a treasure they're identified by a treasury and a white list of collateral so if you look at the white list it is like a a set so an open zeppelin innumerable set of tokens um available we're also storing the symbols for

um convenience and so when you create a dao you have to specify this stuff like treasury so that when you when slashing occurs the tokens will flow back to this treasury and the treasury um can't be changed so there's like no rogue pulling vector and the bond the performance bond can only be created against um collateral that the dav has specified at the start as well and so yeah we can see here that it's the collateral when it's slashing has been returned to the treasury um okay

and then there's various um the kind of periphery stuff in here is a we're using open zeppelin access control which is pretty cool uh permissions permissioning library like a hierarchical style role-based rule-based access control so we can see that we have like a kind of top level dao admin um we have a system admin and we have a bond admin so there's like various levels of permission you know what each of these actors can do and based on spec and like the product requirements so say for example that the system admin

is the only role that can uh perform a system or sorry smart contract upgrades um whereas the bond admin can do things like um slashing um and changing particular parameters and what other contracts are interesting some of these are um so yeah we have a concept of a bond curator um which just kind of is like a layer above if you have a

diode that has several uh performance bonds at the same time it kind of groups them together and we have a bond mediator which is a which is a kind of another level above again that um creates bonds for particular dials and manages them in a kind of in a group together and do we have any questions before i move forwards to the um to the like integration demo maybe if i

talk a little bit more about like just the the setup in general here um in terms of so this is our bonds product most of the stuff lives inside the this directory here and we also have some stub dive functionality for what these various treasuries that the the they just need to be basically compatible for year c20 tokens to come in and out of we have some contracts that are used for testing they're not very interesting the uh sweep contracts are if you send a token accidentally to one of these performance bonds you you

haven't called deposit or redeem you've just tried to transfer in and out it's kind of like prevent prevents and helps with this functionality then we have interfaces for planning on how to interface with different strategies that live in in different repos and places so and that's pretty much the layout and in terms of just like the whole repo um so as i mentioned we use hard hat we use a lot of typescript um in here we also use husky which is like

a commit pre-commit hook thing that like will run all of the lenten basically download the template and play around with it because it's a very uh detailed and strict environment that um helps you produce super clean and mitigates like the risk in terms of code and we're also using a type chain so with typescript we i don't know if you guys are familiar with typechain but it generates typescript types for um

for use with testing and and even um helps you out with deployment and so yeah um [Music] i think that's that's pretty much everything you need to know so again maybe our testing we have like unit tests we also use slitter which is like a static analysis of the smart contracts can help you use sawhand for for linting but slitter can also help you find it's like you define like a set of rules and they can help you uh figure out if your contracts are

adhering to those rules that are um some of them could be possible like security vulnerabilities and so i recommend checking out that tool as well so that was the code walkthrough and then the links are here so there's a more probably a better definition of what performance bonds are this is the treasury that i've just walked through this is the template that i've been mentioning we looked at at the start it's also a link so when drinker are hiring or whatever so um if you're a solidity developer product or whatever even if you're really into testing you just

saw how tight our environment is in terms of testing so there's that there too so i think we've got a few minutes so i'm going to um show a demonstration of how we can actually use the performance bond so the concept here is we're going to um we're going to show how you can write a contract that deposits into a performance bond and so we're going to create a contract and we're going to call it like wrap bond we're going to create a a wrapper around our bond

and within our wrapper so if we were an autonomous entity that wanted to create one of these performance bonds for some reason they might also want to uh mint an nft so for each person like a kind of like a coap style thing if you guys know that protocol where it's like you get minted and nft for um doing a particular action and so in our case we want to mint an nft every time a performance bond every time you have deposited it into or yeah every time you have purchased a performance bond so you

could then add some utility to that nft like um access into a special channel in discord or whatever sort of utility um or just you know use it to display hey i supported this uh the birth of this autonomous entity um by purchasing a performance bond so that's just a a quick demonstration that we'll we'll use um and i'll step you guys through how you can interact with these set of performance bond contracts so i'm gonna like just copy and paste in something and so we obviously have

our kind of standard header there for solidity contracts and i mentioned we're going to be creating nfts so open zeppelin have this nice um contract where it's like an erc71 out of the box with like uh with the like the nice ability to um mint and burn from whoever sets it up and just uh everything is generally set up correctly for for this sort of applications call it wrapped

bond um so we're going to inherit the 721 contract and because we want to be able to enter nfts and so it's saying my editor is complaining saying that i haven't uh that it should be abstract because i haven't implemented whatever this constructor needs so again in the interest of time i have i know what that constructor wants it wants a if we look down here it wants all of this stuff right so name name of the nft the symbol

and the base token uri so i'm providing i'm giving it all of that stuff and also in this case we're going to want so as each bond exists as its own smart contract we're going to want to tell it where the bond contract actually is so this is the address of the bond contract and so we're going to set it up in the constructor as well so right in the wind ranger uh repos like we're using yarn or mpn so if you type here and build it should

compile all of the uh all of the files including this uh new one that we've we've written called wrapped bond although it doesn't seem to be happening here so you can see it compiling it will create that's a type chain notification saying that it's creating uh types for this so okay great it seems to work so we have our now we want to interface with the erc set uh your c20 single collateral bond that we were spent a lot of time looking at earlier and as we mentioned like the main way to get in and out is like the deposit and redeem functions so we're going to want to call this deposit function on

the contract so we're going to write something like function deposit and which will say deposit and get nft or something like that and then we're going to want to specify the amount going to be an external function modify a state that people can see so um and then we're going to want to call it we want to do some like sanity checks which we won't do and then we're going to want to do bond so we want to call the deposit function on the bond to get in right

and then if we look at the um function uh if if this stuff if it's paul's not redeemable it will like revert so we don't really have to worry about that behavior and so and it doesn't return anything so we can just call it like that and then so it will successfully step down here and then we want to min so in our case it will be you can just call the mint function that we've inherited by the egg including and this erc contract up here

so we're going to want to end it to the person i call this function right and so yeah so now we have successfully um implemented like a wrapper contract that has each time you've created or you've purchased some of the performance bond that you've specified up here you're now going to also get an nfe and then we can do the opposite which is where when the user wants to and redeem to go to other way when everything is when the performance bond is finished maybe you want to keep your nft forever

or maybe um you don't want to burn it but we can still um explore that functionality here so we're just going to call bond redeem and then maybe you would want to burn an ft so you no longer have the nft you no longer have this um and see what this says not sure what argument it takes but we'll build and see if it um [Music] um so yeah that's just one very basic

example of how you could integrate a like a performance bond into your bond product or your sorry your product and so yeah i think that kind of like concludes my walkthrough and my little demo so if there's any questions i'd be happy to take them awesome thanks again that was great um yes do we have any questions for our speaker while he is still here doesn't look like it well thanks again aegon and windranger here um for speaking at this workshop it was very great insight into performance bonds understanding kind of the community

engagement within creating these and awesome demo at the end showcasing how to kind of create this wrapped bond here with some minted nfts very insightful thanks to everyone who joined here for this workshop we will be having a second workshop for the dow hackathon next monday it is going to be posted on our mediums and our articles please look out for that i'll actually post the link here if i can get to it um one moment and please you know ping me any questions if you are in the dow hackathon

i'm happy to schedule a call with you anytime understand kind of any questions you have and give some feedback we're here for you these slides that aegon has shown us will be posted online tomorrow along with the recording of this event and awesome thanks everybody for coming and thanks again to aegon gleason here for showcasing his talents it was great workshop and we appreciate you taking the time out of your day to come speak with us and kind of show you show us what you've been doing here at windranger and bitdow so thanks again and

everybody have a great day [Music] you

Related talks