// File: Context.sol



// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/*
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with GSN meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address payable) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes memory) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}

// File: IERC20.sol



pragma solidity >=0.5.0;

interface IERC20 {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);
    event TransferTaxes(address indexed from, address indexed to, uint256 value);

    function name() external view returns (string memory);
    function symbol() external view returns (string memory);
    function decimals() external view returns (uint8);
    function totalSupply() external view returns (uint);
    function balanceOf(address owner) external view returns (uint);
    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint value) external returns (bool);
    function transfer(address to, uint value) external returns (bool);
    function transferFrom(address from, address to, uint value) external returns (bool);
}

// File: SafeMath.sol



// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.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) {
        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(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        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-contracts/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) {
        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(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        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) {
        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(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b != 0, errorMessage);
        return a % b;
    }
}

// File: SQNK.sol



// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;

import "./Context.sol";
import "./IERC20.sol";
import "./SafeMath.sol";

// import "hardhat/console.sol";

contract SQNK is Context, IERC20 {
  using SafeMath for uint256;

  mapping (address => uint256) private _balances;
  mapping(address => bool) minters;
  mapping(address => bool) public admins;
  mapping (address => mapping (address => uint256)) private _allowances;
  mapping (address => bool) private excludedFromTax;

  uint private MARKETING_TAX = 3;
  uint private REWARD_TAX = 6;
  uint private LIQUIDITY_TAX = 1;

  uint256 private _totalSupply;
  string private _name;
  string private _symbol;
  uint8 private _decimals = 18;
  bool private taxEnabled = true;
  address public owner;
  address private _rewardWallet;
  address private _marketingWallet;
  address private sqnetAddress;

  event TransferTaxes(address indexed from, address indexed to, uint256 value);

  constructor(
    string memory name_, 
    string memory symbol_,
    address marketingWallet_, 
    address rewardWallet_,
    address _owner
  ) public {
    _name = name_;
    _symbol = symbol_;
    owner = msg.sender;
    _marketingWallet = marketingWallet_;
    _rewardWallet = rewardWallet_;
    setAdmin(msg.sender, true);
    setMinter(msg.sender, true);
    _mint(_owner, 100e9 * (10 ** uint256(decimals())));
  }

  modifier onlyOwner() {
    require(msg.sender == owner, 'Only owner');
    _;
  }

  modifier onlyMinter() {
    require(minters[msg.sender] == true, 'Only minter');
    _;
  }

  modifier onlyAdmin() {
    require(admins[msg.sender] == true, 'Only admin');
    _;
  }

  function transferOwnership (address _address) public onlyOwner {
		owner = _address;
	}

  function setExcludedFromTax (address _address, bool _status) public onlyOwner {
    excludedFromTax[_address] = _status;
  }

  function getExcludedFromTax (address _address) public view returns (bool) {
    return excludedFromTax[_address];
  }

  function setSqnetAddress(address _address) public onlyOwner {
    setAdmin(sqnetAddress, false);
    sqnetAddress = _address;
    setAdmin(sqnetAddress, true);
  }

  function getTaxes() public view returns(uint, uint, uint) {
    return (MARKETING_TAX, REWARD_TAX, LIQUIDITY_TAX);
  }

  function marketingWallet() public view returns(address) {
    return _marketingWallet;
  }

  function rewardWallet() public view returns(address) {
    return _rewardWallet;
  }

  function setMarketingWallet(address _address) public onlyOwner {
    _marketingWallet = _address;
  }

  function setRewardWallet(address _address) public onlyOwner {
    _rewardWallet = _address;
  }

  function setTaxes(uint marketingTax, uint rewardTax, uint liquidityTax) public onlyOwner {
    MARKETING_TAX = marketingTax;
    REWARD_TAX = rewardTax;
    LIQUIDITY_TAX = liquidityTax;
  }

  function setMinter(address _address, bool status) public onlyAdmin {
    minters[_address] = status;
  }

  function setAdmin(address _address, bool status) public onlyOwner {
    admins[_address] = status;
  }

  function setTaxEnabled(bool status) public onlyAdmin {
    taxEnabled = status;
  }

  function handleTaxes(address sender, uint256 amount) internal returns(uint amountAfterTaxes) {
    uint marketingWalletTax = amount * (MARKETING_TAX + LIQUIDITY_TAX) / 100;
    uint rewardWalletTax = amount * REWARD_TAX / 100;
    transferTaxesFrom(sender, _marketingWallet, marketingWalletTax);
    transferTaxesFrom(sender, _rewardWallet, rewardWalletTax);
    amountAfterTaxes = amount - marketingWalletTax - rewardWalletTax;
  }

  function transferTaxesFrom(address from, address to, uint value) public {
    require(from != address(0), "ERC20: transfer from the zero address");
    require(to != address(0), "ERC20: transfer to the zero address");
    changeBalanceOnTransfer(from, to, value);
    emit TransferTaxes(from, to, value);
  }

  function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
    if (excludedFromTax[sender]) {
      taxEnabled = false;
    }
    _transfer(sender, recipient, amount);
    _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
    return true;
  }

  function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
    _transfer(_msgSender(), recipient, amount);
    return true;
  }

  function _transfer(address sender, address recipient, uint256 amount) internal {
    require(sender != address(0), "ERC20: transfer from the zero address");
    require(recipient != address(0), "ERC20: transfer to the zero address");
    uint amountAfterTaxes;

    if (sender == _marketingWallet || sender == _rewardWallet || sender == owner || sender == sqnetAddress || excludedFromTax[sender] || excludedFromTax[recipient]) {
      taxEnabled = false;
    }

    if (taxEnabled) {
      amountAfterTaxes = handleTaxes(sender, amount);
    } else {
      amountAfterTaxes = amount;
    }

    changeBalanceOnTransfer(sender, recipient, amountAfterTaxes);

    if (!taxEnabled) {
      taxEnabled = true;
    }

    emit Transfer(sender, recipient, amountAfterTaxes);
  }

  function changeBalanceOnTransfer(address sender, address recipient, uint amount) internal {
    _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
    _balances[recipient] = _balances[recipient].add(amount);
  }

  function name() public override view returns (string memory) {
    return _name;
  }

  function symbol() public override view returns (string memory) {
    return _symbol;
  }

  function decimals() public override view returns (uint8) {
    return _decimals;
  }

  function totalSupply() public view override returns (uint256) {
    return _totalSupply;
  }

  function balanceOf(address account) public view override returns (uint256) {
    return _balances[account];
  }

  function allowance(address _owner, address spender) public view virtual override returns (uint256) {
    return _allowances[_owner][spender];
  }

  function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
    _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
    return true;
  }

  function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
    _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
    return true;
  }

  function approve(address spender, uint256 amount) public virtual override returns (bool) {
    _approve(_msgSender(), spender, amount);
    return true;
  }

  function approveMarketingWallet(uint amount) public {
    require(msg.sender == sqnetAddress, 'Only SQNET');
    _approve(_marketingWallet, sqnetAddress, amount);
  }

  function approveRewardWallet(uint amount) public {
    require(msg.sender == sqnetAddress, 'Only SQNET');
    _approve(_rewardWallet, sqnetAddress, amount);
  }

  function _approve(address _owner, address spender, uint256 amount) internal {
    require(_owner != address(0), "ERC20: approve from the zero address");
    require(spender != address(0), "ERC20: approve to the zero address");
    _allowances[_owner][spender] = amount;
    emit Approval(_owner, spender, amount);
  }

  function mint(address to, uint amount) public onlyMinter {
    require(to != address(0), 'Empty address');
    require(amount > 0, 'No amount');
    _mint(to, amount);
  }

  function _mint(address account, uint256 amount) internal {
    require(account != address(0), "ERC20: mint to the zero address");

    _totalSupply = _totalSupply.add(amount);
    _balances[account] = _balances[account].add(amount);
    emit Transfer(address(0), account, amount);
  }

  function _burn(address account, uint256 amount) internal {
    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);
  }

  function _setupDecimals(uint8 decimals_) internal onlyOwner {
    _decimals = decimals_;
  }
}