ETH Price: $1,973.78 (-0.09%)
 

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
Set Platform Fee...243918592026-02-05 16:35:5916 days ago1770309359IN
0xFfFFfFff...4b4efcd3D
0 ETH0.000130094.20634779
Set Position Man...243918592026-02-05 16:35:5916 days ago1770309359IN
0xFfFFfFff...4b4efcd3D
0 ETH0.00020114.20634779
Set Fee Holder243918592026-02-05 16:35:5916 days ago1770309359IN
0xFfFFfFff...4b4efcd3D
0 ETH0.000200084.20634779

Advanced mode:
Parent Transaction Hash Method Block
From
To
View All Internal Transactions
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:
AppsFun

Compiler Version
v0.8.33+commit.64118f21

Optimization Enabled:
Yes with 200 runs

Other Settings:
cancun EvmVersion
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;

import "./interfaces/ICurve.sol";
import "./interfaces/IWETH.sol";
import "./interfaces/IAppsFun.sol";
import "./Curve.sol";
import "./AppsFunToken.sol";
import "./interfaces/IFeeHolder.sol";
import "./libraries/Math.sol";

import "@uniswap/v4-periphery/src/interfaces/IPositionManager.sol";
import "@uniswap/v4-core/src/types/PoolKey.sol";
import "@uniswap/v4-core/src/types/Currency.sol";
import "@uniswap/v4-core/src/interfaces/IHooks.sol";
import {PoolId, PoolIdLibrary} from "@uniswap/v4-core/src/types/PoolId.sol";
import "@uniswap/v4-periphery/src/libraries/Actions.sol";
import {LiquidityAmounts} from "@uniswap/v4-periphery/src/libraries/LiquidityAmounts.sol";
import {TickMath} from "@uniswap/v4-core/src/libraries/TickMath.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IAllowanceTransfer} from "permit2/src/interfaces/IAllowanceTransfer.sol";

contract AppsFun is IAppsFun {
    using SafeERC20 for IERC20;
    using PoolIdLibrary for PoolKey;

    address public WETH;
    uint256 public virtualBaseReserve;
    address public owner;
    address public platformFeeAddress;
    uint256 public graduationThreshold;

    uint256 public constant CREATOR_FEE_BIPS = 50;
    uint256 public constant PLATFORM_FEE_BIPS = 50;
    uint256 public constant FEE_DENOMINATOR = 10000;
    uint256 public constant MAX_TOKEN_DEPOSIT = 2 ** 111;
    uint24 public constant V4_FEE = 3000; // 0.3%
    int24 public constant V4_TICK_SPACING = 60;

    uint256 private unlocked = 1;

    modifier lock() {
        require(unlocked == 1, "AppsFun: LOCKED");
        unlocked = 0;
        _;
        unlocked = 1;
    }

    IPositionManager public positionManager;
    IFeeHolder public feeHolder;
    IAllowanceTransfer public permit2;

    mapping(address => PairInfo) public getPair;
    address[] public allPairs;

    constructor(address _WETH, address _feeHolder, address _permit2, uint256 _virtualBaseReserve, uint256 _graduationThreshold) {
        require(_permit2 != address(0), "AppsFun: INVALID_PERMIT2");
        WETH = _WETH;
        virtualBaseReserve = _virtualBaseReserve;
        graduationThreshold = _graduationThreshold;
        owner = msg.sender;
        platformFeeAddress = msg.sender; // Default to owner
        feeHolder = IFeeHolder(_feeHolder);
        permit2 = IAllowanceTransfer(_permit2);
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "AppsFun: FORBIDDEN");
        _;
    }

    modifier ensure(uint256 deadline) {
        require(deadline >= block.timestamp, "AppsFun: EXPIRED");
        _;
    }

    function setVirtualBaseReserve(uint256 _virtualBaseReserve) external onlyOwner {
        emit VirtualBaseReserveUpdated(virtualBaseReserve, _virtualBaseReserve);
        virtualBaseReserve = _virtualBaseReserve;
    }

    function setPlatformFeeAddress(address _platformFeeAddress) external onlyOwner {
        emit PlatformFeeAddressUpdated(platformFeeAddress, _platformFeeAddress);
        platformFeeAddress = _platformFeeAddress;
    }

    function setPositionManager(address _positionManager) external onlyOwner {
        emit PositionManagerUpdated(address(positionManager), _positionManager);
        positionManager = IPositionManager(_positionManager);
    }

    function setFeeHolder(address _feeHolder) external onlyOwner {
        emit FeeHolderUpdated(address(feeHolder), _feeHolder);
        feeHolder = IFeeHolder(_feeHolder);
    }

    function setPermit2(address _permit2) external onlyOwner {
        emit Permit2Updated(address(permit2), _permit2);
        permit2 = IAllowanceTransfer(_permit2);
    }

    function setGraduationThreshold(uint256 _graduationThreshold) external onlyOwner {
        emit GraduationThresholdUpdated(graduationThreshold, _graduationThreshold);
        graduationThreshold = _graduationThreshold;
    }

    function setOwner(address _owner) external onlyOwner {
        emit OwnerUpdated(owner, _owner);
        owner = _owner;
    }

    function allPairsLength() external view returns (uint256) {
        return allPairs.length;
    }

    // deployAndLaunchWithSplit allows creator to specify an amount of tokens to keep for themselves (creatorAmount)
    // supply is total token supply (will be multiplied by 10^18 in AppsFunToken), creatorAmount is how many tokens (with decimals) to transfer to creator after mint
    // creatorAmount will NOT be multiplied by 10^18!
    function deployAndLaunchWithSplit(string memory name, string memory symbol, uint256 supply, uint256 creatorAmount)
        public
        returns (address pair, address token)
    {
        // Deploy AppsFunToken - it mints supply to this contract
        AppsFunToken newToken = new AppsFunToken(name, symbol, supply);
        token = address(newToken);
        require(token != address(0), "AppsFun: ZERO_ADDRESS");
        uint256 amount = newToken.totalSupply();

        if (creatorAmount > 0) {
            require(creatorAmount < amount, "AppsFun: INVALID_CREATOR_AMOUNT");
            newToken.transfer(msg.sender, creatorAmount);
            amount = amount - creatorAmount;
        }

        require(getPair[token].pair == address(0), "AppsFun: PAIR_EXISTS");
        require(amount > 0 && amount <= MAX_TOKEN_DEPOSIT, "AppsFun: INVALID_AMOUNT");

        // Determine token ordering
        (address token0, address token1) = sortTokens(token, WETH);
        (uint256 virtualReserve0, uint256 virtualReserve1) =
            token0 == WETH ? (virtualBaseReserve, uint256(0)) : (uint256(0), virtualBaseReserve);
        (uint256 amount0, uint256 amount1) = token0 == token ? (amount, uint256(0)) : (uint256(0), amount);

        // Create pair using CREATE2
        bytes memory bytecode = type(Curve).creationCode;
        bytes32 salt = keccak256(abi.encodePacked(token));
        assembly {
            pair := create2(0, add(bytecode, 32), mload(bytecode), salt)
        }
        require(pair != address(0), "AppsFun: FAILED");

        // Initialize and deposit (tokens already in this contract from mint)
        ICurve(pair).initialize(token0, token1, virtualReserve0, virtualReserve1);
        IERC20(token).approve(pair, amount);
        ICurve(pair).depositLiquidity(amount0, amount1);

        // Store pair info - creator is msg.sender (the user calling this function)
        getPair[token] = PairInfo(pair, msg.sender);
        allPairs.push(pair);
        if (creatorAmount == 0) {
            emit TokenFairLaunched(token, pair, allPairs.length);
        } else {
            emit TokenLaunched(token, amount, pair, allPairs.length);
        }
    }

    function deployAndLaunch(string memory name, string memory symbol, uint256 supply)
        external
        returns (address pair, address token)
    {
        return deployAndLaunchWithSplit(name, symbol, supply, 0);
    }

    function launchToken(address token, uint256 amount) external returns (address pair) {
        require(token != WETH, "AppsFun: IDENTICAL_ADDRESSES");
        require(token != address(0), "AppsFun: ZERO_ADDRESS");
        require(getPair[token].pair == address(0), "AppsFun: PAIR_EXISTS");
        require(amount > 0 && amount <= MAX_TOKEN_DEPOSIT, "AppsFun: INVALID_AMOUNT");

        // Determine token ordering (token0 < token1)
        (address token0, address token1) = sortTokens(token, WETH);

        // Calculate virtual reserves based on token ordering
        (uint256 virtualReserve0, uint256 virtualReserve1) =
            token0 == WETH ? (virtualBaseReserve, uint256(0)) : (uint256(0), virtualBaseReserve);

        // Calculate amounts based on token ordering
        (uint256 amount0, uint256 amount1) = token0 == token ? (amount, uint256(0)) : (uint256(0), amount);

        // Create pair using CREATE2
        bytes memory bytecode = type(Curve).creationCode;
        bytes32 salt = keccak256(abi.encodePacked(token));
        assembly {
            pair := create2(0, add(bytecode, 32), mload(bytecode), salt)
        }
        require(pair != address(0), "AppsFun: FAILED");

        // Initialize the pair
        ICurve(pair).initialize(token0, token1, virtualReserve0, virtualReserve1);

        // Transfer tokens from sender and deposit liquidity
        IERC20(token).safeTransferFrom(msg.sender, address(this), amount);
        IERC20(token).approve(pair, amount);
        ICurve(pair).depositLiquidity(amount0, amount1);

        getPair[token] = PairInfo(pair, msg.sender);
        allPairs.push(pair);
        emit TokenLaunched(token, amount, pair, allPairs.length);
    }

    function canGraduate(address token) external view returns (bool) {
        PairInfo memory info = getPair[token];
        if (info.pair == address(0)) {
            return false;
        }
        return IERC20(WETH).balanceOf(info.pair) >= graduationThreshold;
    }

    function graduateToken(address token) external {
        PairInfo memory info = getPair[token];
        require(info.pair != address(0), "AppsFun: PAIR_NOT_FOUND");
        require(IERC20(WETH).balanceOf(info.pair) >= graduationThreshold, "AppsFun: THRESHOLD_NOT_MET");

        // Get virtual reserves BEFORE withdrawal (for price calculation)
        uint256 virtualWeth = token < WETH ? ICurve(info.pair).virtualReserve1() : ICurve(info.pair).virtualReserve0();

        // Withdraw liquidity from Curve
        ICurve(info.pair).withdrawalLiquidity();

        // Get actual token balances
        uint256 tokenBalance = IERC20(token).balanceOf(address(this));
        uint256 wethBalance = IERC20(WETH).balanceOf(address(this));

        // Convert WETH to native ETH for V4 native pool
        IWETH(WETH).withdraw(wethBalance);
        uint256 ethBalance = wethBalance;

        // Use address(0) for native ETH - it always sorts before any token address
        // So native ETH is always currency0, token is always currency1
        (Currency currency0, Currency currency1, uint256 amount0, uint256 amount1) =
            (Currency.wrap(address(0)), Currency.wrap(token), ethBalance, tokenBalance);

        // For price calculation, include virtual ETH to match Curve's effective price
        // price = currency1/currency0 = token/ETH
        uint256 priceAmount0 = amount0 + virtualWeth;  // ETH side with virtual
        uint256 priceAmount1 = amount1;

        // Create PoolKey with native ETH
        PoolKey memory poolKey = PoolKey({
            currency0: Currency.wrap(address(0)),  // Native ETH
            currency1: Currency.wrap(token),       // Token (always > address(0))
            fee: V4_FEE,
            tickSpacing: V4_TICK_SPACING,
            hooks: IHooks(address(0))
        });

        uint160 sqrtPriceX96 = uint160(Math.sqrt( 2**96 * ((priceAmount1 * 2**96) / priceAmount0) ));
        positionManager.initializePool(poolKey, sqrtPriceX96);

        // Only approve the token (no WETH approval needed - using native ETH)
        IERC20(token).approve(address(permit2), tokenBalance);

        // Approve PositionManager as Permit2 spender for token only
        permit2.approve(token, address(positionManager), uint160(tokenBalance), uint48(block.timestamp + 60));

        // Calculate liquidity for full-range position at current price
        // For full range: L = min(amount0 * sqrtPriceX96 / 2^96, amount1 * 2^96 / sqrtPriceX96)
        uint256 liquidity0 = (amount0 * uint256(sqrtPriceX96)) >> 96;
        uint256 liquidity1 = (amount1 << 96) / uint256(sqrtPriceX96);
        uint256 liquidity = liquidity0 < liquidity1 ? liquidity0 : liquidity1;

        // Encode mint position action
        bytes memory actions = abi.encodePacked(uint8(Actions.MINT_POSITION), uint8(Actions.SETTLE_PAIR));
        bytes[] memory params = new bytes[](2);
        params[0] = abi.encode(
            poolKey,
            int24(-887220), // tickLower (full range)
            int24(887220), // tickUpper (full range)
            liquidity,
            uint128(amount0), // amount0Max (slippage protection)
            uint128(amount1), // amount1Max (slippage protection)
            address(feeHolder), // Position owner is FeeHolder
            "" // hookData
        );
        params[1] = abi.encode(currency0, currency1);

        // Execute mint with native ETH
        positionManager.modifyLiquidities{value: ethBalance}(abi.encode(actions, params), block.timestamp + 60);

        // Register first position with FeeHolder
        uint256 positionId = positionManager.nextTokenId() - 1;
        feeHolder.registerPosition(info.creator, token, positionId);

        // Create second position from current price to max (buy side) with leftover tokens
        // Note: Leftovers are always on the token side, never ETH
        uint256 leftoverToken = IERC20(token).balanceOf(address(this));

        if (leftoverToken > 0) {
            // Get current tick from sqrtPriceX96
            int24 currentTick = Math.getTickAtSqrtPrice(sqrtPriceX96, V4_TICK_SPACING);

            // Second position: single-sided with only leftover tokens (no ETH needed)
            // With native ETH pools: ETH (address(0)) is always currency0, token is always currency1
            // For a single-sided token position, we need to be BELOW current tick
            // (token-only liquidity exists when price is below our range)
            int24 tickLower2 = int24(-887220);
            int24 tickUpper2 = currentTick - V4_TICK_SPACING;

            // Approve leftover tokens
            IERC20(token).approve(address(permit2), leftoverToken);
            permit2.approve(token, address(positionManager), uint160(leftoverToken), uint48(block.timestamp + 60));

            // Calculate liquidity using proper formulas for tick range
            // Get sqrt prices at the tick boundaries
            uint160 sqrtPriceLower = TickMath.getSqrtPriceAtTick(tickLower2);
            uint160 sqrtPriceUpper = TickMath.getSqrtPriceAtTick(tickUpper2);

            // Token is currency1, so use getLiquidityForAmount1
            uint128 liquidity2 = LiquidityAmounts.getLiquidityForAmount1(sqrtPriceLower, sqrtPriceUpper, leftoverToken);

            // Token is currency1, so amount0Max=0 (no ETH), amount1Max=leftoverToken
            uint128 amount0Max = 0;
            uint128 amount1Max = uint128(leftoverToken);

            // Mint second position (no ETH value needed - token only)
            bytes memory actions2 = abi.encodePacked(uint8(Actions.MINT_POSITION), uint8(Actions.SETTLE_PAIR));
            bytes[] memory params2 = new bytes[](2);
            params2[0] = abi.encode(
                poolKey,
                tickLower2,
                tickUpper2,
                liquidity2,
                amount0Max,
                amount1Max,
                address(feeHolder),
                ""
            );
            params2[1] = abi.encode(currency0, currency1);

            positionManager.modifyLiquidities{value: 0}(abi.encode(actions2, params2), block.timestamp + 60);

            // Register second position
            uint256 positionId2 = positionManager.nextTokenId() - 1;
            feeHolder.registerPosition(info.creator, token, positionId2);
        }

        emit TokenGraduated(token, positionId, poolKey.toId());
    }

    function feeToSetter() external view returns (address) {
        return owner;
    }

    /**
     * Library Functions
     */
    function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
        require(tokenA != tokenB, "AppsFun: IDENTICAL_ADDRESSES");
        (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
        require(token0 != address(0), "AppsFun: ZERO_ADDRESS");
    }

    function _getAmountOut(uint256 amountIn, uint256 reserveIn, uint256 reserveOut)
        internal
        pure
        returns (uint256 amountOut)
    {
        require(amountIn > 0, "AppsFun: INSUFFICIENT_INPUT_AMOUNT");
        require(reserveIn > 0 && reserveOut > 0, "AppsFun: INSUFFICIENT_LIQUIDITY");
        uint256 amountInWithFee = amountIn * 997;
        uint256 numerator = amountInWithFee * reserveOut;
        uint256 denominator = reserveIn * 1000 + amountInWithFee;
        amountOut = numerator / denominator;
    }

    function getAmountOut(uint256 amountIn, address inputToken, address pair) public view returns (uint256 amountOut) {
        address token0 = ICurve(pair).token0();
        bool zeroForOne = inputToken == token0;
        (uint112 reserve0, uint112 reserve1,) = ICurve(pair).getReserves();
        (uint256 reserveIn, uint256 reserveOut) = zeroForOne ? (reserve0, reserve1) : (reserve1, reserve0);
        amountOut = _getAmountOut(amountIn, reserveIn, reserveOut);
    }

    /**
     * Swap Functions
     */
    function _swap(uint256 amountOut, address inputToken, address pair, address to) internal {
        address token0 = ICurve(pair).token0();
        (uint256 amount0Out, uint256 amount1Out) =
            inputToken == token0 ? (uint256(0), amountOut) : (amountOut, uint256(0));
        ICurve(pair).swap(amount0Out, amount1Out, to);
    }

    function swapExactETHForTokens(uint256 amountOutMin, address token, address to, uint256 deadline)
        external
        payable
        lock
        ensure(deadline)
        returns (uint256 amountOut)
    {
        PairInfo memory info = getPair[token];
        require(info.pair != address(0), "AppsFun: PAIR_NOT_FOUND");

        // Calculate and send fees
        uint256 creatorFee = msg.value * CREATOR_FEE_BIPS / FEE_DENOMINATOR;
        uint256 platformFee = msg.value * PLATFORM_FEE_BIPS / FEE_DENOMINATOR;
        uint256 amountAfterFees = msg.value - creatorFee - platformFee;

        if (creatorFee > 0) {
            _safeTransferETH(address(feeHolder), creatorFee);
            feeHolder.depositFees(info.creator, creatorFee);
        }
        if (platformFee > 0 && platformFeeAddress != address(0)) _safeTransferETH(platformFeeAddress, platformFee);

        emit AppsFunFee(info.creator, token, creatorFee, platformFee);

        // Swap with remaining amount
        amountOut = getAmountOut(amountAfterFees, WETH, info.pair);
        require(amountOut >= amountOutMin, "AppsFun: INSUFFICIENT_OUTPUT_AMOUNT");

        IWETH(WETH).deposit{value: amountAfterFees}();
        IERC20(WETH).safeTransfer(info.pair, amountAfterFees);
        _swap(amountOut, WETH, info.pair, to);
    }

    function swapExactTokensForETH(uint256 amountIn, uint256 amountOutMin, address token, address to, uint256 deadline)
        external
        lock
        ensure(deadline)
        returns (uint256 amountOut)
    {
        PairInfo memory info = getPair[token];
        require(info.pair != address(0), "AppsFun: PAIR_NOT_FOUND");

        amountOut = getAmountOut(amountIn, token, info.pair);

        IERC20(token).safeTransferFrom(msg.sender, info.pair, amountIn);
        _swap(amountOut, token, info.pair, address(this));
        IWETH(WETH).withdraw(amountOut);

        // Calculate and send fees
        uint256 creatorFee = amountOut * CREATOR_FEE_BIPS / FEE_DENOMINATOR;
        uint256 platformFee = amountOut * PLATFORM_FEE_BIPS / FEE_DENOMINATOR;
        uint256 amountAfterFees = amountOut - creatorFee - platformFee;

        if (creatorFee > 0) {
            _safeTransferETH(address(feeHolder), creatorFee);
            feeHolder.depositFees(info.creator, creatorFee);
        }
        if (platformFee > 0 && platformFeeAddress != address(0)) _safeTransferETH(platformFeeAddress, platformFee);

        emit AppsFunFee(info.creator, token, creatorFee, platformFee);

        require(amountAfterFees >= amountOutMin, "AppsFun: INSUFFICIENT_OUTPUT_AMOUNT");
        _safeTransferETH(to, amountAfterFees);
    }

    function quoteSwapExactTokensForETH(uint256 amountIn, address token)
        external
        view
        returns (uint256)
    {
        PairInfo memory info = getPair[token];
        require(info.pair != address(0), "AppsFun: PAIR_NOT_FOUND");

        uint256 amountOut = getAmountOut(amountIn, token, info.pair);

        uint256 creatorFee = amountOut * CREATOR_FEE_BIPS / FEE_DENOMINATOR;
        uint256 platformFee = amountOut * PLATFORM_FEE_BIPS / FEE_DENOMINATOR;
        uint256 amountAfterFees = amountOut - creatorFee - platformFee;
        return amountAfterFees;
    }

    function quoteSwapExactETHForTokens(uint256 amountIn, address token)
        external
        view
        returns (uint256)
    {
        PairInfo memory info = getPair[token];
        require(info.pair != address(0), "AppsFun: PAIR_NOT_FOUND");

        // Deduct fees from input first (matches swapExactETHForTokens logic)
        uint256 creatorFee = amountIn * CREATOR_FEE_BIPS / FEE_DENOMINATOR;
        uint256 platformFee = amountIn * PLATFORM_FEE_BIPS / FEE_DENOMINATOR;
        uint256 amountAfterFees = amountIn - creatorFee - platformFee;

        return getAmountOut(amountAfterFees, WETH, info.pair);
    }

    function _safeTransferETH(address to, uint256 value) internal {
        (bool success,) = to.call{value: value}(new bytes(0));
        require(success, "AppsFun: ETH_TRANSFER_FAILED");
    }

    receive() external payable {}
}

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0;

interface ICurve {
    // Events

    event Swap(
        address indexed sender,
        uint256 amount0In,
        uint256 amount1In,
        uint256 amount0Out,
        uint256 amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);
    event LiquidityDeposited(uint256 amount0, uint256 amount1);
    event LiquidityWithdrawn(uint256 amount0, uint256 amount1);

    // State variables
    function factory() external view returns (address);
    function token0() external view returns (address);
    function token1() external view returns (address);
    function price0CumulativeLast() external view returns (uint256);
    function price1CumulativeLast() external view returns (uint256);
    function virtualReserve0() external view returns (uint256);
    function virtualReserve1() external view returns (uint256);

    // Functions
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    function swap(uint256 amount0Out, uint256 amount1Out, address to) external;
    function skim(address to) external;
    function sync() external;
    function initialize(address _token0, address _token1, uint256 _virtualReserve0, uint256 _virtualReserve1)
        external;
    function withdrawalLiquidity() external;
    function depositLiquidity(uint256 amount0, uint256 amount1) external;
}

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;

interface IWETH {
    function deposit() external payable;
    function withdraw(uint256) external;
    function transfer(address to, uint256 value) external returns (bool);
    function transferFrom(address from, address to, uint256 value) external returns (bool);
    function approve(address spender, uint256 value) external returns (bool);
    function balanceOf(address owner) external view returns (uint256);
}

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0;

import "@uniswap/v4-periphery/src/interfaces/IPositionManager.sol";
import {PoolId} from "@uniswap/v4-core/src/types/PoolId.sol";
import "./IFeeHolder.sol";

interface IAppsFun {
    // Structs
    struct PairInfo {
        address pair;
        address creator;
    }

    // Events
    event TokenFairLaunched(address indexed token, address pair, uint256);
    event TokenLaunched(address indexed token, uint256 deposited, address pair, uint256);
    event AppsFunFee(address indexed creator, address indexed token, uint256 creatorFee, uint256 platformFee);
    event TokenGraduated(address indexed token, uint256 positionId, PoolId poolId);
    event VirtualBaseReserveUpdated(uint256 indexed oldValue, uint256 indexed newValue);
    event PlatformFeeAddressUpdated(address indexed oldAddress, address indexed newAddress);
    event PositionManagerUpdated(address indexed oldManager, address indexed newManager);
    event FeeHolderUpdated(address indexed oldHolder, address indexed newHolder);
    event GraduationThresholdUpdated(uint256 indexed oldThreshold, uint256 indexed newThreshold);
    event OwnerUpdated(address indexed oldOwner, address indexed newOwner);
    event Permit2Updated(address indexed oldPermit2, address indexed newPermit2);

