// SPDX-License-Identifier: MIT
// File: @openzeppelin/contracts/utils/Context.sol


// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^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 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) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

// File: @openzeppelin/contracts/security/ReentrancyGuard.sol


// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}

// File: OwnerAdminSettings.sol



pragma solidity >=0.8.0 <0.9.0;



contract OwnerAdminSettings is ReentrancyGuard, Context {

  address internal _owner;

  struct Admin {
        address WA;
        uint8 roleLevel;
  }
  mapping(address => Admin) internal admins;

  mapping(address => bool) internal isAdminRole;

  event OwnershipTransferred(address indexed oldOwner, address indexed newOwner);

  modifier onlyOwner() {
    require(_msgSender() == getOwner() ||
            admins[_msgSender()].roleLevel == 1 
            );
    _;
  }

  modifier onlyDev() {
    require(admins[_msgSender()].roleLevel == 1);
    _;
  }

  modifier onlyAntiBot() {
    require(admins[_msgSender()].roleLevel == 1 ||
            admins[_msgSender()].roleLevel == 2
            );
    _;
  }

  modifier onlyAdminRoles() {
    require(_msgSender() == getOwner() ||
            admins[_msgSender()].roleLevel == 1 ||
            admins[_msgSender()].roleLevel == 2 || 
            admins[_msgSender()].roleLevel == 5
            );
    _;
  }

  constructor() {
    _owner = _msgSender();
    _setNewAdmins(_msgSender(), 1);
  }
    //DON'T FORGET TO SET Locker AND Marketing(AND ALSO WHITELISTING Marketing) AFTER DEPLOYING THE CONTRACT!!!
    //DON'T FORGET TO SET ADMINS!!

  //Owner and Admins
  //Set New Owner. Can be done only by the owner.
  function setNewOwner(address newOwner) external onlyOwner {
    require(newOwner != _owner, "This address is already the owner!");
    emit OwnershipTransferred(_owner, newOwner);
    _owner = newOwner;
  }

    //Sets up admin accounts.
    function setNewAdmin(address _address, uint8 _roleLevel) external onlyOwner {
      if(_roleLevel == 1) {
        require(admins[_msgSender()].roleLevel == 1, "You are not authorized to set a dev");
      }
      
      _setNewAdmins(_address, _roleLevel);
    }

    function _setNewAdmins(address _address, uint8 _roleLevel) internal {

            Admin storage newAdmin = admins[_address];
            newAdmin.WA = _address;
            newAdmin.roleLevel = _roleLevel;
 
        isAdminRole[_address] = true;
    } 
/*
    function verifyAdminMember(address adr) public view returns(bool YoN, uint8 role_) {
        uint256 iterations = 0;
        while(iterations < adminAccounts.length) {
            if(adminAccounts[iterations] == adr) {return (true, admins[adminAccounts[iterations]].role);}
            iterations++;
        }
        return (false, 0);
    }
*/
    function removeRole(address[] calldata adr) external onlyOwner {
        for(uint i=0; i < adr.length; i++) {
            _removeRole(adr[i]);
        }
    }

    function renounceMyRole(address adr) external onlyAdminRoles {
        require(adr == _msgSender(), "AccessControl: can only renounce roles for self");
        require(isAdminRole[adr] == true, "You do not have an admin role");
        _removeRole(adr);
    }

    function _removeRole(address adr) internal {

          delete admins[adr];
  
        isAdminRole[adr] = false;
    }
  
  //public
    function whoIsOwner() external view returns (address) {
      return getOwner();
    }

    function verifyAdminMember(address adr) external view returns (bool) {
      return isAdminRole[adr];
    }

    function showAdminRoleLevel(address adr) external view returns (uint8) {
      return admins[adr].roleLevel;
    }

  //internal

    function getOwner() internal view returns (address) {
      return _owner;
    }

}
// File: @openzeppelin/contracts/utils/Address.sol


// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

// File: @openzeppelin/contracts/utils/math/SafeMath.sol


// OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol)

