// File: BlackList.sol



pragma solidity ^0.7.1;

import './Context.sol';

/**
* @title Contract to process black list that can not transfer token
*/
abstract contract BlackList is Context{
    /**
    * @dev Mapping to check whether `address` is in blacklist or not
     */
    mapping (address => bool) internal _isBlackListed;

    /**
    * @dev Check whether `account` is in blacklist or not
    * @param account account to check
    * @return _isInBlackList internal function
    */
    function isInBlackList(address account) external view returns (bool) {
        return _isInBlackList(account);
    }
    
    /**
    * @dev Add new account to black list by marked is in black list as true 
    */
    function addToBlackList(address account) external onlyOwner {
        _isBlackListed[account] = true;
        emit AddedToBlackList(account);
    }

    /**
    * @dev Remove account from black list by marked is in black list as false 
    */
    function removeFromBlackList (address account) external onlyOwner {
        _isBlackListed[account] = false;
        emit RemovedFromBlackList(account);
    }

    /**
    * @dev Check whether `account` is in blacklist or not
    * @param account account to check
    * @return If in black list => return true; else return false
    */
    function _isInBlackList(address account) internal view returns(bool){
        return _isBlackListed[account];
    }

    //EVENTS
    event AddedToBlackList(address account);
    event RemovedFromBlackList(address account);
}

// SPDX-License-Identifier: MIT
// File: BNUToken.sol



pragma solidity ^0.7.1;

import './SafeMath.sol';
import './ERC20Token.sol';
import './BlackList.sol';

/**
* @title Token that represents the stake in the ByteNext dividend fund
*/ 
contract BNUToken is ERC20Token, BlackList{
    using SafeMath for uint;

    uint internal _eightteenDecimalValue = 1000000000000000000;
    
    //TOKEN ALLOCATIONS
    address public _foundationalReserveAddress;
    address public _rewardsPoolAddress;
    address public _bnuStoreContractAddress;

    /**
     * @dev Generate token information
     * 1. Generate token information
     * 2. Transfer token for funds
     */
    constructor () {
        name = 'ByteNext';
        symbol = 'BNU';
        decimals = 18;
        _totalSupply = uint(200000000).mul(_eightteenDecimalValue);
        
        _foundationalReserveAddress = 0x219c2BF4C8DF6E05131A0f883b333ECd45bC64f6;
        _rewardsPoolAddress = 0x2E366a202e825606eb9158341D3856061BF26e62;
        _bnuStoreContractAddress = 0x4954e0062E0A7668A2FE3df924cD20E6440a7b77;
        
        //Transfer token to funds
        _balances[owner] = _totalSupply;
        _transfer(owner, _foundationalReserveAddress, uint(16000000).mul(_eightteenDecimalValue));          //16M
        _transfer(owner, _rewardsPoolAddress, uint(28439041).mul(_eightteenDecimalValue));                  //28,439,041
        _transfer(owner, _bnuStoreContractAddress, uint(155560959).mul(_eightteenDecimalValue));            //155,560,959 = 51,250,000 + 57,810,959 + 46,500,000
    }

    /**
    * @dev Transfer token `_value` to `_to`
    * 
    * Requirements
    *   Sender and receipent is not in black list
     */
    function transfer(address _to, uint _value) public override virtual contractActive returns(bool){
        require(!_isInBlackList(_msgSender()) && !_isInBlackList(_to), "Black account");
        _transfer(msg.sender, _to, _value);
        return true;
    }

    /**
    * @dev Transfer token `amount` from `sender` to `recipient`
    * 
    * Requirements
    *   Sender and receipent is not in black list
    */
    function transferFrom(address sender, address recipient, uint amount) public virtual override contractActive returns(bool) {
        require(!_isInBlackList(sender) && !_isInBlackList(recipient), "Blocked account");
        return _transferFrom(sender, recipient, amount);
    }
}

// SPDX-License-Identifier: MIT
// File: Context.sol



pragma solidity ^0.7.1;

/**
 * @title Context
 * @dev Provide context functions
 */
abstract contract Context {
    address public owner;            //Contract owner address
    bool public isContractActive;           //Make sure this contract can be used or not
    
    /**
     * Make sure the sender is the owner of contract
     */ 
    modifier onlyOwner{
        require(_msgSender() == owner, "Only owner can process");
        _;
    }
    
    /**
     * Make sure the contract is active to execute
    */ 
    modifier contractActive{
        require(isContractActive, "This contract is deactived");
        _;
    }

    /**
    * @dev Constructor
    * 
    * Implementations:
    *   1. Set the owner of contract
    *   2. Set contract is active
    */
    constructor(){
       owner = _msgSender();           //Set owner address when contract is created
       isContractActive = true;        //Contract is active when it is created
    }

    /**
     * Get sender address
     */ 
    function _msgSender() internal view returns(address){
        return msg.sender;
    }

    /**
     * Get current time in unix timestamp
     */
    function _now() internal view returns(uint){
        return block.timestamp;
    }

    /**
    * Update contract status to make sure this contract can be executed or not
     */
    function setContractStatus(bool status) external onlyOwner{
        require(isContractActive != status,"The current contract's status is the same with updating status");
        isContractActive = status;
    }

    /**
    * @dev Change contract's owner
    * @return If success return true; else return false
    * 
    * Requirements:
    *   1. Only current owner can execute
    *   2. `newOwner` is not zero address
    *   3. `newOwner` is not current owner
    * 
    * Implementations:
    *   1. Validate requirements
    *   2. Set current owner is newOwner
    *   3. Emit Events
    *   4. Return result
    */
    function setOwner(address newOwner) external onlyOwner returns(bool){
        require(newOwner != address(0), "New owner is zero address");
        require(newOwner != owner, "New owner is current owner");

        owner = newOwner;

        emit OwnerChanged(owner);
        return true;
    }

    /**
    * @dev Event that notifies contract's owner has been changed to `newOwner` 
    */
    event OwnerChanged(address newOwner);
}

