Skip to content
Verified contractPartialMIT

MoistSwapRouter

Address0x2e9c10de129c0ec06830c27a57fb268ecf4874c3
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.28

 

Same code

1 more contract

 

Details

Compiler
solc 0.8.28+commit.7893614a
Language
solidity
Optimization
Yes, 200 runs
EVM version
cancun
Via IR
yes
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,430,042
Creation transaction
0x6a7c53359d…791c13f9f0

contracts/MoistSwapRouter.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import {IPoolManager} from "v4-core/interfaces/IPoolManager.sol";
import {PoolKey} from "v4-core/types/PoolKey.sol";
import {Currency} from "v4-core/types/Currency.sol";
import {BalanceDelta, BalanceDeltaLibrary} from "v4-core/types/BalanceDelta.sol";

interface IMoistSwapRouterToken {
    function balanceOf(address account) external view returns (uint256);
    function transfer(address to, uint256 amount) external returns (bool);
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
}

interface IMoistSwapRouterWETH is IMoistSwapRouterToken {
    function deposit() external payable;
    function withdraw(uint256 amount) external;
}

interface IUniswapV3FactoryLike {
    function getPool(address tokenA, address tokenB, uint24 fee) external view returns (address pool);
}

interface IUniswapV3PoolLike {
    function swap(
        address recipient,
        bool zeroForOne,
        int256 amountSpecified,
        uint160 sqrtPriceLimitX96,
        bytes calldata data
    ) external returns (int256 amount0, int256 amount1);
}

interface IV2PairLike {
    function token0() external view returns (address);
    function token1() external view returns (address);
    function getReserves()
        external
        view
        returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data) external;
}

/// @dev Matches MoistUniswapV4Adapter/ FeeAdapter / OpenFeeAdapter exactInputSingle.
interface IMoistV4SwapAdapter {
    struct ExactInputSingleRequest {
        PoolKey key;
        bool zeroForOne;
        uint128 amountIn;
        uint128 amountOutMinimum;
        uint160 sqrtPriceLimitX96;
        uint256 deadline;
    }

    function exactInputSingle(ExactInputSingleRequest calldata request)
        external
        payable
        returns (uint256 amountIn, uint256 amountOut);
}

/// @dev One hop of an adapter-mediated multihop route. Field order must match
///      MoistUniswapV4Adapter.SwapHop.
struct V4RouteHop {
    PoolKey key;
    bool zeroForOne;
    uint160 sqrtPriceLimitX96;
}

/// @dev Multihop exact-input / exact-output on adapters that implement the
///      route entrypoints (MoistUniswapV4Adapter and subclasses).
interface IMoistV4SwapRouterAdapter {
    function exactInput(V4RouteHop[] calldata hops, uint256 amountIn, uint256 amountOutMinimum, uint256 deadline)
        external
        payable
        returns (uint256 spent, uint256 received);

    function exactOutput(V4RouteHop[] calldata hops, uint256 amountOut, uint256 maxAmountIn, uint256 deadline)
        external
        payable
        returns (uint256 spent, uint256 received);
}

