ETH Price: $3,364.03 (-3.51%)

Contract

0x371A339D21A45d874F1399a4e060B6931f423e8c
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Swap And Increas...214836562024-12-26 2:28:236 hrs ago1735180103IN
0x371A339D...31f423e8c
0 ETH0.002125034.36889525
Swap And Increas...214819822024-12-25 20:50:1112 hrs ago1735159811IN
0x371A339D...31f423e8c
0 ETH0.003448995.75752283
Swap And Increas...214807642024-12-25 16:44:2316 hrs ago1735145063IN
0x371A339D...31f423e8c
0 ETH0.004405788.6550437
Swap And Increas...214807482024-12-25 16:41:1116 hrs ago1735144871IN
0x371A339D...31f423e8c
0 ETH0.004668849.12202747
Swap And Increas...214780392024-12-25 7:37:1125 hrs ago1735112231IN
0x371A339D...31f423e8c
0.037 ETH0.002341954.52963163
Swap And Mint214755142024-12-24 23:09:2333 hrs ago1735081763IN
0x371A339D...31f423e8c
0 ETH0.003085994.31378062
Swap And Increas...214690292024-12-24 1:23:472 days ago1735003427IN
0x371A339D...31f423e8c
0 ETH0.004473548.36681716
Swap And Increas...214686522024-12-24 0:07:232 days ago1734998843IN
0x371A339D...31f423e8c
0 ETH0.0073962911.9681009
Swap And Mint214672622024-12-23 19:26:472 days ago1734982007IN
0x371A339D...31f423e8c
0 ETH0.0110355915.06335548
Swap And Increas...214671742024-12-23 19:08:472 days ago1734980927IN
0x371A339D...31f423e8c
0 ETH0.0069705512.5
Swap And Increas...214657492024-12-23 14:21:592 days ago1734963719IN
0x371A339D...31f423e8c
8 ETH0.0171983232.23538805
Swap And Mint214633592024-12-23 6:20:113 days ago1734934811IN
0x371A339D...31f423e8c
0 ETH0.003097344.20175727
Swap And Mint214626632024-12-23 4:00:233 days ago1734926423IN
0x371A339D...31f423e8c
0 ETH0.003420544.32675388
Swap And Mint214590622024-12-22 15:54:353 days ago1734882875IN
0x371A339D...31f423e8c
2.44 ETH0.006568838.49883526
Swap And Mint214589762024-12-22 15:37:233 days ago1734881843IN
0x371A339D...31f423e8c
1.4 ETH0.006273758.3
Swap And Increas...214586112024-12-22 14:23:473 days ago1734877427IN
0x371A339D...31f423e8c
0 ETH0.006113797.71084829
Swap And Increas...214562142024-12-22 6:22:114 days ago1734848531IN
0x371A339D...31f423e8c
0 ETH0.003244025.94740564
Swap And Mint214497222024-12-21 8:34:595 days ago1734770099IN
0x371A339D...31f423e8c
0.42 ETH0.006462638.58208922
Swap And Mint214494532024-12-21 7:40:355 days ago1734766835IN
0x371A339D...31f423e8c
0 ETH0.00585937.48109066
Swap And Increas...214464322024-12-20 21:30:595 days ago1734730259IN
0x371A339D...31f423e8c
0 ETH0.0094958710.79767285
Swap And Mint214452332024-12-20 17:30:235 days ago1734715823IN
0x371A339D...31f423e8c
0 ETH0.0201998923.30476009
Swap And Mint214373682024-12-19 15:09:476 days ago1734620987IN
0x371A339D...31f423e8c
0 ETH0.0190852827.42276322
Swap And Mint214361382024-12-19 11:02:116 days ago1734606131IN
0x371A339D...31f423e8c
0 ETH0.0145789717.70756158
Swap And Increas...214347202024-12-19 6:16:237 days ago1734588983IN
0x371A339D...31f423e8c
0 ETH0.0058580512.22578368
Swap And Increas...214291222024-12-18 11:28:477 days ago1734521327IN
0x371A339D...31f423e8c
1 ETH0.0112166220.11510698
View all transactions

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block
From
To
214780392024-12-25 7:37:1125 hrs ago1735112231
0x371A339D...31f423e8c
0.037 ETH
214727722024-12-24 13:57:4743 hrs ago1735048667
0x371A339D...31f423e8c
0.15370738 ETH
214727722024-12-24 13:57:4743 hrs ago1735048667
0x371A339D...31f423e8c
0.15370738 ETH
214723602024-12-24 12:34:4744 hrs ago1735043687
0x371A339D...31f423e8c
2.07231639 ETH
214723602024-12-24 12:34:4744 hrs ago1735043687
0x371A339D...31f423e8c
2.07231639 ETH
214657492024-12-23 14:21:592 days ago1734963719
0x371A339D...31f423e8c
0.04512637 ETH
214657492024-12-23 14:21:592 days ago1734963719
0x371A339D...31f423e8c
0.04512637 ETH
214657492024-12-23 14:21:592 days ago1734963719
0x371A339D...31f423e8c
8 ETH
214590622024-12-22 15:54:353 days ago1734882875
0x371A339D...31f423e8c
0.01270341 ETH
214590622024-12-22 15:54:353 days ago1734882875
0x371A339D...31f423e8c
0.01270341 ETH
214590622024-12-22 15:54:353 days ago1734882875
0x371A339D...31f423e8c
2.44 ETH
214589762024-12-22 15:37:233 days ago1734881843
0x371A339D...31f423e8c
0.00179268 ETH
214589762024-12-22 15:37:233 days ago1734881843
0x371A339D...31f423e8c
0.00179268 ETH
214589762024-12-22 15:37:233 days ago1734881843
0x371A339D...31f423e8c
1.4 ETH
214505952024-12-21 11:30:234 days ago1734780623
0x371A339D...31f423e8c
3.74009197 ETH
214505952024-12-21 11:30:234 days ago1734780623
0x371A339D...31f423e8c
3.74009197 ETH
214497222024-12-21 8:34:595 days ago1734770099
0x371A339D...31f423e8c
0.00038993 ETH
214497222024-12-21 8:34:595 days ago1734770099
0x371A339D...31f423e8c
0.00038993 ETH
214497222024-12-21 8:34:595 days ago1734770099
0x371A339D...31f423e8c
0.42 ETH
214380142024-12-19 17:19:236 days ago1734628763
0x371A339D...31f423e8c
0.00073659 ETH
214380142024-12-19 17:19:236 days ago1734628763
0x371A339D...31f423e8c
0.00073659 ETH
214374072024-12-19 15:17:356 days ago1734621455
0x371A339D...31f423e8c
3.70875847 ETH
214374072024-12-19 15:17:356 days ago1734621455
0x371A339D...31f423e8c
3.70875847 ETH
214291222024-12-18 11:28:477 days ago1734521327
0x371A339D...31f423e8c
0.00585191 ETH
214291222024-12-18 11:28:477 days ago1734521327
0x371A339D...31f423e8c
0.00585191 ETH
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
V3Utils

Compiler Version
v0.8.24+commit.e11b9ed9

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion
File 1 of 42 : V3Utils.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import "@openzeppelin/contracts/utils/math/SafeCast.sol";

import "permit2/interfaces/IPermit2.sol";

import "../utils/Swapper.sol";
import "../transformers/Transformer.sol";

/// @title v3Utils v1.1
/// @notice Utility functions for Uniswap V3 positions
/// It does not hold any ERC20 or NFTs.
/// It can be simply redeployed when new / better functionality is implemented
contract V3Utils is Transformer, Swapper, IERC721Receiver {
    using SafeCast for uint256;

    // @notice Permit2 contract
    IPermit2 public immutable permit2;

    // events
    event CompoundFees(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
    event ChangeRange(uint256 indexed tokenId, uint256 newTokenId);
    event WithdrawAndCollectAndSwap(uint256 indexed tokenId, address token, uint256 amount);
    event SwapAndMint(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
    event SwapAndIncreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);

    /// @notice Constructor
    /// @param _nonfungiblePositionManager Uniswap v3 position manager
    /// @param _zeroxRouter 0x Exchange Proxy
    constructor(
        INonfungiblePositionManager _nonfungiblePositionManager,
        address _zeroxRouter,
        address _universalRouter,
        address _permit2
    ) Swapper(_nonfungiblePositionManager, _zeroxRouter, _universalRouter) {
        permit2 = IPermit2(_permit2);
    }

    /// @notice Action which should be executed on provided NFT
    enum WhatToDo {
        CHANGE_RANGE,
        WITHDRAW_AND_COLLECT_AND_SWAP,
        COMPOUND_FEES
    }

    /// @notice Complete description of what should be executed on provided NFT - different fields are used depending on specified WhatToDo
    struct Instructions {
        // what action to perform on provided Uniswap v3 position
        WhatToDo whatToDo;
        // target token for swaps (if this is address(0) no swaps are executed)
        address targetToken;
        // for removing liquidity slippage
        uint256 amountRemoveMin0;
        uint256 amountRemoveMin1;
        // amountIn0 is used for swap and also as minAmount0 for decreased liquidity + collected fees
        uint256 amountIn0;
        // if token0 needs to be swapped to targetToken - set values
        uint256 amountOut0Min;
        bytes swapData0; // encoded data from 0x api call (address,bytes) - allowanceTarget,data
        // amountIn1 is used for swap and also as minAmount1 for decreased liquidity + collected fees
        uint256 amountIn1;
        // if token1 needs to be swapped to targetToken - set values
        uint256 amountOut1Min;
        bytes swapData1; // encoded data from 0x api call (address,bytes) - allowanceTarget,data
        // collect fee amount for COMPOUND_FEES / CHANGE_RANGE / WITHDRAW_AND_COLLECT_AND_SWAP (if uint256(128).max - ALL)
        uint128 feeAmount0;
        uint128 feeAmount1;
        // for creating new positions with CHANGE_RANGE
        uint24 fee;
        int24 tickLower;
        int24 tickUpper;
        // remove liquidity amount for COMPOUND_FEES (in this case should be probably 0) / CHANGE_RANGE / WITHDRAW_AND_COLLECT_AND_SWAP
        uint128 liquidity;
        // for adding liquidity slippage
        uint256 amountAddMin0;
        uint256 amountAddMin1;
        // for all uniswap deadlineable functions
        uint256 deadline;
        // left over tokens will be sent to this address
        address recipient;
        // recipient of newly minted nft (the incoming NFT will ALWAYS be returned to from)
        address recipientNFT;
        // if tokenIn or tokenOut is WETH - unwrap
        bool unwrap;
        // data sent with returned token to IERC721Receiver (optional)
        bytes returnData;
        // data sent with minted token to IERC721Receiver (optional)
        bytes swapAndMintReturnData;
    }

    /// @notice Execute instruction with EIP712 permit
    /// @param tokenId Token to process
    /// @param instructions Instructions to execute
    /// @param v Signature values for EIP712 permit
    /// @param r Signature values for EIP712 permit
    /// @param s Signature values for EIP712 permit
    /// @return newTokenId Id of position (if a new one was created)
    function executeWithPermit(uint256 tokenId, Instructions memory instructions, uint8 v, bytes32 r, bytes32 s)
        public
        returns (uint256 newTokenId)
    {
        if (nonfungiblePositionManager.ownerOf(tokenId) != msg.sender) {
            revert Unauthorized();
        }

        nonfungiblePositionManager.permit(address(this), tokenId, instructions.deadline, v, r, s);
        return execute(tokenId, instructions);

        // NOTE: previous operator can not be reset as operator set by permit can not change operator - so this operator will stay until reset
    }

    /// @notice ERC721 callback function. Called on safeTransferFrom and does manipulation as configured in encoded Instructions parameter.
    /// At the end the NFT (and any newly minted NFT) is returned to sender. The leftover tokens are sent to instructions.recipient.
    function onERC721Received(address, /*operator*/ address from, uint256 tokenId, bytes calldata data)
        external
        override
        returns (bytes4)
    {
        // only Uniswap v3 NFTs allowed
        if (msg.sender != address(nonfungiblePositionManager)) {
            revert WrongContract();
        }

        // not allowed to send to itself
        if (from == address(this)) {
            revert SelfSend();
        }

        Instructions memory instructions = abi.decode(data, (Instructions));

        execute(tokenId, instructions);

        // return token to owner (this line guarantees that token is returned to originating owner)
        nonfungiblePositionManager.safeTransferFrom(address(this), from, tokenId, instructions.returnData);

        return IERC721Receiver.onERC721Received.selector;
    }

    /// @notice Execute instruction by pulling approved NFT instead of direct safeTransferFrom call from owner
    /// @param tokenId Token to process
    /// @param instructions Instructions to execute
    /// @return newTokenId Id of position (if a new one was created)
    function execute(uint256 tokenId, Instructions memory instructions) public returns (uint256 newTokenId) {
        _validateCaller(nonfungiblePositionManager, tokenId);

        (,, address token0, address token1,,,, uint128 liquidity,,,,) = nonfungiblePositionManager.positions(tokenId);

        uint256 amount0;
        uint256 amount1;
        if (instructions.liquidity != 0) {
            (amount0, amount1) = _decreaseLiquidity(
                tokenId,
                instructions.liquidity,
                instructions.deadline,
                instructions.amountRemoveMin0,
                instructions.amountRemoveMin1
            );
        }
        (amount0, amount1) = _collectFees(
            tokenId,
            IERC20(token0),
            IERC20(token1),
            instructions.feeAmount0 == type(uint128).max
                ? type(uint128).max
                : (amount0 + instructions.feeAmount0).toUint128(),
            instructions.feeAmount1 == type(uint128).max
                ? type(uint128).max
                : (amount1 + instructions.feeAmount1).toUint128()
        );

        // check if enough tokens are available for swaps
        if (amount0 < instructions.amountIn0 || amount1 < instructions.amountIn1) {
            revert AmountError();
        }

        if (instructions.whatToDo == WhatToDo.COMPOUND_FEES) {
            if (instructions.targetToken == token0) {
                (liquidity, amount0, amount1) = _swapAndIncrease(
                    SwapAndIncreaseLiquidityParams(
                        tokenId,
                        amount0,
                        amount1,
                        instructions.recipient,
                        instructions.deadline,
                        IERC20(token1),
                        instructions.amountIn1,
                        instructions.amountOut1Min,
                        instructions.swapData1,
                        0,
                        0,
                        "",
                        instructions.amountAddMin0,
                        instructions.amountAddMin1,
                        ""
                    ),
                    IERC20(token0),
                    IERC20(token1),
                    instructions.unwrap
                );
            } else if (instructions.targetToken == token1) {
                (liquidity, amount0, amount1) = _swapAndIncrease(
                    SwapAndIncreaseLiquidityParams(
                        tokenId,
                        amount0,
                        amount1,
                        instructions.recipient,
                        instructions.deadline,
                        IERC20(token0),
                        0,
                        0,
                        "",
                        instructions.amountIn0,
                        instructions.amountOut0Min,
                        instructions.swapData0,
                        instructions.amountAddMin0,
                        instructions.amountAddMin1,
                        ""
                    ),
                    IERC20(token0),
                    IERC20(token1),
                    instructions.unwrap
                );
            } else {
                // no swap is done here
                (liquidity, amount0, amount1) = _swapAndIncrease(
                    SwapAndIncreaseLiquidityParams(
                        tokenId,
                        amount0,
                        amount1,
                        instructions.recipient,
                        instructions.deadline,
                        IERC20(address(0)),
                        0,
                        0,
                        "",
                        0,
                        0,
                        "",
                        instructions.amountAddMin0,
                        instructions.amountAddMin1,
                        ""
                    ),
                    IERC20(token0),
                    IERC20(token1),
                    instructions.unwrap
                );
            }
            emit CompoundFees(tokenId, liquidity, amount0, amount1);
        } else if (instructions.whatToDo == WhatToDo.CHANGE_RANGE) {
            if (instructions.targetToken == token0) {
                (newTokenId,,,) = _swapAndMint(
                    SwapAndMintParams(
                        IERC20(token0),
                        IERC20(token1),
                        instructions.fee,
                        instructions.tickLower,
                        instructions.tickUpper,
                        amount0,
                        amount1,
                        instructions.recipient,
                        instructions.recipientNFT,
                        instructions.deadline,
                        IERC20(token1),
                        instructions.amountIn1,
                        instructions.amountOut1Min,
                        instructions.swapData1,
                        0,
                        0,
                        "",
                        instructions.amountAddMin0,
                        instructions.amountAddMin1,
                        instructions.swapAndMintReturnData,
                        ""
                    ),
                    instructions.unwrap
                );
            } else if (instructions.targetToken == token1) {
                (newTokenId,,,) = _swapAndMint(
                    SwapAndMintParams(
                        IERC20(token0),
                        IERC20(token1),
                        instructions.fee,
                        instructions.tickLower,
                        instructions.tickUpper,
                        amount0,
                        amount1,
                        instructions.recipient,
                        instructions.recipientNFT,
                        instructions.deadline,
                        IERC20(token0),
                        0,
                        0,
                        "",
                        instructions.amountIn0,
                        instructions.amountOut0Min,
                        instructions.swapData0,
                        instructions.amountAddMin0,
                        instructions.amountAddMin1,
                        instructions.swapAndMintReturnData,
                        ""
                    ),
                    instructions.unwrap
                );
            } else {
                // no swap is done here
                (newTokenId,,,) = _swapAndMint(
                    SwapAndMintParams(
                        IERC20(token0),
                        IERC20(token1),
                        instructions.fee,
                        instructions.tickLower,
                        instructions.tickUpper,
                        amount0,
                        amount1,
                        instructions.recipient,
                        instructions.recipientNFT,
                        instructions.deadline,
                        IERC20(address(0)),
                        0,
                        0,
                        "",
                        0,
                        0,
                        "",
                        instructions.amountAddMin0,
                        instructions.amountAddMin1,
                        instructions.swapAndMintReturnData,
                        ""
                    ),
                    instructions.unwrap
                );
            }
            emit ChangeRange(tokenId, newTokenId);
        } else if (instructions.whatToDo == WhatToDo.WITHDRAW_AND_COLLECT_AND_SWAP) {
            uint256 targetAmount;
            if (token0 != instructions.targetToken) {
                (uint256 amountInDelta, uint256 amountOutDelta) = _routerSwap(
                    Swapper.RouterSwapParams(
                        IERC20(token0),
                        IERC20(instructions.targetToken),
                        amount0,
                        instructions.amountOut0Min,
                        instructions.swapData0
                    )
                );
                if (amountInDelta < amount0) {
                    _transferToken(instructions.recipient, IERC20(token0), amount0 - amountInDelta, instructions.unwrap);
                }
                targetAmount += amountOutDelta;
            } else {
                targetAmount += amount0;
            }
            if (token1 != instructions.targetToken) {
                (uint256 amountInDelta, uint256 amountOutDelta) = _routerSwap(
                    Swapper.RouterSwapParams(
                        IERC20(token1),
                        IERC20(instructions.targetToken),
                        amount1,
                        instructions.amountOut1Min,
                        instructions.swapData1
                    )
                );
                if (amountInDelta < amount1) {
                    _transferToken(instructions.recipient, IERC20(token1), amount1 - amountInDelta, instructions.unwrap);
                }
                targetAmount += amountOutDelta;
            } else {
                targetAmount += amount1;
            }

            // send complete target amount
            if (targetAmount != 0 && instructions.targetToken != address(0)) {
                _transferToken(
                    instructions.recipient, IERC20(instructions.targetToken), targetAmount, instructions.unwrap
                );
            }

            emit WithdrawAndCollectAndSwap(tokenId, instructions.targetToken, targetAmount);
        } else {
            revert NotSupportedWhatToDo();
        }
    }

    /// @notice Params for swap() function
    struct SwapParams {
        IERC20 tokenIn;
        IERC20 tokenOut;
        uint256 amountIn;
        uint256 minAmountOut;
        address recipient; // recipient of tokenOut and leftover tokenIn (if any leftover)
        bytes swapData;
        bool unwrap; // if tokenIn or tokenOut is WETH - unwrap
        bytes permitData; // if permit2 signatures are used - set this
    }

    /// @notice Swaps amountIn of tokenIn for tokenOut - returning at least minAmountOut
    /// @param params Swap configuration
    /// @return amountOut Output amount of tokenOut
    /// If tokenIn is wrapped native token - both the token or the wrapped token can be sent (the sum of both must be equal to amountIn)
    /// Optionally unwraps any wrapped native token and returns native token instead
    function swap(SwapParams calldata params) external payable returns (uint256 amountOut) {
        if (params.tokenIn == params.tokenOut) {
            revert SameToken();
        }

        if (params.permitData.length != 0) {
            (ISignatureTransfer.PermitBatchTransferFrom memory pbtf, bytes memory signature) =
                abi.decode(params.permitData, (ISignatureTransfer.PermitBatchTransferFrom, bytes));
            _prepareAddPermit2(
                params.tokenIn, IERC20(address(0)), IERC20(address(0)), params.amountIn, 0, 0, pbtf, signature
            );
        } else {
            _prepareAddApproved(params.tokenIn, IERC20(address(0)), IERC20(address(0)), params.amountIn, 0, 0);
        }

        uint256 amountInDelta;
        (amountInDelta, amountOut) = _routerSwap(
            Swapper.RouterSwapParams(
                params.tokenIn, params.tokenOut, params.amountIn, params.minAmountOut, params.swapData
            )
        );

        // send swapped amount of tokenOut
        if (amountOut != 0) {
            _transferToken(params.recipient, params.tokenOut, amountOut, params.unwrap);
        }

        // if not all was swapped - return leftovers of tokenIn
        uint256 leftOver = params.amountIn - amountInDelta;
        if (leftOver != 0) {
            _transferToken(params.recipient, params.tokenIn, leftOver, params.unwrap);
        }
    }

    /// @notice Params for swapAndMint() function
    struct SwapAndMintParams {
        IERC20 token0;
        IERC20 token1;
        uint24 fee;
        int24 tickLower;
        int24 tickUpper;
        // how much is provided of token0 and token1
        uint256 amount0;
        uint256 amount1;
        address recipient; // recipient of leftover tokens
        address recipientNFT; // recipient of nft
        uint256 deadline;
        // source token for swaps (maybe either address(0), token0, token1 or another token)
        // if swapSourceToken is another token than token0 or token1 -> amountIn0 + amountIn1 of swapSourceToken are expected to be available
        IERC20 swapSourceToken;
        // if swapSourceToken needs to be swapped to token0 - set values
        uint256 amountIn0;
        uint256 amountOut0Min;
        bytes swapData0;
        // if swapSourceToken needs to be swapped to token1 - set values
        uint256 amountIn1;
        uint256 amountOut1Min;
        bytes swapData1;
        // min amount to be added after swap
        uint256 amountAddMin0;
        uint256 amountAddMin1;
        // data to be sent along newly created NFT when transfered to recipientNFT (sent to IERC721Receiver callback)
        bytes returnData;
        // if permit2 signatures are used - set this
        bytes permitData;
    }

    /// @notice Does 1 or 2 swaps from swapSourceToken to token0 and token1 and adds as much as possible liquidity to a newly minted position. Newly minted NFT and leftover tokens are returned to recipient.
    /// @param params Swap and mint configuration
    /// @return tokenId The ID of the token that represents the minted position
    /// @return liquidity The amount of liquidity for this position
    /// @return amount0 The amount of token0
    /// @return amount1 The amount of token1
    function swapAndMint(SwapAndMintParams calldata params)
        external
        payable
        returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1)
    {
        if (params.token0 == params.token1) {
            revert SameToken();
        }

        if (params.permitData.length != 0) {
            (ISignatureTransfer.PermitBatchTransferFrom memory pbtf, bytes memory signature) =
                abi.decode(params.permitData, (ISignatureTransfer.PermitBatchTransferFrom, bytes));
            _prepareAddPermit2(
                params.token0,
                params.token1,
                params.swapSourceToken,
                params.amount0,
                params.amount1,
                params.amountIn0 + params.amountIn1,
                pbtf,
                signature
            );
        } else {
            _prepareAddApproved(
                params.token0,
                params.token1,
                params.swapSourceToken,
                params.amount0,
                params.amount1,
                params.amountIn0 + params.amountIn1
            );
        }

        (tokenId, liquidity, amount0, amount1) = _swapAndMint(params, msg.value != 0);
    }

    /// @notice Params for swapAndIncreaseLiquidity() function
    struct SwapAndIncreaseLiquidityParams {
        uint256 tokenId;
        // how much is provided of token0 and token1
        uint256 amount0;
        uint256 amount1;
        address recipient; // recipient of leftover tokens
        uint256 deadline;
        // source token for swaps (maybe either address(0), token0, token1 or another token)
        // if swapSourceToken is another token than token0 or token1 -> amountIn0 + amountIn1 of swapSourceToken are expected to be available
        IERC20 swapSourceToken;
        // if swapSourceToken needs to be swapped to token0 - set values
        uint256 amountIn0;
        uint256 amountOut0Min;
        bytes swapData0;
        // if swapSourceToken needs to be swapped to token1 - set values
        uint256 amountIn1;
        uint256 amountOut1Min;
        bytes swapData1;
        // min amount to be added after swap
        uint256 amountAddMin0;
        uint256 amountAddMin1;
        // if permit2 signatures are used - set this
        bytes permitData;
    }

    /// @notice Does 1 or 2 swaps from swapSourceToken to token0 and token1 and adds as much as possible liquidity to any existing position (no need to be position owner). Sends any leftover tokens to recipient.
    /// @param params Swap and increase liquidity configuration
    /// @return liquidity The amount of liquidity added
    /// @return amount0 The amount of token0 added
    /// @return amount1 The amount of token1 added
    function swapAndIncreaseLiquidity(SwapAndIncreaseLiquidityParams calldata params)
        external
        payable
        returns (uint128 liquidity, uint256 amount0, uint256 amount1)
    {
        (,, address token0, address token1,,,,,,,,) = nonfungiblePositionManager.positions(params.tokenId);

        if (params.permitData.length != 0) {
            (ISignatureTransfer.PermitBatchTransferFrom memory pbtf, bytes memory signature) =
                abi.decode(params.permitData, (ISignatureTransfer.PermitBatchTransferFrom, bytes));
            _prepareAddPermit2(
                IERC20(token0),
                IERC20(token1),
                params.swapSourceToken,
                params.amount0,
                params.amount1,
                params.amountIn0 + params.amountIn1,
                pbtf,
                signature
            );
        } else {
            _prepareAddApproved(
                IERC20(token0),
                IERC20(token1),
                params.swapSourceToken,
                params.amount0,
                params.amount1,
                params.amountIn0 + params.amountIn1
            );
        }

        (liquidity, amount0, amount1) = _swapAndIncrease(params, IERC20(token0), IERC20(token1), msg.value != 0);
    }

    function _prepareAddApproved(
        IERC20 token0,
        IERC20 token1,
        IERC20 otherToken,
        uint256 amount0,
        uint256 amount1,
        uint256 amountOther
    ) internal {
        (uint256 needed0, uint256 needed1, uint256 neededOther) =
            _prepareAdd(token0, token1, otherToken, amount0, amount1, amountOther);

        if (needed0 != 0) {
            SafeERC20.safeTransferFrom(token0, msg.sender, address(this), needed0);
        }
        if (needed1 != 0) {
            SafeERC20.safeTransferFrom(token1, msg.sender, address(this), needed1);
        }
        if (neededOther != 0) {
            SafeERC20.safeTransferFrom(otherToken, msg.sender, address(this), neededOther);
        }
    }

    struct PrepareAddPermit2State {
        uint256 needed0;
        uint256 needed1;
        uint256 neededOther;
        uint256 i;
        uint256 balanceBefore0;
        uint256 balanceBefore1;
        uint256 balanceBeforeOther;
    }

    function _prepareAddPermit2(
        IERC20 token0,
        IERC20 token1,
        IERC20 otherToken,
        uint256 amount0,
        uint256 amount1,
        uint256 amountOther,
        IPermit2.PermitBatchTransferFrom memory permit,
        bytes memory signature
    ) internal {
        PrepareAddPermit2State memory state;

        (state.needed0, state.needed1, state.neededOther) =
            _prepareAdd(token0, token1, otherToken, amount0, amount1, amountOther);

        ISignatureTransfer.SignatureTransferDetails[] memory transferDetails =
            new ISignatureTransfer.SignatureTransferDetails[](permit.permitted.length);

        // permitted tokens must be in this same order
        if (state.needed0 != 0) {
            state.balanceBefore0 = token0.balanceOf(address(this));
            transferDetails[state.i++] = ISignatureTransfer.SignatureTransferDetails(address(this), state.needed0);
        }
        if (state.needed1 != 0) {
            state.balanceBefore1 = token1.balanceOf(address(this));
            transferDetails[state.i++] = ISignatureTransfer.SignatureTransferDetails(address(this), state.needed1);
        }
        if (state.neededOther != 0) {
            state.balanceBeforeOther = otherToken.balanceOf(address(this));
            transferDetails[state.i++] = ISignatureTransfer.SignatureTransferDetails(address(this), state.neededOther);
        }

        // execute batch transfer
        permit2.permitTransferFrom(permit, transferDetails, msg.sender, signature);

        // check if recieved correct amount of tokens
        if (state.needed0 != 0) {
            if (token0.balanceOf(address(this)) - state.balanceBefore0 != state.needed0) {
                revert TransferError(); // reverts for fee-on-transfer tokens
            }
        }
        if (state.needed1 != 0) {
            if (token1.balanceOf(address(this)) - state.balanceBefore1 != state.needed1) {
                revert TransferError(); // reverts for fee-on-transfer tokens
            }
        }
        if (state.neededOther != 0) {
            if (otherToken.balanceOf(address(this)) - state.balanceBeforeOther != state.neededOther) {
                revert TransferError(); // reverts for fee-on-transfer tokens
            }
        }
    }

    // checks if required amounts are provided and are exact - wraps any provided ETH as WETH
    // if less or more provided reverts
    function _prepareAdd(
        IERC20 token0,
        IERC20 token1,
        IERC20 otherToken,
        uint256 amount0,
        uint256 amount1,
        uint256 amountOther
    ) internal returns (uint256 needed0, uint256 needed1, uint256 neededOther) {
        uint256 amountAdded0;
        uint256 amountAdded1;
        uint256 amountAddedOther;

        // wrap ether sent
        if (msg.value != 0) {
            weth.deposit{value: msg.value}();

            if (address(weth) == address(token0)) {
                amountAdded0 = msg.value;
                if (amountAdded0 > amount0) {
                    revert TooMuchEtherSent();
                }
            } else if (address(weth) == address(token1)) {
                amountAdded1 = msg.value;
                if (amountAdded1 > amount1) {
                    revert TooMuchEtherSent();
                }
            } else if (address(weth) == address(otherToken)) {
                amountAddedOther = msg.value;
                if (amountAddedOther > amountOther) {
                    revert TooMuchEtherSent();
                }
            } else {
                revert NoEtherToken();
            }
        }

        // calculate missing token amounts
        if (amount0 > amountAdded0) {
            needed0 = amount0 - amountAdded0;
        }
        if (amount1 > amountAdded1) {
            needed1 = amount1 - amountAdded1;
        }
        if (
            amountOther > amountAddedOther && address(otherToken) != address(0) && token0 != otherToken
                && token1 != otherToken
        ) {
            neededOther = amountOther - amountAddedOther;
        }
    }

    // swap and mint logic
    function _swapAndMint(SwapAndMintParams memory params, bool unwrap)
        internal
        returns (uint256 tokenId, uint128 liquidity, uint256 added0, uint256 added1)
    {
        (uint256 total0, uint256 total1) = _swapAndPrepareAmounts(params, unwrap);

        INonfungiblePositionManager.MintParams memory mintParams = INonfungiblePositionManager.MintParams(
            address(params.token0),
            address(params.token1),
            params.fee,
            params.tickLower,
            params.tickUpper,
            total0,
            total1,
            params.amountAddMin0,
            params.amountAddMin1,
            address(this), // is sent to real recipient aftwards
            params.deadline
        );

        // mint is done to address(this) because it is not a safemint and safeTransferFrom needs to be done manually afterwards
        (tokenId, liquidity, added0, added1) = nonfungiblePositionManager.mint(mintParams);
        nonfungiblePositionManager.safeTransferFrom(address(this), params.recipientNFT, tokenId, params.returnData);

        emit SwapAndMint(tokenId, liquidity, added0, added1);

        _returnLeftoverTokens(params.recipient, params.token0, params.token1, total0, total1, added0, added1, unwrap);
    }

    // swap and increase logic
    function _swapAndIncrease(SwapAndIncreaseLiquidityParams memory params, IERC20 token0, IERC20 token1, bool unwrap)
        internal
        returns (uint128 liquidity, uint256 added0, uint256 added1)
    {
        (uint256 total0, uint256 total1) = _swapAndPrepareAmounts(
            SwapAndMintParams(
                token0,
                token1,
                0,
                0,
                0,
                params.amount0,
                params.amount1,
                params.recipient,
                params.recipient,
                params.deadline,
                params.swapSourceToken,
                params.amountIn0,
                params.amountOut0Min,
                params.swapData0,
                params.amountIn1,
                params.amountOut1Min,
                params.swapData1,
                params.amountAddMin0,
                params.amountAddMin1,
                "",
                params.permitData
            ),
            unwrap
        );

        INonfungiblePositionManager.IncreaseLiquidityParams memory increaseLiquidityParams = INonfungiblePositionManager
            .IncreaseLiquidityParams(
            params.tokenId, total0, total1, params.amountAddMin0, params.amountAddMin1, params.deadline
        );

        (liquidity, added0, added1) = nonfungiblePositionManager.increaseLiquidity(increaseLiquidityParams);

        emit SwapAndIncreaseLiquidity(params.tokenId, liquidity, added0, added1);

        _returnLeftoverTokens(params.recipient, token0, token1, total0, total1, added0, added1, unwrap);
    }

    // swaps available tokens and prepares max amounts to be added to nonfungiblePositionManager
    function _swapAndPrepareAmounts(SwapAndMintParams memory params, bool unwrap)
        internal
        returns (uint256 total0, uint256 total1)
    {
        if (params.swapSourceToken == params.token0) {
            if (params.amount0 < params.amountIn1) {
                revert AmountError();
            }
            (uint256 amountInDelta, uint256 amountOutDelta) = _routerSwap(
                Swapper.RouterSwapParams(
                    params.token0, params.token1, params.amountIn1, params.amountOut1Min, params.swapData1
                )
            );
            total0 = params.amount0 - amountInDelta;
            total1 = params.amount1 + amountOutDelta;
        } else if (params.swapSourceToken == params.token1) {
            if (params.amount1 < params.amountIn0) {
                revert AmountError();
            }
            (uint256 amountInDelta, uint256 amountOutDelta) = _routerSwap(
                Swapper.RouterSwapParams(
                    params.token1, params.token0, params.amountIn0, params.amountOut0Min, params.swapData0
                )
            );
            total1 = params.amount1 - amountInDelta;
            total0 = params.amount0 + amountOutDelta;
        } else if (address(params.swapSourceToken) != address(0)) {
            (uint256 amountInDelta0, uint256 amountOutDelta0) = _routerSwap(
                Swapper.RouterSwapParams(
                    params.swapSourceToken, params.token0, params.amountIn0, params.amountOut0Min, params.swapData0
                )
            );
            (uint256 amountInDelta1, uint256 amountOutDelta1) = _routerSwap(
                Swapper.RouterSwapParams(
                    params.swapSourceToken, params.token1, params.amountIn1, params.amountOut1Min, params.swapData1
                )
            );
            total0 = params.amount0 + amountOutDelta0;
            total1 = params.amount1 + amountOutDelta1;

            // return third token leftover if any
            uint256 leftOver = params.amountIn0 + params.amountIn1 - amountInDelta0 - amountInDelta1;

            if (leftOver != 0) {
                _transferToken(params.recipient, params.swapSourceToken, leftOver, unwrap);
            }
        } else {
            total0 = params.amount0;
            total1 = params.amount1;
        }

        if (total0 != 0) {
            SafeERC20.safeApprove(params.token0, address(nonfungiblePositionManager), 0);
            SafeERC20.safeIncreaseAllowance(params.token0, address(nonfungiblePositionManager), total0);
        }
        if (total1 != 0) {
            SafeERC20.safeApprove(params.token1, address(nonfungiblePositionManager), 0);
            SafeERC20.safeIncreaseAllowance(params.token1, address(nonfungiblePositionManager), total1);
        }
    }

    // returns leftover token balances
    function _returnLeftoverTokens(
        address to,
        IERC20 token0,
        IERC20 token1,
        uint256 total0,
        uint256 total1,
        uint256 added0,
        uint256 added1,
        bool unwrap
    ) internal {
        uint256 left0 = total0 - added0;
        uint256 left1 = total1 - added1;

        // return leftovers
        if (left0 != 0) {
            _transferToken(to, token0, left0, unwrap);
        }
        if (left1 != 0) {
            _transferToken(to, token1, left1, unwrap);
        }
    }

    // transfers token (or unwraps WETH and sends ETH)
    function _transferToken(address to, IERC20 token, uint256 amount, bool unwrap) internal {
        if (unwrap && address(weth) == address(token)) {
            weth.withdraw(amount);
            (bool sent,) = to.call{value: amount}("");
            if (!sent) {
                revert EtherSendFailed();
            }
        } else {
            SafeERC20.safeTransfer(token, to, amount);
        }
    }

    // decreases liquidity from uniswap v3 position
    function _decreaseLiquidity(
        uint256 tokenId,
        uint128 liquidity,
        uint256 deadline,
        uint256 token0Min,
        uint256 token1Min
    ) internal returns (uint256 amount0, uint256 amount1) {
        if (liquidity != 0) {
            (amount0, amount1) = nonfungiblePositionManager.decreaseLiquidity(
                INonfungiblePositionManager.DecreaseLiquidityParams(tokenId, liquidity, token0Min, token1Min, deadline)
            );
        }
    }

    // collects specified amount of fees from uniswap v3 position
    function _collectFees(uint256 tokenId, IERC20 token0, IERC20 token1, uint128 collectAmount0, uint128 collectAmount1)
        internal
        returns (uint256 amount0, uint256 amount1)
    {
        uint256 balanceBefore0 = token0.balanceOf(address(this));
        uint256 balanceBefore1 = token1.balanceOf(address(this));
        (amount0, amount1) = nonfungiblePositionManager.collect(
            INonfungiblePositionManager.CollectParams(tokenId, address(this), collectAmount0, collectAmount1)
        );
        uint256 balanceAfter0 = token0.balanceOf(address(this));
        uint256 balanceAfter1 = token1.balanceOf(address(this));

        // reverts for fee-on-transfer tokens
        if (balanceAfter0 - balanceBefore0 != amount0) {
            revert CollectError();
        }
        if (balanceAfter1 - balanceBefore1 != amount1) {
            revert CollectError();
        }
    }

    // needed for WETH unwrapping
    receive() external payable {
        if (msg.sender != address(weth)) {
            revert NotWETH();
        }
    }
}

