{"file_path":"src/CappedBurnHook.sol","creation_status":"success","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\n/*\n   ____   ___   ___  _     _  _\n  |  _ \\ / _ \\ / _ \\| |   | || |\n  | |_) | | | | | | | |   | || |_\n  |  __/| |_| | |_| | |___|__   _|\n  |_|    \\___/ \\___/|_____|  |_|\n\n  POOL4 · CappedBurnHook — a Uniswap v4 market that permanently burns what's sold into it.\n*/\n\nimport {Ownable} from \"solady/auth/Ownable.sol\";\nimport {SafeTransferLib} from \"solady/utils/SafeTransferLib.sol\";\nimport {FixedPointMathLib} from \"solady/utils/FixedPointMathLib.sol\";\nimport {IHooks} from \"v4-core/interfaces/IHooks.sol\";\nimport {IPoolManager} from \"v4-core/interfaces/IPoolManager.sol\";\nimport {Hooks} from \"v4-core/libraries/Hooks.sol\";\nimport {SqrtPriceMath} from \"v4-core/libraries/SqrtPriceMath.sol\";\nimport {StateLibrary} from \"v4-core/libraries/StateLibrary.sol\";\nimport {TickMath} from \"v4-core/libraries/TickMath.sol\";\nimport {BalanceDelta} from \"v4-core/types/BalanceDelta.sol\";\nimport {Currency, CurrencyLibrary} from \"v4-core/types/Currency.sol\";\nimport {PoolId} from \"v4-core/types/PoolId.sol\";\nimport {PoolKey} from \"v4-core/types/PoolKey.sol\";\n\n/// @notice An ordinary ETH/token Uniswap v4 market that permanently retires the tokens sold into\n/// it, and recycles the ETH it recovers into a wide single-sided backstop above the price.\n///\n/// @dev Pricing is untouched. The pool carries real full-range liquidity, quotes through standard\n/// concentrated-liquidity math, charges the pool's native LP fee, and declares no delta flags, so\n/// any router or aggregator that can trade a plain v4 pool can trade this one.\n///\n/// Three mechanisms, all enforced after the swap has settled:\n///\n/// 1. CAP. The market position may never hold more tokens than `inventoryCap`. Sells push tokens\n///    in; anything above the cap is withdrawn and leaves permanently, split `rewardShareBps` to\n///    `rewardsRecipient` and the rest to `burnSink`. Withdrawing liquidity is not a swap, so the\n///    square-root price is identical before and after and nobody is quoted differently.\n///\n/// 2. RATCHET. Buys draw the position below the cap; the cap follows it down, so the next sell\n///    burns rather than merely refilling. `capFloor` bounds this: the cap never falls below it, so\n///    once the market has shrunk to that size it simply behaves as an ordinary pool - below the\n///    floor nothing burns, and selling back above it resumes the cap. Without a floor the ratchet\n///    compounds toward zero and the market ratchets itself out of existence.\n///\n/// 3. BACKSTOP. Trimming under the cap is proportional, so it pulls ETH out alongside the tokens.\n///    That ETH accrues to `retainedEth` and is redeployed by a permissionless keeper as one wide\n///    single-sided position above the current price, mirroring the market position's ETH side so\n///    the sell side keeps behaving like an ordinary pool rather than melting. It costs no tokens to\n///    place. Redeployment is batched behind an ETH threshold, so routine sells run with\n///    marginally-less LP instead of paying a remove/redeploy on every trade. The band is never\n///    priced off live spot: its lower tick is floored at `deploymentFloorTick`, which jumps up to\n///    any tick the pool has traded at and drifts back down only at `floorDecayTicksPerDay`, so a\n///    manipulated placement costs days of holding a false price rather than one block. When a dump\n///    pushes price up into the backstop it fills; the next rebalance burns the tokens it bought (the\n///    same burn/reward split as a trim) and redeploys the recovered ETH above the new spot.\ncontract CappedBurnHook is Ownable {\n    using StateLibrary for IPoolManager;\n    using FixedPointMathLib for uint256;\n\n    error AlreadyOpen();\n    error BidNotSingleSided(uint256 tokensRequired);\n    error NotSelf();\n    error CallbackNotExpected();\n    error IncorrectEthAmount(uint256 required, uint256 supplied);\n    error InsufficientRetainedEth(uint256 requested, uint256 available);\n    error InvalidConfiguration();\n    error InvalidLiquidity();\n    error InvalidPool();\n    error InvalidPoolManagerCaller();\n    error LiquidityRestrictedToHook();\n    error InitializationRestrictedToHook();\n    error MarketNotOpen();\n    error PoolNotInitialized();\n    error RebalanceDisabled();\n    error RebalanceNotNeeded();\n    error PriceMovedDuringLiquidityChange(uint160 before_, uint160 after_);\n    error TokenAmountExceeded(uint256 required, uint256 maximum);\n    error UnexpectedLiquidityDelta();\n\n    event PoolInitialized(uint160 sqrtPriceX96, int24 tick);\n    event MarketOpened(uint128 liquidity, uint256 ethDeposited, uint256 inventoryCap);\n    event MarketClosed(address indexed recipient, uint256 ethReturned, uint256 tokensReturned);\n    event InventoryFunded(uint128 liquidity, uint256 ethDeposited, uint256 tokensDeposited, uint256 newCap);\n    event CapRatcheted(uint256 previousCap, uint256 newCap);\n    event Trimmed(uint128 liquidityRemoved, uint256 tokensBurned, uint256 tokensRewarded, uint256 ethRetained);\n    event BackstopDeployed(int24 tickLower, int24 tickUpper, uint128 liquidity, uint256 ethDeployed);\n    event BackstopSettled(uint128 liquidity, uint256 tokensBurned, uint256 tokensRewarded, uint256 ethReturned);\n    event RebalanceConfigUpdated(bool enabled, uint256 ethThreshold);\n    event MaxRefStepUpdated(int24 maxStep);\n    event KeeperRewardUpdated(uint256 reward);\n    event KeeperRewardPaid(address indexed keeper, uint256 reward);\n    event Rebalanced(int24 lower);\n    event DeploymentFloorUpdated(int24 previousFloor, int24 newFloor);\n    event FloorDecayUpdated(uint256 ticksPerDay);\n    event CapFloorUpdated(uint256 previousFloor, uint256 newFloor);\n    event CapDecayUpdated(uint256 tokensPerDay);\n    event RatchetUpdated(uint256 previousBps, uint256 newBps);\n    event BurnSinkUpdated(address indexed previous, address indexed current);\n    event RewardsRecipientUpdated(address indexed previous, address indexed current);\n    event RewardShareUpdated(uint256 previousBps, uint256 newBps);\n    event RetainedEthWithdrawn(address indexed recipient, uint256 amount);\n    event ClaimsSettled(uint256 tokensToBurnSink, uint256 tokensToRewards, uint256 ethRedeemed);\n    /// @notice The LP fee realised by one swap (or a backstop close). Emitted once per collection.\n    event FeeCollected(uint256 tokenFee, uint256 ethFee);\n    event FeesWithdrawn(address indexed recipient, uint256 tokenAmount, uint256 ethAmount);\n\n    uint256 public constant BPS_DENOMINATOR = 10_000;\n    uint256 internal constant FEE_DENOMINATOR = 1_000_000;\n    /// @dev High enough to be effectively unlimited for any real token, low enough that\n    /// `capDecayTokensPerDay * elapsed` in `_applyCap` cannot overflow. Without a bound, a large\n    /// enough setting makes that checked multiplication revert - and because `_applyCap` is\n    /// deliberately not wrapped in try/catch, the revert propagates to every swap and takes the\n    /// whole pool offline.\n    uint256 public constant MAX_CAP_DECAY_PER_DAY = type(uint128).max;\n\n    IPoolManager public immutable poolManager;\n    address public immutable token;\n    address public burnSink;\n    address public rewardsRecipient;\n    /// @notice Share of every trim/backstop burn skimmed to `rewardsRecipient` instead of burned.\n    /// Owner-tunable via `setRewardShareBps`, but capped at `MAX_REWARD_SHARE_BPS` so burning always\n    /// dominates and the owner can never redirect the whole trim.\n    uint256 public rewardShareBps;\n    uint256 internal constant MAX_REWARD_SHARE_BPS = 3_000; // <= 30% to rewards; burn always >= 70%\n    uint256 public immutable minTrimTokens;\n    uint24 public immutable lpFee;\n    int24 public immutable tickSpacing;\n    int24 public immutable tickLower;\n    int24 public immutable tickUpper;\n\n    // --- adjustable policy -------------------------------------------------\n    /// @notice Share of the room a buy opens that the cap gives back. 10_000 = full ratchet.\n    uint256 public ratchetBps;\n    /// @notice The cap never falls below this. Below it the market behaves as an ordinary pool.\n    uint256 public capFloor;\n    /// @notice Maximum number of tokens that may be ratcheted off the cap per day.\n    ///\n    /// @dev Without this the ratchet is bounded by trading volume rather than by the protocol, and\n    /// volume is something anyone can manufacture. A round trip strips its own size out of the\n    /// pool while costing the trader only the LP fee, so wash trading can run the entire burn\n    /// programme to the floor for a few ETH. Rate-limiting the decay decouples burn pace from\n    /// volume: the ratchet still fires on every sell-after-buy, but the cap can only travel so far\n    /// per day no matter how hard the market is pushed. Zero disables ratcheting entirely.\n    ///\n    /// @dev Absolute rather than a share of the cap: a percentage decelerates as the cap shrinks,\n    /// which is the wrong shape for a programme meant to run at a steady pace. Note that wash\n    /// trading is not profitable at any setting - a round trip returns the trader's tokens and\n    /// costs them the LP fee - so this governs pacing, not theft.\n    uint256 public capDecayTokensPerDay;\n    /// @dev Clock for the decay allowance. Partial use advances it proportionally so unused time\n    /// is not thrown away.\n    uint256 public lastCapDecayAt;\n    /// @dev Sub-quantum decay debt carried between ratchets, in token·day units. A single ratchet\n    /// smaller than one clock-second of allowance would otherwise floor its clock advance to zero;\n    /// accumulating the remainder here means such fragments still debit the clock once enough of\n    /// them add up, so splitting a cap reduction into many tiny ratchets cannot outrun the limit.\n    uint256 public capDecayRemainder;\n    /// @notice The single wide single-sided ETH backstop above spot.\n\n    struct Band {\n        int24 tickLower;\n        int24 tickUpper;\n        uint128 liquidity;\n    }\n\n    /// @notice The live backstop. Recovered ETH is redeployed here as one wide single-sided band\n    /// spanning from just above spot to `tickUpper`, so sell-side depth is preserved rather than\n    /// concentrated (see mechanism 3 in the contract doc).\n    Band public backstop;\n    /// @notice ETH principal originally deposited into the live backstop. Keeping this separate from\n    /// the range lets the hook measure how much principal has actually converted into tokens; a tick\n    /// boundary alone is not a fill and cannot justify a keeper reward.\n    uint256 public backstopEthPrincipal;\n\n    // --- rebalance policy (keeper-driven, priced off a block-lagged reference) ---\n    /// @notice Owner kill switch for the keeper backstop rebalance.\n    bool public rebalanceEnabled;\n    /// @notice A keeper rebalance is \"worth it\" once newly trimmed, unbatched ETH reaches this or the\n    /// backstop has converted this much ETH principal. Enforced by both `pendingRebalance()` and\n    /// `rebalance()`.\n    uint256 public rebalanceEthThreshold;\n    /// @notice Maximum ETH tip paid to whoever calls permissionless `rebalance()` for worthwhile work.\n    /// Actual payment is bounded by the pool fee on measured work, held back from deployment, and paid\n    /// after the unlock. `0` disables tipping (the protocol runs its own keeper).\n    uint256 public keeperReward;\n    uint256 internal constant MAX_KEEPER_REWARD = 0.1 ether;\n\n    /// @notice Rate-limited follower of the previous block's closing tick: the target the placement\n    /// floor decays toward. A transaction cannot move it (it is promoted at the next block boundary),\n    /// and one block can move it by at most `maxRefStep`, so a momentary price yank cannot become the\n    /// decay target. Maintained in `afterSwap` by `_observeTick`.\n    int24 public refTick;\n    int24 internal curBlockTick; // running tick within the current block\n    uint64 internal refBlock; // block `curBlockTick` belongs to\n    /// @notice Max ticks `refTick` may advance per block toward the previous block's close. Owner-set\n    /// within [1, ceiling]. Smaller = harder to poison but slower to track genuine moves.\n    int24 public maxRefStep;\n    int24 internal constant DEFAULT_MAX_REF_STEP = 200;\n    int24 internal constant MAX_TICK_RATE_CEIL = 2000;\n\n    /// @notice Lowest tick a backstop band may start at (raw; aligned up to `tickSpacing` when used).\n    /// It jumps to one tick above any tick the pool trades at, immediately, because a higher floor only\n    /// ever moves the bid to cheaper IMD. It comes back down only through `_updateDeploymentFloor`, at\n    /// most `floorDecayTicksPerDay` toward `refTick + 1`. That asymmetry is the whole placement guard:\n    /// a caller can push spot anywhere in one transaction, but relocating retained ETH to a level the\n    /// market has not held costs `gap / floorDecayTicksPerDay` days of sustaining that price against\n    /// every holder who wants to sell into it. Nothing lowers it faster; there is no owner reset.\n    int24 public deploymentFloorTick;\n    /// @notice How fast the floor may follow a genuine price recovery, in ticks per day. Owner-set within\n    /// [1, `MAX_TICK_RATE_CEIL`]; a higher rate tracks recoveries sooner and shortens the holding period\n    /// a manipulator must sustain. ~400 ticks ≈ 4% per day.\n    uint256 public floorDecayTicksPerDay;\n    uint256 internal constant DEFAULT_FLOOR_DECAY_PER_DAY = 400;\n    /// @dev Clock and sub-tick remainder (tick·seconds) for the floor decay, same shape as the cap\n    /// decay: fragments smaller than one tick still add up, so continuous trading cannot starve the decay\n    /// by rounding, and the allowance is evaluated over at most one day so idle time is not banked.\n    uint256 internal lastFloorDecayAt;\n    uint256 internal floorDecayRemainder;\n\n    // --- market state ------------------------------------------------------\n    uint256 public inventoryCap;\n    uint128 public positionLiquidity;\n    uint256 public retainedEth;\n    uint256 public totalBurned;\n    uint256 public totalRewarded;\n    bool public marketOpen;\n\n    // --- deferred settlement ----------------------------------------------\n    // v4 settles a swap only when the unlock closes, so while `afterSwap` runs the swapper's\n    // tokens have not physically reached the PoolManager. `take` would move tokens that are not\n    // there yet. Everything the cap removes is therefore claimed as ERC-6909 instead, and anyone\n    // may convert those claims to real transfers afterwards via `settleClaims`.\n    /// @notice Tokens owed to `burnSink`, held as claims until redeemed.\n    uint256 public burnClaims;\n    /// @notice Tokens owed to `rewardsRecipient`, held as claims until redeemed.\n    uint256 public rewardClaims;\n    /// @notice Recovered ETH still held as claims rather than as a real balance.\n    uint256 public ethClaims;\n    /// @dev Block in which claims were last added. Claims only become redeemable in a later block,\n    /// because the swap that produced them settles when its own unlock closes.\n    uint256 public lastClaimBlock;\n\n    // --- trading-fee ledger -----------------------------------------------\n    // The pool's 1% LP fee is the protocol's revenue. It is collected on every swap and held here,\n    // fully separate from the burn/reward/retained ledgers, until the owner withdraws it. Kept as\n    // ERC-6909 claims for the same deferred-settlement reason as the burn ledger.\n    /// @notice Token-side trading fees held as claims, awaiting `withdrawFees`.\n    uint256 public feeTokenClaims;\n    /// @notice ETH-side trading fees held as claims, awaiting `withdrawFees`.\n    uint256 public feeEthClaims;\n    /// @notice Lifetime trading fees collected, for reporting (never decreases).\n    uint256 public totalFeeToken;\n    uint256 public totalFeeEth;\n\n    uint8 private constant ACTION_OPEN = 1;\n    uint8 private constant ACTION_REBALANCE = 2;\n    uint8 private constant ACTION_CLOSE_BACKSTOP = 3;\n    uint8 private constant ACTION_CLOSE_MARKET = 4;\n    uint8 private constant ACTION_SETTLE_CLAIMS = 5;\n    uint8 private constant ACTION_WITHDRAW_FEES = 6;\n    uint8 private constant ACTION_SETTLE_ETH = 7;\n    bool private _callbackExpected;\n\n    constructor(\n        address owner_,\n        IPoolManager poolManager_,\n        address token_,\n        address burnSink_,\n        address rewardsRecipient_,\n        uint256 rewardShareBps_,\n        uint256 minTrimTokens_,\n        uint24 lpFee_,\n        int24 tickSpacing_\n    ) {\n        if (\n            owner_ == address(0) || address(poolManager_) == address(0) || token_ == address(0)\n                || burnSink_ == address(0) || rewardsRecipient_ == address(0) || rewardShareBps_ > MAX_REWARD_SHARE_BPS\n                || lpFee_ > 1_000_000 || tickSpacing_ <= 0 || tickSpacing_ > TickMath.MAX_TICK_SPACING\n        ) revert InvalidConfiguration();\n\n        _initializeOwner(owner_);\n        poolManager = poolManager_;\n        token = token_;\n        burnSink = burnSink_;\n        rewardsRecipient = rewardsRecipient_;\n        rewardShareBps = rewardShareBps_;\n        minTrimTokens = minTrimTokens_;\n        lpFee = lpFee_;\n        tickSpacing = tickSpacing_;\n        tickLower = TickMath.minUsableTick(tickSpacing_);\n        tickUpper = TickMath.maxUsableTick(tickSpacing_);\n\n        ratchetBps = BPS_DENOMINATOR;\n        rebalanceEnabled = true;\n        rebalanceEthThreshold = 0.1 ether;\n        keeperReward = 0.002 ether; // small default tip; owner tunes (≤ threshold, ≤ MAX_KEEPER_REWARD)\n        maxRefStep = DEFAULT_MAX_REF_STEP;\n        floorDecayTicksPerDay = DEFAULT_FLOOR_DECAY_PER_DAY;\n\n        Hooks.validateHookPermissions(IHooks(address(this)), getHookPermissions());\n    }\n\n    receive() external payable {\n        if (msg.sender != address(poolManager)) revert InvalidPoolManagerCaller();\n    }\n\n    // -------------------------------------------------------------------------\n    // Views\n    // -------------------------------------------------------------------------\n\n    function poolKey() public view returns (PoolKey memory key) {\n        key = PoolKey({\n            currency0: CurrencyLibrary.ADDRESS_ZERO,\n            currency1: Currency.wrap(token),\n            fee: lpFee,\n            tickSpacing: tickSpacing,\n            hooks: IHooks(address(this))\n        });\n    }\n\n    function poolId() public view returns (PoolId) {\n        return poolKey().toId();\n    }\n\n    function currentSqrtPriceX96() public view returns (uint160 sqrtPriceX96) {\n        (sqrtPriceX96,,,) = poolManager.getSlot0(poolId());\n    }\n\n    function currentTick() public view returns (int24 tick) {\n        (, tick,,) = poolManager.getSlot0(poolId());\n    }\n\n    /// @notice Tokens held by the market position. The bid is accounted separately.\n    function tokensInPool() public view returns (uint256) {\n        if (positionLiquidity == 0) return 0;\n        return SqrtPriceMath.getAmount1Delta(\n            TickMath.getSqrtPriceAtTick(tickLower), currentSqrtPriceX96(), positionLiquidity, false\n        );\n    }\n\n    /// @notice ETH held by the market position.\n    function ethInPool() public view returns (uint256) {\n        if (positionLiquidity == 0) return 0;\n        return SqrtPriceMath.getAmount0Delta(\n            currentSqrtPriceX96(), TickMath.getSqrtPriceAtTick(tickUpper), positionLiquidity, false\n        );\n    }\n\n    function pendingTrim() public view returns (uint256) {\n        uint256 held = tokensInPool();\n        uint256 excess = held > inventoryCap ? held - inventoryCap : 0;\n        // Mirror _applyCap: an excess below minTrimTokens is not trimmed by the next swap, so report 0.\n        return excess < minTrimTokens ? 0 : excess;\n    }\n\n    /// @notice ETH principal the live backstop has actually converted into tokens at the current\n    /// price. Accrued LP fees are separate and are not included. At the exact lower boundary this is\n    /// zero apart from at most rounding dust, unlike a tick-only fill predicate.\n    function backstopConvertedEth() public view returns (uint256 converted) {\n        Band memory b = backstop;\n        uint256 principal = backstopEthPrincipal;\n        if (b.liquidity == 0 || principal == 0) return 0;\n\n        uint160 sqrtPriceX96 = currentSqrtPriceX96();\n        uint160 sqrtLowerX96 = TickMath.getSqrtPriceAtTick(b.tickLower);\n        uint160 sqrtUpperX96 = TickMath.getSqrtPriceAtTick(b.tickUpper);\n        uint256 ethRemaining;\n\n        if (sqrtPriceX96 <= sqrtLowerX96) {\n            ethRemaining = SqrtPriceMath.getAmount0Delta(sqrtLowerX96, sqrtUpperX96, b.liquidity, false);\n        } else if (sqrtPriceX96 < sqrtUpperX96) {\n            ethRemaining = SqrtPriceMath.getAmount0Delta(sqrtPriceX96, sqrtUpperX96, b.liquidity, false);\n        }\n\n        // Adding liquidity rounds principal up while removing it rounds down, so an untouched band may\n        // differ by a wei. The material-fill threshold below makes that dust non-rewardable.\n        return principal > ethRemaining ? principal - ethRemaining : 0;\n    }\n\n    /// @notice Minimum converted ETH that makes the current backstop permissionlessly settleable.\n    /// A band smaller than the global threshold must be fully converted rather than becoming stuck.\n    function backstopFillThreshold() public view returns (uint256) {\n        uint256 principal = backstopEthPrincipal;\n        if (principal == 0) return 0;\n        uint256 threshold = rebalanceEthThreshold;\n        return threshold < principal ? threshold : principal;\n    }\n\n    /// @notice True only after a material amount of backstop principal has converted into tokens.\n    function backstopIsFilled() public view returns (bool) {\n        uint256 threshold = backstopFillThreshold();\n        return threshold != 0 && backstopConvertedEth() >= threshold;\n    }\n\n    // -------------------------------------------------------------------------\n    // Policy\n    // -------------------------------------------------------------------------\n\n    /// @notice Sets the floor the cap may never ratchet below.\n    function setCapFloor(uint256 newFloor) external onlyOwner {\n        emit CapFloorUpdated(capFloor, newFloor);\n        capFloor = newFloor;\n        if (inventoryCap < newFloor) inventoryCap = newFloor;\n    }\n\n    /// @notice Configures the keeper backstop rebalance: kill switch + the \"worth a poke\" ETH floor.\n    function setRebalance(bool enabled, uint256 ethThreshold) external onlyOwner {\n        // Keep the useful-work threshold strictly above the flat reward. Equality could consume the\n        // entire qualifying idle balance without deploying any backstop liquidity.\n        if (ethThreshold == 0 || ethThreshold <= keeperReward) revert InvalidConfiguration();\n        rebalanceEnabled = enabled;\n        rebalanceEthThreshold = ethThreshold;\n        emit RebalanceConfigUpdated(enabled, ethThreshold);\n    }\n\n    /// @notice Sets the maximum ETH tip for permissionless keeper work. Actual payment is additionally\n    /// bounded by `lpFee` applied to measured idle/converted ETH. `0` turns tipping off.\n    function setKeeperReward(uint256 reward) external onlyOwner {\n        if (reward > MAX_KEEPER_REWARD || reward >= rebalanceEthThreshold) revert InvalidConfiguration();\n        keeperReward = reward;\n        emit KeeperRewardUpdated(reward);\n    }\n\n    /// @notice Tunes how far `refTick` may advance per block toward the previous block's close. Lower =\n    /// the reference is harder to poison (a distant move takes more blocks) but tracks genuine price moves\n    /// more slowly; bounded so it can never be set to jump arbitrarily far in one block.\n    function setMaxRefStep(int24 maxStep) external onlyOwner {\n        if (maxStep <= 0 || maxStep > MAX_TICK_RATE_CEIL) revert InvalidConfiguration();\n        maxRefStep = maxStep;\n        emit MaxRefStepUpdated(maxStep);\n    }\n\n    /// @notice Sets how fast the placement floor may follow a price recovery, in ticks per day. Bounded\n    /// away from zero (a frozen floor would strand the backstop above every recovery with no way back)\n    /// and from above (a floor that can drop thousands of ticks a day is a block-paced follower again).\n    function setFloorDecay(uint256 ticksPerDay) external onlyOwner {\n        if (ticksPerDay == 0 || ticksPerDay > uint256(uint24(MAX_TICK_RATE_CEIL))) revert InvalidConfiguration();\n        // Re-seat the clock so the new rate paces from now, as setCapDecay does for the cap.\n        lastFloorDecayAt = block.timestamp;\n        floorDecayRemainder = 0;\n        floorDecayTicksPerDay = ticksPerDay;\n        emit FloorDecayUpdated(ticksPerDay);\n    }\n\n    /// @notice Sets how fast the cap may ratchet down, in tokens per day.\n    function setCapDecay(uint256 tokensPerDay) external onlyOwner {\n        if (tokensPerDay > MAX_CAP_DECAY_PER_DAY) revert InvalidConfiguration();\n        // Re-seat the clock so the new rate paces from now on. Without this, the whole idle backlog\n        // accrued under the old rate would be spendable at the new rate on the very next ratchet.\n        lastCapDecayAt = block.timestamp;\n        capDecayRemainder = 0;\n        capDecayTokensPerDay = tokensPerDay;\n        emit CapDecayUpdated(tokensPerDay);\n    }\n\n    function setRatchetBps(uint256 newRatchetBps) external onlyOwner {\n        if (newRatchetBps > BPS_DENOMINATOR) revert InvalidConfiguration();\n        emit RatchetUpdated(ratchetBps, newRatchetBps);\n        ratchetBps = newRatchetBps;\n    }\n\n    /// @notice Redirects the burn destination for future trims.\n    /// @dev Only future settlements are affected; already-accrued `burnClaims` settle to whatever\n    /// `burnSink` is at settlement time, so `settleClaims()` first if the old sink must receive them.\n    function setBurnSink(address newBurnSink) external onlyOwner {\n        if (newBurnSink == address(0)) revert InvalidConfiguration();\n        emit BurnSinkUpdated(burnSink, newBurnSink);\n        burnSink = newBurnSink;\n    }\n\n    /// @notice Redirects the reward-share destination (e.g. to a new staking dripper) for future trims.\n    /// @dev Only future settlements are affected; already-accrued `rewardClaims` settle to whatever\n    /// `rewardsRecipient` is at settlement time, so `settleClaims()` first if the old recipient must\n    /// receive them.\n    function setRewardsRecipient(address newRewardsRecipient) external onlyOwner {\n        if (newRewardsRecipient == address(0)) revert InvalidConfiguration();\n        emit RewardsRecipientUpdated(rewardsRecipient, newRewardsRecipient);\n        rewardsRecipient = newRewardsRecipient;\n    }\n\n    /// @notice Tunes the burn/reward split — the share of each trim skimmed to `rewardsRecipient` instead\n    /// of burned (e.g. 2000 = 20% reward / 80% burn). Capped at `MAX_REWARD_SHARE_BPS` (30%) so burning\n    /// always dominates and no owner can turn the deflation off or redirect the whole trim. Only future\n    /// trims are affected; `settleClaims()` first to settle already-accrued claims under the old split.\n    function setRewardShareBps(uint256 bps) external onlyOwner {\n        if (bps > MAX_REWARD_SHARE_BPS) revert InvalidConfiguration();\n        emit RewardShareUpdated(rewardShareBps, bps);\n        rewardShareBps = bps;\n    }\n\n    // -------------------------------------------------------------------------\n    // Launch and teardown\n    // -------------------------------------------------------------------------\n\n    function initializePool(uint160 sqrtPriceX96) external onlyOwner {\n        int24 tick = poolManager.initialize(poolKey(), sqrtPriceX96);\n        emit PoolInitialized(sqrtPriceX96, tick);\n    }\n\n    /// @notice Adds the market position and freezes the starting cap at the tokens deposited.\n    /// @dev Send at least the ETH v4 requires; the surplus is refunded.\n    function openMarket(uint128 liquidity, uint256 maximumTokenAmount, uint256 capFloor_, uint256 capDecayTokensPerDay_)\n        external\n        payable\n        onlyOwner\n    {\n        if (marketOpen) revert AlreadyOpen();\n        if (liquidity == 0) revert InvalidLiquidity();\n        if (capDecayTokensPerDay_ > MAX_CAP_DECAY_PER_DAY) revert InvalidConfiguration();\n        if (currentSqrtPriceX96() == 0) revert PoolNotInitialized();\n\n        bytes memory result =\n            _unlock(abi.encode(ACTION_OPEN, abi.encode(msg.sender, liquidity, msg.value, maximumTokenAmount)));\n        (uint256 ethDeposited, uint256 tokensDeposited) = abi.decode(result, (uint256, uint256));\n\n        marketOpen = true;\n        positionLiquidity = liquidity;\n        refTick = currentTick(); // seed the rebalance reference at the opening price\n        curBlockTick = currentTick();\n        refBlock = uint64(block.number);\n        deploymentFloorTick = _tickAbove(currentTick());\n        lastFloorDecayAt = block.timestamp;\n        floorDecayRemainder = 0;\n        inventoryCap = tokensDeposited;\n        capFloor = capFloor_;\n        // Keep inventoryCap >= capFloor at open, exactly as setCapFloor does. Without this, a\n        // capFloor_ above the deposited inventory opens the market already violating the invariant,\n        // leaving capFloor dead: it neither raises the cap nor gates the ratchet.\n        if (inventoryCap < capFloor_) inventoryCap = capFloor_;\n        capDecayTokensPerDay = capDecayTokensPerDay_;\n        // Reseat the decay clock and clear any carried remainder, the same reset setCapDecay and\n        // fundInventory perform. On a fresh deploy the remainder is already zero; this matters only if\n        // a closed market is ever reopened, so it inherits no stale sub-quantum decay debt.\n        lastCapDecayAt = block.timestamp;\n        capDecayRemainder = 0;\n        if (msg.value > ethDeposited) SafeTransferLib.safeTransferETH(msg.sender, msg.value - ethDeposited);\n        emit MarketOpened(liquidity, ethDeposited, tokensDeposited);\n    }\n\n    /// @notice Adds inventory to a shrunken market and raises the cap to match.\n    /// @dev The counterpart to the ratchet. Without this the cap only ever falls, so a market that\n    /// has burned its way down can never be re-seeded without closing and redeploying. Liquidity is\n    /// proportional, so this consumes both tokens and ETH; send at least what v4 asks for and the\n    /// surplus is refunded.\n    function fundInventory(uint128 liquidity, uint256 maximumTokenAmount) external payable onlyOwner {\n        if (!marketOpen) revert MarketNotOpen();\n        if (liquidity == 0) revert InvalidLiquidity();\n\n        bytes memory result =\n            _unlock(abi.encode(ACTION_OPEN, abi.encode(msg.sender, liquidity, msg.value, maximumTokenAmount)));\n        (uint256 ethDeposited, uint256 tokensDeposited) = abi.decode(result, (uint256, uint256));\n\n        positionLiquidity += liquidity;\n        inventoryCap += tokensDeposited;\n        // Re-seat the decay clock the way openMarket does. Without this, allowance accrued while the\n        // market sat at the old (smaller) cap would apply to the freshly funded inventory, letting\n        // one swap ratchet the re-seeded tokens straight back down toward capFloor.\n        lastCapDecayAt = block.timestamp;\n        capDecayRemainder = 0;\n        if (msg.value > ethDeposited) SafeTransferLib.safeTransferETH(msg.sender, msg.value - ethDeposited);\n        emit InventoryFunded(liquidity, ethDeposited, tokensDeposited, inventoryCap);\n    }\n\n    /// @notice Withdraws the market position and any live bid, returning both legs to `recipient`.\n    ///\n    /// @dev Deliberately unrestricted, and deliberately the one privileged escape hatch. The hook\n    /// holds the protocol's entire market position inside a v4 pool it cannot upgrade: if a defect\n    /// is found in the cap, ladder or claim accounting, or in the PoolManager itself, this is the\n    /// only way to move funds to safety and redeploy. Gating it on exhaustion or a timelock would\n    /// make it useless in precisely the situation it exists for.\n    ///\n    /// The trade is explicit and must be disclosed: the owner can withdraw the entire position at\n    /// any moment, including from a healthy market. Holders are trusting the owner not to, not the\n    /// contract to prevent it. Mitigation belongs at the ownership layer - a multisig or timelocked\n    /// owner - not in this function.\n    ///\n    /// Terminal: `marketOpen` cannot return to true, so a closed market is redeployed, not reopened.\n    function closeMarket(address recipient) external onlyOwner {\n        if (!marketOpen) revert MarketNotOpen();\n        if (recipient == address(0)) revert InvalidConfiguration();\n        // Escape-hatch resilience: a stuck claim (e.g. a blacklisting token to burnSink/rewardsRecipient)\n        // must not brick this recovery. Settle best-effort, and cap the final ETH payout at the balance\n        // actually held so an unredeemed ETH claim cannot revert the withdrawal of the position itself.\n        try this.settleClaims() {} catch {}\n\n        try this.closeBackstopSelf() {} catch {} // wrapped so a close revert can't brick the recovery\n\n        try this.settleClaims() {} catch {} // unwinding the backstop may have claimed more\n        // Guarantee the retained ETH is realised even if a blacklisting token reverted the settles above\n        // (F5): the ETH-only settle can never be blocked by a token, so retainedEth is fully backed by\n        // real balance before the payout — no orphaned ETH.\n        try this.settleEthClaims() {} catch {}\n        bytes memory result = _unlock(abi.encode(ACTION_CLOSE_MARKET, abi.encode(recipient)));\n        (uint256 ethOut, uint256 tokensOut) = abi.decode(result, (uint256, uint256));\n\n        marketOpen = false;\n        positionLiquidity = 0;\n\n        uint256 ethToSend = ethOut + retainedEth;\n        retainedEth = 0;\n        uint256 bal = address(this).balance;\n        if (ethToSend > bal) ethToSend = bal;\n        if (ethToSend != 0) SafeTransferLib.safeTransferETH(recipient, ethToSend);\n        emit MarketClosed(recipient, ethToSend, tokensOut);\n    }\n\n    function withdrawRetainedEth(address recipient, uint256 amount) external onlyOwner {\n        if (recipient == address(0)) revert InvalidConfiguration();\n        if (amount == 0 || amount > retainedEth) revert InvalidConfiguration();\n        try this.settleClaims() {} catch {} // a stuck claim must not block a retained-ETH withdrawal\n        try this.settleEthClaims() {} catch {} // and realise the ETH leg even if a token settle reverted (F5)\n        retainedEth -= amount;\n        SafeTransferLib.safeTransferETH(recipient, amount);\n        emit RetainedEthWithdrawn(recipient, amount);\n    }\n\n    /// @notice Sends the accumulated trading-fee revenue (token + ETH) to `recipient`. The fee ledger\n    /// is entirely separate from the burn/reward/retained ledgers, so this touches nothing else.\n    function withdrawFees(address recipient) external onlyOwner {\n        if (recipient == address(0)) revert InvalidConfiguration();\n        if (feeTokenClaims == 0 && feeEthClaims == 0) return;\n        _unlock(abi.encode(ACTION_WITHDRAW_FEES, abi.encode(recipient)));\n    }\n\n    // -------------------------------------------------------------------------\n    // Backstop\n    // -------------------------------------------------------------------------\n\n    /// @notice Permissionless keeper entry, and the only rebalance path (the owner uses it too). It runs\n    /// only when idle retained ETH reaches the configured threshold or the live backstop has materially\n    /// converted principal into tokens. Idle ETH cannot re-qualify: a rebalance deploys all of it, so\n    /// the gate is only re-armed by fresh trims (or an owner `closeBackstop`, which is real work).\n    /// Every deployment is floored at `deploymentFloorTick`, so nothing a caller does to spot in this\n    /// transaction can relocate retained ETH below a level the market has held.\n    function rebalance() external {\n        if (!marketOpen) revert MarketNotOpen();\n        uint256 idle = retainedEth;\n        uint256 converted = backstopConvertedEth();\n        bool idleReady = idle >= rebalanceEthThreshold;\n        if (!idleReady && !_materiallyFilled(converted)) revert RebalanceNotNeeded();\n\n        // The configured reward is a ceiling, not an unconditional flat payment. Both idle deployment\n        // and fill settlement are bounded by the pool fee on measured work, so manufacturing either\n        // trigger cannot earn more than the fee paid to create it.\n        uint256 tip = _keeperRewardDue(idleReady ? idle : 0, converted);\n        if (_rebalanceGuarded(tip) && tip != 0) _payKeeper(msg.sender, tip);\n    }\n\n    /// @notice Closes the backstop by hand: the tokens it bought are burned, its ETH returns to\n    /// `retainedEth`. Removing liquidity is price-neutral, so this needs no reference guard.\n    function closeBackstop() external onlyOwner {\n        if (backstop.liquidity == 0) return;\n        _unlock(abi.encode(ACTION_CLOSE_BACKSTOP, bytes(\"\")));\n    }\n\n    /// @notice Whether a keeper `rebalance()` would currently do useful work. The checker for an\n    /// automation task: call `rebalance()` whenever this is true.\n    function pendingRebalance() external view returns (bool) {\n        if (!rebalanceEnabled || !marketOpen || positionLiquidity == 0) return false;\n        return retainedEth >= rebalanceEthThreshold || _materiallyFilled(backstopConvertedEth());\n    }\n\n    /// @dev Brings the placement floor up to date, then deploys the band no lower than it. Live spot only\n    /// ever pushes the band UP (the safe direction); the floor is what stops it going down.\n    function _rebalanceGuarded(uint256 rewardHoldback) internal returns (bool worked) {\n        if (!rebalanceEnabled) revert RebalanceDisabled();\n        int24 spot = currentTick();\n        _updateDeploymentFloor(spot);\n        int24 lower = spot + 1;\n        if (lower < deploymentFloorTick) lower = deploymentFloorTick;\n        lower = _alignUp(lower);\n        bytes memory res = _unlock(abi.encode(ACTION_REBALANCE, abi.encode(lower, rewardHoldback)));\n        return abi.decode(res, (bool));\n    }\n\n    function _materiallyFilled(uint256 converted) internal view returns (bool) {\n        uint256 threshold = backstopFillThreshold();\n        return threshold != 0 && converted >= threshold;\n    }\n\n    /// @dev The keeper tip for an already-qualified rebalance. The configured flat value is only a\n    /// ceiling: actual payment is capped by the LP fee on measured useful work. This makes a\n    /// self-manufactured idle balance or fill fee-dominated even before gas, and safely reduces the tip\n    /// to zero for a zero-fee pool.\n    function _keeperRewardDue(uint256 qualifyingIdleEth, uint256 converted) internal view returns (uint256) {\n        if (keeperReward == 0 || !rebalanceEnabled) return 0;\n        if (positionLiquidity == 0) return 0; // degenerate (capFloor==0): _rebalanceTo no-ops, so no tip\n\n        uint256 workValue = converted;\n        if (qualifyingIdleEth > workValue) workValue = qualifyingIdleEth;\n        uint256 feeBound = workValue.fullMulDiv(lpFee, FEE_DENOMINATOR);\n        return feeBound < keeperReward ? feeBound : keeperReward;\n    }\n\n    /// @dev Pays the held-back keeper tip out of retained ETH, CEI-safe: realise the ETH, debit the\n    /// backing, then transfer last. Capped at `retainedEth` so it can never over-pay.\n    function _payKeeper(address keeper, uint256 reward) internal {\n        if (reward > retainedEth) reward = retainedEth;\n        if (reward == 0) return;\n        settleEthClaims(); // realise ETH so a real transfer is funded (no-op if already realised)\n        retainedEth -= reward;\n        emit KeeperRewardPaid(keeper, reward);\n        SafeTransferLib.safeTransferETH(keeper, reward);\n    }\n\n    /// @dev Settles the current backstop (burning what it bought), then redeploys all retained ETH as\n    /// one fresh single-sided band with lower tick `lower` (computed by `_rebalanceGuarded`). Runs\n    /// inside an unlock.\n    function _rebalanceTo(int24 lower, uint256 rewardHoldback) internal returns (bool worked) {\n        if (positionLiquidity == 0) return false;\n        bool closed = _closeBackstop(); // re-credits the old band's ETH into retainedEth\n        // Hold back the keeper tip (capped at what's actually retained) so the deploy leaves it behind;\n        // `_payKeeper` transfers it after the unlock closes.\n        uint256 hold = rewardHoldback;\n        if (hold > retainedEth) hold = retainedEth;\n        uint256 ethUsed = _deployBackstop(retainedEth - hold, lower);\n        emit Rebalanced(lower);\n        // \"Worked\" = something actually happened (a band was closed or ETH was deployed). A pure no-op\n        // (nothing to close and nothing deployable — e.g. lower >= tickUpper) earns no keeper tip.\n        return closed || ethUsed != 0;\n    }\n\n    /// @dev Removes the whole backstop: its ETH accrues to `retainedEth`, the tokens it bought are\n    /// burned. Removing liquidity is not a swap, so the price is untouched.\n    function _closeBackstop() internal returns (bool) {\n        Band memory b = backstop;\n        if (b.liquidity == 0) return false;\n        uint160 priceBefore = currentSqrtPriceX96();\n\n        // Route the backstop's own LP fees to the fee ledger first, so the removal below returns pure\n        // principal (the tokens the backstop bought), which is what gets burned.\n        _collectFees(b.tickLower, b.tickUpper);\n        (uint256 ethOut, uint256 tokensOut) = _removeLiquidity(b.tickLower, b.tickUpper, b.liquidity);\n        delete backstop;\n        backstopEthPrincipal = 0;\n\n        _claimEth(ethOut);\n        (uint256 burned, uint256 rewarded) = _disperse(tokensOut);\n\n        _requirePriceUnchanged(priceBefore);\n        emit BackstopSettled(b.liquidity, burned, rewarded, ethOut);\n        return true;\n    }\n\n    /// @dev Deploys `ethAmount` of retained ETH as one single-sided ETH band `[lower, tickUpper]`, and\n    /// returns the ETH actually consumed (0 on a no-op). The caller (`_rebalanceGuarded`) has already\n    /// floored `lower` at the reference, so this never prices off unclamped live spot. Whatever the\n    /// inversion cannot place stays in `retainedEth`.\n    function _deployBackstop(uint256 ethAmount, int24 lower) internal returns (uint256) {\n        if (ethAmount == 0) return 0;\n        if (lower >= tickUpper) return 0;\n\n        (uint128 liquidity, uint256 ethUsed) = _addBandLiquidity(lower, tickUpper, ethAmount);\n        backstop = Band({tickLower: lower, tickUpper: tickUpper, liquidity: liquidity});\n        backstopEthPrincipal = ethUsed;\n        emit BackstopDeployed(lower, tickUpper, liquidity, ethUsed);\n        return ethUsed;\n    }\n\n    /// @dev Adds single-sided ETH over `[lower, upper]`. Must run inside an unlock. Reverts unless\n    /// the range sits entirely above the current price, the invariant that makes it cost no tokens.\n    function _addBandLiquidity(int24 lower, int24 upper, uint256 ethAmount)\n        internal\n        returns (uint128 liquidity, uint256 ethUsed)\n    {\n        uint160 sqrtLower = TickMath.getSqrtPriceAtTick(lower);\n        uint160 sqrtUpper = TickMath.getSqrtPriceAtTick(upper);\n\n        // Invert amount0 = L * (sqrtB - sqrtA) * 2^96 / (sqrtA * sqrtB) for L.\n        uint256 product = uint256(sqrtLower).fullMulDiv(uint256(sqrtUpper), 1 << 96);\n        uint256 computed = ethAmount.fullMulDiv(product, uint256(sqrtUpper) - uint256(sqrtLower));\n        if (computed == 0 || computed > type(uint128).max) revert InvalidLiquidity();\n        liquidity = uint128(computed);\n\n        uint160 priceBefore = currentSqrtPriceX96();\n        (BalanceDelta delta,) = poolManager.modifyLiquidity(\n            poolKey(),\n            IPoolManager.ModifyLiquidityParams({\n                tickLower: lower,\n                tickUpper: upper,\n                liquidityDelta: int256(uint256(liquidity)),\n                salt: bytes32(0)\n            }),\n            bytes(\"\")\n        );\n        if (delta.amount0() > 0 || delta.amount1() > 0) revert UnexpectedLiquidityDelta();\n\n        ethUsed = uint256(-int256(delta.amount0()));\n        uint256 tokensRequired = uint256(-int256(delta.amount1()));\n        if (tokensRequired != 0) revert BidNotSingleSided(tokensRequired);\n        if (ethUsed > ethAmount) revert IncorrectEthAmount(ethUsed, ethAmount);\n        _payEth(ethUsed);\n        _requirePriceUnchanged(priceBefore);\n        retainedEth -= ethUsed;\n    }\n\n    /// @dev Settles an ETH debit from claims first, then from the real balance.\n    function _payEth(uint256 amount) internal {\n        if (amount == 0) return;\n        uint256 fromClaims = amount < ethClaims ? amount : ethClaims;\n        if (fromClaims != 0) {\n            ethClaims -= fromClaims;\n            poolManager.burn(address(this), _currencyId(address(0)), fromClaims);\n        }\n        uint256 rest = amount - fromClaims;\n        if (rest != 0) poolManager.settle{value: rest}();\n    }\n\n    function _alignUp(int24 tick) internal view returns (int24) {\n        int24 aligned = (tick / tickSpacing) * tickSpacing;\n        if (aligned < tick) aligned += tickSpacing;\n        return aligned;\n    }\n\n    /// @dev The tick strictly above `tick`, capped at the market position's upper bound so a band at the\n    /// extreme degrades to a no-op deploy rather than an invalid range.\n    function _tickAbove(int24 tick) internal view returns (int24 above) {\n        above = tick + 1;\n        if (above > tickUpper) above = tickUpper;\n    }\n\n    /// @dev Moves the placement floor. Up: instantly, to one tick above any observed tick (a higher floor\n    /// only ever moves the bid to cheaper IMD, so it may follow spot at once). Down: toward `refTick + 1`\n    /// at most `floorDecayTicksPerDay`, paced by wall-clock time. Down is the only direction a\n    /// manipulated placement needs, so it is the only one that costs time: dragging the floor D ticks\n    /// below fair means sustaining a false price for D / floorDecayTicksPerDay days, exposed to every\n    /// seller the whole way. Evaluated on every swap and every rebalance. Elapsed time is clipped to one\n    /// day so an idle stretch cannot be spent in one step, and the sub-tick remainder is carried so\n    /// per-block fragments (a fraction of a tick each) still add up under continuous trading.\n    function _updateDeploymentFloor(int24 observedTick) internal {\n        int24 previous = deploymentFloorTick;\n        int24 floor = previous;\n        uint256 elapsed = block.timestamp - lastFloorDecayAt;\n        if (elapsed != 0) {\n            lastFloorDecayAt = block.timestamp;\n            int24 target = _tickAbove(refTick);\n            if (target < floor) {\n                if (elapsed > 1 days) elapsed = 1 days;\n                uint256 numerator = floorDecayTicksPerDay * elapsed + floorDecayRemainder;\n                uint256 allowed = numerator / 1 days; // <= floorDecayTicksPerDay\n                floorDecayRemainder = numerator % 1 days;\n                uint256 gap = uint256(int256(floor) - int256(target));\n                floor = allowed >= gap ? target : floor - int24(int256(allowed));\n            } else {\n                floorDecayRemainder = 0; // nothing to decay toward: the allowance is not banked\n            }\n        }\n        int24 raise = _tickAbove(observedTick);\n        if (raise > floor) floor = raise;\n        if (floor != previous) {\n            deploymentFloorTick = floor;\n            emit DeploymentFloorUpdated(previous, floor);\n        }\n    }\n\n    // -------------------------------------------------------------------------\n    // Hooks\n    // -------------------------------------------------------------------------\n\n    function getHookPermissions() public pure returns (Hooks.Permissions memory) {\n        return Hooks.Permissions({\n            beforeInitialize: true,\n            afterInitialize: false,\n            beforeAddLiquidity: true,\n            afterAddLiquidity: false,\n            beforeRemoveLiquidity: false,\n            afterRemoveLiquidity: false,\n            beforeSwap: false,\n            afterSwap: true,\n            beforeDonate: false,\n            afterDonate: false,\n            beforeSwapReturnDelta: false,\n            afterSwapReturnDelta: false,\n            afterAddLiquidityReturnDelta: false,\n            afterRemoveLiquidityReturnDelta: false\n        });\n    }\n\n    /// @notice Restricts pool initialization to this hook, i.e. to the owner via `initializePool`.\n    /// @dev `PoolManager.initialize` is otherwise permissionless, and this hook's pool key is fixed\n    /// entirely by its immutables, so without this guard anyone could front-run the owner and stamp\n    /// a launch price of their choosing into the single pool this hook can ever use. When the owner\n    /// calls `initializePool`, the hook is the caller of `poolManager.initialize`, so `sender` is\n    /// this contract; a direct external `initialize` presents any other `sender` and is rejected.\n    function beforeInitialize(address sender, PoolKey calldata key, uint160) external view returns (bytes4) {\n        _requirePoolManagerAndPool(key);\n        if (sender != address(this)) revert InitializationRestrictedToHook();\n        return IHooks.beforeInitialize.selector;\n    }\n\n    function beforeAddLiquidity(address sender, PoolKey calldata key, IPoolManager.ModifyLiquidityParams calldata, bytes calldata)\n        external\n        view\n        returns (bytes4)\n    {\n        _requirePoolManagerAndPool(key);\n        if (sender != address(this)) revert LiquidityRestrictedToHook();\n        return IHooks.beforeAddLiquidity.selector;\n    }\n\n    /// @notice Applies the cap, then rebalances the backstop. Declares no delta, so the swap the\n    /// router quoted is exactly the swap the trader gets.\n    function afterSwap(address, PoolKey calldata key, IPoolManager.SwapParams calldata, BalanceDelta, bytes calldata)\n        external\n        returns (bytes4, int128)\n    {\n        _requirePoolManagerAndPool(key);\n        _maybeRedeemMaturedClaims();\n        // Realise this swap's LP fee into the fee ledger BEFORE the cap runs. Collecting every swap\n        // means each collection is exactly this trade's fee, and it also leaves the position with no\n        // accrued fees for the trim below to fold into principal.\n        if (positionLiquidity != 0) _collectFees(tickLower, tickUpper);\n        // The cap is the load-bearing invariant, left unwrapped. The backstop rebalance is no longer on\n        // the swap path at all — a keeper drives it (`rebalance()`) off a manipulation-resistant\n        // reference — so nothing here prices off live spot.\n        _applyCap();\n        // Load-bearing placement floor: raised here, before the swap's PoolManager unlock can finish, so a\n        // later rebalance cannot forget an upward price the pool just observed; decayed here too, so it\n        // follows a genuine recovery without anyone having to poke it. Runs before `_observeTick` so the\n        // decay target is the previous block's reference, which this transaction cannot have moved.\n        _updateDeploymentFloor(currentTick());\n        _observeTick(); // maintain the block-lagged reference; no backstop touch on this path\n        return (IHooks.afterSwap.selector, int128(0));\n    }\n\n    /// @dev Advances `refTick` toward the previous block's closing tick, by at most `maxRefStep` (the\n    /// rebalance reference the current transaction cannot influence), then records this swap's tick as the\n    /// running block tick. Rate-limiting the step bounds how far one manipulated block can drag the\n    /// reference — a distant poison then costs many consecutive block-edge captures. Pure snapshot — no\n    /// liquidity op, no external call.\n    function _observeTick() internal {\n        if (block.number != refBlock) {\n            int24 target = curBlockTick;\n            int24 step = maxRefStep;\n            int24 delta = target - refTick; // both are valid ticks; diff fits in int24\n            if (delta > step) target = refTick + step;\n            else if (delta < -step) target = refTick - step;\n            refTick = target; // stays a valid tick: |target - refTick| <= |curBlockTick - refTick|\n            refBlock = uint64(block.number);\n        }\n        curBlockTick = currentTick();\n    }\n\n    // -------------------------------------------------------------------------\n    // Cap\n    // -------------------------------------------------------------------------\n\n    /// @dev Runs inside the PoolManager's existing swap unlock; it must not call `unlock` again.\n    function _applyCap() internal {\n        uint128 liquidity = positionLiquidity;\n        if (liquidity == 0) return;\n\n        uint160 priceBefore = currentSqrtPriceX96();\n        uint256 held =\n            SqrtPriceMath.getAmount1Delta(TickMath.getSqrtPriceAtTick(tickLower), priceBefore, liquidity, false);\n\n        if (held < inventoryCap) {\n            // A buy opened room under the cap. Give back `ratchetBps` of it, but never faster than\n            // the daily decay allowance and never below the floor.\n            uint256 next = inventoryCap - ((inventoryCap - held) * ratchetBps) / BPS_DENOMINATOR;\n\n            uint256 elapsed = block.timestamp - lastCapDecayAt;\n            uint256 allowance = (capDecayTokensPerDay * elapsed) / 1 days;\n            uint256 rateFloor = inventoryCap > allowance ? inventoryCap - allowance : 0;\n            if (next < rateFloor) next = rateFloor;\n            if (next < capFloor) next = capFloor;\n\n            if (next < inventoryCap) {\n                uint256 used = inventoryCap - next;\n                // Advance the clock by the exact time-equivalent of the tokens spent:\n                // used * 1 days / capDecayTokensPerDay, carrying the sub-quantum remainder. The old\n                // form `(elapsed * used) / allowance` floored every ratchet independently, so a\n                // ratchet smaller than one clock-second of allowance advanced the clock by zero\n                // while still lowering the cap - letting many tiny ratchets bypass the rate limit.\n                // The carried remainder guarantees total decay over any window stays within\n                // capDecayTokensPerDay no matter how the reduction is fragmented.\n                if (capDecayTokensPerDay != 0) {\n                    uint256 numerator = used * 1 days + capDecayRemainder;\n                    lastCapDecayAt += numerator / capDecayTokensPerDay;\n                    capDecayRemainder = numerator % capDecayTokensPerDay;\n                }\n                emit CapRatcheted(inventoryCap, next);\n                inventoryCap = next;\n            }\n            return;\n        }\n\n        uint256 excess = held - inventoryCap;\n        if (excess == 0 || excess < minTrimTokens) return;\n\n        // Withdrawals are proportional at a fixed price, so removing this share removes `excess`\n        // tokens and leaves the position at the cap. The division rounds down, so a wei-scale\n        // residue can sit above the cap; that rounds in the pool's favour and does not compound.\n        uint256 liquidityToRemove = FixedPointMathLib.fullMulDiv(liquidity, excess, held);\n        if (liquidityToRemove == 0) return;\n\n        (uint256 ethRemoved, uint256 tokensRemoved) = _removeLiquidity(tickLower, tickUpper, liquidityToRemove);\n        positionLiquidity = liquidity - uint128(liquidityToRemove);\n\n        _claimEth(ethRemoved);\n        (uint256 burned, uint256 rewarded) = _disperse(tokensRemoved);\n\n        _requirePriceUnchanged(priceBefore);\n        emit Trimmed(uint128(liquidityToRemove), burned, rewarded, ethRemoved);\n    }\n\n    function _removeLiquidity(int24 lower, int24 upper, uint256 liquidity)\n        internal\n        returns (uint256 ethOut, uint256 tokensOut)\n    {\n        (BalanceDelta delta,) = poolManager.modifyLiquidity(\n            poolKey(),\n            IPoolManager.ModifyLiquidityParams({\n                tickLower: lower,\n                tickUpper: upper,\n                liquidityDelta: -int256(liquidity),\n                salt: bytes32(0)\n            }),\n            bytes(\"\")\n        );\n        if (delta.amount0() < 0 || delta.amount1() < 0) revert UnexpectedLiquidityDelta();\n        ethOut = uint256(int256(delta.amount0()));\n        tokensOut = uint256(int256(delta.amount1()));\n    }\n\n    /// @dev Claims the tokens leaving the pool, splitting them between the sink and the rewards\n    /// recipient. Counted as burned immediately; the physical transfer happens on `settleClaims`.\n    function _disperse(uint256 tokensRemoved) internal returns (uint256 burned, uint256 rewarded) {\n        if (tokensRemoved == 0) return (0, 0);\n        rewarded = FixedPointMathLib.fullMulDiv(tokensRemoved, rewardShareBps, BPS_DENOMINATOR);\n        burned = tokensRemoved - rewarded;\n        poolManager.mint(address(this), _currencyId(token), tokensRemoved);\n        lastClaimBlock = block.number;\n        totalRewarded += rewarded;\n        rewardClaims += rewarded;\n        totalBurned += burned;\n        burnClaims += burned;\n    }\n\n    function _claimEth(uint256 amount) internal {\n        if (amount == 0) return;\n        poolManager.mint(address(this), _currencyId(address(0)), amount);\n        lastClaimBlock = block.number;\n        ethClaims += amount;\n        retainedEth += amount;\n    }\n\n    /// @dev Converts outstanding claims into real transfers. Must run inside an unlock.\n    function _redeemClaims() internal {\n        uint256 toBurn = burnClaims;\n        uint256 toReward = rewardClaims;\n        uint256 toEth = ethClaims;\n        uint256 tokens = toBurn + toReward;\n        if (tokens != 0) {\n            burnClaims = 0;\n            rewardClaims = 0;\n            poolManager.burn(address(this), _currencyId(token), tokens);\n            if (toReward != 0) poolManager.take(Currency.wrap(token), rewardsRecipient, toReward);\n            if (toBurn != 0) poolManager.take(Currency.wrap(token), burnSink, toBurn);\n        }\n        if (toEth != 0) {\n            ethClaims = 0;\n            poolManager.burn(address(this), _currencyId(address(0)), toEth);\n            poolManager.take(CurrencyLibrary.ADDRESS_ZERO, address(this), toEth);\n        }\n        if (tokens != 0 || toEth != 0) emit ClaimsSettled(toBurn, toReward, toEth);\n    }\n\n    /// @dev The ETH leg of `_redeemClaims`, standalone. `take` to `address(this)` (via the PM-only\n    /// `receive()`) can never be blocked by a token, so this always succeeds — it is the escape hatch's\n    /// guarantee that a blacklisting/reverting token cannot strand retained ETH. Must run inside unlock.\n    function _redeemEthClaims() internal {\n        uint256 toEth = ethClaims;\n        if (toEth == 0) return;\n        ethClaims = 0;\n        poolManager.burn(address(this), _currencyId(address(0)), toEth);\n        poolManager.take(CurrencyLibrary.ADDRESS_ZERO, address(this), toEth);\n        emit ClaimsSettled(0, 0, toEth);\n    }\n\n    /// @dev Realises the fee ledger into real transfers to `recipient`. Must run inside an unlock.\n    /// Fee claims are only ever minted by a prior transaction's swap, so they are always fully backed\n    /// by the time this owner call runs.\n    function _withdrawFees(address recipient) internal {\n        uint256 tokenAmount = feeTokenClaims;\n        uint256 ethAmount = feeEthClaims;\n        if (tokenAmount != 0) {\n            feeTokenClaims = 0;\n            poolManager.burn(address(this), _currencyId(token), tokenAmount);\n            poolManager.take(Currency.wrap(token), recipient, tokenAmount);\n        }\n        if (ethAmount != 0) {\n            feeEthClaims = 0;\n            poolManager.burn(address(this), _currencyId(address(0)), ethAmount);\n            poolManager.take(CurrencyLibrary.ADDRESS_ZERO, recipient, ethAmount);\n        }\n        emit FeesWithdrawn(recipient, tokenAmount, ethAmount);\n    }\n\n    function _currencyId(address currency) internal pure returns (uint256) {\n        return uint256(uint160(currency));\n    }\n\n    /// @notice Redeem entry point for the automatic path. Self-only, and always wrapped in\n    /// try/catch so realising a burn can never revert somebody's trade.\n    function redeemClaimsSelf() external {\n        if (msg.sender != address(this)) revert NotSelf();\n        _redeemClaims();\n    }\n\n    /// @notice Self-only backstop close, so `closeMarket` can unwind the band in a try/catch and keep the\n    /// escape hatch's defensive posture: a revert here recovers the main position + retained ETH anyway,\n    /// leaving the band for a later `closeBackstop()`, instead of bricking the whole recovery.\n    function closeBackstopSelf() external {\n        if (msg.sender != address(this)) revert NotSelf();\n        if (backstop.liquidity == 0) return;\n        _unlock(abi.encode(ACTION_CLOSE_BACKSTOP, bytes(\"\")));\n    }\n\n    /// @dev Realises claims left by an earlier block. Claims minted in this block are skipped: the\n    /// tokens backing them have not reached the PoolManager yet, and several swaps can share one\n    /// transaction.\n    function _maybeRedeemMaturedClaims() internal {\n        if (block.number <= lastClaimBlock) return;\n        if (burnClaims == 0 && rewardClaims == 0 && ethClaims == 0) return;\n        try this.redeemClaimsSelf() {} catch {}\n    }\n\n    /// @notice Converts everything the cap has claimed into real transfers. Permissionless: the\n    /// anyone may push it through; it always pays the current burnSink/rewardsRecipient (owner-settable).\n    function settleClaims() public {\n        if (burnClaims == 0 && rewardClaims == 0 && ethClaims == 0) return;\n        _unlock(abi.encode(ACTION_SETTLE_CLAIMS, bytes(\"\")));\n    }\n\n    /// @notice Realises only the ETH claims into real balance — used as the escape hatch's fallback so a\n    /// stuck token settlement (blacklisting sink) can never strand retained ETH. Permissionless.\n    function settleEthClaims() public {\n        if (ethClaims == 0) return;\n        _unlock(abi.encode(ACTION_SETTLE_ETH, bytes(\"\")));\n    }\n\n    function _requirePriceUnchanged(uint160 priceBefore) internal view {\n        uint160 priceAfter = currentSqrtPriceX96();\n        if (priceAfter != priceBefore) revert PriceMovedDuringLiquidityChange(priceBefore, priceAfter);\n    }\n\n    // -------------------------------------------------------------------------\n    // Unlock plumbing\n    // -------------------------------------------------------------------------\n\n    function _unlock(bytes memory data) internal returns (bytes memory) {\n        _callbackExpected = true;\n        return poolManager.unlock(data);\n    }\n\n    function unlockCallback(bytes calldata rawData) external returns (bytes memory) {\n        if (msg.sender != address(poolManager)) revert InvalidPoolManagerCaller();\n        if (!_callbackExpected) revert CallbackNotExpected();\n        _callbackExpected = false;\n\n        (uint8 action, bytes memory payload) = abi.decode(rawData, (uint8, bytes));\n\n        if (action == ACTION_OPEN) {\n            (address payer, uint128 liquidity, uint256 suppliedEth, uint256 maxTokens) =\n                abi.decode(payload, (address, uint128, uint256, uint256));\n            return _addPosition(payer, tickLower, tickUpper, liquidity, suppliedEth, maxTokens);\n        }\n        if (action == ACTION_SETTLE_ETH) {\n            _redeemEthClaims();\n            return \"\";\n        }\n        if (action == ACTION_SETTLE_CLAIMS) {\n            _redeemClaims();\n            return \"\";\n        }\n        if (action == ACTION_WITHDRAW_FEES) {\n            _withdrawFees(abi.decode(payload, (address)));\n            return \"\";\n        }\n        if (action == ACTION_REBALANCE) {\n            (int24 lower, uint256 rewardHoldback) = abi.decode(payload, (int24, uint256));\n            return abi.encode(_rebalanceTo(lower, rewardHoldback));\n        }\n        if (action == ACTION_CLOSE_BACKSTOP) {\n            _closeBackstop();\n            return \"\";\n        }\n        if (action == ACTION_CLOSE_MARKET) {\n            address recipient = abi.decode(payload, (address));\n            uint160 priceBefore = currentSqrtPriceX96();\n            // Realise LP fees into the fee ledger first, so they are not folded into the principal paid\n            // to `recipient` — keeps the fee ledger separate, as at every other liquidity-touching path.\n            if (positionLiquidity != 0) _collectFees(tickLower, tickUpper);\n            (uint256 ethOut, uint256 tokensOut) = _removeLiquidity(tickLower, tickUpper, positionLiquidity);\n            if (ethOut != 0) poolManager.take(CurrencyLibrary.ADDRESS_ZERO, address(this), ethOut);\n            if (tokensOut != 0) poolManager.take(Currency.wrap(token), recipient, tokensOut);\n            _requirePriceUnchanged(priceBefore);\n            return abi.encode(ethOut, tokensOut);\n        }\n        revert CallbackNotExpected();\n    }\n\n    /// @dev Realises the LP fees accrued on the [lower, upper] position into the trading-fee ledger,\n    /// kept fully separate from the burn/reward/retained ledgers. Poking with a zero delta also\n    /// resets the position's fee checkpoint, so a subsequent add or trim in the same transaction sees\n    /// pure principal - which is why this must run before those (a re-add would otherwise fold the\n    /// fees into its caller delta and under-credit `inventoryCap`; a trim would burn them).\n    function _collectFees(int24 lower, int24 upper) internal {\n        (, BalanceDelta feesAccrued) = poolManager.modifyLiquidity(\n            poolKey(),\n            IPoolManager.ModifyLiquidityParams({tickLower: lower, tickUpper: upper, liquidityDelta: 0, salt: bytes32(0)}),\n            bytes(\"\")\n        );\n        int128 ethFees = feesAccrued.amount0();\n        int128 tokenFees = feesAccrued.amount1();\n        uint256 tokenFee = tokenFees > 0 ? uint256(uint128(tokenFees)) : 0;\n        uint256 ethFee = ethFees > 0 ? uint256(uint128(ethFees)) : 0;\n        if (tokenFee != 0) {\n            poolManager.mint(address(this), _currencyId(token), tokenFee);\n            feeTokenClaims += tokenFee;\n            totalFeeToken += tokenFee;\n        }\n        if (ethFee != 0) {\n            poolManager.mint(address(this), _currencyId(address(0)), ethFee);\n            feeEthClaims += ethFee;\n            totalFeeEth += ethFee;\n        }\n        if (tokenFee != 0 || ethFee != 0) {\n            lastClaimBlock = block.number;\n            emit FeeCollected(tokenFee, ethFee);\n        }\n    }\n\n    function _addPosition(\n        address payer,\n        int24 lower,\n        int24 upper,\n        uint128 liquidity,\n        uint256 ethBudget,\n        uint256 maxTokens\n    ) internal returns (bytes memory) {\n        // A re-add to a position that already earned fees would fold those fees into the caller delta\n        // below, under-crediting inventoryCap. Realise them first so the add's delta is pure\n        // principal. A fresh open (no existing liquidity) has nothing to collect.\n        if (positionLiquidity != 0) _collectFees(lower, upper);\n\n        (BalanceDelta delta,) = poolManager.modifyLiquidity(\n            poolKey(),\n            IPoolManager.ModifyLiquidityParams({\n                tickLower: lower,\n                tickUpper: upper,\n                liquidityDelta: int256(uint256(liquidity)),\n                salt: bytes32(0)\n            }),\n            bytes(\"\")\n        );\n        if (delta.amount0() > 0 || delta.amount1() > 0) revert UnexpectedLiquidityDelta();\n\n        uint256 ethRequired = uint256(-int256(delta.amount0()));\n        uint256 tokensRequired = uint256(-int256(delta.amount1()));\n        if (ethBudget < ethRequired) revert IncorrectEthAmount(ethRequired, ethBudget);\n        if (tokensRequired > maxTokens) revert TokenAmountExceeded(tokensRequired, maxTokens);\n\n        if (ethRequired != 0) poolManager.settle{value: ethRequired}();\n        if (tokensRequired != 0) {\n            poolManager.sync(Currency.wrap(token));\n            if (payer == address(0)) {\n                SafeTransferLib.safeTransfer(token, address(poolManager), tokensRequired);\n            } else {\n                SafeTransferLib.safeTransferFrom(token, payer, address(poolManager), tokensRequired);\n            }\n            poolManager.settle();\n        }\n        return abi.encode(ethRequired, tokensRequired);\n    }\n\n    function _requirePoolManagerAndPool(PoolKey calldata key) internal view {\n        if (msg.sender != address(poolManager)) revert InvalidPoolManagerCaller();\n        if (PoolId.unwrap(key.toId()) != PoolId.unwrap(poolId())) revert InvalidPool();\n    }\n}\n","deployed_bytecode":"0x608080604052600436101561005b575b50361561001a575f80fd5b7f000000000000000000000000000000000004444c5dc75cb358380d2e3de08a906001600160a01b0316330361004c57005b63067e68e760e31b5f5260045ffd5b5f905f3560e01c90816305949ff01461227157508063065e53601461224357806307788b4b146121e757806307ec46d0146121cd578063164e68de146121a25780631668d5bf14612133578063182148ef1461210a5780631a54259c146120985780631a8e22e614611e885780631c5ea67f14611e6a578063251fa3ef14611e515780632569296214611e06578063259982e514611d7757806326387ed614611d5957806335302ff214611cea5780633e0dc34e14611cc45780633ec8779c14611c5f57806340e1e4c714611c4457806341becbce14611c1d578063455835ee14611aff57806347fd03d914611aca5780634fd3c91114611aa857806354d1f13d14611a6257806355b812a814611a2457806355e6294114611a0657806359c4f905146119c85780635ae01c91146119a45780635ff09a2f14611986578063632e4bc31461192057806363ace910146118de5780636723bad1146118c35780636dd16b2c146118a5578063704ce43e14611865578063715018a61461181a57806371d2cc5c146117ff5780637211dc36146117d857806373588d61146117b35780637500d411146117955780637ac776be146117745780637d7c2a1c146115695780637dea18171461152a57806381fdec27146115075780638d2998eb146114e65780638da5cb5b146114b95780638fd56138146114485780639124b5c71461142a57806391dd7346146113d55780639797fab8146113645780639d3ec01614611346578063a1b66c0314611328578063a2d75a981461130a578063a34f5429146112f1578063a4de3ed8146112d3578063a736e27014611244578063a9d2293d14611226578063a9ec75f614611208578063ab48b09e146110cc578063aed29d07146110ae578063b47b2fb114610e7e578063b4c076c614610d08578063b4cc4bb114610cea578063b53cf8ac14610ccc578063b53e716f14610cae578063b7bd346514610c73578063c0f4033714610c5a578063c1d64bfb146109a2578063c4e833ce1461083a578063c66bc04614610817578063c8ca4b691461077f578063c8f6cd9a14610761578063d0c93a7c14610723578063d89135cd14610705578063db445ee8146106e7578063dc4c90d3146106a2578063dc98354e14610635578063e1a4521814610618578063e1e49a41146105ab578063e85d84561461058d578063f04e283e1461053f578063f2fde38b14610503578063f426bce8146104df578063f689c98a146104ad578063fc0c546a14610468578063fee81cf4146104355763ff2a7d300361000f57346104325780600319360112610432576001546040516001600160a01b039091168152602090f35b80fd5b50346104325760203660031901126104325761044f61228b565b9063389a75e1600c5252602080600c2054604051908152f35b50346104325780600319360112610432576040517f000000000000000000000000d34a99bc0f67ae1bbd63c660e6d0b0dd03e263b76001600160a01b03168152602090f35b50346104325780600319360112610432573033036104d0576104cd613d71565b80f35b6314e1dbf760e11b8152600490fd5b50346104325780600319360112610432576020600d5460701c60020b604051908152f35b5060203660031901126104325761051861228b565b610520613427565b8060601b15610532576104cd90613a0b565b637448fbae82526004601cfd5b5060203660031901126104325761055461228b565b61055c613427565b63389a75e1600c528082526020600c20805442116105805790826104cd9255613a0b565b636f5e881883526004601cfd5b50346104325780600319360112610432576020601854604051908152f35b5034610432576020366003190112610432576004356105c8613427565b610bb88111610609577f0470487ff198b72012448e1673140b668fcbc9f5f72732475138fb50711e690460406002548151908152836020820152a160025580f35b63c52a9bd360e01b8252600482fd5b503461043257806003193601126104325760206040516127108152f35b50346104325760e03660031901126104325761064f61228b565b60a036602319011261069e57610663612335565b5061066c613549565b306001600160a01b039091160361068f57604051636e4c1aa760e11b8152602090f35b631db1b77f60e21b8152600490fd5b5080fd5b50346104325780600319360112610432576040517f000000000000000000000000000000000004444c5dc75cb358380d2e3de08a906001600160a01b03168152602090f35b50346104325780600319360112610432576020601154604051908152f35b50346104325780600319360112610432576020601454604051908152f35b503461043257806003193601126104325760206040517f000000000000000000000000000000000000000000000000000000000000003c60020b8152f35b50346104325780600319360112610432576020601b54604051908152f35b50346104325760403660031901126104325760043580151580910361069e576024356107a9613427565b8015801561080b575b6107fc577f9d9245b57fa07ba643fbad2d3378aceb453351bb664fe7e7e65f5b2f8586ea559160409160ff19600a541660ff831617600a5580600b5582519182526020820152a180f35b63c52a9bd360e01b8352600483fd5b50600c548111156107b2565b5034610432578060031936011261043257602060ff601654166040519015158152f35b50346104325780600319360112610432576020816101c0926101a060405161086181612384565b82815282858201528260408201528260608201528260808201528260a08201528260c08201528260e082015282610100820152826101208201528261014082015282610160820152826101808201520152806040516108bf81612384565b600181528381018281526040820160018152606083018481526080840185815260a0850186815260c086019087825260e0870192600184526101008801948986526101208901968a88526101408a01988b8a526101a06101608c019b8d8d5261018081019d8e52019c8d526040519d8e916001835251151591015251151560408d015251151560608c015251151560808b015251151560a08a015251151560c089015251151560e08801525115156101008701525115156101208601525115156101408501525115156101608401525115156101808301525115156101a0820152f35b506080366003190112610432576109b761234b565b604435606435916109c6613427565b60ff60165416610c4b576001600160801b038116928315610c3c576001600160801b038111610c2d577f000000000000000000000000000000000004444c5dc75cb358380d2e3de08a9091610a2560a0610a1e6124c2565b208461336e565b5050506001600160a01b031615610c1e57604080513360208201526001600160801b03909216908201523460608281019190915260243560808301527f4a16fcf994dd2b8d8fbfc45545d642ddf26debffd047664077e7d32726013e8d959094909390929091610ad790610ac890610aa690610ac390610ab48160a0810185565b03601f198101835282612405565b60405192839160208301612426565b613443565b60208082518301019101612583565b939092600160ff196016541617601655856001600160801b03196012541617601255610b0d60a0610b066124c2565b208261336e565b50509050600d548162ffffff1662ffffff19821617600d5565ffffff000000610ba0610b97610b4660a0610b3f6124c2565b208761336e565b5050905060181b9362ffffff6dffffffffffffffff0000000000004360301b169616906dffffffffffffffffffffffffffff1916179585878686161717600d5560a0610b906124c2565b209061336e565b50509050614a55565b60881b62ffffff60881b169362ffffff60881b19169116171717600d5542600f55876010558360115580600455808410610c15575b506005554260065585600755803411610bfd575b60405192835260208301526040820152a180f35b610c10610c0a823461266b565b3361352d565b610be9565b6011555f610bd5565b63486aa30760e01b8652600486fd5b63c52a9bd360e01b8552600485fd5b631fff968160e01b8552600485fd5b632597e36560e21b8452600484fd5b50346104325780600319360112610432576104cd61330f565b503461043257806003193601126104325760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b50346104325780600319360112610432576020601e54604051908152f35b50346104325780600319360112610432576020601d54604051908152f35b50346104325780600319360112610432576020600954604051908152f35b50604036600319011261043257610d1d61234b565b90610d26613427565b60ff6016541615610e6f576001600160801b0382168015610e6057604080513360208201526001600160801b038516918101919091523460608201526024356080820152610d8590610ac890610aa690610ac390610ab48160a0810185565b939091601254906001600160801b038216016001600160801b038111610e4c5794610e34916001600160801b037ff0274a7918e8f581dc8bab20fdd27a328453e35288ecd49034b3e7928f3a8fca969716906001600160801b03191617601255610df181601154612599565b6011554260065585600755833411610e3a575b6011549060405194859485909493926060926001600160801b036080840197168352602083015260408201520152565b0390a180f35b610e47610c0a853461266b565b610e04565b634e487b7160e01b85526011600452602485fd5b631fff968160e01b8252600482fd5b63300b4e3360e21b8152600490fd5b50346104325761016036600319011261043257610e9961228b565b5060a03660231901126104325760603660c319011261043257610144356001600160401b03811161069e57610ed29036906004016122e4565b5050610edc613549565b610ee4614584565b6001600160801b036012541661105f575b610efd6145f7565b7f000000000000000000000000000000000004444c5dc75cb358380d2e3de08a9090610f38610f2f60a0610a1e6124c2565b50509050614904565b600d546001600160401b038160301c164303610f95575b50610f6060409260a0610b906124c2565b50509050600d549060181b65ffffff000000169065ffffff000000191617600d5581519063b47b2fb160e01b82526020820152f35b918260181c60020b928060701c60020b8160020b610fb381876148e7565b60020b958287131561100d575060409550610f60939291610fd391613b59565b905b62ffffff6dffffffffffffffff0000000000004360301b169216906dffffffffffffffff000000ffffff19161717600d559250610f4f565b9395627fffff19831461104b57916040969391610f60959382880360020b13611038575b5050610fd5565b6110439293506148e7565b905f80611031565b634e487b7160e01b86526011600452602486fd5b6110a97f00000000000000000000000000000000000000000000000000000000000d89b47ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2764c6141d4565b610ef5565b50346104325780600319360112610432576020601554604051908152f35b5034610432576020366003190112610432576110e661228b565b6110ee613427565b6110f66124c2565b60405163313b65df60e11b815291906111139060048401906122a1565b60018060a01b0316908160a482015260208160c4818660018060a01b037f000000000000000000000000000000000004444c5dc75cb358380d2e3de08a90165af19081156111fd578391611199575b507f5f94feb4624474fb875ef3acdf106e9f8e1b7ad0881a6a86f1e67f67ccd4e5b491604091825191825260020b6020820152a180f35b90506020813d6020116111f5575b816111b460209383612405565b810103126111f1577f5f94feb4624474fb875ef3acdf106e9f8e1b7ad0881a6a86f1e67f67ccd4e5b4916111e96040926128ac565b915091611162565b8280fd5b3d91506111a7565b6040513d85823e3d90fd5b50346104325780600319360112610432576020600c54604051908152f35b50346104325780600319360112610432576020601a54604051908152f35b5034610432576020366003190112610432576004358060020b908181036111f15761126d613427565b8282138015906112c8575b6107fc577fcfbecc91ba4affcc98e65e63a1fb7465085a80673b10741d6dd1ced65ad1c4c591602091600d549060701b62ffffff60701b169062ffffff60701b191617600d55604051908152a180f35b506107d08213611278565b50346104325780600319360112610432576020600354604051908152f35b50346104325780600319360112610432576104cd6132ce565b50346104325780600319360112610432576020601954604051908152f35b50346104325780600319360112610432576020600b54604051908152f35b50346104325780600319360112610432576020601354604051908152f35b503461043257602036600319011261043257600435611381613427565b67016345785d8a0000811180156113c9575b610609576020817fd314a86face0096456c6272915a80b3881d94f4305db4d09cbe1c2e0b929fe7d92600c55604051908152a180f35b50600b54811015611393565b503461043257602036600319011261043257600435906001600160401b0382116104325761142661141261140c36600486016122e4565b906128ba565b604051918291602083526020830190612311565b0390f35b50346104325780600319360112610432576020600254604051908152f35b5034610432578060031936011261043257602090611464612616565b601154808211156114b1576114789161266b565b7f00000000000000000000000000000000000000000000000000000000000000008110156114aa57505b604051908152f35b90506114a2565b505080611478565b5034610432578060031936011261043257638b78c6d819546040516001600160a01b039091168152602090f35b50346104325780600319360112610432576114ff613427565b6104cd61285b565b5034610432578060031936011261043257602060ff600a54166040519015158152f35b503461043257806003193601126104325760606008546001600160801b03604051918060020b83528060181c60020b602084015260301c166040820152f35b503461043257806003193601126104325760ff6016541615610e6f57601354906115916126ae565b600b54831092838061174f575b6117405791926115b2929061173957613a48565b60ff600a54161561172a576116066115f460a06115cd6124c2565b207f000000000000000000000000000000000004444c5dc75cb358380d2e3de08a9061336e565b5050905061160181614904565b613b3e565b600d5460881c60020b808260020b12611722575b507f000000000000000000000000000000000000000000000000000000000000003c9060020b908060020b801561170e57627fffff1983145f19821416610e4c5780830560020b028060020b908103610e4c576116c292610aa69282610ac3939281126116fd575b50506040519060020b6020820152846040820152604081526116a5606082612405565b604051928391600260208401526040808401526060830190612311565b6020818051810103126111f1576020015180151581036111f157806116f4575b6116ea575080f35b6104cd9033613b77565b508015156116e2565b6117079250613b59565b5f80611682565b634e487b7160e01b85526012600452602485fd5b90505f61161a565b63057fe11960e01b8252600482fd5b5082613a48565b635121f34360e01b8352600483fd5b50611758612361565b8015159081611769575b501561159e565b90508210155f611762565b50346104325780600319360112610432576020600d5460020b604051908152f35b50346104325780600319360112610432576020600654604051908152f35b503461043257806003193601126104325760206117ce6127e7565b6040519015158152f35b503461043257806003193601126104325760206001600160801b0360125416604051908152f35b503461043257806003193601126104325760206114a2612792565b50806003193601126104325761182e613427565b80638b78c6d819547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380638b78c6d8195580f35b5034610432578060031936011261043257602060405162ffffff7f0000000000000000000000000000000000000000000000000000000000002710168152f35b50346104325780600319360112610432576020600454604051908152f35b503461043257806003193601126104325760206114a26126ae565b503461043257806003193601126104325760206118f9612361565b801515908161190e575b506040519015158152f35b90506119186126ae565b101582611903565b50346104325760203660031901126104325760043561193d613427565b7f5e458cfdece54e103be9a698a036358c6e051e5c49ed81cc88922ea2c95a1bf660406004548151908152836020820152a1806004558060115410611980575080f35b60115580f35b50346104325780600319360112610432576020600754604051908152f35b50346104325780600319360112610432576020600d5460881c60020b604051908152f35b503461043257806003193601126104325760206040517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2764c60020b8152f35b50346104325780600319360112610432576020600554604051908152f35b503461043257806003193601126104325760206040517f00000000000000000000000000000000000000000000000000000000000d89b460020b8152f35b50806003193601126104325763389a75e1600c52338152806020600c2055337ffa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c928280a280f35b503461043257806003193601126104325760206040516001600160801b038152f35b50346104325780600319360112610432576020611aea60a06115cd6124c2565b50506040516001600160a01b03909216825250f35b503461043257604036600319011261043257611b1961228b565b602435611b24613427565b6001600160a01b038216918215611c035781158015611c12575b611c0357303b15611bea5760405163c0f4033760e01b81528490818160048183305af1611bee575b5050303b15611bea5760405163251fa3ef60e01b81528490818160048183305af1611bd5575b505081611bcb81602093611bc37f74eb25c53a7388d0aeb904d6988be782d21574be8e6dda40c9e6f393da0317a49660135461266b565b60135561352d565b604051908152a280f35b81611bdf91612405565b611bea57835f611b8c565b8380fd5b81611bf891612405565b611bea57835f611b66565b63c52a9bd360e01b8452600484fd5b506013548211611b3e565b5034610432578060031936011261043257546040516001600160a01b039091168152602090f35b503461043257806003193601126104325760206114a2612616565b503461043257602036600319011261043257600435611c7c613427565b6001600160801b0381116106095760207f0906efadb8cedc0ee7e01d6fc84736c3e6d77db8bfcc9801192a22541709d3b591426006558360075580600555604051908152a180f35b5034610432578060031936011261043257602060a0611ce16124c2565b20604051908152f35b503461043257602036600319011261043257600435611d07613427565b80158015611d4e575b6106095760207f3a1d145815cd352bfcbd4080e799e44213275c8927c6a0c3fd6ac016ae51c0329142600f558360105580600e55604051908152a180f35b506107d08111611d10565b50346104325780600319360112610432576020600e54604051908152f35b50346104325761016036600319011261043257611d9261228b565b60a036602319011261069e5760803660c319011261069e57610144356001600160401b0381116111f157611dca9036906004016122e4565b5050611dd4613549565b306001600160a01b0390911603611df75760405163259982e560e01b8152602090f35b63a8a2a59360e01b8152600490fd5b50806003193601126104325763389a75e1600c523381526202a30042016020600c2055337fdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d8280a280f35b50346104325780600319360112610432576104cd6125d5565b50346104325780600319360112610432576020601c54604051908152f35b503461207657602036600319011261207657611ea261228b565b611eaa613427565b60ff6016541615612089576001600160a01b03811690811561207a57303b156120765760405163c0f4033760e01b81525f8160048183305af1612061575b50303b156111f15760405163a34f542960e01b81528390818160048183305af161204c575b5050303b156111f15760405163c0f4033760e01b81528390818160048183305af1612037575b5050303b156111f15760405163251fa3ef60e01b81528390818160048183305af1612022575b505060407f0d684b2ed995adb5369409a53673e2bcecda772f8946aa4b2940fd61abccb3a691611fe4611fbf610ac8610aa6610ac3865189602082015260208152611fa48882612405565b87519283916004602084015289808401526060830190612311565b919060ff19601654166016556001600160801b03196012541660125560135490612599565b91866013554780841161201a575b50828061200a575b505082519182526020820152a280f35b6120139161352d565b5f82611ffa565b92505f611ff2565b8161202c91612405565b6111f157825f611f59565b8161204191612405565b6111f157825f611f33565b8161205691612405565b6111f157825f611f0d565b61206e9193505f90612405565b5f915f611ee8565b5f80fd5b63c52a9bd360e01b5f5260045ffd5b63300b4e3360e21b5f5260045ffd5b34612076576020366003190112612076576120b161228b565b6120b9613427565b6001600160a01b0316801561207a57600154816001600160a01b0382167fa11f9f03282d5dbbf87eea2b08a2b19f333224fddc17402b016b8ae3021f8e9a5f80a36001600160a01b03191617600155005b34612076575f3660031901126120765760a06121246124c2565b61213160405180926122a1565bf35b346120765760203660031901126120765761214c61228b565b612154613427565b6001600160a01b0316801561207a575f548160018060a01b0382167f87087fc7f561aed200aa26f928eeeca78b58bf6fee5b773ce9b0633010ec31ab5f80a36001600160a01b031916175f55005b34612076576020366003190112612076576121cb6121be61228b565b6121c6613427565b612459565b005b34612076575f3660031901126120765760206114a2612361565b3461207657602036600319011261207657600435612203613427565b612710811161207a577f23d6205c6c05e01426fc16b730cf5eca75ee562626d60817d94ebffccc0de3d760406003548151908152836020820152a1600355005b34612076575f36600319011261207657602061226260a06115cd6124c2565b505090506040519060020b8152f35b34612076575f366003190112612076576020906017548152f35b600435906001600160a01b038216820361207657565b80516001600160a01b03908116835260208083015182169084015260408083015162ffffff169084015260608083015160020b9084015260809182015116910152565b9181601f84011215612076578235916001600160401b038311612076576020838186019501011161207657565b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b60c435906001600160a01b038216820361207657565b600435906001600160801b038216820361207657565b600954801561237f57600b54908082101561237a575090565b905090565b505f90565b6101c081019081106001600160401b038211176123a057604052565b634e487b7160e01b5f52604160045260245ffd5b60a081019081106001600160401b038211176123a057604052565b606081019081106001600160401b038211176123a057604052565b608081019081106001600160401b038211176123a057604052565b90601f801991011681019081106001600160401b038211176123a057604052565b90604061243e92600181528160208201520190612311565b90565b90604061243e92600381528160208201520190612311565b6001600160a01b0316801561207a57601b5415806124b8575b6124b557610aa6610ac36124b59260405190602082015260208152612498604082612405565b604051928391600660208401526040808401526060830190612311565b50565b50601c5415612472565b5f60806040516124d1816123b4565b82815282602082015282604082015282606082015201526040516124f4816123b4565b5f81527f000000000000000000000000d34a99bc0f67ae1bbd63c660e6d0b0dd03e263b76001600160a01b031660208201527f000000000000000000000000000000000000000000000000000000000000271062ffffff1660408201527f000000000000000000000000000000000000000000000000000000000000003c60020b606082015230608082015290565b9190826040910312612076576020825192015190565b919082018092116125a657565b634e487b7160e01b5f52601160045260245ffd5b6001600160401b0381116123a057601f01601f191660200190565b60195415612614576124b5610aa6610ac36040516125f4602082612405565b5f8152604051928391600760208401526040808401526060830190612311565b565b6001600160801b0360125416801561237f5761243e906126557ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2764c613621565b61266260a06115cd6124c2565b5050509061394e565b919082039182116125a657565b60405190612685826123cf565b8160406001600160801b036008548060020b84528060181c60020b602085015260301c16910152565b6126b6612678565b6009549060408101906001600160801b0382511615801561278a575b612783576126e360a06115cd6124c2565b5050509161270460206126f9845160020b613621565b93015160020b613621565b5f939091906001600160a01b03808216908516811161274b5750505161273493506001600160801b031691613998565b808211156127455761243e9161266b565b50505f90565b9093506001600160a01b03831611612766575b505050612734565b5161277b93506001600160801b031691613998565b5f808061275e565b5050505f90565b5082156126d2565b6001600160801b0360125416801561237f5761243e906127b560a06115cd6124c2565b5050506127e17f00000000000000000000000000000000000000000000000000000000000d89b4613621565b90613998565b60ff600a541615801561284e575b801561283b575b61283757601354600b54118015906128115790565b5061281a6126ae565b612822612361565b801515918261283057505090565b1015905090565b5f90565b506001600160801b0360125416156127fc565b5060ff60165416156127f5565b6001600160801b0360085460301c1615612614576124b5610aa6610ac3604051612886602082612405565b5f815260405192839160208301612441565b51906001600160a01b038216820361207657565b51908160020b820361207657565b7f000000000000000000000000000000000004444c5dc75cb358380d2e3de08a90906001600160a01b0382169060603383900361004c57601f54945f9560ff8116156132bf5760ff1916601f558201916040818403126120765780359060ff8216809203612076576020810135906001600160401b03821161207657019183601f8401121561207657823561294e816125ba565b9361295c6040519586612405565b81855260208501956020838301011161207657815f92602080930188378501015260018214612ec0575060078114612eb35760058114612e975760068114612c4a5760028114612c035760038114612be1576004146129c457637618476960e01b8552600485fd5b8060209195939495518101031261069e576129f7906001600160a01b03906129eb90612898565b169360a0610b906124c2565b505050906001600160801b0360125416612b92575b612a626001600160801b03601254167f00000000000000000000000000000000000000000000000000000000000d89b47ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2764c614456565b93909485612b2d575b84612a9a575b505050612a7d90614547565b60405191602083015260408201526040815261243e606082612405565b813b156111f157604051630b0d9c0960e01b81526001600160a01b037f000000000000000000000000d34a99bc0f67ae1bbd63c660e6d0b0dd03e263b781166004830152919091166024820152604481018590529082908290606490829084905af18015612b2257612b0d575b80612a71565b612b18828092612405565b6104325780612b07565b6040513d84823e3d90fd5b813b156111f157604051630b0d9c0960e01b81525f600482015230602482015260448101879052838160648183875af18015612b8757908491612b72575b5050612a6b565b81612b7c91612405565b6111f157825f612b6b565b6040513d86823e3d90fd5b612bdc7f00000000000000000000000000000000000000000000000000000000000d89b47ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2764c6141d4565b612a0c565b5050505050612bee6140ec565b5060405190612bfe602083612405565b815290565b506040919350808095935051810103126104325750906040612c27612c30936128ac565b9101519061406f565b60405190151560208201526020815261243e604082612405565b506020919293508051810103126111f1576001600160a01b0390612c6d90612898565b1690601b5490601c549082612d9d575b81612cc3575b507fdeb5099d7943aa2b4c1142e5d53d2f7636aa8f7bd130ec79816f151572bcdf459160409182519182526020820152a260405190612bfe602083612405565b84601c55803b15612d7957604051637a94c56560e11b81523060048201525f602482015260448101839052858160648183865af18015612d9257908691612d7d575b5050803b15612d7957604051630b0d9c0960e01b81525f60048201526001600160a01b0385166024820152604481018390529085908290606490829084905af18015612d6e57908591612d59575b50612c83565b81612d6391612405565b611bea57835f612d53565b6040513d87823e3d90fd5b8480fd5b81612d8791612405565b612d7957845f612d05565b6040513d88823e3d90fd5b601b8590557f000000000000000000000000d34a99bc0f67ae1bbd63c660e6d0b0dd03e263b76001600160a01b0316813b15612e7357604051637a94c56560e11b81523060048201526024810182905260448101859052868160648183875af18015612e8c57908791612e77575b5050813b15612e7357604051630b0d9c0960e01b81526001600160a01b039182166004820152908516602482015260448101849052858160648183865af18015612d9257908691612e5e575b5050612c7d565b81612e6891612405565b612d7957845f612e57565b8580fd5b81612e8191612405565b612e7357855f612e0b565b6040513d89823e3d90fd5b5050505050612ea4613d71565b60405190612bfe602083612405565b5050505050612ea4613c57565b939450509060808280979697518101031261207657612ede90612898565b926040820151906001600160801b03821680920361207657608084840151930151947ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2764c957f00000000000000000000000000000000000000000000000000000000000d89b4936001600160801b03601254166132b0575b612f5d6124c2565b9460405198612f6b8a6123ea565b60020b895260020b602089015260408801525f868801526040602097815195612f948a88612405565b5f8752612fb483519788938493632d35e7ed60e11b855260048501613bed565b03815f875af19384156131e8575f9461327e575b508360801d600f0b5f81138015613272575b61326357612fea612ff391613c38565b94600f0b613c38565b9484811061324d57508085116132375750826131f3575b8361302f575b505061243e939495506040519485015260408401526040835282612405565b7f000000000000000000000000d34a99bc0f67ae1bbd63c660e6d0b0dd03e263b790823b1561207657604051632961046560e21b81526001600160a01b03831660048201525f8160248183885af180156131e8576131cc575b508892879290916001600160a01b0381166131525750816014528560345263a9059cbb60601b845282846044601082855af190816001865114161561312b575b5050826034525b600460405180948193630476982d60e21b83525af18015612e8c5761243e959697506130fe575b869594613010565b61311d90863d8811613124575b6131158183612405565b810190613c48565b505f6130f6565b503d61310b565b91935091503d903b15171015613145578487915f806130c8565b6390b8ec1887526004601cfd5b60408051888a529084905290881b6bffffffffffffffffffffffff1916602c526323b872dd60601b600c529083856064601c82855af19081600187511416156131a3575b50508387526040526130cf565b9193509193503d903b151710156131bf57879186915f80613196565b637939f42488526004601cfd5b879299505f6131dd91949294612405565b5f9891929092613088565b6040513d5f823e3d90fd5b604051630476982d60e21b8152868160048187875af180156131e85761321a575b5061300a565b61323090873d8911613124576131158183612405565b505f613214565b8463ac75201360e01b5f5260045260245260445ffd5b8463ebbfb3bb60e01b5f5260045260245260445ffd5b63c74a40f960e01b5f5260045ffd5b505f85600f0b13612fda565b6132a191945060403d6040116132a9575b6132998183612405565b810190612583565b50925f612fc8565b503d61328f565b6132ba85896141d4565b612f55565b637618476960e01b5f5260045ffd5b303303613300576001600160801b0360085460301c1615612614576124b5610aa6610ac3604051612886602082612405565b6314e1dbf760e11b5f5260045ffd5b6017541580613364575b8061335a575b612614576124b5610aa6610ac360405161333a602082612405565b5f8152604051928391600560208401526040808401526060830190612311565b506019541561331f565b5060185415613319565b91906020906040518281019182526006604082015260408152613392606082612405565b519020604051631e2eaeaf60e01b8152600481019190915292839060249082906001600160a01b03165afa9182156131e8575f926133f3575b506001600160a01b0382169160a081901c60020b9162ffffff60b883901c81169260d01c1690565b9091506020813d60201161341f575b8161340f60209383612405565b810103126120765751905f6133cb565b3d9150613402565b638b78c6d81954330361343657565b6382b429005f526004601cfd5b5f61347791600160ff19601f541617601f55604051809381926348c8949160e01b8352602060048401526024830190612311565b0381837f000000000000000000000000000000000004444c5dc75cb358380d2e3de08a906001600160a01b03165af19081156131e8575f916134b7575090565b90503d805f833e6134c88183612405565b810190602081830312612076578051906001600160401b038211612076570181601f82011215612076578051906134fe826125ba565b9261350c6040519485612405565b8284526020838301011161207657815f9260208093018386015e8301015290565b5f80809338935af11561353c57565b63b12d13eb5f526004601cfd5b7f000000000000000000000000000000000004444c5dc75cb358380d2e3de08a906001600160a01b0316330361004c5760a036602319011261207657604051613591816123b4565b6024356001600160a01b03811681036120765781526044356001600160a01b038116810361207657602082015260643562ffffff811681036120765760408201526084358060020b810361207657606082015260a435906001600160a01b03821682036120765760a09160808201522060a061360b6124c2565b200361361357565b62820f3560e61b5f5260045ffd5b60020b908160ff1d82810118620d89e8811161393b5763ffffffff9192600182167001fffcb933bd6fad37aa2d162d1a59400102600160801b18916002811661391f575b60048116613903575b600881166138e7575b601081166138cb575b602081166138af575b60408116613893575b60808116613877575b610100811661385b575b610200811661383f575b6104008116613823575b6108008116613807575b61100081166137eb575b61200081166137cf575b61400081166137b3575b6180008116613797575b62010000811661377b575b620200008116613760575b620400008116613745575b620800001661372c575b5f12613724575b0160201c90565b5f190461371d565b6b048a170391f7dc42444e8fa290910260801c90613716565b6d2216e584f5fa1ea926041bedfe9890920260801c9161370c565b916e5d6af8dedb81196699c329225ee6040260801c91613701565b916f09aa508b5b7a84e1c677de54f3e99bc90260801c916136f6565b916f31be135f97d08fd981231505542fcfa60260801c916136eb565b916f70d869a156d2a1b890bb3df62baf32f70260801c916136e1565b916fa9f746462d870fdf8a65dc1f90e061e50260801c916136d7565b916fd097f3bdfd2022b8845ad8f792aa58250260801c916136cd565b916fe7159475a2c29b7443b29c7fa6e889d90260801c916136c3565b916ff3392b0822b70005940c7a398e4b70f30260801c916136b9565b916ff987a7253ac413176f2b074cf7815e540260801c916136af565b916ffcbe86c7900a88aedcffc83b479aa3a40260801c916136a5565b916ffe5dee046a99a2a811c461f1969c30530260801c9161369b565b916fff2ea16466c96a3843ec78b326b528610260801c91613692565b916fff973b41fa98c081472e6896dfb254c00260801c91613689565b916fffcb9843d60f6159c9db58835c9266440260801c91613680565b916fffe5caca7e10e4e61c3624eaa0941cd00260801c91613677565b916ffff2e50f5f656932ef12357cf3c7fdcc0260801c9161366e565b916ffff97272373d413259a46990580e213a0260801c91613665565b826345c3193d60e11b5f5260045260245ffd5b61243e926001600160a01b03928316919092160360ff81901d90810118906001600160801b0316614a94565b8115613984570490565b634e487b7160e01b5f52601260045260245ffd5b906001600160a01b0380821690831611613a05575b6001600160a01b0382169182156139f95761243e936139f4926001600160a01b0380821693909103169060601b6fffffffffffffffffffffffffffffffff60601b16614add565b61397a565b62bfc9215f526004601cfd5b906139ad565b60018060a01b031680638b78c6d819547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a3638b78c6d81955565b90600c549182158015613b31575b612783576001600160801b03601254161561278357818111613b29575b5062ffffff7f0000000000000000000000000000000000000000000000000000000000002710169081810291620f424082158284860414170215613ac7575050620f42409004905b8082101561237a575090565b620f4240905f198184098481108501900392099080620f42401115613b1c57828211900360fa1b910360061c177fde8f6cefed634549b62c77574f722e1ac57e23f24d8fd5cb790fb65668c261390290613abb565b63ae47f7025f526004601cfd5b90505f613a73565b5060ff600a541615613a56565b60020b60010190627fffff8213627fffff198312176125a657565b9060020b9060020b0190627fffff198212627fffff8313176125a657565b90601354808211613be5575b508015613be15761261491613b966125d5565b613ba28260135461266b565b6013556040518281526001600160a01b038216907f0cbcc38bb40a7b0940c989eac5abd480ff9917c824c1fd6b2e38227d92c4c70090602090a261352d565b5050565b90505f613b83565b606061243e9493613c0183610140956122a1565b805160020b60a0840152602081015160020b60c0840152604081015160e08401520151610100820152816101208201520190612311565b600160ff1b81146125a6575f0390565b90816020910312612076575190565b6019545f908015613be1575f6019557f000000000000000000000000000000000004444c5dc75cb358380d2e3de08a906001600160a01b0316803b1561207657604051637a94c56560e11b81523060048201525f60248201819052604482018490528160648183865af180156131e857613d5c575b50803b156111f157604051630b0d9c0960e01b81525f6004820152306024820152604481018390529083908290606490829084905af180156111fd57613d47575b507f10ea71883ef0e28b7b04d488d5ffc5952921ddb354e9b56f9331956a80fc9bab916060916040519180835260208301526040820152a1565b613d52838092612405565b61069e575f613d0d565b613d699193505f90612405565b5f915f613ccc565b601754601854601954915f613d868383612599565b9081159182159081613ece575b508515159182613def575b5091613de7575b50613daf57505050565b7f10ea71883ef0e28b7b04d488d5ffc5952921ddb354e9b56f9331956a80fc9bab9260609260405192835260208301526040820152a1565b90505f613da5565b60198190557f000000000000000000000000000000000004444c5dc75cb358380d2e3de08a906001600160a01b0316803b1561069e57604051637a94c56560e11b81523060048201525f602482015260448101899052828160648183865af180156111fd57908391613eb9575b5050803b1561069e57604051630b0d9c0960e01b81525f6004820152306024820152604481018990529082908290606490829084905af18015612b2257613ea4575b50613d9e565b613eaf828092612405565b6104325780613e9e565b81613ec391612405565b61069e57815f613e5c565b5f60178190556018556001600160a01b037f000000000000000000000000000000000004444c5dc75cb358380d2e3de08a908116917f000000000000000000000000d34a99bc0f67ae1bbd63c660e6d0b0dd03e263b790911690823b1561207657604051637a94c56560e11b81523060048201526024810183905260448101919091525f8160648183875af180156131e85761405a575b5086613fe7575b85613f78575b50613d93565b83546001600160a01b031690823b15612d7957604051630b0d9c0960e01b81526001600160a01b03918216600482015291166024820152604481018690529083908290606490829084905af180156111fd5790839115613f725781613fdc91612405565b61069e57815f613f72565b6001546001600160a01b0316823b15612d7957604051630b0d9c0960e01b81526001600160a01b03838116600483015291909116602482015260448101889052848160648183875af18015612d6e57908591614045575b5050613f6c565b8161404f91612405565b611bea57835f61403e565b6140679194505f90612405565b5f925f613f65565b6001600160801b036012541615612745577f5da4124c44e7ab5ea52a261f5f3cb8e7dc215e9eaf017eadcefff627b8247b1260206140c8836140c36140b26140ec565b96806013548091116140e45761266b565b614be3565b926040519060020b8152a181156140dd575090565b9050151590565b90508061266b565b6140f4612678565b60408101906001600160801b03825116156127455761419d6141cc6141956001600160801b037fbdf538edac463a73738d4acbf04fd09f49a98ef14daa6985cb9febb3cf2840629561417c61414c60a06115cd6124c2565b50505096805160020b906141696020820192835160020b906141d4565b5160020b905160020b8484511691614456565b5f6008959295555f60095561419085614efc565b614fa4565b959096614547565b51169260405194859485909493926060926001600160801b036080840197168352602083015260408201520152565b0390a1600190565b907f000000000000000000000000000000000004444c5dc75cb358380d2e3de08a906001600160a01b031690604061420a6124c2565b935f92825191614219836123ea565b60020b825260020b60208201525f828201525f606082015281519461423f602087612405565b5f865261425f83519687938493632d35e7ed60e11b855260048501613bed565b03815f865af19283156131e8575f93614433575b508260801d925f81600f0b135f1461442b576001600160801b0316925b5f81600f0b135f14614423576001600160801b0316915b83159182159081614388575b841515928361430c575b505091614304575b506142ce575050565b7faf7c505ee772ec188af7067e1f73db08ab028e3d564273442b907742b9c41fa09160409143601a5582519182526020820152a1565b90505f6142c5565b803b1561069e57604051630ab714fb60e11b81523060048201525f6024820152604481018790529082908290606490829084905af18015612b2257614373575b505061435a84601c54612599565b601c5561436984601e54612599565b601e555f806142bd565b61437e828092612405565b610432578061434c565b823b1561207657604051630ab714fb60e11b81523060048201526001600160a01b037f000000000000000000000000d34a99bc0f67ae1bbd63c660e6d0b0dd03e263b7166024820152604481018790525f8160648183885af180156131e857614410575b506143f986601b54612599565b601b5561440886601d54612599565b601d556142b3565b61441c91505f90612405565b5f5f6143ec565b505f916142a7565b505f92614290565b61444d91935060403d6040116132a9576132998183612405565b9050915f614273565b60409193929361446d6144676124c2565b95613c38565b9083519261447a846123ea565b60020b835260020b6020830152828201525f606082015281519361449f602086612405565b5f85526144bf83519586938493632d35e7ed60e11b855260048501613bed565b03815f7f000000000000000000000000000000000004444c5dc75cb358380d2e3de08a906001600160a01b03165af19182156131e8575f92614525575b508160801d600f0b5f81128015614519575b6132635791600f0b90565b505f83600f0b1261450e565b61453f91925060403d6040116132a9576132998183612405565b50905f6144fc565b61455460a06115cd6124c2565b5050506001600160a01b03908116911680820361456f575050565b6376bc6d9160e11b5f5260045260245260445ffd5b601a544311156126145760175415806145da575b806145d0575b61261457303b1561207657604051637b44e4c560e11b81525f8160048183305af16145c65750565b5f61261491612405565b506019541561459e565b5060185415614598565b818102929181159184041417156125a657565b6001600160801b036012541680156124b55761461660a06115cd6124c2565b5050507ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2764c9161464e818361464986613621565b61394e565b60115480821061478b57506146656011548261266b565b9081158015614762575b61475b5761467d9183614b5d565b8015614755576146b7816001600160801b03957f00000000000000000000000000000000000000000000000000000000000d89b490614456565b94909116809203906001600160801b0382116125a65761472461471c7f32afb9555b0493ac0021ef7f6b122197e9e58510e694383410f667ec76e4f0fa966001600160801b0361475095166001600160801b0319601254161760125561419084614efc565b919095614547565b60405194859485909493926060926001600160801b036080840197168352602083015260408201520152565b0390a1565b50505050565b5050505050565b507f0000000000000000000000000000000000000000000000000000000000000000821061466f565b93506147b4925061271091506147a46147ad918561266b565b600354906145e4565b048261266b565b906006546147c2814261266b565b90620151806147d460055493846145e4565b04808411156148e0576147e7908461266b565b8085106148d8575b506004548085106148d0575b508284106148095750505050565b614813848461266b565b821590811561485d575b5050505060407fa66e3643af3b5a570ea09b8d485f206950ff1ee042471a211388199518f539a6918151908152836020820152a16011555f808080614755565b62015180819593949502908082046201518014901517156125a6576148886148999160075490612599565b93614893868661397a565b90612599565b6006556139845791900660075560407fa66e3643af3b5a570ea09b8d485f206950ff1ee042471a211388199518f539a65f8061481d565b93505f6147fb565b93505f6147ef565b505f6147e7565b600291820b910b0390627fffff198212627fffff8313176125a657565b600d54908160881c60020b90819261491e600f544261266b565b90816149a7575b505061493090614a55565b8160020b8160020b1361499f575b508060020b9180830361495057505050565b7f73cd8288dc6e2d815bcc3fdbd71bdcc73cb3ad258d80587c5c90d8c85388cd5492604092600d549060881b62ffffff60881b169062ffffff60881b191617600d5582519182526020820152a1565b90505f61493e565b6149bb909391929342600f5560020b614a55565b908160020b928184125f14614a4357620151808111614a39575b6149e46149ed91600e546145e4565b60105490612599565b6201518080820491066010555f8483039412828512811690838613901516176125a657614930938110614a265750505b915b905f614925565b614a34925060020b906148e7565b614a1d565b50620151806149d5565b5092905061493091505f601055614a1f565b614a5e90613b3e565b907f00000000000000000000000000000000000000000000000000000000000d89b48060020b8360020b13614a905750565b9150565b81810291905f1982820991838084109303928084039384600160601b11156120765714614ad457600160601b910990828211900360a01b910360601c1790565b50505060601c90565b91818302915f19818509938380861095039480860395868511156120765714614b55579082910981805f03168092046002816003021880820260020302808202600203028082026002030280820260020302808202600203028091026002030293600183805f03040190848311900302920304170290565b505091500490565b81810292918115828504821417830215614b78575050900490565b82905f1981840985811086019003920990825f0383169281811115613b1c5783900480600302600218808202600203028082026002030280820260020302808202600203028082026002030280910260020302936001848483030494805f0304019211900302170290565b8015612745577f00000000000000000000000000000000000000000000000000000000000d89b4908160020b8360020b9281841215614ef357614c2585613621565b614c2e82613621565b6001600160a01b039182169116808202828104821483151760601b15614eb657614c6692614c5f9160601c9261266b565b9085614b5d565b9081158015614ea6575b614e9757614d0e956001600160801b038316947f000000000000000000000000000000000004444c5dc75cb358380d2e3de08a90906040614cb460a0610a1e6124c2565b50505092614cc06124c2565b908251614ccc816123ea565b8b81528960208201528a848201525f60608201525f845193614cef602086612405565b8185528551632d35e7ed60e11b81529e8f958694859360048501613bed565b03926001600160a01b03165af19889156131e8575f99614e75575b508860801d600f0b5f81138015614e69575b61326357614d4b614d5491613c38565b99600f0b613c38565b80614e575750808911614e415750916080959391614d9d7fe3966151f83ca37a8d733ac53f8f5122134c74fc747f8ea857c2ba5e49f68b73989694614d988b615115565b614547565b614da98960135461266b565b6013558460408051614dba816123cf565b888152866020820152015262ffffff19600854169062ffffff16176008556008549060181b60050b65ffffff000000169065ffffff0000001916176008556601000000000000600160b01b036008549160301b16906601000000000000600160b01b031916176008558560095560405192835260208301526040820152836060820152a190565b8863ebbfb3bb60e01b5f5260045260245260445ffd5b6308e0272d60e01b5f5260045260245ffd5b505f8a600f0b13614d3b565b614e8f91995060403d6040116132a9576132998183612405565b50975f614d29565b631fff968160e01b5f5260045ffd5b506001600160801b038211614c70565b5f198284098181108201900392600160601b838209600160601b851015613b1c57614c66948382614c5f950360601c9211900360a01b179261266b565b50505050505f90565b80156124b5577f000000000000000000000000000000000004444c5dc75cb358380d2e3de08a906001600160a01b031690813b1561207657604051630ab714fb60e11b81523060048201525f602482018190526044820183905290928390606490829084905af19182156131e857614f8f92614f94575b5043601a55614f8481601954612599565b601955601354612599565b601355565b5f614f9e91612405565b5f614f73565b801561510e5760025480820290612710818484041402156150bb57506127109004915b8291614fd3848261266b565b937f000000000000000000000000000000000004444c5dc75cb358380d2e3de08a906001600160a01b0316803b1561207657604051630ab714fb60e11b81523060048201526001600160a01b037f000000000000000000000000d34a99bc0f67ae1bbd63c660e6d0b0dd03e263b716602482015260448101939093525f908390606490829084905af19182156131e857615088926150ab575b5043601a5561507d81601554612599565b601555601854612599565b60185561509783601454612599565b6014556150a683601754612599565b601755565b5f6150b591612405565b5f61506c565b6127105f198285098381108401900391840990806127101115613b1c57828211900360fc1b910360041c177fbc01a36e2eb1c432ca57a786c226809d495182a9930be0ded288ce703afb7e910291614fc7565b505f905f90565b5f8115613be1576019548083101561524a5782905b816151bc575b5061513b919261266b565b9081615145575050565b604051630476982d60e21b815291602090839060049082907f000000000000000000000000000000000004444c5dc75cb358380d2e3de08a906001600160a01b03165af19081156151b057506151985750565b6124b59060203d602011613124576131158183612405565b604051903d90823e3d90fd5b816151c69161266b565b6019557f000000000000000000000000000000000004444c5dc75cb358380d2e3de08a906001600160a01b0316803b1561207657604051637a94c56560e11b81523060048201525f602482018190526044820184905290918290606490829084905af180156131e857156151305761513b92505f61524391612405565b5f91615130565b8061512a56fea26469706673582212204b742b4842ddf3573797eeb169fd986dbed9f8e760799b9572ac9f8ef7d1eba064736f6c634300081e0033","optimization_enabled":true,"verified_twin_address_hash":null,"is_verified":true,"compiler_settings":{"evmVersion":"osaka","metadata":{"appendCBOR":true,"bytecodeHash":"ipfs","useLiteralContent":false},"optimizer":{"enabled":true,"runs":200},"remappings":["v4-core-test/=lib/v4-core/test/","@ensdomains/=lib/v4-core/node_modules/@ensdomains/","@openzeppelin/=lib/v4-core/lib/openzeppelin-contracts/","ds-test/=lib/v4-core/lib/forge-std/lib/ds-test/src/","erc4626-tests/=lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/","forge-std/=lib/forge-std/src/","hardhat/=lib/v4-core/node_modules/hardhat/","openzeppelin-contracts/=lib/v4-core/lib/openzeppelin-contracts/","solady/=lib/solady/src/","solmate/=lib/v4-core/lib/solmate/","v4-core/=lib/v4-core/src/"],"viaIR":true},"optimization_runs":200,"sourcify_repo_url":null,"decoded_constructor_args":[["0x047F606fD5b2BaA5f5C6c4aB8958E45CB6B054B7",{"internalType":"address","name":"owner_","type":"address"}],["0x000000000004444c5dc75cB358380D2e3dE08A90",{"internalType":"contract IPoolManager","name":"poolManager_","type":"address"}],["0xD34a99Bc0f67aE1bbd63C660e6d0b0dd03E263B7",{"internalType":"address","name":"token_","type":"address"}],["0xe29386719C155B6847aD5a4E97C6674f10ffc750",{"internalType":"address","name":"burnSink_","type":"address"}],["0x9046739E1535B40EfBe6AB3f45d0024b690eCA30",{"internalType":"address","name":"rewardsRecipient_","type":"address"}],["1500",{"internalType":"uint256","name":"rewardShareBps_","type":"uint256"}],["0",{"internalType":"uint256","name":"minTrimTokens_","type":"uint256"}],["10000",{"internalType":"uint24","name":"lpFee_","type":"uint24"}],["60",{"internalType":"int24","name":"tickSpacing_","type":"int24"}]],"compiler_version":"0.8.30+commit.73712a01","is_verified_via_verifier_alliance":true,"verified_at":"2026-09-19T20:42:55.200605Z","implementations":[],"proxy_type":null,"external_libraries":[],"creation_bytecode":"0x610160604052346105e157604051601f6158b438819003918201601f19168301916001600160401b038311848410176105e557808492610120946040528339810103126105e15761004f81610619565b60208201516001600160a01b03811692908381036105e15761007360408301610619565b61007f60608401610619565b61008b60808501610619565b9060a08501519260c08601519460e08701519662ffffff8816908189036105e1576101000151998a60020b998a8c036105e1576001600160a01b03169182159182156105d8575b5081156105c6575b81156105b4575b81156105a2575b8115610596575b8115610589575b50801561057f575b8015610574575b6105655780638b78c6d819555f7f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08180a360805260a0525f80546001600160a01b039283166001600160a01b0319918216179091556001805493909216921691909117905560025560c05260e0526101008290528015610551578181620d89e719050260020b61012052620d89e8050260020b61014052612710600355600160ff19600a541617600a5567016345785d8a0000600b5566071afd498d0000600c55601960731b62ffffff60701b19600d541617600d55610190600e555f6101a06101ed6105f9565b8281528260208201528260408201528260608201528260808201528260a08201528260c08201528260e0820152826101008201528261012082015282610140820152826101608201528261018082015201525f6101a061024b6105f9565b60018152826020820152600160408201528260608201528260808201528260a08201528260c0820152600160e08201528261010082015282610120820152826101408201528261016082015282610180820152015261200030161515600114801590610544575b8015610533575b8015610526575b8015610519575b801561050c575b8015610500575b80156104f0575b80156104e4575b80156104d8575b80156104cc575b80156104c0575b80156104b4575b80156104a8575b61049557604051615286908161062e8239608051818181601c015281816106b8015281816109f101528181610eff01528181611132015281816115d0015281816128bc0152818161347c0152818161354b01528181613c6801528181613df601528181613ee1015281816141d7015281816144c401528181614c8501528181614f0401528181614fd60152818161515f01526151cb015260a05181818161047e015281816124f901528181612ab801528181612da40152818161303101528181613f05015281816143ac0152615022015260c051818181610c8b0152818161147a0152614765015260e051818181611881015281816125280152613a7a01526101005181818161073b0152818161161d0152612553015261012051818181611085015281816119e00152818161263101528181612a3e01528181612bb801528181612f02015261461b01526101405181818161106401528181611a3c015281816127bd01528181612a1d01528181612b9701528181612f240152818161469201528181614a610152614beb0152f35b630732d7b560e51b5f523060045260245ffd5b50600130161515610306565b506002301615156102ff565b506004301615156102f8565b506008301615156102f1565b506010301615156102ea565b506020301615156102e3565b50604030161515600114156102dc565b506080301615156102d5565b50610100301615156102ce565b50610200301615156102c7565b50610400301615156102c0565b5061080030161515600114156102b9565b50611000301615156102b2565b634e487b7160e01b5f52601260045260245ffd5b63c52a9bd360e01b5f5260045ffd5b50617fff8913610105565b505f8913156100fe565b620f42409150115f6100f6565b610bb8881191506100ef565b6001600160a01b0387161591506100e8565b6001600160a01b0386161591506100e1565b6001600160a01b0385161591506100da565b1591505f6100d2565b5f80fd5b634e487b7160e01b5f52604160045260245ffd5b604051906101c082016001600160401b038111838210176105e557604052565b51906001600160a01b03821682036105e15756fe608080604052600436101561005b575b50361561001a575f80fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316330361004c57005b63067e68e760e31b5f5260045ffd5b5f905f3560e01c90816305949ff01461227157508063065e53601461224357806307788b4b146121e757806307ec46d0146121cd578063164e68de146121a25780631668d5bf14612133578063182148ef1461210a5780631a54259c146120985780631a8e22e614611e885780631c5ea67f14611e6a578063251fa3ef14611e515780632569296214611e06578063259982e514611d7757806326387ed614611d5957806335302ff214611cea5780633e0dc34e14611cc45780633ec8779c14611c5f57806340e1e4c714611c4457806341becbce14611c1d578063455835ee14611aff57806347fd03d914611aca5780634fd3c91114611aa857806354d1f13d14611a6257806355b812a814611a2457806355e6294114611a0657806359c4f905146119c85780635ae01c91146119a45780635ff09a2f14611986578063632e4bc31461192057806363ace910146118de5780636723bad1146118c35780636dd16b2c146118a5578063704ce43e14611865578063715018a61461181a57806371d2cc5c146117ff5780637211dc36146117d857806373588d61146117b35780637500d411146117955780637ac776be146117745780637d7c2a1c146115695780637dea18171461152a57806381fdec27146115075780638d2998eb146114e65780638da5cb5b146114b95780638fd56138146114485780639124b5c71461142a57806391dd7346146113d55780639797fab8146113645780639d3ec01614611346578063a1b66c0314611328578063a2d75a981461130a578063a34f5429146112f1578063a4de3ed8146112d3578063a736e27014611244578063a9d2293d14611226578063a9ec75f614611208578063ab48b09e146110cc578063aed29d07146110ae578063b47b2fb114610e7e578063b4c076c614610d08578063b4cc4bb114610cea578063b53cf8ac14610ccc578063b53e716f14610cae578063b7bd346514610c73578063c0f4033714610c5a578063c1d64bfb146109a2578063c4e833ce1461083a578063c66bc04614610817578063c8ca4b691461077f578063c8f6cd9a14610761578063d0c93a7c14610723578063d89135cd14610705578063db445ee8146106e7578063dc4c90d3146106a2578063dc98354e14610635578063e1a4521814610618578063e1e49a41146105ab578063e85d84561461058d578063f04e283e1461053f578063f2fde38b14610503578063f426bce8146104df578063f689c98a146104ad578063fc0c546a14610468578063fee81cf4146104355763ff2a7d300361000f57346104325780600319360112610432576001546040516001600160a01b039091168152602090f35b80fd5b50346104325760203660031901126104325761044f61228b565b9063389a75e1600c5252602080600c2054604051908152f35b50346104325780600319360112610432576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b50346104325780600319360112610432573033036104d0576104cd613d71565b80f35b6314e1dbf760e11b8152600490fd5b50346104325780600319360112610432576020600d5460701c60020b604051908152f35b5060203660031901126104325761051861228b565b610520613427565b8060601b15610532576104cd90613a0b565b637448fbae82526004601cfd5b5060203660031901126104325761055461228b565b61055c613427565b63389a75e1600c528082526020600c20805442116105805790826104cd9255613a0b565b636f5e881883526004601cfd5b50346104325780600319360112610432576020601854604051908152f35b5034610432576020366003190112610432576004356105c8613427565b610bb88111610609577f0470487ff198b72012448e1673140b668fcbc9f5f72732475138fb50711e690460406002548151908152836020820152a160025580f35b63c52a9bd360e01b8252600482fd5b503461043257806003193601126104325760206040516127108152f35b50346104325760e03660031901126104325761064f61228b565b60a036602319011261069e57610663612335565b5061066c613549565b306001600160a01b039091160361068f57604051636e4c1aa760e11b8152602090f35b631db1b77f60e21b8152600490fd5b5080fd5b50346104325780600319360112610432576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b50346104325780600319360112610432576020601154604051908152f35b50346104325780600319360112610432576020601454604051908152f35b503461043257806003193601126104325760206040517f000000000000000000000000000000000000000000000000000000000000000060020b8152f35b50346104325780600319360112610432576020601b54604051908152f35b50346104325760403660031901126104325760043580151580910361069e576024356107a9613427565b8015801561080b575b6107fc577f9d9245b57fa07ba643fbad2d3378aceb453351bb664fe7e7e65f5b2f8586ea559160409160ff19600a541660ff831617600a5580600b5582519182526020820152a180f35b63c52a9bd360e01b8352600483fd5b50600c548111156107b2565b5034610432578060031936011261043257602060ff601654166040519015158152f35b50346104325780600319360112610432576020816101c0926101a060405161086181612384565b82815282858201528260408201528260608201528260808201528260a08201528260c08201528260e082015282610100820152826101208201528261014082015282610160820152826101808201520152806040516108bf81612384565b600181528381018281526040820160018152606083018481526080840185815260a0850186815260c086019087825260e0870192600184526101008801948986526101208901968a88526101408a01988b8a526101a06101608c019b8d8d5261018081019d8e52019c8d526040519d8e916001835251151591015251151560408d015251151560608c015251151560808b015251151560a08a015251151560c089015251151560e08801525115156101008701525115156101208601525115156101408501525115156101608401525115156101808301525115156101a0820152f35b506080366003190112610432576109b761234b565b604435606435916109c6613427565b60ff60165416610c4b576001600160801b038116928315610c3c576001600160801b038111610c2d577f000000000000000000000000000000000000000000000000000000000000000091610a2560a0610a1e6124c2565b208461336e565b5050506001600160a01b031615610c1e57604080513360208201526001600160801b03909216908201523460608281019190915260243560808301527f4a16fcf994dd2b8d8fbfc45545d642ddf26debffd047664077e7d32726013e8d959094909390929091610ad790610ac890610aa690610ac390610ab48160a0810185565b03601f198101835282612405565b60405192839160208301612426565b613443565b60208082518301019101612583565b939092600160ff196016541617601655856001600160801b03196012541617601255610b0d60a0610b066124c2565b208261336e565b50509050600d548162ffffff1662ffffff19821617600d5565ffffff000000610ba0610b97610b4660a0610b3f6124c2565b208761336e565b5050905060181b9362ffffff6dffffffffffffffff0000000000004360301b169616906dffffffffffffffffffffffffffff1916179585878686161717600d5560a0610b906124c2565b209061336e565b50509050614a55565b60881b62ffffff60881b169362ffffff60881b19169116171717600d5542600f55876010558360115580600455808410610c15575b506005554260065585600755803411610bfd575b60405192835260208301526040820152a180f35b610c10610c0a823461266b565b3361352d565b610be9565b6011555f610bd5565b63486aa30760e01b8652600486fd5b63c52a9bd360e01b8552600485fd5b631fff968160e01b8552600485fd5b632597e36560e21b8452600484fd5b50346104325780600319360112610432576104cd61330f565b503461043257806003193601126104325760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b50346104325780600319360112610432576020601e54604051908152f35b50346104325780600319360112610432576020601d54604051908152f35b50346104325780600319360112610432576020600954604051908152f35b50604036600319011261043257610d1d61234b565b90610d26613427565b60ff6016541615610e6f576001600160801b0382168015610e6057604080513360208201526001600160801b038516918101919091523460608201526024356080820152610d8590610ac890610aa690610ac390610ab48160a0810185565b939091601254906001600160801b038216016001600160801b038111610e4c5794610e34916001600160801b037ff0274a7918e8f581dc8bab20fdd27a328453e35288ecd49034b3e7928f3a8fca969716906001600160801b03191617601255610df181601154612599565b6011554260065585600755833411610e3a575b6011549060405194859485909493926060926001600160801b036080840197168352602083015260408201520152565b0390a180f35b610e47610c0a853461266b565b610e04565b634e487b7160e01b85526011600452602485fd5b631fff968160e01b8252600482fd5b63300b4e3360e21b8152600490fd5b50346104325761016036600319011261043257610e9961228b565b5060a03660231901126104325760603660c319011261043257610144356001600160401b03811161069e57610ed29036906004016122e4565b5050610edc613549565b610ee4614584565b6001600160801b036012541661105f575b610efd6145f7565b7f000000000000000000000000000000000000000000000000000000000000000090610f38610f2f60a0610a1e6124c2565b50509050614904565b600d546001600160401b038160301c164303610f95575b50610f6060409260a0610b906124c2565b50509050600d549060181b65ffffff000000169065ffffff000000191617600d5581519063b47b2fb160e01b82526020820152f35b918260181c60020b928060701c60020b8160020b610fb381876148e7565b60020b958287131561100d575060409550610f60939291610fd391613b59565b905b62ffffff6dffffffffffffffff0000000000004360301b169216906dffffffffffffffff000000ffffff19161717600d559250610f4f565b9395627fffff19831461104b57916040969391610f60959382880360020b13611038575b5050610fd5565b6110439293506148e7565b905f80611031565b634e487b7160e01b86526011600452602486fd5b6110a97f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006141d4565b610ef5565b50346104325780600319360112610432576020601554604051908152f35b5034610432576020366003190112610432576110e661228b565b6110ee613427565b6110f66124c2565b60405163313b65df60e11b815291906111139060048401906122a1565b60018060a01b0316908160a482015260208160c4818660018060a01b037f0000000000000000000000000000000000000000000000000000000000000000165af19081156111fd578391611199575b507f5f94feb4624474fb875ef3acdf106e9f8e1b7ad0881a6a86f1e67f67ccd4e5b491604091825191825260020b6020820152a180f35b90506020813d6020116111f5575b816111b460209383612405565b810103126111f1577f5f94feb4624474fb875ef3acdf106e9f8e1b7ad0881a6a86f1e67f67ccd4e5b4916111e96040926128ac565b915091611162565b8280fd5b3d91506111a7565b6040513d85823e3d90fd5b50346104325780600319360112610432576020600c54604051908152f35b50346104325780600319360112610432576020601a54604051908152f35b5034610432576020366003190112610432576004358060020b908181036111f15761126d613427565b8282138015906112c8575b6107fc577fcfbecc91ba4affcc98e65e63a1fb7465085a80673b10741d6dd1ced65ad1c4c591602091600d549060701b62ffffff60701b169062ffffff60701b191617600d55604051908152a180f35b506107d08213611278565b50346104325780600319360112610432576020600354604051908152f35b50346104325780600319360112610432576104cd6132ce565b50346104325780600319360112610432576020601954604051908152f35b50346104325780600319360112610432576020600b54604051908152f35b50346104325780600319360112610432576020601354604051908152f35b503461043257602036600319011261043257600435611381613427565b67016345785d8a0000811180156113c9575b610609576020817fd314a86face0096456c6272915a80b3881d94f4305db4d09cbe1c2e0b929fe7d92600c55604051908152a180f35b50600b54811015611393565b503461043257602036600319011261043257600435906001600160401b0382116104325761142661141261140c36600486016122e4565b906128ba565b604051918291602083526020830190612311565b0390f35b50346104325780600319360112610432576020600254604051908152f35b5034610432578060031936011261043257602090611464612616565b601154808211156114b1576114789161266b565b7f00000000000000000000000000000000000000000000000000000000000000008110156114aa57505b604051908152f35b90506114a2565b505080611478565b5034610432578060031936011261043257638b78c6d819546040516001600160a01b039091168152602090f35b50346104325780600319360112610432576114ff613427565b6104cd61285b565b5034610432578060031936011261043257602060ff600a54166040519015158152f35b503461043257806003193601126104325760606008546001600160801b03604051918060020b83528060181c60020b602084015260301c166040820152f35b503461043257806003193601126104325760ff6016541615610e6f57601354906115916126ae565b600b54831092838061174f575b6117405791926115b2929061173957613a48565b60ff600a54161561172a576116066115f460a06115cd6124c2565b207f000000000000000000000000000000000000000000000000000000000000000061336e565b5050905061160181614904565b613b3e565b600d5460881c60020b808260020b12611722575b507f00000000000000000000000000000000000000000000000000000000000000009060020b908060020b801561170e57627fffff1983145f19821416610e4c5780830560020b028060020b908103610e4c576116c292610aa69282610ac3939281126116fd575b50506040519060020b6020820152846040820152604081526116a5606082612405565b604051928391600260208401526040808401526060830190612311565b6020818051810103126111f1576020015180151581036111f157806116f4575b6116ea575080f35b6104cd9033613b77565b508015156116e2565b6117079250613b59565b5f80611682565b634e487b7160e01b85526012600452602485fd5b90505f61161a565b63057fe11960e01b8252600482fd5b5082613a48565b635121f34360e01b8352600483fd5b50611758612361565b8015159081611769575b501561159e565b90508210155f611762565b50346104325780600319360112610432576020600d5460020b604051908152f35b50346104325780600319360112610432576020600654604051908152f35b503461043257806003193601126104325760206117ce6127e7565b6040519015158152f35b503461043257806003193601126104325760206001600160801b0360125416604051908152f35b503461043257806003193601126104325760206114a2612792565b50806003193601126104325761182e613427565b80638b78c6d819547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380638b78c6d8195580f35b5034610432578060031936011261043257602060405162ffffff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b50346104325780600319360112610432576020600454604051908152f35b503461043257806003193601126104325760206114a26126ae565b503461043257806003193601126104325760206118f9612361565b801515908161190e575b506040519015158152f35b90506119186126ae565b101582611903565b50346104325760203660031901126104325760043561193d613427565b7f5e458cfdece54e103be9a698a036358c6e051e5c49ed81cc88922ea2c95a1bf660406004548151908152836020820152a1806004558060115410611980575080f35b60115580f35b50346104325780600319360112610432576020600754604051908152f35b50346104325780600319360112610432576020600d5460881c60020b604051908152f35b503461043257806003193601126104325760206040517f000000000000000000000000000000000000000000000000000000000000000060020b8152f35b50346104325780600319360112610432576020600554604051908152f35b503461043257806003193601126104325760206040517f000000000000000000000000000000000000000000000000000000000000000060020b8152f35b50806003193601126104325763389a75e1600c52338152806020600c2055337ffa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c928280a280f35b503461043257806003193601126104325760206040516001600160801b038152f35b50346104325780600319360112610432576020611aea60a06115cd6124c2565b50506040516001600160a01b03909216825250f35b503461043257604036600319011261043257611b1961228b565b602435611b24613427565b6001600160a01b038216918215611c035781158015611c12575b611c0357303b15611bea5760405163c0f4033760e01b81528490818160048183305af1611bee575b5050303b15611bea5760405163251fa3ef60e01b81528490818160048183305af1611bd5575b505081611bcb81602093611bc37f74eb25c53a7388d0aeb904d6988be782d21574be8e6dda40c9e6f393da0317a49660135461266b565b60135561352d565b604051908152a280f35b81611bdf91612405565b611bea57835f611b8c565b8380fd5b81611bf891612405565b611bea57835f611b66565b63c52a9bd360e01b8452600484fd5b506013548211611b3e565b5034610432578060031936011261043257546040516001600160a01b039091168152602090f35b503461043257806003193601126104325760206114a2612616565b503461043257602036600319011261043257600435611c7c613427565b6001600160801b0381116106095760207f0906efadb8cedc0ee7e01d6fc84736c3e6d77db8bfcc9801192a22541709d3b591426006558360075580600555604051908152a180f35b5034610432578060031936011261043257602060a0611ce16124c2565b20604051908152f35b503461043257602036600319011261043257600435611d07613427565b80158015611d4e575b6106095760207f3a1d145815cd352bfcbd4080e799e44213275c8927c6a0c3fd6ac016ae51c0329142600f558360105580600e55604051908152a180f35b506107d08111611d10565b50346104325780600319360112610432576020600e54604051908152f35b50346104325761016036600319011261043257611d9261228b565b60a036602319011261069e5760803660c319011261069e57610144356001600160401b0381116111f157611dca9036906004016122e4565b5050611dd4613549565b306001600160a01b0390911603611df75760405163259982e560e01b8152602090f35b63a8a2a59360e01b8152600490fd5b50806003193601126104325763389a75e1600c523381526202a30042016020600c2055337fdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d8280a280f35b50346104325780600319360112610432576104cd6125d5565b50346104325780600319360112610432576020601c54604051908152f35b503461207657602036600319011261207657611ea261228b565b611eaa613427565b60ff6016541615612089576001600160a01b03811690811561207a57303b156120765760405163c0f4033760e01b81525f8160048183305af1612061575b50303b156111f15760405163a34f542960e01b81528390818160048183305af161204c575b5050303b156111f15760405163c0f4033760e01b81528390818160048183305af1612037575b5050303b156111f15760405163251fa3ef60e01b81528390818160048183305af1612022575b505060407f0d684b2ed995adb5369409a53673e2bcecda772f8946aa4b2940fd61abccb3a691611fe4611fbf610ac8610aa6610ac3865189602082015260208152611fa48882612405565b87519283916004602084015289808401526060830190612311565b919060ff19601654166016556001600160801b03196012541660125560135490612599565b91866013554780841161201a575b50828061200a575b505082519182526020820152a280f35b6120139161352d565b5f82611ffa565b92505f611ff2565b8161202c91612405565b6111f157825f611f59565b8161204191612405565b6111f157825f611f33565b8161205691612405565b6111f157825f611f0d565b61206e9193505f90612405565b5f915f611ee8565b5f80fd5b63c52a9bd360e01b5f5260045ffd5b63300b4e3360e21b5f5260045ffd5b34612076576020366003190112612076576120b161228b565b6120b9613427565b6001600160a01b0316801561207a57600154816001600160a01b0382167fa11f9f03282d5dbbf87eea2b08a2b19f333224fddc17402b016b8ae3021f8e9a5f80a36001600160a01b03191617600155005b34612076575f3660031901126120765760a06121246124c2565b61213160405180926122a1565bf35b346120765760203660031901126120765761214c61228b565b612154613427565b6001600160a01b0316801561207a575f548160018060a01b0382167f87087fc7f561aed200aa26f928eeeca78b58bf6fee5b773ce9b0633010ec31ab5f80a36001600160a01b031916175f55005b34612076576020366003190112612076576121cb6121be61228b565b6121c6613427565b612459565b005b34612076575f3660031901126120765760206114a2612361565b3461207657602036600319011261207657600435612203613427565b612710811161207a577f23d6205c6c05e01426fc16b730cf5eca75ee562626d60817d94ebffccc0de3d760406003548151908152836020820152a1600355005b34612076575f36600319011261207657602061226260a06115cd6124c2565b505090506040519060020b8152f35b34612076575f366003190112612076576020906017548152f35b600435906001600160a01b038216820361207657565b80516001600160a01b03908116835260208083015182169084015260408083015162ffffff169084015260608083015160020b9084015260809182015116910152565b9181601f84011215612076578235916001600160401b038311612076576020838186019501011161207657565b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b60c435906001600160a01b038216820361207657565b600435906001600160801b038216820361207657565b600954801561237f57600b54908082101561237a575090565b905090565b505f90565b6101c081019081106001600160401b038211176123a057604052565b634e487b7160e01b5f52604160045260245ffd5b60a081019081106001600160401b038211176123a057604052565b606081019081106001600160401b038211176123a057604052565b608081019081106001600160401b038211176123a057604052565b90601f801991011681019081106001600160401b038211176123a057604052565b90604061243e92600181528160208201520190612311565b90565b90604061243e92600381528160208201520190612311565b6001600160a01b0316801561207a57601b5415806124b8575b6124b557610aa6610ac36124b59260405190602082015260208152612498604082612405565b604051928391600660208401526040808401526060830190612311565b50565b50601c5415612472565b5f60806040516124d1816123b4565b82815282602082015282604082015282606082015201526040516124f4816123b4565b5f81527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031660208201527f000000000000000000000000000000000000000000000000000000000000000062ffffff1660408201527f000000000000000000000000000000000000000000000000000000000000000060020b606082015230608082015290565b9190826040910312612076576020825192015190565b919082018092116125a657565b634e487b7160e01b5f52601160045260245ffd5b6001600160401b0381116123a057601f01601f191660200190565b60195415612614576124b5610aa6610ac36040516125f4602082612405565b5f8152604051928391600760208401526040808401526060830190612311565b565b6001600160801b0360125416801561237f5761243e906126557f0000000000000000000000000000000000000000000000000000000000000000613621565b61266260a06115cd6124c2565b5050509061394e565b919082039182116125a657565b60405190612685826123cf565b8160406001600160801b036008548060020b84528060181c60020b602085015260301c16910152565b6126b6612678565b6009549060408101906001600160801b0382511615801561278a575b612783576126e360a06115cd6124c2565b5050509161270460206126f9845160020b613621565b93015160020b613621565b5f939091906001600160a01b03808216908516811161274b5750505161273493506001600160801b031691613998565b808211156127455761243e9161266b565b50505f90565b9093506001600160a01b03831611612766575b505050612734565b5161277b93506001600160801b031691613998565b5f808061275e565b5050505f90565b5082156126d2565b6001600160801b0360125416801561237f5761243e906127b560a06115cd6124c2565b5050506127e17f0000000000000000000000000000000000000000000000000000000000000000613621565b90613998565b60ff600a541615801561284e575b801561283b575b61283757601354600b54118015906128115790565b5061281a6126ae565b612822612361565b801515918261283057505090565b1015905090565b5f90565b506001600160801b0360125416156127fc565b5060ff60165416156127f5565b6001600160801b0360085460301c1615612614576124b5610aa6610ac3604051612886602082612405565b5f815260405192839160208301612441565b51906001600160a01b038216820361207657565b51908160020b820361207657565b7f0000000000000000000000000000000000000000000000000000000000000000906001600160a01b0382169060603383900361004c57601f54945f9560ff8116156132bf5760ff1916601f558201916040818403126120765780359060ff8216809203612076576020810135906001600160401b03821161207657019183601f8401121561207657823561294e816125ba565b9361295c6040519586612405565b81855260208501956020838301011161207657815f92602080930188378501015260018214612ec0575060078114612eb35760058114612e975760068114612c4a5760028114612c035760038114612be1576004146129c457637618476960e01b8552600485fd5b8060209195939495518101031261069e576129f7906001600160a01b03906129eb90612898565b169360a0610b906124c2565b505050906001600160801b0360125416612b92575b612a626001600160801b03601254167f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000614456565b93909485612b2d575b84612a9a575b505050612a7d90614547565b60405191602083015260408201526040815261243e606082612405565b813b156111f157604051630b0d9c0960e01b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000081166004830152919091166024820152604481018590529082908290606490829084905af18015612b2257612b0d575b80612a71565b612b18828092612405565b6104325780612b07565b6040513d84823e3d90fd5b813b156111f157604051630b0d9c0960e01b81525f600482015230602482015260448101879052838160648183875af18015612b8757908491612b72575b5050612a6b565b81612b7c91612405565b6111f157825f612b6b565b6040513d86823e3d90fd5b612bdc7f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006141d4565b612a0c565b5050505050612bee6140ec565b5060405190612bfe602083612405565b815290565b506040919350808095935051810103126104325750906040612c27612c30936128ac565b9101519061406f565b60405190151560208201526020815261243e604082612405565b506020919293508051810103126111f1576001600160a01b0390612c6d90612898565b1690601b5490601c549082612d9d575b81612cc3575b507fdeb5099d7943aa2b4c1142e5d53d2f7636aa8f7bd130ec79816f151572bcdf459160409182519182526020820152a260405190612bfe602083612405565b84601c55803b15612d7957604051637a94c56560e11b81523060048201525f602482015260448101839052858160648183865af18015612d9257908691612d7d575b5050803b15612d7957604051630b0d9c0960e01b81525f60048201526001600160a01b0385166024820152604481018390529085908290606490829084905af18015612d6e57908591612d59575b50612c83565b81612d6391612405565b611bea57835f612d53565b6040513d87823e3d90fd5b8480fd5b81612d8791612405565b612d7957845f612d05565b6040513d88823e3d90fd5b601b8590557f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316813b15612e7357604051637a94c56560e11b81523060048201526024810182905260448101859052868160648183875af18015612e8c57908791612e77575b5050813b15612e7357604051630b0d9c0960e01b81526001600160a01b039182166004820152908516602482015260448101849052858160648183865af18015612d9257908691612e5e575b5050612c7d565b81612e6891612405565b612d7957845f612e57565b8580fd5b81612e8191612405565b612e7357855f612e0b565b6040513d89823e3d90fd5b5050505050612ea4613d71565b60405190612bfe602083612405565b5050505050612ea4613c57565b939450509060808280979697518101031261207657612ede90612898565b926040820151906001600160801b03821680920361207657608084840151930151947f0000000000000000000000000000000000000000000000000000000000000000957f0000000000000000000000000000000000000000000000000000000000000000936001600160801b03601254166132b0575b612f5d6124c2565b9460405198612f6b8a6123ea565b60020b895260020b602089015260408801525f868801526040602097815195612f948a88612405565b5f8752612fb483519788938493632d35e7ed60e11b855260048501613bed565b03815f875af19384156131e8575f9461327e575b508360801d600f0b5f81138015613272575b61326357612fea612ff391613c38565b94600f0b613c38565b9484811061324d57508085116132375750826131f3575b8361302f575b505061243e939495506040519485015260408401526040835282612405565b7f000000000000000000000000000000000000000000000000000000000000000090823b1561207657604051632961046560e21b81526001600160a01b03831660048201525f8160248183885af180156131e8576131cc575b508892879290916001600160a01b0381166131525750816014528560345263a9059cbb60601b845282846044601082855af190816001865114161561312b575b5050826034525b600460405180948193630476982d60e21b83525af18015612e8c5761243e959697506130fe575b869594613010565b61311d90863d8811613124575b6131158183612405565b810190613c48565b505f6130f6565b503d61310b565b91935091503d903b15171015613145578487915f806130c8565b6390b8ec1887526004601cfd5b60408051888a529084905290881b6bffffffffffffffffffffffff1916602c526323b872dd60601b600c529083856064601c82855af19081600187511416156131a3575b50508387526040526130cf565b9193509193503d903b151710156131bf57879186915f80613196565b637939f42488526004601cfd5b879299505f6131dd91949294612405565b5f9891929092613088565b6040513d5f823e3d90fd5b604051630476982d60e21b8152868160048187875af180156131e85761321a575b5061300a565b61323090873d8911613124576131158183612405565b505f613214565b8463ac75201360e01b5f5260045260245260445ffd5b8463ebbfb3bb60e01b5f5260045260245260445ffd5b63c74a40f960e01b5f5260045ffd5b505f85600f0b13612fda565b6132a191945060403d6040116132a9575b6132998183612405565b810190612583565b50925f612fc8565b503d61328f565b6132ba85896141d4565b612f55565b637618476960e01b5f5260045ffd5b303303613300576001600160801b0360085460301c1615612614576124b5610aa6610ac3604051612886602082612405565b6314e1dbf760e11b5f5260045ffd5b6017541580613364575b8061335a575b612614576124b5610aa6610ac360405161333a602082612405565b5f8152604051928391600560208401526040808401526060830190612311565b506019541561331f565b5060185415613319565b91906020906040518281019182526006604082015260408152613392606082612405565b519020604051631e2eaeaf60e01b8152600481019190915292839060249082906001600160a01b03165afa9182156131e8575f926133f3575b506001600160a01b0382169160a081901c60020b9162ffffff60b883901c81169260d01c1690565b9091506020813d60201161341f575b8161340f60209383612405565b810103126120765751905f6133cb565b3d9150613402565b638b78c6d81954330361343657565b6382b429005f526004601cfd5b5f61347791600160ff19601f541617601f55604051809381926348c8949160e01b8352602060048401526024830190612311565b0381837f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165af19081156131e8575f916134b7575090565b90503d805f833e6134c88183612405565b810190602081830312612076578051906001600160401b038211612076570181601f82011215612076578051906134fe826125ba565b9261350c6040519485612405565b8284526020838301011161207657815f9260208093018386015e8301015290565b5f80809338935af11561353c57565b63b12d13eb5f526004601cfd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316330361004c5760a036602319011261207657604051613591816123b4565b6024356001600160a01b03811681036120765781526044356001600160a01b038116810361207657602082015260643562ffffff811681036120765760408201526084358060020b810361207657606082015260a435906001600160a01b03821682036120765760a09160808201522060a061360b6124c2565b200361361357565b62820f3560e61b5f5260045ffd5b60020b908160ff1d82810118620d89e8811161393b5763ffffffff9192600182167001fffcb933bd6fad37aa2d162d1a59400102600160801b18916002811661391f575b60048116613903575b600881166138e7575b601081166138cb575b602081166138af575b60408116613893575b60808116613877575b610100811661385b575b610200811661383f575b6104008116613823575b6108008116613807575b61100081166137eb575b61200081166137cf575b61400081166137b3575b6180008116613797575b62010000811661377b575b620200008116613760575b620400008116613745575b620800001661372c575b5f12613724575b0160201c90565b5f190461371d565b6b048a170391f7dc42444e8fa290910260801c90613716565b6d2216e584f5fa1ea926041bedfe9890920260801c9161370c565b916e5d6af8dedb81196699c329225ee6040260801c91613701565b916f09aa508b5b7a84e1c677de54f3e99bc90260801c916136f6565b916f31be135f97d08fd981231505542fcfa60260801c916136eb565b916f70d869a156d2a1b890bb3df62baf32f70260801c916136e1565b916fa9f746462d870fdf8a65dc1f90e061e50260801c916136d7565b916fd097f3bdfd2022b8845ad8f792aa58250260801c916136cd565b916fe7159475a2c29b7443b29c7fa6e889d90260801c916136c3565b916ff3392b0822b70005940c7a398e4b70f30260801c916136b9565b916ff987a7253ac413176f2b074cf7815e540260801c916136af565b916ffcbe86c7900a88aedcffc83b479aa3a40260801c916136a5565b916ffe5dee046a99a2a811c461f1969c30530260801c9161369b565b916fff2ea16466c96a3843ec78b326b528610260801c91613692565b916fff973b41fa98c081472e6896dfb254c00260801c91613689565b916fffcb9843d60f6159c9db58835c9266440260801c91613680565b916fffe5caca7e10e4e61c3624eaa0941cd00260801c91613677565b916ffff2e50f5f656932ef12357cf3c7fdcc0260801c9161366e565b916ffff97272373d413259a46990580e213a0260801c91613665565b826345c3193d60e11b5f5260045260245ffd5b61243e926001600160a01b03928316919092160360ff81901d90810118906001600160801b0316614a94565b8115613984570490565b634e487b7160e01b5f52601260045260245ffd5b906001600160a01b0380821690831611613a05575b6001600160a01b0382169182156139f95761243e936139f4926001600160a01b0380821693909103169060601b6fffffffffffffffffffffffffffffffff60601b16614add565b61397a565b62bfc9215f526004601cfd5b906139ad565b60018060a01b031680638b78c6d819547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a3638b78c6d81955565b90600c549182158015613b31575b612783576001600160801b03601254161561278357818111613b29575b5062ffffff7f0000000000000000000000000000000000000000000000000000000000000000169081810291620f424082158284860414170215613ac7575050620f42409004905b8082101561237a575090565b620f4240905f198184098481108501900392099080620f42401115613b1c57828211900360fa1b910360061c177fde8f6cefed634549b62c77574f722e1ac57e23f24d8fd5cb790fb65668c261390290613abb565b63ae47f7025f526004601cfd5b90505f613a73565b5060ff600a541615613a56565b60020b60010190627fffff8213627fffff198312176125a657565b9060020b9060020b0190627fffff198212627fffff8313176125a657565b90601354808211613be5575b508015613be15761261491613b966125d5565b613ba28260135461266b565b6013556040518281526001600160a01b038216907f0cbcc38bb40a7b0940c989eac5abd480ff9917c824c1fd6b2e38227d92c4c70090602090a261352d565b5050565b90505f613b83565b606061243e9493613c0183610140956122a1565b805160020b60a0840152602081015160020b60c0840152604081015160e08401520151610100820152816101208201520190612311565b600160ff1b81146125a6575f0390565b90816020910312612076575190565b6019545f908015613be1575f6019557f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316803b1561207657604051637a94c56560e11b81523060048201525f60248201819052604482018490528160648183865af180156131e857613d5c575b50803b156111f157604051630b0d9c0960e01b81525f6004820152306024820152604481018390529083908290606490829084905af180156111fd57613d47575b507f10ea71883ef0e28b7b04d488d5ffc5952921ddb354e9b56f9331956a80fc9bab916060916040519180835260208301526040820152a1565b613d52838092612405565b61069e575f613d0d565b613d699193505f90612405565b5f915f613ccc565b601754601854601954915f613d868383612599565b9081159182159081613ece575b508515159182613def575b5091613de7575b50613daf57505050565b7f10ea71883ef0e28b7b04d488d5ffc5952921ddb354e9b56f9331956a80fc9bab9260609260405192835260208301526040820152a1565b90505f613da5565b60198190557f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316803b1561069e57604051637a94c56560e11b81523060048201525f602482015260448101899052828160648183865af180156111fd57908391613eb9575b5050803b1561069e57604051630b0d9c0960e01b81525f6004820152306024820152604481018990529082908290606490829084905af18015612b2257613ea4575b50613d9e565b613eaf828092612405565b6104325780613e9e565b81613ec391612405565b61069e57815f613e5c565b5f60178190556018556001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116917f000000000000000000000000000000000000000000000000000000000000000090911690823b1561207657604051637a94c56560e11b81523060048201526024810183905260448101919091525f8160648183875af180156131e85761405a575b5086613fe7575b85613f78575b50613d93565b83546001600160a01b031690823b15612d7957604051630b0d9c0960e01b81526001600160a01b03918216600482015291166024820152604481018690529083908290606490829084905af180156111fd5790839115613f725781613fdc91612405565b61069e57815f613f72565b6001546001600160a01b0316823b15612d7957604051630b0d9c0960e01b81526001600160a01b03838116600483015291909116602482015260448101889052848160648183875af18015612d6e57908591614045575b5050613f6c565b8161404f91612405565b611bea57835f61403e565b6140679194505f90612405565b5f925f613f65565b6001600160801b036012541615612745577f5da4124c44e7ab5ea52a261f5f3cb8e7dc215e9eaf017eadcefff627b8247b1260206140c8836140c36140b26140ec565b96806013548091116140e45761266b565b614be3565b926040519060020b8152a181156140dd575090565b9050151590565b90508061266b565b6140f4612678565b60408101906001600160801b03825116156127455761419d6141cc6141956001600160801b037fbdf538edac463a73738d4acbf04fd09f49a98ef14daa6985cb9febb3cf2840629561417c61414c60a06115cd6124c2565b50505096805160020b906141696020820192835160020b906141d4565b5160020b905160020b8484511691614456565b5f6008959295555f60095561419085614efc565b614fa4565b959096614547565b51169260405194859485909493926060926001600160801b036080840197168352602083015260408201520152565b0390a1600190565b907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690604061420a6124c2565b935f92825191614219836123ea565b60020b825260020b60208201525f828201525f606082015281519461423f602087612405565b5f865261425f83519687938493632d35e7ed60e11b855260048501613bed565b03815f865af19283156131e8575f93614433575b508260801d925f81600f0b135f1461442b576001600160801b0316925b5f81600f0b135f14614423576001600160801b0316915b83159182159081614388575b841515928361430c575b505091614304575b506142ce575050565b7faf7c505ee772ec188af7067e1f73db08ab028e3d564273442b907742b9c41fa09160409143601a5582519182526020820152a1565b90505f6142c5565b803b1561069e57604051630ab714fb60e11b81523060048201525f6024820152604481018790529082908290606490829084905af18015612b2257614373575b505061435a84601c54612599565b601c5561436984601e54612599565b601e555f806142bd565b61437e828092612405565b610432578061434c565b823b1561207657604051630ab714fb60e11b81523060048201526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000166024820152604481018790525f8160648183885af180156131e857614410575b506143f986601b54612599565b601b5561440886601d54612599565b601d556142b3565b61441c91505f90612405565b5f5f6143ec565b505f916142a7565b505f92614290565b61444d91935060403d6040116132a9576132998183612405565b9050915f614273565b60409193929361446d6144676124c2565b95613c38565b9083519261447a846123ea565b60020b835260020b6020830152828201525f606082015281519361449f602086612405565b5f85526144bf83519586938493632d35e7ed60e11b855260048501613bed565b03815f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165af19182156131e8575f92614525575b508160801d600f0b5f81128015614519575b6132635791600f0b90565b505f83600f0b1261450e565b61453f91925060403d6040116132a9576132998183612405565b50905f6144fc565b61455460a06115cd6124c2565b5050506001600160a01b03908116911680820361456f575050565b6376bc6d9160e11b5f5260045260245260445ffd5b601a544311156126145760175415806145da575b806145d0575b61261457303b1561207657604051637b44e4c560e11b81525f8160048183305af16145c65750565b5f61261491612405565b506019541561459e565b5060185415614598565b818102929181159184041417156125a657565b6001600160801b036012541680156124b55761461660a06115cd6124c2565b5050507f00000000000000000000000000000000000000000000000000000000000000009161464e818361464986613621565b61394e565b60115480821061478b57506146656011548261266b565b9081158015614762575b61475b5761467d9183614b5d565b8015614755576146b7816001600160801b03957f000000000000000000000000000000000000000000000000000000000000000090614456565b94909116809203906001600160801b0382116125a65761472461471c7f32afb9555b0493ac0021ef7f6b122197e9e58510e694383410f667ec76e4f0fa966001600160801b0361475095166001600160801b0319601254161760125561419084614efc565b919095614547565b60405194859485909493926060926001600160801b036080840197168352602083015260408201520152565b0390a1565b50505050565b5050505050565b507f0000000000000000000000000000000000000000000000000000000000000000821061466f565b93506147b4925061271091506147a46147ad918561266b565b600354906145e4565b048261266b565b906006546147c2814261266b565b90620151806147d460055493846145e4565b04808411156148e0576147e7908461266b565b8085106148d8575b506004548085106148d0575b508284106148095750505050565b614813848461266b565b821590811561485d575b5050505060407fa66e3643af3b5a570ea09b8d485f206950ff1ee042471a211388199518f539a6918151908152836020820152a16011555f808080614755565b62015180819593949502908082046201518014901517156125a6576148886148999160075490612599565b93614893868661397a565b90612599565b6006556139845791900660075560407fa66e3643af3b5a570ea09b8d485f206950ff1ee042471a211388199518f539a65f8061481d565b93505f6147fb565b93505f6147ef565b505f6147e7565b600291820b910b0390627fffff198212627fffff8313176125a657565b600d54908160881c60020b90819261491e600f544261266b565b90816149a7575b505061493090614a55565b8160020b8160020b1361499f575b508060020b9180830361495057505050565b7f73cd8288dc6e2d815bcc3fdbd71bdcc73cb3ad258d80587c5c90d8c85388cd5492604092600d549060881b62ffffff60881b169062ffffff60881b191617600d5582519182526020820152a1565b90505f61493e565b6149bb909391929342600f5560020b614a55565b908160020b928184125f14614a4357620151808111614a39575b6149e46149ed91600e546145e4565b60105490612599565b6201518080820491066010555f8483039412828512811690838613901516176125a657614930938110614a265750505b915b905f614925565b614a34925060020b906148e7565b614a1d565b50620151806149d5565b5092905061493091505f601055614a1f565b614a5e90613b3e565b907f00000000000000000000000000000000000000000000000000000000000000008060020b8360020b13614a905750565b9150565b81810291905f1982820991838084109303928084039384600160601b11156120765714614ad457600160601b910990828211900360a01b910360601c1790565b50505060601c90565b91818302915f19818509938380861095039480860395868511156120765714614b55579082910981805f03168092046002816003021880820260020302808202600203028082026002030280820260020302808202600203028091026002030293600183805f03040190848311900302920304170290565b505091500490565b81810292918115828504821417830215614b78575050900490565b82905f1981840985811086019003920990825f0383169281811115613b1c5783900480600302600218808202600203028082026002030280820260020302808202600203028082026002030280910260020302936001848483030494805f0304019211900302170290565b8015612745577f0000000000000000000000000000000000000000000000000000000000000000908160020b8360020b9281841215614ef357614c2585613621565b614c2e82613621565b6001600160a01b039182169116808202828104821483151760601b15614eb657614c6692614c5f9160601c9261266b565b9085614b5d565b9081158015614ea6575b614e9757614d0e956001600160801b038316947f0000000000000000000000000000000000000000000000000000000000000000906040614cb460a0610a1e6124c2565b50505092614cc06124c2565b908251614ccc816123ea565b8b81528960208201528a848201525f60608201525f845193614cef602086612405565b8185528551632d35e7ed60e11b81529e8f958694859360048501613bed565b03926001600160a01b03165af19889156131e8575f99614e75575b508860801d600f0b5f81138015614e69575b61326357614d4b614d5491613c38565b99600f0b613c38565b80614e575750808911614e415750916080959391614d9d7fe3966151f83ca37a8d733ac53f8f5122134c74fc747f8ea857c2ba5e49f68b73989694614d988b615115565b614547565b614da98960135461266b565b6013558460408051614dba816123cf565b888152866020820152015262ffffff19600854169062ffffff16176008556008549060181b60050b65ffffff000000169065ffffff0000001916176008556601000000000000600160b01b036008549160301b16906601000000000000600160b01b031916176008558560095560405192835260208301526040820152836060820152a190565b8863ebbfb3bb60e01b5f5260045260245260445ffd5b6308e0272d60e01b5f5260045260245ffd5b505f8a600f0b13614d3b565b614e8f91995060403d6040116132a9576132998183612405565b50975f614d29565b631fff968160e01b5f5260045ffd5b506001600160801b038211614c70565b5f198284098181108201900392600160601b838209600160601b851015613b1c57614c66948382614c5f950360601c9211900360a01b179261266b565b50505050505f90565b80156124b5577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690813b1561207657604051630ab714fb60e11b81523060048201525f602482018190526044820183905290928390606490829084905af19182156131e857614f8f92614f94575b5043601a55614f8481601954612599565b601955601354612599565b601355565b5f614f9e91612405565b5f614f73565b801561510e5760025480820290612710818484041402156150bb57506127109004915b8291614fd3848261266b565b937f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316803b1561207657604051630ab714fb60e11b81523060048201526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016602482015260448101939093525f908390606490829084905af19182156131e857615088926150ab575b5043601a5561507d81601554612599565b601555601854612599565b60185561509783601454612599565b6014556150a683601754612599565b601755565b5f6150b591612405565b5f61506c565b6127105f198285098381108401900391840990806127101115613b1c57828211900360fc1b910360041c177fbc01a36e2eb1c432ca57a786c226809d495182a9930be0ded288ce703afb7e910291614fc7565b505f905f90565b5f8115613be1576019548083101561524a5782905b816151bc575b5061513b919261266b565b9081615145575050565b604051630476982d60e21b815291602090839060049082907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165af19081156151b057506151985750565b6124b59060203d602011613124576131158183612405565b604051903d90823e3d90fd5b816151c69161266b565b6019557f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316803b1561207657604051637a94c56560e11b81523060048201525f602482018190526044820184905290918290606490829084905af180156131e857156151305761513b92505f61524391612405565b5f91615130565b8061512a56fea26469706673582212204b742b4842ddf3573797eeb169fd986dbed9f8e760799b9572ac9f8ef7d1eba064736f6c634300081e0033000000000000000000000000047f606fd5b2baa5f5c6c4ab8958e45cb6b054b7000000000000000000000000000000000004444c5dc75cb358380d2e3de08a90000000000000000000000000d34a99bc0f67ae1bbd63c660e6d0b0dd03e263b7000000000000000000000000e29386719c155b6847ad5a4e97c6674f10ffc7500000000000000000000000009046739e1535b40efbe6ab3f45d0024b690eca3000000000000000000000000000000000000000000000000000000000000005dc00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002710000000000000000000000000000000000000000000000000000000000000003c","name":"CappedBurnHook","is_blueprint":false,"license_type":"none","is_fully_verified":true,"is_verified_via_eth_bytecode_db":true,"language":"solidity","evm_version":"osaka","can_be_visualized_via_sol2uml":true,"is_verified_via_sourcify":false,"additional_sources":[{"file_path":"lib/solady/src/auth/Ownable.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.4;\n\n/// @notice Simple single owner authorization mixin.\n/// @author Solady (https://github.com/vectorized/solady/blob/main/src/auth/Ownable.sol)\n///\n/// @dev Note:\n/// This implementation does NOT auto-initialize the owner to `msg.sender`.\n/// You MUST call the `_initializeOwner` in the constructor / initializer.\n///\n/// While the ownable portion follows\n/// [EIP-173](https://eips.ethereum.org/EIPS/eip-173) for compatibility,\n/// the nomenclature for the 2-step ownership handover may be unique to this codebase.\nabstract contract Ownable {\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                       CUSTOM ERRORS                        */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev The caller is not authorized to call the function.\n    error Unauthorized();\n\n    /// @dev The `newOwner` cannot be the zero address.\n    error NewOwnerIsZeroAddress();\n\n    /// @dev The `pendingOwner` does not have a valid handover request.\n    error NoHandoverRequest();\n\n    /// @dev Cannot double-initialize.\n    error AlreadyInitialized();\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                           EVENTS                           */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev The ownership is transferred from `oldOwner` to `newOwner`.\n    /// This event is intentionally kept the same as OpenZeppelin's Ownable to be\n    /// compatible with indexers and [EIP-173](https://eips.ethereum.org/EIPS/eip-173),\n    /// despite it not being as lightweight as a single argument event.\n    event OwnershipTransferred(address indexed oldOwner, address indexed newOwner);\n\n    /// @dev An ownership handover to `pendingOwner` has been requested.\n    event OwnershipHandoverRequested(address indexed pendingOwner);\n\n    /// @dev The ownership handover to `pendingOwner` has been canceled.\n    event OwnershipHandoverCanceled(address indexed pendingOwner);\n\n    /// @dev `keccak256(bytes(\"OwnershipTransferred(address,address)\"))`.\n    uint256 private constant _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE =\n        0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0;\n\n    /// @dev `keccak256(bytes(\"OwnershipHandoverRequested(address)\"))`.\n    uint256 private constant _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE =\n        0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d;\n\n    /// @dev `keccak256(bytes(\"OwnershipHandoverCanceled(address)\"))`.\n    uint256 private constant _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE =\n        0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92;\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                          STORAGE                           */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev The owner slot is given by:\n    /// `bytes32(~uint256(uint32(bytes4(keccak256(\"_OWNER_SLOT_NOT\")))))`.\n    /// It is intentionally chosen to be a high value\n    /// to avoid collision with lower slots.\n    /// The choice of manual storage layout is to enable compatibility\n    /// with both regular and upgradeable contracts.\n    bytes32 internal constant _OWNER_SLOT =\n        0xffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927;\n\n    /// The ownership handover slot of `newOwner` is given by:\n    /// ```\n    ///     mstore(0x00, or(shl(96, user), _HANDOVER_SLOT_SEED))\n    ///     let handoverSlot := keccak256(0x00, 0x20)\n    /// ```\n    /// It stores the expiry timestamp of the two-step ownership handover.\n    uint256 private constant _HANDOVER_SLOT_SEED = 0x389a75e1;\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                     INTERNAL FUNCTIONS                     */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Override to return true to make `_initializeOwner` prevent double-initialization.\n    function _guardInitializeOwner() internal pure virtual returns (bool guard) {}\n\n    /// @dev Initializes the owner directly without authorization guard.\n    /// This function must be called upon initialization,\n    /// regardless of whether the contract is upgradeable or not.\n    /// This is to enable generalization to both regular and upgradeable contracts,\n    /// and to save gas in case the initial owner is not the caller.\n    /// For performance reasons, this function will not check if there\n    /// is an existing owner.\n    function _initializeOwner(address newOwner) internal virtual {\n        if (_guardInitializeOwner()) {\n            /// @solidity memory-safe-assembly\n            assembly {\n                let ownerSlot := _OWNER_SLOT\n                if sload(ownerSlot) {\n                    mstore(0x00, 0x0dc149f0) // `AlreadyInitialized()`.\n                    revert(0x1c, 0x04)\n                }\n                // Clean the upper 96 bits.\n                newOwner := shr(96, shl(96, newOwner))\n                // Store the new value.\n                sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner))))\n                // Emit the {OwnershipTransferred} event.\n                log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner)\n            }\n        } else {\n            /// @solidity memory-safe-assembly\n            assembly {\n                // Clean the upper 96 bits.\n                newOwner := shr(96, shl(96, newOwner))\n                // Store the new value.\n                sstore(_OWNER_SLOT, newOwner)\n                // Emit the {OwnershipTransferred} event.\n                log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner)\n            }\n        }\n    }\n\n    /// @dev Sets the owner directly without authorization guard.\n    function _setOwner(address newOwner) internal virtual {\n        if (_guardInitializeOwner()) {\n            /// @solidity memory-safe-assembly\n            assembly {\n                let ownerSlot := _OWNER_SLOT\n                // Clean the upper 96 bits.\n                newOwner := shr(96, shl(96, newOwner))\n                // Emit the {OwnershipTransferred} event.\n                log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner)\n                // Store the new value.\n                sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner))))\n            }\n        } else {\n            /// @solidity memory-safe-assembly\n            assembly {\n                let ownerSlot := _OWNER_SLOT\n                // Clean the upper 96 bits.\n                newOwner := shr(96, shl(96, newOwner))\n                // Emit the {OwnershipTransferred} event.\n                log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner)\n                // Store the new value.\n                sstore(ownerSlot, newOwner)\n            }\n        }\n    }\n\n    /// @dev Throws if the sender is not the owner.\n    function _checkOwner() internal view virtual {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // If the caller is not the stored owner, revert.\n            if iszero(eq(caller(), sload(_OWNER_SLOT))) {\n                mstore(0x00, 0x82b42900) // `Unauthorized()`.\n                revert(0x1c, 0x04)\n            }\n        }\n    }\n\n    /// @dev Returns how long a two-step ownership handover is valid for in seconds.\n    /// Override to return a different value if needed.\n    /// Made internal to conserve bytecode. Wrap it in a public function if needed.\n    function _ownershipHandoverValidFor() internal view virtual returns (uint64) {\n        return 48 * 3600;\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                  PUBLIC UPDATE FUNCTIONS                   */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Allows the owner to transfer the ownership to `newOwner`.\n    function transferOwnership(address newOwner) public payable virtual onlyOwner {\n        /// @solidity memory-safe-assembly\n        assembly {\n            if iszero(shl(96, newOwner)) {\n                mstore(0x00, 0x7448fbae) // `NewOwnerIsZeroAddress()`.\n                revert(0x1c, 0x04)\n            }\n        }\n        _setOwner(newOwner);\n    }\n\n    /// @dev Allows the owner to renounce their ownership.\n    function renounceOwnership() public payable virtual onlyOwner {\n        _setOwner(address(0));\n    }\n\n    /// @dev Request a two-step ownership handover to the caller.\n    /// The request will automatically expire in 48 hours (172800 seconds) by default.\n    function requestOwnershipHandover() public payable virtual {\n        unchecked {\n            uint256 expires = block.timestamp + _ownershipHandoverValidFor();\n            /// @solidity memory-safe-assembly\n            assembly {\n                // Compute and set the handover slot to `expires`.\n                mstore(0x0c, _HANDOVER_SLOT_SEED)\n                mstore(0x00, caller())\n                sstore(keccak256(0x0c, 0x20), expires)\n                // Emit the {OwnershipHandoverRequested} event.\n                log2(0, 0, _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE, caller())\n            }\n        }\n    }\n\n    /// @dev Cancels the two-step ownership handover to the caller, if any.\n    function cancelOwnershipHandover() public payable virtual {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Compute and set the handover slot to 0.\n            mstore(0x0c, _HANDOVER_SLOT_SEED)\n            mstore(0x00, caller())\n            sstore(keccak256(0x0c, 0x20), 0)\n            // Emit the {OwnershipHandoverCanceled} event.\n            log2(0, 0, _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE, caller())\n        }\n    }\n\n    /// @dev Allows the owner to complete the two-step ownership handover to `pendingOwner`.\n    /// Reverts if there is no existing ownership handover requested by `pendingOwner`.\n    function completeOwnershipHandover(address pendingOwner) public payable virtual onlyOwner {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Compute and set the handover slot to 0.\n            mstore(0x0c, _HANDOVER_SLOT_SEED)\n            mstore(0x00, pendingOwner)\n            let handoverSlot := keccak256(0x0c, 0x20)\n            // If the handover does not exist, or has expired.\n            if gt(timestamp(), sload(handoverSlot)) {\n                mstore(0x00, 0x6f5e8818) // `NoHandoverRequest()`.\n                revert(0x1c, 0x04)\n            }\n            // Set the handover slot to 0.\n            sstore(handoverSlot, 0)\n        }\n        _setOwner(pendingOwner);\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                   PUBLIC READ FUNCTIONS                    */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Returns the owner of the contract.\n    function owner() public view virtual returns (address result) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            result := sload(_OWNER_SLOT)\n        }\n    }\n\n    /// @dev Returns the expiry timestamp for the two-step ownership handover to `pendingOwner`.\n    function ownershipHandoverExpiresAt(address pendingOwner)\n        public\n        view\n        virtual\n        returns (uint256 result)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Compute the handover slot.\n            mstore(0x0c, _HANDOVER_SLOT_SEED)\n            mstore(0x00, pendingOwner)\n            // Load the handover slot.\n            result := sload(keccak256(0x0c, 0x20))\n        }\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                         MODIFIERS                          */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Marks a function as only callable by the owner.\n    modifier onlyOwner() virtual {\n        _checkOwner();\n        _;\n    }\n}\n"},{"file_path":"lib/solady/src/utils/FixedPointMathLib.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.4;\n\n/// @notice Arithmetic library with operations for fixed-point numbers.\n/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/FixedPointMathLib.sol)\n/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol)\nlibrary FixedPointMathLib {\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                       CUSTOM ERRORS                        */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev The operation failed, as the output exceeds the maximum value of uint256.\n    error ExpOverflow();\n\n    /// @dev The operation failed, as the output exceeds the maximum value of uint256.\n    error FactorialOverflow();\n\n    /// @dev The operation failed, due to an overflow.\n    error RPowOverflow();\n\n    /// @dev The mantissa is too big to fit.\n    error MantissaOverflow();\n\n    /// @dev The operation failed, due to an multiplication overflow.\n    error MulWadFailed();\n\n    /// @dev The operation failed, due to an multiplication overflow.\n    error SMulWadFailed();\n\n    /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.\n    error DivWadFailed();\n\n    /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.\n    error SDivWadFailed();\n\n    /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.\n    error MulDivFailed();\n\n    /// @dev The division failed, as the denominator is zero.\n    error DivFailed();\n\n    /// @dev The full precision multiply-divide operation failed, either due\n    /// to the result being larger than 256 bits, or a division by a zero.\n    error FullMulDivFailed();\n\n    /// @dev The output is undefined, as the input is less-than-or-equal to zero.\n    error LnWadUndefined();\n\n    /// @dev The input outside the acceptable domain.\n    error OutOfDomain();\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                         CONSTANTS                          */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev The scalar of ETH and most ERC20s.\n    uint256 internal constant WAD = 1e18;\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*              SIMPLIFIED FIXED POINT OPERATIONS             */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Equivalent to `(x * y) / WAD` rounded down.\n    function mulWad(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`.\n            if gt(x, div(not(0), y)) {\n                if y {\n                    mstore(0x00, 0xbac65e5b) // `MulWadFailed()`.\n                    revert(0x1c, 0x04)\n                }\n            }\n            z := div(mul(x, y), WAD)\n        }\n    }\n\n    /// @dev Equivalent to `(x * y) / WAD` rounded down.\n    function sMulWad(int256 x, int256 y) internal pure returns (int256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := mul(x, y)\n            // Equivalent to `require((x == 0 || z / x == y) && !(x == -1 && y == type(int256).min))`.\n            if iszero(gt(or(iszero(x), eq(sdiv(z, x), y)), lt(not(x), eq(y, shl(255, 1))))) {\n                mstore(0x00, 0xedcd4dd4) // `SMulWadFailed()`.\n                revert(0x1c, 0x04)\n            }\n            z := sdiv(z, WAD)\n        }\n    }\n\n    /// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks.\n    function rawMulWad(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := div(mul(x, y), WAD)\n        }\n    }\n\n    /// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks.\n    function rawSMulWad(int256 x, int256 y) internal pure returns (int256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := sdiv(mul(x, y), WAD)\n        }\n    }\n\n    /// @dev Equivalent to `(x * y) / WAD` rounded up.\n    function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := mul(x, y)\n            // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`.\n            if iszero(eq(div(z, y), x)) {\n                if y {\n                    mstore(0x00, 0xbac65e5b) // `MulWadFailed()`.\n                    revert(0x1c, 0x04)\n                }\n            }\n            z := add(iszero(iszero(mod(z, WAD))), div(z, WAD))\n        }\n    }\n\n    /// @dev Equivalent to `(x * y) / WAD` rounded up, but without overflow checks.\n    function rawMulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := add(iszero(iszero(mod(mul(x, y), WAD))), div(mul(x, y), WAD))\n        }\n    }\n\n    /// @dev Equivalent to `(x * WAD) / y` rounded down.\n    function divWad(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Equivalent to `require(y != 0 && x <= type(uint256).max / WAD)`.\n            if iszero(mul(y, lt(x, add(1, div(not(0), WAD))))) {\n                mstore(0x00, 0x7c5f487d) // `DivWadFailed()`.\n                revert(0x1c, 0x04)\n            }\n            z := div(mul(x, WAD), y)\n        }\n    }\n\n    /// @dev Equivalent to `(x * WAD) / y` rounded down.\n    function sDivWad(int256 x, int256 y) internal pure returns (int256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := mul(x, WAD)\n            // Equivalent to `require(y != 0 && ((x * WAD) / WAD == x))`.\n            if iszero(mul(y, eq(sdiv(z, WAD), x))) {\n                mstore(0x00, 0x5c43740d) // `SDivWadFailed()`.\n                revert(0x1c, 0x04)\n            }\n            z := sdiv(z, y)\n        }\n    }\n\n    /// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks.\n    function rawDivWad(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := div(mul(x, WAD), y)\n        }\n    }\n\n    /// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks.\n    function rawSDivWad(int256 x, int256 y) internal pure returns (int256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := sdiv(mul(x, WAD), y)\n        }\n    }\n\n    /// @dev Equivalent to `(x * WAD) / y` rounded up.\n    function divWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Equivalent to `require(y != 0 && x <= type(uint256).max / WAD)`.\n            if iszero(mul(y, lt(x, add(1, div(not(0), WAD))))) {\n                mstore(0x00, 0x7c5f487d) // `DivWadFailed()`.\n                revert(0x1c, 0x04)\n            }\n            z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y))\n        }\n    }\n\n    /// @dev Equivalent to `(x * WAD) / y` rounded up, but without overflow and divide by zero checks.\n    function rawDivWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y))\n        }\n    }\n\n    /// @dev Equivalent to `x` to the power of `y`.\n    /// because `x ** y = (e ** ln(x)) ** y = e ** (ln(x) * y)`.\n    /// Note: This function is an approximation.\n    function powWad(int256 x, int256 y) internal pure returns (int256) {\n        // Using `ln(x)` means `x` must be greater than 0.\n        return expWad((lnWad(x) * y) / int256(WAD));\n    }\n\n    /// @dev Returns `exp(x)`, denominated in `WAD`.\n    /// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln\n    /// Note: This function is an approximation. Monotonically increasing.\n    function expWad(int256 x) internal pure returns (int256 r) {\n        unchecked {\n            // When the result is less than 0.5 we return zero.\n            // This happens when `x <= (log(1e-18) * 1e18) ~ -4.15e19`.\n            if (x <= -41446531673892822313) return r;\n\n            /// @solidity memory-safe-assembly\n            assembly {\n                // When the result is greater than `(2**255 - 1) / 1e18` we can not represent it as\n                // an int. This happens when `x >= floor(log((2**255 - 1) / 1e18) * 1e18) ≈ 135`.\n                if iszero(slt(x, 135305999368893231589)) {\n                    mstore(0x00, 0xa37bfec9) // `ExpOverflow()`.\n                    revert(0x1c, 0x04)\n                }\n            }\n\n            // `x` is now in the range `(-42, 136) * 1e18`. Convert to `(-42, 136) * 2**96`\n            // for more intermediate precision and a binary basis. This base conversion\n            // is a multiplication by 1e18 / 2**96 = 5**18 / 2**78.\n            x = (x << 78) / 5 ** 18;\n\n            // Reduce range of x to (-½ ln 2, ½ ln 2) * 2**96 by factoring out powers\n            // of two such that exp(x) = exp(x') * 2**k, where k is an integer.\n            // Solving this gives k = round(x / log(2)) and x' = x - k * log(2).\n            int256 k = ((x << 96) / 54916777467707473351141471128 + 2 ** 95) >> 96;\n            x = x - k * 54916777467707473351141471128;\n\n            // `k` is in the range `[-61, 195]`.\n\n            // Evaluate using a (6, 7)-term rational approximation.\n            // `p` is made monic, we'll multiply by a scale factor later.\n            int256 y = x + 1346386616545796478920950773328;\n            y = ((y * x) >> 96) + 57155421227552351082224309758442;\n            int256 p = y + x - 94201549194550492254356042504812;\n            p = ((p * y) >> 96) + 28719021644029726153956944680412240;\n            p = p * x + (4385272521454847904659076985693276 << 96);\n\n            // We leave `p` in `2**192` basis so we don't need to scale it back up for the division.\n            int256 q = x - 2855989394907223263936484059900;\n            q = ((q * x) >> 96) + 50020603652535783019961831881945;\n            q = ((q * x) >> 96) - 533845033583426703283633433725380;\n            q = ((q * x) >> 96) + 3604857256930695427073651918091429;\n            q = ((q * x) >> 96) - 14423608567350463180887372962807573;\n            q = ((q * x) >> 96) + 26449188498355588339934803723976023;\n\n            /// @solidity memory-safe-assembly\n            assembly {\n                // Div in assembly because solidity adds a zero check despite the unchecked.\n                // The q polynomial won't have zeros in the domain as all its roots are complex.\n                // No scaling is necessary because p is already `2**96` too large.\n                r := sdiv(p, q)\n            }\n\n            // r should be in the range `(0.09, 0.25) * 2**96`.\n\n            // We now need to multiply r by:\n            // - The scale factor `s ≈ 6.031367120`.\n            // - The `2**k` factor from the range reduction.\n            // - The `1e18 / 2**96` factor for base conversion.\n            // We do this all at once, with an intermediate result in `2**213`\n            // basis, so the final right shift is always by a positive amount.\n            r = int256(\n                (uint256(r) * 3822833074963236453042738258902158003155416615667) >> uint256(195 - k)\n            );\n        }\n    }\n\n    /// @dev Returns `ln(x)`, denominated in `WAD`.\n    /// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln\n    /// Note: This function is an approximation. Monotonically increasing.\n    function lnWad(int256 x) internal pure returns (int256 r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // We want to convert `x` from `10**18` fixed point to `2**96` fixed point.\n            // We do this by multiplying by `2**96 / 10**18`. But since\n            // `ln(x * C) = ln(x) + ln(C)`, we can simply do nothing here\n            // and add `ln(2**96 / 10**18)` at the end.\n\n            // Compute `k = log2(x) - 96`, `r = 159 - k = 255 - log2(x) = 255 ^ log2(x)`.\n            r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))\n            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))\n            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))\n            r := or(r, shl(4, lt(0xffff, shr(r, x))))\n            r := or(r, shl(3, lt(0xff, shr(r, x))))\n            // We place the check here for more optimal stack operations.\n            if iszero(sgt(x, 0)) {\n                mstore(0x00, 0x1615e638) // `LnWadUndefined()`.\n                revert(0x1c, 0x04)\n            }\n            // forgefmt: disable-next-item\n            r := xor(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),\n                0xf8f9f9faf9fdfafbf9fdfcfdfafbfcfef9fafdfafcfcfbfefafafcfbffffffff))\n\n            // Reduce range of x to (1, 2) * 2**96\n            // ln(2^k * x) = k * ln(2) + ln(x)\n            x := shr(159, shl(r, x))\n\n            // Evaluate using a (8, 8)-term rational approximation.\n            // `p` is made monic, we will multiply by a scale factor later.\n            // forgefmt: disable-next-item\n            let p := sub( // This heavily nested expression is to avoid stack-too-deep for via-ir.\n                sar(96, mul(add(43456485725739037958740375743393,\n                sar(96, mul(add(24828157081833163892658089445524,\n                sar(96, mul(add(3273285459638523848632254066296,\n                    x), x))), x))), x)), 11111509109440967052023855526967)\n            p := sub(sar(96, mul(p, x)), 45023709667254063763336534515857)\n            p := sub(sar(96, mul(p, x)), 14706773417378608786704636184526)\n            p := sub(mul(p, x), shl(96, 795164235651350426258249787498))\n            // We leave `p` in `2**192` basis so we don't need to scale it back up for the division.\n\n            // `q` is monic by convention.\n            let q := add(5573035233440673466300451813936, x)\n            q := add(71694874799317883764090561454958, sar(96, mul(x, q)))\n            q := add(283447036172924575727196451306956, sar(96, mul(x, q)))\n            q := add(401686690394027663651624208769553, sar(96, mul(x, q)))\n            q := add(204048457590392012362485061816622, sar(96, mul(x, q)))\n            q := add(31853899698501571402653359427138, sar(96, mul(x, q)))\n            q := add(909429971244387300277376558375, sar(96, mul(x, q)))\n\n            // `p / q` is in the range `(0, 0.125) * 2**96`.\n\n            // Finalization, we need to:\n            // - Multiply by the scale factor `s = 5.549…`.\n            // - Add `ln(2**96 / 10**18)`.\n            // - Add `k * ln(2)`.\n            // - Multiply by `10**18 / 2**96 = 5**18 >> 78`.\n\n            // The q polynomial is known not to have zeros in the domain.\n            // No scaling required because p is already `2**96` too large.\n            p := sdiv(p, q)\n            // Multiply by the scaling factor: `s * 5**18 * 2**96`, base is now `5**18 * 2**192`.\n            p := mul(1677202110996718588342820967067443963516166, p)\n            // Add `ln(2) * k * 5**18 * 2**192`.\n            // forgefmt: disable-next-item\n            p := add(mul(16597577552685614221487285958193947469193820559219878177908093499208371, sub(159, r)), p)\n            // Add `ln(2**96 / 10**18) * 5**18 * 2**192`.\n            p := add(600920179829731861736702779321621459595472258049074101567377883020018308, p)\n            // Base conversion: mul `2**18 / 2**192`.\n            r := sar(174, p)\n        }\n    }\n\n    /// @dev Returns `W_0(x)`, denominated in `WAD`.\n    /// See: https://en.wikipedia.org/wiki/Lambert_W_function\n    /// a.k.a. Product log function. This is an approximation of the principal branch.\n    /// Note: This function is an approximation. Monotonically increasing.\n    function lambertW0Wad(int256 x)\n        internal\n        pure\n        returns (int256 w)\n    {\n\n        // forgefmt: disable-next-item\n        unchecked {\n            if ((w = x) <= -367879441171442322) revert OutOfDomain(); // `x` less than `-1/e`.\n            (int256 wad, int256 p) = (int256(WAD), x);\n            uint256 c; // Whether we need to avoid catastrophic cancellation.\n            uint256 i = 4; // Number of iterations.\n            if (w <= 0x1ffffffffffff) {\n                if (-0x4000000000000 <= w) {\n                    i = 1; // Inputs near zero only take one step to converge.\n                } else if (w <= -0x3ffffffffffffff) {\n                    i = 32; // Inputs near `-1/e` take very long to converge.\n                }\n            } else if (uint256(w >> 63) == uint256(0)) {\n                /// @solidity memory-safe-assembly\n                assembly {\n                    // Inline log2 for more performance, since the range is small.\n                    let v := shr(49, w)\n                    let l := shl(3, lt(0xff, v))\n                    l := add(or(l, byte(and(0x1f, shr(shr(l, v), 0x8421084210842108cc6318c6db6d54be)),\n                        0x0706060506020504060203020504030106050205030304010505030400000000)), 49)\n                    w := sdiv(shl(l, 7), byte(sub(l, 31), 0x0303030303030303040506080c13))\n                    c := gt(l, 60)\n                    i := add(2, add(gt(l, 53), c))\n                }\n            } else {\n                int256 ll = lnWad(w = lnWad(w));\n                /// @solidity memory-safe-assembly\n                assembly {\n                    // `w = ln(x) - ln(ln(x)) + b * ln(ln(x)) / ln(x)`.\n                    w := add(sdiv(mul(ll, 1023715080943847266), w), sub(w, ll))\n                    i := add(3, iszero(shr(68, x)))\n                    c := iszero(shr(143, x))\n                }\n                if (c == uint256(0)) {\n                    do { // If `x` is big, use Newton's so that intermediate values won't overflow.\n                        int256 e = expWad(w);\n                        /// @solidity memory-safe-assembly\n                        assembly {\n                            let t := mul(w, div(e, wad))\n                            w := sub(w, sdiv(sub(t, x), div(add(e, t), wad)))\n                        }\n                        if (p <= w) break;\n                        p = w;\n                    } while (--i != uint256(0));\n                    /// @solidity memory-safe-assembly\n                    assembly {\n                        w := sub(w, sgt(w, 2))\n                    }\n                    return w;\n                }\n            }\n            do { // Otherwise, use Halley's for faster convergence.\n                int256 e = expWad(w);\n                /// @solidity memory-safe-assembly\n                assembly {\n                    let t := add(w, wad)\n                    let s := sub(mul(w, e), mul(x, wad))\n                    w := sub(w, sdiv(mul(s, wad), sub(mul(e, t), sdiv(mul(add(t, wad), s), add(t, t)))))\n                }\n                if (p <= w) break;\n                p = w;\n            } while (--i != c);\n            /// @solidity memory-safe-assembly\n            assembly {\n                w := sub(w, sgt(w, 2))\n            }\n            // For certain ranges of `x`, we'll use the quadratic-rate recursive formula of\n            // R. Iacono and J.P. Boyd for the last iteration, to avoid catastrophic cancellation.\n            if (c == uint256(0)) return w;\n            int256 t = w | 1;\n            /// @solidity memory-safe-assembly\n            assembly {\n                x := sdiv(mul(x, wad), t)\n            }\n            x = (t * (wad + lnWad(x)));\n            /// @solidity memory-safe-assembly\n            assembly {\n                w := sdiv(x, add(wad, t))\n            }\n        }\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                  GENERAL NUMBER UTILITIES                  */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Returns `a * b == x * y`, with full precision.\n    function fullMulEq(uint256 a, uint256 b, uint256 x, uint256 y)\n        internal\n        pure\n        returns (bool result)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            result := and(eq(mul(a, b), mul(x, y)), eq(mulmod(x, y, not(0)), mulmod(a, b, not(0))))\n        }\n    }\n\n    /// @dev Calculates `floor(x * y / d)` with full precision.\n    /// Throws if result overflows a uint256 or when `d` is zero.\n    /// Credit to Remco Bloemen under MIT license: https://2π.com/21/muldiv\n    function fullMulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // 512-bit multiply `[p1 p0] = x * y`.\n            // Compute the product mod `2**256` and mod `2**256 - 1`\n            // then use the Chinese Remainder Theorem to reconstruct\n            // the 512 bit result. The result is stored in two 256\n            // variables such that `product = p1 * 2**256 + p0`.\n\n            // Temporarily use `z` as `p0` to save gas.\n            z := mul(x, y) // Lower 256 bits of `x * y`.\n            for {} 1 {} {\n                // If overflows.\n                if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) {\n                    let mm := mulmod(x, y, not(0))\n                    let p1 := sub(mm, add(z, lt(mm, z))) // Upper 256 bits of `x * y`.\n\n                    /*------------------- 512 by 256 division --------------------*/\n\n                    // Make division exact by subtracting the remainder from `[p1 p0]`.\n                    let r := mulmod(x, y, d) // Compute remainder using mulmod.\n                    let t := and(d, sub(0, d)) // The least significant bit of `d`. `t >= 1`.\n                    // Make sure `z` is less than `2**256`. Also prevents `d == 0`.\n                    // Placing the check here seems to give more optimal stack operations.\n                    if iszero(gt(d, p1)) {\n                        mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.\n                        revert(0x1c, 0x04)\n                    }\n                    d := div(d, t) // Divide `d` by `t`, which is a power of two.\n                    // Invert `d mod 2**256`\n                    // Now that `d` is an odd number, it has an inverse\n                    // modulo `2**256` such that `d * inv = 1 mod 2**256`.\n                    // Compute the inverse by starting with a seed that is correct\n                    // correct for four bits. That is, `d * inv = 1 mod 2**4`.\n                    let inv := xor(2, mul(3, d))\n                    // Now use Newton-Raphson iteration to improve the precision.\n                    // Thanks to Hensel's lifting lemma, this also works in modular\n                    // arithmetic, doubling the correct bits in each step.\n                    inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**8\n                    inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**16\n                    inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**32\n                    inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**64\n                    inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**128\n                    z := mul(\n                        // Divide [p1 p0] by the factors of two.\n                        // Shift in bits from `p1` into `p0`. For this we need\n                        // to flip `t` such that it is `2**256 / t`.\n                        or(mul(sub(p1, gt(r, z)), add(div(sub(0, t), t), 1)), div(sub(z, r), t)),\n                        mul(sub(2, mul(d, inv)), inv) // inverse mod 2**256\n                    )\n                    break\n                }\n                z := div(z, d)\n                break\n            }\n        }\n    }\n\n    /// @dev Calculates `floor(x * y / d)` with full precision.\n    /// Behavior is undefined if `d` is zero or the final result cannot fit in 256 bits.\n    /// Performs the full 512 bit calculation regardless.\n    function fullMulDivUnchecked(uint256 x, uint256 y, uint256 d)\n        internal\n        pure\n        returns (uint256 z)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := mul(x, y)\n            let mm := mulmod(x, y, not(0))\n            let p1 := sub(mm, add(z, lt(mm, z)))\n            let t := and(d, sub(0, d))\n            let r := mulmod(x, y, d)\n            d := div(d, t)\n            let inv := xor(2, mul(3, d))\n            inv := mul(inv, sub(2, mul(d, inv)))\n            inv := mul(inv, sub(2, mul(d, inv)))\n            inv := mul(inv, sub(2, mul(d, inv)))\n            inv := mul(inv, sub(2, mul(d, inv)))\n            inv := mul(inv, sub(2, mul(d, inv)))\n            z := mul(\n                or(mul(sub(p1, gt(r, z)), add(div(sub(0, t), t), 1)), div(sub(z, r), t)),\n                mul(sub(2, mul(d, inv)), inv)\n            )\n        }\n    }\n\n    /// @dev Calculates `floor(x * y / d)` with full precision, rounded up.\n    /// Throws if result overflows a uint256 or when `d` is zero.\n    /// Credit to Uniswap-v3-core under MIT license:\n    /// https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/FullMath.sol\n    function fullMulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {\n        z = fullMulDiv(x, y, d);\n        /// @solidity memory-safe-assembly\n        assembly {\n            if mulmod(x, y, d) {\n                z := add(z, 1)\n                if iszero(z) {\n                    mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.\n                    revert(0x1c, 0x04)\n                }\n            }\n        }\n    }\n\n    /// @dev Calculates `floor(x * y / 2 ** n)` with full precision.\n    /// Throws if result overflows a uint256.\n    /// Credit to Philogy under MIT license:\n    /// https://github.com/SorellaLabs/angstrom/blob/main/contracts/src/libraries/X128MathLib.sol\n    function fullMulDivN(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Temporarily use `z` as `p0` to save gas.\n            z := mul(x, y) // Lower 256 bits of `x * y`. We'll call this `z`.\n            for {} 1 {} {\n                if iszero(or(iszero(x), eq(div(z, x), y))) {\n                    let k := and(n, 0xff) // `n`, cleaned.\n                    let mm := mulmod(x, y, not(0))\n                    let p1 := sub(mm, add(z, lt(mm, z))) // Upper 256 bits of `x * y`.\n                    //         |      p1     |      z     |\n                    // Before: | p1_0 ¦ p1_1 | z_0  ¦ z_1 |\n                    // Final:  |   0  ¦ p1_0 | p1_1 ¦ z_0 |\n                    // Check that final `z` doesn't overflow by checking that p1_0 = 0.\n                    if iszero(shr(k, p1)) {\n                        z := add(shl(sub(256, k), p1), shr(k, z))\n                        break\n                    }\n                    mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.\n                    revert(0x1c, 0x04)\n                }\n                z := shr(and(n, 0xff), z)\n                break\n            }\n        }\n    }\n\n    /// @dev Returns `floor(x * y / d)`.\n    /// Reverts if `x * y` overflows, or `d` is zero.\n    function mulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := mul(x, y)\n            // Equivalent to `require(d != 0 && (y == 0 || x <= type(uint256).max / y))`.\n            if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) {\n                mstore(0x00, 0xad251c27) // `MulDivFailed()`.\n                revert(0x1c, 0x04)\n            }\n            z := div(z, d)\n        }\n    }\n\n    /// @dev Returns `ceil(x * y / d)`.\n    /// Reverts if `x * y` overflows, or `d` is zero.\n    function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := mul(x, y)\n            // Equivalent to `require(d != 0 && (y == 0 || x <= type(uint256).max / y))`.\n            if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) {\n                mstore(0x00, 0xad251c27) // `MulDivFailed()`.\n                revert(0x1c, 0x04)\n            }\n            z := add(iszero(iszero(mod(z, d))), div(z, d))\n        }\n    }\n\n    /// @dev Returns `x`, the modular multiplicative inverse of `a`, such that `(a * x) % n == 1`.\n    function invMod(uint256 a, uint256 n) internal pure returns (uint256 x) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let g := n\n            let r := mod(a, n)\n            for { let y := 1 } 1 {} {\n                let q := div(g, r)\n                let t := g\n                g := r\n                r := sub(t, mul(r, q))\n                let u := x\n                x := y\n                y := sub(u, mul(y, q))\n                if iszero(r) { break }\n            }\n            x := mul(eq(g, 1), add(x, mul(slt(x, 0), n)))\n        }\n    }\n\n    /// @dev Returns `ceil(x / d)`.\n    /// Reverts if `d` is zero.\n    function divUp(uint256 x, uint256 d) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            if iszero(d) {\n                mstore(0x00, 0x65244e4e) // `DivFailed()`.\n                revert(0x1c, 0x04)\n            }\n            z := add(iszero(iszero(mod(x, d))), div(x, d))\n        }\n    }\n\n    /// @dev Returns `max(0, x - y)`. Alias for `saturatingSub`.\n    function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := mul(gt(x, y), sub(x, y))\n        }\n    }\n\n    /// @dev Returns `max(0, x - y)`.\n    function saturatingSub(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := mul(gt(x, y), sub(x, y))\n        }\n    }\n\n    /// @dev Returns `min(2 ** 256 - 1, x + y)`.\n    function saturatingAdd(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := or(sub(0, lt(add(x, y), x)), add(x, y))\n        }\n    }\n\n    /// @dev Returns `min(2 ** 256 - 1, x * y)`.\n    function saturatingMul(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := or(sub(or(iszero(x), eq(div(mul(x, y), x), y)), 1), mul(x, y))\n        }\n    }\n\n    /// @dev Returns `condition ? x : y`, without branching.\n    function ternary(bool condition, uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := xor(x, mul(xor(x, y), iszero(condition)))\n        }\n    }\n\n    /// @dev Returns `condition ? x : y`, without branching.\n    function ternary(bool condition, bytes32 x, bytes32 y) internal pure returns (bytes32 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := xor(x, mul(xor(x, y), iszero(condition)))\n        }\n    }\n\n    /// @dev Returns `condition ? x : y`, without branching.\n    function ternary(bool condition, address x, address y) internal pure returns (address z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := xor(x, mul(xor(x, y), iszero(condition)))\n        }\n    }\n\n    /// @dev Returns `x != 0 ? x : y`, without branching.\n    function coalesce(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := or(x, mul(y, iszero(x)))\n        }\n    }\n\n    /// @dev Returns `x != bytes32(0) ? x : y`, without branching.\n    function coalesce(bytes32 x, bytes32 y) internal pure returns (bytes32 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := or(x, mul(y, iszero(x)))\n        }\n    }\n\n    /// @dev Returns `x != address(0) ? x : y`, without branching.\n    function coalesce(address x, address y) internal pure returns (address z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := or(x, mul(y, iszero(shl(96, x))))\n        }\n    }\n\n    /// @dev Exponentiate `x` to `y` by squaring, denominated in base `b`.\n    /// Reverts if the computation overflows.\n    function rpow(uint256 x, uint256 y, uint256 b) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := mul(b, iszero(y)) // `0 ** 0 = 1`. Otherwise, `0 ** n = 0`.\n            if x {\n                z := xor(b, mul(xor(b, x), and(y, 1))) // `z = isEven(y) ? scale : x`\n                let half := shr(1, b) // Divide `b` by 2.\n                // Divide `y` by 2 every iteration.\n                for { y := shr(1, y) } y { y := shr(1, y) } {\n                    let xx := mul(x, x) // Store x squared.\n                    let xxRound := add(xx, half) // Round to the nearest number.\n                    // Revert if `xx + half` overflowed, or if `x ** 2` overflows.\n                    if or(lt(xxRound, xx), shr(128, x)) {\n                        mstore(0x00, 0x49f7642b) // `RPowOverflow()`.\n                        revert(0x1c, 0x04)\n                    }\n                    x := div(xxRound, b) // Set `x` to scaled `xxRound`.\n                    // If `y` is odd:\n                    if and(y, 1) {\n                        let zx := mul(z, x) // Compute `z * x`.\n                        let zxRound := add(zx, half) // Round to the nearest number.\n                        // If `z * x` overflowed or `zx + half` overflowed:\n                        if or(xor(div(zx, x), z), lt(zxRound, zx)) {\n                            // Revert if `x` is non-zero.\n                            if x {\n                                mstore(0x00, 0x49f7642b) // `RPowOverflow()`.\n                                revert(0x1c, 0x04)\n                            }\n                        }\n                        z := div(zxRound, b) // Return properly scaled `zxRound`.\n                    }\n                }\n            }\n        }\n    }\n\n    /// @dev Returns the square root of `x`, rounded down.\n    function sqrt(uint256 x) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // `floor(sqrt(2**15)) = 181`. `sqrt(2**15) - 181 = 2.84`.\n            z := 181 // The \"correct\" value is 1, but this saves a multiplication later.\n\n            // This segment is to get a reasonable initial estimate for the Babylonian method. With a bad\n            // start, the correct # of bits increases ~linearly each iteration instead of ~quadratically.\n\n            // Let `y = x / 2**r`. We check `y >= 2**(k + 8)`\n            // but shift right by `k` bits to ensure that if `x >= 256`, then `y >= 256`.\n            let r := shl(7, lt(0xffffffffffffffffffffffffffffffffff, x))\n            r := or(r, shl(6, lt(0xffffffffffffffffff, shr(r, x))))\n            r := or(r, shl(5, lt(0xffffffffff, shr(r, x))))\n            r := or(r, shl(4, lt(0xffffff, shr(r, x))))\n            z := shl(shr(1, r), z)\n\n            // Goal was to get `z*z*y` within a small factor of `x`. More iterations could\n            // get y in a tighter range. Currently, we will have y in `[256, 256*(2**16))`.\n            // We ensured `y >= 256` so that the relative difference between `y` and `y+1` is small.\n            // That's not possible if `x < 256` but we can just verify those cases exhaustively.\n\n            // Now, `z*z*y <= x < z*z*(y+1)`, and `y <= 2**(16+8)`, and either `y >= 256`, or `x < 256`.\n            // Correctness can be checked exhaustively for `x < 256`, so we assume `y >= 256`.\n            // Then `z*sqrt(y)` is within `sqrt(257)/sqrt(256)` of `sqrt(x)`, or about 20bps.\n\n            // For `s` in the range `[1/256, 256]`, the estimate `f(s) = (181/1024) * (s+1)`\n            // is in the range `(1/2.84 * sqrt(s), 2.84 * sqrt(s))`,\n            // with largest error when `s = 1` and when `s = 256` or `1/256`.\n\n            // Since `y` is in `[256, 256*(2**16))`, let `a = y/65536`, so that `a` is in `[1/256, 256)`.\n            // Then we can estimate `sqrt(y)` using\n            // `sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2**18`.\n\n            // There is no overflow risk here since `y < 2**136` after the first branch above.\n            z := shr(18, mul(z, add(shr(r, x), 65536))) // A `mul()` is saved from starting `z` at 181.\n\n            // Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough.\n            z := shr(1, add(z, div(x, z)))\n            z := shr(1, add(z, div(x, z)))\n            z := shr(1, add(z, div(x, z)))\n            z := shr(1, add(z, div(x, z)))\n            z := shr(1, add(z, div(x, z)))\n            z := shr(1, add(z, div(x, z)))\n            z := shr(1, add(z, div(x, z)))\n\n            // If `x+1` is a perfect square, the Babylonian method cycles between\n            // `floor(sqrt(x))` and `ceil(sqrt(x))`. This statement ensures we return floor.\n            // See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division\n            z := sub(z, lt(div(x, z), z))\n        }\n    }\n\n    /// @dev Returns the cube root of `x`, rounded down.\n    /// Credit to bout3fiddy and pcaversaccio under AGPLv3 license:\n    /// https://github.com/pcaversaccio/snekmate/blob/main/src/snekmate/utils/math.vy\n    /// Formally verified by xuwinnie:\n    /// https://github.com/vectorized/solady/blob/main/audits/xuwinnie-solady-cbrt-proof.pdf\n    function cbrt(uint256 x) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))\n            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))\n            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))\n            r := or(r, shl(4, lt(0xffff, shr(r, x))))\n            r := or(r, shl(3, lt(0xff, shr(r, x))))\n            // Makeshift lookup table to nudge the approximate log2 result.\n            z := div(shl(div(r, 3), shl(lt(0xf, shr(r, x)), 0xf)), xor(7, mod(r, 3)))\n            // Newton-Raphson's.\n            z := div(add(add(div(x, mul(z, z)), z), z), 3)\n            z := div(add(add(div(x, mul(z, z)), z), z), 3)\n            z := div(add(add(div(x, mul(z, z)), z), z), 3)\n            z := div(add(add(div(x, mul(z, z)), z), z), 3)\n            z := div(add(add(div(x, mul(z, z)), z), z), 3)\n            z := div(add(add(div(x, mul(z, z)), z), z), 3)\n            z := div(add(add(div(x, mul(z, z)), z), z), 3)\n            // Round down.\n            z := sub(z, lt(div(x, mul(z, z)), z))\n        }\n    }\n\n    /// @dev Returns the square root of `x`, denominated in `WAD`, rounded down.\n    function sqrtWad(uint256 x) internal pure returns (uint256 z) {\n        unchecked {\n            if (x <= type(uint256).max / 10 ** 18) return sqrt(x * 10 ** 18);\n            z = (1 + sqrt(x)) * 10 ** 9;\n            z = (fullMulDivUnchecked(x, 10 ** 18, z) + z) >> 1;\n        }\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := sub(z, gt(999999999999999999, sub(mulmod(z, z, x), 1))) // Round down.\n        }\n    }\n\n    /// @dev Returns the cube root of `x`, denominated in `WAD`, rounded down.\n    /// Formally verified by xuwinnie:\n    /// https://github.com/vectorized/solady/blob/main/audits/xuwinnie-solady-cbrt-proof.pdf\n    function cbrtWad(uint256 x) internal pure returns (uint256 z) {\n        unchecked {\n            if (x <= type(uint256).max / 10 ** 36) return cbrt(x * 10 ** 36);\n            z = (1 + cbrt(x)) * 10 ** 12;\n            z = (fullMulDivUnchecked(x, 10 ** 36, z * z) + z + z) / 3;\n        }\n        /// @solidity memory-safe-assembly\n        assembly {\n            let p := x\n            for {} 1 {} {\n                if iszero(shr(229, p)) {\n                    if iszero(shr(199, p)) {\n                        p := mul(p, 100000000000000000) // 10 ** 17.\n                        break\n                    }\n                    p := mul(p, 100000000) // 10 ** 8.\n                    break\n                }\n                if iszero(shr(249, p)) { p := mul(p, 100) }\n                break\n            }\n            let t := mulmod(mul(z, z), z, p)\n            z := sub(z, gt(lt(t, shr(1, p)), iszero(t))) // Round down.\n        }\n    }\n\n    /// @dev Returns `sqrt(x * y)`. Also called the geometric mean.\n    function mulSqrt(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        if (x == y) return x;\n        uint256 p = rawMul(x, y);\n        if (y == rawDiv(p, x)) return sqrt(p);\n        for (z = saturatingMul(rawAdd(sqrt(x), 1), rawAdd(sqrt(y), 1));; z = avg(z, p)) {\n            if ((p = fullMulDivUnchecked(x, y, z)) >= z) break;\n        }\n    }\n\n    /// @dev Returns the factorial of `x`.\n    function factorial(uint256 x) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := 1\n            if iszero(lt(x, 58)) {\n                mstore(0x00, 0xaba0f2a2) // `FactorialOverflow()`.\n                revert(0x1c, 0x04)\n            }\n            for {} x { x := sub(x, 1) } { z := mul(z, x) }\n        }\n    }\n\n    /// @dev Returns the log2 of `x`.\n    /// Equivalent to computing the index of the most significant bit (MSB) of `x`.\n    /// Returns 0 if `x` is zero.\n    function log2(uint256 x) internal pure returns (uint256 r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))\n            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))\n            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))\n            r := or(r, shl(4, lt(0xffff, shr(r, x))))\n            r := or(r, shl(3, lt(0xff, shr(r, x))))\n            // forgefmt: disable-next-item\n            r := or(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),\n                0x0706060506020504060203020504030106050205030304010505030400000000))\n        }\n    }\n\n    /// @dev Returns the log2 of `x`, rounded up.\n    /// Returns 0 if `x` is zero.\n    function log2Up(uint256 x) internal pure returns (uint256 r) {\n        r = log2(x);\n        /// @solidity memory-safe-assembly\n        assembly {\n            r := add(r, lt(shl(r, 1), x))\n        }\n    }\n\n    /// @dev Returns the log10 of `x`.\n    /// Returns 0 if `x` is zero.\n    function log10(uint256 x) internal pure returns (uint256 r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            if iszero(lt(x, 100000000000000000000000000000000000000)) {\n                x := div(x, 100000000000000000000000000000000000000)\n                r := 38\n            }\n            if iszero(lt(x, 100000000000000000000)) {\n                x := div(x, 100000000000000000000)\n                r := add(r, 20)\n            }\n            if iszero(lt(x, 10000000000)) {\n                x := div(x, 10000000000)\n                r := add(r, 10)\n            }\n            if iszero(lt(x, 100000)) {\n                x := div(x, 100000)\n                r := add(r, 5)\n            }\n            r := add(r, add(gt(x, 9), add(gt(x, 99), add(gt(x, 999), gt(x, 9999)))))\n        }\n    }\n\n    /// @dev Returns the log10 of `x`, rounded up.\n    /// Returns 0 if `x` is zero.\n    function log10Up(uint256 x) internal pure returns (uint256 r) {\n        r = log10(x);\n        /// @solidity memory-safe-assembly\n        assembly {\n            r := add(r, lt(exp(10, r), x))\n        }\n    }\n\n    /// @dev Returns the log256 of `x`.\n    /// Returns 0 if `x` is zero.\n    function log256(uint256 x) internal pure returns (uint256 r) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))\n            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))\n            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))\n            r := or(r, shl(4, lt(0xffff, shr(r, x))))\n            r := or(shr(3, r), lt(0xff, shr(r, x)))\n        }\n    }\n\n    /// @dev Returns the log256 of `x`, rounded up.\n    /// Returns 0 if `x` is zero.\n    function log256Up(uint256 x) internal pure returns (uint256 r) {\n        r = log256(x);\n        /// @solidity memory-safe-assembly\n        assembly {\n            r := add(r, lt(shl(shl(3, r), 1), x))\n        }\n    }\n\n    /// @dev Returns the scientific notation format `mantissa * 10 ** exponent` of `x`.\n    /// Useful for compressing prices (e.g. using 25 bit mantissa and 7 bit exponent).\n    function sci(uint256 x) internal pure returns (uint256 mantissa, uint256 exponent) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            mantissa := x\n            if mantissa {\n                if iszero(mod(mantissa, 1000000000000000000000000000000000)) {\n                    mantissa := div(mantissa, 1000000000000000000000000000000000)\n                    exponent := 33\n                }\n                if iszero(mod(mantissa, 10000000000000000000)) {\n                    mantissa := div(mantissa, 10000000000000000000)\n                    exponent := add(exponent, 19)\n                }\n                if iszero(mod(mantissa, 1000000000000)) {\n                    mantissa := div(mantissa, 1000000000000)\n                    exponent := add(exponent, 12)\n                }\n                if iszero(mod(mantissa, 1000000)) {\n                    mantissa := div(mantissa, 1000000)\n                    exponent := add(exponent, 6)\n                }\n                if iszero(mod(mantissa, 10000)) {\n                    mantissa := div(mantissa, 10000)\n                    exponent := add(exponent, 4)\n                }\n                if iszero(mod(mantissa, 100)) {\n                    mantissa := div(mantissa, 100)\n                    exponent := add(exponent, 2)\n                }\n                if iszero(mod(mantissa, 10)) {\n                    mantissa := div(mantissa, 10)\n                    exponent := add(exponent, 1)\n                }\n            }\n        }\n    }\n\n    /// @dev Convenience function for packing `x` into a smaller number using `sci`.\n    /// The `mantissa` will be in bits [7..255] (the upper 249 bits).\n    /// The `exponent` will be in bits [0..6] (the lower 7 bits).\n    /// Use `SafeCastLib` to safely ensure that the `packed` number is small\n    /// enough to fit in the desired unsigned integer type:\n    /// ```\n    ///     uint32 packed = SafeCastLib.toUint32(FixedPointMathLib.packSci(777 ether));\n    /// ```\n    function packSci(uint256 x) internal pure returns (uint256 packed) {\n        (x, packed) = sci(x); // Reuse for `mantissa` and `exponent`.\n        /// @solidity memory-safe-assembly\n        assembly {\n            if shr(249, x) {\n                mstore(0x00, 0xce30380c) // `MantissaOverflow()`.\n                revert(0x1c, 0x04)\n            }\n            packed := or(shl(7, x), packed)\n        }\n    }\n\n    /// @dev Convenience function for unpacking a packed number from `packSci`.\n    function unpackSci(uint256 packed) internal pure returns (uint256 unpacked) {\n        unchecked {\n            unpacked = (packed >> 7) * 10 ** (packed & 0x7f);\n        }\n    }\n\n    /// @dev Returns the average of `x` and `y`. Rounds towards zero.\n    function avg(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        unchecked {\n            z = (x & y) + ((x ^ y) >> 1);\n        }\n    }\n\n    /// @dev Returns the average of `x` and `y`. Rounds towards negative infinity.\n    function avg(int256 x, int256 y) internal pure returns (int256 z) {\n        unchecked {\n            z = (x >> 1) + (y >> 1) + (x & y & 1);\n        }\n    }\n\n    /// @dev Returns the absolute value of `x`.\n    function abs(int256 x) internal pure returns (uint256 z) {\n        unchecked {\n            z = (uint256(x) + uint256(x >> 255)) ^ uint256(x >> 255);\n        }\n    }\n\n    /// @dev Returns the absolute distance between `x` and `y`.\n    function dist(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := add(xor(sub(0, gt(x, y)), sub(y, x)), gt(x, y))\n        }\n    }\n\n    /// @dev Returns the absolute distance between `x` and `y`.\n    function dist(int256 x, int256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := add(xor(sub(0, sgt(x, y)), sub(y, x)), sgt(x, y))\n        }\n    }\n\n    /// @dev Returns the minimum of `x` and `y`.\n    function min(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := xor(x, mul(xor(x, y), lt(y, x)))\n        }\n    }\n\n    /// @dev Returns the minimum of `x` and `y`.\n    function min(int256 x, int256 y) internal pure returns (int256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := xor(x, mul(xor(x, y), slt(y, x)))\n        }\n    }\n\n    /// @dev Returns the maximum of `x` and `y`.\n    function max(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := xor(x, mul(xor(x, y), gt(y, x)))\n        }\n    }\n\n    /// @dev Returns the maximum of `x` and `y`.\n    function max(int256 x, int256 y) internal pure returns (int256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := xor(x, mul(xor(x, y), sgt(y, x)))\n        }\n    }\n\n    /// @dev Returns `x`, bounded to `minValue` and `maxValue`.\n    function clamp(uint256 x, uint256 minValue, uint256 maxValue)\n        internal\n        pure\n        returns (uint256 z)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := xor(x, mul(xor(x, minValue), gt(minValue, x)))\n            z := xor(z, mul(xor(z, maxValue), lt(maxValue, z)))\n        }\n    }\n\n    /// @dev Returns `x`, bounded to `minValue` and `maxValue`.\n    function clamp(int256 x, int256 minValue, int256 maxValue) internal pure returns (int256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := xor(x, mul(xor(x, minValue), sgt(minValue, x)))\n            z := xor(z, mul(xor(z, maxValue), slt(maxValue, z)))\n        }\n    }\n\n    /// @dev Returns greatest common divisor of `x` and `y`.\n    function gcd(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            for { z := x } y {} {\n                let t := y\n                y := mod(z, y)\n                z := t\n            }\n        }\n    }\n\n    /// @dev Returns `a + (b - a) * (t - begin) / (end - begin)`,\n    /// with `t` clamped between `begin` and `end` (inclusive).\n    /// Agnostic to the order of (`a`, `b`) and (`end`, `begin`).\n    /// If `begins == end`, returns `t <= begin ? a : b`.\n    function lerp(uint256 a, uint256 b, uint256 t, uint256 begin, uint256 end)\n        internal\n        pure\n        returns (uint256)\n    {\n        if (begin > end) (t, begin, end) = (~t, ~begin, ~end);\n        if (t <= begin) return a;\n        if (t >= end) return b;\n        unchecked {\n            if (b >= a) return a + fullMulDiv(b - a, t - begin, end - begin);\n            return a - fullMulDiv(a - b, t - begin, end - begin);\n        }\n    }\n\n    /// @dev Returns `a + (b - a) * (t - begin) / (end - begin)`.\n    /// with `t` clamped between `begin` and `end` (inclusive).\n    /// Agnostic to the order of (`a`, `b`) and (`end`, `begin`).\n    /// If `begins == end`, returns `t <= begin ? a : b`.\n    function lerp(int256 a, int256 b, int256 t, int256 begin, int256 end)\n        internal\n        pure\n        returns (int256)\n    {\n        if (begin > end) (t, begin, end) = (~t, ~begin, ~end);\n        if (t <= begin) return a;\n        if (t >= end) return b;\n        // forgefmt: disable-next-item\n        unchecked {\n            if (b >= a) return int256(uint256(a) + fullMulDiv(uint256(b - a),\n                uint256(t - begin), uint256(end - begin)));\n            return int256(uint256(a) - fullMulDiv(uint256(a - b),\n                uint256(t - begin), uint256(end - begin)));\n        }\n    }\n\n    /// @dev Returns if `x` is an even number. Some people may need this.\n    function isEven(uint256 x) internal pure returns (bool) {\n        return x & uint256(1) == uint256(0);\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                   RAW NUMBER OPERATIONS                    */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Returns `x + y`, without checking for overflow.\n    function rawAdd(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        unchecked {\n            z = x + y;\n        }\n    }\n\n    /// @dev Returns `x + y`, without checking for overflow.\n    function rawAdd(int256 x, int256 y) internal pure returns (int256 z) {\n        unchecked {\n            z = x + y;\n        }\n    }\n\n    /// @dev Returns `x - y`, without checking for underflow.\n    function rawSub(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        unchecked {\n            z = x - y;\n        }\n    }\n\n    /// @dev Returns `x - y`, without checking for underflow.\n    function rawSub(int256 x, int256 y) internal pure returns (int256 z) {\n        unchecked {\n            z = x - y;\n        }\n    }\n\n    /// @dev Returns `x * y`, without checking for overflow.\n    function rawMul(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        unchecked {\n            z = x * y;\n        }\n    }\n\n    /// @dev Returns `x * y`, without checking for overflow.\n    function rawMul(int256 x, int256 y) internal pure returns (int256 z) {\n        unchecked {\n            z = x * y;\n        }\n    }\n\n    /// @dev Returns `x / y`, returning 0 if `y` is zero.\n    function rawDiv(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := div(x, y)\n        }\n    }\n\n    /// @dev Returns `x / y`, returning 0 if `y` is zero.\n    function rawSDiv(int256 x, int256 y) internal pure returns (int256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := sdiv(x, y)\n        }\n    }\n\n    /// @dev Returns `x % y`, returning 0 if `y` is zero.\n    function rawMod(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := mod(x, y)\n        }\n    }\n\n    /// @dev Returns `x % y`, returning 0 if `y` is zero.\n    function rawSMod(int256 x, int256 y) internal pure returns (int256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := smod(x, y)\n        }\n    }\n\n    /// @dev Returns `(x + y) % d`, return 0 if `d` if zero.\n    function rawAddMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := addmod(x, y, d)\n        }\n    }\n\n    /// @dev Returns `(x * y) % d`, return 0 if `d` if zero.\n    function rawMulMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            z := mulmod(x, y, d)\n        }\n    }\n}\n"},{"file_path":"lib/solady/src/utils/SafeTransferLib.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.4;\n\n/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.\n/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol)\n/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)\n/// @author Permit2 operations from (https://github.com/Uniswap/permit2/blob/main/src/libraries/Permit2Lib.sol)\n///\n/// @dev Note:\n/// - For ETH transfers, please use `forceSafeTransferETH` for DoS protection.\nlibrary SafeTransferLib {\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                       CUSTOM ERRORS                        */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev The ETH transfer has failed.\n    error ETHTransferFailed();\n\n    /// @dev The ERC20 `transferFrom` has failed.\n    error TransferFromFailed();\n\n    /// @dev The ERC20 `transfer` has failed.\n    error TransferFailed();\n\n    /// @dev The ERC20 `approve` has failed.\n    error ApproveFailed();\n\n    /// @dev The ERC20 `totalSupply` query has failed.\n    error TotalSupplyQueryFailed();\n\n    /// @dev The Permit2 operation has failed.\n    error Permit2Failed();\n\n    /// @dev The Permit2 amount must be less than `2**160 - 1`.\n    error Permit2AmountOverflow();\n\n    /// @dev The Permit2 approve operation has failed.\n    error Permit2ApproveFailed();\n\n    /// @dev The Permit2 lockdown operation has failed.\n    error Permit2LockdownFailed();\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                         CONSTANTS                          */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Suggested gas stipend for contract receiving ETH that disallows any storage writes.\n    uint256 internal constant GAS_STIPEND_NO_STORAGE_WRITES = 2300;\n\n    /// @dev Suggested gas stipend for contract receiving ETH to perform a few\n    /// storage reads and writes, but low enough to prevent griefing.\n    uint256 internal constant GAS_STIPEND_NO_GRIEF = 100000;\n\n    /// @dev The unique EIP-712 domain separator for the DAI token contract.\n    bytes32 internal constant DAI_DOMAIN_SEPARATOR =\n        0xdbb8cf42e1ecb028be3f3dbc922e1d878b963f411dc388ced501601c60f7c6f7;\n\n    /// @dev The address for the WETH9 contract on Ethereum mainnet.\n    address internal constant WETH9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;\n\n    /// @dev The canonical Permit2 address.\n    /// [Github](https://github.com/Uniswap/permit2)\n    /// [Etherscan](https://etherscan.io/address/0x000000000022D473030F116dDEE9F6B43aC78BA3)\n    address internal constant PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;\n\n    /// @dev The canonical address of the `SELFDESTRUCT` ETH mover.\n    /// See: https://gist.github.com/Vectorized/1cb8ad4cf393b1378e08f23f79bd99fa\n    /// [Etherscan](https://etherscan.io/address/0x00000000000073c48c8055bD43D1A53799176f0D)\n    address internal constant ETH_MOVER = 0x00000000000073c48c8055bD43D1A53799176f0D;\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                       ETH OPERATIONS                       */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    // If the ETH transfer MUST succeed with a reasonable gas budget, use the force variants.\n    //\n    // The regular variants:\n    // - Forwards all remaining gas to the target.\n    // - Reverts if the target reverts.\n    // - Reverts if the current contract has insufficient balance.\n    //\n    // The force variants:\n    // - Forwards with an optional gas stipend\n    //   (defaults to `GAS_STIPEND_NO_GRIEF`, which is sufficient for most cases).\n    // - If the target reverts, or if the gas stipend is exhausted,\n    //   creates a temporary contract to force send the ETH via `SELFDESTRUCT`.\n    //   Future compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758.\n    // - Reverts if the current contract has insufficient balance.\n    //\n    // The try variants:\n    // - Forwards with a mandatory gas stipend.\n    // - Instead of reverting, returns whether the transfer succeeded.\n\n    /// @dev Sends `amount` (in wei) ETH to `to`.\n    function safeTransferETH(address to, uint256 amount) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            if iszero(call(gas(), to, amount, codesize(), 0x00, codesize(), 0x00)) {\n                mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.\n                revert(0x1c, 0x04)\n            }\n        }\n    }\n\n    /// @dev Sends all the ETH in the current contract to `to`.\n    function safeTransferAllETH(address to) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Transfer all the ETH and check if it succeeded or not.\n            if iszero(call(gas(), to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {\n                mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.\n                revert(0x1c, 0x04)\n            }\n        }\n    }\n\n    /// @dev Force sends `amount` (in wei) ETH to `to`, with a `gasStipend`.\n    function forceSafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            if lt(selfbalance(), amount) {\n                mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.\n                revert(0x1c, 0x04)\n            }\n            if iszero(call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)) {\n                mstore(0x00, to) // Store the address in scratch space.\n                mstore8(0x0b, 0x73) // Opcode `PUSH20`.\n                mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.\n                if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.\n            }\n        }\n    }\n\n    /// @dev Force sends all the ETH in the current contract to `to`, with a `gasStipend`.\n    function forceSafeTransferAllETH(address to, uint256 gasStipend) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            if iszero(call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {\n                mstore(0x00, to) // Store the address in scratch space.\n                mstore8(0x0b, 0x73) // Opcode `PUSH20`.\n                mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.\n                if iszero(create(selfbalance(), 0x0b, 0x16)) {\n                    revert(codesize(), codesize())\n                } // For gas estimation.\n            }\n        }\n    }\n\n    /// @dev Force sends `amount` (in wei) ETH to `to`, with `GAS_STIPEND_NO_GRIEF`.\n    function forceSafeTransferETH(address to, uint256 amount) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            if lt(selfbalance(), amount) {\n                mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.\n                revert(0x1c, 0x04)\n            }\n            if iszero(call(GAS_STIPEND_NO_GRIEF, to, amount, codesize(), 0x00, codesize(), 0x00)) {\n                mstore(0x00, to) // Store the address in scratch space.\n                mstore8(0x0b, 0x73) // Opcode `PUSH20`.\n                mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.\n                if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.\n            }\n        }\n    }\n\n    /// @dev Force sends all the ETH in the current contract to `to`, with `GAS_STIPEND_NO_GRIEF`.\n    function forceSafeTransferAllETH(address to) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n\n            // forgefmt: disable-next-item\n            if iszero(call(GAS_STIPEND_NO_GRIEF, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {\n                mstore(0x00, to) // Store the address in scratch space.\n                mstore8(0x0b, 0x73) // Opcode `PUSH20`.\n                mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.\n                if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.\n            }\n        }\n    }\n\n    /// @dev Sends `amount` (in wei) ETH to `to`, with a `gasStipend`.\n    function trySafeTransferETH(address to, uint256 amount, uint256 gasStipend)\n        internal\n        returns (bool success)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            success := call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)\n        }\n    }\n\n    /// @dev Sends all the ETH in the current contract to `to`, with a `gasStipend`.\n    function trySafeTransferAllETH(address to, uint256 gasStipend) internal returns (bool success) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            success := call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)\n        }\n    }\n\n    /// @dev Force transfers ETH to `to`, without triggering the fallback (if any).\n    /// This method attempts to use a separate contract to send via `SELFDESTRUCT`,\n    /// and upon failure, deploys a minimal vault to accrue the ETH.\n    function safeMoveETH(address to, uint256 amount) internal returns (address vault) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            to := shr(96, shl(96, to)) // Clean upper 96 bits.\n            for { let mover := ETH_MOVER } iszero(eq(to, address())) {} {\n                let selfBalanceBefore := selfbalance()\n                if or(lt(selfBalanceBefore, amount), eq(to, mover)) {\n                    mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.\n                    revert(0x1c, 0x04)\n                }\n                if extcodesize(mover) {\n                    let balanceBefore := balance(to) // Check via delta, in case `SELFDESTRUCT` is bricked.\n                    mstore(0x00, to)\n                    pop(call(gas(), mover, amount, 0x00, 0x20, codesize(), 0x00))\n                    // If `address(to).balance >= amount + balanceBefore`, skip vault workflow.\n                    if iszero(lt(balance(to), add(amount, balanceBefore))) { break }\n                    // Just in case `SELFDESTRUCT` is changed to not revert and do nothing.\n                    if lt(selfBalanceBefore, selfbalance()) { invalid() }\n                }\n                let m := mload(0x40)\n                // If the mover is missing or bricked, deploy a minimal vault\n                // that withdraws all ETH to `to` when being called only by `to`.\n                // forgefmt: disable-next-item\n                mstore(add(m, 0x20), 0x33146025575b600160005260206000f35b3d3d3d3d47335af1601a5760003dfd)\n                mstore(m, or(to, shl(160, 0x6035600b3d3960353df3fe73)))\n                // Compute and store the bytecode hash.\n                mstore8(0x00, 0xff) // Write the prefix.\n                mstore(0x35, keccak256(m, 0x40))\n                mstore(0x01, shl(96, address())) // Deployer.\n                mstore(0x15, 0) // Salt.\n                vault := keccak256(0x00, 0x55)\n                pop(call(gas(), vault, amount, codesize(), 0x00, codesize(), 0x00))\n                // The vault returns a single word on success. Failure reverts with empty data.\n                if iszero(returndatasize()) {\n                    if iszero(create2(0, m, 0x40, 0)) { revert(codesize(), codesize()) } // For gas estimation.\n                }\n                mstore(0x40, m) // Restore the free memory pointer.\n                break\n            }\n        }\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                      ERC20 OPERATIONS                      */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Sends `amount` of ERC20 `token` from `from` to `to`.\n    /// Reverts upon failure.\n    ///\n    /// The `from` account must have at least `amount` approved for\n    /// the current contract to manage.\n    function safeTransferFrom(address token, address from, address to, uint256 amount) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let m := mload(0x40) // Cache the free memory pointer.\n            mstore(0x60, amount) // Store the `amount` argument.\n            mstore(0x40, to) // Store the `to` argument.\n            mstore(0x2c, shl(96, from)) // Store the `from` argument.\n            mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`.\n            let success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)\n            if iszero(and(eq(mload(0x00), 1), success)) {\n                if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {\n                    mstore(0x00, 0x7939f424) // `TransferFromFailed()`.\n                    revert(0x1c, 0x04)\n                }\n            }\n            mstore(0x60, 0) // Restore the zero slot to zero.\n            mstore(0x40, m) // Restore the free memory pointer.\n        }\n    }\n\n    /// @dev Sends `amount` of ERC20 `token` from `from` to `to`.\n    ///\n    /// The `from` account must have at least `amount` approved for the current contract to manage.\n    function trySafeTransferFrom(address token, address from, address to, uint256 amount)\n        internal\n        returns (bool success)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let m := mload(0x40) // Cache the free memory pointer.\n            mstore(0x60, amount) // Store the `amount` argument.\n            mstore(0x40, to) // Store the `to` argument.\n            mstore(0x2c, shl(96, from)) // Store the `from` argument.\n            mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`.\n            success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)\n            if iszero(and(eq(mload(0x00), 1), success)) {\n                success := lt(or(iszero(extcodesize(token)), returndatasize()), success)\n            }\n            mstore(0x60, 0) // Restore the zero slot to zero.\n            mstore(0x40, m) // Restore the free memory pointer.\n        }\n    }\n\n    /// @dev Sends all of ERC20 `token` from `from` to `to`.\n    /// Reverts upon failure.\n    ///\n    /// The `from` account must have their entire balance approved for the current contract to manage.\n    function safeTransferAllFrom(address token, address from, address to)\n        internal\n        returns (uint256 amount)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let m := mload(0x40) // Cache the free memory pointer.\n            mstore(0x40, to) // Store the `to` argument.\n            mstore(0x2c, shl(96, from)) // Store the `from` argument.\n            mstore(0x0c, 0x70a08231000000000000000000000000) // `balanceOf(address)`.\n            // Read the balance, reverting upon failure.\n            if iszero(\n                and( // The arguments of `and` are evaluated from right to left.\n                    gt(returndatasize(), 0x1f), // At least 32 bytes returned.\n                    staticcall(gas(), token, 0x1c, 0x24, 0x60, 0x20)\n                )\n            ) {\n                mstore(0x00, 0x7939f424) // `TransferFromFailed()`.\n                revert(0x1c, 0x04)\n            }\n            mstore(0x00, 0x23b872dd) // `transferFrom(address,address,uint256)`.\n            amount := mload(0x60) // The `amount` is already at 0x60. We'll need to return it.\n            // Perform the transfer, reverting upon failure.\n            let success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)\n            if iszero(and(eq(mload(0x00), 1), success)) {\n                if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {\n                    mstore(0x00, 0x7939f424) // `TransferFromFailed()`.\n                    revert(0x1c, 0x04)\n                }\n            }\n            mstore(0x60, 0) // Restore the zero slot to zero.\n            mstore(0x40, m) // Restore the free memory pointer.\n        }\n    }\n\n    /// @dev Sends `amount` of ERC20 `token` from the current contract to `to`.\n    /// Reverts upon failure.\n    function safeTransfer(address token, address to, uint256 amount) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(0x14, to) // Store the `to` argument.\n            mstore(0x34, amount) // Store the `amount` argument.\n            mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.\n            // Perform the transfer, reverting upon failure.\n            let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)\n            if iszero(and(eq(mload(0x00), 1), success)) {\n                if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {\n                    mstore(0x00, 0x90b8ec18) // `TransferFailed()`.\n                    revert(0x1c, 0x04)\n                }\n            }\n            mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.\n        }\n    }\n\n    /// @dev Sends all of ERC20 `token` from the current contract to `to`.\n    /// Reverts upon failure.\n    function safeTransferAll(address token, address to) internal returns (uint256 amount) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(0x00, 0x70a08231) // Store the function selector of `balanceOf(address)`.\n            mstore(0x20, address()) // Store the address of the current contract.\n            // Read the balance, reverting upon failure.\n            if iszero(\n                and( // The arguments of `and` are evaluated from right to left.\n                    gt(returndatasize(), 0x1f), // At least 32 bytes returned.\n                    staticcall(gas(), token, 0x1c, 0x24, 0x34, 0x20)\n                )\n            ) {\n                mstore(0x00, 0x90b8ec18) // `TransferFailed()`.\n                revert(0x1c, 0x04)\n            }\n            mstore(0x14, to) // Store the `to` argument.\n            amount := mload(0x34) // The `amount` is already at 0x34. We'll need to return it.\n            mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.\n            // Perform the transfer, reverting upon failure.\n            let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)\n            if iszero(and(eq(mload(0x00), 1), success)) {\n                if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {\n                    mstore(0x00, 0x90b8ec18) // `TransferFailed()`.\n                    revert(0x1c, 0x04)\n                }\n            }\n            mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.\n        }\n    }\n\n    /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.\n    /// Reverts upon failure.\n    function safeApprove(address token, address to, uint256 amount) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(0x14, to) // Store the `to` argument.\n            mstore(0x34, amount) // Store the `amount` argument.\n            mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.\n            let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)\n            if iszero(and(eq(mload(0x00), 1), success)) {\n                if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {\n                    mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.\n                    revert(0x1c, 0x04)\n                }\n            }\n            mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.\n        }\n    }\n\n    /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.\n    /// If the initial attempt to approve fails, attempts to reset the approved amount to zero,\n    /// then retries the approval again (some tokens, e.g. USDT, requires this).\n    /// Reverts upon failure.\n    function safeApproveWithRetry(address token, address to, uint256 amount) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(0x14, to) // Store the `to` argument.\n            mstore(0x34, amount) // Store the `amount` argument.\n            mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.\n            // Perform the approval, retrying upon failure.\n            let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)\n            if iszero(and(eq(mload(0x00), 1), success)) {\n                if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {\n                    mstore(0x34, 0) // Store 0 for the `amount`.\n                    mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.\n                    pop(call(gas(), token, 0, 0x10, 0x44, codesize(), 0x00)) // Reset the approval.\n                    mstore(0x34, amount) // Store back the original `amount`.\n                    // Retry the approval, reverting upon failure.\n                    success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)\n                    if iszero(and(eq(mload(0x00), 1), success)) {\n                        // Check the `extcodesize` again just in case the token selfdestructs lol.\n                        if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {\n                            mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.\n                            revert(0x1c, 0x04)\n                        }\n                    }\n                }\n            }\n            mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.\n        }\n    }\n\n    /// @dev Returns the amount of ERC20 `token` owned by `account`.\n    /// Returns zero if the `token` does not exist.\n    function balanceOf(address token, address account) internal view returns (uint256 amount) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(0x14, account) // Store the `account` argument.\n            mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`.\n            amount := mul( // The arguments of `mul` are evaluated from right to left.\n                mload(0x20),\n                and( // The arguments of `and` are evaluated from right to left.\n                    gt(returndatasize(), 0x1f), // At least 32 bytes returned.\n                    staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20)\n                )\n            )\n        }\n    }\n\n    /// @dev Performs a `token.balanceOf(account)` check.\n    /// `implemented` denotes whether the `token` does not implement `balanceOf`.\n    /// `amount` is zero if the `token` does not implement `balanceOf`.\n    function checkBalanceOf(address token, address account)\n        internal\n        view\n        returns (bool implemented, uint256 amount)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(0x14, account) // Store the `account` argument.\n            mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`.\n            implemented := and( // The arguments of `and` are evaluated from right to left.\n                gt(returndatasize(), 0x1f), // At least 32 bytes returned.\n                staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20)\n            )\n            amount := mul(mload(0x20), implemented)\n        }\n    }\n\n    /// @dev Returns the total supply of the `token`.\n    /// Reverts if the token does not exist or does not implement `totalSupply()`.\n    function totalSupply(address token) internal view returns (uint256 result) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            mstore(0x00, 0x18160ddd) // `totalSupply()`.\n            if iszero(\n                and(gt(returndatasize(), 0x1f), staticcall(gas(), token, 0x1c, 0x04, 0x00, 0x20))\n            ) {\n                mstore(0x00, 0x54cd9435) // `TotalSupplyQueryFailed()`.\n                revert(0x1c, 0x04)\n            }\n            result := mload(0x00)\n        }\n    }\n\n    /// @dev Sends `amount` of ERC20 `token` from `from` to `to`.\n    /// If the initial attempt fails, try to use Permit2 to transfer the token.\n    /// Reverts upon failure.\n    ///\n    /// The `from` account must have at least `amount` approved for the current contract to manage.\n    function safeTransferFrom2(address token, address from, address to, uint256 amount) internal {\n        if (!trySafeTransferFrom(token, from, to, amount)) {\n            permit2TransferFrom(token, from, to, amount);\n        }\n    }\n\n    /// @dev Sends `amount` of ERC20 `token` from `from` to `to` via Permit2.\n    /// Reverts upon failure.\n    function permit2TransferFrom(address token, address from, address to, uint256 amount) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let m := mload(0x40)\n            mstore(add(m, 0x74), shr(96, shl(96, token)))\n            mstore(add(m, 0x54), amount)\n            mstore(add(m, 0x34), to)\n            mstore(add(m, 0x20), shl(96, from))\n            // `transferFrom(address,address,uint160,address)`.\n            mstore(m, 0x36c78516000000000000000000000000)\n            let p := PERMIT2\n            let exists := eq(chainid(), 1)\n            if iszero(exists) { exists := iszero(iszero(extcodesize(p))) }\n            if iszero(\n                and(\n                    call(gas(), p, 0, add(m, 0x10), 0x84, codesize(), 0x00),\n                    lt(iszero(extcodesize(token)), exists) // Token has code and Permit2 exists.\n                )\n            ) {\n                mstore(0x00, 0x7939f4248757f0fd) // `TransferFromFailed()` or `Permit2AmountOverflow()`.\n                revert(add(0x18, shl(2, iszero(iszero(shr(160, amount))))), 0x04)\n            }\n        }\n    }\n\n    /// @dev Permit a user to spend a given amount of\n    /// another user's tokens via native EIP-2612 permit if possible, falling\n    /// back to Permit2 if native permit fails or is not implemented on the token.\n    function permit2(\n        address token,\n        address owner,\n        address spender,\n        uint256 amount,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) internal {\n        bool success;\n        /// @solidity memory-safe-assembly\n        assembly {\n            for {} shl(96, xor(token, WETH9)) {} {\n                mstore(0x00, 0x3644e515) // `DOMAIN_SEPARATOR()`.\n                if iszero(\n                    and( // The arguments of `and` are evaluated from right to left.\n                        lt(iszero(mload(0x00)), eq(returndatasize(), 0x20)), // Returns 1 non-zero word.\n                        // Gas stipend to limit gas burn for tokens that don't refund gas when\n                        // an non-existing function is called. 5K should be enough for a SLOAD.\n                        staticcall(5000, token, 0x1c, 0x04, 0x00, 0x20)\n                    )\n                ) { break }\n                // After here, we can be sure that token is a contract.\n                let m := mload(0x40)\n                mstore(add(m, 0x34), spender)\n                mstore(add(m, 0x20), shl(96, owner))\n                mstore(add(m, 0x74), deadline)\n                if eq(mload(0x00), DAI_DOMAIN_SEPARATOR) {\n                    mstore(0x14, owner)\n                    mstore(0x00, 0x7ecebe00000000000000000000000000) // `nonces(address)`.\n                    mstore(\n                        add(m, 0x94),\n                        lt(iszero(amount), staticcall(gas(), token, 0x10, 0x24, add(m, 0x54), 0x20))\n                    )\n                    mstore(m, 0x8fcbaf0c000000000000000000000000) // `IDAIPermit.permit`.\n                    // `nonces` is already at `add(m, 0x54)`.\n                    // `amount != 0` is already stored at `add(m, 0x94)`.\n                    mstore(add(m, 0xb4), and(0xff, v))\n                    mstore(add(m, 0xd4), r)\n                    mstore(add(m, 0xf4), s)\n                    success := call(gas(), token, 0, add(m, 0x10), 0x104, codesize(), 0x00)\n                    break\n                }\n                mstore(m, 0xd505accf000000000000000000000000) // `IERC20Permit.permit`.\n                mstore(add(m, 0x54), amount)\n                mstore(add(m, 0x94), and(0xff, v))\n                mstore(add(m, 0xb4), r)\n                mstore(add(m, 0xd4), s)\n                success := call(gas(), token, 0, add(m, 0x10), 0xe4, codesize(), 0x00)\n                break\n            }\n        }\n        if (!success) simplePermit2(token, owner, spender, amount, deadline, v, r, s);\n    }\n\n    /// @dev Simple permit on the Permit2 contract.\n    function simplePermit2(\n        address token,\n        address owner,\n        address spender,\n        uint256 amount,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let m := mload(0x40)\n            mstore(m, 0x927da105) // `allowance(address,address,address)`.\n            {\n                let addressMask := shr(96, not(0))\n                mstore(add(m, 0x20), and(addressMask, owner))\n                mstore(add(m, 0x40), and(addressMask, token))\n                mstore(add(m, 0x60), and(addressMask, spender))\n                mstore(add(m, 0xc0), and(addressMask, spender))\n            }\n            let p := mul(PERMIT2, iszero(shr(160, amount)))\n            if iszero(\n                and( // The arguments of `and` are evaluated from right to left.\n                    gt(returndatasize(), 0x5f), // Returns 3 words: `amount`, `expiration`, `nonce`.\n                    staticcall(gas(), p, add(m, 0x1c), 0x64, add(m, 0x60), 0x60)\n                )\n            ) {\n                mstore(0x00, 0x6b836e6b8757f0fd) // `Permit2Failed()` or `Permit2AmountOverflow()`.\n                revert(add(0x18, shl(2, iszero(p))), 0x04)\n            }\n            mstore(m, 0x2b67b570) // `Permit2.permit` (PermitSingle variant).\n            // `owner` is already `add(m, 0x20)`.\n            // `token` is already at `add(m, 0x40)`.\n            mstore(add(m, 0x60), amount)\n            mstore(add(m, 0x80), 0xffffffffffff) // `expiration = type(uint48).max`.\n            // `nonce` is already at `add(m, 0xa0)`.\n            // `spender` is already at `add(m, 0xc0)`.\n            mstore(add(m, 0xe0), deadline)\n            mstore(add(m, 0x100), 0x100) // `signature` offset.\n            mstore(add(m, 0x120), 0x41) // `signature` length.\n            mstore(add(m, 0x140), r)\n            mstore(add(m, 0x160), s)\n            mstore(add(m, 0x180), shl(248, v))\n            if iszero( // Revert if token does not have code, or if the call fails.\n                mul(extcodesize(token), call(gas(), p, 0, add(m, 0x1c), 0x184, codesize(), 0x00))\n            ) {\n                mstore(0x00, 0x6b836e6b) // `Permit2Failed()`.\n                revert(0x1c, 0x04)\n            }\n        }\n    }\n\n    /// @dev Approves `spender` to spend `amount` of `token` for `address(this)`.\n    function permit2Approve(address token, address spender, uint160 amount, uint48 expiration)\n        internal\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let addressMask := shr(96, not(0))\n            let m := mload(0x40)\n            mstore(m, 0x87517c45) // `approve(address,address,uint160,uint48)`.\n            mstore(add(m, 0x20), and(addressMask, token))\n            mstore(add(m, 0x40), and(addressMask, spender))\n            mstore(add(m, 0x60), and(addressMask, amount))\n            mstore(add(m, 0x80), and(0xffffffffffff, expiration))\n            if iszero(call(gas(), PERMIT2, 0, add(m, 0x1c), 0x84, codesize(), 0x00)) {\n                mstore(0x00, 0x324f14ae) // `Permit2ApproveFailed()`.\n                revert(0x1c, 0x04)\n            }\n        }\n    }\n\n    /// @dev Revokes an approval for `token` and `spender` for `address(this)`.\n    function permit2Lockdown(address token, address spender) internal {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let m := mload(0x40)\n            mstore(m, 0xcc53287f) // `Permit2.lockdown`.\n            mstore(add(m, 0x20), 0x20) // Offset of the `approvals`.\n            mstore(add(m, 0x40), 1) // `approvals.length`.\n            mstore(add(m, 0x60), shr(96, shl(96, token)))\n            mstore(add(m, 0x80), shr(96, shl(96, spender)))\n            if iszero(call(gas(), PERMIT2, 0, add(m, 0x1c), 0xa0, codesize(), 0x00)) {\n                mstore(0x00, 0x96b3de23) // `Permit2LockdownFailed()`.\n                revert(0x1c, 0x04)\n            }\n        }\n    }\n}\n"},{"file_path":"lib/v4-core/src/interfaces/IExtsload.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\n/// @notice Interface for functions to access any storage slot in a contract\ninterface IExtsload {\n    /// @notice Called by external contracts to access granular pool state\n    /// @param slot Key of slot to sload\n    /// @return value The value of the slot as bytes32\n    function extsload(bytes32 slot) external view returns (bytes32 value);\n\n    /// @notice Called by external contracts to access granular pool state\n    /// @param startSlot Key of slot to start sloading from\n    /// @param nSlots Number of slots to load into return value\n    /// @return values List of loaded values.\n    function extsload(bytes32 startSlot, uint256 nSlots) external view returns (bytes32[] memory values);\n\n    /// @notice Called by external contracts to access sparse pool state\n    /// @param slots List of slots to SLOAD from.\n    /// @return values List of loaded values.\n    function extsload(bytes32[] calldata slots) external view returns (bytes32[] memory values);\n}\n"},{"file_path":"lib/v4-core/src/interfaces/IExttload.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\n/// @notice Interface for functions to access any transient storage slot in a contract\ninterface IExttload {\n    /// @notice Called by external contracts to access transient storage of the contract\n    /// @param slot Key of slot to tload\n    /// @return value The value of the slot as bytes32\n    function exttload(bytes32 slot) external view returns (bytes32 value);\n\n    /// @notice Called by external contracts to access sparse transient pool state\n    /// @param slots List of slots to tload\n    /// @return values List of loaded values\n    function exttload(bytes32[] calldata slots) external view returns (bytes32[] memory values);\n}\n"},{"file_path":"lib/v4-core/src/interfaces/IHooks.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport {PoolKey} from \"../types/PoolKey.sol\";\nimport {BalanceDelta} from \"../types/BalanceDelta.sol\";\nimport {IPoolManager} from \"./IPoolManager.sol\";\nimport {BeforeSwapDelta} from \"../types/BeforeSwapDelta.sol\";\n\n/// @notice V4 decides whether to invoke specific hooks by inspecting the least significant bits\n/// of the address that the hooks contract is deployed to.\n/// For example, a hooks contract deployed to address: 0x0000000000000000000000000000000000002400\n/// has the lowest bits '10 0100 0000 0000' which would cause the 'before initialize' and 'after add liquidity' hooks to be used.\n/// See the Hooks library for the full spec.\n/// @dev Should only be callable by the v4 PoolManager.\ninterface IHooks {\n    /// @notice The hook called before the state of a pool is initialized\n    /// @param sender The initial msg.sender for the initialize call\n    /// @param key The key for the pool being initialized\n    /// @param sqrtPriceX96 The sqrt(price) of the pool as a Q64.96\n    /// @return bytes4 The function selector for the hook\n    function beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96) external returns (bytes4);\n\n    /// @notice The hook called after the state of a pool is initialized\n    /// @param sender The initial msg.sender for the initialize call\n    /// @param key The key for the pool being initialized\n    /// @param sqrtPriceX96 The sqrt(price) of the pool as a Q64.96\n    /// @param tick The current tick after the state of a pool is initialized\n    /// @return bytes4 The function selector for the hook\n    function afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)\n        external\n        returns (bytes4);\n\n    /// @notice The hook called before liquidity is added\n    /// @param sender The initial msg.sender for the add liquidity call\n    /// @param key The key for the pool\n    /// @param params The parameters for adding liquidity\n    /// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be passed on to the hook\n    /// @return bytes4 The function selector for the hook\n    function beforeAddLiquidity(\n        address sender,\n        PoolKey calldata key,\n        IPoolManager.ModifyLiquidityParams calldata params,\n        bytes calldata hookData\n    ) external returns (bytes4);\n\n    /// @notice The hook called after liquidity is added\n    /// @param sender The initial msg.sender for the add liquidity call\n    /// @param key The key for the pool\n    /// @param params The parameters for adding liquidity\n    /// @param delta The caller's balance delta after adding liquidity; the sum of principal delta, fees accrued, and hook delta\n    /// @param feesAccrued The fees accrued since the last time fees were collected from this position\n    /// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be passed on to the hook\n    /// @return bytes4 The function selector for the hook\n    /// @return BalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency\n    function afterAddLiquidity(\n        address sender,\n        PoolKey calldata key,\n        IPoolManager.ModifyLiquidityParams calldata params,\n        BalanceDelta delta,\n        BalanceDelta feesAccrued,\n        bytes calldata hookData\n    ) external returns (bytes4, BalanceDelta);\n\n    /// @notice The hook called before liquidity is removed\n    /// @param sender The initial msg.sender for the remove liquidity call\n    /// @param key The key for the pool\n    /// @param params The parameters for removing liquidity\n    /// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be be passed on to the hook\n    /// @return bytes4 The function selector for the hook\n    function beforeRemoveLiquidity(\n        address sender,\n        PoolKey calldata key,\n        IPoolManager.ModifyLiquidityParams calldata params,\n        bytes calldata hookData\n    ) external returns (bytes4);\n\n    /// @notice The hook called after liquidity is removed\n    /// @param sender The initial msg.sender for the remove liquidity call\n    /// @param key The key for the pool\n    /// @param params The parameters for removing liquidity\n    /// @param delta The caller's balance delta after removing liquidity; the sum of principal delta, fees accrued, and hook delta\n    /// @param feesAccrued The fees accrued since the last time fees were collected from this position\n    /// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be be passed on to the hook\n    /// @return bytes4 The function selector for the hook\n    /// @return BalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency\n    function afterRemoveLiquidity(\n        address sender,\n        PoolKey calldata key,\n        IPoolManager.ModifyLiquidityParams calldata params,\n        BalanceDelta delta,\n        BalanceDelta feesAccrued,\n        bytes calldata hookData\n    ) external returns (bytes4, BalanceDelta);\n\n    /// @notice The hook called before a swap\n    /// @param sender The initial msg.sender for the swap call\n    /// @param key The key for the pool\n    /// @param params The parameters for the swap\n    /// @param hookData Arbitrary data handed into the PoolManager by the swapper to be be passed on to the hook\n    /// @return bytes4 The function selector for the hook\n    /// @return BeforeSwapDelta The hook's delta in specified and unspecified currencies. Positive: the hook is owed/took currency, negative: the hook owes/sent currency\n    /// @return uint24 Optionally override the lp fee, only used if three conditions are met: 1. the Pool has a dynamic fee, 2. the value's 2nd highest bit is set (23rd bit, 0x400000), and 3. the value is less than or equal to the maximum fee (1 million)\n    function beforeSwap(\n        address sender,\n        PoolKey calldata key,\n        IPoolManager.SwapParams calldata params,\n        bytes calldata hookData\n    ) external returns (bytes4, BeforeSwapDelta, uint24);\n\n    /// @notice The hook called after a swap\n    /// @param sender The initial msg.sender for the swap call\n    /// @param key The key for the pool\n    /// @param params The parameters for the swap\n    /// @param delta The amount owed to the caller (positive) or owed to the pool (negative)\n    /// @param hookData Arbitrary data handed into the PoolManager by the swapper to be be passed on to the hook\n    /// @return bytes4 The function selector for the hook\n    /// @return int128 The hook's delta in unspecified currency. Positive: the hook is owed/took currency, negative: the hook owes/sent currency\n    function afterSwap(\n        address sender,\n        PoolKey calldata key,\n        IPoolManager.SwapParams calldata params,\n        BalanceDelta delta,\n        bytes calldata hookData\n    ) external returns (bytes4, int128);\n\n    /// @notice The hook called before donate\n    /// @param sender The initial msg.sender for the donate call\n    /// @param key The key for the pool\n    /// @param amount0 The amount of token0 being donated\n    /// @param amount1 The amount of token1 being donated\n    /// @param hookData Arbitrary data handed into the PoolManager by the donor to be be passed on to the hook\n    /// @return bytes4 The function selector for the hook\n    function beforeDonate(\n        address sender,\n        PoolKey calldata key,\n        uint256 amount0,\n        uint256 amount1,\n        bytes calldata hookData\n    ) external returns (bytes4);\n\n    /// @notice The hook called after donate\n    /// @param sender The initial msg.sender for the donate call\n    /// @param key The key for the pool\n    /// @param amount0 The amount of token0 being donated\n    /// @param amount1 The amount of token1 being donated\n    /// @param hookData Arbitrary data handed into the PoolManager by the donor to be be passed on to the hook\n    /// @return bytes4 The function selector for the hook\n    function afterDonate(\n        address sender,\n        PoolKey calldata key,\n        uint256 amount0,\n        uint256 amount1,\n        bytes calldata hookData\n    ) external returns (bytes4);\n}\n"},{"file_path":"lib/v4-core/src/interfaces/IPoolManager.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\nimport {Currency} from \"../types/Currency.sol\";\nimport {PoolKey} from \"../types/PoolKey.sol\";\nimport {IHooks} from \"./IHooks.sol\";\nimport {IERC6909Claims} from \"./external/IERC6909Claims.sol\";\nimport {IProtocolFees} from \"./IProtocolFees.sol\";\nimport {BalanceDelta} from \"../types/BalanceDelta.sol\";\nimport {PoolId} from \"../types/PoolId.sol\";\nimport {IExtsload} from \"./IExtsload.sol\";\nimport {IExttload} from \"./IExttload.sol\";\n\n/// @notice Interface for the PoolManager\ninterface IPoolManager is IProtocolFees, IERC6909Claims, IExtsload, IExttload {\n    /// @notice Thrown when a currency is not netted out after the contract is unlocked\n    error CurrencyNotSettled();\n\n    /// @notice Thrown when trying to interact with a non-initialized pool\n    error PoolNotInitialized();\n\n    /// @notice Thrown when unlock is called, but the contract is already unlocked\n    error AlreadyUnlocked();\n\n    /// @notice Thrown when a function is called that requires the contract to be unlocked, but it is not\n    error ManagerLocked();\n\n    /// @notice Pools are limited to type(int16).max tickSpacing in #initialize, to prevent overflow\n    error TickSpacingTooLarge(int24 tickSpacing);\n\n    /// @notice Pools must have a positive non-zero tickSpacing passed to #initialize\n    error TickSpacingTooSmall(int24 tickSpacing);\n\n    /// @notice PoolKey must have currencies where address(currency0) < address(currency1)\n    error CurrenciesOutOfOrderOrEqual(address currency0, address currency1);\n\n    /// @notice Thrown when a call to updateDynamicLPFee is made by an address that is not the hook,\n    /// or on a pool that does not have a dynamic swap fee.\n    error UnauthorizedDynamicLPFeeUpdate();\n\n    /// @notice Thrown when trying to swap amount of 0\n    error SwapAmountCannotBeZero();\n\n    ///@notice Thrown when native currency is passed to a non native settlement\n    error NonzeroNativeValue();\n\n    /// @notice Thrown when `clear` is called with an amount that is not exactly equal to the open currency delta.\n    error MustClearExactPositiveDelta();\n\n    /// @notice Emitted when a new pool is initialized\n    /// @param id The abi encoded hash of the pool key struct for the new pool\n    /// @param currency0 The first currency of the pool by address sort order\n    /// @param currency1 The second currency of the pool by address sort order\n    /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip\n    /// @param tickSpacing The minimum number of ticks between initialized ticks\n    /// @param hooks The hooks contract address for the pool, or address(0) if none\n    /// @param sqrtPriceX96 The price of the pool on initialization\n    /// @param tick The initial tick of the pool corresponding to the initialized price\n    event Initialize(\n        PoolId indexed id,\n        Currency indexed currency0,\n        Currency indexed currency1,\n        uint24 fee,\n        int24 tickSpacing,\n        IHooks hooks,\n        uint160 sqrtPriceX96,\n        int24 tick\n    );\n\n    /// @notice Emitted when a liquidity position is modified\n    /// @param id The abi encoded hash of the pool key struct for the pool that was modified\n    /// @param sender The address that modified the pool\n    /// @param tickLower The lower tick of the position\n    /// @param tickUpper The upper tick of the position\n    /// @param liquidityDelta The amount of liquidity that was added or removed\n    /// @param salt The extra data to make positions unique\n    event ModifyLiquidity(\n        PoolId indexed id, address indexed sender, int24 tickLower, int24 tickUpper, int256 liquidityDelta, bytes32 salt\n    );\n\n    /// @notice Emitted for swaps between currency0 and currency1\n    /// @param id The abi encoded hash of the pool key struct for the pool that was modified\n    /// @param sender The address that initiated the swap call, and that received the callback\n    /// @param amount0 The delta of the currency0 balance of the pool\n    /// @param amount1 The delta of the currency1 balance of the pool\n    /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96\n    /// @param liquidity The liquidity of the pool after the swap\n    /// @param tick The log base 1.0001 of the price of the pool after the swap\n    /// @param fee The swap fee in hundredths of a bip\n    event Swap(\n        PoolId indexed id,\n        address indexed sender,\n        int128 amount0,\n        int128 amount1,\n        uint160 sqrtPriceX96,\n        uint128 liquidity,\n        int24 tick,\n        uint24 fee\n    );\n\n    /// @notice Emitted for donations\n    /// @param id The abi encoded hash of the pool key struct for the pool that was donated to\n    /// @param sender The address that initiated the donate call\n    /// @param amount0 The amount donated in currency0\n    /// @param amount1 The amount donated in currency1\n    event Donate(PoolId indexed id, address indexed sender, uint256 amount0, uint256 amount1);\n\n    /// @notice All interactions on the contract that account deltas require unlocking. A caller that calls `unlock` must implement\n    /// `IUnlockCallback(msg.sender).unlockCallback(data)`, where they interact with the remaining functions on this contract.\n    /// @dev The only functions callable without an unlocking are `initialize` and `updateDynamicLPFee`\n    /// @param data Any data to pass to the callback, via `IUnlockCallback(msg.sender).unlockCallback(data)`\n    /// @return The data returned by the call to `IUnlockCallback(msg.sender).unlockCallback(data)`\n    function unlock(bytes calldata data) external returns (bytes memory);\n\n    /// @notice Initialize the state for a given pool ID\n    /// @dev A swap fee totaling MAX_SWAP_FEE (100%) makes exact output swaps impossible since the input is entirely consumed by the fee\n    /// @param key The pool key for the pool to initialize\n    /// @param sqrtPriceX96 The initial square root price\n    /// @return tick The initial tick of the pool\n    function initialize(PoolKey memory key, uint160 sqrtPriceX96) external returns (int24 tick);\n\n    struct ModifyLiquidityParams {\n        // the lower and upper tick of the position\n        int24 tickLower;\n        int24 tickUpper;\n        // how to modify the liquidity\n        int256 liquidityDelta;\n        // a value to set if you want unique liquidity positions at the same range\n        bytes32 salt;\n    }\n\n    /// @notice Modify the liquidity for the given pool\n    /// @dev Poke by calling with a zero liquidityDelta\n    /// @param key The pool to modify liquidity in\n    /// @param params The parameters for modifying the liquidity\n    /// @param hookData The data to pass through to the add/removeLiquidity hooks\n    /// @return callerDelta The balance delta of the caller of modifyLiquidity. This is the total of both principal, fee deltas, and hook deltas if applicable\n    /// @return feesAccrued The balance delta of the fees generated in the liquidity range. Returned for informational purposes\n    /// @dev Note that feesAccrued can be artificially inflated by a malicious actor and integrators should be careful using the value\n    /// For pools with a single liquidity position, actors can donate to themselves to inflate feeGrowthGlobal (and consequently feesAccrued)\n    /// atomically donating and collecting fees in the same unlockCallback may make the inflated value more extreme\n    function modifyLiquidity(PoolKey memory key, ModifyLiquidityParams memory params, bytes calldata hookData)\n        external\n        returns (BalanceDelta callerDelta, BalanceDelta feesAccrued);\n\n    struct SwapParams {\n        /// Whether to swap token0 for token1 or vice versa\n        bool zeroForOne;\n        /// The desired input amount if negative (exactIn), or the desired output amount if positive (exactOut)\n        int256 amountSpecified;\n        /// The sqrt price at which, if reached, the swap will stop executing\n        uint160 sqrtPriceLimitX96;\n    }\n\n    /// @notice Swap against the given pool\n    /// @param key The pool to swap in\n    /// @param params The parameters for swapping\n    /// @param hookData The data to pass through to the swap hooks\n    /// @return swapDelta The balance delta of the address swapping\n    /// @dev Swapping on low liquidity pools may cause unexpected swap amounts when liquidity available is less than amountSpecified.\n    /// Additionally note that if interacting with hooks that have the BEFORE_SWAP_RETURNS_DELTA_FLAG or AFTER_SWAP_RETURNS_DELTA_FLAG\n    /// the hook may alter the swap input/output. Integrators should perform checks on the returned swapDelta.\n    function swap(PoolKey memory key, SwapParams memory params, bytes calldata hookData)\n        external\n        returns (BalanceDelta swapDelta);\n\n    /// @notice Donate the given currency amounts to the in-range liquidity providers of a pool\n    /// @dev Calls to donate can be frontrun adding just-in-time liquidity, with the aim of receiving a portion donated funds.\n    /// Donors should keep this in mind when designing donation mechanisms.\n    /// @dev This function donates to in-range LPs at slot0.tick. In certain edge-cases of the swap algorithm, the `sqrtPrice` of\n    /// a pool can be at the lower boundary of tick `n`, but the `slot0.tick` of the pool is already `n - 1`. In this case a call to\n    /// `donate` would donate to tick `n - 1` (slot0.tick) not tick `n` (getTickAtSqrtPrice(slot0.sqrtPriceX96)).\n    /// Read the comments in `Pool.swap()` for more information about this.\n    /// @param key The key of the pool to donate to\n    /// @param amount0 The amount of currency0 to donate\n    /// @param amount1 The amount of currency1 to donate\n    /// @param hookData The data to pass through to the donate hooks\n    /// @return BalanceDelta The delta of the caller after the donate\n    function donate(PoolKey memory key, uint256 amount0, uint256 amount1, bytes calldata hookData)\n        external\n        returns (BalanceDelta);\n\n    /// @notice Writes the current ERC20 balance of the specified currency to transient storage\n    /// This is used to checkpoint balances for the manager and derive deltas for the caller.\n    /// @dev This MUST be called before any ERC20 tokens are sent into the contract, but can be skipped\n    /// for native tokens because the amount to settle is determined by the sent value.\n    /// However, if an ERC20 token has been synced and not settled, and the caller instead wants to settle\n    /// native funds, this function can be called with the native currency to then be able to settle the native currency\n    function sync(Currency currency) external;\n\n    /// @notice Called by the user to net out some value owed to the user\n    /// @dev Will revert if the requested amount is not available, consider using `mint` instead\n    /// @dev Can also be used as a mechanism for free flash loans\n    /// @param currency The currency to withdraw from the pool manager\n    /// @param to The address to withdraw to\n    /// @param amount The amount of currency to withdraw\n    function take(Currency currency, address to, uint256 amount) external;\n\n    /// @notice Called by the user to pay what is owed\n    /// @return paid The amount of currency settled\n    function settle() external payable returns (uint256 paid);\n\n    /// @notice Called by the user to pay on behalf of another address\n    /// @param recipient The address to credit for the payment\n    /// @return paid The amount of currency settled\n    function settleFor(address recipient) external payable returns (uint256 paid);\n\n    /// @notice WARNING - Any currency that is cleared, will be non-retrievable, and locked in the contract permanently.\n    /// A call to clear will zero out a positive balance WITHOUT a corresponding transfer.\n    /// @dev This could be used to clear a balance that is considered dust.\n    /// Additionally, the amount must be the exact positive balance. This is to enforce that the caller is aware of the amount being cleared.\n    function clear(Currency currency, uint256 amount) external;\n\n    /// @notice Called by the user to move value into ERC6909 balance\n    /// @param to The address to mint the tokens to\n    /// @param id The currency address to mint to ERC6909s, as a uint256\n    /// @param amount The amount of currency to mint\n    /// @dev The id is converted to a uint160 to correspond to a currency address\n    /// If the upper 12 bytes are not 0, they will be 0-ed out\n    function mint(address to, uint256 id, uint256 amount) external;\n\n    /// @notice Called by the user to move value from ERC6909 balance\n    /// @param from The address to burn the tokens from\n    /// @param id The currency address to burn from ERC6909s, as a uint256\n    /// @param amount The amount of currency to burn\n    /// @dev The id is converted to a uint160 to correspond to a currency address\n    /// If the upper 12 bytes are not 0, they will be 0-ed out\n    function burn(address from, uint256 id, uint256 amount) external;\n\n    /// @notice Updates the pools lp fees for the a pool that has enabled dynamic lp fees.\n    /// @dev A swap fee totaling MAX_SWAP_FEE (100%) makes exact output swaps impossible since the input is entirely consumed by the fee\n    /// @param key The key of the pool to update dynamic LP fees for\n    /// @param newDynamicLPFee The new dynamic pool LP fee\n    function updateDynamicLPFee(PoolKey memory key, uint24 newDynamicLPFee) external;\n}\n"},{"file_path":"lib/v4-core/src/libraries/LiquidityMath.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\n/// @title Math library for liquidity\nlibrary LiquidityMath {\n    /// @notice Add a signed liquidity delta to liquidity and revert if it overflows or underflows\n    /// @param x The liquidity before change\n    /// @param y The delta by which liquidity should be changed\n    /// @return z The liquidity delta\n    function addDelta(uint128 x, int128 y) internal pure returns (uint128 z) {\n        assembly (\"memory-safe\") {\n            z := add(and(x, 0xffffffffffffffffffffffffffffffff), signextend(15, y))\n            if shr(128, z) {\n                // revert SafeCastOverflow()\n                mstore(0, 0x93dafdf1)\n                revert(0x1c, 0x04)\n            }\n        }\n    }\n}\n"},{"file_path":"lib/v4-core/src/interfaces/IProtocolFees.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport {Currency} from \"../types/Currency.sol\";\nimport {PoolId} from \"../types/PoolId.sol\";\nimport {PoolKey} from \"../types/PoolKey.sol\";\n\n/// @notice Interface for all protocol-fee related functions in the pool manager\ninterface IProtocolFees {\n    /// @notice Thrown when protocol fee is set too high\n    error ProtocolFeeTooLarge(uint24 fee);\n\n    /// @notice Thrown when collectProtocolFees or setProtocolFee is not called by the controller.\n    error InvalidCaller();\n\n    /// @notice Thrown when collectProtocolFees is attempted on a token that is synced.\n    error ProtocolFeeCurrencySynced();\n\n    /// @notice Emitted when the protocol fee controller address is updated in setProtocolFeeController.\n    event ProtocolFeeControllerUpdated(address indexed protocolFeeController);\n\n    /// @notice Emitted when the protocol fee is updated for a pool.\n    event ProtocolFeeUpdated(PoolId indexed id, uint24 protocolFee);\n\n    /// @notice Given a currency address, returns the protocol fees accrued in that currency\n    /// @param currency The currency to check\n    /// @return amount The amount of protocol fees accrued in the currency\n    function protocolFeesAccrued(Currency currency) external view returns (uint256 amount);\n\n    /// @notice Sets the protocol fee for the given pool\n    /// @param key The key of the pool to set a protocol fee for\n    /// @param newProtocolFee The fee to set\n    function setProtocolFee(PoolKey memory key, uint24 newProtocolFee) external;\n\n    /// @notice Sets the protocol fee controller\n    /// @param controller The new protocol fee controller\n    function setProtocolFeeController(address controller) external;\n\n    /// @notice Collects the protocol fees for a given recipient and currency, returning the amount collected\n    /// @dev This will revert if the contract is unlocked\n    /// @param recipient The address to receive the protocol fees\n    /// @param currency The currency to withdraw\n    /// @param amount The amount of currency to withdraw\n    /// @return amountCollected The amount of currency successfully withdrawn\n    function collectProtocolFees(address recipient, Currency currency, uint256 amount)\n        external\n        returns (uint256 amountCollected);\n\n    /// @notice Returns the current protocol fee controller address\n    /// @return address The current protocol fee controller address\n    function protocolFeeController() external view returns (address);\n}\n"},{"file_path":"lib/v4-core/src/interfaces/external/IERC20Minimal.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\n/// @title Minimal ERC20 interface for Uniswap\n/// @notice Contains a subset of the full ERC20 interface that is used in Uniswap V3\ninterface IERC20Minimal {\n    /// @notice Returns an account's balance in the token\n    /// @param account The account for which to look up the number of tokens it has, i.e. its balance\n    /// @return The number of tokens held by the account\n    function balanceOf(address account) external view returns (uint256);\n\n    /// @notice Transfers the amount of token from the `msg.sender` to the recipient\n    /// @param recipient The account that will receive the amount transferred\n    /// @param amount The number of tokens to send from the sender to the recipient\n    /// @return Returns true for a successful transfer, false for an unsuccessful transfer\n    function transfer(address recipient, uint256 amount) external returns (bool);\n\n    /// @notice Returns the current allowance given to a spender by an owner\n    /// @param owner The account of the token owner\n    /// @param spender The account of the token spender\n    /// @return The current allowance granted by `owner` to `spender`\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /// @notice Sets the allowance of a spender from the `msg.sender` to the value `amount`\n    /// @param spender The account which will be allowed to spend a given amount of the owners tokens\n    /// @param amount The amount of tokens allowed to be used by `spender`\n    /// @return Returns true for a successful approval, false for unsuccessful\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /// @notice Transfers `amount` tokens from `sender` to `recipient` up to the allowance given to the `msg.sender`\n    /// @param sender The account from which the transfer will be initiated\n    /// @param recipient The recipient of the transfer\n    /// @param amount The amount of the transfer\n    /// @return Returns true for a successful transfer, false for unsuccessful\n    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);\n\n    /// @notice Event emitted when tokens are transferred from one address to another, either via `#transfer` or `#transferFrom`.\n    /// @param from The account from which the tokens were sent, i.e. the balance decreased\n    /// @param to The account to which the tokens were sent, i.e. the balance increased\n    /// @param value The amount of tokens that were transferred\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /// @notice Event emitted when the approval amount for the spender of a given owner's tokens changes.\n    /// @param owner The account that approved spending of its tokens\n    /// @param spender The account for which the spending allowance was modified\n    /// @param value The new allowance from the owner to the spender\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n}\n"},{"file_path":"lib/v4-core/src/interfaces/external/IERC6909Claims.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\n/// @notice Interface for claims over a contract balance, wrapped as a ERC6909\ninterface IERC6909Claims {\n    /*//////////////////////////////////////////////////////////////\n                                 EVENTS\n    //////////////////////////////////////////////////////////////*/\n\n    event OperatorSet(address indexed owner, address indexed operator, bool approved);\n\n    event Approval(address indexed owner, address indexed spender, uint256 indexed id, uint256 amount);\n\n    event Transfer(address caller, address indexed from, address indexed to, uint256 indexed id, uint256 amount);\n\n    /*//////////////////////////////////////////////////////////////\n                                 FUNCTIONS\n    //////////////////////////////////////////////////////////////*/\n\n    /// @notice Owner balance of an id.\n    /// @param owner The address of the owner.\n    /// @param id The id of the token.\n    /// @return amount The balance of the token.\n    function balanceOf(address owner, uint256 id) external view returns (uint256 amount);\n\n    /// @notice Spender allowance of an id.\n    /// @param owner The address of the owner.\n    /// @param spender The address of the spender.\n    /// @param id The id of the token.\n    /// @return amount The allowance of the token.\n    function allowance(address owner, address spender, uint256 id) external view returns (uint256 amount);\n\n    /// @notice Checks if a spender is approved by an owner as an operator\n    /// @param owner The address of the owner.\n    /// @param spender The address of the spender.\n    /// @return approved The approval status.\n    function isOperator(address owner, address spender) external view returns (bool approved);\n\n    /// @notice Transfers an amount of an id from the caller to a receiver.\n    /// @param receiver The address of the receiver.\n    /// @param id The id of the token.\n    /// @param amount The amount of the token.\n    /// @return bool True, always, unless the function reverts\n    function transfer(address receiver, uint256 id, uint256 amount) external returns (bool);\n\n    /// @notice Transfers an amount of an id from a sender to a receiver.\n    /// @param sender The address of the sender.\n    /// @param receiver The address of the receiver.\n    /// @param id The id of the token.\n    /// @param amount The amount of the token.\n    /// @return bool True, always, unless the function reverts\n    function transferFrom(address sender, address receiver, uint256 id, uint256 amount) external returns (bool);\n\n    /// @notice Approves an amount of an id to a spender.\n    /// @param spender The address of the spender.\n    /// @param id The id of the token.\n    /// @param amount The amount of the token.\n    /// @return bool True, always\n    function approve(address spender, uint256 id, uint256 amount) external returns (bool);\n\n    /// @notice Sets or removes an operator for the caller.\n    /// @param operator The address of the operator.\n    /// @param approved The approval status.\n    /// @return bool True, always\n    function setOperator(address operator, bool approved) external returns (bool);\n}\n"},{"file_path":"lib/v4-core/src/libraries/BitMath.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\n/// @title BitMath\n/// @dev This library provides functionality for computing bit properties of an unsigned integer\n/// @author Solady (https://github.com/Vectorized/solady/blob/8200a70e8dc2a77ecb074fc2e99a2a0d36547522/src/utils/LibBit.sol)\nlibrary BitMath {\n    /// @notice Returns the index of the most significant bit of the number,\n    ///     where the least significant bit is at index 0 and the most significant bit is at index 255\n    /// @param x the value for which to compute the most significant bit, must be greater than 0\n    /// @return r the index of the most significant bit\n    function mostSignificantBit(uint256 x) internal pure returns (uint8 r) {\n        require(x > 0);\n\n        assembly (\"memory-safe\") {\n            r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))\n            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))\n            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))\n            r := or(r, shl(4, lt(0xffff, shr(r, x))))\n            r := or(r, shl(3, lt(0xff, shr(r, x))))\n            // forgefmt: disable-next-item\n            r := or(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),\n                0x0706060506020500060203020504000106050205030304010505030400000000))\n        }\n    }\n\n    /// @notice Returns the index of the least significant bit of the number,\n    ///     where the least significant bit is at index 0 and the most significant bit is at index 255\n    /// @param x the value for which to compute the least significant bit, must be greater than 0\n    /// @return r the index of the least significant bit\n    function leastSignificantBit(uint256 x) internal pure returns (uint8 r) {\n        require(x > 0);\n\n        assembly (\"memory-safe\") {\n            // Isolate the least significant bit.\n            x := and(x, sub(0, x))\n            // For the upper 3 bits of the result, use a De Bruijn-like lookup.\n            // Credit to adhusson: https://blog.adhusson.com/cheap-find-first-set-evm/\n            // forgefmt: disable-next-item\n            r := shl(5, shr(252, shl(shl(2, shr(250, mul(x,\n                0xb6db6db6ddddddddd34d34d349249249210842108c6318c639ce739cffffffff))),\n                0x8040405543005266443200005020610674053026020000107506200176117077)))\n            // For the lower 5 bits of the result, use a De Bruijn lookup.\n            // forgefmt: disable-next-item\n            r := or(r, byte(and(div(0xd76453e0, shr(r, x)), 0x1f),\n                0x001f0d1e100c1d070f090b19131c1706010e11080a1a141802121b1503160405))\n        }\n    }\n}\n"},{"file_path":"lib/v4-core/src/libraries/CustomRevert.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\n/// @title Library for reverting with custom errors efficiently\n/// @notice Contains functions for reverting with custom errors with different argument types efficiently\n/// @dev To use this library, declare `using CustomRevert for bytes4;` and replace `revert CustomError()` with\n/// `CustomError.selector.revertWith()`\n/// @dev The functions may tamper with the free memory pointer but it is fine since the call context is exited immediately\nlibrary CustomRevert {\n    /// @dev ERC-7751 error for wrapping bubbled up reverts\n    error WrappedError(address target, bytes4 selector, bytes reason, bytes details);\n\n    /// @dev Reverts with the selector of a custom error in the scratch space\n    function revertWith(bytes4 selector) internal pure {\n        assembly (\"memory-safe\") {\n            mstore(0, selector)\n            revert(0, 0x04)\n        }\n    }\n\n    /// @dev Reverts with a custom error with an address argument in the scratch space\n    function revertWith(bytes4 selector, address addr) internal pure {\n        assembly (\"memory-safe\") {\n            mstore(0, selector)\n            mstore(0x04, and(addr, 0xffffffffffffffffffffffffffffffffffffffff))\n            revert(0, 0x24)\n        }\n    }\n\n    /// @dev Reverts with a custom error with an int24 argument in the scratch space\n    function revertWith(bytes4 selector, int24 value) internal pure {\n        assembly (\"memory-safe\") {\n            mstore(0, selector)\n            mstore(0x04, signextend(2, value))\n            revert(0, 0x24)\n        }\n    }\n\n    /// @dev Reverts with a custom error with a uint160 argument in the scratch space\n    function revertWith(bytes4 selector, uint160 value) internal pure {\n        assembly (\"memory-safe\") {\n            mstore(0, selector)\n            mstore(0x04, and(value, 0xffffffffffffffffffffffffffffffffffffffff))\n            revert(0, 0x24)\n        }\n    }\n\n    /// @dev Reverts with a custom error with two int24 arguments\n    function revertWith(bytes4 selector, int24 value1, int24 value2) internal pure {\n        assembly (\"memory-safe\") {\n            let fmp := mload(0x40)\n            mstore(fmp, selector)\n            mstore(add(fmp, 0x04), signextend(2, value1))\n            mstore(add(fmp, 0x24), signextend(2, value2))\n            revert(fmp, 0x44)\n        }\n    }\n\n    /// @dev Reverts with a custom error with two uint160 arguments\n    function revertWith(bytes4 selector, uint160 value1, uint160 value2) internal pure {\n        assembly (\"memory-safe\") {\n            let fmp := mload(0x40)\n            mstore(fmp, selector)\n            mstore(add(fmp, 0x04), and(value1, 0xffffffffffffffffffffffffffffffffffffffff))\n            mstore(add(fmp, 0x24), and(value2, 0xffffffffffffffffffffffffffffffffffffffff))\n            revert(fmp, 0x44)\n        }\n    }\n\n    /// @dev Reverts with a custom error with two address arguments\n    function revertWith(bytes4 selector, address value1, address value2) internal pure {\n        assembly (\"memory-safe\") {\n            let fmp := mload(0x40)\n            mstore(fmp, selector)\n            mstore(add(fmp, 0x04), and(value1, 0xffffffffffffffffffffffffffffffffffffffff))\n            mstore(add(fmp, 0x24), and(value2, 0xffffffffffffffffffffffffffffffffffffffff))\n            revert(fmp, 0x44)\n        }\n    }\n\n    /// @notice bubble up the revert message returned by a call and revert with a wrapped ERC-7751 error\n    /// @dev this method can be vulnerable to revert data bombs\n    function bubbleUpAndRevertWith(\n        address revertingContract,\n        bytes4 revertingFunctionSelector,\n        bytes4 additionalContext\n    ) internal pure {\n        bytes4 wrappedErrorSelector = WrappedError.selector;\n        assembly (\"memory-safe\") {\n            // Ensure the size of the revert data is a multiple of 32 bytes\n            let encodedDataSize := mul(div(add(returndatasize(), 31), 32), 32)\n\n            let fmp := mload(0x40)\n\n            // Encode wrapped error selector, address, function selector, offset, additional context, size, revert reason\n            mstore(fmp, wrappedErrorSelector)\n            mstore(add(fmp, 0x04), and(revertingContract, 0xffffffffffffffffffffffffffffffffffffffff))\n            mstore(\n                add(fmp, 0x24),\n                and(revertingFunctionSelector, 0xffffffff00000000000000000000000000000000000000000000000000000000)\n            )\n            // offset revert reason\n            mstore(add(fmp, 0x44), 0x80)\n            // offset additional context\n            mstore(add(fmp, 0x64), add(0xa0, encodedDataSize))\n            // size revert reason\n            mstore(add(fmp, 0x84), returndatasize())\n            // revert reason\n            returndatacopy(add(fmp, 0xa4), 0, returndatasize())\n            // size additional context\n            mstore(add(fmp, add(0xa4, encodedDataSize)), 0x04)\n            // additional context\n            mstore(\n                add(fmp, add(0xc4, encodedDataSize)),\n                and(additionalContext, 0xffffffff00000000000000000000000000000000000000000000000000000000)\n            )\n            revert(fmp, add(0xe4, encodedDataSize))\n        }\n    }\n}\n"},{"file_path":"lib/v4-core/src/libraries/FixedPoint128.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\n/// @title FixedPoint128\n/// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format)\nlibrary FixedPoint128 {\n    uint256 internal constant Q128 = 0x100000000000000000000000000000000;\n}\n"},{"file_path":"lib/v4-core/src/libraries/FixedPoint96.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\n/// @title FixedPoint96\n/// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format)\n/// @dev Used in SqrtPriceMath.sol\nlibrary FixedPoint96 {\n    uint8 internal constant RESOLUTION = 96;\n    uint256 internal constant Q96 = 0x1000000000000000000000000;\n}\n"},{"file_path":"lib/v4-core/src/libraries/FullMath.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\n/// @title Contains 512-bit math functions\n/// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision\n/// @dev Handles \"phantom overflow\" i.e., allows multiplication and division where an intermediate value overflows 256 bits\nlibrary FullMath {\n    /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n    /// @param a The multiplicand\n    /// @param b The multiplier\n    /// @param denominator The divisor\n    /// @return result The 256-bit result\n    /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv\n    function mulDiv(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) {\n        unchecked {\n            // 512-bit multiply [prod1 prod0] = a * b\n            // Compute the product mod 2**256 and mod 2**256 - 1\n            // then use the Chinese Remainder Theorem to reconstruct\n            // the 512 bit result. The result is stored in two 256\n            // variables such that product = prod1 * 2**256 + prod0\n            uint256 prod0 = a * b; // Least significant 256 bits of the product\n            uint256 prod1; // Most significant 256 bits of the product\n            assembly (\"memory-safe\") {\n                let mm := mulmod(a, b, not(0))\n                prod1 := sub(sub(mm, prod0), lt(mm, prod0))\n            }\n\n            // Make sure the result is less than 2**256.\n            // Also prevents denominator == 0\n            require(denominator > prod1);\n\n            // Handle non-overflow cases, 256 by 256 division\n            if (prod1 == 0) {\n                assembly (\"memory-safe\") {\n                    result := div(prod0, denominator)\n                }\n                return result;\n            }\n\n            ///////////////////////////////////////////////\n            // 512 by 256 division.\n            ///////////////////////////////////////////////\n\n            // Make division exact by subtracting the remainder from [prod1 prod0]\n            // Compute remainder using mulmod\n            uint256 remainder;\n            assembly (\"memory-safe\") {\n                remainder := mulmod(a, b, denominator)\n            }\n            // Subtract 256 bit number from 512 bit number\n            assembly (\"memory-safe\") {\n                prod1 := sub(prod1, gt(remainder, prod0))\n                prod0 := sub(prod0, remainder)\n            }\n\n            // Factor powers of two out of denominator\n            // Compute largest power of two divisor of denominator.\n            // Always >= 1.\n            uint256 twos = (0 - denominator) & denominator;\n            // Divide denominator by power of two\n            assembly (\"memory-safe\") {\n                denominator := div(denominator, twos)\n            }\n\n            // Divide [prod1 prod0] by the factors of two\n            assembly (\"memory-safe\") {\n                prod0 := div(prod0, twos)\n            }\n            // Shift in bits from prod1 into prod0. For this we need\n            // to flip `twos` such that it is 2**256 / twos.\n            // If twos is zero, then it becomes one\n            assembly (\"memory-safe\") {\n                twos := add(div(sub(0, twos), twos), 1)\n            }\n            prod0 |= prod1 * twos;\n\n            // Invert denominator mod 2**256\n            // Now that denominator is an odd number, it has an inverse\n            // modulo 2**256 such that denominator * inv = 1 mod 2**256.\n            // Compute the inverse by starting with a seed that is correct\n            // correct for four bits. That is, denominator * inv = 1 mod 2**4\n            uint256 inv = (3 * denominator) ^ 2;\n            // Now use Newton-Raphson iteration to improve the precision.\n            // Thanks to Hensel's lifting lemma, this also works in modular\n            // arithmetic, doubling the correct bits in each step.\n            inv *= 2 - denominator * inv; // inverse mod 2**8\n            inv *= 2 - denominator * inv; // inverse mod 2**16\n            inv *= 2 - denominator * inv; // inverse mod 2**32\n            inv *= 2 - denominator * inv; // inverse mod 2**64\n            inv *= 2 - denominator * inv; // inverse mod 2**128\n            inv *= 2 - denominator * inv; // inverse mod 2**256\n\n            // Because the division is now exact we can divide by multiplying\n            // with the modular inverse of denominator. This will give us the\n            // correct result modulo 2**256. Since the preconditions guarantee\n            // that the outcome is less than 2**256, this is the final result.\n            // We don't need to compute the high bits of the result and prod1\n            // is no longer required.\n            result = prod0 * inv;\n            return result;\n        }\n    }\n\n    /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0\n    /// @param a The multiplicand\n    /// @param b The multiplier\n    /// @param denominator The divisor\n    /// @return result The 256-bit result\n    function mulDivRoundingUp(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) {\n        unchecked {\n            result = mulDiv(a, b, denominator);\n            if (mulmod(a, b, denominator) != 0) {\n                require(++result > 0);\n            }\n        }\n    }\n}\n"},{"file_path":"lib/v4-core/src/libraries/Hooks.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport {PoolKey} from \"../types/PoolKey.sol\";\nimport {IHooks} from \"../interfaces/IHooks.sol\";\nimport {SafeCast} from \"./SafeCast.sol\";\nimport {LPFeeLibrary} from \"./LPFeeLibrary.sol\";\nimport {BalanceDelta, toBalanceDelta, BalanceDeltaLibrary} from \"../types/BalanceDelta.sol\";\nimport {BeforeSwapDelta, BeforeSwapDeltaLibrary} from \"../types/BeforeSwapDelta.sol\";\nimport {IPoolManager} from \"../interfaces/IPoolManager.sol\";\nimport {ParseBytes} from \"./ParseBytes.sol\";\nimport {CustomRevert} from \"./CustomRevert.sol\";\n\n/// @notice V4 decides whether to invoke specific hooks by inspecting the least significant bits\n/// of the address that the hooks contract is deployed to.\n/// For example, a hooks contract deployed to address: 0x0000000000000000000000000000000000002400\n/// has the lowest bits '10 0100 0000 0000' which would cause the 'before initialize' and 'after add liquidity' hooks to be used.\nlibrary Hooks {\n    using LPFeeLibrary for uint24;\n    using Hooks for IHooks;\n    using SafeCast for int256;\n    using BeforeSwapDeltaLibrary for BeforeSwapDelta;\n    using ParseBytes for bytes;\n    using CustomRevert for bytes4;\n\n    uint160 internal constant ALL_HOOK_MASK = uint160((1 << 14) - 1);\n\n    uint160 internal constant BEFORE_INITIALIZE_FLAG = 1 << 13;\n    uint160 internal constant AFTER_INITIALIZE_FLAG = 1 << 12;\n\n    uint160 internal constant BEFORE_ADD_LIQUIDITY_FLAG = 1 << 11;\n    uint160 internal constant AFTER_ADD_LIQUIDITY_FLAG = 1 << 10;\n\n    uint160 internal constant BEFORE_REMOVE_LIQUIDITY_FLAG = 1 << 9;\n    uint160 internal constant AFTER_REMOVE_LIQUIDITY_FLAG = 1 << 8;\n\n    uint160 internal constant BEFORE_SWAP_FLAG = 1 << 7;\n    uint160 internal constant AFTER_SWAP_FLAG = 1 << 6;\n\n    uint160 internal constant BEFORE_DONATE_FLAG = 1 << 5;\n    uint160 internal constant AFTER_DONATE_FLAG = 1 << 4;\n\n    uint160 internal constant BEFORE_SWAP_RETURNS_DELTA_FLAG = 1 << 3;\n    uint160 internal constant AFTER_SWAP_RETURNS_DELTA_FLAG = 1 << 2;\n    uint160 internal constant AFTER_ADD_LIQUIDITY_RETURNS_DELTA_FLAG = 1 << 1;\n    uint160 internal constant AFTER_REMOVE_LIQUIDITY_RETURNS_DELTA_FLAG = 1 << 0;\n\n    struct Permissions {\n        bool beforeInitialize;\n        bool afterInitialize;\n        bool beforeAddLiquidity;\n        bool afterAddLiquidity;\n        bool beforeRemoveLiquidity;\n        bool afterRemoveLiquidity;\n        bool beforeSwap;\n        bool afterSwap;\n        bool beforeDonate;\n        bool afterDonate;\n        bool beforeSwapReturnDelta;\n        bool afterSwapReturnDelta;\n        bool afterAddLiquidityReturnDelta;\n        bool afterRemoveLiquidityReturnDelta;\n    }\n\n    /// @notice Thrown if the address will not lead to the specified hook calls being called\n    /// @param hooks The address of the hooks contract\n    error HookAddressNotValid(address hooks);\n\n    /// @notice Hook did not return its selector\n    error InvalidHookResponse();\n\n    /// @notice Additional context for ERC-7751 wrapped error when a hook call fails\n    error HookCallFailed();\n\n    /// @notice The hook's delta changed the swap from exactIn to exactOut or vice versa\n    error HookDeltaExceedsSwapAmount();\n\n    /// @notice Utility function intended to be used in hook constructors to ensure\n    /// the deployed hooks address causes the intended hooks to be called\n    /// @param permissions The hooks that are intended to be called\n    /// @dev permissions param is memory as the function will be called from constructors\n    function validateHookPermissions(IHooks self, Permissions memory permissions) internal pure {\n        if (\n            permissions.beforeInitialize != self.hasPermission(BEFORE_INITIALIZE_FLAG)\n                || permissions.afterInitialize != self.hasPermission(AFTER_INITIALIZE_FLAG)\n                || permissions.beforeAddLiquidity != self.hasPermission(BEFORE_ADD_LIQUIDITY_FLAG)\n                || permissions.afterAddLiquidity != self.hasPermission(AFTER_ADD_LIQUIDITY_FLAG)\n                || permissions.beforeRemoveLiquidity != self.hasPermission(BEFORE_REMOVE_LIQUIDITY_FLAG)\n                || permissions.afterRemoveLiquidity != self.hasPermission(AFTER_REMOVE_LIQUIDITY_FLAG)\n                || permissions.beforeSwap != self.hasPermission(BEFORE_SWAP_FLAG)\n                || permissions.afterSwap != self.hasPermission(AFTER_SWAP_FLAG)\n                || permissions.beforeDonate != self.hasPermission(BEFORE_DONATE_FLAG)\n                || permissions.afterDonate != self.hasPermission(AFTER_DONATE_FLAG)\n                || permissions.beforeSwapReturnDelta != self.hasPermission(BEFORE_SWAP_RETURNS_DELTA_FLAG)\n                || permissions.afterSwapReturnDelta != self.hasPermission(AFTER_SWAP_RETURNS_DELTA_FLAG)\n                || permissions.afterAddLiquidityReturnDelta != self.hasPermission(AFTER_ADD_LIQUIDITY_RETURNS_DELTA_FLAG)\n                || permissions.afterRemoveLiquidityReturnDelta\n                    != self.hasPermission(AFTER_REMOVE_LIQUIDITY_RETURNS_DELTA_FLAG)\n        ) {\n            HookAddressNotValid.selector.revertWith(address(self));\n        }\n    }\n\n    /// @notice Ensures that the hook address includes at least one hook flag or dynamic fees, or is the 0 address\n    /// @param self The hook to verify\n    /// @param fee The fee of the pool the hook is used with\n    /// @return bool True if the hook address is valid\n    function isValidHookAddress(IHooks self, uint24 fee) internal pure returns (bool) {\n        // The hook can only have a flag to return a hook delta on an action if it also has the corresponding action flag\n        if (!self.hasPermission(BEFORE_SWAP_FLAG) && self.hasPermission(BEFORE_SWAP_RETURNS_DELTA_FLAG)) return false;\n        if (!self.hasPermission(AFTER_SWAP_FLAG) && self.hasPermission(AFTER_SWAP_RETURNS_DELTA_FLAG)) return false;\n        if (!self.hasPermission(AFTER_ADD_LIQUIDITY_FLAG) && self.hasPermission(AFTER_ADD_LIQUIDITY_RETURNS_DELTA_FLAG))\n        {\n            return false;\n        }\n        if (\n            !self.hasPermission(AFTER_REMOVE_LIQUIDITY_FLAG)\n                && self.hasPermission(AFTER_REMOVE_LIQUIDITY_RETURNS_DELTA_FLAG)\n        ) return false;\n\n        // If there is no hook contract set, then fee cannot be dynamic\n        // If a hook contract is set, it must have at least 1 flag set, or have a dynamic fee\n        return address(self) == address(0)\n            ? !fee.isDynamicFee()\n            : (uint160(address(self)) & ALL_HOOK_MASK > 0 || fee.isDynamicFee());\n    }\n\n    /// @notice performs a hook call using the given calldata on the given hook that doesn't return a delta\n    /// @return result The complete data returned by the hook\n    function callHook(IHooks self, bytes memory data) internal returns (bytes memory result) {\n        bool success;\n        assembly (\"memory-safe\") {\n            success := call(gas(), self, 0, add(data, 0x20), mload(data), 0, 0)\n        }\n        // Revert with FailedHookCall, containing any error message to bubble up\n        if (!success) CustomRevert.bubbleUpAndRevertWith(address(self), bytes4(data), HookCallFailed.selector);\n\n        // The call was successful, fetch the returned data\n        assembly (\"memory-safe\") {\n            // allocate result byte array from the free memory pointer\n            result := mload(0x40)\n            // store new free memory pointer at the end of the array padded to 32 bytes\n            mstore(0x40, add(result, and(add(returndatasize(), 0x3f), not(0x1f))))\n            // store length in memory\n            mstore(result, returndatasize())\n            // copy return data to result\n            returndatacopy(add(result, 0x20), 0, returndatasize())\n        }\n\n        // Length must be at least 32 to contain the selector. Check expected selector and returned selector match.\n        if (result.length < 32 || result.parseSelector() != data.parseSelector()) {\n            InvalidHookResponse.selector.revertWith();\n        }\n    }\n\n    /// @notice performs a hook call using the given calldata on the given hook\n    /// @return int256 The delta returned by the hook\n    function callHookWithReturnDelta(IHooks self, bytes memory data, bool parseReturn) internal returns (int256) {\n        bytes memory result = callHook(self, data);\n\n        // If this hook wasn't meant to return something, default to 0 delta\n        if (!parseReturn) return 0;\n\n        // A length of 64 bytes is required to return a bytes4, and a 32 byte delta\n        if (result.length != 64) InvalidHookResponse.selector.revertWith();\n        return result.parseReturnDelta();\n    }\n\n    /// @notice modifier to prevent calling a hook if they initiated the action\n    modifier noSelfCall(IHooks self) {\n        if (msg.sender != address(self)) {\n            _;\n        }\n    }\n\n    /// @notice calls beforeInitialize hook if permissioned and validates return value\n    function beforeInitialize(IHooks self, PoolKey memory key, uint160 sqrtPriceX96) internal noSelfCall(self) {\n        if (self.hasPermission(BEFORE_INITIALIZE_FLAG)) {\n            self.callHook(abi.encodeCall(IHooks.beforeInitialize, (msg.sender, key, sqrtPriceX96)));\n        }\n    }\n\n    /// @notice calls afterInitialize hook if permissioned and validates return value\n    function afterInitialize(IHooks self, PoolKey memory key, uint160 sqrtPriceX96, int24 tick)\n        internal\n        noSelfCall(self)\n    {\n        if (self.hasPermission(AFTER_INITIALIZE_FLAG)) {\n            self.callHook(abi.encodeCall(IHooks.afterInitialize, (msg.sender, key, sqrtPriceX96, tick)));\n        }\n    }\n\n    /// @notice calls beforeModifyLiquidity hook if permissioned and validates return value\n    function beforeModifyLiquidity(\n        IHooks self,\n        PoolKey memory key,\n        IPoolManager.ModifyLiquidityParams memory params,\n        bytes calldata hookData\n    ) internal noSelfCall(self) {\n        if (params.liquidityDelta > 0 && self.hasPermission(BEFORE_ADD_LIQUIDITY_FLAG)) {\n            self.callHook(abi.encodeCall(IHooks.beforeAddLiquidity, (msg.sender, key, params, hookData)));\n        } else if (params.liquidityDelta <= 0 && self.hasPermission(BEFORE_REMOVE_LIQUIDITY_FLAG)) {\n            self.callHook(abi.encodeCall(IHooks.beforeRemoveLiquidity, (msg.sender, key, params, hookData)));\n        }\n    }\n\n    /// @notice calls afterModifyLiquidity hook if permissioned and validates return value\n    function afterModifyLiquidity(\n        IHooks self,\n        PoolKey memory key,\n        IPoolManager.ModifyLiquidityParams memory params,\n        BalanceDelta delta,\n        BalanceDelta feesAccrued,\n        bytes calldata hookData\n    ) internal returns (BalanceDelta callerDelta, BalanceDelta hookDelta) {\n        if (msg.sender == address(self)) return (delta, BalanceDeltaLibrary.ZERO_DELTA);\n\n        callerDelta = delta;\n        if (params.liquidityDelta > 0) {\n            if (self.hasPermission(AFTER_ADD_LIQUIDITY_FLAG)) {\n                hookDelta = BalanceDelta.wrap(\n                    self.callHookWithReturnDelta(\n                        abi.encodeCall(\n                            IHooks.afterAddLiquidity, (msg.sender, key, params, delta, feesAccrued, hookData)\n                        ),\n                        self.hasPermission(AFTER_ADD_LIQUIDITY_RETURNS_DELTA_FLAG)\n                    )\n                );\n                callerDelta = callerDelta - hookDelta;\n            }\n        } else {\n            if (self.hasPermission(AFTER_REMOVE_LIQUIDITY_FLAG)) {\n                hookDelta = BalanceDelta.wrap(\n                    self.callHookWithReturnDelta(\n                        abi.encodeCall(\n                            IHooks.afterRemoveLiquidity, (msg.sender, key, params, delta, feesAccrued, hookData)\n                        ),\n                        self.hasPermission(AFTER_REMOVE_LIQUIDITY_RETURNS_DELTA_FLAG)\n                    )\n                );\n                callerDelta = callerDelta - hookDelta;\n            }\n        }\n    }\n\n    /// @notice calls beforeSwap hook if permissioned and validates return value\n    function beforeSwap(IHooks self, PoolKey memory key, IPoolManager.SwapParams memory params, bytes calldata hookData)\n        internal\n        returns (int256 amountToSwap, BeforeSwapDelta hookReturn, uint24 lpFeeOverride)\n    {\n        amountToSwap = params.amountSpecified;\n        if (msg.sender == address(self)) return (amountToSwap, BeforeSwapDeltaLibrary.ZERO_DELTA, lpFeeOverride);\n\n        if (self.hasPermission(BEFORE_SWAP_FLAG)) {\n            bytes memory result = callHook(self, abi.encodeCall(IHooks.beforeSwap, (msg.sender, key, params, hookData)));\n\n            // A length of 96 bytes is required to return a bytes4, a 32 byte delta, and an LP fee\n            if (result.length != 96) InvalidHookResponse.selector.revertWith();\n\n            // dynamic fee pools that want to override the cache fee, return a valid fee with the override flag. If override flag\n            // is set but an invalid fee is returned, the transaction will revert. Otherwise the current LP fee will be used\n            if (key.fee.isDynamicFee()) lpFeeOverride = result.parseFee();\n\n            // skip this logic for the case where the hook return is 0\n            if (self.hasPermission(BEFORE_SWAP_RETURNS_DELTA_FLAG)) {\n                hookReturn = BeforeSwapDelta.wrap(result.parseReturnDelta());\n\n                // any return in unspecified is passed to the afterSwap hook for handling\n                int128 hookDeltaSpecified = hookReturn.getSpecifiedDelta();\n\n                // Update the swap amount according to the hook's return, and check that the swap type doesn't change (exact input/output)\n                if (hookDeltaSpecified != 0) {\n                    bool exactInput = amountToSwap < 0;\n                    amountToSwap += hookDeltaSpecified;\n                    if (exactInput ? amountToSwap > 0 : amountToSwap < 0) {\n                        HookDeltaExceedsSwapAmount.selector.revertWith();\n                    }\n                }\n            }\n        }\n    }\n\n    /// @notice calls afterSwap hook if permissioned and validates return value\n    function afterSwap(\n        IHooks self,\n        PoolKey memory key,\n        IPoolManager.SwapParams memory params,\n        BalanceDelta swapDelta,\n        bytes calldata hookData,\n        BeforeSwapDelta beforeSwapHookReturn\n    ) internal returns (BalanceDelta, BalanceDelta) {\n        if (msg.sender == address(self)) return (swapDelta, BalanceDeltaLibrary.ZERO_DELTA);\n\n        int128 hookDeltaSpecified = beforeSwapHookReturn.getSpecifiedDelta();\n        int128 hookDeltaUnspecified = beforeSwapHookReturn.getUnspecifiedDelta();\n\n        if (self.hasPermission(AFTER_SWAP_FLAG)) {\n            hookDeltaUnspecified += self.callHookWithReturnDelta(\n                abi.encodeCall(IHooks.afterSwap, (msg.sender, key, params, swapDelta, hookData)),\n                self.hasPermission(AFTER_SWAP_RETURNS_DELTA_FLAG)\n            ).toInt128();\n        }\n\n        BalanceDelta hookDelta;\n        if (hookDeltaUnspecified != 0 || hookDeltaSpecified != 0) {\n            hookDelta = (params.amountSpecified < 0 == params.zeroForOne)\n                ? toBalanceDelta(hookDeltaSpecified, hookDeltaUnspecified)\n                : toBalanceDelta(hookDeltaUnspecified, hookDeltaSpecified);\n\n            // the caller has to pay for (or receive) the hook's delta\n            swapDelta = swapDelta - hookDelta;\n        }\n        return (swapDelta, hookDelta);\n    }\n\n    /// @notice calls beforeDonate hook if permissioned and validates return value\n    function beforeDonate(IHooks self, PoolKey memory key, uint256 amount0, uint256 amount1, bytes calldata hookData)\n        internal\n        noSelfCall(self)\n    {\n        if (self.hasPermission(BEFORE_DONATE_FLAG)) {\n            self.callHook(abi.encodeCall(IHooks.beforeDonate, (msg.sender, key, amount0, amount1, hookData)));\n        }\n    }\n\n    /// @notice calls afterDonate hook if permissioned and validates return value\n    function afterDonate(IHooks self, PoolKey memory key, uint256 amount0, uint256 amount1, bytes calldata hookData)\n        internal\n        noSelfCall(self)\n    {\n        if (self.hasPermission(AFTER_DONATE_FLAG)) {\n            self.callHook(abi.encodeCall(IHooks.afterDonate, (msg.sender, key, amount0, amount1, hookData)));\n        }\n    }\n\n    function hasPermission(IHooks self, uint160 flag) internal pure returns (bool) {\n        return uint160(address(self)) & flag != 0;\n    }\n}\n"},{"file_path":"lib/v4-core/src/libraries/LPFeeLibrary.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport {CustomRevert} from \"./CustomRevert.sol\";\n\n/// @notice Library of helper functions for a pools LP fee\nlibrary LPFeeLibrary {\n    using LPFeeLibrary for uint24;\n    using CustomRevert for bytes4;\n\n    /// @notice Thrown when the static or dynamic fee on a pool exceeds 100%.\n    error LPFeeTooLarge(uint24 fee);\n\n    /// @notice An lp fee of exactly 0b1000000... signals a dynamic fee pool. This isn't a valid static fee as it is > MAX_LP_FEE\n    uint24 public constant DYNAMIC_FEE_FLAG = 0x800000;\n\n    /// @notice the second bit of the fee returned by beforeSwap is used to signal if the stored LP fee should be overridden in this swap\n    // only dynamic-fee pools can return a fee via the beforeSwap hook\n    uint24 public constant OVERRIDE_FEE_FLAG = 0x400000;\n\n    /// @notice mask to remove the override fee flag from a fee returned by the beforeSwaphook\n    uint24 public constant REMOVE_OVERRIDE_MASK = 0xBFFFFF;\n\n    /// @notice the lp fee is represented in hundredths of a bip, so the max is 100%\n    uint24 public constant MAX_LP_FEE = 1000000;\n\n    /// @notice returns true if a pool's LP fee signals that the pool has a dynamic fee\n    /// @param self The fee to check\n    /// @return bool True of the fee is dynamic\n    function isDynamicFee(uint24 self) internal pure returns (bool) {\n        return self == DYNAMIC_FEE_FLAG;\n    }\n\n    /// @notice returns true if an LP fee is valid, aka not above the maximum permitted fee\n    /// @param self The fee to check\n    /// @return bool True of the fee is valid\n    function isValid(uint24 self) internal pure returns (bool) {\n        return self <= MAX_LP_FEE;\n    }\n\n    /// @notice validates whether an LP fee is larger than the maximum, and reverts if invalid\n    /// @param self The fee to validate\n    function validate(uint24 self) internal pure {\n        if (!self.isValid()) LPFeeTooLarge.selector.revertWith(self);\n    }\n\n    /// @notice gets and validates the initial LP fee for a pool. Dynamic fee pools have an initial fee of 0.\n    /// @dev if a dynamic fee pool wants a non-0 initial fee, it should call `updateDynamicLPFee` in the afterInitialize hook\n    /// @param self The fee to get the initial LP from\n    /// @return initialFee 0 if the fee is dynamic, otherwise the fee (if valid)\n    function getInitialLPFee(uint24 self) internal pure returns (uint24) {\n        // the initial fee for a dynamic fee pool is 0\n        if (self.isDynamicFee()) return 0;\n        self.validate();\n        return self;\n    }\n\n    /// @notice returns true if the fee has the override flag set (2nd highest bit of the uint24)\n    /// @param self The fee to check\n    /// @return bool True of the fee has the override flag set\n    function isOverride(uint24 self) internal pure returns (bool) {\n        return self & OVERRIDE_FEE_FLAG != 0;\n    }\n\n    /// @notice returns a fee with the override flag removed\n    /// @param self The fee to remove the override flag from\n    /// @return fee The fee without the override flag set\n    function removeOverrideFlag(uint24 self) internal pure returns (uint24) {\n        return self & REMOVE_OVERRIDE_MASK;\n    }\n\n    /// @notice Removes the override flag and validates the fee (reverts if the fee is too large)\n    /// @param self The fee to remove the override flag from, and then validate\n    /// @return fee The fee without the override flag set (if valid)\n    function removeOverrideFlagAndValidate(uint24 self) internal pure returns (uint24 fee) {\n        fee = self.removeOverrideFlag();\n        fee.validate();\n    }\n}\n"},{"file_path":"lib/v4-core/src/libraries/ParseBytes.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\n/// @notice Parses bytes returned from hooks and the byte selector used to check return selectors from hooks.\n/// @dev parseSelector also is used to parse the expected selector\n/// For parsing hook returns, note that all hooks return either bytes4 or (bytes4, 32-byte-delta) or (bytes4, 32-byte-delta, uint24).\nlibrary ParseBytes {\n    function parseSelector(bytes memory result) internal pure returns (bytes4 selector) {\n        // equivalent: (selector,) = abi.decode(result, (bytes4, int256));\n        assembly (\"memory-safe\") {\n            selector := mload(add(result, 0x20))\n        }\n    }\n\n    function parseFee(bytes memory result) internal pure returns (uint24 lpFee) {\n        // equivalent: (,, lpFee) = abi.decode(result, (bytes4, int256, uint24));\n        assembly (\"memory-safe\") {\n            lpFee := mload(add(result, 0x60))\n        }\n    }\n\n    function parseReturnDelta(bytes memory result) internal pure returns (int256 hookReturn) {\n        // equivalent: (, hookReturnDelta) = abi.decode(result, (bytes4, int256));\n        assembly (\"memory-safe\") {\n            hookReturn := mload(add(result, 0x40))\n        }\n    }\n}\n"},{"file_path":"lib/v4-core/src/libraries/Position.sol","source_code":"// SPDX-License-Identifier: BUSL-1.1\npragma solidity ^0.8.0;\n\nimport {FullMath} from \"./FullMath.sol\";\nimport {FixedPoint128} from \"./FixedPoint128.sol\";\nimport {LiquidityMath} from \"./LiquidityMath.sol\";\nimport {CustomRevert} from \"./CustomRevert.sol\";\n\n/// @title Position\n/// @notice Positions represent an owner address' liquidity between a lower and upper tick boundary\n/// @dev Positions store additional state for tracking fees owed to the position\nlibrary Position {\n    using CustomRevert for bytes4;\n\n    /// @notice Cannot update a position with no liquidity\n    error CannotUpdateEmptyPosition();\n\n    // info stored for each user's position\n    struct State {\n        // the amount of liquidity owned by this position\n        uint128 liquidity;\n        // fee growth per unit of liquidity as of the last update to liquidity or fees owed\n        uint256 feeGrowthInside0LastX128;\n        uint256 feeGrowthInside1LastX128;\n    }\n\n    /// @notice Returns the State struct of a position, given an owner and position boundaries\n    /// @param self The mapping containing all user positions\n    /// @param owner The address of the position owner\n    /// @param tickLower The lower tick boundary of the position\n    /// @param tickUpper The upper tick boundary of the position\n    /// @param salt A unique value to differentiate between multiple positions in the same range\n    /// @return position The position info struct of the given owners' position\n    function get(mapping(bytes32 => State) storage self, address owner, int24 tickLower, int24 tickUpper, bytes32 salt)\n        internal\n        view\n        returns (State storage position)\n    {\n        bytes32 positionKey = calculatePositionKey(owner, tickLower, tickUpper, salt);\n        position = self[positionKey];\n    }\n\n    /// @notice A helper function to calculate the position key\n    /// @param owner The address of the position owner\n    /// @param tickLower the lower tick boundary of the position\n    /// @param tickUpper the upper tick boundary of the position\n    /// @param salt A unique value to differentiate between multiple positions in the same range, by the same owner. Passed in by the caller.\n    function calculatePositionKey(address owner, int24 tickLower, int24 tickUpper, bytes32 salt)\n        internal\n        pure\n        returns (bytes32 positionKey)\n    {\n        // positionKey = keccak256(abi.encodePacked(owner, tickLower, tickUpper, salt))\n        assembly (\"memory-safe\") {\n            let fmp := mload(0x40)\n            mstore(add(fmp, 0x26), salt) // [0x26, 0x46)\n            mstore(add(fmp, 0x06), tickUpper) // [0x23, 0x26)\n            mstore(add(fmp, 0x03), tickLower) // [0x20, 0x23)\n            mstore(fmp, owner) // [0x0c, 0x20)\n            positionKey := keccak256(add(fmp, 0x0c), 0x3a) // len is 58 bytes\n\n            // now clean the memory we used\n            mstore(add(fmp, 0x40), 0) // fmp+0x40 held salt\n            mstore(add(fmp, 0x20), 0) // fmp+0x20 held tickLower, tickUpper, salt\n            mstore(fmp, 0) // fmp held owner\n        }\n    }\n\n    /// @notice Credits accumulated fees to a user's position\n    /// @param self The individual position to update\n    /// @param liquidityDelta The change in pool liquidity as a result of the position update\n    /// @param feeGrowthInside0X128 The all-time fee growth in currency0, per unit of liquidity, inside the position's tick boundaries\n    /// @param feeGrowthInside1X128 The all-time fee growth in currency1, per unit of liquidity, inside the position's tick boundaries\n    /// @return feesOwed0 The amount of currency0 owed to the position owner\n    /// @return feesOwed1 The amount of currency1 owed to the position owner\n    function update(\n        State storage self,\n        int128 liquidityDelta,\n        uint256 feeGrowthInside0X128,\n        uint256 feeGrowthInside1X128\n    ) internal returns (uint256 feesOwed0, uint256 feesOwed1) {\n        uint128 liquidity = self.liquidity;\n\n        if (liquidityDelta == 0) {\n            // disallow pokes for 0 liquidity positions\n            if (liquidity == 0) CannotUpdateEmptyPosition.selector.revertWith();\n        } else {\n            self.liquidity = LiquidityMath.addDelta(liquidity, liquidityDelta);\n        }\n\n        // calculate accumulated fees. overflow in the subtraction of fee growth is expected\n        unchecked {\n            feesOwed0 =\n                FullMath.mulDiv(feeGrowthInside0X128 - self.feeGrowthInside0LastX128, liquidity, FixedPoint128.Q128);\n            feesOwed1 =\n                FullMath.mulDiv(feeGrowthInside1X128 - self.feeGrowthInside1LastX128, liquidity, FixedPoint128.Q128);\n        }\n\n        // update the position\n        self.feeGrowthInside0LastX128 = feeGrowthInside0X128;\n        self.feeGrowthInside1LastX128 = feeGrowthInside1X128;\n    }\n}\n"},{"file_path":"lib/v4-core/src/libraries/SafeCast.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport {CustomRevert} from \"./CustomRevert.sol\";\n\n/// @title Safe casting methods\n/// @notice Contains methods for safely casting between types\nlibrary SafeCast {\n    using CustomRevert for bytes4;\n\n    error SafeCastOverflow();\n\n    /// @notice Cast a uint256 to a uint160, revert on overflow\n    /// @param x The uint256 to be downcasted\n    /// @return y The downcasted integer, now type uint160\n    function toUint160(uint256 x) internal pure returns (uint160 y) {\n        y = uint160(x);\n        if (y != x) SafeCastOverflow.selector.revertWith();\n    }\n\n    /// @notice Cast a uint256 to a uint128, revert on overflow\n    /// @param x The uint256 to be downcasted\n    /// @return y The downcasted integer, now type uint128\n    function toUint128(uint256 x) internal pure returns (uint128 y) {\n        y = uint128(x);\n        if (x != y) SafeCastOverflow.selector.revertWith();\n    }\n\n    /// @notice Cast a int128 to a uint128, revert on overflow or underflow\n    /// @param x The int128 to be casted\n    /// @return y The casted integer, now type uint128\n    function toUint128(int128 x) internal pure returns (uint128 y) {\n        if (x < 0) SafeCastOverflow.selector.revertWith();\n        y = uint128(x);\n    }\n\n    /// @notice Cast a int256 to a int128, revert on overflow or underflow\n    /// @param x The int256 to be downcasted\n    /// @return y The downcasted integer, now type int128\n    function toInt128(int256 x) internal pure returns (int128 y) {\n        y = int128(x);\n        if (y != x) SafeCastOverflow.selector.revertWith();\n    }\n\n    /// @notice Cast a uint256 to a int256, revert on overflow\n    /// @param x The uint256 to be casted\n    /// @return y The casted integer, now type int256\n    function toInt256(uint256 x) internal pure returns (int256 y) {\n        y = int256(x);\n        if (y < 0) SafeCastOverflow.selector.revertWith();\n    }\n\n    /// @notice Cast a uint256 to a int128, revert on overflow\n    /// @param x The uint256 to be downcasted\n    /// @return The downcasted integer, now type int128\n    function toInt128(uint256 x) internal pure returns (int128) {\n        if (x >= 1 << 127) SafeCastOverflow.selector.revertWith();\n        return int128(int256(x));\n    }\n}\n"},{"file_path":"lib/v4-core/src/libraries/SqrtPriceMath.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport {SafeCast} from \"./SafeCast.sol\";\n\nimport {FullMath} from \"./FullMath.sol\";\nimport {UnsafeMath} from \"./UnsafeMath.sol\";\nimport {FixedPoint96} from \"./FixedPoint96.sol\";\n\n/// @title Functions based on Q64.96 sqrt price and liquidity\n/// @notice Contains the math that uses square root of price as a Q64.96 and liquidity to compute deltas\nlibrary SqrtPriceMath {\n    using SafeCast for uint256;\n\n    error InvalidPriceOrLiquidity();\n    error InvalidPrice();\n    error NotEnoughLiquidity();\n    error PriceOverflow();\n\n    /// @notice Gets the next sqrt price given a delta of currency0\n    /// @dev Always rounds up, because in the exact output case (increasing price) we need to move the price at least\n    /// far enough to get the desired output amount, and in the exact input case (decreasing price) we need to move the\n    /// price less in order to not send too much output.\n    /// The most precise formula for this is liquidity * sqrtPX96 / (liquidity +- amount * sqrtPX96),\n    /// if this is impossible because of overflow, we calculate liquidity / (liquidity / sqrtPX96 +- amount).\n    /// @param sqrtPX96 The starting price, i.e. before accounting for the currency0 delta\n    /// @param liquidity The amount of usable liquidity\n    /// @param amount How much of currency0 to add or remove from virtual reserves\n    /// @param add Whether to add or remove the amount of currency0\n    /// @return The price after adding or removing amount, depending on add\n    function getNextSqrtPriceFromAmount0RoundingUp(uint160 sqrtPX96, uint128 liquidity, uint256 amount, bool add)\n        internal\n        pure\n        returns (uint160)\n    {\n        // we short circuit amount == 0 because the result is otherwise not guaranteed to equal the input price\n        if (amount == 0) return sqrtPX96;\n        uint256 numerator1 = uint256(liquidity) << FixedPoint96.RESOLUTION;\n\n        if (add) {\n            unchecked {\n                uint256 product = amount * sqrtPX96;\n                if (product / amount == sqrtPX96) {\n                    uint256 denominator = numerator1 + product;\n                    if (denominator >= numerator1) {\n                        // always fits in 160 bits\n                        return uint160(FullMath.mulDivRoundingUp(numerator1, sqrtPX96, denominator));\n                    }\n                }\n            }\n            // denominator is checked for overflow\n            return uint160(UnsafeMath.divRoundingUp(numerator1, (numerator1 / sqrtPX96) + amount));\n        } else {\n            unchecked {\n                uint256 product = amount * sqrtPX96;\n                // if the product overflows, we know the denominator underflows\n                // in addition, we must check that the denominator does not underflow\n                // equivalent: if (product / amount != sqrtPX96 || numerator1 <= product) revert PriceOverflow();\n                assembly (\"memory-safe\") {\n                    if iszero(\n                        and(\n                            eq(div(product, amount), and(sqrtPX96, 0xffffffffffffffffffffffffffffffffffffffff)),\n                            gt(numerator1, product)\n                        )\n                    ) {\n                        mstore(0, 0xf5c787f1) // selector for PriceOverflow()\n                        revert(0x1c, 0x04)\n                    }\n                }\n                uint256 denominator = numerator1 - product;\n                return FullMath.mulDivRoundingUp(numerator1, sqrtPX96, denominator).toUint160();\n            }\n        }\n    }\n\n    /// @notice Gets the next sqrt price given a delta of currency1\n    /// @dev Always rounds down, because in the exact output case (decreasing price) we need to move the price at least\n    /// far enough to get the desired output amount, and in the exact input case (increasing price) we need to move the\n    /// price less in order to not send too much output.\n    /// The formula we compute is within <1 wei of the lossless version: sqrtPX96 +- amount / liquidity\n    /// @param sqrtPX96 The starting price, i.e., before accounting for the currency1 delta\n    /// @param liquidity The amount of usable liquidity\n    /// @param amount How much of currency1 to add, or remove, from virtual reserves\n    /// @param add Whether to add, or remove, the amount of currency1\n    /// @return The price after adding or removing `amount`\n    function getNextSqrtPriceFromAmount1RoundingDown(uint160 sqrtPX96, uint128 liquidity, uint256 amount, bool add)\n        internal\n        pure\n        returns (uint160)\n    {\n        // if we're adding (subtracting), rounding down requires rounding the quotient down (up)\n        // in both cases, avoid a mulDiv for most inputs\n        if (add) {\n            uint256 quotient = (\n                amount <= type(uint160).max\n                    ? (amount << FixedPoint96.RESOLUTION) / liquidity\n                    : FullMath.mulDiv(amount, FixedPoint96.Q96, liquidity)\n            );\n\n            return (uint256(sqrtPX96) + quotient).toUint160();\n        } else {\n            uint256 quotient = (\n                amount <= type(uint160).max\n                    ? UnsafeMath.divRoundingUp(amount << FixedPoint96.RESOLUTION, liquidity)\n                    : FullMath.mulDivRoundingUp(amount, FixedPoint96.Q96, liquidity)\n            );\n\n            // equivalent: if (sqrtPX96 <= quotient) revert NotEnoughLiquidity();\n            assembly (\"memory-safe\") {\n                if iszero(gt(and(sqrtPX96, 0xffffffffffffffffffffffffffffffffffffffff), quotient)) {\n                    mstore(0, 0x4323a555) // selector for NotEnoughLiquidity()\n                    revert(0x1c, 0x04)\n                }\n            }\n            // always fits 160 bits\n            unchecked {\n                return uint160(sqrtPX96 - quotient);\n            }\n        }\n    }\n\n    /// @notice Gets the next sqrt price given an input amount of currency0 or currency1\n    /// @dev Throws if price or liquidity are 0, or if the next price is out of bounds\n    /// @param sqrtPX96 The starting price, i.e., before accounting for the input amount\n    /// @param liquidity The amount of usable liquidity\n    /// @param amountIn How much of currency0, or currency1, is being swapped in\n    /// @param zeroForOne Whether the amount in is currency0 or currency1\n    /// @return uint160 The price after adding the input amount to currency0 or currency1\n    function getNextSqrtPriceFromInput(uint160 sqrtPX96, uint128 liquidity, uint256 amountIn, bool zeroForOne)\n        internal\n        pure\n        returns (uint160)\n    {\n        // equivalent: if (sqrtPX96 == 0 || liquidity == 0) revert InvalidPriceOrLiquidity();\n        assembly (\"memory-safe\") {\n            if or(\n                iszero(and(sqrtPX96, 0xffffffffffffffffffffffffffffffffffffffff)),\n                iszero(and(liquidity, 0xffffffffffffffffffffffffffffffff))\n            ) {\n                mstore(0, 0x4f2461b8) // selector for InvalidPriceOrLiquidity()\n                revert(0x1c, 0x04)\n            }\n        }\n\n        // round to make sure that we don't pass the target price\n        return zeroForOne\n            ? getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountIn, true)\n            : getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountIn, true);\n    }\n\n    /// @notice Gets the next sqrt price given an output amount of currency0 or currency1\n    /// @dev Throws if price or liquidity are 0 or the next price is out of bounds\n    /// @param sqrtPX96 The starting price before accounting for the output amount\n    /// @param liquidity The amount of usable liquidity\n    /// @param amountOut How much of currency0, or currency1, is being swapped out\n    /// @param zeroForOne Whether the amount out is currency1 or currency0\n    /// @return uint160 The price after removing the output amount of currency0 or currency1\n    function getNextSqrtPriceFromOutput(uint160 sqrtPX96, uint128 liquidity, uint256 amountOut, bool zeroForOne)\n        internal\n        pure\n        returns (uint160)\n    {\n        // equivalent: if (sqrtPX96 == 0 || liquidity == 0) revert InvalidPriceOrLiquidity();\n        assembly (\"memory-safe\") {\n            if or(\n                iszero(and(sqrtPX96, 0xffffffffffffffffffffffffffffffffffffffff)),\n                iszero(and(liquidity, 0xffffffffffffffffffffffffffffffff))\n            ) {\n                mstore(0, 0x4f2461b8) // selector for InvalidPriceOrLiquidity()\n                revert(0x1c, 0x04)\n            }\n        }\n\n        // round to make sure that we pass the target price\n        return zeroForOne\n            ? getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountOut, false)\n            : getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountOut, false);\n    }\n\n    /// @notice Gets the amount0 delta between two prices\n    /// @dev Calculates liquidity / sqrt(lower) - liquidity / sqrt(upper),\n    /// i.e. liquidity * (sqrt(upper) - sqrt(lower)) / (sqrt(upper) * sqrt(lower))\n    /// @param sqrtPriceAX96 A sqrt price\n    /// @param sqrtPriceBX96 Another sqrt price\n    /// @param liquidity The amount of usable liquidity\n    /// @param roundUp Whether to round the amount up or down\n    /// @return uint256 Amount of currency0 required to cover a position of size liquidity between the two passed prices\n    function getAmount0Delta(uint160 sqrtPriceAX96, uint160 sqrtPriceBX96, uint128 liquidity, bool roundUp)\n        internal\n        pure\n        returns (uint256)\n    {\n        unchecked {\n            if (sqrtPriceAX96 > sqrtPriceBX96) (sqrtPriceAX96, sqrtPriceBX96) = (sqrtPriceBX96, sqrtPriceAX96);\n\n            // equivalent: if (sqrtPriceAX96 == 0) revert InvalidPrice();\n            assembly (\"memory-safe\") {\n                if iszero(and(sqrtPriceAX96, 0xffffffffffffffffffffffffffffffffffffffff)) {\n                    mstore(0, 0x00bfc921) // selector for InvalidPrice()\n                    revert(0x1c, 0x04)\n                }\n            }\n\n            uint256 numerator1 = uint256(liquidity) << FixedPoint96.RESOLUTION;\n            uint256 numerator2 = sqrtPriceBX96 - sqrtPriceAX96;\n\n            return roundUp\n                ? UnsafeMath.divRoundingUp(FullMath.mulDivRoundingUp(numerator1, numerator2, sqrtPriceBX96), sqrtPriceAX96)\n                : FullMath.mulDiv(numerator1, numerator2, sqrtPriceBX96) / sqrtPriceAX96;\n        }\n    }\n\n    /// @notice Equivalent to: `a >= b ? a - b : b - a`\n    function absDiff(uint160 a, uint160 b) internal pure returns (uint256 res) {\n        assembly (\"memory-safe\") {\n            let diff :=\n                sub(and(a, 0xffffffffffffffffffffffffffffffffffffffff), and(b, 0xffffffffffffffffffffffffffffffffffffffff))\n            // mask = 0 if a >= b else -1 (all 1s)\n            let mask := sar(255, diff)\n            // if a >= b, res = a - b = 0 ^ (a - b)\n            // if a < b, res = b - a = ~~(b - a) = ~(-(b - a) - 1) = ~(a - b - 1) = (-1) ^ (a - b - 1)\n            // either way, res = mask ^ (a - b + mask)\n            res := xor(mask, add(mask, diff))\n        }\n    }\n\n    /// @notice Gets the amount1 delta between two prices\n    /// @dev Calculates liquidity * (sqrt(upper) - sqrt(lower))\n    /// @param sqrtPriceAX96 A sqrt price\n    /// @param sqrtPriceBX96 Another sqrt price\n    /// @param liquidity The amount of usable liquidity\n    /// @param roundUp Whether to round the amount up, or down\n    /// @return amount1 Amount of currency1 required to cover a position of size liquidity between the two passed prices\n    function getAmount1Delta(uint160 sqrtPriceAX96, uint160 sqrtPriceBX96, uint128 liquidity, bool roundUp)\n        internal\n        pure\n        returns (uint256 amount1)\n    {\n        uint256 numerator = absDiff(sqrtPriceAX96, sqrtPriceBX96);\n        uint256 denominator = FixedPoint96.Q96;\n        uint256 _liquidity = uint256(liquidity);\n\n        /**\n         * Equivalent to:\n         *   amount1 = roundUp\n         *       ? FullMath.mulDivRoundingUp(liquidity, sqrtPriceBX96 - sqrtPriceAX96, FixedPoint96.Q96)\n         *       : FullMath.mulDiv(liquidity, sqrtPriceBX96 - sqrtPriceAX96, FixedPoint96.Q96);\n         * Cannot overflow because `type(uint128).max * type(uint160).max >> 96 < (1 << 192)`.\n         */\n        amount1 = FullMath.mulDiv(_liquidity, numerator, denominator);\n        assembly (\"memory-safe\") {\n            amount1 := add(amount1, and(gt(mulmod(_liquidity, numerator, denominator), 0), roundUp))\n        }\n    }\n\n    /// @notice Helper that gets signed currency0 delta\n    /// @param sqrtPriceAX96 A sqrt price\n    /// @param sqrtPriceBX96 Another sqrt price\n    /// @param liquidity The change in liquidity for which to compute the amount0 delta\n    /// @return int256 Amount of currency0 corresponding to the passed liquidityDelta between the two prices\n    function getAmount0Delta(uint160 sqrtPriceAX96, uint160 sqrtPriceBX96, int128 liquidity)\n        internal\n        pure\n        returns (int256)\n    {\n        unchecked {\n            return liquidity < 0\n                ? getAmount0Delta(sqrtPriceAX96, sqrtPriceBX96, uint128(-liquidity), false).toInt256()\n                : -getAmount0Delta(sqrtPriceAX96, sqrtPriceBX96, uint128(liquidity), true).toInt256();\n        }\n    }\n\n    /// @notice Helper that gets signed currency1 delta\n    /// @param sqrtPriceAX96 A sqrt price\n    /// @param sqrtPriceBX96 Another sqrt price\n    /// @param liquidity The change in liquidity for which to compute the amount1 delta\n    /// @return int256 Amount of currency1 corresponding to the passed liquidityDelta between the two prices\n    function getAmount1Delta(uint160 sqrtPriceAX96, uint160 sqrtPriceBX96, int128 liquidity)\n        internal\n        pure\n        returns (int256)\n    {\n        unchecked {\n            return liquidity < 0\n                ? getAmount1Delta(sqrtPriceAX96, sqrtPriceBX96, uint128(-liquidity), false).toInt256()\n                : -getAmount1Delta(sqrtPriceAX96, sqrtPriceBX96, uint128(liquidity), true).toInt256();\n        }\n    }\n}\n"},{"file_path":"lib/v4-core/src/libraries/StateLibrary.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport {PoolId} from \"../types/PoolId.sol\";\nimport {IPoolManager} from \"../interfaces/IPoolManager.sol\";\nimport {Position} from \"./Position.sol\";\n\n/// @notice A helper library to provide state getters that use extsload\nlibrary StateLibrary {\n    /// @notice index of pools mapping in the PoolManager\n    bytes32 public constant POOLS_SLOT = bytes32(uint256(6));\n\n    /// @notice index of feeGrowthGlobal0X128 in Pool.State\n    uint256 public constant FEE_GROWTH_GLOBAL0_OFFSET = 1;\n\n    // feeGrowthGlobal1X128 offset in Pool.State = 2\n\n    /// @notice index of liquidity in Pool.State\n    uint256 public constant LIQUIDITY_OFFSET = 3;\n\n    /// @notice index of TicksInfo mapping in Pool.State: mapping(int24 => TickInfo) ticks;\n    uint256 public constant TICKS_OFFSET = 4;\n\n    /// @notice index of tickBitmap mapping in Pool.State\n    uint256 public constant TICK_BITMAP_OFFSET = 5;\n\n    /// @notice index of Position.State mapping in Pool.State: mapping(bytes32 => Position.State) positions;\n    uint256 public constant POSITIONS_OFFSET = 6;\n\n    /**\n     * @notice Get Slot0 of the pool: sqrtPriceX96, tick, protocolFee, lpFee\n     * @dev Corresponds to pools[poolId].slot0\n     * @param manager The pool manager contract.\n     * @param poolId The ID of the pool.\n     * @return sqrtPriceX96 The square root of the price of the pool, in Q96 precision.\n     * @return tick The current tick of the pool.\n     * @return protocolFee The protocol fee of the pool.\n     * @return lpFee The swap fee of the pool.\n     */\n    function getSlot0(IPoolManager manager, PoolId poolId)\n        internal\n        view\n        returns (uint160 sqrtPriceX96, int24 tick, uint24 protocolFee, uint24 lpFee)\n    {\n        // slot key of Pool.State value: `pools[poolId]`\n        bytes32 stateSlot = _getPoolStateSlot(poolId);\n\n        bytes32 data = manager.extsload(stateSlot);\n\n        //   24 bits  |24bits|24bits      |24 bits|160 bits\n        // 0x000000   |000bb8|000000      |ffff75 |0000000000000000fe3aa841ba359daa0ea9eff7\n        // ---------- | fee  |protocolfee | tick  | sqrtPriceX96\n        assembly (\"memory-safe\") {\n            // bottom 160 bits of data\n            sqrtPriceX96 := and(data, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)\n            // next 24 bits of data\n            tick := signextend(2, shr(160, data))\n            // next 24 bits of data\n            protocolFee := and(shr(184, data), 0xFFFFFF)\n            // last 24 bits of data\n            lpFee := and(shr(208, data), 0xFFFFFF)\n        }\n    }\n\n    /**\n     * @notice Retrieves the tick information of a pool at a specific tick.\n     * @dev Corresponds to pools[poolId].ticks[tick]\n     * @param manager The pool manager contract.\n     * @param poolId The ID of the pool.\n     * @param tick The tick to retrieve information for.\n     * @return liquidityGross The total position liquidity that references this tick\n     * @return liquidityNet The amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left)\n     * @return feeGrowthOutside0X128 fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)\n     * @return feeGrowthOutside1X128 fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)\n     */\n    function getTickInfo(IPoolManager manager, PoolId poolId, int24 tick)\n        internal\n        view\n        returns (\n            uint128 liquidityGross,\n            int128 liquidityNet,\n            uint256 feeGrowthOutside0X128,\n            uint256 feeGrowthOutside1X128\n        )\n    {\n        bytes32 slot = _getTickInfoSlot(poolId, tick);\n\n        // read all 3 words of the TickInfo struct\n        bytes32[] memory data = manager.extsload(slot, 3);\n        assembly (\"memory-safe\") {\n            let firstWord := mload(add(data, 32))\n            liquidityNet := sar(128, firstWord)\n            liquidityGross := and(firstWord, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)\n            feeGrowthOutside0X128 := mload(add(data, 64))\n            feeGrowthOutside1X128 := mload(add(data, 96))\n        }\n    }\n\n    /**\n     * @notice Retrieves the liquidity information of a pool at a specific tick.\n     * @dev Corresponds to pools[poolId].ticks[tick].liquidityGross and pools[poolId].ticks[tick].liquidityNet. A more gas efficient version of getTickInfo\n     * @param manager The pool manager contract.\n     * @param poolId The ID of the pool.\n     * @param tick The tick to retrieve liquidity for.\n     * @return liquidityGross The total position liquidity that references this tick\n     * @return liquidityNet The amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left)\n     */\n    function getTickLiquidity(IPoolManager manager, PoolId poolId, int24 tick)\n        internal\n        view\n        returns (uint128 liquidityGross, int128 liquidityNet)\n    {\n        bytes32 slot = _getTickInfoSlot(poolId, tick);\n\n        bytes32 value = manager.extsload(slot);\n        assembly (\"memory-safe\") {\n            liquidityNet := sar(128, value)\n            liquidityGross := and(value, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)\n        }\n    }\n\n    /**\n     * @notice Retrieves the fee growth outside a tick range of a pool\n     * @dev Corresponds to pools[poolId].ticks[tick].feeGrowthOutside0X128 and pools[poolId].ticks[tick].feeGrowthOutside1X128. A more gas efficient version of getTickInfo\n     * @param manager The pool manager contract.\n     * @param poolId The ID of the pool.\n     * @param tick The tick to retrieve fee growth for.\n     * @return feeGrowthOutside0X128 fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)\n     * @return feeGrowthOutside1X128 fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)\n     */\n    function getTickFeeGrowthOutside(IPoolManager manager, PoolId poolId, int24 tick)\n        internal\n        view\n        returns (uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128)\n    {\n        bytes32 slot = _getTickInfoSlot(poolId, tick);\n\n        // offset by 1 word, since the first word is liquidityGross + liquidityNet\n        bytes32[] memory data = manager.extsload(bytes32(uint256(slot) + 1), 2);\n        assembly (\"memory-safe\") {\n            feeGrowthOutside0X128 := mload(add(data, 32))\n            feeGrowthOutside1X128 := mload(add(data, 64))\n        }\n    }\n\n    /**\n     * @notice Retrieves the global fee growth of a pool.\n     * @dev Corresponds to pools[poolId].feeGrowthGlobal0X128 and pools[poolId].feeGrowthGlobal1X128\n     * @param manager The pool manager contract.\n     * @param poolId The ID of the pool.\n     * @return feeGrowthGlobal0 The global fee growth for token0.\n     * @return feeGrowthGlobal1 The global fee growth for token1.\n     * @dev Note that feeGrowthGlobal can be artificially inflated\n     * For pools with a single liquidity position, actors can donate to themselves to freely inflate feeGrowthGlobal\n     * atomically donating and collecting fees in the same unlockCallback may make the inflated value more extreme\n     */\n    function getFeeGrowthGlobals(IPoolManager manager, PoolId poolId)\n        internal\n        view\n        returns (uint256 feeGrowthGlobal0, uint256 feeGrowthGlobal1)\n    {\n        // slot key of Pool.State value: `pools[poolId]`\n        bytes32 stateSlot = _getPoolStateSlot(poolId);\n\n        // Pool.State, `uint256 feeGrowthGlobal0X128`\n        bytes32 slot_feeGrowthGlobal0X128 = bytes32(uint256(stateSlot) + FEE_GROWTH_GLOBAL0_OFFSET);\n\n        // read the 2 words of feeGrowthGlobal\n        bytes32[] memory data = manager.extsload(slot_feeGrowthGlobal0X128, 2);\n        assembly (\"memory-safe\") {\n            feeGrowthGlobal0 := mload(add(data, 32))\n            feeGrowthGlobal1 := mload(add(data, 64))\n        }\n    }\n\n    /**\n     * @notice Retrieves total the liquidity of a pool.\n     * @dev Corresponds to pools[poolId].liquidity\n     * @param manager The pool manager contract.\n     * @param poolId The ID of the pool.\n     * @return liquidity The liquidity of the pool.\n     */\n    function getLiquidity(IPoolManager manager, PoolId poolId) internal view returns (uint128 liquidity) {\n        // slot key of Pool.State value: `pools[poolId]`\n        bytes32 stateSlot = _getPoolStateSlot(poolId);\n\n        // Pool.State: `uint128 liquidity`\n        bytes32 slot = bytes32(uint256(stateSlot) + LIQUIDITY_OFFSET);\n\n        liquidity = uint128(uint256(manager.extsload(slot)));\n    }\n\n    /**\n     * @notice Retrieves the tick bitmap of a pool at a specific tick.\n     * @dev Corresponds to pools[poolId].tickBitmap[tick]\n     * @param manager The pool manager contract.\n     * @param poolId The ID of the pool.\n     * @param tick The tick to retrieve the bitmap for.\n     * @return tickBitmap The bitmap of the tick.\n     */\n    function getTickBitmap(IPoolManager manager, PoolId poolId, int16 tick)\n        internal\n        view\n        returns (uint256 tickBitmap)\n    {\n        // slot key of Pool.State value: `pools[poolId]`\n        bytes32 stateSlot = _getPoolStateSlot(poolId);\n\n        // Pool.State: `mapping(int16 => uint256) tickBitmap;`\n        bytes32 tickBitmapMapping = bytes32(uint256(stateSlot) + TICK_BITMAP_OFFSET);\n\n        // slot id of the mapping key: `pools[poolId].tickBitmap[tick]\n        bytes32 slot = keccak256(abi.encodePacked(int256(tick), tickBitmapMapping));\n\n        tickBitmap = uint256(manager.extsload(slot));\n    }\n\n    /**\n     * @notice Retrieves the position information of a pool without needing to calculate the `positionId`.\n     * @dev Corresponds to pools[poolId].positions[positionId]\n     * @param poolId The ID of the pool.\n     * @param owner The owner of the liquidity position.\n     * @param tickLower The lower tick of the liquidity range.\n     * @param tickUpper The upper tick of the liquidity range.\n     * @param salt The bytes32 randomness to further distinguish position state.\n     * @return liquidity The liquidity of the position.\n     * @return feeGrowthInside0LastX128 The fee growth inside the position for token0.\n     * @return feeGrowthInside1LastX128 The fee growth inside the position for token1.\n     */\n    function getPositionInfo(\n        IPoolManager manager,\n        PoolId poolId,\n        address owner,\n        int24 tickLower,\n        int24 tickUpper,\n        bytes32 salt\n    ) internal view returns (uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128) {\n        // positionKey = keccak256(abi.encodePacked(owner, tickLower, tickUpper, salt))\n        bytes32 positionKey = Position.calculatePositionKey(owner, tickLower, tickUpper, salt);\n\n        (liquidity, feeGrowthInside0LastX128, feeGrowthInside1LastX128) = getPositionInfo(manager, poolId, positionKey);\n    }\n\n    /**\n     * @notice Retrieves the position information of a pool at a specific position ID.\n     * @dev Corresponds to pools[poolId].positions[positionId]\n     * @param manager The pool manager contract.\n     * @param poolId The ID of the pool.\n     * @param positionId The ID of the position.\n     * @return liquidity The liquidity of the position.\n     * @return feeGrowthInside0LastX128 The fee growth inside the position for token0.\n     * @return feeGrowthInside1LastX128 The fee growth inside the position for token1.\n     */\n    function getPositionInfo(IPoolManager manager, PoolId poolId, bytes32 positionId)\n        internal\n        view\n        returns (uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128)\n    {\n        bytes32 slot = _getPositionInfoSlot(poolId, positionId);\n\n        // read all 3 words of the Position.State struct\n        bytes32[] memory data = manager.extsload(slot, 3);\n\n        assembly (\"memory-safe\") {\n            liquidity := mload(add(data, 32))\n            feeGrowthInside0LastX128 := mload(add(data, 64))\n            feeGrowthInside1LastX128 := mload(add(data, 96))\n        }\n    }\n\n    /**\n     * @notice Retrieves the liquidity of a position.\n     * @dev Corresponds to pools[poolId].positions[positionId].liquidity. More gas efficient for just retrieiving liquidity as compared to getPositionInfo\n     * @param manager The pool manager contract.\n     * @param poolId The ID of the pool.\n     * @param positionId The ID of the position.\n     * @return liquidity The liquidity of the position.\n     */\n    function getPositionLiquidity(IPoolManager manager, PoolId poolId, bytes32 positionId)\n        internal\n        view\n        returns (uint128 liquidity)\n    {\n        bytes32 slot = _getPositionInfoSlot(poolId, positionId);\n        liquidity = uint128(uint256(manager.extsload(slot)));\n    }\n\n    /**\n     * @notice Calculate the fee growth inside a tick range of a pool\n     * @dev pools[poolId].feeGrowthInside0LastX128 in Position.State is cached and can become stale. This function will calculate the up to date feeGrowthInside\n     * @param manager The pool manager contract.\n     * @param poolId The ID of the pool.\n     * @param tickLower The lower tick of the range.\n     * @param tickUpper The upper tick of the range.\n     * @return feeGrowthInside0X128 The fee growth inside the tick range for token0.\n     * @return feeGrowthInside1X128 The fee growth inside the tick range for token1.\n     */\n    function getFeeGrowthInside(IPoolManager manager, PoolId poolId, int24 tickLower, int24 tickUpper)\n        internal\n        view\n        returns (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128)\n    {\n        (uint256 feeGrowthGlobal0X128, uint256 feeGrowthGlobal1X128) = getFeeGrowthGlobals(manager, poolId);\n\n        (uint256 lowerFeeGrowthOutside0X128, uint256 lowerFeeGrowthOutside1X128) =\n            getTickFeeGrowthOutside(manager, poolId, tickLower);\n        (uint256 upperFeeGrowthOutside0X128, uint256 upperFeeGrowthOutside1X128) =\n            getTickFeeGrowthOutside(manager, poolId, tickUpper);\n        (, int24 tickCurrent,,) = getSlot0(manager, poolId);\n        unchecked {\n            if (tickCurrent < tickLower) {\n                feeGrowthInside0X128 = lowerFeeGrowthOutside0X128 - upperFeeGrowthOutside0X128;\n                feeGrowthInside1X128 = lowerFeeGrowthOutside1X128 - upperFeeGrowthOutside1X128;\n            } else if (tickCurrent >= tickUpper) {\n                feeGrowthInside0X128 = upperFeeGrowthOutside0X128 - lowerFeeGrowthOutside0X128;\n                feeGrowthInside1X128 = upperFeeGrowthOutside1X128 - lowerFeeGrowthOutside1X128;\n            } else {\n                feeGrowthInside0X128 = feeGrowthGlobal0X128 - lowerFeeGrowthOutside0X128 - upperFeeGrowthOutside0X128;\n                feeGrowthInside1X128 = feeGrowthGlobal1X128 - lowerFeeGrowthOutside1X128 - upperFeeGrowthOutside1X128;\n            }\n        }\n    }\n\n    function _getPoolStateSlot(PoolId poolId) internal pure returns (bytes32) {\n        return keccak256(abi.encodePacked(PoolId.unwrap(poolId), POOLS_SLOT));\n    }\n\n    function _getTickInfoSlot(PoolId poolId, int24 tick) internal pure returns (bytes32) {\n        // slot key of Pool.State value: `pools[poolId]`\n        bytes32 stateSlot = _getPoolStateSlot(poolId);\n\n        // Pool.State: `mapping(int24 => TickInfo) ticks`\n        bytes32 ticksMappingSlot = bytes32(uint256(stateSlot) + TICKS_OFFSET);\n\n        // slot key of the tick key: `pools[poolId].ticks[tick]\n        return keccak256(abi.encodePacked(int256(tick), ticksMappingSlot));\n    }\n\n    function _getPositionInfoSlot(PoolId poolId, bytes32 positionId) internal pure returns (bytes32) {\n        // slot key of Pool.State value: `pools[poolId]`\n        bytes32 stateSlot = _getPoolStateSlot(poolId);\n\n        // Pool.State: `mapping(bytes32 => Position.State) positions;`\n        bytes32 positionMapping = bytes32(uint256(stateSlot) + POSITIONS_OFFSET);\n\n        // slot of the mapping key: `pools[poolId].positions[positionId]\n        return keccak256(abi.encodePacked(positionId, positionMapping));\n    }\n}\n"},{"file_path":"lib/v4-core/src/libraries/TickMath.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport {BitMath} from \"./BitMath.sol\";\nimport {CustomRevert} from \"./CustomRevert.sol\";\n\n/// @title Math library for computing sqrt prices from ticks and vice versa\n/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports\n/// prices between 2**-128 and 2**128\nlibrary TickMath {\n    using CustomRevert for bytes4;\n\n    /// @notice Thrown when the tick passed to #getSqrtPriceAtTick is not between MIN_TICK and MAX_TICK\n    error InvalidTick(int24 tick);\n    /// @notice Thrown when the price passed to #getTickAtSqrtPrice does not correspond to a price between MIN_TICK and MAX_TICK\n    error InvalidSqrtPrice(uint160 sqrtPriceX96);\n\n    /// @dev The minimum tick that may be passed to #getSqrtPriceAtTick computed from log base 1.0001 of 2**-128\n    /// @dev If ever MIN_TICK and MAX_TICK are not centered around 0, the absTick logic in getSqrtPriceAtTick cannot be used\n    int24 internal constant MIN_TICK = -887272;\n    /// @dev The maximum tick that may be passed to #getSqrtPriceAtTick computed from log base 1.0001 of 2**128\n    /// @dev If ever MIN_TICK and MAX_TICK are not centered around 0, the absTick logic in getSqrtPriceAtTick cannot be used\n    int24 internal constant MAX_TICK = 887272;\n\n    /// @dev The minimum tick spacing value drawn from the range of type int16 that is greater than 0, i.e. min from the range [1, 32767]\n    int24 internal constant MIN_TICK_SPACING = 1;\n    /// @dev The maximum tick spacing value drawn from the range of type int16, i.e. max from the range [1, 32767]\n    int24 internal constant MAX_TICK_SPACING = type(int16).max;\n\n    /// @dev The minimum value that can be returned from #getSqrtPriceAtTick. Equivalent to getSqrtPriceAtTick(MIN_TICK)\n    uint160 internal constant MIN_SQRT_PRICE = 4295128739;\n    /// @dev The maximum value that can be returned from #getSqrtPriceAtTick. Equivalent to getSqrtPriceAtTick(MAX_TICK)\n    uint160 internal constant MAX_SQRT_PRICE = 1461446703485210103287273052203988822378723970342;\n    /// @dev A threshold used for optimized bounds check, equals `MAX_SQRT_PRICE - MIN_SQRT_PRICE - 1`\n    uint160 internal constant MAX_SQRT_PRICE_MINUS_MIN_SQRT_PRICE_MINUS_ONE =\n        1461446703485210103287273052203988822378723970342 - 4295128739 - 1;\n\n    /// @notice Given a tickSpacing, compute the maximum usable tick\n    function maxUsableTick(int24 tickSpacing) internal pure returns (int24) {\n        unchecked {\n            return (MAX_TICK / tickSpacing) * tickSpacing;\n        }\n    }\n\n    /// @notice Given a tickSpacing, compute the minimum usable tick\n    function minUsableTick(int24 tickSpacing) internal pure returns (int24) {\n        unchecked {\n            return (MIN_TICK / tickSpacing) * tickSpacing;\n        }\n    }\n\n    /// @notice Calculates sqrt(1.0001^tick) * 2^96\n    /// @dev Throws if |tick| > max tick\n    /// @param tick The input tick for the above formula\n    /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the price of the two assets (currency1/currency0)\n    /// at the given tick\n    function getSqrtPriceAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {\n        unchecked {\n            uint256 absTick;\n            assembly (\"memory-safe\") {\n                tick := signextend(2, tick)\n                // mask = 0 if tick >= 0 else -1 (all 1s)\n                let mask := sar(255, tick)\n                // if tick >= 0, |tick| = tick = 0 ^ tick\n                // if tick < 0, |tick| = ~~|tick| = ~(-|tick| - 1) = ~(tick - 1) = (-1) ^ (tick - 1)\n                // either way, |tick| = mask ^ (tick + mask)\n                absTick := xor(mask, add(mask, tick))\n            }\n\n            if (absTick > uint256(int256(MAX_TICK))) InvalidTick.selector.revertWith(tick);\n\n            // The tick is decomposed into bits, and for each bit with index i that is set, the product of 1/sqrt(1.0001^(2^i))\n            // is calculated (using Q128.128). The constants used for this calculation are rounded to the nearest integer\n\n            // Equivalent to:\n            //     price = absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000;\n            //     or price = int(2**128 / sqrt(1.0001)) if (absTick & 0x1) else 1 << 128\n            uint256 price;\n            assembly (\"memory-safe\") {\n                price := xor(shl(128, 1), mul(xor(shl(128, 1), 0xfffcb933bd6fad37aa2d162d1a594001), and(absTick, 0x1)))\n            }\n            if (absTick & 0x2 != 0) price = (price * 0xfff97272373d413259a46990580e213a) >> 128;\n            if (absTick & 0x4 != 0) price = (price * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128;\n            if (absTick & 0x8 != 0) price = (price * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128;\n            if (absTick & 0x10 != 0) price = (price * 0xffcb9843d60f6159c9db58835c926644) >> 128;\n            if (absTick & 0x20 != 0) price = (price * 0xff973b41fa98c081472e6896dfb254c0) >> 128;\n            if (absTick & 0x40 != 0) price = (price * 0xff2ea16466c96a3843ec78b326b52861) >> 128;\n            if (absTick & 0x80 != 0) price = (price * 0xfe5dee046a99a2a811c461f1969c3053) >> 128;\n            if (absTick & 0x100 != 0) price = (price * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128;\n            if (absTick & 0x200 != 0) price = (price * 0xf987a7253ac413176f2b074cf7815e54) >> 128;\n            if (absTick & 0x400 != 0) price = (price * 0xf3392b0822b70005940c7a398e4b70f3) >> 128;\n            if (absTick & 0x800 != 0) price = (price * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128;\n            if (absTick & 0x1000 != 0) price = (price * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;\n            if (absTick & 0x2000 != 0) price = (price * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128;\n            if (absTick & 0x4000 != 0) price = (price * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128;\n            if (absTick & 0x8000 != 0) price = (price * 0x31be135f97d08fd981231505542fcfa6) >> 128;\n            if (absTick & 0x10000 != 0) price = (price * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128;\n            if (absTick & 0x20000 != 0) price = (price * 0x5d6af8dedb81196699c329225ee604) >> 128;\n            if (absTick & 0x40000 != 0) price = (price * 0x2216e584f5fa1ea926041bedfe98) >> 128;\n            if (absTick & 0x80000 != 0) price = (price * 0x48a170391f7dc42444e8fa2) >> 128;\n\n            assembly (\"memory-safe\") {\n                // if (tick > 0) price = type(uint256).max / price;\n                if sgt(tick, 0) { price := div(not(0), price) }\n\n                // this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96.\n                // we then downcast because we know the result always fits within 160 bits due to our tick input constraint\n                // we round up in the division so getTickAtSqrtPrice of the output price is always consistent\n                // `sub(shl(32, 1), 1)` is `type(uint32).max`\n                // `price + type(uint32).max` will not overflow because `price` fits in 192 bits\n                sqrtPriceX96 := shr(32, add(price, sub(shl(32, 1), 1)))\n            }\n        }\n    }\n\n    /// @notice Calculates the greatest tick value such that getSqrtPriceAtTick(tick) <= sqrtPriceX96\n    /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_PRICE, as MIN_SQRT_PRICE is the lowest value getSqrtPriceAtTick may\n    /// ever return.\n    /// @param sqrtPriceX96 The sqrt price for which to compute the tick as a Q64.96\n    /// @return tick The greatest tick for which the getSqrtPriceAtTick(tick) is less than or equal to the input sqrtPriceX96\n    function getTickAtSqrtPrice(uint160 sqrtPriceX96) internal pure returns (int24 tick) {\n        unchecked {\n            // Equivalent: if (sqrtPriceX96 < MIN_SQRT_PRICE || sqrtPriceX96 >= MAX_SQRT_PRICE) revert InvalidSqrtPrice();\n            // second inequality must be >= because the price can never reach the price at the max tick\n            // if sqrtPriceX96 < MIN_SQRT_PRICE, the `sub` underflows and `gt` is true\n            // if sqrtPriceX96 >= MAX_SQRT_PRICE, sqrtPriceX96 - MIN_SQRT_PRICE > MAX_SQRT_PRICE - MIN_SQRT_PRICE - 1\n            if ((sqrtPriceX96 - MIN_SQRT_PRICE) > MAX_SQRT_PRICE_MINUS_MIN_SQRT_PRICE_MINUS_ONE) {\n                InvalidSqrtPrice.selector.revertWith(sqrtPriceX96);\n            }\n\n            uint256 price = uint256(sqrtPriceX96) << 32;\n\n            uint256 r = price;\n            uint256 msb = BitMath.mostSignificantBit(r);\n\n            if (msb >= 128) r = price >> (msb - 127);\n            else r = price << (127 - msb);\n\n            int256 log_2 = (int256(msb) - 128) << 64;\n\n            assembly (\"memory-safe\") {\n                r := shr(127, mul(r, r))\n                let f := shr(128, r)\n                log_2 := or(log_2, shl(63, f))\n                r := shr(f, r)\n            }\n            assembly (\"memory-safe\") {\n                r := shr(127, mul(r, r))\n                let f := shr(128, r)\n                log_2 := or(log_2, shl(62, f))\n                r := shr(f, r)\n            }\n            assembly (\"memory-safe\") {\n                r := shr(127, mul(r, r))\n                let f := shr(128, r)\n                log_2 := or(log_2, shl(61, f))\n                r := shr(f, r)\n            }\n            assembly (\"memory-safe\") {\n                r := shr(127, mul(r, r))\n                let f := shr(128, r)\n                log_2 := or(log_2, shl(60, f))\n                r := shr(f, r)\n            }\n            assembly (\"memory-safe\") {\n                r := shr(127, mul(r, r))\n                let f := shr(128, r)\n                log_2 := or(log_2, shl(59, f))\n                r := shr(f, r)\n            }\n            assembly (\"memory-safe\") {\n                r := shr(127, mul(r, r))\n                let f := shr(128, r)\n                log_2 := or(log_2, shl(58, f))\n                r := shr(f, r)\n            }\n            assembly (\"memory-safe\") {\n                r := shr(127, mul(r, r))\n                let f := shr(128, r)\n                log_2 := or(log_2, shl(57, f))\n                r := shr(f, r)\n            }\n            assembly (\"memory-safe\") {\n                r := shr(127, mul(r, r))\n                let f := shr(128, r)\n                log_2 := or(log_2, shl(56, f))\n                r := shr(f, r)\n            }\n            assembly (\"memory-safe\") {\n                r := shr(127, mul(r, r))\n                let f := shr(128, r)\n                log_2 := or(log_2, shl(55, f))\n                r := shr(f, r)\n            }\n            assembly (\"memory-safe\") {\n                r := shr(127, mul(r, r))\n                let f := shr(128, r)\n                log_2 := or(log_2, shl(54, f))\n                r := shr(f, r)\n            }\n            assembly (\"memory-safe\") {\n                r := shr(127, mul(r, r))\n                let f := shr(128, r)\n                log_2 := or(log_2, shl(53, f))\n                r := shr(f, r)\n            }\n            assembly (\"memory-safe\") {\n                r := shr(127, mul(r, r))\n                let f := shr(128, r)\n                log_2 := or(log_2, shl(52, f))\n                r := shr(f, r)\n            }\n            assembly (\"memory-safe\") {\n                r := shr(127, mul(r, r))\n                let f := shr(128, r)\n                log_2 := or(log_2, shl(51, f))\n                r := shr(f, r)\n            }\n            assembly (\"memory-safe\") {\n                r := shr(127, mul(r, r))\n                let f := shr(128, r)\n                log_2 := or(log_2, shl(50, f))\n            }\n\n            int256 log_sqrt10001 = log_2 * 255738958999603826347141; // Q22.128 number\n\n            // Magic number represents the ceiling of the maximum value of the error when approximating log_sqrt10001(x)\n            int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128);\n\n            // Magic number represents the minimum value of the error when approximating log_sqrt10001(x), when\n            // sqrtPrice is from the range (2^-64, 2^64). This is safe as MIN_SQRT_PRICE is more than 2^-64. If MIN_SQRT_PRICE\n            // is changed, this may need to be changed too\n            int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128);\n\n            tick = tickLow == tickHi ? tickLow : getSqrtPriceAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow;\n        }\n    }\n}\n"},{"file_path":"lib/v4-core/src/libraries/UnsafeMath.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\n/// @title Math functions that do not check inputs or outputs\n/// @notice Contains methods that perform common math functions but do not do any overflow or underflow checks\nlibrary UnsafeMath {\n    /// @notice Returns ceil(x / y)\n    /// @dev division by 0 will return 0, and should be checked externally\n    /// @param x The dividend\n    /// @param y The divisor\n    /// @return z The quotient, ceil(x / y)\n    function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) {\n        assembly (\"memory-safe\") {\n            z := add(div(x, y), gt(mod(x, y), 0))\n        }\n    }\n\n    /// @notice Calculates floor(a×b÷denominator)\n    /// @dev division by 0 will return 0, and should be checked externally\n    /// @param a The multiplicand\n    /// @param b The multiplier\n    /// @param denominator The divisor\n    /// @return result The 256-bit result, floor(a×b÷denominator)\n    function simpleMulDiv(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) {\n        assembly (\"memory-safe\") {\n            result := div(mul(a, b), denominator)\n        }\n    }\n}\n"},{"file_path":"lib/v4-core/src/types/BalanceDelta.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport {SafeCast} from \"../libraries/SafeCast.sol\";\n\n/// @dev Two `int128` values packed into a single `int256` where the upper 128 bits represent the amount0\n/// and the lower 128 bits represent the amount1.\ntype BalanceDelta is int256;\n\nusing {add as +, sub as -, eq as ==, neq as !=} for BalanceDelta global;\nusing BalanceDeltaLibrary for BalanceDelta global;\nusing SafeCast for int256;\n\nfunction toBalanceDelta(int128 _amount0, int128 _amount1) pure returns (BalanceDelta balanceDelta) {\n    assembly (\"memory-safe\") {\n        balanceDelta := or(shl(128, _amount0), and(sub(shl(128, 1), 1), _amount1))\n    }\n}\n\nfunction add(BalanceDelta a, BalanceDelta b) pure returns (BalanceDelta) {\n    int256 res0;\n    int256 res1;\n    assembly (\"memory-safe\") {\n        let a0 := sar(128, a)\n        let a1 := signextend(15, a)\n        let b0 := sar(128, b)\n        let b1 := signextend(15, b)\n        res0 := add(a0, b0)\n        res1 := add(a1, b1)\n    }\n    return toBalanceDelta(res0.toInt128(), res1.toInt128());\n}\n\nfunction sub(BalanceDelta a, BalanceDelta b) pure returns (BalanceDelta) {\n    int256 res0;\n    int256 res1;\n    assembly (\"memory-safe\") {\n        let a0 := sar(128, a)\n        let a1 := signextend(15, a)\n        let b0 := sar(128, b)\n        let b1 := signextend(15, b)\n        res0 := sub(a0, b0)\n        res1 := sub(a1, b1)\n    }\n    return toBalanceDelta(res0.toInt128(), res1.toInt128());\n}\n\nfunction eq(BalanceDelta a, BalanceDelta b) pure returns (bool) {\n    return BalanceDelta.unwrap(a) == BalanceDelta.unwrap(b);\n}\n\nfunction neq(BalanceDelta a, BalanceDelta b) pure returns (bool) {\n    return BalanceDelta.unwrap(a) != BalanceDelta.unwrap(b);\n}\n\n/// @notice Library for getting the amount0 and amount1 deltas from the BalanceDelta type\nlibrary BalanceDeltaLibrary {\n    /// @notice A BalanceDelta of 0\n    BalanceDelta public constant ZERO_DELTA = BalanceDelta.wrap(0);\n\n    function amount0(BalanceDelta balanceDelta) internal pure returns (int128 _amount0) {\n        assembly (\"memory-safe\") {\n            _amount0 := sar(128, balanceDelta)\n        }\n    }\n\n    function amount1(BalanceDelta balanceDelta) internal pure returns (int128 _amount1) {\n        assembly (\"memory-safe\") {\n            _amount1 := signextend(15, balanceDelta)\n        }\n    }\n}\n"},{"file_path":"lib/v4-core/src/types/BeforeSwapDelta.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\n// Return type of the beforeSwap hook.\n// Upper 128 bits is the delta in specified tokens. Lower 128 bits is delta in unspecified tokens (to match the afterSwap hook)\ntype BeforeSwapDelta is int256;\n\n// Creates a BeforeSwapDelta from specified and unspecified\nfunction toBeforeSwapDelta(int128 deltaSpecified, int128 deltaUnspecified)\n    pure\n    returns (BeforeSwapDelta beforeSwapDelta)\n{\n    assembly (\"memory-safe\") {\n        beforeSwapDelta := or(shl(128, deltaSpecified), and(sub(shl(128, 1), 1), deltaUnspecified))\n    }\n}\n\n/// @notice Library for getting the specified and unspecified deltas from the BeforeSwapDelta type\nlibrary BeforeSwapDeltaLibrary {\n    /// @notice A BeforeSwapDelta of 0\n    BeforeSwapDelta public constant ZERO_DELTA = BeforeSwapDelta.wrap(0);\n\n    /// extracts int128 from the upper 128 bits of the BeforeSwapDelta\n    /// returned by beforeSwap\n    function getSpecifiedDelta(BeforeSwapDelta delta) internal pure returns (int128 deltaSpecified) {\n        assembly (\"memory-safe\") {\n            deltaSpecified := sar(128, delta)\n        }\n    }\n\n    /// extracts int128 from the lower 128 bits of the BeforeSwapDelta\n    /// returned by beforeSwap and afterSwap\n    function getUnspecifiedDelta(BeforeSwapDelta delta) internal pure returns (int128 deltaUnspecified) {\n        assembly (\"memory-safe\") {\n            deltaUnspecified := signextend(15, delta)\n        }\n    }\n}\n"},{"file_path":"lib/v4-core/src/types/Currency.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport {IERC20Minimal} from \"../interfaces/external/IERC20Minimal.sol\";\nimport {CustomRevert} from \"../libraries/CustomRevert.sol\";\n\ntype Currency is address;\n\nusing {greaterThan as >, lessThan as <, greaterThanOrEqualTo as >=, equals as ==} for Currency global;\nusing CurrencyLibrary for Currency global;\n\nfunction equals(Currency currency, Currency other) pure returns (bool) {\n    return Currency.unwrap(currency) == Currency.unwrap(other);\n}\n\nfunction greaterThan(Currency currency, Currency other) pure returns (bool) {\n    return Currency.unwrap(currency) > Currency.unwrap(other);\n}\n\nfunction lessThan(Currency currency, Currency other) pure returns (bool) {\n    return Currency.unwrap(currency) < Currency.unwrap(other);\n}\n\nfunction greaterThanOrEqualTo(Currency currency, Currency other) pure returns (bool) {\n    return Currency.unwrap(currency) >= Currency.unwrap(other);\n}\n\n/// @title CurrencyLibrary\n/// @dev This library allows for transferring and holding native tokens and ERC20 tokens\nlibrary CurrencyLibrary {\n    /// @notice Additional context for ERC-7751 wrapped error when a native transfer fails\n    error NativeTransferFailed();\n\n    /// @notice Additional context for ERC-7751 wrapped error when an ERC20 transfer fails\n    error ERC20TransferFailed();\n\n    /// @notice A constant to represent the native currency\n    Currency public constant ADDRESS_ZERO = Currency.wrap(address(0));\n\n    function transfer(Currency currency, address to, uint256 amount) internal {\n        // altered from https://github.com/transmissions11/solmate/blob/44a9963d4c78111f77caa0e65d677b8b46d6f2e6/src/utils/SafeTransferLib.sol\n        // modified custom error selectors\n\n        bool success;\n        if (currency.isAddressZero()) {\n            assembly (\"memory-safe\") {\n                // Transfer the ETH and revert if it fails.\n                success := call(gas(), to, amount, 0, 0, 0, 0)\n            }\n            // revert with NativeTransferFailed, containing the bubbled up error as an argument\n            if (!success) {\n                CustomRevert.bubbleUpAndRevertWith(to, bytes4(0), NativeTransferFailed.selector);\n            }\n        } else {\n            assembly (\"memory-safe\") {\n                // Get a pointer to some free memory.\n                let fmp := mload(0x40)\n\n                // Write the abi-encoded calldata into memory, beginning with the function selector.\n                mstore(fmp, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)\n                mstore(add(fmp, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the \"to\" argument.\n                mstore(add(fmp, 36), amount) // Append the \"amount\" argument. Masking not required as it's a full 32 byte type.\n\n                success :=\n                    and(\n                        // Set success to whether the call reverted, if not we check it either\n                        // returned exactly 1 (can't just be non-zero data), or had no return data.\n                        or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),\n                        // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.\n                        // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.\n                        // Counterintuitively, this call must be positioned second to the or() call in the\n                        // surrounding and() call or else returndatasize() will be zero during the computation.\n                        call(gas(), currency, 0, fmp, 68, 0, 32)\n                    )\n\n                // Now clean the memory we used\n                mstore(fmp, 0) // 4 byte `selector` and 28 bytes of `to` were stored here\n                mstore(add(fmp, 0x20), 0) // 4 bytes of `to` and 28 bytes of `amount` were stored here\n                mstore(add(fmp, 0x40), 0) // 4 bytes of `amount` were stored here\n            }\n            // revert with ERC20TransferFailed, containing the bubbled up error as an argument\n            if (!success) {\n                CustomRevert.bubbleUpAndRevertWith(\n                    Currency.unwrap(currency), IERC20Minimal.transfer.selector, ERC20TransferFailed.selector\n                );\n            }\n        }\n    }\n\n    function balanceOfSelf(Currency currency) internal view returns (uint256) {\n        if (currency.isAddressZero()) {\n            return address(this).balance;\n        } else {\n            return IERC20Minimal(Currency.unwrap(currency)).balanceOf(address(this));\n        }\n    }\n\n    function balanceOf(Currency currency, address owner) internal view returns (uint256) {\n        if (currency.isAddressZero()) {\n            return owner.balance;\n        } else {\n            return IERC20Minimal(Currency.unwrap(currency)).balanceOf(owner);\n        }\n    }\n\n    function isAddressZero(Currency currency) internal pure returns (bool) {\n        return Currency.unwrap(currency) == Currency.unwrap(ADDRESS_ZERO);\n    }\n\n    function toId(Currency currency) internal pure returns (uint256) {\n        return uint160(Currency.unwrap(currency));\n    }\n\n    // If the upper 12 bytes are non-zero, they will be zero-ed out\n    // Therefore, fromId() and toId() are not inverses of each other\n    function fromId(uint256 id) internal pure returns (Currency) {\n        return Currency.wrap(address(uint160(id)));\n    }\n}\n"},{"file_path":"lib/v4-core/src/types/PoolId.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport {PoolKey} from \"./PoolKey.sol\";\n\ntype PoolId is bytes32;\n\n/// @notice Library for computing the ID of a pool\nlibrary PoolIdLibrary {\n    /// @notice Returns value equal to keccak256(abi.encode(poolKey))\n    function toId(PoolKey memory poolKey) internal pure returns (PoolId poolId) {\n        assembly (\"memory-safe\") {\n            // 0xa0 represents the total size of the poolKey struct (5 slots of 32 bytes)\n            poolId := keccak256(poolKey, 0xa0)\n        }\n    }\n}\n"},{"file_path":"lib/v4-core/src/types/PoolKey.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport {Currency} from \"./Currency.sol\";\nimport {IHooks} from \"../interfaces/IHooks.sol\";\nimport {PoolIdLibrary} from \"./PoolId.sol\";\n\nusing PoolIdLibrary for PoolKey global;\n\n/// @notice Returns the key for identifying a pool\nstruct PoolKey {\n    /// @notice The lower currency of the pool, sorted numerically\n    Currency currency0;\n    /// @notice The higher currency of the pool, sorted numerically\n    Currency currency1;\n    /// @notice The pool LP fee, capped at 1_000_000. If the highest bit is 1, the pool has a dynamic fee and must be exactly equal to 0x800000\n    uint24 fee;\n    /// @notice Ticks that involve positions must be a multiple of tick spacing\n    int24 tickSpacing;\n    /// @notice The hooks of the pool\n    IHooks hooks;\n}\n"}],"certified":false,"conflicting_implementations":null,"abi":[{"inputs":[{"internalType":"address","name":"owner_","type":"address"},{"internalType":"contract IPoolManager","name":"poolManager_","type":"address"},{"internalType":"address","name":"token_","type":"address"},{"internalType":"address","name":"burnSink_","type":"address"},{"internalType":"address","name":"rewardsRecipient_","type":"address"},{"internalType":"uint256","name":"rewardShareBps_","type":"uint256"},{"internalType":"uint256","name":"minTrimTokens_","type":"uint256"},{"internalType":"uint24","name":"lpFee_","type":"uint24"},{"internalType":"int24","name":"tickSpacing_","type":"int24"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyInitialized","type":"error"},{"inputs":[],"name":"AlreadyOpen","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokensRequired","type":"uint256"}],"name":"BidNotSingleSided","type":"error"},{"inputs":[],"name":"CallbackNotExpected","type":"error"},{"inputs":[{"internalType":"uint256","name":"required","type":"uint256"},{"internalType":"uint256","name":"supplied","type":"uint256"}],"name":"IncorrectEthAmount","type":"error"},{"inputs":[],"name":"InitializationRestrictedToHook","type":"error"},{"inputs":[{"internalType":"uint256","name":"requested","type":"uint256"},{"internalType":"uint256","name":"available","type":"uint256"}],"name":"InsufficientRetainedEth","type":"error"},{"inputs":[],"name":"InvalidConfiguration","type":"error"},{"inputs":[],"name":"InvalidLiquidity","type":"error"},{"inputs":[],"name":"InvalidPool","type":"error"},{"inputs":[],"name":"InvalidPoolManagerCaller","type":"error"},{"inputs":[],"name":"LiquidityRestrictedToHook","type":"error"},{"inputs":[],"name":"MarketNotOpen","type":"error"},{"inputs":[],"name":"NewOwnerIsZeroAddress","type":"error"},{"inputs":[],"name":"NoHandoverRequest","type":"error"},{"inputs":[],"name":"NotSelf","type":"error"},{"inputs":[],"name":"PoolNotInitialized","type":"error"},{"inputs":[{"internalType":"uint160","name":"before_","type":"uint160"},{"internalType":"uint160","name":"after_","type":"uint160"}],"name":"PriceMovedDuringLiquidityChange","type":"error"},{"inputs":[],"name":"RebalanceDisabled","type":"error"},{"inputs":[],"name":"RebalanceNotNeeded","type":"error"},{"inputs":[{"internalType":"uint256","name":"required","type":"uint256"},{"internalType":"uint256","name":"maximum","type":"uint256"}],"name":"TokenAmountExceeded","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"inputs":[],"name":"UnexpectedLiquidityDelta","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int24","name":"tickLower","type":"int24"},{"indexed":false,"internalType":"int24","name":"tickUpper","type":"int24"},{"indexed":false,"internalType":"uint128","name":"liquidity","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"ethDeployed","type":"uint256"}],"name":"BackstopDeployed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint128","name":"liquidity","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"tokensBurned","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokensRewarded","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"ethReturned","type":"uint256"}],"name":"BackstopSettled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previous","type":"address"},{"indexed":true,"internalType":"address","name":"current","type":"address"}],"name":"BurnSinkUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokensPerDay","type":"uint256"}],"name":"CapDecayUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"previousFloor","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newFloor","type":"uint256"}],"name":"CapFloorUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"previousCap","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newCap","type":"uint256"}],"name":"CapRatcheted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokensToBurnSink","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokensToRewards","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"ethRedeemed","type":"uint256"}],"name":"ClaimsSettled","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int24","name":"previousFloor","type":"int24"},{"indexed":false,"internalType":"int24","name":"newFloor","type":"int24"}],"name":"DeploymentFloorUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"ethFee","type":"uint256"}],"name":"FeeCollected","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"ethAmount","type":"uint256"}],"name":"FeesWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"ticksPerDay","type":"uint256"}],"name":"FloorDecayUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint128","name":"liquidity","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"ethDeposited","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokensDeposited","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newCap","type":"uint256"}],"name":"InventoryFunded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"keeper","type":"address"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"}],"name":"KeeperRewardPaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"}],"name":"KeeperRewardUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"ethReturned","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokensReturned","type":"uint256"}],"name":"MarketClosed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint128","name":"liquidity","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"ethDeposited","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"inventoryCap","type":"uint256"}],"name":"MarketOpened","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int24","name":"maxStep","type":"int24"}],"name":"MaxRefStepUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint160","name":"sqrtPriceX96","type":"uint160"},{"indexed":false,"internalType":"int24","name":"tick","type":"int24"}],"name":"PoolInitialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"previousBps","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newBps","type":"uint256"}],"name":"RatchetUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"enabled","type":"bool"},{"indexed":false,"internalType":"uint256","name":"ethThreshold","type":"uint256"}],"name":"RebalanceConfigUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"int24","name":"lower","type":"int24"}],"name":"Rebalanced","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"RetainedEthWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"previousBps","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newBps","type":"uint256"}],"name":"RewardShareUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previous","type":"address"},{"indexed":true,"internalType":"address","name":"current","type":"address"}],"name":"RewardsRecipientUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint128","name":"liquidityRemoved","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"tokensBurned","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokensRewarded","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"ethRetained","type":"uint256"}],"name":"Trimmed","type":"event"},{"inputs":[],"name":"BPS_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_CAP_DECAY_PER_DAY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"key","type":"tuple"},{"components":[{"internalType":"bool","name":"zeroForOne","type":"bool"},{"internalType":"int256","name":"amountSpecified","type":"int256"},{"internalType":"uint160","name":"sqrtPriceLimitX96","type":"uint160"}],"internalType":"struct IPoolManager.SwapParams","name":"","type":"tuple"},{"internalType":"BalanceDelta","name":"","type":"int256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"afterSwap","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"},{"internalType":"int128","name":"","type":"int128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"backstop","outputs":[{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint128","name":"liquidity","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"backstopConvertedEth","outputs":[{"internalType":"uint256","name":"converted","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"backstopEthPrincipal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"backstopFillThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"backstopIsFilled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"key","type":"tuple"},{"components":[{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"int256","name":"liquidityDelta","type":"int256"},{"internalType":"bytes32","name":"salt","type":"bytes32"}],"internalType":"struct IPoolManager.ModifyLiquidityParams","name":"","type":"tuple"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"beforeAddLiquidity","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"key","type":"tuple"},{"internalType":"uint160","name":"","type":"uint160"}],"name":"beforeInitialize","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"burnClaims","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"burnSink","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cancelOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"capDecayRemainder","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"capDecayTokensPerDay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"capFloor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"closeBackstop","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"closeBackstopSelf","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"}],"name":"closeMarket","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"completeOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"currentSqrtPriceX96","outputs":[{"internalType":"uint160","name":"sqrtPriceX96","type":"uint160"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentTick","outputs":[{"internalType":"int24","name":"tick","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"deploymentFloorTick","outputs":[{"internalType":"int24","name":"","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ethClaims","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ethInPool","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeEthClaims","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeTokenClaims","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"floorDecayTicksPerDay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"maximumTokenAmount","type":"uint256"}],"name":"fundInventory","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"getHookPermissions","outputs":[{"components":[{"internalType":"bool","name":"beforeInitialize","type":"bool"},{"internalType":"bool","name":"afterInitialize","type":"bool"},{"internalType":"bool","name":"beforeAddLiquidity","type":"bool"},{"internalType":"bool","name":"afterAddLiquidity","type":"bool"},{"internalType":"bool","name":"beforeRemoveLiquidity","type":"bool"},{"internalType":"bool","name":"afterRemoveLiquidity","type":"bool"},{"internalType":"bool","name":"beforeSwap","type":"bool"},{"internalType":"bool","name":"afterSwap","type":"bool"},{"internalType":"bool","name":"beforeDonate","type":"bool"},{"internalType":"bool","name":"afterDonate","type":"bool"},{"internalType":"bool","name":"beforeSwapReturnDelta","type":"bool"},{"internalType":"bool","name":"afterSwapReturnDelta","type":"bool"},{"internalType":"bool","name":"afterAddLiquidityReturnDelta","type":"bool"},{"internalType":"bool","name":"afterRemoveLiquidityReturnDelta","type":"bool"}],"internalType":"struct Hooks.Permissions","name":"","type":"tuple"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint160","name":"sqrtPriceX96","type":"uint160"}],"name":"initializePool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"inventoryCap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"keeperReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastCapDecayAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastClaimBlock","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lpFee","outputs":[{"internalType":"uint24","name":"","type":"uint24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"marketOpen","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxRefStep","outputs":[{"internalType":"int24","name":"","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minTrimTokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"maximumTokenAmount","type":"uint256"},{"internalType":"uint256","name":"capFloor_","type":"uint256"},{"internalType":"uint256","name":"capDecayTokensPerDay_","type":"uint256"}],"name":"openMarket","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"result","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"ownershipHandoverExpiresAt","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingRebalance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingTrim","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolId","outputs":[{"internalType":"PoolId","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolKey","outputs":[{"components":[{"internalType":"Currency","name":"currency0","type":"address"},{"internalType":"Currency","name":"currency1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"contract IHooks","name":"hooks","type":"address"}],"internalType":"struct PoolKey","name":"key","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolManager","outputs":[{"internalType":"contract IPoolManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"positionLiquidity","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ratchetBps","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rebalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"rebalanceEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rebalanceEthThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"redeemClaimsSelf","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"refTick","outputs":[{"internalType":"int24","name":"","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"requestOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"retainedEth","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardClaims","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardShareBps","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardsRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newBurnSink","type":"address"}],"name":"setBurnSink","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokensPerDay","type":"uint256"}],"name":"setCapDecay","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newFloor","type":"uint256"}],"name":"setCapFloor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"ticksPerDay","type":"uint256"}],"name":"setFloorDecay","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"reward","type":"uint256"}],"name":"setKeeperReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int24","name":"maxStep","type":"int24"}],"name":"setMaxRefStep","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newRatchetBps","type":"uint256"}],"name":"setRatchetBps","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"enabled","type":"bool"},{"internalType":"uint256","name":"ethThreshold","type":"uint256"}],"name":"setRebalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"bps","type":"uint256"}],"name":"setRewardShareBps","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newRewardsRecipient","type":"address"}],"name":"setRewardsRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"settleClaims","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"settleEthClaims","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"tickLower","outputs":[{"internalType":"int24","name":"","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tickSpacing","outputs":[{"internalType":"int24","name":"","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tickUpper","outputs":[{"internalType":"int24","name":"","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokensInPool","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalBurned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalFeeEth","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalFeeToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalRewarded","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes","name":"rawData","type":"bytes"}],"name":"unlockCallback","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"}],"name":"withdrawFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawRetainedEth","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}],"is_changed_bytecode":false,"is_partially_verified":false,"constructor_args":"0x000000000000000000000000047f606fd5b2baa5f5c6c4ab8958e45cb6b054b7000000000000000000000000000000000004444c5dc75cb358380d2e3de08a90000000000000000000000000d34a99bc0f67ae1bbd63c660e6d0b0dd03e263b7000000000000000000000000e29386719c155b6847ad5a4e97c6674f10ffc7500000000000000000000000009046739e1535b40efbe6ab3f45d0024b690eca3000000000000000000000000000000000000000000000000000000000000005dc00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002710000000000000000000000000000000000000000000000000000000000000003c"}