Market example
Let's consider a question where only one out of multiple choices may be chosen:
Will war in Ukraine stop in 2024?
Yes
No
Prerequisites
Client-side code samples will be written in JavaScript assuming the presence of ethers library. We will also use a forked Gnosis chain. We will need sDai
address from GnosisRouter
:
Before we begin, we still need to deploy multiple dependent contracts, namely ConditionalTokens
, Realitio
, RealityProxy
, Wrapped1155Factory
, Market
.
We will also need an arbitrator, however, for demo purpose, we will use a zero address:
After deploying dependent contracts, we will deploy our main contracts, MarketFactory
and GnosisRouter
:
Create market
To create this market, one can run the following code:
After the call, we will create a Market
contract, which address is stored in MarketFactory
.
Since this is the first market we created, we can access its address at index 0.
Split position
We will then call splitFromBase
to deposit our collateral token (sDai) and receive ERC20 outcome tokens. In this case, we will receive 3 sets of tokens: YES, NO, INVALID_RESULT (INVALID_RESULT is default for every market):
Parameters:
market
: The market to split.
After the call, we will have ERC20 outcome tokens, ready to be traded.
Answer Reality Question
After the opening time, Reality question can be answered. You can learn more about how Reality works here. Basically, it allows multiple players to provide answers for a question in a decentralized manner, and the final correct answer will be rewarded:
Resolve the market
After the answer is finalized, we can resolve the market:
This will calculate payouts for every outcomes and send the result to ConditionalTokens
. In this case, since the finalized answer is 0, the payouts will be [1,0,0]. It means that outcome tokens at index 0 can be redeemed for full amount collateral, while outcome tokens at index 1 and 2 will be redeemed for zero amount.
Redeem positions
A user with ERC20 outcome tokens can redeem their winning positions for collateral token (sDai in this case). For example, if you want to redeem YES tokens only, you can pass an array that contains only outcome index 0.
Parameters:
market
: The market to split.
outcomeIndexes
: An array of outcome indexes you want to redeem.
amounts
: Amount to redeem of each outcome.
To learn more about how split, merge, and redeem work under the hood, visit Gnosis Conditional Tokens Documentation.
Last updated