Gnosis Prediction Market Platform And Crowdfunding Contract Source Code

This is not advise as to whether the Gnosis prediction market platform is a good investment or not. This is just a quick look at the source code behind what Gnosis is offering.

Reference Gnosis contracts published – bug bounty program will start soon.

This is the longest set of Solidity source code I’ve seen so far – 4,779 lines of code and comments.

See https://github.com/ConsenSys/gnosis-contracts for the original contents, and https://github.com/ConsenSys/gnosis.js/ for the code to interact with these contract.

Website – https://www.gnosis.pm/.


Architecture


Table of contents


The source code below is from https://github.com/ConsenSys/gnosis-contracts at Nov 03 2016 14:14:32 UTC.

DAO

AbstractDAO.sol

AbstractDAOAuction.sol

DAO.sol

A placeholder contract for a future DAO governance contract. Offers interfaces to calculate fees for trades based on sender and token count. Can be upgraded by a wallet contract controlled by Gnosis founders.

DAODutchAuction.sol

Implements the Dutch auction used by Gnosis for the token launch. Accepts bids using bid function until funding goal or stop price is reached. After the auction is completed, every successful bidder can claim his tokens using the claimTokens function.

DAOToken.sol

Gnosis token (GNO) contract. At deployment all tokens are assigned to the auction contract. Auction contract transfers tokens to bidders according to their bid and final token price. Tokens can be traded after the auction is over and one week passed.


Event Factory

AbstractEventFactory.sol

EventFactory.sol

Allows creation of new events used to resolve markets. Events can resolve to a number in a range (ranged event) or an outcome out of a list of outcomes. An example for a ranged event is the Apple stock price on date X. An example for a non-ranged event would be the winner of the World Cup on date X. For every outcome, an outcome token is created. Ranged events are represented with two outcome tokens for long and short positions. Non-ranged events have an outcome token for every defined outcome. Every event defines an oracle contract to resolve the event and a token contract denominating the currency used in markets using this event. The event factory contract allows to buy and sell all outcomes for 1 unit of the currency of the event. Winnings can be redeemed after the event has been resolved using the defined oracle.

OutcomeToken.sol

Outcome tokens are created for every outcome of an event. Only the event factory contract is allowed to issue and revoke outcome tokens using buy and sell all outcome functions.

OutcomeTokenLibrary.sol

Implements basic token functionality like transfer and transferFrom. The library is used to reduce the deployment gas costs of outcome tokens.


Market Crowdfunding

MarketCrowdfunding.sol

Allows crowdfunding of automated market makers and distributes collected fees among investors.


Market Factories

AbstractMarketFactory.sol

DefaultMarketFactory.sol

Allows to create markets and trade outcome tokens on markets with a market maker. A market is always associated to an event and has to be funded in the event’s denomination. A market maker contract like the LMSR market maker has to be defined to allow trading. A fee charged for every trade on a market can be defined to return the investment used to fund the market maker.

HunchGameMarketFactory.sol

Inherits functionality from DefaultMarketFactory and adds functionality required for the HunchGame Gnosis App (high-score etc.).


Market Makers

AbstractMarketMaker.sol

LMSRMarketMaker.sol

Calculates prices for event outcome tokens based on demand using a logarithmic market scoring rule. Implementing Robin Hanson’s designed LMSR market maker.


Oracles

All oracle contracts implement the oracle interface for time-limited events developed by Gnosis in cooperation with other oracle providers like Reality Keys. Specifications will be released soon.

AbstractFallbackOracle.sol

AbstractOracle.sol

Oraclize.sol

OraclizeFakeApi.sol

DefaultFallbackOracle.sol

Implements a simple fallback oracle solution allowing to overwrite oracle results with another account controlled by a separate private key.

DifficultyOracle.sol

Allows to resolve markets based on the difficulty at block X.

FutarchyOracle.sol

Allows to resolve a market based on the outcome of a dependent market to use markets for decision making. An introduction to the futarchy concept can be found here: https://blog.ethereum.org/2014/08/21/introduction-futarchy/

OraclizeOracle.sol

An oracle contract wrapping around the oracle service provided by Oraclize. Allows to resolve any ranged event supported by Oraclize.

UltimateOracle.sol

Allows to use signed results by off-chain oracle providers like Reality Keys. Multiple oracles can be combined to resolve an event. A majority vote will define the final outcome. An oracle result can be challenged by anyone within a challenge period. If an oracle was challenged its result will be overwritten by the Ultimate Oracle. When an oracle result was challenged, a second market is opened to define the right outcome. Everyone can put Ether on the outcome they believe is the right outcome. If the frontrunner is not changed within a decision period, the frontrunner will be set as the final ultimate outcome. Everyone participating on the winning side will get its fraction of the losing side. To make sure that this fraction is not diluted by a last minute bet on the clear winner, the amount allowed to bid on the frontrunner is in relation to all Ether bet on all other outcomes. The Ultimate Oracle contracts supports the use of fallback oracles.

State Channels

StateChannel.sol

Generic settlement contract for off-chain transactions. Can be used to settle Gnosis trade agreements between multiple parties.


Tokens

AbstractToken.sol

EtherToken.sol

An ERC20 compliant token exchanging Ether and Ether-tokens 1:1. All Gnosis contracts allow using tokens implementing the ERC20 token interface and don’t allow direct usage of Ether.

HunchGameToken.sol

Token used by the HunchGame Gnosis App. Allows HunchGameMarketFactory to issue new HunchGame tokens. The account used to deploy the contract receives almost unlimited amount of tokens for market making.

StandardToken.sol

An implementation of the ERC standard token. Discussion: https://github.com/ethereum/EIPs/issues/20


Utils

Lockable.sol

Allows an inheriting contract to use global locks for function calls.

MathLibrary.sol

Provides basic math functionality for calculating natural exponential function and natural logarithmic function. This is a Solidity version of Chris Calderon’s implementation in Serpent, which is part of the Augur project: https://github.com/AugurProject/augur-core/blob/develop/src/data_api/fxpFunctions.se


Wallets

MistWallet.sol

MultiSigWallet.sol

Allows multiple parties to agree on transactions before execution. Allows to add and remove owners and update the number of required confirmations.

This entry was posted in Blog and tagged , , , , , . Bookmark the permalink.