aboutsummaryrefslogtreecommitdiffstats
path: root/test/compilationTests/gnosis/Tokens
diff options
context:
space:
mode:
Diffstat (limited to 'test/compilationTests/gnosis/Tokens')
-rw-r--r--test/compilationTests/gnosis/Tokens/EtherToken.sol47
-rw-r--r--test/compilationTests/gnosis/Tokens/OutcomeToken.sol63
-rw-r--r--test/compilationTests/gnosis/Tokens/StandardToken.sol102
-rw-r--r--test/compilationTests/gnosis/Tokens/Token.sol23
4 files changed, 235 insertions, 0 deletions
diff --git a/test/compilationTests/gnosis/Tokens/EtherToken.sol b/test/compilationTests/gnosis/Tokens/EtherToken.sol
new file mode 100644
index 00000000..f6e73e5a
--- /dev/null
+++ b/test/compilationTests/gnosis/Tokens/EtherToken.sol
@@ -0,0 +1,47 @@
+pragma solidity ^0.4.11;
+import "../Tokens/StandardToken.sol";
+
+
+/// @title Token contract - Token exchanging Ether 1:1
+/// @author Stefan George - <stefan@gnosis.pm>
+contract EtherToken is StandardToken {
+ using Math for *;
+
+ /*
+ * Events
+ */
+ event Deposit(address indexed sender, uint value);
+ event Withdrawal(address indexed receiver, uint value);
+
+ /*
+ * Constants
+ */
+ string public constant name = "Ether Token";
+ string public constant symbol = "ETH";
+ uint8 public constant decimals = 18;
+
+ /*
+ * Public functions
+ */
+ /// @dev Buys tokens with Ether, exchanging them 1:1
+ function deposit()
+ public
+ payable
+ {
+ balances[msg.sender] = balances[msg.sender].add(msg.value);
+ totalTokens = totalTokens.add(msg.value);
+ Deposit(msg.sender, msg.value);
+ }
+
+ /// @dev Sells tokens in exchange for Ether, exchanging them 1:1
+ /// @param value Number of tokens to sell
+ function withdraw(uint value)
+ public
+ {
+ // Balance covers value
+ balances[msg.sender] = balances[msg.sender].sub(value);
+ totalTokens = totalTokens.sub(value);
+ msg.sender.transfer(value);
+ Withdrawal(msg.sender, value);
+ }
+}
diff --git a/test/compilationTests/gnosis/Tokens/OutcomeToken.sol b/test/compilationTests/gnosis/Tokens/OutcomeToken.sol
new file mode 100644
index 00000000..fd1fa590
--- /dev/null
+++ b/test/compilationTests/gnosis/Tokens/OutcomeToken.sol
@@ -0,0 +1,63 @@
+pragma solidity ^0.4.11;
+import "../Tokens/StandardToken.sol";
+
+
+/// @title Outcome token contract - Issuing and revoking outcome tokens
+/// @author Stefan George - <stefan@gnosis.pm>
+contract OutcomeToken is StandardToken {
+ using Math for *;
+
+ /*
+ * Events
+ */
+ event Issuance(address indexed owner, uint amount);
+ event Revocation(address indexed owner, uint amount);
+
+ /*
+ * Storage
+ */
+ address public eventContract;
+
+ /*
+ * Modifiers
+ */
+ modifier isEventContract () {
+ // Only event contract is allowed to proceed
+ require(msg.sender == eventContract);
+ _;
+ }
+
+ /*
+ * Public functions
+ */
+ /// @dev Constructor sets events contract address
+ function OutcomeToken()
+ public
+ {
+ eventContract = msg.sender;
+ }
+
+ /// @dev Events contract issues new tokens for address. Returns success
+ /// @param _for Address of receiver
+ /// @param outcomeTokenCount Number of tokens to issue
+ function issue(address _for, uint outcomeTokenCount)
+ public
+ isEventContract
+ {
+ balances[_for] = balances[_for].add(outcomeTokenCount);
+ totalTokens = totalTokens.add(outcomeTokenCount);
+ Issuance(_for, outcomeTokenCount);
+ }
+
+ /// @dev Events contract revokes tokens for address. Returns success
+ /// @param _for Address of token holder
+ /// @param outcomeTokenCount Number of tokens to revoke
+ function revoke(address _for, uint outcomeTokenCount)
+ public
+ isEventContract
+ {
+ balances[_for] = balances[_for].sub(outcomeTokenCount);
+ totalTokens = totalTokens.sub(outcomeTokenCount);
+ Revocation(_for, outcomeTokenCount);
+ }
+}
diff --git a/test/compilationTests/gnosis/Tokens/StandardToken.sol b/test/compilationTests/gnosis/Tokens/StandardToken.sol
new file mode 100644
index 00000000..fc899ca6
--- /dev/null
+++ b/test/compilationTests/gnosis/Tokens/StandardToken.sol
@@ -0,0 +1,102 @@
+pragma solidity ^0.4.11;
+import "../Tokens/Token.sol";
+import "../Utils/Math.sol";
+
+
+/// @title Standard token contract with overflow protection
+contract StandardToken is Token {
+ using Math for *;
+
+ /*
+ * Storage
+ */
+ mapping (address => uint) balances;
+ mapping (address => mapping (address => uint)) allowances;
+ uint totalTokens;
+
+ /*
+ * Public functions
+ */
+ /// @dev Transfers sender's tokens to a given address. Returns success
+ /// @param to Address of token receiver
+ /// @param value Number of tokens to transfer
+ /// @return Was transfer successful?
+ function transfer(address to, uint value)
+ public
+ returns (bool)
+ {
+ if ( !balances[msg.sender].safeToSub(value)
+ || !balances[to].safeToAdd(value))
+ return false;
+ balances[msg.sender] -= value;
+ balances[to] += value;
+ Transfer(msg.sender, to, value);
+ return true;
+ }
+
+ /// @dev Allows allowed third party to transfer tokens from one address to another. Returns success
+ /// @param from Address from where tokens are withdrawn
+ /// @param to Address to where tokens are sent
+ /// @param value Number of tokens to transfer
+ /// @return Was transfer successful?
+ function transferFrom(address from, address to, uint value)
+ public
+ returns (bool)
+ {
+ if ( !balances[from].safeToSub(value)
+ || !allowances[from][msg.sender].safeToSub(value)
+ || !balances[to].safeToAdd(value))
+ return false;
+ balances[from] -= value;
+ allowances[from][msg.sender] -= value;
+ balances[to] += value;
+ Transfer(from, to, value);
+ return true;
+ }
+
+ /// @dev Sets approved amount of tokens for spender. Returns success
+ /// @param spender Address of allowed account
+ /// @param value Number of approved tokens
+ /// @return Was approval successful?
+ function approve(address spender, uint value)
+ public
+ returns (bool)
+ {
+ allowances[msg.sender][spender] = value;
+ Approval(msg.sender, spender, value);
+ return true;
+ }
+
+ /// @dev Returns number of allowed tokens for given address
+ /// @param owner Address of token owner
+ /// @param spender Address of token spender
+ /// @return Remaining allowance for spender
+ function allowance(address owner, address spender)
+ public
+ constant
+ returns (uint)
+ {
+ return allowances[owner][spender];
+ }
+
+ /// @dev Returns number of tokens owned by given address
+ /// @param owner Address of token owner
+ /// @return Balance of owner
+ function balanceOf(address owner)
+ public
+ constant
+ returns (uint)
+ {
+ return balances[owner];
+ }
+
+ /// @dev Returns total supply of tokens
+ /// @return Total supply
+ function totalSupply()
+ public
+ constant
+ returns (uint)
+ {
+ return totalTokens;
+ }
+}
diff --git a/test/compilationTests/gnosis/Tokens/Token.sol b/test/compilationTests/gnosis/Tokens/Token.sol
new file mode 100644
index 00000000..19bb618b
--- /dev/null
+++ b/test/compilationTests/gnosis/Tokens/Token.sol
@@ -0,0 +1,23 @@
+/// Implements ERC 20 Token standard: https://github.com/ethereum/EIPs/issues/20
+pragma solidity ^0.4.11;
+
+
+/// @title Abstract token contract - Functions to be implemented by token contracts
+contract Token {
+
+ /*
+ * Events
+ */
+ event Transfer(address indexed from, address indexed to, uint value);
+ event Approval(address indexed owner, address indexed spender, uint value);
+
+ /*
+ * Public functions
+ */
+ function transfer(address to, uint value) public returns (bool);
+ function transferFrom(address from, address to, uint value) public returns (bool);
+ function approve(address spender, uint value) public returns (bool);
+ function balanceOf(address owner) public constant returns (uint);
+ function allowance(address owner, address spender) public constant returns (uint);
+ function totalSupply() public constant returns (uint);
+}