| pragma solidity ^0.4.21; |
|
|
| |
|
|
| |
| |
| |
| library Math { |
|
|
| |
| |
| uint public constant ONE = 0x10000000000000000; |
| uint public constant LN2 = 0xb17217f7d1cf79ac; |
| uint public constant LOG2_E = 0x171547652b82fe177; |
|
|
| |
| |
| |
| |
| function exp(int x) |
| public |
| pure |
| returns (uint) |
| { |
| |
| |
| require(x <= 2454971259878909886679); |
| |
| |
| if (x < -818323753292969962227) |
| return 0; |
| |
| x = x |
| |
| |
| |
| int shift; |
| uint z; |
| if (x >= 0) { |
| shift = x / int(ONE); |
| z = uint(x % int(ONE)); |
| } |
| else { |
| shift = x / int(ONE) - 1; |
| z = ONE - uint(-x % int(ONE)); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| uint zpow = z; |
| uint result = ONE; |
| result += 0xb17217f7d1cf79ab |
| zpow = zpow |
| result += 0x3d7f7bff058b1d50 |
| zpow = zpow |
| result += 0xe35846b82505fc5 |
| zpow = zpow |
| result += 0x276556df749cee5 |
| zpow = zpow |
| result += 0x5761ff9e299cc4 |
| zpow = zpow |
| result += 0xa184897c363c3 |
| zpow = zpow |
| result += 0xffe5fe2c4586 |
| zpow = zpow |
| result += 0x162c0223a5c8 |
| zpow = zpow |
| result += 0x1b5253d395e |
| zpow = zpow |
| result += 0x1e4cf5158b |
| zpow = zpow |
| result += 0x1e8cac735 |
| zpow = zpow |
| result += 0x1c3bd650 |
| zpow = zpow |
| result += 0x1816193 |
| zpow = zpow |
| result += 0x131496 |
| zpow = zpow |
| result += 0xe1b7 |
| zpow = zpow |
| result += 0x9c7 |
| if (shift >= 0) { |
| if (result >> (256-shift) > 0) |
| return (2 |
| return result << shift; |
| } |
| else |
| return result >> (-shift); |
| } |
|
|
| |
| |
| |
| function ln(uint x) |
| public |
| pure |
| returns (int) |
| { |
| require(x > 0); |
| |
| int ilog2 = floorLog2(x); |
| int z; |
| if (ilog2 < 0) |
| z = int(x << uint(-ilog2)); |
| else |
| z = int(x >> uint(ilog2)); |
| |
| |
| |
| |
| |
| int term = (z - int(ONE)) |
| int halflnz = term; |
| int termpow = term |
| halflnz += termpow / 3; |
| termpow = termpow |
| halflnz += termpow / 5; |
| termpow = termpow |
| halflnz += termpow / 7; |
| termpow = termpow |
| halflnz += termpow / 9; |
| termpow = termpow |
| halflnz += termpow / 11; |
| termpow = termpow |
| halflnz += termpow / 13; |
| termpow = termpow |
| halflnz += termpow / 15; |
| termpow = termpow |
| halflnz += termpow / 17; |
| termpow = termpow |
| halflnz += termpow / 19; |
| termpow = termpow |
| halflnz += termpow / 21; |
| termpow = termpow |
| halflnz += termpow / 23; |
| termpow = termpow |
| halflnz += termpow / 25; |
| return (ilog2 |
| } |
|
|
| |
| |
| |
| function floorLog2(uint x) |
| public |
| pure |
| returns (int lo) |
| { |
| lo = -64; |
| int hi = 193; |
| |
| int mid = (hi + lo) >> 1; |
| while((lo + 1) < hi) { |
| if (mid < 0 && x << uint(-mid) < ONE || mid >= 0 && x >> uint(mid) < ONE) |
| hi = mid; |
| else |
| lo = mid; |
| mid = (hi + lo) >> 1; |
| } |
| } |
|
|
| |
| |
| |
| function max(int[] nums) |
| public |
| pure |
| returns (int maxNum) |
| { |
| require(nums.length > 0); |
| maxNum = -2 |
| for (uint i = 0; i < nums.length; i++) |
| if (nums[i] > maxNum) |
| maxNum = nums[i]; |
| } |
|
|
| |
| |
| |
| |
| function safeToAdd(uint a, uint b) |
| internal |
| pure |
| returns (bool) |
| { |
| return a + b >= a; |
| } |
|
|
| |
| |
| |
| |
| function safeToSub(uint a, uint b) |
| internal |
| pure |
| returns (bool) |
| { |
| return a >= b; |
| } |
|
|
| |
| |
| |
| |
| function safeToMul(uint a, uint b) |
| internal |
| pure |
| returns (bool) |
| { |
| return b == 0 || a |
| } |
|
|
| |
| |
| |
| |
| function add(uint a, uint b) |
| internal |
| pure |
| returns (uint) |
| { |
| require(safeToAdd(a, b)); |
| return a + b; |
| } |
|
|
| |
| |
| |
| |
| function sub(uint a, uint b) |
| internal |
| pure |
| returns (uint) |
| { |
| require(safeToSub(a, b)); |
| return a - b; |
| } |
|
|
| |
| |
| |
| |
| function mul(uint a, uint b) |
| internal |
| pure |
| returns (uint) |
| { |
| require(safeToMul(a, b)); |
| return a |
| } |
|
|
| |
| |
| |
| |
| function safeToAdd(int a, int b) |
| internal |
| pure |
| returns (bool) |
| { |
| return (b >= 0 && a + b >= a) || (b < 0 && a + b < a); |
| } |
|
|
| |
| |
| |
| |
| function safeToSub(int a, int b) |
| internal |
| pure |
| returns (bool) |
| { |
| return (b >= 0 && a - b <= a) || (b < 0 && a - b > a); |
| } |
|
|
| |
| |
| |
| |
| function safeToMul(int a, int b) |
| internal |
| pure |
| returns (bool) |
| { |
| return (b == 0) || (a |
| } |
|
|
| |
| |
| |
| |
| function add(int a, int b) |
| internal |
| pure |
| returns (int) |
| { |
| require(safeToAdd(a, b)); |
| return a + b; |
| } |
|
|
| |
| |
| |
| |
| function sub(int a, int b) |
| internal |
| pure |
| returns (int) |
| { |
| require(safeToSub(a, b)); |
| return a - b; |
| } |
|
|
| |
| |
| |
| |
| function mul(int a, int b) |
| internal |
| pure |
| returns (int) |
| { |
| require(safeToMul(a, b)); |
| return a |
| } |
| } |
|
|
| |
|
|
| |
| |
| contract Proxied { |
| address public masterCopy; |
| } |
|
|
| |
| |
| contract Proxy is Proxied { |
| |
| |
| function Proxy(address _masterCopy) |
| public |
| { |
| require(_masterCopy != 0); |
| masterCopy = _masterCopy; |
| } |
|
|
| |
| function () |
| external |
| payable |
| { |
| address _masterCopy = masterCopy; |
| assembly { |
| calldatacopy(0, 0, calldatasize()) |
| let success := delegatecall(not(0), _masterCopy, 0, calldatasize(), 0, 0) |
| returndatacopy(0, 0, returndatasize()) |
| switch success |
| case 0 { revert(0, returndatasize()) } |
| default { return(0, returndatasize()) } |
| } |
| } |
| } |
|
|
| |
|
|
| |
| pragma solidity ^0.4.21; |
|
|
|
|
| |
| contract Token { |
|
|
| |
| event Transfer(address indexed from, address indexed to, uint value); |
| event Approval(address indexed owner, address indexed spender, uint value); |
|
|
| |
| function transfer(address to, uint value) public returns (bool); |
| function transferFrom(address from, address to, uint value) public returns (bool); |
| function approve(address spender, uint value) public returns (bool); |
| function balanceOf(address owner) public view returns (uint); |
| function allowance(address owner, address spender) public view returns (uint); |
| function totalSupply() public view returns (uint); |
| } |
|
|
| |
|
|
| contract StandardTokenData { |
|
|
| |
| mapping (address => uint) balances; |
| mapping (address => mapping (address => uint)) allowances; |
| uint totalTokens; |
| } |
|
|
| |
| contract StandardToken is Token, StandardTokenData { |
| using Math for |
|
|
| |
| |
| |
| |
| |
| function transfer(address to, uint value) |
| public |
| returns (bool) |
| { |
| if ( !balances[msg.sender].safeToSub(value) |
| || !balances[to].safeToAdd(value)) |
| return false; |
| balances[msg.sender] -= value; |
| balances[to] += value; |
| emit Transfer(msg.sender, to, value); |
| return true; |
| } |
|
|
| |
| |
| |
| |
| |
| function transferFrom(address from, address to, uint value) |
| public |
| returns (bool) |
| { |
| if ( !balances[from].safeToSub(value) |
| || !allowances[from][msg.sender].safeToSub(value) |
| || !balances[to].safeToAdd(value)) |
| return false; |
| balances[from] -= value; |
| allowances[from][msg.sender] -= value; |
| balances[to] += value; |
| emit Transfer(from, to, value); |
| return true; |
| } |
|
|
| |
| |
| |
| |
| function approve(address spender, uint value) |
| public |
| returns (bool) |
| { |
| allowances[msg.sender][spender] = value; |
| emit Approval(msg.sender, spender, value); |
| return true; |
| } |
|
|
| |
| |
| |
| |
| function allowance(address owner, address spender) |
| public |
| view |
| returns (uint) |
| { |
| return allowances[owner][spender]; |
| } |
|
|
| |
| |
| |
| function balanceOf(address owner) |
| public |
| view |
| returns (uint) |
| { |
| return balances[owner]; |
| } |
|
|
| |
| |
| function totalSupply() |
| public |
| view |
| returns (uint) |
| { |
| return totalTokens; |
| } |
| } |
|
|
| |
|
|
| |
| contract TokenFRT is StandardToken { |
| string public constant symbol = "MGN"; |
| string public constant name = "Magnolia Token"; |
| uint8 public constant decimals = 18; |
|
|
| struct unlockedToken { |
| uint amountUnlocked; |
| uint withdrawalTime; |
| } |
|
|
| |
|
|
| address public owner; |
| address public minter; |
|
|
| |
| mapping (address => unlockedToken) public unlockedTokens; |
|
|
| |
| mapping (address => uint) public lockedTokenBalances; |
|
|
| |
|
|
| function TokenFRT( |
| address _owner |
| ) |
| public |
| { |
| require(_owner != address(0)); |
| owner = _owner; |
| } |
|
|
| |
| |
| function updateMinter( |
| address _minter |
| ) |
| public |
| { |
| require(msg.sender == owner); |
| require(_minter != address(0)); |
|
|
| minter = _minter; |
| } |
|
|
| |
| |
| function updateOwner( |
| address _owner |
| ) |
| public |
| { |
| require(msg.sender == owner); |
| require(_owner != address(0)); |
| owner = _owner; |
| } |
|
|
| function mintTokens( |
| address user, |
| uint amount |
| ) |
| public |
| { |
| require(msg.sender == minter); |
|
|
| lockedTokenBalances[user] = add(lockedTokenBalances[user], amount); |
| totalTokens = add(totalTokens, amount); |
| } |
|
|
| |
| function lockTokens( |
| uint amount |
| ) |
| public |
| returns (uint totalAmountLocked) |
| { |
| |
| amount = min(amount, balances[msg.sender]); |
| |
| |
| balances[msg.sender] = sub(balances[msg.sender], amount); |
| lockedTokenBalances[msg.sender] = add(lockedTokenBalances[msg.sender], amount); |
|
|
| |
| totalAmountLocked = lockedTokenBalances[msg.sender]; |
| } |
|
|
| function unlockTokens( |
| uint amount |
| ) |
| public |
| returns (uint totalAmountUnlocked, uint withdrawalTime) |
| { |
| |
| amount = min(amount, lockedTokenBalances[msg.sender]); |
|
|
| if (amount > 0) { |
| |
| lockedTokenBalances[msg.sender] = sub(lockedTokenBalances[msg.sender], amount); |
| unlockedTokens[msg.sender].amountUnlocked = add(unlockedTokens[msg.sender].amountUnlocked, amount); |
| unlockedTokens[msg.sender].withdrawalTime = now + 24 hours; |
| } |
|
|
| |
| totalAmountUnlocked = unlockedTokens[msg.sender].amountUnlocked; |
| withdrawalTime = unlockedTokens[msg.sender].withdrawalTime; |
| } |
|
|
| function withdrawUnlockedTokens() |
| public |
| { |
| require(unlockedTokens[msg.sender].withdrawalTime < now); |
| balances[msg.sender] = add(balances[msg.sender], unlockedTokens[msg.sender].amountUnlocked); |
| unlockedTokens[msg.sender].amountUnlocked = 0; |
| } |
|
|
| function min(uint a, uint b) |
| public |
| pure |
| returns (uint) |
| { |
| if (a < b) { |
| return a; |
| } else { |
| return b; |
| } |
| } |
| |
| |
| |
| |
| function safeToAdd(uint a, uint b) |
| public |
| constant |
| returns (bool) |
| { |
| return a + b >= a; |
| } |
|
|
| |
| |
| |
| |
| function safeToSub(uint a, uint b) |
| public |
| constant |
| returns (bool) |
| { |
| return a >= b; |
| } |
|
|
|
|
| |
| |
| |
| |
| function add(uint a, uint b) |
| public |
| constant |
| returns (uint) |
| { |
| require(safeToAdd(a, b)); |
| return a + b; |
| } |
|
|
| |
| |
| |
| |
| function sub(uint a, uint b) |
| public |
| constant |
| returns (uint) |
| { |
| require(safeToSub(a, b)); |
| return a - b; |
| } |
| } |