/// @notice Stateless multi-venue swap router for Moistly EOAs, Safes, and modules.
/// @dev Exact-input only. Each hop names a venue and venue-specific data:
///      - V3: abi.encode(factory, fee) for any Uniswap V3 fork pool.
///      - V4: abi.encode(PoolKey, zeroForOne, sqrtPriceLimitX96) against the
///        immutable PoolManager. Native-currency V4 pools are not supported;
///        use the wrapped token.
///      - V4Adapter: abi.encode(adapter, PoolKey, zeroForOne, sqrtPriceLimitX96,
///        amountOutMinimum) routed through a MoistUniswapV4*Adapter's
///        exactInputSingle. The adapter must be allowlisted on the pool's hook
///        and this router must be an allowed hook account. ERC-20 only; the
///        adapter's per-hop minimum and the outer deadline apply, and its
///        output fee (if any) is already netted in the returned amountOut.
///      - V4AdapterRoute: abi.encode(adapter, V4RouteHop[] hops,
///        amountOutMinimum) routed through the adapter's multihop exactInput.
///        hops must form a contiguous ERC-20 path from tokenIn to tokenOut;
///        native currencies are rejected. Same approval lifecycle as V4Adapter.
///      swapExactOutV4Adapter is the exact-output counterpart: it pulls
///      maxAmountIn up front, calls the adapter's exactOutput, refunds the
///      unused input to msg.sender, and pays the output to `recipient`.
///      - V2: abi.encode(pair, feeBps) for constant-product pairs. Solidly-style
///        stable/volatile curves are not supported.
///      address(0) in the first hop's tokenIn wraps msg.value into WETH; in the
///      last hop's tokenOut it unwraps WETH and pays native to the recipient.
///      Intermediate hops must be ERC-20 (wrapped) tokens. Venue addresses inside
///      hop data are trusted inputs: use canonical factories, pairs, and PoolKeys.
///      The router holds funds only inside a single locked swap; leftover dust
///      is recoverable by the owner only.
contract MoistSwapRouter {
    using BalanceDeltaLibrary for BalanceDelta;

    enum Venue {
        V3,
        V4,
        V2,
        V4Adapter,
        V4AdapterRoute
    }

    struct Hop {
        Venue venue;
        address tokenIn;
        address tokenOut;
        bytes data;
    }

    uint160 private constant MIN_SQRT_RATIO = 4295128739;
    uint160 private constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342;

    address public immutable owner;
    address public immutable WETH;
    IPoolManager public immutable poolManager;

    uint256 private locked;

    error CallbackUnauthorized();
    error DeadlineExpired(uint256 deadline, uint256 timestamp);
    error EtherTransferFailed(address recipient, uint256 amount);
    error InvalidAddress();
    error InvalidAmount();
    error InvalidDelta();
    error InvalidHop();
    error InvalidPath();
    error InvalidPool();
    error InvalidReserves();
    error NativeValueMismatch();
    error NotOwner(address caller);
    error ReentrantCall();
    error SlippageExceeded(uint256 amountOutMinimum, uint256 amountOut);
    error TokenTransferFailed(address token);
    error UnsupportedVenue();

    event HopSwapped(
        uint256 indexed index,
        Venue indexed venue,
        address indexed tokenIn,
        address tokenOut,
        uint256 hopAmountIn,
        uint256 hopAmountOut
    );
    event SwapExecuted(
        address indexed sender,
        address indexed recipient,
        uint256 amountIn,
        uint256 amountOut,
        uint256 hops
    );
    event TokenRecovered(address indexed token, address indexed to, uint256 amount);
    event EtherRecovered(address indexed to, uint256 amount);

    modifier onlyOwner() {
        if (msg.sender != owner) revert NotOwner(msg.sender);
        _;
    }

    modifier lock() {
        if (locked != 0) revert ReentrantCall();
        locked = 1;
        _;
        locked = 0;
    }

    /// @dev Callbacks are only valid while a swap holds the lock.
    modifier inSwap() {
        if (locked != 1) revert CallbackUnauthorized();
        _;
    }

    constructor(address owner_, address weth_, IPoolManager poolManager_) {
        if (owner_ == address(0) || weth_ == address(0)) revert InvalidAddress();
        owner = owner_;
        WETH = weth_;
        poolManager = poolManager_; // address(0) disables V4 hops
    }

    receive() external payable {}

    /// @notice Execute an exact-input swap across one or more hops.
    /// @param hops Ordered hops; each hop's tokenOut must equal the next hop's tokenIn.
    /// @param recipient Final output recipient.
    /// @param amountIn Exact input amount in the first hop's tokenIn units.
    /// @param amountOutMinimum Minimum acceptable final output.
    /// @param deadline Latest block timestamp for execution.
    function swapExactIn(
        Hop[] calldata hops,
        address recipient,
        uint256 amountIn,
        uint256 amountOutMinimum,
        uint256 deadline
    ) external payable lock returns (uint256 amountOut) {
        if (block.timestamp > deadline) revert DeadlineExpired(deadline, block.timestamp);
        if (hops.length == 0 || recipient == address(0) || amountIn == 0) revert InvalidPath();
        _validatePath(hops);

        bool nativeIn = hops[0].tokenIn == address(0);
        bool nativeOut = hops[hops.length - 1].tokenOut == address(0);
        if (nativeIn) {
            if (msg.value != amountIn) revert NativeValueMismatch();
            IMoistSwapRouterWETH(WETH).deposit{value: amountIn}();
        } else if (msg.value != 0) {
            revert NativeValueMismatch();
        }

        if (!nativeIn) {
            _safeTransferFrom(_normalize(hops[0].tokenIn), msg.sender, address(this), amountIn);
        }

        uint256 amount = amountIn;
        for (uint256 i; i < hops.length; ++i) {
            Hop calldata hop = hops[i];
            uint256 hopAmountIn = amount;
            bool last = i == hops.length - 1;
            address to = last && !nativeOut ? recipient : address(this);
            amount = _executeHop(hop, amount, to, deadline);
            emit HopSwapped(i, hop.venue, _normalize(hop.tokenIn), _normalize(hop.tokenOut), hopAmountIn, amount);
        }

        if (amount < amountOutMinimum) revert SlippageExceeded(amountOutMinimum, amount);
        if (nativeOut) {
            IMoistSwapRouterWETH(WETH).withdraw(amount);
            (bool ok,) = payable(recipient).call{value: amount}("");
            if (!ok) revert EtherTransferFailed(recipient, amount);
        }
        emit SwapExecuted(msg.sender, recipient, amountIn, amount, hops.length);
        return amount;
    }

    /// @notice Batch calls to this router's own functions.
    /// @dev Non-payable: every subcall observes msg.value == 0, so native-input
    ///      swaps must be sent as direct swapExactIn calls. Each subcall acquires
    ///      the swap lock independently; pool callbacks cannot be invoked through it.
    function multicall(bytes[] calldata data) external returns (bytes[] memory results) {
        results = new bytes[](data.length);
        for (uint256 i; i < data.length; ++i) {
            (bool ok, bytes memory result) = address(this).delegatecall(data[i]);
            if (!ok) {
                assembly {
                    revert(add(result, 32), mload(result))
                }
            }
            results[i] = result;
        }
    }

    /// @notice Recover ERC-20 dust left in the router (owner only).
    function recoverToken(address token, uint256 amount) external onlyOwner lock {
        if (token == address(0)) revert InvalidAddress();
        _safeTransfer(token, owner, amount);
        emit TokenRecovered(token, owner, amount);
    }

    /// @notice Recover stray native currency (owner only).
    function recoverETH() external onlyOwner lock {
        uint256 balance = address(this).balance;
        if (balance == 0) revert InvalidAmount();
        (bool ok,) = payable(owner).call{value: balance}("");
        if (!ok) revert EtherTransferFailed(owner, balance);
        emit EtherRecovered(owner, balance);
    }

    /// @dev Uniswap V3 fork callback. Positive deltas are paid to the calling pool.
    ///      data = abi.encode(factory, token0, token1, fee) with token0 < token1.
    function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data)
        external
        inSwap
    {
        (address factory, address token0, address token1, uint24 fee) =
            abi.decode(data, (address, address, address, uint24));
        if (msg.sender != IUniswapV3FactoryLike(factory).getPool(token0, token1, fee)) {
            revert CallbackUnauthorized();
        }
        if (amount0Delta > 0) _safeTransfer(token0, msg.sender, uint256(amount0Delta));
        if (amount1Delta > 0) _safeTransfer(token1, msg.sender, uint256(amount1Delta));
    }

    /// @dev Uniswap V4 unlock callback. Only the immutable PoolManager may call,
    ///      and only while a swap holds the lock.
    function unlockCallback(bytes calldata data) external inSwap returns (bytes memory result) {
        if (msg.sender != address(poolManager)) revert CallbackUnauthorized();
        (PoolKey memory key, bool zeroForOne, uint160 sqrtPriceLimitX96, uint256 amountIn, address to) =
            abi.decode(data, (PoolKey, bool, uint160, uint256, address));

        IPoolManager.SwapParams memory params = IPoolManager.SwapParams({
            zeroForOne: zeroForOne,
            amountSpecified: -int256(amountIn),
            sqrtPriceLimitX96: sqrtPriceLimitX96
        });
        BalanceDelta delta = poolManager.swap(key, params, "");
        int128 inputDelta = zeroForOne ? delta.amount0() : delta.amount1();
        int128 outputDelta = zeroForOne ? delta.amount1() : delta.amount0();
        if (inputDelta >= 0 || outputDelta <= 0) revert InvalidDelta();
        uint256 actualIn = uint256(uint128(-inputDelta));
        uint256 actualOut = uint256(uint128(outputDelta));

        Currency input = zeroForOne ? key.currency0 : key.currency1;
        Currency output = zeroForOne ? key.currency1 : key.currency0;
        poolManager.sync(input);
        _safeTransfer(Currency.unwrap(input), address(poolManager), actualIn);
        poolManager.settle();
        poolManager.take(output, to, actualOut);
        result = abi.encode(actualIn, actualOut);
    }

    function _executeHop(Hop calldata hop, uint256 amountIn, address to, uint256 deadline)
        internal
        returns (uint256 amountOut)
    {
        if (amountIn == 0 || amountIn > uint256(int256(type(int128).max))) revert InvalidAmount();
        address tokenIn = _normalize(hop.tokenIn);
        address tokenOut = _normalize(hop.tokenOut);
        if (tokenIn == tokenOut) revert InvalidHop();

        if (hop.venue == Venue.V3) {
            return _v3Swap(tokenIn, tokenOut, hop.data, amountIn, to);
        }
        if (hop.venue == Venue.V4) {
            return _v4Swap(tokenIn, tokenOut, hop.data, amountIn, to);
        }
        if (hop.venue == Venue.V4Adapter) {
            return _v4AdapterSwap(tokenIn, tokenOut, hop.data, amountIn, to, deadline);
        }
        if (hop.venue == Venue.V4AdapterRoute) {
            return _v4AdapterRouteSwap(tokenIn, tokenOut, hop.data, amountIn, to, deadline);
        }
        if (hop.venue == Venue.V2) {
            return _v2Swap(tokenIn, tokenOut, hop.data, amountIn, to);
        }
        revert UnsupportedVenue();
    }

    function _v3Swap(address tokenIn, address tokenOut, bytes calldata data, uint256 amountIn, address to)
        internal
        returns (uint256 amountOut)
    {
        (address factory, uint24 fee) = abi.decode(data, (address, uint24));
        if (factory == address(0) || factory.code.length == 0) revert InvalidHop();
        (address token0, address token1) = tokenIn < tokenOut ? (tokenIn, tokenOut) : (tokenOut, tokenIn);
        address pool = IUniswapV3FactoryLike(factory).getPool(token0, token1, fee);
        if (pool == address(0) || pool.code.length == 0) revert InvalidPool();
        bool zeroForOne = tokenIn == token0;
        uint160 sqrtPriceLimitX96 = zeroForOne ? MIN_SQRT_RATIO + 1 : MAX_SQRT_RATIO - 1;
        bytes memory callbackData = abi.encode(factory, token0, token1, fee);
        (int256 amount0, int256 amount1) = IUniswapV3PoolLike(pool).swap(
            to, zeroForOne, int256(amountIn), sqrtPriceLimitX96, callbackData
        );
        int256 deltaIn = zeroForOne ? amount0 : amount1;
        int256 deltaOut = zeroForOne ? amount1 : amount0;
        if (deltaIn <= 0 || deltaOut >= 0) revert InvalidDelta();
        return uint256(-deltaOut);
    }

    function _v4Swap(address tokenIn, address tokenOut, bytes calldata data, uint256 amountIn, address to)
        internal
        returns (uint256 amountOut)
    {
        if (address(poolManager) == address(0)) revert UnsupportedVenue();
        (PoolKey memory key, bool zeroForOne, uint160 sqrtPriceLimitX96) =
            abi.decode(data, (PoolKey, bool, uint160));
        address currency0 = Currency.unwrap(key.currency0);
        address currency1 = Currency.unwrap(key.currency1);
        if (currency0 == address(0) || currency1 == address(0)) revert InvalidHop();
        address token0 = tokenIn < tokenOut ? tokenIn : tokenOut;
        address token1 = tokenIn < tokenOut ? tokenOut : tokenIn;
        if (currency0 != token0 || currency1 != token1 || zeroForOne != (tokenIn == currency0)) {
            revert InvalidHop();
        }
        bytes memory result = poolManager.unlock(
            abi.encode(key, zeroForOne, sqrtPriceLimitX96, amountIn, to)
        );
        (, amountOut) = abi.decode(result, (uint256, uint256));
    }

    /// @dev V4 hop through a MoistUniswapV4*Adapter. The adapter pulls the input
    ///      from this router (activeAccount == address(this)) and pays output to
    ///      it; hook-gated pools work because the adapter is in adapters[] and
    ///      this router is in accounts[]. Approvals are granted for exactly
    ///      amountIn inside the lock and reset to zero afterwards.
    function _v4AdapterSwap(
        address tokenIn,
        address tokenOut,
        bytes calldata data,
        uint256 amountIn,
        address to,
        uint256 deadline
    ) internal returns (uint256 amountOut) {
        (address adapter, PoolKey memory key, bool zeroForOne, uint160 sqrtPriceLimitX96, uint128 minOut) =
            abi.decode(data, (address, PoolKey, bool, uint160, uint128));
        if (adapter == address(0) || adapter.code.length == 0) revert InvalidHop();
        address currency0 = Currency.unwrap(key.currency0);
        address currency1 = Currency.unwrap(key.currency1);
        if (currency0 == address(0) || currency1 == address(0)) revert InvalidHop();
        address token0 = tokenIn < tokenOut ? tokenIn : tokenOut;
        address token1 = tokenIn < tokenOut ? tokenOut : tokenIn;
        if (currency0 != token0 || currency1 != token1 || zeroForOne != (tokenIn == currency0)) {
            revert InvalidHop();
        }
        if (amountIn > type(uint128).max) revert InvalidAmount();

        IMoistV4SwapAdapter.ExactInputSingleRequest memory request = IMoistV4SwapAdapter
            .ExactInputSingleRequest({
                key: key,
                zeroForOne: zeroForOne,
                amountIn: uint128(amountIn),
                amountOutMinimum: minOut,
                sqrtPriceLimitX96: sqrtPriceLimitX96,
                deadline: deadline
            });
        _safeApprove(tokenIn, adapter, amountIn);
        (uint256 used, uint256 out) = IMoistV4SwapAdapter(adapter).exactInputSingle(request);
        _safeApprove(tokenIn, adapter, 0);
        if (used > amountIn) revert InvalidAmount();
        amountOut = out;
        if (to != address(this)) _safeTransfer(tokenOut, to, amountOut);
    }

    /// @dev Multihop V4 hop through an adapter's exactInput. hop.data =
    ///      abi.encode(adapter, V4RouteHop[] hops, amountOutMinimum).
    function _v4AdapterRouteSwap(
        address tokenIn,
        address tokenOut,
        bytes calldata data,
        uint256 amountIn,
        address to,
        uint256 deadline
    ) internal returns (uint256 amountOut) {
        (address adapter, V4RouteHop[] memory hops, uint128 minOut) =
            abi.decode(data, (address, V4RouteHop[], uint128));
        if (adapter == address(0) || adapter.code.length == 0) revert InvalidHop();
        (address routeIn, address routeOut) = _validateV4AdapterRoute(hops);
        if (routeIn != tokenIn || routeOut != tokenOut) revert InvalidHop();
        if (amountIn > type(uint128).max) revert InvalidAmount();

        _safeApprove(tokenIn, adapter, amountIn);
        (uint256 spent, uint256 out) =
            IMoistV4SwapRouterAdapter(adapter).exactInput(hops, amountIn, minOut, deadline);
        _safeApprove(tokenIn, adapter, 0);
        if (spent > amountIn) revert InvalidAmount();
        amountOut = out;
        if (to != address(this)) _safeTransfer(tokenOut, to, amountOut);
    }

    /// @dev Validates a V4RouteHop path: contiguous ERC-20 currencies, no
    ///      native legs. Returns (first-hop input, last-hop output).
    function _validateV4AdapterRoute(V4RouteHop[] memory hops)
        private
        pure
        returns (address tokenIn, address tokenOut)
    {
        if (hops.length == 0) revert InvalidHop();
        address expectedIn;
        for (uint256 i; i < hops.length; ++i) {
            address currency0 = Currency.unwrap(hops[i].key.currency0);
            address currency1 = Currency.unwrap(hops[i].key.currency1);
            if (currency0 == address(0) || currency1 == address(0)) revert InvalidHop();
            address hopIn = hops[i].zeroForOne ? currency0 : currency1;
            address hopOut = hops[i].zeroForOne ? currency1 : currency0;
            if (hopIn == hopOut) revert InvalidHop();
            if (i == 0) {
                tokenIn = hopIn;
            } else if (hopIn != expectedIn) {
                revert InvalidHop();
            }
            expectedIn = hopOut;
        }
        tokenOut = expectedIn;
    }

    /// @notice Exact-output swap through an adapter's multihop exactOutput.
    /// @dev `amountOut` is the pool-level output target (gross of any adapter
    ///      fee); the recipient receives the adapter's net `received` amount.
    ///      Pulls maxAmountIn of the route's input token from msg.sender,
    ///      approves the adapter for that maximum, and refunds the unused
    ///      input to msg.sender after the call. ERC-20 only; native legs are
    ///      rejected by route validation.
    function swapExactOutV4Adapter(
        address adapter,
        V4RouteHop[] calldata hops,
        uint256 amountOut,
        uint256 maxAmountIn,
        address recipient,
        uint256 deadline
    ) external payable lock returns (uint256 amountIn) {
        if (block.timestamp > deadline) revert DeadlineExpired(deadline, block.timestamp);
        if (recipient == address(0) || amountOut == 0 || maxAmountIn == 0) revert InvalidPath();
        if (adapter == address(0) || adapter.code.length == 0) revert InvalidHop();
        if (msg.value != 0) revert NativeValueMismatch();
        V4RouteHop[] memory mhops = hops;
        (address tokenIn, address tokenOut) = _validateV4AdapterRoute(mhops);

        _safeTransferFrom(tokenIn, msg.sender, address(this), maxAmountIn);
        _safeApprove(tokenIn, adapter, maxAmountIn);
        (uint256 spent, uint256 received) =
            IMoistV4SwapRouterAdapter(adapter).exactOutput(hops, amountOut, maxAmountIn, deadline);
        _safeApprove(tokenIn, adapter, 0);
        if (spent > maxAmountIn || received == 0) revert InvalidAmount();
        uint256 refund = maxAmountIn - spent;
        if (refund != 0) _safeTransfer(tokenIn, msg.sender, refund);
        _safeTransfer(tokenOut, recipient, received);
        emit SwapExecuted(msg.sender, recipient, spent, received, 1);
        return spent;
    }

    function _v2Swap(address tokenIn, address tokenOut, bytes calldata data, uint256 amountIn, address to)
        internal
        returns (uint256 amountOut)
    {
        (address pair, uint24 feeBps) = abi.decode(data, (address, uint24));
        if (pair == address(0) || pair.code.length == 0 || feeBps >= 10000) revert InvalidHop();
        address token0 = IV2PairLike(pair).token0();
        address token1 = IV2PairLike(pair).token1();
        if ((token0 != tokenIn || token1 != tokenOut) && (token0 != tokenOut || token1 != tokenIn)) {
            revert InvalidHop();
        }
        (uint112 reserve0, uint112 reserve1,) = IV2PairLike(pair).getReserves();
        bool token0In = tokenIn == token0;
        uint256 reserveIn = token0In ? uint256(reserve0) : uint256(reserve1);
        uint256 reserveOut = token0In ? uint256(reserve1) : uint256(reserve0);
        if (reserveIn == 0 || reserveOut == 0) revert InvalidReserves();
        uint256 amountInWithFee = amountIn * (10000 - feeBps);
        amountOut = (reserveOut * amountInWithFee) / (reserveIn * 10000 + amountInWithFee);
        if (amountOut == 0 || amountOut >= reserveOut) revert InvalidReserves();
        _safeTransfer(tokenIn, pair, amountIn);
        IV2PairLike(pair).swap(token0In ? 0 : amountOut, token0In ? amountOut : 0, to, "");
    }

    function _validatePath(Hop[] calldata hops) internal view {
        for (uint256 i; i < hops.length; ++i) {
            if (_normalize(hops[i].tokenIn) == _normalize(hops[i].tokenOut)) revert InvalidHop();
            if (i + 1 < hops.length && _normalize(hops[i].tokenOut) != _normalize(hops[i + 1].tokenIn)) {
                revert InvalidPath();
            }
        }
    }

    function _normalize(address token) internal view returns (address) {
        return token == address(0) ? WETH : token;
    }

    function _safeTransfer(address token, address to, uint256 amount) internal {
        (bool ok, bytes memory result) = token.call(abi.encodeCall(IMoistSwapRouterToken.transfer, (to, amount)));
        if (!ok || (result.length != 0 && (result.length != 32 || !abi.decode(result, (bool))))) {
            revert TokenTransferFailed(token);
        }
    }

    function _safeApprove(address token, address spender, uint256 amount) internal {
        (bool ok, bytes memory result) =
            token.call(abi.encodeWithSelector(bytes4(0x095ea7b3), spender, amount));
        if (!ok || (result.length != 0 && (result.length != 32 || !abi.decode(result, (bool))))) {
            revert TokenTransferFailed(token);
        }
    }

    function _safeTransferFrom(address token, address from, address to, uint256 amount) internal {
        (bool ok, bytes memory result) =
            token.call(abi.encodeCall(IMoistSwapRouterToken.transferFrom, (from, to, amount)));
        if (!ok || (result.length != 0 && (result.length != 32 || !abi.decode(result, (bool))))) {
            revert TokenTransferFailed(token);
        }
    }
}