    // State variable getters
    function WETH() external view returns (address);
    function virtualBaseReserve() external view returns (uint256);
    function owner() external view returns (address);
    function platformFeeAddress() external view returns (address);
    function graduationThreshold() external view returns (uint256);
    function CREATOR_FEE_BIPS() external view returns (uint256);
    function PLATFORM_FEE_BIPS() external view returns (uint256);
    function FEE_DENOMINATOR() external view returns (uint256);
    function V4_FEE() external view returns (uint24);
    function V4_TICK_SPACING() external view returns (int24);
    function positionManager() external view returns (IPositionManager);
    function feeHolder() external view returns (IFeeHolder);
    function getPair(address token) external view returns (address pair, address creator);
    function allPairs(uint256 index) external view returns (address);

    // Owner functions
    function setVirtualBaseReserve(uint256 _virtualBaseReserve) external;
    function setPlatformFeeAddress(address _platformFeeAddress) external;
    function setPositionManager(address _positionManager) external;
    function setFeeHolder(address _feeHolder) external;
    function setGraduationThreshold(uint256 _graduationThreshold) external;
    function setOwner(address _owner) external;

    // View functions
    function allPairsLength() external view returns (uint256);
    function canGraduate(address token) external view returns (bool);
    function getAmountOut(uint256 amountIn, address inputToken, address pair)
        external
        view
        returns (uint256 amountOut);
    function feeToSetter() external view returns (address);
    function quoteSwapExactTokensForETH(uint256 amountIn, address token) external view returns (uint256);
    function quoteSwapExactETHForTokens(uint256 amountIn, address token) external view returns (uint256);

    // State-changing functions
    function deployAndLaunch(string memory name, string memory symbol, uint256 supply)
        external
        returns (address pair, address token);
    function launchToken(address token, uint256 amount) external returns (address pair);
    function graduateToken(address token) external;
    function swapExactETHForTokens(uint256 amountOutMin, address token, address to, uint256 deadline)
        external
        payable
        returns (uint256 amountOut);
    function swapExactTokensForETH(uint256 amountIn, uint256 amountOutMin, address token, address to, uint256 deadline)
        external
        returns (uint256 amountOut);
}

// SPDX-License-Identifier: GPL-3.0
// Modified from Uniswap V2 core contracts.
// Their license can be found here: https://github.com/Uniswap/v2-core/blob/master/LICENSE
pragma solidity ^0.8.0;

import "./interfaces/ICurve.sol";
import "./libraries/Math.sol";
import "./libraries/UQ112x112.sol";

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract Curve is ICurve {
    using UQ112x112 for uint224;
    using SafeERC20 for IERC20;

    uint256 public constant MINIMUM_LIQUIDITY = 10 ** 3;
    uint256 public constant MAX_VIRTUAL_RESERVE = 2 ** 88; // To prevent overflow in getReserves

    address public factory;
    address public token0;
    address public token1;

    uint112 private reserve0; // uses single storage slot, accessible via getReserves
    uint112 private reserve1; // uses single storage slot, accessible via getReserves
    uint32 private blockTimestampLast; // uses single storage slot, accessible via getReserves

    uint256 public price0CumulativeLast;
    uint256 public price1CumulativeLast;
    uint256 public virtualReserve0; // Added line
    uint256 public virtualReserve1; // Added line
    uint256 private unlocked = 1;

    modifier lock() {
        require(unlocked == 1, "AppsFun: LOCKED");
        unlocked = 0;
        _;
        unlocked = 1;
    }

    function getReserves() public view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast) {
        // NOTE: If virtualBaseReserve is set too high and actual reserves grow, this reverts. Not exploitable but can brick the pool.
        // In our usecase, when ONLY the eth/bnb side has virtual reserves, this will not be an issue
        // Total supply of ETH and BNB is less than 2^88, which gives us 24 bits of safe space.
        // We limit the virtual reserves to 2^88 to be safe.
        _reserve0 = uint112(reserve0 + virtualReserve0); // Changed line: add virtual reserves
        _reserve1 = uint112(reserve1 + virtualReserve1); // Changed line: add virtual reserves
        _blockTimestampLast = blockTimestampLast;
    }

    constructor() {
        factory = msg.sender;
    }

    // called once by the factory at time of deployment
    function initialize(address _token0, address _token1, uint256 _virtualReserve0, uint256 _virtualReserve1)
        external
    {
        // Changed line: new params
        require(msg.sender == factory, "AppsFun: FORBIDDEN"); // sufficient check
        token0 = _token0;
        token1 = _token1;
        require(
            _virtualReserve0 <= MAX_VIRTUAL_RESERVE && _virtualReserve1 <= MAX_VIRTUAL_RESERVE,
            "AppsFun: VIRTUAL_RESERVE_TOO_HIGH"
        ); // Added line: limit virtual reserves
        virtualReserve0 = _virtualReserve0; // Added line
        virtualReserve1 = _virtualReserve1; // Added line
    }

    // update reserves and, on the first call per block, price accumulators
    function _update(uint256 balance0, uint256 balance1, uint112 _reserve0, uint112 _reserve1) private {
        require(balance0 <= type(uint112).max && balance1 <= type(uint112).max, "AppsFun: OVERFLOW");
        uint32 blockTimestamp = uint32(block.timestamp % 2 ** 32);
        uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired
        if (timeElapsed > 0 && _reserve0 != 0 && _reserve1 != 0) {
            // * never overflows, and + overflow is desired
            price0CumulativeLast += uint256(UQ112x112.encode(_reserve1).uqdiv(_reserve0)) * timeElapsed;
            price1CumulativeLast += uint256(UQ112x112.encode(_reserve0).uqdiv(_reserve1)) * timeElapsed;
        }
        reserve0 = uint112(balance0);
        reserve1 = uint112(balance1);
        blockTimestampLast = blockTimestamp;
        emit Sync(reserve0, reserve1);
    }

    // this low-level function should be called from a contract which performs important safety checks
    function swap(uint256 amount0Out, uint256 amount1Out, address to) external lock {
        require(msg.sender == factory, "AppsFun: FORBIDDEN"); // Changed line: only factory can call swap
        require(amount0Out > 0 || amount1Out > 0, "AppsFun: INSUFFICIENT_OUTPUT_AMOUNT");
        // Check against the actual reserves (not effective), since we are checking liquidity
        uint256 actualReserve0 = reserve0;
        uint256 actualReserve1 = reserve1;
        require(amount0Out < actualReserve0 || amount0Out == 0, "AppsFun: INSUFFICIENT_LIQUIDITY 0");
        require(amount1Out < actualReserve1 || amount1Out == 0, "AppsFun: INSUFFICIENT_LIQUIDITY 1");

        (uint112 _virtualReserve0, uint112 _virtualReserve1,) = getReserves(); // effective reserves (actual + virtual)

        uint256 balance0;
        uint256 balance1;
        {
            // scope for _token{0,1}, avoids stack too deep errors
            address _token0 = token0;
            address _token1 = token1;
            require(to != _token0 && to != _token1, "AppsFun: INVALID_TO");
            if (amount0Out > 0) IERC20(_token0).safeTransfer(to, amount0Out); // optimistically transfer tokens
            if (amount1Out > 0) IERC20(_token1).safeTransfer(to, amount1Out); // optimistically transfer tokens
            balance0 = IERC20(_token0).balanceOf(address(this));
            balance1 = IERC20(_token1).balanceOf(address(this));
        }
        // Use actual reserves (not effective) for input calculation since balances are actual

        uint256 amount0In = balance0 > actualReserve0 - amount0Out ? balance0 - (actualReserve0 - amount0Out) : 0; // Changed line
        uint256 amount1In = balance1 > actualReserve1 - amount1Out ? balance1 - (actualReserve1 - amount1Out) : 0; // Changed line
        require(amount0In > 0 || amount1In > 0, "AppsFun: INSUFFICIENT_INPUT_AMOUNT");
        {
            // scope for reserve{0,1}Adjusted, avoids stack too deep errors
            // Use effective balances (actual + virtual) for K invariant check
            uint256 effectiveBalance0 = balance0 + virtualReserve0; // Changed line
            uint256 effectiveBalance1 = balance1 + virtualReserve1; // Changed line
            uint256 balance0Adjusted = effectiveBalance0 * 1000 - amount0In * 3; // Changed line
            uint256 balance1Adjusted = effectiveBalance1 * 1000 - amount1In * 3; // Changed line
            require(
                balance0Adjusted * balance1Adjusted >= uint256(_virtualReserve0) * uint256(_virtualReserve1) * 1000 ** 2,
                "AppsFun: K"
            );
        }

        _update(balance0, balance1, _virtualReserve0, _virtualReserve1);
        emit Swap(msg.sender, amount0In, amount1In, amount0Out, amount1Out, to);
    }

    // force balances to match reserves
    function skim(address to) external lock {
        address _token0 = token0; // gas savings
        address _token1 = token1; // gas savings
        IERC20(_token0).safeTransfer(to, IERC20(_token0).balanceOf(address(this)) - reserve0);
        IERC20(_token1).safeTransfer(to, IERC20(_token1).balanceOf(address(this)) - reserve1);
    }

    // force reserves to match balances
    function sync() external lock {
        _update(IERC20(token0).balanceOf(address(this)), IERC20(token1).balanceOf(address(this)), reserve0, reserve1);
    }

    /**
     * NEW FUNCTIONS START
     */

    // Allow the factory to withdraw liquidity tokens accumulated in the pair contract,'
    // for graduation
    function withdrawalLiquidity() external lock {
        require(msg.sender == factory, "AppsFun: FORBIDDEN");

        uint256 balance0 = IERC20(token0).balanceOf(address(this));
        uint256 balance1 = IERC20(token1).balanceOf(address(this));

        IERC20(token0).safeTransfer(msg.sender, balance0);
        IERC20(token1).safeTransfer(msg.sender, balance1);
        _update(IERC20(token0).balanceOf(address(this)), IERC20(token1).balanceOf(address(this)), reserve0, reserve1);

        emit LiquidityWithdrawn(balance0, balance1);
    }

    function depositLiquidity(uint256 amount0, uint256 amount1) external lock {
        // We don't want anyone else to deposit liquidity,
        // we expect only one token to be provided but allow both.
        require(msg.sender == factory, "AppsFun: FORBIDDEN");

        IERC20(token0).safeTransferFrom(msg.sender, address(this), amount0);
        IERC20(token1).safeTransferFrom(msg.sender, address(this), amount1);
        _update(IERC20(token0).balanceOf(address(this)), IERC20(token1).balanceOf(address(this)), reserve0, reserve1);

        emit LiquidityDeposited(amount0, amount1);
    }

    /**
     * NEW FUNCTIONS END *
     */
}

File 6 of 53 : AppsFunToken.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";


contract AppsFunToken is ERC20 {
    constructor(string memory name, string memory symbol, uint256 supply) ERC20(name, symbol) {
        _mint(msg.sender, supply * 10 ** decimals());
    }
}

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0;

import "@uniswap/v4-periphery/src/interfaces/IPositionManager.sol";

interface IFeeHolder {
    event PositionRegistered(uint256 indexed positionId, address indexed token, address indexed creator);
    event FeesWithdrawn(
        uint256 indexed positionId,
        address indexed creator,
        address token0,
        uint256 creatorAmount0,
        uint256 platformAmount0,
        address token1,
        uint256 creatorAmount1,
        uint256 platformAmount1
    );
    event FeesDeposited(address indexed creator, uint256 amount);
    event AppsFunUpdated(address indexed oldAppsFun, address indexed newAppsFun);
    event PositionManagerUpdated(address indexed oldPositionManager, address indexed newPositionManager);
    event PlatformFeeAddressUpdated(address indexed oldAddress, address indexed newAddress);
    event OwnerUpdated(address indexed oldOwner, address indexed newOwner);

    function owner() external view returns (address);
    function appsFun() external view returns (address);
    function platformFeeAddress() external view returns (address);
    function positionManager() external view returns (IPositionManager);
    function positionCreator(uint256 positionId) external view returns (address);
    function positionsByToken(address token) external view returns (uint256[] memory);
    function PLATFORM_FEE_BIPS() external view returns (uint256);
    function FEE_DENOMINATOR() external view returns (uint256);

    function initialize(address _positionManager, address _appsFun) external;
    function setAppsFun(address _appsFun) external;
    function setPositionManager(address _positionManager) external;
    function setPlatformFeeAddress(address _platformFeeAddress) external;
    function setOwner(address _owner) external;
    function registerPosition(address creator, address token, uint256 positionId) external;

    /// @notice Get pending ETH fees for a creator
    /// @param creator The creator address
    /// @return The amount of pending fees in wei
    function creatorFees(address creator) external view returns (uint256);

    /// @notice Deposit ETH fees for a creator (called by AppsFun)
    /// @param creator The creator address to credit
    /// @param amount The amount of fees to deposit
    function depositFees(address creator, uint256 amount) external;

    /// @notice Claim pending ETH fees for the caller
    function claimFees() external;

    /// @notice Claim LP fees from a position (split 50/50 between creator and platform)
    /// @param token The token address to claim fees for
    function claimLPFees(address token) external;
}

pragma solidity >=0.8.0;

// a library for performing various math operations

library Math {
    function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
        z = x < y ? x : y;
    }

    // babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)
    function sqrt(uint256 y) internal pure returns (uint256 z) {
        if (y > 3) {
            z = y;
            uint256 x = y / 2 + 1;
            while (x < z) {
                z = x;
                x = (y / x + x) / 2;
            }
        } else if (y != 0) {
            z = 1;
        }
    }

    /// @notice Get tick from sqrtPriceX96 (approximate, rounded to tick spacing)
    /// @param sqrtPriceX96 The sqrt price as Q64.96
    /// @param tickSpacing The tick spacing to round to
    /// @return tick The calculated tick, rounded down to tick spacing
    function getTickAtSqrtPrice(uint160 sqrtPriceX96, int24 tickSpacing) internal pure returns (int24 tick) {
        // tick ≈ (log2(sqrtPriceX96) - 96) * 2 / log2(1.0001)
        uint256 price = sqrtPriceX96;
        int256 log2 = 0;

        // Find log2 via bit counting
        if (price >= 2**128) { price >>= 128; log2 += 128; }
        if (price >= 2**64) { price >>= 64; log2 += 64; }
        if (price >= 2**32) { price >>= 32; log2 += 32; }
        if (price >= 2**16) { price >>= 16; log2 += 16; }
        if (price >= 2**8) { price >>= 8; log2 += 8; }
        if (price >= 2**4) { price >>= 4; log2 += 4; }
        if (price >= 2**2) { price >>= 2; log2 += 2; }
        if (price >= 2**1) { log2 += 1; }

        // Convert: tick = (log2 - 96) * 2 / log2(1.0001) ≈ (log2 - 96) * 1386 / 10
        tick = int24(((log2 - 96) * 1386) / 10);

        // Round down to tick spacing
        tick = (tick / tickSpacing) * tickSpacing;
    }
}

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

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

import {INotifier} from "./INotifier.sol";
import {IImmutableState} from "./IImmutableState.sol";
import {IERC721Permit_v4} from "./IERC721Permit_v4.sol";
import {IEIP712_v4} from "./IEIP712_v4.sol";
import {IMulticall_v4} from "./IMulticall_v4.sol";
import {IPoolInitializer_v4} from "./IPoolInitializer_v4.sol";
import {IUnorderedNonce} from "./IUnorderedNonce.sol";
import {IPermit2Forwarder} from "./IPermit2Forwarder.sol";

/// @title IPositionManager
/// @notice Interface for the PositionManager contract
interface IPositionManager is
    INotifier,
    IImmutableState,
    IERC721Permit_v4,
    IEIP712_v4,
    IMulticall_v4,
    IPoolInitializer_v4,
    IUnorderedNonce,
    IPermit2Forwarder
{
    /// @notice Thrown when the caller is not approved to modify a position
    error NotApproved(address caller);
    /// @notice Thrown when the block.timestamp exceeds the user-provided deadline
    error DeadlinePassed(uint256 deadline);
    /// @notice Thrown when calling transfer, subscribe, or unsubscribe when the PoolManager is unlocked.
    /// @dev This is to prevent hooks from being able to trigger notifications at the same time the position is being modified.
    error PoolManagerMustBeLocked();

    /// @notice Unlocks Uniswap v4 PoolManager and batches actions for modifying liquidity
    /// @dev This is the standard entrypoint for the PositionManager
    /// @param unlockData is an encoding of actions, and parameters for those actions
    /// @param deadline is the deadline for the batched actions to be executed
    function modifyLiquidities(bytes calldata unlockData, uint256 deadline) external payable;

    /// @notice Batches actions for modifying liquidity without unlocking v4 PoolManager
    /// @dev This must be called by a contract that has already unlocked the v4 PoolManager
    /// @param actions the actions to perform
    /// @param params the parameters to provide for the actions
    function modifyLiquiditiesWithoutUnlock(bytes calldata actions, bytes[] calldata params) external payable;

    /// @notice Used to get the ID that will be used for the next minted liquidity position
    /// @return uint256 The next token ID
    function nextTokenId() external view returns (uint256);

    /// @notice Returns the liquidity of a position
    /// @param tokenId the ERC721 tokenId
    /// @return liquidity the position's liquidity, as a liquidityAmount
    /// @dev this value can be processed as an amount0 and amount1 by using the LiquidityAmounts library
    function getPositionLiquidity(uint256 tokenId) external view returns (uint128 liquidity);

    /// @notice Returns the pool key and position info of a position
    /// @param tokenId the ERC721 tokenId
    /// @return poolKey the pool key of the position
    /// @return PositionInfo a uint256 packed value holding information about the position including the range (tickLower, tickUpper)
    function getPoolAndPositionInfo(uint256 tokenId) external view returns (PoolKey memory, PositionInfo);

    /// @notice Returns the position info of a position
    /// @param tokenId the ERC721 tokenId
    /// @return a uint256 packed value holding information about the position including the range (tickLower, tickUpper)
    function positionInfo(uint256 tokenId) external view returns (PositionInfo);
}

File 10 of 53 : 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;
}

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

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

import {PoolKey} from "../types/PoolKey.sol";
import {BalanceDelta} from "../types/BalanceDelta.sol";
import {ModifyLiquidityParams, SwapParams} from "../types/PoolOperation.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,
        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,
        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,
        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,
        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, 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,
        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)
        }
    }
}

File 14 of 53 : 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.0;

import {FullMath} from "@uniswap/v4-core/src/libraries/FullMath.sol";
import {FixedPoint96} from "@uniswap/v4-core/src/libraries/FixedPoint96.sol";
import {SafeCast} from "@uniswap/v4-core/src/libraries/SafeCast.sol";

/// @notice Provides functions for computing liquidity amounts from token amounts and prices
library LiquidityAmounts {
    using SafeCast for uint256;

    /// @notice Computes the amount of liquidity received for a given amount of token0 and price range
    /// @dev Calculates amount0 * (sqrt(upper) * sqrt(lower)) / (sqrt(upper) - sqrt(lower))
    /// @param sqrtPriceAX96 A sqrt price representing the first tick boundary
    /// @param sqrtPriceBX96 A sqrt price representing the second tick boundary
    /// @param amount0 The amount0 being sent in
    /// @return liquidity The amount of returned liquidity
    function getLiquidityForAmount0(uint160 sqrtPriceAX96, uint160 sqrtPriceBX96, uint256 amount0)
        internal
        pure
        returns (uint128 liquidity)
    {
        unchecked {
            if (sqrtPriceAX96 > sqrtPriceBX96) (sqrtPriceAX96, sqrtPriceBX96) = (sqrtPriceBX96, sqrtPriceAX96);
            uint256 intermediate = FullMath.mulDiv(sqrtPriceAX96, sqrtPriceBX96, FixedPoint96.Q96);
            return FullMath.mulDiv(amount0, intermediate, sqrtPriceBX96 - sqrtPriceAX96).toUint128();
        }
    }

    /// @notice Computes the amount of liquidity received for a given amount of token1 and price range
    /// @dev Calculates amount1 / (sqrt(upper) - sqrt(lower)).
    /// @param sqrtPriceAX96 A sqrt price representing the first tick boundary
    /// @param sqrtPriceBX96 A sqrt price representing the second tick boundary
    /// @param amount1 The amount1 being sent in
    /// @return liquidity The amount of returned liquidity
    function getLiquidityForAmount1(uint160 sqrtPriceAX96, uint160 sqrtPriceBX96, uint256 amount1)
        internal
        pure
        returns (uint128 liquidity)
    {
        unchecked {
            if (sqrtPriceAX96 > sqrtPriceBX96) (sqrtPriceAX96, sqrtPriceBX96) = (sqrtPriceBX96, sqrtPriceAX96);
            return FullMath.mulDiv(amount1, FixedPoint96.Q96, sqrtPriceBX96 - sqrtPriceAX96).toUint128();
        }
    }

    /// @notice Computes the maximum amount of liquidity received for a given amount of token0, token1, the current
    /// pool prices and the prices at the tick boundaries
    /// @param sqrtPriceX96 A sqrt price representing the current pool prices
    /// @param sqrtPriceAX96 A sqrt price representing the first tick boundary
    /// @param sqrtPriceBX96 A sqrt price representing the second tick boundary
    /// @param amount0 The amount of token0 being sent in
    /// @param amount1 The amount of token1 being sent in
    /// @return liquidity The maximum amount of liquidity received
    function getLiquidityForAmounts(
        uint160 sqrtPriceX96,
        uint160 sqrtPriceAX96,
        uint160 sqrtPriceBX96,
        uint256 amount0,
        uint256 amount1
    ) internal pure returns (uint128 liquidity) {
        if (sqrtPriceAX96 > sqrtPriceBX96) {
            (sqrtPriceAX96, sqrtPriceBX96) = (sqrtPriceBX96, sqrtPriceAX96);
        }

        if (sqrtPriceX96 <= sqrtPriceAX96) {
            liquidity = getLiquidityForAmount0(sqrtPriceAX96, sqrtPriceBX96, amount0);
        } else if (sqrtPriceX96 < sqrtPriceBX96) {
            uint128 liquidity0 = getLiquidityForAmount0(sqrtPriceX96, sqrtPriceBX96, amount0);
            uint128 liquidity1 = getLiquidityForAmount1(sqrtPriceAX96, sqrtPriceX96, amount1);

            liquidity = liquidity0 < liquidity1 ? liquidity0 : liquidity1;
        } else {
            liquidity = getLiquidityForAmount1(sqrtPriceAX96, sqrtPriceBX96, amount1);
        }
    }
}

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

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

