Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 145 lines (133 sloc) 6.08 KB
# This software (Augur) allows buying and selling event options in Ethereum.
#
# Copyright (c) 2015 Forecast Foundation OU
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# If you have questions, please contact jack@augur.net or joey@augur.net.
import reporting as REPORTING
import events as EVENTS
import cash as CASH
import consensusData as CONSENSUS
import branches as BRANCHES
import expiringEvents as EXPEVENTS
import backstops as BACKSTOPS
inset('refund.se')
macro POINTSEVEN: 700000000000000000
macro POINTZEROONE: 10000000000000000
event fundedAccount(branch: indexed, sender: indexed, cashBalance, repBalance, timestamp)
# Error -1: Hey, you're not broke!
def cashFaucet():
refund()
if CASH.balance(msg.sender) > 5*ONE:
return(-1)
CASH.setCash(msg.sender, 10000*ONE)
return(1)
def reputationFaucet(branch):
refund()
if REPORTING.repIDToIndex(branch, tx.origin) != 0 or REPORTING.getReporterID(branch, 0) == tx.origin:
index = REPORTING.repIDToIndex(branch, tx.origin)
else:
index = REPORTING.getNumberReporters(branch)
REPORTING.addReporter(branch, tx.origin, 0, 0, 0)
REPORTING.setRep(branch, index, 47*ONE)
periodLength = BRANCHES.getPeriodLength(branch)
if block.timestamp % periodLength <= periodLength / 2:
penalizedUpTo = BRANCHES.getVotePeriod(branch) - 1
else:
penalizedUpTo = BRANCHES.getVotePeriod(branch)
CONSENSUS.setPenalizedUpTo(branch, tx.origin, penalizedUpTo)
CONSENSUS.setFeesCollected(branch, tx.origin, penalizedUpTo)
return(1)
def fundNewAccount(branch):
CASH.send(self, 0)
self.reputationFaucet(branch)
CASH.setCash(msg.sender, 10000*ONE)
log(type=fundedAccount, branch, msg.sender, 10000*ONE, 47*ONE, block.timestamp)
return(1)
# Used to claim rep on a fork or on a new branch
# Returns 1 if successful, 0 if already claimed
# Error:
# -1: parent isn't the actual parent
def claimInitialRep(parent, branch):
refund()
if(BRANCHES.getParent(branch)!=parent):
return(-1)
# have 1 month to claim
if(REPORTING.repIDToIndex(branch, msg.sender)==0 && block.timestamp < (BRANCHES.getCreationDate(branch) + TWENTYFOURHR*30)):
parentPeriod = BRANCHES.getParentPeriod(branch)
forkPeriod = BRANCHES.getForkPeriod(parent)
fork = REPORTING.getFork(parent)
forkEvent = BRANCHES.getEventForkedOver(parent)
report = EXPEVENTS.getReport(parent, forkPeriod, forkEvent, msg.sender)
outcome = EVENTS.getUncaughtOutcome(forkEvent)
if(binary(forkEvent)):
outcome = catch(outcome)
ethical = ethic_catch(EVENTS.getEthical(forkEvent))
ethicReport = EXPEVENTS.getEthicReport(parent, forkPeriod, forkEvent, msg.sender)
rep = EXPEVENTS.getBeforeRep(parent, parentPeriod, msg.sender)
repDecrease = 0
# if forked and (reported with original consensus or didn't report or (reported with original ethicality and forked over ethicality))
if(fork && ((report >= (outcome-POINTZEROONE) && report <= (outcome+POINTZEROONE)) || report==0 || (BACKSTOPS.getForkedOverEthicality(forkEvent) && ethical==ethicReport))):
# take away 30% of rep from liars and those who didn't report
repDecrease = rep - rep*POINTSEVEN/ONE
rep = rep - repDecrease
amountLeftToPayBonder = BACKSTOPS.getBondAmount(forkEvent) - BACKSTOPS.getForkBondPaid(forkEvent)
if(repDecrease < amountLeftToPayBonder):
# send all the rep to the fork bond poster
REPORTING.addRep(branch, REPORTING.repIDToIndex(branch, BACKSTOPS.getForkBondPoster(forkEvent)), repDecrease)
else:
# send amountLeftToPayBonder [if positive] to the fork bond poster
if(amountLeftToPayBonder > 0):
REPORTING.addRep(branch, REPORTING.repIDToIndex(branch, BACKSTOPS.getForkBondPoster(forkEvent)), amountLeftToPayBonder)
# send the rest to the new branch's redistribution pool
REPORTING.addRep(branch, REPORTING.repIDToIndex(branch, branch), (repDecrease - amountLeftToPayBonder))
else:
# send to new branch's redistribution pool
REPORTING.subtractRep(branch, REPORTING.repIDToIndex(branch, branch), repDecrease)
if(fork):
CONSENSUS.setPenalizedUpTo(branch, msg.sender, forkPeriod)
else:
CONSENSUS.setPenalizedUpTo(branch, msg.sender, (BRANCHES.getVotePeriod(branch)-1))
# todo this doesn't work if hasn't reported last period
dormantRep = EXPEVENTS.getPeriodDormantRep(parent, BRANCHES.getParentPeriod(branch), msg.sender)
REPORTING.addReporter(branch, msg.sender, rep, dormantRep, repDecrease)
return(1)
else:
# already claimed or too late
return(0)
macro YES: TWO
macro NO: ONE
macro BAD: 3 * ONEHALF
macro CATCH_TOLERANCE: ONE / 10
macro binary($event):
(EVENTS.getNumOutcomes($event)==2 and EVENTS.getMaxValue($event)==TWO and EVENTS.getMinValue($event)==ONE)
# Bins values to 1, 1.5, 2
macro catch($x):
if($x < (BAD - CATCH_TOLERANCE)):
NO
elif($x > (BAD + CATCH_TOLERANCE)):
YES
else:
BAD
macro ethic_catch($x):
if($x < ONEHALF):
0
else:
ONE