```\nfunction _handlePostOp(uint256 opIndex, IPaymaster.PostOpMode mode, UserOpInfo memory opInfo, bytes memory context, uint256 actualGas) private returns (uint256 actualGasCost) {\n    uint256 preGas = gasleft();\nunchecked {\n    address refundAddress;\n    MemoryUserOp memory mUserOp = opInfo.mUserOp;\n    uint256 gasPrice = getUserOpGasPrice(mUserOp);\n\n    address paymaster = mUserOp.paymaster;\n    if (paymaster == address(0)) {\n        refundAddress = mUserOp.sender;\n    } else {\n        refundAddress = paymaster;\n        if (context.length > 0) {\n            actualGasCost = actualGas * gasPrice;\n            if (mode != IPaymaster.PostOpMode.postOpReverted) {\n                IPaymaster(paymaster).postOp{gas : mUserOp.verificationGasLimit}(mode, context, actualGasCost);\n            } else {\n                // solhint-disable-next-line no-empty-blocks\n                try IPaymaster(paymaster).postOp{gas : mUserOp.verificationGasLimit}(mode, context, actualGasCost) {}\n                catch Error(string memory reason) {\n                    revert FailedOp(opIndex, string.concat("AA50 postOp reverted: ", reason));\n                }\n                catch {\n                    revert FailedOp(opIndex, "AA50 postOp revert");\n                }\n            }\n        }\n    }\n    actualGas += preGas - gasleft();\n    actualGasCost = actualGas * gasPrice;\n    if (opInfo.prefund < actualGasCost) {\n        revert FailedOp(opIndex, "AA51 prefund below actualGasCost");\n    }\n    uint256 refund = opInfo.prefund - actualGasCost;\n    _incrementDeposit(refundAddress, refund);\n    bool success = mode == IPaymaster.PostOpMode.opSucceeded;\n    emit UserOperationEvent(opInfo.userOpHash, mUserOp.sender, mUserOp.paymaster, mUserOp.nonce, success, actualGasCost, actualGas);\n} // unchecked\n}\n```\n