Code Monkey home page Code Monkey logo

augur-core's Introduction

augur-core

Build Status

Important: V2 Development Moved to New Location

This repo contains the current Augur V1 contract code. All new contract development is available in the new Augur monorepo.

About

Smart contracts for Augur, a decentralized prediction market platform on the Ethereum blockchain.

Quick Setup

If you just want to clone the repo and quickly have a couple local proof of authority networks (Geth/Clique and Parity/Aura) running with the contracts deployed then you can just clone the repo and run:

docker-compose -f source/support/test/integration/docker-compose-[geth/parity].yml up --build --force-recreate
  • Parity HTTP RPC will be available on localhost port 47622.
  • Geth HTTP RPC will be available on localhost port 47624.
  • An abundant supply of ETH is available using the private key 0xfae42052f82bed612a724fec3632f325f377120592c75bb78adfcceae6470c5a.
  • The log output will let you know what the address of the various Augur contracts are.

Installation

You need system-wide installations of Python 2.7.6+, Node.js 8+, and Solidity 0.4.20. (Or Docker; see below.) Install the dependencies:

npm install npx
npm install
pip install -r requirements.txt

Note: on macOS, you need to use virtualenv or homebrew Python to work around System Integrity Protection.

Deployment

Solidity contract deployment is handled by ContractDeployer.ts and the wrapper programs located in source/deployment. This deployment framework allows for incremental deploys of contracts to a given controller (specified via a configuration option). This allows us to deploy new contracts without touching the controller, effectively upgrading the deployed system in-place.

  • Main Code

    • source/libraries/ContractCompiler.ts - All logic for compiling contracts, generating ABI
    • source/libraries/ContractDeployer.ts - All logic for uploading, initializing, and whitelisting contracts, generating addresses and block number outputs.
  • Configuration

    • source/libraries/CompilerConfiguration.ts
    • source/libraries/DeployerConfiguration.ts
    • source/libraries/NetworkConfiguration.ts -
  • Wrapper programs

    • source/deployment/compileAndDeploy.ts - Compiles and Uploads contracts in one step. Useful for integration testing.
    • source/deployment/compiledContracts.ts - Compile contract source (from source/contracts) and output contracts.json and abi.json. Outputs to output/contracts or CONTRACTS_OUTPUT_ROOT if defined.
    • source/deployment/deployNetworks.ts - Application that can upload / upgrade all contracts, reads contracts from CONTRACTS_OUTPUT_ROOT, and uses a named network configuration to connect to an ethereum node. The resulting contract addresses are stored in output/contracts or ARTIFACT_OUTPUT_ROOT if defined.

Tests

The tests directory (augur-core/tests) contain tests and test fixtures to test the various functionalities present in Augur, including trading, reporting, and wcl tests.

  • conftest.py -- contains the class ContractFixture, which deals with caching compiled contracts, signatures, etc. as well as resetting the blockchain before each test.
  • delegation_sandbox.py -- tests the delegator contract.
  • sandbox.py -- used for testing miscellaneous Solidity behaviors
  • reporting -- contains tests for reporting purposes.
  • trading -- contains tests for trading purposes.
  • solidity_test_helpers -- small contracts to help run tests.
  • test_controller.py -- tests controller functionalities.
  • test_mutex.py -- tests mutex functionalities.
  • test_helpers.py -- tests the controller, safeMath, and assertNoValue macros.
  • test_legacyRep.py -- tests for legacyRepToken's functionalities.
  • utils.py -- contains useful functions for testing, such as conversion between different data types.
  • wcl-in-python.py -- contains functions for making and taking various types of bids.
  • wcl.txt -- explains tests for the various situations when filling a bid and filling an ask.

Use pytest to run Augur's test suite:

pytest tests

This executes all the tests. To run a test individually, run the following:

pytest path/to/test_file.py -k 'name_of_test'

When writing tests, it is highly recommended to make use of the ContractFixtures class for "placeholder" variables. Python's unit testing framework comes handy here; encapsulate tests within functions that start with "test_", and use assert statements when testing for certain values. Parameterized tests are recommended as well to test various possibilities and edge cases.

Coverage Report

To generate a coverage report simply run the command:

node --max-old-space-size=12288 source/tools/generateCoverageReport.js

The results will be displayed on the command line and a much richer HTML output will be generated in the coverage folder of the project.