contracts/v4-core/src/interfaces/IExtsload.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @notice Interface for functions to access any storage slot in a contract
interface IExtsload {
    /// @notice Called by external contracts to access granular pool state
    /// @param slot Key of slot to sload
    /// @return value The value of the slot as bytes32
    function extsload(bytes32 slot) external view returns (bytes32 value);

    /// @notice Called by external contracts to access granular pool state
    /// @param startSlot Key of slot to start sloading from
    /// @param nSlots Number of slots to load into return value
    /// @return values List of loaded values.
    function extsload(bytes32 startSlot, uint256 nSlots) external view returns (bytes32[] memory values);

    /// @notice Called by external contracts to access sparse pool state
    /// @param slots List of slots to SLOAD from.
    /// @return values List of loaded values.
    function extsload(bytes32[] calldata slots) external view returns (bytes32[] memory values);
}

contracts/v4-core/src/interfaces/IExttload.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

/// @notice Interface for functions to access any transient storage slot in a contract
interface IExttload {
    /// @notice Called by external contracts to access transient storage of the contract
    /// @param slot Key of slot to tload
    /// @return value The value of the slot as bytes32
    function exttload(bytes32 slot) external view returns (bytes32 value);

    /// @notice Called by external contracts to access sparse transient pool state
    /// @param slots List of slots to tload
    /// @return values List of loaded values
    function exttload(bytes32[] calldata slots) external view returns (bytes32[] memory values);
}

