contract Treasury is Ownable{

 address public _hexLotto;
 address token;
 
 constructor () public {
        token = address(0x2b591e99afE9f32eAA6214f7B7629768c40Eeb39); //HEX token
        _hexLotto = address(0xFAA2919aC89975ca7FB2B8326e9393f56de5F28B);
    }

    function setHexLottoContract(address newHexLotto) external onlyOwner{
        require(newHexLotto != address(0), "HexLotto is the zero address");
        _hexLotto = newHexLotto;
    }

     /**
     * @dev Throws if called by any account other than the hex lotto contract.
     */
    modifier onlyHexLotto() {
        require(msg.sender == _hexLotto, "Caller is not the hex lotto contract");
        _;
    }

    /**
     * @dev Withdraw remaining treasury amount to another wallet
     */
    function withdraw(address to) external onlyOwner returns(bool) {
        require(ERC20(token).balanceOf(address(this)) > 0, "Balance is empty");
        require(to != address(0), "Can not withdraw to zero address");

        require(ERC20(token).transfer(to, ERC20(token).balanceOf(address(this))), "Withdrawal of treasury failed");
        return true;
    }

    /**
     * @dev Throws if called by any account other than the hex lotto contract.
     */
    function transfer(address to, uint256 amount) external onlyHexLotto returns(bool){ 
       require(ERC20(token).transfer(to, amount), "Transfer bonus amount failed");
       return true;
    }
}
function withdraw(address to) external onlyOwner returns(bool) {
    require(ERC20(token).balanceOf(address(this)) > 0, "Balance is empty");
    require(to != address(0), "Can not withdraw to zero address");

    require(ERC20(token).transfer(to, ERC20(token).balanceOf(address(this))), "Withdrawal of treasury failed");
    return true;
}

/**
 * @dev Withdraw remaining treasury amount to another wallet
 */