Make sure you actually have enough memory to run the command above. The coverage tool being used will pull a massive file into memory to generate the report and will fail with an OOM exception if not enough is available. Since tests take about 40 minutes to run with coverage enabled this will be a sad event.

Docker

augur-core can optionally be built, run, and tested using Docker. A number of Docker commands are included as npm scripts, which map to the non-Dockerized versions where this makes sense. Docker commands beginning with docker:run execute the command within the Docker image. Docker commands without run (e.g. docker:test) first build the image, then execute docker:run:<command>.

Build

npm run docker:build

Test

# With a pre-built image
npm run docker:run:test:unit:all

# Build and run all unit tests and integration tests
npm run docker:test

# Build and run just integration tests (using Geth)
npm run docker:run:test:integration:geth
# Build and run just integration tests (using Parity)
npm run docker:run:test:integration:parity

For quicker iteration on integration tests follow the instructions here to run tests locally against a node running in docker:

// uncomment one of the following and run `docker-compose up --build --force-recreate --abort-on-container-exit parity-dev-node` then you can debug tests against any chain from within VSCode
// ** Local **
// "env": {
// "ETHEREUM_HOST": "localhost",
// "ETHEREUM_PORT": "8545",
// "ETHEREUM_GAS_PRICE_IN_NANOETH": "1",
//// "ETHEREUM_PRIVATE_KEY": "0xe2b0241b73cd78d450f85eca67188fb884e7ebe961f8981814474c500d581952"
// },

If the contracts aren't changing, after the first run you can add "AUGUR_CONTROLLER_ADDRESS": "..." to the env and it will even skip re-uploading the contracts with each run of the integration tests.

Running Oyente

Install Oyente locally. This can be done by following the instructions on their GitHub: https://github.com/melonproject/oyente

Run the oyente script with this command to get the output for all contracts:

python source/tools/runOyente.py -p

Source code organization

Augur's smart contracts are organized into four folders:

  • source/contracts/factories: Constructors for universes, markets, fee windows, etc.
  • source/contracts/libraries: Data structures used elsewhere in the source code.
  • source/contracts/reporting: Creation and manipulation of universes, markets, fee windows, and reporting-related tokens.
  • source/contracts/trading: Functions to create, view, and fill orders, to issue and close out complete sets of shares, and for traders to claim proceeds after markets are closed.

Additional notes

General information about Augur

Terminology

Augur Terminology

EVM numbers are always integers

There are no floating-point numbers in the EVM, only integers. Therefore, Ether and Reputation values in contracts are always represented in units of wei (i.e., indivisible units of 10^-18 Ether or 10^-18 Reputation).

Reporting diagrams

Worst-case-loss escrow for trades

Verifying the REP contract on the main Ethereum network

On Augur, each Universe has a Reputation Token Contract that is created by the Universe, which is uniquely associated with that Universe. The Reputation token contract is technically a "Delegator" Contract, which simply calls through to its delegation target contract, the Verified Reputation Token Contract.

You can verify that the REP token contract is a Delegator by verifying the ReputationTokenFactory is what created the contract.

To do this, go to the new REP contract 0x1985365e9f78359a9b6ad760e32412f4a445e862. Then go to its creator 0x8fee0da3a35f612f88fb58d7028d14c7d99a3643. Then click on internal transactions and you'll see this 0x44c09f8eeff886723b79890e14743192a8c8d8a8eac158ed17600c94e502cce8 transaction which creates the initial universe.

Then click on internal on that page and you'll see here that that contract created the REP token contract.

You can verify that the REP Token contract is delegating to the verified REP token contract target by calling lookup on the Controller with the string ReputationToken.

augur-core's People

Contributors

adrake33 avatar andrewbezold avatar beaugunderson avatar bthaile avatar carver avatar charltonh avatar cryptomental avatar epheph avatar imkharn avatar janani-sridhar avatar joeykrug avatar johndanz avatar justinbarry avatar kevinday avatar micahzoltu avatar nuevoalex avatar petong avatar pgebheim avatar redsquirrel avatar scottzer0 avatar serpentchris avatar stephensprinkle-zz avatar tinybike avatar tomdev avatar tomkysar avatar vbuterin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

augur-core's Issues

Handle Dormant Rep Decay Process

Time to claim for initial rep distribution is 6 months before inactivity kicks in

