// File: contracts/FeeCollector.sol



// SPDX-License-Identifier: MIT

pragma solidity 0.8.19;

import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "./interfaces/IUniswapV2Router.sol";
import "./interfaces/IFeeCollector.sol";
import "./interfaces/IStaking.sol";
import "./tokens/InQubeta.sol";

contract FeeCollector is IFeeCollector, AccessControl {
    using SafeERC20 for IERC20;

    struct Fee {
        uint256 Rewards; // The percentage of the total transaction amount that will be allocated to rewards
        uint256 Liquidity; // The percentage of the total transaction amount that will be allocated to liquidity
        uint256 Marketing; // The percentage of the total transaction amount that will be allocated to marketing
        uint256 Burn; // The percentage of the total transaction amount that will be burned
    }

    /// @notice Access Control InQubeta token ERC20 role hash
    bytes32 public constant INQUBETA_ROLE = keccak256("INQUBETA_ROLE");
    /// @notice Access Control InQubeta token ERC20 role hash
    bytes32 public constant ADMIN_UPDATER_ROLE =
        keccak256("ADMIN_UPDATER_ROLE");
    /// @notice Precision for mathematical calculations with percentages. 100% is equivalent to 1e21
    uint256 private constant PRECISION = 1e21;
    /// @notice Variable indicates whether the contract has been initialized
    bool public isInitialized;

    /// @notice The address of the InQubeta token
    address public immutable inQubetaToken;
    /// @notice The address of the Uniswap router contract
    address public immutable swapRouter;
    /// @notice The address where the marketing fees will be sent
    address public marketingRecipient;
    /// @notice The address of the contract responsible for staking
    address public stakingContract;
    /// @notice The value of the distribution of rewards
    uint256 public rewardsAmount;
    /// @notice The value of the liquidity distribution
    uint256 public liquidityAmount;
    /// @notice The value for transfer to marketing wallet
    uint256 public marketingAmount;
    /// @notice The value that will be burned by the token
    uint256 public burnAmount;
    /// @notice The minimum value at which liquidity percentages are within the allowed range
    uint256 public minLiquidity;
    /// @notice timestamp indicating when the current reward period ends
    uint256 public periodFinish;
    /// @notice The duration of each reward period
    uint256 public periodDuration;
    /// @notice The path to the pair token on the Uniswap exchange
    address[] public pathToPairToken;
    /// @notice Record structure before purchases
    Fee public buyFeeInfo;
    /// @notice Record structure before sell
    Fee public sellFeeInfo;

    /// ================================ Errors ================================ ///

    /// @notice An error thrown when an address doesn't have the required access level to execute a function
    error AccessIsDenied(string err);
    /// @notice An error thrown when a given address is not used for a specific operation
    error AddressNotUsed(string err);
    /// @notice An error thrown when a non-contract address is provided where a contract address is expected
    error IsNotContract(string err);
    ///@notice An error thrown when a function is passed a zero address
    error ZeroAddress(string err);
    ///@notice An error thrown when a function is passed an amount of zero
    error ZeroAmount(string err);
    /// @notice An error thrown when a function is passed a value higher than the maximum allowed
    error HighValue(string err);
    /// @notice An error thrown when a function is passed an address that is already in use
    error ExistsAddress(string err);
    /// @notice An error thrown when indicating an invalid timestamp value
    error TimeError(string err);
    //// @notice An error thrown when an attempt is made to initialize a contract that has already been initialized
    error ContractIsAlreadyInitialized(string err);
    /// @notice An error thrown when the path array has an invalid length.
    error InvalidPathLength(string err);
    /// @notice An error thrown when ETH transfer failed
    error TransferFailed(string err);

    /// ================================ Events ================================ ///

    /// Emitted when after rewards are distributed to various addresses
    event Distribute(
        uint256 rewardsAmount,
        uint256 liquidityAmount,
        uint256 marketingAmount,
        uint256 burnAmount,
        uint256 indexed timestamp
    );
    /// Emitted when after successfully updating the fee distribution
    event UpdateDistAmounts(
        bool indexed isBuyFee,
        uint256 rewardsAmount,
        uint256 liquidityAmount,
        uint256 marketingAmount,
        uint256 burnAmount,
        uint256 indexed timestamp
    );
    /// Emitted when after successfully updating the path of the token pair
    event UpdatePathToPairToken(
        address[] indexed pathToPairToken,
        uint256 indexed timestamp
    );
    /// Emitted when after successfully updating the minimum number of tokens required to collect the fee
    event UpdateMinLiquidity(uint256 minLiquidity, uint256 indexed timestamp);
    /// Emitted when after successfully updating the end time of the current period to collect the fee
    event UpdatePeriodFinish(
        uint256 newPerionFinish,
        uint256 indexed timestamp
    );
    /// Emitted when after successfully updating the duration of the commission collection period
    event UpdatePeriodDuration(
        uint256 newPerionDuration,
        uint256 indexed timestamp
    );
    /// Emitted when after successfully updating the staking contract address
    event UpdateStakingContract(
        address indexed stakingContract,
        uint256 indexed timestamp
    );
    /// Emitted when after successfully updating the marketing recipient address
    event UpdateMarketingRecipient(
        address indexed marketingRecipient,
        uint256 indexed timestamp
    );
    /// Emitted when after successfully updating the address of the contract owner
    event UpdateOwner(address newOwner, uint256 indexed timestamp);
    /// @notice Emitted when certain tokens mistakenly sent to the contract
    event RecoverERC20(
        address indexed tokenAddress,
        uint256 tokenAmount,
        address indexed recipient,
        uint256 indexed timestamp
    );
    /// @notice Emitted when transferring funds from the wallet еther of the selected token contract to the specified wallet
    event Recover(
        address indexed to,
        uint256 amount,
        uint256 indexed timestamp
    );

    constructor(
        address _owner, /// The address of the contract owner
        Fee memory _buyFeeAllocations, // The allocation of fees to various purposes for buy transactions
        Fee memory _sellFeeAccocations, // The allocation of fees to various purposes for sell transactions
        address _inqubetaToken, // The address of the InQubeta token contract
        address _uniRouter, // The address of the Uniswap router contract that will be used for swapping tokens
        address _marketingRecipient, // The address to which the marketing fees will be sent
        uint256 _minLiquidity // The minimum value at which liquidity percentages are within the allowed range
    )
        checkMaxFeeAllocations(_buyFeeAllocations)
        checkMaxFeeAllocations(_sellFeeAccocations)
    {
        if (
            !Address.isContract(_inqubetaToken) ||
            !Address.isContract(_uniRouter)
        ) {
            revert IsNotContract("Address is not a contract");
        }
        if (_owner == address(0) || _marketingRecipient == address(0)) {
            revert ZeroAddress("Zero address");
        }

        marketingRecipient = _marketingRecipient;
        buyFeeInfo = _buyFeeAllocations;
        sellFeeInfo = _sellFeeAccocations;
        inQubetaToken = _inqubetaToken;
        swapRouter = _uniRouter;
        minLiquidity = _minLiquidity;
        periodDuration = 1 days;

        _grantRole(ADMIN_UPDATER_ROLE, _owner);
        _grantRole(DEFAULT_ADMIN_ROLE, _owner);
        _grantRole(INQUBETA_ROLE, _inqubetaToken);
        _makeApprove(IERC20(inQubetaToken), swapRouter);
    }

    receive() external payable {}

    /**
     * @notice The modifier checks if the sum of the four values in a Fee struct exceeds a certain precision value
     * @param _fees The sum of the four values Fee
     */
    modifier checkMaxFeeAllocations(Fee memory _fees) {
        if (
            _fees.Rewards + _fees.Liquidity + _fees.Marketing + _fees.Burn !=
            PRECISION
        ) {
            revert HighValue("Percents sum should equal precision");
        }
        _;
    }

    /**
     * @notice The modifier сhecks whether the given path of tokens is valid for swaps
     * @param path The path of tokens to be used for swaps
     */
    modifier isCheckPathToToken(address[] memory path) {
        if (path.length <= 1) {
            revert("Path must contain at least two elements");
        }
        for (uint256 i; i < path.length; i++) {
            if (!Address.isContract(path[i])) {
                revert IsNotContract("Address is not a contract");
            }
        }
        _;
    }

    /**
     * @notice The modifier checks whether the contract has been initialized
     * Prevents reinitialization
     */
    modifier isInited() {
        if (isInitialized) {
            revert ContractIsAlreadyInitialized("Already initialized");
        }
        _;
    }

    /// ================================ External functions ================================ ///

    /**
     * @notice The function initializes some contracts may not exist at the time of deploying this contract
     * @param _stakingContract The address of the staking contract
     * @param _path An array of addresses representing the path to the pair token
     */
    function initialize(
        address _stakingContract,
        address[] memory _path
    ) external onlyRole(DEFAULT_ADMIN_ROLE) isInited isCheckPathToToken(_path) {
        if (!Address.isContract(_stakingContract)) {
            revert IsNotContract("Address is not a contract");
        }

        stakingContract = _stakingContract;
        pathToPairToken = _path;
        periodFinish = block.timestamp + periodDuration;

        _makeApprove(
            IERC20(pathToPairToken[pathToPairToken.length - 1]),
            swapRouter
        );
        isInitialized = true;
    }

    /**
     * @notice External function the buy fees for the distribution period
     * @param amount Value to write
     */
    function recordBuyFee(
        uint256 amount
    ) external override onlyRole(INQUBETA_ROLE) {
        _updateDistAmounts(amount, buyFeeInfo, true);
    }

    /**
     * @notice External function the sell fees for the distribution period
     * @param amount Value to write
     */
    function recordSellFee(
        uint256 amount
    ) external override onlyRole(INQUBETA_ROLE) {
        _updateDistAmounts(amount, sellFeeInfo, false);
    }

    /**
    * @notice External function is used to distribute the collected fees,
    rewards and liquidity to the respective parties if the distribution period has ended
     */
    function distributeIfNeeded() external override {
        if (block.timestamp >= periodFinish) {
            (
                uint256 rewards,
                uint256 marketing,
                uint256 burn,
                uint256 liquidity
            ) = _distribute();

            periodFinish = block.timestamp + periodDuration;
            emit Distribute(
                rewards,
                liquidity,
                marketing,
                burn,
                block.timestamp
            );
        }
    }

    /**
     * @notice An external function that performs the approval of ERC20 tokens for Swap Router
     */
    function approveErc20ForRouter(
        address token
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (token == address(0)) {
            revert ZeroAddress("Zero address");
        }
        _makeApprove(IERC20(token), swapRouter);
    }

    /**
     * @notice External function for certain tokens mistakenly sent to the contract
     * @param tokenAddress The address of the token to be rescued
     * @param tokenAmount The amount of tokens to be rescued
     * @param recipient The address to which the tokens will be sent
     */
    function recoverERC20(
        address tokenAddress,
        uint256 tokenAmount,
        address recipient
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (tokenAddress == inQubetaToken) {
            revert AddressNotUsed("Sending InQubeta token not allowed");
        }
        if (recipient == address(0) || tokenAddress == address(0)) {
            revert ZeroAddress("Zero address");
        }
        if (tokenAmount == 0) {
            revert ZeroAmount("Cannot rescue 0");
        }
        IERC20(tokenAddress).safeTransfer(recipient, tokenAmount);
        emit RecoverERC20(
            tokenAddress,
            tokenAmount,
            recipient,
            block.timestamp
        );
    }

    /**
     * @notice External function for tokens mistakenly sent to the contract
     * @param to The address to which the tokens will be sent
     * @param amount The amount of tokens to be rescued
     */
    function recover(
        address to,
        uint256 amount
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (to == address(0)) {
            revert ZeroAddress("Zero address");
        }
        if (amount == 0) {
            revert ZeroAmount("Cannot rescue 0");
        }

        (bool success, ) = to.call{value: amount}("");
        if (!success) {
            revert TransferFailed("ETH transfer failed");
        }
        emit Recover(to, amount, block.timestamp);
    }

    /**
     * @notice External function update the pair token path using the specified addresses
     * @param newPath The array of token addresses forming a pair of trades is specified in the correct order
     */
    function updatePathToPairToken(
        address[] memory newPath
    ) external onlyRole(DEFAULT_ADMIN_ROLE) isCheckPathToToken(newPath) {
        pathToPairToken = newPath;
        _makeApprove(IERC20(newPath[newPath.length - 1]), swapRouter);
        emit UpdatePathToPairToken(newPath, block.timestamp);
    }

    /**
     * @notice External function update minimum value at which liquidity percentages are within the allowed range
     * @param newMinLiquidity New value at which liquidity percentages are within the allowed range
     */
    function updateMinLiquidity(
        uint256 newMinLiquidity
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        minLiquidity = newMinLiquidity;
        emit UpdateMinLiquidity(newMinLiquidity, block.timestamp);
    }

    /**
     * @notice External function update the end time of the current distribution period
     * @param newPeriodFinish The new end time for the distribution period, in Unix time
     */
    function updatePeriodFinish(
        uint256 newPeriodFinish
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (newPeriodFinish < block.timestamp) {
            revert TimeError("Finish period cannot be in the past");
        }
        periodFinish = newPeriodFinish;
        emit UpdatePeriodFinish(newPeriodFinish, block.timestamp);
    }

    /**
     * @notice External function updates the duration of the distribution period for rewards and fees
     * @param newPeriodDuration The duration time for the distribution period, in Unix time
     */
    function updatePeriodDuration(
        uint256 newPeriodDuration
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (newPeriodDuration == 0) {
            revert ZeroAmount("Duration cannot that zero");
        }
        periodDuration = newPeriodDuration;
        emit UpdatePeriodDuration(newPeriodDuration, block.timestamp);
    }

    /**
     * @notice External function updates the address of the marketing recipient
     * @param newMarketingRecipient The new address of the marketing recipient
     */
    function updateMarketingRecipient(
        address newMarketingRecipient
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (newMarketingRecipient == address(0)) {
            revert ZeroAddress("Zero address");
        }
        if (newMarketingRecipient == marketingRecipient) {
            revert ExistsAddress("No new address specified");
        }

        marketingRecipient = newMarketingRecipient;
        emit UpdateMarketingRecipient(newMarketingRecipient, block.timestamp);
    }

    /**
     * @notice External function updates the address the staking contract
     that is used to distribute rewards to stakers
     * @param newStakingContract The address of the new staking contract
     */
    function updateStakingContract(
        address newStakingContract
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (!Address.isContract(newStakingContract)) {
            revert IsNotContract("Address is not a contract");
        }
        if (newStakingContract == stakingContract) {
            revert ExistsAddress("No new address specified");
        }

        stakingContract = newStakingContract;
        emit UpdateStakingContract(newStakingContract, block.timestamp);
    }

    /**
     * @notice External function update the contract owner
     * @param newOwner Address of the new contract owner
     */
    function updateOwner(
        address newOwner
    ) external onlyRole(ADMIN_UPDATER_ROLE) {
        if (newOwner == address(0)) {
            revert ZeroAddress("Zero address");
        }

        _revokeRole(DEFAULT_ADMIN_ROLE, msg.sender);
        _grantRole(DEFAULT_ADMIN_ROLE, newOwner);
        emit UpdateOwner(newOwner, block.timestamp);
    }

    /// ================================ Internal functions ================================ ///

    /**
    * @notice Internal function is used to distribute the collected fees,
    rewards and liquidity to the respective parties if the distribution period has ended
     */
    function _distribute()
        internal
        returns (
            uint256 rewards,
            uint256 marketing,
            uint256 burn,
            uint256 liquidity
        )
    {
        if (rewardsAmount > 0) {
            IERC20(inQubetaToken).transfer(stakingContract, rewardsAmount);
            IStaking(stakingContract).notifyRewardAmount(rewardsAmount);
            rewards = rewardsAmount;
            rewardsAmount = 0;
        }
        if (marketingAmount > 0) {
            IERC20(inQubetaToken).transfer(marketingRecipient, marketingAmount);
            marketing = marketingAmount;
            marketingAmount = 0;
        }
        if (burnAmount > 0) {
            InQubeta(inQubetaToken).burn(burnAmount);
            burn = burnAmount;
            burnAmount = 0;
        }
        if (liquidityAmount > minLiquidity) {
            uint256 processAmount = _swapAndAddLiquidity(liquidityAmount);
            liquidity = liquidityAmount - processAmount;
            liquidityAmount = processAmount;
        }
    }

    /**
    * @notice The function is intended for the distribution of fee amounts between different roles
    (the distribution of the fee is carried out according to the transferred Fee object)
    * @param amount The amount of remuneration to be distributed between different roles
     */
    function _updateDistAmounts(
        uint256 amount,
        Fee memory _fees,
        bool isBuyFee
    ) internal {
        rewardsAmount += (amount * _fees.Rewards) / PRECISION;
        liquidityAmount += (amount * _fees.Liquidity) / PRECISION;
        marketingAmount += (amount * _fees.Marketing) / PRECISION;
        burnAmount += (amount * _fees.Burn) / PRECISION;
        emit UpdateDistAmounts(
            isBuyFee,
            rewardsAmount,
            liquidityAmount,
            marketingAmount,
            burnAmount,
            block.timestamp
        );
    }

    /**
     * @notice Internal function is designed to exchange half of the transferred amount
     for a pair of tokens and add the received liquidity to the UniswapV2 pair
     * @param amount The amount of tokens to be exchanged and added to the pair
     */
    function _swapAndAddLiquidity(uint256 amount) internal returns (uint256) {
        InQubeta(inQubetaToken).disableFees();

        uint256 processAmount = amount;

        uint256[] memory amounts = IUniswapV2Router(swapRouter)
            .swapExactTokensForTokens(
                amount / 2,
                0,
                pathToPairToken,
                address(this),
                block.timestamp
            );

        processAmount -= amounts[0];

        (uint256 amountA, , ) = IUniswapV2Router(swapRouter).addLiquidity(
            pathToPairToken[0],
            pathToPairToken[pathToPairToken.length - 1],
            amounts[0],
            amounts[amounts.length - 1],
            1,
            1,
            address(this),
            block.timestamp
        );

        processAmount -= amountA;

        InQubeta(inQubetaToken).enableFees();

        return processAmount;
    }

    /**
     * @notice Internal function is intended to grant permission to spend tokens
     of the specified token to the specified manager of funds
     * @param token The interface of the ERC20 token to be authorized
     * @param spender The address to be granted
     */
    function _makeApprove(IERC20 token, address spender) internal {
        uint256 allowance = token.allowance(address(this), spender);
        if (allowance < type(uint256).max) {
            token.safeIncreaseAllowance(spender, type(uint256).max - allowance);
        }
    }
}