contracts/v4-core/src/interfaces/IHooks.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {PoolKey} from "../types/PoolKey.sol";
import {BalanceDelta} from "../types/BalanceDelta.sol";
import {IPoolManager} from "./IPoolManager.sol";
import {BeforeSwapDelta} from "../types/BeforeSwapDelta.sol";

/// @notice V4 decides whether to invoke specific hooks by inspecting the least significant bits
/// of the address that the hooks contract is deployed to.
/// For example, a hooks contract deployed to address: 0x0000000000000000000000000000000000002400
/// has the lowest bits '10 0100 0000 0000' which would cause the 'before initialize' and 'after add liquidity' hooks to be used.
/// See the Hooks library for the full spec.
/// @dev Should only be callable by the v4 PoolManager.
interface IHooks {
    /// @notice The hook called before the state of a pool is initialized
    /// @param sender The initial msg.sender for the initialize call
    /// @param key The key for the pool being initialized
    /// @param sqrtPriceX96 The sqrt(price) of the pool as a Q64.96
    /// @return bytes4 The function selector for the hook
    function beforeInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96) external returns (bytes4);

    /// @notice The hook called after the state of a pool is initialized
    /// @param sender The initial msg.sender for the initialize call
    /// @param key The key for the pool being initialized
    /// @param sqrtPriceX96 The sqrt(price) of the pool as a Q64.96
    /// @param tick The current tick after the state of a pool is initialized
    /// @return bytes4 The function selector for the hook
    function afterInitialize(address sender, PoolKey calldata key, uint160 sqrtPriceX96, int24 tick)
        external
        returns (bytes4);

    /// @notice The hook called before liquidity is added
    /// @param sender The initial msg.sender for the add liquidity call
    /// @param key The key for the pool
    /// @param params The parameters for adding liquidity
    /// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be passed on to the hook
    /// @return bytes4 The function selector for the hook
    function beforeAddLiquidity(
        address sender,
        PoolKey calldata key,
        IPoolManager.ModifyLiquidityParams calldata params,
        bytes calldata hookData
    ) external returns (bytes4);

    /// @notice The hook called after liquidity is added
    /// @param sender The initial msg.sender for the add liquidity call
    /// @param key The key for the pool
    /// @param params The parameters for adding liquidity
    /// @param delta The caller's balance delta after adding liquidity; the sum of principal delta, fees accrued, and hook delta
    /// @param feesAccrued The fees accrued since the last time fees were collected from this position
    /// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be passed on to the hook
    /// @return bytes4 The function selector for the hook
    /// @return BalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
    function afterAddLiquidity(
        address sender,
        PoolKey calldata key,
        IPoolManager.ModifyLiquidityParams calldata params,
        BalanceDelta delta,
        BalanceDelta feesAccrued,
        bytes calldata hookData
    ) external returns (bytes4, BalanceDelta);

    /// @notice The hook called before liquidity is removed
    /// @param sender The initial msg.sender for the remove liquidity call
    /// @param key The key for the pool
    /// @param params The parameters for removing liquidity
    /// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be be passed on to the hook
    /// @return bytes4 The function selector for the hook
    function beforeRemoveLiquidity(
        address sender,
        PoolKey calldata key,
        IPoolManager.ModifyLiquidityParams calldata params,
        bytes calldata hookData
    ) external returns (bytes4);

    /// @notice The hook called after liquidity is removed
    /// @param sender The initial msg.sender for the remove liquidity call
    /// @param key The key for the pool
    /// @param params The parameters for removing liquidity
    /// @param delta The caller's balance delta after removing liquidity; the sum of principal delta, fees accrued, and hook delta
    /// @param feesAccrued The fees accrued since the last time fees were collected from this position
    /// @param hookData Arbitrary data handed into the PoolManager by the liquidity provider to be be passed on to the hook
    /// @return bytes4 The function selector for the hook
    /// @return BalanceDelta The hook's delta in token0 and token1. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
    function afterRemoveLiquidity(
        address sender,
        PoolKey calldata key,
        IPoolManager.ModifyLiquidityParams calldata params,
        BalanceDelta delta,
        BalanceDelta feesAccrued,
        bytes calldata hookData
    ) external returns (bytes4, BalanceDelta);

    /// @notice The hook called before a swap
    /// @param sender The initial msg.sender for the swap call
    /// @param key The key for the pool
    /// @param params The parameters for the swap
    /// @param hookData Arbitrary data handed into the PoolManager by the swapper to be be passed on to the hook
    /// @return bytes4 The function selector for the hook
    /// @return BeforeSwapDelta The hook's delta in specified and unspecified currencies. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
    /// @return uint24 Optionally override the lp fee, only used if three conditions are met: 1. the Pool has a dynamic fee, 2. the value's 2nd highest bit is set (23rd bit, 0x400000), and 3. the value is less than or equal to the maximum fee (1 million)
    function beforeSwap(
        address sender,
        PoolKey calldata key,
        IPoolManager.SwapParams calldata params,
        bytes calldata hookData
    ) external returns (bytes4, BeforeSwapDelta, uint24);

    /// @notice The hook called after a swap
    /// @param sender The initial msg.sender for the swap call
    /// @param key The key for the pool
    /// @param params The parameters for the swap
    /// @param delta The amount owed to the caller (positive) or owed to the pool (negative)
    /// @param hookData Arbitrary data handed into the PoolManager by the swapper to be be passed on to the hook
    /// @return bytes4 The function selector for the hook
    /// @return int128 The hook's delta in unspecified currency. Positive: the hook is owed/took currency, negative: the hook owes/sent currency
    function afterSwap(
        address sender,
        PoolKey calldata key,
        IPoolManager.SwapParams calldata params,
        BalanceDelta delta,
        bytes calldata hookData
    ) external returns (bytes4, int128);

    /// @notice The hook called before donate
    /// @param sender The initial msg.sender for the donate call
    /// @param key The key for the pool
    /// @param amount0 The amount of token0 being donated
    /// @param amount1 The amount of token1 being donated
    /// @param hookData Arbitrary data handed into the PoolManager by the donor to be be passed on to the hook
    /// @return bytes4 The function selector for the hook
    function beforeDonate(
        address sender,
        PoolKey calldata key,
        uint256 amount0,
        uint256 amount1,
        bytes calldata hookData
    ) external returns (bytes4);

    /// @notice The hook called after donate
    /// @param sender The initial msg.sender for the donate call
    /// @param key The key for the pool
    /// @param amount0 The amount of token0 being donated
    /// @param amount1 The amount of token1 being donated
    /// @param hookData Arbitrary data handed into the PoolManager by the donor to be be passed on to the hook
    /// @return bytes4 The function selector for the hook
    function afterDonate(
        address sender,
        PoolKey calldata key,
        uint256 amount0,
        uint256 amount1,
        bytes calldata hookData
    ) external returns (bytes4);
}

contracts/v4-core/src/interfaces/IPoolManager.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import {Currency} from "../types/Currency.sol";
import {PoolKey} from "../types/PoolKey.sol";
import {IHooks} from "./IHooks.sol";
import {IERC6909Claims} from "./external/IERC6909Claims.sol";
import {IProtocolFees} from "./IProtocolFees.sol";
import {BalanceDelta} from "../types/BalanceDelta.sol";
import {PoolId} from "../types/PoolId.sol";
import {IExtsload} from "./IExtsload.sol";
import {IExttload} from "./IExttload.sol";

/// @notice Interface for the PoolManager
interface IPoolManager is IProtocolFees, IERC6909Claims, IExtsload, IExttload {
    /// @notice Thrown when a currency is not netted out after the contract is unlocked
    error CurrencyNotSettled();

    /// @notice Thrown when trying to interact with a non-initialized pool
    error PoolNotInitialized();

    /// @notice Thrown when unlock is called, but the contract is already unlocked
    error AlreadyUnlocked();

    /// @notice Thrown when a function is called that requires the contract to be unlocked, but it is not
    error ManagerLocked();

    /// @notice Pools are limited to type(int16).max tickSpacing in #initialize, to prevent overflow
    error TickSpacingTooLarge(int24 tickSpacing);

    /// @notice Pools must have a positive non-zero tickSpacing passed to #initialize
    error TickSpacingTooSmall(int24 tickSpacing);

    /// @notice PoolKey must have currencies where address(currency0) < address(currency1)
    error CurrenciesOutOfOrderOrEqual(address currency0, address currency1);

    /// @notice Thrown when a call to updateDynamicLPFee is made by an address that is not the hook,
    /// or on a pool that does not have a dynamic swap fee.
    error UnauthorizedDynamicLPFeeUpdate();

    /// @notice Thrown when trying to swap amount of 0
    error SwapAmountCannotBeZero();

    ///@notice Thrown when native currency is passed to a non native settlement
    error NonzeroNativeValue();

    /// @notice Thrown when `clear` is called with an amount that is not exactly equal to the open currency delta.
    error MustClearExactPositiveDelta();