File 2 of 42 : IERC721Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)

pragma solidity ^0.8.0;

/**
 * @title ERC721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC721 asset contracts.
 */
interface IERC721Receiver {
    /**
     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
     * by `operator` from `from`, this function is called.
     *
     * It must return its Solidity selector to confirm the token transfer.
     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
     *
     * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}

File 3 of 42 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.

pragma solidity ^0.8.0;

/**
 * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 *
 * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
 * all math on `uint256` and `int256` and then downcasting.
 */
library SafeCast {
    /**
     * @dev Returns the downcasted uint248 from uint256, reverting on
     * overflow (when the input is greater than largest uint248).
     *
     * Counterpart to Solidity's `uint248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
        return uint248(value);
    }

    /**
     * @dev Returns the downcasted uint240 from uint256, reverting on
     * overflow (when the input is greater than largest uint240).
     *
     * Counterpart to Solidity's `uint240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     *
     * _Available since v4.7._
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
        return uint240(value);
    }

    /**
     * @dev Returns the downcasted uint232 from uint256, reverting on
     * overflow (when the input is greater than largest uint232).
     *
     * Counterpart to Solidity's `uint232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     *
     * _Available since v4.7._
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
        return uint232(value);
    }

    /**
     * @dev Returns the downcasted uint224 from uint256, reverting on
     * overflow (when the input is greater than largest uint224).
     *
     * Counterpart to Solidity's `uint224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     *
     * _Available since v4.2._
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
        return uint224(value);
    }

    /**
     * @dev Returns the downcasted uint216 from uint256, reverting on
     * overflow (when the input is greater than largest uint216).
     *
     * Counterpart to Solidity's `uint216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     *
     * _Available since v4.7._
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
        return uint216(value);
    }

    /**
     * @dev Returns the downcasted uint208 from uint256, reverting on
     * overflow (when the input is greater than largest uint208).
     *
     * Counterpart to Solidity's `uint208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     *
     * _Available since v4.7._
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
        return uint208(value);
    }

    /**
     * @dev Returns the downcasted uint200 from uint256, reverting on
     * overflow (when the input is greater than largest uint200).
     *
     * Counterpart to Solidity's `uint200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     *
     * _Available since v4.7._
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
        return uint200(value);
    }

    /**
     * @dev Returns the downcasted uint192 from uint256, reverting on
     * overflow (when the input is greater than largest uint192).
     *
     * Counterpart to Solidity's `uint192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     *
     * _Available since v4.7._
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
        return uint192(value);
    }

    /**
     * @dev Returns the downcasted uint184 from uint256, reverting on
     * overflow (when the input is greater than largest uint184).
     *
     * Counterpart to Solidity's `uint184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     *
     * _Available since v4.7._
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
        return uint184(value);
    }

    /**
     * @dev Returns the downcasted uint176 from uint256, reverting on
     * overflow (when the input is greater than largest uint176).
     *
     * Counterpart to Solidity's `uint176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     *
     * _Available since v4.7._
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
        return uint176(value);
    }

    /**
     * @dev Returns the downcasted uint168 from uint256, reverting on
     * overflow (when the input is greater than largest uint168).
     *
     * Counterpart to Solidity's `uint168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     *
     * _Available since v4.7._
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
        return uint168(value);
    }

    /**
     * @dev Returns the downcasted uint160 from uint256, reverting on
     * overflow (when the input is greater than largest uint160).
     *
     * Counterpart to Solidity's `uint160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     *
     * _Available since v4.7._
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
        return uint160(value);
    }

    /**
     * @dev Returns the downcasted uint152 from uint256, reverting on
     * overflow (when the input is greater than largest uint152).
     *
     * Counterpart to Solidity's `uint152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     *
     * _Available since v4.7._
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
        return uint152(value);
    }

    /**
     * @dev Returns the downcasted uint144 from uint256, reverting on
     * overflow (when the input is greater than largest uint144).
     *
     * Counterpart to Solidity's `uint144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     *
     * _Available since v4.7._
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
        return uint144(value);
    }

    /**
     * @dev Returns the downcasted uint136 from uint256, reverting on
     * overflow (when the input is greater than largest uint136).
     *
     * Counterpart to Solidity's `uint136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     *
     * _Available since v4.7._
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
        return uint136(value);
    }

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v2.5._
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint120 from uint256, reverting on
     * overflow (when the input is greater than largest uint120).
     *
     * Counterpart to Solidity's `uint120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     *
     * _Available since v4.7._
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
        return uint120(value);
    }

    /**
     * @dev Returns the downcasted uint112 from uint256, reverting on
     * overflow (when the input is greater than largest uint112).
     *
     * Counterpart to Solidity's `uint112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     *
     * _Available since v4.7._
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
        return uint112(value);
    }

    /**
     * @dev Returns the downcasted uint104 from uint256, reverting on
     * overflow (when the input is greater than largest uint104).
     *
     * Counterpart to Solidity's `uint104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     *
     * _Available since v4.7._
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
        return uint104(value);
    }

    /**
     * @dev Returns the downcasted uint96 from uint256, reverting on
     * overflow (when the input is greater than largest uint96).
     *
     * Counterpart to Solidity's `uint96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     *
     * _Available since v4.2._
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
        return uint96(value);
    }

    /**
     * @dev Returns the downcasted uint88 from uint256, reverting on
     * overflow (when the input is greater than largest uint88).
     *
     * Counterpart to Solidity's `uint88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     *
     * _Available since v4.7._
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
        return uint88(value);
    }

    /**
     * @dev Returns the downcasted uint80 from uint256, reverting on
     * overflow (when the input is greater than largest uint80).
     *
     * Counterpart to Solidity's `uint80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     *
     * _Available since v4.7._
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
        return uint80(value);
    }

    /**
     * @dev Returns the downcasted uint72 from uint256, reverting on
     * overflow (when the input is greater than largest uint72).
     *
     * Counterpart to Solidity's `uint72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
        return uint72(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v2.5._
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint56 from uint256, reverting on
     * overflow (when the input is greater than largest uint56).
     *
     * Counterpart to Solidity's `uint56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     *
     * _Available since v4.7._
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
        return uint56(value);
    }

    /**
     * @dev Returns the downcasted uint48 from uint256, reverting on
     * overflow (when the input is greater than largest uint48).
     *
     * Counterpart to Solidity's `uint48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     *
     * _Available since v4.7._
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
        return uint48(value);
    }

    /**
     * @dev Returns the downcasted uint40 from uint256, reverting on
     * overflow (when the input is greater than largest uint40).
     *
     * Counterpart to Solidity's `uint40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     *
     * _Available since v4.7._
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
        return uint40(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v2.5._
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint24 from uint256, reverting on
     * overflow (when the input is greater than largest uint24).
     *
     * Counterpart to Solidity's `uint24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     *
     * _Available since v4.7._
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
        return uint24(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v2.5._
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     *
     * _Available since v2.5._
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     *
     * _Available since v3.0._
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        require(value >= 0, "SafeCast: value must be positive");
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int248 from int256, reverting on
     * overflow (when the input is less than smallest int248 or
     * greater than largest int248).
     *
     * Counterpart to Solidity's `int248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toInt248(int256 value) internal pure returns (int248 downcasted) {
        downcasted = int248(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
    }

    /**
     * @dev Returns the downcasted int240 from int256, reverting on
     * overflow (when the input is less than smallest int240 or
     * greater than largest int240).
     *
     * Counterpart to Solidity's `int240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     *
     * _Available since v4.7._
     */
    function toInt240(int256 value) internal pure returns (int240 downcasted) {
        downcasted = int240(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
    }

    /**
     * @dev Returns the downcasted int232 from int256, reverting on
     * overflow (when the input is less than smallest int232 or
     * greater than largest int232).
     *
     * Counterpart to Solidity's `int232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     *
     * _Available since v4.7._
     */
    function toInt232(int256 value) internal pure returns (int232 downcasted) {
        downcasted = int232(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
    }

    /**
     * @dev Returns the downcasted int224 from int256, reverting on
     * overflow (when the input is less than smallest int224 or
     * greater than largest int224).
     *
     * Counterpart to Solidity's `int224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     *
     * _Available since v4.7._
     */
    function toInt224(int256 value) internal pure returns (int224 downcasted) {
        downcasted = int224(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
    }

    /**
     * @dev Returns the downcasted int216 from int256, reverting on
     * overflow (when the input is less than smallest int216 or
     * greater than largest int216).
     *
     * Counterpart to Solidity's `int216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     *
     * _Available since v4.7._
     */
    function toInt216(int256 value) internal pure returns (int216 downcasted) {
        downcasted = int216(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
    }

    /**
     * @dev Returns the downcasted int208 from int256, reverting on
     * overflow (when the input is less than smallest int208 or
     * greater than largest int208).
     *
     * Counterpart to Solidity's `int208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     *
     * _Available since v4.7._
     */
    function toInt208(int256 value) internal pure returns (int208 downcasted) {
        downcasted = int208(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
    }

    /**
     * @dev Returns the downcasted int200 from int256, reverting on
     * overflow (when the input is less than smallest int200 or
     * greater than largest int200).
     *
     * Counterpart to Solidity's `int200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     *
     * _Available since v4.7._
     */
    function toInt200(int256 value) internal pure returns (int200 downcasted) {
        downcasted = int200(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
    }

    /**
     * @dev Returns the downcasted int192 from int256, reverting on
     * overflow (when the input is less than smallest int192 or
     * greater than largest int192).
     *
     * Counterpart to Solidity's `int192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     *
     * _Available since v4.7._
     */
    function toInt192(int256 value) internal pure returns (int192 downcasted) {
        downcasted = int192(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
    }

    /**
     * @dev Returns the downcasted int184 from int256, reverting on
     * overflow (when the input is less than smallest int184 or
     * greater than largest int184).
     *
     * Counterpart to Solidity's `int184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     *
     * _Available since v4.7._
     */
    function toInt184(int256 value) internal pure returns (int184 downcasted) {
        downcasted = int184(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
    }

    /**
     * @dev Returns the downcasted int176 from int256, reverting on
     * overflow (when the input is less than smallest int176 or
     * greater than largest int176).
     *
     * Counterpart to Solidity's `int176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     *
     * _Available since v4.7._
     */
    function toInt176(int256 value) internal pure returns (int176 downcasted) {
        downcasted = int176(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
    }

    /**
     * @dev Returns the downcasted int168 from int256, reverting on
     * overflow (when the input is less than smallest int168 or
     * greater than largest int168).
     *
     * Counterpart to Solidity's `int168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     *
     * _Available since v4.7._
     */
    function toInt168(int256 value) internal pure returns (int168 downcasted) {
        downcasted = int168(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
    }

    /**
     * @dev Returns the downcasted int160 from int256, reverting on
     * overflow (when the input is less than smallest int160 or
     * greater than largest int160).
     *
     * Counterpart to Solidity's `int160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     *
     * _Available since v4.7._
     */
    function toInt160(int256 value) internal pure returns (int160 downcasted) {
        downcasted = int160(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
    }

    /**
     * @dev Returns the downcasted int152 from int256, reverting on
     * overflow (when the input is less than smallest int152 or
     * greater than largest int152).
     *
     * Counterpart to Solidity's `int152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     *
     * _Available since v4.7._
     */
    function toInt152(int256 value) internal pure returns (int152 downcasted) {
        downcasted = int152(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
    }

    /**
     * @dev Returns the downcasted int144 from int256, reverting on
     * overflow (when the input is less than smallest int144 or
     * greater than largest int144).
     *
     * Counterpart to Solidity's `int144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     *
     * _Available since v4.7._
     */
    function toInt144(int256 value) internal pure returns (int144 downcasted) {
        downcasted = int144(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
    }

    /**
     * @dev Returns the downcasted int136 from int256, reverting on
     * overflow (when the input is less than smallest int136 or
     * greater than largest int136).
     *
     * Counterpart to Solidity's `int136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     *
     * _Available since v4.7._
     */
    function toInt136(int256 value) internal pure returns (int136 downcasted) {
        downcasted = int136(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v3.1._
     */
    function toInt128(int256 value) internal pure returns (int128 downcasted) {
        downcasted = int128(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
    }

    /**
     * @dev Returns the downcasted int120 from int256, reverting on
     * overflow (when the input is less than smallest int120 or
     * greater than largest int120).
     *
     * Counterpart to Solidity's `int120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     *
     * _Available since v4.7._
     */
    function toInt120(int256 value) internal pure returns (int120 downcasted) {
        downcasted = int120(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
    }

    /**
     * @dev Returns the downcasted int112 from int256, reverting on
     * overflow (when the input is less than smallest int112 or
     * greater than largest int112).
     *
     * Counterpart to Solidity's `int112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     *
     * _Available since v4.7._
     */
    function toInt112(int256 value) internal pure returns (int112 downcasted) {
        downcasted = int112(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
    }

    /**
     * @dev Returns the downcasted int104 from int256, reverting on
     * overflow (when the input is less than smallest int104 or
     * greater than largest int104).
     *
     * Counterpart to Solidity's `int104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     *
     * _Available since v4.7._
     */
    function toInt104(int256 value) internal pure returns (int104 downcasted) {
        downcasted = int104(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
    }

    /**
     * @dev Returns the downcasted int96 from int256, reverting on
     * overflow (when the input is less than smallest int96 or
     * greater than largest int96).
     *
     * Counterpart to Solidity's `int96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     *
     * _Available since v4.7._
     */
    function toInt96(int256 value) internal pure returns (int96 downcasted) {
        downcasted = int96(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
    }

    /**
     * @dev Returns the downcasted int88 from int256, reverting on
     * overflow (when the input is less than smallest int88 or
     * greater than largest int88).
     *
     * Counterpart to Solidity's `int88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     *
     * _Available since v4.7._
     */
    function toInt88(int256 value) internal pure returns (int88 downcasted) {
        downcasted = int88(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
    }

    /**
     * @dev Returns the downcasted int80 from int256, reverting on
     * overflow (when the input is less than smallest int80 or
     * greater than largest int80).
     *
     * Counterpart to Solidity's `int80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     *
     * _Available since v4.7._
     */
    function toInt80(int256 value) internal pure returns (int80 downcasted) {
        downcasted = int80(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
    }

    /**
     * @dev Returns the downcasted int72 from int256, reverting on
     * overflow (when the input is less than smallest int72 or
     * greater than largest int72).
     *
     * Counterpart to Solidity's `int72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toInt72(int256 value) internal pure returns (int72 downcasted) {
        downcasted = int72(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v3.1._
     */
    function toInt64(int256 value) internal pure returns (int64 downcasted) {
        downcasted = int64(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
    }

    /**
     * @dev Returns the downcasted int56 from int256, reverting on
     * overflow (when the input is less than smallest int56 or
     * greater than largest int56).
     *
     * Counterpart to Solidity's `int56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     *
     * _Available since v4.7._
     */
    function toInt56(int256 value) internal pure returns (int56 downcasted) {
        downcasted = int56(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
    }

    /**
     * @dev Returns the downcasted int48 from int256, reverting on
     * overflow (when the input is less than smallest int48 or
     * greater than largest int48).
     *
     * Counterpart to Solidity's `int48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     *
     * _Available since v4.7._
     */
    function toInt48(int256 value) internal pure returns (int48 downcasted) {
        downcasted = int48(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
    }

    /**
     * @dev Returns the downcasted int40 from int256, reverting on
     * overflow (when the input is less than smallest int40 or
     * greater than largest int40).
     *
     * Counterpart to Solidity's `int40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     *
     * _Available since v4.7._
     */
    function toInt40(int256 value) internal pure returns (int40 downcasted) {
        downcasted = int40(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v3.1._
     */
    function toInt32(int256 value) internal pure returns (int32 downcasted) {
        downcasted = int32(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
    }

    /**
     * @dev Returns the downcasted int24 from int256, reverting on
     * overflow (when the input is less than smallest int24 or
     * greater than largest int24).
     *
     * Counterpart to Solidity's `int24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     *
     * _Available since v4.7._
     */
    function toInt24(int256 value) internal pure returns (int24 downcasted) {
        downcasted = int24(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v3.1._
     */
    function toInt16(int256 value) internal pure returns (int16 downcasted) {
        downcasted = int16(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     *
     * _Available since v3.1._
     */
    function toInt8(int256 value) internal pure returns (int8 downcasted) {
        downcasted = int8(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     *
     * _Available since v3.0._
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
        return int256(value);
    }
}

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

import {ISignatureTransfer} from "./ISignatureTransfer.sol";
import {IAllowanceTransfer} from "./IAllowanceTransfer.sol";

/// @notice Permit2 handles signature-based transfers in SignatureTransfer and allowance-based transfers in AllowanceTransfer.
/// @dev Users must approve Permit2 before calling any of the transfer functions.
interface IPermit2 is ISignatureTransfer, IAllowanceTransfer {
// IPermit2 unifies the two interfaces so users have maximal flexibility with their approval.
}

File 5 of 42 : Swapper.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import "v3-core/interfaces/callback/IUniswapV3SwapCallback.sol";
import "v3-core/interfaces/IUniswapV3Pool.sol";
import "v3-core/libraries/TickMath.sol";

import "v3-periphery/interfaces/INonfungiblePositionManager.sol";

import "../../lib/IWETH9.sol";
import "../../lib/IUniversalRouter.sol";
import "../utils/Constants.sol";

// base functionality to do swaps with different routing protocols
abstract contract Swapper is IUniswapV3SwapCallback, Constants {
    event Swap(address indexed tokenIn, address indexed tokenOut, uint256 amountIn, uint256 amountOut);

    /// @notice Wrapped native token address
    IWETH9 public immutable weth;

    address public immutable factory;

    /// @notice Uniswap v3 position manager
    INonfungiblePositionManager public immutable nonfungiblePositionManager;

    /// @notice 0x Exchange Proxy
    address public immutable zeroxRouter;

    /// @notice Uniswap Universal Router
    address public immutable universalRouter;

    /// @notice Constructor
    /// @param _nonfungiblePositionManager Uniswap v3 position manager
    /// @param _zeroxRouter 0x Exchange Proxy
    constructor(
        INonfungiblePositionManager _nonfungiblePositionManager,
        address _zeroxRouter,
        address _universalRouter
    ) {
        weth = IWETH9(_nonfungiblePositionManager.WETH9());
        factory = _nonfungiblePositionManager.factory();
        nonfungiblePositionManager = _nonfungiblePositionManager;
        zeroxRouter = _zeroxRouter;
        universalRouter = _universalRouter;
    }

    // swap data for 0x
    struct ZeroxRouterData {
        address allowanceTarget;
        bytes data;
    }

    // swap data for uni - must include sweep for input token
    struct UniversalRouterData {
        bytes commands;
        bytes[] inputs;
        uint256 deadline;
    }

    struct RouterSwapParams {
        IERC20 tokenIn;
        IERC20 tokenOut;
        uint256 amountIn;
        uint256 amountOutMin;
        bytes swapData;
    }

    // general swap function which uses external router with off-chain calculated swap instructions
    // does slippage check with amountOutMin param
    // returns token amounts deltas after swap
    function _routerSwap(RouterSwapParams memory params)
        internal
        returns (uint256 amountInDelta, uint256 amountOutDelta)
    {
        if (params.amountIn != 0 && params.swapData.length != 0 && address(params.tokenOut) != address(0)) {
            uint256 balanceInBefore = params.tokenIn.balanceOf(address(this));
            uint256 balanceOutBefore = params.tokenOut.balanceOf(address(this));

            // get router specific swap data
            (address router, bytes memory routerData) = abi.decode(params.swapData, (address, bytes));

            if (router == zeroxRouter) {
                ZeroxRouterData memory data = abi.decode(routerData, (ZeroxRouterData));
                // approve needed amount
                SafeERC20.safeIncreaseAllowance(params.tokenIn, data.allowanceTarget, params.amountIn);
                // execute swap
                (bool success,) = zeroxRouter.call(data.data);
                if (!success) {
                    revert SwapFailed();
                }
                // reset approval
                SafeERC20.safeApprove(params.tokenIn, data.allowanceTarget, 0);
            } else if (router == universalRouter) {
                UniversalRouterData memory data = abi.decode(routerData, (UniversalRouterData));
                // tokens are transfered to Universalrouter directly (data.commands must include sweep action!)
                SafeERC20.safeTransfer(params.tokenIn, universalRouter, params.amountIn);
                IUniversalRouter(universalRouter).execute(data.commands, data.inputs, data.deadline);
            } else {
                revert WrongContract();
            }

            amountInDelta = balanceInBefore - params.tokenIn.balanceOf(address(this));
            amountOutDelta = params.tokenOut.balanceOf(address(this)) - balanceOutBefore;

            // amountMin slippage check
            if (amountOutDelta < params.amountOutMin) {
                revert SlippageError();
            }

            // event for any swap with exact swapped value
            emit Swap(address(params.tokenIn), address(params.tokenOut), amountInDelta, amountOutDelta);
        }
    }

    struct PoolSwapParams {
        IUniswapV3Pool pool;
        IERC20 token0;
        IERC20 token1;
        uint24 fee;
        bool swap0For1;
        uint256 amountIn;
        uint256 amountOutMin;
    }

    // execute swap directly on specified pool
    // amounts must be available on the contract for both tokens
    function _poolSwap(PoolSwapParams memory params) internal returns (uint256 amountInDelta, uint256 amountOutDelta) {
        if (params.amountIn != 0) {
            (int256 amount0Delta, int256 amount1Delta) = params.pool.swap(
                address(this),
                params.swap0For1,
                int256(params.amountIn),
                (params.swap0For1 ? TickMath.MIN_SQRT_RATIO + 1 : TickMath.MAX_SQRT_RATIO - 1),
                abi.encode(
                    params.swap0For1 ? params.token0 : params.token1,
                    params.swap0For1 ? params.token1 : params.token0,
                    params.fee
                )
            );
            amountInDelta = params.swap0For1 ? uint256(amount0Delta) : uint256(amount1Delta);
            amountOutDelta = params.swap0For1 ? uint256(-amount1Delta) : uint256(-amount0Delta);

            // amountMin slippage check
            if (amountOutDelta < params.amountOutMin) {
                revert SlippageError();
            }
        }
    }

    // swap callback function where amount for swap is payed
    function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) external override {
        require(amount0Delta > 0 || amount1Delta > 0); // swaps entirely within 0-liquidity regions are not supported

        // check if really called from pool
        (address tokenIn, address tokenOut, uint24 fee) = abi.decode(data, (address, address, uint24));
        if (address(_getPool(tokenIn, tokenOut, fee)) != msg.sender) {
            revert Unauthorized();
        }

        // transfer needed amount of tokenIn
        SafeERC20.safeTransfer(IERC20(tokenIn), msg.sender, amount0Delta > 0 ? uint256(amount0Delta) : uint256(amount1Delta));
    }

    // get pool for token
    function _getPool(address tokenA, address tokenB, uint24 fee) internal view returns (IUniswapV3Pool) {
        return IUniswapV3Pool(PoolAddress.computeAddress(address(factory), PoolAddress.getPoolKey(tokenA, tokenB, fee)));
    }
}

File 6 of 42 : Transformer.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable2Step.sol";

import "v3-periphery/interfaces/INonfungiblePositionManager.sol";

import "../utils/Constants.sol";
import "../interfaces/IVault.sol";

abstract contract Transformer is Ownable2Step, Constants {
    event VaultSet(address newVault);

    // configurable by owner
    mapping(address => bool) public vaults;

    /**
     * @notice Owner controlled function to activate vault address
     * @param _vault vault
     */
    function setVault(address _vault) external onlyOwner {
        emit VaultSet(_vault);
        vaults[_vault] = true;
    }

    // validates if caller is owner (direct or indirect for a given position)
    function _validateOwner(INonfungiblePositionManager nonfungiblePositionManager, uint256 tokenId, address vault)
        internal
    {
        // vault can not be owner
        if (vaults[msg.sender]) {
            revert Unauthorized();
        }

        address owner;
        if (vault != address(0)) {
            if (!vaults[vault]) {
                revert Unauthorized();
            }
            owner = IVault(vault).ownerOf(tokenId);
        } else {
            owner = nonfungiblePositionManager.ownerOf(tokenId);
        }

        if (owner != msg.sender) {
            revert Unauthorized();
        }
    }

    // validates if caller is allowed to process position
    function _validateCaller(INonfungiblePositionManager nonfungiblePositionManager, uint256 tokenId) internal view {
        if (vaults[msg.sender]) {
            uint256 transformedTokenId = IVault(msg.sender).transformedTokenId();
            if (tokenId != transformedTokenId) {
                revert Unauthorized();
            }
        } else {
            address owner = nonfungiblePositionManager.ownerOf(tokenId);
            if (owner != msg.sender && owner != address(this)) {
                revert Unauthorized();
            }
        }
    }
}

File 7 of 42 : ISignatureTransfer.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

/// @title SignatureTransfer
/// @notice Handles ERC20 token transfers through signature based actions
/// @dev Requires user's token approval on the Permit2 contract
interface ISignatureTransfer is IEIP712 {
    /// @notice Thrown when the requested amount for a transfer is larger than the permissioned amount
    /// @param maxAmount The maximum amount a spender can request to transfer
    error InvalidAmount(uint256 maxAmount);

    /// @notice Thrown when the number of tokens permissioned to a spender does not match the number of tokens being transferred
    /// @dev If the spender does not need to transfer the number of tokens permitted, the spender can request amount 0 to be transferred
    error LengthMismatch();

    /// @notice Emits an event when the owner successfully invalidates an unordered nonce.
    event UnorderedNonceInvalidation(address indexed owner, uint256 word, uint256 mask);

    /// @notice The token and amount details for a transfer signed in the permit transfer signature
    struct TokenPermissions {
        // ERC20 token address
        address token;
        // the maximum amount that can be spent
        uint256 amount;
    }

    /// @notice The signed permit message for a single token transfer
    struct PermitTransferFrom {
        TokenPermissions permitted;
        // a unique value for every token owner's signature to prevent signature replays
        uint256 nonce;
        // deadline on the permit signature
        uint256 deadline;
    }

    /// @notice Specifies the recipient address and amount for batched transfers.
    /// @dev Recipients and amounts correspond to the index of the signed token permissions array.
    /// @dev Reverts if the requested amount is greater than the permitted signed amount.
    struct SignatureTransferDetails {
        // recipient address
        address to;
        // spender requested amount
        uint256 requestedAmount;
    }

    /// @notice Used to reconstruct the signed permit message for multiple token transfers
    /// @dev Do not need to pass in spender address as it is required that it is msg.sender
    /// @dev Note that a user still signs over a spender address
    struct PermitBatchTransferFrom {
        // the tokens and corresponding amounts permitted for a transfer
        TokenPermissions[] permitted;
        // a unique value for every token owner's signature to prevent signature replays
        uint256 nonce;
        // deadline on the permit signature
        uint256 deadline;
    }

    /// @notice A map from token owner address and a caller specified word index to a bitmap. Used to set bits in the bitmap to prevent against signature replay protection
    /// @dev Uses unordered nonces so that permit messages do not need to be spent in a certain order
    /// @dev The mapping is indexed first by the token owner, then by an index specified in the nonce
    /// @dev It returns a uint256 bitmap
    /// @dev The index, or wordPosition is capped at type(uint248).max
    function nonceBitmap(address, uint256) external view returns (uint256);

    /// @notice Transfers a token using a signed permit message
    /// @dev Reverts if the requested amount is greater than the permitted signed amount
    /// @param permit The permit data signed over by the owner
    /// @param owner The owner of the tokens to transfer
    /// @param transferDetails The spender's requested transfer details for the permitted token
    /// @param signature The signature to verify
    function permitTransferFrom(
        PermitTransferFrom memory permit,
        SignatureTransferDetails calldata transferDetails,
        address owner,
        bytes calldata signature
    ) external;

    /// @notice Transfers a token using a signed permit message
    /// @notice Includes extra data provided by the caller to verify signature over
    /// @dev The witness type string must follow EIP712 ordering of nested structs and must include the TokenPermissions type definition
    /// @dev Reverts if the requested amount is greater than the permitted signed amount
    /// @param permit The permit data signed over by the owner
    /// @param owner The owner of the tokens to transfer
    /// @param transferDetails The spender's requested transfer details for the permitted token
    /// @param witness Extra data to include when checking the user signature
    /// @param witnessTypeString The EIP-712 type definition for remaining string stub of the typehash
    /// @param signature The signature to verify
    function permitWitnessTransferFrom(
        PermitTransferFrom memory permit,
        SignatureTransferDetails calldata transferDetails,
        address owner,
        bytes32 witness,
        string calldata witnessTypeString,
        bytes calldata signature
    ) external;

    /// @notice Transfers multiple tokens using a signed permit message
    /// @param permit The permit data signed over by the owner
    /// @param owner The owner of the tokens to transfer
    /// @param transferDetails Specifies the recipient and requested amount for the token transfer
    /// @param signature The signature to verify
    function permitTransferFrom(
        PermitBatchTransferFrom memory permit,
        SignatureTransferDetails[] calldata transferDetails,
        address owner,
        bytes calldata signature
    ) external;

    /// @notice Transfers multiple tokens using a signed permit message
    /// @dev The witness type string must follow EIP712 ordering of nested structs and must include the TokenPermissions type definition
    /// @notice Includes extra data provided by the caller to verify signature over
    /// @param permit The permit data signed over by the owner
    /// @param owner The owner of the tokens to transfer
    /// @param transferDetails Specifies the recipient and requested amount for the token transfer
    /// @param witness Extra data to include when checking the user signature
    /// @param witnessTypeString The EIP-712 type definition for remaining string stub of the typehash
    /// @param signature The signature to verify
    function permitWitnessTransferFrom(
        PermitBatchTransferFrom memory permit,
        SignatureTransferDetails[] calldata transferDetails,
        address owner,
        bytes32 witness,
        string calldata witnessTypeString,
        bytes calldata signature
    ) external;

    /// @notice Invalidates the bits specified in mask for the bitmap at the word position
    /// @dev The wordPos is maxed at type(uint248).max
    /// @param wordPos A number to index the nonceBitmap at
    /// @param mask A bitmap masked against msg.sender's current bitmap at the word position
    function invalidateUnorderedNonces(uint256 wordPos, uint256 mask) external;
}

File 8 of 42 : IAllowanceTransfer.sol
// 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;
}

File 9 of 42 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 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 {
    using Address for address;

    /**
     * @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 {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    /**
     * @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 {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @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.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), 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 data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), 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 data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return
            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
    }
}

File 10 of 42 : IUniswapV3SwapCallback.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Callback for IUniswapV3PoolActions#swap
/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface
interface IUniswapV3SwapCallback {
    /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.
    /// @dev In the implementation you must pay the pool tokens owed for the swap.
    /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.
    /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
    /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
    /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
    /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
    function uniswapV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata data
    ) external;
}

File 11 of 42 : IUniswapV3Pool.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import {IUniswapV3PoolImmutables} from './pool/IUniswapV3PoolImmutables.sol';
import {IUniswapV3PoolState} from './pool/IUniswapV3PoolState.sol';
import {IUniswapV3PoolDerivedState} from './pool/IUniswapV3PoolDerivedState.sol';
import {IUniswapV3PoolActions} from './pool/IUniswapV3PoolActions.sol';
import {IUniswapV3PoolOwnerActions} from './pool/IUniswapV3PoolOwnerActions.sol';
import {IUniswapV3PoolErrors} from './pool/IUniswapV3PoolErrors.sol';
import {IUniswapV3PoolEvents} from './pool/IUniswapV3PoolEvents.sol';

/// @title The interface for a Uniswap V3 Pool
/// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform
/// to the ERC20 specification
/// @dev The pool interface is broken up into many smaller pieces
interface IUniswapV3Pool is
    IUniswapV3PoolImmutables,
    IUniswapV3PoolState,
    IUniswapV3PoolDerivedState,
    IUniswapV3PoolActions,
    IUniswapV3PoolOwnerActions,
    IUniswapV3PoolErrors,
    IUniswapV3PoolEvents
{

}

File 12 of 42 : TickMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

/// @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 {
    error T();
    error R();

    /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128
    int24 internal constant MIN_TICK = -887272;
    /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128
    int24 internal constant MAX_TICK = -MIN_TICK;

    /// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK)
    uint160 internal constant MIN_SQRT_RATIO = 4295128739;
    /// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK)
    uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342;

    /// @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 ratio of the two assets (token1/token0)
    /// at the given tick
    function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {
        unchecked {
            uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick));
            if (absTick > uint256(int256(MAX_TICK))) revert T();

            uint256 ratio = absTick & 0x1 != 0
                ? 0xfffcb933bd6fad37aa2d162d1a594001
                : 0x100000000000000000000000000000000;
            if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128;
            if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128;
            if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128;
            if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128;
            if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128;
            if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128;
            if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128;
            if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128;
            if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128;
            if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128;
            if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128;
            if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;
            if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128;
            if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128;
            if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128;
            if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128;
            if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128;
            if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128;
            if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128;

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

            // 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 getTickAtSqrtRatio of the output price is always consistent
            sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1));
        }
    }

    /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio
    /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may
    /// ever return.
    /// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96
    /// @return tick The greatest tick for which the ratio is less than or equal to the input ratio
    function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) {
        unchecked {
            // second inequality must be < because the price can never reach the price at the max tick
            if (!(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO)) revert R();
            uint256 ratio = uint256(sqrtPriceX96) << 32;

            uint256 r = ratio;
            uint256 msb = 0;

            assembly {
                let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(5, gt(r, 0xFFFFFFFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(4, gt(r, 0xFFFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(3, gt(r, 0xFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(2, gt(r, 0xF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(1, gt(r, 0x3))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := gt(r, 0x1)
                msb := or(msb, f)
            }

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

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

            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(63, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(62, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(61, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(60, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(59, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(58, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(57, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(56, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(55, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(54, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(53, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(52, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(51, f))
                r := shr(f, r)
            }
            assembly {
                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; // 128.128 number

            int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128);
            int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128);

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

File 13 of 42 : INonfungiblePositionManager.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol';
import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol';

import './IPoolInitializer.sol';
import './IERC721Permit.sol';
import './IPeripheryPayments.sol';
import './IPeripheryImmutableState.sol';
import '../libraries/PoolAddress.sol';

/// @title Non-fungible token for positions
/// @notice Wraps Uniswap V3 positions in a non-fungible token interface which allows for them to be transferred
/// and authorized.
interface INonfungiblePositionManager is
    IPoolInitializer,
    IPeripheryPayments,
    IPeripheryImmutableState,
    IERC721Metadata,
    IERC721Enumerable,
    IERC721Permit
{
    /// @notice Emitted when liquidity is increased for a position NFT
    /// @dev Also emitted when a token is minted
    /// @param tokenId The ID of the token for which liquidity was increased
    /// @param liquidity The amount by which liquidity for the NFT position was increased
    /// @param amount0 The amount of token0 that was paid for the increase in liquidity
    /// @param amount1 The amount of token1 that was paid for the increase in liquidity
    event IncreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
    /// @notice Emitted when liquidity is decreased for a position NFT
    /// @param tokenId The ID of the token for which liquidity was decreased
    /// @param liquidity The amount by which liquidity for the NFT position was decreased
    /// @param amount0 The amount of token0 that was accounted for the decrease in liquidity
    /// @param amount1 The amount of token1 that was accounted for the decrease in liquidity
    event DecreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
    /// @notice Emitted when tokens are collected for a position NFT
    /// @dev The amounts reported may not be exactly equivalent to the amounts transferred, due to rounding behavior
    /// @param tokenId The ID of the token for which underlying tokens were collected
    /// @param recipient The address of the account that received the collected tokens
    /// @param amount0 The amount of token0 owed to the position that was collected
    /// @param amount1 The amount of token1 owed to the position that was collected
    event Collect(uint256 indexed tokenId, address recipient, uint256 amount0, uint256 amount1);

    /// @notice Returns the position information associated with a given token ID.
    /// @dev Throws if the token ID is not valid.
    /// @param tokenId The ID of the token that represents the position
    /// @return nonce The nonce for permits
    /// @return operator The address that is approved for spending
    /// @return token0 The address of the token0 for a specific pool
    /// @return token1 The address of the token1 for a specific pool
    /// @return fee The fee associated with the pool
    /// @return tickLower The lower end of the tick range for the position
    /// @return tickUpper The higher end of the tick range for the position
    /// @return liquidity The liquidity of the position
    /// @return feeGrowthInside0LastX128 The fee growth of token0 as of the last action on the individual position
    /// @return feeGrowthInside1LastX128 The fee growth of token1 as of the last action on the individual position
    /// @return tokensOwed0 The uncollected amount of token0 owed to the position as of the last computation
    /// @return tokensOwed1 The uncollected amount of token1 owed to the position as of the last computation
    function positions(uint256 tokenId)
        external
        view
        returns (
            uint96 nonce,
            address operator,
            address token0,
            address token1,
            uint24 fee,
            int24 tickLower,
            int24 tickUpper,
            uint128 liquidity,
            uint256 feeGrowthInside0LastX128,
            uint256 feeGrowthInside1LastX128,
            uint128 tokensOwed0,
            uint128 tokensOwed1
        );

    struct MintParams {
        address token0;
        address token1;
        uint24 fee;
        int24 tickLower;
        int24 tickUpper;
        uint256 amount0Desired;
        uint256 amount1Desired;
        uint256 amount0Min;
        uint256 amount1Min;
        address recipient;
        uint256 deadline;
    }

    /// @notice Creates a new position wrapped in a NFT
    /// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized
    /// a method does not exist, i.e. the pool is assumed to be initialized.
    /// @param params The params necessary to mint a position, encoded as `MintParams` in calldata
    /// @return tokenId The ID of the token that represents the minted position
    /// @return liquidity The amount of liquidity for this position
    /// @return amount0 The amount of token0
    /// @return amount1 The amount of token1
    function mint(MintParams calldata params)
        external
        payable
        returns (
            uint256 tokenId,
            uint128 liquidity,
            uint256 amount0,
            uint256 amount1
        );

    struct IncreaseLiquidityParams {
        uint256 tokenId;
        uint256 amount0Desired;
        uint256 amount1Desired;
        uint256 amount0Min;
        uint256 amount1Min;
        uint256 deadline;
    }

    /// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender`
    /// @param params tokenId The ID of the token for which liquidity is being increased,
    /// amount0Desired The desired amount of token0 to be spent,
    /// amount1Desired The desired amount of token1 to be spent,
    /// amount0Min The minimum amount of token0 to spend, which serves as a slippage check,
    /// amount1Min The minimum amount of token1 to spend, which serves as a slippage check,
    /// deadline The time by which the transaction must be included to effect the change
    /// @return liquidity The new liquidity amount as a result of the increase
    /// @return amount0 The amount of token0 to acheive resulting liquidity
    /// @return amount1 The amount of token1 to acheive resulting liquidity
    function increaseLiquidity(IncreaseLiquidityParams calldata params)
        external
        payable
        returns (
            uint128 liquidity,
            uint256 amount0,
            uint256 amount1
        );

    struct DecreaseLiquidityParams {
        uint256 tokenId;
        uint128 liquidity;
        uint256 amount0Min;
        uint256 amount1Min;
        uint256 deadline;
    }

    /// @notice Decreases the amount of liquidity in a position and accounts it to the position
    /// @param params tokenId The ID of the token for which liquidity is being decreased,
    /// amount The amount by which liquidity will be decreased,
    /// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,
    /// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,
    /// deadline The time by which the transaction must be included to effect the change
    /// @return amount0 The amount of token0 accounted to the position's tokens owed
    /// @return amount1 The amount of token1 accounted to the position's tokens owed
    function decreaseLiquidity(DecreaseLiquidityParams calldata params)
        external
        payable
        returns (uint256 amount0, uint256 amount1);

    struct CollectParams {
        uint256 tokenId;
        address recipient;
        uint128 amount0Max;
        uint128 amount1Max;
    }

    /// @notice Collects up to a maximum amount of fees owed to a specific position to the recipient
    /// @param params tokenId The ID of the NFT for which tokens are being collected,
    /// recipient The account that should receive the tokens,
    /// amount0Max The maximum amount of token0 to collect,
    /// amount1Max The maximum amount of token1 to collect
    /// @return amount0 The amount of fees collected in token0
    /// @return amount1 The amount of fees collected in token1
    function collect(CollectParams calldata params) external payable returns (uint256 amount0, uint256 amount1);

    /// @notice Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens
    /// must be collected first.
    /// @param tokenId The ID of the token that is being burned
    function burn(uint256 tokenId) external payable;
}

File 14 of 42 : IWETH9.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

import '@openzeppelin/contracts/token/ERC20/IERC20.sol';

/// @title Interface for WETH9
interface IWETH9 is IERC20 {
    /// @notice Deposit ether to get wrapped ether
    function deposit() external payable;

    /// @notice Withdraw wrapped ether to get ether
    function withdraw(uint256) external;
}

File 15 of 42 : IUniversalRouter.sol
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;

interface IUniversalRouter {
    /// @notice Executes encoded commands along with provided inputs. Reverts if deadline has expired.
    /// @param commands A set of concatenated commands, each 1 byte in length
    /// @param inputs An array of byte strings containing abi encoded inputs for each command
    /// @param deadline The deadline by which the transaction must be executed
    function execute(bytes calldata commands, bytes[] calldata inputs, uint256 deadline) external payable;
}

File 16 of 42 : Constants.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

abstract contract Constants {
    uint256 internal constant Q32 = 2 ** 32;
    uint256 internal constant Q64 = 2 ** 64;
    uint256 internal constant Q96 = 2 ** 96;
    uint256 internal constant Q128 = 2 ** 128;
    uint256 internal constant Q160 = 2 ** 160;

    error Unauthorized();
    error Reentrancy();
    error NotConfigured();
    error NotReady();
    error InvalidConfig();
    error TWAPCheckFailed();
    error WrongContract();
    error InvalidToken();

    error SwapFailed();
    error SlippageError();
    error MissingSwapData();
    error SwapAmountTooLarge();

    error ExceedsMaxReward();
    error InvalidPool();
    error ChainlinkPriceError();
    error PriceDifferenceExceeded();
    error SequencerDown();
    error SequencerGracePeriodNotOver();

    error CollateralFail();
    error MinLoanSize();
    error GlobalDebtLimit();
    error GlobalLendLimit();
    error DailyDebtIncreaseLimit();
    error DailyLendIncreaseLimit();
    error InsufficientLiquidity();
    error NotLiquidatable();
    error InterestNotUpdated();
    error TransformNotAllowed();
    error TransformFailed();
    error CollateralFactorExceedsMax();
    error CollateralValueLimit();
    error NoLiquidity();
    error DebtChanged();
    error NeedsRepay();
    error NoSharesRepayed();

    error SelfSend();
    error NotSupportedWhatToDo();
    error SameToken();
    error AmountError();
    error CollectError();
    error TransferError();

    error TooMuchEtherSent();
    error NoEtherToken();
    error EtherSendFailed();
    error NotWETH();

    error NotEnoughReward();
    error SameRange();
    error NotSupportedFeeTier();
}

File 17 of 42 : Ownable2Step.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable2Step.sol)

pragma solidity ^0.8.0;

import "./Ownable.sol";

/**
 * @dev Contract module which provides access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership} and {acceptOwnership}.
 *
 * This module is used through inheritance. It will make available all functions
 * from parent (Ownable).
 */
abstract contract Ownable2Step is Ownable {
    address private _pendingOwner;

    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Returns the address of the pending owner.
     */
    function pendingOwner() public view virtual returns (address) {
        return _pendingOwner;
    }

    /**
     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual override onlyOwner {
        _pendingOwner = newOwner;
        emit OwnershipTransferStarted(owner(), newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual override {
        delete _pendingOwner;
        super._transferOwnership(newOwner);
    }

    /**
     * @dev The new owner accepts the ownership transfer.
     */
    function acceptOwnership() public virtual {
        address sender = _msgSender();
        require(pendingOwner() == sender, "Ownable2Step: caller is not the new owner");
        _transferOwnership(sender);
    }
}

File 18 of 42 : IVault.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/interfaces/IERC4626.sol";

interface IVault is IERC4626 {
    function transformedTokenId() external view returns (uint256 tokenId);

    function loans(uint256 tokenId) external view returns (uint256 debtShares);

    function vaultInfo()
        external
        view
        returns (
            uint256 debt,
            uint256 lent,
            uint256 balance,
            uint256 reserves,
            uint256 debtExchangeRateX96,
            uint256 lendExchangeRateX96
        );
    function lendInfo(address account) external view returns (uint256 amount);
    function loanInfo(uint256 tokenId)
        external
        view
        returns (
            uint256 debt,
            uint256 fullValue,
            uint256 collateralValue,
            uint256 liquidationCost,
            uint256 liquidationValue
        );

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

    // functions for iterating over owners loans
    function loanCount(address owner) external view returns (uint256);
    function loanAtIndex(address owner, uint256 index) external view returns (uint256);

    function create(uint256 tokenId, address recipient) external;
    function createWithPermit(uint256 tokenId, address recipient, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
        external;

    function approveTransform(uint256 tokenId, address target, bool active) external;
    function transform(uint256 tokenId, address transformer, bytes calldata data) external returns (uint256);

    // params for decreasing liquidity of collateralized position
    struct DecreaseLiquidityAndCollectParams {
        uint256 tokenId;
        uint128 liquidity;
        // min amount to accept from liquidity removal
        uint256 amount0Min;
        uint256 amount1Min;
        // amount to remove from fees additional to the liquidity amounts
        uint128 feeAmount0; // (if uint256(128).max - all fees)
        uint128 feeAmount1; // (if uint256(128).max - all fees)
        uint256 deadline;
        address recipient;
    }

    function decreaseLiquidityAndCollect(DecreaseLiquidityAndCollectParams calldata params)
        external
        returns (uint256 amount0, uint256 amount1);

    function borrow(uint256 tokenId, uint256 amount) external;
    function repay(uint256 tokenId, uint256 amount, bool isShare) external returns (uint256 assets, uint256 shares);
    function repay(uint256 tokenId, uint256 amount, bool isShare, bytes calldata permitData)
        external
        returns (uint256 assets, uint256 shares);

    struct LiquidateParams {
        // token to liquidate
        uint256 tokenId;
        // min amount to recieve
        uint256 amount0Min;
        uint256 amount1Min;
        // recipient of rewarded tokens
        address recipient;
        // if permit2 signatures are used - set this
        bytes permitData;
        // for uniswap functions
        uint256 deadline;
    }

    function liquidate(LiquidateParams calldata params) external returns (uint256 amount0, uint256 amount1);

    // deposit functions with permit2
    function deposit(uint256 assets, address receiver, bytes calldata permitData) external returns (uint256);
    function mint(uint256 shares, address receiver, bytes calldata permitData) external returns (uint256);
}

File 19 of 42 : IEIP712.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

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

File 20 of 42 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
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 amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves `amount` 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 amount) 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 `amount` 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 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` 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 amount) external returns (bool);
}

File 21 of 42 : IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

File 22 of 42 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

File 23 of 42 : IUniswapV3PoolImmutables.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that never changes
/// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values
interface IUniswapV3PoolImmutables {
    /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface
    /// @return The contract address
    function factory() external view returns (address);

    /// @notice The first of the two tokens of the pool, sorted by address
    /// @return The token contract address
    function token0() external view returns (address);

    /// @notice The second of the two tokens of the pool, sorted by address
    /// @return The token contract address
    function token1() external view returns (address);

    /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6
    /// @return The fee
    function fee() external view returns (uint24);

    /// @notice The pool tick spacing
    /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive
    /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ...
    /// This value is an int24 to avoid casting even though it is always positive.
    /// @return The tick spacing
    function tickSpacing() external view returns (int24);

    /// @notice The maximum amount of position liquidity that can use any tick in the range
    /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and
    /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool
    /// @return The max amount of liquidity per tick
    function maxLiquidityPerTick() external view returns (uint128);
}

File 24 of 42 : IUniswapV3PoolState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that can change
/// @notice These methods compose the pool's state, and can change with any frequency including multiple times
/// per transaction
interface IUniswapV3PoolState {
    /// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas
    /// when accessed externally.
    /// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value
    /// @return tick The current tick of the pool, i.e. according to the last tick transition that was run.
    /// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick
    /// boundary.
    /// @return observationIndex The index of the last oracle observation that was written,
    /// @return observationCardinality The current maximum number of observations stored in the pool,
    /// @return observationCardinalityNext The next maximum number of observations, to be updated when the observation.
    /// @return feeProtocol The protocol fee for both tokens of the pool.
    /// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0
    /// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee.
    /// unlocked Whether the pool is currently locked to reentrancy
    function slot0()
        external
        view
        returns (
            uint160 sqrtPriceX96,
            int24 tick,
            uint16 observationIndex,
            uint16 observationCardinality,
            uint16 observationCardinalityNext,
            uint8 feeProtocol,
            bool unlocked
        );

    /// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool
    /// @dev This value can overflow the uint256
    function feeGrowthGlobal0X128() external view returns (uint256);

    /// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool
    /// @dev This value can overflow the uint256
    function feeGrowthGlobal1X128() external view returns (uint256);

    /// @notice The amounts of token0 and token1 that are owed to the protocol
    /// @dev Protocol fees will never exceed uint128 max in either token
    function protocolFees() external view returns (uint128 token0, uint128 token1);

    /// @notice The currently in range liquidity available to the pool
    /// @dev This value has no relationship to the total liquidity across all ticks
    /// @return The liquidity at the current price of the pool
    function liquidity() external view returns (uint128);

    /// @notice Look up information about a specific tick in the pool
    /// @param tick The tick to look up
    /// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or
    /// tick upper
    /// @return liquidityNet how much liquidity changes when the pool price crosses the tick,
    /// @return feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0,
    /// @return feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1,
    /// @return tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick
    /// @return secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick,
    /// @return secondsOutside the seconds spent on the other side of the tick from the current tick,
    /// @return initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false.
    /// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0.
    /// In addition, these values are only relative and must be used only in comparison to previous snapshots for
    /// a specific position.
    function ticks(int24 tick)
        external
        view
        returns (
            uint128 liquidityGross,
            int128 liquidityNet,
            uint256 feeGrowthOutside0X128,
            uint256 feeGrowthOutside1X128,
            int56 tickCumulativeOutside,
            uint160 secondsPerLiquidityOutsideX128,
            uint32 secondsOutside,
            bool initialized
        );

    /// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information
    function tickBitmap(int16 wordPosition) external view returns (uint256);

    /// @notice Returns the information about a position by the position's key
    /// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper
    /// @return liquidity The amount of liquidity in the position,
    /// @return feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke,
    /// @return feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke,
    /// @return tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke,
    /// @return tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke
    function positions(bytes32 key)
        external
        view
        returns (
            uint128 liquidity,
            uint256 feeGrowthInside0LastX128,
            uint256 feeGrowthInside1LastX128,
            uint128 tokensOwed0,
            uint128 tokensOwed1
        );

    /// @notice Returns data about a specific observation index
    /// @param index The element of the observations array to fetch
    /// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time
    /// ago, rather than at a specific index in the array.
    /// @return blockTimestamp The timestamp of the observation,
    /// @return tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,
    /// @return secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,
    /// @return initialized whether the observation has been initialized and the values are safe to use
    function observations(uint256 index)
        external
        view
        returns (
            uint32 blockTimestamp,
            int56 tickCumulative,
            uint160 secondsPerLiquidityCumulativeX128,
            bool initialized
        );
}

File 25 of 42 : IUniswapV3PoolDerivedState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that is not stored
/// @notice Contains view functions to provide information about the pool that is computed rather than stored on the
/// blockchain. The functions here may have variable gas costs.
interface IUniswapV3PoolDerivedState {
    /// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp
    /// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing
    /// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick,
    /// you must call it with secondsAgos = [3600, 0].
    /// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in
    /// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.
    /// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned
    /// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp
    /// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block
    /// timestamp
    function observe(uint32[] calldata secondsAgos)
        external
        view
        returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);

    /// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range
    /// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed.
    /// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first
    /// snapshot is taken and the second snapshot is taken.
    /// @param tickLower The lower tick of the range
    /// @param tickUpper The upper tick of the range
    /// @return tickCumulativeInside The snapshot of the tick accumulator for the range
    /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range
    /// @return secondsInside The snapshot of seconds per liquidity for the range
    function snapshotCumulativesInside(int24 tickLower, int24 tickUpper)
        external
        view
        returns (
            int56 tickCumulativeInside,
            uint160 secondsPerLiquidityInsideX128,
            uint32 secondsInside
        );
}

File 26 of 42 : IUniswapV3PoolActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Permissionless pool actions
/// @notice Contains pool methods that can be called by anyone
interface IUniswapV3PoolActions {
    /// @notice Sets the initial price for the pool
    /// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
    /// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
    function initialize(uint160 sqrtPriceX96) external;

    /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
    /// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback
    /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
    /// on tickLower, tickUpper, the amount of liquidity, and the current price.
    /// @param recipient The address for which the liquidity will be created
    /// @param tickLower The lower tick of the position in which to add liquidity
    /// @param tickUpper The upper tick of the position in which to add liquidity
    /// @param amount The amount of liquidity to mint
    /// @param data Any data that should be passed through to the callback
    /// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
    /// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
    function mint(
        address recipient,
        int24 tickLower,
        int24 tickUpper,
        uint128 amount,
        bytes calldata data
    ) external returns (uint256 amount0, uint256 amount1);

    /// @notice Collects tokens owed to a position
    /// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
    /// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
    /// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
    /// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
    /// @param recipient The address which should receive the fees collected
    /// @param tickLower The lower tick of the position for which to collect fees
    /// @param tickUpper The upper tick of the position for which to collect fees
    /// @param amount0Requested How much token0 should be withdrawn from the fees owed
    /// @param amount1Requested How much token1 should be withdrawn from the fees owed
    /// @return amount0 The amount of fees collected in token0
    /// @return amount1 The amount of fees collected in token1
    function collect(
        address recipient,
        int24 tickLower,
        int24 tickUpper,
        uint128 amount0Requested,
        uint128 amount1Requested
    ) external returns (uint128 amount0, uint128 amount1);

    /// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
    /// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
    /// @dev Fees must be collected separately via a call to #collect
    /// @param tickLower The lower tick of the position for which to burn liquidity
    /// @param tickUpper The upper tick of the position for which to burn liquidity
    /// @param amount How much liquidity to burn
    /// @return amount0 The amount of token0 sent to the recipient
    /// @return amount1 The amount of token1 sent to the recipient
    function burn(
        int24 tickLower,
        int24 tickUpper,
        uint128 amount
    ) external returns (uint256 amount0, uint256 amount1);

    /// @notice Swap token0 for token1, or token1 for token0
    /// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
    /// @param recipient The address to receive the output of the swap
    /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
    /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
    /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
    /// value after the swap. If one for zero, the price cannot be greater than this value after the swap
    /// @param data Any data to be passed through to the callback
    /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
    /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
    function swap(
        address recipient,
        bool zeroForOne,
        int256 amountSpecified,
        uint160 sqrtPriceLimitX96,
        bytes calldata data
    ) external returns (int256 amount0, int256 amount1);

    /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
    /// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback
    /// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
    /// with 0 amount{0,1} and sending the donation amount(s) from the callback
    /// @param recipient The address which will receive the token0 and token1 amounts
    /// @param amount0 The amount of token0 to send
    /// @param amount1 The amount of token1 to send
    /// @param data Any data to be passed through to the callback
    function flash(
        address recipient,
        uint256 amount0,
        uint256 amount1,
        bytes calldata data
    ) external;

    /// @notice Increase the maximum number of price and liquidity observations that this pool will store
    /// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
    /// the input observationCardinalityNext.
    /// @param observationCardinalityNext The desired minimum number of observations for the pool to store
    function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
}

File 27 of 42 : IUniswapV3PoolOwnerActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Permissioned pool actions
/// @notice Contains pool methods that may only be called by the factory owner
interface IUniswapV3PoolOwnerActions {
    /// @notice Set the denominator of the protocol's % share of the fees
    /// @param feeProtocol0 new protocol fee for token0 of the pool
    /// @param feeProtocol1 new protocol fee for token1 of the pool
    function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external;

    /// @notice Collect the protocol fee accrued to the pool
    /// @param recipient The address to which collected protocol fees should be sent
    /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1
    /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0
    /// @return amount0 The protocol fee collected in token0
    /// @return amount1 The protocol fee collected in token1
    function collectProtocol(
        address recipient,
        uint128 amount0Requested,
        uint128 amount1Requested
    ) external returns (uint128 amount0, uint128 amount1);
}

File 28 of 42 : IUniswapV3PoolErrors.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Errors emitted by a pool
/// @notice Contains all events emitted by the pool
interface IUniswapV3PoolErrors {
    error LOK();
    error TLU();
    error TLM();
    error TUM();
    error AI();
    error M0();
    error M1();
    error AS();
    error IIA();
    error L();
    error F0();
    error F1();
}

File 29 of 42 : IUniswapV3PoolEvents.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Events emitted by a pool
/// @notice Contains all events emitted by the pool
interface IUniswapV3PoolEvents {
    /// @notice Emitted exactly once by a pool when #initialize is first called on the pool
    /// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize
    /// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96
    /// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool
    event Initialize(uint160 sqrtPriceX96, int24 tick);

    /// @notice Emitted when liquidity is minted for a given position
    /// @param sender The address that minted the liquidity
    /// @param owner The owner of the position and recipient of any minted liquidity
    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param amount The amount of liquidity minted to the position range
    /// @param amount0 How much token0 was required for the minted liquidity
    /// @param amount1 How much token1 was required for the minted liquidity
    event Mint(
        address sender,
        address indexed owner,
        int24 indexed tickLower,
        int24 indexed tickUpper,
        uint128 amount,
        uint256 amount0,
        uint256 amount1
    );

    /// @notice Emitted when fees are collected by the owner of a position
    /// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees
    /// @param owner The owner of the position for which fees are collected
    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param amount0 The amount of token0 fees collected
    /// @param amount1 The amount of token1 fees collected
    event Collect(
        address indexed owner,
        address recipient,
        int24 indexed tickLower,
        int24 indexed tickUpper,
        uint128 amount0,
        uint128 amount1
    );

    /// @notice Emitted when a position's liquidity is removed
    /// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect
    /// @param owner The owner of the position for which liquidity is removed
    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param amount The amount of liquidity to remove
    /// @param amount0 The amount of token0 withdrawn
    /// @param amount1 The amount of token1 withdrawn
    event Burn(
        address indexed owner,
        int24 indexed tickLower,
        int24 indexed tickUpper,
        uint128 amount,
        uint256 amount0,
        uint256 amount1
    );

    /// @notice Emitted by the pool for any swaps between token0 and token1
    /// @param sender The address that initiated the swap call, and that received the callback
    /// @param recipient The address that received the output of the swap
    /// @param amount0 The delta of the token0 balance of the pool
    /// @param amount1 The delta of the token1 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 price of the pool after the swap
    event Swap(
        address indexed sender,
        address indexed recipient,
        int256 amount0,
        int256 amount1,
        uint160 sqrtPriceX96,
        uint128 liquidity,
        int24 tick
    );

    /// @notice Emitted by the pool for any flashes of token0/token1
    /// @param sender The address that initiated the swap call, and that received the callback
    /// @param recipient The address that received the tokens from flash
    /// @param amount0 The amount of token0 that was flashed
    /// @param amount1 The amount of token1 that was flashed
    /// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee
    /// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee
    event Flash(
        address indexed sender,
        address indexed recipient,
        uint256 amount0,
        uint256 amount1,
        uint256 paid0,
        uint256 paid1
    );

    /// @notice Emitted by the pool for increases to the number of observations that can be stored
    /// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index
    /// just before a mint/swap/burn.
    /// @param observationCardinalityNextOld The previous value of the next observation cardinality
    /// @param observationCardinalityNextNew The updated value of the next observation cardinality
    event IncreaseObservationCardinalityNext(
        uint16 observationCardinalityNextOld,
        uint16 observationCardinalityNextNew
    );

    /// @notice Emitted when the protocol fee is changed by the pool
    /// @param feeProtocol0Old The previous value of the token0 protocol fee
    /// @param feeProtocol1Old The previous value of the token1 protocol fee
    /// @param feeProtocol0New The updated value of the token0 protocol fee
    /// @param feeProtocol1New The updated value of the token1 protocol fee
    event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New);

    /// @notice Emitted when the collected protocol fees are withdrawn by the factory owner
    /// @param sender The address that collects the protocol fees
    /// @param recipient The address that receives the collected protocol fees
    /// @param amount0 The amount of token0 protocol fees that is withdrawn
    /// @param amount0 The amount of token1 protocol fees that is withdrawn
    event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1);
}

File 30 of 42 : IERC721Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Metadata is IERC721 {
    /**
     * @dev Returns the token collection name.
     */
    function name() external view returns (string memory);

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

    /**
     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
     */
    function tokenURI(uint256 tokenId) external view returns (string memory);
}

File 31 of 42 : IERC721Enumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol)

pragma solidity ^0.8.0;

import "../IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Enumerable is IERC721 {
    /**
     * @dev Returns the total amount of tokens stored by the contract.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns a token ID owned by `owner` at a given `index` of its token list.
     * Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
     */
    function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);

    /**
     * @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
     * Use along with {totalSupply} to enumerate all tokens.
     */
    function tokenByIndex(uint256 index) external view returns (uint256);
}

File 32 of 42 : IPoolInitializer.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;

/// @title Creates and initializes V3 Pools
/// @notice Provides a method for creating and initializing a pool, if necessary, for bundling with other methods that
/// require the pool to exist.
interface IPoolInitializer {
    /// @notice Creates a new pool if it does not exist, then initializes if not initialized
    /// @dev This method can be bundled with others via IMulticall for the first action (e.g. mint) performed against a pool
    /// @param token0 The contract address of token0 of the pool
    /// @param token1 The contract address of token1 of the pool
    /// @param fee The fee amount of the v3 pool for the specified token pair
    /// @param sqrtPriceX96 The initial square root price of the pool as a Q64.96 value
    /// @return pool Returns the pool address based on the pair of tokens and fee, will return the newly created pool address if necessary
    function createAndInitializePoolIfNecessary(
        address token0,
        address token1,
        uint24 fee,
        uint160 sqrtPriceX96
    ) external payable returns (address pool);
}

File 33 of 42 : IERC721Permit.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;

import '@openzeppelin/contracts/token/ERC721/IERC721.sol';

/// @title ERC721 with permit
/// @notice Extension to ERC721 that includes a permit function for signature based approvals
interface IERC721Permit is IERC721 {
    /// @notice The permit typehash used in the permit signature
    /// @return The typehash for the permit
    function PERMIT_TYPEHASH() external pure returns (bytes32);

    /// @notice The domain separator used in the permit signature
    /// @return The domain seperator used in encoding of permit signature
    function DOMAIN_SEPARATOR() external view returns (bytes32);

    /// @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 v Must produce valid secp256k1 signature from the holder along with `r` and `s`
    /// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s`
    /// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v`
    function permit(
        address spender,
        uint256 tokenId,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external payable;
}

File 34 of 42 : IPeripheryPayments.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;

/// @title Periphery Payments
/// @notice Functions to ease deposits and withdrawals of ETH
interface IPeripheryPayments {
    /// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH.
    /// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users.
    /// @param amountMinimum The minimum amount of WETH9 to unwrap
    /// @param recipient The address receiving ETH
    function unwrapWETH9(uint256 amountMinimum, address recipient) external payable;

    /// @notice Refunds any ETH balance held by this contract to the `msg.sender`
    /// @dev Useful for bundling with mint or increase liquidity that uses ether, or exact output swaps
    /// that use ether for the input amount
    function refundETH() external payable;

    /// @notice Transfers the full amount of a token held by this contract to recipient
    /// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users
    /// @param token The contract address of the token which will be transferred to `recipient`
    /// @param amountMinimum The minimum amount of token required for a transfer
    /// @param recipient The destination address of the token
    function sweepToken(
        address token,
        uint256 amountMinimum,
        address recipient
    ) external payable;
}

File 35 of 42 : IPeripheryImmutableState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Immutable state
/// @notice Functions that return immutable state of the router
interface IPeripheryImmutableState {
    /// @return Returns the address of the Uniswap V3 factory
    function factory() external view returns (address);

    /// @return Returns the address of WETH9
    function WETH9() external view returns (address);
}

File 36 of 42 : PoolAddress.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Provides functions for deriving a pool address from the factory, tokens, and the fee
library PoolAddress {
    bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54;

    /// @notice The identifying key of the pool
    struct PoolKey {
        address token0;
        address token1;
        uint24 fee;
    }

    /// @notice Returns PoolKey: the ordered tokens with the matched fee levels
    /// @param tokenA The first token of a pool, unsorted
    /// @param tokenB The second token of a pool, unsorted
    /// @param fee The fee level of the pool
    /// @return Poolkey The pool details with ordered token0 and token1 assignments
    function getPoolKey(
        address tokenA,
        address tokenB,
        uint24 fee
    ) internal pure returns (PoolKey memory) {
        if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA);
        return PoolKey({token0: tokenA, token1: tokenB, fee: fee});
    }

    /// @notice Deterministically computes the pool address given the factory and PoolKey
    /// @param factory The Uniswap V3 factory contract address
    /// @param key The PoolKey
    /// @return pool The contract address of the V3 pool
    function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) {
        require(key.token0 < key.token1);
        pool = address(
            uint160(
                uint256(
                    keccak256(
                        abi.encodePacked(
                            hex'ff',
                            factory,
                            keccak256(abi.encode(key.token0, key.token1, key.fee)),
                            POOL_INIT_CODE_HASH
                        )
                    )
                )
            )
        );
    }
}

File 37 of 42 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

File 38 of 42 : IERC4626.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC4626.sol)

pragma solidity ^0.8.0;

import "../token/ERC20/IERC20.sol";
import "../token/ERC20/extensions/IERC20Metadata.sol";

/**
 * @dev Interface of the ERC4626 "Tokenized Vault Standard", as defined in
 * https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
 *
 * _Available since v4.7._
 */
interface IERC4626 is IERC20, IERC20Metadata {
    event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);

    event Withdraw(
        address indexed sender,
        address indexed receiver,
        address indexed owner,
        uint256 assets,
        uint256 shares
    );

    /**
     * @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
     *
     * - MUST be an ERC-20 token contract.
     * - MUST NOT revert.
     */
    function asset() external view returns (address assetTokenAddress);

    /**
     * @dev Returns the total amount of the underlying asset that is “managed” by Vault.
     *
     * - SHOULD include any compounding that occurs from yield.
     * - MUST be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT revert.
     */
    function totalAssets() external view returns (uint256 totalManagedAssets);

    /**
     * @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
     * scenario where all the conditions are met.
     *
     * - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT show any variations depending on the caller.
     * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
     * - MUST NOT revert.
     *
     * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
     * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
     * from.
     */
    function convertToShares(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
     * scenario where all the conditions are met.
     *
     * - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
     * - MUST NOT show any variations depending on the caller.
     * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
     * - MUST NOT revert.
     *
     * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
     * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
     * from.
     */
    function convertToAssets(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
     * through a deposit call.
     *
     * - MUST return a limited value if receiver is subject to some deposit limit.
     * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
     * - MUST NOT revert.
     */
    function maxDeposit(address receiver) external view returns (uint256 maxAssets);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
     * current on-chain conditions.
     *
     * - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
     *   call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
     *   in the same transaction.
     * - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
     *   deposit would be accepted, regardless if the user has enough tokens approved, etc.
     * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by depositing.
     */
    function previewDeposit(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
     *
     * - MUST emit the Deposit event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   deposit execution, and are accounted for during deposit.
     * - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
     *   approving enough underlying tokens to the Vault contract, etc).
     *
     * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
     */
    function deposit(uint256 assets, address receiver) external returns (uint256 shares);

    /**
     * @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
     * - MUST return a limited value if receiver is subject to some mint limit.
     * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
     * - MUST NOT revert.
     */
    function maxMint(address receiver) external view returns (uint256 maxShares);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
     * current on-chain conditions.
     *
     * - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
     *   in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
     *   same transaction.
     * - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
     *   would be accepted, regardless if the user has enough tokens approved, etc.
     * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by minting.
     */
    function previewMint(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
     *
     * - MUST emit the Deposit event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
     *   execution, and are accounted for during mint.
     * - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
     *   approving enough underlying tokens to the Vault contract, etc).
     *
     * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
     */
    function mint(uint256 shares, address receiver) external returns (uint256 assets);

    /**
     * @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
     * Vault, through a withdraw call.
     *
     * - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
     * - MUST NOT revert.
     */
    function maxWithdraw(address owner) external view returns (uint256 maxAssets);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
     * given current on-chain conditions.
     *
     * - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
     *   call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
     *   called
     *   in the same transaction.
     * - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
     *   the withdrawal would be accepted, regardless if the user has enough shares, etc.
     * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by depositing.
     */
    function previewWithdraw(uint256 assets) external view returns (uint256 shares);

    /**
     * @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
     *
     * - MUST emit the Withdraw event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   withdraw execution, and are accounted for during withdraw.
     * - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
     *   not having enough shares, etc).
     *
     * Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
     * Those methods should be performed separately.
     */
    function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);

    /**
     * @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
     * through a redeem call.
     *
     * - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
     * - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
     * - MUST NOT revert.
     */
    function maxRedeem(address owner) external view returns (uint256 maxShares);

    /**
     * @dev Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block,
     * given current on-chain conditions.
     *
     * - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
     *   in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
     *   same transaction.
     * - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
     *   redemption would be accepted, regardless if the user has enough shares, etc.
     * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
     * - MUST NOT revert.
     *
     * NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
     * share price or some other type of condition, meaning the depositor will lose assets by redeeming.
     */
    function previewRedeem(uint256 shares) external view returns (uint256 assets);

    /**
     * @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
     *
     * - MUST emit the Withdraw event.
     * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
     *   redeem execution, and are accounted for during redeem.
     * - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
     *   not having enough shares, etc).
     *
     * NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
     * Those methods should be performed separately.
     */
    function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
}

File 39 of 42 : IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165.sol";

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
     * understand this adds an external call which potentially creates a reentrancy vulnerability.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the caller.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);
}

File 40 of 42 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)

pragma solidity ^0.8.0;

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

File 41 of 42 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
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);
}

File 42 of 42 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * 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[EIP 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": [
    "@openzeppelin/=lib/openzeppelin-contracts/",
    "@uniswap/v3-core/=lib/v3-core/",
    "@uniswap/v3-periphery/=lib/v3-periphery/",
    "v3-core/=lib/v3-core/contracts/",
    "v3-periphery/=lib/v3-periphery/contracts/",
    "permit2/=lib/permit2/src/",
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-gas-snapshot/=lib/permit2/lib/forge-gas-snapshot/src/",
    "forge-std/=lib/forge-std/src/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "openzeppelin/=lib/openzeppelin-contracts/contracts/",
    "solmate/=lib/permit2/lib/solmate/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "paris",
  "viaIR": true,
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"contract INonfungiblePositionManager","name":"_nonfungiblePositionManager","type":"address"},{"internalType":"address","name":"_zeroxRouter","type":"address"},{"internalType":"address","name":"_universalRouter","type":"address"},{"internalType":"address","name":"_permit2","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AmountError","type":"error"},{"inputs":[],"name":"ChainlinkPriceError","type":"error"},{"inputs":[],"name":"CollateralFactorExceedsMax","type":"error"},{"inputs":[],"name":"CollateralFail","type":"error"},{"inputs":[],"name":"CollateralValueLimit","type":"error"},{"inputs":[],"name":"CollectError","type":"error"},{"inputs":[],"name":"DailyDebtIncreaseLimit","type":"error"},{"inputs":[],"name":"DailyLendIncreaseLimit","type":"error"},{"inputs":[],"name":"DebtChanged","type":"error"},{"inputs":[],"name":"EtherSendFailed","type":"error"},{"inputs":[],"name":"ExceedsMaxReward","type":"error"},{"inputs":[],"name":"GlobalDebtLimit","type":"error"},{"inputs":[],"name":"GlobalLendLimit","type":"error"},{"inputs":[],"name":"InsufficientLiquidity","type":"error"},{"inputs":[],"name":"InterestNotUpdated","type":"error"},{"inputs":[],"name":"InvalidConfig","type":"error"},{"inputs":[],"name":"InvalidPool","type":"error"},{"inputs":[],"name":"InvalidToken","type":"error"},{"inputs":[],"name":"MinLoanSize","type":"error"},{"inputs":[],"name":"MissingSwapData","type":"error"},{"inputs":[],"name":"NeedsRepay","type":"error"},{"inputs":[],"name":"NoEtherToken","type":"error"},{"inputs":[],"name":"NoLiquidity","type":"error"},{"inputs":[],"name":"NoSharesRepayed","type":"error"},{"inputs":[],"name":"NotConfigured","type":"error"},{"inputs":[],"name":"NotEnoughReward","type":"error"},{"inputs":[],"name":"NotLiquidatable","type":"error"},{"inputs":[],"name":"NotReady","type":"error"},{"inputs":[],"name":"NotSupportedFeeTier","type":"error"},{"inputs":[],"name":"NotSupportedWhatToDo","type":"error"},{"inputs":[],"name":"NotWETH","type":"error"},{"inputs":[],"name":"PriceDifferenceExceeded","type":"error"},{"inputs":[],"name":"Reentrancy","type":"error"},{"inputs":[],"name":"SameRange","type":"error"},{"inputs":[],"name":"SameToken","type":"error"},{"inputs":[],"name":"SelfSend","type":"error"},{"inputs":[],"name":"SequencerDown","type":"error"},{"inputs":[],"name":"SequencerGracePeriodNotOver","type":"error"},{"inputs":[],"name":"SlippageError","type":"error"},{"inputs":[],"name":"SwapAmountTooLarge","type":"error"},{"inputs":[],"name":"SwapFailed","type":"error"},{"inputs":[],"name":"TWAPCheckFailed","type":"error"},{"inputs":[],"name":"TooMuchEtherSent","type":"error"},{"inputs":[],"name":"TransferError","type":"error"},{"inputs":[],"name":"TransformFailed","type":"error"},{"inputs":[],"name":"TransformNotAllowed","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"inputs":[],"name":"WrongContract","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newTokenId","type":"uint256"}],"name":"ChangeRange","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"liquidity","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"CompoundFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"tokenIn","type":"address"},{"indexed":true,"internalType":"address","name":"tokenOut","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountOut","type":"uint256"}],"name":"Swap","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"liquidity","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"SwapAndIncreaseLiquidity","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"liquidity","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"amount0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount1","type":"uint256"}],"name":"SwapAndMint","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newVault","type":"address"}],"name":"VaultSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawAndCollectAndSwap","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"components":[{"internalType":"enum V3Utils.WhatToDo","name":"whatToDo","type":"uint8"},{"internalType":"address","name":"targetToken","type":"address"},{"internalType":"uint256","name":"amountRemoveMin0","type":"uint256"},{"internalType":"uint256","name":"amountRemoveMin1","type":"uint256"},{"internalType":"uint256","name":"amountIn0","type":"uint256"},{"internalType":"uint256","name":"amountOut0Min","type":"uint256"},{"internalType":"bytes","name":"swapData0","type":"bytes"},{"internalType":"uint256","name":"amountIn1","type":"uint256"},{"internalType":"uint256","name":"amountOut1Min","type":"uint256"},{"internalType":"bytes","name":"swapData1","type":"bytes"},{"internalType":"uint128","name":"feeAmount0","type":"uint128"},{"internalType":"uint128","name":"feeAmount1","type":"uint128"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"amountAddMin0","type":"uint256"},{"internalType":"uint256","name":"amountAddMin1","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"recipientNFT","type":"address"},{"internalType":"bool","name":"unwrap","type":"bool"},{"internalType":"bytes","name":"returnData","type":"bytes"},{"internalType":"bytes","name":"swapAndMintReturnData","type":"bytes"}],"internalType":"struct V3Utils.Instructions","name":"instructions","type":"tuple"}],"name":"execute","outputs":[{"internalType":"uint256","name":"newTokenId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"components":[{"internalType":"enum V3Utils.WhatToDo","name":"whatToDo","type":"uint8"},{"internalType":"address","name":"targetToken","type":"address"},{"internalType":"uint256","name":"amountRemoveMin0","type":"uint256"},{"internalType":"uint256","name":"amountRemoveMin1","type":"uint256"},{"internalType":"uint256","name":"amountIn0","type":"uint256"},{"internalType":"uint256","name":"amountOut0Min","type":"uint256"},{"internalType":"bytes","name":"swapData0","type":"bytes"},{"internalType":"uint256","name":"amountIn1","type":"uint256"},{"internalType":"uint256","name":"amountOut1Min","type":"uint256"},{"internalType":"bytes","name":"swapData1","type":"bytes"},{"internalType":"uint128","name":"feeAmount0","type":"uint128"},{"internalType":"uint128","name":"feeAmount1","type":"uint128"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"amountAddMin0","type":"uint256"},{"internalType":"uint256","name":"amountAddMin1","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"recipientNFT","type":"address"},{"internalType":"bool","name":"unwrap","type":"bool"},{"internalType":"bytes","name":"returnData","type":"bytes"},{"internalType":"bytes","name":"swapAndMintReturnData","type":"bytes"}],"internalType":"struct V3Utils.Instructions","name":"instructions","type":"tuple"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"executeWithPermit","outputs":[{"internalType":"uint256","name":"newTokenId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nonfungiblePositionManager","outputs":[{"internalType":"contract INonfungiblePositionManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"permit2","outputs":[{"internalType":"contract IPermit2","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_vault","type":"address"}],"name":"setVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20","name":"tokenIn","type":"address"},{"internalType":"contract IERC20","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"bytes","name":"swapData","type":"bytes"},{"internalType":"bool","name":"unwrap","type":"bool"},{"internalType":"bytes","name":"permitData","type":"bytes"}],"internalType":"struct V3Utils.SwapParams","name":"params","type":"tuple"}],"name":"swap","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"contract IERC20","name":"swapSourceToken","type":"address"},{"internalType":"uint256","name":"amountIn0","type":"uint256"},{"internalType":"uint256","name":"amountOut0Min","type":"uint256"},{"internalType":"bytes","name":"swapData0","type":"bytes"},{"internalType":"uint256","name":"amountIn1","type":"uint256"},{"internalType":"uint256","name":"amountOut1Min","type":"uint256"},{"internalType":"bytes","name":"swapData1","type":"bytes"},{"internalType":"uint256","name":"amountAddMin0","type":"uint256"},{"internalType":"uint256","name":"amountAddMin1","type":"uint256"},{"internalType":"bytes","name":"permitData","type":"bytes"}],"internalType":"struct V3Utils.SwapAndIncreaseLiquidityParams","name":"params","type":"tuple"}],"name":"swapAndIncreaseLiquidity","outputs":[{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"contract IERC20","name":"token0","type":"address"},{"internalType":"contract IERC20","name":"token1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"recipientNFT","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"contract IERC20","name":"swapSourceToken","type":"address"},{"internalType":"uint256","name":"amountIn0","type":"uint256"},{"internalType":"uint256","name":"amountOut0Min","type":"uint256"},{"internalType":"bytes","name":"swapData0","type":"bytes"},{"internalType":"uint256","name":"amountIn1","type":"uint256"},{"internalType":"uint256","name":"amountOut1Min","type":"uint256"},{"internalType":"bytes","name":"swapData1","type":"bytes"},{"internalType":"uint256","name":"amountAddMin0","type":"uint256"},{"internalType":"uint256","name":"amountAddMin1","type":"uint256"},{"internalType":"bytes","name":"returnData","type":"bytes"},{"internalType":"bytes","name":"permitData","type":"bytes"}],"internalType":"struct V3Utils.SwapAndMintParams","name":"params","type":"tuple"}],"name":"swapAndMint","outputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int256","name":"amount0Delta","type":"int256"},{"internalType":"int256","name":"amount1Delta","type":"int256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"uniswapV3SwapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"universalRouter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"vaults","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weth","outputs":[{"internalType":"contract IWETH9","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"zeroxRouter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]

610140604081815234620002bc57608082620050c58038038091620000258285620002c1565b833981010312620002bc5781516001600160a01b038082169291838103620002bc5760209062000057828701620002fb565b916200007360606200006b878a01620002fb565b9801620002fb565b600180546001600160a01b03199081169091556000805491821633908117825588519399919288167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08480a36312a9293f60e21b83528383600481845afa928315620002b25790878592849562000267575b506004941660805288519384809263c45a015560e01b82525afa9283156200025b57819362000217575b50505060a05260c05260e052610100938452610120921682525190614db49283620003118439608051838181601e0152818161145101528181613c7101528181613d170152818161446501526145f0015260a0518381816102b20152610709015260c0518381816104940152818161074e015281816115260152818161167501528181611e6b01528181613e9001528181613ef001528181613f3e0152818161425c015281816149f70152614a33015260e05183818161015f015261368c0152518281816114960152818161390f01528181613a4f01528181613a840152613b1e015251818181610c0801528181610cd90152818161176801528181612fdb01526130a80152f35b9091809350813d831162000253575b620002328183620002c1565b810103126200025057506200024790620002fb565b3880806200010f565b80fd5b503d62000226565b508651903d90823e3d90fd5b9280929495508391503d8311620002aa575b620002858183620002c1565b81010312620002a65760049291876200029f8693620002fb565b94620000e5565b8280fd5b503d62000279565b88513d84823e3d90fd5b600080fd5b601f909101601f19168101906001600160401b03821190821017620002e557604052565b634e487b7160e01b600052604160045260246000fd5b51906001600160a01b0382168203620002bc5756fe610180806040526004361015610060575b50361561001c57600080fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316330361004e57005b604051635724f38560e01b8152600490fd5b60003560e01c90816312261ee71461175557508063150b7a021461161d57806321729922146114c557806335a9e4df146114805780633fc8cef31461143b5780636817031b146113c7578063715018a61461136257806379ba50971461129f5780638176835d14610abb5780638da5cb5b14610a92578063a622ee7c14610a53578063b1902ece1461077d578063b44a272214610738578063c45a0155146106f3578063c5f5280a14610439578063dc3253a0146103f4578063e30c3978146103cb578063f2fde38b14610360578063fa461e33146101935763faba4463146101495738610010565b3461018e57600036600319011261018e576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b600080fd5b3461018e57606036600319011261018e576004356024356044356001600160401b03811161018e576101c99036906004016117c1565b9290916000821393848015610356575b1561018e57836060918101031261018e576101f3836117ad565b61020b6040610204602087016117ad565b9501611996565b604080516001600160a01b0393841696841692918791849160009161022f8161186a565b828152826020820152015283881161034a575b5060409062ffffff85808451936102588561186a565b169586845216938460208401521691829101528183101561018e5760405191602083019384526040830152606082015260608152610295816118bb565b519020604051602081019160ff60f81b83526001600160601b03197f000000000000000000000000000000000000000000000000000000000000000060601b16602183015260358201527fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54605582015260558152610312816118bb565b5190201633036103395761032f93156103315750905b33906143e3565b005b905090610328565b6040516282b42960e81b8152600490fd5b87935090506040610242565b50600082136101d9565b3461018e57602036600319011261018e57610379611797565b610381612e57565b60018060a01b0380911690816001600160601b0360a01b6001541617600155600054167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e22700600080a3005b3461018e57600036600319011261018e576001546040516001600160a01b039091168152602090f35b3461018e57604036600319011261018e576024356001600160401b03811161018e5761043161042960209236906004016119b4565b600435611e61565b604051908152f35b60031960203682011261018e576004356001600160401b039182821161018e576101e08260040191833603011261018e5760405163133f757160e31b8152813560048201819052610180926001600160a01b039084846024817f000000000000000000000000000000000000000000000000000000000000000086165afa9485156106e7576000946000966106a7575b506101c4870191826104db8183611c1c565b159050610666576104f26104fa9161053293611c1c565b810190611c65565b9061050760a48b01611c08565b61051a6101248c013560c48d0135611d8a565b9060448c01359060248d013590898d168a8d16612f49565b6040519361053f8561184e565b84526024870135602085015260448701356040850152610561606488016117ad565b60608501526084870135608085015261057c60a488016117ad565b60a085015260c487013560c085015260e487013560e085015261010487013588811161018e576105b290600436918a0101611964565b61010085015261012487013561012085015261014487013561014085015261016487013588811161018e576105ed90600436918a0101611964565b610160850152610184870135908401526101a48601356101a08401523595861161018e5761062761063b9560046106629836920101611964565b6101c083015280341515941692169061404c565b604080516001600160801b0390941684526020840192909252908201529081906060820190565b0390f35b50506106a261067760a48901611c08565b61068a6101248a013560c48b0135611d8a565b9060448a01359060248b013590878b16888b16612eaf565b610532565b908096506106cb9295503d87116106e0575b6106c381836118f1565b810190611db9565b505050505050505095925090509394886104c9565b503d6106b9565b6040513d6000823e3d90fd5b3461018e57600036600319011261018e576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b3461018e57600036600319011261018e576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b60031960203682011261018e576001600160401b0360043581811161018e576102a08160040193823603011261018e576107b683611c08565b60248201906001600160a01b03806107cd84611c08565b16911614610a41576108626102848301916107e88387611c1c565b1590506109f3576108466107ff6104f28589611c1c565b9061080989611c08565b61081285611c08565b61081f6101448a01611c08565b916108346101c48b01356101648c0135611d8a565b9260c48b01359260a48c013592612f49565b61085b6040519661085688611832565b6117ad565b86526117ad565b602085015261087360448301611996565b6040850152610884606483016119a6565b6060850152610895608483016119a6565b608085015260a482013560a085015260c482013560c08501526108ba60e483016117ad565b60e08501526108cc61010483016117ad565b6101008501526101248201356101208501526108eb61014483016117ad565b6101408501526101648201356101608501526101848201356101808501526101a482013583811161018e576109269060043691850101611964565b6101a08501526101c48201356101c08501526101e48201356101e085015261020482013583811161018e576109619060043691850101611964565b61020085015261022482013561022085015261024482013561024085015261026482013583811161018e5761099c9060043691850101611964565b6102608501523591821161018e576080926109c86109d79260046001600160801b039536920101611964565b61028082015234151590613d4a565b9293909160405194855216602084015260408301526060820152f35b610a3c6109ff87611c08565b610a0883611c08565b610a156101448801611c08565b91610a2a6101c48901356101648a0135611d8a565b9260c48901359260a48a013592612eaf565b610846565b60405163100dac0560e11b8152600490fd5b3461018e57602036600319011261018e576001600160a01b03610a74611797565b166000526002602052602060ff604060002054166040519015158152f35b3461018e57600036600319011261018e576000546040516001600160a01b039091168152602090f35b602036600319011261018e576001600160401b036004351161018e576101006004353603600319011261018e57610af6600435600401611c08565b6001600160a01b03610b0c600435602401611c08565b6001600160a01b03909216911614610a415760e460043501610b3381600435600401611c1c565b15905061122c576104f2610b4c91600435600401611c1c565b90610b5b600435600401611c08565b60009160405193610b6b856118a0565b6000855260006020860152600060408601526000606086015260006080860152600060a0860152600060c0860152610ba9604460043501358461442b565b60408801526020870152855281515190610bdb610bc583611c4e565b92610bd360405194856118f1565b808452611c4e565b60005b601f19820181106112075750508551611183575b6020860151611104575b6040860151611058575b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03163b1561018e5760405163edd9444b60e01b815260806004820152835160606084830152805160e4830181905291949293859390926101048501926020019060005b81811061102a57505050806020604092015160a4860152015160c48401526003198382030160248401526020808351928381520192019060005b818110610ffc57505050610cd48291600094336044850152600319848303016064850152611b9e565b0381837f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165af180156106e757610fe8575b508251610f61575b506020820151610ecd575b6040820151610e31575b50505b6020610d3e600435600401611c08565b610dc2610db7610d52602460043501611c08565b92610dad6044600435013594610d7260a460043501600435600401611c1c565b909160405194610d8186611817565b6001600160a01b039081168652168885015260408401879052600435606401356060850152369161192d565b6080820152613598565b9283610e0c57611d67565b80610dd1575b50604051908152f35b610e0690610de3608460043501611c08565b90610df2600435600401611c08565b610e0060c460043501611d5a565b92613c61565b82610dc8565b610e2c610e1d608460043501611c08565b85610df2602460043501611c08565b611d67565b6040516370a0823160e01b8152306004820152602081602481855afa918215610ec15791610e8d575b50610e6c60409160c084015190611d67565b91015103610e7b578080610d2b565b6040516313ff771f60e21b8152600490fd5b90506020813d602011610eb9575b81610ea8602093836118f1565b8101031261018e5751610e6c610e5a565b3d9150610e9b565b604051903d90823e3d90fd5b6040516370a0823160e01b8152306004820152602081602481855afa8015610f56578290610f22575b610f06915060a084015190611d67565b602083015114610d21576040516313ff771f60e21b8152600490fd5b506020813d602011610f4e575b81610f3c602093836118f1565b8101031261018e57610f069051610ef6565b3d9150610f2f565b6040513d84823e3d90fd5b6040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa8015610f56578290610fb4575b610fa79150608084015190611d67565b825103610e7b5782610d16565b506020813d602011610fe0575b81610fce602093836118f1565b8101031261018e57610fa79051610f97565b3d9150610fc1565b610ff39192506117ee565b60009083610d0e565b825180516001600160a01b031685526020908101518186015287955060409094019390920191600101610cab565b825180516001600160a01b031686526020908101518187015289975060409095019490920191600101610c71565b6040516370a0823160e01b815230600482015260208160248160005afa9081156106e7576000916110d2575b5060c08701526110cc60408701516040519061109f82611885565b30825260208201526060880151906110b682612f10565b60608a01526110c58286612f1f565b5283612f1f565b50610c06565b90506020813d6020116110fc575b816110ed602093836118f1565b8101031261018e575187611084565b3d91506110e0565b6040516370a0823160e01b815230600482015260208160248160005afa9081156106e757600091611151575b5060a087015261114b60208701516040519061109f82611885565b50610bfc565b90506020813d60201161117b575b8161116c602093836118f1565b8101031261018e575187611130565b3d915061115f565b6040516370a0823160e01b81523060048201526020816024816001600160a01b0389165afa9081156106e7576000916111d5575b5060808701526111cf86516040519061109f82611885565b50610bf2565b90506020813d6020116111ff575b816111f0602093836118f1565b8101031261018e5751876111b7565b3d91506111e3565b60209060405161121681611885565b6000815260008382015282828701015201610bde565b5061123b600435600401611c08565b61124b604460043501358261442b565b9290918061128b575b50508061127a575b5080611269575b50610d2e565b6112749030336146d2565b80611263565b6112859030336146d2565b8161125c565b6112989130903390614801565b8280611254565b3461018e57600036600319011261018e576001546001600160a01b03338183160361130b576001600160601b0360a01b8092166001556000549133908316176000553391167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3005b60405162461bcd60e51b815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f7420746865206044820152683732bb9037bbb732b960b91b6064820152608490fd5b3461018e57600036600319011261018e5761137b612e57565b600180546001600160a01b0319908116909155600080549182168155906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b3461018e57602036600319011261018e576113e0611797565b6113e8612e57565b6040516001600160a01b03909116808252907fe7ae49f883c825b05681b3e00e8be6fdea9ed2a8a45e4c6ecb9390fc44cce61590602090a16000908152600260205260409020805460ff19166001179055005b3461018e57600036600319011261018e576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b3461018e57600036600319011261018e576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b3461018e5760a036600319011261018e576004356024356001600160401b03811161018e576114f89036906004016119b4565b906044359160ff831680930361018e576040516331a9108f60e11b8152600481018390526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116949190602082602481895afa9182156106e7576000926115e1575b50339116036103395761024082015190843b1561018e5760c4600092836040519788948593637ac2ff7b60e01b855230600486015289602486015260448501526064840152606435608484015260843560a48401525af19182156106e757602093610431936115d2575b50611e61565b6115db906117ee565b846115cc565b9091506020813d602011611615575b816115fd602093836118f1565b8101031261018e5761160e90611bf4565b9086611562565b3d91506115f0565b3461018e57608036600319011261018e57611636611797565b506001600160a01b0360243581811680820361018e57604435926001600160401b039060643582811161018e576116719036906004016117c1565b90917f0000000000000000000000000000000000000000000000000000000000000000169384330361174357301461173157810160208282031261018e57813592831161018e576102c0926116c692016119b4565b6116d08186611e61565b50015190803b1561018e57611701936000809460405196879586948593635c46a7ef60e11b85523060048601611bc3565b03925af180156106e757611722575b604051630a85bd0160e11b8152602090f35b61172b906117ee565b80611710565b604051632797715160e01b8152600490fd5b604051630d348b9b60e41b8152600490fd5b3461018e57600036600319011261018e577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b600435906001600160a01b038216820361018e57565b35906001600160a01b038216820361018e57565b9181601f8401121561018e578235916001600160401b03831161018e576020838186019501011161018e57565b6001600160401b03811161180157604052565b634e487b7160e01b600052604160045260246000fd5b60a081019081106001600160401b0382111761180157604052565b6102a081019081106001600160401b0382111761180157604052565b6101e081019081106001600160401b0382111761180157604052565b606081019081106001600160401b0382111761180157604052565b604081019081106001600160401b0382111761180157604052565b60e081019081106001600160401b0382111761180157604052565b608081019081106001600160401b0382111761180157604052565b602081019081106001600160401b0382111761180157604052565b90601f801991011681019081106001600160401b0382111761180157604052565b6001600160401b03811161180157601f01601f191660200190565b92919261193982611912565b9161194760405193846118f1565b82948184528183011161018e578281602093846000960137010152565b9080601f8301121561018e5781602061197f9335910161192d565b90565b35906001600160801b038216820361018e57565b359062ffffff8216820361018e57565b35908160020b820361018e57565b91909161030090818185031261018e57604051918201906001600160401b0391838110838211176118015760405282948135600381101561018e5784526119fd602083016117ad565b602085015260408201356040850152606082013560608501526080820135608085015260a082013560a085015260c082013583811161018e5781611a42918401611964565b60c085015260e082013560e085015261010080830135908501526101208083013584811161018e5782611a76918501611964565b90850152610140611a88818401611982565b90850152610160611a9a818401611982565b90850152610180611aac818401611996565b908501526101a0611abe8184016119a6565b908501526101c0611ad08184016119a6565b908501526101e0611ae2818401611982565b90850152610200808301359085015261022080830135908501526102408083013590850152610260611b158184016117ad565b90850152610280611b278184016117ad565b908501526102a08083013590811515820361018e578501526102c08083013584811161018e5782611b59918501611964565b908501526102e0928383013590811161018e57611b769201611964565b910152565b60005b838110611b8e5750506000910152565b8181015183820152602001611b7e565b90602091611bb781518092818552858086019101611b7b565b601f01601f1916010190565b6001600160a01b03918216815291166020820152604081019190915260806060820181905261197f92910190611b9e565b51906001600160a01b038216820361018e57565b356001600160a01b038116810361018e5790565b903590601e198136030182121561018e57018035906001600160401b03821161018e5760200191813603831361018e57565b6001600160401b0381116118015760051b60200190565b60409291818103841361018e576001600160401b03823581811161018e5783019460608684031261018e57805190611c9c8261186a565b863583811161018e5787019684601f8901121561018e578735602098611cc182611c4e565b91611cce855193846118f1565b8083528a8084019160061b8301019188831161018e57908b869594939201905b828210611d1d57505050845288810135898501520135908201529483013590811161018e5761197f9201611964565b9091929394828a031261018e578b86918251611d3881611885565b611d41856117ad565b8152828501358382015281520191018594939291611cee565b35801515810361018e5790565b91908203918211611d7457565b634e487b7160e01b600052601160045260246000fd5b91908201809211611d7457565b51908160020b820361018e57565b51906001600160801b038216820361018e57565b91908261018091031261018e5781516001600160601b038116810361018e5791611de560208201611bf4565b91611df260408301611bf4565b91611dff60608201611bf4565b91608082015162ffffff8116810361018e5791611e1e60a08201611d97565b91611e2b60c08301611d97565b91611e3860e08201611da5565b91610100820151916101208101519161197f610160611e5a6101408501611da5565b9301611da5565b919060c0526000917f000000000000000000000000000000000000000000000000000000000000000033600052600260205260ff60406000205416600014612db75760405163ae41abab60e01b8152602081600481335afa9081156106e757600091612d85575b508203610339575b60405163133f757160e31b815260048101839052610180816024816001600160a01b0386165afa80156106e757600090600092600091612d54575b50506000806001600160801b036101e060c05101511680612c70575b506001600160801b0361014060c051015116906001600160801b038214600014612c5d5750506001600160801b03905b6001600160801b0361016060c051015116906001600160801b038214600014612c455750506001600160801b03935b6040516370a0823160e01b8152306004820152946020866024816001600160a01b0388165afa9586156106e757600096612c11575b506040516370a0823160e01b8152306004820152916020836024816001600160a01b038a165afa9283156106e757600093612bdd575b50604051938460808101106001600160401b036080870111176118015760808501604090815289865230602087019081526001600160801b0392831682880190815294831660608801908152825163fc6f786560e01b81529751600489015290516001600160a01b0390811660248901529451831660448801525190911660648601529184916084918391600091165af19485156106e757600092600096612ba6575b506040516370a0823160e01b8152306004820152906020826024816001600160a01b0389165afa9182156106e757600092612b72575b506040516370a0823160e01b8152306004820152906020826024816001600160a01b038b165afa9283156106e7578592600094612b37575b509061210d91611d67565b03612b2557859161211d91611d67565b03612b25578381608060c051015181108015612b16575b612b045760c051516003811015612aee57600203612432576122b394927faede78842f79342b251fe687b26b9f00d35eec5b0d21d44c283dd01a5ad7c136969492889260018060a01b03602060c05101511660018060a01b03861681146000146122b9575050612289955060018060a01b0361026060c05101511661024060c051015160e060c051015161010060c05101519161012060c05101519361020060c05101519561022060c051015197604051996121ef8b61184e565b8a5260208a015260408901526060880152608087015260018060a01b03881660a087015260c086015260e08501526101008401526000610120840152600061014084015260405161223f816118d6565b600081526101608401526101808301526101a0820152604051612261816118d6565b600081526101c082015260c0516102a001511515926001600160a01b0390811692169061404c565b9092905b604051938493846040919493926001600160801b03606083019616825260208201520152565b0390a25b565b6001600160a01b03871603612395575061238d955060018060a01b0361026060c05101511661024060c0510151608060c051015160a060c05101519160c0805101519361020060c05101519561022060c0510151976040519961231b8b61184e565b8a5260208a015260408901526060880152608087015260018060a01b03871660a0870152600060c0870152600060e0870152604051612359816118d6565b600081526101008701526101208601526101408501526101608401526101808301526101a0820152604051612261816118d6565b90929061228d565b9250505061238d9360018060a01b0361026060c05101511661024060c051015161020060c05101519161022060c051015193604051956123d48761184e565b8c87526020870152604086015260608501526080840152600060a0840152600060c0840152600060e084015260405161240c816118d6565b600081526101008401526000610120840152600061014084015260405161223f816118d6565b92959791505060c051516003811015612aee5761290f575060c051602001516001600160a01b039081169085168103612622575062ffffff61018060c051015116610100526101a060c051015160020b926101c060c051015160020b9260018060a01b0361026060c0510151169060018060a01b0361028060c05101511661024060c05101519060e060c05101519361010060c05101519561012060c05101519761020060c05101519961022060c05101519b6102e060c05101519d60405160e0526124ff60e051611832565b60018060a01b031660e0515260018060a01b038816602060e051015261010051604060e0510152606060e0510152608060e051015260a060e051015260c060e051015260e08051015261010060e051015261012060e051015260018060a01b031661014060e051015261016060e051015261018060e05101526101a060e051015260006101c060e051015260006101e060e05101526040516125a0816118d6565b6000815261020060e051015261022060e051015261024060e051015261026060e05101526040516125d0816118d6565b6000815261028060e05101526125f16102a060c0510151151560e051613d4a565b505050915b7f2d3b242342e1e892c96167e80cea1f82a3961348e1576320d5e93deaa75d36896020604051858152a2565b9193916001600160a01b038516036127c35762ffffff61018060c05101511660a0526101a060c051015160020b926101c060c051015160020b9260018060a01b0361026060c0510151169060018060a01b0361028060c05101511661024060c051015190608060c05101519360a060c05101519560c0805101519761020060c05101519961022060c05101519b6102e060c05101519d6040516080526126c9608051611832565b60018060a01b0389166080515260018060a01b03166020608051015260a051604060805101526060608051015260808051015260a0608051015260c0608051015260e060805101526101006080510152610120608051015260018060a01b031661014060805101526000610160608051015260006101806080510152604051612751816118d6565b600081526101a060805101526101c060805101526101e060805101526102006080510152610220608051015261024060805101526102606080510152604051612799816118d6565b6000815261028060805101526127ba6102a060c05101511515608051613d4a565b505050916125f6565b92612842926127ba9462ffffff61018060c051015116916101a060c051015160020b916101c060c051015160020b9160018060a01b0361026060c0510151169160018060a01b0361028060c0510151169361024060c05101519561020060c05101519761022060c0510151996102e060c05101519b6040519d8e611832565b60018060a01b03168d5260018060a01b031660208d015260408c015260608b015260808a015260a089015260c088015260e08701526101008601526101208501526000610140850152600061016085015260006101808501526040516128a7816118d6565b600081526101a085015260006101c085015260006101e08501526040516128cd816118d6565b600081526102008501526102208401526102408301526102608201526040516128f5816118d6565b600081526102808201526102a060c0510151151590613d4a565b95939160c093919351516003811015612aee57600103612adc5760c05160200180517ff8aacb16b34d229aa53d44a7759a3741b5c098e099666e51a4ae9d66a5956c43959194906000906001600160a01b039081169083168114612ad457926129b76129ca9460a060c051015160c080510151906040519261299084611817565b6001600160a01b038816845260208401526040830185905260608301526080820152613598565b939091808310612a80575b505050611d8a565b83516001600160a01b03838116911614612ac357612a0d926129b760018060a01b0386511661010060c051015161012060c0510151906040519261299084611817565b905b81151580612a6d575b612a3a575b51604080516001600160a01b0390921682526020820192909252a2565b60c05161026081015182516102a090920151612a68929015159185916001600160a01b039081169116613c61565b612a1d565b5080516001600160a01b03161515612a18565b612a9d612abb9360018060a01b0361026060c05101511692611d67565b60c0516102a0015115159290916001600160a01b0390911690613c61565b3880806129c2565b612ace929150611d8a565b90612a0f565b5050506129ca565b60405163290db76760e01b8152600490fd5b634e487b7160e01b600052602160045260246000fd5b604051634ff64a9f60e01b8152600490fd5b5060e060c05101518610612134565b604051638ad721cb60e01b8152600490fd5b91925092506020813d602011612b6a575b81612b55602093836118f1565b8101031261018e57519184919061210d612102565b3d9150612b48565b9091506020813d602011612b9e575b81612b8e602093836118f1565b8101031261018e575190386120ca565b3d9150612b81565b909550612bcc91925060403d604011612bd6575b612bc481836118f1565b810190614364565b9190919438612094565b503d612bba565b9092506020813d602011612c09575b81612bf9602093836118f1565b8101031261018e57519138611ff1565b3d9150612bec565b9095506020813d602011612c3d575b81612c2d602093836118f1565b8101031261018e57519438611fbb565b3d9150612c20565b612c5791612c5291611d8a565b61437a565b93611f86565b612c6a91612c5291611d8a565b90611f57565b60c051610240810151604082015160609092015160009550859450909183612c9e575b505050509038611f27565b9193509193506001600160801b0360405194612cb986611817565b8986526020860190815260408601928352606086019384526080860194855260405195630624e65f60e11b87525160048701525116602485015251604484015251606483015251608482015260408160a481600060018060a01b0389165af180156106e757600091600091612d33575b5038808080612c93565b9050612d4e915060403d604011612bd657612bc481836118f1565b38612d29565b915050612d7291506101803d610180116106e0576106c381836118f1565b5050505096505050509150909138611f0b565b90506020813d602011612daf575b81612da0602093836118f1565b8101031261018e575138611ec8565b3d9150612d93565b6040516331a9108f60e11b8152600481018390526001600160a01b03906020816024818686165afa9081156106e757600091612e1d575b5016338114159081612e12575b5015611ed0576040516282b42960e81b8152600490fd5b905030141538612dfb565b90506020813d602011612e4f575b81612e38602093836118f1565b8101031261018e57612e4990611bf4565b38612dee565b3d9150612e2b565b6000546001600160a01b03163303612e6b57565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b93612ebf92959193868587614523565b93909180612efc575b505080612ee8575b505080612edb575050565b6122b79130903390614801565b612ef59130903390614801565b3880612ed0565b612f099130903390614801565b3880612ec8565b6000198114611d745760010190565b8051821015612f335760209160051b010190565b634e487b7160e01b600052603260045260246000fd5b92969093959194612f939060009760405199612f648b6118a0565b898b528960208c01528960408c01528960608c01528960808c01528960a08c01528960c08c0152888888614523565b60408a01526020890152875281515190612faf610bc583611c4e565b875b601f19820181106135035750508751613480575b60208801516133fa575b604088015161333f575b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03163b1561333b5791869160405193849263edd9444b60e01b84526080600485015260e484019080519160606084870152825180915260206101048701930190875b8181106132fb57505050806020604092015160a4870152015160c485015260031984820301602485015260208084519283815201930190855b8181106132ca5750503360448501525082820360031901606484015282916130a391611b9e565b0381837f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165af180156132bf576132ac575b50845161321a575b506020840151613185575b5060408301516130ff57505050565b6040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa918215610ec15791613151575b5061314760409160c084015190611d67565b91015103610e7b57565b90506020813d60201161317d575b8161316c602093836118f1565b8101031261018e5751613147613135565b3d915061315f565b6040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa801561320f5783906131db575b6131cb915060a085015190611d67565b602084015103610e7b57386130f0565b506020813d602011613207575b816131f5602093836118f1565b8101031261018e576131cb90516131bb565b3d91506131e8565b6040513d85823e3d90fd5b6040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa80156132a157849061326d575b6132609150608086015190611d67565b845103610e7b57386130e5565b506020813d602011613299575b81613287602093836118f1565b8101031261018e576132609051613250565b3d915061327a565b6040513d86823e3d90fd5b6132b8909491946117ee565b92386130dd565b6040513d87823e3d90fd5b825180516001600160a01b03168652602090810151818701528c97508896506040909501949092019160010161307c565b929496509281959750604081613328602093600195516020809160018060a01b0381511684520151910152565b0195019101908b96949288969492613043565b8680fd5b6040516370a0823160e01b81523060048201526020816024816001600160a01b038b165afa9081156133ef5788916133b9575b5060c08901526133b360408901516040519061338d82611885565b308252602082015260608a0151906133a482612f10565b60608c01526110c58286612f1f565b50612fd9565b90506020813d6020116133e7575b816133d4602093836118f1565b810103126133e3575138613372565b8780fd5b3d91506133c7565b6040513d8a823e3d90fd5b6040516370a0823160e01b81523060048201526020816024816001600160a01b038a165afa9081156133ef57889161344e575b5060a089015261344860208901516040519061338d82611885565b50612fcf565b90506020813d602011613478575b81613469602093836118f1565b810103126133e357513861342d565b3d915061345c565b6040516370a0823160e01b81523060048201526020816024816001600160a01b0389165afa9081156133ef5788916134d1575b5060808901526134cb88516040519061338d82611885565b50612fc5565b90506020813d6020116134fb575b816134ec602093836118f1565b810103126133e35751386134b3565b3d91506134df565b60209060405161351281611885565b8a81528a8382015282828701015201612fb1565b81601f8201121561018e57805161353c81611912565b9261354a60405194856118f1565b8184526020828401011161018e5761197f9160208085019101611b7b565b3d15613593573d9061357982611912565b9161358760405193846118f1565b82523d6000602084013e565b606090565b6000916000916000906040810151151580613c53575b80613c3d575b6135bc575050565b80516040516370a0823160e01b8152306004820152929550909350602090829060249082906001600160a01b03165afa9081156106e757600091613c0b575b506020838101516040516370a0823160e01b81523060048201529190829060249082906001600160a01b03165afa9081156106e757600091613bd9575b5060808401518051810160408282031261018e5760208201516001600160a01b038116929083900361018e576040810151906001600160401b03821161018e57602061368a92818b9501920101613526565b7f0000000000000000000000000000000000000000000000000000000000000000926001600160a01b038416810361390a57508051810190602081830312613902576020810151906001600160401b03821161390657019260408483031261390257604051936136f985611885565b61370560208201611bf4565b85526040810151906001600160401b0382116138fe57602061372d9281879601920101613526565b602085019081528851855160408b01516137559290916001600160a01b039081169116614843565b519082602083519301915af1613769613568565b50156138ec5784519051613789916001600160a01b0391821691166148fc565b83516040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa9081156138e15786916138ae575b506137cf90602493611d67565b6020858101516040516370a0823160e01b815230600482015292979294859182906001600160a01b03165afa908115610ec1579061387a575b6138129250611d67565b91606081015183106138685760018060a01b0381511690602060018060a01b0391015116907ffa2dda1cc1b86e41239702756b13effbc1a092b5c57e3ad320fbe4f3b13fe23560408051878152866020820152a3565b604051630d4205a160e11b8152600490fd5b506020823d6020116138a6575b81613894602093836118f1565b8101031261018e576138129151613808565b3d9150613887565b90506020813d6020116138d9575b816138c9602093836118f1565b8101031261018e575160246137c2565b3d91506138bc565b6040513d88823e3d90fd5b60405163081ceff360e41b8152600490fd5b8480fd5b8280fd5b8380fd5b9092507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03161415905061174357805181019060208183031261018e5760208101516001600160401b03811161018e57606081830184031261018e576040519161397a8361186a565b602082820101516001600160401b03811161018e576139a3906020808701918585010101613526565b835260408282010151936001600160401b03851161018e5760208101603f868585010101121561018e576020858484010101516139df81611c4e565b956139ed60405197886118f1565b818752602087016020840160408460051b848989010101011161018e576040828787010101905b60408460051b848989010101018210613ba05750505050506020830193845201606001516040808301918252875190880151919291613a7d917f0000000000000000000000000000000000000000000000000000000000000000906001600160a01b03166143e3565b51915190517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03163b1561018e57604051630d64d59360e21b8152606060048201529290918391613ad9906064840190611b9e565b600319838203016024840152815180825260208201916020808360051b8301019401926000915b838310613b6d575050505060448301939093526000925081900381837f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165af180156106e757613b59575b50613789565b613b649195506117ee565b60009338613b53565b91939695509193602080613b8d600193601f198682030187528a51611b9e565b9801930193019092879596949293613b00565b8151906001600160401b03821161018e5760208091613bcc8960408096898e878e019401010101613526565b8152019201919050613a14565b90506020813d602011613c03575b81613bf4602093836118f1565b8101031261018e575138613638565b3d9150613be7565b90506020813d602011613c35575b81613c26602093836118f1565b8101031261018e5751386135fb565b3d9150613c19565b5060208101516001600160a01b031615156135b4565b5060808101515115156135ae565b919280613d14575b15613d0957507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690813b1561018e576040518092632e1a7d4d60e01b82528160246000958680948960048401525af1801561320f57613cf6575b5081809381925af1613cdc613568565b5015613ce457565b604051637cd69c3960e11b8152600490fd5b613d02909291926117ee565b9038613ccc565b906122b792916143e3565b507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0390811690821614613c69565b9091613d568383614937565b909160018060a01b0384511660018060a01b0360208601511662ffffff6040870151166060870151608088015160020b610220890151916102408a0151936101208b0151956040519761016089018981106001600160401b0382111761180157604090815290895260208901918252888101928352600293840b60608a019081526080808b0196875260a08b018e815260c08c018e815260e08d01998a526101008d019a8b52306101208e019081526101408e019c8d529451634418b22b60e11b81529c516001600160a01b0390811660048f01529551861660248e0152955162ffffff1660448d01529151860b60648c0152955190940b60848a0152925160a4890152905160c4880152925160e487015292516101048601529151811661012485015291516101448401529082906101649082906000907f0000000000000000000000000000000000000000000000000000000000000000165af19586156106e757600096600092600090600092613ffa575b508195819785998b60018060a01b03610100830151166102608301519060018060a01b037f0000000000000000000000000000000000000000000000000000000000000000163b1561018e5782600091613f396040519485938493635c46a7ef60e11b85523060048601611bc3565b0381837f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165af180156106e7576122b7997fdbed0571af71402c681d3b0a1f08d80aa2245c9adb30e12d215356c7a274fcf9928892613feb575b50613fc689604051938493846040919493926001600160801b03606083019616825260208201520152565b0390a260e081015181516020909201516001600160a01b039081169281169116614c01565b613ff4906117ee565b38613f9b565b9350505095506080813d608011614044575b81614019608093836118f1565b8101031261018e5780519561403060208301611da5565b966060604084015193015190979238613eca565b3d915061400c565b9290916101605261012052808280808080808080806020810151604082015160018060a01b03606084015116906080840151926101c06101a061018061016061014061012061010060e060c08d60a0600180821b03910151169d01519d01519d01519d01519d01519d01519d01519d01519d01519d604051610140526140d461014051611832565b60018060a01b0316610140515260018060a01b036101605116602061014051015260006040610140510152600060606101405101526000608061014051015260a061014051015260c06101405101528060e0610140510152610100610140510152610120610140510152610140805101526101606101405101526101806101405101526101a06101405101526101c06101405101526101e0610140510152610200610140510152610220610140510152610240610140510152604051614199816118d6565b600081526102606101405101526102806101405101526141bf6101205161014051614937565b93909183516101808501516101a08601516080870151916040519360c085018581106001600160401b038211176118015760405284526020840187815260408501908a8252606086019283526080860193845260a086019485526040519563219f5d1760e01b87525160048701525160248601525160448501525160648401525160848301525160a482015260608160c481600060018060a01b037f0000000000000000000000000000000000000000000000000000000000000000165af19081156106e757600096600091600093614311575b509082916122b794939682988a7f1aa7d7662b161a8d4058004091e4c60474753d2f085db526dfb22da59838d0a7858351926142ef89604051938493846040919493926001600160801b03606083019616825260208201520152565b0390a261012051610160516060909201519096906001600160a01b0316614c01565b9750929150506060863d60601161435c575b81614330606093836118f1565b8101031261018e576122b79161434587611da5565b604060208901519801519097909293919091614293565b3d9150614323565b919082604091031261018e576020825192015190565b6001600160801b039081811161438e571690565b60405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b6064820152608490fd5b60405163a9059cbb60e01b60208201526001600160a01b03909216602483015260448201929092526122b79161442682606481015b03601f1981018452836118f1565b614c54565b60009260008093819382341515918261445b575b50505081811161444d575050565b614458929550611d67565b92565b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811692909190833b1561452057604051630d0e30db60e41b815290808260048134895af1908115610ec15750614511575b501681036144e45750349250508082116144d2575b38808061443f565b6040516307e205e160e41b8152600490fd5b6144ff57156144ca576040516307e205e160e41b8152600490fd5b6040516392b0337360e01b8152600490fd5b61451a906117ee565b386144b5565b80fd5b95929490956000966000938497859786879288346145e5575b508181116145d2575b50508181116145bf575b505084841192836145ac575b83614595575b508261457d575b5050614572575050565b61197f929350611d67565b6001600160a01b039182169116141590503880614568565b6001600160a01b0382811691161415925038614561565b6001600160a01b0382161515935061455b565b6145ca929950611d67565b96388061454f565b6145dd929c50611d67565b993880614545565b916001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811690813b156138fe5760408051630d0e30db60e41b81529095808260048134885af19081156146c757506146b8575b50898116820361466d57505050349181341161465d57505b3861453c565b516307e205e160e41b8152600490fd5b93959193888116820361468c57505050349383341161465d5750614657565b959a5090948616036146a757349888341161465d5750614657565b88516392b0337360e01b8152600490fd5b6146c1906117ee565b3861463f565b8751903d90823e3d90fd5b6040516323b872dd60e01b60208083019182526001600160a01b039384166024840152929093166044820152606480820194909452928352916147679061471881611817565b6040519061472582611885565b8482527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656485830152600080948192519082805af1614761613568565b90614cb3565b8051918215918483156147d9575b5050509050156147825750565b6084906040519062461bcd60e51b82526004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152fd5b9193818094500103126147fd57820151908115158203614520575080388084614775565b5080fd5b6040516323b872dd60e01b60208201526001600160a01b0392831660248201529290911660448301526064808301939093529181526122b79161442682611817565b604051636eb1769f60e11b81523060048201526001600160a01b0383811660248301529093906020908590604490829086165afa9384156106e7576000946148c6575b50614897614426916122b795611d8a565b60405163095ea7b360e01b60208201526001600160a01b03909416602485015260448401528260648101614418565b93506020843d6020116148f4575b816148e1602093836118f1565b8101031261018e57925192614897614886565b3d91506148d4565b60405163095ea7b360e01b60208201526001600160a01b039092166024830152600060448084019190915282526122b79190614426826118bb565b91610140830160018060a01b039283825116918486511690818414600014614a68575050505060a083019283516101c0820190815111612b04576149c66149bf6149d19286855116908760208701511690516101e08701519061020088015192604051946149a486611817565b85526020850152604084015260608301526080820152613598565b9651611d67565b9460c0830151611d8a565b80935b85614a25575b816149e457505050565b60206122b79301908082511691614a1e827f00000000000000000000000000000000000000000000000000000000000000001680946148fc565b5116614843565b614a638682855116614a5a847f00000000000000000000000000000000000000000000000000000000000000001680926148fc565b83865116614843565b6149da565b6020879496970195878751168114600014614ade575050505060c081018051610160830190815111612b0457614ac4614acb9187614ad897511690888651169051610180870151906101a088015192604051946149a486611817565b9251611d67565b93849160a0840151611d8a565b946149d4565b929691928015614be8576101608501938451610180870151906101a08801519260405194614b0b86611817565b85526020850152604084015260608301526080820152614b2a90613598565b8380849a939a5116985116976101c087019889516101e0890151906102008a01519260405194614b5986611817565b85526020850152604084015260608301526080820152614b7890613598565b99909160a088015190614b8a91611d8a565b9960c088015190614b9a91611d8a565b988996519051614ba991611d8a565b90614bb391611d67565b90614bbd91611d67565b80614bcb575b5050506149d4565b614be092848060e08901511691511690613c61565b388080614bc3565b5050935050925060a08301519260c081015180936149d4565b9695614c1487939596614c1a9395611d67565b95611d67565b9380614c42575b50505081614c30575b50505050565b614c3993613c61565b38808080614c2a565b614c4c9287613c61565b388381614c21565b60018060a01b031690614767604051614c6c81611885565b6020938482527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564858301526000808587829751910182855af1614cad613568565b91614d4e565b90919015614d165750805115614cc65790565b60003b15614cd15790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b815115614d265750805190602001fd5b60405162461bcd60e51b815260206004820152908190614d4a906024830190611b9e565b0390fd5b91929015614d6b5750815115614d62575090565b3b15614cd15790565b825190915015614d265750805190602001fdfea26469706673582212208c686dcf0b4da65d053869af5a48dc267fd9ee252cf89bff6c841e2fb5a9b6d864736f6c63430008180033000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe88000000000000000000000000def1c0ded9bec7f1a1670819833240f027b25eff0000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba3

Deployed Bytecode

0x610180806040526004361015610060575b50361561001c57600080fd5b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316330361004e57005b604051635724f38560e01b8152600490fd5b60003560e01c90816312261ee71461175557508063150b7a021461161d57806321729922146114c557806335a9e4df146114805780633fc8cef31461143b5780636817031b146113c7578063715018a61461136257806379ba50971461129f5780638176835d14610abb5780638da5cb5b14610a92578063a622ee7c14610a53578063b1902ece1461077d578063b44a272214610738578063c45a0155146106f3578063c5f5280a14610439578063dc3253a0146103f4578063e30c3978146103cb578063f2fde38b14610360578063fa461e33146101935763faba4463146101495738610010565b3461018e57600036600319011261018e576040517f000000000000000000000000def1c0ded9bec7f1a1670819833240f027b25eff6001600160a01b03168152602090f35b600080fd5b3461018e57606036600319011261018e576004356024356044356001600160401b03811161018e576101c99036906004016117c1565b9290916000821393848015610356575b1561018e57836060918101031261018e576101f3836117ad565b61020b6040610204602087016117ad565b9501611996565b604080516001600160a01b0393841696841692918791849160009161022f8161186a565b828152826020820152015283881161034a575b5060409062ffffff85808451936102588561186a565b169586845216938460208401521691829101528183101561018e5760405191602083019384526040830152606082015260608152610295816118bb565b519020604051602081019160ff60f81b83526001600160601b03197f0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f98460601b16602183015260358201527fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54605582015260558152610312816118bb565b5190201633036103395761032f93156103315750905b33906143e3565b005b905090610328565b6040516282b42960e81b8152600490fd5b87935090506040610242565b50600082136101d9565b3461018e57602036600319011261018e57610379611797565b610381612e57565b60018060a01b0380911690816001600160601b0360a01b6001541617600155600054167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e22700600080a3005b3461018e57600036600319011261018e576001546040516001600160a01b039091168152602090f35b3461018e57604036600319011261018e576024356001600160401b03811161018e5761043161042960209236906004016119b4565b600435611e61565b604051908152f35b60031960203682011261018e576004356001600160401b039182821161018e576101e08260040191833603011261018e5760405163133f757160e31b8152813560048201819052610180926001600160a01b039084846024817f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe8886165afa9485156106e7576000946000966106a7575b506101c4870191826104db8183611c1c565b159050610666576104f26104fa9161053293611c1c565b810190611c65565b9061050760a48b01611c08565b61051a6101248c013560c48d0135611d8a565b9060448c01359060248d013590898d168a8d16612f49565b6040519361053f8561184e565b84526024870135602085015260448701356040850152610561606488016117ad565b60608501526084870135608085015261057c60a488016117ad565b60a085015260c487013560c085015260e487013560e085015261010487013588811161018e576105b290600436918a0101611964565b61010085015261012487013561012085015261014487013561014085015261016487013588811161018e576105ed90600436918a0101611964565b610160850152610184870135908401526101a48601356101a08401523595861161018e5761062761063b9560046106629836920101611964565b6101c083015280341515941692169061404c565b604080516001600160801b0390941684526020840192909252908201529081906060820190565b0390f35b50506106a261067760a48901611c08565b61068a6101248a013560c48b0135611d8a565b9060448a01359060248b013590878b16888b16612eaf565b610532565b908096506106cb9295503d87116106e0575b6106c381836118f1565b810190611db9565b505050505050505095925090509394886104c9565b503d6106b9565b6040513d6000823e3d90fd5b3461018e57600036600319011261018e576040517f0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f9846001600160a01b03168152602090f35b3461018e57600036600319011261018e576040517f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b03168152602090f35b60031960203682011261018e576001600160401b0360043581811161018e576102a08160040193823603011261018e576107b683611c08565b60248201906001600160a01b03806107cd84611c08565b16911614610a41576108626102848301916107e88387611c1c565b1590506109f3576108466107ff6104f28589611c1c565b9061080989611c08565b61081285611c08565b61081f6101448a01611c08565b916108346101c48b01356101648c0135611d8a565b9260c48b01359260a48c013592612f49565b61085b6040519661085688611832565b6117ad565b86526117ad565b602085015261087360448301611996565b6040850152610884606483016119a6565b6060850152610895608483016119a6565b608085015260a482013560a085015260c482013560c08501526108ba60e483016117ad565b60e08501526108cc61010483016117ad565b6101008501526101248201356101208501526108eb61014483016117ad565b6101408501526101648201356101608501526101848201356101808501526101a482013583811161018e576109269060043691850101611964565b6101a08501526101c48201356101c08501526101e48201356101e085015261020482013583811161018e576109619060043691850101611964565b61020085015261022482013561022085015261024482013561024085015261026482013583811161018e5761099c9060043691850101611964565b6102608501523591821161018e576080926109c86109d79260046001600160801b039536920101611964565b61028082015234151590613d4a565b9293909160405194855216602084015260408301526060820152f35b610a3c6109ff87611c08565b610a0883611c08565b610a156101448801611c08565b91610a2a6101c48901356101648a0135611d8a565b9260c48901359260a48a013592612eaf565b610846565b60405163100dac0560e11b8152600490fd5b3461018e57602036600319011261018e576001600160a01b03610a74611797565b166000526002602052602060ff604060002054166040519015158152f35b3461018e57600036600319011261018e576000546040516001600160a01b039091168152602090f35b602036600319011261018e576001600160401b036004351161018e576101006004353603600319011261018e57610af6600435600401611c08565b6001600160a01b03610b0c600435602401611c08565b6001600160a01b03909216911614610a415760e460043501610b3381600435600401611c1c565b15905061122c576104f2610b4c91600435600401611c1c565b90610b5b600435600401611c08565b60009160405193610b6b856118a0565b6000855260006020860152600060408601526000606086015260006080860152600060a0860152600060c0860152610ba9604460043501358461442b565b60408801526020870152855281515190610bdb610bc583611c4e565b92610bd360405194856118f1565b808452611c4e565b60005b601f19820181106112075750508551611183575b6020860151611104575b6040860151611058575b7f000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba36001600160a01b03163b1561018e5760405163edd9444b60e01b815260806004820152835160606084830152805160e4830181905291949293859390926101048501926020019060005b81811061102a57505050806020604092015160a4860152015160c48401526003198382030160248401526020808351928381520192019060005b818110610ffc57505050610cd48291600094336044850152600319848303016064850152611b9e565b0381837f000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba36001600160a01b03165af180156106e757610fe8575b508251610f61575b506020820151610ecd575b6040820151610e31575b50505b6020610d3e600435600401611c08565b610dc2610db7610d52602460043501611c08565b92610dad6044600435013594610d7260a460043501600435600401611c1c565b909160405194610d8186611817565b6001600160a01b039081168652168885015260408401879052600435606401356060850152369161192d565b6080820152613598565b9283610e0c57611d67565b80610dd1575b50604051908152f35b610e0690610de3608460043501611c08565b90610df2600435600401611c08565b610e0060c460043501611d5a565b92613c61565b82610dc8565b610e2c610e1d608460043501611c08565b85610df2602460043501611c08565b611d67565b6040516370a0823160e01b8152306004820152602081602481855afa918215610ec15791610e8d575b50610e6c60409160c084015190611d67565b91015103610e7b578080610d2b565b6040516313ff771f60e21b8152600490fd5b90506020813d602011610eb9575b81610ea8602093836118f1565b8101031261018e5751610e6c610e5a565b3d9150610e9b565b604051903d90823e3d90fd5b6040516370a0823160e01b8152306004820152602081602481855afa8015610f56578290610f22575b610f06915060a084015190611d67565b602083015114610d21576040516313ff771f60e21b8152600490fd5b506020813d602011610f4e575b81610f3c602093836118f1565b8101031261018e57610f069051610ef6565b3d9150610f2f565b6040513d84823e3d90fd5b6040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa8015610f56578290610fb4575b610fa79150608084015190611d67565b825103610e7b5782610d16565b506020813d602011610fe0575b81610fce602093836118f1565b8101031261018e57610fa79051610f97565b3d9150610fc1565b610ff39192506117ee565b60009083610d0e565b825180516001600160a01b031685526020908101518186015287955060409094019390920191600101610cab565b825180516001600160a01b031686526020908101518187015289975060409095019490920191600101610c71565b6040516370a0823160e01b815230600482015260208160248160005afa9081156106e7576000916110d2575b5060c08701526110cc60408701516040519061109f82611885565b30825260208201526060880151906110b682612f10565b60608a01526110c58286612f1f565b5283612f1f565b50610c06565b90506020813d6020116110fc575b816110ed602093836118f1565b8101031261018e575187611084565b3d91506110e0565b6040516370a0823160e01b815230600482015260208160248160005afa9081156106e757600091611151575b5060a087015261114b60208701516040519061109f82611885565b50610bfc565b90506020813d60201161117b575b8161116c602093836118f1565b8101031261018e575187611130565b3d915061115f565b6040516370a0823160e01b81523060048201526020816024816001600160a01b0389165afa9081156106e7576000916111d5575b5060808701526111cf86516040519061109f82611885565b50610bf2565b90506020813d6020116111ff575b816111f0602093836118f1565b8101031261018e5751876111b7565b3d91506111e3565b60209060405161121681611885565b6000815260008382015282828701015201610bde565b5061123b600435600401611c08565b61124b604460043501358261442b565b9290918061128b575b50508061127a575b5080611269575b50610d2e565b6112749030336146d2565b80611263565b6112859030336146d2565b8161125c565b6112989130903390614801565b8280611254565b3461018e57600036600319011261018e576001546001600160a01b03338183160361130b576001600160601b0360a01b8092166001556000549133908316176000553391167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3005b60405162461bcd60e51b815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f7420746865206044820152683732bb9037bbb732b960b91b6064820152608490fd5b3461018e57600036600319011261018e5761137b612e57565b600180546001600160a01b0319908116909155600080549182168155906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b3461018e57602036600319011261018e576113e0611797565b6113e8612e57565b6040516001600160a01b03909116808252907fe7ae49f883c825b05681b3e00e8be6fdea9ed2a8a45e4c6ecb9390fc44cce61590602090a16000908152600260205260409020805460ff19166001179055005b3461018e57600036600319011261018e576040517f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b03168152602090f35b3461018e57600036600319011261018e576040517f0000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad6001600160a01b03168152602090f35b3461018e5760a036600319011261018e576004356024356001600160401b03811161018e576114f89036906004016119b4565b906044359160ff831680930361018e576040516331a9108f60e11b8152600481018390526001600160a01b037f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe888116949190602082602481895afa9182156106e7576000926115e1575b50339116036103395761024082015190843b1561018e5760c4600092836040519788948593637ac2ff7b60e01b855230600486015289602486015260448501526064840152606435608484015260843560a48401525af19182156106e757602093610431936115d2575b50611e61565b6115db906117ee565b846115cc565b9091506020813d602011611615575b816115fd602093836118f1565b8101031261018e5761160e90611bf4565b9086611562565b3d91506115f0565b3461018e57608036600319011261018e57611636611797565b506001600160a01b0360243581811680820361018e57604435926001600160401b039060643582811161018e576116719036906004016117c1565b90917f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe88169384330361174357301461173157810160208282031261018e57813592831161018e576102c0926116c692016119b4565b6116d08186611e61565b50015190803b1561018e57611701936000809460405196879586948593635c46a7ef60e11b85523060048601611bc3565b03925af180156106e757611722575b604051630a85bd0160e11b8152602090f35b61172b906117ee565b80611710565b604051632797715160e01b8152600490fd5b604051630d348b9b60e41b8152600490fd5b3461018e57600036600319011261018e577f000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba36001600160a01b03168152602090f35b600435906001600160a01b038216820361018e57565b35906001600160a01b038216820361018e57565b9181601f8401121561018e578235916001600160401b03831161018e576020838186019501011161018e57565b6001600160401b03811161180157604052565b634e487b7160e01b600052604160045260246000fd5b60a081019081106001600160401b0382111761180157604052565b6102a081019081106001600160401b0382111761180157604052565b6101e081019081106001600160401b0382111761180157604052565b606081019081106001600160401b0382111761180157604052565b604081019081106001600160401b0382111761180157604052565b60e081019081106001600160401b0382111761180157604052565b608081019081106001600160401b0382111761180157604052565b602081019081106001600160401b0382111761180157604052565b90601f801991011681019081106001600160401b0382111761180157604052565b6001600160401b03811161180157601f01601f191660200190565b92919261193982611912565b9161194760405193846118f1565b82948184528183011161018e578281602093846000960137010152565b9080601f8301121561018e5781602061197f9335910161192d565b90565b35906001600160801b038216820361018e57565b359062ffffff8216820361018e57565b35908160020b820361018e57565b91909161030090818185031261018e57604051918201906001600160401b0391838110838211176118015760405282948135600381101561018e5784526119fd602083016117ad565b602085015260408201356040850152606082013560608501526080820135608085015260a082013560a085015260c082013583811161018e5781611a42918401611964565b60c085015260e082013560e085015261010080830135908501526101208083013584811161018e5782611a76918501611964565b90850152610140611a88818401611982565b90850152610160611a9a818401611982565b90850152610180611aac818401611996565b908501526101a0611abe8184016119a6565b908501526101c0611ad08184016119a6565b908501526101e0611ae2818401611982565b90850152610200808301359085015261022080830135908501526102408083013590850152610260611b158184016117ad565b90850152610280611b278184016117ad565b908501526102a08083013590811515820361018e578501526102c08083013584811161018e5782611b59918501611964565b908501526102e0928383013590811161018e57611b769201611964565b910152565b60005b838110611b8e5750506000910152565b8181015183820152602001611b7e565b90602091611bb781518092818552858086019101611b7b565b601f01601f1916010190565b6001600160a01b03918216815291166020820152604081019190915260806060820181905261197f92910190611b9e565b51906001600160a01b038216820361018e57565b356001600160a01b038116810361018e5790565b903590601e198136030182121561018e57018035906001600160401b03821161018e5760200191813603831361018e57565b6001600160401b0381116118015760051b60200190565b60409291818103841361018e576001600160401b03823581811161018e5783019460608684031261018e57805190611c9c8261186a565b863583811161018e5787019684601f8901121561018e578735602098611cc182611c4e565b91611cce855193846118f1565b8083528a8084019160061b8301019188831161018e57908b869594939201905b828210611d1d57505050845288810135898501520135908201529483013590811161018e5761197f9201611964565b9091929394828a031261018e578b86918251611d3881611885565b611d41856117ad565b8152828501358382015281520191018594939291611cee565b35801515810361018e5790565b91908203918211611d7457565b634e487b7160e01b600052601160045260246000fd5b91908201809211611d7457565b51908160020b820361018e57565b51906001600160801b038216820361018e57565b91908261018091031261018e5781516001600160601b038116810361018e5791611de560208201611bf4565b91611df260408301611bf4565b91611dff60608201611bf4565b91608082015162ffffff8116810361018e5791611e1e60a08201611d97565b91611e2b60c08301611d97565b91611e3860e08201611da5565b91610100820151916101208101519161197f610160611e5a6101408501611da5565b9301611da5565b919060c0526000917f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe8833600052600260205260ff60406000205416600014612db75760405163ae41abab60e01b8152602081600481335afa9081156106e757600091612d85575b508203610339575b60405163133f757160e31b815260048101839052610180816024816001600160a01b0386165afa80156106e757600090600092600091612d54575b50506000806001600160801b036101e060c05101511680612c70575b506001600160801b0361014060c051015116906001600160801b038214600014612c5d5750506001600160801b03905b6001600160801b0361016060c051015116906001600160801b038214600014612c455750506001600160801b03935b6040516370a0823160e01b8152306004820152946020866024816001600160a01b0388165afa9586156106e757600096612c11575b506040516370a0823160e01b8152306004820152916020836024816001600160a01b038a165afa9283156106e757600093612bdd575b50604051938460808101106001600160401b036080870111176118015760808501604090815289865230602087019081526001600160801b0392831682880190815294831660608801908152825163fc6f786560e01b81529751600489015290516001600160a01b0390811660248901529451831660448801525190911660648601529184916084918391600091165af19485156106e757600092600096612ba6575b506040516370a0823160e01b8152306004820152906020826024816001600160a01b0389165afa9182156106e757600092612b72575b506040516370a0823160e01b8152306004820152906020826024816001600160a01b038b165afa9283156106e7578592600094612b37575b509061210d91611d67565b03612b2557859161211d91611d67565b03612b25578381608060c051015181108015612b16575b612b045760c051516003811015612aee57600203612432576122b394927faede78842f79342b251fe687b26b9f00d35eec5b0d21d44c283dd01a5ad7c136969492889260018060a01b03602060c05101511660018060a01b03861681146000146122b9575050612289955060018060a01b0361026060c05101511661024060c051015160e060c051015161010060c05101519161012060c05101519361020060c05101519561022060c051015197604051996121ef8b61184e565b8a5260208a015260408901526060880152608087015260018060a01b03881660a087015260c086015260e08501526101008401526000610120840152600061014084015260405161223f816118d6565b600081526101608401526101808301526101a0820152604051612261816118d6565b600081526101c082015260c0516102a001511515926001600160a01b0390811692169061404c565b9092905b604051938493846040919493926001600160801b03606083019616825260208201520152565b0390a25b565b6001600160a01b03871603612395575061238d955060018060a01b0361026060c05101511661024060c0510151608060c051015160a060c05101519160c0805101519361020060c05101519561022060c0510151976040519961231b8b61184e565b8a5260208a015260408901526060880152608087015260018060a01b03871660a0870152600060c0870152600060e0870152604051612359816118d6565b600081526101008701526101208601526101408501526101608401526101808301526101a0820152604051612261816118d6565b90929061228d565b9250505061238d9360018060a01b0361026060c05101511661024060c051015161020060c05101519161022060c051015193604051956123d48761184e565b8c87526020870152604086015260608501526080840152600060a0840152600060c0840152600060e084015260405161240c816118d6565b600081526101008401526000610120840152600061014084015260405161223f816118d6565b92959791505060c051516003811015612aee5761290f575060c051602001516001600160a01b039081169085168103612622575062ffffff61018060c051015116610100526101a060c051015160020b926101c060c051015160020b9260018060a01b0361026060c0510151169060018060a01b0361028060c05101511661024060c05101519060e060c05101519361010060c05101519561012060c05101519761020060c05101519961022060c05101519b6102e060c05101519d60405160e0526124ff60e051611832565b60018060a01b031660e0515260018060a01b038816602060e051015261010051604060e0510152606060e0510152608060e051015260a060e051015260c060e051015260e08051015261010060e051015261012060e051015260018060a01b031661014060e051015261016060e051015261018060e05101526101a060e051015260006101c060e051015260006101e060e05101526040516125a0816118d6565b6000815261020060e051015261022060e051015261024060e051015261026060e05101526040516125d0816118d6565b6000815261028060e05101526125f16102a060c0510151151560e051613d4a565b505050915b7f2d3b242342e1e892c96167e80cea1f82a3961348e1576320d5e93deaa75d36896020604051858152a2565b9193916001600160a01b038516036127c35762ffffff61018060c05101511660a0526101a060c051015160020b926101c060c051015160020b9260018060a01b0361026060c0510151169060018060a01b0361028060c05101511661024060c051015190608060c05101519360a060c05101519560c0805101519761020060c05101519961022060c05101519b6102e060c05101519d6040516080526126c9608051611832565b60018060a01b0389166080515260018060a01b03166020608051015260a051604060805101526060608051015260808051015260a0608051015260c0608051015260e060805101526101006080510152610120608051015260018060a01b031661014060805101526000610160608051015260006101806080510152604051612751816118d6565b600081526101a060805101526101c060805101526101e060805101526102006080510152610220608051015261024060805101526102606080510152604051612799816118d6565b6000815261028060805101526127ba6102a060c05101511515608051613d4a565b505050916125f6565b92612842926127ba9462ffffff61018060c051015116916101a060c051015160020b916101c060c051015160020b9160018060a01b0361026060c0510151169160018060a01b0361028060c0510151169361024060c05101519561020060c05101519761022060c0510151996102e060c05101519b6040519d8e611832565b60018060a01b03168d5260018060a01b031660208d015260408c015260608b015260808a015260a089015260c088015260e08701526101008601526101208501526000610140850152600061016085015260006101808501526040516128a7816118d6565b600081526101a085015260006101c085015260006101e08501526040516128cd816118d6565b600081526102008501526102208401526102408301526102608201526040516128f5816118d6565b600081526102808201526102a060c0510151151590613d4a565b95939160c093919351516003811015612aee57600103612adc5760c05160200180517ff8aacb16b34d229aa53d44a7759a3741b5c098e099666e51a4ae9d66a5956c43959194906000906001600160a01b039081169083168114612ad457926129b76129ca9460a060c051015160c080510151906040519261299084611817565b6001600160a01b038816845260208401526040830185905260608301526080820152613598565b939091808310612a80575b505050611d8a565b83516001600160a01b03838116911614612ac357612a0d926129b760018060a01b0386511661010060c051015161012060c0510151906040519261299084611817565b905b81151580612a6d575b612a3a575b51604080516001600160a01b0390921682526020820192909252a2565b60c05161026081015182516102a090920151612a68929015159185916001600160a01b039081169116613c61565b612a1d565b5080516001600160a01b03161515612a18565b612a9d612abb9360018060a01b0361026060c05101511692611d67565b60c0516102a0015115159290916001600160a01b0390911690613c61565b3880806129c2565b612ace929150611d8a565b90612a0f565b5050506129ca565b60405163290db76760e01b8152600490fd5b634e487b7160e01b600052602160045260246000fd5b604051634ff64a9f60e01b8152600490fd5b5060e060c05101518610612134565b604051638ad721cb60e01b8152600490fd5b91925092506020813d602011612b6a575b81612b55602093836118f1565b8101031261018e57519184919061210d612102565b3d9150612b48565b9091506020813d602011612b9e575b81612b8e602093836118f1565b8101031261018e575190386120ca565b3d9150612b81565b909550612bcc91925060403d604011612bd6575b612bc481836118f1565b810190614364565b9190919438612094565b503d612bba565b9092506020813d602011612c09575b81612bf9602093836118f1565b8101031261018e57519138611ff1565b3d9150612bec565b9095506020813d602011612c3d575b81612c2d602093836118f1565b8101031261018e57519438611fbb565b3d9150612c20565b612c5791612c5291611d8a565b61437a565b93611f86565b612c6a91612c5291611d8a565b90611f57565b60c051610240810151604082015160609092015160009550859450909183612c9e575b505050509038611f27565b9193509193506001600160801b0360405194612cb986611817565b8986526020860190815260408601928352606086019384526080860194855260405195630624e65f60e11b87525160048701525116602485015251604484015251606483015251608482015260408160a481600060018060a01b0389165af180156106e757600091600091612d33575b5038808080612c93565b9050612d4e915060403d604011612bd657612bc481836118f1565b38612d29565b915050612d7291506101803d610180116106e0576106c381836118f1565b5050505096505050509150909138611f0b565b90506020813d602011612daf575b81612da0602093836118f1565b8101031261018e575138611ec8565b3d9150612d93565b6040516331a9108f60e11b8152600481018390526001600160a01b03906020816024818686165afa9081156106e757600091612e1d575b5016338114159081612e12575b5015611ed0576040516282b42960e81b8152600490fd5b905030141538612dfb565b90506020813d602011612e4f575b81612e38602093836118f1565b8101031261018e57612e4990611bf4565b38612dee565b3d9150612e2b565b6000546001600160a01b03163303612e6b57565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b93612ebf92959193868587614523565b93909180612efc575b505080612ee8575b505080612edb575050565b6122b79130903390614801565b612ef59130903390614801565b3880612ed0565b612f099130903390614801565b3880612ec8565b6000198114611d745760010190565b8051821015612f335760209160051b010190565b634e487b7160e01b600052603260045260246000fd5b92969093959194612f939060009760405199612f648b6118a0565b898b528960208c01528960408c01528960608c01528960808c01528960a08c01528960c08c0152888888614523565b60408a01526020890152875281515190612faf610bc583611c4e565b875b601f19820181106135035750508751613480575b60208801516133fa575b604088015161333f575b7f000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba36001600160a01b03163b1561333b5791869160405193849263edd9444b60e01b84526080600485015260e484019080519160606084870152825180915260206101048701930190875b8181106132fb57505050806020604092015160a4870152015160c485015260031984820301602485015260208084519283815201930190855b8181106132ca5750503360448501525082820360031901606484015282916130a391611b9e565b0381837f000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba36001600160a01b03165af180156132bf576132ac575b50845161321a575b506020840151613185575b5060408301516130ff57505050565b6040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa918215610ec15791613151575b5061314760409160c084015190611d67565b91015103610e7b57565b90506020813d60201161317d575b8161316c602093836118f1565b8101031261018e5751613147613135565b3d915061315f565b6040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa801561320f5783906131db575b6131cb915060a085015190611d67565b602084015103610e7b57386130f0565b506020813d602011613207575b816131f5602093836118f1565b8101031261018e576131cb90516131bb565b3d91506131e8565b6040513d85823e3d90fd5b6040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa80156132a157849061326d575b6132609150608086015190611d67565b845103610e7b57386130e5565b506020813d602011613299575b81613287602093836118f1565b8101031261018e576132609051613250565b3d915061327a565b6040513d86823e3d90fd5b6132b8909491946117ee565b92386130dd565b6040513d87823e3d90fd5b825180516001600160a01b03168652602090810151818701528c97508896506040909501949092019160010161307c565b929496509281959750604081613328602093600195516020809160018060a01b0381511684520151910152565b0195019101908b96949288969492613043565b8680fd5b6040516370a0823160e01b81523060048201526020816024816001600160a01b038b165afa9081156133ef5788916133b9575b5060c08901526133b360408901516040519061338d82611885565b308252602082015260608a0151906133a482612f10565b60608c01526110c58286612f1f565b50612fd9565b90506020813d6020116133e7575b816133d4602093836118f1565b810103126133e3575138613372565b8780fd5b3d91506133c7565b6040513d8a823e3d90fd5b6040516370a0823160e01b81523060048201526020816024816001600160a01b038a165afa9081156133ef57889161344e575b5060a089015261344860208901516040519061338d82611885565b50612fcf565b90506020813d602011613478575b81613469602093836118f1565b810103126133e357513861342d565b3d915061345c565b6040516370a0823160e01b81523060048201526020816024816001600160a01b0389165afa9081156133ef5788916134d1575b5060808901526134cb88516040519061338d82611885565b50612fc5565b90506020813d6020116134fb575b816134ec602093836118f1565b810103126133e35751386134b3565b3d91506134df565b60209060405161351281611885565b8a81528a8382015282828701015201612fb1565b81601f8201121561018e57805161353c81611912565b9261354a60405194856118f1565b8184526020828401011161018e5761197f9160208085019101611b7b565b3d15613593573d9061357982611912565b9161358760405193846118f1565b82523d6000602084013e565b606090565b6000916000916000906040810151151580613c53575b80613c3d575b6135bc575050565b80516040516370a0823160e01b8152306004820152929550909350602090829060249082906001600160a01b03165afa9081156106e757600091613c0b575b506020838101516040516370a0823160e01b81523060048201529190829060249082906001600160a01b03165afa9081156106e757600091613bd9575b5060808401518051810160408282031261018e5760208201516001600160a01b038116929083900361018e576040810151906001600160401b03821161018e57602061368a92818b9501920101613526565b7f000000000000000000000000def1c0ded9bec7f1a1670819833240f027b25eff926001600160a01b038416810361390a57508051810190602081830312613902576020810151906001600160401b03821161390657019260408483031261390257604051936136f985611885565b61370560208201611bf4565b85526040810151906001600160401b0382116138fe57602061372d9281879601920101613526565b602085019081528851855160408b01516137559290916001600160a01b039081169116614843565b519082602083519301915af1613769613568565b50156138ec5784519051613789916001600160a01b0391821691166148fc565b83516040516370a0823160e01b815230600482015290602090829060249082906001600160a01b03165afa9081156138e15786916138ae575b506137cf90602493611d67565b6020858101516040516370a0823160e01b815230600482015292979294859182906001600160a01b03165afa908115610ec1579061387a575b6138129250611d67565b91606081015183106138685760018060a01b0381511690602060018060a01b0391015116907ffa2dda1cc1b86e41239702756b13effbc1a092b5c57e3ad320fbe4f3b13fe23560408051878152866020820152a3565b604051630d4205a160e11b8152600490fd5b506020823d6020116138a6575b81613894602093836118f1565b8101031261018e576138129151613808565b3d9150613887565b90506020813d6020116138d9575b816138c9602093836118f1565b8101031261018e575160246137c2565b3d91506138bc565b6040513d88823e3d90fd5b60405163081ceff360e41b8152600490fd5b8480fd5b8280fd5b8380fd5b9092507f0000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad6001600160a01b03161415905061174357805181019060208183031261018e5760208101516001600160401b03811161018e57606081830184031261018e576040519161397a8361186a565b602082820101516001600160401b03811161018e576139a3906020808701918585010101613526565b835260408282010151936001600160401b03851161018e5760208101603f868585010101121561018e576020858484010101516139df81611c4e565b956139ed60405197886118f1565b818752602087016020840160408460051b848989010101011161018e576040828787010101905b60408460051b848989010101018210613ba05750505050506020830193845201606001516040808301918252875190880151919291613a7d917f0000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad906001600160a01b03166143e3565b51915190517f0000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad6001600160a01b03163b1561018e57604051630d64d59360e21b8152606060048201529290918391613ad9906064840190611b9e565b600319838203016024840152815180825260208201916020808360051b8301019401926000915b838310613b6d575050505060448301939093526000925081900381837f0000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad6001600160a01b03165af180156106e757613b59575b50613789565b613b649195506117ee565b60009338613b53565b91939695509193602080613b8d600193601f198682030187528a51611b9e565b9801930193019092879596949293613b00565b8151906001600160401b03821161018e5760208091613bcc8960408096898e878e019401010101613526565b8152019201919050613a14565b90506020813d602011613c03575b81613bf4602093836118f1565b8101031261018e575138613638565b3d9150613be7565b90506020813d602011613c35575b81613c26602093836118f1565b8101031261018e5751386135fb565b3d9150613c19565b5060208101516001600160a01b031615156135b4565b5060808101515115156135ae565b919280613d14575b15613d0957507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031690813b1561018e576040518092632e1a7d4d60e01b82528160246000958680948960048401525af1801561320f57613cf6575b5081809381925af1613cdc613568565b5015613ce457565b604051637cd69c3960e11b8152600490fd5b613d02909291926117ee565b9038613ccc565b906122b792916143e3565b507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0390811690821614613c69565b9091613d568383614937565b909160018060a01b0384511660018060a01b0360208601511662ffffff6040870151166060870151608088015160020b610220890151916102408a0151936101208b0151956040519761016089018981106001600160401b0382111761180157604090815290895260208901918252888101928352600293840b60608a019081526080808b0196875260a08b018e815260c08c018e815260e08d01998a526101008d019a8b52306101208e019081526101408e019c8d529451634418b22b60e11b81529c516001600160a01b0390811660048f01529551861660248e0152955162ffffff1660448d01529151860b60648c0152955190940b60848a0152925160a4890152905160c4880152925160e487015292516101048601529151811661012485015291516101448401529082906101649082906000907f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe88165af19586156106e757600096600092600090600092613ffa575b508195819785998b60018060a01b03610100830151166102608301519060018060a01b037f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe88163b1561018e5782600091613f396040519485938493635c46a7ef60e11b85523060048601611bc3565b0381837f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b03165af180156106e7576122b7997fdbed0571af71402c681d3b0a1f08d80aa2245c9adb30e12d215356c7a274fcf9928892613feb575b50613fc689604051938493846040919493926001600160801b03606083019616825260208201520152565b0390a260e081015181516020909201516001600160a01b039081169281169116614c01565b613ff4906117ee565b38613f9b565b9350505095506080813d608011614044575b81614019608093836118f1565b8101031261018e5780519561403060208301611da5565b966060604084015193015190979238613eca565b3d915061400c565b9290916101605261012052808280808080808080806020810151604082015160018060a01b03606084015116906080840151926101c06101a061018061016061014061012061010060e060c08d60a0600180821b03910151169d01519d01519d01519d01519d01519d01519d01519d01519d01519d604051610140526140d461014051611832565b60018060a01b0316610140515260018060a01b036101605116602061014051015260006040610140510152600060606101405101526000608061014051015260a061014051015260c06101405101528060e0610140510152610100610140510152610120610140510152610140805101526101606101405101526101806101405101526101a06101405101526101c06101405101526101e0610140510152610200610140510152610220610140510152610240610140510152604051614199816118d6565b600081526102606101405101526102806101405101526141bf6101205161014051614937565b93909183516101808501516101a08601516080870151916040519360c085018581106001600160401b038211176118015760405284526020840187815260408501908a8252606086019283526080860193845260a086019485526040519563219f5d1760e01b87525160048701525160248601525160448501525160648401525160848301525160a482015260608160c481600060018060a01b037f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe88165af19081156106e757600096600091600093614311575b509082916122b794939682988a7f1aa7d7662b161a8d4058004091e4c60474753d2f085db526dfb22da59838d0a7858351926142ef89604051938493846040919493926001600160801b03606083019616825260208201520152565b0390a261012051610160516060909201519096906001600160a01b0316614c01565b9750929150506060863d60601161435c575b81614330606093836118f1565b8101031261018e576122b79161434587611da5565b604060208901519801519097909293919091614293565b3d9150614323565b919082604091031261018e576020825192015190565b6001600160801b039081811161438e571690565b60405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b6064820152608490fd5b60405163a9059cbb60e01b60208201526001600160a01b03909216602483015260448201929092526122b79161442682606481015b03601f1981018452836118f1565b614c54565b60009260008093819382341515918261445b575b50505081811161444d575050565b614458929550611d67565b92565b6001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2811692909190833b1561452057604051630d0e30db60e41b815290808260048134895af1908115610ec15750614511575b501681036144e45750349250508082116144d2575b38808061443f565b6040516307e205e160e41b8152600490fd5b6144ff57156144ca576040516307e205e160e41b8152600490fd5b6040516392b0337360e01b8152600490fd5b61451a906117ee565b386144b5565b80fd5b95929490956000966000938497859786879288346145e5575b508181116145d2575b50508181116145bf575b505084841192836145ac575b83614595575b508261457d575b5050614572575050565b61197f929350611d67565b6001600160a01b039182169116141590503880614568565b6001600160a01b0382811691161415925038614561565b6001600160a01b0382161515935061455b565b6145ca929950611d67565b96388061454f565b6145dd929c50611d67565b993880614545565b916001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2811690813b156138fe5760408051630d0e30db60e41b81529095808260048134885af19081156146c757506146b8575b50898116820361466d57505050349181341161465d57505b3861453c565b516307e205e160e41b8152600490fd5b93959193888116820361468c57505050349383341161465d5750614657565b959a5090948616036146a757349888341161465d5750614657565b88516392b0337360e01b8152600490fd5b6146c1906117ee565b3861463f565b8751903d90823e3d90fd5b6040516323b872dd60e01b60208083019182526001600160a01b039384166024840152929093166044820152606480820194909452928352916147679061471881611817565b6040519061472582611885565b8482527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656485830152600080948192519082805af1614761613568565b90614cb3565b8051918215918483156147d9575b5050509050156147825750565b6084906040519062461bcd60e51b82526004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152fd5b9193818094500103126147fd57820151908115158203614520575080388084614775565b5080fd5b6040516323b872dd60e01b60208201526001600160a01b0392831660248201529290911660448301526064808301939093529181526122b79161442682611817565b604051636eb1769f60e11b81523060048201526001600160a01b0383811660248301529093906020908590604490829086165afa9384156106e7576000946148c6575b50614897614426916122b795611d8a565b60405163095ea7b360e01b60208201526001600160a01b03909416602485015260448401528260648101614418565b93506020843d6020116148f4575b816148e1602093836118f1565b8101031261018e57925192614897614886565b3d91506148d4565b60405163095ea7b360e01b60208201526001600160a01b039092166024830152600060448084019190915282526122b79190614426826118bb565b91610140830160018060a01b039283825116918486511690818414600014614a68575050505060a083019283516101c0820190815111612b04576149c66149bf6149d19286855116908760208701511690516101e08701519061020088015192604051946149a486611817565b85526020850152604084015260608301526080820152613598565b9651611d67565b9460c0830151611d8a565b80935b85614a25575b816149e457505050565b60206122b79301908082511691614a1e827f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe881680946148fc565b5116614843565b614a638682855116614a5a847f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe881680926148fc565b83865116614843565b6149da565b6020879496970195878751168114600014614ade575050505060c081018051610160830190815111612b0457614ac4614acb9187614ad897511690888651169051610180870151906101a088015192604051946149a486611817565b9251611d67565b93849160a0840151611d8a565b946149d4565b929691928015614be8576101608501938451610180870151906101a08801519260405194614b0b86611817565b85526020850152604084015260608301526080820152614b2a90613598565b8380849a939a5116985116976101c087019889516101e0890151906102008a01519260405194614b5986611817565b85526020850152604084015260608301526080820152614b7890613598565b99909160a088015190614b8a91611d8a565b9960c088015190614b9a91611d8a565b988996519051614ba991611d8a565b90614bb391611d67565b90614bbd91611d67565b80614bcb575b5050506149d4565b614be092848060e08901511691511690613c61565b388080614bc3565b5050935050925060a08301519260c081015180936149d4565b9695614c1487939596614c1a9395611d67565b95611d67565b9380614c42575b50505081614c30575b50505050565b614c3993613c61565b38808080614c2a565b614c4c9287613c61565b388381614c21565b60018060a01b031690614767604051614c6c81611885565b6020938482527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564858301526000808587829751910182855af1614cad613568565b91614d4e565b90919015614d165750805115614cc65790565b60003b15614cd15790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b815115614d265750805190602001fd5b60405162461bcd60e51b815260206004820152908190614d4a906024830190611b9e565b0390fd5b91929015614d6b5750815115614d62575090565b3b15614cd15790565b825190915015614d265750805190602001fdfea26469706673582212208c686dcf0b4da65d053869af5a48dc267fd9ee252cf89bff6c841e2fb5a9b6d864736f6c63430008180033

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

000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe88000000000000000000000000def1c0ded9bec7f1a1670819833240f027b25eff0000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba3

-----Decoded View---------------
Arg [0] : _nonfungiblePositionManager (address): 0xC36442b4a4522E871399CD717aBDD847Ab11FE88
Arg [1] : _zeroxRouter (address): 0xDef1C0ded9bec7F1a1670819833240f027b25EfF
Arg [2] : _universalRouter (address): 0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD
Arg [3] : _permit2 (address): 0x000000000022D473030F116dDEE9F6B43aC78BA3

-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : 000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe88
Arg [1] : 000000000000000000000000def1c0ded9bec7f1a1670819833240f027b25eff
Arg [2] : 0000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad
Arg [3] : 000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba3


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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