ETH Price: $1,882.87 (-1.35%)

Contract

0xe0e0e08A6A4b9Dc7bD67BCB7aadE5cF48157d444
 
Transaction Hash
Method
Block
From
To
Transfer Ownersh...220524582025-03-15 13:04:2313 days ago1742043863IN
0xe0e0e08A...48157d444
0 ETH0.000013710.47527343

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Method Block
From
To
0x00000000221515292025-03-29 9:00:351 min ago1743238835
0xe0e0e08A...48157d444
0.00329695 ETH
Transfer221515232025-03-29 8:59:232 mins ago1743238763
0xe0e0e08A...48157d444
0.00405818 ETH
0x00000000221514822025-03-29 8:51:1111 mins ago1743238271
0xe0e0e08A...48157d444
0.00417059 ETH
Transfer221514792025-03-29 8:50:3511 mins ago1743238235
0xe0e0e08A...48157d444
0.31865743 ETH
Transfer221514512025-03-29 8:44:5917 mins ago1743237899
0xe0e0e08A...48157d444
0.28797878 ETH
Transfer221514492025-03-29 8:44:3517 mins ago1743237875
0xe0e0e08A...48157d444
0.03116256 ETH
Transfer221514272025-03-29 8:39:5922 mins ago1743237599
0xe0e0e08A...48157d444
0.0053118 ETH
Transfer221514272025-03-29 8:39:5922 mins ago1743237599
0xe0e0e08A...48157d444
0.03163805 ETH
Transfer221513742025-03-29 8:29:1133 mins ago1743236951
0xe0e0e08A...48157d444
0.0155324 ETH
0x00000000221513622025-03-29 8:26:4735 mins ago1743236807
0xe0e0e08A...48157d444
0.0055 ETH
Transfer221513122025-03-29 8:16:4745 mins ago1743236207
0xe0e0e08A...48157d444
0.05229132 ETH
Transfer221512982025-03-29 8:13:5948 mins ago1743236039
0xe0e0e08A...48157d444
0.34646036 ETH
Transfer221512162025-03-29 7:57:351 hr ago1743235055
0xe0e0e08A...48157d444
0.00531868 ETH
0x00000000221512002025-03-29 7:54:111 hr ago1743234851
0xe0e0e08A...48157d444
0.72 ETH
0x00000000221511912025-03-29 7:52:231 hr ago1743234743
0xe0e0e08A...48157d444
0.1201045 ETH
0x00000000221511892025-03-29 7:51:591 hr ago1743234719
0xe0e0e08A...48157d444
0.003 ETH
0x00000000221511812025-03-29 7:50:231 hr ago1743234623
0xe0e0e08A...48157d444
0.03568398 ETH
0x00000000221511762025-03-29 7:49:231 hr ago1743234563
0xe0e0e08A...48157d444
0.12217102 ETH
Transfer221510592025-03-29 7:25:351 hr ago1743233135
0xe0e0e08A...48157d444
0.03212017 ETH
0x00000000221510002025-03-29 7:13:231 hr ago1743232403
0xe0e0e08A...48157d444
0.14068914 ETH
0x00000000221509882025-03-29 7:10:591 hr ago1743232259
0xe0e0e08A...48157d444
0.03204704 ETH
0x00000000221509802025-03-29 7:09:231 hr ago1743232163
0xe0e0e08A...48157d444
0.0656918 ETH
0x00000000221509142025-03-29 6:55:472 hrs ago1743231347
0xe0e0e08A...48157d444
0.02659688 ETH
0x00000000221509132025-03-29 6:55:352 hrs ago1743231335
0xe0e0e08A...48157d444
0.01 ETH
0x00000000221509092025-03-29 6:54:472 hrs ago1743231287
0xe0e0e08A...48157d444
0.02878385 ETH
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Core

Compiler Version
v0.8.28+commit.7893614a

Optimization Enabled:
Yes with 9999999 runs

Other Settings:
cancun EvmVersion
File 1 of 28 : Core.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

import {CallPoints, addressToCallPoints} from "./types/callPoints.sol";
import {PoolKey} from "./types/poolKey.sol";
import {PositionKey, Bounds} from "./types/positionKey.sol";
import {FeesPerLiquidity, feesPerLiquidityFromAmounts} from "./types/feesPerLiquidity.sol";
import {isPriceIncreasing, SqrtRatioLimitWrongDirection, SwapResult, swapResult} from "./math/swap.sol";
import {Position} from "./types/position.sol";
import {Ownable} from "solady/auth/Ownable.sol";
import {tickToSqrtRatio, sqrtRatioToTick} from "./math/ticks.sol";
import {Bitmap} from "./math/bitmap.sol";
import {
    shouldCallBeforeInitializePool,
    shouldCallAfterInitializePool,
    shouldCallBeforeUpdatePosition,
    shouldCallAfterUpdatePosition,
    shouldCallBeforeSwap,
    shouldCallAfterSwap,
    shouldCallBeforeCollectFees,
    shouldCallAfterCollectFees
} from "./types/callPoints.sol";
import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol";
import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol";
import {SafeCastLib} from "solady/utils/SafeCastLib.sol";
import {ExposedStorage} from "./base/ExposedStorage.sol";
import {liquidityDeltaToAmountDelta, addLiquidityDelta, subLiquidityDelta} from "./math/liquidity.sol";
import {computeFee} from "./math/fee.sol";
import {findNextInitializedTick, findPrevInitializedTick, flipTick} from "./math/tickBitmap.sol";
import {ICore, UpdatePositionParameters, IExtension} from "./interfaces/ICore.sol";
import {FlashAccountant} from "./base/FlashAccountant.sol";
import {EfficientHashLib} from "solady/utils/EfficientHashLib.sol";
import {
    MIN_TICK,
    MAX_TICK,
    NATIVE_TOKEN_ADDRESS,
    FULL_RANGE_ONLY_TICK_SPACING,
    MAX_TICK_SPACING
} from "./math/constants.sol";
import {MIN_SQRT_RATIO, MAX_SQRT_RATIO, SqrtRatio} from "./types/sqrtRatio.sol";

/// @title Ekubo Protocol
/// @author Moody Salem <[email protected]>
/// @notice Singleton holding all the tokens and containing all the possible operations in Ekubo Protocol
contract Core is ICore, FlashAccountant, Ownable, ExposedStorage {
    using {findNextInitializedTick, findPrevInitializedTick, flipTick} for mapping(uint256 word => Bitmap bitmap);

    struct TickInfo {
        int128 liquidityDelta;
        uint128 liquidityNet;
    }

    struct PoolState {
        SqrtRatio sqrtRatio;
        int32 tick;
        uint128 liquidity;
    }

    mapping(address extension => bool isRegistered) private isExtensionRegistered;
    mapping(address token => uint256 amountCollected) private protocolFeesCollected;

    mapping(bytes32 poolId => PoolState) private poolState;
    mapping(bytes32 poolId => FeesPerLiquidity feesPerLiquidity) private poolFeesPerLiquidity;
    mapping(bytes32 poolId => mapping(bytes32 positionId => Position position)) private poolPositions;
    mapping(bytes32 poolId => mapping(int32 tick => TickInfo tickInfo)) private poolTicks;
    mapping(bytes32 poolId => mapping(int32 tick => FeesPerLiquidity feesPerLiquidityOutside)) private
        poolTickFeesPerLiquidityOutside;
    mapping(bytes32 poolId => mapping(uint256 word => Bitmap bitmap)) private poolInitializedTickBitmaps;

    mapping(bytes32 key => uint256) private savedBalances;

    constructor(address owner) {
        _initializeOwner(owner);
    }

    function withdrawProtocolFees(address recipient, address token, uint256 amount) external onlyOwner {
        protocolFeesCollected[token] -= amount;
        if (token == NATIVE_TOKEN_ADDRESS) {
            SafeTransferLib.safeTransferETH(recipient, amount);
        } else {
            SafeTransferLib.safeTransfer(token, recipient, amount);
        }
        emit ProtocolFeesWithdrawn(recipient, token, amount);
    }

    // Extensions must call this function to become registered. The call points are validated against the caller address
    function registerExtension(CallPoints memory expectedCallPoints) external {
        CallPoints memory computed = addressToCallPoints(msg.sender);
        if (!computed.eq(expectedCallPoints) || !computed.isValid()) revert FailedRegisterInvalidCallPoints();
        if (isExtensionRegistered[msg.sender]) revert ExtensionAlreadyRegistered();
        isExtensionRegistered[msg.sender] = true;
        emit ExtensionRegistered(msg.sender);
    }

    function initializePool(PoolKey memory poolKey, int32 tick) external returns (SqrtRatio sqrtRatio) {
        poolKey.validatePoolKey();

        address extension = poolKey.extension();
        if (extension != address(0)) {
            if (!isExtensionRegistered[extension]) {
                revert ExtensionNotRegistered();
            }

            if (shouldCallBeforeInitializePool(extension) && extension != msg.sender) {
                IExtension(extension).beforeInitializePool(msg.sender, poolKey, tick);
            }
        }

        bytes32 poolId = poolKey.toPoolId();
        PoolState memory price = poolState[poolId];
        if (SqrtRatio.unwrap(price.sqrtRatio) != 0) revert PoolAlreadyInitialized();

        sqrtRatio = tickToSqrtRatio(tick);
        poolState[poolId] = PoolState({sqrtRatio: sqrtRatio, tick: tick, liquidity: 0});

        emit PoolInitialized(poolId, poolKey, tick, sqrtRatio);

        if (shouldCallAfterInitializePool(extension) && extension != msg.sender) {
            IExtension(extension).afterInitializePool(msg.sender, poolKey, tick, sqrtRatio);
        }
    }

    function prevInitializedTick(bytes32 poolId, int32 fromTick, uint32 tickSpacing, uint256 skipAhead)
        external
        view
        returns (int32 tick, bool isInitialized)
    {
        (tick, isInitialized) =
            poolInitializedTickBitmaps[poolId].findPrevInitializedTick(fromTick, tickSpacing, skipAhead);
    }

    function nextInitializedTick(bytes32 poolId, int32 fromTick, uint32 tickSpacing, uint256 skipAhead)
        external
        view
        returns (int32 tick, bool isInitialized)
    {
        (tick, isInitialized) =
            poolInitializedTickBitmaps[poolId].findNextInitializedTick(fromTick, tickSpacing, skipAhead);
    }

    function load(address token0, address token1, bytes32 salt, uint128 amount0, uint128 amount1) public {
        // note we do not check sort order because for save it must be sorted,
        //  so balances will always be zero if token0 and token1 are not sorted
        //  and this method will throw InsufficientSavedBalance for non-zero amount
        (uint256 id,) = _getLocker();

        bytes32 key = EfficientHashLib.hash(
            bytes32(uint256(uint160(msg.sender))),
            bytes32(uint256(uint160(token0))),
            bytes32(uint256(uint160(token1))),
            salt
        );

        unchecked {
            uint256 packedBalance = savedBalances[key];
            uint128 balance0 = uint128(packedBalance >> 128);
            uint128 balance1 = uint128(packedBalance);
            if (balance0 < amount0 || balance1 < amount1) {
                revert InsufficientSavedBalance();
            }

            // unchecked is ok because we reverted if either balance < amount
            savedBalances[key] = (uint256(balance0 - amount0) << 128) + uint256(balance1 - amount1);

            _accountDebt(id, token0, -int256(uint256(amount0)));
            _accountDebt(id, token1, -int256(uint256(amount1)));
        }
    }

    function save(address owner, address token0, address token1, bytes32 salt, uint128 amount0, uint128 amount1)
        public
        payable
    {
        if (token0 >= token1) revert SavedBalanceTokensNotSorted();

        (uint256 id,) = _requireLocker();

        bytes32 key = EfficientHashLib.hash(
            bytes32(uint256(uint160(owner))), bytes32(uint256(uint160(token0))), bytes32(uint256(uint160(token1))), salt
        );

        uint256 packedBalances = savedBalances[key];

        uint128 balance0 = uint128(packedBalances >> 128);
        uint128 balance1 = uint128(packedBalances);

        // we are using checked math here to protect the uint128 additions from overflowing
        savedBalances[key] = (uint256(balance0 + amount0) << 128) + uint256(balance1 + amount1);

        _maybeAccountDebtToken0(id, token0, int256(uint256(amount0)));
        _accountDebt(id, token1, int256(uint256(amount1)));
    }

    // Returns the pool fees per liquidity inside the given bounds.
    function _getPoolFeesPerLiquidityInside(bytes32 poolId, Bounds memory bounds, uint32 tickSpacing)
        internal
        view
        returns (FeesPerLiquidity memory)
    {
        if (tickSpacing == FULL_RANGE_ONLY_TICK_SPACING) return poolFeesPerLiquidity[poolId];

        int32 tick = poolState[poolId].tick;
        mapping(int32 => FeesPerLiquidity) storage poolIdEntry = poolTickFeesPerLiquidityOutside[poolId];
        FeesPerLiquidity memory lower = poolIdEntry[bounds.lower];
        FeesPerLiquidity memory upper = poolIdEntry[bounds.upper];

        if (tick < bounds.lower) {
            return lower.sub(upper);
        } else if (tick < bounds.upper) {
            FeesPerLiquidity memory fees = poolFeesPerLiquidity[poolId];

            return fees.sub(lower).sub(upper);
        } else {
            return upper.sub(lower);
        }
    }

    function getPoolFeesPerLiquidityInside(PoolKey memory poolKey, Bounds memory bounds)
        external
        view
        returns (FeesPerLiquidity memory)
    {
        return _getPoolFeesPerLiquidityInside(poolKey.toPoolId(), bounds, poolKey.tickSpacing());
    }

    // Accumulates tokens to fees of a pool. Only callable by the extension of the specified pool
    // key, i.e. the current locker _must_ be the extension.
    // The extension must call this function within a lock callback.
    function accumulateAsFees(PoolKey memory poolKey, uint128 amount0, uint128 amount1) external payable {
        (uint256 id, address locker) = _requireLocker();
        require(locker == poolKey.extension());

        bytes32 poolId = poolKey.toPoolId();

        // Note we do not check pool is initialized. If the extension calls this for a pool that does not exist,
        //  the fees are simply burned since liquidity is 0.

        assembly ("memory-safe") {
            if or(amount0, amount1) {
                mstore(0, poolId)
                mstore(32, 2)
                let liquidity := shr(128, sload(keccak256(0, 64)))

                if liquidity {
                    mstore(32, 3)
                    let slot0 := keccak256(0, 64)

                    if amount0 {
                        let v := div(shl(128, amount0), liquidity)
                        sstore(slot0, add(sload(slot0), v))
                    }
                    if amount1 {
                        let slot1 := add(slot0, 1)
                        let v := div(shl(128, amount1), liquidity)
                        sstore(slot1, add(sload(slot1), v))
                    }
                }
            }
        }

        // whether the fees are actually accounted to any position, the caller owes the debt
        _maybeAccountDebtToken0(id, poolKey.token0, int256(uint256(amount0)));
        _accountDebt(id, poolKey.token1, int256(uint256(amount1)));

        emit FeesAccumulated(poolId, amount0, amount1);
    }

    function _updateTick(bytes32 poolId, int32 tick, uint32 tickSpacing, int128 liquidityDelta, bool isUpper) private {
        TickInfo storage tickInfo = poolTicks[poolId][tick];

        uint128 liquidityNetNext = addLiquidityDelta(tickInfo.liquidityNet, liquidityDelta);
        // this is checked math
        int128 liquidityDeltaNext =
            isUpper ? tickInfo.liquidityDelta - liquidityDelta : tickInfo.liquidityDelta + liquidityDelta;

        if ((tickInfo.liquidityNet == 0) != (liquidityNetNext == 0)) {
            flipTick(poolInitializedTickBitmaps[poolId], tick, tickSpacing);
        }

        tickInfo.liquidityDelta = liquidityDeltaNext;
        tickInfo.liquidityNet = liquidityNetNext;
    }

    function _maybeAccountDebtToken0(uint256 id, address token0, int256 debtChange) private {
        if (msg.value == 0) {
            _accountDebt(id, token0, debtChange);
        } else {
            if (msg.value > type(uint128).max) revert PaymentOverflow();

            if (token0 == NATIVE_TOKEN_ADDRESS) {
                unchecked {
                    _accountDebt(id, NATIVE_TOKEN_ADDRESS, debtChange - int256(msg.value));
                }
            } else {
                unchecked {
                    _accountDebt(id, token0, debtChange);
                    _accountDebt(id, NATIVE_TOKEN_ADDRESS, -int256(msg.value));
                }
            }
        }
    }

    function updatePosition(PoolKey memory poolKey, UpdatePositionParameters memory params)
        external
        payable
        returns (int128 delta0, int128 delta1)
    {
        (uint256 id, address locker) = _requireLocker();

        address extension = poolKey.extension();
        if (shouldCallBeforeUpdatePosition(extension) && locker != extension) {
            IExtension(extension).beforeUpdatePosition(locker, poolKey, params);
        }

        params.bounds.validateBounds(poolKey.tickSpacing());

        if (params.liquidityDelta != 0) {
            bytes32 poolId = poolKey.toPoolId();
            PoolState memory price = poolState[poolId];
            if (SqrtRatio.unwrap(price.sqrtRatio) == 0) revert PoolNotInitialized();

            (SqrtRatio sqrtRatioLower, SqrtRatio sqrtRatioUpper) =
                (tickToSqrtRatio(params.bounds.lower), tickToSqrtRatio(params.bounds.upper));

            (delta0, delta1) =
                liquidityDeltaToAmountDelta(price.sqrtRatio, params.liquidityDelta, sqrtRatioLower, sqrtRatioUpper);

            PositionKey memory positionKey = PositionKey({salt: params.salt, owner: locker, bounds: params.bounds});

            if (params.liquidityDelta < 0) {
                if (poolKey.fee() != 0) {
                    unchecked {
                        // uint128(-delta0) is ok in unchecked block
                        uint128 protocolFees0 = computeFee(uint128(-delta0), poolKey.fee());
                        uint128 protocolFees1 = computeFee(uint128(-delta1), poolKey.fee());

                        if (protocolFees0 > 0) {
                            // this will never overflow for a well behaved token since protocol fees are stored as uint256
                            protocolFeesCollected[poolKey.token0] += protocolFees0;

                            // magnitude of protocolFees0 is at most equal to -delta0, so after addition delta0 will maximally reach 0 and no overflow/underflow check is needed
                            // in addition, casting is safe because computed fee is never g.t. the input amount, which is an int128
                            delta0 += int128(protocolFees0);
                        }

                        // same reasoning applies for the unchecked safety here
                        if (protocolFees1 > 0) {
                            protocolFeesCollected[poolKey.token1] += protocolFees1;
                            delta1 += int128(protocolFees1);
                        }
                    }
                }
            }

            bytes32 positionId = positionKey.toPositionId();
            Position storage position = poolPositions[poolId][positionId];

            FeesPerLiquidity memory feesPerLiquidityInside =
                _getPoolFeesPerLiquidityInside(poolId, params.bounds, poolKey.tickSpacing());

            (uint128 fees0, uint128 fees1) = position.fees(feesPerLiquidityInside);

            uint128 liquidityNext = addLiquidityDelta(position.liquidity, params.liquidityDelta);

            if (liquidityNext != 0) {
                position.liquidity = liquidityNext;
                position.feesPerLiquidityInsideLast =
                    feesPerLiquidityInside.sub(feesPerLiquidityFromAmounts(fees0, fees1, liquidityNext));
            } else {
                if (fees0 != 0 || fees1 != 0) revert MustCollectFeesBeforeWithdrawingAllLiquidity();
                position.liquidity = 0;
                position.feesPerLiquidityInsideLast = FeesPerLiquidity(0, 0);
            }

            if (!poolKey.isFullRange()) {
                _updateTick(poolId, params.bounds.lower, poolKey.tickSpacing(), params.liquidityDelta, false);
                _updateTick(poolId, params.bounds.upper, poolKey.tickSpacing(), params.liquidityDelta, true);

                if (price.tick >= params.bounds.lower && price.tick < params.bounds.upper) {
                    poolState[poolId].liquidity = addLiquidityDelta(poolState[poolId].liquidity, params.liquidityDelta);
                }
            } else {
                poolState[poolId].liquidity = addLiquidityDelta(poolState[poolId].liquidity, params.liquidityDelta);
            }

            _maybeAccountDebtToken0(id, poolKey.token0, delta0);
            _accountDebt(id, poolKey.token1, delta1);

            emit PositionUpdated(locker, poolId, params, delta0, delta1);
        }

        if (shouldCallAfterUpdatePosition(extension) && locker != extension) {
            IExtension(extension).afterUpdatePosition(locker, poolKey, params, delta0, delta1);
        }
    }

    function collectFees(PoolKey memory poolKey, bytes32 salt, Bounds memory bounds)
        external
        returns (uint128 amount0, uint128 amount1)
    {
        (uint256 id, address locker) = _requireLocker();

        address extension = poolKey.extension();
        if (shouldCallBeforeCollectFees(extension) && locker != extension) {
            IExtension(extension).beforeCollectFees(locker, poolKey, salt, bounds);
        }

        bytes32 poolId = poolKey.toPoolId();
        PositionKey memory positionKey = PositionKey({salt: salt, owner: locker, bounds: bounds});
        bytes32 positionId = positionKey.toPositionId();
        Position memory position = poolPositions[poolId][positionId];

        FeesPerLiquidity memory feesPerLiquidityInside =
            _getPoolFeesPerLiquidityInside(poolId, bounds, poolKey.tickSpacing());

        (amount0, amount1) = position.fees(feesPerLiquidityInside);

        poolPositions[poolId][positionId] =
            Position({liquidity: position.liquidity, feesPerLiquidityInsideLast: feesPerLiquidityInside});

        _accountDebt(id, poolKey.token0, -int256(uint256(amount0)));
        _accountDebt(id, poolKey.token1, -int256(uint256(amount1)));

        emit PositionFeesCollected(poolId, positionKey, amount0, amount1);

        if (shouldCallAfterCollectFees(extension) && locker != extension) {
            IExtension(extension).afterCollectFees(locker, poolKey, salt, bounds, amount0, amount1);
        }
    }

    function swap_611415377(
        PoolKey memory poolKey,
        int128 amount,
        bool isToken1,
        SqrtRatio sqrtRatioLimit,
        uint256 skipAhead
    ) external payable returns (int128 delta0, int128 delta1) {
        if (!sqrtRatioLimit.isValid()) revert InvalidSqrtRatioLimit();

        (uint256 id, address locker) = _requireLocker();

        address extension = poolKey.extension();
        if (shouldCallBeforeSwap(extension) && locker != extension) {
            IExtension(extension).beforeSwap(locker, poolKey, amount, isToken1, sqrtRatioLimit, skipAhead);
        }

        bytes32 poolId = poolKey.toPoolId();
        SqrtRatio sqrtRatio;
        int32 tick;
        uint128 liquidity;
        {
            PoolState storage state = poolState[poolId];
            (sqrtRatio, tick, liquidity) = (state.sqrtRatio, state.tick, state.liquidity);
        }

        if (sqrtRatio.isZero()) revert PoolNotInitialized();

        // 0 swap amount is no-op
        if (amount != 0) {
            bool increasing = isPriceIncreasing(amount, isToken1);
            if (increasing) {
                if (sqrtRatioLimit < sqrtRatio) revert SqrtRatioLimitWrongDirection();
            } else {
                if (sqrtRatioLimit > sqrtRatio) revert SqrtRatioLimitWrongDirection();
            }

            int128 amountRemaining = amount;

            uint128 calculatedAmount = 0;

            // the slot where inputTokenFeesPerLiquidity is stored, reused later
            bytes32 inputTokenFeesPerLiquiditySlot;

            // fees per liquidity only for the input token
            uint256 inputTokenFeesPerLiquidity;

            // this loads only the input token fees per liquidity
            if (poolKey.mustLoadFees()) {
                assembly ("memory-safe") {
                    mstore(0, poolId)
                    mstore(32, 3)
                    inputTokenFeesPerLiquiditySlot := add(keccak256(0, 64), increasing)
                    inputTokenFeesPerLiquidity := sload(inputTokenFeesPerLiquiditySlot)
                }
            }

            while (amountRemaining != 0 && sqrtRatio != sqrtRatioLimit) {
                int32 nextTick;
                bool isInitialized;
                SqrtRatio nextTickSqrtRatio;
                SwapResult memory result;

                if (poolKey.tickSpacing() != FULL_RANGE_ONLY_TICK_SPACING) {
                    (nextTick, isInitialized) = increasing
                        ? poolInitializedTickBitmaps[poolId].findNextInitializedTick(tick, poolKey.tickSpacing(), skipAhead)
                        : poolInitializedTickBitmaps[poolId].findPrevInitializedTick(tick, poolKey.tickSpacing(), skipAhead);

                    nextTickSqrtRatio = tickToSqrtRatio(nextTick);
                } else {
                    // we never cross ticks in the full range version
                    // isInitialized = false;
                    (nextTick, nextTickSqrtRatio) = increasing ? (MAX_TICK, MAX_SQRT_RATIO) : (MIN_TICK, MIN_SQRT_RATIO);
                }

                SqrtRatio limitedNextSqrtRatio =
                    increasing ? nextTickSqrtRatio.min(sqrtRatioLimit) : nextTickSqrtRatio.max(sqrtRatioLimit);

                result =
                    swapResult(sqrtRatio, liquidity, limitedNextSqrtRatio, amountRemaining, isToken1, poolKey.fee());

                // this accounts the fees into the feesPerLiquidity memory struct
                assembly ("memory-safe") {
                    // div by 0 returns 0, so it's ok
                    let v := div(shl(128, mload(add(result, 96))), liquidity)
                    inputTokenFeesPerLiquidity := add(inputTokenFeesPerLiquidity, v)
                }

                amountRemaining -= result.consumedAmount;
                calculatedAmount += result.calculatedAmount;

                if (result.sqrtRatioNext == nextTickSqrtRatio) {
                    sqrtRatio = result.sqrtRatioNext;
                    tick = increasing ? nextTick : nextTick - 1;

                    if (isInitialized) {
                        int128 liquidityDelta = poolTicks[poolId][nextTick].liquidityDelta;
                        liquidity = increasing
                            ? addLiquidityDelta(liquidity, liquidityDelta)
                            : subLiquidityDelta(liquidity, liquidityDelta);
                        FeesPerLiquidity memory tickFpl = poolTickFeesPerLiquidityOutside[poolId][nextTick];

                        FeesPerLiquidity memory totalFpl;

                        // load only the slot we didn't load before into totalFpl
                        assembly ("memory-safe") {
                            mstore(add(totalFpl, mul(32, increasing)), inputTokenFeesPerLiquidity)

                            let outputTokenFeesPerLiquidity :=
                                sload(add(sub(inputTokenFeesPerLiquiditySlot, increasing), iszero(increasing)))
                            mstore(add(totalFpl, mul(32, iszero(increasing))), outputTokenFeesPerLiquidity)
                        }

                        poolTickFeesPerLiquidityOutside[poolId][nextTick] = totalFpl.sub(tickFpl);
                    }
                } else if (sqrtRatio != result.sqrtRatioNext) {
                    sqrtRatio = result.sqrtRatioNext;
                    tick = sqrtRatioToTick(sqrtRatio);
                }
            }

            unchecked {
                int256 calculatedAmountSign = int256(FixedPointMathLib.ternary(amount < 0, 1, type(uint256).max));
                int128 calculatedAmountDelta = SafeCastLib.toInt128(
                    FixedPointMathLib.max(type(int128).min, calculatedAmountSign * int256(uint256(calculatedAmount)))
                );

                (delta0, delta1) = isToken1
                    ? (calculatedAmountDelta, amount - amountRemaining)
                    : (amount - amountRemaining, calculatedAmountDelta);
            }

            assembly ("memory-safe") {
                mstore(0, poolId)
                mstore(32, 2)
                sstore(keccak256(0, 64), add(add(sqrtRatio, shl(96, and(tick, 0xffffffff))), shl(128, liquidity)))
            }

            if (poolKey.mustLoadFees()) {
                assembly ("memory-safe") {
                    // this stores only the input token fees per liquidity
                    sstore(inputTokenFeesPerLiquiditySlot, inputTokenFeesPerLiquidity)
                }
            }

            _maybeAccountDebtToken0(id, poolKey.token0, delta0);
            _accountDebt(id, poolKey.token1, delta1);

            assembly ("memory-safe") {
                let o := mload(0x40)
                mstore(o, shl(96, locker))
                mstore(add(o, 20), poolId)
                mstore(add(o, 52), or(shl(128, delta0), and(delta1, 0xffffffffffffffffffffffffffffffff)))
                mstore(add(o, 84), shl(128, liquidity))
                mstore(add(o, 100), shl(160, sqrtRatio))
                mstore(add(o, 112), shl(224, tick))
                log0(o, 116)
            }
        }

        if (shouldCallAfterSwap(extension) && locker != extension) {
            IExtension(extension).afterSwap(
                locker, poolKey, amount, isToken1, sqrtRatioLimit, skipAhead, delta0, delta1
            );
        }
    }
}

File 2 of 28 : callPoints.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

struct CallPoints {
    bool beforeInitializePool;
    bool afterInitializePool;
    bool beforeSwap;
    bool afterSwap;
    bool beforeUpdatePosition;
    bool afterUpdatePosition;
    bool beforeCollectFees;
    bool afterCollectFees;
}

using {eq, isValid, toUint8} for CallPoints global;

function eq(CallPoints memory a, CallPoints memory b) pure returns (bool) {
    return (
        a.beforeInitializePool == b.beforeInitializePool && a.afterInitializePool == b.afterInitializePool
            && a.beforeSwap == b.beforeSwap && a.afterSwap == b.afterSwap
            && a.beforeUpdatePosition == b.beforeUpdatePosition && a.afterUpdatePosition == b.afterUpdatePosition
            && a.beforeCollectFees == b.beforeCollectFees && a.afterCollectFees == b.afterCollectFees
    );
}

function isValid(CallPoints memory a) pure returns (bool) {
    return (
        a.beforeInitializePool || a.afterInitializePool || a.beforeSwap || a.afterSwap || a.beforeUpdatePosition
            || a.afterUpdatePosition || a.beforeCollectFees || a.afterCollectFees
    );
}

function toUint8(CallPoints memory callPoints) pure returns (uint8 b) {
    assembly ("memory-safe") {
        b :=
            add(
                add(
                    add(
                        add(
                            add(
                                add(
                                    add(mload(callPoints), mul(128, mload(add(callPoints, 32)))),
                                    mul(64, mload(add(callPoints, 64)))
                                ),
                                mul(32, mload(add(callPoints, 96)))
                            ),
                            mul(16, mload(add(callPoints, 128)))
                        ),
                        mul(8, mload(add(callPoints, 160)))
                    ),
                    mul(4, mload(add(callPoints, 192)))
                ),
                mul(2, mload(add(callPoints, 224)))
            )
    }
}

function addressToCallPoints(address a) pure returns (CallPoints memory result) {
    result = byteToCallPoints(uint8(uint160(a) >> 152));
}

function byteToCallPoints(uint8 b) pure returns (CallPoints memory result) {
    // note the order of bytes does not match the struct order of elements because we are matching the cairo implementation
    // which for legacy reasons has the fields in this order
    result = CallPoints({
        beforeInitializePool: (b & 1) != 0,
        afterInitializePool: (b & 128) != 0,
        beforeSwap: (b & 64) != 0,
        afterSwap: (b & 32) != 0,
        beforeUpdatePosition: (b & 16) != 0,
        afterUpdatePosition: (b & 8) != 0,
        beforeCollectFees: (b & 4) != 0,
        afterCollectFees: (b & 2) != 0
    });
}

function shouldCallBeforeInitializePool(address a) pure returns (bool yes) {
    assembly ("memory-safe") {
        yes := and(shr(152, a), 1)
    }
}

function shouldCallAfterInitializePool(address a) pure returns (bool yes) {
    assembly ("memory-safe") {
        yes := and(shr(159, a), 1)
    }
}

function shouldCallBeforeSwap(address a) pure returns (bool yes) {
    assembly ("memory-safe") {
        yes := and(shr(158, a), 1)
    }
}

function shouldCallAfterSwap(address a) pure returns (bool yes) {
    assembly ("memory-safe") {
        yes := and(shr(157, a), 1)
    }
}

function shouldCallBeforeUpdatePosition(address a) pure returns (bool yes) {
    assembly ("memory-safe") {
        yes := and(shr(156, a), 1)
    }
}

function shouldCallAfterUpdatePosition(address a) pure returns (bool yes) {
    assembly ("memory-safe") {
        yes := and(shr(155, a), 1)
    }
}

function shouldCallBeforeCollectFees(address a) pure returns (bool yes) {
    assembly ("memory-safe") {
        yes := and(shr(154, a), 1)
    }
}

function shouldCallAfterCollectFees(address a) pure returns (bool yes) {
    assembly ("memory-safe") {
        yes := and(shr(153, a), 1)
    }
}

File 3 of 28 : poolKey.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

import {MAX_TICK_SPACING, FULL_RANGE_ONLY_TICK_SPACING} from "../math/constants.sol";

using {toPoolId, validatePoolKey, isFullRange, mustLoadFees, tickSpacing, fee, extension} for PoolKey global;

// address (20 bytes) | fee (8 bytes) | tickSpacing (4 bytes)
type Config is bytes32;

function tickSpacing(PoolKey memory pk) pure returns (uint32 r) {
    assembly ("memory-safe") {
        r := and(mload(add(64, pk)), 0xffffffff)
    }
}

function fee(PoolKey memory pk) pure returns (uint64 r) {
    assembly ("memory-safe") {
        r := and(mload(add(60, pk)), 0xffffffffffffffff)
    }
}

function extension(PoolKey memory pk) pure returns (address r) {
    assembly ("memory-safe") {
        r := and(mload(add(52, pk)), 0xffffffffffffffffffffffffffffffffffffffff)
    }
}

function mustLoadFees(PoolKey memory pk) pure returns (bool r) {
    assembly ("memory-safe") {
        // only if either of tick spacing and fee are nonzero
        // if _both_ are zero, then we know we do not need to load fees for swaps
        r := iszero(iszero(and(mload(add(64, pk)), 0xffffffffffffffffffffffff)))
    }
}

function isFullRange(PoolKey memory pk) pure returns (bool r) {
    r = pk.tickSpacing() == FULL_RANGE_ONLY_TICK_SPACING;
}

function toConfig(uint64 _fee, uint32 _tickSpacing, address _extension) pure returns (Config c) {
    assembly ("memory-safe") {
        c := add(add(shl(96, _extension), shl(32, _fee)), _tickSpacing)
    }
}

// Each pool has its own state associated with this key
struct PoolKey {
    address token0;
    address token1;
    Config config;
}

error TokensMustBeSorted();
error InvalidTickSpacing();

function validatePoolKey(PoolKey memory key) pure {
    if (key.token0 >= key.token1) revert TokensMustBeSorted();
    if (key.tickSpacing() > MAX_TICK_SPACING) {
        revert InvalidTickSpacing();
    }
}

function toPoolId(PoolKey memory key) pure returns (bytes32 result) {
    assembly ("memory-safe") {
        // it's already copied into memory
        result := keccak256(key, 96)
    }
}

File 4 of 28 : positionKey.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

import {MIN_TICK, MAX_TICK, FULL_RANGE_ONLY_TICK_SPACING} from "../math/constants.sol";

using {toPositionId} for PositionKey global;
using {validateBounds} for Bounds global;

// Bounds are lower and upper prices for which a position is active
struct Bounds {
    int32 lower;
    int32 upper;
}

error BoundsOrder();
error MinMaxBounds();
error BoundsTickSpacing();
error FullRangeOnlyPool();

function validateBounds(Bounds memory bounds, uint32 tickSpacing) pure {
    if (tickSpacing == FULL_RANGE_ONLY_TICK_SPACING) {
        if (bounds.lower != MIN_TICK || bounds.upper != MAX_TICK) revert FullRangeOnlyPool();
    } else {
        if (bounds.lower >= bounds.upper) revert BoundsOrder();
        if (bounds.lower < MIN_TICK || bounds.upper > MAX_TICK) revert MinMaxBounds();
        int32 spacing = int32(tickSpacing);
        if (bounds.lower % spacing != 0 || bounds.upper % spacing != 0) revert BoundsTickSpacing();
    }
}

// A position is keyed by the pool and this position key
struct PositionKey {
    bytes32 salt;
    address owner;
    Bounds bounds;
}

function toPositionId(PositionKey memory key) pure returns (bytes32 result) {
    assembly ("memory-safe") {
        // salt and owner
        mstore(0, keccak256(key, 64))
        // bounds
        mstore(32, keccak256(mload(add(key, 64)), 64))

        result := keccak256(0, 64)
    }
}

File 5 of 28 : feesPerLiquidity.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

// The total fees per liquidity for each token.
// Since these are always read together we put them in a struct, even though they cannot be packed.
struct FeesPerLiquidity {
    uint256 value0;
    uint256 value1;
}

using {sub} for FeesPerLiquidity global;

function sub(FeesPerLiquidity memory a, FeesPerLiquidity memory b) pure returns (FeesPerLiquidity memory result) {
    assembly ("memory-safe") {
        mstore(result, sub(mload(a), mload(b)))
        mstore(add(result, 32), sub(mload(add(a, 32)), mload(add(b, 32))))
    }
}

function feesPerLiquidityFromAmounts(uint128 amount0, uint128 amount1, uint128 liquidity)
    pure
    returns (FeesPerLiquidity memory result)
{
    assembly ("memory-safe") {
        mstore(result, div(shl(128, amount0), liquidity))
        mstore(add(result, 32), div(shl(128, amount1), liquidity))
    }
}

File 6 of 28 : swap.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol";
import {computeFee, amountBeforeFee} from "./fee.sol";
import {nextSqrtRatioFromAmount0, nextSqrtRatioFromAmount1} from "./sqrtRatio.sol";
import {amount0Delta, amount1Delta} from "./delta.sol";
import {SafeCastLib} from "solady/utils/SafeCastLib.sol";
import {isPriceIncreasing} from "./isPriceIncreasing.sol";
import {SqrtRatio} from "../types/sqrtRatio.sol";

struct SwapResult {
    int128 consumedAmount;
    uint128 calculatedAmount;
    SqrtRatio sqrtRatioNext;
    uint128 feeAmount;
}

function noOpSwapResult(SqrtRatio sqrtRatioNext) pure returns (SwapResult memory) {
    return SwapResult({consumedAmount: 0, calculatedAmount: 0, feeAmount: 0, sqrtRatioNext: sqrtRatioNext});
}

error SqrtRatioLimitWrongDirection();

function swapResult(
    SqrtRatio sqrtRatio,
    uint128 liquidity,
    SqrtRatio sqrtRatioLimit,
    int128 amount,
    bool isToken1,
    uint64 fee
) pure returns (SwapResult memory) {
    if (amount == 0 || sqrtRatio == sqrtRatioLimit) {
        return noOpSwapResult(sqrtRatio);
    }

    bool increasing = isPriceIncreasing(amount, isToken1);

    // We know sqrtRatio != sqrtRatioLimit because we early return above if it is
    if ((sqrtRatioLimit > sqrtRatio) != increasing) revert SqrtRatioLimitWrongDirection();

    if (liquidity == 0) {
        // if the pool is empty, the swap will always move all the way to the limit price
        return noOpSwapResult(sqrtRatioLimit);
    }

    bool isExactOut = amount < 0;

    // this amount is what moves the price
    int128 priceImpactAmount;
    if (isExactOut) {
        priceImpactAmount = amount;
    } else {
        unchecked {
            // cast is safe because amount is g.t.e. 0
            // then cast back to int128 is also safe because computeFee never returns a value g.t. the input amount
            priceImpactAmount = amount - int128(computeFee(uint128(amount), fee));
        }
    }

    SqrtRatio sqrtRatioNextFromAmount;
    if (isToken1) {
        sqrtRatioNextFromAmount = nextSqrtRatioFromAmount1(sqrtRatio, liquidity, priceImpactAmount);
    } else {
        sqrtRatioNextFromAmount = nextSqrtRatioFromAmount0(sqrtRatio, liquidity, priceImpactAmount);
    }

    int128 consumedAmount;
    uint128 calculatedAmount;
    uint128 feeAmount;

    // the amount requires a swapping past the sqrt ratio limit,
    // so we need to compute the result of swapping only to the limit
    if (
        (increasing && sqrtRatioNextFromAmount > sqrtRatioLimit)
            || (!increasing && sqrtRatioNextFromAmount < sqrtRatioLimit)
    ) {
        uint128 specifiedAmountDelta;
        uint128 calculatedAmountDelta;
        if (isToken1) {
            specifiedAmountDelta = amount1Delta(sqrtRatioLimit, sqrtRatio, liquidity, !isExactOut);
            calculatedAmountDelta = amount0Delta(sqrtRatioLimit, sqrtRatio, liquidity, isExactOut);
        } else {
            specifiedAmountDelta = amount0Delta(sqrtRatioLimit, sqrtRatio, liquidity, !isExactOut);
            calculatedAmountDelta = amount1Delta(sqrtRatioLimit, sqrtRatio, liquidity, isExactOut);
        }

        if (isExactOut) {
            uint128 beforeFee = amountBeforeFee(calculatedAmountDelta, fee);
            consumedAmount = -SafeCastLib.toInt128(specifiedAmountDelta);
            calculatedAmount = beforeFee;
            feeAmount = beforeFee - calculatedAmountDelta;
        } else {
            uint128 beforeFee = amountBeforeFee(specifiedAmountDelta, fee);
            consumedAmount = SafeCastLib.toInt128(beforeFee);
            calculatedAmount = calculatedAmountDelta;
            feeAmount = beforeFee - specifiedAmountDelta;
        }

        return SwapResult({
            consumedAmount: consumedAmount,
            calculatedAmount: calculatedAmount,
            sqrtRatioNext: sqrtRatioLimit,
            feeAmount: feeAmount
        });
    }

    if (sqrtRatioNextFromAmount == sqrtRatio) {
        assert(!isExactOut);

        return SwapResult({
            consumedAmount: amount,
            calculatedAmount: 0,
            sqrtRatioNext: sqrtRatio,
            feeAmount: uint128(amount)
        });
    }

    // rounds down for calculated == output, up for calculated == input
    uint128 calculatedAmountWithoutFee;
    if (isToken1) {
        calculatedAmountWithoutFee = amount0Delta(sqrtRatioNextFromAmount, sqrtRatio, liquidity, isExactOut);
    } else {
        calculatedAmountWithoutFee = amount1Delta(sqrtRatioNextFromAmount, sqrtRatio, liquidity, isExactOut);
    }

    // add on the fee to calculated amount for exact output
    if (isExactOut) {
        uint128 includingFee = amountBeforeFee(calculatedAmountWithoutFee, fee);
        calculatedAmount = includingFee;
        feeAmount = includingFee - calculatedAmountWithoutFee;
    } else {
        calculatedAmount = calculatedAmountWithoutFee;
        feeAmount = uint128(amount - priceImpactAmount);
    }

    return SwapResult({
        consumedAmount: amount,
        calculatedAmount: calculatedAmount,
        sqrtRatioNext: sqrtRatioNextFromAmount,
        feeAmount: feeAmount
    });
}

File 7 of 28 : position.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

import {FeesPerLiquidity} from "./feesPerLiquidity.sol";
import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol";

struct Position {
    uint128 liquidity;
    FeesPerLiquidity feesPerLiquidityInsideLast;
}

using {fees} for Position global;

/// @dev Returns the fee amounts of token0 and token1 owed to a position based on the given fees per liquidity inside snapshot
///      Note if the computed fees overflows the uint128 type, it will return only the lower 128 bits. It is assumed that accumulated
///      fees will never exceed type(uint128).max.
function fees(Position memory position, FeesPerLiquidity memory feesPerLiquidityInside)
    pure
    returns (uint128, uint128)
{
    FeesPerLiquidity memory difference = feesPerLiquidityInside.sub(position.feesPerLiquidityInsideLast);

    return (
        uint128(FixedPointMathLib.fullMulDivN(difference.value0, position.liquidity, 128)),
        uint128(FixedPointMathLib.fullMulDivN(difference.value1, position.liquidity, 128))
    );
}

File 8 of 28 : Ownable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @notice Simple single owner authorization mixin.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/auth/Ownable.sol)
///
/// @dev Note:
/// This implementation does NOT auto-initialize the owner to `msg.sender`.
/// You MUST call the `_initializeOwner` in the constructor / initializer.
///
/// While the ownable portion follows
/// [EIP-173](https://eips.ethereum.org/EIPS/eip-173) for compatibility,
/// the nomenclature for the 2-step ownership handover may be unique to this codebase.
abstract contract Ownable {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The caller is not authorized to call the function.
    error Unauthorized();

    /// @dev The `newOwner` cannot be the zero address.
    error NewOwnerIsZeroAddress();

    /// @dev The `pendingOwner` does not have a valid handover request.
    error NoHandoverRequest();

    /// @dev Cannot double-initialize.
    error AlreadyInitialized();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                           EVENTS                           */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The ownership is transferred from `oldOwner` to `newOwner`.
    /// This event is intentionally kept the same as OpenZeppelin's Ownable to be
    /// compatible with indexers and [EIP-173](https://eips.ethereum.org/EIPS/eip-173),
    /// despite it not being as lightweight as a single argument event.
    event OwnershipTransferred(address indexed oldOwner, address indexed newOwner);

    /// @dev An ownership handover to `pendingOwner` has been requested.
    event OwnershipHandoverRequested(address indexed pendingOwner);

    /// @dev The ownership handover to `pendingOwner` has been canceled.
    event OwnershipHandoverCanceled(address indexed pendingOwner);

    /// @dev `keccak256(bytes("OwnershipTransferred(address,address)"))`.
    uint256 private constant _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE =
        0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0;

    /// @dev `keccak256(bytes("OwnershipHandoverRequested(address)"))`.
    uint256 private constant _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE =
        0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d;

    /// @dev `keccak256(bytes("OwnershipHandoverCanceled(address)"))`.
    uint256 private constant _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE =
        0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                          STORAGE                           */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The owner slot is given by:
    /// `bytes32(~uint256(uint32(bytes4(keccak256("_OWNER_SLOT_NOT")))))`.
    /// It is intentionally chosen to be a high value
    /// to avoid collision with lower slots.
    /// The choice of manual storage layout is to enable compatibility
    /// with both regular and upgradeable contracts.
    bytes32 internal constant _OWNER_SLOT =
        0xffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927;

    /// The ownership handover slot of `newOwner` is given by:
    /// ```
    ///     mstore(0x00, or(shl(96, user), _HANDOVER_SLOT_SEED))
    ///     let handoverSlot := keccak256(0x00, 0x20)
    /// ```
    /// It stores the expiry timestamp of the two-step ownership handover.
    uint256 private constant _HANDOVER_SLOT_SEED = 0x389a75e1;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                     INTERNAL FUNCTIONS                     */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Override to return true to make `_initializeOwner` prevent double-initialization.
    function _guardInitializeOwner() internal pure virtual returns (bool guard) {}

    /// @dev Initializes the owner directly without authorization guard.
    /// This function must be called upon initialization,
    /// regardless of whether the contract is upgradeable or not.
    /// This is to enable generalization to both regular and upgradeable contracts,
    /// and to save gas in case the initial owner is not the caller.
    /// For performance reasons, this function will not check if there
    /// is an existing owner.
    function _initializeOwner(address newOwner) internal virtual {
        if (_guardInitializeOwner()) {
            /// @solidity memory-safe-assembly
            assembly {
                let ownerSlot := _OWNER_SLOT
                if sload(ownerSlot) {
                    mstore(0x00, 0x0dc149f0) // `AlreadyInitialized()`.
                    revert(0x1c, 0x04)
                }
                // Clean the upper 96 bits.
                newOwner := shr(96, shl(96, newOwner))
                // Store the new value.
                sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner))))
                // Emit the {OwnershipTransferred} event.
                log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner)
            }
        } else {
            /// @solidity memory-safe-assembly
            assembly {
                // Clean the upper 96 bits.
                newOwner := shr(96, shl(96, newOwner))
                // Store the new value.
                sstore(_OWNER_SLOT, newOwner)
                // Emit the {OwnershipTransferred} event.
                log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner)
            }
        }
    }

    /// @dev Sets the owner directly without authorization guard.
    function _setOwner(address newOwner) internal virtual {
        if (_guardInitializeOwner()) {
            /// @solidity memory-safe-assembly
            assembly {
                let ownerSlot := _OWNER_SLOT
                // Clean the upper 96 bits.
                newOwner := shr(96, shl(96, newOwner))
                // Emit the {OwnershipTransferred} event.
                log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner)
                // Store the new value.
                sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner))))
            }
        } else {
            /// @solidity memory-safe-assembly
            assembly {
                let ownerSlot := _OWNER_SLOT
                // Clean the upper 96 bits.
                newOwner := shr(96, shl(96, newOwner))
                // Emit the {OwnershipTransferred} event.
                log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner)
                // Store the new value.
                sstore(ownerSlot, newOwner)
            }
        }
    }

    /// @dev Throws if the sender is not the owner.
    function _checkOwner() internal view virtual {
        /// @solidity memory-safe-assembly
        assembly {
            // If the caller is not the stored owner, revert.
            if iszero(eq(caller(), sload(_OWNER_SLOT))) {
                mstore(0x00, 0x82b42900) // `Unauthorized()`.
                revert(0x1c, 0x04)
            }
        }
    }

    /// @dev Returns how long a two-step ownership handover is valid for in seconds.
    /// Override to return a different value if needed.
    /// Made internal to conserve bytecode. Wrap it in a public function if needed.
    function _ownershipHandoverValidFor() internal view virtual returns (uint64) {
        return 48 * 3600;
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                  PUBLIC UPDATE FUNCTIONS                   */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Allows the owner to transfer the ownership to `newOwner`.
    function transferOwnership(address newOwner) public payable virtual onlyOwner {
        /// @solidity memory-safe-assembly
        assembly {
            if iszero(shl(96, newOwner)) {
                mstore(0x00, 0x7448fbae) // `NewOwnerIsZeroAddress()`.
                revert(0x1c, 0x04)
            }
        }
        _setOwner(newOwner);
    }

    /// @dev Allows the owner to renounce their ownership.
    function renounceOwnership() public payable virtual onlyOwner {
        _setOwner(address(0));
    }

    /// @dev Request a two-step ownership handover to the caller.
    /// The request will automatically expire in 48 hours (172800 seconds) by default.
    function requestOwnershipHandover() public payable virtual {
        unchecked {
            uint256 expires = block.timestamp + _ownershipHandoverValidFor();
            /// @solidity memory-safe-assembly
            assembly {
                // Compute and set the handover slot to `expires`.
                mstore(0x0c, _HANDOVER_SLOT_SEED)
                mstore(0x00, caller())
                sstore(keccak256(0x0c, 0x20), expires)
                // Emit the {OwnershipHandoverRequested} event.
                log2(0, 0, _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE, caller())
            }
        }
    }

    /// @dev Cancels the two-step ownership handover to the caller, if any.
    function cancelOwnershipHandover() public payable virtual {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute and set the handover slot to 0.
            mstore(0x0c, _HANDOVER_SLOT_SEED)
            mstore(0x00, caller())
            sstore(keccak256(0x0c, 0x20), 0)
            // Emit the {OwnershipHandoverCanceled} event.
            log2(0, 0, _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE, caller())
        }
    }

    /// @dev Allows the owner to complete the two-step ownership handover to `pendingOwner`.
    /// Reverts if there is no existing ownership handover requested by `pendingOwner`.
    function completeOwnershipHandover(address pendingOwner) public payable virtual onlyOwner {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute and set the handover slot to 0.
            mstore(0x0c, _HANDOVER_SLOT_SEED)
            mstore(0x00, pendingOwner)
            let handoverSlot := keccak256(0x0c, 0x20)
            // If the handover does not exist, or has expired.
            if gt(timestamp(), sload(handoverSlot)) {
                mstore(0x00, 0x6f5e8818) // `NoHandoverRequest()`.
                revert(0x1c, 0x04)
            }
            // Set the handover slot to 0.
            sstore(handoverSlot, 0)
        }
        _setOwner(pendingOwner);
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                   PUBLIC READ FUNCTIONS                    */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Returns the owner of the contract.
    function owner() public view virtual returns (address result) {
        /// @solidity memory-safe-assembly
        assembly {
            result := sload(_OWNER_SLOT)
        }
    }

    /// @dev Returns the expiry timestamp for the two-step ownership handover to `pendingOwner`.
    function ownershipHandoverExpiresAt(address pendingOwner)
        public
        view
        virtual
        returns (uint256 result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            // Compute the handover slot.
            mstore(0x0c, _HANDOVER_SLOT_SEED)
            mstore(0x00, pendingOwner)
            // Load the handover slot.
            result := sload(keccak256(0x0c, 0x20))
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                         MODIFIERS                          */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Marks a function as only callable by the owner.
    modifier onlyOwner() virtual {
        _checkOwner();
        _;
    }
}

File 9 of 28 : ticks.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

import {MAX_TICK_SPACING, MAX_TICK_MAGNITUDE} from "./constants.sol";
import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol";
import {SqrtRatio, toSqrtRatio} from "../types/sqrtRatio.sol";

error InvalidTick(int32 tick);

// Returns the sqrtRatio corresponding for the tick
function tickToSqrtRatio(int32 tick) pure returns (SqrtRatio r) {
    unchecked {
        uint256 t = FixedPointMathLib.abs(tick);
        if (t > MAX_TICK_MAGNITUDE) revert InvalidTick(tick);

        uint256 ratio;
        assembly ("memory-safe") {
            ratio := sub(0x100000000000000000000000000000000, mul(and(t, 0x1), 0x8637b66cd638344daef276cd7c5))
        }

        if ((t & 0x2) != 0) {
            ratio = (ratio * 0xffffef390978c398134b4ff3764fe410) >> 128;
        }
        if ((t & 0x4) != 0) {
            ratio = (ratio * 0xffffde72140b00a354bd3dc828e976c9) >> 128;
        }
        if ((t & 0x8) != 0) {
            ratio = (ratio * 0xffffbce42c7be6c998ad6318193c0b18) >> 128;
        }
        if ((t & 0x10) != 0) {
            ratio = (ratio * 0xffff79c86a8f6150a32d9778eceef97c) >> 128;
        }
        if ((t & 0x20) != 0) {
            ratio = (ratio * 0xfffef3911b7cff24ba1b3dbb5f8f5974) >> 128;
        }
        if ((t & 0x40) != 0) {
            ratio = (ratio * 0xfffde72350725cc4ea8feece3b5f13c8) >> 128;
        }
        if ((t & 0x80) != 0) {
            ratio = (ratio * 0xfffbce4b06c196e9247ac87695d53c60) >> 128;
        }
        if ((t & 0x100) != 0) {
            ratio = (ratio * 0xfff79ca7a4d1bf1ee8556cea23cdbaa5) >> 128;
        }
        if ((t & 0x200) != 0) {
            ratio = (ratio * 0xffef3995a5b6a6267530f207142a5764) >> 128;
        }
        if ((t & 0x400) != 0) {
            ratio = (ratio * 0xffde7444b28145508125d10077ba83b8) >> 128;
        }
        if ((t & 0x800) != 0) {
            ratio = (ratio * 0xffbceceeb791747f10df216f2e53ec57) >> 128;
        }
        if ((t & 0x1000) != 0) {
            ratio = (ratio * 0xff79eb706b9a64c6431d76e63531e929) >> 128;
        }
        if ((t & 0x2000) != 0) {
            ratio = (ratio * 0xfef41d1a5f2ae3a20676bec6f7f9459a) >> 128;
        }
        if ((t & 0x4000) != 0) {
            ratio = (ratio * 0xfde95287d26d81bea159c37073122c73) >> 128;
        }
        if ((t & 0x8000) != 0) {
            ratio = (ratio * 0xfbd701c7cbc4c8a6bb81efd232d1e4e7) >> 128;
        }
        if ((t & 0x10000) != 0) {
            ratio = (ratio * 0xf7bf5211c72f5185f372aeb1d48f937e) >> 128;
        }
        if ((t & 0x20000) != 0) {
            ratio = (ratio * 0xefc2bf59df33ecc28125cf78ec4f167f) >> 128;
        }
        if ((t & 0x40000) != 0) {
            ratio = (ratio * 0xe08d35706200796273f0b3a981d90cfd) >> 128;
        }
        if ((t & 0x80000) != 0) {
            ratio = (ratio * 0xc4f76b68947482dc198a48a54348c4ed) >> 128;
        }
        if ((t & 0x100000) != 0) {
            ratio = (ratio * 0x978bcb9894317807e5fa4498eee7c0fa) >> 128;
        }
        if ((t & 0x200000) != 0) {
            ratio = (ratio * 0x59b63684b86e9f486ec54727371ba6ca) >> 128;
        }
        if ((t & 0x400000) != 0) {
            ratio = (ratio * 0x1f703399d88f6aa83a28b22d4a1f56e3) >> 128;
        }
        if ((t & 0x800000) != 0) {
            ratio = (ratio * 0x3dc5dac7376e20fc8679758d1bcdcfc) >> 128;
        }
        if ((t & 0x1000000) != 0) {
            ratio = (ratio * 0xee7e32d61fdb0a5e622b820f681d0) >> 128;
        }
        if ((t & 0x2000000) != 0) {
            ratio = (ratio * 0xde2ee4bc381afa7089aa84bb66) >> 128;
        }
        if ((t & 0x4000000) != 0) {
            ratio = (ratio * 0xc0d55d4d7152c25fb139) >> 128;
        }

        if (tick > 0) {
            ratio = type(uint256).max / ratio;
        }

        r = toSqrtRatio(ratio, false);
    }
}

function sqrtRatioToTick(SqrtRatio sqrtRatio) pure returns (int32) {
    unchecked {
        uint256 sqrtRatioFixed = sqrtRatio.toFixed();

        bool negative = (sqrtRatioFixed >> 128) == 0;

        uint256 x = negative ? (type(uint256).max / sqrtRatioFixed) : sqrtRatioFixed;

        // we know x >> 128 is never zero because we check bounds above and then reciprocate sqrtRatio if the high 128 bits are zero
        // so we don't need to handle the exceptional case of log2(0)
        uint256 msbHigh = FixedPointMathLib.log2(x >> 128);
        x = x >> (msbHigh + 1);
        uint256 log2_unsigned = msbHigh * 0x10000000000000000;

        assembly ("memory-safe") {
            // 63
            x := shr(127, mul(x, x))
            let is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x8000000000000000))
            x := shr(is_high_nonzero, x)

            // 62
            x := shr(127, mul(x, x))
            is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x4000000000000000))
            x := shr(is_high_nonzero, x)

            // 61
            x := shr(127, mul(x, x))
            is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x2000000000000000))
            x := shr(is_high_nonzero, x)

            // 60
            x := shr(127, mul(x, x))
            is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x1000000000000000))
            x := shr(is_high_nonzero, x)

            // 59
            x := shr(127, mul(x, x))
            is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x800000000000000))
            x := shr(is_high_nonzero, x)

            // 58
            x := shr(127, mul(x, x))
            is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x400000000000000))
            x := shr(is_high_nonzero, x)

            // 57
            x := shr(127, mul(x, x))
            is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x200000000000000))
            x := shr(is_high_nonzero, x)

            // 56
            x := shr(127, mul(x, x))
            is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x100000000000000))
            x := shr(is_high_nonzero, x)

            // 55
            x := shr(127, mul(x, x))
            is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x80000000000000))
            x := shr(is_high_nonzero, x)

            // 54
            x := shr(127, mul(x, x))
            is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x40000000000000))
            x := shr(is_high_nonzero, x)

            // 53
            x := shr(127, mul(x, x))
            is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x20000000000000))
            x := shr(is_high_nonzero, x)

            // 52
            x := shr(127, mul(x, x))
            is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x10000000000000))
            x := shr(is_high_nonzero, x)

            // 51
            x := shr(127, mul(x, x))
            is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x8000000000000))
            x := shr(is_high_nonzero, x)

            // 50
            x := shr(127, mul(x, x))
            is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x4000000000000))
            x := shr(is_high_nonzero, x)

            // 49
            x := shr(127, mul(x, x))
            is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x2000000000000))
            x := shr(is_high_nonzero, x)

            // 48
            x := shr(127, mul(x, x))
            is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x1000000000000))
            x := shr(is_high_nonzero, x)

            // 47
            x := shr(127, mul(x, x))
            is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x800000000000))
            x := shr(is_high_nonzero, x)

            // 46
            x := shr(127, mul(x, x))
            is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x400000000000))
            x := shr(is_high_nonzero, x)

            // 45
            x := shr(127, mul(x, x))
            is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x200000000000))
            x := shr(is_high_nonzero, x)

            // 44
            x := shr(127, mul(x, x))
            is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x100000000000))
            x := shr(is_high_nonzero, x)

            // 43
            x := shr(127, mul(x, x))
            is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x80000000000))
            x := shr(is_high_nonzero, x)

            // 42
            x := shr(127, mul(x, x))
            is_high_nonzero := eq(iszero(shr(128, x)), 0)
            log2_unsigned := add(log2_unsigned, mul(is_high_nonzero, 0x40000000000))
        }

        // 25572630076711825471857579 == 2**64/(log base 2 of sqrt tick size)
        // https://www.wolframalpha.com/input?i=floor%28%281%2F+log+base+2+of+%28sqrt%281.000001%29%29%29*2**64%29
        int256 logBaseTickSizeX128 =
            (negative ? -int256(log2_unsigned) : int256(log2_unsigned)) * 25572630076711825471857579;

        int32 tickLow;
        int32 tickHigh;

        if (negative) {
            tickLow = int32((logBaseTickSizeX128 - 112469616488610087266845472033458199637) >> 128);
            tickHigh = int32((logBaseTickSizeX128) >> 128);
        } else {
            tickLow = int32((logBaseTickSizeX128) >> 128);
            tickHigh = int32((logBaseTickSizeX128 + 112469616488610087266845472033458199637) >> 128);
        }

        if (tickLow == tickHigh) {
            return tickLow;
        }

        if (tickToSqrtRatio(tickHigh) <= sqrtRatio) return tickHigh;

        return tickLow;
    }
}

File 10 of 28 : bitmap.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

import {LibBit} from "solady/utils/LibBit.sol";

type Bitmap is uint256;

using {toggle, isSet, leSetBit, geSetBit} for Bitmap global;

function toggle(Bitmap bitmap, uint8 index) pure returns (Bitmap result) {
    assembly ("memory-safe") {
        result := xor(bitmap, shl(index, 1))
    }
}

function isSet(Bitmap bitmap, uint8 index) pure returns (bool yes) {
    assembly ("memory-safe") {
        yes := and(shr(index, bitmap), 1)
    }
}

// Returns the index of the most significant bit that is set _and_ less or equally significant to index, or 256 if no such bit exists.
function leSetBit(Bitmap bitmap, uint8 index) pure returns (uint256) {
    unchecked {
        uint256 masked;
        assembly ("memory-safe") {
            masked := and(bitmap, sub(shl(add(index, 1), 1), 1))
        }
        return LibBit.fls(masked);
    }
}

// Returns the index of the least significant bit that is set _and_ more or equally significant to index, or 256 if no such bit exists.
function geSetBit(Bitmap bitmap, uint8 index) pure returns (uint256) {
    unchecked {
        uint256 masked;
        assembly ("memory-safe") {
            masked := and(bitmap, not(sub(shl(index, 1), 1)))
        }
        return LibBit.ffs(masked);
    }
}

File 11 of 28 : FixedPointMathLib.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @notice Arithmetic library with operations for fixed-point numbers.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/FixedPointMathLib.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol)
library FixedPointMathLib {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The operation failed, as the output exceeds the maximum value of uint256.
    error ExpOverflow();

    /// @dev The operation failed, as the output exceeds the maximum value of uint256.
    error FactorialOverflow();

    /// @dev The operation failed, due to an overflow.
    error RPowOverflow();

    /// @dev The mantissa is too big to fit.
    error MantissaOverflow();

    /// @dev The operation failed, due to an multiplication overflow.
    error MulWadFailed();

    /// @dev The operation failed, due to an multiplication overflow.
    error SMulWadFailed();

    /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.
    error DivWadFailed();

    /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.
    error SDivWadFailed();

    /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero.
    error MulDivFailed();

    /// @dev The division failed, as the denominator is zero.
    error DivFailed();

    /// @dev The full precision multiply-divide operation failed, either due
    /// to the result being larger than 256 bits, or a division by a zero.
    error FullMulDivFailed();

    /// @dev The output is undefined, as the input is less-than-or-equal to zero.
    error LnWadUndefined();

    /// @dev The input outside the acceptable domain.
    error OutOfDomain();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                         CONSTANTS                          */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The scalar of ETH and most ERC20s.
    uint256 internal constant WAD = 1e18;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*              SIMPLIFIED FIXED POINT OPERATIONS             */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Equivalent to `(x * y) / WAD` rounded down.
    function mulWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`.
            if gt(x, div(not(0), y)) {
                if y {
                    mstore(0x00, 0xbac65e5b) // `MulWadFailed()`.
                    revert(0x1c, 0x04)
                }
            }
            z := div(mul(x, y), WAD)
        }
    }

    /// @dev Equivalent to `(x * y) / WAD` rounded down.
    function sMulWad(int256 x, int256 y) internal pure returns (int256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := mul(x, y)
            // Equivalent to `require((x == 0 || z / x == y) && !(x == -1 && y == type(int256).min))`.
            if iszero(gt(or(iszero(x), eq(sdiv(z, x), y)), lt(not(x), eq(y, shl(255, 1))))) {
                mstore(0x00, 0xedcd4dd4) // `SMulWadFailed()`.
                revert(0x1c, 0x04)
            }
            z := sdiv(z, WAD)
        }
    }

    /// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks.
    function rawMulWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := div(mul(x, y), WAD)
        }
    }

    /// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks.
    function rawSMulWad(int256 x, int256 y) internal pure returns (int256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := sdiv(mul(x, y), WAD)
        }
    }

    /// @dev Equivalent to `(x * y) / WAD` rounded up.
    function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := mul(x, y)
            // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`.
            if iszero(eq(div(z, y), x)) {
                if y {
                    mstore(0x00, 0xbac65e5b) // `MulWadFailed()`.
                    revert(0x1c, 0x04)
                }
            }
            z := add(iszero(iszero(mod(z, WAD))), div(z, WAD))
        }
    }

    /// @dev Equivalent to `(x * y) / WAD` rounded up, but without overflow checks.
    function rawMulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := add(iszero(iszero(mod(mul(x, y), WAD))), div(mul(x, y), WAD))
        }
    }

    /// @dev Equivalent to `(x * WAD) / y` rounded down.
    function divWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            // Equivalent to `require(y != 0 && x <= type(uint256).max / WAD)`.
            if iszero(mul(y, lt(x, add(1, div(not(0), WAD))))) {
                mstore(0x00, 0x7c5f487d) // `DivWadFailed()`.
                revert(0x1c, 0x04)
            }
            z := div(mul(x, WAD), y)
        }
    }

    /// @dev Equivalent to `(x * WAD) / y` rounded down.
    function sDivWad(int256 x, int256 y) internal pure returns (int256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := mul(x, WAD)
            // Equivalent to `require(y != 0 && ((x * WAD) / WAD == x))`.
            if iszero(mul(y, eq(sdiv(z, WAD), x))) {
                mstore(0x00, 0x5c43740d) // `SDivWadFailed()`.
                revert(0x1c, 0x04)
            }
            z := sdiv(z, y)
        }
    }

    /// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks.
    function rawDivWad(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := div(mul(x, WAD), y)
        }
    }

    /// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks.
    function rawSDivWad(int256 x, int256 y) internal pure returns (int256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := sdiv(mul(x, WAD), y)
        }
    }

    /// @dev Equivalent to `(x * WAD) / y` rounded up.
    function divWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            // Equivalent to `require(y != 0 && x <= type(uint256).max / WAD)`.
            if iszero(mul(y, lt(x, add(1, div(not(0), WAD))))) {
                mstore(0x00, 0x7c5f487d) // `DivWadFailed()`.
                revert(0x1c, 0x04)
            }
            z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y))
        }
    }

    /// @dev Equivalent to `(x * WAD) / y` rounded up, but without overflow and divide by zero checks.
    function rawDivWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y))
        }
    }

    /// @dev Equivalent to `x` to the power of `y`.
    /// because `x ** y = (e ** ln(x)) ** y = e ** (ln(x) * y)`.
    /// Note: This function is an approximation.
    function powWad(int256 x, int256 y) internal pure returns (int256) {
        // Using `ln(x)` means `x` must be greater than 0.
        return expWad((lnWad(x) * y) / int256(WAD));
    }

    /// @dev Returns `exp(x)`, denominated in `WAD`.
    /// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln
    /// Note: This function is an approximation. Monotonically increasing.
    function expWad(int256 x) internal pure returns (int256 r) {
        unchecked {
            // When the result is less than 0.5 we return zero.
            // This happens when `x <= (log(1e-18) * 1e18) ~ -4.15e19`.
            if (x <= -41446531673892822313) return r;

            /// @solidity memory-safe-assembly
            assembly {
                // When the result is greater than `(2**255 - 1) / 1e18` we can not represent it as
                // an int. This happens when `x >= floor(log((2**255 - 1) / 1e18) * 1e18) ≈ 135`.
                if iszero(slt(x, 135305999368893231589)) {
                    mstore(0x00, 0xa37bfec9) // `ExpOverflow()`.
                    revert(0x1c, 0x04)
                }
            }

            // `x` is now in the range `(-42, 136) * 1e18`. Convert to `(-42, 136) * 2**96`
            // for more intermediate precision and a binary basis. This base conversion
            // is a multiplication by 1e18 / 2**96 = 5**18 / 2**78.
            x = (x << 78) / 5 ** 18;

            // Reduce range of x to (-½ ln 2, ½ ln 2) * 2**96 by factoring out powers
            // of two such that exp(x) = exp(x') * 2**k, where k is an integer.
            // Solving this gives k = round(x / log(2)) and x' = x - k * log(2).
            int256 k = ((x << 96) / 54916777467707473351141471128 + 2 ** 95) >> 96;
            x = x - k * 54916777467707473351141471128;

            // `k` is in the range `[-61, 195]`.

            // Evaluate using a (6, 7)-term rational approximation.
            // `p` is made monic, we'll multiply by a scale factor later.
            int256 y = x + 1346386616545796478920950773328;
            y = ((y * x) >> 96) + 57155421227552351082224309758442;
            int256 p = y + x - 94201549194550492254356042504812;
            p = ((p * y) >> 96) + 28719021644029726153956944680412240;
            p = p * x + (4385272521454847904659076985693276 << 96);

            // We leave `p` in `2**192` basis so we don't need to scale it back up for the division.
            int256 q = x - 2855989394907223263936484059900;
            q = ((q * x) >> 96) + 50020603652535783019961831881945;
            q = ((q * x) >> 96) - 533845033583426703283633433725380;
            q = ((q * x) >> 96) + 3604857256930695427073651918091429;
            q = ((q * x) >> 96) - 14423608567350463180887372962807573;
            q = ((q * x) >> 96) + 26449188498355588339934803723976023;

            /// @solidity memory-safe-assembly
            assembly {
                // Div in assembly because solidity adds a zero check despite the unchecked.
                // The q polynomial won't have zeros in the domain as all its roots are complex.
                // No scaling is necessary because p is already `2**96` too large.
                r := sdiv(p, q)
            }

            // r should be in the range `(0.09, 0.25) * 2**96`.

            // We now need to multiply r by:
            // - The scale factor `s ≈ 6.031367120`.
            // - The `2**k` factor from the range reduction.
            // - The `1e18 / 2**96` factor for base conversion.
            // We do this all at once, with an intermediate result in `2**213`
            // basis, so the final right shift is always by a positive amount.
            r = int256(
                (uint256(r) * 3822833074963236453042738258902158003155416615667) >> uint256(195 - k)
            );
        }
    }

    /// @dev Returns `ln(x)`, denominated in `WAD`.
    /// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln
    /// Note: This function is an approximation. Monotonically increasing.
    function lnWad(int256 x) internal pure returns (int256 r) {
        /// @solidity memory-safe-assembly
        assembly {
            // We want to convert `x` from `10**18` fixed point to `2**96` fixed point.
            // We do this by multiplying by `2**96 / 10**18`. But since
            // `ln(x * C) = ln(x) + ln(C)`, we can simply do nothing here
            // and add `ln(2**96 / 10**18)` at the end.

            // Compute `k = log2(x) - 96`, `r = 159 - k = 255 - log2(x) = 255 ^ log2(x)`.
            r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
            r := or(r, shl(4, lt(0xffff, shr(r, x))))
            r := or(r, shl(3, lt(0xff, shr(r, x))))
            // We place the check here for more optimal stack operations.
            if iszero(sgt(x, 0)) {
                mstore(0x00, 0x1615e638) // `LnWadUndefined()`.
                revert(0x1c, 0x04)
            }
            // forgefmt: disable-next-item
            r := xor(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),
                0xf8f9f9faf9fdfafbf9fdfcfdfafbfcfef9fafdfafcfcfbfefafafcfbffffffff))

            // Reduce range of x to (1, 2) * 2**96
            // ln(2^k * x) = k * ln(2) + ln(x)
            x := shr(159, shl(r, x))

            // Evaluate using a (8, 8)-term rational approximation.
            // `p` is made monic, we will multiply by a scale factor later.
            // forgefmt: disable-next-item
            let p := sub( // This heavily nested expression is to avoid stack-too-deep for via-ir.
                sar(96, mul(add(43456485725739037958740375743393,
                sar(96, mul(add(24828157081833163892658089445524,
                sar(96, mul(add(3273285459638523848632254066296,
                    x), x))), x))), x)), 11111509109440967052023855526967)
            p := sub(sar(96, mul(p, x)), 45023709667254063763336534515857)
            p := sub(sar(96, mul(p, x)), 14706773417378608786704636184526)
            p := sub(mul(p, x), shl(96, 795164235651350426258249787498))
            // We leave `p` in `2**192` basis so we don't need to scale it back up for the division.

            // `q` is monic by convention.
            let q := add(5573035233440673466300451813936, x)
            q := add(71694874799317883764090561454958, sar(96, mul(x, q)))
            q := add(283447036172924575727196451306956, sar(96, mul(x, q)))
            q := add(401686690394027663651624208769553, sar(96, mul(x, q)))
            q := add(204048457590392012362485061816622, sar(96, mul(x, q)))
            q := add(31853899698501571402653359427138, sar(96, mul(x, q)))
            q := add(909429971244387300277376558375, sar(96, mul(x, q)))

            // `p / q` is in the range `(0, 0.125) * 2**96`.

            // Finalization, we need to:
            // - Multiply by the scale factor `s = 5.549…`.
            // - Add `ln(2**96 / 10**18)`.
            // - Add `k * ln(2)`.
            // - Multiply by `10**18 / 2**96 = 5**18 >> 78`.

            // The q polynomial is known not to have zeros in the domain.
            // No scaling required because p is already `2**96` too large.
            p := sdiv(p, q)
            // Multiply by the scaling factor: `s * 5**18 * 2**96`, base is now `5**18 * 2**192`.
            p := mul(1677202110996718588342820967067443963516166, p)
            // Add `ln(2) * k * 5**18 * 2**192`.
            // forgefmt: disable-next-item
            p := add(mul(16597577552685614221487285958193947469193820559219878177908093499208371, sub(159, r)), p)
            // Add `ln(2**96 / 10**18) * 5**18 * 2**192`.
            p := add(600920179829731861736702779321621459595472258049074101567377883020018308, p)
            // Base conversion: mul `2**18 / 2**192`.
            r := sar(174, p)
        }
    }

    /// @dev Returns `W_0(x)`, denominated in `WAD`.
    /// See: https://en.wikipedia.org/wiki/Lambert_W_function
    /// a.k.a. Product log function. This is an approximation of the principal branch.
    /// Note: This function is an approximation. Monotonically increasing.
    function lambertW0Wad(int256 x) internal pure returns (int256 w) {
        // forgefmt: disable-next-item
        unchecked {
            if ((w = x) <= -367879441171442322) revert OutOfDomain(); // `x` less than `-1/e`.
            (int256 wad, int256 p) = (int256(WAD), x);
            uint256 c; // Whether we need to avoid catastrophic cancellation.
            uint256 i = 4; // Number of iterations.
            if (w <= 0x1ffffffffffff) {
                if (-0x4000000000000 <= w) {
                    i = 1; // Inputs near zero only take one step to converge.
                } else if (w <= -0x3ffffffffffffff) {
                    i = 32; // Inputs near `-1/e` take very long to converge.
                }
            } else if (uint256(w >> 63) == uint256(0)) {
                /// @solidity memory-safe-assembly
                assembly {
                    // Inline log2 for more performance, since the range is small.
                    let v := shr(49, w)
                    let l := shl(3, lt(0xff, v))
                    l := add(or(l, byte(and(0x1f, shr(shr(l, v), 0x8421084210842108cc6318c6db6d54be)),
                        0x0706060506020504060203020504030106050205030304010505030400000000)), 49)
                    w := sdiv(shl(l, 7), byte(sub(l, 31), 0x0303030303030303040506080c13))
                    c := gt(l, 60)
                    i := add(2, add(gt(l, 53), c))
                }
            } else {
                int256 ll = lnWad(w = lnWad(w));
                /// @solidity memory-safe-assembly
                assembly {
                    // `w = ln(x) - ln(ln(x)) + b * ln(ln(x)) / ln(x)`.
                    w := add(sdiv(mul(ll, 1023715080943847266), w), sub(w, ll))
                    i := add(3, iszero(shr(68, x)))
                    c := iszero(shr(143, x))
                }
                if (c == uint256(0)) {
                    do { // If `x` is big, use Newton's so that intermediate values won't overflow.
                        int256 e = expWad(w);
                        /// @solidity memory-safe-assembly
                        assembly {
                            let t := mul(w, div(e, wad))
                            w := sub(w, sdiv(sub(t, x), div(add(e, t), wad)))
                        }
                        if (p <= w) break;
                        p = w;
                    } while (--i != uint256(0));
                    /// @solidity memory-safe-assembly
                    assembly {
                        w := sub(w, sgt(w, 2))
                    }
                    return w;
                }
            }
            do { // Otherwise, use Halley's for faster convergence.
                int256 e = expWad(w);
                /// @solidity memory-safe-assembly
                assembly {
                    let t := add(w, wad)
                    let s := sub(mul(w, e), mul(x, wad))
                    w := sub(w, sdiv(mul(s, wad), sub(mul(e, t), sdiv(mul(add(t, wad), s), add(t, t)))))
                }
                if (p <= w) break;
                p = w;
            } while (--i != c);
            /// @solidity memory-safe-assembly
            assembly {
                w := sub(w, sgt(w, 2))
            }
            // For certain ranges of `x`, we'll use the quadratic-rate recursive formula of
            // R. Iacono and J.P. Boyd for the last iteration, to avoid catastrophic cancellation.
            if (c == uint256(0)) return w;
            int256 t = w | 1;
            /// @solidity memory-safe-assembly
            assembly {
                x := sdiv(mul(x, wad), t)
            }
            x = (t * (wad + lnWad(x)));
            /// @solidity memory-safe-assembly
            assembly {
                w := sdiv(x, add(wad, t))
            }
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                  GENERAL NUMBER UTILITIES                  */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Returns `a * b == x * y`, with full precision.
    function fullMulEq(uint256 a, uint256 b, uint256 x, uint256 y)
        internal
        pure
        returns (bool result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            result := and(eq(mul(a, b), mul(x, y)), eq(mulmod(x, y, not(0)), mulmod(a, b, not(0))))
        }
    }

    /// @dev Calculates `floor(x * y / d)` with full precision.
    /// Throws if result overflows a uint256 or when `d` is zero.
    /// Credit to Remco Bloemen under MIT license: https://2π.com/21/muldiv
    function fullMulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            // 512-bit multiply `[p1 p0] = x * y`.
            // Compute the product mod `2**256` and mod `2**256 - 1`
            // then use the Chinese Remainder Theorem to reconstruct
            // the 512 bit result. The result is stored in two 256
            // variables such that `product = p1 * 2**256 + p0`.

            // Temporarily use `z` as `p0` to save gas.
            z := mul(x, y) // Lower 256 bits of `x * y`.
            for {} 1 {} {
                // If overflows.
                if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) {
                    let mm := mulmod(x, y, not(0))
                    let p1 := sub(mm, add(z, lt(mm, z))) // Upper 256 bits of `x * y`.

                    /*------------------- 512 by 256 division --------------------*/

                    // Make division exact by subtracting the remainder from `[p1 p0]`.
                    let r := mulmod(x, y, d) // Compute remainder using mulmod.
                    let t := and(d, sub(0, d)) // The least significant bit of `d`. `t >= 1`.
                    // Make sure `z` is less than `2**256`. Also prevents `d == 0`.
                    // Placing the check here seems to give more optimal stack operations.
                    if iszero(gt(d, p1)) {
                        mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
                        revert(0x1c, 0x04)
                    }
                    d := div(d, t) // Divide `d` by `t`, which is a power of two.
                    // Invert `d mod 2**256`
                    // Now that `d` is an odd number, it has an inverse
                    // modulo `2**256` such that `d * inv = 1 mod 2**256`.
                    // Compute the inverse by starting with a seed that is correct
                    // correct for four bits. That is, `d * inv = 1 mod 2**4`.
                    let inv := xor(2, mul(3, d))
                    // Now use Newton-Raphson iteration to improve the precision.
                    // Thanks to Hensel's lifting lemma, this also works in modular
                    // arithmetic, doubling the correct bits in each step.
                    inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**8
                    inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**16
                    inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**32
                    inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**64
                    inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**128
                    z :=
                        mul(
                            // Divide [p1 p0] by the factors of two.
                            // Shift in bits from `p1` into `p0`. For this we need
                            // to flip `t` such that it is `2**256 / t`.
                            or(mul(sub(p1, gt(r, z)), add(div(sub(0, t), t), 1)), div(sub(z, r), t)),
                            mul(sub(2, mul(d, inv)), inv) // inverse mod 2**256
                        )
                    break
                }
                z := div(z, d)
                break
            }
        }
    }

    /// @dev Calculates `floor(x * y / d)` with full precision.
    /// Behavior is undefined if `d` is zero or the final result cannot fit in 256 bits.
    /// Performs the full 512 bit calculation regardless.
    function fullMulDivUnchecked(uint256 x, uint256 y, uint256 d)
        internal
        pure
        returns (uint256 z)
    {
        /// @solidity memory-safe-assembly
        assembly {
            z := mul(x, y)
            let mm := mulmod(x, y, not(0))
            let p1 := sub(mm, add(z, lt(mm, z)))
            let t := and(d, sub(0, d))
            let r := mulmod(x, y, d)
            d := div(d, t)
            let inv := xor(2, mul(3, d))
            inv := mul(inv, sub(2, mul(d, inv)))
            inv := mul(inv, sub(2, mul(d, inv)))
            inv := mul(inv, sub(2, mul(d, inv)))
            inv := mul(inv, sub(2, mul(d, inv)))
            inv := mul(inv, sub(2, mul(d, inv)))
            z :=
                mul(
                    or(mul(sub(p1, gt(r, z)), add(div(sub(0, t), t), 1)), div(sub(z, r), t)),
                    mul(sub(2, mul(d, inv)), inv)
                )
        }
    }

    /// @dev Calculates `floor(x * y / d)` with full precision, rounded up.
    /// Throws if result overflows a uint256 or when `d` is zero.
    /// Credit to Uniswap-v3-core under MIT license:
    /// https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/FullMath.sol
    function fullMulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
        z = fullMulDiv(x, y, d);
        /// @solidity memory-safe-assembly
        assembly {
            if mulmod(x, y, d) {
                z := add(z, 1)
                if iszero(z) {
                    mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
                    revert(0x1c, 0x04)
                }
            }
        }
    }

    /// @dev Calculates `floor(x * y / 2 ** n)` with full precision.
    /// Throws if result overflows a uint256.
    /// Credit to Philogy under MIT license:
    /// https://github.com/SorellaLabs/angstrom/blob/main/contracts/src/libraries/X128MathLib.sol
    function fullMulDivN(uint256 x, uint256 y, uint8 n) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            // Temporarily use `z` as `p0` to save gas.
            z := mul(x, y) // Lower 256 bits of `x * y`. We'll call this `z`.
            for {} 1 {} {
                if iszero(or(iszero(x), eq(div(z, x), y))) {
                    let k := and(n, 0xff) // `n`, cleaned.
                    let mm := mulmod(x, y, not(0))
                    let p1 := sub(mm, add(z, lt(mm, z))) // Upper 256 bits of `x * y`.
                    //         |      p1     |      z     |
                    // Before: | p1_0 ¦ p1_1 | z_0  ¦ z_1 |
                    // Final:  |   0  ¦ p1_0 | p1_1 ¦ z_0 |
                    // Check that final `z` doesn't overflow by checking that p1_0 = 0.
                    if iszero(shr(k, p1)) {
                        z := add(shl(sub(256, k), p1), shr(k, z))
                        break
                    }
                    mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
                    revert(0x1c, 0x04)
                }
                z := shr(and(n, 0xff), z)
                break
            }
        }
    }

    /// @dev Returns `floor(x * y / d)`.
    /// Reverts if `x * y` overflows, or `d` is zero.
    function mulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := mul(x, y)
            // Equivalent to `require(d != 0 && (y == 0 || x <= type(uint256).max / y))`.
            if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) {
                mstore(0x00, 0xad251c27) // `MulDivFailed()`.
                revert(0x1c, 0x04)
            }
            z := div(z, d)
        }
    }

    /// @dev Returns `ceil(x * y / d)`.
    /// Reverts if `x * y` overflows, or `d` is zero.
    function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := mul(x, y)
            // Equivalent to `require(d != 0 && (y == 0 || x <= type(uint256).max / y))`.
            if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) {
                mstore(0x00, 0xad251c27) // `MulDivFailed()`.
                revert(0x1c, 0x04)
            }
            z := add(iszero(iszero(mod(z, d))), div(z, d))
        }
    }

    /// @dev Returns `x`, the modular multiplicative inverse of `a`, such that `(a * x) % n == 1`.
    function invMod(uint256 a, uint256 n) internal pure returns (uint256 x) {
        /// @solidity memory-safe-assembly
        assembly {
            let g := n
            let r := mod(a, n)
            for { let y := 1 } 1 {} {
                let q := div(g, r)
                let t := g
                g := r
                r := sub(t, mul(r, q))
                let u := x
                x := y
                y := sub(u, mul(y, q))
                if iszero(r) { break }
            }
            x := mul(eq(g, 1), add(x, mul(slt(x, 0), n)))
        }
    }

    /// @dev Returns `ceil(x / d)`.
    /// Reverts if `d` is zero.
    function divUp(uint256 x, uint256 d) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            if iszero(d) {
                mstore(0x00, 0x65244e4e) // `DivFailed()`.
                revert(0x1c, 0x04)
            }
            z := add(iszero(iszero(mod(x, d))), div(x, d))
        }
    }

    /// @dev Returns `max(0, x - y)`. Alias for `saturatingSub`.
    function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := mul(gt(x, y), sub(x, y))
        }
    }

    /// @dev Returns `max(0, x - y)`.
    function saturatingSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := mul(gt(x, y), sub(x, y))
        }
    }

    /// @dev Returns `min(2 ** 256 - 1, x + y)`.
    function saturatingAdd(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := or(sub(0, lt(add(x, y), x)), add(x, y))
        }
    }

    /// @dev Returns `min(2 ** 256 - 1, x * y)`.
    function saturatingMul(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := or(sub(or(iszero(x), eq(div(mul(x, y), x), y)), 1), mul(x, y))
        }
    }

    /// @dev Returns `condition ? x : y`, without branching.
    function ternary(bool condition, uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := xor(x, mul(xor(x, y), iszero(condition)))
        }
    }

    /// @dev Returns `condition ? x : y`, without branching.
    function ternary(bool condition, bytes32 x, bytes32 y) internal pure returns (bytes32 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := xor(x, mul(xor(x, y), iszero(condition)))
        }
    }

    /// @dev Returns `condition ? x : y`, without branching.
    function ternary(bool condition, address x, address y) internal pure returns (address z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := xor(x, mul(xor(x, y), iszero(condition)))
        }
    }

    /// @dev Returns `x != 0 ? x : y`, without branching.
    function coalesce(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := or(x, mul(y, iszero(x)))
        }
    }

    /// @dev Returns `x != bytes32(0) ? x : y`, without branching.
    function coalesce(bytes32 x, bytes32 y) internal pure returns (bytes32 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := or(x, mul(y, iszero(x)))
        }
    }

    /// @dev Returns `x != address(0) ? x : y`, without branching.
    function coalesce(address x, address y) internal pure returns (address z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := or(x, mul(y, iszero(shl(96, x))))
        }
    }

    /// @dev Exponentiate `x` to `y` by squaring, denominated in base `b`.
    /// Reverts if the computation overflows.
    function rpow(uint256 x, uint256 y, uint256 b) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := mul(b, iszero(y)) // `0 ** 0 = 1`. Otherwise, `0 ** n = 0`.
            if x {
                z := xor(b, mul(xor(b, x), and(y, 1))) // `z = isEven(y) ? scale : x`
                let half := shr(1, b) // Divide `b` by 2.
                // Divide `y` by 2 every iteration.
                for { y := shr(1, y) } y { y := shr(1, y) } {
                    let xx := mul(x, x) // Store x squared.
                    let xxRound := add(xx, half) // Round to the nearest number.
                    // Revert if `xx + half` overflowed, or if `x ** 2` overflows.
                    if or(lt(xxRound, xx), shr(128, x)) {
                        mstore(0x00, 0x49f7642b) // `RPowOverflow()`.
                        revert(0x1c, 0x04)
                    }
                    x := div(xxRound, b) // Set `x` to scaled `xxRound`.
                    // If `y` is odd:
                    if and(y, 1) {
                        let zx := mul(z, x) // Compute `z * x`.
                        let zxRound := add(zx, half) // Round to the nearest number.
                        // If `z * x` overflowed or `zx + half` overflowed:
                        if or(xor(div(zx, x), z), lt(zxRound, zx)) {
                            // Revert if `x` is non-zero.
                            if x {
                                mstore(0x00, 0x49f7642b) // `RPowOverflow()`.
                                revert(0x1c, 0x04)
                            }
                        }
                        z := div(zxRound, b) // Return properly scaled `zxRound`.
                    }
                }
            }
        }
    }

    /// @dev Returns the square root of `x`, rounded down.
    function sqrt(uint256 x) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            // `floor(sqrt(2**15)) = 181`. `sqrt(2**15) - 181 = 2.84`.
            z := 181 // The "correct" value is 1, but this saves a multiplication later.

            // This segment is to get a reasonable initial estimate for the Babylonian method. With a bad
            // start, the correct # of bits increases ~linearly each iteration instead of ~quadratically.

            // Let `y = x / 2**r`. We check `y >= 2**(k + 8)`
            // but shift right by `k` bits to ensure that if `x >= 256`, then `y >= 256`.
            let r := shl(7, lt(0xffffffffffffffffffffffffffffffffff, x))
            r := or(r, shl(6, lt(0xffffffffffffffffff, shr(r, x))))
            r := or(r, shl(5, lt(0xffffffffff, shr(r, x))))
            r := or(r, shl(4, lt(0xffffff, shr(r, x))))
            z := shl(shr(1, r), z)

            // Goal was to get `z*z*y` within a small factor of `x`. More iterations could
            // get y in a tighter range. Currently, we will have y in `[256, 256*(2**16))`.
            // We ensured `y >= 256` so that the relative difference between `y` and `y+1` is small.
            // That's not possible if `x < 256` but we can just verify those cases exhaustively.

            // Now, `z*z*y <= x < z*z*(y+1)`, and `y <= 2**(16+8)`, and either `y >= 256`, or `x < 256`.
            // Correctness can be checked exhaustively for `x < 256`, so we assume `y >= 256`.
            // Then `z*sqrt(y)` is within `sqrt(257)/sqrt(256)` of `sqrt(x)`, or about 20bps.

            // For `s` in the range `[1/256, 256]`, the estimate `f(s) = (181/1024) * (s+1)`
            // is in the range `(1/2.84 * sqrt(s), 2.84 * sqrt(s))`,
            // with largest error when `s = 1` and when `s = 256` or `1/256`.

            // Since `y` is in `[256, 256*(2**16))`, let `a = y/65536`, so that `a` is in `[1/256, 256)`.
            // Then we can estimate `sqrt(y)` using
            // `sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2**18`.

            // There is no overflow risk here since `y < 2**136` after the first branch above.
            z := shr(18, mul(z, add(shr(r, x), 65536))) // A `mul()` is saved from starting `z` at 181.

            // Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough.
            z := shr(1, add(z, div(x, z)))
            z := shr(1, add(z, div(x, z)))
            z := shr(1, add(z, div(x, z)))
            z := shr(1, add(z, div(x, z)))
            z := shr(1, add(z, div(x, z)))
            z := shr(1, add(z, div(x, z)))
            z := shr(1, add(z, div(x, z)))

            // If `x+1` is a perfect square, the Babylonian method cycles between
            // `floor(sqrt(x))` and `ceil(sqrt(x))`. This statement ensures we return floor.
            // See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division
            z := sub(z, lt(div(x, z), z))
        }
    }

    /// @dev Returns the cube root of `x`, rounded down.
    /// Credit to bout3fiddy and pcaversaccio under AGPLv3 license:
    /// https://github.com/pcaversaccio/snekmate/blob/main/src/utils/Math.vy
    /// Formally verified by xuwinnie:
    /// https://github.com/vectorized/solady/blob/main/audits/xuwinnie-solady-cbrt-proof.pdf
    function cbrt(uint256 x) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            let r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
            r := or(r, shl(4, lt(0xffff, shr(r, x))))
            r := or(r, shl(3, lt(0xff, shr(r, x))))
            // Makeshift lookup table to nudge the approximate log2 result.
            z := div(shl(div(r, 3), shl(lt(0xf, shr(r, x)), 0xf)), xor(7, mod(r, 3)))
            // Newton-Raphson's.
            z := div(add(add(div(x, mul(z, z)), z), z), 3)
            z := div(add(add(div(x, mul(z, z)), z), z), 3)
            z := div(add(add(div(x, mul(z, z)), z), z), 3)
            z := div(add(add(div(x, mul(z, z)), z), z), 3)
            z := div(add(add(div(x, mul(z, z)), z), z), 3)
            z := div(add(add(div(x, mul(z, z)), z), z), 3)
            z := div(add(add(div(x, mul(z, z)), z), z), 3)
            // Round down.
            z := sub(z, lt(div(x, mul(z, z)), z))
        }
    }

    /// @dev Returns the square root of `x`, denominated in `WAD`, rounded down.
    function sqrtWad(uint256 x) internal pure returns (uint256 z) {
        unchecked {
            if (x <= type(uint256).max / 10 ** 18) return sqrt(x * 10 ** 18);
            z = (1 + sqrt(x)) * 10 ** 9;
            z = (fullMulDivUnchecked(x, 10 ** 18, z) + z) >> 1;
        }
        /// @solidity memory-safe-assembly
        assembly {
            z := sub(z, gt(999999999999999999, sub(mulmod(z, z, x), 1))) // Round down.
        }
    }

    /// @dev Returns the cube root of `x`, denominated in `WAD`, rounded down.
    /// Formally verified by xuwinnie:
    /// https://github.com/vectorized/solady/blob/main/audits/xuwinnie-solady-cbrt-proof.pdf
    function cbrtWad(uint256 x) internal pure returns (uint256 z) {
        unchecked {
            if (x <= type(uint256).max / 10 ** 36) return cbrt(x * 10 ** 36);
            z = (1 + cbrt(x)) * 10 ** 12;
            z = (fullMulDivUnchecked(x, 10 ** 36, z * z) + z + z) / 3;
        }
        /// @solidity memory-safe-assembly
        assembly {
            let p := x
            for {} 1 {} {
                if iszero(shr(229, p)) {
                    if iszero(shr(199, p)) {
                        p := mul(p, 100000000000000000) // 10 ** 17.
                        break
                    }
                    p := mul(p, 100000000) // 10 ** 8.
                    break
                }
                if iszero(shr(249, p)) { p := mul(p, 100) }
                break
            }
            let t := mulmod(mul(z, z), z, p)
            z := sub(z, gt(lt(t, shr(1, p)), iszero(t))) // Round down.
        }
    }

    /// @dev Returns the factorial of `x`.
    function factorial(uint256 x) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := 1
            if iszero(lt(x, 58)) {
                mstore(0x00, 0xaba0f2a2) // `FactorialOverflow()`.
                revert(0x1c, 0x04)
            }
            for {} x { x := sub(x, 1) } { z := mul(z, x) }
        }
    }

    /// @dev Returns the log2 of `x`.
    /// Equivalent to computing the index of the most significant bit (MSB) of `x`.
    /// Returns 0 if `x` is zero.
    function log2(uint256 x) internal pure returns (uint256 r) {
        /// @solidity memory-safe-assembly
        assembly {
            r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
            r := or(r, shl(4, lt(0xffff, shr(r, x))))
            r := or(r, shl(3, lt(0xff, shr(r, x))))
            // forgefmt: disable-next-item
            r := or(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),
                0x0706060506020504060203020504030106050205030304010505030400000000))
        }
    }

    /// @dev Returns the log2 of `x`, rounded up.
    /// Returns 0 if `x` is zero.
    function log2Up(uint256 x) internal pure returns (uint256 r) {
        r = log2(x);
        /// @solidity memory-safe-assembly
        assembly {
            r := add(r, lt(shl(r, 1), x))
        }
    }

    /// @dev Returns the log10 of `x`.
    /// Returns 0 if `x` is zero.
    function log10(uint256 x) internal pure returns (uint256 r) {
        /// @solidity memory-safe-assembly
        assembly {
            if iszero(lt(x, 100000000000000000000000000000000000000)) {
                x := div(x, 100000000000000000000000000000000000000)
                r := 38
            }
            if iszero(lt(x, 100000000000000000000)) {
                x := div(x, 100000000000000000000)
                r := add(r, 20)
            }
            if iszero(lt(x, 10000000000)) {
                x := div(x, 10000000000)
                r := add(r, 10)
            }
            if iszero(lt(x, 100000)) {
                x := div(x, 100000)
                r := add(r, 5)
            }
            r := add(r, add(gt(x, 9), add(gt(x, 99), add(gt(x, 999), gt(x, 9999)))))
        }
    }

    /// @dev Returns the log10 of `x`, rounded up.
    /// Returns 0 if `x` is zero.
    function log10Up(uint256 x) internal pure returns (uint256 r) {
        r = log10(x);
        /// @solidity memory-safe-assembly
        assembly {
            r := add(r, lt(exp(10, r), x))
        }
    }

    /// @dev Returns the log256 of `x`.
    /// Returns 0 if `x` is zero.
    function log256(uint256 x) internal pure returns (uint256 r) {
        /// @solidity memory-safe-assembly
        assembly {
            r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
            r := or(r, shl(4, lt(0xffff, shr(r, x))))
            r := or(shr(3, r), lt(0xff, shr(r, x)))
        }
    }

    /// @dev Returns the log256 of `x`, rounded up.
    /// Returns 0 if `x` is zero.
    function log256Up(uint256 x) internal pure returns (uint256 r) {
        r = log256(x);
        /// @solidity memory-safe-assembly
        assembly {
            r := add(r, lt(shl(shl(3, r), 1), x))
        }
    }

    /// @dev Returns the scientific notation format `mantissa * 10 ** exponent` of `x`.
    /// Useful for compressing prices (e.g. using 25 bit mantissa and 7 bit exponent).
    function sci(uint256 x) internal pure returns (uint256 mantissa, uint256 exponent) {
        /// @solidity memory-safe-assembly
        assembly {
            mantissa := x
            if mantissa {
                if iszero(mod(mantissa, 1000000000000000000000000000000000)) {
                    mantissa := div(mantissa, 1000000000000000000000000000000000)
                    exponent := 33
                }
                if iszero(mod(mantissa, 10000000000000000000)) {
                    mantissa := div(mantissa, 10000000000000000000)
                    exponent := add(exponent, 19)
                }
                if iszero(mod(mantissa, 1000000000000)) {
                    mantissa := div(mantissa, 1000000000000)
                    exponent := add(exponent, 12)
                }
                if iszero(mod(mantissa, 1000000)) {
                    mantissa := div(mantissa, 1000000)
                    exponent := add(exponent, 6)
                }
                if iszero(mod(mantissa, 10000)) {
                    mantissa := div(mantissa, 10000)
                    exponent := add(exponent, 4)
                }
                if iszero(mod(mantissa, 100)) {
                    mantissa := div(mantissa, 100)
                    exponent := add(exponent, 2)
                }
                if iszero(mod(mantissa, 10)) {
                    mantissa := div(mantissa, 10)
                    exponent := add(exponent, 1)
                }
            }
        }
    }

    /// @dev Convenience function for packing `x` into a smaller number using `sci`.
    /// The `mantissa` will be in bits [7..255] (the upper 249 bits).
    /// The `exponent` will be in bits [0..6] (the lower 7 bits).
    /// Use `SafeCastLib` to safely ensure that the `packed` number is small
    /// enough to fit in the desired unsigned integer type:
    /// ```
    ///     uint32 packed = SafeCastLib.toUint32(FixedPointMathLib.packSci(777 ether));
    /// ```
    function packSci(uint256 x) internal pure returns (uint256 packed) {
        (x, packed) = sci(x); // Reuse for `mantissa` and `exponent`.
        /// @solidity memory-safe-assembly
        assembly {
            if shr(249, x) {
                mstore(0x00, 0xce30380c) // `MantissaOverflow()`.
                revert(0x1c, 0x04)
            }
            packed := or(shl(7, x), packed)
        }
    }

    /// @dev Convenience function for unpacking a packed number from `packSci`.
    function unpackSci(uint256 packed) internal pure returns (uint256 unpacked) {
        unchecked {
            unpacked = (packed >> 7) * 10 ** (packed & 0x7f);
        }
    }

    /// @dev Returns the average of `x` and `y`. Rounds towards zero.
    function avg(uint256 x, uint256 y) internal pure returns (uint256 z) {
        unchecked {
            z = (x & y) + ((x ^ y) >> 1);
        }
    }

    /// @dev Returns the average of `x` and `y`. Rounds towards negative infinity.
    function avg(int256 x, int256 y) internal pure returns (int256 z) {
        unchecked {
            z = (x >> 1) + (y >> 1) + (x & y & 1);
        }
    }

    /// @dev Returns the absolute value of `x`.
    function abs(int256 x) internal pure returns (uint256 z) {
        unchecked {
            z = (uint256(x) + uint256(x >> 255)) ^ uint256(x >> 255);
        }
    }

    /// @dev Returns the absolute distance between `x` and `y`.
    function dist(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := add(xor(sub(0, gt(x, y)), sub(y, x)), gt(x, y))
        }
    }

    /// @dev Returns the absolute distance between `x` and `y`.
    function dist(int256 x, int256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := add(xor(sub(0, sgt(x, y)), sub(y, x)), sgt(x, y))
        }
    }

    /// @dev Returns the minimum of `x` and `y`.
    function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := xor(x, mul(xor(x, y), lt(y, x)))
        }
    }

    /// @dev Returns the minimum of `x` and `y`.
    function min(int256 x, int256 y) internal pure returns (int256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := xor(x, mul(xor(x, y), slt(y, x)))
        }
    }

    /// @dev Returns the maximum of `x` and `y`.
    function max(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := xor(x, mul(xor(x, y), gt(y, x)))
        }
    }

    /// @dev Returns the maximum of `x` and `y`.
    function max(int256 x, int256 y) internal pure returns (int256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := xor(x, mul(xor(x, y), sgt(y, x)))
        }
    }

    /// @dev Returns `x`, bounded to `minValue` and `maxValue`.
    function clamp(uint256 x, uint256 minValue, uint256 maxValue)
        internal
        pure
        returns (uint256 z)
    {
        /// @solidity memory-safe-assembly
        assembly {
            z := xor(x, mul(xor(x, minValue), gt(minValue, x)))
            z := xor(z, mul(xor(z, maxValue), lt(maxValue, z)))
        }
    }

    /// @dev Returns `x`, bounded to `minValue` and `maxValue`.
    function clamp(int256 x, int256 minValue, int256 maxValue) internal pure returns (int256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := xor(x, mul(xor(x, minValue), sgt(minValue, x)))
            z := xor(z, mul(xor(z, maxValue), slt(maxValue, z)))
        }
    }

    /// @dev Returns greatest common divisor of `x` and `y`.
    function gcd(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            for { z := x } y {} {
                let t := y
                y := mod(z, y)
                z := t
            }
        }
    }

    /// @dev Returns `a + (b - a) * (t - begin) / (end - begin)`,
    /// with `t` clamped between `begin` and `end` (inclusive).
    /// Agnostic to the order of (`a`, `b`) and (`end`, `begin`).
    /// If `begins == end`, returns `t <= begin ? a : b`.
    function lerp(uint256 a, uint256 b, uint256 t, uint256 begin, uint256 end)
        internal
        pure
        returns (uint256)
    {
        if (begin > end) (t, begin, end) = (~t, ~begin, ~end);
        if (t <= begin) return a;
        if (t >= end) return b;
        unchecked {
            if (b >= a) return a + fullMulDiv(b - a, t - begin, end - begin);
            return a - fullMulDiv(a - b, t - begin, end - begin);
        }
    }

    /// @dev Returns `a + (b - a) * (t - begin) / (end - begin)`.
    /// with `t` clamped between `begin` and `end` (inclusive).
    /// Agnostic to the order of (`a`, `b`) and (`end`, `begin`).
    /// If `begins == end`, returns `t <= begin ? a : b`.
    function lerp(int256 a, int256 b, int256 t, int256 begin, int256 end)
        internal
        pure
        returns (int256)
    {
        if (begin > end) (t, begin, end) = (~t, ~begin, ~end);
        if (t <= begin) return a;
        if (t >= end) return b;
        // forgefmt: disable-next-item
        unchecked {
            if (b >= a) return int256(uint256(a) + fullMulDiv(uint256(b - a),
                uint256(t - begin), uint256(end - begin)));
            return int256(uint256(a) - fullMulDiv(uint256(a - b),
                uint256(t - begin), uint256(end - begin)));
        }
    }

    /// @dev Returns if `x` is an even number. Some people may need this.
    function isEven(uint256 x) internal pure returns (bool) {
        return x & uint256(1) == uint256(0);
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                   RAW NUMBER OPERATIONS                    */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Returns `x + y`, without checking for overflow.
    function rawAdd(uint256 x, uint256 y) internal pure returns (uint256 z) {
        unchecked {
            z = x + y;
        }
    }

    /// @dev Returns `x + y`, without checking for overflow.
    function rawAdd(int256 x, int256 y) internal pure returns (int256 z) {
        unchecked {
            z = x + y;
        }
    }

    /// @dev Returns `x - y`, without checking for underflow.
    function rawSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
        unchecked {
            z = x - y;
        }
    }

    /// @dev Returns `x - y`, without checking for underflow.
    function rawSub(int256 x, int256 y) internal pure returns (int256 z) {
        unchecked {
            z = x - y;
        }
    }

    /// @dev Returns `x * y`, without checking for overflow.
    function rawMul(uint256 x, uint256 y) internal pure returns (uint256 z) {
        unchecked {
            z = x * y;
        }
    }

    /// @dev Returns `x * y`, without checking for overflow.
    function rawMul(int256 x, int256 y) internal pure returns (int256 z) {
        unchecked {
            z = x * y;
        }
    }

    /// @dev Returns `x / y`, returning 0 if `y` is zero.
    function rawDiv(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := div(x, y)
        }
    }

    /// @dev Returns `x / y`, returning 0 if `y` is zero.
    function rawSDiv(int256 x, int256 y) internal pure returns (int256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := sdiv(x, y)
        }
    }

    /// @dev Returns `x % y`, returning 0 if `y` is zero.
    function rawMod(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := mod(x, y)
        }
    }

    /// @dev Returns `x % y`, returning 0 if `y` is zero.
    function rawSMod(int256 x, int256 y) internal pure returns (int256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := smod(x, y)
        }
    }

    /// @dev Returns `(x + y) % d`, return 0 if `d` if zero.
    function rawAddMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := addmod(x, y, d)
        }
    }

    /// @dev Returns `(x * y) % d`, return 0 if `d` if zero.
    function rawMulMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := mulmod(x, y, d)
        }
    }
}

File 12 of 28 : SafeTransferLib.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @author Permit2 operations from (https://github.com/Uniswap/permit2/blob/main/src/libraries/Permit2Lib.sol)
///
/// @dev Note:
/// - For ETH transfers, please use `forceSafeTransferETH` for DoS protection.
library SafeTransferLib {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The ETH transfer has failed.
    error ETHTransferFailed();

    /// @dev The ERC20 `transferFrom` has failed.
    error TransferFromFailed();

    /// @dev The ERC20 `transfer` has failed.
    error TransferFailed();

    /// @dev The ERC20 `approve` has failed.
    error ApproveFailed();

    /// @dev The ERC20 `totalSupply` query has failed.
    error TotalSupplyQueryFailed();

    /// @dev The Permit2 operation has failed.
    error Permit2Failed();

    /// @dev The Permit2 amount must be less than `2**160 - 1`.
    error Permit2AmountOverflow();

    /// @dev The Permit2 approve operation has failed.
    error Permit2ApproveFailed();

    /// @dev The Permit2 lockdown operation has failed.
    error Permit2LockdownFailed();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                         CONSTANTS                          */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Suggested gas stipend for contract receiving ETH that disallows any storage writes.
    uint256 internal constant GAS_STIPEND_NO_STORAGE_WRITES = 2300;

    /// @dev Suggested gas stipend for contract receiving ETH to perform a few
    /// storage reads and writes, but low enough to prevent griefing.
    uint256 internal constant GAS_STIPEND_NO_GRIEF = 100000;

    /// @dev The unique EIP-712 domain domain separator for the DAI token contract.
    bytes32 internal constant DAI_DOMAIN_SEPARATOR =
        0xdbb8cf42e1ecb028be3f3dbc922e1d878b963f411dc388ced501601c60f7c6f7;

    /// @dev The address for the WETH9 contract on Ethereum mainnet.
    address internal constant WETH9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;

    /// @dev The canonical Permit2 address.
    /// [Github](https://github.com/Uniswap/permit2)
    /// [Etherscan](https://etherscan.io/address/0x000000000022D473030F116dDEE9F6B43aC78BA3)
    address internal constant PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       ETH OPERATIONS                       */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    // If the ETH transfer MUST succeed with a reasonable gas budget, use the force variants.
    //
    // The regular variants:
    // - Forwards all remaining gas to the target.
    // - Reverts if the target reverts.
    // - Reverts if the current contract has insufficient balance.
    //
    // The force variants:
    // - Forwards with an optional gas stipend
    //   (defaults to `GAS_STIPEND_NO_GRIEF`, which is sufficient for most cases).
    // - If the target reverts, or if the gas stipend is exhausted,
    //   creates a temporary contract to force send the ETH via `SELFDESTRUCT`.
    //   Future compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758.
    // - Reverts if the current contract has insufficient balance.
    //
    // The try variants:
    // - Forwards with a mandatory gas stipend.
    // - Instead of reverting, returns whether the transfer succeeded.

    /// @dev Sends `amount` (in wei) ETH to `to`.
    function safeTransferETH(address to, uint256 amount) internal {
        /// @solidity memory-safe-assembly
        assembly {
            if iszero(call(gas(), to, amount, codesize(), 0x00, codesize(), 0x00)) {
                mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
                revert(0x1c, 0x04)
            }
        }
    }

    /// @dev Sends all the ETH in the current contract to `to`.
    function safeTransferAllETH(address to) internal {
        /// @solidity memory-safe-assembly
        assembly {
            // Transfer all the ETH and check if it succeeded or not.
            if iszero(call(gas(), to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
                mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
                revert(0x1c, 0x04)
            }
        }
    }

    /// @dev Force sends `amount` (in wei) ETH to `to`, with a `gasStipend`.
    function forceSafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal {
        /// @solidity memory-safe-assembly
        assembly {
            if lt(selfbalance(), amount) {
                mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
                revert(0x1c, 0x04)
            }
            if iszero(call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)) {
                mstore(0x00, to) // Store the address in scratch space.
                mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
            }
        }
    }

    /// @dev Force sends all the ETH in the current contract to `to`, with a `gasStipend`.
    function forceSafeTransferAllETH(address to, uint256 gasStipend) internal {
        /// @solidity memory-safe-assembly
        assembly {
            if iszero(call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
                mstore(0x00, to) // Store the address in scratch space.
                mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
            }
        }
    }

    /// @dev Force sends `amount` (in wei) ETH to `to`, with `GAS_STIPEND_NO_GRIEF`.
    function forceSafeTransferETH(address to, uint256 amount) internal {
        /// @solidity memory-safe-assembly
        assembly {
            if lt(selfbalance(), amount) {
                mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
                revert(0x1c, 0x04)
            }
            if iszero(call(GAS_STIPEND_NO_GRIEF, to, amount, codesize(), 0x00, codesize(), 0x00)) {
                mstore(0x00, to) // Store the address in scratch space.
                mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
            }
        }
    }

    /// @dev Force sends all the ETH in the current contract to `to`, with `GAS_STIPEND_NO_GRIEF`.
    function forceSafeTransferAllETH(address to) internal {
        /// @solidity memory-safe-assembly
        assembly {
            // forgefmt: disable-next-item
            if iszero(call(GAS_STIPEND_NO_GRIEF, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
                mstore(0x00, to) // Store the address in scratch space.
                mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
            }
        }
    }

    /// @dev Sends `amount` (in wei) ETH to `to`, with a `gasStipend`.
    function trySafeTransferETH(address to, uint256 amount, uint256 gasStipend)
        internal
        returns (bool success)
    {
        /// @solidity memory-safe-assembly
        assembly {
            success := call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)
        }
    }

    /// @dev Sends all the ETH in the current contract to `to`, with a `gasStipend`.
    function trySafeTransferAllETH(address to, uint256 gasStipend)
        internal
        returns (bool success)
    {
        /// @solidity memory-safe-assembly
        assembly {
            success := call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                      ERC20 OPERATIONS                      */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
    /// Reverts upon failure.
    ///
    /// The `from` account must have at least `amount` approved for
    /// the current contract to manage.
    function safeTransferFrom(address token, address from, address to, uint256 amount) internal {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40) // Cache the free memory pointer.
            mstore(0x60, amount) // Store the `amount` argument.
            mstore(0x40, to) // Store the `to` argument.
            mstore(0x2c, shl(96, from)) // Store the `from` argument.
            mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`.
            let success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
            if iszero(and(eq(mload(0x00), 1), success)) {
                if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
                    mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
                    revert(0x1c, 0x04)
                }
            }
            mstore(0x60, 0) // Restore the zero slot to zero.
            mstore(0x40, m) // Restore the free memory pointer.
        }
    }

    /// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
    ///
    /// The `from` account must have at least `amount` approved for the current contract to manage.
    function trySafeTransferFrom(address token, address from, address to, uint256 amount)
        internal
        returns (bool success)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40) // Cache the free memory pointer.
            mstore(0x60, amount) // Store the `amount` argument.
            mstore(0x40, to) // Store the `to` argument.
            mstore(0x2c, shl(96, from)) // Store the `from` argument.
            mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`.
            success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
            if iszero(and(eq(mload(0x00), 1), success)) {
                success := lt(or(iszero(extcodesize(token)), returndatasize()), success)
            }
            mstore(0x60, 0) // Restore the zero slot to zero.
            mstore(0x40, m) // Restore the free memory pointer.
        }
    }

    /// @dev Sends all of ERC20 `token` from `from` to `to`.
    /// Reverts upon failure.
    ///
    /// The `from` account must have their entire balance approved for the current contract to manage.
    function safeTransferAllFrom(address token, address from, address to)
        internal
        returns (uint256 amount)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40) // Cache the free memory pointer.
            mstore(0x40, to) // Store the `to` argument.
            mstore(0x2c, shl(96, from)) // Store the `from` argument.
            mstore(0x0c, 0x70a08231000000000000000000000000) // `balanceOf(address)`.
            // Read the balance, reverting upon failure.
            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    gt(returndatasize(), 0x1f), // At least 32 bytes returned.
                    staticcall(gas(), token, 0x1c, 0x24, 0x60, 0x20)
                )
            ) {
                mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
                revert(0x1c, 0x04)
            }
            mstore(0x00, 0x23b872dd) // `transferFrom(address,address,uint256)`.
            amount := mload(0x60) // The `amount` is already at 0x60. We'll need to return it.
            // Perform the transfer, reverting upon failure.
            let success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
            if iszero(and(eq(mload(0x00), 1), success)) {
                if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
                    mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
                    revert(0x1c, 0x04)
                }
            }
            mstore(0x60, 0) // Restore the zero slot to zero.
            mstore(0x40, m) // Restore the free memory pointer.
        }
    }

    /// @dev Sends `amount` of ERC20 `token` from the current contract to `to`.
    /// Reverts upon failure.
    function safeTransfer(address token, address to, uint256 amount) internal {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x14, to) // Store the `to` argument.
            mstore(0x34, amount) // Store the `amount` argument.
            mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.
            // Perform the transfer, reverting upon failure.
            let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
            if iszero(and(eq(mload(0x00), 1), success)) {
                if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
                    mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
                    revert(0x1c, 0x04)
                }
            }
            mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
        }
    }

    /// @dev Sends all of ERC20 `token` from the current contract to `to`.
    /// Reverts upon failure.
    function safeTransferAll(address token, address to) internal returns (uint256 amount) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, 0x70a08231) // Store the function selector of `balanceOf(address)`.
            mstore(0x20, address()) // Store the address of the current contract.
            // Read the balance, reverting upon failure.
            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    gt(returndatasize(), 0x1f), // At least 32 bytes returned.
                    staticcall(gas(), token, 0x1c, 0x24, 0x34, 0x20)
                )
            ) {
                mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
                revert(0x1c, 0x04)
            }
            mstore(0x14, to) // Store the `to` argument.
            amount := mload(0x34) // The `amount` is already at 0x34. We'll need to return it.
            mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.
            // Perform the transfer, reverting upon failure.
            let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
            if iszero(and(eq(mload(0x00), 1), success)) {
                if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
                    mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
                    revert(0x1c, 0x04)
                }
            }
            mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
        }
    }

    /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.
    /// Reverts upon failure.
    function safeApprove(address token, address to, uint256 amount) internal {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x14, to) // Store the `to` argument.
            mstore(0x34, amount) // Store the `amount` argument.
            mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
            let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
            if iszero(and(eq(mload(0x00), 1), success)) {
                if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
                    mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.
                    revert(0x1c, 0x04)
                }
            }
            mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
        }
    }

    /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.
    /// If the initial attempt to approve fails, attempts to reset the approved amount to zero,
    /// then retries the approval again (some tokens, e.g. USDT, requires this).
    /// Reverts upon failure.
    function safeApproveWithRetry(address token, address to, uint256 amount) internal {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x14, to) // Store the `to` argument.
            mstore(0x34, amount) // Store the `amount` argument.
            mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
            // Perform the approval, retrying upon failure.
            let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
            if iszero(and(eq(mload(0x00), 1), success)) {
                if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
                    mstore(0x34, 0) // Store 0 for the `amount`.
                    mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
                    pop(call(gas(), token, 0, 0x10, 0x44, codesize(), 0x00)) // Reset the approval.
                    mstore(0x34, amount) // Store back the original `amount`.
                    // Retry the approval, reverting upon failure.
                    success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                    if iszero(and(eq(mload(0x00), 1), success)) {
                        // Check the `extcodesize` again just in case the token selfdestructs lol.
                        if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
                            mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.
                            revert(0x1c, 0x04)
                        }
                    }
                }
            }
            mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
        }
    }

    /// @dev Returns the amount of ERC20 `token` owned by `account`.
    /// Returns zero if the `token` does not exist.
    function balanceOf(address token, address account) internal view returns (uint256 amount) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x14, account) // Store the `account` argument.
            mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`.
            amount :=
                mul( // The arguments of `mul` are evaluated from right to left.
                    mload(0x20),
                    and( // The arguments of `and` are evaluated from right to left.
                        gt(returndatasize(), 0x1f), // At least 32 bytes returned.
                        staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20)
                    )
                )
        }
    }

    /// @dev Returns the total supply of the `token`.
    /// Reverts if the token does not exist or does not implement `totalSupply()`.
    function totalSupply(address token) internal view returns (uint256 result) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, 0x18160ddd) // `totalSupply()`.
            if iszero(
                and(gt(returndatasize(), 0x1f), staticcall(gas(), token, 0x1c, 0x04, 0x00, 0x20))
            ) {
                mstore(0x00, 0x54cd9435) // `TotalSupplyQueryFailed()`.
                revert(0x1c, 0x04)
            }
            result := mload(0x00)
        }
    }

    /// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
    /// If the initial attempt fails, try to use Permit2 to transfer the token.
    /// Reverts upon failure.
    ///
    /// The `from` account must have at least `amount` approved for the current contract to manage.
    function safeTransferFrom2(address token, address from, address to, uint256 amount) internal {
        if (!trySafeTransferFrom(token, from, to, amount)) {
            permit2TransferFrom(token, from, to, amount);
        }
    }

    /// @dev Sends `amount` of ERC20 `token` from `from` to `to` via Permit2.
    /// Reverts upon failure.
    function permit2TransferFrom(address token, address from, address to, uint256 amount)
        internal
    {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(add(m, 0x74), shr(96, shl(96, token)))
            mstore(add(m, 0x54), amount)
            mstore(add(m, 0x34), to)
            mstore(add(m, 0x20), shl(96, from))
            // `transferFrom(address,address,uint160,address)`.
            mstore(m, 0x36c78516000000000000000000000000)
            let p := PERMIT2
            let exists := eq(chainid(), 1)
            if iszero(exists) { exists := iszero(iszero(extcodesize(p))) }
            if iszero(
                and(
                    call(gas(), p, 0, add(m, 0x10), 0x84, codesize(), 0x00),
                    lt(iszero(extcodesize(token)), exists) // Token has code and Permit2 exists.
                )
            ) {
                mstore(0x00, 0x7939f4248757f0fd) // `TransferFromFailed()` or `Permit2AmountOverflow()`.
                revert(add(0x18, shl(2, iszero(iszero(shr(160, amount))))), 0x04)
            }
        }
    }

    /// @dev Permit a user to spend a given amount of
    /// another user's tokens via native EIP-2612 permit if possible, falling
    /// back to Permit2 if native permit fails or is not implemented on the token.
    function permit2(
        address token,
        address owner,
        address spender,
        uint256 amount,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        bool success;
        /// @solidity memory-safe-assembly
        assembly {
            for {} shl(96, xor(token, WETH9)) {} {
                mstore(0x00, 0x3644e515) // `DOMAIN_SEPARATOR()`.
                if iszero(
                    and( // The arguments of `and` are evaluated from right to left.
                        lt(iszero(mload(0x00)), eq(returndatasize(), 0x20)), // Returns 1 non-zero word.
                        // Gas stipend to limit gas burn for tokens that don't refund gas when
                        // an non-existing function is called. 5K should be enough for a SLOAD.
                        staticcall(5000, token, 0x1c, 0x04, 0x00, 0x20)
                    )
                ) { break }
                // After here, we can be sure that token is a contract.
                let m := mload(0x40)
                mstore(add(m, 0x34), spender)
                mstore(add(m, 0x20), shl(96, owner))
                mstore(add(m, 0x74), deadline)
                if eq(mload(0x00), DAI_DOMAIN_SEPARATOR) {
                    mstore(0x14, owner)
                    mstore(0x00, 0x7ecebe00000000000000000000000000) // `nonces(address)`.
                    mstore(
                        add(m, 0x94),
                        lt(iszero(amount), staticcall(gas(), token, 0x10, 0x24, add(m, 0x54), 0x20))
                    )
                    mstore(m, 0x8fcbaf0c000000000000000000000000) // `IDAIPermit.permit`.
                    // `nonces` is already at `add(m, 0x54)`.
                    // `amount != 0` is already stored at `add(m, 0x94)`.
                    mstore(add(m, 0xb4), and(0xff, v))
                    mstore(add(m, 0xd4), r)
                    mstore(add(m, 0xf4), s)
                    success := call(gas(), token, 0, add(m, 0x10), 0x104, codesize(), 0x00)
                    break
                }
                mstore(m, 0xd505accf000000000000000000000000) // `IERC20Permit.permit`.
                mstore(add(m, 0x54), amount)
                mstore(add(m, 0x94), and(0xff, v))
                mstore(add(m, 0xb4), r)
                mstore(add(m, 0xd4), s)
                success := call(gas(), token, 0, add(m, 0x10), 0xe4, codesize(), 0x00)
                break
            }
        }
        if (!success) simplePermit2(token, owner, spender, amount, deadline, v, r, s);
    }

    /// @dev Simple permit on the Permit2 contract.
    function simplePermit2(
        address token,
        address owner,
        address spender,
        uint256 amount,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, 0x927da105) // `allowance(address,address,address)`.
            {
                let addressMask := shr(96, not(0))
                mstore(add(m, 0x20), and(addressMask, owner))
                mstore(add(m, 0x40), and(addressMask, token))
                mstore(add(m, 0x60), and(addressMask, spender))
                mstore(add(m, 0xc0), and(addressMask, spender))
            }
            let p := mul(PERMIT2, iszero(shr(160, amount)))
            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    gt(returndatasize(), 0x5f), // Returns 3 words: `amount`, `expiration`, `nonce`.
                    staticcall(gas(), p, add(m, 0x1c), 0x64, add(m, 0x60), 0x60)
                )
            ) {
                mstore(0x00, 0x6b836e6b8757f0fd) // `Permit2Failed()` or `Permit2AmountOverflow()`.
                revert(add(0x18, shl(2, iszero(p))), 0x04)
            }
            mstore(m, 0x2b67b570) // `Permit2.permit` (PermitSingle variant).
            // `owner` is already `add(m, 0x20)`.
            // `token` is already at `add(m, 0x40)`.
            mstore(add(m, 0x60), amount)
            mstore(add(m, 0x80), 0xffffffffffff) // `expiration = type(uint48).max`.
            // `nonce` is already at `add(m, 0xa0)`.
            // `spender` is already at `add(m, 0xc0)`.
            mstore(add(m, 0xe0), deadline)
            mstore(add(m, 0x100), 0x100) // `signature` offset.
            mstore(add(m, 0x120), 0x41) // `signature` length.
            mstore(add(m, 0x140), r)
            mstore(add(m, 0x160), s)
            mstore(add(m, 0x180), shl(248, v))
            if iszero( // Revert if token does not have code, or if the call fails.
            mul(extcodesize(token), call(gas(), p, 0, add(m, 0x1c), 0x184, codesize(), 0x00))) {
                mstore(0x00, 0x6b836e6b) // `Permit2Failed()`.
                revert(0x1c, 0x04)
            }
        }
    }

    /// @dev Approves `spender` to spend `amount` of `token` for `address(this)`.
    function permit2Approve(address token, address spender, uint160 amount, uint48 expiration)
        internal
    {
        /// @solidity memory-safe-assembly
        assembly {
            let addressMask := shr(96, not(0))
            let m := mload(0x40)
            mstore(m, 0x87517c45) // `approve(address,address,uint160,uint48)`.
            mstore(add(m, 0x20), and(addressMask, token))
            mstore(add(m, 0x40), and(addressMask, spender))
            mstore(add(m, 0x60), and(addressMask, amount))
            mstore(add(m, 0x80), and(0xffffffffffff, expiration))
            if iszero(call(gas(), PERMIT2, 0, add(m, 0x1c), 0xa0, codesize(), 0x00)) {
                mstore(0x00, 0x324f14ae) // `Permit2ApproveFailed()`.
                revert(0x1c, 0x04)
            }
        }
    }

    /// @dev Revokes an approval for `token` and `spender` for `address(this)`.
    function permit2Lockdown(address token, address spender) internal {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, 0xcc53287f) // `Permit2.lockdown`.
            mstore(add(m, 0x20), 0x20) // Offset of the `approvals`.
            mstore(add(m, 0x40), 1) // `approvals.length`.
            mstore(add(m, 0x60), shr(96, shl(96, token)))
            mstore(add(m, 0x80), shr(96, shl(96, spender)))
            if iszero(call(gas(), PERMIT2, 0, add(m, 0x1c), 0xa0, codesize(), 0x00)) {
                mstore(0x00, 0x96b3de23) // `Permit2LockdownFailed()`.
                revert(0x1c, 0x04)
            }
        }
    }
}

File 13 of 28 : SafeCastLib.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @notice Safe integer casting library that reverts on overflow.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeCastLib.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeCast.sol)
/// @dev Optimized for runtime gas for very high number of optimizer runs (i.e. >= 1000000).
library SafeCastLib {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Unable to cast to the target type due to overflow.
    error Overflow();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*          UNSIGNED INTEGER SAFE CASTING OPERATIONS          */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Casts `x` to a uint8. Reverts on overflow.
    function toUint8(uint256 x) internal pure returns (uint8) {
        if (x >= 1 << 8) _revertOverflow();
        return uint8(x);
    }

    /// @dev Casts `x` to a uint16. Reverts on overflow.
    function toUint16(uint256 x) internal pure returns (uint16) {
        if (x >= 1 << 16) _revertOverflow();
        return uint16(x);
    }

    /// @dev Casts `x` to a uint24. Reverts on overflow.
    function toUint24(uint256 x) internal pure returns (uint24) {
        if (x >= 1 << 24) _revertOverflow();
        return uint24(x);
    }

    /// @dev Casts `x` to a uint32. Reverts on overflow.
    function toUint32(uint256 x) internal pure returns (uint32) {
        if (x >= 1 << 32) _revertOverflow();
        return uint32(x);
    }

    /// @dev Casts `x` to a uint40. Reverts on overflow.
    function toUint40(uint256 x) internal pure returns (uint40) {
        if (x >= 1 << 40) _revertOverflow();
        return uint40(x);
    }

    /// @dev Casts `x` to a uint48. Reverts on overflow.
    function toUint48(uint256 x) internal pure returns (uint48) {
        if (x >= 1 << 48) _revertOverflow();
        return uint48(x);
    }

    /// @dev Casts `x` to a uint56. Reverts on overflow.
    function toUint56(uint256 x) internal pure returns (uint56) {
        if (x >= 1 << 56) _revertOverflow();
        return uint56(x);
    }

    /// @dev Casts `x` to a uint64. Reverts on overflow.
    function toUint64(uint256 x) internal pure returns (uint64) {
        if (x >= 1 << 64) _revertOverflow();
        return uint64(x);
    }

    /// @dev Casts `x` to a uint72. Reverts on overflow.
    function toUint72(uint256 x) internal pure returns (uint72) {
        if (x >= 1 << 72) _revertOverflow();
        return uint72(x);
    }

    /// @dev Casts `x` to a uint80. Reverts on overflow.
    function toUint80(uint256 x) internal pure returns (uint80) {
        if (x >= 1 << 80) _revertOverflow();
        return uint80(x);
    }

    /// @dev Casts `x` to a uint88. Reverts on overflow.
    function toUint88(uint256 x) internal pure returns (uint88) {
        if (x >= 1 << 88) _revertOverflow();
        return uint88(x);
    }

    /// @dev Casts `x` to a uint96. Reverts on overflow.
    function toUint96(uint256 x) internal pure returns (uint96) {
        if (x >= 1 << 96) _revertOverflow();
        return uint96(x);
    }

    /// @dev Casts `x` to a uint104. Reverts on overflow.
    function toUint104(uint256 x) internal pure returns (uint104) {
        if (x >= 1 << 104) _revertOverflow();
        return uint104(x);
    }

    /// @dev Casts `x` to a uint112. Reverts on overflow.
    function toUint112(uint256 x) internal pure returns (uint112) {
        if (x >= 1 << 112) _revertOverflow();
        return uint112(x);
    }

    /// @dev Casts `x` to a uint120. Reverts on overflow.
    function toUint120(uint256 x) internal pure returns (uint120) {
        if (x >= 1 << 120) _revertOverflow();
        return uint120(x);
    }

    /// @dev Casts `x` to a uint128. Reverts on overflow.
    function toUint128(uint256 x) internal pure returns (uint128) {
        if (x >= 1 << 128) _revertOverflow();
        return uint128(x);
    }

    /// @dev Casts `x` to a uint136. Reverts on overflow.
    function toUint136(uint256 x) internal pure returns (uint136) {
        if (x >= 1 << 136) _revertOverflow();
        return uint136(x);
    }

    /// @dev Casts `x` to a uint144. Reverts on overflow.
    function toUint144(uint256 x) internal pure returns (uint144) {
        if (x >= 1 << 144) _revertOverflow();
        return uint144(x);
    }

    /// @dev Casts `x` to a uint152. Reverts on overflow.
    function toUint152(uint256 x) internal pure returns (uint152) {
        if (x >= 1 << 152) _revertOverflow();
        return uint152(x);
    }

    /// @dev Casts `x` to a uint160. Reverts on overflow.
    function toUint160(uint256 x) internal pure returns (uint160) {
        if (x >= 1 << 160) _revertOverflow();
        return uint160(x);
    }

    /// @dev Casts `x` to a uint168. Reverts on overflow.
    function toUint168(uint256 x) internal pure returns (uint168) {
        if (x >= 1 << 168) _revertOverflow();
        return uint168(x);
    }

    /// @dev Casts `x` to a uint176. Reverts on overflow.
    function toUint176(uint256 x) internal pure returns (uint176) {
        if (x >= 1 << 176) _revertOverflow();
        return uint176(x);
    }

    /// @dev Casts `x` to a uint184. Reverts on overflow.
    function toUint184(uint256 x) internal pure returns (uint184) {
        if (x >= 1 << 184) _revertOverflow();
        return uint184(x);
    }

    /// @dev Casts `x` to a uint192. Reverts on overflow.
    function toUint192(uint256 x) internal pure returns (uint192) {
        if (x >= 1 << 192) _revertOverflow();
        return uint192(x);
    }

    /// @dev Casts `x` to a uint200. Reverts on overflow.
    function toUint200(uint256 x) internal pure returns (uint200) {
        if (x >= 1 << 200) _revertOverflow();
        return uint200(x);
    }

    /// @dev Casts `x` to a uint208. Reverts on overflow.
    function toUint208(uint256 x) internal pure returns (uint208) {
        if (x >= 1 << 208) _revertOverflow();
        return uint208(x);
    }

    /// @dev Casts `x` to a uint216. Reverts on overflow.
    function toUint216(uint256 x) internal pure returns (uint216) {
        if (x >= 1 << 216) _revertOverflow();
        return uint216(x);
    }

    /// @dev Casts `x` to a uint224. Reverts on overflow.
    function toUint224(uint256 x) internal pure returns (uint224) {
        if (x >= 1 << 224) _revertOverflow();
        return uint224(x);
    }

    /// @dev Casts `x` to a uint232. Reverts on overflow.
    function toUint232(uint256 x) internal pure returns (uint232) {
        if (x >= 1 << 232) _revertOverflow();
        return uint232(x);
    }

    /// @dev Casts `x` to a uint240. Reverts on overflow.
    function toUint240(uint256 x) internal pure returns (uint240) {
        if (x >= 1 << 240) _revertOverflow();
        return uint240(x);
    }

    /// @dev Casts `x` to a uint248. Reverts on overflow.
    function toUint248(uint256 x) internal pure returns (uint248) {
        if (x >= 1 << 248) _revertOverflow();
        return uint248(x);
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*           SIGNED INTEGER SAFE CASTING OPERATIONS           */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Casts `x` to a int8. Reverts on overflow.
    function toInt8(int256 x) internal pure returns (int8) {
        unchecked {
            if (((1 << 7) + uint256(x)) >> 8 == uint256(0)) return int8(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int16. Reverts on overflow.
    function toInt16(int256 x) internal pure returns (int16) {
        unchecked {
            if (((1 << 15) + uint256(x)) >> 16 == uint256(0)) return int16(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int24. Reverts on overflow.
    function toInt24(int256 x) internal pure returns (int24) {
        unchecked {
            if (((1 << 23) + uint256(x)) >> 24 == uint256(0)) return int24(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int32. Reverts on overflow.
    function toInt32(int256 x) internal pure returns (int32) {
        unchecked {
            if (((1 << 31) + uint256(x)) >> 32 == uint256(0)) return int32(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int40. Reverts on overflow.
    function toInt40(int256 x) internal pure returns (int40) {
        unchecked {
            if (((1 << 39) + uint256(x)) >> 40 == uint256(0)) return int40(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int48. Reverts on overflow.
    function toInt48(int256 x) internal pure returns (int48) {
        unchecked {
            if (((1 << 47) + uint256(x)) >> 48 == uint256(0)) return int48(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int56. Reverts on overflow.
    function toInt56(int256 x) internal pure returns (int56) {
        unchecked {
            if (((1 << 55) + uint256(x)) >> 56 == uint256(0)) return int56(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int64. Reverts on overflow.
    function toInt64(int256 x) internal pure returns (int64) {
        unchecked {
            if (((1 << 63) + uint256(x)) >> 64 == uint256(0)) return int64(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int72. Reverts on overflow.
    function toInt72(int256 x) internal pure returns (int72) {
        unchecked {
            if (((1 << 71) + uint256(x)) >> 72 == uint256(0)) return int72(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int80. Reverts on overflow.
    function toInt80(int256 x) internal pure returns (int80) {
        unchecked {
            if (((1 << 79) + uint256(x)) >> 80 == uint256(0)) return int80(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int88. Reverts on overflow.
    function toInt88(int256 x) internal pure returns (int88) {
        unchecked {
            if (((1 << 87) + uint256(x)) >> 88 == uint256(0)) return int88(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int96. Reverts on overflow.
    function toInt96(int256 x) internal pure returns (int96) {
        unchecked {
            if (((1 << 95) + uint256(x)) >> 96 == uint256(0)) return int96(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int104. Reverts on overflow.
    function toInt104(int256 x) internal pure returns (int104) {
        unchecked {
            if (((1 << 103) + uint256(x)) >> 104 == uint256(0)) return int104(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int112. Reverts on overflow.
    function toInt112(int256 x) internal pure returns (int112) {
        unchecked {
            if (((1 << 111) + uint256(x)) >> 112 == uint256(0)) return int112(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int120. Reverts on overflow.
    function toInt120(int256 x) internal pure returns (int120) {
        unchecked {
            if (((1 << 119) + uint256(x)) >> 120 == uint256(0)) return int120(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int128. Reverts on overflow.
    function toInt128(int256 x) internal pure returns (int128) {
        unchecked {
            if (((1 << 127) + uint256(x)) >> 128 == uint256(0)) return int128(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int136. Reverts on overflow.
    function toInt136(int256 x) internal pure returns (int136) {
        unchecked {
            if (((1 << 135) + uint256(x)) >> 136 == uint256(0)) return int136(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int144. Reverts on overflow.
    function toInt144(int256 x) internal pure returns (int144) {
        unchecked {
            if (((1 << 143) + uint256(x)) >> 144 == uint256(0)) return int144(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int152. Reverts on overflow.
    function toInt152(int256 x) internal pure returns (int152) {
        unchecked {
            if (((1 << 151) + uint256(x)) >> 152 == uint256(0)) return int152(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int160. Reverts on overflow.
    function toInt160(int256 x) internal pure returns (int160) {
        unchecked {
            if (((1 << 159) + uint256(x)) >> 160 == uint256(0)) return int160(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int168. Reverts on overflow.
    function toInt168(int256 x) internal pure returns (int168) {
        unchecked {
            if (((1 << 167) + uint256(x)) >> 168 == uint256(0)) return int168(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int176. Reverts on overflow.
    function toInt176(int256 x) internal pure returns (int176) {
        unchecked {
            if (((1 << 175) + uint256(x)) >> 176 == uint256(0)) return int176(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int184. Reverts on overflow.
    function toInt184(int256 x) internal pure returns (int184) {
        unchecked {
            if (((1 << 183) + uint256(x)) >> 184 == uint256(0)) return int184(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int192. Reverts on overflow.
    function toInt192(int256 x) internal pure returns (int192) {
        unchecked {
            if (((1 << 191) + uint256(x)) >> 192 == uint256(0)) return int192(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int200. Reverts on overflow.
    function toInt200(int256 x) internal pure returns (int200) {
        unchecked {
            if (((1 << 199) + uint256(x)) >> 200 == uint256(0)) return int200(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int208. Reverts on overflow.
    function toInt208(int256 x) internal pure returns (int208) {
        unchecked {
            if (((1 << 207) + uint256(x)) >> 208 == uint256(0)) return int208(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int216. Reverts on overflow.
    function toInt216(int256 x) internal pure returns (int216) {
        unchecked {
            if (((1 << 215) + uint256(x)) >> 216 == uint256(0)) return int216(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int224. Reverts on overflow.
    function toInt224(int256 x) internal pure returns (int224) {
        unchecked {
            if (((1 << 223) + uint256(x)) >> 224 == uint256(0)) return int224(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int232. Reverts on overflow.
    function toInt232(int256 x) internal pure returns (int232) {
        unchecked {
            if (((1 << 231) + uint256(x)) >> 232 == uint256(0)) return int232(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int240. Reverts on overflow.
    function toInt240(int256 x) internal pure returns (int240) {
        unchecked {
            if (((1 << 239) + uint256(x)) >> 240 == uint256(0)) return int240(x);
            _revertOverflow();
        }
    }

    /// @dev Casts `x` to a int248. Reverts on overflow.
    function toInt248(int256 x) internal pure returns (int248) {
        unchecked {
            if (((1 << 247) + uint256(x)) >> 248 == uint256(0)) return int248(x);
            _revertOverflow();
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*               OTHER SAFE CASTING OPERATIONS                */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Casts `x` to a int8. Reverts on overflow.
    function toInt8(uint256 x) internal pure returns (int8) {
        if (x >= 1 << 7) _revertOverflow();
        return int8(int256(x));
    }

    /// @dev Casts `x` to a int16. Reverts on overflow.
    function toInt16(uint256 x) internal pure returns (int16) {
        if (x >= 1 << 15) _revertOverflow();
        return int16(int256(x));
    }

    /// @dev Casts `x` to a int24. Reverts on overflow.
    function toInt24(uint256 x) internal pure returns (int24) {
        if (x >= 1 << 23) _revertOverflow();
        return int24(int256(x));
    }

    /// @dev Casts `x` to a int32. Reverts on overflow.
    function toInt32(uint256 x) internal pure returns (int32) {
        if (x >= 1 << 31) _revertOverflow();
        return int32(int256(x));
    }

    /// @dev Casts `x` to a int40. Reverts on overflow.
    function toInt40(uint256 x) internal pure returns (int40) {
        if (x >= 1 << 39) _revertOverflow();
        return int40(int256(x));
    }

    /// @dev Casts `x` to a int48. Reverts on overflow.
    function toInt48(uint256 x) internal pure returns (int48) {
        if (x >= 1 << 47) _revertOverflow();
        return int48(int256(x));
    }

    /// @dev Casts `x` to a int56. Reverts on overflow.
    function toInt56(uint256 x) internal pure returns (int56) {
        if (x >= 1 << 55) _revertOverflow();
        return int56(int256(x));
    }

    /// @dev Casts `x` to a int64. Reverts on overflow.
    function toInt64(uint256 x) internal pure returns (int64) {
        if (x >= 1 << 63) _revertOverflow();
        return int64(int256(x));
    }

    /// @dev Casts `x` to a int72. Reverts on overflow.
    function toInt72(uint256 x) internal pure returns (int72) {
        if (x >= 1 << 71) _revertOverflow();
        return int72(int256(x));
    }

    /// @dev Casts `x` to a int80. Reverts on overflow.
    function toInt80(uint256 x) internal pure returns (int80) {
        if (x >= 1 << 79) _revertOverflow();
        return int80(int256(x));
    }

    /// @dev Casts `x` to a int88. Reverts on overflow.
    function toInt88(uint256 x) internal pure returns (int88) {
        if (x >= 1 << 87) _revertOverflow();
        return int88(int256(x));
    }

    /// @dev Casts `x` to a int96. Reverts on overflow.
    function toInt96(uint256 x) internal pure returns (int96) {
        if (x >= 1 << 95) _revertOverflow();
        return int96(int256(x));
    }

    /// @dev Casts `x` to a int104. Reverts on overflow.
    function toInt104(uint256 x) internal pure returns (int104) {
        if (x >= 1 << 103) _revertOverflow();
        return int104(int256(x));
    }

    /// @dev Casts `x` to a int112. Reverts on overflow.
    function toInt112(uint256 x) internal pure returns (int112) {
        if (x >= 1 << 111) _revertOverflow();
        return int112(int256(x));
    }

    /// @dev Casts `x` to a int120. Reverts on overflow.
    function toInt120(uint256 x) internal pure returns (int120) {
        if (x >= 1 << 119) _revertOverflow();
        return int120(int256(x));
    }

    /// @dev Casts `x` to a int128. Reverts on overflow.
    function toInt128(uint256 x) internal pure returns (int128) {
        if (x >= 1 << 127) _revertOverflow();
        return int128(int256(x));
    }

    /// @dev Casts `x` to a int136. Reverts on overflow.
    function toInt136(uint256 x) internal pure returns (int136) {
        if (x >= 1 << 135) _revertOverflow();
        return int136(int256(x));
    }

    /// @dev Casts `x` to a int144. Reverts on overflow.
    function toInt144(uint256 x) internal pure returns (int144) {
        if (x >= 1 << 143) _revertOverflow();
        return int144(int256(x));
    }

    /// @dev Casts `x` to a int152. Reverts on overflow.
    function toInt152(uint256 x) internal pure returns (int152) {
        if (x >= 1 << 151) _revertOverflow();
        return int152(int256(x));
    }

    /// @dev Casts `x` to a int160. Reverts on overflow.
    function toInt160(uint256 x) internal pure returns (int160) {
        if (x >= 1 << 159) _revertOverflow();
        return int160(int256(x));
    }

    /// @dev Casts `x` to a int168. Reverts on overflow.
    function toInt168(uint256 x) internal pure returns (int168) {
        if (x >= 1 << 167) _revertOverflow();
        return int168(int256(x));
    }

    /// @dev Casts `x` to a int176. Reverts on overflow.
    function toInt176(uint256 x) internal pure returns (int176) {
        if (x >= 1 << 175) _revertOverflow();
        return int176(int256(x));
    }

    /// @dev Casts `x` to a int184. Reverts on overflow.
    function toInt184(uint256 x) internal pure returns (int184) {
        if (x >= 1 << 183) _revertOverflow();
        return int184(int256(x));
    }

    /// @dev Casts `x` to a int192. Reverts on overflow.
    function toInt192(uint256 x) internal pure returns (int192) {
        if (x >= 1 << 191) _revertOverflow();
        return int192(int256(x));
    }

    /// @dev Casts `x` to a int200. Reverts on overflow.
    function toInt200(uint256 x) internal pure returns (int200) {
        if (x >= 1 << 199) _revertOverflow();
        return int200(int256(x));
    }

    /// @dev Casts `x` to a int208. Reverts on overflow.
    function toInt208(uint256 x) internal pure returns (int208) {
        if (x >= 1 << 207) _revertOverflow();
        return int208(int256(x));
    }

    /// @dev Casts `x` to a int216. Reverts on overflow.
    function toInt216(uint256 x) internal pure returns (int216) {
        if (x >= 1 << 215) _revertOverflow();
        return int216(int256(x));
    }

    /// @dev Casts `x` to a int224. Reverts on overflow.
    function toInt224(uint256 x) internal pure returns (int224) {
        if (x >= 1 << 223) _revertOverflow();
        return int224(int256(x));
    }

    /// @dev Casts `x` to a int232. Reverts on overflow.
    function toInt232(uint256 x) internal pure returns (int232) {
        if (x >= 1 << 231) _revertOverflow();
        return int232(int256(x));
    }

    /// @dev Casts `x` to a int240. Reverts on overflow.
    function toInt240(uint256 x) internal pure returns (int240) {
        if (x >= 1 << 239) _revertOverflow();
        return int240(int256(x));
    }

    /// @dev Casts `x` to a int248. Reverts on overflow.
    function toInt248(uint256 x) internal pure returns (int248) {
        if (x >= 1 << 247) _revertOverflow();
        return int248(int256(x));
    }

    /// @dev Casts `x` to a int256. Reverts on overflow.
    function toInt256(uint256 x) internal pure returns (int256) {
        if (int256(x) >= 0) return int256(x);
        _revertOverflow();
    }

    /// @dev Casts `x` to a uint256. Reverts on overflow.
    function toUint256(int256 x) internal pure returns (uint256) {
        if (x >= 0) return uint256(x);
        _revertOverflow();
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                      PRIVATE HELPERS                       */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    function _revertOverflow() private pure {
        /// @solidity memory-safe-assembly
        assembly {
            // Store the function selector of `Overflow()`.
            mstore(0x00, 0x35278d12)
            // Revert with (offset, size).
            revert(0x1c, 0x04)
        }
    }
}

File 14 of 28 : ExposedStorage.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

import {IExposedStorage} from "../interfaces/IExposedStorage.sol";

abstract contract ExposedStorage is IExposedStorage {
    function sload() external view {
        assembly ("memory-safe") {
            for { let i := 4 } lt(i, calldatasize()) { i := add(i, 32) } { mstore(sub(i, 4), sload(calldataload(i))) }
            return(0, sub(calldatasize(), 4))
        }
    }

    function tload() external view {
        assembly ("memory-safe") {
            for { let i := 4 } lt(i, calldatasize()) { i := add(i, 32) } { mstore(sub(i, 4), tload(calldataload(i))) }
            return(0, sub(calldatasize(), 4))
        }
    }
}

File 15 of 28 : liquidity.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol";
import {SafeCastLib} from "solady/utils/SafeCastLib.sol";
import {amount0Delta, amount1Delta, sortAndConvertToFixedSqrtRatios} from "./delta.sol";
import {SqrtRatio} from "../types/sqrtRatio.sol";

/**
 * @notice Returns the token0 and token1 delta owed for a given change in liquidity.
 * @param sqrtRatio        Current price (as a sqrt ratio).
 * @param liquidityDelta   Signed liquidity change; positive = added, negative = removed.
 * @param sqrtRatioLower   The lower bound of the price range (as a sqrt ratio).
 * @param sqrtRatioUpper   The upper bound of the price range (as a sqrt ratio).
 */
function liquidityDeltaToAmountDelta(
    SqrtRatio sqrtRatio,
    int128 liquidityDelta,
    SqrtRatio sqrtRatioLower,
    SqrtRatio sqrtRatioUpper
) pure returns (int128 delta0, int128 delta1) {
    unchecked {
        if (liquidityDelta == 0) {
            return (0, 0);
        }
        bool isPositive = (liquidityDelta > 0);
        // type(uint256).max cast to int256 is -1
        int256 sign = int256(FixedPointMathLib.ternary(isPositive, 1, type(uint256).max));
        // absolute value of a int128 always fits in a uint128
        uint128 magnitude = uint128(FixedPointMathLib.abs(liquidityDelta));

        if (sqrtRatio <= sqrtRatioLower) {
            delta0 = SafeCastLib.toInt128(
                sign * int256(uint256(amount0Delta(sqrtRatioLower, sqrtRatioUpper, magnitude, isPositive)))
            );
        } else if (sqrtRatio < sqrtRatioUpper) {
            delta0 = SafeCastLib.toInt128(
                sign * int256(uint256(amount0Delta(sqrtRatio, sqrtRatioUpper, magnitude, isPositive)))
            );
            delta1 = SafeCastLib.toInt128(
                sign * int256(uint256(amount1Delta(sqrtRatioLower, sqrtRatio, magnitude, isPositive)))
            );
        } else {
            delta1 = SafeCastLib.toInt128(
                sign * int256(uint256(amount1Delta(sqrtRatioLower, sqrtRatioUpper, magnitude, isPositive)))
            );
        }
    }
}

function maxLiquidityForToken0(uint256 sqrtRatioLower, uint256 sqrtRatioUpper, uint128 amount) pure returns (uint256) {
    unchecked {
        uint256 numerator_1 = FixedPointMathLib.fullMulDivN(sqrtRatioLower, sqrtRatioUpper, 128);

        return FixedPointMathLib.fullMulDiv(amount, numerator_1, (sqrtRatioUpper - sqrtRatioLower));
    }
}

function maxLiquidityForToken1(uint256 sqrtRatioLower, uint256 sqrtRatioUpper, uint128 amount) pure returns (uint256) {
    unchecked {
        return (uint256(amount) << 128) / (sqrtRatioUpper - sqrtRatioLower);
    }
}

function maxLiquidity(
    SqrtRatio _sqrtRatio,
    SqrtRatio sqrtRatioA,
    SqrtRatio sqrtRatioB,
    uint128 amount0,
    uint128 amount1
) pure returns (uint128) {
    uint256 sqrtRatio = _sqrtRatio.toFixed();
    (uint256 sqrtRatioLower, uint256 sqrtRatioUpper) = sortAndConvertToFixedSqrtRatios(sqrtRatioA, sqrtRatioB);

    if (sqrtRatio <= sqrtRatioLower) {
        return uint128(
            FixedPointMathLib.min(type(uint128).max, maxLiquidityForToken0(sqrtRatioLower, sqrtRatioUpper, amount0))
        );
    } else if (sqrtRatio < sqrtRatioUpper) {
        return uint128(
            FixedPointMathLib.min(
                type(uint128).max,
                FixedPointMathLib.min(
                    maxLiquidityForToken0(sqrtRatio, sqrtRatioUpper, amount0),
                    maxLiquidityForToken1(sqrtRatioLower, sqrtRatio, amount1)
                )
            )
        );
    } else {
        return uint128(
            FixedPointMathLib.min(type(uint128).max, maxLiquidityForToken1(sqrtRatioLower, sqrtRatioUpper, amount1))
        );
    }
}

error LiquidityDeltaOverflow();

function addLiquidityDelta(uint128 liquidity, int128 liquidityDelta) pure returns (uint128 result) {
    assembly ("memory-safe") {
        result := add(liquidity, liquidityDelta)
        if and(result, shl(128, 0xffffffffffffffffffffffffffffffff)) {
            mstore(0, shl(224, 0x6d862c50))
            revert(0, 4)
        }
    }
}

function subLiquidityDelta(uint128 liquidity, int128 liquidityDelta) pure returns (uint128 result) {
    assembly ("memory-safe") {
        result := sub(liquidity, liquidityDelta)
        if and(result, shl(128, 0xffffffffffffffffffffffffffffffff)) {
            mstore(0, shl(224, 0x6d862c50))
            revert(0, 4)
        }
    }
}

File 16 of 28 : fee.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

// Returns the fee to charge based on the amount, which is the fee (a 0.64 number) times the
// amount, rounded up
function computeFee(uint128 amount, uint64 fee) pure returns (uint128 result) {
    assembly ("memory-safe") {
        result := shr(64, add(mul(amount, fee), 0xffffffffffffffff))
    }
}

error AmountBeforeFeeOverflow();

// Returns the amount before the fee is applied, which is the amount minus the fee, rounded up
function amountBeforeFee(uint128 afterFee, uint64 fee) pure returns (uint128 result) {
    uint256 r;
    assembly ("memory-safe") {
        let v := shl(64, afterFee)
        let d := sub(0x10000000000000000, fee)
        let q := div(v, d)
        r := add(iszero(iszero(mod(v, d))), q)
    }
    if (r > type(uint128).max) {
        revert AmountBeforeFeeOverflow();
    }
    result = uint128(r);
}

File 17 of 28 : tickBitmap.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

import {Bitmap} from "../math/bitmap.sol";
import {MIN_TICK, MAX_TICK} from "../math/constants.sol";
import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol";

// Returns the index of the word and the index _in_ that word which contains the bit representing whether the tick is initialized
// Addition of the offset does two things--it centers the 0 tick within a single bitmap regardless of tick spacing,
// and gives us a contiguous range of unsigned integers for all ticks
// Always rounds the tick down to the nearest multiple of tickSpacing
function tickToBitmapWordAndIndex(int32 tick, uint32 tickSpacing) pure returns (uint256 word, uint256 index) {
    assembly ("memory-safe") {
        let rawIndex := add(sub(sdiv(tick, tickSpacing), slt(smod(tick, tickSpacing), 0)), 89421695)
        word := div(rawIndex, 256)
        index := mod(rawIndex, 256)
    }
}

// Returns the index of the word and the index _in_ that word which contains the bit representing whether the tick is initialized
/// @dev This function is only safe if tickSpacing is between 1 and MAX_TICK_SPACING, and word/index correspond to the results of tickToBitmapWordAndIndex for a tick between MIN_TICK and MAX_TICK
function bitmapWordAndIndexToTick(uint256 word, uint256 index, uint32 tickSpacing) pure returns (int32 tick) {
    assembly ("memory-safe") {
        let rawIndex := add(mul(word, 256), index)
        tick := mul(sub(rawIndex, 89421695), tickSpacing)
    }
}

// Flips the tick in the bitmap from true to false or vice versa
function flipTick(mapping(uint256 word => Bitmap bitmap) storage map, int32 tick, uint32 tickSpacing) {
    (uint256 word, uint256 index) = tickToBitmapWordAndIndex(tick, tickSpacing);
    assembly ("memory-safe") {
        mstore(0, word)
        mstore(32, map.slot)
        let k := keccak256(0, 64)
        let v := sload(k)
        sstore(k, xor(v, shl(index, 1)))
    }
}

function findNextInitializedTick(
    mapping(uint256 word => Bitmap bitmap) storage map,
    int32 fromTick,
    uint32 tickSpacing,
    uint256 skipAhead
) view returns (int32 nextTick, bool isInitialized) {
    unchecked {
        nextTick = fromTick;
        while (true) {
            // convert the given tick to the bitmap position of the next nearest potential initialized tick
            (uint256 word, uint256 index) = tickToBitmapWordAndIndex(nextTick + int32(tickSpacing), tickSpacing);

            // find the index of the previous tick in that word
            uint256 nextIndex = map[word].geSetBit(uint8(index));

            // if we found one, return it
            if (nextIndex != 256) {
                (nextTick, isInitialized) = (bitmapWordAndIndexToTick(word, nextIndex, tickSpacing), true);
                break;
            }

            // otherwise, return the tick of the most significant bit in the word
            nextTick = bitmapWordAndIndexToTick(word, 255, tickSpacing);

            if (nextTick >= MAX_TICK) {
                nextTick = MAX_TICK;
                break;
            }

            // if we are done searching, stop here
            if (skipAhead == 0) {
                break;
            }

            skipAhead--;
        }
    }
}

function findPrevInitializedTick(
    mapping(uint256 word => Bitmap bitmap) storage map,
    int32 fromTick,
    uint32 tickSpacing,
    uint256 skipAhead
) view returns (int32 prevTick, bool isInitialized) {
    unchecked {
        prevTick = fromTick;
        while (true) {
            // convert the given tick to its bitmap position
            (uint256 word, uint256 index) = tickToBitmapWordAndIndex(prevTick, tickSpacing);

            // find the index of the previous tick in that word
            uint256 prevIndex = map[word].leSetBit(uint8(index));

            if (prevIndex != 256) {
                (prevTick, isInitialized) = (bitmapWordAndIndexToTick(word, prevIndex, tickSpacing), true);
                break;
            }

            prevTick = bitmapWordAndIndexToTick(word, 0, tickSpacing);

            if (prevTick <= MIN_TICK) {
                prevTick = MIN_TICK;
                break;
            }

            if (skipAhead == 0) {
                break;
            }

            skipAhead--;
            prevTick--;
        }
    }
}

File 18 of 28 : ICore.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

import {CallPoints} from "../types/callPoints.sol";
import {PoolKey} from "../types/poolKey.sol";
import {PositionKey, Bounds} from "../types/positionKey.sol";
import {FeesPerLiquidity} from "../types/feesPerLiquidity.sol";
import {IExposedStorage} from "../interfaces/IExposedStorage.sol";
import {IFlashAccountant} from "../interfaces/IFlashAccountant.sol";
import {SqrtRatio} from "../types/sqrtRatio.sol";

struct UpdatePositionParameters {
    bytes32 salt;
    Bounds bounds;
    int128 liquidityDelta;
}

interface IExtension {
    function beforeInitializePool(address caller, PoolKey calldata key, int32 tick) external;
    function afterInitializePool(address caller, PoolKey calldata key, int32 tick, SqrtRatio sqrtRatio) external;

    function beforeUpdatePosition(address locker, PoolKey memory poolKey, UpdatePositionParameters memory params)
        external;
    function afterUpdatePosition(
        address locker,
        PoolKey memory poolKey,
        UpdatePositionParameters memory params,
        int128 delta0,
        int128 delta1
    ) external;

    function beforeSwap(
        address locker,
        PoolKey memory poolKey,
        int128 amount,
        bool isToken1,
        SqrtRatio sqrtRatioLimit,
        uint256 skipAhead
    ) external;
    function afterSwap(
        address locker,
        PoolKey memory poolKey,
        int128 amount,
        bool isToken1,
        SqrtRatio sqrtRatioLimit,
        uint256 skipAhead,
        int128 delta0,
        int128 delta1
    ) external;

    function beforeCollectFees(address locker, PoolKey memory poolKey, bytes32 salt, Bounds memory bounds) external;
    function afterCollectFees(
        address locker,
        PoolKey memory poolKey,
        bytes32 salt,
        Bounds memory bounds,
        uint128 amount0,
        uint128 amount1
    ) external;
}

interface ICore is IFlashAccountant, IExposedStorage {
    event ProtocolFeesWithdrawn(address recipient, address token, uint256 amount);
    event ExtensionRegistered(address extension);
    event PoolInitialized(bytes32 poolId, PoolKey poolKey, int32 tick, SqrtRatio sqrtRatio);
    event PositionFeesCollected(bytes32 poolId, PositionKey positionKey, uint128 amount0, uint128 amount1);
    event FeesAccumulated(bytes32 poolId, uint128 amount0, uint128 amount1);
    event PositionUpdated(
        address locker, bytes32 poolId, UpdatePositionParameters params, int128 delta0, int128 delta1
    );

    // This error is thrown by swaps and deposits when this particular deployment of the contract is expired.
    error FailedRegisterInvalidCallPoints();
    error ExtensionAlreadyRegistered();
    error InsufficientSavedBalance();
    error PoolAlreadyInitialized();
    error ExtensionNotRegistered();
    error PoolNotInitialized();
    error MustCollectFeesBeforeWithdrawingAllLiquidity();
    error SqrtRatioLimitOutOfRange();
    error InvalidSqrtRatioLimit();
    error SavedBalanceTokensNotSorted();

    // Allows the owner of the contract to withdraw the protocol withdrawal fees collected
    // To withdraw the native token protocol fees, call with token = NATIVE_TOKEN_ADDRESS
    function withdrawProtocolFees(address recipient, address token, uint256 amount) external;

    // Extensions must call this function to become registered. The call points are validated against the caller address
    function registerExtension(CallPoints memory expectedCallPoints) external;

    // Sets the initial price for a new pool in terms of tick.
    function initializePool(PoolKey memory poolKey, int32 tick) external returns (SqrtRatio sqrtRatio);

    function prevInitializedTick(bytes32 poolId, int32 fromTick, uint32 tickSpacing, uint256 skipAhead)
        external
        view
        returns (int32 tick, bool isInitialized);

    function nextInitializedTick(bytes32 poolId, int32 fromTick, uint32 tickSpacing, uint256 skipAhead)
        external
        view
        returns (int32 tick, bool isInitialized);

    // Loads 2 tokens from the saved balances of the caller as payment in the current context.
    function load(address token0, address token1, bytes32 salt, uint128 amount0, uint128 amount1) external;

    // Saves an amount of 2 tokens to be used later, in a single slot.
    function save(address owner, address token0, address token1, bytes32 salt, uint128 amount0, uint128 amount1)
        external
        payable;

    // Returns the pool fees per liquidity inside the given bounds.
    function getPoolFeesPerLiquidityInside(PoolKey memory poolKey, Bounds memory bounds)
        external
        view
        returns (FeesPerLiquidity memory);

    // Accumulates tokens to fees of a pool. Only callable by the extension of the specified pool
    // key, i.e. the current locker _must_ be the extension.
    // The extension must call this function within a lock callback.
    function accumulateAsFees(PoolKey memory poolKey, uint128 amount0, uint128 amount1) external payable;

    function updatePosition(PoolKey memory poolKey, UpdatePositionParameters memory params)
        external
        payable
        returns (int128 delta0, int128 delta1);

    function collectFees(PoolKey memory poolKey, bytes32 salt, Bounds memory bounds)
        external
        returns (uint128 amount0, uint128 amount1);

    function swap_611415377(
        PoolKey memory poolKey,
        int128 amount,
        bool isToken1,
        SqrtRatio sqrtRatioLimit,
        uint256 skipAhead
    ) external payable returns (int128 delta0, int128 delta1);
}

File 19 of 28 : FlashAccountant.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

import {NATIVE_TOKEN_ADDRESS} from "../math/constants.sol";
import {IPayer, IFlashAccountant} from "../interfaces/IFlashAccountant.sol";
import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol";

abstract contract FlashAccountant is IFlashAccountant {
    // These offsets are selected so that they do not accidentally overlap with any other base contract's use of transient storage

    // cast keccak "FlashAccountant#CURRENT_LOCKER_SLOT"
    uint256 private constant _CURRENT_LOCKER_SLOT = 0x07cc7f5195d862f505d6b095c82f92e00cfc1766f5bca4383c28dc5fca1555fd;
    // cast keccak "FlashAccountant#NONZERO_DEBT_COUNT_OFFSET"
    uint256 private constant _NONZERO_DEBT_COUNT_OFFSET =
        0x7772acfd7e0f66ebb20a058830296c3dc1301b111d23348e1c961d324223190d;
    // cast keccak "FlashAccountant#DEBT_HASH_OFFSET"
    uint256 private constant _DEBT_HASH_OFFSET = 0x3fee1dc3ade45aa30d633b5b8645760533723e46597841ef1126c6577a091742;
    // cast keccak "FlashAccountant#PAY_REENTRANCY_LOCK"
    uint256 private constant _PAY_REENTRANCY_LOCK = 0xe1be600102d456bf2d4dee36e1641404df82292916888bf32557e00dfe166412;

    function _getLocker() internal view returns (uint256 id, address locker) {
        assembly ("memory-safe") {
            let current := tload(_CURRENT_LOCKER_SLOT)

            if iszero(current) {
                // cast sig "NotLocked()"
                mstore(0, shl(224, 0x1834e265))
                revert(0, 4)
            }

            id := sub(shr(160, current), 1)
            locker := shr(96, shl(96, current))
        }
    }

    function _requireLocker() internal view returns (uint256 id, address locker) {
        (id, locker) = _getLocker();
        if (locker != msg.sender) revert LockerOnly();
    }

    // We assume debtChange cannot exceed a 128 bits value, even though it uses a int256 container
    // This must be enforced at the places it is called for this contract's safety
    // Negative means erasing debt, positive means adding debt
    function _accountDebt(uint256 id, address token, int256 debtChange) internal {
        assembly ("memory-safe") {
            if iszero(iszero(debtChange)) {
                mstore(0, add(add(shl(160, id), token), _DEBT_HASH_OFFSET))
                let deltaSlot := keccak256(0, 32)
                let current := tload(deltaSlot)

                // we know this never overflows because debtChange is only ever derived from 128 bit values in inheriting contracts
                let next := add(current, debtChange)

                let nextZero := iszero(next)
                if xor(iszero(current), nextZero) {
                    let nzdCountSlot := add(id, _NONZERO_DEBT_COUNT_OFFSET)

                    tstore(nzdCountSlot, add(sub(tload(nzdCountSlot), nextZero), iszero(nextZero)))
                }

                tstore(deltaSlot, next)
            }
        }
    }

    // The entrypoint for all operations on the core contract
    function lock() external {
        assembly ("memory-safe") {
            let current := tload(_CURRENT_LOCKER_SLOT)

            let id := shr(160, current)

            // store the count
            tstore(_CURRENT_LOCKER_SLOT, or(shl(160, add(id, 1)), caller()))

            let free := mload(0x40)
            // Prepare call to locked(uint256) -> selector 0xb45a3c0e
            mstore(free, shl(224, 0xb45a3c0e))
            mstore(add(free, 4), id) // ID argument

            calldatacopy(add(free, 36), 4, sub(calldatasize(), 4))

            // Call the original caller with the packed data
            let success := call(gas(), caller(), 0, free, add(calldatasize(), 32), 0, 0)

            // Pass through the error on failure
            if iszero(success) {
                returndatacopy(free, 0, returndatasize())
                revert(free, returndatasize())
            }

            // Undo the "locker" state changes
            tstore(_CURRENT_LOCKER_SLOT, current)

            // Check if something is nonzero
            let nonzeroDebtCount := tload(add(_NONZERO_DEBT_COUNT_OFFSET, id))
            if nonzeroDebtCount {
                // cast sig "DebtsNotZeroed(uint256)"
                mstore(0x00, 0x9731ba37)
                mstore(0x20, id)
                revert(0x1c, 0x24)
            }

            // Directly return whatever the subcall returned
            returndatacopy(free, 0, returndatasize())
            return(free, returndatasize())
        }
    }

    // Allows forwarding the lock context to another actor, allowing them to act on the original locker's debt
    function forward(address to) external {
        (uint256 id, address locker) = _requireLocker();

        // update this lock's locker to the forwarded address for the duration of the forwarded
        // call, meaning only the forwarded address can update state
        assembly ("memory-safe") {
            tstore(_CURRENT_LOCKER_SLOT, or(shl(160, add(id, 1)), to))

            let free := mload(0x40)

            // Prepare call to forwarded(uint256,address) -> selector 0x64919dea
            mstore(free, shl(224, 0x64919dea))
            mstore(add(free, 4), id)
            mstore(add(free, 36), locker)

            calldatacopy(add(free, 68), 36, sub(calldatasize(), 36))

            // Call the forwardee with the packed data
            let success := call(gas(), to, 0, free, add(32, calldatasize()), 0, 0)

            // Pass through the error on failure
            if iszero(success) {
                returndatacopy(free, 0, returndatasize())
                revert(free, returndatasize())
            }

            tstore(_CURRENT_LOCKER_SLOT, or(shl(160, add(id, 1)), locker))

            // Directly return whatever the subcall returned
            returndatacopy(free, 0, returndatasize())
            return(free, returndatasize())
        }
    }

    function pay(address token) external returns (uint128 payment) {
        assembly ("memory-safe") {
            if tload(_PAY_REENTRANCY_LOCK) {
                // cast sig "PayReentrance()"
                mstore(0, 0xced108be)
                revert(0x1c, 0x04)
            }
            tstore(_PAY_REENTRANCY_LOCK, 1)
        }

        (uint256 id,) = _getLocker();

        assembly ("memory-safe") {
            let free := mload(0x40)

            mstore(20, address()) // Store the `account` argument.
            mstore(0, 0x70a08231000000000000000000000000) // `balanceOf(address)`.
            let tokenBalanceBefore :=
                mul( // The arguments of `mul` are evaluated from right to left.
                    mload(free),
                    and( // The arguments of `and` are evaluated from right to left.
                        gt(returndatasize(), 0x1f), // At least 32 bytes returned.
                        staticcall(gas(), token, 0x10, 0x24, free, 0x20)
                    )
                )

            // Prepare call to "payCallback(uint256,address)"
            mstore(free, shl(224, 0x599d0714))
            mstore(add(free, 4), id)
            mstore(add(free, 36), token)

            // copy the token, plus anything else that they wanted to forward
            calldatacopy(add(free, 68), 36, sub(calldatasize(), 36))

            // Call the forwardee with the packed data
            // Pass through the error on failure
            if iszero(call(gas(), caller(), 0, free, add(32, calldatasize()), 0, 0)) {
                returndatacopy(free, 0, returndatasize())
                revert(free, returndatasize())
            }

            // Arguments are still in scratch, we don't need to rewrite them
            let tokenBalanceAfter :=
                mul( // The arguments of `mul` are evaluated from right to left.
                    mload(0x20),
                    and( // The arguments of `and` are evaluated from right to left.
                        gt(returndatasize(), 0x1f), // At least 32 bytes returned.
                        staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20)
                    )
                )

            if lt(tokenBalanceAfter, tokenBalanceBefore) {
                // cast sig "NoPaymentMade()"
                mstore(0x00, 0x01b243b9)
                revert(0x1c, 4)
            }

            payment := sub(tokenBalanceAfter, tokenBalanceBefore)

            // We never expect tokens to have this much total supply
            if gt(payment, 0xffffffffffffffffffffffffffffffff) {
                // cast sig "PaymentOverflow()"
                mstore(0x00, 0x9cac58ca)
                revert(0x1c, 4)
            }
        }

        // The unary negative operator never fails because payment is less than max uint128
        unchecked {
            _accountDebt(id, token, -int256(uint256(payment)));
        }

        assembly ("memory-safe") {
            tstore(_PAY_REENTRANCY_LOCK, 0)
        }
    }

    function withdraw(address token, address recipient, uint128 amount) external {
        (uint256 id,) = _requireLocker();

        _accountDebt(id, token, int256(uint256(amount)));

        if (token == NATIVE_TOKEN_ADDRESS) {
            SafeTransferLib.safeTransferETH(recipient, amount);
        } else {
            SafeTransferLib.safeTransfer(token, recipient, amount);
        }
    }

    receive() external payable {
        (uint256 id,) = _getLocker();

        // Note because we use msg.value here, this contract can never be multicallable, i.e. it should never expose the ability
        //      to delegatecall itself more than once in a single call
        unchecked {
            // We never expect the native token to exceed this supply
            if (msg.value > type(uint128).max) revert PaymentOverflow();

            _accountDebt(id, NATIVE_TOKEN_ADDRESS, -int256(msg.value));
        }
    }
}

File 20 of 28 : EfficientHashLib.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @notice Library for efficiently performing keccak256 hashes.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/EfficientHashLib.sol)
/// @dev To avoid stack-too-deep, you can use:
/// ```
/// bytes32[] memory buffer = EfficientHashLib.malloc(10);
/// EfficientHashLib.set(buffer, 0, value0);
/// ..
/// EfficientHashLib.set(buffer, 9, value9);
/// bytes32 finalHash = EfficientHashLib.hash(buffer);
/// ```
library EfficientHashLib {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*               MALLOC-LESS HASHING OPERATIONS               */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Returns `keccak256(abi.encode(v0))`.
    function hash(bytes32 v0) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, v0)
            result := keccak256(0x00, 0x20)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0))`.
    function hash(uint256 v0) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, v0)
            result := keccak256(0x00, 0x20)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, v1))`.
    function hash(bytes32 v0, bytes32 v1) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, v0)
            mstore(0x20, v1)
            result := keccak256(0x00, 0x40)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, v1))`.
    function hash(uint256 v0, uint256 v1) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, v0)
            mstore(0x20, v1)
            result := keccak256(0x00, 0x40)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, v1, v2))`.
    function hash(bytes32 v0, bytes32 v1, bytes32 v2) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            result := keccak256(m, 0x60)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, v1, v2))`.
    function hash(uint256 v0, uint256 v1, uint256 v2) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            result := keccak256(m, 0x60)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, v1, v2, v3))`.
    function hash(bytes32 v0, bytes32 v1, bytes32 v2, bytes32 v3)
        internal
        pure
        returns (bytes32 result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            result := keccak256(m, 0x80)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, v1, v2, v3))`.
    function hash(uint256 v0, uint256 v1, uint256 v2, uint256 v3)
        internal
        pure
        returns (bytes32 result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            result := keccak256(m, 0x80)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, .., v4))`.
    function hash(bytes32 v0, bytes32 v1, bytes32 v2, bytes32 v3, bytes32 v4)
        internal
        pure
        returns (bytes32 result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            mstore(add(m, 0x80), v4)
            result := keccak256(m, 0xa0)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, .., v4))`.
    function hash(uint256 v0, uint256 v1, uint256 v2, uint256 v3, uint256 v4)
        internal
        pure
        returns (bytes32 result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            mstore(add(m, 0x80), v4)
            result := keccak256(m, 0xa0)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, .., v5))`.
    function hash(bytes32 v0, bytes32 v1, bytes32 v2, bytes32 v3, bytes32 v4, bytes32 v5)
        internal
        pure
        returns (bytes32 result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            mstore(add(m, 0x80), v4)
            mstore(add(m, 0xa0), v5)
            result := keccak256(m, 0xc0)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, .., v5))`.
    function hash(uint256 v0, uint256 v1, uint256 v2, uint256 v3, uint256 v4, uint256 v5)
        internal
        pure
        returns (bytes32 result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            mstore(add(m, 0x80), v4)
            mstore(add(m, 0xa0), v5)
            result := keccak256(m, 0xc0)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, .., v6))`.
    function hash(
        bytes32 v0,
        bytes32 v1,
        bytes32 v2,
        bytes32 v3,
        bytes32 v4,
        bytes32 v5,
        bytes32 v6
    ) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            mstore(add(m, 0x80), v4)
            mstore(add(m, 0xa0), v5)
            mstore(add(m, 0xc0), v6)
            result := keccak256(m, 0xe0)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, .., v6))`.
    function hash(
        uint256 v0,
        uint256 v1,
        uint256 v2,
        uint256 v3,
        uint256 v4,
        uint256 v5,
        uint256 v6
    ) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            mstore(add(m, 0x80), v4)
            mstore(add(m, 0xa0), v5)
            mstore(add(m, 0xc0), v6)
            result := keccak256(m, 0xe0)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, .., v7))`.
    function hash(
        bytes32 v0,
        bytes32 v1,
        bytes32 v2,
        bytes32 v3,
        bytes32 v4,
        bytes32 v5,
        bytes32 v6,
        bytes32 v7
    ) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            mstore(add(m, 0x80), v4)
            mstore(add(m, 0xa0), v5)
            mstore(add(m, 0xc0), v6)
            mstore(add(m, 0xe0), v7)
            result := keccak256(m, 0x100)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, .., v7))`.
    function hash(
        uint256 v0,
        uint256 v1,
        uint256 v2,
        uint256 v3,
        uint256 v4,
        uint256 v5,
        uint256 v6,
        uint256 v7
    ) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            mstore(add(m, 0x80), v4)
            mstore(add(m, 0xa0), v5)
            mstore(add(m, 0xc0), v6)
            mstore(add(m, 0xe0), v7)
            result := keccak256(m, 0x100)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, .., v8))`.
    function hash(
        bytes32 v0,
        bytes32 v1,
        bytes32 v2,
        bytes32 v3,
        bytes32 v4,
        bytes32 v5,
        bytes32 v6,
        bytes32 v7,
        bytes32 v8
    ) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            mstore(add(m, 0x80), v4)
            mstore(add(m, 0xa0), v5)
            mstore(add(m, 0xc0), v6)
            mstore(add(m, 0xe0), v7)
            mstore(add(m, 0x100), v8)
            result := keccak256(m, 0x120)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, .., v8))`.
    function hash(
        uint256 v0,
        uint256 v1,
        uint256 v2,
        uint256 v3,
        uint256 v4,
        uint256 v5,
        uint256 v6,
        uint256 v7,
        uint256 v8
    ) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            mstore(add(m, 0x80), v4)
            mstore(add(m, 0xa0), v5)
            mstore(add(m, 0xc0), v6)
            mstore(add(m, 0xe0), v7)
            mstore(add(m, 0x100), v8)
            result := keccak256(m, 0x120)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, .., v9))`.
    function hash(
        bytes32 v0,
        bytes32 v1,
        bytes32 v2,
        bytes32 v3,
        bytes32 v4,
        bytes32 v5,
        bytes32 v6,
        bytes32 v7,
        bytes32 v8,
        bytes32 v9
    ) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            mstore(add(m, 0x80), v4)
            mstore(add(m, 0xa0), v5)
            mstore(add(m, 0xc0), v6)
            mstore(add(m, 0xe0), v7)
            mstore(add(m, 0x100), v8)
            mstore(add(m, 0x120), v9)
            result := keccak256(m, 0x140)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, .., v9))`.
    function hash(
        uint256 v0,
        uint256 v1,
        uint256 v2,
        uint256 v3,
        uint256 v4,
        uint256 v5,
        uint256 v6,
        uint256 v7,
        uint256 v8,
        uint256 v9
    ) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            mstore(add(m, 0x80), v4)
            mstore(add(m, 0xa0), v5)
            mstore(add(m, 0xc0), v6)
            mstore(add(m, 0xe0), v7)
            mstore(add(m, 0x100), v8)
            mstore(add(m, 0x120), v9)
            result := keccak256(m, 0x140)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, .., v10))`.
    function hash(
        bytes32 v0,
        bytes32 v1,
        bytes32 v2,
        bytes32 v3,
        bytes32 v4,
        bytes32 v5,
        bytes32 v6,
        bytes32 v7,
        bytes32 v8,
        bytes32 v9,
        bytes32 v10
    ) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            mstore(add(m, 0x80), v4)
            mstore(add(m, 0xa0), v5)
            mstore(add(m, 0xc0), v6)
            mstore(add(m, 0xe0), v7)
            mstore(add(m, 0x100), v8)
            mstore(add(m, 0x120), v9)
            mstore(add(m, 0x140), v10)
            result := keccak256(m, 0x160)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, .., v10))`.
    function hash(
        uint256 v0,
        uint256 v1,
        uint256 v2,
        uint256 v3,
        uint256 v4,
        uint256 v5,
        uint256 v6,
        uint256 v7,
        uint256 v8,
        uint256 v9,
        uint256 v10
    ) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            mstore(add(m, 0x80), v4)
            mstore(add(m, 0xa0), v5)
            mstore(add(m, 0xc0), v6)
            mstore(add(m, 0xe0), v7)
            mstore(add(m, 0x100), v8)
            mstore(add(m, 0x120), v9)
            mstore(add(m, 0x140), v10)
            result := keccak256(m, 0x160)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, .., v11))`.
    function hash(
        bytes32 v0,
        bytes32 v1,
        bytes32 v2,
        bytes32 v3,
        bytes32 v4,
        bytes32 v5,
        bytes32 v6,
        bytes32 v7,
        bytes32 v8,
        bytes32 v9,
        bytes32 v10,
        bytes32 v11
    ) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            mstore(add(m, 0x80), v4)
            mstore(add(m, 0xa0), v5)
            mstore(add(m, 0xc0), v6)
            mstore(add(m, 0xe0), v7)
            mstore(add(m, 0x100), v8)
            mstore(add(m, 0x120), v9)
            mstore(add(m, 0x140), v10)
            mstore(add(m, 0x160), v11)
            result := keccak256(m, 0x180)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, .., v11))`.
    function hash(
        uint256 v0,
        uint256 v1,
        uint256 v2,
        uint256 v3,
        uint256 v4,
        uint256 v5,
        uint256 v6,
        uint256 v7,
        uint256 v8,
        uint256 v9,
        uint256 v10,
        uint256 v11
    ) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            mstore(add(m, 0x80), v4)
            mstore(add(m, 0xa0), v5)
            mstore(add(m, 0xc0), v6)
            mstore(add(m, 0xe0), v7)
            mstore(add(m, 0x100), v8)
            mstore(add(m, 0x120), v9)
            mstore(add(m, 0x140), v10)
            mstore(add(m, 0x160), v11)
            result := keccak256(m, 0x180)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, .., v12))`.
    function hash(
        bytes32 v0,
        bytes32 v1,
        bytes32 v2,
        bytes32 v3,
        bytes32 v4,
        bytes32 v5,
        bytes32 v6,
        bytes32 v7,
        bytes32 v8,
        bytes32 v9,
        bytes32 v10,
        bytes32 v11,
        bytes32 v12
    ) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            mstore(add(m, 0x80), v4)
            mstore(add(m, 0xa0), v5)
            mstore(add(m, 0xc0), v6)
            mstore(add(m, 0xe0), v7)
            mstore(add(m, 0x100), v8)
            mstore(add(m, 0x120), v9)
            mstore(add(m, 0x140), v10)
            mstore(add(m, 0x160), v11)
            mstore(add(m, 0x180), v12)
            result := keccak256(m, 0x1a0)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, .., v12))`.
    function hash(
        uint256 v0,
        uint256 v1,
        uint256 v2,
        uint256 v3,
        uint256 v4,
        uint256 v5,
        uint256 v6,
        uint256 v7,
        uint256 v8,
        uint256 v9,
        uint256 v10,
        uint256 v11,
        uint256 v12
    ) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            mstore(add(m, 0x80), v4)
            mstore(add(m, 0xa0), v5)
            mstore(add(m, 0xc0), v6)
            mstore(add(m, 0xe0), v7)
            mstore(add(m, 0x100), v8)
            mstore(add(m, 0x120), v9)
            mstore(add(m, 0x140), v10)
            mstore(add(m, 0x160), v11)
            mstore(add(m, 0x180), v12)
            result := keccak256(m, 0x1a0)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, .., v13))`.
    function hash(
        bytes32 v0,
        bytes32 v1,
        bytes32 v2,
        bytes32 v3,
        bytes32 v4,
        bytes32 v5,
        bytes32 v6,
        bytes32 v7,
        bytes32 v8,
        bytes32 v9,
        bytes32 v10,
        bytes32 v11,
        bytes32 v12,
        bytes32 v13
    ) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            mstore(add(m, 0x80), v4)
            mstore(add(m, 0xa0), v5)
            mstore(add(m, 0xc0), v6)
            mstore(add(m, 0xe0), v7)
            mstore(add(m, 0x100), v8)
            mstore(add(m, 0x120), v9)
            mstore(add(m, 0x140), v10)
            mstore(add(m, 0x160), v11)
            mstore(add(m, 0x180), v12)
            mstore(add(m, 0x1a0), v13)
            result := keccak256(m, 0x1c0)
        }
    }

    /// @dev Returns `keccak256(abi.encode(v0, .., v13))`.
    function hash(
        uint256 v0,
        uint256 v1,
        uint256 v2,
        uint256 v3,
        uint256 v4,
        uint256 v5,
        uint256 v6,
        uint256 v7,
        uint256 v8,
        uint256 v9,
        uint256 v10,
        uint256 v11,
        uint256 v12,
        uint256 v13
    ) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, v0)
            mstore(add(m, 0x20), v1)
            mstore(add(m, 0x40), v2)
            mstore(add(m, 0x60), v3)
            mstore(add(m, 0x80), v4)
            mstore(add(m, 0xa0), v5)
            mstore(add(m, 0xc0), v6)
            mstore(add(m, 0xe0), v7)
            mstore(add(m, 0x100), v8)
            mstore(add(m, 0x120), v9)
            mstore(add(m, 0x140), v10)
            mstore(add(m, 0x160), v11)
            mstore(add(m, 0x180), v12)
            mstore(add(m, 0x1a0), v13)
            result := keccak256(m, 0x1c0)
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*             BYTES32 BUFFER HASHING OPERATIONS              */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Returns `keccak256(abi.encode(buffer[0], .., buffer[buffer.length - 1]))`.
    function hash(bytes32[] memory buffer) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            result := keccak256(add(buffer, 0x20), shl(5, mload(buffer)))
        }
    }

    /// @dev Sets `buffer[i]` to `value`, without a bounds check.
    /// Returns the `buffer` for function chaining.
    function set(bytes32[] memory buffer, uint256 i, bytes32 value)
        internal
        pure
        returns (bytes32[] memory)
    {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(add(buffer, shl(5, add(1, i))), value)
        }
        return buffer;
    }

    /// @dev Sets `buffer[i]` to `value`, without a bounds check.
    /// Returns the `buffer` for function chaining.
    function set(bytes32[] memory buffer, uint256 i, uint256 value)
        internal
        pure
        returns (bytes32[] memory)
    {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(add(buffer, shl(5, add(1, i))), value)
        }
        return buffer;
    }

    /// @dev Returns `new bytes32[](n)`, without zeroing out the memory.
    function malloc(uint256 n) internal pure returns (bytes32[] memory buffer) {
        /// @solidity memory-safe-assembly
        assembly {
            buffer := mload(0x40)
            mstore(buffer, n)
            mstore(0x40, add(shl(5, add(1, n)), buffer))
        }
    }

    /// @dev Frees memory that has been allocated for `buffer`.
    /// No-op if `buffer.length` is zero, or if new memory has been allocated after `buffer`.
    function free(bytes32[] memory buffer) internal pure {
        /// @solidity memory-safe-assembly
        assembly {
            let n := mload(buffer)
            mstore(shl(6, lt(iszero(n), eq(add(shl(5, add(1, n)), buffer), mload(0x40)))), buffer)
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                      EQUALITY CHECKS                       */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Returns `a == abi.decode(b, (bytes32))`.
    function eq(bytes32 a, bytes memory b) internal pure returns (bool result) {
        /// @solidity memory-safe-assembly
        assembly {
            result := and(eq(0x20, mload(b)), eq(a, mload(add(b, 0x20))))
        }
    }

    /// @dev Returns `abi.decode(a, (bytes32)) == a`.
    function eq(bytes memory a, bytes32 b) internal pure returns (bool result) {
        /// @solidity memory-safe-assembly
        assembly {
            result := and(eq(0x20, mload(a)), eq(b, mload(add(a, 0x20))))
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*               BYTE SLICE HASHING OPERATIONS                */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Returns the keccak256 of the slice from `start` to `end` (exclusive).
    /// `start` and `end` are byte offsets.
    function hash(bytes memory b, uint256 start, uint256 end)
        internal
        pure
        returns (bytes32 result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let n := mload(b)
            end := xor(end, mul(xor(end, n), lt(n, end)))
            start := xor(start, mul(xor(start, n), lt(n, start)))
            result := keccak256(add(add(b, 0x20), start), mul(gt(end, start), sub(end, start)))
        }
    }

    /// @dev Returns the keccak256 of the slice from `start` to the end of the bytes.
    function hash(bytes memory b, uint256 start) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            let n := mload(b)
            start := xor(start, mul(xor(start, n), lt(n, start)))
            result := keccak256(add(add(b, 0x20), start), mul(gt(n, start), sub(n, start)))
        }
    }

    /// @dev Returns the keccak256 of the bytes.
    function hash(bytes memory b) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            result := keccak256(add(b, 0x20), mload(b))
        }
    }

    /// @dev Returns the keccak256 of the slice from `start` to `end` (exclusive).
    /// `start` and `end` are byte offsets.
    function hashCalldata(bytes calldata b, uint256 start, uint256 end)
        internal
        pure
        returns (bytes32 result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            end := xor(end, mul(xor(end, b.length), lt(b.length, end)))
            start := xor(start, mul(xor(start, b.length), lt(b.length, start)))
            let n := mul(gt(end, start), sub(end, start))
            calldatacopy(mload(0x40), add(b.offset, start), n)
            result := keccak256(mload(0x40), n)
        }
    }

    /// @dev Returns the keccak256 of the slice from `start` to the end of the bytes.
    function hashCalldata(bytes calldata b, uint256 start) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            start := xor(start, mul(xor(start, b.length), lt(b.length, start)))
            let n := mul(gt(b.length, start), sub(b.length, start))
            calldatacopy(mload(0x40), add(b.offset, start), n)
            result := keccak256(mload(0x40), n)
        }
    }

    /// @dev Returns the keccak256 of the bytes.
    function hashCalldata(bytes calldata b) internal pure returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            calldatacopy(mload(0x40), b.offset, b.length)
            result := keccak256(mload(0x40), b.length)
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                      SHA2-256 HELPERS                      */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Returns `sha256(abi.encode(b))`. Yes, it's more efficient.
    function sha2(bytes32 b) internal view returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, b)
            result := mload(staticcall(gas(), 2, 0x00, 0x20, 0x01, 0x20))
            if iszero(returndatasize()) { invalid() }
        }
    }

    /// @dev Returns the sha256 of the slice from `start` to `end` (exclusive).
    /// `start` and `end` are byte offsets.
    function sha2(bytes memory b, uint256 start, uint256 end)
        internal
        view
        returns (bytes32 result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let n := mload(b)
            end := xor(end, mul(xor(end, n), lt(n, end)))
            start := xor(start, mul(xor(start, n), lt(n, start)))
            // forgefmt: disable-next-item
            result := mload(staticcall(gas(), 2, add(add(b, 0x20), start),
                mul(gt(end, start), sub(end, start)), 0x01, 0x20))
            if iszero(returndatasize()) { invalid() }
        }
    }

    /// @dev Returns the sha256 of the slice from `start` to the end of the bytes.
    function sha2(bytes memory b, uint256 start) internal view returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            let n := mload(b)
            start := xor(start, mul(xor(start, n), lt(n, start)))
            // forgefmt: disable-next-item
            result := mload(staticcall(gas(), 2, add(add(b, 0x20), start),
                mul(gt(n, start), sub(n, start)), 0x01, 0x20))
            if iszero(returndatasize()) { invalid() }
        }
    }

    /// @dev Returns the sha256 of the bytes.
    function sha2(bytes memory b) internal view returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            result := mload(staticcall(gas(), 2, add(b, 0x20), mload(b), 0x01, 0x20))
            if iszero(returndatasize()) { invalid() }
        }
    }

    /// @dev Returns the sha256 of the slice from `start` to `end` (exclusive).
    /// `start` and `end` are byte offsets.
    function sha2Calldata(bytes calldata b, uint256 start, uint256 end)
        internal
        view
        returns (bytes32 result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            end := xor(end, mul(xor(end, b.length), lt(b.length, end)))
            start := xor(start, mul(xor(start, b.length), lt(b.length, start)))
            let n := mul(gt(end, start), sub(end, start))
            calldatacopy(mload(0x40), add(b.offset, start), n)
            result := mload(staticcall(gas(), 2, mload(0x40), n, 0x01, 0x20))
            if iszero(returndatasize()) { invalid() }
        }
    }

    /// @dev Returns the sha256 of the slice from `start` to the end of the bytes.
    function sha2Calldata(bytes calldata b, uint256 start) internal view returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            start := xor(start, mul(xor(start, b.length), lt(b.length, start)))
            let n := mul(gt(b.length, start), sub(b.length, start))
            calldatacopy(mload(0x40), add(b.offset, start), n)
            result := mload(staticcall(gas(), 2, mload(0x40), n, 0x01, 0x20))
            if iszero(returndatasize()) { invalid() }
        }
    }

    /// @dev Returns the sha256 of the bytes.
    function sha2Calldata(bytes calldata b) internal view returns (bytes32 result) {
        /// @solidity memory-safe-assembly
        assembly {
            calldatacopy(mload(0x40), b.offset, b.length)
            result := mload(staticcall(gas(), 2, mload(0x40), b.length, 0x01, 0x20))
            if iszero(returndatasize()) { invalid() }
        }
    }
}

File 21 of 28 : constants.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

int32 constant MIN_TICK = -88722835;
int32 constant MAX_TICK = 88722835;
uint32 constant MAX_TICK_MAGNITUDE = uint32(MAX_TICK);
uint32 constant MAX_TICK_SPACING = 698605;

uint32 constant FULL_RANGE_ONLY_TICK_SPACING = 0;

// We use this address to represent the native token within the protocol
address constant NATIVE_TOKEN_ADDRESS = address(0);

File 22 of 28 : sqrtRatio.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

// A dynamic fixed point number (a la floating point) that stores a shifting 94 bit view of the underlying fixed point value,
//  based on the most significant bits (mantissa)
// If the most significant 2 bits are 11, it represents a 64.30
// If the most significant 2 bits are 10, it represents a 32.62 number
// If the most significant 2 bits are 01, it represents a 0.94 number
// If the most significant 2 bits are 00, it represents a 0.126 number that is always less than 2**-32

type SqrtRatio is uint96;

uint96 constant MIN_SQRT_RATIO_RAW = 4611797791050542631;
SqrtRatio constant MIN_SQRT_RATIO = SqrtRatio.wrap(MIN_SQRT_RATIO_RAW);
uint96 constant MAX_SQRT_RATIO_RAW = 79227682466138141934206691491;
SqrtRatio constant MAX_SQRT_RATIO = SqrtRatio.wrap(MAX_SQRT_RATIO_RAW);

uint96 constant TWO_POW_95 = 0x800000000000000000000000;
uint96 constant TWO_POW_94 = 0x400000000000000000000000;
uint96 constant TWO_POW_62 = 0x4000000000000000;
uint96 constant TWO_POW_62_MINUS_ONE = 0x3fffffffffffffff;
uint96 constant BIT_MASK = 0xc00000000000000000000000; // TWO_POW_95 | TWO_POW_94

SqrtRatio constant ONE = SqrtRatio.wrap((TWO_POW_95) + (1 << 62));

using {
    toFixed,
    isValid,
    ge as >=,
    le as <=,
    lt as <,
    gt as >,
    eq as ==,
    neq as !=,
    isZero,
    min,
    max
} for SqrtRatio global;

function isValid(SqrtRatio sqrtRatio) pure returns (bool r) {
    assembly ("memory-safe") {
        r :=
            and(
                // greater than or equal to TWO_POW_62, i.e. the whole number portion is nonzero
                gt(and(sqrtRatio, not(BIT_MASK)), TWO_POW_62_MINUS_ONE),
                // and between min/max sqrt ratio
                and(iszero(lt(sqrtRatio, MIN_SQRT_RATIO_RAW)), iszero(gt(sqrtRatio, MAX_SQRT_RATIO_RAW)))
            )
    }
}

error ValueOverflowsSqrtRatioContainer();

// If passing a value greater than this constant with roundUp = true, toSqrtRatio will overflow
// For roundUp = false, the constant is type(uint192).max
uint256 constant MAX_FIXED_VALUE_ROUND_UP =
    0x1000000000000000000000000000000000000000000000000 - 0x4000000000000000000000000;

// Converts a 64.128 value into the compact SqrtRatio representation
function toSqrtRatio(uint256 sqrtRatio, bool roundUp) pure returns (SqrtRatio r) {
    assembly ("memory-safe") {
        let addend := mul(roundUp, 0x3)

        // lt 2**96 after rounding up
        switch lt(sqrtRatio, sub(0x1000000000000000000000000, addend))
        case 1 { r := shr(2, add(sqrtRatio, addend)) }
        default {
            // 2**34 - 1
            addend := mul(roundUp, 0x3ffffffff)
            // lt 2**128 after rounding up
            switch lt(sqrtRatio, sub(0x100000000000000000000000000000000, addend))
            case 1 { r := or(TWO_POW_94, shr(34, add(sqrtRatio, addend))) }
            default {
                addend := mul(roundUp, 0x3ffffffffffffffff)
                // lt 2**160 after rounding up
                switch lt(sqrtRatio, sub(0x10000000000000000000000000000000000000000, addend))
                case 1 { r := or(TWO_POW_95, shr(66, add(sqrtRatio, addend))) }
                default {
                    // 2**98 - 1
                    addend := mul(roundUp, 0x3ffffffffffffffffffffffff)
                    switch lt(sqrtRatio, sub(0x1000000000000000000000000000000000000000000000000, addend))
                    case 1 { r := or(BIT_MASK, shr(98, add(sqrtRatio, addend))) }
                    default {
                        // cast sig "ValueOverflowsSqrtRatioContainer()"
                        mstore(0, shl(224, 0xa10459f4))
                        revert(0, 4)
                    }
                }
            }
        }
    }
}

// Returns the 64.128 representation of the given sqrt ratio
function toFixed(SqrtRatio sqrtRatio) pure returns (uint256 r) {
    assembly ("memory-safe") {
        r := shl(add(2, shr(89, and(sqrtRatio, BIT_MASK))), and(sqrtRatio, not(BIT_MASK)))
    }
}

// The below operators assume that the SqrtRatio is valid, i.e. SqrtRatio#isValid returns true

function lt(SqrtRatio a, SqrtRatio b) pure returns (bool r) {
    r = SqrtRatio.unwrap(a) < SqrtRatio.unwrap(b);
}

function gt(SqrtRatio a, SqrtRatio b) pure returns (bool r) {
    r = SqrtRatio.unwrap(a) > SqrtRatio.unwrap(b);
}

function le(SqrtRatio a, SqrtRatio b) pure returns (bool r) {
    r = SqrtRatio.unwrap(a) <= SqrtRatio.unwrap(b);
}

function ge(SqrtRatio a, SqrtRatio b) pure returns (bool r) {
    r = SqrtRatio.unwrap(a) >= SqrtRatio.unwrap(b);
}

function eq(SqrtRatio a, SqrtRatio b) pure returns (bool r) {
    r = SqrtRatio.unwrap(a) == SqrtRatio.unwrap(b);
}

function neq(SqrtRatio a, SqrtRatio b) pure returns (bool r) {
    r = SqrtRatio.unwrap(a) != SqrtRatio.unwrap(b);
}

function isZero(SqrtRatio a) pure returns (bool r) {
    assembly ("memory-safe") {
        r := iszero(a)
    }
}

function max(SqrtRatio a, SqrtRatio b) pure returns (SqrtRatio r) {
    assembly ("memory-safe") {
        r := xor(a, mul(xor(a, b), gt(b, a)))
    }
}

function min(SqrtRatio a, SqrtRatio b) pure returns (SqrtRatio r) {
    assembly ("memory-safe") {
        r := xor(a, mul(xor(a, b), lt(b, a)))
    }
}

File 23 of 28 : sqrtRatio.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol";
import {SqrtRatio, toSqrtRatio, MAX_FIXED_VALUE_ROUND_UP} from "../types/sqrtRatio.sol";

error ZeroLiquidityNextSqrtRatioFromAmount0();

// Compute the next ratio from a delta amount0, always rounded towards starting price for input, and
// away from starting price for output
function nextSqrtRatioFromAmount0(SqrtRatio _sqrtRatio, uint128 liquidity, int128 amount)
    pure
    returns (SqrtRatio sqrtRatioNext)
{
    if (amount == 0) {
        return _sqrtRatio;
    }

    if (liquidity == 0) {
        revert ZeroLiquidityNextSqrtRatioFromAmount0();
    }

    uint256 sqrtRatio = _sqrtRatio.toFixed();

    uint256 liquidityX128 = uint256(liquidity) << 128;
    uint256 amountAbs = FixedPointMathLib.abs(int256(amount));

    if (amount < 0) {
        unchecked {
            // multiplication will revert on overflow, so we return the maximum value for the type
            if (amountAbs > type(uint256).max / sqrtRatio) {
                return SqrtRatio.wrap(type(uint96).max);
            }

            uint256 product = sqrtRatio * amountAbs;

            // again it will overflow if this is the case, so return the max value
            if (product >= liquidityX128) {
                return SqrtRatio.wrap(type(uint96).max);
            }

            uint256 denominator = liquidityX128 - product;

            uint256 resultFixed = FixedPointMathLib.fullMulDivUp(liquidityX128, sqrtRatio, denominator);

            if (resultFixed > MAX_FIXED_VALUE_ROUND_UP) {
                return SqrtRatio.wrap(type(uint96).max);
            }

            sqrtRatioNext = toSqrtRatio(resultFixed, true);
        }
    } else {
        uint256 denominator;
        unchecked {
            uint256 denominatorP1 = liquidityX128 / sqrtRatio;

            // this can never overflow, amountAbs is limited to 2**128-1 and liquidityX128 / sqrtRatio is limited to (2**128-1 << 128)
            // adding the 2 values can at most equal type(uint256).max
            denominator = denominatorP1 + amountAbs;
        }

        sqrtRatioNext = toSqrtRatio(FixedPointMathLib.divUp(liquidityX128, denominator), true);
    }
}

error ZeroLiquidityNextSqrtRatioFromAmount1();

function nextSqrtRatioFromAmount1(SqrtRatio _sqrtRatio, uint128 liquidity, int128 amount)
    pure
    returns (SqrtRatio sqrtRatioNext)
{
    if (amount == 0) {
        return _sqrtRatio;
    }

    if (liquidity == 0) {
        revert ZeroLiquidityNextSqrtRatioFromAmount1();
    }

    uint256 sqrtRatio = _sqrtRatio.toFixed();

    unchecked {
        uint256 shiftedAmountAbs = FixedPointMathLib.abs(int256(amount)) << 128;

        uint256 quotient = shiftedAmountAbs / liquidity;

        if (amount < 0) {
            if (quotient >= sqrtRatio) {
                // Underflow => return 0
                return SqrtRatio.wrap(0);
            }

            uint256 sqrtRatioNextFixed = sqrtRatio - quotient;

            assembly ("memory-safe") {
                // subtraction of 1 is safe because sqrtRatio > quotient => sqrtRatio - quotient >= 1
                sqrtRatioNextFixed := sub(sqrtRatioNextFixed, iszero(iszero(mod(shiftedAmountAbs, liquidity))))
            }

            sqrtRatioNext = toSqrtRatio(sqrtRatioNextFixed, false);
        } else {
            uint256 sum = sqrtRatio + quotient;
            if (sum < sqrtRatio || sum > type(uint192).max) {
                return SqrtRatio.wrap(type(uint96).max);
            }
            sqrtRatioNext = toSqrtRatio(sum, false);
        }
    }
}

File 24 of 28 : delta.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol";
import {SqrtRatio} from "../types/sqrtRatio.sol";

error Amount0DeltaOverflow();
error Amount1DeltaOverflow();

function sortAndConvertToFixedSqrtRatios(SqrtRatio sqrtRatioA, SqrtRatio sqrtRatioB)
    pure
    returns (uint256 sqrtRatioLower, uint256 sqrtRatioUpper)
{
    uint256 aFixed = sqrtRatioA.toFixed();
    uint256 bFixed = sqrtRatioB.toFixed();
    (sqrtRatioLower, sqrtRatioUpper) = (FixedPointMathLib.min(aFixed, bFixed), FixedPointMathLib.max(aFixed, bFixed));
}

function amount0Delta(SqrtRatio sqrtRatioA, SqrtRatio sqrtRatioB, uint128 liquidity, bool roundUp)
    pure
    returns (uint128 amount0)
{
    unchecked {
        (uint256 sqrtRatioLower, uint256 sqrtRatioUpper) = sortAndConvertToFixedSqrtRatios(sqrtRatioA, sqrtRatioB);

        if (roundUp) {
            uint256 result0 = FixedPointMathLib.fullMulDivUp(
                (uint256(liquidity) << 128), (sqrtRatioUpper - sqrtRatioLower), sqrtRatioUpper
            );
            uint256 result = FixedPointMathLib.divUp(result0, sqrtRatioLower);
            if (result > type(uint128).max) revert Amount0DeltaOverflow();
            amount0 = uint128(result);
        } else {
            uint256 result0 = FixedPointMathLib.fullMulDiv(
                (uint256(liquidity) << 128), (sqrtRatioUpper - sqrtRatioLower), sqrtRatioUpper
            );
            uint256 result = result0 / sqrtRatioLower;
            if (result > type(uint128).max) revert Amount0DeltaOverflow();
            amount0 = uint128(result);
        }
    }
}

function amount1Delta(SqrtRatio sqrtRatioA, SqrtRatio sqrtRatioB, uint128 liquidity, bool roundUp)
    pure
    returns (uint128 amount1)
{
    unchecked {
        (uint256 sqrtRatioLower, uint256 sqrtRatioUpper) = sortAndConvertToFixedSqrtRatios(sqrtRatioA, sqrtRatioB);

        uint256 difference = sqrtRatioUpper - sqrtRatioLower;

        if (roundUp) {
            uint256 result = FixedPointMathLib.fullMulDivN(difference, liquidity, 128);
            assembly {
                // addition is safe from overflow because the result of fullMulDivN will never equal type(uint256).max
                result :=
                    add(result, iszero(iszero(mulmod(difference, liquidity, 0x100000000000000000000000000000000))))
            }
            if (result > type(uint128).max) revert Amount1DeltaOverflow();
            amount1 = uint128(result);
        } else {
            uint256 result = FixedPointMathLib.fullMulDivN(difference, liquidity, 128);
            if (result > type(uint128).max) revert Amount1DeltaOverflow();
            amount1 = uint128(result);
        }
    }
}

File 25 of 28 : isPriceIncreasing.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

function isPriceIncreasing(int128 amount, bool isToken1) pure returns (bool increasing) {
    assembly ("memory-safe") {
        increasing := xor(isToken1, slt(amount, 0))
    }
}

File 26 of 28 : LibBit.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @notice Library for bit twiddling and boolean operations.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/LibBit.sol)
/// @author Inspired by (https://graphics.stanford.edu/~seander/bithacks.html)
library LibBit {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                  BIT TWIDDLING OPERATIONS                  */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Find last set.
    /// Returns the index of the most significant bit of `x`,
    /// counting from the least significant bit position.
    /// If `x` is zero, returns 256.
    function fls(uint256 x) internal pure returns (uint256 r) {
        /// @solidity memory-safe-assembly
        assembly {
            r := or(shl(8, iszero(x)), shl(7, lt(0xffffffffffffffffffffffffffffffff, x)))
            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
            r := or(r, shl(4, lt(0xffff, shr(r, x))))
            r := or(r, shl(3, lt(0xff, shr(r, x))))
            // forgefmt: disable-next-item
            r := or(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),
                0x0706060506020504060203020504030106050205030304010505030400000000))
        }
    }

    /// @dev Count leading zeros.
    /// Returns the number of zeros preceding the most significant one bit.
    /// If `x` is zero, returns 256.
    function clz(uint256 x) internal pure returns (uint256 r) {
        /// @solidity memory-safe-assembly
        assembly {
            r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
            r := or(r, shl(4, lt(0xffff, shr(r, x))))
            r := or(r, shl(3, lt(0xff, shr(r, x))))
            // forgefmt: disable-next-item
            r := add(xor(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),
                0xf8f9f9faf9fdfafbf9fdfcfdfafbfcfef9fafdfafcfcfbfefafafcfbffffffff)), iszero(x))
        }
    }

    /// @dev Find first set.
    /// Returns the index of the least significant bit of `x`,
    /// counting from the least significant bit position.
    /// If `x` is zero, returns 256.
    /// Equivalent to `ctz` (count trailing zeros), which gives
    /// the number of zeros following the least significant one bit.
    function ffs(uint256 x) internal pure returns (uint256 r) {
        /// @solidity memory-safe-assembly
        assembly {
            // Isolate the least significant bit.
            x := and(x, add(not(x), 1))
            // For the upper 3 bits of the result, use a De Bruijn-like lookup.
            // Credit to adhusson: https://blog.adhusson.com/cheap-find-first-set-evm/
            // forgefmt: disable-next-item
            r := shl(5, shr(252, shl(shl(2, shr(250, mul(x,
                0xb6db6db6ddddddddd34d34d349249249210842108c6318c639ce739cffffffff))),
                0x8040405543005266443200005020610674053026020000107506200176117077)))
            // For the lower 5 bits of the result, use a De Bruijn lookup.
            // forgefmt: disable-next-item
            r := or(r, byte(and(div(0xd76453e0, shr(r, x)), 0x1f),
                0x001f0d1e100c1d070f090b19131c1706010e11080a1a141802121b1503160405))
        }
    }

    /// @dev Returns the number of set bits in `x`.
    function popCount(uint256 x) internal pure returns (uint256 c) {
        /// @solidity memory-safe-assembly
        assembly {
            let max := not(0)
            let isMax := eq(x, max)
            x := sub(x, and(shr(1, x), div(max, 3)))
            x := add(and(x, div(max, 5)), and(shr(2, x), div(max, 5)))
            x := and(add(x, shr(4, x)), div(max, 17))
            c := or(shl(8, isMax), shr(248, mul(x, div(max, 255))))
        }
    }

    /// @dev Returns whether `x` is a power of 2.
    function isPo2(uint256 x) internal pure returns (bool result) {
        /// @solidity memory-safe-assembly
        assembly {
            // Equivalent to `x && !(x & (x - 1))`.
            result := iszero(add(and(x, sub(x, 1)), iszero(x)))
        }
    }

    /// @dev Returns `x` reversed at the bit level.
    function reverseBits(uint256 x) internal pure returns (uint256 r) {
        uint256 m0 = 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f;
        uint256 m1 = m0 ^ (m0 << 2);
        uint256 m2 = m1 ^ (m1 << 1);
        r = reverseBytes(x);
        r = (m2 & (r >> 1)) | ((m2 & r) << 1);
        r = (m1 & (r >> 2)) | ((m1 & r) << 2);
        r = (m0 & (r >> 4)) | ((m0 & r) << 4);
    }

    /// @dev Returns `x` reversed at the byte level.
    function reverseBytes(uint256 x) internal pure returns (uint256 r) {
        unchecked {
            // Computing masks on-the-fly reduces bytecode size by about 200 bytes.
            uint256 m0 = 0x100000000000000000000000000000001 * (~toUint(x == uint256(0)) >> 192);
            uint256 m1 = m0 ^ (m0 << 32);
            uint256 m2 = m1 ^ (m1 << 16);
            uint256 m3 = m2 ^ (m2 << 8);
            r = (m3 & (x >> 8)) | ((m3 & x) << 8);
            r = (m2 & (r >> 16)) | ((m2 & r) << 16);
            r = (m1 & (r >> 32)) | ((m1 & r) << 32);
            r = (m0 & (r >> 64)) | ((m0 & r) << 64);
            r = (r >> 128) | (r << 128);
        }
    }

    /// @dev Returns the common prefix of `x` and `y` at the bit level.
    function commonBitPrefix(uint256 x, uint256 y) internal pure returns (uint256) {
        unchecked {
            uint256 s = 256 - clz(x ^ y);
            return (x >> s) << s;
        }
    }

    /// @dev Returns the common prefix of `x` and `y` at the nibble level.
    function commonNibblePrefix(uint256 x, uint256 y) internal pure returns (uint256) {
        unchecked {
            uint256 s = (64 - (clz(x ^ y) >> 2)) << 2;
            return (x >> s) << s;
        }
    }

    /// @dev Returns the common prefix of `x` and `y` at the byte level.
    function commonBytePrefix(uint256 x, uint256 y) internal pure returns (uint256) {
        unchecked {
            uint256 s = (32 - (clz(x ^ y) >> 3)) << 3;
            return (x >> s) << s;
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                     BOOLEAN OPERATIONS                     */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    // A Solidity bool on the stack or memory is represented as a 256-bit word.
    // Non-zero values are true, zero is false.
    // A clean bool is either 0 (false) or 1 (true) under the hood.
    // Usually, if not always, the bool result of a regular Solidity expression,
    // or the argument of a public/external function will be a clean bool.
    // You can usually use the raw variants for more performance.
    // If uncertain, test (best with exact compiler settings).
    // Or use the non-raw variants (compiler can sometimes optimize out the double `iszero`s).

    /// @dev Returns `x & y`. Inputs must be clean.
    function rawAnd(bool x, bool y) internal pure returns (bool z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := and(x, y)
        }
    }

    /// @dev Returns `x & y`.
    function and(bool x, bool y) internal pure returns (bool z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := and(iszero(iszero(x)), iszero(iszero(y)))
        }
    }

    /// @dev Returns `x | y`. Inputs must be clean.
    function rawOr(bool x, bool y) internal pure returns (bool z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := or(x, y)
        }
    }

    /// @dev Returns `x | y`.
    function or(bool x, bool y) internal pure returns (bool z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := or(iszero(iszero(x)), iszero(iszero(y)))
        }
    }

    /// @dev Returns 1 if `b` is true, else 0. Input must be clean.
    function rawToUint(bool b) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := b
        }
    }

    /// @dev Returns 1 if `b` is true, else 0.
    function toUint(bool b) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := iszero(iszero(b))
        }
    }
}

File 27 of 28 : IExposedStorage.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

// Exposes all the storage of a contract via view methods.
// Absent https://eips.ethereum.org/EIPS/eip-2330 this makes it easier to access specific pieces of state in the inheriting contract.
interface IExposedStorage {
    // Loads each slot after the function selector from the contract's storage and returns all of them.
    function sload() external view;
    // Loads each slot after the function selector from the contract's transient storage and returns all of them.
    function tload() external view;
}

File 28 of 28 : IFlashAccountant.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.28;

interface ILocker {
    function locked(uint256 id) external;
}

interface IForwardee {
    function forwarded(uint256 id, address originalLocker) external;
}

interface IPayer {
    function payCallback(uint256 id, address token) external;
}

interface IFlashAccountant {
    error NotLocked();
    error LockerOnly();
    error NoPaymentMade();
    error DebtsNotZeroed(uint256 id);
    // Thrown if the contract receives too much payment in the payment callback or from a direct native token transfer
    error PaymentOverflow();
    error PayReentrance();

    // Create a lock context
    // Any data passed after the function signature is passed through back to the caller after the locked function signature and data, with no additional encoding
    // In addition, any data returned from ILocker#locked is also returned from this function exactly as is, i.e. with no additional encoding or decoding
    // Reverts are also bubbled up
    function lock() external;

    // Forward the lock from the current locker to the given address
    // Any additional calldata is also passed through to the forwardee, with no additional encoding
    // In addition, any data returned from IForwardee#forwarded is also returned from this function exactly as is, i.e. with no additional encoding or decoding
    // Reverts are also bubbled up
    function forward(address to) external;

    // Pays the given amount of token, by calling the payCallback function on the caller to afford them the opportunity to make the payment.
    // This function, unlike lock and forward, does not return any of the returndata from the callback.
    // This function also cannot be re-entered like lock and forward.
    // Must be locked, as the contract accounts the payment against the current locker's debts.
    // Token must not be the NATIVE_TOKEN_ADDRESS, as the `balanceOf` calls will fail.
    // If you want to pay in the chain's native token, simply transfer it to this contract using a call.
    // The payer must implement payCallback in which they must transfer the token to Core.
    function pay(address token) external returns (uint128 payment);

    // Withdraws a token amount from the accountant to the given recipient.
    // The contract must be locked, as it tracks the withdrawn amount against the current locker's delta.
    function withdraw(address token, address recipient, uint128 amount) external;

    // This contract can receive ETH as a payment as well
    receive() external payable;
}

Settings
{
  "remappings": [
    "forge-std/=lib/forge-std/src/",
    "solady/=lib/solady/src/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 9999999
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "cancun",
  "viaIR": true,
  "libraries": {}
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyInitialized","type":"error"},{"inputs":[],"name":"Amount0DeltaOverflow","type":"error"},{"inputs":[],"name":"Amount1DeltaOverflow","type":"error"},{"inputs":[],"name":"AmountBeforeFeeOverflow","type":"error"},{"inputs":[],"name":"BoundsOrder","type":"error"},{"inputs":[],"name":"BoundsTickSpacing","type":"error"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"DebtsNotZeroed","type":"error"},{"inputs":[],"name":"ExtensionAlreadyRegistered","type":"error"},{"inputs":[],"name":"ExtensionNotRegistered","type":"error"},{"inputs":[],"name":"FailedRegisterInvalidCallPoints","type":"error"},{"inputs":[],"name":"FullRangeOnlyPool","type":"error"},{"inputs":[],"name":"InsufficientSavedBalance","type":"error"},{"inputs":[],"name":"InvalidSqrtRatioLimit","type":"error"},{"inputs":[{"internalType":"int32","name":"tick","type":"int32"}],"name":"InvalidTick","type":"error"},{"inputs":[],"name":"InvalidTickSpacing","type":"error"},{"inputs":[],"name":"LockerOnly","type":"error"},{"inputs":[],"name":"MinMaxBounds","type":"error"},{"inputs":[],"name":"MustCollectFeesBeforeWithdrawingAllLiquidity","type":"error"},{"inputs":[],"name":"NewOwnerIsZeroAddress","type":"error"},{"inputs":[],"name":"NoHandoverRequest","type":"error"},{"inputs":[],"name":"NoPaymentMade","type":"error"},{"inputs":[],"name":"NotLocked","type":"error"},{"inputs":[],"name":"PayReentrance","type":"error"},{"inputs":[],"name":"PaymentOverflow","type":"error"},{"inputs":[],"name":"PoolAlreadyInitialized","type":"error"},{"inputs":[],"name":"PoolNotInitialized","type":"error"},{"inputs":[],"name":"SavedBalanceTokensNotSorted","type":"error"},{"inputs":[],"name":"SqrtRatioLimitOutOfRange","type":"error"},{"inputs":[],"name":"SqrtRatioLimitWrongDirection","type":"error"},{"inputs":[],"name":"TokensMustBeSorted","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"inputs":[],"name":"ZeroLiquidityNextSqrtRatioFromAmount0","type":"error"},{"inputs":[],"name":"ZeroLiquidityNextSqrtRatioFromAmount1","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"extension","type":"address"}],"name":"ExtensionRegistered","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"poolId","type":"bytes32"},{"indexed":false,"internalType":"uint128","name":"amount0","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"amount1","type":"uint128"}],"name":"FeesAccumulated","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":"bytes32","name":"poolId","type":"bytes32"},{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"Config","name":"config","type":"bytes32"}],"indexed":false,"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"indexed":false,"internalType":"int32","name":"tick","type":"int32"},{"indexed":false,"internalType":"SqrtRatio","name":"sqrtRatio","type":"uint96"}],"name":"PoolInitialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"poolId","type":"bytes32"},{"components":[{"internalType":"bytes32","name":"salt","type":"bytes32"},{"internalType":"address","name":"owner","type":"address"},{"components":[{"internalType":"int32","name":"lower","type":"int32"},{"internalType":"int32","name":"upper","type":"int32"}],"internalType":"struct Bounds","name":"bounds","type":"tuple"}],"indexed":false,"internalType":"struct PositionKey","name":"positionKey","type":"tuple"},{"indexed":false,"internalType":"uint128","name":"amount0","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"amount1","type":"uint128"}],"name":"PositionFeesCollected","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"locker","type":"address"},{"indexed":false,"internalType":"bytes32","name":"poolId","type":"bytes32"},{"components":[{"internalType":"bytes32","name":"salt","type":"bytes32"},{"components":[{"internalType":"int32","name":"lower","type":"int32"},{"internalType":"int32","name":"upper","type":"int32"}],"internalType":"struct Bounds","name":"bounds","type":"tuple"},{"internalType":"int128","name":"liquidityDelta","type":"int128"}],"indexed":false,"internalType":"struct UpdatePositionParameters","name":"params","type":"tuple"},{"indexed":false,"internalType":"int128","name":"delta0","type":"int128"},{"indexed":false,"internalType":"int128","name":"delta1","type":"int128"}],"name":"PositionUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ProtocolFeesWithdrawn","type":"event"},{"inputs":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"Config","name":"config","type":"bytes32"}],"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"internalType":"uint128","name":"amount0","type":"uint128"},{"internalType":"uint128","name":"amount1","type":"uint128"}],"name":"accumulateAsFees","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"cancelOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"Config","name":"config","type":"bytes32"}],"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"internalType":"bytes32","name":"salt","type":"bytes32"},{"components":[{"internalType":"int32","name":"lower","type":"int32"},{"internalType":"int32","name":"upper","type":"int32"}],"internalType":"struct Bounds","name":"bounds","type":"tuple"}],"name":"collectFees","outputs":[{"internalType":"uint128","name":"amount0","type":"uint128"},{"internalType":"uint128","name":"amount1","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"completeOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"forward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"Config","name":"config","type":"bytes32"}],"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"components":[{"internalType":"int32","name":"lower","type":"int32"},{"internalType":"int32","name":"upper","type":"int32"}],"internalType":"struct Bounds","name":"bounds","type":"tuple"}],"name":"getPoolFeesPerLiquidityInside","outputs":[{"components":[{"internalType":"uint256","name":"value0","type":"uint256"},{"internalType":"uint256","name":"value1","type":"uint256"}],"internalType":"struct FeesPerLiquidity","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"Config","name":"config","type":"bytes32"}],"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"internalType":"int32","name":"tick","type":"int32"}],"name":"initializePool","outputs":[{"internalType":"SqrtRatio","name":"sqrtRatio","type":"uint96"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"bytes32","name":"salt","type":"bytes32"},{"internalType":"uint128","name":"amount0","type":"uint128"},{"internalType":"uint128","name":"amount1","type":"uint128"}],"name":"load","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"poolId","type":"bytes32"},{"internalType":"int32","name":"fromTick","type":"int32"},{"internalType":"uint32","name":"tickSpacing","type":"uint32"},{"internalType":"uint256","name":"skipAhead","type":"uint256"}],"name":"nextInitializedTick","outputs":[{"internalType":"int32","name":"tick","type":"int32"},{"internalType":"bool","name":"isInitialized","type":"bool"}],"stateMutability":"view","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":[{"internalType":"address","name":"token","type":"address"}],"name":"pay","outputs":[{"internalType":"uint128","name":"payment","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"poolId","type":"bytes32"},{"internalType":"int32","name":"fromTick","type":"int32"},{"internalType":"uint32","name":"tickSpacing","type":"uint32"},{"internalType":"uint256","name":"skipAhead","type":"uint256"}],"name":"prevInitializedTick","outputs":[{"internalType":"int32","name":"tick","type":"int32"},{"internalType":"bool","name":"isInitialized","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"bool","name":"beforeInitializePool","type":"bool"},{"internalType":"bool","name":"afterInitializePool","type":"bool"},{"internalType":"bool","name":"beforeSwap","type":"bool"},{"internalType":"bool","name":"afterSwap","type":"bool"},{"internalType":"bool","name":"beforeUpdatePosition","type":"bool"},{"internalType":"bool","name":"afterUpdatePosition","type":"bool"},{"internalType":"bool","name":"beforeCollectFees","type":"bool"},{"internalType":"bool","name":"afterCollectFees","type":"bool"}],"internalType":"struct CallPoints","name":"expectedCallPoints","type":"tuple"}],"name":"registerExtension","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"requestOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"bytes32","name":"salt","type":"bytes32"},{"internalType":"uint128","name":"amount0","type":"uint128"},{"internalType":"uint128","name":"amount1","type":"uint128"}],"name":"save","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"sload","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"Config","name":"config","type":"bytes32"}],"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"internalType":"int128","name":"amount","type":"int128"},{"internalType":"bool","name":"isToken1","type":"bool"},{"internalType":"SqrtRatio","name":"sqrtRatioLimit","type":"uint96"},{"internalType":"uint256","name":"skipAhead","type":"uint256"}],"name":"swap_611415377","outputs":[{"internalType":"int128","name":"delta0","type":"int128"},{"internalType":"int128","name":"delta1","type":"int128"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"tload","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"Config","name":"config","type":"bytes32"}],"internalType":"struct PoolKey","name":"poolKey","type":"tuple"},{"components":[{"internalType":"bytes32","name":"salt","type":"bytes32"},{"components":[{"internalType":"int32","name":"lower","type":"int32"},{"internalType":"int32","name":"upper","type":"int32"}],"internalType":"struct Bounds","name":"bounds","type":"tuple"},{"internalType":"int128","name":"liquidityDelta","type":"int128"}],"internalType":"struct UpdatePositionParameters","name":"params","type":"tuple"}],"name":"updatePosition","outputs":[{"internalType":"int128","name":"delta0","type":"int128"},{"internalType":"int128","name":"delta1","type":"int128"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint128","name":"amount","type":"uint128"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawProtocolFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

608034608957601f615d6838819003918201601f19168301916001600160401b03831184841017608d57808492602094604052833981010312608957516001600160a01b0381169081900360895780638b78c6d819555f7f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08180a3604051615cc690816100a28239f35b5f80fd5b634e487b7160e01b5f52604160045260245ffdfe6103006040526004361015610070575b3615610019575f80fd5b6100216150b3565b506fffffffffffffffffffffffffffffffff34116100485761004690345f0390614e8c565b005b7f9cac58ca000000000000000000000000000000000000000000000000000000005f5260045ffd5b5f6101a0525f3560e01c805f14612d0f57806303a65ab614612c6b57806305d7e69414612ba25780630c11dedd146129b95780630e7f26391461298e578063101e89521461287f5780632569296214612807578063380eb4e0146127955780633d5125141461269b57806354d1f13d1461262557806355f48d0114611877578063624ae7e314611681578063645ec9b5146111b457806366e064a814611172578063715018a6146110c95780638da5cb5b14611056578063acdf754f14610ea0578063c05302441461098b578063de6f935f146105d6578063e96404f81461046c578063ed832830146103fa578063f04e283e14610385578063f2fde38b14610322578063f83d08ba146101e25763fee81cf40361000f57346101db5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576101bf61393e565b63389a75e1600c526101a05152602080600c2054604051908152f35b6101a05180fd5b346101db577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36016101a05181126101db577f07cc7f5195d862f505d6b095c82f92e00cfc1766f5bca4383c28dc5fca1555fd5c8060a01c90336001830160a01b177f07cc7f5195d862f505d6b095c82f92e00cfc1766f5bca4383c28dc5fca1555fd5d604051927fb45a3c0e000000000000000000000000000000000000000000000000000000008452826004850152600460248501376101a05180366020018582335af115610316577f07cc7f5195d862f505d6b095c82f92e00cfc1766f5bca4383c28dc5fca1555fd5d807f7772acfd7e0f66ebb20a058830296c3dc1301b111d23348e1c961d324223190d015c61030357503d6101a051823e3d90f35b639731ba376101a051526020526024601cfd5b823d6101a051823e3d90fd5b60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db5761035461393e565b61035c615144565b8060601b156103755761036e90615309565b6101a05180f35b637448fbae6101a051526004601cfd5b60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576103b761393e565b6103bf615144565b63389a75e1600c52806101a051526020600c2090815442116103ea5761036e916101a0519055615309565b636f5e88186101a051526004601cfd5b346101db577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36016101a05181126101db5760045b36811061043d57506101a051f35b80355c7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc82015260200161042f565b60a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db5761049f36613984565b6104a7613a3b565b906104b0613a1c565b906104b9613ca0565b73ffffffffffffffffffffffffffffffffffffffff808460349694960151169116036101db577ff7e050d866774820d81a86ca676f3afe7bc72603ee893f82e99c08fbde39af6c9361055a6060946fffffffffffffffffffffffffffffffff73ffffffffffffffffffffffffffffffffffffffff602088882097878717610572575b61054d84848351169816809887614e26565b0151169416938491614f0c565b60405192835260208301526040820152a16101a05180f35b886101a051526002825260406101a051205460801c80610593575b5061053b565b60038352878960406101a05120916105c6575b6105b1575b5061058d565b600101908960801b0481540190558b806105ab565b828a60801b0482540182556105a6565b346101db576101007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db57604051610612816138c4565b60043580151581036101db57815260243580151581036101db57602082015260443580151581036101db57604082015260643580151581036101db57606082015261065b613a0d565b608082015260a43580151581036101db5760a082015260c43580151581036101db5760c082015260e43580151581036101db5760e082015261069b61538a565b506106a461538a565b5060013360981c1615906040516106ba816138c4565b82158082523360981c6080818116151560208086019190915260408084161515908601528216151560608501526010821615159084015260088116151560a084015260048116151560c0840152600216151560e09092019190915281511515149081610972575b81610959575b81610940575b81610927575b8161090e575b816108f5575b816108dd575b501590811561083a575b5061080c57336101a051526101a05160205260ff60406101a0512054166107de57336101a051526101a05160205260406101a0512060017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff008254161790557fec1256266e470abb868620c851f6bde2a3ff602549dcad318ab9ccfcb2977f146020604051338152a16101a05180f35b7f8b20f687000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b7f7865ebfd000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b801591506108ce575b80156108bf575b80156108b0575b80156108a1575b8015610892575b8015610883575b8015610874575b158161074f565b5060023360981c16151561086d565b5060043360981c161515610866565b5060083360981c16151561085f565b5060103360981c161515610858565b5060203360981c161515610851565b5060403360981c16151561084a565b5060803360981c161515610843565b60e091500151151560023360981c1615151482610745565b905060c0810151151560043360981c161515149061073f565b905060a0810151151560083360981c1615151490610739565b90506080810151151560103360981c1615151490610733565b90506060810151151560203360981c161515149061072d565b90506040810151151560403360981c1615151490610727565b90506020810151151560803360981c1615151490610721565b346101db5760807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576109c336613984565b606435600381900b91908281036101db5773ffffffffffffffffffffffffffffffffffffffff82511673ffffffffffffffffffffffffffffffffffffffff6020840151161115610e7257620aa8ed63ffffffff83604001511611610e445781603401519273ffffffffffffffffffffffffffffffffffffffff84169182610d1c575b6060842094856101a05152600260205260406101a0512060405190610a698261385f565b549060406bffffffffffffffffffffffff8316928383528060601c60030b602084015260801c910152610cee577f5e4688b340694b7c7fd30047fd082117dc46e32acfbf81a44bb1fac0ae65154d60c0610ac460019461404e565b97610bae6bffffffffffffffffffffffff6040519a610ae28c61385f565b16998a81526fffffffffffffffffffffffffffffffff6020820189815260408301906101a0518252856101a0515260026020526bffffffffffffffffffffffff60406101a051209451167fffffffffffffffffffffffffffffffff000000000000000000000000000000008554925160601b6fffffffff0000000000000000000000001692161717835551166fffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffff0000000000000000000000000000000083549260801b169116179055565b604051908152610c0160208201896040809173ffffffffffffffffffffffffffffffffffffffff815116845273ffffffffffffffffffffffffffffffffffffffff60208201511660208501520151910152565b8560808201528860a0820152a1609f1c1680610ce4575b610c28575b602084604051908152f35b813b156101db57604080517f948374ff000000000000000000000000000000000000000000000000000000008152336004820152845173ffffffffffffffffffffffffffffffffffffffff90811660248301526020860151166044820152930151606484015260848301528260a48301528160c4816101a051936101a051905af18015610cd657610cbb575b8080610c1d565b6101a051610cc8916138fd565b6101a0516101db5781610cb4565b6040513d6101a051823e3d90fd5b5033821415610c18565b7f7983c051000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b826101a051526101a05160205260ff60406101a05120541615610e165760018560981c1680610e0c575b15610a4557823b156101db576040517f1fbbb462000000000000000000000000000000000000000000000000000000008152336004820152610dcb60248201866040809173ffffffffffffffffffffffffffffffffffffffff815116845273ffffffffffffffffffffffffffffffffffffffff60208201511660208501520151910152565b8260848201526101a0518160a4816101a051885af18015610cd657610df1575b50610a45565b6101a051610dfe916138fd565b6101a0516101db5785610deb565b5033831415610d46565b7fcd72c3bc000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b7f270815a0000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b7f88a2efcf000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b346101db5760a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db57610ed761393e565b610edf613961565b610ee7613a3b565b90610ef0613a1c565b91610ef96150b3565b5092610f4e60443573ffffffffffffffffffffffffffffffffffffffff851673ffffffffffffffffffffffffffffffffffffffff88163391608093916040519384526020840152604083015260608201522090565b94856101a05152600860205260406101a0512054906fffffffffffffffffffffffffffffffff8260801c9216916fffffffffffffffffffffffffffffffff851690818110801561103b575b61100d577fffffffffffffffffffffffffffffffff000000000000000000000000000000006fffffffffffffffffffffffffffffffff9687876110019761036e9d6101a0515260086020520316920360801b160160406101a05120556101a051039086614f0c565b166101a0510391614f0c565b7f7b3df0ec000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b506fffffffffffffffffffffffffffffffff85168410610f99565b346101db576101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db5760207fffffffffffffffffffffffffffffffffffffffffffffffffffffffff748739275473ffffffffffffffffffffffffffffffffffffffff60405191168152f35b6101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576110fd615144565b6101a0517fffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a36101a0517fffffffffffffffffffffffffffffffffffffffffffffffffffffffff7487392781905580f35b346101db5761119d61118336613ab5565b926101a09291925152600760205260406101a05120613ebb565b6040805160039390930b8352901515602083015290f35b346101db5760c07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576111ec36613984565b6064356111f836613a5a565b90611201613ca0565b91909380603401519373ffffffffffffffffffffffffffffffffffffffff851692600186609a1c1680611661575b61159e575b6060832095604051966112468861385f565b828852602088019673ffffffffffffffffffffffffffffffffffffffff1696878152604089019085825261128a8a604080918181205f5201512060205260405f2090565b99836101a0515260046020526101a051604090208b6101a051526020526101a051604090206112b890613c3d565b9b8c9b896040015163ffffffff166112d1908a88614fd2565b9d8e6112dc916152bf565b9e909d516fffffffffffffffffffffffffffffffff169160405192611300846138a8565b835260208301918252876101a0515260046020526101a05160409020906101a051526020526101a0516040902091516fffffffffffffffffffffffffffffffff166fffffffffffffffffffffffffffffffff1682547fffffffffffffffffffffffffffffffff00000000000000000000000000000000161782555180516001830155602001519060020155885173ffffffffffffffffffffffffffffffffffffffff169b6fffffffffffffffffffffffffffffffff169b6113c08d613c74565b6113ca9183614f0c565b602089015173ffffffffffffffffffffffffffffffffffffffff169c6fffffffffffffffffffffffffffffffff169c6114028e613c74565b9061140c92614f0c565b6040519384525160208401525173ffffffffffffffffffffffffffffffffffffffff16604083015251606082016114529160208091805160030b8452015160030b910152565b8760a08201528860c082015260e07fbb3992d83c721f12a8f32242e0d21c3613949c6a69d2a35deecdf6943a61c8b291a160991c60011680611594575b6114a4575b6040868882519182526020820152f35b833b156101db5761152861154793604051967fcdd0fa0e000000000000000000000000000000000000000000000000000000008852600488015260248701906040809173ffffffffffffffffffffffffffffffffffffffff815116845273ffffffffffffffffffffffffffffffffffffffff60208201511660208501520151910152565b608485015260a484019060208091805160030b8452015160030b910152565b8260e48301528361010483015281610124816101a051936101a051905af18015610cd657611579575b80808080611494565b6101a051611586916138fd565b6101a0516101db5782611570565b508385141561148f565b833b156101db57604080517f6fb5bfe300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8781166004830152855181166024830152602086015116604482015290840151606482015281608482015261162960a482018460208091805160030b8452015160030b910152565b6101a0518160e48183895af18015610cd657611646575b50611234565b6101a051611653916138fd565b6101a0516101db5787611640565b508373ffffffffffffffffffffffffffffffffffffffff8616141561122f565b60c07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576116b361393e565b6116bb613961565b9060443573ffffffffffffffffffffffffffffffffffffffff8116918282036101db576116e6613a1c565b936101a0515060a435906fffffffffffffffffffffffffffffffff8216948583036101db5773ffffffffffffffffffffffffffffffffffffffff821693818510156118495761177191611737613ca0565b509573ffffffffffffffffffffffffffffffffffffffff606435931691608093916040519384526020840152604083015260608201522090565b806101a0515260086020526fffffffffffffffffffffffffffffffff6117d360406101a051205494827fffffffffffffffffffffffffffffffff000000000000000000000000000000006117c88c8960801c613ba0565b60801b169616613ba0565b1683018093116118165761036e96611811936fffffffffffffffffffffffffffffffff926101a05152600860205260406101a0512055169083614e26565b614f0c565b7f4e487b71000000000000000000000000000000000000000000000000000000006101a05152601160045260246101a051fd5b7f5b0110b2000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b60e07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576118aa36613984565b60807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9c3601126101db57604051906118e18261385f565b60643582526118ef36613a5a565b602083015260c435600f81900b81036101db5760408301526101a05191829190611917613ca0565b929091816034015192600184609c1c16806125ef575b612515575b6020820151604084015163ffffffff16806123f157507ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffab6326d815160030b14908115916123db575b506123ad575b6040820151600f0b611b0c575b50600183609b1c1680611ad6575b6119b3575b60408051600f87810b825288900b6020820152f35b73ffffffffffffffffffffffffffffffffffffffff83163b156101db57611a63611a6d9273ffffffffffffffffffffffffffffffffffffffff604051967f3c85e5a100000000000000000000000000000000000000000000000000000000885216600487015260248601906040809173ffffffffffffffffffffffffffffffffffffffff815116845273ffffffffffffffffffffffffffffffffffffffff60208201511660208501520151910152565b6084840190613c08565b82600f0b61010483015283600f0b61012483015281610144816101a0519373ffffffffffffffffffffffffffffffffffffffff6101a05191165af18015610cd657611abb575b80808061199e565b6101a051611ac8916138fd565b6101a0516101db5782611ab3565b5073ffffffffffffffffffffffffffffffffffffffff831673ffffffffffffffffffffffffffffffffffffffff85161415611999565b945094506060812094856101a05152600260205260406101a051209460405195611b358761385f565b546bffffffffffffffffffffffff8116908188528060601c60030b602089015260801c60408801521561237f57611ba8611b7660208401515160030b61404e565b611b89602080860151015160030b61404e565b906bffffffffffffffffffffffff8951166040860151600f0b9061518d565b96909787988098855191602087015160405193611bc48561385f565b845273ffffffffffffffffffffffffffffffffffffffff8b16602085015260408401526101a0516040880151600f0b126121ef575b5050611c1590604080918181205f5201512060205260405f2090565b816101a05152600460205260406101a05120906101a0515260205260406101a05120611c51602086015163ffffffff8860400151169084614fd2565b611c6381611c5e84613c3d565b6152bf565b91611c896fffffffffffffffffffffffffffffffff85541660408a0151600f0b90614d75565b6fffffffffffffffffffffffffffffffff81161561212a5791611d0a91836002956fffffffffffffffffffffffffffffffff602096167fffffffffffffffffffffffffffffffff000000000000000000000000000000008954161788558160405194611cf4866138a8565b608090811b9190910485521b0484830152614dc8565b8051600185015501519101555b604085015163ffffffff16156120d95760208401515160030b9263ffffffff866040015116936040860151600f0b936101a05150836101a05152600560205260406101a051208260030b5f5260205260405f2095865496611d7b878960801c614d75565b906f7fffffffffffffffffffffffffffffff600f8a900b89019081137fffffffffffffffffffffffffffffffff8000000000000000000000000000000090911217611816577fa2d4008be4187c63684f323788e131e1370dbc2205499befe2834005a00c792c9861010098602096611e5b956fffffffffffffffffffffffffffffffff861615608085901c150361209d575b505060809390931b7fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff600f9290920b9390930116919091179055565b611f1b8280890151015160030b63ffffffff8a60400151169060408a0151600f0b876101a051526005865260406101a051208260030b5f52865260405f2091825493611eb88560801c93611eaf8186614d75565b96600f0b613b2c565b926fffffffffffffffffffffffffffffffff861615901503612061575b505060809290921b7fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff909216919091179055565b015160030b602086015190815160030b8112159182612050575b5050611fce575b73ffffffffffffffffffffffffffffffffffffffff865116611f638a600f0b809284614e26565b611f8e73ffffffffffffffffffffffffffffffffffffffff602089015116928c600f0b938491614f0c565b6040519273ffffffffffffffffffffffffffffffffffffffff8a1684526020840152611fbd6040840187613c08565b60c083015260e0820152a18661198b565b816101a05152600260205261204b611ff860406101a051205460801c6040880151600f0b90614d75565b836101a05152600260205260406101a05120906fffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffff0000000000000000000000000000000083549260801b169116179055565b611f3c565b6020015160030b1390508b80611f35565b61207c908a6101a051526007895260406101a05120926153c6565b91906101a05152875260406101a051209060018254911b1890555f80611ed5565b6120b8908b6101a0515260078a5260406101a05120926153c6565b91906101a05152885260406101a051209060018254911b1890555f80611e0d565b61010091507fa2d4008be4187c63684f323788e131e1370dbc2205499befe2834005a00c792c92816101a05152600260205261204b611ff860406101a051205460801c6040880151600f0b90614d75565b50506fffffffffffffffffffffffffffffffff1615908115916121d3575b506121a5577fffffffffffffffffffffffffffffffff00000000000000000000000000000000815416815560405161217f816138a8565b6101a051815260206101a0519101526101a051600182015560026101a051910155611d17565b7fea22ccd0000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b6fffffffffffffffffffffffffffffffff91501615158b612148565b67ffffffffffffffff88603c015116908161220b575b50611bf9565b6fffffffffffffffffffffffffffffffff67ffffffffffffffff83836101a051038316020160401c166122ee575b506fffffffffffffffffffffffffffffffff67ffffffffffffffff82846101a051038316020160401c1661226e575b80612205565b611c15929b5067ffffffffffffffff6fffffffffffffffffffffffffffffffff9173ffffffffffffffffffffffffffffffffffffffff60208b0151166101a05152600160205260406101a05120838383876101a051038316020160401c168154019055836101a051038316020160401c16600f0b01600f0b99908b612268565b909a5073ffffffffffffffffffffffffffffffffffffffff8851166101a05152600160205260406101a051206fffffffffffffffffffffffffffffffff67ffffffffffffffff8d846101a051038316020160401c1681540190556fffffffffffffffffffffffffffffffff67ffffffffffffffff8c836101a051038316020160401c16600f0b01600f0b998c612239565b7f486aa307000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b7fe5e15e5d000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b630549cd9391506020015160030b141588611978565b90805160030b916020820192835160030b13156124e7577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffab6326d825160030b1280156124d6575b6124a85761244c9060030b80925160030b61517b565b60030b159182159261248e575b50501561197e577f89fd41b1000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b61249c92505160030b61517b565b60030b15158880612459565b7fabfa4a31000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b50630549cd93835160030b13612436565b7f68651c5c000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b73ffffffffffffffffffffffffffffffffffffffff84163b156101db57604080517fb14b106d00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff878116600483015285518116602483015260208601511660448201529084015160648201526125a06084820184613c08565b6101a05181610104818373ffffffffffffffffffffffffffffffffffffffff8a165af18015610cd6576125d4575b50611932565b6101a0516125e1916138fd565b6101a0516101db57876125ce565b5073ffffffffffffffffffffffffffffffffffffffff841673ffffffffffffffffffffffffffffffffffffffff8616141561192d565b6101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db5763389a75e1600c52336101a051526101a0516020600c2055337ffa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c926101a0516101a051a26101a05180f35b346101db5760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576126d261393e565b6126da613961565b90604435906126e7615144565b73ffffffffffffffffffffffffffffffffffffffff831691826101a05152600160205260406101a0512092835494828603958611611816577f8fc241308ffc17817e6a8c6a52a8f7cd4931dfca0c539fd35a630311c7e4c57b9560609555828483155f14612787576127599250614fb6565b73ffffffffffffffffffffffffffffffffffffffff6040519316835260208301526040820152a16101a05180f35b61279092614f5c565b612759565b346101db577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36016101a05181126101db5760045b3681106127d857506101a051f35b8035547ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc8201526020016127ca565b6101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db5763389a75e1600c52336101a051526202a30042016020600c2055337fdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d6101a0516101a051a26101a05180f35b346101db5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576128b661393e565b6128be613ca0565b90916001830160a01b908082177f07cc7f5195d862f505d6b095c82f92e00cfc1766f5bca4383c28dc5fca1555fd5d604051937f64919dea00000000000000000000000000000000000000000000000000000000855260048501528260248501527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc3601602460448601376101a0519081906020360190869083905af11561031657177f07cc7f5195d862f505d6b095c82f92e00cfc1766f5bca4383c28dc5fca1555fd5d3d6101a051823e3d90f35b346101db5761119d61299f36613ab5565b926101a09291925152600760205260406101a05120613cf1565b346101db5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576129f061393e565b7fe1be600102d456bf2d4dee36e1641404df82292916888bf32557e00dfe1664125c612b925760017fe1be600102d456bf2d4dee36e1641404df82292916888bf32557e00dfe1664125d612a426150b3565b5090604051306014526f70a082310000000000000000000000006101a0515260208160246010855afa601f3d1116815102907f599d07140000000000000000000000000000000000000000000000000000000081528360048201528260248201527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc3601602460448301376101a05180602036018382335af115612b87575060208060246010855afa601f3d111660205102818110612b7757036fffffffffffffffffffffffffffffffff8111612b67576020926fffffffffffffffffffffffffffffffff612b39921692836101a0510391614f0c565b6101a0517fe1be600102d456bf2d4dee36e1641404df82292916888bf32557e00dfe1664125d604051908152f35b639cac58ca6101a051526004601cfd5b6301b243b96101a051526004601cfd5b3d6101a051823e3d90fd5b63ced108be6101a051526004601cfd5b346101db5760a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db57612bda36613984565b6040367fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9c01126101db5760405190612c11826138a8565b606435600381900b81036101db57825260843590600382900b82036101db5782612c599260206040950152612c44613bf0565b5063ffffffff60608320928501511691614fd2565b60208251918051835201516020820152f35b346101db5760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db57612ca261393e565b612caa613961565b6044356fffffffffffffffffffffffffffffffff811691908290036101db57612cdc8284612cd6613ca0565b50614f0c565b73ffffffffffffffffffffffffffffffffffffffff8316612d015761036e9250614fb6565b612d0a92614f5c565b61036e565b60e07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126137fd57612d4236613984565b606435610160819052600f81900b90036137fd57612d5e613a0d565b6bffffffffffffffffffffffff60a4351660a435036137fd575f905f926bffff9a5889f795069a41a8a360a435111567400065a8177fae2760a435101516673fffffffffffffff7fffffffffffffffffffffffffffffffffffffffff3fffffffffffffffffffffff60a4351611161561383757612dd9613ca0565b906101005291816034015191600183609e1c1680613801575b6136fc575b606080822060808181526101a0805160e081815293905260026020525160409020549081901c9091526bffffffffffffffffffffffff8116911c60030b81801561237f5761016051600f0b612fa2575b505050600183609d1c1680612f6c575b612e705760408051600f87810b825288900b6020820152f35b73ffffffffffffffffffffffffffffffffffffffff83163b156101db57604080517fc0578abb00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff9586166004820152825186166024820152602083015190951660448601520151606484015261016051600f0b6084840152151560a48301526bffffffffffffffffffffffff60a4351660c483015260c43560e483015282600f0b61010483015283600f0b61012483015281610144816101a0519373ffffffffffffffffffffffffffffffffffffffff6101a05191165af18015610cd657611abb5780808061199e565b5073ffffffffffffffffffffffffffffffffffffffff831673ffffffffffffffffffffffffffffffffffffffff85161415612e57565b91965092949196506101a051610160511285185f146136b75760a4356bffffffffffffffffffffffff1610613689575b61016051610180526101a05160c081905260a081905260408701519093906bffffffffffffffffffffffff1661365a575b9491925b61018051600f0b15158061363c575b15613451576101a05161014081905261012052613031613b08565b50604087015163ffffffff16156133f6576101a051610160511285146133c1576080516101a05152600760205261307e60406101a0512060c435908663ffffffff8b604001511691613ebb565b9390935b6101405261308f8461404e565b610120525b6101a051610160511286146133a3576130dc6101205160a4351060a43561012051180261012051185b8767ffffffffffffffff8b603c01511691610180519060e05186614504565b9160e051606084015160801b0401946130fc8351600f0b61018051613b2c565b610180526131226fffffffffffffffffffffffffffffffff60208501511660c051613ba0565b60c0526040830151610120516bffffffffffffffffffffffff9182169116810361336b57505050604001516101a051610160516bffffffffffffffffffffffff90921696911285146132e257825b9261014051613184575b505b949192613007565b6080516101a05152600560205260406101a051208160030b5f5260205260405f2054600f0b6101a051506101a051610160511287185f14613280576131cb9060e051614d75565b60e0526080516101a05152600660205260406101a051208160030b5f5260205261324a6131fa60405f20613bd2565b604051613206816138a8565b5f81525f6020820152876101a05161016051128a1860051b8201526101a05161016051128914806101a05161016051128b1860a0510301549060051b820152614dc8565b906080516101a05152600660205260406101a051209060030b5f526020526001602060405f20928051845501519101558761317a565b7fffffffffffffffffffffffffffffffff000000000000000000000000000000008160e05103166132b45760e051036131cb565b7f6d862c50000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8360030b01637fffffff81137fffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000000082121715613170577f4e487b71000000000000000000000000000000000000000000000000000000006101a05152601160045260246101a051fd5b919790945091506bffffffffffffffffffffffff871681900361338f575b5061317c565b9550915061339c856148c8565b9187613389565b6130dc6101205160a4351160a43561012051180261012051186130bd565b6080516101a0515260076020526133ee60406101a0512060c435908663ffffffff8b604001511691613cf1565b939093613082565b6101a0516101605112851461342257630549cd936bffff9a5889f795069a41a8a35b6101205292613094565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffab6326d67400065a8177fae27613418565b959093919492946135116fffffffffffffffffffffffffffffffff60c051166101a05161016051600f0b12157ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe02600118027fffffffffffffffffffffffffffffffff800000000000000000000000000000008113907fffffffffffffffffffffffffffffffff8000000000000000000000000000000018027fffffffffffffffffffffffffffffffff8000000000000000000000000000000018614df8565b8315613627579060749196610180516101605103600f0b915b8299896080516101a05152600260205260e05160801b91826fffffffff0000000000000000000000008660601b1685010160406101a05120556bffffffffffffffffffffffff88604001511661361d575b506135a573ffffffffffffffffffffffffffffffffffffffff88511682600f0b9061010051614e26565b6135d173ffffffffffffffffffffffffffffffffffffffff60208901511686600f0b9061010051614f0c565b6fffffffffffffffffffffffffffffffff604051958b60601b87526080516014880152169060801b176034850152605484015260a01b606483015260e01b6070820152a0868080612e47565b60a051558c61357b565b610180516101605103600f0b9660749261352a565b506bffffffffffffffffffffffff83811660a4359091161415613016565b92506080516101a0515260036020526101a0516101605112841860406101a051200160a05260a0515492613003565b7fa574a6b4000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b60a4356bffffffffffffffffffffffff161115612fd2577fa574a6b4000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b73ffffffffffffffffffffffffffffffffffffffff83163b156137fd57604080517f3c65c87a00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8681166004830152835181166024830152602084015116604482015290820151606482015261016051600f0b608482015282151560a48201526bffffffffffffffffffffffff60a4351660c482015260c43560e48201525f81610104818373ffffffffffffffffffffffffffffffffffffffff89165af180156137f2576137dd575b50612df7565b5f6137e7916138fd565b5f6101a052866137d7565b6040513d5f823e3d90fd5b5f80fd5b5073ffffffffffffffffffffffffffffffffffffffff831673ffffffffffffffffffffffffffffffffffffffff85161415612df2565b7f9cc3dd4a000000000000000000000000000000000000000000000000000000005f5260045ffd5b6060810190811067ffffffffffffffff82111761387b57604052565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6040810190811067ffffffffffffffff82111761387b57604052565b610100810190811067ffffffffffffffff82111761387b57604052565b6080810190811067ffffffffffffffff82111761387b57604052565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff82111761387b57604052565b6004359073ffffffffffffffffffffffffffffffffffffffff821682036137fd57565b6024359073ffffffffffffffffffffffffffffffffffffffff821682036137fd57565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc60609101126137fd57604051906139bb8261385f565b8160043573ffffffffffffffffffffffffffffffffffffffff811681036137fd57815260243573ffffffffffffffffffffffffffffffffffffffff811681036137fd5760208201526040604435910152565b6084359081151582036137fd57565b608435906fffffffffffffffffffffffffffffffff821682036137fd57565b606435906fffffffffffffffffffffffffffffffff821682036137fd57565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7c60409101126137fd5760405190613a91826138a8565b816084358060030b81036137fd57815260a435908160030b82036137fd5760200152565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc60809101126137fd57600435906024358060030b81036137fd579060443563ffffffff811681036137fd579060643590565b60405190613b15826138e1565b5f6060838281528260208201528260408201520152565b90600f0b90600f0b03906f7fffffffffffffffffffffffffffffff82137fffffffffffffffffffffffffffffffff80000000000000000000000000000000831217613b7357565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b906fffffffffffffffffffffffffffffffff809116911601906fffffffffffffffffffffffffffffffff8211613b7357565b90604051613bdf816138a8565b602060018294805484520154910152565b60405190613bfd826138a8565b5f6020838281520152565b604060609180518452613c336020820151602086019060208091805160030b8452015160030b910152565b0151600f0b910152565b90604051613c4a816138a8565b6020613c6f600183956fffffffffffffffffffffffffffffffff815416855201613bd2565b910152565b7f80000000000000000000000000000000000000000000000000000000000000008114613b73575f0390565b613ca86150b3565b90913373ffffffffffffffffffffffffffffffffffffffff831603613cc957565b7feed0f119000000000000000000000000000000000000000000000000000000005f5260045ffd5b919091613cff825f946153c6565b815f52826020527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60018060ff60405f20549416011b01167f07060605060205040602030205040301060502050303040105050304000000006f8421084210842108cc6318c6db6d54be826fffffffffffffffffffffffffffffffff1060071b831560081b1783811c67ffffffffffffffff1060061b1783811c63ffffffff1060051b1783811c61ffff1060041b1783811c60ff1060031b1792831c1c601f161a176101008103613e8757507ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaab8881839160081b0102937ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffab6326d8560030b1315613e5e578015613e5757827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80613cff9301960160030b6153c6565b5050509091565b50505090507ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffab6326d91565b915093507ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaab888191925060019360081b01010291565b919091613ed8825f945b63ffffffff821660030b0160030b6153c6565b815f52826020527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff600160ff60405f205493161b0119166001811901167e1f0d1e100c1d070f090b19131c1706010e11080a1a141802121b1503160405601f6101e07f804040554300526644320000502061067405302602000010750620017611707760fc7fb6db6db6ddddddddd34d34d349249249210842108c6318c639ce739cffffffff860260f81c161b60f71c1692831c63d76453e004161a176101008103613e8757507ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaab8980839160081b010293630549cd938560030b121561400a578015613e5757827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff613ed8920195613ec5565b5050509050630549cd9391565b8115614021570490565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b60030b8060ff1d8082011890630549cd9382116144a7576d08637b66cd638344daef276cd7c5600183160270010000000000000000000000000000000003916002811661448b575b6004811661446f575b60088116614453575b60108116614437575b6020811661441b575b604081166143ff575b608081166143e3575b61010081166143c7575b61020081166143ab575b610400811661438f575b6108008116614373575b6110008116614357575b612000811661433b575b614000811661431f575b6180008116614303575b6201000081166142e7575b6202000081166142cb575b6204000081166142af575b620800008116614293575b621000008116614277575b62200000811661425b575b62400000811661423f575b628000008116614223575b63010000008116614208575b630200000081166141ee575b6304000000166141d7575b5f126141aa575b6141a7906153e3565b90565b8015614021577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0461419e565b69c0d55d4d7152c25fb13990910260801c90614197565b6cde2ee4bc381afa7089aa84bb6690920260801c9161418c565b916e0ee7e32d61fdb0a5e622b820f681d00260801c91614180565b916f03dc5dac7376e20fc8679758d1bcdcfc0260801c91614174565b916f1f703399d88f6aa83a28b22d4a1f56e30260801c91614169565b916f59b63684b86e9f486ec54727371ba6ca0260801c9161415e565b916f978bcb9894317807e5fa4498eee7c0fa0260801c91614153565b916fc4f76b68947482dc198a48a54348c4ed0260801c91614148565b916fe08d35706200796273f0b3a981d90cfd0260801c9161413d565b916fefc2bf59df33ecc28125cf78ec4f167f0260801c91614132565b916ff7bf5211c72f5185f372aeb1d48f937e0260801c91614127565b916ffbd701c7cbc4c8a6bb81efd232d1e4e70260801c9161411c565b916ffde95287d26d81bea159c37073122c730260801c91614112565b916ffef41d1a5f2ae3a20676bec6f7f9459a0260801c91614108565b916fff79eb706b9a64c6431d76e63531e9290260801c916140fe565b916fffbceceeb791747f10df216f2e53ec570260801c916140f4565b916fffde7444b28145508125d10077ba83b80260801c916140ea565b916fffef3995a5b6a6267530f207142a57640260801c916140e0565b916ffff79ca7a4d1bf1ee8556cea23cdbaa50260801c916140d6565b916ffffbce4b06c196e9247ac87695d53c600260801c916140cc565b916ffffde72350725cc4ea8feece3b5f13c80260801c916140c3565b916ffffef3911b7cff24ba1b3dbb5f8f59740260801c916140ba565b916fffff79c86a8f6150a32d9778eceef97c0260801c916140b1565b916fffffbce42c7be6c998ad6318193c0b180260801c916140a8565b916fffffde72140b00a354bd3dc828e976c90260801c9161409f565b916fffffef390978c398134b4ff3764fe4100260801c91614096565b7f073ee172000000000000000000000000000000000000000000000000000000005f5260045260245ffd5b906fffffffffffffffffffffffffffffffff809116911603906fffffffffffffffffffffffffffffffff8211613b7357565b9490939192614511613b08565b5080600f0b95861580156148a3575b614893575f8212808518916bffffffffffffffffffffffff8716956bffffffffffffffffffffffff8216968781119382149384150361486b576fffffffffffffffffffffffffffffffff8a1615614857575f8b129889156148255786955b83156148145761458f878d87615769565b955b816147fb575b81156147d6575b506146b75750506bffffffffffffffffffffffff83169680881461464757509787916fffffffffffffffffffffffffffffffff995f14614638576145e193615863565b945b156146245750506145ff6145f8859285615a24565b93846144d2565b925b6040519561460e876138e1565b8652166020850152604084015216606082015290565b85925061463091613b2c565b811692614601565b61464193615942565b946145e3565b9850505050509291505061468a576fffffffffffffffffffffffffffffffff9160405193614674856138e1565b84525f6020850152604084015216606082015290565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52600160045260245ffd5b989a5098935091509394508792505f146147b9576146e2926146dc8315838389615942565b95615863565b935b15614780576fffffffffffffffffffffffffffffffff61470761470e9286615a24565b9216615a8f565b600f0b917fffffffffffffffffffffffffffffffff800000000000000000000000000000008314613b73576fffffffffffffffffffffffffffffffff61475881945f0395846144d2565b925b60405195614767876138e1565b600f0b8652166020850152604084015216606082015290565b916fffffffffffffffffffffffffffffffff6147b36147a0829585615a24565b936147ac838616615a8f565b96946144d2565b9261475a565b6147d0926147ca8315838389615863565b95615942565b936146e4565b9050806147e4575b5f61459e565b50816bffffffffffffffffffffffff8616106147de565b9050826bffffffffffffffffffffffff87161190614597565b61481f878d876155fa565b95614591565b6fffffffffffffffffffffffffffffffff67ffffffffffffffff89898316020160401c16600f0b8703600f0b9561457e565b505050505050505090506141a791506155bf565b7fa574a6b4000000000000000000000000000000000000000000000000000000005f5260045ffd5b9450505050506141a791506155bf565b506bffffffffffffffffffffffff85166bffffffffffffffffffffffff821614614520565b7fffffffffffffffffffffffffffffffffffffffff3fffffffffffffffffffffff81166002605983901c606016011b908160801c1591825f14614d70578015614021577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff045b8060801c61026052610260516fffffffffffffffffffffffffffffffff1060071b61026051811c67ffffffffffffffff1060061b1761026051811c63ffffffff1060051b1761026051811c61ffff1060041b1761026051811c60ff1060031b176102005260017f07060605060205040602030205040301060502050303040105050304000000006f8421084210842108cc6318c6db6d54be61026051610200511c1c601f161a6102005117011c80026102c0526a1527370de4706fc9ea63ab6102c051607f1c6102c05160ff1c15151c800280607f1c8160ff1c15151c800280607f1c8160ff1c15151c800280607f1c8160ff1c15151c800280607f1c8160ff1c15151c80029182607f1c8360ff1c15151c80029384607f1c8560ff1c15151c80029586607f1c8760ff1c15151c800280607f1c8160ff1c15151c800280607f1c8160ff1c15151c800280607f1c8160ff1c15151c80029081607f1c8260ff1c15151c80029283607f1c8460ff1c15151c80029485607f1c8660ff1c15151c80026101c0526101c051607f1c6101c05160ff1c15151c80026102205261022051607f1c6102205160ff1c15151c80026102805261028051607f1c6102805160ff1c15151c6102e0526102e0516102e05102607f1c6102e0516102e0510260ff1c15151c6102a0526102a0516102a05102607f1c6102a0516102a0510260ff1c15151c61024052610240516102405102607f1c61024051610240510260ff1c15151c6101e0526101e0516101e05102607f1c6101e0516101e0510260ff1c15151c800260ff1c1515602a1b9c6101e0516101e0510260ff1c1515602b1b9c61024051610240510260ff1c1515602c1b9c6102a0516102a0510260ff1c1515602d1b9c6102e0516102e0510260ff1c1515602e1b9c6102805160ff1c1515602f1b9c6102205160ff1c151560301b9c6101c05160ff1c151560311b9c60ff1c151560321b9b60ff1c151560331b9a60ff1c151560341b9960ff1c151560351b9860ff1c151560361b9760ff1c151560371b9660ff1c151560381b9560ff1c151560391b9460ff1c1515603a1b9360ff1c1515603b1b9260ff1c1515603c1b9160ff1c1515603d1b9060ff1c1515603e1b6102c05160ff1c1515603f1b7f07060605060205040602030205040301060502050303040105050304000000006f8421084210842108cc6318c6db6d54be61026051610200511c1c601f161a610200511760401b01010101010101010101010101010101010101010101835f14614d6b575f035b029115614d45577fffffffffffffffffffffffffffffffffab6323c86e53680f6455c46fc9ea63ab820160801d60030b9160801d60030b905b8160030b8360030b14614d40576bffffffffffffffffffffffff80614d2d8461404e565b921691161115614d3b575090565b905090565b505090565b6f549cdc3791ac97f09baa3b9036159c558260801d60030b920160801d60030b90614d09565b614cd0565b61492e565b01907fffffffffffffffffffffffffffffffff000000000000000000000000000000008216614da057565b7f6d862c50000000000000000000000000000000000000000000000000000000005f5260045ffd5b919091602060405191614dda836138a8565b5f83525f828401528180849680518451038652015191015103910152565b806f800000000000000000000000000000000160801c15614e20576335278d125f526004601cfd5b600f0b90565b34614e385790614e369291614f0c565b565b906fffffffffffffffffffffffffffffffff34116100485773ffffffffffffffffffffffffffffffffffffffff8116614e795750614e369134900390614e8c565b614e3692614e879183614f0c565b345f03905b9080614e96575050565b7f3fee1dc3ade45aa30d633b5b8645760533723e46597841ef1126c6577a0917428260a01b015f5260205f2090815c90810192831580921518614ed9575b50505d565b7f7772acfd7e0f66ebb20a058830296c3dc1301b111d23348e1c961d324223190d0190801590825c0301905d5f80614ed4565b919081614f1857505050565b7f3fee1dc3ade45aa30d633b5b8645760533723e46597841ef1126c6577a091742908360a01b01015f5260205f2090815c90810192831580921518614ed95750505d565b91906014526034526fa9059cbb0000000000000000000000005f5260205f6044601082855af1908160015f51141615614f98575b50505f603452565b3b153d171015614fa9575f80614f90565b6390b8ec185f526004601cfd5b5f80809338935af115614fc557565b63b12d13eb5f526004601cfd5b909163ffffffff90604051614fe6816138a8565b5f81525f602082015250161561509e57805f52600260205260405f205460601c60030b90805f52600660205260405f2091835160030b60030b5f528260205261503160405f20613bd2565b926020850190815160030b60030b5f5260205261505060405f20613bd2565b945160030b82121561506957505050906141a791614dc8565b5160030b1315615094576141a7929161508f915f52600360205261508f60405f20613bd2565b614dc8565b506141a791614dc8565b90505f5260036020526141a760405f20613bd2565b7f07cc7f5195d862f505d6b095c82f92e00cfc1766f5bca4383c28dc5fca1555fd5c90811561511c5773ffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8360a01c01921690565b7f1834e265000000000000000000000000000000000000000000000000000000005f5260045ffd5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffff7487392754330361516e57565b6382b429005f526004601cfd5b9060030b9081156140215760030b0790565b90925f905f94600f0b9384156152b3575f8513936fffffffffffffffffffffffffffffffff85157ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe02600118968060ff1d8091011816936bffffffffffffffffffffffff82166bffffffffffffffffffffffff84168111155f1461523957505050926fffffffffffffffffffffffffffffffff9261522f926152369695615863565b1602614df8565b91565b929897509092916bffffffffffffffffffffffff8316111561528f57509282826152896fffffffffffffffffffffffffffffffff6152818582986141a79b9a61522f99615863565b168702614df8565b98615942565b9661522f9250926141a79594916fffffffffffffffffffffffffffffffff94615942565b5050505050505f905f90565b91906153056152e46fffffffffffffffffffffffffffffffff92602086015190614dc8565b93826020816152f888518286511690615aba565b1696015191511690615aba565b1690565b73ffffffffffffffffffffffffffffffffffffffff16807fffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a37fffffffffffffffffffffffffffffffffffffffffffffffffffffffff7487392755565b60405190615397826138c4565b5f60e0838281528260208201528260408201528260608201528260808201528260a08201528260c08201520152565b905f8183071291050390610100630554777f80840160081c930890565b6c0100000000000000000000000081106001146154bb5770010000000000000000000000000000000081106001146154a757740100000000000000000000000000000000000000008110600114615493577801000000000000000000000000000000000000000000000000811060011461547f577fa10459f4000000000000000000000000000000000000000000000000000000005f5260045ffd5b60621c6bc000000000000000000000001790565b60421c6b8000000000000000000000001790565b60221c6b4000000000000000000000001790565b60021c90565b6bfffffffffffffffffffffffd81106001146155b6576ffffffffffffffffffffffffc00000001811060011461559b5773fffffffffffffffffffffffc0000000000000001811060011461557c5777fffffffffffffffffffffffc0000000000000000000000018110600114615559577fa10459f4000000000000000000000000000000000000000000000000000000005f5260045ffd5b6c03ffffffffffffffffffffffff0160621c6bc000000000000000000000001790565b6803ffffffffffffffff0160421c6b8000000000000000000000001790565b6403ffffffff0160221c6b4000000000000000000000001790565b60030160021c90565b6155c7613b08565b506bffffffffffffffffffffffff604051916155e2836138e1565b5f83525f60208401521660408201525f606082015290565b9091600f0b908115615763576fffffffffffffffffffffffffffffffff83161561573b576156747fffffffffffffffffffffffffffffffff000000000000000000000000000000009160607fffffffffffffffffffffffffffffffffffffffff3fffffffffffffffffffffff82169160591c166002011b90565b9260801b16905f8160ff1d8083011891125f1461571d57821561402157827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04811161570a578202918183101561570a576156d192820391615b3e565b77fffffffffffffffffffffffc00000000000000000000000081116156f9576141a7906154c1565b506bffffffffffffffffffffffff90565b5050506bffffffffffffffffffffffff90565b906157369161572f6141a79483614017565b0190615b1f565b6154c1565b7fe0fbe467000000000000000000000000000000000000000000000000000000005f5260045ffd5b91505090565b91600f0b8015614d40576fffffffffffffffffffffffffffffffff821692831561583b576157c29060607fffffffffffffffffffffffffffffffffffffffff3fffffffffffffffffffffff82169160591c166002011b90565b915f6157d98360ff1d8085011860801b9586614017565b9212156157ff57828210156157f7576141a7930615159103036153e3565b505050505f90565b50810191508110801561581a575b6156f9576141a7906153e3565b5077ffffffffffffffffffffffffffffffffffffffffffffffff811161580d565b7f1043d0ac000000000000000000000000000000000000000000000000000000005f5260045ffd5b9061587091939293615b6e565b9290911561590757826158ae917fffffffffffffffffffffffffffffffff00000000000000000000000000000000846158b396039160801b16615b3e565b615b1f565b6fffffffffffffffffffffffffffffffff81116158df576fffffffffffffffffffffffffffffffff1690565b7fb4ef2546000000000000000000000000000000000000000000000000000000005f5260045ffd5b8261593d917fffffffffffffffffffffffffffffffff00000000000000000000000000000000846158b396039160801b16615beb565b614017565b9061594c91615b6e565b0391156159db57806159826fffffffffffffffffffffffffffffffff700100000000000000000000000000000000931684615aba565b92091515016fffffffffffffffffffffffffffffffff81116159b3576fffffffffffffffffffffffffffffffff1690565b7f59d2b24a000000000000000000000000000000000000000000000000000000005f5260045ffd5b906fffffffffffffffffffffffffffffffff6159f8921690615aba565b6fffffffffffffffffffffffffffffffff81116159b3576fffffffffffffffffffffffffffffffff1690565b60401b90680100000000000000000380820491061515016fffffffffffffffffffffffffffffffff8111615a67576fffffffffffffffffffffffffffffffff1690565b7f0d88f526000000000000000000000000000000000000000000000000000000005f5260045ffd5b6f80000000000000000000000000000000811015615aad57600f0b90565b6335278d125f526004601cfd5b81810291808284041482151715615ad357505060801c90565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff910981811082019003908160801c15615b145763ae47f7025f526004601cfd5b60801c9060801b0190565b908015615b3157808204910615150190565b6365244e4e5f526004601cfd5b929190615b4c828286615beb565b9309615b5457565b90600101908115615b6157565b63ae47f7025f526004601cfd5b615ba6615bd89160607fffffffffffffffffffffffffffffffffffffffff3fffffffffffffffffffffff82169160591c166002011b90565b9160607fffffffffffffffffffffffffffffffffffffffff3fffffffffffffffffffffff82169160591c166002011b90565b9081811881808411820281189310021891565b81810292918115828504821417830215615c06575050900490565b807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8492840985811086019003920990825f0383169281811115615b615783900480600302600218808202600203028082026002030280820260020302808202600203028082026002030280910260020302936001848483030494805f030401921190030217029056fea2646970667358221220e4f7b87ac02c1c54159fbd8c9c53944a24ad0f260c7bc93c967e23f6d37c71b964736f6c634300081c003300000000000000000000000000000c771f6176268d5a9846e0956c3ef58597a1

Deployed Bytecode

0x6103006040526004361015610070575b3615610019575f80fd5b6100216150b3565b506fffffffffffffffffffffffffffffffff34116100485761004690345f0390614e8c565b005b7f9cac58ca000000000000000000000000000000000000000000000000000000005f5260045ffd5b5f6101a0525f3560e01c805f14612d0f57806303a65ab614612c6b57806305d7e69414612ba25780630c11dedd146129b95780630e7f26391461298e578063101e89521461287f5780632569296214612807578063380eb4e0146127955780633d5125141461269b57806354d1f13d1461262557806355f48d0114611877578063624ae7e314611681578063645ec9b5146111b457806366e064a814611172578063715018a6146110c95780638da5cb5b14611056578063acdf754f14610ea0578063c05302441461098b578063de6f935f146105d6578063e96404f81461046c578063ed832830146103fa578063f04e283e14610385578063f2fde38b14610322578063f83d08ba146101e25763fee81cf40361000f57346101db5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576101bf61393e565b63389a75e1600c526101a05152602080600c2054604051908152f35b6101a05180fd5b346101db577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36016101a05181126101db577f07cc7f5195d862f505d6b095c82f92e00cfc1766f5bca4383c28dc5fca1555fd5c8060a01c90336001830160a01b177f07cc7f5195d862f505d6b095c82f92e00cfc1766f5bca4383c28dc5fca1555fd5d604051927fb45a3c0e000000000000000000000000000000000000000000000000000000008452826004850152600460248501376101a05180366020018582335af115610316577f07cc7f5195d862f505d6b095c82f92e00cfc1766f5bca4383c28dc5fca1555fd5d807f7772acfd7e0f66ebb20a058830296c3dc1301b111d23348e1c961d324223190d015c61030357503d6101a051823e3d90f35b639731ba376101a051526020526024601cfd5b823d6101a051823e3d90fd5b60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db5761035461393e565b61035c615144565b8060601b156103755761036e90615309565b6101a05180f35b637448fbae6101a051526004601cfd5b60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576103b761393e565b6103bf615144565b63389a75e1600c52806101a051526020600c2090815442116103ea5761036e916101a0519055615309565b636f5e88186101a051526004601cfd5b346101db577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36016101a05181126101db5760045b36811061043d57506101a051f35b80355c7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc82015260200161042f565b60a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db5761049f36613984565b6104a7613a3b565b906104b0613a1c565b906104b9613ca0565b73ffffffffffffffffffffffffffffffffffffffff808460349694960151169116036101db577ff7e050d866774820d81a86ca676f3afe7bc72603ee893f82e99c08fbde39af6c9361055a6060946fffffffffffffffffffffffffffffffff73ffffffffffffffffffffffffffffffffffffffff602088882097878717610572575b61054d84848351169816809887614e26565b0151169416938491614f0c565b60405192835260208301526040820152a16101a05180f35b886101a051526002825260406101a051205460801c80610593575b5061053b565b60038352878960406101a05120916105c6575b6105b1575b5061058d565b600101908960801b0481540190558b806105ab565b828a60801b0482540182556105a6565b346101db576101007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db57604051610612816138c4565b60043580151581036101db57815260243580151581036101db57602082015260443580151581036101db57604082015260643580151581036101db57606082015261065b613a0d565b608082015260a43580151581036101db5760a082015260c43580151581036101db5760c082015260e43580151581036101db5760e082015261069b61538a565b506106a461538a565b5060013360981c1615906040516106ba816138c4565b82158082523360981c6080818116151560208086019190915260408084161515908601528216151560608501526010821615159084015260088116151560a084015260048116151560c0840152600216151560e09092019190915281511515149081610972575b81610959575b81610940575b81610927575b8161090e575b816108f5575b816108dd575b501590811561083a575b5061080c57336101a051526101a05160205260ff60406101a0512054166107de57336101a051526101a05160205260406101a0512060017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff008254161790557fec1256266e470abb868620c851f6bde2a3ff602549dcad318ab9ccfcb2977f146020604051338152a16101a05180f35b7f8b20f687000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b7f7865ebfd000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b801591506108ce575b80156108bf575b80156108b0575b80156108a1575b8015610892575b8015610883575b8015610874575b158161074f565b5060023360981c16151561086d565b5060043360981c161515610866565b5060083360981c16151561085f565b5060103360981c161515610858565b5060203360981c161515610851565b5060403360981c16151561084a565b5060803360981c161515610843565b60e091500151151560023360981c1615151482610745565b905060c0810151151560043360981c161515149061073f565b905060a0810151151560083360981c1615151490610739565b90506080810151151560103360981c1615151490610733565b90506060810151151560203360981c161515149061072d565b90506040810151151560403360981c1615151490610727565b90506020810151151560803360981c1615151490610721565b346101db5760807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576109c336613984565b606435600381900b91908281036101db5773ffffffffffffffffffffffffffffffffffffffff82511673ffffffffffffffffffffffffffffffffffffffff6020840151161115610e7257620aa8ed63ffffffff83604001511611610e445781603401519273ffffffffffffffffffffffffffffffffffffffff84169182610d1c575b6060842094856101a05152600260205260406101a0512060405190610a698261385f565b549060406bffffffffffffffffffffffff8316928383528060601c60030b602084015260801c910152610cee577f5e4688b340694b7c7fd30047fd082117dc46e32acfbf81a44bb1fac0ae65154d60c0610ac460019461404e565b97610bae6bffffffffffffffffffffffff6040519a610ae28c61385f565b16998a81526fffffffffffffffffffffffffffffffff6020820189815260408301906101a0518252856101a0515260026020526bffffffffffffffffffffffff60406101a051209451167fffffffffffffffffffffffffffffffff000000000000000000000000000000008554925160601b6fffffffff0000000000000000000000001692161717835551166fffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffff0000000000000000000000000000000083549260801b169116179055565b604051908152610c0160208201896040809173ffffffffffffffffffffffffffffffffffffffff815116845273ffffffffffffffffffffffffffffffffffffffff60208201511660208501520151910152565b8560808201528860a0820152a1609f1c1680610ce4575b610c28575b602084604051908152f35b813b156101db57604080517f948374ff000000000000000000000000000000000000000000000000000000008152336004820152845173ffffffffffffffffffffffffffffffffffffffff90811660248301526020860151166044820152930151606484015260848301528260a48301528160c4816101a051936101a051905af18015610cd657610cbb575b8080610c1d565b6101a051610cc8916138fd565b6101a0516101db5781610cb4565b6040513d6101a051823e3d90fd5b5033821415610c18565b7f7983c051000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b826101a051526101a05160205260ff60406101a05120541615610e165760018560981c1680610e0c575b15610a4557823b156101db576040517f1fbbb462000000000000000000000000000000000000000000000000000000008152336004820152610dcb60248201866040809173ffffffffffffffffffffffffffffffffffffffff815116845273ffffffffffffffffffffffffffffffffffffffff60208201511660208501520151910152565b8260848201526101a0518160a4816101a051885af18015610cd657610df1575b50610a45565b6101a051610dfe916138fd565b6101a0516101db5785610deb565b5033831415610d46565b7fcd72c3bc000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b7f270815a0000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b7f88a2efcf000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b346101db5760a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db57610ed761393e565b610edf613961565b610ee7613a3b565b90610ef0613a1c565b91610ef96150b3565b5092610f4e60443573ffffffffffffffffffffffffffffffffffffffff851673ffffffffffffffffffffffffffffffffffffffff88163391608093916040519384526020840152604083015260608201522090565b94856101a05152600860205260406101a0512054906fffffffffffffffffffffffffffffffff8260801c9216916fffffffffffffffffffffffffffffffff851690818110801561103b575b61100d577fffffffffffffffffffffffffffffffff000000000000000000000000000000006fffffffffffffffffffffffffffffffff9687876110019761036e9d6101a0515260086020520316920360801b160160406101a05120556101a051039086614f0c565b166101a0510391614f0c565b7f7b3df0ec000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b506fffffffffffffffffffffffffffffffff85168410610f99565b346101db576101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db5760207fffffffffffffffffffffffffffffffffffffffffffffffffffffffff748739275473ffffffffffffffffffffffffffffffffffffffff60405191168152f35b6101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576110fd615144565b6101a0517fffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a36101a0517fffffffffffffffffffffffffffffffffffffffffffffffffffffffff7487392781905580f35b346101db5761119d61118336613ab5565b926101a09291925152600760205260406101a05120613ebb565b6040805160039390930b8352901515602083015290f35b346101db5760c07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576111ec36613984565b6064356111f836613a5a565b90611201613ca0565b91909380603401519373ffffffffffffffffffffffffffffffffffffffff851692600186609a1c1680611661575b61159e575b6060832095604051966112468861385f565b828852602088019673ffffffffffffffffffffffffffffffffffffffff1696878152604089019085825261128a8a604080918181205f5201512060205260405f2090565b99836101a0515260046020526101a051604090208b6101a051526020526101a051604090206112b890613c3d565b9b8c9b896040015163ffffffff166112d1908a88614fd2565b9d8e6112dc916152bf565b9e909d516fffffffffffffffffffffffffffffffff169160405192611300846138a8565b835260208301918252876101a0515260046020526101a05160409020906101a051526020526101a0516040902091516fffffffffffffffffffffffffffffffff166fffffffffffffffffffffffffffffffff1682547fffffffffffffffffffffffffffffffff00000000000000000000000000000000161782555180516001830155602001519060020155885173ffffffffffffffffffffffffffffffffffffffff169b6fffffffffffffffffffffffffffffffff169b6113c08d613c74565b6113ca9183614f0c565b602089015173ffffffffffffffffffffffffffffffffffffffff169c6fffffffffffffffffffffffffffffffff169c6114028e613c74565b9061140c92614f0c565b6040519384525160208401525173ffffffffffffffffffffffffffffffffffffffff16604083015251606082016114529160208091805160030b8452015160030b910152565b8760a08201528860c082015260e07fbb3992d83c721f12a8f32242e0d21c3613949c6a69d2a35deecdf6943a61c8b291a160991c60011680611594575b6114a4575b6040868882519182526020820152f35b833b156101db5761152861154793604051967fcdd0fa0e000000000000000000000000000000000000000000000000000000008852600488015260248701906040809173ffffffffffffffffffffffffffffffffffffffff815116845273ffffffffffffffffffffffffffffffffffffffff60208201511660208501520151910152565b608485015260a484019060208091805160030b8452015160030b910152565b8260e48301528361010483015281610124816101a051936101a051905af18015610cd657611579575b80808080611494565b6101a051611586916138fd565b6101a0516101db5782611570565b508385141561148f565b833b156101db57604080517f6fb5bfe300000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8781166004830152855181166024830152602086015116604482015290840151606482015281608482015261162960a482018460208091805160030b8452015160030b910152565b6101a0518160e48183895af18015610cd657611646575b50611234565b6101a051611653916138fd565b6101a0516101db5787611640565b508373ffffffffffffffffffffffffffffffffffffffff8616141561122f565b60c07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576116b361393e565b6116bb613961565b9060443573ffffffffffffffffffffffffffffffffffffffff8116918282036101db576116e6613a1c565b936101a0515060a435906fffffffffffffffffffffffffffffffff8216948583036101db5773ffffffffffffffffffffffffffffffffffffffff821693818510156118495761177191611737613ca0565b509573ffffffffffffffffffffffffffffffffffffffff606435931691608093916040519384526020840152604083015260608201522090565b806101a0515260086020526fffffffffffffffffffffffffffffffff6117d360406101a051205494827fffffffffffffffffffffffffffffffff000000000000000000000000000000006117c88c8960801c613ba0565b60801b169616613ba0565b1683018093116118165761036e96611811936fffffffffffffffffffffffffffffffff926101a05152600860205260406101a0512055169083614e26565b614f0c565b7f4e487b71000000000000000000000000000000000000000000000000000000006101a05152601160045260246101a051fd5b7f5b0110b2000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b60e07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576118aa36613984565b60807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9c3601126101db57604051906118e18261385f565b60643582526118ef36613a5a565b602083015260c435600f81900b81036101db5760408301526101a05191829190611917613ca0565b929091816034015192600184609c1c16806125ef575b612515575b6020820151604084015163ffffffff16806123f157507ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffab6326d815160030b14908115916123db575b506123ad575b6040820151600f0b611b0c575b50600183609b1c1680611ad6575b6119b3575b60408051600f87810b825288900b6020820152f35b73ffffffffffffffffffffffffffffffffffffffff83163b156101db57611a63611a6d9273ffffffffffffffffffffffffffffffffffffffff604051967f3c85e5a100000000000000000000000000000000000000000000000000000000885216600487015260248601906040809173ffffffffffffffffffffffffffffffffffffffff815116845273ffffffffffffffffffffffffffffffffffffffff60208201511660208501520151910152565b6084840190613c08565b82600f0b61010483015283600f0b61012483015281610144816101a0519373ffffffffffffffffffffffffffffffffffffffff6101a05191165af18015610cd657611abb575b80808061199e565b6101a051611ac8916138fd565b6101a0516101db5782611ab3565b5073ffffffffffffffffffffffffffffffffffffffff831673ffffffffffffffffffffffffffffffffffffffff85161415611999565b945094506060812094856101a05152600260205260406101a051209460405195611b358761385f565b546bffffffffffffffffffffffff8116908188528060601c60030b602089015260801c60408801521561237f57611ba8611b7660208401515160030b61404e565b611b89602080860151015160030b61404e565b906bffffffffffffffffffffffff8951166040860151600f0b9061518d565b96909787988098855191602087015160405193611bc48561385f565b845273ffffffffffffffffffffffffffffffffffffffff8b16602085015260408401526101a0516040880151600f0b126121ef575b5050611c1590604080918181205f5201512060205260405f2090565b816101a05152600460205260406101a05120906101a0515260205260406101a05120611c51602086015163ffffffff8860400151169084614fd2565b611c6381611c5e84613c3d565b6152bf565b91611c896fffffffffffffffffffffffffffffffff85541660408a0151600f0b90614d75565b6fffffffffffffffffffffffffffffffff81161561212a5791611d0a91836002956fffffffffffffffffffffffffffffffff602096167fffffffffffffffffffffffffffffffff000000000000000000000000000000008954161788558160405194611cf4866138a8565b608090811b9190910485521b0484830152614dc8565b8051600185015501519101555b604085015163ffffffff16156120d95760208401515160030b9263ffffffff866040015116936040860151600f0b936101a05150836101a05152600560205260406101a051208260030b5f5260205260405f2095865496611d7b878960801c614d75565b906f7fffffffffffffffffffffffffffffff600f8a900b89019081137fffffffffffffffffffffffffffffffff8000000000000000000000000000000090911217611816577fa2d4008be4187c63684f323788e131e1370dbc2205499befe2834005a00c792c9861010098602096611e5b956fffffffffffffffffffffffffffffffff861615608085901c150361209d575b505060809390931b7fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff600f9290920b9390930116919091179055565b611f1b8280890151015160030b63ffffffff8a60400151169060408a0151600f0b876101a051526005865260406101a051208260030b5f52865260405f2091825493611eb88560801c93611eaf8186614d75565b96600f0b613b2c565b926fffffffffffffffffffffffffffffffff861615901503612061575b505060809290921b7fffffffffffffffffffffffffffffffff00000000000000000000000000000000166fffffffffffffffffffffffffffffffff909216919091179055565b015160030b602086015190815160030b8112159182612050575b5050611fce575b73ffffffffffffffffffffffffffffffffffffffff865116611f638a600f0b809284614e26565b611f8e73ffffffffffffffffffffffffffffffffffffffff602089015116928c600f0b938491614f0c565b6040519273ffffffffffffffffffffffffffffffffffffffff8a1684526020840152611fbd6040840187613c08565b60c083015260e0820152a18661198b565b816101a05152600260205261204b611ff860406101a051205460801c6040880151600f0b90614d75565b836101a05152600260205260406101a05120906fffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffff0000000000000000000000000000000083549260801b169116179055565b611f3c565b6020015160030b1390508b80611f35565b61207c908a6101a051526007895260406101a05120926153c6565b91906101a05152875260406101a051209060018254911b1890555f80611ed5565b6120b8908b6101a0515260078a5260406101a05120926153c6565b91906101a05152885260406101a051209060018254911b1890555f80611e0d565b61010091507fa2d4008be4187c63684f323788e131e1370dbc2205499befe2834005a00c792c92816101a05152600260205261204b611ff860406101a051205460801c6040880151600f0b90614d75565b50506fffffffffffffffffffffffffffffffff1615908115916121d3575b506121a5577fffffffffffffffffffffffffffffffff00000000000000000000000000000000815416815560405161217f816138a8565b6101a051815260206101a0519101526101a051600182015560026101a051910155611d17565b7fea22ccd0000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b6fffffffffffffffffffffffffffffffff91501615158b612148565b67ffffffffffffffff88603c015116908161220b575b50611bf9565b6fffffffffffffffffffffffffffffffff67ffffffffffffffff83836101a051038316020160401c166122ee575b506fffffffffffffffffffffffffffffffff67ffffffffffffffff82846101a051038316020160401c1661226e575b80612205565b611c15929b5067ffffffffffffffff6fffffffffffffffffffffffffffffffff9173ffffffffffffffffffffffffffffffffffffffff60208b0151166101a05152600160205260406101a05120838383876101a051038316020160401c168154019055836101a051038316020160401c16600f0b01600f0b99908b612268565b909a5073ffffffffffffffffffffffffffffffffffffffff8851166101a05152600160205260406101a051206fffffffffffffffffffffffffffffffff67ffffffffffffffff8d846101a051038316020160401c1681540190556fffffffffffffffffffffffffffffffff67ffffffffffffffff8c836101a051038316020160401c16600f0b01600f0b998c612239565b7f486aa307000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b7fe5e15e5d000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b630549cd9391506020015160030b141588611978565b90805160030b916020820192835160030b13156124e7577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffab6326d825160030b1280156124d6575b6124a85761244c9060030b80925160030b61517b565b60030b159182159261248e575b50501561197e577f89fd41b1000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b61249c92505160030b61517b565b60030b15158880612459565b7fabfa4a31000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b50630549cd93835160030b13612436565b7f68651c5c000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b73ffffffffffffffffffffffffffffffffffffffff84163b156101db57604080517fb14b106d00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff878116600483015285518116602483015260208601511660448201529084015160648201526125a06084820184613c08565b6101a05181610104818373ffffffffffffffffffffffffffffffffffffffff8a165af18015610cd6576125d4575b50611932565b6101a0516125e1916138fd565b6101a0516101db57876125ce565b5073ffffffffffffffffffffffffffffffffffffffff841673ffffffffffffffffffffffffffffffffffffffff8616141561192d565b6101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db5763389a75e1600c52336101a051526101a0516020600c2055337ffa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c926101a0516101a051a26101a05180f35b346101db5760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576126d261393e565b6126da613961565b90604435906126e7615144565b73ffffffffffffffffffffffffffffffffffffffff831691826101a05152600160205260406101a0512092835494828603958611611816577f8fc241308ffc17817e6a8c6a52a8f7cd4931dfca0c539fd35a630311c7e4c57b9560609555828483155f14612787576127599250614fb6565b73ffffffffffffffffffffffffffffffffffffffff6040519316835260208301526040820152a16101a05180f35b61279092614f5c565b612759565b346101db577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36016101a05181126101db5760045b3681106127d857506101a051f35b8035547ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc8201526020016127ca565b6101a0517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db5763389a75e1600c52336101a051526202a30042016020600c2055337fdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d6101a0516101a051a26101a05180f35b346101db5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576128b661393e565b6128be613ca0565b90916001830160a01b908082177f07cc7f5195d862f505d6b095c82f92e00cfc1766f5bca4383c28dc5fca1555fd5d604051937f64919dea00000000000000000000000000000000000000000000000000000000855260048501528260248501527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc3601602460448601376101a0519081906020360190869083905af11561031657177f07cc7f5195d862f505d6b095c82f92e00cfc1766f5bca4383c28dc5fca1555fd5d3d6101a051823e3d90f35b346101db5761119d61299f36613ab5565b926101a09291925152600760205260406101a05120613cf1565b346101db5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db576129f061393e565b7fe1be600102d456bf2d4dee36e1641404df82292916888bf32557e00dfe1664125c612b925760017fe1be600102d456bf2d4dee36e1641404df82292916888bf32557e00dfe1664125d612a426150b3565b5090604051306014526f70a082310000000000000000000000006101a0515260208160246010855afa601f3d1116815102907f599d07140000000000000000000000000000000000000000000000000000000081528360048201528260248201527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc3601602460448301376101a05180602036018382335af115612b87575060208060246010855afa601f3d111660205102818110612b7757036fffffffffffffffffffffffffffffffff8111612b67576020926fffffffffffffffffffffffffffffffff612b39921692836101a0510391614f0c565b6101a0517fe1be600102d456bf2d4dee36e1641404df82292916888bf32557e00dfe1664125d604051908152f35b639cac58ca6101a051526004601cfd5b6301b243b96101a051526004601cfd5b3d6101a051823e3d90fd5b63ced108be6101a051526004601cfd5b346101db5760a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db57612bda36613984565b6040367fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9c01126101db5760405190612c11826138a8565b606435600381900b81036101db57825260843590600382900b82036101db5782612c599260206040950152612c44613bf0565b5063ffffffff60608320928501511691614fd2565b60208251918051835201516020820152f35b346101db5760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101db57612ca261393e565b612caa613961565b6044356fffffffffffffffffffffffffffffffff811691908290036101db57612cdc8284612cd6613ca0565b50614f0c565b73ffffffffffffffffffffffffffffffffffffffff8316612d015761036e9250614fb6565b612d0a92614f5c565b61036e565b60e07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126137fd57612d4236613984565b606435610160819052600f81900b90036137fd57612d5e613a0d565b6bffffffffffffffffffffffff60a4351660a435036137fd575f905f926bffff9a5889f795069a41a8a360a435111567400065a8177fae2760a435101516673fffffffffffffff7fffffffffffffffffffffffffffffffffffffffff3fffffffffffffffffffffff60a4351611161561383757612dd9613ca0565b906101005291816034015191600183609e1c1680613801575b6136fc575b606080822060808181526101a0805160e081815293905260026020525160409020549081901c9091526bffffffffffffffffffffffff8116911c60030b81801561237f5761016051600f0b612fa2575b505050600183609d1c1680612f6c575b612e705760408051600f87810b825288900b6020820152f35b73ffffffffffffffffffffffffffffffffffffffff83163b156101db57604080517fc0578abb00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff9586166004820152825186166024820152602083015190951660448601520151606484015261016051600f0b6084840152151560a48301526bffffffffffffffffffffffff60a4351660c483015260c43560e483015282600f0b61010483015283600f0b61012483015281610144816101a0519373ffffffffffffffffffffffffffffffffffffffff6101a05191165af18015610cd657611abb5780808061199e565b5073ffffffffffffffffffffffffffffffffffffffff831673ffffffffffffffffffffffffffffffffffffffff85161415612e57565b91965092949196506101a051610160511285185f146136b75760a4356bffffffffffffffffffffffff1610613689575b61016051610180526101a05160c081905260a081905260408701519093906bffffffffffffffffffffffff1661365a575b9491925b61018051600f0b15158061363c575b15613451576101a05161014081905261012052613031613b08565b50604087015163ffffffff16156133f6576101a051610160511285146133c1576080516101a05152600760205261307e60406101a0512060c435908663ffffffff8b604001511691613ebb565b9390935b6101405261308f8461404e565b610120525b6101a051610160511286146133a3576130dc6101205160a4351060a43561012051180261012051185b8767ffffffffffffffff8b603c01511691610180519060e05186614504565b9160e051606084015160801b0401946130fc8351600f0b61018051613b2c565b610180526131226fffffffffffffffffffffffffffffffff60208501511660c051613ba0565b60c0526040830151610120516bffffffffffffffffffffffff9182169116810361336b57505050604001516101a051610160516bffffffffffffffffffffffff90921696911285146132e257825b9261014051613184575b505b949192613007565b6080516101a05152600560205260406101a051208160030b5f5260205260405f2054600f0b6101a051506101a051610160511287185f14613280576131cb9060e051614d75565b60e0526080516101a05152600660205260406101a051208160030b5f5260205261324a6131fa60405f20613bd2565b604051613206816138a8565b5f81525f6020820152876101a05161016051128a1860051b8201526101a05161016051128914806101a05161016051128b1860a0510301549060051b820152614dc8565b906080516101a05152600660205260406101a051209060030b5f526020526001602060405f20928051845501519101558761317a565b7fffffffffffffffffffffffffffffffff000000000000000000000000000000008160e05103166132b45760e051036131cb565b7f6d862c50000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8360030b01637fffffff81137fffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000000082121715613170577f4e487b71000000000000000000000000000000000000000000000000000000006101a05152601160045260246101a051fd5b919790945091506bffffffffffffffffffffffff871681900361338f575b5061317c565b9550915061339c856148c8565b9187613389565b6130dc6101205160a4351160a43561012051180261012051186130bd565b6080516101a0515260076020526133ee60406101a0512060c435908663ffffffff8b604001511691613cf1565b939093613082565b6101a0516101605112851461342257630549cd936bffff9a5889f795069a41a8a35b6101205292613094565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffab6326d67400065a8177fae27613418565b959093919492946135116fffffffffffffffffffffffffffffffff60c051166101a05161016051600f0b12157ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe02600118027fffffffffffffffffffffffffffffffff800000000000000000000000000000008113907fffffffffffffffffffffffffffffffff8000000000000000000000000000000018027fffffffffffffffffffffffffffffffff8000000000000000000000000000000018614df8565b8315613627579060749196610180516101605103600f0b915b8299896080516101a05152600260205260e05160801b91826fffffffff0000000000000000000000008660601b1685010160406101a05120556bffffffffffffffffffffffff88604001511661361d575b506135a573ffffffffffffffffffffffffffffffffffffffff88511682600f0b9061010051614e26565b6135d173ffffffffffffffffffffffffffffffffffffffff60208901511686600f0b9061010051614f0c565b6fffffffffffffffffffffffffffffffff604051958b60601b87526080516014880152169060801b176034850152605484015260a01b606483015260e01b6070820152a0868080612e47565b60a051558c61357b565b610180516101605103600f0b9660749261352a565b506bffffffffffffffffffffffff83811660a4359091161415613016565b92506080516101a0515260036020526101a0516101605112841860406101a051200160a05260a0515492613003565b7fa574a6b4000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b60a4356bffffffffffffffffffffffff161115612fd2577fa574a6b4000000000000000000000000000000000000000000000000000000006101a0515260046101a051fd5b73ffffffffffffffffffffffffffffffffffffffff83163b156137fd57604080517f3c65c87a00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8681166004830152835181166024830152602084015116604482015290820151606482015261016051600f0b608482015282151560a48201526bffffffffffffffffffffffff60a4351660c482015260c43560e48201525f81610104818373ffffffffffffffffffffffffffffffffffffffff89165af180156137f2576137dd575b50612df7565b5f6137e7916138fd565b5f6101a052866137d7565b6040513d5f823e3d90fd5b5f80fd5b5073ffffffffffffffffffffffffffffffffffffffff831673ffffffffffffffffffffffffffffffffffffffff85161415612df2565b7f9cc3dd4a000000000000000000000000000000000000000000000000000000005f5260045ffd5b6060810190811067ffffffffffffffff82111761387b57604052565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6040810190811067ffffffffffffffff82111761387b57604052565b610100810190811067ffffffffffffffff82111761387b57604052565b6080810190811067ffffffffffffffff82111761387b57604052565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff82111761387b57604052565b6004359073ffffffffffffffffffffffffffffffffffffffff821682036137fd57565b6024359073ffffffffffffffffffffffffffffffffffffffff821682036137fd57565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc60609101126137fd57604051906139bb8261385f565b8160043573ffffffffffffffffffffffffffffffffffffffff811681036137fd57815260243573ffffffffffffffffffffffffffffffffffffffff811681036137fd5760208201526040604435910152565b6084359081151582036137fd57565b608435906fffffffffffffffffffffffffffffffff821682036137fd57565b606435906fffffffffffffffffffffffffffffffff821682036137fd57565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7c60409101126137fd5760405190613a91826138a8565b816084358060030b81036137fd57815260a435908160030b82036137fd5760200152565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc60809101126137fd57600435906024358060030b81036137fd579060443563ffffffff811681036137fd579060643590565b60405190613b15826138e1565b5f6060838281528260208201528260408201520152565b90600f0b90600f0b03906f7fffffffffffffffffffffffffffffff82137fffffffffffffffffffffffffffffffff80000000000000000000000000000000831217613b7357565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b906fffffffffffffffffffffffffffffffff809116911601906fffffffffffffffffffffffffffffffff8211613b7357565b90604051613bdf816138a8565b602060018294805484520154910152565b60405190613bfd826138a8565b5f6020838281520152565b604060609180518452613c336020820151602086019060208091805160030b8452015160030b910152565b0151600f0b910152565b90604051613c4a816138a8565b6020613c6f600183956fffffffffffffffffffffffffffffffff815416855201613bd2565b910152565b7f80000000000000000000000000000000000000000000000000000000000000008114613b73575f0390565b613ca86150b3565b90913373ffffffffffffffffffffffffffffffffffffffff831603613cc957565b7feed0f119000000000000000000000000000000000000000000000000000000005f5260045ffd5b919091613cff825f946153c6565b815f52826020527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60018060ff60405f20549416011b01167f07060605060205040602030205040301060502050303040105050304000000006f8421084210842108cc6318c6db6d54be826fffffffffffffffffffffffffffffffff1060071b831560081b1783811c67ffffffffffffffff1060061b1783811c63ffffffff1060051b1783811c61ffff1060041b1783811c60ff1060031b1792831c1c601f161a176101008103613e8757507ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaab8881839160081b0102937ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffab6326d8560030b1315613e5e578015613e5757827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80613cff9301960160030b6153c6565b5050509091565b50505090507ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffab6326d91565b915093507ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaab888191925060019360081b01010291565b919091613ed8825f945b63ffffffff821660030b0160030b6153c6565b815f52826020527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff600160ff60405f205493161b0119166001811901167e1f0d1e100c1d070f090b19131c1706010e11080a1a141802121b1503160405601f6101e07f804040554300526644320000502061067405302602000010750620017611707760fc7fb6db6db6ddddddddd34d34d349249249210842108c6318c639ce739cffffffff860260f81c161b60f71c1692831c63d76453e004161a176101008103613e8757507ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaab8980839160081b010293630549cd938560030b121561400a578015613e5757827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff613ed8920195613ec5565b5050509050630549cd9391565b8115614021570490565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b60030b8060ff1d8082011890630549cd9382116144a7576d08637b66cd638344daef276cd7c5600183160270010000000000000000000000000000000003916002811661448b575b6004811661446f575b60088116614453575b60108116614437575b6020811661441b575b604081166143ff575b608081166143e3575b61010081166143c7575b61020081166143ab575b610400811661438f575b6108008116614373575b6110008116614357575b612000811661433b575b614000811661431f575b6180008116614303575b6201000081166142e7575b6202000081166142cb575b6204000081166142af575b620800008116614293575b621000008116614277575b62200000811661425b575b62400000811661423f575b628000008116614223575b63010000008116614208575b630200000081166141ee575b6304000000166141d7575b5f126141aa575b6141a7906153e3565b90565b8015614021577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0461419e565b69c0d55d4d7152c25fb13990910260801c90614197565b6cde2ee4bc381afa7089aa84bb6690920260801c9161418c565b916e0ee7e32d61fdb0a5e622b820f681d00260801c91614180565b916f03dc5dac7376e20fc8679758d1bcdcfc0260801c91614174565b916f1f703399d88f6aa83a28b22d4a1f56e30260801c91614169565b916f59b63684b86e9f486ec54727371ba6ca0260801c9161415e565b916f978bcb9894317807e5fa4498eee7c0fa0260801c91614153565b916fc4f76b68947482dc198a48a54348c4ed0260801c91614148565b916fe08d35706200796273f0b3a981d90cfd0260801c9161413d565b916fefc2bf59df33ecc28125cf78ec4f167f0260801c91614132565b916ff7bf5211c72f5185f372aeb1d48f937e0260801c91614127565b916ffbd701c7cbc4c8a6bb81efd232d1e4e70260801c9161411c565b916ffde95287d26d81bea159c37073122c730260801c91614112565b916ffef41d1a5f2ae3a20676bec6f7f9459a0260801c91614108565b916fff79eb706b9a64c6431d76e63531e9290260801c916140fe565b916fffbceceeb791747f10df216f2e53ec570260801c916140f4565b916fffde7444b28145508125d10077ba83b80260801c916140ea565b916fffef3995a5b6a6267530f207142a57640260801c916140e0565b916ffff79ca7a4d1bf1ee8556cea23cdbaa50260801c916140d6565b916ffffbce4b06c196e9247ac87695d53c600260801c916140cc565b916ffffde72350725cc4ea8feece3b5f13c80260801c916140c3565b916ffffef3911b7cff24ba1b3dbb5f8f59740260801c916140ba565b916fffff79c86a8f6150a32d9778eceef97c0260801c916140b1565b916fffffbce42c7be6c998ad6318193c0b180260801c916140a8565b916fffffde72140b00a354bd3dc828e976c90260801c9161409f565b916fffffef390978c398134b4ff3764fe4100260801c91614096565b7f073ee172000000000000000000000000000000000000000000000000000000005f5260045260245ffd5b906fffffffffffffffffffffffffffffffff809116911603906fffffffffffffffffffffffffffffffff8211613b7357565b9490939192614511613b08565b5080600f0b95861580156148a3575b614893575f8212808518916bffffffffffffffffffffffff8716956bffffffffffffffffffffffff8216968781119382149384150361486b576fffffffffffffffffffffffffffffffff8a1615614857575f8b129889156148255786955b83156148145761458f878d87615769565b955b816147fb575b81156147d6575b506146b75750506bffffffffffffffffffffffff83169680881461464757509787916fffffffffffffffffffffffffffffffff995f14614638576145e193615863565b945b156146245750506145ff6145f8859285615a24565b93846144d2565b925b6040519561460e876138e1565b8652166020850152604084015216606082015290565b85925061463091613b2c565b811692614601565b61464193615942565b946145e3565b9850505050509291505061468a576fffffffffffffffffffffffffffffffff9160405193614674856138e1565b84525f6020850152604084015216606082015290565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52600160045260245ffd5b989a5098935091509394508792505f146147b9576146e2926146dc8315838389615942565b95615863565b935b15614780576fffffffffffffffffffffffffffffffff61470761470e9286615a24565b9216615a8f565b600f0b917fffffffffffffffffffffffffffffffff800000000000000000000000000000008314613b73576fffffffffffffffffffffffffffffffff61475881945f0395846144d2565b925b60405195614767876138e1565b600f0b8652166020850152604084015216606082015290565b916fffffffffffffffffffffffffffffffff6147b36147a0829585615a24565b936147ac838616615a8f565b96946144d2565b9261475a565b6147d0926147ca8315838389615863565b95615942565b936146e4565b9050806147e4575b5f61459e565b50816bffffffffffffffffffffffff8616106147de565b9050826bffffffffffffffffffffffff87161190614597565b61481f878d876155fa565b95614591565b6fffffffffffffffffffffffffffffffff67ffffffffffffffff89898316020160401c16600f0b8703600f0b9561457e565b505050505050505090506141a791506155bf565b7fa574a6b4000000000000000000000000000000000000000000000000000000005f5260045ffd5b9450505050506141a791506155bf565b506bffffffffffffffffffffffff85166bffffffffffffffffffffffff821614614520565b7fffffffffffffffffffffffffffffffffffffffff3fffffffffffffffffffffff81166002605983901c606016011b908160801c1591825f14614d70578015614021577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff045b8060801c61026052610260516fffffffffffffffffffffffffffffffff1060071b61026051811c67ffffffffffffffff1060061b1761026051811c63ffffffff1060051b1761026051811c61ffff1060041b1761026051811c60ff1060031b176102005260017f07060605060205040602030205040301060502050303040105050304000000006f8421084210842108cc6318c6db6d54be61026051610200511c1c601f161a6102005117011c80026102c0526a1527370de4706fc9ea63ab6102c051607f1c6102c05160ff1c15151c800280607f1c8160ff1c15151c800280607f1c8160ff1c15151c800280607f1c8160ff1c15151c800280607f1c8160ff1c15151c80029182607f1c8360ff1c15151c80029384607f1c8560ff1c15151c80029586607f1c8760ff1c15151c800280607f1c8160ff1c15151c800280607f1c8160ff1c15151c800280607f1c8160ff1c15151c80029081607f1c8260ff1c15151c80029283607f1c8460ff1c15151c80029485607f1c8660ff1c15151c80026101c0526101c051607f1c6101c05160ff1c15151c80026102205261022051607f1c6102205160ff1c15151c80026102805261028051607f1c6102805160ff1c15151c6102e0526102e0516102e05102607f1c6102e0516102e0510260ff1c15151c6102a0526102a0516102a05102607f1c6102a0516102a0510260ff1c15151c61024052610240516102405102607f1c61024051610240510260ff1c15151c6101e0526101e0516101e05102607f1c6101e0516101e0510260ff1c15151c800260ff1c1515602a1b9c6101e0516101e0510260ff1c1515602b1b9c61024051610240510260ff1c1515602c1b9c6102a0516102a0510260ff1c1515602d1b9c6102e0516102e0510260ff1c1515602e1b9c6102805160ff1c1515602f1b9c6102205160ff1c151560301b9c6101c05160ff1c151560311b9c60ff1c151560321b9b60ff1c151560331b9a60ff1c151560341b9960ff1c151560351b9860ff1c151560361b9760ff1c151560371b9660ff1c151560381b9560ff1c151560391b9460ff1c1515603a1b9360ff1c1515603b1b9260ff1c1515603c1b9160ff1c1515603d1b9060ff1c1515603e1b6102c05160ff1c1515603f1b7f07060605060205040602030205040301060502050303040105050304000000006f8421084210842108cc6318c6db6d54be61026051610200511c1c601f161a610200511760401b01010101010101010101010101010101010101010101835f14614d6b575f035b029115614d45577fffffffffffffffffffffffffffffffffab6323c86e53680f6455c46fc9ea63ab820160801d60030b9160801d60030b905b8160030b8360030b14614d40576bffffffffffffffffffffffff80614d2d8461404e565b921691161115614d3b575090565b905090565b505090565b6f549cdc3791ac97f09baa3b9036159c558260801d60030b920160801d60030b90614d09565b614cd0565b61492e565b01907fffffffffffffffffffffffffffffffff000000000000000000000000000000008216614da057565b7f6d862c50000000000000000000000000000000000000000000000000000000005f5260045ffd5b919091602060405191614dda836138a8565b5f83525f828401528180849680518451038652015191015103910152565b806f800000000000000000000000000000000160801c15614e20576335278d125f526004601cfd5b600f0b90565b34614e385790614e369291614f0c565b565b906fffffffffffffffffffffffffffffffff34116100485773ffffffffffffffffffffffffffffffffffffffff8116614e795750614e369134900390614e8c565b614e3692614e879183614f0c565b345f03905b9080614e96575050565b7f3fee1dc3ade45aa30d633b5b8645760533723e46597841ef1126c6577a0917428260a01b015f5260205f2090815c90810192831580921518614ed9575b50505d565b7f7772acfd7e0f66ebb20a058830296c3dc1301b111d23348e1c961d324223190d0190801590825c0301905d5f80614ed4565b919081614f1857505050565b7f3fee1dc3ade45aa30d633b5b8645760533723e46597841ef1126c6577a091742908360a01b01015f5260205f2090815c90810192831580921518614ed95750505d565b91906014526034526fa9059cbb0000000000000000000000005f5260205f6044601082855af1908160015f51141615614f98575b50505f603452565b3b153d171015614fa9575f80614f90565b6390b8ec185f526004601cfd5b5f80809338935af115614fc557565b63b12d13eb5f526004601cfd5b909163ffffffff90604051614fe6816138a8565b5f81525f602082015250161561509e57805f52600260205260405f205460601c60030b90805f52600660205260405f2091835160030b60030b5f528260205261503160405f20613bd2565b926020850190815160030b60030b5f5260205261505060405f20613bd2565b945160030b82121561506957505050906141a791614dc8565b5160030b1315615094576141a7929161508f915f52600360205261508f60405f20613bd2565b614dc8565b506141a791614dc8565b90505f5260036020526141a760405f20613bd2565b7f07cc7f5195d862f505d6b095c82f92e00cfc1766f5bca4383c28dc5fca1555fd5c90811561511c5773ffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8360a01c01921690565b7f1834e265000000000000000000000000000000000000000000000000000000005f5260045ffd5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffff7487392754330361516e57565b6382b429005f526004601cfd5b9060030b9081156140215760030b0790565b90925f905f94600f0b9384156152b3575f8513936fffffffffffffffffffffffffffffffff85157ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe02600118968060ff1d8091011816936bffffffffffffffffffffffff82166bffffffffffffffffffffffff84168111155f1461523957505050926fffffffffffffffffffffffffffffffff9261522f926152369695615863565b1602614df8565b91565b929897509092916bffffffffffffffffffffffff8316111561528f57509282826152896fffffffffffffffffffffffffffffffff6152818582986141a79b9a61522f99615863565b168702614df8565b98615942565b9661522f9250926141a79594916fffffffffffffffffffffffffffffffff94615942565b5050505050505f905f90565b91906153056152e46fffffffffffffffffffffffffffffffff92602086015190614dc8565b93826020816152f888518286511690615aba565b1696015191511690615aba565b1690565b73ffffffffffffffffffffffffffffffffffffffff16807fffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a37fffffffffffffffffffffffffffffffffffffffffffffffffffffffff7487392755565b60405190615397826138c4565b5f60e0838281528260208201528260408201528260608201528260808201528260a08201528260c08201520152565b905f8183071291050390610100630554777f80840160081c930890565b6c0100000000000000000000000081106001146154bb5770010000000000000000000000000000000081106001146154a757740100000000000000000000000000000000000000008110600114615493577801000000000000000000000000000000000000000000000000811060011461547f577fa10459f4000000000000000000000000000000000000000000000000000000005f5260045ffd5b60621c6bc000000000000000000000001790565b60421c6b8000000000000000000000001790565b60221c6b4000000000000000000000001790565b60021c90565b6bfffffffffffffffffffffffd81106001146155b6576ffffffffffffffffffffffffc00000001811060011461559b5773fffffffffffffffffffffffc0000000000000001811060011461557c5777fffffffffffffffffffffffc0000000000000000000000018110600114615559577fa10459f4000000000000000000000000000000000000000000000000000000005f5260045ffd5b6c03ffffffffffffffffffffffff0160621c6bc000000000000000000000001790565b6803ffffffffffffffff0160421c6b8000000000000000000000001790565b6403ffffffff0160221c6b4000000000000000000000001790565b60030160021c90565b6155c7613b08565b506bffffffffffffffffffffffff604051916155e2836138e1565b5f83525f60208401521660408201525f606082015290565b9091600f0b908115615763576fffffffffffffffffffffffffffffffff83161561573b576156747fffffffffffffffffffffffffffffffff000000000000000000000000000000009160607fffffffffffffffffffffffffffffffffffffffff3fffffffffffffffffffffff82169160591c166002011b90565b9260801b16905f8160ff1d8083011891125f1461571d57821561402157827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04811161570a578202918183101561570a576156d192820391615b3e565b77fffffffffffffffffffffffc00000000000000000000000081116156f9576141a7906154c1565b506bffffffffffffffffffffffff90565b5050506bffffffffffffffffffffffff90565b906157369161572f6141a79483614017565b0190615b1f565b6154c1565b7fe0fbe467000000000000000000000000000000000000000000000000000000005f5260045ffd5b91505090565b91600f0b8015614d40576fffffffffffffffffffffffffffffffff821692831561583b576157c29060607fffffffffffffffffffffffffffffffffffffffff3fffffffffffffffffffffff82169160591c166002011b90565b915f6157d98360ff1d8085011860801b9586614017565b9212156157ff57828210156157f7576141a7930615159103036153e3565b505050505f90565b50810191508110801561581a575b6156f9576141a7906153e3565b5077ffffffffffffffffffffffffffffffffffffffffffffffff811161580d565b7f1043d0ac000000000000000000000000000000000000000000000000000000005f5260045ffd5b9061587091939293615b6e565b9290911561590757826158ae917fffffffffffffffffffffffffffffffff00000000000000000000000000000000846158b396039160801b16615b3e565b615b1f565b6fffffffffffffffffffffffffffffffff81116158df576fffffffffffffffffffffffffffffffff1690565b7fb4ef2546000000000000000000000000000000000000000000000000000000005f5260045ffd5b8261593d917fffffffffffffffffffffffffffffffff00000000000000000000000000000000846158b396039160801b16615beb565b614017565b9061594c91615b6e565b0391156159db57806159826fffffffffffffffffffffffffffffffff700100000000000000000000000000000000931684615aba565b92091515016fffffffffffffffffffffffffffffffff81116159b3576fffffffffffffffffffffffffffffffff1690565b7f59d2b24a000000000000000000000000000000000000000000000000000000005f5260045ffd5b906fffffffffffffffffffffffffffffffff6159f8921690615aba565b6fffffffffffffffffffffffffffffffff81116159b3576fffffffffffffffffffffffffffffffff1690565b60401b90680100000000000000000380820491061515016fffffffffffffffffffffffffffffffff8111615a67576fffffffffffffffffffffffffffffffff1690565b7f0d88f526000000000000000000000000000000000000000000000000000000005f5260045ffd5b6f80000000000000000000000000000000811015615aad57600f0b90565b6335278d125f526004601cfd5b81810291808284041482151715615ad357505060801c90565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff910981811082019003908160801c15615b145763ae47f7025f526004601cfd5b60801c9060801b0190565b908015615b3157808204910615150190565b6365244e4e5f526004601cfd5b929190615b4c828286615beb565b9309615b5457565b90600101908115615b6157565b63ae47f7025f526004601cfd5b615ba6615bd89160607fffffffffffffffffffffffffffffffffffffffff3fffffffffffffffffffffff82169160591c166002011b90565b9160607fffffffffffffffffffffffffffffffffffffffff3fffffffffffffffffffffff82169160591c166002011b90565b9081811881808411820281189310021891565b81810292918115828504821417830215615c06575050900490565b807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8492840985811086019003920990825f0383169281811115615b615783900480600302600218808202600203028082026002030280820260020302808202600203028082026002030280910260020302936001848483030494805f030401921190030217029056fea2646970667358221220e4f7b87ac02c1c54159fbd8c9c53944a24ad0f260c7bc93c967e23f6d37c71b964736f6c634300081c0033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

00000000000000000000000000000c771f6176268d5a9846e0956c3ef58597a1

-----Decoded View---------------
Arg [0] : owner (address): 0x00000C771F6176268D5A9846E0956C3eF58597A1

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 00000000000000000000000000000c771f6176268d5a9846e0956c3ef58597a1


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.