ETH Price: $2,118.67 (+6.99%)

Contract

0xfDAc54ef2A98c37405F759D42DeDF05bb2Ea0a4A
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

1 Internal Transaction found.

Latest 1 internal transaction

Advanced mode:
Parent Transaction Hash Method Block
From
To
0x61215a61245687862026-03-02 9:12:232 days ago1772442743  Contract Creation0 ETH
Loading...
Loading
Loading...
Loading
Cross-Chain Transactions

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
UniswapV4Lib

Compiler Version
v0.8.25+commit.b61c2a91

Optimization Enabled:
Yes with 1 runs

Other Settings:
cancun EvmVersion
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.21;

import { Currency } from "../../lib/uniswap-v4-core/src/types/Currency.sol";
import { PoolKey }  from "../../lib/uniswap-v4-core/src/types/PoolKey.sol";

import { IV4Router }    from "../../lib/uniswap-v4-periphery/src/interfaces/IV4Router.sol";
import { Actions }      from "../../lib/uniswap-v4-periphery/src/libraries/Actions.sol";
import { PositionInfo } from "../../lib/uniswap-v4-periphery/src/libraries/PositionInfoLibrary.sol";

import { IERC20Like, IPermit2Like }                   from "../interfaces/Common.sol";
import { IALMProxy }                                  from "../interfaces/IALMProxy.sol";
import { IRateLimits }                                from "../interfaces/IRateLimits.sol";
import { IPositionManagerLike, IUniversalRouterLike } from "../interfaces/UniswapV4.sol";

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

