//SPDX-License-Identifier: MIT
/*
   ░ ░ ░ ░ ░     ░             ░ ░ ░   ░   ░       ░           ░ ░ ░ ░     ░ ░  
░ ░   ░ ░       ░               ░ ░ ░ ░ ░     ░   ░           ░ ░   ░ ░   ░ ░ ░ 
 ░ ░ ░   ░       ░  ▒░░░░░░        ░   ░   ░         ░░░░░░░░    ░ ░ ░   ░   ░  
░ ░   ░ ░ ░   ░    ░███████▓▒       ░   ░     ░     ▒▓▓▓▓▓▓▓▒   ░ ░ ░ ░     ░   
           ░ ░ ░ ░ ░▓█▓▓▓▓▓▓█▓░      ░ ░ ░ ░      ▒▓▓▓▒▒▒▒▒▓▒  ░ ░   ░ ░ ░ ░   ░
░ ░   ░   ░   ░ ░    ▒▓▓▓▓▓▓▓▓█▓░         ░     ▒▓▓▓▓▒▒▒▓▓▒░    ░ ░ ░ ░ ░ ░ ░ ░ 
 ░ ░ ░   ░ ░   ░       ▒▓█▓▓▓▓▓██▓░           ▒▓▓▓▓▓▒▓▓▓▒░     ░ ░   ░ ░ ░ ░ ░ ░
░   ░         ░ ░  ░░    ▒█▓▓▓▓▓▓▓█▓░       ▒▓█▓▓▓▓▓▓▓▓░            ░   ░ ░ ░   
       ░ ░   ░     ░█▓     ▒██▓▓▓▓▓██▓░   ▒▓█▓▓▓▓▓▓▓▓▒     ░▓    ░   ░ ░ ░ ░ ░ ░
░   ░ ░ ░ ░ ░ ░     ███▒    ░▒██▓▓▓▓▓██▒▒▓█▓▓▓▓▓▓▓▓▒      ▓██   ░ ░   ░   ░ ░ ░ 
 ░ ░   ░ ░ ░ ░      ▓▓▓██▓    ░▓██▓▓▓▓▓██▓▓▓▓▓▓█▓▒      ▓████    ░     ░ ░ ░ ░ ░
░ ░ ░   ░ ░ ░   ░   ▓▓▓▓▓█▒     ░▓██▓▓▓▓▓▓▓▓▓█▓▒      ▓██████   ░       ░ ░ ░ ░ 
 ░ ░         ░ ░    ▓▓▓▓▓█▒       ░▓██▓▓▓▓▓██▒     ░▓████████        ░   ░ ░   ░
░   ░ ░   ░ ░ ░     ▓▓▓▓▓█▒         ░▓█▓▓██▒     ░▓██████████     ░       ░ ░ ░ 
   ░ ░ ░ ░   ░ ░    ▓▓▓▓▓█▒           ░▓█▓     ░▓█████▓██████  ░ ░ ░     ░ ░   ░
░   ░ ░ ░ ░ ░   ░   ▓▓▓▓▓▓▒     ░ ░     ░    ░███████░ ▓█████   ░ ░ ░ ░     ░   
 ░ ░ ░ ░ ░   ░ ░    ▓▓▓▓▓█▒    ░ ░         ▒██████▓▒   ██████    ░   ░ ░ ░ ░ ░  
░ ░ ░ ░ ░           ▓▓▓▓▓▓▒   ░   ░ ░    ▒███████      ██████     ░ ░ ░ ░ ░ ░ ░ 
 ░   ░ ░ ░ ░       ░▓▓▓▓▓█▒    ░ ░ ░     ░▓██████▓     ██████    ░ ░     ░   ░ ░
░ ░ ░ ░ ░ ░ ░ ░ ░   ▓▓▓▓▓▓▒   ░ ░ ░ ░       ▒██████▓░  ██████   ░   ░ ░   ░ ░   
 ░ ░ ░ ░ ░ ░ ░ ░   ░▓▓▓▓▓▓▒    ░   ░   ░      ▓██████▓ ██████    ░   ░ ░   ░ ░  
░     ░ ░ ░ ░      ░▓▓▓▓▓▓▒       ░ ░ ░     ░▓██████▒  ██████   ░ ░   ░       ░ 
         ░   ░ ░   ░▓▓▓▓▓▓▒  ░   ░ ░      ░███████░    ██████      ░ ░ ░ ░   ░ ░
░ ░ ░     ░ ░   ░    ░▓▓▓▓▒   ░   ░     ▒██████▓░      █████▒     ░   ░ ░   ░   
 ░   ░ ░ ░ ░ ░ ░ ░     ▒▓█▒  ░   ░    ▒███████░        ██▓░      ░ ░ ░ ░   ░ ░ ░
░   ░ ░   ░   ░          ▒▒         ▒███████░          ▓▒     ░ ░ ░ ░ ░   ░     
 ░   ░   ░   ░   ░   ░              ░            ░ ░         ░ ░ ░
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▒▒▒▒▒▒▒▓▓▓▒▒▒▒▒▒▒▒▒▒▒▓▒▒▒▓▓▓▓▒▒▒▒▒▒▒▓▓▓▒▒▒▒▒▒▒▓▓▓▒▒▒▓▒▒▒▒▒▓▒▒▒
▓█▓▒▒▒▒▒██▒▒▓███████▒▒▒███████▒▒██▓▒▒▒▓█▒▒███████▒▒▓██████▓▒▒▓██████▓▒█▓▒▒▓██▒▒▒
▓██▓▒▒▒███▒▒██▒▒▒▒▒██▒██▒▒▒▒▒██▒████▒▒▓█▒▒██▒▒▒░█▓▓█▓▒▒▒▒▓█▓▒██▒▒▒▒▒▒▒█▓▒██▓▒▒▒▒
▓█▒█▓▒██▓█▒██▒▒▒▒▒▒▓█▒█▒▒▒▒▒▒▓█▒██░██▓▓█▒▒██▓▓▓██▒██▒▒▒▒▒▒██▓█▒▒▒▒▒▒▒▒████▓▒▒▒▒▒
▓█▒▒███▒▓█▒▒██▒▒▒▒▓██▒██▒▒▒▒▒██▒██▒▒▓███▒▒██████▒▒▓█▓▒▒▒▒▓█▓▒██▒▒▒▒▓▒▒██▒▓██▒▒▒▒
▓█▒▒▒█▒▒▓█▒▒▒███████▒▒▒███████▒▒██▒▒▒▒██▒▒██▒▒▒██▓▒▓██████▓▒▒▒██████▓▒█▓▒▒▒██▓▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▒▒▒▒▒▒▒▒▓▓▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▒▒▒▒▒▓▓▒▒▒▒▒▒▒▒▓▓▓▒▒▒▓▒▒▒▒▒▓▓▒▒
            Written, deployed & Migrated by Krakovia (@karola96)
 */