//SPDX-License-Identifier: MIT
// File: ERC20Token.sol



pragma solidity ^0.7.1;

import './SafeMath.sol';
import './Context.sol';

interface IERC20Token {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint);

    /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, uint amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: 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
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address sender, address recipient, uint amount) external returns (bool);

    /** 
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function burn(address account, uint amount) external;

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint value);
}

abstract contract ERC20Token is IERC20Token, Context {
    using SafeMath for uint;
    
    mapping (address => mapping (address => uint)) internal _allowances;
    mapping (address => uint) internal _balances;
    uint internal _totalSupply;
    
    string public name;
    string public symbol;
    uint public decimals;
    
    function totalSupply() external view override virtual returns (uint){
        return _totalSupply;
    }
    
    function balanceOf(address account) external override virtual view returns (uint){
        return _balances[account];
    }
    
    function transfer(address _to, uint _value) public override virtual contractActive returns(bool){
        _transfer(msg.sender, _to, _value);
        return true;
    }

    function transferFrom(address sender, address recipient, uint amount) public virtual contractActive override returns(bool) {
        return _transferFrom(sender, recipient, amount);
    }

    function approve(address spender, uint value) public virtual override returns(bool) {
        return _approve(_msgSender(), spender, value);
    }

    function allowance(address owner, address spender) public virtual view override returns (uint) {
        return _allowance(owner, spender);
    }

    function burn(address account, uint amount) external virtual override onlyOwner {
        _burn(account, amount);
    }
    
    /**
     * @dev Withdraw ERC-20 token of this contract
     */ 
    function withdrawToken(address tokenAddress) external onlyOwner contractActive{
        require(tokenAddress != address(0), "Contract address is zero address");
        require(tokenAddress != address(this), "Can not transfer self token");
        
        IERC20Token tokenContract = IERC20Token(tokenAddress);
        uint tokenBalance = tokenContract.balanceOf(address(this));
        require(tokenBalance > 0, "Balance is zero");
        
        tokenContract.transfer(owner, tokenBalance);
    }
    
    function _transfer(address sender, address recipient, uint amount) internal {
        require(amount > 0, "Transfer amount should be greater than zero");
        require(_balances[sender] >= amount);
        
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");

        _balances[sender] = _balances[sender].sub(amount);
        _balances[recipient] = _balances[recipient].add(amount);
        emit Transfer(sender, recipient, amount);
    }
    
    function _transferFrom(address sender, address recipient, uint amount) internal returns(bool) {
        require(_allowance(sender, _msgSender()) >= amount, "Allowance is not enough");
        _transfer(sender, recipient, amount);
        _approve(sender,_msgSender(),_allowance(sender, _msgSender()).sub(amount));
        return true;
    }
    
    function _approve(address owner, address spender, uint value) internal returns (bool){
        require(value >= 0,"Approval value can not be negative");
        _allowances[owner][spender] = value;
        emit Approval(owner, spender, value);
        return true;
    }
    
    function _allowance(address owner, address spender) internal view returns (uint) {
        return _allowances[owner][spender];
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint amount) internal virtual returns(bool){
        require(account != address(0), "ERC20: burn from the zero address");

        _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
        _totalSupply = _totalSupply.sub(amount);
        emit Transfer(account, address(0), amount);

        return true;
    }
}

// SPDX-License-Identifier: MIT
// File: SafeMath.sol



pragma solidity ^0.7.1;

/**
 * @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(uint a, uint b) internal pure returns (uint) {
        uint 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(uint a, uint b) internal pure returns (uint) {
        return sub(a, b, "SafeMath: subtraction overflow");
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint a, uint b, string memory errorMessage) internal pure returns (uint) {
        require(b <= a, errorMessage);
        uint 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(uint a, uint b) internal pure returns (uint) {
        // 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-contracts/pull/522
        if (a == 0) {
            return 0;
        }

        uint 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(uint a, uint b) internal pure returns (uint) {
        return div(a, b, "SafeMath: division by zero");
    }

    /**
     * @dev Returns the integer division of two unsigned integers. Reverts with custom message 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(uint a, uint b, string memory errorMessage) internal pure returns (uint) {
        require(b > 0, errorMessage);
        uint 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(uint a, uint b) internal pure returns (uint) {
        return mod(a, b, "SafeMath: modulo by zero");
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * Reverts with custom message 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(uint a, uint b, string memory errorMessage) internal pure returns (uint) {
        require(b != 0, errorMessage);
        return a % b;
    }
}
//SPDX-License-Identifier: MIT