    /// @notice Emitted when a new pool is initialized
    /// @param id The abi encoded hash of the pool key struct for the new pool
    /// @param currency0 The first currency of the pool by address sort order
    /// @param currency1 The second currency of the pool by address sort order
    /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
    /// @param tickSpacing The minimum number of ticks between initialized ticks
    /// @param hooks The hooks contract address for the pool, or address(0) if none
    /// @param sqrtPriceX96 The price of the pool on initialization
    /// @param tick The initial tick of the pool corresponding to the initialized price
    event Initialize(
        PoolId indexed id,
        Currency indexed currency0,
        Currency indexed currency1,
        uint24 fee,
        int24 tickSpacing,
        IHooks hooks,
        uint160 sqrtPriceX96,
        int24 tick
    );

    /// @notice Emitted when a liquidity position is modified
    /// @param id The abi encoded hash of the pool key struct for the pool that was modified
    /// @param sender The address that modified the pool
    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param liquidityDelta The amount of liquidity that was added or removed
    /// @param salt The extra data to make positions unique
    event ModifyLiquidity(
        PoolId indexed id, address indexed sender, int24 tickLower, int24 tickUpper, int256 liquidityDelta, bytes32 salt
    );

    /// @notice Emitted for swaps between currency0 and currency1
    /// @param id The abi encoded hash of the pool key struct for the pool that was modified
    /// @param sender The address that initiated the swap call, and that received the callback
    /// @param amount0 The delta of the currency0 balance of the pool
    /// @param amount1 The delta of the currency1 balance of the pool
    /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96
    /// @param liquidity The liquidity of the pool after the swap
    /// @param tick The log base 1.0001 of the price of the pool after the swap
    /// @param fee The swap fee in hundredths of a bip
    event Swap(
        PoolId indexed id,
        address indexed sender,
        int128 amount0,
        int128 amount1,
        uint160 sqrtPriceX96,
        uint128 liquidity,
        int24 tick,
        uint24 fee
    );

    /// @notice Emitted for donations
    /// @param id The abi encoded hash of the pool key struct for the pool that was donated to
    /// @param sender The address that initiated the donate call
    /// @param amount0 The amount donated in currency0
    /// @param amount1 The amount donated in currency1
    event Donate(PoolId indexed id, address indexed sender, uint256 amount0, uint256 amount1);

    /// @notice All interactions on the contract that account deltas require unlocking. A caller that calls `unlock` must implement
    /// `IUnlockCallback(msg.sender).unlockCallback(data)`, where they interact with the remaining functions on this contract.
    /// @dev The only functions callable without an unlocking are `initialize` and `updateDynamicLPFee`
    /// @param data Any data to pass to the callback, via `IUnlockCallback(msg.sender).unlockCallback(data)`
    /// @return The data returned by the call to `IUnlockCallback(msg.sender).unlockCallback(data)`
    function unlock(bytes calldata data) external returns (bytes memory);

    /// @notice Initialize the state for a given pool ID
    /// @dev A swap fee totaling MAX_SWAP_FEE (100%) makes exact output swaps impossible since the input is entirely consumed by the fee
    /// @param key The pool key for the pool to initialize
    /// @param sqrtPriceX96 The initial square root price
    /// @return tick The initial tick of the pool
    function initialize(PoolKey memory key, uint160 sqrtPriceX96) external returns (int24 tick);

    struct ModifyLiquidityParams {
        // the lower and upper tick of the position
        int24 tickLower;
        int24 tickUpper;
        // how to modify the liquidity
        int256 liquidityDelta;
        // a value to set if you want unique liquidity positions at the same range
        bytes32 salt;
    }

    /// @notice Modify the liquidity for the given pool
    /// @dev Poke by calling with a zero liquidityDelta
    /// @param key The pool to modify liquidity in
    /// @param params The parameters for modifying the liquidity
    /// @param hookData The data to pass through to the add/removeLiquidity hooks
    /// @return callerDelta The balance delta of the caller of modifyLiquidity. This is the total of both principal, fee deltas, and hook deltas if applicable
    /// @return feesAccrued The balance delta of the fees generated in the liquidity range. Returned for informational purposes
    /// @dev Note that feesAccrued can be artificially inflated by a malicious actor and integrators should be careful using the value
    /// For pools with a single liquidity position, actors can donate to themselves to inflate feeGrowthGlobal (and consequently feesAccrued)
    /// atomically donating and collecting fees in the same unlockCallback may make the inflated value more extreme
    function modifyLiquidity(PoolKey memory key, ModifyLiquidityParams memory params, bytes calldata hookData)
        external
        returns (BalanceDelta callerDelta, BalanceDelta feesAccrued);

    struct SwapParams {
        /// Whether to swap token0 for token1 or vice versa
        bool zeroForOne;
        /// The desired input amount if negative (exactIn), or the desired output amount if positive (exactOut)
        int256 amountSpecified;
        /// The sqrt price at which, if reached, the swap will stop executing
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swap against the given pool
    /// @param key The pool to swap in
    /// @param params The parameters for swapping
    /// @param hookData The data to pass through to the swap hooks
    /// @return swapDelta The balance delta of the address swapping
    /// @dev Swapping on low liquidity pools may cause unexpected swap amounts when liquidity available is less than amountSpecified.
    /// Additionally note that if interacting with hooks that have the BEFORE_SWAP_RETURNS_DELTA_FLAG or AFTER_SWAP_RETURNS_DELTA_FLAG
    /// the hook may alter the swap input/output. Integrators should perform checks on the returned swapDelta.
    function swap(PoolKey memory key, SwapParams memory params, bytes calldata hookData)
        external
        returns (BalanceDelta swapDelta);

    /// @notice Donate the given currency amounts to the in-range liquidity providers of a pool
    /// @dev Calls to donate can be frontrun adding just-in-time liquidity, with the aim of receiving a portion donated funds.
    /// Donors should keep this in mind when designing donation mechanisms.
    /// @dev This function donates to in-range LPs at slot0.tick. In certain edge-cases of the swap algorithm, the `sqrtPrice` of
    /// a pool can be at the lower boundary of tick `n`, but the `slot0.tick` of the pool is already `n - 1`. In this case a call to
    /// `donate` would donate to tick `n - 1` (slot0.tick) not tick `n` (getTickAtSqrtPrice(slot0.sqrtPriceX96)).
    /// Read the comments in `Pool.swap()` for more information about this.
    /// @param key The key of the pool to donate to
    /// @param amount0 The amount of currency0 to donate
    /// @param amount1 The amount of currency1 to donate
    /// @param hookData The data to pass through to the donate hooks
    /// @return BalanceDelta The delta of the caller after the donate
    function donate(PoolKey memory key, uint256 amount0, uint256 amount1, bytes calldata hookData)
        external
        returns (BalanceDelta);

    /// @notice Writes the current ERC20 balance of the specified currency to transient storage
    /// This is used to checkpoint balances for the manager and derive deltas for the caller.
    /// @dev This MUST be called before any ERC20 tokens are sent into the contract, but can be skipped
    /// for native tokens because the amount to settle is determined by the sent value.
    /// However, if an ERC20 token has been synced and not settled, and the caller instead wants to settle
    /// native funds, this function can be called with the native currency to then be able to settle the native currency
    function sync(Currency currency) external;

    /// @notice Called by the user to net out some value owed to the user
    /// @dev Will revert if the requested amount is not available, consider using `mint` instead
    /// @dev Can also be used as a mechanism for free flash loans
    /// @param currency The currency to withdraw from the pool manager
    /// @param to The address to withdraw to
    /// @param amount The amount of currency to withdraw
    function take(Currency currency, address to, uint256 amount) external;

    /// @notice Called by the user to pay what is owed
    /// @return paid The amount of currency settled
    function settle() external payable returns (uint256 paid);

    /// @notice Called by the user to pay on behalf of another address
    /// @param recipient The address to credit for the payment
    /// @return paid The amount of currency settled
    function settleFor(address recipient) external payable returns (uint256 paid);

    /// @notice WARNING - Any currency that is cleared, will be non-retrievable, and locked in the contract permanently.
    /// A call to clear will zero out a positive balance WITHOUT a corresponding transfer.
    /// @dev This could be used to clear a balance that is considered dust.
    /// Additionally, the amount must be the exact positive balance. This is to enforce that the caller is aware of the amount being cleared.
    function clear(Currency currency, uint256 amount) external;

    /// @notice Called by the user to move value into ERC6909 balance
    /// @param to The address to mint the tokens to
    /// @param id The currency address to mint to ERC6909s, as a uint256
    /// @param amount The amount of currency to mint
    /// @dev The id is converted to a uint160 to correspond to a currency address
    /// If the upper 12 bytes are not 0, they will be 0-ed out
    function mint(address to, uint256 id, uint256 amount) external;

    /// @notice Called by the user to move value from ERC6909 balance
    /// @param from The address to burn the tokens from
    /// @param id The currency address to burn from ERC6909s, as a uint256
    /// @param amount The amount of currency to burn
    /// @dev The id is converted to a uint160 to correspond to a currency address
    /// If the upper 12 bytes are not 0, they will be 0-ed out
    function burn(address from, uint256 id, uint256 amount) external;

