DAPPCON 2019: Workshop - Training with a New Binding Library w/ R. Mazet & J. Wojciechowski (Alice)

DappCon 2019 · August 2019 · 45:17

At a DappCon 2019 workshop, developers from Alice train attendees on a new binding library for building Ethereum applications, covering how it connects front-end code to on-chain smart contracts. The session walks through practical setup and usage, drawing on Alice's experience building outcome-based funding tools on Ethereum. It gives developers hands-on practice with a tool aimed at simplifying dApp development.

Speakers

Topics

From DappCon 2019, hosted by Dappcon Berlin.

Transcript

I'm the both of us I'm Raphael I'm CEO Valles this is cool bar this is our CTO we're both cofounders and we we came to this because we have a social defy company and basically we're working on exponential social finance the idea behind what we're trying to solve is that there's trillions of dollars that are being poured into social environmental projects every year taxes grants everything you can think of and we're not moving the needle fast enough in terms of solving the word the world's social environmental problems and the one of the main reasons for that is that we're not tracking there are no incentives to actually track what works and what doesn't so what we do at Alice

is basically build a protocol that turns impact into a financial instrument because the idea is that is if there is some money attached to achieving impact then people will want to track whether it's being achieved and the way that that work is we have a collateralization system essentially what we do is we bring together people who want to pay for impact so let's say donors to make it simple but also taxpayers conscious consumers or whatever they want to pay for impact but only if it happens so that means that their money is put into a collateral pot that only gets paid out as and when say a charity or social organization achieves its goals but

obviously that organization that delivery organization needs the money upfront to start running a program so that's where investors can provide that upfront capital and we have a tokenization solution you can see here which is that when you set up this impact future so a financial primitive that we're using to run all of this is called an impact future people can put collateral in and then there is a tokenization of what we call impact credits that are given to investors and those give a right on the unlock collateral as and when it's proven that the charity is has achieved its goal so for example we're working with st.

Mungo's which is a homelessness charity in the UK they make promises about how many homeless people they're going to homes for they only get the money when a validator says that they've achieved their goals of finding homes for people but they can sell on the impact credits so that when the collateral is unlocked it's the investors that get the money so the charity has the the money that it needs up front the investors have return on their investment and the donors are really happy because they know exactly what's been achieved so that's kind of the basic Alice system and what it creates is just a ton of data hopefully at scale because right now we're we've run three live pilots we have another

ten that are in the pipeline they're going to go live very soon but the idea is that you have all these data about all these projects and whether they work or not and you can start benchmarking and scaling those that are really effective so where we can where we come with where the green OSIS comes in because we're do I have the slide here somewhere at the it wait in a second all right there you go we're Gekko grantees we received a grant to build the the binding library and just to go back I'm going to explain why we we're doing that so these are some of our partners first of all these are the types of charities that were working with Cancer Research UK we've done a bunch of technical integrations as well

Vodafone foundation etc but what we what we want to do is that if you're investing in a social environmental project and you're taking on the risk of it not being achieved so say this delivery organization does not manage to find a home for these homeless people that's absolutely fine you can take that risk in isolation but there might be external factors that that affect the ability of the delivery organization to to achieve its goals so what we want to do is use a nurse's prediction markets to allow investors to hedge against those external factors we also have the idea of allowing beneficiaries and any

given social project to be able to use prediction markets to signal whether the the the program that supporting them is actually effective or not but that will be they'll be further down the line is everybody familiar with how the prediction markets work and how the conditional tokens work more or less yeah I'll just do a really quick overview then this is kind of like the simplest way that we can that we that we can come up with to explain it is basically anybody can create a condition for something that's going to happen so for example do I think that brexit is going to happen yes or no and you create this condition using the grossest

protocol and it spits out these conditional tokens with the all the range of possible answers so it was Briggs it's gonna happen it's either yes or it's going to be no but the really cool thing about the conditional tokens is you can also split these conditions so you can have child conditions or nested conditions based on the principle one and that is for example if brexit happens will there be a recession and in that case the collateral that you're putting into the initial condition right because it's a bet on whether it's going to happen or not and the people who get the right hands they get the collateral that's held in there in the initial condition you can actually actually transfer that split it into the child

condition and that's literally what the the conditional tokens allow you to do so the way that we want to use them is you have this homelessness project is it going to be affected by brexit happening is it going to be affected by something else and we want to plug that in so we were looking at that and essentially it's quite complex to manage all of the the abstractions there and to calculate all the different nested positions to do it in on an operated way so I'm going to pass it on to kuba now who's going to explain exactly why we set about doing the the binding library if I can manage to get this or think oh okay

so when we try to reach our business goal so building this system for hedging risk for social project and started integrating we've know this conditional tokens we explore the smart contracts and I must admit it's a great piece of engineering all of credit should go to to Alan well I love it I love it's very minimalistic very lean very distilled and that's where is super efficient in terms of gas it's easy to manage the critter such a small code base etc but

the trade-off is that integrating and using smart contract in your dubs could be a bit problematic because there is absolutely no storage for tracking for convenience in the smart contracts and all of the low-level calculations are done on on hashes ID calculation concatenation of that it's pretty complex structure that needs to be mirrored and mimicked on your client side and it's let's say it's not the most creative not the most entertaining process for developer just to mimic all

of the smart contracts so you did code inside your DAP it's probably taken well I know a day or two of hard work is very error-prone you can quite easily get into mistake especially dealing with larger numbers so having a robust robust solution to easily connect to gnosis smart contracts mmm-hmm have a nice interface could be could be helpful and as we get through this painful process we we wanted to give back something to the community as we receive the grant prognosis so if you find it helpful useful that will be great let's don't let's get through the same thing on suffering that we did with the binding library so in other words you

can focus on really interesting creative tasks building can iced up for your business purpose instead of like doing the boilerplate code mmm what can you learn for the next hour you know that it's not the best timing we are competing with the land so we want to promise you something instead of skipping the food cards so you should learn how to create conditions treat merge conditions how to report results redeem collateral and how to manage a more complex structure of multiple nested positions and the main benefit should be basically to fully understand the mechanics of conditional tokens not

listening to abstract talk which is hard to grasp but doing it by yourself coding experimenting creating merging splitting all on your own and I think it's the best way to fully understand what's going on and obviously you can learn how to use a tool that will allow you to build apps quicker so we prepare a small set of scenarios kind of interactive that should put present you with some some tasks some tips some hints in the form of travel tests to follow and experiment with that let me

maybe open so that's the link to the github repo mmm obviously we are going to be around to help you install all the necessary dependencies all of the tools I don't know if you are familiar with using truffle and ganache if somebody is not familiar I'm happy to go and teach how to install it and yeah I think let's start I said holding the piece you should get to and I would start by giving who I don't know who is going to follow the hands-on coding okay that's fine yeah so

let's give you like a few minutes just to download all the stuff down repo install dependencies and then you can give it a try and maybe after five minutes I can also like present you the correct answers or any of you can feel free to go and choose and the answers you you you you

you you so there is documentation in the readme of the repo that should help you to complete all of the tasks you you

okay for everyone who is struggling with to compile the original you know this contract and just pointing you to the the working configuration of travel with the correct CDT version let's try to work it'd be simple yeah that would be nice yeah okay I

think that let's maybe try to go together because some people are not coding so it could be beneficial for them just to look how it works practice I would try to I would try to make it pass so I think you try so so first we need to create the binding library on top of the prediction market system contract let me just [Music] okay let's track down the twist and so get to the first test obviously

there are other ways to initialize HD not to be known about the idea is to remain in to and focusing on building prediction market bindings and then another task was to create the first condition it should also be like one-liner so we used annually then we pass some idea of the condition i'li should lead to some external

metadata about the condition but we can pass anything for the test purpose than first condition then we point to the Oracle that will provide results for this condition and resolve the condition we used one of the injected test account but obviously will be any system external system linking to reward data like chain link Al Gore it could be we out here anything that you may think of and we define how many possible answers could be given by for this condition

outcomes not a lot so I hope that interface is intuitive but any feedback is obviously welcome and now all of the fun begins so we put some tokens and we try to do the magic so split against that condition to create two positions so let's first get some tokens our talk is called

tariffs which is a simple year see 20 min table token so we can easily create mmm thanks for the test if our user some tokens and what's also important and we should allow the prediction market contract to take out on our behalf the tokens whenever we decide to create a position so we used a lot of approve allowance mechanism of year see 20

tokens and allow and approve PMS certain amount of tokens to be taken now let's try to speed so for the speed we pass a collateral

address so which token are we going to use as a collateral for newly created positions and what what amount of our other ones do we want to use for these positions obviously you can create and approve other ones much higher that we are going to use for the first split so we get like a credit line for our interactions what's also interesting we use the function called full speed which is a little helper so instead of passing all of the possible positions in our case isn't very complex because we got only two answers but for bigger asset set it could be a mmm troublesome task just to

prepare an array with all of the possible alternative so when we use the full speed the library takes care of that and what should happen so we should get two positions maybe let's check first [Music] it's the first test so what we've done first we can see that the user balance mmm it's reduced to zero because

actually the prediction market system used the given allowance and all of the tokens are held by the prediction market system contracts so we passed the collateral to the contract and then we can also check the balance of positions and every position gets its unique identifier we we may treat as a kind of token to use a multi token standard 1155 of eternal to handle the scenario in every position because it's unique token that we may further transfer trade exchange for some other tokens okay and then let's try as we speak we might try

to emerge then you will create a position see what's gonna happen so here we also is a little helper method so instead of remembering all of the positions we can call March all so of the position that have been

