Created
July 20, 2017 10:08
-
-
Save retotrinkler/3d32f448c3b53b6e6a9550b782e47274 to your computer and use it in GitHub Desktop.
PremindAsset.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.11; | |
/// @title ERC20 Token Protocol | |
/// @author Melonport AG <[email protected]> | |
/// @notice See https://github.com/ethereum/EIPs/issues/20 | |
contract ERC20Protocol { | |
// CONSTANT METHODS | |
function totalSupply() constant returns (uint256 totalSupply) {} | |
function balanceOf(address _owner) constant returns (uint256 balance) {} | |
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {} | |
// NON-CONSTANT METHODS | |
function transfer(address _to, uint256 _value) returns (bool success) {} | |
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {} | |
function approve(address _spender, uint256 _value) returns (bool success) {} | |
// EVENTS | |
event Transfer(address indexed _from, address indexed _to, uint256 _value); | |
event Approval(address indexed _owner, address indexed _spender, uint256 _value); | |
} | |
/// @title ERC20 Token | |
/// @author Melonport AG <[email protected]> | |
/// @notice Original taken from https://github.com/ethereum/EIPs/issues/20 | |
/// @notice Checked against integer overflow | |
contract ERC20 is ERC20Protocol { | |
function transfer(address _to, uint256 _value) returns (bool success) { | |
if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) { | |
balances[msg.sender] -= _value; | |
balances[_to] += _value; | |
Transfer(msg.sender, _to, _value); | |
return true; | |
} else { return false; } | |
} | |
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) { | |
if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) { | |
balances[_to] += _value; | |
balances[_from] -= _value; | |
allowed[_from][msg.sender] -= _value; | |
Transfer(_from, _to, _value); | |
return true; | |
} else { return false; } | |
} | |
function balanceOf(address _owner) constant returns (uint256 balance) { | |
return balances[_owner]; | |
} | |
function approve(address _spender, uint256 _value) returns (bool success) { | |
allowed[msg.sender][_spender] = _value; | |
Approval(msg.sender, _spender, _value); | |
return true; | |
} | |
function allowance(address _owner, address _spender) constant returns (uint256 remaining) { | |
return allowed[_owner][_spender]; | |
} | |
mapping (address => uint256) balances; | |
mapping (address => mapping (address => uint256)) allowed; | |
uint256 public totalSupply; | |
} | |
/// @title Asset Contract. | |
/// @author Melonport AG <[email protected]> | |
contract Asset is ERC20 { | |
// FIELDS | |
// Constant token specific fields | |
string public name; | |
string public symbol; | |
uint public decimals; | |
// CONSTANT METHODS | |
function getName() constant returns (string) { return name; } | |
function getSymbol() constant returns (string) { return symbol; } | |
function getDecimals() constant returns (uint) { return decimals; } | |
// NON-CONSTANT METHODS | |
function Asset(string _name, string _symbol, uint _decimals) { | |
name = _name; // Set the name for display purposes | |
symbol = _symbol; // Set the symbol for display purposes | |
decimals = _decimals; // Defined in price feed protocol | |
} | |
} | |
/// @title Math operations with safety checks | |
/// @author Melonport AG <[email protected]> | |
/// @notice From https://github.com/status-im/status-network-token/blob/master/contracts/SafeMath.sol | |
library SafeMath { | |
function mul(uint a, uint b) internal returns (uint) { | |
uint c = a * b; | |
assert(a == 0 || c / a == b); | |
return c; | |
} | |
function div(uint a, uint b) internal returns (uint) { | |
uint c = a / b; | |
return c; | |
} | |
function sub(uint a, uint b) internal returns (uint) { | |
assert(b <= a); | |
return a - b; | |
} | |
function add(uint a, uint b) internal returns (uint) { | |
uint c = a + b; | |
assert(c >= a); | |
return c; | |
} | |
function max64(uint64 a, uint64 b) internal constant returns (uint64) { | |
return a >= b ? a : b; | |
} | |
function min64(uint64 a, uint64 b) internal constant returns (uint64) { | |
return a < b ? a : b; | |
} | |
function max256(uint256 a, uint256 b) internal constant returns (uint256) { | |
return a >= b ? a : b; | |
} | |
function min256(uint256 a, uint256 b) internal constant returns (uint256) { | |
return a < b ? a : b; | |
} | |
} | |
/// @title PreminedAsset Contract. | |
/// @author Melonport AG <[email protected]> | |
/// @notice Premined amount used to make markets | |
contract PreminedAsset is Asset { | |
using SafeMath for uint256; | |
// METHODS | |
function PreminedAsset(string _name, string _symbol, uint8 _decimals, uint _amount) | |
Asset(_name, _symbol, _decimals) | |
{ | |
balances[msg.sender] = balances[msg.sender].add(_amount); | |
totalSupply = totalSupply.add(_amount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment