{"sources":{"npm/@openzeppelin/contracts@5.6.1/access/Ownable.sol":{"content":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)\n\npragma solidity ^0.8.20;\n\nimport {Context} from \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * The initial owner is set to the address provided by the deployer. This can\n * later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n    address private _owner;\n\n    /**\n     * @dev The caller account is not authorized to perform an operation.\n     */\n    error OwnableUnauthorizedAccount(address account);\n\n    /**\n     * @dev The owner is not a valid owner account. (eg. `address(0)`)\n     */\n    error OwnableInvalidOwner(address owner);\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.\n     */\n    constructor(address initialOwner) {\n        if (initialOwner == address(0)) {\n            revert OwnableInvalidOwner(address(0));\n        }\n        _transferOwnership(initialOwner);\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        if (owner() != _msgSender()) {\n            revert OwnableUnauthorizedAccount(_msgSender());\n        }\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        if (newOwner == address(0)) {\n            revert OwnableInvalidOwner(address(0));\n        }\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n}\n"},"npm/@openzeppelin/contracts@5.6.1/interfaces/IERC1363.sol":{"content":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)\n\npragma solidity >=0.6.2;\n\nimport {IERC20} from \"./IERC20.sol\";\nimport {IERC165} from \"./IERC165.sol\";\n\n/**\n * @title IERC1363\n * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].\n *\n * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract\n * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.\n */\ninterface IERC1363 is IERC20, IERC165 {\n    /*\n     * Note: the ERC-165 identifier for this interface is 0xb0202a11.\n     * 0xb0202a11 ===\n     *   bytes4(keccak256('transferAndCall(address,uint256)')) ^\n     *   bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^\n     *   bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^\n     *   bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^\n     *   bytes4(keccak256('approveAndCall(address,uint256)')) ^\n     *   bytes4(keccak256('approveAndCall(address,uint256,bytes)'))\n     */\n\n    /**\n     * @dev Moves a `value` amount of tokens from the caller's account to `to`\n     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n     * @param to The address which you want to transfer to.\n     * @param value The amount of tokens to be transferred.\n     * @return A boolean value indicating whether the operation succeeded unless throwing.\n     */\n    function transferAndCall(address to, uint256 value) external returns (bool);\n\n    /**\n     * @dev Moves a `value` amount of tokens from the caller's account to `to`\n     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n     * @param to The address which you want to transfer to.\n     * @param value The amount of tokens to be transferred.\n     * @param data Additional data with no specified format, sent in call to `to`.\n     * @return A boolean value indicating whether the operation succeeded unless throwing.\n     */\n    function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);\n\n    /**\n     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism\n     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n     * @param from The address which you want to send tokens from.\n     * @param to The address which you want to transfer to.\n     * @param value The amount of tokens to be transferred.\n     * @return A boolean value indicating whether the operation succeeded unless throwing.\n     */\n    function transferFromAndCall(address from, address to, uint256 value) external returns (bool);\n\n    /**\n     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism\n     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.\n     * @param from The address which you want to send tokens from.\n     * @param to The address which you want to transfer to.\n     * @param value The amount of tokens to be transferred.\n     * @param data Additional data with no specified format, sent in call to `to`.\n     * @return A boolean value indicating whether the operation succeeded unless throwing.\n     */\n    function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);\n\n    /**\n     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.\n     * @param spender The address which will spend the funds.\n     * @param value The amount of tokens to be spent.\n     * @return A boolean value indicating whether the operation succeeded unless throwing.\n     */\n    function approveAndCall(address spender, uint256 value) external returns (bool);\n\n    /**\n     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.\n     * @param spender The address which will spend the funds.\n     * @param value The amount of tokens to be spent.\n     * @param data Additional data with no specified format, sent in call to `spender`.\n     * @return A boolean value indicating whether the operation succeeded unless throwing.\n     */\n    function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);\n}\n"},"npm/@openzeppelin/contracts@5.6.1/interfaces/IERC165.sol":{"content":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)\n\npragma solidity >=0.4.16;\n\nimport {IERC165} from \"../utils/introspection/IERC165.sol\";\n"},"npm/@openzeppelin/contracts@5.6.1/interfaces/IERC20.sol":{"content":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)\n\npragma solidity >=0.4.16;\n\nimport {IERC20} from \"../token/ERC20/IERC20.sol\";\n"},"npm/@openzeppelin/contracts@5.6.1/token/ERC20/IERC20.sol":{"content":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)\n\npragma solidity >=0.4.16;\n\n/**\n * @dev Interface of the ERC-20 standard as defined in the ERC.\n */\ninterface IERC20 {\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n\n    /**\n     * @dev Returns the value of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the value of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves a `value` amount of tokens from the caller's account to `to`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address to, uint256 value) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n     * caller's tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender's allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 value) external returns (bool);\n\n    /**\n     * @dev Moves a `value` amount of tokens from `from` to `to` using the\n     * allowance mechanism. `value` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address from, address to, uint256 value) external returns (bool);\n}\n"},"npm/@openzeppelin/contracts@5.6.1/token/ERC20/utils/SafeERC20.sol":{"content":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.5.0) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../IERC20.sol\";\nimport {IERC1363} from \"../../../interfaces/IERC1363.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC-20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n    /**\n     * @dev An operation with an ERC-20 token failed.\n     */\n    error SafeERC20FailedOperation(address token);\n\n    /**\n     * @dev Indicates a failed `decreaseAllowance` request.\n     */\n    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);\n\n    /**\n     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful.\n     */\n    function safeTransfer(IERC20 token, address to, uint256 value) internal {\n        if (!_safeTransfer(token, to, value, true)) {\n            revert SafeERC20FailedOperation(address(token));\n        }\n    }\n\n    /**\n     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the\n     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.\n     */\n    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\n        if (!_safeTransferFrom(token, from, to, value, true)) {\n            revert SafeERC20FailedOperation(address(token));\n        }\n    }\n\n    /**\n     * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.\n     */\n    function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {\n        return _safeTransfer(token, to, value, false);\n    }\n\n    /**\n     * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.\n     */\n    function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {\n        return _safeTransferFrom(token, from, to, value, false);\n    }\n\n    /**\n     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful.\n     *\n     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the \"client\"\n     * smart contract uses ERC-7674 to set temporary allowances, then the \"client\" smart contract should avoid using\n     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract\n     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.\n     */\n    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n        uint256 oldAllowance = token.allowance(address(this), spender);\n        forceApprove(token, spender, oldAllowance + value);\n    }\n\n    /**\n     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no\n     * value, non-reverting calls are assumed to be successful.\n     *\n     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the \"client\"\n     * smart contract uses ERC-7674 to set temporary allowances, then the \"client\" smart contract should avoid using\n     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract\n     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.\n     */\n    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {\n        unchecked {\n            uint256 currentAllowance = token.allowance(address(this), spender);\n            if (currentAllowance < requestedDecrease) {\n                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);\n            }\n            forceApprove(token, spender, currentAllowance - requestedDecrease);\n        }\n    }\n\n    /**\n     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval\n     * to be set to zero before setting it to a non-zero value, such as USDT.\n     *\n     * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function\n     * only sets the \"standard\" allowance. Any temporary allowance will remain active, in addition to the value being\n     * set here.\n     */\n    function forceApprove(IERC20 token, address spender, uint256 value) internal {\n        if (!_safeApprove(token, spender, value, false)) {\n            if (!_safeApprove(token, spender, 0, true)) revert SafeERC20FailedOperation(address(token));\n            if (!_safeApprove(token, spender, value, true)) revert SafeERC20FailedOperation(address(token));\n        }\n    }\n\n    /**\n     * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no\n     * code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when\n     * targeting contracts.\n     *\n     * Reverts if the returned value is other than `true`.\n     */\n    function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {\n        if (to.code.length == 0) {\n            safeTransfer(token, to, value);\n        } else if (!token.transferAndCall(to, value, data)) {\n            revert SafeERC20FailedOperation(address(token));\n        }\n    }\n\n    /**\n     * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target\n     * has no code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when\n     * targeting contracts.\n     *\n     * Reverts if the returned value is other than `true`.\n     */\n    function transferFromAndCallRelaxed(\n        IERC1363 token,\n        address from,\n        address to,\n        uint256 value,\n        bytes memory data\n    ) internal {\n        if (to.code.length == 0) {\n            safeTransferFrom(token, from, to, value);\n        } else if (!token.transferFromAndCall(from, to, value, data)) {\n            revert SafeERC20FailedOperation(address(token));\n        }\n    }\n\n    /**\n     * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no\n     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when\n     * targeting contracts.\n     *\n     * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.\n     * Oppositely, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}\n     * once without retrying, and relies on the returned value to be true.\n     *\n     * Reverts if the returned value is other than `true`.\n     */\n    function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {\n        if (to.code.length == 0) {\n            forceApprove(token, to, value);\n        } else if (!token.approveAndCall(to, value, data)) {\n            revert SafeERC20FailedOperation(address(token));\n        }\n    }\n\n    /**\n     * @dev Imitates a Solidity `token.transfer(to, value)` call, relaxing the requirement on the return value: the\n     * return value is optional (but if data is returned, it must not be false).\n     *\n     * @param token The token targeted by the call.\n     * @param to The recipient of the tokens\n     * @param value The amount of token to transfer\n     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.\n     */\n    function _safeTransfer(IERC20 token, address to, uint256 value, bool bubble) private returns (bool success) {\n        bytes4 selector = IERC20.transfer.selector;\n\n        assembly (\"memory-safe\") {\n            let fmp := mload(0x40)\n            mstore(0x00, selector)\n            mstore(0x04, and(to, shr(96, not(0))))\n            mstore(0x24, value)\n            success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)\n            // if call success and return is true, all is good.\n            // otherwise (not success or return is not true), we need to perform further checks\n            if iszero(and(success, eq(mload(0x00), 1))) {\n                // if the call was a failure and bubble is enabled, bubble the error\n                if and(iszero(success), bubble) {\n                    returndatacopy(fmp, 0x00, returndatasize())\n                    revert(fmp, returndatasize())\n                }\n                // if the return value is not true, then the call is only successful if:\n                // - the token address has code\n                // - the returndata is empty\n                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))\n            }\n            mstore(0x40, fmp)\n        }\n    }\n\n    /**\n     * @dev Imitates a Solidity `token.transferFrom(from, to, value)` call, relaxing the requirement on the return\n     * value: the return value is optional (but if data is returned, it must not be false).\n     *\n     * @param token The token targeted by the call.\n     * @param from The sender of the tokens\n     * @param to The recipient of the tokens\n     * @param value The amount of token to transfer\n     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.\n     */\n    function _safeTransferFrom(\n        IERC20 token,\n        address from,\n        address to,\n        uint256 value,\n        bool bubble\n    ) private returns (bool success) {\n        bytes4 selector = IERC20.transferFrom.selector;\n\n        assembly (\"memory-safe\") {\n            let fmp := mload(0x40)\n            mstore(0x00, selector)\n            mstore(0x04, and(from, shr(96, not(0))))\n            mstore(0x24, and(to, shr(96, not(0))))\n            mstore(0x44, value)\n            success := call(gas(), token, 0, 0x00, 0x64, 0x00, 0x20)\n            // if call success and return is true, all is good.\n            // otherwise (not success or return is not true), we need to perform further checks\n            if iszero(and(success, eq(mload(0x00), 1))) {\n                // if the call was a failure and bubble is enabled, bubble the error\n                if and(iszero(success), bubble) {\n                    returndatacopy(fmp, 0x00, returndatasize())\n                    revert(fmp, returndatasize())\n                }\n                // if the return value is not true, then the call is only successful if:\n                // - the token address has code\n                // - the returndata is empty\n                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))\n            }\n            mstore(0x40, fmp)\n            mstore(0x60, 0)\n        }\n    }\n\n    /**\n     * @dev Imitates a Solidity `token.approve(spender, value)` call, relaxing the requirement on the return value:\n     * the return value is optional (but if data is returned, it must not be false).\n     *\n     * @param token The token targeted by the call.\n     * @param spender The spender of the tokens\n     * @param value The amount of token to transfer\n     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.\n     */\n    function _safeApprove(IERC20 token, address spender, uint256 value, bool bubble) private returns (bool success) {\n        bytes4 selector = IERC20.approve.selector;\n\n        assembly (\"memory-safe\") {\n            let fmp := mload(0x40)\n            mstore(0x00, selector)\n            mstore(0x04, and(spender, shr(96, not(0))))\n            mstore(0x24, value)\n            success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)\n            // if call success and return is true, all is good.\n            // otherwise (not success or return is not true), we need to perform further checks\n            if iszero(and(success, eq(mload(0x00), 1))) {\n                // if the call was a failure and bubble is enabled, bubble the error\n                if and(iszero(success), bubble) {\n                    returndatacopy(fmp, 0x00, returndatasize())\n                    revert(fmp, returndatasize())\n                }\n                // if the return value is not true, then the call is only successful if:\n                // - the token address has code\n                // - the returndata is empty\n                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))\n            }\n            mstore(0x40, fmp)\n        }\n    }\n}\n"},"npm/@openzeppelin/contracts@5.6.1/utils/Context.sol":{"content":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    function _contextSuffixLength() internal view virtual returns (uint256) {\n        return 0;\n    }\n}\n"},"npm/@openzeppelin/contracts@5.6.1/utils/introspection/IERC165.sol":{"content":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)\n\npragma solidity >=0.4.16;\n\n/**\n * @dev Interface of the ERC-165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[ERC].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n    /**\n     * @dev Returns true if this contract implements the interface defined by\n     * `interfaceId`. See the corresponding\n     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]\n     * to learn more about how these ids are created.\n     *\n     * This function call must use less than 30 000 gas.\n     */\n    function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n"},"npm/@openzeppelin/contracts@5.6.1/utils/Pausable.sol":{"content":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.3.0) (utils/Pausable.sol)\n\npragma solidity ^0.8.20;\n\nimport {Context} from \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which allows children to implement an emergency stop\n * mechanism that can be triggered by an authorized account.\n *\n * This module is used through inheritance. It will make available the\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\n * the functions of your contract. Note that they will not be pausable by\n * simply including this module, only once the modifiers are put in place.\n */\nabstract contract Pausable is Context {\n    bool private _paused;\n\n    /**\n     * @dev Emitted when the pause is triggered by `account`.\n     */\n    event Paused(address account);\n\n    /**\n     * @dev Emitted when the pause is lifted by `account`.\n     */\n    event Unpaused(address account);\n\n    /**\n     * @dev The operation failed because the contract is paused.\n     */\n    error EnforcedPause();\n\n    /**\n     * @dev The operation failed because the contract is not paused.\n     */\n    error ExpectedPause();\n\n    /**\n     * @dev Modifier to make a function callable only when the contract is not paused.\n     *\n     * Requirements:\n     *\n     * - The contract must not be paused.\n     */\n    modifier whenNotPaused() {\n        _requireNotPaused();\n        _;\n    }\n\n    /**\n     * @dev Modifier to make a function callable only when the contract is paused.\n     *\n     * Requirements:\n     *\n     * - The contract must be paused.\n     */\n    modifier whenPaused() {\n        _requirePaused();\n        _;\n    }\n\n    /**\n     * @dev Returns true if the contract is paused, and false otherwise.\n     */\n    function paused() public view virtual returns (bool) {\n        return _paused;\n    }\n\n    /**\n     * @dev Throws if the contract is paused.\n     */\n    function _requireNotPaused() internal view virtual {\n        if (paused()) {\n            revert EnforcedPause();\n        }\n    }\n\n    /**\n     * @dev Throws if the contract is not paused.\n     */\n    function _requirePaused() internal view virtual {\n        if (!paused()) {\n            revert ExpectedPause();\n        }\n    }\n\n    /**\n     * @dev Triggers stopped state.\n     *\n     * Requirements:\n     *\n     * - The contract must not be paused.\n     */\n    function _pause() internal virtual whenNotPaused {\n        _paused = true;\n        emit Paused(_msgSender());\n    }\n\n    /**\n     * @dev Returns to normal state.\n     *\n     * Requirements:\n     *\n     * - The contract must be paused.\n     */\n    function _unpause() internal virtual whenPaused {\n        _paused = false;\n        emit Unpaused(_msgSender());\n    }\n}\n"},"npm/@openzeppelin/contracts@5.6.1/utils/ReentrancyGuard.sol":{"content":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.5.0) (utils/ReentrancyGuard.sol)\n\npragma solidity ^0.8.20;\n\nimport {StorageSlot} from \"./StorageSlot.sol\";\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,\n * consider using {ReentrancyGuardTransient} instead.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n *\n * IMPORTANT: Deprecated. This storage-based reentrancy guard will be removed and replaced\n * by the {ReentrancyGuardTransient} variant in v6.0.\n *\n * @custom:stateless\n */\nabstract contract ReentrancyGuard {\n    using StorageSlot for bytes32;\n\n    // keccak256(abi.encode(uint256(keccak256(\"openzeppelin.storage.ReentrancyGuard\")) - 1)) & ~bytes32(uint256(0xff))\n    bytes32 private constant REENTRANCY_GUARD_STORAGE =\n        0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;\n\n    // Booleans are more expensive than uint256 or any type that takes up a full\n    // word because each write operation emits an extra SLOAD to first read the\n    // slot's contents, replace the bits taken up by the boolean, and then write\n    // back. This is the compiler's defense against contract upgrades and\n    // pointer aliasing, and it cannot be disabled.\n\n    // The values being non-zero value makes deployment a bit more expensive,\n    // but in exchange the refund on every call to nonReentrant will be lower in\n    // amount. Since refunds are capped to a percentage of the total\n    // transaction's gas, it is best to keep them low in cases like this one, to\n    // increase the likelihood of the full refund coming into effect.\n    uint256 private constant NOT_ENTERED = 1;\n    uint256 private constant ENTERED = 2;\n\n    /**\n     * @dev Unauthorized reentrant call.\n     */\n    error ReentrancyGuardReentrantCall();\n\n    constructor() {\n        _reentrancyGuardStorageSlot().getUint256Slot().value = NOT_ENTERED;\n    }\n\n    /**\n     * @dev Prevents a contract from calling itself, directly or indirectly.\n     * Calling a `nonReentrant` function from another `nonReentrant`\n     * function is not supported. It is possible to prevent this from happening\n     * by making the `nonReentrant` function external, and making it call a\n     * `private` function that does the actual work.\n     */\n    modifier nonReentrant() {\n        _nonReentrantBefore();\n        _;\n        _nonReentrantAfter();\n    }\n\n    /**\n     * @dev A `view` only version of {nonReentrant}. Use to block view functions\n     * from being called, preventing reading from inconsistent contract state.\n     *\n     * CAUTION: This is a \"view\" modifier and does not change the reentrancy\n     * status. Use it only on view functions. For payable or non-payable functions,\n     * use the standard {nonReentrant} modifier instead.\n     */\n    modifier nonReentrantView() {\n        _nonReentrantBeforeView();\n        _;\n    }\n\n    function _nonReentrantBeforeView() private view {\n        if (_reentrancyGuardEntered()) {\n            revert ReentrancyGuardReentrantCall();\n        }\n    }\n\n    function _nonReentrantBefore() private {\n        // On the first call to nonReentrant, _status will be NOT_ENTERED\n        _nonReentrantBeforeView();\n\n        // Any calls to nonReentrant after this point will fail\n        _reentrancyGuardStorageSlot().getUint256Slot().value = ENTERED;\n    }\n\n    function _nonReentrantAfter() private {\n        // By storing the original value once again, a refund is triggered (see\n        // https://eips.ethereum.org/EIPS/eip-2200)\n        _reentrancyGuardStorageSlot().getUint256Slot().value = NOT_ENTERED;\n    }\n\n    /**\n     * @dev Returns true if the reentrancy guard is currently set to \"entered\", which indicates there is a\n     * `nonReentrant` function in the call stack.\n     */\n    function _reentrancyGuardEntered() internal view returns (bool) {\n        return _reentrancyGuardStorageSlot().getUint256Slot().value == ENTERED;\n    }\n\n    function _reentrancyGuardStorageSlot() internal pure virtual returns (bytes32) {\n        return REENTRANCY_GUARD_STORAGE;\n    }\n}\n"},"npm/@openzeppelin/contracts@5.6.1/utils/StorageSlot.sol":{"content":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)\n// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Library for reading and writing primitive types to specific storage slots.\n *\n * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.\n * This library helps with reading and writing to such slots without the need for inline assembly.\n *\n * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.\n *\n * Example usage to set ERC-1967 implementation slot:\n * ```solidity\n * contract ERC1967 {\n *     // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.\n *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n *\n *     function _getImplementation() internal view returns (address) {\n *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n *     }\n *\n *     function _setImplementation(address newImplementation) internal {\n *         require(newImplementation.code.length > 0);\n *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n *     }\n * }\n * ```\n *\n * TIP: Consider using this library along with {SlotDerivation}.\n */\nlibrary StorageSlot {\n    struct AddressSlot {\n        address value;\n    }\n\n    struct BooleanSlot {\n        bool value;\n    }\n\n    struct Bytes32Slot {\n        bytes32 value;\n    }\n\n    struct Uint256Slot {\n        uint256 value;\n    }\n\n    struct Int256Slot {\n        int256 value;\n    }\n\n    struct StringSlot {\n        string value;\n    }\n\n    struct BytesSlot {\n        bytes value;\n    }\n\n    /**\n     * @dev Returns an `AddressSlot` with member `value` located at `slot`.\n     */\n    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {\n        assembly (\"memory-safe\") {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns a `BooleanSlot` with member `value` located at `slot`.\n     */\n    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {\n        assembly (\"memory-safe\") {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns a `Bytes32Slot` with member `value` located at `slot`.\n     */\n    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {\n        assembly (\"memory-safe\") {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns a `Uint256Slot` with member `value` located at `slot`.\n     */\n    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {\n        assembly (\"memory-safe\") {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns a `Int256Slot` with member `value` located at `slot`.\n     */\n    function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {\n        assembly (\"memory-safe\") {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns a `StringSlot` with member `value` located at `slot`.\n     */\n    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {\n        assembly (\"memory-safe\") {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.\n     */\n    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {\n        assembly (\"memory-safe\") {\n            r.slot := store.slot\n        }\n    }\n\n    /**\n     * @dev Returns a `BytesSlot` with member `value` located at `slot`.\n     */\n    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {\n        assembly (\"memory-safe\") {\n            r.slot := slot\n        }\n    }\n\n    /**\n     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.\n     */\n    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {\n        assembly (\"memory-safe\") {\n            r.slot := store.slot\n        }\n    }\n}\n"},"project/contracts/interfaces/IMokeAC.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\ninterface IMokeAC {\n    function mint(address to, uint256 amount) external;\n    function burnFrom(address account, uint256 amount) external;\n    function balanceOf(address account) external view returns (uint256);\n    function transfer(address to, uint256 amount) external returns (bool);\n    function transferFrom(address from, address to, uint256 amount) external returns (bool);\n    function approve(address spender, uint256 amount) external returns (bool);\n}\n"},"project/contracts/interfaces/IMokeReferral.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\ninterface IMokeReferral {\n    function bind(address referrer) external;\n    function bindFor(address user, address referrer) external;\n    function getReferrer(address user) external view returns (address);\n    function getDirectReferrals(address user) external view returns (address[] memory);\n    function getDirectReferralCount(address user) external view returns (uint256);\n    function getTotalReferrals(address user) external view returns (uint256);\n    function getTeamPerformance(address user) external view returns (uint256);\n    function getReferrerChain(address user, uint256 depth) external view returns (address[] memory);\n    function addTeamPerformance(address user, uint256 amount) external;\n    function markParticipant(address user) external;\n    function isParticipant(address user) external view returns (bool);\n    function effectiveReferralCount(address user) external view returns (uint256);\n}\n"},"project/contracts/interfaces/IMokeRelease.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\ninterface IMokeRelease {\n    function addReleaseQuota(address user, uint256 quotaUsdt) external;\n    function claim() external payable;\n    function settle() external;\n    function setDailyRate(uint256 _rate) external;\n    function getPendingRelease(address user) external view returns (uint256 mokeAmount);\n    function getUserRelease(address user) external view returns (\n        uint256 totalQuota,\n        uint256 releasedQuota,\n        uint256 pendingUsdt,\n        uint256 lastClaimTime\n    );\n}\n"},"project/contracts/interfaces/IMokeToken.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\ninterface IMokeToken {\n    function enableTrading() external;\n    function isTradingEnabled() external view returns (bool);\n    function setTaxRate(uint256 _lpRate, uint256 _nftRate, uint256 _marketingRate) external;\n    function setMarketingWallet(address _wallet) external;\n    function setWhitelist(address account, bool status) external;\n    function setMarketPair(address _pair, bool status) external;\n    function addReleasedBalance(address user, uint256 amount) external;\n    function releaseFromPair(address to, uint256 amount) external;\n    function releasedMokeBalance(address user) external view returns (uint256);\n}\n"},"project/contracts/MokeRelease.sol":{"content":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\nimport \"@openzeppelin/contracts/utils/ReentrancyGuard.sol\";\nimport \"@openzeppelin/contracts/utils/Pausable.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport \"./interfaces/IMokeRelease.sol\";\nimport \"./interfaces/IMokeToken.sol\";\nimport \"./interfaces/IMokeAC.sol\";\nimport \"./interfaces/IMokeReferral.sol\";\n\ninterface IPancakePair {\n    function getReserves() external view returns (uint112, uint112, uint32);\n    function token0() external view returns (address);\n    function token1() external view returns (address);\n    function sync() external;\n}\n\ninterface ITokenX {\n    function burnFromPair(uint256 amount) external;\n    function balanceOf(address account) external view returns (uint256);\n}\n\n/**\n * @title MokeRelease\n * @dev Per-user linear release from `userFirstSettleDay` (UTC+8 day index).\n *      Accrued factor = min(periodsSinceFirst * dailyRate / 10000, 1) in PRECISION.\n *      Per-period accrual is computed on `(totalQuotaUsdt - claimedSnapshotAtReset)`\n *      so the rate is always dailyRate% of *what remains to vest in the current window*.\n *\n *      Additional deposits behaviour (v4):\n *        - Every new deposit RESTARTS the vesting window from today. Whatever has\n *          already been released (claimed + vested-but-unclaimed pending) is frozen\n *          as `claimedSnapshotAtReset` (consumed by the previous window); only the\n *          still-unvested remainder of the old quota PLUS the new quota vests over a\n *          fresh dailyRate × maxSettleDays cycle from today.\n *        - This removes the v3 path where topping up an already-aged, still-active\n *          window instantly released `quota * currentFactor` (the \"账户叠加秒放\" bug).\n *\n *      `pendingUsdt` is always capped so claimed + pending never exceeds total quota.\n */\ncontract MokeRelease is IMokeRelease, Ownable, ReentrancyGuard, Pausable {\n    using SafeERC20 for IERC20;\n\n    IERC20 public mokeToken;\n    IMokeAC public mokeAC;\n    IMokeReferral public referral;\n    address public mokeBnbPair;\n    address public bnbUsdtPair;\n    address public wbnb;\n\n    // X/MOKE reserve pool\n    ITokenX public xToken;\n    address public xMokePair;\n\n    uint256 public constant PRECISION = 1e18;\n    uint256 public constant BASIS_POINTS = 10000;\n    uint256 public constant SETTLE_OFFSET = 28800; // UTC+8\n\n    uint256 public dailyRate = 100; // 1% in basis points\n    uint256 public settlePeriod = 86400;\n    uint256 public maxSettleDays = 30;\n\n    uint256 public claimFee = 0.000341 ether;\n    address public feeReceiver;\n\n    uint256 public settledMokePrice;\n    uint256 public maxPriceDeviation = 2000;\n    uint256 public settleMinInterval = 600; // 10 minutes\n    uint256 public lastSettleTime;\n\n    uint256 public referralL1Rate = 2000;\n    uint256 public referralL2_10Rate = 500;\n    uint256 public maxReferralLayers = 10;\n    uint256 public claimInterval = 1 days;\n\n    uint256 public cumulativeReleaseFactor;\n    uint256 public lastSettledDay;\n\n    struct UserRelease {\n        uint256 totalQuotaUsdt;\n        uint256 pendingUsdt;\n        uint256 claimedUsdt;\n        uint256 lastReleaseFactor;\n        uint256 lastClaimTime;\n        // Claimed amount at the moment the current vesting window started.\n        // 0 for the first-ever window; updated on every \"window expired & re-deposit\" reset.\n        uint256 claimedSnapshotAtReset;\n    }\n\n    /// @notice One row for `batchMigrateUsers` (keeps stack shallow for Ignition/solc).\n    struct UserMigrateRow {\n        address user;\n        uint256 totalQuotaUsdt;\n        uint256 claimedUsdt;\n        uint256 pendingUsdt;\n        uint256 lastReleaseFactor;\n        uint256 lastClaimTime;\n        uint256 firstSettleDay;\n        uint256 claimedSnapshotAtReset;\n    }\n\n    mapping(address => UserRelease) public userRelease;\n    mapping(address => bool) public isSettler;\n    /// @dev Day index (same as _trySettle's `today`) when user first received release quota; 0 = none yet\n    mapping(address => uint256) public userFirstSettleDay;\n\n    address[] private _allUsers;\n    mapping(address => bool) private _isKnownUser;\n\n    event ReleaseQuotaAdded(address indexed user, uint256 quotaUsdt);\n    event Settled(uint256 newFactor, uint256 daysPassed);\n    event Claimed(address indexed user, uint256 mokeAmount, uint256 usdtValue);\n    event DynamicReward(address indexed referrer, address indexed downline, uint256 layer, uint256 acAmount);\n    event DailyRateSet(uint256 newRate);\n    event ClaimFeeSet(uint256 newFee);\n    event FeeReceiverSet(address indexed receiver);\n    event SettlerSet(address indexed settler, bool status);\n    event PriceSettled(uint256 mokePrice);\n    event MaxPriceDeviationSet(uint256 deviation);\n    event ReferralRatesSet(uint256 l1Rate, uint256 l2_10Rate);\n    event MaxReferralLayersSet(uint256 layers);\n    event ClaimIntervalSet(uint256 interval);\n    event SettlePeriodSet(uint256 period);\n    event MaxSettleDaysSet(uint256 maxDays);\n    event EmergencyWithdraw(address indexed token, uint256 amount, address indexed to);\n    event DynamicRewardFailed(address indexed referrer, address indexed downline, uint256 layer, uint256 acAmount);\n    event UsersMigrated(uint256 count);\n\n    constructor(\n        address _mokeToken,\n        address _mokeAC,\n        address _referral,\n        address _feeReceiver\n    ) Ownable(msg.sender) {\n        mokeToken = IERC20(_mokeToken);\n        mokeAC = IMokeAC(_mokeAC);\n        referral = IMokeReferral(_referral);\n        feeReceiver = _feeReceiver;\n    }\n\n    modifier onlyAuthorized() {\n        require(isSettler[msg.sender] || msg.sender == owner(), \"Not authorized\");\n        _;\n    }\n\n    // ============ Admin Functions ============\n\n    function setMokeToken(address _mokeToken) external onlyOwner {\n        require(_mokeToken != address(0), \"Invalid token\");\n        mokeToken = IERC20(_mokeToken);\n    }\n\n    function setMokeAC(address _mokeAC) external onlyOwner {\n        require(_mokeAC != address(0), \"Invalid AC\");\n        mokeAC = IMokeAC(_mokeAC);\n    }\n\n    function setReferral(address _referral) external onlyOwner {\n        require(_referral != address(0), \"Invalid referral\");\n        referral = IMokeReferral(_referral);\n    }\n\n    function setSettler(address settler, bool status) external onlyOwner {\n        isSettler[settler] = status;\n        emit SettlerSet(settler, status);\n    }\n\n    function setDailyRate(uint256 _rate) external override onlyOwner {\n        _trySettle();\n        dailyRate = _rate;\n        emit DailyRateSet(_rate);\n    }\n\n    function setClaimFee(uint256 _fee) external onlyOwner {\n        claimFee = _fee;\n        emit ClaimFeeSet(_fee);\n    }\n\n    function setFeeReceiver(address _receiver) external onlyOwner {\n        require(_receiver != address(0), \"Invalid receiver\");\n        feeReceiver = _receiver;\n        emit FeeReceiverSet(_receiver);\n    }\n\n    function setReferralRates(uint256 _l1Rate, uint256 _l2_10Rate) external onlyOwner {\n        require(_l1Rate <= 5000 && _l2_10Rate <= 2000, \"Rate too high\");\n        referralL1Rate = _l1Rate;\n        referralL2_10Rate = _l2_10Rate;\n        emit ReferralRatesSet(_l1Rate, _l2_10Rate);\n    }\n\n    function setMaxReferralLayers(uint256 _layers) external onlyOwner {\n        require(_layers > 0 && _layers <= 20, \"Invalid layers\");\n        maxReferralLayers = _layers;\n        emit MaxReferralLayersSet(_layers);\n    }\n\n    function setClaimInterval(uint256 _interval) external onlyOwner {\n        claimInterval = _interval;\n        emit ClaimIntervalSet(_interval);\n    }\n\n    function setPairs(address _mokeBnbPair, address _bnbUsdtPair, address _wbnb) external onlyOwner {\n        require(_wbnb != address(0), \"Invalid WBNB\");\n        mokeBnbPair = _mokeBnbPair;\n        bnbUsdtPair = _bnbUsdtPair;\n        wbnb = _wbnb;\n    }\n\n    function setXToken(address _xToken) external onlyOwner {\n        require(_xToken != address(0), \"Invalid X token\");\n        xToken = ITokenX(_xToken);\n    }\n\n    function setXMokePair(address _pair) external onlyOwner {\n        require(_pair != address(0), \"Invalid pair\");\n        xMokePair = _pair;\n    }\n\n    function setMaxPriceDeviation(uint256 _deviation) external onlyOwner {\n        require(_deviation <= 5000, \"Max 50%\");\n        maxPriceDeviation = _deviation;\n        emit MaxPriceDeviationSet(_deviation);\n    }\n\n    function setSettleMinInterval(uint256 _interval) external onlyOwner {\n        settleMinInterval = _interval;\n    }\n\n    function setSettlePeriod(uint256 _period) external onlyOwner {\n        require(_period >= 60, \"Min 60s\");\n        _trySettle();\n        settlePeriod = _period;\n        if (lastSettledDay > 0) {\n            lastSettledDay = (block.timestamp + SETTLE_OFFSET) / _period;\n        }\n        emit SettlePeriodSet(_period);\n    }\n\n    function setMaxSettleDays(uint256 _maxDays) external onlyOwner {\n        require(_maxDays >= 1 && _maxDays <= 365, \"Invalid\");\n        maxSettleDays = _maxDays;\n        emit MaxSettleDaysSet(_maxDays);\n    }\n\n    function setSettledMokePrice(uint256 _price) external onlyOwner {\n        require(_price > 0, \"Invalid price\");\n        settledMokePrice = _price;\n        emit PriceSettled(_price);\n    }\n\n    function setCumulativeReleaseFactor(uint256 _factor) external onlyOwner {\n        require(_factor < PRECISION, \"Factor must < 1e18\");\n        cumulativeReleaseFactor = _factor;\n    }\n\n    function setLastSettledDay(uint256 _day) external onlyOwner {\n        lastSettledDay = _day;\n    }\n\n    function resetUserRelease(address user) external onlyOwner {\n        _snapshotUser(user);\n        UserRelease storage ur = userRelease[user];\n        ur.pendingUsdt = 0;\n        ur.claimedUsdt = 0;\n        ur.lastClaimTime = 0;\n        ur.claimedSnapshotAtReset = 0;\n    }\n\n    function setUserQuota(address user, uint256 quotaUsdt) external onlyOwner {\n        _trackUser(user);\n        _trySettle();\n        _snapshotUser(user);\n\n        UserRelease storage ur2 = userRelease[user];\n        if (quotaUsdt > 0) {\n            uint256 today = (block.timestamp + SETTLE_OFFSET) / settlePeriod;\n            userFirstSettleDay[user] = today;\n            ur2.lastReleaseFactor = 0;\n            // Owner override starts a fresh window. Already-claimed AND already-vested\n            // (but not yet claimed) amounts count as \"consumed by previous window\".\n            ur2.claimedSnapshotAtReset = ur2.claimedUsdt + ur2.pendingUsdt;\n        }\n\n        ur2.totalQuotaUsdt = quotaUsdt;\n        _clampPendingUser(user);\n    }\n\n    /// @notice Owner-only migration of user rows (e.g. new release contract). Caps pending per quota.\n    function batchMigrateUsers(UserMigrateRow[] calldata rows) external onlyOwner {\n        uint256 n = rows.length;\n        require(n > 0 && n <= 100, \"Batch size\");\n        for (uint256 i; i < n; ) {\n            UserMigrateRow calldata r = rows[i];\n            require(r.user != address(0), \"Zero user\");\n            _trackUser(r.user);\n            userFirstSettleDay[r.user] = r.firstSettleDay;\n            UserRelease storage ur = userRelease[r.user];\n            ur.totalQuotaUsdt = r.totalQuotaUsdt;\n            ur.claimedUsdt = r.claimedUsdt;\n            ur.pendingUsdt = r.pendingUsdt;\n            ur.lastReleaseFactor = r.lastReleaseFactor;\n            ur.lastClaimTime = r.lastClaimTime;\n            ur.claimedSnapshotAtReset = r.claimedSnapshotAtReset;\n            _clampPendingUser(r.user);\n            unchecked {\n                ++i;\n            }\n        }\n        emit UsersMigrated(n);\n    }\n\n    // ============ Settlement (O(1) global) ============\n\n    function settle() external override {\n        require(\n            isSettler[msg.sender] || msg.sender == owner() || msg.sender == tx.origin,\n            \"Only authorized or EOA\"\n        );\n        require(\n            block.timestamp >= lastSettleTime + settleMinInterval,\n            \"Settle cooldown\"\n        );\n        _trySettle();\n        uint256 price = getMokeUsdtPrice();\n        if (price > 0) {\n            settledMokePrice = price;\n            lastSettleTime = block.timestamp;\n            emit PriceSettled(price);\n        }\n    }\n\n    function _trySettle() internal {\n        uint256 today = (block.timestamp + SETTLE_OFFSET) / settlePeriod;\n        if (lastSettledDay == 0) {\n            lastSettledDay = today;\n            return;\n        }\n        if (today <= lastSettledDay) return;\n\n        uint256 daysPassed = today - lastSettledDay;\n        lastSettledDay = today;\n        emit Settled(cumulativeReleaseFactor, daysPassed);\n    }\n\n    function _accruedReleaseFactor(address user) internal view returns (uint256) {\n        uint256 firstDay = userFirstSettleDay[user];\n        if (firstDay == 0) return 0;\n        uint256 today = (block.timestamp + SETTLE_OFFSET) / settlePeriod;\n        if (today <= firstDay) return 0;\n        uint256 periods = today - firstDay;\n        if (periods > maxSettleDays) periods = maxSettleDays;\n        uint256 f = periods * PRECISION * dailyRate / BASIS_POINTS;\n        if (f > PRECISION) return PRECISION;\n        return f;\n    }\n\n    function _snapshotUser(address user) internal {\n        UserRelease storage ur = userRelease[user];\n        uint256 currentFactor = _accruedReleaseFactor(user);\n        if (currentFactor > ur.lastReleaseFactor) {\n            uint256 delta = currentFactor - ur.lastReleaseFactor;\n            uint256 vestBase = ur.totalQuotaUsdt > ur.claimedSnapshotAtReset\n                ? ur.totalQuotaUsdt - ur.claimedSnapshotAtReset\n                : 0;\n            if (vestBase > 0) {\n                ur.pendingUsdt += vestBase * delta / PRECISION;\n            }\n        }\n        ur.lastReleaseFactor = currentFactor;\n        _clampPendingUser(user);\n    }\n\n    /// @dev Ensures released (pending + claimed) never exceeds total quota.\n    function _clampPendingUser(address user) internal {\n        UserRelease storage ur = userRelease[user];\n        uint256 cap = ur.totalQuotaUsdt > ur.claimedUsdt ? ur.totalQuotaUsdt - ur.claimedUsdt : 0;\n        if (ur.pendingUsdt > cap) {\n            ur.pendingUsdt = cap;\n        }\n    }\n\n    // ============ Core Functions ============\n\n    function addReleaseQuota(address user, uint256 quotaUsdt) external override onlyAuthorized {\n        _trackUser(user);\n        _trySettle();\n\n        // Snapshot first so any already-accrued (but unsnapshotted) portion of the\n        // existing quota is captured into `pendingUsdt` before we change anything.\n        _snapshotUser(user);\n\n        UserRelease storage ur = userRelease[user];\n\n        if (quotaUsdt > 0) {\n            // v4: EVERY deposit restarts the vesting window from today.\n            // Everything already released (claimed + vested-but-unclaimed pending) is\n            // frozen as \"consumed by the previous window\"; only the still-unvested\n            // remainder of the old quota plus the new quota vests from today, i.e.:\n            //   vestBase = totalQuotaUsdt - claimedSnapshotAtReset\n            //            = (oldUnvestedRemainder) + quotaUsdt\n            // This removes the v3 \"top-up onto an aged active window instantly releases\n            // quota * currentFactor\" behaviour.\n            uint256 today = (block.timestamp + SETTLE_OFFSET) / settlePeriod;\n            userFirstSettleDay[user] = today;\n            ur.lastReleaseFactor = 0;\n            ur.claimedSnapshotAtReset = ur.claimedUsdt + ur.pendingUsdt;\n\n            ur.totalQuotaUsdt += quotaUsdt;\n            _clampPendingUser(user);\n        }\n\n        emit ReleaseQuotaAdded(user, quotaUsdt);\n    }\n\n    function claim() external payable override nonReentrant whenNotPaused {\n        require(msg.value >= claimFee, \"Insufficient claim fee\");\n\n        _trySettle();\n        _snapshotUser(msg.sender);\n\n        UserRelease storage ur = userRelease[msg.sender];\n        require(ur.pendingUsdt > 0, \"Nothing to claim\");\n        require(\n            block.timestamp >= ur.lastClaimTime + claimInterval,\n            \"Claim interval not reached\"\n        );\n\n        if (claimFee > 0 && feeReceiver != address(0)) {\n            (bool sent,) = payable(feeReceiver).call{value: claimFee}(\"\");\n            require(sent, \"Fee transfer failed\");\n        }\n        uint256 refund = msg.value - claimFee;\n        if (refund > 0) {\n            (bool refunded,) = payable(msg.sender).call{value: refund}(\"\");\n            require(refunded, \"Refund failed\");\n        }\n\n        uint256 pendingUsdt = ur.pendingUsdt;\n        require(settledMokePrice > 0, \"Price not settled\");\n\n        uint256 livePrice = getMokeUsdtPrice();\n        if (livePrice > 0) {\n            uint256 deviation = livePrice > settledMokePrice\n                ? (livePrice - settledMokePrice) * BASIS_POINTS / settledMokePrice\n                : (settledMokePrice - livePrice) * BASIS_POINTS / settledMokePrice;\n            require(deviation <= maxPriceDeviation, \"Price deviation too high\");\n        }\n\n        uint256 mokeAmount = pendingUsdt * PRECISION / settledMokePrice;\n\n        require(address(xToken) != address(0), \"X token not set\");\n        require(xMokePair != address(0), \"X/MOKE pair not set\");\n\n        uint256 mokeBalBefore = mokeToken.balanceOf(xMokePair);\n        require(mokeBalBefore >= mokeAmount, \"Insufficient MOKE in reserve pool\");\n\n        ur.pendingUsdt = 0;\n        ur.claimedUsdt += pendingUsdt;\n        ur.lastClaimTime = block.timestamp;\n\n        // 1. Extract MOKE from X/MOKE reserve pool → user\n        IMokeToken(address(mokeToken)).releaseFromPair(msg.sender, mokeAmount);\n\n        // 2. Burn proportional X to maintain ratio\n        uint256 xBal = xToken.balanceOf(xMokePair);\n        if (xBal > 0 && mokeBalBefore > 0) {\n            uint256 xAmount = mokeAmount * xBal / mokeBalBefore;\n            if (xAmount > 0) {\n                xToken.burnFromPair(xAmount);\n            }\n        }\n\n        // 3. Sync pair reserves after balance changes\n        IPancakePair(xMokePair).sync();\n\n        // 4. Mark released balance\n        IMokeToken(address(mokeToken)).addReleasedBalance(msg.sender, mokeAmount);\n\n        // 5. Referral rewards\n        _distributeDynamicReward(msg.sender, pendingUsdt);\n\n        emit Claimed(msg.sender, mokeAmount, pendingUsdt);\n    }\n\n    // ============ Referral Rewards ============\n\n    function _distributeDynamicReward(address user, uint256 claimedUsdtVal) internal {\n        address current = referral.getReferrer(user);\n\n        for (uint256 i = 0; i < maxReferralLayers && current != address(0); i++) {\n            uint256 effectiveCount = _countEffectiveReferrals(current);\n            if (effectiveCount <= i) {\n                current = referral.getReferrer(current);\n                continue;\n            }\n\n            uint256 rate = (i == 0) ? referralL1Rate : referralL2_10Rate;\n            uint256 acReward = claimedUsdtVal * rate / BASIS_POINTS;\n\n            if (acReward > 0) {\n                try mokeAC.mint(current, acReward) {\n                    emit DynamicReward(current, user, i + 1, acReward);\n                } catch {\n                    emit DynamicRewardFailed(current, user, i + 1, acReward);\n                }\n            }\n\n            current = referral.getReferrer(current);\n        }\n    }\n\n    function _countEffectiveReferrals(address user) internal view returns (uint256) {\n        return referral.effectiveReferralCount(user);\n    }\n\n    // ============ Price Oracle ============\n\n    function getMokeUsdtPrice() public view returns (uint256) {\n        if (mokeBnbPair == address(0) || bnbUsdtPair == address(0) || wbnb == address(0)) return 0;\n\n        uint256 mokeBnbPrice = _getPriceFromPair(mokeBnbPair, address(mokeToken));\n        uint256 bnbUsdtPrice = _getPriceFromPair(bnbUsdtPair, wbnb);\n\n        if (mokeBnbPrice == 0 || bnbUsdtPrice == 0) return 0;\n        return mokeBnbPrice * bnbUsdtPrice / PRECISION;\n    }\n\n    function _getPriceFromPair(address pairAddr, address tokenAddr) internal view returns (uint256) {\n        IPancakePair pairContract = IPancakePair(pairAddr);\n        (uint112 reserve0, uint112 reserve1,) = pairContract.getReserves();\n        if (reserve0 == 0 || reserve1 == 0) return 0;\n\n        address token0 = pairContract.token0();\n\n        if (token0 == tokenAddr) {\n            return uint256(reserve1) * PRECISION / uint256(reserve0);\n        } else {\n            return uint256(reserve0) * PRECISION / uint256(reserve1);\n        }\n    }\n\n    // ============ View Functions ============\n\n    function getPendingRelease(address user) external view override returns (uint256 mokeAmount) {\n        uint256 pending = _pendingUsdtCapped(user);\n        if (pending == 0) return 0;\n        uint256 price = settledMokePrice > 0 ? settledMokePrice : getMokeUsdtPrice();\n        if (price == 0) return 0;\n        return pending * PRECISION / price;\n    }\n\n    function getUserRelease(address user) external view override returns (\n        uint256 totalQuota,\n        uint256 releasedQuota,\n        uint256 pendingUsdt,\n        uint256 lastClaimTime\n    ) {\n        UserRelease storage ur = userRelease[user];\n        uint256 pending = _pendingUsdtCapped(user);\n        uint256 released = ur.claimedUsdt + pending;\n        return (ur.totalQuotaUsdt, released, pending, ur.lastClaimTime);\n    }\n\n    /// @dev Pending USDT including not-yet-snapshotted accrual, capped by remaining quota.\n    function _pendingUsdtCapped(address user) internal view returns (uint256) {\n        UserRelease storage ur = userRelease[user];\n        uint256 currentFactor = _accruedReleaseFactor(user);\n        uint256 pending = ur.pendingUsdt;\n        if (currentFactor > ur.lastReleaseFactor) {\n            uint256 vestBase = ur.totalQuotaUsdt > ur.claimedSnapshotAtReset\n                ? ur.totalQuotaUsdt - ur.claimedSnapshotAtReset\n                : 0;\n            if (vestBase > 0) {\n                uint256 delta = currentFactor - ur.lastReleaseFactor;\n                pending += vestBase * delta / PRECISION;\n            }\n        }\n        uint256 cap = ur.totalQuotaUsdt > ur.claimedUsdt ? ur.totalQuotaUsdt - ur.claimedUsdt : 0;\n        return pending > cap ? cap : pending;\n    }\n\n    // ============ User Tracking ============\n\n    function _trackUser(address user) internal {\n        if (!_isKnownUser[user]) {\n            _isKnownUser[user] = true;\n            _allUsers.push(user);\n        }\n    }\n\n    function getUserCount() external view returns (uint256) {\n        return _allUsers.length;\n    }\n\n    /// @notice Enumerate tracked users (same order as internal `_allUsers`) for off-chain migration.\n    function getUserAt(uint256 index) external view returns (address) {\n        require(index < _allUsers.length, \"Index OOB\");\n        return _allUsers[index];\n    }\n\n    // ============ Emergency / Pausable ============\n\n    function emergencyWithdraw(address token, uint256 amount) external onlyOwner {\n        if (token == address(0)) {\n            (bool sent,) = payable(owner()).call{value: amount}(\"\");\n            require(sent, \"BNB transfer failed\");\n        } else {\n            IERC20(token).safeTransfer(owner(), amount);\n        }\n        emit EmergencyWithdraw(token, amount, owner());\n    }\n\n    function pause() external onlyOwner { _pause(); }\n    function unpause() external onlyOwner { _unpause(); }\n\n    receive() external payable {}\n}\n"}},"matchId":"43229478","creationMatch":"exact_match","runtimeMatch":"exact_match","verifiedAt":"2026-08-03T04:14:00Z","match":"exact_match","chainId":"56","address":"0x684D722EbF8980f49492f631f56765DD4Fb302A7"}