RealityProxy
Contract used as a Reality Oracle. Is called to resolve a market based on the answer provided.
Variables
conditionalTokens
contract IConditionalTokens conditionalTokensConditional Tokens contract.
realitio
contract IRealityETH_v3_0 realitioReality.eth contract.
INVALID_RESULT
bytes32 INVALID_RESULTINVALID_RESULT reserved value.
REALITY_UINT_TEMPLATE
uint256 REALITY_UINT_TEMPLATETemplate for scalar and multi scalar markets.
REALITY_SINGLE_SELECT_TEMPLATE
uint256 REALITY_SINGLE_SELECT_TEMPLATETemplate for categorical markets.
REALITY_MULTI_SELECT_TEMPLATE
uint256 REALITY_MULTI_SELECT_TEMPLATETemplate for multi categorical markets.
Functions
constructor
constructor(contract IConditionalTokens _conditionalTokens, contract IRealityETH_v3_0 _realitio) publicConstructor.
Parameters
_conditionalTokens
contract IConditionalTokens
Conditional Tokens contract address.
_realitio
contract IRealityETH_v3_0
Reality.eth contract address.
resolve
function resolve(contract Market market) externalResolves the specified market.
Parameters
market
contract Market
Market to resolve. UNTRUSTED.
Pre-condition
This market reality questions must be finalized. If there is a reopened question, that question need to be finalized instead.
Logic
From the provided market contract, hash back the original
questionIdfromquestionsIds,outcomes.length,templateId,lowerBound,upperBound.Call one of the 4 internal resolution functions corresponding to 4 market types, passing
questionId,questionsIds, as well asnumOutcomesorlow,highdepending on the market type.
resolveCategoricalMarket
function resolveCategoricalMarket(bytes32 questionId, bytes32[] questionsIds, uint256 numOutcomes) internalResolves to invalid if the answer is invalid or the result is greater than the amount of outcomes.
Parameters
questionId
bytes32
Conditional Tokens questionId.
questionsIds
bytes32[]
Reality questions ids.
numOutcomes
uint256
The number of outcomes, excluding the INVALID_RESULT outcome.
Pre-condition
This market reality questions must be finalized. If there is a reopened question, that question need to be finalized instead.
Logic
Get reality final answer by calling
realitio.resultForOnceSettled()for the first question inquestionsIds.Create a payouts array defaulting to 0s. Its length is
numOutcomes+1(last index is for INVALID outcome).Calculates the payout for each outcome based on the answer. A payout which index matches the answer will be set to 1. If the answer is INVALID_RESULT or larger than or equal to the number of outcomes, sets the payout of the last index to 1.
Reports the final payouts of the
questionIdto theConditionalTokenscontract.
resolveMultiCategoricalMarket
function resolveMultiCategoricalMarket(bytes32 questionId, bytes32[] questionsIds, uint256 numOutcomes) internalResolves to invalid if the answer is invalid or all the results are zero.
Parameters
questionId
bytes32
Conditional Tokens questionId.
questionsIds
bytes32[]
Reality questions ids.
numOutcomes
uint256
The number of outcomes, excluding the INVALID_RESULT outcome.
Pre-condition
This market reality questions must be finalized. If there is a reopened question, that question need to be finalized instead.
Logic
Get reality final answer by calling
realitio.resultForOnceSettled()for the first question inquestionsIds.Create a payouts array defaulting to 0s. Its length is
numOutcomes+1(last index is for INVALID outcome).Calculates payouts based on a binary representation of the answer. If the answer is INVALID_RESULT, sets the payout of the last index to 1. Otherwise, it processes each bit of the answer:
For each outcome, sets the payout to 1 if the corresponding bit in the answer is set, otherwise 0.
Tracks if all outcomes have zero payouts.
If all outcomes have zero payouts after processing, sets the payout of the last index to 1.
Reports the final payouts of the
questionIdto theConditionalTokenscontract.
resolveScalarMarket
function resolveScalarMarket(bytes32 questionId, bytes32[] questionsIds, uint256 low, uint256 high) internalResolves to invalid if the answer is invalid.
Parameters
questionId
bytes32
Conditional Tokens questionId.
questionsIds
bytes32[]
Reality questions ids.
low
uint256
Lower bound.
high
uint256
Upper bound.
Pre-condition
This market reality questions must be finalized. If there is a reopened question, that question need to be finalized instead.
Logic
Get reality final answer by calling
realitio.resultForOnceSettled()for the first question inquestionsIds.Create a payouts array defaulting to 0s. Its length is 3 (last index is for INVALID outcome).
Calculates the payout for each outcome based on the answer:
If the answer is INVALID_RESULT, sets the payout for the third outcome to 1.
If the answer is less than or equal to
lowerBound, sets the payout for the first outcome to 1. If the answer is greater than or equal toupperBound, sets the payout for the second outcome to 1.For answers between
lowerBoundandupperBound, calculates proportional payouts for the first two outcomes based on the answer's position within the range.
Reports the final payouts of the
questionIdto theConditionalTokenscontract.
resolveMultiScalarMarket
function resolveMultiScalarMarket(bytes32 questionId, bytes32[] questionsIds, uint256 numOutcomes) internalIf any individual result is invalid then the corresponding payout element is set to 0. If all the elements of the payout vector are 0 or all are invalid, the market resolves to invalid.
Parameters
questionId
bytes32
Conditional Tokens questionId.
questionsIds
bytes32[]
Reality questions ids.
numOutcomes
uint256
The number of outcomes, excluding the INVALID_RESULT outcome.
Pre-condition
This market reality questions must be finalized. If there is one or more reopened questions, those questions need to be finalized instead.
Logic
Get reality final answers by calling
realitio.resultForOnceSettled()for each question inquestionsIds.Create a payouts array defaulting to 0s. Its length is
numOutcomes+1(last index is for INVALID outcome).For each answer + index:
If the answer is INVALID_RESULT, sets the payout at that index to 0.
If the answer exceeds the maximum payout, caps it at the maximum, otherwise sets the payout at that index to answer.
Tracks if all outcomes have zero payouts.
If all outcomes have zero payouts after processing, sets the payout of the last index to 1.
Reports the final payouts of the
questionIdto theConditionalTokenscontract.
Last updated