2017-07-12 13:46:33 +00:00
|
|
|
pragma solidity ^0.4.11;
|
|
|
|
import "../Events/Event.sol";
|
|
|
|
|
|
|
|
|
|
|
|
/// @title Categorical event contract - Categorical events resolve to an outcome from a set of outcomes
|
|
|
|
/// @author Stefan George - <stefan@gnosis.pm>
|
|
|
|
contract CategoricalEvent is Event {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Public functions
|
|
|
|
*/
|
|
|
|
/// @dev Contract constructor validates and sets basic event properties
|
|
|
|
/// @param _collateralToken Tokens used as collateral in exchange for outcome tokens
|
|
|
|
/// @param _oracle Oracle contract used to resolve the event
|
|
|
|
/// @param outcomeCount Number of event outcomes
|
2018-06-25 13:02:20 +00:00
|
|
|
constructor(
|
2017-07-12 13:46:33 +00:00
|
|
|
Token _collateralToken,
|
|
|
|
Oracle _oracle,
|
|
|
|
uint8 outcomeCount
|
|
|
|
)
|
|
|
|
public
|
|
|
|
Event(_collateralToken, _oracle, outcomeCount)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @dev Exchanges sender's winning outcome tokens for collateral tokens
|
|
|
|
/// @return Sender's winnings
|
|
|
|
function redeemWinnings()
|
|
|
|
public
|
|
|
|
returns (uint winnings)
|
|
|
|
{
|
|
|
|
// Winning outcome has to be set
|
|
|
|
require(isOutcomeSet);
|
|
|
|
// Calculate winnings
|
|
|
|
winnings = outcomeTokens[uint(outcome)].balanceOf(msg.sender);
|
|
|
|
// Revoke tokens from winning outcome
|
|
|
|
outcomeTokens[uint(outcome)].revoke(msg.sender, winnings);
|
|
|
|
// Payout winnings
|
|
|
|
require(collateralToken.transfer(msg.sender, winnings));
|
2018-06-27 08:35:38 +00:00
|
|
|
emit WinningsRedemption(msg.sender, winnings);
|
2017-07-12 13:46:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @dev Calculates and returns event hash
|
|
|
|
/// @return Event hash
|
|
|
|
function getEventHash()
|
|
|
|
public
|
2018-07-02 09:14:28 +00:00
|
|
|
view
|
2017-07-12 13:46:33 +00:00
|
|
|
returns (bytes32)
|
|
|
|
{
|
2018-06-14 10:28:33 +00:00
|
|
|
return keccak256(abi.encodePacked(collateralToken, oracle, outcomeTokens.length));
|
2017-07-12 13:46:33 +00:00
|
|
|
}
|
|
|
|
}
|