[Music] Hi guys. So we'll go through the introduction of prediction market uh how it works, what is it and we'll also walk through uh the speedun ethereum.com uh prediction market challenge. Uh so yeah like prediction market is one of the biggest use case of onchain application. uh if you heard about poly market.
So basically uh the difference between poly market and a prediction market is like poly market is an app which helps you create prediction market and in 2004 US presidential election during that like there was this prediction market created on poly market which where people baited around $3.3 billion dollars of money between Trump and Kamla Harris. Um so yeah like what prediction market is like prediction market you can think it as a betting market where user bet on the future outcomes and uh the difference between the traditional betting platforms and prediction market is that like in uh betting platforms uh people usually when they bet the bet is locked in but in prediction market like people can usually trade this uh uh bet until the market is closed so they can trade the outcome. terms and since it's onchain like all the benefits of composibility interoperability comes into play and people can also trade in the open market these outcomes until the market is closed. Um so why prediction market like it's best I think best kind of a forecasting engine like where it aggregates the belief of the people uh into probabilities uh and it's often more accurate than um experts or polls or pundits.
Uh it has skin in the game. So like traders are incentivized to uh get the profit. So they had to make some good decisions uh like select the good outcomes and also the trade. It desend decentralize the misreport of the thing. Uh because like you are betting and if you lost the bet you are basically lose the money.
So you are discouraged to provide the misinformation. Uh there is dynamic update since price fluctuates and uh the probability also decre increases decreases as the information comes out. So some of the example of prediction markets are elections u you sports marketing events or geopolitical outcomes even researchers use this uh can use prediction market uh for their research and yeah I mean um so in speed and ethereum challenge uh there are different kind of prediction market but in speed and ethereum challenge like we are going to build a binary prediction market. Uh so this binary prediction market basically has two outcomes yes and no. Yes and no are basically the shares which people buys and it define it defines the uh price and the probability.
So uh let's suppose and the way binary prediction market works is like in the end when the prediction market ends uh the price of the outcome is complete like and the price of the losing token basically wents to zero. Um so for example like this is one of the prediction market been created on poly market um and you see like this uh prediction market says like will Taylor Swift be pregnant in 2025. So it has a fixed date and here people can buy the tokens of uh people can basically buy the shares of yes or people can buy the shares of no and since this is already live people can start trading these shares and the price of uh it increases or decreases and also the price basically represents the probability of the outcome. So yeah like in prediction market uh basically price defines the probability like opinions of the people goes into price and the price is which uh which defines the probability like if the price of a yes token is high it means the probability of happening that event is high and until the fixed date like people can start or stop trading the things and do um cool. So the while building a prediction market there are these three uh main components of a prediction market or tokens.
So basically in previous example which we saw right like there is the shares like yes shares and no shares which people can buy. So basically these are basically in our prediction market are ERC20 tokens. So we'll mint a bunch of yes tokens and a bunch of no tokens which will represent the shares and the outcomes basically. Um yeah and the another component of this prediction market is uh uh liquidity thing like uh automated market where you know like till the date like the till the prediction market ends people can trade tokens or swap these outcomes and earn profit. And the third uh part of this prediction market is Oracle.
Oracle basically is the one which settles the thing on chain and uh gives the result out to the world. And this is where the prediction market stops. Um there can be various kind of oracles but yeah and yeah like let's go through how the setup of the challenge looks like. Um so if you go to speedrun ethereum.com and go to the challenge 7 which is a prediction market uh I already did some steps like it gives you a nice introduction about what prediction market is like which we already went through uh where liquidity comes from and we'll also go through this during the workshop.
So just to be quick on time, I already ran this steps like npx created. Uh these are basically the challenge setup steps and yeah like let me just close. So I already ran the command uh npx created uh prediction market and it scaffolded uh and challenge for me. And now like as always like um if since this challenge are built on top of scaffold so we have this three magical command yan chain yan deploy and yan start. So I have this three terminal split up here.
In the first terminal we run the chain yan chain yan deploy and yan start. So if you look at the code like um you can open this in your code editor but if you look at the code uh the challenge basically comes with these two contracts. One is the prediction markets which we need to fill out while following the challenge and the another one is pred prediction market token which basically u responsibility of it is to basically mean the yes and no shares and yeah like the in the challenge throughout if you go through the challenge basically you will fill out these functions which we have given in the template and yeah let let's look at the front end how it looks. So I started the front end. If I go to local host 3000.
Yeah. So as we uh saw right like prediction market has this three important component. So challenge also comes with these three important components. The liquidity provider, the oracle and basically the users who will be interacting with the prediction market. So let's start with the liquidity provider like how it is set up.
So yeah like to start a challenge uh let me also deploy it once again. Yeah. And uh what I've done is like I set up the burner wallet as a deployer of this contract. So he is the liquidity provider. So liquidity provider is the one who initiates the market by putting some initial funds.
So you see like current prediction market collateral is basically one. So this is the one which is put by the liquidity provider and this think it kind of a bounty like the winning price pool. So the winning price pool is one E and the token value. So basically while bootstrapping a prediction market you also need to define. So since we are uh working on this binary prediction market uh while bootstrapping a prediction market you need to define the winning price like what will be the winning price of a winning outcome share.
So the way if you look at poly market poly market sets it at one USDC. So like if a winning outcome wins like each share will cost you one USDC and the other basically the other outcome will basically cost you 0 USDC. So that's what we have done in the challenge as well. Uh so if I go to the yeah so you see like here we defined like what will be the winning price of each share. So here we have defined it as 0.
018 018 and basically these two values are the ones which defines what amount of token shall be minted like what amount of uh shares can be minted. So if you do like 1 / 0.01 so it says right like uh to get like the winning share to hold the price of 0.1 is we need to mint 100 of each tokens like the yes share and the no share. So that's what we did.
We minted 100 yes shares and 100 no shares and we have so like liquidity provider can also add and remove liquidity. Um and yeah like this is the important thing. So if you look here it says like amount of cash tokens locked away by prediction market. So this is very important concept like uh you need to lock certain amount of tokens initially because if you don't lock it like the prediction market might swing completely on the initial buy of the token. So if you look at this example um let's suppose like if we don't have the locking mechanism like if we don't have the locking mechanism if you don't lock initial tokens let's take an example where we don't have a lock.
So the initial market like if we look at the current state of the market um the market is basically betting on will the green car win or not and LP deposits won it uh which means 100 yes and 100 no token each represent 0.01 01 is like the winning share and if you don't have the locking mechanism initial sold of US token and no token are zero Alice buys just one tokens and once as soon as she buys the one token you see like the probability has completely went to 100%. even if the one token is bought. So like this basically um is kind of uh you could say like fluctuating the market a lot like as soon as a person buys the token the probability went to 100%. And if a new user comes to the prediction market he might be like oh I mean the probability is always already 100%.
So they might start betting on ES tokens only. So yeah like and if you now like look at the logic of locking the token. So here what we did is like here here we also took the example like oh like there might be the chance that there is always not 50% chance of the prediction market winning like there might be the case where green car is more powerful. So the liquidity provider also sets the initial probability that oh like uh green car the probability of winning green car is 60%. and the lock is 10%.
So like we locked 12 and eight tokens out of 100 tokens. And now if Alice buys one tokens, you could see like the new probability just shift shifted from 60 to 61%. But in the previous case if you see like initially the probability was undecent and as soon as the Alice buys the token it went to 100%. So that's the important thing like once we lock the token you could see right like Alice buys one token it still didn't move to 100% it just moved to 61 uh 9%. So that's the importance of locking some initial set of tokens and yeah like some of the benefits is like it anchors the starting beliefs that um if LP provider feels that a certain outcome is more happening then he could set the probability initially.
uh it again prevents the wild swings from early trades. Uh if new user comes to the prediction market they can see like u there is not a token who is completely winning and it also avoids some maths. Uh yeah and like yeah like the initial UI. So the main thing of the prediction market which we are creating is like we are betting on this question will the green car win or not win the race or not. And here we have a dummy.
So if you start the race uh it races the car. Uh we have built this and it's basically a 30-cond race so that we don't consume a lot of time and once the race has started people can start betting. So let me open a new incognito tab. Uh so this is so this guy is the one who bootstrap the whole thing uh the liquidity and he will be also acting as oracle. will look um after some time.
And if I go to user here, basically I can buy uh the tokens. Um and basically this is the part where you know like you need to set the market. So if you go to the challenge scroll below the important part about uh creating this market is like you need to make sure that the final price like the final winning share of the winning outcome is always the predefined value. So in this case we set to 0.18.
So we need to make sure like no matter if people buy initially like uh let's suppose like initially someone buys the full 100 token the price is 0.018. Now like if people buy if no tokens were sold 20 and yes tokens were sold 80. So the price we need to make sure that the final winning outcome is 0.018 018 it like it doesn't exits that and yeah so if we start the market now again like if we start the race and let's start betting like here I have an incognito tab and let's buy some amount of US tokens maybe five and you see like now it's increasing the probability because people are buying And the year's token price is basically increasing.
And um I will also open a chrome like so that I can get a new user here. And maybe this guy buys no token. Uh let me get some faucet funds. So now no token is costing like 0.026 0 268 because like the uh yes token already increases the probability and now if I refresh the probability is back to 50/50%.
Since both of the people holds five tokens. Now let's suppose like this guy buys more no tokens and now the probability of yes token is less and no token is more. So the price of no token will increase and let's suppose now we settle the market right like uh once the race is over you see like the green car is already won. So the oracle so here uh for the demo purposes like the guy who created the predict prediction market is the one acting as a oracle and he will be the he will be the one posting the result on chain. So yeah like we need to now trust that the guy is doing the right thing.
So he reports yes like the green car won. He reports the outcome and yeah like the prediction market has now ended and in between time like people could have traded the yes and no tokens and cool yes and no tokens until the price fluctuates. And now if you go here like this is the guy who lost. Oh no this is the guy who won because like he betted on yes token. So you could see like uh he got five tokens of yes.
So the since the predefined winning price was 0.01 it and he hold five shares of yes token he could now withdraw like 0.05 amount of it. And if you look at the loser obviously he will have zero uh because that's how binary prediction market works like in the end the outcome which loses has holds the zero value. So yeah like here all his u money is gone and if you come here we have 0.
05 with and we could redeem like 0.05 uh we could redeem the five token. We basically put in the five tokens and withdraw the amount of ETH from it. And yeah like this guy's uh uh balance has increased. And another thing so if you go through the market there are also some gotchas for liquidity provider.
So we need to make sure like there might be the thing where liquidity provider might might lose money. So we have explained that logic here nicely and yeah like there are also some good things if you need to explore more like you need to add a add a deadline like here uh the deadline is basically the report of the uh winning of the out outcome but usually in prediction market like there is this fixed date and yeah like again like Oracle uh currently we had this centralized Oracle where uh the creator of the prediction market is the one who is posting the result. Uh we could also rethink like uh the token locking mechanism uh the reward of the LPS like currently we were giving some reward to the LP. So like when the tokens were bought and sold we were giving some of the things to the LP. So if I come here so there was this some amount of fees which was been in incurred uh when people were buying and selling the tokens.
So you could also change these values a bit and try on and yeah like you could also uh think of alternative marketing uh designs. Uh so the way poly market work is like they use order book like it's not decentralized uh but here we have used amm with a linear algorithm but you could also find some uh different market uh design strategies and yeah like this is the case where LP can lose money. Yeah. And if you have like if you want resources for this, you could go through this slide like scaffolding is the is the one on which these challenges were built. Speed run Ethereum and the slides.
[Music]
Automatic transcript — names and jargon may be misspelled.