Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
102 lines (97 sloc) 4.66 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 branches as BRANCHES
import expiringEvents as EXPEVENTS
import cash as CASH
import markets as MARKETS
inset('refund.se')
event completeSets_logReturn(sender: indexed, market: indexed, type: indexed, returnValue, numOutcomes, timestamp)
# Buys amount of every outcome
# cost 850k gas
# Errors:
# 0: invalid market/doesn't exist
# -1: oracle only branch [no trading allowed]
# -2: not enough money
def buyCompleteSets(market, amount):
refund()
branch = MARKETS.getBranchID(market)
numOutcomes = MARKETS.getMarketNumOutcomes(market)
cumScale = MARKETS.getCumScale(market)
cost = amount*cumScale/ONE
if(!MARKETS.getCreationTime(market)):
log(type=completeSets_logReturn, msg.sender, market, 0)
return(0)
if(BRANCHES.getOracleOnly(branch)):
log(type=completeSets_logReturn, msg.sender, market, -1)
return(-1)
if(CASH.balance(msg.sender) < cost):
log(type=completeSets_logReturn, msg.sender, market, -2)
return(-2)
n = 1
# send shares of the event to user address and increment the number issued in the market for each outcome
while n <= numOutcomes:
MARKETS.modifyShares(market, n, amount)
MARKETS.modifyParticipantShares(market, msg.sender, n, amount, 0)
n += 1
# if still before voting period has started count it in the share value for the period and market to target # of reporters to be higher in markets w/ more outstanding value
if(BRANCHES.getVotePeriod(branch) < MARKETS.getTradingPeriod(market)):
MARKETS.modifySharesValue(market, amount*cumScale/ONE)
EXPEVENTS.adjustPeriodShareValueOutstanding(branch, MARKETS.getTradingPeriod(market), amount*cumScale/ONE)
# send money from user acc. to market address/account
CASH.sendFrom(market, cost, msg.sender)
log(type=completeSets_logReturn, msg.sender, market, 1, amount, numOutcomes, block.timestamp)
return(amount)
# Sells amount of every outcome [if user owns it]
# cost 850k gas
# Errors:
# -1: oracle only / no trading branch
# -2: trader doesn't exist
# -3: user doesn't own enough shares
def sellCompleteSets(market, amount):
refund()
branch = MARKETS.getBranchID(market)
numOutcomes = MARKETS.getMarketNumOutcomes(market)
cumScale = MARKETS.getCumScale(market)
cost = amount*cumScale/ONE
if(BRANCHES.getOracleOnly(branch)):
log(type=completeSets_logReturn, msg.sender, market, -1)
return(-1)
n = 1
while n <= numOutcomes:
if(MARKETS.getParticipantSharesPurchased(market, msg.sender, n) < amount):
log(type=completeSets_logReturn, msg.sender, market, -3)
return(-3)
n += 1
n = 1
# Takes shares away from participant and decreases the amount issued in the market since we're exchanging complete sets
while n <= numOutcomes:
MARKETS.modifyShares(market, n, -amount)
MARKETS.modifyParticipantShares(market, msg.sender, n, -amount, 0)
n += 1
# if still before voting period has started count it in the share value for the period and market to target # of reporters to be higher in markets w/ more outstanding value
if(BRANCHES.getVotePeriod(branch)<MARKETS.getTradingPeriod(market)):
MARKETS.modifySharesValue(market, -amount*cumScale/ONE)
EXPEVENTS.adjustPeriodShareValueOutstanding(branch, MARKETS.getTradingPeriod(market), -amount*cumScale/ONE)
# send funds from the market to the user acc.
CASH.subtractCash(market, cost)
CASH.addCash(msg.sender, cost)
log(type=completeSets_logReturn, msg.sender, market, 2, amount, numOutcomes, block.timestamp)
return(amount)