// File: contracts/ColiseumMining.sol



// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "./IERC721A.sol";

/// @title ColiseumMiningAllocation
/// @dev This contract manages the allocation of USDC/USDT based on user's tier
contract ColiseumMiningAllocation is Ownable, ReentrancyGuard {
    // Interfaces for interacting with external token contracts
    IERC20 private usdc = IERC20(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);
    IERC20 private usdt = IERC20(0xdAC17F958D2ee523a2206206994597C13D831ec7);
    IERC721A private soulbounds =
        IERC721A(0xCE37F9052E0f3f8E56887d8496FcD6cd6BeC06d0);
    IERC721A private stakedTokens =
        IERC721A(0xe07d6a4b99017aB280115f8711067871A4450640);
    IERC721A private vestedTokens =
        IERC721A(0x575D99d27ffF5974d608b7089404daDc9e291aca);
    IERC721A private normalTokens =
        IERC721A(0x08244aC887bb5d8d689315ce6335D742350133E6);

    /// @dev Structure to hold allocation information per user.
    struct Allocation {
        uint256 usdAllocated;
        uint256 allocationTimestamp;
    }

    /// @dev Counter to keep track of the total number of allocations.
    uint256 public totalAllocations;

    /// @dev Mapping from counter ID to user's address.
    mapping(uint256 => address) public idToAddress;

    /// @dev Mapping for tier 1.
    mapping(address => bool) public userAllowlisted;

    /// @dev Mapping of user address to their allocation information.
    mapping(address => Allocation) private allocations;

    constructor() Ownable(msg.sender) {
        userAllowlisted[0xb65e896544f2742E2F913E28eA00DaeaaF79C27c] = true;
        userAllowlisted[0x44F4e6c03B05bA04A08E2311040c85DC492493Ef] = true;
        userAllowlisted[0x2E12D1E5d81F9e4c50879Ee61C1483DF8160b2EE] = true;
        userAllowlisted[0xdF9092DcF734b7A036C9D42160E796541216Be3F] = true;
        userAllowlisted[0x0F615319D7CeeD5801faF6b13C9034DE9223a3eC] = true;
        userAllowlisted[0x1CB1c4b0A13B5E542cE3181C1dE845396e967C5a] = true;
        userAllowlisted[0xF0bF1C59ee9b78A2Ce5763165e1B6B24Cb35fD8A] = true;
        userAllowlisted[0x132371B1D1415C47C3441566c5bC2010364fD167] = true;
        userAllowlisted[0x88Fe79E3e74bB28faAF1532AaFF4d2cDDb594F74] = true;
        userAllowlisted[0x9e3DF23C284ceF828438a4143D6BdD950de54C82] = true;
        userAllowlisted[0xAedaD68EAfa16Dc0E4c231A02273A93d574323Ca] = true;
        userAllowlisted[0xB2030A19bC762Fe0E86aD8B5279865e2024dC6f7] = true;
        userAllowlisted[0x47664CD441143Be6553B6e7A57d8Fee9B7479B49] = true;
        userAllowlisted[0x241AbeFc7014e7c38831bbAf8800d54f15C64CC5] = true;
        userAllowlisted[0xB2a3041Dd3C35AeF30Dfc3B67096F67f7274146f] = true;
        userAllowlisted[0x8C0ccB514819DD2fb7888D7a9b1De3D75EA085bC] = true;
        userAllowlisted[0x68AD1Fa00cB9D499B73e85c6449766374463B6B2] = true;
        userAllowlisted[0x77410ab3B8775A8164c9BBBa92B64B341Be7b402] = true;
        userAllowlisted[0xB8ea3836bd58575360E3F012F781456291912ff1] = true;
        userAllowlisted[0x88B7bB15024D9cb9D506Bb21F3dC67f50294EB8C] = true;
        userAllowlisted[0x39f9A70a9a370793C6403b6796Bf49cE3ce9D65D] = true;
        userAllowlisted[0xbe5BE78a570126E6D66E0E5C211d4be03878a760] = true;
        userAllowlisted[0x1929e51F2151dF522F27C748b78a6F9F314A3138] = true;
        userAllowlisted[0xcCaE544F936daE9D7f588269BAD6F3F86DcdF2E4] = true;
        userAllowlisted[0x8cA64fb828A2Ad2C977A28A7e7a723Bf1b877Ee8] = true;
        userAllowlisted[0x5A432ecb3776d8bEEA169c31E5a460FFE24706Ab] = true;
        userAllowlisted[0x47664CD441143Be6553B6e7A57d8Fee9B7479B49] = true;
        userAllowlisted[0x9b4c11981D6d62a8b7d8007Dd1fa253F2Fc1f846] = true;
        userAllowlisted[0xEa2271D3484143F2A7e2A950A93e372906da8240] = true;
        userAllowlisted[0x0280991b064204C1118E13C071e5201bA870e20d] = true;
        userAllowlisted[0x0E84776F50D9C4b70020165edbA16b69e78E989C] = true;
        userAllowlisted[0x7E0e14b8Af95B8724eB9C6Fc6f7F38e55D0e197C] = true;
        userAllowlisted[0xD1CE3Ebb36C00E68ADd5E7C8343489D102283811] = true;
        userAllowlisted[0x1830A2e92ce6BF9EAc68E99692584544fF284024] = true;
        userAllowlisted[0xe1343b0557378b6Cd915C33AbBCB264d64D81BBe] = true;
        userAllowlisted[0x3bF165E64D853ACc3cCE25a23295eaDc69A03E19] = true;
        userAllowlisted[0xb65e896544f2742E2F913E28eA00DaeaaF79C27c] = true;
        userAllowlisted[0xa392D363B81620B0e78adF0f7e650F1bF3892E07] = true;
        userAllowlisted[0xbd5beaa49b793D35db39a79022ee70EBadB007bf] = true;
    }

    /// @dev Modifier to check the allocation eligibility based on tier.
    modifier checkAllocationLimit(uint256 amount) {
        uint256 userTier = getUserTier(msg.sender);
        require(userTier > 0, "Not eligible for allocation");
        if (userTier == 1) {
            _;
        } else if (
            userTier == 2 &&
            allocations[msg.sender].usdAllocated + amount * 1e6 <= 10000 * 1e6
        ) {
            _;
        } else if (
            userTier == 3 &&
            allocations[msg.sender].usdAllocated + amount * 1e6 <= 5000 * 1e6
        ) {
            _;
        } else if (
            userTier == 4 &&
            allocations[msg.sender].usdAllocated + amount * 1e6 <= 2500 * 1e6
        ) {
            _;
        } else if (
            userTier == 5 &&
            allocations[msg.sender].usdAllocated + amount * 1e6 <= 1000 * 1e6
        ) {
            _;
        } else {
            revert("Allocation limit exceeded");
        }
    }

    /// @notice Determines user tier based on their token holdings.
    /// @param user The address of the user.
    /// @return The tier of the user.
    function getUserTier(address user) public view returns (uint256) {
        uint256 staked = stakedTokens.balanceOf(user);
        uint256 vested = vestedTokens.balanceOf(user);
        uint256 normal = normalTokens.balanceOf(user);
        uint256 sbt = soulbounds.balanceOf(user);
        if (((staked + vested) > 2) || userAllowlisted[user] == true) {
            return 1;
        } else if (staked + vested + normal > 2) {
            return 2;
        } else if (staked + vested > 0) {
            return 3;
        } else if (normal > 0) {
            return 4;
        } else if (sbt == 1) {
            return 5;
        } else {
            return 0;
        }
    }

    /// @notice Allows users to allocate USDC or USDT.
    /// @param amount The amount of USDC or USDT to allocate.
    function allocate(
        uint256 amount
    ) external checkAllocationLimit(amount) nonReentrant {
        uint256 usdcBalance = usdc.balanceOf(msg.sender);
        if(amount == 0) revert ("Amount cannot be 0");
        if (usdcBalance >= amount * 1e6) {
            require(
                usdc.transferFrom(msg.sender, address(this), amount * 1e6),
                "USDC transfer failed"
            );
        } else {
            uint256 usdtBalance = usdt.balanceOf(msg.sender);

            require(usdtBalance >= amount * 1e6, "Insufficient USDT balance");

            require(
                usdt.transferFrom(msg.sender, address(this), amount * 1e6),
                "USDT transfer failed"
            );
        }

        // Check if this is a new allocation, if yes, increment counter and update mapping.
        if (allocations[msg.sender].usdAllocated == 0) {
            totalAllocations += 1;
            idToAddress[totalAllocations] = msg.sender;
        }
        allocations[msg.sender].usdAllocated += amount * 1e6;
        allocations[msg.sender].allocationTimestamp = block.timestamp;
    }

    /// @notice Allows owner to withdraw all USDC.
    function withdrawUSDC() external onlyOwner {
        uint256 usdcBalance = usdc.balanceOf(address(this));
        require(usdc.transfer(msg.sender, usdcBalance), "USDC transfer failed");
    }

    /// @notice Allows owner to withdraw all USDT.
    function withdrawUSDT() external onlyOwner {
        uint256 usdtBalance = usdt.balanceOf(address(this));
        require(usdt.transfer(msg.sender, usdtBalance), "USDC transfer failed");
    }

    /// @notice Allows owner to withdraw all USDC using transferFrom.
    function alternativeWithdrawUSDC() external onlyOwner {
        uint256 usdcBalance = usdc.balanceOf(address(this));
        require(
            usdc.transferFrom(address(this), msg.sender, usdcBalance),
            "USDC transferFrom failed"
        );
    }

    /// @notice Allows owner to withdraw all USDT using transferFrom.
    function alternativeWithdrawUSDT() external onlyOwner {
        uint256 usdtBalance = usdt.balanceOf(address(this));
        require(
            usdt.transferFrom(address(this), msg.sender, usdtBalance),
            "USDT transferFrom failed"
        );
    }

    /// @notice Allows owner to withdraw all ETH.
    function withdraw() external onlyOwner {
        uint256 ethBalance = address(this).balance;
        payable(msg.sender).transfer(ethBalance);
    }

    /**
     * @notice Allows the owner to withdraw any ERC20 token.
     * @dev Only callable by the owner of the contract.
     * @param tokenAddress The address of the ERC20 token to be withdrawn.
     */
    function withdrawToken(address tokenAddress) external onlyOwner {
        IERC20 token = IERC20(tokenAddress);
        uint256 tokenBalance = token.balanceOf(address(this));
        require(
            token.transfer(msg.sender, tokenBalance),
            "Token transfer failed"
        );
    }

    /**
     * @notice Updates the address of the USDC token contract.
     * @dev Only callable by the owner of the contract.
     * @param _usdc The new address of the USDC token contract.
     */
    function setUSDC(address _usdc) external onlyOwner {
        usdc = IERC20(_usdc);
    }

    /**
     * @notice Updates the address of the USDT token contract.
     * @dev Only callable by the owner of the contract.
     * @param _usdt The new address of the USDT token contract.
     */
    function setUSDT(address _usdt) external onlyOwner {
        usdt = IERC20(_usdt);
    }

    /**
     * @notice Updates the address of the Soulbounds token contract.
     * @dev Only callable by the owner of the contract.
     * @param _soulbounds The new address of the Soulbounds token contract.
     */
    function setSoulbounds(address _soulbounds) external onlyOwner {
        soulbounds = IERC721A(_soulbounds);
    }

    /**
     * @notice Updates the address of the StakedTokens token contract.
     * @dev Only callable by the owner of the contract.
     * @param _stakedTokens The new address of the StakedTokens token contract.
     */
    function setStakedTokens(address _stakedTokens) external onlyOwner {
        stakedTokens = IERC721A(_stakedTokens);
    }

    /**
     * @notice Updates the address of the VestedTokens token contract.
     * @dev Only callable by the owner of the contract.
     * @param _vestedTokens The new address of the VestedTokens token contract.
     */
    function setVestedTokens(address _vestedTokens) external onlyOwner {
        vestedTokens = IERC721A(_vestedTokens);
    }

    /**
     * @notice Updates the address of the NormalTokens token contract.
     * @dev Only callable by the owner of the contract.
     * @param _normalTokens The new address of the NormalTokens token contract.
     */
    function setNormalTokens(address _normalTokens) external onlyOwner {
        normalTokens = IERC721A(_normalTokens);
    }

    /// @notice Allows the contract to approve a user to transfer a specified amount of its tokens.
    /// @param tokenAddress The address of the token (USDT/USDC).
    /// @param user The address of the user to be approved.
    /// @param amount The amount of tokens to approve.
    function approveTokenTransfer(
        address tokenAddress,
        address user,
        uint256 amount
    ) external onlyOwner {
        IERC20 token = IERC20(tokenAddress);
        require(token.approve(user, amount), "Token approval failed");
    }

    /// @notice Retrieves a user's allocation information.
    /// @param user The address of the user.
    /// @return Allocation structure containing the user's allocation info.
    function getAllocation(
        address user
    ) external view returns (Allocation memory) {
        return allocations[user];
    }

    /// @notice Retrieves the timestamp of allocation for a specific user.
    /// @param _user The address of the user.
    /// @return The timestamp of when the user made an allocation.
    function getAllocationTimestampOfUser(
        address _user
    ) external view returns (uint256) {
        return allocations[_user].allocationTimestamp;
    }

    /// @notice Retrieves the amount of USDC allocated by a specific user.
    /// @param _user The address of the user.
    /// @return The amount of USDC the user has allocated.
    function getAllocatedUSDOfUser(
        address _user
    ) external view returns (uint256) {
        return allocations[_user].usdAllocated;
    }

    /// @notice Adds multiple addresses to the allowlist.
    /// @param addresses An array of addresses to be added to the allowlist.
    function addToAllowlist(address[] calldata addresses) external onlyOwner {
        for (uint256 i = 0; i < addresses.length; i++) {
            userAllowlisted[addresses[i]] = true;
        }
    }

    /// @notice Removes multiple addresses from the allowlist.
    /// @param addresses An array of addresses to be removed from the allowlist.
    function removeFromAllowlist(
        address[] calldata addresses
    ) external onlyOwner {
        for (uint256 i = 0; i < addresses.length; i++) {
            userAllowlisted[addresses[i]] = false;
        }
    }

    /// @notice Returns the allocation information of all users.
    /// @return An array of tuples, where each tuple contains an address and an Allocation struct.
    function getAllAllocations()
        external
        view
        returns (address[] memory, Allocation[] memory)
    {
        address[] memory allAddresses = new address[](totalAllocations);
        Allocation[] memory allAllocations = new Allocation[](totalAllocations);

        for (uint256 i = 1; i <= totalAllocations; i++) {
            address userAddress = idToAddress[i];
            allAddresses[i - 1] = userAddress;
            allAllocations[i - 1] = allocations[userAddress];
        }

        return (allAddresses, allAllocations);
    }
}