// o/
pragma solidity 0.8.13;
//interfaces
interface IUniswapV2Factory {
    function createPair(address tokenA, address tokenB) external returns (address pair);
}
interface IUniswapV2Router02 {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
}
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);
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
}
interface IERC20Metadata is IERC20 {
    function name() external view returns (string memory);
    function symbol() external view returns (string memory);
    function decimals() external view returns (uint8);
}
// contracts
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }
    function _msgData() internal view virtual returns (bytes calldata) {
        this;
        return msg.data;
    }
}
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() public 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;
    }
    
    function getTime() public view returns (uint256) {
        
        return block.timestamp;
    }
}
// main contract
contract moonrock is Context, IERC20, Ownable {

//custom
    IUniswapV2Router02 public uniswapV2Router;
//string
    string private _name = "MoonRock";
    string private _symbol = "ROCK";
//bool
    bool public moveEthToWallets = true;
    bool public TakeEthForFees = true;
    bool public swapAndLiquifyEnabled = true;
    bool public blockMultiBuys = true;
    bool public marketActive = false;
    bool private isInternalTransaction = false;
    bool public vestingActive = true;
//address
    address public uniswapV2Pair;
    address public _MarketingWalletAddress = 0x9151D7B75601E8407049F3642365629e24d8f13d;
    address public _DevelopmentWalletAddress = 0xc040621C8853d1E5fF74f891F976168d39Ba29aA;
    address public _InvfundWalletAddress = 0x03c754661A0B30E01768D612328d95938716Cd31;
    address[] private _excluded;
//uint
    uint public buyReflectionFee = 4;
    uint public sellReflectionFee = 4;
    uint public buyMarketingFee = 2;
    uint public sellMarketingFee = 2;
    uint public buyDevelopmentFee = 2;
    uint public sellDevelopmentFee = 2;
    uint public buyInvfundFee = 2;
    uint public sellInvfundFee = 2;
    uint public buyFee = buyReflectionFee + buyMarketingFee + buyDevelopmentFee + buyInvfundFee;
    uint public sellFee = sellReflectionFee + sellMarketingFee + sellDevelopmentFee + sellInvfundFee;
    uint public buySecondsLimit = 5;
    uint public minimumTokensBeforeSwap;
    uint public tokensToSwap;
    uint public intervalSecondsForSwap = 60;
    uint public minimumWeiForTokenomics = 1 * 10**16; // 0.01 ETH
    uint private startTimeForSwap;
    uint private MarketActiveAt;
    uint private constant MAX = ~uint256(0);
    uint8 private _decimals = 9;
    uint private _tTotal = 1_000_000_000 * 10 ** _decimals;
    uint private _rTotal = (MAX - (MAX % _tTotal));
    uint private _tFeeTotal;
    uint private _ReflectionFee;
    uint private _MarketingFee;
    uint private _DevelopmentFee;
    uint private _InvfundFee;
    uint private _OldReflectionFee;
    uint private _OldMarketingFee;
    uint private _OldDevelopmentFee;
    uint private _OldInvfundFee;
//struct
    struct userData {
        uint lastBuyTime;
    }
//mapping
    mapping (address => uint256) private _rOwned;
    mapping (address => uint256) private _tOwned;
    mapping (address => mapping (address => uint256)) private _allowances;
    mapping (address => bool) public premarketUser;
    mapping (address => bool) public VestedUser;
    mapping (address => bool) public excludedFromFees;
    mapping (address => bool) private _isExcluded;
    mapping (address => bool) public automatedMarketMakerPairs;
    mapping (address => userData) public userLastTradeData;
//event
    event MarketingCollected(uint256 amount);
    event DevelopmentCollected(uint256 amount);
    event InvestmentFundCollected(uint256 amount);
    event ExcludedFromFees(address indexed user, bool state);
    event SwapSystemChanged(bool status, uint256 intervalSecondsToWait, uint256 minimumToSwap, uint256 tokensToSwap);
    event MoveEthToWallets(bool state);
// constructor
    constructor() {
        // set gvars
        IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
        uniswapV2Router = _uniswapV2Router;
        minimumTokensBeforeSwap = 50_000 * 10 ** _decimals ;
        tokensToSwap = minimumTokensBeforeSwap;
        excludedFromFees[address(this)] = true;
        excludedFromFees[owner()] = true;
        premarketUser[owner()] = true;
        excludedFromFees[_MarketingWalletAddress] = true;
        //spawn pair
        uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
        .createPair(address(this), _uniswapV2Router.WETH());
        // mappings
        automatedMarketMakerPairs[uniswapV2Pair] = true;
        _rOwned[owner()] = _rTotal;
        emit Transfer(address(0), owner(), _tTotal);
    }
    // accept eth for autoswap
    receive() external payable {
  	}
    function name() public view returns (string memory) {
        return _name;
    }
    function symbol() public view returns (string memory) {
        return _symbol;
    }
    function decimals() public view returns (uint8) {
        return _decimals;
    }
    function totalSupply() public view override returns (uint256) {
        return _tTotal;
    }
    function balanceOf(address account) public view override returns (uint256) {
        if (_isExcluded[account]) return _tOwned[account];
        return tokenFromReflection(_rOwned[account]);
    }
    function transfer(address recipient, uint256 amount) public override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }
    function allowance(address owner, address spender) public view override returns (uint256) {
        return _allowances[owner][spender];
    }
    function approve(address spender, uint256 amount) public 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");
        _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");
        _approve(_msgSender(), spender, currentAllowance - subtractedValue);
        return true;
    }
    function isExcludedFromReward(address account) public view returns (bool) {
        return _isExcluded[account];
    }
    function totalFees() public view returns (uint256) {
        return _tFeeTotal;
    }
    function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) {
        require(tAmount <= _tTotal, "Amount must be less than supply");
        if (!deductTransferFee) {
            (uint256 rAmount,,,,,,,) = _getValues(tAmount);
            return rAmount;
        } else {
            (,uint256 rTransferAmount,,,,,,) = _getValues(tAmount);
            return rTransferAmount;
        }
    }
    function tokenFromReflection(uint256 rAmount) public view returns(uint256) {
        require(rAmount <= _rTotal, "Amount must be less than total reflections");
        uint256 currentRate =  _getRate();
        return rAmount / currentRate;
    }
    function setFees() private {
        buyFee = buyReflectionFee + buyMarketingFee + buyDevelopmentFee + buyInvfundFee;
        sellFee = sellReflectionFee + sellMarketingFee + sellDevelopmentFee + sellInvfundFee;
    }
    function excludeFromReward(address account) external onlyOwner() {
        require(!_isExcluded[account], "Account is already excluded");
        if(_rOwned[account] > 0) {
            _tOwned[account] = tokenFromReflection(_rOwned[account]);
        }
        _isExcluded[account] = true;
        _excluded.push(account);
    }
    function includeInReward(address account) external onlyOwner() {
        require(_isExcluded[account], "Account is already included");
        for (uint256 i = 0; i < _excluded.length; i++) {
            if (_excluded[i] == account) {
                _excluded[i] = _excluded[_excluded.length - 1];
                _tOwned[account] = 0;
                _isExcluded[account] = false;
                _excluded.pop();
                break;
            }
        }
    }
    function setMoveEthToWallets(bool state) external onlyOwner {
        moveEthToWallets = state;
        emit MoveEthToWallets(state);
    }
    function excludeFromFee(address account) external onlyOwner {
        excludedFromFees[account] = true;
        emit ExcludedFromFees(account,true);
    }
    function includeInFee(address account) external onlyOwner {
        excludedFromFees[account] = false;
        emit ExcludedFromFees(account,false);
    }
    function setReflectionFee(uint buy, uint sell) external onlyOwner() {
        buyReflectionFee = buy;
        sellReflectionFee = sell;
        setFees();
        require(buyFee + sellFee <= 25, "Fees to high");
    }
    function setMarketingFee(uint buy, uint sell) external onlyOwner() {
        buyMarketingFee = buy;
        sellMarketingFee = sell;
        setFees();
        require(buyFee + sellFee <= 25, "Fees to high");
    }
    function setDevelopmentFee(uint buy, uint sell) external onlyOwner() {
        buyDevelopmentFee = buy;
        sellDevelopmentFee = sell;
        setFees();
        require(buyFee + sellFee <= 25, "Fees to high");
    }
    function setInvfundFee(uint buy, uint sell) external onlyOwner() {
        buyInvfundFee = buy;
        sellInvfundFee = sell;
        setFees();
        require(buyFee + sellFee <= 25, "Fees to high");
    }
    function VestingMultipleAccounts(address[] calldata accounts, bool _state) external onlyOwner {
        for(uint256 i = 0; i < accounts.length; i++) {
            VestedUser[accounts[i]] = _state;
        }
    }
    function setMinimumWeiForTokenomics(uint _value) external onlyOwner {
        minimumWeiForTokenomics = _value;
    }
    function disableVesting() external onlyOwner {
        // there is no coming back after disabling vesting.
        vestingActive = false;
    }
    function _reflectFee(uint256 rFee, uint256 tFee) private {
        _rTotal = _rTotal - rFee;
        _tFeeTotal = _tFeeTotal + tFee;
    }

    function _getValues(uint256 tAmount) private view returns (uint256 rAmount, uint256 rTransferAmount, uint256 rFee,
                                                               uint256 tTransferAmount, uint256 tFee, uint256 tMarketing,
                                                               uint256 tDevelopment, uint256 tInvfund) {
        (tTransferAmount, tFee, tMarketing, tDevelopment, tInvfund) = _getTValues(tAmount);
        (rAmount, rTransferAmount, rFee) = _getRValues(tAmount, tFee, tMarketing, tDevelopment, tInvfund, _getRate());
        return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tMarketing, tDevelopment, tInvfund);
    }

    function _getTValues(uint256 tAmount) private view returns (uint256 tTransferAmount, uint256 tFee, uint256 tMarketing, uint256 tDevelopment, uint256 tInvfund) {
        tFee = calculateReflectionFee(tAmount);
        tMarketing = calculateMarketingFee(tAmount);
        tDevelopment = calculateDevelopmentFee(tAmount);
        tInvfund = calculateInvfundFee(tAmount);
        tTransferAmount = tAmount - tFee - tMarketing - tDevelopment - tInvfund;
        return (tTransferAmount, tFee, tMarketing, tDevelopment, tInvfund);
    }

    function _getRValues(uint256 tAmount, uint256 tFee, uint256 tMarketing, uint256 tDevelopment, uint256 tInvfund, uint256 currentRate) private pure returns (uint256, uint256, uint256) {
        uint256 rAmount = tAmount * currentRate;
        uint256 rFee = tFee * currentRate;
        uint256 rMarketing = tMarketing * currentRate;
        uint256 rDevelopment = tDevelopment * currentRate;
        uint256 rInvfund = tInvfund * currentRate;
        uint256 rTransferAmount = rAmount - rFee - rMarketing - rDevelopment - rInvfund;
        return (rAmount, rTransferAmount, rFee);
    }

    function _getRate() private view returns(uint256) {
        (uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
        return rSupply / tSupply;
    }

    function _getCurrentSupply() private view returns(uint256, uint256) {
        uint256 rSupply = _rTotal;
        uint256 tSupply = _tTotal;      
        for (uint256 i = 0; i < _excluded.length; i++) {
            if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal);
            rSupply = rSupply - _rOwned[_excluded[i]];
            tSupply = tSupply - _tOwned[_excluded[i]];
        }
        if (rSupply < _rTotal / _tTotal) return (_rTotal, _tTotal);
        return (rSupply, tSupply);
    }
    function _takeMarketing(uint256 tMarketing) private {
        uint256 currentRate =  _getRate();
        uint256 rMarketing = tMarketing * currentRate;
        _rOwned[address(this)] = _rOwned[address(this)] + rMarketing;
        if(_isExcluded[address(this)])
            _tOwned[address(this)] = _tOwned[address(this)] + tMarketing;
    }
    function _takeDevelopment(uint256 tDevelopment) private {
        uint256 currentRate =  _getRate();
        uint256 rDevelopment = tDevelopment * currentRate;
        _rOwned[address(this)] = _rOwned[address(this)] + rDevelopment;
        if(_isExcluded[address(this)])
            _tOwned[address(this)] = _tOwned[address(this)] + tDevelopment;
    }
    function _takeInvfund(uint256 tInvfund) private {
        uint256 currentRate =  _getRate();
        uint256 rInvfund = tInvfund * currentRate;
        _rOwned[address(this)] = _rOwned[address(this)] + rInvfund;
        if(_isExcluded[address(this)])
            _tOwned[address(this)] = _tOwned[address(this)] + tInvfund;
    }

    function calculateReflectionFee(uint256 _amount) private view returns (uint256) {
        return _amount * _ReflectionFee / 10**2;
    }
    function calculateMarketingFee(uint256 _amount) private view returns (uint256) {
        return _amount * _MarketingFee / 10**2;
    }
    function calculateDevelopmentFee(uint256 _amount) private view returns (uint256) {
        return _amount * _DevelopmentFee / 10**2;
    }
    function calculateInvfundFee(uint256 _amount) private view returns (uint256) {
        return _amount * _InvfundFee / 10**2;
    }
    function setOldFees() private {
        _OldReflectionFee = _ReflectionFee;
        _OldMarketingFee = _MarketingFee;
        _OldDevelopmentFee = _DevelopmentFee;
        _OldInvfundFee = _InvfundFee;
    }
    function shutdownFees() private {
        _ReflectionFee = 0;
        _MarketingFee = 0;
        _DevelopmentFee = 0;
        _InvfundFee = 0;
    }
    function setFeesByType(uint tradeType) private {
        //buy
        if(tradeType == 1) {
            _ReflectionFee = buyReflectionFee;
            _MarketingFee = buyMarketingFee;
            _DevelopmentFee = buyDevelopmentFee;
            _InvfundFee = buyInvfundFee;
        }
        //sell
        else if(tradeType == 2) {
            _ReflectionFee = sellReflectionFee;
            _MarketingFee = sellMarketingFee;
            _DevelopmentFee = sellDevelopmentFee;
            _InvfundFee = sellInvfundFee;
        }
    }
    function restoreFees() private {
        _ReflectionFee = _OldReflectionFee;
        _MarketingFee = _OldMarketingFee;
        _DevelopmentFee = _OldDevelopmentFee;
            _InvfundFee = _OldInvfundFee;
    }

    modifier CheckDisableFees(bool isEnabled, uint tradeType, address from) {
        if(!isEnabled) {
            setOldFees();
            shutdownFees();
            _;
            restoreFees();
        } else {
            // vesting, used to lock vested users, no tranfer, no sell, buy allowed.
            // can be disabled and cannot be enabled again
            if(vestingActive) {
                if(tradeType == 0 || tradeType == 2) {
                    require(!VestedUser[from],"your account is locked.");
                }
            }
            //buy & sell
            if(tradeType == 1 || tradeType == 2) {
                setOldFees();
                setFeesByType(tradeType);
                _;
                restoreFees();
            }
            // no wallet to wallet tax
            else {
                setOldFees();
                shutdownFees();
                _;
                restoreFees();
            }
        }
    }

    function isExcludedFromFee(address account) public view returns(bool) {
        return excludedFromFees[account];
    }

    function _approve(address owner, address spender, uint256 amount) private {
        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);
    }

    modifier FastTx() {
        isInternalTransaction = true;
        _;
        isInternalTransaction = false;
    }
    function sendToWallet(uint amount) private {
        uint256 marketing_part = amount * sellMarketingFee / 100;
        uint256 development_part = amount * sellDevelopmentFee / 100;
        uint256 invfund_part = amount * sellInvfundFee / 100;
        (bool success, ) = payable(_MarketingWalletAddress).call{value: marketing_part}("");
        if(success) {
            emit MarketingCollected(marketing_part);
        }
        (bool success1, ) = payable(_DevelopmentWalletAddress).call{value: development_part}("");
        if(success1) {
            emit DevelopmentCollected(development_part);
        }
        (bool success2, ) = payable(_InvfundWalletAddress).call{value: invfund_part}("");
        if(success2) {
            emit InvestmentFundCollected(invfund_part);
        }
    }

    function swapAndLiquify(uint256 _tokensToSwap) private FastTx {
        swapTokensForEth(_tokensToSwap);
    }
// utility functions
    function transferForeignToken(address _token, address _to, uint _value) external onlyOwner returns(bool _sent){
        if(_value == 0) {
            _value = IERC20(_token).balanceOf(address(this));
        }
        _sent = IERC20(_token).transfer(_to, _value);
    }
    function Sweep() external onlyOwner {
        uint balance = address(this).balance;
        payable(owner()).transfer(balance);
    }
//switch functions
    function ActivateMarket(bool _state) external onlyOwner {
        marketActive = _state;
        if(_state) {
            MarketActiveAt = block.timestamp;
        }
    }
//set functions
    function setMarketingAddress(address _value) external onlyOwner {
        _MarketingWalletAddress = _value;
    }
    function setDevelopmentAddress(address _value) external onlyOwner {
        _DevelopmentWalletAddress = _value;
    }
    function setInvfundAddress(address _value) external onlyOwner {
        _InvfundWalletAddress = _value;
    }
    function setSwapAndLiquify(bool _state, uint _minimumTokensBeforeSwap, uint _intervalSecondsForSwap, uint _tokenToSwap) external onlyOwner {
        swapAndLiquifyEnabled = _state;
        intervalSecondsForSwap = _intervalSecondsForSwap;
        minimumTokensBeforeSwap = _minimumTokensBeforeSwap*10**decimals();
        tokensToSwap = _tokenToSwap*10**decimals();
        require(tokensToSwap <= _tTotal / 500,"tokensToSwap should be max 0.2% of total supply.");
        emit SwapSystemChanged(_state,_intervalSecondsForSwap,_minimumTokensBeforeSwap,_tokenToSwap);
    }
