|
|
|
|
|
pragma solidity ^0.4.20; |
|
|
|
|
|
|
|
contract ERC20Basic { |
|
uint256 public totalSupply; |
|
function balanceOf(address who) public view returns (uint256); |
|
function transfer(address to, uint256 value) public returns (bool); |
|
event Transfer(address indexed from, address indexed to, uint256 value); |
|
} |
|
|
|
|
|
|
|
|
|
library SafeMath { |
|
function mul(uint256 a, uint256 b) internal pure returns (uint256) { |
|
if (a == 0) { |
|
return 0; |
|
} |
|
uint256 c = a * b; |
|
assert(c / a == b); |
|
return c; |
|
} |
|
|
|
function div(uint256 a, uint256 b) internal pure returns (uint256) { |
|
|
|
uint256 c = a / b; |
|
|
|
return c; |
|
} |
|
|
|
function sub(uint256 a, uint256 b) internal pure returns (uint256) { |
|
assert(b <= a); |
|
return a - b; |
|
} |
|
|
|
function add(uint256 a, uint256 b) internal pure returns (uint256) { |
|
uint256 c = a + b; |
|
assert(c >= a); |
|
return c; |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
contract BasicToken is ERC20Basic { |
|
using SafeMath for uint256; |
|
|
|
mapping(address => uint256) balances; |
|
|
|
|
|
function transfer(address _to, uint256 _value) public returns (bool) { |
|
require(_to != address(0)); |
|
require(_value <= balances[msg.sender]); |
|
|
|
|
|
balances[msg.sender] = balances[msg.sender].sub(_value); |
|
balances[_to] = balances[_to].add(_value); |
|
Transfer(msg.sender, _to, _value); |
|
return true; |
|
} |
|
|
|
|
|
function balanceOf(address _owner) public view returns (uint256 balance) { |
|
return balances[_owner]; |
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
contract ERC20 is ERC20Basic { |
|
function allowance(address owner, address spender) public view returns (uint256); |
|
function transferFrom(address from, address to, uint256 value) public returns (bool); |
|
function approve(address spender, uint256 value) public returns (bool); |
|
event Approval(address indexed owner, address indexed spender, uint256 value); |
|
} |
|
|
|
|
|
|
|
|
|
contract StandardToken is ERC20, BasicToken { |
|
|
|
mapping (address => mapping (address => uint256)) internal allowed; |
|
|
|
|
|
|
|
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { |
|
require(_to != address(0)); |
|
require(_value <= balances[_from]); |
|
require(_value <= allowed[_from][msg.sender]); |
|
|
|
balances[_from] = balances[_from].sub(_value); |
|
balances[_to] = balances[_to].add(_value); |
|
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); |
|
Transfer(_from, _to, _value); |
|
return true; |
|
} |
|
|
|
|
|
function approve(address _spender, uint256 _value) public returns (bool) { |
|
allowed[msg.sender][_spender] = _value; |
|
Approval(msg.sender, _spender, _value); |
|
return true; |
|
} |
|
|
|
|
|
function allowance(address _owner, address _spender) public view returns (uint256) { |
|
return allowed[_owner][_spender]; |
|
} |
|
|
|
|
|
function increaseApproval(address _spender, uint _addedValue) public returns (bool) { |
|
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); |
|
Approval(msg.sender, _spender, allowed[msg.sender][_spender]); |
|
return true; |
|
} |
|
|
|
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) { |
|
uint oldValue = allowed[msg.sender][_spender]; |
|
if (_subtractedValue > oldValue) { |
|
allowed[msg.sender][_spender] = 0; |
|
} else { |
|
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); |
|
} |
|
Approval(msg.sender, _spender, allowed[msg.sender][_spender]); |
|
return true; |
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
contract Ownable { |
|
address public owner; |
|
|
|
|
|
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); |
|
|
|
|
|
|
|
function Ownable() public { |
|
owner = msg.sender; |
|
} |
|
|
|
|
|
|
|
modifier onlyOwner() { |
|
require(msg.sender == owner); |
|
_; |
|
} |
|
|
|
|
|
|
|
function transferOwnership(address newOwner) public onlyOwner { |
|
require(newOwner != address(0)); |
|
OwnershipTransferred(owner, newOwner); |
|
owner = newOwner; |
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
contract MintableToken is StandardToken, Ownable { |
|
event Mint(address indexed to, uint256 amount); |
|
event MintFinished(); |
|
|
|
bool public mintingFinished = false; |
|
|
|
|
|
modifier canMint() { |
|
require(!mintingFinished); |
|
_; |
|
} |
|
|
|
|
|
function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) { |
|
totalSupply = totalSupply.add(_amount); |
|
balances[_to] = balances[_to].add(_amount); |
|
Mint(_to, _amount); |
|
Transfer(address(0), _to, _amount); |
|
return true; |
|
} |
|
|
|
|
|
function finishMinting() onlyOwner canMint public returns (bool) { |
|
mintingFinished = true; |
|
MintFinished(); |
|
return true; |
|
} |
|
} |
|
|
|
|
|
|
|
contract FreezableToken is StandardToken { |
|
|
|
mapping (bytes32 => uint64) internal chains; |
|
|
|
mapping (bytes32 => uint) internal freezings; |
|
|
|
mapping (address => uint) internal freezingBalance; |
|
|
|
event Freezed(address indexed to, uint64 release, uint amount); |
|
event Released(address indexed owner, uint amount); |
|
|
|
|
|
|
|
function balanceOf(address _owner) public view returns (uint256 balance) { |
|
return super.balanceOf(_owner) + freezingBalance[_owner]; |
|
} |
|
|
|
|
|
function actualBalanceOf(address _owner) public view returns (uint256 balance) { |
|
return super.balanceOf(_owner); |
|
} |
|
|
|
function freezingBalanceOf(address _owner) public view returns (uint256 balance) { |
|
return freezingBalance[_owner]; |
|
} |
|
|
|
|
|
function freezingCount(address _addr) public view returns (uint count) { |
|
uint64 release = chains[toKey(_addr, 0)]; |
|
while (release != 0) { |
|
count ++; |
|
release = chains[toKey(_addr, release)]; |
|
} |
|
} |
|
|
|
|
|
function getFreezing(address _addr, uint _index) public view returns (uint64 _release, uint _balance) { |
|
for (uint i = 0; i < _index + 1; i ++) { |
|
_release = chains[toKey(_addr, _release)]; |
|
if (_release == 0) { |
|
return; |
|
} |
|
} |
|
_balance = freezings[toKey(_addr, _release)]; |
|
} |
|
|
|
|
|
function freezeTo(address _to, uint _amount, uint64 _until) public { |
|
require(_to != address(0)); |
|
require(_amount <= balances[msg.sender]); |
|
|
|
balances[msg.sender] = balances[msg.sender].sub(_amount); |
|
|
|
bytes32 currentKey = toKey(_to, _until); |
|
freezings[currentKey] = freezings[currentKey].add(_amount); |
|
freezingBalance[_to] = freezingBalance[_to].add(_amount); |
|
|
|
freeze(_to, _until); |
|
Transfer(msg.sender, _to, _amount); |
|
Freezed(_to, _until, _amount); |
|
} |
|
|
|
|
|
function releaseOnce() public { |
|
bytes32 headKey = toKey(msg.sender, 0); |
|
uint64 head = chains[headKey]; |
|
require(head != 0); |
|
require(uint64(block.timestamp) > head); |
|
bytes32 currentKey = toKey(msg.sender, head); |
|
|
|
uint64 next = chains[currentKey]; |
|
|
|
uint amount = freezings[currentKey]; |
|
delete freezings[currentKey]; |
|
|
|
balances[msg.sender] = balances[msg.sender].add(amount); |
|
freezingBalance[msg.sender] = freezingBalance[msg.sender].sub(amount); |
|
|
|
if (next == 0) { |
|
delete chains[headKey]; |
|
} |
|
else { |
|
chains[headKey] = next; |
|
delete chains[currentKey]; |
|
} |
|
Released(msg.sender, amount); |
|
} |
|
|
|
|
|
function releaseAll() public returns (uint tokens) { |
|
uint release; |
|
uint balance; |
|
(release, balance) = getFreezing(msg.sender, 0); |
|
while (release != 0 && block.timestamp > release) { |
|
releaseOnce(); |
|
tokens += balance; |
|
(release, balance) = getFreezing(msg.sender, 0); |
|
} |
|
} |
|
|
|
function toKey(address _addr, uint _release) internal pure returns (bytes32 result) { |
|
|
|
result = 0x5749534800000000000000000000000000000000000000000000000000000000; |
|
assembly { |
|
result := or(result, mul(_addr, 0x10000000000000000)) |
|
result := or(result, _release) |
|
} |
|
} |
|
|
|
function freeze(address _to, uint64 _until) internal { |
|
require(_until > block.timestamp); |
|
bytes32 key = toKey(_to, _until); |
|
bytes32 parentKey = toKey(_to, uint64(0)); |
|
uint64 next = chains[parentKey]; |
|
|
|
if (next == 0) { |
|
chains[parentKey] = _until; |
|
return; |
|
} |
|
|
|
bytes32 nextKey = toKey(_to, next); |
|
uint parent; |
|
|
|
while (next != 0 && _until > next) { |
|
parent = next; |
|
parentKey = nextKey; |
|
|
|
next = chains[nextKey]; |
|
nextKey = toKey(_to, next); |
|
} |
|
|
|
if (_until == next) { |
|
return; |
|
} |
|
|
|
if (next != 0) { |
|
chains[key] = next; |
|
} |
|
|
|
chains[parentKey] = _until; |
|
} |
|
} |
|
|
|
|
|
|
|
contract ERC223Receiver { |
|
|
|
function tokenFallback(address _from, uint _value, bytes _data) public; |
|
} |
|
|
|
contract ERC223Basic is ERC20Basic { |
|
function transfer(address to, uint value, bytes data) public returns (bool); |
|
event Transfer(address indexed from, address indexed to, uint value, bytes data); |
|
} |
|
|
|
|
|
contract SuccessfulERC223Receiver is ERC223Receiver { |
|
event Invoked(address from, uint value, bytes data); |
|
|
|
function tokenFallback(address _from, uint _value, bytes _data) public { |
|
Invoked(_from, _value, _data); |
|
} |
|
} |
|
|
|
contract FailingERC223Receiver is ERC223Receiver { |
|
function tokenFallback(address, uint, bytes) public { |
|
revert(); |
|
} |
|
} |
|
|
|
contract ERC223ReceiverWithoutTokenFallback { |
|
} |
|
|
|
|
|
contract BurnableToken is StandardToken { |
|
|
|
event Burn(address indexed burner, uint256 value); |
|
|
|
|
|
function burn(uint256 _value) public { |
|
require(_value > 0); |
|
require(_value <= balances[msg.sender]); |
|
|
|
|
|
|
|
address burner = msg.sender; |
|
balances[burner] = balances[burner].sub(_value); |
|
totalSupply = totalSupply.sub(_value); |
|
Burn(burner, _value); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
contract Pausable is Ownable { |
|
event Pause(); |
|
event Unpause(); |
|
|
|
bool public paused = false; |
|
|
|
|
|
|
|
modifier whenNotPaused() { |
|
require(!paused); |
|
_; |
|
} |
|
|
|
|
|
modifier whenPaused() { |
|
require(paused); |
|
_; |
|
} |
|
|
|
|
|
function pause() onlyOwner whenNotPaused public { |
|
paused = true; |
|
Pause(); |
|
} |
|
|
|
|
|
function unpause() onlyOwner whenPaused public { |
|
paused = false; |
|
Unpause(); |
|
} |
|
} |
|
|
|
|
|
|
|
contract FreezableMintableToken is FreezableToken, MintableToken { |
|
|
|
function mintAndFreeze(address _to, uint _amount, uint64 _until) onlyOwner canMint public returns (bool) { |
|
totalSupply = totalSupply.add(_amount); |
|
|
|
bytes32 currentKey = toKey(_to, _until); |
|
freezings[currentKey] = freezings[currentKey].add(_amount); |
|
freezingBalance[_to] = freezingBalance[_to].add(_amount); |
|
|
|
freeze(_to, _until); |
|
Mint(_to, _amount); |
|
Freezed(_to, _until, _amount); |
|
Transfer(msg.sender, _to, _amount); |
|
return true; |
|
} |
|
} |
|
|
|
contract Consts { |
|
uint constant TOKEN_DECIMALS = 18; |
|
uint8 constant TOKEN_DECIMALS_UINT8 = 18; |
|
uint constant TOKEN_DECIMAL_MULTIPLIER = 10 ** TOKEN_DECIMALS; |
|
|
|
string constant TOKEN_NAME = "OOO"; |
|
string constant TOKEN_SYMBOL = "OOO"; |
|
bool constant PAUSED = false; |
|
address constant TARGET_USER = 0x085DA0829d1e2338F18312AA3FF872ff8053d355; |
|
|
|
bool constant CONTINUE_MINTING = true; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
contract ERC223Token is ERC223Basic, BasicToken, FailingERC223Receiver { |
|
using SafeMath for uint; |
|
|
|
|
|
function transfer(address _to, uint _value, bytes _data) public returns (bool) { |
|
|
|
|
|
uint codeLength; |
|
|
|
assembly { |
|
|
|
codeLength := extcodesize(_to) |
|
} |
|
|
|
balances[msg.sender] = balances[msg.sender].sub(_value); |
|
balances[_to] = balances[_to].add(_value); |
|
if(codeLength > 0) { |
|
ERC223Receiver receiver = ERC223Receiver(_to); |
|
receiver.tokenFallback(msg.sender, _value, _data); |
|
} |
|
Transfer(msg.sender, _to, _value, _data); |
|
return true; |
|
} |
|
|
|
|
|
function transfer(address _to, uint256 _value) public returns (bool) { |
|
bytes memory empty; |
|
return transfer(_to, _value, empty); |
|
} |
|
} |
|
|
|
|
|
contract MainToken is Consts, FreezableMintableToken, BurnableToken, Pausable |
|
|
|
{ |
|
|
|
event Initialized(); |
|
bool public initialized = false; |
|
|
|
function MainToken() public { |
|
init(); |
|
transferOwnership(TARGET_USER); |
|
} |
|
|
|
function init() private { |
|
require(!initialized); |
|
initialized = true; |
|
|
|
if (PAUSED) { |
|
pause(); |
|
} |
|
|
|
|
|
|
|
if (!CONTINUE_MINTING) { |
|
finishMinting(); |
|
} |
|
|
|
Initialized(); |
|
} |
|
|
|
|
|
function name() pure public returns (string _name) { |
|
return TOKEN_NAME; |
|
} |
|
|
|
function symbol() pure public returns (string _symbol) { |
|
return TOKEN_SYMBOL; |
|
} |
|
|
|
function decimals() pure public returns (uint8 _decimals) { |
|
return TOKEN_DECIMALS_UINT8; |
|
} |
|
|
|
function transferFrom(address _from, address _to, uint256 _value) public returns (bool _success) { |
|
require(!paused); |
|
return super.transferFrom(_from, _to, _value); |
|
} |
|
|
|
function transfer(address _to, uint256 _value) public returns (bool _success) { |
|
require(!paused); |
|
return super.transfer(_to, _value); |
|
} |
|
} |