library UniswapV4Lib {

    struct TickLimits {
        int24  tickLowerMin;
        int24  tickUpperMax;
        uint24 maxTickSpacing;
    }

    bytes32 public constant LIMIT_DEPOSIT  = keccak256("LIMIT_UNISWAP_V4_DEPOSIT");
    bytes32 public constant LIMIT_WITHDRAW = keccak256("LIMIT_UNISWAP_V4_WITHDRAW");
    bytes32 public constant LIMIT_SWAP     = keccak256("LIMIT_UNISWAP_V4_SWAP");

    uint256 internal constant _V4_SWAP = 0x10;

    // NOTE: From https://docs.uniswap.org/contracts/v4/deployments (Ethereum Mainnet).
    address internal constant _PERMIT2          = 0x000000000022D473030F116dDEE9F6B43aC78BA3;
    address internal constant _POSITION_MANAGER = 0xbD216513d74C8cf14cf4747E6AaA6420FF64ee9e;
    address internal constant _ROUTER           = 0x66a9893cC07D91D95644AEDD05D03f95e1dBA8Af;

    /**********************************************************************************************/
    /*** Interactive Functions                                                                  ***/
    /**********************************************************************************************/

    function mintPosition(
        address proxy,
        address rateLimits,
        bytes32 poolId,
        int24   tickLower,
        int24   tickUpper,
        uint128 liquidity,
        uint128 amount0Max,
        uint128 amount1Max,
        mapping(bytes32 poolId => TickLimits tickLimits) storage tickLimits
    )
        external
    {
        _checkTickLimits(tickLimits[poolId], tickLower, tickUpper);

        PoolKey memory poolKey = _getPoolKeyFromPoolId(poolId);

        _requirePoolIdMatch(poolId, poolKey);

        bytes memory callData = _getMintCalldata({
            poolKey    : poolKey,
            tickLower  : tickLower,
            tickUpper  : tickUpper,
            liquidity  : liquidity,
            amount0Max : amount0Max,
            amount1Max : amount1Max,
            proxy      : proxy
        });

        _increaseLiquidity({
            proxy      : proxy,
            rateLimits : rateLimits,
            poolId     : poolId,
            token0     : Currency.unwrap(poolKey.currency0),
            token1     : Currency.unwrap(poolKey.currency1),
            amount0Max : amount0Max,
            amount1Max : amount1Max,
            callData   : callData
        });
    }

    function increasePosition(
        address proxy,
        address rateLimits,
        bytes32 poolId,
        uint256 tokenId,
        uint128 liquidityIncrease,
        uint128 amount0Max,
        uint128 amount1Max,
        mapping(bytes32 poolId => TickLimits tickLimits) storage tickLimits
    )
        external
    {
        // Must not increase liquidity on a position that is not owned by the ALMProxy.
        require(
            IPositionManagerLike(_POSITION_MANAGER).ownerOf(tokenId) == proxy,
            "MC/non-proxy-position"
        );

        ( PoolKey memory poolKey, PositionInfo info ) = _getPoolKeyAndPositionInfo(tokenId);

        _requirePoolIdMatch(poolId, poolKey);

        // Since funds are being added to the position, the ticks of the position need to be checked
        // against the current constraints, since it's possible the position was minted under
        // outdated tick limits, or was transferred to the proxy.
        _checkTickLimits(tickLimits[poolId], info.tickLower(), info.tickUpper());

        bytes memory callData = _getIncreaseLiquidityCallData({
            poolKey           : poolKey,
            tokenId           : tokenId,
            liquidityIncrease : liquidityIncrease,
            amount0Max        : amount0Max,
            amount1Max        : amount1Max
        });

        _increaseLiquidity({
            proxy      : proxy,
            rateLimits : rateLimits,
            poolId     : poolId,
            token0     : Currency.unwrap(poolKey.currency0),
            token1     : Currency.unwrap(poolKey.currency1),
            amount0Max : amount0Max,
            amount1Max : amount1Max,
            callData   : callData
        });
    }

    function decreasePosition(
        address proxy,
        address rateLimits,
        bytes32 poolId,
        uint256 tokenId,
        uint128 liquidityDecrease,
        uint128 amount0Min,
        uint128 amount1Min
    )
        external
    {
        PoolKey memory poolKey = _getPoolKeyFromTokenId(tokenId);

        // NOTE: No need to check the token ownership here, as the proxy will be defined as the
        //       recipient of the tokens, so the worst case is that another account's position is
        //       decreased or closed by the proxy.
        _requirePoolIdMatch(poolId, poolKey);

        bytes memory callData = _getDecreaseLiquidityCallData({
            proxy             : proxy,
            poolKey           : poolKey,
            tokenId           : tokenId,
            liquidityDecrease : liquidityDecrease,
            amount0Min        : amount0Min,
            amount1Min        : amount1Min
        });

        _decreaseLiquidity({
            proxy      : proxy,
            rateLimits : rateLimits,
            poolId     : poolId,
            token0     : Currency.unwrap(poolKey.currency0),
            token1     : Currency.unwrap(poolKey.currency1),
            callData   : callData
        });
    }

    function swap(
        address proxy,
        address rateLimits,
        bytes32 poolId,
        address tokenIn,
        uint128 amountIn,
        uint128 amountOutMin,
        uint256 maxSlippage
    )
        external
    {
        require(maxSlippage != 0, "MC/max-slippage-not-set");

        PoolKey memory poolKey = _getPoolKeyFromPoolId(poolId);

        _requirePoolIdMatch(poolId, poolKey);

        require(
            tokenIn == Currency.unwrap(poolKey.currency0) ||
            tokenIn == Currency.unwrap(poolKey.currency1),
            "MC/invalid-tokenIn"
        );

        // Perform rate limit decrease.
        // NOTE: Rate limit decrease does not account for the net amount of tokenIn actually taken.
        IRateLimits(rateLimits).triggerRateLimitDecrease(
            RateLimitHelpers.makeBytes32Key(LIMIT_SWAP, poolId),
            _getNormalizedBalance(tokenIn, amountIn)
        );

        bytes memory actions = abi.encodePacked(
            uint8(Actions.SWAP_EXACT_IN_SINGLE),
            uint8(Actions.SETTLE_ALL),
            uint8(Actions.TAKE_ALL)
        );

        bool zeroForOne = tokenIn == Currency.unwrap(poolKey.currency0);

        address tokenOut = zeroForOne
            ? Currency.unwrap(poolKey.currency1)
            : Currency.unwrap(poolKey.currency0);

        require(
            _getNormalizedBalance(tokenOut, amountOutMin) * 1e18 >=
            _getNormalizedBalance(tokenIn, amountIn) * maxSlippage,
            "MC/amountOutMin-too-low"
        );

        bytes[] memory params = new bytes[](3);

        params[0] = abi.encode(
            IV4Router.ExactInputSingleParams({
                poolKey          : poolKey,
                zeroForOne       : zeroForOne,
                amountIn         : amountIn,
                amountOutMinimum : amountOutMin,
                hookData         : bytes("")
            })
        );

        params[1] = abi.encode(tokenIn,  amountIn);
        params[2] = abi.encode(tokenOut, amountOutMin);

        // Combine actions and params into inputs.
        bytes[] memory inputs = new bytes[](1);

        inputs[0] = abi.encode(actions, params);

        _approveWithPermit2(proxy, tokenIn, _ROUTER, amountIn);

        // Perform action.
        IALMProxy(proxy).doCall(
            _ROUTER,
            abi.encodeCall(
                IUniversalRouterLike.execute,
                (abi.encodePacked(uint8(_V4_SWAP)), inputs, block.timestamp)
            )
        );

        // Reset approval of Permit2 in tokenIn.
        _approveWithPermit2(proxy, tokenIn, _ROUTER, 0);
    }

    /**********************************************************************************************/
    /*** Internal Interactive Functions                                                         ***/
    /**********************************************************************************************/

    function _approveWithPermit2(
        address proxy,
        address token,
        address spender,
        uint128 amount
    )
        internal
    {
        // Approve the Permit2 contract to spend none of the token (success is optional).
        // NOTE: We don't care about the success of this call, since the only outcomes are:
        //         - the allowance is 0 (it was reset or was already 0)
        //         - the allowance is not 0, in which case the success of the overall set of
        //           operations is dependent on the success of the subsequent calls.
        //       In other words, this is a convenience call that may not even be needed for success.
        proxy.call(
            abi.encodeCall(
                IALMProxy.doCall,
                (token, abi.encodeCall(IERC20Like.approve, (_PERMIT2, 0)))
            )
        );

        if (amount != 0) {
            // Approve the Permit2 contract to spend the amount of token (success is mandatory).
            bytes memory approveResult = IALMProxy(proxy).doCall(
                token,
                abi.encodeCall(IERC20Like.approve, (_PERMIT2, amount))
            );

            // Revert if approve returns anything, and that anything is not `true`.
            require(
                approveResult.length == 0 ||
                (approveResult.length == 32 && abi.decode(approveResult, (bool))),
                "MC/permit2-approve-failed"
            );
        }

        // Finally, approve the spender to spend the token via Permit2.
        IALMProxy(proxy).doCall(
            _PERMIT2,
            abi.encodeCall(
                IPermit2Like.approve,
                (token, spender, uint160(amount), uint48(block.timestamp))
            )
        );
    }

    function _increaseLiquidity(
        address        proxy,
        address        rateLimits,
        bytes32        poolId,
        address        token0,
        address        token1,
        uint128        amount0Max,
        uint128        amount1Max,
        bytes   memory callData
    )
        internal
    {
        _approveWithPermit2(proxy, token0, _POSITION_MANAGER, amount0Max);
        _approveWithPermit2(proxy, token1, _POSITION_MANAGER, amount1Max);

        // Get token balances before liquidity increase.
        uint256 startingBalance0 = _getBalance(token0, proxy);
        uint256 startingBalance1 = _getBalance(token1, proxy);

        // Perform action
        IALMProxy(proxy).doCall(_POSITION_MANAGER, callData);

        // Get token balances after liquidity increase.
        uint256 endingBalance0 = _getBalance(token0, proxy);
        uint256 endingBalance1 = _getBalance(token1, proxy);

        // Account for the theoretical possibility of receiving tokens when adding liquidity by
        // using a clamped subtraction.
        // NOTE: The limitation of this integration is the assumption that the tokens are valued
        //       equally (i.e. 1.000000 USDC = 1.000000000000000000 USDS).
        uint256 rateLimitDecrease = _clampedSub(
            _getNormalizedBalance(token0, startingBalance0) +
            _getNormalizedBalance(token1, startingBalance1),
            _getNormalizedBalance(token0, endingBalance0) +
            _getNormalizedBalance(token1, endingBalance1)
        );

        // Perform rate limit decrease.
        // NOTE: Rate limit decrease is net of any token0 or token1 received due to fees.
        IRateLimits(rateLimits).triggerRateLimitDecrease(
            RateLimitHelpers.makeBytes32Key(LIMIT_DEPOSIT, poolId),
            rateLimitDecrease
        );

        // Reset approvals for token0 and token1.
        _approveWithPermit2(proxy, token0, _POSITION_MANAGER, 0);
        _approveWithPermit2(proxy, token1, _POSITION_MANAGER, 0);
    }

    function _decreaseLiquidity(
        address        proxy,
        address        rateLimits,
        bytes32        poolId,
        address        token0,
        address        token1,
        bytes   memory callData
    )
        internal
    {
        // Get token balances before liquidity decrease.
        uint256 startingBalance0 = _getBalance(token0, proxy);
        uint256 startingBalance1 = _getBalance(token1, proxy);

        // Perform action.
        IALMProxy(proxy).doCall(_POSITION_MANAGER, callData);

        // Get token balances after liquidity decrease.
        uint256 endingBalance0 = _getBalance(token0, proxy);
        uint256 endingBalance1 = _getBalance(token1, proxy);

        // NOTE: The limitation of this integration is the assumption that the tokens are valued
        //       equally (i.e. 1.000000 USDC = 1.000000000000000000 USDS).
        uint256 rateLimitDecrease =
            _getNormalizedBalance(token0, endingBalance0 - startingBalance0) +
            _getNormalizedBalance(token1, endingBalance1 - startingBalance1);

        // Perform rate limit decrease.
        // NOTE: Rate limit decrease includes any token0 or token1 received due to fees.
        IRateLimits(rateLimits).triggerRateLimitDecrease(
            RateLimitHelpers.makeBytes32Key(LIMIT_WITHDRAW, poolId),
            rateLimitDecrease
        );
    }

    /**********************************************************************************************/
    /*** Internal View/Pure Functions                                                           ***/
    /**********************************************************************************************/

    function _checkTickLimits(TickLimits memory limits, int24 tickLower, int24 tickUpper)
        internal pure
    {
        require(limits.maxTickSpacing != 0,       "MC/tickLimits-not-set");
        require(tickLower < tickUpper,            "MC/ticks-misordered");
        require(tickLower >= limits.tickLowerMin, "MC/tickLower-too-low");
        require(tickUpper <= limits.tickUpperMax, "MC/tickUpper-too-high");

        require(
            uint256(int256(tickUpper) - int256(tickLower)) <= limits.maxTickSpacing,
            "MC/tickSpacing-too-wide"
        );
    }

    function _clampedSub(uint256 a, uint256 b) internal pure returns (uint256 c) {
        return a > b ? a - b : 0;
    }

    function _getBalance(address token, address account) internal view returns (uint256 balance) {
        return IERC20Like(token).balanceOf(account);
    }

    function _getMintCalldata(
        address        proxy,
        PoolKey memory poolKey,
        int24          tickLower,
        int24          tickUpper,
        uint128        liquidity,
        uint128        amount0Max,
        uint128        amount1Max
    )
        internal view returns (bytes memory callData)
    {
        bytes memory actions = abi.encodePacked(
            uint8(Actions.MINT_POSITION),
            uint8(Actions.CLOSE_CURRENCY),
            uint8(Actions.CLOSE_CURRENCY)
        );

        bytes[] memory params = new bytes[](3);

        params[0] = abi.encode(
            poolKey,             // Which pool to mint in
            tickLower,           // Position's lower price bound
            tickUpper,           // Position's upper price bound
            uint256(liquidity),  // Amount of liquidity to mint
            amount0Max,          // Maximum amount of token0 to use
            amount1Max,          // Maximum amount of token1 to use
            proxy,               // NFT recipient
            ""                   // No hook data needed
        );

        params[1] = abi.encode(poolKey.currency0); // First token to close
        params[2] = abi.encode(poolKey.currency1); // Second token to close

        return _getModifyLiquiditiesCallData(actions, params);
    }

    function _getIncreaseLiquidityCallData(
        PoolKey memory poolKey,
        uint256        tokenId,
        uint128        liquidityIncrease,
        uint128        amount0Max,
        uint128        amount1Max
    )
        internal view returns (bytes memory callData)
    {
        bytes memory actions = abi.encodePacked(
            uint8(Actions.INCREASE_LIQUIDITY),
            uint8(Actions.CLOSE_CURRENCY),
            uint8(Actions.CLOSE_CURRENCY)
        );

        bytes[] memory params = new bytes[](3);

        params[0] = abi.encode(
            tokenId,                     // Position to increase
            uint256(liquidityIncrease),  // Amount to add
            amount0Max,                  // Maximum token0 to spend
            amount1Max,                  // Maximum token1 to spend
            ""                           // No hook data needed
        );

        params[1] = abi.encode(poolKey.currency0); // First token to close
        params[2] = abi.encode(poolKey.currency1); // Second token to close

        return _getModifyLiquiditiesCallData(actions, params);
    }

    function _getDecreaseLiquidityCallData(
        address        proxy,
        PoolKey memory poolKey,
        uint256        tokenId,
        uint128        liquidityDecrease,
        uint128        amount0Min,
        uint128        amount1Min
    )
        internal view returns (bytes memory callData)
    {
        bytes memory actions = abi.encodePacked(
            uint8(Actions.DECREASE_LIQUIDITY),
            uint8(Actions.TAKE_PAIR)
        );

        bytes[] memory params = new bytes[](2);

        params[0] = abi.encode(
            tokenId,                     // Position to decrease
            uint256(liquidityDecrease),  // Amount to remove
            amount0Min,                  // Minimum token0 to receive
            amount1Min,                  // Minimum token1 to receive
            ""                           // No hook data needed
        );

        params[1] = abi.encode(
            poolKey.currency0,  // First token
            poolKey.currency1,  // Second token
            proxy               // Who receives the tokens
        );

        return _getModifyLiquiditiesCallData(actions, params);
    }

    function _getModifyLiquiditiesCallData(bytes memory actions, bytes[] memory params)
        internal view returns (bytes memory callData)
    {
        return abi.encodeCall(
            IPositionManagerLike.modifyLiquidities,
            (abi.encode(actions, params), block.timestamp)
        );
    }

    function _getNormalizedBalance(address token, uint256 balance)
        internal view returns (uint256 normalizedBalance)
    {
        return balance * 1e18 / (10 ** IERC20Like(token).decimals());
    }

    function _getPoolKeyAndPositionInfo(uint256 tokenId)
        internal view returns (PoolKey memory poolKey, PositionInfo info)
    {
        return IPositionManagerLike(_POSITION_MANAGER).getPoolAndPositionInfo(tokenId);
    }

    function _getPoolKeyFromPoolId(bytes32 poolId) internal view returns (PoolKey memory poolKey) {
        return IPositionManagerLike(_POSITION_MANAGER).poolKeys(bytes25(poolId));
    }

    function _getPoolKeyFromTokenId(uint256 tokenId)
        internal view returns (PoolKey memory poolKey)
    {
        (poolKey, ) = _getPoolKeyAndPositionInfo(tokenId);
    }

    function _requirePoolIdMatch(bytes32 poolId, PoolKey memory poolKey) internal pure {
        require(keccak256(abi.encode(poolKey)) == poolId, "MC/poolKey-poolId-mismatch");
    }

}

// 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)));
    }
}

File 3 of 26 : 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;
}