// File: contracts/IERC721A.sol



// SPDX-License-Identifier: MIT
// ERC721A Contracts v4.2.3
// Creator: Chiru Labs

pragma solidity ^0.8.4;

/**
 * @dev Interface of ERC721A.
 */
interface IERC721A {
    /**
     * The caller must own the token or be an approved operator.
     */
    error ApprovalCallerNotOwnerNorApproved();

    /**
     * The token does not exist.
     */
    error ApprovalQueryForNonexistentToken();

    /**
     * Cannot query the balance for the zero address.
     */
    error BalanceQueryForZeroAddress();

    /**
     * Cannot mint to the zero address.
     */
    error MintToZeroAddress();

    /**
     * The quantity of tokens minted must be more than zero.
     */
    error MintZeroQuantity();

    /**
     * The token does not exist.
     */
    error OwnerQueryForNonexistentToken();

    /**
     * The caller must own the token or be an approved operator.
     */
    error TransferCallerNotOwnerNorApproved();

    /**
     * The token must be owned by `from`.
     */
    error TransferFromIncorrectOwner();

    /**
     * Cannot safely transfer to a contract that does not implement the
     * ERC721Receiver interface.
     */
    error TransferToNonERC721ReceiverImplementer();

    /**
     * Cannot transfer to the zero address.
     */
    error TransferToZeroAddress();

