How to: Waves dApps — Prediction Markets example with RIDE -language. Part 1
Couple of days ago, Waves Labs announced new grants for Waves dApp developers.
In this article we’ll learn how to create the simple Prediction Market dApp (like Augur or Gnosis) to create new markets, trade shares and win if the prediction will come true.
What are Prediction Markets?
Essentially it’s placing a bet on the probability of specific results in certain situations, such as elections, sales of a company, price fluctuations of commodities, even changes in the weather.
Prediction Markets dApp demo case
Participants:
Alice — Prediction Markets dApp creator
Bob — Trader
Cooper — Trader
Elon — creator of market for an event: “The first human colony on Mars at 1 Jan 2020 by Elon Musk”
Oracle — it’s the trusted account who is responsible for disclosing the final result (i.e.: happened or not happened within the disclosed time interval).
Actions:
[DEPOSIT & WITHDRAW]
Everyone is able to use dApp as a simple multi-user wallet. We have two deposits: 300 WAVES from Bob and 100 WAVES from Cooper.
[CREATE MARKET]
Everyone is able to create a new Prediction Market. For example: Elon has created a market for an exciting event: “The first human colony on Mars at 1 Jan 2020 by Elon Musk”
[TRADES & ORDERS]
Bob and Cooper now can trade for “Elon’s Market”-shares. One share represents the future contract equal to 0.01 WAVES if event will come true and 0 WAVES otherwise. The order-book price for 1-share is between 1 and 100 units, this number represents estimated probability for an event. We’ll describe only two types of trading orders for simplification: “Limit Sell order” and “Market Buy order”.
[REPORT RESULTS]
When the right moment comes someone must report the final result. The creator of the market has identified the responsible oracle at the stage of creating the market.
We have described a comprehensive but slightly simplified example of a prediction market.
To create a full functional order-book we can use the same logic to add “Limit Buy” and “Market Sell” types of orders. Unfortunately RIDE for dApps language is based on high level of security principles, so it’s not possible to work with orders in the same way as it works within centralised matcher in exchanges. I.E.: all orders matching checks (prices, time priority etc) or partial executions should be implemented by client side application.
Also, in the Part 2. we’ll consider how to add the TCR-based dispute resolution module for our Prediction Markets dApp.
RIDE for dApps implementation
In recent article we have described how to create dApps on Waves platform. So, there is no new information about RIDE smart contracts development and integration.
We used complex logic for key-value data storage and data transactions to implement Prediction Markets dApp
One important moment is that our market should have a “default scenario” if the Oracle at that time has not yet announced the result. We agreed that it should be “NO”.
dApp Web Application
To allow non-technical users to work with Prediction Markets dApp we need to integrate it into some simple html+js web page. In recent article we have described that.
To work with data from dApp data storage we can use accountData and currentHeight from nodeInteraction module.
import { invokeScript, broadcast, nodeInteraction } from '@waves/waves-transactions'
The source code is open for everyone on GitHub.
Be careful with the seed phrase. Waves-Keeper will support RIDE for dApps (invokeScript) shortly.
Enjoy the dApp development with Waves!
Links:
Waves: https://wavesplatform.com/products-blockchain
Demo: https://waves-prediction-market-demo.herokuapp.com/
Waves Labs: https://medium.com/waves-lab/waves-announces-funding-for-ride-for-dapps-developers-f724095fdbe1
GitHub: https://github.com/AlekseiPupyshev/Waves-Augur
RIDE How to: https://medium.com/@alexpupyshev/how-to-waves-dapps-dao-example-using-ride-language-for-smart-contracts-3b0ca55e48a8
Multi-User Wallet Doc: https://docs.wavesplatform.com/en/smart-contracts/writing-dapps.html
Waves Oracles: https://oracles.wavesexplorer.com/