Overview
xDAI Balance
xDAI Value
$0.00More Info
Private Name Tags
ContractCreator
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Latest 1 internal transaction
Parent Transaction Hash | Block | From | To | |||
---|---|---|---|---|---|---|
37129073 | 86 days ago | Contract Creation | 0 xDAI |
Loading...
Loading
Minimal Proxy Contract for 0x8f76bc35f8c72e5e2ec55ebed785da5efaa9636a
Contract Name:
Market
Compiler Version
v0.8.20+commit.a1b79de6
Contract Source Code (Solidity Standard Json-Input format)
/** * @authors: [@xyzseer] * @reviewers: [@nvm1410, @madhurMongia, @unknownunknown1, @mani99brar] * @auditors: [] * @bounties: [] * @deployments: [] */ // SPDX-License-Identifier: MIT pragma solidity 0.8.20; import {IERC20} from "./Interfaces.sol"; import "./RealityProxy.sol"; contract Market { /// @dev Flag to initialize the market only once. bool public initialized; /// @dev Contains the information associated to Reality. /// @param questionsIds Reality questions ids. /// @param templateId Reality templateId. /// @param encodedQuestions Encoded questions parameters, needed to create and reopen a question. struct RealityParams { bytes32[] questionsIds; uint256 templateId; string[] encodedQuestions; } /// @dev Contains the information associated to Conditional Tokens. /// @param conditionId Conditional Tokens conditionId. /// @param parentCollectionId Conditional Tokens parentCollectionId. /// @param parentOutcome Conditional outcome to use (optional). /// @param parentMarket Conditional market to use (optional). /// @param questionId Conditional Tokens questionId. /// @param wrapped1155 Outcome tokens Wrapped1155 address. /// @param data Wrapped1155 token data. struct ConditionalTokensParams { bytes32 conditionId; bytes32 parentCollectionId; uint256 parentOutcome; address parentMarket; bytes32 questionId; IERC20[] wrapped1155; bytes[] data; } /// @dev The name of the market. string public marketName; /// @dev The market outcomes, doesn't include the INVALID_RESULT outcome. string[] public outcomes; /// @dev Lower bound, only used for scalar markets. uint256 public lowerBound; /// @dev Upper bound, only used for scalar markets. uint256 public upperBound; /// @dev Conditional Tokens parameters. ConditionalTokensParams public conditionalTokensParams; /// @dev Reality parameters. RealityParams public realityParams; /// @dev Oracle contract. RealityProxy public realityProxy; /// @dev Initializer. /// @param _marketName The name of the market. /// @param _outcomes The market outcomes, doesn't include the INVALID_RESULT outcome. /// @param _lowerBound Lower bound, only used for scalar markets. /// @param _upperBound Upper bound, only used for scalar markets. /// @param _conditionalTokensParams Conditional Tokens params. /// @param _realityParams Reality params. /// @param _realityProxy Oracle contract. function initialize( string memory _marketName, string[] memory _outcomes, uint256 _lowerBound, uint256 _upperBound, ConditionalTokensParams memory _conditionalTokensParams, RealityParams memory _realityParams, RealityProxy _realityProxy ) external { require(!initialized, "Already initialized."); marketName = _marketName; outcomes = _outcomes; lowerBound = _lowerBound; upperBound = _upperBound; conditionalTokensParams = _conditionalTokensParams; realityParams = _realityParams; realityProxy = _realityProxy; initialized = true; } /// @dev The templateId associated to the Reality question. /// @return The template id. function templateId() external view returns (uint256) { return realityParams.templateId; } /// @dev Returns the Reality questions ids. Multi Scalar markets have one question for each outcome, while any other market has only one question. /// @return The Reality questions ids. function questionsIds() external view returns (bytes32[] memory) { return realityParams.questionsIds; } /// @dev Encoded questions parameters, needed to create and reopen a question. /// @param index The question index. /// @return The encoded question. function encodedQuestions(uint256 index) external view returns (string memory) { return realityParams.encodedQuestions[index]; } /// @dev Conditional Tokens questionId. /// @return the question ID. function questionId() external view returns (bytes32) { return conditionalTokensParams.questionId; } /// @dev Conditional Tokens conditionId. /// @return The condition ID. function conditionId() external view returns (bytes32) { return conditionalTokensParams.conditionId; } /// @dev Conditional Tokens parentCollectionId. /// @return The parent collection ID. function parentCollectionId() external view returns (bytes32) { return conditionalTokensParams.parentCollectionId; } /// @dev The parent market (optional). This market redeems to an outcome token of the parent market. /// @return The parent market address. function parentMarket() external view returns (address) { return conditionalTokensParams.parentMarket; } /// @dev The parent outcome (optional). The parent market's outcome token this market redeems for. /// @return The parent outcome index. function parentOutcome() external view returns (uint256) { return conditionalTokensParams.parentOutcome; } /// @dev Returns the wrapped1155 and the data corresponding to an outcome token. /// @param index The outcome index. /// @return wrapped1155 The wrapped token. /// @return data The token data. function wrappedOutcome(uint256 index) external view returns (IERC20 wrapped1155, bytes memory data) { return (conditionalTokensParams.wrapped1155[index], conditionalTokensParams.data[index]); } /// @dev Returns the wrapped1155 and the data corresponding to the parent market. /// @return wrapped1155 The wrapped token. /// @return data The token data. function parentWrappedOutcome() external view returns (IERC20 wrapped1155, bytes memory data) { if (conditionalTokensParams.parentMarket != address(0)) { (wrapped1155, data) = Market(conditionalTokensParams.parentMarket).wrappedOutcome(conditionalTokensParams.parentOutcome); } } /// @dev Returns the number of outcomes. /// Doesn't include the INVALID_RESULT outcome. /// @return numOutcomes The number of outcomes. function numOutcomes() external view returns (uint256) { return outcomes.length; } /// @dev Helper function to resolve the market. function resolve() external { realityProxy.resolve(this); } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.20; interface IERC20 { function transferFrom(address from, address to, uint256 amount) external returns (bool); function transfer(address to, uint256 amount) external returns (bool); function approve(address spender, uint256 amount) external returns (bool); function balanceOf(address owner) external returns (uint256); function totalSupply() external view returns (uint256); } // https://github.com/RealityETH/reality-eth-monorepo/blob/main/packages/contracts/flat/RealityETH-3.0.sol interface IRealityETH_v3_0 { function askQuestionWithMinBond( uint256 template_id, string memory question, address arbitrator, uint32 timeout, uint32 opening_ts, uint256 nonce, uint256 min_bond ) external payable returns (bytes32); function resultForOnceSettled(bytes32 question_id) external view returns (bytes32); function getContentHash(bytes32 question_id) external view returns (bytes32); function getTimeout(bytes32 question_id) external view returns (uint32); function submitAnswer(bytes32 question_id, bytes32 answer, uint256 max_previous) external payable; } interface IConditionalTokens { function payoutNumerators(bytes32 conditionId, uint256 index) external view returns (uint256); function payoutDenominator(bytes32 conditionId) external view returns (uint256); function prepareCondition(address oracle, bytes32 questionId, uint256 outcomeSlotCount) external; function reportPayouts(bytes32 questionId, uint256[] calldata payouts) external; function splitPosition( /*IERC20*/ address collateralToken, bytes32 parentCollectionId, bytes32 conditionId, uint256[] calldata partition, uint256 amount ) external; function mergePositions( /*IERC20*/ address collateralToken, bytes32 parentCollectionId, bytes32 conditionId, uint256[] calldata partition, uint256 amount ) external; function redeemPositions( /*IERC20*/ address collateralToken, bytes32 parentCollectionId, bytes32 conditionId, uint256[] calldata indexSets ) external; function getConditionId( address oracle, bytes32 questionId, uint256 outcomeSlotCount ) external pure returns (bytes32); function getCollectionId( bytes32 parentCollectionId, bytes32 conditionId, uint256 indexSet ) external view returns (bytes32); function getPositionId(address collateralToken, bytes32 collectionId) external pure returns (uint256); function getOutcomeSlotCount(bytes32 conditionId) external view returns (uint256); function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes calldata data) external; function balanceOf(address owner, uint256 id) external view returns (uint256); } interface IWrapped1155Factory { function requireWrapped1155( /*IERC1155*/ address multiToken, uint256 tokenId, bytes calldata data ) external /*Wrapped1155*/ returns (IERC20); function unwrap( /*IERC1155*/ address multiToken, uint256 tokenId, uint256 amount, address recipient, bytes calldata data ) external; }
/** * @authors: [@xyzseer] * @reviewers: [@nvm1410, @madhurMongia, @unknownunknown1, @mani99brar] * @auditors: [] * @bounties: [] * @deployments: [] */ // SPDX-License-Identifier: MIT pragma solidity 0.8.20; import {IConditionalTokens, IRealityETH_v3_0} from "./Interfaces.sol"; import "./Market.sol"; contract RealityProxy { /// @dev Conditional Tokens contract. IConditionalTokens public immutable conditionalTokens; /// @dev Reality.eth contract. IRealityETH_v3_0 public immutable realitio; /// @dev INVALID_RESULT reserved value. bytes32 internal constant INVALID_RESULT = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff; /// @dev Template for scalar and multi scalar markets. uint256 internal constant REALITY_UINT_TEMPLATE = 1; /// @dev Template for categorical markets. uint256 internal constant REALITY_SINGLE_SELECT_TEMPLATE = 2; /// @dev Template for multi categorical markets. uint256 internal constant REALITY_MULTI_SELECT_TEMPLATE = 3; /// @dev Constructor. /// @param _conditionalTokens Conditional Tokens contract address. /// @param _realitio Reality.eth contract address. constructor(IConditionalTokens _conditionalTokens, IRealityETH_v3_0 _realitio) { conditionalTokens = _conditionalTokens; realitio = _realitio; } /// @dev Resolves the specified market. /// @param market Market to resolve. UNTRUSTED. function resolve(Market market) external { bytes32[] memory questionsIds = market.questionsIds(); uint256 numOutcomes = market.numOutcomes(); uint256 templateId = market.templateId(); uint256 low = market.lowerBound(); uint256 high = market.upperBound(); // questionId must be a hash of all the values used to resolve a market, this way if an attacker tries to resolve a fake market by changing some value its questionId will not match the id of a valid market. bytes32 questionId = keccak256(abi.encode(questionsIds, numOutcomes, templateId, low, high)); if (templateId == REALITY_SINGLE_SELECT_TEMPLATE) { resolveCategoricalMarket(questionId, questionsIds, numOutcomes); return; } if (templateId == REALITY_MULTI_SELECT_TEMPLATE) { resolveMultiCategoricalMarket(questionId, questionsIds, numOutcomes); return; } if (questionsIds.length > 1) { resolveMultiScalarMarket(questionId, questionsIds, numOutcomes); return; } resolveScalarMarket(questionId, questionsIds, low, high); } /// @dev Resolves to invalid if the answer is invalid or the result is greater than the amount of outcomes. /// @param questionId Conditional Tokens questionId. /// @param questionsIds Reality questions ids. /// @param numOutcomes The number of outcomes, excluding the INVALID_RESULT outcome. function resolveCategoricalMarket( bytes32 questionId, bytes32[] memory questionsIds, uint256 numOutcomes ) internal { uint256 answer = uint256(realitio.resultForOnceSettled(questionsIds[0])); uint256[] memory payouts = new uint256[](numOutcomes + 1); if (answer == uint256(INVALID_RESULT) || answer >= numOutcomes) { // the last outcome is INVALID_RESULT. payouts[numOutcomes] = 1; } else { payouts[answer] = 1; } conditionalTokens.reportPayouts(questionId, payouts); } /// @dev Resolves to invalid if the answer is invalid or all the results are zero. /// @param questionId Conditional Tokens questionId. /// @param questionsIds Reality questions ids. /// @param numOutcomes The number of outcomes, excluding the INVALID_RESULT outcome. function resolveMultiCategoricalMarket( bytes32 questionId, bytes32[] memory questionsIds, uint256 numOutcomes ) internal { uint256 answer = uint256(realitio.resultForOnceSettled(questionsIds[0])); uint256[] memory payouts = new uint256[](numOutcomes + 1); if (answer == uint256(INVALID_RESULT)) { // the last outcome is INVALID_RESULT. payouts[numOutcomes] = 1; } else { bool allZeroes = true; for (uint256 i = 0; i < numOutcomes; i++) { payouts[i] = (answer >> i) & 1; allZeroes = allZeroes && payouts[i] == 0; } if (allZeroes) { // invalid result. payouts[numOutcomes] = 1; } } conditionalTokens.reportPayouts(questionId, payouts); } /// @dev Resolves to invalid if the answer is invalid. /// @param questionId Conditional Tokens questionId. /// @param questionsIds Reality questions ids. /// @param low Lower bound. /// @param high Upper bound. function resolveScalarMarket( bytes32 questionId, bytes32[] memory questionsIds, uint256 low, uint256 high ) internal { uint256 answer = uint256(realitio.resultForOnceSettled(questionsIds[0])); uint256[] memory payouts = new uint256[](3); if (answer == uint256(INVALID_RESULT)) { // the last outcome is INVALID_RESULT. payouts[2] = 1; } else if (answer <= low) { payouts[0] = 1; } else if (answer >= high) { payouts[1] = 1; } else { payouts[0] = high - answer; payouts[1] = answer - low; } conditionalTokens.reportPayouts(questionId, payouts); } /// @dev If any individual result is invalid then the corresponding payout element is set to 0. /// @dev If all the elements of the payout vector are 0 or all are invalid, the market resolves to invalid. /// @param questionId Conditional Tokens questionId. /// @param questionsIds Reality questions ids. /// @param numOutcomes The number of outcomes, excluding the INVALID_RESULT outcome. function resolveMultiScalarMarket( bytes32 questionId, bytes32[] memory questionsIds, uint256 numOutcomes ) internal { uint256[] memory payouts = new uint256[](numOutcomes + 1); bool allZeroesOrInvalid = true; /* * We set maxPayout to a sufficiently large number for most possible outcomes that also avoids overflows in the following places: * https://github.com/gnosis/conditional-tokens-contracts/blob/master/contracts/ConditionalTokens.sol#L89 * https://github.com/gnosis/conditional-tokens-contracts/blob/master/contracts/ConditionalTokens.sol#L242 */ uint256 maxPayout = 2 ** (256 / 2) - 1; for (uint256 i = 0; i < numOutcomes; i++) { payouts[i] = uint256(realitio.resultForOnceSettled(questionsIds[i])); if (payouts[i] == uint256(INVALID_RESULT)) { payouts[i] = 0; } else if (payouts[i] > maxPayout) { payouts[i] = maxPayout; } allZeroesOrInvalid = allZeroesOrInvalid && payouts[i] == 0; } if (allZeroesOrInvalid) { // invalid result. payouts[numOutcomes] = 1; } conditionalTokens.reportPayouts(questionId, payouts); } }
{ "evmVersion": "paris", "libraries": {}, "metadata": { "bytecodeHash": "ipfs", "useLiteralContent": true }, "optimizer": { "enabled": true, "runs": 100 }, "remappings": [], "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } } }
[{"inputs":[],"name":"conditionId","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"conditionalTokensParams","outputs":[{"internalType":"bytes32","name":"conditionId","type":"bytes32"},{"internalType":"bytes32","name":"parentCollectionId","type":"bytes32"},{"internalType":"uint256","name":"parentOutcome","type":"uint256"},{"internalType":"address","name":"parentMarket","type":"address"},{"internalType":"bytes32","name":"questionId","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"encodedQuestions","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_marketName","type":"string"},{"internalType":"string[]","name":"_outcomes","type":"string[]"},{"internalType":"uint256","name":"_lowerBound","type":"uint256"},{"internalType":"uint256","name":"_upperBound","type":"uint256"},{"components":[{"internalType":"bytes32","name":"conditionId","type":"bytes32"},{"internalType":"bytes32","name":"parentCollectionId","type":"bytes32"},{"internalType":"uint256","name":"parentOutcome","type":"uint256"},{"internalType":"address","name":"parentMarket","type":"address"},{"internalType":"bytes32","name":"questionId","type":"bytes32"},{"internalType":"contract IERC20[]","name":"wrapped1155","type":"address[]"},{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"internalType":"struct Market.ConditionalTokensParams","name":"_conditionalTokensParams","type":"tuple"},{"components":[{"internalType":"bytes32[]","name":"questionsIds","type":"bytes32[]"},{"internalType":"uint256","name":"templateId","type":"uint256"},{"internalType":"string[]","name":"encodedQuestions","type":"string[]"}],"internalType":"struct Market.RealityParams","name":"_realityParams","type":"tuple"},{"internalType":"contract RealityProxy","name":"_realityProxy","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"initialized","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lowerBound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"marketName","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"numOutcomes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"outcomes","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"parentCollectionId","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"parentMarket","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"parentOutcome","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"parentWrappedOutcome","outputs":[{"internalType":"contract IERC20","name":"wrapped1155","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"questionId","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"questionsIds","outputs":[{"internalType":"bytes32[]","name":"","type":"bytes32[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"realityParams","outputs":[{"internalType":"uint256","name":"templateId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"realityProxy","outputs":[{"internalType":"contract RealityProxy","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"resolve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"templateId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"upperBound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"wrappedOutcome","outputs":[{"internalType":"contract IERC20","name":"wrapped1155","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"stateMutability":"view","type":"function"}]
Loading...
Loading
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 31 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.