File 4 of 26 : IV4Router.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";
import {PathKey} from "../libraries/PathKey.sol";
import {IImmutableState} from "./IImmutableState.sol";

/// @title IV4Router
/// @notice Interface for the V4Router contract
interface IV4Router is IImmutableState {
    /// @notice Emitted when an exactInput swap does not receive its minAmountOut
    error V4TooLittleReceived(uint256 minAmountOutReceived, uint256 amountReceived);
    /// @notice Emitted when an exactOutput is asked for more than its maxAmountIn
    error V4TooMuchRequested(uint256 maxAmountInRequested, uint256 amountRequested);
    /// @notice Emitted when an exactInput swap does not receive its relative minAmountOut per hop (max price)
    error V4TooLittleReceivedPerHop(uint256 hopIndex, uint256 maxPrice, uint256 price);
    /// @notice Emitted when an exactOutput is asked for more than its relative maxAmountIn per hop (max price)
    error V4TooMuchRequestedPerHop(uint256 hopIndex, uint256 maxPrice, uint256 price);
    /// @notice Emitted when the length of the maxHopSlippage array is not zero and not equal to the path length
    error InvalidHopSlippageLength();

    /// @notice Parameters for a single-hop exact-input swap
    struct ExactInputSingleParams {
        PoolKey poolKey;
        bool zeroForOne;
        uint128 amountIn;
        uint128 amountOutMinimum;
        bytes hookData;
    }

    /// @notice Parameters for a multi-hop exact-input swap
    struct ExactInputParams {
        Currency currencyIn;
        PathKey[] path;
        uint256[] maxHopSlippage;
        uint128 amountIn;
        uint128 amountOutMinimum;
    }

    /// @notice Parameters for a single-hop exact-output swap
    struct ExactOutputSingleParams {
        PoolKey poolKey;
        bool zeroForOne;
        uint128 amountOut;
        uint128 amountInMaximum;
        bytes hookData;
    }

    /// @notice Parameters for a multi-hop exact-output swap
    struct ExactOutputParams {
        Currency currencyOut;
        PathKey[] path;
        uint256[] maxHopSlippage;
        uint128 amountOut;
        uint128 amountInMaximum;
    }
}

File 5 of 26 : Actions.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @notice Library to define different pool actions.
/// @dev These are suggested common commands, however additional commands should be defined as required
/// Some of these actions are not supported in the Router contracts or Position Manager contracts, but are left as they may be helpful commands for other peripheral contracts.
library Actions {
    // pool actions
    // liquidity actions
    uint256 internal constant INCREASE_LIQUIDITY = 0x00;
    uint256 internal constant DECREASE_LIQUIDITY = 0x01;
    uint256 internal constant MINT_POSITION = 0x02;
    uint256 internal constant BURN_POSITION = 0x03;
    uint256 internal constant INCREASE_LIQUIDITY_FROM_DELTAS = 0x04;
    uint256 internal constant MINT_POSITION_FROM_DELTAS = 0x05;

    // swapping
    uint256 internal constant SWAP_EXACT_IN_SINGLE = 0x06;
    uint256 internal constant SWAP_EXACT_IN = 0x07;
    uint256 internal constant SWAP_EXACT_OUT_SINGLE = 0x08;
    uint256 internal constant SWAP_EXACT_OUT = 0x09;

    // donate
    // note this is not supported in the position manager or router
    uint256 internal constant DONATE = 0x0a;

    // closing deltas on the pool manager
    // settling
    uint256 internal constant SETTLE = 0x0b;
    uint256 internal constant SETTLE_ALL = 0x0c;
    uint256 internal constant SETTLE_PAIR = 0x0d;
    // taking
    uint256 internal constant TAKE = 0x0e;
    uint256 internal constant TAKE_ALL = 0x0f;
    uint256 internal constant TAKE_PORTION = 0x10;
    uint256 internal constant TAKE_PAIR = 0x11;

    uint256 internal constant CLOSE_CURRENCY = 0x12;
    uint256 internal constant CLEAR_OR_TAKE = 0x13;
    uint256 internal constant SWEEP = 0x14;

    uint256 internal constant WRAP = 0x15;
    uint256 internal constant UNWRAP = 0x16;

    // minting/burning 6909s to close deltas
    // note this is not supported in the position manager or router
    uint256 internal constant MINT_6909 = 0x17;
    uint256 internal constant BURN_6909 = 0x18;
}

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

import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
import {PoolId} from "@uniswap/v4-core/src/types/PoolId.sol";

/**
 * @dev PositionInfo is a packed version of solidity structure.
 * Using the packaged version saves gas and memory by not storing the structure fields in memory slots.
 *
 * Layout:
 * 200 bits poolId | 24 bits tickUpper | 24 bits tickLower | 8 bits hasSubscriber
 *
 * Fields in the direction from the least significant bit:
 *
 * A flag to know if the tokenId is subscribed to an address
 * uint8 hasSubscriber;
 *
 * The tickUpper of the position
 * int24 tickUpper;
 *
 * The tickLower of the position
 * int24 tickLower;
 *
 * The truncated poolId. Truncates a bytes32 value so the most signifcant (highest) 200 bits are used.
 * bytes25 poolId;
 *
 * Note: If more bits are needed, hasSubscriber can be a single bit.
 *
 */
type PositionInfo is uint256;

using PositionInfoLibrary for PositionInfo global;

library PositionInfoLibrary {
    PositionInfo internal constant EMPTY_POSITION_INFO = PositionInfo.wrap(0);

    uint256 internal constant MASK_UPPER_200_BITS = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000;
    uint256 internal constant MASK_8_BITS = 0xFF;
    uint24 internal constant MASK_24_BITS = 0xFFFFFF;
    uint256 internal constant SET_UNSUBSCRIBE = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00;
    uint256 internal constant SET_SUBSCRIBE = 0x01;
    uint8 internal constant TICK_LOWER_OFFSET = 8;
    uint8 internal constant TICK_UPPER_OFFSET = 32;

    /// @dev This poolId is NOT compatible with the poolId used in UniswapV4 core. It is truncated to 25 bytes, and just used to lookup PoolKey in the poolKeys mapping.
    function poolId(PositionInfo info) internal pure returns (bytes25 _poolId) {
        assembly ("memory-safe") {
            _poolId := and(MASK_UPPER_200_BITS, info)
        }
    }

    function tickLower(PositionInfo info) internal pure returns (int24 _tickLower) {
        assembly ("memory-safe") {
            _tickLower := signextend(2, shr(TICK_LOWER_OFFSET, info))
        }
    }

    function tickUpper(PositionInfo info) internal pure returns (int24 _tickUpper) {
        assembly ("memory-safe") {
            _tickUpper := signextend(2, shr(TICK_UPPER_OFFSET, info))
        }
    }

    function hasSubscriber(PositionInfo info) internal pure returns (bool _hasSubscriber) {
        assembly ("memory-safe") {
            _hasSubscriber := and(MASK_8_BITS, info)
        }
    }

    /// @dev this does not actually set any storage
    function setSubscribe(PositionInfo info) internal pure returns (PositionInfo _info) {
        assembly ("memory-safe") {
            _info := or(info, SET_SUBSCRIBE)
        }
    }

    /// @dev this does not actually set any storage
    function setUnsubscribe(PositionInfo info) internal pure returns (PositionInfo _info) {
        assembly ("memory-safe") {
            _info := and(info, SET_UNSUBSCRIBE)
        }
    }

    /// @notice Creates the default PositionInfo struct
    /// @dev Called when minting a new position
    /// @param _poolKey the pool key of the position
    /// @param _tickLower the lower tick of the position
    /// @param _tickUpper the upper tick of the position
    /// @return info packed position info, with the truncated poolId and the hasSubscriber flag set to false
    function initialize(PoolKey memory _poolKey, int24 _tickLower, int24 _tickUpper)
        internal
        pure
        returns (PositionInfo info)
    {
        bytes25 _poolId = bytes25(PoolId.unwrap(_poolKey.toId()));
        assembly {
            info := or(
                or(and(MASK_UPPER_200_BITS, _poolId), shl(TICK_UPPER_OFFSET, and(MASK_24_BITS, _tickUpper))),
                shl(TICK_LOWER_OFFSET, and(MASK_24_BITS, _tickLower))
            )
        }
    }
}

// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.21;

interface IERC20Like {

    function approve(address spender, uint256 amount) external returns (bool success);

    function balanceOf(address account) external view returns (uint256 balance);

    function decimals() external view returns (uint8 decimals);

}

interface IPermit2Like {

    function approve(address token, address spender, uint160 amount, uint48 expiration) external;

}

// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity >=0.8.0;

import { IAccessControl } from "openzeppelin-contracts/contracts/access/IAccessControl.sol";

interface IALMProxy is IAccessControl {

    /**
     * @dev    This function retrieves a constant `bytes32` value that represents the controller.
     * @return The `bytes32` identifier of the controller.
     */
    function CONTROLLER() external view returns (bytes32);

    /**
     * @dev    Performs a standard call to the specified `target` with the given `data`.
     *         Reverts if the call fails.
     * @param  target The address of the target contract to call.
     * @param  data   The calldata that will be sent to the target contract.
     * @return result The returned data from the call.
     */
    function doCall(address target, bytes calldata data)
        external returns (bytes memory result);

    /**
     * @dev    This function allows for transferring `value` (ether) along with the call to the target contract.
     *         Reverts if the call fails.
     * @param  target The address of the target contract to call.
     * @param  data   The calldata that will be sent to the target contract.
     * @param  value  The amount of Ether (in wei) to send with the call.
     * @return result The returned data from the call.
     */
    function doCallWithValue(address target, bytes memory data, uint256 value)
        external payable returns (bytes memory result);

    /**
     * @dev    This function performs a delegate call to the specified `target`
     *         with the given `data`. Reverts if the call fails.
     * @param  target The address of the target contract to delegate call.
     * @param  data   The calldata that will be sent to the target contract.
     * @return result The returned data from the delegate call.
     */
    function doDelegateCall(address target, bytes calldata data)
        external returns (bytes memory result);

}

// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity >=0.8.0;

import { IAccessControl } from "openzeppelin-contracts/contracts/access/IAccessControl.sol";

interface IRateLimits is IAccessControl {

    /**********************************************************************************************/
    /*** Structs                                                                                ***/
    /**********************************************************************************************/

    /**
     * @dev   Struct representing a rate limit.
     *        The current rate limit is calculated using the formula:
     *        `currentRateLimit = min(slope * (block.timestamp - lastUpdated) + lastAmount, maxAmount)`.
     * @param maxAmount   Maximum allowed amount at any time.
     * @param slope       The slope of the rate limit, used to calculate the new
     *                    limit based on time passed. [tokens / second]
     * @param lastAmount  The amount left available at the last update.
     * @param lastUpdated The timestamp when the rate limit was last updated.
     */
    struct RateLimitData {
        uint256 maxAmount;
        uint256 slope;
        uint256 lastAmount;
        uint256 lastUpdated;
    }

    /**********************************************************************************************/
    /*** Events                                                                                 ***/
    /**********************************************************************************************/

    /**
     * @dev   Emitted when the rate limit data is set.
     * @param key         The identifier for the rate limit.
     * @param maxAmount   The maximum allowed amount for the rate limit.
     * @param slope       The slope value used in the rate limit calculation.
     * @param lastAmount  The amount left available at the last update.
     * @param lastUpdated The timestamp when the rate limit was last updated.
     */
    event RateLimitDataSet(
        bytes32 indexed key,
        uint256 maxAmount,
        uint256 slope,
        uint256 lastAmount,
        uint256 lastUpdated
    );

    /**
     * @dev   Emitted when a rate limit decrease is triggered.
     * @param key              The identifier for the rate limit.
     * @param amountToDecrease The amount to decrease from the current rate limit.
     * @param oldRateLimit     The previous rate limit value before triggering.
     * @param newRateLimit     The new rate limit value after triggering.
     */
    event RateLimitDecreaseTriggered(
        bytes32 indexed key,
        uint256 amountToDecrease,
        uint256 oldRateLimit,
        uint256 newRateLimit
    );

    /**
     * @dev   Emitted when a rate limit increase is triggered.
     * @param key              The identifier for the rate limit.
     * @param amountToIncrease The amount to increase from the current rate limit.
     * @param oldRateLimit     The previous rate limit value before triggering.
     * @param newRateLimit     The new rate limit value after triggering.
     */
    event RateLimitIncreaseTriggered(
        bytes32 indexed key,
        uint256 amountToIncrease,
        uint256 oldRateLimit,
        uint256 newRateLimit
    );

    /**********************************************************************************************/
    /*** State variables                                                                        ***/
    /**********************************************************************************************/

    /**
     * @dev    Returns the controller identifier as a bytes32 value.
     * @return The controller identifier.
     */
    function CONTROLLER() external view returns (bytes32);

    /**********************************************************************************************/
    /*** Admin functions                                                                        ***/
    /**********************************************************************************************/

    /**
     * @dev   Sets rate limit data for a specific key.
     * @param key         The identifier for the rate limit.
     * @param maxAmount   The maximum allowed amount for the rate limit.
     * @param slope       The slope value used in the rate limit calculation.
     * @param lastAmount  The amount left available at the last update.
     * @param lastUpdated The timestamp when the rate limit was last updated.
     */
    function setRateLimitData(
        bytes32 key,
        uint256 maxAmount,
        uint256 slope,
        uint256 lastAmount,
        uint256 lastUpdated
    ) external;

    /**
     * @dev   Sets rate limit data for a specific key with
     *        `lastAmount == maxAmount` and `lastUpdated == block.timestamp`.
     * @param key       The identifier for the rate limit.
     * @param maxAmount The maximum allowed amount for the rate limit.
     * @param slope     The slope value used in the rate limit calculation.
     */
    function setRateLimitData(bytes32 key, uint256 maxAmount, uint256 slope) external;

    /**
     * @dev   Sets an unlimited rate limit.
     * @param key The identifier for the rate limit.
     */
    function setUnlimitedRateLimitData(bytes32 key) external;

    /**********************************************************************************************/
    /*** Getter Functions                                                                       ***/
    /**********************************************************************************************/

    /**
     * @dev    Retrieves the RateLimitData struct associated with a specific key.
     * @param  key The identifier for the rate limit.
     * @return The data associated with the rate limit.
     */
    function getRateLimitData(bytes32 key) external view returns (RateLimitData memory);

    /**
     * @dev    Retrieves the current rate limit for a specific key.
     * @param  key The identifier for the rate limit.
     * @return The current rate limit value for the given key.
     */
    function getCurrentRateLimit(bytes32 key) external view returns (uint256);

    /**********************************************************************************************/
    /*** Controller functions                                                                   ***/
    /**********************************************************************************************/

    /**
     * @dev    Triggers the rate limit for a specific key and reduces the available
     *         amount by the provided value.
     * @param  key              The identifier for the rate limit.
     * @param  amountToDecrease The amount to decrease from the current rate limit.
     * @return newLimit         The updated rate limit after the deduction.
     */
    function triggerRateLimitDecrease(bytes32 key, uint256 amountToDecrease)
        external returns (uint256 newLimit);

    /**
     * @dev    Increases the rate limit for a given key up to the maxAmount. Does not revert if
     *         the new rate limit exceeds the maxAmount.
     * @param  key              The identifier for the rate limit.
     * @param  amountToIncrease The amount to increase from the current rate limit.
     * @return newLimit         The updated rate limit after the addition.
     */
    function triggerRateLimitIncrease(bytes32 key, uint256 amountToIncrease)
        external returns (uint256 newLimit);

}

// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.21;

import { PoolId }  from "../../lib/uniswap-v4-core/src/types/PoolId.sol";
import { PoolKey } from "../../lib/uniswap-v4-core/src/types/PoolKey.sol";

import { PositionInfo } from "../../lib/uniswap-v4-periphery/src/libraries/PositionInfoLibrary.sol";

interface IPositionManagerLike {

    function modifyLiquidities(bytes calldata unlockData, uint256 deadline) external payable;

    function getPoolAndPositionInfo(
        uint256 tokenId
    ) external view returns (PoolKey memory poolKey, PositionInfo info);

    function poolKeys(bytes25 poolId) external view returns (PoolKey memory poolKey);

    function ownerOf(uint256 tokenId) external view returns (address owner);

}

interface IUniversalRouterLike {

    function execute(bytes calldata commands, bytes[] calldata inputs, uint256 deadline) external;

}

// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.21;

library RateLimitHelpers {

    function makeAddressKey(bytes32 key, address a) internal pure returns (bytes32) {
        return keccak256(abi.encode(key, a));
    }

    function makeAddressAddressKey(bytes32 key, address a, address b) internal pure returns (bytes32) {
        return keccak256(abi.encode(key, a, b));
    }

    function makeBytes32Key(bytes32 key, bytes32 a) internal pure returns (bytes32) {
        return keccak256(abi.encode(key, a));
    }

    function makeUint32Key(bytes32 key, uint32 a) internal pure returns (bytes32) {
        return keccak256(abi.encode(key, a));
    }

}

// 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);
}

// 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))
        }
    }
}

// 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);
}

// 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)
        }
    }
}

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

import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";
import {IHooks} from "@uniswap/v4-core/src/interfaces/IHooks.sol";
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";

struct PathKey {
    Currency intermediateCurrency;
    uint24 fee;
    int24 tickSpacing;
    IHooks hooks;
    bytes hookData;
}

using PathKeyLibrary for PathKey global;

/// @title PathKey Library
/// @notice Functions for working with PathKeys
library PathKeyLibrary {
    /// @notice Get the pool and swap direction for a given PathKey
    /// @param params the given PathKey
    /// @param currencyIn the input currency
    /// @return poolKey the pool key of the swap
    /// @return zeroForOne the direction of the swap, true if currency0 is being swapped for currency1
    function getPoolAndSwapDirection(PathKey calldata params, Currency currencyIn)
        internal
        pure
        returns (PoolKey memory poolKey, bool zeroForOne)
    {
        Currency currencyOut = params.intermediateCurrency;
        (Currency currency0, Currency currency1) =
            currencyIn < currencyOut ? (currencyIn, currencyOut) : (currencyOut, currencyIn);

        zeroForOne = currencyIn == currency0;
        poolKey = PoolKey(currency0, currency1, params.fee, params.tickSpacing, params.hooks);
    }
}

File 17 of 26 : IImmutableState.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";

/// @title IImmutableState
/// @notice Interface for the ImmutableState contract
interface IImmutableState {
    /// @notice The Uniswap v4 PoolManager contract
    function poolManager() external view returns (IPoolManager);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/IAccessControl.sol)

pragma solidity ^0.8.20;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @dev The `account` is missing a role.
     */
    error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);

    /**
     * @dev The caller of a function is not the expected one.
     *
     * NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
     */
    error AccessControlBadConfirmation();

    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     */
    function renounceRole(bytes32 role, address callerConfirmation) external;
}

// SPDX-License-Identifier: MIT
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)
        }
    }
}

// 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;
}

// 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)
        }
    }
}

// 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));
    }
}

// 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);
}

// 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);
}

// 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);
}

// 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);
}

Settings
{
  "remappings": [
    "@layerzerolabs/oft-evm/=lib/devtools/packages/oft-evm/",
    "layerzerolabs/oapp-evm/=lib/devtools/packages/oapp-evm/",
    "@layerzerolabs/lz-evm-protocol-v2/=lib/layerzero-v2/packages/layerzero-v2/evm/protocol/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "@layerzerolabs/lz-evm-messagelib-v2/=lib/layerzero-v2/packages/layerzero-v2/evm/messagelib/",
    "solidity-bytes-utils/=lib/solidity-bytes-utils/",
    "forge-std/=lib/forge-std/src/",
    "@uniswap/v4-core/=lib/uniswap-v4-core/",
    "@ensdomains/=lib/uniswap-v4-core/node_modules/@ensdomains/",
    "@openzeppelin/contracts-upgradeable/=lib/sdai/lib/openzeppelin-contracts-upgradeable/contracts/",
    "aave-v3-core/=lib/aave-v3-origin/src/core/",
    "aave-v3-origin/=lib/aave-v3-origin/",
    "aave-v3-periphery/=lib/aave-v3-origin/src/periphery/",
    "devtools/=lib/devtools/packages/toolbox-foundry/src/",
    "ds-test/=lib/metamorpho/lib/forge-std/lib/ds-test/src/",
    "dss-allocator/=lib/dss-allocator/",
    "dss-interfaces/=lib/dss-test/lib/dss-interfaces/src/",
    "dss-test/=lib/dss-test/src/",
    "erc20-helpers/=lib/erc20-helpers/src/",
    "erc4626-tests/=lib/metamorpho/lib/erc4626-tests/",
    "forge-gas-snapshot/=lib/uniswap-v4-periphery/lib/permit2/lib/forge-gas-snapshot/src/",
    "halmos-cheatcodes/=lib/spark-vaults-v2/lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
    "hardhat/=lib/uniswap-v4-core/node_modules/hardhat/",
    "layerzero-v2/=lib/layerzero-v2/",
    "metamorpho/=lib/metamorpho/src/",
    "morpho-blue/=lib/metamorpho/lib/morpho-blue/",
    "murky/=lib/metamorpho/lib/universal-rewards-distributor/lib/murky/src/",
    "openzeppelin-contracts-upgradeable/=lib/sdai/lib/openzeppelin-contracts-upgradeable/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "openzeppelin-foundry-upgrades/=lib/sdai/lib/openzeppelin-foundry-upgrades/src/",
    "openzeppelin/=lib/metamorpho/lib/universal-rewards-distributor/lib/openzeppelin-contracts/contracts/",
    "permit2/=lib/uniswap-v4-periphery/lib/permit2/",
    "sdai/=lib/sdai/",
    "solidity-stringutils/=lib/sdai/lib/openzeppelin-foundry-upgrades/lib/solidity-stringutils/",
    "solidity-utils/=lib/aave-v3-origin/lib/solidity-utils/",
    "solmate/=lib/uniswap-v4-core/lib/solmate/",
    "spark-address-registry/=lib/spark-address-registry/src/",
    "spark-psm/=lib/spark-psm/",
    "spark-vaults-v2/=lib/spark-vaults-v2/",
    "sparklend-address-registry/=lib/spark-psm/lib/xchain-ssr-oracle/lib/sparklend-address-registry/",
    "token-tests/=lib/sdai/lib/token-tests/src/",
    "uniswap-v4-core/=lib/uniswap-v4-core/src/",
    "uniswap-v4-periphery/=lib/uniswap-v4-periphery/",
    "universal-rewards-distributor/=lib/metamorpho/lib/universal-rewards-distributor/src/",
    "usds/=lib/usds/",
    "v4-core/=lib/uniswap-v4-periphery/lib/v4-core/src/",
    "xchain-helpers/=lib/xchain-helpers/src/",
    "xchain-ssr-oracle/=lib/spark-psm/lib/xchain-ssr-oracle/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 1
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "cancun",
  "viaIR": false
}

Contract Security Audit

Contract ABI

API
[{"inputs":[],"name":"LIMIT_DEPOSIT","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LIMIT_SWAP","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LIMIT_WITHDRAW","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"}]

61215a610034600b8282823980515f1a607314602857634e487b7160e01b5f525f60045260245ffd5b305f52607381538281f3fe7300000000000000000000000000000000000000003014608060405260043610610076575f3560e01c80631572a72f1461007a57806344237d5f146100a057806375a52251146100c15780639058f93e146100e0578063c881b435146100f4578063d32c5c6114610108578063d63ea7d314610127575b5f80fd5b61008e5f805160206120a583398151915281565b60405190815260200160405180910390f35b8180156100ab575f80fd5b506100bf6100ba3660046117de565b610146565b005b8180156100cc575f80fd5b506100bf6100db36600461185f565b6102bd565b61008e5f8051602061210583398151915281565b61008e5f805160206120e583398151915281565b818015610113575f80fd5b506100bf6101223660046118d8565b6107d3565b818015610132575f80fd5b506100bf61014136600461195d565b61081a565b6040516331a9108f60e11b8152600481018690526001600160a01b038916905f805160206120c583398151915290636352211e90602401602060405180830381865afa158015610198573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101bc91906119f9565b6001600160a01b03161461020f5760405162461bcd60e51b815260206004820152601560248201527426a197b737b716b83937bc3c96b837b9b4ba34b7b760591b60448201526064015b60405180910390fd5b5f8061021a876108a8565b915091506102288883610926565b5f888152602084815260409182902082516060810184529054600281810b835263010000008204810b93830193909352600160301b900462ffffff16928101929092526102899190600884901c900b6102848460201c60020b90565b61099c565b5f6102978389898989610b42565b90506102b08b8b8b865f015187602001518b8b88610c7a565b5050505050505050505050565b805f036103065760405162461bcd60e51b81526020600482015260176024820152761350cbdb585e0b5cdb1a5c1c1859d94b5b9bdd0b5cd95d604a1b6044820152606401610206565b5f61031086610e5d565b905061031c8682610926565b80516001600160a01b038681169116148061034c575080602001516001600160a01b0316856001600160a01b0316145b61038d5760405162461bcd60e51b815260206004820152601260248201527126a197b4b73b30b634b216ba37b5b2b724b760711b6044820152606401610206565b866001600160a01b0316633bf076b06103b35f805160206120e583398151915289610edf565b6103c688886001600160801b0316610f11565b6040518363ffffffff1660e01b81526004016103e3929190611a14565b6020604051808303815f875af11580156103ff573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906104239190611a22565b505f6006600c600f60405160200161043d93929190611a39565b60408051601f1981840301815291905282519091506001600160a01b038781169116145f8161046d578351610473565b83602001515b90508461048989896001600160801b0316610f11565b6104939190611a77565b6104a682886001600160801b0316610f11565b6104b890670de0b6b3a7640000611a77565b10156105005760405162461bcd60e51b81526020600482015260176024820152764d432f616d6f756e744f75744d696e2d746f6f2d6c6f7760481b6044820152606401610206565b604080516003808252608082019092525f91816020015b60608152602001906001900390816105175790505090506040518060a001604052808681526020018415158152602001896001600160801b03168152602001886001600160801b0316815260200160405180602001604052805f8152508152506040516020016105879190611b13565b604051602081830303815290604052815f815181106105a8576105a8611b76565b602002602001018190525088886040516020016105c6929190611b8a565b604051602081830303815290604052816001815181106105e8576105e8611b76565b60200260200101819052508187604051602001610606929190611b8a565b6040516020818303038152906040528160028151811061062857610628611b76565b60209081029190910101526040805160018082528183019092525f91816020015b60608152602001906001900390816106495790505090508482604051602001610673929190611c04565b604051602081830303815290604052815f8151811061069457610694611b76565b60200260200101819052506106bf8d8b7366a9893cc07d91d95644aedd05d03f95e1dba8af8c610fa0565b604051600160fc1b60208201526001600160a01b038e1690633aada4d2907366a9893cc07d91d95644aedd05d03f95e1dba8af9060210160408051601f19818403018152908290526107179186904290602401611c31565b60408051601f198184030181529181526020820180516001600160e01b0316630d64d59360e21b179052516001600160e01b031960e085901b168152610761929190600401611c66565b5f604051808303815f875af115801561077c573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526107a39190810190611c89565b506107c48d8b7366a9893cc07d91d95644aedd05d03f95e1dba8af5f610fa0565b50505050505050505050505050565b5f6107dd856112a9565b90506107e98682610926565b5f6107f88983888888886112c1565b905061080f898989855f01518660200151866113e0565b505050505050505050565b5f878152602082815260409182902082516060810184529054600281810b835263010000008204900b92820192909252600160301b90910462ffffff169181019190915261086990878761099c565b5f61087388610e5d565b905061087f8882610926565b5f61088f8b838a8a8a8a8a611553565b90506102b08b8b8b855f015186602001518a8a88610c7a565b6108b061177f565b604051637ba03aad60e01b8152600481018390525f905f805160206120c583398151915290637ba03aad9060240160c060405180830381865afa1580156108f9573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061091d9190611dd5565b91509150915091565b81816040516020016109389190611e00565b60405160208183030381529060405280519060200120146109985760405162461bcd60e51b815260206004820152601a60248201527909a865ee0deded896caf25ae0deded892c85adad2e6dac2e8c6d60331b6044820152606401610206565b5050565b826040015162ffffff165f036109ec5760405162461bcd60e51b81526020600482015260156024820152741350cbdd1a58dad31a5b5a5d1ccb5b9bdd0b5cd95d605a1b6044820152606401610206565b8060020b8260020b12610a375760405162461bcd60e51b81526020600482015260136024820152721350cbdd1a58dadccb5b5a5cdbdc99195c9959606a1b6044820152606401610206565b825f015160020b8260020b1215610a875760405162461bcd60e51b81526020600482015260146024820152734d432f7469636b4c6f7765722d746f6f2d6c6f7760601b6044820152606401610206565b826020015160020b8160020b1315610ad95760405162461bcd60e51b815260206004820152601560248201527409a865ee8d2c6d6aae0e0cae45ae8dede5ad0d2ced605b1b6044820152606401610206565b826040015162ffffff168260020b8260020b610af59190611e0e565b1115610b3d5760405162461bcd60e51b81526020600482015260176024820152764d432f7469636b53706163696e672d746f6f2d7769646560481b6044820152606401610206565b505050565b60605f80601280604051602001610b5b93929190611a39565b60408051808303601f1901815260038084526080840190925292505f9190816020015b6060815260200190600190039081610b7e57905050905086866001600160801b03168686604051602001610bb59493929190611e2d565b604051602081830303815290604052815f81518110610bd657610bd6611b76565b6020026020010181905250875f0151604051602001610bf59190611e62565b60405160208183030381529060405281600181518110610c1757610c17611b76565b60200260200101819052508760200151604051602001610c379190611e62565b60405160208183030381529060405281600281518110610c5957610c59611b76565b6020026020010181905250610c6e8282611694565b98975050505050505050565b610c9388865f805160206120c583398151915286610fa0565b610cac88855f805160206120c583398151915285610fa0565b5f610cb7868a6116fa565b90505f610cc4868b6116fa565b604051631d56d26960e11b81529091506001600160a01b038b1690633aada4d290610d02905f805160206120c5833981519152908790600401611c66565b5f604051808303815f875af1158015610d1d573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052610d449190810190611c89565b505f610d50888c6116fa565b90505f610d5d888d6116fa565b90505f610da4610d6d8a86610f11565b610d778c88610f11565b610d819190611e76565b610d8b8b85610f11565b610d958d87610f11565b610d9f9190611e76565b611767565b90508b6001600160a01b0316633bf076b0610dcc5f805160206121058339815191528e610edf565b836040518363ffffffff1660e01b8152600401610dea929190611a14565b6020604051808303815f875af1158015610e06573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e2a9190611a22565b50610e448d8b5f805160206120c58339815191525f610fa0565b6107c48d8a5f805160206120c58339815191525f610fa0565b610e6561177f565b6040516386b6be7d60e01b815266ffffffffffffff19831660048201525f805160206120c5833981519152906386b6be7d9060240160a060405180830381865afa158015610eb5573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ed99190611e89565b92915050565b5f8282604051602001610ef3929190611a14565b60405160208183030381529060405280519060200120905092915050565b5f826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f4e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f729190611ea3565b610f7d90600a611fa3565b610f8f83670de0b6b3a7640000611a77565b610f999190611fb1565b9392505050565b6040516e22d473030f116ddee9f6b43ac78ba360248201525f60448201526001600160a01b03851690849060640160408051601f198184030181529181526020820180516001600160e01b031663095ea7b360e01b17905251611007929190602401611c66565b60408051601f198184030181529181526020820180516001600160e01b0316631d56d26960e11b1790525161103c9190611fd0565b5f604051808303815f865af19150503d805f8114611075576040519150601f19603f3d011682016040523d82523d5f602084013e61107a565b606091505b5050506001600160801b038116156111c1575f846001600160a01b0316633aada4d2856e22d473030f116ddee9f6b43ac78ba3856040516024016110bf929190611b8a565b60408051601f198184030181529181526020820180516001600160e01b031663095ea7b360e01b179052516001600160e01b031960e085901b168152611109929190600401611c66565b5f604051808303815f875af1158015611124573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261114b9190810190611c89565b905080515f14806111775750805160201480156111775750808060200190518101906111779190611fe6565b6111bf5760405162461bcd60e51b81526020600482015260196024820152781350cbdc195c9b5a5d0c8b585c1c1c9bdd994b59985a5b1959603a1b6044820152606401610206565b505b6040516001600160a01b03848116602483015283811660448301526001600160801b038316606483015265ffffffffffff42166084830152851690633aada4d2906e22d473030f116ddee9f6b43ac78ba39060a40160408051601f198184030181529181526020820180516001600160e01b03166387517c4560e01b179052516001600160e01b031960e085901b168152611260929190600401611c66565b5f604051808303815f875af115801561127b573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526112a29190810190611c89565b5050505050565b6112b161177f565b6112ba826108a8565b5092915050565b60408051600160f81b6020820152601160f81b60218201528151600281830381018252602283018181526082840190945260609391925f9291906042015b60608152602001906001900390816112ff57905050905086866001600160801b031686866040516020016113369493929190611e2d565b604051602081830303815290604052815f8151811061135757611357611b76565b6020026020010181905250875f015188602001518a60405160200161139c939291906001600160a01b0393841681529183166020830152909116604082015260600190565b604051602081830303815290604052816001815181106113be576113be611b76565b60200260200101819052506113d38282611694565b9998505050505050505050565b5f6113eb84886116fa565b90505f6113f884896116fa565b604051631d56d26960e11b81529091506001600160a01b03891690633aada4d290611436905f805160206120c5833981519152908790600401611c66565b5f604051808303815f875af1158015611451573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526114789190810190611c89565b505f611484868a6116fa565b90505f611491868b6116fa565b90505f6114a7876114a28685612005565b610f11565b6114b5896114a28887612005565b6114bf9190611e76565b9050896001600160a01b0316633bf076b06114e75f805160206120a58339815191528c610edf565b836040518363ffffffff1660e01b8152600401611505929190611a14565b6020604051808303815f875af1158015611521573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115459190611a22565b505050505050505050505050565b60605f600260128060405160200161156d93929190611a39565b60408051808303601f1901815260038084526080840190925292505f9190816020015b6060815260200190600190039081611590579050509050888888886001600160801b031688888f6040516020016115cd9796959493929190612018565b604051602081830303815290604052815f815181106115ee576115ee611b76565b6020026020010181905250885f015160405160200161160d9190611e62565b6040516020818303038152906040528160018151811061162f5761162f611b76565b6020026020010181905250886020015160405160200161164f9190611e62565b6040516020818303038152906040528160028151811061167157611671611b76565b60200260200101819052506116868282611694565b9a9950505050505050505050565b606082826040516020016116a9929190611c04565b60408051601f19818403018152908290526116c8914290602401612083565b60408051601f198184030181529190526020810180516001600160e01b031663dd46508f60e01b179052905092915050565b6040516370a0823160e01b81525f906001600160a01b038416906370a0823190611728908590600401611e62565b602060405180830381865afa158015611743573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f999190611a22565b5f818311611775575f610f99565b610f998284612005565b6040805160a0810182525f8082526020820181905291810182905260608101829052608081019190915290565b6001600160a01b03811681146117c0575f80fd5b50565b80356001600160801b03811681146117d9575f80fd5b919050565b5f805f805f805f80610100898b0312156117f6575f80fd5b8835611801816117ac565b97506020890135611811816117ac565b9650604089013595506060890135945061182d60808a016117c3565b935061183b60a08a016117c3565b925061184960c08a016117c3565b915060e089013590509295985092959890939650565b5f805f805f805f60e0888a031215611875575f80fd5b8735611880816117ac565b96506020880135611890816117ac565b95506040880135945060608801356118a7816117ac565b93506118b5608089016117c3565b92506118c360a089016117c3565b915060c0880135905092959891949750929550565b5f805f805f805f60e0888a0312156118ee575f80fd5b87356118f9816117ac565b96506020880135611909816117ac565b95506040880135945060608801359350611925608089016117c3565b925061193360a089016117c3565b915061194160c089016117c3565b905092959891949750929550565b8060020b81146117c0575f80fd5b5f805f805f805f805f6101208a8c031215611976575f80fd5b8935611981816117ac565b985060208a0135611991816117ac565b975060408a0135965060608a01356119a88161194f565b955060808a01356119b88161194f565b94506119c660a08b016117c3565b93506119d460c08b016117c3565b92506119e260e08b016117c3565b91506101008a013590509295985092959850929598565b5f60208284031215611a09575f80fd5b8151610f99816117ac565b918252602082015260400190565b5f60208284031215611a32575f80fd5b5051919050565b6001600160f81b031960f894851b8116825292841b83166001820152921b16600282015260030190565b634e487b7160e01b5f52601160045260245ffd5b8082028115828204841417610ed957610ed9611a63565b634e487b7160e01b5f52604160045260245ffd5b80516001600160a01b03908116835260208083015182169084015260408083015162ffffff169084015260608083015160020b9084015260809182015116910152565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b60208152611b25602082018351611aa2565b6020820151151560c082015260408201516001600160801b0390811660e08301526060830151166101008201526080820151610120808301525f90611b6e610140840182611ae5565b949350505050565b634e487b7160e01b5f52603260045260245ffd5b6001600160a01b039290921682526001600160801b0316602082015260400190565b5f8282518085526020808601955060208260051b840101602086015f5b84811015611bf757601f19868403018952611be5838351611ae5565b98840198925090830190600101611bc9565b5090979650505050505050565b604081525f611c166040830185611ae5565b8281036020840152611c288185611bac565b95945050505050565b606081525f611c436060830186611ae5565b8281036020840152611c558186611bac565b915050826040830152949350505050565b6001600160a01b03831681526040602082018190525f90611b6e90830184611ae5565b5f60208284031215611c99575f80fd5b81516001600160401b0380821115611caf575f80fd5b818401915084601f830112611cc2575f80fd5b815181811115611cd457611cd4611a8e565b604051601f8201601f19908116603f01168101908382118183101715611cfc57611cfc611a8e565b81604052828152876020848701011115611d14575f80fd5b8260208601602083015e5f928101602001929092525095945050505050565b5f60a08284031215611d43575f80fd5b60405160a081016001600160401b0381118282101715611d6557611d65611a8e565b80604052508091508251611d78816117ac565b81526020830151611d88816117ac565b6020820152604083015162ffffff81168114611da2575f80fd5b60408201526060830151611db58161194f565b60608201526080830151611dc8816117ac565b6080919091015292915050565b5f8060c08385031215611de6575f80fd5b611df08484611d33565b915060a083015190509250929050565b60a08101610ed98284611aa2565b8181035f8312801583831316838312821617156112ba576112ba611a63565b93845260208401929092526001600160801b03908116604084015216606082015260a0608082018190525f9082015260c00190565b6001600160a01b0391909116815260200190565b80820180821115610ed957610ed9611a63565b5f60a08284031215611e99575f80fd5b610f998383611d33565b5f60208284031215611eb3575f80fd5b815160ff81168114610f99575f80fd5b600181815b80851115611efd57815f1904821115611ee357611ee3611a63565b80851615611ef057918102915b93841c9390800290611ec8565b509250929050565b5f82611f1357506001610ed9565b81611f1f57505f610ed9565b8160018114611f355760028114611f3f57611f5b565b6001915050610ed9565b60ff841115611f5057611f50611a63565b50506001821b610ed9565b5060208310610133831016604e8410600b8410161715611f7e575081810a610ed9565b611f888383611ec3565b805f1904821115611f9b57611f9b611a63565b029392505050565b5f610f9960ff841683611f05565b5f82611fcb57634e487b7160e01b5f52601260045260245ffd5b500490565b5f82518060208501845e5f920191825250919050565b5f60208284031215611ff6575f80fd5b81518015158114610f99575f80fd5b81810381811115610ed957610ed9611a63565b5f610180612026838b611aa2565b600298890b60a08401529690970b60c082015260e08101949094526001600160801b0392831661010085015291166101208301526001600160a01b031661014082015261016081018290525f918101919091526101a00192915050565b604081525f6120956040830185611ae5565b9050826020830152939250505056fec59bd072250d6fc36cd0770967850f0c32937e79afaaaa622062591d6fe7b6cb000000000000000000000000bd216513d74c8cf14cf4747e6aaa6420ff64ee9e225b3b1db609505774121429e4f0d44307067f6c07bce0c5d69868f0cb16acc379c8abd914f784b8449d20ca3d1c1f4d9fd49e46d2a83d5ab3391590751073aca2646970667358221220442f5b7578b7ee463c59ff83ac65ae01dfae441c71bb70e17fccf0cdd15c992564736f6c63430008190033

Deployed Bytecode

0x73fdac54ef2a98c37405f759d42dedf05bb2ea0a4a3014608060405260043610610076575f3560e01c80631572a72f1461007a57806344237d5f146100a057806375a52251146100c15780639058f93e146100e0578063c881b435146100f4578063d32c5c6114610108578063d63ea7d314610127575b5f80fd5b61008e5f805160206120a583398151915281565b60405190815260200160405180910390f35b8180156100ab575f80fd5b506100bf6100ba3660046117de565b610146565b005b8180156100cc575f80fd5b506100bf6100db36600461185f565b6102bd565b61008e5f8051602061210583398151915281565b61008e5f805160206120e583398151915281565b818015610113575f80fd5b506100bf6101223660046118d8565b6107d3565b818015610132575f80fd5b506100bf61014136600461195d565b61081a565b6040516331a9108f60e11b8152600481018690526001600160a01b038916905f805160206120c583398151915290636352211e90602401602060405180830381865afa158015610198573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101bc91906119f9565b6001600160a01b03161461020f5760405162461bcd60e51b815260206004820152601560248201527426a197b737b716b83937bc3c96b837b9b4ba34b7b760591b60448201526064015b60405180910390fd5b5f8061021a876108a8565b915091506102288883610926565b5f888152602084815260409182902082516060810184529054600281810b835263010000008204810b93830193909352600160301b900462ffffff16928101929092526102899190600884901c900b6102848460201c60020b90565b61099c565b5f6102978389898989610b42565b90506102b08b8b8b865f015187602001518b8b88610c7a565b5050505050505050505050565b805f036103065760405162461bcd60e51b81526020600482015260176024820152761350cbdb585e0b5cdb1a5c1c1859d94b5b9bdd0b5cd95d604a1b6044820152606401610206565b5f61031086610e5d565b905061031c8682610926565b80516001600160a01b038681169116148061034c575080602001516001600160a01b0316856001600160a01b0316145b61038d5760405162461bcd60e51b815260206004820152601260248201527126a197b4b73b30b634b216ba37b5b2b724b760711b6044820152606401610206565b866001600160a01b0316633bf076b06103b35f805160206120e583398151915289610edf565b6103c688886001600160801b0316610f11565b6040518363ffffffff1660e01b81526004016103e3929190611a14565b6020604051808303815f875af11580156103ff573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906104239190611a22565b505f6006600c600f60405160200161043d93929190611a39565b60408051601f1981840301815291905282519091506001600160a01b038781169116145f8161046d578351610473565b83602001515b90508461048989896001600160801b0316610f11565b6104939190611a77565b6104a682886001600160801b0316610f11565b6104b890670de0b6b3a7640000611a77565b10156105005760405162461bcd60e51b81526020600482015260176024820152764d432f616d6f756e744f75744d696e2d746f6f2d6c6f7760481b6044820152606401610206565b604080516003808252608082019092525f91816020015b60608152602001906001900390816105175790505090506040518060a001604052808681526020018415158152602001896001600160801b03168152602001886001600160801b0316815260200160405180602001604052805f8152508152506040516020016105879190611b13565b604051602081830303815290604052815f815181106105a8576105a8611b76565b602002602001018190525088886040516020016105c6929190611b8a565b604051602081830303815290604052816001815181106105e8576105e8611b76565b60200260200101819052508187604051602001610606929190611b8a565b6040516020818303038152906040528160028151811061062857610628611b76565b60209081029190910101526040805160018082528183019092525f91816020015b60608152602001906001900390816106495790505090508482604051602001610673929190611c04565b604051602081830303815290604052815f8151811061069457610694611b76565b60200260200101819052506106bf8d8b7366a9893cc07d91d95644aedd05d03f95e1dba8af8c610fa0565b604051600160fc1b60208201526001600160a01b038e1690633aada4d2907366a9893cc07d91d95644aedd05d03f95e1dba8af9060210160408051601f19818403018152908290526107179186904290602401611c31565b60408051601f198184030181529181526020820180516001600160e01b0316630d64d59360e21b179052516001600160e01b031960e085901b168152610761929190600401611c66565b5f604051808303815f875af115801561077c573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526107a39190810190611c89565b506107c48d8b7366a9893cc07d91d95644aedd05d03f95e1dba8af5f610fa0565b50505050505050505050505050565b5f6107dd856112a9565b90506107e98682610926565b5f6107f88983888888886112c1565b905061080f898989855f01518660200151866113e0565b505050505050505050565b5f878152602082815260409182902082516060810184529054600281810b835263010000008204900b92820192909252600160301b90910462ffffff169181019190915261086990878761099c565b5f61087388610e5d565b905061087f8882610926565b5f61088f8b838a8a8a8a8a611553565b90506102b08b8b8b855f015186602001518a8a88610c7a565b6108b061177f565b604051637ba03aad60e01b8152600481018390525f905f805160206120c583398151915290637ba03aad9060240160c060405180830381865afa1580156108f9573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061091d9190611dd5565b91509150915091565b81816040516020016109389190611e00565b60405160208183030381529060405280519060200120146109985760405162461bcd60e51b815260206004820152601a60248201527909a865ee0deded896caf25ae0deded892c85adad2e6dac2e8c6d60331b6044820152606401610206565b5050565b826040015162ffffff165f036109ec5760405162461bcd60e51b81526020600482015260156024820152741350cbdd1a58dad31a5b5a5d1ccb5b9bdd0b5cd95d605a1b6044820152606401610206565b8060020b8260020b12610a375760405162461bcd60e51b81526020600482015260136024820152721350cbdd1a58dadccb5b5a5cdbdc99195c9959606a1b6044820152606401610206565b825f015160020b8260020b1215610a875760405162461bcd60e51b81526020600482015260146024820152734d432f7469636b4c6f7765722d746f6f2d6c6f7760601b6044820152606401610206565b826020015160020b8160020b1315610ad95760405162461bcd60e51b815260206004820152601560248201527409a865ee8d2c6d6aae0e0cae45ae8dede5ad0d2ced605b1b6044820152606401610206565b826040015162ffffff168260020b8260020b610af59190611e0e565b1115610b3d5760405162461bcd60e51b81526020600482015260176024820152764d432f7469636b53706163696e672d746f6f2d7769646560481b6044820152606401610206565b505050565b60605f80601280604051602001610b5b93929190611a39565b60408051808303601f1901815260038084526080840190925292505f9190816020015b6060815260200190600190039081610b7e57905050905086866001600160801b03168686604051602001610bb59493929190611e2d565b604051602081830303815290604052815f81518110610bd657610bd6611b76565b6020026020010181905250875f0151604051602001610bf59190611e62565b60405160208183030381529060405281600181518110610c1757610c17611b76565b60200260200101819052508760200151604051602001610c379190611e62565b60405160208183030381529060405281600281518110610c5957610c59611b76565b6020026020010181905250610c6e8282611694565b98975050505050505050565b610c9388865f805160206120c583398151915286610fa0565b610cac88855f805160206120c583398151915285610fa0565b5f610cb7868a6116fa565b90505f610cc4868b6116fa565b604051631d56d26960e11b81529091506001600160a01b038b1690633aada4d290610d02905f805160206120c5833981519152908790600401611c66565b5f604051808303815f875af1158015610d1d573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052610d449190810190611c89565b505f610d50888c6116fa565b90505f610d5d888d6116fa565b90505f610da4610d6d8a86610f11565b610d778c88610f11565b610d819190611e76565b610d8b8b85610f11565b610d958d87610f11565b610d9f9190611e76565b611767565b90508b6001600160a01b0316633bf076b0610dcc5f805160206121058339815191528e610edf565b836040518363ffffffff1660e01b8152600401610dea929190611a14565b6020604051808303815f875af1158015610e06573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e2a9190611a22565b50610e448d8b5f805160206120c58339815191525f610fa0565b6107c48d8a5f805160206120c58339815191525f610fa0565b610e6561177f565b6040516386b6be7d60e01b815266ffffffffffffff19831660048201525f805160206120c5833981519152906386b6be7d9060240160a060405180830381865afa158015610eb5573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ed99190611e89565b92915050565b5f8282604051602001610ef3929190611a14565b60405160208183030381529060405280519060200120905092915050565b5f826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f4e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f729190611ea3565b610f7d90600a611fa3565b610f8f83670de0b6b3a7640000611a77565b610f999190611fb1565b9392505050565b6040516e22d473030f116ddee9f6b43ac78ba360248201525f60448201526001600160a01b03851690849060640160408051601f198184030181529181526020820180516001600160e01b031663095ea7b360e01b17905251611007929190602401611c66565b60408051601f198184030181529181526020820180516001600160e01b0316631d56d26960e11b1790525161103c9190611fd0565b5f604051808303815f865af19150503d805f8114611075576040519150601f19603f3d011682016040523d82523d5f602084013e61107a565b606091505b5050506001600160801b038116156111c1575f846001600160a01b0316633aada4d2856e22d473030f116ddee9f6b43ac78ba3856040516024016110bf929190611b8a565b60408051601f198184030181529181526020820180516001600160e01b031663095ea7b360e01b179052516001600160e01b031960e085901b168152611109929190600401611c66565b5f604051808303815f875af1158015611124573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f1916820160405261114b9190810190611c89565b905080515f14806111775750805160201480156111775750808060200190518101906111779190611fe6565b6111bf5760405162461bcd60e51b81526020600482015260196024820152781350cbdc195c9b5a5d0c8b585c1c1c9bdd994b59985a5b1959603a1b6044820152606401610206565b505b6040516001600160a01b03848116602483015283811660448301526001600160801b038316606483015265ffffffffffff42166084830152851690633aada4d2906e22d473030f116ddee9f6b43ac78ba39060a40160408051601f198184030181529181526020820180516001600160e01b03166387517c4560e01b179052516001600160e01b031960e085901b168152611260929190600401611c66565b5f604051808303815f875af115801561127b573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526112a29190810190611c89565b5050505050565b6112b161177f565b6112ba826108a8565b5092915050565b60408051600160f81b6020820152601160f81b60218201528151600281830381018252602283018181526082840190945260609391925f9291906042015b60608152602001906001900390816112ff57905050905086866001600160801b031686866040516020016113369493929190611e2d565b604051602081830303815290604052815f8151811061135757611357611b76565b6020026020010181905250875f015188602001518a60405160200161139c939291906001600160a01b0393841681529183166020830152909116604082015260600190565b604051602081830303815290604052816001815181106113be576113be611b76565b60200260200101819052506113d38282611694565b9998505050505050505050565b5f6113eb84886116fa565b90505f6113f884896116fa565b604051631d56d26960e11b81529091506001600160a01b03891690633aada4d290611436905f805160206120c5833981519152908790600401611c66565b5f604051808303815f875af1158015611451573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526114789190810190611c89565b505f611484868a6116fa565b90505f611491868b6116fa565b90505f6114a7876114a28685612005565b610f11565b6114b5896114a28887612005565b6114bf9190611e76565b9050896001600160a01b0316633bf076b06114e75f805160206120a58339815191528c610edf565b836040518363ffffffff1660e01b8152600401611505929190611a14565b6020604051808303815f875af1158015611521573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115459190611a22565b505050505050505050505050565b60605f600260128060405160200161156d93929190611a39565b60408051808303601f1901815260038084526080840190925292505f9190816020015b6060815260200190600190039081611590579050509050888888886001600160801b031688888f6040516020016115cd9796959493929190612018565b604051602081830303815290604052815f815181106115ee576115ee611b76565b6020026020010181905250885f015160405160200161160d9190611e62565b6040516020818303038152906040528160018151811061162f5761162f611b76565b6020026020010181905250886020015160405160200161164f9190611e62565b6040516020818303038152906040528160028151811061167157611671611b76565b60200260200101819052506116868282611694565b9a9950505050505050505050565b606082826040516020016116a9929190611c04565b60408051601f19818403018152908290526116c8914290602401612083565b60408051601f198184030181529190526020810180516001600160e01b031663dd46508f60e01b179052905092915050565b6040516370a0823160e01b81525f906001600160a01b038416906370a0823190611728908590600401611e62565b602060405180830381865afa158015611743573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f999190611a22565b5f818311611775575f610f99565b610f998284612005565b6040805160a0810182525f8082526020820181905291810182905260608101829052608081019190915290565b6001600160a01b03811681146117c0575f80fd5b50565b80356001600160801b03811681146117d9575f80fd5b919050565b5f805f805f805f80610100898b0312156117f6575f80fd5b8835611801816117ac565b97506020890135611811816117ac565b9650604089013595506060890135945061182d60808a016117c3565b935061183b60a08a016117c3565b925061184960c08a016117c3565b915060e089013590509295985092959890939650565b5f805f805f805f60e0888a031215611875575f80fd5b8735611880816117ac565b96506020880135611890816117ac565b95506040880135945060608801356118a7816117ac565b93506118b5608089016117c3565b92506118c360a089016117c3565b915060c0880135905092959891949750929550565b5f805f805f805f60e0888a0312156118ee575f80fd5b87356118f9816117ac565b96506020880135611909816117ac565b95506040880135945060608801359350611925608089016117c3565b925061193360a089016117c3565b915061194160c089016117c3565b905092959891949750929550565b8060020b81146117c0575f80fd5b5f805f805f805f805f6101208a8c031215611976575f80fd5b8935611981816117ac565b985060208a0135611991816117ac565b975060408a0135965060608a01356119a88161194f565b955060808a01356119b88161194f565b94506119c660a08b016117c3565b93506119d460c08b016117c3565b92506119e260e08b016117c3565b91506101008a013590509295985092959850929598565b5f60208284031215611a09575f80fd5b8151610f99816117ac565b918252602082015260400190565b5f60208284031215611a32575f80fd5b5051919050565b6001600160f81b031960f894851b8116825292841b83166001820152921b16600282015260030190565b634e487b7160e01b5f52601160045260245ffd5b8082028115828204841417610ed957610ed9611a63565b634e487b7160e01b5f52604160045260245ffd5b80516001600160a01b03908116835260208083015182169084015260408083015162ffffff169084015260608083015160020b9084015260809182015116910152565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b60208152611b25602082018351611aa2565b6020820151151560c082015260408201516001600160801b0390811660e08301526060830151166101008201526080820151610120808301525f90611b6e610140840182611ae5565b949350505050565b634e487b7160e01b5f52603260045260245ffd5b6001600160a01b039290921682526001600160801b0316602082015260400190565b5f8282518085526020808601955060208260051b840101602086015f5b84811015611bf757601f19868403018952611be5838351611ae5565b98840198925090830190600101611bc9565b5090979650505050505050565b604081525f611c166040830185611ae5565b8281036020840152611c288185611bac565b95945050505050565b606081525f611c436060830186611ae5565b8281036020840152611c558186611bac565b915050826040830152949350505050565b6001600160a01b03831681526040602082018190525f90611b6e90830184611ae5565b5f60208284031215611c99575f80fd5b81516001600160401b0380821115611caf575f80fd5b818401915084601f830112611cc2575f80fd5b815181811115611cd457611cd4611a8e565b604051601f8201601f19908116603f01168101908382118183101715611cfc57611cfc611a8e565b81604052828152876020848701011115611d14575f80fd5b8260208601602083015e5f928101602001929092525095945050505050565b5f60a08284031215611d43575f80fd5b60405160a081016001600160401b0381118282101715611d6557611d65611a8e565b80604052508091508251611d78816117ac565b81526020830151611d88816117ac565b6020820152604083015162ffffff81168114611da2575f80fd5b60408201526060830151611db58161194f565b60608201526080830151611dc8816117ac565b6080919091015292915050565b5f8060c08385031215611de6575f80fd5b611df08484611d33565b915060a083015190509250929050565b60a08101610ed98284611aa2565b8181035f8312801583831316838312821617156112ba576112ba611a63565b93845260208401929092526001600160801b03908116604084015216606082015260a0608082018190525f9082015260c00190565b6001600160a01b0391909116815260200190565b80820180821115610ed957610ed9611a63565b5f60a08284031215611e99575f80fd5b610f998383611d33565b5f60208284031215611eb3575f80fd5b815160ff81168114610f99575f80fd5b600181815b80851115611efd57815f1904821115611ee357611ee3611a63565b80851615611ef057918102915b93841c9390800290611ec8565b509250929050565b5f82611f1357506001610ed9565b81611f1f57505f610ed9565b8160018114611f355760028114611f3f57611f5b565b6001915050610ed9565b60ff841115611f5057611f50611a63565b50506001821b610ed9565b5060208310610133831016604e8410600b8410161715611f7e575081810a610ed9565b611f888383611ec3565b805f1904821115611f9b57611f9b611a63565b029392505050565b5f610f9960ff841683611f05565b5f82611fcb57634e487b7160e01b5f52601260045260245ffd5b500490565b5f82518060208501845e5f920191825250919050565b5f60208284031215611ff6575f80fd5b81518015158114610f99575f80fd5b81810381811115610ed957610ed9611a63565b5f610180612026838b611aa2565b600298890b60a08401529690970b60c082015260e08101949094526001600160801b0392831661010085015291166101208301526001600160a01b031661014082015261016081018290525f918101919091526101a00192915050565b604081525f6120956040830185611ae5565b9050826020830152939250505056fec59bd072250d6fc36cd0770967850f0c32937e79afaaaa622062591d6fe7b6cb000000000000000000000000bd216513d74c8cf14cf4747e6aaa6420ff64ee9e225b3b1db609505774121429e4f0d44307067f6c07bce0c5d69868f0cb16acc379c8abd914f784b8449d20ca3d1c1f4d9fd49e46d2a83d5ab3391590751073aca2646970667358221220442f5b7578b7ee463c59ff83ac65ae01dfae441c71bb70e17fccf0cdd15c992564736f6c63430008190033

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ 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.