Skip to content

Instantly share code, notes, and snippets.

@nuevoalex
Created March 4, 2019 23:08
Show Gist options
  • Save nuevoalex/3ad9e51f6ff53da4d76f4b364f961bb0 to your computer and use it in GitHub Desktop.
Save nuevoalex/3ad9e51f6ff53da4d76f4b364f961bb0 to your computer and use it in GitHub Desktop.
Augur flattened
pragma solidity 0.4.24;
library Order {
using SafeMathUint256 for uint256;
enum Types {
Bid, Ask
}
enum TradeDirections {
Long, Short
}
struct Data {
// Contracts
IOrders orders;
IMarket market;
IAugur augur;
// Order
bytes32 id;
address creator;
uint256 outcome;
Order.Types orderType;
uint256 amount;
uint256 price;
uint256 sharesEscrowed;
uint256 moneyEscrowed;
bytes32 betterOrderId;
bytes32 worseOrderId;
bool ignoreShares;
}
// No validation is needed here as it is simply a librarty function for organizing data
function create(IAugur _augur, address _creator, uint256 _outcome, Order.Types _type, uint256 _attoshares, uint256 _price, IMarket _market, bytes32 _betterOrderId, bytes32 _worseOrderId, bool _ignoreShares) internal view returns (Data) {
require(_outcome < _market.getNumberOfOutcomes());
require(_price < _market.getNumTicks());
require(_attoshares > 0);
require(_creator != address(0));
IOrders _orders = IOrders(_augur.lookup("Orders"));
return Data({
orders: _orders,
market: _market,
augur: _augur,
id: 0,
creator: _creator,
outcome: _outcome,
orderType: _type,
amount: _attoshares,
price: _price,
sharesEscrowed: 0,
moneyEscrowed: 0,
betterOrderId: _betterOrderId,
worseOrderId: _worseOrderId,
ignoreShares: _ignoreShares
});
}
//
// "public" functions
//
function getOrderId(Order.Data _orderData) internal view returns (bytes32) {
if (_orderData.id == bytes32(0)) {
bytes32 _orderId = _orderData.orders.getOrderId(_orderData.orderType, _orderData.market, _orderData.amount, _orderData.price, _orderData.creator, block.number, _orderData.outcome, _orderData.moneyEscrowed, _orderData.sharesEscrowed);
require(_orderData.orders.getAmount(_orderId) == 0);
_orderData.id = _orderId;
}
return _orderData.id;
}
function getOrderTradingTypeFromMakerDirection(Order.TradeDirections _creatorDirection) internal pure returns (Order.Types) {
return (_creatorDirection == Order.TradeDirections.Long) ? Order.Types.Bid : Order.Types.Ask;
}
function getOrderTradingTypeFromFillerDirection(Order.TradeDirections _fillerDirection) internal pure returns (Order.Types) {
return (_fillerDirection == Order.TradeDirections.Long) ? Order.Types.Ask : Order.Types.Bid;
}
function escrowFunds(Order.Data _orderData) internal returns (bool) {
if (_orderData.orderType == Order.Types.Ask) {
return escrowFundsForAsk(_orderData);
} else if (_orderData.orderType == Order.Types.Bid) {
return escrowFundsForBid(_orderData);
}
}
function saveOrder(Order.Data _orderData, bytes32 _tradeGroupId) internal returns (bytes32) {
return _orderData.orders.saveOrder(_orderData.orderType, _orderData.market, _orderData.amount, _orderData.price, _orderData.creator, _orderData.outcome, _orderData.moneyEscrowed, _orderData.sharesEscrowed, _orderData.betterOrderId, _orderData.worseOrderId, _tradeGroupId);
}
//
// Private functions
//
function escrowFundsForBid(Order.Data _orderData) private returns (bool) {
require(_orderData.moneyEscrowed == 0);
require(_orderData.sharesEscrowed == 0);
uint256 _attosharesToCover = _orderData.amount;
uint256 _numberOfOutcomes = _orderData.market.getNumberOfOutcomes();
// Figure out how many almost-complete-sets (just missing `outcome` share) the creator has
if (!_orderData.ignoreShares) {
uint256 _attosharesHeld = 2**254;
for (uint256 _i = 0; _i < _numberOfOutcomes; _i++) {
if (_i != _orderData.outcome) {
uint256 _creatorShareTokenBalance = _orderData.market.getShareToken(_i).balanceOf(_orderData.creator);
_attosharesHeld = SafeMathUint256.min(_creatorShareTokenBalance, _attosharesHeld);
}
}
// Take shares into escrow if they have any almost-complete-sets
if (_attosharesHeld > 0) {
_orderData.sharesEscrowed = SafeMathUint256.min(_attosharesHeld, _attosharesToCover);
_attosharesToCover -= _orderData.sharesEscrowed;
for (_i = 0; _i < _numberOfOutcomes; _i++) {
if (_i != _orderData.outcome) {
_orderData.market.getShareToken(_i).trustedOrderTransfer(_orderData.creator, _orderData.market, _orderData.sharesEscrowed);
}
}
}
}
// If not able to cover entire order with shares alone, then cover remaining with tokens
if (_attosharesToCover > 0) {
_orderData.moneyEscrowed = _attosharesToCover.mul(_orderData.price);
require(_orderData.augur.trustedTransfer(_orderData.market.getDenominationToken(), _orderData.creator, _orderData.market, _orderData.moneyEscrowed));
}
return true;
}
function escrowFundsForAsk(Order.Data _orderData) private returns (bool) {
require(_orderData.moneyEscrowed == 0);
require(_orderData.sharesEscrowed == 0);
IShareToken _shareToken = _orderData.market.getShareToken(_orderData.outcome);
uint256 _attosharesToCover = _orderData.amount;
// Figure out how many shares of the outcome the creator has
if (!_orderData.ignoreShares) {
uint256 _attosharesHeld = _shareToken.balanceOf(_orderData.creator);
// Take shares in escrow if user has shares
if (_attosharesHeld > 0) {
_orderData.sharesEscrowed = SafeMathUint256.min(_attosharesHeld, _attosharesToCover);
_attosharesToCover -= _orderData.sharesEscrowed;
_shareToken.trustedOrderTransfer(_orderData.creator, _orderData.market, _orderData.sharesEscrowed);
}
}
// If not able to cover entire order with shares alone, then cover remaining with tokens
if (_attosharesToCover > 0) {
_orderData.moneyEscrowed = _orderData.market.getNumTicks().sub(_orderData.price).mul(_attosharesToCover);
require(_orderData.augur.trustedTransfer(_orderData.market.getDenominationToken(), _orderData.creator, _orderData.market, _orderData.moneyEscrowed));
}
return true;
}
}
contract ITyped {
function getTypeName() public view returns (bytes32);
}
contract IDisputeWindow is ITyped {
function initialize(IAugur _augur, IUniverse _universe, uint256 _disputeWindowId) public returns (bool);
function getUniverse() public view returns (IUniverse);
function getReputationToken() public view returns (IReputationToken);
function getStartTime() public view returns (uint256);
function getEndTime() public view returns (uint256);
function getNumMarkets() public view returns (uint256);
function getNumInvalidMarkets() public view returns (uint256);
function getNumIncorrectDesignatedReportMarkets() public view returns (uint256);
function getNumDesignatedReportNoShows() public view returns (uint256);
function isActive() public view returns (bool);
function isOver() public view returns (bool);
function onMarketFinalized() public returns (bool);
}
contract IOrders {
function saveOrder(Order.Types _type, IMarket _market, uint256 _amount, uint256 _price, address _sender, uint256 _outcome, uint256 _moneyEscrowed, uint256 _sharesEscrowed, bytes32 _betterOrderId, bytes32 _worseOrderId, bytes32 _tradeGroupId) external returns (bytes32 _orderId);
function removeOrder(bytes32 _orderId) external returns (bool);
function getMarket(bytes32 _orderId) public view returns (IMarket);
function getOrderType(bytes32 _orderId) public view returns (Order.Types);
function getOutcome(bytes32 _orderId) public view returns (uint256);
function getAmount(bytes32 _orderId) public view returns (uint256);
function getPrice(bytes32 _orderId) public view returns (uint256);
function getOrderCreator(bytes32 _orderId) public view returns (address);
function getOrderSharesEscrowed(bytes32 _orderId) public view returns (uint256);
function getOrderMoneyEscrowed(bytes32 _orderId) public view returns (uint256);
function getBetterOrderId(bytes32 _orderId) public view returns (bytes32);
function getWorseOrderId(bytes32 _orderId) public view returns (bytes32);
function getBestOrderId(Order.Types _type, IMarket _market, uint256 _outcome) public view returns (bytes32);
function getWorstOrderId(Order.Types _type, IMarket _market, uint256 _outcome) public view returns (bytes32);
function getLastOutcomePrice(IMarket _market, uint256 _outcome) public view returns (uint256);
function getOrderId(Order.Types _type, IMarket _market, uint256 _amount, uint256 _price, address _sender, uint256 _blockNumber, uint256 _outcome, uint256 _moneyEscrowed, uint256 _sharesEscrowed) public pure returns (bytes32);
function getTotalEscrowed(IMarket _market) public view returns (uint256);
function isBetterPrice(Order.Types _type, uint256 _price, bytes32 _orderId) public view returns (bool);
function isWorsePrice(Order.Types _type, uint256 _price, bytes32 _orderId) public view returns (bool);
function assertIsNotBetterPrice(Order.Types _type, uint256 _price, bytes32 _betterOrderId) public view returns (bool);
function assertIsNotWorsePrice(Order.Types _type, uint256 _price, bytes32 _worseOrderId) public returns (bool);
function recordFillOrder(bytes32 _orderId, uint256 _sharesFilled, uint256 _tokensFilled) external returns (bool);
function setPrice(IMarket _market, uint256 _outcome, uint256 _price) external returns (bool);
}
contract IUniverse is ITyped {
function fork() public returns (bool);
function getParentUniverse() public view returns (IUniverse);
function createChildUniverse(uint256[] _parentPayoutNumerators) public returns (IUniverse);
function getChildUniverse(bytes32 _parentPayoutDistributionHash) public view returns (IUniverse);
function getReputationToken() public view returns (IV2ReputationToken);
function getAuction() public view returns (IAuction);
function getForkingMarket() public view returns (IMarket);
function getForkEndTime() public view returns (uint256);
function getForkReputationGoal() public view returns (uint256);
function getParentPayoutDistributionHash() public view returns (bytes32);
function getDisputeRoundDurationInSeconds() public view returns (uint256);
function getOrCreateDisputeWindowByTimestamp(uint256 _timestamp) public returns (IDisputeWindow);
function getOrCreateCurrentDisputeWindow() public returns (IDisputeWindow);
function getOrCreateNextDisputeWindow() public returns (IDisputeWindow);
function getOpenInterestInAttoEth() public view returns (uint256);
function getRepMarketCapInAttoEth() public view returns (uint256);
function getTargetRepMarketCapInAttoEth() public view returns (uint256);
function getOrCacheValidityBond() public returns (uint256);
function getOrCacheDesignatedReportStake() public returns (uint256);
function getOrCacheDesignatedReportNoShowBond() public returns (uint256);
function getOrCacheReportingFeeDivisor() public returns (uint256);
function getDisputeThresholdForFork() public view returns (uint256);
function getDisputeThresholdForDisputePacing() public view returns (uint256);
function getInitialReportMinValue() public view returns (uint256);
function calculateFloatingValue(uint256 _badMarkets, uint256 _totalMarkets, uint256 _targetDivisor, uint256 _previousValue, uint256 _defaultValue, uint256 _floor) public pure returns (uint256 _newValue);
function getOrCacheMarketCreationCost() public returns (uint256);
function getCurrentDisputeWindow() public view returns (IDisputeWindow);
function getOrCreateDisputeWindowBefore(IDisputeWindow _disputeWindow) public returns (IDisputeWindow);
function isParentOf(IUniverse _shadyChild) public view returns (bool);
function updateTentativeWinningChildUniverse(bytes32 _parentPayoutDistributionHash) public returns (bool);
function isContainerForDisputeWindow(IDisputeWindow _shadyTarget) public view returns (bool);
function isContainerForMarket(IMarket _shadyTarget) public view returns (bool);
function isContainerForReportingParticipant(IReportingParticipant _reportingParticipant) public view returns (bool);
function isContainerForShareToken(IShareToken _shadyTarget) public view returns (bool);
function addMarketTo() public returns (bool);
function removeMarketFrom() public returns (bool);
function decrementOpenInterest(uint256 _amount) public returns (bool);
function decrementOpenInterestFromMarket(uint256 _amount) public returns (bool);
function incrementOpenInterest(uint256 _amount) public returns (bool);
function incrementOpenInterestFromMarket(uint256 _amount) public returns (bool);
function getWinningChildUniverse() public view returns (IUniverse);
function isForking() public view returns (bool);
}
contract IAugur {
function createChildUniverse(bytes32 _parentPayoutDistributionHash, uint256[] _parentPayoutNumerators) public returns (IUniverse);
function isKnownUniverse(IUniverse _universe) public view returns (bool);
function trustedTransfer(ERC20Token _token, address _from, address _to, uint256 _amount) public returns (bool);
function logMarketCreated(bytes32 _topic, string _description, string _extraInfo, IUniverse _universe, IMarket _market, address _marketCreator, bytes32[] _outcomes, int256 _minPrice, int256 _maxPrice, IMarket.MarketType _marketType) public returns (bool);
function logMarketCreated(bytes32 _topic, string _description, string _extraInfo, IUniverse _universe, IMarket _market, address _marketCreator, int256 _minPrice, int256 _maxPrice, IMarket.MarketType _marketType) public returns (bool);
function logInitialReportSubmitted(IUniverse _universe, address _reporter, address _market, uint256 _amountStaked, bool _isDesignatedReporter, uint256[] _payoutNumerators, string description) public returns (bool);
function disputeCrowdsourcerCreated(IUniverse _universe, address _market, address _disputeCrowdsourcer, uint256[] _payoutNumerators, uint256 _size) public returns (bool);
function logDisputeCrowdsourcerContribution(IUniverse _universe, address _reporter, address _market, address _disputeCrowdsourcer, uint256 _amountStaked, string description) public returns (bool);
function logDisputeCrowdsourcerCompleted(IUniverse _universe, address _market, address _disputeCrowdsourcer) public returns (bool);
function logInitialReporterRedeemed(IUniverse _universe, address _reporter, address _market, uint256 _amountRedeemed, uint256 _repReceived, uint256[] _payoutNumerators) public returns (bool);
function logDisputeCrowdsourcerRedeemed(IUniverse _universe, address _reporter, address _market, uint256 _amountRedeemed, uint256 _repReceived, uint256[] _payoutNumerators) public returns (bool);
function logMarketFinalized(IUniverse _universe) public returns (bool);
function logMarketMigrated(IMarket _market, IUniverse _originalUniverse) public returns (bool);
function logReportingParticipantDisavowed(IUniverse _universe, IMarket _market) public returns (bool);
function logMarketParticipantsDisavowed(IUniverse _universe) public returns (bool);
function logOrderCanceled(IUniverse _universe, address _shareToken, address _sender, bytes32 _orderId, Order.Types _orderType, uint256 _tokenRefund, uint256 _sharesRefund) public returns (bool);
function logOrderCreated(Order.Types _orderType, uint256 _amount, uint256 _price, address _creator, uint256 _moneyEscrowed, uint256 _sharesEscrowed, bytes32 _tradeGroupId, bytes32 _orderId, IUniverse _universe, address _shareToken) public returns (bool);
function logOrderFilled(IUniverse _universe, address _shareToken, address _filler, bytes32 _orderId, uint256 _numCreatorShares, uint256 _numCreatorTokens, uint256 _numFillerShares, uint256 _numFillerTokens, uint256 _marketCreatorFees, uint256 _reporterFees, uint256 _amountFilled, bytes32 _tradeGroupId) public returns (bool);
function logCompleteSetsPurchased(IUniverse _universe, IMarket _market, address _account, uint256 _numCompleteSets) public returns (bool);
function logCompleteSetsSold(IUniverse _universe, IMarket _market, address _account, uint256 _numCompleteSets) public returns (bool);
function logTradingProceedsClaimed(IUniverse _universe, address _shareToken, address _sender, address _market, uint256 _numShares, uint256 _numPayoutTokens, uint256 _finalTokenBalance) public returns (bool);
function logUniverseForked() public returns (bool);
function logDisputeCrowdsourcerTokensTransferred(IUniverse _universe, address _from, address _to, uint256 _value) public returns (bool);
function logShareTokensTransferred(IUniverse _universe, address _from, address _to, uint256 _value) public returns (bool);
function logReputationTokensTransferred(IUniverse _universe, address _from, address _to, uint256 _value) public returns (bool);
function logReputationTokenBurned(IUniverse _universe, address _target, uint256 _amount) public returns (bool);
function logReputationTokenMinted(IUniverse _universe, address _target, uint256 _amount) public returns (bool);
function logShareTokenBurned(IUniverse _universe, address _target, uint256 _amount) public returns (bool);
function logShareTokenMinted(IUniverse _universe, address _target, uint256 _amount) public returns (bool);
function logDisputeCrowdsourcerTokensBurned(IUniverse _universe, address _target, uint256 _amount) public returns (bool);
function logDisputeCrowdsourcerTokensMinted(IUniverse _universe, address _target, uint256 _amount) public returns (bool);
function logDisputeWindowCreated(IDisputeWindow _disputeWindow, uint256 _id) public returns (bool);
function logTimestampSet(uint256 _newTimestamp) public returns (bool);
function logInitialReporterTransferred(IUniverse _universe, IMarket _market, address _from, address _to) public returns (bool);
function logMarketTransferred(IUniverse _universe, address _from, address _to) public returns (bool);
function logAuctionTokensTransferred(IUniverse _universe, address _from, address _to, uint256 _value) public returns (bool);
function logAuctionTokenBurned(IUniverse _universe, address _target, uint256 _amount) public returns (bool);
function logAuctionTokenMinted(IUniverse _universe, address _target, uint256 _amount) public returns (bool);
function recordAuctionTokens(IUniverse _universe) public returns (bool);
function isKnownFeeSender(address _feeSender) public view returns (bool);
function lookup(bytes32 _key) public view returns (address);
function getTimestamp() public view returns (uint256);
function isValidMarket(IMarket _market) public view returns (bool);
}
contract Augur is IAugur {
enum TokenType{
ReputationToken,
ShareToken,
DisputeCrowdsourcer,
FeeWindow, // No longer a valid type but here for backward compat with Augur Node processing
FeeToken, // No longer a valid type but here for backward compat with Augur Node processing
AuctionToken
}
event MarketCreated(bytes32 indexed topic, string description, string extraInfo, address indexed universe, address market, address indexed marketCreator, bytes32[] outcomes, uint256 marketCreationFee, int256 minPrice, int256 maxPrice, IMarket.MarketType marketType);
event InitialReportSubmitted(address indexed universe, address indexed reporter, address indexed market, uint256 amountStaked, bool isDesignatedReporter, uint256[] payoutNumerators, string description);
event DisputeCrowdsourcerCreated(address indexed universe, address indexed market, address disputeCrowdsourcer, uint256[] payoutNumerators, uint256 size);
event DisputeCrowdsourcerContribution(address indexed universe, address indexed reporter, address indexed market, address disputeCrowdsourcer, uint256 amountStaked, string description);
event DisputeCrowdsourcerCompleted(address indexed universe, address indexed market, address disputeCrowdsourcer);
event InitialReporterRedeemed(address indexed universe, address indexed reporter, address indexed market, uint256 amountRedeemed, uint256 repReceived, uint256[] payoutNumerators);
event DisputeCrowdsourcerRedeemed(address indexed universe, address indexed reporter, address indexed market, address disputeCrowdsourcer, uint256 amountRedeemed, uint256 repReceived, uint256[] payoutNumerators);
event ReportingParticipantDisavowed(address indexed universe, address indexed market, address reportingParticipant);
event MarketParticipantsDisavowed(address indexed universe, address indexed market);
event MarketFinalized(address indexed universe, address indexed market);
event MarketMigrated(address indexed market, address indexed originalUniverse, address indexed newUniverse);
event UniverseForked(address indexed universe);
event UniverseCreated(address indexed parentUniverse, address indexed childUniverse, uint256[] payoutNumerators);
event OrderCanceled(address indexed universe, address indexed shareToken, address indexed sender, bytes32 orderId, Order.Types orderType, uint256 tokenRefund, uint256 sharesRefund);
// The ordering here is to match functions higher in the call chain to avoid stack depth issues
event OrderCreated(Order.Types orderType, uint256 amount, uint256 price, address indexed creator, uint256 moneyEscrowed, uint256 sharesEscrowed, bytes32 tradeGroupId, bytes32 orderId, address indexed universe, address indexed shareToken);
event OrderFilled(address indexed universe, address indexed shareToken, address filler, bytes32 orderId, uint256 numCreatorShares, uint256 numCreatorTokens, uint256 numFillerShares, uint256 numFillerTokens, uint256 marketCreatorFees, uint256 reporterFees, uint256 amountFilled, bytes32 tradeGroupId);
event CompleteSetsPurchased(address indexed universe, address indexed market, address indexed account, uint256 numCompleteSets);
event CompleteSetsSold(address indexed universe, address indexed market, address indexed account, uint256 numCompleteSets);
event TradingProceedsClaimed(address indexed universe, address indexed shareToken, address indexed sender, address market, uint256 numShares, uint256 numPayoutTokens, uint256 finalTokenBalance);
event TokensTransferred(address indexed universe, address indexed token, address indexed from, address to, uint256 value, TokenType tokenType, address market);
event TokensMinted(address indexed universe, address indexed token, address indexed target, uint256 amount, TokenType tokenType, address market);
event TokensBurned(address indexed universe, address indexed token, address indexed target, uint256 amount, TokenType tokenType, address market);
event DisputeWindowCreated(address indexed universe, address disputeWindow, uint256 startTime, uint256 endTime, uint256 id);
event InitialReporterTransferred(address indexed universe, address indexed market, address from, address to);
event MarketTransferred(address indexed universe, address indexed market, address from, address to);
event EscapeHatchChanged(bool isOn);
event TimestampSet(uint256 newTimestamp);
mapping(address => bool) private markets;
mapping(address => bool) private universes;
mapping(address => bool) private crowdsourcers;
mapping(address => bool) private shareTokens;
mapping(address => bool) private auctionTokens;
mapping(address => bool) private trustedSender;
address public uploader;
mapping(bytes32 => address) public registry;
ITime public time;
constructor() public {
uploader = msg.sender;
}
//
// Registry
//
function registerContract(bytes32 _key, address _address) public returns (bool) {
require(msg.sender == uploader);
require(registry[_key] == address(0));
registry[_key] = _address;
if (_key == "CompleteSets" || _key == "Orders" || _key == "CreateOrder" || _key == "CancelOrder" || _key == "FillOrder" || _key == "Trade" || _key == "ClaimTradingProceeds" || _key == "MarketFactory") {
trustedSender[_address] = true;
}
if (_key == "Time") {
time = ITime(_address);
}
return true;
}
function lookup(bytes32 _key) public view returns (address) {
return registry[_key];
}
function finishDeployment() public returns (bool) {
require(msg.sender == uploader);
uploader = address(1);
return true;
}
//
// Universe
//
function createGenesisUniverse() public returns (IUniverse) {
require(msg.sender == uploader);
return createUniverse(IUniverse(0), bytes32(0), new uint256[](0));
}
function createChildUniverse(bytes32 _parentPayoutDistributionHash, uint256[] _parentPayoutNumerators) public returns (IUniverse) {
IUniverse _parentUniverse = IUniverse(msg.sender);
require(isKnownUniverse(_parentUniverse));
return createUniverse(_parentUniverse, _parentPayoutDistributionHash, _parentPayoutNumerators);
}
function createUniverse(IUniverse _parentUniverse, bytes32 _parentPayoutDistributionHash, uint256[] _parentPayoutNumerators) private returns (IUniverse) {
IUniverseFactory _universeFactory = IUniverseFactory(registry["UniverseFactory"]);
IUniverse _newUniverse = _universeFactory.createUniverse(this, _parentUniverse, _parentPayoutDistributionHash);
universes[_newUniverse] = true;
trustedSender[_newUniverse.getAuction()] = true;
emit UniverseCreated(_parentUniverse, _newUniverse, _parentPayoutNumerators);
return _newUniverse;
}
function isKnownUniverse(IUniverse _universe) public view returns (bool) {
return universes[_universe];
}
//
// Crowdsourcers
//
function isKnownCrowdsourcer(IDisputeCrowdsourcer _crowdsourcer) public view returns (bool) {
return crowdsourcers[_crowdsourcer];
}
function disputeCrowdsourcerCreated(IUniverse _universe, address _market, address _disputeCrowdsourcer, uint256[] _payoutNumerators, uint256 _size) public returns (bool) {
require(isKnownUniverse(_universe));
require(_universe.isContainerForMarket(IMarket(msg.sender)));
crowdsourcers[_disputeCrowdsourcer] = true;
emit DisputeCrowdsourcerCreated(_universe, _market, _disputeCrowdsourcer, _payoutNumerators, _size);
return true;
}
//
// Share Tokens
//
function recordMarketShareTokens(IMarket _market) private returns (bool) {
uint256 _numOutcomes = _market.getNumberOfOutcomes();
for (uint256 _outcome = 0; _outcome < _numOutcomes; _outcome++) {
shareTokens[_market.getShareToken(_outcome)] = true;
}
}
function isKnownShareToken(IShareToken _token) public view returns (bool) {
return shareTokens[_token];
}
function isKnownFeeSender(address _feeSender) public view returns (bool) {
return _feeSender == registry["CompleteSets"] || _feeSender == registry["ClaimTradingProceeds"] || markets[_feeSender];
}
//
// Auction Tokens
//
function recordAuctionTokens(IUniverse _universe) public returns (bool) {
require(isKnownUniverse(_universe));
IAuction _auction = _universe.getAuction();
IAuctionToken _ethAuctionToken = _auction.ethAuctionToken();
IAuctionToken _repAuctionToken = _auction.repAuctionToken();
if (_ethAuctionToken != IAuctionToken(0)) {
auctionTokens[_ethAuctionToken] = true;
}
if (_repAuctionToken != IAuctionToken(0)) {
auctionTokens[_repAuctionToken] = true;
}
}
function isKnownAuctionToken(IAuctionToken _token) public view returns (bool) {
return auctionTokens[_token];
}
//
// Transfer
//
function trustedTransfer(ERC20Token _token, address _from, address _to, uint256 _amount) public returns (bool) {
require(trustedSender[msg.sender]);
require(_token.transferFrom(_from, _to, _amount));
return true;
}
//
// Time
//
function getTimestamp() public view returns (uint256) {
return time.getTimestamp();
}
//
// Markets
//
function isValidMarket(IMarket _market) public view returns (bool) {
return markets[_market];
}
//
// Logging
//
// This signature is intended for the categorical market creation. We use two signatures for the same event because of stack depth issues which can be circumvented by maintaining order of paramaters
function logMarketCreated(bytes32 _topic, string _description, string _extraInfo, IUniverse _universe, IMarket _market, address _marketCreator, bytes32[] _outcomes, int256 _minPrice, int256 _maxPrice, IMarket.MarketType _marketType) public returns (bool) {
require(isKnownUniverse(_universe));
require(_universe == IUniverse(msg.sender));
recordMarketShareTokens(_market);
markets[_market] = true;
emit MarketCreated(_topic, _description, _extraInfo, _universe, _market, _marketCreator, _outcomes, _universe.getOrCacheMarketCreationCost(), _minPrice, _maxPrice, _marketType);
return true;
}
// This signature is intended for yesNo and scalar market creation. See function comment above for explanation.
function logMarketCreated(bytes32 _topic, string _description, string _extraInfo, IUniverse _universe, IMarket _market, address _marketCreator, int256 _minPrice, int256 _maxPrice, IMarket.MarketType _marketType) public returns (bool) {
require(isKnownUniverse(_universe));
require(_universe == IUniverse(msg.sender));
recordMarketShareTokens(_market);
markets[_market] = true;
emit MarketCreated(_topic, _description, _extraInfo, _universe, _market, _marketCreator, new bytes32[](0), _universe.getOrCacheMarketCreationCost(), _minPrice, _maxPrice, _marketType);
return true;
}
function logInitialReportSubmitted(IUniverse _universe, address _reporter, address _market, uint256 _amountStaked, bool _isDesignatedReporter, uint256[] _payoutNumerators, string _description) public returns (bool) {
require(isKnownUniverse(_universe));
require(_universe.isContainerForMarket(IMarket(msg.sender)));
emit InitialReportSubmitted(_universe, _reporter, _market, _amountStaked, _isDesignatedReporter, _payoutNumerators, _description);
return true;
}
function logDisputeCrowdsourcerContribution(IUniverse _universe, address _reporter, address _market, address _disputeCrowdsourcer, uint256 _amountStaked, string _description) public returns (bool) {
require(isKnownUniverse(_universe));
require(_universe.isContainerForMarket(IMarket(msg.sender)));
emit DisputeCrowdsourcerContribution(_universe, _reporter, _market, _disputeCrowdsourcer, _amountStaked, _description);
return true;
}
function logDisputeCrowdsourcerCompleted(IUniverse _universe, address _market, address _disputeCrowdsourcer) public returns (bool) {
require(isKnownUniverse(_universe));
require(_universe.isContainerForMarket(IMarket(msg.sender)));
emit DisputeCrowdsourcerCompleted(_universe, _market, _disputeCrowdsourcer);
return true;
}
function logInitialReporterRedeemed(IUniverse _universe, address _reporter, address _market, uint256 _amountRedeemed, uint256 _repReceived, uint256[] _payoutNumerators) public returns (bool) {
require(isKnownUniverse(_universe));
require(_universe.isContainerForReportingParticipant(IReportingParticipant(msg.sender)));
emit InitialReporterRedeemed(_universe, _reporter, _market, _amountRedeemed, _repReceived, _payoutNumerators);
return true;
}
function logDisputeCrowdsourcerRedeemed(IUniverse _universe, address _reporter, address _market, uint256 _amountRedeemed, uint256 _repReceived, uint256[] _payoutNumerators) public returns (bool) {
IDisputeCrowdsourcer _disputeCrowdsourcer = IDisputeCrowdsourcer(msg.sender);
require(isKnownCrowdsourcer(_disputeCrowdsourcer));
emit DisputeCrowdsourcerRedeemed(_universe, _reporter, _market, _disputeCrowdsourcer, _amountRedeemed, _repReceived, _payoutNumerators);
return true;
}
function logReportingParticipantDisavowed(IUniverse _universe, IMarket _market) public returns (bool) {
require(isKnownUniverse(_universe));
require(_universe.isContainerForReportingParticipant(IReportingParticipant(msg.sender)));
emit ReportingParticipantDisavowed(_universe, _market, msg.sender);
return true;
}
function logMarketParticipantsDisavowed(IUniverse _universe) public returns (bool) {
require(isKnownUniverse(_universe));
IMarket _market = IMarket(msg.sender);
require(_universe.isContainerForMarket(_market));
emit MarketParticipantsDisavowed(_universe, _market);
return true;
}
function logMarketFinalized(IUniverse _universe) public returns (bool) {
require(isKnownUniverse(_universe));
IMarket _market = IMarket(msg.sender);
require(_universe.isContainerForMarket(_market));
emit MarketFinalized(_universe, _market);
return true;
}
function logMarketMigrated(IMarket _market, IUniverse _originalUniverse) public returns (bool) {
IUniverse _newUniverse = IUniverse(msg.sender);
require(isKnownUniverse(_newUniverse));
emit MarketMigrated(_market, _originalUniverse, _newUniverse);
return true;
}
function logOrderCanceled(IUniverse _universe, address _shareToken, address _sender, bytes32 _orderId, Order.Types _orderType, uint256 _tokenRefund, uint256 _sharesRefund) public returns (bool) {
require(msg.sender == registry["CancelOrder"]);
emit OrderCanceled(_universe, _shareToken, _sender, _orderId, _orderType, _tokenRefund, _sharesRefund);
return true;
}
function logOrderCreated(Order.Types _orderType, uint256 _amount, uint256 _price, address _creator, uint256 _moneyEscrowed, uint256 _sharesEscrowed, bytes32 _tradeGroupId, bytes32 _orderId, IUniverse _universe, address _shareToken) public returns (bool) {
require(msg.sender == registry["Orders"]);
emit OrderCreated(_orderType, _amount, _price, _creator, _moneyEscrowed, _sharesEscrowed, _tradeGroupId, _orderId, _universe, _shareToken);
return true;
}
function logOrderFilled(IUniverse _universe, address _shareToken, address _filler, bytes32 _orderId, uint256 _numCreatorShares, uint256 _numCreatorTokens, uint256 _numFillerShares, uint256 _numFillerTokens, uint256 _marketCreatorFees, uint256 _reporterFees, uint256 _amountFilled, bytes32 _tradeGroupId) public returns (bool) {
require(msg.sender == registry["FillOrder"]);
emit OrderFilled(_universe, _shareToken, _filler, _orderId, _numCreatorShares, _numCreatorTokens, _numFillerShares, _numFillerTokens, _marketCreatorFees, _reporterFees, _amountFilled, _tradeGroupId);
return true;
}
function logCompleteSetsPurchased(IUniverse _universe, IMarket _market, address _account, uint256 _numCompleteSets) public returns (bool) {
require(msg.sender == registry["CompleteSets"]);
emit CompleteSetsPurchased(_universe, _market, _account, _numCompleteSets);
return true;
}
function logCompleteSetsSold(IUniverse _universe, IMarket _market, address _account, uint256 _numCompleteSets) public returns (bool) {
require(msg.sender == registry["CompleteSets"]);
emit CompleteSetsSold(_universe, _market, _account, _numCompleteSets);
return true;
}
function logTradingProceedsClaimed(IUniverse _universe, address _shareToken, address _sender, address _market, uint256 _numShares, uint256 _numPayoutTokens, uint256 _finalTokenBalance) public returns (bool) {
require(msg.sender == registry["ClaimTradingProceeds"]);
emit TradingProceedsClaimed(_universe, _shareToken, _sender, _market, _numShares, _numPayoutTokens, _finalTokenBalance);
return true;
}
function logUniverseForked() public returns (bool) {
require(universes[msg.sender]);
emit UniverseForked(msg.sender);
return true;
}
function logReputationTokensTransferred(IUniverse _universe, address _from, address _to, uint256 _value) public returns (bool) {
require(isKnownUniverse(_universe));
require(_universe.getReputationToken() == IReputationToken(msg.sender));
emit TokensTransferred(_universe, msg.sender, _from, _to, _value, TokenType.ReputationToken, 0);
return true;
}
function logDisputeCrowdsourcerTokensTransferred(IUniverse _universe, address _from, address _to, uint256 _value) public returns (bool) {
IDisputeCrowdsourcer _disputeCrowdsourcer = IDisputeCrowdsourcer(msg.sender);
require(isKnownCrowdsourcer(_disputeCrowdsourcer));
emit TokensTransferred(_universe, msg.sender, _from, _to, _value, TokenType.DisputeCrowdsourcer, _disputeCrowdsourcer.getMarket());
return true;
}
function logShareTokensTransferred(IUniverse _universe, address _from, address _to, uint256 _value) public returns (bool) {
IShareToken _shareToken = IShareToken(msg.sender);
require(isKnownShareToken(_shareToken));
emit TokensTransferred(_universe, msg.sender, _from, _to, _value, TokenType.ShareToken, _shareToken.getMarket());
return true;
}
function logReputationTokenBurned(IUniverse _universe, address _target, uint256 _amount) public returns (bool) {
require(isKnownUniverse(_universe));
require(_universe.getReputationToken() == IReputationToken(msg.sender));
emit TokensBurned(_universe, msg.sender, _target, _amount, TokenType.ReputationToken, 0);
return true;
}
function logReputationTokenMinted(IUniverse _universe, address _target, uint256 _amount) public returns (bool) {
require(isKnownUniverse(_universe));
require(_universe.getReputationToken() == IReputationToken(msg.sender));
emit TokensMinted(_universe, msg.sender, _target, _amount, TokenType.ReputationToken, 0);
return true;
}
function logShareTokenBurned(IUniverse _universe, address _target, uint256 _amount) public returns (bool) {
IShareToken _shareToken = IShareToken(msg.sender);
require(isKnownShareToken(_shareToken));
emit TokensBurned(_universe, msg.sender, _target, _amount, TokenType.ShareToken, _shareToken.getMarket());
return true;
}
function logShareTokenMinted(IUniverse _universe, address _target, uint256 _amount) public returns (bool) {
IShareToken _shareToken = IShareToken(msg.sender);
require(isKnownShareToken(_shareToken));
emit TokensMinted(_universe, msg.sender, _target, _amount, TokenType.ShareToken, _shareToken.getMarket());
return true;
}
function logDisputeCrowdsourcerTokensBurned(IUniverse _universe, address _target, uint256 _amount) public returns (bool) {
IDisputeCrowdsourcer _disputeCrowdsourcer = IDisputeCrowdsourcer(msg.sender);
require(isKnownCrowdsourcer(_disputeCrowdsourcer));
emit TokensBurned(_universe, msg.sender, _target, _amount, TokenType.DisputeCrowdsourcer, _disputeCrowdsourcer.getMarket());
return true;
}
function logDisputeCrowdsourcerTokensMinted(IUniverse _universe, address _target, uint256 _amount) public returns (bool) {
IDisputeCrowdsourcer _disputeCrowdsourcer = IDisputeCrowdsourcer(msg.sender);
require(isKnownCrowdsourcer(_disputeCrowdsourcer));
emit TokensMinted(_universe, msg.sender, _target, _amount, TokenType.DisputeCrowdsourcer, _disputeCrowdsourcer.getMarket());
return true;
}
function logDisputeWindowCreated(IDisputeWindow _disputeWindow, uint256 _id) public returns (bool) {
require(universes[msg.sender]);
emit DisputeWindowCreated(msg.sender, _disputeWindow, _disputeWindow.getStartTime(), _disputeWindow.getEndTime(), _id);
return true;
}
function logTimestampSet(uint256 _newTimestamp) public returns (bool) {
require(msg.sender == registry["Time"]);
emit TimestampSet(_newTimestamp);
return true;
}
function logInitialReporterTransferred(IUniverse _universe, IMarket _market, address _from, address _to) public returns (bool) {
require(isKnownUniverse(_universe));
require(_universe.isContainerForMarket(_market));
require(msg.sender == _market.getInitialReporterAddress());
emit InitialReporterTransferred(_universe, _market, _from, _to);
return true;
}
function logMarketTransferred(IUniverse _universe, address _from, address _to) public returns (bool) {
require(isKnownUniverse(_universe));
IMarket _market = IMarket(msg.sender);
require(_universe.isContainerForMarket(_market));
emit MarketTransferred(_universe, _market, _from, _to);
return true;
}
function logAuctionTokensTransferred(IUniverse _universe, address _from, address _to, uint256 _value) public returns (bool) {
require(isKnownAuctionToken(IAuctionToken(msg.sender)));
emit TokensTransferred(_universe, msg.sender, _from, _to, _value, TokenType.AuctionToken, 0);
return true;
}
function logAuctionTokenBurned(IUniverse _universe, address _target, uint256 _amount) public returns (bool) {
require(isKnownAuctionToken(IAuctionToken(msg.sender)));
emit TokensBurned(_universe, msg.sender, _target, _amount, TokenType.AuctionToken, 0);
return true;
}
function logAuctionTokenMinted(IUniverse _universe, address _target, uint256 _amount) public returns (bool) {
require(isKnownAuctionToken(IAuctionToken(msg.sender)));
emit TokensMinted(_universe, msg.sender, _target, _amount, TokenType.AuctionToken, 0);
return true;
}
}
contract IReportingParticipant {
function getStake() public view returns (uint256);
function getPayoutDistributionHash() public view returns (bytes32);
function liquidateLosing() public returns (bool);
function redeem(address _redeemer) public returns (bool);
function isDisavowed() public view returns (bool);
function getPayoutNumerator(uint256 _outcome) public view returns (uint256);
function getMarket() public view returns (IMarket);
function getSize() public view returns (uint256);
}
contract IInitialReporter is IReportingParticipant {
function initialize(IAugur _augur, IMarket _market, address _designatedReporter) public returns (bool);
function report(address _reporter, bytes32 _payoutDistributionHash, uint256[] _payoutNumerators, uint256 _initialReportStake) public returns (bool);
function designatedReporterShowed() public view returns (bool);
function designatedReporterWasCorrect() public view returns (bool);
function getDesignatedReporter() public view returns (address);
function getReportTimestamp() public view returns (uint256);
function migrateToNewUniverse(address _designatedReporter) public returns (bool);
function returnRepFromDisavow() public returns (bool);
}
contract ITime is ITyped {
function getTimestamp() external view returns (uint256);
}
contract IOwnable {
function getOwner() public view returns (address);
function transferOwnership(address newOwner) public returns (bool);
}
contract IUniverseFactory {
function createUniverse(IAugur _augur, IUniverse _parentUniverse, bytes32 _parentPayoutDistributionHash) public returns (IUniverse);
}
library SafeMathUint256 {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a * b;
require(a == 0 || c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
function min(uint256 a, uint256 b) internal pure returns (uint256) {
if (a <= b) {
return a;
} else {
return b;
}
}
function max(uint256 a, uint256 b) internal pure returns (uint256) {
if (a >= b) {
return a;
} else {
return b;
}
}
function getUint256Min() internal pure returns (uint256) {
return 0;
}
function getUint256Max() internal pure returns (uint256) {
return 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
}
function isMultipleOf(uint256 a, uint256 b) internal pure returns (bool) {
return a % b == 0;
}
// Float [fixed point] Operations
function fxpMul(uint256 a, uint256 b, uint256 base) internal pure returns (uint256) {
return div(mul(a, b), base);
}
function fxpDiv(uint256 a, uint256 b, uint256 base) internal pure returns (uint256) {
return div(mul(a, base), b);
}
}
contract IRepPriceOracle {
function getRepPriceInAttoEth() public view returns (uint256);
}
contract IAuction is IRepPriceOracle {
IAuctionToken public repAuctionToken; // The token keeping track of ETH provided to purchase the REP being auctioned off
IAuctionToken public ethAuctionToken; // The token keeping track of REP provided to purchase the ETH being auctioned off
function initialize(IAugur _augur, IUniverse _universe, IReputationToken _reputationToken) public returns (bool);
function recordFees(uint256 _feeAmount) public returns (bool);
function getUniverse() public view returns (IUniverse);
function getAuctionIndexForCurrentTime() public view returns (uint256);
}
contract ERC20Token {
function totalSupply() public view returns (uint256);
function balanceOf(address owner) public view returns (uint256);
function transfer(address to, uint256 amount) public returns (bool);
function transferFrom(address from, address to, uint256 amount) public returns (bool);
function approve(address spender, uint256 amount) public returns (bool);
function allowance(address owner, address spender) public view returns (uint256);
// solhint-disable-next-line no-simple-event-func-name
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
contract IReputationToken is ITyped, ERC20Token {
function migrateOut(IReputationToken _destination, uint256 _attotokens) public returns (bool);
function migrateIn(address _reporter, uint256 _attotokens) public returns (bool);
function trustedReportingParticipantTransfer(address _source, address _destination, uint256 _attotokens) public returns (bool);
function trustedMarketTransfer(address _source, address _destination, uint256 _attotokens) public returns (bool);
function trustedUniverseTransfer(address _source, address _destination, uint256 _attotokens) public returns (bool);
function getUniverse() public view returns (IUniverse);
function getTotalMigrated() public view returns (uint256);
function getTotalTheoreticalSupply() public view returns (uint256);
function mintForReportingParticipant(uint256 _amountMigrated) public returns (bool);
}
contract IAuctionToken is ITyped, ERC20Token {
uint256 public maxSupply;
function initialize(IAugur _augur, IAuction _auction, ERC20Token _redemptionToken, uint256 _auctionIndex, address _erc820RegistryAddress) public returns (bool);
function mintForPurchaser(address _purchaser, uint256 _amount) public returns (bool);
function retrieveFunds() public returns (bool);
}
contract IDisputeCrowdsourcer is IReportingParticipant, ERC20Token{
function initialize(IAugur _augur, IMarket market, uint256 _size, bytes32 _payoutDistributionHash, uint256[] _payoutNumerators, address _erc820RegistryAddress) public returns (bool);
function contribute(address _participant, uint256 _amount) public returns (uint256);
}
contract IV2ReputationToken is IReputationToken {
function trustedAuctionTransfer(address _source, address _destination, uint256 _attotokens) public returns (bool);
function mintForAuction(uint256 _amountToMint) public returns (bool);
function burnForAuction(uint256 _amountToMint) public returns (bool);
function burnForMarket(uint256 _amountToBurn) public returns (bool);
}
contract ICash is ERC20Token {
function depositEther() external payable returns(bool);
function depositEtherFor(address _to) external payable returns(bool);
function withdrawEther(uint256 _amount) external returns(bool);
function withdrawEtherTo(address _to, uint256 _amount) external returns(bool);
function withdrawEtherToIfPossible(address _to, uint256 _amount) external returns (bool);
}
contract IShareToken is ITyped, ERC20Token {
function initialize(IAugur _augur, IMarket _market, uint256 _outcome, address _erc820RegistryAddress) external returns (bool);
function createShares(address _owner, uint256 _amount) external returns (bool);
function destroyShares(address, uint256 balance) external returns (bool);
function getMarket() external view returns (IMarket);
function getOutcome() external view returns (uint256);
function trustedOrderTransfer(address _source, address _destination, uint256 _attotokens) public returns (bool);
function trustedFillOrderTransfer(address _source, address _destination, uint256 _attotokens) public returns (bool);
function trustedCancelOrderTransfer(address _source, address _destination, uint256 _attotokens) public returns (bool);
}
contract IMarket is ITyped, IOwnable {
enum MarketType {
YES_NO,
CATEGORICAL,
SCALAR
}
function initialize(IAugur _augur, IUniverse _universe, uint256 _endTime, uint256 _feePerEthInAttoEth, address _designatedReporterAddress, address _creator, uint256 _numOutcomes, uint256 _numTicks) public returns (bool _success);
function derivePayoutDistributionHash(uint256[] _payoutNumerators) public view returns (bytes32);
function getUniverse() public view returns (IUniverse);
function getDisputeWindow() public view returns (IDisputeWindow);
function getNumberOfOutcomes() public view returns (uint256);
function getNumTicks() public view returns (uint256);
function getDenominationToken() public view returns (ICash);
function getShareToken(uint256 _outcome) public view returns (IShareToken);
function getMarketCreatorSettlementFeeDivisor() public view returns (uint256);
function getForkingMarket() public view returns (IMarket _market);
function getEndTime() public view returns (uint256);
function getWinningPayoutDistributionHash() public view returns (bytes32);
function getWinningPayoutNumerator(uint256 _outcome) public view returns (uint256);
function getReputationToken() public view returns (IV2ReputationToken);
function getFinalizationTime() public view returns (uint256);
function getInitialReporterAddress() public view returns (address);
function getDesignatedReportingEndTime() public view returns (uint256);
function deriveMarketCreatorFeeAmount(uint256 _amount) public view returns (uint256);
function recordMarketCreatorFees(uint256 _marketCreatorFees) public returns (bool);
function isContainerForShareToken(IShareToken _shadyTarget) public view returns (bool);
function isContainerForReportingParticipant(IReportingParticipant _reportingParticipant) public view returns (bool);
function isInvalid() public view returns (bool);
function finalize() public returns (bool);
function designatedReporterWasCorrect() public view returns (bool);
function designatedReporterShowed() public view returns (bool);
function isFinalized() public view returns (bool);
function finalizeFork() public returns (bool);
function assertBalances() public view returns (bool);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment