ETH Price: $2,418.90 (-0.82%)
Gas: 0.35 Gwei

Transaction Decoder

Block:
22788229 at Jun-26-2025 11:10:11 AM +UTC
Transaction Fee:
0.00027755123482818 ETH $0.67
Gas Used:
216,046 Gas / 1.28468583 Gwei

Emitted Events:

408 SingletonPaymasterV8.UserOperationSponsored( userOpHash=738870A111FEEB5130505637DA99F5B6EFAF949D8799830ECD54E7DFDB9DBAC1, user=0xd31b802b241277dfd20cd250e2c1664f0fd8b727, paymasterMode=0, token=0x00000000...000000000, tokenAmountPaid=0, exchangeRate=0 )
409 EntryPoint.BeforeExecution( )
410 0xd31b802b241277dfd20cd250e2c1664f0fd8b727.0x2d025324f0a785e8c12d0a0d91a9caa49df4ef20ff87e0df7213a1d4f3157beb( 0x2d025324f0a785e8c12d0a0d91a9caa49df4ef20ff87e0df7213a1d4f3157beb, 0x0000000000000000000000000000000000000000000000000000000000000000, 0x000000000000000000000000d31b802b241277dfd20cd250e2c1664f0fd8b727 )
411 0xd31b802b241277dfd20cd250e2c1664f0fd8b727.0x038596bb31e2e7d3d9f184d4c98b310103f6d7f5830e5eec32bffe6f1728f969( 0x038596bb31e2e7d3d9f184d4c98b310103f6d7f5830e5eec32bffe6f1728f969, 0x0000000000000000000000009365487e19f17b121393351002b9b1c55cdcc4d6 )
412 0xd31b802b241277dfd20cd250e2c1664f0fd8b727.0x038596bb31e2e7d3d9f184d4c98b310103f6d7f5830e5eec32bffe6f1728f969( 0x038596bb31e2e7d3d9f184d4c98b310103f6d7f5830e5eec32bffe6f1728f969, 0x00000000000000000000000091c3560cfaaeb34dfeb847953325299ad514158e )
413 EntryPoint.UserOperationEvent( userOpHash=738870A111FEEB5130505637DA99F5B6EFAF949D8799830ECD54E7DFDB9DBAC1, sender=0xd31b802b241277dfd20cd250e2c1664f0fd8b727, paymaster=SingletonPaymasterV8, nonce=32299071971826539878350634090496, success=True, actualGasCost=289027280639860, actualGasUsed=224542 )

Account State Difference:

  Address   Before After State Difference Code
0x4337009B...Aa065187E
(Pimlico: ERC-4337 Bundler 9)
0.279366208772430755 Eth
Nonce: 1170
0.279377684818242435 Eth
Nonce: 1171
0.00001147604581168
0x4337084D...E3b5Ff108
(Entry Point 0.8.0)
3.18758481121497444 Eth3.18729578393433458 Eth0.00028902728063986
(Titan Builder)
3.180065171436490399 Eth3.180075973736490399 Eth0.0000108023
0xD31b802B...F0fd8b727
0 Eth
Nonce: 0
0 Eth
Nonce: 1
From: 0 To: 22892026444234553999853090417533245297989650203068533057

Execution Trace

EntryPoint.handleOps( ops=, beneficiary=0x4337009Be43c7ECc9bfbDe0F1780553Aa065187E )
  • 0xd31b802b241277dfd20cd250e2c1664f0fd8b727.19822f7c( )
    • Null: 0x000...001.738870a1( )
    • SingletonPaymasterV8.validatePaymasterUserOp( userOp=[{name:sender, type:address, order:1, indexed:false, value:0xD31b802B241277DFD20cD250e2C1664F0fd8b727, valueString:0xD31b802B241277DFD20cD250e2C1664F0fd8b727}, {name:nonce, type:uint256, order:2, indexed:false, value:32299071971826539878350634090496, valueString:32299071971826539878350634090496}, {name:initCode, type:bytes, order:3, indexed:false, value:0x7702000000000000000000000000000000000000, valueString:0x7702000000000000000000000000000000000000}, {name:callData, type:bytes, order:4, indexed:false, value:0x34FCD5BE00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001C000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000340000000000000000000000000D31B802B241277DFD20CD250E2C1664F0FD8B7270000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000A457FB25CC00000000000000000000000033158C65C91C0D36E7C2CFF50C41A29C2EBA92A400000000000000000000000033158C65C91C0D36E7C2CFF50C41A29C2EBA92A400000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000064000000000000000000000000E324C63FDB51F7D597FF68D92BEC74FA054EE12800000000000000000000000000000000000000000000000000000000000000000000000000000000D31B802B241277DFD20CD250E2C1664F0FD8B727000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000024130F3C8A000000000000000000000000D31B802B241277DFD20CD250E2C1664F0FD8B72700000000000000000000000000000000000000000000000000000000000000000000000000000000D31B802B241277DFD20CD250E2C1664F0FD8B727000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000024A526D83B0000000000000000000000009365487E19F17B121393351002B9B1C55CDCC4D600000000000000000000000000000000000000000000000000000000000000000000000000000000D31B802B241277DFD20CD250E2C1664F0FD8B727000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000024A526D83B00000000000000000000000091C3560CFAAEB34DFEB847953325299AD514158E00000000000000000000000000000000000000000000000000000000, valueString:0x34FCD5BE00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001C000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000340000000000000000000000000D31B802B241277DFD20CD250E2C1664F0FD8B7270000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000A457FB25CC00000000000000000000000033158C65C91C0D36E7C2CFF50C41A29C2EBA92A400000000000000000000000033158C65C91C0D36E7C2CFF50C41A29C2EBA92A400000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000064000000000000000000000000E324C63FDB51F7D597FF68D92BEC74FA054EE12800000000000000000000000000000000000000000000000000000000000000000000000000000000D31B802B241277DFD20CD250E2C1664F0FD8B727000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000024130F3C8A000000000000000000000000D31B802B241277DFD20CD250E2C1664F0FD8B72700000000000000000000000000000000000000000000000000000000000000000000000000000000D31B802B241277DFD20CD250E2C1664F0FD8B727000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000024A526D83B0000000000000000000000009365487E19F17B121393351002B9B1C55CDCC4D600000000000000000000000000000000000000000000000000000000000000000000000000000000D31B802B241277DFD20CD250E2C1664F0FD8B727000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000024A526D83B00000000000000000000000091C3560CFAAEB34DFEB847953325299AD514158E00000000000000000000000000000000000000000000000000000000}, {name:accountGasLimits, type:bytes32, order:5, indexed:false, value:0000000000000000000000000000E7A800000000000000000000000000016160, valueString:0000000000000000000000000000E7A800000000000000000000000000016160}, {name:preVerificationGas, type:uint256, order:6, indexed:false, value:85470, valueString:85470}, {name:gasFees, type:bytes32, order:7, indexed:false, value:0000000000000000000000000321162000000000000000000000000059D793FC, valueString:0000000000000000000000000321162000000000000000000000000059D793FC}, {name:paymasterAndData, type:bytes, order:8, indexed:false, value:0x888888888888EC68A58AB8094CC1AD20BA3D240200000000000000000000000000006ED800000000000000000000000000000001010000685D2CE00000000000007EAECB17BEB743EE19C5F6325E430FC4EBF1F7E98379F64DFB546AFD72929B7F73FFE8E80A32239B9649F87B8D6D934A0561FA1C4BF9B6F84B33E90744A6D5601C, valueString:0x888888888888EC68A58AB8094CC1AD20BA3D240200000000000000000000000000006ED800000000000000000000000000000001010000685D2CE00000000000007EAECB17BEB743EE19C5F6325E430FC4EBF1F7E98379F64DFB546AFD72929B7F73FFE8E80A32239B9649F87B8D6D934A0561FA1C4BF9B6F84B33E90744A6D5601C}, {name:signature, type:bytes, order:9, indexed:false, value:0xCB86E6988FEA95A98139C34CB2EC609134DA2FE2DBAFD7D47B5E5B882F15E72E53B2387196BE31A754A534423DD36C4BD105AAE2320349DF188ED57738D0A64C1C, valueString:0xCB86E6988FEA95A98139C34CB2EC609134DA2FE2DBAFD7D47B5E5B882F15E72E53B2387196BE31A754A534423DD36C4BD105AAE2320349DF188ED57738D0A64C1C}], userOpHash=738870A111FEEB5130505637DA99F5B6EFAF949D8799830ECD54E7DFDB9DBAC1, requiredPreFund=397346981238020 ) => ( context=0x, validationData=2558997000062931696710221669204783898330695627814259916800 )
      • Null: 0x000...001.54ee9a2c( )
      • EntryPoint.innerHandleOp( callData=0x34FCD5BE00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000001C000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000340000000000000000000000000D31B802B241277DFD20CD250E2C1664F0FD8B7270000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000A457FB25CC00000000000000000000000033158C65C91C0D36E7C2CFF50C41A29C2EBA92A400000000000000000000000033158C65C91C0D36E7C2CFF50C41A29C2EBA92A400000000000000000000000000000000000000000000000000000000000000640000000000000000000000000000000000000000000000000000000000000064000000000000000000000000E324C63FDB51F7D597FF68D92BEC74FA054EE12800000000000000000000000000000000000000000000000000000000000000000000000000000000D31B802B241277DFD20CD250E2C1664F0FD8B727000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000024130F3C8A000000000000000000000000D31B802B241277DFD20CD250E2C1664F0FD8B72700000000000000000000000000000000000000000000000000000000000000000000000000000000D31B802B241277DFD20CD250E2C1664F0FD8B727000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000024A526D83B0000000000000000000000009365487E19F17B121393351002B9B1C55CDCC4D600000000000000000000000000000000000000000000000000000000000000000000000000000000D31B802B241277DFD20CD250E2C1664F0FD8B727000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000024A526D83B00000000000000000000000091C3560CFAAEB34DFEB847953325299AD514158E00000000000000000000000000000000000000000000000000000000, opInfo=[{name:mUserOp, type:tuple, order:1, indexed:false, value:[{name:sender, type:address, order:1, indexed:false, value:0xD31b802B241277DFD20cD250e2C1664F0fd8b727, valueString:0xD31b802B241277DFD20cD250e2C1664F0fd8b727}, {name:nonce, type:uint256, order:2, indexed:false, value:32299071971826539878350634090496, valueString:32299071971826539878350634090496}, {name:verificationGasLimit, type:uint256, order:3, indexed:false, value:59304, valueString:59304}, {name:callGasLimit, type:uint256, order:4, indexed:false, value:90464, valueString:90464}, {name:paymasterVerificationGasLimit, type:uint256, order:5, indexed:false, value:28376, valueString:28376}, {name:paymasterPostOpGasLimit, type:uint256, order:6, indexed:false, value:1, valueString:1}, {name:preVerificationGas, type:uint256, order:7, indexed:false, value:85470, valueString:85470}, {name:paymaster, type:address, order:8, indexed:false, value:0x888888888888Ec68A58AB8094Cc1AD20Ba3D2402, valueString:0x888888888888Ec68A58AB8094Cc1AD20Ba3D2402}, {name:maxFeePerGas, type:uint256, order:9, indexed:false, value:1507300348, valueString:1507300348}, {name:maxPriorityFeePerGas, type:uint256, order:10, indexed:false, value:52500000, valueString:52500000}], valueString:[{name:sender, type:address, order:1, indexed:false, value:0xD31b802B241277DFD20cD250e2C1664F0fd8b727, valueString:0xD31b802B241277DFD20cD250e2C1664F0fd8b727}, {name:nonce, type:uint256, order:2, indexed:false, value:32299071971826539878350634090496, valueString:32299071971826539878350634090496}, {name:verificationGasLimit, type:uint256, order:3, indexed:false, value:59304, valueString:59304}, {name:callGasLimit, type:uint256, order:4, indexed:false, value:90464, valueString:90464}, {name:paymasterVerificationGasLimit, type:uint256, order:5, indexed:false, value:28376, valueString:28376}, {name:paymasterPostOpGasLimit, type:uint256, order:6, indexed:false, value:1, valueString:1}, {name:preVerificationGas, type:uint256, order:7, indexed:false, value:85470, valueString:85470}, {name:paymaster, type:address, order:8, indexed:false, value:0x888888888888Ec68A58AB8094Cc1AD20Ba3D2402, valueString:0x888888888888Ec68A58AB8094Cc1AD20Ba3D2402}, {name:maxFeePerGas, type:uint256, order:9, indexed:false, value:1507300348, valueString:1507300348}, {name:maxPriorityFeePerGas, type:uint256, order:10, indexed:false, value:52500000, valueString:52500000}]}, {name:userOpHash, type:bytes32, order:2, indexed:false, value:738870A111FEEB5130505637DA99F5B6EFAF949D8799830ECD54E7DFDB9DBAC1, valueString:738870A111FEEB5130505637DA99F5B6EFAF949D8799830ECD54E7DFDB9DBAC1}, {name:prefund, type:uint256, order:3, indexed:false, value:397346981238020, valueString:397346981238020}, {name:contextOffset, type:uint256, order:4, indexed:false, value:960, valueString:960}, {name:preOpGas, type:uint256, order:5, indexed:false, value:148821, valueString:148821}], context=0x ) => ( actualGasCost=289027280639860 )
        • 0xd31b802b241277dfd20cd250e2c1664f0fd8b727.34fcd5be( )
          • 0xd31b802b241277dfd20cd250e2c1664f0fd8b727.57fb25cc( )
          • 0xd31b802b241277dfd20cd250e2c1664f0fd8b727.130f3c8a( )
          • 0xd31b802b241277dfd20cd250e2c1664f0fd8b727.a526d83b( )
          • 0xd31b802b241277dfd20cd250e2c1664f0fd8b727.a526d83b( )
          • ETH 0.00028902728063986 Pimlico: ERC-4337 Bundler 9.CALL( )
            File 1 of 2: EntryPoint
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)
            pragma solidity ^0.8.20;
            interface IERC5267 {
                /**
                 * @dev MAY be emitted to signal that the domain could have changed.
                 */
                event EIP712DomainChanged();
                /**
                 * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712
                 * signature.
                 */
                function eip712Domain()
                    external
                    view
                    returns (
                        bytes1 fields,
                        string memory name,
                        string memory version,
                        uint256 chainId,
                        address verifyingContract,
                        bytes32 salt,
                        uint256[] memory extensions
                    );
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/EIP712.sol)
            pragma solidity ^0.8.20;
            import {MessageHashUtils} from "./MessageHashUtils.sol";
            import {ShortStrings, ShortString} from "../ShortStrings.sol";
            import {IERC5267} from "../../interfaces/IERC5267.sol";
            /**
             * @dev https://eips.ethereum.org/EIPS/eip-712[EIP-712] is a standard for hashing and signing of typed structured data.
             *
             * The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose
             * encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract
             * does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to
             * produce the hash of their typed data using a combination of `abi.encode` and `keccak256`.
             *
             * This contract implements the EIP-712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
             * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
             * ({_hashTypedDataV4}).
             *
             * The implementation of the domain separator was designed to be as efficient as possible while still properly updating
             * the chain id to protect against replay attacks on an eventual fork of the chain.
             *
             * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
             * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
             *
             * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain
             * separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the
             * separator from the immutable values, which is cheaper than accessing a cached version in cold storage.
             *
             * @custom:oz-upgrades-unsafe-allow state-variable-immutable
             */
            abstract contract EIP712 is IERC5267 {
                using ShortStrings for *;
                bytes32 private constant TYPE_HASH =
                    keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
                // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
                // invalidate the cached domain separator if the chain id changes.
                bytes32 private immutable _cachedDomainSeparator;
                uint256 private immutable _cachedChainId;
                address private immutable _cachedThis;
                bytes32 private immutable _hashedName;
                bytes32 private immutable _hashedVersion;
                ShortString private immutable _name;
                ShortString private immutable _version;
                string private _nameFallback;
                string private _versionFallback;
                /**
                 * @dev Initializes the domain separator and parameter caches.
                 *
                 * The meaning of `name` and `version` is specified in
                 * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP-712]:
                 *
                 * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
                 * - `version`: the current major version of the signing domain.
                 *
                 * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
                 * contract upgrade].
                 */
                constructor(string memory name, string memory version) {
                    _name = name.toShortStringWithFallback(_nameFallback);
                    _version = version.toShortStringWithFallback(_versionFallback);
                    _hashedName = keccak256(bytes(name));
                    _hashedVersion = keccak256(bytes(version));
                    _cachedChainId = block.chainid;
                    _cachedDomainSeparator = _buildDomainSeparator();
                    _cachedThis = address(this);
                }
                /**
                 * @dev Returns the domain separator for the current chain.
                 */
                function _domainSeparatorV4() internal view returns (bytes32) {
                    if (address(this) == _cachedThis && block.chainid == _cachedChainId) {
                        return _cachedDomainSeparator;
                    } else {
                        return _buildDomainSeparator();
                    }
                }
                function _buildDomainSeparator() private view returns (bytes32) {
                    return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
                }
                /**
                 * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
                 * function returns the hash of the fully encoded EIP712 message for this domain.
                 *
                 * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
                 *
                 * ```solidity
                 * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
                 *     keccak256("Mail(address to,string contents)"),
                 *     mailTo,
                 *     keccak256(bytes(mailContents))
                 * )));
                 * address signer = ECDSA.recover(digest, signature);
                 * ```
                 */
                function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
                    return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);
                }
                /**
                 * @dev See {IERC-5267}.
                 */
                function eip712Domain()
                    public
                    view
                    virtual
                    returns (
                        bytes1 fields,
                        string memory name,
                        string memory version,
                        uint256 chainId,
                        address verifyingContract,
                        bytes32 salt,
                        uint256[] memory extensions
                    )
                {
                    return (
                        hex"0f", // 01111
                        _EIP712Name(),
                        _EIP712Version(),
                        block.chainid,
                        address(this),
                        bytes32(0),
                        new uint256[](0)
                    );
                }
                /**
                 * @dev The name parameter for the EIP712 domain.
                 *
                 * NOTE: By default this function reads _name which is an immutable value.
                 * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
                 */
                // solhint-disable-next-line func-name-mixedcase
                function _EIP712Name() internal view returns (string memory) {
                    return _name.toStringWithFallback(_nameFallback);
                }
                /**
                 * @dev The version parameter for the EIP712 domain.
                 *
                 * NOTE: By default this function reads _version which is an immutable value.
                 * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
                 */
                // solhint-disable-next-line func-name-mixedcase
                function _EIP712Version() internal view returns (string memory) {
                    return _version.toStringWithFallback(_versionFallback);
                }
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.1.0) (utils/cryptography/MessageHashUtils.sol)
            pragma solidity ^0.8.20;
            import {Strings} from "../Strings.sol";
            /**
             * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.
             *
             * The library provides methods for generating a hash of a message that conforms to the
             * https://eips.ethereum.org/EIPS/eip-191[ERC-191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]
             * specifications.
             */
            library MessageHashUtils {
                /**
                 * @dev Returns the keccak256 digest of an ERC-191 signed data with version
                 * `0x45` (`personal_sign` messages).
                 *
                 * The digest is calculated by prefixing a bytes32 `messageHash` with
                 * `"\\x19Ethereum Signed Message:\
            32"` and hashing the result. It corresponds with the
                 * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
                 *
                 * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with
                 * keccak256, although any bytes32 value can be safely used because the final digest will
                 * be re-hashed.
                 *
                 * See {ECDSA-recover}.
                 */
                function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {
                    assembly ("memory-safe") {
                        mstore(0x00, "\\x19Ethereum Signed Message:\
            32") // 32 is the bytes-length of messageHash
                        mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix
                        digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)
                    }
                }
                /**
                 * @dev Returns the keccak256 digest of an ERC-191 signed data with version
                 * `0x45` (`personal_sign` messages).
                 *
                 * The digest is calculated by prefixing an arbitrary `message` with
                 * `"\\x19Ethereum Signed Message:\
            " + len(message)` and hashing the result. It corresponds with the
                 * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
                 *
                 * See {ECDSA-recover}.
                 */
                function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {
                    return
                        keccak256(bytes.concat("\\x19Ethereum Signed Message:\
            ", bytes(Strings.toString(message.length)), message));
                }
                /**
                 * @dev Returns the keccak256 digest of an ERC-191 signed data with version
                 * `0x00` (data with intended validator).
                 *
                 * The digest is calculated by prefixing an arbitrary `data` with `"\\x19\\x00"` and the intended
                 * `validator` address. Then hashing the result.
                 *
                 * See {ECDSA-recover}.
                 */
                function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
                    return keccak256(abi.encodePacked(hex"19_00", validator, data));
                }
                /**
                 * @dev Returns the keccak256 digest of an EIP-712 typed data (ERC-191 version `0x01`).
                 *
                 * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with
                 * `\\x19\\x01` and hashing the result. It corresponds to the hash signed by the
                 * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.
                 *
                 * See {ECDSA-recover}.
                 */
                function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {
                    assembly ("memory-safe") {
                        let ptr := mload(0x40)
                        mstore(ptr, hex"19_01")
                        mstore(add(ptr, 0x02), domainSeparator)
                        mstore(add(ptr, 0x22), structHash)
                        digest := keccak256(ptr, 0x42)
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165.sol)
            pragma solidity ^0.8.20;
            import {IERC165} from "./IERC165.sol";
            /**
             * @dev Implementation of the {IERC165} interface.
             *
             * Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check
             * for the additional interface id that will be supported. For example:
             *
             * ```solidity
             * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
             *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
             * }
             * ```
             */
            abstract contract ERC165 is IERC165 {
                /**
                 * @dev See {IERC165-supportsInterface}.
                 */
                function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
                    return interfaceId == type(IERC165).interfaceId;
                }
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
            pragma solidity ^0.8.20;
            /**
             * @dev Interface of the ERC-165 standard, as defined in the
             * https://eips.ethereum.org/EIPS/eip-165[ERC].
             *
             * Implementers can declare support of contract interfaces, which can then be
             * queried by others ({ERC165Checker}).
             *
             * For an implementation, see {ERC165}.
             */
            interface IERC165 {
                /**
                 * @dev Returns true if this contract implements the interface defined by
                 * `interfaceId`. See the corresponding
                 * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
                 * to learn more about how these ids are created.
                 *
                 * This function call must use less than 30 000 gas.
                 */
                function supportsInterface(bytes4 interfaceId) external view returns (bool);
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.1.0) (utils/math/Math.sol)
            pragma solidity ^0.8.20;
            import {Panic} from "../Panic.sol";
            import {SafeCast} from "./SafeCast.sol";
            /**
             * @dev Standard math utilities missing in the Solidity language.
             */
            library Math {
                enum Rounding {
                    Floor, // Toward negative infinity
                    Ceil, // Toward positive infinity
                    Trunc, // Toward zero
                    Expand // Away from zero
                }
                /**
                 * @dev Returns the addition of two unsigned integers, with an success flag (no overflow).
                 */
                function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
                    unchecked {
                        uint256 c = a + b;
                        if (c < a) return (false, 0);
                        return (true, c);
                    }
                }
                /**
                 * @dev Returns the subtraction of two unsigned integers, with an success flag (no overflow).
                 */
                function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
                    unchecked {
                        if (b > a) return (false, 0);
                        return (true, a - b);
                    }
                }
                /**
                 * @dev Returns the multiplication of two unsigned integers, with an success flag (no overflow).
                 */
                function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
                    unchecked {
                        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
                        // benefit is lost if 'b' is also tested.
                        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
                        if (a == 0) return (true, 0);
                        uint256 c = a * b;
                        if (c / a != b) return (false, 0);
                        return (true, c);
                    }
                }
                /**
                 * @dev Returns the division of two unsigned integers, with a success flag (no division by zero).
                 */
                function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
                    unchecked {
                        if (b == 0) return (false, 0);
                        return (true, a / b);
                    }
                }
                /**
                 * @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).
                 */
                function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
                    unchecked {
                        if (b == 0) return (false, 0);
                        return (true, a % b);
                    }
                }
                /**
                 * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
                 *
                 * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
                 * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
                 * one branch when needed, making this function more expensive.
                 */
                function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
                    unchecked {
                        // branchless ternary works because:
                        // b ^ (a ^ b) == a
                        // b ^ 0 == b
                        return b ^ ((a ^ b) * SafeCast.toUint(condition));
                    }
                }
                /**
                 * @dev Returns the largest of two numbers.
                 */
                function max(uint256 a, uint256 b) internal pure returns (uint256) {
                    return ternary(a > b, a, b);
                }
                /**
                 * @dev Returns the smallest of two numbers.
                 */
                function min(uint256 a, uint256 b) internal pure returns (uint256) {
                    return ternary(a < b, a, b);
                }
                /**
                 * @dev Returns the average of two numbers. The result is rounded towards
                 * zero.
                 */
                function average(uint256 a, uint256 b) internal pure returns (uint256) {
                    // (a + b) / 2 can overflow.
                    return (a & b) + (a ^ b) / 2;
                }
                /**
                 * @dev Returns the ceiling of the division of two numbers.
                 *
                 * This differs from standard division with `/` in that it rounds towards infinity instead
                 * of rounding towards zero.
                 */
                function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
                    if (b == 0) {
                        // Guarantee the same behavior as in a regular Solidity division.
                        Panic.panic(Panic.DIVISION_BY_ZERO);
                    }
                    // The following calculation ensures accurate ceiling division without overflow.
                    // Since a is non-zero, (a - 1) / b will not overflow.
                    // The largest possible result occurs when (a - 1) / b is type(uint256).max,
                    // but the largest value we can obtain is type(uint256).max - 1, which happens
                    // when a = type(uint256).max and b = 1.
                    unchecked {
                        return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
                    }
                }
                /**
                 * @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
                 * denominator == 0.
                 *
                 * Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
                 * Uniswap Labs also under MIT license.
                 */
                function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
                    unchecked {
                        // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use
                        // the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
                        // variables such that product = prod1 * 2²⁵⁶ + prod0.
                        uint256 prod0 = x * y; // Least significant 256 bits of the product
                        uint256 prod1; // Most significant 256 bits of the product
                        assembly {
                            let mm := mulmod(x, y, not(0))
                            prod1 := sub(sub(mm, prod0), lt(mm, prod0))
                        }
                        // Handle non-overflow cases, 256 by 256 division.
                        if (prod1 == 0) {
                            // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                            // The surrounding unchecked block does not change this fact.
                            // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                            return prod0 / denominator;
                        }
                        // Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
                        if (denominator <= prod1) {
                            Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
                        }
                        ///////////////////////////////////////////////
                        // 512 by 256 division.
                        ///////////////////////////////////////////////
                        // Make division exact by subtracting the remainder from [prod1 prod0].
                        uint256 remainder;
                        assembly {
                            // Compute remainder using mulmod.
                            remainder := mulmod(x, y, denominator)
                            // Subtract 256 bit number from 512 bit number.
                            prod1 := sub(prod1, gt(remainder, prod0))
                            prod0 := sub(prod0, remainder)
                        }
                        // Factor powers of two out of denominator and compute largest power of two divisor of denominator.
                        // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
                        uint256 twos = denominator & (0 - denominator);
                        assembly {
                            // Divide denominator by twos.
                            denominator := div(denominator, twos)
                            // Divide [prod1 prod0] by twos.
                            prod0 := div(prod0, twos)
                            // Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.
                            twos := add(div(sub(0, twos), twos), 1)
                        }
                        // Shift in bits from prod1 into prod0.
                        prod0 |= prod1 * twos;
                        // Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such
                        // that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for
                        // four bits. That is, denominator * inv ≡ 1 mod 2⁴.
                        uint256 inverse = (3 * denominator) ^ 2;
                        // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
                        // works in modular arithmetic, doubling the correct bits in each step.
                        inverse *= 2 - denominator * inverse; // inverse mod 2⁸
                        inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
                        inverse *= 2 - denominator * inverse; // inverse mod 2³²
                        inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
                        inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
                        inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶
                        // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
                        // This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is
                        // less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and prod1
                        // is no longer required.
                        result = prod0 * inverse;
                        return result;
                    }
                }
                /**
                 * @dev Calculates x * y / denominator with full precision, following the selected rounding direction.
                 */
                function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
                    return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
                }
                /**
                 * @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
                 *
                 * If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
                 * If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
                 *
                 * If the input value is not inversible, 0 is returned.
                 *
                 * NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
                 * inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
                 */
                function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
                    unchecked {
                        if (n == 0) return 0;
                        // The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
                        // Used to compute integers x and y such that: ax + ny = gcd(a, n).
                        // When the gcd is 1, then the inverse of a modulo n exists and it's x.
                        // ax + ny = 1
                        // ax = 1 + (-y)n
                        // ax ≡ 1 (mod n) # x is the inverse of a modulo n
                        // If the remainder is 0 the gcd is n right away.
                        uint256 remainder = a % n;
                        uint256 gcd = n;
                        // Therefore the initial coefficients are:
                        // ax + ny = gcd(a, n) = n
                        // 0a + 1n = n
                        int256 x = 0;
                        int256 y = 1;
                        while (remainder != 0) {
                            uint256 quotient = gcd / remainder;
                            (gcd, remainder) = (
                                // The old remainder is the next gcd to try.
                                remainder,
                                // Compute the next remainder.
                                // Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
                                // where gcd is at most n (capped to type(uint256).max)
                                gcd - remainder * quotient
                            );
                            (x, y) = (
                                // Increment the coefficient of a.
                                y,
                                // Decrement the coefficient of n.
                                // Can overflow, but the result is casted to uint256 so that the
                                // next value of y is "wrapped around" to a value between 0 and n - 1.
                                x - y * int256(quotient)
                            );
                        }
                        if (gcd != 1) return 0; // No inverse exists.
                        return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
                    }
                }
                /**
                 * @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
                 *
                 * From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
                 * prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
                 * `a**(p-2)` is the modular multiplicative inverse of a in Fp.
                 *
                 * NOTE: this function does NOT check that `p` is a prime greater than `2`.
                 */
                function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
                    unchecked {
                        return Math.modExp(a, p - 2, p);
                    }
                }
                /**
                 * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
                 *
                 * Requirements:
                 * - modulus can't be zero
                 * - underlying staticcall to precompile must succeed
                 *
                 * IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
                 * sure the chain you're using it on supports the precompiled contract for modular exponentiation
                 * at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
                 * the underlying function will succeed given the lack of a revert, but the result may be incorrectly
                 * interpreted as 0.
                 */
                function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
                    (bool success, uint256 result) = tryModExp(b, e, m);
                    if (!success) {
                        Panic.panic(Panic.DIVISION_BY_ZERO);
                    }
                    return result;
                }
                /**
                 * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
                 * It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
                 * to operate modulo 0 or if the underlying precompile reverted.
                 *
                 * IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
                 * you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
                 * https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
                 * of a revert, but the result may be incorrectly interpreted as 0.
                 */
                function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
                    if (m == 0) return (false, 0);
                    assembly ("memory-safe") {
                        let ptr := mload(0x40)
                        // | Offset    | Content    | Content (Hex)                                                      |
                        // |-----------|------------|--------------------------------------------------------------------|
                        // | 0x00:0x1f | size of b  | 0x0000000000000000000000000000000000000000000000000000000000000020 |
                        // | 0x20:0x3f | size of e  | 0x0000000000000000000000000000000000000000000000000000000000000020 |
                        // | 0x40:0x5f | size of m  | 0x0000000000000000000000000000000000000000000000000000000000000020 |
                        // | 0x60:0x7f | value of b | 0x<.............................................................b> |
                        // | 0x80:0x9f | value of e | 0x<.............................................................e> |
                        // | 0xa0:0xbf | value of m | 0x<.............................................................m> |
                        mstore(ptr, 0x20)
                        mstore(add(ptr, 0x20), 0x20)
                        mstore(add(ptr, 0x40), 0x20)
                        mstore(add(ptr, 0x60), b)
                        mstore(add(ptr, 0x80), e)
                        mstore(add(ptr, 0xa0), m)
                        // Given the result < m, it's guaranteed to fit in 32 bytes,
                        // so we can use the memory scratch space located at offset 0.
                        success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
                        result := mload(0x00)
                    }
                }
                /**
                 * @dev Variant of {modExp} that supports inputs of arbitrary length.
                 */
                function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
                    (bool success, bytes memory result) = tryModExp(b, e, m);
                    if (!success) {
                        Panic.panic(Panic.DIVISION_BY_ZERO);
                    }
                    return result;
                }
                /**
                 * @dev Variant of {tryModExp} that supports inputs of arbitrary length.
                 */
                function tryModExp(
                    bytes memory b,
                    bytes memory e,
                    bytes memory m
                ) internal view returns (bool success, bytes memory result) {
                    if (_zeroBytes(m)) return (false, new bytes(0));
                    uint256 mLen = m.length;
                    // Encode call args in result and move the free memory pointer
                    result = abi.encodePacked(b.length, e.length, mLen, b, e, m);
                    assembly ("memory-safe") {
                        let dataPtr := add(result, 0x20)
                        // Write result on top of args to avoid allocating extra memory.
                        success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
                        // Overwrite the length.
                        // result.length > returndatasize() is guaranteed because returndatasize() == m.length
                        mstore(result, mLen)
                        // Set the memory pointer after the returned data.
                        mstore(0x40, add(dataPtr, mLen))
                    }
                }
                /**
                 * @dev Returns whether the provided byte array is zero.
                 */
                function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
                    for (uint256 i = 0; i < byteArray.length; ++i) {
                        if (byteArray[i] != 0) {
                            return false;
                        }
                    }
                    return true;
                }
                /**
                 * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
                 * towards zero.
                 *
                 * This method is based on Newton's method for computing square roots; the algorithm is restricted to only
                 * using integer operations.
                 */
                function sqrt(uint256 a) internal pure returns (uint256) {
                    unchecked {
                        // Take care of easy edge cases when a == 0 or a == 1
                        if (a <= 1) {
                            return a;
                        }
                        // In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
                        // sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
                        // the current value as `ε_n = | x_n - sqrt(a) |`.
                        //
                        // For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
                        // of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
                        // bigger than any uint256.
                        //
                        // By noticing that
                        // `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
                        // we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
                        // to the msb function.
                        uint256 aa = a;
                        uint256 xn = 1;
                        if (aa >= (1 << 128)) {
                            aa >>= 128;
                            xn <<= 64;
                        }
                        if (aa >= (1 << 64)) {
                            aa >>= 64;
                            xn <<= 32;
                        }
                        if (aa >= (1 << 32)) {
                            aa >>= 32;
                            xn <<= 16;
                        }
                        if (aa >= (1 << 16)) {
                            aa >>= 16;
                            xn <<= 8;
                        }
                        if (aa >= (1 << 8)) {
                            aa >>= 8;
                            xn <<= 4;
                        }
                        if (aa >= (1 << 4)) {
                            aa >>= 4;
                            xn <<= 2;
                        }
                        if (aa >= (1 << 2)) {
                            xn <<= 1;
                        }
                        // We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
                        //
                        // We can refine our estimation by noticing that the middle of that interval minimizes the error.
                        // If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
                        // This is going to be our x_0 (and ε_0)
                        xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)
                        // From here, Newton's method give us:
                        // x_{n+1} = (x_n + a / x_n) / 2
                        //
                        // One should note that:
                        // x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
                        //              = ((x_n² + a) / (2 * x_n))² - a
                        //              = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
                        //              = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
                        //              = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
                        //              = (x_n² - a)² / (2 * x_n)²
                        //              = ((x_n² - a) / (2 * x_n))²
                        //              ≥ 0
                        // Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
                        //
                        // This gives us the proof of quadratic convergence of the sequence:
                        // ε_{n+1} = | x_{n+1} - sqrt(a) |
                        //         = | (x_n + a / x_n) / 2 - sqrt(a) |
                        //         = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
                        //         = | (x_n - sqrt(a))² / (2 * x_n) |
                        //         = | ε_n² / (2 * x_n) |
                        //         = ε_n² / | (2 * x_n) |
                        //
                        // For the first iteration, we have a special case where x_0 is known:
                        // ε_1 = ε_0² / | (2 * x_0) |
                        //     ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
                        //     ≤ 2**(2*e-4) / (3 * 2**(e-1))
                        //     ≤ 2**(e-3) / 3
                        //     ≤ 2**(e-3-log2(3))
                        //     ≤ 2**(e-4.5)
                        //
                        // For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
                        // ε_{n+1} = ε_n² / | (2 * x_n) |
                        //         ≤ (2**(e-k))² / (2 * 2**(e-1))
                        //         ≤ 2**(2*e-2*k) / 2**e
                        //         ≤ 2**(e-2*k)
                        xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5)  -- special case, see above
                        xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9)    -- general case with k = 4.5
                        xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18)   -- general case with k = 9
                        xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36)   -- general case with k = 18
                        xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72)   -- general case with k = 36
                        xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144)  -- general case with k = 72
                        // Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
                        // ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
                        // sqrt(a) or sqrt(a) + 1.
                        return xn - SafeCast.toUint(xn > a / xn);
                    }
                }
                /**
                 * @dev Calculates sqrt(a), following the selected rounding direction.
                 */
                function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
                    unchecked {
                        uint256 result = sqrt(a);
                        return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
                    }
                }
                /**
                 * @dev Return the log in base 2 of a positive value rounded towards zero.
                 * Returns 0 if given 0.
                 */
                function log2(uint256 value) internal pure returns (uint256) {
                    uint256 result = 0;
                    uint256 exp;
                    unchecked {
                        exp = 128 * SafeCast.toUint(value > (1 << 128) - 1);
                        value >>= exp;
                        result += exp;
                        exp = 64 * SafeCast.toUint(value > (1 << 64) - 1);
                        value >>= exp;
                        result += exp;
                        exp = 32 * SafeCast.toUint(value > (1 << 32) - 1);
                        value >>= exp;
                        result += exp;
                        exp = 16 * SafeCast.toUint(value > (1 << 16) - 1);
                        value >>= exp;
                        result += exp;
                        exp = 8 * SafeCast.toUint(value > (1 << 8) - 1);
                        value >>= exp;
                        result += exp;
                        exp = 4 * SafeCast.toUint(value > (1 << 4) - 1);
                        value >>= exp;
                        result += exp;
                        exp = 2 * SafeCast.toUint(value > (1 << 2) - 1);
                        value >>= exp;
                        result += exp;
                        result += SafeCast.toUint(value > 1);
                    }
                    return result;
                }
                /**
                 * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
                 * Returns 0 if given 0.
                 */
                function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
                    unchecked {
                        uint256 result = log2(value);
                        return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
                    }
                }
                /**
                 * @dev Return the log in base 10 of a positive value rounded towards zero.
                 * Returns 0 if given 0.
                 */
                function log10(uint256 value) internal pure returns (uint256) {
                    uint256 result = 0;
                    unchecked {
                        if (value >= 10 ** 64) {
                            value /= 10 ** 64;
                            result += 64;
                        }
                        if (value >= 10 ** 32) {
                            value /= 10 ** 32;
                            result += 32;
                        }
                        if (value >= 10 ** 16) {
                            value /= 10 ** 16;
                            result += 16;
                        }
                        if (value >= 10 ** 8) {
                            value /= 10 ** 8;
                            result += 8;
                        }
                        if (value >= 10 ** 4) {
                            value /= 10 ** 4;
                            result += 4;
                        }
                        if (value >= 10 ** 2) {
                            value /= 10 ** 2;
                            result += 2;
                        }
                        if (value >= 10 ** 1) {
                            result += 1;
                        }
                    }
                    return result;
                }
                /**
                 * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
                 * Returns 0 if given 0.
                 */
                function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
                    unchecked {
                        uint256 result = log10(value);
                        return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
                    }
                }
                /**
                 * @dev Return the log in base 256 of a positive value rounded towards zero.
                 * Returns 0 if given 0.
                 *
                 * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
                 */
                function log256(uint256 value) internal pure returns (uint256) {
                    uint256 result = 0;
                    uint256 isGt;
                    unchecked {
                        isGt = SafeCast.toUint(value > (1 << 128) - 1);
                        value >>= isGt * 128;
                        result += isGt * 16;
                        isGt = SafeCast.toUint(value > (1 << 64) - 1);
                        value >>= isGt * 64;
                        result += isGt * 8;
                        isGt = SafeCast.toUint(value > (1 << 32) - 1);
                        value >>= isGt * 32;
                        result += isGt * 4;
                        isGt = SafeCast.toUint(value > (1 << 16) - 1);
                        value >>= isGt * 16;
                        result += isGt * 2;
                        result += SafeCast.toUint(value > (1 << 8) - 1);
                    }
                    return result;
                }
                /**
                 * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
                 * Returns 0 if given 0.
                 */
                function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
                    unchecked {
                        uint256 result = log256(value);
                        return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
                    }
                }
                /**
                 * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
                 */
                function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
                    return uint8(rounding) % 2 == 1;
                }
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
            // This file was procedurally generated from scripts/generate/templates/SafeCast.js.
            pragma solidity ^0.8.20;
            /**
             * @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
             * checks.
             *
             * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
             * easily result in undesired exploitation or bugs, since developers usually
             * assume that overflows raise errors. `SafeCast` restores this intuition by
             * reverting the transaction when such an operation overflows.
             *
             * Using this library instead of the unchecked operations eliminates an entire
             * class of bugs, so it's recommended to use it always.
             */
            library SafeCast {
                /**
                 * @dev Value doesn't fit in an uint of `bits` size.
                 */
                error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
                /**
                 * @dev An int value doesn't fit in an uint of `bits` size.
                 */
                error SafeCastOverflowedIntToUint(int256 value);
                /**
                 * @dev Value doesn't fit in an int of `bits` size.
                 */
                error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
                /**
                 * @dev An uint value doesn't fit in an int of `bits` size.
                 */
                error SafeCastOverflowedUintToInt(uint256 value);
                /**
                 * @dev Returns the downcasted uint248 from uint256, reverting on
                 * overflow (when the input is greater than largest uint248).
                 *
                 * Counterpart to Solidity's `uint248` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 248 bits
                 */
                function toUint248(uint256 value) internal pure returns (uint248) {
                    if (value > type(uint248).max) {
                        revert SafeCastOverflowedUintDowncast(248, value);
                    }
                    return uint248(value);
                }
                /**
                 * @dev Returns the downcasted uint240 from uint256, reverting on
                 * overflow (when the input is greater than largest uint240).
                 *
                 * Counterpart to Solidity's `uint240` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 240 bits
                 */
                function toUint240(uint256 value) internal pure returns (uint240) {
                    if (value > type(uint240).max) {
                        revert SafeCastOverflowedUintDowncast(240, value);
                    }
                    return uint240(value);
                }
                /**
                 * @dev Returns the downcasted uint232 from uint256, reverting on
                 * overflow (when the input is greater than largest uint232).
                 *
                 * Counterpart to Solidity's `uint232` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 232 bits
                 */
                function toUint232(uint256 value) internal pure returns (uint232) {
                    if (value > type(uint232).max) {
                        revert SafeCastOverflowedUintDowncast(232, value);
                    }
                    return uint232(value);
                }
                /**
                 * @dev Returns the downcasted uint224 from uint256, reverting on
                 * overflow (when the input is greater than largest uint224).
                 *
                 * Counterpart to Solidity's `uint224` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 224 bits
                 */
                function toUint224(uint256 value) internal pure returns (uint224) {
                    if (value > type(uint224).max) {
                        revert SafeCastOverflowedUintDowncast(224, value);
                    }
                    return uint224(value);
                }
                /**
                 * @dev Returns the downcasted uint216 from uint256, reverting on
                 * overflow (when the input is greater than largest uint216).
                 *
                 * Counterpart to Solidity's `uint216` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 216 bits
                 */
                function toUint216(uint256 value) internal pure returns (uint216) {
                    if (value > type(uint216).max) {
                        revert SafeCastOverflowedUintDowncast(216, value);
                    }
                    return uint216(value);
                }
                /**
                 * @dev Returns the downcasted uint208 from uint256, reverting on
                 * overflow (when the input is greater than largest uint208).
                 *
                 * Counterpart to Solidity's `uint208` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 208 bits
                 */
                function toUint208(uint256 value) internal pure returns (uint208) {
                    if (value > type(uint208).max) {
                        revert SafeCastOverflowedUintDowncast(208, value);
                    }
                    return uint208(value);
                }
                /**
                 * @dev Returns the downcasted uint200 from uint256, reverting on
                 * overflow (when the input is greater than largest uint200).
                 *
                 * Counterpart to Solidity's `uint200` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 200 bits
                 */
                function toUint200(uint256 value) internal pure returns (uint200) {
                    if (value > type(uint200).max) {
                        revert SafeCastOverflowedUintDowncast(200, value);
                    }
                    return uint200(value);
                }
                /**
                 * @dev Returns the downcasted uint192 from uint256, reverting on
                 * overflow (when the input is greater than largest uint192).
                 *
                 * Counterpart to Solidity's `uint192` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 192 bits
                 */
                function toUint192(uint256 value) internal pure returns (uint192) {
                    if (value > type(uint192).max) {
                        revert SafeCastOverflowedUintDowncast(192, value);
                    }
                    return uint192(value);
                }
                /**
                 * @dev Returns the downcasted uint184 from uint256, reverting on
                 * overflow (when the input is greater than largest uint184).
                 *
                 * Counterpart to Solidity's `uint184` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 184 bits
                 */
                function toUint184(uint256 value) internal pure returns (uint184) {
                    if (value > type(uint184).max) {
                        revert SafeCastOverflowedUintDowncast(184, value);
                    }
                    return uint184(value);
                }
                /**
                 * @dev Returns the downcasted uint176 from uint256, reverting on
                 * overflow (when the input is greater than largest uint176).
                 *
                 * Counterpart to Solidity's `uint176` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 176 bits
                 */
                function toUint176(uint256 value) internal pure returns (uint176) {
                    if (value > type(uint176).max) {
                        revert SafeCastOverflowedUintDowncast(176, value);
                    }
                    return uint176(value);
                }
                /**
                 * @dev Returns the downcasted uint168 from uint256, reverting on
                 * overflow (when the input is greater than largest uint168).
                 *
                 * Counterpart to Solidity's `uint168` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 168 bits
                 */
                function toUint168(uint256 value) internal pure returns (uint168) {
                    if (value > type(uint168).max) {
                        revert SafeCastOverflowedUintDowncast(168, value);
                    }
                    return uint168(value);
                }
                /**
                 * @dev Returns the downcasted uint160 from uint256, reverting on
                 * overflow (when the input is greater than largest uint160).
                 *
                 * Counterpart to Solidity's `uint160` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 160 bits
                 */
                function toUint160(uint256 value) internal pure returns (uint160) {
                    if (value > type(uint160).max) {
                        revert SafeCastOverflowedUintDowncast(160, value);
                    }
                    return uint160(value);
                }
                /**
                 * @dev Returns the downcasted uint152 from uint256, reverting on
                 * overflow (when the input is greater than largest uint152).
                 *
                 * Counterpart to Solidity's `uint152` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 152 bits
                 */
                function toUint152(uint256 value) internal pure returns (uint152) {
                    if (value > type(uint152).max) {
                        revert SafeCastOverflowedUintDowncast(152, value);
                    }
                    return uint152(value);
                }
                /**
                 * @dev Returns the downcasted uint144 from uint256, reverting on
                 * overflow (when the input is greater than largest uint144).
                 *
                 * Counterpart to Solidity's `uint144` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 144 bits
                 */
                function toUint144(uint256 value) internal pure returns (uint144) {
                    if (value > type(uint144).max) {
                        revert SafeCastOverflowedUintDowncast(144, value);
                    }
                    return uint144(value);
                }
                /**
                 * @dev Returns the downcasted uint136 from uint256, reverting on
                 * overflow (when the input is greater than largest uint136).
                 *
                 * Counterpart to Solidity's `uint136` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 136 bits
                 */
                function toUint136(uint256 value) internal pure returns (uint136) {
                    if (value > type(uint136).max) {
                        revert SafeCastOverflowedUintDowncast(136, value);
                    }
                    return uint136(value);
                }
                /**
                 * @dev Returns the downcasted uint128 from uint256, reverting on
                 * overflow (when the input is greater than largest uint128).
                 *
                 * Counterpart to Solidity's `uint128` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 128 bits
                 */
                function toUint128(uint256 value) internal pure returns (uint128) {
                    if (value > type(uint128).max) {
                        revert SafeCastOverflowedUintDowncast(128, value);
                    }
                    return uint128(value);
                }
                /**
                 * @dev Returns the downcasted uint120 from uint256, reverting on
                 * overflow (when the input is greater than largest uint120).
                 *
                 * Counterpart to Solidity's `uint120` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 120 bits
                 */
                function toUint120(uint256 value) internal pure returns (uint120) {
                    if (value > type(uint120).max) {
                        revert SafeCastOverflowedUintDowncast(120, value);
                    }
                    return uint120(value);
                }
                /**
                 * @dev Returns the downcasted uint112 from uint256, reverting on
                 * overflow (when the input is greater than largest uint112).
                 *
                 * Counterpart to Solidity's `uint112` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 112 bits
                 */
                function toUint112(uint256 value) internal pure returns (uint112) {
                    if (value > type(uint112).max) {
                        revert SafeCastOverflowedUintDowncast(112, value);
                    }
                    return uint112(value);
                }
                /**
                 * @dev Returns the downcasted uint104 from uint256, reverting on
                 * overflow (when the input is greater than largest uint104).
                 *
                 * Counterpart to Solidity's `uint104` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 104 bits
                 */
                function toUint104(uint256 value) internal pure returns (uint104) {
                    if (value > type(uint104).max) {
                        revert SafeCastOverflowedUintDowncast(104, value);
                    }
                    return uint104(value);
                }
                /**
                 * @dev Returns the downcasted uint96 from uint256, reverting on
                 * overflow (when the input is greater than largest uint96).
                 *
                 * Counterpart to Solidity's `uint96` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 96 bits
                 */
                function toUint96(uint256 value) internal pure returns (uint96) {
                    if (value > type(uint96).max) {
                        revert SafeCastOverflowedUintDowncast(96, value);
                    }
                    return uint96(value);
                }
                /**
                 * @dev Returns the downcasted uint88 from uint256, reverting on
                 * overflow (when the input is greater than largest uint88).
                 *
                 * Counterpart to Solidity's `uint88` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 88 bits
                 */
                function toUint88(uint256 value) internal pure returns (uint88) {
                    if (value > type(uint88).max) {
                        revert SafeCastOverflowedUintDowncast(88, value);
                    }
                    return uint88(value);
                }
                /**
                 * @dev Returns the downcasted uint80 from uint256, reverting on
                 * overflow (when the input is greater than largest uint80).
                 *
                 * Counterpart to Solidity's `uint80` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 80 bits
                 */
                function toUint80(uint256 value) internal pure returns (uint80) {
                    if (value > type(uint80).max) {
                        revert SafeCastOverflowedUintDowncast(80, value);
                    }
                    return uint80(value);
                }
                /**
                 * @dev Returns the downcasted uint72 from uint256, reverting on
                 * overflow (when the input is greater than largest uint72).
                 *
                 * Counterpart to Solidity's `uint72` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 72 bits
                 */
                function toUint72(uint256 value) internal pure returns (uint72) {
                    if (value > type(uint72).max) {
                        revert SafeCastOverflowedUintDowncast(72, value);
                    }
                    return uint72(value);
                }
                /**
                 * @dev Returns the downcasted uint64 from uint256, reverting on
                 * overflow (when the input is greater than largest uint64).
                 *
                 * Counterpart to Solidity's `uint64` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 64 bits
                 */
                function toUint64(uint256 value) internal pure returns (uint64) {
                    if (value > type(uint64).max) {
                        revert SafeCastOverflowedUintDowncast(64, value);
                    }
                    return uint64(value);
                }
                /**
                 * @dev Returns the downcasted uint56 from uint256, reverting on
                 * overflow (when the input is greater than largest uint56).
                 *
                 * Counterpart to Solidity's `uint56` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 56 bits
                 */
                function toUint56(uint256 value) internal pure returns (uint56) {
                    if (value > type(uint56).max) {
                        revert SafeCastOverflowedUintDowncast(56, value);
                    }
                    return uint56(value);
                }
                /**
                 * @dev Returns the downcasted uint48 from uint256, reverting on
                 * overflow (when the input is greater than largest uint48).
                 *
                 * Counterpart to Solidity's `uint48` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 48 bits
                 */
                function toUint48(uint256 value) internal pure returns (uint48) {
                    if (value > type(uint48).max) {
                        revert SafeCastOverflowedUintDowncast(48, value);
                    }
                    return uint48(value);
                }
                /**
                 * @dev Returns the downcasted uint40 from uint256, reverting on
                 * overflow (when the input is greater than largest uint40).
                 *
                 * Counterpart to Solidity's `uint40` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 40 bits
                 */
                function toUint40(uint256 value) internal pure returns (uint40) {
                    if (value > type(uint40).max) {
                        revert SafeCastOverflowedUintDowncast(40, value);
                    }
                    return uint40(value);
                }
                /**
                 * @dev Returns the downcasted uint32 from uint256, reverting on
                 * overflow (when the input is greater than largest uint32).
                 *
                 * Counterpart to Solidity's `uint32` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 32 bits
                 */
                function toUint32(uint256 value) internal pure returns (uint32) {
                    if (value > type(uint32).max) {
                        revert SafeCastOverflowedUintDowncast(32, value);
                    }
                    return uint32(value);
                }
                /**
                 * @dev Returns the downcasted uint24 from uint256, reverting on
                 * overflow (when the input is greater than largest uint24).
                 *
                 * Counterpart to Solidity's `uint24` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 24 bits
                 */
                function toUint24(uint256 value) internal pure returns (uint24) {
                    if (value > type(uint24).max) {
                        revert SafeCastOverflowedUintDowncast(24, value);
                    }
                    return uint24(value);
                }
                /**
                 * @dev Returns the downcasted uint16 from uint256, reverting on
                 * overflow (when the input is greater than largest uint16).
                 *
                 * Counterpart to Solidity's `uint16` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 16 bits
                 */
                function toUint16(uint256 value) internal pure returns (uint16) {
                    if (value > type(uint16).max) {
                        revert SafeCastOverflowedUintDowncast(16, value);
                    }
                    return uint16(value);
                }
                /**
                 * @dev Returns the downcasted uint8 from uint256, reverting on
                 * overflow (when the input is greater than largest uint8).
                 *
                 * Counterpart to Solidity's `uint8` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 8 bits
                 */
                function toUint8(uint256 value) internal pure returns (uint8) {
                    if (value > type(uint8).max) {
                        revert SafeCastOverflowedUintDowncast(8, value);
                    }
                    return uint8(value);
                }
                /**
                 * @dev Converts a signed int256 into an unsigned uint256.
                 *
                 * Requirements:
                 *
                 * - input must be greater than or equal to 0.
                 */
                function toUint256(int256 value) internal pure returns (uint256) {
                    if (value < 0) {
                        revert SafeCastOverflowedIntToUint(value);
                    }
                    return uint256(value);
                }
                /**
                 * @dev Returns the downcasted int248 from int256, reverting on
                 * overflow (when the input is less than smallest int248 or
                 * greater than largest int248).
                 *
                 * Counterpart to Solidity's `int248` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 248 bits
                 */
                function toInt248(int256 value) internal pure returns (int248 downcasted) {
                    downcasted = int248(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(248, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int240 from int256, reverting on
                 * overflow (when the input is less than smallest int240 or
                 * greater than largest int240).
                 *
                 * Counterpart to Solidity's `int240` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 240 bits
                 */
                function toInt240(int256 value) internal pure returns (int240 downcasted) {
                    downcasted = int240(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(240, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int232 from int256, reverting on
                 * overflow (when the input is less than smallest int232 or
                 * greater than largest int232).
                 *
                 * Counterpart to Solidity's `int232` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 232 bits
                 */
                function toInt232(int256 value) internal pure returns (int232 downcasted) {
                    downcasted = int232(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(232, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int224 from int256, reverting on
                 * overflow (when the input is less than smallest int224 or
                 * greater than largest int224).
                 *
                 * Counterpart to Solidity's `int224` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 224 bits
                 */
                function toInt224(int256 value) internal pure returns (int224 downcasted) {
                    downcasted = int224(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(224, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int216 from int256, reverting on
                 * overflow (when the input is less than smallest int216 or
                 * greater than largest int216).
                 *
                 * Counterpart to Solidity's `int216` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 216 bits
                 */
                function toInt216(int256 value) internal pure returns (int216 downcasted) {
                    downcasted = int216(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(216, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int208 from int256, reverting on
                 * overflow (when the input is less than smallest int208 or
                 * greater than largest int208).
                 *
                 * Counterpart to Solidity's `int208` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 208 bits
                 */
                function toInt208(int256 value) internal pure returns (int208 downcasted) {
                    downcasted = int208(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(208, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int200 from int256, reverting on
                 * overflow (when the input is less than smallest int200 or
                 * greater than largest int200).
                 *
                 * Counterpart to Solidity's `int200` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 200 bits
                 */
                function toInt200(int256 value) internal pure returns (int200 downcasted) {
                    downcasted = int200(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(200, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int192 from int256, reverting on
                 * overflow (when the input is less than smallest int192 or
                 * greater than largest int192).
                 *
                 * Counterpart to Solidity's `int192` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 192 bits
                 */
                function toInt192(int256 value) internal pure returns (int192 downcasted) {
                    downcasted = int192(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(192, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int184 from int256, reverting on
                 * overflow (when the input is less than smallest int184 or
                 * greater than largest int184).
                 *
                 * Counterpart to Solidity's `int184` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 184 bits
                 */
                function toInt184(int256 value) internal pure returns (int184 downcasted) {
                    downcasted = int184(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(184, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int176 from int256, reverting on
                 * overflow (when the input is less than smallest int176 or
                 * greater than largest int176).
                 *
                 * Counterpart to Solidity's `int176` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 176 bits
                 */
                function toInt176(int256 value) internal pure returns (int176 downcasted) {
                    downcasted = int176(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(176, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int168 from int256, reverting on
                 * overflow (when the input is less than smallest int168 or
                 * greater than largest int168).
                 *
                 * Counterpart to Solidity's `int168` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 168 bits
                 */
                function toInt168(int256 value) internal pure returns (int168 downcasted) {
                    downcasted = int168(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(168, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int160 from int256, reverting on
                 * overflow (when the input is less than smallest int160 or
                 * greater than largest int160).
                 *
                 * Counterpart to Solidity's `int160` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 160 bits
                 */
                function toInt160(int256 value) internal pure returns (int160 downcasted) {
                    downcasted = int160(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(160, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int152 from int256, reverting on
                 * overflow (when the input is less than smallest int152 or
                 * greater than largest int152).
                 *
                 * Counterpart to Solidity's `int152` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 152 bits
                 */
                function toInt152(int256 value) internal pure returns (int152 downcasted) {
                    downcasted = int152(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(152, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int144 from int256, reverting on
                 * overflow (when the input is less than smallest int144 or
                 * greater than largest int144).
                 *
                 * Counterpart to Solidity's `int144` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 144 bits
                 */
                function toInt144(int256 value) internal pure returns (int144 downcasted) {
                    downcasted = int144(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(144, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int136 from int256, reverting on
                 * overflow (when the input is less than smallest int136 or
                 * greater than largest int136).
                 *
                 * Counterpart to Solidity's `int136` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 136 bits
                 */
                function toInt136(int256 value) internal pure returns (int136 downcasted) {
                    downcasted = int136(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(136, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int128 from int256, reverting on
                 * overflow (when the input is less than smallest int128 or
                 * greater than largest int128).
                 *
                 * Counterpart to Solidity's `int128` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 128 bits
                 */
                function toInt128(int256 value) internal pure returns (int128 downcasted) {
                    downcasted = int128(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(128, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int120 from int256, reverting on
                 * overflow (when the input is less than smallest int120 or
                 * greater than largest int120).
                 *
                 * Counterpart to Solidity's `int120` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 120 bits
                 */
                function toInt120(int256 value) internal pure returns (int120 downcasted) {
                    downcasted = int120(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(120, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int112 from int256, reverting on
                 * overflow (when the input is less than smallest int112 or
                 * greater than largest int112).
                 *
                 * Counterpart to Solidity's `int112` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 112 bits
                 */
                function toInt112(int256 value) internal pure returns (int112 downcasted) {
                    downcasted = int112(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(112, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int104 from int256, reverting on
                 * overflow (when the input is less than smallest int104 or
                 * greater than largest int104).
                 *
                 * Counterpart to Solidity's `int104` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 104 bits
                 */
                function toInt104(int256 value) internal pure returns (int104 downcasted) {
                    downcasted = int104(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(104, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int96 from int256, reverting on
                 * overflow (when the input is less than smallest int96 or
                 * greater than largest int96).
                 *
                 * Counterpart to Solidity's `int96` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 96 bits
                 */
                function toInt96(int256 value) internal pure returns (int96 downcasted) {
                    downcasted = int96(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(96, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int88 from int256, reverting on
                 * overflow (when the input is less than smallest int88 or
                 * greater than largest int88).
                 *
                 * Counterpart to Solidity's `int88` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 88 bits
                 */
                function toInt88(int256 value) internal pure returns (int88 downcasted) {
                    downcasted = int88(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(88, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int80 from int256, reverting on
                 * overflow (when the input is less than smallest int80 or
                 * greater than largest int80).
                 *
                 * Counterpart to Solidity's `int80` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 80 bits
                 */
                function toInt80(int256 value) internal pure returns (int80 downcasted) {
                    downcasted = int80(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(80, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int72 from int256, reverting on
                 * overflow (when the input is less than smallest int72 or
                 * greater than largest int72).
                 *
                 * Counterpart to Solidity's `int72` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 72 bits
                 */
                function toInt72(int256 value) internal pure returns (int72 downcasted) {
                    downcasted = int72(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(72, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int64 from int256, reverting on
                 * overflow (when the input is less than smallest int64 or
                 * greater than largest int64).
                 *
                 * Counterpart to Solidity's `int64` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 64 bits
                 */
                function toInt64(int256 value) internal pure returns (int64 downcasted) {
                    downcasted = int64(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(64, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int56 from int256, reverting on
                 * overflow (when the input is less than smallest int56 or
                 * greater than largest int56).
                 *
                 * Counterpart to Solidity's `int56` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 56 bits
                 */
                function toInt56(int256 value) internal pure returns (int56 downcasted) {
                    downcasted = int56(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(56, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int48 from int256, reverting on
                 * overflow (when the input is less than smallest int48 or
                 * greater than largest int48).
                 *
                 * Counterpart to Solidity's `int48` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 48 bits
                 */
                function toInt48(int256 value) internal pure returns (int48 downcasted) {
                    downcasted = int48(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(48, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int40 from int256, reverting on
                 * overflow (when the input is less than smallest int40 or
                 * greater than largest int40).
                 *
                 * Counterpart to Solidity's `int40` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 40 bits
                 */
                function toInt40(int256 value) internal pure returns (int40 downcasted) {
                    downcasted = int40(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(40, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int32 from int256, reverting on
                 * overflow (when the input is less than smallest int32 or
                 * greater than largest int32).
                 *
                 * Counterpart to Solidity's `int32` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 32 bits
                 */
                function toInt32(int256 value) internal pure returns (int32 downcasted) {
                    downcasted = int32(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(32, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int24 from int256, reverting on
                 * overflow (when the input is less than smallest int24 or
                 * greater than largest int24).
                 *
                 * Counterpart to Solidity's `int24` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 24 bits
                 */
                function toInt24(int256 value) internal pure returns (int24 downcasted) {
                    downcasted = int24(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(24, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int16 from int256, reverting on
                 * overflow (when the input is less than smallest int16 or
                 * greater than largest int16).
                 *
                 * Counterpart to Solidity's `int16` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 16 bits
                 */
                function toInt16(int256 value) internal pure returns (int16 downcasted) {
                    downcasted = int16(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(16, value);
                    }
                }
                /**
                 * @dev Returns the downcasted int8 from int256, reverting on
                 * overflow (when the input is less than smallest int8 or
                 * greater than largest int8).
                 *
                 * Counterpart to Solidity's `int8` operator.
                 *
                 * Requirements:
                 *
                 * - input must fit into 8 bits
                 */
                function toInt8(int256 value) internal pure returns (int8 downcasted) {
                    downcasted = int8(value);
                    if (downcasted != value) {
                        revert SafeCastOverflowedIntDowncast(8, value);
                    }
                }
                /**
                 * @dev Converts an unsigned uint256 into a signed int256.
                 *
                 * Requirements:
                 *
                 * - input must be less than or equal to maxInt256.
                 */
                function toInt256(uint256 value) internal pure returns (int256) {
                    // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
                    if (value > uint256(type(int256).max)) {
                        revert SafeCastOverflowedUintToInt(value);
                    }
                    return int256(value);
                }
                /**
                 * @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
                 */
                function toUint(bool b) internal pure returns (uint256 u) {
                    assembly ("memory-safe") {
                        u := iszero(iszero(b))
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SignedMath.sol)
            pragma solidity ^0.8.20;
            import {SafeCast} from "./SafeCast.sol";
            /**
             * @dev Standard signed math utilities missing in the Solidity language.
             */
            library SignedMath {
                /**
                 * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
                 *
                 * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
                 * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
                 * one branch when needed, making this function more expensive.
                 */
                function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) {
                    unchecked {
                        // branchless ternary works because:
                        // b ^ (a ^ b) == a
                        // b ^ 0 == b
                        return b ^ ((a ^ b) * int256(SafeCast.toUint(condition)));
                    }
                }
                /**
                 * @dev Returns the largest of two signed numbers.
                 */
                function max(int256 a, int256 b) internal pure returns (int256) {
                    return ternary(a > b, a, b);
                }
                /**
                 * @dev Returns the smallest of two signed numbers.
                 */
                function min(int256 a, int256 b) internal pure returns (int256) {
                    return ternary(a < b, a, b);
                }
                /**
                 * @dev Returns the average of two signed numbers without overflow.
                 * The result is rounded towards zero.
                 */
                function average(int256 a, int256 b) internal pure returns (int256) {
                    // Formula from the book "Hacker's Delight"
                    int256 x = (a & b) + ((a ^ b) >> 1);
                    return x + (int256(uint256(x) >> 255) & (a ^ b));
                }
                /**
                 * @dev Returns the absolute unsigned value of a signed value.
                 */
                function abs(int256 n) internal pure returns (uint256) {
                    unchecked {
                        // Formula from the "Bit Twiddling Hacks" by Sean Eron Anderson.
                        // Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,
                        // taking advantage of the most significant (or "sign" bit) in two's complement representation.
                        // This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,
                        // the mask will either be `bytes32(0)` (if n is positive) or `~bytes32(0)` (if n is negative).
                        int256 mask = n >> 255;
                        // A `bytes32(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.
                        return uint256((n + mask) ^ mask);
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)
            pragma solidity ^0.8.20;
            /**
             * @dev Helper library for emitting standardized panic codes.
             *
             * ```solidity
             * contract Example {
             *      using Panic for uint256;
             *
             *      // Use any of the declared internal constants
             *      function foo() { Panic.GENERIC.panic(); }
             *
             *      // Alternatively
             *      function foo() { Panic.panic(Panic.GENERIC); }
             * }
             * ```
             *
             * Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
             *
             * _Available since v5.1._
             */
            // slither-disable-next-line unused-state
            library Panic {
                /// @dev generic / unspecified error
                uint256 internal constant GENERIC = 0x00;
                /// @dev used by the assert() builtin
                uint256 internal constant ASSERT = 0x01;
                /// @dev arithmetic underflow or overflow
                uint256 internal constant UNDER_OVERFLOW = 0x11;
                /// @dev division or modulo by zero
                uint256 internal constant DIVISION_BY_ZERO = 0x12;
                /// @dev enum conversion error
                uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
                /// @dev invalid encoding in storage
                uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
                /// @dev empty array pop
                uint256 internal constant EMPTY_ARRAY_POP = 0x31;
                /// @dev array out of bounds access
                uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
                /// @dev resource error (too large allocation or too large array)
                uint256 internal constant RESOURCE_ERROR = 0x41;
                /// @dev calling invalid internal function
                uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;
                /// @dev Reverts with a panic code. Recommended to use with
                /// the internal constants with predefined codes.
                function panic(uint256 code) internal pure {
                    assembly ("memory-safe") {
                        mstore(0x00, 0x4e487b71)
                        mstore(0x20, code)
                        revert(0x1c, 0x24)
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuardTransient.sol)
            pragma solidity ^0.8.24;
            import {TransientSlot} from "./TransientSlot.sol";
            /**
             * @dev Variant of {ReentrancyGuard} that uses transient storage.
             *
             * NOTE: This variant only works on networks where EIP-1153 is available.
             *
             * _Available since v5.1._
             */
            abstract contract ReentrancyGuardTransient {
                using TransientSlot for *;
                // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
                bytes32 private constant REENTRANCY_GUARD_STORAGE =
                    0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;
                /**
                 * @dev Unauthorized reentrant call.
                 */
                error ReentrancyGuardReentrantCall();
                /**
                 * @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
                    if (_reentrancyGuardEntered()) {
                        revert ReentrancyGuardReentrantCall();
                    }
                    // Any calls to nonReentrant after this point will fail
                    REENTRANCY_GUARD_STORAGE.asBoolean().tstore(true);
                }
                function _nonReentrantAfter() private {
                    REENTRANCY_GUARD_STORAGE.asBoolean().tstore(false);
                }
                /**
                 * @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 REENTRANCY_GUARD_STORAGE.asBoolean().tload();
                }
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.1.0) (utils/ShortStrings.sol)
            pragma solidity ^0.8.20;
            import {StorageSlot} from "./StorageSlot.sol";
            // | string  | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA   |
            // | length  | 0x                                                              BB |
            type ShortString is bytes32;
            /**
             * @dev This library provides functions to convert short memory strings
             * into a `ShortString` type that can be used as an immutable variable.
             *
             * Strings of arbitrary length can be optimized using this library if
             * they are short enough (up to 31 bytes) by packing them with their
             * length (1 byte) in a single EVM word (32 bytes). Additionally, a
             * fallback mechanism can be used for every other case.
             *
             * Usage example:
             *
             * ```solidity
             * contract Named {
             *     using ShortStrings for *;
             *
             *     ShortString private immutable _name;
             *     string private _nameFallback;
             *
             *     constructor(string memory contractName) {
             *         _name = contractName.toShortStringWithFallback(_nameFallback);
             *     }
             *
             *     function name() external view returns (string memory) {
             *         return _name.toStringWithFallback(_nameFallback);
             *     }
             * }
             * ```
             */
            library ShortStrings {
                // Used as an identifier for strings longer than 31 bytes.
                bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;
                error StringTooLong(string str);
                error InvalidShortString();
                /**
                 * @dev Encode a string of at most 31 chars into a `ShortString`.
                 *
                 * This will trigger a `StringTooLong` error is the input string is too long.
                 */
                function toShortString(string memory str) internal pure returns (ShortString) {
                    bytes memory bstr = bytes(str);
                    if (bstr.length > 31) {
                        revert StringTooLong(str);
                    }
                    return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));
                }
                /**
                 * @dev Decode a `ShortString` back to a "normal" string.
                 */
                function toString(ShortString sstr) internal pure returns (string memory) {
                    uint256 len = byteLength(sstr);
                    // using `new string(len)` would work locally but is not memory safe.
                    string memory str = new string(32);
                    assembly ("memory-safe") {
                        mstore(str, len)
                        mstore(add(str, 0x20), sstr)
                    }
                    return str;
                }
                /**
                 * @dev Return the length of a `ShortString`.
                 */
                function byteLength(ShortString sstr) internal pure returns (uint256) {
                    uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;
                    if (result > 31) {
                        revert InvalidShortString();
                    }
                    return result;
                }
                /**
                 * @dev Encode a string into a `ShortString`, or write it to storage if it is too long.
                 */
                function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {
                    if (bytes(value).length < 32) {
                        return toShortString(value);
                    } else {
                        StorageSlot.getStringSlot(store).value = value;
                        return ShortString.wrap(FALLBACK_SENTINEL);
                    }
                }
                /**
                 * @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
                 */
                function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {
                    if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
                        return toString(value);
                    } else {
                        return store;
                    }
                }
                /**
                 * @dev Return the length of a string that was encoded to `ShortString` or written to storage using
                 * {setWithFallback}.
                 *
                 * WARNING: This will return the "byte length" of the string. This may not reflect the actual length in terms of
                 * actual characters as the UTF-8 encoding of a single character can span over multiple bytes.
                 */
                function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {
                    if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
                        return byteLength(value);
                    } else {
                        return bytes(store).length;
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)
            // This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
            pragma solidity ^0.8.20;
            /**
             * @dev Library for reading and writing primitive types to specific storage slots.
             *
             * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
             * This library helps with reading and writing to such slots without the need for inline assembly.
             *
             * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
             *
             * Example usage to set ERC-1967 implementation slot:
             * ```solidity
             * contract ERC1967 {
             *     // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
             *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
             *
             *     function _getImplementation() internal view returns (address) {
             *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
             *     }
             *
             *     function _setImplementation(address newImplementation) internal {
             *         require(newImplementation.code.length > 0);
             *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
             *     }
             * }
             * ```
             *
             * TIP: Consider using this library along with {SlotDerivation}.
             */
            library StorageSlot {
                struct AddressSlot {
                    address value;
                }
                struct BooleanSlot {
                    bool value;
                }
                struct Bytes32Slot {
                    bytes32 value;
                }
                struct Uint256Slot {
                    uint256 value;
                }
                struct Int256Slot {
                    int256 value;
                }
                struct StringSlot {
                    string value;
                }
                struct BytesSlot {
                    bytes value;
                }
                /**
                 * @dev Returns an `AddressSlot` with member `value` located at `slot`.
                 */
                function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
                    assembly ("memory-safe") {
                        r.slot := slot
                    }
                }
                /**
                 * @dev Returns a `BooleanSlot` with member `value` located at `slot`.
                 */
                function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
                    assembly ("memory-safe") {
                        r.slot := slot
                    }
                }
                /**
                 * @dev Returns a `Bytes32Slot` with member `value` located at `slot`.
                 */
                function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
                    assembly ("memory-safe") {
                        r.slot := slot
                    }
                }
                /**
                 * @dev Returns a `Uint256Slot` with member `value` located at `slot`.
                 */
                function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
                    assembly ("memory-safe") {
                        r.slot := slot
                    }
                }
                /**
                 * @dev Returns a `Int256Slot` with member `value` located at `slot`.
                 */
                function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
                    assembly ("memory-safe") {
                        r.slot := slot
                    }
                }
                /**
                 * @dev Returns a `StringSlot` with member `value` located at `slot`.
                 */
                function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
                    assembly ("memory-safe") {
                        r.slot := slot
                    }
                }
                /**
                 * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
                 */
                function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
                    assembly ("memory-safe") {
                        r.slot := store.slot
                    }
                }
                /**
                 * @dev Returns a `BytesSlot` with member `value` located at `slot`.
                 */
                function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
                    assembly ("memory-safe") {
                        r.slot := slot
                    }
                }
                /**
                 * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
                 */
                function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
                    assembly ("memory-safe") {
                        r.slot := store.slot
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.1.0) (utils/Strings.sol)
            pragma solidity ^0.8.20;
            import {Math} from "./math/Math.sol";
            import {SignedMath} from "./math/SignedMath.sol";
            /**
             * @dev String operations.
             */
            library Strings {
                bytes16 private constant HEX_DIGITS = "0123456789abcdef";
                uint8 private constant ADDRESS_LENGTH = 20;
                /**
                 * @dev The `value` string doesn't fit in the specified `length`.
                 */
                error StringsInsufficientHexLength(uint256 value, uint256 length);
                /**
                 * @dev Converts a `uint256` to its ASCII `string` decimal representation.
                 */
                function toString(uint256 value) internal pure returns (string memory) {
                    unchecked {
                        uint256 length = Math.log10(value) + 1;
                        string memory buffer = new string(length);
                        uint256 ptr;
                        assembly ("memory-safe") {
                            ptr := add(buffer, add(32, length))
                        }
                        while (true) {
                            ptr--;
                            assembly ("memory-safe") {
                                mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
                            }
                            value /= 10;
                            if (value == 0) break;
                        }
                        return buffer;
                    }
                }
                /**
                 * @dev Converts a `int256` to its ASCII `string` decimal representation.
                 */
                function toStringSigned(int256 value) internal pure returns (string memory) {
                    return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
                }
                /**
                 * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
                 */
                function toHexString(uint256 value) internal pure returns (string memory) {
                    unchecked {
                        return toHexString(value, Math.log256(value) + 1);
                    }
                }
                /**
                 * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
                 */
                function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
                    uint256 localValue = value;
                    bytes memory buffer = new bytes(2 * length + 2);
                    buffer[0] = "0";
                    buffer[1] = "x";
                    for (uint256 i = 2 * length + 1; i > 1; --i) {
                        buffer[i] = HEX_DIGITS[localValue & 0xf];
                        localValue >>= 4;
                    }
                    if (localValue != 0) {
                        revert StringsInsufficientHexLength(value, length);
                    }
                    return string(buffer);
                }
                /**
                 * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
                 * representation.
                 */
                function toHexString(address addr) internal pure returns (string memory) {
                    return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
                }
                /**
                 * @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal
                 * representation, according to EIP-55.
                 */
                function toChecksumHexString(address addr) internal pure returns (string memory) {
                    bytes memory buffer = bytes(toHexString(addr));
                    // hash the hex part of buffer (skip length + 2 bytes, length 40)
                    uint256 hashValue;
                    assembly ("memory-safe") {
                        hashValue := shr(96, keccak256(add(buffer, 0x22), 40))
                    }
                    for (uint256 i = 41; i > 1; --i) {
                        // possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)
                        if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {
                            // case shift by xoring with 0x20
                            buffer[i] ^= 0x20;
                        }
                        hashValue >>= 4;
                    }
                    return string(buffer);
                }
                /**
                 * @dev Returns true if the two strings are equal.
                 */
                function equal(string memory a, string memory b) internal pure returns (bool) {
                    return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
                }
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.1.0) (utils/TransientSlot.sol)
            // This file was procedurally generated from scripts/generate/templates/TransientSlot.js.
            pragma solidity ^0.8.24;
            /**
             * @dev Library for reading and writing value-types to specific transient storage slots.
             *
             * Transient slots are often used to store temporary values that are removed after the current transaction.
             * This library helps with reading and writing to such slots without the need for inline assembly.
             *
             *  * Example reading and writing values using transient storage:
             * ```solidity
             * contract Lock {
             *     using TransientSlot for *;
             *
             *     // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
             *     bytes32 internal constant _LOCK_SLOT = 0xf4678858b2b588224636b8522b729e7722d32fc491da849ed75b3fdf3c84f542;
             *
             *     modifier locked() {
             *         require(!_LOCK_SLOT.asBoolean().tload());
             *
             *         _LOCK_SLOT.asBoolean().tstore(true);
             *         _;
             *         _LOCK_SLOT.asBoolean().tstore(false);
             *     }
             * }
             * ```
             *
             * TIP: Consider using this library along with {SlotDerivation}.
             */
            library TransientSlot {
                /**
                 * @dev UDVT that represent a slot holding a address.
                 */
                type AddressSlot is bytes32;
                /**
                 * @dev Cast an arbitrary slot to a AddressSlot.
                 */
                function asAddress(bytes32 slot) internal pure returns (AddressSlot) {
                    return AddressSlot.wrap(slot);
                }
                /**
                 * @dev UDVT that represent a slot holding a bool.
                 */
                type BooleanSlot is bytes32;
                /**
                 * @dev Cast an arbitrary slot to a BooleanSlot.
                 */
                function asBoolean(bytes32 slot) internal pure returns (BooleanSlot) {
                    return BooleanSlot.wrap(slot);
                }
                /**
                 * @dev UDVT that represent a slot holding a bytes32.
                 */
                type Bytes32Slot is bytes32;
                /**
                 * @dev Cast an arbitrary slot to a Bytes32Slot.
                 */
                function asBytes32(bytes32 slot) internal pure returns (Bytes32Slot) {
                    return Bytes32Slot.wrap(slot);
                }
                /**
                 * @dev UDVT that represent a slot holding a uint256.
                 */
                type Uint256Slot is bytes32;
                /**
                 * @dev Cast an arbitrary slot to a Uint256Slot.
                 */
                function asUint256(bytes32 slot) internal pure returns (Uint256Slot) {
                    return Uint256Slot.wrap(slot);
                }
                /**
                 * @dev UDVT that represent a slot holding a int256.
                 */
                type Int256Slot is bytes32;
                /**
                 * @dev Cast an arbitrary slot to a Int256Slot.
                 */
                function asInt256(bytes32 slot) internal pure returns (Int256Slot) {
                    return Int256Slot.wrap(slot);
                }
                /**
                 * @dev Load the value held at location `slot` in transient storage.
                 */
                function tload(AddressSlot slot) internal view returns (address value) {
                    assembly ("memory-safe") {
                        value := tload(slot)
                    }
                }
                /**
                 * @dev Store `value` at location `slot` in transient storage.
                 */
                function tstore(AddressSlot slot, address value) internal {
                    assembly ("memory-safe") {
                        tstore(slot, value)
                    }
                }
                /**
                 * @dev Load the value held at location `slot` in transient storage.
                 */
                function tload(BooleanSlot slot) internal view returns (bool value) {
                    assembly ("memory-safe") {
                        value := tload(slot)
                    }
                }
                /**
                 * @dev Store `value` at location `slot` in transient storage.
                 */
                function tstore(BooleanSlot slot, bool value) internal {
                    assembly ("memory-safe") {
                        tstore(slot, value)
                    }
                }
                /**
                 * @dev Load the value held at location `slot` in transient storage.
                 */
                function tload(Bytes32Slot slot) internal view returns (bytes32 value) {
                    assembly ("memory-safe") {
                        value := tload(slot)
                    }
                }
                /**
                 * @dev Store `value` at location `slot` in transient storage.
                 */
                function tstore(Bytes32Slot slot, bytes32 value) internal {
                    assembly ("memory-safe") {
                        tstore(slot, value)
                    }
                }
                /**
                 * @dev Load the value held at location `slot` in transient storage.
                 */
                function tload(Uint256Slot slot) internal view returns (uint256 value) {
                    assembly ("memory-safe") {
                        value := tload(slot)
                    }
                }
                /**
                 * @dev Store `value` at location `slot` in transient storage.
                 */
                function tstore(Uint256Slot slot, uint256 value) internal {
                    assembly ("memory-safe") {
                        tstore(slot, value)
                    }
                }
                /**
                 * @dev Load the value held at location `slot` in transient storage.
                 */
                function tload(Int256Slot slot) internal view returns (int256 value) {
                    assembly ("memory-safe") {
                        value := tload(slot)
                    }
                }
                /**
                 * @dev Store `value` at location `slot` in transient storage.
                 */
                function tstore(Int256Slot slot, int256 value) internal {
                    assembly ("memory-safe") {
                        tstore(slot, value)
                    }
                }
            }
            pragma solidity ^0.8.28;
            // SPDX-License-Identifier: MIT
            // solhint-disable no-inline-assembly
            import "../interfaces/PackedUserOperation.sol";
            import "../core/UserOperationLib.sol";
            library Eip7702Support {
                // EIP-7702 code prefix before delegate address.
                bytes3 internal constant EIP7702_PREFIX = 0xef0100;
                // EIP-7702 initCode marker, to specify this account is EIP-7702.
                bytes2 internal constant INITCODE_EIP7702_MARKER = 0x7702;
                using UserOperationLib for PackedUserOperation;
                /**
                 * Get the alternative 'InitCodeHash' value for the UserOp hash calculation when using EIP-7702.
                 *
                 * @param userOp - the UserOperation to for the 'InitCodeHash' calculation.
                 * @return the 'InitCodeHash' value.
                 */
                function _getEip7702InitCodeHashOverride(PackedUserOperation calldata userOp) internal view returns (bytes32) {
                    bytes calldata initCode = userOp.initCode;
                    if (!_isEip7702InitCode(initCode)) {
                        return 0;
                    }
                    address delegate = _getEip7702Delegate(userOp.sender);
                    if (initCode.length <= 20)
                        return keccak256(abi.encodePacked(delegate));
                    else
                        return keccak256(abi.encodePacked(delegate, initCode[20 :]));
                }
                /**
                 * Check if this 'initCode' is actually an EIP-7702 authorization.
                 * This is indicated by 'initCode' that starts with INITCODE_EIP7702_MARKER.
                 *
                 * @param initCode - the 'initCode' to check.
                 * @return true if the 'initCode' is EIP-7702 authorization, false otherwise.
                 */
                function _isEip7702InitCode(bytes calldata initCode) internal pure returns (bool) {
                    if (initCode.length < 2) {
                        return false;
                    }
                    bytes20 initCodeStart;
                    // non-empty calldata bytes are always zero-padded to 32-bytes, so can be safely casted to "bytes20"
                    assembly ("memory-safe") {
                        initCodeStart := calldataload(initCode.offset)
                    }
                    // make sure first 20 bytes of initCode are "0x7702" (padded with zeros)
                    return initCodeStart == bytes20(INITCODE_EIP7702_MARKER);
                }
                /**
                 * Get the EIP-7702 delegate from contract code.
                 * Must only be used if _isEip7702InitCode(initCode) is true.
                 *
                 * @param sender - the EIP-7702 'sender' account to get the delegated contract code address.
                 * @return the address of the EIP-7702 authorized contract.
                 */
                function _getEip7702Delegate(address sender) internal view returns (address) {
                    bytes32 senderCode;
                    assembly ("memory-safe") {
                        extcodecopy(sender, 0, 0, 23)
                        senderCode := mload(0)
                    }
                    // To be a valid EIP-7702 delegate, the first 3 bytes are EIP7702_PREFIX
                    // followed by the delegate address
                    if (bytes3(senderCode) != EIP7702_PREFIX) {
                        // instead of just "not an EIP-7702 delegate", if some info.
                        require(sender.code.length > 0, "sender has no code");
                        revert("not an EIP-7702 delegate");
                    }
                    return address(bytes20(senderCode << 24));
                }
            }
            // SPDX-License-Identifier: GPL-3.0
            pragma solidity ^0.8.28;
            /* solhint-disable avoid-low-level-calls */
            /* solhint-disable no-inline-assembly */
            import "../interfaces/IAccount.sol";
            import "../interfaces/IAccountExecute.sol";
            import "../interfaces/IEntryPoint.sol";
            import "../interfaces/IPaymaster.sol";
            import "./UserOperationLib.sol";
            import "./StakeManager.sol";
            import "./NonceManager.sol";
            import "./Helpers.sol";
            import "./SenderCreator.sol";
            import "./Eip7702Support.sol";
            import "../utils/Exec.sol";
            import "@openzeppelin/contracts/utils/ReentrancyGuardTransient.sol";
            import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
            import "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
            /**
             * Account-Abstraction (EIP-4337) singleton EntryPoint v0.8 implementation.
             * Only one instance required on each chain.
             * @custom:security-contact https://bounty.ethereum.org
             */
            contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuardTransient, ERC165, EIP712 {
                using UserOperationLib for PackedUserOperation;
                /**
                 * internal-use constants
                 */
                // allow some slack for future gas price changes.
                uint256 private constant INNER_GAS_OVERHEAD = 10000;
                // Marker for inner call revert on out of gas
                bytes32 private constant INNER_OUT_OF_GAS = hex"deaddead";
                bytes32 private constant INNER_REVERT_LOW_PREFUND = hex"deadaa51";
                uint256 private constant REVERT_REASON_MAX_LEN = 2048;
                // Penalty charged for either unused execution gas or postOp gas
                uint256 private constant UNUSED_GAS_PENALTY_PERCENT = 10;
                // Threshold below which no penalty would be charged
                uint256 private constant PENALTY_GAS_THRESHOLD = 40000;
                SenderCreator private immutable _senderCreator = new SenderCreator();
                string constant internal DOMAIN_NAME = "ERC4337";
                string constant internal DOMAIN_VERSION = "1";
                constructor() EIP712(DOMAIN_NAME, DOMAIN_VERSION)  {
                }
                /// @inheritdoc IEntryPoint
                function handleOps(
                    PackedUserOperation[] calldata ops,
                    address payable beneficiary
                ) external nonReentrant {
                    uint256 opslen = ops.length;
                    UserOpInfo[] memory opInfos = new UserOpInfo[](opslen);
                    unchecked {
                        _iterateValidationPhase(ops, opInfos, address(0), 0);
                        uint256 collected = 0;
                        emit BeforeExecution();
                        for (uint256 i = 0; i < opslen; i++) {
                            collected += _executeUserOp(i, ops[i], opInfos[i]);
                        }
                        _compensate(beneficiary, collected);
                    }
                }
                /// @inheritdoc IEntryPoint
                function handleAggregatedOps(
                    UserOpsPerAggregator[] calldata opsPerAggregator,
                    address payable beneficiary
                ) external nonReentrant {
                    unchecked {
                        uint256 opasLen = opsPerAggregator.length;
                        uint256 totalOps = 0;
                        for (uint256 i = 0; i < opasLen; i++) {
                            UserOpsPerAggregator calldata opa = opsPerAggregator[i];
                            PackedUserOperation[] calldata ops = opa.userOps;
                            IAggregator aggregator = opa.aggregator;
                            // address(1) is special marker of "signature error"
                            require(
                                address(aggregator) != address(1),
                                SignatureValidationFailed(address(aggregator))
                            );
                            if (address(aggregator) != address(0)) {
                                // solhint-disable-next-line no-empty-blocks
                                try aggregator.validateSignatures(ops, opa.signature) {} catch {
                                    revert SignatureValidationFailed(address(aggregator));
                                }
                            }
                            totalOps += ops.length;
                        }
                        UserOpInfo[] memory opInfos = new UserOpInfo[](totalOps);
                        uint256 opIndex = 0;
                        for (uint256 a = 0; a < opasLen; a++) {
                            UserOpsPerAggregator calldata opa = opsPerAggregator[a];
                            PackedUserOperation[] calldata ops = opa.userOps;
                            IAggregator aggregator = opa.aggregator;
                            opIndex += _iterateValidationPhase(ops, opInfos, address(aggregator), opIndex);
                        }
                        emit BeforeExecution();
                        uint256 collected = 0;
                        opIndex = 0;
                        for (uint256 a = 0; a < opasLen; a++) {
                            UserOpsPerAggregator calldata opa = opsPerAggregator[a];
                            emit SignatureAggregatorChanged(address(opa.aggregator));
                            PackedUserOperation[] calldata ops = opa.userOps;
                            uint256 opslen = ops.length;
                            for (uint256 i = 0; i < opslen; i++) {
                                collected += _executeUserOp(opIndex, ops[i], opInfos[opIndex]);
                                opIndex++;
                            }
                        }
                        _compensate(beneficiary, collected);
                    }
                }
                /// @inheritdoc IEntryPoint
                function getUserOpHash(
                    PackedUserOperation calldata userOp
                ) public view returns (bytes32) {
                    bytes32 overrideInitCodeHash = Eip7702Support._getEip7702InitCodeHashOverride(userOp);
                    return
                        MessageHashUtils.toTypedDataHash(getDomainSeparatorV4(), userOp.hash(overrideInitCodeHash));
                }
                /// @inheritdoc IEntryPoint
                function getSenderAddress(bytes calldata initCode) external {
                    address sender = senderCreator().createSender(initCode);
                    revert SenderAddressResult(sender);
                }
                /// @inheritdoc IEntryPoint
                function senderCreator() public view virtual returns (ISenderCreator) {
                    return _senderCreator;
                }
                /// @inheritdoc IEntryPoint
                function delegateAndRevert(address target, bytes calldata data) external {
                    (bool success, bytes memory ret) = target.delegatecall(data);
                    revert DelegateAndRevert(success, ret);
                }
                function getPackedUserOpTypeHash() external pure returns (bytes32) {
                    return UserOperationLib.PACKED_USEROP_TYPEHASH;
                }
                function getDomainSeparatorV4() public virtual view returns (bytes32) {
                    return _domainSeparatorV4();
                }
                /// @inheritdoc IERC165
                function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
                    // note: solidity "type(IEntryPoint).interfaceId" is without inherited methods but we want to check everything
                    return interfaceId == (type(IEntryPoint).interfaceId ^ type(IStakeManager).interfaceId ^ type(INonceManager).interfaceId) ||
                    interfaceId == type(IEntryPoint).interfaceId ||
                    interfaceId == type(IStakeManager).interfaceId ||
                    interfaceId == type(INonceManager).interfaceId ||
                        super.supportsInterface(interfaceId);
                }
                /**
                 * Compensate the caller's beneficiary address with the collected fees of all UserOperations.
                 * @param beneficiary - The address to receive the fees.
                 * @param amount      - Amount to transfer.
                 */
                function _compensate(address payable beneficiary, uint256 amount) internal virtual {
                    require(beneficiary != address(0), "AA90 invalid beneficiary");
                    (bool success,) = beneficiary.call{value: amount}("");
                    require(success, "AA91 failed send to beneficiary");
                }
                /**
                 * Execute a user operation.
                 * @param opIndex    - Index into the opInfo array.
                 * @param userOp     - The userOp to execute.
                 * @param opInfo     - The opInfo filled by validatePrepayment for this userOp.
                 * @return collected - The total amount this userOp paid.
                 */
                function _executeUserOp(
                    uint256 opIndex,
                    PackedUserOperation calldata userOp,
                    UserOpInfo memory opInfo
                )
                internal virtual
                returns (uint256 collected) {
                    uint256 preGas = gasleft();
                    bytes memory context = _getMemoryBytesFromOffset(opInfo.contextOffset);
                    bool success;
                    {
                        uint256 saveFreePtr = _getFreePtr();
                        bytes calldata callData = userOp.callData;
                        bytes memory innerCall;
                        bytes4 methodSig;
                        assembly ("memory-safe") {
                            let len := callData.length
                            if gt(len, 3) {
                                methodSig := calldataload(callData.offset)
                            }
                        }
                        if (methodSig == IAccountExecute.executeUserOp.selector) {
                            bytes memory executeUserOp = abi.encodeCall(IAccountExecute.executeUserOp, (userOp, opInfo.userOpHash));
                            innerCall = abi.encodeCall(this.innerHandleOp, (executeUserOp, opInfo, context));
                        } else
                        {
                            innerCall = abi.encodeCall(this.innerHandleOp, (callData, opInfo, context));
                        }
                        assembly ("memory-safe") {
                            success := call(gas(), address(), 0, add(innerCall, 0x20), mload(innerCall), 0, 32)
                            collected := mload(0)
                        }
                        _restoreFreePtr(saveFreePtr);
                    }
                    if (!success) {
                        bytes32 innerRevertCode;
                        assembly ("memory-safe") {
                            let len := returndatasize()
                            if eq(32, len) {
                                returndatacopy(0, 0, 32)
                                innerRevertCode := mload(0)
                            }
                        }
                        if (innerRevertCode == INNER_OUT_OF_GAS) {
                            // handleOps was called with gas limit too low. abort entire bundle.
                            // can only be caused by bundler (leaving not enough gas for inner call)
                            revert FailedOp(opIndex, "AA95 out of gas");
                        } else if (innerRevertCode == INNER_REVERT_LOW_PREFUND) {
                            // innerCall reverted on prefund too low. treat entire prefund as "gas cost"
                            uint256 actualGas = preGas - gasleft() + opInfo.preOpGas;
                            uint256 actualGasCost = opInfo.prefund;
                            _emitPrefundTooLow(opInfo);
                            _emitUserOperationEvent(opInfo, false, actualGasCost, actualGas);
                            collected = actualGasCost;
                        } else {
                            uint256 freePtr = _getFreePtr();
                            emit PostOpRevertReason(
                                opInfo.userOpHash,
                                opInfo.mUserOp.sender,
                                opInfo.mUserOp.nonce,
                                Exec.getReturnData(REVERT_REASON_MAX_LEN)
                            );
                            _restoreFreePtr(freePtr);
                            uint256 actualGas = preGas - gasleft() + opInfo.preOpGas;
                            collected = _postExecution(
                                IPaymaster.PostOpMode.postOpReverted,
                                opInfo,
                                context,
                                actualGas
                            );
                        }
                    }
                }
                /**
                 * Emit the UserOperationEvent for the given UserOperation.
                 *
                 * @param opInfo         - The details of the current UserOperation.
                 * @param success        - Whether the execution of the UserOperation has succeeded or not.
                 * @param actualGasCost  - The actual cost of the consumed gas charged from the sender or the paymaster.
                 * @param actualGas      - The actual amount of gas used.
                 */
                function _emitUserOperationEvent(UserOpInfo memory opInfo, bool success, uint256 actualGasCost, uint256 actualGas) internal virtual {
                    emit UserOperationEvent(
                        opInfo.userOpHash,
                        opInfo.mUserOp.sender,
                        opInfo.mUserOp.paymaster,
                        opInfo.mUserOp.nonce,
                        success,
                        actualGasCost,
                        actualGas
                    );
                }
                /**
                 * Emit the UserOperationPrefundTooLow event for the given UserOperation.
                 *
                 * @param opInfo - The details of the current UserOperation.
                 */
                function _emitPrefundTooLow(UserOpInfo memory opInfo) internal virtual {
                    emit UserOperationPrefundTooLow(
                        opInfo.userOpHash,
                        opInfo.mUserOp.sender,
                        opInfo.mUserOp.nonce
                    );
                }
                /**
                 * Iterate over calldata PackedUserOperation array and perform account and paymaster validation.
                 * @notice UserOpInfo is a global array of all UserOps while PackedUserOperation is grouped per aggregator.
                 *
                 * @param ops - an array of UserOps to be validated
                 * @param opInfos - an array of UserOp metadata being read and filled in during this function's execution
                 * @param expectedAggregator - an address of the aggregator specified for a given UserOp if any, or address(0)
                 * @param opIndexOffset - an offset for the index between 'ops' and 'opInfos' arrays, see the notice.
                 * @return opsLen - processed UserOps (length of "ops" array)
                 */
                function _iterateValidationPhase(
                    PackedUserOperation[] calldata ops,
                    UserOpInfo[] memory opInfos,
                    address expectedAggregator,
                    uint256 opIndexOffset
                ) internal returns (uint256 opsLen){
                    unchecked {
                        opsLen = ops.length;
                        for (uint256 i = 0; i < opsLen; i++) {
                            UserOpInfo memory opInfo = opInfos[opIndexOffset + i];
                            (
                                uint256 validationData,
                                uint256 pmValidationData
                            ) = _validatePrepayment(opIndexOffset + i, ops[i], opInfo);
                            _validateAccountAndPaymasterValidationData(
                                opIndexOffset + i,
                                validationData,
                                pmValidationData,
                                expectedAggregator
                            );
                        }
                    }
                }
                /**
                 * A memory copy of UserOp static fields only.
                 * Excluding: callData, initCode and signature. Replacing paymasterAndData with paymaster.
                 */
                struct MemoryUserOp {
                    address sender;
                    uint256 nonce;
                    uint256 verificationGasLimit;
                    uint256 callGasLimit;
                    uint256 paymasterVerificationGasLimit;
                    uint256 paymasterPostOpGasLimit;
                    uint256 preVerificationGas;
                    address paymaster;
                    uint256 maxFeePerGas;
                    uint256 maxPriorityFeePerGas;
                }
                struct UserOpInfo {
                    MemoryUserOp mUserOp;
                    bytes32 userOpHash;
                    uint256 prefund;
                    uint256 contextOffset;
                    uint256 preOpGas;
                }
                /**
                 * Inner function to handle a UserOperation.
                 * Must be declared "external" to open a call context, but it can only be called by handleOps.
                 * @param callData - The callData to execute.
                 * @param opInfo   - The UserOpInfo struct.
                 * @param context  - The context bytes.
                 * @return actualGasCost - the actual cost in eth this UserOperation paid for gas
                 */
                function innerHandleOp(
                    bytes memory callData,
                    UserOpInfo memory opInfo,
                    bytes calldata context
                ) external returns (uint256 actualGasCost) {
                    uint256 preGas = gasleft();
                    require(msg.sender == address(this), "AA92 internal call only");
                    MemoryUserOp memory mUserOp = opInfo.mUserOp;
                    uint256 callGasLimit = mUserOp.callGasLimit;
                    unchecked {
                    // handleOps was called with gas limit too low. abort entire bundle.
                        if (
                            gasleft() * 63 / 64 <
                            callGasLimit +
                            mUserOp.paymasterPostOpGasLimit +
                            INNER_GAS_OVERHEAD
                        ) {
                            assembly ("memory-safe") {
                                mstore(0, INNER_OUT_OF_GAS)
                                revert(0, 32)
                            }
                        }
                    }
                    IPaymaster.PostOpMode mode = IPaymaster.PostOpMode.opSucceeded;
                    if (callData.length > 0) {
                        bool success = Exec.call(mUserOp.sender, 0, callData, callGasLimit);
                        if (!success) {
                            uint256 freePtr = _getFreePtr();
                            bytes memory result = Exec.getReturnData(REVERT_REASON_MAX_LEN);
                            if (result.length > 0) {
                                emit UserOperationRevertReason(
                                    opInfo.userOpHash,
                                    mUserOp.sender,
                                    mUserOp.nonce,
                                    result
                                );
                            }
                            _restoreFreePtr(freePtr);
                            mode = IPaymaster.PostOpMode.opReverted;
                        }
                    }
                    unchecked {
                        uint256 actualGas = preGas - gasleft() + opInfo.preOpGas;
                        return _postExecution(mode, opInfo, context, actualGas);
                    }
                }
                /**
                 * Copy general fields from userOp into the memory opInfo structure.
                 * @param userOp  - The user operation.
                 * @param mUserOp - The memory user operation.
                 */
                function _copyUserOpToMemory(
                    PackedUserOperation calldata userOp,
                    MemoryUserOp memory mUserOp
                ) internal virtual pure {
                    mUserOp.sender = userOp.sender;
                    mUserOp.nonce = userOp.nonce;
                    (mUserOp.verificationGasLimit, mUserOp.callGasLimit) = UserOperationLib.unpackUints(userOp.accountGasLimits);
                    mUserOp.preVerificationGas = userOp.preVerificationGas;
                    (mUserOp.maxPriorityFeePerGas, mUserOp.maxFeePerGas) = UserOperationLib.unpackUints(userOp.gasFees);
                    bytes calldata paymasterAndData = userOp.paymasterAndData;
                    if (paymasterAndData.length > 0) {
                        require(
                            paymasterAndData.length >= UserOperationLib.PAYMASTER_DATA_OFFSET,
                            "AA93 invalid paymasterAndData"
                        );
                        address paymaster;
                        (paymaster, mUserOp.paymasterVerificationGasLimit, mUserOp.paymasterPostOpGasLimit) = UserOperationLib.unpackPaymasterStaticFields(paymasterAndData);
                        require(paymaster != address(0), "AA98 invalid paymaster");
                        mUserOp.paymaster = paymaster;
                    }
                }
                /**
                 * Get the required prefunded gas fee amount for an operation.
                 *
                 * @param mUserOp - The user operation in memory.
                 * @return requiredPrefund - the required amount.
                 */
                function _getRequiredPrefund(
                    MemoryUserOp memory mUserOp
                ) internal virtual pure returns (uint256 requiredPrefund) {
                    unchecked {
                        uint256 requiredGas = mUserOp.verificationGasLimit +
                                        mUserOp.callGasLimit +
                                        mUserOp.paymasterVerificationGasLimit +
                                        mUserOp.paymasterPostOpGasLimit +
                                        mUserOp.preVerificationGas;
                        requiredPrefund = requiredGas * mUserOp.maxFeePerGas;
                    }
                }
                /**
                 * Create sender smart contract account if init code is provided.
                 * @param opIndex  - The operation index.
                 * @param opInfo   - The operation info.
                 * @param initCode - The init code for the smart contract account.
                 */
                function _createSenderIfNeeded(
                    uint256 opIndex,
                    UserOpInfo memory opInfo,
                    bytes calldata initCode
                ) internal virtual {
                    if (initCode.length != 0) {
                        address sender = opInfo.mUserOp.sender;
                        if (Eip7702Support._isEip7702InitCode(initCode)) {
                            if (initCode.length > 20) {
                                // Already validated it is an EIP-7702 delegate (and hence, already has code) - see getUserOpHash()
                                // Note: Can be called multiple times as long as an appropriate initCode is supplied
                                senderCreator().initEip7702Sender{
                                        gas: opInfo.mUserOp.verificationGasLimit
                                    }(sender, initCode[20 :]);
                            }
                            return;
                        }
                        if (sender.code.length != 0)
                            revert FailedOp(opIndex, "AA10 sender already constructed");
                        if (initCode.length < 20) {
                            revert FailedOp(opIndex, "AA99 initCode too small");
                        }
                        address sender1 = senderCreator().createSender{
                                gas: opInfo.mUserOp.verificationGasLimit
                            }(initCode);
                        if (sender1 == address(0))
                            revert FailedOp(opIndex, "AA13 initCode failed or OOG");
                        if (sender1 != sender)
                            revert FailedOp(opIndex, "AA14 initCode must return sender");
                        if (sender1.code.length == 0)
                            revert FailedOp(opIndex, "AA15 initCode must create sender");
                        address factory = address(bytes20(initCode[0 : 20]));
                        emit AccountDeployed(
                            opInfo.userOpHash,
                            sender,
                            factory,
                            opInfo.mUserOp.paymaster
                        );
                    }
                }
                /**
                 * Call account.validateUserOp.
                 * Revert (with FailedOp) in case validateUserOp reverts, or account didn't send required prefund.
                 * Decrement account's deposit if needed.
                 * @param opIndex         - The operation index.
                 * @param op              - The user operation.
                 * @param opInfo          - The operation info.
                 * @param requiredPrefund - The required prefund amount.
                 * @return validationData - The account's validationData.
                 */
                function _validateAccountPrepayment(
                    uint256 opIndex,
                    PackedUserOperation calldata op,
                    UserOpInfo memory opInfo,
                    uint256 requiredPrefund
                )
                internal virtual
                returns (
                    uint256 validationData
                )
                {
                    unchecked {
                        MemoryUserOp memory mUserOp = opInfo.mUserOp;
                        address sender = mUserOp.sender;
                        _createSenderIfNeeded(opIndex, opInfo, op.initCode);
                        address paymaster = mUserOp.paymaster;
                        uint256 missingAccountFunds = 0;
                        if (paymaster == address(0)) {
                            uint256 bal = balanceOf(sender);
                            missingAccountFunds = bal > requiredPrefund
                                ? 0
                                : requiredPrefund - bal;
                        }
                        validationData = _callValidateUserOp(opIndex, op, opInfo, missingAccountFunds);
                        if (paymaster == address(0)) {
                            if (!_tryDecrementDeposit(sender, requiredPrefund)) {
                                revert FailedOp(opIndex, "AA21 didn't pay prefund");
                            }
                        }
                    }
                }
                /**
                 * Make a call to the sender.validateUserOp() function.
                 * Handle wrong output size by reverting with a FailedOp error.
                 *
                 * @param opIndex - index of the UserOperation in the bundle.
                 * @param op - the packed UserOperation object.
                 * @param opInfo - the in-memory UserOperation information.
                 * @param missingAccountFunds - the amount of deposit the account has to make to cover the UserOperation gas.
                 */
                function _callValidateUserOp(
                    uint256 opIndex,
                    PackedUserOperation calldata op,
                    UserOpInfo memory opInfo,
                    uint256 missingAccountFunds
                )
                internal virtual returns (uint256 validationData) {
                    uint256 gasLimit = opInfo.mUserOp.verificationGasLimit;
                    address sender = opInfo.mUserOp.sender;
                    bool success;
                    {
                        uint256 saveFreePtr = _getFreePtr();
                        bytes memory callData = abi.encodeCall(IAccount.validateUserOp, (op, opInfo.userOpHash, missingAccountFunds));
                        assembly ("memory-safe"){
                            success := call(gasLimit, sender, 0, add(callData, 0x20), mload(callData), 0, 32)
                            validationData := mload(0)
                        // any return data size other than 32 is considered failure
                            if iszero(eq(returndatasize(), 32)) {
                                success := 0
                            }
                        }
                        _restoreFreePtr(saveFreePtr);
                    }
                    if (!success) {
                        if (sender.code.length == 0) {
                            revert FailedOp(opIndex, "AA20 account not deployed");
                        } else {
                            revert FailedOpWithRevert(opIndex, "AA23 reverted", Exec.getReturnData(REVERT_REASON_MAX_LEN));
                        }
                    }
                }
                /**
                 * In case the request has a paymaster:
                 *  - Validate paymaster has enough deposit.
                 *  - Call paymaster.validatePaymasterUserOp.
                 *  - Revert with proper FailedOp in case paymaster reverts.
                 *  - Decrement paymaster's deposit.
                 * @param opIndex                            - The operation index.
                 * @param op                                 - The user operation.
                 * @param opInfo                             - The operation info.
                 * @return context                           - The Paymaster-provided value to be passed to the 'postOp' function later
                 * @return validationData                    - The Paymaster's validationData.
                 */
                function _validatePaymasterPrepayment(
                    uint256 opIndex,
                    PackedUserOperation calldata op,
                    UserOpInfo memory opInfo
                ) internal virtual returns (bytes memory context, uint256 validationData) {
                    unchecked {
                        uint256 preGas = gasleft();
                        MemoryUserOp memory mUserOp = opInfo.mUserOp;
                        address paymaster = mUserOp.paymaster;
                        uint256 requiredPreFund = opInfo.prefund;
                        if (!_tryDecrementDeposit(paymaster, requiredPreFund)) {
                            revert FailedOp(opIndex, "AA31 paymaster deposit too low");
                        }
                        uint256 pmVerificationGasLimit = mUserOp.paymasterVerificationGasLimit;
                        (context, validationData) = _callValidatePaymasterUserOp(opIndex, op, opInfo);
                        if (preGas - gasleft() > pmVerificationGasLimit) {
                            revert FailedOp(opIndex, "AA36 over paymasterVerificationGasLimit");
                        }
                    }
                }
                function _callValidatePaymasterUserOp(
                    uint256 opIndex,
                    PackedUserOperation calldata op,
                    UserOpInfo memory opInfo
                ) internal returns (bytes memory context, uint256 validationData)  {
                    uint256 freePtr = _getFreePtr();
                    bytes memory validatePaymasterCall = abi.encodeCall(
                        IPaymaster.validatePaymasterUserOp,
                        (op, opInfo.userOpHash, opInfo.prefund)
                    );
                    address paymaster = opInfo.mUserOp.paymaster;
                    uint256 paymasterVerificationGasLimit = opInfo.mUserOp.paymasterVerificationGasLimit;
                    bool success;
                    uint256 contextLength;
                    uint256 contextOffset;
                    uint256 maxContextLength;
                    uint256 len;
                    assembly ("memory-safe") {
                        success := call(paymasterVerificationGasLimit, paymaster, 0, add(validatePaymasterCall, 0x20), mload(validatePaymasterCall), 0, 0)
                        len := returndatasize()
                        // return data from validatePaymasterUserOp is (bytes context, validationData)
                        // encoded as:
                        // 32 bytes offset of context (always 64)
                        // 32 bytes of validationData
                        // 32 bytes of context length
                        // context data (rounded up, to 32 bytes boundary)
                        // so entire buffer size is (at least) 96+content.length.
                        //
                        // we use freePtr, fetched before calling encodeCall, as return data pointer.
                        // this way we reuse that memory without unnecessary memory expansion
                        returndatacopy(freePtr, 0, len)
                        validationData := mload(add(freePtr, 32))
                        contextOffset := mload(freePtr)
                        maxContextLength := sub(len, 96)
                        context := add(freePtr, 64)
                        contextLength := mload(context)
                    }
                    unchecked {
                        if (!success || contextOffset != 64 || contextLength + 31 < maxContextLength) {
                            revert FailedOpWithRevert(opIndex, "AA33 reverted", Exec.getReturnData(REVERT_REASON_MAX_LEN));
                        }
                    }
                    finalizeAllocation(freePtr, len);
                }
                /**
                 * Revert if either account validationData or paymaster validationData is expired.
                 * @param opIndex                 - The operation index.
                 * @param validationData          - The account validationData.
                 * @param paymasterValidationData - The paymaster validationData.
                 * @param expectedAggregator      - The expected aggregator.
                 */
                function _validateAccountAndPaymasterValidationData(
                    uint256 opIndex,
                    uint256 validationData,
                    uint256 paymasterValidationData,
                    address expectedAggregator
                ) internal virtual view {
                    (address aggregator, bool outOfTimeRange) = _getValidationData(
                        validationData
                    );
                    if (expectedAggregator != aggregator) {
                        revert FailedOp(opIndex, "AA24 signature error");
                    }
                    if (outOfTimeRange) {
                        revert FailedOp(opIndex, "AA22 expired or not due");
                    }
                    // pmAggregator is not a real signature aggregator: we don't have logic to handle it as address.
                    // Non-zero address means that the paymaster fails due to some signature check (which is ok only during estimation).
                    address pmAggregator;
                    (pmAggregator, outOfTimeRange) = _getValidationData(
                        paymasterValidationData
                    );
                    if (pmAggregator != address(0)) {
                        revert FailedOp(opIndex, "AA34 signature error");
                    }
                    if (outOfTimeRange) {
                        revert FailedOp(opIndex, "AA32 paymaster expired or not due");
                    }
                }
                /**
                 * Parse validationData into its components.
                 * @param validationData - The packed validation data (sigFailed, validAfter, validUntil).
                 * @return aggregator the aggregator of the validationData
                 * @return outOfTimeRange true if current time is outside the time range of this validationData.
                 */
                function _getValidationData(
                    uint256 validationData
                ) internal virtual view returns (address aggregator, bool outOfTimeRange) {
                    if (validationData == 0) {
                        return (address(0), false);
                    }
                    ValidationData memory data = _parseValidationData(validationData);
                    // solhint-disable-next-line not-rely-on-time
                    outOfTimeRange = block.timestamp > data.validUntil || block.timestamp <= data.validAfter;
                    aggregator = data.aggregator;
                }
                /**
                 * Validate account and paymaster (if defined) and
                 * also make sure total validation doesn't exceed verificationGasLimit.
                 * This method is called off-chain (simulateValidation()) and on-chain (from handleOps)
                 * @param opIndex    - The index of this userOp into the "opInfos" array.
                 * @param userOp     - The packed calldata UserOperation structure to validate.
                 * @param outOpInfo  - The empty unpacked in-memory UserOperation structure that will be filled in here.
                 *
                 * @return validationData          - The account's validationData.
                 * @return paymasterValidationData - The paymaster's validationData.
                 */
                function _validatePrepayment(
                    uint256 opIndex,
                    PackedUserOperation calldata userOp,
                    UserOpInfo memory outOpInfo
                )
                internal virtual
                returns (uint256 validationData, uint256 paymasterValidationData)
                {
                    uint256 preGas = gasleft();
                    MemoryUserOp memory mUserOp = outOpInfo.mUserOp;
                    _copyUserOpToMemory(userOp, mUserOp);
                    // getUserOpHash uses temporary allocations, no required after it returns
                    uint256 freePtr = _getFreePtr();
                    outOpInfo.userOpHash = getUserOpHash(userOp);
                    _restoreFreePtr(freePtr);
                    // Validate all numeric values in userOp are well below 128 bit, so they can safely be added
                    // and multiplied without causing overflow.
                    uint256 verificationGasLimit = mUserOp.verificationGasLimit;
                    uint256 maxGasValues = mUserOp.preVerificationGas |
                                verificationGasLimit |
                                    mUserOp.callGasLimit |
                                    mUserOp.paymasterVerificationGasLimit |
                                    mUserOp.paymasterPostOpGasLimit |
                                    mUserOp.maxFeePerGas |
                                    mUserOp.maxPriorityFeePerGas;
                    require(maxGasValues <= type(uint120).max, FailedOp(opIndex, "AA94 gas values overflow"));
                    uint256 requiredPreFund = _getRequiredPrefund(mUserOp);
                    outOpInfo.prefund = requiredPreFund;
                    validationData = _validateAccountPrepayment(
                        opIndex,
                        userOp,
                        outOpInfo,
                        requiredPreFund
                    );
                    require(
                        _validateAndUpdateNonce(mUserOp.sender, mUserOp.nonce),
                        FailedOp(opIndex, "AA25 invalid account nonce")
                    );
                    unchecked {
                        if (preGas - gasleft() > verificationGasLimit) {
                            revert FailedOp(opIndex, "AA26 over verificationGasLimit");
                        }
                    }
                    bytes memory context;
                    if (mUserOp.paymaster != address(0)) {
                        (context, paymasterValidationData) = _validatePaymasterPrepayment(
                            opIndex,
                            userOp,
                            outOpInfo
                        );
                    }
                    unchecked {
                        outOpInfo.contextOffset = _getOffsetOfMemoryBytes(context);
                        outOpInfo.preOpGas = preGas - gasleft() + userOp.preVerificationGas;
                    }
                }
                /**
                 * Process post-operation, called just after the callData is executed.
                 * If a paymaster is defined and its validation returned a non-empty context, its postOp is called.
                 * The excess amount is refunded to the account (or paymaster - if it was used in the request).
                 * @param mode      - Whether is called from innerHandleOp, or outside (postOpReverted).
                 * @param opInfo    - UserOp fields and info collected during validation.
                 * @param context   - The context returned in validatePaymasterUserOp.
                 * @param actualGas - The gas used so far by this user operation.
                 *
                 * @return actualGasCost - the actual cost in eth this UserOperation paid for gas
                 */
                function _postExecution(
                    IPaymaster.PostOpMode mode,
                    UserOpInfo memory opInfo,
                    bytes memory context,
                    uint256 actualGas
                ) internal virtual returns (uint256 actualGasCost) {
                    uint256 preGas = gasleft();
                    unchecked {
                        address refundAddress;
                        MemoryUserOp memory mUserOp = opInfo.mUserOp;
                        uint256 gasPrice = _getUserOpGasPrice(mUserOp);
                        address paymaster = mUserOp.paymaster;
                    // Calculating a penalty for unused execution gas
                        {
                            uint256 executionGasUsed = actualGas - opInfo.preOpGas;
                            // this check is required for the gas used within EntryPoint and not covered by explicit gas limits
                            actualGas += _getUnusedGasPenalty(executionGasUsed, mUserOp.callGasLimit);
                        }
                        uint256 postOpUnusedGasPenalty;
                        if (paymaster == address(0)) {
                            refundAddress = mUserOp.sender;
                        } else {
                            refundAddress = paymaster;
                            if (context.length > 0) {
                                actualGasCost = actualGas * gasPrice;
                                uint256 postOpPreGas = gasleft();
                                if (mode != IPaymaster.PostOpMode.postOpReverted) {
                                    try IPaymaster(paymaster).postOp{
                                            gas: mUserOp.paymasterPostOpGasLimit
                                        }(mode, context, actualGasCost, gasPrice)
                                    // solhint-disable-next-line no-empty-blocks
                                    {} catch {
                                        bytes memory reason = Exec.getReturnData(REVERT_REASON_MAX_LEN);
                                        revert PostOpReverted(reason);
                                    }
                                }
                                // Calculating a penalty for unused postOp gas
                                // note that if postOp is reverted, the maximum penalty (10% of postOpGasLimit) is charged.
                                uint256 postOpGasUsed = postOpPreGas - gasleft();
                                postOpUnusedGasPenalty = _getUnusedGasPenalty(postOpGasUsed, mUserOp.paymasterPostOpGasLimit);
                            }
                        }
                        actualGas += preGas - gasleft() + postOpUnusedGasPenalty;
                        actualGasCost = actualGas * gasPrice;
                        uint256 prefund = opInfo.prefund;
                        if (prefund < actualGasCost) {
                            if (mode == IPaymaster.PostOpMode.postOpReverted) {
                                actualGasCost = prefund;
                                _emitPrefundTooLow(opInfo);
                                _emitUserOperationEvent(opInfo, false, actualGasCost, actualGas);
                            } else {
                                assembly ("memory-safe") {
                                    mstore(0, INNER_REVERT_LOW_PREFUND)
                                    revert(0, 32)
                                }
                            }
                        } else {
                            uint256 refund = prefund - actualGasCost;
                            _incrementDeposit(refundAddress, refund);
                            bool success = mode == IPaymaster.PostOpMode.opSucceeded;
                            _emitUserOperationEvent(opInfo, success, actualGasCost, actualGas);
                        }
                    } // unchecked
                }
                /**
                 * The gas price this UserOp agrees to pay.
                 * Relayer/block builder might submit the TX with higher priorityFee, but the user should not be affected.
                 * @param mUserOp - The userOp to get the gas price from.
                 */
                function _getUserOpGasPrice(
                    MemoryUserOp memory mUserOp
                ) internal view returns (uint256) {
                    unchecked {
                        uint256 maxFeePerGas = mUserOp.maxFeePerGas;
                        uint256 maxPriorityFeePerGas = mUserOp.maxPriorityFeePerGas;
                        return min(maxFeePerGas, maxPriorityFeePerGas + block.basefee);
                    }
                }
                /**
                 * The offset of the given bytes in memory.
                 * @param data - The bytes to get the offset of.
                 */
                function _getOffsetOfMemoryBytes(
                    bytes memory data
                ) internal pure returns (uint256 offset) {
                    assembly ("memory-safe") {
                        offset := data
                    }
                }
                /**
                 * The bytes in memory at the given offset.
                 * @param offset - The offset to get the bytes from.
                 */
                function _getMemoryBytesFromOffset(
                    uint256 offset
                ) internal pure returns (bytes memory data) {
                    assembly ("memory-safe") {
                        data := offset
                    }
                }
                /**
                 * save free memory pointer.
                 * save "free memory" pointer, so that it can be restored later using restoreFreePtr.
                 * This reduce unneeded memory expansion, and reduce memory expansion cost.
                 * NOTE: all dynamic allocations between saveFreePtr and restoreFreePtr MUST NOT be used after restoreFreePtr is called.
                 */
                function _getFreePtr() internal pure returns (uint256 ptr) {
                    assembly ("memory-safe") {
                        ptr := mload(0x40)
                    }
                }
                /**
                 * restore free memory pointer.
                 * any allocated memory since saveFreePtr is cleared, and MUST NOT be accessed later.
                 */
                function _restoreFreePtr(uint256 ptr) internal pure {
                    assembly ("memory-safe") {
                        mstore(0x40, ptr)
                    }
                }
                function _getUnusedGasPenalty(uint256 gasUsed, uint256 gasLimit) internal pure returns (uint256) {
                    unchecked {
                        if (gasLimit <= gasUsed + PENALTY_GAS_THRESHOLD) {
                            return 0;
                        }
                        uint256 unusedGas = gasLimit - gasUsed;
                        uint256 unusedGasPenalty = (unusedGas * UNUSED_GAS_PENALTY_PERCENT) / 100;
                        return unusedGasPenalty;
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.28;
            /* solhint-disable no-inline-assembly */
             /*
              * For simulation purposes, validateUserOp (and validatePaymasterUserOp)
              * must return this value in case of signature failure, instead of revert.
              */
            uint256 constant SIG_VALIDATION_FAILED = 1;
            /*
             * For simulation purposes, validateUserOp (and validatePaymasterUserOp)
             * return this value on success.
             */
            uint256 constant SIG_VALIDATION_SUCCESS = 0;
            /**
             * Returned data from validateUserOp.
             * validateUserOp returns a uint256, which is created by `_packedValidationData` and
             * parsed by `_parseValidationData`.
             * @param aggregator  - address(0) - The account validated the signature by itself.
             *                      address(1) - The account failed to validate the signature.
             *                      otherwise - This is an address of a signature aggregator that must
             *                                  be used to validate the signature.
             * @param validAfter  - This UserOp is valid only after this timestamp.
             * @param validUntil - Last timestamp this operation is valid at, or 0 for "indefinitely".
             */
            struct ValidationData {
                address aggregator;
                uint48 validAfter;
                uint48 validUntil;
            }
            /**
             * Extract aggregator/sigFailed, validAfter, validUntil.
             * Also convert zero validUntil to type(uint48).max.
             * @param validationData - The packed validation data.
             * @return data - The unpacked in-memory validation data.
             */
            function _parseValidationData(
                uint256 validationData
            ) pure returns (ValidationData memory data) {
                address aggregator = address(uint160(validationData));
                uint48 validUntil = uint48(validationData >> 160);
                if (validUntil == 0) {
                    validUntil = type(uint48).max;
                }
                uint48 validAfter = uint48(validationData >> (48 + 160));
                return ValidationData(aggregator, validAfter, validUntil);
            }
            /**
             * Helper to pack the return value for validateUserOp.
             * @param data - The ValidationData to pack.
             * @return the packed validation data.
             */
            function _packValidationData(
                ValidationData memory data
            ) pure returns (uint256) {
                return
                    uint160(data.aggregator) |
                    (uint256(data.validUntil) << 160) |
                    (uint256(data.validAfter) << (160 + 48));
            }
            /**
             * Helper to pack the return value for validateUserOp, when not using an aggregator.
             * @param sigFailed  - True for signature failure, false for success.
             * @param validUntil - Last timestamp this operation is valid at, or 0 for "indefinitely".
             * @param validAfter - First timestamp this UserOperation is valid.
             * @return the packed validation data.
             */
            function _packValidationData(
                bool sigFailed,
                uint48 validUntil,
                uint48 validAfter
            ) pure returns (uint256) {
                return
                    (sigFailed ?  SIG_VALIDATION_FAILED : SIG_VALIDATION_SUCCESS) |
                    (uint256(validUntil) << 160) |
                    (uint256(validAfter) << (160 + 48));
            }
            /**
             * keccak function over calldata.
             * @dev copy calldata into memory, do keccak and drop allocated memory. Strangely, this is more efficient than letting solidity do it.
             *
             * @param data - the calldata bytes array to perform keccak on.
             * @return ret - the keccak hash of the 'data' array.
             */
                function calldataKeccak(bytes calldata data) pure returns (bytes32 ret) {
                    assembly ("memory-safe") {
                        let mem := mload(0x40)
                        let len := data.length
                        calldatacopy(mem, data.offset, len)
                        ret := keccak256(mem, len)
                    }
                }
            /**
             * The minimum of two numbers.
             * @param a - First number.
             * @param b - Second number.
             * @return - the minimum value.
             */
                function min(uint256 a, uint256 b) pure returns (uint256) {
                    return a < b ? a : b;
                }
            /**
             * standard solidity memory allocation finalization.
             * copied from solidity generated code
             * @param memPointer - The current memory pointer
             * @param allocationSize - Bytes allocated from memPointer.
             */
                function finalizeAllocation(uint256 memPointer, uint256 allocationSize) pure {
                    assembly ("memory-safe"){
                        finalize_allocation(memPointer, allocationSize)
                        function finalize_allocation(memPtr, size) {
                            let newFreePtr := add(memPtr, round_up_to_mul_of_32(size))
                            mstore(64, newFreePtr)
                        }
                        function round_up_to_mul_of_32(value) -> result {
                            result := and(add(value, 31), not(31))
                        }
                    }
                }
            // SPDX-License-Identifier: GPL-3.0
            pragma solidity ^0.8.28;
            import "../interfaces/INonceManager.sol";
            /**
             * nonce management functionality
             */
            abstract contract NonceManager is INonceManager {
                /**
                 * The next valid sequence number for a given nonce key.
                 */
                mapping(address => mapping(uint192 => uint256)) public nonceSequenceNumber;
                /// @inheritdoc INonceManager
                function getNonce(address sender, uint192 key)
                public view override returns (uint256 nonce) {
                    return nonceSequenceNumber[sender][key] | (uint256(key) << 64);
                }
                /// @inheritdoc INonceManager
                function incrementNonce(uint192 key) external override {
                    nonceSequenceNumber[msg.sender][key]++;
                }
                /**
                 * validate nonce uniqueness for this account.
                 * called just after validateUserOp()
                 * @return true if the nonce was incremented successfully.
                 *         false if the current nonce doesn't match the given one.
                 */
                function _validateAndUpdateNonce(address sender, uint256 nonce) internal returns (bool) {
                    uint192 key = uint192(nonce >> 64);
                    uint64 seq = uint64(nonce);
                    return nonceSequenceNumber[sender][key]++ == seq;
                }
            }
            // SPDX-License-Identifier: GPL-3.0
            pragma solidity ^0.8.28;
            /* solhint-disable avoid-low-level-calls */
            /* solhint-disable no-inline-assembly */
            import "../interfaces/ISenderCreator.sol";
            import "../interfaces/IEntryPoint.sol";
            import "../utils/Exec.sol";
            /**
             * Helper contract for EntryPoint, to call userOp.initCode from a "neutral" address,
             * which is explicitly not the entryPoint itself.
             */
            contract SenderCreator is ISenderCreator {
                address public immutable entryPoint;
                constructor(){
                    entryPoint = msg.sender;
                }
                uint256 private constant REVERT_REASON_MAX_LEN = 2048;
                /**
                 * Call the "initCode" factory to create and return the sender account address.
                 * @param initCode - The initCode value from a UserOp. contains 20 bytes of factory address,
                 *                   followed by calldata.
                 * @return sender  - The returned address of the created account, or zero address on failure.
                 */
                function createSender(
                    bytes calldata initCode
                ) external returns (address sender) {
                    require(msg.sender == entryPoint, "AA97 should call from EntryPoint");
                    address factory = address(bytes20(initCode[0 : 20]));
                    bytes memory initCallData = initCode[20 :];
                    bool success;
                    assembly ("memory-safe") {
                        success := call(
                            gas(),
                            factory,
                            0,
                            add(initCallData, 0x20),
                            mload(initCallData),
                            0,
                            32
                        )
                        if success {
                            sender := mload(0)
                        }
                    }
                }
                /// @inheritdoc ISenderCreator
                function initEip7702Sender(
                    address sender,
                    bytes memory initCallData
                ) external {
                    require(msg.sender == entryPoint, "AA97 should call from EntryPoint");
                    bool success;
                    assembly ("memory-safe") {
                        success := call(
                            gas(),
                            sender,
                            0,
                            add(initCallData, 0x20),
                            mload(initCallData),
                            0,
                            0
                        )
                    }
                    if (!success) {
                        bytes memory result = Exec.getReturnData(REVERT_REASON_MAX_LEN);
                        revert IEntryPoint.FailedOpWithRevert(0, "AA13 EIP7702 sender init failed", result);
                    }
                }
            }
            // SPDX-License-Identifier: GPL-3.0
            pragma solidity ^0.8.28;
            import "../interfaces/IStakeManager.sol";
            /* solhint-disable avoid-low-level-calls */
            /* solhint-disable not-rely-on-time */
            /**
             * Manage deposits and stakes.
             * Deposit is just a balance used to pay for UserOperations (either by a paymaster or an account).
             * Stake is value locked for at least "unstakeDelay" by a paymaster.
             */
            abstract contract StakeManager is IStakeManager {
                /// maps paymaster to their deposits and stakes
                mapping(address => DepositInfo) private deposits;
                /// @inheritdoc IStakeManager
                function getDepositInfo(
                    address account
                ) external view returns (DepositInfo memory info) {
                    return deposits[account];
                }
                /**
                 * Internal method to return just the stake info.
                 * @param addr - The account to query.
                 */
                function _getStakeInfo(
                    address addr
                ) internal view returns (StakeInfo memory info) {
                    DepositInfo storage depositInfo = deposits[addr];
                    info.stake = depositInfo.stake;
                    info.unstakeDelaySec = depositInfo.unstakeDelaySec;
                }
                /// @inheritdoc IStakeManager
                function balanceOf(address account) public view returns (uint256) {
                    return deposits[account].deposit;
                }
                receive() external payable {
                    depositTo(msg.sender);
                }
                /**
                 * Increments an account's deposit.
                 * @param account - The account to increment.
                 * @param amount  - The amount to increment by.
                 * @return the updated deposit of this account
                 */
                function _incrementDeposit(address account, uint256 amount) internal returns (uint256) {
                    unchecked {
                        DepositInfo storage info = deposits[account];
                        uint256 newAmount = info.deposit + amount;
                        info.deposit = newAmount;
                        return newAmount;
                    }
                }
                /**
                 * Try to decrement the account's deposit.
                 * @param account - The account to decrement.
                 * @param amount  - The amount to decrement by.
                 * @return true if the decrement succeeded (that is, previous balance was at least that amount)
                 */
                function _tryDecrementDeposit(address account, uint256 amount) internal returns(bool) {
                    unchecked {
                        DepositInfo storage info = deposits[account];
                        uint256 currentDeposit = info.deposit;
                        if (currentDeposit < amount) {
                            return false;
                        }
                        info.deposit = currentDeposit - amount;
                        return true;
                    }
                }
                /// @inheritdoc IStakeManager
                function depositTo(address account) public virtual payable {
                    uint256 newDeposit = _incrementDeposit(account, msg.value);
                    emit Deposited(account, newDeposit);
                }
                /// @inheritdoc IStakeManager
                function addStake(uint32 unstakeDelaySec) external payable {
                    DepositInfo storage info = deposits[msg.sender];
                    require(unstakeDelaySec > 0, "must specify unstake delay");
                    require(
                        unstakeDelaySec >= info.unstakeDelaySec,
                        "cannot decrease unstake time"
                    );
                    uint256 stake = info.stake + msg.value;
                    require(stake > 0, "no stake specified");
                    require(stake <= type(uint112).max, "stake overflow");
                    deposits[msg.sender] = DepositInfo(
                        info.deposit,
                        true,
                        uint112(stake),
                        unstakeDelaySec,
                        0
                    );
                    emit StakeLocked(msg.sender, stake, unstakeDelaySec);
                }
                /// @inheritdoc IStakeManager
                function unlockStake() external {
                    DepositInfo storage info = deposits[msg.sender];
                    require(info.unstakeDelaySec != 0, "not staked");
                    require(info.staked, "already unstaking");
                    uint48 withdrawTime = uint48(block.timestamp) + info.unstakeDelaySec;
                    info.withdrawTime = withdrawTime;
                    info.staked = false;
                    emit StakeUnlocked(msg.sender, withdrawTime);
                }
                /// @inheritdoc IStakeManager
                function withdrawStake(address payable withdrawAddress) external {
                    DepositInfo storage info = deposits[msg.sender];
                    uint256 stake = info.stake;
                    require(stake > 0, "No stake to withdraw");
                    require(info.withdrawTime > 0, "must call unlockStake() first");
                    require(
                        info.withdrawTime <= block.timestamp,
                        "Stake withdrawal is not due"
                    );
                    info.unstakeDelaySec = 0;
                    info.withdrawTime = 0;
                    info.stake = 0;
                    emit StakeWithdrawn(msg.sender, withdrawAddress, stake);
                    (bool success,) = withdrawAddress.call{value: stake}("");
                    require(success, "failed to withdraw stake");
                }
                /// @inheritdoc IStakeManager
                function withdrawTo(
                    address payable withdrawAddress,
                    uint256 withdrawAmount
                ) external {
                    DepositInfo storage info = deposits[msg.sender];
                    uint256 currentDeposit = info.deposit;
                    require(withdrawAmount <= currentDeposit, "Withdraw amount too large");
                    info.deposit = currentDeposit - withdrawAmount;
                    emit Withdrawn(msg.sender, withdrawAddress, withdrawAmount);
                    (bool success,) = withdrawAddress.call{value: withdrawAmount}("");
                    require(success, "failed to withdraw");
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.28;
            /* solhint-disable no-inline-assembly */
            import "../interfaces/PackedUserOperation.sol";
            import {calldataKeccak, min} from "./Helpers.sol";
            /**
             * Utility functions helpful when working with UserOperation structs.
             */
            library UserOperationLib {
                uint256 public constant PAYMASTER_VALIDATION_GAS_OFFSET = 20;
                uint256 public constant PAYMASTER_POSTOP_GAS_OFFSET = 36;
                uint256 public constant PAYMASTER_DATA_OFFSET = 52;
                /**
                 * Relayer/block builder might submit the TX with higher priorityFee,
                 * but the user should not pay above what he signed for.
                 * @param userOp - The user operation data.
                 */
                function gasPrice(
                    PackedUserOperation calldata userOp
                ) internal view returns (uint256) {
                    unchecked {
                        (uint256 maxPriorityFeePerGas, uint256 maxFeePerGas) = unpackUints(userOp.gasFees);
                        return min(maxFeePerGas, maxPriorityFeePerGas + block.basefee);
                    }
                }
                bytes32 internal constant PACKED_USEROP_TYPEHASH =
                keccak256(
                    "PackedUserOperation(address sender,uint256 nonce,bytes initCode,bytes callData,bytes32 accountGasLimits,uint256 preVerificationGas,bytes32 gasFees,bytes paymasterAndData)"
                );
                /**
                 * Pack the user operation data into bytes for hashing.
                 * @param userOp - The user operation data.
                 * @param overrideInitCodeHash - If set, encode this instead of the initCode field in the userOp.
                 */
                function encode(
                    PackedUserOperation calldata userOp,
                    bytes32 overrideInitCodeHash
                ) internal pure returns (bytes memory ret) {
                    address sender = userOp.sender;
                    uint256 nonce = userOp.nonce;
                    bytes32 hashInitCode = overrideInitCodeHash != 0 ? overrideInitCodeHash : calldataKeccak(userOp.initCode);
                    bytes32 hashCallData = calldataKeccak(userOp.callData);
                    bytes32 accountGasLimits = userOp.accountGasLimits;
                    uint256 preVerificationGas = userOp.preVerificationGas;
                    bytes32 gasFees = userOp.gasFees;
                    bytes32 hashPaymasterAndData = calldataKeccak(userOp.paymasterAndData);
                    return abi.encode(
                        UserOperationLib.PACKED_USEROP_TYPEHASH,
                        sender, nonce,
                        hashInitCode, hashCallData,
                        accountGasLimits, preVerificationGas, gasFees,
                        hashPaymasterAndData
                    );
                }
                function unpackUints(
                    bytes32 packed
                ) internal pure returns (uint256 high128, uint256 low128) {
                    return (unpackHigh128(packed), unpackLow128(packed));
                }
                // Unpack just the high 128-bits from a packed value
                function unpackHigh128(bytes32 packed) internal pure returns (uint256) {
                    return uint256(packed) >> 128;
                }
                // Unpack just the low 128-bits from a packed value
                function unpackLow128(bytes32 packed) internal pure returns (uint256) {
                    return uint128(uint256(packed));
                }
                function unpackMaxPriorityFeePerGas(PackedUserOperation calldata userOp)
                internal pure returns (uint256) {
                    return unpackHigh128(userOp.gasFees);
                }
                function unpackMaxFeePerGas(PackedUserOperation calldata userOp)
                internal pure returns (uint256) {
                    return unpackLow128(userOp.gasFees);
                }
                function unpackVerificationGasLimit(PackedUserOperation calldata userOp)
                internal pure returns (uint256) {
                    return unpackHigh128(userOp.accountGasLimits);
                }
                function unpackCallGasLimit(PackedUserOperation calldata userOp)
                internal pure returns (uint256) {
                    return unpackLow128(userOp.accountGasLimits);
                }
                function unpackPaymasterVerificationGasLimit(PackedUserOperation calldata userOp)
                internal pure returns (uint256) {
                    return uint128(bytes16(userOp.paymasterAndData[PAYMASTER_VALIDATION_GAS_OFFSET : PAYMASTER_POSTOP_GAS_OFFSET]));
                }
                function unpackPostOpGasLimit(PackedUserOperation calldata userOp)
                internal pure returns (uint256) {
                    return uint128(bytes16(userOp.paymasterAndData[PAYMASTER_POSTOP_GAS_OFFSET : PAYMASTER_DATA_OFFSET]));
                }
                function unpackPaymasterStaticFields(
                    bytes calldata paymasterAndData
                ) internal pure returns (address paymaster, uint256 validationGasLimit, uint256 postOpGasLimit) {
                    return (
                        address(bytes20(paymasterAndData[: PAYMASTER_VALIDATION_GAS_OFFSET])),
                        uint128(bytes16(paymasterAndData[PAYMASTER_VALIDATION_GAS_OFFSET : PAYMASTER_POSTOP_GAS_OFFSET])),
                        uint128(bytes16(paymasterAndData[PAYMASTER_POSTOP_GAS_OFFSET : PAYMASTER_DATA_OFFSET]))
                    );
                }
                /**
                 * Hash the user operation data.
                 * @param userOp - The user operation data.
                 * @param overrideInitCodeHash - If set, the initCode hash will be replaced with this value just for UserOp hashing.
                 */
                function hash(
                    PackedUserOperation calldata userOp,
                    bytes32 overrideInitCodeHash
                ) internal pure returns (bytes32) {
                    return keccak256(encode(userOp, overrideInitCodeHash));
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.28;
            import "./PackedUserOperation.sol";
            interface IAccount {
                /**
                 * Validate user's signature and nonce
                 * the entryPoint will make the call to the recipient only if this validation call returns successfully.
                 * signature failure should be reported by returning SIG_VALIDATION_FAILED (1).
                 * This allows making a "simulation call" without a valid signature
                 * Other failures (e.g. nonce mismatch, or invalid signature format) should still revert to signal failure.
                 *
                 * @dev Must validate caller is the entryPoint.
                 *      Must validate the signature and nonce
                 * @param userOp              - The operation that is about to be executed.
                 * @param userOpHash          - Hash of the user's request data. can be used as the basis for signature.
                 * @param missingAccountFunds - Missing funds on the account's deposit in the entrypoint.
                 *                              This is the minimum amount to transfer to the sender(entryPoint) to be
                 *                              able to make the call. The excess is left as a deposit in the entrypoint
                 *                              for future calls. Can be withdrawn anytime using "entryPoint.withdrawTo()".
                 *                              In case there is a paymaster in the request (or the current deposit is high
                 *                              enough), this value will be zero.
                 * @return validationData       - Packaged ValidationData structure. use `_packValidationData` and
                 *                              `_unpackValidationData` to encode and decode.
                 *                              <20-byte> aggregatorOrSigFail - 0 for valid signature, 1 to mark signature failure,
                 *                                 otherwise, an address of an "aggregator" contract.
                 *                              <6-byte> validUntil - Last timestamp this operation is valid at, or 0 for "indefinitely"
                 *                              <6-byte> validAfter - First timestamp this operation is valid
                 *                                                    If an account doesn't use time-range, it is enough to
                 *                                                    return SIG_VALIDATION_FAILED value (1) for signature failure.
                 *                              Note that the validation code cannot use block.timestamp (or block.number) directly.
                 */
                function validateUserOp(
                    PackedUserOperation calldata userOp,
                    bytes32 userOpHash,
                    uint256 missingAccountFunds
                ) external returns (uint256 validationData);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.28;
            import "./PackedUserOperation.sol";
            interface IAccountExecute {
                /**
                 * Account may implement this execute method.
                 * passing this methodSig at the beginning of callData will cause the entryPoint to pass the full UserOp (and hash)
                 * to the account.
                 * The account should skip the methodSig, and use the callData (and optionally, other UserOp fields)
                 *
                 * @param userOp              - The operation that was just validated.
                 * @param userOpHash          - Hash of the user's request data.
                 */
                function executeUserOp(
                    PackedUserOperation calldata userOp,
                    bytes32 userOpHash
                ) external;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.28;
            import "./PackedUserOperation.sol";
            /**
             * Aggregated Signatures validator.
             */
            interface IAggregator {
                /**
                 * Validate an aggregated signature.
                 * Reverts if the aggregated signature does not match the given list of operations.
                 * @param userOps   - An array of UserOperations to validate the signature for.
                 * @param signature - The aggregated signature.
                 */
                function validateSignatures(
                    PackedUserOperation[] calldata userOps,
                    bytes calldata signature
                ) external;
                /**
                 * Validate the signature of a single userOp.
                 * This method should be called by bundler after EntryPointSimulation.simulateValidation() returns
                 * the aggregator this account uses.
                 * First it validates the signature over the userOp. Then it returns data to be used when creating the handleOps.
                 * @param userOp        - The userOperation received from the user.
                 * @return sigForUserOp - The value to put into the signature field of the userOp when calling handleOps.
                 *                        (usually empty, unless account and aggregator support some kind of "multisig".
                 */
                function validateUserOpSignature(
                    PackedUserOperation calldata userOp
                ) external view returns (bytes memory sigForUserOp);
                /**
                 * Aggregate multiple signatures into a single value.
                 * This method is called off-chain to calculate the signature to pass with handleOps()
                 * bundler MAY use optimized custom code to perform this aggregation.
                 * @param userOps              - An array of UserOperations to collect the signatures from.
                 * @return aggregatedSignature - The aggregated signature.
                 */
                function aggregateSignatures(
                    PackedUserOperation[] calldata userOps
                ) external view returns (bytes memory aggregatedSignature);
            }
            /**
             ** Account-Abstraction (EIP-4337) singleton EntryPoint implementation.
             ** Only one instance required on each chain.
             **/
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.28;
            /* solhint-disable avoid-low-level-calls */
            /* solhint-disable no-inline-assembly */
            /* solhint-disable reason-string */
            import "./PackedUserOperation.sol";
            import "./IStakeManager.sol";
            import "./IAggregator.sol";
            import "./INonceManager.sol";
            import "./ISenderCreator.sol";
            interface IEntryPoint is IStakeManager, INonceManager {
                /***
                 * An event emitted after each successful request.
                 * @param userOpHash    - Unique identifier for the request (hash its entire content, except signature).
                 * @param sender        - The account that generates this request.
                 * @param paymaster     - If non-null, the paymaster that pays for this request.
                 * @param nonce         - The nonce value from the request.
                 * @param success       - True if the sender transaction succeeded, false if reverted.
                 * @param actualGasCost - Actual amount paid (by account or paymaster) for this UserOperation.
                 * @param actualGasUsed - Total gas used by this UserOperation (including preVerification, creation,
                 *                        validation and execution).
                 */
                event UserOperationEvent(
                    bytes32 indexed userOpHash,
                    address indexed sender,
                    address indexed paymaster,
                    uint256 nonce,
                    bool success,
                    uint256 actualGasCost,
                    uint256 actualGasUsed
                );
                /**
                 * Account "sender" was deployed.
                 * @param userOpHash - The userOp that deployed this account. UserOperationEvent will follow.
                 * @param sender     - The account that is deployed
                 * @param factory    - The factory used to deploy this account (in the initCode)
                 * @param paymaster  - The paymaster used by this UserOp
                 */
                event AccountDeployed(
                    bytes32 indexed userOpHash,
                    address indexed sender,
                    address factory,
                    address paymaster
                );
                /**
                 * An event emitted if the UserOperation "callData" reverted with non-zero length.
                 * @param userOpHash   - The request unique identifier.
                 * @param sender       - The sender of this request.
                 * @param nonce        - The nonce used in the request.
                 * @param revertReason - The return bytes from the reverted "callData" call.
                 */
                event UserOperationRevertReason(
                    bytes32 indexed userOpHash,
                    address indexed sender,
                    uint256 nonce,
                    bytes revertReason
                );
                /**
                 * An event emitted if the UserOperation Paymaster's "postOp" call reverted with non-zero length.
                 * @param userOpHash   - The request unique identifier.
                 * @param sender       - The sender of this request.
                 * @param nonce        - The nonce used in the request.
                 * @param revertReason - The return bytes from the reverted call to "postOp".
                 */
                event PostOpRevertReason(
                    bytes32 indexed userOpHash,
                    address indexed sender,
                    uint256 nonce,
                    bytes revertReason
                );
                /**
                 * UserOp consumed more than prefund. The UserOperation is reverted, and no refund is made.
                 * @param userOpHash   - The request unique identifier.
                 * @param sender       - The sender of this request.
                 * @param nonce        - The nonce used in the request.
                 */
                event UserOperationPrefundTooLow(
                    bytes32 indexed userOpHash,
                    address indexed sender,
                    uint256 nonce
                );
                /**
                 * An event emitted by handleOps() and handleAggregatedOps(), before starting the execution loop.
                 * Any event emitted before this event, is part of the validation.
                 */
                event BeforeExecution();
                /**
                 * Signature aggregator used by the following UserOperationEvents within this bundle.
                 * @param aggregator - The aggregator used for the following UserOperationEvents.
                 */
                event SignatureAggregatorChanged(address indexed aggregator);
                /**
                 * A custom revert error of handleOps andhandleAggregatedOps, to identify the offending op.
                 * Should be caught in off-chain handleOps/handleAggregatedOps simulation and not happen on-chain.
                 * Useful for mitigating DoS attempts against batchers or for troubleshooting of factory/account/paymaster reverts.
                 * NOTE: If simulateValidation passes successfully, there should be no reason for handleOps to fail on it.
                 * @param opIndex - Index into the array of ops to the failed one (in simulateValidation, this is always zero).
                 * @param reason  - Revert reason. The string starts with a unique code "AAmn",
                 *                  where "m" is "1" for factory, "2" for account and "3" for paymaster issues,
                 *                  so a failure can be attributed to the correct entity.
                 */
                error FailedOp(uint256 opIndex, string reason);
                /**
                 * A custom revert error of handleOps and handleAggregatedOps, to report a revert by account or paymaster.
                 * @param opIndex - Index into the array of ops to the failed one (in simulateValidation, this is always zero).
                 * @param reason  - Revert reason. see FailedOp(uint256,string), above
                 * @param inner   - data from inner cought revert reason
                 * @dev note that inner is truncated to 2048 bytes
                 */
                error FailedOpWithRevert(uint256 opIndex, string reason, bytes inner);
                error PostOpReverted(bytes returnData);
                /**
                 * Error case when a signature aggregator fails to verify the aggregated signature it had created.
                 * @param aggregator The aggregator that failed to verify the signature
                 */
                error SignatureValidationFailed(address aggregator);
                // Return value of getSenderAddress.
                error SenderAddressResult(address sender);
                // UserOps handled, per aggregator.
                struct UserOpsPerAggregator {
                    PackedUserOperation[] userOps;
                    // Aggregator address
                    IAggregator aggregator;
                    // Aggregated signature
                    bytes signature;
                }
                /**
                 * Execute a batch of UserOperations.
                 * No signature aggregator is used.
                 * If any account requires an aggregator (that is, it returned an aggregator when
                 * performing simulateValidation), then handleAggregatedOps() must be used instead.
                 * @param ops         - The operations to execute.
                 * @param beneficiary - The address to receive the fees.
                 */
                function handleOps(
                    PackedUserOperation[] calldata ops,
                    address payable beneficiary
                ) external;
                /**
                 * Execute a batch of UserOperation with Aggregators
                 * @param opsPerAggregator - The operations to execute, grouped by aggregator (or address(0) for no-aggregator accounts).
                 * @param beneficiary      - The address to receive the fees.
                 */
                function handleAggregatedOps(
                    UserOpsPerAggregator[] calldata opsPerAggregator,
                    address payable beneficiary
                ) external;
                /**
                 * Generate a request Id - unique identifier for this request.
                 * The request ID is a hash over the content of the userOp (except the signature), entrypoint address, chainId and (optionally) 7702 delegate address
                 * @param userOp - The user operation to generate the request ID for.
                 * @return hash the hash of this UserOperation
                 */
                function getUserOpHash(
                    PackedUserOperation calldata userOp
                ) external view returns (bytes32);
                /**
                 * Gas and return values during simulation.
                 * @param preOpGas         - The gas used for validation (including preValidationGas)
                 * @param prefund          - The required prefund for this operation
                 * @param accountValidationData   - returned validationData from account.
                 * @param paymasterValidationData - return validationData from paymaster.
                 * @param paymasterContext - Returned by validatePaymasterUserOp (to be passed into postOp)
                 */
                struct ReturnInfo {
                    uint256 preOpGas;
                    uint256 prefund;
                    uint256 accountValidationData;
                    uint256 paymasterValidationData;
                    bytes paymasterContext;
                }
                /**
                 * Get counterfactual sender address.
                 * Calculate the sender contract address that will be generated by the initCode and salt in the UserOperation.
                 * This method always revert, and returns the address in SenderAddressResult error.
                 * @notice this method cannot be used for EIP-7702 derived contracts.
                 *
                 * @param initCode - The constructor code to be passed into the UserOperation.
                 */
                function getSenderAddress(bytes memory initCode) external;
                error DelegateAndRevert(bool success, bytes ret);
                /**
                 * Helper method for dry-run testing.
                 * @dev calling this method, the EntryPoint will make a delegatecall to the given data, and report (via revert) the result.
                 *  The method always revert, so is only useful off-chain for dry run calls, in cases where state-override to replace
                 *  actual EntryPoint code is less convenient.
                 * @param target a target contract to make a delegatecall from entrypoint
                 * @param data data to pass to target in a delegatecall
                 */
                function delegateAndRevert(address target, bytes calldata data) external;
                /**
                 * @notice Retrieves the immutable SenderCreator contract which is responsible for deployment of sender contracts.
                 */
                function senderCreator() external view returns (ISenderCreator);
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.28;
            interface INonceManager {
                /**
                 * Return the next nonce for this sender.
                 * Within a given key, the nonce values are sequenced (starting with zero, and incremented by one on each userop)
                 * But UserOp with different keys can come with arbitrary order.
                 *
                 * @param sender the account address
                 * @param key the high 192 bit of the nonce
                 * @return nonce a full nonce to pass for next UserOp with this sender.
                 */
                function getNonce(address sender, uint192 key)
                external view returns (uint256 nonce);
                /**
                 * Manually increment the nonce of the sender.
                 * This method is exposed just for completeness..
                 * Account does NOT need to call it, neither during validation, nor elsewhere,
                 * as the EntryPoint will update the nonce regardless.
                 * Possible use-case is call it with various keys to "initialize" their nonces to one, so that future
                 * UserOperations will not pay extra for the first transaction with a given key.
                 *
                 * @param key - the "nonce key" to increment the "nonce sequence" for.
                 */
                function incrementNonce(uint192 key) external;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.28;
            import "./PackedUserOperation.sol";
            /**
             * The interface exposed by a paymaster contract, who agrees to pay the gas for user's operations.
             * A paymaster must hold a stake to cover the required entrypoint stake and also the gas for the transaction.
             */
            interface IPaymaster {
                enum PostOpMode {
                    // User op succeeded.
                    opSucceeded,
                    // User op reverted. Still has to pay for gas.
                    opReverted,
                    // Only used internally in the EntryPoint (cleanup after postOp reverts). Never calling paymaster with this value
                    postOpReverted
                }
                /**
                 * Payment validation: check if paymaster agrees to pay.
                 * Must verify sender is the entryPoint.
                 * Revert to reject this request.
                 * Note that bundlers will reject this method if it changes the state, unless the paymaster is trusted (whitelisted).
                 * The paymaster pre-pays using its deposit, and receive back a refund after the postOp method returns.
                 * @param userOp          - The user operation.
                 * @param userOpHash      - Hash of the user's request data.
                 * @param maxCost         - The maximum cost of this transaction (based on maximum gas and gas price from userOp).
                 * @return context        - Value to send to a postOp. Zero length to signify postOp is not required.
                 * @return validationData - Signature and time-range of this operation, encoded the same as the return
                 *                          value of validateUserOperation.
                 *                          <20-byte> aggregatorOrSigFail - 0 for valid signature, 1 to mark signature failure,
                 *                                                    other values are invalid for paymaster.
                 *                          <6-byte> validUntil - Last timestamp this operation is valid at, or 0 for "indefinitely"
                 *                          <6-byte> validAfter - first timestamp this operation is valid
                 *                          Note that the validation code cannot use block.timestamp (or block.number) directly.
                 */
                function validatePaymasterUserOp(
                    PackedUserOperation calldata userOp,
                    bytes32 userOpHash,
                    uint256 maxCost
                ) external returns (bytes memory context, uint256 validationData);
                /**
                 * Post-operation handler.
                 * Must verify sender is the entryPoint.
                 * @param mode          - Enum with the following options:
                 *                        opSucceeded - User operation succeeded.
                 *                        opReverted  - User op reverted. The paymaster still has to pay for gas.
                 *                        postOpReverted - never passed in a call to postOp().
                 * @param context       - The context value returned by validatePaymasterUserOp
                 * @param actualGasCost - Actual cost of gas used so far (without this postOp call).
                 * @param actualUserOpFeePerGas - the gas price this UserOp pays. This value is based on the UserOp's maxFeePerGas
                 *                        and maxPriorityFee (and basefee)
                 *                        It is not the same as tx.gasprice, which is what the bundler pays.
                 */
                function postOp(
                    PostOpMode mode,
                    bytes calldata context,
                    uint256 actualGasCost,
                    uint256 actualUserOpFeePerGas
                ) external;
            }
            
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.28;
            interface ISenderCreator {
                /**
                 * @dev Creates a new sender contract.
                 * @return sender Address of the newly created sender contract.
                 */
                function createSender(bytes calldata initCode) external returns (address sender);
                /**
                 * Use initCallData to initialize an EIP-7702 account.
                 * The caller is the EntryPoint contract and it is already verified to be an EIP-7702 account.
                 * Note: Can be called multiple times as long as an appropriate initCode is supplied
                 *
                 * @param sender - the 'sender' EIP-7702 account to be initialized.
                 * @param initCallData - the call data to be passed to the sender account call.
                 */
                function initEip7702Sender(address sender, bytes calldata initCallData) external;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.28;
            /**
             * Manage deposits and stakes.
             * Deposit is just a balance used to pay for UserOperations (either by a paymaster or an account).
             * Stake is value locked for at least "unstakeDelay" by the staked entity.
             */
            interface IStakeManager {
                event Deposited(address indexed account, uint256 totalDeposit);
                event Withdrawn(
                    address indexed account,
                    address withdrawAddress,
                    uint256 amount
                );
                // Emitted when stake or unstake delay are modified.
                event StakeLocked(
                    address indexed account,
                    uint256 totalStaked,
                    uint256 unstakeDelaySec
                );
                // Emitted once a stake is scheduled for withdrawal.
                event StakeUnlocked(address indexed account, uint256 withdrawTime);
                event StakeWithdrawn(
                    address indexed account,
                    address withdrawAddress,
                    uint256 amount
                );
                /**
                 * @param deposit         - The entity's deposit.
                 * @param staked          - True if this entity is staked.
                 * @param stake           - Actual amount of ether staked for this entity.
                 * @param unstakeDelaySec - Minimum delay to withdraw the stake.
                 * @param withdrawTime    - First block timestamp where 'withdrawStake' will be callable, or zero if already locked.
                 * @dev Sizes were chosen so that deposit fits into one cell (used during handleOp)
                 *      and the rest fit into a 2nd cell (used during stake/unstake)
                 *      - 112 bit allows for 10^15 eth
                 *      - 48 bit for full timestamp
                 *      - 32 bit allows 150 years for unstake delay
                 */
                struct DepositInfo {
                    uint256 deposit;
                    bool staked;
                    uint112 stake;
                    uint32 unstakeDelaySec;
                    uint48 withdrawTime;
                }
                // API struct used by getStakeInfo and simulateValidation.
                struct StakeInfo {
                    uint256 stake;
                    uint256 unstakeDelaySec;
                }
                /**
                 * Get deposit info.
                 * @param account - The account to query.
                 * @return info   - Full deposit information of given account.
                 */
                function getDepositInfo(
                    address account
                ) external view returns (DepositInfo memory info);
                /**
                 * Get account balance.
                 * @param account - The account to query.
                 * @return        - The deposit (for gas payment) of the account.
                 */
                function balanceOf(address account) external view returns (uint256);
                /**
                 * Add to the deposit of the given account.
                 * @param account - The account to add to.
                 */
                function depositTo(address account) external payable;
                /**
                 * Add to the account's stake - amount and delay
                 * any pending unstake is first cancelled.
                 * @param unstakeDelaySec - The new lock duration before the deposit can be withdrawn.
                 */
                function addStake(uint32 unstakeDelaySec) external payable;
                /**
                 * Attempt to unlock the stake.
                 * The value can be withdrawn (using withdrawStake) after the unstake delay.
                 */
                function unlockStake() external;
                /**
                 * Withdraw from the (unlocked) stake.
                 * Must first call unlockStake and wait for the unstakeDelay to pass.
                 * @param withdrawAddress - The address to send withdrawn value.
                 */
                function withdrawStake(address payable withdrawAddress) external;
                /**
                 * Withdraw from the deposit.
                 * @param withdrawAddress - The address to send withdrawn value.
                 * @param withdrawAmount  - The amount to withdraw.
                 */
                function withdrawTo(
                    address payable withdrawAddress,
                    uint256 withdrawAmount
                ) external;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.28;
            /**
             * User Operation struct
             * @param sender                - The sender account of this request.
             * @param nonce                 - Unique value the sender uses to verify it is not a replay.
             * @param initCode              - If set, the account contract will be created by this constructor
             * @param callData              - The method call to execute on this account.
             * @param accountGasLimits      - Packed gas limits for validateUserOp and gas limit passed to the callData method call.
             * @param preVerificationGas    - Gas not calculated by the handleOps method, but added to the gas paid.
             *                                Covers batch overhead.
             * @param gasFees               - packed gas fields maxPriorityFeePerGas and maxFeePerGas - Same as EIP-1559 gas parameters.
             * @param paymasterAndData      - If set, this field holds the paymaster address, verification gas limit, postOp gas limit and paymaster-specific extra data
             *                                The paymaster will pay for the transaction instead of the sender.
             * @param signature             - Sender-verified signature over the entire request, the EntryPoint address and the chain ID.
             */
            struct PackedUserOperation {
                address sender;
                uint256 nonce;
                bytes initCode;
                bytes callData;
                bytes32 accountGasLimits;
                uint256 preVerificationGas;
                bytes32 gasFees;
                bytes paymasterAndData;
                bytes signature;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.28;
            // solhint-disable no-inline-assembly
            /**
             * Utility functions helpful when making different kinds of contract calls in Solidity.
             */
            library Exec {
                function call(
                    address to,
                    uint256 value,
                    bytes memory data,
                    uint256 txGas
                ) internal returns (bool success) {
                    assembly ("memory-safe") {
                        success := call(txGas, to, value, add(data, 0x20), mload(data), 0, 0)
                    }
                }
                function staticcall(
                    address to,
                    bytes memory data,
                    uint256 txGas
                ) internal view returns (bool success) {
                    assembly ("memory-safe") {
                        success := staticcall(txGas, to, add(data, 0x20), mload(data), 0, 0)
                    }
                }
                function delegateCall(
                    address to,
                    bytes memory data,
                    uint256 txGas
                ) internal returns (bool success) {
                    assembly ("memory-safe") {
                        success := delegatecall(txGas, to, add(data, 0x20), mload(data), 0, 0)
                    }
                }
                // get returned data from last call or delegateCall
                // maxLen - maximum length of data to return, or zero, for the full length
                function getReturnData(uint256 maxLen) internal pure returns (bytes memory returnData) {
                    assembly ("memory-safe") {
                        let len := returndatasize()
                        if gt(maxLen,0) {
                            if gt(len, maxLen) {
                                len := maxLen
                            }
                        }
                        let ptr := mload(0x40)
                        mstore(0x40, add(ptr, add(len, 0x20)))
                        mstore(ptr, len)
                        returndatacopy(add(ptr, 0x20), 0, len)
                        returnData := ptr
                    }
                }
                // revert with explicit byte array (probably reverted info from call)
                function revertWithData(bytes memory returnData) internal pure {
                    assembly ("memory-safe") {
                        revert(add(returnData, 32), mload(returnData))
                    }
                }
                // Propagate revert data from last call
                function revertWithReturnData() internal pure {
                    revertWithData(getReturnData(0));
                }
            }
            

            File 2 of 2: SingletonPaymasterV8
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.26;
            import { SingletonPaymasterV7 } from "./SingletonPaymasterV7.sol";
            /// @title SingletonPaymasterV8
            /// @author Pimlico (https://github.com/pimlicolabs/singleton-paymaster/blob/main/src/SingletonPaymasterV8.sol)
            /// @author Using Solady (https://github.com/vectorized/solady)
            /// @notice An ERC-4337 Paymaster contract that extends SingletonPaymasterV7 where getHash is 7702 aware.
            /// @dev Inherits from SingletonPaymasterV7
            /// @custom:security-contact [email protected]
            contract SingletonPaymasterV8 is SingletonPaymasterV7 {
                constructor(
                    address _entryPoint,
                    address _owner,
                    address _manager,
                    address[] memory _signers
                )
                    SingletonPaymasterV7(_entryPoint, _owner, _manager, _signers)
                { }
                function _expectedPenaltyGasCost(
                    uint256, /* _actualGasCost */
                    uint256, /* _actualUserOpFeePerGas */
                    uint128, /* postOpGas */
                    uint256, /* preOpGasApproximation */
                    uint256 /* executionGasLimit */
                )
                    public
                    pure
                    override
                    returns (uint256)
                {
                    return 0;
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.26;
            import { PackedUserOperation } from "@account-abstraction-v7/interfaces/PackedUserOperation.sol";
            import { _packValidationData } from "@account-abstraction-v7/core/Helpers.sol";
            import { UserOperationLib } from "@account-abstraction-v7/core/UserOperationLib.sol";
            import { ECDSA } from "@openzeppelin-v5.0.2/contracts/utils/cryptography/ECDSA.sol";
            import { MessageHashUtils } from "@openzeppelin-v5.0.2/contracts/utils/cryptography/MessageHashUtils.sol";
            import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol";
            import { BaseSingletonPaymaster, ERC20PaymasterData, ERC20PostOpContext } from "./base/BaseSingletonPaymaster.sol";
            import { IPaymasterV7 } from "./interfaces/IPaymasterV7.sol";
            import { PostOpMode } from "./interfaces/PostOpMode.sol";
            using UserOperationLib for PackedUserOperation;
            /// @title SingletonPaymasterV7
            /// @author Pimlico (https://github.com/pimlicolabs/singleton-paymaster/blob/main/src/SingletonPaymasterV7.sol)
            /// @author Using Solady (https://github.com/vectorized/solady)
            /// @notice An ERC-4337 Paymaster contract which supports two modes, Verifying and ERC-20.
            /// In ERC-20 mode, the paymaster sponsors a UserOperation in exchange for tokens.
            /// In Verifying mode, the paymaster sponsors a UserOperation and deducts prepaid balance from the user's Pimlico
            /// balance.
            /// @dev Inherits from BaseSingletonPaymaster.
            /// @custom:security-contact [email protected]
            contract SingletonPaymasterV7 is BaseSingletonPaymaster, IPaymasterV7 {
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                  CONSTANTS AND IMMUTABLES                  */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                uint256 private immutable PAYMASTER_DATA_OFFSET = UserOperationLib.PAYMASTER_DATA_OFFSET;
                uint256 private immutable PAYMASTER_VALIDATION_GAS_OFFSET = UserOperationLib.PAYMASTER_VALIDATION_GAS_OFFSET;
                uint256 private constant PENALTY_PERCENT = 10;
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                        CONSTRUCTOR                         */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                constructor(
                    address _entryPoint,
                    address _owner,
                    address _manager,
                    address[] memory _signers
                )
                    BaseSingletonPaymaster(_entryPoint, _owner, _manager, _signers)
                { }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*        ENTRYPOINT V0.7 ERC-4337 PAYMASTER OVERRIDES        */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @inheritdoc IPaymasterV7
                function validatePaymasterUserOp(
                    PackedUserOperation calldata userOp,
                    bytes32 userOpHash,
                    uint256 requiredPreFund
                )
                    external
                    override
                    returns (bytes memory context, uint256 validationData)
                {
                    _requireFromEntryPoint();
                    return _validatePaymasterUserOp(userOp, userOpHash, requiredPreFund);
                }
                /// @inheritdoc IPaymasterV7
                function postOp(
                    PostOpMode mode,
                    bytes calldata context,
                    uint256 actualGasCost,
                    uint256 actualUserOpFeePerGas
                )
                    external
                    override
                {
                    _requireFromEntryPoint();
                    _postOp(mode, context, actualGasCost, actualUserOpFeePerGas);
                }
                /**
                 * @notice Internal helper to parse and validate the userOperation's paymasterAndData.
                 * @param _userOp The userOperation.
                 * @param _userOpHash The userOperation hash.
                 * @return (context, validationData) The context and validation data to return to the EntryPoint.
                 *
                 * @dev paymasterAndData for mode 0:
                 * - paymaster address (20 bytes)
                 * - paymaster verification gas (16 bytes)
                 * - paymaster postop gas (16 bytes)
                 * - mode and allowAllBundlers (1 byte) - lowest bit represents allowAllBundlers, rest of the bits represent mode
                 * - validUntil (6 bytes)
                 * - validAfter (6 bytes)
                 * - signature (64 or 65 bytes)
                 *
                 * @dev paymasterAndData for mode 1:
                 * - paymaster address (20 bytes)
                 * - paymaster verification gas (16 bytes)
                 * - paymaster postop gas (16 bytes)
                 * - mode and allowAllBundlers (1 byte) - lowest bit represents allowAllBundlers, rest of the bits represent mode
                 * - constantFeePresent and recipientPresent and preFundPresent (1 byte) - 00000{preFundPresent
                 * bit}{recipientPresent bit}{constantFeePresent bit}
                 * - validUntil (6 bytes)
                 * - validAfter (6 bytes)
                 * - token address (20 bytes)
                 * - postOpGas (16 bytes)
                 * - exchangeRate (32 bytes)
                 * - paymasterValidationGasLimit (16 bytes)
                 * - treasury (20 bytes)
                 * - preFund (16 bytes) - only if preFundPresent is 1
                 * - constantFee (16 bytes - only if constantFeePresent is 1)
                 * - recipient (20 bytes - only if recipientPresent is 1)
                 * - signature (64 or 65 bytes)
                 *
                 *
                 */
                function _validatePaymasterUserOp(
                    PackedUserOperation calldata _userOp,
                    bytes32 _userOpHash,
                    uint256 _requiredPreFund
                )
                    internal
                    returns (bytes memory, uint256)
                {
                    (uint8 mode, bool allowAllBundlers, bytes calldata paymasterConfig) =
                        _parsePaymasterAndData(_userOp.paymasterAndData, PAYMASTER_DATA_OFFSET);
                    if (!allowAllBundlers && !isBundlerAllowed[tx.origin]) {
                        revert BundlerNotAllowed(tx.origin);
                    }
                    if (mode != ERC20_MODE && mode != VERIFYING_MODE) {
                        revert PaymasterModeInvalid();
                    }
                    bytes memory context;
                    uint256 validationData;
                    if (mode == VERIFYING_MODE) {
                        (context, validationData) = _validateVerifyingMode(_userOp, paymasterConfig, _userOpHash);
                    }
                    if (mode == ERC20_MODE) {
                        (context, validationData) =
                            _validateERC20Mode(mode, _userOp, paymasterConfig, _userOpHash, _requiredPreFund);
                    }
                    return (context, validationData);
                }
                /**
                 * @notice Internal helper to validate the paymasterAndData when used in verifying mode.
                 * @param _userOp The userOperation.
                 * @param _paymasterConfig The encoded paymaster config taken from paymasterAndData.
                 * @param _userOpHash The userOperation hash.
                 * @return (context, validationData) The validation data to return to the EntryPoint.
                 */
                function _validateVerifyingMode(
                    PackedUserOperation calldata _userOp,
                    bytes calldata _paymasterConfig,
                    bytes32 _userOpHash
                )
                    internal
                    returns (bytes memory, uint256)
                {
                    (uint48 validUntil, uint48 validAfter, bytes calldata signature) = _parseVerifyingConfig(_paymasterConfig);
                    bytes32 hash = MessageHashUtils.toEthSignedMessageHash(getHash(VERIFYING_MODE, _userOp));
                    address recoveredSigner = ECDSA.recover(hash, signature);
                    bool isSignatureValid = signers[recoveredSigner];
                    uint256 validationData = _packValidationData(!isSignatureValid, validUntil, validAfter);
                    emit UserOperationSponsored(_userOpHash, _userOp.getSender(), VERIFYING_MODE, address(0), 0, 0);
                    return ("", validationData);
                }
                /**
                 * @notice Internal helper to validate the paymasterAndData when used in ERC-20 mode.
                 * @param _userOp The userOperation.
                 * @param _paymasterConfig The encoded paymaster config taken from paymasterAndData.
                 * @param _userOpHash The userOperation hash.
                 * @return (context, validationData) The validation data to return to the EntryPoint.
                 */
                function _validateERC20Mode(
                    uint8 _mode,
                    PackedUserOperation calldata _userOp,
                    bytes calldata _paymasterConfig,
                    bytes32 _userOpHash,
                    uint256 _requiredPreFund
                )
                    internal
                    returns (bytes memory, uint256)
                {
                    ERC20PaymasterData memory cfg = _parseErc20Config(_paymasterConfig);
                    bytes32 hash = MessageHashUtils.toEthSignedMessageHash(getHash(_mode, _userOp));
                    address recoveredSigner = ECDSA.recover(hash, cfg.signature);
                    bool isSignatureValid = signers[recoveredSigner];
                    uint256 validationData = _packValidationData(!isSignatureValid, cfg.validUntil, cfg.validAfter);
                    bytes memory context = _createPostOpContext(_userOp, _userOpHash, cfg, _requiredPreFund);
                    if (!isSignatureValid) {
                        return (context, validationData);
                    }
                    uint256 costInToken = getCostInToken(_requiredPreFund, 0, 0, cfg.exchangeRate);
                    if (cfg.preFundInToken > costInToken) {
                        revert PreFundTooHigh();
                    }
                    if (cfg.preFundInToken > 0) {
                        SafeTransferLib.safeTransferFrom(cfg.token, _userOp.sender, cfg.treasury, cfg.preFundInToken);
                    }
                    return (context, validationData);
                }
                function _expectedPenaltyGasCost(
                    uint256 _actualGasCost,
                    uint256 _actualUserOpFeePerGas,
                    uint128 postOpGas,
                    uint256 preOpGasApproximation,
                    uint256 executionGasLimit
                )
                    public
                    pure
                    virtual
                    returns (uint256)
                {
                    uint256 executionGasUsed = 0;
                    uint256 actualGas = _actualGasCost / _actualUserOpFeePerGas + postOpGas;
                    if (actualGas > preOpGasApproximation) {
                        executionGasUsed = actualGas - preOpGasApproximation;
                    }
                    uint256 expectedPenaltyGas = 0;
                    if (executionGasLimit > executionGasUsed) {
                        expectedPenaltyGas = ((executionGasLimit - executionGasUsed) * PENALTY_PERCENT) / 100;
                    }
                    return expectedPenaltyGas * _actualUserOpFeePerGas;
                }
                /**
                 * @notice Handles ERC-20 token payment.
                 * @dev PostOp is skipped in verifying mode because paymaster's postOp isn't called when context is empty.
                 * @param _context The encoded ERC-20 paymaster context.
                 * @param _actualGasCost The totla gas cost (in wei) of this userOperation.
                 * @param _actualUserOpFeePerGas The actual gas price of the userOperation.
                 */
                function _postOp(
                    PostOpMode, /* mode */
                    bytes calldata _context,
                    uint256 _actualGasCost,
                    uint256 _actualUserOpFeePerGas
                )
                    internal
                {
                    ERC20PostOpContext memory ctx = _parsePostOpContext(_context);
                    uint256 expectedPenaltyGasCost = _expectedPenaltyGasCost(
                        _actualGasCost, _actualUserOpFeePerGas, ctx.postOpGas, ctx.preOpGasApproximation, ctx.executionGasLimit
                    );
                    uint256 actualGasCost = _actualGasCost + expectedPenaltyGasCost;
                    uint256 costInToken =
                        getCostInToken(actualGasCost, ctx.postOpGas, _actualUserOpFeePerGas, ctx.exchangeRate) + ctx.constantFee;
                    uint256 absoluteCostInToken =
                        costInToken > ctx.preFundCharged ? costInToken - ctx.preFundCharged : ctx.preFundCharged - costInToken;
                    SafeTransferLib.safeTransferFrom(
                        ctx.token,
                        costInToken > ctx.preFundCharged ? ctx.sender : ctx.treasury,
                        costInToken > ctx.preFundCharged ? ctx.treasury : ctx.sender,
                        absoluteCostInToken
                    );
                    uint256 preFundInToken = (ctx.preFund * ctx.exchangeRate) / 1e18;
                    if (ctx.recipient != address(0) && preFundInToken > costInToken) {
                        SafeTransferLib.safeTransferFrom(ctx.token, ctx.sender, ctx.recipient, preFundInToken - costInToken);
                    }
                    emit UserOperationSponsored(ctx.userOpHash, ctx.sender, ERC20_MODE, ctx.token, costInToken, ctx.exchangeRate);
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                      PUBLIC HELPERS                        */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /**
                 * @notice Hashses the userOperation data when used in ERC-20 mode.
                 * @param _userOp The user operation data.
                 * @param _mode The mode that we want to get the hash for.
                 * @return bytes32 The hash that the signer should sign over.
                 */
                function getHash(uint8 _mode, PackedUserOperation calldata _userOp) public view returns (bytes32) {
                    if (_mode == VERIFYING_MODE) {
                        return _getHash(_userOp, MODE_AND_ALLOW_ALL_BUNDLERS_LENGTH + VERIFYING_PAYMASTER_DATA_LENGTH);
                    } else {
                        uint8 paymasterDataLength = MODE_AND_ALLOW_ALL_BUNDLERS_LENGTH + ERC20_PAYMASTER_DATA_LENGTH;
                        uint8 combinedByte =
                            uint8(_userOp.paymasterAndData[PAYMASTER_DATA_OFFSET + MODE_AND_ALLOW_ALL_BUNDLERS_LENGTH]);
                        // constantFeePresent is in the *lowest* bit
                        bool constantFeePresent = (combinedByte & 0x01) != 0;
                        // recipientPresent is in the second lowest bit
                        bool recipientPresent = (combinedByte & 0x02) != 0;
                        // preFundPresent is in the third lowest bit
                        bool preFundPresent = (combinedByte & 0x04) != 0;
                        if (preFundPresent) {
                            paymasterDataLength += 16;
                        }
                        if (constantFeePresent) {
                            paymasterDataLength += 16;
                        }
                        if (recipientPresent) {
                            paymasterDataLength += 20;
                        }
                        return _getHash(_userOp, paymasterDataLength);
                    }
                }
                /**
                 * @notice Internal helper that hashes the user operation data.
                 * @dev We hash over all fields in paymasterAndData but the paymaster signature.
                 * @param paymasterDataLength The paymasterData length.
                 * @return bytes32 The hash that the signer should sign over.
                 */
                function _getHash(
                    PackedUserOperation calldata _userOp,
                    uint256 paymasterDataLength
                )
                    internal
                    view
                    returns (bytes32)
                {
                    bytes32 userOpHash = keccak256(
                        abi.encode(
                            _userOp.getSender(),
                            _userOp.nonce,
                            _userOp.accountGasLimits,
                            _userOp.preVerificationGas,
                            _userOp.gasFees,
                            keccak256(_userOp.initCode),
                            keccak256(_userOp.callData),
                            // hashing over all paymaster fields besides signature
                            keccak256(_userOp.paymasterAndData[:PAYMASTER_DATA_OFFSET + paymasterDataLength])
                        )
                    );
                    return keccak256(abi.encode(userOpHash, block.chainid));
                }
            }
            // SPDX-License-Identifier: GPL-3.0
            pragma solidity >=0.7.5;
            /**
             * User Operation struct
             * @param sender                - The sender account of this request.
             * @param nonce                 - Unique value the sender uses to verify it is not a replay.
             * @param initCode              - If set, the account contract will be created by this constructor/
             * @param callData              - The method call to execute on this account.
             * @param accountGasLimits      - Packed gas limits for validateUserOp and gas limit passed to the callData method call.
             * @param preVerificationGas    - Gas not calculated by the handleOps method, but added to the gas paid.
             *                                Covers batch overhead.
             * @param gasFees               - packed gas fields maxPriorityFeePerGas and maxFeePerGas - Same as EIP-1559 gas parameters.
             * @param paymasterAndData      - If set, this field holds the paymaster address, verification gas limit, postOp gas limit and paymaster-specific extra data
             *                                The paymaster will pay for the transaction instead of the sender.
             * @param signature             - Sender-verified signature over the entire request, the EntryPoint address and the chain ID.
             */
            struct PackedUserOperation {
                address sender;
                uint256 nonce;
                bytes initCode;
                bytes callData;
                bytes32 accountGasLimits;
                uint256 preVerificationGas;
                bytes32 gasFees;
                bytes paymasterAndData;
                bytes signature;
            }
            // SPDX-License-Identifier: GPL-3.0
            pragma solidity ^0.8.23;
            /* solhint-disable no-inline-assembly */
             /*
              * For simulation purposes, validateUserOp (and validatePaymasterUserOp)
              * must return this value in case of signature failure, instead of revert.
              */
            uint256 constant SIG_VALIDATION_FAILED = 1;
            /*
             * For simulation purposes, validateUserOp (and validatePaymasterUserOp)
             * return this value on success.
             */
            uint256 constant SIG_VALIDATION_SUCCESS = 0;
            /**
             * Returned data from validateUserOp.
             * validateUserOp returns a uint256, which is created by `_packedValidationData` and
             * parsed by `_parseValidationData`.
             * @param aggregator  - address(0) - The account validated the signature by itself.
             *                      address(1) - The account failed to validate the signature.
             *                      otherwise - This is an address of a signature aggregator that must
             *                                  be used to validate the signature.
             * @param validAfter  - This UserOp is valid only after this timestamp.
             * @param validaUntil - This UserOp is valid only up to this timestamp.
             */
            struct ValidationData {
                address aggregator;
                uint48 validAfter;
                uint48 validUntil;
            }
            /**
             * Extract sigFailed, validAfter, validUntil.
             * Also convert zero validUntil to type(uint48).max.
             * @param validationData - The packed validation data.
             */
            function _parseValidationData(
                uint256 validationData
            ) pure returns (ValidationData memory data) {
                address aggregator = address(uint160(validationData));
                uint48 validUntil = uint48(validationData >> 160);
                if (validUntil == 0) {
                    validUntil = type(uint48).max;
                }
                uint48 validAfter = uint48(validationData >> (48 + 160));
                return ValidationData(aggregator, validAfter, validUntil);
            }
            /**
             * Helper to pack the return value for validateUserOp.
             * @param data - The ValidationData to pack.
             */
            function _packValidationData(
                ValidationData memory data
            ) pure returns (uint256) {
                return
                    uint160(data.aggregator) |
                    (uint256(data.validUntil) << 160) |
                    (uint256(data.validAfter) << (160 + 48));
            }
            /**
             * Helper to pack the return value for validateUserOp, when not using an aggregator.
             * @param sigFailed  - True for signature failure, false for success.
             * @param validUntil - Last timestamp this UserOperation is valid (or zero for infinite).
             * @param validAfter - First timestamp this UserOperation is valid.
             */
            function _packValidationData(
                bool sigFailed,
                uint48 validUntil,
                uint48 validAfter
            ) pure returns (uint256) {
                return
                    (sigFailed ? 1 : 0) |
                    (uint256(validUntil) << 160) |
                    (uint256(validAfter) << (160 + 48));
            }
            /**
             * keccak function over calldata.
             * @dev copy calldata into memory, do keccak and drop allocated memory. Strangely, this is more efficient than letting solidity do it.
             */
                function calldataKeccak(bytes calldata data) pure returns (bytes32 ret) {
                    assembly ("memory-safe") {
                        let mem := mload(0x40)
                        let len := data.length
                        calldatacopy(mem, data.offset, len)
                        ret := keccak256(mem, len)
                    }
                }
            /**
             * The minimum of two numbers.
             * @param a - First number.
             * @param b - Second number.
             */
                function min(uint256 a, uint256 b) pure returns (uint256) {
                    return a < b ? a : b;
                }
            // SPDX-License-Identifier: GPL-3.0
            pragma solidity ^0.8.23;
            /* solhint-disable no-inline-assembly */
            import "../interfaces/PackedUserOperation.sol";
            import {calldataKeccak, min} from "./Helpers.sol";
            /**
             * Utility functions helpful when working with UserOperation structs.
             */
            library UserOperationLib {
                uint256 public constant PAYMASTER_VALIDATION_GAS_OFFSET = 20;
                uint256 public constant PAYMASTER_POSTOP_GAS_OFFSET = 36;
                uint256 public constant PAYMASTER_DATA_OFFSET = 52;
                /**
                 * Get sender from user operation data.
                 * @param userOp - The user operation data.
                 */
                function getSender(
                    PackedUserOperation calldata userOp
                ) internal pure returns (address) {
                    address data;
                    //read sender from userOp, which is first userOp member (saves 800 gas...)
                    assembly {
                        data := calldataload(userOp)
                    }
                    return address(uint160(data));
                }
                /**
                 * Relayer/block builder might submit the TX with higher priorityFee,
                 * but the user should not pay above what he signed for.
                 * @param userOp - The user operation data.
                 */
                function gasPrice(
                    PackedUserOperation calldata userOp
                ) internal view returns (uint256) {
                    unchecked {
                        (uint256 maxPriorityFeePerGas, uint256 maxFeePerGas) = unpackUints(userOp.gasFees);
                        if (maxFeePerGas == maxPriorityFeePerGas) {
                            //legacy mode (for networks that don't support basefee opcode)
                            return maxFeePerGas;
                        }
                        return min(maxFeePerGas, maxPriorityFeePerGas + block.basefee);
                    }
                }
                /**
                 * Pack the user operation data into bytes for hashing.
                 * @param userOp - The user operation data.
                 */
                function encode(
                    PackedUserOperation calldata userOp
                ) internal pure returns (bytes memory ret) {
                    address sender = getSender(userOp);
                    uint256 nonce = userOp.nonce;
                    bytes32 hashInitCode = calldataKeccak(userOp.initCode);
                    bytes32 hashCallData = calldataKeccak(userOp.callData);
                    bytes32 accountGasLimits = userOp.accountGasLimits;
                    uint256 preVerificationGas = userOp.preVerificationGas;
                    bytes32 gasFees = userOp.gasFees;
                    bytes32 hashPaymasterAndData = calldataKeccak(userOp.paymasterAndData);
                    return abi.encode(
                        sender, nonce,
                        hashInitCode, hashCallData,
                        accountGasLimits, preVerificationGas, gasFees,
                        hashPaymasterAndData
                    );
                }
                function unpackUints(
                    bytes32 packed
                ) internal pure returns (uint256 high128, uint256 low128) {
                    return (uint128(bytes16(packed)), uint128(uint256(packed)));
                }
                //unpack just the high 128-bits from a packed value
                function unpackHigh128(bytes32 packed) internal pure returns (uint256) {
                    return uint256(packed) >> 128;
                }
                // unpack just the low 128-bits from a packed value
                function unpackLow128(bytes32 packed) internal pure returns (uint256) {
                    return uint128(uint256(packed));
                }
                function unpackMaxPriorityFeePerGas(PackedUserOperation calldata userOp)
                internal pure returns (uint256) {
                    return unpackHigh128(userOp.gasFees);
                }
                function unpackMaxFeePerGas(PackedUserOperation calldata userOp)
                internal pure returns (uint256) {
                    return unpackLow128(userOp.gasFees);
                }
                function unpackVerificationGasLimit(PackedUserOperation calldata userOp)
                internal pure returns (uint256) {
                    return unpackHigh128(userOp.accountGasLimits);
                }
                function unpackCallGasLimit(PackedUserOperation calldata userOp)
                internal pure returns (uint256) {
                    return unpackLow128(userOp.accountGasLimits);
                }
                function unpackPaymasterVerificationGasLimit(PackedUserOperation calldata userOp)
                internal pure returns (uint256) {
                    return uint128(bytes16(userOp.paymasterAndData[PAYMASTER_VALIDATION_GAS_OFFSET : PAYMASTER_POSTOP_GAS_OFFSET]));
                }
                function unpackPostOpGasLimit(PackedUserOperation calldata userOp)
                internal pure returns (uint256) {
                    return uint128(bytes16(userOp.paymasterAndData[PAYMASTER_POSTOP_GAS_OFFSET : PAYMASTER_DATA_OFFSET]));
                }
                function unpackPaymasterStaticFields(
                    bytes calldata paymasterAndData
                ) internal pure returns (address paymaster, uint256 validationGasLimit, uint256 postOpGasLimit) {
                    return (
                        address(bytes20(paymasterAndData[: PAYMASTER_VALIDATION_GAS_OFFSET])),
                        uint128(bytes16(paymasterAndData[PAYMASTER_VALIDATION_GAS_OFFSET : PAYMASTER_POSTOP_GAS_OFFSET])),
                        uint128(bytes16(paymasterAndData[PAYMASTER_POSTOP_GAS_OFFSET : PAYMASTER_DATA_OFFSET]))
                    );
                }
                /**
                 * Hash the user operation data.
                 * @param userOp - The user operation data.
                 */
                function hash(
                    PackedUserOperation calldata userOp
                ) internal pure returns (bytes32) {
                    return keccak256(encode(userOp));
                }
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/ECDSA.sol)
            pragma solidity ^0.8.20;
            /**
             * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
             *
             * These functions can be used to verify that a message was signed by the holder
             * of the private keys of a given address.
             */
            library ECDSA {
                enum RecoverError {
                    NoError,
                    InvalidSignature,
                    InvalidSignatureLength,
                    InvalidSignatureS
                }
                /**
                 * @dev The signature derives the `address(0)`.
                 */
                error ECDSAInvalidSignature();
                /**
                 * @dev The signature has an invalid length.
                 */
                error ECDSAInvalidSignatureLength(uint256 length);
                /**
                 * @dev The signature has an S value that is in the upper half order.
                 */
                error ECDSAInvalidSignatureS(bytes32 s);
                /**
                 * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
                 * return address(0) without also returning an error description. Errors are documented using an enum (error type)
                 * and a bytes32 providing additional information about the error.
                 *
                 * If no error is returned, then the address can be used for verification purposes.
                 *
                 * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
                 * this function rejects them by requiring the `s` value to be in the lower
                 * half order, and the `v` value to be either 27 or 28.
                 *
                 * IMPORTANT: `hash` _must_ be the result of a hash operation for the
                 * verification to be secure: it is possible to craft signatures that
                 * recover to arbitrary addresses for non-hashed data. A safe way to ensure
                 * this is by receiving a hash of the original message (which may otherwise
                 * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
                 *
                 * Documentation for signature generation:
                 * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
                 * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
                 */
                function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) {
                    if (signature.length == 65) {
                        bytes32 r;
                        bytes32 s;
                        uint8 v;
                        // ecrecover takes the signature parameters, and the only way to get them
                        // currently is to use assembly.
                        /// @solidity memory-safe-assembly
                        assembly {
                            r := mload(add(signature, 0x20))
                            s := mload(add(signature, 0x40))
                            v := byte(0, mload(add(signature, 0x60)))
                        }
                        return tryRecover(hash, v, r, s);
                    } else {
                        return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));
                    }
                }
                /**
                 * @dev Returns the address that signed a hashed message (`hash`) with
                 * `signature`. This address can then be used for verification purposes.
                 *
                 * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
                 * this function rejects them by requiring the `s` value to be in the lower
                 * half order, and the `v` value to be either 27 or 28.
                 *
                 * IMPORTANT: `hash` _must_ be the result of a hash operation for the
                 * verification to be secure: it is possible to craft signatures that
                 * recover to arbitrary addresses for non-hashed data. A safe way to ensure
                 * this is by receiving a hash of the original message (which may otherwise
                 * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
                 */
                function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
                    (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
                    _throwError(error, errorArg);
                    return recovered;
                }
                /**
                 * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
                 *
                 * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
                 */
                function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) {
                    unchecked {
                        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
                        // We do not check for an overflow here since the shift operation results in 0 or 1.
                        uint8 v = uint8((uint256(vs) >> 255) + 27);
                        return tryRecover(hash, v, r, s);
                    }
                }
                /**
                 * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
                 */
                function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
                    (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
                    _throwError(error, errorArg);
                    return recovered;
                }
                /**
                 * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
                 * `r` and `s` signature fields separately.
                 */
                function tryRecover(
                    bytes32 hash,
                    uint8 v,
                    bytes32 r,
                    bytes32 s
                ) internal pure returns (address, RecoverError, bytes32) {
                    // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
                    // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
                    // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
                    // signatures from current libraries generate a unique signature with an s-value in the lower half order.
                    //
                    // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
                    // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
                    // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
                    // these malleable signatures as well.
                    if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
                        return (address(0), RecoverError.InvalidSignatureS, s);
                    }
                    // If the signature is valid (and not malleable), return the signer address
                    address signer = ecrecover(hash, v, r, s);
                    if (signer == address(0)) {
                        return (address(0), RecoverError.InvalidSignature, bytes32(0));
                    }
                    return (signer, RecoverError.NoError, bytes32(0));
                }
                /**
                 * @dev Overload of {ECDSA-recover} that receives the `v`,
                 * `r` and `s` signature fields separately.
                 */
                function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
                    (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);
                    _throwError(error, errorArg);
                    return recovered;
                }
                /**
                 * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
                 */
                function _throwError(RecoverError error, bytes32 errorArg) private pure {
                    if (error == RecoverError.NoError) {
                        return; // no error: do nothing
                    } else if (error == RecoverError.InvalidSignature) {
                        revert ECDSAInvalidSignature();
                    } else if (error == RecoverError.InvalidSignatureLength) {
                        revert ECDSAInvalidSignatureLength(uint256(errorArg));
                    } else if (error == RecoverError.InvalidSignatureS) {
                        revert ECDSAInvalidSignatureS(errorArg);
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MessageHashUtils.sol)
            pragma solidity ^0.8.20;
            import {Strings} from "../Strings.sol";
            /**
             * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.
             *
             * The library provides methods for generating a hash of a message that conforms to the
             * https://eips.ethereum.org/EIPS/eip-191[EIP 191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]
             * specifications.
             */
            library MessageHashUtils {
                /**
                 * @dev Returns the keccak256 digest of an EIP-191 signed data with version
                 * `0x45` (`personal_sign` messages).
                 *
                 * The digest is calculated by prefixing a bytes32 `messageHash` with
                 * `"\\x19Ethereum Signed Message:\
            32"` and hashing the result. It corresponds with the
                 * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
                 *
                 * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with
                 * keccak256, although any bytes32 value can be safely used because the final digest will
                 * be re-hashed.
                 *
                 * See {ECDSA-recover}.
                 */
                function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        mstore(0x00, "\\x19Ethereum Signed Message:\
            32") // 32 is the bytes-length of messageHash
                        mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix
                        digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)
                    }
                }
                /**
                 * @dev Returns the keccak256 digest of an EIP-191 signed data with version
                 * `0x45` (`personal_sign` messages).
                 *
                 * The digest is calculated by prefixing an arbitrary `message` with
                 * `"\\x19Ethereum Signed Message:\
            " + len(message)` and hashing the result. It corresponds with the
                 * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
                 *
                 * See {ECDSA-recover}.
                 */
                function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {
                    return
                        keccak256(bytes.concat("\\x19Ethereum Signed Message:\
            ", bytes(Strings.toString(message.length)), message));
                }
                /**
                 * @dev Returns the keccak256 digest of an EIP-191 signed data with version
                 * `0x00` (data with intended validator).
                 *
                 * The digest is calculated by prefixing an arbitrary `data` with `"\\x19\\x00"` and the intended
                 * `validator` address. Then hashing the result.
                 *
                 * See {ECDSA-recover}.
                 */
                function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
                    return keccak256(abi.encodePacked(hex"19_00", validator, data));
                }
                /**
                 * @dev Returns the keccak256 digest of an EIP-712 typed data (EIP-191 version `0x01`).
                 *
                 * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with
                 * `\\x19\\x01` and hashing the result. It corresponds to the hash signed by the
                 * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.
                 *
                 * See {ECDSA-recover}.
                 */
                function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let ptr := mload(0x40)
                        mstore(ptr, hex"19_01")
                        mstore(add(ptr, 0x02), domainSeparator)
                        mstore(add(ptr, 0x22), structHash)
                        digest := keccak256(ptr, 0x42)
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.4;
            /// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
            /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol)
            /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
            /// @author Permit2 operations from (https://github.com/Uniswap/permit2/blob/main/src/libraries/Permit2Lib.sol)
            ///
            /// @dev Note:
            /// - For ETH transfers, please use `forceSafeTransferETH` for DoS protection.
            /// - For ERC20s, this implementation won't check that a token has code,
            ///   responsibility is delegated to the caller.
            library SafeTransferLib {
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                       CUSTOM ERRORS                        */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev The ETH transfer has failed.
                error ETHTransferFailed();
                /// @dev The ERC20 `transferFrom` has failed.
                error TransferFromFailed();
                /// @dev The ERC20 `transfer` has failed.
                error TransferFailed();
                /// @dev The ERC20 `approve` has failed.
                error ApproveFailed();
                /// @dev The Permit2 operation has failed.
                error Permit2Failed();
                /// @dev The Permit2 amount must be less than `2**160 - 1`.
                error Permit2AmountOverflow();
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                         CONSTANTS                          */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Suggested gas stipend for contract receiving ETH that disallows any storage writes.
                uint256 internal constant GAS_STIPEND_NO_STORAGE_WRITES = 2300;
                /// @dev Suggested gas stipend for contract receiving ETH to perform a few
                /// storage reads and writes, but low enough to prevent griefing.
                uint256 internal constant GAS_STIPEND_NO_GRIEF = 100000;
                /// @dev The unique EIP-712 domain domain separator for the DAI token contract.
                bytes32 internal constant DAI_DOMAIN_SEPARATOR =
                    0xdbb8cf42e1ecb028be3f3dbc922e1d878b963f411dc388ced501601c60f7c6f7;
                /// @dev The address for the WETH9 contract on Ethereum mainnet.
                address internal constant WETH9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
                /// @dev The canonical Permit2 address.
                /// [Github](https://github.com/Uniswap/permit2)
                /// [Etherscan](https://etherscan.io/address/0x000000000022D473030F116dDEE9F6B43aC78BA3)
                address internal constant PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                       ETH OPERATIONS                       */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                // If the ETH transfer MUST succeed with a reasonable gas budget, use the force variants.
                //
                // The regular variants:
                // - Forwards all remaining gas to the target.
                // - Reverts if the target reverts.
                // - Reverts if the current contract has insufficient balance.
                //
                // The force variants:
                // - Forwards with an optional gas stipend
                //   (defaults to `GAS_STIPEND_NO_GRIEF`, which is sufficient for most cases).
                // - If the target reverts, or if the gas stipend is exhausted,
                //   creates a temporary contract to force send the ETH via `SELFDESTRUCT`.
                //   Future compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758.
                // - Reverts if the current contract has insufficient balance.
                //
                // The try variants:
                // - Forwards with a mandatory gas stipend.
                // - Instead of reverting, returns whether the transfer succeeded.
                /// @dev Sends `amount` (in wei) ETH to `to`.
                function safeTransferETH(address to, uint256 amount) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if iszero(call(gas(), to, amount, codesize(), 0x00, codesize(), 0x00)) {
                            mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                    }
                }
                /// @dev Sends all the ETH in the current contract to `to`.
                function safeTransferAllETH(address to) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // Transfer all the ETH and check if it succeeded or not.
                        if iszero(call(gas(), to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
                            mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                    }
                }
                /// @dev Force sends `amount` (in wei) ETH to `to`, with a `gasStipend`.
                function forceSafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if lt(selfbalance(), amount) {
                            mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                        if iszero(call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)) {
                            mstore(0x00, to) // Store the address in scratch space.
                            mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                            mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                            if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
                        }
                    }
                }
                /// @dev Force sends all the ETH in the current contract to `to`, with a `gasStipend`.
                function forceSafeTransferAllETH(address to, uint256 gasStipend) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if iszero(call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
                            mstore(0x00, to) // Store the address in scratch space.
                            mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                            mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                            if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
                        }
                    }
                }
                /// @dev Force sends `amount` (in wei) ETH to `to`, with `GAS_STIPEND_NO_GRIEF`.
                function forceSafeTransferETH(address to, uint256 amount) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        if lt(selfbalance(), amount) {
                            mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                        if iszero(call(GAS_STIPEND_NO_GRIEF, to, amount, codesize(), 0x00, codesize(), 0x00)) {
                            mstore(0x00, to) // Store the address in scratch space.
                            mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                            mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                            if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
                        }
                    }
                }
                /// @dev Force sends all the ETH in the current contract to `to`, with `GAS_STIPEND_NO_GRIEF`.
                function forceSafeTransferAllETH(address to) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        // forgefmt: disable-next-item
                        if iszero(call(GAS_STIPEND_NO_GRIEF, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
                            mstore(0x00, to) // Store the address in scratch space.
                            mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                            mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                            if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
                        }
                    }
                }
                /// @dev Sends `amount` (in wei) ETH to `to`, with a `gasStipend`.
                function trySafeTransferETH(address to, uint256 amount, uint256 gasStipend)
                    internal
                    returns (bool success)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        success := call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)
                    }
                }
                /// @dev Sends all the ETH in the current contract to `to`, with a `gasStipend`.
                function trySafeTransferAllETH(address to, uint256 gasStipend)
                    internal
                    returns (bool success)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        success := call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)
                    }
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                      ERC20 OPERATIONS                      */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
                /// Reverts upon failure.
                ///
                /// The `from` account must have at least `amount` approved for
                /// the current contract to manage.
                function safeTransferFrom(address token, address from, address to, uint256 amount) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let m := mload(0x40) // Cache the free memory pointer.
                        mstore(0x60, amount) // Store the `amount` argument.
                        mstore(0x40, to) // Store the `to` argument.
                        mstore(0x2c, shl(96, from)) // Store the `from` argument.
                        mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`.
                        // Perform the transfer, reverting upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
                            )
                        ) {
                            mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x60, 0) // Restore the zero slot to zero.
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
                ///
                /// The `from` account must have at least `amount` approved for the current contract to manage.
                function trySafeTransferFrom(address token, address from, address to, uint256 amount)
                    internal
                    returns (bool success)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let m := mload(0x40) // Cache the free memory pointer.
                        mstore(0x60, amount) // Store the `amount` argument.
                        mstore(0x40, to) // Store the `to` argument.
                        mstore(0x2c, shl(96, from)) // Store the `from` argument.
                        mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`.
                        success :=
                            and( // The arguments of `and` are evaluated from right to left.
                                or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
                            )
                        mstore(0x60, 0) // Restore the zero slot to zero.
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /// @dev Sends all of ERC20 `token` from `from` to `to`.
                /// Reverts upon failure.
                ///
                /// The `from` account must have their entire balance approved for the current contract to manage.
                function safeTransferAllFrom(address token, address from, address to)
                    internal
                    returns (uint256 amount)
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let m := mload(0x40) // Cache the free memory pointer.
                        mstore(0x40, to) // Store the `to` argument.
                        mstore(0x2c, shl(96, from)) // Store the `from` argument.
                        mstore(0x0c, 0x70a08231000000000000000000000000) // `balanceOf(address)`.
                        // Read the balance, reverting upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                gt(returndatasize(), 0x1f), // At least 32 bytes returned.
                                staticcall(gas(), token, 0x1c, 0x24, 0x60, 0x20)
                            )
                        ) {
                            mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x00, 0x23b872dd) // `transferFrom(address,address,uint256)`.
                        amount := mload(0x60) // The `amount` is already at 0x60. We'll need to return it.
                        // Perform the transfer, reverting upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
                            )
                        ) {
                            mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x60, 0) // Restore the zero slot to zero.
                        mstore(0x40, m) // Restore the free memory pointer.
                    }
                }
                /// @dev Sends `amount` of ERC20 `token` from the current contract to `to`.
                /// Reverts upon failure.
                function safeTransfer(address token, address to, uint256 amount) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        mstore(0x14, to) // Store the `to` argument.
                        mstore(0x34, amount) // Store the `amount` argument.
                        mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.
                        // Perform the transfer, reverting upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                            )
                        ) {
                            mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
                    }
                }
                /// @dev Sends all of ERC20 `token` from the current contract to `to`.
                /// Reverts upon failure.
                function safeTransferAll(address token, address to) internal returns (uint256 amount) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        mstore(0x00, 0x70a08231) // Store the function selector of `balanceOf(address)`.
                        mstore(0x20, address()) // Store the address of the current contract.
                        // Read the balance, reverting upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                gt(returndatasize(), 0x1f), // At least 32 bytes returned.
                                staticcall(gas(), token, 0x1c, 0x24, 0x34, 0x20)
                            )
                        ) {
                            mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x14, to) // Store the `to` argument.
                        amount := mload(0x34) // The `amount` is already at 0x34. We'll need to return it.
                        mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.
                        // Perform the transfer, reverting upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                            )
                        ) {
                            mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
                    }
                }
                /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.
                /// Reverts upon failure.
                function safeApprove(address token, address to, uint256 amount) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        mstore(0x14, to) // Store the `to` argument.
                        mstore(0x34, amount) // Store the `amount` argument.
                        mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
                        // Perform the approval, reverting upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                            )
                        ) {
                            mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.
                            revert(0x1c, 0x04)
                        }
                        mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
                    }
                }
                /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.
                /// If the initial attempt to approve fails, attempts to reset the approved amount to zero,
                /// then retries the approval again (some tokens, e.g. USDT, requires this).
                /// Reverts upon failure.
                function safeApproveWithRetry(address token, address to, uint256 amount) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        mstore(0x14, to) // Store the `to` argument.
                        mstore(0x34, amount) // Store the `amount` argument.
                        mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
                        // Perform the approval, retrying upon failure.
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                            )
                        ) {
                            mstore(0x34, 0) // Store 0 for the `amount`.
                            mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
                            pop(call(gas(), token, 0, 0x10, 0x44, codesize(), 0x00)) // Reset the approval.
                            mstore(0x34, amount) // Store back the original `amount`.
                            // Retry the approval, reverting upon failure.
                            if iszero(
                                and(
                                    or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                                    call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                                )
                            ) {
                                mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.
                                revert(0x1c, 0x04)
                            }
                        }
                        mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
                    }
                }
                /// @dev Returns the amount of ERC20 `token` owned by `account`.
                /// Returns zero if the `token` does not exist.
                function balanceOf(address token, address account) internal view returns (uint256 amount) {
                    /// @solidity memory-safe-assembly
                    assembly {
                        mstore(0x14, account) // Store the `account` argument.
                        mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`.
                        amount :=
                            mul( // The arguments of `mul` are evaluated from right to left.
                                mload(0x20),
                                and( // The arguments of `and` are evaluated from right to left.
                                    gt(returndatasize(), 0x1f), // At least 32 bytes returned.
                                    staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20)
                                )
                            )
                    }
                }
                /// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
                /// If the initial attempt fails, try to use Permit2 to transfer the token.
                /// Reverts upon failure.
                ///
                /// The `from` account must have at least `amount` approved for the current contract to manage.
                function safeTransferFrom2(address token, address from, address to, uint256 amount) internal {
                    if (!trySafeTransferFrom(token, from, to, amount)) {
                        permit2TransferFrom(token, from, to, amount);
                    }
                }
                /// @dev Sends `amount` of ERC20 `token` from `from` to `to` via Permit2.
                /// Reverts upon failure.
                function permit2TransferFrom(address token, address from, address to, uint256 amount)
                    internal
                {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let m := mload(0x40)
                        mstore(add(m, 0x74), shr(96, shl(96, token)))
                        mstore(add(m, 0x54), amount)
                        mstore(add(m, 0x34), to)
                        mstore(add(m, 0x20), shl(96, from))
                        // `transferFrom(address,address,uint160,address)`.
                        mstore(m, 0x36c78516000000000000000000000000)
                        let p := PERMIT2
                        let exists := eq(chainid(), 1)
                        if iszero(exists) { exists := iszero(iszero(extcodesize(p))) }
                        if iszero(and(call(gas(), p, 0, add(m, 0x10), 0x84, codesize(), 0x00), exists)) {
                            mstore(0x00, 0x7939f4248757f0fd) // `TransferFromFailed()` or `Permit2AmountOverflow()`.
                            revert(add(0x18, shl(2, iszero(iszero(shr(160, amount))))), 0x04)
                        }
                    }
                }
                /// @dev Permit a user to spend a given amount of
                /// another user's tokens via native EIP-2612 permit if possible, falling
                /// back to Permit2 if native permit fails or is not implemented on the token.
                function permit2(
                    address token,
                    address owner,
                    address spender,
                    uint256 amount,
                    uint256 deadline,
                    uint8 v,
                    bytes32 r,
                    bytes32 s
                ) internal {
                    bool success;
                    /// @solidity memory-safe-assembly
                    assembly {
                        for {} shl(96, xor(token, WETH9)) {} {
                            mstore(0x00, 0x3644e515) // `DOMAIN_SEPARATOR()`.
                            if iszero(
                                and( // The arguments of `and` are evaluated from right to left.
                                    lt(iszero(mload(0x00)), eq(returndatasize(), 0x20)), // Returns 1 non-zero word.
                                    // Gas stipend to limit gas burn for tokens that don't refund gas when
                                    // an non-existing function is called. 5K should be enough for a SLOAD.
                                    staticcall(5000, token, 0x1c, 0x04, 0x00, 0x20)
                                )
                            ) { break }
                            // After here, we can be sure that token is a contract.
                            let m := mload(0x40)
                            mstore(add(m, 0x34), spender)
                            mstore(add(m, 0x20), shl(96, owner))
                            mstore(add(m, 0x74), deadline)
                            if eq(mload(0x00), DAI_DOMAIN_SEPARATOR) {
                                mstore(0x14, owner)
                                mstore(0x00, 0x7ecebe00000000000000000000000000) // `nonces(address)`.
                                mstore(add(m, 0x94), staticcall(gas(), token, 0x10, 0x24, add(m, 0x54), 0x20))
                                mstore(m, 0x8fcbaf0c000000000000000000000000) // `IDAIPermit.permit`.
                                // `nonces` is already at `add(m, 0x54)`.
                                // `1` is already stored at `add(m, 0x94)`.
                                mstore(add(m, 0xb4), and(0xff, v))
                                mstore(add(m, 0xd4), r)
                                mstore(add(m, 0xf4), s)
                                success := call(gas(), token, 0, add(m, 0x10), 0x104, codesize(), 0x00)
                                break
                            }
                            mstore(m, 0xd505accf000000000000000000000000) // `IERC20Permit.permit`.
                            mstore(add(m, 0x54), amount)
                            mstore(add(m, 0x94), and(0xff, v))
                            mstore(add(m, 0xb4), r)
                            mstore(add(m, 0xd4), s)
                            success := call(gas(), token, 0, add(m, 0x10), 0xe4, codesize(), 0x00)
                            break
                        }
                    }
                    if (!success) simplePermit2(token, owner, spender, amount, deadline, v, r, s);
                }
                /// @dev Simple permit on the Permit2 contract.
                function simplePermit2(
                    address token,
                    address owner,
                    address spender,
                    uint256 amount,
                    uint256 deadline,
                    uint8 v,
                    bytes32 r,
                    bytes32 s
                ) internal {
                    /// @solidity memory-safe-assembly
                    assembly {
                        let m := mload(0x40)
                        mstore(m, 0x927da105) // `allowance(address,address,address)`.
                        {
                            let addressMask := shr(96, not(0))
                            mstore(add(m, 0x20), and(addressMask, owner))
                            mstore(add(m, 0x40), and(addressMask, token))
                            mstore(add(m, 0x60), and(addressMask, spender))
                            mstore(add(m, 0xc0), and(addressMask, spender))
                        }
                        let p := mul(PERMIT2, iszero(shr(160, amount)))
                        if iszero(
                            and( // The arguments of `and` are evaluated from right to left.
                                gt(returndatasize(), 0x5f), // Returns 3 words: `amount`, `expiration`, `nonce`.
                                staticcall(gas(), p, add(m, 0x1c), 0x64, add(m, 0x60), 0x60)
                            )
                        ) {
                            mstore(0x00, 0x6b836e6b8757f0fd) // `Permit2Failed()` or `Permit2AmountOverflow()`.
                            revert(add(0x18, shl(2, iszero(p))), 0x04)
                        }
                        mstore(m, 0x2b67b570) // `Permit2.permit` (PermitSingle variant).
                        // `owner` is already `add(m, 0x20)`.
                        // `token` is already at `add(m, 0x40)`.
                        mstore(add(m, 0x60), amount)
                        mstore(add(m, 0x80), 0xffffffffffff) // `expiration = type(uint48).max`.
                        // `nonce` is already at `add(m, 0xa0)`.
                        // `spender` is already at `add(m, 0xc0)`.
                        mstore(add(m, 0xe0), deadline)
                        mstore(add(m, 0x100), 0x100) // `signature` offset.
                        mstore(add(m, 0x120), 0x41) // `signature` length.
                        mstore(add(m, 0x140), r)
                        mstore(add(m, 0x160), s)
                        mstore(add(m, 0x180), shl(248, v))
                        if iszero(call(gas(), p, 0, add(m, 0x1c), 0x184, codesize(), 0x00)) {
                            mstore(0x00, 0x6b836e6b) // `Permit2Failed()`.
                            revert(0x1c, 0x04)
                        }
                    }
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            /* solhint-disable reason-string */
            import { BasePaymaster } from "./BasePaymaster.sol";
            import { MultiSigner } from "./MultiSigner.sol";
            import { UserOperation } from "@account-abstraction-v6/interfaces/IPaymaster.sol";
            import { UserOperationLib } from "@account-abstraction-v7/core/UserOperationLib.sol";
            import { PackedUserOperation } from "@account-abstraction-v7/interfaces/PackedUserOperation.sol";
            import { ManagerAccessControl } from "./ManagerAccessControl.sol";
            using UserOperationLib for PackedUserOperation;
            /// @notice Holds all context needed during the EntryPoint's postOp call.
            struct ERC20PostOpContext {
                /// @dev The userOperation sender.
                address sender;
                /// @dev The token used to pay for gas sponsorship.
                address token;
                /// @dev The treasury address where the tokens will be sent to.
                address treasury;
                /// @dev The exchange rate between the token and the chain's native currency.
                uint256 exchangeRate;
                /// @dev The gas overhead when performing the transferFrom call.
                uint128 postOpGas;
                /// @dev The userOperation hash.
                bytes32 userOpHash;
                /// @dev The userOperation's maxFeePerGas (v0.6 only)
                uint256 maxFeePerGas;
                /// @dev The userOperation's maxPriorityFeePerGas (v0.6 only)
                uint256 maxPriorityFeePerGas;
                /// @dev The pre fund of the userOperation.
                uint256 preFund;
                /// @dev The pre fund of the userOperation that was charged.
                uint256 preFundCharged;
                /// @dev The total allowed execution gas limit, i.e the sum of the callGasLimit and postOpGasLimit.
                uint256 executionGasLimit;
                /// @dev Estimate of the gas used before the userOp is executed.
                uint256 preOpGasApproximation;
                /// @dev A constant fee that is added to the userOp's gas cost.
                uint128 constantFee;
                /// @dev The recipient of the tokens.
                address recipient;
            }
            /// @notice Hold all configs needed in ERC-20 mode.
            struct ERC20PaymasterData {
                /// @dev The treasury address where the tokens will be sent to.
                address treasury;
                /// @dev Timestamp until which the sponsorship is valid.
                uint48 validUntil;
                /// @dev Timestamp after which the sponsorship is valid.
                uint48 validAfter;
                /// @dev The gas overhead of calling transferFrom during the postOp.
                uint128 postOpGas;
                /// @dev ERC-20 token that the sender will pay with.
                address token;
                /// @dev The exchange rate of the ERC-20 token during sponsorship.
                uint256 exchangeRate;
                /// @dev The paymaster signature.
                bytes signature;
                /// @dev The paymasterValidationGasLimit to be used in the postOp.
                uint128 paymasterValidationGasLimit;
                /// @dev The preFund of the userOperation.
                uint256 preFundInToken;
                /// @dev A constant fee that is added to the userOp's gas cost.
                uint128 constantFee;
                /// @dev The recipient of the tokens.
                address recipient;
            }
            /// @title BaseSingletonPaymaster
            /// @author Pimlico (https://github.com/pimlicolabs/singleton-paymaster/blob/main/src/base/BaseSingletonPaymaster.sol)
            /// @notice Helper class for creating a singleton paymaster.
            /// @dev Inherits from BasePaymaster.
            /// @dev Inherits from MultiSigner.
            abstract contract BaseSingletonPaymaster is ManagerAccessControl, BasePaymaster, MultiSigner {
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                       CUSTOM ERRORS                        */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @notice The paymaster data length is invalid.
                error PaymasterAndDataLengthInvalid();
                /// @notice The paymaster data mode is invalid. The mode should be 0 or 1.
                error PaymasterModeInvalid();
                /// @notice The paymaster data length is invalid for the selected mode.
                error PaymasterConfigLengthInvalid();
                /// @notice The paymaster signature length is invalid.
                error PaymasterSignatureLengthInvalid();
                /// @notice The token is invalid.
                error TokenAddressInvalid();
                /// @notice The token exchange rate is invalid.
                error ExchangeRateInvalid();
                /// @notice The recipient is invalid.
                error RecipientInvalid();
                /// @notice The payment failed due to the TransferFrom call in the PostOp reverting.
                /// @dev We need to throw with params due to this bug in EntryPoint v0.6:
                /// https://github.com/eth-infinitism/account-abstraction/pull/293
                error PostOpTransferFromFailed(string msg);
                /// @notice The preFund is too high.
                error PreFundTooHigh();
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                           EVENTS                           */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @dev Emitted when a user operation is sponsored by the paymaster.
                event UserOperationSponsored(
                    bytes32 indexed userOpHash,
                    /// @param The user that requested sponsorship.
                    address indexed user,
                    /// @param The paymaster mode that was used.
                    uint8 paymasterMode,
                    /// @param The token that was used during sponsorship (ERC-20 mode only).
                    address token,
                    /// @param The amount of token paid during sponsorship (ERC-20 mode only).
                    uint256 tokenAmountPaid,
                    /// @param The exchange rate of the token at time of sponsorship (ERC-20 mode only).
                    uint256 exchangeRate
                );
                /// @notice Event for changing a bundler allowlist configuration
                ///
                /// @param bundler Address of the bundler
                /// @param allowed True if was allowlisted, false if removed from allowlist
                event BundlerAllowlistUpdated(address bundler, bool allowed);
                /// @notice Error for bundler not allowed
                ///
                /// @param bundler address of the bundler that was not allowlisted
                error BundlerNotAllowed(address bundler);
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                  CONSTANTS AND IMMUTABLES                  */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @notice Mode indicating that the Paymaster is in Verifying mode.
                uint8 immutable VERIFYING_MODE = 0;
                /// @notice Mode indicating that the Paymaster is in ERC-20 mode.
                uint8 immutable ERC20_MODE = 1;
                /// @notice The length of the mode and allowAllBundlers bytes.
                uint8 immutable MODE_AND_ALLOW_ALL_BUNDLERS_LENGTH = 1;
                /// @notice The length of the ERC-20 config without singature.
                uint8 immutable ERC20_PAYMASTER_DATA_LENGTH = 117;
                /// @notice The length of the verfiying config without singature.
                uint8 immutable VERIFYING_PAYMASTER_DATA_LENGTH = 12; // 12
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                          STORAGE                           */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @notice Allowlist of bundlers to use if restricting bundlers is enabled by flag
                mapping(address bundler => bool allowed) public isBundlerAllowed;
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                        CONSTRUCTOR                         */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /**
                 * @notice Initializes a SingletonPaymaster instance.
                 * @param _entryPoint The entryPoint address.
                 * @param _owner The initial contract owner.
                 */
                constructor(
                    address _entryPoint,
                    address _owner,
                    address _manager,
                    address[] memory _signers
                )
                    BasePaymaster(_entryPoint, _owner, _manager)
                    MultiSigner(_signers)
                { }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                      ADMIN FUNCTIONS                       */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @notice Add or remove multiple bundlers to/from the allowlist
                ///
                /// @param bundlers Array of bundler addresses
                /// @param allowed Boolean indicating if bundlers should be allowed or not
                function updateBundlerAllowlist(address[] calldata bundlers, bool allowed) external onlyAdminOrManager {
                    for (uint256 i = 0; i < bundlers.length; i++) {
                        isBundlerAllowed[bundlers[i]] = allowed;
                        emit BundlerAllowlistUpdated(bundlers[i], allowed);
                    }
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                      INTERNAL HELPERS                      */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /**
                 * @notice Parses the userOperation's paymasterAndData field and returns the paymaster mode and encoded paymaster
                 * configuration bytes.
                 * @dev _paymasterDataOffset should have value 20 for V6 and 52 for V7.
                 * @param _paymasterAndData The paymasterAndData to parse.
                 * @param _paymasterDataOffset The paymasterData offset in paymasterAndData.
                 * @return mode The paymaster mode.
                 * @return paymasterConfig The paymaster config bytes.
                 */
                function _parsePaymasterAndData(
                    bytes calldata _paymasterAndData,
                    uint256 _paymasterDataOffset
                )
                    internal
                    pure
                    returns (uint8, bool, bytes calldata)
                {
                    if (_paymasterAndData.length < _paymasterDataOffset + 1) {
                        revert PaymasterAndDataLengthInvalid();
                    }
                    uint8 combinedByte = uint8(_paymasterAndData[_paymasterDataOffset]);
                    // allowAllBundlers is in the *lowest* bit
                    bool allowAllBundlers = (combinedByte & 0x01) != 0;
                    // rest of the bits represent the mode
                    uint8 mode = uint8((combinedByte >> 1));
                    bytes calldata paymasterConfig = _paymasterAndData[_paymasterDataOffset + 1:];
                    return (mode, allowAllBundlers, paymasterConfig);
                }
                /**
                 * @notice Parses the paymaster configuration when used in ERC-20 mode.
                 * @param _paymasterConfig The paymaster configuration in bytes.
                 * @return config The parsed paymaster configuration values.
                 */
                function _parseErc20Config(
                    bytes calldata _paymasterConfig
                )
                    internal
                    pure
                    returns (ERC20PaymasterData memory config)
                {
                    if (_paymasterConfig.length < ERC20_PAYMASTER_DATA_LENGTH) {
                        revert PaymasterConfigLengthInvalid();
                    }
                    uint128 configPointer = 0;
                    uint8 combinedByte = uint8(_paymasterConfig[configPointer]);
                    // constantFeePresent is in the *lowest* bit
                    bool constantFeePresent = (combinedByte & 0x01) != 0;
                    // recipientPresent is in the second lowest bit
                    bool recipientPresent = (combinedByte & 0x02) != 0;
                    // preFundPresent is in the third lowest bit
                    bool preFundPresent = (combinedByte & 0x04) != 0;
                    configPointer += 1;
                    config.validUntil = uint48(bytes6(_paymasterConfig[configPointer:configPointer + 6])); // 6 bytes
                    configPointer += 6;
                    config.validAfter = uint48(bytes6(_paymasterConfig[configPointer:configPointer + 6])); // 6 bytes
                    configPointer += 6;
                    config.token = address(bytes20(_paymasterConfig[configPointer:configPointer + 20])); // 20 bytes
                    configPointer += 20;
                    config.postOpGas = uint128(bytes16(_paymasterConfig[configPointer:configPointer + 16])); // 16 bytes
                    configPointer += 16;
                    config.exchangeRate = uint256(bytes32(_paymasterConfig[configPointer:configPointer + 32])); // 32 bytes
                    configPointer += 32;
                    config.paymasterValidationGasLimit = uint128(bytes16(_paymasterConfig[configPointer:configPointer + 16])); // 16
                        // bytes
                    configPointer += 16;
                    config.treasury = address(bytes20(_paymasterConfig[configPointer:configPointer + 20])); // 20 bytes
                    configPointer += 20;
                    config.preFundInToken = uint256(0);
                    if (preFundPresent) {
                        if (_paymasterConfig.length < configPointer + 16) {
                            revert PaymasterConfigLengthInvalid();
                        }
                        config.preFundInToken = uint128(bytes16(_paymasterConfig[configPointer:configPointer + 16])); // 16 bytes
                        configPointer += 16;
                    }
                    config.constantFee = uint128(0);
                    if (constantFeePresent) {
                        if (_paymasterConfig.length < configPointer + 16) {
                            revert PaymasterConfigLengthInvalid();
                        }
                        config.constantFee = uint128(bytes16(_paymasterConfig[configPointer:configPointer + 16])); // 16 bytes
                        configPointer += 16;
                    }
                    config.recipient = address(0);
                    if (recipientPresent) {
                        if (_paymasterConfig.length < configPointer + 20) {
                            revert PaymasterConfigLengthInvalid();
                        }
                        config.recipient = address(bytes20(_paymasterConfig[configPointer:configPointer + 20])); // 20 bytes
                        configPointer += 20;
                    }
                    config.signature = _paymasterConfig[configPointer:];
                    if (config.token == address(0)) {
                        revert TokenAddressInvalid();
                    }
                    if (config.exchangeRate == 0) {
                        revert ExchangeRateInvalid();
                    }
                    if (recipientPresent && config.recipient == address(0)) {
                        revert RecipientInvalid();
                    }
                    if (config.signature.length != 64 && config.signature.length != 65) {
                        revert PaymasterSignatureLengthInvalid();
                    }
                    return config;
                }
                /**
                 * @notice Parses the paymaster configuration when used in verifying mode.
                 * @param _paymasterConfig The paymaster configuration in bytes.
                 * @return validUntil The timestamp until which the sponsorship is valid.
                 * @return validAfter The timestamp after which the sponsorship is valid.
                 * @return signature The signature over the hashed sponsorship fields.
                 * @dev The function reverts if the configuration length is invalid or if the signature length is not 64 or 65
                 * bytes.
                 */
                function _parseVerifyingConfig(
                    bytes calldata _paymasterConfig
                )
                    internal
                    pure
                    returns (uint48, uint48, bytes calldata)
                {
                    if (_paymasterConfig.length < VERIFYING_PAYMASTER_DATA_LENGTH) {
                        revert PaymasterConfigLengthInvalid();
                    }
                    uint48 validUntil = uint48(bytes6(_paymasterConfig[0:6]));
                    uint48 validAfter = uint48(bytes6(_paymasterConfig[6:12]));
                    bytes calldata signature = _paymasterConfig[12:];
                    if (signature.length != 64 && signature.length != 65) {
                        revert PaymasterSignatureLengthInvalid();
                    }
                    return (validUntil, validAfter, signature);
                }
                /**
                 * @notice Helper function to encode the postOp context data for V6 userOperations.
                 * @param _userOp The userOperation.
                 * @param _userOpHash The userOperation hash.
                 * @param _cfg The paymaster configuration.
                 * @return bytes memory The encoded context.
                 */
                function _createPostOpContext(
                    UserOperation calldata _userOp,
                    bytes32 _userOpHash,
                    ERC20PaymasterData memory _cfg,
                    uint256 _requiredPreFund
                )
                    internal
                    pure
                    returns (bytes memory)
                {
                    address _token = _cfg.token;
                    uint256 _exchangeRate = _cfg.exchangeRate;
                    uint128 _postOpGas = _cfg.postOpGas;
                    address treasury = _cfg.treasury;
                    uint128 constantFee = _cfg.constantFee;
                    address recipient = _cfg.recipient;
                    return abi.encode(
                        ERC20PostOpContext({
                            sender: _userOp.sender,
                            token: _token,
                            treasury: treasury,
                            exchangeRate: _exchangeRate,
                            postOpGas: _postOpGas,
                            userOpHash: _userOpHash,
                            maxFeePerGas: _userOp.maxFeePerGas,
                            maxPriorityFeePerGas: _userOp.maxPriorityFeePerGas,
                            preOpGasApproximation: uint256(0), // for v0.6 userOperations, we don't need this due to no penalty.
                            executionGasLimit: uint256(0),
                            preFund: _requiredPreFund,
                            preFundCharged: _cfg.preFundInToken,
                            constantFee: constantFee,
                            recipient: recipient
                        })
                    );
                }
                /**
                 * @notice Helper function to encode the postOp context data for V7 userOperations.
                 * @param _userOp The userOperation.
                 * @param _userOpHash The userOperation hash.
                 * @param _cfg The paymaster configuration.
                 * @return bytes memory The encoded context.
                 */
                function _createPostOpContext(
                    PackedUserOperation calldata _userOp,
                    bytes32 _userOpHash,
                    ERC20PaymasterData memory _cfg,
                    uint256 _requiredPreFund
                )
                    internal
                    pure
                    returns (bytes memory)
                {
                    // the limit we have for executing the userOp.
                    uint256 executionGasLimit = _userOp.unpackCallGasLimit() + _userOp.unpackPostOpGasLimit();
                    // the limit we are allowed for everything before the userOp is executed.
                    uint256 preOpGasApproximation = _userOp.preVerificationGas + _userOp.unpackVerificationGasLimit() // VerificationGasLimit
                        // is an overestimation.
                        + _cfg.paymasterValidationGasLimit; // paymasterValidationGasLimit has to be an under estimation to compensate
                        // for
                        // the overestimation.
                    return abi.encode(
                        ERC20PostOpContext({
                            sender: _userOp.sender,
                            token: _cfg.token,
                            treasury: _cfg.treasury,
                            exchangeRate: _cfg.exchangeRate,
                            postOpGas: _cfg.postOpGas,
                            userOpHash: _userOpHash,
                            maxFeePerGas: uint256(0), // for v0.7 userOperations, the gasPrice is passed in the postOp.
                            maxPriorityFeePerGas: uint256(0), // for v0.7 userOperations, the gasPrice is passed in the postOp.
                            executionGasLimit: executionGasLimit,
                            preFund: _requiredPreFund,
                            preFundCharged: _cfg.preFundInToken,
                            preOpGasApproximation: preOpGasApproximation,
                            constantFee: _cfg.constantFee,
                            recipient: _cfg.recipient
                        })
                    );
                }
                function _parsePostOpContext(bytes calldata _context) internal pure returns (ERC20PostOpContext memory ctx) {
                    ctx = abi.decode(_context, (ERC20PostOpContext));
                }
                /**
                 * @notice Gets the cost in amount of tokens.
                 * @param _actualGasCost The gas consumed by the userOperation.
                 * @param _postOpGas The gas overhead of transfering the ERC-20 when making the postOp payment.
                 * @param _actualUserOpFeePerGas The actual gas cost of the userOperation.
                 * @param _exchangeRate The token exchange rate - how many tokens one full ETH (1e18 wei) is worth.
                 * @return uint256 The gasCost in token units.
                 */
                function getCostInToken(
                    uint256 _actualGasCost,
                    uint256 _postOpGas,
                    uint256 _actualUserOpFeePerGas,
                    uint256 _exchangeRate
                )
                    public
                    pure
                    returns (uint256)
                {
                    return ((_actualGasCost + (_postOpGas * _actualUserOpFeePerGas)) * _exchangeRate) / 1e18;
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            import { PackedUserOperation } from "@account-abstraction-v7/core/UserOperationLib.sol";
            import { PostOpMode } from "./PostOpMode.sol";
            /**
             * The interface exposed by a paymaster contract, who agrees to pay the gas for user's operations.
             * A paymaster must hold a stake to cover the required entrypoint stake and also the gas for the transaction.
             */
            interface IPaymasterV7 {
                /**
                 * Payment validation: check if paymaster agrees to pay.
                 * Must verify sender is the entryPoint.
                 * Revert to reject this request.
                 * Note that bundlers will reject this method if it changes the state, unless the paymaster is trusted
                 * (whitelisted).
                 * The paymaster pre-pays using its deposit, and receive back a refund after the postOp method returns.
                 * @param userOp          - The user operation.
                 * @param userOpHash      - Hash of the user's request data.
                 * @param maxCost         - The maximum cost of this transaction (based on maximum gas and gas price from userOp).
                 * @return context        - Value to send to a postOp. Zero length to signify postOp is not required.
                 * @return validationData - Signature and time-range of this operation, encoded the same as the return
                 *                          value of validateUserOperation.
                 *                          <20-byte> sigAuthorizer - 0 for valid signature, 1 to mark signature failure,
                 *                                                    other values are invalid for paymaster.
                 *                          <6-byte> validUntil - last timestamp this operation is valid. 0 for "indefinite"
                 *                          <6-byte> validAfter - first timestamp this operation is valid
                 *                          Note that the validation code cannot use block.timestamp (or block.number) directly.
                 */
                function validatePaymasterUserOp(
                    PackedUserOperation calldata userOp,
                    bytes32 userOpHash,
                    uint256 maxCost
                )
                    external
                    returns (bytes memory context, uint256 validationData);
                /**
                 * Post-operation handler.
                 * Must verify sender is the entryPoint.
                 * @param mode          - Enum with the following options:
                 *                        opSucceeded - User operation succeeded.
                 *                        opReverted  - User op reverted. The paymaster still has to pay for gas.
                 *                        postOpReverted - never passed in a call to postOp().
                 * @param context       - The context value returned by validatePaymasterUserOp
                 * @param actualGasCost - Actual gas used so far (without this postOp call).
                 * @param actualUserOpFeePerGas - the gas price this UserOp pays. This value is based on the UserOp's maxFeePerGas
                 *                        and maxPriorityFee (and basefee)
                 *                        It is not the same as tx.gasprice, which is what the bundler pays.
                 */
                function postOp(
                    PostOpMode mode,
                    bytes calldata context,
                    uint256 actualGasCost,
                    uint256 actualUserOpFeePerGas
                )
                    external;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            enum PostOpMode {
                // User op succeeded.
                opSucceeded,
                // User op reverted. Still has to pay for gas.
                opReverted,
                // Only used internally in the EntryPoint (cleanup after postOp reverts). Never calling paymaster with this value in
                // v7.
                postOpReverted
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)
            pragma solidity ^0.8.20;
            import {Math} from "./math/Math.sol";
            import {SignedMath} from "./math/SignedMath.sol";
            /**
             * @dev String operations.
             */
            library Strings {
                bytes16 private constant HEX_DIGITS = "0123456789abcdef";
                uint8 private constant ADDRESS_LENGTH = 20;
                /**
                 * @dev The `value` string doesn't fit in the specified `length`.
                 */
                error StringsInsufficientHexLength(uint256 value, uint256 length);
                /**
                 * @dev Converts a `uint256` to its ASCII `string` decimal representation.
                 */
                function toString(uint256 value) internal pure returns (string memory) {
                    unchecked {
                        uint256 length = Math.log10(value) + 1;
                        string memory buffer = new string(length);
                        uint256 ptr;
                        /// @solidity memory-safe-assembly
                        assembly {
                            ptr := add(buffer, add(32, length))
                        }
                        while (true) {
                            ptr--;
                            /// @solidity memory-safe-assembly
                            assembly {
                                mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
                            }
                            value /= 10;
                            if (value == 0) break;
                        }
                        return buffer;
                    }
                }
                /**
                 * @dev Converts a `int256` to its ASCII `string` decimal representation.
                 */
                function toStringSigned(int256 value) internal pure returns (string memory) {
                    return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
                }
                /**
                 * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
                 */
                function toHexString(uint256 value) internal pure returns (string memory) {
                    unchecked {
                        return toHexString(value, Math.log256(value) + 1);
                    }
                }
                /**
                 * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
                 */
                function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
                    uint256 localValue = value;
                    bytes memory buffer = new bytes(2 * length + 2);
                    buffer[0] = "0";
                    buffer[1] = "x";
                    for (uint256 i = 2 * length + 1; i > 1; --i) {
                        buffer[i] = HEX_DIGITS[localValue & 0xf];
                        localValue >>= 4;
                    }
                    if (localValue != 0) {
                        revert StringsInsufficientHexLength(value, length);
                    }
                    return string(buffer);
                }
                /**
                 * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
                 * representation.
                 */
                function toHexString(address addr) internal pure returns (string memory) {
                    return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
                }
                /**
                 * @dev Returns true if the two strings are equal.
                 */
                function equal(string memory a, string memory b) internal pure returns (bool) {
                    return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            /* solhint-disable reason-string */
            import { ManagerAccessControl } from "./ManagerAccessControl.sol";
            import { IEntryPoint } from "@account-abstraction-v7/interfaces/IEntryPoint.sol";
            /**
             * Helper class for creating a paymaster.
             * provides helper methods for staking.
             * Validates that the postOp is called only by the entryPoint.
             */
            abstract contract BasePaymaster is ManagerAccessControl {
                IEntryPoint public immutable entryPoint;
                constructor(address _entryPoint, address _owner, address _manager) {
                    entryPoint = IEntryPoint(_entryPoint);
                    _grantRole(DEFAULT_ADMIN_ROLE, _owner);
                    _grantRole(MANAGER_ROLE, _manager);
                }
                /**
                 * Add a deposit for this paymaster, used for paying for transaction fees.
                 */
                function deposit() public payable {
                    entryPoint.depositTo{ value: msg.value }(address(this));
                }
                /**
                 * Withdraw value from the deposit.
                 * @param withdrawAddress - Target to send to.
                 * @param amount          - Amount to withdraw.
                 */
                function withdrawTo(address payable withdrawAddress, uint256 amount) public onlyRole(DEFAULT_ADMIN_ROLE) {
                    entryPoint.withdrawTo(withdrawAddress, amount);
                }
                /**
                 * Add stake for this paymaster.
                 * This method can also carry eth value to add to the current stake.
                 * @param unstakeDelaySec - The unstake delay for this paymaster. Can only be increased.
                 */
                function addStake(uint32 unstakeDelaySec) external payable onlyAdminOrManager {
                    entryPoint.addStake{ value: msg.value }(unstakeDelaySec);
                }
                /**
                 * Return current paymaster's deposit on the entryPoint.
                 */
                function getDeposit() public view returns (uint256) {
                    return entryPoint.balanceOf(address(this));
                }
                /**
                 * Unlock the stake, in order to withdraw it.
                 * The paymaster can't serve requests once unlocked, until it calls addStake again
                 */
                function unlockStake() external onlyAdminOrManager {
                    entryPoint.unlockStake();
                }
                /**
                 * Withdraw the entire paymaster's stake.
                 * stake must be unlocked first (and then wait for the unstakeDelay to be over)
                 * @param withdrawAddress - The address to send withdrawn value.
                 */
                function withdrawStake(address payable withdrawAddress) external onlyRole(DEFAULT_ADMIN_ROLE) {
                    entryPoint.withdrawStake(withdrawAddress);
                }
                /**
                 * Validate the call is made from a valid entrypoint
                 */
                function _requireFromEntryPoint() internal view virtual {
                    require(msg.sender == address(entryPoint), "Sender not EntryPoint");
                }
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            /* solhint-disable reason-string */
            import { ManagerAccessControl } from "./ManagerAccessControl.sol";
            /**
             * Helper class for creating a contract with multiple valid signers.
             */
            abstract contract MultiSigner is ManagerAccessControl {
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                           EVENTS                           */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @notice Emitted when a signer is added.
                event SignerAdded(address signer);
                /// @notice Emitted when a signer is removed.
                event SignerRemoved(address signer);
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                          STORAGE                           */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                /// @notice Mapping of valid signers.
                mapping(address account => bool isValidSigner) public signers;
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                       CONSTRUCTOR                          */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                constructor(address[] memory _initialSigners) {
                    for (uint256 i = 0; i < _initialSigners.length; i++) {
                        signers[_initialSigners[i]] = true;
                    }
                }
                /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
                /*                      ADMIN FUNCTIONS                       */
                /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
                function removeSigner(address _signer) public onlyAdminOrManager {
                    signers[_signer] = false;
                    emit SignerRemoved(_signer);
                }
                function addSigner(address _signer) public onlyAdminOrManager {
                    signers[_signer] = true;
                    emit SignerAdded(_signer);
                }
            }
            // SPDX-License-Identifier: GPL-3.0
            pragma solidity ^0.8.12;
            import "./UserOperation.sol";
            /**
             * the interface exposed by a paymaster contract, who agrees to pay the gas for user's operations.
             * a paymaster must hold a stake to cover the required entrypoint stake and also the gas for the transaction.
             */
            interface IPaymaster {
                enum PostOpMode {
                    opSucceeded, // user op succeeded
                    opReverted, // user op reverted. still has to pay for gas.
                    postOpReverted //user op succeeded, but caused postOp to revert. Now it's a 2nd call, after user's op was deliberately reverted.
                }
                /**
                 * payment validation: check if paymaster agrees to pay.
                 * Must verify sender is the entryPoint.
                 * Revert to reject this request.
                 * Note that bundlers will reject this method if it changes the state, unless the paymaster is trusted (whitelisted)
                 * The paymaster pre-pays using its deposit, and receive back a refund after the postOp method returns.
                 * @param userOp the user operation
                 * @param userOpHash hash of the user's request data.
                 * @param maxCost the maximum cost of this transaction (based on maximum gas and gas price from userOp)
                 * @return context value to send to a postOp
                 *      zero length to signify postOp is not required.
                 * @return validationData signature and time-range of this operation, encoded the same as the return value of validateUserOperation
                 *      <20-byte> sigAuthorizer - 0 for valid signature, 1 to mark signature failure,
                 *         otherwise, an address of an "authorizer" contract.
                 *      <6-byte> validUntil - last timestamp this operation is valid. 0 for "indefinite"
                 *      <6-byte> validAfter - first timestamp this operation is valid
                 *      Note that the validation code cannot use block.timestamp (or block.number) directly.
                 */
                function validatePaymasterUserOp(UserOperation calldata userOp, bytes32 userOpHash, uint256 maxCost)
                external returns (bytes memory context, uint256 validationData);
                /**
                 * post-operation handler.
                 * Must verify sender is the entryPoint
                 * @param mode enum with the following options:
                 *      opSucceeded - user operation succeeded.
                 *      opReverted  - user op reverted. still has to pay for gas.
                 *      postOpReverted - user op succeeded, but caused postOp (in mode=opSucceeded) to revert.
                 *                       Now this is the 2nd call, after user's op was deliberately reverted.
                 * @param context - the context value returned by validatePaymasterUserOp
                 * @param actualGasCost - actual gas used so far (without this postOp call).
                 */
                function postOp(PostOpMode mode, bytes calldata context, uint256 actualGasCost) external;
            }
            // SPDX-License-Identifier: MIT
            pragma solidity ^0.8.0;
            /* solhint-disable reason-string */
            import { AccessControl } from "@openzeppelin-v5.0.2/contracts/access/AccessControl.sol";
            interface IManagerAccessControl {
                function MANAGER_ROLE() external view returns (bytes32);
                error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
            }
            /**
             * Helper class for creating a contract with multiple valid signers.
             */
            abstract contract ManagerAccessControl is AccessControl {
                bytes32 public constant MANAGER_ROLE = keccak256("MANAGER_ROLE");
                modifier onlyAdminOrManager() {
                    if (!hasRole(DEFAULT_ADMIN_ROLE, msg.sender) && !hasRole(ManagerAccessControl.MANAGER_ROLE, msg.sender)) {
                        revert IManagerAccessControl.AccessControlUnauthorizedAccount(msg.sender, ManagerAccessControl.MANAGER_ROLE);
                    }
                    _;
                }
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)
            pragma solidity ^0.8.20;
            /**
             * @dev Standard math utilities missing in the Solidity language.
             */
            library Math {
                /**
                 * @dev Muldiv operation overflow.
                 */
                error MathOverflowedMulDiv();
                enum Rounding {
                    Floor, // Toward negative infinity
                    Ceil, // Toward positive infinity
                    Trunc, // Toward zero
                    Expand // Away from zero
                }
                /**
                 * @dev Returns the addition of two unsigned integers, with an overflow flag.
                 */
                function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
                    unchecked {
                        uint256 c = a + b;
                        if (c < a) return (false, 0);
                        return (true, c);
                    }
                }
                /**
                 * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
                 */
                function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
                    unchecked {
                        if (b > a) return (false, 0);
                        return (true, a - b);
                    }
                }
                /**
                 * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
                 */
                function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
                    unchecked {
                        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
                        // benefit is lost if 'b' is also tested.
                        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
                        if (a == 0) return (true, 0);
                        uint256 c = a * b;
                        if (c / a != b) return (false, 0);
                        return (true, c);
                    }
                }
                /**
                 * @dev Returns the division of two unsigned integers, with a division by zero flag.
                 */
                function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
                    unchecked {
                        if (b == 0) return (false, 0);
                        return (true, a / b);
                    }
                }
                /**
                 * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
                 */
                function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
                    unchecked {
                        if (b == 0) return (false, 0);
                        return (true, a % b);
                    }
                }
                /**
                 * @dev Returns the largest of two numbers.
                 */
                function max(uint256 a, uint256 b) internal pure returns (uint256) {
                    return a > b ? a : b;
                }
                /**
                 * @dev Returns the smallest of two numbers.
                 */
                function min(uint256 a, uint256 b) internal pure returns (uint256) {
                    return a < b ? a : b;
                }
                /**
                 * @dev Returns the average of two numbers. The result is rounded towards
                 * zero.
                 */
                function average(uint256 a, uint256 b) internal pure returns (uint256) {
                    // (a + b) / 2 can overflow.
                    return (a & b) + (a ^ b) / 2;
                }
                /**
                 * @dev Returns the ceiling of the division of two numbers.
                 *
                 * This differs from standard division with `/` in that it rounds towards infinity instead
                 * of rounding towards zero.
                 */
                function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
                    if (b == 0) {
                        // Guarantee the same behavior as in a regular Solidity division.
                        return a / b;
                    }
                    // (a + b - 1) / b can overflow on addition, so we distribute.
                    return a == 0 ? 0 : (a - 1) / b + 1;
                }
                /**
                 * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
                 * denominator == 0.
                 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
                 * Uniswap Labs also under MIT license.
                 */
                function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
                    unchecked {
                        // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
                        // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
                        // variables such that product = prod1 * 2^256 + prod0.
                        uint256 prod0 = x * y; // Least significant 256 bits of the product
                        uint256 prod1; // Most significant 256 bits of the product
                        assembly {
                            let mm := mulmod(x, y, not(0))
                            prod1 := sub(sub(mm, prod0), lt(mm, prod0))
                        }
                        // Handle non-overflow cases, 256 by 256 division.
                        if (prod1 == 0) {
                            // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                            // The surrounding unchecked block does not change this fact.
                            // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                            return prod0 / denominator;
                        }
                        // Make sure the result is less than 2^256. Also prevents denominator == 0.
                        if (denominator <= prod1) {
                            revert MathOverflowedMulDiv();
                        }
                        ///////////////////////////////////////////////
                        // 512 by 256 division.
                        ///////////////////////////////////////////////
                        // Make division exact by subtracting the remainder from [prod1 prod0].
                        uint256 remainder;
                        assembly {
                            // Compute remainder using mulmod.
                            remainder := mulmod(x, y, denominator)
                            // Subtract 256 bit number from 512 bit number.
                            prod1 := sub(prod1, gt(remainder, prod0))
                            prod0 := sub(prod0, remainder)
                        }
                        // Factor powers of two out of denominator and compute largest power of two divisor of denominator.
                        // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
                        uint256 twos = denominator & (0 - denominator);
                        assembly {
                            // Divide denominator by twos.
                            denominator := div(denominator, twos)
                            // Divide [prod1 prod0] by twos.
                            prod0 := div(prod0, twos)
                            // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                            twos := add(div(sub(0, twos), twos), 1)
                        }
                        // Shift in bits from prod1 into prod0.
                        prod0 |= prod1 * twos;
                        // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
                        // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
                        // four bits. That is, denominator * inv = 1 mod 2^4.
                        uint256 inverse = (3 * denominator) ^ 2;
                        // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
                        // works in modular arithmetic, doubling the correct bits in each step.
                        inverse *= 2 - denominator * inverse; // inverse mod 2^8
                        inverse *= 2 - denominator * inverse; // inverse mod 2^16
                        inverse *= 2 - denominator * inverse; // inverse mod 2^32
                        inverse *= 2 - denominator * inverse; // inverse mod 2^64
                        inverse *= 2 - denominator * inverse; // inverse mod 2^128
                        inverse *= 2 - denominator * inverse; // inverse mod 2^256
                        // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
                        // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
                        // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
                        // is no longer required.
                        result = prod0 * inverse;
                        return result;
                    }
                }
                /**
                 * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
                 */
                function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
                    uint256 result = mulDiv(x, y, denominator);
                    if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
                        result += 1;
                    }
                    return result;
                }
                /**
                 * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
                 * towards zero.
                 *
                 * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
                 */
                function sqrt(uint256 a) internal pure returns (uint256) {
                    if (a == 0) {
                        return 0;
                    }
                    // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
                    //
                    // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
                    // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
                    //
                    // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
                    // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
                    // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
                    //
                    // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
                    uint256 result = 1 << (log2(a) >> 1);
                    // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
                    // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
                    // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
                    // into the expected uint128 result.
                    unchecked {
                        result = (result + a / result) >> 1;
                        result = (result + a / result) >> 1;
                        result = (result + a / result) >> 1;
                        result = (result + a / result) >> 1;
                        result = (result + a / result) >> 1;
                        result = (result + a / result) >> 1;
                        result = (result + a / result) >> 1;
                        return min(result, a / result);
                    }
                }
                /**
                 * @notice Calculates sqrt(a), following the selected rounding direction.
                 */
                function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
                    unchecked {
                        uint256 result = sqrt(a);
                        return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
                    }
                }
                /**
                 * @dev Return the log in base 2 of a positive value rounded towards zero.
                 * Returns 0 if given 0.
                 */
                function log2(uint256 value) internal pure returns (uint256) {
                    uint256 result = 0;
                    unchecked {
                        if (value >> 128 > 0) {
                            value >>= 128;
                            result += 128;
                        }
                        if (value >> 64 > 0) {
                            value >>= 64;
                            result += 64;
                        }
                        if (value >> 32 > 0) {
                            value >>= 32;
                            result += 32;
                        }
                        if (value >> 16 > 0) {
                            value >>= 16;
                            result += 16;
                        }
                        if (value >> 8 > 0) {
                            value >>= 8;
                            result += 8;
                        }
                        if (value >> 4 > 0) {
                            value >>= 4;
                            result += 4;
                        }
                        if (value >> 2 > 0) {
                            value >>= 2;
                            result += 2;
                        }
                        if (value >> 1 > 0) {
                            result += 1;
                        }
                    }
                    return result;
                }
                /**
                 * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
                 * Returns 0 if given 0.
                 */
                function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
                    unchecked {
                        uint256 result = log2(value);
                        return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
                    }
                }
                /**
                 * @dev Return the log in base 10 of a positive value rounded towards zero.
                 * Returns 0 if given 0.
                 */
                function log10(uint256 value) internal pure returns (uint256) {
                    uint256 result = 0;
                    unchecked {
                        if (value >= 10 ** 64) {
                            value /= 10 ** 64;
                            result += 64;
                        }
                        if (value >= 10 ** 32) {
                            value /= 10 ** 32;
                            result += 32;
                        }
                        if (value >= 10 ** 16) {
                            value /= 10 ** 16;
                            result += 16;
                        }
                        if (value >= 10 ** 8) {
                            value /= 10 ** 8;
                            result += 8;
                        }
                        if (value >= 10 ** 4) {
                            value /= 10 ** 4;
                            result += 4;
                        }
                        if (value >= 10 ** 2) {
                            value /= 10 ** 2;
                            result += 2;
                        }
                        if (value >= 10 ** 1) {
                            result += 1;
                        }
                    }
                    return result;
                }
                /**
                 * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
                 * Returns 0 if given 0.
                 */
                function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
                    unchecked {
                        uint256 result = log10(value);
                        return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
                    }
                }
                /**
                 * @dev Return the log in base 256 of a positive value rounded towards zero.
                 * Returns 0 if given 0.
                 *
                 * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
                 */
                function log256(uint256 value) internal pure returns (uint256) {
                    uint256 result = 0;
                    unchecked {
                        if (value >> 128 > 0) {
                            value >>= 128;
                            result += 16;
                        }
                        if (value >> 64 > 0) {
                            value >>= 64;
                            result += 8;
                        }
                        if (value >> 32 > 0) {
                            value >>= 32;
                            result += 4;
                        }
                        if (value >> 16 > 0) {
                            value >>= 16;
                            result += 2;
                        }
                        if (value >> 8 > 0) {
                            result += 1;
                        }
                    }
                    return result;
                }
                /**
                 * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
                 * Returns 0 if given 0.
                 */
                function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
                    unchecked {
                        uint256 result = log256(value);
                        return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
                    }
                }
                /**
                 * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
                 */
                function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
                    return uint8(rounding) % 2 == 1;
                }
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)
            pragma solidity ^0.8.20;
            /**
             * @dev Standard signed math utilities missing in the Solidity language.
             */
            library SignedMath {
                /**
                 * @dev Returns the largest of two signed numbers.
                 */
                function max(int256 a, int256 b) internal pure returns (int256) {
                    return a > b ? a : b;
                }
                /**
                 * @dev Returns the smallest of two signed numbers.
                 */
                function min(int256 a, int256 b) internal pure returns (int256) {
                    return a < b ? a : b;
                }
                /**
                 * @dev Returns the average of two signed numbers without overflow.
                 * The result is rounded towards zero.
                 */
                function average(int256 a, int256 b) internal pure returns (int256) {
                    // Formula from the book "Hacker's Delight"
                    int256 x = (a & b) + ((a ^ b) >> 1);
                    return x + (int256(uint256(x) >> 255) & (a ^ b));
                }
                /**
                 * @dev Returns the absolute unsigned value of a signed value.
                 */
                function abs(int256 n) internal pure returns (uint256) {
                    unchecked {
                        // must be unchecked in order to support `n = type(int256).min`
                        return uint256(n >= 0 ? n : -n);
                    }
                }
            }
            /**
             ** Account-Abstraction (EIP-4337) singleton EntryPoint implementation.
             ** Only one instance required on each chain.
             **/
            // SPDX-License-Identifier: GPL-3.0
            pragma solidity >=0.7.5;
            /* solhint-disable avoid-low-level-calls */
            /* solhint-disable no-inline-assembly */
            /* solhint-disable reason-string */
            import "./PackedUserOperation.sol";
            import "./IStakeManager.sol";
            import "./IAggregator.sol";
            import "./INonceManager.sol";
            interface IEntryPoint is IStakeManager, INonceManager {
                /***
                 * An event emitted after each successful request.
                 * @param userOpHash    - Unique identifier for the request (hash its entire content, except signature).
                 * @param sender        - The account that generates this request.
                 * @param paymaster     - If non-null, the paymaster that pays for this request.
                 * @param nonce         - The nonce value from the request.
                 * @param success       - True if the sender transaction succeeded, false if reverted.
                 * @param actualGasCost - Actual amount paid (by account or paymaster) for this UserOperation.
                 * @param actualGasUsed - Total gas used by this UserOperation (including preVerification, creation,
                 *                        validation and execution).
                 */
                event UserOperationEvent(
                    bytes32 indexed userOpHash,
                    address indexed sender,
                    address indexed paymaster,
                    uint256 nonce,
                    bool success,
                    uint256 actualGasCost,
                    uint256 actualGasUsed
                );
                /**
                 * Account "sender" was deployed.
                 * @param userOpHash - The userOp that deployed this account. UserOperationEvent will follow.
                 * @param sender     - The account that is deployed
                 * @param factory    - The factory used to deploy this account (in the initCode)
                 * @param paymaster  - The paymaster used by this UserOp
                 */
                event AccountDeployed(
                    bytes32 indexed userOpHash,
                    address indexed sender,
                    address factory,
                    address paymaster
                );
                /**
                 * An event emitted if the UserOperation "callData" reverted with non-zero length.
                 * @param userOpHash   - The request unique identifier.
                 * @param sender       - The sender of this request.
                 * @param nonce        - The nonce used in the request.
                 * @param revertReason - The return bytes from the (reverted) call to "callData".
                 */
                event UserOperationRevertReason(
                    bytes32 indexed userOpHash,
                    address indexed sender,
                    uint256 nonce,
                    bytes revertReason
                );
                /**
                 * An event emitted if the UserOperation Paymaster's "postOp" call reverted with non-zero length.
                 * @param userOpHash   - The request unique identifier.
                 * @param sender       - The sender of this request.
                 * @param nonce        - The nonce used in the request.
                 * @param revertReason - The return bytes from the (reverted) call to "callData".
                 */
                event PostOpRevertReason(
                    bytes32 indexed userOpHash,
                    address indexed sender,
                    uint256 nonce,
                    bytes revertReason
                );
                /**
                 * UserOp consumed more than prefund. The UserOperation is reverted, and no refund is made.
                 * @param userOpHash   - The request unique identifier.
                 * @param sender       - The sender of this request.
                 * @param nonce        - The nonce used in the request.
                 */
                event UserOperationPrefundTooLow(
                    bytes32 indexed userOpHash,
                    address indexed sender,
                    uint256 nonce
                );
                /**
                 * An event emitted by handleOps(), before starting the execution loop.
                 * Any event emitted before this event, is part of the validation.
                 */
                event BeforeExecution();
                /**
                 * Signature aggregator used by the following UserOperationEvents within this bundle.
                 * @param aggregator - The aggregator used for the following UserOperationEvents.
                 */
                event SignatureAggregatorChanged(address indexed aggregator);
                /**
                 * A custom revert error of handleOps, to identify the offending op.
                 * Should be caught in off-chain handleOps simulation and not happen on-chain.
                 * Useful for mitigating DoS attempts against batchers or for troubleshooting of factory/account/paymaster reverts.
                 * NOTE: If simulateValidation passes successfully, there should be no reason for handleOps to fail on it.
                 * @param opIndex - Index into the array of ops to the failed one (in simulateValidation, this is always zero).
                 * @param reason  - Revert reason. The string starts with a unique code "AAmn",
                 *                  where "m" is "1" for factory, "2" for account and "3" for paymaster issues,
                 *                  so a failure can be attributed to the correct entity.
                 */
                error FailedOp(uint256 opIndex, string reason);
                /**
                 * A custom revert error of handleOps, to report a revert by account or paymaster.
                 * @param opIndex - Index into the array of ops to the failed one (in simulateValidation, this is always zero).
                 * @param reason  - Revert reason. see FailedOp(uint256,string), above
                 * @param inner   - data from inner cought revert reason
                 * @dev note that inner is truncated to 2048 bytes
                 */
                error FailedOpWithRevert(uint256 opIndex, string reason, bytes inner);
                error PostOpReverted(bytes returnData);
                /**
                 * Error case when a signature aggregator fails to verify the aggregated signature it had created.
                 * @param aggregator The aggregator that failed to verify the signature
                 */
                error SignatureValidationFailed(address aggregator);
                // Return value of getSenderAddress.
                error SenderAddressResult(address sender);
                // UserOps handled, per aggregator.
                struct UserOpsPerAggregator {
                    PackedUserOperation[] userOps;
                    // Aggregator address
                    IAggregator aggregator;
                    // Aggregated signature
                    bytes signature;
                }
                /**
                 * Execute a batch of UserOperations.
                 * No signature aggregator is used.
                 * If any account requires an aggregator (that is, it returned an aggregator when
                 * performing simulateValidation), then handleAggregatedOps() must be used instead.
                 * @param ops         - The operations to execute.
                 * @param beneficiary - The address to receive the fees.
                 */
                function handleOps(
                    PackedUserOperation[] calldata ops,
                    address payable beneficiary
                ) external;
                /**
                 * Execute a batch of UserOperation with Aggregators
                 * @param opsPerAggregator - The operations to execute, grouped by aggregator (or address(0) for no-aggregator accounts).
                 * @param beneficiary      - The address to receive the fees.
                 */
                function handleAggregatedOps(
                    UserOpsPerAggregator[] calldata opsPerAggregator,
                    address payable beneficiary
                ) external;
                /**
                 * Generate a request Id - unique identifier for this request.
                 * The request ID is a hash over the content of the userOp (except the signature), the entrypoint and the chainid.
                 * @param userOp - The user operation to generate the request ID for.
                 * @return hash the hash of this UserOperation
                 */
                function getUserOpHash(
                    PackedUserOperation calldata userOp
                ) external view returns (bytes32);
                /**
                 * Gas and return values during simulation.
                 * @param preOpGas         - The gas used for validation (including preValidationGas)
                 * @param prefund          - The required prefund for this operation
                 * @param accountValidationData   - returned validationData from account.
                 * @param paymasterValidationData - return validationData from paymaster.
                 * @param paymasterContext - Returned by validatePaymasterUserOp (to be passed into postOp)
                 */
                struct ReturnInfo {
                    uint256 preOpGas;
                    uint256 prefund;
                    uint256 accountValidationData;
                    uint256 paymasterValidationData;
                    bytes paymasterContext;
                }
                /**
                 * Returned aggregated signature info:
                 * The aggregator returned by the account, and its current stake.
                 */
                struct AggregatorStakeInfo {
                    address aggregator;
                    StakeInfo stakeInfo;
                }
                /**
                 * Get counterfactual sender address.
                 * Calculate the sender contract address that will be generated by the initCode and salt in the UserOperation.
                 * This method always revert, and returns the address in SenderAddressResult error
                 * @param initCode - The constructor code to be passed into the UserOperation.
                 */
                function getSenderAddress(bytes memory initCode) external;
                error DelegateAndRevert(bool success, bytes ret);
                /**
                 * Helper method for dry-run testing.
                 * @dev calling this method, the EntryPoint will make a delegatecall to the given data, and report (via revert) the result.
                 *  The method always revert, so is only useful off-chain for dry run calls, in cases where state-override to replace
                 *  actual EntryPoint code is less convenient.
                 * @param target a target contract to make a delegatecall from entrypoint
                 * @param data data to pass to target in a delegatecall
                 */
                function delegateAndRevert(address target, bytes calldata data) external;
            }
            // SPDX-License-Identifier: GPL-3.0
            pragma solidity ^0.8.12;
            /* solhint-disable no-inline-assembly */
            import {calldataKeccak} from "../core/Helpers.sol";
            /**
             * User Operation struct
             * @param sender the sender account of this request.
                 * @param nonce unique value the sender uses to verify it is not a replay.
                 * @param initCode if set, the account contract will be created by this constructor/
                 * @param callData the method call to execute on this account.
                 * @param callGasLimit the gas limit passed to the callData method call.
                 * @param verificationGasLimit gas used for validateUserOp and validatePaymasterUserOp.
                 * @param preVerificationGas gas not calculated by the handleOps method, but added to the gas paid. Covers batch overhead.
                 * @param maxFeePerGas same as EIP-1559 gas parameter.
                 * @param maxPriorityFeePerGas same as EIP-1559 gas parameter.
                 * @param paymasterAndData if set, this field holds the paymaster address and paymaster-specific data. the paymaster will pay for the transaction instead of the sender.
                 * @param signature sender-verified signature over the entire request, the EntryPoint address and the chain ID.
                 */
                struct UserOperation {
                    address sender;
                    uint256 nonce;
                    bytes initCode;
                    bytes callData;
                    uint256 callGasLimit;
                    uint256 verificationGasLimit;
                    uint256 preVerificationGas;
                    uint256 maxFeePerGas;
                    uint256 maxPriorityFeePerGas;
                    bytes paymasterAndData;
                    bytes signature;
                }
            /**
             * Utility functions helpful when working with UserOperation structs.
             */
            library UserOperationLib {
                function getSender(UserOperation calldata userOp) internal pure returns (address) {
                    address data;
                    //read sender from userOp, which is first userOp member (saves 800 gas...)
                    assembly {data := calldataload(userOp)}
                    return address(uint160(data));
                }
                //relayer/block builder might submit the TX with higher priorityFee, but the user should not
                // pay above what he signed for.
                function gasPrice(UserOperation calldata userOp) internal view returns (uint256) {
                unchecked {
                    uint256 maxFeePerGas = userOp.maxFeePerGas;
                    uint256 maxPriorityFeePerGas = userOp.maxPriorityFeePerGas;
                    if (maxFeePerGas == maxPriorityFeePerGas) {
                        //legacy mode (for networks that don't support basefee opcode)
                        return maxFeePerGas;
                    }
                    return min(maxFeePerGas, maxPriorityFeePerGas + block.basefee);
                }
                }
                function pack(UserOperation calldata userOp) internal pure returns (bytes memory ret) {
                    address sender = getSender(userOp);
                    uint256 nonce = userOp.nonce;
                    bytes32 hashInitCode = calldataKeccak(userOp.initCode);
                    bytes32 hashCallData = calldataKeccak(userOp.callData);
                    uint256 callGasLimit = userOp.callGasLimit;
                    uint256 verificationGasLimit = userOp.verificationGasLimit;
                    uint256 preVerificationGas = userOp.preVerificationGas;
                    uint256 maxFeePerGas = userOp.maxFeePerGas;
                    uint256 maxPriorityFeePerGas = userOp.maxPriorityFeePerGas;
                    bytes32 hashPaymasterAndData = calldataKeccak(userOp.paymasterAndData);
                    return abi.encode(
                        sender, nonce,
                        hashInitCode, hashCallData,
                        callGasLimit, verificationGasLimit, preVerificationGas,
                        maxFeePerGas, maxPriorityFeePerGas,
                        hashPaymasterAndData
                    );
                }
                function hash(UserOperation calldata userOp) internal pure returns (bytes32) {
                    return keccak256(pack(userOp));
                }
                function min(uint256 a, uint256 b) internal pure returns (uint256) {
                    return a < b ? a : b;
                }
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)
            pragma solidity ^0.8.20;
            import {IAccessControl} from "./IAccessControl.sol";
            import {Context} from "../utils/Context.sol";
            import {ERC165} from "../utils/introspection/ERC165.sol";
            /**
             * @dev Contract module that allows children to implement role-based access
             * control mechanisms. This is a lightweight version that doesn't allow enumerating role
             * members except through off-chain means by accessing the contract event logs. Some
             * applications may benefit from on-chain enumerability, for those cases see
             * {AccessControlEnumerable}.
             *
             * Roles are referred to by their `bytes32` identifier. These should be exposed
             * in the external API and be unique. The best way to achieve this is by
             * using `public constant` hash digests:
             *
             * ```solidity
             * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
             * ```
             *
             * Roles can be used to represent a set of permissions. To restrict access to a
             * function call, use {hasRole}:
             *
             * ```solidity
             * function foo() public {
             *     require(hasRole(MY_ROLE, msg.sender));
             *     ...
             * }
             * ```
             *
             * Roles can be granted and revoked dynamically via the {grantRole} and
             * {revokeRole} functions. Each role has an associated admin role, and only
             * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
             *
             * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
             * that only accounts with this role will be able to grant or revoke other
             * roles. More complex role relationships can be created by using
             * {_setRoleAdmin}.
             *
             * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
             * grant and revoke this role. Extra precautions should be taken to secure
             * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
             * to enforce additional security measures for this role.
             */
            abstract contract AccessControl is Context, IAccessControl, ERC165 {
                struct RoleData {
                    mapping(address account => bool) hasRole;
                    bytes32 adminRole;
                }
                mapping(bytes32 role => RoleData) private _roles;
                bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
                /**
                 * @dev Modifier that checks that an account has a specific role. Reverts
                 * with an {AccessControlUnauthorizedAccount} error including the required role.
                 */
                modifier onlyRole(bytes32 role) {
                    _checkRole(role);
                    _;
                }
                /**
                 * @dev See {IERC165-supportsInterface}.
                 */
                function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
                    return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
                }
                /**
                 * @dev Returns `true` if `account` has been granted `role`.
                 */
                function hasRole(bytes32 role, address account) public view virtual returns (bool) {
                    return _roles[role].hasRole[account];
                }
                /**
                 * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
                 * is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
                 */
                function _checkRole(bytes32 role) internal view virtual {
                    _checkRole(role, _msgSender());
                }
                /**
                 * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
                 * is missing `role`.
                 */
                function _checkRole(bytes32 role, address account) internal view virtual {
                    if (!hasRole(role, account)) {
                        revert AccessControlUnauthorizedAccount(account, role);
                    }
                }
                /**
                 * @dev Returns the admin role that controls `role`. See {grantRole} and
                 * {revokeRole}.
                 *
                 * To change a role's admin, use {_setRoleAdmin}.
                 */
                function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
                    return _roles[role].adminRole;
                }
                /**
                 * @dev Grants `role` to `account`.
                 *
                 * If `account` had not been already granted `role`, emits a {RoleGranted}
                 * event.
                 *
                 * Requirements:
                 *
                 * - the caller must have ``role``'s admin role.
                 *
                 * May emit a {RoleGranted} event.
                 */
                function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
                    _grantRole(role, account);
                }
                /**
                 * @dev Revokes `role` from `account`.
                 *
                 * If `account` had been granted `role`, emits a {RoleRevoked} event.
                 *
                 * Requirements:
                 *
                 * - the caller must have ``role``'s admin role.
                 *
                 * May emit a {RoleRevoked} event.
                 */
                function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
                    _revokeRole(role, account);
                }
                /**
                 * @dev Revokes `role` from the calling account.
                 *
                 * Roles are often managed via {grantRole} and {revokeRole}: this function's
                 * purpose is to provide a mechanism for accounts to lose their privileges
                 * if they are compromised (such as when a trusted device is misplaced).
                 *
                 * If the calling account had been revoked `role`, emits a {RoleRevoked}
                 * event.
                 *
                 * Requirements:
                 *
                 * - the caller must be `callerConfirmation`.
                 *
                 * May emit a {RoleRevoked} event.
                 */
                function renounceRole(bytes32 role, address callerConfirmation) public virtual {
                    if (callerConfirmation != _msgSender()) {
                        revert AccessControlBadConfirmation();
                    }
                    _revokeRole(role, callerConfirmation);
                }
                /**
                 * @dev Sets `adminRole` as ``role``'s admin role.
                 *
                 * Emits a {RoleAdminChanged} event.
                 */
                function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
                    bytes32 previousAdminRole = getRoleAdmin(role);
                    _roles[role].adminRole = adminRole;
                    emit RoleAdminChanged(role, previousAdminRole, adminRole);
                }
                /**
                 * @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
                 *
                 * Internal function without access restriction.
                 *
                 * May emit a {RoleGranted} event.
                 */
                function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
                    if (!hasRole(role, account)) {
                        _roles[role].hasRole[account] = true;
                        emit RoleGranted(role, account, _msgSender());
                        return true;
                    } else {
                        return false;
                    }
                }
                /**
                 * @dev Attempts to revoke `role` to `account` and returns a boolean indicating if `role` was revoked.
                 *
                 * Internal function without access restriction.
                 *
                 * May emit a {RoleRevoked} event.
                 */
                function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
                    if (hasRole(role, account)) {
                        _roles[role].hasRole[account] = false;
                        emit RoleRevoked(role, account, _msgSender());
                        return true;
                    } else {
                        return false;
                    }
                }
            }
            // SPDX-License-Identifier: GPL-3.0-only
            pragma solidity >=0.7.5;
            /**
             * Manage deposits and stakes.
             * Deposit is just a balance used to pay for UserOperations (either by a paymaster or an account).
             * Stake is value locked for at least "unstakeDelay" by the staked entity.
             */
            interface IStakeManager {
                event Deposited(address indexed account, uint256 totalDeposit);
                event Withdrawn(
                    address indexed account,
                    address withdrawAddress,
                    uint256 amount
                );
                // Emitted when stake or unstake delay are modified.
                event StakeLocked(
                    address indexed account,
                    uint256 totalStaked,
                    uint256 unstakeDelaySec
                );
                // Emitted once a stake is scheduled for withdrawal.
                event StakeUnlocked(address indexed account, uint256 withdrawTime);
                event StakeWithdrawn(
                    address indexed account,
                    address withdrawAddress,
                    uint256 amount
                );
                /**
                 * @param deposit         - The entity's deposit.
                 * @param staked          - True if this entity is staked.
                 * @param stake           - Actual amount of ether staked for this entity.
                 * @param unstakeDelaySec - Minimum delay to withdraw the stake.
                 * @param withdrawTime    - First block timestamp where 'withdrawStake' will be callable, or zero if already locked.
                 * @dev Sizes were chosen so that deposit fits into one cell (used during handleOp)
                 *      and the rest fit into a 2nd cell (used during stake/unstake)
                 *      - 112 bit allows for 10^15 eth
                 *      - 48 bit for full timestamp
                 *      - 32 bit allows 150 years for unstake delay
                 */
                struct DepositInfo {
                    uint256 deposit;
                    bool staked;
                    uint112 stake;
                    uint32 unstakeDelaySec;
                    uint48 withdrawTime;
                }
                // API struct used by getStakeInfo and simulateValidation.
                struct StakeInfo {
                    uint256 stake;
                    uint256 unstakeDelaySec;
                }
                /**
                 * Get deposit info.
                 * @param account - The account to query.
                 * @return info   - Full deposit information of given account.
                 */
                function getDepositInfo(
                    address account
                ) external view returns (DepositInfo memory info);
                /**
                 * Get account balance.
                 * @param account - The account to query.
                 * @return        - The deposit (for gas payment) of the account.
                 */
                function balanceOf(address account) external view returns (uint256);
                /**
                 * Add to the deposit of the given account.
                 * @param account - The account to add to.
                 */
                function depositTo(address account) external payable;
                /**
                 * Add to the account's stake - amount and delay
                 * any pending unstake is first cancelled.
                 * @param _unstakeDelaySec - The new lock duration before the deposit can be withdrawn.
                 */
                function addStake(uint32 _unstakeDelaySec) external payable;
                /**
                 * Attempt to unlock the stake.
                 * The value can be withdrawn (using withdrawStake) after the unstake delay.
                 */
                function unlockStake() external;
                /**
                 * Withdraw from the (unlocked) stake.
                 * Must first call unlockStake and wait for the unstakeDelay to pass.
                 * @param withdrawAddress - The address to send withdrawn value.
                 */
                function withdrawStake(address payable withdrawAddress) external;
                /**
                 * Withdraw from the deposit.
                 * @param withdrawAddress - The address to send withdrawn value.
                 * @param withdrawAmount  - The amount to withdraw.
                 */
                function withdrawTo(
                    address payable withdrawAddress,
                    uint256 withdrawAmount
                ) external;
            }
            // SPDX-License-Identifier: GPL-3.0
            pragma solidity >=0.7.5;
            import "./PackedUserOperation.sol";
            /**
             * Aggregated Signatures validator.
             */
            interface IAggregator {
                /**
                 * Validate aggregated signature.
                 * Revert if the aggregated signature does not match the given list of operations.
                 * @param userOps   - Array of UserOperations to validate the signature for.
                 * @param signature - The aggregated signature.
                 */
                function validateSignatures(
                    PackedUserOperation[] calldata userOps,
                    bytes calldata signature
                ) external view;
                /**
                 * Validate signature of a single userOp.
                 * This method should be called by bundler after EntryPointSimulation.simulateValidation() returns
                 * the aggregator this account uses.
                 * First it validates the signature over the userOp. Then it returns data to be used when creating the handleOps.
                 * @param userOp        - The userOperation received from the user.
                 * @return sigForUserOp - The value to put into the signature field of the userOp when calling handleOps.
                 *                        (usually empty, unless account and aggregator support some kind of "multisig".
                 */
                function validateUserOpSignature(
                    PackedUserOperation calldata userOp
                ) external view returns (bytes memory sigForUserOp);
                /**
                 * Aggregate multiple signatures into a single value.
                 * This method is called off-chain to calculate the signature to pass with handleOps()
                 * bundler MAY use optimized custom code perform this aggregation.
                 * @param userOps              - Array of UserOperations to collect the signatures from.
                 * @return aggregatedSignature - The aggregated signature.
                 */
                function aggregateSignatures(
                    PackedUserOperation[] calldata userOps
                ) external view returns (bytes memory aggregatedSignature);
            }
            // SPDX-License-Identifier: GPL-3.0
            pragma solidity >=0.7.5;
            interface INonceManager {
                /**
                 * Return the next nonce for this sender.
                 * Within a given key, the nonce values are sequenced (starting with zero, and incremented by one on each userop)
                 * But UserOp with different keys can come with arbitrary order.
                 *
                 * @param sender the account address
                 * @param key the high 192 bit of the nonce
                 * @return nonce a full nonce to pass for next UserOp with this sender.
                 */
                function getNonce(address sender, uint192 key)
                external view returns (uint256 nonce);
                /**
                 * Manually increment the nonce of the sender.
                 * This method is exposed just for completeness..
                 * Account does NOT need to call it, neither during validation, nor elsewhere,
                 * as the EntryPoint will update the nonce regardless.
                 * Possible use-case is call it with various keys to "initialize" their nonces to one, so that future
                 * UserOperations will not pay extra for the first transaction with a given key.
                 */
                function incrementNonce(uint192 key) external;
            }
            // SPDX-License-Identifier: GPL-3.0
            pragma solidity ^0.8.12;
            /* solhint-disable no-inline-assembly */
            /**
             * returned data from validateUserOp.
             * validateUserOp returns a uint256, with is created by `_packedValidationData` and parsed by `_parseValidationData`
             * @param aggregator - address(0) - the account validated the signature by itself.
             *              address(1) - the account failed to validate the signature.
             *              otherwise - this is an address of a signature aggregator that must be used to validate the signature.
             * @param validAfter - this UserOp is valid only after this timestamp.
             * @param validaUntil - this UserOp is valid only up to this timestamp.
             */
                struct ValidationData {
                    address aggregator;
                    uint48 validAfter;
                    uint48 validUntil;
                }
            //extract sigFailed, validAfter, validUntil.
            // also convert zero validUntil to type(uint48).max
                function _parseValidationData(uint validationData) pure returns (ValidationData memory data) {
                    address aggregator = address(uint160(validationData));
                    uint48 validUntil = uint48(validationData >> 160);
                    if (validUntil == 0) {
                        validUntil = type(uint48).max;
                    }
                    uint48 validAfter = uint48(validationData >> (48 + 160));
                    return ValidationData(aggregator, validAfter, validUntil);
                }
            // intersect account and paymaster ranges.
                function _intersectTimeRange(uint256 validationData, uint256 paymasterValidationData) pure returns (ValidationData memory) {
                    ValidationData memory accountValidationData = _parseValidationData(validationData);
                    ValidationData memory pmValidationData = _parseValidationData(paymasterValidationData);
                    address aggregator = accountValidationData.aggregator;
                    if (aggregator == address(0)) {
                        aggregator = pmValidationData.aggregator;
                    }
                    uint48 validAfter = accountValidationData.validAfter;
                    uint48 validUntil = accountValidationData.validUntil;
                    uint48 pmValidAfter = pmValidationData.validAfter;
                    uint48 pmValidUntil = pmValidationData.validUntil;
                    if (validAfter < pmValidAfter) validAfter = pmValidAfter;
                    if (validUntil > pmValidUntil) validUntil = pmValidUntil;
                    return ValidationData(aggregator, validAfter, validUntil);
                }
            /**
             * helper to pack the return value for validateUserOp
             * @param data - the ValidationData to pack
             */
                function _packValidationData(ValidationData memory data) pure returns (uint256) {
                    return uint160(data.aggregator) | (uint256(data.validUntil) << 160) | (uint256(data.validAfter) << (160 + 48));
                }
            /**
             * helper to pack the return value for validateUserOp, when not using an aggregator
             * @param sigFailed - true for signature failure, false for success
             * @param validUntil last timestamp this UserOperation is valid (or zero for infinite)
             * @param validAfter first timestamp this UserOperation is valid
             */
                function _packValidationData(bool sigFailed, uint48 validUntil, uint48 validAfter) pure returns (uint256) {
                    return (sigFailed ? 1 : 0) | (uint256(validUntil) << 160) | (uint256(validAfter) << (160 + 48));
                }
            /**
             * keccak function over calldata.
             * @dev copy calldata into memory, do keccak and drop allocated memory. Strangely, this is more efficient than letting solidity do it.
             */
                function calldataKeccak(bytes calldata data) pure returns (bytes32 ret) {
                    assembly {
                        let mem := mload(0x40)
                        let len := data.length
                        calldatacopy(mem, data.offset, len)
                        ret := keccak256(mem, len)
                    }
                }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.0.0) (access/IAccessControl.sol)
            pragma solidity ^0.8.20;
            /**
             * @dev External interface of AccessControl declared to support ERC165 detection.
             */
            interface IAccessControl {
                /**
                 * @dev The `account` is missing a role.
                 */
                error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
                /**
                 * @dev The caller of a function is not the expected one.
                 *
                 * NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
                 */
                error AccessControlBadConfirmation();
                /**
                 * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
                 *
                 * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
                 * {RoleAdminChanged} not being emitted signaling this.
                 */
                event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
                /**
                 * @dev Emitted when `account` is granted `role`.
                 *
                 * `sender` is the account that originated the contract call, an admin role
                 * bearer except when using {AccessControl-_setupRole}.
                 */
                event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
                /**
                 * @dev Emitted when `account` is revoked `role`.
                 *
                 * `sender` is the account that originated the contract call:
                 *   - if using `revokeRole`, it is the admin role bearer
                 *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
                 */
                event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
                /**
                 * @dev Returns `true` if `account` has been granted `role`.
                 */
                function hasRole(bytes32 role, address account) external view returns (bool);
                /**
                 * @dev Returns the admin role that controls `role`. See {grantRole} and
                 * {revokeRole}.
                 *
                 * To change a role's admin, use {AccessControl-_setRoleAdmin}.
                 */
                function getRoleAdmin(bytes32 role) external view returns (bytes32);
                /**
                 * @dev Grants `role` to `account`.
                 *
                 * If `account` had not been already granted `role`, emits a {RoleGranted}
                 * event.
                 *
                 * Requirements:
                 *
                 * - the caller must have ``role``'s admin role.
                 */
                function grantRole(bytes32 role, address account) external;
                /**
                 * @dev Revokes `role` from `account`.
                 *
                 * If `account` had been granted `role`, emits a {RoleRevoked} event.
                 *
                 * Requirements:
                 *
                 * - the caller must have ``role``'s admin role.
                 */
                function revokeRole(bytes32 role, address account) external;
                /**
                 * @dev Revokes `role` from the calling account.
                 *
                 * Roles are often managed via {grantRole} and {revokeRole}: this function's
                 * purpose is to provide a mechanism for accounts to lose their privileges
                 * if they are compromised (such as when a trusted device is misplaced).
                 *
                 * If the calling account had been granted `role`, emits a {RoleRevoked}
                 * event.
                 *
                 * Requirements:
                 *
                 * - the caller must be `callerConfirmation`.
                 */
                function renounceRole(bytes32 role, address callerConfirmation) external;
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.0.1) (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;
                }
                function _contextSuffixLength() internal view virtual returns (uint256) {
                    return 0;
                }
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)
            pragma solidity ^0.8.20;
            import {IERC165} from "./IERC165.sol";
            /**
             * @dev Implementation of the {IERC165} interface.
             *
             * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
             * for the additional interface id that will be supported. For example:
             *
             * ```solidity
             * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
             *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
             * }
             * ```
             */
            abstract contract ERC165 is IERC165 {
                /**
                 * @dev See {IERC165-supportsInterface}.
                 */
                function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
                    return interfaceId == type(IERC165).interfaceId;
                }
            }
            // SPDX-License-Identifier: MIT
            // OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)
            pragma solidity ^0.8.20;
            /**
             * @dev Interface of the ERC165 standard, as defined in the
             * https://eips.ethereum.org/EIPS/eip-165[EIP].
             *
             * Implementers can declare support of contract interfaces, which can then be
             * queried by others ({ERC165Checker}).
             *
             * For an implementation, see {ERC165}.
             */
            interface IERC165 {
                /**
                 * @dev Returns true if this contract implements the interface defined by
                 * `interfaceId`. See the corresponding
                 * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
                 * to learn more about how these ids are created.
                 *
                 * This function call must use less than 30 000 gas.
                 */
                function supportsInterface(bytes4 interfaceId) external view returns (bool);
            }