Need to prevent going dormant after already revealed report in second half of period to prevent dormancy to skip rep penalization. And what if I go dormant - do I have to do rbcr and not reporting cr for all past periods? How's that work? Shouldnt have to do during dormant period

Penalization catchup etc for dormant and not dormant rep - make rr be done before converting to and back so no one loses any dormant rep from that beyond the dormant decay rate

Make sure rr up to date before doing dormant back and forth conversions

Dormant rep loses only if round 2 or forking [or maybe just forking?] not reported on [and loss is n% of the y% rep that is dormant], otherwise just gets no fees.

when handling dormant rep stuff:
# if a person reported on a round 2 event, they cannot convert their rep to dormant or send rep until they've finished the resolution process for that round 2 event
# unless this just happened to them last period and they reported correctly then

reportingdone early shouldn't be allowed b/c prevents bonds, num reports/expected may not be needed

is reporting happening on orig. branch for forked events or no? when / if / should a forked event's setmoved be set/ when /if should its branch be moved? which branch do i re report on a forked event on?

  • always subtract first before updating / sending stuff, only do that later on

Great Refactoring of April 2015

Entire codebase needs to be refactored into two sets of contracts:

  1. data structures and getters and setters for them
  2. business logic functions that call these contracts to get & set data

Search and sort service-on-a-contract

Pre-loading all markets during the initial UI load will become prohibitively slow as the number of markets grows. These are good candidates for services that could be provided as a separate contract: search/sort are read-only operations and can use eth_call "gas".

Replace "import" syntax with externs

The import syntax makes it a headache to upload contracts manually in the event that load_contracts.py fails. It should be replaced with Serpent's extern syntax.

Ls-lmsr sum trick

Use the log sum of exp trick to calculate ls-lmsr at higher numbers in the exp.

Resolve 99 market function

- If at anytime after expiry an event's market's odds are <.99, someone can prove it and push it into next reporting period

(and don't allow rbrr for original exp period of this market, actually, don't allow this regardless)

- Should probably still have an option to pay to resolve in case something somehow goes wrong here or people really want a market resolved.

Misc. mega issue

  • make fork + round 1 pushback wait 48 hr instead of 24
  • make so can't report in last 48 hr of period
  • Market has tags, description (where someone has to put a title at minimum), and should have an additional optional information section where they can either put all the additional information they want there and/or add link(s).
  • Event has a question and should have a resolution source
  • Handle: Report threshold is raised so anyone can report on it if it has no reports in last 24 hr
  • if 0 reports on an event either push back or indeterminate?
  • want reporters to report on 2x min reports number
  • No auto pushback for .5, must be challenged
  • add moving events to new period in case fall behind in beta w/ shorter cycles
  • When selecting to report make sure based off of total active rep, not including dormant
  • finalize rep transfer api
  • Assign reporters based on shares outstanding when expiration date arrives, not volume
  • when to allow / prohibit trading and how it fits into outstanding shares at the end of a market
  • mm pay cost to close markets ahead of time in a fee instead of forcing users to do it: closing gas cost [1.1194M + 1M per addl. event]
  • get list of events to report on for a user w/ a call function
  • Keep reporters low below some $ in volume amount according to fee on market
    • need to keep track of amount of fees charged in a market for this
    • calc. # of reporters per outstanding shares [old version was volume]
    • calc. ability to pay for reporting fees calculated from fees from market for how many reporters it can pay for
    • whichever is less is # of reporters targeted towards the market
  • it should be exactly what is needed for reporters to report on the market should no traders show up:
    • (decent labor compensation rate for reporters) + (gas cost for these reporters)
    • (Initial_Liquidity_Requirement * 0.5 * Fee) + Base_Reporter_Quantity * (Gas cost of commit [1.055M] + Gas cost of reveal [1.358M] + Gas cost of penalize [1.08M])
  • multiple of adj. cost for appeal bond?
  • round 2 bond cost discussion
  • make sure round 2 bond formulas correct
  • make sure reporting selection formula correct
  • reporting penalty based on market size? round 1 penalties at all? reporting penalties change/make less severe [see V discussion]
  • check for anything called that should take sender as a param but doesn't atm
  • users for min(30, numevents) when reporting paid to report... hmmm
    • Gas rewards to reporters as in minimum creation fee used to directly pay people who reported on a given event for gas fee rebates. Make sure to account for how many a market has paid for already and cap it at that
    • penalization catchup - what if actually not selected to report
    • prove voted on less than actually could have and <.5 of shouldve
    • must report on max(selected estimate/2, 1 if actually selected)
    • if couldve reported on more to meet .5 or max req above but didnt lose rep if someone proves it
    • need at least 1 rep to vote
    • only commit for round 2 and fork events perhaps?
  • Handle penalization automatically so UI doesn't have to (how to do in case of fork or round 2 event?). If these aren't done you can't send rep, convert rep, or report
    • penalizeNotEnoughReports(branch) - once in first half of a period per reporter, so if not done do that
    • closeMarket if event doesn't have an outcome via EVENTS.getOutcome(event) yet. Closing any one market associated w/ the event [you can get a list of markets associated w/ an event via getMarkets(event)] will finalize the event's outcome. And round 2 resolve for those events
    • penalizeWrong(branch, event) for each event reported on in first half of a period
    • do penalizationCatchup(branch) if further behind automatically in submitreporthash or any of the rep sending / converting functions
    • collectFees(branch) - once in second half of a period [so during first submit report]
    • round 2 penalize rep sending etc
    • todo: make it 0.98 * old rep + 0.02 * new rep

    • (1-k) * old rep + k * new rep where k = 0.2 / (number of events you reported on last period) for penalization and pen. rate for forking and backstop 1

  • go over any various todos i missed
  • msg.sender vs tx.origin
  • Handle 1.5 vs .5 vs .5 in fxp + 1 for binary, scalar, and categorical events
  • other tests where api changed
  • make exp events data struct more efficient
  • categorical .5 single market handling
  • ph note
  • pushed forward round 2 / fork handling