/// @title Math library for computing sqrt prices from ticks and vice versa
/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports
/// prices between 2**-128 and 2**128
library TickMath {
    using CustomRevert for bytes4;

    /// @notice Thrown when the tick passed to #getSqrtPriceAtTick is not between MIN_TICK and MAX_TICK
    error InvalidTick(int24 tick);
    /// @notice Thrown when the price passed to #getTickAtSqrtPrice does not correspond to a price between MIN_TICK and MAX_TICK
    error InvalidSqrtPrice(uint160 sqrtPriceX96);

    /// @dev The minimum tick that may be passed to #getSqrtPriceAtTick computed from log base 1.0001 of 2**-128
    /// @dev If ever MIN_TICK and MAX_TICK are not centered around 0, the absTick logic in getSqrtPriceAtTick cannot be used
    int24 internal constant MIN_TICK = -887272;
    /// @dev The maximum tick that may be passed to #getSqrtPriceAtTick computed from log base 1.0001 of 2**128
    /// @dev If ever MIN_TICK and MAX_TICK are not centered around 0, the absTick logic in getSqrtPriceAtTick cannot be used
    int24 internal constant MAX_TICK = 887272;

    /// @dev The minimum tick spacing value drawn from the range of type int16 that is greater than 0, i.e. min from the range [1, 32767]
    int24 internal constant MIN_TICK_SPACING = 1;
    /// @dev The maximum tick spacing value drawn from the range of type int16, i.e. max from the range [1, 32767]
    int24 internal constant MAX_TICK_SPACING = type(int16).max;

    /// @dev The minimum value that can be returned from #getSqrtPriceAtTick. Equivalent to getSqrtPriceAtTick(MIN_TICK)
    uint160 internal constant MIN_SQRT_PRICE = 4295128739;
    /// @dev The maximum value that can be returned from #getSqrtPriceAtTick. Equivalent to getSqrtPriceAtTick(MAX_TICK)
    uint160 internal constant MAX_SQRT_PRICE = 1461446703485210103287273052203988822378723970342;
    /// @dev A threshold used for optimized bounds check, equals `MAX_SQRT_PRICE - MIN_SQRT_PRICE - 1`
    uint160 internal constant MAX_SQRT_PRICE_MINUS_MIN_SQRT_PRICE_MINUS_ONE =
        1461446703485210103287273052203988822378723970342 - 4295128739 - 1;

    /// @notice Given a tickSpacing, compute the maximum usable tick
    function maxUsableTick(int24 tickSpacing) internal pure returns (int24) {
        unchecked {
            return (MAX_TICK / tickSpacing) * tickSpacing;
        }
    }

    /// @notice Given a tickSpacing, compute the minimum usable tick
    function minUsableTick(int24 tickSpacing) internal pure returns (int24) {
        unchecked {
            return (MIN_TICK / tickSpacing) * tickSpacing;
        }
    }

    /// @notice Calculates sqrt(1.0001^tick) * 2^96
    /// @dev Throws if |tick| > max tick
    /// @param tick The input tick for the above formula
    /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the price of the two assets (currency1/currency0)
    /// at the given tick
    function getSqrtPriceAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {
        unchecked {
            uint256 absTick;
            assembly ("memory-safe") {
                tick := signextend(2, tick)
                // mask = 0 if tick >= 0 else -1 (all 1s)
                let mask := sar(255, tick)
                // if tick >= 0, |tick| = tick = 0 ^ tick
                // if tick < 0, |tick| = ~~|tick| = ~(-|tick| - 1) = ~(tick - 1) = (-1) ^ (tick - 1)
                // either way, |tick| = mask ^ (tick + mask)
                absTick := xor(mask, add(mask, tick))
            }

            if (absTick > uint256(int256(MAX_TICK))) InvalidTick.selector.revertWith(tick);

            // The tick is decomposed into bits, and for each bit with index i that is set, the product of 1/sqrt(1.0001^(2^i))
            // is calculated (using Q128.128). The constants used for this calculation are rounded to the nearest integer

            // Equivalent to:
            //     price = absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000;
            //     or price = int(2**128 / sqrt(1.0001)) if (absTick & 0x1) else 1 << 128
            uint256 price;
            assembly ("memory-safe") {
                price := xor(shl(128, 1), mul(xor(shl(128, 1), 0xfffcb933bd6fad37aa2d162d1a594001), and(absTick, 0x1)))
            }
            if (absTick & 0x2 != 0) price = (price * 0xfff97272373d413259a46990580e213a) >> 128;
            if (absTick & 0x4 != 0) price = (price * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128;
            if (absTick & 0x8 != 0) price = (price * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128;
            if (absTick & 0x10 != 0) price = (price * 0xffcb9843d60f6159c9db58835c926644) >> 128;
            if (absTick & 0x20 != 0) price = (price * 0xff973b41fa98c081472e6896dfb254c0) >> 128;
            if (absTick & 0x40 != 0) price = (price * 0xff2ea16466c96a3843ec78b326b52861) >> 128;
            if (absTick & 0x80 != 0) price = (price * 0xfe5dee046a99a2a811c461f1969c3053) >> 128;
            if (absTick & 0x100 != 0) price = (price * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128;
            if (absTick & 0x200 != 0) price = (price * 0xf987a7253ac413176f2b074cf7815e54) >> 128;
            if (absTick & 0x400 != 0) price = (price * 0xf3392b0822b70005940c7a398e4b70f3) >> 128;
            if (absTick & 0x800 != 0) price = (price * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128;
            if (absTick & 0x1000 != 0) price = (price * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;
            if (absTick & 0x2000 != 0) price = (price * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128;
            if (absTick & 0x4000 != 0) price = (price * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128;
            if (absTick & 0x8000 != 0) price = (price * 0x31be135f97d08fd981231505542fcfa6) >> 128;
            if (absTick & 0x10000 != 0) price = (price * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128;
            if (absTick & 0x20000 != 0) price = (price * 0x5d6af8dedb81196699c329225ee604) >> 128;
            if (absTick & 0x40000 != 0) price = (price * 0x2216e584f5fa1ea926041bedfe98) >> 128;
            if (absTick & 0x80000 != 0) price = (price * 0x48a170391f7dc42444e8fa2) >> 128;

            assembly ("memory-safe") {
                // if (tick > 0) price = type(uint256).max / price;
                if sgt(tick, 0) { price := div(not(0), price) }

                // this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96.
                // we then downcast because we know the result always fits within 160 bits due to our tick input constraint
                // we round up in the division so getTickAtSqrtPrice of the output price is always consistent
                // `sub(shl(32, 1), 1)` is `type(uint32).max`
                // `price + type(uint32).max` will not overflow because `price` fits in 192 bits
                sqrtPriceX96 := shr(32, add(price, sub(shl(32, 1), 1)))
            }
        }
    }

    /// @notice Calculates the greatest tick value such that getSqrtPriceAtTick(tick) <= sqrtPriceX96
    /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_PRICE, as MIN_SQRT_PRICE is the lowest value getSqrtPriceAtTick may
    /// ever return.
    /// @param sqrtPriceX96 The sqrt price for which to compute the tick as a Q64.96
    /// @return tick The greatest tick for which the getSqrtPriceAtTick(tick) is less than or equal to the input sqrtPriceX96
    function getTickAtSqrtPrice(uint160 sqrtPriceX96) internal pure returns (int24 tick) {
        unchecked {
            // Equivalent: if (sqrtPriceX96 < MIN_SQRT_PRICE || sqrtPriceX96 >= MAX_SQRT_PRICE) revert InvalidSqrtPrice();
            // second inequality must be >= because the price can never reach the price at the max tick
            // if sqrtPriceX96 < MIN_SQRT_PRICE, the `sub` underflows and `gt` is true
            // if sqrtPriceX96 >= MAX_SQRT_PRICE, sqrtPriceX96 - MIN_SQRT_PRICE > MAX_SQRT_PRICE - MIN_SQRT_PRICE - 1
            if ((sqrtPriceX96 - MIN_SQRT_PRICE) > MAX_SQRT_PRICE_MINUS_MIN_SQRT_PRICE_MINUS_ONE) {
                InvalidSqrtPrice.selector.revertWith(sqrtPriceX96);
            }

            uint256 price = uint256(sqrtPriceX96) << 32;

            uint256 r = price;
            uint256 msb = BitMath.mostSignificantBit(r);

            if (msb >= 128) r = price >> (msb - 127);
            else r = price << (127 - msb);

            int256 log_2 = (int256(msb) - 128) << 64;

            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(63, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(62, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(61, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(60, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(59, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(58, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(57, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(56, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(55, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(54, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(53, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(52, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(51, f))
                r := shr(f, r)
            }
            assembly ("memory-safe") {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(50, f))
            }

            int256 log_sqrt10001 = log_2 * 255738958999603826347141; // Q22.128 number

            // Magic number represents the ceiling of the maximum value of the error when approximating log_sqrt10001(x)
            int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128);

            // Magic number represents the minimum value of the error when approximating log_sqrt10001(x), when
            // sqrtPrice is from the range (2^-64, 2^64). This is safe as MIN_SQRT_PRICE is more than 2^-64. If MIN_SQRT_PRICE
            // is changed, this may need to be changed too
            int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128);

            tick = tickLow == tickHi ? tickLow : getSqrtPriceAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow;
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC-20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    /**
     * @dev An operation with an ERC-20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        if (!_safeTransfer(token, to, value, true)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        if (!_safeTransferFrom(token, from, to, value, true)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
        return _safeTransfer(token, to, value, false);
    }

    /**
     * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
        return _safeTransferFrom(token, from, to, value, false);
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     *
     * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
     * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
     * set here.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        if (!_safeApprove(token, spender, value, false)) {
            if (!_safeApprove(token, spender, 0, true)) revert SafeERC20FailedOperation(address(token));
            if (!_safeApprove(token, spender, value, true)) revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            safeTransfer(token, to, value);
        } else if (!token.transferAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
     * has no code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferFromAndCallRelaxed(
        IERC1363 token,
        address from,
        address to,
        uint256 value,
        bytes memory data
    ) internal {
        if (to.code.length == 0) {
            safeTransferFrom(token, from, to, value);
        } else if (!token.transferFromAndCall(from, to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
     * Oppositely, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
     * once without retrying, and relies on the returned value to be true.
     *
     * Reverts if the returned value is other than `true`.
     */
    function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            forceApprove(token, to, value);
        } else if (!token.approveAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity `token.transfer(to, value)` call, relaxing the requirement on the return value: the
     * return value is optional (but if data is returned, it must not be false).
     *
     * @param token The token targeted by the call.
     * @param to The recipient of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeTransfer(IERC20 token, address to, uint256 value, bool bubble) private returns (bool success) {
        bytes4 selector = IERC20.transfer.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(to, shr(96, not(0))))
            mstore(0x24, value)
            success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
        }
    }

    /**
     * @dev Imitates a Solidity `token.transferFrom(from, to, value)` call, relaxing the requirement on the return
     * value: the return value is optional (but if data is returned, it must not be false).
     *
     * @param token The token targeted by the call.
     * @param from The sender of the tokens
     * @param to The recipient of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value,
        bool bubble
    ) private returns (bool success) {
        bytes4 selector = IERC20.transferFrom.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(from, shr(96, not(0))))
            mstore(0x24, and(to, shr(96, not(0))))
            mstore(0x44, value)
            success := call(gas(), token, 0, 0x00, 0x64, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
            mstore(0x60, 0)
        }
    }

    /**
     * @dev Imitates a Solidity `token.approve(spender, value)` call, relaxing the requirement on the return value:
     * the return value is optional (but if data is returned, it must not be false).
     *
     * @param token The token targeted by the call.
     * @param spender The spender of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeApprove(IERC20 token, address spender, uint256 value, bool bubble) private returns (bool success) {
        bytes4 selector = IERC20.approve.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(spender, shr(96, not(0))))
            mstore(0x24, value)
            success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}

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

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

/// @title AllowanceTransfer
/// @notice Handles ERC20 token permissions through signature based allowance setting and ERC20 token transfers by checking allowed amounts
/// @dev Requires user's token approval on the Permit2 contract
interface IAllowanceTransfer is IEIP712 {
    /// @notice Thrown when an allowance on a token has expired.
    /// @param deadline The timestamp at which the allowed amount is no longer valid
    error AllowanceExpired(uint256 deadline);

    /// @notice Thrown when an allowance on a token has been depleted.
    /// @param amount The maximum amount allowed
    error InsufficientAllowance(uint256 amount);

    /// @notice Thrown when too many nonces are invalidated.
    error ExcessiveInvalidation();

    /// @notice Emits an event when the owner successfully invalidates an ordered nonce.
    event NonceInvalidation(
        address indexed owner, address indexed token, address indexed spender, uint48 newNonce, uint48 oldNonce
    );

    /// @notice Emits an event when the owner successfully sets permissions on a token for the spender.
    event Approval(
        address indexed owner, address indexed token, address indexed spender, uint160 amount, uint48 expiration
    );

    /// @notice Emits an event when the owner successfully sets permissions using a permit signature on a token for the spender.
    event Permit(
        address indexed owner,
        address indexed token,
        address indexed spender,
        uint160 amount,
        uint48 expiration,
        uint48 nonce
    );

    /// @notice Emits an event when the owner sets the allowance back to 0 with the lockdown function.
    event Lockdown(address indexed owner, address token, address spender);

    /// @notice The permit data for a token
    struct PermitDetails {
        // ERC20 token address
        address token;
        // the maximum amount allowed to spend
        uint160 amount;
        // timestamp at which a spender's token allowances become invalid
        uint48 expiration;
        // an incrementing value indexed per owner,token,and spender for each signature
        uint48 nonce;
    }

    /// @notice The permit message signed for a single token allowance
    struct PermitSingle {
        // the permit data for a single token alownce
        PermitDetails details;
        // address permissioned on the allowed tokens
        address spender;
        // deadline on the permit signature
        uint256 sigDeadline;
    }

    /// @notice The permit message signed for multiple token allowances
    struct PermitBatch {
        // the permit data for multiple token allowances
        PermitDetails[] details;
        // address permissioned on the allowed tokens
        address spender;
        // deadline on the permit signature
        uint256 sigDeadline;
    }

    /// @notice The saved permissions
    /// @dev This info is saved per owner, per token, per spender and all signed over in the permit message
    /// @dev Setting amount to type(uint160).max sets an unlimited approval
    struct PackedAllowance {
        // amount allowed
        uint160 amount;
        // permission expiry
        uint48 expiration;
        // an incrementing value indexed per owner,token,and spender for each signature
        uint48 nonce;
    }

    /// @notice A token spender pair.
    struct TokenSpenderPair {
        // the token the spender is approved
        address token;
        // the spender address
        address spender;
    }

    /// @notice Details for a token transfer.
    struct AllowanceTransferDetails {
        // the owner of the token
        address from;
        // the recipient of the token
        address to;
        // the amount of the token
        uint160 amount;
        // the token to be transferred
        address token;
    }

    /// @notice A mapping from owner address to token address to spender address to PackedAllowance struct, which contains details and conditions of the approval.
    /// @notice The mapping is indexed in the above order see: allowance[ownerAddress][tokenAddress][spenderAddress]
    /// @dev The packed slot holds the allowed amount, expiration at which the allowed amount is no longer valid, and current nonce thats updated on any signature based approvals.
    function allowance(address user, address token, address spender)
        external
        view
        returns (uint160 amount, uint48 expiration, uint48 nonce);

    /// @notice Approves the spender to use up to amount of the specified token up until the expiration
    /// @param token The token to approve
    /// @param spender The spender address to approve
    /// @param amount The approved amount of the token
    /// @param expiration The timestamp at which the approval is no longer valid
    /// @dev The packed allowance also holds a nonce, which will stay unchanged in approve
    /// @dev Setting amount to type(uint160).max sets an unlimited approval
    function approve(address token, address spender, uint160 amount, uint48 expiration) external;

    /// @notice Permit a spender to a given amount of the owners token via the owner's EIP-712 signature
    /// @dev May fail if the owner's nonce was invalidated in-flight by invalidateNonce
    /// @param owner The owner of the tokens being approved
    /// @param permitSingle Data signed over by the owner specifying the terms of approval
    /// @param signature The owner's signature over the permit data
    function permit(address owner, PermitSingle memory permitSingle, bytes calldata signature) external;

    /// @notice Permit a spender to the signed amounts of the owners tokens via the owner's EIP-712 signature
    /// @dev May fail if the owner's nonce was invalidated in-flight by invalidateNonce
    /// @param owner The owner of the tokens being approved
    /// @param permitBatch Data signed over by the owner specifying the terms of approval
    /// @param signature The owner's signature over the permit data
    function permit(address owner, PermitBatch memory permitBatch, bytes calldata signature) external;

    /// @notice Transfer approved tokens from one address to another
    /// @param from The address to transfer from
    /// @param to The address of the recipient
    /// @param amount The amount of the token to transfer
    /// @param token The token address to transfer
    /// @dev Requires the from address to have approved at least the desired amount
    /// of tokens to msg.sender.
    function transferFrom(address from, address to, uint160 amount, address token) external;

    /// @notice Transfer approved tokens in a batch
    /// @param transferDetails Array of owners, recipients, amounts, and tokens for the transfers
    /// @dev Requires the from addresses to have approved at least the desired amount
    /// of tokens to msg.sender.
    function transferFrom(AllowanceTransferDetails[] calldata transferDetails) external;

    /// @notice Enables performing a "lockdown" of the sender's Permit2 identity
    /// by batch revoking approvals
    /// @param approvals Array of approvals to revoke.
    function lockdown(TokenSpenderPair[] calldata approvals) external;

    /// @notice Invalidate nonces for a given (token, spender) pair
    /// @param token The token to invalidate nonces for
    /// @param spender The spender to invalidate nonces for
    /// @param newNonce The new nonce to set. Invalidates all nonces less than it.
    /// @dev Can't invalidate more than 2**16 nonces per transaction.
    function invalidateNonces(address token, address spender, uint48 newNonce) external;
}

pragma solidity >=0.8.0;

// a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))

// range: [0, 2**112 - 1]
// resolution: 1 / 2**112

library UQ112x112 {
    uint224 constant Q112 = 2 ** 112;

    // encode a uint112 as a UQ112x112
    function encode(uint112 y) internal pure returns (uint224 z) {
        z = uint224(y) * Q112; // never overflows
    }

    // divide a UQ112x112 by a uint112, returning a UQ112x112
    function uqdiv(uint224 x, uint112 y) internal pure returns (uint224 z) {
        z = x / uint224(y);
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC-20
 * applications.
 */
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
    mapping(address account => uint256) private _balances;

    mapping(address account => mapping(address spender => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * Both values are immutable: they can only be set once during construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the default value returned by this function, unless
     * it's overridden.
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual returns (uint8) {
        return 18;
    }

    /// @inheritdoc IERC20
    function totalSupply() public view virtual returns (uint256) {
        return _totalSupply;
    }

    /// @inheritdoc IERC20
    function balanceOf(address account) public view virtual returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - the caller must have a balance of at least `value`.
     */
    function transfer(address to, uint256 value) public virtual returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, value);
        return true;
    }

    /// @inheritdoc IERC20
    function allowance(address owner, address spender) public view virtual returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 value) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, value);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Skips emitting an {Approval} event indicating an allowance update. This is not
     * required by the ERC. See {xref-ERC20-_approve-address-address-uint256-bool-}[_approve].
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `value`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `value`.
     */
    function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, value);
        _transfer(from, to, value);
        return true;
    }

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _transfer(address from, address to, uint256 value) internal {
        if (from == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        if (to == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(from, to, value);
    }

    /**
     * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
     * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
     * this function.
     *
     * Emits a {Transfer} event.
     */
    function _update(address from, address to, uint256 value) internal virtual {
        if (from == address(0)) {
            // Overflow check required: The rest of the code assumes that totalSupply never overflows
            _totalSupply += value;
        } else {
            uint256 fromBalance = _balances[from];
            if (fromBalance < value) {
                revert ERC20InsufficientBalance(from, fromBalance, value);
            }
            unchecked {
                // Overflow not possible: value <= fromBalance <= totalSupply.
                _balances[from] = fromBalance - value;
            }
        }

        if (to == address(0)) {
            unchecked {
                // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
                _totalSupply -= value;
            }
        } else {
            unchecked {
                // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
                _balances[to] += value;
            }
        }

        emit Transfer(from, to, value);
    }

    /**
     * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
     * Relies on the `_update` mechanism
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _mint(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(address(0), account, value);
    }

    /**
     * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
     * Relies on the `_update` mechanism.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead
     */
    function _burn(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        _update(account, address(0), value);
    }

    /**
     * @dev Sets `value` as the allowance of `spender` over the `owner`'s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     *
     * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
     */
    function _approve(address owner, address spender, uint256 value) internal {
        _approve(owner, spender, value, true);
    }

    /**
     * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
     *
     * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
     * `_spendAllowance` during the `transferFrom` operation sets the flag to false. This saves gas by not emitting any
     * `Approval` event during `transferFrom` operations.
     *
     * Anyone who wishes to continue emitting `Approval` events on the `transferFrom` operation can force the flag to
     * true using the following override:
     *
     * ```solidity
     * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
     *     super._approve(owner, spender, value, true);
     * }
     * ```
     *
     * Requirements are the same as {_approve}.
     */
    function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
        if (owner == address(0)) {
            revert ERC20InvalidApprover(address(0));
        }
        if (spender == address(0)) {
            revert ERC20InvalidSpender(address(0));
        }
        _allowances[owner][spender] = value;
        if (emitEvent) {
            emit Approval(owner, spender, value);
        }
    }

    /**
     * @dev Updates `owner`'s allowance for `spender` based on spent `value`.
     *
     * Does not update the allowance value in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Does not emit an {Approval} event.
     */
    function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance < type(uint256).max) {
            if (currentAllowance < value) {
                revert ERC20InsufficientAllowance(spender, currentAllowance, value);
            }
            unchecked {
                _approve(owner, spender, currentAllowance - value, false);
            }
        }
    }
}

// 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: MIT
pragma solidity ^0.8.0;

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

/// @title INotifier
/// @notice Interface for the Notifier contract
interface INotifier {
    /// @notice Thrown when unsubscribing without a subscriber
    error NotSubscribed();
    /// @notice Thrown when a subscriber does not have code
    error NoCodeSubscriber();
    /// @notice Thrown when a user specifies a gas limit too low to avoid valid unsubscribe notifications
    error GasLimitTooLow();
    /// @notice Wraps the revert message of the subscriber contract on a reverting subscription
    error SubscriptionReverted(address subscriber, bytes reason);
    /// @notice Wraps the revert message of the subscriber contract on a reverting modify liquidity notification
    error ModifyLiquidityNotificationReverted(address subscriber, bytes reason);
    /// @notice Wraps the revert message of the subscriber contract on a reverting burn notification
    error BurnNotificationReverted(address subscriber, bytes reason);
    /// @notice Thrown when a tokenId already has a subscriber
    error AlreadySubscribed(uint256 tokenId, address subscriber);

    /// @notice Emitted on a successful call to subscribe
    event Subscription(uint256 indexed tokenId, address indexed subscriber);
    /// @notice Emitted on a successful call to unsubscribe
    event Unsubscription(uint256 indexed tokenId, address indexed subscriber);

    /// @notice Returns the subscriber for a respective position
    /// @param tokenId the ERC721 tokenId
    /// @return subscriber the subscriber contract
    function subscriber(uint256 tokenId) external view returns (ISubscriber subscriber);

    /// @notice Enables the subscriber to receive notifications for a respective position
    /// @param tokenId the ERC721 tokenId
    /// @param newSubscriber the address of the subscriber contract
    /// @param data caller-provided data that's forwarded to the subscriber contract
    /// @dev Calling subscribe when a position is already subscribed will revert
    /// @dev payable so it can be multicalled with NATIVE related actions
    /// @dev will revert if pool manager is locked
    function subscribe(uint256 tokenId, address newSubscriber, bytes calldata data) external payable;

    /// @notice Removes the subscriber from receiving notifications for a respective position
    /// @param tokenId the ERC721 tokenId
    /// @dev Callers must specify a high gas limit (remaining gas should be higher than unsubscriberGasLimit) such that the subscriber can be notified
    /// @dev payable so it can be multicalled with NATIVE related actions
    /// @dev Must always allow a user to unsubscribe. In the case of a malicious subscriber, a user can always unsubscribe safely, ensuring liquidity is always modifiable.
    /// @dev will revert if pool manager is locked
    function unsubscribe(uint256 tokenId) external payable;

    /// @notice Returns and determines the maximum allowable gas-used for notifying unsubscribe
    /// @return uint256 the maximum gas limit when notifying a subscriber's `notifyUnsubscribe` function
    function unsubscribeGasLimit() external view returns (uint256);
}

File 24 of 53 : 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
pragma solidity ^0.8.0;

/// @title IERC721Permit_v4
/// @notice Interface for the ERC721Permit_v4 contract
interface IERC721Permit_v4 {
    error SignatureDeadlineExpired();
    error NoSelfPermit();
    error Unauthorized();

    /// @notice Approve of a specific token ID for spending by spender via signature
    /// @param spender The account that is being approved
    /// @param tokenId The ID of the token that is being approved for spending
    /// @param deadline The deadline timestamp by which the call must be mined for the approve to work
    /// @param nonce a unique value, for an owner, to prevent replay attacks; an unordered nonce where the top 248 bits correspond to a word and the bottom 8 bits calculate the bit position of the word
    /// @param signature Concatenated data from a valid secp256k1 signature from the holder, i.e. abi.encodePacked(r, s, v)
    /// @dev payable so it can be multicalled with NATIVE related actions
    function permit(address spender, uint256 tokenId, uint256 deadline, uint256 nonce, bytes calldata signature)
        external
        payable;

    /// @notice Set an operator with full permission to an owner's tokens via signature
    /// @param owner The address that is setting the operator
    /// @param operator The address that will be set as an operator for the owner
    /// @param approved The permission to set on the operator
    /// @param deadline The deadline timestamp by which the call must be mined for the approve to work
    /// @param nonce a unique value, for an owner, to prevent replay attacks; an unordered nonce where the top 248 bits correspond to a word and the bottom 8 bits calculate the bit position of the word
    /// @param signature Concatenated data from a valid secp256k1 signature from the holder, i.e. abi.encodePacked(r, s, v)
    /// @dev payable so it can be multicalled with NATIVE related actions
    function permitForAll(
        address owner,
        address operator,
        bool approved,
        uint256 deadline,
        uint256 nonce,
        bytes calldata signature
    ) external payable;
}

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

/// @title IEIP712_v4
/// @notice Interface for the EIP712 contract
interface IEIP712_v4 {
    /// @notice Returns the domain separator for the current chain.
    /// @return bytes32 The domain separator
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

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

/// @title IMulticall_v4
/// @notice Interface for the Multicall_v4 contract
interface IMulticall_v4 {
    /// @notice Call multiple functions in the current contract and return the data from all of them if they all succeed
    /// @dev The `msg.value` is passed onto all subcalls, even if a previous subcall has consumed the ether.
    /// Subcalls can instead use `address(this).value` to see the available ETH, and consume it using {value: x}.
    /// @param data The encoded function data for each of the calls to make to this contract
    /// @return results The results from each of the calls passed in via data
    function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);
}

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

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

/// @title IPoolInitializer_v4
/// @notice Interface for the PoolInitializer_v4 contract
interface IPoolInitializer_v4 {
    /// @notice Initialize a Uniswap v4 Pool
    /// @dev If the pool is already initialized, this function will not revert and just return type(int24).max
    /// @param key The PoolKey of the pool to initialize
    /// @param sqrtPriceX96 The initial starting price of the pool, expressed as a sqrtPriceX96
    /// @return The current tick of the pool, or type(int24).max if the pool creation failed, or the pool already existed
    function initializePool(PoolKey calldata key, uint160 sqrtPriceX96) external payable returns (int24);
}

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

/// @title IUnorderedNonce
/// @notice Interface for the UnorderedNonce contract
interface IUnorderedNonce {
    error NonceAlreadyUsed();

    /// @notice mapping of nonces consumed by each address, where a nonce is a single bit on the 256-bit bitmap
    /// @dev word is at most type(uint248).max
    function nonces(address owner, uint256 word) external view returns (uint256);

    /// @notice Revoke a nonce by spending it, preventing it from being used again
    /// @dev Used in cases where a valid nonce has not been broadcasted onchain, and the owner wants to revoke the validity of the nonce
    /// @dev payable so it can be multicalled with native-token related actions
    function revokeNonce(uint256 nonce) external payable;
}

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

import {IAllowanceTransfer} from "permit2/src/interfaces/IAllowanceTransfer.sol";

/// @title IPermit2Forwarder
/// @notice Interface for the Permit2Forwarder contract
interface IPermit2Forwarder {
    /// @notice allows forwarding a single permit to permit2
    /// @dev this function is payable to allow multicall with NATIVE based actions
    /// @param owner the owner of the tokens
    /// @param permitSingle the permit data
    /// @param signature the signature of the permit; abi.encodePacked(r, s, v)
    /// @return err the error returned by a reverting permit call, empty if successful
    function permit(address owner, IAllowanceTransfer.PermitSingle calldata permitSingle, bytes calldata signature)
        external
        payable
        returns (bytes memory err);

    /// @notice allows forwarding batch permits to permit2
    /// @dev this function is payable to allow multicall with NATIVE based actions
    /// @param owner the owner of the tokens
    /// @param _permitBatch a batch of approvals
    /// @param signature the signature of the permit; abi.encodePacked(r, s, v)
    /// @return err the error returned by a reverting permit call, empty if successful
    function permitBatch(address owner, IAllowanceTransfer.PermitBatch calldata _permitBatch, bytes calldata signature)
        external
        payable
        returns (bytes memory err);
}

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

File 34 of 53 : PoolOperation.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

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

/// @notice Parameter struct for `ModifyLiquidity` pool operations
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 Parameter struct for `Swap` pool operations
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;
}

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

/// @title Contains 512-bit math functions
/// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision
/// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits
library FullMath {
    /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
    /// @param a The multiplicand
    /// @param b The multiplier
    /// @param denominator The divisor
    /// @return result The 256-bit result
    /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv
    function mulDiv(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = a * b
            // Compute the product mod 2**256 and mod 2**256 - 1
            // then use the Chinese Remainder Theorem to reconstruct
            // the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2**256 + prod0
            uint256 prod0 = a * b; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly ("memory-safe") {
                let mm := mulmod(a, b, not(0))
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Make sure the result is less than 2**256.
            // Also prevents denominator == 0
            require(denominator > prod1);

            // Handle non-overflow cases, 256 by 256 division
            if (prod1 == 0) {
                assembly ("memory-safe") {
                    result := div(prod0, denominator)
                }
                return result;
            }

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0]
            // Compute remainder using mulmod
            uint256 remainder;
            assembly ("memory-safe") {
                remainder := mulmod(a, b, denominator)
            }
            // Subtract 256 bit number from 512 bit number
            assembly ("memory-safe") {
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator
            // Compute largest power of two divisor of denominator.
            // Always >= 1.
            uint256 twos = (0 - denominator) & denominator;
            // Divide denominator by power of two
            assembly ("memory-safe") {
                denominator := div(denominator, twos)
            }

            // Divide [prod1 prod0] by the factors of two
            assembly ("memory-safe") {
                prod0 := div(prod0, twos)
            }
            // Shift in bits from prod1 into prod0. For this we need
            // to flip `twos` such that it is 2**256 / twos.
            // If twos is zero, then it becomes one
            assembly ("memory-safe") {
                twos := add(div(sub(0, twos), twos), 1)
            }
            prod0 |= prod1 * twos;

            // Invert denominator mod 2**256
            // Now that denominator is an odd number, it has an inverse
            // modulo 2**256 such that denominator * inv = 1 mod 2**256.
            // Compute the inverse by starting with a seed that is correct
            // correct for four bits. That is, denominator * inv = 1 mod 2**4
            uint256 inv = (3 * denominator) ^ 2;
            // Now use Newton-Raphson iteration to improve the precision.
            // Thanks to Hensel's lifting lemma, this also works in modular
            // arithmetic, doubling the correct bits in each step.
            inv *= 2 - denominator * inv; // inverse mod 2**8
            inv *= 2 - denominator * inv; // inverse mod 2**16
            inv *= 2 - denominator * inv; // inverse mod 2**32
            inv *= 2 - denominator * inv; // inverse mod 2**64
            inv *= 2 - denominator * inv; // inverse mod 2**128
            inv *= 2 - denominator * inv; // inverse mod 2**256

            // Because the division is now exact we can divide by multiplying
            // with the modular inverse of denominator. This will give us the
            // correct result modulo 2**256. Since the preconditions guarantee
            // that the outcome is less than 2**256, this is the final result.
            // We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inv;
            return result;
        }
    }

    /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
    /// @param a The multiplicand
    /// @param b The multiplier
    /// @param denominator The divisor
    /// @return result The 256-bit result
    function mulDivRoundingUp(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            result = mulDiv(a, b, denominator);
            if (mulmod(a, b, denominator) != 0) {
                require(++result > 0);
            }
        }
    }
}

File 37 of 53 : FixedPoint96.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @title FixedPoint96
/// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format)
/// @dev Used in SqrtPriceMath.sol
library FixedPoint96 {
    uint8 internal constant RESOLUTION = 96;
    uint256 internal constant Q96 = 0x1000000000000000000000000;
}

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

/// @title BitMath
/// @dev This library provides functionality for computing bit properties of an unsigned integer
/// @author Solady (https://github.com/Vectorized/solady/blob/8200a70e8dc2a77ecb074fc2e99a2a0d36547522/src/utils/LibBit.sol)
library BitMath {
    /// @notice Returns the index of the most significant bit of the number,
    ///     where the least significant bit is at index 0 and the most significant bit is at index 255
    /// @param x the value for which to compute the most significant bit, must be greater than 0
    /// @return r the index of the most significant bit
    function mostSignificantBit(uint256 x) internal pure returns (uint8 r) {
        require(x > 0);

        assembly ("memory-safe") {
            r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
            r := or(r, shl(4, lt(0xffff, shr(r, x))))
            r := or(r, shl(3, lt(0xff, shr(r, x))))
            // forgefmt: disable-next-item
            r := or(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)),
                0x0706060506020500060203020504000106050205030304010505030400000000))
        }
    }

    /// @notice Returns the index of the least significant bit of the number,
    ///     where the least significant bit is at index 0 and the most significant bit is at index 255
    /// @param x the value for which to compute the least significant bit, must be greater than 0
    /// @return r the index of the least significant bit
    function leastSignificantBit(uint256 x) internal pure returns (uint8 r) {
        require(x > 0);

        assembly ("memory-safe") {
            // Isolate the least significant bit.
            x := and(x, sub(0, x))
            // For the upper 3 bits of the result, use a De Bruijn-like lookup.
            // Credit to adhusson: https://blog.adhusson.com/cheap-find-first-set-evm/
            // forgefmt: disable-next-item
            r := shl(5, shr(252, shl(shl(2, shr(250, mul(x,
                0xb6db6db6ddddddddd34d34d349249249210842108c6318c639ce739cffffffff))),
                0x8040405543005266443200005020610674053026020000107506200176117077)))
            // For the lower 5 bits of the result, use a De Bruijn lookup.
            // forgefmt: disable-next-item
            r := or(r, byte(and(div(0xd76453e0, shr(r, x)), 0x1f),
                0x001f0d1e100c1d070f090b19131c1706010e11080a1a141802121b1503160405))
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)

pragma solidity >=0.6.2;

import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";

/**
 * @title IERC1363
 * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
 *
 * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
 * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
 */
interface IERC1363 is IERC20, IERC165 {
    /*
     * Note: the ERC-165 identifier for this interface is 0xb0202a11.
     * 0xb0202a11 ===
     *   bytes4(keccak256('transferAndCall(address,uint256)')) ^
     *   bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
     */

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @param data Additional data with no specified format, sent in call to `spender`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}

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

interface IEIP712 {
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity >=0.6.2;

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

/**
 * @dev Interface for the optional metadata functions from the ERC-20 standard.
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (interfaces/draft-IERC6093.sol)

pragma solidity >=0.8.4;

/**
 * @dev Standard ERC-20 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-20 tokens.
 */
interface IERC20Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC20InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC20InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     * @param allowance Amount of tokens a `spender` is allowed to operate with.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC20InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `spender` to be approved. Used in approvals.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC20InvalidSpender(address spender);
}

/**
 * @dev Standard ERC-721 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-721 tokens.
 */
interface IERC721Errors {
    /**
     * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in ERC-721.
     * Used in balance queries.
     * @param owner Address of the current owner of a token.
     */
    error ERC721InvalidOwner(address owner);

    /**
     * @dev Indicates a `tokenId` whose `owner` is the zero address.
     * @param tokenId Identifier number of a token.
     */
    error ERC721NonexistentToken(uint256 tokenId);

    /**
     * @dev Indicates an error related to the ownership over a particular token. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param tokenId Identifier number of a token.
     * @param owner Address of the current owner of a token.
     */
    error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC721InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC721InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param tokenId Identifier number of a token.
     */
    error ERC721InsufficientApproval(address operator, uint256 tokenId);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC721InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC721InvalidOperator(address operator);
}

/**
 * @dev Standard ERC-1155 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC-1155 tokens.
 */
interface IERC1155Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     * @param tokenId Identifier number of a token.
     */
    error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC1155InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC1155InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param owner Address of the current owner of a token.
     */
    error ERC1155MissingApprovalForAll(address operator, address owner);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC1155InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC1155InvalidOperator(address operator);

    /**
     * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
     * Used in batch transfers.
     * @param idsLength Length of the array of token identifiers
     * @param valuesLength Length of the array of token amounts
     */
    error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}

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

import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";
import {PositionInfo} from "../libraries/PositionInfoLibrary.sol";

/// @title ISubscriber
/// @notice Interface that a Subscriber contract should implement to receive updates from the v4 position manager
interface ISubscriber {
    /// @notice Called when a position subscribes to this subscriber contract
    /// @param tokenId the token ID of the position
    /// @param data additional data passed in by the caller
    function notifySubscribe(uint256 tokenId, bytes memory data) external;

    /// @notice Called when a position unsubscribes from the subscriber
    /// @dev This call's gas is capped at `unsubscribeGasLimit` (set at deployment)
    /// @dev Because of EIP-150, solidity may only allocate 63/64 of gasleft()
    /// @param tokenId the token ID of the position
    function notifyUnsubscribe(uint256 tokenId) external;

    /// @notice Called when a position is burned
    /// @param tokenId the token ID of the position
    /// @param owner the current owner of the tokenId
    /// @param info information about the position
    /// @param liquidity the amount of liquidity decreased in the position, may be 0
    /// @param feesAccrued the fees accrued by the position if liquidity was decreased
    function notifyBurn(uint256 tokenId, address owner, PositionInfo info, uint256 liquidity, BalanceDelta feesAccrued)
        external;

    /// @notice Called when a position modifies its liquidity or collects fees
    /// @param tokenId the token ID of the position
    /// @param liquidityChange the change in liquidity on the underlying position
    /// @param feesAccrued the fees to be collected from the position as a result of the modifyLiquidity call
    /// @dev Note that feesAccrued can be artificially inflated by a malicious user
    /// Pools with a single liquidity position can inflate feeGrowthGlobal (and consequently feesAccrued) by donating to themselves;
    /// atomically donating and collecting fees within the same unlockCallback may further inflate feeGrowthGlobal/feesAccrued
    function notifyModifyLiquidity(uint256 tokenId, int256 liquidityChange, BalanceDelta feesAccrued) external;
}

// 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";
import {ModifyLiquidityParams, SwapParams} from "../types/PoolOperation.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);

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

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

File 47 of 53 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)

pragma solidity >=0.4.16;

import {IERC20} from "../token/ERC20/IERC20.sol";

File 48 of 53 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)

pragma solidity >=0.4.16;

import {IERC165} from "../utils/introspection/IERC165.sol";

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

Settings
{
  "remappings": [
    "@uniswap/v4-core/=lib/v4-core/",
    "@uniswap/v4-periphery/=lib/v4-periphery/",
    "@uniswap/v2-core/=lib/v2-core/",
    "v4-core/=lib/v4-core/src/",
    "v4-periphery/=lib/v4-periphery/",
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "permit2/=lib/v4-periphery/lib/permit2/",
    "@ensdomains/=lib/v4-core/node_modules/@ensdomains/",
    "ds-test/=lib/v4-core/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-gas-snapshot/=lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/src/",
    "forge-std/=lib/forge-std/src/",
    "halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "hardhat/=lib/v4-core/node_modules/hardhat/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "solmate/=lib/v4-core/lib/solmate/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "cancun",
  "viaIR": true
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"_WETH","type":"address"},{"internalType":"address","name":"_feeHolder","type":"address"},{"internalType":"address","name":"_permit2","type":"address"},{"internalType":"uint256","name":"_virtualBaseReserve","type":"uint256"},{"internalType":"uint256","name":"_graduationThreshold","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"creator","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"creatorFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"platformFee","type":"uint256"}],"name":"AppsFunFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldHolder","type":"address"},{"indexed":true,"internalType":"address","name":"newHolder","type":"address"}],"name":"FeeHolderUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"oldThreshold","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"newThreshold","type":"uint256"}],"name":"GraduationThresholdUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldPermit2","type":"address"},{"indexed":true,"internalType":"address","name":"newPermit2","type":"address"}],"name":"Permit2Updated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldAddress","type":"address"},{"indexed":true,"internalType":"address","name":"newAddress","type":"address"}],"name":"PlatformFeeAddressUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldManager","type":"address"},{"indexed":true,"internalType":"address","name":"newManager","type":"address"}],"name":"PositionManagerUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"address","name":"pair","type":"address"},{"indexed":false,"internalType":"uint256","name":"","type":"uint256"}],"name":"TokenFairLaunched","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"positionId","type":"uint256"},{"indexed":false,"internalType":"PoolId","name":"poolId","type":"bytes32"}],"name":"TokenGraduated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"deposited","type":"uint256"},{"indexed":false,"internalType":"address","name":"pair","type":"address"},{"indexed":false,"internalType":"uint256","name":"","type":"uint256"}],"name":"TokenLaunched","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"oldValue","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"newValue","type":"uint256"}],"name":"VirtualBaseReserveUpdated","type":"event"},{"inputs":[],"name":"CREATOR_FEE_BIPS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"FEE_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_TOKEN_DEPOSIT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PLATFORM_FEE_BIPS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"V4_FEE","outputs":[{"internalType":"uint24","name":"","type":"uint24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"V4_TICK_SPACING","outputs":[{"internalType":"int24","name":"","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WETH","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"allPairs","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"allPairsLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"canGraduate","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"uint256","name":"supply","type":"uint256"}],"name":"deployAndLaunch","outputs":[{"internalType":"address","name":"pair","type":"address"},{"internalType":"address","name":"token","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"uint256","name":"supply","type":"uint256"},{"internalType":"uint256","name":"creatorAmount","type":"uint256"}],"name":"deployAndLaunchWithSplit","outputs":[{"internalType":"address","name":"pair","type":"address"},{"internalType":"address","name":"token","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feeHolder","outputs":[{"internalType":"contract IFeeHolder","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeToSetter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address","name":"inputToken","type":"address"},{"internalType":"address","name":"pair","type":"address"}],"name":"getAmountOut","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"getPair","outputs":[{"internalType":"address","name":"pair","type":"address"},{"internalType":"address","name":"creator","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"graduateToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"graduationThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"launchToken","outputs":[{"internalType":"address","name":"pair","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"permit2","outputs":[{"internalType":"contract IAllowanceTransfer","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"platformFeeAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"positionManager","outputs":[{"internalType":"contract IPositionManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address","name":"token","type":"address"}],"name":"quoteSwapExactETHForTokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address","name":"token","type":"address"}],"name":"quoteSwapExactTokensForETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_feeHolder","type":"address"}],"name":"setFeeHolder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_graduationThreshold","type":"uint256"}],"name":"setGraduationThreshold","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"setOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_permit2","type":"address"}],"name":"setPermit2","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_platformFeeAddress","type":"address"}],"name":"setPlatformFeeAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_positionManager","type":"address"}],"name":"setPositionManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_virtualBaseReserve","type":"uint256"}],"name":"setVirtualBaseReserve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactETHForTokens","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"swapExactTokensForETH","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"virtualBaseReserve","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]

