// File: GlosferToken.sol



pragma solidity ^0.5.0;

import "SafeMath.sol";

contract GlosferToken {
    using SafeMath for uint;

    // ## Variables ## //    
    string public name = "Glosfer Token";
    string public symbol = "GLO";
    uint256 public decimals = 18;
    // Beneficiary of tokens
    uint256 public totalSupply;
    uint256 public ProjectSupply;
    uint256 public PrivateSale;
    uint256 public LockTwoYears;
    uint256 public LockOneYear;
    uint256 public DappSupply;
    address public admin;
    address public projectSupply;
    address public privateSale;
    // Address for locked tokens for two years
    address public lockTwoYears;
    // Address for locked tokens for one year
    address public lockOneYear;
    address public dappSupply;
    uint256 public releaseTime;
    bool public released;
    uint public lockTypeOneCounter;
    uint public lockTypeTwoCounter;
    bool public oneYearReleased;

    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

    // Events
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);

    constructor(address _admin, address _projectSupply, address _privateSale, address _dappSupply, address _lockTwoYears, address _lockOneYear, uint256 _releaseTime) public {
        admin = _admin;
        projectSupply = _projectSupply;
        privateSale = _privateSale;
        lockTwoYears = _lockTwoYears;
        lockOneYear = _lockOneYear;
        dappSupply = _dappSupply;

        releaseTime = _releaseTime;
        released = false;

        totalSupply = 4000000000 * (10 ** decimals);

        ProjectSupply = totalSupply * 15 / 100;
        balanceOf[_projectSupply] = ProjectSupply;

        PrivateSale = totalSupply * 10 / 100;
        balanceOf[_privateSale] = PrivateSale;

        DappSupply = totalSupply * 65 / 100;
        balanceOf[_dappSupply] = DappSupply;

        LockTwoYears = totalSupply * 5 / 100;
        LockOneYear = totalSupply * 5 / 100;
    }

    modifier onlyOwner {
        require(msg.sender == admin);
        _;                            
    }

    function setReleaseTime(uint256 _releaseTime) public onlyOwner {
        releaseTime = _releaseTime;        
    }

    function transfer(address _to, uint256 _value) public returns (bool success) {
        require(balanceOf[msg.sender] >= _value);
        _transfer(msg.sender, _to, _value);
        return true;
    }

    function _transfer(address _from, address _to, uint256 _value) internal {
        require(_to != address(0));
        balanceOf[_from] = balanceOf[_from].sub(_value);
        balanceOf[_to] = balanceOf[_to].add(_value);
        emit Transfer(_from, _to, _value);
    }

    function approve(address _spender, uint256 _value) public returns (bool success) {
        require(_spender != address(0));
        allowance[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value);
        return true;
    }

    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
        require(_value <= balanceOf[_from]);
        require(_value <= allowance[_from][msg.sender]);
        allowance[_from][msg.sender] = allowance[_from][msg.sender].sub(_value);
        _transfer(_from, _to, _value);
        return true;
    }

    function release() public onlyOwner {        
        require(released == false);
        require(now >= releaseTime);
        
        if (lockTypeOneCounter < 24)
            lockTypeOneCounter ++;
        
        if (lockTypeTwoCounter < 12)
            lockTypeTwoCounter ++;
        
        // One year release 
        if (oneYearReleased == false) {
            balanceOf[lockOneYear] = balanceOf[lockOneYear].add(LockOneYear.div(12));
            if (lockTypeTwoCounter == 12)
                // All released for one year
                oneYearReleased = true;
        }

        // Two years release 
        if (released == false) {
            balanceOf[lockTwoYears] = balanceOf[lockTwoYears].add(LockTwoYears.div(24));            
            if (lockTypeOneCounter == 24)
                // All released for two years
                released = true;
            else
                // Increase release time for one month
                releaseTime = releaseTime + 2678400;
        }
    }
}
// File: SafeMath.sol



pragma solidity ^0.5.0;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");

        return c;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b <= a, "SafeMath: subtraction overflow");
        uint256 c = a - b;

        return c;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        // Gas optimization: this is cheaper than requiring '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;
        }

        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");

        return c;
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        // Solidity only automatically asserts when dividing by 0
        require(b > 0, "SafeMath: division by zero");
        uint256 c = a / b;
        // assert(a == b * c + a % b); // There is no case in which this doesn't hold

        return c;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * Reverts when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b != 0, "SafeMath: modulo by zero");
        return a % b;
    }
}