I’m trying to understand how betting works.
I post notes here. I suppose it will be useful for others too.
http://counterparty.io/docs/protocol_specification/ - See BROADCAST and BET
http://www.rubydoc.info/github/brighton36/counterparty_ruby/Counterparty/Bet
Oracle / Feed Operator
When an address makes a broadcast with value -1 it creates a feed (opens a bet).
The next broadcast from the same address settles the bet. The broadcast value determines the outcome. A settlement value must be non-negative. -2 cancels all open bets. -3 cancels all bet matches. Any other negative value is ignored.
'broadcast': ['source', 'fee_fraction', 'text', 'timestamp', 'value'],
The fee_fraction enables the oracle to take a cut. Eg at 1% the winner will get 99% of the escrowed amount and the oracle gets 1%.
Bet
Anyone can play on a feed. There are two kind of bets; CFDs and Bionomial (Equal/Not Equal). When you make a bet, the specified amount of XCP on your address will be escrowed. If someone else has made an opposite bet with equal or overlapping odds, your two bets will match. Your amounts will remain escrowed until the oracle determines the outcome (or if he doesn’t, you’ll both get your XCP amounts back two weeks after the deadline). If there is no matching bet, your bet will be pending until there is a match (and the oracle decides the outcome), the deadline or it expires.
'bet': ['source', 'feed_address', 'bet_type','deadline', 'wager_quantity', 'counterwager_quantity', 'expiration', 'target_value', 'leverage'],
For two Bets to be matched, their leverage levels, deadlines and target values must be identical. Otherwise, they are matched the same way that orders are, except a Bet’s odds are the multiplicative inverse of an order’s price (odds = wager/counterwager)
Source is your own address.
Feed address is that of the operator/oracle (a oracle can only have one feed at a time)
Bet type can be 0 (Bullish CFD), 1 (Bearish CFD), 2 (Equal), 3 (Not Equal)
Deadline: Unix timestamp. If the operator has not settled the bet within 2016 blocks (~14 days) after the deadline, the bet will expire and escrow returned ???
Wager quantity ??? If you place a Bullish CFD or Equal bet, you will escrow this amount?
Counterwager quantity ??? If you place a Bearish CFD or Not Equal bet, you will escrow this amount?
The odds equal wager/counterwager. If you place Equal bet, wager = 1, counterwager = 2, the odds is 1 to 2. You have 1 XCP escrowed. Alice bets on Not equal, wager = 1, counterwager = 2. She gets 2 XCP escrowed. Since your two bets match (assuming leverage, deadline, target equal) the final outcome is settled by the oracle. If broadcast value = target value, you will receive the entire 3 XCP pot, else Alice will receive the 3 XCP (minus any oracle fee).
Expiration ??? Number of blocks until an unmatched bet expires?
Target value A non-negative number that sets the bet. For binomial bets, the Equal bet wins if the oracle broadcasts this value, otherwise the Not equal bet wins. For CFDs it is more complicated (can look at this later).
Leverage For binomial bets this must be 5040. It’s just a magic number. Does only have a meaning for CFDs. This I can look at later.
…
Bet transaction
A valid bet transaction:
http://blockscan.com/betInfo?q=11551745
https://www.blocktrail.com/BTC/tx/1b23d932cfb73a12dc0be593b95164c00524864ee21580c6bf799fd78ed9e045
The ‘feed_address’ is encoded by sending some btc dust to it (as with asset send). All other parameters are encoded in a single multisig. It should be possible also to encode as op_return.