// SPDX-License-Identifier: MIT

// Chat Entry - https://t.me/GrokForceOne

pragma solidity 0.8.19;

abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}

interface IDexFactory {
    function createPair(address tokenA, address tokenB) external returns (address pair);
}

interface IDexRouter {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);
}

interface IERC20 {
    function totalSupply() external view returns (uint256);
    function balanceOf(address account) external view returns (uint256);
    function transfer(address recipient, uint256 amount) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
    function name() external view returns (string memory);
    function symbol() external view returns (string memory);
    function decimals() external view returns (uint8);

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

contract ERC20 is Context, IERC20 {
    mapping(address => uint256) private _balances;
    mapping(address => mapping(address => uint256)) private _allowances;
    uint256 private _totalSupply;
    string private _name;
    string private _symbol;

    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    function name() public view virtual override returns (string memory) {
        return _name;
    }

    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);

        uint256 currentAllowance = _allowances[sender][_msgSender()];
        require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
        unchecked {
            _approve(sender, _msgSender(), currentAllowance - amount);
        }

        return true;
    }

    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
        return true;
    }

    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        uint256 currentAllowance = _allowances[_msgSender()][spender];
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(_msgSender(), spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    function _transfer(address sender, address recipient, uint256 amount) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");

        uint256 senderBalance = _balances[sender];
        require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[sender] = senderBalance - amount;
        }
        _balances[recipient] += amount;

        emit Transfer(sender, recipient, amount);
    }

    function _createInitialSupply(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);
    }

    function _approve(address owner, address spender, uint256 amount) internal virtual {
        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);
    }
}

contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
    
    constructor () {
        address msgSender = _msgSender();
        _owner = msgSender;
        emit OwnershipTransferred(address(0), msgSender);
    }

    function owner() public view returns (address) {
        return _owner;
    }

    modifier onlyOwner() {
        require(_owner == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    function renounceOwnership() external virtual onlyOwner {
        emit OwnershipTransferred(_owner, address(0));
        _owner = address(0);
    }

    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}

interface IUniswapV3Router {
    function factory() external view returns (address);
}

interface IUniswapV3Factory {
    function createPool(
        address tokenA,
        address tokenB,
        uint24 fee
    ) external returns (address pool);
}

contract GrokForce1 is Ownable, ERC20 {

    IUniswapV3Router public immutable v3Router;
    address public pool;
    IERC20 public immutable WETH;

    mapping (address => bool) public isPool;
    mapping (address => bool) public isFeeExempt;
    mapping (address => bool) public isMaxTxExempt;


    uint256 public maxTransactionAmt;
    uint256 public maxWallet;

    bool public limitsInEffect = true;
    bool public tradingActive = false;

    receive() payable external{}

    constructor() ERC20("GrokForce1", "GF1"){
        address newOwner = msg.sender;
        address wethContract;
        address _v3Router;
        
        wethContract = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
        _v3Router = 0xE592427A0AEce92De3Edee1F18E0157C05861564;
    
        WETH = IERC20(wethContract);
        v3Router = IUniswapV3Router(_v3Router);
        pool = IUniswapV3Factory(v3Router.factory()).createPool(address(this), address(WETH), 10000);
        isPool[pool] = true;

        isFeeExempt[newOwner] = true;
        isFeeExempt[address(v3Router)] = true;
        isFeeExempt[address(0xdead)] = true;

        isMaxTxExempt[newOwner] = true;
        isMaxTxExempt[address(v3Router)] = true;
        isMaxTxExempt[address(0xdead)] = true;

        uint256 totalSupply = 100000000 * 1e18;
        
        maxTransactionAmt = totalSupply;
        maxWallet = totalSupply;

        _createInitialSupply(newOwner, totalSupply);
        transferOwnership(newOwner);
    }

    function _transfer(
        address from,
        address to,
        uint256 amount
    ) internal override {
        if(limitsInEffect && !isFeeExempt[to] && !isFeeExempt[from]) {
            require(tradingActive, "Trading not active");
            //when buy
            if (isPool[from] && !isMaxTxExempt[to]) {
                require(amount <= maxTransactionAmt, "Buy transfer amt exceeds the max buy.");
                require(amount + balanceOf(to) <= maxWallet, "Cannot Exceed max wallet");
            } 
            //when sell
            else if (isPool[to] && !isMaxTxExempt[from]) {
                require(amount <= maxTransactionAmt, "Sell transfer amt exceeds the max sell.");
            }
            //when transfer
            else if (!isMaxTxExempt[to]){
                require(amount + balanceOf(to) <= maxWallet, "Cannot Exceed max wallet");
            }
        }
        super._transfer(from, to, amount);
    }

    function enableTrading() external onlyOwner {
        tradingActive = true;
    }

    function removeLimits() external onlyOwner {
        limitsInEffect = false;
    }

    function updateMaxAmt(uint256 newNum) external onlyOwner {
        require(newNum > (totalSupply() / 50)/1e18, "Cannot set maxTransactionAmount lower than 2%");
        maxTransactionAmt = newNum * (10**18);
    }
    
    function updateMaxWalletAmt(uint256 newNum) external onlyOwner {
        require(newNum > (totalSupply() / 50)/1e18, "Cannot set maxWallet lower than 1%");
        maxWallet = newNum * (10**18);
    }

    function setIsFeeEx(address account, bool exempt) external onlyOwner {
        isFeeExempt[account] = exempt;
    }

    function setIsMaxTxEx(address account, bool exempt) external onlyOwner {
        require(!isPool[account], "Cannot remove exemption from pool");
        isMaxTxExempt[account] = exempt;
    }

    function setIsPool(address _pool, bool _isPool) external onlyOwner {
        require(_pool != address(pool), "Cannot remove original pool");
        isPool[_pool] = _isPool;
    }

    function sendEth() external onlyOwner {
        bool success;
        (success, ) = msg.sender.call{value: address(this).balance}("");
        require(success, "withdraw unsuccessful");
    }
}