contract BlockonixToken is IERC20, Ownable, Vestable, HasAddresses, VestingPeriods, IsUpgradable {
    
    using SafeMathLib for uint256;
    
    uint256 public constant totalTokenSupply = 1009208335 * 10**16;    // Total Supply:10,092,083.35

    uint256 public burntTokens;

    string public constant name = "Blockonix";    // Blockonix
    string public constant symbol = "BDT";  // BDT
    uint8 public constant decimals = 18;            

    mapping (address => uint256) public balances;
    mapping(address => mapping(address => uint256)) approved;
    
    event Upgraded(address _owner, uint256 amount); 
    constructor() public {
        
        uint256 lockedTokenPerAddress = 280335648611111000000000;   // Total Founder Tokens(LOCKED): 2,523,020.8375, divided equally in 9 chunks
        balances[founder1FirstLockup] = lockedTokenPerAddress;
        balances[founder2FirstLockup] = lockedTokenPerAddress;
        balances[founder3FirstLockup] = lockedTokenPerAddress;
        balances[founder1SecondLockup] = lockedTokenPerAddress;
        balances[founder2SecondLockup] = lockedTokenPerAddress;
        balances[founder3SecondLockup] = lockedTokenPerAddress;
        balances[founder1ThirdLockup] = lockedTokenPerAddress;
        balances[founder2ThirdLockup] = lockedTokenPerAddress;
        balances[founder3ThirdLockup] = lockedTokenPerAddress;

        emit Transfer(address(this), founder1FirstLockup, lockedTokenPerAddress);
        emit Transfer(address(this), founder2FirstLockup, lockedTokenPerAddress);
        emit Transfer(address(this), founder3FirstLockup, lockedTokenPerAddress);
        
        emit Transfer(address(this), founder1SecondLockup, lockedTokenPerAddress);
        emit Transfer(address(this), founder2SecondLockup, lockedTokenPerAddress);
        emit Transfer(address(this), founder3SecondLockup, lockedTokenPerAddress);

        emit Transfer(address(this), founder1ThirdLockup, lockedTokenPerAddress);
        emit Transfer(address(this), founder2ThirdLockup, lockedTokenPerAddress);
        emit Transfer(address(this), founder3ThirdLockup, lockedTokenPerAddress);


        addVestingAddress(founder1FirstLockup, firstLockup);
        addVestingAddress(founder2FirstLockup, firstLockup);
        addVestingAddress(founder3FirstLockup, firstLockup);

        addVestingAddress(founder1SecondLockup, secondLockup);
        addVestingAddress(founder2SecondLockup, secondLockup);
        addVestingAddress(founder3SecondLockup, secondLockup);

        addVestingAddress(founder1ThirdLockup, thirdLockup);
        addVestingAddress(founder2ThirdLockup, thirdLockup);
        addVestingAddress(founder3ThirdLockup, thirdLockup);

    }

    function burn(uint256 _value) public {
        require (balances[msg.sender] >= _value);                 // Check if the sender has enough
        balances[msg.sender] = balances[msg.sender].minus(_value);
        burntTokens += _value;
        emit BurnToken(msg.sender, _value);
    } 

    
    function totalSupply() view public returns (uint256 _totalSupply) {
        return totalTokenSupply - burntTokens;
    }
    
    function balanceOf(address _owner) view public returns (uint256 balance) {
        return balances[_owner];
    }
    
    /* Internal transfer, only can be called by this contract */
    function _transfer(address _from, address _to, uint256 _value) internal {
        require (_to != 0x0);                               // Prevent transfer to 0x0 address. Use burn() instead
        require (balances[_from] >= _value);                 // Check if the sender has enough
        require (balances[_to] + _value > balances[_to]);   // Check for overflows
        balances[_from] = balances[_from].minus(_value);    // Subtract from the sender
        balances[_to] = balances[_to].plus(_value);         // Add the same to the recipient
        emit Transfer(_from, _to, _value);
    }

    /**
     * @notice Send `_value` tokens to `_to` from your account
     * @param _to The address of the recipient
     * @param _value the amount to send
     */
    function transfer(address _to, uint256 _value) public returns (bool success){
        require(checkVestingCondition(msg.sender));
        _transfer(msg.sender, _to, _value);
        return true;
    }
    
    /**
     * @notice Send `_value` tokens to `_to` on behalf of `_from`
     * @param _from The address of the sender
     * @param _to The address of the recipient
     * @param _value the amount to send
     */
    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
        require(checkVestingCondition(_from));
        require (_value <= approved[_from][msg.sender]);     // Check allowance
        approved[_from][msg.sender] = approved[_from][msg.sender].minus(_value);
        _transfer(_from, _to, _value);
        return true;
    }
    
    /**
     * @notice Approve `_value` tokens for `_spender`
     * @param _spender The address of the sender
     * @param _value the amount to send
     */
    function approve(address _spender, uint256 _value) public returns (bool success) {
        require(checkVestingCondition(_spender));
        if(balances[msg.sender] >= _value) {
            approved[msg.sender][_spender] = _value;
            emit Approval(msg.sender, _spender, _value);
            return true;
        }
        return false;
    }
        
    /**
     * @notice Check `_value` tokens allowed to `_spender` by `_owner`
     * @param _owner The address of the Owner
     * @param _spender The address of the Spender
     */
    function allowance(address _owner, address _spender) view public returns (uint256 remaining) {
        return approved[_owner][_spender];
    }
        
    event Transfer(address indexed _from, address indexed _to, uint256 _value);
    
    event Approval(address indexed _owner, address indexed _spender, uint256 _value);

    event BurnToken(address _owner, uint256 _value);
    
     /**
     * Upgrade function, requires the owner to first approve tokens equal to their old token balance to this address 
     *
     */
    function upgrade() external {
        require(now <=upgradeDeadline);
        uint256 balance = oldToken.balanceOf(msg.sender);
        require(balance>0);
        oldToken.transferFrom(msg.sender, oldTokenBurnAddress, balance);
        balances[msg.sender] += balance;
        emit Transfer(this, msg.sender, balance);
        emit Upgraded(msg.sender, balance);
    }

}
/**
 * @title BlockonixToken Token
 * @notice The ERC20 Token.
 */
function _transfer(address _from, address _to, uint256 _value) internal {
    require (_to != 0x0);                               // Prevent transfer to 0x0 address. Use burn() instead
    require (balances[_from] >= _value);                 // Check if the sender has enough
    require (balances[_to] + _value > balances[_to]);   // Check for overflows
    balances[_from] = balances[_from].minus(_value);    // Subtract from the sender
    balances[_to] = balances[_to].plus(_value);         // Add the same to the recipient
    emit Transfer(_from, _to, _value);
}

/* Internal transfer, only can be called by this contract */