previously created on that condition are automatically merge it just takes you a little bit of time for tracking positions of obviously there is an alternative way to do it when you we can pass the array of position to be March let's let you stir the shortcut first yes so if we hold all of the possible alternatives obviously whatever happen we'll get back the collateral so merging them actually mmm reduces the the sort of Feltham the full set of alternatives

so we get to the first stage let me also comments away when we are from the marriage automatically mmm the collateral is sent back to the user account so we see that user has backed the hundred tokens that we mean that for his account and the prediction market system contract it's currently without any holdings so yeah that's maybe spent like five minutes for for you to work on the on the second stage and we can fill in their answers later on [Music]

you don't have so we don't have a lot of time so let me try to fill in the answers could be also more interesting people who do not actively code and have you managed to get the solution our report with yesterday at this taster anyway okay so I can provide the answers and comments you can do it later on at home it's not a problem okay so let's first with border resolved and we pass the result as an array

indicating which outcome was successful so that's the message from Oracle Oracle is calling this she's called Smith odd so that's my first position as a winner and the second one as a loser so the convention is that you put values per every outcome and positive value up to one indicates a successful result so they could be like two winners if we get for example three outcome slots and how for the first outcome slot how for the

second one and zero for the third one or we can have a draw when we get half and half in this scenario the the library also tries to do a nice trick with automatically fetching the Oracle from the available addresses of a provider so you do not need to you switch your context obviously we don't happen interest

should be fine and let us try to redeem the collateral for positions so first we start with a losing position and see what's happened but look at the balance is held by user and EMS okay that's the question what should we

put here what do you expect to be a user balance on this position so the hint is that it's a losing position yeah sorry losing position should be redeemed to a zero collateral and let's check what's going to stay on the prediction market contract and your guesses about it so yeah so we

sent there 100 we get zero so the expected value should be 100 if there is no money disappearing in the prediction market system thank you okay it works fine and lets out of curiosity do another check what's the balance of our position tokens after redeeming and successful position because we can either have this let's say go stalk us without any value do you think in the

system which is not nice or maybe we just destroy the balance let's see how PA must handle that situation that's not all

mm-hmm okay having a sauna you guys obviously position is just a token so we need to put the context whose balance is that so I I try to keep the interface for position as close as possible to the original UC 20 so you can easily check the balance without all of the exhausting calculation of indexes okay and the second one let me just take a

shortcut and copy/paste a little bit of Education so right now we're expecting user to get the fonts EMS contract to release the funds and the position balance should also be 0 because we are redeeming it so burning the toughness okay so now let's try to do the more

interesting example of nested conditions positions and moving them around yeah it should be a nice way to discover that depositions are partly fungible so when you get a nested position and we start with a condition a and then condition B and if you do the reverse of start from question B and go to punishing a actually there should be the same tokens in the system how much time have we got eight minutes okay so that's maybe give

you three minutes to play around and then I try to fill it some people are trying to cooperate hmm all right Oh for this so so currently in that situation Erica is just one of the accounts that is injected and you will automatically take it out of the provider for reporting results but usually the the production market system is abstract away the problem of Oracle so you just provide an address that could be anything like our system chiming we all do anything that will give you the answer yes so you know

this provides the smart contracts and the library it just makes using the smart contract easier that's why it's called a binding library as I mentioned the the smart contracts are really low level so they don't keep a stay they required a lot of calculation of indexes hashes etc to have a correct ID for position correct ID for condition and when you start nesting obviously getting harder and harder to track everything that's why the library that's their own internal state and perform all of the calculations so the libraries also built like we got the utilities for

calculating all of the staff and obviously we get some object layer for interacting with the contracts it's still small library love you find really useful if it's going to save you a bit of time that will be great I'm just going to talk okay okay we don't have much time so let me start to get through this example so let's first

create condition I oh very effective easier I just Oh the checks are not so necessary so what

we are doing is just repeating the stuff we done before just creating another condition with two positions let me quickly copy paste for the second step okay condition so it's exactly the same

except just with another condition so right now we get two conditions and four positions that our user health and now it's going to be interesting part because we are going to split an existing position to create a nested set of positions try to skate half of the defense for

that okay so we created two nested positions our system I can skip the ball striking and then let's great part of the second first level position be one against this time condition I so the sound we've let's call it a symmetric operation so we got step position one position other numbers to have a better

visibility what's going to happen so maybe let's perform a check to see how much we got position [Music] and that's the question so sweet 25

okay so let's have something surprising for that so we just waited a position with $25 bad as we see interests we we got 75 tokens and that's the magic and as I mentioned the positions are in jabal so the position B 1 a 1 is actually merge together with position a1 b1 and the 50 balance to create nice 25 I think we ran out of time if you want to do it at home that will be great you can play have some fun learn there is a cheat sheet obviously you guys with the X branch with all of the answers and

some comments if you get lost somewhere and obviously feel free to contact us with some ideas comments etc and they give hyperbole thanks [Applause]