GithubHelp home page GithubHelp logo

swswsw / predictionmkt Goto Github PK

View Code? Open in Web Editor NEW
12.0 4.0 2.0 6.52 MB

prediction market on lotionjs with tendermint

License: MIT License

JavaScript 8.09% CSS 80.19% HTML 11.73%
blockchain tendermint lotionjs cosmos prediction-market

predictionmkt's Introduction

prediction market

market phase

  1. open new market
  2. allow bet
  3. someone bets (record them)
  4. market closes (by time)

oracle phase

condition to enter phase: time

  1. get data from oracle
  2. determine the result and record it

condition to end phase: time

challenge phase

condition to enter phase: time, someone triggers it

  1. someone stake their coin and challenges

condition to end phase: time

vote phase

condition to enter phase: challenge phase completed

  1. anyone can stake their coin and vote

condition to end phase: time

distribute phase

condition to enter phase: time

  1. determine the final outcome
if (challenged)
  update the final outcome according to voting results
  distributed the staked coins in voting pool according to voting results.
distribute betting pool coins according to outcome

condition to end phase: when everything in the phase is executed

note

the time of the phase is indicated by block height. since we have finality, the phase start and stop block can be next to each other. in other ledger that lacks finality, we should reserve more time (several blocks) between each phase.

run

node app.js

test invocation:

it is possible to do test invocation using curl. however, you will need to supply signature yourself.
it is recommended to use test/testCommon.js complexSendTx(), which will handle the signature, public key (pubkey), and sequence.

for example of test invocation, please see test/testIntegrate2.js


if you need to if you need to send a transaction manually, you need to supply from.pubkey, from.signature, from.sequence, and to. the format is as follows.

curl -X POST http://localhost:3000/txs -d '{"type": "verifySig", "from": { "pubkey": "rewlkjrlw", "signature": "rewlkajrlewk", "sequence": 0 }, "to": {} }'

all of the tx will need from and to. however, for brevity purpose, they are omitted in the following calls:

curl -X POST http://localhost:3000/txs -d '{"type": "start", "marketId": "market2", "startInfo": ...}'

example startInfo:

  "startInfo": {
      "question": "Who will win FIFA 2018?",
      "outcomes": [
        "england",
        "italy",
        "brazil",
        "germany"
      ],
      "oracle": ["9x2yu6AzwWphm3j6h9pTaJh63h5ioG8RL","5wvwWgKP3Qfw1akQoXWg4NtKmzx5v4dTj"], // addresses of approved oracles
      // meta data about oracle.  eg. description
      "oracleMeta": "http://data.com/oracleinfo",
      "phaseTime":{
        "marketStart":9,"marketEnd":3609,
        "oracleStart":3610,"oracleEnd":7210,
        "challengeStart":7211,"challengeEnd":10811,
        "voteStart":10812,"voteEnd":14412,
        "distributeStart":14413,"distributeEnd":18013
      },
    }

curl -X POST http://localhost:3000/txs -d '{"type": "bet", "marketId": "market2", "outcome": 1, "amount": 10, "user": "5wvwWgKP3Qfw1akQoXWg4NtKmzx5v4dTj"}'

curl -X POST http://localhost:3000/txs -d '{"type": "bet", "marketId": "market2", "outcome": 2, "amount": 10, "user": "9x2yu6AzwWphm3j6h9pTaJh63h5ioG8RL"}'

curl -X POST http://localhost:3000/txs -d '{"type": "oracle", "marketId": "market2", "outcome": 2}'

curl -X POST http://localhost:3000/txs -d '{"type": "challenge", "marketId": "market2", "user": "5wvwWgKP3Qfw1akQoXWg4NtKmzx5v4dTj", "amount": 100}'

curl -X POST http://localhost:3000/txs -d '{"type": "vote", "marketId": "market2", "user": "5wvwWgKP3Qfw1akQoXWg4NtKmzx5v4dTj", "amount": 1000, "outcome": 1}'

curl -X POST http://localhost:3000/txs -d '{"type": "vote", "marketId": "market2", "user": "9x2yu6AzwWphm3j6h9pTaJh63h5ioG8RL", "amount": 10, "outcome": 2}'

curl -X POST http://localhost:3000/txs -d '{"type": "vote", "marketId": "market2", "user": "9x2yu6AzwWphm3j6h9pTaJh63h5ioG8RL", "amount": 1000, "outcome": 1}'

curl -X POST http://localhost:3000/txs -d '{"type": "distribute", "marketId": "market2"}'

for example of sending token to another address, see test/testSend.js for example of tx format.

update

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.