    /// @notice Updates the pools lp fees for the a pool that has enabled dynamic lp fees.
    /// @dev A swap fee totaling MAX_SWAP_FEE (100%) makes exact output swaps impossible since the input is entirely consumed by the fee
    /// @param key The key of the pool to update dynamic LP fees for
    /// @param newDynamicLPFee The new dynamic pool LP fee
    function updateDynamicLPFee(PoolKey memory key, uint24 newDynamicLPFee) external;
}

contracts/v4-core/src/interfaces/IProtocolFees.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {Currency} from "../types/Currency.sol";
import {PoolId} from "../types/PoolId.sol";
import {PoolKey} from "../types/PoolKey.sol";

/// @notice Interface for all protocol-fee related functions in the pool manager
interface IProtocolFees {
    /// @notice Thrown when protocol fee is set too high
    error ProtocolFeeTooLarge(uint24 fee);

    /// @notice Thrown when collectProtocolFees or setProtocolFee is not called by the controller.
    error InvalidCaller();

    /// @notice Thrown when collectProtocolFees is attempted on a token that is synced.
    error ProtocolFeeCurrencySynced();

    /// @notice Emitted when the protocol fee controller address is updated in setProtocolFeeController.
    event ProtocolFeeControllerUpdated(address indexed protocolFeeController);

    /// @notice Emitted when the protocol fee is updated for a pool.
    event ProtocolFeeUpdated(PoolId indexed id, uint24 protocolFee);

    /// @notice Given a currency address, returns the protocol fees accrued in that currency
    /// @param currency The currency to check
    /// @return amount The amount of protocol fees accrued in the currency
    function protocolFeesAccrued(Currency currency) external view returns (uint256 amount);

    /// @notice Sets the protocol fee for the given pool
    /// @param key The key of the pool to set a protocol fee for
    /// @param newProtocolFee The fee to set
    function setProtocolFee(PoolKey memory key, uint24 newProtocolFee) external;

    /// @notice Sets the protocol fee controller
    /// @param controller The new protocol fee controller
    function setProtocolFeeController(address controller) external;

    /// @notice Collects the protocol fees for a given recipient and currency, returning the amount collected
    /// @dev This will revert if the contract is unlocked
    /// @param recipient The address to receive the protocol fees
    /// @param currency The currency to withdraw
    /// @param amount The amount of currency to withdraw
    /// @return amountCollected The amount of currency successfully withdrawn
    function collectProtocolFees(address recipient, Currency currency, uint256 amount)
        external
        returns (uint256 amountCollected);

    /// @notice Returns the current protocol fee controller address
    /// @return address The current protocol fee controller address
    function protocolFeeController() external view returns (address);
}

contracts/v4-core/src/interfaces/external/IERC20Minimal.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @title Minimal ERC20 interface for Uniswap
/// @notice Contains a subset of the full ERC20 interface that is used in Uniswap V3
interface IERC20Minimal {
    /// @notice Returns an account's balance in the token
    /// @param account The account for which to look up the number of tokens it has, i.e. its balance
    /// @return The number of tokens held by the account
    function balanceOf(address account) external view returns (uint256);

    /// @notice Transfers the amount of token from the `msg.sender` to the recipient
    /// @param recipient The account that will receive the amount transferred
    /// @param amount The number of tokens to send from the sender to the recipient
    /// @return Returns true for a successful transfer, false for an unsuccessful transfer
    function transfer(address recipient, uint256 amount) external returns (bool);

    /// @notice Returns the current allowance given to a spender by an owner
    /// @param owner The account of the token owner
    /// @param spender The account of the token spender
    /// @return The current allowance granted by `owner` to `spender`
    function allowance(address owner, address spender) external view returns (uint256);

    /// @notice Sets the allowance of a spender from the `msg.sender` to the value `amount`
    /// @param spender The account which will be allowed to spend a given amount of the owners tokens
    /// @param amount The amount of tokens allowed to be used by `spender`
    /// @return Returns true for a successful approval, false for unsuccessful
    function approve(address spender, uint256 amount) external returns (bool);

    /// @notice Transfers `amount` tokens from `sender` to `recipient` up to the allowance given to the `msg.sender`
    /// @param sender The account from which the transfer will be initiated
    /// @param recipient The recipient of the transfer
    /// @param amount The amount of the transfer
    /// @return Returns true for a successful transfer, false for unsuccessful
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);

    /// @notice Event emitted when tokens are transferred from one address to another, either via `#transfer` or `#transferFrom`.
    /// @param from The account from which the tokens were sent, i.e. the balance decreased
    /// @param to The account to which the tokens were sent, i.e. the balance increased
    /// @param value The amount of tokens that were transferred
    event Transfer(address indexed from, address indexed to, uint256 value);

    /// @notice Event emitted when the approval amount for the spender of a given owner's tokens changes.
    /// @param owner The account that approved spending of its tokens
    /// @param spender The account for which the spending allowance was modified
    /// @param value The new allowance from the owner to the spender
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

contracts/v4-core/src/interfaces/external/IERC6909Claims.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @notice Interface for claims over a contract balance, wrapped as a ERC6909
interface IERC6909Claims {
    /*//////////////////////////////////////////////////////////////
                                 EVENTS
    //////////////////////////////////////////////////////////////*/

    event OperatorSet(address indexed owner, address indexed operator, bool approved);

    event Approval(address indexed owner, address indexed spender, uint256 indexed id, uint256 amount);

    event Transfer(address caller, address indexed from, address indexed to, uint256 indexed id, uint256 amount);

    /*//////////////////////////////////////////////////////////////
                                 FUNCTIONS
    //////////////////////////////////////////////////////////////*/

    /// @notice Owner balance of an id.
    /// @param owner The address of the owner.
    /// @param id The id of the token.
    /// @return amount The balance of the token.
    function balanceOf(address owner, uint256 id) external view returns (uint256 amount);

    /// @notice Spender allowance of an id.
    /// @param owner The address of the owner.
    /// @param spender The address of the spender.
    /// @param id The id of the token.
    /// @return amount The allowance of the token.
    function allowance(address owner, address spender, uint256 id) external view returns (uint256 amount);

    /// @notice Checks if a spender is approved by an owner as an operator
    /// @param owner The address of the owner.
    /// @param spender The address of the spender.
    /// @return approved The approval status.
    function isOperator(address owner, address spender) external view returns (bool approved);

    /// @notice Transfers an amount of an id from the caller to a receiver.
    /// @param receiver The address of the receiver.
    /// @param id The id of the token.
    /// @param amount The amount of the token.
    /// @return bool True, always, unless the function reverts
    function transfer(address receiver, uint256 id, uint256 amount) external returns (bool);

    /// @notice Transfers an amount of an id from a sender to a receiver.
    /// @param sender The address of the sender.
    /// @param receiver The address of the receiver.
    /// @param id The id of the token.
    /// @param amount The amount of the token.
    /// @return bool True, always, unless the function reverts
    function transferFrom(address sender, address receiver, uint256 id, uint256 amount) external returns (bool);

    /// @notice Approves an amount of an id to a spender.
    /// @param spender The address of the spender.
    /// @param id The id of the token.
    /// @param amount The amount of the token.
    /// @return bool True, always
    function approve(address spender, uint256 id, uint256 amount) external returns (bool);

    /// @notice Sets or removes an operator for the caller.
    /// @param operator The address of the operator.
    /// @param approved The approval status.
    /// @return bool True, always
    function setOperator(address operator, bool approved) external returns (bool);
}

contracts/v4-core/src/libraries/CustomRevert.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @title Library for reverting with custom errors efficiently
/// @notice Contains functions for reverting with custom errors with different argument types efficiently
/// @dev To use this library, declare `using CustomRevert for bytes4;` and replace `revert CustomError()` with
/// `CustomError.selector.revertWith()`
/// @dev The functions may tamper with the free memory pointer but it is fine since the call context is exited immediately
library CustomRevert {
    /// @dev ERC-7751 error for wrapping bubbled up reverts
    error WrappedError(address target, bytes4 selector, bytes reason, bytes details);

    /// @dev Reverts with the selector of a custom error in the scratch space
    function revertWith(bytes4 selector) internal pure {
        assembly ("memory-safe") {
            mstore(0, selector)
            revert(0, 0x04)
        }
    }

    /// @dev Reverts with a custom error with an address argument in the scratch space
    function revertWith(bytes4 selector, address addr) internal pure {
        assembly ("memory-safe") {
            mstore(0, selector)
            mstore(0x04, and(addr, 0xffffffffffffffffffffffffffffffffffffffff))
            revert(0, 0x24)
        }
    }

    /// @dev Reverts with a custom error with an int24 argument in the scratch space
    function revertWith(bytes4 selector, int24 value) internal pure {
        assembly ("memory-safe") {
            mstore(0, selector)
            mstore(0x04, signextend(2, value))
            revert(0, 0x24)
        }
    }

    /// @dev Reverts with a custom error with a uint160 argument in the scratch space
    function revertWith(bytes4 selector, uint160 value) internal pure {
        assembly ("memory-safe") {
            mstore(0, selector)
            mstore(0x04, and(value, 0xffffffffffffffffffffffffffffffffffffffff))
            revert(0, 0x24)
        }
    }

    /// @dev Reverts with a custom error with two int24 arguments
    function revertWith(bytes4 selector, int24 value1, int24 value2) internal pure {
        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(fmp, selector)
            mstore(add(fmp, 0x04), signextend(2, value1))
            mstore(add(fmp, 0x24), signextend(2, value2))
            revert(fmp, 0x44)
        }
    }

