A network of smart-contracts to facilitate a system of peer-to-peer betting called Mevu.
This code is still in active development and is not yet intended for a main net release.
Please see the contracts/ directory.
- Contracts are written in Solidity and tested using Truffle and ganache-cli and the Oraclize ethereum-bridge.
https://github.com/OpenZeppelin/zeppelin-solidity
https://github.com/oraclize/ethereum-api
If testing :
https://github.com/trufflesuite/ganache-cli
https://github.com/oraclize/ethereum-bridge
truffle test
setCallbackGasLimit
function setCallbackGasLimit (uint newLimit) external onlyAuth
Sets the gas limit for the callbcak transaction initiated by the oraclizeAPI.
setCallbackInterval
function setCallbackInterval(uint newInterval) external onlyAuth
Sets the interval (seconds) between the callback loops which update events.
setMinOracleStake
function setMinOracleStake (uint newMin) external onlyAuth
Sets the minimum stake required for a user to oraclize an event.
setMinOracleNum
function setMinOracleNum (bytes32 eventId, uint min) external onlyAuth
Sets the minimum number of Oracles required to satisfactorily determine the winner of a particular event.
setMinWagerAmount
function setMinWagerAmount(uint256 minWager) external onlyAuth
Sets the minimum amount of ETH a player is allowed to make a bet with.
setMaxOracleInterval
function setMaxOracleInterval (uint max) external onlyAuth
Set the maximum amount of time (seconds) allowable between oraclizations for a user to be eligible to win the monthly lottery.
setOracleRepPenalty
function setOracleRepPenalty (int penalty) external onlyAuth
Set the reputation penalty incurred by an Oracle who has voted against consensus.
setOracleRepReward
function setOracleRepReward (int reward) external onlyAuth
Set the reputation reward awarded to an Oracle who has voted with consensus.
setPlayerAgreeRepReward
function setPlayerAgreeRepReward (int reward) external onlyAuth
Set the reputation reward awarded to a player who has successfully settled their bet without requiring Oracles.
setPlayerDisagreeRepPenalty
function setPlayerDisagreeRepPenalty (int penalty) external onlyAuth
Set the reputation penalty incurred by a player who disputed an event outcome and was found to be aganist Oracle consensus.
getCallbackGasLimit
function getCallbackGasLimit() external view returns (uint)
Returns the gas limit for oraclize callbacks.
getCallbackInterval
function getCallbackInterval() external view returns (uint)
Returns the interval (seconds) between oraclize callback loops.
getMaxOracleInterval
function getMaxOracleInterval() external view returns (uint)
Returns the max alllowable interval (seconds) between oraclizations for an oracle to be eligible to win the monthly lottery.
getMinOracleNum
function getMinOracleNum (bytes32 eventId) external view returns (uint)
Returns minimum number of Oracles required to settle a specific event.
getMinOracleStake
function getMinOracleStake () external view returns (uint)
Returns minimum stake required to register as an oracle for an event.
getMinWagerAmount
function getMinWagerAmount() external view returns (uint)
Returns minimum amount of ETH required to bet with.
getOracleRepPenalty
function getOracleRepPenalty () external view returns (int)
Returns rep penalty incurred by Oracle for reporting against consensus.
getOracleRepReward
function getOracleRepReward () external view returns (int)
Returns rep reward awarded to an Oracle for reporting with consensus.
getPlayerAgreeRepReward
function getPlayerAgreeRepReward () external view returns (int)
Returns rep reward awarded to a player for settling a bet without requiring Oracles.
getPlayerDisagreeRepPenalty
function getPlayerDisagreeRepPenalty () external view returns (int)
Returns rep penalty incurred by a player who diputed an outcome and was found to be against Oracle consensus.
grantAuthority
function grantAuthority (address nowAuthorized) external onlyOwner
Grants an address authority by adding it to the isAuthorized mapping.
removeAuthority
function removeAuthority (address unauthorized) external onlyOwner
Takes an address' authority by removing it from the isAuthorized mapping.
setMevuContract
function setMevuContract (address thisAddr) external onlyOwner
Sets the address which the latest Mevu contract is deployed to.
setCustomWagersContract
function setCustomWagersContract (address thisAddr) external onlyOwner
Sets the address which the latest CustomWagers contract is deployed to.
setWagersContract
function setWagersContract (address thisAddr) external onlyOwner
Sets the address which the latest Wagers contract is deployed to.
setRewardsContract
function setRewardsContract (address thisAddr) external onlyOwner
Sets the address which the latest Rewards contract is deployed to.
abortWagerCustom
function abortWagerCustom(bytes32 wagerId) internal
Settles a custom wager and refunds the players.
abortWagerStandard
function abortWagerStandard(bytes32 wagerId) internal
Settles a standard wager and refunds the players.
cancelWagerStandard
function cancelWagerStandard (bytes32 wagerId, bool withdraw)
onlyBettorStandard(wagerId)
notPaused
notTakenStandard(wagerId)
external
Cancels a standard wager before a player has taken it.
cancelWagerCustom
function cancelWagerCustom (bytes32 wagerId, bool withdraw)
onlyBettorCustom(wagerId)
notPaused
notTakenCustom(wagerId)
external
Cancels a custom wager before a player has taken it.
requestCancelCustom
function requestCancelCustom (bytes32 wagerId)
onlyBettorCustom(wagerId)
mustBeTakenCustom(wagerId)
notSettledCustom(wagerId)
external
Requests the cancellation of a matched custom wager.
requestCancelStandard
function requestCancelStandard (bytes32 wagerId)
onlyBettorStandard(wagerId)
mustBeTakenStandard(wagerId)
notSettledStandard(wagerId)
external
Requests the cancellation of a matched standard wager.
confirmCancelStandard
function confirmCancelStandard (bytes32 wagerId)
notSettledStandard(wagerId)
external
Confirms the cancellation of a matched standard wager where both players have requested cacellation.
confirmCancelCustom
function confirmCancelCustom (bytes32 wagerId)
notSettledCustom(wagerId)
external
Confirms the cancellation of a matched custom wager where both players have requested cancellation.
makeWager
function makeWager (
bytes32 wagerId,
uint endTime,
uint reportinEndTime,
uint origValue,
uint winningValue,
uint makerChoice,
uint takerChoice,
uint odds,
uint makerWinnerVote,
uint takerWinnerVote,
address maker,
address judge
)
external
onlyAuth
Creates a wager in the wagers mapping.
setCancelled
function setCancelled (bytes32 wagerId) external onlyAuth
Sets a wager as cancelled.
setSettled
function setSettled (bytes32 wagerId) external onlyAuth
Sets a wager as settled.
setMakerWinVote
function setMakerWinVote (bytes32 id, uint winnerVote) external onlyAuth
After an event is over set the bet maker's vote for the event winner.
setTakerWinVote
function setTakerWinVote (bytes32 id, uint winnerVote) external onlyAuth
After an event is over set the bet taker's vote for the event winner.
setRefund
function setRefund (address bettor, bytes32 wagerId) external onlyAuth
Sets the boolean indicating that a player has recieved a refund for a particular bet to true.
setMakerCancelRequest
function setMakerCancelRequest (bytes32 id) external onlyAuth
Sets the boolean indicating that a bet maker has requested a cancellation for a particular bet to true.
setTakerCancelRequest
function setTakerCancelRequest (bytes32 id) external onlyAuth
Sets the boolean indicating that a bet taker has requested a cancellation for a particular bet to true.
setTaker
function setTaker (bytes32 wagerId, address taker) external onlyAuth
Sets the taker for a bet.
setWinner
function setWinner (bytes32 id, address winner) external onlyAuth
Sets the winner for a bet.
setJudgesVote
function setJudgesVote (bytes32 id, uint vote) external onlyAuth
Sets the judges vote for a bet.
setLoser
function setLoser (bytes32 id, address loser) external onlyAuth
Sets the loser for a bet.
setWinningValue
function setWinningValue (bytes32 wagerId, uint value) external onlyAuth
Sets the amount that the bet winner will recieve before fees.
getCancelled
function getCancelled (bytes32 wagerId) external view returns (bool)
Returns the bool indicating if the given bet has been cancelled.
getEndTime
function getEndTime (bytes32 wagerId) external view returns (uint)
Returns the end timestamp of the given bet.
getReportingEndTime
function getReportingEndTime (bytes32 wagerId) external view returns (uint)
Returns the end timestamp of the reporting period for a given bet.
getLocked
function getLocked (bytes32 id) external view returns (bool)
Returns true if the given bet has been taken.
getSettled
function getSettled (bytes32 id) external view returns (bool)
Returns true if the given bet has been settled (paid out or cancelled).
getMaker
function getMaker(bytes32 wagerId) external view returns (address)
Returns the bets maker.
getTaker
function getTaker(bytes32 wagerId) external view returns (address)
Returns the bets taker.
getMakerChoice
function getMakerChoice (bytes32 wagerId) external view returns (uint)
Returns the team number the maker bet on.
getTakerChoice
function getTakerChoice (bytes32 wagerId) external view returns (uint)
Returns the team number the taker bet on.
getMakerCancelRequest
function getMakerCancelRequest (bytes32 wagerId) external view returns (bool)
Returns true if the maker has requested a bet cancellation.
getTakerCancelRequest
function getTakerCancelRequest (bytes32 wagerId) external view returns (bool)
Returns true if the taker has requested a bet cancellation.
getMakerWinVote
function getMakerWinVote (bytes32 wagerId) external view returns (uint)
Returns the maker's vote for the event winner regarding a given bet.
getTakerWinVote
function getTakerWinVote (bytes32 wagerId) external view returns (uint)
Returns the taker's vote for the event winner regarding a given bet.
getRefund
function getRefund (address bettor, bytes32 wagerId) external view returns (bool)
Returns true if the given bettor has already recieved a refund for the given bet.
getOdds
function getOdds (bytes32 wagerId) external view returns (uint)
Returns the odds for a given bet.
getOrigValue
function getOrigValue (bytes32 wagerId) external view returns (uint)
Returns the amount sent by the maker for a given bet.
getWinningValue
function getWinningValue (bytes32 wagerId) external view returns (uint)
Returns the amount sent by the maker and taker for a given bet.
getWinner
function getWinner (bytes32 wagerId) external view returns (address)
Returns the winner of a given bet.
getLoser
function getLoser (bytes32 wagerId) external view returns (address)
Returns the loser of a given bet.
getJudge
function getJudge (bytes32 wagerId) external view returns (address)
Returns the judge of a given bet.
getJudgesVote
function getJudgesVote (bytes32 wagerId) external view returns (uint)
Returns the vote cast by a judge of a given bet.
setAdminContract
function setAdminContract (address thisAddr) external onlyOwner
Sets the address which the latest Admin contract is deployed to.
setMevuContract
function setMevuContract (address thisAddr) external onlyOwner
Sets the address which the latest Mevu contract is deployed to.
setCustomWagersContract
function setCustomWagersContract (address thisAddr) external onlyOwner
Sets the address which the latest CustomWagers contract is deployed to.
setRewardsContract
function setRewardsContract (address thisAddr) external onlyOwner
Sets the address which the latest Rewards contract is deployed to.
makeWager
function makeWager (
bytes32 id,
uint endTime,
uint reportingEndTime,
uint makerChoice,
uint value,
uint odds,
address judge
)
notMade(id)
checkBalance(value)
notPaused
external
payable
Used by a player to make a new bet.
takeWager
function takeWager (
bytes32 id,
address judge
)
notTaken(id)
notOver(id)
external
payable
Used by a player to take a bet.
submitVote
function submitVote (
bytes32 wagerId,
uint winnerVote
)
onlyBettor(wagerId)
mustBeEnded(wagerId)
notSettled(wagerId)
notPaused
external
Used by a player to submit vote for winner after event has ended.
submitJudgeVote
function submitJudgeVote (bytes32 wagerId, uint vote)
mustBeEnded(wagerId)
notSettled(wagerId)
validVote(vote)
external
Used by a player assigned as a judge for a custom wager to submit vote for winner after event has ended.
settle
function settle(bytes32 wagerId) internal
Settles bet after both bettors have voted.
judgeSettle
function judgeSettle (
bytes32 wagerId,
address judge,
uint judgesVote,
address maker,
address taker,
uint makerWinVote,
uint origValue,
uint payoutValue
)
internal
Settles bet after the judge has voted.
tieJudged
function tieJudged(address judge, address maker, address taker, uint origValue, uint payoutValue ) internal
Facilitates payout if the judge had to rule a tie.
checkJudge
function checkJudge (bytes32 wagerId, address maker, address taker, uint makerWinVote, uint takerWinVote, uint origValue, uint payoutValue) internal
Checks to see if there has been a judge appointed, if so, checks to see if they've voted yet. If there is no judge the wager is aborted.
finalizeAbandonedBet
function finalizeAbandonedBet (bytes32 wagerId)
onlyBettor(wagerId)
reportingOver(wagerId)
external
Allows a bettor to reclaim their eth if the person they are betting with never reports.
payout
function payout(bytes32 wagerId, address maker, address taker, uint payoutValue, bool agreed) internal
Pays out a settled wager.
withdraw
function withdraw(
uint eth
)
notPaused
external
Allows a user to withdraw eth that may still be in the mevu contract due to an aborted wager.
abortWager
function abortWager(bytes32 wagerId) internal
Sets a wager as settled and unlocks the eth so users can withdraw.
JudgeNeeded
event JudgeNeeded (address judge, bytes32 wagerId)
WagerMade
event WagerMade(bytes32 id)
WagerTaken
event WagerTaken(bytes32 id)
WagerSettled
event WagerSettled(bytes32 wagerId)
setAdminContract
function setAdminContract (address thisAddr) external onlyOwner
Sets the address which the latest Admin contract is deployed to.
setMevuContract
function setMevuContract (address thisAddr) external onlyOwner
Sets the address which the latest Mevu contract is deployed to.
setOraclesContract
function setOraclesContract (address thisAddr) external onlyOwner
Sets the address which the latest Oracles contract is deployed to.
makeStandardEvent
function makeStandardEvent(
bytes32 id,
bytes32 name,
uint startTime,
uint duration,
bytes32 teamOne,
bytes32 teamTwo
)
external
onlyOwner
Creates a supported event for users to bet on and oraclize.
addResolvedWager
function addResolvedWager (bytes32 eventId, uint value) external onlyAuth
Adds the value of a resolved wagger to the running total value of resolved wagers based on a specific event.
determineEventStage
function determineEventStage (bytes32 thisEventId, uint lastIndex) external onlyAuth
If an event is recently completed, it is designated as voteReady, if it was already voteReady then it is now locked.
decideWinner
function decideWinner (bytes32 eventId) internal
Determines the winner of a completed event based on oracle votes.
removeEventFromActive
function removeEventFromActive (bytes32 eventId) internal
Removes an event which is over and settled from the active events array.
removeWager
function removeWager (bytes32 eventId, uint value) external onlyAuth
Removes wager data from the event struct.
addWager
function addWager(bytes32 eventId, uint value) external onlyAuth
Adds wager data to the event struct.
setWinner
function setWinner (bytes32 eventId, uint winner) public onlyAuth
Sets event winner.
setLocked
function setLocked (bytes32 eventId) public onlyAuth
Sets event as locked.
getFinished
function getFinished (bytes32 eventId) external view returns (bool)
Returns true if the current block time is later than the event end time.
getActiveEventId
function getActiveEventId (uint i) external view returns (bytes32)
Returns the bytes32 id of the wager in the active events array at the given index.
getActiveEventsLength
function getActiveEventsLength () external view returns (uint)
Returns the length of the active events array.
getStandardEventCount
function getStandardEventCount () external view returns (uint)
Returns the total number of events ever.
getTotalAmountBet
function getTotalAmountBet (bytes32 eventId) external view returns (uint)
Returns the total number of events ever.
getTotalAmountResolvedWithoutOracles
function getTotalAmountResolvedWithoutOracles (bytes32 eventId) external view returns (uint)
Returns the amount of wei that bettors on this event who have resolved without oracles have bet.
getCancelled
function getCancelled(bytes32 id) external view returns (bool)
Returns true if the given event has been cancelled.
getStart
function getStart (bytes32 id) public view returns (uint)
Returns the start time (timestamp in seconds) of given event.
getDuration
function getDuration (bytes32 id) public view returns (uint)
Returns the duration (seconds) of given event.
getEndTime
function getEndTime (bytes32 id) public view returns (uint)
Returns the end time (timestamp in seconds) of given event.
getLocked
function getLocked(bytes32 id) public view returns (bool)
Returns true if event is over and settled or cancelled.
getWinner
function getWinner (bytes32 id) external view returns (uint)
Returns the winner of the event. 1 = team one, 2 = team two, 3 = tie, 4 = no clear winnner
getVoteReady
function getVoteReady (bytes32 id) public view returns (bool)
Returns true if the event is currently in the voting/reporting period (i.e. finished but not locked).
makeVoteReady
function makeVoteReady (bytes32 id) internal
Sets an event as vote ready to initiate the voting period.
EventVoteReady
event EventVoteReady(bytes32 eventId)
setAdminContract
function setAdminContract (address thisAddr) external onlyOwner
Sets the address which the latest Admin contract is deployed to.
setEventsContract
function setEventsContract (address thisAddr) external onlyOwner
Sets the address which the latest Events contract is deployed to.
setMvuTokenContract
function setEventsContract (address thisAddr) external onlyOwner
Sets the address which the latest Events contract is deployed to.
setOraclesContract
function setOraclesContract (address thisAddr) external onlyOwner
Sets the address which the MvuToken contract is deployed to.
setRewardsContract
function setRewardsContract (address thisAddr) external onlyOwner
Sets the address which the latest Rewards contract is deployed to.
setWagersContract
function setWagersContract (address thisAddr) external onlyOwner
Sets the address which the latest Wagers contract is deployed to.
setMevuWallet
function setMevuWallet (address newAddress) external onlyOwner
Sets the address which the mevu multi-sig wallet is deployed to.
abandonContract
function abandonContract() external onlyPaused
Allows user to abandon contract and withdraw funds if platform has been compromised and admin has paused it.
__callback
function __callback (bytes32 myid, string result) notPaused
Is called by Oraclize API.
randomNum
function randomNum(uint max) private
Calls the oraclize contract for a random number generated through the Wolfram Alpha engine.
checkLottery
function checkLottery() internal
Checks to see if a month (in seconds) has passed since the last lottery paid out, pays out if so.
payoutLottery
function payoutLottery(address potentialWinner) internal
Pays out the monthly lottery balance to a random oracle.
playerRefund
function playerRefund (bytes32 wagerId) external onlyBettor(wagerId)
Players should call this when an event has been cancelled after thay have made a wager to recieve a refund.
allowedToWin
function allowedToWin (address potentialWinner) internal view returns (bool)
Checks if a potential lottery winner has oraclized an event recently enough to be eligible to win.
pauseContract
function pauseContract () external onlyOwner
Pauses the contract, preventing betting and only allowing emergency withdrawals.
restartContract
function restartContract(uint secondsFromNow) external onlyOwner payable
Restarts a paused contract by reinitiating the oraclize recursion.
mevuWithdraw
function mevuWithdraw (uint amount) external onlyOwner
Allows mevu team to withdraw earnings to multi-sig wallet.
addMevuBalance
function addMevuBalance (uint amount) external onlyAuth
Adds to the mevu balance.
addEventToIterator
function addEventToIterator () external onlyAuth
Adds one to the iterator index.
addLotteryBalance
function addLotteryBalance (uint amount) external onlyAuth
Adds to the lottery balance.
addToPlayerFunds
function addToPlayerFunds (uint amount) external onlyAuth
Adds to the player funds balance.
subFromPlayerFunds
function subFromPlayerFunds (uint amount) external onlyAuth
Subs from the player funds balance.
transferEth
function transferEth (address recipient, uint amount) external onlyAuth
Transfers eth from the mevu contract.
getContractPaused
function getContractPaused() external view returns (bool)
Returns true if contract is paused.
getOracleFee
function getOracleFee () external view returns (uint256)
Returns the oracle service fee.
transferTokensToMevu
function transferTokensToMevu (address oracle, uint mvuStake) internal
Transfers MVU tokens to the mevu contract.
transferTokensFromMevu
function transferTokensFromMevu (address oracle, uint mvuStake) external onlyAuth
Transfers MVU tokens from the mevu contract.
addMonth
function addMonth () internal
Resets the newMonth variable to a month in the future.
getNewMonth
function getNewMonth () internal view returns (uint256)
Resets the newMonth variable, this is when the lottery will payout.
uintToBytes
function uintToBytes(uint v) internal view returns (bytes32 ret)
Returns the bytes32 of a given uint.
bytes32ToString
function bytes32ToString (bytes32 data) internal view returns (string)
Returns the string of a given bytes32.
NewOraclizeQuery
event NewOraclizeQuery (string description)
addOracle
function addOracle (address oracle, bytes32 eventId, uint mvuStake, uint winnerVote) external onlyAuth
Adds an oracle and their vote info to the oracleStructs and eventStructs mappings.
removeOracle
function removeOracle (address oracle, bytes32 eventId) external onlyAuth
Removes an oracle from an event
setEventsContract
function setEventsContract (address thisAddress) external onlyOwner
setCurrentWinner
function setCurrentWinner (bytes32 eventId)
Calculates votes and sets winner of the event
addToOracleList
function addToOracleList (address oracle) external onlyAuth
Adds an oracle to oracle list
setPaid
function setPaid (address oracle, bytes32 eventId) external onlyAuth
Sets oracle as paid for the event
setLastEventOraclized
function setLastEventOraclized (address oracle, bytes32 eventId) external onlyAuth
Sets current event as the last event an oracle has orcalized
setRefunded
function setRefunded (address oracle, bytes32 eventId) external onlyAuth
Sets oracle as refunded for the event
setRegistered
function setRegistered (address oracle, bytes32 eventId) external onlyAuth
Registers oracles for a event
getCurrentWinner
function getCurrentWinner (bytes32 eventId) external view returns (uint)
Returns current winner of a given event
getRegistered
function getRegistered (address oracle, bytes32 eventId) external view returns (bool)
Returns if oracle is registered for a given event
getWinnerVote
function getWinnerVote(bytes32 eventId, address oracle) external view returns (uint)
Returns the oracles vote on a given event
getPaid
function getPaid (bytes32 eventId, address oracle) external view returns (bool)
Returns oracle paid status
getRefunded
function getRefunded (bytes32 eventId, address oracle) external view returns (bool)
Returns oracle refund status
getVotesForOne
function getVotesForOne (bytes32 eventId) external view returns (uint)
Returns votes for outcome or team number one from a given event ID
getVotesForTwo
function getVotesForTwo (bytes32 eventId) external view returns (uint)
Returns votes for outcome or team number two from a given event ID
getVotesForThree
function getVotesForThree (bytes32 eventId) external view returns (uint)
Returns votes for outcome or team number three from a given event ID
getStakeForOne
function getStakeForOne (bytes32 eventId) external view returns (uint)
Returns total MVU staked by oracles for outcome or team number one from a given event ID
getStakeForTwo
function getStakeForTwo (bytes32 eventId) external view returns (uint)
Returns total MVU staked by oracles for outcome or team number two from a given event ID
getStakeForThree
function getStakeForThree (bytes32 eventId) external view returns (uint)
Returns total MVU staked by oracles for outcome or team number three from a given event ID
getMvuStake
function getMvuStake (bytes32 eventId, address oracle) external view returns (uint)
Returns MVU staked in an event for an oracle
getEventOraclesLength
function getEventOraclesLength (bytes32 eventId) external view returns (uint)
returns number of oracles in a given event
getOracleVotesNum
function getOracleVotesNum (bytes32 eventId) external view returns (uint)
Returns the number of votes in a given event ID
getTotalOracleStake
function getTotalOracleStake (bytes32 eventId) external view returns (uint)
Returns total amount staked by oracles in a given event ID
getThreshold
function getThreshold (bytes32 eventId) external view returns (bool)
getOracleListLength
function getOracleListLength() external view returns (uint)
Returns number of oracles from a given event ID
getOracleListAt
function getOracleListAt (uint index) external view returns (address)
Returns list of oracles from a given event ID
getLastEventOraclized
function getLastEventOraclized (address oracle) external view returns (bytes32)
Returns last event an oracle has orcalized
checkOracleStatus
function checkOracleStatus (address oracle, bytes32 eventId) external view returns (bool)
Returns the status of an oracle in a given event
MIT License