// mappings functions
    function editPowerUser(address _target, bool _status) external onlyOwner {
        premarketUser[_target] = _status;
        excludedFromFees[_target] = _status;
    }
    function editPremarketUser(address _target, bool _status) external onlyOwner {
        premarketUser[_target] = _status;
    }
    function editExcludedFromFees(address _target, bool _status) external onlyOwner {
        excludedFromFees[_target] = _status;
    }
    function editBatchExcludedFromFees(address[] memory _address, bool _status) external onlyOwner {
        for(uint i=0; i< _address.length; i++){
            address adr = _address[i];
            excludedFromFees[adr] = _status;
        }
    }
    function editAutomatedMarketMakerPairs(address _target, bool _status) external onlyOwner {
        automatedMarketMakerPairs[_target] = _status;
    }
// operational functions
    function swapTokensForEth(uint256 tokenAmount) private {
        address[] memory path = new address[](2);
        path[0] = address(this);
        path[1] = uniswapV2Router.WETH();
        _approve(address(this), address(uniswapV2Router), tokenAmount);
        uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
            tokenAmount,
            0,
            path,
            address(this),
            block.timestamp
        );
    }
    function _transfer(address from, address to, uint256 amount) private {
        uint trade_type = 0;
        bool takeFee = true;
        bool overMinimumTokenBalance = balanceOf(address(this)) >= minimumTokensBeforeSwap;
        require(from != address(0), "ERC20: transfer from the zero address");
    // market status flag
        if(!marketActive) {
            require(premarketUser[from],"cannot trade before the market opening");
        }
    // normal transaction
        if(!isInternalTransaction) {
        // tx limits
            //buy
            if(automatedMarketMakerPairs[from]) {
                trade_type = 1;
            }
            //sell
            else if(automatedMarketMakerPairs[to]) {
                trade_type = 2;
                // liquidity generator for tokenomics
                if (swapAndLiquifyEnabled && 
                    balanceOf(uniswapV2Pair) > 0 && 
                    overMinimumTokenBalance &&
                    startTimeForSwap + intervalSecondsForSwap <= block.timestamp
                    ) {
                        startTimeForSwap = block.timestamp;
                        swapAndLiquify(tokensToSwap);
                }
            }
            // send converted eth from fees to respective wallets
            if(moveEthToWallets) {
                uint256 remaningEth = address(this).balance;
                if(remaningEth > minimumWeiForTokenomics) {
                    sendToWallet(remaningEth);
                }
            }
        }
        //if any account belongs to excludedFromFees account then remove the fee
        if(excludedFromFees[from] || excludedFromFees[to]){
            takeFee = false;
        }
        // transfer tokens
        _tokenTransfer(from,to,amount,takeFee,trade_type);
    }

    function _tokenTransfer(address sender, address recipient, uint256 amount,bool takeFee, uint tradeType) private CheckDisableFees(takeFee,tradeType,sender) {
        if (_isExcluded[sender] && !_isExcluded[recipient]) {
            _transferFromExcluded(sender, recipient, amount);
        } else if (!_isExcluded[sender] && _isExcluded[recipient]) {
            _transferToExcluded(sender, recipient, amount);
        } else if (!_isExcluded[sender] && !_isExcluded[recipient]) {
            _transferStandard(sender, recipient, amount);
        } else if (_isExcluded[sender] && _isExcluded[recipient]) {
            _transferBothExcluded(sender, recipient, amount);
        } else {
            _transferStandard(sender, recipient, amount);
        }
    }

    function _transferStandard(address sender, address recipient, uint256 tAmount) private {
        (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tMarketing, uint256 tDevelopment, uint256 tInvFund) = _getValues(tAmount);
        _rOwned[sender] = _rOwned[sender] - rAmount;
        _rOwned[recipient] = _rOwned[recipient] + rTransferAmount;
        _takeMarketing(tMarketing);
        _takeDevelopment(tDevelopment);
        _takeInvfund(tInvFund);
        _reflectFee(rFee, tFee);
        emit Transfer(sender, recipient, tTransferAmount);
    }

    function _transferToExcluded(address sender, address recipient, uint256 tAmount) private {
        (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tMarketing, uint256 tDevelopment, uint256 tInvFund) = _getValues(tAmount);
        _rOwned[sender] = _rOwned[sender] - rAmount;
        _tOwned[recipient] = _tOwned[recipient] + tTransferAmount;
        _rOwned[recipient] = _rOwned[recipient] + rTransferAmount;
        _takeMarketing(tMarketing);
        _takeDevelopment(tDevelopment);
        _takeInvfund(tInvFund);
        _reflectFee(rFee, tFee);
        emit Transfer(sender, recipient, tTransferAmount);
    }

    function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private {
        (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tMarketing, uint256 tDevelopment, uint256 tInvFund) = _getValues(tAmount);
        _tOwned[sender] = _tOwned[sender] - tAmount;
        _rOwned[sender] = _rOwned[sender] - rAmount;
        _rOwned[recipient] = _rOwned[recipient] + rTransferAmount;
        _takeMarketing(tMarketing);
        _takeDevelopment(tDevelopment);
        _takeInvfund(tInvFund);
        _reflectFee(rFee, tFee);
        emit Transfer(sender, recipient, tTransferAmount);
    }
    function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private {
        (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tMarketing, uint256 tDevelopment, uint256 tInvFund) = _getValues(tAmount);
        _tOwned[sender] = _tOwned[sender] - tAmount;
        _rOwned[sender] = _rOwned[sender] - rAmount;
        _tOwned[recipient] = _tOwned[recipient] + tTransferAmount;
        _rOwned[recipient] = _rOwned[recipient] + rTransferAmount;
        _takeMarketing(tMarketing);
        _takeDevelopment(tDevelopment);
        _takeInvfund(tInvFund);
        _reflectFee(rFee, tFee);
        emit Transfer(sender, recipient, tTransferAmount);
    }
    function KKMigration(address[] memory _address, uint256[] memory _amount) external onlyOwner {
        require(_amount.length == _amount.length,"wrong address:amount rows");
        for(uint i=0; i< _amount.length; i++){
            address adr = _address[i];
            uint amnt = _amount[i] *10**decimals();
            (uint256 rAmount, uint256 rTransferAmount,,,,,,) = _getValues(amnt);
            _rOwned[owner()] = _rOwned[owner()] - rAmount;
            _rOwned[adr] = _rOwned[adr] + rTransferAmount;
            emit Transfer(owner(),adr,rTransferAmount);
        } 
    }
}