    /**
     * The token does not exist.
     */
    error URIQueryForNonexistentToken();

    /**
     * The `quantity` minted with ERC2309 exceeds the safety limit.
     */
    error MintERC2309QuantityExceedsLimit();

    /**
     * The `extraData` cannot be set on an unintialized ownership slot.
     */
    error OwnershipNotInitializedForExtraData();

    // =============================================================
    //                            STRUCTS
    // =============================================================

    struct TokenOwnership {
        // The address of the owner.
        address addr;
        // Stores the start time of ownership with minimal overhead for tokenomics.
        uint64 startTimestamp;
        // Whether the token has been burned.
        bool burned;
        // Arbitrary data similar to `startTimestamp` that can be set via {_extraData}.
        uint24 extraData;
    }

    // =============================================================
    //                         TOKEN COUNTERS
    // =============================================================

    /**
     * @dev Returns the total number of tokens in existence.
     * Burned tokens will reduce the count.
     * To get the total number of tokens minted, please see {_totalMinted}.
     */
    function totalSupply() external view returns (uint256);

    // =============================================================
    //                            IERC165
    // =============================================================

    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified)
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);

    // =============================================================
    //                            IERC721
    // =============================================================

    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables
     * (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in `owner`'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`,
     * checking first that contract recipients are aware of the ERC721 protocol
     * to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be have been allowed to move
     * this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement
     * {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes calldata data
    ) external payable;

    /**
     * @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external payable;

    /**
     * @dev Transfers `tokenId` from `from` to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {safeTransferFrom}
     * whenever possible.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token
     * by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external payable;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the
     * zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external payable;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom}
     * for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the caller.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool _approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}.
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);

    // =============================================================
    //                        IERC721Metadata
    // =============================================================

    /**
     * @dev Returns the token collection name.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the token collection symbol.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
     */
    function tokenURI(uint256 tokenId) external view returns (string memory);

    // =============================================================
    //                           IERC2309
    // =============================================================

    /**
     * @dev Emitted when tokens in `fromTokenId` to `toTokenId`
     * (inclusive) is transferred from `from` to `to`, as defined in the
     * [ERC2309](https://eips.ethereum.org/EIPS/eip-2309) standard.
     *
     * See {_mintERC2309} for more details.
     */
    event ConsecutiveTransfer(uint256 indexed fromTokenId, uint256 toTokenId, address indexed from, address indexed to);
}
// File: @openzeppelin/contracts/security/ReentrancyGuard.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == _ENTERED;
    }
}

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



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

pragma solidity ^0.8.20;

/**
 * @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 value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` 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 value) external returns (bool);
}

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



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

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



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @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;
    }
}