Refactor:

  • markets.se
  • consensus.se [and make cheaper]
  • backstops.se [and make cheaper]
  • buy&sellshares.se
  • closemarket.se
  • createmarket.se
  • forking.se [and make cheaper]
  • makereports.se
  • marketcreatortrading.se

Market outcome checking

Check that the market actually has that outcome as a possible outcome when buying/selling.

New market getters needed

Below are some market methods i wrote in the demo-stub contact object while flushing out the UI design and functionality in the past few weeks. These either need to exist in some fashion or alternatives created. Some of these can be stored in a RESTful document data store like MongoDB. They are broken up like this with the limitations of evm data fetching in mind, but if put somewhere else, i would ideally combine them as they are most often (always?) fetched together when getting a market.

// placing here for for demo purposes
getMarketComments: function(id) {
   return demo.markets[id]['comments'];
},
getMarketHistory: function(id) {
   return demo.markets[id]['priceHistory'];
},
getMarketVolume: function(id) {
   return demo.markets[id]['volume'];
},
getMarketShares: function(id, account) {
   return demo.markets[id]['sharesHeld'][account];
}
getMarketImage: function(id) {
   return demo.markets[id]['imageUr'];
}

Load contracts test fails

When I try to run test_load_contracts.py, I get this error:

(master) jack@vent:~/src/augur-core/tests$ ./test_load_contracts.py 
Setting up node environment.
  Cloning go-ethereum
  Building geth
  Done
Starting node. To open a console:
  geth attach rpc:http://localhost:9696
Mining coins...
python: can't open file 'load_contracts.py': [Errno 2] No such file or directory
Traceback (most recent call last):
  File "./test_load_contracts.py", line 124, in <module>
    test_compile_imports()
  File "./test_load_contracts.py", line 89, in test_compile_imports
    '-s', 'foobar'])
  File "/usr/lib/python2.7/subprocess.py", line 540, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['python', 'load_contracts.py', '-C', '.', '-p', '9696', '-b', '2', '-d', 'test_load_contracts.json', '-s', 'foobar']' returned non-zero exit status 2

Block number to hash

Block.number needs to be added to both createEvent & createMarket again once web3.js callbacks are working (or UI uses Jack's script)

Trading fee adj.

Allow trading fee adjustment

Locking in fees when trading/buy/sell?

Order Statistic Tree

Allow generalization of OST to create more than one tree within the same contract.

Create Logs

Logs need to be created for contracts to provide useful data to UI

simulated buy/sell not working

since the core has changed a bunch recently and these were working just fine before then, i'm assuming that this issue goes here.

Generic subcurrencies

Switch everything using cash to using generic subcurrencies once the new subcurrency API is final
remove setcash/add/remove cash when doing this

  • tx.origin vs msg.sender

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.