60803461013457601f615d2d38819003918201601f19168301916001600160401b038311848410176101385780849260a094604052833981010312610134576100478161014c565b906100546020820161014c565b906100616040820161014c565b906080606082015191015191600160055560018060a01b03169384156100ef575f80546001600160a01b03199081166001600160a01b03938416179091556001929092556004929092556002805482163390811790915560038054831690911790556007805482169390921692909217905560088054909116919091179055604051615bcc90816101618239f35b60405162461bcd60e51b815260206004820152601860248201527f4170707346756e3a20494e56414c49445f5045524d49543200000000000000006044820152606490fd5b5f80fd5b634e487b7160e01b5f52604160045260245ffd5b51906001600160a01b03821682036101345756fe6080604052600436101561001a575b3615610018575f80fd5b005b5f3560e01c8063094b7415146101d25780630bb0d329146102405780630eff45c31461023b578063101ec30a1461023657806310407f2f1461023157806312261ee71461022c57806313af4035146102275780631a788a02146102225780631e3dd18b1461021d5780632ece4999146102185780633494c26214610213578063451776561461020e5780634b05d78c1461020957806352f5b3ef14610204578063574f2ba3146101ff5780635760f2e3146101fa5780635c76be21146101f55780635e1e6325146101f05780636c569f21146101eb57806373d99ad3146101a0578063791b98bc146101e65780637f7e5bba146101e157806384b040c6146101dc5780638b0bc501146101d75780638da5cb5b146101d25780639375da5a146101cd57806397f548f7146101c8578063ad5c4648146101c3578063b1e1e98f146101be578063cc6be5e4146101b9578063d277ee75146101b4578063d73792a9146101af578063e37c6f8c146101aa578063ed14834f146101a55763eeab8ea00361000e575b611183565b61269d565b6123fd565b6123e1565b6123b0565b612388565b612308565b6122e1565b61177b565b611702565b610253565b6116e5565b611274565b6111c6565b61119e565b611166565b611127565b61110c565b611093565b611076565b611020565b611004565b610d2d565b610cd7565b61091f565b6107de565b610778565b610702565b6106da565b610661565b6105e8565b6102ab565b61027b565b5f91031261024f57565b5f80fd5b3461024f575f36600319011261024f576002546040516001600160a01b039091168152602090f35b3461024f575f36600319011261024f576040516001606f1b8152602090f35b6001600160a01b0381160361024f57565b3461024f57604036600319011261024f576004356102c88161029a565b5f54602435916001600160a01b0391821691811690610352836102ed848214156126c5565b6102f8841515612711565b61033a61033461032861031b8660018060a01b03165f52600960205260405f2090565b546001600160a01b031690565b6001600160a01b031690565b15612755565b851515806105da575b61034c90612798565b826130c5565b936001600160a01b0382169081036105ce5760015490845f915b036105c55786915f915b61131e610385602082016108af565b908082526020820190613e0b8239604051606089901b6001600160601b03191660208201908152906103c481603481015b03601f19810183528261086d565b5190209151905ff5976001600160a01b038916956103e38715156127e4565b863b1561024f5760405163eb990c5960e01b81526001600160a01b03918216600482015291166024820152604481019290925260648201525f8160848183885af1801561057f576105b1575b5061043c87303388613104565b60405163095ea7b360e01b81526001600160a01b0387166004820152602481018890526020816044815f8a5af1801561057f57610584575b50823b1561024f57604051630d2a183960e21b815260048101929092526024820152905f908290604490829084905af194851561057f576105187f28f6f5ceea521e91f6f2956665771f6f979641ef3ec6c812f0a4d1d2e73462ea93869361056198610565575b506105136104e761088f565b6001600160a01b0386168152913360208401526001600160a01b03165f90815260096020526040902090565b612845565b6105218261287a565b600a54604080519283526001600160a01b0393909316602083015291810191909152606090a26040516001600160a01b0390911681529081906020820190565b0390f35b806105735f6105799361086d565b80610245565b5f6104db565b612822565b6105a59060203d6020116105aa575b61059d818361086d565b81019061282d565b610474565b503d610593565b806105735f6105bf9361086d565b5f61042f565b5f918791610376565b6001545f91859061036c565b506001606f1b861115610343565b3461024f57602036600319011261024f576004356106058161029a565b61061a60018060a01b036002541633146128e4565b6008546001600160a01b0391821691829082167f458609883bfc2c0eb1300d68839f0a6aa0b7a1997aba004773946caf044a06ff5f80a36001600160a01b03191617600855005b3461024f57602036600319011261024f5760043561067e8161029a565b61069360018060a01b036002541633146128e4565b6007546001600160a01b0391821691829082167fc3a1129c241b1b8ea5a005d72142e13b31209f18f3cdd36e03631e910270e6055f80a36001600160a01b03191617600755005b3461024f575f36600319011261024f576008546040516001600160a01b039091168152602090f35b3461024f57602036600319011261024f5760043561071f8161029a565b6002546001600160a01b038116916107383384146128e4565b6001600160a01b03169182907f8292fce18fa69edf4db7b94ea2e58241df0ae57f97e0a6c9b29067028bf92d765f80a36001600160a01b03191617600255005b3461024f57602036600319011261024f576004356107958161029a565b6001600160a01b039081165f908152600960209081526040918290208054600190910154835191851682529093169083015290f35b634e487b7160e01b5f52603260045260245ffd5b3461024f57602036600319011261024f57600435600a5481101561024f57600a5f527fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a801546040516001600160a01b039091168152602090f35b634e487b7160e01b5f52604160045260245ffd5b6040810190811067ffffffffffffffff82111761086857604052565b610838565b90601f8019910116810190811067ffffffffffffffff82111761086857604052565b6040519061089e60408361086d565b565b6040519061089e60a08361086d565b9061089e604051928361086d565b67ffffffffffffffff811161086857601f01601f191660200190565b81601f8201121561024f578035906108f0826108bd565b926108fe604051948561086d565b8284526020838301011161024f57815f926020809301838601378301015290565b3461024f57606036600319011261024f5760043567ffffffffffffffff811161024f576109509036906004016108d9565b60243567ffffffffffffffff811161024f576109709036906004016108d9565b906044359160405192610a4e918285019385851067ffffffffffffffff8611176108685785946109a4946151298739612cdb565b03905ff0801561057f576001600160a01b03166109c2811515612711565b6040516318160ddd60e01b8152602081600481855afa801561057f57610a44915f91610ca8575b50610a0d61033461032861031b8660018060a01b03165f52600960205260405f2090565b80151580610c9a575b610a1f90612798565b5f546001600160a01b031690610a3582856130c5565b9390926001600160a01b031690565b6001600160a01b038316908103610c8e57600154855f925b03610c8557825f925b61131e610a74602082016108af565b908082526020820190613e0b823960405160608b901b6001600160601b0319166020820190815290610aa981603481016103b6565b5190209151905ff5966001600160a01b03881696610ac88815156127e4565b873b1561024f5760405163eb990c5960e01b81526001600160a01b03918216600482015291166024820152604481019390935260648301525f8260848183895af190811561057f57610b4d92602092610c71575b5060405163095ea7b360e01b81526001600160a01b0388166004820152602481019190915291829081906044820190565b03815f8a5af1801561057f57610c54575b50823b1561024f57604051630d2a183960e21b815260048101929092526024820152905f908290604490829084905af1801561057f57610c40575b50610bd3610ba561088f565b6001600160a01b03831681523360208201526001600160a01b0384165f908152600960205260409020612845565b610bdc8161287a565b600a54604080516001600160a01b0384168152602081019290925283917f67191a2a61d496102827fa6683fb3a6a251cb28e3eb8bf0b7b2f466277358e0a91819081015b0390a2604080516001600160a01b03928316815292909116602083015290f35b806105735f610c4e9361086d565b5f610b99565b610c6c9060203d6020116105aa5761059d818361086d565b610b5e565b806105735f610c7f9361086d565b5f610b1c565b5f928092610a65565b600154855f9192610a5c565b506001606f1b811115610a16565b610cca915060203d602011610cd0575b610cc2818361086d565b810190612d09565b5f6109e9565b503d610cb8565b3461024f57602036600319011261024f57600435610d0060018060a01b036002541633146128e4565b806001547f2ef7bc232054955f8d12845c90c0cdaecac0635f600eb7ec027047b5eee425c95f80a3600155005b608036600319011261024f57602435600435610d488261029a565b604435610d548161029a565b610d756064355b610d69600160055414612925565b5f600555421115612963565b6001600160a01b0383165f908152600960205260409020610d95906129a2565b8051909190610db2906001600160a01b039081165b1615156129ce565b610dc6610dbe34612a2e565b612710900490565b610dd2610dbe34612a2e565b94610de686610de18434612aee565b612aee565b9582610f54575b805f516020615b775f395f51905f5291151580610f37575b610f16575b60208681015160408051968752918601929092526001600160a01b03938416949390911692a35f54610e6690610328906001600160a01b0316845161032890610e5d906001600160a01b0316838a612bb5565b96871015612afb565b91823b1561024f575f8593600460405180968193630d0e30db60e41b83525af1801561057f5761056195610ee894610ec392610f02575b505f54610eb2906001600160a01b0316610328565b83516001600160a01b031690613231565b5f54610ee1906001600160a01b03165b91516001600160a01b031690565b9084613287565b610ef26001600555565b6040519081529081906020820190565b806105735f610f109361086d565b5f610e9d565b600354610f329082906001600160a01b0316613192565b613192565b610e0a565b50600354610f4d906001600160a01b0316610328565b1515610e05565b600754610f6f908490610f2d906001600160a01b0316610328565b600754610f84906001600160a01b0316610328565b60208601516001600160a01b03169190803b1561024f5760405163a71532cd60e01b81526001600160a01b03939093166004840152602483018590525f908390604490829084905af191821561057f575f516020615b775f395f51905f5292610ff0575b509050610ded565b806105735f610ffe9361086d565b5f610fe8565b3461024f575f36600319011261024f576020604051610bb88152f35b3461024f57602036600319011261024f5760043561104960018060a01b036002541633146128e4565b806004547f74fa33832976c63d8bc0ee8ecb7180955e8222b437b61c2d88aa8acdbc0ba1bc5f80a3600455005b3461024f575f36600319011261024f576020600a54604051908152f35b3461024f57602036600319011261024f576004356110b08161029a565b6110c560018060a01b036002541633146128e4565b6006546001600160a01b0391821691829082167f9ee681927833c2398c73d0f5b2a218383929087bada1b839781887af24e6bb025f80a36001600160a01b03191617600655005b3461024f575f36600319011261024f576020604051603c8152f35b3461024f57606036600319011261024f57602061115e60043560243561114c8161029a565b604435916111598361029a565b612bb5565b604051908152f35b3461024f575f36600319011261024f576020600154604051908152f35b3461024f575f36600319011261024f57602060405160328152f35b3461024f575f36600319011261024f576006546040516001600160a01b039091168152602090f35b3461024f57604036600319011261024f57610561610ef26004356024356111ec8161029a565b60018060a01b03165f52600960205261125760405f2091611236604051936112138561084c565b80546001600160a01b039081168087526001909201548116602087015290610daa565b610de1611245610dbe83612a2e565b611251610dbe84612a2e565b92612aee565b5f5490919061126e906001600160a01b0316610ed3565b91612bb5565b3461024f57608036600319011261024f5760043567ffffffffffffffff811161024f576112a59036906004016108d9565b60243567ffffffffffffffff811161024f576112c59036906004016108d9565b90604435906064359260405192610a4e918285019385851067ffffffffffffffff8611176108685785946112fd946151298739612cdb565b03905ff0801561057f576001600160a01b03169061131c821515612711565b6040516318160ddd60e01b8152602081600481865afa90811561057f575f916116c6575b50808215918215611657575b506113ac925061137561033461032861031b8760018060a01b03165f52600960205260405f2090565b80151580611649575b61138790612798565b5f546001600160a01b03169161139d83866130c5565b9490936001600160a01b031690565b6001600160a01b03841690810361163d5760015490865f915b036116345783915f915b61131e6113de602082016108af565b908082526020820190613e0b823960405160608c901b6001600160601b031916602082019081529061141381603481016103b6565b5190209151905ff5976001600160a01b038916976114328915156127e4565b883b1561024f5760405163eb990c5960e01b81526001600160a01b03918216600482015291166024820152604481019290925260648201525f81608481838a5af1801561057f57611620575b5060405163095ea7b360e01b81526001600160a01b0387166004820152602481018590526020816044815f8c5af1801561057f57611603575b50843b1561024f57604051630d2a183960e21b815260048101929092526024820152925f908490604490829084905af190811561057f57859385926115ef575b5061153161150361088f565b6001600160a01b03841681523360208201526001600160a01b0386165f908152600960205260409020612845565b61153a8261287a565b156115a5575050600a54604080516001600160a01b038516815260208101929092527f67191a2a61d496102827fa6683fb3a6a251cb28e3eb8bf0b7b2f466277358e0a919081908101610c20565b604080516001600160a01b03928316815292909116602083015290f35b600a54604080519384526001600160a01b03929092166020840152908201527f28f6f5ceea521e91f6f2956665771f6f979641ef3ec6c812f0a4d1d2e73462ea90606090a2611588565b806105735f6115fd9361086d565b5f6114f7565b61161b9060203d6020116105aa5761059d818361086d565b6114b7565b806105735f61162e9361086d565b5f61147e565b5f9184916113cf565b6001545f9187906113c5565b506001606f1b81111561137e565b9050611664818410612d18565b60405163a9059cbb60e01b815233600482015260248101849052926020846044815f895af191821561057f576113ac946116a3936116a9575b50612aee565b5f61134c565b6116c19060203d6020116105aa5761059d818361086d565b61169d565b6116df915060203d602011610cd057610cc2818361086d565b5f611340565b3461024f575f36600319011261024f576020600454604051908152f35b3461024f57602036600319011261024f5760043561171f8161029a565b61173460018060a01b036002541633146128e4565b6003546001600160a01b0391821691829082167f698bfb5cd028a0af42ac6831cc213cb879e4543e1b6997a0cc64dd5ea41957495f80a36001600160a01b03191617600355005b3461024f57602036600319011261024f576004356117988161029a565b6001600160a01b0381165f9081526009602052604090206117b8906129a2565b80519091906117d1906001600160a01b03908116610daa565b5f546117e5906001600160a01b0316610328565b82516040516370a0823160e01b81526001600160a01b039182166004820152919391906020908290602490829088165afa801561057f57611832915f916122c2575b506004541115612d64565b6001600160a01b0382169283101561225e57805160049060209061186090610328906001600160a01b031681565b604051634b4af0ff60e01b815292839182905afa90811561057f575f9161223f575b50905b805161189b90610328906001600160a01b031681565b803b1561024f575f809160046040518094819363fce4624d60e01b83525af1801561057f5761222b575b506040516370a0823160e01b815230600482015290602082602481885afa91821561057f575f9261220a575b505f5461190890610328906001600160a01b031681565b6040516370a0823160e01b815230600482015293602085602481855afa94851561057f575f956121e9575b50813b1561024f57604051632e1a7d4d60e01b815260048101869052915f908390602490829084905af191821561057f57611974926121d5575b5084612dbe565b916119c96103286119c46119bf6119896108a0565b5f81526001600160a01b038b16602082015296610bb86040890152603c60608901525f60808901526119ba86612a49565b612ad1565b612a62565b613434565b6006549094906119e1906001600160a01b0316610328565b6020604051809263f702040560e01b8252815f81611a038c8c60048401612e27565b03925af1801561057f576121a8575b50600854611a62906020908490611a31906001600160a01b0316610328565b60405163095ea7b360e01b81526001600160a01b039091166004820152602481019190915291829081906044820190565b03815f8c5af1801561057f5761218b575b50600854611a89906001600160a01b0316610328565b600654611a9e906001600160a01b0316610328565b611ab5611aaa42612db0565b65ffffffffffff1690565b823b1561024f576040516387517c4560e01b81526001600160a01b038a811660048301529283166024820152918516604483015265ffffffffffff166064820152905f908290608490829084905af1801561057f57612177575b506001600160a01b038516611b3b611b30611b2a8385612aaa565b60601c90565b916119ba8560601b90565b8082101561216f5750915b604051600160f91b6020820152600d60f81b602182015260028152906001600160801b0390611bbb90611b7a60228561086d565b6103b6611b85612e47565b600754909790611b9d906001600160a01b0316610328565b9060405195869416906001600160801b038916908c60208701612e81565b611bc484612ee5565b52611bce83612ee5565b50604080515f60208201526001600160a01b038a1691810191909152611bf781606081016103b6565b611c0084612ef2565b52611c0a83612ef2565b50600654611c4590611c24906001600160a01b0316610328565b91611c3760405195869260208401612f02565b03601f19810185528461086d565b611c4e42612db0565b90803b1561024f5760405163dd46508f60e01b8152935f93859384928391611c799160048401612f74565b03925af1801561057f5761215b575b50600654600490602090611ca4906001600160a01b0316610328565b604051631d5e528f60e21b815292839182905afa801561057f57611ccf915f916120c2575b50612ae0565b600754909390602090611cea906001600160a01b0316610328565b920180519092906001600160a01b031690803b1561024f57604051636eb2f49d60e11b81526001600160a01b0392831660048201529187166024830152604482018690525f908290606490829084905af1801561057f57612147575b506040516370a0823160e01b8152306004820152906020826024818a5afa91821561057f575f92612126575b5081611db4575b60a0842060408051878152602081019290925288917ff315359bf184d3fe9fa6521f1b73b8aab071cf4d9e05dc239ca51147fee209289190a2005b611dc0611dc5916135b1565b612f8b565b600854611de3906020908490611a31906001600160a01b0316610328565b03815f8c5af1801561057f57612109575b50600854611e0a906001600160a01b0316610328565b600654611e1f906001600160a01b0316610328565b611e2b611aaa42612db0565b823b1561024f576040516387517c4560e01b81526001600160a01b038a811660048301529283166024820152918516604483015265ffffffffffff166064820152905f908290608490829084905af1801561057f576120f5575b506001600160801b03611f0b611eac84611e9d6136d9565b611ea6866139ee565b90613d0d565b604051600160f91b6020820152600d60f81b60218201526002815294906103b690611ed860228861086d565b611ee0612e47565b600754909690611ef8906001600160a01b0316610328565b9160405196879516918b60208701612fa7565b611f1482612ee5565b52611f1e81612ee5565b50604080515f60208201526001600160a01b03891691810191909152611f4781606081016103b6565b611f5082612ef2565b52611f5a81612ef2565b50600654611f8790611f74906001600160a01b0316610328565b926103b660405193849260208401612f02565b611f9042612db0565b823b1561024f57611fba925f928360405180968195829463dd46508f60e01b845260048401612f74565b03925af1801561057f576120e1575b50600654600490602090611fe5906001600160a01b0316610328565b604051631d5e528f60e21b815292839182905afa801561057f5761200f915f916120c25750612ae0565b60075461203690612028906001600160a01b0316610328565b92516001600160a01b031690565b91803b1561024f57604051636eb2f49d60e11b81526001600160a01b03938416600482015295909216602486015260448501525f908490606490829084905af190811561057f577ff315359bf184d3fe9fa6521f1b73b8aab071cf4d9e05dc239ca51147fee209289360a0926120ae575b8192611d79565b806105735f6120bc9361086d565b5f6120a7565b6120db915060203d602011610cd057610cc2818361086d565b5f611cc9565b806105735f6120ef9361086d565b5f611fc9565b806105735f6121039361086d565b5f611e85565b6121219060203d6020116105aa5761059d818361086d565b611df4565b61214091925060203d602011610cd057610cc2818361086d565b905f611d72565b806105735f6121559361086d565b5f611d46565b806105735f6121699361086d565b5f611c88565b905091611b46565b806105735f6121859361086d565b5f611b0f565b6121a39060203d6020116105aa5761059d818361086d565b611a73565b6121c99060203d6020116121ce575b6121c1818361086d565b810190612dcb565b611a12565b503d6121b7565b806105735f6121e39361086d565b5f61196d565b61220391955060203d602011610cd057610cc2818361086d565b935f611933565b61222491925060203d602011610cd057610cc2818361086d565b905f6118f1565b806105735f6122399361086d565b5f6118c5565b612258915060203d602011610cd057610cc2818361086d565b5f611882565b805160049060209061227a90610328906001600160a01b031681565b60405163c62b92ef60e01b815292839182905afa90811561057f575f916122a3575b5090611885565b6122bc915060203d602011610cd057610cc2818361086d565b5f61229c565b6122db915060203d602011610cd057610cc2818361086d565b5f611827565b3461024f575f36600319011261024f575f546040516001600160a01b039091168152602090f35b3461024f57604036600319011261024f57610561610ef26112366004356024356123318161029a565b60018060a01b0381165f52600960205261126e60405f2061237b604051916123588361084c565b80546001600160a01b039081168085526001909201548116602085015290610daa565b516001600160a01b031690565b3461024f575f36600319011261024f576007546040516001600160a01b039091168152602090f35b3461024f57602036600319011261024f5760206123d76004356123d28161029a565b61300a565b6040519015158152f35b3461024f575f36600319011261024f5760206040516127108152f35b3461024f5760a036600319011261024f576024356044356004356124208261029a565b6064359261242d8461029a565b612438608435610d5b565b6001600160a01b0383165f908152600960205260409020612458906129a2565b8051909290612471906001600160a01b03908116610daa565b82516124bd9061248b906001600160a01b03168684612bb5565b845190956001600160a01b038082169491926124aa9291163386613104565b84516001600160a01b0316309187613287565b5f546124d390610328906001600160a01b031681565b803b1561024f57604051632e1a7d4d60e01b815260048101869052905f908290602490829084905af1801561057f57612689575b50612514610dbe85612a2e565b612520610dbe86612a2e565b61252e81610de18489612aee565b94826125c3575b92610f2d925f516020615b775f395f51905f52836105619a96610ee89998951515806125a6575b61258a575b60209081015160408051958652918501929092526001600160a01b0390911692a3831015612afb565b6003546125a19083906001600160a01b0316613192565b612561565b506003546125bc906001600160a01b0316610328565b151561255c565b94939096926125e083610f2d61032860075460018060a01b031690565b6007546125f5906001600160a01b0316610328565b60208701516001600160a01b03169390803b1561024f5760405163a71532cd60e01b81526001600160a01b03959095166004860152602485018290525f908590604490829084905af1801561057f5761056199610ee898610f2d965f516020615b775f395f51905f5293612675575b5093969a5093969750509250612535565b806105735f6126839361086d565b5f612664565b806105735f6126979361086d565b5f612507565b3461024f575f36600319011261024f576003546040516001600160a01b039091168152602090f35b156126cc57565b60405162461bcd60e51b815260206004820152601c60248201527f4170707346756e3a204944454e544943414c5f414444524553534553000000006044820152606490fd5b1561271857565b60405162461bcd60e51b81526020600482015260156024820152744170707346756e3a205a45524f5f4144445245535360581b6044820152606490fd5b1561275c57565b60405162461bcd60e51b81526020600482015260146024820152734170707346756e3a20504149525f45584953545360601b6044820152606490fd5b1561279f57565b60405162461bcd60e51b815260206004820152601760248201527f4170707346756e3a20494e56414c49445f414d4f554e540000000000000000006044820152606490fd5b156127eb57565b60405162461bcd60e51b815260206004820152600f60248201526e105c1c1cd19d5b8e88119052531151608a1b6044820152606490fd5b6040513d5f823e3d90fd5b9081602091031261024f5751801515810361024f5790565b815181546001600160a01b039182166001600160a01b0319918216178355602090930151600190920180549093169116179055565b600a54600160401b8110156108685760018101600a55600a548110156128df57600a5f527fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a80180546001600160a01b0319166001600160a01b03909216919091179055565b6107ca565b156128eb57565b60405162461bcd60e51b815260206004820152601260248201527120b83839a33ab71d102327a92124a22222a760711b6044820152606490fd5b1561292c57565b60405162461bcd60e51b815260206004820152600f60248201526e105c1c1cd19d5b8e881313d0d2d151608a1b6044820152606490fd5b1561296a57565b60405162461bcd60e51b815260206004820152601060248201526f105c1c1cd19d5b8e881156141254915160821b6044820152606490fd5b906040516129af8161084c565b82546001600160a01b0390811682526001909301549092166020830152565b156129d557565b60405162461bcd60e51b815260206004820152601760248201527f4170707346756e3a20504149525f4e4f545f464f554e440000000000000000006044820152606490fd5b634e487b7160e01b5f52601160045260245ffd5b90603282029180830460321490151715612a4457565b612a1a565b908160601b91808304600160601b1490151715612a4457565b606081901b91906001600160a01b03811603612a4457565b906103e58202918083046103e51490151715612a4457565b906103e88202918083046103e81490151715612a4457565b81810292918115918404141715612a4457565b634e487b7160e01b5f52601260045260245ffd5b8115612adb570490565b612abd565b5f19810191908211612a4457565b91908203918211612a4457565b15612b0257565b60405162461bcd60e51b815260206004820152602360248201527f4170707346756e3a20494e53554646494349454e545f4f55545055545f414d4f60448201526215539560ea1b6064820152608490fd5b9081602091031261024f5751612b688161029a565b90565b51906001600160701b038216820361024f57565b9081606091031261024f57612b9381612b6b565b916040612ba260208401612b6b565b92015163ffffffff8116810361024f5790565b604051630dfe168160e01b8152926001600160a01b0316602084600481845afa93841561057f575f94612c80575b50606060049160405192838092630240bc6b60e21b82525afa92831561057f57612b68945f925f95612c48575b506001600160a01b03918216911603612c38576001600160701b038091935b16921690613354565b6001600160701b03908190612c2f565b909450612c6e91925060603d606011612c79575b612c66818361086d565b810190612b7f565b50919091935f612c10565b503d612c5c565b6004919450612ca860609160203d602011612cb0575b612ca0818361086d565b810190612b53565b949150612be3565b503d612c96565b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b939291612d0490612cf6604093606088526060880190612cb7565b908682036020880152612cb7565b930152565b9081602091031261024f575190565b15612d1f57565b60405162461bcd60e51b815260206004820152601f60248201527f4170707346756e3a20494e56414c49445f43524541544f525f414d4f554e54006044820152606490fd5b15612d6b57565b60405162461bcd60e51b815260206004820152601a60248201527f4170707346756e3a205448524553484f4c445f4e4f545f4d45540000000000006044820152606490fd5b90603c8201809211612a4457565b91908201809211612a4457565b9081602091031261024f57518060020b810361024f5790565b80516001600160a01b03908116835260208083015182169084015260408083015162ffffff169084015260608083015160020b9084015260809182015116910152565b90929160a090612e3b8360c0810196612de4565b600180831b0316910152565b60405160609190612e58838261086d565b6002815291601f1901825f5b828110612e7057505050565b806060602080938501015201612e64565b93906101a095936001600160801b0393612e9c878694612de4565b620d89b31960a0880152620d89b460c088015260e087015216610100850152166101208301526001600160a01b031661014082015261018061016082018190525f908201520190565b8051156128df5760200190565b8051600110156128df5760400190565b90612f1590604083526040830190612cb7565b906020818303910152815180825260208201916020808360051b8301019401925f915b838310612f4757505050505090565b9091929394602080612f65600193601f198682030187528951612cb7565b97019301930191939290612f38565b929190612d04602091604086526040860190612cb7565b60020b603b190190627fffff198212627fffff831317612a4457565b93906101a095936001600160801b0393612fc2878694612de4565b620d89b31960a088015260020b60c08701521660e08501525f6101008501521661012083015260018060a01b03166101408201526101806101608201525f6101808201520190565b6001600160a01b03165f90815260096020526040902061302d9061237b906129a2565b6001600160a01b038116156130c0575f546130869160209161305990610328906001600160a01b031681565b6040516370a0823160e01b81526001600160a01b0390921660048301529092839190829081906024820190565b03915afa90811561057f575f916130a1575b50600454111590565b6130ba915060203d602011610cd057610cc2818361086d565b5f613098565b505f90565b9091906001600160a01b038084169082166130e2818314156126c5565b10156130ff57915b9061089e6001600160a01b0384161515612711565b6130ea565b6040516323b872dd60e01b5f9081526001600160a01b039384166004529290931660245260449390935260209060648180865af160015f5114811615613173575b6040919091525f606052155b6131585750565b635274afe760e01b5f526001600160a01b031660045260245ffd5b6001811516613189573d15833b15151616613145565b503d5f823e3d90fd5b5f8091602093604051906131a6868361086d565b83825285820191601f19870136843751925af13d1561322c573d6131c9816108bd565b906131d7604051928361086d565b81525f833d92013e5b156131e85750565b6064906040519062461bcd60e51b82526004820152601c60248201527f4170707346756e3a204554485f5452414e534645525f4641494c4544000000006044820152fd5b6131e0565b916040519163a9059cbb60e01b5f5260018060a01b031660045260245260205f60448180865af160015f5114811615613271575b60409190915215613151565b6001811516613189573d15833b15151616613265565b604051630dfe168160e01b81526001600160a01b03909316939092909190602081600481885afa90811561057f575f91613335575b506001600160a01b0391821691160361332e575f91925b803b1561024f576040516336cd320560e11b8152600481019390935260248301939093526001600160a01b03166044820152905f908290606490829084905af1801561057f576133205750565b806105735f61089e9361086d565b5f926132d3565b61334e915060203d602011612cb057612ca0818361086d565b5f6132bc565b80156133e457811515806133db575b1561339657612b689261338b61338561337e61339094612a7a565b9283612aaa565b93612a92565b612dbe565b90612ad1565b60405162461bcd60e51b815260206004820152601f60248201527f4170707346756e3a20494e53554646494349454e545f4c4951554944495459006044820152606490fd5b50821515613363565b60405162461bcd60e51b815260206004820152602260248201527f4170707346756e3a20494e53554646494349454e545f494e5055545f414d4f55604482015261139560f21b6064820152608490fd5b905f600383111561347d5750818060011c60018101809111612a4457905b83821061345d575050565b909250828015612adb57808204908101809111612a445760011c90613452565b9161348457565b60019150565b9060408201915f604084129112908015821691151617612a4457565b9060208201915f602084129112908015821691151617612a4457565b9060108201915f601084129112908015821691151617612a4457565b9060088201915f600884129112908015821691151617612a4457565b9060048201915f600484129112908015821691151617612a4457565b9060028201915f600284129112908015821691151617612a4457565b9060018201915f600184129112908015821691151617612a4457565b90605f198201918213600116612a4457565b9061056a82029180830561056a1490151715612a4457565b60020b9060020b908115612adb57627fffff1981145f19831416612a44570590565b9060020b9060020b02908160020b918203612a4457565b603c6136498161364461363e613637613632612b689760018060a01b03165f90600160801b8110156136ce575b80600160401b60029210156136bb575b6401000000008110156136a8575b62010000811015613695575b610100811015613682575b601081101561366f575b600481101561365c575b101561364e5761354e565b613560565b600a900590565b60020b90565b613578565b61359a565b61365790613532565b61354e565b6136699060021c92613516565b91613627565b61367c9060041c926134fa565b9161361d565b61368f9060081c926134de565b91613613565b6136a29060101c926134c2565b91613608565b6136b59060201c926134a6565b916135fc565b6136c89060401c9261348a565b916135ee565b60809150811c6135de565b620d89b31960ff1d620d89b319810118620d89e881116139e45763ffffffff90600160801b7001fffcb933bd6fad37aa2d162d1a59400160018316021890600281166139c8575b600481166139ac575b60088116613990575b60108116613974575b60208116613958575b6040811661393c575b60808116613920575b6101008116613904575b61020081166138e8575b61040081166138cc575b61080081166138b0575b6110008116613894575b6120008116613878575b614000811661385c575b6180008116613840575b620100008116613824575b620200008116613809575b6204000081166137ee575b62080000166137d8575b0160201c90565b6b048a170391f7dc42444e8fa20260801c6137d1565b6d2216e584f5fa1ea926041bedfe9890910260801c906137c7565b906e5d6af8dedb81196699c329225ee6040260801c906137bc565b906f09aa508b5b7a84e1c677de54f3e99bc90260801c906137b1565b906f31be135f97d08fd981231505542fcfa60260801c906137a6565b906f70d869a156d2a1b890bb3df62baf32f70260801c9061379c565b906fa9f746462d870fdf8a65dc1f90e061e50260801c90613792565b906fd097f3bdfd2022b8845ad8f792aa58250260801c90613788565b906fe7159475a2c29b7443b29c7fa6e889d90260801c9061377e565b906ff3392b0822b70005940c7a398e4b70f30260801c90613774565b906ff987a7253ac413176f2b074cf7815e540260801c9061376a565b906ffcbe86c7900a88aedcffc83b479aa3a40260801c90613760565b906ffe5dee046a99a2a811c461f1969c30530260801c90613756565b906fff2ea16466c96a3843ec78b326b528610260801c9061374d565b906fff973b41fa98c081472e6896dfb254c00260801c90613744565b906fffcb9843d60f6159c9db58835c9266440260801c9061373b565b906fffe5caca7e10e4e61c3624eaa0941cd00260801c90613732565b906ffff2e50f5f656932ef12357cf3c7fdcc0260801c90613729565b906ffff97272373d413259a46990580e213a0260801c90613720565b620d89b319613d61565b60020b908160ff1d82810118620d89e88111613d075763ffffffff9192600182167001fffcb933bd6fad37aa2d162d1a59400102600160801b189160028116613ceb575b60048116613ccf575b60088116613cb3575b60108116613c97575b60208116613c7b575b60408116613c5f575b60808116613c43575b6101008116613c27575b6102008116613c0b575b6104008116613bef575b6108008116613bd3575b6110008116613bb7575b6120008116613b9b575b6140008116613b7f575b6180008116613b63575b620100008116613b47575b620200008116613b2c575b620400008116613b11575b6208000016613af8575b5f12613af0570160201c90565b5f19046137d1565b6b048a170391f7dc42444e8fa290910260801c90613ae3565b6d2216e584f5fa1ea926041bedfe9890920260801c91613ad9565b916e5d6af8dedb81196699c329225ee6040260801c91613ace565b916f09aa508b5b7a84e1c677de54f3e99bc90260801c91613ac3565b916f31be135f97d08fd981231505542fcfa60260801c91613ab8565b916f70d869a156d2a1b890bb3df62baf32f70260801c91613aae565b916fa9f746462d870fdf8a65dc1f90e061e50260801c91613aa4565b916fd097f3bdfd2022b8845ad8f792aa58250260801c91613a9a565b916fe7159475a2c29b7443b29c7fa6e889d90260801c91613a90565b916ff3392b0822b70005940c7a398e4b70f30260801c91613a86565b916ff987a7253ac413176f2b074cf7815e540260801c91613a7c565b916ffcbe86c7900a88aedcffc83b479aa3a40260801c91613a72565b916ffe5dee046a99a2a811c461f1969c30530260801c91613a68565b916fff2ea16466c96a3843ec78b326b528610260801c91613a5f565b916fff973b41fa98c081472e6896dfb254c00260801c91613a56565b916fffcb9843d60f6159c9db58835c9266440260801c91613a4d565b916fffe5caca7e10e4e61c3624eaa0941cd00260801c91613a44565b916ffff2e50f5f656932ef12357cf3c7fdcc0260801c91613a3b565b916ffff97272373d413259a46990580e213a0260801c91613a32565b82613d61565b613d389291906001600160a01b0380831690821611613d5b575b90036001600160a01b031690613d7d565b6001600160801b038116809103613d4c5790565b6393dafdf160e01b5f5260045ffd5b90613d27565b6345c3193d60e11b5f5260020b60045260245ffd5b1561024f57565b90606082901b905f19600160601b8409928280851094039380850394613da4868511613d76565b14613e03578190600160601b900981805f03168092046002816003021880820260020302808202600203028082026002030280820260020302808202600203028091026002030293600183805f03040190848311900302920304170290565b509150049056fe60808060405234602b5760016008555f80546001600160a01b031916331790556112ee90816100308239f35b5f80fdfe60806040526004361015610011575f80fd5b5f3560e01c80630902f1ac14610e835780630dfe168114610e5b57806334a860e414610cc85780634b4af0ff14610cab5780635909c0d514610c8e5780635a3d549314610c715780636d9a640a14610751578063ba9a7a5614610735578063bc25cf77146105f3578063c45a0155146105cc578063c62b92ef146105af578063d21220a714610587578063d3e3747214610568578063eb990c591461046e578063fce4624d146101fd5763fff6cae9146100c9575f80fd5b346101b3575f3660031901126101b3576100e7600160085414610f22565b5f6008556001546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa80156101bf575f906101ca575b6002546040516370a0823160e01b81523060048201529250602090839060249082906001600160a01b03165afa9081156101bf575f91610185575b61017e9250600354916001600160701b03808460701c16931691611089565b6001600855005b90506020823d6020116101b7575b816101a060209383610fa1565b810103126101b35761017e91519061015f565b5f80fd5b3d9150610193565b6040513d5f823e3d90fd5b506020813d6020116101f5575b816101e460209383610fa1565b810103126101b35760249051610124565b3d91506101d7565b346101b3575f3660031901126101b35761021b600160085414610f22565b5f60085561023360018060a01b035f54163314610f60565b6001546040516370a0823160e01b8152306004820152906001600160a01b0316602082602481845afa9182156101bf575f9261043a575b506002546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa9081156101bf5783905f92610404575b506102b4919233906111f8565b6002546102cd90829033906001600160a01b03166111f8565b6001546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa80156101bf575f906103d1575b6002546040516370a0823160e01b81523060048201529250602090839060249082906001600160a01b03165afa9182156101bf575f92610397575b7ff3f4772b0ce29670f0f94b6bb2b4afed357a2ee57d34e31562426895e978f71e604086866103858787600354916001600160701b03808460701c16931691611089565b82519182526020820152a16001600855005b939150916020843d6020116103c9575b816103b460209383610fa1565b810103126101b3579251909291610385610341565b3d91506103a7565b506020813d6020116103fc575b816103eb60209383610fa1565b810103126101b35760249051610306565b3d91506103de565b9150506020813d602011610432575b8161042060209383610fa1565b810103126101b35751826102b46102a7565b3d9150610413565b9091506020813d602011610466575b8161045660209383610fa1565b810103126101b35751908261026a565b3d9150610449565b346101b35760803660031901126101b357610487610ec3565b6024356001600160a01b038116908190036101b35760443590606435926104b860018060a01b035f54163314610f60565b60018060a01b03166bffffffffffffffffffffffff60a01b60015416176001556bffffffffffffffffffffffff60a01b6002541617600255600160581b8111158061055a575b1561050b57600655600755005b60405162461bcd60e51b815260206004820152602160248201527f4170707346756e3a205649525455414c5f524553455256455f544f4f5f4849476044820152600960fb1b6064820152608490fd5b50600160581b8211156104fe565b346101b3575f3660031901126101b357604051600160581b8152602090f35b346101b3575f3660031901126101b3576002546040516001600160a01b039091168152602090f35b346101b3575f3660031901126101b3576020600654604051908152f35b346101b3575f3660031901126101b3575f546040516001600160a01b039091168152602090f35b346101b35760203660031901126101b35761060c610ec3565b61061a600160085414610f22565b5f6008556001546002546040516370a0823160e01b81523060048201526001600160a01b0391821692909116602082602481845afa9182156101bf5784905f936106fd575b5061067961067f936001600160701b036003541690610fd7565b916111f8565b6040516370a0823160e01b815230600482015291602083602481855afa9283156101bf575f936106c7575b5061067961017e936001600160701b0360035460701c1690610fd7565b92506020833d6020116106f5575b816106e260209383610fa1565b810103126101b3579151916106796106aa565b3d91506106d5565b9250506020823d60201161072d575b8161071960209383610fa1565b810103126101b3579051908361067961065f565b3d915061070c565b346101b3575f3660031901126101b35760206040516103e88152f35b346101b35760603660031901126101b3576044356001600160a01b038116906024356004358383036101b35761078b600160085414610f22565b5f6008556107a360018060a01b035f54163314610f60565b8015809381158092610c68575b15610c17576003546001600160701b038082169160701c1695818510908115610c0f575b5015610bc0578585108015610bb8575b15610b69576107f1610ee6565b506001546002546001600160a01b039081169692949291168a81141580610b5f575b15610b2457602495602092610b14575b8980610b03575b50506040516370a0823160e01b815230600482015295869182905afa9384156101bf575f94610acc575b506020602495604051968780926370a0823160e01b82523060048301525afa9485156101bf57879187915f97610a93575b506108908282610fd7565b861115610a8a576108aa916108a491610fd7565b85610fd7565b975b6108b68282610fd7565b861115610a81576108ca916108a491610fd7565b935b8715801581610a78575b15610a28576108e760065486610ed9565b6108f360075484610ed9565b916103e88202918083046103e81490151715610a145760038b02908b82046003141715610a145761092391610fd7565b6103e88202918083046103e81490151715610a1457600387029187830460031488151715610a145761095e9261095891610fd7565b90610fe4565b61097a6001600160701b0385166001600160701b038516610fe4565b90620f4240820291808304620f42401490151715610a1457106109e2576109a093611089565b6040519384526020840152604083015260608201527fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d82260803392a36001600855005b60405162461bcd60e51b815260206004820152600a6024820152694170707346756e3a204b60b01b6044820152606490fd5b634e487b7160e01b5f52601160045260245ffd5b60405162461bcd60e51b815260206004820152602260248201527f4170707346756e3a20494e53554646494349454e545f494e5055545f414d4f55604482015261139560f21b6064820152608490fd5b508515156108d6565b50505f936108cc565b50505f976108ac565b92509550506020813d602011610ac4575b81610ab160209383610fa1565b810103126101b35785879151958b610885565b3d9150610aa4565b9493506020853d602011610afb575b81610ae860209383610fa1565b810103126101b357935192936020610854565b3d9150610adb565b610b0d91896111f8565b8b8961082a565b610b1f8982846111f8565b610823565b60405162461bcd60e51b81526020600482015260136024820152724170707346756e3a20494e56414c49445f544f60681b6044820152606490fd5b50868b1415610813565b60405162461bcd60e51b815260206004820152602160248201527f4170707346756e3a20494e53554646494349454e545f4c4951554944495459206044820152603160f81b6064820152608490fd5b5084156107e4565b60405162461bcd60e51b815260206004820152602160248201527f4170707346756e3a20494e53554646494349454e545f4c4951554944495459206044820152600360fc1b6064820152608490fd5b9050886107d4565b60405162461bcd60e51b815260206004820152602360248201527f4170707346756e3a20494e53554646494349454e545f4f55545055545f414d4f60448201526215539560ea1b6064820152608490fd5b508315156107b0565b346101b3575f3660031901126101b3576020600554604051908152f35b346101b3575f3660031901126101b3576020600454604051908152f35b346101b3575f3660031901126101b3576020600754604051908152f35b346101b35760403660031901126101b357600435602435610ced600160085414610f22565b5f600855610d0560018060a01b035f54163314610f60565b600154610d20908390309033906001600160a01b0316610ff7565b610d3681303360018060a01b0360025416610ff7565b6001546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa80156101bf575f90610e28575b6002546040516370a0823160e01b81523060048201529250602090839060249082906001600160a01b03165afa9182156101bf575f92610dee575b7f9c86429231ed0411e3112a1dd5c6578826c2d48089d5ec491e874ce0029c0bbe604086866103858787600354916001600160701b03808460701c16931691611089565b939150916020843d602011610e20575b81610e0b60209383610fa1565b810103126101b3579251909291610385610daa565b3d9150610dfe565b506020813d602011610e53575b81610e4260209383610fa1565b810103126101b35760249051610d6f565b3d9150610e35565b346101b3575f3660031901126101b3576001546040516001600160a01b039091168152602090f35b346101b3575f3660031901126101b35760606001600160701b0363ffffffff610eaa610ee6565b9193908160405195168552166020840152166040820152f35b600435906001600160a01b03821682036101b357565b91908201809211610a1457565b6003546001600160701b03610eff600654828416610ed9565b16916001600160701b03610f1a600754828560701c16610ed9565b169160e01c90565b15610f2957565b60405162461bcd60e51b815260206004820152600f60248201526e105c1c1cd19d5b8e881313d0d2d151608a1b6044820152606490fd5b15610f6757565b60405162461bcd60e51b815260206004820152601260248201527120b83839a33ab71d102327a92124a22222a760711b6044820152606490fd5b90601f8019910116810190811067ffffffffffffffff821117610fc357604052565b634e487b7160e01b5f52604160045260245ffd5b91908203918211610a1457565b81810292918115918404141715610a1457565b6040516323b872dd60e01b5f9081526001600160a01b039384166004529290931660245260449390935260209060648180865af19060015f5114821615611068575b6040525f606052156110485750565b635274afe760e01b5f9081526001600160a01b0391909116600452602490fd5b90600181151661108057823b15153d15161690611039565b503d5f823e3d90fd5b926001600160701b03841115806111e7575b156111ae5760035460e01c63ffffffff42160363ffffffff8111610a14577f1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1946040946001600160701b039363ffffffff859416801515806111a3575b80611198575b611137575b50505016918263ffffffff60e01b4260e01b16918360701b9060701b16171780600355835192835260701c166020820152a1565b61118d926111859261116290611170611168856001600160e01b03858761115d87611250565b611286565b16610fe4565b600454610ed9565b6004556001600160e01b039261115d90611250565b600554610ed9565b6005555f8080611103565b5084821615156110fe565b5084831615156110f8565b60405162461bcd60e51b81526020600482015260116024820152704170707346756e3a204f564552464c4f5760781b6044820152606490fd5b506001600160701b0382111561109b565b916040519163a9059cbb60e01b5f5260018060a01b031660045260245260205f60448180865af19060015f5114821615611238575b604052156110485750565b90600181151661108057823b15153d1516169061122d565b6dffffffffffffffffffffffffffff60701b607082901b16906001600160701b0316808204600160701b1490151715610a145790565b906001600160701b03169081156112a4576001600160e01b03160490565b634e487b7160e01b5f52601260045260245ffdfea26469706673582212207a5d8a286c5b5c08be25c332be776afe91d6061c271cb652a3ff1d95abc19b1864736f6c634300082100336080604052346103cc57610a4e80380380610019816103d0565b9283398101906060818303126103cc5780516001600160401b0381116103cc57826100459183016103f5565b60208201519092906001600160401b0381116103cc576040916100699184016103f5565b91015182516001600160401b0381116102d257600354600181811c911680156103c2575b60208210146102b457601f8111610354575b506020601f82116001146102f157819293945f926102e6575b50508160011b915f199060031b1c1916176003555b81516001600160401b0381116102d257600454600181811c911680156102c8575b60208210146102b457601f8111610246575b50602092601f82116001146101e557928192935f926101da575b50508160011b915f199060031b1c1916176004555b670de0b6b3a7640000810290808204670de0b6b3a764000014901517156101b35733156101c7576002548181018091116101b357600255335f525f60205260405f208181540190556040519081525f7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60203393a360405161060790816104478239f35b634e487b7160e01b5f52601160045260245ffd5b63ec442f0560e01b5f525f60045260245ffd5b015190505f8061011a565b601f1982169360045f52805f20915f5b86811061022e5750836001959610610216575b505050811b0160045561012f565b01515f1960f88460031b161c191690555f8080610208565b919260206001819286850151815501940192016101f5565b818111156101005760045f52601f820160051c7f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b602084106102ac575b81601f9101920160051c03905f5b82811061029f575050610100565b5f82820155600101610291565b5f9150610283565b634e487b7160e01b5f52602260045260245ffd5b90607f16906100ee565b634e487b7160e01b5f52604160045260245ffd5b015190505f806100b8565b601f1982169060035f52805f20915f5b81811061033c57509583600195969710610324575b505050811b016003556100cd565b01515f1960f88460031b161c191690555f8080610316565b9192602060018192868b015181550194019201610301565b8181111561009f5760035f52601f820160051c7fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b602084106103ba575b81601f9101920160051c03905f5b8281106103ad57505061009f565b5f8282015560010161039f565b5f9150610391565b90607f169061008d565b5f80fd5b6040519190601f01601f191682016001600160401b038111838210176102d257604052565b81601f820112156103cc578051906001600160401b0382116102d257610424601f8301601f19166020016103d0565b92828452602083830101116103cc57815f9260208093018386015e830101529056fe6080806040526004361015610012575f80fd5b5f3560e01c90816306fdde03146103ef57508063095ea7b31461036d57806318160ddd1461035057806323b872dd14610271578063313ce5671461025657806370a082311461021f57806395d89b4114610104578063a9059cbb146100d35763dd62ed3e1461007f575f80fd5b346100cf5760403660031901126100cf576100986104e8565b6100a06104fe565b6001600160a01b039182165f908152600160209081526040808320949093168252928352819020549051908152f35b5f80fd5b346100cf5760403660031901126100cf576100f96100ef6104e8565b6024359033610514565b602060405160018152f35b346100cf575f3660031901126100cf576040515f6004548060011c90600181168015610215575b602083108114610201578285529081156101e55750600114610190575b50819003601f01601f191681019067ffffffffffffffff82118183101761017c57610178829182604052826104be565b0390f35b634e487b7160e01b5f52604160045260245ffd5b905060045f527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b5f905b8282106101cf57506020915082010182610148565b60018160209254838588010152019101906101ba565b90506020925060ff191682840152151560051b82010182610148565b634e487b7160e01b5f52602260045260245ffd5b91607f169161012b565b346100cf5760203660031901126100cf576001600160a01b036102406104e8565b165f525f602052602060405f2054604051908152f35b346100cf575f3660031901126100cf57602060405160128152f35b346100cf5760603660031901126100cf5761028a6104e8565b6102926104fe565b6001600160a01b0382165f818152600160209081526040808320338452909152902054909260443592915f1981106102d0575b506100f99350610514565b83811061033557841561032257331561030f576100f9945f52600160205260405f2060018060a01b0333165f526020528360405f2091039055846102c5565b634a1406b160e11b5f525f60045260245ffd5b63e602df0560e01b5f525f60045260245ffd5b8390637dc7a0d960e11b5f523360045260245260445260645ffd5b346100cf575f3660031901126100cf576020600254604051908152f35b346100cf5760403660031901126100cf576103866104e8565b602435903315610322576001600160a01b031690811561030f57335f52600160205260405f20825f526020528060405f20556040519081527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560203392a3602060405160018152f35b346100cf575f3660031901126100cf575f6003548060011c906001811680156104b4575b602083108114610201578285529081156101e5575060011461045f5750819003601f01601f191681019067ffffffffffffffff82118183101761017c57610178829182604052826104be565b905060035f527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b5f905b82821061049e57506020915082010182610148565b6001816020925483858801015201910190610489565b91607f1691610413565b602060409281835280519182918282860152018484015e5f828201840152601f01601f1916010190565b600435906001600160a01b03821682036100cf57565b602435906001600160a01b03821682036100cf57565b6001600160a01b03169081156105be576001600160a01b03169182156105ab57815f525f60205260405f205481811061059257817fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92602092855f525f84520360405f2055845f525f825260405f20818154019055604051908152a3565b8263391434e360e21b5f5260045260245260445260645ffd5b63ec442f0560e01b5f525f60045260245ffd5b634b637e8f60e11b5f525f60045260245ffdfea26469706673582212201a6a3a3237e854b17ceca01ed6af0bdbe39376282039344b36a11c73a3183a0164736f6c634300082100333156e57706371fe93e9988fd472f36cdf2f3e93a7a9b1a23d57c676731e2057fa26469706673582212209386ba9ed17eb663aec0afdbc7595febc3313205cd237128befc11fe0ecb3c3f64736f6c63430008210033000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba30000000000000000000000000000000000000000000000004563918244f400000000000000000000000000000000000000000000000000008ac7230489e80000