    /// @dev Reverts with a custom error with two uint160 arguments
    function revertWith(bytes4 selector, uint160 value1, uint160 value2) internal pure {
        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(fmp, selector)
            mstore(add(fmp, 0x04), and(value1, 0xffffffffffffffffffffffffffffffffffffffff))
            mstore(add(fmp, 0x24), and(value2, 0xffffffffffffffffffffffffffffffffffffffff))
            revert(fmp, 0x44)
        }
    }

    /// @dev Reverts with a custom error with two address arguments
    function revertWith(bytes4 selector, address value1, address value2) internal pure {
        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(fmp, selector)
            mstore(add(fmp, 0x04), and(value1, 0xffffffffffffffffffffffffffffffffffffffff))
            mstore(add(fmp, 0x24), and(value2, 0xffffffffffffffffffffffffffffffffffffffff))
            revert(fmp, 0x44)
        }
    }

    /// @notice bubble up the revert message returned by a call and revert with a wrapped ERC-7751 error
    /// @dev this method can be vulnerable to revert data bombs
    function bubbleUpAndRevertWith(
        address revertingContract,
        bytes4 revertingFunctionSelector,
        bytes4 additionalContext
    ) internal pure {
        bytes4 wrappedErrorSelector = WrappedError.selector;
        assembly ("memory-safe") {
            // Ensure the size of the revert data is a multiple of 32 bytes
            let encodedDataSize := mul(div(add(returndatasize(), 31), 32), 32)

            let fmp := mload(0x40)

            // Encode wrapped error selector, address, function selector, offset, additional context, size, revert reason
            mstore(fmp, wrappedErrorSelector)
            mstore(add(fmp, 0x04), and(revertingContract, 0xffffffffffffffffffffffffffffffffffffffff))
            mstore(
                add(fmp, 0x24),
                and(revertingFunctionSelector, 0xffffffff00000000000000000000000000000000000000000000000000000000)
            )
            // offset revert reason
            mstore(add(fmp, 0x44), 0x80)
            // offset additional context
            mstore(add(fmp, 0x64), add(0xa0, encodedDataSize))
            // size revert reason
            mstore(add(fmp, 0x84), returndatasize())
            // revert reason
            returndatacopy(add(fmp, 0xa4), 0, returndatasize())
            // size additional context
            mstore(add(fmp, add(0xa4, encodedDataSize)), 0x04)
            // additional context
            mstore(
                add(fmp, add(0xc4, encodedDataSize)),
                and(additionalContext, 0xffffffff00000000000000000000000000000000000000000000000000000000)
            )
            revert(fmp, add(0xe4, encodedDataSize))
        }
    }
}

contracts/v4-core/src/libraries/SafeCast.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {CustomRevert} from "./CustomRevert.sol";

/// @title Safe casting methods
/// @notice Contains methods for safely casting between types
library SafeCast {
    using CustomRevert for bytes4;

    error SafeCastOverflow();

    /// @notice Cast a uint256 to a uint160, revert on overflow
    /// @param x The uint256 to be downcasted
    /// @return y The downcasted integer, now type uint160
    function toUint160(uint256 x) internal pure returns (uint160 y) {
        y = uint160(x);
        if (y != x) SafeCastOverflow.selector.revertWith();
    }

    /// @notice Cast a uint256 to a uint128, revert on overflow
    /// @param x The uint256 to be downcasted
    /// @return y The downcasted integer, now type uint128
    function toUint128(uint256 x) internal pure returns (uint128 y) {
        y = uint128(x);
        if (x != y) SafeCastOverflow.selector.revertWith();
    }

    /// @notice Cast a int128 to a uint128, revert on overflow or underflow
    /// @param x The int128 to be casted
    /// @return y The casted integer, now type uint128
    function toUint128(int128 x) internal pure returns (uint128 y) {
        if (x < 0) SafeCastOverflow.selector.revertWith();
        y = uint128(x);
    }

    /// @notice Cast a int256 to a int128, revert on overflow or underflow
    /// @param x The int256 to be downcasted
    /// @return y The downcasted integer, now type int128
    function toInt128(int256 x) internal pure returns (int128 y) {
        y = int128(x);
        if (y != x) SafeCastOverflow.selector.revertWith();
    }

    /// @notice Cast a uint256 to a int256, revert on overflow
    /// @param x The uint256 to be casted
    /// @return y The casted integer, now type int256
    function toInt256(uint256 x) internal pure returns (int256 y) {
        y = int256(x);
        if (y < 0) SafeCastOverflow.selector.revertWith();
    }

    /// @notice Cast a uint256 to a int128, revert on overflow
    /// @param x The uint256 to be downcasted
    /// @return The downcasted integer, now type int128
    function toInt128(uint256 x) internal pure returns (int128) {
        if (x >= 1 << 127) SafeCastOverflow.selector.revertWith();
        return int128(int256(x));
    }
}

contracts/v4-core/src/types/BalanceDelta.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {SafeCast} from "../libraries/SafeCast.sol";

/// @dev Two `int128` values packed into a single `int256` where the upper 128 bits represent the amount0
/// and the lower 128 bits represent the amount1.
type BalanceDelta is int256;

using {add as +, sub as -, eq as ==, neq as !=} for BalanceDelta global;
using BalanceDeltaLibrary for BalanceDelta global;
using SafeCast for int256;

function toBalanceDelta(int128 _amount0, int128 _amount1) pure returns (BalanceDelta balanceDelta) {
    assembly ("memory-safe") {
        balanceDelta := or(shl(128, _amount0), and(sub(shl(128, 1), 1), _amount1))
    }
}

function add(BalanceDelta a, BalanceDelta b) pure returns (BalanceDelta) {
    int256 res0;
    int256 res1;
    assembly ("memory-safe") {
        let a0 := sar(128, a)
        let a1 := signextend(15, a)
        let b0 := sar(128, b)
        let b1 := signextend(15, b)
        res0 := add(a0, b0)
        res1 := add(a1, b1)
    }
    return toBalanceDelta(res0.toInt128(), res1.toInt128());
}

function sub(BalanceDelta a, BalanceDelta b) pure returns (BalanceDelta) {
    int256 res0;
    int256 res1;
    assembly ("memory-safe") {
        let a0 := sar(128, a)
        let a1 := signextend(15, a)
        let b0 := sar(128, b)
        let b1 := signextend(15, b)
        res0 := sub(a0, b0)
        res1 := sub(a1, b1)
    }
    return toBalanceDelta(res0.toInt128(), res1.toInt128());
}

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

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

/// @notice Library for getting the amount0 and amount1 deltas from the BalanceDelta type
library BalanceDeltaLibrary {
    /// @notice A BalanceDelta of 0
    BalanceDelta public constant ZERO_DELTA = BalanceDelta.wrap(0);

    function amount0(BalanceDelta balanceDelta) internal pure returns (int128 _amount0) {
        assembly ("memory-safe") {
            _amount0 := sar(128, balanceDelta)
        }
    }

    function amount1(BalanceDelta balanceDelta) internal pure returns (int128 _amount1) {
        assembly ("memory-safe") {
            _amount1 := signextend(15, balanceDelta)
        }
    }
}

contracts/v4-core/src/types/BeforeSwapDelta.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// Return type of the beforeSwap hook.
// Upper 128 bits is the delta in specified tokens. Lower 128 bits is delta in unspecified tokens (to match the afterSwap hook)
type BeforeSwapDelta is int256;

// Creates a BeforeSwapDelta from specified and unspecified
function toBeforeSwapDelta(int128 deltaSpecified, int128 deltaUnspecified)
    pure
    returns (BeforeSwapDelta beforeSwapDelta)
{
    assembly ("memory-safe") {
        beforeSwapDelta := or(shl(128, deltaSpecified), and(sub(shl(128, 1), 1), deltaUnspecified))
    }
}

/// @notice Library for getting the specified and unspecified deltas from the BeforeSwapDelta type
library BeforeSwapDeltaLibrary {
    /// @notice A BeforeSwapDelta of 0
    BeforeSwapDelta public constant ZERO_DELTA = BeforeSwapDelta.wrap(0);

    /// extracts int128 from the upper 128 bits of the BeforeSwapDelta
    /// returned by beforeSwap
    function getSpecifiedDelta(BeforeSwapDelta delta) internal pure returns (int128 deltaSpecified) {
        assembly ("memory-safe") {
            deltaSpecified := sar(128, delta)
        }
    }

    /// extracts int128 from the lower 128 bits of the BeforeSwapDelta
    /// returned by beforeSwap and afterSwap
    function getUnspecifiedDelta(BeforeSwapDelta delta) internal pure returns (int128 deltaUnspecified) {
        assembly ("memory-safe") {
            deltaUnspecified := signextend(15, delta)
        }
    }
}

contracts/v4-core/src/types/Currency.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IERC20Minimal} from "../interfaces/external/IERC20Minimal.sol";
import {CustomRevert} from "../libraries/CustomRevert.sol";

type Currency is address;

using {greaterThan as >, lessThan as <, greaterThanOrEqualTo as >=, equals as ==} for Currency global;
using CurrencyLibrary for Currency global;

