Giter Club home page Giter Club logo

pm-contracts's Introduction

Gnosis Prediction Market Contracts

Logo

Build Status

Codecov badge

Greenkeeper badge

Collection of smart contracts for the Gnosis prediction market platform (https://www.gnosis.pm). To interact with those contracts have a look at (https://github.com/gnosis/pm-js/).

Install

Install requirements with npm:

npm install @gnosis.pm/pm-contracts

Testing and Linting

Run all tests (requires Node version >=7 for async/await, and will automatically run TestRPC in the background):

npm test

Run all tests matching a regexp pattern by setting the TEST_GREP environment variable

TEST_GREP='short selling' npm test

Lint the JS

npm run lint

Compile and Deploy

These commands apply to the RPC provider running on port 8545. You may want to have TestRPC running in the background. They are really wrappers around the corresponding Truffle commands.

Compile all contracts to obtain ABI and bytecode:

npm run compile

Migrate all contracts required for the basic framework onto network associated with RPC provider:

npm run migrate

Network Artifacts

Show the deployed addresses of all contracts on all networks:

npm run networks

Command line options for truffle can be passed down through NPM by preceding the options list with --. For example:

Clean network artifacts:

npm run networks -- --clean

Network artifacts from running migrations will contain addresses of deployed contracts on the Kovan and Rinkeby testnets.

Take network info from networks.json and inject it into contract build artifacts. This is done prepublish as well.

npm run injectnetinfo

Extract all network information into networks.json.

Be aware that this will clobber networks.json, so be careful with this command:

npm run extractnetinfo

Gas Measurements

Log gas measurements into build/gas-stats.json

npm run measuregasstats

Documentation

There is a copy version hosted online at https://gnosis-pm-contracts.readthedocs.io/en/latest/

Locally build docs for readthedocs

Will install Sphinx and Solidity Domain for Sphinx:

cd docs
pip install -r requirements.txt
make html

Audits

Security and Liability

All contracts are WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

License

All smart contracts are released under LGPL v.3.

Contributors

pm-contracts's People

Contributors

cag avatar collinc97 avatar denisgranha avatar fvictorio avatar georgi87 avatar germartinez avatar greenkeeper[bot] avatar greenkeeperio-bot avatar muhammad-altabba avatar uxio0 avatar v1rtuouscycle 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

pm-contracts's Issues

An in-range update of decimal.js is breaking the build 🚨

The devDependency decimal.js was updated from 10.1.1 to 10.2.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

decimal.js is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 7 commits.

  • 30828c0 v10.2.0
  • 3f9eeb0 #128 Accept + prefix
  • f468de8 #128 Add tinyPow to workaround V8 Math.pow change
  • fe487dc Merge pull request #129 from zgayjjf/patch-1
  • 0a81a67 docs: typo fixed
  • f0dc751 Merge pull request #127 from harrysarson/patch-1
  • 6c6fbe7 Check node 12 in CI

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of cross-env is breaking the build 🚨

The devDependency cross-env was updated from 6.0.0 to 6.0.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

cross-env is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for v6.0.1

6.0.1 (2019-10-01)

Bug Fixes

  • update all packages, tests, and README (36bb6c3)
Commits

The new version differs by 3 commits.

  • 36bb6c3 fix: update all packages, tests, and README
  • 67d9aa6 docs: add coderberry as a contributor (#213)
  • f6978f5 chore: Add CodeFund sponsorship message to README (#212)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of babel-eslint is breaking the build 🚨

The devDependency babel-eslint was updated from 10.0.1 to 10.0.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

babel-eslint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v10.0.2

Fixes #772

Commits

The new version differs by 2 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Adding more Outcomes after a deal has started

Using event.sol you need to know all the possible events before you deploy the contract is a little too limiting.

Imagine if you wanted to play chess with a futarchy. You will need to have a separate token for each move that only pays out if that move happens and there is a win. You would have to have 1 round to allow people to propose moves and then you would have to take that list and reduces it so that you do not go over the gasBlockLimit in the for loop. Which would be quite a small list as OutcomeTokenCreation costs alot of gas.

Is it possible to use the current token model to start trading and still be able to propose other moves, and distribute the associated token to the everyone that calls buyAllOutcomes after the fact without being prohibitively expensive?

Approval attack

https://github.com/gnosis/gnosis-contracts/blob/9285b3e12708b921eecba827161b9295894b406f/contracts/Tokens/StandardToken.sol#L61

Some solidity coders propose to use an approvalIncrease function

    • @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
    • Beware that changing an allowance with this method brings the risk that someone may use both the old
    • and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
    • race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
    • ethereum/EIPs#20 (comment)
    • @param _spender The address which will spend the funds.
    • @param _value The amount of tokens to be spent.
      */
      function approve(address _spender, uint256 _value) public returns (bool) {
      allowed[msg.sender][_spender] = _value;
      Approval(msg.sender, _spender, _value);
      return true;
      }

Currently, all our smart contracts are save. But at some point, this might change, hence it would make sense to use an increaseApproval from the start.

An exemplary contract can be found here:
https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/token/StandardToken.sol

I think it should be done, but it is NOT important currently

An in-range update of babel-eslint is breaking the build 🚨

The devDependency babel-eslint was updated from 10.0.3 to 10.1.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

babel-eslint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 2 commits.

  • 4bd049e 10.1.0
  • 2c754a8 Update Babel to ^7.7.0 and enable Flow enums parsing (#812)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of @gnosis.pm/util-contracts is breaking the build 🚨

The dependency @gnosis.pm/util-contracts was updated from 2.0.0-alpha.3 to 2.0.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@gnosis.pm/util-contracts is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 43 commits ahead by 43, behind by 14.

There are 43 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Optimize LMSR calculations

Currently, StandardMarket is optimized via an automated market maker which employs the following formula:

cost = cost level after trade - cost level before trade

where

b = market funding / ln(number of outcomes)

cost level = b * ln( sum ( exp( net quantity of outcome sold / b ) over all outcomes ) )

See:

LMSR Primer
Hanson's original paper on LMSR
This other tutorial on LMSR

There are some computational tricks necessary to get this to compute on the EVM. For example, since the calculations internally use a fixed-point representation, it is very easy for the inner exponential sum to overflow. See comments in LMSRMarketMaker.sol for more details.

A couple of ways more optimal calculations of the price may be achieved:

  • Replace all ln with log2 and exp with pow2. You may verify that this does not change the result of the LMSR functions, but may be more computationally expedient. See #26
  • There is a floorLog2 meant to cut down on the computation required for logarithms in general. Right now it is used to adjust the natural logarithm, but of course, it may also be used for the base 2 logarithm. There may be a more efficient way to compute that than a binary search: #25

Acceptance criteria:

  • PR is made against the development branch
  • The existing test suite passes
  • There are significant gas cost savings for buying and selling (try npm run measuregasstats)
  • There are additional fuzz tests for pow2 and log2 like the existing tests for exp and ln with at most an error of 1e-9 (or for any other non-primitive math functions which are implemented as part of an optimization). See the math tests for existing examples.

An in-range update of lodash is breaking the build 🚨

The devDependency lodash was updated from 4.17.11 to 4.17.12.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

lodash is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of truffle is breaking the build 🚨

The devDependency truffle was updated from 5.0.30 to 5.0.31.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

truffle is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of truffle is breaking the build 🚨

The devDependency truffle was updated from 5.1.4 to 5.1.5.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

truffle is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of solhint is breaking the build 🚨

The devDependency solhint was updated from 1.2.1 to 1.3.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

solhint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 63 commits.

  • 2453bdf 1.3.0
  • 767bf88 Merge pull request #50 from canufeel/feat/multiple-vars-returned
  • e8c1dff Merge branch 'master' into canufeel-feat/multiple-vars-returned
  • fe21181 Merge pull request #67 from unjapones/add-poa-popa-to-who-uses-solhint
  • 03a1944 Add poanetwork/poa-popa to Projects in main README.md.
  • e3c5ce1 Merge pull request #66 from protofire/readmme-remove-rules-enumeration
  • 394b14b Remove rules enumeration from README file
  • 02d6e88 Merge pull request #64 from unjapones/projects-that-use-solhint
  • fd9f3dc Set name of dex-contract in README.md "Projects".
  • df83bb0 List (GitHub) organizations and projects that use solhint.
  • c032a0a Add "Projects that use solhint" to README.md.
  • 0657e8c Upgrade coveralls dependency
  • ac60a6d Merge pull request #60 from protofire/add-prettier-and-airbnb
  • b47c7f2 Merge pull request #61 from Cambalab/add-contribution-complete-docs
  • 302a1b5 Update index.md

There are 63 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Gas stats should take inheritance into account

The gas stats have this going on:

Contract: Event
  buyAllOutcomes:
    min: 90982
    max: 135662
    avg: 126726
    med: 135662

...

Contract: CategoricalEvent
  buyAllOutcomes:
    min: 91046
    max: 91046
    avg: 91046
    med: 91046

Upgrade to Truffle 4.x

This repo still relies on Truffle 3.4.11. As you probably know for a while Solidity started issuing deprecation warnings for a lot of old syntax/features which will turn into errors with the 0.5.0 release.

Truffle in the 4.x releases has updated Assert.sol to deal with all those requirements. It would be great if Gnosis could upgrade to 4.x and get the benefit of these updates.

Since the Solidity CI also compiles Gnosis contracts, that would make our life much more easier 😉

Add another withdraw method to allow ETH transfer directly to other address

It would be easy for plasma like a contract to use WETH, if EtherToken.sol can add withdraw(uint value, address user) method.

This change will reduce transfer ETH easy by doing -

WETH(wethAddress).withdraw(amount, msg.sender)

// instead of this (will not work when you have payable default function)
// WETH(wethAddress).withdraw(amount)
// msg.sender.transfer(amount)

Following is the example -

    /// @dev Sells tokens in exchange for Ether, exchanging them 1:1
    /// @param value Number of tokens to sell
    /// @param user Address of user
    function withdraw(uint value, address user)
        public
    {
        // Balance covers value
        balances[msg.sender] = balances[msg.sender].sub(value);
        totalTokens = totalTokens.sub(value);
        user.transfer(value);
        Withdrawal(msg.sender, value); // can have different event or can change current event
    }

Let me know what do you think. I can send pull request if everyone agrees.

Deployed instance of EtherToken

Hello, I am looking to make use of the Gnosis EtherToken. I happened across this deployed Wrapped Ether contract that seems like it is pretty heavily used. Unfortunately it has no link to its source code. I'm wondering if you are able to verify that this is an instance of the Gnosis EtherToken implementation, or maybe point me in the direction of what other implementation it might be if you happen to have an idea?

LSMR is effectively charging fees even with 0% fee input

https://github.com/gnosis/gnosis-contracts/blob/8c72d7ec6aff48478ab1eba78596a572c77a9cba/contracts/MarketMakers/LMSRMarketMaker.sol#L73

In most cases, the calcProfit function is called followed by an enforced eventContract.sellAllOutcomes(outcomeTokenProfit);

In these situations, it would be nice to offer traders something like this ipo line 73

for(uint outcomeTokenIndex=0;outcomeTokenIndex< OutcomeTokens.length;outcomeTokenIndex++) {      
netOutcomeTokensSold[outcomeTokenIndex] = netOutcomeTokensSold[outcomeTokenIndex].sub(int(outcomeTokenCount));
}

to enable the most efficient markets, which allow a buy order followed by an immediate sell without loosing money.
With the current version, the LSMR is charging indirect fees by calculating the costLevelAfter on wrong outcomeTokensSold assumptions. Just try to first buy 10 tokens and then sell them again, but you will end up with less. If we have the for loop, we won't end up with less.

If the function calcProfit is called somewhere without an enforced sellAllOutcomes, then it does not make sense to have this for loop in.
@cag What do you think about it?

An in-range update of eslint is breaking the build 🚨

The devDependency eslint was updated from 5.15.3 to 5.16.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v5.16.0
  • dfef227 Build: gensite passes rulesMeta to formatter rendering (#11567) (Kevin Partington)
  • c06d38c Fix: Allow HTML formatter to handle no meta data (#11566) (Ilya Volodin)
  • 87a5c03 Docs: func-style: clarify when allowArrowFunctions is used (#11548) (Oliver Joseph Ash)
  • bc3e427 Update: pass rule meta to formatters RFC 10 (#11551) (Chris Meyer)
  • b452f27 Chore: Update README to pull in reviewer data (#11506) (Nicholas C. Zakas)
  • afe3d25 Upgrade: Bump js-yaml dependency to fix Denial of Service vulnerability (#11550) (Vernon de Goede)
  • 4fe7eb7 Chore: use nyc instead of istanbul (#11532) (Toru Nagashima)
  • f16af43 Chore: fix formatters/table test (#11534) (Toru Nagashima)
  • 78358a8 Docs: fix duplicate punctuation in CLI docs (#11528) (Teddy Katz)
Commits

The new version differs by 11 commits.

  • ded2f94 5.16.0
  • ea36e13 Build: changelog update for 5.16.0
  • dfef227 Build: gensite passes rulesMeta to formatter rendering (#11567)
  • c06d38c Fix: Allow HTML formatter to handle no meta data (#11566)
  • 87a5c03 Docs: func-style: clarify when allowArrowFunctions is used (#11548)
  • bc3e427 Update: pass rule meta to formatters RFC 10 (#11551)
  • b452f27 Chore: Update README to pull in reviewer data (#11506)
  • afe3d25 Upgrade: Bump js-yaml dependency to fix Denial of Service vulnerability (#11550)
  • 4fe7eb7 Chore: use nyc instead of istanbul (#11532)
  • f16af43 Chore: fix formatters/table test (#11534)
  • 78358a8 Docs: fix duplicate punctuation in CLI docs (#11528)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Should allow to pass variables to default oracle functions `isOutcomeSet()` and `getOutcome()`

The default oracle functions (isOutcomeSet() and getOutcome()) should contain a bytes32 as input. The reason being that right now an oracle contract can only report on a single event as there is no way to request specific information.

To keep things general it would be nice to pass bytes32 always so that a single oracle can report upon multiple events.

For example: If i have a tic tac toe contract that plays multiple games in it. And i want to allow prediction markets to link into it. Each game is identified with keccak256(msg.sender,block.number) and each time i want to resolve a game i need to specify the game i want to resolve like below.

        function isOutcomeSet(bytes32 hash) public constant returns (bool) {
                return(games[hash].isFinished);
        }

        function getOutcome(bytes32 hash) public constant returns (int) {
                return(games[hash].winner);
        }

I understand the need to keep this general. But passing nothing will force ppl to deploy alot of contracts to act as intermediaries. Using the bytes32 is the best IMO as its the size of the keccak256 hash output which is used most often.

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.