Deployed Bytecode

0x6080604052600436101561001a575b3615610018575f80fd5b005b5f3560e01c8063094b7415146101d25780630bb0d329146102405780630eff45c31461023b578063101ec30a1461023657806310407f2f1461023157806312261ee71461022c57806313af4035146102275780631a788a02146102225780631e3dd18b1461021d5780632ece4999146102185780633494c26214610213578063451776561461020e5780634b05d78c1461020957806352f5b3ef14610204578063574f2ba3146101ff5780635760f2e3146101fa5780635c76be21146101f55780635e1e6325146101f05780636c569f21146101eb57806373d99ad3146101a0578063791b98bc146101e65780637f7e5bba146101e157806384b040c6146101dc5780638b0bc501146101d75780638da5cb5b146101d25780639375da5a146101cd57806397f548f7146101c8578063ad5c4648146101c3578063b1e1e98f146101be578063cc6be5e4146101b9578063d277ee75146101b4578063d73792a9146101af578063e37c6f8c146101aa578063ed14834f146101a55763eeab8ea00361000e575b611183565b61269d565b6123fd565b6123e1565b6123b0565b612388565b612308565b6122e1565b61177b565b611702565b610253565b6116e5565b611274565b6111c6565b61119e565b611166565b611127565b61110c565b611093565b611076565b611020565b611004565b610d2d565b610cd7565b61091f565b6107de565b610778565b610702565b6106da565b610661565b6105e8565b6102ab565b61027b565b5f91031261024f57565b5f80fd5b3461024f575f36600319011261024f576002546040516001600160a01b039091168152602090f35b3461024f575f36600319011261024f576040516001606f1b8152602090f35b6001600160a01b0381160361024f57565b3461024f57604036600319011261024f576004356102c88161029a565b5f54602435916001600160a01b0391821691811690610352836102ed848214156126c5565b6102f8841515612711565b61033a61033461032861031b8660018060a01b03165f52600960205260405f2090565b546001600160a01b031690565b6001600160a01b031690565b15612755565b851515806105da575b61034c90612798565b826130c5565b936001600160a01b0382169081036105ce5760015490845f915b036105c55786915f915b61131e610385602082016108af565b908082526020820190613e0b8239604051606089901b6001600160601b03191660208201908152906103c481603481015b03601f19810183528261086d565b5190209151905ff5976001600160a01b038916956103e38715156127e4565b863b1561024f5760405163eb990c5960e01b81526001600160a01b03918216600482015291166024820152604481019290925260648201525f8160848183885af1801561057f576105b1575b5061043c87303388613104565b60405163095ea7b360e01b81526001600160a01b0387166004820152602481018890526020816044815f8a5af1801561057f57610584575b50823b1561024f57604051630d2a183960e21b815260048101929092526024820152905f908290604490829084905af194851561057f576105187f28f6f5ceea521e91f6f2956665771f6f979641ef3ec6c812f0a4d1d2e73462ea93869361056198610565575b506105136104e761088f565b6001600160a01b0386168152913360208401526001600160a01b03165f90815260096020526040902090565b612845565b6105218261287a565b600a54604080519283526001600160a01b0393909316602083015291810191909152606090a26040516001600160a01b0390911681529081906020820190565b0390f35b806105735f6105799361086d565b80610245565b5f6104db565b612822565b6105a59060203d6020116105aa575b61059d818361086d565b81019061282d565b610474565b503d610593565b806105735f6105bf9361086d565b5f61042f565b5f918791610376565b6001545f91859061036c565b506001606f1b861115610343565b3461024f57602036600319011261024f576004356106058161029a565b61061a60018060a01b036002541633146128e4565b6008546001600160a01b0391821691829082167f458609883bfc2c0eb1300d68839f0a6aa0b7a1997aba004773946caf044a06ff5f80a36001600160a01b03191617600855005b3461024f57602036600319011261024f5760043561067e8161029a565b61069360018060a01b036002541633146128e4565b6007546001600160a01b0391821691829082167fc3a1129c241b1b8ea5a005d72142e13b31209f18f3cdd36e03631e910270e6055f80a36001600160a01b03191617600755005b3461024f575f36600319011261024f576008546040516001600160a01b039091168152602090f35b3461024f57602036600319011261024f5760043561071f8161029a565b6002546001600160a01b038116916107383384146128e4565b6001600160a01b03169182907f8292fce18fa69edf4db7b94ea2e58241df0ae57f97e0a6c9b29067028bf92d765f80a36001600160a01b03191617600255005b3461024f57602036600319011261024f576004356107958161029a565b6001600160a01b039081165f908152600960209081526040918290208054600190910154835191851682529093169083015290f35b634e487b7160e01b5f52603260045260245ffd5b3461024f57602036600319011261024f57600435600a5481101561024f57600a5f527fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a801546040516001600160a01b039091168152602090f35b634e487b7160e01b5f52604160045260245ffd5b6040810190811067ffffffffffffffff82111761086857604052565b610838565b90601f8019910116810190811067ffffffffffffffff82111761086857604052565b6040519061089e60408361086d565b565b6040519061089e60a08361086d565b9061089e604051928361086d565b67ffffffffffffffff811161086857601f01601f191660200190565b81601f8201121561024f578035906108f0826108bd565b926108fe604051948561086d565b8284526020838301011161024f57815f926020809301838601378301015290565b3461024f57606036600319011261024f5760043567ffffffffffffffff811161024f576109509036906004016108d9565b60243567ffffffffffffffff811161024f576109709036906004016108d9565b906044359160405192610a4e918285019385851067ffffffffffffffff8611176108685785946109a4946151298739612cdb565b03905ff0801561057f576001600160a01b03166109c2811515612711565b6040516318160ddd60e01b8152602081600481855afa801561057f57610a44915f91610ca8575b50610a0d61033461032861031b8660018060a01b03165f52600960205260405f2090565b80151580610c9a575b610a1f90612798565b5f546001600160a01b031690610a3582856130c5565b9390926001600160a01b031690565b6001600160a01b038316908103610c8e57600154855f925b03610c8557825f925b61131e610a74602082016108af565b908082526020820190613e0b823960405160608b901b6001600160601b0319166020820190815290610aa981603481016103b6565b5190209151905ff5966001600160a01b03881696610ac88815156127e4565b873b1561024f5760405163eb990c5960e01b81526001600160a01b03918216600482015291166024820152604481019390935260648301525f8260848183895af190811561057f57610b4d92602092610c71575b5060405163095ea7b360e01b81526001600160a01b0388166004820152602481019190915291829081906044820190565b03815f8a5af1801561057f57610c54575b50823b1561024f57604051630d2a183960e21b815260048101929092526024820152905f908290604490829084905af1801561057f57610c40575b50610bd3610ba561088f565b6001600160a01b03831681523360208201526001600160a01b0384165f908152600960205260409020612845565b610bdc8161287a565b600a54604080516001600160a01b0384168152602081019290925283917f67191a2a61d496102827fa6683fb3a6a251cb28e3eb8bf0b7b2f466277358e0a91819081015b0390a2604080516001600160a01b03928316815292909116602083015290f35b806105735f610c4e9361086d565b5f610b99565b610c6c9060203d6020116105aa5761059d818361086d565b610b5e565b806105735f610c7f9361086d565b5f610b1c565b5f928092610a65565b600154855f9192610a5c565b506001606f1b811115610a16565b610cca915060203d602011610cd0575b610cc2818361086d565b810190612d09565b5f6109e9565b503d610cb8565b3461024f57602036600319011261024f57600435610d0060018060a01b036002541633146128e4565b806001547f2ef7bc232054955f8d12845c90c0cdaecac0635f600eb7ec027047b5eee425c95f80a3600155005b608036600319011261024f57602435600435610d488261029a565b604435610d548161029a565b610d756064355b610d69600160055414612925565b5f600555421115612963565b6001600160a01b0383165f908152600960205260409020610d95906129a2565b8051909190610db2906001600160a01b039081165b1615156129ce565b610dc6610dbe34612a2e565b612710900490565b610dd2610dbe34612a2e565b94610de686610de18434612aee565b612aee565b9582610f54575b805f516020615b775f395f51905f5291151580610f37575b610f16575b60208681015160408051968752918601929092526001600160a01b03938416949390911692a35f54610e6690610328906001600160a01b0316845161032890610e5d906001600160a01b0316838a612bb5565b96871015612afb565b91823b1561024f575f8593600460405180968193630d0e30db60e41b83525af1801561057f5761056195610ee894610ec392610f02575b505f54610eb2906001600160a01b0316610328565b83516001600160a01b031690613231565b5f54610ee1906001600160a01b03165b91516001600160a01b031690565b9084613287565b610ef26001600555565b6040519081529081906020820190565b806105735f610f109361086d565b5f610e9d565b600354610f329082906001600160a01b0316613192565b613192565b610e0a565b50600354610f4d906001600160a01b0316610328565b1515610e05565b600754610f6f908490610f2d906001600160a01b0316610328565b600754610f84906001600160a01b0316610328565b60208601516001600160a01b03169190803b1561024f5760405163a71532cd60e01b81526001600160a01b03939093166004840152602483018590525f908390604490829084905af191821561057f575f516020615b775f395f51905f5292610ff0575b509050610ded565b806105735f610ffe9361086d565b5f610fe8565b3461024f575f36600319011261024f576020604051610bb88152f35b3461024f57602036600319011261024f5760043561104960018060a01b036002541633146128e4565b806004547f74fa33832976c63d8bc0ee8ecb7180955e8222b437b61c2d88aa8acdbc0ba1bc5f80a3600455005b3461024f575f36600319011261024f576020600a54604051908152f35b3461024f57602036600319011261024f576004356110b08161029a565b6110c560018060a01b036002541633146128e4565b6006546001600160a01b0391821691829082167f9ee681927833c2398c73d0f5b2a218383929087bada1b839781887af24e6bb025f80a36001600160a01b03191617600655005b3461024f575f36600319011261024f576020604051603c8152f35b3461024f57606036600319011261024f57602061115e60043560243561114c8161029a565b604435916111598361029a565b612bb5565b604051908152f35b3461024f575f36600319011261024f576020600154604051908152f35b3461024f575f36600319011261024f57602060405160328152f35b3461024f575f36600319011261024f576006546040516001600160a01b039091168152602090f35b3461024f57604036600319011261024f57610561610ef26004356024356111ec8161029a565b60018060a01b03165f52600960205261125760405f2091611236604051936112138561084c565b80546001600160a01b039081168087526001909201548116602087015290610daa565b610de1611245610dbe83612a2e565b611251610dbe84612a2e565b92612aee565b5f5490919061126e906001600160a01b0316610ed3565b91612bb5565b3461024f57608036600319011261024f5760043567ffffffffffffffff811161024f576112a59036906004016108d9565b60243567ffffffffffffffff811161024f576112c59036906004016108d9565b90604435906064359260405192610a4e918285019385851067ffffffffffffffff8611176108685785946112fd946151298739612cdb565b03905ff0801561057f576001600160a01b03169061131c821515612711565b6040516318160ddd60e01b8152602081600481865afa90811561057f575f916116c6575b50808215918215611657575b506113ac925061137561033461032861031b8760018060a01b03165f52600960205260405f2090565b80151580611649575b61138790612798565b5f546001600160a01b03169161139d83866130c5565b9490936001600160a01b031690565b6001600160a01b03841690810361163d5760015490865f915b036116345783915f915b61131e6113de602082016108af565b908082526020820190613e0b823960405160608c901b6001600160601b031916602082019081529061141381603481016103b6565b5190209151905ff5976001600160a01b038916976114328915156127e4565b883b1561024f5760405163eb990c5960e01b81526001600160a01b03918216600482015291166024820152604481019290925260648201525f81608481838a5af1801561057f57611620575b5060405163095ea7b360e01b81526001600160a01b0387166004820152602481018590526020816044815f8c5af1801561057f57611603575b50843b1561024f57604051630d2a183960e21b815260048101929092526024820152925f908490604490829084905af190811561057f57859385926115ef575b5061153161150361088f565b6001600160a01b03841681523360208201526001600160a01b0386165f908152600960205260409020612845565b61153a8261287a565b156115a5575050600a54604080516001600160a01b038516815260208101929092527f67191a2a61d496102827fa6683fb3a6a251cb28e3eb8bf0b7b2f466277358e0a919081908101610c20565b604080516001600160a01b03928316815292909116602083015290f35b600a54604080519384526001600160a01b03929092166020840152908201527f28f6f5ceea521e91f6f2956665771f6f979641ef3ec6c812f0a4d1d2e73462ea90606090a2611588565b806105735f6115fd9361086d565b5f6114f7565b61161b9060203d6020116105aa5761059d818361086d565b6114b7565b806105735f61162e9361086d565b5f61147e565b5f9184916113cf565b6001545f9187906113c5565b506001606f1b81111561137e565b9050611664818410612d18565b60405163a9059cbb60e01b815233600482015260248101849052926020846044815f895af191821561057f576113ac946116a3936116a9575b50612aee565b5f61134c565b6116c19060203d6020116105aa5761059d818361086d565b61169d565b6116df915060203d602011610cd057610cc2818361086d565b5f611340565b3461024f575f36600319011261024f576020600454604051908152f35b3461024f57602036600319011261024f5760043561171f8161029a565b61173460018060a01b036002541633146128e4565b6003546001600160a01b0391821691829082167f698bfb5cd028a0af42ac6831cc213cb879e4543e1b6997a0cc64dd5ea41957495f80a36001600160a01b03191617600355005b3461024f57602036600319011261024f576004356117988161029a565b6001600160a01b0381165f9081526009602052604090206117b8906129a2565b80519091906117d1906001600160a01b03908116610daa565b5f546117e5906001600160a01b0316610328565b82516040516370a0823160e01b81526001600160a01b039182166004820152919391906020908290602490829088165afa801561057f57611832915f916122c2575b506004541115612d64565b6001600160a01b0382169283101561225e57805160049060209061186090610328906001600160a01b031681565b604051634b4af0ff60e01b815292839182905afa90811561057f575f9161223f575b50905b805161189b90610328906001600160a01b031681565b803b1561024f575f809160046040518094819363fce4624d60e01b83525af1801561057f5761222b575b506040516370a0823160e01b815230600482015290602082602481885afa91821561057f575f9261220a575b505f5461190890610328906001600160a01b031681565b6040516370a0823160e01b815230600482015293602085602481855afa94851561057f575f956121e9575b50813b1561024f57604051632e1a7d4d60e01b815260048101869052915f908390602490829084905af191821561057f57611974926121d5575b5084612dbe565b916119c96103286119c46119bf6119896108a0565b5f81526001600160a01b038b16602082015296610bb86040890152603c60608901525f60808901526119ba86612a49565b612ad1565b612a62565b613434565b6006549094906119e1906001600160a01b0316610328565b6020604051809263f702040560e01b8252815f81611a038c8c60048401612e27565b03925af1801561057f576121a8575b50600854611a62906020908490611a31906001600160a01b0316610328565b60405163095ea7b360e01b81526001600160a01b039091166004820152602481019190915291829081906044820190565b03815f8c5af1801561057f5761218b575b50600854611a89906001600160a01b0316610328565b600654611a9e906001600160a01b0316610328565b611ab5611aaa42612db0565b65ffffffffffff1690565b823b1561024f576040516387517c4560e01b81526001600160a01b038a811660048301529283166024820152918516604483015265ffffffffffff166064820152905f908290608490829084905af1801561057f57612177575b506001600160a01b038516611b3b611b30611b2a8385612aaa565b60601c90565b916119ba8560601b90565b8082101561216f5750915b604051600160f91b6020820152600d60f81b602182015260028152906001600160801b0390611bbb90611b7a60228561086d565b6103b6611b85612e47565b600754909790611b9d906001600160a01b0316610328565b9060405195869416906001600160801b038916908c60208701612e81565b611bc484612ee5565b52611bce83612ee5565b50604080515f60208201526001600160a01b038a1691810191909152611bf781606081016103b6565b611c0084612ef2565b52611c0a83612ef2565b50600654611c4590611c24906001600160a01b0316610328565b91611c3760405195869260208401612f02565b03601f19810185528461086d565b611c4e42612db0565b90803b1561024f5760405163dd46508f60e01b8152935f93859384928391611c799160048401612f74565b03925af1801561057f5761215b575b50600654600490602090611ca4906001600160a01b0316610328565b604051631d5e528f60e21b815292839182905afa801561057f57611ccf915f916120c2575b50612ae0565b600754909390602090611cea906001600160a01b0316610328565b920180519092906001600160a01b031690803b1561024f57604051636eb2f49d60e11b81526001600160a01b0392831660048201529187166024830152604482018690525f908290606490829084905af1801561057f57612147575b506040516370a0823160e01b8152306004820152906020826024818a5afa91821561057f575f92612126575b5081611db4575b60a0842060408051878152602081019290925288917ff315359bf184d3fe9fa6521f1b73b8aab071cf4d9e05dc239ca51147fee209289190a2005b611dc0611dc5916135b1565b612f8b565b600854611de3906020908490611a31906001600160a01b0316610328565b03815f8c5af1801561057f57612109575b50600854611e0a906001600160a01b0316610328565b600654611e1f906001600160a01b0316610328565b611e2b611aaa42612db0565b823b1561024f576040516387517c4560e01b81526001600160a01b038a811660048301529283166024820152918516604483015265ffffffffffff166064820152905f908290608490829084905af1801561057f576120f5575b506001600160801b03611f0b611eac84611e9d6136d9565b611ea6866139ee565b90613d0d565b604051600160f91b6020820152600d60f81b60218201526002815294906103b690611ed860228861086d565b611ee0612e47565b600754909690611ef8906001600160a01b0316610328565b9160405196879516918b60208701612fa7565b611f1482612ee5565b52611f1e81612ee5565b50604080515f60208201526001600160a01b03891691810191909152611f4781606081016103b6565b611f5082612ef2565b52611f5a81612ef2565b50600654611f8790611f74906001600160a01b0316610328565b926103b660405193849260208401612f02565b611f9042612db0565b823b1561024f57611fba925f928360405180968195829463dd46508f60e01b845260048401612f74565b03925af1801561057f576120e1575b50600654600490602090611fe5906001600160a01b0316610328565b604051631d5e528f60e21b815292839182905afa801561057f5761200f915f916120c25750612ae0565b60075461203690612028906001600160a01b0316610328565b92516001600160a01b031690565b91803b1561024f57604051636eb2f49d60e11b81526001600160a01b03938416600482015295909216602486015260448501525f908490606490829084905af190811561057f577ff315359bf184d3fe9fa6521f1b73b8aab071cf4d9e05dc239ca51147fee209289360a0926120ae575b8192611d79565b806105735f6120bc9361086d565b5f6120a7565b6120db915060203d602011610cd057610cc2818361086d565b5f611cc9565b806105735f6120ef9361086d565b5f611fc9565b806105735f6121039361086d565b5f611e85565b6121219060203d6020116105aa5761059d818361086d565b611df4565b61214091925060203d602011610cd057610cc2818361086d565b905f611d72565b806105735f6121559361086d565b5f611d46565b806105735f6121699361086d565b5f611c88565b905091611b46565b806105735f6121859361086d565b5f611b0f565b6121a39060203d6020116105aa5761059d818361086d565b611a73565b6121c99060203d6020116121ce575b6121c1818361086d565b810190612dcb565b611a12565b503d6121b7565b806105735f6121e39361086d565b5f61196d565b61220391955060203d602011610cd057610cc2818361086d565b935f611933565b61222491925060203d602011610cd057610cc2818361086d565b905f6118f1565b806105735f6122399361086d565b5f6118c5565b612258915060203d602011610cd057610cc2818361086d565b5f611882565b805160049060209061227a90610328906001600160a01b031681565b60405163c62b92ef60e01b815292839182905afa90811561057f575f916122a3575b5090611885565b6122bc915060203d602011610cd057610cc2818361086d565b5f61229c565b6122db915060203d602011610cd057610cc2818361086d565b5f611827565b3461024f575f36600319011261024f575f546040516001600160a01b039091168152602090f35b3461024f57604036600319011261024f57610561610ef26112366004356024356123318161029a565b60018060a01b0381165f52600960205261126e60405f2061237b604051916123588361084c565b80546001600160a01b039081168085526001909201548116602085015290610daa565b516001600160a01b031690565b3461024f575f36600319011261024f576007546040516001600160a01b039091168152602090f35b3461024f57602036600319011261024f5760206123d76004356123d28161029a565b61300a565b6040519015158152f35b3461024f575f36600319011261024f5760206040516127108152f35b3461024f5760a036600319011261024f576024356044356004356124208261029a565b6064359261242d8461029a565b612438608435610d5b565b6001600160a01b0383165f908152600960205260409020612458906129a2565b8051909290612471906001600160a01b03908116610daa565b82516124bd9061248b906001600160a01b03168684612bb5565b845190956001600160a01b038082169491926124aa9291163386613104565b84516001600160a01b0316309187613287565b5f546124d390610328906001600160a01b031681565b803b1561024f57604051632e1a7d4d60e01b815260048101869052905f908290602490829084905af1801561057f57612689575b50612514610dbe85612a2e565b612520610dbe86612a2e565b61252e81610de18489612aee565b94826125c3575b92610f2d925f516020615b775f395f51905f52836105619a96610ee89998951515806125a6575b61258a575b60209081015160408051958652918501929092526001600160a01b0390911692a3831015612afb565b6003546125a19083906001600160a01b0316613192565b612561565b506003546125bc906001600160a01b0316610328565b151561255c565b94939096926125e083610f2d61032860075460018060a01b031690565b6007546125f5906001600160a01b0316610328565b60208701516001600160a01b03169390803b1561024f5760405163a71532cd60e01b81526001600160a01b03959095166004860152602485018290525f908590604490829084905af1801561057f5761056199610ee898610f2d965f516020615b775f395f51905f5293612675575b5093969a5093969750509250612535565b806105735f6126839361086d565b5f612664565b806105735f6126979361086d565b5f612507565b3461024f575f36600319011261024f576003546040516001600160a01b039091168152602090f35b156126cc57565b60405162461bcd60e51b815260206004820152601c60248201527f4170707346756e3a204944454e544943414c5f414444524553534553000000006044820152606490fd5b1561271857565b60405162461bcd60e51b81526020600482015260156024820152744170707346756e3a205a45524f5f4144445245535360581b6044820152606490fd5b1561275c57565b60405162461bcd60e51b81526020600482015260146024820152734170707346756e3a20504149525f45584953545360601b6044820152606490fd5b1561279f57565b60405162461bcd60e51b815260206004820152601760248201527f4170707346756e3a20494e56414c49445f414d4f554e540000000000000000006044820152606490fd5b156127eb57565b60405162461bcd60e51b815260206004820152600f60248201526e105c1c1cd19d5b8e88119052531151608a1b6044820152606490fd5b6040513d5f823e3d90fd5b9081602091031261024f5751801515810361024f5790565b815181546001600160a01b039182166001600160a01b0319918216178355602090930151600190920180549093169116179055565b600a54600160401b8110156108685760018101600a55600a548110156128df57600a5f527fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a80180546001600160a01b0319166001600160a01b03909216919091179055565b6107ca565b156128eb57565b60405162461bcd60e51b815260206004820152601260248201527120b83839a33ab71d102327a92124a22222a760711b6044820152606490fd5b1561292c57565b60405162461bcd60e51b815260206004820152600f60248201526e105c1c1cd19d5b8e881313d0d2d151608a1b6044820152606490fd5b1561296a57565b60405162461bcd60e51b815260206004820152601060248201526f105c1c1cd19d5b8e881156141254915160821b6044820152606490fd5b906040516129af8161084c565b82546001600160a01b0390811682526001909301549092166020830152565b156129d557565b60405162461bcd60e51b815260206004820152601760248201527f4170707346756e3a20504149525f4e4f545f464f554e440000000000000000006044820152606490fd5b634e487b7160e01b5f52601160045260245ffd5b90603282029180830460321490151715612a4457565b612a1a565b908160601b91808304600160601b1490151715612a4457565b606081901b91906001600160a01b03811603612a4457565b906103e58202918083046103e51490151715612a4457565b906103e88202918083046103e81490151715612a4457565b81810292918115918404141715612a4457565b634e487b7160e01b5f52601260045260245ffd5b8115612adb570490565b612abd565b5f19810191908211612a4457565b91908203918211612a4457565b15612b0257565b60405162461bcd60e51b815260206004820152602360248201527f4170707346756e3a20494e53554646494349454e545f4f55545055545f414d4f60448201526215539560ea1b6064820152608490fd5b9081602091031261024f5751612b688161029a565b90565b51906001600160701b038216820361024f57565b9081606091031261024f57612b9381612b6b565b916040612ba260208401612b6b565b92015163ffffffff8116810361024f5790565b604051630dfe168160e01b8152926001600160a01b0316602084600481845afa93841561057f575f94612c80575b50606060049160405192838092630240bc6b60e21b82525afa92831561057f57612b68945f925f95612c48575b506001600160a01b03918216911603612c38576001600160701b038091935b16921690613354565b6001600160701b03908190612c2f565b909450612c6e91925060603d606011612c79575b612c66818361086d565b810190612b7f565b50919091935f612c10565b503d612c5c565b6004919450612ca860609160203d602011612cb0575b612ca0818361086d565b810190612b53565b949150612be3565b503d612c96565b805180835260209291819084018484015e5f828201840152601f01601f1916010190565b939291612d0490612cf6604093606088526060880190612cb7565b908682036020880152612cb7565b930152565b9081602091031261024f575190565b15612d1f57565b60405162461bcd60e51b815260206004820152601f60248201527f4170707346756e3a20494e56414c49445f43524541544f525f414d4f554e54006044820152606490fd5b15612d6b57565b60405162461bcd60e51b815260206004820152601a60248201527f4170707346756e3a205448524553484f4c445f4e4f545f4d45540000000000006044820152606490fd5b90603c8201809211612a4457565b91908201809211612a4457565b9081602091031261024f57518060020b810361024f5790565b80516001600160a01b03908116835260208083015182169084015260408083015162ffffff169084015260608083015160020b9084015260809182015116910152565b90929160a090612e3b8360c0810196612de4565b600180831b0316910152565b60405160609190612e58838261086d565b6002815291601f1901825f5b828110612e7057505050565b806060602080938501015201612e64565b93906101a095936001600160801b0393612e9c878694612de4565b620d89b31960a0880152620d89b460c088015260e087015216610100850152166101208301526001600160a01b031661014082015261018061016082018190525f908201520190565b8051156128df5760200190565b8051600110156128df5760400190565b90612f1590604083526040830190612cb7565b906020818303910152815180825260208201916020808360051b8301019401925f915b838310612f4757505050505090565b9091929394602080612f65600193601f198682030187528951612cb7565b97019301930191939290612f38565b929190612d04602091604086526040860190612cb7565b60020b603b190190627fffff198212627fffff831317612a4457565b93906101a095936001600160801b0393612fc2878694612de4565b620d89b31960a088015260020b60c08701521660e08501525f6101008501521661012083015260018060a01b03166101408201526101806101608201525f6101808201520190565b6001600160a01b03165f90815260096020526040902061302d9061237b906129a2565b6001600160a01b038116156130c0575f546130869160209161305990610328906001600160a01b031681565b6040516370a0823160e01b81526001600160a01b0390921660048301529092839190829081906024820190565b03915afa90811561057f575f916130a1575b50600454111590565b6130ba915060203d602011610cd057610cc2818361086d565b5f613098565b505f90565b9091906001600160a01b038084169082166130e2818314156126c5565b10156130ff57915b9061089e6001600160a01b0384161515612711565b6130ea565b6040516323b872dd60e01b5f9081526001600160a01b039384166004529290931660245260449390935260209060648180865af160015f5114811615613173575b6040919091525f606052155b6131585750565b635274afe760e01b5f526001600160a01b031660045260245ffd5b6001811516613189573d15833b15151616613145565b503d5f823e3d90fd5b5f8091602093604051906131a6868361086d565b83825285820191601f19870136843751925af13d1561322c573d6131c9816108bd565b906131d7604051928361086d565b81525f833d92013e5b156131e85750565b6064906040519062461bcd60e51b82526004820152601c60248201527f4170707346756e3a204554485f5452414e534645525f4641494c4544000000006044820152fd5b6131e0565b916040519163a9059cbb60e01b5f5260018060a01b031660045260245260205f60448180865af160015f5114811615613271575b60409190915215613151565b6001811516613189573d15833b15151616613265565b604051630dfe168160e01b81526001600160a01b03909316939092909190602081600481885afa90811561057f575f91613335575b506001600160a01b0391821691160361332e575f91925b803b1561024f576040516336cd320560e11b8152600481019390935260248301939093526001600160a01b03166044820152905f908290606490829084905af1801561057f576133205750565b806105735f61089e9361086d565b5f926132d3565b61334e915060203d602011612cb057612ca0818361086d565b5f6132bc565b80156133e457811515806133db575b1561339657612b689261338b61338561337e61339094612a7a565b9283612aaa565b93612a92565b612dbe565b90612ad1565b60405162461bcd60e51b815260206004820152601f60248201527f4170707346756e3a20494e53554646494349454e545f4c4951554944495459006044820152606490fd5b50821515613363565b60405162461bcd60e51b815260206004820152602260248201527f4170707346756e3a20494e53554646494349454e545f494e5055545f414d4f55604482015261139560f21b6064820152608490fd5b905f600383111561347d5750818060011c60018101809111612a4457905b83821061345d575050565b909250828015612adb57808204908101809111612a445760011c90613452565b9161348457565b60019150565b9060408201915f604084129112908015821691151617612a4457565b9060208201915f602084129112908015821691151617612a4457565b9060108201915f601084129112908015821691151617612a4457565b9060088201915f600884129112908015821691151617612a4457565b9060048201915f600484129112908015821691151617612a4457565b9060028201915f600284129112908015821691151617612a4457565b9060018201915f600184129112908015821691151617612a4457565b90605f198201918213600116612a4457565b9061056a82029180830561056a1490151715612a4457565b60020b9060020b908115612adb57627fffff1981145f19831416612a44570590565b9060020b9060020b02908160020b918203612a4457565b603c6136498161364461363e613637613632612b689760018060a01b03165f90600160801b8110156136ce575b80600160401b60029210156136bb575b6401000000008110156136a8575b62010000811015613695575b610100811015613682575b601081101561366f575b600481101561365c575b101561364e5761354e565b613560565b600a900590565b60020b90565b613578565b61359a565b61365790613532565b61354e565b6136699060021c92613516565b91613627565b61367c9060041c926134fa565b9161361d565b61368f9060081c926134de565b91613613565b6136a29060101c926134c2565b91613608565b6136b59060201c926134a6565b916135fc565b6136c89060401c9261348a565b916135ee565b60809150811c6135de565b620d89b31960ff1d620d89b319810118620d89e881116139e45763ffffffff90600160801b7001fffcb933bd6fad37aa2d162d1a59400160018316021890600281166139c8575b600481166139ac575b60088116613990575b60108116613974575b60208116613958575b6040811661393c575b60808116613920575b6101008116613904575b61020081166138e8575b61040081166138cc575b61080081166138b0575b6110008116613894575b6120008116613878575b614000811661385c575b6180008116613840575b620100008116613824575b620200008116613809575b6204000081166137ee575b62080000166137d8575b0160201c90565b6b048a170391f7dc42444e8fa20260801c6137d1565b6d2216e584f5fa1ea926041bedfe9890910260801c906137c7565b906e5d6af8dedb81196699c329225ee6040260801c906137bc565b906f09aa508b5b7a84e1c677de54f3e99bc90260801c906137b1565b906f31be135f97d08fd981231505542fcfa60260801c906137a6565b906f70d869a156d2a1b890bb3df62baf32f70260801c9061379c565b906fa9f746462d870fdf8a65dc1f90e061e50260801c90613792565b906fd097f3bdfd2022b8845ad8f792aa58250260801c90613788565b906fe7159475a2c29b7443b29c7fa6e889d90260801c9061377e565b906ff3392b0822b70005940c7a398e4b70f30260801c90613774565b906ff987a7253ac413176f2b074cf7815e540260801c9061376a565b906ffcbe86c7900a88aedcffc83b479aa3a40260801c90613760565b906ffe5dee046a99a2a811c461f1969c30530260801c90613756565b906fff2ea16466c96a3843ec78b326b528610260801c9061374d565b906fff973b41fa98c081472e6896dfb254c00260801c90613744565b906fffcb9843d60f6159c9db58835c9266440260801c9061373b565b906fffe5caca7e10e4e61c3624eaa0941cd00260801c90613732565b906ffff2e50f5f656932ef12357cf3c7fdcc0260801c90613729565b906ffff97272373d413259a46990580e213a0260801c90613720565b620d89b319613d61565b60020b908160ff1d82810118620d89e88111613d075763ffffffff9192600182167001fffcb933bd6fad37aa2d162d1a59400102600160801b189160028116613ceb575b60048116613ccf575b60088116613cb3575b60108116613c97575b60208116613c7b575b60408116613c5f575b60808116613c43575b6101008116613c27575b6102008116613c0b575b6104008116613bef575b6108008116613bd3575b6110008116613bb7575b6120008116613b9b575b6140008116613b7f575b6180008116613b63575b620100008116613b47575b620200008116613b2c575b620400008116613b11575b6208000016613af8575b5f12613af0570160201c90565b5f19046137d1565b6b048a170391f7dc42444e8fa290910260801c90613ae3565b6d2216e584f5fa1ea926041bedfe9890920260801c91613ad9565b916e5d6af8dedb81196699c329225ee6040260801c91613ace565b916f09aa508b5b7a84e1c677de54f3e99bc90260801c91613ac3565b916f31be135f97d08fd981231505542fcfa60260801c91613ab8565b916f70d869a156d2a1b890bb3df62baf32f70260801c91613aae565b916fa9f746462d870fdf8a65dc1f90e061e50260801c91613aa4565b916fd097f3bdfd2022b8845ad8f792aa58250260801c91613a9a565b916fe7159475a2c29b7443b29c7fa6e889d90260801c91613a90565b916ff3392b0822b70005940c7a398e4b70f30260801c91613a86565b916ff987a7253ac413176f2b074cf7815e540260801c91613a7c565b916ffcbe86c7900a88aedcffc83b479aa3a40260801c91613a72565b916ffe5dee046a99a2a811c461f1969c30530260801c91613a68565b916fff2ea16466c96a3843ec78b326b528610260801c91613a5f565b916fff973b41fa98c081472e6896dfb254c00260801c91613a56565b916fffcb9843d60f6159c9db58835c9266440260801c91613a4d565b916fffe5caca7e10e4e61c3624eaa0941cd00260801c91613a44565b916ffff2e50f5f656932ef12357cf3c7fdcc0260801c91613a3b565b916ffff97272373d413259a46990580e213a0260801c91613a32565b82613d61565b613d389291906001600160a01b0380831690821611613d5b575b90036001600160a01b031690613d7d565b6001600160801b038116809103613d4c5790565b6393dafdf160e01b5f5260045ffd5b90613d27565b6345c3193d60e11b5f5260020b60045260245ffd5b1561024f57565b90606082901b905f19600160601b8409928280851094039380850394613da4868511613d76565b14613e03578190600160601b900981805f03168092046002816003021880820260020302808202600203028082026002030280820260020302808202600203028091026002030293600183805f03040190848311900302920304170290565b509150049056fe60808060405234602b5760016008555f80546001600160a01b031916331790556112ee90816100308239f35b5f80fdfe60806040526004361015610011575f80fd5b5f3560e01c80630902f1ac14610e835780630dfe168114610e5b57806334a860e414610cc85780634b4af0ff14610cab5780635909c0d514610c8e5780635a3d549314610c715780636d9a640a14610751578063ba9a7a5614610735578063bc25cf77146105f3578063c45a0155146105cc578063c62b92ef146105af578063d21220a714610587578063d3e3747214610568578063eb990c591461046e578063fce4624d146101fd5763fff6cae9146100c9575f80fd5b346101b3575f3660031901126101b3576100e7600160085414610f22565b5f6008556001546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa80156101bf575f906101ca575b6002546040516370a0823160e01b81523060048201529250602090839060249082906001600160a01b03165afa9081156101bf575f91610185575b61017e9250600354916001600160701b03808460701c16931691611089565b6001600855005b90506020823d6020116101b7575b816101a060209383610fa1565b810103126101b35761017e91519061015f565b5f80fd5b3d9150610193565b6040513d5f823e3d90fd5b506020813d6020116101f5575b816101e460209383610fa1565b810103126101b35760249051610124565b3d91506101d7565b346101b3575f3660031901126101b35761021b600160085414610f22565b5f60085561023360018060a01b035f54163314610f60565b6001546040516370a0823160e01b8152306004820152906001600160a01b0316602082602481845afa9182156101bf575f9261043a575b506002546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa9081156101bf5783905f92610404575b506102b4919233906111f8565b6002546102cd90829033906001600160a01b03166111f8565b6001546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa80156101bf575f906103d1575b6002546040516370a0823160e01b81523060048201529250602090839060249082906001600160a01b03165afa9182156101bf575f92610397575b7ff3f4772b0ce29670f0f94b6bb2b4afed357a2ee57d34e31562426895e978f71e604086866103858787600354916001600160701b03808460701c16931691611089565b82519182526020820152a16001600855005b939150916020843d6020116103c9575b816103b460209383610fa1565b810103126101b3579251909291610385610341565b3d91506103a7565b506020813d6020116103fc575b816103eb60209383610fa1565b810103126101b35760249051610306565b3d91506103de565b9150506020813d602011610432575b8161042060209383610fa1565b810103126101b35751826102b46102a7565b3d9150610413565b9091506020813d602011610466575b8161045660209383610fa1565b810103126101b35751908261026a565b3d9150610449565b346101b35760803660031901126101b357610487610ec3565b6024356001600160a01b038116908190036101b35760443590606435926104b860018060a01b035f54163314610f60565b60018060a01b03166bffffffffffffffffffffffff60a01b60015416176001556bffffffffffffffffffffffff60a01b6002541617600255600160581b8111158061055a575b1561050b57600655600755005b60405162461bcd60e51b815260206004820152602160248201527f4170707346756e3a205649525455414c5f524553455256455f544f4f5f4849476044820152600960fb1b6064820152608490fd5b50600160581b8211156104fe565b346101b3575f3660031901126101b357604051600160581b8152602090f35b346101b3575f3660031901126101b3576002546040516001600160a01b039091168152602090f35b346101b3575f3660031901126101b3576020600654604051908152f35b346101b3575f3660031901126101b3575f546040516001600160a01b039091168152602090f35b346101b35760203660031901126101b35761060c610ec3565b61061a600160085414610f22565b5f6008556001546002546040516370a0823160e01b81523060048201526001600160a01b0391821692909116602082602481845afa9182156101bf5784905f936106fd575b5061067961067f936001600160701b036003541690610fd7565b916111f8565b6040516370a0823160e01b815230600482015291602083602481855afa9283156101bf575f936106c7575b5061067961017e936001600160701b0360035460701c1690610fd7565b92506020833d6020116106f5575b816106e260209383610fa1565b810103126101b3579151916106796106aa565b3d91506106d5565b9250506020823d60201161072d575b8161071960209383610fa1565b810103126101b3579051908361067961065f565b3d915061070c565b346101b3575f3660031901126101b35760206040516103e88152f35b346101b35760603660031901126101b3576044356001600160a01b038116906024356004358383036101b35761078b600160085414610f22565b5f6008556107a360018060a01b035f54163314610f60565b8015809381158092610c68575b15610c17576003546001600160701b038082169160701c1695818510908115610c0f575b5015610bc0578585108015610bb8575b15610b69576107f1610ee6565b506001546002546001600160a01b039081169692949291168a81141580610b5f575b15610b2457602495602092610b14575b8980610b03575b50506040516370a0823160e01b815230600482015295869182905afa9384156101bf575f94610acc575b506020602495604051968780926370a0823160e01b82523060048301525afa9485156101bf57879187915f97610a93575b506108908282610fd7565b861115610a8a576108aa916108a491610fd7565b85610fd7565b975b6108b68282610fd7565b861115610a81576108ca916108a491610fd7565b935b8715801581610a78575b15610a28576108e760065486610ed9565b6108f360075484610ed9565b916103e88202918083046103e81490151715610a145760038b02908b82046003141715610a145761092391610fd7565b6103e88202918083046103e81490151715610a1457600387029187830460031488151715610a145761095e9261095891610fd7565b90610fe4565b61097a6001600160701b0385166001600160701b038516610fe4565b90620f4240820291808304620f42401490151715610a1457106109e2576109a093611089565b6040519384526020840152604083015260608201527fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d82260803392a36001600855005b60405162461bcd60e51b815260206004820152600a6024820152694170707346756e3a204b60b01b6044820152606490fd5b634e487b7160e01b5f52601160045260245ffd5b60405162461bcd60e51b815260206004820152602260248201527f4170707346756e3a20494e53554646494349454e545f494e5055545f414d4f55604482015261139560f21b6064820152608490fd5b508515156108d6565b50505f936108cc565b50505f976108ac565b92509550506020813d602011610ac4575b81610ab160209383610fa1565b810103126101b35785879151958b610885565b3d9150610aa4565b9493506020853d602011610afb575b81610ae860209383610fa1565b810103126101b357935192936020610854565b3d9150610adb565b610b0d91896111f8565b8b8961082a565b610b1f8982846111f8565b610823565b60405162461bcd60e51b81526020600482015260136024820152724170707346756e3a20494e56414c49445f544f60681b6044820152606490fd5b50868b1415610813565b60405162461bcd60e51b815260206004820152602160248201527f4170707346756e3a20494e53554646494349454e545f4c4951554944495459206044820152603160f81b6064820152608490fd5b5084156107e4565b60405162461bcd60e51b815260206004820152602160248201527f4170707346756e3a20494e53554646494349454e545f4c4951554944495459206044820152600360fc1b6064820152608490fd5b9050886107d4565b60405162461bcd60e51b815260206004820152602360248201527f4170707346756e3a20494e53554646494349454e545f4f55545055545f414d4f60448201526215539560ea1b6064820152608490fd5b508315156107b0565b346101b3575f3660031901126101b3576020600554604051908152f35b346101b3575f3660031901126101b3576020600454604051908152f35b346101b3575f3660031901126101b3576020600754604051908152f35b346101b35760403660031901126101b357600435602435610ced600160085414610f22565b5f600855610d0560018060a01b035f54163314610f60565b600154610d20908390309033906001600160a01b0316610ff7565b610d3681303360018060a01b0360025416610ff7565b6001546040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa80156101bf575f90610e28575b6002546040516370a0823160e01b81523060048201529250602090839060249082906001600160a01b03165afa9182156101bf575f92610dee575b7f9c86429231ed0411e3112a1dd5c6578826c2d48089d5ec491e874ce0029c0bbe604086866103858787600354916001600160701b03808460701c16931691611089565b939150916020843d602011610e20575b81610e0b60209383610fa1565b810103126101b3579251909291610385610daa565b3d9150610dfe565b506020813d602011610e53575b81610e4260209383610fa1565b810103126101b35760249051610d6f565b3d9150610e35565b346101b3575f3660031901126101b3576001546040516001600160a01b039091168152602090f35b346101b3575f3660031901126101b35760606001600160701b0363ffffffff610eaa610ee6565b9193908160405195168552166020840152166040820152f35b600435906001600160a01b03821682036101b357565b91908201809211610a1457565b6003546001600160701b03610eff600654828416610ed9565b16916001600160701b03610f1a600754828560701c16610ed9565b169160e01c90565b15610f2957565b60405162461bcd60e51b815260206004820152600f60248201526e105c1c1cd19d5b8e881313d0d2d151608a1b6044820152606490fd5b15610f6757565b60405162461bcd60e51b815260206004820152601260248201527120b83839a33ab71d102327a92124a22222a760711b6044820152606490fd5b90601f8019910116810190811067ffffffffffffffff821117610fc357604052565b634e487b7160e01b5f52604160045260245ffd5b91908203918211610a1457565b81810292918115918404141715610a1457565b6040516323b872dd60e01b5f9081526001600160a01b039384166004529290931660245260449390935260209060648180865af19060015f5114821615611068575b6040525f606052156110485750565b635274afe760e01b5f9081526001600160a01b0391909116600452602490fd5b90600181151661108057823b15153d15161690611039565b503d5f823e3d90fd5b926001600160701b03841115806111e7575b156111ae5760035460e01c63ffffffff42160363ffffffff8111610a14577f1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1946040946001600160701b039363ffffffff859416801515806111a3575b80611198575b611137575b50505016918263ffffffff60e01b4260e01b16918360701b9060701b16171780600355835192835260701c166020820152a1565b61118d926111859261116290611170611168856001600160e01b03858761115d87611250565b611286565b16610fe4565b600454610ed9565b6004556001600160e01b039261115d90611250565b600554610ed9565b6005555f8080611103565b5084821615156110fe565b5084831615156110f8565b60405162461bcd60e51b81526020600482015260116024820152704170707346756e3a204f564552464c4f5760781b6044820152606490fd5b506001600160701b0382111561109b565b916040519163a9059cbb60e01b5f5260018060a01b031660045260245260205f60448180865af19060015f5114821615611238575b604052156110485750565b90600181151661108057823b15153d1516169061122d565b6dffffffffffffffffffffffffffff60701b607082901b16906001600160701b0316808204600160701b1490151715610a145790565b906001600160701b03169081156112a4576001600160e01b03160490565b634e487b7160e01b5f52601260045260245ffdfea26469706673582212207a5d8a286c5b5c08be25c332be776afe91d6061c271cb652a3ff1d95abc19b1864736f6c634300082100336080604052346103cc57610a4e80380380610019816103d0565b9283398101906060818303126103cc5780516001600160401b0381116103cc57826100459183016103f5565b60208201519092906001600160401b0381116103cc576040916100699184016103f5565b91015182516001600160401b0381116102d257600354600181811c911680156103c2575b60208210146102b457601f8111610354575b506020601f82116001146102f157819293945f926102e6575b50508160011b915f199060031b1c1916176003555b81516001600160401b0381116102d257600454600181811c911680156102c8575b60208210146102b457601f8111610246575b50602092601f82116001146101e557928192935f926101da575b50508160011b915f199060031b1c1916176004555b670de0b6b3a7640000810290808204670de0b6b3a764000014901517156101b35733156101c7576002548181018091116101b357600255335f525f60205260405f208181540190556040519081525f7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef60203393a360405161060790816104478239f35b634e487b7160e01b5f52601160045260245ffd5b63ec442f0560e01b5f525f60045260245ffd5b015190505f8061011a565b601f1982169360045f52805f20915f5b86811061022e5750836001959610610216575b505050811b0160045561012f565b01515f1960f88460031b161c191690555f8080610208565b919260206001819286850151815501940192016101f5565b818111156101005760045f52601f820160051c7f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b602084106102ac575b81601f9101920160051c03905f5b82811061029f575050610100565b5f82820155600101610291565b5f9150610283565b634e487b7160e01b5f52602260045260245ffd5b90607f16906100ee565b634e487b7160e01b5f52604160045260245ffd5b015190505f806100b8565b601f1982169060035f52805f20915f5b81811061033c57509583600195969710610324575b505050811b016003556100cd565b01515f1960f88460031b161c191690555f8080610316565b9192602060018192868b015181550194019201610301565b8181111561009f5760035f52601f820160051c7fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b602084106103ba575b81601f9101920160051c03905f5b8281106103ad57505061009f565b5f8282015560010161039f565b5f9150610391565b90607f169061008d565b5f80fd5b6040519190601f01601f191682016001600160401b038111838210176102d257604052565b81601f820112156103cc578051906001600160401b0382116102d257610424601f8301601f19166020016103d0565b92828452602083830101116103cc57815f9260208093018386015e830101529056fe6080806040526004361015610012575f80fd5b5f3560e01c90816306fdde03146103ef57508063095ea7b31461036d57806318160ddd1461035057806323b872dd14610271578063313ce5671461025657806370a082311461021f57806395d89b4114610104578063a9059cbb146100d35763dd62ed3e1461007f575f80fd5b346100cf5760403660031901126100cf576100986104e8565b6100a06104fe565b6001600160a01b039182165f908152600160209081526040808320949093168252928352819020549051908152f35b5f80fd5b346100cf5760403660031901126100cf576100f96100ef6104e8565b6024359033610514565b602060405160018152f35b346100cf575f3660031901126100cf576040515f6004548060011c90600181168015610215575b602083108114610201578285529081156101e55750600114610190575b50819003601f01601f191681019067ffffffffffffffff82118183101761017c57610178829182604052826104be565b0390f35b634e487b7160e01b5f52604160045260245ffd5b905060045f527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b5f905b8282106101cf57506020915082010182610148565b60018160209254838588010152019101906101ba565b90506020925060ff191682840152151560051b82010182610148565b634e487b7160e01b5f52602260045260245ffd5b91607f169161012b565b346100cf5760203660031901126100cf576001600160a01b036102406104e8565b165f525f602052602060405f2054604051908152f35b346100cf575f3660031901126100cf57602060405160128152f35b346100cf5760603660031901126100cf5761028a6104e8565b6102926104fe565b6001600160a01b0382165f818152600160209081526040808320338452909152902054909260443592915f1981106102d0575b506100f99350610514565b83811061033557841561032257331561030f576100f9945f52600160205260405f2060018060a01b0333165f526020528360405f2091039055846102c5565b634a1406b160e11b5f525f60045260245ffd5b63e602df0560e01b5f525f60045260245ffd5b8390637dc7a0d960e11b5f523360045260245260445260645ffd5b346100cf575f3660031901126100cf576020600254604051908152f35b346100cf5760403660031901126100cf576103866104e8565b602435903315610322576001600160a01b031690811561030f57335f52600160205260405f20825f526020528060405f20556040519081527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560203392a3602060405160018152f35b346100cf575f3660031901126100cf575f6003548060011c906001811680156104b4575b602083108114610201578285529081156101e5575060011461045f5750819003601f01601f191681019067ffffffffffffffff82118183101761017c57610178829182604052826104be565b905060035f527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b5f905b82821061049e57506020915082010182610148565b6001816020925483858801015201910190610489565b91607f1691610413565b602060409281835280519182918282860152018484015e5f828201840152601f01601f1916010190565b600435906001600160a01b03821682036100cf57565b602435906001600160a01b03821682036100cf57565b6001600160a01b03169081156105be576001600160a01b03169182156105ab57815f525f60205260405f205481811061059257817fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92602092855f525f84520360405f2055845f525f825260405f20818154019055604051908152a3565b8263391434e360e21b5f5260045260245260445260645ffd5b63ec442f0560e01b5f525f60045260245ffd5b634b637e8f60e11b5f525f60045260245ffdfea26469706673582212201a6a3a3237e854b17ceca01ed6af0bdbe39376282039344b36a11c73a3183a0164736f6c634300082100333156e57706371fe93e9988fd472f36cdf2f3e93a7a9b1a23d57c676731e2057fa26469706673582212209386ba9ed17eb663aec0afdbc7595febc3313205cd237128befc11fe0ecb3c3f64736f6c63430008210033

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

000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba30000000000000000000000000000000000000000000000004563918244f400000000000000000000000000000000000000000000000000008ac7230489e80000

-----Decoded View---------------
Arg [0] : _WETH (address): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
Arg [1] : _feeHolder (address): 0x0000000000000000000000000000000000000000
Arg [2] : _permit2 (address): 0x000000000022D473030F116dDEE9F6B43aC78BA3
Arg [3] : _virtualBaseReserve (uint256): 5000000000000000000
Arg [4] : _graduationThreshold (uint256): 10000000000000000000

-----Encoded View---------------
5 Constructor Arguments found :
Arg [0] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [2] : 000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba3
Arg [3] : 0000000000000000000000000000000000000000000000004563918244f40000
Arg [4] : 0000000000000000000000000000000000000000000000008ac7230489e80000


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.