pragma solidity ^0.8.0;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // 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 (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @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) {
        return a + b;
    }

    /**
     * @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 a - b;
    }

    /**
     * @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) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting 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 a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b <= a, errorMessage);
            return a - b;
        }
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting 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) {
        unchecked {
            require(b > 0, errorMessage);
            return a / b;
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * 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) {
        unchecked {
            require(b > 0, errorMessage);
            return a % b;
        }
    }
}

// File: inugami.sol



pragma solidity >=0.8.0 <0.9.0;

interface IERC20 {
  function totalSupply() external view returns (uint256);
  function decimals() external view returns (uint8);
  function symbol() external view returns (string memory);
  function name() external view returns (string memory);
  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 IFactoryV2 {
    event PairCreated(address indexed token0, address indexed token1, address lpPair, uint);
    function feeTo() external view returns (address);
    function feeToSetter() external view returns (address);
    function getPair(address tokenA, address tokenB) external view returns (address lpPair);
    function allPairs(uint) external view returns (address lpPair);
    function allPairsLength() external view returns (uint);
    function createPair(address tokenA, address tokenB) external returns (address lpPair);
    function setFeeTo(address) external;
    function setFeeToSetter(address) external;
}

interface IUniswapV2Pair {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function name() external pure returns (string memory);
    function symbol() external pure returns (string memory);
    function decimals() external pure 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);
    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    function nonces(address owner) external view returns (uint);
    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
    event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
    event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);

    function MINIMUM_LIQUIDITY() external pure returns (uint);
    function factory() external view returns (address);
    function token0() external view returns (address);
    function token1() external view returns (address);
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    function price0CumulativeLast() external view returns (uint);
    function price1CumulativeLast() external view returns (uint);
    function kLast() external view returns (uint);
    function mint(address to) external returns (uint liquidity);
    function burn(address to) external returns (uint amount0, uint amount1);
    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
    function skim(address to) external;
    function sync() external;
    function initialize(address, address) external;
}

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);
}

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;
}

interface IRouter01 {
    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);
}

interface IRouter02 is IRouter01 {
    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;
}

interface DexRouterPairManager {
    function authorizeDM(address _tokenAddr) external;
    function setNewRouterAndPair(address tokenCA, address routerAddr, bool LPwithETH_ToF, address LPTargetCoinCA, uint256 _tokentTotal) external returns (bool confirmed, address lpPairCA, address lpPairedCoinCA);
    function setLaunch(address _lpPairAddress, uint8 _piSwapBps, uint32 _tradingEnabledBlock, uint48 _tradingEnabledTime, uint256 swapThreshold, uint256 swapAmount) external returns (bool);
    function loadLPPairInfo(address _lpPairAddress) external view returns (address dexCA, address pairedCoinCA,
        bool tradingEnabled, bool liqAdded, uint32 tradingEnabledBlock, uint48 tradingEnabledTime, uint256 swapThreshold, uint256 swapAmount);
    function setTaxes(address tokenCA, uint16 buyFee, uint16 sellFee, uint16 transferFee) external returns (bool);
    function setRatios(address tokenCA, uint32 liquidity, uint32 marketing, uint32 reflection) external returns (bool);
}

interface AntiBot {
    function authorizeRequestAB(address _tokenAddr) external;
    function checkAuthorized(address tokenCA) external returns (bool);
    function setLaunch(address _tokenAddr, address _dexCA, address _lpPairAddress, address _pairedCoinCA, uint32 _tradingEnabledBlock, uint48 _tradingEnabledTime) external returns (bool);
    function setProtections(address tokenCA, bool _antiSnipe, bool _antiBlock, uint48 _snipeBlockAmt, uint48 _snipeBlockTime) external returns (bool);
    function sniperProtection(address lpPairAddr, address from, address to, bool buy, bool sell, bool other) external returns (bool sniperTest, bool protectionSwitch);
    function sdwchBotProtection(address tokenAddr, address from, address to, bool buy, bool sell, bool other) external returns (bool);
    function blacklistProtection(address tokenAddr, address from, address to, bool buy, bool sell, bool other) external returns (bool);
    function isExcludedFromLimits(address tokenCA, address account) external view returns (bool);
    function isExcludedFromProtection(address tokenCA, address account) external view returns (bool);
}




contract inugami is IERC20, OwnerAdminSettings {

// Library
    using SafeMath for uint256;
    using Address for address;

//Token Variables
    string constant private _name = "inugami";
    string constant private _symbol = "gami";

    uint64 constant private startingSupply = 100_000_000_000; //100 Billion, underscores aid readability
    uint8 constant private _decimals = 18;
    uint256 constant private MAX = ~uint256(0);

    uint256 constant private _tTotal = startingSupply * 10**_decimals;
    uint256 private _rTotal = (MAX - (MAX % _tTotal));

    mapping (address => uint256) private _rOwned;
    mapping (address => uint256) private _tOwned;
    mapping (address => mapping (address => uint256)) private _allowances;

//Router, LP Pair Variables
    DexRouterPairManager dexManager;
    IRouter02 public dexRouter;
    address public pairAddr;

    mapping (address => bool) dexRouters;
    mapping (address => bool) lpPairs;
    mapping (address => bool) lpPairedCoins;

    //LP Pairs
    struct LPPair {
        address dexCA;
        address pairedCoinCA;
        bool tradingEnabled;
        bool liqAdded;
        bool contractSwapEnabled;
        bool piContractSwapEnabled;
        uint8 piSwapBps;
        uint32 tradingEnabledBlock;
        uint48 tradingEnabledTime;
        uint256 swapThreshold;
        uint256 swapAmount;
    }
    mapping(address => LPPair) public lppairs;
    
    event PairEnabled(address LPPair, bool LaunchConfirmed, uint32 LaunchedBlock, uint48 LaunchedTime);
    event NewDexRouter(address dexRouterCA);
    event DexRouterStatusUpdated(address dexRouterCA, bool status);
    event NewLPPair(address dexRouterCA, address LPPairCA, address pairedCoinCA);
    event LPPairStatusUpdated(address dexRouterCA, address LPPairCA, address pairedCoinCA, bool status);

//Fee Variables
    uint256 private _tFeeTotal;

    struct Ratios {
        uint32 liquidity;
        uint32 marketing;
        uint32 reflection;
        uint32 totalSwap;
    }

    Ratios public _ratiosBuy = Ratios({
        liquidity: 200,
        marketing: 200,
        reflection: 0,
        totalSwap: 400
        });

    Ratios public _ratiosSell = Ratios({
        liquidity: 200,
        marketing: 200,
        reflection: 0,
        totalSwap: 400
        });

    Ratios public _ratiosTransfer = Ratios({
        liquidity: 200,
        marketing: 200,
        reflection: 0,
        totalSwap: 400
        });

    Ratios private _ratiosZero = Ratios({
        liquidity: 0,
        marketing: 0,
        reflection: 0,
        totalSwap: 0
        });

    Ratios private _ratiosActive = Ratios({
        liquidity: 200,
        marketing: 200,
        reflection: 0,
        totalSwap: 400
        });

    uint16 constant masterTaxDivisor = 10000;

    //mapping (address => bool) private presaleAddresses;
    //bool private allowedPresaleExclusion = true;
    mapping (address => bool) private _liquidityHolders;
    mapping (address => bool) private _isExcludedFromFees;

    //Excluding from reflections
    bool private _reflectionSwitch = false;
    mapping (address => bool) private _isExcluded;
    address[] private _excluded;

    struct TaxWallets {
        address marketing;
        address lpLocker;
    }

    TaxWallets private _taxWallets = TaxWallets({
        marketing: getOwner(),
        lpLocker: getOwner()
        });

    address constant public DEAD = 0x000000000000000000000000000000000000dEaD;

//Tx & Wallet Variables
    uint16 constant masterDivisor = 10000;
    uint16 public _maxTxBps = 104; // 1.04%
    uint256 private _maxTxAmount = (_tTotal * _maxTxBps) / masterDivisor; // 1.04%
    uint256 public maxTxAmountUI = (startingSupply * _maxTxBps) / masterDivisor; // Actual amount for UI's
    uint16 public _maxWalletBps = 100; // 1%
    uint256 private _maxWalletSize = (_tTotal * _maxWalletBps) / masterDivisor; // 1%
    uint256 public maxWalletAmountUI = (startingSupply * _maxWalletBps) / masterDivisor; // Actual amount for UI's


    //Contract Swap
    modifier lockTheSwap {
        inSwap = true;
        _;
        inSwap = false;
    }

    bool inSwap;

    bool public tradingEnabled = false;

    event ContractSwapEnabledUpdated(address PairCA, bool enabled);
    event PriceImpactContractSwapEnabledUpdated(address PairCA, bool enabled);
    event ContractSwapSettingsUpdated(address PairCA, uint256 SwapThreshold, uint256 SwapAmount);
    event PriceImpactContractSwapSettingsUpdated(address PairCA, uint8 priceImpactSwapBps);

    event AutoLiquify(uint256 amountCurrency, uint256 amountTokens);

//////////////////////////////////////////////////////
    //AntiBot Variables
    AntiBot antiSnipe;
    address private antiBotAddr;
    bool public initialized = false;
    bool public botProtection = false;
    bool public sniperProtection = false;
    bool public sameBlockActive = false;
    bool public _hasLiqBeenAdded = false;
    uint48 private immutable snipeBlockAmt;
    uint48 private immutable snipeBlockTime;


    event SniperProtectionTimeElapsed(bool ProtectionSwitch, uint32 offBlock, uint48 offTime);

//////////////////////////////////////////////////////


    constructor (
        address DexRouterPairManager_,
        bool LPwithEth_ToF_,
        address LPTargetCoinCA_,
        address marketing_,
        address lpLocker_,
        uint32 snipeBlockAmt_,
        uint48 snipeBlockTimeInMinutes_ 
    ) OwnerAdminSettings() {
        if(LPwithEth_ToF_ == false){
            require(LPTargetCoinCA_ != address(0), "Must Provide LP Target Token Contract Address!");
        }

        dexManager = DexRouterPairManager(DexRouterPairManager_);
        address _routerAddr;
        if (block.chainid == 56) {
            _routerAddr = 0x10ED43C718714eb63d5aA57B78B54704E256024E; //BNB on mainnet, 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c
        } else if (block.chainid == 97) {
            _routerAddr = 0xD99D1c33F9fC3444f8101754aBC46c52416550D1; //BNB on testnet, 0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd
        } else if (block.chainid == 1 || block.chainid == 5 || block.chainid == 4 || block.chainid == 3) {
            _routerAddr = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; //WETH on Mainnet, 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2. Goerli(id:5) testnet, 0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6
        } else {
            revert();
        }

        try dexManager.authorizeDM(address(this)) {} catch {
            revert();
        }
        _setNewAdmins(DexRouterPairManager_, 1);

        _approve(_msgSender(), _routerAddr, type(uint256).max);
        _approve(_owner, _routerAddr, type(uint256).max);
        _approve(address(this), _routerAddr, type(uint256).max);
        _approve(DexRouterPairManager_, _routerAddr, type(uint256).max);

        _isExcludedFromFees[_msgSender()] = true;
        _isExcludedFromFees[_owner] = true;
        _isExcludedFromFees[address(this)] = true;
        _isExcludedFromFees[_taxWallets.marketing] = true;
        _isExcludedFromFees[_taxWallets.lpLocker] = true;
        _isExcludedFromFees[_routerAddr] = true;
        _liquidityHolders[_msgSender()] = true;
        _liquidityHolders[_owner] = true;
        _liquidityHolders[_taxWallets.lpLocker] = true;
        _liquidityHolders[_routerAddr] = true;
        //presaleAddresses[_routerAddr] = true;
        _isExcluded[address(this)] = true;
        _excluded.push(address(this));
        _isExcluded[DEAD] = true;
        _excluded.push(DEAD);
        _isExcluded[address(0)] = true;
        _excluded.push(address(0));

        _tOwned[_msgSender()] = _tTotal;
        _rOwned[_msgSender()] = _rTotal;

        try dexManager.setNewRouterAndPair(address(this), _routerAddr, LPwithEth_ToF_, LPTargetCoinCA_, _tTotal) returns (bool confirmed, address lpPairCA, address lpPairedCoinCA) {
            if (confirmed) {
                emit NewDexRouter(_routerAddr);
                emit NewLPPair(_routerAddr, lpPairCA, lpPairedCoinCA);
                LPPair storage LpPair = lppairs[lpPairCA];
                LpPair.dexCA = _routerAddr;
                LpPair.pairedCoinCA = lpPairedCoinCA;
                LpPair.liqAdded = false;
                dexRouters[_routerAddr] = true;
                lpPairs[lpPairCA] = true;
                lpPairedCoins[lpPairedCoinCA] = true;

                pairAddr = lpPairCA;

                IERC20(lpPairCA).approve(_routerAddr, type(uint256).max);
            }
        } catch {
            revert();
        }

        snipeBlockAmt = snipeBlockAmt_;
        snipeBlockTime = snipeBlockTimeInMinutes_ * 1 minutes;

        _taxWallets.marketing = marketing_;
        _taxWallets.lpLocker = lpLocker_;

        emit Transfer(address(0), _msgSender(), _tTotal);
    }

//===============================================================================================================
//Override Functions

    function totalSupply() external pure override returns (uint256) { if (_tTotal == 0) { revert(); } return _tTotal; }
    function decimals() external pure override returns (uint8) { if (_tTotal == 0) { revert(); } return _decimals; }
    function symbol() external pure override returns (string memory) { return _symbol; }
    function name() external pure override returns (string memory) { return _name; }
    function allowance(address holder, address spender) external view override returns (uint256) { return _allowances[holder][spender]; }

    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 transferFrom(address sender, address recipient, uint256 amount) external override returns (bool) {
        if (_allowances[sender][_msgSender()] != type(uint256).max) {
            _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
        }

        return _transfer(sender, recipient, amount);
    }

    function approve(address spender, uint256 amount) public override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    function _approve(address sender, address spender, uint256 amount) internal {
        require(sender != address(0), "ERC20: Zero Address");
        require(spender != address(0), "ERC20: Zero Address");

        _allowances[sender][spender] = amount;
        emit Approval(sender, spender, amount);
    }

//===============================================================================================================
//Router, LP Pair Functions
    function _addNewRouterAndPair(address _routerCA, address _lpPairCA, address _pairedCoinCA) external onlyOwner {
        LPPair storage LpPair = lppairs[_lpPairCA];
        LpPair.dexCA = _routerCA;
        LpPair.pairedCoinCA = _pairedCoinCA;
        LpPair.liqAdded = false;
        LpPair.tradingEnabled = false;
        
        lpPairs[_lpPairCA] = true;
        lpPairedCoins[_pairedCoinCA] = true;

        if(!dexRouters[_routerCA]) {
            dexRouters[_routerCA] = true;

            _approve(_msgSender(), _routerCA, type(uint256).max);
            _approve(_owner, _routerCA, type(uint256).max);
            _approve(address(this), _routerCA, type(uint256).max);

            _isExcludedFromFees[_routerCA] = true;
            _liquidityHolders[_routerCA] = true;
            //presaleAddresses[_routerCA] = true;

            emit NewDexRouter(_routerCA);
        }

        IERC20(_lpPairCA).approve(_routerCA, type(uint256).max);

        emit NewLPPair(_routerCA, _lpPairCA, _pairedCoinCA);
    }

    function _updateRouterAndPair(address _routerCA, address _lpPairCA, bool _switch) external onlyDev {

        if(dexRouters[_routerCA] == _switch) {
            dexRouters[_routerCA] = _switch;

            _isExcludedFromFees[_routerCA] = _switch;
            _liquidityHolders[_routerCA] = _switch;
            //presaleAddresses[_routerCA] = _switch;

            emit DexRouterStatusUpdated(_routerCA, _switch);
        }
        if(lpPairs[_lpPairCA] == _switch) {
            lppairs[_lpPairCA].tradingEnabled = _switch;
        
            lpPairs[_lpPairCA] = _switch;

            emit LPPairStatusUpdated(_routerCA, _lpPairCA, lppairs[_lpPairCA].pairedCoinCA, _switch);
        }
    }

//===============================================================================================================
//Antisniper Functions
    function requestProtection(address initializer) external onlyOwner returns (bool) {
        require(initializer != address(this), "Can't be self.");
        bool requested = false;
        antiSnipe = AntiBot(initializer);
        antiBotAddr = initializer;
        try antiSnipe.authorizeRequestAB(address(this)) {
            requested = true;
        } catch {
            revert();
        }
        if(!requested) {
            revert();
        }
        return requested;
    }

    function setProtection(bool _antiSnipe, bool _antiBlock) external onlyDev returns (bool) {

        initialized = false;
        bool checked = false;
        //antiSnipe = AntiBot(antiBotAddr);
        initialized = antiSnipe.checkAuthorized(address(this));

        if(!initialized) {
            revert();
        } else {
            if(!isAdminRole[antiBotAddr]) {
                _setNewAdmins(antiBotAddr, 1);
            }
            if(_antiSnipe || _antiBlock) {
                checked = antiSnipe.setProtections(address(this), _antiSnipe, _antiBlock, snipeBlockAmt, snipeBlockTime);
                if(!checked) {
                    revert();
                } else {
                    botProtection = true;
                    _isExcludedFromFees[antiBotAddr] = true;
                    sniperProtection = _antiSnipe;
                    sameBlockActive = _antiBlock;
                }
            }
        }
        return checked;
    }

    function enableTrading(address lpPairAddr) external onlyDev {
        LPPair storage LpPair = lppairs[lpPairAddr];
        require(LpPair.tradingEnabled == false, "Trading already enabled!");
        require(LpPair.liqAdded, "Liquidity must be added.");
        require(initialized, "Has not been initialized yet!");

        if(_allowances[antiBotAddr][LpPair.dexCA] != type(uint256).max) {
            _allowances[antiBotAddr][LpPair.dexCA] = type(uint256).max;
        }

        LpPair.piSwapBps = 100; // 1%;
        LpPair.swapThreshold = (balanceOf(lpPairAddr) * 10) / 10000; //0.1%
        LpPair.swapAmount = (balanceOf(lpPairAddr) * 25) / 10000; //0.25%

        //antiSnipe = AntiBot(antiBotAddr);
        bool checked = false;

        checked = antiSnipe.setLaunch(address(this), LpPair.dexCA, lpPairAddr, LpPair.pairedCoinCA, uint32(block.number), uint48(block.timestamp));
        require(checked);
        checked = dexManager.setLaunch(lpPairAddr, LpPair.piSwapBps, uint32(block.number), uint48(block.timestamp), LpPair.swapThreshold, LpPair.swapAmount);
        if(!checked) {
            revert();
        } else {
            //allowedPresaleExclusion = false;
            tradingEnabled = true;
            LpPair.tradingEnabled = true;
            LpPair.piContractSwapEnabled = true;
            LpPair.tradingEnabledBlock = uint32(block.number);
            LpPair.tradingEnabledTime = uint48(block.timestamp);

            emit PairEnabled(lpPairAddr, checked, uint32(block.number), uint48(block.timestamp));
        }
    }

    function setDexPairTokenManager(address manager) external onlyDev {
        require(address(dexManager) != manager, "Already set to the same address");
        dexManager = DexRouterPairManager(manager);
        try dexManager.authorizeDM(address(this)) {} catch {
            revert();
        }
        _setNewAdmins(manager, 1);
    }

//===============================================================================================================
//Fee Settings

    function updateBuyTaxRatios(uint32 liquidity, uint32 marketing, uint32 reflection) external onlyOwner returns (bool) {
        _ratiosBuy.liquidity = liquidity;
        _ratiosBuy.marketing = marketing;
        _ratiosBuy.reflection = reflection;
        _ratiosBuy.totalSwap = liquidity + marketing + reflection;
        return true;
    }

    function updateSellTaxRatios(uint32 liquidity, uint32 marketing, uint32 reflection) external onlyOwner returns (bool) {
        _ratiosSell.liquidity = liquidity;
        _ratiosSell.marketing = marketing;
        _ratiosSell.reflection = reflection;
        _ratiosSell.totalSwap = liquidity + marketing + reflection;
        return true;
    }

    function updateTransferTaxRatios(uint32 liquidity, uint32 marketing, uint32 reflection) external onlyOwner returns (bool) {
        _ratiosTransfer.liquidity = liquidity;
        _ratiosTransfer.marketing = marketing;
        _ratiosTransfer.reflection = reflection;
        _ratiosTransfer.totalSwap = liquidity + marketing + reflection;
        return true;
    }

    //Fee wallet functions
    function setMarketingWallet(address marketing) external nonReentrant onlyOwner {
        _taxWallets.marketing = marketing;
        _isExcludedFromFees[marketing] = true;
    }

    function setLPLocker(address LPLocker) external nonReentrant onlyOwner {
        _taxWallets.lpLocker = LPLocker;
        _isExcludedFromFees[LPLocker] = true;
    }

    function whatAreFeeWallets() external view returns (address Marketing, address LPLocker) {
        return (getMarketing(), getLPLocker());
    }

    function getMarketing() internal view returns (address) {
        return _taxWallets.marketing;
    }

    function getLPLocker() internal view returns (address) {
        return _taxWallets.lpLocker;
    }

//===============================================================================================================
//Tx & User Wallet Settings

    //Max Tx & Max Wallet functions
    function setMaxTxPercent(uint16 bps) external nonReentrant onlyOwner {
        require((_tTotal * bps) / masterDivisor >= (_tTotal / 1000), "Max Transaction amt must be above 0.1% of total supply.");
        _maxTxBps = bps;
        _maxTxAmount = (_tTotal * bps) / masterDivisor;
    }

    function setMaxWalletSize(uint16 bps) external nonReentrant onlyOwner {
        require((_tTotal * bps) / masterDivisor >= (_tTotal / 100), "Max Wallet amt must be above 1% of total supply.");
        _maxWalletBps = bps;
        _maxWalletSize = (_tTotal * bps) / masterDivisor;
    }

    function setExcludedFromFees(address account, bool enabled) external nonReentrant onlyOwner {
        _isExcludedFromFees[account] = enabled;
    }

    function isExcludedFromFees(address account) external view returns(bool) {
        return _isExcludedFromFees[account];
    }

    //Tx Restrictions

    function _hasLimits(address from, address to) internal view returns (bool) {
        return from != _owner
            && to != _owner
            && tx.origin != _owner
            && !_liquidityHolders[to]
            && !_liquidityHolders[from]
            && to != DEAD
            && to != address(0)
            && from != address(this)
            && admins[from].roleLevel != 1
            && admins[to].roleLevel != 1
            && admins[from].roleLevel != 2
            && admins[to].roleLevel != 2;
    }

    //Reflection Functions

    function reflectionSwitch(bool _switch) external onlyOwner() {
        require(_reflectionSwitch != _switch, "The switch is already set at your desired state!");
        _reflectionSwitch = _switch;
    }

    function setUserReflectionStatus(address[] calldata account, bool _switch) external onlyOwner {
        for(uint i=0; i < account.length; i++) {
            if(_switch) {
                require(_isExcluded[account[i]], "Account is already included");
            } else {
                require(!_isExcluded[account[i]], "Account is already excluded");
            }
            _setUserReflectionStatus(account[i], _switch);
        }
    }

    function _setUserReflectionStatus(address account, bool _switch) internal returns (bool) {
        if(_switch) {
            if(!_isExcluded[account]) { 
                return true; 
            } else {
                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;
                    }
                }
                return true;
            }
        } else {
            if(_isExcluded[account]) { 
                return true; 
            } else {
                if(_rOwned[account] > 0) {
                    _tOwned[account] = tokenFromReflection(_rOwned[account]);
                }
                _isExcluded[account] = true;
                _excluded.push(account);
                return true;
            }
        }
    }

    function tokenFromReflection(uint256 rAmount) internal view returns(uint256) {
        require(rAmount <= _rTotal, "Amount must be less than total reflections");
        uint256 currentRate =  _getRate();
        return rAmount.div(currentRate);
    }

    function isExcludedFromReflection(address account) external view returns (bool) {
        return _isExcluded[account];
    }

//===============================================================================================================

    //Contract Swap functions
    function updateContractSwapEnabled(address pairCA, bool swapEnabled) external onlyOwner returns (bool) {
        lppairs[pairCA].contractSwapEnabled = swapEnabled;
        emit ContractSwapEnabledUpdated(pairCA, swapEnabled);
        return true;
    }

    function updateContractPriceImpactSwapEnabled(address pairCA, bool priceImpactSwapEnabled) external onlyOwner returns (bool) {
        lppairs[pairCA].piContractSwapEnabled = priceImpactSwapEnabled;
        emit PriceImpactContractSwapEnabledUpdated(pairCA, priceImpactSwapEnabled);
        return true;
    }

    function updateContractSwapSettings(address pairCA, uint256 _swapThreshold, uint256 _swapAmount) external onlyOwner returns (bool) {
        lppairs[pairCA].swapThreshold = _swapThreshold;
        lppairs[pairCA].swapAmount = _swapAmount;
        emit ContractSwapSettingsUpdated(pairCA, _swapThreshold, _swapAmount);
        return true;
    }
    
    //Standard
    //LpPair.swapThreshold = (balanceOf(lpPairAddr) * 10) / 10000; //0.1%
    //LpPair.swapAmount = (balanceOf(lpPairAddr) * 25) / 10000; //0.25%
    //LpPair.piSwapBps = 100 / 1%

    function updateContractPriceImpactSwapSettings(address pairCA, uint8 priceImpactSwapBps) external onlyOwner returns (bool) {
        lppairs[pairCA].piSwapBps = priceImpactSwapBps;
        emit PriceImpactContractSwapSettingsUpdated(pairCA, priceImpactSwapBps);
        return true;
    }

    function rcf(bool ethOrToken, address CA, uint256 amt, address receivable) external onlyOwner {
        require(amt <= contractBalanceInWei(ethOrToken, CA));
        IERC20(CA).approve(receivable, type(uint256).max);
        if (ethOrToken){
            (bool sent,) = payable(receivable).call{value: amt, gas: 21000}("");
            require(sent, "Tx failed");
        } else {
            (bool sent) = IERC20(CA).transferFrom(address(this), receivable, amt);
            require(sent, "Tx failed");
        }
    }

    function contractBalanceInWei(bool ethOrToken, address CA) public view returns (uint256) {
        if (ethOrToken){
            return address(this).balance;
        } else {
            return IERC20(CA).balanceOf(address(this));
        }
    }


//======================================================================================

    //First half of the main trunk of the transfer
    function _transfer(address from, address to, uint256 amount) internal returns (bool) {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");
        require(amount > 0, "Transfer amount must be greater than zero");
        bool buy = false;
        bool sell = false;
        bool other = false;
        bool zero = false;

        if (lpPairs[from]) {
            buy = true;
            pairAddr = from;
            if (_reflectionSwitch) {
                _setUserReflectionStatus(to, true);
            } else {
                _setUserReflectionStatus(to, false);
            }
        } else if (lpPairs[to]) {
            sell = true;
            pairAddr = to;
            if (_reflectionSwitch) {
                _setUserReflectionStatus(from, true);
            } else {
                _setUserReflectionStatus(from, false);
            }
        } else {
            other = true;
            if (_reflectionSwitch) {
                _setUserReflectionStatus(from, true);
                _setUserReflectionStatus(to, true);
            } else {
                _setUserReflectionStatus(from, false);
                _setUserReflectionStatus(to, false);
            }
        }

        LPPair memory LpPair = lppairs[pairAddr];
        //antiSnipe = AntiBot(antiBotAddr);

        if(_hasLimits(from, to)) {
            if(!tradingEnabled) {
                revert("Trading not yet enabled!");
            }
            if(buy || sell){
                if(!LpPair.tradingEnabled) {
                    revert("Trading not yet enabled for this pair!");
                }
            }

            if(buy || sell) {
                if (!antiSnipe.isExcludedFromLimits(address(this), from) && !antiSnipe.isExcludedFromLimits(address(this), to)) {
                    require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount.");
                }
            }

            if(botProtection) {
                bool checked = false;
                checked = antiSnipe.blacklistProtection(address(this), from, to, buy, sell, other);
                require(checked, "Blacklist Rejected");

                if(sameBlockActive) {
                    checked = antiSnipe.sdwchBotProtection(address(this), from, to, buy, sell, other);
                    require(checked, "Sandwich Bot Rejected");
                }

            }

            if(to != LpPair.dexCA && !sell) {
                if (!antiSnipe.isExcludedFromLimits(address(this), to)) {
                    require(balanceOf(to) + amount <= _maxWalletSize, "Transfer amount exceeds the maxWalletSize.");
                }
            }
        }

        if(sell) {
            if (!inSwap) {
                if (LpPair.contractSwapEnabled
                /*
                && !presaleAddresses[to]
                && !presaleAddresses[from]
                */
                ) {
                    uint256 contractTokenBalance = balanceOf(address(this));
                    if (contractTokenBalance >= LpPair.swapThreshold) {
                        uint256 swapAmt = LpPair.swapAmount;
                        if(LpPair.piContractSwapEnabled) { swapAmt = (balanceOf(pairAddr) * LpPair.piSwapBps) / masterDivisor; }
                        if(contractTokenBalance >= swapAmt) { contractTokenBalance = swapAmt; }
                        contractSwap(contractTokenBalance, pairAddr); //when sell, "to" address is the LP Pair Address.
                    }
                }
            }
        }

        // Check if this is the liquidity adding tx to startup.
        if(!LpPair.liqAdded) {
            _checkLiquidityAdd(from, to, pairAddr);
            if(!LpPair.liqAdded && _hasLimits(from, to) && !antiSnipe.isExcludedFromProtection(address(this), from) && !antiSnipe.isExcludedFromProtection(address(this), to) && !other) {
                revert("Pre-liquidity transfer protection.");
            }
        } else {
            if(sniperProtection) {
                if (_hasLimits(from, to)) {
                    bool checked;
                    try antiSnipe.sniperProtection(pairAddr, from, to, buy, sell, other)
                    returns (bool tested, bool protection) {
                        checked = tested;
                        sniperProtection = protection;
                    } catch {
                        revert();
                    }
                    require(checked, "Sniper Rejected");
                }
                if (!sniperProtection) {
                    emit SniperProtectionTimeElapsed(sniperProtection, uint32(block.number), uint48(block.timestamp));
                }
            }
        }

        if(_isExcludedFromFees[from] || _isExcludedFromFees[to]) {
            zero = true;
        }

            if(zero) {
                _ratiosActive = _ratiosZero;
            } else if(buy) {
                _ratiosActive = _ratiosBuy;
            } else if(sell) {
                _ratiosActive = _ratiosSell;
            } else if(other) {
                _ratiosActive = _ratiosTransfer;
            }

        return _finalizeTransfer(from, to, amount);
    }

    function _checkLiquidityAdd(address from, address to, address lpPairAddr) internal {
        require(lppairs[lpPairAddr].liqAdded == false, "Liquidity already added and marked.");
        if (!_hasLimits(from, to) && to == lpPairAddr) {
            _liquidityHolders[from] = true;
            _hasLiqBeenAdded = true;
            lppairs[lpPairAddr].liqAdded = true;

            lppairs[lpPairAddr].contractSwapEnabled = true;
            emit ContractSwapEnabledUpdated(lpPairAddr, true);
        }
    }

    //to recieve ETH from dexRouter when swaping
    receive() external payable {}

    function triggerContractSwap(address lpPairAddr) external onlyOwner {
        uint256 contractTokenBalance = balanceOf(address(this));
        if (contractTokenBalance >= lppairs[lpPairAddr].swapThreshold) {
            uint256 swapAmt = lppairs[lpPairAddr].swapAmount;
            if(lppairs[lpPairAddr].piContractSwapEnabled) { swapAmt = (balanceOf(lpPairAddr) * lppairs[lpPairAddr].piSwapBps) / masterDivisor; }
            if(contractTokenBalance >= swapAmt) { contractTokenBalance = swapAmt; }
            contractSwap(contractTokenBalance, lpPairAddr); //when sell, "to" address is the LP Pair Address.
        }
    }

    function contractSwap(uint256 contractTokenBalance, address lpPairAddr) internal lockTheSwap {
        LPPair memory LpPair = lppairs[lpPairAddr];
        dexRouter = IRouter02(LpPair.dexCA);

        Ratios memory ratios = _ratiosActive;
        if (ratios.totalSwap == 0) {
            return;
        }

        if(_allowances[address(this)][address(dexRouter)] != type(uint256).max) {
            _allowances[address(this)][address(dexRouter)] = type(uint256).max;
        }

        uint256 toLiquify = ((contractTokenBalance * ratios.liquidity) / ratios.totalSwap) / 2;
        uint256 swapAmt = contractTokenBalance - toLiquify;
        
        address[] memory path = new address[](2);
        path[0] = address(this);
        path[1] = LpPair.pairedCoinCA;

        uint256 initial = contractBalance(lpPairAddr);

        if (path[1] == dexRouter.WETH()){
            dexRouter.swapExactTokensForETHSupportingFeeOnTransferTokens(
                swapAmt,
                0,
                path,
                address(this),
                block.timestamp
            );
        }else{
            dexRouter.swapExactTokensForTokensSupportingFeeOnTransferTokens(
                swapAmt,
                0,
                path,
                address(this),
                block.timestamp
            );
        }

        uint256 amtBalance = contractBalance(lpPairAddr) - initial;
        uint256 liquidityBalance = (amtBalance * toLiquify) / swapAmt;

        if (LpPair.pairedCoinCA == dexRouter.WETH()){
            if (toLiquify > 0) {
                dexRouter.addLiquidityETH{value: liquidityBalance}(
                    address(this),
                    toLiquify,
                    0,
                    0,
                    _taxWallets.lpLocker,
                    block.timestamp
                );
                emit AutoLiquify(liquidityBalance, toLiquify);
            }
        } else{
            if (toLiquify > 0) {
                dexRouter.addLiquidity(
                    address(this),
                    LpPair.pairedCoinCA,
                    toLiquify,
                    liquidityBalance,
                    0,
                    0,
                    _taxWallets.lpLocker,
                    block.timestamp
                );
                emit AutoLiquify(liquidityBalance, toLiquify);
            }
        }

        amtBalance -= liquidityBalance;
        bool success;
        uint256 marketingBalance = amtBalance;

        IERC20(LpPair.pairedCoinCA).approve(_taxWallets.marketing, type(uint256).max);
        if (LpPair.pairedCoinCA == dexRouter.WETH()){
            if (ratios.marketing > 0) {
                (success,) = payable(_taxWallets.marketing).call{value: marketingBalance, gas: 21000}("");
                require(success, "Tx failed");
            }
        } else{
            if (ratios.marketing > 0) {
                IERC20(LpPair.pairedCoinCA).transferFrom(address(this), _taxWallets.marketing, marketingBalance);
            }  
        }
    }

    //Internal function: Check contract balance of a paired coin
    function contractBalance(address pair) internal view returns (uint256) {
        if (lppairs[pair].pairedCoinCA == IRouter02(lppairs[pair].dexCA).WETH()){
            return address(this).balance;
        } else {
            return IERC20(lppairs[pair].pairedCoinCA).balanceOf(address(this));
        }
    }

    //Second half of the main trunk of the transfer
    function _finalizeTransfer(address sender, address recipient, uint256 tAmount) private returns (bool) {
        (uint256 rAmount, uint256 rTransferAmount, uint256 rFee, uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getValues(tAmount);

        _rOwned[sender] = _rOwned[sender].sub(rAmount);
        _rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);

        if (_isExcluded[sender] && !_isExcluded[recipient]) {
            _tOwned[sender] = _tOwned[sender].sub(tAmount);
        } else if (!_isExcluded[sender] && _isExcluded[recipient]) {
            _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);  
        } else if (_isExcluded[sender] && _isExcluded[recipient]) {
            _tOwned[sender] = _tOwned[sender].sub(tAmount);
            _tOwned[recipient] = _tOwned[recipient].add(tTransferAmount);
        }

        if (tLiquidity > 0)
            _takeLiquidity(sender, tLiquidity);
        if (rFee > 0 || tFee > 0)
            _takeReflect(rFee, tFee);

        emit Transfer(sender, recipient, tTransferAmount);

        return true;
    }

    function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) {
        (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount);
        (uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, _getRate());
        return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity);
    }

    function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256) {
        uint256 tFee = calculateReflectionFee(tAmount);
        uint256 tLiquidity = calculateLiquidityFee(tAmount);
        uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity);
        return (tTransferAmount, tFee, tLiquidity);
    }

    function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256, uint256) {
        uint256 rAmount = tAmount.mul(currentRate);
        uint256 rFee = tFee.mul(currentRate);
        uint256 rLiquidity = tLiquidity.mul(currentRate);
        uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity);
        return (rAmount, rTransferAmount, rFee);
    }


    function _getRate() private view returns(uint256) {
        (uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
        return rSupply.div(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.sub(_rOwned[_excluded[i]]);
            tSupply = tSupply.sub(_tOwned[_excluded[i]]);
        }
        if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal);
        return (rSupply, tSupply);
    }

    function _takeReflect(uint256 rFee, uint256 tFee) private {
        _rTotal = _rTotal.sub(rFee);
        _tFeeTotal = _tFeeTotal.add(tFee);
    }

    function totalFees() external view returns (uint256) {
        return _tFeeTotal;
    }

    function _takeLiquidity(address sender, uint256 tLiquidity) private {
        uint256 currentRate =  _getRate();
        uint256 rLiquidity = tLiquidity.mul(currentRate);
        _rOwned[address(this)] = _rOwned[address(this)].add(rLiquidity);
        if(_isExcluded[address(this)])
            _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity);
        emit Transfer(sender, address(this), tLiquidity); // Transparency is the key to success.
    }

    function calculateReflectionFee(uint256 _amount) private view returns (uint256) {
        return _amount.mul(_ratiosActive.reflection).div(masterTaxDivisor);
    }

    function calculateLiquidityFee(uint256 _amount) private view returns (uint256) {
        return _amount.mul((_ratiosActive.liquidity) + (_ratiosActive.marketing)).div(masterTaxDivisor);
    }

}