function equals(Currency currency, Currency other) pure returns (bool) {
    return Currency.unwrap(currency) == Currency.unwrap(other);
}

function greaterThan(Currency currency, Currency other) pure returns (bool) {
    return Currency.unwrap(currency) > Currency.unwrap(other);
}

function lessThan(Currency currency, Currency other) pure returns (bool) {
    return Currency.unwrap(currency) < Currency.unwrap(other);
}

function greaterThanOrEqualTo(Currency currency, Currency other) pure returns (bool) {
    return Currency.unwrap(currency) >= Currency.unwrap(other);
}

/// @title CurrencyLibrary
/// @dev This library allows for transferring and holding native tokens and ERC20 tokens
library CurrencyLibrary {
    /// @notice Additional context for ERC-7751 wrapped error when a native transfer fails
    error NativeTransferFailed();

    /// @notice Additional context for ERC-7751 wrapped error when an ERC20 transfer fails
    error ERC20TransferFailed();

    /// @notice A constant to represent the native currency
    Currency public constant ADDRESS_ZERO = Currency.wrap(address(0));

    function transfer(Currency currency, address to, uint256 amount) internal {
        // altered from https://github.com/transmissions11/solmate/blob/44a9963d4c78111f77caa0e65d677b8b46d6f2e6/src/utils/SafeTransferLib.sol
        // modified custom error selectors

        bool success;
        if (currency.isAddressZero()) {
            assembly ("memory-safe") {
                // Transfer the ETH and revert if it fails.
                success := call(gas(), to, amount, 0, 0, 0, 0)
            }
            // revert with NativeTransferFailed, containing the bubbled up error as an argument
            if (!success) {
                CustomRevert.bubbleUpAndRevertWith(to, bytes4(0), NativeTransferFailed.selector);
            }
        } else {
            assembly ("memory-safe") {
                // Get a pointer to some free memory.
                let fmp := mload(0x40)

                // Write the abi-encoded calldata into memory, beginning with the function selector.
                mstore(fmp, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
                mstore(add(fmp, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
                mstore(add(fmp, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.

                success :=
                    and(
                        // Set success to whether the call reverted, if not we check it either
                        // returned exactly 1 (can't just be non-zero data), or had no return data.
                        or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
                        // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
                        // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                        // Counterintuitively, this call must be positioned second to the or() call in the
                        // surrounding and() call or else returndatasize() will be zero during the computation.
                        call(gas(), currency, 0, fmp, 68, 0, 32)
                    )

                // Now clean the memory we used
                mstore(fmp, 0) // 4 byte `selector` and 28 bytes of `to` were stored here
                mstore(add(fmp, 0x20), 0) // 4 bytes of `to` and 28 bytes of `amount` were stored here
                mstore(add(fmp, 0x40), 0) // 4 bytes of `amount` were stored here
            }
            // revert with ERC20TransferFailed, containing the bubbled up error as an argument
            if (!success) {
                CustomRevert.bubbleUpAndRevertWith(
                    Currency.unwrap(currency), IERC20Minimal.transfer.selector, ERC20TransferFailed.selector
                );
            }
        }
    }

    function balanceOfSelf(Currency currency) internal view returns (uint256) {
        if (currency.isAddressZero()) {
            return address(this).balance;
        } else {
            return IERC20Minimal(Currency.unwrap(currency)).balanceOf(address(this));
        }
    }

    function balanceOf(Currency currency, address owner) internal view returns (uint256) {
        if (currency.isAddressZero()) {
            return owner.balance;
        } else {
            return IERC20Minimal(Currency.unwrap(currency)).balanceOf(owner);
        }
    }

    function isAddressZero(Currency currency) internal pure returns (bool) {
        return Currency.unwrap(currency) == Currency.unwrap(ADDRESS_ZERO);
    }

    function toId(Currency currency) internal pure returns (uint256) {
        return uint160(Currency.unwrap(currency));
    }

    // If the upper 12 bytes are non-zero, they will be zero-ed out
    // Therefore, fromId() and toId() are not inverses of each other
    function fromId(uint256 id) internal pure returns (Currency) {
        return Currency.wrap(address(uint160(id)));
    }
}

contracts/v4-core/src/types/PoolId.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {PoolKey} from "./PoolKey.sol";

type PoolId is bytes32;

/// @notice Library for computing the ID of a pool
library PoolIdLibrary {
    /// @notice Returns value equal to keccak256(abi.encode(poolKey))
    function toId(PoolKey memory poolKey) internal pure returns (PoolId poolId) {
        assembly ("memory-safe") {
            // 0xa0 represents the total size of the poolKey struct (5 slots of 32 bytes)
            poolId := keccak256(poolKey, 0xa0)
        }
    }
}

contracts/v4-core/src/types/PoolKey.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {Currency} from "./Currency.sol";
import {IHooks} from "../interfaces/IHooks.sol";
import {PoolIdLibrary} from "./PoolId.sol";

using PoolIdLibrary for PoolKey global;

/// @notice Returns the key for identifying a pool
struct PoolKey {
    /// @notice The lower currency of the pool, sorted numerically
    Currency currency0;
    /// @notice The higher currency of the pool, sorted numerically
    Currency currency1;
    /// @notice The pool LP fee, capped at 1_000_000. If the highest bit is 1, the pool has a dynamic fee and must be exactly equal to 0x800000
    uint24 fee;
    /// @notice Ticks that involve positions must be a multiple of tick spacing
    int24 tickSpacing;
    /// @notice The hooks of the pool
    IHooks hooks;
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "bytecodeHash": "none"
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@arbitrum/=node_modules/@arbitrum/",
    "@ensdomains/=contracts/v4-core/node_modules/@ensdomains/",
    "@eth-optimism/=lib/unruggable-gateways/lib/optimism/packages/",
    "@layerzerolabs/lz-evm-messagelib-v2/=lib/layerzero-v2/packages/layerzero-v2/evm/messagelib/",
    "@layerzerolabs/lz-evm-protocol-v2/=lib/layerzero-v2/packages/layerzero-v2/evm/protocol/",
    "@layerzerolabs/oapp-evm/=lib/devtools/packages/oapp-evm/",
    "@offchainlabs/=node_modules/@offchainlabs/",
    "@openzeppelin/=node_modules/@openzeppelin/",
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "@uniswap/=node_modules/@uniswap/",
    "base64-sol/=node_modules/base64-sol/",
    "create3-factory/=lib/create3-factory/",
    "devtools/=lib/devtools/",
    "ds-test/=contracts/v4-core/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "flap/=contracts/flap/",
    "forge-std-1.16.2/=dependencies/forge-std-1.16.2/",
    "forge-std/=lib/forge-std/src/",
    "halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "hardhat/=contracts/v4-core/node_modules/hardhat/",
    "interfaces/=contracts/interfaces/",
    "layerzero-v2/=lib/layerzero-v2/",
    "libraries/=contracts/libraries/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/",
    "optimism/=lib/unruggable-gateways/lib/optimism/packages/contracts-bedrock/src/",
    "solady/=node_modules/solady/",
    "solidity-bytes-utils/=lib/solidity-bytes-utils/",
    "solmate/=contracts/v4-core/lib/solmate/",
    "splits-contracts-monorepo/=contracts/splits-contracts-monorepo/src/",
    "unruggable-gateways/=lib/unruggable-gateways/contracts/",
    "v4-core/=contracts/v4-core/src/",
    "vault/=contracts/vault/",
    "contracts/v4-core/:openzeppelin-contracts/=contracts/v4-core/lib/openzeppelin-contracts/",
    "contracts/v4-core/:solmate/=contracts/v4-core/lib/solmate/",
    "contracts/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=contracts/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "contracts/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=contracts/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
    "contracts/v4-core/lib/solmate/:ds-test/=contracts/v4-core/lib/solmate/lib/ds-test/src/",
    "lib/create3-factory/:solmate/=lib/create3-factory/lib/solmate/src/",
    "lib/create3-factory/lib/forge-std/:ds-test/=lib/create3-factory/lib/forge-std/lib/ds-test/src/",
    "lib/create3-factory/lib/solmate/:ds-test/=lib/create3-factory/lib/solmate/lib/ds-test/src/",
    "lib/openzeppelin-contracts-upgradeable/:erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
    "lib/openzeppelin-contracts-upgradeable/:halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
    "lib/openzeppelin-contracts-upgradeable/:openzeppelin-contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/",
    "lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/:erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/:halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "lib/openzeppelin-contracts/:erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/openzeppelin-contracts/:halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "lib/unruggable-gateways/:openzeppelin-contracts/=lib/unruggable-gateways/lib/openzeppelin-contracts/",
    "lib/unruggable-gateways/lib/openzeppelin-contracts/:erc4626-tests/=lib/unruggable-gateways/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "lib/unruggable-gateways/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=lib/unruggable-gateways/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
    "node_modules/@arbitrum/chain-actions/lib/forge-std/:ds-test/=node_modules/@arbitrum/chain-actions/lib/forge-std/lib/ds-test/",
    "node_modules/@arbitrum/token-bridge-contracts/:@arbitrum/nitro-contracts/=node_modules/@arbitrum/token-bridge-contracts/node_modules/@arbitrum/nitro-contracts/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.