// File: @openzeppelin/contracts/utils/Address.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.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 functionCall(target, data, "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");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason 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 {
            // 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

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

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



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

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

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

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

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) external returns (bool);
}

// File: @openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

// File: @openzeppelin/contracts/access/AccessControl.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (access/AccessControl.sol)

pragma solidity ^0.8.0;

import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
        return _roles[role].members[account];
    }

    /**
     * @dev Revert with a standard message if `_msgSender()` is missing `role`.
     * Overriding this function changes the behavior of the {onlyRole} modifier.
     *
     * Format of the revert message is described in {_checkRole}.
     *
     * _Available since v4.6._
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        Strings.toHexString(uint160(account), 20),
                        " is missing role ",
                        Strings.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) public virtual override {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     *
     * NOTE: This function is deprecated in favor of {_grantRole}.
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * Internal function without access restriction.
     */
    function _grantRole(bytes32 role, address account) internal virtual {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * Internal function without access restriction.
     */
    function _revokeRole(bytes32 role, address account) internal virtual {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }
}

// File: contracts/interfaces/IUniswapV2Router.sol



// SPDX-License-Identifier: MIT

pragma solidity 0.8.19;

interface IUniswapV2Router {
    function factory() external pure returns (address);

    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint256 amountADesired,
        uint256 amountBDesired,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountA, uint256 amountB, uint256 liquidity);

    function addLiquidityETH(
        address token,
        uint256 amountTokenDesired,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    )
        external
        payable
        returns (uint256 amountToken, uint256 amountETH, uint256 liquidity);

    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint256 liquidity,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountA, uint256 amountB);

    function removeLiquidityETH(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline
    ) external returns (uint256 amountToken, uint256 amountETH);

    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint256 liquidity,
        uint256 amountAMin,
        uint256 amountBMin,
        address to,
        uint256 deadline,
        bool approveMax,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (uint256 amountA, uint256 amountB);

    function removeLiquidityETHWithPermit(
        address token,
        uint256 liquidity,
        uint256 amountTokenMin,
        uint256 amountETHMin,
        address to,
        uint256 deadline,
        bool approveMax,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external returns (uint256 amountToken, uint256 amountETH);

    function swapExactTokensForTokens(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapTokensForExactTokens(
        uint256 amountOut,
        uint256 amountInMax,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapExactETHForTokens(
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external payable returns (uint256[] memory amounts);

    function swapTokensForExactETH(
        uint256 amountOut,
        uint256 amountInMax,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapExactTokensForETH(
        uint256 amountIn,
        uint256 amountOutMin,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external returns (uint256[] memory amounts);

    function swapETHForExactTokens(
        uint256 amountOut,
        address[] calldata path,
        address to,
        uint256 deadline
    ) external payable returns (uint256[] memory amounts);

    function quote(
        uint256 amountA,
        uint256 reserveA,
        uint256 reserveB
    ) external pure returns (uint256 amountB);

    function getAmountOut(
        uint256 amountIn,
        uint256 reserveIn,
        uint256 reserveOut
    ) external pure returns (uint256 amountOut);

    function getAmountIn(
        uint256 amountOut,
        uint256 reserveIn,
        uint256 reserveOut
    ) external pure returns (uint256 amountIn);

    function getAmountsOut(
        uint256 amountIn,
        address[] calldata path
    ) external view returns (uint256[] memory amounts);

    function getAmountsIn(
        uint256 amountOut,
        address[] calldata path
    ) external view returns (uint256[] memory amounts);
}
// File: contracts/interfaces/IFeeCollector.sol



// SPDX-License-Identifier: MIT

pragma solidity 0.8.19;

interface IFeeCollector {
    function recordBuyFee(uint amount) external;

    function recordSellFee(uint amount) external;

    function distributeIfNeeded() external;
}
// File: contracts/interfaces/IStaking.sol



// SPDX-License-Identifier: MIT

pragma solidity 0.8.19;

interface IStaking {
    function notifyRewardAmount(uint256 reward) external;
}
// File: contracts/tokens/InQubeta.sol



// SPDX-License-Identifier: MIT

pragma solidity 0.8.19;

import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "../interfaces/IFeeCollector.sol";

contract InQubeta is ERC20, ERC20Burnable, AccessControl {
    /// @notice Precision for mathematical calculations with percents. 100% === 10000
    uint256 private constant PRECISION = 100_00;
    /// @notice Access Control fee collector role hash
    bytes32 public constant FEE_DISTRIBUTION_ROLE =
        keccak256("FEE_DISTRIBUTION_ROLE");
    /// @notice fee collector address
    address public feeCollector;
    /// @notice the percentage of the fee charged for the purchase of the token
    uint256 public buyFee;
    /// @notice the percentage of the fee charged for the selling of the token
    uint256 public sellFee;
    /// @notice bool value, if true, fees is enabled, if false, disabled
    bool public isEnabledFees;
    /// @notice pair mapping, if true the pair is added and fees are charged,
    /// if false, no fees are charged
    mapping(address => bool) public pairs;

    /// ================================ Errors ================================ ///

    /// @dev - address is not a contract;
    error IsNotContract(string err);
    ///@dev returned if passed zero address
    error ZeroAddress(string err);
    ///@dev returned if passed zero amount
    error ZeroAmount(string err);
    ///@dev returned if the set percentage is equal to or greater than PRECISION
    error HighValue(string err);
    ///@dev returned if the pair address already exists
    error ExistsAddress(string err);
    ///@dev returned if the value already assigned
    error ExistsValue(string err);
    ///@dev returned if the pair address has not been added
    error NotFoundAddress(string err);
    ///@dev returned if the caller dont have access to function
    error AccessIsDenied(string err);

    /// ================================ Events ================================ ///

    ///@dev emitted when owner add new pair
    event AddPair(
        address indexed addressPair,
        bool enabled,
        uint256 indexed timestamp
    );
    ///@dev emitted when owner set fee percents
    event SetFees(uint256 buyFee, uint256 sellFee, uint256 indexed timestamp);
    ///@dev emitted when owner update fee collector address
    event UpdateFeeCollector(
        address indexed feeCollector,
        uint256 indexed timestamp
    );
    ///@dev emitted when fees enabled
    event EnableFees(bool indexed enabled, uint256 indexed timestamp);
    ///@dev emitted when fees disabled
    event DisableFees(bool indexed enabled, uint256 indexed timestamp);
    ///@dev emitted when owner disable pair address
    event RemovePair(
        address indexed addressPair,
        bool disable,
        uint256 indexed timestamp
    );
    ///@dev emitted when buy fee is updated for all pairs
    event UpdateBuyFee(uint256 buyFee, uint256 indexed timestamp);
    ///@dev emitted when sell fee is updated for all pairs
    event UpdateSellFee(uint256 buyFee, uint256 indexed timestamp);

    constructor(
        address _admin, /// contract owner
        uint256 _initialSupply, /// total supply of tokens
        uint256 _buyFee, /// buy fee percent. 5% * 100 = 500
        uint256 _sellFee, /// buy fee percent. 10% * 100 = 1000
        address _feeCollector /// fee collector contract addrees
    ) ERC20("InQubeta", "QUBE") checkMaxFee(_buyFee, _sellFee) {
        if (_feeCollector == address(0) || _admin == address(0)) {
            revert ZeroAddress("InQubeta: Zero address");
        }
        if (!Address.isContract(_feeCollector)) {
            revert IsNotContract("InQubeta: Fee collector is not a contract");
        }

        _mint(_admin, _initialSupply);
        feeCollector = _feeCollector;

        _grantRole(DEFAULT_ADMIN_ROLE, _admin);
        _grantRole(FEE_DISTRIBUTION_ROLE, _admin);
        _grantRole(FEE_DISTRIBUTION_ROLE, _feeCollector);

        buyFee = _buyFee;
        sellFee = _sellFee;
        isEnabledFees = true;
    }

    /**
    @dev the modifier checks whether the commission percentages 
    are within the allowed range
    */
    modifier checkMaxFee(uint256 _buyFee, uint256 _sellFee) {
        if (_buyFee >= PRECISION || _sellFee >= PRECISION) {
            revert HighValue("InQubeta: Fee value is too high");
        }
        _;
    }

    /**
     * @notice The function performs an ERC20 transfer, but with some modifications. In the event
     *  that the token will be sent to the pool that is added to our contract, the sell commission
     *  will be charged from the number of tokens sent. If the token will
     *  be sent from the pool, the buy fee will be charged from the number of tokens sent.
     * If it is a normal transfer that is not sent to or from the pool,
     * it will work as a standard ERC20 transfer
     */
    function transfer(
        address to,
        uint256 amount
    ) public virtual override returns (bool) {
        return _transferFrom(msg.sender, to, amount);
    }

    /**
     * @notice The function performs an ERC20 transferFrom, but with some modifications. In the event
     *  that the token will be sent to the pool that is added to our contract, the sell commission
     *  will be charged from the number of tokens sent. If the token will
     *  be sent from the pool, the buy fee will be charged from the number of tokens sent.
     *  If it is a normal transferFrom that is not sent to or from the pool,
     *  it will work as a standard ERC20 transferFrom.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual override returns (bool) {
        _spendAllowance(from, msg.sender, amount);
        return _transferFrom(from, to, amount);
    }

    /**
     * @notice The function adds a new pair from which commissions will be charged
     * for the purchase and sale of our token. Only the owner can call.
     * @param addressPair - pair address
     */
    function addPair(
        address addressPair
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (addressPair == address(0)) {
            revert ZeroAddress("InQubeta: Zero address");
        }

        if (pairs[addressPair]) {
            revert ExistsAddress("InQubeta: Address already exists");
        }

        pairs[addressPair] = true;
        emit AddPair(addressPair, true, block.timestamp);
    }

    /**
     * @notice The function performs disabling pool.
     * Only the owner can call.
     * @param addressPair - pair address
     */
    function removePair(
        address addressPair
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (addressPair == address(0)) {
            revert ZeroAddress("InQubeta: Zero address");
        }

        pairs[addressPair] = false;
        emit RemovePair(addressPair, false, block.timestamp);
    }

    /**
     * @notice The function performs disabling buy and sell fees.
     * Only the default admin or fee collector can call it.
     */
    function disableFees() external onlyRole(FEE_DISTRIBUTION_ROLE) {
        isEnabledFees = false;
        emit DisableFees(false, block.timestamp);
    }

    /**
     * @notice The function performs enabling buy and sell fees.
     * Only the default admin or fee collector can call it.
     */
    function enableFees() external onlyRole(FEE_DISTRIBUTION_ROLE) {
        isEnabledFees = true;
        emit EnableFees(true, block.timestamp);
    }

    /**
     * @notice The function updates the buy fee percentage.
     * Only the owner can call.
     * @param _buyFee - sell fee percent
     */
    function updateBuyFee(
        uint256 _buyFee
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (_buyFee >= PRECISION) {
            revert HighValue("InQubeta: Fee value is too high");
        }

        buyFee = _buyFee;
        emit UpdateBuyFee(_buyFee, block.timestamp);
    }

    /**
     * @notice The function updates the sell fee percentage.
     * Only the owner can call.
     * @param _sellFee - sell fee percent
     */
    function updateSellFee(
        uint256 _sellFee
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (_sellFee >= PRECISION) {
            revert HighValue("InQubeta: Fee value is too high");
        }

        sellFee = _sellFee;
        emit UpdateSellFee(_sellFee, block.timestamp);
    }

    /**
     * @notice The function updates the settings of commission percentages
     * for buying and selling. Only the owner can call.
     * @param _buyFee - buy fee percent
     * @param _sellFee - sell fee percent
     */
    function updateFeesPercents(
        uint256 _buyFee,
        uint256 _sellFee
    ) external onlyRole(DEFAULT_ADMIN_ROLE) checkMaxFee(_buyFee, _sellFee) {
        buyFee = _buyFee;
        sellFee = _sellFee;

        emit SetFees(_buyFee, _sellFee, block.timestamp);
    }

    /**
     * @notice The function updates the address that receives all commissions.
     * Only the owner can call.
     * @param newFeeCollector - new fee collector address
     */
    function updateFeeCollector(
        address newFeeCollector
    ) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (newFeeCollector == address(0)) {
            revert ZeroAddress("InQubeta: Zero address");
        }
        if (newFeeCollector == feeCollector) {
            revert ExistsAddress("InQubeta: No new address specified");
        }
        if (!Address.isContract(newFeeCollector)) {
            revert IsNotContract("InQubeta: Fee collector is not a contract");
        }
        revokeRole(FEE_DISTRIBUTION_ROLE, feeCollector);
        feeCollector = newFeeCollector;
        grantRole(FEE_DISTRIBUTION_ROLE, newFeeCollector);

        emit UpdateFeeCollector(newFeeCollector, block.timestamp);
    }

    /**
     * @notice Internal function that implements the logic of token transfer and the logic of fee collection.
     */
    function _transferFrom(
        address from,
        address to,
        uint256 amount
    ) internal returns (bool) {
        if (isEnabledFees) {
            if (pairs[to]) {
                uint256 fee = (amount * sellFee) / PRECISION;
                uint256 transferAmount = amount - fee;
                _transfer(from, feeCollector, fee);
                _transfer(from, to, transferAmount);
                IFeeCollector(feeCollector).recordSellFee(fee);
            } else if (pairs[from]) {
                uint256 fee = (amount * buyFee) / PRECISION;
                _transfer(from, to, amount);
                _transfer(to, feeCollector, fee);
                IFeeCollector(feeCollector).recordBuyFee(fee);
            } else {
                _transfer(from, to, amount);
            }
        } else {
            _transfer(from, to, amount);
        }
        return true;
    }
}

// File: @openzeppelin/contracts/access/IAccessControl.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) external;
}

// File: @openzeppelin/contracts/utils/Context.sol



// SPDX-License-Identifier: MIT
// 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/utils/Strings.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _HEX_SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }
}

// File: @openzeppelin/contracts/utils/introspection/ERC165.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

// File: @openzeppelin/contracts/utils/introspection/IERC165.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

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



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

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless this function is
     * overridden;
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address to, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual override returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, amount);
        _transfer(from, to, amount);
        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, allowance(owner, spender) + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        address owner = _msgSender();
        uint256 currentAllowance = allowance(owner, spender);
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(owner, spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `sender` to `recipient`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     */
    function _transfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
        }
        _balances[to] += amount;

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        _totalSupply -= amount;

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}
}

// File: @openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/extensions/ERC20Burnable.sol)

pragma solidity ^0.8.0;

import "../ERC20.sol";
import "../../../utils/Context.sol";

/**
 * @dev Extension of {ERC20} that allows token holders to destroy both their own
 * tokens and those that they have an allowance for, in a way that can be
 * recognized off-chain (via event analysis).
 */
abstract contract ERC20Burnable is Context, ERC20 {
    /**
     * @dev Destroys `amount` tokens from the caller.
     *
     * See {ERC20-_burn}.
     */
    function burn(uint256 amount) public virtual {
        _burn(_msgSender(), amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, deducting from the caller's
     * allowance.
     *
     * See {ERC20-_burn} and {ERC20-allowance}.
     *
     * Requirements:
     *
     * - the caller must have allowance for ``accounts``'s tokens of at least
     * `amount`.
     */
    function burnFrom(address account, uint256 amount) public virtual {
        _spendAllowance(account, _msgSender(), amount);
        _burn(account, amount);
    }
}

// File: @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}