Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 212 lines (181 sloc) 7.27 KB
# This software (Augur) allows buying && selling event outcomes in ethereum
# Copyright (C) 2015 Forecast Foundation OU
# This program is free software; you can redistribute it &&/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 &&/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/>.
# Any questions please contact joey@augur.net
import cash as CASH
inset('refund.se')
# Branches keeps track of data associated with branches in augur
# Branches' index is the hash of the branch (aka branchID)
# currentVotePeriod is the current index in eventsExpDates and tells us which bucket of events are up to be
# voted on in the current vote period (should always be 1 behind block.timestamp/periodlength or current EventsExpDates index)
# currentExpPeriod = (block.timestamp / self.Branches[branch].periodLength)
# currentExpPeriod - 1 is what's up for reporting at any given time
# periodLength is the length in seconds of the branch's reporting period
# parentPeriod is the period the parent was in when the branch was created [useful for claiming rep after a fork]
# baseReporters the number of reporters which report on a market at a minimum
# forkPeriod is the period a branch was last forked over
# eventForkedOver is the event a branch was last forked over
# parent is the parent branch of the given branch
# How to set minimum reporting fee guidelines for reporters, abs. minimum should be calc. as follows:
#Volume per period * .5 * fee * ev/ebit * 6 >= rep market cap
#Say ev/ebit or valuation is 15, so:
#45 * fee * volume per period = rep market cap
#Want:
#Rep market cap >> outstanding shares value at all times
# min can be no lower than ~0.0000001 or so otherwise can run into underflow isues
data Branches[](currentVotePeriod, periodLength, markets[], numMarkets, minTradingFee, balance[], creationDate, oracleOnly, parentPeriod, baseReporters, forkPeriod, eventForkedOver, parent)
# first param is the branch, second param is the subcurrency contract
data cash[][]
# keeps track of a list of all branches
data branchList[]
data branchListCount
def init():
self.Branches[1010101].currentVotePeriod = (block.timestamp / 172800) - 1
self.Branches[1010101].periodLength = 172800 # 1 week
# .5%
self.Branches[1010101].minTradingFee = 5000000000000000
self.branchListCount = 1
self.branchList[0] = 1010101
# since only have to report on half this targets 3
self.Branches[1010101].baseReporters = 2*3
# call once after uploading (externed method not allowed in init)
def initDefaultBranch():
refund()
return(CASH.initiateOwner(1010101))
# event a branch was most recently forked over
def getEventForkedOver(branch):
return(self.Branches[branch].eventForkedOver)
def setEventForkedOver(branch, event):
self.Branches[branch].eventForkedOver = event
return(1)
def getBaseReporters(branch):
refund()
return(self.Branches[branch].baseReporters)
def setBaseReporters(branch, num):
refund()
self.Branches[branch].baseReporters = num
return(1)
def getOracleOnly(branch):
refund()
return(self.Branches[branch].oracleOnly)
def getVotePeriod(branch):
refund()
return(self.Branches[branch].currentVotePeriod)
def getPeriodLength(branch):
refund()
return(self.Branches[branch].periodLength)
# branch cash balance at start of period
def setInitialBalance(branch, period, balance):
refund()
self.Branches[branch].balance[period] = balance
return(balance)
def getInitialBalance(branch, period):
refund()
return(self.Branches[branch].balance[period])
# @return all markets in a branch
def getMarketsInBranch(branch):
refund()
numMarkets = self.Branches[branch].numMarkets
markets = array(numMarkets)
i = 0
while i < numMarkets:
markets[i] = self.Branches[branch].markets[i]
i += 1
return(markets: arr)
def getParent(branch):
return(self.Branches[branch].parent)
# @return all markets in a branch
def getSomeMarketsInBranch(branch, initial, last):
refund()
numMarkets = last - initial
markets = array(numMarkets)
i = 0
while i < numMarkets:
markets[i] = self.Branches[branch].markets[initial+i]
i += 1
return(markets: arr)
def getNumMarketsBranch(branch):
refund()
return(self.Branches[branch].numMarkets)
def getMinTradingFee(branch):
refund()
return(self.Branches[branch].minTradingFee)
# @return all branches
def getBranches():
refund()
b = 0
numBranches = self.branchListCount
branches = array(numBranches)
while b < numBranches:
branches[b] = self.branchList[b]
b += 1
return(branches: arr)
def getNumBranches():
refund()
return(self.branchListCount)
def getBranchByNum(branchNumber):
refund()
return(self.branchList[branchNumber])
def getCreationDate(ID):
refund()
return(self.Branches[ID].creationDate)
# check that msg.sender is one of our function contracts
def initializeBranch(ID, currentVotePeriod, periodLength, minTradingFee, oracleOnly, parentPeriod, parent):
#if(!self.whitelist.check(msg.sender)):
# return(-1)
refund()
if(self.Branches[ID].periodLength==0):
self.Branches[ID].currentVotePeriod = currentVotePeriod
self.Branches[ID].periodLength = periodLength
self.Branches[ID].minTradingFee = minTradingFee
self.branchList[self.branchListCount] = ID
self.branchListCount += 1
self.Branches[ID].creationDate = block.timestamp
self.Branches[ID].parentPeriod = parentPeriod
self.Branches[ID].oracleOnly = oracleOnly
self.Branches[ID].parent = parent
self.Branches[ID].baseReporters = self.Branches[parent].baseReporters
CASH.initiateOwner(ID)
return(1)
else:
return(0)
def getParentPeriod(branch):
refund()
return(self.Branches[branch].parentPeriod)
def incrementPeriod(branch):
#if(!self.whitelist.check(msg.sender)):
# return(-1)
refund()
self.Branches[branch].currentVotePeriod += 1
return(1)
# check that msg.sender is one of our function contracts
def addMarketToBranch(branch, market):
#if(!self.whitelist.check(msg.sender)):
# return(-1)
refund()
numMarkets = self.Branches[branch].numMarkets
self.Branches[branch].markets[numMarkets] = market
self.Branches[branch].numMarkets += 1
return(1)
def setForkPeriod(branch):
self.Branches[branch].forkPeriod = self.Branches[branch].currentVotePeriod
return(1)
# gets the period in which a branch was most recently forked
def getForkPeriod(branch):
return(self.Branches[branch].forkPeriod)